OSDN Git Service

Change ioctl() cmd argument to be unsigned int
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 22 Mar 2019 11:38:30 +0000 (19:38 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 22 Mar 2019 11:38:30 +0000 (19:38 +0800)
commitaa8f2fcf2ba6bd9ab1973c48e06970f33d1e90b0
tree482b47bc58e654131147f372102a497927c81802
parent23a4e18bfaa64a15019bee1960992bd51bd7363a
Change ioctl() cmd argument to be unsigned int

On Linux, the ioctl() function is defined in <sys/ioctl.h> with a request
argument defined as an unsigned long. However the libfuse library defines
it as a signed int. This is inconsistent.

The values defined for the ioctl() command are meant to be unsigned. For
instance FITRIM is defined as 0xc0185879 in <linux/fs.h>, which does not
fit into a signed int.

As a consequence the clang compiler complains:

 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.

Th problem has been reported to https://github.com/libfuse/libfuse/issues/367

According to the discussion, we should change unsigned int. If change it to
unsigned long, an int would be sign extended to a wrong value.
include/ntfs-3g/ioctl.h
libntfs-3g/ioctl.c