Re: fclose then fopen equivalent for stdout?
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Thu, 26 Oct 2006 22:13:41 +0000 (UTC)
In article <eholcr$efp$1@xxxxxxxxxxxxxxxxxxxxxxx>,
Serve Laurijssen <ser@xxxx> wrote:
"David Mathog" <mathog@xxxxxxxxxxx> wrote in message
news:eho4hq$6vb$1@xxxxxxxxxxxxxxxxxxx
A program of mine writes to a tape unit. Output can be either through
stdout or through a file opened with fopen(). When all the data is
transferred to tape the program needs to close the output stream so that
the tape driver will write a filemark on the tape.
what part of fclose exactly triggers the filemark writing? You probably
tried it, but it might be as simple as fflush
As others have noted, it is part of the device driver, not a standard
C function.
Someone referenced a Linux ioctl(); that's certainly a possibility on
appropriate versions of Linux.
As additional off-topic information about the difficulty of doing this:
On SCSI tape devices, the end-of-file marker or end-of-medium markers
are handled by specific operation codes. If your device driver does not
provide an ioctl() or equivilent, then you may have to issue the
SCSI-layer command yourself, if your system provides a generalized
SCSI device driver.
Also it might be worth keeping in mind that most Unix-type systems
provide a command "mt" with a "weof" option. But then there's the
difficulty that "mt" wants the name of a tape device on its command
line, and if you are using stdout then you don't know the tape device
name. Since you'd be presuming a unix-type system for this purpose,
you could fstat() to find the major and minor device numbers
associated with stdout, and iterate through the standard tape drive
name /dev subdirectory and hope for a match... and then mangle that
name to ensure that you include the appropriate name code for
non-rewind.
I wonder if the OP took into account that if the invoking user
redirected to an autorewind tape device (as is likely if they
hadn't been hit over the head several times with this issue),
that the fclose() equivilent that is proposed to be done would
trigger a tape rewind...
How would I handle it? Well, I would code the application to
take a tape device name as a parameter, and write to that instead
of stdout; perhaps I'd allow the semi-standard use of a single dash
to indicate standard output, but in that case I'd have the program
balk if it would have been expected to write several file marks.
No matter what you know about your own system, I don't think you
can reasonably be expected to be able to write multiple file marks
in a scenario such as
$ OurTapeBackups basedirectory | \
ssh -c operator@remotehost "dd of=/dev/tape"
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
.
- Follow-Ups:
- Re: fclose then fopen equivalent for stdout?
- From: CBFalconer
- Re: fclose then fopen equivalent for stdout?
- References:
- fclose then fopen equivalent for stdout?
- From: David Mathog
- Re: fclose then fopen equivalent for stdout?
- From: Serve Laurijssen
- fclose then fopen equivalent for stdout?
- Prev by Date: Re: in something not a structure or union
- Next by Date: Re: New to Programming
- Previous by thread: Re: fclose then fopen equivalent for stdout?
- Next by thread: Re: fclose then fopen equivalent for stdout?
- Index(es):
Relevant Pages
|
|