File: msdos.c

package info (click to toggle)
zoo 2.10-21
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 852 kB
  • ctags: 1,258
  • sloc: ansic: 8,944; asm: 793; makefile: 179
file content (97 lines) | stat: -rw-r--r-- 2,290 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* msdos.c */

/* Highly system-dependent routines go here */

/* settime() */

/* Accepts a date/time in DOS format and sets the file time. Returns 1
if OK, 0 if error */

#include "options.h"
#include "zoo.h"
#include "zooio.h"		/* to satisfy declarations in zoofns.h */
#include "zoofns.h"
#include "errors.i"
#include <stdio.h>		/* to get fileno() */

/* register definitions specific for Turbo C */
union	REGS	{
	struct { unsigned ax, bx, cx, dx, si, di, carry, flags; } x;
	struct { unsigned char al, ah, bl, bh, cl, ch, dl, dh; }  h;
};

int settime (file,date,time)
ZOOFILE file;
unsigned date, time;
{
	extern intdos();
	union REGS regs;
	regs.h.ah = 0x57;						/* DOS FileTimes call */
	regs.h.al = 0x01;					/* set date/time request */
	regs.x.bx = fileno (file);		/* get handle */
	regs.x.cx = time;
	regs.x.dx = date;

	/* first flush file so later write won't occur on close */
	fflush (file);

	intdos (&regs, &regs);
	if (regs.x.carry != 0)
		return (0);
	else
		return (1);
} /* settime */

/* gets date and time of file */
gettime (file,date,time)
ZOOFILE file;
unsigned *date, *time;
{
	union REGS regs;
	regs.h.ah = 0x57;						/* DOS FileTimes call */
	regs.h.al = 0x00;						/* get date/time request */
	regs.x.bx = fileno (file);		/* get handle */
	intdos (&regs, &regs);
	*time = regs.x.cx;
	*date = regs.x.dx;
	if (regs.x.carry != 0)
		return (0);
	else
		return (1);
} /* settime */


/* space() */

/* Returns free space in bytes on disk n (0 = default, 1 = A, etc.).  Returns
	0 if drive number is invalid.  Before getting disk space, the function
	requests DOS to flush its internal buffers */

unsigned long space (drive, alloc_size)
int drive;
int *alloc_size;
{
	unsigned long free_space;
	union REGS regs;

	regs.h.ah = 0x0d;										/* disk reset DOS call */
	intdos (&regs, &regs);

	regs.h.ah = 0x36;										/* GetFreeSpace DOS call */
	regs.h.dl = drive;
	intdos (&regs, &regs);

	/* space = clusters * sectors/cluster * bytes/sector.  */
	/* ax=0xFFFF on error */

	/* cluster size = sectors/cluster * bytes/sector */
	*alloc_size = regs.x.ax * regs.x.cx;

	/* space = cluster * alloc_size */
	if (regs.x.ax == 0xffff)
		return (0L);			/* invalid drive */
	else {
		free_space = ((unsigned long) regs.x.bx) * *alloc_size;
		return (free_space);
	}
}