Skip to content

Commit 6e7c177

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: simplify get_filesystem_list / get_all_fs_names
Just output the '\0' separate list of supported file systems for block devices directly rather than going through a pointless round of string manipulation. Based on an earlier patch from Al Viro <viro@zeniv.linux.org.uk>. Vivek: Modified list_bdev_fs_names() and split_fs_names() to return number of null terminted strings to caller. Callers now use that information to loop through all the strings instead of relying on one extra null char being present at the end. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f9259be commit 6e7c177

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

fs/filesystems.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,28 @@ SYSCALL_DEFINE3(sysfs, int, option, unsigned long, arg1, unsigned long, arg2)
209209
}
210210
#endif
211211

212-
int __init get_filesystem_list(char *buf)
212+
int __init list_bdev_fs_names(char *buf, size_t size)
213213
{
214-
int len = 0;
215-
struct file_system_type * tmp;
214+
struct file_system_type *p;
215+
size_t len;
216+
int count = 0;
216217

217218
read_lock(&file_systems_lock);
218-
tmp = file_systems;
219-
while (tmp && len < PAGE_SIZE - 80) {
220-
len += sprintf(buf+len, "%s\t%s\n",
221-
(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
222-
tmp->name);
223-
tmp = tmp->next;
219+
for (p = file_systems; p; p = p->next) {
220+
if (!(p->fs_flags & FS_REQUIRES_DEV))
221+
continue;
222+
len = strlen(p->name) + 1;
223+
if (len > size) {
224+
pr_warn("%s: truncating file system list\n", __func__);
225+
break;
226+
}
227+
memcpy(buf, p->name, len);
228+
buf += len;
229+
size -= len;
230+
count++;
224231
}
225232
read_unlock(&file_systems_lock);
226-
return len;
233+
return count;
227234
}
228235

229236
#ifdef CONFIG_PROC_FS

include/linux/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3622,7 +3622,7 @@ int proc_nr_dentry(struct ctl_table *table, int write,
36223622
void *buffer, size_t *lenp, loff_t *ppos);
36233623
int proc_nr_inodes(struct ctl_table *table, int write,
36243624
void *buffer, size_t *lenp, loff_t *ppos);
3625-
int __init get_filesystem_list(char *buf);
3625+
int __init list_bdev_fs_names(char *buf, size_t size);
36263626

36273627
#define __FMODE_EXEC ((__force int) FMODE_EXEC)
36283628
#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY)

init/do_mounts.c

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -338,32 +338,22 @@ __setup("rootflags=", root_data_setup);
338338
__setup("rootfstype=", fs_names_setup);
339339
__setup("rootdelay=", root_delay_setup);
340340

341-
static void __init split_fs_names(char *page, char *names)
341+
static int __init split_fs_names(char *page, char *names)
342342
{
343-
strcpy(page, root_fs_names);
344-
while (*page++) {
345-
if (page[-1] == ',')
346-
page[-1] = '\0';
347-
}
348-
*page = '\0';
349-
}
350-
351-
static void __init get_all_fs_names(char *page)
352-
{
353-
int len = get_filesystem_list(page);
354-
char *s = page, *p, *next;
343+
int count = 0;
344+
char *p = page;
355345

356-
page[len] = '\0';
357-
for (p = page - 1; p; p = next) {
358-
next = strchr(++p, '\n');
359-
if (*p++ != '\t')
360-
continue;
361-
while ((*s++ = *p++) != '\n')
362-
;
363-
s[-1] = '\0';
346+
strcpy(p, root_fs_names);
347+
while (*p++) {
348+
if (p[-1] == ',')
349+
p[-1] = '\0';
364350
}
351+
*p = '\0';
352+
353+
for (p = page; *p; p += strlen(p)+1)
354+
count++;
365355

366-
*s = '\0';
356+
return count;
367357
}
368358

369359
static int __init do_mount_root(const char *name, const char *fs,
@@ -409,15 +399,16 @@ void __init mount_block_root(char *name, int flags)
409399
char *fs_names = page_address(page);
410400
char *p;
411401
char b[BDEVNAME_SIZE];
402+
int num_fs, i;
412403

413404
scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
414405
MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
415406
if (root_fs_names)
416-
split_fs_names(fs_names, root_fs_names);
407+
num_fs = split_fs_names(fs_names, root_fs_names);
417408
else
418-
get_all_fs_names(fs_names);
409+
num_fs = list_bdev_fs_names(fs_names, PAGE_SIZE);
419410
retry:
420-
for (p = fs_names; *p; p += strlen(p)+1) {
411+
for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1) {
421412
int err = do_mount_root(name, p, flags, root_mount_data);
422413
switch (err) {
423414
case 0:
@@ -450,7 +441,7 @@ void __init mount_block_root(char *name, int flags)
450441
printk("List of all partitions:\n");
451442
printk_all_partitions();
452443
printk("No filesystem could mount root, tried: ");
453-
for (p = fs_names; *p; p += strlen(p)+1)
444+
for (i = 0, p = fs_names; i < num_fs; i++, p += strlen(p)+1)
454445
printk(" %s", p);
455446
printk("\n");
456447
panic("VFS: Unable to mount root fs on %s", b);
@@ -551,13 +542,15 @@ static int __init mount_nodev_root(void)
551542
{
552543
char *fs_names, *fstype;
553544
int err = -EINVAL;
545+
int num_fs, i;
554546

555547
fs_names = (void *)__get_free_page(GFP_KERNEL);
556548
if (!fs_names)
557549
return -EINVAL;
558-
split_fs_names(fs_names, root_fs_names);
550+
num_fs = split_fs_names(fs_names, root_fs_names);
559551

560-
for (fstype = fs_names; *fstype; fstype += strlen(fstype) + 1) {
552+
for (i = 0, fstype = fs_names; i < num_fs;
553+
i++, fstype += strlen(fstype) + 1) {
561554
if (!fs_is_nodev(fstype))
562555
continue;
563556
err = do_mount_root(root_device_name, fstype, root_mountflags,

0 commit comments

Comments
 (0)