Re: Meaning of Size Directories

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/16/21 11:51 AM, John Reiser wrote:
> On 3/16/21, David Howells wrote:
>> John Reiser <jreiser@xxxxxxxxxxxx> wrote:
>>
>>> See the manual page "man 2 getdents".
>>
>> Um, which bit?  I don't see anything obvious to that end.
> 
> On that manual page:
> =====
> The system call getdents() reads several linux_dirent structures from the directory
> referred to by the open file descriptor fd into the buffer pointed to by dirp.
>    [snip]]
> On  success, the number of bytes read is returned.

But the original question was about the st_size returned stat, which is not
calling getdents.

Two different numbers, which mean 2 different things.

> =====
> 
> So the return value is related to the size of the directory; the sum of the values
> returned before End-Of-File should be quite close to the .st_size of the directory.

Again, that's not at all correct. Counter-example on ext4:

# stat -c %s dir
2547712
# ls -a1 dir
.
..
file
# strace -v -egetdents ls dir
getdents(3, [{d_ino=524289, d_off=4294967296, d_reclen=24, d_name=".", d_type=DT_DIR}, {d_ino=2, d_off=3358761300848251151, d_reclen=24, d_name="..", d_type=DT_DIR}, {d_ino=534290, d_off=9223372036854775807, d_reclen=24, d_name="file", d_type=DT_REG}], 32768) = 72

72 is not anywhere close to 2547712

> If a program is walking through the directory, reading all the entries via getdents64(),
> then .st_size of the directory is the only thing known in advance about the total size.

But it tells you nothing about how much is likely to be returned by getdents.

You should not use st_size to infer anything about the amount of data which will be
returned by getdents. POSIX does not define the meaning of st_size for directories,
and different filesystems can do wildly different things.

As Steve mentioned, st_blksize is your best hint for this purpose.

-Eric
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux