{
int fd;
struct stat statbuf;
- ext2_ino_t newfile;
+ ext2_ino_t newfile, parent_ino;
errcode_t retval;
struct ext2_inode inode;
+ char *cp;
fd = ext2fs_open_file(src, O_RDONLY, 0);
if (fd < 0) {
goto out;
}
- retval = ext2fs_namei(fs, root, cwd, dest, &newfile);
+ cp = strrchr(dest, '/');
+ if (cp) {
+ *cp = 0;
+ retval = ext2fs_namei(fs, root, cwd, dest, &parent_ino);
+ if (retval) {
+ com_err(dest, retval, _("while looking up \"%s\""),
+ dest);
+ return retval;
+ }
+ dest = cp+1;
+ } else
+ parent_ino = cwd;
+
+ retval = ext2fs_namei(fs, root, parent_ino, dest, &newfile);
if (retval == 0) {
retval = EXT2_ET_FILE_EXISTS;
goto out;
}
- retval = ext2fs_new_inode(fs, cwd, 010755, 0, &newfile);
+ retval = ext2fs_new_inode(fs, parent_ino, 010755, 0, &newfile);
if (retval)
goto out;
#ifdef DEBUGFS
printf("Allocated inode: %u\n", newfile);
#endif
- retval = ext2fs_link(fs, cwd, dest, newfile,
- EXT2_FT_REG_FILE);
+ retval = ext2fs_link(fs, parent_ino, dest, newfile, EXT2_FT_REG_FILE);
if (retval == EXT2_ET_DIR_NO_SPACE) {
- retval = ext2fs_expand_dir(fs, cwd);
+ retval = ext2fs_expand_dir(fs, parent_ino);
if (retval)
goto out;
- retval = ext2fs_link(fs, cwd, dest, newfile,
+ retval = ext2fs_link(fs, parent_ino, dest, newfile,
EXT2_FT_REG_FILE);
}
if (retval)
--- /dev/null
+FSCK_OPT=-nf
+
+$MKE2FS -q -F -o Linux -I 256 -b 4096 $TMPFILE 10000 > $test_name.log 2>&1
+status=$?
+if [ "$status" != 0 ] ; then
+ echo "mke2fs failed" > $test_name.failed
+ echo "$test_name: $test_description: failed"
+ return $status
+fi
+
+touch $TMPFILE.1
+cat <<- EOF | $DEBUGFS -w $TMPFILE >> $test_name.log 2>&1
+ mkdir aaa
+ mkdir aaa/bbb
+ write $TMPFILE.1 aaa/bbb/ccc
+EOF
+rm -f $TMPFILE.1
+
+$FSCK $FSCK_OPT $TMPFILE >> $test_name.log 2>&1
+status=$?
+if [ "$status" = 0 ] ; then
+ echo "$test_name: $test_description: ok"
+ touch $test_name.ok
+else
+ echo "e2fsck with failed with $status" > $test_name.failed
+ echo "$test_name: $test_description: failed"
+ return $status
+fi
+rm -f $TMPFILE