Tiny kprintf implementation, only decimal and hexadecimal output (unsigned).
[AROS.git] / test / partition.c
blob092034d37cb8520338d8dc75ac9fe35129ce1f5e
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
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>
14 #include <stdio.h>
15 #include <stdlib.h>
17 struct PartitionBase *PartitionBase;
19 LONG PrintPartitionTable(struct PartitionHandle *root, ULONG i);
21 static UQUAD getStartBlock(struct PartitionHandle *ph)
23 ULONG ret = 0;
25 while (ph)
27 UQUAD start;
29 GetPartitionAttrsTags(ph, PT_STARTBLOCK, &start, TAG_DONE);
30 ret += start;
31 ph = ph->root;
34 return ret;
37 void PrintDE(struct DosEnvec *de, ULONG i) {
38 ULONG a;
40 for (a=i;a;a--)
41 printf(" ");
42 printf("SizeBlock = %ld\n", de->de_SizeBlock<<2);
43 for (a=i;a;a--)
44 printf(" ");
45 printf("Surfaces = %ld\n", de->de_Surfaces);
46 for (a=i;a;a--)
47 printf(" ");
48 printf("BlocksPerTrack = %ld\n", de->de_BlocksPerTrack);
49 for (a=i;a;a--)
50 printf(" ");
51 printf("LowCyl = %ld\n", de->de_LowCyl);
52 for (a=i;a;a--)
53 printf(" ");
54 printf("HighCyl = %ld\n", de->de_HighCyl);
57 void PrintPInfo(struct PartitionHandle *ph, ULONG i)
59 struct DosEnvec de;
60 UBYTE name[32];
61 struct PartitionType type;
62 ULONG a;
63 UQUAD start, end, abs;
65 GetPartitionAttrsTags(ph,
66 PT_DOSENVEC , &de,
67 PT_NAME , name,
68 PT_TYPE , &type,
69 PT_STARTBLOCK, &start,
70 PT_ENDBLOCK , &end,
71 TAG_DONE);
73 for (a=i;a;a--)
74 printf(" ");
75 printf("name: %s\n", name);
76 for (a=i+1;a;a--)
77 printf(" ");
79 printf("type:");
80 for (a = 0; a < type.id_len; a++)
81 printf(" %02X", type.id[a]);
82 printf("\n");
84 PrintDE(&de, i+1);
86 for (a = i + 1; a; a--)
87 printf(" ");
88 printf("StartBlock = %llu\n", (unsigned long long)start);
89 for (a = i + 1; a; a--)
90 printf(" ");
91 printf("EndBlock = %llu\n", (unsigned long long)end);
93 abs = getStartBlock(ph->root);
94 for (a = i + 1; a; a--)
95 printf(" ");
96 printf("Abs StartBlock = %llu\n", (unsigned long long)(start + abs));
97 for (a = i + 1; a; a--)
98 printf(" ");
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));
111 PrintPInfo(ph, i);
112 ph = (struct PartitionHandle *)ph->ln.ln_Succ;
116 LONG PrintPartitionTable(struct PartitionHandle *root, ULONG i)
118 struct DosEnvec de;
119 ULONG type = 0;
120 ULONG reserved = 0;
121 ULONG a;
123 a = OpenPartitionTable(root);
124 if (a)
125 return a;
127 GetPartitionTableAttrsTags(root,
128 PTT_TYPE , &type,
129 PTT_RESERVED, &reserved,
130 TAG_DONE);
131 GetPartitionAttrsTags(root, PT_DOSENVEC, &de, TAG_DONE);
133 for (a=i;a;a--)
134 printf(" ");
135 printf("Partition table type is ");
136 switch (type)
138 case PHPTT_RDB:
139 printf("Rigid Disk Block\n");
140 break;
142 case PHPTT_MBR:
143 printf("MBR -> PC\n");
144 break;
146 case PHPTT_EBR:
147 printf("EBR -> PC\n");
148 break;
150 default:
151 printf("unknown\n");
152 break;
155 for (a=i;a;a--)
156 printf(" ");
157 printf("reserved blocks: %d\n", (int)reserved);
159 PrintDE(&de,i);
160 for (a=i;a;a--)
161 printf(" ");
162 printf("partitions:\n");
163 PrintPartitions(root,i+1);
164 ClosePartitionTable(root);
166 return 0;
169 int main(int argc, char **argv)
171 struct PartitionHandle *root;
172 char *device = "fdsk.device";
173 ULONG unit = 1;
175 if (argc > 2)
177 device = argv[1];
178 unit = atoi(argv[2]);
181 PartitionBase = (struct PartitionBase *)OpenLibrary("partition.library", 1);
182 if (PartitionBase)
184 root = OpenRootPartition(device, unit);
185 if (root)
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);
194 else
195 printf("No root handle for %s unit %d\n", device, (int)unit);
196 CloseLibrary((struct Library *)PartitionBase);
198 else
199 printf("No partition.library\n");
201 return 0;