secondary cache feature in vm.
[minix.git] / commands / simple / devsize.c
blob863c95452ec8c172a480796bcbc230d62ebcc714
1 /* Ben Gras
3 * Based on sizeup() in mkfs.c.
4 */
6 #include <sys/types.h>
7 #include <sys/dir.h>
8 #include <sys/stat.h>
9 #include <machine/partition.h>
10 #include <minix/partition.h>
11 #include <minix/u64.h>
12 #include <sys/ioc_disk.h>
13 #include <stdio.h>
14 #include <errno.h>
15 #include <fcntl.h>
16 #include <limits.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <time.h>
20 #include <unistd.h>
22 unsigned long sizeup(char *);
24 int main(int argc, char *argv[])
26 if(argc != 2) {
27 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
28 return 1;
31 printf("%lu\n", sizeup(argv[1]));
32 return 0;
36 unsigned long sizeup(device)
37 char *device;
39 int fd;
40 struct partition entry;
41 unsigned long d;
43 if ((fd = open(device, O_RDONLY)) == -1) {
44 perror("sizeup open");
45 exit(1);
47 if (ioctl(fd, DIOCGETP, &entry) == -1) {
48 perror("sizeup ioctl");
49 exit(1);
51 close(fd);
52 d = div64u(entry.size, 512);
53 return d;