Skip to content
/ opfs Public

A set of simple utilities for manipulating xv6-riscv file system images

License

Notifications You must be signed in to change notification settings

wtakuo/opfs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opfs

A set of simple utilities for manipulating xv6-riscv file system images

Installation

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

Usage

This package provides three commands: opfs, newfs and modfs.

1. opfs

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 file
  • info path : displays the detailed information of a file specified by path
  • ls path : lists the contents of a directory specified by path
  • get path : copies the contents of a file specified by path to the standard output
  • put path : copies the standard input to a file specified by path
  • rm path : removes a file specified by path
  • cp spath dpath : copies the contents of a file specified by spath to the destination specified by dpath
  • mv spath dpath : moves (renames) a file specified by spath to the destination specified by dpath
  • ln spath dpath : creates a new directory entry specified by dpath which points to the same file specified by spath
  • mkdir path : creates a new directory specified by path
  • rmdir path : removes an empty directory specified by path

Examples

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

2. newfs

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

Example

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

3. modfs

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] : the magic field of the superblock
  • superblock.size [val] : the size field of the superblock (total number of blocks)
  • superblock.nblocks [val] : the nblocks field of the superblock (number of data blocks)
  • superblock.ninodes [val] : the ninodes field of the superblock (number of i-nodes)
  • superblock.nlog [val] : the nlog field of the superblock (number of log blocks)
  • superblock.logstart [val] : the logstart field of the superblock (starting block number of log blocks)
  • superblock.inodestart [val] : the inodestart field of the superblock (starting number of i-node blocks)
  • superblock.bmapstart [val] : the bmapstart 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] : the type field of the inum-th i-node
  • inode.nlink inum [val] : the nlink field of the inum-th i-node
  • inode.size inum [val] : the size field of the inum-th i-node
  • inode.addrs inum n [val] : the block number of the n-th data block referred from the inum-th i-node
  • inode.indirect inum [val] : the block number of the indirect block referred from the inum-th i-node
  • dirent 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.

About

A set of simple utilities for manipulating xv6-riscv file system images

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published