mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-25 04:04:26 -04:00
[ext2fs] update to latest e2fsprogs
* e2fsprogs commit [cecc2bc78b39ddcd34a819a4d7e7cd30897958cb] * Also add LGPLv2 license text
This commit is contained in:
parent
cda716c1ff
commit
cec443ef61
36 changed files with 1721 additions and 597 deletions
|
@ -179,6 +179,14 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
|
|||
EXT2_INODE_SCAN_DEFAULT_BUFFER_BLOCKS;
|
||||
scan->current_block = ext2fs_inode_table_loc(scan->fs,
|
||||
scan->current_group);
|
||||
if (scan->current_block &&
|
||||
((scan->current_block < fs->super->s_first_data_block) ||
|
||||
(scan->current_block + fs->inode_blocks_per_group - 1 >=
|
||||
ext2fs_blocks_count(fs->super)))) {
|
||||
ext2fs_free_mem(&scan);
|
||||
return EXT2_ET_GDESC_BAD_INODE_TABLE;
|
||||
}
|
||||
|
||||
scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super);
|
||||
scan->blocks_left = scan->fs->inode_blocks_per_group;
|
||||
if (ext2fs_has_group_desc_csum(fs)) {
|
||||
|
@ -288,7 +296,11 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan)
|
|||
(fs->blocksize / scan->inode_size - 1)) *
|
||||
scan->inode_size / fs->blocksize;
|
||||
}
|
||||
|
||||
if (scan->current_block &&
|
||||
((scan->current_block < fs->super->s_first_data_block) ||
|
||||
(scan->current_block + fs->inode_blocks_per_group - 1 >=
|
||||
ext2fs_blocks_count(fs->super))))
|
||||
return EXT2_ET_GDESC_BAD_INODE_TABLE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -728,11 +740,13 @@ errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
|
|||
/*
|
||||
* 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)
|
||||
errcode_t ext2fs_read_inode2(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode * inode, int bufsize,
|
||||
int flags)
|
||||
{
|
||||
blk64_t block_nr;
|
||||
unsigned long group, block, offset;
|
||||
dgrp_t group;
|
||||
unsigned long block, offset;
|
||||
char *ptr;
|
||||
errcode_t retval;
|
||||
unsigned i;
|
||||
|
@ -782,10 +796,14 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
|||
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))
|
||||
block_nr = ext2fs_inode_table_loc(fs, group);
|
||||
if (!block_nr)
|
||||
return EXT2_ET_MISSING_INODE_TABLE;
|
||||
block_nr = ext2fs_inode_table_loc(fs, group) +
|
||||
block;
|
||||
if ((block_nr < fs->super->s_first_data_block) ||
|
||||
(block_nr + fs->inode_blocks_per_group - 1 >=
|
||||
ext2fs_blocks_count(fs->super)))
|
||||
return EXT2_ET_GDESC_BAD_INODE_TABLE;
|
||||
block_nr += block;
|
||||
io = fs->io;
|
||||
}
|
||||
offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
|
||||
|
@ -833,24 +851,33 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
|||
}
|
||||
memcpy(inode, iptr, (bufsize > length) ? length : bufsize);
|
||||
|
||||
if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) && fail_csum)
|
||||
if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
|
||||
!(flags & READ_INODE_NOCSUM) && fail_csum)
|
||||
return EXT2_ET_INODE_CSUM_INVALID;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode * inode, int bufsize)
|
||||
{
|
||||
return ext2fs_read_inode2(fs, ino, inode, bufsize, 0);
|
||||
}
|
||||
|
||||
errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode * inode)
|
||||
{
|
||||
return ext2fs_read_inode_full(fs, ino, inode,
|
||||
sizeof(struct ext2_inode));
|
||||
return ext2fs_read_inode2(fs, ino, inode,
|
||||
sizeof(struct ext2_inode), 0);
|
||||
}
|
||||
|
||||
errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode * inode, int bufsize)
|
||||
errcode_t ext2fs_write_inode2(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode * inode, int bufsize,
|
||||
int flags)
|
||||
{
|
||||
blk64_t block_nr;
|
||||
unsigned long group, block, offset;
|
||||
dgrp_t group;
|
||||
unsigned long block, offset;
|
||||
errcode_t retval = 0;
|
||||
struct ext2_inode_large *w_inode;
|
||||
char *ptr;
|
||||
|
@ -876,13 +903,9 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
|||
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);
|
||||
retval = ext2fs_read_inode2(fs, ino,
|
||||
(struct ext2_inode *)w_inode,
|
||||
length, READ_INODE_NOCSUM);
|
||||
if (retval)
|
||||
goto errout;
|
||||
}
|
||||
|
@ -912,19 +935,28 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
|||
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;
|
||||
if ((flags & WRITE_INODE_NOCSUM) == 0) {
|
||||
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)) {
|
||||
block_nr = ext2fs_inode_table_loc(fs, (unsigned) group);
|
||||
if (!block_nr) {
|
||||
retval = EXT2_ET_MISSING_INODE_TABLE;
|
||||
goto errout;
|
||||
}
|
||||
block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block;
|
||||
if ((block_nr < fs->super->s_first_data_block) ||
|
||||
(block_nr + fs->inode_blocks_per_group - 1 >=
|
||||
ext2fs_blocks_count(fs->super))) {
|
||||
retval = EXT2_ET_GDESC_BAD_INODE_TABLE;
|
||||
goto errout;
|
||||
}
|
||||
block_nr += block;
|
||||
|
||||
offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
|
||||
|
||||
|
@ -964,11 +996,17 @@ errout:
|
|||
return retval;
|
||||
}
|
||||
|
||||
errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode * inode, int bufsize)
|
||||
{
|
||||
return ext2fs_write_inode2(fs, ino, inode, bufsize, 0);
|
||||
}
|
||||
|
||||
errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
|
||||
struct ext2_inode *inode)
|
||||
{
|
||||
return ext2fs_write_inode_full(fs, ino, inode,
|
||||
sizeof(struct ext2_inode));
|
||||
return ext2fs_write_inode2(fs, ino, inode,
|
||||
sizeof(struct ext2_inode), 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue