[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | close.c -- close a file for the Buchla 700 C I/O Library
|
---|
| 4 | Version 9 -- 1987-11-13 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[b28a12e] | 8 | #include "ram.h"
|
---|
[f40a309] | 9 |
|
---|
| 10 | /*
|
---|
| 11 | =============================================================================
|
---|
| 12 | _clsfat() -- write out the modified FAT
|
---|
| 13 | =============================================================================
|
---|
| 14 | */
|
---|
| 15 |
|
---|
[0580615] | 16 | void _clsfat(void)
|
---|
[f40a309] | 17 | {
|
---|
| 18 | /* write the primary FAT to disk */
|
---|
| 19 |
|
---|
| 20 | BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
|
---|
| 21 | _thebpb->fatrec, 0);
|
---|
| 22 |
|
---|
| 23 | /* write the secondary FAT to disk */
|
---|
| 24 |
|
---|
| 25 | BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
|
---|
| 26 | (_thebpb->fatrec - _thebpb->fsiz), 0);
|
---|
| 27 |
|
---|
| 28 | _fatmod = FALSE; /* FAT on disk now matches memory */
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | /*
|
---|
| 32 | =============================================================================
|
---|
| 33 | _clsdir() -- write out the modified directory
|
---|
| 34 | =============================================================================
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[0580615] | 37 | void _clsdir(void)
|
---|
[f40a309] | 38 | {
|
---|
| 39 | /* write the directory to disk */
|
---|
| 40 |
|
---|
| 41 | BIOS(B_RDWR, 1, _thedir, _thebpb->rdlen,
|
---|
| 42 | (_thebpb->fatrec + _thebpb->fsiz), 0);
|
---|
| 43 |
|
---|
| 44 | _dirmod = FALSE; /* directory on disk now matches memory */
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | /*
|
---|
| 48 | =============================================================================
|
---|
| 49 | close(fd) -- close file 'fd'
|
---|
| 50 | =============================================================================
|
---|
| 51 | */
|
---|
| 52 |
|
---|
[7258c6a] | 53 | int16_t close(int16_t fd)
|
---|
[f40a309] | 54 | {
|
---|
| 55 | register struct channel *chp;
|
---|
[7258c6a] | 56 | register int16_t rc;
|
---|
[f40a309] | 57 |
|
---|
| 58 | if ((fd < 0) OR (fd > MAXCHAN)) {
|
---|
| 59 |
|
---|
| 60 | errno = EBADF;
|
---|
| 61 | return(FAILURE);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | chp = &chantab[fd]; /* point at the channel */
|
---|
| 65 |
|
---|
| 66 | rc = (*chp->c_close)(chp->c_arg); /* close the FCB */
|
---|
| 67 |
|
---|
| 68 | chp->c_read = 0; /* release the channel */
|
---|
| 69 | chp->c_write = 0;
|
---|
| 70 | chp->c_ioctl = 0;
|
---|
| 71 | chp->c_seek = 0;
|
---|
[4a17aeb] | 72 | chp->c_close = _badfc;
|
---|
[f40a309] | 73 |
|
---|
| 74 | if (_fatmod)
|
---|
| 75 | _clsfat(); /* write modified FAT */
|
---|
| 76 |
|
---|
| 77 | if (_dirmod)
|
---|
| 78 | _clsdir(); /* write modified directory */
|
---|
| 79 |
|
---|
| 80 | return(rc); /* return result of close */
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /*
|
---|
| 84 | =============================================================================
|
---|
| 85 | _filecl(fp) -- close file 'fp' at the BDOS level
|
---|
| 86 | =============================================================================
|
---|
| 87 | */
|
---|
| 88 |
|
---|
[8973acd] | 89 | int16_t _filecl(io_arg arg)
|
---|
[f40a309] | 90 | {
|
---|
[8973acd] | 91 | struct fcb *fp;
|
---|
[7258c6a] | 92 | register int16_t rc;
|
---|
[f40a309] | 93 |
|
---|
[8973acd] | 94 | fp = (struct fcb *)arg;
|
---|
| 95 |
|
---|
[f40a309] | 96 | rc = ClsFile(fp); /* close the FCB */
|
---|
| 97 | fp->modefl = 0; /* mark the FILE closed */
|
---|
| 98 | return(rc);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | /*
|
---|
| 102 | =============================================================================
|
---|
| 103 | _fd_cls() -- close all open files
|
---|
| 104 | =============================================================================
|
---|
| 105 | */
|
---|
| 106 |
|
---|
[0580615] | 107 | void _fd_cls(void)
|
---|
[f40a309] | 108 | {
|
---|
[7258c6a] | 109 | register int16_t fd;
|
---|
[f40a309] | 110 |
|
---|
| 111 | for (fd = 0; fd < MAXCHAN; ++fd)
|
---|
[4a17aeb] | 112 | if (chantab[fd].c_close NE _badfc)
|
---|
[f40a309] | 113 | close(fd);
|
---|
| 114 |
|
---|
| 115 | _clsvol(); /* write modified directory adn FAT */
|
---|
| 116 | }
|
---|
[6262b5c] | 117 |
|
---|