OSDN Git Service

Don't define our own ioctls unless we have to.
authorPeter Jones <pjones@redhat.com>
Fri, 10 Oct 2014 21:09:51 +0000 (17:09 -0400)
committerPeter Jones <pjones@redhat.com>
Wed, 15 Oct 2014 14:42:34 +0000 (10:42 -0400)
The way it was, BLKGETSIZE64 wound up being 0x80041272 instead of the
0x80081272 it should be on -m32 builds.  4 isn't the size of 64 bits, so
that results in integer overflow into who knows what space on the stack,
and when we compare it to our gpt header, it's also just plain wrong.

This is all madness, of course, the kernel has exported all of this
stuff since the ancient past.  Use that instead.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Tested-by: Michael Tokarev <mjt@tls.msk.ru>
src/include/disk.h
src/lib/disk.c
src/lib/gpt.c

index 3b3370d..8284c93 100644 (file)
 
 #include <sys/ioctl.h>
 #include <stdint.h>
+#include <asm/ioctl.h>
+#include <linux/fs.h>
 
-/* Snagged from linux/include/asm-ia64/ioctl.h */
-#define _IOC_NRBITS     8
-#define _IOC_TYPEBITS   8
-#define _IOC_SIZEBITS   14
-#define _IOC_DIRBITS    2
-
-#define _IOC_NRMASK     ((1 << _IOC_NRBITS)-1)
-#define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
-#define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
-#define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
-
-#define _IOC_NRSHIFT    0
-#define _IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
-#define _IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
-#define _IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
-
-/*
- * Direction bits.
- */
-#define _IOC_NONE       0U
-#define _IOC_WRITE      1U
-#define _IOC_READ       2U
-
-#define _IOC(dir,type,nr,size) \
-        (((dir)  << _IOC_DIRSHIFT) | \
-         ((type) << _IOC_TYPESHIFT) | \
-         ((nr)   << _IOC_NRSHIFT) | \
-         ((size) << _IOC_SIZESHIFT))
-
-/* used to create numbers */
-#define _IO(type,nr)            _IOC(_IOC_NONE,(type),(nr),0)
-
-
-/* Snagged from linux/include/linux/fs.h */
+#ifndef BLKGETSIZE
 #define BLKGETSIZE _IO(0x12,96)      /* return device size */
+#endif
+#ifndef BLKSZGET
+#define BLKSSZGET  _IO(0x12,104)       /* get block device sector size */
+#endif
+#ifndef BLKGETSIZE64
+#define BLKGETSIZE64 _IOR(0x12,114,uint64_t)   /* return device size in bytes (u64 *arg) */
+#endif
+#ifndef BLKGETLASTSECT
+#define BLKGETLASTSECT _IO(0x12,108) /* get last sector of block device */
+#endif
 
 
 enum _bus_type {bus_type_unknown, isa, pci};
index 337909e..6f8dd1a 100644 (file)
@@ -32,8 +32,6 @@
 #include "gpt.h"
 #include "efibootmgr.h"
 
-#define BLKSSZGET  _IO(0x12,104)       /* get block device sector size */
-
 /* The major device number for virtio-blk disks is decided on module load time.
  */
 static int
index 460b42a..363214e 100644 (file)
 #include "gpt.h"
 #include "efibootmgr.h"
 
-#define BLKGETLASTSECT  _IO(0x12,108) /* get last sector of block device */
-#define BLKGETSIZE _IO(0x12,96)        /* return device size */
-#define BLKSSZGET  _IO(0x12,104)       /* get block device sector size */
-#define BLKGETSIZE64 _IOR(0x12,114,uint64_t)   /* return device size in bytes (u64 *arg) */
-
 struct blkdev_ioctl_param {
         unsigned int block;
         size_t content_length;