7

I noticed that renaming a file doesn't change its hash. I also noticed that creating an empty file gives a file of zero bytes, yet it has a filename.

Since the filename seems to travel with the file across devices I was wondering what exactly is the filename? How come it can be changed without altering the hash, and why doesn't it seem to take up any space?

I guess if I understood how they are stored, it would answer those questions.

Louis Waweru
  • 25,409
  • 45
  • 137
  • 203

1 Answers1

12

In NTFS, all file data — file name, creation date, access permissions (by the use of access control lists), and contents — are stored as metadata in the Master File Table. In Windows world, you might also have heard about the File Allocation Table. Other file systems have other names and structures.

All file systems work this way. A certain amount of space is reserved, usually at the very beginning of the disk, right after the boot sector. That space contains a data structure which contains the information to retrieve the files.

The Master File Table is not a file. It is just organized data. As a matter of fact, files are just data that have a beginning and a size, stored in an MFT, FAT, or similar. When you change the file name, you do not change the file, just some bytes in the Master File Table.

Since the name and attributes are different from the data, you can download a file stored on a Linux server to a Windows machine. The data is transferred, not the metadata. You have to name and select a location for the file yourself (although the server and browser can hint you the original file name).

Pang
  • 1,017
ixe013
  • 990