Lines Matching refs:fs
44 static void ext2fs_swap_bitmap(ext2_filsys fs, char *bitmap, int nbytes)
54 static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
66 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
68 if (!(fs->flags & EXT2_FLAG_RW))
70 if (EXT2_HAS_COMPAT_FEATURE(fs->super,
76 block_bitmap = fs->block_map->bitmap;
77 block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
78 retval = ext2fs_get_mem(fs->blocksize, &block_buf);
81 memset(block_buf, 0xff, fs->blocksize);
84 inode_bitmap = fs->inode_map->bitmap;
86 ((EXT2_INODES_PER_GROUP(fs->super)+7) / 8);
87 retval = ext2fs_get_mem(fs->blocksize, &inode_buf);
90 memset(inode_buf, 0xff, fs->blocksize);
93 for (i = 0; i < fs->group_desc_count; i++) {
97 if (lazy_flag && fs->group_desc[i].bg_flags &
102 if (i == fs->group_desc_count - 1) {
104 nbits = ((fs->super->s_blocks_count
105 - fs->super->s_first_data_block)
106 % EXT2_BLOCKS_PER_GROUP(fs->super));
108 for (j = nbits; j < fs->blocksize * 8; j++)
111 blk = fs->group_desc[i].bg_block_bitmap;
114 if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
115 (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)))
116 ext2fs_swap_bitmap(fs, block_buf,
119 retval = io_channel_write_blk(fs->io, blk, 1,
131 if (lazy_flag && fs->group_desc[i].bg_flags &
136 blk = fs->group_desc[i].bg_inode_bitmap;
139 if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
140 (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)))
141 ext2fs_swap_bitmap(fs, inode_buf,
144 retval = io_channel_write_blk(fs->io, blk, 1,
154 fs->flags &= ~EXT2_FLAG_BB_DIRTY;
158 fs->flags &= ~EXT2_FLAG_IB_DIRTY;
164 static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
170 int block_nbytes = (int) EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
171 int inode_nbytes = (int) EXT2_INODES_PER_GROUP(fs->super) / 8;
175 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
177 fs->write_bitmaps = ext2fs_write_bitmaps;
179 if (EXT2_HAS_COMPAT_FEATURE(fs->super,
183 retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf);
187 if (fs->block_map)
188 ext2fs_free_block_bitmap(fs->block_map);
189 sprintf(buf, "block bitmap for %s", fs->device_name);
190 retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map);
193 block_bitmap = fs->block_map->bitmap;
196 if (fs->inode_map)
197 ext2fs_free_inode_bitmap(fs->inode_map);
198 sprintf(buf, "inode bitmap for %s", fs->device_name);
199 retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map);
202 inode_bitmap = fs->inode_map->bitmap;
206 if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
208 blk = (fs->image_header->offset_inodemap /
209 fs->blocksize);
210 retval = io_channel_read_blk(fs->image_io, blk,
211 -(inode_nbytes * fs->group_desc_count),
217 blk = (fs->image_header->offset_blockmap /
218 fs->blocksize);
219 retval = io_channel_read_blk(fs->image_io, blk,
220 -(block_nbytes * fs->group_desc_count),
228 for (i = 0; i < fs->group_desc_count; i++) {
230 blk = fs->group_desc[i].bg_block_bitmap;
231 if (lazy_flag && fs->group_desc[i].bg_flags &
235 retval = io_channel_read_blk(fs->io, blk,
242 if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
243 (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)))
244 ext2fs_swap_bitmap(fs, block_bitmap, block_nbytes);
251 blk = fs->group_desc[i].bg_inode_bitmap;
252 if (lazy_flag && fs->group_desc[i].bg_flags &
256 retval = io_channel_read_blk(fs->io, blk,
263 if (!((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
264 (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)))
265 ext2fs_swap_bitmap(fs, inode_bitmap, inode_nbytes);
276 ext2fs_free_mem(&fs->block_map);
277 fs->block_map = 0;
280 ext2fs_free_mem(&fs->inode_map);
281 fs->inode_map = 0;
288 errcode_t ext2fs_read_inode_bitmap(ext2_filsys fs)
290 return read_bitmaps(fs, 1, 0);
293 errcode_t ext2fs_read_block_bitmap(ext2_filsys fs)
295 return read_bitmaps(fs, 0, 1);
298 errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
300 return write_bitmaps(fs, 1, 0);
303 errcode_t ext2fs_write_block_bitmap (ext2_filsys fs)
305 return write_bitmaps(fs, 0, 1);
308 errcode_t ext2fs_read_bitmaps(ext2_filsys fs)
310 if (fs->inode_map && fs->block_map)
313 return read_bitmaps(fs, !fs->inode_map, !fs->block_map);
316 errcode_t ext2fs_write_bitmaps(ext2_filsys fs)
318 int do_inode = fs->inode_map && ext2fs_test_ib_dirty(fs);
319 int do_block = fs->block_map && ext2fs_test_bb_dirty(fs);
324 return write_bitmaps(fs, do_inode, do_block);