Doesn't metadata occupy any size?

51

11

I put 4096 characters in a text file and save it.Since every character is 1 byte, Size of the text file must be 4K byte.As you see below that's OK:

enter image description here

I connect my flash memory to my computer. the free space on the flash memory is 1,717,518,336 bytes :

enter image description here

I created a copy of the file in my flash memory. And again take a look at the free space. it has 1,717,514,240 bytes free space :

enter image description here

Let see what is the difference :

1,717,518,336 - 1,717,514,240 = 4096 bytes


My question :

Q1:

As you see in the last picture above, the only space that the file occupy on the flash, is the space for its contents [characters].So where is metadata file ?

I mean, when I move the file to another computer, how it understand name of file, Owner of file, Date created and modified and ... ?

Doesn't it occupy any size?!!

Q2:

Can I see the metadata file in the flash memory?

enter image description here

Appreciate your time and consideration.

TheGoodUser

Posted 2014-08-04T10:41:51.990

Reputation: 1 045

10metadata would be contained in the filesystem itself. that isn't part of the file size reported by Windows. Furthermore FAT32 and NTFS metadata would be different. – Ramhound – 2014-08-04T10:47:02.660

@Ramhound when I move the text file to flash memory, its metadata file also move to flash memory, right? how I can see it? – TheGoodUser – 2014-08-04T10:53:47.790

You already know how to view the file's metadata. – Ramhound – 2014-08-04T11:05:06.027

@Ramhound I want to see the file that metadata store in it. and I want to edit it. Is it possible? I mean can I open it with a hex editor and ... ? – TheGoodUser – 2014-08-04T11:08:44.670

So edit it through the filesystem. This involves using Win32 programming. As explained before. A hex editor woudld only open the file, the metadata is handled by the file system, so you would have to modify the data through the file system. – Ramhound – 2014-08-04T11:12:16.370

@Ramhound Thank you. Is there any tool to see file system on the flash memory? – TheGoodUser – 2014-08-04T11:14:21.150

That is up to you to design. – Ramhound – 2014-08-04T11:21:22.520

6

Possible duplicate of How are the file metadata stored in Windows?, How are filenames stored?

– and31415 – 2014-08-04T13:06:35.347

An interesting exercise for you would be to open your text file with HxD and look around, this should give you many questions :) You may also be interested in reading more about "file system forensic analysis" or "data hiding" enjoy. Additionally, you can open your flash drive with something like FTK Imager. – Matthew Peters – 2014-08-04T20:57:06.550

1Aside from understanding OS internals (worthwhile in its own right), there is probably no reason to ever look at or modify such information unless you're writing a disk repair/recovery program. For normal use, you would never want to alter information at this level as it could easily undermine the integrity of the filesystem itself and of everything that uses it. – Joe – 2014-08-04T21:16:36.307

You know when you buy your 1TB harddrive, but windows only says that it's about 900GB? Yeah, that's where your metadata goes. – Cruncher – 2014-08-05T15:06:02.370

See How can I visualize the file system usage on Windows?

– Scott – 2014-08-05T22:22:32.087

3Short answer: It does take up space, but it's not counted as part of the file size. – user253751 – 2014-08-06T02:43:47.937

@Cruncher That's a different matter, actually. When you buy a 1 TB disk you're getting a total of 10^12 bytes, which correspond to about 931 GiB (when not formatted).

– and31415 – 2014-08-06T21:35:22.830

Answers

50

Yes, metadata occupies space. On NTFS it occupies 1024 bytes, to be specific. However, the information is not stored in the file, but in the master file table MFT. Specifically in MFT record #4 $AttrDef.

See this Technet article for details: table 3.5 holds all MFT records defined.

When a volume is formatted with NTFS, a Master File Table (MFT) file and other pieces of metadata are created. Metadata are the files NTFS uses to implement the file system structure. NTFS reserves the first 16 records of the MFT for metadata files.

NTFS creates a file record for each file and a directory record for each directory created on an NTFS volume. The MFT includes a separate file record for the MFT itself. These file and directory records are stored on the MFT. The attributes of the file are written to the allocated space in the MFT. Besides file attributes, each file record contains information about the position of the file record in the MFT.

Note that other file systems can and do deal differently with metadata.

EDIT: It has been pointed out in the comments section that this answer is missing the point because the OP asked for metadata on FAT32 filesystems, not NTFS. If I knew how, I would remove the "correct answer" attribute. Therefore I provide additional information that answers the question with regard to FAT32.

FAT32 saves simple metadata such as visibility or modification time for each file and folder in an entry in the parent folder of the the file or folder, creating a tree down from the root folder of the FS. As pointed out with regards to NTFS this is not a file but saved within the folder data structure. The entry originally was 32 byte large and contained the following attributes:

Name (8.3) xxxxxxxx.yyy. (88 bits)

Attribute byte (8 bits of information, described later in this section).

One reserved byte.

Create time (24 bits).

Create date (16 bits).

Last access date (16 bits).

Two reserved bytes.

Last modified time (16 bits).

Last modified date (16 bits).

Starting cluster number in the file allocation table (16 bits).

File size (32 bits).

The list was taken from this Microsoft Technet article and pertains to FAT16. Since the cluster size of FAT32 can be 32 bits and the name of files can be longer than 8.3 the table is not wholly accurate. To accomodate long file names and larger disks FAT32 modifies some behaviour which can be read up in the Wikipedia here but the basic idea holds.

bjanssen

Posted 2014-08-04T10:41:51.990

Reputation: 2 289

Thank you dear friend. Can I see the file that metadata store in it? and edit it with a tool, for example with a hex viewer? – TheGoodUser – 2014-08-04T11:06:07.033

2

You can use the Sysinternal suite's NTFSinfo to look at Metadata and find any extends. You can download it here: http://technet.microsoft.com/en-us/sysinternals/default There are several metadata editors around, but I can't recommend any one because I haven't used them.

– bjanssen – 2014-08-04T11:48:23.873

9@TheGoodUser-Sp metadata, on NTFS at least, isn't stored in "a file" in the conventional sense, which is what I get the impression you are looking for. There isn't something tucked away in the \windows folder somewhere that we're all just not telling you about; file metadata is an integral part of the filesystem itself. – Rob Moir – 2014-08-04T13:59:54.893

2

In this case the Flash Drive is formatted as FAT-32. So the metada are stored in File Allocation Table (FAT) http://en.wikipedia.org/wiki/File_Allocation_Table

– jnovacho – 2014-08-05T07:41:41.980

2It's important to note that the allocation tables for NTFS and FAT are preallocated. It differs from format to format, but several sectors are usually occupied with empty preallocated blocks that are to be used for storing metadata in order to reduce fragmentation. – Kaslai – 2014-08-05T13:49:52.803

2What makes you think metadata is fixed size? The access control list certainly can vary quite a lot in complexity; I fail to see how it can always fit in 1024 bytes (along with all the other metadata like access and modification times) – Ben Voigt – 2014-08-06T00:01:54.540

@Ben Voigt: I see where you are coming from. That's bad phrasing on my part, so let me clarify. The metadata record in the MFT is always 1024 bytes, if used or not. The actual used space is tracked in the Allocated Size attribute. If the metadata is smaller than 1024 bytes the record is padded, if it is larger another record is created and linked to the now primary record. You can read a treatment of this in the Wikipedia article https://en.wikipedia.org/wiki/Ntfs#Attribute_lists.2C_attributes.2C_and_streams In summary you are right in saying there can be more metadata than fits in 1KB.

– bjanssen – 2014-08-06T05:31:04.237

@RobM: Technically $MFT is a file in the root directory, isn't it? ntfs-3g allows one to read it under Linux. – user1686 – 2014-08-06T16:09:55.867

1@grawity yes you're right but I think referring to it in that manner in the context of this question is just going to confuse the OP. – Rob Moir – 2014-08-06T17:04:53.967

For completeness, note that in addition to the information added to the MFT, there is also information added to the directory entry. (As with the MFT, however, most of the time the space for this will already be reserved.) – Harry Johnston – 2014-08-06T20:57:25.650

But this answer is irrelevant. He's using small capacity flash storage. In the overwhelming majority of cases this is USB memory sticks, SD Cards, Cameras, etc. That'll be formatted with FAT, not NTFS. FAT - no user access control, no permissions, no metadata requirements for storing identity, access control, etc. If he was looking at a 2TB capacity, we could (today) be fairly sure it was a disk, and is probably NTFS or HFS. But at 2GB FLASH, 99%+ likely to be FAT. – JezC – 2014-08-07T08:51:54.360

@JezC: You are right, I missed this part. Even the screenshot states FAT32. So I have added some information with regards to saving simple metadata in FAT-FS. – bjanssen – 2014-08-09T09:03:09.023

FYI, I don't think $AttrDef contains what you think it contains. – user541686 – 2016-12-29T04:58:33.870

26

Doesn't it occupy any size?!!

Yes, but it's a small entry in a large pre-allocated block. That block is counted in the "used" portion of your disk. Adding an entry inside that block doesn't require the block to be expanded.

Depending on the filesystem, eventually the block will be filled and extended somehow after a lot of filenames are added.

Can I see the metadata file in the flash memory?

Not easily

As Ruslan and Blorgbeard commented. You can install a hex viewer such as HxD which will allow you to view (and edit - be very careful) the raw filesystem data. But you'll have to do the interpretation yourself concerning which bytes belong to which filesystem structures. For that you would need some good documentation of the specific filesystem used on the flash disk. FAT32 is likely to be simpler to understand than any of the many variants of NTFS. See Understanding FAT32 Filesystems for example.

RedGrittyBrick

Posted 2014-08-04T10:41:51.990

Reputation: 70 632

Not easily!? So I can? :D how? – TheGoodUser – 2014-08-04T11:26:45.720

3@TheGood If deprived of Google, I'd probably start by booting Linux and using dd to copy the raw flash filesystem to a file on another disk then use a hex-viewer to examine it in conjunction with a good reference-work on the specific filesystem (if not proprietary and undisclosed). I might make a metadata change with touch, repeat the dd and use a binary diff. – RedGrittyBrick – 2014-08-04T11:47:00.293

1Good thing I'm not deprived of Google. – Cthulhu – 2014-08-04T12:50:48.030

5@Cthulhu: The old ones have no need of the necronomicon. fhtagn. – RedGrittyBrick – 2014-08-04T15:06:50.077

2There's no need to change OS to use a hex-viewer on a hard drive directly. Just use a decent hex viewer. (It seems even hiew can do it, but I'm not sure since I was on windows long ago). – Ruslan – 2014-08-05T07:51:11.480

1HxD will definitely do it, on Windows. Extras menu, Open Disk. – Blorgbeard is out – 2014-08-06T02:39:29.657

@Blorgbeard, Ruslan: Thanks, I've updated the answer to include your suggestions. – RedGrittyBrick – 2014-08-06T09:05:06.807

7

Metadata is not stored (nor reported by usual file management tools) as files, it is stored on filesystem's data on disk.

Depending on the nature / version of the filesystem, each entry will take some amount of disk space to represent the metadata information.

Moreover alongside the space allocated in the Master File Table, some filesystems will also keep journal about files change (taking extra space), and some filesystems can even be extended with extra fields containing special purpose metadata.

So technically metadata takes disk space, but it is not taken in account by most file management utilities which works calling system's API that query the filesystem for file space, not for metadata space.

And this abstraction is only the tip of the iceberg, as filesystem itself works on an abstraction of underlying physical disk space, provided by low level disk routines, so actually only the disk's internal logic will know how many actual memory positions are available for higher levels and how many are marked as not reliable, reserved, or used for checksum.

Dice9

Posted 2014-08-04T10:41:51.990

Reputation: 191

3

The metadata depends on the file system. The most basic file systems usually used on exchangeable media is based on a DOS file system (FAT). DOS doesn't have users, and permissions. Or, more correctly, some of that information is carried in the 8th data bit of the file name. The only resource overhead that is used in a basic DOS FS is to account for the blocks of the file, or the directory that it is in - and that block is probably already committed for handling ".", already. IOW, adding an empty file wouldn't add another bit of storage, but it would change some existing consumed and allocated bits.

When you use more advanced file systems, with journalling and users, you get metadata, and journal entries and possibly a forensic chain to recover previous file versions, etc. Then a small file can explode in used storage.

So, check the FS type. If it is FAT, then you probably don't have a user recorded in metadata on the media. Hence... no space used. :)

A good example of a FAT FS is an open source implementation - and you can see that the list of operations available does not include "get/set user" and "check access by user". No identity = no storage of that identity.

JezC

Posted 2014-08-04T10:41:51.990

Reputation: 550

2

As you see in the last picture above, the only space that the file occupy on the flash, is the space for its contents [characters].So where is metadata file ?

The "metadata file" is the directory that contains the file. That's basically what a directory is -- a collection of metadata describing the contents of the directory.

I mean, when I move the file to another computer, how it understand name of file, Owner of file, Date created and modified and ... ?

Doesn't it occupy any size?!!

Yes, in the directory. In most filesytems, the same file can have two different names if it's linked into two different directories.

Can I see the metadata file in the flash memory?

If your filesystem supports it, you can see it by looking at the size of the directory.

David Schwartz

Posted 2014-08-04T10:41:51.990

Reputation: 58 310

2

Where are metadata kept?

When we talk about metadata, there are two types of metadata.

The first type includes created date, last modified date, last accessed date. Depending on file system (i.e. NTFS / FAT / Ext3 etc...) there will be different "metadata" available, for example Windows owner and permission on NTFS.

The first type applies to all files, e.g. the .txt file in your example.

All file systems pre-allocate spaces to contain these metadata at the Master File Table (MFT for NTFS, some other names for other file system), which is not directly accessible by users. Since MFT is not counted as part of drive capacity, there is no "additional" storage space required anyway.

The second type of "metadata" is defined by the file type or application. For example, Office documents keeps "Author", "Subject" and other metadata; JPEG images keeps a set of EXIF data including "date picture taken", "camera model", "shutter speed"; while MP3 sound contains "album", "track #", "bitrate"...

The second type DOES take up additional space, because these "metadata" forms part of the file.


Different size in different drive

When your text file is on C:\ it takes up 4K. It becomes 1K in size when you put it on your flash drive H:\. This is because different "block size" for the different partitions.

Files are allocated spaces in block. Therefore, on a file system of block size 4K, 1 byte is allocated 4K while 4,097 bytes (4K + 1 byte) is allocated 8K.

Apparently your C: is formatted with 4K block size while H: is formatted with 1K block size, resulting in the difference.

Kenneth L

Posted 2014-08-04T10:41:51.990

Reputation: 12 537

When I copy a blank text file to a flash memory, its metadata also will moved to flash memory. now, Is there any way , in Linux for example, to see the metadata file? in binary for example. – TheGoodUser – 2014-08-06T05:58:16.537

Whether the metadata is copied depends on how you do it. For example robocopy gives you option whether to copy timestamps, attributes, owner information, access control lists (ACL) etc. It also depends on whether the file system on your flash memory supports it (e.g. FAT32 does not keep owner info and ACL so they are discarded anyway). Metadata is not in the form of a file so you cannot see the raw data; if you want to see low level things you may need dd in Linux but how to interpret them is another story. – Kenneth L – 2014-08-06T06:23:14.493