1.1 --- a/libe2access/host/e2access.c Thu Feb 17 19:41:23 2022 +0100
1.2 +++ b/libe2access/host/e2access.c Thu Feb 17 19:42:31 2022 +0100
1.3 @@ -226,7 +226,7 @@
1.4
1.5 /* Locate the target and test whether it is a file or a directory. */
1.6
1.7 - if (image_find_path(fs, &target_remaining, &ino_target))
1.8 + if (image_resolve_by_path(fs, &target_remaining, &ino_target))
1.9 {
1.10 /* Only a non-existent file in an existing directory is permitted. */
1.11
1.12 @@ -410,7 +410,7 @@
1.13 {
1.14 path = argv[i];
1.15
1.16 - if (image_find_path(fs, &path, &ino_file))
1.17 + if (image_find_by_path(fs, path, &ino_file))
1.18 {
1.19 fprintf(stderr, "Failed to find file: %s\n", argv[i]);
1.20 return 1;
1.21 @@ -471,7 +471,7 @@
1.22
1.23 /* Search for the remaining components. */
1.24
1.25 - if ((!*path) || !image_find_path(fs, &path, &ino))
1.26 + if ((!*path) || !image_resolve_by_path(fs, &path, &ino))
1.27 {
1.28 fprintf(stderr, "Path exists: %s\n", argv[i]);
1.29 return 1;
2.1 --- a/libe2access/include/e2access/image.h Thu Feb 17 19:41:23 2022 +0100
2.2 +++ b/libe2access/include/e2access/image.h Thu Feb 17 19:42:31 2022 +0100
2.3 @@ -49,16 +49,18 @@
2.4
2.5 int image_file_type(int mode);
2.6
2.7 -errcode_t image_find_next(ext2_filsys fs, ext2_ino_t ino_dir,
2.8 - const char **basename, char *buf, ext2_ino_t *ino);
2.9 +errcode_t image_find_by_path(ext2_filsys fs, const char *path, ext2_ino_t *ino);
2.10
2.11 -errcode_t image_find_path(ext2_filsys fs, const char **pathname,
2.12 - ext2_ino_t *ino);
2.13 +errcode_t image_resolve_by_path(ext2_filsys fs, const char **path,
2.14 + ext2_ino_t *ino);
2.15 +
2.16 +errcode_t image_resolve_next(ext2_filsys fs, ext2_ino_t ino_dir,
2.17 + const char **basename, char *buf, ext2_ino_t *ino);
2.18
2.19 errcode_t image_find_file(ext2_filsys fs, const char *dirname,
2.20 const char *basename, ext2_ino_t *ino);
2.21
2.22 -errcode_t image_inode(ext2_filsys fs, const char *pathname,
2.23 +errcode_t image_inode(ext2_filsys fs, const char *path,
2.24 struct ext2_inode *inode);
2.25
2.26 errcode_t image_inode_refcount_update(ext2_filsys fs, ext2_ino_t ino,
2.27 @@ -77,7 +79,7 @@
2.28 const char **basename, __u16 mode, __u16 uid,
2.29 __u16 gid, ext2_ino_t *ino);
2.30
2.31 -errcode_t image_make_dirs(ext2_filsys fs, const char **pathname,
2.32 +errcode_t image_make_dirs(ext2_filsys fs, const char **path,
2.33 ext2_ino_t ino_dir, __u16 mode, __u16 uid,
2.34 __u16 gid);
2.35
3.1 --- a/libe2access/lib/src/image.c Thu Feb 17 19:41:23 2022 +0100
3.2 +++ b/libe2access/lib/src/image.c Thu Feb 17 19:42:31 2022 +0100
3.3 @@ -125,8 +125,7 @@
3.4 errcode_t (*op)(ext2_filsys, ext2_ino_t),
3.5 ext2_ino_t *ino)
3.6 {
3.7 - const char *remaining = path;
3.8 - errcode_t retval = image_find_path(fs, &remaining, ino);
3.9 + errcode_t retval = image_find_by_path(fs, path, ino);
3.10
3.11 if (retval)
3.12 return retval;
3.13 @@ -226,30 +225,17 @@
3.14 }
3.15 }
3.16
3.17 -/* Find an object in the given directory with the given name in the filesystem
3.18 - image, updating the name reference to refer to the next component. */
3.19 -
3.20 -errcode_t image_find_next(ext2_filsys fs, ext2_ino_t ino_dir,
3.21 - const char **basename, char *buf, ext2_ino_t *ino)
3.22 -{
3.23 - const char *end = path_component_end(*basename);
3.24 - errcode_t retval;
3.25 +/* Find an object with the given path in the filesystem image. */
3.26
3.27 - /* Find the basename in the directory. */
3.28 -
3.29 - retval = ext2fs_lookup(fs, ino_dir, *basename, end - *basename, buf, ino);
3.30 -
3.31 - /* Update the current component. */
3.32 -
3.33 - if (!retval)
3.34 - *basename = path_component_next(end);
3.35 -
3.36 - return retval;
3.37 +errcode_t image_find_by_path(ext2_filsys fs, const char *path, ext2_ino_t *ino)
3.38 +{
3.39 + return image_resolve_by_path(fs, &path, ino);
3.40 }
3.41
3.42 -/* Find an object with the given pathname in the filesystem image. */
3.43 +/* Find an object with the given path in the filesystem image. */
3.44
3.45 -errcode_t image_find_path(ext2_filsys fs, const char **pathname, ext2_ino_t *ino)
3.46 +errcode_t image_resolve_by_path(ext2_filsys fs, const char **path,
3.47 + ext2_ino_t *ino)
3.48 {
3.49 char *buf;
3.50 ext2_ino_t ino_dir;
3.51 @@ -261,10 +247,10 @@
3.52
3.53 /* Skip any leading root marker. */
3.54
3.55 - if (**pathname == '/')
3.56 - (*pathname)++;
3.57 + if (**path == '/')
3.58 + (*path)++;
3.59
3.60 - if (!**pathname)
3.61 + if (!**path)
3.62 *ino = EXT2_ROOT_INO;
3.63
3.64 /* Start at the root. */
3.65 @@ -273,9 +259,9 @@
3.66
3.67 /* With any remaining path, find the next component. */
3.68
3.69 - while (**pathname)
3.70 + while (**path)
3.71 {
3.72 - retval = image_find_next(fs, ino_dir, pathname, buf, ino);
3.73 + retval = image_resolve_next(fs, ino_dir, path, buf, ino);
3.74 if (retval)
3.75 {
3.76 *ino = ino_dir;
3.77 @@ -293,31 +279,52 @@
3.78 }
3.79
3.80 /* Find an object in the given directory with the given name in the filesystem
3.81 + image, updating the name reference to refer to the next component. */
3.82 +
3.83 +errcode_t image_resolve_next(ext2_filsys fs, ext2_ino_t ino_dir,
3.84 + const char **basename, char *buf, ext2_ino_t *ino)
3.85 +{
3.86 + const char *end = path_component_end(*basename);
3.87 + errcode_t retval;
3.88 +
3.89 + /* Find the basename in the directory. */
3.90 +
3.91 + retval = ext2fs_lookup(fs, ino_dir, *basename, end - *basename, buf, ino);
3.92 +
3.93 + /* Update the current component. */
3.94 +
3.95 + if (!retval)
3.96 + *basename = path_component_next(end);
3.97 +
3.98 + return retval;
3.99 +}
3.100 +
3.101 +/* Find an object in the given directory with the given name in the filesystem
3.102 image. */
3.103
3.104 errcode_t image_find_file(ext2_filsys fs, const char *dirname,
3.105 const char *basename, ext2_ino_t *ino)
3.106 {
3.107 - char pathname[strlen(dirname) + strlen(basename) + 2];
3.108 - const char *s = pathname;
3.109 + char path[strlen(dirname) + strlen(basename) + 2];
3.110
3.111 - strcpy(pathname, dirname);
3.112 - strcat(pathname, "/");
3.113 - strcat(pathname, basename);
3.114 + strcpy(path, dirname);
3.115 + strcat(path, "/");
3.116 + strcat(path, basename);
3.117
3.118 - return image_find_path(fs, &s, ino);
3.119 + return image_find_by_path(fs, path, ino);
3.120 }
3.121
3.122 -/* Obtain the inode for the object with the given pathname in the filesystem
3.123 +/* Obtain the inode for the object with the given path in the filesystem
3.124 image. */
3.125
3.126 -errcode_t image_inode(ext2_filsys fs, const char *pathname,
3.127 +errcode_t image_inode(ext2_filsys fs, const char *path,
3.128 struct ext2_inode *inode)
3.129 {
3.130 ext2_ino_t ino;
3.131 errcode_t retval;
3.132
3.133 - retval = image_find_path(fs, &pathname, &ino);
3.134 + retval = image_find_by_path(fs, path, &ino);
3.135 +
3.136 if (retval)
3.137 return retval;
3.138
3.139 @@ -363,7 +370,8 @@
3.140
3.141 /* Locate the object and test whether it is a directory. */
3.142
3.143 - retval = image_find_path(fs, &path, &ino);
3.144 + retval = image_find_by_path(fs, path, &ino);
3.145 +
3.146 if (retval)
3.147 {
3.148 ext2fs_free_mem(&buf);
3.149 @@ -376,6 +384,7 @@
3.150 /* List the directory contents. */
3.151
3.152 retval = ext2fs_dir_iterate(fs, ino, 0, buf, proc, data);
3.153 +
3.154 if (retval)
3.155 {
3.156 ext2fs_free_mem(&buf);
3.157 @@ -451,15 +460,15 @@
3.158
3.159 /* Make directories descending to the given path in the filesystem image. */
3.160
3.161 -errcode_t image_make_dirs(ext2_filsys fs, const char **pathname,
3.162 +errcode_t image_make_dirs(ext2_filsys fs, const char **path,
3.163 ext2_ino_t ino_dir, __u16 mode, __u16 uid, __u16 gid)
3.164 {
3.165 ext2_ino_t ino;
3.166 errcode_t retval;
3.167
3.168 - while (**pathname)
3.169 + while (**path)
3.170 {
3.171 - retval = image_make_next_dir(fs, ino_dir, pathname, mode, uid, gid, &ino);
3.172 + retval = image_make_next_dir(fs, ino_dir, path, mode, uid, gid, &ino);
3.173 if (retval)
3.174 return retval;
3.175
3.176 @@ -668,7 +677,6 @@
3.177 errcode_t image_unlink_by_path(ext2_filsys fs, const char *path)
3.178 {
3.179 char _path[strlen(path) + 1];
3.180 - const char *remaining = _path;
3.181 char *basename;
3.182 ext2_ino_t ino_parent;
3.183 errcode_t retval;
3.184 @@ -682,7 +690,7 @@
3.185
3.186 if (basename != _path)
3.187 {
3.188 - retval = image_find_path(fs, &remaining, &ino_parent);
3.189 + retval = image_find_by_path(fs, _path, &ino_parent);
3.190
3.191 if (retval)
3.192 return retval;
3.193 @@ -709,7 +717,7 @@
3.194 {
3.195 ext2_ino_t ino;
3.196
3.197 - return !image_find_path(fs, &name, &ino);
3.198 + return !image_find_by_path(fs, name, &ino);
3.199 }
3.200
3.201 int _image_isdir(ext2_filsys fs, ext2_ino_t ino)
3.202 @@ -731,7 +739,7 @@
3.203
3.204 int image_isdir_by_path(ext2_filsys fs, const char *name, ext2_ino_t *ino)
3.205 {
3.206 - if (image_find_path(fs, &name, ino))
3.207 + if (image_find_by_path(fs, name, ino))
3.208 return 0;
3.209
3.210 return _image_isdir(fs, *ino);
3.211 @@ -756,7 +764,7 @@
3.212
3.213 int image_isfile_by_path(ext2_filsys fs, const char *name, ext2_ino_t *ino)
3.214 {
3.215 - if (image_find_path(fs, &name, ino))
3.216 + if (image_find_by_path(fs, name, ino))
3.217 return 0;
3.218
3.219 return _image_isfile(fs, *ino);