From 246cc6dddd3df2164e8a925ebd8e9a7bba379253 Mon Sep 17 00:00:00 2001 From: Erik Andersen Date: Tue, 7 Mar 2000 07:41:42 +0000 Subject: Wrote killall. Adjusted mount, ps, utility.c, etc to handle my nifty new kernel patches the allow busybox to run perfectly without /proc. -Erik --- mount.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 7 deletions(-) (limited to 'mount.c') diff --git a/mount.c b/mount.c index 37f789d3c..f46664bf4 100644 --- a/mount.c +++ b/mount.c @@ -46,6 +46,10 @@ #include #include #include +#if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB +#include +#endif + #if defined BB_FEATURE_MOUNT_LOOP #include @@ -221,9 +225,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, { int status = 0; - char buf[255]; - #if defined BB_FEATURE_USE_PROCFS + char buf[255]; if (strcmp(filesystemType, "auto") == 0) { FILE *f = fopen("/proc/filesystems", "r"); @@ -251,6 +254,43 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, } fclose(f); } else +#endif +#if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB + if (strcmp(filesystemType, "auto") == 0) { + int fd, i, numfilesystems; + char device[] = "/dev/mtab"; + struct k_fstype *fslist; + + /* open device */ + fd = open(device, O_RDONLY); + if (fd < 0) + fatalError("open failed for `%s': %s\n", device, strerror (errno)); + + /* How many filesystems? We need to know to allocate enough space */ + numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); + if (numfilesystems<0) + fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno)); + fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype)); + + /* Grab the list of available filesystems */ + status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); + if (status<0) + fatalError("\nDEVMTAB_GET_FILESYSTEMS: %s\n", strerror (errno)); + + /* Walk the list trying to mount filesystems + * that do not claim to be nodev filesystems */ + for( i = 0 ; i < numfilesystems ; i++) { + if (fslist[i].mnt_nodev) + continue; + status = do_mount(blockDevice, directory, fslist[i].mnt_type, + flags | MS_MGC_VAL, string_flags, + useMtab, fakeIt, mtab_opts); + if (status == TRUE) + break; + } + free( fslist); + close(fd); + } else #endif { status = do_mount(blockDevice, directory, filesystemType, @@ -285,6 +325,39 @@ extern int mount_main(int argc, char **argv) /* Only compiled in if BB_MTAB is not defined */ whine_if_fstab_is_missing(); +#if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB + if (argc == 1) { + int fd, i, numfilesystems; + char device[] = "/dev/mtab"; + struct k_mntent *mntentlist; + + /* open device */ + fd = open(device, O_RDONLY); + if (fd < 0) + fatalError("open failed for `%s': %s\n", device, strerror (errno)); + + /* How many mounted filesystems? We need to know to + * allocate enough space for later... */ + numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS); + if (numfilesystems<0) + fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno)); + mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent)); + + /* Grab the list of mounted filesystems */ + if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) + fatalError( "\nDEVMTAB_GET_MOUNTS: %s\n", strerror (errno)); + + for( i = 0 ; i < numfilesystems ; i++) { + fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname, + mntentlist[i].mnt_dir, mntentlist[i].mnt_type, + mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, + mntentlist[i].mnt_passno); + } + free( mntentlist); + close(fd); + exit(TRUE); + } +#else if (argc == 1) { FILE *mountTable = setmntent(mtab_file, "r"); @@ -310,7 +383,7 @@ extern int mount_main(int argc, char **argv) } exit(TRUE); } - +#endif /* Parse options */ i = --argc; @@ -372,10 +445,9 @@ extern int mount_main(int argc, char **argv) struct mntent *m; FILE *f = setmntent("/etc/fstab", "r"); - if (f == NULL) { - perror("/etc/fstab"); - exit(FALSE); - } + if (f == NULL) + fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); + while ((m = getmntent(f)) != NULL) { // If the file system isn't noauto, // and isn't swap or nfs, then mount it -- cgit v1.2.3