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 #ifndef _LARGEFILE_SOURCE
14 #define _LARGEFILE_SOURCE
16 #ifndef _LARGEFILE64_SOURCE
17 #define _LARGEFILE64_SOURCE
29 #ifdef HAVE_LINUX_FD_H
30 #include <sys/ioctl.h>
34 #if defined(__linux__) && defined(_IO)
35 #if !defined(BLKSSZGET)
36 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
38 #if !defined(BLKPBSZGET)
39 #define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */
47 * Returns the logical sector size of a device
49 errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
53 fd = ext2fs_open_file(file, O_RDONLY, 0);
58 if (ioctl(fd, BLKSSZGET, sectsize) >= 0) {
69 * Return desired alignment for direct I/O
71 int ext2fs_get_dio_alignment(int fd)
76 if (ioctl(fd, BLKSSZGET, &align) < 0)
82 align = sysconf(_SC_PAGESIZE);
84 #ifdef HAVE_GETPAGESIZE
86 align = getpagesize();
95 * Returns the physical sector size of a device
97 errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
101 fd = ext2fs_open_file(file, O_RDONLY, 0);
106 if (ioctl(fd, BLKPBSZGET, sectsize) >= 0) {