0001
0002
0003
0004
0005
0006
0007 #include <linux/init.h>
0008 #include <linux/fs.h>
0009 #include <linux/types.h>
0010 #include <linux/ctype.h>
0011 #include <linux/string.h>
0012 #include <linux/root_dev.h>
0013 #include <linux/kernel.h>
0014 #include <linux/in.h>
0015 #include <linux/inet.h>
0016 #include <net/ipconfig.h>
0017
0018 #define DEFAULT_MNT_OPTS \
0019 "vers=1.0,cifsacl,mfsymlinks,rsize=1048576,wsize=65536,uid=0,gid=0," \
0020 "hard,rootfs"
0021
0022 static char root_dev[2048] __initdata = "";
0023 static char root_opts[1024] __initdata = DEFAULT_MNT_OPTS;
0024
0025 static __be32 __init parse_srvaddr(char *start, char *end)
0026 {
0027
0028 char addr[sizeof("aaa.bbb.ccc.ddd")];
0029 int i = 0;
0030
0031 while (start < end && i < sizeof(addr) - 1) {
0032 if (isdigit(*start) || *start == '.')
0033 addr[i++] = *start;
0034 start++;
0035 }
0036 addr[i] = '\0';
0037 return in_aton(addr);
0038 }
0039
0040
0041 static int __init cifs_root_setup(char *line)
0042 {
0043 char *s;
0044 int len;
0045 __be32 srvaddr = htonl(INADDR_NONE);
0046
0047 ROOT_DEV = Root_CIFS;
0048
0049 if (strlen(line) > 3 && line[0] == '/' && line[1] == '/') {
0050 s = strchr(&line[2], '/');
0051 if (!s || s[1] == '\0')
0052 return 1;
0053
0054
0055 s = strchrnul(s, ',');
0056
0057 len = s - line + 1;
0058 if (len > sizeof(root_dev)) {
0059 pr_err("Root-CIFS: UNC path too long\n");
0060 return 1;
0061 }
0062 strscpy(root_dev, line, len);
0063 srvaddr = parse_srvaddr(&line[2], s);
0064 if (*s) {
0065 int n = snprintf(root_opts,
0066 sizeof(root_opts), "%s,%s",
0067 DEFAULT_MNT_OPTS, s + 1);
0068 if (n >= sizeof(root_opts)) {
0069 pr_err("Root-CIFS: mount options string too long\n");
0070 root_opts[sizeof(root_opts)-1] = '\0';
0071 return 1;
0072 }
0073 }
0074 }
0075
0076 root_server_addr = srvaddr;
0077
0078 return 1;
0079 }
0080
0081 __setup("cifsroot=", cifs_root_setup);
0082
0083 int __init cifs_root_data(char **dev, char **opts)
0084 {
0085 if (!root_dev[0] || root_server_addr == htonl(INADDR_NONE)) {
0086 pr_err("Root-CIFS: no SMB server address\n");
0087 return -1;
0088 }
0089
0090 *dev = root_dev;
0091 *opts = root_opts;
0092
0093 return 0;
0094 }