Lines Matching refs:fs
32 blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
38 if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) ||
39 (i < fs->super->s_first_meta_bg))
42 bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
43 if (ext2fs_bg_has_super(fs, bg))
45 ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
54 if (group_block != fs->super->s_first_data_block &&
55 ((ret_blk + fs->super->s_blocks_per_group) <
56 fs->super->s_blocks_count))
57 ret_blk += fs->super->s_blocks_per_group;
85 ext2_filsys fs;
99 retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs);
103 memset(fs, 0, sizeof(struct struct_ext2_filsys));
104 fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
105 fs->flags = flags;
107 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
108 fs->umask = 022;
109 retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name);
112 strcpy(fs->device_name, name);
113 cp = strchr(fs->device_name, '?');
126 retval = manager->open(fs->device_name, io_flags, &fs->io);
130 (retval = io_channel_set_options(fs->io, io_options)))
132 fs->image_io = fs->io;
133 fs->io->app_data = fs;
134 retval = ext2fs_get_memalign(SUPERBLOCK_SIZE, 512, &fs->super);
139 &fs->image_header);
142 retval = io_channel_read_blk(fs->io, 0,
144 fs->image_header);
147 if (fs->image_header->magic_number != EXT2_ET_MAGIC_E2IMAGE)
150 block_size = fs->image_header->fs_blocksize;
167 io_channel_set_blksize(fs->io, block_size);
169 fs->orig_super = 0;
171 io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET);
174 retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->orig_super);
178 retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE,
179 fs->super);
182 if (fs->orig_super)
183 memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
186 fs->flags |= EXT2_FLAG_SWAP_BYTES;
187 ext2fs_swap_super(fs->super);
189 if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
195 if (fs->super->s_magic != EXT2_SUPER_MAGIC) {
199 if (fs->super->s_rev_level > EXT2_LIB_CURRENT_REV) {
208 features = fs->super->s_feature_incompat;
218 features = fs->super->s_feature_ro_compat;
230 (fs->super->s_feature_incompat &
237 if ((fs->super->s_log_block_size + EXT2_MIN_BLOCK_LOG_SIZE) >
242 fs->blocksize = EXT2_BLOCK_SIZE(fs->super);
243 if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) {
247 fs->fragsize = EXT2_FRAG_SIZE(fs->super);
248 fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) *
249 EXT2_INODE_SIZE(fs->super) +
250 EXT2_BLOCK_SIZE(fs->super) - 1) /
251 EXT2_BLOCK_SIZE(fs->super));
253 if (block_size != fs->blocksize) {
261 io_channel_set_blksize(fs->io, fs->blocksize);
267 if (fs->super->s_feature_incompat &
269 fs->group_desc_count = 0;
270 *ret_fs = fs;
274 if (EXT2_INODES_PER_GROUP(fs->super) == 0) {
282 blocks_per_group = EXT2_BLOCKS_PER_GROUP(fs->super);
284 blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(fs->super) ||
285 fs->inode_blocks_per_group > EXT2_MAX_INODES_PER_GROUP(fs->super) ||
286 EXT2_DESC_PER_BLOCK(fs->super) == 0 ||
287 fs->super->s_first_data_block >= fs->super->s_blocks_count) {
291 fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
292 fs->super->s_first_data_block,
294 if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
295 fs->super->s_inodes_count) {
299 fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
300 EXT2_DESC_PER_BLOCK(fs->super));
301 retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
302 &fs->group_desc);
306 group_block = fs->super->s_first_data_block;
307 dest = (char *) fs->group_desc;
308 groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
309 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
310 first_meta_bg = fs->super->s_first_meta_bg;
312 first_meta_bg = fs->desc_blocks;
314 retval = io_channel_read_blk(fs->io, group_block+1,
323 dest += fs->blocksize*first_meta_bg;
325 for (i=first_meta_bg ; i < fs->desc_blocks; i++) {
326 blk = ext2fs_descriptor_block_loc(fs, group_block, i);
327 retval = io_channel_read_blk(fs->io, blk, 1, dest);
335 dest += fs->blocksize;
338 fs->stride = fs->super->s_raid_stride;
344 if (superblock > 1 && EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
347 for (i = 0, gd = fs->group_desc; i < fs->group_desc_count;
353 ext2fs_mark_super_dirty(fs);
356 fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR;
357 *ret_fs = fs;
361 *ret_fs = fs;
363 ext2fs_free(fs);
372 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io)
374 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
377 *old_io = (fs->image_io == fs->io) ? 0 : fs->io;
382 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io)
384 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
386 fs->io = new_io ? new_io : fs->image_io;
390 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io)
392 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
394 fs->io = fs->image_io = new_io;
395 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_RW |
397 fs->flags &= ~EXT2_FLAG_IMAGE_FILE;