Changeset e272949 in mainline for uspace/lib/ext2/libext2_filesystem.c
- Timestamp:
- 2011-02-13T20:27:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 566c401
- Parents:
- 36bca8eb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext2/libext2_filesystem.c
r36bca8eb re272949 37 37 #include <errno.h> 38 38 #include <libblock.h> 39 #include <mem.h>40 39 #include <malloc.h> 41 42 int ext2_superblock_read_direct(ext2_superblock_t **superblock,43 devmap_handle_t dev) {44 int rc;45 size_t phys_block_size;46 size_t buf_size;47 uint8_t *buffer;48 size_t first_block;49 size_t last_block;50 size_t blocks;51 size_t offset;52 ext2_superblock_t *tmp_superblock;53 54 rc = block_get_bsize(dev, &phys_block_size);55 if (rc != EOK) {56 return rc;57 }58 59 // calculate superblock position and required space60 first_block = EXT2_SUPERBLOCK_OFFSET / phys_block_size;61 offset = EXT2_SUPERBLOCK_OFFSET % phys_block_size;62 last_block = EXT2_SUPERBLOCK_LAST_BYTE / phys_block_size;63 blocks = last_block - first_block + 1;64 buf_size = blocks * phys_block_size;65 66 // read the superblock into memory67 buffer = malloc(buf_size);68 if (buffer == NULL) {69 return ENOMEM;70 }71 72 rc = block_read_direct(dev, first_block, blocks, buffer);73 if (rc != EOK) {74 free(buffer);75 return rc;76 }77 78 // copy the superblock from the buffer79 // as it may not be at the start of the block80 // (i.e. blocks larger than 1K)81 tmp_superblock = malloc(EXT2_SUPERBLOCK_SIZE);82 if (tmp_superblock == NULL) {83 free(buffer);84 return ENOMEM;85 }86 87 memcpy(tmp_superblock, buffer + offset, EXT2_SUPERBLOCK_SIZE);88 free(buffer);89 (*superblock) = tmp_superblock;90 91 return EOK;92 }93 40 94 41 /** … … 108 55 } 109 56 110 rc = ext2_superblock_read_direct( &temp_superblock, dev);57 rc = ext2_superblock_read_direct(dev, &temp_superblock); 111 58 if (rc != EOK) { 112 59 block_fini(dev);
Note:
See TracChangeset
for help on using the changeset viewer.