]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tools/fstype.c
Integrate Preben 'Peppe' Guldberg <peppe@wielders.org>'s
[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 /*
11    Copyright (C) 2004 Kern Sibbald
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"
31 #include "findlib/find.h"
32
33 static void usage()
34 {
35    fprintf(stderr, _(
36 "\n"
37 "Usage: fstype [-d debug_level] 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    while ((ch = getopt(argc, argv, "v?")) != -1) {
59       switch (ch) {
60          case 'v':
61             verbose = 1;
62             break;
63          case '?':
64          default:
65             usage();
66
67       }
68    }
69    argc -= optind;
70    argv += optind;
71
72    if (argc < 1) {
73       usage();
74    }
75
76    for (i = 0; i < argc; --argc, ++argv) {
77       if (fstype(*argv, fs, sizeof(fs))) {
78          if (verbose) {
79             printf("%s: %s\n", *argv, fs);
80          } else {
81             puts(fs);
82          }
83       } else {
84          fprintf(stderr, "%s: unknown\n", *argv);
85          status = 1;
86       }
87    }
88
89    exit(status);
90 }