summaryrefslogtreecommitdiffstats
path: root/rescue/kernel_read_part.c
blob: 4b9d16d6595fa9f0238f76195854144ba880bc0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <fcntl.h>


void die(char *msg)
{
  perror(msg);
  exit(1);
}

void kernel_read(char *dev)
{
  int fd;

  sync();
  if ((fd = open(dev, O_RDONLY)) == -1) die("can't open device");
  sync(); 
  sleep(1);
  ioctl(fd, BLKRRPART, 0);
  sync();
  close(fd);
  sync();
}

int main(int argc, char **argv) 
{
  if (argc != 2) {
    fprintf(stderr, "usage: kernel_read_part <hard drive device>\n");
    exit(1);
  }
  kernel_read(argv[1]);
}