2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Program for determining file system type
23 * Written by Preben 'Peppe' Guldberg, December MMIV
27 #include "findlib/find.h"
33 "Usage: fstype [-v] path ...\n"
35 " Print the file system type for each file/directory argument given.\n"
36 " The following options are supported:\n"
38 " -l print all file system types in mtab.\n"
39 " -m print full entries in mtab.\n"
40 " -v print both path and file system type of each argument.\n"
41 " -? print this message.\n"
53 /* Compare two device types */
54 static int compare_mtab_items(void *item1, void *item2)
56 mtab_item *mtab1, *mtab2;
57 mtab1 = (mtab_item *)item1;
58 mtab2 = (mtab_item *)item2;
59 if (mtab1->dev < mtab2->dev) return -1;
60 if (mtab1->dev > mtab2->dev) return 1;
64 void print_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
65 const char *mountpoint, const char *mntopts,
68 fprintf(stderr, "dev=%p fstype=%s mountpoint=%s mntopts=%s\n",
69 ((void *)st->st_dev), fstype, mountpoint, mntopts);
72 void add_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
73 const char *mountpoint, const char *mntopts,
76 rblist *mtab_list = (rblist *)user_ctx;
77 mtab_item *item, *ritem;
78 int len = strlen(fstype) + 1;
80 item = (mtab_item *)malloc(sizeof(mtab_item) + len);
81 item->dev = (uint64_t)st->st_dev;
82 bstrncpy(item->fstype, fstype, len);
83 //fprintf(stderr, "Add dev=%lx fstype=%s\n", item->dev, item->fstype);
84 ritem = (mtab_item *)mtab_list->insert((void *)item, compare_mtab_items);
86 fprintf(stderr, "Problem!! Returned item not equal added item\n");
88 //fprintf(stderr, "dev=%p fstype=%s mountpoint=%s mntopts=%s\n",
89 // ((void *)st->st_dev), fstype, mountpoint, mntopts);
93 int main (int argc, char *const *argv)
102 setlocale(LC_ALL, "");
103 bindtextdomain("bacula", LOCALEDIR);
104 textdomain("bacula");
106 while ((ch = getopt(argc, argv, "lmv?")) != -1) {
112 mtab = true; /* list mtab */
130 read_mtab(print_mtab_item, NULL);
137 mtab_list = New(rblist());
138 read_mtab(add_mtab_item, mtab_list);
139 fprintf(stderr, "Size of mtab=%d\n", mtab_list->size());
140 foreach_rblist(item, mtab_list) {
141 fprintf(stderr, "Found dev=%lx fstype=%s\n", item->dev, item->fstype);
150 for (i = 0; i < argc; --argc, ++argv) {
152 memset(&ff_pkt, 0, sizeof(ff_pkt));
153 ff_pkt.fname = ff_pkt.link = *argv;
154 if (lstat(ff_pkt.fname, &ff_pkt.statp) != 0) {
155 fprintf(stderr, "lstat of %s failed.\n", ff_pkt.fname);
159 if (fstype(&ff_pkt, fs, sizeof(fs))) {
161 printf("%s: %s\n", *argv, fs);
166 fprintf(stderr, _("%s: unknown file system type\n"), *argv);