#include <afs/afssyscalls.h>
#include <afs/afsutil.h>
+static const char *progname = "volinfo";
+
int DumpVnodes = 0; /* Dump everything, i.e. summary of all vnodes */
int DumpInodeNumber = 0; /* Dump inode numbers with vnodes */
int DumpDate = 0; /* Dump vnode date (server modify date) with vnode */
if (vsn->magic != magic) {
bad++;
- printf("Inode %s: Bad magic %x (%x): IGNORED\n",
- PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
+ fprintf(stderr, "%s: Inode %s: Bad magic %x (%x): IGNORED\n",
+ progname, PrintInode(NULL, ih->ih_ino), vsn->magic, magic);
}
/* Check is conditional, in case caller wants to inspect version himself */
if (version && vsn->version != version) {
bad++;
- printf("Inode %s: Bad version %x (%x): IGNORED\n",
- PrintInode(NULL, ih->ih_ino), vsn->version, version);
+ fprintf(stderr, "%s: Inode %s: Bad version %x (%x): IGNORED\n",
+ progname,
+ PrintInode(NULL, ih->ih_ino), vsn->version, version);
}
if (bad && fixheader) {
vsn->magic = magic;
PrintInode(NULL, ih->ih_ino));
code = IH_IWRITE(ih, 0, to, size);
if (code != size) {
- printf("Write failed; header left in damaged state\n");
+ fprintf(stderr,
+ "%s: Write failed for inode %s; header left in damaged state\n",
+ progname, PrintInode(NULL, ih->ih_ino));
}
} else {
if (!dsizeOnly && !saveinodes) {
#ifndef AFS_NT40_ENV
if (geteuid() != 0) {
- printf("vol-info must be run as root; sorry\n");
+ fprintf(stderr, "%s: Must be run as root; sorry\n", progname);
exit(1);
}
#endif
err = VAttachPartitions();
if (err) {
- printf("%d partitions had errors during attach.\n", err);
+ fprintf(stderr, "%s: %d partitions had errors during attach.\n",
+ progname, err);
}
if (partName) {
partP = VGetPartition(partName, 0);
if (!partP) {
- printf("%s is not an AFS partition name on this server.\n",
- partName);
+ fprintf(stderr, "%s: %s is not an AFS partition name on this server.\n",
+ progname, partName);
exit(1);
}
}
if (!partP) {
partP = FindCurrentPartition();
if (!partP) {
- printf("Current partition is not a vice partition.\n");
+ fprintf(stderr,
+ "%s: Current partition is not a vice partition.\n",
+ progname);
exit(1);
}
}
break;
}
if (!dp) {
- printf("Current drive is not a valid vice partition.\n");
+ fprintf(stderr, "%s: Current drive is not a valid vice partition.\n",
+ progname);
}
return dp;
}
struct DiskPartition64 *dp;
if (!getcwd(partName, 1023)) {
+ fprintf(stderr, "%s: Failed to get current working directory: ",
+ progname);
perror("pwd");
exit(1);
}
if (!(dp = VGetPartition(partName, 0))) {
if (tmp)
*p = tmp;
- printf("%s is not a valid vice partition.\n", partName);
+ fprintf(stderr, "%s: %s is not a valid vice partition.\n", progname,
+ partName);
exit(1);
}
return dp;
#endif
if ((dirp = opendir(p)) == NULL) {
- printf("Can't read directory %s; giving up\n", p);
+ fprintf(stderr, "%s: Can't read directory %s; giving up\n", progname,
+ p);
exit(1);
}
if (dsizeOnly && !saveinodes)
char headerName[1024];
if (online) {
- printf("volinfo: -online not supported\n");
+ fprintf(stderr, "%s: -online not supported\n", progname);
exit(1);
} else {
afs_sfsize_t n;
VPartitionPath(dp), name);
if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD
|| OS_SIZE(fd) < 0) {
- printf("Volinfo: Cannot read volume header %s\n", name);
+ fprintf(stderr, "%s: Cannot read volume header %s\n", progname,
+ name);
OS_CLOSE(fd);
exit(1);
}
if (n != sizeof(diskHeader)
|| diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
- printf("Volinfo: Error reading volume header %s\n", name);
+ fprintf(stderr, "%s: Error reading volume header %s\n", progname,
+ name);
exit(1);
}
if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
- printf
- ("Volinfo: Volume %s, version number is incorrect; volume needs salvage\n",
- name);
+ fprintf(stderr,
+ "%s: Volume %s, version number is incorrect; volume needs salvage\n",
+ progname, name);
exit(1);
}
DiskToVolumeHeader(&header, &diskHeader);
IH_INIT(ih, dp->device, header.parent, header.volumeInfo);
fdP = IH_OPEN(ih);
if (fdP == NULL) {
- perror("opening volume info");
+ fprintf(stderr, "%s: Error opening volume info: ", progname);
+ perror("open");
exit(1);
}
code = FDH_SIZE(fdP);
if (code == -1) {
+ fprintf(stderr, "%s: Error getting size of volume info: ",
+ progname);
perror("fstat");
exit(1);
}
IH_INIT(ih, dp->device, header.parent, header.smallVnodeIndex);
fdP = IH_OPEN(ih);
if (fdP == NULL) {
- perror("opening small vnode index");
+ fprintf(stderr, "%s: Error opening small vnode index: ",
+ progname);
+ perror("open");
exit(1);
}
code = FDH_SIZE(fdP);
if (code == -1) {
+ fprintf(stderr,
+ "%s: Error getting size of small vnode index: ",
+ progname);
perror("fstat");
exit(1);
}
IH_INIT(ih, dp->device, header.parent, header.largeVnodeIndex);
fdP = IH_OPEN(ih);
if (fdP == NULL) {
- perror("opening large vnode index");
+ fprintf(stderr, "%s: Error opening large vnode index: ",
+ progname);
+ perror("open");
exit(1);
}
code = FDH_SIZE(fdP);
if (code == -1) {
+ fprintf(stderr,
+ "%s: Error getting size of large vnode index: ",
+ progname);
perror("fstat");
exit(1);
}
IH_INIT(ih, dp->device, header.parent, header.linkTable);
fdP = IH_OPEN(ih);
if (fdP == NULL) {
- perror("opening link table index");
+ fprintf(stderr, "%s: Error opening link table index: ",
+ progname);
+ perror("open");
exit(1);
}
code = FDH_SIZE(fdP);
if (code == -1) {
+ fprintf(stderr,
+ "%s: Error getting size of link table index: ",
+ progname);
perror("fstat");
exit(1);
}
OS_CLOSE(fd);
vp = AttachVolume(dp, name, &header);
if (!vp) {
- printf("Volinfo: Error attaching volume header %s\n", name);
+ fprintf(stderr, "%s: Error attaching volume header %s\n",
+ progname, name);
return;
}
}
if (!FileTimeToLocalFileTime(ft, &lft)
|| !FileTimeToSystemTime(&lft, &st)) {
- printf("Time conversion failed.\n");
+ fprintf(stderr, "%s: Time conversion failed.\n", progname);
exit(1);
}
sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
#ifdef AFS_NT40_ENV
BY_HANDLE_FILE_INFORMATION fi;
if (!GetFileInformationByHandle(fd, &fi)) {
- printf("GetFileInformationByHandle failed, exiting\n");
+ fprintf(stderr, "%s: GetFileInformationByHandle failed, exiting\n",
+ progname);
exit(1);
}
*size = (int)fi.nFileSizeLow;
#else
struct afs_stat_st status;
if (afs_fstat(fd, &status) == -1) {
- printf("fstat failed %d\n", errno);
+ fprintf(stderr, "%s: fstat failed %d\n", progname, errno);
exit(1);
}
*size = (int)status.st_size;
fdP = IH_OPEN(ih);
if (fdP == NULL) {
- printf("open failed\n");
+ fprintf(stderr, "%s: open failed: ", progname);
exit(1);
}
file = FDH_FDOPEN(fdP, "r");
if (!file) {
- printf("fdopen failed\n");
+ fprintf(stderr, "%s: fdopen failed\n", progname);
exit(1);
}
IH_INIT(ih1, V_device(vp), V_parentId(vp), ino);
fdP1 = IH_OPEN(ih1);
if (fdP1 == NULL) {
- printf("Can't open inode %s error %d (ignored)\n",
- PrintInode(NULL, ino), errno);
+ fprintf(stderr,
+ "%s: Can't open inode %s error %d (ignored)\n",
+ progname, PrintInode(NULL, ino), errno);
continue;
}
snprintf(nfile, sizeof nfile, "TmpInode.%s",
PrintInode(NULL, ino));
ofd = afs_open(nfile, O_CREAT | O_RDWR | O_TRUNC, 0600);
if (ofd < 0) {
- printf("Can't create file %s; error %d (ignored)\n",
- nfile, errno);
+ fprintf(stderr,
+ "%s: Can't create file %s; error %d (ignored)\n",
+ progname, nfile, errno);
continue;
}
total = bad = 0;
IH_RELEASE(ih1);
close(ofd);
unlink(nfile);
- printf
- ("Error while reading from inode %s (%d - ignored)\n",
- PrintInode(NULL, ino), errno);
+ fprintf(stderr,
+ "%s: Error while reading from inode %s (%d - ignored)\n",
+ progname, PrintInode(NULL, ino), errno);
bad = 1;
break;
}
IH_RELEASE(ih1);
close(ofd);
unlink(nfile);
- printf
- ("Error while writing to \"%s\" (%d - ignored)\n",
- nfile, errno);
+ fprintf(stderr,
+ "%s: Error while writing to \"%s\" (%d - ignored)\n",
+ progname, nfile, errno);
bad = 1;
break;
}