0

Not sure if off-topic, but I believe it is the job of a filesystem to recognize blocks of bits/bytes and call these "files" just to make it more convenient to access data better, and packed as a unit, as opposed to an ocean of flip-flop States with no order. But how, more or less, is this done? Does the filesystem (any in question) map out or keep a reference of the offset between data start/data end, does it use an identifier for a checked address or something, etc.? I have programming knowledge, but this low-lovel concept has puzzled me surely. I know most filesystems are written in HLL (like C, C++, D, etc.), but how exactly, at the lowest level, do they perfectly keep track of everything from sector/block 1 of file "A" all the way to the last range?

1

2 Answers 2

0

hard disks are arranged in clusters of 512 or 4k bytes of data. Each of these clusters is referred to as a block.

At the lowest level, an OS is going to issue commands like read from block 4 or write to block 11. The SATA specification defines exactly how these commands work and what commands should be available. These low level commands are abstracted into higher level commands which file systems interface with.

A file system provides a mapping of files to disk blocks. A very basic file system (like MS-DOS FS) would start by having a partition table (at block 0, the "superblock") which allows you to define logical disks on top of a physical disk. Each logical disk would then start with a single entry which defines a directory. Each of these directory entries would contain a list of files and which block points to that files.

For each of the files, the first block would be a meta-data structure which defines what the file is (file, directory, link, or something else), how big it is, what it's access permissions are, and a list of blocks where the file data resides.

0

File systems do not recognize files. Instead, they define what a

Start with an empty disk, and ask the file system to create a file there. It will:

  1. Decide whether your file name and/or path syntax is correct
  2. Determine the location within the directory structure where your file will be logically located
  3. Decide whether another file of the same name is already present at that location, and if so, whether to overwrite it, append to it, or return an error.
  4. Create one or more entries in the file system metadata indicating that the file is present within the desired parent directory
  5. Allocate disk space for the bytes making up the file
  6. Write the byte of the file into the allocated disk space
  7. Change the metadata to indicate the locations of all the blocks of the file, and say where the EOF is (if it's a sequential file).

None of that requires the file system to "recognize" anything except for the same data structures that it created in the first place.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .