* The fs_shell is now always using BLKGETSIZE64 on Linux, and only if that fails
it will fall back to HDIO_GETGEO. * This fixes incorrectly reported disk sizes for a number of disks I have here. Please open a bug report if this change causes problems for you (we would then have to check the kernel version to choose the preferred method). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31332 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -27,7 +27,8 @@ namespace FSShell {
|
|||||||
struct FileRestriction {
|
struct FileRestriction {
|
||||||
FileRestriction(fssh_dev_t device, fssh_ino_t node, fssh_off_t startOffset,
|
FileRestriction(fssh_dev_t device, fssh_ino_t node, fssh_off_t startOffset,
|
||||||
fssh_off_t endOffset)
|
fssh_off_t endOffset)
|
||||||
: device(device),
|
:
|
||||||
|
device(device),
|
||||||
node(node),
|
node(node),
|
||||||
startOffset(startOffset),
|
startOffset(startOffset),
|
||||||
endOffset(endOffset)
|
endOffset(endOffset)
|
||||||
@@ -50,8 +51,7 @@ static FileRestriction*
|
|||||||
find_file_restriction(fssh_dev_t device, fssh_ino_t node)
|
find_file_restriction(fssh_dev_t device, fssh_ino_t node)
|
||||||
{
|
{
|
||||||
for (FileRestrictionList::iterator it = sFileRestrictions.begin();
|
for (FileRestrictionList::iterator it = sFileRestrictions.begin();
|
||||||
it != sFileRestrictions.end();
|
it != sFileRestrictions.end(); ++it) {
|
||||||
++it) {
|
|
||||||
FileRestriction* restriction = *it;
|
FileRestriction* restriction = *it;
|
||||||
if (restriction->device == device && restriction->node == node)
|
if (restriction->device == device && restriction->node == node)
|
||||||
return restriction;
|
return restriction;
|
||||||
|
|||||||
@@ -164,16 +164,13 @@ fssh_ioctl(int fd, unsigned long op, ...)
|
|||||||
error = errno;
|
error = errno;
|
||||||
|
|
||||||
#elif defined(HAIKU_HOST_PLATFORM_LINUX)
|
#elif defined(HAIKU_HOST_PLATFORM_LINUX)
|
||||||
struct hd_geometry hdGeometry;
|
// If BLKGETSIZE64 don't work for us, we will fall back to
|
||||||
// BLKGETSIZE and BLKGETSIZE64 don't seem to work for
|
// HDIO_GETGEO (which is kind of obsolete, BTW), and
|
||||||
// partitions. So we get the device geometry (there only seems
|
|
||||||
// to be HDIO_GETGEO, which is kind of obsolete, BTW), and
|
|
||||||
// get the partition size via binary search.
|
// get the partition size via binary search.
|
||||||
if (ioctl(fd, HDIO_GETGEO, &hdGeometry) == 0) {
|
struct hd_geometry hdGeometry;
|
||||||
int blockSize = 512;
|
int blockSize = 512;
|
||||||
if (hdGeometry.heads == 0) {
|
|
||||||
off_t size;
|
off_t size;
|
||||||
if (ioctl(fd, BLKGETSIZE64, &size) == 0) {
|
if (ioctl(fd, BLKGETSIZE64, &size) == 0 && size > 0) {
|
||||||
off_t blocks = size / blockSize;
|
off_t blocks = size / blockSize;
|
||||||
uint32_t heads = (blocks + ULONG_MAX - 1)
|
uint32_t heads = (blocks + ULONG_MAX - 1)
|
||||||
/ ULONG_MAX;
|
/ ULONG_MAX;
|
||||||
@@ -184,8 +181,9 @@ fssh_ioctl(int fd, unsigned long op, ...)
|
|||||||
geometry->cylinder_count = blocks / heads;
|
geometry->cylinder_count = blocks / heads;
|
||||||
geometry->sectors_per_track = 1;
|
geometry->sectors_per_track = 1;
|
||||||
error = B_OK;
|
error = B_OK;
|
||||||
} else
|
} else if (ioctl(fd, HDIO_GETGEO, &hdGeometry) == 0) {
|
||||||
error = errno;
|
if (hdGeometry.heads == 0) {
|
||||||
|
error = B_ERROR;
|
||||||
} else {
|
} else {
|
||||||
off_t bytesPerCylinder = (off_t)hdGeometry.heads
|
off_t bytesPerCylinder = (off_t)hdGeometry.heads
|
||||||
* hdGeometry.sectors * 512;
|
* hdGeometry.sectors * 512;
|
||||||
@@ -240,8 +238,7 @@ fssh_ioctl(int fd, unsigned long op, ...)
|
|||||||
|
|
||||||
disklabel.d_secperunit = mediaSize / disklabel.d_secsize;
|
disklabel.d_secperunit = mediaSize / disklabel.d_secsize;
|
||||||
disklabel.d_ncylinders = mediaSize / disklabel.d_secsize
|
disklabel.d_ncylinders = mediaSize / disklabel.d_secsize
|
||||||
/ disklabel.d_nsectors
|
/ disklabel.d_nsectors / disklabel.d_ntracks;
|
||||||
/ disklabel.d_ntracks;
|
|
||||||
|
|
||||||
geometry->head_count = disklabel.d_ntracks;
|
geometry->head_count = disklabel.d_ntracks;
|
||||||
geometry->cylinder_count = disklabel.d_ncylinders;
|
geometry->cylinder_count = disklabel.d_ncylinders;
|
||||||
|
|||||||
Reference in New Issue
Block a user