Changeset 5b26747 in mainline
- Timestamp:
- 2012-05-08T08:03:02Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bed78cb
- Parents:
- 3169f3b0
- Location:
- uspace/lib/ext4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_filesystem.c
r3169f3b0 r5b26747 41 41 #include "libext4.h" 42 42 43 /** TODO comment 44 * 43 /** Initialize filesystem and read all needed data. 44 * 45 * @param fs filesystem instance to be initialized 46 * @param service_id identifier if device with the filesystem 47 * @return error code 45 48 */ 46 49 int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id) … … 50 53 fs->device = service_id; 51 54 55 // Initialize block library (4096 is size of communication channel) 52 56 rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096); 53 57 if (rc != EOK) { … … 55 59 } 56 60 57 / * Read superblock from device */61 // Read superblock from device to memory 58 62 ext4_superblock_t *temp_superblock; 59 63 rc = ext4_superblock_read_direct(fs->device, &temp_superblock); … … 63 67 } 64 68 65 / * Read block size from superblock and check */69 // Read block size from superblock and check 66 70 uint32_t block_size = ext4_superblock_get_block_size(temp_superblock); 67 71 if (block_size > EXT4_MAX_BLOCK_SIZE) { … … 70 74 } 71 75 72 / * Initialize block caching */76 // Initialize block caching by libblock 73 77 rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT); 74 78 if (rc != EOK) { … … 77 81 } 78 82 83 // Compute limits for indirect block levels 79 84 uint32_t block_ids_per_block = block_size / sizeof(uint32_t); 80 85 fs->inode_block_limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT; … … 87 92 } 88 93 89 / * Return loaded superblock */94 // Return loaded superblock 90 95 fs->superblock = temp_superblock; 91 96 … … 93 98 } 94 99 95 /** TODO comment 96 * 100 /** Destroy filesystem instance (used by unmount operation). 101 * 102 * @param fs filesystem to be destroyed 103 * @param write_sb flag if superblock should be written to device 104 * @return error code 97 105 */ 98 106 int ext4_filesystem_fini(ext4_filesystem_t *fs, bool write_sb) … … 100 108 int rc = EOK; 101 109 110 // If needed, write the superblock to the device 102 111 if (write_sb) { 103 112 rc = ext4_superblock_write_direct(fs->device, fs->superblock); 104 113 } 105 114 115 // Release memory space for superblock 106 116 free(fs->superblock); 117 118 // Finish work with block library 107 119 block_fini(fs->device); 108 120 … … 110 122 } 111 123 112 /** TODO comment 113 * 124 /** Check sanity of the filesystem. 125 * 126 * Main is the check of the superblock structure. 127 * 128 * @param fs filesystem to be checked 129 * @return error code 114 130 */ 115 131 int ext4_filesystem_check_sanity(ext4_filesystem_t *fs) … … 117 133 int rc; 118 134 135 // Check superblock 119 136 rc = ext4_superblock_check_sanity(fs->superblock); 120 137 if (rc != EOK) { … … 125 142 } 126 143 127 /** TODO comment 128 * 129 */ 130 int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *o_read_only) 131 { 132 /* Feature flags are present in rev 1 and later */ 144 /** Check filesystem's features, if supported by this driver 145 * 146 * Function can return EOK and set read_only flag. It mean's that 147 * there are some not-supported features, that can cause problems 148 * during some write operations. 149 * 150 * @param fs filesystem to be checked 151 * @param read_only flag if filesystem should be mounted only for reading 152 * @return error code 153 */ 154 int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *read_only) 155 { 156 // Feature flags are present only in higher revisions 133 157 if (ext4_superblock_get_rev_level(fs->superblock) == 0) { 134 * o_read_only = false;158 *read_only = false; 135 159 return EOK; 136 160 } 137 161 162 // Check incompatible features - if filesystem has some, 163 // volume can't be mounted 138 164 uint32_t incompatible_features; 139 165 incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock); 140 166 incompatible_features &= ~EXT4_FEATURE_INCOMPAT_SUPP; 141 167 if (incompatible_features > 0) { 142 *o_read_only = true;143 168 return ENOTSUP; 144 169 } 145 170 171 // Check read-only features, if filesystem has some, 172 // volume can be mount only in read-only mode 146 173 uint32_t compatible_read_only; 147 174 compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock); 148 175 compatible_read_only &= ~EXT4_FEATURE_RO_COMPAT_SUPP; 149 176 if (compatible_read_only > 0) { 150 *o_read_only = true; 151 } 152 153 return EOK; 154 } 155 156 /** TODO comment 157 * 177 *read_only = true; 178 return EOK; 179 } 180 181 return EOK; 182 } 183 184 /** Get reference to block group specified by index. 185 * 186 * @param fs filesystem to find block group on 187 * @param bgid index of block group to load 188 * @oaram ref output pointer for reference 189 * @return error code 158 190 */ 159 191 int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *fs, uint32_t bgid, … … 162 194 int rc; 163 195 196 // Allocate memory for new structure 164 197 ext4_block_group_ref_t *newref = malloc(sizeof(ext4_block_group_ref_t)); 165 198 if (newref == NULL) { … … 167 200 } 168 201 202 // Compute number of descriptors, that fits in one data block 169 203 uint32_t descriptors_per_block = ext4_superblock_get_block_size(fs->superblock) 170 204 / ext4_superblock_get_desc_size(fs->superblock); 171 205 172 / * Block group descriptor table starts at the next block after superblock */206 // Block group descriptor table starts at the next block after superblock 173 207 aoff64_t block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1; 174 208 175 / * Find the block containing the descriptor we are looking for */209 // Find the block containing the descriptor we are looking for 176 210 block_id += bgid / descriptors_per_block; 177 211 uint32_t offset = (bgid % descriptors_per_block) * ext4_superblock_get_desc_size(fs->superblock); 178 212 213 // Load block with descriptors 179 214 rc = block_get(&newref->block, fs->device, block_id, 0); 180 215 if (rc != EOK) { … … 183 218 } 184 219 220 // Inititialize in-memory representation 185 221 newref->block_group = newref->block->data + offset; 186 222 newref->fs = fs; … … 228 264 } 229 265 230 /** TODO comment 231 * 266 /** Put reference to block group. 267 * 268 * @oaram ref pointer for reference to be put back 269 * @return error code 232 270 */ 233 271 int ext4_filesystem_put_block_group_ref(ext4_block_group_ref_t *ref) … … 235 273 int rc; 236 274 275 // Check if reference modified 237 276 if (ref->dirty) { 277 278 // Compute new checksum of block group 238 279 uint16_t checksum = ext4_filesystem_bg_checksum( 239 280 ref->fs->superblock, ref->index, ref->block_group); 240 241 281 ext4_block_group_set_checksum(ref->block_group, checksum); 242 282 283 // Mark block dirty for writing changes to physical device 243 284 ref->block->dirty = true; 244 285 } 245 286 287 // Put back block, that contains block group descriptor 246 288 rc = block_put(ref->block); 247 289 free(ref); … … 250 292 } 251 293 252 /** TODO comment 253 * 294 /** Get reference to i-node specified by index. 295 * 296 * @param fs filesystem to find i-node on 297 * @param index index of i-node to load 298 * @oaram ref output pointer for reference 299 * @return error code 254 300 */ 255 301 int ext4_filesystem_get_inode_ref(ext4_filesystem_t *fs, uint32_t index, … … 258 304 int rc; 259 305 306 // Allocate memory for new structure 260 307 ext4_inode_ref_t *newref = malloc(sizeof(ext4_inode_ref_t)); 261 308 if (newref == NULL) { … … 263 310 } 264 311 312 // Compute number of i-nodes, that fits in one data block 265 313 uint32_t inodes_per_group = 266 314 ext4_superblock_get_inodes_per_group(fs->superblock); 267 315 268 /* inode numbers are 1-based, but it is simpler to work with 0-based 316 /* 317 * inode numbers are 1-based, but it is simpler to work with 0-based 269 318 * when computing indices 270 319 */ … … 273 322 uint32_t offset_in_group = index % inodes_per_group; 274 323 324 // Load block group, where i-node is located 275 325 ext4_block_group_ref_t *bg_ref; 276 326 rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref); … … 280 330 } 281 331 332 // Load block address, where i-node table is located 282 333 uint32_t inode_table_start = ext4_block_group_get_inode_table_first_block( 283 334 bg_ref->block_group, fs->superblock); 284 335 336 // Put back block group reference (not needed more) 285 337 rc = ext4_filesystem_put_block_group_ref(bg_ref); 286 338 if (rc != EOK) { … … 289 341 } 290 342 343 // Compute position of i-node in the block group 291 344 uint16_t inode_size = ext4_superblock_get_inode_size(fs->superblock); 292 345 uint32_t block_size = ext4_superblock_get_block_size(fs->superblock); 293 346 uint32_t byte_offset_in_group = offset_in_group * inode_size; 294 347 348 // Compute block address 295 349 aoff64_t block_id = inode_table_start + (byte_offset_in_group / block_size); 296 350 rc = block_get(&newref->block, fs->device, block_id, 0); … … 300 354 } 301 355 356 // Compute position of i-node in the data block 302 357 uint32_t offset_in_block = byte_offset_in_group % block_size; 303 358 newref->inode = newref->block->data + offset_in_block; 304 /* we decremented index above, but need to store the original value 305 * in the reference 306 */ 359 360 // We need to store the original value of index in the reference 307 361 newref->index = index + 1; 308 362 newref->fs = fs; -
uspace/lib/ext4/libext4_inode.c
r3169f3b0 r5b26747 188 188 } 189 189 190 /** TODO comment 191 * 190 /** Get time, when i-node was deleted. 191 * 192 * @param inode i-node 193 * @return time of the delete action (POSIX) 192 194 */ 193 195 uint32_t ext4_inode_get_deletion_time(ext4_inode_t *inode) … … 196 198 } 197 199 198 /** TODO comment 199 * 200 /** Set time, when i-node was deleted. 201 * 202 * @param inode i-node 203 * @param time time of the delete action (POSIX) 200 204 */ 201 205 void ext4_inode_set_deletion_time(ext4_inode_t *inode, uint32_t time) -
uspace/lib/ext4/libext4_superblock.c
r3169f3b0 r5b26747 964 964 } 965 965 966 /** TODO comment 967 * 966 /** Check sanity of the superblock. 967 * 968 * This check is performed at mount time. 969 * Checks are described by one-line comments in the code. 970 * 971 * @param sb superblock to check 972 * @return error code 968 973 */ 969 974 int ext4_superblock_check_sanity(ext4_superblock_t *sb)
Note:
See TracChangeset
for help on using the changeset viewer.