1/*
2 * Copyright (c) 2003-2007 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * You can do a pretty grueling self-test with:
25 * find -x /System -print0 | xargs -0 -n 1 ./build/testgetfileid  | grep -v ^Success:
26 */
27
28#define DEBUG 1
29
30#include <libc.h>
31#include <stdint.h>
32#include <inttypes.h>
33#include <sys/mount.h>
34#include <bless.h>
35#include <AssertMacros.h>
36
37void usage() {
38    fprintf(stderr, "Usage: %s device\n", getprogname());
39    exit(1);
40}
41
42int main(int argc, char *argv[]) {
43
44    char *dev;
45    char parentDev[MNAMELEN];
46    unsigned long slice = 0;
47    BLPartitionType pmapType;
48    char *typestr;
49
50    if(argc != 2) {
51	usage();
52    }
53
54    dev = argv[1];
55
56    require_noerr(BLGetParentDeviceAndPartitionType(NULL,
57					       dev,
58					       parentDev,
59					       &slice,
60					       &pmapType),
61		  failed);
62
63    printf("Partition: %s\n", dev);
64    printf("Parent: %s\n", parentDev);
65    printf("Slice: %lu\n", slice);
66    if(pmapType == kBLPartitionType_APM) {
67	typestr = "Apple Partition Map";
68    } else if(pmapType == kBLPartitionType_MBR) {
69	typestr = "FDisk Partition Map";
70    } else {
71	typestr = "Unknown";
72    }
73
74    printf("Partition Type: %s\n", typestr);
75
76    return 0;
77
78failed:
79	return 1;
80}
81
82