2 * Copyright 2000, International Business Machines Corporation and others.
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
13 Institution: The Information Technology Center, Carnegie-Mellon University
17 #include <afsconfig.h>
18 #include <afs/param.h>
24 #ifdef HAVE_SYS_FILE_H
30 #include <afs/afsint.h>
31 #include <afs/errors.h>
33 #include <afs/prs_fs.h>
34 #include <rx/rx_queue.h>
41 #include "partition.h"
43 #include "daemon_com_inline.h"
44 #include "fssync_inline.h"
47 static int volinfo_init = 0;
48 static const char *progname = "";
49 static const char *PLACEHOLDER = "-";
52 /* Numeric column type ids */
53 typedef enum columnType {
65 /* Table of id:name tuples of possible columns. */
66 struct columnName ColumnName[] = {
67 #define c(x) { col_##x, #x },
70 {max_column_type, NULL}
74 /* VnodeDetails union descriminator */
86 VnodeDiskObject *vnode;
99 struct acl_accessEntry *access;
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. */
107 static int NumOutputColumns = 0;
108 static columnType OutputColumn[max_column_type];
111 * Volume size running totals
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 */
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 */
128 * List of procedures to call when scanning vnodes.
130 struct VnodeScanProc {
131 struct opr_queue link;
133 void (*proc) (struct VolInfoOpt *opt, struct VnodeDetails * vdp);
135 static struct opr_queue VnodeScanLists[nVNODECLASSES];
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);
150 extern void SetSalvageDirHandle(DirHandle * dir, afs_int32 volume,
151 Device device, Inode inode,
153 extern void FidZap(DirHandle * file);
156 * Format time as a timestamp string
158 * @param[in] date time value to format
160 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
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.
170 #define MAX_DATE_RESULT 100
171 static char results[8][MAX_DATE_RESULT];
173 struct tm *tm = localtime(&date);
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];
184 * Format file time as a timestamp string
186 * @param[in] ft file time
188 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
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.
196 NT_date(FILETIME * ft)
198 static char result[8][64];
203 if (!FileTimeToLocalFileTime(ft, &lft)
204 || !FileTimeToSystemTime(&lft, &st)) {
205 fprintf(stderr, "%s: Time conversion failed.\n", progname);
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);
215 * Add vnode size to the running volume totals.
217 * @param[in] vdp vnode details object
222 volinfo_AddVnodeToSizeTotals(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
224 afs_fsize_t fileLength;
226 VNDISK_GET_LEN(fileLength, vdp->vnode);
227 if (fileLength > 0) {
228 volumeTotals.vnodesize += fileLength;
229 volumeTotals.vnodesize_k += fileLength / 1024;
234 * Print the volume size table heading line, if needed.
239 PrintVolumeSizeHeading(void)
241 if (!PrintingVolumeSizes) {
243 ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n");
244 PrintingVolumeSizes = 1;
254 AddSizeTotals(struct sizeTotals *a, struct sizeTotals *b)
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;
265 * Print the sizes for a volume.
270 PrintVolumeSizes(Volume * vp)
272 afs_int64 diff_k = volumeTotals.size_k - volumeTotals.diskused_k;
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));
283 * Print the size totals for the partition.
288 PrintPartitionTotals(afs_uint64 nvols)
290 afs_int64 diff_k = partitionTotals.size_k - partitionTotals.diskused_k;
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;
300 * Print the size totals for all the partitions.
305 PrintServerTotals(void)
307 afs_int64 diff_k = serverTotals.size_k - serverTotals.diskused_k;
309 printf("\nServer Totals%12lld%9lld%10lld%10lld%9lld\n",
310 serverTotals.diskused_k, serverTotals.auxsize,
311 serverTotals.vnodesize, serverTotals.size_k, diff_k);
315 * Read a volume header file
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
325 * @retval -1 failed to read file
328 ReadHdr1(struct VolInfoOpt *opt, IHandle_t * ih, char *to, afs_sfsize_t size,
329 u_int magic, u_int version)
331 struct versionStamp *vsn;
335 vsn = (struct versionStamp *)to;
337 code = IH_IREAD(ih, 0, to, size);
341 if (vsn->magic != magic) {
343 fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
344 progname, PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
347 /* Check is conditional, in case caller wants to inspect version himself */
348 if (version && vsn->version != version) {
350 fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
352 PrintInode(NULL, ih->ih_ino), vsn->version, version);
354 if (bad && opt->fixHeader) {
356 vsn->version = version;
357 printf("Special index inode %s has a bad header. Reconstructing...\n",
358 PrintInode(NULL, ih->ih_ino));
359 code = IH_IWRITE(ih, 0, to, size);
362 "%s: Write failed for inode %s; header left in damaged state\n",
363 progname, PrintInode(NULL, ih->ih_ino));
366 if (!bad && opt->dumpInfo) {
367 printf("Inode %s: Good magic %x and version %x\n",
368 PrintInode(NULL, ih->ih_ino), magic, version);
374 * Simplified attach volume
376 * param[in] dp vice disk partition object
377 * param[in] volname volume header file name
378 * param[in] header volume header object
380 * @return volume object or null on error
383 AttachVolume(struct VolInfoOpt *opt, struct DiskPartition64 *dp,
384 char *volname, struct VolumeHeader *header)
391 SYNC_response response;
392 VolumeId volid = header->id;
394 memset(&response, 0, sizeof(response));
396 FSYNC_VolOp(volid, dp->name, FSYNC_VOL_NEEDVOLUME, V_DUMP,
398 if (code != SYNC_OK) {
399 if (response.hdr.reason == FSYNC_SALVAGE) {
401 "%s: file server says volume %lu is salvaging.\n",
402 progname, afs_printable_uint32_lu(volid));
406 "%s: attach of volume %lu denied by file server.\n",
407 progname, afs_printable_uint32_lu(volid));
413 vp = (Volume *) calloc(1, sizeof(Volume));
415 fprintf(stderr, "%s: Failed to allocate volume object.\n", progname);
418 vp->specialStatus = 0;
419 vp->device = dp->device;
421 IH_INIT(vp->vnodeIndex[vLarge].handle, dp->device, header->parent,
422 header->largeVnodeIndex);
423 IH_INIT(vp->vnodeIndex[vSmall].handle, dp->device, header->parent,
424 header->smallVnodeIndex);
425 IH_INIT(vp->diskDataHandle, dp->device, header->parent,
427 IH_INIT(V_linkHandle(vp), dp->device, header->parent, header->linkTable);
428 vp->cacheCheck = 0; /* XXXX */
429 vp->shuttingDown = 0;
430 vp->goingOffline = 0;
432 vp->header = calloc(1, sizeof(*vp->header));
434 fprintf(stderr, "%s: Failed to allocate volume header.\n", progname);
438 ec = ReadHdr1(opt, V_diskDataHandle(vp), (char *)&V_disk(vp),
439 sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
441 struct IndexFileHeader iHead;
442 ec = ReadHdr1(opt, vp->vnodeIndex[vSmall].handle, (char *)&iHead,
443 sizeof(iHead), SMALLINDEXMAGIC, SMALLINDEXVERSION);
446 struct IndexFileHeader iHead;
447 ec = ReadHdr1(opt, vp->vnodeIndex[vLarge].handle, (char *)&iHead,
448 sizeof(iHead), LARGEINDEXMAGIC, LARGEINDEXVERSION);
452 struct versionStamp stamp;
453 ec = ReadHdr1(opt, V_linkHandle(vp), (char *)&stamp, sizeof(stamp),
454 LINKTABLEMAGIC, LINKTABLEVERSION);
463 * Simplified detach volume
465 * param[in] vp volume object from AttachVolume
470 DetachVolume(struct VolInfoOpt *opt, Volume * vp)
474 SYNC_response response;
475 memset(&response, 0, sizeof(response));
477 code = FSYNC_VolOp(V_id(vp), V_partition(vp)->name,
478 FSYNC_VOL_ON, FSYNC_WHATEVER, &response);
479 if (code != SYNC_OK) {
480 fprintf(stderr, "%s: FSSYNC error %d (%s)\n", progname, code,
481 SYNC_res2string(code));
482 fprintf(stderr, "%s: protocol response code was %d (%s)\n",
483 progname, response.hdr.response,
484 SYNC_res2string(response.hdr.response));
485 fprintf(stderr, "%s: protocol reason code was %d (%s)\n",
486 progname, response.hdr.reason,
487 FSYNC_reason2string(response.hdr.reason));
491 IH_RELEASE(vp->vnodeIndex[vLarge].handle);
492 IH_RELEASE(vp->vnodeIndex[vSmall].handle);
493 IH_RELEASE(vp->diskDataHandle);
494 IH_RELEASE(V_linkHandle(vp));
500 * Convert the partition device number into a partition name.
502 * @param[in] partId partition number, 0 to 254
503 * @param[out] partName buffer to hold partition name (e.g. /vicepa)
504 * @param[in] partNameSize size of partName buffer
508 * @retval -1 error, partId is out of range
509 * @retval -2 error, partition name exceeds partNameSize
512 GetPartitionName(afs_uint32 partId, char *partName, afs_size_t partNameSize)
514 const afs_uint32 OLD_NUM_DEVICES = 26; /* a..z */
516 if (partId < OLD_NUM_DEVICES) {
517 if (partNameSize < 8) {
520 strlcpy(partName, "/vicep", partNameSize);
521 partName[6] = partId + 'a';
525 if (partId < VOLMAXPARTS) {
526 if (partNameSize < 9) {
529 strlcpy(partName, "/vicep", partNameSize);
530 partId -= OLD_NUM_DEVICES;
531 partName[6] = 'a' + (partId / OLD_NUM_DEVICES);
532 partName[7] = 'a' + (partId % OLD_NUM_DEVICES);
540 * Scan the volumes in the partitions
542 * Scan the specified volume in the specified partition if both
543 * are given. Scan all the volumes in the specified partition if
544 * only the partition is given. If neither a partition nor volume
545 * is given, scan all the volumes in all the partitions. If only
546 * the volume is given, attempt to find it in the current working
549 * @param[in] partNameOrId partition name or id to be scannned
550 * @param[in] volumeId volume id to be scanned
552 * @return 0 if successful
555 volinfo_ScanPartitions(struct VolInfoOpt *opt, char *partNameOrId, VolumeId volumeId)
558 char partName[64] = "";
559 struct DiskPartition64 *partP = NULL;
562 if (!FSYNC_clientInit()) {
563 fprintf(stderr, "%s: Failed to connect to fileserver.\n",
570 /* Allow user to specify partition by name or id. */
572 afs_uint32 partId = volutil_GetPartitionID(partNameOrId);
574 fprintf(stderr, "%s: Could not parse '%s' as a partition name.\n",
575 progname, partNameOrId);
579 if (GetPartitionName(partId, partName, sizeof(partName))) {
581 "%s: Could not format '%s' as a partition name.\n",
582 progname, partNameOrId);
588 err = VAttachPartitions();
590 fprintf(stderr, "%s: %d partitions had errors during attach.\n",
597 partP = VGetPartition(partName, 0);
600 "%s: %s is not an AFS partition name on this server.\n",
608 if (opt->printHeading) {
609 PrintColumnHeading(opt);
614 HandlePart(opt, partP);
620 partP = FindCurrentPartition();
623 "%s: Current partition is not a vice partition.\n",
629 snprintf(name1, sizeof name1, VFORMAT,
630 afs_printable_VolumeId_lu(volumeId));
631 if (opt->printHeading) {
632 PrintColumnHeading(opt);
634 HandleVolume(opt, partP, name1);
645 * Add a vnode scanning procedure
647 * @param[in] class vnode class for this handler
648 * @param[in] proc handler proc to be called by HandleVnodes
649 * @param[in] heading optional string to pring before scanning vnodes
654 volinfo_AddVnodeHandler(int vnodeClass,
655 void (*proc) (struct VolInfoOpt * opt,
656 struct VnodeDetails * vdp), const char *heading)
658 struct VnodeScanProc *entry = malloc(sizeof(struct VnodeScanProc));
660 entry->heading = heading;
661 opr_queue_Append(&VnodeScanLists[vnodeClass], (struct opr_queue *)entry);
665 * Initialize the vol-info module.
668 volinfo_Init(const char *aprogname)
671 progname = aprogname; /* for error messages */
673 if (geteuid() != 0) {
674 fprintf(stderr, "%s: Must be run as root.\n", progname);
679 VInitVnodes(vLarge, 0);
680 VInitVnodes(vSmall, 0);
681 opr_queue_Init(&VnodeScanLists[vLarge]);
682 opr_queue_Init(&VnodeScanLists[vSmall]);
689 * Alloc an options structure with default values.
691 * The caller must free the options pointer after use.
693 * @param[out] optp address of options pointer
694 * @return 0 on success
697 volinfo_Options(struct VolInfoOpt **optp)
699 struct VolInfoOpt *opt;
701 opt = calloc(1, sizeof(struct VolInfoOpt));
703 fprintf(stderr, "%s: Failed to allocate options (%d).\n", progname, ENOMEM);
707 gethostname(opt->hostname, sizeof(opt->hostname));
708 opt->columnDelim[0] = ' ';
715 * Add a column type to be displayed.
717 * @param[in] name column type name
721 * @retval 1 too many columns
722 * @retval 2 invalid column name
725 volinfo_AddOutputColumn(char *name)
729 if (NumOutputColumns >= sizeof(OutputColumn) / sizeof(*OutputColumn)) {
730 fprintf(stderr, "%s: Too many output columns (%d).\n", progname,
734 for (i = 0; i < max_column_type; i++) {
735 if (!strcmp(ColumnName[i].name, name)) {
736 columnType t = ColumnName[i].type;
737 OutputColumn[NumOutputColumns++] = t;
750 * Determine if the current directory is a vice partition
752 * @return disk partition object
756 static struct DiskPartition64 *
757 FindCurrentPartition(void)
759 int dr = _getdrive();
760 struct DiskPartition64 *dp;
763 for (dp = DiskPartitionList; dp; dp = dp->next) {
764 if (*dp->devName - 'A' == dr)
768 fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
774 static struct DiskPartition64 *
775 FindCurrentPartition(void)
780 struct DiskPartition64 *dp;
782 if (!getcwd(partName, 1023)) {
783 fprintf(stderr, "%s: Failed to get current working directory: ",
788 p = strchr(&partName[1], OS_DIRSEPC);
793 if (!(dp = VGetPartition(partName, 0))) {
796 fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
805 * Scan and handle all the partitions detected on this server
810 HandleAllPart(struct VolInfoOpt *opt)
812 struct DiskPartition64 *partP;
814 for (partP = DiskPartitionList; partP; partP = partP->next) {
815 if (opt->dumpInfo || opt->saveInodes || opt->showSizes) {
816 printf("Processing Partition %s:\n", partP->name);
818 HandlePart(opt, partP);
819 if (opt->showSizes) {
820 AddSizeTotals(&serverTotals, &partitionTotals);
824 if (opt->showSizes) {
830 * Scan the partition and handle volumes
832 * @param[in] partP disk partition to scan
837 HandlePart(struct VolInfoOpt *opt, struct DiskPartition64 *partP)
845 (void)sprintf(pname, "%s\\", VPartitionPath(partP));
847 char *p = VPartitionPath(partP);
850 if ((dirp = opendir(p)) == NULL) {
851 fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
855 while ((dp = readdir(dirp))) {
856 p = (char *)strrchr(dp->d_name, '.');
857 if (p != NULL && strcmp(p, VHDREXT) == 0) {
858 HandleVolume(opt, partP, dp->d_name);
859 if (opt->showSizes) {
861 AddSizeTotals(&partitionTotals, &volumeTotals);
866 if (opt->showSizes) {
867 PrintPartitionTotals(nvols);
872 * Inspect a volume header special file.
874 * @param[in] name descriptive name of the type of header special file
875 * @param[in] dp partition object for this volume
876 * @param[in] header header object for this volume
877 * @param[in] inode fileserver inode number for this header special file
878 * @param[out] psize total of the header special file
883 HandleSpecialFile(struct VolInfoOpt *opt, const char *name, struct DiskPartition64 *dp,
884 struct VolumeHeader *header, Inode inode,
885 afs_sfsize_t * psize)
887 afs_sfsize_t size = -1;
888 IHandle_t *ih = NULL;
889 FdHandle_t *fdP = NULL;
892 #endif /* AFS_NAMEI_ENV */
894 IH_INIT(ih, dp->device, header->parent, inode);
898 "%s: Error opening header file '%s' for volume %" AFS_VOLID_FMT "\n", progname,
899 name, afs_printable_VolumeId_lu(header->id));
903 size = FDH_SIZE(fdP);
906 "%s: Error getting size of header file '%s' for volume %" AFS_VOLID_FMT "\n",
907 progname, name, afs_printable_VolumeId_lu(header->id));
915 printf("\t%s inode\t= %s (size = ", name, PrintInode(NULL, inode));
917 printf("%lld)\n", size);
919 printf("unknown)\n");
922 namei_HandleToName(&filename, ih);
923 printf("\t%s namei\t= %s\n", name, filename.n_path);
924 #endif /* AFS_NAMEI_ENV */
928 FDH_REALLYCLOSE(fdP);
936 * Inspect this volume header files.
938 * @param[in] dp partition object for this volume
939 * @param[in] header_fd volume header file descriptor
940 * @param[in] header volume header object
941 * @param[out] psize total of the header special file
946 HandleHeaderFiles(struct VolInfoOpt *opt, struct DiskPartition64 *dp, FD_t header_fd,
947 struct VolumeHeader *header)
949 afs_sfsize_t size = 0;
952 size = OS_SIZE(header_fd);
953 printf("Volume header (size = %lld):\n", size);
954 printf("\tstamp\t= 0x%x\n", header->stamp.version);
955 printf("\tVolId\t= %" AFS_VOLID_FMT "\n", afs_printable_VolumeId_lu(header->id));
956 printf("\tparent\t= %" AFS_VOLID_FMT "\n", afs_printable_VolumeId_lu(header->parent));
959 HandleSpecialFile(opt, "Info", dp, header, header->volumeInfo, &size);
960 HandleSpecialFile(opt, "Small", dp, header, header->smallVnodeIndex,
962 HandleSpecialFile(opt, "Large", dp, header, header->largeVnodeIndex,
965 HandleSpecialFile(opt, "Link", dp, header, header->linkTable, &size);
966 #endif /* AFS_NAMEI_ENV */
969 printf("Total aux volume size = %lld\n\n", size);
972 if (opt->showSizes) {
973 volumeTotals.auxsize = size;
974 volumeTotals.auxsize_k = size / 1024;
979 * Determine if the vnodes of this volume should be scanned.
981 * @param[in] vp volume object
983 * @return true if vnodes should be scanned
986 IsScannable(struct VolInfoOpt *opt, Volume * vp)
988 if (opr_queue_IsEmpty(&VnodeScanLists[vLarge]) &&
989 opr_queue_IsEmpty(&VnodeScanLists[vSmall])) {
992 if (!opt->scanVolType) {
993 return 1; /* filtering disabled; do not check vol type */
995 switch (V_type(vp)) {
997 return opt->scanVolType & SCAN_RW;
999 return opt->scanVolType & SCAN_RO;
1001 return opt->scanVolType & SCAN_BK;
1003 fprintf(stderr, "%s: Volume %" AFS_VOLID_FMT "; Unknown volume type %d\n", progname,
1004 afs_printable_VolumeId_lu(V_id(vp)), V_type(vp));
1011 * Attach and scan the volume and handle the header and vnodes
1013 * Print the volume header and vnode information, depending on the
1016 * @param[in] dp vice partition object for this volume
1017 * @param[in] name volume header file name
1022 HandleVolume(struct VolInfoOpt *opt, struct DiskPartition64 *dp, char *name)
1024 struct VolumeHeader header;
1025 struct VolumeDiskHeader diskHeader;
1026 FD_t fd = INVALID_FD;
1028 char headerName[1024];
1031 snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
1032 VPartitionPath(dp), name);
1033 if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD) {
1034 fprintf(stderr, "%s: Cannot open volume header %s\n", progname, name);
1037 if (OS_SIZE(fd) < 0) {
1038 fprintf(stderr, "%s: Cannot read volume header %s\n", progname, name);
1041 n = OS_READ(fd, &diskHeader, sizeof(diskHeader));
1042 if (n != sizeof(diskHeader)
1043 || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
1044 fprintf(stderr, "%s: Error reading volume header %s\n", progname,
1048 if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
1050 "%s: Volume %s, version number is incorrect; volume needs to be salvaged\n",
1055 DiskToVolumeHeader(&header, &diskHeader);
1056 if (opt->dumpHeader || opt->showSizes) {
1057 HandleHeaderFiles(opt, dp, fd, &header);
1060 vp = AttachVolume(opt, dp, name, &header);
1062 fprintf(stderr, "%s: Error attaching volume header %s\n",
1067 if (opt->dumpInfo) {
1070 if (IsScannable(opt, vp)) {
1072 IHandle_t *ih = vp->vnodeIndex[vLarge].handle;
1073 DirIndexFd = IH_OPEN(ih);
1074 if (DirIndexFd == NULL) {
1075 fprintf(stderr, "%s: Failed to open index for directories.",
1080 HandleVnodes(opt, vp, vLarge);
1081 HandleVnodes(opt, vp, vSmall);
1084 FDH_CLOSE(DirIndexFd);
1088 if (opt->showSizes) {
1089 volumeTotals.diskused_k = V_diskused(vp);
1090 volumeTotals.size_k =
1091 volumeTotals.auxsize_k + volumeTotals.vnodesize_k;
1092 if (opt->saveInodes) {
1093 PrintingVolumeSizes = 0; /* print heading again */
1095 PrintVolumeSizes(vp);
1099 if (fd != INVALID_FD) {
1103 DetachVolume(opt, vp);
1108 * Return a display string for the volume type.
1110 * @param[in] type volume type
1112 * @return volume type description string
1114 static_inline char *
1115 volumeTypeString(int type)
1118 (type == RWVOL ? "read/write" :
1119 (type == ROVOL ? "readonly" :
1120 (type == BACKVOL ? "backup" : "unknown")));
1124 * Return a short display string for the volume type.
1126 * @param[in] type volume type
1128 * @return volume type short description string
1130 static_inline char *
1131 volumeTypeShortString(int type)
1134 (type == RWVOL ? "RW" :
1135 (type == ROVOL ? "RO" : (type == BACKVOL ? "BK" : "??")));
1139 * Print the volume header information
1141 * @param[in] volume object
1146 PrintHeader(Volume * vp)
1148 printf("Volume header for volume %" AFS_VOLID_FMT " (%s)\n", afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
1149 printf("stamp.magic = %x, stamp.version = %u\n", V_stamp(vp).magic,
1150 V_stamp(vp).version);
1152 ("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n",
1153 V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp),
1156 ("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n",
1157 V_type(vp), volumeTypeString(V_type(vp)), V_uniquifier(vp),
1158 V_needsCallback(vp), V_destroyMe(vp));
1160 ("id = %" AFS_VOLID_FMT ", parentId = %" AFS_VOLID_FMT ", cloneId = %" AFS_VOLID_FMT ", backupId = %" AFS_VOLID_FMT ", restoredFromId = %" AFS_VOLID_FMT "\n",
1161 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 ("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n",
1164 V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp),
1166 printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)),
1167 date(V_copyDate(vp)));
1168 printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)),
1169 date(V_expirationDate(vp)));
1170 printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)),
1171 date(V_updateDate(vp)));
1172 printf("owner = %u, accountNumber = %u\n", V_owner(vp),
1173 V_accountNumber(vp));
1175 ("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n",
1176 V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2],
1177 V_weekUse(vp)[3], V_weekUse(vp)[4], V_weekUse(vp)[5],
1178 V_weekUse(vp)[6], date(V_dayUseDate(vp)));
1179 printf("volUpdateCounter = %u\n", V_volUpCounter(vp));
1183 * Get the size and times of a file
1185 * @param[in] fd file descriptor of file to stat
1186 * @param[out] size size of the file
1187 * @param[out] ctime ctime of file as a formatted string
1188 * @param[out] mtime mtime of file as a formatted string
1189 * @param[out] atime atime of file as a formatted string
1191 * @return error code
1193 * @retval -1 failed to retrieve file information
1196 GetFileInfo(FD_t fd, afs_sfsize_t * size, char **ctime, char **mtime,
1200 BY_HANDLE_FILE_INFORMATION fi;
1201 LARGE_INTEGER fsize;
1202 if (!GetFileInformationByHandle(fd, &fi)) {
1203 fprintf(stderr, "%s: GetFileInformationByHandle failed\n", progname);
1206 if (!GetFileSizeEx(fd, &fsize)) {
1207 fprintf(stderr, "%s: GetFileSizeEx failed\n", progname);
1210 *size = fsize.QuadPart;
1212 *mtime = NT_date(&fi.ftLastWriteTime);
1213 *atime = NT_date(&fi.ftLastAccessTime);
1215 struct afs_stat_st status;
1216 if (afs_fstat(fd, &status) == -1) {
1217 fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
1220 *size = status.st_size;
1221 *ctime = date(status.st_ctime);
1222 *mtime = date(status.st_mtime);
1223 *atime = date(status.st_atime);
1229 * Copy the inode data to a file in the current directory.
1231 * @param[in] vdp vnode details object
1236 volinfo_SaveInode(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1240 char nfile[50], buffer[256];
1244 Inode ino = VNDISK_GET_INO(vdp->vnode);
1246 if (!VALID_INO(ino)) {
1250 IH_INIT(ih, V_device(vdp->vp), V_parentId(vdp->vp), ino);
1254 "%s: Can't open inode %s error %d (ignored)\n",
1255 progname, PrintInode(NULL, ino), errno);
1258 snprintf(nfile, sizeof nfile, "TmpInode.%s", PrintInode(NULL, ino));
1259 ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
1262 "%s: Can't create file %s; error %d (ignored)\n",
1263 progname, nfile, errno);
1265 FDH_REALLYCLOSE(fdP);
1272 len = FDH_PREAD(fdP, buffer, sizeof(buffer), total);
1274 FDH_REALLYCLOSE(fdP);
1279 "%s: Error while reading from inode %s (%d)\n",
1280 progname, PrintInode(NULL, ino), errno);
1284 break; /* No more input */
1285 nBytes = write(ofd, buffer, (size_t)len);
1286 if (nBytes != len) {
1287 FDH_REALLYCLOSE(fdP);
1292 "%s: Error while writing to \"%s\" (%d - ignored)\n",
1293 progname, nfile, errno);
1299 FDH_REALLYCLOSE(fdP);
1302 printf("... Copied inode %s to file %s (%lu bytes)\n",
1303 PrintInode(NULL, ino), nfile, (unsigned long)total);
1307 * get the VnodeDiskObject for a directory given its vnode id.
1309 * @param[in] vp volume object
1310 * @param[in] parent vnode id to read
1311 * @param[out] pvn vnode disk object to populate
1313 * @post pvn contains copy of disk object for parent id
1315 * @return operation status
1317 * @retval -1 failure
1320 GetDirVnode(struct VolInfoOpt *opt, Volume * vp, VnodeId parent, VnodeDiskObject * pvn)
1326 return -1; /* previously failed to open the large vnode index. */
1328 if (parent % 2 == 0) {
1329 fprintf(stderr, "%s: Invalid parent vnode id %lu in volume %lu\n",
1331 afs_printable_uint32_lu(parent),
1332 afs_printable_uint32_lu(V_id(vp)));
1334 offset = vnodeIndexOffset(&VnodeClassInfo[vLarge], parent);
1335 code = FDH_SEEK(DirIndexFd, offset, 0);
1338 "%s: GetDirVnode: seek failed for %lu.%lu to offset %llu\n",
1339 progname, afs_printable_uint32_lu(V_id(vp)),
1340 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1343 code = FDH_READ(DirIndexFd, pvn, SIZEOF_LARGEDISKVNODE);
1344 if (code != SIZEOF_LARGEDISKVNODE) {
1346 "%s: GetDirVnode: read failed 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);
1351 if (opt->checkMagic && (pvn->vnodeMagic != LARGEVNODEMAGIC)) {
1352 fprintf(stderr, "%s: GetDirVnode: bad vnode magic 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);
1357 if (!pvn->dataVersion) {
1358 fprintf(stderr, "%s: GetDirVnode: dv is zero for %lu.%lu at offset %llu\n",
1359 progname, afs_printable_uint32_lu(V_id(vp)),
1360 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1367 * Perform inverse lookup on a vice directory object to map a fid onto a dirent string.
1369 * @param[in] vp volume object
1370 * @param[in] pvnode parent directory vnode object
1371 * @param[in] cvnid child vnode id to inverse lookup
1372 * @param[in] cuniq child uniquifier to inverse lookup
1373 * @param[out] dirent buffer in which to store dirent string
1374 * @param[out] dirent_len length of dirent buffer
1376 * @post dirent contains string for the (cvnid, cuniq) entry
1378 * @return operation status
1382 GetDirEntry(Volume * vp, VnodeDiskObject * pvnode, VnodeId cvnid,
1383 afs_uint32 cuniq, char *dirent, size_t dirent_len)
1390 ino = VNDISK_GET_INO(pvnode);
1391 if (!VALID_INO(ino)) {
1392 fprintf(stderr, "%s: GetDirEntry invalid parent ino\n", progname);
1395 SetSalvageDirHandle(&dir, V_parentId(vp), V_device(vp), ino,
1397 code = afs_dir_InverseLookup(&dir, cvnid, cuniq, dirent, dirent_len);
1399 fprintf(stderr, "%s: afs_dir_InverseLookup failed with code %d\n",
1407 * Lookup the path of this vnode, relative to the root of the volume.
1409 * @param[in] vdp vnode details
1416 LookupPath(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1418 #define MAX_PATH_LEN 1023
1419 static char path_buffer[MAX_PATH_LEN + 1];
1420 static char dirent[MAX_PATH_LEN + 1];
1421 char vnode_buffer[SIZEOF_LARGEDISKVNODE];
1422 struct VnodeDiskObject *pvn = (struct VnodeDiskObject *)vnode_buffer;
1426 Volume *vp = vdp->vp;
1427 VnodeId parent = vdp->vnode->parent;
1428 VnodeId cvnid = vdp->vnodeNumber;
1429 afs_uint32 cuniq = vdp->vnode->uniquifier;
1432 vdp->path = "/"; /* this is root */
1436 space = sizeof(path_buffer) - 1;
1437 cursor = &path_buffer[space];
1443 code = GetDirVnode(opt, vp, parent, pvn);
1448 code = GetDirEntry(vp, pvn, cvnid, cuniq, dirent, MAX_PATH_LEN);
1454 len = strlen(dirent);
1457 "%s: Failed to lookup path for fid %lu.%lu.%lu: empty dir entry\n",
1458 progname, afs_printable_uint32_lu(V_id(vdp->vp)),
1459 afs_printable_uint32_lu(vdp->vnodeNumber),
1460 afs_printable_uint32_lu(vdp->vnode->uniquifier));
1466 if (space < (len + 1)) {
1468 "%s: Failed to lookup path for fid %lu.%lu.%lu: path exceeds max length (%u).\n",
1469 progname, afs_printable_uint32_lu(V_id(vdp->vp)),
1470 afs_printable_uint32_lu(vdp->vnodeNumber),
1471 afs_printable_uint32_lu(vdp->vnode->uniquifier),
1478 /* prepend path component */
1480 memcpy(cursor, dirent, len);
1486 cuniq = pvn->uniquifier;
1487 parent = pvn->parent;
1497 * Read the symlink target and determine if this vnode is a mount point.
1499 * @param[inout] vdp vnode details object
1501 * @return error code
1503 * @retval -1 failure
1506 ReadSymlinkTarget(struct VnodeDetails *vdp)
1508 #define MAX_SYMLINK_LEN 1023
1509 static char buffer[MAX_SYMLINK_LEN + 1];
1511 Volume *vp = vdp->vp;
1512 VnodeDiskObject *vnode = vdp->vnode;
1513 VnodeId vnodeNumber = vdp->vnodeNumber;
1514 IHandle_t *ihP = NULL;
1515 FdHandle_t *fdP = NULL;
1516 afs_fsize_t fileLength;
1520 ino = VNDISK_GET_INO(vnode);
1521 VNDISK_GET_LEN(fileLength, vnode);
1523 if (fileLength > MAX_SYMLINK_LEN) {
1525 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) exceeds "
1526 "%u, file length is %llu)!\n", progname,
1527 afs_printable_uint32_lu(V_id(vp)),
1528 afs_printable_uint32_lu(vnodeNumber),
1529 afs_printable_uint32_lu(vnode->uniquifier),
1530 afs_printable_uint32_lu(vnode->dataVersion),
1535 if (fileLength == 0) {
1537 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) is empty.\n",
1539 afs_printable_uint32_lu(V_id(vp)),
1540 afs_printable_uint32_lu(vnodeNumber),
1541 afs_printable_uint32_lu(vnode->uniquifier),
1542 afs_printable_uint32_lu(vnode->dataVersion));
1546 IH_INIT(ihP, V_device(vp), V_parentId(vp), ino);
1552 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
1556 readLength = FDH_READ(fdP, buffer, fileLength);
1557 if (readLength < 0) {
1559 "%s: Error reading symlink contents for fid (%lu.%lu.%lu.%lu); "
1562 afs_printable_uint32_lu(V_id(vp)),
1563 afs_printable_uint32_lu(vnodeNumber),
1564 afs_printable_uint32_lu(vnode->uniquifier),
1565 afs_printable_uint32_lu(vnode->dataVersion), errno);
1568 } else if (readLength != fileLength) {
1570 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) don't match "
1571 "vnode file length metadata (len=%llu, actual=%lld)!\n",
1573 afs_printable_uint32_lu(V_id(vp)),
1574 afs_printable_uint32_lu(vnodeNumber),
1575 afs_printable_uint32_lu(vnode->uniquifier),
1576 afs_printable_uint32_lu(vnode->dataVersion), fileLength,
1577 (long long)readLength);
1583 if (readLength > 1 && (buffer[0] == '#' || buffer[0] == '%')
1584 && buffer[readLength - 1] == '.') {
1586 buffer[readLength - 1] = '\0'; /* stringify; clobbers trailing dot */
1587 sep = strchr(buffer, ':');
1588 vdp->t = VNODE_U_MOUNT;
1589 vdp->u.mnt.type = buffer[0];
1591 vdp->u.mnt.cell = NULL;
1592 vdp->u.mnt.vol = buffer + 1;
1595 vdp->u.mnt.cell = buffer + 1;
1596 vdp->u.mnt.vol = sep + 1;
1599 buffer[readLength] = '\0';
1600 vdp->t = VNODE_U_SYMLINK;
1601 vdp->u.target = buffer;
1615 * Print vnode details line
1617 * @param[inout] vdp vnode details object
1622 volinfo_PrintVnodeDetails(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1624 switch (vdp->vnode->type) {
1628 if (opt->findVnType & FIND_FILE) {
1629 PrintColumns(opt, vdp, "file");
1633 if (opt->findVnType & FIND_DIR) {
1634 PrintColumns(opt, vdp, "dir");
1638 if (opt->findVnType & (FIND_MOUNT | FIND_SYMLINK)) {
1639 ReadSymlinkTarget(vdp);
1640 if ((opt->findVnType & FIND_MOUNT) && (vdp->t == VNODE_U_MOUNT)) {
1641 PrintColumns(opt, vdp, "mount");
1643 if ((opt->findVnType & FIND_SYMLINK) && (vdp->t == VNODE_U_SYMLINK)) {
1644 PrintColumns(opt, vdp, "symlink");
1650 "%s: Warning: unexpected vnode type %u on fid %lu.%lu.%lu",
1651 progname, vdp->vnode->type,
1652 afs_printable_uint32_lu(V_id(vdp->vp)),
1653 afs_printable_uint32_lu(vdp->vnodeNumber),
1654 afs_printable_uint32_lu(vdp->vnode->uniquifier));
1659 * Print each access entry of a vnode
1661 * @param[in] vdp vnode details object
1666 volinfo_ScanAcl(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1669 struct acl_accessList *acl;
1670 VnodeDiskObject *vnode = vdp->vnode;
1672 if (vnode->type == vNull) {
1676 acl = VVnodeDiskACL(vnode);
1677 for (i = 0; i < acl->positive; i++) {
1678 vdp->t = VNODE_U_POS_ACCESS;
1679 vdp->u.access = &(acl->entries[i]);
1680 PrintColumns(opt, vdp, "acl");
1682 for (i = (acl->total - 1); i >= (acl->total - acl->negative); i--) {
1683 vdp->t = VNODE_U_NEG_ACCESS;
1684 vdp->u.access = &(acl->entries[i]);
1685 PrintColumns(opt, vdp, "acl");
1690 * Determine if the mode matches all the given masks.
1692 * Returns true if the mode bits match all the given masks. A mask matches if at
1693 * least one bit in the mask is present in the mode bits. An empty mode mask
1694 * list matches all modes (even if all the mode bits are zero.)
1696 * param[in] modeBits unix mode bits of a vnode
1700 ModeMaskMatch(struct VolInfoOpt *opt, unsigned int modeBits)
1704 for (i = 0; i < sizeof(opt->modeMask) / sizeof(*opt->modeMask) && opt->modeMask[i]; i++) {
1705 if ((opt->modeMask[i] & modeBits) == 0) {
1706 return 0; /* at least one mode bit is not present */
1713 * Scan a volume index and handle each vnode
1715 * @param[in] vp volume object
1716 * @param[in] class which index to scan
1721 HandleVnodes(struct VolInfoOpt *opt, Volume * vp, VnodeClass class)
1723 afs_int32 diskSize =
1724 (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE);
1725 char buf[SIZEOF_LARGEDISKVNODE];
1726 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1727 StreamHandle_t *file = NULL;
1729 afs_sfsize_t nVnodes;
1730 afs_foff_t offset = 0;
1731 IHandle_t *ih = vp->vnodeIndex[class].handle;
1732 FdHandle_t *fdP = NULL;
1734 char *ctime, *atime, *mtime;
1735 struct opr_queue *scanList = &VnodeScanLists[class];
1736 struct opr_queue *cursor;
1738 if (opr_queue_IsEmpty(scanList)) {
1742 for (opr_queue_Scan(scanList, cursor)) {
1743 struct VnodeScanProc *entry = (struct VnodeScanProc *)cursor;
1744 if (entry->heading) {
1745 printf("%s", entry->heading);
1751 fprintf(stderr, "%s: open failed: ", progname);
1755 file = FDH_FDOPEN(fdP, "r");
1757 fprintf(stderr, "%s: fdopen failed\n", progname);
1761 if (GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime) != 0) {
1764 if (opt->dumpInodeTimes) {
1765 printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime,
1769 nVnodes = (size / diskSize) - 1;
1771 STREAM_ASEEK(file, diskSize);
1775 for (vnodeIndex = 0;
1776 nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1;
1777 nVnodes--, vnodeIndex++, offset += diskSize) {
1779 struct VnodeDetails vnodeDetails;
1781 if (!ModeMaskMatch(opt, vnode->modeBits)) {
1785 memset(&vnodeDetails, 0, sizeof(struct VnodeDetails));
1786 vnodeDetails.vp = vp;
1787 vnodeDetails.class = class;
1788 vnodeDetails.vnode = vnode;
1789 vnodeDetails.vnodeNumber = bitNumberToVnodeNumber(vnodeIndex, class);
1790 vnodeDetails.offset = offset;
1791 vnodeDetails.index = vnodeIndex;
1793 for (opr_queue_Scan(scanList, cursor)) {
1794 struct VnodeScanProc *entry = (struct VnodeScanProc *)cursor;
1796 (*entry->proc) (opt, &vnodeDetails);
1811 * Print vnode information
1813 * @param[in] vdp vnode details object
1818 volinfo_PrintVnode(struct VolInfoOpt *opt, struct VnodeDetails *vdp)
1820 #if defined(AFS_NAMEI_ENV)
1824 afs_foff_t offset = vdp->offset;
1825 VnodeDiskObject *vnode = vdp->vnode;
1826 afs_fsize_t fileLength;
1829 ino = VNDISK_GET_INO(vnode);
1830 VNDISK_GET_LEN(fileLength, vnode);
1832 /* The check for orphaned vnodes is currently limited to non-empty
1833 * vnodes with a parent of zero (and which are not the first entry
1835 if (opt->showOrphaned && (fileLength == 0 || vnode->parent || !offset))
1839 ("%10lld Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
1840 (long long)offset, vdp->vnodeNumber, vnode->uniquifier,
1841 vnode->dataVersion, vnode->cloned, (afs_uintmax_t) fileLength,
1842 vnode->linkCount, vnode->parent);
1843 if (opt->dumpInodeNumber)
1844 printf(" inode: %s", PrintInode(NULL, ino));
1846 printf(" ServerModTime: %s", date(vnode->serverModifyTime));
1847 #if defined(AFS_NAMEI_ENV)
1848 if (opt->dumpFileNames) {
1849 IH_INIT(ihtmpp, V_device(vdp->vp), V_parentId(vdp->vp), ino);
1850 namei_HandleToName(&filename, ihtmpp);
1851 #if !defined(AFS_NT40_ENV)
1852 printf(" UFS-Filename: %s", filename.n_path);
1854 printf(" NTFS-Filename: %s", filename.n_path);
1862 * Print the volume partition id
1864 * @param[in] vp volume object
1869 PrintPartitionId(Volume * vp)
1871 char *partition = VPartitionPath(V_partition(vp));
1873 if (!strncmp(partition, "/vicep", 6)) {
1874 printf("%s", partition + 6);
1875 } else if (!strncmp(partition, "vicep", 5)) {
1876 printf("%s", partition + 5);
1878 fprintf(stderr, "Invalid partition for volume id %lu\n",
1879 afs_printable_uint32_lu(V_id(vp)));
1880 printf("%s", PLACEHOLDER);
1885 * Print the vnode type description string
1887 * @param[in] type vnode type
1892 volinfo_PrintVnodeType(int type)
1913 * Print right bits as string.
1915 * param[in] rights rights bitmap
1918 PrintRights(int rights)
1920 if (rights & PRSFS_READ) {
1923 if (rights & PRSFS_LOOKUP) {
1926 if (rights & PRSFS_INSERT) {
1929 if (rights & PRSFS_DELETE) {
1932 if (rights & PRSFS_WRITE) {
1935 if (rights & PRSFS_LOCK) {
1938 if (rights & PRSFS_ADMINISTER) {
1941 if (rights & PRSFS_USR0) {
1944 if (rights & PRSFS_USR1) {
1947 if (rights & PRSFS_USR2) {
1950 if (rights & PRSFS_USR3) {
1953 if (rights & PRSFS_USR4) {
1956 if (rights & PRSFS_USR5) {
1959 if (rights & PRSFS_USR6) {
1962 if (rights & PRSFS_USR7) {
1968 * Print the path to the namei file.
1971 PrintNamei(Volume * vp, VnodeDiskObject * vnode)
1973 #ifdef AFS_NAMEI_ENV
1975 IHandle_t *ihP = NULL;
1977 ino = VNDISK_GET_INO(vnode);
1978 IH_INIT(ihP, V_device(vp), V_parentId(vp), ino);
1979 namei_HandleToName(&name, ihP);
1980 printf("%s", name.n_path);
1983 printf("%s", PLACEHOLDER);
1988 * Print the column heading line.
1991 PrintColumnHeading(struct VolInfoOpt *opt)
1996 for (i = 0; i < NumOutputColumns; i++) {
1998 printf("%s", opt->columnDelim);
2000 name = ColumnName[OutputColumn[i]].name;
2002 putchar(toupper(*name++));
2009 * Print output columns for the vnode/acess entry.
2011 * @param[in] vdp vnode details object
2012 * @param[in] desc type of line to be printed
2017 PrintColumns(struct VolInfoOpt *opt, struct VnodeDetails *vdp, const char *desc)
2022 for (i = 0; i < NumOutputColumns; i++) {
2024 printf("%s", opt->columnDelim);
2026 switch (OutputColumn[i]) {
2028 printf("%s", opt->hostname);
2034 printf("%lu", afs_printable_uint32_lu(V_id(vdp->vp)));
2037 printf("%llu", vdp->offset);
2040 printf("%s", volumeTypeShortString(V_type(vdp->vp)));
2043 printf("%s", V_name(vdp->vp));
2046 printf("%s", VPartitionPath(V_partition(vdp->vp)));
2049 PrintPartitionId(vdp->vp);
2052 printf("%lu.%lu.%lu",
2053 afs_printable_uint32_lu(V_id(vdp->vp)),
2054 afs_printable_uint32_lu(vdp->vnodeNumber),
2055 afs_printable_uint32_lu(vdp->vnode->uniquifier));
2059 LookupPath(opt, vdp);
2061 printf("%s", vdp->path ? vdp->path : PLACEHOLDER);
2065 (vdp->t == VNODE_U_SYMLINK ? vdp->u.target : PLACEHOLDER));
2068 if (vdp->t != VNODE_U_MOUNT) {
2069 printf("%s", PLACEHOLDER);
2071 printf("%c", vdp->u.mnt.type);
2072 if (vdp->u.mnt.cell) {
2073 printf("%s:", vdp->u.mnt.cell);
2075 printf("%s.", vdp->u.mnt.vol);
2079 printf("%c", (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.type : '-'));
2083 (vdp->t == VNODE_U_MOUNT && vdp->u.mnt.cell ? vdp->u.mnt.cell : PLACEHOLDER));
2087 (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.vol : PLACEHOLDER));
2090 if (vdp->t == VNODE_U_POS_ACCESS || vdp->t == VNODE_U_NEG_ACCESS) {
2091 printf("%d", vdp->u.access->id);
2093 printf("%s", PLACEHOLDER);
2097 if (vdp->t == VNODE_U_POS_ACCESS) {
2099 PrintRights(vdp->u.access->rights);
2100 } else if (vdp->t == VNODE_U_NEG_ACCESS) {
2102 PrintRights(vdp->u.access->rights);
2106 volinfo_PrintVnodeType(vdp->vnode->type);
2109 printf("%c", vdp->vnode->cloned ? 'y' : 'n');
2112 printf("0%o", vdp->vnode->modeBits);
2115 printf("%lu", afs_printable_uint32_lu(vdp->vnode->linkCount));
2118 VNDISK_GET_LEN(length, vdp->vnode);
2119 printf("%llu", length);
2122 printf("%lu", afs_printable_uint32_lu(vdp->vnode->uniquifier));
2125 printf("%lu", afs_printable_uint32_lu(vdp->vnode->dataVersion));
2128 printf("%" AFS_UINT64_FMT, VNDISK_GET_INO(vdp->vnode));
2131 PrintNamei(vdp->vp, vdp->vnode);
2135 afs_printable_uint32_lu(vdp->vnode->unixModifyTime));
2138 printf("%lu", afs_printable_uint32_lu(vdp->vnode->author));
2141 printf("%lu", afs_printable_uint32_lu(vdp->vnode->owner));
2144 printf("%lu", afs_printable_uint32_lu(vdp->vnode->parent));
2147 printf("0x%08X", vdp->vnode->vnodeMagic);
2151 afs_printable_uint32_lu(vdp->vnode->lock.lockCount),
2152 afs_printable_uint32_lu(vdp->vnode->lock.lockTime));
2156 afs_printable_uint32_lu(vdp->vnode->serverModifyTime));
2159 printf("%lu", afs_printable_uint32_lu(vdp->vnode->group));
2162 fprintf(stderr, "%s: Unknown column type: %d (%d)\n", progname,
2163 OutputColumn[i], i);