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
32 #include <afs/afsint.h>
34 #include <afs/errors.h>
37 #include <afs/afssyscalls.h>
41 #include "partition.h"
42 #include "viceinode.h"
43 #include <afs/afssyscalls.h>
44 #include <afs/afsutil.h>
47 #include "AFS_component_version_number.c"
50 static const char *progname = "volinfo";
53 static int DumpInfo = 1; /**< Dump volume information, defualt mode*/
54 static int DumpHeader = 0; /**< Dump volume header files info */
55 static int DumpVnodes = 0; /**< Dump vnode info */
56 static int DumpInodeNumber = 0; /**< Dump inode numbers with vnodes */
57 static int DumpDate = 0; /**< Dump vnode date (server modify date) with vnode */
58 static int InodeTimes = 0; /**< Dump some of the dates associated with inodes */
59 #if defined(AFS_NAMEI_ENV)
60 static int PrintFileNames = 0; /**< Dump vnode and special file name filenames */
62 static int ShowOrphaned = 0; /**< Show "orphaned" vnodes (vnodes with parent of 0) */
63 static int ShowSizes = 0; /**< Show volume size summary */
64 static int SaveInodes = 0; /**< Save vnode data to files */
65 static int FixHeader = 0; /**< Repair header files magic and version fields. */
68 * Volume size running totals
71 afs_uint64 diskused_k; /**< volume size from disk data file, in kilobytes */
72 afs_uint64 auxsize; /**< size of header files, in bytes */
73 afs_uint64 auxsize_k; /**< size of header files, in kilobytes */
74 afs_uint64 vnodesize; /**< size of the large and small vnodes, in bytes */
75 afs_uint64 vnodesize_k; /**< size of the large and small vnodes, in kilobytes */
76 afs_uint64 size_k; /**< size of headers and vnodes, in kilobytes */
79 static struct sizeTotals volumeTotals = { 0, 0, 0, 0, 0, 0 };
80 static struct sizeTotals partitionTotals = { 0, 0, 0, 0, 0, 0 };
81 static struct sizeTotals serverTotals = { 0, 0, 0, 0, 0, 0 };
82 static int PrintingVolumeSizes = 0; /*print volume size lines */
84 /* Forward Declarations */
85 void PrintHeader(Volume * vp);
86 void HandleAllPart(void);
87 void HandlePart(struct DiskPartition64 *partP);
88 void HandleVolume(struct DiskPartition64 *partP, char *name);
89 struct DiskPartition64 *FindCurrentPartition(void);
90 Volume *AttachVolume(struct DiskPartition64 *dp, char *volname,
91 struct VolumeHeader *header);
92 void PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
93 Inode ino, Volume * vp);
94 void HandleVnodes(Volume * vp, VnodeClass class);
97 * Format time as a timestamp string
99 * @param[in] date time value to format
101 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
103 * @note A static array of 8 strings are stored by this
104 * function. The array slots are overwritten, so the
105 * caller must not reference the returned string after
106 * seven additional calls to this function.
111 #define MAX_DATE_RESULT 100
112 static char results[8][MAX_DATE_RESULT];
114 struct tm *tm = localtime(&date);
117 (void)strftime(buf, 32, "%Y/%m/%d.%H:%M:%S", tm); /* NT does not have %T */
118 snprintf(results[next = (next + 1) & 7], MAX_DATE_RESULT,
119 "%lu (%s)", (unsigned long)date, buf);
120 return results[next];
125 * Format file time as a timestamp string
127 * @param[in] ft file time
129 * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
131 * @note A static array of 8 strings are stored by this
132 * function. The array slots are overwritten, so the
133 * caller must not reference the returned string after
134 * seven additional calls to this function.
137 NT_date(FILETIME * ft)
139 static char result[8][64];
144 if (!FileTimeToLocalFileTime(ft, &lft)
145 || !FileTimeToSystemTime(&lft, &st)) {
146 fprintf(stderr, "%s: Time conversion failed.\n", progname);
149 sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
150 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
156 * Print the volume size table heading line, if needed.
161 PrintVolumeSizeHeading(void)
163 if (!PrintingVolumeSizes) {
165 ("Volume-Id\t Volsize Auxsize Inodesize AVolsize SizeDiff (VolName)\n");
166 PrintingVolumeSizes = 1;
176 AddSizeTotals(struct sizeTotals *a, struct sizeTotals *b)
178 a->diskused_k += b->diskused_k;
179 a->auxsize += b->auxsize;
180 a->auxsize_k += b->auxsize_k;
181 a->vnodesize += b->vnodesize;
182 a->vnodesize_k += b->vnodesize_k;
183 a->size_k += b->size_k;
187 * Print the sizes for a volume.
192 PrintVolumeSizes(Volume * vp)
194 afs_int64 diff_k = volumeTotals.size_k - volumeTotals.diskused_k;
196 PrintVolumeSizeHeading();
197 printf("%u\t%9llu%9llu%10llu%10llu%9lld\t%24s\n",
199 volumeTotals.diskused_k,
200 volumeTotals.auxsize_k, volumeTotals.vnodesize_k,
201 volumeTotals.size_k, diff_k, V_name(vp));
205 * Print the size totals for the partition.
210 PrintPartitionTotals(afs_uint64 nvols)
212 afs_int64 diff_k = partitionTotals.size_k - partitionTotals.diskused_k;
214 PrintVolumeSizeHeading();
215 printf("\nPart Totals %12llu%9llu%10llu%10llu%9lld (%llu volumes)\n\n",
216 partitionTotals.diskused_k, partitionTotals.auxsize,
217 partitionTotals.vnodesize, partitionTotals.size_k, diff_k, nvols);
218 PrintingVolumeSizes = 0;
222 * Print the size totals for all the partitions.
227 PrintServerTotals(void)
229 afs_int64 diff_k = serverTotals.size_k - serverTotals.diskused_k;
231 printf("\nServer Totals%12lld%9lld%10lld%10lld%9lld\n",
232 serverTotals.diskused_k, serverTotals.auxsize,
233 serverTotals.vnodesize, serverTotals.size_k, diff_k);
237 * Read a volume header file
239 * @param[in] ih ihandle of the header file
240 * @param[in] to destination
241 * @param[in] size expected header size
242 * @param[in] magic expected header magic number
243 * @param[in] version expected header version number
247 * @retval -1 failed to read file
250 ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
252 struct versionStamp *vsn;
256 vsn = (struct versionStamp *)to;
258 code = IH_IREAD(ih, 0, to, size);
262 if (vsn->magic != magic) {
264 fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
265 progname, PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
268 /* Check is conditional, in case caller wants to inspect version himself */
269 if (version && vsn->version != version) {
271 fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
273 PrintInode(NULL, ih->ih_ino), vsn->version, version);
275 if (bad && FixHeader) {
277 vsn->version = version;
278 printf("Special index inode %s has a bad header. Reconstructing...\n",
279 PrintInode(NULL, ih->ih_ino));
280 code = IH_IWRITE(ih, 0, to, size);
283 "%s: Write failed for inode %s; header left in damaged state\n",
284 progname, PrintInode(NULL, ih->ih_ino));
288 printf("Inode %s: Good magic %x and version %x\n",
289 PrintInode(NULL, ih->ih_ino), magic, version);
296 * Simplified attach volume
298 * param[in] dp vice disk partition object
299 * param[in] volname volume header file name
300 * param[in] header volume header object
302 * @return volume object or null on error
305 AttachVolume(struct DiskPartition64 * dp, char *volname,
306 struct VolumeHeader * header)
311 vp = (Volume *) calloc(1, sizeof(Volume));
312 vp->specialStatus = 0;
313 vp->device = dp->device;
315 IH_INIT(vp->vnodeIndex[vLarge].handle, dp->device, header->parent,
316 header->largeVnodeIndex);
317 IH_INIT(vp->vnodeIndex[vSmall].handle, dp->device, header->parent,
318 header->smallVnodeIndex);
319 IH_INIT(vp->diskDataHandle, dp->device, header->parent,
321 IH_INIT(V_linkHandle(vp), dp->device, header->parent, header->linkTable);
322 vp->cacheCheck = 0; /* XXXX */
323 vp->shuttingDown = 0;
324 vp->goingOffline = 0;
326 vp->header = (struct volHeader *)calloc(1, sizeof(*vp->header));
327 ec = ReadHdr1(V_diskDataHandle(vp), (char *)&V_disk(vp),
328 sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
330 struct IndexFileHeader iHead;
331 ec = ReadHdr1(vp->vnodeIndex[vSmall].handle, (char *)&iHead,
332 sizeof(iHead), SMALLINDEXMAGIC, SMALLINDEXVERSION);
335 struct IndexFileHeader iHead;
336 ec = ReadHdr1(vp->vnodeIndex[vLarge].handle, (char *)&iHead,
337 sizeof(iHead), LARGEINDEXMAGIC, LARGEINDEXVERSION);
341 struct versionStamp stamp;
342 ec = ReadHdr1(V_linkHandle(vp), (char *)&stamp, sizeof(stamp),
343 LINKTABLEMAGIC, LINKTABLEVERSION);
352 * Process command line options and start scanning
354 * @param[in] as command syntax object
355 * @param[in] arock opaque object; not used
360 handleit(struct cmd_syndesc *as, void *arock)
364 afs_uint32 volumeId = 0;
366 struct DiskPartition64 *partP = NULL;
370 if (geteuid() != 0) {
371 fprintf(stderr, "%s: Must be run as root; sorry\n", progname);
376 if (as->parms[0].items) { /* -online */
377 fprintf(stderr, "%s: -online not supported\n", progname);
380 if (as->parms[1].items) { /* -vnode */
383 if (as->parms[2].items) { /* -date */
386 if (as->parms[3].items) { /* -inode */
389 if (as->parms[4].items) { /* -itime */
392 if ((ti = as->parms[5].items)) { /* -part */
395 if ((ti = as->parms[6].items)) { /* -volumeid */
396 volumeId = strtoul(ti->data, NULL, 10);
398 if (as->parms[7].items) { /* -header */
401 if (as->parms[8].items) { /* -sizeOnly */
404 if (as->parms[9].items) { /* -FixHeader */
407 if (as->parms[10].items) { /* -saveinodes */
410 if (as->parms[11].items) { /* -orphaned */
413 #if defined(AFS_NAMEI_ENV)
414 if (as->parms[12].items) { /* -filenames */
419 /* -saveinodes and -sizeOnly override the default mode.
420 * For compatibility with old versions of volinfo, -orphaned
421 * and -filename options imply -vnodes */
422 if (SaveInodes || ShowSizes) {
428 } else if (ShowOrphaned || PrintFileNames) {
429 DumpVnodes = 1; /* implied */
434 err = VAttachPartitions();
436 fprintf(stderr, "%s: %d partitions had errors during attach.\n",
441 partP = VGetPartition(partName, 0);
444 "%s: %s is not an AFS partition name on this server.\n",
460 partP = FindCurrentPartition();
463 "%s: Current partition is not a vice partition.\n",
468 snprintf(name1, sizeof name1, VFORMAT,
469 afs_printable_uint32_lu(volumeId));
470 HandleVolume(partP, name1);
476 * Determine if the current directory is a vice partition
478 * @return disk partition object
482 struct DiskPartition64 *
483 FindCurrentPartition(void)
485 int dr = _getdrive();
486 struct DiskPartition64 *dp;
489 for (dp = DiskPartitionList; dp; dp = dp->next) {
490 if (*dp->devName - 'A' == dr)
494 fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
500 struct DiskPartition64 *
501 FindCurrentPartition(void)
506 struct DiskPartition64 *dp;
508 if (!getcwd(partName, 1023)) {
509 fprintf(stderr, "%s: Failed to get current working directory: ",
514 p = strchr(&partName[1], OS_DIRSEPC);
519 if (!(dp = VGetPartition(partName, 0))) {
522 fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
531 * Scan and handle all the partitions detected on this server
538 struct DiskPartition64 *partP;
541 for (partP = DiskPartitionList; partP; partP = partP->next) {
542 printf("Processing Partition %s:\n", partP->name);
545 AddSizeTotals(&serverTotals, &partitionTotals);
555 * Scan the partition and handle volumes
557 * @param[in] partP disk partition to scan
562 HandlePart(struct DiskPartition64 *partP)
570 (void)sprintf(pname, "%s\\", VPartitionPath(partP));
572 char *p = VPartitionPath(partP);
575 if ((dirp = opendir(p)) == NULL) {
576 fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
580 while ((dp = readdir(dirp))) {
581 p = (char *)strrchr(dp->d_name, '.');
582 if (p != NULL && strcmp(p, VHDREXT) == 0) {
583 HandleVolume(partP, dp->d_name);
586 AddSizeTotals(&partitionTotals, &volumeTotals);
592 PrintPartitionTotals(nvols);
597 * Inspect a volume header special file.
599 * @param[in] name descriptive name of the type of header special file
600 * @param[in] dp partition object for this volume
601 * @param[in] header header object for this volume
602 * @param[in] inode fileserver inode number for this header special file
603 * @param[out] psize total of the header special file
608 HandleSpecialFile(const char *name, struct DiskPartition64 *dp,
609 struct VolumeHeader *header, Inode inode,
610 afs_sfsize_t * psize)
612 afs_sfsize_t size = 0;
613 IHandle_t *ih = NULL;
614 FdHandle_t *fdP = NULL;
617 #endif /* AFS_NAMEI_ENV */
619 IH_INIT(ih, dp->device, header->parent, inode);
623 "%s: Error opening header file '%s' for volume %u", progname,
628 size = FDH_SIZE(fdP);
631 "%s: Error getting size of header file '%s' for volume %u",
632 progname, name, header->id);
637 printf("\t%s inode\t= %s (size = %lld)\n",
638 name, PrintInode(NULL, inode), size);
640 namei_HandleToName(&filename, ih);
641 printf("\t%s namei\t= %s\n", name, filename.n_path);
642 #endif /* AFS_NAMEI_ENV */
648 FDH_REALLYCLOSE(fdP);
656 * Inspect this volume header files.
658 * @param[in] dp partition object for this volume
659 * @param[in] header_fd volume header file descriptor
660 * @param[in] header volume header object
661 * @param[out] psize total of the header special file
666 HandleHeaderFiles(struct DiskPartition64 *dp, FD_t header_fd,
667 struct VolumeHeader *header)
669 afs_sfsize_t size = 0;
672 size = OS_SIZE(header_fd);
673 printf("Volume header (size = %lld):\n", size);
674 printf("\tstamp\t= 0x%x\n", header->stamp.version);
675 printf("\tVolId\t= %u\n", header->id);
676 printf("\tparent\t= %u\n", header->parent);
679 HandleSpecialFile("Info", dp, header, header->volumeInfo, &size);
680 HandleSpecialFile("Small", dp, header, header->smallVnodeIndex,
682 HandleSpecialFile("Large", dp, header, header->largeVnodeIndex,
685 HandleSpecialFile("Link", dp, header, header->linkTable, &size);
686 #endif /* AFS_NAMEI_ENV */
689 printf("Total aux volume size = %lld\n\n", size);
693 volumeTotals.auxsize = size;
694 volumeTotals.auxsize_k = size / 1024;
699 * Attach and scan the volume and handle the header and vnodes
701 * Print the volume header and vnode information, depending on the
704 * @param[in] dp vice partition object for this volume
705 * @param[in] name volume header file name
710 HandleVolume(struct DiskPartition64 *dp, char *name)
712 struct VolumeHeader header;
713 struct VolumeDiskHeader diskHeader;
714 FD_t fd = INVALID_FD;
716 char headerName[1024];
719 snprintf(headerName, sizeof headerName, "%s" OS_DIRSEP "%s",
720 VPartitionPath(dp), name);
721 if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD) {
722 fprintf(stderr, "%s: Cannot open volume header %s\n", progname, name);
725 if (OS_SIZE(fd) < 0) {
726 fprintf(stderr, "%s: Cannot read volume header %s\n", progname, name);
730 n = OS_READ(fd, &diskHeader, sizeof(diskHeader));
731 if (n != sizeof(diskHeader)
732 || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
733 fprintf(stderr, "%s: Error reading volume header %s\n", progname,
738 if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
740 "%s: Volume %s, version number is incorrect; volume needs to be salvaged\n",
745 DiskToVolumeHeader(&header, &diskHeader);
746 if (DumpHeader || ShowSizes) {
747 HandleHeaderFiles(dp, fd, &header);
750 vp = AttachVolume(dp, name, &header);
752 fprintf(stderr, "%s: Error attaching volume header %s\n",
759 if (DumpVnodes || ShowSizes || ShowOrphaned) {
760 HandleVnodes(vp, vLarge);
762 if (DumpVnodes || ShowSizes || SaveInodes || ShowOrphaned) {
763 HandleVnodes(vp, vSmall);
766 volumeTotals.diskused_k = V_diskused(vp);
767 volumeTotals.size_k =
768 volumeTotals.auxsize_k + volumeTotals.vnodesize_k;
769 PrintVolumeSizes(vp);
776 * volinfo program entry
779 main(int argc, char **argv)
781 struct cmd_syndesc *ts;
784 ts = cmd_CreateSyntax(NULL, handleit, NULL, "Dump volume's internal state");
785 cmd_AddParm(ts, "-online", CMD_FLAG, CMD_OPTIONAL,
786 "Get info from running fileserver");
787 cmd_AddParm(ts, "-vnode", CMD_FLAG, CMD_OPTIONAL, "Dump vnode info");
788 cmd_AddParm(ts, "-date", CMD_FLAG, CMD_OPTIONAL,
789 "Also dump vnode's mod date");
790 cmd_AddParm(ts, "-inode", CMD_FLAG, CMD_OPTIONAL,
791 "Also dump vnode's inode number");
792 cmd_AddParm(ts, "-itime", CMD_FLAG, CMD_OPTIONAL,
793 "Dump special inode's mod times");
794 cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL,
795 "AFS partition name (default current partition)");
796 cmd_AddParm(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id");
797 cmd_AddParm(ts, "-header", CMD_FLAG, CMD_OPTIONAL,
798 "Dump volume's header info");
799 cmd_AddParm(ts, "-sizeOnly", CMD_FLAG, CMD_OPTIONAL,
800 "Dump volume's size");
801 cmd_AddParm(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL,
802 "Try to fix header");
803 cmd_AddParm(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL,
804 "Try to save all inodes");
805 cmd_AddParm(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
806 "List all dir/files without a parent");
807 #if defined(AFS_NAMEI_ENV)
808 cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's namei filename");
810 code = cmd_Dispatch(argc, argv);
814 #define typestring(type) (type == RWVOL? "read/write": type == ROVOL? "readonly": type == BACKVOL? "backup": "unknown")
817 * Print the volume header information
819 * @param[in] volume object
824 PrintHeader(Volume * vp)
826 printf("Volume header for volume %u (%s)\n", V_id(vp), V_name(vp));
827 printf("stamp.magic = %x, stamp.version = %u\n", V_stamp(vp).magic,
828 V_stamp(vp).version);
830 ("inUse = %d, inService = %d, blessed = %d, needsSalvaged = %d, dontSalvage = %d\n",
831 V_inUse(vp), V_inService(vp), V_blessed(vp), V_needsSalvaged(vp),
834 ("type = %d (%s), uniquifier = %u, needsCallback = %d, destroyMe = %x\n",
835 V_type(vp), typestring(V_type(vp)), V_uniquifier(vp),
836 V_needsCallback(vp), V_destroyMe(vp));
838 ("id = %u, parentId = %u, cloneId = %u, backupId = %u, restoredFromId = %u\n",
839 V_id(vp), V_parentId(vp), V_cloneId(vp), V_backupId(vp),
840 V_restoredFromId(vp));
842 ("maxquota = %d, minquota = %d, maxfiles = %d, filecount = %d, diskused = %d\n",
843 V_maxquota(vp), V_minquota(vp), V_maxfiles(vp), V_filecount(vp),
845 printf("creationDate = %s, copyDate = %s\n", date(V_creationDate(vp)),
846 date(V_copyDate(vp)));
847 printf("backupDate = %s, expirationDate = %s\n", date(V_backupDate(vp)),
848 date(V_expirationDate(vp)));
849 printf("accessDate = %s, updateDate = %s\n", date(V_accessDate(vp)),
850 date(V_updateDate(vp)));
851 printf("owner = %u, accountNumber = %u\n", V_owner(vp),
852 V_accountNumber(vp));
854 ("dayUse = %u; week = (%u, %u, %u, %u, %u, %u, %u), dayUseDate = %s\n",
855 V_dayUse(vp), V_weekUse(vp)[0], V_weekUse(vp)[1], V_weekUse(vp)[2],
856 V_weekUse(vp)[3], V_weekUse(vp)[4], V_weekUse(vp)[5],
857 V_weekUse(vp)[6], date(V_dayUseDate(vp)));
858 printf("volUpdateCounter = %u\n", V_volUpCounter(vp));
862 * Get the size and times of a file
864 * @param[in] fd file descriptor of file to stat
865 * @param[out] size size of the file
866 * @param[out] ctime ctime of file as a formatted string
867 * @param[out] mtime mtime of file as a formatted string
868 * @param[out] atime atime of file as a formatted string
872 * @retval -1 failed to retrieve file information
875 GetFileInfo(FD_t fd, afs_sfsize_t * size, char **ctime, char **mtime,
879 BY_HANDLE_FILE_INFORMATION fi;
881 if (!GetFileInformationByHandle(fd, &fi)) {
882 fprintf(stderr, "%s: GetFileInformationByHandle failed\n", progname);
885 if (!GetFileSizeEx(fd, &fsize)) {
886 fprintf(stderr, "%s: GetFileSizeEx failed\n", progname);
889 *size = fsize.QuadPart;
891 *mtime = NT_date(&fi.ftLastWriteTime);
892 *atime = NT_date(&fi.ftLastAccessTime);
894 struct afs_stat_st status;
895 if (afs_fstat(fd, &status) == -1) {
896 fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
899 *size = status.st_size;
900 *ctime = date(status.st_ctime);
901 *mtime = date(status.st_mtime);
902 *atime = date(status.st_atime);
908 * Copy the inode data to a file in the current directory.
910 * @param[in] vp volume object
911 * @param[in] vnode vnode object
912 * @param[in] inode inode of the source file
917 SaveInode(Volume * vp, struct VnodeDiskObject *vnode, Inode ino)
921 char nfile[50], buffer[256];
926 if (!VALID_INO(ino)) {
930 IH_INIT(ih, V_device(vp), V_parentId(vp), ino);
934 "%s: Can't open inode %s error %d (ignored)\n",
935 progname, PrintInode(NULL, ino), errno);
938 snprintf(nfile, sizeof nfile, "TmpInode.%s", PrintInode(NULL, ino));
939 ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
942 "%s: Can't create file %s; error %d (ignored)\n",
943 progname, nfile, errno);
945 FDH_REALLYCLOSE(fdP);
952 len = FDH_PREAD(fdP, buffer, sizeof(buffer), total);
954 FDH_REALLYCLOSE(fdP);
959 "%s: Error while reading from inode %s (%d)\n",
960 progname, PrintInode(NULL, ino), errno);
964 break; /* No more input */
965 nBytes = write(ofd, buffer, len);
967 FDH_REALLYCLOSE(fdP);
972 "%s: Error while writing to \"%s\" (%d - ignored)\n",
973 progname, nfile, errno);
979 FDH_REALLYCLOSE(fdP);
982 printf("... Copied inode %s to file %s (%lu bytes)\n",
983 PrintInode(NULL, ino), nfile, (unsigned long)total);
987 * Scan a volume index and handle each vnode
989 * @param[in] vp volume object
990 * @param[in] class which index to scan
995 HandleVnodes(Volume * vp, VnodeClass class)
998 (class == vSmall ? SIZEOF_SMALLDISKVNODE : SIZEOF_LARGEDISKVNODE);
999 char buf[SIZEOF_LARGEDISKVNODE];
1000 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
1001 StreamHandle_t *file = NULL;
1003 afs_sfsize_t nVnodes;
1004 afs_foff_t offset = 0;
1006 IHandle_t *ih = vp->vnodeIndex[class].handle;
1007 FdHandle_t *fdP = NULL;
1009 char *ctime, *atime, *mtime;
1011 /* print vnode table heading */
1012 if (class == vLarge) {
1014 printf("\nLarge vnodes (directories)\n");
1018 printf("\nSmall vnodes(files, symbolic links)\n");
1022 printf("Saving all volume files to current directory ...\n");
1024 PrintingVolumeSizes = 0; /* print heading again */
1031 fprintf(stderr, "%s: open failed: ", progname);
1035 file = FDH_FDOPEN(fdP, "r");
1037 fprintf(stderr, "%s: fdopen failed\n", progname);
1041 if (GetFileInfo(fdP->fd_fd, &size, &ctime, &atime, &mtime) != 0) {
1045 printf("ichanged : %s\nimodified: %s\niaccessed: %s\n\n", ctime,
1049 nVnodes = (size / diskSize) - 1;
1051 STREAM_ASEEK(file, diskSize);
1055 for (vnodeIndex = 0;
1056 nVnodes && STREAM_READ(vnode, diskSize, 1, file) == 1;
1057 nVnodes--, vnodeIndex++, offset += diskSize) {
1059 ino = VNDISK_GET_INO(vnode);
1061 afs_fsize_t fileLength;
1063 VNDISK_GET_LEN(fileLength, vnode);
1064 if (fileLength > 0) {
1065 volumeTotals.vnodesize += fileLength;
1066 volumeTotals.vnodesize_k += fileLength / 1024;
1069 if (SaveInodes && (class == vSmall)) {
1070 SaveInode(vp, vnode, ino);
1072 if (DumpVnodes || ShowOrphaned) {
1073 PrintVnode(offset, vnode,
1074 bitNumberToVnodeNumber(vnodeIndex, class), ino, vp);
1088 * Print vnode information
1090 * @param[in] offset index offset of this vnode
1091 * @param[in] vnode vnode object to be printed
1092 * @param[in] vnodeNumber vnode number
1093 * @param[in] ino fileserver inode number
1094 * @param[in] vp parent volume of the vnode
1099 PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
1100 Inode ino, Volume * vp)
1102 #if defined(AFS_NAMEI_ENV)
1106 afs_fsize_t fileLength;
1108 VNDISK_GET_LEN(fileLength, vnode);
1110 /* The check for orphaned vnodes is currently limited to non-empty
1111 * vnodes with a parent of zero (and which are not the first entry
1113 if (ShowOrphaned && (fileLength == 0 || vnode->parent || !offset))
1117 ("%10lld Vnode %u.%u.%u cloned: %u, length: %llu linkCount: %d parent: %u",
1118 (long long)offset, vnodeNumber, vnode->uniquifier, vnode->dataVersion,
1119 vnode->cloned, (afs_uintmax_t) fileLength, vnode->linkCount,
1121 if (DumpInodeNumber)
1122 printf(" inode: %s", PrintInode(NULL, ino));
1124 printf(" ServerModTime: %s", date(vnode->serverModifyTime));
1125 #if defined(AFS_NAMEI_ENV)
1126 if (PrintFileNames) {
1127 IH_INIT(ihtmpp, V_device(vp), V_parentId(vp), ino);
1128 namei_HandleToName(&filename, ihtmpp);
1129 #if !defined(AFS_NT40_ENV)
1130 printf(" UFS-Filename: %s", filename.n_path);
1132 printf(" NTFS-Filename: %s", filename.n_path);