这篇教程C++ EXT2_BLOCK_SIZE函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中EXT2_BLOCK_SIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ EXT2_BLOCK_SIZE函数的具体用法?C++ EXT2_BLOCK_SIZE怎么用?C++ EXT2_BLOCK_SIZE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了EXT2_BLOCK_SIZE函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ext2fs_read_inodestatic quik_err_text2fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode){ struct ext2_block_group blkgrp; struct ext2_sblock *sblock = &data->sblock; int inodes_per_block; quik_err_t err; unsigned int blkno; unsigned int blkoff;#ifdef DEBUG printk ("ext2fs read inode %d, inode_size %d/n", ino, inode_size);#endif /* It is easier to calculate if the first inode is 0. */ ino--; err = ext2fs_blockgroup(data, ino / __le32_to_cpu (sblock->inodes_per_group), &blkgrp); if (err != ERR_NONE) { return err; } inodes_per_block = EXT2_BLOCK_SIZE(data) / inode_size; blkno = __le32_to_cpu(blkgrp.inode_table_id) + (ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block; blkoff = (ino % inodes_per_block) * inode_size;#ifdef DEBUG printk ("ext2fs read inode blkno %d blkoff %d/n", blkno, blkoff);#endif /* Read the inode. */ err = part_read(data->part, blkno << LOG2_EXT2_BLOCK_SIZE (data), blkoff, sizeof(struct ext2_inode), (char *) inode); if (err != ERR_NONE) { return err; } return ERR_NONE;}
开发者ID:andreiw,项目名称:iQUIK,代码行数:44,
示例2: EXT2_BLOCK_SIZEstatic int ext2fs_blockgroup (struct ext2_data *data, int group, struct ext2_block_group *blkgrp) { unsigned int blkno; unsigned int blkoff; unsigned int desc_per_blk; desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group); blkno = __le32_to_cpu(data->sblock.first_data_block) + 1 + group / desc_per_blk; blkoff = (group % desc_per_blk) * sizeof(struct ext2_block_group);#ifdef DEBUG printf ("ext2fs read %d group descriptor (blkno %d blkoff %d)/n", group, blkno, blkoff);#endif return (ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE(data), blkoff, sizeof(struct ext2_block_group), (char *)blkgrp));}
开发者ID:Scorpio92,项目名称:mstar6a918,代码行数:19,
示例3: ext4fs_get_indir_blockint ext4fs_get_indir_block(struct ext2fs_node *node, struct ext4fs_indir_block *indir, int blkno){ struct ext_filesystem *fs = node->data->fs; int blksz; int ret; blksz = EXT2_BLOCK_SIZE(node->data); if (indir->blkno == blkno) return 0; ret = ext4fs_devread(fs, blkno, 0, blksz, (void *)indir->data); if (ret) { dev_err(fs->dev, "** SI ext2fs read block (indir 1)" "failed. **/n"); return ret; } return 0;}
开发者ID:AshishNamdev,项目名称:barebox,代码行数:20,
示例4: printfstatic int ext2fs_read_inode (struct ext2_data *data, int ino, struct ext2_inode *inode) { struct ext2_block_group blkgrp; struct ext2_sblock *sblock = &data->sblock; int inodes_per_block; int status; unsigned int blkno; unsigned int blkoff; /* It is easier to calculate if the first inode is 0. */ ino--;#ifdef DEBUG printf ("ext2fs read inode %d/n", ino);#endif status = ext2fs_blockgroup (data, ino / __le32_to_cpu (sblock->inodes_per_group), &blkgrp); if (status == 0) { return (0); } inodes_per_block = EXT2_BLOCK_SIZE (data) / 128; blkno = (ino % __le32_to_cpu (sblock->inodes_per_group)) / inodes_per_block; blkoff = (ino % __le32_to_cpu (sblock->inodes_per_group)) % inodes_per_block;#ifdef DEBUG printf ("ext2fs read inode blkno %d blkoff %d/n", blkno, blkoff);#endif /* Read the inode. */ status = ext2fs_devread (((__le32_to_cpu (blkgrp.inode_table_id) + blkno) << LOG2_EXT2_BLOCK_SIZE (data)), sizeof (struct ext2_inode) * blkoff, sizeof (struct ext2_inode), (char *) inode); if (status == 0) { return (0); } return (1);}
开发者ID:BillTheBest,项目名称:pandorabox,代码行数:40,
示例5: grub_ext4_find_leafstatic struct grub_ext4_extent_header *grub_ext4_find_leaf (struct grub_ext2_data *data, char *buf, struct grub_ext4_extent_header *ext_block, grub_uint32_t fileblock){ struct grub_ext4_extent_idx *index; while (1) { int i; grub_disk_addr_t block; index = (struct grub_ext4_extent_idx *) (ext_block + 1); if (grub_le_to_cpu16(ext_block->magic) != EXT4_EXT_MAGIC) return 0; if (ext_block->depth == 0) return ext_block; for (i = 0; i < grub_le_to_cpu16 (ext_block->entries); i++) { if (fileblock < grub_le_to_cpu32(index[i].block)) break; } if (--i < 0) return 0; block = grub_le_to_cpu16 (index[i].leaf_hi); block = (block << 32) + grub_le_to_cpu32 (index[i].leaf); if (grub_disk_read (data->disk, block << LOG2_EXT2_BLOCK_SIZE (data), 0, EXT2_BLOCK_SIZE(data), buf)) return 0; ext_block = (struct grub_ext4_extent_header *) buf; }}
开发者ID:TemmeR,项目名称:grub2,代码行数:39,
示例6: ext2_mountext2_VOLUME* ext2_mount(int fd){ ext2_VOLUME *volume; struct ext2_super_block *super; char *buffer; super = (struct ext2_super_block*)malloc(sizeof(struct ext2_super_block)); if (super == NULL) return NULL; ext2_get_super(fd, super); if (super->s_magic != EXT2_SUPER_MAGIC) { free(super); return NULL; } buffer = (char*)malloc(EXT2_BLOCK_SIZE(super)); if (buffer == NULL) { free(super); return NULL; } volume = (ext2_VOLUME*)malloc(sizeof(ext2_VOLUME)); if (volume == NULL) { free(super); free(buffer); return NULL; } volume->buffer = buffer; volume->fd = fd; volume->super = super; volume->current = -1; ext2_read_block(volume, 0); return volume;}
开发者ID:3a9LL,项目名称:panda,代码行数:38,
示例7: EXT2_BLOCK_SIZEstatic struct ext4_extent_header *ext4fs_get_extent_block(struct ext2_data *data, char *buf, struct ext4_extent_header *ext_block, uint32_t fileblock, int log2_blksz){ struct ext4_extent_idx *index; unsigned long long block; struct ext_filesystem *fs = data->fs; int blksz = EXT2_BLOCK_SIZE(data); int i, ret; while (1) { index = (struct ext4_extent_idx *)(ext_block + 1); if (le16_to_cpu(ext_block->eh_magic) != EXT4_EXT_MAGIC) return 0; if (ext_block->eh_depth == 0) return ext_block; i = -1; do { i++; if (i >= le16_to_cpu(ext_block->eh_entries)) break; } while (fileblock >= le32_to_cpu(index[i].ei_block)); if (--i < 0) return 0; block = le16_to_cpu(index[i].ei_leaf_hi); block = (block << 32) + le32_to_cpu(index[i].ei_leaf_lo); ret = ext4fs_devread(fs, block << log2_blksz, 0, blksz, buf); if (ret) return NULL; else ext_block = (struct ext4_extent_header *)buf; }}
开发者ID:zandar,项目名称:barebox,代码行数:38,
示例8: move_metadata_blockstatic int move_metadata_block(struct defrag_ctx *c, struct inode *inode, blk64_t from, blk64_t to){ struct ext3_extent_header *header = malloc(EXT2_BLOCK_SIZE(&c->sb)); /* Whether it's a leaf or an index doesn't matter for the logical block address */ struct ext3_extent *extents = (void *)(header + 1); __u32 logical_block; int ret; ret = read_block(c, header, from); if (ret) goto out_error; ret = write_block(c, header, to); if (ret) goto out_error; logical_block = extents->ee_block; free(header); return update_metadata_move(c, inode, from, to, logical_block, 0);out_error: free(header); return ret;}
开发者ID:ennoruijters,项目名称:e2defrag,代码行数:24,
示例9: ext2fs_read_blockstatic int ext2fs_read_block(struct ext2fs_node *node, int fileblock){ struct ext2_data *data = node->data; struct ext2_inode *inode = &node->inode; int blknr; int blksz = EXT2_BLOCK_SIZE (data); int log2_blksz = LOG2_EXT2_BLOCK_SIZE (data); int status; /* Direct blocks. */ if (fileblock < INDIRECT_BLOCKS) { blknr = __le32_to_cpu (inode->b.blocks.dir_blocks[fileblock]); } /* Indirect. */ else if (fileblock < (INDIRECT_BLOCKS + (blksz / 4))) { if (indir1_block == NULL) { indir1_block = (uint32_t *) malloc (blksz); if (indir1_block == NULL) { printf ("** ext2fs read block (indir 1) malloc failed. **/n"); return (-1); } indir1_size = blksz; indir1_blkno = -1; } if (blksz != indir1_size) { free (indir1_block); indir1_block = NULL; indir1_size = 0; indir1_blkno = -1; indir1_block = (uint32_t *) malloc (blksz); if (indir1_block == NULL) { printf ("** ext2fs read block (indir 1) malloc failed. **/n"); return (-1); } indir1_size = blksz; } if ((__le32_to_cpu (inode->b.blocks.indir_block) << log2_blksz) != indir1_blkno) { status = ext2fs_devread (__le32_to_cpu(inode->b.blocks.indir_block) << log2_blksz, 0, blksz, (char *) indir1_block); if (status == 0) { printf ("** ext2fs read block (indir 1) failed. **/n"); return (0); } indir1_blkno = __le32_to_cpu (inode->b.blocks. indir_block) << log2_blksz; } blknr = __le32_to_cpu (indir1_block [fileblock - INDIRECT_BLOCKS]); } /* Double indirect. */ else if (fileblock < (INDIRECT_BLOCKS + (blksz / 4 * (blksz / 4 + 1)))) { unsigned int perblock = blksz / 4; unsigned int rblock = fileblock - (INDIRECT_BLOCKS + blksz / 4); if (indir1_block == NULL) { indir1_block = (uint32_t *) malloc (blksz); if (indir1_block == NULL) { printf ("** ext2fs read block (indir 2 1) malloc failed. **/n"); return (-1); } indir1_size = blksz; indir1_blkno = -1; } if (blksz != indir1_size) { free (indir1_block); indir1_block = NULL; indir1_size = 0; indir1_blkno = -1; indir1_block = (uint32_t *) malloc (blksz); if (indir1_block == NULL) { printf ("** ext2fs read block (indir 2 1) malloc failed. **/n"); return (-1); } indir1_size = blksz; } if ((__le32_to_cpu (inode->b.blocks.double_indir_block) << log2_blksz) != indir1_blkno) { status = ext2fs_devread (__le32_to_cpu(inode->b.blocks.double_indir_block) << log2_blksz, 0, blksz, (char *) indir1_block); if (status == 0) { printf ("** ext2fs read block (indir 2 1) failed. **/n"); return (-1); } indir1_blkno = __le32_to_cpu (inode->b.blocks.double_indir_block) << log2_blksz; } if (indir2_block == NULL) { indir2_block = (uint32_t *) malloc (blksz); if (indir2_block == NULL) { printf ("** ext2fs read block (indir 2 2) malloc failed. **/n"); return (-1); } indir2_size = blksz;//.........这里部分代码省略.........
开发者ID:Scorpio92,项目名称:mstar6a918,代码行数:101,
示例10: ext2fs_write_inode_fullerrcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize){ blk64_t block_nr; unsigned long group, block, offset; errcode_t retval = 0; struct ext2_inode_large *w_inode; char *ptr; unsigned i; int clen; int length = EXT2_INODE_SIZE(fs->super); EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); /* Check to see if user provided an override function */ if (fs->write_inode) { retval = (fs->write_inode)(fs, ino, inode); if (retval != EXT2_ET_CALLBACK_NOTHANDLED) return retval; } if ((ino == 0) || (ino > fs->super->s_inodes_count)) return EXT2_ET_BAD_INODE_NUM; /* Prepare our shadow buffer for read/modify/byteswap/write */ retval = ext2fs_get_mem(length, &w_inode); if (retval) return retval; if (bufsize < length) { int old_flags = fs->flags; fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; retval = ext2fs_read_inode_full(fs, ino, (struct ext2_inode *)w_inode, length); fs->flags = (old_flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) | (fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS); if (retval) goto errout; } /* Check to see if the inode cache needs to be updated */ if (fs->icache) { for (i=0; i < fs->icache->cache_size; i++) { if (fs->icache->cache[i].ino == ino) { memcpy(fs->icache->cache[i].inode, inode, (bufsize > length) ? length : bufsize); break; } } } else { retval = ext2fs_create_inode_cache(fs, 4); if (retval) goto errout; } memcpy(w_inode, inode, (bufsize > length) ? length : bufsize); if (!(fs->flags & EXT2_FLAG_RW)) { retval = EXT2_ET_RO_FILSYS; goto errout; }#ifdef WORDS_BIGENDIAN ext2fs_swap_inode_full(fs, w_inode, w_inode, 1, length);#endif retval = ext2fs_inode_csum_set(fs, ino, w_inode); if (retval) goto errout; group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * EXT2_INODE_SIZE(fs->super); block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); if (!ext2fs_inode_table_loc(fs, (unsigned) group)) { retval = EXT2_ET_MISSING_INODE_TABLE; goto errout; } block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block; offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); ptr = (char *) w_inode; while (length) { clen = length; if ((offset + length) > fs->blocksize) clen = fs->blocksize - offset; if (fs->icache->buffer_blk != block_nr) { retval = io_channel_read_blk64(fs->io, block_nr, 1, fs->icache->buffer); if (retval) goto errout; fs->icache->buffer_blk = block_nr; } memcpy((char *) fs->icache->buffer + (unsigned) offset, ptr, clen);//.........这里部分代码省略.........
开发者ID:MIPS,项目名称:external-e2fsprogs,代码行数:101,
示例11: list_descstatic void list_desc (ext2_filsys fs){ unsigned long i; blk64_t first_block, last_block; blk64_t super_blk, old_desc_blk, new_desc_blk; char *block_bitmap=NULL, *inode_bitmap=NULL; const char *units = _("blocks"); int inode_blocks_per_group, old_desc_blocks, reserved_gdt; int block_nbytes, inode_nbytes; int has_super; blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); ext2_ino_t ino_itr = 1; errcode_t retval; if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_BIGALLOC)) units = _("clusters"); block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; if (fs->block_map) block_bitmap = malloc(block_nbytes); if (fs->inode_map) inode_bitmap = malloc(inode_nbytes); inode_blocks_per_group = ((fs->super->s_inodes_per_group * EXT2_INODE_SIZE(fs->super)) + EXT2_BLOCK_SIZE(fs->super) - 1) / EXT2_BLOCK_SIZE(fs->super); reserved_gdt = fs->super->s_reserved_gdt_blocks; fputc('/n', stdout); first_block = fs->super->s_first_data_block; if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) old_desc_blocks = fs->super->s_first_meta_bg; else old_desc_blocks = fs->desc_blocks; for (i = 0; i < fs->group_desc_count; i++) { first_block = ext2fs_group_first_block2(fs, i); last_block = ext2fs_group_last_block2(fs, i); ext2fs_super_and_bgd_loc2(fs, i, &super_blk, &old_desc_blk, &new_desc_blk, 0); printf (_("Group %lu: (Blocks "), i); print_range(first_block, last_block); fputs(")", stdout); print_bg_opts(fs, i); if (ext2fs_has_group_desc_csum(fs)) { unsigned csum = ext2fs_bg_checksum(fs, i); unsigned exp_csum = ext2fs_group_desc_csum(fs, i); printf(_(" Checksum 0x%04x"), csum); if (csum != exp_csum) printf(_(" (EXPECTED 0x%04x)"), exp_csum); printf(_(", unused inodes %u/n"), ext2fs_bg_itable_unused(fs, i)); } has_super = ((i==0) || super_blk); if (has_super) { printf (_(" %s superblock at "), i == 0 ? _("Primary") : _("Backup")); print_number(super_blk); } if (old_desc_blk) { printf("%s", _(", Group descriptors at ")); print_range(old_desc_blk, old_desc_blk + old_desc_blocks - 1); if (reserved_gdt) { printf("%s", _("/n Reserved GDT blocks at ")); print_range(old_desc_blk + old_desc_blocks, old_desc_blk + old_desc_blocks + reserved_gdt - 1); } } else if (new_desc_blk) { fputc(has_super ? ',' : ' ', stdout); printf("%s", _(" Group descriptor at ")); print_number(new_desc_blk); has_super++; } if (has_super) fputc('/n', stdout); fputs(_(" Block bitmap at "), stdout); print_number(ext2fs_block_bitmap_loc(fs, i)); print_bg_rel_offset(fs, ext2fs_block_bitmap_loc(fs, i), 0, first_block, last_block); if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) printf(_(", csum 0x%08x"), ext2fs_block_bitmap_checksum(fs, i)); fputs(_(", Inode bitmap at "), stdout); print_number(ext2fs_inode_bitmap_loc(fs, i)); print_bg_rel_offset(fs, ext2fs_inode_bitmap_loc(fs, i), 0, first_block, last_block); if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) printf(_(", csum 0x%08x"), ext2fs_inode_bitmap_checksum(fs, i)); fputs(_("/n Inode table at "), stdout); print_range(ext2fs_inode_table_loc(fs, i),//.........这里部分代码省略.........
开发者ID:Gwinel,项目名称:e2fsprogs,代码行数:101,
示例12: e2fsck_get_device_sizeerrcode_t e2fsck_get_device_size(e2fsck_t ctx){ return (ext2fs_get_device_size(ctx->filesystem_name, EXT2_BLOCK_SIZE(ctx->fs->super), &ctx->num_blocks));}
开发者ID:crossmeta,项目名称:linux,代码行数:6,
示例13: get_block_size// Return the block size for a filesystem.__u32 get_block_size(void *fs) { return EXT2_BLOCK_SIZE(get_super_block(fs));}
开发者ID:HelloBinge,项目名称:EECS-343,代码行数:4,
示例14: grub_ext2_read_blockstatic grub_disk_addr_tgrub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock){ struct grub_ext2_data *data = node->data; struct grub_ext2_inode *inode = &node->inode; int blknr = -1; unsigned int blksz = EXT2_BLOCK_SIZE (data); int log2_blksz = LOG2_EXT2_BLOCK_SIZE (data); if (grub_le_to_cpu32(inode->flags) & EXT4_EXTENTS_FLAG) { char buf[EXT2_BLOCK_SIZE(data)]; struct grub_ext4_extent_header *leaf; struct grub_ext4_extent *ext; int i; leaf = grub_ext4_find_leaf (data, buf, (struct grub_ext4_extent_header *) inode->blocks.dir_blocks, fileblock); if (! leaf) { grub_error (GRUB_ERR_BAD_FS, "invalid extent"); return -1; } ext = (struct grub_ext4_extent *) (leaf + 1); for (i = 0; i < grub_le_to_cpu16 (leaf->entries); i++) { if (fileblock < grub_le_to_cpu32 (ext[i].block)) break; } if (--i >= 0) { fileblock -= grub_le_to_cpu32 (ext[i].block); if (fileblock >= grub_le_to_cpu16 (ext[i].len)) return 0; else { grub_disk_addr_t start; start = grub_le_to_cpu16 (ext[i].start_hi); start = (start << 32) + grub_le_to_cpu32 (ext[i].start); return fileblock + start; } } else { grub_error (GRUB_ERR_BAD_FS, "something wrong with extent"); return -1; } } /* Direct blocks. */ if (fileblock < INDIRECT_BLOCKS) blknr = grub_le_to_cpu32 (inode->blocks.dir_blocks[fileblock]); /* Indirect. */ else if (fileblock < INDIRECT_BLOCKS + blksz / 4) { grub_uint32_t indir[blksz / 4]; if (grub_disk_read (data->disk, ((grub_disk_addr_t) grub_le_to_cpu32 (inode->blocks.indir_block)) << log2_blksz, 0, blksz, indir)) return grub_errno; blknr = grub_le_to_cpu32 (indir[fileblock - INDIRECT_BLOCKS]); } /* Double indirect. */ else if (fileblock < INDIRECT_BLOCKS + blksz / 4 * (blksz / 4 + 1)) { unsigned int perblock = blksz / 4; unsigned int rblock = fileblock - (INDIRECT_BLOCKS + blksz / 4); grub_uint32_t indir[blksz / 4]; if (grub_disk_read (data->disk, ((grub_disk_addr_t) grub_le_to_cpu32 (inode->blocks.double_indir_block)) << log2_blksz, 0, blksz, indir)) return grub_errno; if (grub_disk_read (data->disk, ((grub_disk_addr_t) grub_le_to_cpu32 (indir[rblock / perblock])) << log2_blksz, 0, blksz, indir)) return grub_errno; blknr = grub_le_to_cpu32 (indir[rblock % perblock]); } /* triple indirect. */ else { grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "ext2fs doesn't support triple indirect blocks");//.........这里部分代码省略.........
开发者ID:TemmeR,项目名称:grub2,代码行数:101,
示例15: ext2_lblknoint ext2_lblkno( struct ext2_super_block * fs, vm_offset_t offset){ return offset / EXT2_BLOCK_SIZE(fs);}
开发者ID:rohsaini,项目名称:mkunity,代码行数:6,
示例16: ext2_blkoffint ext2_blkoff( struct ext2_super_block * fs, vm_offset_t offset){ return offset % EXT2_BLOCK_SIZE(fs);}
开发者ID:rohsaini,项目名称:mkunity,代码行数:6,
示例17: ext2_fsbtodbint ext2_fsbtodb( struct ext2_super_block *fs, int b){ return (b * EXT2_BLOCK_SIZE(fs)) / DEV_BSIZE;}
开发者ID:rohsaini,项目名称:mkunity,代码行数:6,
示例18: ext2fs_write_inode_fullerrcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize){ blk64_t block_nr; unsigned long group, block, offset; errcode_t retval = 0; struct ext2_inode_large temp_inode, *w_inode; char *ptr; int clen, i, length; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); /* Check to see if user provided an override function */ if (fs->write_inode) { retval = (fs->write_inode)(fs, ino, inode); if (retval != EXT2_ET_CALLBACK_NOTHANDLED) return retval; } /* Check to see if the inode cache needs to be updated */ if (fs->icache) { for (i=0; i < fs->icache->cache_size; i++) { if (fs->icache->cache[i].ino == ino) { fs->icache->cache[i].inode = *inode; break; } } } else { retval = create_icache(fs); if (retval) return retval; } if (!(fs->flags & EXT2_FLAG_RW)) return EXT2_ET_RO_FILSYS; if ((ino == 0) || (ino > fs->super->s_inodes_count)) return EXT2_ET_BAD_INODE_NUM; length = bufsize; if (length < EXT2_INODE_SIZE(fs->super)) length = EXT2_INODE_SIZE(fs->super); if (length > (int) sizeof(struct ext2_inode_large)) { w_inode = malloc(length); if (!w_inode) { retval = ENOMEM; goto errout; } } else w_inode = &temp_inode; memset(w_inode, 0, length);#ifdef WORDS_BIGENDIAN ext2fs_swap_inode_full(fs, w_inode, (struct ext2_inode_large *) inode, 1, bufsize);#else memcpy(w_inode, inode, bufsize);#endif group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * EXT2_INODE_SIZE(fs->super); block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); if (!ext2fs_inode_table_loc(fs, (unsigned) group)) { retval = EXT2_ET_MISSING_INODE_TABLE; goto errout; } block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block; offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); length = EXT2_INODE_SIZE(fs->super); if (length > bufsize) length = bufsize; ptr = (char *) w_inode; while (length) { clen = length; if ((offset + length) > fs->blocksize) clen = fs->blocksize - offset; if (fs->icache->buffer_blk != block_nr) { retval = io_channel_read_blk64(fs->io, block_nr, 1, fs->icache->buffer); if (retval) goto errout; fs->icache->buffer_blk = block_nr; } memcpy((char *) fs->icache->buffer + (unsigned) offset, ptr, clen); retval = io_channel_write_blk64(fs->io, block_nr, 1, fs->icache->buffer); if (retval) goto errout;//.........这里部分代码省略.........
开发者ID:keyu-lai,项目名称:Geo-tagged-Filesystem,代码行数:101,
示例19: ext2_bmaparrayintext2_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, int *runp, int *runb){ struct inode *ip; struct buf *bp; struct ext2mount *ump; struct mount *mp; struct vnode *devvp; struct indir a[NIADDR+1], *ap; daddr_t daddr; e2fs_lbn_t metalbn; int error, num, maxrun = 0, bsize; int *nump; ap = NULL; ip = VTOI(vp); mp = vp->v_mount; ump = VFSTOEXT2(mp); devvp = ump->um_devvp; bsize = EXT2_BLOCK_SIZE(ump->um_e2fs); if (runp) { maxrun = mp->mnt_iosize_max / bsize - 1; *runp = 0; } if (runb) { *runb = 0; } ap = a; nump = # error = ext2_getlbns(vp, bn, ap, nump); if (error) return (error); num = *nump; if (num == 0) { *bnp = blkptrtodb(ump, ip->i_db[bn]); if (*bnp == 0) { *bnp = -1; } else if (runp) { daddr_t bnb = bn; for (++bn; bn < NDADDR && *runp < maxrun && is_sequential(ump, ip->i_db[bn - 1], ip->i_db[bn]); ++bn, ++*runp); bn = bnb; if (runb && (bn > 0)) { for (--bn; (bn >= 0) && (*runb < maxrun) && is_sequential(ump, ip->i_db[bn], ip->i_db[bn + 1]); --bn, ++*runb); } } return (0); } /* Get disk address out of indirect block array */ daddr = ip->i_ib[ap->in_off]; for (bp = NULL, ++ap; --num; ++ap) { /* * Exit the loop if there is no disk address assigned yet and * the indirect block isn't in the cache, or if we were * looking for an indirect block and we've found it. */ metalbn = ap->in_lbn; if ((daddr == 0 && !incore(&vp->v_bufobj, metalbn)) || metalbn == bn) break; /* * If we get here, we've either got the block in the cache * or we have a disk address for it, go fetch it. */ if (bp) bqrelse(bp); bp = getblk(vp, metalbn, bsize, 0, 0, 0); if ((bp->b_flags & B_CACHE) == 0) {#ifdef INVARIANTS if (!daddr) panic("ext2_bmaparray: indirect block not in cache");#endif bp->b_blkno = blkptrtodb(ump, daddr); bp->b_iocmd = BIO_READ; bp->b_flags &= ~B_INVAL; bp->b_ioflags &= ~BIO_ERROR; vfs_busy_pages(bp, 0); bp->b_iooffset = dbtob(bp->b_blkno); bstrategy(bp); curthread->td_ru.ru_inblock++; error = bufwait(bp); if (error) { brelse(bp); return (error); } }//.........这里部分代码省略.........
开发者ID:Alkzndr,项目名称:freebsd,代码行数:101,
示例20: read_allocated_blocklong int read_allocated_block(struct ext2fs_node *node, int fileblock){ long int blknr; int blksz; int log2_blksz; long int rblock; long int perblock_parent; long int perblock_child; unsigned long long start; struct ext2_inode *inode = &node->inode; struct ext2_data *data = node->data; int ret; /* get the blocksize of the filesystem */ blksz = EXT2_BLOCK_SIZE(node->data); log2_blksz = LOG2_EXT2_BLOCK_SIZE(node->data); if (le32_to_cpu(inode->flags) & EXT4_EXTENTS_FL) { char *buf = zalloc(blksz); struct ext4_extent_header *ext_block; struct ext4_extent *extent; int i = -1; if (!buf) return -ENOMEM; ext_block = ext4fs_get_extent_block(node->data, buf, (struct ext4_extent_header *)inode->b.blocks.dir_blocks, fileblock, log2_blksz); if (!ext_block) { pr_err("invalid extent block/n"); free(buf); return -EINVAL; } extent = (struct ext4_extent *)(ext_block + 1); do { i++; if (i >= le32_to_cpu(ext_block->eh_entries)) break; } while (fileblock >= le32_to_cpu(extent[i].ee_block)); if (--i >= 0) { fileblock -= le32_to_cpu(extent[i].ee_block); if (fileblock >= le32_to_cpu(extent[i].ee_len)) { free(buf); return 0; } start = le32_to_cpu(extent[i].ee_start_hi); start = (start << 32) + le32_to_cpu(extent[i].ee_start_lo); free(buf); return fileblock + start; } free(buf); return -EIO; } if (fileblock < INDIRECT_BLOCKS) { /* Direct blocks. */ blknr = __le32_to_cpu(inode->b.blocks.dir_blocks[fileblock]); } else if (fileblock < (INDIRECT_BLOCKS + (blksz / 4))) { /* Indirect. */ ret = ext4fs_get_indir_block(node, &data->indir1, __le32_to_cpu(inode->b.blocks.indir_block) << log2_blksz); if (ret) return ret; blknr = __le32_to_cpu(data->indir1.data[fileblock - INDIRECT_BLOCKS]); } else if (fileblock < (INDIRECT_BLOCKS + (blksz / 4 * (blksz / 4 + 1)))) { /* Double indirect. */ long int perblock = blksz / 4; long int rblock = fileblock - (INDIRECT_BLOCKS + blksz / 4); ret = ext4fs_get_indir_block(node, &data->indir1, __le32_to_cpu(inode->b.blocks.double_indir_block) << log2_blksz); if (ret) return ret; ret = ext4fs_get_indir_block(node, &data->indir2, __le32_to_cpu(data->indir1.data[rblock / perblock]) << log2_blksz); if (ret) return ret; blknr = __le32_to_cpu(data->indir2.data[rblock % perblock]); } else { /* Triple indirect. */ rblock = fileblock - (INDIRECT_BLOCKS + blksz / 4 + (blksz / 4 * blksz / 4)); perblock_child = blksz / 4; perblock_parent = ((blksz / 4) * (blksz / 4)); ret = ext4fs_get_indir_block(node, &data->indir1, __le32_to_cpu(inode->b.blocks.triple_indir_block) << log2_blksz); if (ret) return ret;//.........这里部分代码省略.........
开发者ID:AshishNamdev,项目名称:barebox,代码行数:101,
示例21: list_super2void list_super2(struct ext2_super_block * sb, FILE *f){ int inode_blocks_per_group; char buf[80], *str; time_t tm; inode_blocks_per_group = (((sb->s_inodes_per_group * EXT2_INODE_SIZE(sb)) + EXT2_BLOCK_SIZE(sb) - 1) / EXT2_BLOCK_SIZE(sb)); if (sb->s_volume_name[0]) { memset(buf, 0, sizeof(buf)); strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name)); } else strcpy(buf, "<none>"); fprintf(f, "Filesystem volume name: %s/n", buf); if (sb->s_last_mounted[0]) { memset(buf, 0, sizeof(buf)); strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted)); } else strcpy(buf, "<not available>"); fprintf(f, "Last mounted on: %s/n", buf); fprintf(f, "Filesystem UUID: %s/n", e2p_uuid2str(sb->s_uuid)); fprintf(f, "Filesystem magic number: 0x%04X/n", sb->s_magic); fprintf(f, "Filesystem revision #: %d", sb->s_rev_level); if (sb->s_rev_level == EXT2_GOOD_OLD_REV) { fprintf(f, " (original)/n");#ifdef EXT2_DYNAMIC_REV } else if (sb->s_rev_level == EXT2_DYNAMIC_REV) { fprintf(f, " (dynamic)/n");#endif } else fprintf(f, " (unknown)/n"); print_features(sb, f); print_super_flags(sb, f); print_mntopts(sb, f); fprintf(f, "Filesystem state: "); print_fs_state (f, sb->s_state); fprintf(f, "/n"); fprintf(f, "Errors behavior: "); print_fs_errors(f, sb->s_errors); fprintf(f, "/n"); str = e2p_os2string(sb->s_creator_os); fprintf(f, "Filesystem OS type: %s/n", str); free(str); fprintf(f, "Inode count: %u/n", sb->s_inodes_count); fprintf(f, "Block count: %u/n", sb->s_blocks_count); fprintf(f, "Reserved block count: %u/n", sb->s_r_blocks_count); fprintf(f, "Free blocks: %u/n", sb->s_free_blocks_count); fprintf(f, "Free inodes: %u/n", sb->s_free_inodes_count); fprintf(f, "First block: %u/n", sb->s_first_data_block); fprintf(f, "Block size: %u/n", EXT2_BLOCK_SIZE(sb)); fprintf(f, "Fragment size: %u/n", EXT2_FRAG_SIZE(sb)); if (sb->s_reserved_gdt_blocks) fprintf(f, "Reserved GDT blocks: %u/n", sb->s_reserved_gdt_blocks); fprintf(f, "Blocks per group: %u/n", sb->s_blocks_per_group); fprintf(f, "Fragments per group: %u/n", sb->s_frags_per_group); fprintf(f, "Inodes per group: %u/n", sb->s_inodes_per_group); fprintf(f, "Inode blocks per group: %u/n", inode_blocks_per_group); if (sb->s_raid_stride) fprintf(f, "RAID stride: %u/n", sb->s_raid_stride); if (sb->s_raid_stripe_width) fprintf(f, "RAID stripe width: %u/n", sb->s_raid_stripe_width); if (sb->s_first_meta_bg) fprintf(f, "First meta block group: %u/n", sb->s_first_meta_bg); if (sb->s_log_groups_per_flex) fprintf(f, "Flex block group size: %u/n", 1 << sb->s_log_groups_per_flex); if (sb->s_mkfs_time) { tm = sb->s_mkfs_time; fprintf(f, "Filesystem created: %s", ctime(&tm)); } tm = sb->s_mtime; fprintf(f, "Last mount time: %s", sb->s_mtime ? ctime(&tm) : "n/a/n"); tm = sb->s_wtime; fprintf(f, "Last write time: %s", ctime(&tm)); fprintf(f, "Mount count: %u/n", sb->s_mnt_count); fprintf(f, "Maximum mount count: %d/n", sb->s_max_mnt_count); tm = sb->s_lastcheck; fprintf(f, "Last checked: %s", ctime(&tm)); fprintf(f, "Check interval: %u (%s)/n", sb->s_checkinterval, interval_string(sb->s_checkinterval)); if (sb->s_checkinterval) { time_t next; next = sb->s_lastcheck + sb->s_checkinterval; fprintf(f, "Next check after: %s", ctime(&next)); } fprintf(f, "Reserved blocks uid: "); print_user(sb->s_def_resuid, f); fprintf(f, "Reserved blocks gid: "); print_group(sb->s_def_resgid, f); if (sb->s_rev_level >= EXT2_DYNAMIC_REV) { fprintf(f, "First inode: %d/n", sb->s_first_ino);//.........这里部分代码省略.........
开发者ID:rocklee104,项目名称:e2fsprogs-1.41.0,代码行数:101,
示例22: dump_journalstatic void dump_journal(char *cmdname, FILE *out_file, struct journal_source *source){ struct ext2_super_block *sb; char jsb_buffer[1024]; char buf[8192]; journal_superblock_t *jsb; unsigned int blocksize = 1024; unsigned int got; int retval; __u32 magic, sequence, blocktype; journal_header_t *header; tid_t transaction; unsigned int blocknr = 0; /* First, check to see if there's an ext2 superblock header */ retval = read_journal_block(cmdname, source, 0, buf, 2048, &got); if (retval) return; jsb = (journal_superblock_t *) buf; sb = (struct ext2_super_block *) (buf+1024);#ifdef ENABLE_SWAPFS if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ext2fs_swap_super(sb);#endif if ((be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) && (sb->s_magic == EXT2_SUPER_MAGIC) && (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { blocksize = EXT2_BLOCK_SIZE(sb); blocknr = (blocksize == 1024) ? 2 : 1; uuid_unparse(sb->s_uuid, jsb_buffer); fprintf(out_file, "Ext2 superblock header found./n"); if (dump_all) { fprintf(out_file, "/tuuid=%s/n", jsb_buffer); fprintf(out_file, "/tblocksize=%d/n", blocksize); fprintf(out_file, "/tjournal data size %ld/n", (long) sb->s_blocks_count); } } /* Next, read the journal superblock */ retval = read_journal_block(cmdname, source, blocknr*blocksize, jsb_buffer, 1024, &got); if (retval) return; jsb = (journal_superblock_t *) jsb_buffer; if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) { fprintf(out_file, "Journal superblock magic number invalid!/n"); return; } blocksize = be32_to_cpu(jsb->s_blocksize); transaction = be32_to_cpu(jsb->s_sequence); blocknr = be32_to_cpu(jsb->s_start); fprintf(out_file, "Journal starts at block %u, transaction %u/n", blocknr, transaction); if (!blocknr) /* Empty journal, nothing to do. */ return; while (1) { retval = read_journal_block(cmdname, source, blocknr*blocksize, buf, blocksize, &got); if (retval || got != blocksize) return; header = (journal_header_t *) buf; magic = be32_to_cpu(header->h_magic); sequence = be32_to_cpu(header->h_sequence); blocktype = be32_to_cpu(header->h_blocktype); if (magic != JFS_MAGIC_NUMBER) { fprintf (out_file, "No magic number at block %u: " "end of journal./n", blocknr); return; } if (sequence != transaction) { fprintf (out_file, "Found sequence %u (not %u) at " "block %u: end of journal./n", sequence, transaction, blocknr); return; } if (dump_descriptors) { fprintf (out_file, "Found expected sequence %u, " "type %u (%s) at block %u/n", sequence, blocktype, type_to_name(blocktype), blocknr); }//.........这里部分代码省略.........
开发者ID:acassis,项目名称:emlinux-ssd1935,代码行数:101,
示例23: main//.........这里部分代码省略......... (ctx->options & E2F_OPT_READONLY) ? "r/o" : "r/w"); else if (retval == ENXIO) printf(_("Possibly non-existent or swap device?/n")); else if (retval == EBUSY) printf(_("Filesystem mounted or opened exclusively " "by another program?/n")); else if (retval == ENOENT) printf(_("Possibly non-existent device?/n"));#ifdef EROFS else if (retval == EROFS) printf(_("Disk write-protected; use the -n option " "to do a read-only/n" "check of the device./n"));#endif else fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); fatal_error(ctx, 0); } /* * We only update the master superblock because (a) paranoia; * we don't want to corrupt the backup superblocks, and (b) we * don't need to update the mount count and last checked * fields in the backup superblock (the kernel doesn't update * the backup superblocks anyway). With newer versions of the * library this flag is set by ext2fs_open2(), but we set this * here just to be sure. (No, we don't support e2fsck running * with some other libext2fs than the one that it was shipped * with, but just in case....) */ fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; if (!(ctx->flags & E2F_FLAG_GOT_DEVSIZE)) { __u32 blocksize = EXT2_BLOCK_SIZE(fs->super); int need_restart = 0; pctx.errcode = ext2fs_get_device_size2(ctx->filesystem_name, blocksize, &ctx->num_blocks); /* * The floppy driver refuses to allow anyone else to * open the device if has been opened with O_EXCL; * this is unlike other block device drivers in Linux. * To handle this, we close the filesystem and then * reopen the filesystem after we get the device size. */ if (pctx.errcode == EBUSY) { ext2fs_close(fs); need_restart++; pctx.errcode = ext2fs_get_device_size2(ctx->filesystem_name, blocksize, &ctx->num_blocks); } if (pctx.errcode == EXT2_ET_UNIMPLEMENTED) ctx->num_blocks = 0; else if (pctx.errcode) { fix_problem(ctx, PR_0_GETSIZE_ERROR, &pctx); ctx->flags |= E2F_FLAG_ABORT; fatal_error(ctx, 0); } ctx->flags |= E2F_FLAG_GOT_DEVSIZE; if (need_restart) goto restart; }
开发者ID:xiejinfeng850414,项目名称:BananaPi-Android-4.2.2-Liab,代码行数:66,
示例24: ext2fs_open2//.........这里部分代码省略......... (features & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP)) { retval = EXT2_ET_RO_UNSUPP_FEATURE; goto cleanup; } if (!(flags & EXT2_FLAG_JOURNAL_DEV_OK) && ext2fs_has_feature_journal_dev(fs->super)) { retval = EXT2_ET_UNSUPP_FEATURE; goto cleanup; } } if ((fs->super->s_log_block_size + EXT2_MIN_BLOCK_LOG_SIZE) > EXT2_MAX_BLOCK_LOG_SIZE) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } /* * bigalloc requires cluster-aware bitfield operations, which at the * moment means we need EXT2_FLAG_64BITS. */ if (ext2fs_has_feature_bigalloc(fs->super) && !(flags & EXT2_FLAG_64BITS)) { retval = EXT2_ET_CANT_USE_LEGACY_BITMAPS; goto cleanup; } if (!ext2fs_has_feature_bigalloc(fs->super) && (fs->super->s_log_block_size != fs->super->s_log_cluster_size)) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(fs->super); if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } /* Enforce the block group descriptor size */ if (ext2fs_has_feature_64bit(fs->super)) { if (fs->super->s_desc_size < EXT2_MIN_DESC_SIZE_64BIT) { retval = EXT2_ET_BAD_DESC_SIZE; goto cleanup; } } else { if (fs->super->s_desc_size && fs->super->s_desc_size != EXT2_MIN_DESC_SIZE) { retval = EXT2_ET_BAD_DESC_SIZE; goto cleanup; } } fs->cluster_ratio_bits = fs->super->s_log_cluster_size - fs->super->s_log_block_size; if (EXT2_BLOCKS_PER_GROUP(fs->super) != EXT2_CLUSTERS_PER_GROUP(fs->super) << fs->cluster_ratio_bits) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) * EXT2_INODE_SIZE(fs->super) + EXT2_BLOCK_SIZE(fs->super) - 1) / EXT2_BLOCK_SIZE(fs->super)); if (block_size) { if (block_size != fs->blocksize) {
开发者ID:MIPS,项目名称:external-e2fsprogs,代码行数:67,
示例25: parse_extended_optsstatic void parse_extended_opts(struct ext2_super_block *param, const char *opts){ char *buf, *token, *next, *p, *arg; int len; int r_usage = 0; len = strlen(opts); buf = malloc(len+1); if (!buf) { fprintf(stderr, _("Couldn't allocate memory to parse options!/n")); exit(1); } strcpy(buf, opts); for (token = buf; token && *token; token = next) { p = strchr(token, ','); next = 0; if (p) { *p = 0; next = p+1; } arg = strchr(token, '='); if (arg) { *arg = 0; arg++; } if (strcmp(token, "stride") == 0) { if (!arg) { r_usage++; continue; } fs_stride = strtoul(arg, &p, 0); if (*p || (fs_stride == 0)) { fprintf(stderr, _("Invalid stride parameter: %s/n"), arg); r_usage++; continue; } } else if (!strcmp(token, "resize")) { unsigned long resize, bpg, rsv_groups; unsigned long group_desc_count, desc_blocks; unsigned int gdpb, blocksize; int rsv_gdb; if (!arg) { r_usage++; continue; } resize = parse_num_blocks(arg, param->s_log_block_size); if (resize == 0) { fprintf(stderr, _("Invalid resize parameter: %s/n"), arg); r_usage++; continue; } if (resize <= param->s_blocks_count) { fprintf(stderr, _("The resize maximum must be greater " "than the filesystem size./n")); r_usage++; continue; } blocksize = EXT2_BLOCK_SIZE(param); bpg = param->s_blocks_per_group; if (!bpg) bpg = blocksize * 8; gdpb = blocksize / sizeof(struct ext2_group_desc); group_desc_count = (param->s_blocks_count + bpg - 1) / bpg; desc_blocks = (group_desc_count + gdpb - 1) / gdpb; rsv_groups = (resize + bpg - 1) / bpg; rsv_gdb = (rsv_groups + gdpb - 1) / gdpb - desc_blocks; if (rsv_gdb > (int) EXT2_ADDR_PER_BLOCK(param)) rsv_gdb = EXT2_ADDR_PER_BLOCK(param); if (rsv_gdb > 0) { param->s_feature_compat |= EXT2_FEATURE_COMPAT_RESIZE_INODE; param->s_reserved_gdt_blocks = rsv_gdb; } } else r_usage++; } if (r_usage) { fprintf(stderr, _("/nBad options specified./n/n" "Extended options are separated by commas, " "and may take an argument which/n" "/tis set off by an equals ('=') sign./n/n" "Valid extended options are:/n" "/tstride=<stride length in blocks>/n"//.........这里部分代码省略.........
开发者ID:OPSF,项目名称:uClinux,代码行数:101,
示例26: get_backup_sbblk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name, io_manager manager){ struct ext2_super_block *sb; io_channel io = NULL; void *buf = NULL; int blocksize; blk64_t superblock, ret_sb = 8193; if (fs && fs->super) { ret_sb = (fs->super->s_blocks_per_group + fs->super->s_first_data_block); if (ctx) { ctx->superblock = ret_sb; ctx->blocksize = fs->blocksize; } return ret_sb; } if (ctx) { if (ctx->blocksize) { ret_sb = ctx->blocksize * 8; if (ctx->blocksize == 1024) ret_sb++; ctx->superblock = ret_sb; return ret_sb; } ctx->superblock = ret_sb; ctx->blocksize = 1024; } if (!name || !manager) goto cleanup; if (manager->open(name, 0, &io) != 0) goto cleanup; if (ext2fs_get_mem(SUPERBLOCK_SIZE, &buf)) goto cleanup; sb = (struct ext2_super_block *) buf; for (blocksize = EXT2_MIN_BLOCK_SIZE; blocksize <= EXT2_MAX_BLOCK_SIZE ; blocksize *= 2) { superblock = blocksize*8; if (blocksize == 1024) superblock++; io_channel_set_blksize(io, blocksize); if (io_channel_read_blk64(io, superblock, -SUPERBLOCK_SIZE, buf)) continue;#ifdef WORDS_BIGENDIAN if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ext2fs_swap_super(sb);#endif if ((sb->s_magic == EXT2_SUPER_MAGIC) && (EXT2_BLOCK_SIZE(sb) == blocksize)) { ret_sb = superblock; if (ctx) { ctx->superblock = superblock; ctx->blocksize = blocksize; } break; } }cleanup: if (io) io_channel_close(io); if (buf) ext2fs_free_mem(&buf); return (ret_sb);}
开发者ID:guaneryu,项目名称:e2fsprogs,代码行数:72,
示例27: ext2_mountint ext2_mount(bdev_t *dev, fscookie *cookie){ int err; LTRACEF("dev %p/n", dev); ext2_t *ext2 = malloc(sizeof(ext2_t)); ext2->dev = dev; err = bio_read(dev, &ext2->sb, 1024, sizeof(struct ext2_super_block)); if (err < 0) goto err; endian_swap_superblock(&ext2->sb); /* see if the superblock is good */ if (ext2->sb.s_magic != EXT2_SUPER_MAGIC) { err = -1; return err; } /* calculate group count, rounded up */ ext2->s_group_count = (ext2->sb.s_blocks_count + ext2->sb.s_blocks_per_group - 1) / ext2->sb.s_blocks_per_group; /* print some info */ LTRACEF("rev level %d/n", ext2->sb.s_rev_level); LTRACEF("compat features 0x%x/n", ext2->sb.s_feature_compat); LTRACEF("incompat features 0x%x/n", ext2->sb.s_feature_incompat); LTRACEF("ro compat features 0x%x/n", ext2->sb.s_feature_ro_compat); LTRACEF("block size %d/n", EXT2_BLOCK_SIZE(ext2->sb)); LTRACEF("inode size %d/n", EXT2_INODE_SIZE(ext2->sb)); LTRACEF("block count %d/n", ext2->sb.s_blocks_count); LTRACEF("blocks per group %d/n", ext2->sb.s_blocks_per_group); LTRACEF("group count %d/n", ext2->s_group_count); LTRACEF("inodes per group %d/n", ext2->sb.s_inodes_per_group); /* we only support dynamic revs */ if (ext2->sb.s_rev_level > EXT2_DYNAMIC_REV) { err = -2; return err; } /* make sure it doesn't have any ro features we don't support */ if (ext2->sb.s_feature_ro_compat & ~(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|EXT2_FEATURE_RO_COMPAT_LARGE_FILE)) { err = -3; return err; } /* read in all the group descriptors */ ext2->gd = malloc(sizeof(struct ext2_group_desc) * ext2->s_group_count); err = bio_read(ext2->dev, (void *)ext2->gd, (EXT2_BLOCK_SIZE(ext2->sb) == 4096) ? 4096 : 2048, sizeof(struct ext2_group_desc) * ext2->s_group_count); if (err < 0) { err = -4; return err; } int i; for (i=0; i < ext2->s_group_count; i++) { endian_swap_group_desc(&ext2->gd[i]); LTRACEF("group %d:/n", i); LTRACEF("/tblock bitmap %d/n", ext2->gd[i].bg_block_bitmap); LTRACEF("/tinode bitmap %d/n", ext2->gd[i].bg_inode_bitmap); LTRACEF("/tinode table %d/n", ext2->gd[i].bg_inode_table); LTRACEF("/tfree blocks %d/n", ext2->gd[i].bg_free_blocks_count); LTRACEF("/tfree inodes %d/n", ext2->gd[i].bg_free_inodes_count); LTRACEF("/tused dirs %d/n", ext2->gd[i].bg_used_dirs_count); } /* initialize the block cache */ ext2->cache = bcache_create(ext2->dev, EXT2_BLOCK_SIZE(ext2->sb), 4); /* load the first inode */ err = ext2_load_inode(ext2, EXT2_ROOT_INO, &ext2->root_inode); if (err < 0) goto err;// TRACE("successfully mounted volume/n"); *cookie = ext2; return 0;err: LTRACEF("exiting with err code %d/n", err); free(ext2); return err;}
开发者ID:ArthurMurata,项目名称:lk,代码行数:90,
示例28: ext2fs_read_inode_full/* * Functions to read and write a single inode. */errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize){ blk64_t block_nr; unsigned long group, block, offset; char *ptr; errcode_t retval; unsigned i; int clen, inodes_per_block; io_channel io; int length = EXT2_INODE_SIZE(fs->super); struct ext2_inode_large *iptr; int cache_slot, fail_csum; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); /* Check to see if user has an override function */ if (fs->read_inode && ((bufsize == sizeof(struct ext2_inode)) || (EXT2_INODE_SIZE(fs->super) == sizeof(struct ext2_inode)))) { retval = (fs->read_inode)(fs, ino, inode); if (retval != EXT2_ET_CALLBACK_NOTHANDLED) return retval; } if ((ino == 0) || (ino > fs->super->s_inodes_count)) return EXT2_ET_BAD_INODE_NUM; /* Create inode cache if not present */ if (!fs->icache) { retval = ext2fs_create_inode_cache(fs, 4); if (retval) return retval; } /* Check to see if it's in the inode cache */ for (i = 0; i < fs->icache->cache_size; i++) { if (fs->icache->cache[i].ino == ino) { memcpy(inode, fs->icache->cache[i].inode, (bufsize > length) ? length : bufsize); return 0; } } if (fs->flags & EXT2_FLAG_IMAGE_FILE) { inodes_per_block = fs->blocksize / EXT2_INODE_SIZE(fs->super); block_nr = fs->image_header->offset_inode / fs->blocksize; block_nr += (ino - 1) / inodes_per_block; offset = ((ino - 1) % inodes_per_block) * EXT2_INODE_SIZE(fs->super); io = fs->image_io; } else { group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); if (group > fs->group_desc_count) return EXT2_ET_BAD_INODE_NUM; offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * EXT2_INODE_SIZE(fs->super); block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); if (!ext2fs_inode_table_loc(fs, (unsigned) group)) return EXT2_ET_MISSING_INODE_TABLE; block_nr = ext2fs_inode_table_loc(fs, group) + block; io = fs->io; } offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); cache_slot = (fs->icache->cache_last + 1) % fs->icache->cache_size; iptr = (struct ext2_inode_large *)fs->icache->cache[cache_slot].inode; ptr = (char *) iptr; while (length) { clen = length; if ((offset + length) > fs->blocksize) clen = fs->blocksize - offset; if (block_nr != fs->icache->buffer_blk) { retval = io_channel_read_blk64(io, block_nr, 1, fs->icache->buffer); if (retval) return retval; fs->icache->buffer_blk = block_nr; } memcpy(ptr, ((char *) fs->icache->buffer) + (unsigned) offset, clen); offset = 0; length -= clen; ptr += clen; block_nr++; } length = EXT2_INODE_SIZE(fs->super); /* Verify the inode checksum. */ fail_csum = !ext2fs_inode_csum_verify(fs, ino, iptr);#ifdef WORDS_BIGENDIAN ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) iptr, (struct ext2_inode_large *) iptr, 0, length);#endif//.........这里部分代码省略.........
开发者ID:MIPS,项目名称:external-e2fsprogs,代码行数:101,
注:本文中的EXT2_BLOCK_SIZE函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ EXT2_DESC_PER_BLOCK函数代码示例 C++ EXT2_BLOCKS_PER_GROUP函数代码示例 |