2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
9 #include <proto/exec.h>
10 #include <proto/gadtools.h>
11 #include <proto/intuition.h>
12 #include <proto/partition.h>
14 #include <devices/trackdisk.h>
15 #include <exec/memory.h>
16 #include <utility/tagitem.h>
18 #include "partitions.h"
19 #include "hdtoolbox_support.h"
25 void setPartitionName(struct HDTBPartition
*pnode
) {
28 sprintf(pnode
->listnode
.ln
.ln_Name
, "Partition %ld", pnode
->pos
);
33 pnode
->listnode
.ln
.ln_Name
,
41 struct HDTBPartition
*newPartition
43 struct ListNode
*parent
,
44 struct HDTBPartition
*partition
47 struct HDTBPartition
*pn
;
49 pn
= AllocMem(sizeof(struct HDTBPartition
), MEMF_PUBLIC
| MEMF_CLEAR
);
52 pn
->listnode
.ln
.ln_Name
= AllocVec(100, MEMF_PUBLIC
| MEMF_CLEAR
);
53 if (pn
->listnode
.ln
.ln_Name
)
55 if (InitListNode(&pn
->listnode
, parent
))
57 pn
->listnode
.ln
.ln_Type
= LNT_Partition
;
61 FreeVec(pn
->listnode
.ln
.ln_Name
);
63 FreeMem(pn
, sizeof(struct HDTBPartition
));
68 void findPartitions(struct ListNode
*parent
, struct HDTBPartition
*partition
) {
69 struct PartitionHandle
*ph
;
70 struct HDTBPartition
*pn
;
75 ph
= (struct PartitionHandle
*)partition
->ph
->table
->list
.lh_Head
;
77 ph
= (struct PartitionHandle
*)ph
->ln
.ln_Succ
80 pn
= newPartition(parent
, partition
);
91 if (getAttrInfo(pn
->root
->table
->pattrlist
, PTA_TYPE
) & PLAM_READ
)
92 GetPartitionAttrsA(pn
->ph
, PT_TYPE
, &pn
->type
, TAG_DONE
);
98 if (getAttrInfo(pn
->root
->table
->pattrlist
, PTA_POSITION
) & PLAM_READ
)
99 GetPartitionAttrsA(pn
->ph
, PT_POSITION
, &pn
->pos
, TAG_DONE
);
102 if (getAttrInfo(pn
->root
->table
->pattrlist
, PTA_NAME
) & PLAM_READ
)
103 GetPartitionAttrsA(pn
->ph
, PT_NAME
, pn
->listnode
.ln
.ln_Name
, TAG_DONE
);
105 setPartitionName(pn
);
106 if (getAttrInfo(pn
->root
->table
->pattrlist
, PTA_BOOTABLE
) & PLAM_READ
)
108 GetPartitionAttrsA(pn
->ph
, PT_BOOTABLE
, &flag
, TAG_DONE
);
110 pn
->flags
|= PNF_BOOTABLE
;
112 if (getAttrInfo(pn
->root
->table
->pattrlist
, PTA_AUTOMOUNT
) & PLAM_READ
)
114 GetPartitionAttrsA(pn
->ph
, PT_AUTOMOUNT
, &flag
, TAG_DONE
);
116 pn
->flags
|= PNF_AUTOMOUNT
;
118 if (getAttrInfo(pn
->root
->table
->pattrlist
, PTA_ACTIVE
) & PLAM_READ
)
120 GetPartitionAttrsA(pn
->ph
, PT_ACTIVE
, &flag
, TAG_DONE
);
122 pn
->flags
|= PNF_ACTIVE
;
124 if (pn
->root
->table
->max_partitions
)
126 pn
->listnode
.ln
.ln_Pri
=pn
->root
->table
->max_partitions
-1-pn
->pos
;
127 Enqueue(&parent
->list
, &pn
->listnode
.ln
);
130 AddTail(&parent
->list
, &pn
->listnode
.ln
);
131 if (findPartitionTable(pn
))
133 findPartitions(&pn
->listnode
, pn
);
134 pn
->listnode
.flags
|= LNF_Listable
;
140 void freePartitionNode(struct HDTBPartition
*node
) {
144 freePartitionList(&node
->listnode
.list
);
145 freePartitionTable(node
);
147 UninitListNode(&node
->listnode
);
148 FreeVec(node
->listnode
.ln
.ln_Name
);
149 FreeMem(node
, sizeof(struct HDTBPartition
));
152 void freePartitionList(struct List
*list
) {
153 struct HDTBPartition
*node
;
154 struct HDTBPartition
*next
;
156 node
= (struct HDTBPartition
*)list
->lh_Head
;
157 while (node
->listnode
.ln
.ln_Succ
)
159 next
= (struct HDTBPartition
*)node
->listnode
.ln
.ln_Succ
;
160 if (node
->listnode
.ln
.ln_Type
!= LNT_Parent
)
162 Remove(&node
->listnode
.ln
);
163 freePartitionNode(node
);
171 struct HDTBPartition
*table
,
172 struct HDTBPartition
*current
,
176 struct HDTBPartition
*pn
;
179 if (value
<table
->table
->reserved
)
181 spc
= table
->dg
.dg_Heads
*table
->dg
.dg_TrackSectors
;
182 if (value
>=(table
->dg
.dg_Cylinders
*spc
))
184 pn
= (struct HDTBPartition
*)table
->listnode
.list
.lh_Head
;
185 while (pn
->listnode
.ln
.ln_Succ
)
187 /* dont't check currently processed partition */
190 spc
= pn
->de
.de_Surfaces
*pn
->de
.de_BlocksPerTrack
;
192 (value
>= (pn
->de
.de_LowCyl
*spc
)) &&
193 (value
< (((pn
->de
.de_HighCyl
+1)*spc
)-1))
197 pn
= (struct HDTBPartition
*)pn
->listnode
.ln
.ln_Succ
;
202 struct PartitionHandle
*AddPartitionA
204 struct PartitionHandle
*root
,
210 return AddPartition(root
, (struct TagItem
*)&tag
);
213 struct HDTBPartition
*addPartition
215 struct HDTBPartition
*table
,
219 struct HDTBPartition
*partition
;
220 struct HDTBPartition
*pn
;
221 struct TableTypeNode
*ttn
;
223 partition
= newPartition(&table
->listnode
, table
);
226 if (table
->table
->max_partitions
)
228 /* find first free position */
230 pn
= (struct HDTBPartition
*)table
->listnode
.list
.lh_Head
;
231 while (pn
->listnode
.ln
.ln_Succ
)
233 if (pn
->listnode
.ln
.ln_Type
!= LNT_Parent
)
237 partition
->pos
= count
;
242 pn
= (struct HDTBPartition
*)pn
->listnode
.ln
.ln_Succ
;
244 if (pn
->listnode
.ln
.ln_Succ
== NULL
)
245 partition
->pos
= count
;
246 partition
->listnode
.ln
.ln_Pri
= table
->table
->max_partitions
-1-partition
->pos
;
247 Enqueue(&table
->listnode
.list
, &partition
->listnode
.ln
);
250 AddTail(&table
->listnode
.list
, &partition
->listnode
.ln
);
251 de
->de_TableSize
= DE_DOSTYPE
;
252 de
->de_MaxTransfer
= 0xFFFFFF;
253 de
->de_Mask
= 0xFFFFFFFE;
255 de
->de_BufMemType
= MEMF_ANY
;
256 CopyMem(de
, &partition
->de
, sizeof(struct DosEnvec
));
257 ttn
= findTableTypeNode(table
->table
->type
);
258 CopyMem(&ttn
->defaulttype
, &partition
->type
, sizeof(struct PartitionType
));
259 if (getAttrInfo(table
->table
->pattrlist
, PTA_NAME
) & PLAM_WRITE
)
260 strcpy(partition
->listnode
.ln
.ln_Name
, "DH0");
262 setPartitionName(partition
);
263 partition
->ph
= AddPartitionA
267 PT_TYPE
, &partition
->type
,
268 PT_NAME
, partition
->listnode
.ln
.ln_Name
,
269 PT_POSITION
, partition
->pos
,
274 /* we did not set GEOMETRY so partitionlib did it */
278 PT_GEOMETRY
, &partition
->dg
,
281 /* Update DOS type in local DOSEnvec */
282 GetPartitionAttrsA(partition
->ph
, PT_DOSENVEC
, &partition
->de
, TAG_DONE
);
285 freePartitionNode(partition
);