1 // SPDX-License-Identifier: GPL-2.0
3 * SMB root file system support
5 * Copyright (c) 2019 Paulo Alcantara <palcantara@suse.de>
7 #include <linux/init.h>
9 #include <linux/types.h>
10 #include <linux/ctype.h>
11 #include <linux/string.h>
12 #include <linux/root_dev.h>
13 #include <linux/kernel.h>
15 #include <linux/inet.h>
16 #include <net/ipconfig.h>
18 #define DEFAULT_MNT_OPTS \
19 "vers=1.0,cifsacl,mfsymlinks,rsize=1048576,wsize=65536,uid=0,gid=0," \
22 static char root_dev[2048] __initdata = "";
23 static char root_opts[1024] __initdata = DEFAULT_MNT_OPTS;
25 static __be32 __init parse_srvaddr(char *start, char *end)
27 /* TODO: ipv6 support */
28 char addr[sizeof("aaa.bbb.ccc.ddd")];
31 while (start < end && i < sizeof(addr) - 1) {
32 if (isdigit(*start) || *start == '.')
40 /* cifsroot=//<server-ip>/<share>[,options] */
41 static int __init cifs_root_setup(char *line)
45 __be32 srvaddr = htonl(INADDR_NONE);
49 if (strlen(line) > 3 && line[0] == '/' && line[1] == '/') {
50 s = strchr(&line[2], '/');
51 if (!s || s[1] == '\0')
54 /* make s point to ',' or '\0' at end of line */
55 s = strchrnul(s, ',');
56 /* len is strlen(unc) + '\0' */
58 if (len > sizeof(root_dev)) {
59 pr_err("Root-CIFS: UNC path too long\n");
62 strscpy(root_dev, line, len);
63 srvaddr = parse_srvaddr(&line[2], s);
65 int n = snprintf(root_opts,
66 sizeof(root_opts), "%s,%s",
67 DEFAULT_MNT_OPTS, s + 1);
68 if (n >= sizeof(root_opts)) {
69 pr_err("Root-CIFS: mount options string too long\n");
70 root_opts[sizeof(root_opts)-1] = '\0';
76 root_server_addr = srvaddr;
81 __setup("cifsroot=", cifs_root_setup);
83 int __init cifs_root_data(char **dev, char **opts)
85 if (!root_dev[0] || root_server_addr == htonl(INADDR_NONE)) {
86 pr_err("Root-CIFS: no SMB server address\n");