char pname[10];
afs_int32 idx, j;
+ if (as->parms[1].items && !as->parms[0].items) {
+ fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
+ return EINVAL;
+ }
+
if (as->parms[0].items) {
server = GetServer(as->parms[0].items->data);
if (!server) {
afs_uint32 tserver;
tserver = 0;
+
+ if (as->parms[1].items && !as->parms[0].items) {
+ fprintf(STDERR, "vos: The -partition option requires the -server option.\n");
+ exit(1);
+ }
+
if (as->parms[0].items) {
tserver = GetServer(as->parms[0].items->data);
if (!tserver) {
exit(1);
}
flags = 1;
-
- if (!tserver) {
- fprintf(STDERR,
- "The -partition option requires a -server option\n");
- exit(1);
- }
}
if (as->parms[3].items) {
}
if (pntr->iflags) {
fprintf(STDOUT, "attachFlags: ");
- switch (pntr->iflags) {
- case ITOffline:
+ if ((pntr->iflags & ITOffline) != 0) {
fprintf(STDOUT, "offline ");
- break;
- case ITBusy:
+ }
+ if ((pntr->iflags & ITBusy) != 0) {
fprintf(STDOUT, "busy ");
- break;
- case ITReadOnly:
+ }
+ if ((pntr->iflags & ITReadOnly) != 0) {
fprintf(STDOUT, "readonly ");
- break;
- case ITCreate:
+ }
+ if ((pntr->iflags & ITCreate) != 0) {
fprintf(STDOUT, "create ");
- break;
- case ITCreateVolID:
+ }
+ if ((pntr->iflags & ITCreateVolID) != 0) {
fprintf(STDOUT, "create volid ");
- break;
}
fprintf(STDOUT, "\n");
}
if (pntr->vflags) {
fprintf(STDOUT, "volumeStatus: ");
- switch (pntr->vflags) {
- case VTDeleteOnSalvage:
+ if ((pntr->vflags & VTDeleteOnSalvage) != 0) {
fprintf(STDOUT, "deleteOnSalvage ");
- case VTOutOfService:
+ }
+ if ((pntr->vflags & VTOutOfService) != 0) {
fprintf(STDOUT, "outOfService ");
- case VTDeleted:
+ }
+ if ((pntr->vflags & VTDeleted) != 0) {
fprintf(STDOUT, "deleted ");
}
fprintf(STDOUT, "\n");
static int
RenameVolume(struct cmd_syndesc *as, void *arock)
{
- afs_int32 code1, code2, code;
+ afs_int32 code;
struct nvldbentry entry;
+ struct nvldbentry entry2;
- code1 = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
- if (code1) {
+ /* Get the entry of the volume to be renamed (-oldname), by name or id. */
+ code = VLDB_GetEntryByName(as->parms[0].items->data, &entry);
+ if (code) {
fprintf(STDERR, "vos: Could not find entry for volume %s\n",
as->parms[0].items->data);
+ PrintError("", code);
exit(1);
}
- code2 = VLDB_GetEntryByName(as->parms[1].items->data, &entry);
- if ((!code1) && (!code2)) { /*the newname already exists */
- fprintf(STDERR, "vos: volume %s already exists\n",
+
+ /*
+ * Verify the new name is available before attempting to rename.
+ * Allow renaming of the same volume in order to complete a
+ * previously interrupted rename.
+ */
+ code = VLDB_GetEntryByName(as->parms[1].items->data, &entry2);
+ if (code != 0 && code != VL_NOENT) {
+ fprintf(STDERR, "vos: Could not check entry for volume %s\n",
as->parms[1].items->data);
+ PrintError("", code);
exit(1);
}
-
- if (code1 && code2) {
- fprintf(STDERR, "vos: Could not find entry for volume %s or %s\n",
- as->parms[0].items->data, as->parms[1].items->data);
+ if (code == 0 && entry.volumeId[RWVOL] != entry2.volumeId[RWVOL]) {
+ fprintf(STDERR, "vos: Cannot rename volume %s (%lu) to %s;"
+ " volume %s (%lu) already exists\n",
+ as->parms[0].items->data,
+ (unsigned long)entry.volumeId[RWVOL],
+ as->parms[1].items->data,
+ as->parms[1].items->data,
+ (unsigned long)entry2.volumeId[RWVOL]);
exit(1);
}
if (!VolNameOK(as->parms[0].items->data)) {
as->parms[1].items->data);
exit(1);
}
- if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
- if (code)
- PrintError("", code);
- else
- fprintf(STDERR,
- "vos : partition %s does not exist on the server\n",
- as->parms[1].items->data);
- exit(1);
+ if (aserver) {
+ /* Check for validity of the partition if a server was given. */
+ if (!IsPartValid(apart, aserver, &code)) {
+ if (code)
+ PrintError("", code);
+ else
+ fprintf(STDERR,
+ "vos : partition %s does not exist on the server\n",
+ as->parms[1].items->data);
+ exit(1);
+ }
}
attributes.partition = apart;
attributes.Mask |= VLLIST_PARTITION;