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

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

Use standard integer types.

  • Property mode set to 100644
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 int16_t _badfd(void);
15extern int16_t ClsFile(struct fcb *fcp);
16extern void _clsvol(void);
17
18extern int16_t _fatmod, _dirmod;
19extern struct bpb *_thebpb;
20extern struct dirent _thedir[];
21extern uint16_t _thefat[];
22
23/*
24
25*/
26
27/*
28 =============================================================================
29 _clsfat() -- write out the modified FAT
30 =============================================================================
31*/
32
33void _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*/
53
54void _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 =============================================================================
72*/
73
74int16_t close(int16_t fd)
75{
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
111 =============================================================================
112*/
113
114int16_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
126 =============================================================================
127*/
128
129void _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}
Note: See TracBrowser for help on using the repository browser.