How The File Size Is Limited on a Specific File System

how the file size is limited on a specific file system?

The file size limit of a filesystem is generally decided by the size of the variable containing its file size. In a filesystem where the size is defined as a 32 bit unsigned integer you will not be able to store a file larger than 2^32-1 (=4294967295) bytes in size. On many modern filesystems file size is commonly stored as 64 bits which gives a maximum file size of 2^64 (16 EiB), a very large number.

The maximum size of the filesystem itself is generally limited by the size of the addresses of the filesystem blocks times the filesystem block size. On old FAT16 filesystems the addresses were limited to 16 bits (=65536 unique addresses) and block (or cluster) size were limited to maximum 64kB, this led to the limit of 4GB maximum filesystem size, this was the reason that a larger variant, FAT32, was developed. On modern filesystems such as NTFS, ext4, btrfs, and many others the maximum filesystem size is very large and not likely to be hit in a long time. However, because of limitations in the implementations, there are some artificial limits that are lower than the actual format limit in some cases, for example NTFS has a filesystem size limit of 256TB (according to Wikipedia).

How to detect file system size limitations of individual files

You can detect the filesystem type on Windows with GetVolumeInformation

Limit file size on Dokan FileSystem

You can check the offset of the WriteFile function, if offset is bigger than 2GB - you return NtStatus.FileTooLarge.

Also, you should check the buffer.Length too, in case when you edit the file on the disk - it doesn't chop it into smaller buffered chunks, instead the entire file is put into a one buffer. In this scenario, you should find a way not to destroy the file, because the CleanUp will be called immediately after returning NtStatus.FileTooLarge from WriteFile method with info.DeleteOnClose set to true.

Find file size limit for a logical drive

Probably this will help GetVolumeInformation

See also this



Related Topics



Leave a reply



Submit