From 079709dc3a35b68657435a35bdf78b2793691932 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sat, 13 Sep 1997 11:41:50 +0000 Subject: [PATCH] Some tweaks to get this to cope with ELF where the address space starts higher up in memory (0x0800000 upwards) rather than near zero (0x1000 for our qmagic a.out format). The method that mount_mfs uses to allocate the memory within data size rlimits for the ram disk is entirely too much of a kludge for my liking. I mean, if it's run as root, surely it makes sense to just raise the resource limits to infinity or something, and if it's a non-root user mount (do these work? with mfs?) it could just fail if it's outside limits. --- sbin/newfs/mkfs.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index c95183a3d260..6531437a6c06 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -208,9 +208,9 @@ mkfs(pp, fsys, fi, fo) #ifndef STANDALONE get_memleft(); #endif - if (fssize * sectorsize > (memleft - 16384)) - fssize = (memleft - 16384) / sectorsize; - if ((membase = malloc(fssize * sectorsize)) == 0) { + if (fssize * sectorsize > (memleft - 131072)) + fssize = (memleft - 131072) / sectorsize; + if ((membase = malloc(fssize * sectorsize)) == NULL) { perror("malloc"); exit(13); } @@ -1210,18 +1210,28 @@ raise_data_limit() perror("setrlimit"); } +#ifdef __ELF__ +extern char *_etext; +#define etext _etext +#else +extern char *etext; +#endif + get_memleft() { - char *base; - static u_long pgsz, i; + static u_long pgsz; struct rlimit rlp; + u_long freestart; + u_long dstart; + u_long memused; - base = sbrk(0); pgsz = getpagesize() - 1; - i = ((u_long)(base + pgsz) &~ pgsz); + dstart = ((u_long)&etext) &~ pgsz; + freestart = ((u_long)(sbrk(0) + pgsz) &~ pgsz); if (getrlimit(RLIMIT_DATA, &rlp) < 0) perror("getrlimit"); - memleft = rlp.rlim_cur - (u_long)base - i; + memused = freestart - dstart; + memleft = rlp.rlim_cur - memused; } #endif /* STANDALONE */