From mboxrd@z Thu Jan 1 00:00:00 1970 From: Maneesh Soni Subject: Re: Help on automatic population of directories Date: Mon, 8 Mar 2004 11:44:01 +0530 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20040308061401.GA23384@in.ibm.com> References: <4048B0ED.1010702@watson.ibm.com> Reply-To: maneesh@in.ibm.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel Return-path: Received: from e5.ny.us.ibm.com ([32.97.182.105]:33158 "EHLO e5.ny.us.ibm.com") by vger.kernel.org with ESMTP id S262419AbUCHGif (ORCPT ); Mon, 8 Mar 2004 01:38:35 -0500 Received: from northrelay04.pok.ibm.com (northrelay04.pok.ibm.com [9.56.224.206]) by e5.ny.us.ibm.com (8.12.10/8.12.2) with ESMTP id i286cXJr575040 for ; Mon, 8 Mar 2004 01:38:33 -0500 To: Shailabh Content-Disposition: inline In-Reply-To: <4048B0ED.1010702@watson.ibm.com> List-Id: linux-fsdevel.vger.kernel.org On Fri, Mar 05, 2004 at 04:57:49PM +0000, Shailabh wrote: > Hi, > > I'm writing a ram-based filesystem. I want the filesystem to > automatically create a few files inside every directory that a user creates. > > > I'm trying to do this within the mkdir dir_inode op of the fs > using code which looks like this: > > >>>>>>>>>>>>>>>>>> > /* rcfs_mknod and rcfs_get_inode are replicas of corresponding code from > fs/ramfs/inode.c */ > > static int > rcfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) > { > struct inode * inode = rcfs_get_inode(dir->i_sb, mode, dev); > int error = -ENOSPC, i=0; > > if (inode) { > if (dir->i_mode & S_ISGID) { > inode->i_gid = dir->i_gid; > if (S_ISDIR(mode)) > inode->i_mode |= S_ISGID; > } > d_instantiate(dentry, inode); > dget(dentry); /* Extra count - pin the dentry in core */ > error = 0; > } > return error; > } > > static int rcfs_mkdir(struct inode * dir, struct dentry * dentry, int mode) > { > int retval = rcfs_mknod(dir, dentry, mode | S_IFDIR, 0); > /* rcfs_mknod is a complete replica of > fs/ramfs/inode.c:ramfs_mknod */ > > if (!retval) > dir->i_nlink++; > > /* Do something here to create some "magic" files in this > directory before returning to the user */ > > return retval; > } > > <<<<<<<<<<<<<<<<<<<<<<<<<< > > Q1: is there sufficient info in the dir/dentry variables for a file to > be created within rcfs_mkdir (at the comment point) ? If so, what would > be the best way to do this ? > For creating new files, dentry and inode for the new files are needed. So that can be done as follows where dentry is the dentry for the directory under which you want to create new files. down(&dentry->d_inode->i_sem); new_dentry = rcfs_get_dentry(dentry->d_inode, "New_file"); if (!IS_ERR(new_dentry)) { retval = rcfs_mknod(dentry->d_inode, new_dentry, mode, 0); } up(&dentry->d_inode->i_sem); Now for rcfs_get_dentry(), have a look at sysfs_get_dentry(). This should allocate new dentry if it is not already in dcache. Also you have to define ->lookup() dir_inode operation as simple_lookup(). > > Q2: How can one find the vfsmnt given the dentry of a directory that has > just been created ? > > I was thinking of using d_path() to lookup the complete path of the > just-created directory and then calling a modified version of sys_mknod > on the resulting string. Probably not the best way of doing this but it > was simpler to understand :-) But I'm having trouble determining the > vfsmnt from the dentry returned from rcfs_mknod - I tried using > current->namespace->root and also current->fs->rootmnt with no success - > dpath returns blank or garbage as the resulting string and not > "/rcfs/hello/" which is what I expect when directory hello is being created. > Why do you need this?.. It seems you want to know the absolute path for the new created dentry. Maneesh -- Maneesh Soni Linux Technology Center, IBM Software Lab, Bangalore, India email: maneesh@in.ibm.com Phone: 91-80-25044999 Fax: 91-80-25268553 T/L : 9243696