From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: Re: [PATCH] hfsplus: emit proper file type from readdir Date: Fri, 9 May 2014 15:05:03 -0400 Message-ID: <20140509190503.GA6121@linux.intel.com> References: <1399474449-5415-1-git-send-email-saproj@gmail.com> <1399479937.2400.22.camel@slavad-CELSIUS-H720> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Vyacheslav Dubeyko , Anton Altaparmakov , "linux-fsdevel@vger.kernel.org" , Al Viro , Christoph Hellwig , Andrew Morton , Hin-Tak Leung To: Sergei Antonov Return-path: Received: from mga01.intel.com ([192.55.52.88]:19811 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752159AbaEJJbz (ORCPT ); Sat, 10 May 2014 05:31:55 -0400 Content-Disposition: inline In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed, May 07, 2014 at 06:56:56PM +0200, Sergei Antonov wrote: > On 7 May 2014 18:25, Vyacheslav Dubeyko 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.