]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/drivetype.c
Fix #1762 about bat version browser performance problem
[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-2006 Free Software Foundation Europe e.V.
13
14    The main author of Bacula is Kern Sibbald, with contributions from
15    many others, a complete list can be found in the file AUTHORS.
16    This program is Free Software; you can redistribute it and/or
17    modify it under the terms of version three of the GNU Affero General Public
18    License as published by the Free Software Foundation and included
19    in the file LICENSE.
20
21    This program is distributed in the hope that it will be useful, but
22    WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24    General Public License for more details.
25
26    You should have received a copy of the GNU Affero General Public License
27    along with this program; if not, write to the Free Software
28    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29    02110-1301, USA.
30
31    Bacula® is a registered trademark of Kern Sibbald.
32    The licensor of Bacula is the Free Software Foundation Europe
33    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34    Switzerland, email:ftf@fsfeurope.org.
35 */
36
37 #include "bacula.h"
38 #include "findlib/find.h"
39
40 /* Dummy functions */
41 int generate_daemon_event(JCR *jcr, const char *event) 
42    { return 1; }
43
44 static void usage()
45 {
46    fprintf(stderr, _(
47 "\n"
48 "Usage: drivetype [-v] path ...\n"
49 "\n"
50 "       Print the drive type a given file/directory is on.\n"
51 "       The following options are supported:\n"
52 "\n"
53 "       -l     print local fixed hard drive\n"
54 "       -a     display information on all drives\n"
55 "       -v     print both path and file system type.\n"
56 "       -?     print this message.\n"
57 "\n"));
58
59    exit(1);
60 }
61
62 int display_drive(char *drive, bool display_local, int verbose)
63 {
64    char dt[100];
65    int status = 0;
66
67    if (drivetype(drive, dt, sizeof(dt))) {
68       if (display_local) {      /* in local mode, display only harddrive */
69          if (strcmp(dt, "fixed") == 0) {
70             printf("%s\n", drive);
71          }
72       } else if (verbose) {
73          printf("%s: %s\n", drive, dt);
74       } else {
75          puts(dt);
76       }
77    } else if (!display_local) { /* local mode is used by FileSet scripts */
78       fprintf(stderr, _("%s: unknown\n"), drive);
79       status = 1;
80    }
81    return status;
82 }
83
84 int
85 main (int argc, char *const *argv)
86 {
87    int verbose = 0;
88    int status = 0;
89    int ch, i;
90    bool display_local = false;
91    bool display_all = false;
92    char drive='A';
93    char buf[16];
94
95    setlocale(LC_ALL, "");
96    bindtextdomain("bacula", LOCALEDIR);
97    textdomain("bacula");
98
99    while ((ch = getopt(argc, argv, "alv?")) != -1) {
100       switch (ch) {
101          case 'v':
102             verbose = 1;
103             break;
104          case 'l':
105             display_local = true;
106             break;
107          case 'a':
108             display_all = true;
109             break;
110          case '?':
111          default:
112             usage();
113
114       }
115    }
116    argc -= optind;
117    argv += optind;
118
119    OSDependentInit();
120  
121    if (argc < 1 && display_all) {
122       /* Try all letters */
123       for (drive = 'A'; drive <= 'Z'; drive++) {
124          bsnprintf(buf, sizeof(buf), "%c:/", drive);
125          display_drive(buf, display_local, verbose);
126       }
127       exit(status);
128    }
129
130    if (argc < 1) {
131       usage();
132    }
133
134    for (i = 0; i < argc; --argc, ++argv) {
135       status += display_drive(*argv, display_local, verbose);
136    }
137    exit(status);
138 }