mkswap: do not do extra seek
authorDenis Vlasenko <vda.linux@googlemail.com>
Sun, 3 Feb 2008 23:52:41 +0000 (23:52 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Sun, 3 Feb 2008 23:52:41 +0000 (23:52 -0000)
mount: add another mount helper call method

util-linux/Config.in
util-linux/mkswap.c
util-linux/mount.c

index d236b77b6f30878ed0d2f4d140a248233d898380..e97f8406229f1efd8b0f58c63f16f6e5a7fef657 100644 (file)
@@ -392,9 +392,11 @@ config FEATURE_MOUNT_HELPERS
        depends on MOUNT
        help
          Enable mounting of virtual file systems via external helpers.
-         E.g. mount obexfs#-b00.11.22.33.44.55 /mnt will in effect call
-         obexfs -b00.11.22.33.44.55 /mnt
-         The idea is to use such virtual filesystems in /etc/fstab
+         E.g. "mount obexfs#-b00.11.22.33.44.55 /mnt" will in effect call
+         "obexfs -b00.11.22.33.44.55 /mnt"
+         Also "mount -t sometype [-o opts] fs /mnt" will try
+         "sometype [-o opts] fs /mnt" if simple mount syscall fails.
+         The idea is to use such virtual filesystems in /etc/fstab.
 
 config FEATURE_MOUNT_NFS
        bool "Support mounting NFS file systems"
index f047cce26a2761e275e923cebde7d6ecc079bbbb..31d577315c38331bf51965c693ae7dbcbcea2f6f 100644 (file)
@@ -66,7 +66,9 @@ int mkswap_main(int argc, char **argv)
        fd = xopen(argv[1], O_RDWR);
        /* fdlength was reported to be unreliable - use seek */
        len = xlseek(fd, 0, SEEK_END);
+#if ENABLE_SELINUX
        xlseek(fd, 0, SEEK_SET);
+#endif
        pagesize = getpagesize();
        printf("Setting up swapspace version 1, size = %"OFF_FMT"u bytes\n",
                        len - pagesize);
index 4ac52cd02f2fca3e3f656d4700be1b532723e370..5e6c3ba72886d4eb18e8171fcf07b0ef30344ea4 100644 (file)
@@ -309,6 +309,27 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts)
        for (;;) {
                rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
                                vfsflags, filteropts);
+
+               // If mount failed, try
+               // helper program <mnt_type>
+               if (ENABLE_FEATURE_MOUNT_HELPERS && rc) {
+                       char *args[6];
+                       int errno_save = errno;
+                       args[0] = mp->mnt_type;
+                       rc = 1;
+                       if (filteropts) {
+                               args[rc++] = (char *)"-o";
+                               args[rc++] = filteropts;
+                       }
+                       args[rc++] = mp->mnt_fsname;
+                       args[rc++] = mp->mnt_dir;
+                       args[rc] = NULL;
+                       rc = wait4pid(spawn(args));
+                       if (!rc)
+                               break;
+                       errno = errno_save;
+               }
+
                if (!rc || (vfsflags & MS_RDONLY) || (errno != EACCES && errno != EROFS))
                        break;
                if (!(vfsflags & MS_SILENT))