unstack - fix ipcvecs
[minix.git] / commands / devsize / devsize.c
bloba85d20821a04906133e8b38ad745538ea319211b
1 /* Ben Gras
3 * Based on sizeup() in mkfs.c.
4 */
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>
20 unsigned long sizeup(char *);
22 int main(int argc, char *argv[])
24 if(argc != 2) {
25 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
26 return 1;
29 printf("%lu\n", sizeup(argv[1]));
30 return 0;
34 unsigned long sizeup(device)
35 char *device;
37 int fd;
38 struct partition entry;
39 unsigned long d;
41 if ((fd = open(device, O_RDONLY)) == -1) {
42 perror("sizeup open");
43 exit(1);
45 if (ioctl(fd, DIOCGETP, &entry) == -1) {
46 perror("sizeup ioctl");
47 exit(1);
49 close(fd);
50 d = entry.size / 512;
51 return d;