aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2016-09-13 18:31:20 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-09-13 18:31:20 -0400
commit370a24cd33940068a890235bea2151b5f0440f56 (patch)
treedec4aba04d7de6e7d606f63c1d1f4d66db581518 /lib
parent065c01cdbaaf6bf150112e85adeaac56315ce408 (diff)
downloade2fsprogs-370a24cd33940068a890235bea2151b5f0440f56.tar.gz
libext2fs: add FreeBSD support to getsectsize.c
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib')
-rw-r--r--lib/ext2fs/Makefile.in12
-rw-r--r--lib/ext2fs/getsectsize.c22
-rw-r--r--lib/ext2fs/tst_getsectsize.c9
3 files changed, 38 insertions, 5 deletions
diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
index 6a3656d08..1e90dd80a 100644
--- a/lib/ext2fs/Makefile.in
+++ b/lib/ext2fs/Makefile.in
@@ -312,10 +312,12 @@ tst_bitops: tst_bitops.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
$(Q) $(CC) -o tst_bitops tst_bitops.o $(ALL_CFLAGS) $(ALL_LDFLAGS) \
$(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
-tst_getsectsize: tst_getsectsize.o $(STATIC_LIBEXT2FS) $(DEPSTATIC_LIBCOM_ERR)
+tst_getsectsize: tst_getsectsize.o getsectsize.o $(STATIC_LIBEXT2FS) \
+ $(DEPSTATIC_LIBCOM_ERR)
$(E) " LD $@"
- $(Q) $(CC) -o tst_sectgetsize tst_getsectsize.o $(ALL_LDFLAGS) \
- $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) $(SYSLIBS)
+ $(Q) $(CC) -o tst_getsectsize tst_getsectsize.o getsectsize.o \
+ $(ALL_LDFLAGS) $(STATIC_LIBEXT2FS) $(STATIC_LIBCOM_ERR) \
+ $(SYSLIBS)
tst_types.o: $(srcdir)/tst_types.c ext2_types.h
@@ -521,7 +523,7 @@ mkjournal: mkjournal.c $(STATIC_LIBEXT2FS) $(DEPLIBCOM_ERR)
check:: tst_bitops tst_badblocks tst_iscan tst_types tst_icount \
tst_super_size tst_types tst_inode_size tst_csum tst_crc32c tst_bitmaps \
tst_inline tst_inline_data tst_libext2fs tst_sha256 tst_sha512 \
- tst_digest_encode
+ tst_digest_encode tst_getsize tst_getsectsize
$(TESTENV) ./tst_bitops
$(TESTENV) ./tst_badblocks
$(TESTENV) ./tst_iscan
@@ -574,7 +576,7 @@ uninstall::
clean::
$(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* \
tst_badblocks tst_iscan ext2_err.et ext2_err.c ext2_err.h \
- tst_byteswap tst_ismounted tst_getsize tst_sectgetsize \
+ tst_byteswap tst_ismounted tst_getsize tst_getsectsize \
tst_bitops tst_types tst_icount tst_super_size tst_csum \
tst_bitmaps tst_bitmaps_out tst_extents tst_inline \
tst_inline_data tst_inode_size tst_bitmaps_cmd.c \
diff --git a/lib/ext2fs/getsectsize.c b/lib/ext2fs/getsectsize.c
index b57bf56a5..d6bc3767d 100644
--- a/lib/ext2fs/getsectsize.c
+++ b/lib/ext2fs/getsectsize.c
@@ -26,6 +26,9 @@
#include <errno.h>
#endif
#include <fcntl.h>
+#ifdef HAVE_SYS_DISK_H
+#include <sys/disk.h>
+#endif
#ifdef HAVE_LINUX_FD_H
#include <sys/ioctl.h>
#include <linux/fd.h>
@@ -60,6 +63,12 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize)
return 0;
}
#endif
+#ifdef DIOCGSECTORSIZE
+ if (ioctl(fd, DIOCGSECTORSIZE, sectsize) >= 0) {
+ close(fd);
+ return 0;
+ }
+#endif
*sectsize = 0;
close(fd);
return 0;
@@ -76,6 +85,11 @@ int ext2fs_get_dio_alignment(int fd)
if (ioctl(fd, BLKSSZGET, &align) < 0)
align = 0;
#endif
+#ifdef DIOCGSECTORSIZE
+ if (align <= 0 &&
+ ioctl(fd, DIOCGSECTORSIZE, &align) < 0)
+ align = 0;
+#endif
#ifdef _SC_PAGESIZE
if (align <= 0)
@@ -108,6 +122,14 @@ errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize)
return 0;
}
#endif
+#ifdef DIOCGSECTORSIZE
+ /* This isn't really the physical sector size, but FreeBSD
+ * doesn't seem to have this concept. */
+ if (ioctl(fd, DIOCGSECTORSIZE, sectsize) >= 0) {
+ close(fd);
+ return 0;
+ }
+#endif
*sectsize = 0;
close(fd);
return 0;
diff --git a/lib/ext2fs/tst_getsectsize.c b/lib/ext2fs/tst_getsectsize.c
index a6b234e09..d616965e6 100644
--- a/lib/ext2fs/tst_getsectsize.c
+++ b/lib/ext2fs/tst_getsectsize.c
@@ -30,6 +30,7 @@ int main(int argc, char **argv)
{
int lsectsize, psectsize;
int retval;
+ int fd;
if (argc < 2) {
fprintf(stderr, "Usage: %s device\n", argv[0]);
@@ -50,5 +51,13 @@ int main(int argc, char **argv)
}
printf("Device %s has logical/physical sector size of %d/%d.\n",
argv[1], lsectsize, psectsize);
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ perror("open");
+ exit(1);
+ }
+ printf("The device's DIO alignment is %d\n",
+ ext2fs_get_dio_alignment(fd));
+ close(fd);
exit(0);
}