Changeset 566c401 in mainline
- Timestamp:
- 2011-02-13T20:37:31Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8bd5dad
- Parents:
- e272949
- Location:
- uspace/lib/ext2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext2/libext2.h
re272949 r566c401 1 1 /* 2 * Copyright (c) 201 0Martin Sucha2 * Copyright (c) 2011 Martin Sucha 3 3 * All rights reserved. 4 4 * … … 50 50 uint8_t unused2[12]; 51 51 uint16_t magic; // Magic value 52 } __attribute__ ((packed)) ext2_superblock_t; 52 53 53 // TODO: add __attribute__((aligned(...)) for better performance? 54 54 // (it is necessary to ensure the superblock is correctly aligned then 55 55 // though) 56 } __attribute__ ((packed)) ext2_superblock_t; 57 56 58 57 59 typedef struct ext2_filesystem { … … 66 68 EXT2_SUPERBLOCK_SIZE -1) 67 69 68 inline uint16_t ext2_superblock_get_magic(ext2_superblock_t * sb);69 inline uint32_t ext2_superblock_get_first_block(ext2_superblock_t * sb);70 inline uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t * sb);71 inline uint32_t ext2_superblock_get_block_size(ext2_superblock_t * sb);72 inline int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t * sb);73 inline uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t * sb);74 inline uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t * sb);75 inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t * sb);70 inline uint16_t ext2_superblock_get_magic(ext2_superblock_t *); 71 inline uint32_t ext2_superblock_get_first_block(ext2_superblock_t *); 72 inline uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *); 73 inline uint32_t ext2_superblock_get_block_size(ext2_superblock_t *); 74 inline int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t *); 75 inline uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *); 76 inline uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *); 77 inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *); 76 78 77 int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **);79 extern int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **); 78 80 79 int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t dev);80 void ext2_filesystem_fini(ext2_filesystem_t *fs);81 extern int ext2_filesystem_init(ext2_filesystem_t *, devmap_handle_t); 82 extern void ext2_filesystem_fini(ext2_filesystem_t *); 81 83 82 84 #endif -
uspace/lib/ext2/libext2_filesystem.c
re272949 r566c401 43 43 * This function reads superblock from the device and 44 44 * initializes libblock cache with appropriate logical block size. 45 * 46 * @param fs Pointer to ext2_filesystem_t to initialize 47 * @param devmap_handle Device handle of the block device 45 48 */ 46 int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t dev) { 49 int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t devmap_handle) 50 { 47 51 int rc; 48 52 ext2_superblock_t *temp_superblock; 49 53 50 fs->device = dev ;54 fs->device = devmap_handle; 51 55 52 56 rc = block_init(fs->device, 2048); … … 55 59 } 56 60 57 rc = ext2_superblock_read_direct( dev, &temp_superblock);61 rc = ext2_superblock_read_direct(fs->device, &temp_superblock); 58 62 if (rc != EOK) { 59 block_fini( dev);63 block_fini(fs->device); 60 64 return rc; 61 65 } … … 68 72 /** 69 73 * Finalize an instance of filesystem 74 * 75 * @param fs Pointer to ext2_filesystem_t to finalize 70 76 */ 71 void ext2_filesystem_fini(ext2_filesystem_t *fs) { 77 void ext2_filesystem_fini(ext2_filesystem_t *fs) 78 { 72 79 block_fini(fs->device); 73 80 } -
uspace/lib/ext2/libext2_superblock.c
re272949 r566c401 42 42 * Return a magic number from ext2 superblock, this should be equal to 43 43 * EXT_SUPERBLOCK_MAGIC for valid ext2 superblock 44 * 45 * @param sb pointer to superblock 44 46 */ 45 inline uint16_t ext2_superblock_get_magic(ext2_superblock_t *sb) { 47 inline uint16_t ext2_superblock_get_magic(ext2_superblock_t *sb) 48 { 46 49 return uint16_t_le2host(sb->magic); 47 50 } … … 50 53 * Get the position of first ext2 data block (i.e. the block number 51 54 * containing main superblock) 55 * 56 * @param sb pointer to superblock 52 57 */ 53 inline uint32_t ext2_superblock_get_first_block(ext2_superblock_t *sb) { 58 inline uint32_t ext2_superblock_get_first_block(ext2_superblock_t *sb) 59 { 54 60 return uint32_t_le2host(sb->first_block); 55 61 } … … 58 64 * Get the number of bits to shift a value of 1024 to the left necessary 59 65 * to get the size of a block 66 * 67 * @param sb pointer to superblock 60 68 */ 61 inline uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *sb) { 69 inline uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *sb) 70 { 62 71 return uint32_t_le2host(sb->block_size_log2); 63 72 } … … 65 74 /** 66 75 * Get the size of a block, in bytes 76 * 77 * @param sb pointer to superblock 67 78 */ 68 inline uint32_t ext2_superblock_get_block_size(ext2_superblock_t *sb) { 79 inline uint32_t ext2_superblock_get_block_size(ext2_superblock_t *sb) 80 { 69 81 return 1024 << ext2_superblock_get_block_size(sb); 70 82 } … … 74 86 * to get the size of a fragment (note that this is a signed integer and 75 87 * if negative, the value should be shifted to the right instead) 88 * 89 * @param sb pointer to superblock 76 90 */ 77 inline int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t *sb) { 91 inline int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t *sb) 92 { 78 93 return uint32_t_le2host(sb->fragment_size_log2); 79 94 } … … 81 96 /** 82 97 * Get the size of a fragment, in bytes 98 * 99 * @param sb pointer to superblock 83 100 */ 84 inline uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *sb) { 101 inline uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *sb) 102 { 85 103 int32_t log = ext2_superblock_get_fragment_size_log2(sb); 86 104 if (log >= 0) { … … 94 112 /** 95 113 * Get number of blocks per block group 114 * 115 * @param sb pointer to superblock 96 116 */ 97 inline uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *sb) { 117 inline uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *sb) 118 { 98 119 return uint32_t_le2host(sb->blocks_per_group); 99 120 } … … 101 122 /** 102 123 * Get number of fragments per block group 124 * 125 * @param sb pointer to superblock 103 126 */ 104 inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *sb) { 127 inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *sb) 128 { 105 129 return uint32_t_le2host(sb->fragments_per_group); 106 130 }
Note:
See TracChangeset
for help on using the changeset viewer.