|
|
1.1 root 1: /*
2: * Copyright (c) 1995-1994 The University of Utah and
3: * the Computer Systems Laboratory at the University of Utah (CSL).
4: * All rights reserved.
5: *
6: * Permission to use, copy, modify and distribute this software is hereby
7: * granted provided that (1) source code retains these copyright, permission,
8: * and disclaimer notices, and (2) redistributions including binaries
9: * reproduce the notices in supporting documentation, and (3) all advertising
10: * materials mentioning features or use of this software display the following
11: * acknowledgement: ``This product includes software developed by the
12: * Computer Systems Laboratory at the University of Utah.''
13: *
14: * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
15: * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
16: * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17: *
18: * CSL requests users of this software to return to [email protected] any
19: * improvements that they make and grant CSL redistribution rights.
20: *
21: * Author: Bryan Ford, University of Utah CSL
22: */
23:
24: #include <unistd.h>
25: #include <errno.h>
26: #include <string.h>
27: #include <sys/stat.h>
28:
29: #include "dos_io.h"
30:
31: int dos_fstat(dos_fd_t fd, struct stat *st)
32: {
33: int err;
34: int actual = 0;
35: struct real_call_data real_call_data;
36: vm_offset_t old_pos, new_pos;
37:
38: dos_init_rcd(&real_call_data);
39:
40: bzero(st, sizeof(*st));
41: st->st_nlink = 1;
42: st->st_mode = S_IRWXU | S_IRWXG | S_IRWXO; /* XXX attributes */
43:
44: /* Get device information,
45: which will tell us whether this is a character device
46: or a regular file. */
47: real_call_data.eax = 0x4400;
48: real_call_data.ebx = fd;
49: real_int(0x21, &real_call_data);
50: if (err = dos_check_err(&real_call_data))
51: return err;
52: if (real_call_data.edx & (1<<7))
53: st->st_mode |= S_IFCHR;
54: else
55: st->st_mode |= S_IFREG;
56:
57: /* XXX get date/time with int 21 5700 */
58:
59: /* Get file size by seeking to the end and back. */
60: if (!dos_seek(fd, 0, 1, &old_pos)
61: && !dos_seek(fd, 0, 2, &st->st_size))
62: {
63: if (err = dos_seek(fd, old_pos, 0, &new_pos))
64: return err;
65: if (new_pos != old_pos)
66: return EIO;/*XXX*/
67: }
68:
69: /* Always assume 512-byte blocks for now... */
70: st->st_blocks = (st->st_size + 511) / 512;
71: st->st_blksize = 512;
72:
73: return 0;
74: }
75:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.