Changes in uspace/srv/fs/mfs/mfs_balloc.c [9d58539:1eaa3cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/mfs/mfs_balloc.c
r9d58539 r1eaa3cf 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 * … … 84 88 { 85 89 int r = mfs_alloc_bit(inst, zone, BMAP_ZONE); 90 if (r != EOK) 91 return r; 92 93 /* Update the cached number of free zones */ 94 struct mfs_sb_info *sbi = inst->sbi; 95 if (sbi->nfree_zones_valid) 96 sbi->nfree_zones--; 86 97 87 98 *zone += inst->sbi->firstdatazone - 1; … … 99 110 mfs_free_zone(struct mfs_instance *inst, uint32_t zone) 100 111 { 112 int r; 113 101 114 zone -= inst->sbi->firstdatazone - 1; 102 115 103 return mfs_free_bit(inst, zone, BMAP_ZONE); 116 r = mfs_free_bit(inst, zone, BMAP_ZONE); 117 if (r != EOK) 118 return r; 119 120 /* Update the cached number of free zones */ 121 struct mfs_sb_info *sbi = inst->sbi; 122 if (sbi->nfree_zones_valid) 123 sbi->nfree_zones++; 124 125 return r; 126 } 127 128 /** Count the number of free zones 129 * 130 * @param inst Pointer to the instance structure. 131 * @param zones Pointer to the memory location where the result 132 * will be stored. 133 * 134 * @return EOK on success or a negative error code. 135 */ 136 int 137 mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones) 138 { 139 return mfs_count_free_bits(inst, BMAP_ZONE, zones); 140 } 141 142 /** Count the number of free inodes 143 * 144 * @param inst Pointer to the instance structure. 145 * @param zones Pointer to the memory location where the result 146 * will be stored. 147 * 148 * @return EOK on success or a negative error code. 149 */ 150 151 int 152 mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes) 153 { 154 return mfs_count_free_bits(inst, BMAP_INODE, inodes); 155 } 156 157 /** Count the number of free bits in a bitmap 158 * 159 * @param inst Pointer to the instance structure. 160 * @param bid Type of the bitmap (inode or zone). 161 * @param free Pointer to the memory location where the result 162 * will be stores. 163 * 164 * @return EOK on success or a negative error code. 165 */ 166 static int 167 mfs_count_free_bits(struct mfs_instance *inst, bmap_id_t bid, uint32_t *free) 168 { 169 int r; 170 unsigned start_block; 171 unsigned long nblocks; 172 unsigned long nbits; 173 unsigned long block; 174 unsigned long free_bits = 0; 175 bitchunk_t chunk; 176 size_t const bitchunk_bits = sizeof(bitchunk_t) * 8; 177 block_t *b; 178 struct mfs_sb_info *sbi = inst->sbi; 179 180 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 181 nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid); 182 nbits = MFS_BMAP_SIZE_BITS(sbi, bid); 183 184 for (block = 0; block < nblocks; ++block) { 185 r = block_get(&b, inst->service_id, block + start_block, 186 BLOCK_FLAGS_NONE); 187 if (r != EOK) 188 return r; 189 190 size_t i; 191 bitchunk_t *data = (bitchunk_t *) b->data; 192 193 /* Read the bitmap block, chunk per chunk, 194 * counting the zero bits. 195 */ 196 for (i = 0; i < sbi->block_size / sizeof(bitchunk_t); ++i) { 197 chunk = conv32(sbi->native, data[i]); 198 199 size_t bit; 200 for (bit = 0; bit < bitchunk_bits && nbits > 0; 201 ++bit, --nbits) { 202 if (!(chunk & (1 << bit))) 203 free_bits++; 204 } 205 206 if (nbits == 0) 207 break; 208 } 209 210 r = block_put(b); 211 if (r != EOK) 212 return r; 213 } 214 215 *free = free_bits; 216 assert(nbits == 0); 217 218 return EOK; 104 219 } 105 220 … … 124 239 sbi = inst->sbi; 125 240 241 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 242 126 243 if (bid == BMAP_ZONE) { 127 244 search = &sbi->zsearch; 128 start_block = 2 + sbi->ibmap_blocks;129 245 if (idx > sbi->nzones) { 130 printf(NAME ": Error! Trying to free beyond the " \246 printf(NAME ": Error! Trying to free beyond the " 131 247 "bitmap max size\n"); 132 248 return -1; … … 135 251 /* bid == BMAP_INODE */ 136 252 search = &sbi->isearch; 137 start_block = 2;138 253 if (idx > sbi->ninodes) { 139 printf(NAME ": Error! Trying to free beyond the " \254 printf(NAME ": Error! Trying to free beyond the " 140 255 "bitmap max size\n"); 141 256 return -1; … … 192 307 sbi = inst->sbi; 193 308 309 start_block = MFS_BMAP_START_BLOCK(sbi, bid); 310 limit = MFS_BMAP_SIZE_BITS(sbi, bid); 311 nblocks = MFS_BMAP_SIZE_BLOCKS(sbi, bid); 312 194 313 if (bid == BMAP_ZONE) { 195 314 search = &sbi->zsearch; 196 start_block = 2 + sbi->ibmap_blocks;197 nblocks = sbi->zbmap_blocks;198 limit = sbi->nzones - sbi->firstdatazone - 1;199 315 } else { 200 316 /* bid == BMAP_INODE */ 201 317 search = &sbi->isearch; 202 start_block = 2;203 nblocks = sbi->ibmap_blocks;204 limit = sbi->ninodes;205 318 } 206 319 bits_per_block = sbi->block_size * 8;
Note:
See TracChangeset
for help on using the changeset viewer.