// Unofficial helper for renaming APA partitions. static int apaRename(s32 device, const apa_params_t *oldParams, const apa_params_t *newParams) { apa_cache_t *clink; int i, rv; // look to see if can make(newname) or not... if((clink = apaFindPartition(device, newParams->id, &rv)) != NULL) { apaCacheFree(clink); SignalSema(fioSema); return -EEXIST; // File exists } // 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) { SignalSema(fioSema); return -EBUSY; } } } // Do not allow system partitions (__*) to be renamed. if(oldParams->id[0]=='_' && oldParams->id[1]=='_') return -EACCES; // find :) if((clink = apaFindPartition(device, oldParams->id, &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); // Update passwords memcpy(clink->header->rpwd, newParams->rpwd, APA_PASSMAX); memcpy(clink->header->fpwd, newParams->fpwd, APA_PASSMAX); clink->flags|=APA_CACHE_FLAG_DIRTY; apaCacheFlushAllDirty(device); apaCacheFree(clink); return 0; }
int hddReName(iop_file_t *f, const char *oldname, const char *newname) { int rv; int i; apa_cache *clink; char tmpBuf[APA_IDMAX]; if(f->unit >= 2 || hddDeviceBuf[f->unit].status!=0) return -ENODEV;// No such device WaitSema(fioSema); // look to see if can make(newname) or not... memset(tmpBuf, 0, APA_IDMAX); strncpy(tmpBuf, newname, APA_IDMAX - 1); tmpBuf[APA_IDMAX - 1] = '\0'; if((clink=apaFindPartition(f->unit, tmpBuf, &rv))){ cacheAdd(clink); SignalSema(fioSema); return -EEXIST; // File exists } // look to see if open(oldname) memset(tmpBuf, 0, APA_IDMAX); strncpy(tmpBuf, oldname, APA_IDMAX - 1); tmpBuf[APA_IDMAX - 1] = '\0'; for(i=0;i<maxOpen;i++) { if(fileSlots[i].f!=0) if(fileSlots[i].f->unit==f->unit) if(memcmp(fileSlots[i].id, oldname, APA_IDMAX)==0) { SignalSema(fioSema); return -EBUSY; } } // find :) if(!(clink=apaFindPartition(f->unit, tmpBuf, &rv))) { SignalSema(fioSema); return -ENOENT; } // do the renameing :) note: subs have no names!! memset(clink->header->id, 0, APA_IDMAX); // all cmp are done with memcmp! strncpy(clink->header->id, newname, APA_IDMAX - 1); clink->header->id[APA_IDMAX - 1] = '\0'; clink->flags|=CACHE_FLAG_DIRTY; cacheFlushAllDirty(f->unit); cacheAdd(clink); SignalSema(fioSema); return 0; }
static int devctlSwapTemp(s32 device, char *argp) { int rv; apa_params_t params; char szBuf[APA_IDMAX]; apa_cache_t *partTemp; apa_cache_t *partNew; if((rv=fioGetInput(argp, ¶ms)) < 0) return rv; if(params.id[0] == '_' && params.id[1] == '_')// test for '__' system partition return -EINVAL; memset(szBuf, 0, APA_IDMAX); strcpy(szBuf, "_tmp"); if(!(partTemp=apaFindPartition(device, szBuf, &rv))) return rv; if((partNew=apaFindPartition(device, params.id, &rv))) { if((rv=apaPassCmp(partNew->header->fpwd, params.fpwd))==0) { memcpy(partTemp->header->id, partNew->header->id, APA_IDMAX); memcpy(partTemp->header->rpwd, partNew->header->rpwd, APA_PASSMAX); memcpy(partTemp->header->fpwd, partNew->header->fpwd, APA_PASSMAX); //memset(partNew->header->id, 0, 8);// BUG! can make it so can not open!! memset(partNew->header->id, 0, APA_IDMAX); strcpy(partNew->header->id, "_tmp"); memset(partNew->header->rpwd, 0, APA_PASSMAX); memset(partNew->header->fpwd, 0, APA_PASSMAX); partTemp->flags|=APA_CACHE_FLAG_DIRTY; partNew->flags|=APA_CACHE_FLAG_DIRTY; apaCacheFlushAllDirty(device); } apaCacheFree(partNew); } apaCacheFree(partTemp); return rv; }
int devctlSwapTemp(u32 device, char *argp) { int rv; input_param params; char szBuf[APA_IDMAX]; apa_cache *partTemp; apa_cache *partNew; if((rv=fioGetInput(argp, ¶ms)) < 0) return rv; if(*(u16 *)(params.id)==(u16)0x5F5F)// test for '__' system partition return -EINVAL; memset(szBuf, 0, APA_IDMAX); strcpy(szBuf, "_tmp"); if(!(partTemp=apaFindPartition(device, szBuf, &rv))) return rv; if((partNew=apaFindPartition(device, params.id, &rv))) { if((rv=passcmp(partNew->header->fpwd, NULL))==0) { memcpy(partTemp->header->id, partNew->header->id, APA_IDMAX); memcpy(partTemp->header->rpwd, partNew->header->rpwd, APA_PASSMAX); memcpy(partTemp->header->fpwd, partNew->header->fpwd, APA_PASSMAX); //memset(partNew->header->id, 0, 8);// BUG! can make it so can not open!! memset(partNew->header->id, 0, APA_IDMAX); strcpy(partNew->header->id, "_tmp"); memset(partNew->header->rpwd, 0, APA_PASSMAX); memset(partNew->header->fpwd, 0, APA_PASSMAX); partTemp->flags|=CACHE_FLAG_DIRTY; partNew->flags|=CACHE_FLAG_DIRTY; cacheFlushAllDirty(device); } cacheAdd(partNew); } cacheAdd(partTemp); return rv; }
int hddGetStat(iop_file_t *f, const char *name, iox_stat_t *stat) { apa_cache_t *clink; apa_params_t params; int rv; if((rv=fioGetInput(name, ¶ms))<0) return rv; WaitSema(fioSema); if((clink=apaFindPartition(f->unit, params.id, &rv))){ if((rv=apaPassCmp(clink->header->fpwd, params.fpwd))==0 || (rv=apaPassCmp(clink->header->rpwd, params.rpwd))==0) fioGetStatFiller(clink, stat); apaCacheFree(clink); } SignalSema(fioSema); return rv; }
int hddGetStat(iop_file_t *f, const char *name, iox_stat_t *stat) { apa_cache *clink; input_param params; int rv; if((rv=fioGetInput(name, ¶ms))<0) return rv; WaitSema(fioSema); if((clink=apaFindPartition(f->unit, params.id, &rv))){ if((rv=passcmp(clink->header->rpwd, NULL))==0) fioGetStatFiller(clink, stat); cacheAdd(clink); } SignalSema(fioSema); return rv; }
int apaRemove(u32 device, char *id) { int i; u32 nsub; apa_cache *clink; apa_cache *clink2; int rv; for(i=0;i<maxOpen;i++) // look to see if open { if(fileSlots[i].f!=0) { if(memcmp(fileSlots[i].id, id, APA_IDMAX)==0) return -EBUSY; } } if(id[0]=='_' && id[1]=='_') return -EACCES; if((clink=apaFindPartition(device, id, &rv))==NULL) return rv; if(passcmp(clink->header->fpwd, NULL)) { cacheAdd(clink); return -EACCES; } // remove all subs frist... nsub=clink->header->nsub; clink->header->nsub=0; clink->flags|=CACHE_FLAG_DIRTY; cacheFlushAllDirty(device); for(i=nsub-1;i!=-1;i--) { if((clink2=cacheGetHeader(device, clink->header->subs[i].start, 0, &rv))){ if((rv=apaDelete(clink2))){ cacheAdd(clink); return rv; } } } if(rv==0) return apaDelete(clink); cacheAdd(clink); return rv; }
static int apaRemove(s32 device, const char *id, const char *fpwd) { u32 nsub; apa_cache_t *clink; apa_cache_t *clink2; int rv, i; for(i=0;i<apaMaxOpen;i++) // look to see if open { if(hddFileSlots[i].f!=0) { if(memcmp(hddFileSlots[i].id, id, APA_IDMAX)==0) return -EBUSY; } } if(id[0]=='_' && id[1]=='_') return -EACCES; if((clink=apaFindPartition(device, id, &rv))==NULL) return rv; if(apaPassCmp(clink->header->fpwd, fpwd)) { apaCacheFree(clink); return -EACCES; } // remove all subs frist... nsub=clink->header->nsub; clink->header->nsub=0; clink->flags|=APA_CACHE_FLAG_DIRTY; apaCacheFlushAllDirty(device); for(i=nsub-1;i!=-1;i--) { if((clink2=apaCacheGetHeader(device, clink->header->subs[i].start, APA_IO_MODE_READ, &rv))){ if((rv=apaDelete(clink2))){ apaCacheFree(clink); return rv; } } } if(rv==0) return apaDelete(clink); apaCacheFree(clink); return rv; }