Open System Services Programmer's Guide

/* create the OSS file before opening it with Guardian FILE_OPEN_() */
if ((fd = open(Grd_WRITE_file, O_WRONLY | O_NONBLOCK | O_CREAT |
O_TRUNC, S_IRWXU)) < 0)
{
printf("*** ERROR in Grd_WRITE_thread: open() of %s failed
w/error %d ***\n", Grd_WRITE_file, errno);
exit(0);
}
close(fd);
/******************************************************************/
/* now open the OSS file using FILE_OPEN_() so we can do */
/* Guardian nowait I/O */
/************************************************************ *****/
err = FILE_OPEN_(Grd_WRITE_file,
(short) sizeof(Grd_WRITE_file),
&fnum,
0 /* rd_wr */,
0 /* shared */,
1 /* nowait-depth */ ,
0 /* sync depth - NO CHECKPOINTING */,
0x0020 /* options - bit <10> set to open OSS pathname */);
if (err > 0)
{
printf("*** ERROR in Grd_WRITE_thread: FILE_OPEN_() of % failed
w/error %d ***\n", Grd_WRITE_file, (int) err);
exit(0);
}
/* register the fnum */
spte = spt_regFile(fnum);
if (spte != SPT_SUCCESS)
{
printf("*** ERROR in Grd_WRITE_thread: spt_regFile() failed
w/error %d ***\n", (int) spte);
exit(0);
}
/***************************************************/
/* Do Guardian nowait I/O in a thread aware manner */
/***************************************************/
while (currsize < WRITE_FILESIZE)
{
tag = spt_generateTag();
cc = WRITEX(fnum, iobuf, (short) IOSIZE, /* count read */, tag);
if (_status_ne(cc))
{
(void) FILE_GETINFO_(fnum, &err);
printf("*** ERROR in Grd_WRITE_thread: WRITEX() failed
w/error %d ***\n", (int) err);
exit(0);
}
else /* CCE - write successfully initiated */
{
spte = spt_awaitio(fnum, tag, -1, &count_written, &error, NULL);
if (spte != SPT_SUCCESS)
{
(void) CANCELREQ(fnum, tag);
printf("*** ERROR in Grd_WRITE_thread: spt_awaitio() failed
w/error %d ***\n", (int) error);
exit(0);
}
currsize += count_written;
}
} /* while */
Thread-Aware and Nonblocking OSS Functions 357