lkml.org 
[lkml]   [2018]   [Oct]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] fs: ufs: Remove switch statement from ufs_set_de_type function
On Wed, Oct 17, 2018 at 10:11:47AM +0000, David Laight wrote:
> From: Phillip Potter
> > Sent: 17 October 2018 11:08
> >
> > Remove switch statement from ufs_set_de_type function in fs/ufs/util.h
> > header and replace with simple assignment. For each case, S_IFx >> 12
> > is equal to DT_x, so in valid cases (mode & S_IFMT) >> 12 should give
> > us the correct file type. For invalid cases, upper layer validation
> > catches this anyway, so this improves readability and arguably
> > performance by assigning (mode & S_IFMT) >> 12 directly.
> >
> ...
> > - case S_IFIFO:
> > - de->d_u.d_44.d_type = DT_FIFO;
> > - break;
> > - default:
> > - de->d_u.d_44.d_type = DT_UNKNOWN;
> > - }
> > + de->d_u.d_44.d_type = (mode & S_IFMT) >> S_SHIFT;
>
> This requires that the two sets of constants are correctly aligned.

They are. BSD folks had (sanely, IMO) put the 'type' bits of st_mode
into directory entry verbatim. Again, "symbolic constant" != "can be
expected to change"... If, e.g., some port decides to change S_IFIFO,
they'll have no end of fun accessing ext*, xfs, ufs, etc. since that
value is stored in the on-disk inode and in effect pinned down by
that.

All S_... constants are universal and going to remain unchanged on
any Unices.

\
 
 \ /
  Last update: 2018-10-18 01:33    [W:0.091 / U:0.428 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site