Reputation: 42753
$path = "/////////.";
echo filesize( $path );
result is 4096
What the ... fail is this? from whence is this 4096
?
Upvotes: 3
Views: 119
Reputation: 157947
Answer:
$path = "/////////.";
although looking weird, the path refers to the root of the filesystem, the same as /
, what is a directory. On most filesystems a directory takes at least 4096 bytes to store (what is the size of one sector of a harddisk, the smallest allocation unit for most filesystems). The size can be even bigger if there are many files stored in that directory. But in the system root there are usually only the standard system directories, therefore just 4096.
Upvotes: 6
Reputation: 360592
A Unix "directory" is actually, essentially, just a text file that lists the inodes and names of all the "files" it contains. The directory "file" always starts out as the same size as the block allocation size of the file system - in your case that's 4096 bytes. Once enough filenames and inode numbers have been listed in that file to exceed 4096 bytes, another block will be allocated, and the directory file will now take up 8196 bytes, and so on.
Upvotes: 1
Reputation: 731
You're asking for the filesize of a directory, which in this case is 4,096 bytes. This number will vary for a directory depending on what sort of filesystem you're using and how many files are in it.
Upvotes: 2
Reputation: 10677
Every file has a minimum file size because it must take up at least one block of space, even if it is empty. It depends on the filesystem and how it was set up, but it appears that your default block size is 4096 bytes. Therefore each file entry must take up at least that much space. This include directories, since directories are technically files too in a Linux file system.
Upvotes: 1