source: trunk/minix/commands/simple/devsize.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 945 bytes
RevLine 
[9]1/* Ben Gras
2 *
3 * Based on sizeup() in mkfs.c.
4 */
5
6#include <sys/types.h>
7#include <sys/dir.h>
8#include <sys/stat.h>
9#include <ibm/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>
21
22unsigned long sizeup(char *);
23
24int main(int argc, char *argv[])
25{
26 int sec;
27
28 if(argc != 2) {
29 fprintf(stderr, "Usage: %s <device>\n", argv[0]);
30 return 1;
31 }
32
33 printf("%lu\n", sizeup(argv[1]));
34 return 0;
35}
36
37
38unsigned long sizeup(device)
39char *device;
40{
41 int fd;
42 struct partition entry;
43 unsigned long d;
44 struct stat st;
45
46 if ((fd = open(device, O_RDONLY)) == -1) {
47 perror("sizeup open");
48 exit(1);
49 }
50 if (ioctl(fd, DIOCGETP, &entry) == -1) {
51 perror("sizeup ioctl");
52 exit(1);
53 }
54 close(fd);
55 d = div64u(entry.size, 512);
56 return d;
57}
Note: See TracBrowser for help on using the repository browser.