1.1 --- a/libe2access/include/e2access/image.h Mon Feb 14 00:42:55 2022 +0100
1.2 +++ b/libe2access/include/e2access/image.h Mon Feb 14 00:44:19 2022 +0100
1.3 @@ -29,6 +29,8 @@
1.4 extern "C" {
1.5 #endif
1.6
1.7 +/* Filesystem operations. */
1.8 +
1.9 errcode_t image_create_file(ext2_filsys fs, ext2_ino_t ino_target,
1.10 const char *basename, __u16 mode,
1.11 __u16 uid, __u16 gid, ext2_ino_t *ino_file);
1.12 @@ -66,6 +68,8 @@
1.13
1.14 errcode_t image_remove_by_inode(ext2_filsys fs, ext2_ino_t ino);
1.15
1.16 +errcode_t image_remove_by_path(ext2_filsys fs, const char *path);
1.17 +
1.18 errcode_t image_rename(ext2_filsys fs, ext2_ino_t source,
1.19 ext2_ino_t source_parent, const char *source_basename,
1.20 ext2_ino_t target_parent, const char *target_basename);
1.21 @@ -78,9 +82,15 @@
1.22 errcode_t image_unlink_by_name(ext2_filsys fs, ext2_ino_t ino_parent,
1.23 const char *basename);
1.24
1.25 +errcode_t image_unlink_by_path(ext2_filsys fs, const char *path);
1.26 +
1.27 errcode_t image_unlink_by_inode(ext2_filsys fs, ext2_ino_t ino_parent,
1.28 ext2_ino_t ino);
1.29
1.30 +/* Presence and type tests. */
1.31 +
1.32 +int image_exists(ext2_filsys fs, const char *name);
1.33 +
1.34 int _image_isdir(ext2_filsys fs, ext2_ino_t ino);
1.35
1.36 int image_isdir(ext2_filsys fs, const char *name);
2.1 --- a/libe2access/lib/src/image.c Mon Feb 14 00:42:55 2022 +0100
2.2 +++ b/libe2access/lib/src/image.c Mon Feb 14 00:44:19 2022 +0100
2.3 @@ -84,6 +84,8 @@
2.4 return 0;
2.5 }
2.6
2.7 +
2.8 +
2.9 /* Create an inode for a file. */
2.10
2.11 errcode_t image_create_file(ext2_filsys fs, ext2_ino_t ino_target,
2.12 @@ -404,6 +406,20 @@
2.13 sizeof(inode));
2.14 }
2.15
2.16 +/* Remove a directory entry using its full path. */
2.17 +
2.18 +errcode_t image_remove_by_path(ext2_filsys fs, const char *path)
2.19 +{
2.20 + const char *remaining = path;
2.21 + ext2_ino_t ino;
2.22 + errcode_t retval = image_find_path(fs, &remaining, &ino);
2.23 +
2.24 + if (retval)
2.25 + return retval;
2.26 +
2.27 + return image_remove_by_inode(fs, ino);
2.28 +}
2.29 +
2.30 /* Rename a file. */
2.31
2.32 errcode_t image_rename(ext2_filsys fs, ext2_ino_t source,
2.33 @@ -529,7 +545,26 @@
2.34 errcode_t image_unlink_by_name(ext2_filsys fs, ext2_ino_t ino_parent,
2.35 const char *basename)
2.36 {
2.37 - /* NOTE: This might do more work for a directory. */
2.38 + return ext2fs_unlink(fs, ino_parent, basename, 0, 0);
2.39 +}
2.40 +
2.41 +/* Unlink a directory entry by full path. */
2.42 +
2.43 +errcode_t image_unlink_by_path(ext2_filsys fs, const char *path)
2.44 +{
2.45 + char _path[strlen(path) + 1];
2.46 + const char *remaining = _path;
2.47 + char *basename;
2.48 + ext2_ino_t ino_parent;
2.49 + errcode_t retval;
2.50 +
2.51 + strcpy(_path, path);
2.52 + basename = path_split(_path);
2.53 +
2.54 + retval = image_find_path(fs, &remaining, &ino_parent);
2.55 +
2.56 + if (retval)
2.57 + return retval;
2.58
2.59 return ext2fs_unlink(fs, ino_parent, basename, 0, 0);
2.60 }
2.61 @@ -539,12 +574,19 @@
2.62 errcode_t image_unlink_by_inode(ext2_filsys fs, ext2_ino_t ino_parent,
2.63 ext2_ino_t ino)
2.64 {
2.65 - /* NOTE: This might do more work for a directory. */
2.66 -
2.67 return ext2fs_unlink(fs, ino_parent, 0, ino, 0);
2.68 }
2.69
2.70 -/* Test object types in the filesystem image. */
2.71 +
2.72 +
2.73 +/* Test object presence and types in the filesystem image. */
2.74 +
2.75 +int image_exists(ext2_filsys fs, const char *name)
2.76 +{
2.77 + ext2_ino_t ino;
2.78 +
2.79 + return !image_find_path(fs, &name, &ino);
2.80 +}
2.81
2.82 int _image_isdir(ext2_filsys fs, ext2_ino_t ino)
2.83 {