diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-29 19:18:39 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-10-29 19:18:39 +0000 |
commit | 63430ae35ad98d5946851e8a366379dd1574f2a2 (patch) | |
tree | fcfdb5ab456be523745ba0b2314a3f83718364b5 | |
parent | a59f435b5f823ee7bdf55ed0e39688a12b7c881e (diff) | |
download | busybox-w32-63430ae35ad98d5946851e8a366379dd1574f2a2.tar.gz busybox-w32-63430ae35ad98d5946851e8a366379dd1574f2a2.tar.bz2 busybox-w32-63430ae35ad98d5946851e8a366379dd1574f2a2.zip |
mount: size-optimize mount_options[] and nfs_errtbl[]
777253 974 9676 787903 c05bf busybox_old
777209 974 9676 787859 c0593 busybox_unstripped
-rw-r--r-- | util-linux/mount.c | 167 |
1 files changed, 107 insertions, 60 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index fee2f6ee0..1ecdd9529 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #if defined(__dietlibc__) | 37 | #if defined(__dietlibc__) |
38 | /* 16.12.2006, Sampo Kellomaki (sampo@iki.fi) | 38 | /* 16.12.2006, Sampo Kellomaki (sampo@iki.fi) |
39 | * dietlibc-0.30 does not have implementation of getmntent_r() */ | 39 | * dietlibc-0.30 does not have implementation of getmntent_r() */ |
40 | struct mntent *getmntent_r(FILE* stream, struct mntent* result, char* buffer, int bufsize) | 40 | static struct mntent *getmntent_r(FILE* stream, struct mntent* result, char* buffer, int bufsize) |
41 | { | 41 | { |
42 | struct mntent* ment = getmntent(stream); | 42 | struct mntent* ment = getmntent(stream); |
43 | memcpy(result, ment, sizeof(struct mntent)); | 43 | memcpy(result, ment, sizeof(struct mntent)); |
@@ -66,63 +66,105 @@ enum { | |||
66 | /* Standard mount options (from -o options or --options), with corresponding | 66 | /* Standard mount options (from -o options or --options), with corresponding |
67 | * flags */ | 67 | * flags */ |
68 | 68 | ||
69 | static const struct { | 69 | static const int32_t mount_options[] = { |
70 | const char *name; | ||
71 | long flags; | ||
72 | } mount_options[] = { | ||
73 | // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs. | 70 | // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs. |
74 | 71 | ||
75 | USE_FEATURE_MOUNT_LOOP( | 72 | USE_FEATURE_MOUNT_LOOP( |
76 | {"loop", 0}, | 73 | /* "loop" */ 0, |
77 | ) | 74 | ) |
78 | 75 | ||
79 | USE_FEATURE_MOUNT_FSTAB( | 76 | USE_FEATURE_MOUNT_FSTAB( |
80 | {"defaults", 0}, | 77 | /* "defaults" */ 0, |
81 | /* {"quiet", 0}, - do not filter out, vfat wants to see it */ | 78 | /* "quiet" 0 - do not filter out, vfat wants to see it */ |
82 | {"noauto", MOUNT_NOAUTO}, | 79 | /* "noauto" */ MOUNT_NOAUTO, |
83 | {"sw", MOUNT_SWAP}, | 80 | /* "sw" */ MOUNT_SWAP, |
84 | {"swap", MOUNT_SWAP}, | 81 | /* "swap" */ MOUNT_SWAP, |
85 | USE_DESKTOP({"user", MOUNT_USERS},) | 82 | USE_DESKTOP(/* "user" */ MOUNT_USERS,) |
86 | USE_DESKTOP({"users", MOUNT_USERS},) | 83 | USE_DESKTOP(/* "users" */ MOUNT_USERS,) |
87 | ) | 84 | ) |
88 | 85 | ||
89 | USE_FEATURE_MOUNT_FLAGS( | 86 | USE_FEATURE_MOUNT_FLAGS( |
90 | // vfs flags | 87 | // vfs flags |
91 | {"nosuid", MS_NOSUID}, | 88 | /* "nosuid" */ MS_NOSUID, |
92 | {"suid", ~MS_NOSUID}, | 89 | /* "suid" */ ~MS_NOSUID, |
93 | {"dev", ~MS_NODEV}, | 90 | /* "dev" */ ~MS_NODEV, |
94 | {"nodev", MS_NODEV}, | 91 | /* "nodev" */ MS_NODEV, |
95 | {"exec", ~MS_NOEXEC}, | 92 | /* "exec" */ ~MS_NOEXEC, |
96 | {"noexec", MS_NOEXEC}, | 93 | /* "noexec" */ MS_NOEXEC, |
97 | {"sync", MS_SYNCHRONOUS}, | 94 | /* "sync" */ MS_SYNCHRONOUS, |
98 | {"async", ~MS_SYNCHRONOUS}, | 95 | /* "async" */ ~MS_SYNCHRONOUS, |
99 | {"atime", ~MS_NOATIME}, | 96 | /* "atime" */ ~MS_NOATIME, |
100 | {"noatime", MS_NOATIME}, | 97 | /* "noatime" */ MS_NOATIME, |
101 | {"diratime", ~MS_NODIRATIME}, | 98 | /* "diratime" */ ~MS_NODIRATIME, |
102 | {"nodiratime", MS_NODIRATIME}, | 99 | /* "nodiratime" */ MS_NODIRATIME, |
103 | {"loud", ~MS_SILENT}, | 100 | /* "loud" */ ~MS_SILENT, |
104 | 101 | ||
105 | // action flags | 102 | // action flags |
106 | 103 | /* "bind" */ MS_BIND, | |
107 | {"bind", MS_BIND}, | 104 | /* "move" */ MS_MOVE, |
108 | {"move", MS_MOVE}, | 105 | /* "shared" */ MS_SHARED, |
109 | {"shared", MS_SHARED}, | 106 | /* "slave" */ MS_SLAVE, |
110 | {"slave", MS_SLAVE}, | 107 | /* "private" */ MS_PRIVATE, |
111 | {"private", MS_PRIVATE}, | 108 | /* "unbindable" */ MS_UNBINDABLE, |
112 | {"unbindable", MS_UNBINDABLE}, | 109 | /* "rshared" */ MS_SHARED|MS_RECURSIVE, |
113 | {"rshared", MS_SHARED|MS_RECURSIVE}, | 110 | /* "rslave" */ MS_SLAVE|MS_RECURSIVE, |
114 | {"rslave", MS_SLAVE|MS_RECURSIVE}, | 111 | /* "rprivate" */ MS_SLAVE|MS_RECURSIVE, |
115 | {"rprivate", MS_SLAVE|MS_RECURSIVE}, | 112 | /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE, |
116 | {"runbindable", MS_UNBINDABLE|MS_RECURSIVE}, | ||
117 | ) | 113 | ) |
118 | 114 | ||
119 | // Always understood. | 115 | // Always understood. |
120 | 116 | /* "ro" */ MS_RDONLY, // vfs flag | |
121 | {"ro", MS_RDONLY}, // vfs flag | 117 | /* "rw" */ ~MS_RDONLY, // vfs flag |
122 | {"rw", ~MS_RDONLY}, // vfs flag | 118 | /* "remount" */ MS_REMOUNT // action flag |
123 | {"remount", MS_REMOUNT}, // action flag | ||
124 | }; | 119 | }; |
125 | 120 | ||
121 | static const char mount_option_str[] = | ||
122 | USE_FEATURE_MOUNT_LOOP( | ||
123 | "loop" "\0" | ||
124 | ) | ||
125 | USE_FEATURE_MOUNT_FSTAB( | ||
126 | "defaults" "\0" | ||
127 | /* "quiet" "\0" - do not filter out, vfat wants to see it */ | ||
128 | "noauto" "\0" | ||
129 | "sw" "\0" | ||
130 | "swap" "\0" | ||
131 | USE_DESKTOP("user" "\0") | ||
132 | USE_DESKTOP("users" "\0") | ||
133 | ) | ||
134 | USE_FEATURE_MOUNT_FLAGS( | ||
135 | // vfs flags | ||
136 | "nosuid" "\0" | ||
137 | "suid" "\0" | ||
138 | "dev" "\0" | ||
139 | "nodev" "\0" | ||
140 | "exec" "\0" | ||
141 | "noexec" "\0" | ||
142 | "sync" "\0" | ||
143 | "async" "\0" | ||
144 | "atime" "\0" | ||
145 | "noatime" "\0" | ||
146 | "diratime" "\0" | ||
147 | "nodiratime" "\0" | ||
148 | "loud" "\0" | ||
149 | |||
150 | // action flags | ||
151 | "bind" "\0" | ||
152 | "move" "\0" | ||
153 | "shared" "\0" | ||
154 | "slave" "\0" | ||
155 | "private" "\0" | ||
156 | "unbindable" "\0" | ||
157 | "rshared" "\0" | ||
158 | "rslave" "\0" | ||
159 | "rprivate" "\0" | ||
160 | "runbindable" "\0" | ||
161 | ) | ||
162 | |||
163 | // Always understood. | ||
164 | "ro" "\0" // vfs flag | ||
165 | "rw" "\0" // vfs flag | ||
166 | "remount" "\0" // action flag | ||
167 | ; | ||
126 | 168 | ||
127 | /* Append mount options to string */ | 169 | /* Append mount options to string */ |
128 | static void append_mount_options(char **oldopts, const char *newopts) | 170 | static void append_mount_options(char **oldopts, const char *newopts) |
@@ -137,7 +179,7 @@ static void append_mount_options(char **oldopts, const char *newopts) | |||
137 | p = *oldopts; | 179 | p = *oldopts; |
138 | while (1) { | 180 | while (1) { |
139 | if (!strncmp(p, newopts, len) | 181 | if (!strncmp(p, newopts, len) |
140 | && (p[len]==',' || p[len]==0)) | 182 | && (p[len] == ',' || p[len] == '\0')) |
141 | goto skip; | 183 | goto skip; |
142 | p = strchr(p,','); | 184 | p = strchr(p,','); |
143 | if (!p) break; | 185 | if (!p) break; |
@@ -146,7 +188,7 @@ static void append_mount_options(char **oldopts, const char *newopts) | |||
146 | p = xasprintf("%s,%.*s", *oldopts, len, newopts); | 188 | p = xasprintf("%s,%.*s", *oldopts, len, newopts); |
147 | free(*oldopts); | 189 | free(*oldopts); |
148 | *oldopts = p; | 190 | *oldopts = p; |
149 | skip: | 191 | skip: |
150 | newopts += len; | 192 | newopts += len; |
151 | while (newopts[0] == ',') newopts++; | 193 | while (newopts[0] == ',') newopts++; |
152 | } | 194 | } |
@@ -166,17 +208,19 @@ static int parse_mount_options(char *options, char **unrecognized) | |||
166 | for (;;) { | 208 | for (;;) { |
167 | int i; | 209 | int i; |
168 | char *comma = strchr(options, ','); | 210 | char *comma = strchr(options, ','); |
211 | const char *option_str = mount_option_str; | ||
169 | 212 | ||
170 | if (comma) *comma = 0; | 213 | if (comma) *comma = '\0'; |
171 | 214 | ||
172 | // Find this option in mount_options | 215 | // Find this option in mount_options |
173 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { | 216 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { |
174 | if (!strcasecmp(mount_options[i].name, options)) { | 217 | if (!strcasecmp(option_str, options)) { |
175 | long fl = mount_options[i].flags; | 218 | long fl = mount_options[i]; |
176 | if (fl < 0) flags &= fl; | 219 | if (fl < 0) flags &= fl; |
177 | else flags |= fl; | 220 | else flags |= fl; |
178 | break; | 221 | break; |
179 | } | 222 | } |
223 | option_str += strlen(option_str) + 1; | ||
180 | } | 224 | } |
181 | // If unrecognized not NULL, append unrecognized mount options */ | 225 | // If unrecognized not NULL, append unrecognized mount options */ |
182 | if (unrecognized && i == ARRAY_SIZE(mount_options)) { | 226 | if (unrecognized && i == ARRAY_SIZE(mount_options)) { |
@@ -263,7 +307,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) | |||
263 | for (;;) { | 307 | for (;;) { |
264 | rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, | 308 | rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, |
265 | vfsflags, filteropts); | 309 | vfsflags, filteropts); |
266 | if (!rc || (vfsflags&MS_RDONLY) || (errno!=EACCES && errno!=EROFS)) | 310 | if (!rc || (vfsflags & MS_RDONLY) || (errno != EACCES && errno != EROFS)) |
267 | break; | 311 | break; |
268 | if (!(vfsflags & MS_SILENT)) | 312 | if (!(vfsflags & MS_SILENT)) |
269 | bb_error_msg("%s is write-protected, mounting read-only", | 313 | bb_error_msg("%s is write-protected, mounting read-only", |
@@ -282,23 +326,26 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) | |||
282 | if (ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc && !(vfsflags & MS_REMOUNT)) { | 326 | if (ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc && !(vfsflags & MS_REMOUNT)) { |
283 | char *fsname; | 327 | char *fsname; |
284 | FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); | 328 | FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); |
329 | const char *option_str = mount_option_str; | ||
285 | int i; | 330 | int i; |
286 | 331 | ||
287 | if (!mountTable) { | 332 | if (!mountTable) { |
288 | bb_error_msg("no %s",bb_path_mtab_file); | 333 | bb_error_msg("no %s", bb_path_mtab_file); |
289 | goto ret; | 334 | goto ret; |
290 | } | 335 | } |
291 | 336 | ||
292 | // Add vfs string flags | 337 | // Add vfs string flags |
293 | 338 | ||
294 | for (i=0; mount_options[i].flags != MS_REMOUNT; i++) | 339 | for (i = 0; mount_options[i] != MS_REMOUNT; i++) { |
295 | if (mount_options[i].flags > 0 && (mount_options[i].flags & vfsflags)) | 340 | if (mount_options[i] > 0 && (mount_options[i] & vfsflags)) |
296 | append_mount_options(&(mp->mnt_opts), mount_options[i].name); | 341 | append_mount_options(&(mp->mnt_opts), option_str); |
342 | option_str += strlen(option_str) + 1; | ||
343 | } | ||
297 | 344 | ||
298 | // Remove trailing / (if any) from directory we mounted on | 345 | // Remove trailing / (if any) from directory we mounted on |
299 | 346 | ||
300 | i = strlen(mp->mnt_dir) - 1; | 347 | i = strlen(mp->mnt_dir) - 1; |
301 | if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = 0; | 348 | if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0'; |
302 | 349 | ||
303 | // Convert to canonical pathnames as needed | 350 | // Convert to canonical pathnames as needed |
304 | 351 | ||
@@ -550,8 +597,8 @@ enum { | |||
550 | // Convert each NFSERR_BLAH into EBLAH | 597 | // Convert each NFSERR_BLAH into EBLAH |
551 | 598 | ||
552 | static const struct { | 599 | static const struct { |
553 | int stat; | 600 | short stat; |
554 | int errnum; | 601 | short errnum; |
555 | } nfs_errtbl[] = { | 602 | } nfs_errtbl[] = { |
556 | {0,0}, {1,EPERM}, {2,ENOENT}, {5,EIO}, {6,ENXIO}, {13,EACCES}, {17,EEXIST}, | 603 | {0,0}, {1,EPERM}, {2,ENOENT}, {5,EIO}, {6,ENXIO}, {13,EACCES}, {17,EEXIST}, |
557 | {19,ENODEV}, {20,ENOTDIR}, {21,EISDIR}, {22,EINVAL}, {27,EFBIG}, | 604 | {19,ENODEV}, {20,ENOTDIR}, {21,EISDIR}, {22,EINVAL}, {27,EFBIG}, |
@@ -1154,7 +1201,7 @@ static int nfsmount(struct mntent *mp, int vfsflags, char *filteropts) | |||
1154 | timeout = time(NULL) + 60 * retry; | 1201 | timeout = time(NULL) + 60 * retry; |
1155 | prevt = 0; | 1202 | prevt = 0; |
1156 | t = 30; | 1203 | t = 30; |
1157 | retry: | 1204 | retry: |
1158 | /* be careful not to use too many CPU cycles */ | 1205 | /* be careful not to use too many CPU cycles */ |
1159 | if (t - prevt < 30) | 1206 | if (t - prevt < 30) |
1160 | sleep(30); | 1207 | sleep(30); |
@@ -1254,7 +1301,7 @@ retry: | |||
1254 | goto retry; | 1301 | goto retry; |
1255 | } | 1302 | } |
1256 | 1303 | ||
1257 | prepare_kernel_data: | 1304 | prepare_kernel_data: |
1258 | 1305 | ||
1259 | if (nfsvers == 2) { | 1306 | if (nfsvers == 2) { |
1260 | if (status.nfsv2.fhs_status != 0) { | 1307 | if (status.nfsv2.fhs_status != 0) { |
@@ -1349,13 +1396,13 @@ prepare_kernel_data: | |||
1349 | } | 1396 | } |
1350 | } | 1397 | } |
1351 | 1398 | ||
1352 | do_mount: /* perform actual mount */ | 1399 | do_mount: /* perform actual mount */ |
1353 | 1400 | ||
1354 | mp->mnt_type = (char*)"nfs"; | 1401 | mp->mnt_type = (char*)"nfs"; |
1355 | retval = mount_it_now(mp, vfsflags, (char*)&data); | 1402 | retval = mount_it_now(mp, vfsflags, (char*)&data); |
1356 | goto ret; | 1403 | goto ret; |
1357 | 1404 | ||
1358 | fail: /* abort */ | 1405 | fail: /* abort */ |
1359 | 1406 | ||
1360 | if (msock >= 0) { | 1407 | if (msock >= 0) { |
1361 | if (mclient) { | 1408 | if (mclient) { |
@@ -1367,7 +1414,7 @@ fail: /* abort */ | |||
1367 | if (fsock >= 0) | 1414 | if (fsock >= 0) |
1368 | close(fsock); | 1415 | close(fsock); |
1369 | 1416 | ||
1370 | ret: | 1417 | ret: |
1371 | free(hostname); | 1418 | free(hostname); |
1372 | free(mounthost); | 1419 | free(mounthost); |
1373 | free(filteropts); | 1420 | free(filteropts); |
@@ -1756,7 +1803,7 @@ int mount_main(int argc, char **argv) | |||
1756 | } | 1803 | } |
1757 | if (ENABLE_FEATURE_CLEAN_UP) endmntent(fstab); | 1804 | if (ENABLE_FEATURE_CLEAN_UP) endmntent(fstab); |
1758 | 1805 | ||
1759 | clean_up: | 1806 | clean_up: |
1760 | 1807 | ||
1761 | if (ENABLE_FEATURE_CLEAN_UP) { | 1808 | if (ENABLE_FEATURE_CLEAN_UP) { |
1762 | free(storage_path); | 1809 | free(storage_path); |