1.1 --- a/libe2access/host/e2access.c Wed Feb 16 01:25:39 2022 +0100
1.2 +++ b/libe2access/host/e2access.c Wed Feb 16 17:55:47 2022 +0100
1.3 @@ -33,6 +33,7 @@
1.4 #include "format.h"
1.5 #include "image.h"
1.6 #include "path.h"
1.7 +#include "utils.h"
1.8
1.9
1.10
1.11 @@ -93,50 +94,6 @@
1.12
1.13
1.14
1.15 -/* Show directory entries when iterating. */
1.16 -
1.17 -struct _list_dir_data
1.18 -{
1.19 - ext2_filsys fs;
1.20 - char *filename;
1.21 -};
1.22 -
1.23 -static int _list_dir_proc(struct ext2_dir_entry *dirent, int offset,
1.24 - int blocksize, char *buf, void *priv_data)
1.25 -{
1.26 - struct _list_dir_data *data = (struct _list_dir_data *) priv_data;
1.27 - ext2_filsys fs = data->fs;
1.28 - struct ext2_inode inode;
1.29 -
1.30 - /* Select any indicated filename. */
1.31 -
1.32 - if ((data->filename != NULL) && (strcmp(dirent->name, data->filename)))
1.33 - return 0;
1.34 -
1.35 - /* Obtain the inode details for metadata. */
1.36 -
1.37 - if (ext2fs_read_inode(fs, dirent->inode, &inode))
1.38 - return DIRENT_ABORT;
1.39 -
1.40 - /* Output details in the style of "ls -l" showing directory, permissions,
1.41 - owner, group and size information. */
1.42 -
1.43 - printf("%s%s %5d %5d %6d ",
1.44 - _image_isdir(fs, dirent->inode) ? "d" : "-",
1.45 - get_permission_string(inode.i_mode),
1.46 - inode.i_uid,
1.47 - inode.i_gid,
1.48 - EXT2_I_SIZE(&inode));
1.49 -
1.50 - /* Output the name which is presumably not necessarily null-terminated. */
1.51 -
1.52 - fwrite(dirent->name, sizeof(char), ext2fs_dirent_name_len(dirent), stdout);
1.53 - fputc((int) '\n', stdout);
1.54 - return 0;
1.55 -}
1.56 -
1.57 -
1.58 -
1.59 /* Copy a file into the filesystem image. */
1.60
1.61 int copy_file_in(const char *filename, ext2_filsys fs, ext2_ino_t ino_file, int flags)
1.62 @@ -477,7 +434,6 @@
1.63 {
1.64 int i;
1.65 char *path;
1.66 - struct _list_dir_data data;
1.67
1.68 for (i = 0; i < argc; i++)
1.69 {
1.70 @@ -489,14 +445,7 @@
1.71
1.72 /* List individual files or directories. */
1.73
1.74 - if (image_isfile(fs, path))
1.75 - data.filename = path_split(path);
1.76 - else
1.77 - data.filename = NULL;
1.78 -
1.79 - data.fs = fs;
1.80 -
1.81 - if (image_list_dir(fs, path, _list_dir_proc, &data))
1.82 + if (utils_list_dir(fs, path))
1.83 {
1.84 fprintf(stderr, "Failed to list directory: %s\n", path);
1.85 return 1;