2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Program for determining file system type
22 * Written by Preben 'Peppe' Guldberg, December MMIV
26 #include "findlib/find.h"
32 "Usage: fstype [-v] path ...\n"
34 " Print the file system type for each file/directory argument given.\n"
35 " The following options are supported:\n"
37 " -l print all file system types in mtab.\n"
38 " -m print full entries in mtab.\n"
39 " -v print both path and file system type of each argument.\n"
40 " -? print this message.\n"
52 /* Compare two device types */
53 static int compare_mtab_items(void *item1, void *item2)
55 mtab_item *mtab1, *mtab2;
56 mtab1 = (mtab_item *)item1;
57 mtab2 = (mtab_item *)item2;
58 if (mtab1->dev < mtab2->dev) return -1;
59 if (mtab1->dev > mtab2->dev) return 1;
63 void print_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
64 const char *mountpoint, const char *mntopts,
67 fprintf(stderr, "dev=%p fstype=%s mountpoint=%s mntopts=%s\n",
68 ((void *)st->st_dev), fstype, mountpoint, mntopts);
71 static void add_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
72 const char *mountpoint, const char *mntopts,
75 rblist *mtab_list = (rblist *)user_ctx;
76 mtab_item *item, *ritem;
77 int len = strlen(fstype) + 1;
79 item = (mtab_item *)malloc(sizeof(mtab_item) + len);
80 item->dev = (uint64_t)st->st_dev;
81 bstrncpy(item->fstype, fstype, len);
82 //fprintf(stderr, "Add dev=%lx fstype=%s\n", item->dev, item->fstype);
83 ritem = (mtab_item *)mtab_list->insert((void *)item, compare_mtab_items);
85 fprintf(stderr, "Problem!! Returned item not equal added item\n");
87 //fprintf(stderr, "dev=%p fstype=%s mountpoint=%s mntopts=%s\n",
88 // ((void *)st->st_dev), fstype, mountpoint, mntopts);
92 int main (int argc, char *const *argv)
101 setlocale(LC_ALL, "");
102 bindtextdomain("bacula", LOCALEDIR);
103 textdomain("bacula");
105 while ((ch = getopt(argc, argv, "lmv?")) != -1) {
111 mtab = true; /* list mtab */
129 read_mtab(print_mtab_item, NULL);
136 mtab_list = New(rblist());
137 read_mtab(add_mtab_item, mtab_list);
138 fprintf(stderr, "Size of mtab=%d\n", mtab_list->size());
139 foreach_rblist(item, mtab_list) {
140 fprintf(stderr, "Found dev=%lx fstype=%s\n", item->dev, item->fstype);
149 for (i = 0; i < argc; --argc, ++argv) {
151 memset(&ff_pkt, 0, sizeof(ff_pkt));
152 ff_pkt.fname = ff_pkt.link = *argv;
153 if (lstat(ff_pkt.fname, &ff_pkt.statp) != 0) {
154 fprintf(stderr, "lstat of %s failed.\n", ff_pkt.fname);
158 if (fstype(&ff_pkt, fs, sizeof(fs))) {
160 printf("%s: %s\n", *argv, fs);
165 fprintf(stderr, _("%s: unknown file system type\n"), *argv);