Skip to content

Commit

Permalink
pjdfstest fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alperakcan committed Mar 30, 2015
1 parent dcd29e3 commit 0528a7c
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 35 deletions.
4 changes: 2 additions & 2 deletions fuse-ext2/do_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ int do_check_split (const char *path, char **dirname, char **basename)
free(cpath);
return -ENAMETOOLONG;
}
*dirname=cpath;
*basename=tmp;
*dirname = cpath;
*basename = tmp;
return 0;
}

Expand Down
41 changes: 41 additions & 0 deletions fuse-ext2/do_writeinode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2008-2010 Alper Akcan <[email protected]>
* Copyright (c) 2009 Renzo Davoli <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the fuse-ext2
* distribution in the file COPYING); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "fuse-ext2.h"

int do_writeinode (ext2_filsys e2fs, ext2_ino_t ino, struct ext2_inode *inode)
{
int rt;
errcode_t rc;
if (inode->i_links_count < 1) {
rt = do_killfilebyinode(e2fs, ino, inode);
if (rt) {
debugf("do_killfilebyinode(e2fs, ino, inode); failed");
return rt;
}
} else {
rc = ext2fs_write_inode(e2fs, ino, inode);
if (rc) {
debugf("ext2fs_read_inode(e2fs, *ino, inode); failed");
return -EIO;
}
}
return 0;
}
4 changes: 2 additions & 2 deletions fuse-ext2/fuse-ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
static const char *HOME = "http://sourceforge.net/projects/fuse-ext2/";

#if __FreeBSD__ == 10
static char def_opts[] = "allow_other,local,";
static char def_opts[] = "allow_other,default_permissions,local,";
static char def_opts_rd[] = "noappledouble,";
#else
static char def_opts[] = "";
static char def_opts[] = "allow_other,default_permissions,";
static char def_opts_rd[] = "";
#endif

Expand Down
2 changes: 1 addition & 1 deletion fuse-ext2/op_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int op_access (const char *path, int mask)
}

if ((mask & W_OK) && !(e2fs->flags & EXT2_FLAG_RW)) {
return -1;
return -EACCES;
}

debugf("leave");
Expand Down
4 changes: 2 additions & 2 deletions fuse-ext2/op_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ int do_create (ext2_filsys e2fs, const char *path, mode_t mode, dev_t dev, const
return -EIO;
}
inode.i_ctime = inode.i_mtime = tm;
rc = ext2fs_write_inode(e2fs, ino, &inode);
rc = do_writeinode(e2fs, ino, &inode);
if (rc) {
debugf("ext2fs_write_inode(e2fs, ino, &inode); failed");
debugf("do_writeinode(e2fs, ino, &inode); failed");
free_split(p_path, r_path);
return -EIO;
}
Expand Down
4 changes: 3 additions & 1 deletion fuse-ext2/op_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ int op_link (const char *source, const char *dest)
return rc;
}


rc = do_readinode(e2fs, source, &s_ino, &s_inode);
if (rc) {
debugf("do_readinode(%s, &s_ino, &s_inode); failed", p_path);
Expand Down Expand Up @@ -83,18 +82,21 @@ int op_link (const char *source, const char *dest)

d_inode.i_mtime = d_inode.i_ctime = s_inode.i_ctime = e2fs->now ? e2fs->now : time(NULL);
s_inode.i_links_count += 1;

rc = do_writeinode(e2fs, s_ino, &s_inode);
if (rc) {
debugf("do_writeinode(e2fs, s_ino, &s_inode); failed");
free_split(p_path, r_path);
return -EIO;
}

rc = do_writeinode(e2fs, d_ino, &d_inode);
if (rc) {
debugf("do_writeinode(e2fs, d_ino, &d_inode); failed");
free_split(p_path, r_path);
return -EIO;
}

free_split(p_path, r_path);
debugf("done");

Expand Down
10 changes: 5 additions & 5 deletions fuse-ext2/op_mkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int op_mkdir (const char *path, mode_t mode)
debugf("enter");
debugf("path = %s, mode: 0%o, dir:0%o", path, mode, LINUX_S_IFDIR);

rt=do_check_split(path, &p_path ,&r_path);
rt = do_check_split(path, &p_path ,&r_path);
if (rt != 0) {
debugf("do_check(%s); failed", path);
return rt;
Expand Down Expand Up @@ -87,9 +87,9 @@ int op_mkdir (const char *path, mode_t mode)
inode.i_uid = ctx->uid;
inode.i_gid = ctx->gid;
}
rc = ext2fs_write_inode(e2fs, ino, &inode);
rc = do_writeinode(e2fs, ino, &inode);
if (rc) {
debugf("ext2fs_write_inode(e2fs, ino, &inode); failed");
debugf("do_writeinode(e2fs, ino, &inode); failed");
free_split(p_path, r_path);
return -EIO;
}
Expand All @@ -102,9 +102,9 @@ int op_mkdir (const char *path, mode_t mode)
return -EIO;
}
inode.i_ctime = inode.i_mtime = tm;
rc = ext2fs_write_inode(e2fs, ino, &inode);
rc = do_writeinode(e2fs, ino, &inode);
if (rc) {
debugf("ext2fs_write_inode(e2fs, ino, &inode); failed");
debugf("do_writeinode(e2fs, ino, &inode); failed");
free_split(p_path, r_path);
return -EIO;
}
Expand Down
9 changes: 8 additions & 1 deletion fuse-ext2/op_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ext2_file_t do_open (ext2_filsys e2fs, const char *path, int flags)

rt = do_readinode(e2fs, path, &ino, &inode);
if (rt) {
debugf("do_readinode(%s, &ino, &vnode); failed", path);
debugf("do_readinode(%s, &ino, &inode); failed", path);
return NULL;
}

Expand All @@ -53,6 +53,13 @@ ext2_file_t do_open (ext2_filsys e2fs, const char *path, int flags)
return NULL;
}

inode.i_mtime = e2fs->now ? e2fs->now : time(NULL);
rt = do_writeinode(e2fs, ino, &inode);
if (rt) {
debugf("do_writeinode(%s, &ino, &inode); failed", path);
return NULL;
}

debugf("leave");
return efile;
}
Expand Down
2 changes: 1 addition & 1 deletion fuse-ext2/op_readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static int walk_dir2 (ext2_ino_t dir, int entry, struct ext2_dir_entry *dirent
}
st.st_ino = dirent->inode;
st.st_mode = type << 12;
debugf("%s %d %d %d",dirent->name,dirent->name_len &0xff, dirent->name_len >> 8,type);
debugf("%s %d %d %d", dirent->name, dirent->name_len & 0xff, dirent->name_len >> 8, type);
res = psid->filler(psid->buf, dirent->name, &st, 0);
if (res != 0) {
return BLOCK_ABORT;
Expand Down
13 changes: 5 additions & 8 deletions fuse-ext2/op_rename.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ int op_rename (const char *source, const char *dest)
goto out;
}

rt = do_readinode(e2fs, p_dest, &src_ino, &src_inode);
rt = do_readinode(e2fs, source, &src_ino, &src_inode);
if (rt != 0) {
debugf("do_readinode(%s, &src_ino, &src_inode); failed", p_dest);
goto out;
}

rt = do_readinode(e2fs, p_dest, &dest_ino, &dest_inode);
rt = do_readinode(e2fs, dest, &dest_ino, &dest_inode);
if (rt != 0 && rt != -ENOENT) {
debugf("do_readinode(%s, &dest_ino, &dest_inode); failed", dest);
goto out;
Expand Down Expand Up @@ -181,6 +181,8 @@ int op_rename (const char *source, const char *dest)
if (d_dest_inode.i_links_count > 1) {
d_dest_inode.i_links_count--;
}
d_dest_inode.i_mtime = e2fs->now ? e2fs->now : time(NULL);
d_dest_inode.i_ctime = e2fs->now ? e2fs->now : time(NULL);
rc = do_writeinode(e2fs, d_dest_ino, &d_dest_inode);
if (rc) {
debugf("do_writeinode(e2fs, ino, inode); failed");
Expand All @@ -190,7 +192,7 @@ int op_rename (const char *source, const char *dest)
if (dest_inode.i_links_count > 0) {
dest_inode.i_links_count -= 1;
}
rc = do_writeinode(e2fs, d_dest_ino, &d_dest_inode);
rc = do_writeinode(e2fs, dest_ino, &dest_inode);
if (rc) {
debugf("do_writeinode(e2fs, ino, inode); failed");
goto out;
Expand Down Expand Up @@ -249,11 +251,6 @@ int op_rename (const char *source, const char *dest)
debugf("do_writeinode(e2fs, d_dest_ino, &d_dest_inode); failed");
goto out;
}
rt = do_writeinode(e2fs, d_dest_ino, &d_dest_inode);
if (rt != 0) {
debugf("do_writeinode(e2fs, d_dest_ino, &d_dest_inode); failed");
goto out;
}
rt = do_writeinode(e2fs, src_ino, &src_inode);
if (rt != 0) {
debugf("do_writeinode(e2fs, src_ino, &src_inode); failed");
Expand Down
6 changes: 4 additions & 2 deletions fuse-ext2/op_rmdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ int op_rmdir (const char *path)
if (p_inode.i_links_count > 1) {
p_inode.i_links_count--;
}
rc = ext2fs_write_inode(e2fs, p_ino, &p_inode);
p_inode.i_mtime = e2fs->now ? e2fs->now : time(NULL);
p_inode.i_ctime = e2fs->now ? e2fs->now : time(NULL);
rc = do_writeinode(e2fs, p_ino, &p_inode);
if (rc) {
debugf("ext2fs_write_inode(e2fs, ino, inode); failed");
debugf("do_writeinode(e2fs, ino, inode); failed");
free_split(p_path, r_path);
return -EIO;
}
Expand Down
65 changes: 57 additions & 8 deletions fuse-ext2/op_truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

#include "fuse-ext2.h"

int op_truncate(const char *path, off_t length)
int op_truncate (const char *path, off_t length)
{
int rt;
errcode_t rc;
ext2_ino_t ino;
struct ext2_inode inode;
ext2_file_t efile;
ext2_filsys e2fs = current_ext2fs();

Expand All @@ -40,12 +43,27 @@ int op_truncate(const char *path, off_t length)
return -ENOENT;
}

rt = ext2fs_file_set_size(efile, length);
if (rt) {
rc = ext2fs_file_set_size2(efile, length);
if (rc) {
do_release(efile);
debugf("ext2fs_file_set_size(efile, %d); failed", length);
if (rc == EXT2_ET_FILE_TOO_BIG) {
return -EFBIG;
}
return -EIO;
}

rt = do_readinode(e2fs, path, &ino, &inode);
if (rt) {
debugf("do_readinode(%s, &ino, &vnode); failed", path);
return rt;
}
inode.i_ctime = e2fs->now ? e2fs->now : time(NULL);
rt = do_writeinode(e2fs, ino, &inode);
if (rt) {
debugf("do_writeinode(e2fs, ino, &inode); failed");
return -EIO;
}

rt = do_release(efile);
if (rt != 0) {
Expand All @@ -57,20 +75,51 @@ int op_truncate(const char *path, off_t length)
return 0;
}

int op_ftruncate(const char *path, off_t length, struct fuse_file_info *fi)
int op_ftruncate (const char *path, off_t length, struct fuse_file_info *fi)
{
size_t rt;
int rt;
errcode_t rc;
ext2_ino_t ino;
struct ext2_inode inode;
ext2_filsys e2fs = current_ext2fs();
ext2_file_t efile = EXT2FS_FILE(fi->fh);

debugf("enter");
debugf("path = %s", path);

rt = ext2fs_file_set_size(efile, length);
rt = do_check(path);
if (rt != 0) {
debugf("do_check(%s); failed", path);
return rt;
}

rt = do_readinode(e2fs, path, &ino, &inode);
if (rt) {
debugf("ext2fs_file_set_size(efile, %d); failed", length);
debugf("do_readinode(%s, &ino, &vnode); failed", path);
return rt;
}

rc = ext2fs_file_set_size2(efile, length);
if (rc) {
debugf("ext2fs_file_set_size(efile, %lld); failed: rc: %d", length, rc);
if (rc == EXT2_ET_FILE_TOO_BIG) {
return -EFBIG;
}
return -EIO;
}

rt = do_readinode(e2fs, path, &ino, &inode);
if (rt) {
debugf("do_readinode(%s, &ino, &vnode); failed", path);
return rt;
}
inode.i_ctime = e2fs->now ? e2fs->now : time(NULL);
rt = do_writeinode(e2fs, ino, &inode);
if (rt) {
debugf("do_writeinode(e2fs, ino, &inode); failed");
return -EIO;
}

debugf("leave");
return 0;
return 0;
}
4 changes: 2 additions & 2 deletions fuse-ext2/op_unlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int op_unlink (const char *path)
return rt;
}

debugf("parent: %s, child: %s", p_path, p_ino);
debugf("parent: %s, child: %s", p_path, r_path);

rt = do_readinode(e2fs, p_path, &p_ino, &p_inode);
if (rt) {
Expand Down Expand Up @@ -81,7 +81,7 @@ int op_unlink (const char *path)
p_inode.i_ctime = p_inode.i_mtime = e2fs->now ? e2fs->now : time(NULL);
rt = do_writeinode(e2fs, p_ino, &p_inode);
if (rt) {
debugf("ext2fs_write_inode(e2fs, p_ino, &p_inode); failed");
debugf("do_writeinode(e2fs, p_ino, &p_inode); failed");
free_split(p_path, r_path);
return -EIO;
}
Expand Down

0 comments on commit 0528a7c

Please sign in to comment.