libc, libutil: remove compat hacks
[minix.git] / lib / libc / sys-minix / sizeup.c
blobea843075ae520719776c003a34f0d15c7f4dee4b
1 #include <sys/cdefs.h>
2 #include "namespace.h"
3 #include <lib.h>
4 #include <minix/u64.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <limits.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <time.h>
14 #include <unistd.h>
15 #include <minix/config.h>
16 #include <minix/const.h>
17 #include <minix/type.h>
18 #include <minix/minlib.h>
19 #include <minix/partition.h>
20 #include <sys/ioc_disk.h>
22 #include <unistd.h>
24 /*================================================================
25 * minix_sizeup - determine device size
26 *===============================================================*/
27 int minix_sizeup(device, bytes)
28 char *device;
29 u64_t *bytes;
31 int fd;
32 struct partition entry;
33 struct stat st;
35 if ((fd = open(device, O_RDONLY)) == -1) {
36 if (errno != ENOENT)
37 perror("sizeup open");
38 return -1;
40 if (ioctl(fd, DIOCGETP, &entry) == -1) {
41 perror("sizeup ioctl");
42 if(fstat(fd, &st) < 0) {
43 perror("fstat");
44 entry.size = cvu64(0);
45 } else {
46 entry.size = cvu64(st.st_size);
49 close(fd);
50 *bytes = entry.size;
51 return 0;