[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 |
|
---|
| 8 | #include "biosdefs.h"
|
---|
| 9 | #include "errno.h"
|
---|
| 10 | #include "fcntl.h"
|
---|
| 11 | #include "io.h"
|
---|
| 12 | #include "stddefs.h"
|
---|
| 13 |
|
---|
[7258c6a] | 14 | extern int16_t _badfd(void);
|
---|
| 15 | extern int16_t ClsFile(struct fcb *fcp);
|
---|
[0580615] | 16 | extern void _clsvol(void);
|
---|
[f40a309] | 17 |
|
---|
[7258c6a] | 18 | extern int16_t _fatmod, _dirmod;
|
---|
[f40a309] | 19 | extern struct bpb *_thebpb;
|
---|
| 20 | extern struct dirent _thedir[];
|
---|
[7258c6a] | 21 | extern uint16_t _thefat[];
|
---|
[f40a309] | 22 |
|
---|
| 23 | /* |
---|
| 24 |
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | /*
|
---|
| 28 | =============================================================================
|
---|
| 29 | _clsfat() -- write out the modified FAT
|
---|
| 30 | =============================================================================
|
---|
| 31 | */
|
---|
[0580615] | 32 |
|
---|
[f40a309] | 33 | void _clsfat(void)
|
---|
| 34 | {
|
---|
| 35 | /* write the primary FAT to disk */
|
---|
| 36 |
|
---|
| 37 | BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
|
---|
| 38 | _thebpb->fatrec, 0);
|
---|
| 39 |
|
---|
| 40 | /* write the secondary FAT to disk */
|
---|
| 41 |
|
---|
| 42 | BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
|
---|
| 43 | (_thebpb->fatrec - _thebpb->fsiz), 0);
|
---|
| 44 |
|
---|
| 45 | _fatmod = FALSE; /* FAT on disk now matches memory */
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /*
|
---|
| 49 | =============================================================================
|
---|
| 50 | _clsdir() -- write out the modified directory
|
---|
| 51 | =============================================================================
|
---|
| 52 | */
|
---|
[0580615] | 53 |
|
---|
[f40a309] | 54 | void _clsdir(void)
|
---|
| 55 | {
|
---|
| 56 | /* write the directory to disk */
|
---|
| 57 |
|
---|
| 58 | BIOS(B_RDWR, 1, _thedir, _thebpb->rdlen,
|
---|
| 59 | (_thebpb->fatrec + _thebpb->fsiz), 0);
|
---|
| 60 |
|
---|
| 61 | _dirmod = FALSE; /* directory on disk now matches memory */
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /* |
---|
| 65 |
|
---|
| 66 | */
|
---|
| 67 |
|
---|
| 68 | /*
|
---|
| 69 | =============================================================================
|
---|
| 70 | close(fd) -- close file 'fd'
|
---|
| 71 | =============================================================================
|
---|
[7258c6a] | 72 | */
|
---|
[f40a309] | 73 |
|
---|
| 74 | int16_t close(int16_t fd)
|
---|
[7258c6a] | 75 | {
|
---|
[f40a309] | 76 | register struct channel *chp;
|
---|
| 77 | register int16_t rc;
|
---|
| 78 |
|
---|
| 79 | if ((fd < 0) OR (fd > MAXCHAN)) {
|
---|
| 80 |
|
---|
| 81 | errno = EBADF;
|
---|
| 82 | return(FAILURE);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | chp = &chantab[fd]; /* point at the channel */
|
---|
| 86 |
|
---|
| 87 | rc = (*chp->c_close)(chp->c_arg); /* close the FCB */
|
---|
| 88 |
|
---|
| 89 | chp->c_read = 0; /* release the channel */
|
---|
| 90 | chp->c_write = 0;
|
---|
| 91 | chp->c_ioctl = 0;
|
---|
| 92 | chp->c_seek = 0;
|
---|
| 93 | chp->c_close = _badfd;
|
---|
| 94 |
|
---|
| 95 | if (_fatmod)
|
---|
| 96 | _clsfat(); /* write modified FAT */
|
---|
| 97 |
|
---|
| 98 | if (_dirmod)
|
---|
| 99 | _clsdir(); /* write modified directory */
|
---|
| 100 |
|
---|
| 101 | return(rc); /* return result of close */
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /* |
---|
| 105 |
|
---|
| 106 | */
|
---|
| 107 |
|
---|
| 108 | /*
|
---|
| 109 | =============================================================================
|
---|
| 110 | _filecl(fp) -- close file 'fp' at the BDOS level
|
---|
[7258c6a] | 111 | =============================================================================
|
---|
[f40a309] | 112 | */
|
---|
[7258c6a] | 113 |
|
---|
[f40a309] | 114 | int16_t _filecl(struct fcb *fp)
|
---|
| 115 | {
|
---|
| 116 | register int16_t rc;
|
---|
| 117 |
|
---|
| 118 | rc = ClsFile(fp); /* close the FCB */
|
---|
| 119 | fp->modefl = 0; /* mark the FILE closed */
|
---|
| 120 | return(rc);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /*
|
---|
| 124 | =============================================================================
|
---|
| 125 | _fd_cls() -- close all open files
|
---|
[0580615] | 126 | =============================================================================
|
---|
[f40a309] | 127 | */
|
---|
[7258c6a] | 128 |
|
---|
[f40a309] | 129 | void _fd_cls(void)
|
---|
| 130 | {
|
---|
| 131 | register int16_t fd;
|
---|
| 132 |
|
---|
| 133 | for (fd = 0; fd < MAXCHAN; ++fd)
|
---|
| 134 | if (chantab[fd].c_close NE _badfd)
|
---|
| 135 | close(fd);
|
---|
| 136 |
|
---|
| 137 | _clsvol(); /* write modified directory adn FAT */
|
---|
| 138 | }
|
---|