dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / growfs / growfs.sh
blobf17199aad1b5d9ea3d9ae641b82eef4e7f4ec198
1 #!/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
25 # Copyright 2003 Sun Microsystems, Inc. All rights reserved.
26 # Use is subject to license terms.
29 #exec newfs -G "$@"
31 myname=`basename $0`
32 USAGE="usage: $myname [ -M mount-point ] [ newfs-options ] raw-special-device"
33 if [ ! "$UFS_MKFS" ]; then
34 UFS_MKFS="/usr/lib/fs/ufs/mkfs"
36 verbose=""
37 mkfs_opts="-G"
38 mkfs_subopts=""
39 size=""
40 newsize=0
41 mount_pt=
42 UFS_MKFS_NOTENOUGHSPACE=33
44 add_opt() {
45 mkfs_opts="$mkfs_opts $1"
48 add_subopt() {
49 if [ ! "$mkfs_subopts" ]; then
50 mkfs_subopts="-o $1"
51 else
52 mkfs_subopts="$mkfs_subopts,$1"
56 while getopts "GM:Nva:b:c:d:f:i:m:n:o:r:s:t:C:" c ; do
57 save=$OPTIND
59 case $c in
60 G) ;;
61 M) add_opt "-M $OPTARG"; mount_pt="$OPTARG" ;;
62 N) add_subopt "N" ;;
63 v) verbose="1" ;;
64 a) add_subopt "apc=$OPTARG" ;;
65 b) add_subopt "bsize=$OPTARG" ;;
66 c) add_subopt "cgsize=$OPTARG" ;;
67 d) add_subopt "gap=$OPTARG" ;;
68 f) add_subopt "fragsize=$OPTARG" ;;
69 i) add_subopt "nbpi=$OPTARG" ;;
70 m) add_subopt "free=$OPTARG" ;;
71 n) add_subopt "nrpos=$OPTARG" ;;
72 o) add_subopt "opt=$OPTARG" ;;
73 r) add_subopt "rps=`expr $OPTARG / 60`" ;;
74 s) size=$OPTARG ;;
75 t) add_subopt "ntrack=$OPTARG" ;;
76 C) add_subopt "maxcontig=$OPTARG" ;;
77 \?) echo $USAGE; exit 1 ;;
78 esac
80 OPTIND=$save
81 done
83 shift `expr $OPTIND - 1`
84 if [ $# -ne 1 ]; then
85 echo $USAGE
86 exit 1
88 raw_special=$1
90 if [ ! "$size" ]; then
91 size=`devinfo -p $raw_special | awk '{ print $5 }'`
92 if [ $? -ne 0 -o ! "$size" ]; then
93 echo "$myname: cannot get partition size"
94 exit 2
98 cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $size"
99 if [ -n "$verbose" ]; then
100 echo $cmd
102 $cmd; retv=$?
104 if [ $retv -eq $UFS_MKFS_NOTENOUGHSPACE ]; then
105 echo "Growing filesystem in increments due to limited available space."
107 while [ "$newsize" -lt "$size" ]; do
108 cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts -P $raw_special $size"
109 if [ -n "$verbose" ]; then
110 echo $cmd
112 newsize=`$cmd`; retv=$?
113 if [ 0 -ne $retv -o -z "$newsize" ]; then
114 echo "$myname: cannot probe the possible file system size"
115 exit 2
117 if [ 0 -eq "$newsize" ]; then
118 echo "$myname: the file system is full and cannot be grown, please delete some files"
119 exit 2
122 cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $newsize"; retv=$?
123 if [ -n "$verbose" ]; then
124 echo $cmd
126 $cmd; retv=$?
127 if [ 0 -ne $retv ]; then
128 echo "$myname: cannot grow file system to $newsize sectors"
129 exit $retv
131 done
132 echo \
133 "\nThe incremental grow has successfully completed, but since the first growth \
134 attempt failed (see output from first mkfs(1M) run), the filesystem is still \
135 locked and needs to be checked with fsck(1M).\n\
136 Please run \`fsck -F ufs $raw_special' and then unlock the filesystem \
137 with \`lockfs -u $mount_pt'." | fmt;
141 exit $retv