1433d6423SLionel Sambuc #include <sys/cdefs.h> 2433d6423SLionel Sambuc #include "namespace.h" 3433d6423SLionel Sambuc #include <lib.h> 4433d6423SLionel Sambuc #include <minix/u64.h> 5433d6423SLionel Sambuc #include <sys/types.h> 6433d6423SLionel Sambuc #include <sys/stat.h> 7433d6423SLionel Sambuc #include <stdio.h> 8433d6423SLionel Sambuc #include <errno.h> 9433d6423SLionel Sambuc #include <fcntl.h> 10433d6423SLionel Sambuc #include <limits.h> 11433d6423SLionel Sambuc #include <stdlib.h> 12433d6423SLionel Sambuc #include <string.h> 13433d6423SLionel Sambuc #include <time.h> 14433d6423SLionel Sambuc #include <unistd.h> 15433d6423SLionel Sambuc #include <minix/config.h> 16433d6423SLionel Sambuc #include <minix/const.h> 17433d6423SLionel Sambuc #include <minix/type.h> 18433d6423SLionel Sambuc #include <minix/minlib.h> 19433d6423SLionel Sambuc #include <minix/partition.h> 20*5dd8da10SDavid van Moolenbroek #include <sys/ioctl.h> 21433d6423SLionel Sambuc #include <sys/ioc_disk.h> 22433d6423SLionel Sambuc 23433d6423SLionel Sambuc #include <unistd.h> 24433d6423SLionel Sambuc 25433d6423SLionel Sambuc /*================================================================ 26433d6423SLionel Sambuc * minix_sizeup - determine device size 27433d6423SLionel Sambuc *===============================================================*/ minix_sizeup(device,bytes)28433d6423SLionel Sambucint minix_sizeup(device, bytes) 29433d6423SLionel Sambuc char *device; 30433d6423SLionel Sambuc u64_t *bytes; 31433d6423SLionel Sambuc { 32433d6423SLionel Sambuc int fd; 33433d6423SLionel Sambuc struct part_geom entry; 34433d6423SLionel Sambuc struct stat st; 35433d6423SLionel Sambuc 36433d6423SLionel Sambuc if ((fd = open(device, O_RDONLY)) == -1) { 37433d6423SLionel Sambuc if (errno != ENOENT) 38433d6423SLionel Sambuc perror("sizeup open"); 39433d6423SLionel Sambuc return -1; 40433d6423SLionel Sambuc } 41433d6423SLionel Sambuc if (ioctl(fd, DIOCGETP, &entry) == -1) { 42433d6423SLionel Sambuc perror("sizeup ioctl"); 43433d6423SLionel Sambuc if(fstat(fd, &st) < 0) { 44433d6423SLionel Sambuc perror("fstat"); 45433d6423SLionel Sambuc entry.size = ((u64_t)(0)); 46433d6423SLionel Sambuc } else { 47433d6423SLionel Sambuc entry.size = ((u64_t)(st.st_size)); 48433d6423SLionel Sambuc } 49433d6423SLionel Sambuc } 50433d6423SLionel Sambuc close(fd); 51433d6423SLionel Sambuc *bytes = entry.size; 52433d6423SLionel Sambuc return 0; 53433d6423SLionel Sambuc } 54