|
Lines 57-95
Link Here
|
| 57 |
#include <errno.h> |
57 |
#include <errno.h> |
| 58 |
#include <fnmatch.h> |
58 |
#include <fnmatch.h> |
| 59 |
#include <fts.h> |
59 |
#include <fts.h> |
| 60 |
#include <math.h> |
|
|
| 61 |
#include <stdio.h> |
60 |
#include <stdio.h> |
| 62 |
#include <stdlib.h> |
61 |
#include <stdlib.h> |
| 63 |
#include <string.h> |
62 |
#include <string.h> |
| 64 |
#include <sysexits.h> |
63 |
#include <sysexits.h> |
| 65 |
#include <unistd.h> |
64 |
#include <unistd.h> |
| 66 |
|
65 |
|
| 67 |
#define KILO_SZ(n) (n) |
|
|
| 68 |
#define MEGA_SZ(n) ((n) * (n)) |
| 69 |
#define GIGA_SZ(n) ((n) * (n) * (n)) |
| 70 |
#define TERA_SZ(n) ((n) * (n) * (n) * (n)) |
| 71 |
#define PETA_SZ(n) ((n) * (n) * (n) * (n) * (n)) |
| 72 |
|
| 73 |
#define KILO_2_SZ (KILO_SZ(1024ULL)) |
| 74 |
#define MEGA_2_SZ (MEGA_SZ(1024ULL)) |
| 75 |
#define GIGA_2_SZ (GIGA_SZ(1024ULL)) |
| 76 |
#define TERA_2_SZ (TERA_SZ(1024ULL)) |
| 77 |
#define PETA_2_SZ (PETA_SZ(1024ULL)) |
| 78 |
|
| 79 |
#define KILO_SI_SZ (KILO_SZ(1000ULL)) |
| 80 |
#define MEGA_SI_SZ (MEGA_SZ(1000ULL)) |
| 81 |
#define GIGA_SI_SZ (GIGA_SZ(1000ULL)) |
| 82 |
#define TERA_SI_SZ (TERA_SZ(1000ULL)) |
| 83 |
#define PETA_SI_SZ (PETA_SZ(1000ULL)) |
| 84 |
|
| 85 |
unsigned long long vals_si [] = {1, KILO_SI_SZ, MEGA_SI_SZ, GIGA_SI_SZ, TERA_SI_SZ, PETA_SI_SZ}; |
| 86 |
unsigned long long vals_base2[] = {1, KILO_2_SZ, MEGA_2_SZ, GIGA_2_SZ, TERA_2_SZ, PETA_2_SZ}; |
| 87 |
unsigned long long *valp; |
| 88 |
|
| 89 |
typedef enum { NONE, KILO, MEGA, GIGA, TERA, PETA, UNIT_MAX } unit_t; |
| 90 |
|
| 91 |
int unitp [] = { NONE, KILO, MEGA, GIGA, TERA, PETA }; |
| 92 |
|
| 93 |
SLIST_HEAD(ignhead, ignentry) ignores; |
66 |
SLIST_HEAD(ignhead, ignentry) ignores; |
| 94 |
struct ignentry { |
67 |
struct ignentry { |
| 95 |
char *mask; |
68 |
char *mask; |
|
Lines 98-105
Link Here
|
| 98 |
|
71 |
|
| 99 |
int linkchk __P((FTSENT *)); |
72 |
int linkchk __P((FTSENT *)); |
| 100 |
static void usage __P((void)); |
73 |
static void usage __P((void)); |
| 101 |
void prthumanval __P((double)); |
74 |
void prthumanval __P((u_int64_t)); |
| 102 |
unit_t unit_adjust __P((double *)); |
|
|
| 103 |
void ignoreadd __P((const char *)); |
75 |
void ignoreadd __P((const char *)); |
| 104 |
void ignoreclean __P((void)); |
76 |
void ignoreclean __P((void)); |
| 105 |
int ignorep __P((FTSENT *)); |
77 |
int ignorep __P((FTSENT *)); |
|
Lines 165-171
Link Here
|
| 165 |
case 'h': |
137 |
case 'h': |
| 166 |
putenv("BLOCKSIZE=512"); |
138 |
putenv("BLOCKSIZE=512"); |
| 167 |
hflag = 1; |
139 |
hflag = 1; |
| 168 |
valp = vals_base2; |
|
|
| 169 |
break; |
140 |
break; |
| 170 |
case 'k': |
141 |
case 'k': |
| 171 |
if (!hflag) |
142 |
if (!hflag) |
|
Lines 349-391
Link Here
|
| 349 |
* especially on huge disks. |
320 |
* especially on huge disks. |
| 350 |
* |
321 |
* |
| 351 |
*/ |
322 |
*/ |
| 352 |
unit_t |
|
|
| 353 |
unit_adjust(val) |
| 354 |
double *val; |
| 355 |
{ |
| 356 |
double abval; |
| 357 |
unit_t unit; |
| 358 |
unsigned int unit_sz; |
| 359 |
|
| 360 |
abval = fabs(*val); |
| 361 |
|
| 362 |
unit_sz = abval ? ilogb(abval) / 10 : 0; |
| 363 |
|
| 364 |
if (unit_sz >= UNIT_MAX) { |
| 365 |
unit = NONE; |
| 366 |
} else { |
| 367 |
unit = unitp[unit_sz]; |
| 368 |
*val /= (double)valp[unit_sz]; |
| 369 |
} |
| 370 |
|
| 371 |
return (unit); |
| 372 |
} |
| 373 |
|
| 374 |
void |
323 |
void |
| 375 |
prthumanval(bytes) |
324 |
prthumanval(bytes) |
| 376 |
double bytes; |
325 |
u_int64_t bytes; |
| 377 |
{ |
326 |
{ |
| 378 |
unit_t unit; |
327 |
static const char prefixes[] = "BkMGTPE"; |
|
|
328 |
|
| 329 |
int i; |
| 330 |
u_int64_t s1, s2; |
| 379 |
|
331 |
|
| 380 |
bytes *= 512; |
332 |
bytes *= 51200; |
| 381 |
unit = unit_adjust(&bytes); |
|
|
| 382 |
|
333 |
|
| 383 |
if (bytes == 0) |
334 |
for (i = 0; bytes >= 100000 && i < sizeof(prefixes); i++) |
| 384 |
(void)printf(" 0B"); |
335 |
bytes /= 1024; |
| 385 |
else if (bytes > 10) |
336 |
|
| 386 |
(void)printf("%3.0f%c", bytes, "BKMGTPE"[unit]); |
337 |
if (bytes < 1000 ) { |
| 387 |
else |
338 |
s1 = bytes / 100; |
| 388 |
(void)printf("%3.1f%c", bytes, "BKMGTPE"[unit]); |
339 |
if (( s2 = (( (bytes % 100 ) + 5 ) / 10 ) ) == 10 ) { |
|
|
340 |
s1++; |
| 341 |
s2 = 0; |
| 342 |
} |
| 343 |
printf("%qd.%qd%c", s1, s2, prefixes[i]); |
| 344 |
} else |
| 345 |
printf("%3qd%c", (bytes + 50) / 100, prefixes[i]); |
| 389 |
} |
346 |
} |
| 390 |
|
347 |
|
| 391 |
static void |
348 |
static void |