]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/fstype.c
Backport from BEE
[bacula/bacula] / bacula / src / tools / fstype.c
1 /*
2  * Program for determining file system type
3  *
4  *   Written by Preben 'Peppe' Guldberg, December MMIV
5  *
6  *   Version $Id$
7  *
8  */
9 /*
10    Bacula® - The Network Backup Solution
11
12    Copyright (C) 2004-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 #include "lib/mntent_cache.h"
28
29 /* Dummy functions */
30 int generate_daemon_event(JCR *jcr, const char *event)
31    { return 1; }
32
33 static void usage()
34 {
35    fprintf(stderr, _(
36 "\n"
37 "Usage: fstype [-v] path ...\n"
38 "\n"
39 "       Print the file system type a given file/directory is on.\n"
40 "       The following options are supported:\n"
41 "\n"
42 "       -v     print both path and file system type.\n"
43 "       -?     print this message.\n"
44 "\n"));
45
46    exit(1);
47 }
48
49
50 int
51 main (int argc, char *const *argv)
52 {
53    char fs[1000];
54    int verbose = 0;
55    int status = 0;
56    int ch, i;
57
58    setlocale(LC_ALL, "");
59    bindtextdomain("bacula", LOCALEDIR);
60    textdomain("bacula");
61
62    while ((ch = getopt(argc, argv, "v?")) != -1) {
63       switch (ch) {
64          case 'v':
65             verbose = 1;
66             break;
67          case '?':
68          default:
69             usage();
70
71       }
72    }
73    argc -= optind;
74    argv += optind;
75
76    if (argc < 1) {
77       usage();
78    }
79
80    OSDependentInit();
81
82    for (i = 0; i < argc; --argc, ++argv) {
83       if (fstype(*argv, fs, sizeof(fs))) {
84          if (verbose) {
85             printf("%s: %s\n", *argv, fs);
86          } else {
87             puts(fs);
88          }
89       } else {
90          fprintf(stderr, _("%s: unknown\n"), *argv);
91          status = 1;
92       }
93    }
94
95    flush_mntent_cache();
96
97    exit(status);
98 }