1

I am writing a file system for my operating system and am doing research on existing file systems before I start designing my own. I came across some slides about the System Five File System and am pretty confused on how blocks of files are found.

For example, if I wanted to find block 5 of the file represented by inode 12...how would I do this?

Can someone explain (at a high level) how to find a block of a file represented by an inode?

closed as too broad by cas, Jeff Schaller, Anthon, garethTheRed, user34720 May 23 '16 at 10:43

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2

Structures fetched from Ultrix 3.0 v7 of restor so variations can occur:

ftp://ftp.uvsq.fr/pub/tuhs/PDP-11/Distributions/dec/Ultrix-3.0/v7restor/include/sys/

The s5fs is rather archaic but ...:

Disk layout could be something like:

[B][S][Inode List][ Data Blocks ]
 |  |
 |  +-- Super Block
 +----- Boot Area

The Super Block holds data for the file system. The Inode List is an array of inodes holding data for files (including directories) and pointers to the data residing in the Data Blocks.

The Inode List is of fixed size.

Structure of the Super Block on disk:

struct  filsys {
    unsigned short s_isize;  /* size in blocks of i-list */
    daddr_t s_fsize;         /* size in blocks of entire volume */
    short   s_nfree;         /* number of addresses in s_free */
    daddr_t s_free[NICFREE]; /* free block list */
    short   s_ninode;        /* number of i-nodes in s_inode */
    ino_t   s_inode[NICINOD];/* free i-node list */
    char    s_flock;         /* lock during free list manipulation */
    char    s_ilock;         /* lock during i-list manipulation */
    char    s_fmod;          /* super block modified flag */
    char    s_ronly;         /* mounted read-only flag */
    time_t  s_time;          /* last super block update */
    daddr_t s_tfree;         /* total free blocks*/
    ino_t   s_tinode;        /* total free inodes */
    short   s_m;             /* interleave factor */
    short   s_n;
    char    s_fname[6];      /* file system name */
    char    s_fpack[6];      /* file system pack name */
    long    s_unique;        /* saved unique number (sys unique) */
};

Structure of a Inode on disk:

struct dinode
{
    unsigned short  di_mode; /* mode and type of file */
    short   di_nlink;        /* number of links to file */
    short   di_uid;          /* owner's user id */
    short   di_gid;          /* access control file (was gid) */
    off_t   di_size;         /* number of bytes in file */
    char    di_addr[40];     /* disk block addresses */
    time_t  di_atime;        /* time last accessed */
    time_t  di_mtime;        /* time last modified */
    time_t  di_ctime;        /* time created */
};

di_mode would tell you if it is a regular file, directory, named pipe etc. and what permissions it holds.

You are specifically asking about the di_addr. This holds 13 three byte addresses, total of 39 bytes. The last byte is used by some systems as file creation mask for directories.

The lib.c file at root of the restor source, (see top), holds functions for convert longs to and from 3-byte disk addresses.

The first 10 are direct pointers, 11-13 are indirect pointers.

As you request block number 5, that would be a direct pointer. Read it's value and read the data from that block.

Another ref: http://erdos.csie.ncnu.edu.tw/~ccyang/Os2/Slides/chapter9.ppt

Not the answer you're looking for? Browse other questions tagged or ask your own question.