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