2006-04-27 19:11:45 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-12-04 22:50:29 +03:00
|
|
|
// $Id: cdrom_beos.cc,v 1.6 2009-12-04 19:50:26 sshwarts Exp $
|
2006-04-27 19:11:45 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-02-08 12:05:52 +03:00
|
|
|
//
|
2009-12-04 22:50:29 +03:00
|
|
|
// Copyright (C) 2000-2009 The Bochs Project
|
2009-02-08 12:05:52 +03:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-04-27 19:11:45 +04:00
|
|
|
|
2001-12-07 21:58:24 +03:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <Drivers.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "cdrom_beos.h"
|
|
|
|
|
2009-02-08 00:05:31 +03:00
|
|
|
int GetLogicalBlockSize(int fd)
|
2001-12-07 21:58:24 +03:00
|
|
|
{
|
2009-02-08 00:05:31 +03:00
|
|
|
partition_info p_info;
|
2001-12-07 21:58:24 +03:00
|
|
|
|
|
|
|
if (ioctl(fd, B_GET_PARTITION_INFO, &p_info) == B_NO_ERROR)
|
|
|
|
{
|
2009-02-08 00:05:31 +03:00
|
|
|
//dprintf("GetLogicalBlockSize: ioctl suceed\n");
|
|
|
|
return p_info.logical_block_size;
|
|
|
|
}
|
2001-12-07 21:58:24 +03:00
|
|
|
else //dprintf("GetLogicalBlockSize = ioctl returned error\n");
|
2009-02-08 00:05:31 +03:00
|
|
|
return 0;
|
2001-12-07 21:58:24 +03:00
|
|
|
}
|
|
|
|
|
2009-02-08 00:05:31 +03:00
|
|
|
int GetDeviceBlockSize(int fd)
|
2001-12-07 21:58:24 +03:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
device_geometry dg;
|
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
if (ioctl(fd, B_GET_GEOMETRY, &dg) < 0)
|
2001-12-07 21:58:24 +03:00
|
|
|
{
|
2009-02-08 00:05:31 +03:00
|
|
|
if (fstat(fd, &st) < 0 || S_ISDIR(st.st_mode))
|
|
|
|
return 0;
|
|
|
|
return 512; /* just assume it's a plain old file or something */
|
2001-12-07 21:58:24 +03:00
|
|
|
}
|
2008-01-27 01:24:03 +03:00
|
|
|
|
2001-12-07 21:58:24 +03:00
|
|
|
return dg.bytes_per_sector;
|
|
|
|
}
|
|
|
|
|
2009-02-08 00:05:31 +03:00
|
|
|
off_t GetNumDeviceBlocks(int fd, int block_size)
|
2001-12-07 21:58:24 +03:00
|
|
|
{
|
2009-02-08 00:05:31 +03:00
|
|
|
struct stat st;
|
|
|
|
device_geometry dg;
|
2001-12-07 21:58:24 +03:00
|
|
|
|
2008-01-27 01:24:03 +03:00
|
|
|
if (ioctl(fd, B_GET_GEOMETRY, &dg) >= 0)
|
2001-12-07 21:58:24 +03:00
|
|
|
{
|
2009-02-08 00:05:31 +03:00
|
|
|
return (off_t)dg.cylinder_count *
|
|
|
|
(off_t)dg.sectors_per_track *
|
|
|
|
(off_t)dg.head_count;
|
2001-12-07 21:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the ioctl fails, try just stat'ing in case it's a regular file */
|
|
|
|
if (fstat(fd, &st) < 0)
|
2009-02-08 00:05:31 +03:00
|
|
|
return 0;
|
2001-12-07 21:58:24 +03:00
|
|
|
|
|
|
|
return st.st_size / block_size;
|
|
|
|
}
|