]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/drivetype.c
License cleanups
[bacula/bacula] / bacula / src / tools / drivetype.c
1 /*
2  * Program for determining drive type
3  *
4  *   Written by Robert Nelson, June 2006
5  *
6  */
7 /*
8    Bacula® - The Network Backup Solution
9
10    Copyright (C) 2006-2014 Free Software Foundation Europe e.V.
11
12    The main author of Bacula is Kern Sibbald, with contributions from many
13    others, a complete list can be found in the file AUTHORS.
14
15    You may use this file and others of this release according to the
16    license defined in the LICENSE file, which includes the Affero General
17    Public License, v3.0 ("AGPLv3") and some additional permissions and
18    terms pursuant to its AGPLv3 Section 7.
19
20    Bacula® is a registered trademark of Kern Sibbald.
21 */
22
23 #include "bacula.h"
24 #include "findlib/find.h"
25
26 static void usage()
27 {
28    fprintf(stderr, _(
29 "\n"
30 "Usage: drivetype [-v] path ...\n"
31 "\n"
32 "       Print the drive type a given file/directory is on.\n"
33 "       The following options are supported:\n"
34 "\n"
35 "       -l     print local fixed hard drive\n"
36 "       -a     display information on all drives\n"
37 "       -v     print both path and file system type.\n"
38 "       -?     print this message.\n"
39 "\n"));
40
41    exit(1);
42 }
43
44 int display_drive(char *drive, bool display_local, int verbose)
45 {
46    char dt[100];
47    int status = 0;
48
49    if (drivetype(drive, dt, sizeof(dt))) {
50       if (display_local) {      /* in local mode, display only harddrive */
51          if (strcmp(dt, "fixed") == 0) {
52             printf("%s\n", drive);
53          }
54       } else if (verbose) {
55          printf("%s: %s\n", drive, dt);
56       } else {
57          puts(dt);
58       }
59    } else if (!display_local) { /* local mode is used by FileSet scripts */
60       fprintf(stderr, _("%s: unknown\n"), drive);
61       status = 1;
62    }
63    return status;
64 }
65
66 int
67 main (int argc, char *const *argv)
68 {
69    int verbose = 0;
70    int status = 0;
71    int ch, i;
72    bool display_local = false;
73    bool display_all = false;
74    char drive='A';
75    char buf[16];
76
77    setlocale(LC_ALL, "");
78    bindtextdomain("bacula", LOCALEDIR);
79    textdomain("bacula");
80
81    while ((ch = getopt(argc, argv, "alv?")) != -1) {
82       switch (ch) {
83          case 'v':
84             verbose = 1;
85             break;
86          case 'l':
87             display_local = true;
88             break;
89          case 'a':
90             display_all = true;
91             break;
92          case '?':
93          default:
94             usage();
95
96       }
97    }
98    argc -= optind;
99    argv += optind;
100
101    OSDependentInit();
102
103    if (argc < 1 && display_all) {
104       /* Try all letters */
105       for (drive = 'A'; drive <= 'Z'; drive++) {
106          bsnprintf(buf, sizeof(buf), "%c:/", drive);
107          display_drive(buf, display_local, verbose);
108       }
109       exit(status);
110    }
111
112    if (argc < 1) {
113       usage();
114    }
115
116    for (i = 0; i < argc; --argc, ++argv) {
117       status += display_drive(*argv, display_local, verbose);
118    }
119    exit(status);
120 }