[comp.os.msdos.programmer] Help. End of Diskette VS EOF

levericw@clutx.clarkson.edu (Allanon) (08/09/90)

I would like to know if a C program will return different error codes if
it reaches the end of a file or reaches the end of a diskette, are these
two things the same or can I tell them apart.

If anyone has an established, or just working, way to save files across
volumes I would like to know, please E-Mail me.  I will post summary if
there is enough interest.

And, yes  now DOS backup does something like this, I am looking for
another way, I need to break .ZIP files across diskettes.

Thanks in advance.

Walden

---------------------------------------------------------------------------
Walden H. Leverich III               | Inet: levericw@clutx.clarkson.edu
     ECE Dept.                       | CServ: 73237,2212
 Clarkson University                 | SnailMail: 100 Market St.
                                     |            N.C.M. Apt 10
                                     |            Potsdam, NY 13676-1702
Just once, I wish we would encounter an alien menace that wasn't immune to 
bullets.    -The Brigader [Dr. Who]
--------------------------------------------------------------------------

jcmorris@mwunix.mitre.org (Joe Morris) (08/09/90)

In a recent article levericw@clutx.clarkson.edu (Allanon) writes:
>I would like to know if a C program will return different error codes if
>it reaches the end of a file or reaches the end of a diskette, are these
>two things the same or can I tell them apart.

Unless the application which writes the file leaves some out-of-band information
about the ending status, there is no way to distinguish the cases.  By 
definition a file ends when the forward pointer in the FAT is the EOF flag,
and DOS does not define the concept of a multi-volume file.  One could
probably be devised which would provide a multiplex interrupt hook to
let the writing program mark EOV instead of EOF, and let the reader know
which one terminated the read, but there's nothing there now.  (Microsoft,
are you reading this?)

Programs like BACKUP have a separate file for the out-of-band signals such as
disk number and EOF/EOV status.  DOS has nothing to do with the ability
of these programs to carry large files across multiple volumes.  

For your particular application what is needed is a special dump/restore type
of program.  There's gotta be someone who has written such a beastie...

cramer@optilink.UUCP (Clayton Cramer) (08/11/90)

In article <1990Aug9.004845.16663@sun.soe.clarkson.edu>, levericw@clutx.clarkson.edu (Allanon) writes:
> I would like to know if a C program will return different error codes if
> it reaches the end of a file or reaches the end of a diskette, are these
> two things the same or can I tell them apart.

I don't believe that there's any difference, as far as something
like fwrite cares.

> If anyone has an established, or just working, way to save files across
> volumes I would like to know, please E-Mail me.  I will post summary if
> there is enough interest.

> Walden H. Leverich III               | Inet: levericw@clutx.clarkson.edu

#include <stdio.h>
#include <malloc.h>
#include "std.h"

main(Argc, Argv)

int		Argc;
char*	Argv[];

	{
	long		BytesThisPartFile;
	long		BytesPerPart;
	int			PartNbr;
	char		OutFileName[40];
	FILE*		OutFile;
	FILE*		FileToPart;
	char*		Bytes;
	bool		MoreBytes = TRUE;
	int			BytesRead;
	
	FileToPart = fopen(Argv[1], "rb");
	sscanf(Argv[3], "%ld", &BytesPerPart);
	BytesPerPart *= 1000L;
	Bytes = malloc(1000);
	if((Bytes) && (FileToPart))
		{
		PartNbr = 0;
		sprintf(OutFileName, Argv[2], PartNbr);
		fprintf(stderr, "creating %s\n", OutFileName);
		BytesThisPartFile = 0L;
		OutFile = fopen(OutFileName, "wb");
		if(OutFile)
			{
			while(MoreBytes)
				{
				BytesRead = fread(Bytes, sizeof(char), sizeof(Bytes), 
								  FileToPart);
				fwrite(Bytes, sizeof(char), BytesRead, OutFile);
				BytesThisPartFile += sizeof(Bytes);
				if(feof(FileToPart))
					MoreBytes = FALSE;
				else if(BytesThisPartFile >= BytesPerPart)
					{
					PartNbr++;
					fclose(OutFile);
					sprintf(OutFileName, Argv[2], PartNbr);
					fprintf(stderr, "creating %s\n", OutFileName);
					BytesThisPartFile = 0L;
					OutFile = fopen(OutFileName, "wb");
					}
				}
			}
		fclose(OutFile);
		}
	}
-- 
Clayton E. Cramer {pyramid,pixar,tekbspa}!optilink!cramer
"Our Constitution is color-blind.  The arbitrary separation of citizens,
on the basis of race... is a badge of servitude wholly inconsistent with
civil freedom." -- Justice John Marshall Harlan (1896)