Changeset d241aae in mainline for uspace/lib/ext2
- Timestamp:
- 2011-02-15T19:24:38Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ce13577
- Parents:
- 1d6f507
- Location:
- uspace/lib/ext2
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext2/Makefile
r1d6f507 rd241aae 36 36 SOURCES = \ 37 37 libext2_filesystem.c \ 38 libext2_superblock.c 38 libext2_superblock.c \ 39 libext2_block_group.c 39 40 40 41 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/ext2/libext2.h
r1d6f507 rd241aae 38 38 39 39 #include "libext2_superblock.h" 40 #include "libext2_block_group.h" 40 41 #include "libext2_filesystem.h" 41 42 -
uspace/lib/ext2/libext2_filesystem.c
r1d6f507 rd241aae 34 34 */ 35 35 36 #include "libext2.h" 36 #include "libext2_filesystem.h" 37 #include "libext2_superblock.h" 38 #include "libext2_block_group.h" 37 39 #include <errno.h> 38 40 #include <libblock.h> … … 105 107 106 108 /** 109 * Get a reference to block descriptor 110 * 111 * @param fs Pointer to filesystem information 112 * @param bgid Index of block group to find 113 * @param ref Pointer where to store pointer to block group reference 114 * 115 * @return EOK on success or negative error code on failure 116 */ 117 int ext2_filesystem_get_block_group_ref(ext2_filesystem_t *fs, uint32_t bgid, 118 ext2_block_group_ref_t **ref) 119 { 120 int rc; 121 aoff64_t block_id; 122 uint32_t descriptors_per_block; 123 size_t offset; 124 ext2_block_group_ref_t *newref; 125 126 newref = malloc(sizeof(ext2_block_group_ref_t)); 127 if (newref == NULL) { 128 return ENOMEM; 129 } 130 131 descriptors_per_block = ext2_superblock_get_block_size(fs->superblock) 132 / EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE; 133 134 // Block group descriptor table starts at the next block after superblock 135 block_id = ext2_superblock_get_first_block(fs->superblock) + 1; 136 137 // Find the block containing the descriptor we are looking for 138 block_id += bgid / descriptors_per_block; 139 offset = (bgid % descriptors_per_block) * EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE; 140 141 rc = block_get(&newref->block, fs->device, block_id, 0); 142 if (rc != EOK) { 143 free(newref); 144 return rc; 145 } 146 147 newref->block_group = newref->block->data + offset; 148 149 *ref = newref; 150 151 return EOK; 152 } 153 154 /** 155 * Free a reference to block group 156 * 157 * @param ref Pointer to block group reference to free 158 * 159 * @return EOK on success or negative error code on failure 160 */ 161 int ext2_filesystem_put_block_group_ref(ext2_block_group_ref_t *ref) 162 { 163 int rc; 164 165 rc = block_put(ref->block); 166 free(ref); 167 168 return rc; 169 } 170 171 /** 107 172 * Finalize an instance of filesystem 108 173 * -
uspace/lib/ext2/libext2_filesystem.h
r1d6f507 rd241aae 39 39 #include <libblock.h> 40 40 #include "libext2_superblock.h" 41 #include "libext2_block_group.h" 41 42 42 43 typedef struct ext2_filesystem { … … 52 53 extern int ext2_filesystem_init(ext2_filesystem_t *, devmap_handle_t); 53 54 extern int ext2_filesystem_check_sanity(ext2_filesystem_t *); 55 extern int ext2_filesystem_get_block_group_ref(ext2_filesystem_t *, uint32_t, 56 ext2_block_group_ref_t **); 57 extern int ext2_filesystem_put_block_group_ref(ext2_block_group_ref_t *); 54 58 extern void ext2_filesystem_fini(ext2_filesystem_t *); 55 59 -
uspace/lib/ext2/libext2_superblock.c
r1d6f507 rd241aae 260 260 * Compute count of block groups present in the filesystem 261 261 * 262 * Note: This function works only for correct filesystem, 263 * i.e. it assumes that total block count > 0 and 264 * blocks per group > 0 265 * 266 * Example: 267 * If there are 3 blocks per group, the result should be as follows: 268 * Total blocks Result 269 * 1 1 270 * 2 1 271 * 3 1 272 * 4 2 273 * 274 * 262 275 * @param sb pointer to superblock 263 276 */ 264 277 inline uint32_t ext2_superblock_get_block_group_count(ext2_superblock_t *sb) 265 278 { 266 return ext2_superblock_get_total_block_count(sb) / 267 ext2_superblock_get_blocks_per_group(sb); 279 /* We add one to the result because e.g. 2/3 = 0, while to store 280 * 2 blocks in 3-block group we need one (1) block group 281 * 282 * We subtract one first because of special case that to store e.g. 283 * 3 blocks in a 3-block group we need only one group 284 * (and 3/3 yields one - this is one more that we want as we 285 * already add one at the end) 286 */ 287 return ((ext2_superblock_get_total_block_count(sb)-1) / 288 ext2_superblock_get_blocks_per_group(sb))+1; 268 289 } 269 290
Note:
See TracChangeset
for help on using the changeset viewer.