]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/initscripts/init.d/functions
ramdisk: Avoid copying data if no ramdisk is used
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / functions
index bd2c946e0de6ae62217e5a7235492e63fd81b4f9..fc4d8a4b9aff01f43884b60f55d169d3f93a5b98 100644 (file)
@@ -743,29 +743,45 @@ use_ramdisk() {
 }
 
 mount_ramdisk() {
 }
 
 mount_ramdisk() {
-       mount -t tmpfs none $1
-}
+       local path="${1}"
+       local path_tmpfs="${path}.tmpfs"
 
 
-umount_ramdisk() {
-       if mountpoint $1 &>/dev/null; then
-               umount $1
+       # Check if the ramdisk is already mounted
+       if mountpoint "${path}" &>/dev/null; then
+               return 0
        fi
        fi
-}
 
 
-backup_ramdisk() {
-       if [ ! -e $1.bak ]; then
-               mkdir -p $1.bak
-       fi
+       # Create ramdisk
+       mkdir -p "${path_tmpfs}"
+       mount -t tmpfs none "${path_tmpfs}"
+
+       # Restore ramdisk content
+       cp -pR "${path}/*" "${path_tmpfs}"
 
 
-       cp -pR $1/* $1.bak/
-       rm -rf $1/*
+       # Move ramdisk to final destination
+       mount --move "${path_tmpfs}" "${path}"
+       rm -f "${path_tmpfs}"
 }
 
 }
 
-restore_ramdisk() {
-       if [ -e $1.bak ];then
-               cp -pR $1.bak/* $1/
-               rm -rf $1.bak/*
+umount_ramdisk() {
+       local path="${1}"
+       local path_tmpfs="${path}.tmpfs"
+
+       # Check if a ramdisk is actually mounted
+       if ! mountpoint "${path}" &>/dev/null; then
+               return 0
        fi
        fi
+
+       # Move the ramdisk
+       mkdir -p "${path_tmpfs}"
+       mount --move "${path}" "${path_tmpfs}"
+
+       # Backup ramdisk content
+       cp -pR "${path_tmpfs}/*" "${path}"
+
+       # Destroy the ramdisk
+       umount "${path_tmpfs}"
+       rm -f "${path_tmpfs}"
 }
 
 # End $rc_base/init.d/functions
 }
 
 # End $rc_base/init.d/functions