[parted-devel] [PATCH] linux-swap: generate UUIDs for fresh swap spaces
Colin Watson
cjwatson at ubuntu.com
Tue Jun 16 17:09:45 UTC 2009
* libparted/fs/linux_swap/linux_swap.c: Generate a UUID when creating a
fresh swap space.
* tests/t2100-mkswap.sh: Test that two fresh swap spaces get different
UUIDs, and that 'check' preserves the swap UUID.
---
libparted/fs/linux_swap/linux_swap.c | 8 ++++++
tests/t2100-mkswap.sh | 43 ++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/libparted/fs/linux_swap/linux_swap.c b/libparted/fs/linux_swap/linux_swap.c
index 16b869a..62bb121 100644
--- a/libparted/fs/linux_swap/linux_swap.c
+++ b/libparted/fs/linux_swap/linux_swap.c
@@ -31,6 +31,7 @@
#endif /* ENABLE_NLS */
#include <unistd.h>
+#include <uuid/uuid.h>
#define SWAP_SPECIFIC(fs) ((SwapSpecific*) (fs->type_specific))
#define BUFFER_SIZE 128
@@ -178,7 +179,14 @@ swap_init (PedFileSystem* fs, int fresh)
- sizeof (SwapNewHeader)) / 4;
if (fresh) {
+ uuid_t uuid_dat;
+
memset (fs_info->header, 0, getpagesize());
+
+ /* version is always 1 here */
+ uuid_generate (uuid_dat);
+ memcpy (fs_info->header->new.sws_uuid, uuid_dat,
+ sizeof (fs_info->header->new.sws_uuid));
return 1;
}
else
diff --git a/tests/t2100-mkswap.sh b/tests/t2100-mkswap.sh
index 420c250..cde1639 100755
--- a/tests/t2100-mkswap.sh
+++ b/tests/t2100-mkswap.sh
@@ -27,6 +27,7 @@ test_description='create linux-swap partitions'
######################################################################
N=1M
dev=loop-file
+dev2=loop-file-2
test_expect_success \
'create a file to simulate the underlying device' \
'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'
@@ -52,4 +53,46 @@ test_expect_success \
'od -t x1 -An -j450 -N1 $dev > out && echo " 82" > exp'
test_expect_success 'expect it to be 82, not 83' 'compare out exp'
+test_expect_success \
+ 'create another file to simulate the underlying device' \
+ 'dd if=/dev/null of=$dev2 bs=1 seek=$N 2> /dev/null'
+
+test_expect_success \
+ 'label another test disk' \
+ 'parted -s $dev2 mklabel msdos > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+test_expect_success \
+ 'create another partition' \
+ 'parted -s $dev2 mkpart primary 0 1 > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+test_expect_success \
+ 'create another linux-swap file system' \
+ 'parted -s $dev2 mkfs 1 "linux-swap(new)" > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+# partition starts at offset 16384; swap UUID is 1036 bytes in
+test_expect_success \
+ 'extract UUID 1' \
+ 'od -t x1 -An -j17420 -N16 $dev > uuid1'
+test_expect_success \
+ 'extract UUID 2' \
+ 'od -t x1 -An -j17420 -N16 $dev2 > uuid2'
+test_expect_failure \
+ 'two linux-swap file systems have different UUIDs' \
+ 'compare uuid1 uuid2'
+
+test_expect_success \
+ 'check linux-swap file system' \
+ 'parted -s $dev2 check 1 > out 2>&1'
+test_expect_success 'expect no output' 'compare out /dev/null'
+
+test_expect_success \
+ 'extract new UUID 2' \
+ 'od -t x1 -An -j17420 -N16 $dev2 > uuid2-new'
+test_expect_success \
+ 'check preserves linux-swap UUID' \
+ 'compare uuid2 uuid2-new'
+
test_done
--
1.6.3.1
More information about the parted-devel
mailing list