- added instructions how to update the online documentation
[bochs-mirror.git] / iodev / cdrom_beos.cc
blob1cea070f378537c4038e287f2213b575989eea72
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: cdrom_beos.cc,v 1.3 2008/01/26 22:24:00 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
5 #include <SupportDefs.h>
6 #include <Drivers.h>
8 #include <sys/stat.h>
9 #include <unistd.h>
11 #include "cdrom_beos.h"
13 int
14 GetLogicalBlockSize(int fd)
16 partition_info p_info;
18 if (ioctl(fd, B_GET_PARTITION_INFO, &p_info) == B_NO_ERROR)
20 //dprintf("GetLogicalBlockSize: ioctl suceed\n");
21 return p_info.logical_block_size;
23 else //dprintf("GetLogicalBlockSize = ioctl returned error\n");
24 return 0;
27 int
28 GetDeviceBlockSize(int fd)
30 struct stat st;
31 device_geometry dg;
33 if (ioctl(fd, B_GET_GEOMETRY, &dg) < 0)
35 if (fstat(fd, &st) < 0 || S_ISDIR(st.st_mode))
36 return 0;
37 return 512; /* just assume it's a plain old file or something */
40 return dg.bytes_per_sector;
43 off_t
44 GetNumDeviceBlocks(int fd, int block_size)
46 struct stat st;
47 device_geometry dg;
49 if (ioctl(fd, B_GET_GEOMETRY, &dg) >= 0)
51 return (off_t)dg.cylinder_count *
52 (off_t)dg.sectors_per_track *
53 (off_t)dg.head_count;
56 /* if the ioctl fails, try just stat'ing in case it's a regular file */
57 if (fstat(fd, &st) < 0)
58 return 0;
60 return st.st_size / block_size;