* [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes
@ 2009-11-18 16:25 Jan Blunck
2009-11-19 7:34 ` Andreas Dilger
0 siblings, 1 reply; 4+ messages in thread
From: Jan Blunck @ 2009-11-18 16:25 UTC (permalink / raw)
To: Andreas Dilger; +Cc: Linux-Kernel Mailinglist, Andrew Morton, Jan Kara
Here is an old patch that I found in my tree. Andreas, it seems that this is
something you proposed.
Comments?
Jan
>From 290d3d969850ff9555bc213035b1c4e401ea9ada Mon Sep 17 00:00:00 2001
From: Jan Blunck <jblunck@suse.de>
Date: Wed, 18 Nov 2009 17:10:56 +0100
Subject: [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes
It is somewhat dangerous to use a straight enum here, because this will
reassign values of later variables if one of the earlier ones is removed.
Signed-off-by: Jan Blunck <jblunck@suse.de>
Cc: Andreas Dilger <adilger@sun.com>
---
include/linux/ext2_fs.h | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/linux/ext2_fs.h b/include/linux/ext2_fs.h
index 121720d..2dfa707 100644
--- a/include/linux/ext2_fs.h
+++ b/include/linux/ext2_fs.h
@@ -565,14 +565,14 @@ struct ext2_dir_entry_2 {
* other bits are reserved for now.
*/
enum {
- EXT2_FT_UNKNOWN,
- EXT2_FT_REG_FILE,
- EXT2_FT_DIR,
- EXT2_FT_CHRDEV,
- EXT2_FT_BLKDEV,
- EXT2_FT_FIFO,
- EXT2_FT_SOCK,
- EXT2_FT_SYMLINK,
+ EXT2_FT_UNKNOWN = 0,
+ EXT2_FT_REG_FILE = 1,
+ EXT2_FT_DIR = 2,
+ EXT2_FT_CHRDEV = 3,
+ EXT2_FT_BLKDEV = 4,
+ EXT2_FT_FIFO = 5,
+ EXT2_FT_SOCK = 6,
+ EXT2_FT_SYMLINK = 7,
EXT2_FT_MAX
};
--
1.6.4.2
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes
2009-11-18 16:25 [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes Jan Blunck
@ 2009-11-19 7:34 ` Andreas Dilger
2009-11-19 14:38 ` Jan Kara
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Dilger @ 2009-11-19 7:34 UTC (permalink / raw)
To: Jan Blunck; +Cc: Linux-Kernel Mailinglist, Andrew Morton, Jan Kara
On 2009-11-18, at 08:25, Jan Blunck wrote:
> Here is an old patch that I found in my tree. Andreas, it seems that
> this is something you proposed.
>
> Comments?
This is definitely my preferred coding style for constants that form a
permanent part of the API/ABI/disk format.
The enum is useful because some debuggers can display the symbolic
name of a constant if a named enum is present (though in this case it
isn't), but it avoids the risk of someone accidentally inserting or
removing a value in the middle of the enum.
For in-memory-only enums that isn't important at all, but for some
developers it isn't always clear what is in-memory and what is on-disk
or part of an API. Also, the compiler will warn if the same value is
assigned multiple times, which isn't necessarily a worry with the few
values here, but for large lists of #defines like e.g.
EXT2_FEATURE_INCOMPAT_* it is a real risk, and I've seen a few cases
where the same value was #defined multiple times accidentally (e.g.
with patches vs. upstream merges).
> From 290d3d969850ff9555bc213035b1c4e401ea9ada Mon Sep 17 00:00:00 2001
> From: Jan Blunck <jblunck@suse.de>
> Date: Wed, 18 Nov 2009 17:10:56 +0100
> Subject: [PATCH] ext2: Explicitly assign values to on-disk enum of
> filetypes
>
> It is somewhat dangerous to use a straight enum here, because this
> will
> reassign values of later variables if one of the earlier ones is
> removed.
>
> Signed-off-by: Jan Blunck <jblunck@suse.de>
> Cc: Andreas Dilger <adilger@sun.com>
> ---
> include/linux/ext2_fs.h | 16 ++++++++--------
> 1 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/ext2_fs.h b/include/linux/ext2_fs.h
> index 121720d..2dfa707 100644
> --- a/include/linux/ext2_fs.h
> +++ b/include/linux/ext2_fs.h
> @@ -565,14 +565,14 @@ struct ext2_dir_entry_2 {
> * other bits are reserved for now.
> */
> enum {
> - EXT2_FT_UNKNOWN,
> - EXT2_FT_REG_FILE,
> - EXT2_FT_DIR,
> - EXT2_FT_CHRDEV,
> - EXT2_FT_BLKDEV,
> - EXT2_FT_FIFO,
> - EXT2_FT_SOCK,
> - EXT2_FT_SYMLINK,
> + EXT2_FT_UNKNOWN = 0,
> + EXT2_FT_REG_FILE = 1,
> + EXT2_FT_DIR = 2,
> + EXT2_FT_CHRDEV = 3,
> + EXT2_FT_BLKDEV = 4,
> + EXT2_FT_FIFO = 5,
> + EXT2_FT_SOCK = 6,
> + EXT2_FT_SYMLINK = 7,
> EXT2_FT_MAX
> };
>
> --
> 1.6.4.2
>
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes
2009-11-19 7:34 ` Andreas Dilger
@ 2009-11-19 14:38 ` Jan Kara
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2009-11-19 14:38 UTC (permalink / raw)
To: Andreas Dilger
Cc: Jan Blunck, Linux-Kernel Mailinglist, Andrew Morton, Jan Kara
On Wed 18-11-09 23:34:46, Andreas Dilger wrote:
> On 2009-11-18, at 08:25, Jan Blunck wrote:
> >Here is an old patch that I found in my tree. Andreas, it seems
> >that this is something you proposed.
> >
> >Comments?
>
> This is definitely my preferred coding style for constants that form
> a permanent part of the API/ABI/disk format.
>
> The enum is useful because some debuggers can display the symbolic
> name of a constant if a named enum is present (though in this case
> it isn't), but it avoids the risk of someone accidentally inserting
> or removing a value in the middle of the enum.
In this particular case, I don't have a strong opinion... There isn't
much churn in FT_ fields but OTOH it doesn't hurt to have numbers
explicitely assigned and as you write for on-disk format it's really
important to have them fixed. OK, probably I'm slightly in favor of
merging the patch so I've queued it up.
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes
@ 2009-05-19 10:00 Jan Blunck
0 siblings, 0 replies; 4+ messages in thread
From: Jan Blunck @ 2009-05-19 10:00 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel; +Cc: Andreas Dilger
It is somewhat dangerous to use a straight enum here, because this will
reassign values of later variables if one of the earlier ones is removed.
Signed-off-by: Andreas Dilger <adilger@sun.com>
Signed-off-by: Jan Blunck <jblunck@suse.de>
---
include/linux/ext2_fs.h | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/linux/ext2_fs.h b/include/linux/ext2_fs.h
index 121720d..2dfa707 100644
--- a/include/linux/ext2_fs.h
+++ b/include/linux/ext2_fs.h
@@ -565,14 +565,14 @@ struct ext2_dir_entry_2 {
* other bits are reserved for now.
*/
enum {
- EXT2_FT_UNKNOWN,
- EXT2_FT_REG_FILE,
- EXT2_FT_DIR,
- EXT2_FT_CHRDEV,
- EXT2_FT_BLKDEV,
- EXT2_FT_FIFO,
- EXT2_FT_SOCK,
- EXT2_FT_SYMLINK,
+ EXT2_FT_UNKNOWN = 0,
+ EXT2_FT_REG_FILE = 1,
+ EXT2_FT_DIR = 2,
+ EXT2_FT_CHRDEV = 3,
+ EXT2_FT_BLKDEV = 4,
+ EXT2_FT_FIFO = 5,
+ EXT2_FT_SOCK = 6,
+ EXT2_FT_SYMLINK = 7,
EXT2_FT_MAX
};
--
1.6.1.3
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-19 14:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-18 16:25 [PATCH] ext2: Explicitly assign values to on-disk enum of filetypes Jan Blunck
2009-11-19 7:34 ` Andreas Dilger
2009-11-19 14:38 ` Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2009-05-19 10:00 Jan Blunck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®