Re: [PATCH 1/2] init: split get_fs_names

From: Al Viro
Date: Mon Jun 21 2021 - 10:46:43 EST


On Mon, Jun 21, 2021 at 08:26:56AM +0200, Christoph Hellwig wrote:
> Split get_fs_names into one function that splits up the command line
> argument, and one that gets the list of all registered file systems.

> +static void __init get_all_fs_names(char *page)
> +{
> + int len = get_filesystem_list(page);
> + char *s = page, *p, *next;
> +
> + page[len] = '\0';
> + for (p = page - 1; p; p = next) {
> + next = strchr(++p, '\n');
> + if (*p++ != '\t')
> + continue;
> + while ((*s++ = *p++) != '\n')
> + ;
> + s[-1] = '\0';
> }
> +
> *s = '\0';
> }

TBH, I would rather take that one into fs/filesystems.c. Rationale:
get_filesystem_list(), for all its resemblance to /proc/filesystems
contents, is used only by init/*.c and it's not a big deal to make
it

int __init get_filesystem_list(char *buf, bool is_dev)
{
int f = is_dev ? FS_REQUIRES_DEV : 0;
int left = PAGE_SIZE, count = 0;
struct file_system_type *p;

read_lock(&file_systems_lock);
for (p = file_systems; p; p = p->next) {
if ((p->fs_flags & FS_REQUIRES_DEV) == f) {
size_t len = strlen(p->name) + 1;
if (len > left)
break;
memcpy(buf, p->name, len);
buf += len;
left -= len;
count++;
}
}
read_unlock(&file_systems_lock);
return count;
}

Generates NUL-separated list, returns the number of list elements,
the second argument is "what kind do you want"...