A set of simple utilities for manipulating xv6-riscv file system images
Simply invoking make should build all the things: opfs, newfs, and modfs.
$ make
You can copy these executables to your favorite place.
Alternatively, you can invoke the target install of Makefile with the specification of PREFIX as follows.
$ sudo make PREFIX=/usr/local install
This package provides three commands: opfs, newfs and modfs.
The command opfs provides safe operations on an xv6 file system in the disk image file (imgfile).
opfs imgfile command
Command is one of the following:
diskinfo: displays the information of the file system in the disk image fileinfopath : displays the detailed information of a file specified by pathlspath : lists the contents of a directory specified by pathgetpath : copies the contents of a file specified by path to the standard outputputpath : copies the standard input to a file specified by pathrmpath : removes a file specified by pathcpspath dpath : copies the contents of a file specified by spath to the destination specified by dpathmvspath dpath : moves (renames) a file specified by spath to the destination specified by dpathlnspath dpath : creates a new directory entry specified by dpath which points to the same file specified by spathmkdirpath : creates a new directory specified by pathrmdirpath : removes an empty directory specified by path
Display the information of the file system in fs.img.
$ opfs fs.img diskinfo
magic: 10203040
total blocks: 1000 (1024000 bytes)
log blocks: #2-#31 (30 blocks)
inode blocks: #32-#44 (13 blocks, 200 inodes)
bitmap blocks: #45-#45 (1 blocks)
data blocks: #46-#999 (954 blocks)
maximum file size (bytes): 274432
# of used blocks: 594
# of used inodes: 19 (dirs: 1, files: 17, devs: 1)
List the contents of the root directory of the file system in fs.img.
$ opfs fs.img ls /
. 1 1 1024
.. 1 1 1024
README 2 2 2059
cat 2 3 23888
echo 2 4 22720
forktest 2 5 13080
grep 2 6 27248
init 2 7 23824
kill 2 8 22696
ln 2 9 22648
ls 2 10 26120
mkdir 2 11 22792
rm 2 12 22784
sh 2 13 41656
stressfs 2 14 23792
usertests 2 15 152224
grind 2 16 37928
wc 2 17 25032
zombie 2 18 22184
console 3 19 0
Copy the contents of the file README in fs.img into the file README_xv6.txt in the host OS file system.
$ opfs fs.img get README > REAMDE_xv6.txt
The command newfs creates a new empty disk image file named imgfile.
newfs imgfile size ninodes nlog
- size : number of all blocks
- ninodes : number of i-nodes
- nlog : number of log blocks
Create a new empty disk image file named fs0.img.
$ newfs fs0.img 1000 200 30
# of blocks: 1000
# of inodes: 200
# of log blocks: 30
# of inode blocks: 13
# of bitmap blocks: 1
# of data blocks: 954
The command modfs provides potentially unsafe operations on an xv6 file system in the disk image file (imgfile).
modfs imgfile command
Command is one of the following:
superblock.magic[val] : themagicfield of the superblocksuperblock.size[val] : thesizefield of the superblock (total number of blocks)superblock.nblocks[val] : thenblocksfield of the superblock (number of data blocks)superblock.ninodes[val] : theninodesfield of the superblock (number of i-nodes)superblock.nlog[val] : thenlogfield of the superblock (number of log blocks)superblock.logstart[val] : thelogstartfield of the superblock (starting block number of log blocks)superblock.inodestart[val] : theinodestartfield of the superblock (starting number of i-node blocks)superblock.bmapstart[val] : thebmapstartfield of the superblock (starting block number of bitmap blocks)bitmapbnum [val] : the bnum-th value of the bitmap (0 or 1)inode.typeinum [val] : thetypefield of the inum-th i-nodeinode.nlinkinum [val] : thenlinkfield of the inum-th i-nodeinode.sizeinum [val] : thesizefield of the inum-th i-nodeinode.addrsinum n [val] : the block number of the n-th data block referred from the inum-th i-nodeinode.indirectinum [val] : the block number of the indirect block referred from the inum-th i-nodedirentpath name [val] : the i-node number of the entry name of the directory specified by path
In each command, providing optional parameter val modifies the specified value. Be aware that such modification may break the consistency of the file system.