Changeset 2b3e8840 in mainline
- Timestamp:
- 2013-07-11T15:52:52Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e6edc8d1
- Parents:
- 224174f (diff), b2c96093 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/srv/fs/mfs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs.h
r224174f r2b3e8840 58 58 #endif 59 59 60 #define MFS_BMAP_START_BLOCK(sbi, bid) \ 61 ((bid) == BMAP_ZONE ? 2 + (sbi)->ibmap_blocks : 2) 62 63 #define MFS_BMAP_SIZE_BITS(sbi, bid) \ 64 ((bid) == BMAP_ZONE ? (sbi)->nzones - (sbi)->firstdatazone - 1 : \ 65 (sbi)->ninodes - 1) 66 67 #define MFS_BMAP_SIZE_BLOCKS(sbi, bid) \ 68 ((bid) == BMAP_ZONE ? (sbi)->zbmap_blocks : (sbi)->ibmap_blocks) 69 60 70 typedef uint32_t bitchunk_t; 61 71 … … 201 211 mfs_free_zone(struct mfs_instance *inst, uint32_t zone); 202 212 213 extern int 214 mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones); 215 216 extern int 217 mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes); 218 219 203 220 /* mfs_utils.c */ 204 221 extern uint16_t -
uspace/srv/fs/mfs/mfs_balloc.c
r224174f r2b3e8840 44 44 mfs_alloc_bit(struct mfs_instance *inst, uint32_t *idx, bmap_id_t bid); 45 45 46 static int 47 mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free); 48 49 46 50 /**Allocate a new inode. 47 51 * … … 102 106 103 107 return mfs_free_bit(inst, zone, BMAP_ZONE); 108 } 109 110 /** Count the number of free zones 111 * 112 * @param inst Pointer to the instance structure. 113 * @param zones Pointer to the memory location where the result 114 * will be stored. 115 * 116 * @return EOK on success or a negative error code. 117 */ 118 int 119 mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones) 120 { 121 return mfs_count_free_bits(inst, BMAP_ZONE, zones); 122 } 123 124 /** Count the number of free inodes 125 * 126 * @param inst Pointer to the instance structure. 127 * @param zones Pointer to the memory location where the result 128 * will be stored. 129 * 130 * @return EOK on success or a negative error code. 131 */ 132 133 int 134 mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes) 135 { 136 return mfs_count_free_bits(inst, BMAP_INODE, inodes); 137 } 138 139 /** Count the number of free bits in a bitmap 140 * 141 * @param inst Pointer to the instance structure. 142 * @param bid Type of the bitmap (inode or zone). 143 * @param free Pointer to the memory location where the result 144 * will be stores. 145 * 146 * @return EOK on success or a negative error code. 147 */ 148 static int 149 mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free) 150 { 151 int r; 152 unsigned start_block; 153 unsigned long nblocks; 154 unsigned long nbits; 155 unsigned long block; 156 unsigned long free_bits = 0; 157 bitchunk_t chunk; 158 size_t const bitchunk_bits = sizeof(bitchunk_t) * 8; 159 block_t *b; 160 struct mfs_sb_info *sbi = inst->sbi; 161 162 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 163 nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid); 164 nbits = MFS_BMAP_SIZE_BITS(sbi, bid); 165 166 for (block = 0; block < nblocks; ++block) { 167 r = block_get(&b, inst->service_id, block + start_block, 168 BLOCK_FLAGS_NONE); 169 if (r != EOK) 170 return r; 171 172 size_t i; 173 bitchunk_t *data = (bitchunk_t *) b->data; 174 175 /* Read the bitmap block, chunk per chunk, 176 * counting the zero bits. 177 */ 178 for (i = 0; i < sbi->block_size / sizeof(bitchunk_t); ++i) { 179 chunk = conv32(sbi->native, data[i]); 180 181 size_t bit; 182 for (bit = 0; bit < bitchunk_bits && nbits > 0; 183 ++bit, --nbits) { 184 if (!(chunk & (1 << bit))) 185 free_bits++; 186 } 187 188 if (nbits == 0) 189 break; 190 } 191 192 r = block_put(b); 193 if (r != EOK) 194 return r; 195 } 196 197 *free = free_bits; 198 assert(nbits == 0); 199 200 return EOK; 104 201 } 105 202 … … 124 221 sbi = inst->sbi; 125 222 223 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 224 126 225 if (bid == BMAP_ZONE) { 127 226 search = &sbi->zsearch; 128 start_block = 2 + sbi->ibmap_blocks;129 227 if (idx > sbi->nzones) { 130 228 printf(NAME ": Error! Trying to free beyond the " … … 135 233 /* bid == BMAP_INODE */ 136 234 search = &sbi->isearch; 137 start_block = 2;138 235 if (idx > sbi->ninodes) { 139 236 printf(NAME ": Error! Trying to free beyond the " … … 192 289 sbi = inst->sbi; 193 290 291 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 292 limit = MFS_BMAP_SIZE_BITS(sbi, bid); 293 nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid); 294 194 295 if (bid == BMAP_ZONE) { 195 296 search = &sbi->zsearch; 196 start_block = 2 + sbi->ibmap_blocks;197 nblocks = sbi->zbmap_blocks;198 limit = sbi->nzones - sbi->firstdatazone - 1;199 297 } else { 200 298 /* bid == BMAP_INODE */ 201 299 search = &sbi->isearch; 202 start_block = 2;203 nblocks = sbi->ibmap_blocks;204 limit = sbi->ninodes - 1;205 300 } 206 301 bits_per_block = sbi->block_size * 8;
Note:
See TracChangeset
for help on using the changeset viewer.