11-08-07 06:27 PM
David Schwartz wrote:
> On Nov 5, 9:36 am, jombocito <jomboc...@gmail.com> wrote:
>
> I don't think it's defined.
Right. In POSIX.1 the description of fstat() says:
If fildes references a shared memory object, the implementation
shall update in the stat structure pointed to by the buf argument
only the st_uid, st_gid, st_size, and st_mode fields, and only the
S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file
permission bits need be valid. The implementation may update other
fields and flags.
>
> This may be for one of three reasons:
>
> 1) The system just puts in 1 for st_nlink when it's dealing with files
> that have no defined number of links.
That's not allowed by POSIX for most file types. Only shared memory
objects, typed memory objects and symbolic links need not have a
meaningful st_nlink. For all other file types it must be the number
of links (directory entries) that the file has. If it has no links,
st_nlink must be zero. (I seem to recall that Linux gets this wrong
for pipes.)
> 2) The way shared memory is implemented on this system results in
> shared memory segments always having exactly one link.
This would be typical for systems where shared memory objects are
visible in the file hierarchy. (If you could find the file and
execute "ln thefile anotherfile" you may find st_nlink is then 2.)
> 3) The code doesn't do anything special and this is just what winds up
> in there.
Or a slight variant of that: the value of st_nlink happened to be 1
before the fstat() call and the call did not set it.
--
Geoff Clare <netnews@gclare.org.uk>
[ Post a follow-up to this message ]
|