xref: /titanic_41/usr/src/cmd/lvm/util/growfs.sh (revision 6185db853e024a486ff8837e6784dd290d866112)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
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.
9#
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.
14#
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]
20#
21# CDDL HEADER END
22#
23#
24#pragma ident	"%Z%%M%	%I%	%E% SMI"
25#
26# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29
30#exec newfs -G "$@"
31
32myname=`basename $0`
33USAGE="usage: $myname [ -M mount-point ] [ newfs-options ] raw-special-device"
34if [ ! "$UFS_MKFS" ]; then
35	UFS_MKFS="/usr/lib/fs/ufs/mkfs"
36fi
37verbose=""
38mkfs_opts="-G"
39mkfs_subopts=""
40size=""
41newsize=0
42mount_pt=
43UFS_MKFS_NOTENOUGHSPACE=33
44
45add_opt() {
46	mkfs_opts="$mkfs_opts $1"
47}
48
49add_subopt() {
50	if [ ! "$mkfs_subopts" ]; then
51		mkfs_subopts="-o $1"
52	else
53		mkfs_subopts="$mkfs_subopts,$1"
54	fi
55}
56
57while getopts "GM:Nva:b:c:d:f:i:m:n:o:r:s:t:C:" c ; do
58	save=$OPTIND
59
60	case $c in
61	G)	;;
62	M)	add_opt "-M $OPTARG"; mount_pt="$OPTARG" ;;
63	N)	add_subopt "N" ;;
64	v)	verbose="1" ;;
65	a)	add_subopt "apc=$OPTARG" ;;
66	b)	add_subopt "bsize=$OPTARG" ;;
67	c)	add_subopt "cgsize=$OPTARG" ;;
68	d)	add_subopt "gap=$OPTARG" ;;
69	f)	add_subopt "fragsize=$OPTARG" ;;
70	i)	add_subopt "nbpi=$OPTARG" ;;
71	m)	add_subopt "free=$OPTARG" ;;
72	n)	add_subopt "nrpos=$OPTARG" ;;
73	o)	add_subopt "opt=$OPTARG" ;;
74	r)	add_subopt "rps=`expr $OPTARG / 60`" ;;
75	s)	size=$OPTARG ;;
76	t)	add_subopt "ntrack=$OPTARG" ;;
77	C)	add_subopt "maxcontig=$OPTARG" ;;
78	\?)	echo $USAGE; exit 1 ;;
79	esac
80
81	OPTIND=$save
82done
83
84shift `expr $OPTIND - 1`
85if [ $# -ne 1 ]; then
86	echo $USAGE
87	exit 1
88fi
89raw_special=$1
90
91if [ ! "$size" ]; then
92	size=`devinfo -p $raw_special | awk '{ print $5 }'`
93	if [ $? -ne 0 -o ! "$size" ]; then
94		echo "$myname: cannot get partition size"
95		exit 2
96	fi
97fi
98
99cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $size"
100if [ -n "$verbose" ]; then
101	echo $cmd
102fi
103$cmd; retv=$?
104
105if [ $retv -eq $UFS_MKFS_NOTENOUGHSPACE ]; then
106	echo "Growing filesystem in increments due to limited available space."
107
108	while [ "$newsize" -lt "$size" ]; do
109		cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts -P $raw_special $size"
110		if [ -n "$verbose" ]; then
111			echo $cmd
112		fi
113		newsize=`$cmd`; retv=$?
114		if [ 0 -ne $retv -o -z "$newsize" ]; then
115			echo "$myname: cannot probe the possible file system size"
116			exit 2
117		fi
118		if [ 0 -eq "$newsize" ]; then
119			echo "$myname: the file system is full and cannot be grown, please delete some files"
120			exit 2
121		fi
122
123		cmd="$UFS_MKFS $mkfs_opts $mkfs_subopts $raw_special $newsize"; retv=$?
124		if [ -n "$verbose" ]; then
125			echo $cmd
126		fi
127		$cmd; retv=$?
128		if [ 0 -ne $retv ]; then
129			echo "$myname: cannot grow file system to $newsize sectors"
130			exit  $retv
131		fi
132	done
133	echo \
134"\nThe incremental grow has successfully completed, but since the first growth \
135attempt failed (see output from first mkfs(1M) run), the filesystem is still \
136locked and needs to be checked with fsck(1M).\n\
137Please run \`fsck -F ufs $raw_special' and then unlock the filesystem \
138with \`lockfs -u $mount_pt'." | fmt;
139
140fi
141
142exit $retv
143