/*
* Finally, create the directory link
*/
- pctx.errcode = ext2fs_link(fs, EXT2_ROOT_INO, name, ino, EXT2_FT_DIR);
- if (pctx.errcode == EXT2_ET_DIR_NO_SPACE) {
- pctx.errcode = ext2fs_expand_dir(fs, EXT2_ROOT_INO);
- if (pctx.errcode)
- goto link_error;
- pctx.errcode = ext2fs_link(fs, EXT2_ROOT_INO, name, ino,
- EXT2_FT_DIR);
- }
+ pctx.errcode = ext2fs_link(fs, EXT2_ROOT_INO, name, ino,
+ EXT2_FT_DIR | EXT2FS_LINK_EXPAND);
if (pctx.errcode) {
-link_error:
pctx.str = "ext2fs_link";
fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
return 0;
*/
#define EXT2FS_LINK_FT_MASK 0x0007
#define EXT2FS_LINK_APPEND 0x0010
+#define EXT2FS_LINK_EXPAND 0x0020
/*
* function prototypes
if (!(fs->flags & EXT2_FLAG_RW))
return EXT2_ET_RO_FILSYS;
+retry:
if ((retval = ext2fs_read_inode(fs, dir, &inode)) != 0)
return retval;
if (ls.err)
return ls.err;
- if (!ls.done)
- return EXT2_ET_DIR_NO_SPACE;
+ if (!ls.done) {
+ if (!(flags & EXT2FS_LINK_EXPAND))
+ return EXT2_ET_DIR_NO_SPACE;
+ retval = ext2fs_expand_dir(fs, dir);
+ if (retval)
+ return retval;
+ goto retry;
+ }
return 0;
}
/* 64KiB is the minimum blksize to best minimize system call overhead. */
#define COPY_FILE_BUFLEN 65536
-int link_append_flag = 0;
+int link_append_flag = EXT2FS_LINK_EXPAND;
static int ext2_file_type(unsigned int mode)
{
retval = ext2fs_link(fs, parent_ino, name, ino,
ext2_file_type(inode.i_mode) | link_append_flag);
- if (retval == EXT2_ET_DIR_NO_SPACE) {
- retval = ext2fs_expand_dir(fs, parent_ino);
- if (retval) {
- com_err(__func__, retval,
- _("while expanding directory"));
- return retval;
- }
- retval = ext2fs_link(fs, parent_ino, name, ino,
- (ext2_file_type(inode.i_mode) |
- link_append_flag));
- }
if (retval) {
com_err(__func__, retval, _("while linking \"%s\""), name);
return retval;
printf("Allocated inode: %u\n", ino);
#endif
retval = ext2fs_link(fs, cwd, name, ino, filetype | link_append_flag);
- if (retval == EXT2_ET_DIR_NO_SPACE) {
- retval = ext2fs_expand_dir(fs, cwd);
- if (retval) {
- com_err(__func__, retval,
- _("while expanding directory"));
- return retval;
- }
- retval = ext2fs_link(fs, cwd, name, ino,
- filetype | link_append_flag);
- }
if (retval) {
com_err(name, retval, _("while creating inode \"%s\""), name);
return retval;
#endif
retval = ext2fs_link(fs, parent_ino, dest, newfile,
EXT2_FT_REG_FILE | link_append_flag);
- if (retval == EXT2_ET_DIR_NO_SPACE) {
- retval = ext2fs_expand_dir(fs, parent_ino);
- if (retval)
- goto out;
- retval = ext2fs_link(fs, parent_ino, dest, newfile,
- EXT2_FT_REG_FILE | link_append_flag);
- }
if (retval)
goto out;
if (ext2fs_test_inode_bitmap2(fs->inode_map, newfile))
file_info.path_max_len = 255;
file_info.path = calloc(file_info.path_max_len, 1);
- link_append_flag = (flags & POPULATE_FS_LINK_APPEND) ?
+ link_append_flag = EXT2FS_LINK_EXPAND;
+ link_append_flag |= (flags & POPULATE_FS_LINK_APPEND) ?
EXT2FS_LINK_APPEND : 0;
/* interpret input as tarball either if it's "-" (stdin) or if it's
out:
free(file_info.path);
free(hdlinks.hdl);
- link_append_flag = 0;
+ link_append_flag = EXT2FS_LINK_EXPAND;
return retval;
}
#endif
retval = ext2fs_link(fs, cwd, dest, newfile,
EXT2_FT_REG_FILE | link_append_flag);
- if (retval == EXT2_ET_DIR_NO_SPACE) {
- retval = ext2fs_expand_dir(fs, cwd);
- if (retval)
- goto out;
- retval = ext2fs_link(fs, cwd, dest, newfile,
- EXT2_FT_REG_FILE | link_append_flag);
- }
if (retval)
goto out;
if (ext2fs_test_inode_bitmap2(fs->inode_map, newfile))
dbg_printf(ff, "%s: create ino=%d/name=%s in dir=%d\n", __func__, child,
node_name, parent);
- err = ext2fs_link(fs, parent, node_name, child, filetype);
- if (err == EXT2_ET_DIR_NO_SPACE) {
- err = ext2fs_expand_dir(fs, parent);
- if (err) {
- ret = translate_error(fs, parent, err);
- goto out2;
- }
-
- err = ext2fs_link(fs, parent, node_name, child,
- filetype);
- }
+ err = ext2fs_link(fs, parent, node_name, child,
+ filetype | EXT2FS_LINK_EXPAND);
if (err) {
ret = translate_error(fs, parent, err);
goto out2;
dbg_printf(ff, "%s: linking ino=%d/path=%s to dir=%d\n", __func__,
from_ino, cp + 1, to_dir_ino);
err = ext2fs_link(fs, to_dir_ino, cp + 1, from_ino,
- ext2_file_type(inode.i_mode));
- if (err == EXT2_ET_DIR_NO_SPACE) {
- err = ext2fs_expand_dir(fs, to_dir_ino);
- if (err) {
- ret = translate_error(fs, to_dir_ino, err);
- goto out2;
- }
-
- err = ext2fs_link(fs, to_dir_ino, cp + 1, from_ino,
- ext2_file_type(inode.i_mode));
- }
+ ext2_file_type(inode.i_mode) | EXT2FS_LINK_EXPAND);
if (err) {
ret = translate_error(fs, to_dir_ino, err);
goto out2;
dbg_printf(ff, "%s: linking ino=%d/name=%s to dir=%d\n", __func__, ino,
node_name, parent);
err = ext2fs_link(fs, parent, node_name, ino,
- ext2_file_type(inode.i_mode));
- if (err == EXT2_ET_DIR_NO_SPACE) {
- err = ext2fs_expand_dir(fs, parent);
- if (err) {
- ret = translate_error(fs, parent, err);
- goto out2;
- }
-
- err = ext2fs_link(fs, parent, node_name, ino,
- ext2_file_type(inode.i_mode));
- }
+ ext2_file_type(inode.i_mode) | EXT2FS_LINK_EXPAND);
if (err) {
ret = translate_error(fs, parent, err);
goto out2;
dbg_printf(ff, "%s: creating ino=%d/name=%s in dir=%d\n", __func__, child,
node_name, parent);
- err = ext2fs_link(fs, parent, node_name, child, filetype);
- if (err == EXT2_ET_DIR_NO_SPACE) {
- err = ext2fs_expand_dir(fs, parent);
- if (err) {
- ret = translate_error(fs, parent, err);
- goto out2;
- }
-
- err = ext2fs_link(fs, parent, node_name, child,
- filetype);
- }
+ err = ext2fs_link(fs, parent, node_name, child,
+ filetype | EXT2FS_LINK_EXPAND);
if (err) {
ret = translate_error(fs, parent, err);
goto out2;
sprintf(fn_numbuf, "%lu", idx);
retry:
- retval = ext2fs_link(fs, dir, fn_buf, *ino, EXT2_FT_REG_FILE);
- if (retval == EXT2_ET_DIR_NO_SPACE) {
- retval = ext2fs_expand_dir(fs, dir);
- if (retval)
- goto errout;
- goto retry;
- }
-
+ retval = ext2fs_link(fs, dir, fn_buf, *ino,
+ EXT2_FT_REG_FILE | EXT2FS_LINK_EXPAND);
if (retval)
goto errout;