Linux filesystem development
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@linux.intel.com>
To: Sergei Antonov <saproj@gmail.com>
Cc: Vyacheslav Dubeyko <slava@dubeyko.com>,
	Anton Altaparmakov <aia21@cam.ac.uk>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Hin-Tak Leung <htl10@users.sourceforge.net>
Subject: Re: [PATCH] hfsplus: emit proper file type from readdir
Date: Fri, 9 May 2014 15:05:03 -0400	[thread overview]
Message-ID: <20140509190503.GA6121@linux.intel.com> (raw)
In-Reply-To: <CABikg9wYAacJW2Oj0jSZDGe_MTOE7EdBFBUFCvi0g9Pb0=WGEg@mail.gmail.com>

On Wed, May 07, 2014 at 06:56:56PM +0200, Sergei Antonov wrote:
> On 7 May 2014 18:25, Vyacheslav Dubeyko <slava@dubeyko.com> wrote:
> > I believe that such example is good solution too:
> >
> > static unsigned char
> > nilfs_filetype_table[NILFS_FT_MAX] = {
> >         [NILFS_FT_UNKNOWN]      = DT_UNKNOWN,
> >         [NILFS_FT_REG_FILE]     = DT_REG,
> >         [NILFS_FT_DIR]          = DT_DIR,
> >         [NILFS_FT_CHRDEV]       = DT_CHR,
> >         [NILFS_FT_BLKDEV]       = DT_BLK,
> >         [NILFS_FT_FIFO]         = DT_FIFO,
> >         [NILFS_FT_SOCK]         = DT_SOCK,
> >         [NILFS_FT_SYMLINK]      = DT_LNK,
> > };
> >
> > What about likewise way?
> 
> Using an array means calculating an index to it using such expression:
> (mode & S_IFMT) >> 12.
> I prefer a more straightforward "if/else if".

This should all be wrapped up neatly like so:

 		} else if (type == HFSPLUS_FILE) {
+			unsigned type;
+
			if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
				pr_err("small file entry\n");
				err = -EIO;
				goto out;
			}
+
+			type = hfsplus_de_type(&entry);
+
			if (!dir_emit(ctx, strbuf, len,
-					be32_to_cpu(entry.file.id), DT_REG))
+					be32_to_cpu(entry.file.id), type))
 				break;

and then the array, case, series of else ifs, whatever can all be confined
to a single function.

  reply	other threads:[~2014-05-10  9:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07 14:54 [PATCH] hfsplus: emit proper file type from readdir Sergei Antonov
2014-05-07 15:55 ` Anton Altaparmakov
2014-05-07 16:25   ` Vyacheslav Dubeyko
2014-05-07 16:41     ` Anton Altaparmakov
2014-05-07 16:56     ` Sergei Antonov
2014-05-09 19:05       ` Matthew Wilcox [this message]
2014-05-10 18:11         ` Sergei Antonov

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=20140509190503.GA6121@linux.intel.com \
    --to=willy@linux.intel.com \
    --cc=aia21@cam.ac.uk \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=htl10@users.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=saproj@gmail.com \
    --cc=slava@dubeyko.com \
    --cc=viro@zeniv.linux.org.uk \
    /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