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