1772Skucharsk#!/bin/ksh 2772Skucharsk# 3772Skucharsk# CDDL HEADER START 4772Skucharsk# 5772Skucharsk# The contents of this file are subject to the terms of the 6*2826Ssc157166# Common Development and Distribution License (the "License"). 7*2826Ssc157166# You may not use this file except in compliance with the License. 8772Skucharsk# 9772Skucharsk# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10772Skucharsk# or http://www.opensolaris.org/os/licensing. 11772Skucharsk# See the License for the specific language governing permissions 12772Skucharsk# and limitations under the License. 13772Skucharsk# 14772Skucharsk# When distributing Covered Code, include this CDDL HEADER in each 15772Skucharsk# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16772Skucharsk# If applicable, add the following below this CDDL HEADER, with the 17772Skucharsk# fields enclosed by brackets "[]" replaced with your own identifying 18772Skucharsk# information: Portions Copyright [yyyy] [name of copyright owner] 19772Skucharsk# 20772Skucharsk# CDDL HEADER END 21772Skucharsk# 22772Skucharsk# 23772Skucharsk# ident "%Z%%M% %I% %E% SMI" 24772Skucharsk# 251358Sck142721# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 26772Skucharsk# Use is subject to license terms. 27772Skucharsk# 28772Skucharsk 29772Skucharsk# 30772Skucharsk# This script is called by flarcreate.sh 31772Skucharsk# 32772Skucharsk# Unmount all hwcap libraries (like /usr/lib/libc/libc_hwcap2.so.1) 33772Skucharsk# and store commands needed to remount them in preexit/remount_hwcap.xxxx 34772Skucharsk# scripts, which remounts them in the preexit phase. 35772Skucharsk# 36772Skucharsk 371358Sck142721if [ -z "$FLASH_PID" ]; then 38772Skucharsk echo "$0: ERROR: FLASH_PID not set in execution environment, exiting..." 39772Skucharsk exit 1 40772Skucharskfi 41*2826Ssc157166if [ -z "$FLASH_DIR" ]; then 42*2826Ssc157166 echo "$0: ERROR: FLASH_DIR not set in execution environment, exiting..." 43*2826Ssc157166 exit 1 44*2826Ssc157166fi 45772Skucharsk 46772SkucharskCHMOD=/usr/bin/chmod 47772SkucharskELFDUMP=/usr/ccs/bin/elfdump 48772SkucharskMOUNT=/usr/sbin/mount 49772SkucharskUMOUNT=/usr/sbin/umount 50772SkucharskEGREP=/usr/bin/egrep 51772SkucharskSED=/usr/bin/sed 52772SkucharskCMD_LIST="$CHMOD $ELFDUMP $MOUNT $UMOUNT $EGREP $SED" 53772Skucharsk 54772Skucharskfor cmd in $CMD_LIST 55772Skucharskdo 56772Skucharsk if [ ! -x $cmd ]; then 57772Skucharsk echo "$0: ERROR: $cmd not found or not executable, exiting..." 58772Skucharsk exit 1 59772Skucharsk fi 60772Skucharskdone 61772Skucharsk 62772Skucharsk# 63772Skucharsk# Fill "LIBS" with a list of mounted libraries in the form: 64772Skucharsk# MOUNTPOUNT:FILE 65772Skucharsk# e.g.: 66772Skucharsk# /lib/libc.so.1:/usr/lib/libc/libc_hwcap2.so.1 67772Skucharsk# 68772SkucharskLIBS=`$MOUNT | $EGREP "^/lib|^/usr/lib" | \ 69772Skucharsk $SED -e 's:^\(/[^ ]*\) on \([^ ]*\).*$:\1@\2:'` 70772Skucharsk 711358Sck142721if [ ! "$LIBS" ]; then 72772Skucharsk exit 0 73772Skucharskfi 74772Skucharsk 75*2826Ssc157166REMOUNT_DIR=${FLASH_DIR}/preexit 76772SkucharskREMOUNT=${REMOUNT_DIR}/remount_hwcap.${FLASH_PID} 77772Skucharsk 78772Skucharsk# 79772Skucharsk# Create the flash preexit script directory for the remount scripts if it 80772Skucharsk# doesn't already exist. 81772Skucharsk# 82772Skucharskif [ ! -d $REMOUNT_DIR ]; then 83772Skucharsk umask 077 84772Skucharsk /usr/bin/mkdir $REMOUNT_DIR 85772Skucharsk if [ $? -ne 0 ]; then 86772Skucharsk echo "$0: ERROR: could not mkdir $REMOUNT_DIR, exiting..." 87772Skucharsk exit 1 88772Skucharsk fi 89772Skucharskfi 90772Skucharsk 91772Skucharsk# 92772Skucharsk# If an old remount script by this name exists, delete it 93772Skucharsk# 94772Skucharskif [ -f $REMOUNT ]; then 95772Skucharsk /bin/rm -f $REMOUNT 96772Skucharskfi 97772Skucharsk 98772Skucharskumask 477 99772Skucharsk 100772Skucharskcat > $REMOUNT << EOF 101772Skucharsk#!/bin/sh 102772Skucharskif [ \"\$FLASH_PID\" != \"$FLASH_PID\" ]; then 103772Skucharsk /bin/rm -f $REMOUNT 104772Skucharsk exit 0 105772Skucharskfi 106772SkucharskEOF 107772Skucharsk 108772Skucharskif [ $? -ne 0 ]; then 109772Skucharsk echo "$0: ERROR: could not create $REMOUNT, exiting..." 110772Skucharsk exit 1 111772Skucharskfi 112772Skucharsk 113772Skucharsk# 114772Skucharsk# Now process each of the libraries that are mounted. For each, find out if 115772Skucharsk# it's a hwcap library; if it is, unmount it and write instructions to the 116772Skucharsk# preexit script as to how to remount it. 117772Skucharsk# 118772Skucharskfor entry in $LIBS 119772Skucharskdo 120772Skucharsk echo $entry | IFS=@ read MOUNTPOINT MOUNTLIB 121772Skucharsk CAPLIB=`$ELFDUMP -H $MOUNTLIB` 122772Skucharsk if [ \( $? -eq 0 \) -a \( -n "$CAPLIB" \) ]; then 123772Skucharsk $UMOUNT $MOUNTPOINT || $UMOUNT -f $MOUNTPOINT || \ 124772Skucharsk { echo "$0: ERROR: Could not unmount" \ 125772Skucharsk "$MOUNTPOINT, exiting..."; \ 126772Skucharsk /bin/sh $REMOUNT; /bin/rm -f $REMOUNT; exit 1; } 127772Skucharsk 128772Skucharsk echo $MOUNTLIB | $EGREP -s : 129772Skucharsk if [ $? -eq 0 ]; then 130772Skucharsk MOUNTOPTS="-O" 131772Skucharsk else 132772Skucharsk MOUNTOPTS="-O -F lofs" 133772Skucharsk fi 134772Skucharsk echo "$MOUNT $MOUNTOPTS $MOUNTLIB $MOUNTPOINT" >> $REMOUNT 135772Skucharsk fi 136772Skucharskdone 137772Skucharsk 138772Skucharsk# 139772Skucharsk# Write final cleanup instructions to the flash preexit remount script and make 140772Skucharsk# it executable. 141772Skucharsk# 142772Skucharskecho "/bin/rm -f $REMOUNT" >> $REMOUNT 143772Skucharskecho "exit 0" >> $REMOUNT 144772Skucharsk$CHMOD 0500 $REMOUNT 145772Skucharskexit 0 146