/**
 * Get size of file
 * 
 * For regular files in revision 1 and later, the high 32 bits of
 * file size are stored in inode->size_high and are 0 otherwise
 * 
 * @param inode pointer to inode
 */
uint64_t ext2_inode_get_size(ext2_superblock_t *sb, ext2_inode_t *inode)
{
	uint32_t major_rev = ext2_superblock_get_rev_major(sb);
	
	if (major_rev > 0 && ext2_inode_is_type(sb, inode, EXT2_INODE_MODE_FILE)) {
		return ((uint64_t)uint32_t_le2host(inode->size_high)) << 32 |
		    ((uint64_t)uint32_t_le2host(inode->size));
	}
	return uint32_t_le2host(inode->size);
}
Exemple #2
0
/** Perform basic sanity checks on the file system.
 *
 * Verify if values of boot sector fields are sane. Also verify media
 * descriptor. This is used to rule out cases when a device obviously
 * does not contain a exfat file system.
 */
int exfat_sanity_check(exfat_bs_t *bs, service_id_t service_id)
{
	if (str_cmp((char const *)bs->oem_name, "EXFAT   "))
		return ENOTSUP;
	else if (uint16_t_le2host(bs->signature) != 0xAA55)
		return ENOTSUP;
	else if (uint32_t_le2host(bs->fat_sector_count) == 0)
		return ENOTSUP;
	else if (uint32_t_le2host(bs->data_clusters) == 0)
		return ENOTSUP;
	else if (bs->fat_count != 1)
		return ENOTSUP;
	else if ((bs->bytes_per_sector + bs->sec_per_cluster) > 25) {
		/* exFAT does not support cluster size > 32 Mb */
		return ENOTSUP;
	}
	return EOK;
}
Exemple #3
0
/** Get cluster from the FAT.
 *
 * @param bs		Buffer holding the boot sector for the file system.
 * @param service_id	Service ID for the file system.
 * @param clst		Cluster which to get.
 * @param value		Output argument holding the value of the cluster.
 *
 * @return		EOK or a negative error code.
 */
int
exfat_get_cluster(exfat_bs_t *bs, service_id_t service_id,
    exfat_cluster_t clst, exfat_cluster_t *value)
{
	block_t *b;
	aoff64_t offset;
	int rc;

	offset = clst * sizeof(exfat_cluster_t);

	rc = block_get(&b, service_id, FAT_FS(bs) + offset / BPS(bs), BLOCK_FLAGS_NONE);
	if (rc != EOK)
		return rc;

	*value = uint32_t_le2host(*(uint32_t *)(b->data + offset % BPS(bs)));

	rc = block_put(b);

	return rc;
}
/** Get number of data blocks in the whole filesystem.
 *
 * @param sb Superblock
 *
 * @return Number of data blocks
 *
 */
uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *sb)
{
	return ((uint64_t) uint32_t_le2host(sb->blocks_count_hi) << 32) |
	    uint32_t_le2host(sb->blocks_count_lo);
}
/** Get number of i-nodes in the whole filesystem.
 *
 * @param sb Superblock
 *
 * @return Number of i-nodes
 *
 */
uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *sb)
{
	return uint32_t_le2host(sb->inodes_count);
}
Exemple #6
0
/** Get i-node number from directory entry.
 *
 * @param de Directory entry
 *
 * @return I-node number
 *
 */
uint32_t ext4_directory_entry_ll_get_inode(ext4_directory_entry_ll_t *de)
{
	return uint32_t_le2host(de->inode);
}
Exemple #7
0
uint32_t hda_reg32_read(uint32_t *r)
{
	return uint32_t_le2host(pio_read_32(r));
}
/**
 * Get indirect block ID
 * 
 * @param inode pointer to inode
 * @param idx Indirection level. Valid values are 0 <= idx < 3, where 0 is
 *            singly-indirect block and 2 is triply-indirect-block
 */
uint32_t ext2_inode_get_indirect_block(ext2_inode_t *inode, uint8_t idx)
{
	assert(idx < 3);
	return uint32_t_le2host(inode->indirect_blocks[idx]);
}
/**
 * Get direct block ID
 * 
 * @param inode pointer to inode
 * @param idx Index to block. Valid values are 0 <= idx < 12
 */
uint32_t ext2_inode_get_direct_block(ext2_inode_t *inode, uint8_t idx)
{
	assert(idx < EXT2_INODE_DIRECT_BLOCKS);
	return uint32_t_le2host(inode->direct_blocks[idx]);
}
/**
 * Get inode flags
 * 
 * @param inode pointer to inode
 */
uint32_t ext2_inode_get_flags(ext2_inode_t *inode) {
	return uint32_t_le2host(inode->flags);
}
/**
 * Get number of 512-byte data blocks allocated for contents of the file
 * represented by this inode.
 * This should be multiple of block size unless fragments are used.
 * 
 * @param inode pointer to inode
 */
uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *inode)
{
	return uint32_t_le2host(inode->reserved_512_blocks);
}