0

if i only have a file that contain 1 byte and another file_2 that contain 1 bytes in my hard drive , how are they separated is there a character that separate them like NULL for example like : 01001011NULL10100111

1 Answer 1

0

Disk space is assigned by clusters of blocks. The minimum cluster size might depend on the filesystem and the underlying block device. So, a one-byte file will use a whole cluster.

If you are running Linux, you can do the following:

# create a one-byte file
echo > /tmp/one_byte.txt

# list it
ls -l /tmp/one_byte.txt

# list its disk actual usage
du -h /tmp/one_byte.txt

So, your two files will get two groups of clusters. There is an index that keeps tracks of which files get which clusters, that's how they are stored. The clusters do not need to be contiguous.

6
  • i mean if for example a file is 3 bytes then it use 3 clusters but then after how does the computer know that the file data ends there and its not 4 clusters or more Jun 5, 2020 at 3:10
  • The file has a list of clusters. Each file gets clusters as needed, and its data will be written there. Once the cluster is full, the file gets another one. So, you have the list of clusters and the file size, to know just how much data in the cluster actually belongs to the file. A cluster size might be for example 4096 bytes. Jun 5, 2020 at 3:12
  • and the number of clusters that the file need is written to the hard drive too ? with the file data ? Jun 5, 2020 at 3:16
  • Yes, that is written in the directory. Same as a phone directory lists all people with their phone numbers, a file directory lists all files with their clusters.
    – Aganju
    Jun 5, 2020 at 3:21
  • 1
    in general, filesystem metadata records where files begin/end, the files names, create/mod dates, path, etc. NTFS uses $MFT table data, Linux uses inodes, etc, but the general idea is the same. An OS driver knows how to read the filesystem metadata to discern the what/where/when/who details associated with the file. most of the time, a filesystems metadata for the entire volume will be stored in one predictable place on disk, so the OS always knows where to find info about files so it doesn't have to search the disk for info which is slow. the binary data of the file is stored separately. Jun 5, 2020 at 4:59

You must log in to answer this question.

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