From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Andreas Dilger <adilger@dilger.ca>
Cc: Jonny Grant <jg@jguk.org>,
Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: /fs/ext4/ext4.h add a comment to ext4_dir_entry_2
Date: Mon, 4 May 2020 15:39:00 -0700 [thread overview]
Message-ID: <20200504223900.GA5691@magnolia> (raw)
In-Reply-To: <1B91A6E6-7F4A-4C58-93E7-394217C1631C@dilger.ca>
On Mon, May 04, 2020 at 04:26:35PM -0600, Andreas Dilger wrote:
>
> > On May 3, 2020, at 6:52 AM, Jonny Grant <jg@jguk.org> wrote:
> >
> > Hello
> >
> > Could a comment be added to clarify 'file_type' ?
> >
> > struct ext4_dir_entry_2 {
> > __le32 inode; /* Inode number */
> > __le16 rec_len; /* Directory entry length */
> > __u8 name_len; /* Name length */
> > __u8 file_type;
> > char name[EXT4_NAME_LEN]; /* File name */
> > };
> >
> >
> >
> > This what I am proposing to add:
> >
> > __u8 file_type; /* See directory file type macros below */
>
> For this kind of structure field, it makes sense to reference the macro
> names directly, like:
>
> __u8 file_type; /* See EXT4_FT_* type macros below */
>
> since "macros below" may be ambiguous as the header changes over time.
>
>
> Even better (IMHO) is to use a named enum for this, like:
>
> enum ext4_file_type file_type:8; /* See EXT4_FT_ types below */
>
> /*
> * Ext4 directory file types. Only the low 3 bits are used. The
> * other bits are reserved for now.
> */
> enum ext4_file_type {
> EXT4_FT_UNKNOWN = 0,
> EXT4_FT_REG_FILE = 1,
> EXT4_FT_DIR = 2,
> EXT4_FT_CHRDEV = 3,
> EXT4_FT_BLKDEV = 4,
> EXT4_FT_FIFO = 5,
> EXT4_FT_SOCK = 6,
> EXT4_FT_SYMLINK = 7,
> EXT4_FT_MAX,
> EXT4_FT_DIR_CSUM = 0xDE
> };
>
> so that the allowed values for this field are clear from the definition.
> However, the use of a fixed-with bitfield (enum :8) is a GCC-ism and Ted
> may be against that for portability reasons, since the kernel and
> userspace headers should be as similar as possible.
This is an on-disk structure. Do /not/ make this an enum because that
would replace a __u8 with an int, which will break directories.
--D
> Cheers, Andreas
>
>
>
>
>
next prev parent reply other threads:[~2020-05-04 22:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-03 12:52 /fs/ext4/ext4.h add a comment to ext4_dir_entry_2 Jonny Grant
2020-05-04 22:26 ` Andreas Dilger
2020-05-04 22:39 ` Darrick J. Wong [this message]
2020-05-04 23:00 ` Andreas Dilger
2020-05-04 23:14 ` Jonny Grant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200504223900.GA5691@magnolia \
--to=darrick.wong@oracle.com \
--cc=adilger@dilger.ca \
--cc=jg@jguk.org \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox