summaryrefslogtreecommitdiff
path: root/pm/power.d/journal-commit
blob: 5c0fc162f2e3338164729d8e176d6b37638b5c5a (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

. ${PM_FUNCTIONS}

JOURNAL_COMMIT_TIME_AC=${JOURNAL_COMMIT_TIME_AC:-0}
JOURNAL_COMMIT_TIME_BAT=${JOURNAL_COMMIT_TIME_BAT:-600}

help() {
    cat <<EOF
Journal commit time parameters:

JOURNAL_COMMIT_TIME_AC = number of seconds between journal commits on AC.
Defaults to 0, which sets the filesystem back to its default value.

JOURNAL_COMMIT_TIME_BAT = number of seconds between journal commits on battery.
Defaults to 600 (10 minutes).

We currently only handle EXT3 filesystems
EOF
}

# actually remount the file system
remount_fs()
{
	# $1 = filesystem to remount
	# $2 = mount option to change
	mount -o remount,$2 $1
}

# invoked on an ext3 file system
handle_ext3()
{
	# $1 = filesystem to remount
	# $2 = commit time
	remount_fs $1 "commit=${2}"
}

handle_ext4() { handle_ext3 "$@"; }

handle_filesystems()
{
	# $1 = new journal commit time in seconds
	while read DEV MOUNT FSTYPE REST; 
	do
		command_exists "handle_${FSTYPE}" || continue
		printf "Setting journal commit time for %s to %d..." \
		    "$MOUNT" "$1"
		"handle_${FSTYPE}" $MOUNT $1 && echo Done. || echo Failed.
	done < /proc/mounts
}

case $1 in
	true) handle_filesystems $JOURNAL_COMMIT_TIME_BAT ;;
	false) handle_filesystems $JOURNAL_COMMIT_TIME_AC ;;
        help) help;;
	*) exit $NA ;;
esac

exit 0