Always return 0 in OM_SET (instead of TRUE). texteditor
[tangerine.git] / test / partition.c
blobbb5aa0c703d6b9f3935ca68a5cdacdb3a01b14ed
1 #include <stdio.h>
2 #include <proto/exec.h>
3 #include <proto/partition.h>
4 #include <libraries/partition.h>
5 #include <utility/tagitem.h>
7 struct PartitionBase *PartitionBase;
9 void PrintDE(struct DosEnvec *de, ULONG i) {
10 ULONG a;
12 for (a=i;a;a--)
13 printf(" ");
14 printf("SizeBlock = %ld\n", de->de_SizeBlock<<2);
15 for (a=i;a;a--)
16 printf(" ");
17 printf("Surfaces = %ld\n", de->de_Surfaces);
18 for (a=i;a;a--)
19 printf(" ");
20 printf("BlocksPerTrack = %ld\n", de->de_BlocksPerTrack);
21 for (a=i;a;a--)
22 printf(" ");
23 printf("LowCyl = %ld\n", de->de_LowCyl);
24 for (a=i;a;a--)
25 printf(" ");
26 printf("HighCyl = %ld\n", de->de_HighCyl);
29 LONG GetPartitionAttrsA(struct PartitionHandle *ph, LONG tag, ...) {
31 return GetPartitionAttrs(ph, (struct TagItem *)&tag);
34 void PrintPInfo(struct PartitionHandle *ph, ULONG i) {
35 struct DosEnvec de;
36 UBYTE name[32];
37 LONG type;
38 ULONG a;
40 GetPartitionAttrsA
42 ph,
43 PT_DOSENVEC, &de,
44 PT_NAME, name,
45 PT_TYPE, &type,
46 TAG_DONE
48 for (a=i;a;a--)
49 printf(" ");
50 printf("name: %s\n", name);
51 for (a=i+1;a;a--)
52 printf(" ");
53 printf("type: %lx\n", type);
54 PrintDE(&de, i+1);
57 void PrintPartitions(struct PartitionHandle *root, ULONG i) {
58 struct PartitionHandle *ph;
60 ph = (struct PartitionHandle *)root->table->list.lh_Head;
61 while (ph->ln.ln_Succ)
63 PrintPInfo(ph, i);
64 ph = (struct PartitionHandle *)ph->ln.ln_Succ;
68 LONG GetPartitionTableAttrsA(struct PartitionHandle *ph, LONG tag, ...) {
69 //FIXME: buggy
70 return GetPartitionTableAttrs(ph, (struct TagItem *) &tag);
73 void PrintPartitionTable(struct PartitionHandle *root, ULONG i) {
74 struct DosEnvec de;
75 ULONG type;
76 ULONG reserved;
77 ULONG a;
79 if (OpenPartitionTable(root)==0)
81 GetPartitionTableAttrsA
83 root,
84 PTT_TYPE, &type,
85 PTT_RESERVED, &reserved,
86 TAG_DONE
88 GetPartitionAttrsA(root, PT_DOSENVEC, &de, TAG_DONE);
89 for (a=i;a;a--)
90 printf(" ");
91 printf("Partition type is ");
92 switch (type)
94 case PHPTT_UNKNOWN:
95 printf("unknown\n");
96 break;
97 case PHPTT_RDB:
98 printf("Rigid Disk Block\n");
99 break;
100 case PHPTT_MBR:
101 printf("MBR -> PC\n");
102 break;
104 for (a=i;a;a--)
105 printf(" ");
106 printf("reserved blocks: %ld\n", reserved);
107 PrintDE(&de,i);
108 for (a=i;a;a--)
109 printf(" ");
110 printf("partitions:\n");
111 PrintPartitions(root,i+1);
112 ClosePartitionTable(root);
114 else
115 printf("Couldn't read partition table\n");
118 int main(void) {
119 struct PartitionHandle *root;
120 char *device = "fdsk.device";
121 ULONG unit = 1;
123 PartitionBase = (struct PartitionBase *)OpenLibrary("partition.library", 1);
124 if (PartitionBase)
126 root = OpenRootPartition(device, unit);
127 if (root)
129 printf("got root handle of %s unit %ld\n", device, unit);
130 PrintPartitionTable(root, 0);
131 CloseRootPartition(root);
133 else
134 printf("No root handle\n");
135 CloseLibrary((struct Library *)PartitionBase);
137 else
138 printf("No partition.library\n");
140 return 0;