File: diskcache

package info (click to toggle)
hibernate 2.0%2B15%2Bg88d54a8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 740 kB
  • ctags: 114
  • sloc: sh: 1,223; makefile: 17
file content (45 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet

AddConfigHandler DiskCacheOptions
AddConfigHelp "DisableWriteCacheOn <drive> [...]" "On some hardware the power is cut off before the disk has flushed its own hardware cache. List the devices that contain swap partitions (eg, /dev/hda) to disable the write cache before suspending."

DiskCacheDisable() {
    local i
    for i in $DISKCACHE_DISABLEDON ; do
	if ! which hdparm > /dev/null ; then
	    vecho 0 "hdparm utility is not in PATH! Is it installed? Can not disable write cache."
	    return 1
	fi
	vecho 1 "$EXE: Disabling disk cache on $i"
	hdparm -W 0 $i > /dev/null 2>&1
    done
    return 0
}

DiskCacheEnable() {
    local i
    for i in $DISKCACHE_DISABLEDON ; do
	command -v hdparm > /dev/null || return 1
	vecho 1 "$EXE: Enabling disk cache on $i"
	hdparm -W 1 $i > /dev/null 2>&1
    done
    return 0
}

DiskCacheOptions() {
    case $1 in
	disablewritecacheon)
	    if [ -z "$DISKCACHE_DISABLEDON" ] ; then
		AddSuspendHook 93 DiskCacheDisable
		AddResumeHook 93 DiskCacheEnable
	    fi
	    DISKCACHE_DISABLEDON="$DISKCACHE_DISABLEDON $2"
	    ;;
	*)
	    return 1
    esac
    return 0
}

# $Id$