minix/minix/commands/devsize/devsize.c

52 lines
857 B
C
Raw Normal View History

2005-09-08 17:45:33 +02:00
/* Ben Gras
*
* Based on sizeup() in mkfs.c.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <machine/partition.h>
2005-09-08 17:45:33 +02:00
#include <minix/partition.h>
#include <sys/ioctl.h>
2005-09-08 17:45:33 +02:00
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
unsigned long sizeup(char *);
int main(int argc, char *argv[])
{
if(argc != 2) {
fprintf(stderr, "Usage: %s <device>\n", argv[0]);
return 1;
}
2005-09-13 11:57:40 +02:00
printf("%lu\n", sizeup(argv[1]));
2005-09-08 17:45:33 +02:00
return 0;
}
unsigned long sizeup(char *device)
2005-09-08 17:45:33 +02:00
{
int fd;
struct part_geom entry;
2005-09-08 17:45:33 +02:00
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;
2005-09-08 17:45:33 +02:00
return d;
}