1 /* msdos.c */
2
3 /* Highly system-dependent routines go here */
4
5 /* settime() */
6
7 /* Accepts a date/time in DOS format and sets the file time. Returns 1
8 if OK, 0 if error */
9
10 #include "options.h"
11 #include "zoo.h"
12 #include "zooio.h" /* to satisfy declarations in zoofns.h */
13 #include "zoofns.h"
14 #include "errors.i"
15 #include <stdio.h> /* to get fileno() */
16
17 /* register definitions specific for Turbo C */
18 union REGS {
19 struct { unsigned ax, bx, cx, dx, si, di, carry, flags; } x;
20 struct { unsigned char al, ah, bl, bh, cl, ch, dl, dh; } h;
21 };
22
settime(file,date,time)23 int settime (file,date,time)
24 ZOOFILE file;
25 unsigned date, time;
26 {
27 extern intdos();
28 union REGS regs;
29 regs.h.ah = 0x57; /* DOS FileTimes call */
30 regs.h.al = 0x01; /* set date/time request */
31 regs.x.bx = fileno (file); /* get handle */
32 regs.x.cx = time;
33 regs.x.dx = date;
34
35 /* first flush file so later write won't occur on close */
36 fflush (file);
37
38 intdos (®s, ®s);
39 if (regs.x.carry != 0)
40 return (0);
41 else
42 return (1);
43 } /* settime */
44
45 /* gets date and time of file */
gettime(file,date,time)46 gettime (file,date,time)
47 ZOOFILE file;
48 unsigned *date, *time;
49 {
50 union REGS regs;
51 regs.h.ah = 0x57; /* DOS FileTimes call */
52 regs.h.al = 0x00; /* get date/time request */
53 regs.x.bx = fileno (file); /* get handle */
54 intdos (®s, ®s);
55 *time = regs.x.cx;
56 *date = regs.x.dx;
57 if (regs.x.carry != 0)
58 return (0);
59 else
60 return (1);
61 } /* settime */
62
63
64 /* space() */
65
66 /* Returns free space in bytes on disk n (0 = default, 1 = A, etc.). Returns
67 0 if drive number is invalid. Before getting disk space, the function
68 requests DOS to flush its internal buffers */
69
space(drive,alloc_size)70 unsigned long space (drive, alloc_size)
71 int drive;
72 int *alloc_size;
73 {
74 unsigned long free_space;
75 union REGS regs;
76
77 regs.h.ah = 0x0d; /* disk reset DOS call */
78 intdos (®s, ®s);
79
80 regs.h.ah = 0x36; /* GetFreeSpace DOS call */
81 regs.h.dl = drive;
82 intdos (®s, ®s);
83
84 /* space = clusters * sectors/cluster * bytes/sector. */
85 /* ax=0xFFFF on error */
86
87 /* cluster size = sectors/cluster * bytes/sector */
88 *alloc_size = regs.x.ax * regs.x.cx;
89
90 /* space = cluster * alloc_size */
91 if (regs.x.ax == 0xffff)
92 return (0L); /* invalid drive */
93 else {
94 free_space = ((unsigned long) regs.x.bx) * *alloc_size;
95 return (free_space);
96 }
97 }
98