diff --git a/src/image_mad/remotes/fs/mkfs b/src/image_mad/remotes/fs/mkfs index d4e8c61157..344e669335 100755 --- a/src/image_mad/remotes/fs/mkfs +++ b/src/image_mad/remotes/fs/mkfs @@ -21,7 +21,7 @@ # as (FS) ############################################################################### -# ------------ Set up the environment to source common tools ------------ +# ------------ Set up the environment to source common tools ------------ if [ -z "${ONE_LOCATION}" ]; then LIB_LOCATION=/usr/lib/one @@ -32,37 +32,20 @@ fi . $LIB_LOCATION/sh/scripts_common.sh source $(dirname $0)/fsrc -# ------------ Create the image to the repository ------------ +# ------------ Create the image to the repository ------------ FSTYPE=$1 SIZE=$2 ID=$3 -# Specific options for different FS -case "$FSTYPE" in - "ext2"|"ext3"|"ext4"|"ntfs") - OPTS="-F" - ;; - - "reiserfs") - OPTS="-f -q" - ;; - - "jfs") - OPTS="-q" - ;; - *) - OPTS="" - ;; -esac - DST=`generate_image_path` +MKFS_CMD=`mkfs_command $DST $FSTYPE` + exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \ "Could not create image $DST" -exec_and_log "$MKFS -t $FSTYPE $OPTS $DST" \ +exec_and_log "$MKFS_CMD" \ "Unable to create filesystem $FSTYPE in $DST" - exec_and_log "chmod 0660 $DST" # ---------------- Get the size of the image ------------ diff --git a/src/mad/sh/scripts_common.sh b/src/mad/sh/scripts_common.sh index 5730e0b99c..0153c6bff6 100755 --- a/src/mad/sh/scripts_common.sh +++ b/src/mad/sh/scripts_common.sh @@ -148,3 +148,30 @@ function timeout_exec_and_log exit $CMD_CODE fi } + +# This function will return a command that upon execution will format a +# filesystem with its proper parameters based on the filesystem type +function mkfs_command { + DST=$1 + FSTYPE=${2:-ext3} + + # Specific options for different FS + case "$FSTYPE" in + "ext2"|"ext3"|"ext4"|"ntfs") + OPTS="-F" + ;; + + "reiserfs") + OPTS="-f -q" + ;; + + "jfs") + OPTS="-q" + ;; + *) + OPTS="" + ;; + esac + + echo "$MKFS -t $FSTYPE $OPTS $DST" +} diff --git a/src/tm_mad/lvm/tm_mkimage.sh b/src/tm_mad/lvm/tm_mkimage.sh index d092a8b9b2..1410eae120 100755 --- a/src/tm_mad/lvm/tm_mkimage.sh +++ b/src/tm_mad/lvm/tm_mkimage.sh @@ -32,7 +32,9 @@ DST_PATH=`arg_path $DST` DST_HOST=`arg_host $DST` DST_DIR=`dirname $DST_PATH` +MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` + exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" -exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH" +exec_and_log "$SSH $DST_HOST $MKFS_CMD" exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH" diff --git a/src/tm_mad/shared/tm_mkimage.sh b/src/tm_mad/shared/tm_mkimage.sh index b30c0ff327..97985c0368 100755 --- a/src/tm_mad/shared/tm_mkimage.sh +++ b/src/tm_mad/shared/tm_mkimage.sh @@ -36,11 +36,13 @@ fix_dst_path DST_DIR=`dirname $DST_PATH` +MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` + exec_and_log "mkdir -p $DST_DIR" \ "Error creating directory $DST_DIR" exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \ "Could not create image $DST_PATH" -exec_and_log "$MKFS -t $FSTYPE -F $DST_PATH" \ +exec_and_log "$MKFS_CMD" \ "Unable to create filesystem $FSTYPE in $DST_PATH" exec_and_log "chmod a+rw $DST_PATH" diff --git a/src/tm_mad/ssh/tm_mkimage.sh b/src/tm_mad/ssh/tm_mkimage.sh index 81ff20f32c..dec17c3d1e 100755 --- a/src/tm_mad/ssh/tm_mkimage.sh +++ b/src/tm_mad/ssh/tm_mkimage.sh @@ -32,10 +32,12 @@ DST_PATH=`arg_path $DST` DST_HOST=`arg_host $DST` DST_DIR=`dirname $DST_PATH` +MKFS_CMD=`mkfs_command $DST_PATH $FSTYPE` + exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \ "Error creating directory $DST_DIR" exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \ "Could not create image $DST_PATH" -exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH" \ +exec_and_log "$SSH $DST_HOST $MKFS_CMD" \ "Unable to create filesystem $FSTYPE in $DST_PATH" -exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH" \ No newline at end of file +exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"