st_size is the number of bytes of data that are stored in the file.
In other words, if you wanted to read the entire file in your program,
you would need to read "st_size bytes".

st_allocsize is the number of bytes of disk space that have been reserved
for the file.   Disk space is allocated in chunks, so most of the time the
st_allocsize will be larger than st_size.   (I'm not sure what terminology
OS/400 uses for these "chunks", I know in Windows you allocate things one
"cluster" at a time so if you have a 16k cluster size, a file thats
between one and 16384 bytes takes up 16k of disk space, a file thats
between 16385 and 32768 takes up 32k of disk space, etc.   OS/400 may
call these chunks "blocks" or "sectors" or "clusters", I don't know, but
the concept is the same as it relates to st_allocsize)

The one that baffles me is st_blksize.  OS/400 documentation says "the
size of a block of the file" or "the block size of the file".   but, if
that's the case, how can a file have 16k allocated and a block size of
32k?!

The documentation for FreeBSD claims that this field is "the optimal block
size for I/O."   Which implies to me that it's actually the number of
bytes read in each disk transfer from the filesystem to the operating
system.   This makes more sense to me, but that doesn't seem to be saying
what OS/400 is saying...  so I really don't know.

Fortunately, I don't need pay any attention to the "st_blksize" value in
any of my programs :)



On Thu, 10 Oct 2002, Tom Liotta wrote:
>
> Does anyone have a useful definition of stat's st_allocsize? I'm trying
> to handle some file size threshhold issues and I'm not sure if st_size
> or st_alcsize is best.
>
> Example... I have a program calling procedures to create and open a
> streamfile, write lines to it in a loop and close down when st_size
> exceeds 10K as reported by fstat() over the open file descriptor. Works
> fine. The program is purely a testing function to get a clear
> understanding of stat()/fstat().
>
> But I'm feeling uncomfortable about what's _really_ happening.
>
> When I run the test program specifying a path into the local /root file
> system, the program ends and reports the following values from the stat
> structure:
>
>   st_size = x'00002732' = 10034 bytes
>   st_allocsize = x'00004000' = 16384 bytes(?)
>   st_blksize = x'00008000' = 32768 bytes
>
> When I run the same program specifying a path through /QNTC to a Win2000
> Server system, the values are reported as:
>
>   st_size = x'00002732' = 10034 bytes
>   st_allocsize = x'00011000' = 69632 bytes(???)
>   st_blksize = x'00001000' = 4096 bytes
>
> (The path is retrieved from a data area so I can run the program easily
> over different file systems.) Okay, st_size and st_blksize seem
> reasonable in both cases. But what in the world is st_allocsize telling
> me? Is this a reference to space that is tied up by this object but not
> yet used for data? If I want to manage by object size, should I be
> totalling st_allocsize instead of st_size?
>
> Various 'net searches have given little but confusion since st_allocsize
> seems something less than "standard".
>
> Thank you.
>
> Tom Liotta
>



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.