Home | History | Annotate | Download | only in ext2fs

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 = (fs->blocksize / sizeof (struct ext2_group_desc)) * i;
43 if (ext2fs_bg_has_super(fs, bg))
45 ret_blk = (fs->super->s_first_data_block + has_super +
46 (bg * fs->super->s_blocks_per_group));
55 if (group_block != fs->super->s_first_data_block &&
56 ((ret_blk + fs->super->s_blocks_per_group) <
57 fs->super->s_blocks_count))
58 ret_blk += fs->super->s_blocks_per_group;
86 ext2_filsys fs;
97 retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs);
101 memset(fs, 0, sizeof(struct struct_ext2_filsys));
102 fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
103 fs->flags = flags;
105 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
106 fs->umask = 022;
107 retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name);
110 strcpy(fs->device_name, name);
111 cp = strchr(fs->device_name, '?');
122 retval = manager->open(fs->device_name, io_flags, &fs->io);
126 (retval = io_channel_set_options(fs->io, io_options)))
128 fs->image_io = fs->io;
129 fs->io->app_data = fs;
130 retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->super);
135 &fs->image_header);
138 retval = io_channel_read_blk(fs->io, 0,
140 fs->image_header);
143 if (fs->image_header->magic_number != EXT2_ET_MAGIC_E2IMAGE)
146 block_size = fs->image_header->fs_blocksize;
163 io_channel_set_blksize(fs->io, block_size);
165 fs->orig_super = 0;
167 io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET);
170 retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->orig_super);
174 retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE,
175 fs->super);
178 if (fs->orig_super)
179 memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
182 if ((fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ||
183 (fs->flags & EXT2_FLAG_SWAP_BYTES)) {
184 fs->flags |= EXT2_FLAG_SWAP_BYTES;
186 ext2fs_swap_super(fs->super);
190 if (fs->super->s_magic != EXT2_SUPER_MAGIC) {
194 if (fs->super->s_rev_level > EXT2_LIB_CURRENT_REV) {
203 features = fs->super->s_feature_incompat;
213 features = fs->super->s_feature_ro_compat;
225 (fs->super->s_feature_incompat &
232 fs->blocksize = EXT2_BLOCK_SIZE(fs->super);
233 if (fs->blocksize == 0) {
237 if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) {
241 fs->fragsize = EXT2_FRAG_SIZE(fs->super);
242 fs->inode_blocks_per_group = ((fs->super->s_inodes_per_group *
243 EXT2_INODE_SIZE(fs->super) +
244 EXT2_BLOCK_SIZE(fs->super) - 1) /
245 EXT2_BLOCK_SIZE(fs->super));
247 if (block_size != fs->blocksize) {
255 io_channel_set_blksize(fs->io, fs->blocksize);
261 if (fs->super->s_feature_incompat &
263 fs->group_desc_count = 0;
264 *ret_fs = fs;
271 blocks_per_group = EXT2_BLOCKS_PER_GROUP(fs->super);
273 blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(fs->super) ||
274 fs->inode_blocks_per_group > EXT2_MAX_INODES_PER_GROUP(fs->super)) {
278 fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
279 fs->super->s_first_data_block,
281 fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
282 EXT2_DESC_PER_BLOCK(fs->super));
283 retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
284 &fs->group_desc);
288 group_block = fs->super->s_first_data_block;
289 dest = (char *) fs->group_desc;
290 groups_per_block = fs->blocksize / sizeof(struct ext2_group_desc);
291 for (i=0 ; i < fs->desc_blocks; i++) {
292 blk = ext2fs_descriptor_block_loc(fs, group_block, i);
293 retval = io_channel_read_blk(fs->io, blk, 1, dest);
297 if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
303 dest += fs->blocksize;
306 fs->stride = fs->super->s_raid_stride;
308 fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR;
309 *ret_fs = fs;
313 *ret_fs = fs;
315 ext2fs_free(fs);
324 errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io)
326 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
329 *old_io = (fs->image_io == fs->io) ? 0 : fs->io;
334 errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io)
336 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
338 fs->io = new_io ? new_io : fs->image_io;
342 errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io)
344 if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
346 fs->io = fs->image_io = new_io;
347 fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_RW |
349 fs->flags &= ~EXT2_FLAG_IMAGE_FILE;