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