From 21908a2fb537fce069372592a61054d2a6606049 Mon Sep 17 00:00:00 2001 From: Guillaume Romagny Date: Thu, 16 Jun 2016 13:43:33 +0200 Subject: [PATCH] added /dev/loop as target device --- README | 28 ++++++++++++++++++--- src/piclone.c | 67 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 18 deletions(-) diff --git a/README b/README index 8261cd4..cad37ca 100644 --- a/README +++ b/README @@ -3,6 +3,28 @@ This is an application which allows the SD card inserted into the Pi to be copie To build, run autogen.sh, then ./configure and make. To generate a Debian package for piclone: -1/ run autogen.sh -2/ run dpkg-buildpackage -us -uc -3/ install the deb package with sudo dpkg -i piclone_0.?_armhf.deb +1/ run dpkg-buildpackage -us -uc +2/ install the deb package with sudo dpkg -i piclone_0.?_armhf.deb + + +You can also create a dump image of a SDcard on a USB hard drive for archive + +1/ create an empty file on your harddrive about the size of your SD card (for example 32GB) + + cd /mnt/myharddrive + dd if=/dev/zero of=PicloneSAVE_YYYY_MM_DD.bin bs=100M count=320 + +2/ attach the file to a loopback device (example "/dev/loop0") + + sudo losetup /dev/loop0 PicloneSAVE_YYYY_MM_DD.bin + +3/ use piclone with /dev/loop0 as target + +4/ detach loop device + + sudo losetup -d /dev/loop0 + +5/ you can use md5sum / sha1sum / sha256sum on the file PicloneSAVE_YYYY_MM_DD.bin as usual + +6/ you can zip the image using 7zip or another compression tool + \ No newline at end of file diff --git a/src/piclone.c b/src/piclone.c index 3259eb5..ff865f0 100644 --- a/src/piclone.c +++ b/src/piclone.c @@ -141,25 +141,41 @@ static int get_dev_name (char *dev, char *name) char buffer[256]; FILE *fp; - sprintf (buffer, "sudo parted -l | grep -B 1 \"%s\" | head -n 1 | cut -d \":\" -f 2 | cut -d \"(\" -f 1", dev); - fp = popen (buffer, "r"); - if (fp == NULL) return 0; - if (fgets (buffer, sizeof (buffer) - 1, fp) == NULL) - { - pclose (fp); - return 0; - } - pclose (fp); - buffer[strlen (buffer) - 2] = 0; - strcpy (name, buffer + 1); - return 1; + if (!strncmp (dev, "/dev/loop", 9)) + { + sprintf (buffer, "sudo losetup -a | grep -B 1 \"%s\" | head -n 1 | cut -d \"(\" -f 2 | cut -d \")\" -f 1", dev); + fp = popen (buffer, "r"); + if (fp == NULL) return 0; + if (fgets (buffer, sizeof (buffer) - 1, fp) == NULL) + { + pclose (fp); + return 0; + } + pclose (fp); + buffer[strlen (buffer) - 1] = 0; + strcpy (name, buffer); + } + else + { + sprintf (buffer, "sudo parted -l | grep -B 1 \"%s\" | head -n 1 | cut -d \":\" -f 2 | cut -d \"(\" -f 1", dev); + fp = popen (buffer, "r"); + if (fp == NULL) return 0; + if (fgets (buffer, sizeof (buffer) - 1, fp) == NULL) + { + pclose (fp); + return 0; + } + pclose (fp); + buffer[strlen (buffer) - 2] = 0; + strcpy (name, buffer + 1); + return 1; + } } - static char *partition_name (char *device, char *buffer) { - if (!strncmp (device, "/dev/mmcblk", 11)) - sprintf (buffer, "%sp", device); + if (!strncmp (device, "/dev/mmcblk", 11) || !strncmp (device, "/dev/loop", 9)) + sprintf (buffer, "%sp", device); else sprintf (buffer, "%s", device); return buffer; @@ -733,6 +749,7 @@ static void on_drives_changed (void) gtk_combo_box_set_active (GTK_COMBO_BOX (from_cb), 0); src_count++; + // add existing physical disk as source or target (excepted boot device mmcblk0) fp = popen ("sudo parted -l | grep \"^Disk /dev/\" | cut -d ' ' -f 2 | cut -d ':' -f 1", "r"); if (fp != NULL) { @@ -753,6 +770,26 @@ static void on_drives_changed (void) } pclose (fp); } + + // add existing loopback devices as target + fp = popen ("sudo losetup -a | cut -d ' ' -f 1 | cut -d ':' -f 1", "r"); + if (fp != NULL) + { + while (1) + { + if (fgets (device, sizeof (device) - 1, fp) == NULL) break; + + if (!strncmp (device + 5, "loop", 4) ) + { + device[strlen (device) - 1] = 0; + get_dev_name (device, name); + sprintf (buffer, "%s (%s)", name, device); + gtk_combo_box_append_text (GTK_COMBO_BOX (to_cb), buffer); + dst_count++; + } + } + pclose (fp); + } if (dst_count == 0) {