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.
8 #endif /* HAVE_CONFIG_H */
15 #ifdef HAVE_SYS_STAT_H
17 #endif /* HAVE_SYS_STAT_H */
19 #include "directory.h"
20 #include "parse_mtab.h"
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.
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))
35 main(int argc, char **argv)
37 char *file_name = "afpd.mtab";
38 struct afpd_mount_table *table = NULL;
41 if (argc >= 3 && strcmp(argv[1], "-f") == 0) {
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",
51 table = afpd_mtab_parse(file_name);
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];
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);
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",
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));