Exemplo n.º 1
0
int apaJournalRestore(s32 device)
{	// copys apa headers from apal to apa system
	int i;
	u32 sector;
	apa_cache_t *clink;

	APA_PRINTF(APA_DRV_NAME": checking log...\n");
	if(ata_device_sector_io(device, &journalBuf, APA_SECTOR_APAL, sizeof(apa_journal_t)/512, ATA_DIR_READ)){
		apaJournalReset(device);
		return -EIO;
	}
	if(journalBuf.magic==APAL_MAGIC)
	{
		if(journalBuf.num==0)
			return 0;
		clink=apaCacheAlloc();
		for(i=0, sector=APA_SECTOR_APAL_HEADERS;i<journalBuf.num;i++, sector+=2)
		{
			if(ata_device_sector_io(device, clink->header, sector, 2, ATA_DIR_READ))
				break;
			if(ata_device_sector_io(device, clink->header, journalBuf.sectors[i], 2, ATA_DIR_WRITE))
				break;
		}
		apaCacheFree(clink);
		return apaJournalReset(device);// only do if journal..
	}
	memset(&journalBuf, 0, sizeof(apa_journal_t));// safe e
	journalBuf.magic=APAL_MAGIC;
	return 0;//-EINVAL;
}
Exemplo n.º 2
0
int apaGetIlinkID(u8 *idbuf)
{
	u32 err=0;

	memset(idbuf, 0, 32);
	if(sceCdRI(idbuf, &err))
		if(err==0)
			return 0;
	APA_PRINTF(APA_DRV_NAME": Error: cannot get ilink id\n");
	return -EIO;
}
Exemplo n.º 3
0
static int fioPartitionSizeLookUp(char *str)
{
	int	i;

	for(i=0;i<APA_NUMBER_OF_SIZES;i++){
		if(strcmp(str, sizeList[i])==0)
			return (256*1024) << i;
	}
	APA_PRINTF(APA_DRV_NAME": Error: Invalid partition size, %s.\n", str);
	return -EINVAL;
}
Exemplo n.º 4
0
int apaReadHeader(s32 device, apa_header_t *header, u32 lba)
{
    if (ata_device_sector_io(device, header, lba, 2, ATA_DIR_READ) != 0)
        return -EIO;
    if (header->magic != APA_MAGIC)
        return -EIO;
    if (apaCheckSum(header) != header->checksum)
        return -EIO;
    if (lba == APA_SECTOR_MBR) {
        if (strncmp(header->mbr.magic, apaMBRMagic, sizeof(header->mbr.magic)) == 0)
            return 0;
        APA_PRINTF(APA_DRV_NAME ": error: invalid partition table or version newer than I know.\n");
        return -EIO;
    }
    return 0;
}
Exemplo n.º 5
0
static int devctlSetOsdMBR(s32 device, hddSetOsdMBR_t *mbrInfo)
{
	int rv;
	apa_cache_t *clink;

	if(!(clink=apaCacheGetHeader(device, APA_SECTOR_MBR, APA_IO_MODE_READ, &rv)))
		return rv;

	APA_PRINTF(	APA_DRV_NAME": mbr start: %ld\n"
				APA_DRV_NAME": mbr size : %ld\n", mbrInfo->start, mbrInfo->size);
	clink->header->mbr.osdStart=mbrInfo->start;
	clink->header->mbr.osdSize=mbrInfo->size;
	clink->flags|=APA_CACHE_FLAG_DIRTY;
	apaCacheFlushAllDirty(device);
	apaCacheFree(clink);
	return rv;
}
Exemplo n.º 6
0
apa_cache_t *apaGetNextHeader(apa_cache_t *clink, int *err)
{
    u32 start = clink->header->start;

    apaCacheFree(clink);
    if (!clink->header->next)
        return NULL;

    if (!(clink = apaCacheGetHeader(clink->device, clink->header->next, APA_IO_MODE_READ, err)))
        return NULL;

    if (start != clink->header->prev) {
        APA_PRINTF(APA_DRV_NAME ": Warning: Invalid partition information. start != prev\n");
        clink->header->prev = start;
        clink->flags |= APA_CACHE_FLAG_DIRTY;
        apaCacheFlushAllDirty(clink->device);
    }
    return clink;
}
Exemplo n.º 7
0
int _start(int argc, char **argv)
{
    int i, ret;
    char *input;
    int cacheSize = 3;
    apa_ps2time_t tm;
    ata_devinfo_t *hddInfo;

    printStartup();

    if ((input = strrchr(argv[0], '/')))
        input++;
    else
        input = argv[0];

    argc--;
    argv++;
    while (argc) {
        if (argv[0][0] != '-')
            break;
        if (strcmp("-o", argv[0]) == 0) {
            argc--;
            argv++;
            if (!argc)
                return inputError(input);
            i = strtol(argv[0], 0, 10);
            if (i - 1 < 32)
                apaMaxOpen = i;
        } else if (strcmp("-n", argv[0]) == 0) {
            argc--;
            argv++;
            if (!argc)
                return inputError(input);
            i = strtol(*argv, 0, 10);
            if (cacheSize < i)
                cacheSize = i;
        }
        argc--;
        argv++;
    }

    APA_PRINTF(APA_DRV_NAME ": max open = %d, %d buffers\n", apaMaxOpen, cacheSize);
    if (dev9RegisterShutdownCb(0, &hddShutdownCb) != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: dev9 may not be resident.\n");
        return hddInitError();
    }

    if (apaGetTime(&tm) != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: could not get date.\n");
        return hddInitError();
    }

    APA_PRINTF(APA_DRV_NAME ": %02d:%02d:%02d %02d/%02d/%d\n",
               tm.hour, tm.min, tm.sec, tm.month, tm.day, tm.year);
    for (i = 0; i < 2; i++) {
        if (!(hddInfo = ata_get_devinfo(i))) {
            APA_PRINTF(APA_DRV_NAME ": Error: ata initialization failed.\n");
            return hddInitError();
        }
        if (hddInfo->exists != 0 && hddInfo->has_packet == 0) {
            hddDevices[i].status--;
            hddDevices[i].totalLBA = hddInfo->total_sectors;
            hddDevices[i].partitionMaxSize = apaGetPartitionMax(hddInfo->total_sectors);
            if (unlockDrive(i) == 0)
                hddDevices[i].status--;
            APA_PRINTF(APA_DRV_NAME ": disk%d: 0x%08lx sectors, max 0x%08lx\n", i,
                       hddDevices[i].totalLBA, hddDevices[i].partitionMaxSize);
        }
    }
    hddFileSlots = apaAllocMem(apaMaxOpen * sizeof(hdd_file_slot_t));
    ret = (hddFileSlots == NULL) ? -ENOMEM : 0;
    if (ret != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: file descriptor initialization failed.\n");
        return hddInitError();
    }

    memset(hddFileSlots, 0, apaMaxOpen * sizeof(hdd_file_slot_t));

    if (apaCacheInit(cacheSize) != 0) {
        APA_PRINTF(APA_DRV_NAME ": error: cache buffer initialization failed.\n");
        return hddInitError();
    }

    for (i = 0; i < 2; i++) {
        if (hddDevices[i].status < 2) {
            if (apaJournalRestore(i) != 0) {
                APA_PRINTF(APA_DRV_NAME ": error: log check failed.\n");
                return hddInitError();
            }
            if (apaGetFormat(i, &hddDevices[i].format))
                hddDevices[i].status--;
            APA_PRINTF(APA_DRV_NAME ": drive status %d, format version %08x\n",
                       hddDevices[i].status, hddDevices[i].format);
        }
    }
    DelDrv("hdd");
    if (AddDrv(&hddFioDev) == 0) {
#ifdef APA_OSD_VER
        APA_PRINTF(APA_DRV_NAME ": version %04x driver start. This is OSD version!\n", IRX_VER(APA_MODVER_MAJOR, APA_MODVER_MINOR));
#else
        APA_PRINTF(APA_DRV_NAME ": version %04x driver start.\n", IRX_VER(APA_MODVER_MAJOR, APA_MODVER_MINOR));
#endif
        return MODULE_RESIDENT_END;
    } else {
        APA_PRINTF(APA_DRV_NAME ": error: add device failed.\n");
        return hddInitError();
    }
}
Exemplo n.º 8
0
static void printStartup(void)
{
    APA_PRINTF(APA_DRV_NAME ": PS2 APA Driver v%d.%d (c) 2003 Vector\n", APA_MODVER_MAJOR, APA_MODVER_MINOR);
    return;
}
Exemplo n.º 9
0
static int inputError(char *input)
{
    APA_PRINTF(APA_DRV_NAME ": Error: Usage: %s [-o <apaMaxOpen>] [-n <maxcache>]\n", input);
    return MODULE_NO_RESIDENT_END;
}