source: buchla-68k/orig/IOLIB/CLOSE.C@ 0580615

Last change on this file since 0580615 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 3.0 KB
Line 
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
14extern int _badfd(), ClsFile(), _clsvol();
15
16extern int _fatmod, _dirmod;
17extern struct bpb *_thebpb;
18extern struct dirent _thedir[];
19extern 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
72int
73close(fd)
74int 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
114int
115_filecl(fp)
116register 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}
Note: See TracBrowser for help on using the repository browser.