5 This is the rfs program
\r
7 After run nfsscan, you will get a file-list file in the output
\r
9 This perl program do post processing based on this file
\r
14 $writebuf = "R" x 8193;
\r
15 $writeBlockSize = 8192;
\r
22 my ($path, $pathcnt, $sizeHexStr) = @_;
\r
23 $sizeHexStr = "0x".$sizeHexStr;
\r
29 $dir =~ /(^.*)\/(.*)/;
\r
32 if (!$dir) {$dir = ".";}
\r
33 die "name is empty\n" if (!$name);
\r
34 #print "path($path) dir($dir) name($name)\n";
\r
37 $cmdbuf = "mkdir -p $dir";
\r
39 print "RFS: Warning: the directory should be created already: $path\n";
\r
41 die "warning: directory name exist but not a directory: $path\n" if (!(-d $dir));
\r
44 my $size = hex($sizeHexStr);
\r
45 my $remSize = $size % $writeBlockSize;
\r
46 my $lp = ($size - $remSize) / $writeBlockSize;
\r
47 #print "size($sizeHexStr) lp($lp) rem($remSize)\n";
\r
49 open RFSTMPWRITE, ">$path" || die "RFS: can not open file for write";
\r
52 for ($i = 0; $i < $lp; $i++) {
\r
53 syswrite(RFSTMPWRITE, $writebuf, $writeBlockSize);
\r
56 syswrite(RFSTMPWRITE, $writebuf, $remSize);
\r
57 #print "write ($remSize) byte\n";
\r
63 # sort -n -k a,b -c -u
\r
71 # skip comment lines
\r
72 # if (path_count ($6) == 0 or original_op($9) == "create" or "mkdir") skip the file
\r
74 $cmdbuf = 'gawk \' !/^[#]/ { if ($6 != "0" && $9 != "create" && $9 != "mkdir") print $0 }\' test.fil > active.fil';
\r
78 # sort the active.fil according to path_count
\r
79 $cmdbuf = 'sort -k 5,5 active.fil > active.fil.order';
\r
82 $cmdbuf = 'sort -n -k 6,6 active.fil > active.fil.order-pathcnt';
\r
86 # keep the interested field only
\r
87 # 2(D/F) 4(FH) 5(path) 6(count) 7(size) 8(mode)
\r
88 $cmdbuf = 'gawk \' { print $2, $4, $5, $6, $7, $8 }\' active.fil.order > active';
\r
91 $cmdbuf = 'gawk \' { print $4, $5 }\' active.fil.order > fh-path-map';
\r
94 $cmdbuf = 'gawk \' { print $2, $4, $5, $6, $7, $8 }\' active.fil.order-pathcnt > active-pathcnt';
\r
97 $cmdbuf = 'gawk \' { print $4, $5 }\' active.fil.order-pathcnt > fh-path-map-pathcnt';
\r
103 # so far, you got the following information
\r
104 # in active: all files/dirs active
\r
105 # in noattrdir-root: a set of fhs pointing to RFSNN0
\r
106 # in rfsinfo: a set of dir fhs refer to RFSNNxxx(>0)
\r
107 # a set of file fhs should be discard due to short of information
\r
109 # create the active fs
\r
110 # 1. BASEDIR/RFSNN0
\r
111 # 2. BASEDIR/active
\r
112 $cmdbuf = "mkdir -p RFSFS/RFSNN0";
\r
114 open RFS_ACTIVE, "active";
\r
115 while (<RFS_ACTIVE>) {
\r
117 my ($type, $fh, $path, $pathcnt, $sizeHexStr, $mode) = split (' ', $_, 7);
\r
118 if ($type eq "D") {
\r
119 $cmdbuf = "mkdir -p RFSFS$path";
\r
123 &rfsCreateFile("RFSFS$path", $pathcnt, $sizeHexStr);
\r
128 # create map table: key (fh), value (path/fn)
\r
130 # check whether there is fh that is not mapped to any path/fn in the trace
\r
132 # simulate a replay of trace
\r