1.1 --- a/libe2access/lib/src/image.c Wed Feb 16 17:55:47 2022 +0100
1.2 +++ b/libe2access/lib/src/image.c Wed Feb 16 18:21:01 2022 +0100
1.3 @@ -60,28 +60,21 @@
1.4 return 0;
1.5 }
1.6
1.7 -/* Common parent entry state. */
1.8 -
1.9 -struct _image_parent_entry_state
1.10 -{
1.11 - ext2_ino_t ino;
1.12 - int nonempty;
1.13 -};
1.14 -
1.15 /* Get entry details for a directory to be removed. */
1.16
1.17 static int _image_get_parent_entry(struct ext2_dir_entry *dir_entry,
1.18 int offset, int blocksize, char *buf,
1.19 void *priv_data)
1.20 {
1.21 - struct _image_parent_entry_state *state = (struct _image_parent_entry_state *) priv_data;
1.22 + ext2_ino_t *ino = (ext2_ino_t *) priv_data;
1.23
1.24 (void) offset; (void) blocksize; (void) buf;
1.25
1.26 if (!strcmp(dir_entry->name, ".."))
1.27 - state->ino = dir_entry->inode;
1.28 - else if (strcmp(dir_entry->name, "."))
1.29 - state->nonempty = 1;
1.30 + {
1.31 + *ino = dir_entry->inode;
1.32 + return DIRENT_ABORT;
1.33 + }
1.34
1.35 return 0;
1.36 }
1.37 @@ -92,13 +85,13 @@
1.38 int offset, int blocksize, char *buf,
1.39 void *priv_data)
1.40 {
1.41 - struct _image_parent_entry_state *state = (struct _image_parent_entry_state *) priv_data;
1.42 + int *nonempty = (int *) priv_data;
1.43
1.44 (void) offset; (void) blocksize; (void) buf;
1.45
1.46 if (strcmp(dir_entry->name, ".") && strcmp(dir_entry->name, ".."))
1.47 {
1.48 - state->nonempty = 1;
1.49 + *nonempty = 1;
1.50 return DIRENT_ABORT;
1.51 }
1.52
1.53 @@ -111,13 +104,13 @@
1.54 int offset, int blocksize, char *buf,
1.55 void *priv_data)
1.56 {
1.57 - struct _image_parent_entry_state *state = (struct _image_parent_entry_state *) priv_data;
1.58 + ext2_ino_t *ino = (ext2_ino_t *) priv_data;
1.59
1.60 (void) offset; (void) blocksize; (void) buf;
1.61
1.62 if (!strcmp(dir_entry->name, ".."))
1.63 {
1.64 - dir_entry->inode = state->ino;
1.65 + dir_entry->inode = *ino;
1.66 return DIRENT_CHANGED | DIRENT_ABORT;
1.67 }
1.68 else
1.69 @@ -178,16 +171,16 @@
1.70 {
1.71 /* Initialise the directory listing processing state. */
1.72
1.73 - struct _image_parent_entry_state state = {.nonempty = 0};
1.74 + int nonempty = 0;
1.75 errcode_t retval = ext2fs_dir_iterate(fs, ino, 0, NULL,
1.76 - _image_test_directory, &state);
1.77 + _image_test_directory, &nonempty);
1.78
1.79 if (retval)
1.80 return retval;
1.81
1.82 /* NOTE: Need a proper error here. */
1.83
1.84 - return state.nonempty;
1.85 + return nonempty;
1.86 }
1.87
1.88 /* Test for an empty directory using its path. */
1.89 @@ -204,18 +197,13 @@
1.90 {
1.91 /* Initialise the directory listing processing state. */
1.92
1.93 - struct _image_parent_entry_state state = {.ino = 0};
1.94 -
1.95 - /* A directory needs to be inspected for files and for the .. entry
1.96 - to be queried to obtain the parent directory. */
1.97 + *ino_parent = 0;
1.98
1.99 - errcode_t retval = ext2fs_dir_iterate(fs, ino, 0, NULL,
1.100 - _image_get_parent_entry, &state);
1.101 + /* A directory needs to be inspected for the .. entry in order to obtain the
1.102 + parent directory. */
1.103
1.104 - if (!retval)
1.105 - *ino_parent = state.ino;
1.106 -
1.107 - return retval;
1.108 + return ext2fs_dir_iterate(fs, ino, 0, NULL, _image_get_parent_entry,
1.109 + ino_parent);
1.110 }
1.111
1.112 /* Return the appropriate ext2 file type value for the given mode value. */
1.113 @@ -571,11 +559,6 @@
1.114 errcode_t retval;
1.115 struct ext2_inode source_inode, source_parent_inode, target_parent_inode;
1.116
1.117 - /* Initialise the directory listing processing state to refer to the target
1.118 - parent. */
1.119 -
1.120 - struct _image_parent_entry_state state = {.ino = target_parent};
1.121 -
1.122 /* NOTE: Should check for space. */
1.123
1.124 /* Obtain the source object. */
1.125 @@ -613,7 +596,7 @@
1.126 parent. */
1.127
1.128 retval = ext2fs_dir_iterate(fs, source, 0, NULL,
1.129 - _image_update_parent_entry, &state);
1.130 + _image_update_parent_entry, &target_parent);
1.131
1.132 /* Update the link count for the source. */
1.133