[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 |
|
---|
| 14 | extern int _badfd(), ClsFile(), _clsvol();
|
---|
| 15 |
|
---|
| 16 | extern int _fatmod, _dirmod;
|
---|
| 17 | extern struct bpb *_thebpb;
|
---|
| 18 | extern struct dirent _thedir[];
|
---|
| 19 | extern unsigned _thefat[];
|
---|
| 20 |
|
---|
| 21 | /* |
---|
| 22 |
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | /*
|
---|
| 26 | =============================================================================
|
---|
| 27 | _clsfat() -- write out the modified FAT
|
---|
| 28 | =============================================================================
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | _clsfat()
|
---|
| 32 | {
|
---|
| 33 | /* write the primary FAT to disk */
|
---|
| 34 |
|
---|
| 35 | BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
|
---|
| 36 | _thebpb->fatrec, 0);
|
---|
| 37 |
|
---|
| 38 | /* write the secondary FAT to disk */
|
---|
| 39 |
|
---|
| 40 | BIOS(B_RDWR, 1, _thefat, _thebpb->fsiz,
|
---|
| 41 | (_thebpb->fatrec - _thebpb->fsiz), 0);
|
---|
| 42 |
|
---|
| 43 | _fatmod = FALSE; /* FAT on disk now matches memory */
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | =============================================================================
|
---|
| 48 | _clsdir() -- write out the modified directory
|
---|
| 49 | =============================================================================
|
---|
| 50 | */
|
---|
| 51 |
|
---|
| 52 | _clsdir()
|
---|
| 53 | {
|
---|
| 54 | /* write the directory to disk */
|
---|
| 55 |
|
---|
| 56 | BIOS(B_RDWR, 1, _thedir, _thebpb->rdlen,
|
---|
| 57 | (_thebpb->fatrec + _thebpb->fsiz), 0);
|
---|
| 58 |
|
---|
| 59 | _dirmod = FALSE; /* directory on disk now matches memory */
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /* |
---|
| 63 |
|
---|
| 64 | */
|
---|
| 65 |
|
---|
| 66 | /*
|
---|
| 67 | =============================================================================
|
---|
| 68 | close(fd) -- close file 'fd'
|
---|
| 69 | =============================================================================
|
---|
| 70 | */
|
---|
| 71 |
|
---|
| 72 | int
|
---|
| 73 | close(fd)
|
---|
| 74 | int fd;
|
---|
| 75 | {
|
---|
| 76 | register struct channel *chp;
|
---|
| 77 | register int 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
|
---|
| 111 | =============================================================================
|
---|
| 112 | */
|
---|
| 113 |
|
---|
| 114 | int
|
---|
| 115 | _filecl(fp)
|
---|
| 116 | register struct fcb *fp;
|
---|
| 117 | {
|
---|
| 118 | register int rc;
|
---|
| 119 |
|
---|
| 120 | rc = ClsFile(fp); /* close the FCB */
|
---|
| 121 | fp->modefl = 0; /* mark the FILE closed */
|
---|
| 122 | return(rc);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /*
|
---|
| 126 | =============================================================================
|
---|
| 127 | _fd_cls() -- close all open files
|
---|
| 128 | =============================================================================
|
---|
| 129 | */
|
---|
| 130 |
|
---|
| 131 | _fd_cls()
|
---|
| 132 | {
|
---|
| 133 | register int fd;
|
---|
| 134 |
|
---|
| 135 | for (fd = 0; fd < MAXCHAN; ++fd)
|
---|
| 136 | if (chantab[fd].c_close NE _badfd)
|
---|
| 137 | close(fd);
|
---|
| 138 |
|
---|
| 139 | _clsvol(); /* write modified directory adn FAT */
|
---|
| 140 | }
|
---|