#include <mntent.h>
#include <sys/mount.h>
#include <ctype.h>
-#include <fstab.h>
+#if defined BB_FEATURE_USE_DEVPS_PATCH
+#include <linux/devmtab.h>
+#endif
+
#if defined BB_FEATURE_MOUNT_LOOP
#include <fcntl.h>
"\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n"
"\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n"
"\tro / rw: Mount for read-only / read-write.\n"
- "\t"
-
"There are EVEN MORE flags that are specific to each filesystem.\n"
"You'll have to see the written documentation for those.\n";
fprintf(stderr, "WARNING: loop device is read-only\n");
flags &= ~MS_RDONLY;
}
- use_loop = FALSE;
}
#endif
status =
{
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");
}
fclose(f);
} else
+#endif
+#if defined BB_FEATURE_USE_DEVPS_PATCH
+ 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,
int useMtab = TRUE;
int i;
- /* Only compiled in if BB_MTAB is not defined */
- whine_if_fstab_is_missing();
-
+#if defined BB_FEATURE_USE_DEVPS_PATCH
+ 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);
+ }
+ /* Don't bother to close files or free memory. Exit
+ * does that automagically, so we can save a few bytes */
+#if 0
+ free( mntentlist);
+ close(fd);
+#endif
+ exit(TRUE);
+ }
+#else
if (argc == 1) {
FILE *mountTable = setmntent(mtab_file, "r");
struct mntent *m;
while ((m = getmntent(mountTable)) != 0) {
- struct fstab *fstabItem;
char *blockDevice = m->mnt_fsname;
-
- /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp(blockDevice, "/dev/root") == 0) {
- fstabItem = getfsfile("/");
- if (fstabItem != NULL)
- blockDevice = fstabItem->fs_spec;
+ find_real_root_device_name( blockDevice);
}
printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
m->mnt_type, m->mnt_opts);
}
exit(TRUE);
}
-
+#endif
/* Parse options */
i = --argc;
case 'a':
all = TRUE;
break;
-#ifdef BB_MTAB
case 'f':
fakeIt = TRUE;
break;
+#ifdef BB_MTAB
case 'n':
useMtab = FALSE;
break;
#endif
case 'v':
+ break; /* ignore -v */
case 'h':
case '-':
goto goodbye;
struct mntent *m;
FILE *f = setmntent("/etc/fstab", "r");
- if (f == NULL) {
- perror("/etc/fstab");
- exit(FALSE);
- }
+ if (f == NULL)
+ fatalError( "\nCannot read /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