Why does such a char array exist?

Hi,

I have a problem about some structures in MS DDK & IFS. For example, in STORAGE_DEVICE_DESCRIPTOR, there exists a char array whoes length is only ONE character. The definition is listed as below:
struct _STORAGE_DEVICE_DESCRIPTOR{
//…some definitions

//
// Place holder for the first byte of the bus specific property data
//

UCHAR RawDeviceProperties[1];

}

Why is such an array defined here? Is it just a programing skill?

It is raw device properties so you must define them and set their length
(RawPropertiesLength). There are a lot of structures defined in that way.

Andrey Gunko
soft Xpansion Ukraine Ltd.
Programmer
Powered by eKnow-how
Artjoma St. 118B … 83048 Donetsk … Tel/Fax: +38 062 3818874 …
Internet: [www.soft-xpansion.com]

|-----Original Message-----
|From: xxxxx@lists.osr.com [mailto:bounce-265605-
|xxxxx@lists.osr.com] On Behalf Of headium2006@163.com
|Sent: Tuesday, October 10, 2006 10:15 AM
|To: Windows File Systems Devs Interest List
|Subject: [ntfsd] Why does such a char array exist?
|
|Hi,
|
|I have a problem about some structures in MS DDK & IFS. For example, in
|STORAGE_DEVICE_DESCRIPTOR, there exists a char array whoes length is only
|ONE character. The definition is listed as below:
|struct _STORAGE_DEVICE_DESCRIPTOR{
| //…some definitions
|
| //
| // Place holder for the first byte of the bus specific property data
| //
|
| UCHAR RawDeviceProperties[1];
|
|}
|
|Why is such an array defined here? Is it just a programing skill?
|
|—
|Questions? First check the IFS FAQ at
|https://www.osronline.com/article.cfm?id=17
|
|You are currently subscribed to ntfsd as: xxxxx@maus.donetsk.ua
|To unsubscribe send a blank email to xxxxx@lists.osr.com

> Why is such an array defined here? Is it just a programing skill?

It is very handy to use such structures; You don’t need
to make two allocations for such structure (one for structure itself
and one for the name). You just take the sizeof(structure),
then add the length of the name in bytes, allocate a block and cast
it to the structure pointer. It also has slightly less memoty occupation
(one pool block instead of two, and you don’t need extra pointer
for the name).

L.

All true, but I think the major reason is that they don’t require a deep
copy when passed to the system; embedded pointers would require the
system to know about the layout of each structure it copied to and from
the kernel. Not very generic.

mm

>> xxxxx@volny.cz 2006-10-10 03:41 >>>
Why is such an array defined here? Is it just a programing skill?

It is very handy to use such structures; You don’t need
to make two allocations for such structure (one for structure itself
and one for the name). You just take the sizeof(structure),
then add the length of the name in bytes, allocate a block and cast
it to the structure pointer. It also has slightly less memoty
occupation
(one pool block instead of two, and you don’t need extra pointer
for the name).

L.


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@evitechnology.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks!
But I still have questions about this problem. What content is stored in the one-char-size array of RawDeviceProperties. In fact, all properties read out can be append to the structure directly. Defining such an array seems to waste memory. MS says this array is defined to “Place holder for the first byte of the bus specific property data”. Why is such a holder needed?

headium2006@163.com wrote:

Thanks! But I still have questions about this problem. What content
is stored in the one-char-size array of RawDeviceProperties. In fact,
all properties read out can be append to the structure directly.
Defining such an array seems to waste memory. MS says this array is
defined to “Place holder for the first byte of the bus specific
property data”. Why is such a holder needed?

If you didn’t have that you wouldn’t be able to refer to the data by
name, reducing your code readability.

You could equally say every other element of the structure is a ‘waste’

  • eg. if you have no serial number is SerialNumberOffset a waste of 4 bytes?

Personally I like the zero length array syntax that gcc has, because it
is more explicit what that kind of thing means… but there’s nothing
wrong with the way it is.

Tony

Also, it allows the compiler to align the array… It would be a lot
harder to do so on your own.

-Jeff

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tony Hoyle
Sent: Wednesday, October 11, 2006 5:03 AM
To: Windows File Systems Devs Interest List
Subject: Re: [ntfsd] Why does such a char array exist?

headium2006@163.com wrote:

Thanks! But I still have questions about this problem. What content
is stored in the one-char-size array of RawDeviceProperties. In fact,
all properties read out can be append to the structure directly.
Defining such an array seems to waste memory. MS says this array is
defined to “Place holder for the first byte of the bus specific
property data”. Why is such a holder needed?

If you didn’t have that you wouldn’t be able to refer to the data by
name, reducing your code readability.

You could equally say every other element of the structure is a ‘waste’

  • eg. if you have no serial number is SerialNumberOffset a waste of 4
    bytes?

Personally I like the zero length array syntax that gcc has, because it
is more explicit what that kind of thing means… but there’s nothing
wrong with the way it is.

Tony


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@emc.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> I have a problem about some structures in MS DDK & IFS. For example, in

STORAGE_DEVICE_DESCRIPTOR, there exists a char array whoes length is
only ONE character. The definition is listed as below:
struct _STORAGE_DEVICE_DESCRIPTOR{
//…some definitions

//
// Place holder for the first byte of the bus specific property data
//

UCHAR RawDeviceProperties[1];

This is a C language question. This means - the structure has tail of variable
size, and the RawDeviceProperties name references this variable-size tail.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

I do believe Messrs Kernighan and Ritchie should be your first point of
call; bedtime reading?

wrote in message news:xxxxx@ntfsd…
> Hi,
>
> I have a problem about some structures in MS DDK & IFS. For example, in
> STORAGE_DEVICE_DESCRIPTOR, there exists a char array whoes length is only
> ONE character. The definition is listed as below:
> struct _STORAGE_DEVICE_DESCRIPTOR{
> //…some definitions
>
> //
> // Place holder for the first byte of the bus specific property data
> //
>
> UCHAR RawDeviceProperties[1];
>
> }
>
> Why is such an array defined here? Is it just a programing skill?
>