1 /*
2 libparted - a library for manipulating disk partitions
3 Copyright (C) 2001, 2007 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20
21 #include <parted/parted.h>
22 #include <parted/endian.h>
23
24 #define _JFS_UTILITY
25 #include "jfs_types.h"
26 #include "jfs_superblock.h"
27
28 #define JFS_SUPER_SECTOR 64
29
30 #if ENABLE_NLS
31 # include <libintl.h>
32 # define _(String) dgettext (PACKAGE, String)
33 #else
34 # define _(String) (String)
35 #endif /* ENABLE_NLS */
36
37 #define JFS_BLOCK_SIZES ((int[2]){512, 0})
38
39 static PedGeometry*
40 jfs_probe (PedGeometry* geom)
41 {
42 union {
43 struct superblock sb;
44 char bytes[512];
45 } buf;
46
47 if (geom->length < JFS_SUPER_SECTOR + 1)
48 return NULL;
49 if (!ped_geometry_read (geom, &buf, JFS_SUPER_SECTOR, 1))
50 return NULL;
51
52 if (strncmp (buf.sb.s_magic, JFS_MAGIC, 4) == 0) {
53 PedSector block_size = PED_LE32_TO_CPU (buf.sb.s_pbsize) / 512;
54 PedSector block_count = PED_LE64_TO_CPU (buf.sb.s_size);
55
56 return ped_geometry_new (geom->dev, geom->start,
57 block_size * block_count);
58 } else {
59 return NULL;
60 }
61 }
62
63 #ifndef DISCOVER_ONLY
64 static int
65 jfs_clobber (PedGeometry* geom)
66 {
67 char buf[512];
68
69 memset (buf, 0, 512);
70 return ped_geometry_write (geom, buf, JFS_SUPER_SECTOR, 1);
71 }
72 #endif /* !DISCOVER_ONLY */
73
74 static PedFileSystemOps jfs_ops = {
75 .probe = jfs_probe,
76 #ifndef DISCOVER_ONLY
77 .clobber = jfs_clobber,
78 #else
79 .clobber = NULL,
80 #endif
81 .open = NULL,
82 .create = NULL,
83 .close = NULL,
84 .check = NULL,
85 .copy = NULL,
86 .resize = NULL,
87 .get_create_constraint = NULL,
88 .get_resize_constraint = NULL,
89 .get_copy_constraint = NULL
90 };
91
92 static PedFileSystemType jfs_type = {
93 .next = NULL,
94 .ops = &jfs_ops,
95 .name = "jfs",
96 .block_sizes = JFS_BLOCK_SIZES
97 };
98
99 void
100 ped_file_system_jfs_init ()
101 {
102 ped_file_system_type_register (&jfs_type);
103 }
104
105 void
106 ped_file_system_jfs_done ()
107 {
108 ped_file_system_type_unregister (&jfs_type);
109 }