diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-11 22:25:34 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-11 22:25:34 +0000 |
commit | 98f5cdfca7401e4e159b73b1efa600ca58fb292d (patch) | |
tree | e81d04c59a25577430bb127166ce777804776b84 /coreutils/stat.c | |
parent | f3c2d1360222f54126e5b0322ae4f8c1853e4782 (diff) | |
download | busybox-w32-98f5cdfca7401e4e159b73b1efa600ca58fb292d.tar.gz busybox-w32-98f5cdfca7401e4e159b73b1efa600ca58fb292d.tar.bz2 busybox-w32-98f5cdfca7401e4e159b73b1efa600ca58fb292d.zip |
stat: make stat -f show filesystem "ID:" as coreutils does
print_statfs 358 370 +12
Diffstat (limited to 'coreutils/stat.c')
-rw-r--r-- | coreutils/stat.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c index c34c06acb..4c729e071 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -139,6 +139,20 @@ static void printfs(char *pformat, const char *msg) | |||
139 | printf(pformat, msg); | 139 | printf(pformat, msg); |
140 | } | 140 | } |
141 | 141 | ||
142 | /* "man statfs" says that statfsbuf->f_fsid is a mess */ | ||
143 | /* coreutils treats it as an array of ints, most significant first */ | ||
144 | static unsigned long long get_f_fsid(const struct statfs *statfsbuf) | ||
145 | { | ||
146 | const unsigned *p = (const void*) &statfsbuf->f_fsid; | ||
147 | unsigned sz = sizeof(statfsbuf->f_fsid) / sizeof(unsigned); | ||
148 | unsigned long long r = 0; | ||
149 | |||
150 | do | ||
151 | r = (r << (sizeof(unsigned)*8)) | *p++; | ||
152 | while (--sz > 0); | ||
153 | return r; | ||
154 | } | ||
155 | |||
142 | /* print statfs info */ | 156 | /* print statfs info */ |
143 | static void print_statfs(char *pformat, const char m, | 157 | static void print_statfs(char *pformat, const char m, |
144 | const char *const filename, const void *data | 158 | const char *const filename, const void *data |
@@ -148,11 +162,11 @@ static void print_statfs(char *pformat, const char m, | |||
148 | if (m == 'n') { | 162 | if (m == 'n') { |
149 | printfs(pformat, filename); | 163 | printfs(pformat, filename); |
150 | } else if (m == 'i') { | 164 | } else if (m == 'i') { |
151 | strcat(pformat, "Lx"); | 165 | strcat(pformat, "llx"); |
152 | printf(pformat, statfsbuf->f_fsid); | 166 | printf(pformat, get_f_fsid(statfsbuf)); |
153 | } else if (m == 'l') { | 167 | } else if (m == 'l') { |
154 | strcat(pformat, "lu"); | 168 | strcat(pformat, "lu"); |
155 | printf(pformat, statfsbuf->f_namelen); | 169 | printf(pformat, (unsigned long) (statfsbuf->f_namelen)); |
156 | } else if (m == 't') { | 170 | } else if (m == 't') { |
157 | strcat(pformat, "lx"); | 171 | strcat(pformat, "lx"); |
158 | printf(pformat, (unsigned long) (statfsbuf->f_type)); /* no equiv */ | 172 | printf(pformat, (unsigned long) (statfsbuf->f_type)); /* no equiv */ |
@@ -349,10 +363,11 @@ static void print_it(const char *masterformat, const char *filename, | |||
349 | #endif | 363 | #endif |
350 | static bool do_statfs(const char *filename, const char *format) | 364 | static bool do_statfs(const char *filename, const char *format) |
351 | { | 365 | { |
366 | struct statfs statfsbuf; | ||
367 | |||
352 | #if !ENABLE_FEATURE_STAT_FORMAT | 368 | #if !ENABLE_FEATURE_STAT_FORMAT |
353 | const char *format; | 369 | const char *format; |
354 | #endif | 370 | #endif |
355 | struct statfs statfsbuf; | ||
356 | #if ENABLE_SELINUX | 371 | #if ENABLE_SELINUX |
357 | security_context_t scontext = NULL; | 372 | security_context_t scontext = NULL; |
358 | 373 | ||
@@ -406,10 +421,10 @@ static bool do_statfs(const char *filename, const char *format) | |||
406 | format = (option_mask32 & OPT_TERSE | 421 | format = (option_mask32 & OPT_TERSE |
407 | ? "%s %llx %lu " | 422 | ? "%s %llx %lu " |
408 | : " File: \"%s\"\n" | 423 | : " File: \"%s\"\n" |
409 | " ID: %-8Lx Namelen: %-7lu "); | 424 | " ID: %-8llx Namelen: %-7lu "); |
410 | printf(format, | 425 | printf(format, |
411 | filename, | 426 | filename, |
412 | statfsbuf.f_fsid, | 427 | get_f_fsid(&statfsbuf), |
413 | statfsbuf.f_namelen); | 428 | statfsbuf.f_namelen); |
414 | 429 | ||
415 | if (option_mask32 & OPT_TERSE) | 430 | if (option_mask32 & OPT_TERSE) |