linux-embedded.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Mundt <lethal@linux-sh.org>
To: Marco Stornelli <marco.stornelli@gmail.com>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>,
	Linux Embedded <linux-embedded@vger.kernel.org>,
	Linux FS Devel <linux-fsdevel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tim Bird <tim.bird@am.sony.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: Re: [PATCH 09/16 v4] pramfs: dir operations
Date: Wed, 24 Nov 2010 17:17:55 +0900	[thread overview]
Message-ID: <20101124081755.GD2212@linux-sh.org> (raw)
In-Reply-To: <4CE79C4D.6000104@gmail.com>

On Sat, Nov 20, 2010 at 11:00:45AM +0100, Marco Stornelli wrote:
> +int pram_add_link(struct dentry *dentry, struct inode *inode)
> +{
> +	struct inode *dir = dentry->d_parent->d_inode;
> +	struct pram_inode *pidir, *pi, *pitail = NULL;
> +	u64 tail_ino, prev_ino;
> +
> +	const char *name = dentry->d_name.name;
> +
> +	int namelen = dentry->d_name.len > PRAM_NAME_LEN ?
> +		PRAM_NAME_LEN : dentry->d_name.len;
> +

	namelen = min_t(unsigned int, dentry->d_name.len, PRAM_NAME_LEN);

?

> +#define S_SHIFT 12
> +static unsigned int dtype_by_mode[S_IFMT >> S_SHIFT] = {
> +	[S_IFREG >> S_SHIFT]    DT_REG,
> +	[S_IFDIR >> S_SHIFT]    DT_DIR,
> +	[S_IFCHR >> S_SHIFT]    DT_CHR,
> +	[S_IFBLK >> S_SHIFT]    DT_BLK,
> +	[S_IFIFO >> S_SHIFT]    DT_FIFO,
> +	[S_IFSOCK >> S_SHIFT]   DT_SOCK,
> +	[S_IFLNK >> S_SHIFT]    DT_LNK,
> +};
> +
> +static int pram_readdir(struct file *filp, void *dirent, filldir_t filldir)
> +{
...
> +		ret = filldir(dirent, name, namelen,
> +			      filp->f_pos, ino,
> +			      dtype_by_mode[(be16_to_cpu(pi->i_mode) & S_IFMT)>>S_SHIFT]);
> +		filp->f_pos = pi->i_d.d_next ? be64_to_cpu(pi->i_d.d_next) : 3;

You might try to provide some generic helpers for this, at least GFS2
also does the same thing:

include/linux/gfs2_ondisk.h:#define DT2IF(dt) (((dt) << 12) & S_IFMT)
include/linux/gfs2_ondisk.h:#define IF2DT(sif) (((sif) & S_IFMT) >> 12)

  reply	other threads:[~2010-11-24  8:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-20 10:00 [PATCH 09/16 v4] pramfs: dir operations Marco Stornelli
2010-11-24  8:17 ` Paul Mundt [this message]
2010-11-24  8:30   ` Marco Stornelli

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=20101124081755.GD2212@linux-sh.org \
    --to=lethal@linux-sh.org \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@suse.de \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marco.stornelli@gmail.com \
    --cc=tim.bird@am.sony.com \
    /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;
as well as URLs for NNTP newsgroup(s).