示例#1
0
文件: file.c 项目: mnv104/capfs
/* capfs_open()
 *
 * Called from fs/open.c:filep_open()
 *
 * NOTES:
 * Truncation and creation are handled by fs/namei.c:open_namei()
 * We need to take care of O_APPEND here.
 *
 * The inode for the file is not necessarily up to date.  This is
 * important in the O_APPEND case because we need to have the most
 * recent size, so we're going to force a revalidate_inode() in the case
 * of an append.
 */
int capfs_open(struct inode *inode, struct file *file)
{
	int error = 0;
	/* update the statistics */
	if(capfs_collect_stats) capfs_vfs_stat.open++;
	PENTRY;
	
	lock_kernel();
	inode->i_mapping->host = inode;
	inode->i_mapping->a_ops = &capfs_file_aops;
	inode->i_mapping->backing_dev_info = &capfs_backing_dev_info;

	if (S_ISDIR(inode->i_mode))
	{
		error = dcache_dir_open(inode, file);
		unlock_kernel();
		return error;
	}
	/* we need to calculate file size if a) the user wants append mode or
	 * b) if O_LARGEFILE is not used (so that we can throw an error if
	 * the file is to large)
	 */
	if ((file->f_flags & O_APPEND) || !(file->f_flags & O_LARGEFILE))
	{
		/* force a revalidate */
		PDEBUG(D_FILE, "capfs_open: getting most up to date size\n");

		if ((error = capfs_inode_getattr(file->f_dentry)) < 0) {
			unlock_kernel();
			PEXIT;
			return error;
		}
	}

	/* make sure the file isn't too large */
	if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
	{
		unlock_kernel();
		PEXIT;
		return -EFBIG;
	}

	if (file->f_flags & O_APPEND)
	{
		/* set the file position to point to one byte past the last byte
		 * in the file
		 */
		file->f_pos = i_size_read(inode);
	}
	error = generic_file_open(inode, file);
	unlock_kernel();
	PEXIT;
	return error;
}
示例#2
0
int sjfs_dir_fops_open(struct inode *dir, struct file *file) {
	printk("sjfs_dir_fops_open -> dcache_dir_open(\n");

        if(dir) {
                printk("--- dir.ino:%lu\n", dir->i_ino);
        } else {
                printk("--- dir.ino:NULL\n");
        }
        if(file && &(file->f_path) != NULL && file->f_path.dentry != NULL && &(file->f_path.dentry->d_name) != NULL && file->f_path.dentry->d_name.name != NULL) {
                printk("--- file.path: \"%s\");\n", file->f_path.dentry->d_name.name);
        } else {
                printk("--- file.path: NULL);\n");
        }

	return dcache_dir_open(dir, file);
}