Re: format of unformatted file??



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
.



Relevant Pages

  • How to show .rtf file having pictures and text in PrintPreviewDialog ??
    ... How to open rich text formatted file in PrintPreviewDialog, the file is having word document like structure that has Title, Header, footed, text and pictures. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Altering the beginning of a file
    ... > I have a code which outputs data to a file as it runs. ... > like to be able to put that information in the file header. ... > tried rewinding, but that deletes all of the information already saved, ... be read using direct access, ...
    (comp.lang.fortran)
  • Re: Direct access to hadware
    ... I would like to know if exite some header ".h" in FreeBSD so ... that I can make a direct access to hadware in machine with C. ...
    (freebsd-hackers)
  • Direct access to hadware
    ... I would like to know if exite some header ".h" in FreeBSD so ... that I can make a direct access to hadware in machine with C. ...
    (freebsd-hackers)
  • Re: Portable record length
    ... The header contains 16 and 32 bit integer and 32 bit floating ... Direct access has fixed length records, ... This is not an issue as I have to conform to a format specification. ...
    (comp.lang.fortran)