00001
00002
00003
00004
00005
00006
00007 #include "local.h"
00008
00009 #include <linux/fs.h>
00010 #include <linux/module.h>
00011 #include <linux/mount.h>
00012
00013
00014
00015
00016 LIST_HEAD(super_blocks);
00017
00018
00019
00020
00021
00022 struct inode* new_inode(struct super_block *sb)
00023 {
00024 if (sb->s_op->alloc_inode)
00025 return sb->s_op->alloc_inode(sb);
00026
00027 return kzalloc(sizeof(struct inode), GFP_KERNEL);
00028 }
00029
00030 void __mark_inode_dirty(struct inode *inode, int flags)
00031 {
00032 WARN_UNIMPL;
00033 }
00034
00035 void iput(struct inode *inode)
00036 {
00037 WARN_UNIMPL;
00038 }
00039
00040 void generic_delete_inode(struct inode *inode)
00041 {
00042 WARN_UNIMPL;
00043 }
00044
00045 int invalidate_inodes(struct super_block * sb)
00046 {
00047 WARN_UNIMPL;
00048 return 0;
00049 }
00050
00051 void truncate_inode_pages(struct address_space *mapping, loff_t lstart)
00052 {
00053 WARN_UNIMPL;
00054 }
00055
00056 void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
00057 {
00058 WARN_UNIMPL;
00059 }
00060
00061
00062
00063
00064
00065 struct super_block * get_super(struct block_device *bdev)
00066 {
00067 WARN_UNIMPL;
00068 return NULL;
00069 }
00070
00071 int simple_statfs(struct dentry *dentry, struct kstatfs *buf)
00072 {
00073 WARN_UNIMPL;
00074 return 0;
00075 }
00076
00077 void kill_anon_super(struct super_block *sb)
00078 {
00079 WARN_UNIMPL;
00080 }
00081
00082 void shrink_dcache_sb(struct super_block * sb)
00083 {
00084 WARN_UNIMPL;
00085 }
00086
00087 void drop_super(struct super_block *sb)
00088 {
00089 WARN_UNIMPL;
00090 }
00091
00092 struct inode_operations empty_iops = { };
00093 struct file_operations empty_fops = { };
00094
00095
00096
00097
00098
00099 static struct inode *dde_alloc_inode(struct super_block *sb)
00100 {
00101 struct inode *inode;
00102
00103 if (sb->s_op->alloc_inode)
00104 inode = sb->s_op->alloc_inode(sb);
00105 else
00106 inode = kzalloc(sizeof(*inode), GFP_KERNEL);
00107
00108 if (inode) {
00109 inode->i_sb = sb;
00110 inode->i_blkbits = sb->s_blocksize_bits;
00111 inode->i_flags = 0;
00112 atomic_set(&inode->i_count, 1);
00113 inode->i_op = &empty_iops;
00114 inode->i_fop = &empty_fops;
00115 inode->i_nlink = 1;
00116 atomic_set(&inode->i_writecount, 0);
00117 inode->i_size = 0;
00118 inode->i_blocks = 0;
00119 inode->i_bytes = 0;
00120 inode->i_generation = 0;
00121 inode->i_pipe = NULL;
00122 inode->i_bdev = NULL;
00123 inode->i_cdev = NULL;
00124 inode->i_rdev = 0;
00125 inode->dirtied_when = 0;
00126 inode->i_private = NULL;
00127 }
00128
00129 return inode;
00130 }
00131
00132
00133 void __iget(struct inode *inode)
00134 {
00135 atomic_inc(&inode->i_count);
00136 }
00137
00138
00139 static struct inode *dde_new_inode(struct super_block *sb, struct list_head *head,
00140 int (*test)(struct inode *, void *),
00141 int (*set)(struct inode *, void *), void *data)
00142 {
00143 struct inode *ret = dde_alloc_inode(sb);
00144 int err = 0;
00145
00146 if (set)
00147 err = set(ret, data);
00148
00149 BUG_ON(err);
00150
00151 __iget(ret);
00152 ret->i_state = I_LOCK|I_NEW;
00153
00154 list_add_tail(&ret->i_sb_list, &sb->s_inodes);
00155
00156 return ret;
00157 }
00158
00159
00160 struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
00161 int (*test)(struct inode *, void *),
00162 int (*set)(struct inode *, void *), void *data)
00163 {
00164 struct inode *inode = NULL;
00165 struct list_head *p;
00166
00167 list_for_each(p, &sb->s_inodes) {
00168 struct inode *i = list_entry(p, struct inode, i_sb_list);
00169 if (test) {
00170 if (!test(i, data)) {
00171 DEBUG_MSG("test false");
00172 continue;
00173 }
00174 else {
00175 inode = i;
00176 break;
00177 }
00178 }
00179 }
00180
00181 if (inode)
00182 return inode;
00183
00184 return dde_new_inode(sb, &sb->s_inodes, test, set, data);
00185 }
00186
00187 void unlock_new_inode(struct inode *inode)
00188 {
00189 inode->i_state &= ~(I_LOCK | I_NEW);
00190 wake_up_bit(&inode->i_state, __I_LOCK);
00191 }
00192
00193 struct super_block *sget(struct file_system_type *type,
00194 int (*test)(struct super_block *, void*),
00195 int (*set)(struct super_block *, void*),
00196 void *data)
00197 {
00198 struct super_block *s = NULL;
00199 struct list_head *p;
00200 int err;
00201
00202 if (test) {
00203 list_for_each(p, &type->fs_supers) {
00204 struct super_block *block = list_entry(p,
00205 struct super_block,
00206 s_instances);
00207 if (!test(block, data))
00208 continue;
00209 return block;
00210 }
00211 }
00212
00213 s = kzalloc(sizeof(*s), GFP_KERNEL);
00214 BUG_ON(!s);
00215
00216 INIT_LIST_HEAD(&s->s_dirty);
00217 INIT_LIST_HEAD(&s->s_io);
00218 INIT_LIST_HEAD(&s->s_files);
00219 INIT_LIST_HEAD(&s->s_instances);
00220 INIT_HLIST_HEAD(&s->s_anon);
00221 INIT_LIST_HEAD(&s->s_inodes);
00222 init_rwsem(&s->s_umount);
00223 mutex_init(&s->s_lock);
00224 lockdep_set_class(&s->s_umount, &type->s_umount_key);
00225
00226
00227
00228
00229
00230 lockdep_set_class(&s->s_lock, &type->s_lock_key);
00231 down_write(&s->s_umount);
00232 s->s_count = S_BIAS;
00233 atomic_set(&s->s_active, 1);
00234 mutex_init(&s->s_vfs_rename_mutex);
00235 mutex_init(&s->s_dquot.dqio_mutex);
00236 mutex_init(&s->s_dquot.dqonoff_mutex);
00237 init_rwsem(&s->s_dquot.dqptr_sem);
00238 init_waitqueue_head(&s->s_wait_unfrozen);
00239 s->s_maxbytes = MAX_NON_LFS;
00240 #if 0
00241 s->dq_op = sb_dquot_ops;
00242 s->s_qcop = sb_quotactl_ops;
00243 s->s_op = &default_op;
00244 #endif
00245 s->s_time_gran = 1000000000;
00246
00247 err = set(s, data);
00248 BUG_ON(err);
00249
00250 s->s_type = type;
00251 strlcpy(s->s_id, type->name, sizeof(s->s_id));
00252 list_add_tail(&s->s_list, &super_blocks);
00253 list_add(&s->s_instances, &type->fs_supers);
00254 __module_get(type->owner);
00255 return s;
00256 }
00257
00258 int set_anon_super(struct super_block *s, void *data)
00259 {
00260 WARN_UNIMPL;
00261 return 0;
00262 }
00263
00264 int get_sb_pseudo(struct file_system_type *fs_type, char *name,
00265 const struct super_operations *ops, unsigned long magic,
00266 struct vfsmount *mnt)
00267 {
00268 struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
00269 struct super_operations default_ops = {};
00270 struct inode *root = NULL;
00271 struct dentry *dentry = NULL;
00272 struct qstr d_name = {.name = name, .len = strlen(name)};
00273
00274 BUG_ON(IS_ERR(s));
00275
00276 s->s_flags = MS_NOUSER;
00277 s->s_maxbytes = ~0ULL;
00278 s->s_blocksize = 1024;
00279 s->s_blocksize_bits = 10;
00280 s->s_magic = magic;
00281 s->s_op = ops ? ops : &default_ops;
00282 s->s_time_gran = 1;
00283 root = new_inode(s);
00284
00285 BUG_ON(!root);
00286
00287 root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR;
00288 root->i_uid = root->i_gid = 0;
00289 #if 0
00290 root->i_atime = root->i_mtime = root->i_ctime = CURRENT_TIME;
00291 dentry = d_alloc(NULL, &d_name);
00292 dentry->d_sb = s;
00293 dentry->d_parent = dentry;
00294 d_instantiate(dentry, root);
00295 #endif
00296 s->s_root = dentry;
00297 s->s_flags |= MS_ACTIVE;
00298
00299 mnt->mnt_sb = s;
00300 mnt->mnt_root = dget(s->s_root);
00301
00302 DEBUG_MSG("root mnt sb @ %p", mnt->mnt_sb);
00303
00304 return 0;
00305 }
00306
00307 void inode_init_once(struct inode *inode)
00308 {
00309 WARN_UNIMPL;
00310 }
00311