hush: rename o_quoted to has_quoted_part; small code shrink
[oweals/busybox.git] / util-linux / mount.c
index 0bad597709eea48f1ee401c2ee149eb8f820f470..5e85f998641c473ef5f4e66c42dc394b245adc80 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  * Copyright (C) 2005-2006 by Rob Landley <rob@landley.net>
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 // Design notes: There is no spec for mount.  Remind me to write one.
 //
@@ -267,7 +267,6 @@ struct globals {
 #endif
        llist_t *fslist;
        char getmntent_buf[1];
-
 } FIX_ALIASING;
 enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) };
 #define G (*(struct globals*)&bb_common_bufsiz1)
@@ -457,7 +456,7 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
                                args[rc++] = filteropts;
                        }
                        args[rc] = NULL;
-                       rc = wait4pid(spawn(args));
+                       rc = spawn_and_wait(args);
                        free(args[0]);
                        if (!rc)
                                break;
@@ -533,7 +532,7 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
  * Linux NFS mount
  * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
  *
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  *
  * Wed Feb  8 12:51:48 1995, biro@yggdrasil.com (Ross Biro): allow all port
  * numbers to be specified on the command line.
@@ -750,7 +749,15 @@ static const uint8_t nfs_err_stat[] = {
        19, 20, 21, 22, 27, 28,
        30, 63, 66, 69, 70, 71
 };
-static const uint8_t nfs_err_errnum[] = {
+#if ( \
+       EPERM | ENOENT      | EIO      | ENXIO | EACCES| EEXIST | \
+       ENODEV| ENOTDIR     | EISDIR   | EINVAL| EFBIG | ENOSPC | \
+       EROFS | ENAMETOOLONG| ENOTEMPTY| EDQUOT| ESTALE| EREMOTE) < 256
+typedef uint8_t nfs_err_type;
+#else
+typedef uint16_t nfs_err_type;
+#endif
+static const nfs_err_type nfs_err_errnum[] = {
        EPERM , ENOENT      , EIO      , ENXIO , EACCES, EEXIST,
        ENODEV, ENOTDIR     , EISDIR   , EINVAL, EFBIG , ENOSPC,
        EROFS , ENAMETOOLONG, ENOTEMPTY, EDQUOT, ESTALE, EREMOTE
@@ -1044,12 +1051,10 @@ static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
                        bb_herror_msg("%s", hostname);
                        goto fail;
                }
-               if ((size_t)hp->h_length > sizeof(struct in_addr)) {
-                       bb_error_msg("got bad hp->h_length");
-                       hp->h_length = sizeof(struct in_addr);
+               if (hp->h_length != (int)sizeof(struct in_addr)) {
+                       bb_error_msg_and_die("only IPv4 is supported");
                }
-               memcpy(&server_addr.sin_addr,
-                               hp->h_addr, hp->h_length);
+               memcpy(&server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr));
        }
 
        memcpy(&mount_server_addr, &server_addr, sizeof(mount_server_addr));
@@ -1142,7 +1147,7 @@ static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
                                continue;
                        }
 
-                       val = xatoi_u(opteq);
+                       val = xatoi_positive(opteq);
                        switch (idx) {
                        case 0: // "rsize"
                                data.rsize = val;
@@ -1332,13 +1337,11 @@ static NOINLINE int nfsmount(struct mntent *mp, long vfsflags, char *filteropts)
                                bb_herror_msg("%s", mounthost);
                                goto fail;
                        }
-                       if ((size_t)hp->h_length > sizeof(struct in_addr)) {
-                               bb_error_msg("got bad hp->h_length");
-                               hp->h_length = sizeof(struct in_addr);
+                       if (hp->h_length != (int)sizeof(struct in_addr)) {
+                               bb_error_msg_and_die("only IPv4 is supported");
                        }
                        mount_server_addr.sin_family = AF_INET;
-                       memcpy(&mount_server_addr.sin_addr,
-                                               hp->h_addr, hp->h_length);
+                       memcpy(&mount_server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr));
                }
        }
 
@@ -1638,7 +1641,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
                }
                args[n++] = mp->mnt_dir;
                args[n] = NULL;
-               rc = wait4pid(xspawn(args));
+               rc = spawn_and_wait(args);
                goto report_error;
        }
 
@@ -1715,9 +1718,9 @@ static int singlemount(struct mntent *mp, int ignore_busy)
 
        // If we know the fstype (or don't need to), jump straight
        // to the actual mount.
-       if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE)))
+       if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) {
                rc = mount_it_now(mp, vfsflags, filteropts);
-       else {
+       else {
                // Loop through filesystem types until mount succeeds
                // or we run out
 
@@ -1753,7 +1756,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
 
        if (errno == EBUSY && ignore_busy)
                return 0;
-       if (rc < 0)
+       if (rc != 0)
                bb_perror_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir);
        return rc;
 }
@@ -1926,7 +1929,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
        }
        fstab = setmntent(fstabname, "r");
        if (!fstab)
-               bb_perror_msg_and_die("can't read %s", fstabname);
+               bb_perror_msg_and_die("can't read '%s'", fstabname);
 
        // Loop through entries until we find what we're looking for
        memset(mtpair, 0, sizeof(mtpair));