diff mbox

[1/3] UUID support

Message ID 1362606710-18089-2-git-send-email-kix@kix.es (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Rodolfo García Peñas (kix) March 6, 2013, 9:51 p.m. UTC
From: "Rodolfo García Peñas (kix)" <kix@kix.es>

This patch includes support for UUID tags.

The new code detect if the resume device starts with the string "UUID="
and then convert the UUID to the /dev device.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
---
 Makefile.am  |    2 ++
 configure.ac |   11 +++++++++++
 suspend.c    |   32 ++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
diff mbox

Patch

diff --git a/Makefile.am b/Makefile.am
index 76a041d..4da1b4e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,11 +69,13 @@  AM_CFLAGS=\
 	-DS2RAM \
 	-D_LARGEFILE64_SOURCE \
 	$(LZO_CFLAGS) \
+	$(LIBBLKID_LIBS_CFLAGS) \
 	$(LIBGCRYPT_CFLAGS)
 
 common_s2disk_libs=\
 	$(LZO_LIBS) \
 	$(LIBGCRYPT_LIBS) \
+	$(LIBBLKID_LIBS) \
 	$(PTHREAD_LIBS)
 common_s2ram_libs=
 
diff --git a/configure.ac b/configure.ac
index 9172296..3924532 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,6 +188,17 @@  else
 	AC_MSG_ERROR([Unsupported architecture ${host}])
 fi
 
+if test -z "${LIBBLKID_LIBS}"; then
+	AC_ARG_VAR([LIBBLKID_CFLAGS], [C compiler flags for libblkid])
+	AC_ARG_VAR([LIBBLKID_LIBS], [linker flags for libblkid])
+	AC_CHECK_LIB(
+		[blkid],
+		[blkid_new_probe],
+		[LIBBLKID_LIBS="-lblkid"],
+		[AC_MSG_ERROR([Required libblkid was not found])]
+	)
+fi
+
 if test "${enable_compress}" = "yes"; then
 	CONFIG_FEATURES="${CONFIG_FEATURES} compress"
 	AC_DEFINE([CONFIG_COMPRESS], [1], [Define if compression enabled])
diff --git a/suspend.c b/suspend.c
index 479ce58..56a99db 100644
--- a/suspend.c
+++ b/suspend.c
@@ -38,6 +38,7 @@ 
 #ifdef CONFIG_COMPRESS
 #include <lzo/lzo1x.h>
 #endif
+#include <blkid/blkid.h>
 
 #include "swsusp.h"
 #include "memalloc.h"
@@ -229,6 +230,8 @@  static struct config_par parameters[] = {
 	}
 };
 
+static char *fsprobe_get_devname_by_uuid(const char *uuid);
+
 static loff_t check_free_swap(int dev)
 {
 	int error;
@@ -2414,6 +2417,21 @@  int main(int argc, char *argv[])
 	}
 
 	ret = 0;
+
+	/* If device is UUID, convert it to dev file */
+	if (!strncmp(resume_dev_name, "UUID=", 5)) {
+		char *tmpdev = NULL;
+
+		tmpdev = (char *) fsprobe_get_devname_by_uuid(resume_dev_name);
+		if (!tmpdev) {
+			ret = ENODEV;
+			goto Umount;
+		}
+
+		snprintf(resume_dev_name, MAX_STR_LEN -1, "%s", tmpdev);
+		free(tmpdev);
+	}
+
 	if (stat(resume_dev_name, &stat_buf)) {
 		suspend_error("Could not stat the resume device file.");
 		ret = ENODEV;
@@ -2561,3 +2579,17 @@  Umount:
 
 	return ret;
 }
+
+static char *fsprobe_get_devname_by_uuid(const char *uuid)
+{
+	char *tmp_uuid = NULL, *ptr = NULL, *ret = NULL;
+
+	tmp_uuid = strdup(uuid);
+	ptr = strtok(tmp_uuid, "=");	/* string UUID */
+	ptr = strtok(NULL, "=");	/* UUID value */
+
+	if (ptr)
+		ret = blkid_evaluate_tag("UUID", ptr, NULL);
+
+	return ret;
+}