5 #include <proto/exec.h>
6 #include <proto/partition.h>
7 #include <libraries/partition.h>
12 char *listtemplate
= "DEVICE/K/A,UNIT/K/N,PARTITION/K";
13 struct PartitionBase
*PartitionBase
;
15 /************************* list partition **********************************/
16 BOOL
existsAttr(ULONG
*list
, ULONG attr
) {
27 void printPartitionInfo(struct PartitionHandle
*ph
) {
29 struct TagItem tags
[2];
31 pattr
= QueryPartitionAttrs(ph
->root
);
32 tags
[1].ti_Tag
= TAG_DONE
;
36 tags
[0].ti_Tag
= PT_DOSENVEC
;
37 tags
[0].ti_Data
= (STACKIPTR
)&de
;
38 GetPartitionAttrs(ph
, tags
);
43 (QUAD
)(de
.de_HighCyl
-de
.de_LowCyl
+1)*de
.de_Surfaces
*
44 (QUAD
)de
.de_BlocksPerTrack
*(de
.de_SizeBlock
<<2)
48 if (existsAttr(pattr
, PTA_TYPE
))
50 struct PartitionType type
;
53 tags
[0].ti_Tag
= PT_TYPE
;
54 tags
[0].ti_Data
= (STACKIPTR
)&type
;
55 GetPartitionAttrs(ph
, tags
);
57 for (i
=0;i
<type
.id_len
;i
++)
58 printf("%02x", type
.id
[i
]);
61 if (existsAttr(pattr
, PTA_POSITION
))
65 tags
[0].ti_Tag
= PT_POSITION
;
66 tags
[0].ti_Data
= (STACKIPTR
)&pos
;
67 GetPartitionAttrs(ph
, tags
);
68 printf("position: %ld\n", pos
);
70 if (existsAttr(pattr
, PTA_ACTIVE
))
74 tags
[0].ti_Tag
= PT_ACTIVE
;
75 tags
[0].ti_Data
= (STACKIPTR
)&active
;
76 GetPartitionAttrs(ph
, tags
);
77 printf("active: %ld\n", active
);
79 if (existsAttr(pattr
, PTA_NAME
))
83 tags
[0].ti_Tag
= PT_NAME
;
84 tags
[0].ti_Data
= (STACKIPTR
)name
;
85 GetPartitionAttrs(ph
, tags
);
86 printf("name: %s\n", name
);
88 if (existsAttr(pattr
, PTA_BOOTABLE
))
92 tags
[0].ti_Tag
= PT_ACTIVE
;
93 tags
[0].ti_Data
= (STACKIPTR
)&ba
;
94 GetPartitionAttrs(ph
, tags
);
95 printf("bootable: %ld\n", ba
);
97 if (existsAttr(pattr
, PTA_AUTOMOUNT
))
101 tags
[0].ti_Tag
= PT_ACTIVE
;
102 tags
[0].ti_Data
= (STACKIPTR
)&am
;
103 GetPartitionAttrs(ph
, tags
);
104 printf("automount: %ld\n", am
);
108 LONG
nextPartitionTable(struct PartitionHandle
*part
, STRPTR partition
) {
109 LONG retval
= RETURN_FAIL
;
112 struct PartitionHandle
*ph
;
114 pnum
=strtol(partition
, (char **)&newpos
, 0);
117 if (newpos
!= partition
)
119 if (OpenPartitionTable(part
)==0)
121 ph
= (struct PartitionHandle
*)part
->table
->list
.lh_Head
;
122 while (ph
->ln
.ln_Succ
)
127 ph
= (struct PartitionHandle
*)ph
->ln
.ln_Succ
;
135 printPartitionInfo(ph
);
140 retval
=nextPartitionTable(ph
, newpos
);
144 printf("partition not found\n");
145 ClosePartitionTable(part
);
148 printf("no partition table\n");
151 PrintFault(ERROR_BAD_NUMBER
, NULL
);
154 PrintFault(ERROR_BAD_NUMBER
, NULL
);
158 LONG
listPartition(STRPTR device
, ULONG unit
, STRPTR partition
) {
159 LONG retval
= RETURN_FAIL
;
160 struct PartitionHandle
*ph
;
162 PartitionBase
= (struct PartitionBase
*)OpenLibrary("partition.library", 1);
165 ph
= OpenRootPartition(device
, unit
);
168 retval
= nextPartitionTable(ph
, partition
);
169 CloseRootPartition(ph
);
172 printf("Could not open root partition on device %s unit %ld\n", device
, unit
);
173 CloseLibrary((struct Library
*)PartitionBase
);
178 /************************* list partitions *********************************/
179 void printTable(struct PartitionHandle
*root
, WORD depth
) {
180 struct PartitionHandle
*ph
;
181 struct TagItem tags
[2];
185 tags
[1].ti_Tag
= TAG_DONE
;
186 if (OpenPartitionTable(root
) == 0)
188 tags
[0].ti_Tag
= PTT_TYPE
;
189 tags
[0].ti_Data
= (STACKIPTR
)&type
;
190 GetPartitionTableAttrs(root
, tags
);
191 for (i
=0;i
<depth
;i
++) printf("\t");
192 printf("Partition table type = %ld\n", type
);
193 ph
= (struct PartitionHandle
*)root
->table
->list
.lh_Head
;
195 while (ph
->ln
.ln_Succ
)
197 struct PartitionType ptype
;
199 tags
[0].ti_Tag
= PT_TYPE
;
200 tags
[0].ti_Data
= (IPTR
)&ptype
;
201 GetPartitionAttrs(ph
, tags
);
202 for (i
=0;i
<(depth
+1);i
++) printf("\t");
203 printf("Partition %d: type = 0x", j
);
204 for (i
=0;i
<ptype
.id_len
;i
++)
205 printf("%02x", ptype
.id
[i
]);
207 printTable(ph
, depth
+1);
209 ph
= (struct PartitionHandle
*)ph
->ln
.ln_Succ
;
211 ClosePartitionTable(root
);
215 BOOL
listPartitions(STRPTR device
, ULONG unit
) {
216 BOOL retval
= RETURN_FAIL
;
217 struct PartitionHandle
*ph
;
219 PartitionBase
= (struct PartitionBase
*)OpenLibrary("partition.library", 1);
222 ph
= OpenRootPartition(device
, unit
);
227 CloseRootPartition(ph
);
229 CloseLibrary((struct Library
*)PartitionBase
);
234 /***************************** list HDs ************************************/
235 BOOL
printHD(STRPTR device
, ULONG unit
) {
240 if (openIO(&dio
, device
, unit
))
242 if (iscorrectType(dio
.iotd
))
244 printf("\tUnit=%ld: ", unit
);
245 if (identify(dio
.iotd
, id
))
256 LONG
listHDs(STRPTR device
) {
257 LONG retval
= RETURN_OK
;
260 if (strcmp(device
, "ide.device") == 0)
262 else if (strcmp(device
, "scsi.devce") == 0)
266 printf("%s\n", device
);
269 if (!printHD(device
, i
))
271 retval
= RETURN_FAIL
;
278 LONG
list(char *name
, STRPTR args
) {
279 BOOL retval
= RETURN_FAIL
;
280 IPTR myargs
[]={0,0,0,0};
281 struct RDArgs
*rdargs
;
282 struct RDArgs rda
= {{args
, strlen(args
), 0}, 0, 0, 0, NULL
, 0};
284 rda
.RDA_Source
.CS_Buffer
[rda
.RDA_Source
.CS_Length
]='\n';
285 rdargs
= ReadArgs(listtemplate
,myargs
, &rda
);
290 retval
= listPartition
300 retval
= listPartitions((STRPTR
)myargs
[0], *(LONG
*)myargs
[1]);
302 retval
= listHDs((STRPTR
)myargs
[0]);
307 PrintFault(IoErr(), name
);