# HG changeset patch # User Paul Boddie # Date 1645132373 -3600 # Node ID 85345ba9f3db3e15af244c0842f21d7518d35899 # Parent ccbbee67d9fc3b875b8f41e0a0f72099ec608d83 Introduced a simpler inode finding function, image_find_by_path, renaming the existing function from image_find_path to image_resolve_by_path. Simplified various path-based functions to not return inode numbers, and renamed the type testing functions to be consistent with more recently introduced functions. diff -r ccbbee67d9fc -r 85345ba9f3db libe2access/host/e2access.c --- a/libe2access/host/e2access.c Thu Feb 17 19:42:31 2022 +0100 +++ b/libe2access/host/e2access.c Thu Feb 17 22:12:53 2022 +0100 @@ -230,7 +230,7 @@ { /* Only a non-existent file in an existing directory is permitted. */ - if (!_image_isdir(fs, ino_target) || !path_is_leafname(target_remaining)) + if (!image_isdir_by_inode(fs, ino_target) || !path_is_leafname(target_remaining)) { fprintf(stderr, "Target not found: %s\n", target); return 1; @@ -241,7 +241,7 @@ } else { - target_is_file = _image_isfile(fs, ino_target); + target_is_file = image_isfile_by_inode(fs, ino_target); target_is_new = 0; } @@ -255,7 +255,7 @@ return 1; } } - else if (!_image_isdir(fs, ino_target)) + else if (!image_isdir_by_inode(fs, ino_target)) { fprintf(stderr, "Target is not a directory: %s\n", target); return 1; @@ -397,7 +397,7 @@ for (i = 0; i < argc - 1; i++) { - if (!image_isfile(fs, argv[i])) + if (!image_isfile_by_path(fs, argv[i])) { fprintf(stderr, "Source is not a file: %s\n", argv[i]); return 1; @@ -509,7 +509,7 @@ /* Detect missing objects. */ - if ((!*path) || !image_exists(fs, path)) + if ((!*path) || image_find_by_path(fs, path, &ino)) { fprintf(stderr, "Not found: %s\n", path); return 1; @@ -519,7 +519,7 @@ if (dir_only) { - if (!image_isdir(fs, path)) + if (!image_isdir_by_inode(fs, ino)) { fprintf(stderr, "Not a directory: %s\n", path); return 1; @@ -527,7 +527,7 @@ /* Test for an empty directory. */ - if (image_dir_empty_by_path(fs, path, &ino)) + if (image_dir_empty_by_inode(fs, ino)) { fprintf(stderr, "Directory not empty: %s\n", path); return 1; @@ -536,7 +536,7 @@ /* Otherwise, insist on a non-directory. */ - else if (image_isdir_by_path(fs, path, &ino)) + else if (image_isdir_by_inode(fs, ino)) { fprintf(stderr, "Cannot remove a directory: %s\n", path); return 1; diff -r ccbbee67d9fc -r 85345ba9f3db libe2access/include/e2access/image.h --- a/libe2access/include/e2access/image.h Thu Feb 17 19:42:31 2022 +0100 +++ b/libe2access/include/e2access/image.h Thu Feb 17 22:12:53 2022 +0100 @@ -107,19 +107,15 @@ /* Presence and type tests. */ -int image_exists(ext2_filsys fs, const char *name); +int image_exists(ext2_filsys fs, const char *path); -int _image_isdir(ext2_filsys fs, ext2_ino_t ino); - -int image_isdir(ext2_filsys fs, const char *name); +int image_isdir_by_inode(ext2_filsys fs, ext2_ino_t ino); -int image_isdir_by_path(ext2_filsys fs, const char *name, ext2_ino_t *ino); - -int _image_isfile(ext2_filsys fs, ext2_ino_t ino); +int image_isdir_by_path(ext2_filsys fs, const char *path); -int image_isfile(ext2_filsys fs, const char *name); +int image_isfile_by_inode(ext2_filsys fs, ext2_ino_t ino); -int image_isfile_by_path(ext2_filsys fs, const char *name, ext2_ino_t *ino); +int image_isfile_by_path(ext2_filsys fs, const char *path); #ifdef __cplusplus } diff -r ccbbee67d9fc -r 85345ba9f3db libe2access/lib/src/image.c --- a/libe2access/lib/src/image.c Thu Feb 17 19:42:31 2022 +0100 +++ b/libe2access/lib/src/image.c Thu Feb 17 22:12:53 2022 +0100 @@ -378,7 +378,7 @@ return retval; } - if (!_image_isdir(fs, ino)) + if (!image_isdir_by_inode(fs, ino)) return 1; /* List the directory contents. */ @@ -487,7 +487,7 @@ struct ext2_inode_large inode; ext2_ino_t ino_parent = 0; errcode_t retval; - int isdir = _image_isdir(fs, ino); + int isdir = image_isdir_by_inode(fs, ino); if (isdir) { @@ -585,7 +585,7 @@ if (retval) return retval; - if (_image_isdir(fs, source)) + if (image_isdir_by_inode(fs, source)) { /* Update the link count for the target. */ @@ -713,14 +713,14 @@ /* Test object presence and types in the filesystem image. */ -int image_exists(ext2_filsys fs, const char *name) +int image_exists(ext2_filsys fs, const char *path) { ext2_ino_t ino; - return !image_find_by_path(fs, name, &ino); + return !image_find_by_path(fs, path, &ino); } -int _image_isdir(ext2_filsys fs, ext2_ino_t ino) +int image_isdir_by_inode(ext2_filsys fs, ext2_ino_t ino) { struct ext2_inode inode; @@ -730,22 +730,17 @@ return LINUX_S_ISDIR(inode.i_mode); } -int image_isdir(ext2_filsys fs, const char *name) +int image_isdir_by_path(ext2_filsys fs, const char *path) { ext2_ino_t ino; - return image_isdir_by_path(fs, name, &ino); + if (image_find_by_path(fs, path, &ino)) + return 0; + + return image_isdir_by_inode(fs, ino); } -int image_isdir_by_path(ext2_filsys fs, const char *name, ext2_ino_t *ino) -{ - if (image_find_by_path(fs, name, ino)) - return 0; - - return _image_isdir(fs, *ino); -} - -int _image_isfile(ext2_filsys fs, ext2_ino_t ino) +int image_isfile_by_inode(ext2_filsys fs, ext2_ino_t ino) { struct ext2_inode inode; @@ -755,19 +750,14 @@ return LINUX_S_ISREG(inode.i_mode); } -int image_isfile(ext2_filsys fs, const char *name) +int image_isfile_by_path(ext2_filsys fs, const char *path) { ext2_ino_t ino; - return image_isfile_by_path(fs, name, &ino); -} - -int image_isfile_by_path(ext2_filsys fs, const char *name, ext2_ino_t *ino) -{ - if (image_find_by_path(fs, name, ino)) + if (image_find_by_path(fs, path, &ino)) return 0; - return _image_isfile(fs, *ino); + return image_isfile_by_inode(fs, ino); } /* vim: tabstop=4 expandtab shiftwidth=4 diff -r ccbbee67d9fc -r 85345ba9f3db libe2access/lib/src/utils.c --- a/libe2access/lib/src/utils.c Thu Feb 17 19:42:31 2022 +0100 +++ b/libe2access/lib/src/utils.c Thu Feb 17 22:12:53 2022 +0100 @@ -39,7 +39,7 @@ /* Select a specific object, if appropriate. */ - if (!image_isdir(fs, path)) + if (!image_isdir_by_path(fs, path)) data.filename = path_basename(path); else data.filename = NULL; @@ -76,7 +76,7 @@ owner, group and size information. */ printf("%s%s %5d %5d %6lld ", - _image_isdir(fs, dirent->inode) ? "d" : "-", + image_isdir_by_inode(fs, dirent->inode) ? "d" : "-", get_permission_string(inode.i_mode), inode.i_uid, inode.i_gid, diff -r ccbbee67d9fc -r 85345ba9f3db libfsserver/lib/files/ext2_file_operations.cc --- a/libfsserver/lib/files/ext2_file_operations.cc Thu Feb 17 19:42:31 2022 +0100 +++ b/libfsserver/lib/files/ext2_file_operations.cc Thu Feb 17 22:12:53 2022 +0100 @@ -59,7 +59,7 @@ { std::lock_guard guard(_lock); - return _image_isdir(_fs, ino_file); + return image_isdir_by_inode(_fs, ino_file); } /* Test for a file. */ @@ -68,7 +68,7 @@ { std::lock_guard guard(_lock); - return _image_isfile(_fs, ino_file); + return image_isfile_by_inode(_fs, ino_file); } @@ -119,7 +119,7 @@ std::lock_guard guard(_lock); *remaining = path; - errcode_t retval = image_find_path(_fs, remaining, ino); + errcode_t retval = image_resolve_by_path(_fs, remaining, ino); // NOTE: Map error conditions.