From b34cbddbd66baedc163d36dd281b63ef478f547a Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Sun, 28 Dec 2003 18:21:26 +0100 Subject: [PATCH] Re-add FreeBSD support. Tested on FreeBSD 5.2-CURRENT as of 2003-12-28. Tested on FreeBSD 4.9-STABLE as of 2003-12-27. --- configure.in | 2 +- e2fsck/journal.c | 1 + lib/ext2fs/flushb.c | 1 + lib/ext2fs/getsize.c | 17 +++++++++++++++++ lib/ext2fs/unix_io.c | 14 ++++++++++---- misc/filefrag.c | 13 ++++++++++--- misc/util.c | 8 +++++++- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/configure.in b/configure.in index e90707de..875f5cf9 100644 --- a/configure.in +++ b/configure.in @@ -569,7 +569,7 @@ if test $cross_compiling = no; then else AC_CHECK_PROGS(BUILD_CC, gcc cc) fi -AC_CHECK_HEADERS(stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h netinet/in.h) +AC_CHECK_HEADERS(stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disk.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h netinet/in.h) AC_FUNC_VPRINTF dnl Check to see if dirent has member d_reclen. On cygwin those d_reclen dnl is not decleared. diff --git a/e2fsck/journal.c b/e2fsck/journal.c index 7432eedf..59d4bdc6 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -13,6 +13,7 @@ */ #ifdef HAVE_SYS_MOUNT_H +#include #include #define MNT_FL (MS_MGC_VAL | MS_RDONLY) #endif diff --git a/lib/ext2fs/flushb.c b/lib/ext2fs/flushb.c index 81d5adb0..18827955 100644 --- a/lib/ext2fs/flushb.c +++ b/lib/ext2fs/flushb.c @@ -21,6 +21,7 @@ #include #endif #if HAVE_SYS_MOUNT_H +#include #include /* This may define BLKFLSBUF */ #endif diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index 49a1bd9f..25169cde 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -28,9 +28,14 @@ #include #endif #ifdef HAVE_SYS_DISKLABEL_H +#include /* for __FreeBSD_version */ #include #include #endif /* HAVE_SYS_DISKLABEL_H */ +#ifdef HAVE_SYS_DISK_H +#include /* for LIST_HEAD */ +#include +#endif /* HAVE_SYS_DISK_H */ #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE) #define BLKGETSIZE _IO(0x12,96) /* return device size */ @@ -147,6 +152,8 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, } #endif #ifdef HAVE_SYS_DISKLABEL_H +#if defined(__FreeBSD__) && __FreeBSD_version < 500040 + /* old disklabel interface */ part = strlen(file) - 1; if (part >= 0) { ch = file[part]; @@ -165,6 +172,16 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, return 0; } } +#else /* __FreeBSD_version < 500040 */ + { + off_t ms; + u_int bs; + if (ioctl(fd, DIOCGMEDIASIZE, &ms) >= 0) { + *retblocks = ms / blocksize; + return 0; + } + } +#endif /* __FreeBSD_version < 500040 */ #endif /* HAVE_SYS_DISKLABEL_H */ /* diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 5b2f364b..accd71f4 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -85,6 +85,12 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset, static void reuse_cache(io_channel channel, struct unix_private_data *data, struct unix_cache *cache, unsigned long block); +#if defined(__CYGWIN__) || defined(__FreeBSD__) +#define NEED_BOUNCE_BUFFER +#else +#undef NEED_BOUNCE_BUFFER +#endif + static struct struct_io_manager struct_unix_manager = { EXT2_ET_MAGIC_IO_MANAGER, "Unix I/O Manager", @@ -94,7 +100,7 @@ static struct struct_io_manager struct_unix_manager = { unix_read_blk, unix_write_blk, unix_flush, -#ifdef __CYGWIN__ +#ifdef NEED_BOUNCE_BUFFER 0 #else unix_write_byte @@ -106,7 +112,7 @@ io_manager unix_io_manager = &struct_unix_manager; /* * Here are the raw I/O functions */ -#ifndef __CYGWIN__ +#ifndef NEED_BOUNCE_BUFFER static errcode_t raw_read_blk(io_channel channel, struct unix_private_data *data, unsigned long block, @@ -139,9 +145,9 @@ error_out: size, actual, retval); return retval; } -#else /* __CYGWIN__ */ +#else /* NEED_BOUNCE_BUFFER */ /* - * Windows block devices only allow sector alignment IO in offset and size + * Windows and FreeBSD block devices only allow sector alignment IO in offset and size */ static errcode_t raw_read_blk(io_channel channel, struct unix_private_data *data, diff --git a/misc/filefrag.c b/misc/filefrag.c index c8cf38fc..35fcf84b 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -9,6 +9,15 @@ * %End-Header% */ +#ifndef __LINUX__ +#include +#include + +int main(void) { + fputs("This program is only supported on Linux!\n", stderr); + exit(EXIT_FAILURE); +} +#else #define _LARGEFILE64_SOURCE #include @@ -158,6 +167,4 @@ int main(int argc, char**argv) } return 0; } - - - +#endif diff --git a/misc/util.c b/misc/util.c index b5e6f94b..80871353 100644 --- a/misc/util.c +++ b/misc/util.c @@ -97,7 +97,13 @@ void check_plausibility(const char *device) "did you specify it correctly?\n"), stderr); exit(1); } - if (!S_ISBLK(s.st_mode)) { +#ifdef __FreeBSD__ + /* On FreeBSD, all disk devices are character specials */ + if (!S_ISBLK(s.st_mode) && !S_ISCHR(s.st_mode)) +#else + if (!S_ISBLK(s.st_mode)) +#endif + { printf(_("%s is not a block special device.\n"), device); proceed_question(); return;