Windows Driver Kit structur - How do I get something from it

Windows specific forum
harff182
Enthusiast
Enthusiast
Posts: 105
Joined: Thu Dec 08, 2005 4:58 pm
Location: Duesseldorf, Germany

Windows Driver Kit structur - How do I get something from it

Post by harff182 »

moin, moin...

Yesterday I found on MSDNhttp://msdn2.microsoft.com/en-us/library/ms809046.aspx this sttructure:

Code: Select all

typedef struct _DVD_LAYER_DESCRIPTOR {
  UCHAR  BookVersion : 4;
  UCHAR  BookType : 4;
  UCHAR  MinimumRate : 4;
  UCHAR  DiskSize : 4;
  UCHAR  LayerType : 4;
  UCHAR  TrackPath : 1;
  UCHAR  NumberOfLayers : 2;
  UCHAR  Reserved1 : 1;
  UCHAR  TrackDensity : 4;
  UCHAR  LinearDensity : 4;
  ULONG  StartingDataSector;
  ULONG  EndDataSector;
  ULONG  EndLayerZeroSector;
  UCHAR  Reserved5 : 7;
  UCHAR  BCAFlag : 1;
  UCHAR  Reserved6;
} DVD_LAYER_DESCRIPTOR, *PDVD_LAYER_DESCRIPTOR
Unfortunately I'm not good enough to write my own Procedure, that returnes the BookType.

Is there some kind soul around, that helps me with a code?

tia... scholly
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I may have some code for you to try later tonight when I get home. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
harff182
Enthusiast
Enthusiast
Posts: 105
Joined: Thu Dec 08, 2005 4:58 pm
Location: Duesseldorf, Germany

Post by harff182 »

Drive carefully ;)
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

:lol:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Well here's what I have so far. I must admit these damn bitfield structures are a pain in the ass to work with. (Or maybe I'm making a mountain out of a molehill :P ) This is not fully tested but I do get some sort of results. I'll try to do some more with this tomorrow.

Maybe someone else out there has more knowledge in this area. 8)

Code: Select all

#IOCTL_DVD_READ_STRUCTURE = $450
#FILE_DEVICE_DVD = $33
#IOCTL_DVD_BASE = #FILE_DEVICE_DVD
#METHOD_BUFFERED = 0
#FILE_READ_ACCESS = 1

#BookType_DVD_ROM     = 0
#BookType_DVD_RAM     = 1
#BookType_DVD_R       = 2
#BookType_DVD_RW      = 3
#BookType_DVD_PlusRW  = 9

;...Credit for this Procedure goes to netmaestro
Procedure.s ReadBit(number.l, index.l, length) 
  Protected bin$ 
  bin$=RSet(Bin(number), 32, "0") 
  ProcedureReturn Mid(bin$, 32-index, length)
EndProcedure 

;..Credit for this Procedure goes to KarlKox
Procedure.l CTL_CODE(DeviceType, Function, Method, Access) 
  ProcedureReturn ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) 
EndProcedure

IOCTL_DVD_READ_STRUCTURE = CTL_CODE(#IOCTL_DVD_BASE, $0450, #METHOD_BUFFERED, #FILE_READ_ACCESS)

Structure _DVD_READ_STRUCTURE
  BlockByteOffset.LARGE_INTEGER 
  Format.l
  SessionId.l
  LayerNumber.l
EndStructure

Structure _DVD_LAYER_DESCRIPTOR
  dummy.l
  Flags1.l
  StartingDataSector.l 
  EndDataSector.l 
  EndLayerZeroSector.l 
  Flags2.b
  Reserved6.l 
EndStructure
drive$ = "f"
hDevice = CreateFile_("\\.\" + drive$ + ":",#GENERIC_READ, #FILE_SHARE_READ, 0, #OPEN_EXISTING, 0, 0) 
If hDevice
  DeviceIoControl_(hDevice, IOCTL_DVD_READ_STRUCTURE, drs._DVD_READ_STRUCTURE, SizeOf(_DVD_READ_STRUCTURE), @dld._DVD_LAYER_DESCRIPTOR, SizeOf(_DVD_LAYER_DESCRIPTOR)+1, @returned, 0)
  CloseHandle_(hDevice)
  BookVersion.s = ReadBit(dld\Flags1, 0, 4)
  BookType.s = ReadBit(dld\Flags1, 4, 4)
  MinimumRate.s = ReadBit(dld\Flags1, 8, 4)
  DiskSize.s = ReadBit(dld\Flags1, 12, 4)
  LayerType.s = ReadBit(dld\Flags1, 16, 4)
  TrackPath.s = ReadBit(dld\Flags1, 20, 1)
  NumberOfLayers.s = ReadBit(dld\Flags1, 21, 2)
  TrackDensity.s = ReadBit(dld\Flags1, 0, 4)
  LinearDensity.s = ReadBit(dld\Flags1, 4, 4)
  StartingDataSector = dld\StartingDataSector
  EndDataSector = dld\EndDataSector
  EndLayerZeroSector = dld\EndLayerZeroSector
  BCAFlag.s = ReadBit(dld\Flags2, 7, 1)
   
  Debug "BookVersion        " + BookVersion
  Debug "BookType           " + BookType
  Debug "MinimumRate        " + MinimumRate
  Debug "DiskSize           " + DiskSize
  Debug "LayerType          " + LayerType
  Debug "TrackPath          " + TrackPath
  Debug "NumberOfLayers     " + NumberOfLayers
  Debug "TrackDensity       " + TrackDensity
  Debug "LinearDensity      " + LinearDensity
  Debug "StartingDataSector " + Hex(StartingDataSector)
  Debug "EndDataSector      " + Hex(EndDataSector)
  Debug "EndLayerZeroSector " + Hex(EndLayerZeroSector)
  Debug "BCAFlag            " + BCAFlag
  
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
harff182
Enthusiast
Enthusiast
Posts: 105
Joined: Thu Dec 08, 2005 4:58 pm
Location: Duesseldorf, Germany

Post by harff182 »

As soon as I get home, I will try it with all different kind of media I have.
And yes, I will also drive carefully :)

thanks so far... scholly
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
harff182
Enthusiast
Enthusiast
Posts: 105
Joined: Thu Dec 08, 2005 4:58 pm
Location: Duesseldorf, Germany

Post by harff182 »

Sparkie wrote: (Or maybe I'm making a mountain out of a molehill :P )
I hope I didn't show you the wrong track.

I'm programming a database for moviefiles, like MediaMonkey for MP3 and will most probably give the source to the community because of the large amount of help I've already gotten.
When I discovered MediaInfo.dll to get some infos directly from the moviefiles, I decided to try the same with the media they are on. I'm not that good when it comes to do researches, but I found 4 ways to get these infos on optical media:

1. WMI / Win32_PhysicalMedia, from http://msdn2.microsoft.com/en-us/library/aa394346.aspx
Problem: Neither with PB nor VBS or the M$-tools(Scriptomatic, WMI Code Creator) I was able to retrieve the promised infos.

2. IMAPI2, from http://msdn2.microsoft.com/en-us/library/aa364821.aspx]
I played a little bit with the VBS, but my knowledge is too small to use it frop within PB using the 2 libs from PureArea.net.
I also discovered, that the recognition only seems to work correctly with EMPTY Media.

3. Book Type Field, from http://en.wikipedia.org/wiki/Book_type
I found no infos, how to read the lead-in from a CD/DVD from within PB.
Or I just don't understand similar code.

4. Windows Driver Kit, from http://msdn2.microsoft.com/en-us/library/ms809046.aspx
Here we are at the end of a small story, that possibly nobody is interested in :)

Back to your code:
It works, but some results are unexpected:

Code: Select all

Mediumtyp       |DVD-ROM|DVD-RAM|DVD-R|DVD-R DL|DVD-RW|DVD+RW|DVD+R|DVD+RW DL|DVD+R DL|
----------------+-------+-------+-----+--------+------+------+-----+---------+--------+
Wikipedia bin   |0000   |0001   |0010 |0010    |0011  |1001  |1010 |1101     |1110    |
Wikipedia dec   |0      |1      |2    |2       |3     |9     |10   |13       |15      |
DVD_Layer_Descr |0      |1      |2    |--      |3     |9     |--   |--       |--      |
----------------+-------+-------+-----+--------+------+------+-----+---------+--------+
Sparkie.pb ;)	|0000   |1011   |0010 | ------ |------|1001  |0000 |---------|--------|
----------------+-------+-------+-----+--------+------+------+-----+---------+--------+
DVDInfoBookType |DVD-ROM|DVD-RAM|DVD-R| ------ |------|DVD+RW|DVD+R|---------|--------|
DVDInfoMediaType|DVD-ROM|DVD-RAM|DVD-R| ------ |------|DVD+RW|DVD+R|---------|--------|
----------------+-------+-------+-----+--------+------+------+-----+---------+--------+
cdrecord        |DVD-ROM|DVD-RAM|DVD-R| ------ |------|DVD+RW|DVD+R|---------|--------|
----------------+-------+-------+-----+--------+------+------+-----+---------+--------+

DVDInfo: DVD+Rx4 get the BookType DVD-ROM, while DVD+Rx8 geht DVD+R. Weird.
I don't use or have all of the possible Media but I'll try to buy and burn a single one for the missing ones the next days.

back to coding... scholly
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Well it looks like the code works at least a little bit :wink:

I do not do much with DVD's, so testing on my side will be difficult at best. I'll get back to Googling tonight and see if I can make any improvements to the code. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I don't know about this one. After hours (days) of tinkering with this code, I just can't get the correct results. I'm guessing that the structure bitfields are not being handled properly. I've tried right to left...left to right...nuth'n works here for me. :?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
harff182
Enthusiast
Enthusiast
Posts: 105
Joined: Thu Dec 08, 2005 4:58 pm
Location: Duesseldorf, Germany

Post by harff182 »

So I think we may close the thread for now.
Yesterday evening I testet 6 different Disks of every DVD-Type I have used and always got the same results.
Even if you/I expected other values because of the docs, I think I can use your code successfully (to replace the use of cdrecord) as long as no better solution comes around.
Since my database is primarily for me and 2 friends, I don't await problems - even if they get other/different results because of other media/burner/software, I can rework the code.
And when I release the code to public, I'll point to this thread, so interested people may understand the trouble.

Sparkie, thanks for your helpfull efforts...
scholly
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
Post Reply