home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Module: flopbram.c - Track copy floppy B into a RAMdisk */
- /* */
- /* Programmer: George R. Woodside */
- /* */
- /* Date: February 22, 1987 */
- /* */
- /****************************************************************************/
-
- #include <stdio.h>
- #include <osbind.h>
-
- #define RMAGIC 0x1234543L
- #define E_CHNG -14L
- #define OHEAD 8704
-
- /****************************************************************************/
- /* */
- /* Structure returned from a Dfree() call */
- /* */
- /****************************************************************************/
-
- struct frees
- {
- long sp_clust; /* number of free clusters */
- long sp_totc; /* total number of clusters */
- long sp_ssize; /* sector size in bytes */
- long sp_csize; /* cluster size in sectors */
- };
-
- /****************************************************************************/
- /* */
- /* Structure of a BIOS Parameter Block */
- /* */
- /****************************************************************************/
-
- struct bpb
- {
- int byt_sect; /* bytes per sector */
- int sec_clust; /* sectors per cluster */
- int byt_clust; /* bytes per cluster */
- int dir_len; /* directory length */
- int fat_size; /* file allocation table size */
- int fat2_start; /* start of second copy of fat */
- int clust_start; /* start of data clusters */
- int clusters; /* number of clusters */
- int flags; /* parameter flags */
- long ram_start; /* RAMdisk only! RAM start address */
- long ram_magic; /* RAMdisk only! Magic number */
- };
-
- struct bpb *bpb_at; /* assign a pointer */
- long block[2176]; /* overhead buffer */
-
- /****************************************************************************/
- /* */
- /* Main - Test for a drive designator. */
- /* If valid, be sure the contents of the floppy */
- /* will fit into the active RAMdisk. */
- /* If they will, copy them. */
- /* */
- /****************************************************************************/
-
- main()
- {
-
- register int drive = 1; /* drive to read */
- register int sectors; /* number of sectors to read */
- register int limit; /* space on RAMdisk */
- register long start; /* save RAMdisk data start here */
- register long *from; /* copy from address */
- register long *to; /* copy to address */
-
- bpb_at = (struct bpb *)Getbpb(12); /* get RAMdisk BPB */
-
- if(bpb_at == (struct bpb *) NULL) /* if no RAMdisk, */
- {
- printf("flobpram: No active RAMdisk.\n"); /* log an error */
- exit(1); /* and punt */
- }
-
- if(bpb_at->ram_magic != RMAGIC) /* if wrong RAmdisk, */
- {
- printf("flopbram: Wrong RAMdisk running.\n"); /* log an error */
- exit(1); /* and punt */
- }
-
- start = bpb_at->ram_start; /* get data address */
-
- Getbpb(drive); /* insure drive is established */
-
- get_some(drive,1,block,17); /* read FATs and directory */
-
- limit = all_space(); /* get RAMdisk size */
-
- sectors = sp_used(block); /* compute sectors used on floppy */
-
- if(sectors > limit) /* if too much data, */
- {
- printf("flopbram: Too much data on disk.\n"); /* log an error */
- exit(1); /* and punt */
- }
- from = &block[0]; /* copy data from here */
- to = (long *)(start + 512L); /* copy data to here */
-
- for(limit = 0; limit < OHEAD/sizeof(long); limit++)
- *to++ = *from++; /* copy the overhead portion */
-
- get_some(drive,18,(start + (18L*512L)),sectors); /* read the data */
-
- Rwabs(0,0L,2,0,12); /* mark media as changed */
- } /* end main */
-
- /****************************************************************************/
- /* */
- /* Compute the number of sectors on the RAMdisk */
- /* */
- /****************************************************************************/
-
- all_space()
- {
- struct frees space; /* put parameters here */
- register int savail; /* sesctors available */
-
- Dfree(&space,13); /* get RAMdisk space structure */
- savail = space.sp_totc * space.sp_csize; /* compute sectors */
- return(savail); /* and return it */
- }
-
- /****************************************************************************/
- /* */
- /* Compute sectors used in data area of drive. */
- /* FATs are 12 bits on a floppy, or floppy compatible RAmdisk. */
- /* */
- /* Start at the end of the FAT table, and back up to the first */
- /* non-zero int. This is the last FAT used. Convert ints to bits, and */
- /* round up to insure a full FAT entry. Divide by 12 to get FATs, or */
- /* clusters, in use. Multiply clusters * 2 for sectors. */
- /* */
- /****************************************************************************/
-
- sp_used(dstart)
- long dstart; /* overhead start address */
- {
- register int *fatptr = (int *)(dstart + 1066L); /* end of FATs */
- register int i = 534; /* ints in a FAT table + 1 */
-
- while(*fatptr-- == 0) /* until an active entry, */
- i--; /* count down the FATs */
-
- i *= sizeof(int); /* convert to bytes */
- i *= 8; /* convert to bits */
- i += 11; /* round up for divide */
- i /= 12; /* number of FATs or clusters */
- i *= 2; /* convert FATs to sectors */
-
- return(i-4); /* FATs 0 & 1 do not exist, so -4 */
- }
-
- /****************************************************************************/
- /* */
- /* Read a portion of the floppy. */
- /* Using Rwabs eliminates track and sector counting, but requires */
- /* that Mediach not be set. Mediach is checked before this call. */
- /* */
- /****************************************************************************/
-
- get_some(drv,strt,buf,cnt)
- int drv; /* drive to read */
- int strt; /* starting sector number */
- char *buf; /* buffer address */
- int cnt; /* sector count */
- {
- register long reply;
-
- if((reply = Rwabs(0,buf,cnt,strt,drv) ) != 0L) /* if an error */
- {
- printf("flopbram: I/O error %D.\n"); /* log an error */
- exit(1); /* and punt */
- }
- }
-