All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add support for DragonFly BSD operating system.
@ 2012-07-12 19:48 Antonio Huete Jiménez
  2012-07-12 22:25 ` Andreas Dilger
  2012-07-13  0:30 ` Theodore Ts'o
  0 siblings, 2 replies; 6+ messages in thread
From: Antonio Huete Jiménez @ 2012-07-12 19:48 UTC (permalink / raw)
  To: linux-ext4

Hi,

Find below a patch to add support for DragonFly BSD to e2fsprogs. In the  
case it gets rejected please indicate a reason so I can get it fixed.

For convenience I've uploaded the patch here:  
http://island.quantumachine.net/~antonioh/archive/patches/0001-Add-support-for-DragonFly-BSD-operating-system.patch

Regards,
Antonio Huete



 From 31838ebfd8dd6a52a98ca083fb20401db82e6398 Mon Sep 17 00:00:00 2001
From: Antonio Huete Jimenez <tuxillo@quantumachine.net>
Date: Thu, 12 Jul 2012 21:33:57 +0200
Subject: [PATCH] Add support for DragonFly BSD operating system.

- Add a new OS tag.
- DragonFly uses DIOCGPART to return disk information.
- Avoid falling to some old FreeBSD 4.x code blocks.

Signed-off-by: Antonio Huete Jimenez <tuxillo@dragonflybsd.org>
---
  lib/blkid/getsize.c     |   15 ++++++++++++++-
  lib/e2p/ostype.c        |    5 +++--
  lib/ext2fs/ext2_fs.h    |    1 +
  lib/ext2fs/getsize.c    |   13 +++++++++++++
  lib/ext2fs/initialize.c |    4 ++++
  lib/ext2fs/unix_io.c    |    2 +-
  misc/mke2fs.c           |    2 ++
  misc/util.c             |    2 +-
  8 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c
index f670e1b..9b7cf9f 100644
--- a/lib/blkid/getsize.c
+++ b/lib/blkid/getsize.c
@@ -45,7 +45,9 @@
  #if HAVE_SYS_STAT_H
  #include <sys/stat.h>
  #endif
-
+#ifdef __DragonFly__
+#include <sys/diskslice.h>
+#endif

  #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
  #define BLKGETSIZE _IO(0x12,96)	/* return device size */
@@ -87,8 +89,10 @@ blkid_loff_t blkid_get_dev_size(int fd)
  #endif
  #ifdef HAVE_SYS_DISKLABEL_H
  	int part = -1;
+#ifndef __DragonFly__
  	struct disklabel lab;
  	struct partition *pp;
+#endif /* __DragonFly__ */
  	char ch;
  	struct stat st;
  #endif /* HAVE_SYS_DISKLABEL_H */
@@ -129,11 +133,19 @@ blkid_loff_t blkid_get_dev_size(int fd)
  		return (off_t)size64;
  #endif /* DIOCGMEDIASIZE */

+/* tested on DragonFly 3.1-DEVELOPMENT i386/X86_64 */
+#ifdef DIOCGPART
+	struct partinfo dp;
+	if (ioctl(fd, DIOCGPART, &dp) >= 0)
+		return (off_t)dp.media_size;
+#endif /* DIOCGPART */
+
  #ifdef FDGETPRM
  	if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
  		return (blkid_loff_t)this_floppy.size << 9;
  #endif
  #ifdef HAVE_SYS_DISKLABEL_H
+#ifndef __DragonFly__
  	/*
  	 * This code works for FreeBSD 4.11 i386, except for the full device
  	 * (such as /dev/ad0). It doesn't work properly for newer FreeBSD
@@ -151,6 +163,7 @@ blkid_loff_t blkid_get_dev_size(int fd)
  		if (pp->p_size)
  			return pp->p_size << 9;
  	}
+#endif / __DragonFly__ */
  #endif /* HAVE_SYS_DISKLABEL_H */
  	{
  #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
diff --git a/lib/e2p/ostype.c b/lib/e2p/ostype.c
index d002e75..6d5579a 100644
--- a/lib/e2p/ostype.c
+++ b/lib/e2p/ostype.c
@@ -20,6 +20,7 @@ static const char *os_tab[] =
  	  "Masix",
  	  "FreeBSD",
  	  "Lites",
+	  "DragonFly",
  	  0 };

  /*
@@ -30,7 +31,7 @@ char *e2p_os2string(int os_type)
          const char	*os;
  	char 		*ret;

-	if (os_type <= EXT2_OS_LITES)
+	if (os_type <= EXT2_OS_DRAGONFLY)
  		os = os_tab[os_type];
  	else
  		os = "(unknown os)";
@@ -62,7 +63,7 @@ int main(int argc, char **argv)
  	char 	*s;
  	int	i, os;

-	for (i=0; i <= EXT2_OS_LITES; i++) {
+	for (i=0; i <= EXT2_OS_DRAGONFLY; i++) {
  		s = e2p_os2string(i);
  		os = e2p_string2os(s);
  		printf("%d: %s (%d)\n", i, s, os);
diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index fb3f7cc..d85fb2f 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -659,6 +659,7 @@ struct ext2_super_block {
  #define EXT2_OBSO_OS_MASIX	2
  #define EXT2_OS_FREEBSD		3
  #define EXT2_OS_LITES		4
+#define EXT2_OS_DRAGONFLY	5

  /*
   * Revision levels
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index 0a7053e..1b7cca2 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -46,6 +46,9 @@
  #include <sys/stat.h>
  #endif
  #include <ctype.h>
+#ifdef __DragonFly__
+#include <sys/diskslice.h>
+#endif

  #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
  #define BLKGETSIZE _IO(0x12,96)	/* return device size */
@@ -155,8 +158,10 @@ errcode_t ext2fs_get_device_size2(const char *file,  
int blocksize,
  #endif
  #ifdef HAVE_SYS_DISKLABEL_H
  	int part;
+#ifndef __DragonFly__
  	struct disklabel lab;
  	struct partition *pp;
+#endif /*__DragonFly__ */
  	char ch;
  #endif /* HAVE_SYS_DISKLABEL_H */

@@ -228,6 +233,14 @@ errcode_t ext2fs_get_device_size2(const char *file,  
int blocksize,
  			goto out;
  		}
  	}
+#elif defined(DIOCGPART)
+/* DragonFly partition information */
+        struct partinfo dp;
+        if (ioctl(fd, DIOCGPART, &dp) >= 0) {
+		*retblocks = dp.media_size / blocksize;
+		goto out;
+	}
+
  #endif /* defined(DIOCG*) */
  #endif /* HAVE_SYS_DISKLABEL_H */

diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index b06371c..e7acb19 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -40,7 +40,11 @@
  #if defined(LITES) 	   &&	defined(EXT2_OS_LITES)
  #define CREATOR_OS EXT2_OS_LITES
  #else
+#if defined(__DragonFly__) &&	defined(EXT2_OS_DRAGONFLY)
+#define CREATOR_OS EXT2_OS_DRAGONFLY
+#else
  #define CREATOR_OS EXT2_OS_LINUX /* by default */
+#endif /* defined(__DragonFly__) &&   defined(EXT2_OS_DRAGONFLY) */
  #endif /* defined(LITES) && defined(EXT2_OS_LITES) */
  #endif /* defined(__FreeBSD__) && defined(EXT2_OS_FREEBSD) */
  #endif /* defined(__GNU__)     && defined(EXT2_OS_HURD) */
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 02570f0..c305a6c 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -554,7 +554,7 @@ static errcode_t unix_open(const char *name, int  
flags, io_channel *channel)
  		io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES;
  #endif

-#if defined(__CYGWIN__) || defined(__FreeBSD__) ||  
defined(__FreeBSD_kernel__)
+#if defined(__CYGWIN__) || defined(__FreeBSD__) ||  
defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  	/*
  	 * Some operating systems require that the buffers be aligned,
  	 * regardless of O_DIRECT
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 7ec8cc2..1bd7f6b 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -641,6 +641,8 @@ static int set_os(struct ext2_super_block *sb, char  
*os)
  		sb->s_creator_os = EXT2_OS_FREEBSD;
  	else if (strcasecmp(os, "lites") == 0)
  		sb->s_creator_os = EXT2_OS_LITES;
+	else if (strcasecmp(os, "dragonfly") == 0)
+		sb->s_creator_os = EXT2_OS_DRAGONFLY;
  	else
  		return 0;
  	return 1;
diff --git a/misc/util.c b/misc/util.c
index 6c93e1c..ead4467 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -93,7 +93,7 @@ void check_plausibility(const char *device)
  				"did you specify it correctly?\n"), stderr);
  		exit(1);
  	}
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ||  
defined(__DragonFly__)
  	/* On FreeBSD, all disk devices are character specials */
  	if (!S_ISBLK(s.st_mode) && !S_ISCHR(s.st_mode))
  #else
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add support for DragonFly BSD operating system.
  2012-07-12 19:48 [PATCH] Add support for DragonFly BSD operating system Antonio Huete Jiménez
@ 2012-07-12 22:25 ` Andreas Dilger
  2012-07-13  0:30 ` Theodore Ts'o
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Dilger @ 2012-07-12 22:25 UTC (permalink / raw)
  To: Antonio Huete Jiménez; +Cc: linux-ext4

On 2012-07-12, at 1:48 PM, Antonio Huete Jiménez wrote:
> Find below a patch to add support for DragonFly BSD to e2fsprogs. In the case it gets rejected please indicate a reason so I can get it fixed.
> @@ -87,8 +89,10 @@ blkid_loff_t blkid_get_dev_size(int fd)
> #endif
> #ifdef HAVE_SYS_DISKLABEL_H
> 	int part = -1;
> +#ifndef __DragonFly__
> 	struct disklabel lab;
> 	struct partition *pp;
> +#endif /* __DragonFly__ */
> 	char ch;
> 	struct stat st;
> #endif /* HAVE_SYS_DISKLABEL_H */

Hmm, why not #ifndef out the whole HAVE_SYS_DISKLABEL_H block?  The "part",
"ch", and "st" variables are only used inside HAVE_SYS_DISKLABEL_H below,
and it appears that "ch" isn't even used anywhere and could just be removed.

It would be cleaner to move these declarations into a small sub-context
at the HAVE_SYS_DISKLABEL_H case (ala HAVE_FSTAT64), since $diety knows
this code has too many #ifdefs already and could use some cleanup.

> @@ -129,11 +133,19 @@ blkid_loff_t blkid_get_dev_size(int fd)
> 		return (off_t)size64;
> #endif /* DIOCGMEDIASIZE */
> 
> +/* tested on DragonFly 3.1-DEVELOPMENT i386/X86_64 */
> +#ifdef DIOCGPART
> +	struct partinfo dp;
> +	if (ioctl(fd, DIOCGPART, &dp) >= 0)
> +		return (off_t)dp.media_size;
> +#endif /* DIOCGPART */

While supported by newer C standards, it is atypical to have variable
declarations in the middle of the code.  Better would be to make this a
small sub-context, like is done with HAVE_FSTAT64.

> #ifdef FDGETPRM
> 	if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
> 		return (blkid_loff_t)this_floppy.size << 9;
> #endif
> #ifdef HAVE_SYS_DISKLABEL_H
> +#ifndef __DragonFly__

Better (IMHO) would be:

#if defined(HAVE_SYS_DISKLABEL_H) && !defined __DragonFly__

> 	/*
> 	 * This code works for FreeBSD 4.11 i386, except for the full device
> 	 * (such as /dev/ad0). It doesn't work properly for newer FreeBSD
> @@ -151,6 +163,7 @@ blkid_loff_t blkid_get_dev_size(int fd)
> 		if (pp->p_size)
> 			return pp->p_size << 9;
> 	}
> +#endif / __DragonFly__ */
> #endif /* HAVE_SYS_DISKLABEL_H */
> 	{
> #if defined(HAVE_FSTAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
> diff --git a/lib/e2p/ostype.c b/lib/e2p/ostype.c
> index d002e75..6d5579a 100644
> --- a/lib/e2p/ostype.c
> +++ b/lib/e2p/ostype.c
> @@ -20,6 +20,7 @@ static const char *os_tab[] =
> 	  "Masix",
> 	  "FreeBSD",
> 	  "Lites",
> +	  "DragonFly",
> 	  0 };
> 
> /*
> @@ -30,7 +31,7 @@ char *e2p_os2string(int os_type)
>         const char	*os;
> 	char 		*ret;
> 
> -	if (os_type <= EXT2_OS_LITES)
> +	if (os_type <= EXT2_OS_DRAGONFLY)
> 		os = os_tab[os_type];
> 	else
> 		os = "(unknown os)";
> @@ -62,7 +63,7 @@ int main(int argc, char **argv)
> 	char 	*s;
> 	int	i, os;
> 
> -	for (i=0; i <= EXT2_OS_LITES; i++) {
> +	for (i=0; i <= EXT2_OS_DRAGONFLY; i++) {
> 		s = e2p_os2string(i);
> 		os = e2p_string2os(s);
> 		printf("%d: %s (%d)\n", i, s, os);
> diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
> index fb3f7cc..d85fb2f 100644
> --- a/lib/ext2fs/ext2_fs.h
> +++ b/lib/ext2fs/ext2_fs.h
> @@ -659,6 +659,7 @@ struct ext2_super_block {
> #define EXT2_OBSO_OS_MASIX	2
> #define EXT2_OS_FREEBSD		3
> #define EXT2_OS_LITES		4
> +#define EXT2_OS_DRAGONFLY	5
> 
> /*
>  * Revision levels
> diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
> index 0a7053e..1b7cca2 100644
> --- a/lib/ext2fs/getsize.c
> +++ b/lib/ext2fs/getsize.c
> @@ -46,6 +46,9 @@
> #include <sys/stat.h>
> #endif
> #include <ctype.h>
> +#ifdef __DragonFly__
> +#include <sys/diskslice.h>
> +#endif
> 
> #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
> #define BLKGETSIZE _IO(0x12,96)	/* return device size */
> @@ -155,8 +158,10 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
> #endif
> #ifdef HAVE_SYS_DISKLABEL_H
> 	int part;
> +#ifndef __DragonFly__
> 	struct disklabel lab;
> 	struct partition *pp;
> +#endif /*__DragonFly__ */
> 	char ch;
> #endif /* HAVE_SYS_DISKLABEL_H */
> 
> @@ -228,6 +233,14 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize,
> 			goto out;
> 		}
> 	}
> +#elif defined(DIOCGPART)
> +/* DragonFly partition information */
> +        struct partinfo dp;
> +        if (ioctl(fd, DIOCGPART, &dp) >= 0) {
> +		*retblocks = dp.media_size / blocksize;
> +		goto out;
> +	}
> +
> #endif /* defined(DIOCG*) */
> #endif /* HAVE_SYS_DISKLABEL_H */

Same comments here.  Makes me wonder if we couldn't share this code in
some manner, but they are independent libraries and we didn't want to have blkid depending on e2fsprogs, though the reverse is already true so maybe
we should just beef up blkid_get_dev_size() and have ext2fs_get_device_size()
and ext2fs_get_device_size2() be thin wrappers around that function?

I don't think it changes frequently enough that we need to worry about the
fact that on Linux the libblkid code is now maintained in util-linux-ng.

> diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
> index b06371c..e7acb19 100644
> --- a/lib/ext2fs/initialize.c
> +++ b/lib/ext2fs/initialize.c
> @@ -40,7 +40,11 @@
> #if defined(LITES) 	   &&	defined(EXT2_OS_LITES)
> #define CREATOR_OS EXT2_OS_LITES
> #else
> +#if defined(__DragonFly__) &&	defined(EXT2_OS_DRAGONFLY)
> +#define CREATOR_OS EXT2_OS_DRAGONFLY
> +#else
> #define CREATOR_OS EXT2_OS_LINUX /* by default */
> +#endif /* defined(__DragonFly__) &&   defined(EXT2_OS_DRAGONFLY) */
> #endif /* defined(LITES) && defined(EXT2_OS_LITES) */
> #endif /* defined(__FreeBSD__) && defined(EXT2_OS_FREEBSD) */
> #endif /* defined(__GNU__)     && defined(EXT2_OS_HURD) */

Ugh.  Existing code uglyness aside, this would be better as an #elif
instead of a nested series if #if/#else blocks.

> diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
> index 02570f0..c305a6c 100644
> --- a/lib/ext2fs/unix_io.c
> +++ b/lib/ext2fs/unix_io.c
> @@ -554,7 +554,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
> 		io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES;
> #endif
> 
> -#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
> +#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
> 	/*
> 	 * Some operating systems require that the buffers be aligned,
> 	 * regardless of O_DIRECT
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index 7ec8cc2..1bd7f6b 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -641,6 +641,8 @@ static int set_os(struct ext2_super_block *sb, char *os)
> 		sb->s_creator_os = EXT2_OS_FREEBSD;
> 	else if (strcasecmp(os, "lites") == 0)
> 		sb->s_creator_os = EXT2_OS_LITES;
> +	else if (strcasecmp(os, "dragonfly") == 0)
> +		sb->s_creator_os = EXT2_OS_DRAGONFLY;
> 	else
> 		return 0;
> 	return 1;
> diff --git a/misc/util.c b/misc/util.c
> index 6c93e1c..ead4467 100644
> --- a/misc/util.c
> +++ b/misc/util.c
> @@ -93,7 +93,7 @@ void check_plausibility(const char *device)
> 				"did you specify it correctly?\n"), stderr);
> 		exit(1);
> 	}
> -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
> +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
> 	/* On FreeBSD, all disk devices are character specials */
> 	if (!S_ISBLK(s.st_mode) && !S_ISCHR(s.st_mode))
> #else
> -- 
> 1.7.3.4
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas





--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add support for DragonFly BSD operating system.
  2012-07-12 19:48 [PATCH] Add support for DragonFly BSD operating system Antonio Huete Jiménez
  2012-07-12 22:25 ` Andreas Dilger
@ 2012-07-13  0:30 ` Theodore Ts'o
  2012-07-16  0:26   ` Antonio Huete Jiménez
  1 sibling, 1 reply; 6+ messages in thread
From: Theodore Ts'o @ 2012-07-13  0:30 UTC (permalink / raw)
  To: Antonio Huete Jiménez; +Cc: linux-ext4

On Thu, Jul 12, 2012 at 09:48:37PM +0200, Antonio Huete Jiménez wrote:
> 
> - Add a new OS tag.

Is there a particular reason why you need the OS tag?  That's really
more of a historical thing than anything else.  I'd be much happier
renaming the FreeBSD tag to BSD.

The only thing where we change what we do based on the OS tag was for
the Hurd operating system, and I consider what was done back then by
Remy Card (one of the original ext2 authors) to be a design mistake.

Also, for future reference, it's highly preferable to have separate
patches for each logically distinct change; it's easier to review,
especially if it's only one patch out of several that needs to be
modified/reworked.

Regards,

						- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add support for DragonFly BSD operating system.
  2012-07-13  0:30 ` Theodore Ts'o
@ 2012-07-16  0:26   ` Antonio Huete Jiménez
  2012-07-16  2:03     ` Theodore Ts'o
  0 siblings, 1 reply; 6+ messages in thread
From: Antonio Huete Jiménez @ 2012-07-16  0:26 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4

Hello Theodore, Andreas,

Thanks for taking the time to review the patch. I've split the patch in  
two parts.

- First one to change the tag as recommended by Theodore. There is not  
specific reason for wanting a tag for DragonFly so I also think the idea  
of a 'BSD' tag is nicer. The rest of main BSDs are included now. I've also  
untangled the #ifdef #else's and converted it to a shorter block using  
#elif, as specified by Andreas.

- Second patch fixes the issues I consider necessary for DragonFly BSD to  
be able to format disk/slices in ext2/3/4 format. Andreas, I've followed  
the recommendation of using less #ifdefs, you will see that patch is  
cleaner now. With regards to merging both libraries (ext2fs and blkid) I  
am afraid I have not much time for doing it, sorry.

I've pasted both new patches in this email with the intention of producing  
less traffic in the mailing list, but I'm unsure if this is the correct  
thing to do, opposed to sending one mail per patch.

If there is anything wrong, just let me know and I'll try to correct it.

Best regards,
Antonio Huete

 From 66c7097eaf08fd9c0e2453fb35c2e95939e3303b Mon Sep 17 00:00:00 2001
From: Antonio Huete Jimenez <tuxillo@quantumachine.net>
Date: Mon, 16 Jul 2012 00:50:50 +0200
Subject: [PATCH 1/2] Common BSD tag for FreeBSD, NetBSD, OpenBSD and  
DragonFly BSD.

- All BSD will appear now as "BSD" under the OS creator field.
- Minor adjustments to multiple #if's

Signed-off-by: Antonio Huete Jimenez <tuxillo@dragonflybsd.org>
---
  lib/e2p/ostype.c        |    2 +-
  lib/ext2fs/ext2_fs.h    |    2 +-
  lib/ext2fs/initialize.c |   19 ++++++-------------
  misc/mke2fs.c           |    8 +++++++-
  4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/lib/e2p/ostype.c b/lib/e2p/ostype.c
index d002e75..f9105fd 100644
--- a/lib/e2p/ostype.c
+++ b/lib/e2p/ostype.c
@@ -18,7 +18,7 @@ static const char *os_tab[] =
         { "Linux",
           "Hurd",
           "Masix",
-         "FreeBSD",
+         "BSD",
           "Lites",
           0 };

diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index fb3f7cc..ca870c9 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -657,7 +657,7 @@ struct ext2_super_block {
  #define EXT2_OS_LINUX          0
  #define EXT2_OS_HURD           1
  #define EXT2_OBSO_OS_MASIX     2
-#define EXT2_OS_FREEBSD                3
+#define EXT2_OS_BSD            3
  #define EXT2_OS_LITES          4

  /*
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index b06371c..b801494 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -28,23 +28,16 @@
  #include "ext2_fs.h"
  #include "ext2fs.h"

-#if defined(__linux__)    &&   defined(EXT2_OS_LINUX)
-#define CREATOR_OS EXT2_OS_LINUX
-#else
-#if defined(__GNU__)     &&    defined(EXT2_OS_HURD)
+#if defined(__GNU__)     &&     defined(EXT2_OS_HURD)
  #define CREATOR_OS EXT2_OS_HURD
-#else
-#if defined(__FreeBSD__) &&    defined(EXT2_OS_FREEBSD)
-#define CREATOR_OS EXT2_OS_FREEBSD
-#else
-#if defined(LITES)        &&   defined(EXT2_OS_LITES)
+#elif (defined(__FreeBSD__) || defined(__NetBSD__) ||  
defined(__OpenBSD__) \
+    || defined(__DragonFly__)) && defined(EXT2_OS_BSD)
+#define CREATOR_OS EXT2_OS_BSD
+#elif defined(LITES)         &&   defined(EXT2_OS_LITES)
  #define CREATOR_OS EXT2_OS_LITES
  #else
  #define CREATOR_OS EXT2_OS_LINUX /* by default */
-#endif /* defined(LITES) && defined(EXT2_OS_LITES) */
-#endif /* defined(__FreeBSD__) && defined(EXT2_OS_FREEBSD) */
-#endif /* defined(__GNU__)     && defined(EXT2_OS_HURD) */
-#endif /* defined(__linux__)   && defined(EXT2_OS_LINUX) */
+#endif

  /*
   * Calculate the number of GDT blocks to reserve for online filesystem  
growth.
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 7ec8cc2..d7ef0e9 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -638,7 +638,13 @@ static int set_os(struct ext2_super_block *sb, char  
*os)
         else if (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0)
                 sb->s_creator_os = EXT2_OS_HURD;
         else if (strcasecmp(os, "freebsd") == 0)
-               sb->s_creator_os = EXT2_OS_FREEBSD;
+               sb->s_creator_os = EXT2_OS_BSD;
+       else if (strcasecmp(os, "netbsd") == 0)
+               sb->s_creator_os = EXT2_OS_BSD;
+       else if (strcasecmp(os, "openbsd") == 0)
+               sb->s_creator_os = EXT2_OS_BSD;
+       else if (strcasecmp(os, "dragonfly") == 0)
+               sb->s_creator_os = EXT2_OS_BSD;
         else if (strcasecmp(os, "lites") == 0)
                 sb->s_creator_os = EXT2_OS_LITES;
         else
--
1.7.3.4

 From 2c310b676a8fe9e1f2187aadcfc84cbeca07539d Mon Sep 17 00:00:00 2001
From: Antonio Huete Jimenez <tuxillo@quantumachine.net>
Date: Mon, 16 Jul 2012 01:25:55 +0200
Subject: [PATCH 2/2] Fix to support DragonFly BSD

- DragonFly uses DIOCGPART to return disk information.

Signed-off-by: Antonio Huete Jimenez <tuxillo@dragonflybsd.org>
---
  lib/blkid/getsize.c  |   15 ++++++++++++---
  lib/ext2fs/getsize.c |   20 ++++++++++++++++----
  lib/ext2fs/unix_io.c |    2 +-
  misc/util.c          |    2 +-
  4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c
index f670e1b..0536968 100644
--- a/lib/blkid/getsize.c
+++ b/lib/blkid/getsize.c
@@ -46,6 +46,9 @@
  #include <sys/stat.h>
  #endif

+#ifdef __DragonFly__
+#include <sys/diskslice.h>
+#endif

  #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
  #define BLKGETSIZE _IO(0x12,96)        /* return device size */
@@ -85,11 +88,10 @@ blkid_loff_t blkid_get_dev_size(int fd)
  #ifdef FDGETPRM
         struct floppy_struct this_floppy;
  #endif
-#ifdef HAVE_SYS_DISKLABEL_H
+#if defined(HAVE_SYS_DISKLABEL_H) && !defined(__DragonFly__)
         int part = -1;
         struct disklabel lab;
         struct partition *pp;
-       char ch;
         struct stat st;
  #endif /* HAVE_SYS_DISKLABEL_H */

@@ -129,11 +131,18 @@ blkid_loff_t blkid_get_dev_size(int fd)
                 return (off_t)size64;
  #endif /* DIOCGMEDIASIZE */

+/* tested on DragonFly 3.1-DEVELOPMENT i386/X86_64 */
+#ifdef DIOCGPART
+       struct partinfo dp;
+       if (ioctl(fd, DIOCGPART, &dp) >= 0)
+               return (off_t)dp.media_size;
+#endif /* DIOCGPART */
+
  #ifdef FDGETPRM
         if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
                 return (blkid_loff_t)this_floppy.size << 9;
  #endif
-#ifdef HAVE_SYS_DISKLABEL_H
+#if defined(HAVE_SYS_DISKLABEL_H) && !defined(__DragonFly__)
         /*
          * This code works for FreeBSD 4.11 i386, except for the full  
device
          * (such as /dev/ad0). It doesn't work properly for newer FreeBSD
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index 0a7053e..ce9404e 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -46,6 +46,9 @@
  #include <sys/stat.h>
  #endif
  #include <ctype.h>
+#ifdef __DragonFly__
+#include <sys/diskslice.h>
+#endif

  #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
  #define BLKGETSIZE _IO(0x12,96)        /* return device size */
@@ -153,12 +156,12 @@ errcode_t ext2fs_get_device_size2(const char *file,  
int blocksize,
  #ifdef FDGETPRM
         struct floppy_struct this_floppy;
  #endif
-#ifdef HAVE_SYS_DISKLABEL_H
+#if defined(HAVE_SYS_DISKLABEL_H) && !defined(__DragonFly__)
         int part;
         struct disklabel lab;
         struct partition *pp;
         char ch;
-#endif /* HAVE_SYS_DISKLABEL_H */
+#endif /* HAVE_SYS_DISKLABEL_H && !defined(__DragonFly__) */

         fd = ext2fs_open_file(file, O_RDONLY, 0);
         if (fd < 0)
@@ -199,7 +202,7 @@ errcode_t ext2fs_get_device_size2(const char *file,  
int blocksize,
         }
  #endif

-#ifdef HAVE_SYS_DISKLABEL_H
+#if defined(HAVE_SYS_DISKLABEL_H)
  #if defined(DIOCGMEDIASIZE)
         {
             off_t ms;
@@ -228,8 +231,17 @@ errcode_t ext2fs_get_device_size2(const char *file,  
int blocksize,
                         goto out;
                 }
         }
+#elif defined(DIOCGPART)
+       /* DragonFly partition information */
+       struct partinfo dp;
+       if (ioctl(fd, DIOCGPART, &dp) >= 0) {
+               *retblocks = dp.media_size / blocksize;
+               printf("success!\n");
+               goto out;
+       }
+
  #endif /* defined(DIOCG*) */
-#endif /* HAVE_SYS_DISKLABEL_H */
+#endif /* HAVE_SYS_DISKLABEL_H && !defined(__DragonFly__) */

         {
                 ext2fs_struct_stat st;
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 02570f0..ad28bc3 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -554,7 +554,7 @@ static errcode_t unix_open(const char *name, int  
flags, io_channel *channel)
                 io->flags |= CHANNEL_FLAGS_DISCARD_ZEROES;
  #endif

-#if defined(__CYGWIN__) || defined(__FreeBSD__) ||  
defined(__FreeBSD_kernel__)
+#if defined(__CYGWIN__) || defined(__FreeBSD__) ||  
defined(__FreeBSD_kernel__) || defined(__DragonFly)
         /*
          * Some operating systems require that the buffers be aligned,
          * regardless of O_DIRECT
diff --git a/misc/util.c b/misc/util.c
index 6c93e1c..ead4467 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -93,7 +93,7 @@ void check_plausibility(const char *device)
                                 "did you specify it correctly?\n"),  
stderr);
                 exit(1);
         }
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ||  
defined(__DragonFly__)
         /* On FreeBSD, all disk devices are character specials */
         if (!S_ISBLK(s.st_mode) && !S_ISCHR(s.st_mode))
  #else
--
1.7.3.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add support for DragonFly BSD operating system.
  2012-07-16  0:26   ` Antonio Huete Jiménez
@ 2012-07-16  2:03     ` Theodore Ts'o
       [not found]       ` <CACegU+tjX0_6zkADvL2F1GP1QOZpPYk8sK5ETCEvw3FqU3aXiA@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Theodore Ts'o @ 2012-07-16  2:03 UTC (permalink / raw)
  To: Antonio Huete Jiménez; +Cc: Andreas Dilger, linux-ext4

On Mon, Jul 16, 2012 at 02:26:57AM +0200, Antonio Huete Jiménez wrote:
> I've pasted both new patches in this email with the intention of
> producing less traffic in the mailing list, but I'm unsure if this
> is the correct thing to do, opposed to sending one mail per patch.

It's better to send one mail per patch.  The reason for that is we
have automated tools that do the right thing with patches sent one per
e-mail.  This includes patchwork (which tracks patches sent to the
mailing list; see
http://patchwork.ozlabs.org/project/linux-ext4/list/) and "git am".

Just use the git send-email tool; it will do the right thing.

There are places where you are using #if defined(__DragonFly__) and
there are other places where you are using #ifdef DIOCGPART.  Is there
a reason for this?

In general, it's better to avoid using explicit feature tests rather
things like defined(__Dragonfly__) or defined(__solaris__).  What if
an OS changes names or forks (i.e., like Open Solaris, Nextensa,
Illumos, etc.).

And the combination of an #ifdef based on HAVE_SYS_DISKLABEL_H,
DIOCGPART, and defined(__DragonFly__) raises red flags that the
combinatorics may be very brittle in the long run.

Regards,

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Fwd: [PATCH] Add support for DragonFly BSD operating system.
       [not found]       ` <CACegU+tjX0_6zkADvL2F1GP1QOZpPYk8sK5ETCEvw3FqU3aXiA@mail.gmail.com>
@ 2012-08-20 12:28         ` Antonio Huete Jimenez
  0 siblings, 0 replies; 6+ messages in thread
From: Antonio Huete Jimenez @ 2012-08-20 12:28 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4

2012/7/16 Theodore Ts'o <tytso@mit.edu>
>
> On Mon, Jul 16, 2012 at 02:26:57AM +0200, Antonio Huete Jiménez wrote:
> > I've pasted both new patches in this email with the intention of
> > producing less traffic in the mailing list, but I'm unsure if this
> > is the correct thing to do, opposed to sending one mail per patch.
>
> It's better to send one mail per patch.  The reason for that is we
> have automated tools that do the right thing with patches sent one per
> e-mail.  This includes patchwork (which tracks patches sent to the
> mailing list; see
> http://patchwork.ozlabs.org/project/linux-ext4/list/) and "git am".
>
> Just use the git send-email tool; it will do the right thing.


I've used git send-email to send the patch that combines all BSDs into
a single tag.

>
>
> There are places where you are using #if defined(__DragonFly__) and
> there are other places where you are using #ifdef DIOCGPART.  Is there
> a reason for this?

I've used DIOCGPART because the rest of the code around uses
DIOCGMEDIASIZE, DIOCGDINFO in a kind of sorted order, so I just copied
the style.

>
>
> In general, it's better to avoid using explicit feature tests rather
> things like defined(__Dragonfly__) or defined(__solaris__).  What if
> an OS changes names or forks (i.e., like Open Solaris, Nextensa,
> Illumos, etc.).
>

Same could happen to the DIOCGDINFO #ifdefs, no?

>
> And the combination of an #ifdef based on HAVE_SYS_DISKLABEL_H,
> DIOCGPART, and defined(__DragonFly__) raises red flags that the
> combinatorics may be very brittle in the long run.
>

Right but in some parts it is necessary to skip the code even if
HAVE_SYS_DISKLABEL_H is defined. If you think there's a better way,
just let me know and I'll change it righaway.

>
> Regards,
>
>                                         - Ted


Cheers,
Antonio Huete
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-08-20 12:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-12 19:48 [PATCH] Add support for DragonFly BSD operating system Antonio Huete Jiménez
2012-07-12 22:25 ` Andreas Dilger
2012-07-13  0:30 ` Theodore Ts'o
2012-07-16  0:26   ` Antonio Huete Jiménez
2012-07-16  2:03     ` Theodore Ts'o
     [not found]       ` <CACegU+tjX0_6zkADvL2F1GP1QOZpPYk8sK5ETCEvw3FqU3aXiA@mail.gmail.com>
2012-08-20 12:28         ` Fwd: " Antonio Huete Jimenez

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.