summaryrefslogtreecommitdiff
path: root/tmpfs/tmpfs.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-03-24 03:17:24 +0000
committerRoland McGrath <roland@gnu.org>2002-03-24 03:17:24 +0000
commit3460505239e0af2470813bb5ea711a01290b9667 (patch)
treed958d1b5fbd9bd6ecf3e93204d113306956cd30d /tmpfs/tmpfs.c
parent59c44966394a8d4bb814dc830b390aaf9287bdf5 (diff)
2002-03-23 Roland McGrath <roland@frob.com>
* tmpfs.c (parse_opt): Grok % suffix on number to mean percentage of the machine's RAM.
Diffstat (limited to 'tmpfs/tmpfs.c')
-rw-r--r--tmpfs/tmpfs.c19
1 files changed, 19 insertions, 0 deletions
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)