internal DiscFreeBsd(string device) { int fd = open(device, O_RDONLY | O_NONBLOCK); if (fd < 0) { throw new LocalDiscException(String.Format("Cannot open device `{0}'", device)); } try { ioc_toc_header h = new ioc_toc_header(); if (cd_read_toc_header(fd, ref h) < 0) { throw new LocalDiscException("Cannot read table of contents header"); } if (h.ending_track == 0) { throw new LocalDiscException("This disc has no tracks"); } first_track = h.starting_track; last_track = h.ending_track; int n = h.ending_track - h.starting_track + 1; int len = (n + 1) * Marshal.SizeOf(typeof(cd_toc_entry)); ioc_read_toc_entry t = new ioc_read_toc_entry(); t.address_format = CD_LBA_FORMAT; t.starting_track = 0; t.data_len = (ushort)len; t.data = Marshal.AllocHGlobal(len); try { if (cd_read_toc_entrys(fd, ref t) < 0) { throw new LocalDiscException("Cannot read table of contents entries"); } for (int i = 0; i <= n; i++) { ulong offset = (ulong)(i * Marshal.SizeOf(typeof(cd_toc_entry))); cd_toc_entry e = (cd_toc_entry)Marshal.PtrToStructure((IntPtr)((ulong)t.data + offset), typeof(cd_toc_entry)); track_offsets[first_track + i] = System.Net.IPAddress.NetworkToHostOrder(e.addr.lba) + 150; } // Move Leadout to the beginning. track_offsets [0] = track_offsets [last_track + 1]; track_offsets [last_track + 1] = 0; } finally { Marshal.FreeHGlobal(t.data); } } finally { close(fd); } Init(); }
internal DiscFreeBsd(string device) { int fd = open (device, O_RDONLY | O_NONBLOCK); if (fd < 0) { throw new LocalDiscException (String.Format ("Cannot open device `{0}'", device)); } try { ioc_toc_header h = new ioc_toc_header (); if (cd_read_toc_header (fd, ref h) < 0) { throw new LocalDiscException ("Cannot read table of contents header"); } if (h.ending_track == 0) { throw new LocalDiscException ("This disc has no tracks"); } first_track = h.starting_track; last_track = h.ending_track; int n = h.ending_track - h.starting_track + 1; int len = (n + 1) * Marshal.SizeOf (typeof (cd_toc_entry)); ioc_read_toc_entry t = new ioc_read_toc_entry (); t.address_format = CD_LBA_FORMAT; t.starting_track = 0; t.data_len = (ushort) len; t.data = Marshal.AllocHGlobal (len); try { if (cd_read_toc_entrys (fd, ref t) < 0) { throw new LocalDiscException ("Cannot read table of contents entries"); } for (int i = 0; i <= n; i++) { ulong offset = (ulong) (i * Marshal.SizeOf (typeof (cd_toc_entry))); cd_toc_entry e = (cd_toc_entry) Marshal.PtrToStructure ((IntPtr) ((ulong)t.data + offset), typeof (cd_toc_entry)); track_offsets[first_track + i] = System.Net.IPAddress.NetworkToHostOrder (e.addr.lba) + 150; } // Move Leadout to the beginning. track_offsets [0] = track_offsets [last_track + 1]; track_offsets [last_track + 1] = 0; } finally { Marshal.FreeHGlobal (t.data); } } finally { close (fd); } Init (); }
static int cd_read_toc_header (int fd, ref ioc_toc_header data) { return cd_read_toc_header (fd, CDIOREADTOCHEADER, ref data); }
static extern int cd_read_toc_header (int fd, ulong request, ref ioc_toc_header data);
static int cd_read_toc_header(int fd, ref ioc_toc_header data) { return(cd_read_toc_header(fd, CDIOREADTOCHEADER, ref data)); }
static extern int cd_read_toc_header(int fd, ulong request, ref ioc_toc_header data);