Many files:

alloc.c (ext2fs_alloc_block): New function which allocates a
  	block and updates the filesystem accounting records
  	appropriately.
  ext2_err.et.in: Added new error codes: EXT2_NO_MEMORY,
  	EXT2_INVALID_ARGUMENT, EXT2_BLOCK_ALLOC_FAIL, EXT2_INODE_ALLOC_FAIL,
  	EXT2_NOT_DIRECTORY
  Change various library files to use these functions instead of EINVAL,
  ENOENT, etc.
ChangeLog, pass1.c, pass3.c:
  pass3.c (get_lost_and_found): Check error return of
  	EXT2_FILE_NOT_FOUND instead of ENOTDIR
  pass1.c (pass1_check_directory): Return EXT2_NO_DIRECTORY instead of
  	ENOTDIR
expect.icount:
  Change expected error string to be "Invalid argument passed to ext2 library"
  instead of just "Invalid argument"
bitmap-optimize
Theodore Ts'o 1997-10-25 04:16:53 +00:00
parent f13048113f
commit c555aebde4
42 changed files with 165 additions and 209 deletions

View File

@ -1,3 +1,11 @@
Sat Oct 25 00:10:58 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* pass3.c (get_lost_and_found): Check error return of
EXT2_FILE_NOT_FOUND instead of ENOTDIR
* pass1.c (pass1_check_directory): Return EXT2_NO_DIRECTORY
instead of ENOTDIR
Fri Oct 24 00:12:39 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* unix.c (PRS): Make the variable which getopt returns into be

View File

@ -1213,6 +1213,6 @@ errcode_t pass1_check_directory(ext2_filsys fs, ino_t ino)
return EXT2_ET_CALLBACK_NOTHANDLED;
if (!LINUX_S_ISDIR(ctx->stashed_inode->i_mode))
return ENOTDIR;
return EXT2_NO_DIRECTORY;
return 0;
}

View File

@ -310,7 +310,7 @@ ino_t get_lost_and_found(e2fsck_t ctx)
sizeof(name)-1, 0, &ino);
if (!retval)
return ino;
if (retval != ENOENT) {
if (retval != EXT2_FILE_NOT_FOUND) {
pctx.errcode = retval;
fix_problem(ctx, PR_3_ERR_FIND_LPF, &pctx);
}

View File

@ -1,3 +1,18 @@
Sat Oct 25 00:06:58 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* alloc.c (ext2fs_alloc_block): New function which allocates a
block and updates the filesystem accounting records
appropriately.
Wed Oct 22 16:47:27 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* ext2_err.et.in: Added new error codes: EXT2_NO_MEMORY,
EXT2_INVALID_ARGUMENT, EXT2_BLOCK_ALLOC_FAIL,
EXT2_INODE_ALLOC_FAIL, EXT2_NOT_DIRECTORY
* Change various library files to use these functions instead of
EINVAL, ENOENT, etc.
Mon Oct 20 19:32:40 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* llseek.c: Check HAVE_LLSEEK_PROTOTYPE to see whether or not we

View File

@ -22,9 +22,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -67,7 +64,7 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode,
} while (i != start_inode);
if (ext2fs_test_inode_bitmap(map, i))
return ENOSPC;
return EXT2_INODE_ALLOC_FAIL;
*ret = i;
return 0;
}
@ -99,7 +96,33 @@ errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
if (i >= fs->super->s_blocks_count)
i = fs->super->s_first_data_block;
} while (i != goal);
return ENOSPC;
return EXT2_BLOCK_ALLOC_FAIL;
}
/*
* This function uses fs->block_map, and updates the filesystem
* accounting records appropriately.
*/
errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, blk_t *ret)
{
errcode_t retval;
int group;
if (!fs->block_map)
ext2fs_read_block_bitmap(fs);
retval = ext2fs_new_block(fs, goal, 0, ret);
if (retval)
return retval;
fs->super->s_free_blocks_count--;
group = ((*ret - fs->super->s_first_data_block) /
fs->super->s_blocks_per_group);
fs->group_desc[group].bg_free_blocks_count--;
ext2fs_mark_block_bitmap(fs->block_map, *ret);
ext2fs_mark_super_dirty(fs);
ext2fs_mark_bb_dirty(fs);
return 0;
}
errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,
@ -128,6 +151,6 @@ errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,
}
b++;
} while (b != finish);
return ENOSPC;
return EXT2_BLOCK_ALLOC_FAIL;
}

View File

@ -24,9 +24,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>

View File

@ -23,9 +23,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -41,7 +38,7 @@ static errcode_t make_badblocks_list(int size, int num, blk_t *list,
bb = malloc(sizeof(struct ext2_struct_badblocks_list));
if (!bb)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(bb, 0, sizeof(struct ext2_struct_badblocks_list));
bb->magic = EXT2_ET_MAGIC_BADBLOCKS_LIST;
bb->size = size ? size : 10;
@ -49,7 +46,7 @@ static errcode_t make_badblocks_list(int size, int num, blk_t *list,
bb->list = malloc(bb->size * sizeof(blk_t));
if (!bb->list) {
free(bb);
return ENOMEM;
return EXT2_NO_MEMORY;
}
if (list)
memcpy(bb->list, list, bb->size * sizeof(blk_t));
@ -106,7 +103,7 @@ errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, blk_t blk)
bb->size += 10;
new_list = realloc(bb->list, bb->size * sizeof(blk_t));
if (!new_list)
return ENOMEM;
return EXT2_NO_MEMORY;
bb->list = new_list;
}
@ -170,7 +167,7 @@ errcode_t ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
iter = malloc(sizeof(struct ext2_struct_badblocks_iterate));
if (!iter)
return ENOMEM;
return EXT2_NO_MEMORY;
iter->magic = EXT2_ET_MAGIC_BADBLOCKS_ITERATE;
iter->bb = bb;

View File

@ -23,9 +23,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>

View File

@ -27,9 +27,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -73,11 +70,11 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
rec.max_ind_blocks = 10;
rec.ind_blocks = malloc(rec.max_ind_blocks * sizeof(blk_t));
if (!rec.ind_blocks)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(rec.ind_blocks, 0, rec.max_ind_blocks * sizeof(blk_t));
rec.block_buf = malloc(fs->blocksize);
if (!rec.block_buf) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
memset(rec.block_buf, 0, fs->blocksize);
@ -189,7 +186,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr, int blockcnt,
rec->max_ind_blocks *
sizeof(blk_t));
if (!rec->ind_blocks) {
rec->err = ENOMEM;
rec->err = EXT2_NO_MEMORY;
return BLOCK_ABORT;
}
}

View File

@ -24,9 +24,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -41,7 +38,7 @@ static errcode_t make_bitmap(__u32 start, __u32 end, __u32 real_end,
bitmap = malloc(sizeof(struct ext2fs_struct_generic_bitmap));
if (!bitmap)
return ENOMEM;
return EXT2_NO_MEMORY;
bitmap->magic = EXT2_ET_MAGIC_GENERIC_BITMAP;
bitmap->fs = NULL;
@ -53,7 +50,7 @@ static errcode_t make_bitmap(__u32 start, __u32 end, __u32 real_end,
bitmap->description = malloc(strlen(descr)+1);
if (!bitmap->description) {
free(bitmap);
return ENOMEM;
return EXT2_NO_MEMORY;
}
strcpy(bitmap->description, descr);
} else
@ -64,7 +61,7 @@ static errcode_t make_bitmap(__u32 start, __u32 end, __u32 real_end,
if (!bitmap->bitmap) {
free(bitmap->description);
free(bitmap);
return ENOMEM;
return EXT2_NO_MEMORY;
}
if (init_map)

View File

@ -15,9 +15,6 @@
#include <unistd.h>
#endif
#include <stdlib.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -337,7 +334,7 @@ errcode_t ext2fs_block_iterate2(ext2_filsys fs,
} else {
ctx.ind_buf = malloc(fs->blocksize * 3);
if (!ctx.ind_buf)
return ENOMEM;
return EXT2_NO_MEMORY;
}
ctx.dind_buf = ctx.ind_buf + fs->blocksize;
ctx.tind_buf = ctx.dind_buf + fs->blocksize;

View File

@ -18,9 +18,6 @@
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
#include "ext2fs/ext2fs.h"
@ -56,7 +53,7 @@ static int process_block(ext2_filsys fs, blk_t *block_nr,
if (++block >= fs->super->s_blocks_count)
block = fs->super->s_first_data_block;
if (block == orig) {
pb->error = ENOSPC;
pb->error = EXT2_BLOCK_ALLOC_FAIL;
return BLOCK_ABORT;
}
} while (ext2fs_test_block_bitmap(pb->reserve, block) ||
@ -113,7 +110,7 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
block_buf = malloc(fs->blocksize * 4);
if (!block_buf)
return ENOMEM;
return EXT2_NO_MEMORY;
pb.buf = block_buf + fs->blocksize * 3;
/*

View File

@ -58,7 +58,7 @@ errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block,
/*
* Allocate memory structures
*/
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
brel = malloc(sizeof(struct ext2_block_relocation_table));
if (!brel)
goto errout;
@ -109,7 +109,7 @@ static errcode_t bma_put(ext2_brel brel, blk_t old,
ma = brel->private;
if (old > ma->max_block)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
ma->entries[(unsigned)old] = *ent;
return 0;
}
@ -121,7 +121,7 @@ static errcode_t bma_get(ext2_brel brel, blk_t old,
ma = brel->private;
if (old > ma->max_block)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned)old].new == 0)
return ENOENT;
*ent = ma->entries[old];
@ -157,7 +157,7 @@ static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new)
ma = brel->private;
if ((old > ma->max_block) || (new > ma->max_block))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned)old].new == 0)
return ENOENT;
ma->entries[(unsigned)new] = ma->entries[old];
@ -171,7 +171,7 @@ static errcode_t bma_delete(ext2_brel brel, blk_t old)
ma = brel->private;
if (old > ma->max_block)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned)old].new == 0)
return ENOENT;
ma->entries[(unsigned)old].new = 0;

View File

@ -16,9 +16,6 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -73,7 +70,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
fs->super->s_wtime = time(NULL);
if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
if (!(super_shadow = malloc(SUPERBLOCK_SIZE)))
goto errout;
if (!(group_shadow = malloc((size_t) fs->blocksize *

View File

@ -23,9 +23,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>

View File

@ -17,9 +17,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -68,7 +65,7 @@ static errcode_t make_dblist(ext2_filsys fs, ino_t size, ino_t count,
dblist = malloc(sizeof(struct ext2_struct_dblist));
if (!dblist)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(dblist, 0, sizeof(struct ext2_struct_dblist));
dblist->magic = EXT2_ET_MAGIC_DBLIST;
@ -85,7 +82,7 @@ static errcode_t make_dblist(ext2_filsys fs, ino_t size, ino_t count,
dblist->count = count;
dblist->list = malloc(len);
if (dblist->list == NULL) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
if (list)
@ -161,7 +158,7 @@ errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino, blk_t blk,
sizeof(struct ext2_db_entry));
if (nlist == 0) {
dblist->size -= 100;
return ENOMEM;
return EXT2_NO_MEMORY;
}
dblist->list = nlist;
}

View File

@ -17,9 +17,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -53,7 +50,7 @@ extern errcode_t
else {
ctx.buf = malloc(dblist->fs->blocksize);
if (!ctx.buf)
return ENOMEM;
return EXT2_NO_MEMORY;
}
ctx.func = 0;
ctx.func2 = func;

View File

@ -50,7 +50,7 @@ errcode_t ext2fs_dir_iterate(ext2_filsys fs,
else {
ctx.buf = malloc(fs->blocksize);
if (!ctx.buf)
return ENOMEM;
return EXT2_NO_MEMORY;
}
ctx.func = func;
ctx.func2 = 0;

View File

@ -16,9 +16,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -61,7 +58,7 @@ errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
write_buf = buf = malloc(fs->blocksize);
if (!buf)
return ENOMEM;
return EXT2_NO_MEMORY;
memcpy(buf, inbuf, fs->blocksize);
p = buf;
end = buf + fs->blocksize;

View File

@ -16,9 +16,6 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -33,7 +30,7 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest)
fs = (ext2_filsys) malloc(sizeof(struct struct_ext2_filsys));
if (!fs)
return ENOMEM;
return EXT2_NO_MEMORY;
*fs = *src;
fs->device_name = 0;
@ -48,7 +45,7 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest)
if (fs->icache)
fs->icache->refcount++;
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
fs->device_name = malloc(strlen(src->device_name)+1);
if (!fs->device_name)
goto errout;

View File

@ -15,9 +15,6 @@
#include <unistd.h>
#endif
#include <stdlib.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -59,7 +56,7 @@ static int expand_dir_proc(ext2_filsys fs,
} else {
block = malloc(fs->blocksize);
if (!block) {
es->err = ENOMEM;
es->err = EXT2_NO_MEMORY;
return BLOCK_ABORT;
}
memset(block, 0, fs->blocksize);

View File

@ -381,6 +381,7 @@ extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
blk_t finish, int num,
ext2fs_block_bitmap map,
blk_t *ret);
extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, blk_t *ret);
/* alloc_tables.c */
extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);

View File

@ -24,9 +24,6 @@
#include <unistd.h>
#endif
#include <stdlib.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -58,7 +55,7 @@ static int get_pathname_proc(struct ext2_dir_entry *dirent,
if (dirent->inode == gp->search_ino) {
gp->name = malloc(dirent->name_len + 1);
if (!gp->name) {
gp->errcode = ENOMEM;
gp->errcode = EXT2_NO_MEMORY;
return DIRENT_ABORT;
}
strncpy(gp->name, dirent->name, dirent->name_len);
@ -78,7 +75,7 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ino_t dir, ino_t ino,
if (dir == ino) {
*name = malloc(2);
if (!*name)
return ENOMEM;
return EXT2_NO_MEMORY;
strcpy(*name, (dir == EXT2_ROOT_INO) ? "/" : ".");
return 0;
}
@ -86,7 +83,7 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ino_t dir, ino_t ino,
if (!dir || (maxdepth < 0)) {
*name = malloc(4);
if (!*name)
return ENOMEM;
return EXT2_NO_MEMORY;
strcpy(*name, "...");
return 0;
}
@ -119,7 +116,7 @@ static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ino_t dir, ino_t ino,
ret = malloc(strlen(parent_name)+5); /* strlen("???") + 2 */
if (!ret) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
ret[0] = 0;
@ -150,7 +147,7 @@ errcode_t ext2fs_get_pathname(ext2_filsys fs, ino_t dir, ino_t ino,
buf = malloc(fs->blocksize);
if (!buf)
return ENOMEM;
return EXT2_NO_MEMORY;
if (dir == ino)
ino = 0;
retval = ext2fs_get_pathname_int(fs, dir, ino, 32, buf, name);

View File

@ -16,9 +16,6 @@
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <fcntl.h>
#ifdef HAVE_LINUX_FS_H
#include <linux/fs.h>

View File

@ -16,9 +16,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
#include "ext2fs.h"
@ -89,7 +86,7 @@ errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
icount = malloc(sizeof(struct ext2_icount));
if (!icount)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(icount, 0, sizeof(struct ext2_icount));
retval = ext2fs_allocate_inode_bitmap(fs, 0,
@ -282,14 +279,14 @@ errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *out)
if (icount->count > icount->size) {
fprintf(out, "%s: count > size\n", bad);
return EINVAL;
return EXT2_INVALID_ARGUMENT;
}
for (i=1; i < icount->count; i++) {
if (icount->list[i-1].ino >= icount->list[i].ino) {
fprintf(out, "%s: list[%d].ino=%ld, list[%d].ino=%ld\n",
bad, i-1, icount->list[i-1].ino,
i, icount->list[i].ino);
ret = EINVAL;
ret = EXT2_INVALID_ARGUMENT;
}
}
return ret;
@ -302,7 +299,7 @@ errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ino_t ino, __u16 *ret)
EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
if (!ino || (ino > icount->num_inodes))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ext2fs_test_inode_bitmap(icount->single, ino)) {
*ret = 1;
@ -330,7 +327,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
if (!ino || (ino > icount->num_inodes))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ext2fs_test_inode_bitmap(icount->single, ino)) {
/*
@ -339,7 +336,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
*/
el = get_icount_el(icount, ino, 1);
if (!el)
return ENOMEM;
return EXT2_NO_MEMORY;
ext2fs_unmark_inode_bitmap(icount->single, ino);
el->count = 2;
} else if (icount->multiple) {
@ -352,7 +349,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
if (ext2fs_test_inode_bitmap(icount->multiple, ino)) {
el = get_icount_el(icount, ino, 1);
if (!el)
return ENOMEM;
return EXT2_NO_MEMORY;
el->count++;
} else {
/*
@ -377,7 +374,7 @@ errcode_t ext2fs_icount_increment(ext2_icount_t icount, ino_t ino,
}
el = get_icount_el(icount, ino, 1);
if (!el)
return ENOMEM;
return EXT2_NO_MEMORY;
el->count++;
}
if (icount->multiple)
@ -393,7 +390,7 @@ errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino,
struct ext2_icount_el *el;
if (!ino || (ino > icount->num_inodes))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
@ -413,11 +410,11 @@ errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ino_t ino,
if (icount->multiple &&
!ext2fs_test_inode_bitmap(icount->multiple, ino))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
el = get_icount_el(icount, ino, 0);
if (!el || el->count == 0)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
el->count--;
if (el->count == 1)
@ -436,7 +433,7 @@ errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino,
struct ext2_icount_el *el;
if (!ino || (ino > icount->num_inodes))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT);
@ -467,7 +464,7 @@ errcode_t ext2fs_icount_store(ext2_icount_t icount, ino_t ino,
*/
el = get_icount_el(icount, ino, 1);
if (!el)
return ENOMEM;
return EXT2_NO_MEMORY;
el->count = count;
ext2fs_unmark_inode_bitmap(icount->single, ino);
if (icount->multiple)

View File

@ -24,9 +24,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -73,11 +70,11 @@ errcode_t ext2fs_initialize(const char *name, int flags,
char *buf;
if (!param || !param->s_blocks_count)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
fs = (ext2_filsys) malloc(sizeof(struct struct_ext2_filsys));
if (!fs)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(fs, 0, sizeof(struct struct_ext2_filsys));
fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
@ -88,13 +85,13 @@ errcode_t ext2fs_initialize(const char *name, int flags,
fs->io->app_data = fs;
fs->device_name = malloc(strlen(name)+1);
if (!fs->device_name) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
strcpy(fs->device_name, name);
fs->super = super = malloc(SUPERBLOCK_SIZE);
if (!super) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
memset(super, 0, SUPERBLOCK_SIZE);
@ -142,7 +139,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
super->s_blocks_count = param->s_blocks_count;
super->s_r_blocks_count = param->s_r_blocks_count;
if (super->s_r_blocks_count >= param->s_blocks_count) {
retval = EINVAL;
retval = EXT2_INVALID_ARGUMENT;
goto cleanup;
}
@ -234,7 +231,7 @@ retry:
buf = malloc(strlen(fs->device_name) + 80);
if (!buf) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
@ -252,7 +249,7 @@ retry:
fs->group_desc = malloc((size_t) fs->desc_blocks * fs->blocksize);
if (!fs->group_desc) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
memset(fs->group_desc, 0, (size_t) fs->desc_blocks * fs->blocksize);

View File

@ -21,9 +21,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -65,7 +62,7 @@ static errcode_t create_icache(ext2_filsys fs)
fs->icache->buffer = malloc(fs->blocksize);
if (!fs->icache->buffer) {
free(fs->icache);
return ENOMEM;
return EXT2_NO_MEMORY;
}
fs->icache->buffer_blk = 0;
fs->icache->cache_last = -1;
@ -76,7 +73,7 @@ static errcode_t create_icache(ext2_filsys fs)
if (!fs->icache->cache) {
free(fs->icache->buffer);
free(fs->icache);
return ENOMEM;
return EXT2_NO_MEMORY;
}
for (i=0; i < fs->icache->cache_size; i++)
fs->icache->cache[i].ino = 0;
@ -113,7 +110,7 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
scan = (ext2_inode_scan) malloc(sizeof(struct ext2_struct_inode_scan));
if (!scan)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(scan, 0, sizeof(struct ext2_struct_inode_scan));
scan->magic = EXT2_ET_MAGIC_INODE_SCAN;
@ -130,13 +127,13 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
scan->bad_block_ptr = 0;
if (!scan->inode_buffer) {
free(scan);
return ENOMEM;
return EXT2_NO_MEMORY;
}
scan->temp_buffer = malloc(scan->inode_size);
if (!scan->temp_buffer) {
free(scan->inode_buffer);
free(scan);
return ENOMEM;
return EXT2_NO_MEMORY;
}
if (scan->fs->badblocks && scan->fs->badblocks->num)
scan->scan_flags |= EXT2_SF_CHK_BADBLOCKS;
@ -642,7 +639,7 @@ errcode_t ext2fs_check_directory(ext2_filsys fs, ino_t ino)
if (retval)
return retval;
if (!LINUX_S_ISDIR(inode.i_mode))
return ENOTDIR;
return EXT2_NO_DIRECTORY;
return 0;
}

View File

@ -74,7 +74,7 @@ errcode_t ext2fs_irel_memarray_create(char *name, ino_t max_inode,
/*
* Allocate memory structures
*/
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
irel = malloc(sizeof(struct ext2_inode_relocation_table));
if (!irel)
goto errout;
@ -145,7 +145,7 @@ static errcode_t ima_put(ext2_irel irel, ino_t old,
ma = irel->private;
if (old > ma->max_inode)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
/*
* Force the orig field to the correct value; the application
@ -165,7 +165,7 @@ static errcode_t ima_put(ext2_irel irel, ino_t old,
size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
new_refs = realloc(ref_ent->refs, size);
if (!new_refs)
return ENOMEM;
return EXT2_NO_MEMORY;
ref_ent->refs = new_refs;
}
@ -181,7 +181,7 @@ static errcode_t ima_get(ext2_irel irel, ino_t old,
ma = irel->private;
if (old > ma->max_inode)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned) old].new == 0)
return ENOENT;
*ent = ma->entries[(unsigned) old];
@ -196,7 +196,7 @@ static errcode_t ima_get_by_orig(ext2_irel irel, ino_t orig, ino_t *old,
ma = irel->private;
if (orig > ma->max_inode)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
ino = ma->orig_map[(unsigned) orig];
if (ino == 0)
return ENOENT;
@ -238,7 +238,7 @@ static errcode_t ima_add_ref(ext2_irel irel, ino_t ino,
ma = irel->private;
if (ino > ma->max_inode)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
ref_ent = ma->ref_entries + (unsigned) ino;
ent = ma->entries + (unsigned) ino;
@ -251,13 +251,13 @@ static errcode_t ima_add_ref(ext2_irel irel, ino_t ino,
ent->max_refs));
ref_ent->refs = malloc(size);
if (ref_ent->refs == 0)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(ref_ent->refs, 0, size);
ref_ent->num = 0;
}
if (ref_ent->num >= ent->max_refs)
return ENOSPC;
return EXT2_TOO_MANY_REFS;
ref_ent->refs[(unsigned) ref_ent->num++] = *ref;
return 0;
@ -269,7 +269,7 @@ static errcode_t ima_start_iter_ref(ext2_irel irel, ino_t ino)
ma = irel->private;
if (ino > ma->max_inode)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned) ino].new == 0)
return ENOENT;
ma->ref_current = ino;
@ -304,7 +304,7 @@ static errcode_t ima_move(ext2_irel irel, ino_t old, ino_t new)
ma = irel->private;
if ((old > ma->max_inode) || (new > ma->max_inode))
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned) old].new == 0)
return ENOENT;
@ -327,7 +327,7 @@ static errcode_t ima_delete(ext2_irel irel, ino_t old)
ma = irel->private;
if (old > ma->max_inode)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
if (ma->entries[(unsigned) old].new == 0)
return ENOENT;

View File

@ -16,9 +16,6 @@
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <fcntl.h>
#ifdef HAVE_LINUX_FS_H
#include <linux/fs.h>

View File

@ -13,7 +13,9 @@
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
@ -112,7 +114,7 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
{
if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
(offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
errno = EINVAL;
errno = EXT2_INVALID_ARGUMENT;
return -1;
}
return lseek (fd, (off_t) offset, origin);

View File

@ -15,9 +15,6 @@
#include <unistd.h>
#endif
#include <stdlib.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -68,7 +65,7 @@ errcode_t ext2fs_lookup(ext2_filsys fs, ino_t dir, const char *name,
if (retval)
return retval;
return (ls.found) ? 0 : ENOENT;
return (ls.found) ? 0 : EXT2_FILE_NOT_FOUND;
}

View File

@ -23,9 +23,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -114,7 +111,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ino_t parent, ino_t inum,
name = 0;
goto cleanup;
}
if (retval != ENOENT)
if (retval != EXT2_FILE_NOT_FOUND)
goto cleanup;
retval = ext2fs_link(fs, parent, name, ino, 0);
if (retval)

View File

@ -15,9 +15,6 @@
#include <unistd.h>
#endif
#include <stdlib.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
/* #define NAMEI_DEBUG */
@ -55,7 +52,7 @@ static errcode_t follow_link(ext2_filsys fs, ino_t root, ino_t dir,
if (ei.i_blocks) {
buffer = malloc (fs->blocksize);
if (!buffer)
return ENOMEM;
return EXT2_NO_MEMORY;
retval = io_channel_read_blk(fs->io, ei.i_block[0], 1, buffer);
if (retval) {
free(buffer);
@ -161,7 +158,7 @@ errcode_t ext2fs_namei(ext2_filsys fs, ino_t root, ino_t cwd,
buf = malloc(fs->blocksize);
if (!buf)
return ENOMEM;
return EXT2_NO_MEMORY;
retval = open_namei(fs, root, cwd, name, strlen(name), 0, 0,
buf, inode);
@ -180,7 +177,7 @@ errcode_t ext2fs_namei_follow(ext2_filsys fs, ino_t root, ino_t cwd,
buf = malloc(fs->blocksize);
if (!buf)
return ENOMEM;
return EXT2_NO_MEMORY;
retval = open_namei(fs, root, cwd, name, strlen(name), 1, 0,
buf, inode);
@ -199,7 +196,7 @@ extern errcode_t ext2fs_follow_link(ext2_filsys fs, ino_t root, ino_t cwd,
buf = malloc(fs->blocksize);
if (!buf)
return ENOMEM;
return EXT2_NO_MEMORY;
retval = follow_link(fs, root, cwd, inode, 0, buf, res_inode);

View File

@ -15,9 +15,6 @@
#include <unistd.h>
#endif
#include <stdlib.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -37,7 +34,7 @@ errcode_t ext2fs_new_dir_block(ext2_filsys fs, ino_t dir_ino, ino_t parent_ino,
buf = malloc(fs->blocksize);
if (!buf)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(buf, 0, fs->blocksize);
dir = (struct ext2_dir_entry *) buf;
dir->rec_len = fs->blocksize;

View File

@ -19,9 +19,6 @@
#endif
#include <fcntl.h>
#include <time.h>
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
@ -58,7 +55,7 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
fs = (ext2_filsys) malloc(sizeof(struct struct_ext2_filsys));
if (!fs)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(fs, 0, sizeof(struct struct_ext2_filsys));
fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
@ -70,13 +67,13 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
fs->io->app_data = fs;
fs->device_name = malloc(strlen(name)+1);
if (!fs->device_name) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
strcpy(fs->device_name, name);
fs->super = malloc(SUPERBLOCK_SIZE);
if (!fs->super) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
@ -88,7 +85,7 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
*/
if (superblock) {
if (!block_size) {
retval = EINVAL;
retval = EXT2_INVALID_ARGUMENT;
goto cleanup;
}
io_channel_set_blksize(fs->io, block_size);
@ -177,7 +174,7 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
/ EXT2_DESC_PER_BLOCK(fs->super);
fs->group_desc = malloc((size_t) (fs->desc_blocks * fs->blocksize));
if (!fs->group_desc) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
if (!group_block)

View File

@ -23,9 +23,6 @@
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -39,7 +36,7 @@ errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
__u32 bitno;
if (!bmap)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_GENERIC_BITMAP);
@ -64,7 +61,7 @@ errcode_t ext2fs_resize_generic_bitmap(__u32 new_end, __u32 new_real_end,
new_bitmap = realloc(bmap->bitmap, new_size);
if (!new_bitmap)
return ENOMEM;
return EXT2_NO_MEMORY;
if (new_size > size)
memset(new_bitmap + size, 0, new_size - size);
@ -80,7 +77,7 @@ errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
errcode_t retval;
if (!bmap)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_INODE_BITMAP);
@ -97,7 +94,7 @@ errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
errcode_t retval;
if (!bmap)
return EINVAL;
return EXT2_INVALID_ARGUMENT;
EXT2_CHECK_MAGIC(bmap, EXT2_ET_MAGIC_BLOCK_BITMAP);

View File

@ -23,9 +23,6 @@
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
@ -74,7 +71,7 @@ errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
bitmap_block = malloc(fs->blocksize);
if (!bitmap_block)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(bitmap_block, 0xff, fs->blocksize);
for (i = 0; i < fs->group_desc_count; i++) {
memcpy(bitmap_block, inode_bitmap, nbytes);
@ -118,7 +115,7 @@ errcode_t ext2fs_write_block_bitmap (ext2_filsys fs)
nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
bitmap_block = malloc(fs->blocksize);
if (!bitmap_block)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(bitmap_block, 0xff, fs->blocksize);
for (i = 0; i < fs->group_desc_count; i++) {
memcpy(bitmap_block, block_bitmap, nbytes);

View File

@ -23,9 +23,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include "et/com_err.h"
#include "ext2fs/ext2_err.h"
@ -90,19 +87,19 @@ static errcode_t test_open(const char *name, int flags, io_channel *channel)
return EXT2_ET_BAD_DEVICE_NAME;
io = (io_channel) malloc(sizeof(struct struct_io_channel));
if (!io)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(io, 0, sizeof(struct struct_io_channel));
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
data = (struct test_private_data *)
malloc(sizeof(struct test_private_data));
if (!data) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
io->manager = test_io_manager;
io->name = malloc(strlen(name)+1);
if (!io->name) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
strcpy(io->name, name);

View File

@ -25,9 +25,6 @@
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#include "et/com_err.h"
#include "ext2fs/ext2_err.h"
@ -80,19 +77,19 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
return EXT2_ET_BAD_DEVICE_NAME;
io = (io_channel) malloc(sizeof(struct struct_io_channel));
if (!io)
return ENOMEM;
return EXT2_NO_MEMORY;
memset(io, 0, sizeof(struct struct_io_channel));
io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
data = (struct unix_private_data *)
malloc(sizeof(struct unix_private_data));
if (!data) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
io->manager = unix_io_manager;
io->name = malloc(strlen(name)+1);
if (!io->name) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
strcpy(io->name, name);
@ -107,7 +104,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
data->buf = malloc(io->block_size);
data->buf_block_nr = -1;
if (!data->buf) {
retval = ENOMEM;
retval = EXT2_NO_MEMORY;
goto cleanup;
}
data->dev = open(name, (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY);
@ -166,7 +163,7 @@ static errcode_t unix_set_blksize(io_channel channel, int blksize)
free(data->buf);
data->buf = malloc(blksize);
if (!data->buf)
return ENOMEM;
return EXT2_NO_MEMORY;
data->buf_block_nr = -1;
}
return 0;

View File

@ -17,9 +17,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>

View File

@ -17,9 +17,6 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <linux/ext2_fs.h>
#include "ext2fs.h"

View File

@ -2,18 +2,18 @@ test_icount: validate
Icount structure successfully validated
test_icount: store 0
usage: store inode counttest_icount: fetch 0
fetch: Invalid argument while calling ext2fs_icount_fetch
fetch: Invalid argument passed to ext2 library while calling ext2fs_icount_fetch
test_icount: increment 0
increment: Invalid argument while calling ext2fs_icount_increment
increment: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: decrement 0
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: store 20001
usage: store inode counttest_icount: fetch 20001
fetch: Invalid argument while calling ext2fs_icount_fetch
fetch: Invalid argument passed to ext2 library while calling ext2fs_icount_fetch
test_icount: increment 20001
increment: Invalid argument while calling ext2fs_icount_increment
increment: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: decrement 20001
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: validate
Icount structure successfully validated
test_icount: fetch 1
@ -56,7 +56,7 @@ Count is 0
test_icount: get_size
Size of icount is: 5
test_icount: decrement 2
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: increment 2
Count is now 1
test_icount: fetch 2
@ -88,7 +88,7 @@ Count is 1
test_icount: decrement 2
Count is now 0
test_icount: decrement 2
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: store 3 1
test_icount: increment 3
Count is now 2
@ -128,9 +128,9 @@ Count is now 1
test_icount: decrement 4
Count is now 0
test_icount: decrement 4
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: decrement 4
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: store 5 4
test_icount: decrement 5
Count is now 3
@ -141,7 +141,7 @@ Count is now 1
test_icount: decrement 5
Count is now 0
test_icount: decrement 5
decrement: Invalid argument while calling ext2fs_icount_increment
decrement: Invalid argument passed to ext2 library while calling ext2fs_icount_increment
test_icount: get_size
Size of icount is: 105
test_icount: validate