/* Ben Gras * * Based on sizeup() in mkfs.c. */ #include #include #include #include #include #include #include #include #include #include #include #include #include unsigned long sizeup(char *); int main(int argc, char *argv[]) { if(argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } printf("%lu\n", sizeup(argv[1])); return 0; } unsigned long sizeup(char *device) { int fd; struct part_geom entry; unsigned long d; if ((fd = open(device, O_RDONLY)) == -1) { perror("sizeup open"); exit(1); } if (ioctl(fd, DIOCGETP, &entry) == -1) { perror("sizeup ioctl"); exit(1); } close(fd); d = entry.size / 512; return d; }