/* * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights * Reserved. This file contains Original Code and/or Modifications of * Original Code as defined in and that are subject to the Apple Public * Source License Version 1.0 (the 'License'). You may not use this file * except in compliance with the License. Please obtain a copy of the * License at http://www.apple.com/publicsource and read it before using * this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License." * * @APPLE_LICENSE_HEADER_END@ */ #include #ifndef __linux__ #include #include #endif #include #include #include #include "io.h" #include "errors.h" #ifdef __APPLE__ #include #endif #import "pdisk.h" #import "partition_map.h" #import "dump.h" #define MIN_PARTITION_SIZE 4 typedef int (*funcPtr_t)(); typedef struct { unsigned char * name; funcPtr_t func; int nargs; unsigned char * description; } cmdline_option_t; static int block_size(); static int create_partition(); static int delete_partition(); static int disk_is_partitioned(); static int disk_size(); static int get_partition_of_type(); static int get_partition_with_name(); static int initialize(); static int make_bootable(); static int our_dump(); static int partition_display(); static int split_partition(); static int set_automount(); static int set_writable(); cmdline_option_t optionTable[] = { { "-blockSize", block_size, 0, "display the block size used by the map" }, { "-dump", our_dump, 0, "dump the list of partitions" }, { "-isDiskPartitioned", disk_is_partitioned, 0, "is the disk partitioned" }, { "-diskSize", disk_size, 0, "prints the size of the disk in megs" }, { "-partitionSize", partition_display, 0, "get the partition size in blocks" }, { "-partitionBase", partition_display, 0, "get the partition base in blocks" }, { "-partitionType", partition_display, 0, "get the partition type" }, { "-partitionName", partition_display, 0, "get the partition name" }, { "-partitionEntry", partition_display, 0, "get the partition name, type, base, and size" }, { "-splitPartition", split_partition, 0, "split an existing partition in two pieces" }, { "-createPartition", create_partition, 0, "create a new partition" }, { "-initialize", initialize, 0, "initialize the partition map" }, { "-deletePartition", delete_partition, 0, "delete a partition" }, { "-getPartitionOfType", get_partition_of_type, 0, "get partition of specified type" }, { "-getPartitionWithName", get_partition_with_name, 0, "get partition with specified name" }, { "-makeBootable", make_bootable, 0, "make a partition bootable" }, { "-setAutoMount", set_automount, 0, "set or clear the auto-mount bit for HFS volumes" }, { "-setWritable", set_writable, 0, "set or clear the writable bit in the pmap" }, { 0, 0, 0 }, }; static void command_usage() { fprintf(stderr, "usage:\tpdisk