Skip to contentSkip to conversation

UAPI linux/fs.h: add a warning about wrong ioctl argument types

PATCH In review Aurelien Jarno 2 participants 3 messages Nov 27, 2013 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 UAPI linux/fs.h: add a warning about wrong ioctl argument types

The FS_IOC_GETFLAGS, FS_IOC_SETFLAGS, FS_IOC_GETVERSION and FS_IOC_SETVERSION ioctls are declared for historical reasons with a long argument, while in practice they take an int argument. This is unfortunately not possible to fix that without breaking the kernel ABI.

However good programmers actually lookup for the argument type of these ioctls in <fs/linux.h> and end-up using a long. This breaks on 64-bit big endian machines.

Instead of letting the same "mistake" to be done again and again, add an explanation to <fs/linux.h> so that people use the correct argument type in their code. Also add a small comment on the same line while staying within 80 characters so that the issue appears when doing a grep on this file.

Cc Alexander Viro <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Theodore Ts'o <[email protected]>
---
 include/uapi/linux/fs.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
include/uapi/linux/fs.h +10 -4
index 6c28b61..baeb803 100644
@@ -154,10 +154,16 @@ struct inodes_stat_t {
 #define FITHAW		_IOWR('X', 120, int)	/* Thaw */
 #define FITRIM		_IOWR('X', 121, struct fstrim_range)	/* Trim */
 
-#define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
-#define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
-#define	FS_IOC_GETVERSION		_IOR('v', 1, long)
-#define	FS_IOC_SETVERSION		_IOW('v', 2, long)
+/*
+ * WARNING: The next four following ioctls actually take an int argument
+ * despite their definition. This is important to support 64-bit big-endian
+ * machines.
+ */
+#define	FS_IOC_GETFLAGS			_IOR('f', 1, long) /* should be int */
+#define	FS_IOC_SETFLAGS			_IOW('f', 2, long) /* should be int */
+#define	FS_IOC_GETVERSION		_IOR('v', 1, long) /* should be int */
+#define	FS_IOC_SETVERSION		_IOW('v', 2, long) /* should be int */
+
 #define FS_IOC_FIEMAP			_IOWR('f', 11, struct fiemap)
 #define FS_IOC32_GETFLAGS		_IOR('f', 1, int)
 #define FS_IOC32_SETFLAGS		_IOW('f', 2, int)
Signature · 1 line
1.8.4.2
#2 lore raw
Quoted 6 lines · Christoph Hellwig

Thanks Aurelien,

the added comment looks good and very useful,

Thanks for the review.

Quoted 2 lines

We don't have any man pages documenting these ioctls or other user visible documentation, do we?

The only documentation I have found about these ioctls is from the ioctl_list(2) manpage, but with different name and defined in <linux/ext2_fs.h>. In any case they are correctly defined:

       0x80046601   EXT2_IOC_GETFLAGS     int *
       0x40046602   EXT2_IOC_SETFLAGS     const int *
       0x80047601   EXT2_IOC_GETVERSION   int *
       0x40047602   EXT2_IOC_SETVERSION   const int *
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net