1.1 --- a/libfsserver/lib/files/ext2_file_opener.cc Sun Jul 25 23:18:39 2021 +0200
1.2 +++ b/libfsserver/lib/files/ext2_file_opener.cc Fri Jul 30 00:20:35 2021 +0200
1.3 @@ -19,8 +19,6 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <e2access/access.h>
1.8 -#include <e2access/image.h>
1.9 #include <e2access/path.h>
1.10
1.11 #include <systypes/fcntl.h>
1.12 @@ -32,55 +30,39 @@
1.13
1.14 long Ext2FileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)
1.15 {
1.16 - const char *filename = path;
1.17 -
1.18 - /* Obtain the inode number. */
1.19 -
1.20 ext2_ino_t ino;
1.21 - errcode_t retval = image_find_path(_fs, &filename, &ino);
1.22 -
1.23 - /* Handle a missing file. */
1.24 -
1.25 - if (retval)
1.26 - {
1.27 - /* Create a missing file if possible. */
1.28 -
1.29 - if (flags & O_CREAT)
1.30 - {
1.31 - /* Determine whether only the leafname is left of the path, with
1.32 - the inode number referring to the parent directory. */
1.33 -
1.34 - if (path_is_leafname(filename))
1.35 - {
1.36 - struct ext2_inode inode_parent;
1.37 + const char *remaining;
1.38 + long err = _ops->find_file(path, &ino, &remaining);
1.39
1.40 - /* Determine write access in the directory. */
1.41 -
1.42 - retval = ext2fs_read_inode(_fs, ino, &inode_parent);
1.43 -
1.44 - if (retval)
1.45 - return -L4_EIO;
1.46 -
1.47 - if (!access_can_write(_user, &inode_parent))
1.48 - return -L4_EPERM;
1.49 -
1.50 - /* If so, use the parent directory inode to create a new file. */
1.51 + /* Return an existing file. */
1.52
1.53 - if (image_create_file(_fs, ino, filename, 0666 & ~_user.umask,
1.54 - _user.uid, _user.gid, &ino))
1.55 - return -L4_EIO;
1.56 -
1.57 - *fileid = (fileid_t) ino;
1.58 - return L4_EOK;
1.59 - }
1.60 - }
1.61 -
1.62 - *fileid = FILEID_INVALID;
1.63 - return -L4_ENOENT;
1.64 + if (!err)
1.65 + {
1.66 + *fileid = (fileid_t) ino;
1.67 + return L4_EOK;
1.68 }
1.69
1.70 - *fileid = (fileid_t) ino;
1.71 - return L4_EOK;
1.72 + *fileid = FILEID_INVALID;
1.73 +
1.74 + /* Create a missing file if possible. */
1.75 +
1.76 + if (flags & O_CREAT)
1.77 + {
1.78 + /* Determine whether only the leafname is left of the path, with
1.79 + the inode number referring to the parent directory. */
1.80 +
1.81 + if (path_is_leafname(remaining))
1.82 + {
1.83 + err = _ops->create_file(ino, remaining, _user, &ino);
1.84 + if (err)
1.85 + return err;
1.86 +
1.87 + *fileid = (fileid_t) ino;
1.88 + return L4_EOK;
1.89 + }
1.90 + }
1.91 +
1.92 + return -L4_ENOENT;
1.93 }
1.94
1.95 /* Return a new accessor for 'fileid'. */
1.96 @@ -90,14 +72,12 @@
1.97 (void) path; (void) flags;
1.98
1.99 ext2_file_t file;
1.100 - errcode_t retval = ext2fs_file_open(_fs, (ext2_ino_t) fileid, EXT2_FILE_WRITE, &file);
1.101 -
1.102 - // NOTE: Map error conditions.
1.103 + long err = _ops->open_file((ext2_ino_t) fileid, &file);
1.104
1.105 - if (retval)
1.106 - return -L4_EIO;
1.107 + if (err)
1.108 + return err;
1.109
1.110 - *accessor = new Ext2FileAccessor(file, fileid);
1.111 + *accessor = new Ext2FileAccessor(_ops, file, fileid);
1.112 return L4_EOK;
1.113 }
1.114