コード例 #1
0
ファイル: hdd.c プロジェクト: uyjulian/pfsshell
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();
    }
}
コード例 #2
0
ファイル: hdd.c プロジェクト: EvertonSilva/ps2sdk
int _start(int argc, char **argv)
{
	int 	i;
	char	*input;
	int		cacheSize=3;
	ps2time tm;
	t_shddInfo *hddInfo;

	printStartup();
	// decode MBR Magic
	for(i=0;i!=0x20;i++)
		mbrMagic[i]^='x';

	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)
				maxOpen=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++;
	}

	printf("ps2hdd: max open = %ld, %d buffers\n", maxOpen, cacheSize);
	getPs2Time(&tm);
	printf("ps2hdd: %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=atadInit((u16)i))){
			printf("ps2hdd: Error: ata initialization failed.\n");
			return 0;
		}
		if(hddInfo->exists!=0 && hddInfo->has_packet==0){
				hddDeviceBuf[i].status--;
				hddDeviceBuf[i].totalLBA=hddInfo->total_sectors;
				hddDeviceBuf[i].partitionMaxSize=apaGetPartitionMax(hddInfo->total_sectors);
				if(unlockDrive(i)==0)
					hddDeviceBuf[i].status--;
				printf("ps2hdd: disk%d: 0x%08lx sectors, max 0x%08lx\n", i,
					hddDeviceBuf[i].totalLBA, hddDeviceBuf[i].partitionMaxSize);
		}
	}
	fileSlots=allocMem(maxOpen*sizeof(hdd_file_slot_t));
	if(fileSlots)
		memset(fileSlots, 0, maxOpen*sizeof(hdd_file_slot_t));

	cacheInit(cacheSize);
	for(i=0;i < 2;i++)
	{
		if(hddDeviceBuf[i].status<2){
			if(journalResetore(i)!=0)
				return 1;
			if(apaGetFormat(i, (int *)&hddDeviceBuf[i].format))
				hddDeviceBuf[i].status--;
			printf("ps2hdd: drive status %ld, format version %08lx\n",
				hddDeviceBuf[i].status, hddDeviceBuf[i].format);
		}
	}
	DelDrv("hdd");
	if(AddDrv(&hddFioDev)==0)
	{
		printf("ps2hdd: driver start.\n");
		return 0;
	}
	return 1;
}