Skip to contentSkip to conversation

xfsprogs/io: add readdir command

PATCH In review Brian Foster 2 participants 2 messages Aug 9, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xfsprogs/io: add readdir command

readdir reads the directory entries from an open directory from the provided offset (or 0 if not specified). On completion, readdir prints summary information regarding the number of operations and bytes transferred. Options are available to specify the starting offset, length and verbose mode to dump directory entry information.

---

v3:
- dup() file->fd and add corresponding closedir() (mark).
- add readdir section to xfs_io manpage (mark).

v2:
- Convert from getdents to readdir.
- Use configure mechanism for libc readdir() availability (zab).
- Add extra dirent fields to verbose output (zab).

 configure.ac          |   1 +
 include/builddefs.in  |   1 +
 io/Makefile           |   5 ++
 io/init.c             |   1 +
 io/io.h               |   6 ++
 io/readdir.c          | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++
 m4/package_libcdev.m4 |  15 ++++
 man/man8/xfs_io.8     |  24 +++++-
 8 files changed, 251 insertions(+), 1 deletion(-)
 create mode 100644 io/readdir.c
configure.ac +1 -0
index e5fd94e..da099d8 100644
@@ -112,6 +112,7 @@ AC_HAVE_FIEMAP
 AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_BLKID_TOPO($enable_blkid)
+AC_HAVE_READDIR
 
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([char *])
include/builddefs.in +1 -0
index 744e8d3..944bcf6 100644
@@ -103,6 +103,7 @@ HAVE_FALLOCATE = @have_fallocate@
 HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
+HAVE_READDIR = @have_readdir@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
io/Makefile +5 -0
index 50edf91..d73f9b9 100644
@@ -80,6 +80,11 @@ ifeq ($(HAVE_PREADV),yes)
 LCFLAGS += -DHAVE_PREADV -DHAVE_PWRITEV
 endif
 
+ifeq ($(HAVE_READDIR),yes)
+CFILES += readdir.c
+LCFLAGS += -DHAVE_READDIR
+endif
+
 default: depend $(LTCOMMAND)
 
 include $(BUILDRULES)
io/init.c +1 -0
index ca3055a..ee99761 100644
@@ -74,6 +74,7 @@ init_commands(void)
 	fiemap_init();
 	pwrite_init();
 	quit_init();
+	readdir_init();
 	resblks_init();
 	sendfile_init();
 	shutdown_init();
io/io.h +6 -0
index 91f0e3e..e1f5328 100644
@@ -149,3 +149,9 @@ extern void		sync_range_init(void);
 #else
 #define sync_range_init()	do { } while (0)
 #endif
+
+#ifdef HAVE_READDIR
+extern void		readdir_init(void);
+#else
+#define readdir_init()		do { } while (0)
+#endif
io/readdir.c new file +199 -0

199 lines not on this page · raw message

m4/package_libcdev.m4 +15 -0
index f489f52..8267ba0 100644
@@ -170,3 +170,18 @@ AC_DEFUN([AC_HAVE_SYNC_FILE_RANGE],
     AC_SUBST(have_sync_file_range)
   ])
 
+#
+# Check if we have a readdir libc call
+#
+AC_DEFUN([AC_HAVE_READDIR],
+  [ AC_MSG_CHECKING([for readdir])
+    AC_TRY_LINK([
+#include <dirent.h>
+    ], [
+         readdir(0);
+    ], have_readdir=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_readdir)
+  ])
+
man/man8/xfs_io.8 +23 -1
index 5e3535b..ee7ef4e 100644
@@ -397,6 +397,27 @@ must be specified as another open file
 .RB ( \-f )
 or by path
 .RB ( \-i ).
+.TP
+.BI "readdir [ -v ] [ -o " offset " ] [ -l " length " ] "
+Read a range of directory entries from a given offset of a directory.
+.RS 1.0i
+.PD 0
+.TP 0.4i
+.B \-v
+verbose mode - dump dirent content as defined in
+.BR readdir (3)
+.TP
+.B \-o
+specify starting
+.I offset
+.TP
+.B \-l
+specify total
+.I length
+to read (in bytes)
+.RE
+.PD
+.TP
 
 .SH MEMORY MAPPED I/O COMMANDS
 .TP
@@ -649,4 +670,5 @@ verbose output will be printed.
 .BR msync (2),
 .BR open (2),
 .BR pread (2),
-.BR pwrite (2).
+.BR pwrite (2),
+.BR readdir (3).
Signature · 6 lines
1.8.1.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v3 1/1
#1 lore raw
Quoted 10 lines · Brian Foster

readdir reads the directory entries from an open directory from the provided offset (or 0 if not specified). On completion, readdir prints summary information regarding the number of operations and bytes transferred. Options are available to specify the starting offset, length and verbose mode to dump directory entry information.

---

Quoted 8 lines

v3:
- dup() file->fd and add corresponding closedir() (mark).
- add readdir section to xfs_io manpage (mark).

v2:
- Convert from getdents to readdir.
- Use configure mechanism for libc readdir() availability (zab).
- Add extra dirent fields to verbose output (zab).

Thank-you, looks great. We can get it in right away.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs