예제 #1
0
파일: journal.c 프로젝트: AKuHAK2/ps2sdk
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;
}
예제 #2
0
파일: hdd_fio.c 프로젝트: ps2dev/ps2sdk
int hddFormat(iop_file_t *f, const char *dev, const char *blockdev, void *arg, int arglen)
{
	int				rv=0;
	apa_cache_t		*clink;
	u32			i;
#ifdef APA_FORMAT_MAKE_PARTITIONS
	apa_params_t		params;
	u32				emptyBlocks[32];
#endif

	if(f->unit >= 2)
		return -ENXIO;

	// clear all errors on hdd
	clink=apaCacheAlloc();
	memset(clink->header, 0, sizeof(apa_header_t));
	if(ata_device_sector_io(f->unit, clink->header, APA_SECTOR_SECTOR_ERROR, 1, ATA_DIR_WRITE)){
		apaCacheFree(clink);
		return -EIO;
	}
	if(ata_device_sector_io(f->unit, clink->header, APA_SECTOR_PART_ERROR, 1, ATA_DIR_WRITE)){
		apaCacheFree(clink);
		return -EIO;
	}
	// clear apa headers
	for(i=1024*8;i<hddDevices[f->unit].totalLBA;i+=(1024*256))
	{
		ata_device_sector_io(f->unit, clink->header, i, sizeof(apa_header_t)/512,
			ATA_DIR_WRITE);
	}
	apaCacheFree(clink);
	if((rv=apaJournalReset(f->unit))!=0)
		return rv;

	// set up mbr :)
	if((clink=apaCacheGetHeader(f->unit, 0, APA_IO_MODE_WRITE, &rv))){
		apa_header_t *header=clink->header;
		memset(header, 0, sizeof(apa_header_t));
		header->magic=APA_MAGIC;
		header->length=(1024*256);	// 128MB
		header->type=APA_TYPE_MBR;
		strcpy(header->id,"__mbr");
#ifdef APA_FORMAT_LOCK_MBR
		apaEncryptPassword(header->id, header->fpwd, "sce_mbr");
		apaEncryptPassword(header->id, header->rpwd, "sce_mbr");
#endif
		memcpy(header->mbr.magic, apaMBRMagic, sizeof(header->mbr.magic));

		header->mbr.version=APA_MBR_VERSION;
		header->mbr.nsector=0;
		apaGetTime(&header->created);
		apaGetTime(&header->mbr.created);
		header->checksum=apaCheckSum(header);
		clink->flags|=APA_CACHE_FLAG_DIRTY;
		apaCacheFlushDirty(clink);
		ata_device_flush_cache(f->unit);
		apaCacheFree(clink);
		hddDevices[f->unit].status=0;
		hddDevices[f->unit].format=APA_MBR_VERSION;
	}
#ifdef APA_FORMAT_MAKE_PARTITIONS
	memset(&emptyBlocks, 0, sizeof(emptyBlocks));
	memset(&params, 0, sizeof(apa_params_t));
	params.size=(1024*256);
	params.type=APA_TYPE_PFS;

	// add __net, __system....
	for(i=0;formatPartList[i];i++)
	{
		memset(params.id, 0, APA_IDMAX);
		strcpy(params.id, formatPartList[i]);
		if(!(clink=hddAddPartitionHere(f->unit, &params, emptyBlocks, i ? clink->sector : 0, &rv)))
			return rv;
		apaCacheFree(clink);

		params.size<<=1;
		if(hddDevices[f->unit].partitionMaxSize < params.size)
			params.size=hddDevices[f->unit].partitionMaxSize;
	}
#endif
	return rv;
}