File System Implementation Basics

My current project for an operating system course is the development and implementation of a basic file system. I read the chapters in our book on file systems, but I lost where to start. I know some necessary structures (file management blocks, a system-wide open file table, an open file table for each process, r + w buffers, a directory structure) and the operations I need to support (open, read, write, delete, create, close) .

I have been given a 10 megabyte "drive" to implement the file system inside. Any help with resources or direct answers would be greatly appreciated.

EDIT: here is a link to the destination https://www.dropbox.com/s/971ec21u3yn62wz/Laboratory%20Project%204_5%20Creating%20a%20File%20System.pdf

+4
source share
1 answer

You asked a very broad question. And it was not clear whether you need to implement a real file system, but now it seems that you need to implement the set of operations that your prof defined.

You write:

I know some necessary structures (file management blocks, a system-wide open file table, an open file table for each process, r + w buffers, a directory structure)

I think you're focusing on the wrong things. These are memory structures used by a real operating system to support efficient access to the file system.

  • file management blocks - your version can be very simple
  • public table of open files - you do not need this to support a single user
  • a table of open files for each process - you only need one, and it can be quite simple.
  • r + w buffers are performance improvements that are not strictly required at the time of assignment, and can be added later if necessary.
  • directory structure - oh, now you have done something.

I read the assignment designating the "directory structure" as referring to the structure on disk. And this is what you probably need to focus on. You are given a large storage unit, and you need to hand out small pieces. Therefore, you will need to write a memory allocator. The hard part really is designing structures on disk. You will need to keep track of which blocks are free. Files can be deleted, so you get holes. Two simple approaches use a bitmap or a list of contiguous free spaces. Whichever approach you choose, they will be part of your code where you want you to choose another.

You will also need a structure for tracking names. When a user creates a file, he calls it. To open the file later, it gives the same name. To support this, disk structures are required. There are other metadata: the last modified date (this requires a special task), file size, data location. You can use your allocator to get a place to store metadata.

Typically, for a fixed block at (or near) the start of storage, configuration information and pointers to other storage needed to load your file system are used.

For a good overview of Unix file system concepts, I can recommend the Design and Implementation of the FreeBSD Operating System by Marshall Kirk McKusick and George W. Neville-Neal, Chapter 8 Local File Systems.

http://www.amazon.com/Design-Implementation-FreeBSD-Operating-System/dp/0201702452

In particular, these subheadings:

  • 8.8. Local filestore
  • 8.3. Naming
  • 8.9. Berkeley fast filesystem

This allows you to think separately about the allocation and assignment of memory.

Your destination page contains some useful links. I had the opportunity to take a look at the Practical File System , which the author generously published on the Internet. I can specifically recommend the following chapters:

  • Chapter 4 BFS Data Structures
  • Chapter 6 Distribution Policy

Plus, maybe:

  • Appendix A File System Building Kit

Perhaps the problem you are facing is a project that seems large and overwhelming. It really helps to break it into smaller parts. If you are still lost, start by implementing the part that you understand best.

Let's get back to the specifics of your assignment. He mentions these file system limitations:

  • File size 16384 bytes can be
  • Distribution units or blocks on disk: 512 bytes .
  • Your total storage area is 2-10 MB

Limitations in this context are not bad, it’s good because they limit what you have to deal with and allow you to cut several angles. (I'm not saying anymore, because figuring out the details is the point of your assignment.)

If you are still stuck, you can read the source code in a simple file system such as FAT. Here is a fairly accessible description of FAT:

http://www.pjrc.com/tech/8051/ide/fat32.html

(Also check out Wikipedia.)

Here's a link to the CAT implementation of FAT for embedded applications:

http://ultra-embedded.com/?fat_filelib

The source code is only about 5 thousand lines.

Good luck.

+6
source

Source: https://habr.com/ru/post/1447086/


All Articles