OSDN Git Service

8dcd72155667d333ea9ce83487e9330b20d73b57
[android-x86/external-parted.git] / libparted / labels / aix.c
1 /* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
3     libparted - a library for manipulating disk partitions
4     Copyright (C) 2000, 2001 Free Software Foundation, Inc.
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20     Contributor:  Matt Wilson <msw@redhat.com>
21 */
22
23 #include "config.h"
24
25 #include <parted/parted.h>
26 #include <parted/debug.h>
27 #include <parted/endian.h>
28
29 #if ENABLE_NLS
30 #  include <libintl.h>
31 #  define _(String) dgettext (PACKAGE, String)
32 #else
33 #  define _(String) (String)
34 #endif /* ENABLE_NLS */
35
36 typedef struct {
37         unsigned int   magic;        /* expect AIX_LABEL_MAGIC */
38         unsigned int   fillbytes[127];
39 } AixLabel;
40
41 #define AIX_LABEL_MAGIC         0xc9c2d4c1
42
43 static PedDiskType aix_disk_type;
44
45 static int
46 aix_probe (const PedDevice *dev)
47 {
48         PedDiskType*    disk_type;
49         AixLabel        label;
50         int             i;
51
52         PED_ASSERT (dev != NULL, return 0);
53
54         if (!ped_device_read (dev, &label, 0, 1))
55                 return 0;
56
57         if (PED_BE32_TO_CPU (label.magic) != AIX_LABEL_MAGIC)
58                 return 0;
59
60         return 1;
61 }
62
63 #ifndef DISCOVER_ONLY
64 static int
65 aix_clobber (PedDevice* dev)
66 {
67         AixLabel label;
68
69         PED_ASSERT (dev != NULL, return 0);
70         PED_ASSERT (aix_probe (dev), return 0);
71
72         if (!ped_device_read (dev, &label, 0, 1))
73                 return 0;
74         
75         label.magic = 0;
76         return ped_device_write (dev, &label, 0, 1);
77 }
78 #endif /* !DISCOVER_ONLY */
79
80 static PedDisk*
81 aix_alloc (const PedDevice* dev)
82 {
83         PedDisk*        disk;
84
85         disk = _ped_disk_alloc (dev, &aix_disk_type);
86         if (!disk)
87                 return NULL;
88
89         return disk;
90 }
91
92 static PedDisk*
93 aix_duplicate (const PedDisk* disk)
94 {
95         PedDisk*        new_disk;
96        
97         new_disk = ped_disk_new_fresh (disk->dev, &aix_disk_type);
98         if (!new_disk)
99                 return NULL;
100
101         return new_disk;
102 }
103
104 static void
105 aix_free (PedDisk *disk)
106 {
107         _ped_disk_free (disk);
108 }
109
110 static int
111 aix_read (PedDisk* disk)
112 {
113         ped_disk_delete_all (disk);
114         ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
115                              PED_EXCEPTION_CANCEL,
116                              _("Support for reading AIX disk labels is "
117                                "is not implemented yet."));
118         return 0;
119 }
120
121 #ifndef DISCOVER_ONLY
122 static int
123 aix_write (PedDisk* disk)
124 {
125         ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
126                              PED_EXCEPTION_CANCEL,
127                              _("Support for writing AIX disk labels is "
128                                "is not implemented yet."));
129         return 0;
130 }
131 #endif /* !DISCOVER_ONLY */
132
133 static PedPartition*
134 aix_partition_new (const PedDisk* disk, PedPartitionType part_type,
135                    const PedFileSystemType* fs_type,
136                    PedSector start, PedSector end)
137 {
138         PedPartition*           part;
139
140         ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
141                              PED_EXCEPTION_CANCEL,
142                              _("Support for adding partitions to AIX disk "
143                                "labels is not implemented yet."));
144         return NULL;
145 }
146
147 static PedPartition*
148 aix_partition_duplicate (const PedPartition* part)
149 {
150         PedPartition*           new_part;
151
152         ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
153                              PED_EXCEPTION_CANCEL,
154                              _("Support for duplicating partitions in AIX "
155                                "disk labels is not implemented yet."));
156         return NULL;
157 }
158
159 static void
160 aix_partition_destroy (PedPartition* part)
161 {
162         PED_ASSERT (part != NULL, return);
163
164         _ped_partition_free (part);
165 }
166
167 static int
168 aix_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
169 {
170         ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
171                              PED_EXCEPTION_CANCEL,
172                              _("Support for setting system type of partitions "
173                                "in AIX disk labels is not implemented yet."));
174         return 0;
175 }
176
177 static int
178 aix_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state)
179 {
180         ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
181                              PED_EXCEPTION_CANCEL,
182                              _("Support for setting flags "
183                                "in AIX disk labels is not implemented yet."));
184         return 0;
185 }
186
187 static int
188 aix_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
189 {
190         return 0;
191 }
192
193
194 static int
195 aix_partition_is_flag_available (const PedPartition* part,
196                                  PedPartitionFlag flag)
197 {
198         return 0;
199 }
200
201
202 static int
203 aix_get_max_primary_partition_count (const PedDisk* disk)
204 {
205         return 4;
206 }
207
208 static int
209 aix_partition_align (PedPartition* part, const PedConstraint* constraint)
210 {
211         PED_ASSERT (part != NULL, return 0);
212
213         return 1;
214 }
215
216 static int
217 aix_partition_enumerate (PedPartition* part)
218 {
219         return 1;
220 }
221
222 static int
223 aix_alloc_metadata (PedDisk* disk)
224 {
225         return 1;
226 }
227
228 static PedDiskOps aix_disk_ops = {
229         probe:                  aix_probe,
230 #ifndef DISCOVER_ONLY
231         clobber:                aix_clobber,
232 #else
233         clobber:                NULL,
234 #endif
235         alloc:                  aix_alloc,
236         duplicate:              aix_duplicate,
237         free:                   aix_free,
238         read:                   aix_read,
239 #ifndef DISCOVER_ONLY
240         write:                  aix_write,
241 #else
242         write:                  NULL,
243 #endif
244
245         partition_new:          aix_partition_new,
246         partition_duplicate:    aix_partition_duplicate,
247         partition_destroy:      aix_partition_destroy,
248         partition_set_system:   aix_partition_set_system,
249         partition_set_flag:     aix_partition_set_flag,
250         partition_get_flag:     aix_partition_get_flag,
251         partition_is_flag_available:    aix_partition_is_flag_available,
252         partition_align:        aix_partition_align,
253         partition_enumerate:    aix_partition_enumerate,
254         alloc_metadata:         aix_alloc_metadata,
255         get_max_primary_partition_count:
256                                 aix_get_max_primary_partition_count,
257
258         partition_set_name:             NULL,
259         partition_get_name:             NULL,
260 };
261
262 static PedDiskType aix_disk_type = {
263         next:           NULL,
264         name:           "aix",
265         ops:            &aix_disk_ops,
266         features:       0
267 };
268
269 void
270 ped_disk_aix_init ()
271 {
272         PED_ASSERT (sizeof (AixLabel) == 512, return);
273         ped_disk_type_register (&aix_disk_type);
274 }
275
276 void
277 ped_disk_aix_done ()
278 {
279         ped_disk_type_unregister (&aix_disk_type);
280 }