4 #define DEBUG_SUBSYSTEM S_SNAP
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/string.h>
9 #include <linux/slab.h>
10 #include <linux/stat.h>
11 #include <linux/unistd.h>
13 #include "smfs_internal.h"
15 static void d_unalloc(struct dentry *dentry)
18 list_del(&dentry->d_hash);
19 INIT_LIST_HEAD(&dentry->d_hash);
23 static struct inode *sm_create_inode(struct super_block *sb,
24 struct inode *cache_inode)
28 inode = new_inode(sb);
30 /*FIXME there are still some
31 * other attributes need to
33 inode->i_ino = cache_inode->i_ino;
34 inode->i_mode = cache_inode->i_mode;
40 static void prepare_parent_dentry(struct dentry *dentry, struct inode *inode)
42 atomic_set(&dentry->d_count, 1);
43 dentry->d_vfs_flags = 0;
45 dentry->d_inode = inode;
47 dentry->d_fsdata = NULL;
48 dentry->d_mounted = 0;
49 INIT_LIST_HEAD(&dentry->d_hash);
50 INIT_LIST_HEAD(&dentry->d_lru);
51 INIT_LIST_HEAD(&dentry->d_subdirs);
52 INIT_LIST_HEAD(&dentry->d_alias);
55 static int smfs_create(struct inode *dir,
56 struct dentry *dentry,
59 struct inode *cache_dir;
60 struct inode *cache_inode, *inode;
62 struct dentry *cache_dentry;
67 cache_dir = I2CI(dir);
71 prepare_parent_dentry(&tmp, cache_dir);
72 cache_dentry = d_alloc(&tmp, &dentry->d_name);
77 if(cache_dir && cache_dir->i_op->create)
78 rc = cache_dir->i_op->create(cache_dir, cache_dentry, mode);
82 cache_inode = cache_dentry->d_inode;
83 inode = sm_create_inode(dir->i_sb, cache_inode);
88 sm_set_inode_ops(cache_inode, inode);
90 d_unalloc(cache_dentry);
93 static struct dentry *smfs_lookup(struct inode *dir,
94 struct dentry *dentry)
96 struct inode *cache_dir;
97 struct inode *cache_inode, *inode;
99 struct dentry *cache_dentry;
100 struct dentry *rc = NULL;
104 cache_dir = I2CI(dir);
106 RETURN(ERR_PTR(-ENOENT));
107 prepare_parent_dentry(&tmp, cache_dir);
108 cache_dentry = d_alloc(&tmp, &dentry->d_name);
111 RETURN(ERR_PTR(-ENOENT));
113 if(cache_dir && cache_dir->i_op->lookup)
114 rc = cache_dir->i_op->lookup(cache_dir, cache_dentry);
116 if (rc || !cache_dentry->d_inode ||
117 is_bad_inode(cache_dentry->d_inode) ||
118 IS_ERR(cache_dentry->d_inode)) {
122 cache_inode = cache_dentry->d_inode;
124 inode = iget(dir->i_sb, cache_inode->i_ino);
126 d_add(dentry, inode);
128 d_unalloc(cache_dentry);
131 struct inode_operations smfs_dir_iops = {
135 struct file_operations smfs_dir_fops = {