diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-03-01 07:50:04 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-03-01 07:50:04 +0000 |
commit | 7b91f020217823736f59e9eccfc721b05b937807 (patch) | |
tree | b07ee09c54df47e3809f6433ee2cf24eb3abe5d5 | |
parent | 93ba60f01d19f443187d8720fd8a93bdb890d4e5 (diff) | |
download | busybox-w32-7b91f020217823736f59e9eccfc721b05b937807.tar.gz busybox-w32-7b91f020217823736f59e9eccfc721b05b937807.tar.bz2 busybox-w32-7b91f020217823736f59e9eccfc721b05b937807.zip |
Reduce the size of mount (and bypass /proc/filesystems) by using the sysfs
system call, based on work done by Glenn McGrath in December.
-Erik
-rw-r--r-- | mount.c | 75 | ||||
-rw-r--r-- | util-linux/mount.c | 75 | ||||
-rw-r--r-- | utility.c | 4 |
3 files changed, 30 insertions, 124 deletions
@@ -83,6 +83,7 @@ extern int mount (__const char *__special_file, __const char *__dir, | |||
83 | __const void *__data); | 83 | __const void *__data); |
84 | extern int umount (__const char *__special_file); | 84 | extern int umount (__const char *__special_file); |
85 | extern int umount2 (__const char *__special_file, int __flags); | 85 | extern int umount2 (__const char *__special_file, int __flags); |
86 | static _syscall3(int, sysfs, int, option, unsigned int, fs_index, char *, buf); | ||
86 | 87 | ||
87 | 88 | ||
88 | extern const char mtab_file[]; /* Defined in utility.c */ | 89 | extern const char mtab_file[]; /* Defined in utility.c */ |
@@ -233,72 +234,24 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
233 | { | 234 | { |
234 | int status = 0; | 235 | int status = 0; |
235 | 236 | ||
236 | char buf[255]; | ||
237 | if (strcmp(filesystemType, "auto") == 0) { | 237 | if (strcmp(filesystemType, "auto") == 0) { |
238 | FILE *f = xfopen("/proc/filesystems", "r"); | 238 | int i=0; |
239 | 239 | const int num_of_filesystems = sysfs(3, 0, 0); | |
240 | while (fgets(buf, sizeof(buf), f) != NULL) { | 240 | char buf[255]; |
241 | filesystemType = buf; | 241 | filesystemType=buf; |
242 | if (*filesystemType == '\t') { // Not a nodev filesystem | 242 | |
243 | 243 | while(i < num_of_filesystems) { | |
244 | // Add NULL termination to each line | 244 | sysfs(2, i++, filesystemType); |
245 | while (*filesystemType && *filesystemType != '\n') | 245 | status = do_mount(blockDevice, directory, filesystemType, |
246 | filesystemType++; | 246 | flags | MS_MGC_VAL, string_flags, |
247 | *filesystemType = '\0'; | 247 | useMtab, fakeIt, mtab_opts); |
248 | |||
249 | filesystemType = buf; | ||
250 | filesystemType++; // hop past tab | ||
251 | |||
252 | status = do_mount(blockDevice, directory, filesystemType, | ||
253 | flags | MS_MGC_VAL, string_flags, | ||
254 | useMtab, fakeIt, mtab_opts); | ||
255 | if (status == TRUE) | ||
256 | break; | ||
257 | } | ||
258 | } | ||
259 | fclose(f); | ||
260 | } else | ||
261 | #if defined BB_FEATURE_USE_DEVPS_PATCH | ||
262 | if (strcmp(filesystemType, "auto") == 0) { | ||
263 | int fd, i, numfilesystems; | ||
264 | char device[] = "/dev/mtab"; | ||
265 | struct k_fstype *fslist; | ||
266 | |||
267 | /* open device */ | ||
268 | fd = open(device, O_RDONLY); | ||
269 | if (fd < 0) | ||
270 | perror_msg_and_die("open failed for `%s'", device); | ||
271 | |||
272 | /* How many filesystems? We need to know to allocate enough space */ | ||
273 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); | ||
274 | if (numfilesystems<0) | ||
275 | perror_msg_and_die("\nDEVMTAB_COUNT_FILESYSTEMS"); | ||
276 | fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype)); | ||
277 | |||
278 | /* Grab the list of available filesystems */ | ||
279 | status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); | ||
280 | if (status<0) | ||
281 | perror_msg_and_die("\nDEVMTAB_GET_FILESYSTEMS"); | ||
282 | |||
283 | /* Walk the list trying to mount filesystems | ||
284 | * that do not claim to be nodev filesystems */ | ||
285 | for( i = 0 ; i < numfilesystems ; i++) { | ||
286 | if (fslist[i].mnt_nodev) | ||
287 | continue; | ||
288 | status = do_mount(blockDevice, directory, fslist[i].mnt_type, | ||
289 | flags | MS_MGC_VAL, string_flags, | ||
290 | useMtab, fakeIt, mtab_opts); | ||
291 | if (status == TRUE) | 248 | if (status == TRUE) |
292 | break; | 249 | break; |
293 | } | 250 | } |
294 | free( fslist); | 251 | } else { |
295 | close(fd); | ||
296 | } else | ||
297 | #endif | ||
298 | { | ||
299 | status = do_mount(blockDevice, directory, filesystemType, | 252 | status = do_mount(blockDevice, directory, filesystemType, |
300 | flags | MS_MGC_VAL, string_flags, useMtab, | 253 | flags | MS_MGC_VAL, string_flags, useMtab, |
301 | fakeIt, mtab_opts); | 254 | fakeIt, mtab_opts); |
302 | } | 255 | } |
303 | 256 | ||
304 | if (status == FALSE) { | 257 | if (status == FALSE) { |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 76cab7d79..2353a8ac2 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -83,6 +83,7 @@ extern int mount (__const char *__special_file, __const char *__dir, | |||
83 | __const void *__data); | 83 | __const void *__data); |
84 | extern int umount (__const char *__special_file); | 84 | extern int umount (__const char *__special_file); |
85 | extern int umount2 (__const char *__special_file, int __flags); | 85 | extern int umount2 (__const char *__special_file, int __flags); |
86 | static _syscall3(int, sysfs, int, option, unsigned int, fs_index, char *, buf); | ||
86 | 87 | ||
87 | 88 | ||
88 | extern const char mtab_file[]; /* Defined in utility.c */ | 89 | extern const char mtab_file[]; /* Defined in utility.c */ |
@@ -233,72 +234,24 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
233 | { | 234 | { |
234 | int status = 0; | 235 | int status = 0; |
235 | 236 | ||
236 | char buf[255]; | ||
237 | if (strcmp(filesystemType, "auto") == 0) { | 237 | if (strcmp(filesystemType, "auto") == 0) { |
238 | FILE *f = xfopen("/proc/filesystems", "r"); | 238 | int i=0; |
239 | 239 | const int num_of_filesystems = sysfs(3, 0, 0); | |
240 | while (fgets(buf, sizeof(buf), f) != NULL) { | 240 | char buf[255]; |
241 | filesystemType = buf; | 241 | filesystemType=buf; |
242 | if (*filesystemType == '\t') { // Not a nodev filesystem | 242 | |
243 | 243 | while(i < num_of_filesystems) { | |
244 | // Add NULL termination to each line | 244 | sysfs(2, i++, filesystemType); |
245 | while (*filesystemType && *filesystemType != '\n') | 245 | status = do_mount(blockDevice, directory, filesystemType, |
246 | filesystemType++; | 246 | flags | MS_MGC_VAL, string_flags, |
247 | *filesystemType = '\0'; | 247 | useMtab, fakeIt, mtab_opts); |
248 | |||
249 | filesystemType = buf; | ||
250 | filesystemType++; // hop past tab | ||
251 | |||
252 | status = do_mount(blockDevice, directory, filesystemType, | ||
253 | flags | MS_MGC_VAL, string_flags, | ||
254 | useMtab, fakeIt, mtab_opts); | ||
255 | if (status == TRUE) | ||
256 | break; | ||
257 | } | ||
258 | } | ||
259 | fclose(f); | ||
260 | } else | ||
261 | #if defined BB_FEATURE_USE_DEVPS_PATCH | ||
262 | if (strcmp(filesystemType, "auto") == 0) { | ||
263 | int fd, i, numfilesystems; | ||
264 | char device[] = "/dev/mtab"; | ||
265 | struct k_fstype *fslist; | ||
266 | |||
267 | /* open device */ | ||
268 | fd = open(device, O_RDONLY); | ||
269 | if (fd < 0) | ||
270 | perror_msg_and_die("open failed for `%s'", device); | ||
271 | |||
272 | /* How many filesystems? We need to know to allocate enough space */ | ||
273 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); | ||
274 | if (numfilesystems<0) | ||
275 | perror_msg_and_die("\nDEVMTAB_COUNT_FILESYSTEMS"); | ||
276 | fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype)); | ||
277 | |||
278 | /* Grab the list of available filesystems */ | ||
279 | status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); | ||
280 | if (status<0) | ||
281 | perror_msg_and_die("\nDEVMTAB_GET_FILESYSTEMS"); | ||
282 | |||
283 | /* Walk the list trying to mount filesystems | ||
284 | * that do not claim to be nodev filesystems */ | ||
285 | for( i = 0 ; i < numfilesystems ; i++) { | ||
286 | if (fslist[i].mnt_nodev) | ||
287 | continue; | ||
288 | status = do_mount(blockDevice, directory, fslist[i].mnt_type, | ||
289 | flags | MS_MGC_VAL, string_flags, | ||
290 | useMtab, fakeIt, mtab_opts); | ||
291 | if (status == TRUE) | 248 | if (status == TRUE) |
292 | break; | 249 | break; |
293 | } | 250 | } |
294 | free( fslist); | 251 | } else { |
295 | close(fd); | ||
296 | } else | ||
297 | #endif | ||
298 | { | ||
299 | status = do_mount(blockDevice, directory, filesystemType, | 252 | status = do_mount(blockDevice, directory, filesystemType, |
300 | flags | MS_MGC_VAL, string_flags, useMtab, | 253 | flags | MS_MGC_VAL, string_flags, useMtab, |
301 | fakeIt, mtab_opts); | 254 | fakeIt, mtab_opts); |
302 | } | 255 | } |
303 | 256 | ||
304 | if (status == FALSE) { | 257 | if (status == FALSE) { |
@@ -63,8 +63,8 @@ | |||
63 | #include <sys/syscall.h> | 63 | #include <sys/syscall.h> |
64 | #include <linux/unistd.h> | 64 | #include <linux/unistd.h> |
65 | 65 | ||
66 | /* Busybox mount uses either /proc/filesystems or /dev/mtab to get the | 66 | /* Busybox mount uses either /proc/mounts or /dev/mtab to |
67 | * list of available filesystems used for the -t auto option */ | 67 | * get the list of currently mounted filesystems */ |
68 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF | 68 | #if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF |
69 | # if defined BB_MTAB | 69 | # if defined BB_MTAB |
70 | const char mtab_file[] = "/etc/mtab"; | 70 | const char mtab_file[] = "/etc/mtab"; |