Print this page
6198 Let's EOL cachefs
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/initpkg/mountall.sh
+++ new/usr/src/cmd/initpkg/mountall.sh
1 1 #!/sbin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License, Version 1.0 only
7 7 # (the "License"). You may not use this file except in compliance
8 8 # with the License.
9 9 #
10 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 # or http://www.opensolaris.org/os/licensing.
12 12 # See the License for the specific language governing permissions
13 13 # and limitations under the License.
14 14 #
15 15 # When distributing Covered Code, include this CDDL HEADER in each
16 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 # If applicable, add the following below this CDDL HEADER, with the
18 18 # fields enclosed by brackets "[]" replaced with your own identifying
19 19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 20 #
21 21 # CDDL HEADER END
22 22 #
23 23
24 24 #
25 25 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
26 26 # Use is subject to license terms.
27 +# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 28 #
28 29 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
29 30 # All Rights Reserved
30 31 #
31 32
32 33 usage () {
33 34 if [ -n "$1" ]; then
34 35 echo "mountall: $1" 1>&2
35 36 fi
36 37 echo "Usage:\nmountall [-F FSType] [-l|-r|-g] [file_system_table]" 1>&2
37 38 exit 2
38 39 }
39 40
40 41 PATH=/usr/sbin:/usr/bin
41 42 TYPES=all
42 43 FSTAB=/etc/vfstab
43 44 err=0
44 45
45 46 # Clear these in case they were already set in our environment.
46 47 FSType=
47 48 GFLAG=
48 49 RFLAG=
49 50 LFLAG=
50 51 SFLAG=
51 52 RemoteFSTypes=
52 53
53 54 # checkmessage "fsck_device | mount_point"
54 55 #
55 56 # Simple auxilary routine to the shell function checkfs. Prints out
56 57 # instructions for a manual file system check before entering the shell.
57 58 #
58 59 checkmessage() {
59 60 echo "" > /dev/console
60 61 if [ "$1" != "" ] ; then
61 62 echo "WARNING - Unable to repair one or more \c" > /dev/console
62 63 echo "of the following filesystem(s):" > /dev/console
63 64 echo "\t$1" > /dev/console
64 65 else
65 66 echo "WARNING - Unable to repair one or more filesystems." \
66 67 > /dev/console
67 68 fi
68 69 echo "Run fsck manually (fsck filesystem...)." > /dev/console
69 70 echo "" > /dev/console
70 71 }
71 72
72 73 #
73 74 # checkfs raw_device fstype mountpoint
74 75 #
75 76 # Check the file system specified. The return codes from fsck have the
76 77 # following meanings.
77 78 # 0 - file system is unmounted and okay
78 79 # 32 - file system is unmounted and needs checking (fsck -m only)
79 80 # 33 - file system is already mounted
80 81 # 34 - cannot stat device
81 82 # 36 - uncorrectable errors detected - terminate normally (4.1 code 8)
82 83 # 37 - a signal was caught during processing (4.1 exit 12)
83 84 # 39 - uncorrectable errors detected - terminate rightaway (4.1 code 8)
84 85 # 40 - for root, same as 0 (used by rcS to remount root)
85 86 #
86 87 checkfs() {
87 88 /usr/sbin/fsck -F $2 -m $1 >/dev/null 2>&1
88 89
89 90 if [ $? -ne 0 ]
90 91 then
91 92 # Determine fsck options by file system type
92 93 case "$2" in
93 94 ufs) foptions="-o p"
94 95 ;;
95 96 *) foptions="-y"
96 97 ;;
97 98 esac
98 99
99 100 echo "The "$3" file system ("$1") is being checked."
100 101 /usr/sbin/fsck -F $2 ${foptions} $1
101 102
102 103 case $? in
103 104 0|40) # file system OK
104 105 ;;
105 106
106 107 *) # couldn't fix the file system
107 108 echo "/usr/sbin/fsck failed with exit code "$?"."
108 109 checkmessage "$1"
109 110 ;;
110 111 esac
111 112 fi
112 113 }
113 114
114 115 #
115 116 # Used to save an entry that we will want to mount either in
116 117 # a command file or as a mount point list.
117 118 #
118 119 # saveentry fstype options special mountp
119 120 #
120 121 saveentry() {
121 122 if [ "$ALTM" ]; then
122 123 echo "/sbin/mount -F $1 $2 $3 $4" >> $ALTM
123 124 else
124 125 mntlist="$mntlist $4"
125 126 fi
126 127 }
127 128
128 129 # Do the passed mount options include "global"?
129 130 isglobal() {
130 131 case ",${1}," in
131 132 *,global,*)
132 133 return 0
133 134 ;;
134 135 esac
135 136 return 1
136 137 }
137 138
138 139 # Is the passed fstype a "remote" one?
139 140 # Essentially: /usr/bin/grep "^$1" /etc/dfs/fstypes
140 141 isremote() {
141 142 for t in $RemoteFSTypes
142 143 do
143 144 [ "$t" = "$1" ] && return 0
144 145 done
145 146 return 1
146 147 }
147 148
148 149 # Get list of remote FS types (just once)
149 150 RemoteFSTypes=`while read t junk; do echo $t; done < /etc/dfs/fstypes`
150 151
151 152
152 153 #
153 154 # Process command line args
154 155 #
155 156 while getopts ?grlsF: c
156 157 do
157 158 case $c in
158 159 g) GFLAG="g";;
159 160 r) RFLAG="r";;
160 161 l) LFLAG="l";;
161 162 s) SFLAG="s";;
162 163 F) FSType="$OPTARG";
163 164 if [ "$TYPES" = "one" ]
164 165 then
165 166 echo "mountall: more than one FSType specified"
166 167 exit 2
167 168 fi
168 169 TYPES="one";
169 170
170 171 case $FSType in
171 172 ?????????*)
172 173 echo "mountall: FSType $FSType exceeds 8 characters"
173 174 exit 2
174 175 esac
175 176 ;;
176 177 \?) usage "";;
177 178 esac
178 179 done
179 180
180 181 shift `/usr/bin/expr $OPTIND - 1` # get past the processed args
181 182
182 183 if [ $# -gt 1 ]; then
183 184 usage "multiple arguments not supported"
184 185 fi
185 186
186 187 # get file system table name and make sure file exists
187 188 if [ $# = 1 ]; then
188 189 case $1 in
189 190 "-") FSTAB=""
190 191 ;;
191 192 *) FSTAB=$1
192 193 ;;
193 194 esac
194 195 fi
195 196 #
196 197 # if an alternate vfstab file is used or serial mode is specified, then
197 198 # use a mount command file
198 199 #
199 200 if [ $# = 1 -o "$SFLAG" ]; then
200 201 ALTM=/var/tmp/mount$$
201 202 rm -f $ALTM
202 203 fi
203 204
204 205 if [ "$FSTAB" != "" -a ! -s "$FSTAB" ]
205 206 then
206 207 echo "mountall: file system table ($FSTAB) not found"
207 208 exit 1
208 209 fi
209 210
210 211 #
211 212 # Check for incompatible args
212 213 #
213 214 if [ "$GFLAG" = "g" -a "$RFLAG$LFLAG" != "" -o \
214 215 "$RFLAG" = "r" -a "$GFLAG$LFLAG" != "" -o \
215 216 "$LFLAG" = "l" -a "$RFLAG$GFLAG" != "" ]
216 217 then
217 218 usage "options -g, -r and -l are mutually exclusive"
218 219 fi
219 220
220 221 if [ "$LFLAG" = "l" -a -n "$FSType" ]; then
221 222 # remote FSType not allowed
222 223 isremote "$FSType" &&
223 224 usage "option -l and FSType are incompatible"
224 225 fi
225 226
226 227 if [ "$RFLAG" = "r" -a -n "$FSType" ]; then
227 228 # remote FSType required
228 229 isremote "$FSType" ||
229 230 usage "option -r and FSType are incompatible"
230 231 fi
231 232
232 233 # file-system-table format:
233 234 #
234 235 # column 1: special- block special device or resource name
235 236 # column 2: fsckdev- char special device for fsck
236 237 # column 3: mountp- mount point
237 238 # column 4: fstype- File system type
238 239 # column 5: fsckpass- number if to be checked automatically
239 240 # column 6: automnt- yes/no for automatic mount
240 241 # column 7: mntopts- -o specific mount options
241 242
242 243 # White-space separates columns.
243 244 # Lines beginning with \"#\" are comments. Empty lines are ignored.
244 245 # a '-' in any field is a no-op.
245 246
246 247 #
247 248 # Read FSTAB, fsck'ing appropriate filesystems:
248 249 #
249 250 exec < $FSTAB
250 251 while read special fsckdev mountp fstype fsckpass automnt mntopts
251 252 do
252 253 case $special in
253 254 '#'* | '') # Ignore comments, empty lines
254 255 continue ;;
255 256 '-') # Ignore no-action lines
256 257 continue
257 258 esac
258 259
259 260 if [ "$automnt" != "yes" ]; then
260 261 continue
261 262 fi
262 263 if [ "$FSType" -a "$FSType" != "$fstype" ]; then
263 264 # ignore different fstypes
264 265 continue
265 266 fi
266 267
267 268 # The -g option is not in the man page, but according to
268 269 # PSARC/1998/255 it's used by Sun Cluster (via contract) to
269 270 # mount disk-based filesystems with the "global" option.
270 271 # Also, the -l option now skips those "global" mounts.
271 272 #
272 273 # Note: options -g -l -r are mutually exclusive
273 274 #
274 275 if [ -n "$GFLAG" ]; then
275 276 # Mount "local" filesystems that have
276 277 # the "global" option in mntopts.
277 278 isremote "$fstype" && continue
278 279 isglobal "$mntopts" || continue
279 280 fi
280 281 if [ -n "$LFLAG" ]; then
281 282 # Mount "local" filesystems, excluding
282 283 # those marked "global".
283 284 isremote "$fstype" && continue
284 285 isglobal "$mntopts" && continue
285 286 fi
286 287 if [ -n "$RFLAG" ]; then
287 288 # Mount "remote" filesystems.
288 289 isremote "$fstype" || continue
289 290 fi
290 291
291 292 if [ "$fstype" = "-" ]; then
292 293 echo "mountall: FSType of $special cannot be identified" 1>&2
293 294 continue
294 295 fi
295 296
296 297 if [ "$ALTM" -a "$mntopts" != "-" ]; then
297 298 OPTIONS="-o $mntopts" # Use mount options if any
298 299 else
299 300 OPTIONS=""
300 301 fi
301 302
302 303 #
303 304 # Ignore entries already mounted
304 305 #
305 306 /usr/bin/grep " $mountp " /etc/mnttab >/dev/null 2>&1 && continue
306 307
307 308 #
308 309 # Can't fsck if no fsckdev is specified
309 310 #
310 311 if [ "$fsckdev" = "-" ]; then
311 312 saveentry $fstype "$OPTIONS" $special $mountp
312 313 continue
313 314 fi
314 315 #
315 316 # For fsck purposes, we make a distinction between file systems
316 317 # that have a /usr/lib/fs/<fstyp>/fsckall script and those
317 318 # that don't. For those that do, just keep a list of them
318 319 # and pass the list to the fsckall script for that file
319 320 # file system type.
320 321 #
321 322 if [ -x /usr/lib/fs/$fstype/fsckall ]; then
322 323
323 324 #
324 325 # add fstype to the list of fstypes for which
325 326 # fsckall should be called, if it's not already
326 327 # in the list.
327 328 #
328 329 found=no
329 330 if [ "$fsckall_fstypes" != "" ] ; then
330 331 for fst in $fsckall_fstypes; do
331 332 if [ "$fst" = "$fstype" ] ; then
332 333 found=yes
333 334 break
334 335 fi
335 336 done
336 337 fi
337 338 if [ $found = no ] ; then
338 339 fsckall_fstypes="$fsckall_fstypes ${fstype}"
339 340 fi
340 341
341 342 #
342 343 # add the device to the name of devices to be passed
343 344 # to the fsckall program for this file system type
344 345 #
345 346 cmd="${fstype}_fscklist=\"\$${fstype}_fscklist $fsckdev\""
346 347 eval $cmd
347 348 saveentry $fstype "$OPTIONS" $special $mountp
348 349 continue
349 350 fi
350 351 #
351 352 # fsck everything else:
352 353 #
353 354 # fsck -m simply returns true if the filesystem is suitable for
354 355 # mounting.
355 356 #
356 357 /usr/sbin/fsck -m -F $fstype $fsckdev >/dev/null 2>&1
357 358 case $? in
358 359 0|40) saveentry $fstype "$OPTIONS" $special $mountp
359 360 continue
360 361 ;;
361 362 32) checkfs $fsckdev $fstype $mountp
362 363 saveentry $fstype "$OPTIONS" $special $mountp
363 364 continue
364 365 ;;
365 366 33) # already mounted
366 367 echo "$special already mounted"
367 368 ;;
368 369 34) # bogus special device
369 370 echo "Cannot stat $fsckdev - ignoring"
370 371 err=1
371 372 ;;
372 373 *) # uncorrectable errors
373 374 echo "$fsckdev uncorrectable error"
374 375 err=1
375 376 ;;
376 377 esac
377 378 done
378 379
379 380 #
380 381 # Call the fsckall programs
381 382 #
382 383 for fst in $fsckall_fstypes
383 384 do
384 385 cmd="/usr/lib/fs/$fst/fsckall \$${fst}_fscklist"
385 386 eval $cmd
386 387
387 388 case $? in
388 389 0) # file systems OK
389 390 ;;
390 391
391 392 *) # couldn't fix some of the filesystems
392 393 echo "fsckall failed with exit code "$?"."
393 394 checkmessage
394 395 ;;
395 396 esac
396 397 done
397 398
398 399 if [ "$ALTM" ]; then
399 400 if [ ! -f "$ALTM" ]; then
400 401 exit
401 402 fi
↓ open down ↓ |
365 lines elided |
↑ open up ↑ |
402 403 /sbin/sh $ALTM # run the saved mount commands
403 404 /usr/bin/rm -f $ALTM
404 405 exit
405 406 fi
406 407
407 408 if [ -n "$FSType" ]; then
408 409 /sbin/mount -a -F $FSType
409 410 exit
410 411 fi
411 412
412 -# Some remote filesystems (e.g. cachefs or autofs) shouldn't be be mounted
413 +# Some remote filesystems (e.g. autofs) shouldn't be mounted
413 414 # with mountall, so the list here is explicit (not from /etc/dfs/fstypes)
414 415 if [ "$RFLAG" ]; then
415 416 /sbin/mount -a -F nfs
416 417 /sbin/mount -a -F smbfs
417 418 exit
418 419 fi
419 420
420 421 if [ "$LFLAG" -o "$GFLAG" -o $err != 0 ]; then
421 422 [ -z "$mntlist" ] || /sbin/mount -a $mntlist
422 423 exit
423 424 fi
424 425
425 426 # else mount them all
426 427
427 428 /sbin/mount -a
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX