file_systems: Pass size argument to ioctl in a lot more places.

This commit is contained in:
Augustin Cavalier
2019-07-11 23:26:02 -04:00
parent 394fba6684
commit 1418cade55
8 changed files with 35 additions and 34 deletions
@@ -102,7 +102,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) { if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access // check out if the device really allows for read/write access
device_geometry geometry; device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) { if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) { if (geometry.read_only) {
// reopen device read-only // reopen device read-only
close(fDevice); close(fDevice);
@@ -162,7 +162,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize) DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{ {
device_geometry geometry; device_geometry geometry;
if (ioctl(fDevice, B_GET_GEOMETRY, &geometry) < 0) { if (ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry)) < 0) {
// maybe it's just a file // maybe it's just a file
struct stat stat; struct stat stat;
if (fstat(fDevice, &stat) < 0) if (fstat(fDevice, &stat) < 0)
@@ -106,7 +106,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) { if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access // check out if the device really allows for read/write access
device_geometry geometry; device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) { if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) { if (geometry.read_only) {
// reopen device read-only // reopen device read-only
close(fDevice); close(fDevice);
@@ -166,7 +166,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize) DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{ {
device_geometry geometry; device_geometry geometry;
if (ioctl(fDevice, B_GET_GEOMETRY, &geometry) < 0) { if (ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry)) < 0) {
// maybe it's just a file // maybe it's just a file
struct stat stat; struct stat stat;
if (fstat(fDevice, &stat) < 0) if (fstat(fDevice, &stat) < 0)
@@ -506,7 +506,7 @@ read_frames(int fd, off_t firstFrame, uint8 *buffer, size_t count)
read.buffer = (char *)buffer; read.buffer = (char *)buffer;
read.play = false; read.play = false;
if (ioctl(fd, B_SCSI_READ_CD, &read) < 0) { if (ioctl(fd, B_SCSI_READ_CD, &read, sizeof(scsi_read_cd)) < 0) {
// drive couldn't read data - try again to read with a smaller block size // drive couldn't read data - try again to read with a smaller block size
if (count == 1) if (count == 1)
return errno; return errno;
@@ -122,7 +122,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) { if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access // check out if the device really allows for read/write access
device_geometry geometry; device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) { if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) { if (geometry.read_only) {
// reopen device read-only // reopen device read-only
close(fDevice); close(fDevice);
@@ -182,7 +182,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize) DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{ {
device_geometry geometry; device_geometry geometry;
if (ioctl(fDevice, B_GET_GEOMETRY, &geometry) < 0) { if (ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry)) < 0) {
// maybe it's just a file // maybe it's just a file
struct stat stat; struct stat stat;
if (fstat(fDevice, &stat) < 0) if (fstat(fDevice, &stat) < 0)
@@ -111,7 +111,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) { if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access // check out if the device really allows for read/write access
device_geometry geometry; device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) { if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) { if (geometry.read_only) {
// reopen device read-only // reopen device read-only
close(fDevice); close(fDevice);
@@ -171,7 +171,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize) DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{ {
device_geometry geometry; device_geometry geometry;
if (ioctl(fDevice, B_GET_GEOMETRY, &geometry) < 0) { if (ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry)) < 0) {
// maybe it's just a file // maybe it's just a file
struct stat stat; struct stat stat;
if (fstat(fDevice, &stat) < 0) if (fstat(fDevice, &stat) < 0)
+1 -1
View File
@@ -525,7 +525,7 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags,
} }
// get device characteristics // get device characteristics
if (ioctl(fd, B_GET_GEOMETRY, &geo) < 0) { if (ioctl(fd, B_GET_GEOMETRY, &geo, sizeof(device_geometry)) < 0) {
struct stat st; struct stat st;
if (fstat(fd, &st) >= 0 && S_ISREG(st.st_mode)) { if (fstat(fd, &st) >= 0 && S_ISREG(st.st_mode)) {
/* support mounting disk images */ /* support mounting disk images */
@@ -49,7 +49,7 @@ get_device_block_size(int fd)
{ {
device_geometry geometry; device_geometry geometry;
if (ioctl(fd, B_GET_GEOMETRY, &geometry) < 0) { if (ioctl(fd, B_GET_GEOMETRY, &geometry, sizeof(device_geometry)) < 0) {
struct stat st; struct stat st;
if (fstat(fd, &st) < 0 || S_ISDIR(st.st_mode)) if (fstat(fd, &st) < 0 || S_ISDIR(st.st_mode))
return 0; return 0;
@@ -628,7 +628,8 @@ ISOMount(const char *path, uint32 flags, iso9660_volume **_newVolume,
/* try to open the raw device to get access to the other sessions as well */ /* try to open the raw device to get access to the other sessions as well */
if (volume->fdOfSession >= 0) { if (volume->fdOfSession >= 0) {
if (ioctl(volume->fdOfSession, B_GET_PARTITION_INFO, &partitionInfo) < 0) { if (ioctl(volume->fdOfSession, B_GET_PARTITION_INFO, &partitionInfo,
sizeof(partition_info)) < 0) {
TRACE(("B_GET_PARTITION_INFO: ioctl returned error\n")); TRACE(("B_GET_PARTITION_INFO: ioctl returned error\n"));
strcpy(partitionInfo.device, path); strcpy(partitionInfo.device, path);
} }
@@ -560,7 +560,7 @@ udf_mount(fs_volume *_volume, const char *_device, uint32 flags,
// //
// If that fails, you're just SOL. // If that fails, you're just SOL.
if (ioctl(device, B_GET_PARTITION_INFO, &info) == 0) { if (ioctl(device, B_GET_PARTITION_INFO, &info, sizeof(partition_info)) == 0) {
TRACE(("partition_info:\n")); TRACE(("partition_info:\n"));
TRACE(("\toffset: %Ld\n", info.offset)); TRACE(("\toffset: %Ld\n", info.offset));
TRACE(("\tsize: %Ld\n", info.size)); TRACE(("\tsize: %Ld\n", info.size));
@@ -571,7 +571,7 @@ udf_mount(fs_volume *_volume, const char *_device, uint32 flags,
_device = info.device; _device = info.device;
deviceOffset = info.offset / info.logical_block_size; deviceOffset = info.offset / info.logical_block_size;
numBlock = deviceOffset + info.size / info.logical_block_size; numBlock = deviceOffset + info.size / info.logical_block_size;
} else if (ioctl(device, B_GET_GEOMETRY, &geometry) == 0) { } else if (ioctl(device, B_GET_GEOMETRY, &geometry, sizeof(device_geometry)) == 0) {
TRACE(("geometry_info:\n")); TRACE(("geometry_info:\n"));
TRACE(("\tsectors_per_track: %ld\n", geometry.sectors_per_track)); TRACE(("\tsectors_per_track: %ld\n", geometry.sectors_per_track));
TRACE(("\tcylinder_count: %ld\n", geometry.cylinder_count)); TRACE(("\tcylinder_count: %ld\n", geometry.cylinder_count));