int hddDevctl(iop_file_t *f, const char *devname, int cmd, void *arg, unsigned int arglen, void *bufp, unsigned int buflen) { int rv=0; WaitSema(fioSema); switch(cmd) { // Command set 1 ('H') case HDIOC_DEV9OFF: //Early versions called ata_device_smart_save_attr() here, when their old dev9 versions did not support the pre-shutdown callback. dev9Shutdown(); break; case HDIOC_IDLE: rv=ata_device_idle(f->unit, *(char *)arg); break; case HDIOC_MAXSECTOR: rv=hddDevices[f->unit].partitionMaxSize; break; case HDIOC_TOTALSECTOR: rv=hddDevices[f->unit].totalLBA; break; case HDIOC_FLUSH: if(ata_device_flush_cache(f->unit)) rv=-EIO; break; case HDIOC_SWAPTMP: rv=devctlSwapTemp(f->unit, (char *)arg); break; case HDIOC_SMARTSTAT: rv=ata_device_smart_get_status(f->unit); break; case HDIOC_STATUS: rv=hddDevices[f->unit].status; break; case HDIOC_FORMATVER: rv=hddDevices[f->unit].format; break; case HDIOC_FREESECTOR: rv=apaGetFreeSectors(f->unit, bufp, hddDevices); break; case HDIOC_IDLEIMM: rv=ata_device_idle_immediate(f->unit); break; // Command set 2 ('h') case HDIOC_GETTIME: rv=apaGetTime((apa_ps2time_t *)bufp); break; case HDIOC_SETOSDMBR: rv=devctlSetOsdMBR(f->unit, (hddSetOsdMBR_t *)arg); break; case HDIOC_GETSECTORERROR: rv=apaGetPartErrorSector(f->unit, APA_SECTOR_SECTOR_ERROR, 0); break; case HDIOC_GETERRORPARTNAME: rv=apaGetPartErrorName(f->unit, (char *)bufp); break; case HDIOC_READSECTOR: rv=ata_device_sector_io(f->unit, (void *)bufp, ((hddAtaTransfer_t *)arg)->lba, ((hddAtaTransfer_t *)arg)->size, ATA_DIR_READ); break; case HDIOC_WRITESECTOR: rv=ata_device_sector_io(f->unit, ((hddAtaTransfer_t *)arg)->data, ((hddAtaTransfer_t *)arg)->lba, ((hddAtaTransfer_t *)arg)->size, ATA_DIR_WRITE); break; case HDIOC_SCEIDENTIFY: rv=ata_device_sce_identify_drive(f->unit, (u16 *)bufp); break; default: rv=-EINVAL; break; } SignalSema(fioSema); return rv; }
int hddDevctl(iop_file_t *f, const char *devname, int cmd, void *arg, unsigned int arglen, void *bufp, unsigned int buflen) { int rv=0; WaitSema(fioSema); switch(cmd) { // cmd set 1 case APA_DEVCTL_DEV9_SHUTDOWN: atadUpdateAttrib(f->unit); dev9Shutdown(); break; case APA_DEVCTL_IDLE: rv=atadIdle(f->unit, *(char *)arg); break; case APA_DEVCTL_MAX_SECTORS: rv=hddDeviceBuf[f->unit].partitionMaxSize; break; case APA_DEVCTL_TOTAL_SECTORS: rv=hddDeviceBuf[f->unit].totalLBA; break; case APA_DEVCTL_FLUSH_CACHE: if(atadFlushCache(f->unit)) rv=-EIO; break; case APA_DEVCTL_SWAP_TMP: rv=devctlSwapTemp(f->unit, (char *)arg); break; case APA_DEVCTL_SMART_STAT: rv=atadGetStatus(f->unit); break; case APA_DEVCTL_STATUS: rv=hddDeviceBuf[f->unit].status; break; case APA_DEVCTL_FORMAT: rv=hddDeviceBuf[f->unit].format; break; // removed dos not work the way you like... use hddlib ;) //case APA_DEVCTL_FREE_SECTORS: //case APA_DEVCTL_FREE_SECTORS2: // rv=apaGetFreeSectors(f->unit, bufp); // break; // cmd set 2 :) case APA_DEVCTL_GETTIME: rv=getPs2Time((ps2time *)bufp); break; case APA_DEVCTL_SET_OSDMBR: rv=devctlSetOsdMBR(f->unit, (hddSetOsdMBR_t *)arg); break; case APA_DEVCTL_GET_SECTOR_ERROR: rv=getPartErrorSector(f->unit, APA_SECTOR_SECTOR_ERROR, 0); break; case APA_DEVCTL_GET_ERROR_PART_NAME: rv=getPartErrorName(f->unit, (char *)bufp); break; case APA_DEVCTL_ATA_READ: rv=atadDmaTransfer(f->unit, (void *)bufp, ((hddAtaTransfer_t *)arg)->lba, ((hddAtaTransfer_t *)arg)->size, ATAD_MODE_READ); break; case APA_DEVCTL_ATA_WRITE: rv=atadDmaTransfer(f->unit, ((hddAtaTransfer_t *)arg)->data, ((hddAtaTransfer_t *)arg)->lba, ((hddAtaTransfer_t *)arg)->size, ATAD_MODE_WRITE); break; case APA_DEVCTL_SCE_IDENTIFY_DRIVE: rv=atadSceIdentifyDrive(f->unit, (u16 *)bufp); break; case APA_DEVCTL_IS_48BIT: rv=atadIs48bit(f->unit); break; case APA_DEVCTL_SET_TRANSFER_MODE: rv=atadSetTransferMode(f->unit, ((hddAtaSetMode_t *)arg)->type, ((hddAtaSetMode_t *)arg)->mode); break; case APA_DEVCTL_ATA_IOP_WRITE: rv=atadDmaTransfer(f->unit, ((hddAtaIOPTransfer_t *)arg)->data, ((hddAtaIOPTransfer_t *)arg)->lba, ((hddAtaIOPTransfer_t *)arg)->size, ATAD_MODE_WRITE); break; default: rv=-EINVAL; break; } SignalSema(fioSema); return rv; }