[hackers] [sbase] Add -x support for du(1) || Quentin Rameau
commit c85f83e530572b35186def0fc98b9ddacd25e33a
Author: Quentin Rameau <quinq_AT_quinq.eu.org>
Date: Wed Feb 18 18:24:21 2015 +0100
Add -x support for du(1)
diff --git a/du.1 b/du.1
index bae293f..211d83f 100644
--- a/du.1
+++ b/du.1
_AT_@ -11,6 +11,7 @@
.Op Fl h
.Op Fl k
.Op Fl H | L | P
+.Op Fl x
.Op Ar file ...
.Sh DESCRIPTION
.Nm
_AT_@ -43,4 +44,6 @@ recursively traversing directories.
Always dereference symbolic links while recursively traversing directories.
.It Fl P
Don't dereference symbolic links. This is the default.
+.It Fl x
+Do not traverse file systems mount points.
.El
diff --git a/du.c b/du.c
index a71a6f9..1617801 100644
--- a/du.c
+++ b/du.c
_AT_@ -21,6 +21,7 @@ static int dflag = 0;
static int sflag = 0;
static int kflag = 0;
static int hflag = 0;
+static int xflag = 0;
static int HLPflag = 'P';
static char *
_AT_@ -72,19 +73,19 @@ static size_t
du(const char *path, char follow)
{
struct dirent *dent;
- struct stat st;
+ struct stat pst, st;
DIR *dp;
size_t n = 0, m, t;
int r;
char *cwd;
- if (lstat(path, &st) < 0)
+ if (lstat(path, &pst) < 0)
eprintf("stat: %s:", path);
- n = nblks(&st);
+ n = nblks(&pst);
- if (!(S_ISDIR(st.st_mode) ||
- (follow != 'P' && S_ISLNK(st.st_mode) &&
- stat(path, &st) == 0 && S_ISDIR(st.st_mode))))
+ if (!(S_ISDIR(pst.st_mode) ||
+ (follow != 'P' && S_ISLNK(pst.st_mode) &&
+ stat(path, &pst) == 0 && S_ISDIR(pst.st_mode))))
goto done;
follow = follow == 'H' ? 'P' : follow;
_AT_@ -102,6 +103,8 @@ du(const char *path, char follow)
continue;
if (lstat(dent->d_name, &st) < 0)
eprintf("stat: %s:", dent->d_name);
+ if (xflag && st.st_dev != pst.st_dev)
+ continue;
if (S_ISDIR(st.st_mode) ||
(follow != 'P' && S_ISLNK(st.st_mode) &&
stat(dent->d_name, &st) == 0 && S_ISDIR(st.st_mode))) {
_AT_@ -138,7 +141,7 @@ done:
static void
usage(void)
{
- eprintf("usage: %s [-a | -s] [-d depth] [-h] [-k] [-H | -L | -P] [file ...]\n", argv0);
+ eprintf("usage: %s [-a | -s] [-d depth] [-h] [-k] [-H | -L | -P] [-x] [file ...]\n", argv0);
}
int
_AT_@ -169,6 +172,9 @@ main(int argc, char *argv[])
case 'P':
HLPflag = ARGC();
break;
+ case 'x':
+ xflag = 1;
+ break;
default:
usage();
} ARGEND;
Received on Wed Feb 18 2015 - 21:44:42 CET
This archive was generated by hypermail 2.3.0
: Wed Feb 18 2015 - 21:48:09 CET