* Fixed 'swapon -a' and 'swapoff -a', which were broken.
authorEric Andersen <andersen@codepoet.org>
Wed, 7 Jun 2000 17:28:53 +0000 (17:28 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 7 Jun 2000 17:28:53 +0000 (17:28 -0000)
* Fixed 'mount -a' so it works as expected.
* Implemented 'ls -R' (enabled by enabling BB_FEATURE_LS_RECURSIVE)
 -Erik

Changelog
TODO
busybox.def.h
coreutils/ls.c
docs/busybox.pod
ls.c
mount.c
swaponoff.c
util-linux/mount.c
util-linux/swaponoff.c

index da229a962667281e54aecac11e0db8a332cc6c62..50b28cf62adc8043a097c9d8f74de75d1e7f63e1 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -60,6 +60,9 @@
        * "mount" now reports errors from nfsmount() and assumes NFS mount
            if ':' is present in the device name - Pavel Roskin
        * Fixed exit status for killall - Pavel Roskin
+       * Fixed 'swapon -a' and 'swapoff -a', which were broken.
+       * Fixed 'mount -a' so it works as expected.
+       * Implemented 'ls -R' (enabled by enabling BB_FEATURE_LS_RECURSIVE)
        * More doc updates
 
 
diff --git a/TODO b/TODO
index 182408b75b44c0f227d5310710f800e46e1c38ac..71bb5365a169909c9665a396989cac827c04cc9f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -18,19 +18,12 @@ around to it some time. If you have any good ideas, please let me know.
 
 Bugs that need fixing before the 0.44 release goes out the door:
 
- - mkfs.minix rev 1.7 completely broke the parser.  Fix it.
  - 'grep foo$ file' doesn't work
  - 'grep *foo file' segfaults
  - ps dirent race bug (need to stat the file before attempting chdir)
-  - I believe that swaponoff may also be also broken (check it).
-  - It used to be that BusyBox tar would happily overwrite existing files on
-      an extraction.  However, as of 0.42, BusyBox tar simply dies as soon as an 
-      existing file is found.
- - Make 'mount -a' work even when /proc isn't mounted (ugly bug).
  - Make 'ln -s /tmp/file .' work the way GNU ln does (i.e. makes a link to 
     /tmp/file in the current directory, rather then trying and failing to create
     a symlink named "." in the current working directory).
- - implement 'ls -R'.
  - "math" should also take input from stdin
  - "more" doesn't accept " " to scroll by one page when BB_FEATURE_USE_TERMIOS
     is not on.
index 3b7c8bf26dbc1055b3870584d117f7744745fd63..11a791ef4d40a65359596d13e3548bfe3e7242bf 100644 (file)
 // enable ls -p and -F
 #define BB_FEATURE_LS_FILETYPES
 //
+// enable ls -R
+#define BB_FEATURE_LS_RECURSIVE
+//
 // Change ping implementation -- simplified, featureless, but really small.
 //#define BB_SIMPLE_PING
 //
index 6ab11c4e5f21dcbbea41db921b1026fef4722533..0b1aa6221639305efd01dc05eefceb59acb50b0c 100644 (file)
@@ -86,8 +86,9 @@
 #define DISP_DOT       8                       /* show . and .. */
 #define DISP_NUMERIC   16              /* numeric uid and gid */
 #define DISP_FULLTIME  32              /* show extended time display */
-#define DIR_NOLIST     64                      /* show directory as itself, not contents */
+#define DIR_NOLIST             64              /* show directory as itself, not contents */
 #define DISP_DIRNAME   128             /* show directory name (for internal use) */
+#define DISP_RECURSIVE 256             /* Do a recursive listing */
 
 #ifndef MAJOR
 #define MAJOR(dev) (((dev)>>8)&0xff)
@@ -448,6 +449,9 @@ static const char ls_usage[] = "ls [-1a"
        "xAC"
 #ifdef BB_FEATURE_LS_FILETYPES
        "F"
+#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+       "R"
 #endif
        "] [filenames...]\n"
 #ifndef BB_FEATURE_TRIVIAL_HELP
@@ -477,9 +481,24 @@ static const char ls_usage[] = "ls [-1a"
 #ifdef BB_FEATURE_LS_FILETYPES
        "\t-F\tappend indicator (one of */=@|) to entries\n"
 #endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+       "\t-R\tlist subdirectories recursively\n"
+#endif
 #endif
        ;
 
+
+#ifdef BB_FEATURE_LS_RECURSIVE
+static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
+{
+       int i;
+       fprintf(stdout, "\n%s:\n", fileName);
+       i = list_item(fileName);
+       newline();
+       return (i);
+}
+#endif
+
 extern int ls_main(int argc, char **argv)
 {
        int argi = 1, i;
@@ -543,6 +562,11 @@ extern int ls_main(int argc, char **argv)
                        case 'e':
                                opts |= DISP_FULLTIME;
                                break;
+#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+                       case 'R':
+                               opts |= DISP_RECURSIVE;
+                               break;
 #endif
                        default:
                                goto print_usage_message;
@@ -570,12 +594,25 @@ extern int ls_main(int argc, char **argv)
 #endif
 
        /* process files specified, or current directory if none */
-       i = 0;
-       if (argi == argc)
-               i = list_item(".");
-       while (argi < argc)
-               i |= list_item(argv[argi++]);
-       newline();
+#ifdef BB_FEATURE_LS_RECURSIVE
+       if (opts & DISP_RECURSIVE) {
+               i = 0;
+               if (argi == argc) {
+                       i = recursiveAction(".", TRUE, FALSE, FALSE, NULL, dirAction, NULL);
+               }
+               while (argi < argc) {
+                       i |= recursiveAction(argv[argi++], TRUE, FALSE, FALSE, NULL, dirAction, NULL);
+               }
+       } else 
+#endif
+       {
+               i = 0;
+               if (argi == argc)
+                       i = list_item(".");
+               while (argi < argc)
+                       i |= list_item(argv[argi++]);
+               newline();
+       }
        exit(i);
 
   print_usage_message:
index 7b76e7e79442b2f1dc3b950c7e39fa42b54eac5f..3cd45f7bd1a42301ad60a8893b92b9406a4b3b9c 100644 (file)
@@ -956,7 +956,7 @@ Example:
 
 =item ls
 
-Usage: ls [B<-1acdelnpuxACF>] [filenames...]
+Usage: ls [B<-1acdelnpuxACFR>] [filenames...]
 
 Options:
 
@@ -974,6 +974,7 @@ Options:
        -A      do not list implied . and ..
        -C      list entries by columns
        -F      append indicator (one of */=@|) to entries
+       -R  list subdirectories recursively
 
 -------------------------------
 
@@ -1947,4 +1948,4 @@ Enrique Zanardi <ezanardi@ull.es>
 
 =cut
 
-# $Id: busybox.pod,v 1.35 2000/06/06 16:15:23 andersen Exp $
+# $Id: busybox.pod,v 1.36 2000/06/07 17:28:53 andersen Exp $
diff --git a/ls.c b/ls.c
index 6ab11c4e5f21dcbbea41db921b1026fef4722533..0b1aa6221639305efd01dc05eefceb59acb50b0c 100644 (file)
--- a/ls.c
+++ b/ls.c
@@ -86,8 +86,9 @@
 #define DISP_DOT       8                       /* show . and .. */
 #define DISP_NUMERIC   16              /* numeric uid and gid */
 #define DISP_FULLTIME  32              /* show extended time display */
-#define DIR_NOLIST     64                      /* show directory as itself, not contents */
+#define DIR_NOLIST             64              /* show directory as itself, not contents */
 #define DISP_DIRNAME   128             /* show directory name (for internal use) */
+#define DISP_RECURSIVE 256             /* Do a recursive listing */
 
 #ifndef MAJOR
 #define MAJOR(dev) (((dev)>>8)&0xff)
@@ -448,6 +449,9 @@ static const char ls_usage[] = "ls [-1a"
        "xAC"
 #ifdef BB_FEATURE_LS_FILETYPES
        "F"
+#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+       "R"
 #endif
        "] [filenames...]\n"
 #ifndef BB_FEATURE_TRIVIAL_HELP
@@ -477,9 +481,24 @@ static const char ls_usage[] = "ls [-1a"
 #ifdef BB_FEATURE_LS_FILETYPES
        "\t-F\tappend indicator (one of */=@|) to entries\n"
 #endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+       "\t-R\tlist subdirectories recursively\n"
+#endif
 #endif
        ;
 
+
+#ifdef BB_FEATURE_LS_RECURSIVE
+static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
+{
+       int i;
+       fprintf(stdout, "\n%s:\n", fileName);
+       i = list_item(fileName);
+       newline();
+       return (i);
+}
+#endif
+
 extern int ls_main(int argc, char **argv)
 {
        int argi = 1, i;
@@ -543,6 +562,11 @@ extern int ls_main(int argc, char **argv)
                        case 'e':
                                opts |= DISP_FULLTIME;
                                break;
+#endif
+#ifdef BB_FEATURE_LS_RECURSIVE
+                       case 'R':
+                               opts |= DISP_RECURSIVE;
+                               break;
 #endif
                        default:
                                goto print_usage_message;
@@ -570,12 +594,25 @@ extern int ls_main(int argc, char **argv)
 #endif
 
        /* process files specified, or current directory if none */
-       i = 0;
-       if (argi == argc)
-               i = list_item(".");
-       while (argi < argc)
-               i |= list_item(argv[argi++]);
-       newline();
+#ifdef BB_FEATURE_LS_RECURSIVE
+       if (opts & DISP_RECURSIVE) {
+               i = 0;
+               if (argi == argc) {
+                       i = recursiveAction(".", TRUE, FALSE, FALSE, NULL, dirAction, NULL);
+               }
+               while (argi < argc) {
+                       i |= recursiveAction(argv[argi++], TRUE, FALSE, FALSE, NULL, dirAction, NULL);
+               }
+       } else 
+#endif
+       {
+               i = 0;
+               if (argi == argc)
+                       i = list_item(".");
+               while (argi < argc)
+                       i |= list_item(argv[argi++]);
+               newline();
+       }
        exit(i);
 
   print_usage_message:
diff --git a/mount.c b/mount.c
index ee6c9475ab3923091a614678a35e2939a09fc06e..76f048b1c86c55dfb717b317f104e3d9f7b439aa 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -154,8 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
                        }
                }
 #endif
-               status =
-                       mount(specialfile, dir, filesystemtype, flags, string_flags);
+               status = mount(specialfile, dir, filesystemtype, flags, string_flags);
        }
 
 
@@ -176,6 +175,11 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
                del_loop(specialfile);
        }
 #endif
+
+       if (errno == EPERM) {
+               fatalError("mount: permission denied. Are you root?\n");
+       }
+
        return (FALSE);
 }
 
@@ -307,7 +311,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
                                                  fakeIt, mtab_opts);
        }
 
-       if (status == FALSE && whineOnErrors == TRUE) {
+       if (status == FALSE) {
                if (whineOnErrors == TRUE) {
                        fprintf(stderr, "Mounting %s on %s failed: %s\n",
                                        blockDevice, directory, strerror(errno));
@@ -458,24 +462,19 @@ extern int mount_main(int argc, char **argv)
                        // If the filesystem isn't noauto, 
                        // and isn't swap or nfs, then mount it
                        if ((!strstr(m->mnt_opts, "noauto")) &&
-                               (!strstr(m->mnt_type, "swap")) &&
-                               (!strstr(m->mnt_type, "nfs"))) {
+                                       (!strstr(m->mnt_type, "swap")) &&
+                                       (!strstr(m->mnt_type, "nfs"))) {
                                flags = 0;
                                *string_flags = '\0';
                                parse_mount_options(m->mnt_opts, &flags, string_flags);
-                               /* If the directory is /, try to remount
-                                * with the options specified in fstab */
-                               if (m->mnt_dir[0] == '/' && m->mnt_dir[1] == '\0') {
-                                       flags |= MS_REMOUNT;
-                               }
                                if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
-                                                 flags, string_flags, useMtab, fakeIt,
-                                                 extra_opts, FALSE)
+                                                       flags, string_flags, useMtab, fakeIt,
+                                                       extra_opts, FALSE)==FALSE
                                {
                                        /* Try again, but this time try a remount */
                                        mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
-                                                         flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
-                                                         extra_opts, TRUE);
+                                                       flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
+                                                       extra_opts, TRUE);
                                }
                        }
                }
index 0f8c4f5f349b010aefb2722083d2f8f30deb1d11..83aadd08a3031e2bd72d894f716ea911b50a63f4 100644 (file)
@@ -83,7 +83,7 @@ static void do_em_all()
                exit(FALSE);
        }
        while ((m = getmntent(f)) != NULL) {
-               if (!strstr(m->mnt_type, MNTTYPE_SWAP)) {
+               if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
                        swap_enable_disable(m->mnt_fsname);
                }
        }
index ee6c9475ab3923091a614678a35e2939a09fc06e..76f048b1c86c55dfb717b317f104e3d9f7b439aa 100644 (file)
@@ -154,8 +154,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
                        }
                }
 #endif
-               status =
-                       mount(specialfile, dir, filesystemtype, flags, string_flags);
+               status = mount(specialfile, dir, filesystemtype, flags, string_flags);
        }
 
 
@@ -176,6 +175,11 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
                del_loop(specialfile);
        }
 #endif
+
+       if (errno == EPERM) {
+               fatalError("mount: permission denied. Are you root?\n");
+       }
+
        return (FALSE);
 }
 
@@ -307,7 +311,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
                                                  fakeIt, mtab_opts);
        }
 
-       if (status == FALSE && whineOnErrors == TRUE) {
+       if (status == FALSE) {
                if (whineOnErrors == TRUE) {
                        fprintf(stderr, "Mounting %s on %s failed: %s\n",
                                        blockDevice, directory, strerror(errno));
@@ -458,24 +462,19 @@ extern int mount_main(int argc, char **argv)
                        // If the filesystem isn't noauto, 
                        // and isn't swap or nfs, then mount it
                        if ((!strstr(m->mnt_opts, "noauto")) &&
-                               (!strstr(m->mnt_type, "swap")) &&
-                               (!strstr(m->mnt_type, "nfs"))) {
+                                       (!strstr(m->mnt_type, "swap")) &&
+                                       (!strstr(m->mnt_type, "nfs"))) {
                                flags = 0;
                                *string_flags = '\0';
                                parse_mount_options(m->mnt_opts, &flags, string_flags);
-                               /* If the directory is /, try to remount
-                                * with the options specified in fstab */
-                               if (m->mnt_dir[0] == '/' && m->mnt_dir[1] == '\0') {
-                                       flags |= MS_REMOUNT;
-                               }
                                if (mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
-                                                 flags, string_flags, useMtab, fakeIt,
-                                                 extra_opts, FALSE)
+                                                       flags, string_flags, useMtab, fakeIt,
+                                                       extra_opts, FALSE)==FALSE
                                {
                                        /* Try again, but this time try a remount */
                                        mount_one(m->mnt_fsname, m->mnt_dir, m->mnt_type,
-                                                         flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
-                                                         extra_opts, TRUE);
+                                                       flags|MS_REMOUNT, string_flags, useMtab, fakeIt,
+                                                       extra_opts, TRUE);
                                }
                        }
                }
index 0f8c4f5f349b010aefb2722083d2f8f30deb1d11..83aadd08a3031e2bd72d894f716ea911b50a63f4 100644 (file)
@@ -83,7 +83,7 @@ static void do_em_all()
                exit(FALSE);
        }
        while ((m = getmntent(f)) != NULL) {
-               if (!strstr(m->mnt_type, MNTTYPE_SWAP)) {
+               if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
                        swap_enable_disable(m->mnt_fsname);
                }
        }