Chih-Wei Huang wrote:
Hi,
I'm building ntfs-3g on Android 9.
The clang compiler complained:
external/ntfs-3g/libntfs-3g/ioctl.c:398:7: error: overflow converting
case value to switch condition type (3222820985 to
18446744072637405305) [-Werror,-Wswitch]
case FITRIM:
^
bionic/libc/kernel/uapi/linux/fs.h:169:16: note: expanded from macro 'FITRIM'
#define FITRIM _IOWR('X', 121, struct fstrim_range)
^
bionic/libc/kernel/uapi/asm-generic/ioctl.h:51:29: note: expanded from
macro '_IOWR'
#define _IOWR(type,nr,size) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr),
(_IOC_TYPECHECK(size)))
^
bionic/libc/kernel/uapi/asm-generic/ioctl.h:46:32: note: expanded from
macro '_IOC'
#define _IOC(dir,type,nr,size) (((dir) << _IOC_DIRSHIFT) | ((type) <<
_IOC_TYPESHIFT) | ((nr) << _IOC_NRSHIFT) | ((size) << _IOC_SIZESHIFT))
^
1 error generated.
I think it's because FITRIM is 3222820985
which is greater the max of a signed int (2^31-1).
Apparently yes, the FITRIM value does not fit into
a 32-bit int.
This could be fixed by simply casting cmd to unsigned:
Sounds reasonable, the cmd values look like being
intended to be unsigned values.
diff --git a/libntfs-3g/ioctl.c b/libntfs-3g/ioctl.c
index 6c49395..fcf3ac1 100644
--- a/libntfs-3g/ioctl.c
+++ b/libntfs-3g/ioctl.c
@@ -393,7 +393,7 @@ int ntfs_ioctl(ntfs_inode *ni, int cmd, void *arg
__attribute__((unused)),
{
int ret = 0;
- switch (cmd) {
+ switch ((unsigned)cmd) {
#if defined(FITRIM) && defined(BLKDISCARD)
case FITRIM:
if (!ni || !data)
However, I'm thinking a more proper fix.
The standard prototype of ioctl() is
int ioctl(int fd, unsigned long request, ...);
But ntfs-3g defines ioctl method to be
int (*ioctl)(struct ntfs_device *dev, int request, void *argp);
(include/ntfs-3g/device.h etc)
Shouldn't the 'request' be changed to unsigned (long)?
Maybe, but ntfs-3g has to rely on the fuse definition.
The "unsigned long" interface is probably a Linux extension,
the Posix specification and "man ioctl" state "int request"
Jean-Pierre
_______________________________________________
ntfs-3g-devel mailing list
ntfs-3g-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel