/*
 * Read uncompressed inode lookup table indexes off disk into memory
 */
__le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
		u64 lookup_table_start, unsigned int inodes)
{
	unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes);
	__le64 *inode_lookup_table;
	int err;

	TRACE("In read_inode_lookup_table, length %d\n", length);

	/* Allocate inode lookup table indexes */
	inode_lookup_table = kmalloc(length, GFP_KERNEL);
	if (inode_lookup_table == NULL) {
		ERROR("Failed to allocate inode lookup table\n");
		return ERR_PTR(-ENOMEM);
	}

	err = squashfs_read_table(sb, inode_lookup_table, lookup_table_start,
			length);
	if (err < 0) {
		ERROR("unable to read inode lookup table\n");
		kfree(inode_lookup_table);
		return ERR_PTR(err);
	}

	return inode_lookup_table;
}
Example #2
0
int read_inode_lookup_table(int fd, squashfs_super_block *sBlk, squashfs_inode **inode_lookup_table)
{
	int lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);
	int indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);
	long long index[indexes];
	int i;

	if(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)
		return 1;

	if((*inode_lookup_table = malloc(lookup_bytes)) == NULL) {
		ERROR("Failed to allocate inode lookup table\n");
		return 0;
	}

	if(swap) {
		long long sindex[indexes];

		read_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) sindex);
		SQUASHFS_SWAP_FRAGMENT_INDEXES(index, sindex, indexes);
	} else
		read_bytes(fd, sBlk->lookup_table_start, SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), (char *) index);

	for(i = 0; i <  indexes; i++) {
		int length = read_block(fd, index[i], NULL, ((unsigned char *) *inode_lookup_table) + (i * SQUASHFS_METADATA_SIZE), sBlk);
		TRACE("Read inode lookup table block %d, from 0x%llx, length %d\n", i, index[i], length);
	}

	if(swap) {
		squashfs_inode_t sinode;
		for(i = 0; i < sBlk->inodes; i++) {
			SQUASHFS_SWAP_INODE_T((&sinode), (&(*inode_lookup_table)[i]));
			memcpy((char *) &(*inode_lookup_table)[i], (char *) &sinode, sizeof(squashfs_inode_t));
		}
	}

	return 1;
}
Example #3
0
int read_inode_lookup_table(int fd, struct squashfs_super_block *sBlk,
	squashfs_inode **inode_lookup_table)
{
	int lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);
	int indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);
	long long index[indexes];
	int res, i;

	if(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)
		return 1;

	*inode_lookup_table = malloc(lookup_bytes);
	if(*inode_lookup_table == NULL)
		MEM_ERROR();

	res = read_fs_bytes(fd, sBlk->lookup_table_start,
		SQUASHFS_LOOKUP_BLOCK_BYTES(sBlk->inodes), index);
	if(res == 0) {
		ERROR("Failed to read inode lookup table index\n");
		ERROR("Filesystem corrupted?\n");
		free(*inode_lookup_table);
		return 0;
	}

	SQUASHFS_INSWAP_LONG_LONGS(index, indexes);

	for(i = 0; i <  indexes; i++) {
		int expected = (i + 1) != indexes ? SQUASHFS_METADATA_SIZE :
				lookup_bytes & (SQUASHFS_METADATA_SIZE - 1);
		int length = read_block(fd, index[i], NULL, expected,
			((unsigned char *) *inode_lookup_table) +
			(i * SQUASHFS_METADATA_SIZE));
		TRACE("Read inode lookup table block %d, from 0x%llx, length "
			"%d\n", i, index[i], length);
		if(length == 0) {
			ERROR("Failed to read inode lookup table block %d, "
				"from 0x%llx, length %d\n", i, index[i],
				length);
			ERROR("Filesystem corrupted?\n");
			free(*inode_lookup_table);
			return 0;
		}
	}

	SQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);

	return 1;
}