Example #1
0
int blockInitPos(pfs_cache_t *clink, pfs_blockpos_t *blockpos, u64 position)
{
	blockpos->inode=cacheUsedAdd(clink);
	blockpos->byte_offset=0;

	if (clink->u.inode->size)
	{
		blockpos->block_segment=1;
		blockpos->block_offset=0;
	}else{
		blockpos->block_segment=0;
		blockpos->block_offset=1;
	}
	return inodeSync(blockpos, position, clink->u.inode->number_data);
}
Example #2
0
int getNextDentry(pfs_cache_t *clink, pfs_blockpos_t *blockpos, u32 *position, char *name, pfs_blockinfo *bi)
{
	int result;
	pfs_cache_t *dcache;
	pfs_dentry *dentry;
	u32 len=0;

	// loop until a non-empty entry is found or until the end of the dentry chunk is reached
	while((len == 0) && (*position < clink->u.inode->size))
	{

		if (!(dcache=getDentriesChunk(blockpos, &result)))
		{
			dprintf("ps2fs: couldnt get dentries chunk for dread!\n");
			break;
		}

		dentry = (pfs_dentry*)((u32)dcache->u.data + (blockpos->byte_offset % metaSize));

		len = dentry->pLen;
		memcpy(name, dentry->path, len);
		name[len] = '\0';

		bi->subpart = dentry->sub;
		bi->number = dentry->inode;
		cacheAdd(dcache);

		*position += dentry->aLen & 0xFFF;

		// update blockpos
		if (inodeSync(blockpos, dentry->aLen & 0xFFF, clink->u.inode->number_data))
			break;
	}

	return len;
}
Example #3
0
// Gets a dir entry from the inode specified by clink
pfs_cache_t *getDentry(pfs_cache_t *clink, char *path, pfs_dentry **dentry, u32 *size, int option)
{
	pfs_blockpos_t block_pos;
	u32	result;
	pfs_dentry *d;
	u16 aLen;
	pfs_dentry *d2;
	pfs_cache_t *dentCache;
	u32 dentryLen=0;
	int len=0;

	if (path)
	{
		len = strlen(path);
		dentryLen = (len+8+3) &~4;
	}
	*size = 0;

	block_pos.inode = cacheUsedAdd(clink);
	block_pos.block_segment = 1;
	block_pos.block_offset = 0;
	block_pos.byte_offset = 0;
	dentCache = getDentriesChunk(&block_pos, (int *)&result);

	if (dentCache)
	{
		d2=d=dentCache->u.dentry;
		while(*size < clink->u.inode->size)
		{
			// Read another dentry chunk if we need to
			if ((int)d2 >= ((int)dentCache->u.inode + metaSize))
			{
				if (inodeSync(&block_pos, metaSize, clink->u.inode->number_data))
					break;
				cacheAdd(dentCache);

				if ((dentCache=getDentriesChunk(&block_pos, (int *)&result))==0)
					break;
				d=dentCache->u.dentry;
			}

			for (d2=(pfs_dentry*)((int)d+512); d < d2; (int)d+=aLen)
			{
				aLen=(d->aLen & 0xFFF);

				if (aLen & 3){
					printf("ps2fs: Error: dir-entry allocated length/4 != 0\n");
					goto _exit;
				}
				if (aLen < ((d->pLen + 8 + 3) & 0x1FC)){
					printf("ps2fs: Error: dir-entry is too small\n");
					goto _exit;
				}
				if ((u32)d2 < ((u32)d + aLen)){
					printf("ps2fs: Error: dir-entry across sectors\n");
					goto _exit;
				}

				// decide if the current dentry meets the required criteria, based on 'option'
				switch(option)
				{
					case 0: // result = 1 when paths are equal
						result = (len==d->pLen) && (memcmp(path, d->path, d->pLen)==0);
						break;
					case 1: // hrm..
						result = ((d->inode) || (aLen < dentryLen)) ? ((aLen - ((d->pLen + 8 + 3) & 0x1FC))
								> dentryLen) : 1;
						break;
					case 2: // result = 1 when dir path is not empty, "." or ".."
						result = d->pLen && strcmp(d->path, ".") && strcmp(d->path, "..");
						break;
					default:
						goto _exit;
				}

				if (result)
				{
					*dentry=d;
					cacheAdd(block_pos.inode);
					return dentCache;
				}
				*size+=aLen;
			}
		}
_exit:		cacheAdd(dentCache);
	}
	cacheAdd(block_pos.inode);
	return NULL;
}