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> 21 22 #include <unistd.h> 23 24 /*================================================================ 25 * minix_sizeup - determine device size 26 *===============================================================*/ 27 int minix_sizeup(device, bytes) 28 char *device; 29 u64_t *bytes; 30 { 31 int fd; 32 struct part_geom entry; 33 struct stat st; 34 35 if ((fd = open(device, O_RDONLY)) == -1) { 36 if (errno != ENOENT) 37 perror("sizeup open"); 38 return -1; 39 } 40 if (ioctl(fd, DIOCGETP, &entry) == -1) { 41 perror("sizeup ioctl"); 42 if(fstat(fd, &st) < 0) { 43 perror("fstat"); 44 entry.size = ((u64_t)(0)); 45 } else { 46 entry.size = ((u64_t)(st.st_size)); 47 } 48 } 49 close(fd); 50 *bytes = entry.size; 51 return 0; 52 } 53