Subject: [PATCH 5/5] md_size can now contain more flexible definitions of size.

From: Rumko <[email-masked]>
Date: Sun, 18 Apr 2010 17:54:41 +0200

Pass whatever is inside md_size (e.g.: 10M) directly to mount_tmpfs unless if there is only a number inside md_size (without a suffix). In that case, multiply by 512 and pass that to mount_tmpfs since that number represents the size in number of sectors (backwards compatibility).
---
 etc/rc.d/diskless     |    6 +++---
 etc/rc.d/initdiskless |   10 +++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/etc/rc.d/diskless b/etc/rc.d/diskless
index d4cb867..ed9f8c5 100644
--- a/etc/rc.d/diskless
+++ b/etc/rc.d/diskless
@@ -46,7 +46,7 @@ name="diskless"
 #   $1 = size
 #   $2 = mount point
 mount_md() {
-	/sbin/mount_tmpfs -s `expr $1 '*' 512` tmpfs $2
+	/sbin/mount_tmpfs -s $1 tmpfs $2
 }
 
 # If there is a global system configuration file, suck it in.
@@ -71,7 +71,7 @@ if (/bin/mkdir /var/.diskless 2> /dev/null); then
         rmdir /var/.diskless
 else
 	echo "+++ mount_md of /var"
-	mount_md ${varsize:=32768} /var
+	mount_md ${varsize:=16M} /var
 fi
 
 if [ ! -d /var/db ]; then
@@ -117,7 +117,7 @@ else
 		echo "dropping into shell, ^D to continue anyway."
 		/bin/sh
 	else
-		mount_md ${tmpsize:=20480} /tmp
+		mount_md ${tmpsize:=10M} /tmp
 		chmod 01777 /tmp
 	fi
 fi
diff --git a/etc/rc.d/initdiskless b/etc/rc.d/initdiskless
index cc8f8d7..3380683 100644
--- a/etc/rc.d/initdiskless
+++ b/etc/rc.d/initdiskless
@@ -105,7 +105,7 @@ chkerr() {
 # Create a generic memory disk
 #
 mount_md() {
-	/sbin/mount_tmpfs -s `expr $1 '*' 512` tmpfs $2
+	/sbin/mount_tmpfs -s $1 tmpfs $2
 }
 
 # Create the memory filesystem if it has not already been created
@@ -114,12 +114,16 @@ create_md() {
 	if [ "x`eval echo \\$md_created_$1`" = "x" ]; then
 		if [ "x`eval echo \\$md_size_$1`" = "x" ]; then
 			if [ "$1" = "etc" ]; then
-				md_size=20480
+				md_size=12M
 			else
-				md_size=4096
+				md_size=2M
 			fi
 		else
 			md_size=`eval echo \\$md_size_$1`
+			# for backwards compatibility ... if it's a number, then it's the number of desired sectors and not bytes!
+			if [ "$md_size" = "${md_size%%[!0-9]*}" ]; then
+				md_size=`expr $md_size '*' 512`
+			fi
 		fi
 		mount_md $md_size /$1
 		/bin/chmod 755 /$1
-- 
1.6.6.2