xref: /minix3/minix/commands/devsize/devsize.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1 /* Ben Gras
2  *
3  * Based on sizeup() in mkfs.c.
4  */
5 
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <machine/partition.h>
9 #include <minix/partition.h>
10 #include <sys/ioc_disk.h>
11 #include <stdio.h>
12 #include <errno.h>
13 #include <fcntl.h>
14 #include <limits.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <time.h>
18 #include <unistd.h>
19 
20 unsigned long sizeup(char *);
21 
22 int main(int argc, char *argv[])
23 {
24   if(argc != 2) {
25 	fprintf(stderr, "Usage: %s <device>\n", argv[0]);
26 	return 1;
27   }
28 
29   printf("%lu\n", sizeup(argv[1]));
30   return 0;
31 }
32 
33 
34 unsigned long sizeup(char *device)
35 {
36   int fd;
37   struct part_geom entry;
38   unsigned long d;
39 
40   if ((fd = open(device, O_RDONLY)) == -1) {
41   	perror("sizeup open");
42   	exit(1);
43   }
44   if (ioctl(fd, DIOCGETP, &entry) == -1) {
45   	perror("sizeup ioctl");
46   	exit(1);
47   }
48   close(fd);
49   d = entry.size / 512;
50   return d;
51 }
52