[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | fsize.c -- file size and disk capacity functions
|
---|
| 4 | Version 1 -- 1987-10-29 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "stdio.h"
|
---|
| 9 | #include "biosdefs.h"
|
---|
| 10 | #include "io.h"
|
---|
| 11 | #include "stddefs.h"
|
---|
| 12 |
|
---|
[7258c6a] | 13 | extern uint16_t _gtcl12(int8_t *fat, uint16_t cl);
|
---|
| 14 | extern int16_t _opnvol(void);
|
---|
| 15 | extern int16_t _filecl(struct fcb *fp);
|
---|
[f40a309] | 16 |
|
---|
[7258c6a] | 17 | extern uint16_t _thefat[];
|
---|
[f40a309] | 18 |
|
---|
| 19 | extern struct bpb *_thebpb;
|
---|
| 20 |
|
---|
| 21 | /*
|
---|
| 22 | =============================================================================
|
---|
| 23 | fsize() -- return the current size of an open stream file
|
---|
| 24 |
|
---|
| 25 | how = 0: in bytes, 1: in allocated clusters
|
---|
| 26 | =============================================================================
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[7258c6a] | 29 | int32_t fsize(FILE *fp, int16_t how)
|
---|
[f40a309] | 30 | {
|
---|
| 31 | register struct channel *chp;
|
---|
| 32 | register struct fcb *fcp;
|
---|
| 33 |
|
---|
| 34 | if (fp EQ (FILE *)0L)
|
---|
| 35 | return(-1L);
|
---|
| 36 |
|
---|
| 37 | if (fp->_flags & _BUSY) {
|
---|
| 38 |
|
---|
| 39 | chp = &chantab[fp->_unit];
|
---|
| 40 |
|
---|
| 41 | if (chp->c_close NE _filecl)
|
---|
| 42 | return(-1L);
|
---|
| 43 |
|
---|
| 44 | fcp = chp->c_arg;
|
---|
| 45 |
|
---|
| 46 | if (fcp->modefl & FC_OPN) {
|
---|
| 47 |
|
---|
| 48 | if (how)
|
---|
| 49 | return(fcp->asects);
|
---|
| 50 | else
|
---|
| 51 | return(fcp->curlen);
|
---|
| 52 |
|
---|
| 53 | } else
|
---|
| 54 | return(-1L);
|
---|
| 55 |
|
---|
| 56 | } else
|
---|
| 57 | return(-1L);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /* |
---|
| 61 |
|
---|
| 62 | */
|
---|
| 63 |
|
---|
| 64 | /*
|
---|
| 65 | =============================================================================
|
---|
| 66 | dspace() -- return disk capacity or usage
|
---|
| 67 |
|
---|
| 68 | which = 0: capcity, 1: usage
|
---|
| 69 | =============================================================================
|
---|
| 70 | */
|
---|
[7258c6a] | 71 |
|
---|
[f40a309] | 72 | int16_t dspace(int16_t which)
|
---|
[7258c6a] | 73 | {
|
---|
[f40a309] | 74 | register int16_t maxcl, clcount, nc;
|
---|
| 75 |
|
---|
| 76 | if (_opnvol())
|
---|
| 77 | return(-1L);
|
---|
| 78 |
|
---|
| 79 | maxcl = _thebpb->numcl;
|
---|
| 80 |
|
---|
| 81 | if (which) {
|
---|
| 82 |
|
---|
| 83 | clcount = 0;
|
---|
| 84 |
|
---|
| 85 | for (nc = 2; nc < maxcl; nc++)
|
---|
| 86 | if (0 EQ _gtcl12(_thefat, nc))
|
---|
| 87 | ++clcount;
|
---|
| 88 |
|
---|
| 89 | return(clcount);
|
---|
| 90 |
|
---|
| 91 | } else {
|
---|
| 92 |
|
---|
| 93 | return(maxcl);
|
---|
| 94 | }
|
---|
| 95 | }
|
---|