StuBS
Loading...
Searching...
No Matches
Minix V3 file system layout

On a disk with Minix V3 the following is written one after the other

  1. boot block (1024 bytes)
  2. superblock (1024 bytes), see struct Minix_Super_Block in minix/minix.h
  3. bitmap inodes
  4. bitmap zonemap (zones here are the same size as a block)
  5. inodes, for the structure of an inode see struct Minix_Disk_Inode in minix/minix.h
  6. data in blocks. With mkfs.minix from Linux, blocks are 1024 bytes in size.
    • Alternatively, a data block can also contain directory entries, see struct Minix_Dirent in minix/minix.h.

Create Minix V3 file system image

On a Linux host:

$ dd if=/dev/zero of=~/file.img bs=1MiB count=1
$ mkfs.minix -3 ~/file.img # optional --inodes <number>
352 inodes
1024 blocks
Firstdatazone=26 (26)
Zonesize=1024
Maxsize=2147483647

Access as mounted file system

As root on Linux host:

$ losetup --find --show ~/file.img
$ mount /dev/loop0 /mnt/tmp
# Now create files etc
$ umount /dev/loop0
$ losetup --detach /dev/loop0

Access with the fstool

Since root access is not always available (e.g. in the Lab), there is a command line application that allows direct access to the image using FTP-like commands

$ cd tool
$ make
$ fstool ~/file.img
# Now edit files etc.
# "help" for further information

Include file system image in OOStuBS

ATA driver

Enables writing from OOStuBS to the image so that this data can then be read later in e.g. Linux.

In common.mk at QEMU add -drive file=./test_imgs/minix_sample_data.img,format=raw. Then the image - if it is the only one - is the master on the first port. Then, it is sufficient to write the following in the app.

#include "fs/harddisk.h"

Harddisk harddisk;

int error = VFS::mount("minix", &harddisk, "");

If you want to use a different port, you must add e.g. -drive file=./test_imgs/minix_sample_data.img,format=raw,bus=1,unit=1 to QEMU (see man qemu). Accordingly, use Harddisk harddisk(secondary_bus_slave); in the app. All other supported ports can be found in enum Drive under harddisk.h.

Initrd

The initial ramdisk does not allow writing. Pass the file system image as initrd via QEMUINITRD.

In the app:

#include "memory/multiboot.h"
external void *multiboot_addr;

multiboot_info_t *mb_info = (multiboot_info_t*)multiboot_addr;
if (mb_info->mods_count <= 0) {
    GuardedScheduler::exit();
}
multiboot_module_t *mod = (multiboot_module_t*)mb_info->mods_addr;
    void *initrd = (void *)mod->mod_start;
    size_t initrdsize = ((size_t)mod->mod_end) - ((size_t)mod->mod_start);
Ramdisk ramdisk(initrd, initrdsize);
int error = VFS::mount("minix", &ramdisk, "");

Header file (not recommended)

Does not allow writing. To create a header file so that the image can then be used via a variable, proceed as follows:

xxd -i minix_mkfs.img > minix_img.h

In the app:

#include "minix_img.h"
#include "fs/ramdisk.h"

static Ramdisk ramdisk(test_imgs_minix_sample_data_img, test_imgs_minix_sample_data_img_len);

int error = VFS::mount("minix", &ramdisk, "");

Working with files

The Virtual File System (VFS for short) offers some folder and file operations. For example, operations such as VFS::open(...), VFS::lseek(...) or VFS::stat(...) can be found there. More detailed descriptions of the methods can be found in the comments of vfs.h.