[BACK]Return to cp_extents CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfsmisc

File: [Development] / xfs-cmds / xfsmisc / cp_extents (download)

Revision 1.1, Wed Apr 4 06:07:09 2007 UTC (10 years, 6 months ago) by tes.longdrop.melbourne.sgi.com
Branch: MAIN
CVS Tags: HEAD

Simple testing script for creating a file with a set of extents
matching some provided bmap output.
Merge of master-melb:xfs-cmds:28354a by kenmcd.

  Simple testing script for creating a file with a set of extents
  matching some provided bmap output.

#!/bin/sh
#
# Usage: 
#   xfs_bmap -v oldfile | cp_extents newfile
# or
#   cp_extents newfile < given_bmap_output
#
# Expect some form of bmap output on stdin.
# Done this way as sometimes the bmap output has come from email
# or from the web.
#
# Reverse sort so that we write in backwards direction such that
# the allocator doesn't detect a sequence.
# Simple script which worked for what I wanted; not sure if it will
# be useful in general.
#
# TODO: add support for unwritten extents
#
# Example input:
#
# EXT: FILE-OFFSET      BLOCK-RANGE          AG AG-OFFSET        TOTAL  FLG
#   0: [0..31]:         hole                                        32
#   1: [32..55]:        101029448..101029471 12 366152..366175      24
#   2: [56..87]:        hole                                        32
#   3: [88..199]:       101029504..101029615 12 366208..366319     112
#   4: [200..255]:      hole                                        56
#   5: [256..279]:      101029672..101029695 12 366376..366399      24
#   6: [280..559]:      hole                                       280
#   7: [560..647]:      101029976..101030063 12 366680..366767      88
#   8: [648..695]:      hole                                        48
#   9: [696..823]:      101030112..101030239 12 366816..366943     128
#  10: [824..855]:      hole                                        32
#  11: [856..879]:      101030272..101030295 12 366976..366999      24
#  12: [880..943]:      hole                                        64
#  13: [944..1015]:     101030360..101030431 12 367064..367135      72
#  14: [1016..1055]:    hole                                        40
#  15: [1056..1175]:    101030472..101030591 12 367176..367295     120
#  16: [1176..1199]:    hole                                        24
#  17: [1200..1279]:    101030616..101030695 12 367320..367399      80
#  18: [1280..1311]:    hole                                        32
#  19: [1312..1351]:    101030728..101030767 12 367432..367471      40
#  20: [1352..1447]:    hole                                        96
#  21: [1448..1535]:    101030864..101030951 12 367568..367655      88
#  22: [1536..1567]:    hole                                        32
#  23: [1568..3135]:    101461064..101462631 12 797768..799335    1568
#  24: [3136..3543]:    101465928..101466335 12 802632..803039     408
#

outfile=$1
sed -e 's/[][]//g' |\
sort -nr -k1,1 |\
tee |\
awk -v file=$outfile '
    /EXT:/ { next } # ignore header
    /[0-9][0-9]*:/ { 
		range = $2
		type = $3
		#printf("range = %s, type = %s\n", range, type)
		if (type ~ /hole/) {
		    next	
		} else {
		    n = split(range, arr, ".") 
		    start = arr[1]
		    end = arr[3]
		    size = end - start + 1
		    cmd = sprintf("xfs_io -d -f -c \"pwrite -b %ds %ds %ds\" %s", size, start, size, file) 

		    printf("start = %d, end = %d\n", start, end)
		    printf("cmd = %s\n", cmd)
		    system(cmd)
		}
    }
'