1N/A/*
1N/A apfs.c -- parted support for apfs file systems
1N/A Copyright (C) 1998-2000, 2007, 2009-2010 Free Software Foundation,
1N/A Inc.
1N/A
1N/A This program is free software; you can redistribute it and/or modify
1N/A it under the terms of the GNU General Public License as published by
1N/A the Free Software Foundation; either version 3 of the License, or
1N/A (at your option) any later version.
1N/A
1N/A This program is distributed in the hope that it will be useful,
1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A GNU General Public License for more details.
1N/A
1N/A You should have received a copy of the GNU General Public License
1N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
1N/A*/
1N/A
1N/A#include <config.h>
1N/A
1N/A#include <parted/parted.h>
1N/A#include <parted/debug.h>
1N/A#include <parted/endian.h>
1N/A
1N/A#include "amiga.h"
1N/A#include "apfs.h"
1N/A
1N/A#if ENABLE_NLS
1N/A# include <libintl.h>
1N/A# define _(String) dgettext (PACKAGE, String)
1N/A#else
1N/A# define _(String) (String)
1N/A#endif /* ENABLE_NLS */
1N/A
1N/Astatic int
1N/A_apfs_probe_root (uint32_t *block, uint32_t blocksize, uint32_t kind) {
1N/A if (PED_BE32_TO_CPU (block[0]) != kind) return 0;
1N/A return 1;
1N/A}
1N/A
1N/Astatic PedGeometry*
1N/A_generic_apfs_probe (PedGeometry* geom, uint32_t kind)
1N/A{
1N/A uint32_t *block;
1N/A PedSector root;
1N/A struct PartitionBlock * part;
1N/A uint32_t blocksize = 1, reserved = 2;
1N/A
1N/A PED_ASSERT (geom != NULL, return NULL);
1N/A PED_ASSERT (geom->dev != NULL, return NULL);
1N/A
1N/A /* Finds the blocksize and reserved values of the partition block */
1N/A if (!(part = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) {
1N/A ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1N/A _("%s : Failed to allocate partition block\n"), __func__);
1N/A goto error_part;
1N/A }
1N/A if (amiga_find_part(geom, part) != NULL) {
1N/A reserved = PED_BE32_TO_CPU (part->de_Reserved);
1N/A blocksize = PED_BE32_TO_CPU (part->de_SizeBlock)
1N/A * PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128;
1N/A }
1N/A free (part);
1N/A
1N/A /* Test boot block */
1N/A if (!(block = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) {
1N/A ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1N/A _("%s : Failed to allocate block\n"), __func__);
1N/A goto error_block;
1N/A }
1N/A if (!ped_device_read (geom->dev, block, geom->start, blocksize)) {
1N/A ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1N/A _("%s : Couldn't read boot block %llu\n"), __func__, geom->start);
1N/A goto error;
1N/A }
1N/A if (PED_BE32_TO_CPU (block[0]) != kind) {
1N/A goto error;
1N/A }
1N/A
1N/A /* Find and test the root block */
1N/A root = geom->start+reserved*blocksize;
1N/A if (!ped_device_read (geom->dev, block, root, blocksize)) {
1N/A ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
1N/A _("%s : Couldn't read root block %llu\n"), __func__, root);
1N/A goto error;
1N/A }
1N/A if (_apfs_probe_root(block, blocksize, kind) == 1) {
1N/A free(block);
1N/A return ped_geometry_duplicate (geom);
1N/A }
1N/A
1N/Aerror:
1N/A free (block);
1N/Aerror_block:
1N/Aerror_part:
1N/A return NULL;
1N/A}
1N/A
1N/Astatic PedGeometry*
1N/A_apfs1_probe (PedGeometry* geom) {
1N/A return _generic_apfs_probe (geom, 0x50463101);
1N/A}
1N/A
1N/Astatic PedGeometry*
1N/A_apfs2_probe (PedGeometry* geom) {
1N/A return _generic_apfs_probe (geom, 0x50463102);
1N/A}
1N/A
1N/Astatic PedFileSystemOps _apfs1_ops = {
1N/A .probe = _apfs1_probe,
1N/A .clobber = NULL,
1N/A .open = NULL,
1N/A .create = NULL,
1N/A .close = NULL,
1N/A .check = NULL,
1N/A .resize = NULL,
1N/A .copy = NULL,
1N/A .get_create_constraint = NULL,
1N/A .get_copy_constraint = NULL,
1N/A .get_resize_constraint = NULL
1N/A};
1N/Astatic PedFileSystemOps _apfs2_ops = {
1N/A .probe = _apfs2_probe,
1N/A .clobber = NULL,
1N/A .open = NULL,
1N/A .create = NULL,
1N/A .close = NULL,
1N/A .check = NULL,
1N/A .resize = NULL,
1N/A .copy = NULL,
1N/A .get_create_constraint = NULL,
1N/A .get_copy_constraint = NULL,
1N/A .get_resize_constraint = NULL
1N/A};
1N/A
1N/A#define APFS_BLOCK_SIZES ((int[2]){512, 0})
1N/A
1N/APedFileSystemType _apfs1_type = {
1N/A .next = NULL,
1N/A .ops = &_apfs1_ops,
1N/A .name = "apfs1",
1N/A .block_sizes = APFS_BLOCK_SIZES
1N/A};
1N/APedFileSystemType _apfs2_type = {
1N/A .next = NULL,
1N/A .ops = &_apfs2_ops,
1N/A .name = "apfs2",
1N/A .block_sizes = APFS_BLOCK_SIZES
1N/A};