]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/drivetype.c
Make PurgeMigrationJob directive name correspond to doc
[bacula/bacula] / bacula / src / tools / drivetype.c
index fde223a4daebf38811a04d4ee31f2363771b73e3..0a630385d3de6c995916fa2fbc605f03751fbee5 100644 (file)
@@ -14,7 +14,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -50,6 +50,8 @@ static void usage()
 "       Print the drive type a given file/directory is on.\n"
 "       The following options are supported:\n"
 "\n"
+"       -l     print local fixed hard drive\n"
+"       -a     display information on all drives\n"
 "       -v     print both path and file system type.\n"
 "       -?     print this message.\n"
 "\n"));
@@ -57,24 +59,54 @@ static void usage()
    exit(1);
 }
 
+int display_drive(char *drive, bool display_local, int verbose)
+{
+   char dt[100];
+   int status = 0;
+
+   if (drivetype(drive, dt, sizeof(dt))) {
+      if (display_local) {      /* in local mode, display only harddrive */
+         if (strcmp(dt, "fixed") == 0) {
+            printf("%s\n", drive);
+         }
+      } else if (verbose) {
+         printf("%s: %s\n", drive, dt);
+      } else {
+         puts(dt);
+      }
+   } else if (!display_local) { /* local mode is used by FileSet scripts */
+      fprintf(stderr, _("%s: unknown\n"), drive);
+      status = 1;
+   }
+   return status;
+}
 
 int
 main (int argc, char *const *argv)
 {
-   char dt[100];
    int verbose = 0;
    int status = 0;
    int ch, i;
+   bool display_local = false;
+   bool display_all = false;
+   char drive='A';
+   char buf[16];
 
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
 
-   while ((ch = getopt(argc, argv, "v?")) != -1) {
+   while ((ch = getopt(argc, argv, "alv?")) != -1) {
       switch (ch) {
          case 'v':
             verbose = 1;
             break;
+         case 'l':
+            display_local = true;
+            break;
+         case 'a':
+            display_all = true;
+            break;
          case '?':
          default:
             usage();
@@ -84,24 +116,23 @@ main (int argc, char *const *argv)
    argc -= optind;
    argv += optind;
 
+   OSDependentInit();
+   if (argc < 1 && display_all) {
+      /* Try all letters */
+      for (drive = 'A'; drive <= 'Z'; drive++) {
+         bsnprintf(buf, sizeof(buf), "%c:/", drive);
+         display_drive(buf, display_local, verbose);
+      }
+      exit(status);
+   }
+
    if (argc < 1) {
       usage();
    }
 
-   OSDependentInit();
    for (i = 0; i < argc; --argc, ++argv) {
-      if (drivetype(*argv, dt, sizeof(dt))) {
-         if (verbose) {
-            printf("%s: %s\n", *argv, dt);
-         } else {
-            puts(dt);
-         }
-      } else {
-         fprintf(stderr, _("%s: unknown\n"), *argv);
-         status = 1;
-      }
+      status += display_drive(*argv, display_local, verbose);
    }
-
    exit(status);
 }