Re: format of unformatted file??
- From: nospam@xxxxxxxxxxxxx (Richard Maine)
- Date: Fri, 9 Feb 2007 08:58:57 -0800
gaurav <gauravgautam123@xxxxxxxxx> wrote:
It might sound a bit odd, but what is the format of an unformatted
file.? I mean to say that given a unformatted file, how does we
determine it is unformatted. There must be some header or
something.? that helps us to know that it is an unformatted one?
No, it is not true that there "must" be some header or something. In
theory, you are just supposed to know. There have existed operating
systems where this kind of information was stored in the directory, but
currently popular systems have been "dumbed down" a lot; the operating
system knows nothing about the file format.
If you want guarantees, there are none. But there are some pretty good
heuristics that will probably work well enough for the purpose. See Bob
Corbett's suggestion, for example.
Formatted files usually contain at least mostly text, plus the record
terminators. It is possible to put non-text data in a formatted file. I
have seen it done, but that's moderately rare. Unformatted files can and
often do contain both text and non-text data. However, in most current
implementations ("most" is a bit of an understatements; make it "almost
all"), the first 4 or 8 bytes of a sequential formatted file has a
record length header. That record length header could, in theory, be
indistiguishable from text, but that would be an awfully long record.
For the case of a 4-byte header, the record length would have to be
about 2**24 (16 million) or so before the high order byte was anything
other than zero; it would have to get a bit larger than that before it
would look like anything plausible as text. So if your records are known
to be of "reasonable" length, looking for a zero, or at least something
non-text, in the first 8 bytes is a reasonable heuristic.
The above heuristic applies only to sequential files. if the file in
question might be direct access, then pretty much all bets are off. In
fact, a direct access file could quite plausibly be openable as either
formatted or unformatted. The standard allows for files that can be
opened both ways. I have worked on systems where sequential files could
be open both ways (hi, Bob), but that is rare today. Direct access files
are usually openable both ways.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.
- References:
- format of unformatted file??
- From: gaurav
- format of unformatted file??
- Prev by Date: Re: C_F_POINTER, aliasing and performance
- Next by Date: Re: Error in decimal places?
- Previous by thread: Re: format of unformatted file??
- Next by thread: format of unformatted file??
- Index(es):
Relevant Pages
|
|