source: buchla-68k/libcio/close.c@ 6262b5c

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

Added include files for global functions and variables.

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