~ubuntu-branches/ubuntu/natty/sysvinit/natty-proposed

« back to all changes in this revision

Viewing changes to debian/initscripts/lib/init/mount-functions.sh

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2009-09-15 02:45:59 UTC
  • Revision ID: james.westby@ubuntu.com-20090915024559-2bv3ihsb0cu9xw2c
Tags: 2.87dsf-4ubuntu3
FFE LP: #427356.

* Various initscripts have been replaced by Upstart jobs shipped in
  other packages, the following have been removed:
  - hostname.sh
  - mountkernfs.sh
  - mountdevsubfs.sh
  - checkroot.sh
  - mtab.sh
  - checkfs.sh
  - mountall.sh
  - mountall-bootclean.sh
  - mountoverflowtmp
  - mountnfs.sh
  - mountnfs-bootclean.sh
  - bootmisc.sh
  - bootlogs
  - rmnlogin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Functions used by several mount* scripts in initscripts package
3
 
#
4
 
# Sourcer must set PATH and include /lib/init in it because
5
 
# domount() uses the custom readlink program
6
 
#
7
 
# Sourcer must also source /lib/lsb/init-functions.sh
8
 
 
9
 
# $1: directory
10
 
is_empty_dir() {
11
 
        for FILE in $1/* $1/.*
12
 
        do
13
 
                case "$FILE" in
14
 
                  "$1/.*") return 0 ;;
15
 
                  "$1/*"|"$1/."|"$1/..") continue ;;
16
 
                  *) return 1 ;;
17
 
                esac
18
 
        done
19
 
        return 0
20
 
}
21
 
 
22
 
 
23
 
selinux_enabled () {
24
 
        which selinuxenabled >/dev/null 2>&1 && selinuxenabled
25
 
}
26
 
 
27
 
 
28
 
# Called before mtab is writable to mount kernel and device file systems.
29
 
# $1: file system type
30
 
# $2: alternative file system type (or empty string if none)
31
 
# $3: mount point
32
 
# $4: mount device name
33
 
# $5... : extra mount program options
34
 
domount () {
35
 
        MTPT="$3"
36
 
        KERNEL="$(uname -s)"
37
 
        # Figure out filesystem type
38
 
        FSTYPE=
39
 
        if [ "$1" = proc ]
40
 
        then
41
 
                case "$KERNEL" in
42
 
                        Linux|GNU) FSTYPE=proc ;;
43
 
                        *FreeBSD)  FSTYPE=linprocfs ;;
44
 
                        *)         FSTYPE=procfs ;;
45
 
                esac
46
 
        elif [ "$1" = tmpfs ]
47
 
        then # always accept tmpfs, to mount /lib/init/rw before /proc
48
 
                FSTYPE=$1
49
 
        elif [ "$1" = spufs ]
50
 
        then # spufs is only relevant on Cell so may be compiled as a kernel module
51
 
                if grep -E -qs "spufs\$" /proc/filesystems || modprobe -q spufs
52
 
                then
53
 
                        FSTYPE=$1
54
 
                fi
55
 
        elif grep -E -qs "$1\$" /proc/filesystems
56
 
        then
57
 
                FSTYPE=$1
58
 
        elif grep -E -qs "$2\$" /proc/filesystems
59
 
        then
60
 
                FSTYPE=$2
61
 
        fi
62
 
 
63
 
        if [ ! "$FSTYPE" ]
64
 
        then
65
 
                if [ "$2" ]
66
 
                then
67
 
                        log_warning_msg "Filesystem types '$1' and '$2' are not supported. Skipping mount."
68
 
                else
69
 
                        log_warning_msg "Filesystem type '$1' is not supported. Skipping mount."
70
 
                fi
71
 
                return
72
 
        fi
73
 
 
74
 
        # We give file system type as device name if not specified as
75
 
        # an argument
76
 
        if [ "$4" ] ; then
77
 
            DEVNAME=$4
78
 
        else
79
 
            DEVNAME=$FSTYPE
80
 
        fi
81
 
 
82
 
        # Get the options from /etc/fstab.
83
 
        OPTS=
84
 
        if [ -f /etc/fstab ]
85
 
        then
86
 
                exec 9<&0 </etc/fstab
87
 
 
88
 
                while read TAB_DEV TAB_MTPT TAB_FSTYPE TAB_OPTS TAB_REST
89
 
                do
90
 
                        case "$TAB_DEV" in (""|\#*) continue ;; esac
91
 
                        [ "$MTPT" = "$TAB_MTPT" ] || continue
92
 
                        [ "$FSTYPE" = "$TAB_FSTYPE" ] || continue
93
 
                        case "$TAB_OPTS" in
94
 
                          noauto|*,noauto|noauto,*|*,noauto,*)
95
 
                                exec 0<&9 9<&-
96
 
                                return
97
 
                                ;;
98
 
                          ?*)
99
 
                                OPTS="-o$TAB_OPTS"
100
 
                                ;;
101
 
                        esac
102
 
                        break
103
 
                done
104
 
 
105
 
                exec 0<&9 9<&-
106
 
        fi
107
 
 
108
 
        if [ ! -d "$MTPT" ]
109
 
        then
110
 
                log_warning_msg "Mount point '$MTPT' does not exist. Skipping mount."
111
 
                return
112
 
        fi
113
 
 
114
 
        if mountpoint -q "$MTPT"
115
 
        then
116
 
                return # Already mounted
117
 
        fi
118
 
 
119
 
        if [ "$VERBOSE" != "no" ]; then
120
 
                is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden."
121
 
        fi
122
 
        mount -n -t $FSTYPE $5 $OPTS $DEVNAME $MTPT
123
 
        if [ "$FSTYPE" = "tmpfs" -a -x /sbin/restorecon ]; then
124
 
                /sbin/restorecon $MTPT
125
 
        fi
126
 
}
127
 
 
128
 
#
129
 
# Preserve /var/run and /var/lock mountpoints
130
 
#
131
 
pre_mountall ()
132
 
{
133
 
        # We may end up mounting something over top of /var, either directly
134
 
        # or because /var is a symlink to something that's mounted.  So keep
135
 
        # copies of the /var/run and /var/lock mounts elsewhere on the root
136
 
        # filesystem so they can be moved back.
137
 
        if [ yes = "$RAMRUN" ] ; then
138
 
                mkdir /lib/init/rw/var.run
139
 
                mount -n --bind /var/run /lib/init/rw/var.run
140
 
        fi
141
 
        if [ yes = "$RAMLOCK" ] ; then
142
 
                mkdir /lib/init/rw/var.lock
143
 
                mount -n --bind /var/lock /lib/init/rw/var.lock
144
 
        fi
145
 
}
146
 
 
147
 
#
148
 
# Restore /var/run and /var/lock mountpoints if something was mounted
149
 
# as /var/.  Avoid mounting them back over themselves if nothing was
150
 
# mounted as /var/ by checking if /var/run/ and /var/lock/ are still
151
 
# mount points.  Enabling RAMRUN and RAMLOCK while listing /var/run or
152
 
# /var/lock in /etc/fstab is not supported.
153
 
#
154
 
post_mountall ()
155
 
{
156
 
        if [ yes = "$RAMRUN" ] ; then
157
 
                [ -d /var/run ] || mkdir /var/run
158
 
                if mountpoint -q /var/run ; then
159
 
                        umount /lib/init/rw/var.run
160
 
                else
161
 
                        mount -n --move /lib/init/rw/var.run /var/run
162
 
                fi
163
 
                rmdir /lib/init/rw/var.run
164
 
        fi
165
 
        if [ yes = "$RAMLOCK" ] ; then
166
 
                [ -d /var/lock ] || mkdir /var/lock
167
 
                if mountpoint -q /var/lock ; then
168
 
                        umount /lib/init/rw/var.lock
169
 
                else
170
 
                        mount -n --move /lib/init/rw/var.lock /var/lock
171
 
                fi
172
 
                rmdir /lib/init/rw/var.lock
173
 
        fi
174
 
}