FILE_BUSY

Help,


I’m trying to determine if a file is busy, but I’m having
difficulty in finding how to do it. In the file fsys.h is
a #define for _FILE_BUSY. The file says that they are
bits in the d_status element of the dir_entry structure.

I have used opendir and readdir to get the file names in
the directory but a file that I know is being written
to never tests as _FILE_BUSY.

Could someone educate me on the correct method to test
for a file being busy?

Thanks
Rick

“Rick Mullholand” <rick@node180.ctc.cummins.com> wrote in message
news:mailman.976567395.4354.qdn.public.qnx4@qnx.iaware.org

I’m trying to determine if a file is busy, but I’m having
difficulty in finding how to do it. In the file fsys.h is
a #define for _FILE_BUSY. The file says that they are
bits in the d_status element of the dir_entry structure.

I have used opendir and readdir to get the file names in
the directory but a file that I know is being written
to never tests as _FILE_BUSY.

Could someone educate me on the correct method to test
for a file being busy?

[non-QSSL response]

I have noticed that _FILE_BUSY will not work if your file is on
a node other than the node that is testing the flag. It also appears
not to work reliably on a local node, but I’ve never been able to
discover the rules for its validity. I don’t believe that _FILE_BUSY
is POSIX, and I have not encountered any other OS that offers
it (that I’ve found, anyway). I think the proper method to test for
a file being busy is to change your algorithm so that you do not
depend on this flag. “Busy” is, after all, a somewhat undefined term
when you consider that there is caching both in Fsys and in the user
program. Also, busy for read? Busy for write?

Just sharing my experience. I’d like to hear the official answer
as well.

Andrew

Andrew Thomas <andrew-s-thomas@home.nospam.com> wrote in message
news:915qlj$4ih$1@inn.qnx.com

“Rick Mullholand” <> rick@node180.ctc.cummins.com> > wrote in message
news:> mailman.976567395.4354.qdn.public.qnx4@qnx.iaware.org> …
I’m trying to determine if a file is busy, but I’m having
difficulty in finding how to do it. In the file fsys.h is
a #define for _FILE_BUSY. The file says that they are
bits in the d_status element of the dir_entry structure.

I have used opendir and readdir to get the file names in
the directory but a file that I know is being written
to never tests as _FILE_BUSY.

Could someone educate me on the correct method to test
for a file being busy?

[non-QSSL response]

I have noticed that _FILE_BUSY will not work if your file is on
a node other than the node that is testing the flag. It also appears
not to work reliably on a local node, but I’ve never been able to
discover the rules for its validity. I don’t believe that _FILE_BUSY
is POSIX, and I have not encountered any other OS that offers
it (that I’ve found, anyway). I think the proper method to test for
a file being busy is to change your algorithm so that you do not
depend on this flag. “Busy” is, after all, a somewhat undefined term
when you consider that there is caching both in Fsys and in the user
program. Also, busy for read? Busy for write?

Just sharing my experience. I’d like to hear the official answer
as well.

Andrew
\

This isn’t official, but it may help?

The following is a portion of a previous thread, when I had the same
questions.
I had the same problem when I was waiting for a file to be completely ftp’ed
to me. I used the ‘struct stat’ in the stat() function and used the
st_status and _FILE_BUSY, but it wasn’t 100%. What I ended up doing in
addition to this check is to save the last modification time (st_mtime), and
then check it again after a few seconds to see if it’s changed. If the file
isn’t busy and hasn’t changed I proceeded. In my case however, I could wait
10 seconds without a problem.
(Qnx2 did have a file write-busy bit, as I recall.)
ms…


Bit 0x04 is indeed _FILE_BUSY, but it doesn’t quite mean that. It means
that the file has allocated physical disk space beyond the logical EOF.
It will be cleared when the file is close()d (but also when the file is
ltrunc()d or fsync()d). Also, if the file already exists and was not
opened O_TRUNC (i.e. there are disk sectors already associated with the
file) then this bit will never be set initially. So, depending on the
operation of ftp, this may indeed work for you (although
partial/restarted
transfers may be a problem?), although there isn’t an approved/official
mechanism to do this in general that I know of, sorry…

Rick Mullholand <rick@node180.ctc.cummins.com> wrote:

Help,



I’m trying to determine if a file is busy, but I’m having
difficulty in finding how to do it. In the file fsys.h is
a #define for _FILE_BUSY. The file says that they are
bits in the d_status element of the dir_entry structure.

I have used opendir and readdir to get the file names in
the directory but a file that I know is being written
to never tests as _FILE_BUSY.

The _FILE_BUSY flag does not mean that a file is open for write
or anything useful like that. My understanding is that bit indicates
that there are blocks written to that file in Fsys’ cache that have
not yet made it to disk. “_FILE_DIRTY” might have been a better
name for the particular bit. You’ll note that _FILE_BUSY is in
fsys.h (internal QNX4 Fsys definitions) not in any standard header.

The actual comment with the bit is “/* Indicates file grown or truncated */”.

Could someone educate me on the correct method to test
for a file being busy?

There is no prescribed method – this is where you should be looking
at using advisory file locks between the processes involved or something
similar. If you don’t have control of the code for all the processes
involved, you may have to use the mtime (modification time) trick that
somebody suggested elsewhere in this thread.

-David

From: steve@grapevinetelecom.co.uk

I had a similar problem trying to decide when inbound ‘ftp’ files were
complete so this is what I ended up with [it might be overkill, but it
works!]…

:
:
lstat (pathn, &fdata.d_stat);
if ((fdata.d_stat.st_status & _FILE_USED) &&
(fdata.d_stat.st_status & _FILE_MODIFIED) &&
!(fdata.d_stat.st_status & _FILE_BUSY) &&
fdata.d_stat.st_size != 0)
{ process it…!
:
:
}

ie. if the file exists and has been modified and is not currently busy and
is not 0-length, DO IT! Hope this helps.


“Rick Mullholand” <rick@node180.ctc.cummins.com> wrote in message
news:mailman.976567395.4354.qdn.public.qnx4@qnx.iaware.org

Help,


I’m trying to determine if a file is busy, but I’m having
difficulty in finding how to do it. In the file fsys.h is
a #define for _FILE_BUSY. The file says that they are
bits in the d_status element of the dir_entry structure.

I have used opendir and readdir to get the file names in
the directory but a file that I know is being written
to never tests as _FILE_BUSY.

Could someone educate me on the correct method to test
for a file being busy?

Thanks
Rick