예제 #1
0
파일: hdd_fio.c 프로젝트: ps2dev/ps2sdk
static int ioctl2AddSub(hdd_file_slot_t *fileSlot, char *argp)
{
	int			rv;
	u32 		device=fileSlot->f->unit;
	apa_params_t	params;
	u32			emptyBlocks[32];
	apa_cache_t	*clink;
	u32			sector=0;
	u32			length;

	if(!(fileSlot->f->mode & O_WRONLY))
		return -EACCES;

	if(!(fileSlot->nsub < APA_MAXSUB))
		return -EFBIG;

	memset(&params, 0, sizeof(apa_params_t));

	if((rv=fioPartitionSizeLookUp(argp)) < 0)
		return rv;

	params.size=rv;
	params.flags=APA_FLAG_SUB;
	params.type=fileSlot->type;
	params.main=fileSlot->parts[0].start;
	params.number=fileSlot->nsub+1;
	if((rv=hddCheckPartitionMax(device, params.size)) < 0)
		return rv;

	// walk all looking for any empty blocks
	memset(&emptyBlocks, 0, sizeof(emptyBlocks));
	clink=apaCacheGetHeader(device, 0, APA_IO_MODE_READ, &rv);
	while(clink){
		sector=clink->sector;
		apaAddEmptyBlock(clink->header, emptyBlocks);
		clink=apaGetNextHeader(clink, &rv);
	}
	if(rv!=0)
		return rv;

	if(!(clink=hddAddPartitionHere(device, &params, emptyBlocks, sector, &rv)))
		return rv;

	sector=clink->header->start;
	length=clink->header->length;
	apaCacheFree(clink);
	if(!(clink=apaCacheGetHeader(device, fileSlot->parts[0].start, APA_IO_MODE_READ, &rv)))
		return rv;

	clink->header->subs[clink->header->nsub].start=sector;
	clink->header->subs[clink->header->nsub].length=length;
	clink->header->nsub++;
	fileSlot->nsub++;
	fileSlot->parts[fileSlot->nsub].start=sector;
	fileSlot->parts[fileSlot->nsub].length=length;
	clink->flags|=APA_CACHE_FLAG_DIRTY;
	apaCacheFlushAllDirty(device);
	apaCacheFree(clink);
	return rv;
}
예제 #2
0
파일: apa.c 프로젝트: EvertonSilva/ps2sdk
int getPartErrorName(u32 device, char *name)
{
	int lba;
	int rv=0;
	apa_cache *clink;

	if((rv=getPartErrorSector(device, APA_SECTOR_PART_ERROR, &lba)) <= 0)
		return rv;
	if(!(clink=cacheGetHeader(device, 0, THEADER_MODE_READ, &rv)))
		return rv;

	while(clink)
	{
		if(clink->header->type!=APA_TYPE_FREE && 
			!(clink->header->flags & CACHE_FLAG_DIRTY) && 
			clink->header->start==lba) {
				if(name) {
					strncpy(name, clink->header->id, APA_IDMAX - 1);
					name[APA_IDMAX - 1] = '\0';
				}
				cacheAdd(clink);
				return 1;
		}
		clink=apaGetNextHeader(clink, &rv);
	}

	// clear error if no errors and partitions was not found...
	if(rv==0)
		setPartErrorSector(device, 0);
	return rv;
}
예제 #3
0
파일: hdd_fio.c 프로젝트: ps2dev/ps2sdk
static int apaOpen(s32 device, hdd_file_slot_t *fileSlot, apa_params_t *params, int mode)
{
	int				rv=0;
	u32				emptyBlocks[32];
	apa_cache_t		*clink;
	apa_cache_t		*clink2;
	u32				sector=0;

	// walk all looking for any empty blocks & look for partition
	clink=apaCacheGetHeader(device, 0, APA_IO_MODE_READ, &rv);
	memset(&emptyBlocks, 0, sizeof(emptyBlocks));
	while(clink)
	{
		sector=clink->sector;
		if(!(clink->header->flags & APA_FLAG_SUB)) {
			if(memcmp(clink->header->id, params->id, APA_IDMAX) == 0)
				break;	// found :)
		}
		apaAddEmptyBlock(clink->header, emptyBlocks);
		clink=apaGetNextHeader(clink, &rv);
	}

	if(rv!=0)
		return rv;
	rv=-ENOENT;

	if(clink==NULL && (mode & O_CREAT))
	{
		if((rv=hddCheckPartitionMax(device, params->size))>=0) {
			if((clink=hddAddPartitionHere(device, params, emptyBlocks, sector, &rv))!=NULL)
			{
				sector=clink->header->start;
				clink2=apaCacheAlloc();
				memset(clink2->header, 0, sizeof(apa_header_t));
				ata_device_sector_io(device, clink2->header, sector+8     , 2, ATA_DIR_WRITE);
				ata_device_sector_io(device, clink2->header, sector+0x2000, 2, ATA_DIR_WRITE);
				apaCacheFree(clink2);
			}
		}
	}
	if(clink==NULL)
		return rv;
	fileSlot->parts[0].start=clink->header->start;
	fileSlot->parts[0].length=clink->header->length;
	memcpy(&fileSlot->parts[1], &clink->header->subs, APA_MAXSUB*sizeof(apa_sub_t));
	fileSlot->type=clink->header->type;
	fileSlot->nsub=clink->header->nsub;
	memcpy(&fileSlot->id, &clink->header->id, APA_IDMAX);
	apaCacheFree(clink);
	if(apaPassCmp(clink->header->fpwd, params->fpwd)!=0)
	{
		rv = (!(mode & O_WRONLY)) ? apaPassCmp(clink->header->rpwd, params->rpwd) : -EACCES;
	} else
		rv = 0;

	return rv;
}
예제 #4
0
파일: apa.c 프로젝트: EvertonSilva/ps2sdk
int apaOpen(u32 device, hdd_file_slot_t *fileSlot, input_param *params, int mode)
{
	int				rv=0;
	u32				emptyBlocks[32];
	apa_cache		*clink;
	apa_cache		*clink2;
	u32				sector=0;
	

	// walk all looking for any empty blocks & look for partition
	clink=cacheGetHeader(device, 0, 0, &rv);
	memset(&emptyBlocks, 0, sizeof(emptyBlocks));
	while(clink)
	{
		sector=clink->sector;
		if(!(clink->header->flags & APA_FLAG_SUB)) {
			if(memcmp(clink->header->id, params->id, APA_IDMAX) == 0)
				break;	// found :)
		}
		addEmptyBlock(clink->header, emptyBlocks);
		clink=apaGetNextHeader(clink, &rv);
	}

	if(rv!=0)
		return rv;
	rv=-ENOENT;

	if(clink==NULL && (mode & O_CREAT))
	{
		if((rv=apaCheckPartitionMax(device, params->size))>=0) {
			if((clink=apaAddPartitionHere(device, params, emptyBlocks, sector, &rv))!=NULL)
			{
				sector=clink->header->start;
				clink2=cacheGetFree();
				memset(clink2->header, 0, sizeof(apa_header));
				atadDmaTransfer(device, clink2->header, sector+8     , 2, ATAD_MODE_WRITE);
				atadDmaTransfer(device, clink2->header, sector+0x2000, 2, ATAD_MODE_WRITE);
				cacheAdd(clink2);
			}
		}
	}
	if(clink==NULL)
		return rv;
	fileSlot->start=clink->header->start;
	fileSlot->length=clink->header->length;
	memcpy(&fileSlot->subs, &clink->header->subs, APA_MAXSUB*sizeof(apa_subs));
	fileSlot->type=clink->header->type;
	fileSlot->nsub=clink->header->nsub;
	memcpy(&fileSlot->id, &clink->header->id, APA_IDMAX);
	cacheAdd(clink);
	rv=0; if(passcmp(clink->header->fpwd, NULL)!=0)
		rv=-EACCES;
	return rv;
}
예제 #5
0
파일: apa.c 프로젝트: uyjulian/pfsshell
apa_cache_t *apaFindPartition(s32 device, const char *id, int *err)
{
    apa_cache_t *clink;

    clink = apaCacheGetHeader(device, 0, APA_IO_MODE_READ, err);
    while (clink) {
        if (!(clink->header->flags & APA_FLAG_SUB)) {
            if (memcmp(clink->header->id, id, APA_IDMAX) == 0)
                return clink; // found
        }
        clink = apaGetNextHeader(clink, (int *)err);
    }
    if (*err == 0) {
        *err = -ENOENT;
        return NULL;
        //return (apa_cache_t *)-ENOENT;		// <-- BUG code tests for NULL only
    }
    *err = 0;
    return NULL;
}