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 fileinfo
path : displays the detailed information of a file specified by pathls
path : lists the contents of a directory specified by pathget
path : copies the contents of a file specified by path to the standard outputput
path : copies the standard input to a file specified by pathrm
path : removes a file specified by pathcp
spath dpath : copies the contents of a file specified by spath to the destination specified by dpathmv
spath dpath : moves (renames) a file specified by spath to the destination specified by dpathln
spath dpath : creates a new directory entry specified by dpath which points to the same file specified by spathmkdir
path : creates a new directory specified by pathrmdir
path : 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] : themagic
field of the superblocksuperblock.size
[val] : thesize
field of the superblock (total number of blocks)superblock.nblocks
[val] : thenblocks
field of the superblock (number of data blocks)superblock.ninodes
[val] : theninodes
field of the superblock (number of i-nodes)superblock.nlog
[val] : thenlog
field of the superblock (number of log blocks)superblock.logstart
[val] : thelogstart
field of the superblock (starting block number of log blocks)superblock.inodestart
[val] : theinodestart
field of the superblock (starting number of i-node blocks)superblock.bmapstart
[val] : thebmapstart
field of the superblock (starting block number of bitmap blocks)bitmap
bnum [val] : the bnum-th value of the bitmap (0 or 1)inode.type
inum [val] : thetype
field of the inum-th i-nodeinode.nlink
inum [val] : thenlink
field of the inum-th i-nodeinode.size
inum [val] : thesize
field of the inum-th i-nodeinode.addrs
inum n [val] : the block number of the n-th data block referred from the inum-th i-nodeinode.indirect
inum [val] : the block number of the indirect block referred from the inum-th i-nodedirent
path 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.