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>
38 #include "partition.h"
41 #include "AFS_component_version_number.c"
44 static const char *progname = "volinfo";
46 /* Command line options */
64 static int DumpInfo = 1; /**< Dump volume information, defualt mode*/
65 static int DumpHeader = 0; /**< Dump volume header files info */
66 static int DumpVnodes = 0; /**< Dump vnode info */
67 static int DumpInodeNumber = 0; /**< Dump inode numbers with vnodes */
68 static int DumpDate = 0; /**< Dump vnode date (server modify date) with vnode */
69 static int InodeTimes = 0; /**< Dump some of the dates associated with inodes */
70 #if defined(AFS_NAMEI_ENV)
71 static int PrintFileNames = 0; /**< Dump vnode and special file name filenames */
73 static int ShowOrphaned = 0; /**< Show "orphaned" vnodes (vnodes with parent of 0) */
74 static int ShowSizes = 0; /**< Show volume size summary */
75 static int SaveInodes = 0; /**< Save vnode data to files */
76 static int FixHeader = 0; /**< Repair header files magic and version fields. */
79 * Volume size running totals
82 afs_uint64 diskused_k; /**< volume size from disk data file, in kilobytes */
83 afs_uint64 auxsize; /**< size of header files, in bytes */
84 afs_uint64 auxsize_k; /**< size of header files, in kilobytes */
85 afs_uint64 vnodesize; /**< size of the large and small vnodes, in bytes */
86 afs_uint64 vnodesize_k; /**< size of the large and small vnodes, in kilobytes */
87 afs_uint64 size_k; /**< size of headers and vnodes, in kilobytes */
90 static struct sizeTotals volumeTotals = { 0, 0, 0, 0, 0, 0 };
91 static struct sizeTotals partitionTotals = { 0, 0, 0, 0, 0, 0 };
92 static struct sizeTotals serverTotals = { 0, 0, 0, 0, 0, 0 };
93 static int PrintingVolumeSizes = 0; /*print volume size lines */
95 /* Forward Declarations */
96 void PrintHeader(Volume * vp);
97 void HandleAllPart(void);
98 void HandlePart(struct DiskPartition64 *partP);
99 void HandleVolume(struct DiskPartition64 *partP, char *name);
100 struct DiskPartition64 *FindCurrentPartition(void);
101 Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
102 struct VolumeHeader *header);
103 void PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
104 Inode ino, Volume * vp);
105 void HandleVnodes(Volume * vp, VnodeClass class);
108 * Format time as a timestamp string
110 * @param[in] date time value to format
112 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
114 * @note A static array of 8 strings are stored by this
115 * function. The array slots are overwritten, so the
116 * caller must not reference the returned string after
117 * seven additional calls to this function.
122 #define MAX_DATE_RESULT 100
123 static char results[8][MAX_DATE_RESULT];
125 struct tm *tm = localtime(&date);
128 (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm); /* NT does not have %T */
129 snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT,
130 "%lu (%s)", (unsigned long)date, buf);
131 return results[next];
136 * Format file time as a timestamp string
138 * @param[in] ft file time
140 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
142 * @note A static array of 8 strings are stored by this
143 * function. The array slots are overwritten, so the
144 * caller must not reference the returned string after
145 * seven additional calls to this function.
148 NT_date(FILETIME * ft)
150 static char result[8][64];
155 if (!FileTimeToLocalFileTime(ft, &lft)
156 || !FileTimeToSystemTime(&lft, &st)) {
157 fprintf(stderr, "%s: Time conversion failed.\n", progname);
160 sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
161 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
167 * Print the volume size table heading line, if needed.
172 PrintVolumeSizeHeading(void)
174 if (!PrintingVolumeSizes) {
176 ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n");
177 PrintingVolumeSizes = 1;
187 AddSizeTotals(struct sizeTotals *a, struct sizeTotals *b)
189 a->diskused_k += b->diskused_k;
190 a->auxsize += b->auxsize;
191 a->auxsize_k += b->auxsize_k;
192 a->vnodesize += b->vnodesize;
193 a->vnodesize_k += b->vnodesize_k;
194 a->size_k += b->size_k;
198 * Print the sizes for a volume.
203 PrintVolumeSizes(Volume * vp)
205 afs_int64 diff_k = volumeTotals.size_k - volumeTotals.diskused_k;
207 PrintVolumeSizeHeading();
208 printf("%u\t%9llu%9llu%10llu%10llu%9lld\t%24s\n",
210 volumeTotals.diskused_k,
211 volumeTotals.auxsize_k, volumeTotals.vnodesize_k,
212 volumeTotals.size_k, diff_k, V_name(vp));
216 * Print the size totals for the partition.
221 PrintPartitionTotals(afs_uint64 nvols)
223 afs_int64 diff_k = partitionTotals.size_k - partitionTotals.diskused_k;
225 PrintVolumeSizeHeading();
226 printf("\nPart Totals %12llu%9llu%10llu%10llu%9lld (%llu volumes)\n\n",
227 partitionTotals.diskused_k, partitionTotals.auxsize,
228 partitionTotals.vnodesize, partitionTotals.size_k, diff_k, nvols);
229 PrintingVolumeSizes = 0;
233 * Print the size totals for all the partitions.
238 PrintServerTotals(void)
240 afs_int64 diff_k = serverTotals.size_k - serverTotals.diskused_k;
242 printf("\nServer Totals%12lld%9lld%10lld%10lld%9lld\n",
243 serverTotals.diskused_k, serverTotals.auxsize,
244 serverTotals.vnodesize, serverTotals.size_k, diff_k);
248 * Read a volume header file
250 * @param[in] ih ihandle of the header file
251 * @param[in] to destination
252 * @param[in] size expected header size
253 * @param[in] magic expected header magic number
254 * @param[in] version expected header version number
258 * @retval -1 failed to read file
261 ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
263 struct versionStamp *vsn;
267 vsn = (struct versionStamp *)to;
269 code = IH_IREAD(ih, 0, to, size);
273 if (vsn->magic != magic) {
275 fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
276 progname, PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
279 /* Check is conditional, in case caller wants to inspect version himself */
280 if (version && vsn->version != version) {
282 fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
284 PrintInode(NULL, ih->ih_ino), vsn->version, version);
286 if (bad && FixHeader) {
288 vsn->version = version;
289 printf("Special index inode %s has a bad header. Reconstructing...\n",
290 PrintInode(NULL, ih->ih_ino));
291 code = IH_IWRITE(ih, 0, to, size);
294 "%s: Write failed for inode %s; header left in damaged state\n",
295 progname, PrintInode(NULL, ih->ih_ino));
298 if (!bad && DumpInfo) {
299 printf("Inode %s: Good magic %x and version %x\n",
300 PrintInode(NULL, ih->ih_ino), magic, version);
306 * Simplified attach volume
308 * param[in] dp vice disk partition object
309 * param[in] volname volume header file name
310 * param[in] header volume header object
312 * @return volume object or null on error
315 AttachVolume(struct DiskPartition64 * dp, char *volname,
316 struct VolumeHeader * header)
321 vp = (Volume *) calloc(1, sizeof(Volume));
322 vp->specialStatus = 0;
323 vp->device = dp->device;
325 IH_INIT(vp->vnodeIndex[vLarge].handle, dp->device, header->parent,
326 header->largeVnodeIndex);
327 IH_INIT(vp->vnodeIndex[vSmall].handle, dp->device, header->parent,
328 header->smallVnodeIndex);
329 IH_INIT(vp->diskDataHandle, dp->device, header->parent,
331 IH_INIT(V_linkHandle(vp), dp->device, header->parent, header->linkTable);
332 vp->cacheCheck = 0; /* XXXX */
333 vp->shuttingDown = 0;
334 vp->goingOffline = 0;
336 vp->header = (struct volHeader *)calloc(1, sizeof(*vp->header));
337 ec = ReadHdr1(V_diskDataHandle(vp), (char *)&V_disk(vp),
338 sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
340 struct IndexFileHeader iHead;
341 ec = ReadHdr1(vp->vnodeIndex[vSmall].handle, (char *)&iHead,
342 sizeof(iHead), SMALLINDEXMAGIC, SMALLINDEXVERSION);
345 struct IndexFileHeader iHead;
346 ec = ReadHdr1(vp->vnodeIndex[vLarge].handle, (char *)&iHead,
347 sizeof(iHead), LARGEINDEXMAGIC, LARGEINDEXVERSION);
351 struct versionStamp stamp;
352 ec = ReadHdr1(V_linkHandle(vp), (char *)&stamp, sizeof(stamp),
353 LINKTABLEMAGIC, LINKTABLEVERSION);
362 * Convert the partition device number into a partition name.
364 * @param[in] partId partition number, 0 to 254
365 * @param[out] partName buffer to hold partition name (e.g. /vicepa)
366 * @param[in] partNameSize size of partName buffer
370 * @retval -1 error, partId is out of range
371 * @retval -2 error, partition name exceeds partNameSize
374 GetPartitionName(afs_uint32 partId, char *partName, afs_size_t partNameSize)
376 const int OLD_NUM_DEVICES = 26; /* a..z */
378 if (partId < OLD_NUM_DEVICES) {
379 if (partNameSize < 8) {
382 strlcpy(partName, "/vicep", partNameSize);
383 partName[6] = partId + 'a';
387 if (partId < VOLMAXPARTS) {
388 if (partNameSize < 9) {
391 strlcpy(partName, "/vicep", partNameSize);
392 partId -= OLD_NUM_DEVICES;
393 partName[6] = 'a' + (partId / OLD_NUM_DEVICES);
394 partName[7] = 'a' + (partId % OLD_NUM_DEVICES);
402 * Process command line options and start scanning
404 * @param[in] as command syntax object
405 * @param[in] arock opaque object; not used
410 handleit(struct cmd_syndesc *as, void *arock)
414 afs_uint32 volumeId = 0;
415 char *partNameOrId = 0;
416 char partName[64] = "";
417 struct DiskPartition64 *partP = NULL;
421 if (geteuid() != 0) {
422 fprintf(stderr, "%s: Must be run as root; sorry\n", progname);
427 if (as->parms[P_ONLINE].items) {
428 fprintf(stderr, "%s: -online not supported\n", progname);
431 if (as->parms[P_VNODE].items) {
434 if (as->parms[P_DATE].items) {
437 if (as->parms[P_INODE].items) {
440 if (as->parms[P_ITIME].items) {
443 if ((ti = as->parms[P_PART].items)) {
444 partNameOrId = ti->data;
446 if ((ti = as->parms[P_VOLUMEID].items)) {
447 volumeId = strtoul(ti->data, NULL, 10);
449 if (as->parms[P_HEADER].items) {
452 if (as->parms[P_SIZEONLY].items) {
455 if (as->parms[P_FIXHEADER].items) {
458 if (as->parms[P_SAVEINODES].items) {
461 if (as->parms[P_ORPHANED].items) {
464 #if defined(AFS_NAMEI_ENV)
465 if (as->parms[P_FILENAMES].items) {
470 /* -saveinodes and -sizeOnly override the default mode.
471 * For compatibility with old versions of volinfo, -orphaned
472 * and -filename options imply -vnodes */
473 if (SaveInodes || ShowSizes) {
479 } else if (ShowOrphaned) {
480 DumpVnodes = 1; /* implied */
482 } else if (PrintFileNames) {
483 DumpVnodes = 1; /* implied */
487 /* Allow user to specify partition by name or id. */
489 afs_uint32 partId = volutil_GetPartitionID(partNameOrId);
491 fprintf(stderr, "%s: Could not parse '%s' as a partition name.\n",
492 progname, partNameOrId);
495 if (GetPartitionName(partId, partName, sizeof(partName))) {
497 "%s: Could not format '%s' as a partition name.\n",
498 progname, partNameOrId);
505 err = VAttachPartitions();
507 fprintf(stderr, "%s: %d partitions had errors during attach.\n",
512 partP = VGetPartition(partName, 0);
515 "%s: %s is not an AFS partition name on this server.\n",
531 partP = FindCurrentPartition();
534 "%s: Current partition is not a vice partition.\n",
539 snprintf(name1, sizeof name1, VFORMAT,
540 afs_printable_uint32_lu(volumeId));
541 HandleVolume(partP, name1);
547 * Determine if the current directory is a vice partition
549 * @return disk partition object
553 struct DiskPartition64 *
554 FindCurrentPartition(void)
556 int dr = _getdrive();
557 struct DiskPartition64 *dp;
560 for (dp = DiskPartitionList; dp; dp = dp->next) {
561 if (*dp->devName - 'A' == dr)
565 fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
571 struct DiskPartition64 *
572 FindCurrentPartition(void)
577 struct DiskPartition64 *dp;
579 if (!getcwd(partName, 1023)) {
580 fprintf(stderr, "%s: Failed to get current working directory: ",
585 p = strchr(&partName[1], OS_DIRSEPC);
590 if (!(dp = VGetPartition(partName, 0))) {
593 fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
602 * Scan and handle all the partitions detected on this server
609 struct DiskPartition64 *partP;
612 for (partP = DiskPartitionList; partP; partP = partP->next) {
613 printf("Processing Partition %s:\n", partP->name);
616 AddSizeTotals(&serverTotals, &partitionTotals);
626 * Scan the partition and handle volumes
628 * @param[in] partP disk partition to scan
633 HandlePart(struct DiskPartition64 *partP)
641 (void)sprintf(pname, "%s\\", VPartitionPath(partP));
643 char *p = VPartitionPath(partP);
646 if ((dirp = opendir(p)) == NULL) {
647 fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
651 while ((dp = readdir(dirp))) {
652 p = (char *)strrchr(dp->d_name, '.');
653 if (p != NULL && strcmp(p, VHDREXT) == 0) {
654 HandleVolume(partP, dp->d_name);
657 AddSizeTotals(&partitionTotals, &volumeTotals);
663 PrintPartitionTotals(nvols);
668 * Inspect a volume header special file.
670 * @param[in] name descriptive name of the type of header special file
671 * @param[in] dp partition object for this volume
672 * @param[in] header header object for this volume
673 * @param[in] inode fileserver inode number for this header special file
674 * @param[out] psize total of the header special file
679 HandleSpecialFile(const char *name, struct DiskPartition64 *dp,
680 struct VolumeHeader *header, Inode inode,
681 afs_sfsize_t * psize)
683 afs_sfsize_t size = 0;
684 IHandle_t *ih = NULL;
685 FdHandle_t *fdP = NULL;
688 #endif /* AFS_NAMEI_ENV */
690 IH_INIT(ih, dp->device, header->parent, inode);
694 "%s: Error opening header file '%s' for volume %u", progname,
699 size = FDH_SIZE(fdP);
702 "%s: Error getting size of header file '%s' for volume %u",
703 progname, name, header->id);
708 printf("\t%s inode\t= %s (size = %lld)\n",
709 name, PrintInode(NULL, inode), size);
711 namei_HandleToName(&filename, ih);
712 printf("\t%s namei\t= %s\n", name, filename.n_path);
713 #endif /* AFS_NAMEI_ENV */
719 FDH_REALLYCLOSE(fdP);
727 * Inspect this volume header files.
729 * @param[in] dp partition object for this volume
730 * @param[in] header_fd volume header file descriptor
731 * @param[in] header volume header object
732 * @param[out] psize total of the header special file
737 HandleHeaderFiles(struct DiskPartition64 *dp, FD_t header_fd,
738 struct VolumeHeader *header)
740 afs_sfsize_t size = 0;
743 size = OS_SIZE(header_fd);
744 printf("Volume header (size = %lld):\n", size);
745 printf("\tstamp\t= 0x%x\n", header->stamp.version);
746 printf("\tVolId\t= %u\n", header->id);
747 printf("\tparent\t= %u\n", header->parent);
750 HandleSpecialFile("Info", dp, header, header->volumeInfo, &size);
751 HandleSpecialFile("Small", dp, header, header->smallVnodeIndex,
753 HandleSpecialFile("Large", dp, header, header->largeVnodeIndex,
756 HandleSpecialFile("Link", dp, header, header->linkTable, &size);
757 #endif /* AFS_NAMEI_ENV */
760 printf("Total aux volume size = %lld\n\n", size);
764 volumeTotals.auxsize = size;
765 volumeTotals.auxsize_k = size / 1024;
770 * Attach and scan the volume and handle the header and vnodes
772 * Print the volume header and vnode information, depending on the
775 * @param[in] dp vice partition object for this volume
776 * @param[in] name volume header file name
781 HandleVolume(struct DiskPartition64 *dp, char *name)
783 struct VolumeHeader header;
784 struct VolumeDiskHeader diskHeader;
785 FD_t fd = INVALID_FD;
787 char headerName[1024];
790 snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
791 VPartitionPath(dp), name);
792 if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD) {
793 fprintf(stderr, "%s: Cannot open volume header %s\n", progname, name);
796 if (OS_SIZE(fd) < 0) {
797 fprintf(stderr, "%s: Cannot read volume header %s\n", progname, name);
801 n = OS_READ(fd, &diskHeader, sizeof(diskHeader));
802 if (n != sizeof(diskHeader)
803 || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
804 fprintf(stderr, "%s: Error reading volume header %s\n", progname,
809 if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
811 "%s: Volume %s, version number is incorrect; volume needs to be salvaged\n",
816 DiskToVolumeHeader(&header, &diskHeader);
817 if (DumpHeader || ShowSizes) {
818 HandleHeaderFiles(dp, fd, &header);
821 vp = AttachVolume(dp, name, &header);
823 fprintf(stderr, "%s: Error attaching volume header %s\n",
830 if (DumpVnodes || ShowSizes || ShowOrphaned) {
831 HandleVnodes(vp, vLarge);
833 if (DumpVnodes || ShowSizes || SaveInodes || ShowOrphaned) {
834 HandleVnodes(vp, vSmall);
837 volumeTotals.diskused_k = V_diskused(vp);
838 volumeTotals.size_k =
839 volumeTotals.auxsize_k + volumeTotals.vnodesize_k;
840 PrintVolumeSizes(vp);
848 * volinfo program entry
851 main(int argc, char **argv)
853 struct cmd_syndesc *ts;
856 ts = cmd_CreateSyntax(NULL, handleit, NULL,
857 "Dump volume's internal state");
858 cmd_AddParmAtOffset(ts, P_ONLINE, "-online", CMD_FLAG, CMD_OPTIONAL,
859 "Get info from running fileserver");
860 cmd_AddParmAtOffset(ts, P_VNODE, "-vnode", CMD_FLAG, CMD_OPTIONAL,
862 cmd_AddParmAtOffset(ts, P_DATE, "-date", CMD_FLAG, CMD_OPTIONAL,
863 "Also dump vnode's mod date");
864 cmd_AddParmAtOffset(ts, P_INODE, "-inode", CMD_FLAG, CMD_OPTIONAL,
865 "Also dump vnode's inode number");
866 cmd_AddParmAtOffset(ts, P_ITIME, "-itime", CMD_FLAG, CMD_OPTIONAL,
867 "Dump special inode's mod times");
868 cmd_AddParmAtOffset(ts, P_PART, "-part", CMD_LIST, CMD_OPTIONAL,
869 "AFS partition name or id (default current partition)");
870 cmd_AddParmAtOffset(ts, P_VOLUMEID, "-volumeid", CMD_LIST, CMD_OPTIONAL,
872 cmd_AddParmAtOffset(ts, P_HEADER, "-header", CMD_FLAG, CMD_OPTIONAL,
873 "Dump volume's header info");
874 cmd_AddParmAtOffset(ts, P_SIZEONLY, "-sizeonly", CMD_FLAG, CMD_OPTIONAL,
875 "Dump volume's size");
876 cmd_AddParmAtOffset(ts, P_FIXHEADER, "-fixheader", CMD_FLAG,
877 CMD_OPTIONAL, "Try to fix header");
878 cmd_AddParmAtOffset(ts, P_SAVEINODES, "-saveinodes", CMD_FLAG,
879 CMD_OPTIONAL, "Try to save all inodes");
880 cmd_AddParmAtOffset(ts, P_ORPHANED, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
881 "List all dir/files without a parent");
882 #if defined(AFS_NAMEI_ENV)
883 cmd_AddParmAtOffset(ts, P_FILENAMES, "-filenames", CMD_FLAG,
884 CMD_OPTIONAL, "Also dump vnode's namei filename");
887 /* For compatibility with older versions. */
888 cmd_AddParmAlias(ts, P_SIZEONLY, "-sizeOnly");
890 code = cmd_Dispatch(argc, argv);
894 #define typestring(type) (type == RWVOL? "read/write": type == ROVOL? "readonly": type == BACKVOL? "backup": "unknown")
897 * Print the volume header information
899 * @param[in] volume object
904 PrintHeader(Volume * vp)
906 printf("Volume header for volume %u (%s)\n", V_id(vp), V_name(vp));
907 printf("stamp.magic = %x, stamp.version = %u\n", V_stamp(vp).magic,
908 V_stamp(vp).version);
910 ("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n",
911 V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp),
914 ("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n",
915 V_type(vp), typestring(V_type(vp)), V_uniquifier(vp),
916 V_needsCallback(vp), V_destroyMe(vp));
918 ("id = %u, parentId = %u, cloneId = %u, backupId = %u, restoredFromId = %u\n",
919 V_id(vp), V_parentId(vp), V_cloneId(vp), V_backupId(vp),
920 V_restoredFromId(vp));
922 ("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n",
923 V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp),
925 printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)),
926 date(V_copyDate(vp)));
927 printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)),
928 date(V_expirationDate(vp)));
929 printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)),
930 date(V_updateDate(vp)));
931 printf("owner = %u, accountNumber = %u\n", V_owner(vp),
932 V_accountNumber(vp));
934 ("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n",
935 V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2],
936 V_weekUse(vp)[3], V_weekUse(vp)[4], V_weekUse(vp)[5],
937 V_weekUse(vp)[6], date(V_dayUseDate(vp)));
938 printf("volUpdateCounter = %u\n", V_volUpCounter(vp));
942 * Get the size and times of a file
944 * @param[in] fd file descriptor of file to stat
945 * @param[out] size size of the file
946 * @param[out] ctime ctime of file as a formatted string
947 * @param[out] mtime mtime of file as a formatted string
948 * @param[out] atime atime of file as a formatted string
952 * @retval -1 failed to retrieve file information
955 GetFileInfo(FD_t fd, afs_sfsize_t * size, char **ctime, char **mtime,
959 BY_HANDLE_FILE_INFORMATION fi;
961 if (!GetFileInformationByHandle(fd, &fi)) {
962 fprintf(stderr, "%s: GetFileInformationByHandle failed\n", progname);
965 if (!GetFileSizeEx(fd, &fsize)) {
966 fprintf(stderr, "%s: GetFileSizeEx failed\n", progname);
969 *size = fsize.QuadPart;
971 *mtime = NT_date(&fi.ftLastWriteTime);
972 *atime = NT_date(&fi.ftLastAccessTime);
974 struct afs_stat_st status;
975 if (afs_fstat(fd, &status) == -1) {
976 fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
979 *size = status.st_size;
980 *ctime = date(status.st_ctime);
981 *mtime = date(status.st_mtime);
982 *atime = date(status.st_atime);
988 * Copy the inode data to a file in the current directory.
990 * @param[in] vp volume object
991 * @param[in] vnode vnode object
992 * @param[in] inode inode of the source file
997 SaveInode(Volume * vp, struct VnodeDiskObject *vnode, Inode ino)
1001 char nfile[50], buffer[256];
1006 if (!VALID_INO(ino)) {
1010 IH_INIT(ih, V_device(vp), V_parentId(vp), ino);
1014 "%s: Can't open inode %s error %d (ignored)\n",
1015 progname, PrintInode(NULL, ino), errno);
1018 snprintf(nfile, sizeof nfile, "TmpInode.%s", PrintInode(NULL, ino));
1019 ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
1022 "%s: Can't create file %s; error %d (ignored)\n",
1023 progname, nfile, errno);
1025 FDH_REALLYCLOSE(fdP);
1032 len = FDH_PREAD(fdP, buffer, sizeof(buffer), total);
1034 FDH_REALLYCLOSE(fdP);
1039 "%s: Error while reading from inode %s (%d)\n",
1040 progname, PrintInode(NULL, ino), errno);
1044 break; /* No more input */
1045 nBytes = write(ofd, buffer, len);
1046 if (nBytes != len) {
1047 FDH_REALLYCLOSE(fdP);
1052 "%s: Error while writing to \"%s\" (%d - ignored)\n",
1053 progname, nfile, errno);
1059 FDH_REALLYCLOSE(fdP);
1062 printf("... Copied inode %s to file %s (%lu bytes)\n",
1063 PrintInode(NULL, ino), nfile, (unsigned long)total);
1067 * Scan a volume index and handle each vnode
1069 * @param[in] vp volume object
1070 * @param[in] class which index to scan
1075 HandleVnodes(Volume * vp, VnodeClass class)
1077 afs_int32 diskSize =
1078 (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE);
1079 char buf[SIZEOF_LARGEDISKVNODE];
1080 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1081 StreamHandle_t *file = NULL;
1083 afs_sfsize_t nVnodes;
1084 afs_foff_t offset = 0;
1086 IHandle_t *ih = vp->vnodeIndex[class].handle;
1087 FdHandle_t *fdP = NULL;
1089 char *ctime, *atime, *mtime;
1091 /* print vnode table heading */
1092 if (class == vLarge) {
1094 printf("\nLarge vnodes (directories)\n");
1098 printf("\nSmall vnodes(files, symbolic links)\n");
1102 printf("Saving all volume files to current directory ...\n");
1104 PrintingVolumeSizes = 0; /* print heading again */
1111 fprintf(stderr, "%s: open failed: ", progname);
1115 file = FDH_FDOPEN(fdP, "r");
1117 fprintf(stderr, "%s: fdopen failed\n", progname);
1121 if (GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime) != 0) {
1125 printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime,
1129 nVnodes = (size / diskSize) - 1;
1131 STREAM_ASEEK(file, diskSize);
1135 for (vnodeIndex = 0;
1136 nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1;
1137 nVnodes--, vnodeIndex++, offset += diskSize) {
1139 ino = VNDISK_GET_INO(vnode);
1141 afs_fsize_t fileLength;
1143 VNDISK_GET_LEN(fileLength, vnode);
1144 if (fileLength > 0) {
1145 volumeTotals.vnodesize += fileLength;
1146 volumeTotals.vnodesize_k += fileLength / 1024;
1149 if (SaveInodes && (class == vSmall)) {
1150 SaveInode(vp, vnode, ino);
1152 if (DumpVnodes || ShowOrphaned) {
1153 PrintVnode(offset, vnode,
1154 bitNumberToVnodeNumber(vnodeIndex, class), ino, vp);
1168 * Print vnode information
1170 * @param[in] offset index offset of this vnode
1171 * @param[in] vnode vnode object to be printed
1172 * @param[in] vnodeNumber vnode number
1173 * @param[in] ino fileserver inode number
1174 * @param[in] vp parent volume of the vnode
1179 PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
1180 Inode ino, Volume * vp)
1182 #if defined(AFS_NAMEI_ENV)
1186 afs_fsize_t fileLength;
1188 VNDISK_GET_LEN(fileLength, vnode);
1190 /* The check for orphaned vnodes is currently limited to non-empty
1191 * vnodes with a parent of zero (and which are not the first entry
1193 if (ShowOrphaned && (fileLength == 0 || vnode->parent || !offset))
1197 ("%10lld Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
1198 (long long)offset, vnodeNumber, vnode->uniquifier, vnode->dataVersion,
1199 vnode->cloned, (afs_uintmax_t) fileLength, vnode->linkCount,
1201 if (DumpInodeNumber)
1202 printf(" inode: %s", PrintInode(NULL, ino));
1204 printf(" ServerModTime: %s", date(vnode->serverModifyTime));
1205 #if defined(AFS_NAMEI_ENV)
1206 if (PrintFileNames) {
1207 IH_INIT(ihtmpp, V_device(vp), V_parentId(vp), ino);
1208 namei_HandleToName(&filename, ihtmpp);
1209 #if !defined(AFS_NT40_ENV)
1210 printf(" UFS-Filename: %s", filename.n_path);
1212 printf(" NTFS-Filename: %s", filename.n_path);