# HG changeset patch # User Paul Boddie # Date 1646256448 -3600 # Node ID d91bc1fca7881df5a882b6bef1023cc6d6372f5f # Parent f58459304d8348ece07c1f8630bf0df1443ed223 Improved stat support using the systypes structure definition for IPC messages. diff -r f58459304d83 -r d91bc1fca788 libfsclient/lib/src/file.cc --- a/libfsclient/lib/src/file.cc Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsclient/lib/src/file.cc Wed Mar 02 22:27:28 2022 +0100 @@ -21,6 +21,7 @@ #include #include +#include #include @@ -96,14 +97,15 @@ void file_close(file_t *file) { if (l4_is_valid_cap(file->ref)) + { ipc_cap_free_um(file->ref); - /* Only unsubscribe after actually closing the file and sending any - notifications. This depends on a valid reference, so it is also tested - here. */ + /* Only unsubscribe after actually closing the file and sending any + notifications. This depends on a valid reference, so it is also tested + here. */ - if (l4_is_valid_cap(file->ref)) notifier_get_task_notifier()->unsubscribe(file); + } if (file->memory != NULL) ipc_detach_dataspace(file->memory); @@ -282,7 +284,10 @@ if (err) return err; - memcpy(st, context->memory, sizeof(struct stat)); + /* Copy the stat structure manually in case of any divergence. */ + + systypes_copy_from_sys_stat(st, (sys_stat_t *) context->memory); + return L4_EOK; } diff -r f58459304d83 -r d91bc1fca788 libfsserver/include/fsserver/ext2_file_opener.h --- a/libfsserver/include/fsserver/ext2_file_opener.h Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/include/fsserver/ext2_file_opener.h Wed Mar 02 22:27:28 2022 +0100 @@ -64,6 +64,8 @@ virtual long make_directory_accessor(flags_t flags, fileid_t fileid, DirectoryAccessor **accessor); + /* Filesystem object access and manipulation methods. */ + virtual long remove_object(fileid_t fileid); virtual long rename_object(const char *source, const char *target); diff -r f58459304d83 -r d91bc1fca788 libfsserver/include/fsserver/file_opening.h --- a/libfsserver/include/fsserver/file_opening.h Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/include/fsserver/file_opening.h Wed Mar 02 22:27:28 2022 +0100 @@ -47,6 +47,8 @@ virtual long make_directory_accessor(flags_t flags, fileid_t fileid, DirectoryAccessor **accessor) = 0; + /* Filesystem object access and manipulation methods. */ + virtual long stat_object(const char *path, void *base, offset_t size) = 0; virtual long remove_object(fileid_t fileid) = 0; diff -r f58459304d83 -r d91bc1fca788 libfsserver/include/fsserver/host_file_opener.h --- a/libfsserver/include/fsserver/host_file_opener.h Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/include/fsserver/host_file_opener.h Wed Mar 02 22:27:28 2022 +0100 @@ -78,6 +78,8 @@ virtual long make_directory_accessor(flags_t flags, fileid_t fileid, DirectoryAccessor **accessor); + /* Filesystem object access and manipulation methods. */ + virtual long remove_object(fileid_t fileid); virtual long rename_object(const char *source, const char *target); diff -r f58459304d83 -r d91bc1fca788 libfsserver/include/fsserver/test_file_opener.h --- a/libfsserver/include/fsserver/test_file_opener.h Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/include/fsserver/test_file_opener.h Wed Mar 02 22:27:28 2022 +0100 @@ -55,6 +55,8 @@ virtual long make_directory_accessor(flags_t flags, fileid_t fileid, DirectoryAccessor **accessor); + /* Filesystem object access and manipulation methods. */ + virtual long remove_object(fileid_t fileid); virtual long rename_object(const char *source, const char *target); diff -r f58459304d83 -r d91bc1fca788 libfsserver/lib/files/ext2_file_opener.cc --- a/libfsserver/lib/files/ext2_file_opener.cc Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/lib/files/ext2_file_opener.cc Wed Mar 02 22:27:28 2022 +0100 @@ -24,6 +24,7 @@ #include #include #include +#include #include "ext2_directory_accessor.h" #include "ext2_file_accessor.h" @@ -129,22 +130,7 @@ return L4_EOK; } -/* Populate a memory region with statistics metadata for a filesystem object. */ -long Ext2FileOpener::stat_object(const char *path, void *base, offset_t size) -{ - struct stat *st = (struct stat *) base; - fileid_t fileid; - long err = get_fileid(path, 0, &fileid); - - if (err) - return err; - - if (sizeof(struct stat) > size) - return -L4_ENOMEM; - - return _ops->stat_inode((ext2_ino_t) fileid, st); -} /* Remove a filesystem object. */ @@ -180,6 +166,33 @@ (ext2_ino_t) target_parent, path_basename(target)); } +/* Populate a memory region with statistics metadata for a filesystem object. */ + +long Ext2FileOpener::stat_object(const char *path, void *base, offset_t size) +{ + struct stat st; + fileid_t fileid; + long err = get_fileid(path, 0, &fileid); + + if (err) + return err; + + if (sizeof(struct stat) > size) + return -L4_ENOMEM; + + err = _ops->stat_inode((ext2_ino_t) fileid, &st); + + if (err) + return err; + + /* Use the systypes version of the structure to permit different library + implementations on the client and server sides of an IPC invocation. */ + + systypes_copy_to_sys_stat(&st, (sys_stat_t *) base); + + return L4_EOK; +} + /* Unlink a filesystem object. */ long Ext2FileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid) diff -r f58459304d83 -r d91bc1fca788 libfsserver/lib/files/host_file_opener.cc --- a/libfsserver/lib/files/host_file_opener.cc Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/lib/files/host_file_opener.cc Wed Mar 02 22:27:28 2022 +0100 @@ -196,17 +196,7 @@ return L4_EOK; } -/* Populate a memory region with statistics metadata for a filesystem object. */ -long HostFileOpener::stat_object(const char *path, void *base, offset_t size) -{ - struct stat *st = (struct stat *) base; - - if (sizeof(struct stat) > size) - return -L4_ENOMEM; - - return ::stat(path, st); -} /* Remove a filesystem object. */ @@ -228,6 +218,18 @@ return L4_EOK; } +/* Populate a memory region with statistics metadata for a filesystem object. */ + +long HostFileOpener::stat_object(const char *path, void *base, offset_t size) +{ + struct stat *st = (struct stat *) base; + + if (sizeof(struct stat) > size) + return -L4_ENOMEM; + + return ::stat(path, st); +} + /* Unlink a filesystem object. */ long HostFileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid) diff -r f58459304d83 -r d91bc1fca788 libfsserver/lib/files/test_file_opener.cc --- a/libfsserver/lib/files/test_file_opener.cc Wed Mar 02 22:27:19 2022 +0100 +++ b/libfsserver/lib/files/test_file_opener.cc Wed Mar 02 22:27:28 2022 +0100 @@ -86,13 +86,7 @@ return -L4_EIO; } -/* Populate a memory region with statistics metadata for a filesystem object. */ -long TestFileOpener::stat_object(const char *path, void *base, offset_t size) -{ - (void) path; (void) base; (void) size; - return -L4_EIO; -} /* Remove a filesystem object. */ @@ -110,6 +104,14 @@ return -L4_EIO; } +/* Populate a memory region with statistics metadata for a filesystem object. */ + +long TestFileOpener::stat_object(const char *path, void *base, offset_t size) +{ + (void) path; (void) base; (void) size; + return -L4_EIO; +} + /* Unlink a filesystem object. */ long TestFileOpener::unlink_object(fileid_t parent_fileid, fileid_t fileid) diff -r f58459304d83 -r d91bc1fca788 libsystypes/include/systypes/base.h --- a/libsystypes/include/systypes/base.h Wed Mar 02 22:27:19 2022 +0100 +++ b/libsystypes/include/systypes/base.h Wed Mar 02 22:27:28 2022 +0100 @@ -65,12 +65,16 @@ /* Equivalent types are defined in sys/types.h typically. In newlib, they are defined in sys/_types.h if not defined elsewhere (such as in - machine/_types.h). */ + machine/_types.h). -typedef unsigned long long sys_dev_t; /* device number */ -typedef unsigned long sys_ino_t; /* inode number */ + These types are intended for IPC, permitting different parties to employ + different library implementations where these types may be different. +*/ + +typedef unsigned long int sys_dev_t; /* device number */ +typedef unsigned long int sys_ino_t; /* inode number */ typedef unsigned int sys_mode_t; /* file permissions */ -typedef unsigned int sys_nlink_t; /* link count */ +typedef unsigned long int sys_nlink_t; /* link count */ typedef unsigned int sys_uid_t; /* user identifier */ typedef unsigned int sys_gid_t; /* group identifier */ typedef long sys_off_t; /* file offset/position */ diff -r f58459304d83 -r d91bc1fca788 libsystypes/include/systypes/stat.h --- a/libsystypes/include/systypes/stat.h Wed Mar 02 22:27:19 2022 +0100 +++ b/libsystypes/include/systypes/stat.h Wed Mar 02 22:27:28 2022 +0100 @@ -1,7 +1,7 @@ /* * File metadata abstractions. * - * Copyright (C) 2019 Paul Boddie + * Copyright (C) 2019, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -21,6 +21,8 @@ #pragma once +#include + #include #include @@ -46,4 +48,11 @@ } sys_stat_t; +void systypes_copy_from_sys_stat(struct stat *st, sys_stat_t *sst); + +void systypes_copy_to_sys_stat(struct stat *st, sys_stat_t *sst); + EXTERN_C_END + +/* vim: tabstop=4 expandtab shiftwidth=4 +*/ diff -r f58459304d83 -r d91bc1fca788 tests/dstest_file_readdir.cc --- a/tests/dstest_file_readdir.cc Wed Mar 02 22:27:19 2022 +0100 +++ b/tests/dstest_file_readdir.cc Wed Mar 02 22:27:28 2022 +0100 @@ -81,12 +81,12 @@ printf("%s %ld %ld %x %d %d ", path, st.st_size, st.st_blocks, st.st_mode, st.st_uid, st.st_gid); - printf("%d %d %d %x %x ", + printf("%ld %ld %ld %x %x ", st.st_dev, st.st_ino, st.st_nlink, major(st.st_rdev), minor(st.st_rdev)); - printf("%d %d %d ", - st.st_atim, st.st_mtim, st.st_ctim); + printf("%ld %ld %ld ", + st.st_atim.tv_sec, st.st_mtim.tv_sec, st.st_ctim.tv_sec); /* NOTE: Arbitrary values: %W (creation time) given as 0