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 <opr/queue.h>
41 #include "partition.h"
43 #include "daemon_com_inline.h"
44 #include "fssync_inline.h"
47 #include "AFS_component_version_number.c"
50 static const char *progname = NULL;
51 static const char *PLACEHOLDER = "-";
53 /* Command line options */
77 * volscan output columns
79 #define VOLSCAN_COLUMNS \
114 /* Numeric column type ids */
115 typedef enum columnType {
116 #define c(x) col_##x,
127 /* Table of id:name tuples of possible columns. */
128 struct columnName ColumnName[] = {
129 #define c(x) { col_##x, #x },
132 {max_column_type, NULL}
135 /* All columns names as a single string. */
137 static char *ColumnNames = VOLSCAN_COLUMNS;
139 #undef VOLSCAN_COLUMNS
142 /* VnodeDetails union descriminator */
151 struct VnodeDetails {
154 VnodeDiskObject *vnode;
167 struct acl_accessEntry *access;
172 static int Checkout = 0; /**< Use FSSYNC to checkout volumes from the fileserver. */
173 static int DumpInfo = 0; /**< Dump volume information */
174 static int DumpHeader = 0; /**< Dump volume header files info */
175 static int DumpVnodes = 0; /**< Dump vnode info */
176 static int DumpInodeNumber = 0; /**< Dump inode numbers with vnodes */
177 static int DumpDate = 0; /**< Dump vnode date (server modify date) with vnode */
178 static int InodeTimes = 0; /**< Dump some of the dates associated with inodes */
179 #if defined(AFS_NAMEI_ENV)
180 static int PrintFileNames = 0; /**< Dump vnode and special file name filenames */
182 static int ShowOrphaned = 0; /**< Show "orphaned" vnodes (vnodes with parent of 0) */
183 static int ShowSizes = 0; /**< Show volume size summary */
184 static int SaveInodes = 0; /**< Save vnode data to files */
185 static int FixHeader = 0; /**< Repair header files magic and version fields. */
186 static char Hostname[64] = ""; /**< This hostname, for volscan output. */
187 static int NeedDirIndex = 0; /**< Large vnode index handle is needed for path lookups. */
188 static char *ColumnDelim = " "; /**< Column delimiter char(s) */
189 static char PrintHeading = 0; /**< Print column heading */
190 static unsigned int ModeMask[64];
192 static FdHandle_t *DirIndexFd = NULL; /**< Current large vnode index handle for path lookups. */
194 static int NumOutputColumns = 0;
195 static columnType OutputColumn[max_column_type];
197 #define SCAN_RW 0x01 /**< scan read-write volumes vnodes */
198 #define SCAN_RO 0x02 /**< scan read-only volume vnodes */
199 #define SCAN_BK 0x04 /**< scan backup volume vnodes */
200 static int ScanVolType = 0; /**< volume types to scan; zero means do not check */
202 #define FIND_FILE 0x01 /**< find regular files */
203 #define FIND_DIR 0x02 /**< find directories */
204 #define FIND_MOUNT 0x04 /**< find afs mount points */
205 #define FIND_SYMLINK 0x08 /**< find symlinks */
206 #define FIND_ACL 0x10 /**< find access entiries */
207 static int FindVnType = 0; /**< types of objects to find */
210 * Volume size running totals
213 afs_uint64 diskused_k; /**< volume size from disk data file, in kilobytes */
214 afs_uint64 auxsize; /**< size of header files, in bytes */
215 afs_uint64 auxsize_k; /**< size of header files, in kilobytes */
216 afs_uint64 vnodesize; /**< size of the large and small vnodes, in bytes */
217 afs_uint64 vnodesize_k; /**< size of the large and small vnodes, in kilobytes */
218 afs_uint64 size_k; /**< size of headers and vnodes, in kilobytes */
221 static struct sizeTotals volumeTotals = { 0, 0, 0, 0, 0, 0 };
222 static struct sizeTotals partitionTotals = { 0, 0, 0, 0, 0, 0 };
223 static struct sizeTotals serverTotals = { 0, 0, 0, 0, 0, 0 };
224 static int PrintingVolumeSizes = 0; /*print volume size lines */
227 * List of procedures to call when scanning vnodes.
229 struct VnodeScanProc {
230 struct opr_queue link;
232 void (*proc) (struct VnodeDetails * vdp);
234 static struct opr_queue VnodeScanLists[nVNODECLASSES];
236 /* Forward Declarations */
237 void PrintHeader(Volume * vp);
238 void HandleAllPart(void);
239 void HandlePart(struct DiskPartition64 *partP);
240 void HandleVolume(struct DiskPartition64 *partP, char *name);
241 struct DiskPartition64 *FindCurrentPartition(void);
242 Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
243 struct VolumeHeader *header);
244 void HandleVnodes(Volume * vp, VnodeClass class);
245 static void AddVnodeToSizeTotals(struct VnodeDetails *vdp);
246 static void SaveInode(struct VnodeDetails *vdp);
247 static void PrintVnode(struct VnodeDetails *vdp);
248 static void PrintVnodeDetails(struct VnodeDetails *vdp);
249 static void ScanAcl(struct VnodeDetails *vdp);
250 static void PrintColumnHeading(void);
251 static void PrintColumns(struct VnodeDetails *vdp, const char *desc);
254 extern void SetSalvageDirHandle(DirHandle * dir, afs_int32 volume,
255 Device device, Inode inode,
257 extern void FidZap(DirHandle * file);
260 * Format time as a timestamp string
262 * @param[in] date time value to format
264 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
266 * @note A static array of 8 strings are stored by this
267 * function. The array slots are overwritten, so the
268 * caller must not reference the returned string after
269 * seven additional calls to this function.
274 #define MAX_DATE_RESULT 100
275 static char results[8][MAX_DATE_RESULT];
277 struct tm *tm = localtime(&date);
280 (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm); /* NT does not have %T */
281 snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT,
282 "%lu (%s)", (unsigned long)date, buf);
283 return results[next];
288 * Format file time as a timestamp string
290 * @param[in] ft file time
292 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
294 * @note A static array of 8 strings are stored by this
295 * function. The array slots are overwritten, so the
296 * caller must not reference the returned string after
297 * seven additional calls to this function.
300 NT_date(FILETIME * ft)
302 static char result[8][64];
307 if (!FileTimeToLocalFileTime(ft, &lft)
308 || !FileTimeToSystemTime(&lft, &st)) {
309 fprintf(stderr, "%s: Time conversion failed.\n", progname);
312 sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
313 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
319 * Add vnode size to the running volume totals.
321 * @param[in] vdp vnode details object
326 AddVnodeToSizeTotals(struct VnodeDetails *vdp)
328 afs_fsize_t fileLength;
330 VNDISK_GET_LEN(fileLength, vdp->vnode);
331 if (fileLength > 0) {
332 volumeTotals.vnodesize += fileLength;
333 volumeTotals.vnodesize_k += fileLength / 1024;
338 * Print the volume size table heading line, if needed.
343 PrintVolumeSizeHeading(void)
345 if (!PrintingVolumeSizes) {
347 ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n");
348 PrintingVolumeSizes = 1;
358 AddSizeTotals(struct sizeTotals *a, struct sizeTotals *b)
360 a->diskused_k += b->diskused_k;
361 a->auxsize += b->auxsize;
362 a->auxsize_k += b->auxsize_k;
363 a->vnodesize += b->vnodesize;
364 a->vnodesize_k += b->vnodesize_k;
365 a->size_k += b->size_k;
369 * Print the sizes for a volume.
374 PrintVolumeSizes(Volume * vp)
376 afs_int64 diff_k = volumeTotals.size_k - volumeTotals.diskused_k;
378 PrintVolumeSizeHeading();
379 printf("%u\t%9llu%9llu%10llu%10llu%9lld\t%24s\n",
381 volumeTotals.diskused_k,
382 volumeTotals.auxsize_k, volumeTotals.vnodesize_k,
383 volumeTotals.size_k, diff_k, V_name(vp));
387 * Print the size totals for the partition.
392 PrintPartitionTotals(afs_uint64 nvols)
394 afs_int64 diff_k = partitionTotals.size_k - partitionTotals.diskused_k;
396 PrintVolumeSizeHeading();
397 printf("\nPart Totals %12llu%9llu%10llu%10llu%9lld (%llu volumes)\n\n",
398 partitionTotals.diskused_k, partitionTotals.auxsize,
399 partitionTotals.vnodesize, partitionTotals.size_k, diff_k, nvols);
400 PrintingVolumeSizes = 0;
404 * Print the size totals for all the partitions.
409 PrintServerTotals(void)
411 afs_int64 diff_k = serverTotals.size_k - serverTotals.diskused_k;
413 printf("\nServer Totals%12lld%9lld%10lld%10lld%9lld\n",
414 serverTotals.diskused_k, serverTotals.auxsize,
415 serverTotals.vnodesize, serverTotals.size_k, diff_k);
419 * Read a volume header file
421 * @param[in] ih ihandle of the header file
422 * @param[in] to destination
423 * @param[in] size expected header size
424 * @param[in] magic expected header magic number
425 * @param[in] version expected header version number
429 * @retval -1 failed to read file
432 ReadHdr1(IHandle_t * ih, char *to, afs_sfsize_t size, u_int magic, u_int version)
434 struct versionStamp *vsn;
438 vsn = (struct versionStamp *)to;
440 code = IH_IREAD(ih, 0, to, size);
444 if (vsn->magic != magic) {
446 fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
447 progname, PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
450 /* Check is conditional, in case caller wants to inspect version himself */
451 if (version && vsn->version != version) {
453 fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
455 PrintInode(NULL, ih->ih_ino), vsn->version, version);
457 if (bad && FixHeader) {
459 vsn->version = version;
460 printf("Special index inode %s has a bad header. Reconstructing...\n",
461 PrintInode(NULL, ih->ih_ino));
462 code = IH_IWRITE(ih, 0, to, size);
465 "%s: Write failed for inode %s; header left in damaged state\n",
466 progname, PrintInode(NULL, ih->ih_ino));
469 if (!bad && DumpInfo) {
470 printf("Inode %s: Good magic %x and version %x\n",
471 PrintInode(NULL, ih->ih_ino), magic, version);
477 * Simplified attach volume
479 * param[in] dp vice disk partition object
480 * param[in] volname volume header file name
481 * param[in] header volume header object
483 * @return volume object or null on error
486 AttachVolume(struct DiskPartition64 * dp, char *volname,
487 struct VolumeHeader * header)
494 SYNC_response response;
495 VolumeId volid = header->id;
497 memset(&response, 0, sizeof(response));
499 FSYNC_VolOp(volid, dp->name, FSYNC_VOL_NEEDVOLUME, V_DUMP,
501 if (code != SYNC_OK) {
502 if (response.hdr.reason == FSYNC_SALVAGE) {
504 "%s: file server says volume %lu is salvaging.\n",
505 progname, afs_printable_uint32_lu(volid));
509 "%s: attach of volume %lu denied by file server.\n",
510 progname, afs_printable_uint32_lu(volid));
516 vp = (Volume *) calloc(1, sizeof(Volume));
518 fprintf(stderr, "%s: Failed to allocate volume object.\n", progname);
521 vp->specialStatus = 0;
522 vp->device = dp->device;
524 IH_INIT(vp->vnodeIndex[vLarge].handle, dp->device, header->parent,
525 header->largeVnodeIndex);
526 IH_INIT(vp->vnodeIndex[vSmall].handle, dp->device, header->parent,
527 header->smallVnodeIndex);
528 IH_INIT(vp->diskDataHandle, dp->device, header->parent,
530 IH_INIT(V_linkHandle(vp), dp->device, header->parent, header->linkTable);
531 vp->cacheCheck = 0; /* XXXX */
532 vp->shuttingDown = 0;
533 vp->goingOffline = 0;
535 vp->header = (struct volHeader *)calloc(1, sizeof(*vp->header));
537 fprintf(stderr, "%s: Failed to allocate volume header.\n", progname);
541 ec = ReadHdr1(V_diskDataHandle(vp), (char *)&V_disk(vp),
542 sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
544 struct IndexFileHeader iHead;
545 ec = ReadHdr1(vp->vnodeIndex[vSmall].handle, (char *)&iHead,
546 sizeof(iHead), SMALLINDEXMAGIC, SMALLINDEXVERSION);
549 struct IndexFileHeader iHead;
550 ec = ReadHdr1(vp->vnodeIndex[vLarge].handle, (char *)&iHead,
551 sizeof(iHead), LARGEINDEXMAGIC, LARGEINDEXVERSION);
555 struct versionStamp stamp;
556 ec = ReadHdr1(V_linkHandle(vp), (char *)&stamp, sizeof(stamp),
557 LINKTABLEMAGIC, LINKTABLEVERSION);
566 * Simplified detach volume
568 * param[in] vp volume object from AttachVolume
573 DetachVolume(Volume * vp)
577 SYNC_response response;
578 memset(&response, 0, sizeof(response));
580 code = FSYNC_VolOp(V_id(vp), V_partition(vp)->name,
581 FSYNC_VOL_ON, FSYNC_WHATEVER, &response);
582 if (code != SYNC_OK) {
583 fprintf(stderr, "%s: FSSYNC error %d (%s)\n", progname, code,
584 SYNC_res2string(code));
585 fprintf(stderr, "%s: protocol response code was %d (%s)\n",
586 progname, response.hdr.response,
587 SYNC_res2string(response.hdr.response));
588 fprintf(stderr, "%s: protocol reason code was %d (%s)\n",
589 progname, response.hdr.reason,
590 FSYNC_reason2string(response.hdr.reason));
594 IH_RELEASE(vp->vnodeIndex[vLarge].handle);
595 IH_RELEASE(vp->vnodeIndex[vSmall].handle);
596 IH_RELEASE(vp->diskDataHandle);
597 IH_RELEASE(V_linkHandle(vp));
603 * Convert the partition device number into a partition name.
605 * @param[in] partId partition number, 0 to 254
606 * @param[out] partName buffer to hold partition name (e.g. /vicepa)
607 * @param[in] partNameSize size of partName buffer
611 * @retval -1 error, partId is out of range
612 * @retval -2 error, partition name exceeds partNameSize
615 GetPartitionName(afs_uint32 partId, char *partName, afs_size_t partNameSize)
617 const afs_uint32 OLD_NUM_DEVICES = 26; /* a..z */
619 if (partId < OLD_NUM_DEVICES) {
620 if (partNameSize < 8) {
623 strlcpy(partName, "/vicep", partNameSize);
624 partName[6] = partId + 'a';
628 if (partId < VOLMAXPARTS) {
629 if (partNameSize < 9) {
632 strlcpy(partName, "/vicep", partNameSize);
633 partId -= OLD_NUM_DEVICES;
634 partName[6] = 'a' + (partId / OLD_NUM_DEVICES);
635 partName[7] = 'a' + (partId % OLD_NUM_DEVICES);
643 * Scan the volumes in the partitions
645 * Scan the specified volume in the specified partition if both
646 * are given. Scan all the volumes in the specified partition if
647 * only the partition is given. If neither a partition nor volume
648 * is given, scan all the volumes in all the partitions. If only
649 * the volume is given, attempt to find it in the current working
652 * @param[in] partNameOrId partition name or id to be scannned
653 * @param[in] volumeId volume id to be scanned
655 * @return 0 if successful
658 ScanPartitions(char *partNameOrId, afs_uint32 volumeId)
661 char partName[64] = "";
662 struct DiskPartition64 *partP = NULL;
665 if (geteuid() != 0) {
666 fprintf(stderr, "%s: Must be run as root; sorry\n", progname);
672 if (!FSYNC_clientInit()) {
673 fprintf(stderr, "%s: Failed to connect to fileserver.\n",
680 VInitVnodes(vLarge, 0);
681 VInitVnodes(vSmall, 0);
683 /* Allow user to specify partition by name or id. */
685 afs_uint32 partId = volutil_GetPartitionID(partNameOrId);
687 fprintf(stderr, "%s: Could not parse '%s' as a partition name.\n",
688 progname, partNameOrId);
692 if (GetPartitionName(partId, partName, sizeof(partName))) {
694 "%s: Could not format '%s' as a partition name.\n",
695 progname, partNameOrId);
701 err = VAttachPartitions();
703 fprintf(stderr, "%s: %d partitions had errors during attach.\n",
710 partP = VGetPartition(partName, 0);
713 "%s: %s is not an AFS partition name on this server.\n",
722 PrintColumnHeading();
733 partP = FindCurrentPartition();
736 "%s: Current partition is not a vice partition.\n",
742 snprintf(name1, sizeof name1, VFORMAT,
743 afs_printable_uint32_lu(volumeId));
745 PrintColumnHeading();
747 HandleVolume(partP, name1);
758 * Add a vnode scanning procedure
760 * @param[in] class vnode class for this handler
761 * @param[in] proc handler proc to be called by HandleVnodes
762 * @param[in] heading optional string to pring before scanning vnodes
767 AddVnodeHandler(VnodeClass class, void (*proc) (struct VnodeDetails * vdp),
770 struct VnodeScanProc *entry = malloc(sizeof(struct VnodeScanProc));
772 entry->heading = heading;
773 opr_queue_Append(&VnodeScanLists[class], (struct opr_queue *)entry);
777 * Process command line options and start scanning
779 * @param[in] as command syntax object
780 * @param[in] arock opaque object; not used
785 VolInfo(struct cmd_syndesc *as, void *arock)
788 afs_uint32 volumeId = 0;
789 char *partNameOrId = NULL;
791 DumpInfo = 1; /* volinfo default mode */
793 if (as->parms[P_CHECKOUT].items) {
796 if (as->parms[P_VNODE].items) {
799 if (as->parms[P_DATE].items) {
802 if (as->parms[P_INODE].items) {
805 if (as->parms[P_ITIME].items) {
808 if ((ti = as->parms[P_PART].items)) {
809 partNameOrId = ti->data;
811 if ((ti = as->parms[P_VOLUMEID].items)) {
812 volumeId = strtoul(ti->data, NULL, 10);
814 if (as->parms[P_HEADER].items) {
817 if (as->parms[P_SIZEONLY].items) {
820 if (as->parms[P_FIXHEADER].items) {
823 if (as->parms[P_SAVEINODES].items) {
826 if (as->parms[P_ORPHANED].items) {
829 #if defined(AFS_NAMEI_ENV)
830 if (as->parms[P_FILENAMES].items) {
835 /* -saveinodes and -sizeOnly override the default mode.
836 * For compatibility with old versions of volinfo, -orphaned
837 * and -filename options imply -vnodes */
838 if (SaveInodes || ShowSizes) {
844 } else if (ShowOrphaned) {
845 DumpVnodes = 1; /* implied */
847 } else if (PrintFileNames) {
848 DumpVnodes = 1; /* implied */
853 AddVnodeHandler(vSmall, SaveInode,
854 "Saving all volume files to current directory ...\n");
857 AddVnodeHandler(vLarge, AddVnodeToSizeTotals, NULL);
858 AddVnodeHandler(vSmall, AddVnodeToSizeTotals, NULL);
861 AddVnodeHandler(vLarge, PrintVnode, "\nLarge vnodes (directories)\n");
862 AddVnodeHandler(vSmall, PrintVnode,
863 "\nSmall vnodes(files, symbolic links)\n");
865 return ScanPartitions(partNameOrId, volumeId);
869 * Add a column type to be displayed.
871 * @param[in] name column type name
875 * @retval 1 too many columns
876 * @retval 2 invalid column name
879 AddOutputColumn(char *name)
883 if (NumOutputColumns >= sizeof(OutputColumn) / sizeof(*OutputColumn)) {
884 fprintf(stderr, "%s: Too many output columns (%d).\n", progname,
888 for (i = 0; i < max_column_type; i++) {
889 if (!strcmp(ColumnName[i].name, name)) {
890 columnType t = ColumnName[i].type;
891 OutputColumn[NumOutputColumns++] = t;
903 * Process command line options and start scanning
905 * @param[in] as command syntax object
906 * @param[in] arock opaque object; not used
913 VolScan(struct cmd_syndesc *as, void *arock)
916 afs_uint32 volumeId = 0;
917 char *partNameOrId = NULL;
920 if (as->parms[P_CHECKOUT].items) {
923 if ((ti = as->parms[P_PART].items)) {
924 partNameOrId = ti->data;
926 if ((ti = as->parms[P_VOLUMEID].items)) {
927 volumeId = strtoul(ti->data, NULL, 10);
929 if (as->parms[P_NOHEADING].items) {
935 /* Limit types of volumes to scan. */
936 if (!as->parms[P_TYPE].items) {
937 ScanVolType = (SCAN_RW | SCAN_RO | SCAN_BK);
940 for (ti = as->parms[P_TYPE].items; ti; ti = ti->next) {
941 if (strcmp(ti->data, "rw") == 0) {
942 ScanVolType |= SCAN_RW;
943 } else if (strcmp(ti->data, "ro") == 0) {
944 ScanVolType |= SCAN_RO;
945 } else if (strcmp(ti->data, "bk") == 0) {
946 ScanVolType |= SCAN_BK;
948 fprintf(stderr, "%s: Unknown -type value: %s\n", progname,
955 /* Limit types of vnodes to find (plus access entries) */
956 if (!as->parms[P_FIND].items) {
957 FindVnType = (FIND_FILE | FIND_DIR | FIND_MOUNT | FIND_SYMLINK);
960 for (ti = as->parms[P_FIND].items; ti; ti = ti->next) {
961 if (strcmp(ti->data, "file") == 0) {
962 FindVnType |= FIND_FILE;
963 } else if (strcmp(ti->data, "dir") == 0) {
964 FindVnType |= FIND_DIR;
965 } else if (strcmp(ti->data, "mount") == 0) {
966 FindVnType |= FIND_MOUNT;
967 } else if (strcmp(ti->data, "symlink") == 0) {
968 FindVnType |= FIND_SYMLINK;
969 } else if (strcmp(ti->data, "acl") == 0) {
970 FindVnType |= FIND_ACL;
972 fprintf(stderr, "%s: Unknown -find value: %s\n", progname,
979 /* Show vnodes matching one of the mode masks */
980 for (i = 0, ti = as->parms[P_MASK].items; ti; i++, ti = ti->next) {
981 if (i >= (sizeof(ModeMask) / sizeof(*ModeMask))) {
982 fprintf(stderr, "Too many -mask values\n");
985 ModeMask[i] = strtol(ti->data, NULL, 8);
987 fprintf(stderr, "Invalid -mask value: %s\n", ti->data);
992 /* Set which columns to be printed. */
993 if (!as->parms[P_OUTPUT].items) {
994 AddOutputColumn("host");
995 AddOutputColumn("desc");
996 AddOutputColumn("fid");
997 AddOutputColumn("dv");
998 if (FindVnType & FIND_ACL) {
999 AddOutputColumn("aid");
1000 AddOutputColumn("arights");
1002 AddOutputColumn("path");
1004 for (ti = as->parms[P_OUTPUT].items; ti; ti = ti->next) {
1005 if (AddOutputColumn(ti->data) != 0) {;
1006 fprintf(stderr, "%s: Unknown -output value: %s\n", progname,
1013 if (FindVnType & FIND_DIR) {
1014 AddVnodeHandler(vLarge, PrintVnodeDetails, NULL);
1016 if (FindVnType & (FIND_FILE | FIND_MOUNT | FIND_SYMLINK)) {
1017 AddVnodeHandler(vSmall, PrintVnodeDetails, NULL);
1019 if (FindVnType & FIND_ACL) {
1020 AddVnodeHandler(vLarge, ScanAcl, NULL);
1023 return ScanPartitions(partNameOrId, volumeId);
1027 * Determine if the current directory is a vice partition
1029 * @return disk partition object
1033 struct DiskPartition64 *
1034 FindCurrentPartition(void)
1036 int dr = _getdrive();
1037 struct DiskPartition64 *dp;
1040 for (dp = DiskPartitionList; dp; dp = dp->next) {
1041 if (*dp->devName - 'A' == dr)
1045 fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
1051 struct DiskPartition64 *
1052 FindCurrentPartition(void)
1054 char partName[1024];
1057 struct DiskPartition64 *dp;
1059 if (!getcwd(partName, 1023)) {
1060 fprintf(stderr, "%s: Failed to get current working directory: ",
1065 p = strchr(&partName[1], OS_DIRSEPC);
1070 if (!(dp = VGetPartition(partName, 0))) {
1073 fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
1082 * Scan and handle all the partitions detected on this server
1089 struct DiskPartition64 *partP;
1092 for (partP = DiskPartitionList; partP; partP = partP->next) {
1093 if (DumpInfo || SaveInodes || ShowSizes) {
1094 printf("Processing Partition %s:\n", partP->name);
1098 AddSizeTotals(&serverTotals, &partitionTotals);
1103 PrintServerTotals();
1108 * Scan the partition and handle volumes
1110 * @param[in] partP disk partition to scan
1115 HandlePart(struct DiskPartition64 *partP)
1117 afs_int64 nvols = 0;
1123 (void)sprintf(pname, "%s\\", VPartitionPath(partP));
1125 char *p = VPartitionPath(partP);
1128 if ((dirp = opendir(p)) == NULL) {
1129 fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
1133 while ((dp = readdir(dirp))) {
1134 p = (char *)strrchr(dp->d_name, '.');
1135 if (p != NULL && strcmp(p, VHDREXT) == 0) {
1136 HandleVolume(partP, dp->d_name);
1139 AddSizeTotals(&partitionTotals, &volumeTotals);
1145 PrintPartitionTotals(nvols);
1150 * Inspect a volume header special file.
1152 * @param[in] name descriptive name of the type of header special file
1153 * @param[in] dp partition object for this volume
1154 * @param[in] header header object for this volume
1155 * @param[in] inode fileserver inode number for this header special file
1156 * @param[out] psize total of the header special file
1161 HandleSpecialFile(const char *name, struct DiskPartition64 *dp,
1162 struct VolumeHeader *header, Inode inode,
1163 afs_sfsize_t * psize)
1165 afs_sfsize_t size = 0;
1166 IHandle_t *ih = NULL;
1167 FdHandle_t *fdP = NULL;
1168 #ifdef AFS_NAMEI_ENV
1170 #endif /* AFS_NAMEI_ENV */
1172 IH_INIT(ih, dp->device, header->parent, inode);
1176 "%s: Error opening header file '%s' for volume %u", progname,
1181 size = FDH_SIZE(fdP);
1184 "%s: Error getting size of header file '%s' for volume %u",
1185 progname, name, header->id);
1190 printf("\t%s inode\t= %s (size = %lld)\n",
1191 name, PrintInode(NULL, inode), size);
1192 #ifdef AFS_NAMEI_ENV
1193 namei_HandleToName(&filename, ih);
1194 printf("\t%s namei\t= %s\n", name, filename.n_path);
1195 #endif /* AFS_NAMEI_ENV */
1201 FDH_REALLYCLOSE(fdP);
1209 * Inspect this volume header files.
1211 * @param[in] dp partition object for this volume
1212 * @param[in] header_fd volume header file descriptor
1213 * @param[in] header volume header object
1214 * @param[out] psize total of the header special file
1219 HandleHeaderFiles(struct DiskPartition64 *dp, FD_t header_fd,
1220 struct VolumeHeader *header)
1222 afs_sfsize_t size = 0;
1225 size = OS_SIZE(header_fd);
1226 printf("Volume header (size = %lld):\n", size);
1227 printf("\tstamp\t= 0x%x\n", header->stamp.version);
1228 printf("\tVolId\t= %u\n", header->id);
1229 printf("\tparent\t= %u\n", header->parent);
1232 HandleSpecialFile("Info", dp, header, header->volumeInfo, &size);
1233 HandleSpecialFile("Small", dp, header, header->smallVnodeIndex,
1235 HandleSpecialFile("Large", dp, header, header->largeVnodeIndex,
1237 #ifdef AFS_NAMEI_ENV
1238 HandleSpecialFile("Link", dp, header, header->linkTable, &size);
1239 #endif /* AFS_NAMEI_ENV */
1242 printf("Total aux volume size = %lld\n\n", size);
1246 volumeTotals.auxsize = size;
1247 volumeTotals.auxsize_k = size / 1024;
1252 * Determine if the vnodes of this volume should be scanned.
1254 * @param[in] vp volume object
1256 * @return true if vnodes should be scanned
1259 IsScannable(Volume * vp)
1261 if (opr_queue_IsEmpty(&VnodeScanLists[vLarge]) &&
1262 opr_queue_IsEmpty(&VnodeScanLists[vSmall])) {
1266 return 1; /* filtering disabled; do not check vol type */
1268 switch (V_type(vp)) {
1270 return ScanVolType & SCAN_RW;
1272 return ScanVolType & SCAN_RO;
1274 return ScanVolType & SCAN_BK;
1276 fprintf(stderr, "%s: Volume %u; Unknown volume type %d\n", progname,
1277 V_id(vp), V_type(vp));
1284 * Attach and scan the volume and handle the header and vnodes
1286 * Print the volume header and vnode information, depending on the
1289 * @param[in] dp vice partition object for this volume
1290 * @param[in] name volume header file name
1295 HandleVolume(struct DiskPartition64 *dp, char *name)
1297 struct VolumeHeader header;
1298 struct VolumeDiskHeader diskHeader;
1299 FD_t fd = INVALID_FD;
1301 char headerName[1024];
1304 snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
1305 VPartitionPath(dp), name);
1306 if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD) {
1307 fprintf(stderr, "%s: Cannot open volume header %s\n", progname, name);
1310 if (OS_SIZE(fd) < 0) {
1311 fprintf(stderr, "%s: Cannot read volume header %s\n", progname, name);
1314 n = OS_READ(fd, &diskHeader, sizeof(diskHeader));
1315 if (n != sizeof(diskHeader)
1316 || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
1317 fprintf(stderr, "%s: Error reading volume header %s\n", progname,
1321 if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
1323 "%s: Volume %s, version number is incorrect; volume needs to be salvaged\n",
1328 DiskToVolumeHeader(&header, &diskHeader);
1329 if (DumpHeader || ShowSizes) {
1330 HandleHeaderFiles(dp, fd, &header);
1333 vp = AttachVolume(dp, name, &header);
1335 fprintf(stderr, "%s: Error attaching volume header %s\n",
1343 if (IsScannable(vp)) {
1345 IHandle_t *ih = vp->vnodeIndex[vLarge].handle;
1346 DirIndexFd = IH_OPEN(ih);
1347 if (DirIndexFd == NULL) {
1348 fprintf(stderr, "%s: Failed to open index for directories.",
1353 HandleVnodes(vp, vLarge);
1354 HandleVnodes(vp, vSmall);
1357 FDH_CLOSE(DirIndexFd);
1362 volumeTotals.diskused_k = V_diskused(vp);
1363 volumeTotals.size_k =
1364 volumeTotals.auxsize_k + volumeTotals.vnodesize_k;
1366 PrintingVolumeSizes = 0; /* print heading again */
1368 PrintVolumeSizes(vp);
1372 if (fd != INVALID_FD) {
1381 * Declare volinfo command line syntax
1388 struct cmd_syndesc *ts;
1390 ts = cmd_CreateSyntax(NULL, VolInfo, NULL,
1391 "Dump volume's internal state");
1392 cmd_AddParmAtOffset(ts, P_CHECKOUT, "-checkout", CMD_FLAG, CMD_OPTIONAL,
1393 "Checkout volumes from running fileserver");
1394 cmd_AddParmAtOffset(ts, P_VNODE, "-vnode", CMD_FLAG, CMD_OPTIONAL,
1396 cmd_AddParmAtOffset(ts, P_DATE, "-date", CMD_FLAG, CMD_OPTIONAL,
1397 "Also dump vnode's mod date");
1398 cmd_AddParmAtOffset(ts, P_INODE, "-inode", CMD_FLAG, CMD_OPTIONAL,
1399 "Also dump vnode's inode number");
1400 cmd_AddParmAtOffset(ts, P_ITIME, "-itime", CMD_FLAG, CMD_OPTIONAL,
1401 "Dump special inode's mod times");
1402 cmd_AddParmAtOffset(ts, P_PART, "-part", CMD_LIST, CMD_OPTIONAL,
1403 "AFS partition name or id (default current partition)");
1404 cmd_AddParmAtOffset(ts, P_VOLUMEID, "-volumeid", CMD_LIST, CMD_OPTIONAL,
1406 cmd_AddParmAtOffset(ts, P_HEADER, "-header", CMD_FLAG, CMD_OPTIONAL,
1407 "Dump volume's header info");
1408 cmd_AddParmAtOffset(ts, P_SIZEONLY, "-sizeonly", CMD_FLAG, CMD_OPTIONAL,
1409 "Dump volume's size");
1410 cmd_AddParmAtOffset(ts, P_FIXHEADER, "-fixheader", CMD_FLAG,
1411 CMD_OPTIONAL, "Try to fix header");
1412 cmd_AddParmAtOffset(ts, P_SAVEINODES, "-saveinodes", CMD_FLAG,
1413 CMD_OPTIONAL, "Try to save all inodes");
1414 cmd_AddParmAtOffset(ts, P_ORPHANED, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
1415 "List all dir/files without a parent");
1416 #if defined(AFS_NAMEI_ENV)
1417 cmd_AddParmAtOffset(ts, P_FILENAMES, "-filenames", CMD_FLAG,
1418 CMD_OPTIONAL, "Also dump vnode's namei filename");
1421 /* For compatibility with older versions. */
1422 cmd_AddParmAlias(ts, P_SIZEONLY, "-sizeOnly");
1426 * Declare volscan command line syntax
1433 struct cmd_syndesc *ts;
1435 ts = cmd_CreateSyntax(NULL, VolScan, NULL,
1436 "Print volume vnode information");
1438 cmd_AddParmAtOffset(ts, P_CHECKOUT, "-checkout", CMD_FLAG, CMD_OPTIONAL,
1439 "Checkout volumes from running fileserver");
1440 cmd_AddParmAtOffset(ts, P_PART, "-partition", CMD_SINGLE, CMD_OPTIONAL,
1441 "AFS partition name or id (default current partition)");
1442 cmd_AddParmAtOffset(ts, P_VOLUMEID, "-volumeid", CMD_SINGLE, CMD_OPTIONAL,
1443 "Volume id (-partition required)");
1444 cmd_AddParmAtOffset(ts, P_TYPE, "-type", CMD_LIST, CMD_OPTIONAL,
1445 "Volume types: rw, ro, bk");
1446 cmd_AddParmAtOffset(ts, P_FIND, "-find", CMD_LIST, CMD_OPTIONAL,
1447 "Objects to find: file, dir, mount, symlink, acl");
1448 cmd_AddParmAtOffset(ts, P_MASK, "-mask", CMD_LIST, CMD_OPTIONAL,
1449 "Unix mode mask (example: 06000)");
1450 cmd_AddParmAtOffset(ts, P_OUTPUT, "-output", CMD_LIST, CMD_OPTIONAL,
1452 cmd_AddParmAtOffset(ts, P_DELIM, "-delim", CMD_SINGLE, CMD_OPTIONAL,
1453 "Output field delimiter");
1454 cmd_AddParmAtOffset(ts, P_NOHEADING, "-noheading", CMD_FLAG, CMD_OPTIONAL,
1455 "Do not print the heading line");
1459 * volinfo/volscan program entry
1462 main(int argc, char **argv)
1467 opr_queue_Init(&VnodeScanLists[vLarge]);
1468 opr_queue_Init(&VnodeScanLists[vSmall]);
1469 memset(ModeMask, 0, sizeof(ModeMask) / sizeof(*ModeMask));
1470 gethostname(Hostname, sizeof(Hostname));
1472 base = strrchr(argv[0], '/');
1475 base = strrchr(pathname, '\\');
1477 #endif /* AFS_NT40_ENV */
1482 if ((base[0] == '/' || base[0] == '\\') && base[1] != '\0') {
1483 #else /* AFS_NT40_ENV */
1484 if (base[0] == '/' && base[1] != '\0') {
1485 #endif /* AFS_NT40_ENV */
1491 if (stricmp(progname, "volscan") == 0
1492 || stricmp(progname, "volscan.exe") == 0) {
1493 #else /* AFS_NT40_ENV */
1494 if (strcmp(progname, "volscan") == 0) {
1495 #endif /* AFS_NT40_ENV */
1501 code = cmd_Dispatch(argc, argv);
1506 * Return a display string for the volume type.
1508 * @param[in] type volume type
1510 * @return volume type description string
1512 static_inline char *
1513 volumeTypeString(int type)
1516 (type == RWVOL ? "read/write" :
1517 (type == ROVOL ? "readonly" :
1518 (type == BACKVOL ? "backup" : "unknown")));
1522 * Return a short display string for the volume type.
1524 * @param[in] type volume type
1526 * @return volume type short description string
1528 static_inline char *
1529 volumeTypeShortString(int type)
1532 (type == RWVOL ? "RW" :
1533 (type == ROVOL ? "RO" : (type == BACKVOL ? "BK" : "??")));
1537 * Print the volume header information
1539 * @param[in] volume object
1544 PrintHeader(Volume * vp)
1546 printf("Volume header for volume %u (%s)\n", V_id(vp), V_name(vp));
1547 printf("stamp.magic = %x, stamp.version = %u\n", V_stamp(vp).magic,
1548 V_stamp(vp).version);
1550 ("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n",
1551 V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp),
1554 ("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n",
1555 V_type(vp), volumeTypeString(V_type(vp)), V_uniquifier(vp),
1556 V_needsCallback(vp), V_destroyMe(vp));
1558 ("id = %u, parentId = %u, cloneId = %u, backupId = %u, restoredFromId = %u\n",
1559 V_id(vp), V_parentId(vp), V_cloneId(vp), V_backupId(vp),
1560 V_restoredFromId(vp));
1562 ("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n",
1563 V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp),
1565 printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)),
1566 date(V_copyDate(vp)));
1567 printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)),
1568 date(V_expirationDate(vp)));
1569 printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)),
1570 date(V_updateDate(vp)));
1571 printf("owner = %u, accountNumber = %u\n", V_owner(vp),
1572 V_accountNumber(vp));
1574 ("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n",
1575 V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2],
1576 V_weekUse(vp)[3], V_weekUse(vp)[4], V_weekUse(vp)[5],
1577 V_weekUse(vp)[6], date(V_dayUseDate(vp)));
1578 printf("volUpdateCounter = %u\n", V_volUpCounter(vp));
1582 * Get the size and times of a file
1584 * @param[in] fd file descriptor of file to stat
1585 * @param[out] size size of the file
1586 * @param[out] ctime ctime of file as a formatted string
1587 * @param[out] mtime mtime of file as a formatted string
1588 * @param[out] atime atime of file as a formatted string
1590 * @return error code
1592 * @retval -1 failed to retrieve file information
1595 GetFileInfo(FD_t fd, afs_sfsize_t * size, char **ctime, char **mtime,
1599 BY_HANDLE_FILE_INFORMATION fi;
1600 LARGE_INTEGER fsize;
1601 if (!GetFileInformationByHandle(fd, &fi)) {
1602 fprintf(stderr, "%s: GetFileInformationByHandle failed\n", progname);
1605 if (!GetFileSizeEx(fd, &fsize)) {
1606 fprintf(stderr, "%s: GetFileSizeEx failed\n", progname);
1609 *size = fsize.QuadPart;
1611 *mtime = NT_date(&fi.ftLastWriteTime);
1612 *atime = NT_date(&fi.ftLastAccessTime);
1614 struct afs_stat_st status;
1615 if (afs_fstat(fd, &status) == -1) {
1616 fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
1619 *size = status.st_size;
1620 *ctime = date(status.st_ctime);
1621 *mtime = date(status.st_mtime);
1622 *atime = date(status.st_atime);
1628 * Copy the inode data to a file in the current directory.
1630 * @param[in] vdp vnode details object
1635 SaveInode(struct VnodeDetails *vdp)
1639 char nfile[50], buffer[256];
1643 Inode ino = VNDISK_GET_INO(vdp->vnode);
1645 if (!VALID_INO(ino)) {
1649 IH_INIT(ih, V_device(vdp->vp), V_parentId(vdp->vp), ino);
1653 "%s: Can't open inode %s error %d (ignored)\n",
1654 progname, PrintInode(NULL, ino), errno);
1657 snprintf(nfile, sizeof nfile, "TmpInode.%s", PrintInode(NULL, ino));
1658 ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
1661 "%s: Can't create file %s; error %d (ignored)\n",
1662 progname, nfile, errno);
1664 FDH_REALLYCLOSE(fdP);
1671 len = FDH_PREAD(fdP, buffer, sizeof(buffer), total);
1673 FDH_REALLYCLOSE(fdP);
1678 "%s: Error while reading from inode %s (%d)\n",
1679 progname, PrintInode(NULL, ino), errno);
1683 break; /* No more input */
1684 nBytes = write(ofd, buffer, (size_t)len);
1685 if (nBytes != len) {
1686 FDH_REALLYCLOSE(fdP);
1691 "%s: Error while writing to \"%s\" (%d - ignored)\n",
1692 progname, nfile, errno);
1698 FDH_REALLYCLOSE(fdP);
1701 printf("... Copied inode %s to file %s (%lu bytes)\n",
1702 PrintInode(NULL, ino), nfile, (unsigned long)total);
1706 * get the VnodeDiskObject for a directory given its vnode id.
1708 * @param[in] vp volume object
1709 * @param[in] parent vnode id to read
1710 * @param[out] pvn vnode disk object to populate
1712 * @post pvn contains copy of disk object for parent id
1714 * @return operation status
1716 * @retval -1 failure
1719 GetDirVnode(Volume * vp, VnodeId parent, VnodeDiskObject * pvn)
1725 return -1; /* previously failed to open the large vnode index. */
1727 if (parent % 2 == 0) {
1728 fprintf(stderr, "%s: Invalid parent vnode id %lu in volume %lu\n",
1730 afs_printable_uint32_lu(parent),
1731 afs_printable_uint32_lu(V_id(vp)));
1733 offset = vnodeIndexOffset(&VnodeClassInfo[vLarge], parent);
1734 code = FDH_SEEK(DirIndexFd, offset, 0);
1737 "%s: GetDirVnode: seek failed for %lu.%lu to offset %llu\n",
1738 progname, afs_printable_uint32_lu(V_id(vp)),
1739 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1742 code = FDH_READ(DirIndexFd, pvn, SIZEOF_LARGEDISKVNODE);
1743 if (code != SIZEOF_LARGEDISKVNODE) {
1745 "%s: GetDirVnode: read failed for %lu.%lu at offset %llu\n",
1746 progname, afs_printable_uint32_lu(V_id(vp)),
1747 afs_printable_uint32_lu(parent), (long long unsigned)offset);
1750 if (pvn->vnodeMagic != LARGEVNODEMAGIC) {
1751 fprintf(stderr, "%s: GetDirVnode: bad vnode magic\n", progname);
1754 if (!pvn->dataVersion) {
1755 fprintf(stderr, "%s: GetDirVnode: dv is zero\n", progname);
1762 * Perform inverse lookup on a vice directory object to map a fid onto a dirent string.
1764 * @param[in] vp volume object
1765 * @param[in] pvnode parent directory vnode object
1766 * @param[in] cvnid child vnode id to inverse lookup
1767 * @param[in] cuniq child uniquifier to inverse lookup
1768 * @param[out] dirent buffer in which to store dirent string
1769 * @param[out] dirent_len length of dirent buffer
1771 * @post dirent contains string for the (cvnid, cuniq) entry
1773 * @return operation status
1777 GetDirEntry(Volume * vp, VnodeDiskObject * pvnode, VnodeId cvnid,
1778 afs_uint32 cuniq, char *dirent, size_t dirent_len)
1785 ino = VNDISK_GET_INO(pvnode);
1786 if (!VALID_INO(ino)) {
1787 fprintf(stderr, "%s: GetDirEntry invalid parent ino\n", progname);
1790 SetSalvageDirHandle(&dir, V_parentId(vp), V_device(vp), ino,
1792 code = afs_dir_InverseLookup(&dir, cvnid, cuniq, dirent, dirent_len);
1794 fprintf(stderr, "%s: afs_dir_InverseLookup failed with code %d\n",
1802 * Lookup the path of this vnode, relative to the root of the volume.
1804 * @param[in] vdp vnode details
1811 LookupPath(struct VnodeDetails *vdp)
1813 const int MAX_PATH_LEN = 1023;
1814 static char path_buffer[MAX_PATH_LEN + 1];
1815 static char dirent[MAX_PATH_LEN + 1];
1816 char vnode_buffer[SIZEOF_LARGEDISKVNODE];
1817 struct VnodeDiskObject *pvn = (struct VnodeDiskObject *)vnode_buffer;
1821 Volume *vp = vdp->vp;
1822 VnodeId parent = vdp->vnode->parent;
1823 VnodeId cvnid = vdp->vnodeNumber;
1824 afs_uint32 cuniq = vdp->vnode->uniquifier;
1827 vdp->path = "/"; /* this is root */
1831 space = sizeof(path_buffer) - 1;
1832 cursor = &path_buffer[space];
1838 code = GetDirVnode(vp, parent, pvn);
1843 code = GetDirEntry(vp, pvn, cvnid, cuniq, dirent, MAX_PATH_LEN);
1849 len = strlen(dirent);
1852 "%s: Failed to lookup path for fid %lu.%lu.%lu: empty dir entry\n",
1853 progname, afs_printable_uint32_lu(V_id(vdp->vp)),
1854 afs_printable_uint32_lu(vdp->vnodeNumber),
1855 afs_printable_uint32_lu(vdp->vnode->uniquifier));
1861 if (space < (len + 1)) {
1863 "%s: Failed to lookup path for fid %lu.%lu.%lu: path exceeds max length (%d).\n",
1864 progname, afs_printable_uint32_lu(V_id(vdp->vp)),
1865 afs_printable_uint32_lu(vdp->vnodeNumber),
1866 afs_printable_uint32_lu(vdp->vnode->uniquifier),
1867 sizeof(path_buffer) - 1);
1873 /* prepend path component */
1875 memcpy(cursor, dirent, len);
1881 cuniq = pvn->uniquifier;
1882 parent = pvn->parent;
1892 * Read the symlink target and determine if this vnode is a mount point.
1894 * @param[inout] vdp vnode details object
1896 * @return error code
1898 * @retval -1 failure
1901 ReadSymlinkTarget(struct VnodeDetails *vdp)
1903 const int MAX_SYMLINK_LEN = 1023;
1904 static char buffer[MAX_SYMLINK_LEN + 1];
1906 Volume *vp = vdp->vp;
1907 VnodeDiskObject *vnode = vdp->vnode;
1908 VnodeId vnodeNumber = vdp->vnodeNumber;
1909 IHandle_t *ihP = NULL;
1910 FdHandle_t *fdP = NULL;
1911 afs_fsize_t fileLength;
1915 ino = VNDISK_GET_INO(vnode);
1916 VNDISK_GET_LEN(fileLength, vnode);
1918 if (fileLength > MAX_SYMLINK_LEN) {
1920 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) exceeds "
1921 "%u, file length is %llu)!\n", progname,
1922 afs_printable_uint32_lu(V_id(vp)),
1923 afs_printable_uint32_lu(vnodeNumber),
1924 afs_printable_uint32_lu(vnode->uniquifier),
1925 afs_printable_uint32_lu(vnode->dataVersion), MAX_SYMLINK_LEN,
1929 if (fileLength == 0) {
1931 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) is empty.\n",
1933 afs_printable_uint32_lu(V_id(vp)),
1934 afs_printable_uint32_lu(vnodeNumber),
1935 afs_printable_uint32_lu(vnode->uniquifier),
1936 afs_printable_uint32_lu(vnode->dataVersion));
1940 IH_INIT(ihP, V_device(vp), V_parentId(vp), ino);
1946 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
1950 readLength = FDH_READ(fdP, buffer, fileLength);
1951 if (readLength < 0) {
1953 "%s: Error reading symlink contents for fid (%lu.%lu.%lu.%lu); "
1956 afs_printable_uint32_lu(V_id(vp)),
1957 afs_printable_uint32_lu(vnodeNumber),
1958 afs_printable_uint32_lu(vnode->uniquifier),
1959 afs_printable_uint32_lu(vnode->dataVersion), errno);
1962 } else if (readLength != fileLength) {
1964 "%s: Symlink contents for fid (%lu.%lu.%lu.%lu) don't match "
1965 "vnode file length metadata (len=%llu, actual=%lld)!\n",
1967 afs_printable_uint32_lu(V_id(vp)),
1968 afs_printable_uint32_lu(vnodeNumber),
1969 afs_printable_uint32_lu(vnode->uniquifier),
1970 afs_printable_uint32_lu(vnode->dataVersion), fileLength,
1971 (long long)readLength);
1977 if (readLength > 1 && (buffer[0] == '#' || buffer[0] == '%')
1978 && buffer[readLength - 1] == '.') {
1980 buffer[readLength - 1] = '\0'; /* stringify; clobbers trailing dot */
1981 sep = strchr(buffer, ':');
1982 vdp->t = VNODE_U_MOUNT;
1983 vdp->u.mnt.type = buffer[0];
1985 vdp->u.mnt.cell = NULL;
1986 vdp->u.mnt.vol = buffer + 1;
1989 vdp->u.mnt.cell = buffer + 1;
1990 vdp->u.mnt.vol = sep + 1;
1993 buffer[readLength] = '\0';
1994 vdp->t = VNODE_U_SYMLINK;
1995 vdp->u.target = buffer;
2009 * Print vnode details line
2011 * @param[inout] vdp vnode details object
2016 PrintVnodeDetails(struct VnodeDetails *vdp)
2018 switch (vdp->vnode->type) {
2022 if (FindVnType & FIND_FILE) {
2023 PrintColumns(vdp, "file");
2027 if (FindVnType & FIND_DIR) {
2028 PrintColumns(vdp, "dir");
2032 if (FindVnType & (FIND_MOUNT | FIND_SYMLINK)) {
2033 ReadSymlinkTarget(vdp);
2034 if ((FindVnType & FIND_MOUNT) && (vdp->t == VNODE_U_MOUNT)) {
2035 PrintColumns(vdp, "mount");
2037 if ((FindVnType & FIND_SYMLINK) && (vdp->t == VNODE_U_SYMLINK)) {
2038 PrintColumns(vdp, "symlink");
2044 "%s: Warning: unexpected vnode type %u on fid %lu.%lu.%lu",
2045 progname, vdp->vnode->type,
2046 afs_printable_uint32_lu(V_id(vdp->vp)),
2047 afs_printable_uint32_lu(vdp->vnodeNumber),
2048 afs_printable_uint32_lu(vdp->vnode->uniquifier));
2053 * Print each access entry of a vnode
2055 * @param[in] vdp vnode details object
2060 ScanAcl(struct VnodeDetails *vdp)
2063 struct acl_accessList *acl;
2064 VnodeDiskObject *vnode = vdp->vnode;
2066 if (vnode->type == vNull) {
2070 acl = VVnodeDiskACL(vnode);
2071 for (i = 0; i < acl->positive; i++) {
2072 vdp->t = VNODE_U_POS_ACCESS;
2073 vdp->u.access = &(acl->entries[i]);
2074 PrintColumns(vdp, "acl");
2076 for (i = (acl->total - 1); i >= (acl->total - acl->negative); i--) {
2077 vdp->t = VNODE_U_NEG_ACCESS;
2078 vdp->u.access = &(acl->entries[i]);
2079 PrintColumns(vdp, "acl");
2084 * Determine if the mode matches all the given masks.
2086 * Returns true if the mode bits match all the given masks. A mask matches if at
2087 * least one bit in the mask is present in the mode bits. An empty mode mask
2088 * list matches all modes (even if all the mode bits are zero.)
2090 * param[in] modeBits unix mode bits of a vnode
2094 ModeMaskMatch(unsigned int modeBits)
2098 for (i = 0; ModeMask[i] && i <= sizeof(ModeMask) / sizeof(*ModeMask); i++) {
2099 if ((ModeMask[i] & modeBits) == 0) {
2100 return 0; /* at least one mode bit is not present */
2107 * Scan a volume index and handle each vnode
2109 * @param[in] vp volume object
2110 * @param[in] class which index to scan
2115 HandleVnodes(Volume * vp, VnodeClass class)
2117 afs_int32 diskSize =
2118 (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE);
2119 char buf[SIZEOF_LARGEDISKVNODE];
2120 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
2121 StreamHandle_t *file = NULL;
2123 afs_sfsize_t nVnodes;
2124 afs_foff_t offset = 0;
2125 IHandle_t *ih = vp->vnodeIndex[class].handle;
2126 FdHandle_t *fdP = NULL;
2128 char *ctime, *atime, *mtime;
2129 struct opr_queue *scanList = &VnodeScanLists[class];
2130 struct opr_queue *cursor;
2132 if (opr_queue_IsEmpty(scanList)) {
2136 for (opr_queue_Scan(scanList, cursor)) {
2137 struct VnodeScanProc *entry = (struct VnodeScanProc *)cursor;
2138 if (entry->heading) {
2139 printf("%s", entry->heading);
2145 fprintf(stderr, "%s: open failed: ", progname);
2149 file = FDH_FDOPEN(fdP, "r");
2151 fprintf(stderr, "%s: fdopen failed\n", progname);
2155 if (GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime) != 0) {
2159 printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime,
2163 nVnodes = (size / diskSize) - 1;
2165 STREAM_ASEEK(file, diskSize);
2169 for (vnodeIndex = 0;
2170 nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1;
2171 nVnodes--, vnodeIndex++, offset += diskSize) {
2173 struct VnodeDetails vnodeDetails;
2175 if (!ModeMaskMatch(vnode->modeBits)) {
2179 vnodeDetails.vp = vp;
2180 vnodeDetails.class = class;
2181 vnodeDetails.vnode = vnode;
2182 vnodeDetails.vnodeNumber = bitNumberToVnodeNumber(vnodeIndex, class);
2183 vnodeDetails.offset = offset;
2184 vnodeDetails.index = vnodeIndex;
2186 for (opr_queue_Scan(scanList, cursor)) {
2187 struct VnodeScanProc *entry = (struct VnodeScanProc *)cursor;
2189 (*entry->proc) (&vnodeDetails);
2204 * Print vnode information
2206 * @param[in] vdp vnode details object
2211 PrintVnode(struct VnodeDetails *vdp)
2213 #if defined(AFS_NAMEI_ENV)
2217 afs_foff_t offset = vdp->offset;
2218 VnodeDiskObject *vnode = vdp->vnode;
2219 afs_fsize_t fileLength;
2222 ino = VNDISK_GET_INO(vnode);
2223 VNDISK_GET_LEN(fileLength, vnode);
2225 /* The check for orphaned vnodes is currently limited to non-empty
2226 * vnodes with a parent of zero (and which are not the first entry
2228 if (ShowOrphaned && (fileLength == 0 || vnode->parent || !offset))
2232 ("%10lld Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
2233 (long long)offset, vdp->vnodeNumber, vnode->uniquifier,
2234 vnode->dataVersion, vnode->cloned, (afs_uintmax_t) fileLength,
2235 vnode->linkCount, vnode->parent);
2236 if (DumpInodeNumber)
2237 printf(" inode: %s", PrintInode(NULL, ino));
2239 printf(" ServerModTime: %s", date(vnode->serverModifyTime));
2240 #if defined(AFS_NAMEI_ENV)
2241 if (PrintFileNames) {
2242 IH_INIT(ihtmpp, V_device(vdp->vp), V_parentId(vdp->vp), ino);
2243 namei_HandleToName(&filename, ihtmpp);
2244 #if !defined(AFS_NT40_ENV)
2245 printf(" UFS-Filename: %s", filename.n_path);
2247 printf(" NTFS-Filename: %s", filename.n_path);
2255 * Print the volume partition id
2257 * @param[in] vp volume object
2262 PrintPartitionId(Volume * vp)
2264 char *partition = VPartitionPath(V_partition(vp));
2266 if (!strncmp(partition, "/vicep", 6)) {
2267 printf("%s", partition + 6);
2268 } else if (!strncmp(partition, "vicep", 5)) {
2269 printf("%s", partition + 5);
2271 fprintf(stderr, "Invalid partition for volume id %lu\n",
2272 afs_printable_uint32_lu(V_id(vp)));
2273 printf(PLACEHOLDER);
2278 * Print the vnode type description string
2280 * @param[in] type vnode type
2285 PrintVnodeType(int type)
2306 * Print right bits as string.
2308 * param[in] rights rights bitmap
2311 PrintRights(int rights)
2313 if (rights & PRSFS_READ) {
2316 if (rights & PRSFS_LOOKUP) {
2319 if (rights & PRSFS_INSERT) {
2322 if (rights & PRSFS_DELETE) {
2325 if (rights & PRSFS_WRITE) {
2328 if (rights & PRSFS_LOCK) {
2331 if (rights & PRSFS_ADMINISTER) {
2334 if (rights & PRSFS_USR0) {
2337 if (rights & PRSFS_USR1) {
2340 if (rights & PRSFS_USR2) {
2343 if (rights & PRSFS_USR3) {
2346 if (rights & PRSFS_USR4) {
2349 if (rights & PRSFS_USR5) {
2352 if (rights & PRSFS_USR6) {
2355 if (rights & PRSFS_USR7) {
2361 * Print the path to the namei file.
2364 PrintNamei(Volume * vp, VnodeDiskObject * vnode)
2366 #ifdef AFS_NAMEI_ENV
2368 IHandle_t *ihP = NULL;
2370 ino = VNDISK_GET_INO(vnode);
2371 IH_INIT(ihP, V_device(vp), V_parentId(vp), ino);
2372 namei_HandleToName(&name, ihP);
2373 printf("%s", name.n_path);
2376 printf(PLACEHOLDER);
2381 * Print the column heading line.
2384 PrintColumnHeading(void)
2389 for (i = 0; i < NumOutputColumns; i++) {
2391 printf("%s", ColumnDelim);
2393 name = ColumnName[OutputColumn[i]].name;
2395 putchar(toupper(*name++));
2402 * Print output columns for the vnode/acess entry.
2404 * @param[in] vdp vnode details object
2405 * @param[in] desc type of line to be printed
2410 PrintColumns(struct VnodeDetails *vdp, const char *desc)
2415 for (i = 0; i < NumOutputColumns; i++) {
2417 printf("%s", ColumnDelim);
2419 switch (OutputColumn[i]) {
2421 printf("%s", Hostname);
2427 printf("%lu", afs_printable_uint32_lu(V_id(vdp->vp)));
2430 printf("%s", volumeTypeShortString(V_type(vdp->vp)));
2433 printf("%s", V_name(vdp->vp));
2436 printf("%s", VPartitionPath(V_partition(vdp->vp)));
2439 PrintPartitionId(vdp->vp);
2442 printf("%lu.%lu.%lu",
2443 afs_printable_uint32_lu(V_id(vdp->vp)),
2444 afs_printable_uint32_lu(vdp->vnodeNumber),
2445 afs_printable_uint32_lu(vdp->vnode->uniquifier));
2451 printf("%s", vdp->path ? vdp->path : PLACEHOLDER);
2455 (vdp->t == VNODE_U_SYMLINK ? vdp->u.target : PLACEHOLDER));
2458 if (vdp->t != VNODE_U_MOUNT) {
2459 printf("%s", PLACEHOLDER);
2461 printf("%c", vdp->u.mnt.type);
2462 if (vdp->u.mnt.cell) {
2463 printf("%s:", vdp->u.mnt.cell);
2465 printf("%s.", vdp->u.mnt.vol);
2469 printf("%c", (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.type : '-'));
2473 (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.cell : PLACEHOLDER));
2477 (vdp->t == VNODE_U_MOUNT ? vdp->u.mnt.vol : PLACEHOLDER));
2480 if (vdp->t == VNODE_U_POS_ACCESS || vdp->t == VNODE_U_NEG_ACCESS) {
2481 printf("%d", vdp->u.access->id);
2483 printf(PLACEHOLDER);
2487 if (vdp->t == VNODE_U_POS_ACCESS) {
2489 PrintRights(vdp->u.access->rights);
2490 } else if (vdp->t == VNODE_U_NEG_ACCESS) {
2492 PrintRights(vdp->u.access->rights);
2496 PrintVnodeType(vdp->vnode->type);
2499 printf("%c", vdp->vnode->cloned ? 'y' : 'n');
2502 printf("0%o", vdp->vnode->modeBits);
2505 printf("%lu", afs_printable_uint32_lu(vdp->vnode->linkCount));
2508 VNDISK_GET_LEN(length, vdp->vnode);
2509 printf("%llu", length);
2512 printf("%lu", afs_printable_uint32_lu(vdp->vnode->uniquifier));
2515 printf("%lu", afs_printable_uint32_lu(vdp->vnode->dataVersion));
2518 printf("%" AFS_UINT64_FMT, VNDISK_GET_INO(vdp->vnode));
2521 PrintNamei(vdp->vp, vdp->vnode);
2525 afs_printable_uint32_lu(vdp->vnode->unixModifyTime));
2528 printf("%lu", afs_printable_uint32_lu(vdp->vnode->author));
2531 printf("%lu", afs_printable_uint32_lu(vdp->vnode->owner));
2534 printf("%lu", afs_printable_uint32_lu(vdp->vnode->parent));
2537 printf("0x%08X", vdp->vnode->vnodeMagic);
2541 afs_printable_uint32_lu(vdp->vnode->lock.lockCount),
2542 afs_printable_uint32_lu(vdp->vnode->lock.lockTime));
2546 afs_printable_uint32_lu(vdp->vnode->serverModifyTime));
2549 printf("%lu", afs_printable_uint32_lu(vdp->vnode->group));
2552 fprintf(stderr, "%s: Unknown column type: %d (%d)\n", progname,
2553 OutputColumn[i], i);