1.1 --- a/libfsserver/include/fsserver/block_file_opener.h Sun Aug 01 22:48:12 2021 +0200 1.2 +++ b/libfsserver/include/fsserver/block_file_opener.h Mon Aug 02 19:39:10 2021 +0200 1.3 @@ -35,6 +35,8 @@ 1.4 { 1.5 } 1.6 1.7 + virtual ~BlockFileOpener(); 1.8 + 1.9 /* Configurable methods. */ 1.10 1.11 virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid);
2.1 --- a/libfsserver/include/fsserver/ext2_file_opener.h Sun Aug 01 22:48:12 2021 +0200 2.2 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Mon Aug 02 19:39:10 2021 +0200 2.3 @@ -37,12 +37,20 @@ 2.4 Ext2FileOperations *_ops; 2.5 user_t _user; 2.6 2.7 + /* Convenience methods determining different object types. */ 2.8 + 2.9 + virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid); 2.10 + 2.11 + virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); 2.12 + 2.13 public: 2.14 explicit Ext2FileOpener(FilePaging *paging, Ext2FileOperations *ops, user_t user) 2.15 : OpenerResource(paging), _ops(ops), _user(user) 2.16 { 2.17 } 2.18 2.19 + virtual ~Ext2FileOpener(); 2.20 + 2.21 /* Configurable methods. */ 2.22 2.23 virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid);
3.1 --- a/libfsserver/include/fsserver/ext2_file_operations.h Sun Aug 01 22:48:12 2021 +0200 3.2 +++ b/libfsserver/include/fsserver/ext2_file_operations.h Mon Aug 02 19:39:10 2021 +0200 3.3 @@ -44,13 +44,17 @@ 3.4 { 3.5 } 3.6 3.7 + bool is_directory(ext2_ino_t ino_file); 3.8 + 3.9 + bool is_file(ext2_ino_t ino_file); 3.10 + 3.11 long create_file(ext2_ino_t ino_parent, const char *filename, user_t user, 3.12 ext2_ino_t *ino); 3.13 3.14 long find_file(const char *path, ext2_ino_t *ino, const char **remaining); 3.15 3.16 void close_file(ext2_file_t file); 3.17 - 3.18 + 3.19 long open_file(ext2_ino_t ino, ext2_file_t *file); 3.20 3.21 offset_t get_size(ext2_file_t file);
4.1 --- a/libfsserver/include/fsserver/file_paging.h Sun Aug 01 22:48:12 2021 +0200 4.2 +++ b/libfsserver/include/fsserver/file_paging.h Mon Aug 02 19:39:10 2021 +0200 4.3 @@ -67,7 +67,7 @@ 4.4 4.5 long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 4.6 4.7 - long get_pager(FileOpening *opening, const char *path, flags_t flags, Pager **pager); 4.8 + long get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager); 4.9 4.10 /* Methods for the pager. */ 4.11
5.1 --- a/libfsserver/include/fsserver/host_file_opener.h Sun Aug 01 22:48:12 2021 +0200 5.2 +++ b/libfsserver/include/fsserver/host_file_opener.h Mon Aug 02 19:39:10 2021 +0200 5.3 @@ -48,12 +48,20 @@ 5.4 5.5 virtual fileid_t _get_fileid(const char *path, bool create); 5.6 5.7 + /* Convenience methods determining different object types. */ 5.8 + 5.9 + virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid); 5.10 + 5.11 + virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); 5.12 + 5.13 public: 5.14 explicit HostFileOpener(FilePaging *paging) 5.15 : OpenerResource(paging) 5.16 { 5.17 } 5.18 5.19 + virtual ~HostFileOpener(); 5.20 + 5.21 /* Configurable methods. */ 5.22 5.23 virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid);
6.1 --- a/libfsserver/include/fsserver/opener_resource.h Sun Aug 01 22:48:12 2021 +0200 6.2 +++ b/libfsserver/include/fsserver/opener_resource.h Mon Aug 02 19:39:10 2021 +0200 6.3 @@ -36,9 +36,23 @@ 6.4 protected: 6.5 FilePaging *_paging; 6.6 6.7 + /* Convenience methods determining different object types. */ 6.8 + 6.9 + virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid) = 0; 6.10 + 6.11 + virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid) = 0; 6.12 + 6.13 + /* Convenience methods obtaining different pager types. */ 6.14 + 6.15 + virtual long get_directory(const char *path, flags_t flags, fileid_t fileid, Pager **pager); 6.16 + 6.17 + virtual long get_file(const char *path, flags_t flags, fileid_t fileid, Pager **pager); 6.18 + 6.19 public: 6.20 explicit OpenerResource(FilePaging *paging); 6.21 6.22 + virtual ~OpenerResource(); 6.23 + 6.24 /* Server details. */ 6.25 6.26 int expected_items();
7.1 --- a/libfsserver/include/fsserver/test_file_opener.h Sun Aug 01 22:48:12 2021 +0200 7.2 +++ b/libfsserver/include/fsserver/test_file_opener.h Mon Aug 02 19:39:10 2021 +0200 7.3 @@ -32,9 +32,17 @@ 7.4 protected: 7.5 offset_t _file_size; 7.6 7.7 + /* Convenience methods determining different object types. */ 7.8 + 7.9 + virtual bool accessing_directory(const char *path, flags_t flags, fileid_t fileid); 7.10 + 7.11 + virtual bool accessing_file(const char *path, flags_t flags, fileid_t fileid); 7.12 + 7.13 public: 7.14 explicit TestFileOpener(FilePaging *paging, offset_t file_size=0); 7.15 7.16 + virtual ~TestFileOpener(); 7.17 + 7.18 /* Configurable methods. */ 7.19 7.20 virtual long get_fileid(const char *path, flags_t flags, fileid_t *fileid);
8.1 --- a/libfsserver/lib/files/block_file_opener.cc Sun Aug 01 22:48:12 2021 +0200 8.2 +++ b/libfsserver/lib/files/block_file_opener.cc Mon Aug 02 19:39:10 2021 +0200 8.3 @@ -24,6 +24,10 @@ 8.4 #include "block_file_accessor.h" 8.5 #include "block_file_opener.h" 8.6 8.7 +BlockFileOpener::~BlockFileOpener() 8.8 +{ 8.9 +} 8.10 + 8.11 /* Return a file identifier for the given 'path'. */ 8.12 8.13 long BlockFileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)
9.1 --- a/libfsserver/lib/files/ext2_file_opener.cc Sun Aug 01 22:48:12 2021 +0200 9.2 +++ b/libfsserver/lib/files/ext2_file_opener.cc Mon Aug 02 19:39:10 2021 +0200 9.3 @@ -26,6 +26,26 @@ 9.4 #include "ext2_file_accessor.h" 9.5 #include "ext2_file_opener.h" 9.6 9.7 +Ext2FileOpener::~Ext2FileOpener() 9.8 +{ 9.9 +} 9.10 + 9.11 +/* Test if a directory is being accessed. */ 9.12 + 9.13 +bool Ext2FileOpener::accessing_directory(const char *path, flags_t flags, fileid_t fileid) 9.14 +{ 9.15 + (void) path; (void) flags; 9.16 + return _ops->is_directory((ext2_ino_t) fileid); 9.17 +} 9.18 + 9.19 +/* Test if a file is being accessed. */ 9.20 + 9.21 +bool Ext2FileOpener::accessing_file(const char *path, flags_t flags, fileid_t fileid) 9.22 +{ 9.23 + (void) path; (void) flags; 9.24 + return _ops->is_file((ext2_ino_t) fileid); 9.25 +} 9.26 + 9.27 /* Return a file identifier for the given 'path'. */ 9.28 9.29 long Ext2FileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid) 9.30 @@ -46,7 +66,7 @@ 9.31 9.32 /* Create a missing file if possible. */ 9.33 9.34 - if (flags & O_CREAT) 9.35 + if ((flags & O_CREAT) && (flags & ~O_DIRECTORY)) 9.36 { 9.37 /* Determine whether only the leafname is left of the path, with 9.38 the inode number referring to the parent directory. */
10.1 --- a/libfsserver/lib/files/ext2_file_operations.cc Sun Aug 01 22:48:12 2021 +0200 10.2 +++ b/libfsserver/lib/files/ext2_file_operations.cc Mon Aug 02 19:39:10 2021 +0200 10.3 @@ -25,6 +25,22 @@ 10.4 10.5 #include "ext2_file_operations.h" 10.6 10.7 +/* Object type tests. */ 10.8 + 10.9 +bool Ext2FileOperations::is_directory(ext2_ino_t ino_file) 10.10 +{ 10.11 + std::lock_guard<std::mutex> guard(_lock); 10.12 + 10.13 + return _image_isdir(_fs, ino_file); 10.14 +} 10.15 + 10.16 +bool Ext2FileOperations::is_file(ext2_ino_t ino_file) 10.17 +{ 10.18 + std::lock_guard<std::mutex> guard(_lock); 10.19 + 10.20 + return _image_isfile(_fs, ino_file); 10.21 +} 10.22 + 10.23 /* Create a file in the directory indicated by the given inode number with the 10.24 given filename. The file is created with the given user permissions. */ 10.25
11.1 --- a/libfsserver/lib/files/file_paging.cc Sun Aug 01 22:48:12 2021 +0200 11.2 +++ b/libfsserver/lib/files/file_paging.cc Mon Aug 02 19:39:10 2021 +0200 11.3 @@ -110,23 +110,15 @@ 11.4 11.5 /* Return a pager initialised with a page mapper. */ 11.6 11.7 -long FilePaging::get_pager(FileOpening *opening, const char *path, flags_t flags, Pager **pager) 11.8 +long FilePaging::get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager) 11.9 { 11.10 std::lock_guard<std::mutex> guard(_lock); 11.11 11.12 - /* Obtain an identifier for the file, even for new files. */ 11.13 - 11.14 - fileid_t fileid; 11.15 - long err = opening->get_fileid(path, flags, &fileid); 11.16 - 11.17 - if (err) 11.18 - return err; 11.19 - 11.20 /* Obtain any existing page mapper registered for the file, or make a new 11.21 page mapper. */ 11.22 11.23 PageMapper *mapper; 11.24 - err = get_mapper(opening, path, flags, fileid, &mapper); 11.25 + long err = get_mapper(opening, path, flags, fileid, &mapper); 11.26 11.27 if (err) 11.28 return err;
12.1 --- a/libfsserver/lib/files/host_file_opener.cc Sun Aug 01 22:48:12 2021 +0200 12.2 +++ b/libfsserver/lib/files/host_file_opener.cc Mon Aug 02 19:39:10 2021 +0200 12.3 @@ -19,9 +19,37 @@ 12.4 * Boston, MA 02110-1301, USA 12.5 */ 12.6 12.7 +#include <sys/stat.h> 12.8 + 12.9 #include "host_file_accessor.h" 12.10 #include "host_file_opener.h" 12.11 12.12 +HostFileOpener::~HostFileOpener() 12.13 +{ 12.14 +} 12.15 + 12.16 +bool HostFileOpener::accessing_directory(const char *path, flags_t flags, fileid_t fileid) 12.17 +{ 12.18 + (void) flags; (void) fileid; 12.19 + struct stat st; 12.20 + 12.21 + if (stat(path, &st)) 12.22 + return false; 12.23 + 12.24 + return (st.st_mode & S_IFDIR) ? true : false; 12.25 +} 12.26 + 12.27 +bool HostFileOpener::accessing_file(const char *path, flags_t flags, fileid_t fileid) 12.28 +{ 12.29 + (void) flags; (void) fileid; 12.30 + struct stat st; 12.31 + 12.32 + if (stat(path, &st)) 12.33 + return false; 12.34 + 12.35 + return (st.st_mode & S_IFREG) ? true : false; 12.36 +} 12.37 + 12.38 /* Return a file identifier for the given 'path'. */ 12.39 12.40 long HostFileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)
13.1 --- a/libfsserver/lib/files/opener_resource.cc Sun Aug 01 22:48:12 2021 +0200 13.2 +++ b/libfsserver/lib/files/opener_resource.cc Mon Aug 02 19:39:10 2021 +0200 13.3 @@ -30,6 +30,10 @@ 13.4 { 13.5 } 13.6 13.7 +OpenerResource::~OpenerResource() 13.8 +{ 13.9 +} 13.10 + 13.11 int OpenerResource::expected_items() 13.12 { 13.13 return Opener_expected_items; 13.14 @@ -46,7 +50,39 @@ 13.15 13.16 long OpenerResource::open(const char *path, flags_t flags, Pager **pager) 13.17 { 13.18 - return _paging->get_pager(this, path, flags, pager); 13.19 + /* Obtain an identifier for the file, even for new files. */ 13.20 + 13.21 + fileid_t fileid; 13.22 + long err = get_fileid(path, flags, &fileid); 13.23 + 13.24 + if (err) 13.25 + return err; 13.26 + 13.27 + /* Test for file and directory access. */ 13.28 + 13.29 + if (accessing_directory(path, flags, fileid)) 13.30 + return get_directory(path, flags, fileid, pager); 13.31 + else if (accessing_file(path, flags, fileid)) 13.32 + return get_file(path, flags, fileid, pager); 13.33 + else 13.34 + return -L4_EIO; 13.35 +} 13.36 + 13.37 + 13.38 + 13.39 +/* Return a directory pager. */ 13.40 + 13.41 +long OpenerResource::get_directory(const char *path, flags_t flags, fileid_t fileid, Pager **pager) 13.42 +{ 13.43 + (void) path; (void) flags; (void) fileid; *pager = NULL; 13.44 + return -L4_EIO; 13.45 +} 13.46 + 13.47 +/* Return a file pager. */ 13.48 + 13.49 +long OpenerResource::get_file(const char *path, flags_t flags, fileid_t fileid, Pager **pager) 13.50 +{ 13.51 + return _paging->get_pager(this, path, flags, fileid, pager); 13.52 } 13.53 13.54
14.1 --- a/libfsserver/lib/files/test_file_opener.cc Sun Aug 01 22:48:12 2021 +0200 14.2 +++ b/libfsserver/lib/files/test_file_opener.cc Mon Aug 02 19:39:10 2021 +0200 14.3 @@ -31,6 +31,22 @@ 14.4 { 14.5 } 14.6 14.7 +TestFileOpener::~TestFileOpener() 14.8 +{ 14.9 +} 14.10 + 14.11 +bool TestFileOpener::accessing_directory(const char *path, flags_t flags, fileid_t fileid) 14.12 +{ 14.13 + (void) path; (void) flags; (void) fileid; 14.14 + return false; 14.15 +} 14.16 + 14.17 +bool TestFileOpener::accessing_file(const char *path, flags_t flags, fileid_t fileid) 14.18 +{ 14.19 + (void) path; (void) flags; (void) fileid; 14.20 + return true; 14.21 +} 14.22 + 14.23 /* Return a file identifier for the given 'path'. */ 14.24 14.25 long TestFileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)