linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Help on automatic population of directories
@ 2004-03-05 16:55 Shailabh
  2004-03-06 20:51 ` Jan Hudec
  2004-03-08  6:14 ` Maneesh Soni
  0 siblings, 2 replies; 6+ messages in thread
From: Shailabh @ 2004-03-05 16:55 UTC (permalink / raw)
  To: linux-fsdevel

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 ?


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.



I'm new to filesystem development and still not completely clear about 
the relationships between mount points, dentries etc....Any pointers on
useful functions would be much appreciated !


Thanks,
Shailabh

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-03-09  8:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-05 16:55 Help on automatic population of directories Shailabh
2004-03-06 20:51 ` Jan Hudec
2004-03-08 20:32   ` Shailabh Nagar
2004-03-09  8:22     ` Jan Hudec
2004-03-08  6:14 ` Maneesh Soni
2004-03-08 20:38   ` Shailabh Nagar

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).