Merge branch 'maint' into next

This commit is contained in:
Theodore Ts'o 2020-03-07 13:13:55 -05:00
commit b84a5568c7
47 changed files with 387 additions and 345 deletions

View File

@ -48,8 +48,14 @@ extern char *optarg;
int journal_enable_debug = -1;
#endif
/*
* There must be only one definition if we're hooking in extra commands or
* chaging default prompt. Use -DSKIP_GLOBDEF for that.
*/
#ifndef SKIP_GLOBDEFS
ss_request_table *extra_cmds;
const char *debug_prog_name;
#endif
int ss_sci_idx;
ext2_filsys current_fs;
@ -467,7 +473,7 @@ void do_show_super_stats(int argc, char *argv[],
}
for (i=0; i < current_fs->group_desc_count; i++)
numdirs += ext2fs_bg_used_dirs_count(current_fs, i);
fprintf(out, "Directories: %d\n", numdirs);
fprintf(out, "Directories: %u\n", numdirs);
if (header_only) {
close_pager(out);
@ -718,7 +724,7 @@ static void dump_extents(FILE *f, const char *prefix, ext2_ino_t ino,
continue;
}
fprintf(f, "%s(ETB%d):%lld",
fprintf(f, "%s(ETB%d):%llu",
printed ? ", " : "", info.curr_level,
extent.e_pblk);
printed = 1;
@ -851,10 +857,10 @@ void internal_dump_inode(FILE *out, const char *prefix,
if (LINUX_S_ISREG(inode->i_mode) || LINUX_S_ISDIR(inode->i_mode))
fprintf(out, "%llu\n", EXT2_I_SIZE(inode));
else
fprintf(out, "%d\n", inode->i_size);
fprintf(out, "%u\n", inode->i_size);
if (os == EXT2_OS_HURD)
fprintf(out,
"%sFile ACL: %d Translator: %d\n",
"%sFile ACL: %u Translator: %u\n",
prefix,
inode->i_file_acl,
inode->osd1.hurd1.h_i_translator);
@ -864,13 +870,13 @@ void internal_dump_inode(FILE *out, const char *prefix,
inode->i_file_acl | ((long long)
(inode->osd2.linux2.l_i_file_acl_high) << 32));
if (os != EXT2_OS_HURD)
fprintf(out, "%sLinks: %d Blockcount: %llu\n",
fprintf(out, "%sLinks: %u Blockcount: %llu\n",
prefix, inode->i_links_count,
(((unsigned long long)
inode->osd2.linux2.l_i_blocks_hi << 32)) +
inode->i_blocks);
else
fprintf(out, "%sLinks: %d Blockcount: %u\n",
fprintf(out, "%sLinks: %u Blockcount: %u\n",
prefix, inode->i_links_count, inode->i_blocks);
switch (os) {
case EXT2_OS_HURD:
@ -880,7 +886,7 @@ void internal_dump_inode(FILE *out, const char *prefix,
default:
frag = fsize = 0;
}
fprintf(out, "%sFragment: Address: %d Number: %d Size: %d\n",
fprintf(out, "%sFragment: Address: %u Number: %u Size: %u\n",
prefix, inode->i_faddr, frag, fsize);
if (is_large_inode && large_inode->i_extra_isize >= 24) {
fprintf(out, "%s ctime: 0x%08x:%08x -- %s", prefix,
@ -1397,7 +1403,7 @@ void do_modify_inode(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
modify_u8(argv[0], "Fragment size", decimal_format, fsize);
for (i=0; i < EXT2_NDIR_BLOCKS; i++) {
sprintf(buf, "Direct Block #%d", i);
sprintf(buf, "Direct Block #%u", i);
modify_u32(argv[0], buf, decimal_format, &inode.i_block[i]);
}
modify_u32(argv[0], "Indirect Block", decimal_format,
@ -2133,7 +2139,7 @@ void do_imap(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
block;
offset &= (EXT2_BLOCK_SIZE(current_fs->super) - 1);
printf("Inode %d is part of block group %lu\n"
printf("Inode %u is part of block group %lu\n"
"\tlocated at block %lu, offset 0x%04lx\n", ino, group,
block_nr, offset);
@ -2488,6 +2494,10 @@ static int source_file(const char *cmd_file, int ss_idx)
while (!feof(f)) {
if (fgets(buf, sizeof(buf), f) == NULL)
break;
if (buf[0] == '#') {
printf("%s", buf);
continue;
}
cp = strchr(buf, '\n');
if (cp)
*cp = 0;

View File

@ -123,6 +123,8 @@ extern void do_set_block_group_descriptor(int argc, char **, int sci_idx, void *
extern void do_dump_unused(int argc, char **argv, int sci_idx, void *infop);
/* debugfs.c */
extern ss_request_table *extra_cmds;
extern const char *debug_prog_name;
extern void internal_dump_inode(FILE *, const char *, ext2_ino_t,
struct ext2_inode *, int);

View File

@ -59,7 +59,7 @@ static journal_t *current_journal = NULL;
static void journal_dump_trans(journal_transaction_t *trans EXT2FS_ATTR((unused)),
const char *tag EXT2FS_ATTR((unused)))
{
dbg_printf("TRANS %p(%s): tid=%d start=%llu block=%llu end=%llu "
dbg_printf("TRANS %p(%s): tid=%u start=%llu block=%llu end=%llu "
"flags=0x%x\n", trans, tag, trans->tid, trans->start,
trans->block, trans->end, trans->flags);
}
@ -915,7 +915,7 @@ void do_journal_open(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
}
journal = current_journal;
dbg_printf("JOURNAL: seq=%d tailseq=%d start=%lu first=%lu "
dbg_printf("JOURNAL: seq=%u tailseq=%u start=%lu first=%lu "
"maxlen=%lu\n", journal->j_tail_sequence,
journal->j_transaction_sequence, journal->j_tail,
journal->j_first, journal->j_last);

View File

@ -77,7 +77,7 @@ void do_extent_open(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
if (argc == 1) {
if (current_ino)
printf("Current inode is %d\n", current_ino);
printf("Current inode is %u\n", current_ino);
else
printf("No current inode\n");
return;
@ -107,7 +107,7 @@ void do_extent_open(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
cp = strchr(extent_prompt, ':');
if (cp)
*cp = 0;
sprintf(extent_prompt + strlen(extent_prompt), " (extent ino %d): ",
sprintf(extent_prompt + strlen(extent_prompt), " (extent ino %u): ",
current_ino);
ss_add_request_table(sci_idx, &extent_cmds, 1, &ret);
ss_set_prompt(sci_idx, extent_prompt);

View File

@ -301,7 +301,7 @@ void do_htree_dump(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version);
fprintf(pager, "\t Info length: %d\n", rootnode->info_length);
fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels);
fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags);
fprintf(pager, "\t Flags: %#x\n", rootnode->unused_flags);
ent = (struct ext2_dx_entry *)
((char *)rootnode + rootnode->info_length);

View File

@ -135,7 +135,7 @@ tst_problem: $(srcdir)/problem.c $(srcdir)/problem.h $(LIBEXT2FS) \
$(srcdir)/problem.c -DUNITTEST $(LIBEXT2FS) $(LIBCOM_ERR) \
$(LIBINTL) $(SYSLIBS)
tst_refcount: ea_refcount.c $(DEPLIBCOM_ERR)
tst_refcount: ea_refcount.c $(DEPLIBCOM_ERR) $(LIBEXT2FS)
$(E) " LD $@"
$(Q) $(CC) -o tst_refcount $(srcdir)/ea_refcount.c \
$(ALL_CFLAGS) $(ALL_LDFLAGS) -DTEST_PROGRAM \
@ -146,11 +146,11 @@ tst_logfile: $(srcdir)/logfile.c
$(Q) $(CC) -o tst_logfile $(srcdir)/logfile.c \
$(ALL_CFLAGS) $(ALL_LDFLAGS) -DTEST_PROGRAM $(SYSLIBS)
tst_region: region.c $(DEPLIBCOM_ERR)
tst_region: region.c $(DEPLIBCOM_ERR) $(LIBEXT2FS)
$(E) " LD $@"
$(Q) $(CC) -o tst_region $(srcdir)/region.c \
$(ALL_CFLAGS) $(ALL_LDFLAGS) -DTEST_PROGRAM \
$(LIBCOM_ERR) $(SYSLIBS)
$(LIBCOM_ERR) $(LIBEXT2FS) $(SYSLIBS)
fullcheck check:: tst_refcount tst_region tst_problem
$(TESTENV) ./tst_refcount

View File

@ -17,8 +17,8 @@
#include <ext2fs/tdb.h>
struct dir_info_db {
int count;
int size;
ext2_ino_t count;
ext2_ino_t size;
struct dir_info *array;
struct dir_info *last_lookup;
#ifdef CONFIG_TDB
@ -28,7 +28,7 @@ struct dir_info_db {
};
struct dir_info_iter {
int i;
ext2_ino_t i;
#ifdef CONFIG_TDB
TDB_DATA tdb_iter;
#endif
@ -46,7 +46,7 @@ static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir);
static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
{
struct dir_info_db *db = ctx->dir_info;
unsigned int threshold;
ext2_ino_t threshold;
errcode_t retval;
mode_t save_umask;
char *tdb_dir, uuid[40];
@ -130,12 +130,12 @@ static void setup_db(e2fsck_t ctx)
void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
{
struct dir_info *dir, *old_array;
int i, j;
ext2_ino_t i, j;
errcode_t retval;
unsigned long old_size;
#ifdef DIRINFO_DEBUG
printf("add_dir_info for inode (%lu, %lu)...\n", ino, parent);
printf("add_dir_info for inode (%u, %u)...\n", ino, parent);
#endif
if (!ctx->dir_info)
setup_db(ctx);
@ -149,7 +149,7 @@ void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
&ctx->dir_info->array);
if (retval) {
fprintf(stderr, "Couldn't reallocate dir_info "
"structure to %d entries\n",
"structure to %u entries\n",
ctx->dir_info->size);
fatal_error(ctx, 0);
ctx->dir_info->size -= 10;
@ -204,13 +204,13 @@ void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
{
struct dir_info_db *db = ctx->dir_info;
int low, high, mid;
ext2_ino_t low, high, mid;
if (!db)
return 0;
#ifdef DIRINFO_DEBUG
printf("e2fsck_get_dir_info %d...", ino);
printf("e2fsck_get_dir_info %u...", ino);
#endif
#ifdef CONFIG_TDB
@ -235,7 +235,7 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
ret_dir_info.dotdot = buf->dotdot;
ret_dir_info.parent = buf->parent;
#ifdef DIRINFO_DEBUG
printf("(%d,%d,%d)\n", ino, buf->dotdot, buf->parent);
printf("(%u,%u,%u)\n", ino, buf->dotdot, buf->parent);
#endif
free(data.dptr);
return &ret_dir_info;
@ -246,10 +246,10 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
return db->last_lookup;
low = 0;
high = ctx->dir_info->count-1;
high = ctx->dir_info->count - 1;
if (ino == ctx->dir_info->array[low].ino) {
#ifdef DIRINFO_DEBUG
printf("(%d,%d,%d)\n", ino,
printf("(%u,%u,%u)\n", ino,
ctx->dir_info->array[low].dotdot,
ctx->dir_info->array[low].parent);
#endif
@ -257,7 +257,7 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
}
if (ino == ctx->dir_info->array[high].ino) {
#ifdef DIRINFO_DEBUG
printf("(%d,%d,%d)\n", ino,
printf("(%u,%u,%u)\n", ino,
ctx->dir_info->array[high].dotdot,
ctx->dir_info->array[high].parent);
#endif
@ -265,12 +265,13 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
}
while (low < high) {
mid = (low+high)/2;
/* sum may overflow, but result will fit into mid again */
mid = (unsigned long long)(low + high) / 2;
if (mid == low || mid == high)
break;
if (ino == ctx->dir_info->array[mid].ino) {
#ifdef DIRINFO_DEBUG
printf("(%d,%d,%d)\n", ino,
printf("(%u,%u,%u)\n", ino,
ctx->dir_info->array[mid].dotdot,
ctx->dir_info->array[mid].parent);
#endif
@ -294,7 +295,7 @@ static void e2fsck_put_dir_info(e2fsck_t ctx EXT2FS_NO_TDB_UNUSED,
#endif
#ifdef DIRINFO_DEBUG
printf("e2fsck_put_dir_info (%d, %d, %d)...", dir->ino, dir->dotdot,
printf("e2fsck_put_dir_info (%u, %u, %u)...", dir->ino, dir->dotdot,
dir->parent);
#endif
@ -329,7 +330,7 @@ void e2fsck_free_dir_info(e2fsck_t ctx)
if (unlink(ctx->dir_info->tdb_fn) < 0)
com_err("e2fsck_free_dir_info", errno,
_("while freeing dir_info tdb file"));
free(ctx->dir_info->tdb_fn);
ext2fs_free_mem(&ctx->dir_info->tdb_fn);
}
#endif
if (ctx->dir_info->array)
@ -412,7 +413,7 @@ struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, struct dir_info_iter *iter)
return 0;
#ifdef DIRINFO_DEBUG
printf("iter(%d, %d, %d)...", ctx->dir_info->array[iter->i].ino,
printf("iter(%u, %u, %u)...", ctx->dir_info->array[iter->i].ino,
ctx->dir_info->array[iter->i].dotdot,
ctx->dir_info->array[iter->i].parent);
#endif

View File

@ -17,7 +17,7 @@ void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, struct ext2_inode *inode,
int num_blocks)
{
struct dx_dir_info *dir;
int i, j;
ext2_ino_t i, j;
errcode_t retval;
unsigned long old_size;
@ -41,7 +41,7 @@ void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, struct ext2_inode *inode,
&ctx->dx_dir_info);
if (retval) {
fprintf(stderr, "Couldn't reallocate dx_dir_info "
"structure to %d entries\n",
"structure to %u entries\n",
ctx->dx_dir_info_size);
fatal_error(ctx, 0);
ctx->dx_dir_info_size -= 10;
@ -73,11 +73,10 @@ void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, struct ext2_inode *inode,
dir->ino = ino;
dir->numblocks = num_blocks;
dir->hashversion = 0;
dir->casefolded_hash = inode->i_flags & EXT4_CASEFOLD_FL;
dir->casefolded_hash = !!(inode->i_flags & EXT4_CASEFOLD_FL);
dir->dx_block = e2fsck_allocate_memory(ctx, num_blocks
* sizeof (struct dx_dirblock_info),
"dx_block info array");
}
/*
@ -86,7 +85,7 @@ void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino, struct ext2_inode *inode,
*/
struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino)
{
int low, high, mid;
ext2_ino_t low, high, mid;
low = 0;
high = ctx->dx_dir_info_count-1;
@ -98,7 +97,8 @@ struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino)
return &ctx->dx_dir_info[high];
while (low < high) {
mid = (low+high)/2;
/* sum may overflow, but result will fit into mid again */
mid = (unsigned long long)(low + high) / 2;
if (mid == low || mid == high)
break;
if (ino == ctx->dx_dir_info[mid].ino)
@ -116,8 +116,8 @@ struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino)
*/
void e2fsck_free_dx_dir_info(e2fsck_t ctx)
{
int i;
struct dx_dir_info *dir;
ext2_ino_t i;
if (ctx->dx_dir_info) {
dir = ctx->dx_dir_info;
@ -137,7 +137,7 @@ void e2fsck_free_dx_dir_info(e2fsck_t ctx)
/*
* Return the count of number of directories in the dx_dir_info structure
*/
int e2fsck_get_num_dx_dirinfo(e2fsck_t ctx)
ext2_ino_t e2fsck_get_num_dx_dirinfo(e2fsck_t ctx)
{
return ctx->dx_dir_info_count;
}
@ -145,10 +145,10 @@ int e2fsck_get_num_dx_dirinfo(e2fsck_t ctx)
/*
* A simple interator function
*/
struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control)
struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, ext2_ino_t *control)
{
if (*control >= ctx->dx_dir_info_count)
return 0;
return(ctx->dx_dir_info + (*control)++);
return ctx->dx_dir_info + (*control)++;
}

View File

@ -104,12 +104,12 @@ struct dir_info {
* directories which contain a hash tree index.
*/
struct dx_dir_info {
ext2_ino_t ino; /* Inode number */
int numblocks; /* number of blocks */
int hashversion;
short depth; /* depth of tree */
struct dx_dirblock_info *dx_block; /* Array of size numblocks */
int casefolded_hash;
ext2_ino_t ino; /* Inode number */
short depth; /* depth of tree (15 bits) */
__u8 hashversion;
__u8 casefolded_hash:1;
blk_t numblocks; /* number of blocks in dir */
struct dx_dirblock_info *dx_block; /* Array of size numblocks */
};
#define DX_DIRBLOCK_ROOT 1
@ -120,8 +120,8 @@ struct dx_dir_info {
struct dx_dirblock_info {
int type;
blk64_t phys;
int flags;
blk64_t phys;
blk64_t parent;
blk64_t previous;
ext2_dirhash_t min_hash;
@ -238,12 +238,12 @@ struct e2fsck_struct {
char *problem_log_fn;
int flags; /* E2fsck internal flags */
int options;
int blocksize; /* blocksize */
unsigned blocksize; /* blocksize */
blk64_t use_superblock; /* sb requested by user */
blk64_t superblock; /* sb used to open fs */
blk64_t num_blocks; /* Total number of blocks */
blk64_t free_blocks;
ino_t free_inodes;
blk64_t free_blocks;
ext2_ino_t free_inodes;
int mount_flags;
int openfs_flags;
blkid_cache blkid; /* blkid cache */
@ -321,9 +321,9 @@ struct e2fsck_struct {
/*
* Indexed directory information
*/
int dx_dir_info_count;
int dx_dir_info_size;
struct dx_dir_info *dx_dir_info;
ext2_ino_t dx_dir_info_count;
ext2_ino_t dx_dir_info_size;
struct dx_dir_info *dx_dir_info;
/*
* Directories to hash
@ -485,8 +485,9 @@ extern void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino,
struct ext2_inode *inode, int num_blocks);
extern struct dx_dir_info *e2fsck_get_dx_dir_info(e2fsck_t ctx, ext2_ino_t ino);
extern void e2fsck_free_dx_dir_info(e2fsck_t ctx);
extern int e2fsck_get_num_dx_dirinfo(e2fsck_t ctx);
extern struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx, int *control);
extern ext2_ino_t e2fsck_get_num_dx_dirinfo(e2fsck_t ctx);
extern struct dx_dir_info *e2fsck_dx_dir_info_iter(e2fsck_t ctx,
ext2_ino_t *control);
/* ea_refcount.c */
typedef __u64 ea_key_t;
@ -614,7 +615,7 @@ int check_backup_super_block(e2fsck_t ctx);
void check_resize_inode(e2fsck_t ctx);
/* util.c */
extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
const char *description);
extern int ask(e2fsck_t ctx, const char * string, int def);
extern int ask_yn(e2fsck_t ctx, const char * string, int def);

View File

@ -53,10 +53,9 @@ errcode_t ea_refcount_create(size_t size, ext2_refcount_t *ret)
errcode_t retval;
size_t bytes;
retval = ext2fs_get_mem(sizeof(struct ea_refcount), &refcount);
retval = ext2fs_get_memzero(sizeof(struct ea_refcount), &refcount);
if (retval)
return retval;
memset(refcount, 0, sizeof(struct ea_refcount));
if (!size)
size = 500;
@ -66,10 +65,9 @@ errcode_t ea_refcount_create(size_t size, ext2_refcount_t *ret)
printf("Refcount allocated %zu entries, %zu bytes.\n",
refcount->size, bytes);
#endif
retval = ext2fs_get_mem(bytes, &refcount->list);
retval = ext2fs_get_memzero(bytes, &refcount->list);
if (retval)
goto errout;
memset(refcount->list, 0, bytes);
refcount->count = 0;
refcount->cursor = 0;

View File

@ -44,12 +44,11 @@ empty_dir_info init_empty_dir(e2fsck_t ctx)
empty_dir_info edi;
errcode_t retval;
edi = malloc(sizeof(struct empty_dir_info_struct));
if (!edi)
edi = e2fsck_allocate_memzero(ctx, sizeof(struct empty_dir_info_struct),
"empty dir info");
if (retval)
return NULL;
memset(edi, 0, sizeof(struct empty_dir_info_struct));
retval = ext2fs_init_dblist(ctx->fs, &edi->empty_dblist);
if (retval)
goto errout;
@ -83,7 +82,7 @@ void free_empty_dirblock(empty_dir_info edi)
ext2fs_free_inode_bitmap(edi->dir_map);
memset(edi, 0, sizeof(struct empty_dir_info_struct));
free(edi);
ext2fs_free_mem(&edi);
}
void add_empty_dirblock(empty_dir_info edi,
@ -182,13 +181,14 @@ void process_empty_dirblock(e2fsck_t ctx, empty_dir_info edi)
if (!edi)
return;
edi->block_buf = malloc(ctx->fs->blocksize * 3);
retval = ext2f_get_mem(ctx, ctx->fs->blocksize * 3,
&edi->block_buf);
if (edi->block_buf) {
(void) ext2fs_dblist_iterate2(edi->empty_dblist,
fix_directory, &edi);
}
free(edi->block_buf);
ext2fs_free_mem(&edi->block_buf);
free_empty_dirblock(edi);
}

View File

@ -31,6 +31,7 @@ int main(int argc, char **argv)
int nblocks, blocksize;
int fd;
char *block;
errcode_t retval;
int ret;
if (argc != 4)
@ -45,13 +46,12 @@ int main(int argc, char **argv)
exit(1);
}
block = malloc(blocksize);
if (block == 0) {
retval = ext2fs_get_memzero(blocksize, &block);
if (retval) {
fprintf(stderr, _("Couldn't allocate block buffer (size=%d)\n"),
blocksize);
exit(1);
}
memset(block, 0, blocksize);
fd = open(filename, O_RDWR);
if (fd < 0) {
@ -78,5 +78,6 @@ int main(int argc, char **argv)
perror("read");
exit(1);
}
exit(0);
ext2fs_free_mem(&block);
return(0);
}

View File

@ -322,7 +322,7 @@ err:
/* Rebuild the extents immediately */
static errcode_t e2fsck_rebuild_extents(e2fsck_t ctx, ext2_ino_t ino)
{
struct extent_list list;
struct extent_list list = { 0 };
errcode_t err;
if (!ext2fs_has_feature_extents(ctx->fs->super) ||
@ -331,9 +331,8 @@ static errcode_t e2fsck_rebuild_extents(e2fsck_t ctx, ext2_ino_t ino)
return 0;
e2fsck_read_bitmaps(ctx);
memset(&list, 0, sizeof(list));
err = ext2fs_get_mem(sizeof(struct ext2fs_extent) * NUM_EXTENTS,
&list.extents);
err = ext2fs_get_array(NUM_EXTENTS, sizeof(struct ext2fs_extent),
&list.extents);
if (err)
return err;
list.size = NUM_EXTENTS;
@ -349,7 +348,7 @@ static void rebuild_extents(e2fsck_t ctx, const char *pass_name, int pr_header)
#ifdef RESOURCE_TRACK
struct resource_track rtrack;
#endif
struct extent_list list;
struct extent_list list = { 0 };
int first = 1;
ext2_ino_t ino = 0;
errcode_t retval;
@ -369,10 +368,11 @@ static void rebuild_extents(e2fsck_t ctx, const char *pass_name, int pr_header)
clear_problem_context(&pctx);
e2fsck_read_bitmaps(ctx);
memset(&list, 0, sizeof(list));
retval = ext2fs_get_mem(sizeof(struct ext2fs_extent) * NUM_EXTENTS,
&list.extents);
list.size = NUM_EXTENTS;
retval = ext2fs_get_array(sizeof(struct ext2fs_extent),
list.size, &list.extents);
if (retval)
return;
while (1) {
retval = ext2fs_find_first_set_inode_bitmap2(
ctx->inodes_to_rebuild, ino + 1,

View File

@ -353,7 +353,7 @@ void set_up_logging(e2fsck_t ctx)
ctx->problem_log_fn);
}
#else
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
const char *description)
{
void *ret;

View File

@ -180,10 +180,10 @@ static void inode_dnode_free(dnode_t *node,
di = (struct dup_inode *) dnode_get(node);
for (p = di->cluster_list; p; p = next) {
next = p->next;
free(p);
ext2fs_free_mem(&p);
}
free(di);
free(node);
ext2fs_free_mem(&di);
ext2fs_free_mem(&node);
}
/*
@ -198,10 +198,10 @@ static void cluster_dnode_free(dnode_t *node,
dc = (struct dup_cluster *) dnode_get(node);
for (p = dc->inode_list; p; p = next) {
next = p->next;
free(p);
ext2fs_free_mem(&p);
}
free(dc);
free(node);
ext2fs_free_mem(&dc);
ext2fs_free_mem(&node);
}

View File

@ -73,8 +73,8 @@ static int allocate_dir_block(e2fsck_t ctx,
struct ext2_db_entry2 *dir_blocks_info,
char *buf, struct problem_context *pctx);
static void clear_htree(e2fsck_t ctx, ext2_ino_t ino);
static int htree_depth(struct dx_dir_info *dx_dir,
struct dx_dirblock_info *dx_db);
static short htree_depth(struct dx_dir_info *dx_dir,
struct dx_dirblock_info *dx_db);
static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b);
struct check_dir_struct {
@ -90,7 +90,7 @@ struct check_dir_struct {
static void update_parents(struct dx_dir_info *dx_dir, int type)
{
struct dx_dirblock_info *dx_db, *dx_parent, *dx_previous;
int b;
blk_t b;
for (b = 0, dx_db = dx_dir->dx_block;
b < dx_dir->numblocks;
@ -132,8 +132,9 @@ void e2fsck_pass2(e2fsck_t ctx)
struct check_dir_struct cd;
struct dx_dir_info *dx_dir;
struct dx_dirblock_info *dx_db;
int b;
int i, depth;
blk_t b;
ext2_ino_t i;
short depth;
problem_t code;
int bad_dir;
int (*check_dir_func)(ext2_filsys fs,
@ -309,10 +310,10 @@ cleanup:
}
#define MAX_DEPTH 32000
static int htree_depth(struct dx_dir_info *dx_dir,
struct dx_dirblock_info *dx_db)
static short htree_depth(struct dx_dir_info *dx_dir,
struct dx_dirblock_info *dx_db)
{
int depth = 0;
short depth = 0;
while (dx_db->type != DX_DIRBLOCK_ROOT && depth < MAX_DEPTH) {
dx_db = &dx_dir->dx_block[dx_db->parent];
@ -566,8 +567,8 @@ static void parse_int_node(ext2_filsys fs,
struct dx_dir_info *dx_dir,
char *block_buf, int failed_csum)
{
struct ext2_dx_root_info *root;
struct ext2_dx_entry *ent;
struct ext2_dx_root_info *root;
struct ext2_dx_entry *ent;
struct ext2_dx_countlimit *limit;
struct dx_dirblock_info *dx_db;
int i, expect_limit, count;
@ -583,10 +584,10 @@ static void parse_int_node(ext2_filsys fs,
#ifdef DX_DEBUG
printf("Root node dump:\n");
printf("\t Reserved zero: %u\n", root->reserved_zero);
printf("\t Hash Version: %d\n", root->hash_version);
printf("\t Info length: %d\n", root->info_length);
printf("\t Indirect levels: %d\n", root->indirect_levels);
printf("\t Flags: %d\n", root->unused_flags);
printf("\t Hash Version: %u\n", root->hash_version);
printf("\t Info length: %u\n", root->info_length);
printf("\t Indirect levels: %u\n", root->indirect_levels);
printf("\t Flags: %x\n", root->unused_flags);
#endif
ent = (struct ext2_dx_entry *) (block_buf + 24 + root->info_length);
@ -642,7 +643,7 @@ static void parse_int_node(ext2_filsys fs,
#endif
blk = ext2fs_le32_to_cpu(ent[i].block) & EXT4_DX_BLOCK_MASK;
/* Check to make sure the block is valid */
if (blk >= (blk_t) dx_dir->numblocks) {
if (blk >= dx_dir->numblocks) {
cd->pctx.blk = blk;
if (fix_problem(cd->ctx, PR_2_HTREE_BADBLK,
&cd->pctx))

View File

@ -842,7 +842,7 @@ static void check_inode_end(e2fsck_t ctx)
clear_problem_context(&pctx);
end = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
end = (__u64)EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
pctx.errcode = ext2fs_fudge_inode_bitmap_end(fs->inode_map, end,
&save_inodes_count);
if (pctx.errcode) {

View File

@ -36,11 +36,12 @@ struct region_struct {
region_t region_create(region_addr_t min, region_addr_t max)
{
region_t region;
errcode_t retval;
region = malloc(sizeof(struct region_struct));
if (!region)
retval = ext2fs_get_memzero(sizeof(struct region_struct), &region);
if (retval)
return NULL;
memset(region, 0, sizeof(struct region_struct));
region->min = min;
region->max = max;
region->last = NULL;
@ -53,16 +54,17 @@ void region_free(region_t region)
for (r = region->allocated; r; r = next) {
next = r->next;
free(r);
ext2fs_free_mem(&r);
}
memset(region, 0, sizeof(struct region_struct));
free(region);
ext2fs_free_mem(&region);
}
int region_allocate(region_t region, region_addr_t start, int n)
{
struct region_el *r, *new_region, *prev, *next;
region_addr_t end;
errcode_t retval;
end = start+n;
if ((start < region->min) || (end > region->max))
@ -105,7 +107,7 @@ int region_allocate(region_t region, region_addr_t start, int n)
if (end == next->start) {
r->end = next->end;
r->next = next->next;
free(next);
ext2fs_free_mem(&next);
if (!r->next)
region->last = r;
return 0;
@ -121,8 +123,8 @@ int region_allocate(region_t region, region_addr_t start, int n)
* Insert a new region element structure into the linked list
*/
append_to_list:
new_region = malloc(sizeof(struct region_el));
if (!new_region)
retval = ext2fs_get_mem(sizeof(struct region_el), &new_region);
if (retval)
return -1;
new_region->start = start;
new_region->end = start + n;

View File

@ -80,10 +80,10 @@ struct fill_dir_struct {
errcode_t err;
e2fsck_t ctx;
struct hash_entry *harray;
int max_array, num_array;
unsigned int dir_size;
blk_t max_array, num_array;
ext2_off64_t dir_size;
int compress;
ino_t parent;
ext2_ino_t parent;
ext2_ino_t dir;
};
@ -95,8 +95,8 @@ struct hash_entry {
};
struct out_dir {
int num;
int max;
blk_t num;
blk_t max;
char *buf;
ext2_dirhash_t *hashes;
};
@ -173,13 +173,16 @@ static int fill_dir_block(ext2_filsys fs,
continue;
}
if (fd->num_array >= fd->max_array) {
new_array = realloc(fd->harray,
sizeof(struct hash_entry) * (fd->max_array+500));
if (!new_array) {
fd->err = ENOMEM;
errcode_t retval;
retval = ext2fs_resize_array(sizeof(struct hash_entry),
fd->max_array,
fd->max_array + 500,
&fd->harray);
if (retval) {
fd->err = retval;
return BLOCK_ABORT;
}
fd->harray = new_array;
fd->max_array += 500;
}
ent = fd->harray + fd->num_array++;
@ -260,27 +263,28 @@ static EXT2_QSORT_TYPE hash_cmp(const void *a, const void *b)
}
static errcode_t alloc_size_dir(ext2_filsys fs, struct out_dir *outdir,
int blocks)
blk_t blocks)
{
void *new_mem;
errcode_t retval;
if (outdir->max) {
new_mem = realloc(outdir->buf, blocks * fs->blocksize);
if (!new_mem)
return ENOMEM;
outdir->buf = new_mem;
new_mem = realloc(outdir->hashes,
blocks * sizeof(ext2_dirhash_t));
if (!new_mem)
return ENOMEM;
outdir->hashes = new_mem;
retval = ext2fs_resize_array(fs->blocksize, outdir->max, blocks,
&outdir->buf);
if (retval)
return retval;
retval = ext2fs_resize_array(sizeof(ext2_dirhash_t),
outdir->max, blocks,
&outdir->hashes);
if (retval)
return retval;
} else {
outdir->buf = malloc(blocks * fs->blocksize);
if (!outdir->buf)
return ENOMEM;
outdir->hashes = malloc(blocks * sizeof(ext2_dirhash_t));
if (!outdir->hashes)
return ENOMEM;
retval = ext2fs_get_array(fs->blocksize, blocks, &outdir->buf);
if (retval)
return retval;
retval = ext2fs_get_array(sizeof(ext2_dirhash_t), blocks,
&outdir->hashes);
if (retval)
return retval;
outdir->num = 0;
}
outdir->max = blocks;
@ -309,7 +313,7 @@ static errcode_t get_next_block(ext2_filsys fs, struct out_dir *outdir,
if (retval)
return retval;
}
*ret = outdir->buf + (outdir->num++ * fs->blocksize);
*ret = outdir->buf + (size_t)outdir->num++ * fs->blocksize;
memset(*ret, 0, fs->blocksize);
return 0;
}
@ -379,8 +383,8 @@ static int duplicate_search_and_fix(e2fsck_t ctx, ext2_filsys fs,
struct fill_dir_struct *fd)
{
struct problem_context pctx;
struct hash_entry *ent, *prev;
int i, j;
struct hash_entry *ent, *prev;
blk_t i, j;
int fixed = 0;
char new_name[256];
unsigned int new_len;
@ -897,14 +901,14 @@ errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino,
(inode.i_flags & EXT4_INLINE_DATA_FL))
return 0;
retval = ENOMEM;
dir_buf = malloc(inode.i_size);
if (!dir_buf)
retval = ext2fs_get_mem(inode.i_size, &dir_buf);
if (retval)
goto errout;
fd.max_array = inode.i_size / 32;
fd.harray = malloc(fd.max_array * sizeof(struct hash_entry));
if (!fd.harray)
retval = ext2fs_get_array(sizeof(struct hash_entry),
fd.max_array, &fd.harray);
if (retval)
goto errout;
fd.ino = ino;
@ -993,8 +997,8 @@ resort:
else
retval = e2fsck_check_rebuild_extents(ctx, ino, &inode, pctx);
errout:
free(dir_buf);
free(fd.harray);
ext2fs_free_mem(&dir_buf);
ext2fs_free_mem(&fd.harray);
free_out_dir(&outdir);
return retval;

View File

@ -76,8 +76,8 @@ static void print_resource_track(struct resource_track *track)
gettimeofday(&time_end, 0);
getrusage(RUSAGE_SELF, &r);
printf(_("Memory used: %d, elapsed time: %6.3f/%6.3f/%6.3f\n"),
(int) (((char *) sbrk(0)) - ((char *) track->brk_start)),
printf(_("Memory used: %lu, elapsed time: %6.3f/%6.3f/%6.3f\n"),
(unsigned long)((char *)sbrk(0) - (char *)track->brk_start),
timeval_subtract(&time_end, &track->time_start),
timeval_subtract(&r.ru_utime, &track->user_start),
timeval_subtract(&r.ru_stime, &track->system_start));

View File

@ -595,7 +595,7 @@ void check_super_block(e2fsck_t ctx)
blk64_t should_be;
struct problem_context pctx;
blk64_t free_blocks = 0;
ino_t free_inodes = 0;
ext2_ino_t free_inodes = 0;
int csum_flag, clear_test_fs_flag;
inodes_per_block = EXT2_INODES_PER_BLOCK(fs->super);

View File

@ -116,7 +116,7 @@ void log_err(e2fsck_t ctx, const char *fmt, ...)
}
}
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
const char *description)
{
void *ret;
@ -125,13 +125,12 @@ void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
#ifdef DEBUG_ALLOCATE_MEMORY
printf("Allocating %u bytes for %s...\n", size, description);
#endif
ret = malloc(size);
if (!ret) {
if (ext2fs_get_memzero(size, &ret)) {
sprintf(buf, "Can't allocate %u bytes for %s\n",
size, description);
fatal_error(ctx, buf);
}
memset(ret, 0, size);
return ret;
}
@ -421,9 +420,6 @@ void print_resource_track(e2fsck_t ctx, const char *desc,
{
#ifdef HAVE_GETRUSAGE
struct rusage r;
#endif
#ifdef HAVE_MALLINFO
struct mallinfo malloc_info;
#endif
struct timeval time_end;
@ -437,18 +433,21 @@ void print_resource_track(e2fsck_t ctx, const char *desc,
if (desc)
log_out(ctx, "%s: ", desc);
#define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
#ifdef HAVE_MALLINFO
#define kbytes(x) (((unsigned long)(x) + 1023) / 1024)
/* don't use mallinfo() if over 2GB used, since it returns "int" */
if ((char *)sbrk(0) - (char *)track->brk_start < 2ULL << 30) {
struct mallinfo malloc_info = mallinfo();
malloc_info = mallinfo();
log_out(ctx, _("Memory used: %luk/%luk (%luk/%luk), "),
kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
#else
log_out(ctx, _("Memory used: %lu, "),
(unsigned long) (((char *) sbrk(0)) -
((char *) track->brk_start)));
log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
kbytes(malloc_info.uordblks),
kbytes(malloc_info.fordblks));
} else
#endif
log_out(ctx, _("Memory used: %lluk, "),
kbytes(((char *)sbrk(0)) - ((char *)track->brk_start)));
#ifdef HAVE_GETRUSAGE
getrusage(RUSAGE_SELF, &r);

View File

@ -377,7 +377,7 @@ extent_cmds.c extent_cmds.h: $(top_srcdir)/debugfs/extent_cmds.ct
debugfs.o: $(top_srcdir)/debugfs/debugfs.c
$(E) " CC $<"
$(Q) $(CC) $(DEBUGFS_CFLAGS) -c $< -o $@
$(Q) $(CC) $(DEBUGFS_CFLAGS) -DSKIP_GLOBDEFS -c $< -o $@
extent_inode.o: $(top_srcdir)/debugfs/extent_inode.c
$(E) " CC $<"

View File

@ -62,7 +62,8 @@ errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
start = 1;
end = fs->super->s_inodes_count;
real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count);
real_end = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
fs->group_desc_count;
/* Are we permitted to use new-style bitmaps? */
if (fs->flags & EXT2_FLAG_64BITS)

View File

@ -1769,6 +1769,8 @@ extern errcode_t ext2fs_get_arrayzero(unsigned long count,
extern errcode_t ext2fs_free_mem(void *ptr);
extern errcode_t ext2fs_resize_mem(unsigned long old_size,
unsigned long size, void *ptr);
extern errcode_t ext2fs_resize_array(unsigned long old_count, unsigned long count,
unsigned long size, void *ptr);
extern void ext2fs_mark_super_dirty(ext2_filsys fs);
extern void ext2fs_mark_changed(ext2_filsys fs);
extern int ext2fs_test_changed(ext2_filsys fs);
@ -1846,7 +1848,8 @@ _INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr)
return 0;
}
_INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr)
_INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size,
void *ptr)
{
if (count && (~0UL)/count < size)
return EXT2_ET_NO_MEMORY;
@ -1856,15 +1859,10 @@ _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, voi
_INLINE_ errcode_t ext2fs_get_arrayzero(unsigned long count,
unsigned long size, void *ptr)
{
void *pp;
if (count && (~0UL)/count < size)
return EXT2_ET_NO_MEMORY;
pp = calloc(count, size);
if (!pp)
return EXT2_ET_NO_MEMORY;
memcpy(ptr, &pp, sizeof(pp));
return 0;
return ext2fs_get_memzero((size_t)count * size, ptr);
}
/*
@ -1898,6 +1896,36 @@ _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_siz
memcpy(ptr, &p, sizeof(p));
return 0;
}
/*
* Resize array. The 'ptr' arg must point to a pointer.
*/
_INLINE_ errcode_t ext2fs_resize_array(unsigned long size,
unsigned long old_count,
unsigned long count, void *ptr)
{
unsigned long old_size;
errcode_t retval;
if (count && (~0UL)/count < size)
return EXT2_ET_NO_MEMORY;
size *= count;
old_size = size * old_count;
retval = ext2fs_resize_mem(old_size, size, ptr);
if (retval)
return retval;
if (size > old_size) {
void *p;
memcpy(&p, ptr, sizeof(p));
memset((char *)p + old_size, 0, size - old_size);
memcpy(ptr, &p, sizeof(p));
}
return 0;
}
#endif /* Custom memory routines */
/*

View File

@ -61,19 +61,20 @@ static int check_zero_block(char *buf, int blocksize)
errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
{
unsigned int group, left, c, d;
dgrp_t group;
ssize_t left, c, d;
char *buf, *cp;
blk64_t blk;
ssize_t actual;
errcode_t retval;
off_t r;
loff_t r;
buf = malloc(fs->blocksize * BUF_BLOCKS);
if (!buf)
return ENOMEM;
for (group = 0; group < fs->group_desc_count; group++) {
blk = ext2fs_inode_table_loc(fs, (unsigned)group);
blk = ext2fs_inode_table_loc(fs, group);
if (!blk) {
retval = EXT2_ET_MISSING_INODE_TABLE;
goto errout;
@ -107,23 +108,25 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
continue;
}
/* Find non-zero blocks */
for (d=1; d < c; d++) {
if (check_zero_block(cp + d*fs->blocksize, fs->blocksize))
for (d = 1; d < c; d++) {
if (check_zero_block(cp +
d * fs->blocksize,
fs->blocksize))
break;
}
skip_sparse:
actual = write(fd, cp, fs->blocksize * d);
actual = write(fd, cp, d * fs->blocksize);
if (actual == -1) {
retval = errno;
goto errout;
}
if (actual != (ssize_t) (fs->blocksize * d)) {
if (actual != d * fs->blocksize) {
retval = EXT2_ET_SHORT_WRITE;
goto errout;
}
blk += d;
left -= d;
cp += fs->blocksize * d;
cp += d * fs->blocksize;
c -= d;
}
}
@ -141,7 +144,8 @@ errout:
errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
int flags EXT2FS_ATTR((unused)))
{
unsigned int group, c, left;
dgrp_t group;
ssize_t c, left;
char *buf;
blk64_t blk;
ssize_t actual;
@ -152,7 +156,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
return ENOMEM;
for (group = 0; group < fs->group_desc_count; group++) {
blk = ext2fs_inode_table_loc(fs, (unsigned)group);
blk = ext2fs_inode_table_loc(fs, group);
if (!blk) {
retval = EXT2_ET_MISSING_INODE_TABLE;
goto errout;
@ -167,7 +171,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
retval = errno;
goto errout;
}
if (actual != (ssize_t) (fs->blocksize * c)) {
if (actual != fs->blocksize * c) {
retval = EXT2_ET_SHORT_READ;
goto errout;
}
@ -252,7 +256,7 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
}
#endif
actual = write(fd, cp, fs->blocksize * fs->desc_blocks);
actual = write(fd, cp, (ssize_t)fs->blocksize * fs->desc_blocks);
#ifdef WORDS_BIGENDIAN
@ -268,7 +272,7 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
retval = errno;
goto errout;
}
if (actual != (ssize_t) (fs->blocksize * fs->desc_blocks)) {
if (actual != (ssize_t)fs->blocksize * fs->desc_blocks) {
retval = EXT2_ET_SHORT_WRITE;
goto errout;
}
@ -290,7 +294,7 @@ errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
ssize_t actual, size;
errcode_t retval;
size = fs->blocksize * (fs->group_desc_count + 1);
size = (ssize_t)fs->blocksize * (fs->group_desc_count + 1);
buf = malloc(size);
if (!buf)
return ENOMEM;
@ -314,7 +318,7 @@ errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd,
memcpy(fs->super, buf, SUPERBLOCK_SIZE);
memcpy(fs->group_desc, buf + fs->blocksize,
fs->blocksize * fs->group_desc_count);
(ssize_t)fs->blocksize * fs->group_desc_count);
retval = 0;
@ -343,7 +347,8 @@ errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags)
}
bmap = fs->inode_map;
itr = 1;
cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
cnt = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
fs->group_desc_count;
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
} else {
if (!fs->block_map) {
@ -418,7 +423,8 @@ errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags)
}
bmap = fs->inode_map;
itr = 1;
cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count;
cnt = (__u64)EXT2_INODES_PER_GROUP(fs->super) *
fs->group_desc_count;
size = (EXT2_INODES_PER_GROUP(fs->super) / 8);
} else {
if (!fs->block_map) {

View File

@ -309,6 +309,7 @@ errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
{
scan->current_group = group - 1;
scan->groups_left = scan->fs->group_desc_count - group;
scan->bad_block_ptr = 0;
return get_next_blockgroup(scan);
}
@ -332,6 +333,12 @@ static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan,
if (blk == 0)
return 0;
/* Make sure bad_block_ptr is still valid */
if (scan->bad_block_ptr >= bb->num) {
scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS;
return 0;
}
/*
* If the current block is greater than the bad block listed
* in the bad block list, then advance the pointer until this

View File

@ -352,6 +352,7 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
char *mtpt, int mtlen)
{
errcode_t retval = 0;
int busy = 0;
if (getenv("EXT2FS_PRETEND_RO_MOUNT")) {
*mount_flags = EXT2_MF_MOUNTED | EXT2_MF_READONLY;
@ -366,6 +367,30 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
return 0;
}
#ifdef __linux__ /* This only works on Linux 2.6+ systems */
{
struct stat st_buf;
if (stat(device, &st_buf) == 0 &&
ext2fsP_is_disk_device(st_buf.st_mode)) {
int fd = open(device, O_RDONLY | O_EXCL);
if (fd >= 0) {
/*
* The device is not busy so it's
* definitelly not mounted. No need to
* to perform any more checks.
*/
close(fd);
*mount_flags = 0;
return 0;
} else if (errno == EBUSY) {
busy = 1;
}
}
}
#endif
if (is_swap_device(device)) {
*mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP;
strncpy(mtpt, "<swap>", mtlen);
@ -386,21 +411,8 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
if (retval)
return retval;
#ifdef __linux__ /* This only works on Linux 2.6+ systems */
{
struct stat st_buf;
if (stat(device, &st_buf) == 0 &&
ext2fsP_is_disk_device(st_buf.st_mode)) {
int fd = open(device, O_RDONLY | O_EXCL);
if (fd >= 0)
close(fd);
else if (errno == EBUSY)
*mount_flags |= EXT2_MF_BUSY;
}
}
#endif
if (busy)
*mount_flags |= EXT2_MF_BUSY;
return 0;
}

View File

@ -57,8 +57,21 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
* regardless of how the io_manager is doing reads, to avoid caching of
* the MMP block by the io_manager or the VM. It needs to be fresh. */
if (fs->mmp_fd <= 0) {
fs->mmp_fd = open(fs->device_name, O_RDWR | O_DIRECT);
int flags = O_RDWR | O_DIRECT;
retry:
fs->mmp_fd = open(fs->device_name, flags);
if (fs->mmp_fd < 0) {
struct stat st;
/* Avoid O_DIRECT for filesystem image files if open
* fails, since it breaks when running on tmpfs. */
if (errno == EINVAL && (flags & O_DIRECT) &&
stat(fs->device_name, &st) == 0 &&
S_ISREG(st.st_mode)) {
flags &= ~O_DIRECT;
goto retry;
}
retval = EXT2_ET_MMP_OPEN_DIRECT;
goto out;
}

View File

@ -416,10 +416,11 @@ errcode_t ext2fs_dirent_swab_in2(ext2_filsys fs, char *buf,
errcode_t retval;
char *p, *end;
struct ext2_dir_entry *dirent;
unsigned int name_len, rec_len;
unsigned int name_len, rec_len, left;
p = (char *) buf;
end = (char *) buf + size;
left = size;
while (p < end-8) {
dirent = (struct ext2_dir_entry *) p;
dirent->inode = ext2fs_swab32(dirent->inode);
@ -436,6 +437,9 @@ errcode_t ext2fs_dirent_swab_in2(ext2_filsys fs, char *buf,
retval = EXT2_ET_DIR_CORRUPTED;
} else if (((name_len & 0xFF) + 8) > rec_len)
retval = EXT2_ET_DIR_CORRUPTED;
if (rec_len > left)
return EXT2_ET_DIR_CORRUPTED;
left -= rec_len;
p += rec_len;
}
@ -452,11 +456,12 @@ errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf,
{
errcode_t retval;
char *p, *end;
unsigned int rec_len;
unsigned int rec_len, left;
struct ext2_dir_entry *dirent;
p = buf;
end = buf + size;
left = size;
while (p < end) {
dirent = (struct ext2_dir_entry *) p;
retval = ext2fs_get_rec_len(fs, dirent, &rec_len);
@ -471,6 +476,9 @@ errcode_t ext2fs_dirent_swab_out2(ext2_filsys fs, char *buf,
dirent->inode = ext2fs_swab32(dirent->inode);
dirent->rec_len = ext2fs_swab16(dirent->rec_len);
dirent->name_len = ext2fs_swab16(dirent->name_len);
if (rec_len > size)
return EXT2_ET_DIR_CORRUPTED;
size -= rec_len;
if (flags & EXT2_DIRBLOCK_V2_STRUCT)
dirent->name_len = ext2fs_swab16(dirent->name_len);

View File

@ -79,20 +79,25 @@ Set the file's version/generation number.
.BI \-p " project"
Set the file's project number.
.SH ATTRIBUTES
.TP
.B a
A file with the 'a' attribute set can only be opened in append mode for
writing. Only the superuser or a process possessing the
CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
.PP
.TP
.B A
When a file with the 'A' attribute set is accessed, its atime record is
not modified. This avoids a certain amount of disk I/O for laptop
systems.
.PP
.TP
.B c
A file with the 'c' attribute set is automatically compressed on the disk
by the kernel. A read from this file returns uncompressed data. A write to
this file compresses data before storing them on the disk. Note: please
make sure to read the bugs and limitations section at the end of this
document.
.PP
.TP
.B C
A file with the 'C' attribute set will not be subject to copy-on-write
updates. This flag is only supported on file systems which perform
copy-on-write. (Note: For btrfs, the 'C' flag should be
@ -101,42 +106,50 @@ data blocks, it is undefined when the blocks assigned to the file will
be fully stable. If the 'C' flag is set on a directory, it will have no
effect on the directory, but new files created in that directory will
have the No_COW attribute set.)
.PP
.TP
.B d
A file with the 'd' attribute set is not a candidate for backup when the
.BR dump (8)
program is run.
.PP
.TP
.B D
When a directory with the 'D' attribute set is modified,
the changes are written synchronously to the disk; this is equivalent to
the 'dirsync' mount option applied to a subset of the files.
.PP
.TP
.B e
The 'e' attribute indicates that the file is using extents for mapping
the blocks on disk. It may not be removed using
.BR chattr (1).
.PP
.TP
.B E
A file, directory, or symlink with the 'E' attribute set is encrypted by the
filesystem. This attribute may not be set or cleared using
.BR chattr (1),
although it can be displayed by
.BR lsattr (1).
.PP
.TP
.B F
A directory with the 'F' attribute set indicates that all the path
lookups inside that directory are made in a case-insensitive fashion.
This attribute can only be changed in empty directories on file systems
with the casefold feature enabled.
.PP
.TP
.B i
A file with the 'i' attribute cannot be modified: it cannot be deleted or
renamed, no link can be created to this file, most of the file's
metadata can not be modified, and the file can not be opened in write mode.
Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE
capability can set or clear this attribute.
.PP
.TP
.B I
The 'I' attribute is used by the htree code to indicate that a directory
is being indexed using hashed trees. It may not be set or cleared using
.BR chattr (1),
although it can be displayed by
.BR lsattr (1).
.PP
.TP
.B j
A file with the 'j' attribute has all of its data written to the ext3 or
ext4 journal before being written to the file itself, if the file system
is mounted with the "data=ordered" or "data=writeback" options and the
@ -144,14 +157,16 @@ file system has a journal. When the filesystem is mounted with the
"data=journal" option all file data is already journalled and this
attribute has no effect. Only the superuser or a process possessing the
CAP_SYS_RESOURCE capability can set or clear this attribute.
.PP
.TP
.B N
A file with the 'N' attribute set indicates that the file has data
stored inline, within the inode itself. It may not be set or cleared
using
.BR chattr (1),
although it can be displayed by
.BR lsattr (1).
.PP
.TP
.B P
A directory with the 'P' attribute set will enforce a hierarchical
structure for project id's. This means that files and directory created
in the directory will inherit the project id of the directory, rename
@ -159,22 +174,26 @@ operations are constrained so when a file or directory is moved into
another directory, that the project id's much match. In addition, a
hard link to file can only be created when the project id for the file
and the destination directory match.
.PP
.TP
.B s
When a file with the 's' attribute set is deleted, its blocks are zeroed
and written back to the disk. Note: please make sure to read the bugs
and limitations section at the end of this document.
.PP
.TP
.B S
When a file with the 'S' attribute set is modified,
the changes are written synchronously to the disk; this is equivalent to
the 'sync' mount option applied to a subset of the files.
.PP
.TP
.B t
A file with the 't' attribute will not have a partial block fragment at
the end of the file merged with other files (for those filesystems which
support tail-merging). This is necessary for applications such as LILO
which read the filesystem directly, and which don't understand tail-merged
files. Note: As of this writing, the ext2, ext3, and ext4 filesystems do
not support tail-merging.
.PP
.TP
.B T
A directory with the 'T' attribute will be deemed to be the top of
directory hierarchies for the purposes of the Orlov block allocator.
This is a hint to the block allocator used by ext3 and ext4 that the
@ -184,12 +203,14 @@ idea to set the 'T' attribute on the /home directory, so that /home/john
and /home/mary are placed into separate block groups. For directories
where this attribute is not set, the Orlov block allocator will try to
group subdirectories closer together where possible.
.PP
.TP
.B u
When a file with the 'u' attribute set is deleted, its contents are
saved. This allows the user to ask for its undeletion. Note: please
make sure to read the bugs and limitations section at the end of this
document.
.PP
.TP
.B V
A file with the 'V' attribute set has fs-verity enabled. It cannot be
written to, and the filesystem will automatically verify all data read
from it against a cryptographic hash that covers the entire file's

View File

@ -124,7 +124,7 @@ static errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t ino,
ext2fs_set_i_uid_high(inode, st->st_uid >> 16);
inode.i_gid = st->st_gid;
ext2fs_set_i_gid_high(inode, st->st_gid >> 16);
inode.i_mode |= st->st_mode;
inode.i_mode = (LINUX_S_IFMT & inode.i_mode) | (~S_IFMT & st->st_mode);
inode.i_atime = st->st_atime;
inode.i_mtime = st->st_mtime;
inode.i_ctime = st->st_ctime;
@ -601,7 +601,7 @@ out:
return err;
}
static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ino_t ino)
static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ext2_ino_t ino)
{
int i;
@ -662,7 +662,7 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src,
com_err(__func__, 0, "Warning: inode already set");
ext2fs_inode_alloc_stats2(fs, newfile, +1, 0);
memset(&inode, 0, sizeof(inode));
inode.i_mode = (statbuf.st_mode & ~LINUX_S_IFMT) | LINUX_S_IFREG;
inode.i_mode = (statbuf.st_mode & ~S_IFMT) | LINUX_S_IFREG;
inode.i_atime = inode.i_ctime = inode.i_mtime =
fs->now ? fs->now : time(0);
inode.i_links_count = 1;

View File

@ -362,7 +362,7 @@ static void print_inline_journal_information(ext2_filsys fs)
struct ext2_inode inode;
ext2_file_t journal_file;
errcode_t retval;
ino_t ino = fs->super->s_journal_inum;
ext2_ino_t ino = fs->super->s_journal_inum;
char buf[1024];
if (fs->flags & EXT2_FLAG_IMAGE_FILE)

View File

@ -181,9 +181,9 @@ static int process_fs(const char *fsname)
int flags, fd;
ext2_filsys fs = NULL;
ext2fs_block_bitmap corrupt_map;
off_t hsize, count, off, offset, corrupt_bytes;
loff_t hsize, count, off, offset, corrupt_bytes;
unsigned char c;
off_t i;
loff_t i;
/* If mounted rw, force dryrun mode */
ret = ext2fs_check_if_mounted(fsname, &flags);
@ -277,8 +277,8 @@ static int process_fs(const char *fsname)
c |= 0x80;
if (verbose)
printf("Corrupting byte %lld in block %lld to 0x%x\n",
(long long) off % fs->blocksize,
(long long) off / fs->blocksize, c);
off % fs->blocksize,
off / fs->blocksize, c);
if (dryrun)
continue;
#ifdef HAVE_PWRITE64

View File

@ -312,7 +312,7 @@ struct process_block_struct {
* structure, so there's no point in letting the ext2fs library read
* the inode again.
*/
static ino_t stashed_ino = 0;
static ext2_ino_t stashed_ino = 0;
static struct ext2_inode *stashed_inode;
static errcode_t meta_get_blocks(ext2_filsys fs EXT2FS_ATTR((unused)),

View File

@ -33,8 +33,8 @@ testing purposes.
.BI \-b blocksize
Use
.I blocksize
in bytes for output instead of the filesystem blocksize.
For compatibility with earlier versions of
in bytes, or with [KMG] suffix, up to 1GB for output instead of the
filesystem blocksize. For compatibility with earlier versions of
.BR filefrag ,
if
.I blocksize

View File

@ -53,7 +53,7 @@ extern int optind;
#include <ext2fs/fiemap.h>
int verbose = 0;
int blocksize; /* Use specified blocksize (default 1kB) */
unsigned int blocksize; /* Use specified blocksize (default 1kB) */
int sync_file = 0; /* fsync file before getting the mapping */
int precache_file = 0; /* precache the file before getting the mapping */
int xattr_map = 0; /* get xattr mapping */
@ -75,7 +75,7 @@ const char *hex_fmt = "%4d: %*llx..%*llx: %*llx..%*llx: %6llx: %s\n";
#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
#define EXT3_IOC_GETFLAGS _IOR('f', 1, long)
static int int_log2(int arg)
static int ulong_log2(unsigned long arg)
{
int l = 0;
@ -87,7 +87,7 @@ static int int_log2(int arg)
return l;
}
static int int_log10(unsigned long long arg)
static int ulong_log10(unsigned long long arg)
{
int l = 0;
@ -472,20 +472,20 @@ static int frag_report(const char *filename)
}
last_device = st.st_dev;
width = int_log10(fsinfo.f_blocks);
width = ulong_log10(fsinfo.f_blocks);
if (width > physical_width)
physical_width = width;
numblocks = (st.st_size + blksize - 1) / blksize;
if (blocksize != 0)
blk_shift = int_log2(blocksize);
blk_shift = ulong_log2(blocksize);
else
blk_shift = int_log2(blksize);
blk_shift = ulong_log2(blksize);
if (use_extent_cache)
width = 10;
else
width = int_log10(numblocks);
width = ulong_log10(numblocks);
if (width > logical_width)
logical_width = width;
if (verbose) {
@ -558,7 +558,7 @@ out_close:
static void usage(const char *progname)
{
fprintf(stderr, "Usage: %s [-b{blocksize}] [-BeEksvxX] file ...\n",
fprintf(stderr, "Usage: %s [-b{blocksize}[KMG]] [-BeEksvxX] file ...\n",
progname);
exit(1);
}
@ -576,7 +576,9 @@ int main(int argc, char**argv)
case 'b':
if (optarg) {
char *end;
blocksize = strtoul(optarg, &end, 0);
unsigned long val;
val = strtoul(optarg, &end, 0);
if (end) {
#if __GNUC_PREREQ (7, 0)
#pragma GCC diagnostic push
@ -585,15 +587,15 @@ int main(int argc, char**argv)
switch (end[0]) {
case 'g':
case 'G':
blocksize *= 1024;
val *= 1024;
/* fall through */
case 'm':
case 'M':
blocksize *= 1024;
val *= 1024;
/* fall through */
case 'k':
case 'K':
blocksize *= 1024;
val *= 1024;
break;
default:
break;
@ -602,6 +604,16 @@ int main(int argc, char**argv)
#pragma GCC diagnostic pop
#endif
}
/* Specifying too large a blocksize will just
* shift all extents down to zero length. Even
* 1GB is questionable, but caveat emptor. */
if (val > 1024 * 1024 * 1024) {
fprintf(stderr,
"%s: blocksize %lu over 1GB\n",
argv[0], val);
usage(argv[0]);
}
blocksize = val;
} else { /* Allow -b without argument for compat. Remove
* this eventually so "-b {blocksize}" works */
fprintf(stderr, "%s: -b needs a blocksize "

View File

@ -2358,7 +2358,7 @@ static int op_statfs(const char *path EXT2FS_ATTR((unused)),
overhead = 0;
else
overhead = fs->desc_blocks +
fs->group_desc_count *
(blk64_t)fs->group_desc_count *
(fs->inode_blocks_per_group + 2);
reserved = ext2fs_r_blocks_count(fs->super);
if (!reserved)

View File

@ -369,7 +369,7 @@ static errcode_t remove_journal_inode(ext2_filsys fs)
{
struct ext2_inode inode;
errcode_t retval;
ino_t ino = fs->super->s_journal_inum;
ext2_ino_t ino = fs->super->s_journal_inum;
retval = ext2fs_read_inode(fs, ino, &inode);
if (retval) {

View File

@ -1,16 +1,5 @@
FSCK_OPT=-yf
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ]; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
echo "make the test image ..." > $test_name.log
$MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1
status=$?

View File

@ -1,16 +1,5 @@
FSCK_OPT=-yf
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ] ; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
echo "make the test image ..." > $test_name.log
$MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1
status=$?

View File

@ -1,14 +1,3 @@
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ]; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
$MKE2FS -q -F -o Linux -b 4096 -O mmp -E mmp_update_interval=1 $TMPFILE 100 >> $test_name.log 2>&1
status=$?
if [ "$status" != 0 ] ; then

View File

@ -3,16 +3,6 @@ FS_SIZE=65536
MKE2FS_DEVICE_SECTSIZE=2048
export MKE2FS_DEVICE_SECTSIZE
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ]; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
MKE2FS_OPTS="-b 4096 -O mmp"
. $cmd_dir/run_mke2fs
unset MKE2FS_DEVICE_SECTSIZE

View File

@ -1,13 +1,3 @@
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ]; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
gzip -dc < $test_dir/image.gz > $TMPFILE
OUT=$test_name.log

View File

@ -1,13 +1,3 @@
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ]; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
gzip -dc < $test_dir/image.gz > $TMPFILE
OUT=$test_name.log

View File

@ -1,16 +1,5 @@
FSCK_OPT=-yf
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ] ; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
$MKE2FS -q -F -o Linux -b 4096 $TMPFILE 100 > $test_name.log 2>&1
status=$?
if [ "$status" != 0 ] ; then

View File

@ -1,16 +1,5 @@
FSCK_OPT=-yf
# use current directory instead of /tmp becase tmpfs doesn't support DIO
rm -f $TMPFILE
TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX)
stat -f $TMPFILE | grep -q "Type: tmpfs"
if [ $? = 0 ]; then
rm -f $TMPFILE
echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)"
return 0
fi
$MKE2FS -q -F -o Linux -b 4096 -O mmp $TMPFILE 100 > $test_name.log 2>&1
status=$?
if [ "$status" != 0 ] ; then