1 /* 2 libparted - a library for manipulating disk partitions 3 Copyright (C) 2001 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 #if ENABLE_NLS 25 # include <libintl.h> 26 # define _(String) dgettext (PACKAGE, String) 27 #else 28 # define _(String) (String) 29 #endif /* ENABLE_NLS */ 30 31 #include <uuid/uuid.h> 32 #include "platform_defs.h" 33 #include "xfs_types.h" 34 #include "xfs_sb.h" 35 36 #define XFS_BLOCK_SIZES ((int[2]){512, 0}) 37 38 static PedGeometry* 39 xfs_probe (PedGeometry* geom) 40 { 41 PedSector block_size; 42 PedSector block_count; 43 union { 44 struct xfs_sb sb; 45 char bytes [512]; 46 } buf; 47 48 if (geom->length < XFS_SB_DADDR + 1) 49 return NULL; 50 if (!ped_geometry_read (geom, &buf, XFS_SB_DADDR, 1)) 51 return NULL; 52 53 if (PED_LE32_TO_CPU (buf.sb.sb_magicnum) == XFS_SB_MAGIC) { 54 block_size = PED_LE32_TO_CPU (buf.sb.sb_blocksize) / 512; 55 block_count = PED_LE64_TO_CPU (buf.sb.sb_dblocks); 56 57 return ped_geometry_new (geom->dev, geom->start, 58 block_size * block_count); 59 } 60 61 if (PED_BE32_TO_CPU (buf.sb.sb_magicnum) == XFS_SB_MAGIC) { 62 block_size = PED_BE32_TO_CPU (buf.sb.sb_blocksize) / 512; 63 block_count = PED_BE64_TO_CPU (buf.sb.sb_dblocks); 64 65 return ped_geometry_new (geom->dev, geom->start, 66 block_size * block_count); 67 } 68 69 return NULL; 70 } 71 72 #ifndef DISCOVER_ONLY 73 static int 74 xfs_clobber (PedGeometry* geom) 75 { 76 char buf[512]; 77 78 memset (buf, 0, 512); 79 return ped_geometry_write (geom, buf, XFS_SB_DADDR, 1); 80 } 81 #endif /* !DISCOVER_ONLY */ 82 83 static PedFileSystemOps xfs_ops = { 84 .probe = xfs_probe, 85 #ifndef DISCOVER_ONLY 86 .clobber = xfs_clobber, 87 #else 88 .clobber = NULL, 89 #endif 90 .open = NULL, 91 .create = NULL, 92 .close = NULL, 93 .check = NULL, 94 .copy = NULL, 95 .resize = NULL, 96 .get_create_constraint = NULL, 97 .get_resize_constraint = NULL, 98 .get_copy_constraint = NULL 99 }; 100 101 static PedFileSystemType xfs_type = { 102 .next = NULL, 103 .ops = &xfs_ops, 104 .name = "xfs", 105 .block_sizes = XFS_BLOCK_SIZES 106 }; 107 108 void 109 ped_file_system_xfs_init () 110 { 111 ped_file_system_type_register (&xfs_type); 112 } 113 114 void 115 ped_file_system_xfs_done () 116 { 117 ped_file_system_type_unregister (&xfs_type); 118 } 119