summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-11-01 21:46:50 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-11-01 21:46:50 -0400
commit8c3b9aaaab11be9d0fe24a72ebb16e171ca22125 (patch)
tree1eceebe2763cec5a010a193d48b50edef5fb78a2
parentb74261ac825ec2b9c02d73e36f7b44b64c9d184c (diff)
downloadbfs-8c3b9aaaab11be9d0fe24a72ebb16e171ca22125.tar.xz
Print device major/minor numbers for -ls
-rw-r--r--eval.c14
-rw-r--r--stat.c9
-rw-r--r--stat.h11
-rw-r--r--util.c16
-rw-r--r--util.h15
5 files changed, 56 insertions, 9 deletions
diff --git a/eval.c b/eval.c
index 15dddf4..b3d85f2 100644
--- a/eval.c
+++ b/eval.c
@@ -658,9 +658,17 @@ bool eval_fls(const struct expr *expr, struct eval_state *state) {
}
}
- uintmax_t size = statbuf->size;
- if (fprintf(file, " %8ju", size) < 0) {
- goto error;
+ if (ftwbuf->typeflag & (BFTW_BLK | BFTW_CHR)) {
+ int ma = bfs_major(statbuf->rdev);
+ int mi = bfs_minor(statbuf->rdev);
+ if (fprintf(file, " %3d, %3d", ma, mi) < 0) {
+ goto error;
+ }
+ } else {
+ uintmax_t size = statbuf->size;
+ if (fprintf(file, " %8ju", size) < 0) {
+ goto error;
+ }
}
time_t time = statbuf->mtime.tv_sec;
diff --git a/stat.c b/stat.c
index 2e046d6..b8f1704 100644
--- a/stat.c
+++ b/stat.c
@@ -32,7 +32,6 @@
#if HAVE_STATX || defined(__NR_statx)
# define HAVE_BFS_STATX true
-# include <sys/sysmacros.h>
#endif
#if __APPLE__
@@ -82,6 +81,9 @@ static void bfs_stat_convert(const struct stat *statbuf, struct bfs_stat *buf) {
buf->blocks = statbuf->st_blocks;
buf->mask |= BFS_STAT_BLOCKS;
+ buf->rdev = statbuf->st_rdev;
+ buf->mask |= BFS_STAT_RDEV;
+
buf->atime = statbuf->st_atim;
buf->mask |= BFS_STAT_ATIME;
@@ -154,7 +156,7 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, enum bfs
buf->mask = 0;
- buf->dev = makedev(xbuf.stx_dev_major, xbuf.stx_dev_minor);
+ buf->dev = bfs_makedev(xbuf.stx_dev_major, xbuf.stx_dev_minor);
buf->mask |= BFS_STAT_DEV;
if (xbuf.stx_mask & STATX_INO) {
@@ -195,6 +197,9 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, enum bfs
buf->mask |= BFS_STAT_BLOCKS;
}
+ buf->rdev = bfs_makedev(xbuf.stx_rdev_major, xbuf.stx_rdev_minor);
+ buf->mask |= BFS_STAT_RDEV;
+
if (xbuf.stx_mask & STATX_ATIME) {
buf->atime.tv_sec = xbuf.stx_atime.tv_sec;
buf->atime.tv_nsec = xbuf.stx_atime.tv_nsec;
diff --git a/stat.h b/stat.h
index 95c61ec..2519ff3 100644
--- a/stat.h
+++ b/stat.h
@@ -35,10 +35,11 @@ enum bfs_stat_field {
BFS_STAT_UID = 1 << 6,
BFS_STAT_SIZE = 1 << 7,
BFS_STAT_BLOCKS = 1 << 8,
- BFS_STAT_ATIME = 1 << 9,
- BFS_STAT_BTIME = 1 << 10,
- BFS_STAT_CTIME = 1 << 11,
- BFS_STAT_MTIME = 1 << 12,
+ BFS_STAT_RDEV = 1 << 9,
+ BFS_STAT_ATIME = 1 << 10,
+ BFS_STAT_BTIME = 1 << 11,
+ BFS_STAT_CTIME = 1 << 12,
+ BFS_STAT_MTIME = 1 << 13,
};
/**
@@ -80,6 +81,8 @@ struct bfs_stat {
off_t size;
/** Number of disk blocks allocated (of size BFS_STAT_BLKSIZE). */
blkcnt_t blocks;
+ /** The device ID represented by this file. */
+ dev_t rdev;
/** Access time. */
struct timespec atime;
diff --git a/util.c b/util.c
index 9730a5e..64785be 100644
--- a/util.c
+++ b/util.c
@@ -30,6 +30,10 @@
#include <sys/types.h>
#include <unistd.h>
+#if __GLIBC__ || __has_include(<sys/sysmacros.h>)
+# include <sys/sysmacros.h>
+#endif
+
int xreaddir(DIR *dir, struct dirent **de) {
errno = 0;
*de = readdir(dir);
@@ -440,3 +444,15 @@ int ynprompt() {
dstrfree(line);
return ret;
}
+
+dev_t bfs_makedev(int ma, int mi) {
+ return makedev(ma, mi);
+}
+
+int bfs_major(dev_t dev) {
+ return major(dev);
+}
+
+int bfs_minor(dev_t dev) {
+ return minor(dev);
+}
diff --git a/util.h b/util.h
index f0512f7..18fc318 100644
--- a/util.h
+++ b/util.h
@@ -172,4 +172,19 @@ enum bftw_typeflag dirent_to_typeflag(const struct dirent *de);
*/
int ynprompt(void);
+/**
+ * Portable version of makedev().
+ */
+dev_t bfs_makedev(int ma, int mi);
+
+/**
+ * Portable version of major().
+ */
+int bfs_major(dev_t dev);
+
+/**
+ * Portable version of minor().
+ */
+int bfs_minor(dev_t dev);
+
#endif // BFS_UTIL_H