summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-08-27 21:10:07 +0200
committerYorhel <git@yorhel.nl>2012-08-27 21:10:07 +0200
commit21c056f51d7323de11c0a6abe94129ed64bc6891 (patch)
tree3c0dbe46fcfd5a47de41ff69d301a1e8ce507fe6 /src
parentcabb55290dd33131b62549c5499cc77e6edb0ccf (diff)
Use uint64_t instead of dev_t as well + added comment explaining this
Diffstat (limited to 'src')
-rw-r--r--src/dir_scan.c8
-rw-r--r--src/global.h20
2 files changed, 15 insertions, 13 deletions
diff --git a/src/dir_scan.c b/src/dir_scan.c
index 4b07ed5..a0efcb3 100644
--- a/src/dir_scan.c
+++ b/src/dir_scan.c
@@ -43,14 +43,14 @@
int dir_scan_smfs; /* Stay on the same filesystem */
-static dev_t curdev; /* current device we're scanning on */
+static uint64_t curdev; /* current device we're scanning on */
/* Populates the struct dir item with information from the stat struct. Sets
* everything necessary for output_dir.item() except FF_ERR and FF_EXL. */
static void stat_to_dir(struct dir *d, struct stat *fs) {
d->ino = (uint64_t)fs->st_ino;
- d->dev = fs->st_dev;
+ d->dev = (uint64_t)fs->st_dev;
if(S_ISREG(fs->st_mode))
d->flags |= FF_FILE;
@@ -60,7 +60,7 @@ static void stat_to_dir(struct dir *d, struct stat *fs) {
if(!S_ISDIR(fs->st_mode) && fs->st_nlink > 1)
d->flags |= FF_HLNKC;
- if(dir_scan_smfs && curdev != fs->st_dev)
+ if(dir_scan_smfs && curdev != d->dev)
d->flags |= FF_OTHFS;
if(!(d->flags & (FF_OTHFS|FF_EXL))) {
@@ -254,7 +254,7 @@ int dir_scan_process() {
}
if(!dir_fatalerr) {
- curdev = fs.st_dev;
+ curdev = (uint64_t)fs.st_dev;
d = dir_createstruct(dir_curpath);
if(fail)
d->flags |= FF_ERR;
diff --git a/src/global.h b/src/global.h
index 7737204..edebb83 100644
--- a/src/global.h
+++ b/src/global.h
@@ -55,25 +55,27 @@
#define ST_HELP 3
-/* structure representing a file or directory
- * XXX: probably a good idea to get rid of the custom _t types and use
- * fixed-size integers instead, which are much more predictable */
+/* structure representing a file or directory */
struct dir {
struct dir *parent, *next, *prev, *sub, *hlnk;
int64_t size, asize;
- uint64_t ino;
+ uint64_t ino, dev;
int items;
- dev_t dev;
unsigned char flags;
char name[3]; /* must be large enough to hold ".." */
};
/* sizeof(total dir) = SDIRSIZE + strlen(name) = sizeof(struct dir) - 3 + strlen(name) + 1 */
#define SDIRSIZE (sizeof(struct dir)-2)
-/* Ideally, the name array should be as large as the padding added to the end of
- * the struct, but I can't figure out a portable way to calculate this. We can
- * be sure that it's at least 3 bytes, though, as the struct is aligned to at
- * least 4 bytes and the flags field is a single byte. */
+/* A note on the ino and dev fields above: ino is usually represented as ino_t,
+ * which POSIX specifies to be an unsigned integer. dev is usually represented
+ * as dev_t, which may be either a signed or unsigned integer, and in practice
+ * both are used. dev represents an index / identifier of a device or
+ * filesystem, and I'm unsure whether a negative value has any meaning in that
+ * context. Hence my choice of using an unsigned integer. Negative values, if
+ * we encounter them, will just get typecasted into a positive value. No
+ * information is lost in this conversion, and the semantics remain the same.
+ */
/* program state */