]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/drivetype.c
Backport from BEE
[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 /* Dummy functions */
29 int generate_daemon_event(JCR *jcr, const char *event)
30    { return 1; }
31
32 static void usage()
33 {
34    fprintf(stderr, _(
35 "\n"
36 "Usage: drivetype [-v] path ...\n"
37 "\n"
38 "       Print the drive type a given file/directory is on.\n"
39 "       The following options are supported:\n"
40 "\n"
41 "       -l     print local fixed hard drive\n"
42 "       -a     display information on all drives\n"
43 "       -v     print both path and file system type.\n"
44 "       -?     print this message.\n"
45 "\n"));
46
47    exit(1);
48 }
49
50 int display_drive(char *drive, bool display_local, int verbose)
51 {
52    char dt[100];
53    int status = 0;
54
55    if (drivetype(drive, dt, sizeof(dt))) {
56       if (display_local) {      /* in local mode, display only harddrive */
57          if (strcmp(dt, "fixed") == 0) {
58             printf("%s\n", drive);
59          }
60       } else if (verbose) {
61          printf("%s: %s\n", drive, dt);
62       } else {
63          puts(dt);
64       }
65    } else if (!display_local) { /* local mode is used by FileSet scripts */
66       fprintf(stderr, _("%s: unknown\n"), drive);
67       status = 1;
68    }
69    return status;
70 }
71
72 int
73 main (int argc, char *const *argv)
74 {
75    int verbose = 0;
76    int status = 0;
77    int ch, i;
78    bool display_local = false;
79    bool display_all = false;
80    char drive='A';
81    char buf[16];
82
83    setlocale(LC_ALL, "");
84    bindtextdomain("bacula", LOCALEDIR);
85    textdomain("bacula");
86
87    while ((ch = getopt(argc, argv, "alv?")) != -1) {
88       switch (ch) {
89          case 'v':
90             verbose = 1;
91             break;
92          case 'l':
93             display_local = true;
94             break;
95          case 'a':
96             display_all = true;
97             break;
98          case '?':
99          default:
100             usage();
101
102       }
103    }
104    argc -= optind;
105    argv += optind;
106
107    OSDependentInit();
108
109    if (argc < 1 && display_all) {
110       /* Try all letters */
111       for (drive = 'A'; drive <= 'Z'; drive++) {
112          bsnprintf(buf, sizeof(buf), "%c:/", drive);
113          display_drive(buf, display_local, verbose);
114       }
115       exit(status);
116    }
117
118    if (argc < 1) {
119       usage();
120    }
121
122    for (i = 0; i < argc; --argc, ++argv) {
123       status += display_drive(*argv, display_local, verbose);
124    }
125    exit(status);
126 }