summaryrefslogtreecommitdiffstats
path: root/debian/patches/zfs.patch
blob: 8d0e92778a55bc98084e2a5dd04d1be3336ffd0a (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From a652c80f142411473d14c038e91c24ba81537f5b Mon Sep 17 00:00:00 2001
From: Colin Watson <cjwatson@ubuntu.com>
Date: Fri, 28 Mar 2014 17:09:48 +0000
Subject: Add ZFS support

Last-Update: 2019-10-11

Patch-Name: zfs.patch
---
 libparted/fs/Makefile.am |  3 +-
 libparted/fs/zfs/zfs.c   | 77 ++++++++++++++++++++++++++++++++++++++++
 libparted/libparted.c    |  4 +++
 3 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 libparted/fs/zfs/zfs.c

diff --git a/libparted/fs/Makefile.am b/libparted/fs/Makefile.am
index 41a60d98..1636d49f 100644
--- a/libparted/fs/Makefile.am
+++ b/libparted/fs/Makefile.am
@@ -52,7 +52,8 @@ libfs_la_SOURCES =		\
   xfs/platform_defs.h		\
   xfs/xfs.c			\
   xfs/xfs_sb.h			\
-  xfs/xfs_types.h
+  xfs/xfs_types.h		\
+  zfs/zfs.c
 
 lib_LTLIBRARIES = libparted-fs-resize.la
 
diff --git a/libparted/fs/zfs/zfs.c b/libparted/fs/zfs/zfs.c
new file mode 100644
index 00000000..47cd6773
--- /dev/null
+++ b/libparted/fs/zfs/zfs.c
@@ -0,0 +1,77 @@
+/*
+    libparted - a library for manipulating disk partitions
+    Copyright (C) 2000, 2007, 2009-2010 Free Software Foundation, Inc.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+
+#include <parted/parted.h>
+#include <parted/endian.h>
+
+#if ENABLE_NLS
+#  include <libintl.h>
+#  define _(String) dgettext (PACKAGE, String)
+#else
+#  define _(String) (String)
+#endif /* ENABLE_NLS */
+
+#include <unistd.h>
+
+#define ZFS_SIGNATURE		0x00bab10c
+
+struct zfs_uberblock
+{
+  uint64_t signature;
+  uint64_t version;
+};
+
+static PedGeometry*
+zfs_probe (PedGeometry* geom)
+{
+	struct zfs_uberblock *uber = alloca (geom->dev->sector_size);
+
+	if (!ped_geometry_read (geom, uber, 256, 1))
+		return 0;
+
+	if ((le64toh (uber->signature) == ZFS_SIGNATURE
+		|| be64toh (uber->signature) == ZFS_SIGNATURE)
+		&& uber->version != 0)
+		return ped_geometry_new (geom->dev, geom->start, geom->length);
+	else
+		return NULL;
+}
+
+static PedFileSystemOps zfs_ops = {
+	probe:		zfs_probe,
+};
+
+static PedFileSystemType zfs_type = {
+	next:	NULL,
+	ops:	&zfs_ops,
+	name:	"zfs",
+};
+
+void
+ped_file_system_zfs_init ()
+{
+	ped_file_system_type_register (&zfs_type);
+}
+
+void
+ped_file_system_zfs_done ()
+{
+	ped_file_system_type_unregister (&zfs_type);
+}
diff --git a/libparted/libparted.c b/libparted/libparted.c
index 204ce007..88e7eea2 100644
--- a/libparted/libparted.c
+++ b/libparted/libparted.c
@@ -115,6 +115,7 @@ extern void ped_file_system_ext2_init (void);
 extern void ped_file_system_nilfs2_init (void);
 extern void ped_file_system_btrfs_init (void);
 extern void ped_file_system_udf_init (void);
+extern void ped_file_system_zfs_init (void);
 
 static void
 init_file_system_types ()
@@ -133,6 +134,7 @@ init_file_system_types ()
 	ped_file_system_nilfs2_init ();
 	ped_file_system_btrfs_init ();
 	ped_file_system_udf_init ();
+	ped_file_system_zfs_init ();
 }
 
 extern void ped_disk_aix_done ();
@@ -200,10 +202,12 @@ extern void ped_file_system_xfs_done (void);
 extern void ped_file_system_amiga_done (void);
 extern void ped_file_system_btrfs_done (void);
 extern void ped_file_system_udf_done (void);
+extern void ped_file_system_zfs_done (void);
 
 static void
 done_file_system_types ()
 {
+	ped_file_system_zfs_done ();
 	ped_file_system_nilfs2_done ();
 	ped_file_system_ext2_done ();
 	ped_file_system_f2fs_done ();