rom/exec: Added SaveTaskStorage() and the RestoreTaskStorage() functions.
[AROS.git] / test / partition.c
blob526c6c62870cc5eda542c7cffa6376271cceca11
1 #define DEBUG 0
3 #include <aros/debug.h>
4 #include <proto/exec.h>
5 #include <proto/partition.h>
6 #include <libraries/partition.h>
7 #include <utility/tagitem.h>
9 #include <stdio.h>
10 #include <stdlib.h>
12 struct PartitionBase *PartitionBase;
14 LONG PrintPartitionTable(struct PartitionHandle *root, ULONG i);
16 static ULONG getStartBlock(struct PartitionHandle *ph)
18 ULONG ret = 0;
20 while (ph)
22 ULONG start;
24 GetPartitionAttrsTags(ph, PT_STARTBLOCK, &start, TAG_DONE);
25 ret += start;
26 ph = ph->root;
29 return ret;
32 void PrintDE(struct DosEnvec *de, ULONG i) {
33 ULONG a;
35 for (a=i;a;a--)
36 printf(" ");
37 printf("SizeBlock = %ld\n", de->de_SizeBlock<<2);
38 for (a=i;a;a--)
39 printf(" ");
40 printf("Surfaces = %ld\n", de->de_Surfaces);
41 for (a=i;a;a--)
42 printf(" ");
43 printf("BlocksPerTrack = %ld\n", de->de_BlocksPerTrack);
44 for (a=i;a;a--)
45 printf(" ");
46 printf("LowCyl = %ld\n", de->de_LowCyl);
47 for (a=i;a;a--)
48 printf(" ");
49 printf("HighCyl = %ld\n", de->de_HighCyl);
52 void PrintPInfo(struct PartitionHandle *ph, ULONG i)
54 struct DosEnvec de;
55 UBYTE name[32];
56 struct PartitionType type;
57 ULONG a;
58 ULONG start, end, abs;
60 GetPartitionAttrsTags(ph,
61 PT_DOSENVEC , &de,
62 PT_NAME , name,
63 PT_TYPE , &type,
64 PT_STARTBLOCK, &start,
65 PT_ENDBLOCK , &end,
66 TAG_DONE);
68 for (a=i;a;a--)
69 printf(" ");
70 printf("name: %s\n", name);
71 for (a=i+1;a;a--)
72 printf(" ");
74 printf("type:");
75 for (a = 0; a < type.id_len; a++)
76 printf(" %02X", type.id[a]);
77 printf("\n");
79 PrintDE(&de, i+1);
81 for (a = i + 1; a; a--)
82 printf(" ");
83 printf("StartBlock = %d\n", (int)start);
84 for (a = i + 1; a; a--)
85 printf(" ");
86 printf("EndBlock = %d\n", (int)end);
88 abs = getStartBlock(ph->root);
89 for (a = i + 1; a; a--)
90 printf(" ");
91 printf("Abs StartBlock = %d\n", (int)(start + abs));
92 for (a = i + 1; a; a--)
93 printf(" ");
94 printf("Abs EndBlock = %d\n", (int)(end + abs));
96 PrintPartitionTable(ph, i + 1);
99 void PrintPartitions(struct PartitionHandle *root, ULONG i) {
100 struct PartitionHandle *ph;
102 ph = (struct PartitionHandle *)root->table->list.lh_Head;
103 while (ph->ln.ln_Succ)
105 D(printf("PartitionHandle 0x%p\n", ph));
106 PrintPInfo(ph, i);
107 ph = (struct PartitionHandle *)ph->ln.ln_Succ;
111 LONG PrintPartitionTable(struct PartitionHandle *root, ULONG i)
113 struct DosEnvec de;
114 ULONG type = 0;
115 ULONG reserved = 0;
116 ULONG a;
118 a = OpenPartitionTable(root);
119 if (a)
120 return a;
122 GetPartitionTableAttrsTags(root,
123 PTT_TYPE , &type,
124 PTT_RESERVED, &reserved,
125 TAG_DONE);
126 GetPartitionAttrsTags(root, PT_DOSENVEC, &de, TAG_DONE);
128 for (a=i;a;a--)
129 printf(" ");
130 printf("Partition table type is ");
131 switch (type)
133 case PHPTT_RDB:
134 printf("Rigid Disk Block\n");
135 break;
137 case PHPTT_MBR:
138 printf("MBR -> PC\n");
139 break;
141 case PHPTT_EBR:
142 printf("EBR -> PC\n");
143 break;
145 default:
146 printf("unknown\n");
147 break;
150 for (a=i;a;a--)
151 printf(" ");
152 printf("reserved blocks: %d\n", (int)reserved);
154 PrintDE(&de,i);
155 for (a=i;a;a--)
156 printf(" ");
157 printf("partitions:\n");
158 PrintPartitions(root,i+1);
159 ClosePartitionTable(root);
161 return 0;
164 int main(int argc, char **argv)
166 struct PartitionHandle *root;
167 char *device = "fdsk.device";
168 ULONG unit = 1;
170 if (argc > 2)
172 device = argv[1];
173 unit = atoi(argv[2]);
176 PartitionBase = (struct PartitionBase *)OpenLibrary("partition.library", 1);
177 if (PartitionBase)
179 root = OpenRootPartition(device, unit);
180 if (root)
182 printf("got root handle of %s unit %d\n", device, (int)unit);
184 if (PrintPartitionTable(root, 0))
185 printf("Couldn't read partition table\n");
187 CloseRootPartition(root);
189 else
190 printf("No root handle\n");
191 CloseLibrary((struct Library *)PartitionBase);
193 else
194 printf("No partition.library\n");
196 return 0;