Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 13 additions & 27 deletions iop/hdd/apa/src/hdd_fio.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,13 @@ static int apaRemove(s32 device, const char *id, const char *fpwd)
}

// Unofficial helper for renaming APA partitions.
static int apaRename(s32 device, const apa_params_t *oldParams, const apa_params_t *newParams)
static int apaRename(s32 device, const char *oldId, const char *newId)
{
apa_cache_t *clink;
int i, rv;

// look to see if can make(newname) or not...
if ((clink = apaFindPartition(device, newParams->id, &rv)) != NULL) {
if ((clink = apaFindPartition(device, newId, &rv)) != NULL) {
apaCacheFree(clink);
SignalSema(fioSema);
return -EEXIST; // File exists
Expand All @@ -507,35 +507,31 @@ static int apaRename(s32 device, const apa_params_t *oldParams, const apa_params
// look to see if open(oldname)
for (i = 0; i < apaMaxOpen; i++) {
if (hddFileSlots[i].f != NULL) {
if (memcmp(hddFileSlots[i].id, oldParams->id, APA_IDMAX) == 0) {
if (memcmp(hddFileSlots[i].id, oldId, APA_IDMAX) == 0) {
SignalSema(fioSema);
return -EBUSY;
}
}
}

// Do not allow system partitions (__*) to be renamed.
if (oldParams->id[0] == '_' && oldParams->id[1] == '_')
#ifndef APA_ALLOW_REMOVE_PARTITION_WITH_LEADING_UNDERSCORE
if (oldId[0] == '_' && oldId[1] == '_')
return -EACCES;
#endif

// find :)
if ((clink = apaFindPartition(device, oldParams->id, &rv)) == NULL) {
if ((clink = apaFindPartition(device, oldId, &rv)) == NULL) {
SignalSema(fioSema);
return rv;
}

// Check for access rights.
if (apaPassCmp(clink->header->fpwd, oldParams->fpwd) != 0) {
apaCacheFree(clink);
return -EACCES;
}

// do the renaming :) note: subs have no names!!
memcpy(clink->header->id, newParams->id, APA_IDMAX);
memcpy(clink->header->id, newId, APA_IDMAX);

// Update passwords
memcpy(clink->header->rpwd, newParams->rpwd, APA_PASSMAX);
memcpy(clink->header->fpwd, newParams->fpwd, APA_PASSMAX);
// touch creation time
apaGetTime(&clink->header->created);
clink->header->checksum = apaCheckSum(clink->header, 1);

clink->flags |= APA_CACHE_FLAG_DIRTY;

Expand Down Expand Up @@ -761,23 +757,13 @@ int hddDread(iomanX_iop_file_t *f, iox_dirent_t *dirent)
}

/* Originally, SONY provided no function for renaming partitions.
Syntax: rename <Old ID>,<fpwd> <New ID>,<fpwd>

The full-access password (fpwd) is required.
System partitions (__*) cannot be renamed. */
Syntax: rename <Old ID> <New ID>*/
int hddReName(iomanX_iop_file_t *f, const char *oldname, const char *newname)
{
apa_params_t oldParams;
apa_params_t newParams;
int rv;

if ((rv = fioGetInput(oldname, &oldParams)) < 0)
return rv;
if ((rv = fioGetInput(newname, &newParams)) < 0)
return rv;

WaitSema(fioSema);
rv = apaRename(f->unit, &oldParams, &newParams);
rv = apaRename(f->unit, oldname, newname);
SignalSema(fioSema);

return rv;
Expand Down