2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include <proto/partition.h>
11 #include <libraries/partition.h>
12 #include <utility/tagitem.h>
17 struct PartitionBase
*PartitionBase
;
19 LONG
PrintPartitionTable(struct PartitionHandle
*root
, ULONG i
);
21 static UQUAD
getStartBlock(struct PartitionHandle
*ph
)
29 GetPartitionAttrsTags(ph
, PT_STARTBLOCK
, &start
, TAG_DONE
);
37 void PrintDE(struct DosEnvec
*de
, ULONG i
) {
42 printf("SizeBlock = %ld\n", de
->de_SizeBlock
<<2);
45 printf("Surfaces = %ld\n", de
->de_Surfaces
);
48 printf("BlocksPerTrack = %ld\n", de
->de_BlocksPerTrack
);
51 printf("LowCyl = %ld\n", de
->de_LowCyl
);
54 printf("HighCyl = %ld\n", de
->de_HighCyl
);
57 void PrintPInfo(struct PartitionHandle
*ph
, ULONG i
)
61 struct PartitionType type
;
63 UQUAD start
, end
, abs
;
65 GetPartitionAttrsTags(ph
,
69 PT_STARTBLOCK
, &start
,
75 printf("name: %s\n", name
);
80 for (a
= 0; a
< type
.id_len
; a
++)
81 printf(" %02X", type
.id
[a
]);
86 for (a
= i
+ 1; a
; a
--)
88 printf("StartBlock = %llu\n", (unsigned long long)start
);
89 for (a
= i
+ 1; a
; a
--)
91 printf("EndBlock = %llu\n", (unsigned long long)end
);
93 abs
= getStartBlock(ph
->root
);
94 for (a
= i
+ 1; a
; a
--)
96 printf("Abs StartBlock = %llu\n", (unsigned long long)(start
+ abs
));
97 for (a
= i
+ 1; a
; a
--)
99 printf("Abs EndBlock = %llu\n", (unsigned long long)(end
+ abs
));
101 PrintPartitionTable(ph
, i
+ 1);
104 void PrintPartitions(struct PartitionHandle
*root
, ULONG i
) {
105 struct PartitionHandle
*ph
;
107 ph
= (struct PartitionHandle
*)root
->table
->list
.lh_Head
;
108 while (ph
->ln
.ln_Succ
)
110 D(printf("PartitionHandle 0x%p\n", ph
));
112 ph
= (struct PartitionHandle
*)ph
->ln
.ln_Succ
;
116 LONG
PrintPartitionTable(struct PartitionHandle
*root
, ULONG i
)
123 a
= OpenPartitionTable(root
);
127 GetPartitionTableAttrsTags(root
,
129 PTT_RESERVED
, &reserved
,
131 GetPartitionAttrsTags(root
, PT_DOSENVEC
, &de
, TAG_DONE
);
135 printf("Partition table type is ");
139 printf("Rigid Disk Block\n");
143 printf("MBR -> PC\n");
147 printf("EBR -> PC\n");
157 printf("reserved blocks: %d\n", (int)reserved
);
162 printf("partitions:\n");
163 PrintPartitions(root
,i
+1);
164 ClosePartitionTable(root
);
169 int main(int argc
, char **argv
)
171 struct PartitionHandle
*root
;
172 char *device
= "fdsk.device";
178 unit
= atoi(argv
[2]);
181 PartitionBase
= (struct PartitionBase
*)OpenLibrary("partition.library", 1);
184 root
= OpenRootPartition(device
, unit
);
187 printf("got root handle of %s unit %d\n", device
, (int)unit
);
189 if (PrintPartitionTable(root
, 0))
190 printf("Couldn't read partition table\n");
192 CloseRootPartition(root
);
195 printf("No root handle for %s unit %d\n", device
, (int)unit
);
196 CloseLibrary((struct Library
*)PartitionBase
);
199 printf("No partition.library\n");