A Shared Memory File System (part 3)

In previous blog posts, I have presented the idea of a shared memory file system, that is FAT based. The FAT consists of a Boot Block and a Disk Block Table. I will finish up this discussion when I describe:

  • Directory Blocks.
  • Extending a FAT in place.
  • File Locking.

Shared Memory File System Directory Blocks

So if a disk block is used, then it is either a directory or a file. So how do we know if a disk block is a directory or a file? We use the next to last most significant bit in the disk block number as a directory flag. The most significant bit is the sign bit. On a 32 bit machine, the directory bit would be bit 30, counting bits 0 – 31.

If the disk block is a directory, then the disk block contains the following data structure. Note: a directory can consist of multiple disk blocks.

*) Magic number.

Used to detect data corruption.

*) File array.

This array contains an entry for each file in this directory.
This array consists of:

o) Magic number.

To help detect directory corruption.

o) File name.
o) File size.

In bytes.

o) First disk block for the file.

o) File creation time.

o) File modification time.

o) File mutex.

Protects the Locked field.

o) File locked?

Is the file locked?

Extensible

As previously stated, the Boot Block is extensible. It can reside on more that one disk block. So why do we allow this? So that the file system is extensible in place.

To extend a file system in place we have to add the new disk blocks to the Disk Block Table. If the current table is not big enough, then we first have to increase the size of the Boot Block. This process is straight forward and simple.

File Locking

One of the goals for our shared file memory system is to allow multiple users to be able to access the file system at the same time. In fact, we want multiple users to be able to access the same file at the same time. We enable this feature by the fields {File Mutex, File Locked}.
The File Locked field indicates if the file is locked. The File Mutex field protects the File Locked field from corruption.

So here is how you lock a file:

1) Lock the File Mutex.

2) If File Locked?

UnLock the File Mutex.
Sleep.
Goto step 1.

Here is how you unlock a file:

1) Lock the File Mutex.

2) Set File Locked to False.

3) UnLock the File Mutex.

Please note that the locking mechanism defined here in is very simple. It is easy to use but can result in performance problems. I will describe a more complicated locking mechanism that addresses these problems in subsequent blog posts.

So there you have it. You now know how to properly construct a Shared Memory File System.