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