static const char *progname = "volinfo";
+/* Command line options */
+typedef enum {
+ P_ONLINE,
+ P_VNODE,
+ P_DATE,
+ P_INODE,
+ P_ITIME,
+ P_PART,
+ P_VOLUMEID,
+ P_HEADER,
+ P_SIZEONLY,
+ P_FIXHEADER,
+ P_SAVEINODES,
+ P_ORPHANED,
+ P_FILENAMES
+} volinfo_parm_t;
+
/* Modes */
static int DumpInfo = 1; /**< Dump volume information, defualt mode*/
static int DumpHeader = 0; /**< Dump volume header files info */
Inode ino, Volume * vp);
void HandleVnodes(Volume * vp, VnodeClass class);
+/**
+ * Format time as a timestamp string
+ *
+ * @param[in] date time value to format
+ *
+ * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
+ *
+ * @note A static array of 8 strings are stored by this
+ * function. The array slots are overwritten, so the
+ * caller must not reference the returned string after
+ * seven additional calls to this function.
+ */
char *
date(time_t date)
{
return results[next];
}
+#ifdef AFS_NT40_ENV
+/**
+ * Format file time as a timestamp string
+ *
+ * @param[in] ft file time
+ *
+ * @return timestamp string in the form YYYY/MM/DD.hh:mm:ss
+ *
+ * @note A static array of 8 strings are stored by this
+ * function. The array slots are overwritten, so the
+ * caller must not reference the returned string after
+ * seven additional calls to this function.
+ */
+char *
+NT_date(FILETIME * ft)
+{
+ static char result[8][64];
+ static int next = 0;
+ SYSTEMTIME st;
+ FILETIME lft;
+
+ if (!FileTimeToLocalFileTime(ft, &lft)
+ || !FileTimeToSystemTime(&lft, &st)) {
+ fprintf(stderr, "%s: Time conversion failed.\n", progname);
+ exit(1);
+ }
+ sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
+ st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
+ return result[next];
+}
+#endif
+
/**
* Print the volume size table heading line, if needed.
*
serverTotals.vnodesize, serverTotals.size_k, diff_k);
}
+/**
+ * Read a volume header file
+ *
+ * @param[in] ih ihandle of the header file
+ * @param[in] to destination
+ * @param[in] size expected header size
+ * @param[in] magic expected header magic number
+ * @param[in] version expected header version number
+ *
+ * @return error code
+ * @retval 0 success
+ * @retval -1 failed to read file
+ */
int
ReadHdr1(IHandle_t * ih, char *to, int size, u_int magic, u_int version)
{
return 0;
}
-
+/**
+ * Simplified attach volume
+ *
+ * param[in] dp vice disk partition object
+ * param[in] volname volume header file name
+ * param[in] header volume header object
+ *
+ * @return volume object or null on error
+ */
Volume *
AttachVolume(struct DiskPartition64 * dp, char *volname,
struct VolumeHeader * header)
return vp;
}
+/**
+ * Convert the partition device number into a partition name.
+ *
+ * @param[in] partId partition number, 0 to 254
+ * @param[out] partName buffer to hold partition name (e.g. /vicepa)
+ * @param[in] partNameSize size of partName buffer
+ *
+ * @return status
+ * @retval 0 success
+ * @retval -1 error, partId is out of range
+ * @retval -2 error, partition name exceeds partNameSize
+ */
+static int
+GetPartitionName(afs_uint32 partId, char *partName, afs_size_t partNameSize)
+{
+ const int OLD_NUM_DEVICES = 26; /* a..z */
+ if (partId < OLD_NUM_DEVICES) {
+ if (partNameSize < 8) {
+ return -2;
+ }
+ strlcpy(partName, "/vicep", partNameSize);
+ partName[6] = partId + 'a';
+ partName[7] = '\0';
+ return 0;
+ }
+ if (partId < VOLMAXPARTS) {
+ if (partNameSize < 9) {
+ return -2;
+ }
+ strlcpy(partName, "/vicep", partNameSize);
+ partId -= OLD_NUM_DEVICES;
+ partName[6] = 'a' + (partId / OLD_NUM_DEVICES);
+ partName[7] = 'a' + (partId % OLD_NUM_DEVICES);
+ partName[8] = '\0';
+ return 0;
+ }
+ return -1;
+}
+
+/**
+ * Process command line options and start scanning
+ *
+ * @param[in] as command syntax object
+ * @param[in] arock opaque object; not used
+ *
+ * @return error code
+ */
static int
handleit(struct cmd_syndesc *as, void *arock)
{
struct cmd_item *ti;
int err = 0;
afs_uint32 volumeId = 0;
- char *partName = 0;
+ char *partNameOrId = 0;
+ char partName[64] = "";
struct DiskPartition64 *partP = NULL;
}
#endif
- if (as->parms[0].items) { /* -online */
+ if (as->parms[P_ONLINE].items) {
fprintf(stderr, "%s: -online not supported\n", progname);
return 1;
}
- if (as->parms[1].items) { /* -vnode */
+ if (as->parms[P_VNODE].items) {
DumpVnodes = 1;
}
- if (as->parms[2].items) { /* -date */
+ if (as->parms[P_DATE].items) {
DumpDate = 1;
}
- if (as->parms[3].items) { /* -inode */
+ if (as->parms[P_INODE].items) {
DumpInodeNumber = 1;
}
- if (as->parms[4].items) { /* -itime */
+ if (as->parms[P_ITIME].items) {
InodeTimes = 1;
}
- if ((ti = as->parms[5].items)) { /* -part */
- partName = ti->data;
+ if ((ti = as->parms[P_PART].items)) {
+ partNameOrId = ti->data;
}
- if ((ti = as->parms[6].items)) { /* -volumeid */
+ if ((ti = as->parms[P_VOLUMEID].items)) {
volumeId = strtoul(ti->data, NULL, 10);
}
- if (as->parms[7].items) { /* -header */
+ if (as->parms[P_HEADER].items) {
DumpHeader = 1;
}
- if (as->parms[8].items) { /* -sizeOnly */
+ if (as->parms[P_SIZEONLY].items) {
ShowSizes = 1;
}
- if (as->parms[9].items) { /* -FixHeader */
+ if (as->parms[P_FIXHEADER].items) {
FixHeader = 1;
}
- if (as->parms[10].items) { /* -saveinodes */
+ if (as->parms[P_SAVEINODES].items) {
SaveInodes = 1;
}
- if (as->parms[11].items) { /* -orphaned */
+ if (as->parms[P_ORPHANED].items) {
ShowOrphaned = 1;
}
#if defined(AFS_NAMEI_ENV)
- if (as->parms[12].items) { /* -filenames */
+ if (as->parms[P_FILENAMES].items) {
PrintFileNames = 1;
}
#endif
DumpVnodes = 1; /* implied */
}
+ /* Allow user to specify partition by name or id. */
+ if (partNameOrId) {
+ afs_uint32 partId = volutil_GetPartitionID(partNameOrId);
+ if (partId == -1) {
+ fprintf(stderr, "%s: Could not parse '%s' as a partition name.\n",
+ progname, partNameOrId);
+ return 1;
+ }
+ if (GetPartitionName(partId, partName, sizeof(partName))) {
+ fprintf(stderr,
+ "%s: Could not format '%s' as a partition name.\n",
+ progname, partNameOrId);
+ return 1;
+ }
+ }
+
DInit(10);
err = VAttachPartitions();
progname, err);
}
- if (partName) {
+ if (partName[0]) {
partP = VGetPartition(partName, 0);
if (!partP) {
fprintf(stderr,
return 0;
}
+/**
+ * Determine if the current directory is a vice partition
+ *
+ * @return disk partition object
+ */
#ifdef AFS_NT40_ENV
#include <direct.h>
struct DiskPartition64 *
}
#endif
+/**
+ * Scan and handle all the partitions detected on this server
+ *
+ * @return none
+ */
void
HandleAllPart(void)
{
}
}
-
+/**
+ * Scan the partition and handle volumes
+ *
+ * @param[in] partP disk partition to scan
+ *
+ * @return none
+ */
void
HandlePart(struct DiskPartition64 *partP)
{
}
}
+/**
+ * Attach and scan the volume and handle the header and vnodes
+ *
+ * Print the volume header and vnode information, depending on the
+ * current modes.
+ *
+ * @param[in] dp vice partition object for this volume
+ * @param[in] name volume header file name
+ *
+ * @return none
+ */
void
HandleVolume(struct DiskPartition64 *dp, char *name)
{
free(vp);
}
+
+/**
+ * volinfo program entry
+ */
int
main(int argc, char **argv)
{
struct cmd_syndesc *ts;
afs_int32 code;
- ts = cmd_CreateSyntax(NULL, handleit, NULL, "Dump volume's internal state");
- cmd_AddParm(ts, "-online", CMD_FLAG, CMD_OPTIONAL,
- "Get info from running fileserver");
- cmd_AddParm(ts, "-vnode", CMD_FLAG, CMD_OPTIONAL, "Dump vnode info");
- cmd_AddParm(ts, "-date", CMD_FLAG, CMD_OPTIONAL,
- "Also dump vnode's mod date");
- cmd_AddParm(ts, "-inode", CMD_FLAG, CMD_OPTIONAL,
- "Also dump vnode's inode number");
- cmd_AddParm(ts, "-itime", CMD_FLAG, CMD_OPTIONAL,
- "Dump special inode's mod times");
- cmd_AddParm(ts, "-part", CMD_LIST, CMD_OPTIONAL,
- "AFS partition name (default current partition)");
- cmd_AddParm(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id");
- cmd_AddParm(ts, "-header", CMD_FLAG, CMD_OPTIONAL,
- "Dump volume's header info");
- cmd_AddParm(ts, "-sizeOnly", CMD_FLAG, CMD_OPTIONAL,
- "Dump volume's size");
- cmd_AddParm(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL,
- "Try to fix header");
- cmd_AddParm(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL,
- "Try to save all inodes");
- cmd_AddParm(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
- "List all dir/files without a parent");
+ ts = cmd_CreateSyntax(NULL, handleit, NULL,
+ "Dump volume's internal state");
+ cmd_AddParmAtOffset(ts, "-online", CMD_FLAG, CMD_OPTIONAL,
+ "Get info from running fileserver", P_ONLINE);
+ cmd_AddParmAtOffset(ts, "-vnode", CMD_FLAG, CMD_OPTIONAL,
+ "Dump vnode info", P_VNODE);
+ cmd_AddParmAtOffset(ts, "-date", CMD_FLAG, CMD_OPTIONAL,
+ "Also dump vnode's mod date", P_DATE);
+ cmd_AddParmAtOffset(ts, "-inode", CMD_FLAG, CMD_OPTIONAL,
+ "Also dump vnode's inode number", P_INODE);
+ cmd_AddParmAtOffset(ts, "-itime", CMD_FLAG, CMD_OPTIONAL,
+ "Dump special inode's mod times", P_ITIME);
+ cmd_AddParmAtOffset(ts, "-part", CMD_LIST, CMD_OPTIONAL,
+ "AFS partition name or id (default current partition)",
+ P_PART);
+ cmd_AddParmAtOffset(ts, "-volumeid", CMD_LIST, CMD_OPTIONAL, "Volume id",
+ P_VOLUMEID);
+ cmd_AddParmAtOffset(ts, "-header", CMD_FLAG, CMD_OPTIONAL,
+ "Dump volume's header info", P_HEADER);
+ cmd_AddParmAtOffset(ts, "-sizeonly", CMD_FLAG, CMD_OPTIONAL,
+ "Dump volume's size", P_SIZEONLY);
+ cmd_AddParmAtOffset(ts, "-fixheader", CMD_FLAG, CMD_OPTIONAL,
+ "Try to fix header", P_FIXHEADER);
+ cmd_AddParmAtOffset(ts, "-saveinodes", CMD_FLAG, CMD_OPTIONAL,
+ "Try to save all inodes", P_SAVEINODES);
+ cmd_AddParmAtOffset(ts, "-orphaned", CMD_FLAG, CMD_OPTIONAL,
+ "List all dir/files without a parent", P_ORPHANED);
#if defined(AFS_NAMEI_ENV)
- cmd_AddParm(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL, "Also dump vnode's namei filename");
+ cmd_AddParmAtOffset(ts, "-filenames", CMD_FLAG, CMD_OPTIONAL,
+ "Also dump vnode's namei filename", P_FILENAMES);
#endif
+
+ /* For compatibility with older versions. */
+ cmd_AddParmAlias(ts, P_SIZEONLY, "-sizeOnly");
+
code = cmd_Dispatch(argc, argv);
return code;
}
#define typestring(type) (type == RWVOL? "read/write": type == ROVOL? "readonly": type == BACKVOL? "backup": "unknown")
+/**
+ * Print the volume header information
+ *
+ * @param[in] volume object
+ *
+ * @return none
+ */
void
PrintHeader(Volume * vp)
{
printf("volUpdateCounter = %u\n", V_volUpCounter(vp));
}
-/* GetFileInfo
- * OS independent file info. Die on failure.
+/**
+ * Get the size and times of a file
+ *
+ * @param[in] fd file descriptor of file to stat
+ * @param[out] size size of the file
+ * @param[out] ctime ctime of file as a formatted string
+ * @param[out] mtime mtime of file as a formatted string
+ * @param[out] atime atime of file as a formatted string
+ *
+ * @return error code
+ * @retval 0 success
+ * @retval -1 failed to retrieve file information
*/
-#ifdef AFS_NT40_ENV
-char *
-NT_date(FILETIME * ft)
-{
- static char result[8][64];
- static int next = 0;
- SYSTEMTIME st;
- FILETIME lft;
-
- if (!FileTimeToLocalFileTime(ft, &lft)
- || !FileTimeToSystemTime(&lft, &st)) {
- fprintf(stderr, "%s: Time conversion failed.\n", progname);
- exit(1);
- }
- sprintf(result[next = ((next + 1) & 7)], "%4d/%02d/%02d.%2d:%2d:%2d",
- st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
- return result[next];
-}
-#endif
-
static int
GetFileInfo(FD_t fd, afs_sfsize_t * size, char **ctime, char **mtime,
char **atime)
* @param[in] vnode vnode object
* @param[in] inode inode of the source file
*
- * @returns none
+ * @return none
*/
static void
SaveInode(Volume * vp, struct VnodeDiskObject *vnode, Inode ino)
PrintInode(NULL, ino), nfile, (unsigned long)total);
}
+/**
+ * Scan a volume index and handle each vnode
+ *
+ * @param[in] vp volume object
+ * @param[in] class which index to scan
+ *
+ * @return none
+ */
void
HandleVnodes(Volume * vp, VnodeClass class)
{
}
}
+/**
+ * Print vnode information
+ *
+ * @param[in] offset index offset of this vnode
+ * @param[in] vnode vnode object to be printed
+ * @param[in] vnodeNumber vnode number
+ * @param[in] ino fileserver inode number
+ * @param[in] vp parent volume of the vnode
+ *
+ * @return none
+ */
void
PrintVnode(afs_foff_t offset, VnodeDiskObject * vnode, VnodeId vnodeNumber,
Inode ino, Volume * vp)