Exercise with ramfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Let's suppose I want to create a file "bar" on the creation of
the file "foo" with a ramfs-like filesystem, actually "myramfs" :)

Below follows some code from fs/ramfs/inode.c:


struct inode *myramfs_get_inode(struct super_block *sb, int mode, int dev)
{
	struct inode * inode = new_inode(sb);

	if (inode) {
		inode->i_mode = mode;
		inode->i_uid = current->fsuid;
		inode->i_gid = current->fsgid;
		inode->i_blksize = PAGE_CACHE_SIZE;
		inode->i_blocks = 0;
		inode->i_rdev = NODEV;
		inode->i_mapping->a_ops = &myramfs_aops;
		inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
		switch (mode & S_IFMT) {
		default:
			init_special_inode(inode, mode, dev);
			break;
		case S_IFREG:
			inode->i_fop = &myramfs_file_operations;
			break;
		case S_IFDIR:
			inode->i_op = &myramfs_dir_inode_operations;
			inode->i_fop = &myramfs_dir_operations;
			break;
		case S_IFLNK:
			inode->i_op = &page_symlink_inode_operations;
			break;
		}
	}
	return inode;
}

/*
 * File creation. Allocate an inode, and we're done..
 */
static int myramfs_mknod(struct inode *dir, struct dentry *dentry, int
mode, int dev)
{
	struct inode * inode = myramfs_get_inode(dir->i_sb, mode, dev);
	int error = -ENOSPC;

	if (inode) {
		d_instantiate(dentry, inode);
		dget(dentry);		/* Extra count - pin the dentry in core */
		error = 0;
	}
	return error;
}

static int myramfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
{
	return myramfs_mknod(dir, dentry, mode | S_IFDIR, 0);
}

static int myramfs_create(struct inode *dir, struct dentry *dentry, int mode)
{
	if (strcmp(dentry->d_name.name, "foo") == 0) {
		/*
		 * Insert some code here to create a file "bar"
		 * (in the same directory of "foo")
		 */
	}

	return myramfs_mknod(dir, dentry, mode | S_IFREG, 0);
}


Somebody willing to help me? :)



-- 
Lorenzo
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux