/** * Constructs a full data block representation from the specified minimal block * entry. The resultant block's pointers are populated via hash table lookups. * * @param out_block On success, this gets populated with the data * block information. * @param block_entry The source block entry to convert. * * @return 0 on success; nonzero on failure. */ int nffs_block_from_hash_entry(struct nffs_block *out_block, struct nffs_hash_entry *block_entry) { struct nffs_disk_block disk_block; uint32_t area_offset; uint8_t area_idx; int rc; assert(nffs_hash_id_is_block(block_entry->nhe_id)); nffs_flash_loc_expand(block_entry->nhe_flash_loc, &area_idx, &area_offset); rc = nffs_block_read_disk(area_idx, area_offset, &disk_block); if (rc != 0) { return rc; } out_block->nb_hash_entry = block_entry; rc = nffs_block_from_disk(out_block, &disk_block, area_idx, area_offset); if (rc != 0) { return rc; } return 0; }
/** * Constructs a block representation from a minimal block hash entry. If the * hash entry references other objects (inode or previous data block), the * resulting block object is populated with pointers to the referenced objects. * If the any referenced objects are not present in the NFFS RAM * representation, this indicates file system corruption. In this case, the * resulting block is populated with all valid references, and an FS_ECORRUPT * code is returned. * * @param out_block On success, this gets populated with the data * block information. * @param block_entry The source block entry to convert. * * @return 0 on success; * FS_ECORRUPT if one or more pointers could not * be filled in due to file system corruption; * FS_EOFFSET on an attempt to read an invalid * address range; * FS_EHW on flash error; * FS_EUNEXP if the specified disk location does * not contain a block. */ int nffs_block_from_hash_entry(struct nffs_block *out_block, struct nffs_hash_entry *block_entry) { struct nffs_disk_block disk_block; uint32_t area_offset; uint8_t area_idx; int rc; assert(nffs_hash_id_is_block(block_entry->nhe_id)); if (nffs_block_is_dummy(block_entry)) { out_block->nb_hash_entry = block_entry; out_block->nb_inode_entry = NULL; out_block->nb_prev = NULL; /* * Dummy block added when inode was read in before real block * (see nffs_restore_inode()). Return success (because there's * too many places that ned to check for this, * but it's the responsibility fo the upstream code to check * whether this is still a dummy entry. XXX */ return 0; /*return FS_ENOENT;*/ } nffs_flash_loc_expand(block_entry->nhe_flash_loc, &area_idx, &area_offset); rc = nffs_block_read_disk(area_idx, area_offset, &disk_block); if (rc != 0) { return rc; } out_block->nb_hash_entry = block_entry; rc = nffs_block_from_disk(out_block, &disk_block); if (rc != 0) { return rc; } return 0; }