etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / sys / sizeup.c
blob11df1e96b5e17781f5c9a9b325f740cd01453572
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/ioctl.h>
21 #include <sys/ioc_disk.h>
23 #include <unistd.h>
25 /*================================================================
26 * minix_sizeup - determine device size
27 *===============================================================*/
28 int minix_sizeup(device, bytes)
29 char *device;
30 u64_t *bytes;
32 int fd;
33 struct part_geom entry;
34 struct stat st;
36 if ((fd = open(device, O_RDONLY)) == -1) {
37 if (errno != ENOENT)
38 perror("sizeup open");
39 return -1;
41 if (ioctl(fd, DIOCGETP, &entry) == -1) {
42 perror("sizeup ioctl");
43 if(fstat(fd, &st) < 0) {
44 perror("fstat");
45 entry.size = ((u64_t)(0));
46 } else {
47 entry.size = ((u64_t)(st.st_size));
50 close(fd);
51 *bytes = entry.size;
52 return 0;