本文整理汇总了C++中EXT2_BLOCK_SIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ EXT2_BLOCK_SIZE函数的具体用法?C++ EXT2_BLOCK_SIZE怎么用?C++ EXT2_BLOCK_SIZE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EXT2_BLOCK_SIZE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ext2fs_read_inode
static quik_err_t
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;
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;
}
示例2: EXT2_BLOCK_SIZE
static 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));
}
示例3: ext4fs_get_indir_block
int 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;
}
示例4: printf
static 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);
}
示例5: grub_ext4_find_leaf
static 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;
}
}
示例6: ext2_mount
ext2_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;
}
示例7: EXT2_BLOCK_SIZE
static 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;
}
}
示例8: move_metadata_block
static 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;
}
示例9: ext2fs_read_block
static 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;
//.........这里部分代码省略.........
示例10: ext2fs_write_inode_full
errcode_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);
//.........这里部分代码省略.........
示例11: list_desc
static 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),
//.........这里部分代码省略.........
示例12: e2fsck_get_device_size
errcode_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));
}
示例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));
}
示例14: grub_ext2_read_block
static grub_disk_addr_t
grub_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");
//.........这里部分代码省略.........
示例15: ext2_lblkno
int ext2_lblkno(
struct ext2_super_block * fs,
vm_offset_t offset)
{
return offset / EXT2_BLOCK_SIZE(fs);
}