aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-05-14 17:00:33 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-05-15 09:40:23 +0200
commit69cf28db0dfa175884c9c41fc3f329b051e0a9c5 (patch)
tree0e1fe1f0c2f7a5c85aa6a88f4d8c8cc5ea04804d
parent20a4e5acd78dcb5f681ab5320adb0289cebfc277 (diff)
libio: remove device number from dir_iterator_t, add flag field
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/io/dir_iterator.h24
-rw-r--r--lib/io/src/dir_tree_iterator.c3
-rw-r--r--lib/io/src/unix/dir_iterator.c8
3 files changed, 18 insertions, 17 deletions
diff --git a/include/io/dir_iterator.h b/include/io/dir_iterator.h
index b7212b3..0de135a 100644
--- a/include/io/dir_iterator.h
+++ b/include/io/dir_iterator.h
@@ -10,6 +10,12 @@
#include "sqfs/predef.h"
#include "io/istream.h"
+typedef enum {
+ DIR_ENTRY_FLAG_MOUNT_POINT = 0x0001,
+
+ DIR_ENTRY_FLAG_HARD_LINK = 0x0002,
+} DIR_ENTRY_FLAG;
+
/**
* @struct dir_entry_t
*
@@ -61,6 +67,11 @@ typedef struct {
sqfs_u16 mode;
/**
+ * @brief Combination of DIR_ENTRY_FLAG values
+ */
+ sqfs_u16 flags;
+
+ /**
* @brief Name of the entry
*
* On Unix-like OSes, the name is returned as-is. On systems like
@@ -78,19 +89,6 @@ typedef struct dir_iterator_t {
sqfs_object_t obj;
/**
- * @brief A device number for detecting mount points and hard links.
- *
- * On Unix-like systems this exposes the underlying device number
- * backing this directory. Each entry returned by the iterator also
- * has a device number and if it is different, you found a mount point.
- *
- * The device number, combined with inode number, are also needed to
- * detect hard links. Entries with same device and inode number point
- * to the same file.
- */
- sqfs_u64 dev;
-
- /**
* @brief Read the next entry and update internal state relating to it
*
* @param it A pointer to the iterator itself
diff --git a/lib/io/src/dir_tree_iterator.c b/lib/io/src/dir_tree_iterator.c
index 67d33c3..51d289a 100644
--- a/lib/io/src/dir_tree_iterator.c
+++ b/lib/io/src/dir_tree_iterator.c
@@ -59,7 +59,7 @@ static bool should_skip(const dir_tree_iterator_t *dir, const dir_entry_t *ent)
return true;
if ((dir->cfg.flags & DIR_SCAN_ONE_FILESYSTEM)) {
- if (ent->dev != ((const dir_iterator_t *)dir)->dev)
+ if (ent->flags & DIR_ENTRY_FLAG_MOUNT_POINT)
return true;
}
@@ -310,7 +310,6 @@ dir_iterator_t *dir_tree_iterator_create(const char *path,
}
sqfs_object_init(it, destroy, NULL);
- ((dir_iterator_t *)it)->dev = it->top->dir->dev;
((dir_iterator_t *)it)->next = next;
((dir_iterator_t *)it)->read_link = read_link;
((dir_iterator_t *)it)->open_subdir = open_subdir;
diff --git a/lib/io/src/unix/dir_iterator.c b/lib/io/src/unix/dir_iterator.c
index 8d30b3f..d6a7454 100644
--- a/lib/io/src/unix/dir_iterator.c
+++ b/lib/io/src/unix/dir_iterator.c
@@ -20,6 +20,7 @@ typedef struct {
struct dirent *ent;
struct stat sb;
+ dev_t device;
int state;
DIR *dir;
} unix_dir_iterator_t;
@@ -117,6 +118,9 @@ static int dir_next(dir_iterator_t *base, dir_entry_t **out)
decoded->gid = it->sb.st_gid;
decoded->mode = it->sb.st_mode;
+ if (decoded->dev != it->device)
+ decoded->flags |= DIR_ENTRY_FLAG_MOUNT_POINT;
+
*out = decoded;
return it->state;
}
@@ -168,7 +172,7 @@ static int dir_open_subdir(dir_iterator_t *base, dir_iterator_t **out)
}
sqfs_object_init(sub, dir_destroy, NULL);
- ((dir_iterator_t *)sub)->dev = sub->sb.st_dev;
+ sub->device = sub->sb.st_dev;
((dir_iterator_t *)sub)->next = dir_next;
((dir_iterator_t *)sub)->read_link = dir_read_link;
((dir_iterator_t *)sub)->open_subdir = dir_open_subdir;
@@ -209,7 +213,7 @@ dir_iterator_t *dir_iterator_create(const char *path)
}
sqfs_object_init(it, dir_destroy, NULL);
- ((dir_iterator_t *)it)->dev = it->sb.st_dev;
+ it->device = it->sb.st_dev;
((dir_iterator_t *)it)->next = dir_next;
((dir_iterator_t *)it)->read_link = dir_read_link;
((dir_iterator_t *)it)->open_subdir = dir_open_subdir;