bin/50988: [Patch] find -size -- express argument in kilo, mega...
bytes
Matthew Seaman
m.seaman at infracaninophile.co.uk
Tue Apr 15 07:30:03 PDT 2003
>Number: 50988
>Category: bin
>Synopsis: [Patch] find -size -- express argument in kilo, mega... bytes
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Apr 15 07:30:01 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Matthew Seaman
>Release: FreeBSD 4.8-STABLE i386
>Organization:
Infracaninophile
>Environment:
System: FreeBSD happy-idiot-talk.infracaninophile.co.uk 4.8-STABLE FreeBSD 4.8-STABLE #3: Sat Apr 12 09:42:52 BST 2003 root at happy-idiot-talk.infracaninophile.co.uk:/usr/obj/usr/src/sys/HAPPY-IDIOT-TALK i386
>Description:
find(1)'s -size primary accepts an argument either as a multiple of
512 blocks or a the number of characters (bytes) in a file. This
patch add the capability for a trailing scale indicator to cause the
specified size to be read in the more familiar units of kilobytes,
megabytes etc. Eg. to find files more than 23Mb in size:
find / -size +23M
>How-To-Repeat:
>Fix:
--- function.c.diff begins here ---
--- function.c.orig Tue Apr 15 14:03:08 2003
+++ function.c Tue Apr 15 14:33:08 2003
@@ -130,7 +130,7 @@
value = strtoq(str, &endchar, 10);
if (value == 0 && endchar == str)
errx(1, "%s: %s: illegal numeric value", option, vp);
- if (endchar[0] && (endch == NULL || endchar[0] != *endch))
+ if (endchar[0] && endch == NULL)
errx(1, "%s: %s: illegal trailing character", option, vp);
if (endch)
*endch = endchar[0];
@@ -1280,7 +1280,8 @@
*
* True if the file size in bytes, divided by an implementation defined
* value and rounded up to the next integer, is n. If n is followed by
- * a c, the size is in bytes.
+ * one of c k M G T P, the size is in bytes, kilobytes, megabytes,
+ * gigabytes, terabytes or petabytes respectively.
*/
#define FIND_SIZE 512
static int divsize = 1;
@@ -1305,15 +1306,46 @@
char *size_str;
PLAN *new;
char endch;
-
+ off_t scale;
+
size_str = nextarg(option, argvp);
ftsoptions &= ~FTS_NOSTAT;
new = palloc(option);
endch = 'c';
new->o_data = find_parsenum(new, option->name, size_str, &endch);
- if (endch == 'c')
+ if (endch != '\0') {
divsize = 0;
+
+ switch (endch) {
+ case 'c': /* characters */
+ scale = 0x1LL;
+ break;
+ case 'k': /* kilobytes 1<<10 */
+ scale = 0x400LL;
+ break;
+ case 'M': /* megabytes 1<<20 */
+ scale = 0x100000LL;
+ break;
+ case 'G': /* gigabytes 1<<30 */
+ scale = 0x4000000LL;
+ break;
+ case 'T': /* terabytes 1<<40 */
+ scale = 0x1000000000LL;
+ break;
+ case 'P': /* petabytes 1<<50 */
+ scale = 0x40000000000LL;
+ break;
+ default:
+ errx(1, "%s: %s: illegal trailing character",
+ option->name, size_str);
+ break;
+ }
+ if (new->o_data > QUAD_MAX / scale)
+ errx(1, "%s: %s: value too large",
+ option->name, size_str);
+ new->o_data *= scale;
+ }
return new;
}
--- function.c.diff ends here ---
--- find.1.diff begins here ---
--- find.1.orig Tue Apr 15 14:40:26 2003
+++ find.1 Tue Apr 15 15:04:17 2003
@@ -595,7 +595,7 @@
.Dq Li xyzzy
or
.Dq Li /foo/ .
-.It Ic -size Ar n Ns Op Cm c
+.It Ic -size Ar n Ns Op Cm ckMGTP
True if the file's size, rounded up, in 512\-byte blocks is
.Ar n .
If
@@ -606,6 +606,25 @@
file's size is
.Ar n
bytes (characters).
+Similarly if
+.Ar n
+is followed by a scale indicator then the file's size is compared to
+.Ar n
+scaled as:
+.Pp
+.Bl -tag -width indent -compact
+.It Cm k
+kilobytes (1024 bytes)
+.It Cm M
+megabytes (1024 kilobytes)
+.It Cm G
+gigabytes (1024 megabytes)
+.It Cm T
+terabytes (1024 gigabytes)
+.It Cm P
+petabytes (1024 terabytes)
+.El
+.Pp
.It Ic -type Ar t
True if the file is of the specified type.
Possible file types are as follows:
--- find.1.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list