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