1.1 --- a/libfsclient/lib/src/file.cc Wed Mar 02 22:27:19 2022 +0100 1.2 +++ b/libfsclient/lib/src/file.cc Wed Mar 02 22:27:28 2022 +0100 1.3 @@ -21,6 +21,7 @@ 1.4 1.5 #include <ipc/cap_alloc.h> 1.6 #include <ipc/mem_ipc.h> 1.7 +#include <systypes/stat.h> 1.8 1.9 #include <string.h> 1.10 1.11 @@ -96,14 +97,15 @@ 1.12 void file_close(file_t *file) 1.13 { 1.14 if (l4_is_valid_cap(file->ref)) 1.15 + { 1.16 ipc_cap_free_um(file->ref); 1.17 1.18 - /* Only unsubscribe after actually closing the file and sending any 1.19 - notifications. This depends on a valid reference, so it is also tested 1.20 - here. */ 1.21 + /* Only unsubscribe after actually closing the file and sending any 1.22 + notifications. This depends on a valid reference, so it is also tested 1.23 + here. */ 1.24 1.25 - if (l4_is_valid_cap(file->ref)) 1.26 notifier_get_task_notifier()->unsubscribe(file); 1.27 + } 1.28 1.29 if (file->memory != NULL) 1.30 ipc_detach_dataspace(file->memory); 1.31 @@ -282,7 +284,10 @@ 1.32 if (err) 1.33 return err; 1.34 1.35 - memcpy(st, context->memory, sizeof(struct stat)); 1.36 + /* Copy the stat structure manually in case of any divergence. */ 1.37 + 1.38 + systypes_copy_from_sys_stat(st, (sys_stat_t *) context->memory); 1.39 + 1.40 return L4_EOK; 1.41 } 1.42
2.1 --- a/libfsserver/include/fsserver/ext2_file_opener.h Wed Mar 02 22:27:19 2022 +0100 2.2 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Wed Mar 02 22:27:28 2022 +0100 2.3 @@ -64,6 +64,8 @@ 2.4 virtual long make_directory_accessor(flags_t flags, fileid_t fileid, 2.5 DirectoryAccessor **accessor); 2.6 2.7 + /* Filesystem object access and manipulation methods. */ 2.8 + 2.9 virtual long remove_object(fileid_t fileid); 2.10 2.11 virtual long rename_object(const char *source, const char *target);
3.1 --- a/libfsserver/include/fsserver/file_opening.h Wed Mar 02 22:27:19 2022 +0100 3.2 +++ b/libfsserver/include/fsserver/file_opening.h Wed Mar 02 22:27:28 2022 +0100 3.3 @@ -47,6 +47,8 @@ 3.4 virtual long make_directory_accessor(flags_t flags, fileid_t fileid, 3.5 DirectoryAccessor **accessor) = 0; 3.6 3.7 + /* Filesystem object access and manipulation methods. */ 3.8 + 3.9 virtual long stat_object(const char *path, void *base, offset_t size) = 0; 3.10 3.11 virtual long remove_object(fileid_t fileid) = 0;
4.1 --- a/libfsserver/include/fsserver/host_file_opener.h Wed Mar 02 22:27:19 2022 +0100 4.2 +++ b/libfsserver/include/fsserver/host_file_opener.h Wed Mar 02 22:27:28 2022 +0100 4.3 @@ -78,6 +78,8 @@ 4.4 virtual long make_directory_accessor(flags_t flags, fileid_t fileid, 4.5 DirectoryAccessor **accessor); 4.6 4.7 + /* Filesystem object access and manipulation methods. */ 4.8 + 4.9 virtual long remove_object(fileid_t fileid); 4.10 4.11 virtual long rename_object(const char *source, const char *target);
5.1 --- a/libfsserver/include/fsserver/test_file_opener.h Wed Mar 02 22:27:19 2022 +0100 5.2 +++ b/libfsserver/include/fsserver/test_file_opener.h Wed Mar 02 22:27:28 2022 +0100 5.3 @@ -55,6 +55,8 @@ 5.4 virtual long make_directory_accessor(flags_t flags, fileid_t fileid, 5.5 DirectoryAccessor **accessor); 5.6 5.7 + /* Filesystem object access and manipulation methods. */ 5.8 + 5.9 virtual long remove_object(fileid_t fileid); 5.10 5.11 virtual long rename_object(const char *source, const char *target);
6.1 --- a/libfsserver/lib/files/ext2_file_opener.cc Wed Mar 02 22:27:19 2022 +0100 6.2 +++ b/libfsserver/lib/files/ext2_file_opener.cc Wed Mar 02 22:27:28 2022 +0100 6.3 @@ -24,6 +24,7 @@ 6.4 #include <e2access/path.h> 6.5 #include <fsclient/client.h> 6.6 #include <systypes/fcntl.h> 6.7 +#include <systypes/stat.h> 6.8 6.9 #include "ext2_directory_accessor.h" 6.10 #include "ext2_file_accessor.h" 6.11 @@ -129,22 +130,7 @@ 6.12 return L4_EOK; 6.13 } 6.14 6.15 -/* Populate a memory region with statistics metadata for a filesystem object. */ 6.16 6.17 -long Ext2FileOpener::stat_object(const char *path, void *base, offset_t size) 6.18 -{ 6.19 - struct stat *st = (struct stat *) base; 6.20 - fileid_t fileid; 6.21 - long err = get_fileid(path, 0, &fileid); 6.22 - 6.23 - if (err) 6.24 - return err; 6.25 - 6.26 - if (sizeof(struct stat) > size) 6.27 - return -L4_ENOMEM; 6.28 - 6.29 - return _ops->stat_inode((ext2_ino_t) fileid, st); 6.30 -} 6.31 6.32 /* Remove a filesystem object. */ 6.33 6.34 @@ -180,6 +166,33 @@ 6.35 (ext2_ino_t) target_parent, path_basename(target)); 6.36 } 6.37 6.38 +/* Populate a memory region with statistics metadata for a filesystem object. */ 6.39 + 6.40 +long Ext2FileOpener::stat_object(const char *path, void *base, offset_t size) 6.41 +{ 6.42 + struct stat st; 6.43 + fileid_t fileid; 6.44 + long err = get_fileid(path, 0, &fileid); 6.45 + 6.46 + if (err) 6.47 + return err; 6.48 + 6.49 + if (sizeof(struct stat) > size) 6.50 + return -L4_ENOMEM; 6.51 + 6.52 + err = _ops->stat_inode((ext2_ino_t) fileid, &st); 6.53 + 6.54 + if (err) 6.55 + return err; 6.56 + 6.57 + /* Use the systypes version of the structure to permit different library 6.58 + implementations on the client and server sides of an IPC invocation. */ 6.59 + 6.60 + systypes_copy_to_sys_stat(&st, (sys_stat_t *) base); 6.61 + 6.62 + return L4_EOK; 6.63 +} 6.64 + 6.65 /* Unlink a filesystem object. */ 6.66 6.67 long Ext2FileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid)
7.1 --- a/libfsserver/lib/files/host_file_opener.cc Wed Mar 02 22:27:19 2022 +0100 7.2 +++ b/libfsserver/lib/files/host_file_opener.cc Wed Mar 02 22:27:28 2022 +0100 7.3 @@ -196,17 +196,7 @@ 7.4 return L4_EOK; 7.5 } 7.6 7.7 -/* Populate a memory region with statistics metadata for a filesystem object. */ 7.8 7.9 -long HostFileOpener::stat_object(const char *path, void *base, offset_t size) 7.10 -{ 7.11 - struct stat *st = (struct stat *) base; 7.12 - 7.13 - if (sizeof(struct stat) > size) 7.14 - return -L4_ENOMEM; 7.15 - 7.16 - return ::stat(path, st); 7.17 -} 7.18 7.19 /* Remove a filesystem object. */ 7.20 7.21 @@ -228,6 +218,18 @@ 7.22 return L4_EOK; 7.23 } 7.24 7.25 +/* Populate a memory region with statistics metadata for a filesystem object. */ 7.26 + 7.27 +long HostFileOpener::stat_object(const char *path, void *base, offset_t size) 7.28 +{ 7.29 + struct stat *st = (struct stat *) base; 7.30 + 7.31 + if (sizeof(struct stat) > size) 7.32 + return -L4_ENOMEM; 7.33 + 7.34 + return ::stat(path, st); 7.35 +} 7.36 + 7.37 /* Unlink a filesystem object. */ 7.38 7.39 long HostFileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid)
8.1 --- a/libfsserver/lib/files/test_file_opener.cc Wed Mar 02 22:27:19 2022 +0100 8.2 +++ b/libfsserver/lib/files/test_file_opener.cc Wed Mar 02 22:27:28 2022 +0100 8.3 @@ -86,13 +86,7 @@ 8.4 return -L4_EIO; 8.5 } 8.6 8.7 -/* Populate a memory region with statistics metadata for a filesystem object. */ 8.8 8.9 -long TestFileOpener::stat_object(const char *path, void *base, offset_t size) 8.10 -{ 8.11 - (void) path; (void) base; (void) size; 8.12 - return -L4_EIO; 8.13 -} 8.14 8.15 /* Remove a filesystem object. */ 8.16 8.17 @@ -110,6 +104,14 @@ 8.18 return -L4_EIO; 8.19 } 8.20 8.21 +/* Populate a memory region with statistics metadata for a filesystem object. */ 8.22 + 8.23 +long TestFileOpener::stat_object(const char *path, void *base, offset_t size) 8.24 +{ 8.25 + (void) path; (void) base; (void) size; 8.26 + return -L4_EIO; 8.27 +} 8.28 + 8.29 /* Unlink a filesystem object. */ 8.30 8.31 long TestFileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid)
9.1 --- a/libsystypes/include/systypes/base.h Wed Mar 02 22:27:19 2022 +0100 9.2 +++ b/libsystypes/include/systypes/base.h Wed Mar 02 22:27:28 2022 +0100 9.3 @@ -65,12 +65,16 @@ 9.4 9.5 /* Equivalent types are defined in sys/types.h typically. In newlib, they are 9.6 defined in sys/_types.h if not defined elsewhere (such as in 9.7 - machine/_types.h). */ 9.8 + machine/_types.h). 9.9 9.10 -typedef unsigned long long sys_dev_t; /* device number */ 9.11 -typedef unsigned long sys_ino_t; /* inode number */ 9.12 + These types are intended for IPC, permitting different parties to employ 9.13 + different library implementations where these types may be different. 9.14 +*/ 9.15 + 9.16 +typedef unsigned long int sys_dev_t; /* device number */ 9.17 +typedef unsigned long int sys_ino_t; /* inode number */ 9.18 typedef unsigned int sys_mode_t; /* file permissions */ 9.19 -typedef unsigned int sys_nlink_t; /* link count */ 9.20 +typedef unsigned long int sys_nlink_t; /* link count */ 9.21 typedef unsigned int sys_uid_t; /* user identifier */ 9.22 typedef unsigned int sys_gid_t; /* group identifier */ 9.23 typedef long sys_off_t; /* file offset/position */
10.1 --- a/libsystypes/include/systypes/stat.h Wed Mar 02 22:27:19 2022 +0100 10.2 +++ b/libsystypes/include/systypes/stat.h Wed Mar 02 22:27:28 2022 +0100 10.3 @@ -1,7 +1,7 @@ 10.4 /* 10.5 * File metadata abstractions. 10.6 * 10.7 - * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> 10.8 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk> 10.9 * 10.10 * This program is free software; you can redistribute it and/or 10.11 * modify it under the terms of the GNU General Public License as 10.12 @@ -21,6 +21,8 @@ 10.13 10.14 #pragma once 10.15 10.16 +#include <sys/stat.h> 10.17 + 10.18 #include <systypes/base.h> 10.19 #include <systypes/timespec.h> 10.20 10.21 @@ -46,4 +48,11 @@ 10.22 10.23 } sys_stat_t; 10.24 10.25 +void systypes_copy_from_sys_stat(struct stat *st, sys_stat_t *sst); 10.26 + 10.27 +void systypes_copy_to_sys_stat(struct stat *st, sys_stat_t *sst); 10.28 + 10.29 EXTERN_C_END 10.30 + 10.31 +/* vim: tabstop=4 expandtab shiftwidth=4 10.32 +*/
11.1 --- a/tests/dstest_file_readdir.cc Wed Mar 02 22:27:19 2022 +0100 11.2 +++ b/tests/dstest_file_readdir.cc Wed Mar 02 22:27:28 2022 +0100 11.3 @@ -81,12 +81,12 @@ 11.4 printf("%s %ld %ld %x %d %d ", 11.5 path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid); 11.6 11.7 - printf("%d %d %d %x %x ", 11.8 + printf("%ld %ld %ld %x %x ", 11.9 st.st_dev, st.st_ino, st.st_nlink, 11.10 major(st.st_rdev), minor(st.st_rdev)); 11.11 11.12 - printf("%d %d %d ", 11.13 - st.st_atim, st.st_mtim, st.st_ctim); 11.14 + printf("%ld %ld %ld ", 11.15 + st.st_atim.tv_sec, st.st_mtim.tv_sec, st.st_ctim.tv_sec); 11.16 11.17 /* NOTE: Arbitrary values: 11.18 %W (creation time) given as 0