Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Last active February 26, 2017 15:50
Show Gist options
  • Save blackknight36/2a2e75c27cc0ca9c5fe313f8b374f01b to your computer and use it in GitHub Desktop.
Save blackknight36/2a2e75c27cc0ca9c5fe313f8b374f01b to your computer and use it in GitHub Desktop.
#include <parted/parted.h>
#include <parted/device.h>
#include <parted/debug.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <stdio.h>
int check_card_size(char const *dev_name);
int main (int argc) {
while(true) {
char const *dev_name = "/dev/sdc";
check_card_size(dev_name);
printf("Change card and press enter to continue.\n");
char input = getchar();
sleep(3);
}
return 0;
}
int check_card_size(char const *dev_name) {
PedGeometry geom;
PedDevice *dev = ped_device_get(dev_name);
if (!dev) {
fprintf(stderr, "cannot create device %s\n", dev_name);
return 1;
}
if (!ped_device_open(dev)) {
fprintf(stderr, "cannot open device %s\n", dev_name);
return 1;
}
if (!ped_geometry_init(&geom, dev, 0, dev->length)) {
fprintf(stderr, "cannot initialize geometry\n");
return 1;
}
printf("size: %d\n", dev->length);
/* Flush cache to force parted to reread the device */
ped_device_cache_remove(dev);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment