]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/test_parse_mtab.c
Warning fixes.
[netatalk.git] / etc / afpd / test_parse_mtab.c
1 /*
2  * $Id: test_parse_mtab.c,v 1.3 2001-07-31 19:50:14 srittau Exp $
3  * test driver for the afpd_mtab_parse fn.  -- rgr, 9-Apr-01.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif /* HAVE_CONFIG_H */
9
10 #include <stdio.h>
11 #include <errno.h>
12 #include <string.h>
13 #include <stdlib.h>
14
15 #ifdef HAVE_SYS_STAT_H
16 #include <sys/stat.h>
17 #endif /* HAVE_SYS_STAT_H */
18
19 #include "directory.h"
20 #include "parse_mtab.h"
21
22 /* hack.  etc/afpd/directory.h would need to be patched accordingly.  this
23    version ignores the filep stuff.  based on the comment starting around
24    line 200 in etc/afpd/file.c (search for "fucking mess"), this may be OK.
25    */
26 #ifdef CNID
27 #undef CNID
28 #endif /* ! CNID */
29
30 /* keep-filep version.  must also decrement AFPD_MTAB_DEV_AND_INODE_BITS.  */
31 /* #define CNID(pst, filep)     (afpd_st_cnid(pst) | CNID_FILE(filep)) */
32 #define CNID(pst, filep)        (afpd_st_cnid(pst))
33
34 int
35 main(int argc, char **argv)
36 {
37   char *file_name = "afpd.mtab";
38   struct afpd_mount_table *table = NULL;
39   int arg = 1;
40
41   if (argc >= 3 && strcmp(argv[1], "-f") == 0) {
42     file_name = argv[2];
43     arg += 2;
44   }
45   if (arg < argc && argv[arg][0] == '-') {
46     /* either they don't understand, or they must be asking for help anyway. */
47     fprintf(stderr, "Usage:  %s [-f file-name] [file . . . ]\n",
48             argv[0]);
49     exit(1);
50   }
51   table = afpd_mtab_parse(file_name);
52   if (table != NULL) {
53     struct stat st;
54     int id, count = 0;
55
56     fprintf(stderr, "File %s:  Field width %d, shift %d.\n",
57             file_name, table->bits, table->shift);
58     for (id = 0; id < table->size; id++) {
59       struct afpd_mtab_entry *entry = table->table[id];
60
61       if (entry != NULL) {
62         fprintf(stderr, "  Id %d -> device %s (%d,%d) on %s -> bits 0x%08x.\n",
63                 id, entry->device, entry->dev_major, entry->dev_minor,
64                 entry->mount_point, entry->bit_value);
65         count++;
66       }
67     }
68     fprintf(stderr, "%d entries used out of a maximum of %d (1..%d).\n",
69             count, table->size-1, table->size-1);
70     for (; arg < argc; arg++) {
71       if (lstat(argv[arg], &st) != 0) {
72         fprintf(stderr, "Can't lstat '%s':  code %d\n",
73                 argv[arg], errno);
74       }
75       else {
76         fprintf(stderr, "File %s, device (%d,%d), inode %ld, CNID 0x%08x.\n",
77                 argv[arg], major(st.st_dev), minor(st.st_dev), st.st_ino,
78                 CNID(&st, S_ISDIR(st.st_mode) ? 1 : 0));
79       }
80     }
81   }
82   return(0);
83 }