add NOWARN_SIZEOF_POINTER_MEMACCESS
[AROS.git] / rom / partition / getpartitionattrs.c
blob52374c12a422a541aae52791a45e3e4bda1d0b91
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 */
7 #include <proto/utility.h>
9 #include "partition_support.h"
10 #include "platform.h"
11 #include "debug.h"
13 /*****************************************************************************
15 NAME */
16 #include <utility/tagitem.h>
17 #include <libraries/partition.h>
19 AROS_LH2(LONG, GetPartitionAttrs,
21 /* SYNOPSIS */
22 AROS_LHA(struct PartitionHandle *, ph, A1),
23 AROS_LHA(struct TagItem *, taglist, A2),
25 /* LOCATION */
26 struct Library *, PartitionBase, 15, Partition)
28 /* FUNCTION
29 get attributes of a partition
31 INPUTS
32 ph - PartitionHandle
33 taglist - list of attributes, unknown tags are ignored:
35 PT_GEOMETRY - struct DriveGeometry * ; Fill in DriveGeometry structure
36 PT_DOSENVEC - struct DosEnvec * ; Fill in DosEnvec structure
37 PT_TYPE - struct PartitionType * ; Get partition type
38 PT_POSITION - ULONG * ; Get position (entry number) of partition within its table.
39 ; Returns -1 is there's no table (e. g. if used on disk root)
40 PT_ACTIVE - LONG * ; Get value of "active" flag (PC-MBR specific)
41 PT_BOOTABLE - LONG * ; Get value of "bootable" flag
42 PT_AUTOMOUNT - LONG * ; Get value of "automount" flag
43 PT_NAME - STRPTR ; Get name of partition (max 31 Bytes + NULL-byte)
44 PT_STARTBLOCK - UQUAD * ; Get number of starting block for the partition (V2)
45 PT_ENDBLOCK - UQUAD * ; Get number of ending block for the partition (V2)
47 RESULT
48 Currently reserved, always zero.
50 NOTES
51 Nested partition tables (e. g. RDB subpartitions on PC MBR drive) are treated as virtual disks.
52 In this case start and end block numbers are relative to the beginning of the virtual disk
53 (which is represented by parent partition containing the RDB itself), not absolute numbers.
54 The same applies to DriveGeomerty and geometry-related fields in DosEnvec structure.
56 Note that geometry data can be stored on disk in the partition table ifself (RDB for example), and
57 this way it can not match physical device's geometry (for example, if the disk was partitioned on
58 another operating system which used virtual geometry). In this case you might need to adjust these
59 data in order to mount the file system correctly (if absolute start/end blocks are not
60 cylinder-aligned).
62 Starting from V2, partition.library always provides default values for all attributes, even for those
63 not listed as readable in QueryPartitionAttrs() results.
65 EXAMPLE
67 BUGS
69 SEE ALSO
70 SetPartitionAttrs()
72 INTERNALS
74 HISTORY
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
80 LONG (*getPartitionAttr)(struct Library *, struct PartitionHandle *, struct TagItem *) = NULL;
82 struct TagItem *tag;
84 if (ph->root)
86 struct PTFunctionTable *handler = ph->root->table->handler;
88 getPartitionAttr = handler->getPartitionAttr;
91 while ((tag = NextTagItem((struct TagItem **)&taglist)))
93 ULONG sup;
95 /* If we have partition handler, call its function first */
96 if (getPartitionAttr)
97 sup = getPartitionAttr(PartitionBase, ph, tag);
98 else
99 sup = FALSE;
101 if (!sup)
103 struct PartitionHandle *list_ph = NULL;
106 * No handler (root partition) or the handler didn't process the attribute.
107 * Return defaults.
109 switch (tag->ti_Tag)
111 case PT_GEOMETRY:
112 CopyMem(&ph->dg, (APTR)tag->ti_Data, sizeof(struct DriveGeometry));
113 break;
115 case PT_DOSENVEC:
116 CopyMem(&ph->de, (APTR)tag->ti_Data, sizeof(struct DosEnvec));
117 break;
119 case PT_TYPE:
120 /* We have no type semantics */
121 PTYPE(tag->ti_Data)->id_len = 0;
122 break;
124 case PT_LEADIN:
125 case PT_ACTIVE:
126 case PT_BOOTABLE:
127 case PT_AUTOMOUNT:
128 *((ULONG *)tag->ti_Data) = 0;
129 break;
131 case PT_POSITION:
132 D(bug("[GetPartitionAttrs] PT_POSITION(0x%p)\n", ph));
134 if (ph->root)
136 ULONG i = 0;
138 D(bug("[GetPartitionAttrs] Parent table 0x%p\n", ph->root->table));
140 ForeachNode(&ph->root->table->list, list_ph)
142 D(bug("[GetPartitionAttrs] Child handle 0x%p\n", list_ph));
144 if (list_ph == ph)
146 *((ULONG *)tag->ti_Data) = i;
147 break;
149 i++;
153 /* If nothing was found, return -1 (means "not applicable") */
154 if (list_ph != ph)
155 *((ULONG *)tag->ti_Data) = -1;
157 break;
159 case PT_NAME:
160 if (ph->ln.ln_Name)
162 strncpy((STRPTR)tag->ti_Data, ph->ln.ln_Name, 31);
163 /* Make sure that name is NULL-terminated */
164 ((STRPTR)tag->ti_Data)[31] = 0;
166 else
167 ((STRPTR)tag->ti_Data)[0] = 0;
168 break;
170 case PT_STARTBLOCK:
171 *((UQUAD *)tag->ti_Data) = (UQUAD)ph->de.de_LowCyl * ph->de.de_Surfaces * ph->de.de_BlocksPerTrack;
172 break;
174 case PT_ENDBLOCK:
175 *((UQUAD *)tag->ti_Data) = ((UQUAD)ph->de.de_HighCyl + 1) * ph->de.de_Surfaces * ph->de.de_BlocksPerTrack - 1;
176 break;
181 return 0;
183 AROS_LIBFUNC_EXIT