Skip to content

Commit

Permalink
[DFS][romfs] fix the mkrom issue when file/dir size zero
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardXiong committed Jan 13, 2019
1 parent 8f0d865 commit bd7ebbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions components/dfs/filesystems/romfs/dfs_romfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

struct romfs_dirent
{
rt_uint32_t type; /* dirent type */
rt_uint32_t type; /* dirent type */

const char *name; /* dirent name */
const rt_uint8_t *data; /* file date ptr */
rt_size_t size; /* file size */
const char *name; /* dirent name */
const rt_uint8_t *data; /* file date ptr */
rt_size_t size; /* file size */
};

int dfs_romfs_init(void);
Expand Down
18 changes: 15 additions & 3 deletions components/dfs/filesystems/romfs/mkromfs.py → tools/mkromfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def c_data(self, prefix=''):
head = 'static const rt_uint8_t %s[] = {\n' % \
(prefix + self.c_name)
tail = '\n};'

if self.entry_size == 0:
return ''

return head + ','.join(('0x%02x' % ord(i) for i in self._data)) + tail

@property
Expand Down Expand Up @@ -118,23 +122,31 @@ def c_data(self, prefix=''):
It is recursive.'''
# make the current dirent
# static is good. Only root dirent is global visible.
if self.entry_size == 0:
return ''

dhead = 'static const struct romfs_dirent %s[] = {\n' % (prefix + self.c_name)
dtail = '\n};'
body_fmt = ' {{{type}, "{name}", (rt_uint8_t *){data}, sizeof({data})/sizeof({data}[0])}}'
body_fmt0= ' {{{type}, "{name}", RT_NULL, 0}}'
# prefix of children
cpf = prefix+self.c_name
body_li = []
payload_li = []
for c in self._children:
entry_size = c.entry_size
if isinstance(c, File):
tp = 'ROMFS_DIRENT_FILE'
elif isinstance(c, Folder):
tp = 'ROMFS_DIRENT_DIR'
else:
assert False, 'Unkown instance:%s' % str(c)
body_li.append(body_fmt.format(type=tp,
name=c.name,
data=cpf+c.c_name))
if entry_size == 0:
body_li.append(body_fmt0.format(type=tp, name = c.name))
else:
body_li.append(body_fmt.format(type=tp,
name=c.name,
data=cpf+c.c_name))
payload_li.append(c.c_data(prefix=cpf))

# All the data we need is defined in payload so we should append the
Expand Down

0 comments on commit bd7ebbf

Please sign in to comment.