ext2: implement FIOSEEKDATA and FIOSEEKHOLE ioctl commands

Change-Id: I5f267620e904fe7bb294a4864a8ed017d27a7e68
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3387
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Jérôme Duval 2020-11-09 11:36:30 +01:00
parent dfb36b35b9
commit 602051e8eb

View File

@ -7,6 +7,7 @@
#include <algorithm>
#include <dirent.h>
#include <sys/ioctl.h>
#include <util/kernel_cpp.h>
#include <string.h>
@ -574,6 +575,33 @@ ext2_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,
return B_OK;
}
case FIOSEEKDATA:
case FIOSEEKHOLE:
{
off_t* offset = (off_t*)buffer;
Inode* inode = (Inode*)_node->private_node;
if (*offset >= inode->Size())
return ENXIO;
while (*offset < inode->Size()) {
fsblock_t block;
uint32 count = 1;
status_t status = inode->FindBlock(*offset, block, &count);
if (status != B_OK)
return status;
if ((block != 0 && cmd == FIOSEEKDATA)
|| (block == 0 && cmd == FIOSEEKHOLE)) {
return B_OK;
}
*offset += count * volume->BlockSize();
}
if (*offset > inode->Size())
*offset = inode->Size();
return cmd == FIOSEEKDATA ? ENXIO : B_OK;
}
}
return B_DEV_INVALID_IOCTL;