2007-11-07 05:37:30 -06:00
|
|
|
#ifndef BLKDEV_H
|
|
|
|
#define BLKDEV_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
2011-01-17 15:00:35 -06:00
|
|
|
#ifdef HAVE_SYS_IOCCOM_H
|
|
|
|
# include <sys/ioccom.h> /* for _IO macro on e.g. Solaris */
|
|
|
|
#endif
|
2009-03-11 08:00:21 -05:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2007-11-07 05:37:30 -06:00
|
|
|
|
2011-01-20 16:16:41 -06:00
|
|
|
#if HAVE_SYS_MKDEV_H
|
|
|
|
# include <sys/mkdev.h> /* major and minor on Solaris */
|
|
|
|
#endif
|
|
|
|
|
2007-11-07 05:37:30 -06:00
|
|
|
#define DEFAULT_SECTOR_SIZE 512
|
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
#ifdef __linux__
|
|
|
|
/* very basic ioclts, should be available everywhere */
|
|
|
|
# ifndef BLKROSET
|
|
|
|
# define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
|
|
|
|
# define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
|
|
|
|
# define BLKRRPART _IO(0x12,95) /* re-read partition table */
|
|
|
|
# define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
|
|
|
|
# define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
|
|
|
|
# define BLKRASET _IO(0x12,98) /* set read ahead for block device */
|
|
|
|
# define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
|
|
|
|
# define BLKFRASET _IO(0x12,100) /* set filesystem (mm/filemap.c) read-ahead */
|
|
|
|
# define BLKFRAGET _IO(0x12,101) /* get filesystem (mm/filemap.c) read-ahead */
|
|
|
|
# define BLKSECTSET _IO(0x12,102) /* set max sectors per request (ll_rw_blk.c) */
|
|
|
|
# define BLKSECTGET _IO(0x12,103) /* get max sectors per request (ll_rw_blk.c) */
|
|
|
|
# define BLKSSZGET _IO(0x12,104) /* get block device sector size */
|
2007-11-07 05:37:30 -06:00
|
|
|
|
2007-11-07 14:25:48 -06:00
|
|
|
/* ioctls introduced in 2.2.16, removed in 2.5.58 */
|
2010-08-24 05:04:24 -05:00
|
|
|
# define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
|
|
|
|
# define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
|
2007-11-07 05:37:30 -06:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
# define BLKBSZGET _IOR(0x12,112,size_t)
|
|
|
|
# define BLKBSZSET _IOW(0x12,113,size_t)
|
|
|
|
# endif /* !BLKROSET */
|
2007-11-07 05:37:30 -06:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
# ifndef BLKGETSIZE64
|
|
|
|
# define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
|
|
|
|
# endif
|
2010-03-10 08:41:40 -06:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
/* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
|
|
|
|
# ifndef BLKIOMIN
|
|
|
|
# define BLKIOMIN _IO(0x12,120)
|
|
|
|
# define BLKIOOPT _IO(0x12,121)
|
|
|
|
# define BLKALIGNOFF _IO(0x12,122)
|
|
|
|
# define BLKPBSZGET _IO(0x12,123)
|
|
|
|
# endif
|
2010-08-24 04:43:21 -05:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
/* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
|
|
|
|
# ifndef BLKDISCARDZEROES
|
|
|
|
# define BLKDISCARDZEROES _IO(0x12,124)
|
|
|
|
# endif
|
2009-10-14 19:32:03 -05:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
/* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
|
|
|
|
# ifndef FIFREEZE
|
|
|
|
# define FIFREEZE _IOWR('X', 119, int) /* Freeze */
|
|
|
|
# define FITHAW _IOWR('X', 120, int) /* Thaw */
|
|
|
|
# endif
|
2007-11-07 05:37:30 -06:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
#endif /* __linux */
|
2010-08-24 04:43:21 -05:00
|
|
|
|
2010-08-24 05:04:24 -05:00
|
|
|
#ifdef APPLE_DARWIN
|
|
|
|
# define BLKGETSIZE DKIOCGETBLOCKCOUNT32
|
2010-05-13 06:23:49 -05:00
|
|
|
#endif
|
|
|
|
|
2007-11-07 05:37:30 -06:00
|
|
|
#ifndef HDIO_GETGEO
|
2008-07-23 17:30:21 -05:00
|
|
|
# ifdef __linux__
|
|
|
|
# define HDIO_GETGEO 0x0301
|
|
|
|
# endif
|
2007-11-07 05:37:30 -06:00
|
|
|
struct hd_geometry {
|
|
|
|
unsigned char heads;
|
|
|
|
unsigned char sectors;
|
|
|
|
unsigned short cylinders; /* truncated */
|
|
|
|
unsigned long start;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2008-07-23 17:30:21 -05:00
|
|
|
/* Determine size in bytes */
|
|
|
|
off_t blkdev_find_size (int fd);
|
|
|
|
|
2007-11-07 05:37:30 -06:00
|
|
|
/* get size in bytes */
|
|
|
|
int blkdev_get_size(int fd, unsigned long long *bytes);
|
|
|
|
|
|
|
|
/* get 512-byte sector count */
|
|
|
|
int blkdev_get_sectors(int fd, unsigned long long *sectors);
|
|
|
|
|
|
|
|
/* get hardware sector size */
|
|
|
|
int blkdev_get_sector_size(int fd, int *sector_size);
|
|
|
|
|
2011-04-08 19:20:49 -05:00
|
|
|
/* specifies whether or not the device is misaligned */
|
|
|
|
int blkdev_is_misaligned(int fd);
|
|
|
|
|
2007-11-07 05:37:30 -06:00
|
|
|
#endif /* BLKDEV_H */
|