aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/partprobe.c
blob: 2fe3bd53fabc84c891f90752489e29539f02e7fd (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
40
41
42
43
44
45
46
47
48
49
50
51
/* partprobe.c - Tell the kernel about partition table changes
 *
 * Copyright 2014 Bertold Van den Bergh <vandenbergh@bertold.org>
 *
 * see http://man7.org/linux/man-pages/man8/partprobe.8.html

USE_PARTPROBE(NEWTOY(partprobe, NULL, TOYFLAG_SBIN))

config PARTPROBE
  bool "partprobe"
  default n
  help
    partprobe - Tell the kernel about partition table changes
	
    usage: partprobe [devices...]

    Asks the kernel to re-read the partition table on the specified
    devices.
*/

#include "toys.h"

void update_device(char* path)
{
  int sd_fd = open(path, 0);
  
  if(sd_fd < 0){
	perror_msg("Unable to open %s", path);
	return;
  }
  
  if(ioctl(sd_fd, BLKRRPART, NULL) < 0)
    perror_msg("ioctl (BLKRRPART) failed, old layout still used");
  
  close(sd_fd);
}

void partprobe_main(void)
{
  char** opt; 
  if(*toys.optargs == NULL){
    printf("No devices specified.\n");
    exit(EXIT_FAILURE);
  }
  
  for (opt = toys.optargs; *opt; opt++) {
    update_device(*opt);
  }
  
  exit(EXIT_SUCCESS);
}