2 * OBDFS Super operations
4 * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
5 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
6 * Copryright (C) 1999 Seagate Technology Inc.
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/stat.h>
18 #include <linux/errno.h>
19 #include <linux/locks.h>
20 #include <linux/unistd.h>
22 #include <asm/system.h>
23 #include <asm/uaccess.h>
26 #include <linux/stat.h>
27 #include <asm/uaccess.h>
28 #include <linux/vmalloc.h>
29 #include <asm/segment.h>
31 #include <linux/obd_support.h>
32 #include <linux/obd_class.h>
33 #include <linux/obdfs.h>
35 /* VFS super_block ops */
36 static struct super_block *obdfs_read_super(struct super_block *, void *, int);
37 static int obdfs_notify_change(struct dentry *dentry, struct iattr *attr);
38 static void obdfs_write_inode(struct inode *);
39 static void obdfs_delete_inode(struct inode *);
40 static void obdfs_put_super(struct super_block *);
41 static int obdfs_statfs(struct super_block *sb, struct statfs *buf,
44 /* exported operations */
45 struct super_operations obdfs_super_operations =
47 obdfs_read_inode, /* read_inode */
48 obdfs_write_inode, /* write_inode */
50 obdfs_delete_inode, /* delete_inode */
51 obdfs_notify_change, /* notify_change */
52 obdfs_put_super, /* put_super */
53 NULL, /* write_super */
54 obdfs_statfs, /* statfs */
58 static char *obdfs_read_opt(const char *opt, char *data)
63 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
64 if ( strncmp(opt, data, strlen(opt)) )
67 if ( (value = strchr(data, '=')) == NULL )
71 OBD_ALLOC(retval, char *, strlen(value) + 1);
73 printk("OBDFS: Out of memory!\n");
77 memcpy(retval, value, strlen(value)+1);
78 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
82 void obdfs_options(char *options, char **dev, char **vers)
89 for (this_char = strtok (options, ",");
91 this_char = strtok (NULL, ",")) {
92 CDEBUG(D_SUPER, "this_char %s\n", this_char);
93 if ( (!*dev && (*dev = obdfs_read_opt("device", this_char)))||
94 (!*vers && (*vers = obdfs_read_opt("version", this_char))) )
100 static int obdfs_getdev(char *devpath, int *dev)
102 struct dentry *dentry;
105 dentry = lookup_dentry(devpath, NULL, 0);
107 return PTR_ERR(dentry);
109 if (!S_ISCHR(dentry->d_inode->i_mode))
112 devno = dentry->d_inode->i_rdev;
113 if ( MAJOR(devno) != OBD_PSDEV_MAJOR )
116 if ( MINOR(devno) >= MAX_OBD_DEVICES )
123 static struct super_block * obdfs_read_super(struct super_block *sb,
124 void *data, int silent)
126 struct inode *root = 0;
127 struct obdfs_sb_info *sbi = (struct obdfs_sb_info *)(&sb->u.generic_sbp);
128 struct obd_device *obddev;
131 char *version = NULL;
134 unsigned long blocksize;
135 unsigned long blocksize_bits;
136 unsigned long root_ino;
143 memset(sbi, 0, sizeof(*sbi));
145 obdfs_options(data, &device, &version);
147 printk("No device\n");
153 if ( (err = obdfs_getdev(device, &devno)) ) {
154 printk("Cannot get devno of %s, error %d\n", device, err);
160 if ( MAJOR(devno) != OBD_PSDEV_MAJOR ) {
161 printk("Wrong major number!\n");
167 if ( MINOR(devno) >= MAX_OBD_DEVICES ) {
168 printk("Minor of %s too high (%d)\n", device, MINOR(devno));
174 obddev = &obd_dev[MINOR(devno)];
176 if ( ! (obddev->obd_flags & OBD_ATTACHED) ||
177 ! (obddev->obd_flags & OBD_SET_UP) ){
178 printk("Device %s not attached or not set up (%d)\n",
179 device, MINOR(devno));
185 sbi->osi_obd = obddev;
186 sbi->osi_ops = sbi->osi_obd->obd_type->typ_ops;
188 sbi->osi_conn.oc_dev = obddev;
189 error = sbi->osi_ops->o_connect(&sbi->osi_conn);
191 printk("OBDFS: cannot connect to %s\n", device);
199 error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
202 &scratch, (void *)&blocksize);
204 printk("Getinfo call to drive failed (blocksize)\n");
208 error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
209 strlen("blocksize_bits"),
211 &scratch, (void *)&blocksize_bits);
213 printk("Getinfo call to drive failed (blocksize_bits)\n");
217 error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
220 &scratch, (void *)&root_ino);
222 printk("Getinfo call to drive failed (root_ino)\n");
230 sb->s_blocksize = blocksize;
231 sb->s_blocksize_bits = (unsigned char)blocksize_bits;
232 sb->s_magic = OBDFS_SUPER_MAGIC;
233 sb->s_op = &obdfs_super_operations;
235 /* make root inode */
236 root = iget(sb, root_ino);
237 if (!root || is_bad_inode(root)) {
238 printk("OBDFS: bad iget for root\n");
246 printk("obdfs_read_super: sbdev %d, rootino: %ld, dev %s, "
247 "minor: %d, blocksize: %ld, blocksize bits %ld\n",
248 sb->s_dev, root->i_ino, device, MINOR(devno),
249 blocksize, blocksize_bits);
250 sb->s_root = d_alloc_root(root);
259 sbi->osi_super = NULL;
268 static void obdfs_put_super(struct super_block *sb)
270 struct obdfs_sb_info *sbi;
277 /* XXX flush stuff */
278 sbi = (struct obdfs_sb_info *) &sb->u.generic_sbp;
280 OPS(sb,disconnect)(ID(sb));
282 memset(sbi, 0, sizeof(* sbi));
284 printk("OBDFS: Bye bye.\n");
290 /* all filling in of inodes postponed until lookup */
291 void obdfs_read_inode(struct inode *inode)
296 error = IOPS(inode, getattr)(IID(inode), inode);
298 printk("obdfs_read_inode: obd_getattr fails (%d)\n", error);
301 CDEBUG(D_INODE, "ino %ld, mode: %o\n", inode->i_ino, inode->i_mode);
303 if (S_ISREG(inode->i_mode))
304 inode->i_op = &obdfs_file_inode_operations;
305 else if (S_ISDIR(inode->i_mode))
306 inode->i_op = &obdfs_dir_inode_operations;
307 else if (S_ISLNK(inode->i_mode))
308 inode->i_op = &obdfs_symlink_inode_operations;
310 /* XXX what do we pass here??? */
311 init_special_inode(inode, inode->i_mode, 0 /* XXX XXX */ );
315 static void obdfs_write_inode(struct inode *inode)
319 error = IOPS(inode, setattr)(IID(inode), inode);
321 printk("obdfs_write_inode: obd_setattr fails (%d)\n", error);
328 static void obdfs_delete_inode(struct inode *inode)
333 error = IOPS(inode, destroy)(IID(inode), inode);
335 printk("obdfs_delete_node: ibd_destroy fails (%d)\n", error);
342 static int obdfs_notify_change(struct dentry *de, struct iattr *iattr)
344 struct inode *inode = de->d_inode;
345 struct iattr saved_copy;
349 inode_to_iattr(inode, &saved_copy);
351 inode_setattr(inode, iattr);
352 error = IOPS(inode, setattr)(IID(inode), inode);
354 inode_setattr(inode, &saved_copy);
355 printk("obdfs_notify_change: obd_setattr fails (%d)\n", error);
359 CDEBUG(D_INODE, "inode blocks now %ld\n", inode->i_blocks);
365 static int obdfs_statfs(struct super_block *sb, struct statfs *buf,
373 error = OPS(sb,statfs)(ID(sb), &tmp);
375 printk("obdfs_notify_change: obd_statfs fails (%d)\n", error);
378 copy_to_user(buf, &tmp, (bufsize<sizeof(tmp)) ? bufsize : sizeof(tmp));
385 struct file_system_type obdfs_fs_type = {
386 "obdfs", 0, obdfs_read_super, NULL
391 printk(KERN_INFO "OBDFS v0.1, braam@stelias.com\n");
395 return register_filesystem(&obdfs_fs_type);
400 int init_module(void)
405 void cleanup_module(void)
409 obdfs_sysctl_clean();
410 unregister_filesystem(&obdfs_fs_type);