1

I know that the same file will have a different size in Linux and Windows because of how the two OS define kilobyte. I wanted to know whether a file within the same OS(say Windows) will have different sizes on two drives with a different file system (say NTFS vs FAT).

Utkarsh
  • 25
  • 1
  • 6
  • the allocated file size will be different if the file systems have different cluster size. See [Microsoft Support: Default cluster size for NTFS, FAT, and exFAT](https://support.microsoft.com/en-us/help/140365/default-cluster-size-for-ntfs-fat-and-exfat) for more – xmojmr May 11 '18 at 10:17
  • Thanks, that was useful. Don't have the option to upvote the comment yet (probably due to low points.) – Utkarsh May 11 '18 at 21:57

1 Answers1

1

Files generally have two file sizes.

  1. The size of the data in the file. This will be the same on most file systems.

  2. The amount of disk space required to store the file.

The latter includes space required for overhead and unused allocations. In the case of overhead, you can have things like links to file extents and some file systems include indices and record counts. That overhead can vary on file system.

In the latter, disk space is allocated in clusters (which are multiples of the block size). The sized file can have different numbers of clusters if the cluster size is different or something in the overhead (e.g. file fragmentation) causes the file to require more clusters.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • You said latter twice? Did you mean former? So, I'm looking at a file in windows and right click-> Properties gives me two pieces of info in the General tab -> Size: 204576 bytes and Size on disk: 204800 bytes. Size on disk is cluster based so it's divisible by 1024. Can I assume that the Size 204576 consists only of the size of the data + other file metadata (not the data the filesystem needs for itself)? Basically I'm unit testing file attributes and I was wondering if my code runs on different filesystems(pretty sure it will always be windows OS) should I get rid of size testing? – Utkarsh May 11 '18 at 21:51
  • I meant "latter" twice. – user3344003 May 12 '18 at 00:36
  • Okay, in that case and also looking at https://stackoverflow.com/questions/839625/where-does-windows-store-acls-and-do-acls-follow-a-file-from-one-machine-to-anot it seems to me that space allocated to metadata(name, attributes, permissions etc.) about file will be not counted towards the value that I see in "size" but it will count towards "size on disk", correct? Then, is it safe to assume that the value in size will remain the same both on say NTFS and exFAT? – Utkarsh May 12 '18 at 00:53
  • That depends upon the file system. On some systems, the file name is stored in a header and attributes are stored in a header that normally does not count towards the file size, even on disk. The data size should be the same on all systems. – user3344003 May 12 '18 at 00:58
  • Interesting. The last thing that remains to be confirmed is whether the "size" in file properties on windows is just an exact measure of data size or if it's more than that? Looking at https://technet.microsoft.com/en-us/library/hh148159.aspx I understand that I shouldn't trust either value for across file systems at least for the purpose of unit testing. Thanks – Utkarsh May 12 '18 at 01:25