From 3460505239e0af2470813bb5ea711a01290b9667 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sun, 24 Mar 2002 03:17:24 +0000 Subject: 2002-03-23 Roland McGrath * tmpfs.c (parse_opt): Grok % suffix on number to mean percentage of the machine's RAM. --- tmpfs/tmpfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tmpfs/tmpfs.c') diff --git a/tmpfs/tmpfs.c b/tmpfs/tmpfs.c index b691f718..f10b9803 100644 --- a/tmpfs/tmpfs.c +++ b/tmpfs/tmpfs.c @@ -186,6 +186,25 @@ parse_opt (int key, char *arg, struct argp_state *state) case 'K': size <<= 10; break; + case '%': + { + /* Set as a percentage of the machine's physical memory. */ + struct vm_statistics vmstats; + error_t err = vm_statistics (mach_task_self (), &vmstats); + if (err) + { + argp_error (state, "cannot find total physical memory: %s", + strerror (err)); + return err; + } + size = round_page ((((vmstats.free_count + + vmstats.active_count + + vmstats.inactive_count + + vmstats.wire_count) + * vm_page_size) + * size + 99) / 100); + break; + } } size = (off_t) size; if (size < 0) -- cgit v1.2.3