Skip to content

Commit 48b96ae

Browse files
AphlitaAphlita
authored andcommitted
style: format code with clang-format [skip ci]
1 parent abe3b03 commit 48b96ae

2 files changed

Lines changed: 106 additions & 89 deletions

File tree

components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args)
4343
switch (cmd)
4444
{
4545
case RT_FIOGETADDR:
46+
{
47+
if (args == RT_NULL)
4648
{
47-
if (args == RT_NULL)
48-
{
49-
ret = -RT_EINVAL;
50-
break;
51-
}
52-
*(rt_ubase_t*)args = (rt_ubase_t)dirent->data;
49+
ret = -RT_EINVAL;
5350
break;
5451
}
52+
*(rt_ubase_t *)args = (rt_ubase_t)dirent->data;
53+
break;
54+
}
5555
case RT_FIOFTRUNCATE:
56-
{
57-
break;
58-
}
56+
{
57+
break;
58+
}
5959
default:
6060
ret = -RT_EINVAL;
6161
break;
@@ -65,8 +65,7 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args)
6565

6666
rt_inline int check_dirent(struct romfs_dirent *dirent)
6767
{
68-
if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR)
69-
|| dirent->size == ~0U)
68+
if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) || dirent->size == ~0U)
7069
return -1;
7170
return 0;
7271
}
@@ -96,31 +95,31 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch
9695
subpath_end = path;
9796
/* skip /// */
9897
while (*subpath_end && *subpath_end == '/')
99-
subpath_end ++;
98+
subpath_end++;
10099
subpath = subpath_end;
101100
while ((*subpath_end != '/') && *subpath_end)
102-
subpath_end ++;
101+
subpath_end++;
103102

104103
while (dirent != NULL)
105104
{
106105
found = 0;
107106

108107
/* search in folder */
109-
for (index = 0; index < dirent_size; index ++)
108+
for (index = 0; index < dirent_size; index++)
110109
{
111110
if (check_dirent(&dirent[index]) != 0)
112111
return NULL;
113-
if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) &&
114-
rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
112+
if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) &&
113+
rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
115114
{
116115
dirent_size = dirent[index].size;
117116

118117
/* skip /// */
119118
while (*subpath_end && *subpath_end == '/')
120-
subpath_end ++;
119+
subpath_end++;
121120
subpath = subpath_end;
122121
while ((*subpath_end != '/') && *subpath_end)
123-
subpath_end ++;
122+
subpath_end++;
124123

125124
if (!(*subpath))
126125
{
@@ -215,8 +214,7 @@ int dfs_romfs_open(struct dfs_file *file)
215214
RT_ASSERT(file->vnode->ref_count > 0);
216215
if (file->vnode->ref_count > 1)
217216
{
218-
if (file->vnode->type == FT_DIRECTORY
219-
&& !(file->flags & O_DIRECTORY))
217+
if (file->vnode->type == FT_DIRECTORY && !(file->flags & O_DIRECTORY))
220218
{
221219
return -ENOENT;
222220
}
@@ -345,14 +343,13 @@ int dfs_romfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32_t coun
345343
rt_strncpy(d->d_name, name, DIRENT_NAME_MAX);
346344

347345
/* move to next position */
348-
++ file->pos;
346+
++file->pos;
349347
}
350348

351349
return index * sizeof(struct dirent);
352350
}
353351

354-
static const struct dfs_file_ops _rom_fops =
355-
{
352+
static const struct dfs_file_ops _rom_fops = {
356353
dfs_romfs_open,
357354
dfs_romfs_close,
358355
dfs_romfs_ioctl,
@@ -363,8 +360,7 @@ static const struct dfs_file_ops _rom_fops =
363360
dfs_romfs_getdents,
364361
NULL,
365362
};
366-
static const struct dfs_filesystem_ops _romfs =
367-
{
363+
static const struct dfs_filesystem_ops _romfs = {
368364
"rom",
369365
DFS_FS_FLAG_DEFAULT,
370366
&_rom_fops,
@@ -388,29 +384,56 @@ int dfs_romfs_init(void)
388384
INIT_COMPONENT_EXPORT(dfs_romfs_init);
389385

390386
#ifndef RT_USING_DFS_ROMFS_USER_ROOT
391-
static const unsigned char _dummy_dummy_txt[] =
392-
{
393-
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a,
387+
static const unsigned char _dummy_dummy_txt[] = {
388+
0x74,
389+
0x68,
390+
0x69,
391+
0x73,
392+
0x20,
393+
0x69,
394+
0x73,
395+
0x20,
396+
0x61,
397+
0x20,
398+
0x66,
399+
0x69,
400+
0x6c,
401+
0x65,
402+
0x21,
403+
0x0d,
404+
0x0a,
394405
};
395406

396-
static const struct romfs_dirent _dummy[] =
397-
{
398-
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt)},
407+
static const struct romfs_dirent _dummy[] = {
408+
{ ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt) },
399409
};
400410

401-
static const unsigned char _dummy_txt[] =
402-
{
403-
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a,
411+
static const unsigned char _dummy_txt[] = {
412+
0x74,
413+
0x68,
414+
0x69,
415+
0x73,
416+
0x20,
417+
0x69,
418+
0x73,
419+
0x20,
420+
0x61,
421+
0x20,
422+
0x66,
423+
0x69,
424+
0x6c,
425+
0x65,
426+
0x21,
427+
0x0d,
428+
0x0a,
404429
};
405430

406-
rt_weak const struct romfs_dirent _root_dirent[] =
407-
{
408-
{ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0])},
409-
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)},
431+
rt_weak const struct romfs_dirent _root_dirent[] = {
432+
{ ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0]) },
433+
{ ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt) },
410434
};
411435

412-
rt_weak const struct romfs_dirent romfs_root =
413-
{
436+
rt_weak const struct romfs_dirent romfs_root = {
414437
ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent) / sizeof(_root_dirent[0])
415438
};
416439
#endif

components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222

2323
static const struct dfs_file_ops _rom_fops;
2424

25-
static const mode_t romfs_modemap[] =
26-
{
27-
S_IFREG | 0644, /* regular file */
28-
S_IFDIR | 0644, /* directory */
25+
static const mode_t romfs_modemap[] = {
26+
S_IFREG | 0644, /* regular file */
27+
S_IFDIR | 0644, /* directory */
2928
0, /* hard link */
30-
S_IFLNK | 0777, /* symlink */
31-
S_IFBLK | 0600, /* blockdev */
32-
S_IFCHR | 0600, /* chardev */
29+
S_IFLNK | 0777, /* symlink */
30+
S_IFBLK | 0600, /* blockdev */
31+
S_IFCHR | 0600, /* chardev */
3332
S_IFSOCK | 0644, /* socket */
34-
S_IFIFO | 0644 /* FIFO */
33+
S_IFIFO | 0644 /* FIFO */
3534
};
3635

3736
static int dfs_romfs_mount(struct dfs_mnt *mnt, unsigned long rwflag, const void *data)
@@ -63,19 +62,19 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args)
6362
switch (cmd)
6463
{
6564
case RT_FIOGETADDR:
65+
{
66+
if (args == RT_NULL)
6667
{
67-
if (args == RT_NULL)
68-
{
69-
ret = -RT_EINVAL;
70-
break;
71-
}
72-
*(rt_ubase_t*)args = (rt_ubase_t)dirent->data;
68+
ret = -RT_EINVAL;
7369
break;
7470
}
71+
*(rt_ubase_t *)args = (rt_ubase_t)dirent->data;
72+
break;
73+
}
7574
case RT_FIOFTRUNCATE:
76-
{
77-
break;
78-
}
75+
{
76+
break;
77+
}
7978
default:
8079
ret = -RT_EINVAL;
8180
break;
@@ -85,9 +84,7 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args)
8584

8685
rt_inline int check_dirent(struct romfs_dirent *dirent)
8786
{
88-
if (dirent == NULL
89-
||(dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR)
90-
|| dirent->size == ~0)
87+
if (dirent == NULL || (dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) || dirent->size == ~0)
9188
return -1;
9289
return 0;
9390
}
@@ -117,31 +114,31 @@ struct romfs_dirent *__dfs_romfs_lookup(struct romfs_dirent *root_dirent, const
117114
subpath_end = path;
118115
/* skip /// */
119116
while (*subpath_end && *subpath_end == '/')
120-
subpath_end ++;
117+
subpath_end++;
121118
subpath = subpath_end;
122119
while ((*subpath_end != '/') && *subpath_end)
123-
subpath_end ++;
120+
subpath_end++;
124121

125122
while (dirent != NULL)
126123
{
127124
found = 0;
128125

129126
/* search in folder */
130-
for (index = 0; index < dirent_size; index ++)
127+
for (index = 0; index < dirent_size; index++)
131128
{
132129
if (check_dirent(&dirent[index]) != 0)
133130
return NULL;
134131
if (rt_strlen(dirent[index].name) == (subpath_end - subpath) &&
135-
rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
132+
rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0)
136133
{
137134
dirent_size = dirent[index].size;
138135

139136
/* skip /// */
140137
while (*subpath_end && *subpath_end == '/')
141-
subpath_end ++;
138+
subpath_end++;
142139
subpath = subpath_end;
143140
while ((*subpath_end != '/') && *subpath_end)
144-
subpath_end ++;
141+
subpath_end++;
145142

146143
if (!(*subpath))
147144
{
@@ -172,7 +169,7 @@ struct romfs_dirent *__dfs_romfs_lookup(struct romfs_dirent *root_dirent, const
172169
return NULL;
173170
}
174171

175-
static struct dfs_vnode *dfs_romfs_lookup (struct dfs_dentry *dentry)
172+
static struct dfs_vnode *dfs_romfs_lookup(struct dfs_dentry *dentry)
176173
{
177174
rt_size_t size;
178175
struct dfs_vnode *vnode = RT_NULL;
@@ -360,37 +357,34 @@ static int dfs_romfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32
360357
rt_strncpy(d->d_name, name, DIRENT_NAME_MAX);
361358

362359
/* move to next position */
363-
++ file->fpos;
360+
++file->fpos;
364361
}
365362

366363
return index * sizeof(struct dirent);
367364
}
368365

369-
static const struct dfs_file_ops _rom_fops =
370-
{
371-
.open = dfs_romfs_open,
372-
.close = dfs_romfs_close,
373-
.ioctl = dfs_romfs_ioctl,
374-
.lseek = generic_dfs_lseek,
375-
.read = dfs_romfs_read,
376-
.getdents = dfs_romfs_getdents,
366+
static const struct dfs_file_ops _rom_fops = {
367+
.open = dfs_romfs_open,
368+
.close = dfs_romfs_close,
369+
.ioctl = dfs_romfs_ioctl,
370+
.lseek = generic_dfs_lseek,
371+
.read = dfs_romfs_read,
372+
.getdents = dfs_romfs_getdents,
377373
};
378374

379-
static const struct dfs_filesystem_ops _romfs_ops =
380-
{
381-
.name ="rom",
382-
.flags = 0,
383-
.default_fops = &_rom_fops,
384-
.mount = dfs_romfs_mount,
385-
.umount = dfs_romfs_umount,
386-
.stat = dfs_romfs_stat,
387-
.lookup = dfs_romfs_lookup,
388-
.free_vnode = dfs_romfs_free_vnode
375+
static const struct dfs_filesystem_ops _romfs_ops = {
376+
.name = "rom",
377+
.flags = 0,
378+
.default_fops = &_rom_fops,
379+
.mount = dfs_romfs_mount,
380+
.umount = dfs_romfs_umount,
381+
.stat = dfs_romfs_stat,
382+
.lookup = dfs_romfs_lookup,
383+
.free_vnode = dfs_romfs_free_vnode
389384
};
390385

391-
static struct dfs_filesystem_type _romfs =
392-
{
393-
.fs_ops = &_romfs_ops,
386+
static struct dfs_filesystem_type _romfs = {
387+
.fs_ops = &_romfs_ops,
394388
};
395389

396390
int dfs_romfs_init(void)

0 commit comments

Comments
 (0)