CD/DVD raw data reading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lucky Luke
    New Member
    • Mar 2011
    • 1

    #1

    CD/DVD raw data reading

    Hi everyone,

    i'm trying to read CD/DVD bytes, like a disk analyzer.
    But when Stream() is Seek() over to 102400 offset, ReadByte() returns -1. It's problem only for CD discs.

    How can i read all of the disc bytes?

    Here's my code:

    Code:
     
    
     [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            internal static extern SafeFileHandle CreateFile(string lpFileName,
                FileAccess dwDesiredAccess,
                FileShare dwShareMode,
                uint lpSecurityAttributes,
                FileMode dwCreationDisposition,
                int flagsAndAttributes,
                uint hTemplateFile);
    
    Microsoft.Win32.SafeHandles.SafeFileHandle handle = null;
    handle = CreateFile("\\\\.\\E:",
                        FileAccess.Read,
                        FileShare.Read,
                        0,
                        FileMode.Open,
                        FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN,
                        0);
    
    Stream strm= new FileStream(handle, FileAccess.Read);
    
    strm.Seek(24608768, SeekOrigin.Begin); 
    
    int dt=strm.ReadByte(); // here it returns -1
  • TRScheel
    Recognized Expert Contributor
    • Apr 2007
    • 638

    #2
    Does this happen on all CDs? Or just this one?

    ReadByte() will return -1 if you are the end of the stream, granted 102400 is 102 Kb so WAY lower than what can fit on a CD.

    I would try:
    A) Checking Stream.CanSeek
    and
    B) Stream.Length to check the length of the stream

    Comment

    Working...