bozo: Introduce bnode_Wait()
[openafs.git] / src / vol / vol-info.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11    System:              VICE-TWO
12    Module:              vol-info.c
13    Institution: The Information Technology Center, Carnegie-Mellon University
14
15    */
16
17 #include <afsconfig.h>
18 #include <afs/param.h>
19
20 #include <roken.h>
21
22 #include <ctype.h>
23
24 #ifdef HAVE_SYS_FILE_H
25 #include <sys/file.h>
26 #endif
27
28 #include <afs/cmd.h>
29 #include <afs/dir.h>
30 #include <afs/afsint.h>
31 #include <afs/errors.h>
32 #include <afs/acl.h>
33 #include <afs/prs_fs.h>
34 #include <rx/rx_queue.h>
35
36 #include "nfs.h"
37 #include "lock.h"
38 #include "ihandle.h"
39 #include "vnode.h"
40 #include "volume.h"
41 #include "partition.h"
42 #include "salvage.h"
43 #include "daemon_com_inline.h"
44 #include "fssync_inline.h"
45 #include "vol-info.h"
46
47 static int volinfo_init = 0;
48 static const char *progname = "";
49 static const char *PLACEHOLDER = "-";
50
51
52 /* Numeric column type ids */
53 typedef enum columnType {
54 #define c(x) col_##x,
55     VOLSCAN_COLUMNS
56 #undef c
57     max_column_type
58 } columnType;
59
60 struct columnName {
61     columnType type;
62     const char *name;
63 };
64
65 /* Table of id:name tuples of possible columns. */
66 struct columnName ColumnName[] = {
67 #define c(x) { col_##x, #x },
68     VOLSCAN_COLUMNS
69 #undef c
70     {max_column_type, NULL}
71 };
72
73
74 /* VnodeDetails union descriminator */
75 typedef enum {
76     VNODE_U_NONE,
77     VNODE_U_MOUNT,
78     VNODE_U_SYMLINK,
79     VNODE_U_POS_ACCESS,
80     VNODE_U_NEG_ACCESS
81 } vnode_details_u_t;
82
83 struct VnodeDetails {
84     Volume *vp;
85     VnodeClass class;
86     VnodeDiskObject *vnode;
87     VnodeId vnodeNumber;
88     afs_foff_t offset;
89     int index;
90     char *path;
91     vnode_details_u_t t;
92     union {
93         struct {
94             char type;
95             char *cell;
96             char *vol;
97         } mnt;
98         char *target;
99         struct acl_accessEntry *access;
100     } u;
101 };
102
103
104 static int NeedDirIndex;        /**< Large vnode index handle is needed for path lookups. */
105 static FdHandle_t *DirIndexFd = NULL; /**< Current large vnode index handle for path lookups. */
106
107 static int NumOutputColumns = 0;
108 static columnType OutputColumn[max_column_type];
109
110 /**
111  * Volume size running totals
112  */
113 struct sizeTotals {
114     afs_uint64 diskused_k;      /**< volume size from disk data file, in kilobytes */
115     afs_uint64 auxsize;         /**< size of header files, in bytes  */
116     afs_uint64 auxsize_k;       /**< size of header files, in kilobytes */
117     afs_uint64 vnodesize;       /**< size of the large and small vnodes, in bytes */
118     afs_uint64 vnodesize_k;     /**< size of the large and small vnodes, in kilobytes */
119     afs_uint64 size_k;          /**< size of headers and vnodes, in kilobytes */
120 };
121
122 static struct sizeTotals volumeTotals = { 0, 0, 0, 0, 0, 0 };
123 static struct sizeTotals partitionTotals = { 0, 0, 0, 0, 0, 0 };
124 static struct sizeTotals serverTotals = { 0, 0, 0, 0, 0, 0 };
125 static int PrintingVolumeSizes = 0;     /*print volume size lines */
126
127 /**
128  * List of procedures to call when scanning vnodes.
129  */
130 struct VnodeScanProc {
131     struct opr_queue link;
132     const char *heading;
133     void (*proc) (struct VolInfoOpt *opt, struct VnodeDetails * vdp);
134 };
135 static struct opr_queue VnodeScanLists[nVNODECLASSES];
136
137 /* Forward Declarations */
138 static void PrintHeader(Volume * vp);
139 static void HandleAllPart(struct VolInfoOpt *opt);
140 static void HandlePart(struct VolInfoOpt *opt, struct DiskPartition64 *partP);
141 static void HandleVolume(struct VolInfoOpt *opt, struct DiskPartition64 *partP, char *name);
142 static struct DiskPartition64 *FindCurrentPartition(void);
143 static Volume *AttachVolume(struct VolInfoOpt *opt, struct DiskPartition64 *dp, char *volname,
144                      struct VolumeHeader *header);
145 static void HandleVnodes(struct VolInfoOpt *opt, Volume * vp, VnodeClass class);
146 static void PrintColumnHeading(struct VolInfoOpt *opt);
147 static void PrintColumns(struct VolInfoOpt *opt, struct VnodeDetails *vdp, const char *desc);
148
149 /* externs */
150 extern void SetSalvageDirHandle(DirHandle * dir, afs_int32 volume,
151                                 Device device, Inode inode,
152                                 int *volumeChanged);
153 extern void FidZap(DirHandle * file);
154
155 /**
156  * Format time as a timestamp string
157  *
158  * @param[in] date  time value to format
159  *
160  * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
161  *
162  * @note A static array of 8 strings are stored by this
163  *       function. The array slots are overwritten, so the
164  *       caller must not reference the returned string after
165  *       seven additional calls to this function.
166  */
167 static char *
168 date(time_t date)
169 {
170 #define MAX_DATE_RESULT 100
171     static char results[8][MAX_DATE_RESULT];
172     static int next;
173     struct tm *tm = localtime(&date);
174     char buf[32];
175
176     (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm);   /* NT does not have %T */
177     snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT,
178              "%lu (%s)", (unsigned long)date, buf);
179     return results[next];
180 }
181
182 #ifdef AFS_NT40_ENV
183 /**
184  * Format file time as a timestamp string
185  *
186  * @param[in] ft  file time
187  *
188  * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
189  *
190  * @note A static array of 8 strings are stored by this
191  *       function. The array slots are overwritten, so the
192  *       caller must not reference the returned string after
193  *       seven additional calls to this function.
194  */
195 static char *
196 NT_date(FILETIME * ft)
197 {
198     static char result[8][64];
199     static int next = 0;
200     SYSTEMTIME st;
201     FILETIME lft;
202
203     if (!FileTimeToLocalFileTime(ft, &lft)
204         || !FileTimeToSystemTime(&lft, &st)) {
205         fprintf(stderr, "%s: Time conversion failed.\n", progname);
206         exit(1);
207     }
208     sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
209             st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
210     return result[next];
211 }
212 #endif
213
214 /**
215  * Add vnode size to the running volume totals.
216  *
217  * @param[in]  vdp   vnode details object
218  *
219  * @return none
220  */
221 void
222 volinfo_AddVnodeToSizeTotals(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
223 {
224     afs_fsize_t fileLength;
225
226     VNDISK_GET_LEN(fileLength, vdp->vnode);
227     if (fileLength > 0) {
228         volumeTotals.vnodesize += fileLength;
229         volumeTotals.vnodesize_k += fileLength / 1024;
230     }
231 }
232
233 /**
234  * Print the volume size table heading line, if needed.
235  *
236  * @return none
237  */
238 static void
239 PrintVolumeSizeHeading(void)
240 {
241     if (!PrintingVolumeSizes) {
242         printf
243             ("Volume-Id\t  Volsize  Auxsize Inodesize  AVolsize SizeDiff                (VolName)\n");
244         PrintingVolumeSizes = 1;
245     }
246 }
247
248 /**
249  * Accumulate totals.
250  *
251  * @return 0
252  */
253 static void
254 AddSizeTotals(struct sizeTotals *a, struct sizeTotals *b)
255 {
256     a->diskused_k += b->diskused_k;
257     a->auxsize += b->auxsize;
258     a->auxsize_k += b->auxsize_k;
259     a->vnodesize += b->vnodesize;
260     a->vnodesize_k += b->vnodesize_k;
261     a->size_k += b->size_k;
262 }
263
264 /**
265  * Print the sizes for a volume.
266  *
267  * @return none
268  */
269 static void
270 PrintVolumeSizes(Volume * vp)
271 {
272     afs_int64 diff_k = volumeTotals.size_k - volumeTotals.diskused_k;
273
274     PrintVolumeSizeHeading();
275     printf("%" AFS_VOLID_FMT "\t%9llu%9llu%10llu%10llu%9lld\t%24s\n",
276            afs_printable_VolumeId_lu(V_id(vp)),
277            volumeTotals.diskused_k,
278            volumeTotals.auxsize_k, volumeTotals.vnodesize_k,
279            volumeTotals.size_k, diff_k, V_name(vp));
280 }
281
282 /**
283  * Print the size totals for the partition.
284  *
285  * @return none
286  */
287 static void
288 PrintPartitionTotals(afs_uint64 nvols)
289 {
290     afs_int64 diff_k = partitionTotals.size_k - partitionTotals.diskused_k;
291
292     PrintVolumeSizeHeading();
293     printf("\nPart Totals  %12llu%9llu%10llu%10llu%9lld (%llu volumes)\n\n",
294            partitionTotals.diskused_k, partitionTotals.auxsize,
295            partitionTotals.vnodesize, partitionTotals.size_k, diff_k, nvols);
296     PrintingVolumeSizes = 0;
297 }
298
299 /**
300  * Print the size totals for all the partitions.
301  *
302  * @return none
303  */
304 static void
305 PrintServerTotals(void)
306 {
307     afs_int64 diff_k = serverTotals.size_k - serverTotals.diskused_k;
308
309     printf("\nServer Totals%12lld%9lld%10lld%10lld%9lld\n",
310            serverTotals.diskused_k, serverTotals.auxsize,
311            serverTotals.vnodesize, serverTotals.size_k, diff_k);
312 }
313
314 /**
315  * Read a volume header file
316  *
317  * @param[in] ih        ihandle of the header file
318  * @param[in] to        destination
319  * @param[in] size      expected header size
320  * @param[in] magic     expected header magic number
321  * @param[in] version   expected header version number
322  *
323  * @return error code
324  *   @retval 0 success
325  *   @retval -1 failed to read file
326  */
327 static int
328 ReadHdr1(struct VolInfoOpt *opt, IHandle_t * ih, char *to, afs_sfsize_t size,
329          u_int magic, u_int version)
330 {
331     struct versionStamp *vsn;
332     int bad = 0;
333     int code;
334     afs_ino_str_t inode_str;
335
336     vsn = (struct versionStamp *)to;
337
338     code = IH_IREAD(ih, 0, to, size);
339     if (code != size)
340         return -1;
341
342     if (vsn->magic != magic) {
343         bad++;
344         fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
345                 progname, PrintInode(inode_str, ih->ih_ino), vsn->magic, magic);
346     }
347
348     /* Check is conditional, in case caller wants to inspect version himself */
349     if (version && vsn->version != version) {
350         bad++;
351         fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
352                 progname,
353                 PrintInode(inode_str, ih->ih_ino), vsn->version, version);
354     }
355     if (bad && opt->fixHeader) {
356         vsn->magic = magic;
357         vsn->version = version;
358         printf("Special index inode %s has a bad header. Reconstructing...\n",
359                PrintInode(inode_str, ih->ih_ino));
360         code = IH_IWRITE(ih, 0, to, size);
361         if (code != size) {
362             fprintf(stderr,
363                     "%s: Write failed for inode %s; header left in damaged state\n",
364                     progname, PrintInode(inode_str, ih->ih_ino));
365         }
366     }
367     if (!bad && opt->dumpInfo) {
368         printf("Inode %s: Good magic %x and version %x\n",
369                PrintInode(inode_str, ih->ih_ino), magic, version);
370     }
371     return 0;
372 }
373
374 /**
375  * Simplified attach volume
376  *
377  * param[in] dp       vice disk partition object
378  * param[in] volname  volume header file name
379  * param[in] header   volume header object
380  *
381  * @return volume object or null on error
382  */
383 static Volume *
384 AttachVolume(struct VolInfoOpt *opt, struct DiskPartition64 *dp,
385              char *volname, struct VolumeHeader *header)
386 {
387     Volume *vp;
388     afs_int32 ec = 0;
389
390     if (opt->checkout) {
391         afs_int32 code;
392         SYNC_response response;
393         VolumeId volid = header->id;
394
395         memset(&response, 0, sizeof(response));
396         code =
397             FSYNC_VolOp(volid, dp->name, FSYNC_VOL_NEEDVOLUME, V_DUMP,
398                         &response);
399         if (code != SYNC_OK) {
400             if (response.hdr.reason == FSYNC_SALVAGE) {
401                 fprintf(stderr,
402                         "%s: file server says volume %lu is salvaging.\n",
403                         progname, afs_printable_uint32_lu(volid));
404                 return NULL;
405             } else {
406                 fprintf(stderr,
407                         "%s: attach of volume %lu denied by file server.\n",
408                         progname, afs_printable_uint32_lu(volid));
409                 return NULL;
410             }
411         }
412     }
413
414     vp = (Volume *) calloc(1, sizeof(Volume));
415     if (!vp) {
416         fprintf(stderr, "%s: Failed to allocate volume object.\n", progname);
417         return NULL;
418     }
419     vp->specialStatus = 0;
420     vp->device = dp->device;
421     vp->partition = dp;
422     IH_INIT(vp->vnodeIndex[vLarge].handle, dp->device, header->parent,
423             header->largeVnodeIndex);
424     IH_INIT(vp->vnodeIndex[vSmall].handle, dp->device, header->parent,
425             header->smallVnodeIndex);
426     IH_INIT(vp->diskDataHandle, dp->device, header->parent,
427             header->volumeInfo);
428     IH_INIT(V_linkHandle(vp), dp->device, header->parent, header->linkTable);
429     vp->cacheCheck = 0;         /* XXXX */
430     vp->shuttingDown = 0;
431     vp->goingOffline = 0;
432     vp->nUsers = 1;
433     vp->header = calloc(1, sizeof(*vp->header));
434     if (!vp->header) {
435         fprintf(stderr, "%s: Failed to allocate volume header.\n", progname);
436         free(vp);
437         return NULL;
438     }
439     ec = ReadHdr1(opt, V_diskDataHandle(vp), (char *)&V_disk(vp),
440                   sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
441     if (!ec) {
442         struct IndexFileHeader iHead;
443         ec = ReadHdr1(opt, vp->vnodeIndex[vSmall].handle, (char *)&iHead,
444                       sizeof(iHead), SMALLINDEXMAGIC, SMALLINDEXVERSION);
445     }
446     if (!ec) {
447         struct IndexFileHeader iHead;
448         ec = ReadHdr1(opt, vp->vnodeIndex[vLarge].handle, (char *)&iHead,
449                       sizeof(iHead), LARGEINDEXMAGIC, LARGEINDEXVERSION);
450     }
451 #ifdef AFS_NAMEI_ENV
452     if (!ec) {
453         struct versionStamp stamp;
454         ec = ReadHdr1(opt, V_linkHandle(vp), (char *)&stamp, sizeof(stamp),
455                       LINKTABLEMAGIC, LINKTABLEVERSION);
456     }
457 #endif
458     if (ec)
459         return (Volume *) 0;
460     return vp;
461 }
462
463 /**
464  * Simplified detach volume
465  *
466  * param[in] vp       volume object from AttachVolume
467  *
468  * @return none
469  */
470 static void
471 DetachVolume(struct VolInfoOpt *opt, Volume * vp)
472 {
473     if (opt->checkout) {
474         afs_int32 code;
475         SYNC_response response;
476         memset(&response, 0, sizeof(response));
477
478         code = FSYNC_VolOp(V_id(vp), V_partition(vp)->name,
479                            FSYNC_VOL_ON, FSYNC_WHATEVER, &response);
480         if (code != SYNC_OK) {
481             fprintf(stderr, "%s: FSSYNC error %d (%s)\n", progname, code,
482                     SYNC_res2string(code));
483             fprintf(stderr, "%s:  protocol response code was %d (%s)\n",
484                     progname, response.hdr.response,
485                     SYNC_res2string(response.hdr.response));
486             fprintf(stderr, "%s:  protocol reason code was %d (%s)\n",
487                     progname, response.hdr.reason,
488                     FSYNC_reason2string(response.hdr.reason));
489         }
490     }
491
492     IH_RELEASE(vp->vnodeIndex[vLarge].handle);
493     IH_RELEASE(vp->vnodeIndex[vSmall].handle);
494     IH_RELEASE(vp->diskDataHandle);
495     IH_RELEASE(V_linkHandle(vp));
496     free(vp->header);
497     free(vp);
498 }
499
500 /**
501  * Convert the partition device number into a partition name.
502  *
503  * @param[in]   partId      partition number, 0 to 254
504  * @param[out]  partName    buffer to hold partition name (e.g. /vicepa)
505  * @param[in]   partNameSize    size of partName buffer
506  *
507  * @return status
508  *   @retval 0 success
509  *   @retval -1 error, partId is out of range
510  *   @retval -2 error, partition name exceeds partNameSize
511  */
512 static int
513 GetPartitionName(afs_uint32 partId, char *partName, afs_size_t partNameSize)
514 {
515     const afs_uint32 OLD_NUM_DEVICES = 26;      /* a..z */
516
517     if (partId < OLD_NUM_DEVICES) {
518         if (partNameSize < 8) {
519             return -2;
520         }
521         strlcpy(partName, "/vicep", partNameSize);
522         partName[6] = partId + 'a';
523         partName[7] = '\0';
524         return 0;
525     }
526     if (partId < VOLMAXPARTS) {
527         if (partNameSize < 9) {
528             return -2;
529         }
530         strlcpy(partName, "/vicep", partNameSize);
531         partId -= OLD_NUM_DEVICES;
532         partName[6] = 'a' + (partId / OLD_NUM_DEVICES);
533         partName[7] = 'a' + (partId % OLD_NUM_DEVICES);
534         partName[8] = '\0';
535         return 0;
536     }
537     return -1;
538 }
539
540 /**
541  * Scan the volumes in the partitions
542  *
543  * Scan the specified volume in the specified partition if both
544  * are given. Scan all the volumes in the specified partition if
545  * only the partition is given.  If neither a partition nor volume
546  * is given, scan all the volumes in all the partitions.  If only
547  * the volume is given, attempt to find it in the current working
548  * directory.
549  *
550  * @param[in] partNameOrId   partition name or id to be scannned
551  * @param[in] volumeId       volume id to be scanned
552  *
553  * @return 0 if successful
554  */
555 int
556 volinfo_ScanPartitions(struct VolInfoOpt *opt, char *partNameOrId, VolumeId volumeId)
557 {
558     int err = 0;
559     char partName[64] = "";
560     struct DiskPartition64 *partP = NULL;
561
562     if (opt->checkout) {
563         if (!FSYNC_clientInit()) {
564             fprintf(stderr, "%s: Failed to connect to fileserver.\n",
565                     progname);
566             return 1;
567         }
568     }
569
570
571     /* Allow user to specify partition by name or id. */
572     if (partNameOrId) {
573         afs_uint32 partId = volutil_GetPartitionID(partNameOrId);
574         if (partId == -1) {
575             fprintf(stderr, "%s: Could not parse '%s' as a partition name.\n",
576                     progname, partNameOrId);
577             err = 1;
578             goto cleanup;
579         }
580         if (GetPartitionName(partId, partName, sizeof(partName))) {
581             fprintf(stderr,
582                     "%s: Could not format '%s' as a partition name.\n",
583                     progname, partNameOrId);
584             err = 1;
585             goto cleanup;
586         }
587     }
588
589     err = VAttachPartitions();
590     if (err) {
591         fprintf(stderr, "%s: %d partitions had errors during attach.\n",
592                 progname, err);
593         err = 1;
594         goto cleanup;
595     }
596
597     if (partName[0]) {
598         partP = VGetPartition(partName, 0);
599         if (!partP) {
600             fprintf(stderr,
601                     "%s: %s is not an AFS partition name on this server.\n",
602                     progname, partName);
603             err = 1;
604             goto cleanup;
605         }
606     }
607
608     if (!volumeId) {
609         if (opt->printHeading) {
610             PrintColumnHeading(opt);
611         }
612         if (!partP) {
613             HandleAllPart(opt);
614         } else {
615             HandlePart(opt, partP);
616         }
617     } else {
618         char name1[128];
619
620         if (!partP) {
621             partP = FindCurrentPartition();
622             if (!partP) {
623                 fprintf(stderr,
624                         "%s: Current partition is not a vice partition.\n",
625                         progname);
626                 err = 1;
627                 goto cleanup;
628             }
629         }
630         snprintf(name1, sizeof name1, VFORMAT,
631                  afs_printable_VolumeId_lu(volumeId));
632         if (opt->printHeading) {
633             PrintColumnHeading(opt);
634         }
635         HandleVolume(opt, partP, name1);
636     }
637
638   cleanup:
639     if (opt->checkout) {
640         FSYNC_clientFinis();
641     }
642     return err;
643 }
644
645 /**
646  * Add a vnode scanning procedure
647  *
648  * @param[in]   class   vnode class for this handler
649  * @param[in]   proc    handler proc to be called by HandleVnodes
650  * @param[in]   heading optional string to pring before scanning vnodes
651  *
652  * @return none
653  */
654 void
655 volinfo_AddVnodeHandler(int vnodeClass,
656                 void (*proc) (struct VolInfoOpt * opt,
657                               struct VnodeDetails * vdp), const char *heading)
658 {
659     struct VnodeScanProc *entry = malloc(sizeof(struct VnodeScanProc));
660     entry->proc = proc;
661     entry->heading = heading;
662     opr_queue_Append(&VnodeScanLists[vnodeClass], (struct opr_queue *)entry);
663 }
664
665 /**
666  * Initialize the vol-info module.
667  */
668 int
669 volinfo_Init(const char *aprogname)
670 {
671     if (!volinfo_init) {
672         progname = aprogname;  /* for error messages */
673 #ifndef AFS_NT40_ENV
674         if (geteuid() != 0) {
675             fprintf(stderr, "%s: Must be run as root.\n", progname);
676             return EPERM;
677         }
678 #endif
679         DInit(1024);
680         VInitVnodes(vLarge, 0);
681         VInitVnodes(vSmall, 0);
682         opr_queue_Init(&VnodeScanLists[vLarge]);
683         opr_queue_Init(&VnodeScanLists[vSmall]);
684         volinfo_init = 1;
685     }
686     return 0;
687 }
688
689 /**
690  * Alloc an options structure with default values.
691  *
692  * The caller must free the options pointer after use.
693  *
694  * @param[out] optp address of options pointer
695  * @return 0 on success
696  */
697 int
698 volinfo_Options(struct VolInfoOpt **optp)
699 {
700     struct VolInfoOpt *opt;
701
702     opt = calloc(1, sizeof(struct VolInfoOpt));
703     if (!opt) {
704         fprintf(stderr, "%s: Failed to allocate options (%d).\n", progname, ENOMEM);
705         return ENOMEM;
706     }
707     opt->dumpInfo = 1;
708     gethostname(opt->hostname, sizeof(opt->hostname));
709     opt->columnDelim[0] = ' ';
710     opt->checkMagic = 1;
711     *optp = opt;
712     return 0;
713 }
714
715 /**
716  * Add a column type to be displayed.
717  *
718  * @param[in]  name   column type name
719  *
720  * @return error code
721  *   @retval 0 success
722  *   @retval 1 too many columns
723  *   @retval 2 invalid column name
724  */
725 int
726 volinfo_AddOutputColumn(char *name)
727 {
728     int i;
729
730     if (NumOutputColumns >= sizeof(OutputColumn) / sizeof(*OutputColumn)) {
731         fprintf(stderr, "%s: Too many output columns (%d).\n", progname,
732                 NumOutputColumns);
733         return 1;
734     }
735     for (i = 0; i < max_column_type; i++) {
736         if (!strcmp(ColumnName[i].name, name)) {
737             columnType t = ColumnName[i].type;
738             OutputColumn[NumOutputColumns++] = t;
739
740             if (t == col_path) {
741                 NeedDirIndex = 1;
742             }
743             return 0;
744         }
745     }
746     return 2;
747 }
748
749
750 /**
751  * Determine if the current directory is a vice partition
752  *
753  * @return disk partition object
754  */
755 #ifdef AFS_NT40_ENV
756 #include <direct.h>
757 static struct DiskPartition64 *
758 FindCurrentPartition(void)
759 {
760     int dr = _getdrive();
761     struct DiskPartition64 *dp;
762
763     dr--;
764     for (dp = DiskPartitionList; dp; dp = dp->next) {
765         if (*dp->devName - 'A' == dr)
766             break;
767     }
768     if (!dp) {
769         fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
770                 progname);
771     }
772     return dp;
773 }
774 #else
775 static struct DiskPartition64 *
776 FindCurrentPartition(void)
777 {
778     char partName[1024];
779     char tmp = '\0';
780     char *p;
781     struct DiskPartition64 *dp;
782
783     if (!getcwd(partName, 1023)) {
784         fprintf(stderr, "%s: Failed to get current working directory: ",
785                 progname);
786         perror("pwd");
787         return NULL;
788     }
789     p = strchr(&partName[1], OS_DIRSEPC);
790     if (p) {
791         tmp = *p;
792         *p = '\0';
793     }
794     if (!(dp = VGetPartition(partName, 0))) {
795         if (tmp)
796             *p = tmp;
797         fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
798                 partName);
799         return NULL;
800     }
801     return dp;
802 }
803 #endif
804
805 /**
806  * Scan and handle all the partitions detected on this server
807  *
808  * @return none
809  */
810 static void
811 HandleAllPart(struct VolInfoOpt *opt)
812 {
813     struct DiskPartition64 *partP;
814
815     for (partP = DiskPartitionList; partP; partP = partP->next) {
816         if (opt->dumpInfo || opt->saveInodes || opt->showSizes) {
817             printf("Processing Partition %s:\n", partP->name);
818         }
819         HandlePart(opt, partP);
820         if (opt->showSizes) {
821             AddSizeTotals(&serverTotals, &partitionTotals);
822         }
823     }
824
825     if (opt->showSizes) {
826         PrintServerTotals();
827     }
828 }
829
830 /**
831  * Scan the partition and handle volumes
832  *
833  * @param[in] partP  disk partition to scan
834  *
835  * @return none
836  */
837 static void
838 HandlePart(struct VolInfoOpt *opt, struct DiskPartition64 *partP)
839 {
840     afs_int64 nvols = 0;
841     DIR *dirp;
842     struct dirent *dp;
843 #ifdef AFS_NT40_ENV
844     char pname[64];
845     char *p = pname;
846     (void)sprintf(pname, "%s\\", VPartitionPath(partP));
847 #else
848     char *p = VPartitionPath(partP);
849 #endif
850
851     if ((dirp = opendir(p)) == NULL) {
852         fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
853                 p);
854         return;
855     }
856     while ((dp = readdir(dirp))) {
857         p = (char *)strrchr(dp->d_name, '.');
858         if (p != NULL && strcmp(p, VHDREXT) == 0) {
859             HandleVolume(opt, partP, dp->d_name);
860             if (opt->showSizes) {
861                 nvols++;
862                 AddSizeTotals(&partitionTotals, &volumeTotals);
863             }
864         }
865     }
866     closedir(dirp);
867     if (opt->showSizes) {
868         PrintPartitionTotals(nvols);
869     }
870 }
871
872 /**
873  * Inspect a volume header special file.
874  *
875  * @param[in]    name       descriptive name of the type of header special file
876  * @param[in]    dp         partition object for this volume
877  * @param[in]    header     header object for this volume
878  * @param[in]    inode      fileserver inode number for this header special file
879  * @param[inout] psize      total of the header special file sizes
880  *
881  * @return none
882  */
883 static void
884 HandleSpecialFile(struct VolInfoOpt *opt, const char *name, struct DiskPartition64 *dp,
885                   struct VolumeHeader *header, Inode inode,
886                   afs_sfsize_t * psize)
887 {
888     afs_sfsize_t size = -1;
889     IHandle_t *ih = NULL;
890     FdHandle_t *fdP = NULL;
891     afs_ino_str_t inode_str;
892 #ifdef AFS_NAMEI_ENV
893     namei_t filename;
894 #endif /* AFS_NAMEI_ENV */
895
896     IH_INIT(ih, dp->device, header->parent, inode);
897     fdP = IH_OPEN(ih);
898     if (fdP == NULL) {
899         fprintf(stderr,
900                 "%s: Error opening header file '%s' for volume %" AFS_VOLID_FMT "\n", progname,
901                 name, afs_printable_VolumeId_lu(header->id));
902         perror("open");
903         goto error;
904     }
905     size = FDH_SIZE(fdP);
906     if (size == -1) {
907         fprintf(stderr,
908                 "%s: Error getting size of header file '%s' for volume %" AFS_VOLID_FMT "\n",
909                 progname, name, afs_printable_VolumeId_lu(header->id));
910         perror("fstat");
911         goto error;
912     }
913     *psize += size;
914
915   error:
916     if (opt->dumpInfo) {
917         printf("\t%s inode\t= %s (size = ", name, PrintInode(inode_str, inode));
918         if (size != -1) {
919             printf("%lld)\n", size);
920         } else {
921             printf("unknown)\n");
922         }
923 #ifdef AFS_NAMEI_ENV
924         namei_HandleToName(&filename, ih);
925         printf("\t%s namei\t= %s\n", name, filename.n_path);
926 #endif /* AFS_NAMEI_ENV */
927     }
928
929     if (fdP != NULL) {
930         FDH_REALLYCLOSE(fdP);
931     }
932     if (ih != NULL) {
933         IH_RELEASE(ih);
934     }
935 }
936
937 /**
938  * Inspect this volume header files.
939  *
940  * @param[in]  dp         partition object for this volume
941  * @param[in]  header_fd  volume header file descriptor
942  * @param[in]  header     volume header object
943  *
944  * @return none
945  */
946 static void
947 HandleHeaderFiles(struct VolInfoOpt *opt, struct DiskPartition64 *dp, FD_t header_fd,
948                   struct VolumeHeader *header)
949 {
950     afs_sfsize_t size = 0;
951
952     if (opt->dumpInfo) {
953         size = OS_SIZE(header_fd);
954         printf("Volume header (size = %lld):\n", size);
955         printf("\tstamp\t= 0x%x\n", header->stamp.version);
956         printf("\tVolId\t= %" AFS_VOLID_FMT "\n", afs_printable_VolumeId_lu(header->id));
957         printf("\tparent\t= %" AFS_VOLID_FMT "\n", afs_printable_VolumeId_lu(header->parent));
958     }
959
960     HandleSpecialFile(opt, "Info", dp, header, header->volumeInfo, &size);
961     HandleSpecialFile(opt, "Small", dp, header, header->smallVnodeIndex,
962                       &size);
963     HandleSpecialFile(opt, "Large", dp, header, header->largeVnodeIndex,
964                       &size);
965 #ifdef AFS_NAMEI_ENV
966     HandleSpecialFile(opt, "Link", dp, header, header->linkTable, &size);
967 #endif /* AFS_NAMEI_ENV */
968
969     if (opt->dumpInfo) {
970         printf("Total aux volume size = %lld\n\n", size);
971     }
972
973     if (opt->showSizes) {
974         volumeTotals.auxsize = size;
975         volumeTotals.auxsize_k = size / 1024;
976     }
977 }
978
979 /**
980  * Determine if the vnodes of this volume should be scanned.
981  *
982  * @param[in]  vp   volume object
983  *
984  * @return true if vnodes should be scanned
985  */
986 static int
987 IsScannable(struct VolInfoOpt *opt, Volume * vp)
988 {
989     if (opr_queue_IsEmpty(&VnodeScanLists[vLarge]) &&
990         opr_queue_IsEmpty(&VnodeScanLists[vSmall])) {
991         return 0;
992     }
993     if (!opt->scanVolType) {
994         return 1;               /* filtering disabled; do not check vol type */
995     }
996     switch (V_type(vp)) {
997     case RWVOL:
998         return opt->scanVolType & SCAN_RW;
999     case ROVOL:
1000         return opt->scanVolType & SCAN_RO;
1001     case BACKVOL:
1002         return opt->scanVolType & SCAN_BK;
1003     default:
1004         fprintf(stderr, "%s: Volume %" AFS_VOLID_FMT "; Unknown volume type %d\n", progname,
1005                 afs_printable_VolumeId_lu(V_id(vp)), V_type(vp));
1006         break;
1007     }
1008     return 0;
1009 }
1010
1011 /**
1012  * Attach and scan the volume and handle the header and vnodes
1013  *
1014  * Print the volume header and vnode information, depending on the
1015  * current modes.
1016  *
1017  * @param[in] dp    vice partition object for this volume
1018  * @param[in] name  volume header file name
1019  *
1020  * @return none
1021  */
1022 static void
1023 HandleVolume(struct VolInfoOpt *opt, struct DiskPartition64 *dp, char *name)
1024 {
1025     struct VolumeHeader header;
1026     struct VolumeDiskHeader diskHeader;
1027     FD_t fd = INVALID_FD;
1028     Volume *vp = NULL;
1029     char headerName[1024];
1030     afs_sfsize_t n;
1031
1032     snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
1033              VPartitionPath(dp), name);
1034     if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD) {
1035         fprintf(stderr, "%s: Cannot open volume header %s\n", progname, name);
1036         goto cleanup;
1037     }
1038     if (OS_SIZE(fd) < 0) {
1039         fprintf(stderr, "%s: Cannot read volume header %s\n", progname, name);
1040         goto cleanup;
1041     }
1042     n = OS_READ(fd, &diskHeader, sizeof(diskHeader));
1043     if (n != sizeof(diskHeader)
1044         || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
1045         fprintf(stderr, "%s: Error reading volume header %s\n", progname,
1046                 name);
1047         goto cleanup;
1048     }
1049     if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
1050         fprintf(stderr,
1051                 "%s: Volume %s, version number is incorrect; volume needs to be salvaged\n",
1052                 progname, name);
1053         goto cleanup;
1054     }
1055
1056     DiskToVolumeHeader(&header, &diskHeader);
1057     if (opt->dumpHeader || opt->showSizes) {
1058         HandleHeaderFiles(opt, dp, fd, &header);
1059     }
1060
1061     vp = AttachVolume(opt, dp, name, &header);
1062     if (!vp) {
1063         fprintf(stderr, "%s: Error attaching volume header %s\n",
1064                 progname, name);
1065         goto cleanup;
1066     }
1067
1068     if (opt->dumpInfo) {
1069         PrintHeader(vp);
1070     }
1071     if (IsScannable(opt, vp)) {
1072         if (NeedDirIndex) {
1073             IHandle_t *ih = vp->vnodeIndex[vLarge].handle;
1074             DirIndexFd = IH_OPEN(ih);
1075             if (DirIndexFd == NULL) {
1076                 fprintf(stderr, "%s: Failed to open index for directories.",
1077                         progname);
1078             }
1079         }
1080
1081         HandleVnodes(opt, vp, vLarge);
1082         HandleVnodes(opt, vp, vSmall);
1083
1084         if (DirIndexFd) {
1085             FDH_CLOSE(DirIndexFd);
1086             DirIndexFd = NULL;
1087         }
1088     }
1089     if (opt->showSizes) {
1090         volumeTotals.diskused_k = V_diskused(vp);
1091         volumeTotals.size_k =
1092             volumeTotals.auxsize_k + volumeTotals.vnodesize_k;
1093         if (opt->saveInodes) {
1094             PrintingVolumeSizes = 0;    /* print heading again */
1095         }
1096         PrintVolumeSizes(vp);
1097     }
1098
1099   cleanup:
1100     if (fd != INVALID_FD) {
1101         OS_CLOSE(fd);
1102     }
1103     if (vp) {
1104         DetachVolume(opt, vp);
1105     }
1106 }
1107
1108 /**
1109  * Return a display string for the volume type.
1110  *
1111  * @param[in]  type  volume type
1112  *
1113  * @return volume type description string
1114  */
1115 static_inline char *
1116 volumeTypeString(int type)
1117 {
1118     return
1119         (type == RWVOL ? "read/write" :
1120          (type == ROVOL ? "readonly" :
1121           (type == BACKVOL ? "backup" : "unknown")));
1122 }
1123
1124 /**
1125  * Return a short display string for the volume type.
1126  *
1127  * @param[in]  type  volume type
1128  *
1129  * @return volume type short description string
1130  */
1131 static_inline char *
1132 volumeTypeShortString(int type)
1133 {
1134     return
1135         (type == RWVOL ? "RW" :
1136          (type == ROVOL ? "RO" : (type == BACKVOL ? "BK" : "??")));
1137 }
1138
1139 /**
1140  * Print the volume header information
1141  *
1142  * @param[in]  volume object
1143  *
1144  * @return none
1145  */
1146 static void
1147 PrintHeader(Volume * vp)
1148 {
1149     printf("Volume header for volume %" AFS_VOLID_FMT " (%s)\n", afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
1150     printf("stamp.magic = %x, stamp.version = %u\n", V_stamp(vp).magic,
1151            V_stamp(vp).version);
1152     printf
1153         ("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n",
1154          V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp),
1155          V_dontSalvage(vp));
1156     printf
1157         ("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n",
1158          V_type(vp), volumeTypeString(V_type(vp)), V_uniquifier(vp),
1159          V_needsCallback(vp), V_destroyMe(vp));
1160     printf
1161         ("id = %" AFS_VOLID_FMT ", parentId = %" AFS_VOLID_FMT ", cloneId = %" AFS_VOLID_FMT ", backupId = %" AFS_VOLID_FMT ", restoredFromId = %" AFS_VOLID_FMT "\n",
1162          afs_printable_VolumeId_lu(V_id(vp)), afs_printable_VolumeId_lu(V_parentId(vp)), afs_printable_VolumeId_lu(V_cloneId(vp)), afs_printable_VolumeId_lu(V_backupId(vp)), afs_printable_VolumeId_lu(V_restoredFromId(vp)));
1163     printf
1164         ("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n",
1165          V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp),
1166          V_diskused(vp));
1167     printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)),
1168            date(V_copyDate(vp)));
1169     printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)),
1170            date(V_expirationDate(vp)));
1171     printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)),
1172            date(V_updateDate(vp)));
1173     printf("owner = %u, accountNumber = %u\n", V_owner(vp),
1174            V_accountNumber(vp));
1175     printf
1176         ("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n",
1177          V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2],
1178          V_weekUse(vp)[3], V_weekUse(vp)[4], V_weekUse(vp)[5],
1179          V_weekUse(vp)[6], date(V_dayUseDate(vp)));
1180     printf("volUpdateCounter = %u\n", V_volUpdateCounter(vp));
1181 }
1182
1183 /**
1184  * Get the size and times of a file
1185  *
1186  * @param[in]  fd     file descriptor of file to stat
1187  * @param[out] size   size of the file
1188  * @param[out] ctime  ctime of file as a formatted string
1189  * @param[out] mtime  mtime of file as a formatted string
1190  * @param[out] atime  atime of file as a formatted string
1191  *
1192  * @return error code
1193  *   @retval 0 success
1194  *   @retval -1 failed to retrieve file information
1195  */
1196 static int
1197 GetFileInfo(FD_t fd, afs_sfsize_t * size, char **ctime, char **mtime,
1198             char **atime)
1199 {
1200 #ifdef AFS_NT40_ENV
1201     BY_HANDLE_FILE_INFORMATION fi;
1202     LARGE_INTEGER fsize;
1203     if (!GetFileInformationByHandle(fd, &fi)) {
1204         fprintf(stderr, "%s: GetFileInformationByHandle failed\n", progname);
1205         return -1;
1206     }
1207     if (!GetFileSizeEx(fd, &fsize)) {
1208         fprintf(stderr, "%s: GetFileSizeEx failed\n", progname);
1209         return -1;
1210     }
1211     *size = fsize.QuadPart;
1212     *ctime = "N/A";
1213     *mtime = NT_date(&fi.ftLastWriteTime);
1214     *atime = NT_date(&fi.ftLastAccessTime);
1215 #else
1216     struct afs_stat_st status;
1217     if (afs_fstat(fd, &status) == -1) {
1218         fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
1219         return -1;
1220     }
1221     *size = status.st_size;
1222     *ctime = date(status.st_ctime);
1223     *mtime = date(status.st_mtime);
1224     *atime = date(status.st_atime);
1225 #endif
1226     return 0;
1227 }
1228
1229 /**
1230  * Copy the inode data to a file in the current directory.
1231  *
1232  * @param[in] vdp     vnode details object
1233  *
1234  * @return none
1235  */
1236 void
1237 volinfo_SaveInode(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1238 {
1239     IHandle_t *ih;
1240     FdHandle_t *fdP;
1241     char nfile[50], buffer[256];
1242     int ofd = 0;
1243     afs_foff_t total;
1244     ssize_t len;
1245     Inode ino = VNDISK_GET_INO(vdp->vnode);
1246     afs_ino_str_t inode_str;
1247
1248     if (!VALID_INO(ino)) {
1249         return;
1250     }
1251
1252     IH_INIT(ih, V_device(vdp->vp), V_parentId(vdp->vp), ino);
1253     fdP = IH_OPEN(ih);
1254     if (fdP == NULL) {
1255         fprintf(stderr,
1256                 "%s: Can't open inode %s error %d (ignored)\n",
1257                 progname, PrintInode(inode_str, ino), errno);
1258         return;
1259     }
1260     snprintf(nfile, sizeof nfile, "TmpInode.%s", PrintInode(inode_str, ino));
1261     ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
1262     if (ofd < 0) {
1263         fprintf(stderr,
1264                 "%s: Can't create file %s; error %d (ignored)\n",
1265                 progname, nfile, errno);
1266
1267         FDH_REALLYCLOSE(fdP);
1268         IH_RELEASE(ih);
1269         return;
1270     }
1271     total = 0;
1272     while (1) {
1273         ssize_t nBytes;
1274         len = FDH_PREAD(fdP, buffer, sizeof(buffer), total);
1275         if (len < 0) {
1276             FDH_REALLYCLOSE(fdP);
1277             IH_RELEASE(ih);
1278             close(ofd);
1279             unlink(nfile);
1280             fprintf(stderr,
1281                     "%s: Error while reading from inode %s (%d)\n",
1282                     progname, PrintInode(inode_str, ino), errno);
1283             return;
1284         }
1285         if (len == 0)
1286             break;              /* No more input */
1287         nBytes = write(ofd, buffer, (size_t)len);
1288         if (nBytes != len) {
1289             FDH_REALLYCLOSE(fdP);
1290             IH_RELEASE(ih);
1291             close(ofd);
1292             unlink(nfile);
1293             fprintf(stderr,
1294                     "%s: Error while writing to \"%s\" (%d - ignored)\n",
1295                     progname, nfile, errno);
1296             return;
1297         }
1298         total += len;
1299     }
1300
1301     FDH_REALLYCLOSE(fdP);
1302     IH_RELEASE(ih);
1303     close(ofd);
1304     printf("... Copied inode %s to file %s (%lu bytes)\n",
1305            PrintInode(inode_str, ino), nfile, (unsigned long)total);
1306 }
1307
1308 /**
1309  * get the VnodeDiskObject for a directory given its vnode id.
1310  *
1311  * @param[in]   vp       volume object
1312  * @param[in]   parent   vnode id to read
1313  * @param[out]  pvn      vnode disk object to populate
1314  *
1315  * @post pvn contains copy of disk object for parent id
1316  *
1317  * @return operation status
1318  *   @retval 0   success
1319  *   @retval -1  failure
1320  */
1321 static int
1322 GetDirVnode(struct VolInfoOpt *opt, Volume * vp, VnodeId parent, VnodeDiskObject * pvn)
1323 {
1324     afs_int32 code;
1325     afs_foff_t offset;
1326
1327     if (!DirIndexFd) {
1328         return -1;              /* previously failed to open the large vnode index. */
1329     }
1330     if (parent % 2 == 0) {
1331         fprintf(stderr, "%s: Invalid parent vnode id %lu in volume %lu\n",
1332                 progname,
1333                 afs_printable_uint32_lu(parent),
1334                 afs_printable_uint32_lu(V_id(vp)));
1335     }
1336     offset = vnodeIndexOffset(&VnodeClassInfo[vLarge], parent);
1337     code = FDH_PREAD(DirIndexFd, pvn, SIZEOF_LARGEDISKVNODE, offset);
1338     if (code != SIZEOF_LARGEDISKVNODE) {
1339         fprintf(stderr,
1340                 "%s: GetDirVnode: read failed for %lu.%lu at offset %llu\n",
1341                 progname, afs_printable_uint32_lu(V_id(vp)),
1342                 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1343         return -1;
1344     }
1345     if (opt->checkMagic && (pvn->vnodeMagic != LARGEVNODEMAGIC)) {
1346         fprintf(stderr, "%s: GetDirVnode: bad vnode magic for %lu.%lu at offset %llu\n",
1347                 progname, afs_printable_uint32_lu(V_id(vp)),
1348                 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1349         return -1;
1350     }
1351     if (!pvn->dataVersion) {
1352         fprintf(stderr, "%s: GetDirVnode: dv is zero for %lu.%lu at offset %llu\n",
1353                 progname, afs_printable_uint32_lu(V_id(vp)),
1354                 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1355         return -1;
1356     }
1357     return 0;
1358 }
1359
1360 /**
1361  * Perform inverse lookup on a vice directory object to map a fid onto a dirent string.
1362  *
1363  * @param[in]   vp          volume object
1364  * @param[in]   pvnode      parent directory vnode object
1365  * @param[in]   cvnid       child vnode id to inverse lookup
1366  * @param[in]   cuniq       child uniquifier to inverse lookup
1367  * @param[out]  dirent      buffer in which to store dirent string
1368  * @param[out]  dirent_len  length of dirent buffer
1369  *
1370  * @post dirent contains string for the (cvnid, cuniq) entry
1371  *
1372  * @return operation status
1373  *    @retval 0 success
1374  */
1375 static int
1376 GetDirEntry(Volume * vp, VnodeDiskObject * pvnode, VnodeId cvnid,
1377             afs_uint32 cuniq, char *dirent, size_t dirent_len)
1378 {
1379     DirHandle dir;
1380     Inode ino;
1381     int volumeChanged;
1382     afs_int32 code;
1383
1384     ino = VNDISK_GET_INO(pvnode);
1385     if (!VALID_INO(ino)) {
1386         fprintf(stderr, "%s: GetDirEntry invalid parent ino\n", progname);
1387         return -1;
1388     }
1389     SetSalvageDirHandle(&dir, V_parentId(vp), V_device(vp), ino,
1390                         &volumeChanged);
1391     code = afs_dir_InverseLookup(&dir, cvnid, cuniq, dirent, dirent_len);
1392     if (code) {
1393         fprintf(stderr, "%s: afs_dir_InverseLookup failed with code %d\n",
1394                 progname, code);
1395     }
1396     FidZap(&dir);
1397     return code;
1398 }
1399
1400 /**
1401  * Lookup the path of this vnode, relative to the root of the volume.
1402  *
1403  * @param[in] vdp    vnode details
1404  *
1405  * @return status
1406  *   @retval 0 success
1407  *   @retval -1 error
1408  */
1409 static int
1410 LookupPath(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1411 {
1412 #define MAX_PATH_LEN 1023
1413     static char path_buffer[MAX_PATH_LEN + 1];
1414     static char dirent[MAX_PATH_LEN + 1];
1415     char vnode_buffer[SIZEOF_LARGEDISKVNODE];
1416     struct VnodeDiskObject *pvn = (struct VnodeDiskObject *)vnode_buffer;
1417     int code = 0;
1418     int space;
1419     char *cursor;
1420     Volume *vp = vdp->vp;
1421     VnodeId parent = vdp->vnode->parent;
1422     VnodeId cvnid = vdp->vnodeNumber;
1423     afs_uint32 cuniq = vdp->vnode->uniquifier;
1424
1425     if (!parent) {
1426         vdp->path = "/";        /* this is root */
1427         return 0;
1428     }
1429
1430     space = sizeof(path_buffer) - 1;
1431     cursor = &path_buffer[space];
1432     *cursor = '\0';
1433
1434     while (parent) {
1435         int len;
1436
1437         code = GetDirVnode(opt, vp, parent, pvn);
1438         if (code) {
1439             cursor = NULL;
1440             break;
1441         }
1442         code = GetDirEntry(vp, pvn, cvnid, cuniq, dirent, MAX_PATH_LEN);
1443         if (code) {
1444             cursor = NULL;
1445             break;
1446         }
1447
1448         len = strlen(dirent);
1449         if (len == 0) {
1450             fprintf(stderr,
1451                     "%s: Failed to lookup path for fid %lu.%lu.%lu: empty dir entry\n",
1452                     progname, afs_printable_uint32_lu(V_id(vdp->vp)),
1453                     afs_printable_uint32_lu(vdp->vnodeNumber),
1454                     afs_printable_uint32_lu(vdp->vnode->uniquifier));
1455             cursor = NULL;
1456             code = -1;
1457             break;
1458         }
1459
1460         if (space < (len + 1)) {
1461             fprintf(stderr,
1462                     "%s: Failed to lookup path for fid %lu.%lu.%lu: path exceeds max length (%u).\n",
1463                     progname, afs_printable_uint32_lu(V_id(vdp->vp)),
1464                     afs_printable_uint32_lu(vdp->vnodeNumber),
1465                     afs_printable_uint32_lu(vdp->vnode->uniquifier),
1466                     MAX_PATH_LEN);
1467             cursor = NULL;
1468             code = -1;
1469             break;
1470         }
1471
1472         /* prepend path component */
1473         cursor -= len;
1474         memcpy(cursor, dirent, len);
1475         *--cursor = '/';
1476         space -= (len + 1);
1477
1478         /* next parent */
1479         cvnid = parent;
1480         cuniq = pvn->uniquifier;
1481         parent = pvn->parent;
1482     }
1483
1484     if (cursor) {
1485         vdp->path = cursor;
1486     }
1487     return code;
1488 }
1489
1490 /**
1491  * Read the symlink target and determine if this vnode is a mount point.
1492  *
1493  * @param[inout]   vdp    vnode details object
1494  *
1495  * @return error code
1496  *   @retval 0 success
1497  *   @retval -1 failure
1498  */
1499 static int
1500 ReadSymlinkTarget(struct VnodeDetails *vdp)
1501 {
1502 #define MAX_SYMLINK_LEN 1023
1503     static char buffer[MAX_SYMLINK_LEN + 1];
1504     int code;
1505     Volume *vp = vdp->vp;
1506     VnodeDiskObject *vnode = vdp->vnode;
1507     VnodeId vnodeNumber = vdp->vnodeNumber;
1508     IHandle_t *ihP = NULL;
1509     FdHandle_t *fdP = NULL;
1510     afs_fsize_t fileLength;
1511     int readLength;
1512     Inode ino;
1513
1514     ino = VNDISK_GET_INO(vnode);
1515     VNDISK_GET_LEN(fileLength, vnode);
1516
1517     if (fileLength > MAX_SYMLINK_LEN) {
1518         fprintf(stderr,
1519                 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) exceeds "
1520                 "%u, file length is %llu)!\n", progname,
1521                 afs_printable_uint32_lu(V_id(vp)),
1522                 afs_printable_uint32_lu(vnodeNumber),
1523                 afs_printable_uint32_lu(vnode->uniquifier),
1524                 afs_printable_uint32_lu(vnode->dataVersion),
1525                 MAX_SYMLINK_LEN,
1526                 fileLength);
1527         return -1;
1528     }
1529     if (fileLength == 0) {
1530         fprintf(stderr,
1531                 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) is empty.\n",
1532                 progname,
1533                 afs_printable_uint32_lu(V_id(vp)),
1534                 afs_printable_uint32_lu(vnodeNumber),
1535                 afs_printable_uint32_lu(vnode->uniquifier),
1536                 afs_printable_uint32_lu(vnode->dataVersion));
1537         return -1;
1538     }
1539
1540     IH_INIT(ihP, V_device(vp), V_parentId(vp), ino);
1541     fdP = IH_OPEN(ihP);
1542     if (fdP == NULL) {
1543         code = -1;
1544         goto cleanup;
1545     }
1546     readLength = FDH_PREAD(fdP, buffer, fileLength, 0);
1547     if (readLength < 0) {
1548         fprintf(stderr,
1549                 "%s: Error reading symlink contents for fid (%lu.%lu.%lu.%lu); "
1550                 "errno %d\n",
1551                 progname,
1552                 afs_printable_uint32_lu(V_id(vp)),
1553                 afs_printable_uint32_lu(vnodeNumber),
1554                 afs_printable_uint32_lu(vnode->uniquifier),
1555                 afs_printable_uint32_lu(vnode->dataVersion), errno);
1556         code = -1;
1557         goto cleanup;
1558     } else if (readLength != fileLength) {
1559         fprintf(stderr,
1560                 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) don't match "
1561                 "vnode file length metadata (len=%llu, actual=%lld)!\n",
1562                 progname,
1563                 afs_printable_uint32_lu(V_id(vp)),
1564                 afs_printable_uint32_lu(vnodeNumber),
1565                 afs_printable_uint32_lu(vnode->uniquifier),
1566                 afs_printable_uint32_lu(vnode->dataVersion), fileLength,
1567                 (long long)readLength);
1568         code = -1;
1569         goto cleanup;
1570     }
1571     code = 0;
1572
1573     if (readLength > 1 && (buffer[0] == '#' || buffer[0] == '%')
1574         && buffer[readLength - 1] == '.') {
1575         char *sep;
1576         buffer[readLength - 1] = '\0';  /* stringify; clobbers trailing dot */
1577         sep = strchr(buffer, ':');
1578         vdp->t = VNODE_U_MOUNT;
1579         vdp->u.mnt.type = buffer[0];
1580         if (!sep) {
1581             vdp->u.mnt.cell = NULL;
1582             vdp->u.mnt.vol = buffer + 1;
1583         } else {
1584             *sep = '\0';
1585             vdp->u.mnt.cell = buffer + 1;
1586             vdp->u.mnt.vol = sep + 1;
1587         }
1588     } else {
1589         buffer[readLength] = '\0';
1590         vdp->t = VNODE_U_SYMLINK;
1591         vdp->u.target = buffer;
1592     }
1593
1594   cleanup:
1595     if (fdP) {
1596         FDH_CLOSE(fdP);
1597     }
1598     if (ihP) {
1599         IH_RELEASE(ihP);
1600     }
1601     return code;
1602 }
1603
1604 /**
1605  * Print vnode details line
1606  *
1607  * @param[inout]  vdp   vnode details object
1608  *
1609  * @return none
1610  */
1611 void
1612 volinfo_PrintVnodeDetails(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1613 {
1614     switch (vdp->vnode->type) {
1615     case vNull:
1616         break;
1617     case vFile:
1618         if (opt->findVnType & FIND_FILE) {
1619             PrintColumns(opt, vdp, "file");
1620         }
1621         break;
1622     case vDirectory:
1623         if (opt->findVnType & FIND_DIR) {
1624             PrintColumns(opt, vdp, "dir");
1625         }
1626         break;
1627     case vSymlink:
1628         if (opt->findVnType & (FIND_MOUNT | FIND_SYMLINK)) {
1629             ReadSymlinkTarget(vdp);
1630             if ((opt->findVnType & FIND_MOUNT) && (vdp->t == VNODE_U_MOUNT)) {
1631                 PrintColumns(opt, vdp, "mount");
1632             }
1633             if ((opt->findVnType & FIND_SYMLINK) && (vdp->t == VNODE_U_SYMLINK)) {
1634                 PrintColumns(opt, vdp, "symlink");
1635             }
1636         }
1637         break;
1638     default:
1639         fprintf(stderr,
1640                 "%s: Warning: unexpected vnode type %u on fid %lu.%lu.%lu",
1641                 progname, vdp->vnode->type,
1642                 afs_printable_uint32_lu(V_id(vdp->vp)),
1643                 afs_printable_uint32_lu(vdp->vnodeNumber),
1644                 afs_printable_uint32_lu(vdp->vnode->uniquifier));
1645     }
1646 }
1647
1648 /**
1649  * Print each access entry of a vnode
1650  *
1651  * @param[in]  vdp   vnode details object
1652  *
1653  * @return none
1654  */
1655 void
1656 volinfo_ScanAcl(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1657 {
1658     int i;
1659     struct acl_accessList *acl;
1660     VnodeDiskObject *vnode = vdp->vnode;
1661
1662     if (vnode->type == vNull) {
1663         return;
1664     }
1665
1666     acl = VVnodeDiskACL(vnode);
1667     for (i = 0; i < acl->positive; i++) {
1668         vdp->t = VNODE_U_POS_ACCESS;
1669         vdp->u.access = &(acl->entries[i]);
1670         PrintColumns(opt, vdp, "acl");
1671     }
1672     for (i = (acl->total - 1); i >= (acl->total - acl->negative); i--) {
1673         vdp->t = VNODE_U_NEG_ACCESS;
1674         vdp->u.access = &(acl->entries[i]);
1675         PrintColumns(opt, vdp, "acl");
1676     }
1677 }
1678
1679 /**
1680  * Determine if the mode matches all the given masks.
1681  *
1682  * Returns true if the mode bits match all the given masks. A mask matches if at
1683  * least one bit in the mask is present in the mode bits.  An empty mode mask
1684  * list matches all modes (even if all the mode bits are zero.)
1685  *
1686  * param[in]  modeBits  unix mode bits of a vnode
1687  *
1688  */
1689 static int
1690 ModeMaskMatch(struct VolInfoOpt *opt, unsigned int modeBits)
1691 {
1692     int i;
1693
1694     for (i = 0; i < sizeof(opt->modeMask) / sizeof(*opt->modeMask) && opt->modeMask[i]; i++) {
1695         if ((opt->modeMask[i] & modeBits) == 0) {
1696             return 0;           /* at least one mode bit is not present */
1697         }
1698     }
1699     return 1;
1700 }
1701
1702 /**
1703  * Scan a volume index and handle each vnode
1704  *
1705  * @param[in] vp      volume object
1706  * @param[in] class   which index to scan
1707  *
1708  * @return none
1709  */
1710 static void
1711 HandleVnodes(struct VolInfoOpt *opt, Volume * vp, VnodeClass class)
1712 {
1713     afs_int32 diskSize =
1714         (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE);
1715     char buf[SIZEOF_LARGEDISKVNODE];
1716     struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1717     StreamHandle_t *file = NULL;
1718     int vnodeIndex;
1719     afs_sfsize_t nVnodes;
1720     afs_foff_t offset = 0;
1721     IHandle_t *ih = vp->vnodeIndex[class].handle;
1722     FdHandle_t *fdP = NULL;
1723     afs_sfsize_t size;
1724     char *ctime, *atime, *mtime;
1725     struct opr_queue *scanList = &VnodeScanLists[class];
1726     struct opr_queue *cursor;
1727
1728     if (opr_queue_IsEmpty(scanList)) {
1729         return;
1730     }
1731
1732     for (opr_queue_Scan(scanList, cursor)) {
1733         struct VnodeScanProc *entry = (struct VnodeScanProc *)cursor;
1734         if (entry->heading) {
1735             printf("%s", entry->heading);
1736         }
1737     }
1738
1739     fdP = IH_OPEN(ih);
1740     if (fdP == NULL) {
1741         fprintf(stderr, "%s: open failed: ", progname);
1742         goto error;
1743     }
1744
1745     file = FDH_FDOPEN(fdP, "r");
1746     if (!file) {
1747         fprintf(stderr, "%s: fdopen failed\n", progname);
1748         goto error;
1749     }
1750
1751     if (GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime) != 0) {
1752         goto error;
1753     }
1754     if (opt->dumpInodeTimes) {
1755         printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime,
1756                mtime, atime);
1757     }
1758
1759     nVnodes = (size / diskSize) - 1;
1760     if (nVnodes > 0) {
1761         STREAM_ASEEK(file, diskSize);
1762     } else
1763         nVnodes = 0;
1764
1765     for (vnodeIndex = 0;
1766          nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1;
1767          nVnodes--, vnodeIndex++, offset += diskSize) {
1768
1769         struct VnodeDetails vnodeDetails;
1770
1771         if (!ModeMaskMatch(opt, vnode->modeBits)) {
1772             continue;
1773         }
1774
1775         memset(&vnodeDetails, 0, sizeof(struct VnodeDetails));
1776         vnodeDetails.vp = vp;
1777         vnodeDetails.class = class;
1778         vnodeDetails.vnode = vnode;
1779         vnodeDetails.vnodeNumber = bitNumberToVnodeNumber(vnodeIndex, class);
1780         vnodeDetails.offset = offset;
1781         vnodeDetails.index = vnodeIndex;
1782
1783         for (opr_queue_Scan(scanList, cursor)) {
1784             struct VnodeScanProc *entry = (struct VnodeScanProc *)cursor;
1785             if (entry->proc) {
1786                 (*entry->proc) (opt, &vnodeDetails);
1787             }
1788         }
1789     }
1790
1791   error:
1792     if (file) {
1793         STREAM_CLOSE(file);
1794     }
1795     if (fdP) {
1796         FDH_CLOSE(fdP);
1797     }
1798 }
1799
1800 /**
1801  * Print vnode information
1802  *
1803  * @param[in] vdp          vnode details object
1804  *
1805  * @return none
1806  */
1807 void
1808 volinfo_PrintVnode(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1809 {
1810 #if defined(AFS_NAMEI_ENV)
1811     IHandle_t *ihtmpp;
1812     namei_t filename;
1813 #endif
1814     afs_foff_t offset = vdp->offset;
1815     VnodeDiskObject *vnode = vdp->vnode;
1816     afs_fsize_t fileLength;
1817     Inode ino;
1818     afs_ino_str_t inode_str;
1819
1820     ino = VNDISK_GET_INO(vnode);
1821     VNDISK_GET_LEN(fileLength, vnode);
1822
1823     /* The check for orphaned vnodes is currently limited to non-empty
1824      * vnodes with a parent of zero (and which are not the first entry
1825      * in the index). */
1826     if (opt->showOrphaned && (fileLength == 0 || vnode->parent || !offset))
1827         return;
1828
1829     printf
1830         ("%10lld Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
1831          (long long)offset, vdp->vnodeNumber, vnode->uniquifier,
1832          vnode->dataVersion, vnode->cloned, (afs_uintmax_t) fileLength,
1833          vnode->linkCount, vnode->parent);
1834     if (opt->dumpInodeNumber)
1835         printf(" inode: %s", PrintInode(inode_str, ino));
1836     if (opt->dumpDate)
1837         printf(" ServerModTime: %s", date(vnode->serverModifyTime));
1838 #if defined(AFS_NAMEI_ENV)
1839     if (opt->dumpFileNames) {
1840         IH_INIT(ihtmpp, V_device(vdp->vp), V_parentId(vdp->vp), ino);
1841         namei_HandleToName(&filename, ihtmpp);
1842 #if !defined(AFS_NT40_ENV)
1843         printf(" UFS-Filename: %s", filename.n_path);
1844 #else
1845         printf(" NTFS-Filename: %s", filename.n_path);
1846 #endif
1847     }
1848 #endif
1849     printf("\n");
1850 }
1851
1852 /**
1853  * Print the volume partition id
1854  *
1855  * @param[in]  vp  volume object
1856  *
1857  * @return none
1858  */
1859 static void
1860 PrintPartitionId(Volume * vp)
1861 {
1862     char *partition = VPartitionPath(V_partition(vp));
1863
1864     if (!strncmp(partition, "/vicep", 6)) {
1865         printf("%s", partition + 6);
1866     } else if (!strncmp(partition, "vicep", 5)) {
1867         printf("%s", partition + 5);
1868     } else {
1869         fprintf(stderr, "Invalid partition for volume id %lu\n",
1870                 afs_printable_uint32_lu(V_id(vp)));
1871         printf("%s", PLACEHOLDER);
1872     }
1873 }
1874
1875 /**
1876  * Print the vnode type description string
1877  *
1878  * @param[in]  type  vnode type
1879  *
1880  * @return none
1881  */
1882 static void
1883 volinfo_PrintVnodeType(int type)
1884 {
1885     switch (type) {
1886     case vNull:
1887         printf("null");
1888         break;
1889     case vFile:
1890         printf("file");
1891         break;
1892     case vDirectory:
1893         printf("dir");
1894         break;
1895     case vSymlink:
1896         printf("symlink");
1897         break;
1898     default:
1899         printf("unknown");
1900     }
1901 }
1902
1903 /**
1904  * Print right bits as string.
1905  *
1906  * param[in] rights  rights bitmap
1907  */
1908 static void
1909 PrintRights(int rights)
1910 {
1911     if (rights & PRSFS_READ) {
1912         printf("r");
1913     }
1914     if (rights & PRSFS_LOOKUP) {
1915         printf("l");
1916     }
1917     if (rights & PRSFS_INSERT) {
1918         printf("i");
1919     }
1920     if (rights & PRSFS_DELETE) {
1921         printf("d");
1922     }
1923     if (rights & PRSFS_WRITE) {
1924         printf("w");
1925     }
1926     if (rights & PRSFS_LOCK) {
1927         printf("k");
1928     }
1929     if (rights & PRSFS_ADMINISTER) {
1930         printf("a");
1931     }
1932     if (rights & PRSFS_USR0) {
1933         printf("A");
1934     }
1935     if (rights & PRSFS_USR1) {
1936         printf("B");
1937     }
1938     if (rights & PRSFS_USR2) {
1939         printf("C");
1940     }
1941     if (rights & PRSFS_USR3) {
1942         printf("D");
1943     }
1944     if (rights & PRSFS_USR4) {
1945         printf("E");
1946     }
1947     if (rights & PRSFS_USR5) {
1948         printf("F");
1949     }
1950     if (rights & PRSFS_USR6) {
1951         printf("G");
1952     }
1953     if (rights & PRSFS_USR7) {
1954         printf("H");
1955     }
1956 }
1957
1958 /**
1959  * Print the path to the namei file.
1960  */
1961 static void
1962 PrintNamei(Volume * vp, VnodeDiskObject * vnode)
1963 {
1964 #ifdef AFS_NAMEI_ENV
1965     namei_t name;
1966     IHandle_t *ihP = NULL;
1967     Inode ino;
1968     ino = VNDISK_GET_INO(vnode);
1969     IH_INIT(ihP, V_device(vp), V_parentId(vp), ino);
1970     namei_HandleToName(&name, ihP);
1971     printf("%s", name.n_path);
1972     IH_RELEASE(ihP);
1973 #else
1974     printf("%s", PLACEHOLDER);
1975 #endif
1976 }
1977
1978 /**
1979  * Print the column heading line.
1980  */
1981 static void
1982 PrintColumnHeading(struct VolInfoOpt *opt)
1983 {
1984     int i;
1985     const char *name;
1986
1987     for (i = 0; i < NumOutputColumns; i++) {
1988         if (i > 0) {
1989             printf("%s", opt->columnDelim);
1990         }
1991         name = ColumnName[OutputColumn[i]].name;
1992         while (*name) {
1993             putchar(toupper(*name++));
1994         }
1995     }
1996     printf("\n");
1997 }
1998
1999 /**
2000  * Print output columns for the vnode/acess entry.
2001  *
2002  * @param[in]  vdp   vnode details object
2003  * @param[in]  desc  type of line to be printed
2004  *
2005  * @return none
2006  */
2007 static void
2008 PrintColumns(struct VolInfoOpt *opt, struct VnodeDetails *vdp, const char *desc)
2009 {
2010     int i;
2011     afs_fsize_t length;
2012
2013     for (i = 0; i < NumOutputColumns; i++) {
2014         if (i > 0) {
2015             printf("%s", opt->columnDelim);
2016         }
2017         switch (OutputColumn[i]) {
2018         case col_host:
2019             printf("%s", opt->hostname);
2020             break;
2021         case col_desc:
2022             printf("%s", desc);
2023             break;
2024         case col_vid:
2025             printf("%lu", afs_printable_uint32_lu(V_id(vdp->vp)));
2026             break;
2027         case col_offset:
2028             printf("%llu", vdp->offset);
2029             break;
2030         case col_vtype:
2031             printf("%s", volumeTypeShortString(V_type(vdp->vp)));
2032             break;
2033         case col_vname:
2034             printf("%s", V_name(vdp->vp));
2035             break;
2036         case col_part:
2037             printf("%s", VPartitionPath(V_partition(vdp->vp)));
2038             break;
2039         case col_partid:
2040             PrintPartitionId(vdp->vp);
2041             break;
2042         case col_fid:
2043             printf("%lu.%lu.%lu",
2044                    afs_printable_uint32_lu(V_id(vdp->vp)),
2045                    afs_printable_uint32_lu(vdp->vnodeNumber),
2046                    afs_printable_uint32_lu(vdp->vnode->uniquifier));
2047             break;
2048         case col_path:
2049             if (!vdp->path) {
2050                 LookupPath(opt, vdp);
2051             }
2052             printf("%s", vdp->path ? vdp->path : PLACEHOLDER);
2053             break;
2054         case col_target:
2055             printf("%s",
2056                    (vdp->t == VNODE_U_SYMLINK ? vdp->u.target : PLACEHOLDER));
2057             break;
2058         case col_mount:
2059             if (vdp->t != VNODE_U_MOUNT) {
2060                 printf("%s", PLACEHOLDER);
2061             } else {
2062                 printf("%c", vdp->u.mnt.type);
2063                 if (vdp->u.mnt.cell) {
2064                     printf("%s:", vdp->u.mnt.cell);
2065                 }
2066                 printf("%s.", vdp->u.mnt.vol);
2067             }
2068             break;
2069         case col_mtype:
2070             printf("%c", (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.type : '-'));
2071             break;
2072         case col_mcell:
2073             printf("%s",
2074                    (vdp->t == VNODE_U_MOUNT && vdp->u.mnt.cell ? vdp->u.mnt.cell : PLACEHOLDER));
2075             break;
2076         case col_mvol:
2077             printf("%s",
2078                    (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.vol : PLACEHOLDER));
2079             break;
2080         case col_aid:
2081             if (vdp->t == VNODE_U_POS_ACCESS || vdp->t == VNODE_U_NEG_ACCESS) {
2082                 printf("%d", vdp->u.access->id);
2083             } else {
2084                 printf("%s", PLACEHOLDER);
2085             }
2086             break;
2087         case col_arights:
2088             if (vdp->t == VNODE_U_POS_ACCESS) {
2089                 printf("+");
2090                 PrintRights(vdp->u.access->rights);
2091             } else if (vdp->t == VNODE_U_NEG_ACCESS) {
2092                 printf("-");
2093                 PrintRights(vdp->u.access->rights);
2094             }
2095             break;
2096         case col_vntype:
2097             volinfo_PrintVnodeType(vdp->vnode->type);
2098             break;
2099         case col_cloned:
2100             printf("%c", vdp->vnode->cloned ? 'y' : 'n');
2101             break;
2102         case col_mode:
2103             printf("0%o", vdp->vnode->modeBits);
2104             break;
2105         case col_links:
2106             printf("%lu", afs_printable_uint32_lu(vdp->vnode->linkCount));
2107             break;
2108         case col_length:
2109             VNDISK_GET_LEN(length, vdp->vnode);
2110             printf("%llu", length);
2111             break;
2112         case col_uniq:
2113             printf("%lu", afs_printable_uint32_lu(vdp->vnode->uniquifier));
2114             break;
2115         case col_dv:
2116             printf("%lu", afs_printable_uint32_lu(vdp->vnode->dataVersion));
2117             break;
2118         case col_inode:
2119             printf("%" AFS_UINT64_FMT, VNDISK_GET_INO(vdp->vnode));
2120             break;
2121         case col_namei:
2122             PrintNamei(vdp->vp, vdp->vnode);
2123             break;
2124         case col_modtime:
2125             printf("%lu",
2126                    afs_printable_uint32_lu(vdp->vnode->unixModifyTime));
2127             break;
2128         case col_author:
2129             printf("%lu", afs_printable_uint32_lu(vdp->vnode->author));
2130             break;
2131         case col_owner:
2132             printf("%lu", afs_printable_uint32_lu(vdp->vnode->owner));
2133             break;
2134         case col_parent:
2135             printf("%lu", afs_printable_uint32_lu(vdp->vnode->parent));
2136             break;
2137         case col_magic:
2138             printf("0x%08X", vdp->vnode->vnodeMagic);
2139             break;
2140         case col_lock:
2141             printf("%lu.%lu",
2142                    afs_printable_uint32_lu(vdp->vnode->lock.lockCount),
2143                    afs_printable_uint32_lu(vdp->vnode->lock.lockTime));
2144             break;
2145         case col_smodtime:
2146             printf("%lu",
2147                    afs_printable_uint32_lu(vdp->vnode->serverModifyTime));
2148             break;
2149         case col_group:
2150             printf("%lu", afs_printable_uint32_lu(vdp->vnode->group));
2151             break;
2152         default:
2153             fprintf(stderr, "%s: Unknown column type: %d (%d)\n", progname,
2154                     OutputColumn[i], i);
2155             break;
2156         }
2157     }
2158     printf("\n");
2159 }