2 * getsectsize.c --- get the sector size of a device.
4 * Copyright (C) 1995, 1995 Theodore Ts'o.
5 * Copyright (C) 2003 VMware, Inc.
8 * This file may be redistributed under the terms of the GNU Library
9 * General Public License, version 2.
13 #define _LARGEFILE_SOURCE
14 #define _LARGEFILE64_SOURCE
25 #ifdef HAVE_LINUX_FD_H
26 #include <sys/ioctl.h>
30 #if defined(__linux__) && defined(_IO)
31 #if !defined(BLKSSZGET)
32 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
34 #if !defined(BLKPBSZGET)
35 #define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */
43 * Returns the logical sector size of a device
45 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
49 fd = ext2fs_open_file(file, O_RDONLY, 0);
54 if (ioctl(fd, BLKSSZGET, sectsize) >= 0) {
65 * Return desired alignment for direct I/O
67 int ext2fs_get_dio_alignment(int fd)
72 if (ioctl(fd, BLKSSZGET, &align) < 0)
78 align = sysconf(_SC_PAGESIZE);
80 #ifdef HAVE_GETPAGESIZE
82 align = getpagesize();
91 * Returns the physical sector size of a device
93 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
97 fd = ext2fs_open_file(file, O_RDONLY, 0);
102 if (ioctl(fd, BLKPBSZGET, sectsize) >= 0) {