Blame view
fs/cifs/cifsroot.c
2.05 KB
8eecd1c2e
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// SPDX-License-Identifier: GPL-2.0 /* * SMB root file system support * * Copyright (c) 2019 Paulo Alcantara <palcantara@suse.de> */ #include <linux/init.h> #include <linux/fs.h> #include <linux/types.h> #include <linux/ctype.h> #include <linux/string.h> #include <linux/root_dev.h> #include <linux/kernel.h> #include <linux/in.h> #include <linux/inet.h> #include <net/ipconfig.h> #define DEFAULT_MNT_OPTS \ "vers=1.0,cifsacl,mfsymlinks,rsize=1048576,wsize=65536,uid=0,gid=0," \ "hard,rootfs" static char root_dev[2048] __initdata = ""; static char root_opts[1024] __initdata = DEFAULT_MNT_OPTS; static __be32 __init parse_srvaddr(char *start, char *end) { |
352f2c9a5
|
27 |
/* TODO: ipv6 support */ |
8eecd1c2e
|
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
char addr[sizeof("aaa.bbb.ccc.ddd")]; int i = 0; while (start < end && i < sizeof(addr) - 1) { if (isdigit(*start) || *start == '.') addr[i++] = *start; start++; } addr[i] = '\0'; return in_aton(addr); } /* cifsroot=//<server-ip>/<share>[,options] */ static int __init cifs_root_setup(char *line) { char *s; int len; __be32 srvaddr = htonl(INADDR_NONE); ROOT_DEV = Root_CIFS; if (strlen(line) > 3 && line[0] == '/' && line[1] == '/') { s = strchr(&line[2], '/'); if (!s || s[1] == '\0') return 1; |
352f2c9a5
|
53 |
/* make s point to ',' or '\0' at end of line */ |
8eecd1c2e
|
54 |
s = strchrnul(s, ','); |
352f2c9a5
|
55 |
/* len is strlen(unc) + '\0' */ |
8eecd1c2e
|
56 |
len = s - line + 1; |
352f2c9a5
|
57 |
if (len > sizeof(root_dev)) { |
a0a3036b8
|
58 59 |
pr_err("Root-CIFS: UNC path too long "); |
352f2c9a5
|
60 61 62 63 64 65 66 |
return 1; } strlcpy(root_dev, line, len); srvaddr = parse_srvaddr(&line[2], s); if (*s) { int n = snprintf(root_opts, sizeof(root_opts), "%s,%s", |
8eecd1c2e
|
67 |
DEFAULT_MNT_OPTS, s + 1); |
352f2c9a5
|
68 |
if (n >= sizeof(root_opts)) { |
a0a3036b8
|
69 70 |
pr_err("Root-CIFS: mount options string too long "); |
352f2c9a5
|
71 72 |
root_opts[sizeof(root_opts)-1] = '\0'; return 1; |
8eecd1c2e
|
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
} } } root_server_addr = srvaddr; return 1; } __setup("cifsroot=", cifs_root_setup); int __init cifs_root_data(char **dev, char **opts) { if (!root_dev[0] || root_server_addr == htonl(INADDR_NONE)) { |
a0a3036b8
|
87 88 |
pr_err("Root-CIFS: no SMB server address "); |
8eecd1c2e
|
89 90 91 92 93 94 95 96 |
return -1; } *dev = root_dev; *opts = root_opts; return 0; } |