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