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)) {
// check out if the device really allows for read/write access
device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) {
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) {
// reopen device read-only
close(fDevice);
@@ -162,7 +162,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{
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
struct stat stat;
if (fstat(fDevice, &stat) < 0)
@@ -106,7 +106,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access
device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) {
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) {
// reopen device read-only
close(fDevice);
@@ -166,7 +166,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{
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
struct stat stat;
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.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
if (count == 1)
return errno;
@@ -122,7 +122,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access
device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) {
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) {
// reopen device read-only
close(fDevice);
@@ -182,7 +182,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{
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
struct stat stat;
if (fstat(fDevice, &stat) < 0)
@@ -255,7 +255,7 @@ exfat_super_block::IsValid()
return false;
if (version_minor != 0 || version_major != 1)
return false;
return true;
}
@@ -480,7 +480,7 @@ Volume::GetIno(cluster_t cluster, uint32 offset, ino_t parent)
node->parent = parent;
fNodeTree.Insert(node);
fInoTree.Insert(node);
TRACE("Volume::GetIno() new cluster %" B_PRIu32 " offset %" B_PRIu32
TRACE("Volume::GetIno() new cluster %" B_PRIu32 " offset %" B_PRIu32
" ino %" B_PRIdINO "\n", cluster, offset, node->ino);
return node->ino;
}
+20 -20
View File
@@ -111,7 +111,7 @@ DeviceOpener::Open(const char* device, int mode)
if (_IsReadWrite(mode)) {
// check out if the device really allows for read/write access
device_geometry geometry;
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) {
if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry, sizeof(device_geometry))) {
if (geometry.read_only) {
// reopen device read-only
close(fDevice);
@@ -171,7 +171,7 @@ status_t
DeviceOpener::GetSize(off_t* _size, uint32* _blockSize)
{
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
struct stat stat;
if (fstat(fDevice, &stat) < 0)
@@ -210,7 +210,7 @@ ext2_super_block::IsValid()
|| ReservedGDTBlocks() > (1UL << BlockShift()) / 4) {
return false;
}
return true;
}
@@ -283,7 +283,7 @@ Volume::Mount(const char* deviceName, uint32 flags)
{
// flags |= B_MOUNT_READ_ONLY;
// we only support read-only for now
if ((flags & B_MOUNT_READ_ONLY) != 0) {
TRACE("Volume::Mount(): Read only\n");
} else {
@@ -312,7 +312,7 @@ Volume::Mount(const char* deviceName, uint32 flags)
FATAL("Volume::Mount(): Identify() failed\n");
return status;
}
// check read-only features if mounting read-write
if (!IsReadOnly() && _UnsupportedReadOnlyFeatures(fSuperBlock) != 0)
return B_UNSUPPORTED;
@@ -345,7 +345,7 @@ Volume::Mount(const char* deviceName, uint32 flags)
TRACE("block size %" B_PRIu32 ", num groups %" B_PRIu32 ", groups per "
"block %" B_PRIu32 ", first %" B_PRIu32 "\n", fBlockSize, fNumGroups,
fGroupsPerBlock, fFirstDataBlock);
uint32 blockCount = (fNumGroups + fGroupsPerBlock - 1) / fGroupsPerBlock;
fGroupBlocks = (uint8**)malloc(blockCount * sizeof(uint8*));
@@ -366,7 +366,7 @@ Volume::Mount(const char* deviceName, uint32 flags)
fBlockCache = opener.InitCache(NumBlocks(), fBlockSize);
if (fBlockCache == NULL)
return B_ERROR;
TRACE("Volume::Mount(): Initialized block cache: %p\n", fBlockCache);
// initialize journal if mounted read-write
@@ -374,7 +374,7 @@ Volume::Mount(const char* deviceName, uint32 flags)
(fSuperBlock.CompatibleFeatures() & EXT2_FEATURE_HAS_JOURNAL) != 0) {
// TODO: There should be a mount option to ignore the existent journal
if (fSuperBlock.JournalInode() != 0) {
fJournalInode = new(std::nothrow) Inode(this,
fJournalInode = new(std::nothrow) Inode(this,
fSuperBlock.JournalInode());
if (fJournalInode == NULL)
@@ -526,7 +526,7 @@ Volume::_UnsupportedIncompatibleFeatures(ext2_super_block& superBlock)
| EXT2_INCOMPATIBLE_FEATURE_EXTENTS
| EXT2_INCOMPATIBLE_FEATURE_FLEX_GROUP;
/*| EXT2_INCOMPATIBLE_FEATURE_META_GROUP*/;
uint32 unsupported = superBlock.IncompatibleFeatures()
uint32 unsupported = superBlock.IncompatibleFeatures()
& ~supportedIncompatible;
if (unsupported != 0) {
@@ -585,7 +585,7 @@ Volume::_GroupCheckSum(ext2_block_group *group, int32 index)
checksum = calculate_crc(checksum, (uint8*)&number, sizeof(number));
checksum = calculate_crc(checksum, (uint8*)group, 30);
if (Has64bitFeature()) {
checksum = calculate_crc(checksum, (uint8*)group + 34,
checksum = calculate_crc(checksum, (uint8*)group + 34,
fGroupDescriptorSize - 34);
}
}
@@ -621,13 +621,13 @@ Volume::GetBlockGroup(int32 index, ext2_block_group** _group)
memcpy(fGroupBlocks[blockIndex], block, fBlockSize);
TRACE("group [%" B_PRId32 "]: inode table %" B_PRIu64 "\n", index,
((ext2_block_group*)(fGroupBlocks[blockIndex] + blockOffset
((ext2_block_group*)(fGroupBlocks[blockIndex] + blockOffset
* fGroupDescriptorSize))->InodeTable(Has64bitFeature()));
}
*_group = (ext2_block_group*)(fGroupBlocks[blockIndex]
+ blockOffset * fGroupDescriptorSize);
if (HasChecksumFeature()
if (HasChecksumFeature()
&& (*_group)->checksum != _GroupCheckSum(*_group, index)) {
return B_BAD_DATA;
}
@@ -653,7 +653,7 @@ Volume::WriteBlockGroup(Transaction& transaction, int32 index)
ext2_block_group *group = (ext2_block_group*)(fGroupBlocks[blockIndex]
+ blockOffset * fGroupDescriptorSize);
group->checksum = _GroupCheckSum(group, index);
TRACE("Volume::WriteBlockGroup() checksum 0x%x for group %" B_PRId32 " "
"(free inodes %" B_PRIu32 ", unused %" B_PRIu32 ")\n", group->checksum,
@@ -677,13 +677,13 @@ Volume::WriteBlockGroup(Transaction& transaction, int32 index)
status_t
Volume::ActivateLargeFiles(Transaction& transaction)
{
if ((fSuperBlock.ReadOnlyFeatures()
if ((fSuperBlock.ReadOnlyFeatures()
& EXT2_READ_ONLY_FEATURE_LARGE_FILE) != 0)
return B_OK;
fSuperBlock.SetReadOnlyFeatures(fSuperBlock.ReadOnlyFeatures()
| EXT2_READ_ONLY_FEATURE_LARGE_FILE);
return WriteSuperBlock(transaction);
}
@@ -691,13 +691,13 @@ Volume::ActivateLargeFiles(Transaction& transaction)
status_t
Volume::ActivateDirNLink(Transaction& transaction)
{
if ((fSuperBlock.ReadOnlyFeatures()
if ((fSuperBlock.ReadOnlyFeatures()
& EXT2_READ_ONLY_FEATURE_DIR_NLINK) != 0)
return B_OK;
fSuperBlock.SetReadOnlyFeatures(fSuperBlock.ReadOnlyFeatures()
| EXT2_READ_ONLY_FEATURE_DIR_NLINK);
return WriteSuperBlock(transaction);
}
@@ -734,7 +734,7 @@ Volume::RemoveOrphan(Transaction& transaction, ino_t id)
ext2_inode* inode = (ext2_inode*)(block
+ InodeBlockIndex(currentID) * InodeSize());
if (currentID == id) {
TRACE("Volume::RemoveOrphan(): First entry. Updating head to: %d\n",
(int)inode->NextOrphan());
+1 -1
View File
@@ -525,7 +525,7 @@ mount_fat_disk(const char *path, fs_volume *_vol, const int flags,
}
// 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;
if (fstat(fd, &st) >= 0 && S_ISREG(st.st_mode)) {
/* support mounting disk images */
@@ -49,7 +49,7 @@ get_device_block_size(int fd)
{
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;
if (fstat(fd, &st) < 0 || S_ISDIR(st.st_mode))
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 */
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"));
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 (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(("\toffset: %Ld\n", info.offset));
TRACE(("\tsize: %Ld\n", info.size));
@@ -571,7 +571,7 @@ udf_mount(fs_volume *_volume, const char *_device, uint32 flags,
_device = info.device;
deviceOffset = info.offset / 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(("\tsectors_per_track: %ld\n", geometry.sectors_per_track));
TRACE(("\tcylinder_count: %ld\n", geometry.cylinder_count));