vxfs_super.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /*
  2. * Copyright (c) 2000-2001 Christoph Hellwig.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions, and the following disclaimer,
  10. * without modification.
  11. * 2. The name of the author may not be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * Alternatively, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL").
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  21. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. /*
  30. * Veritas filesystem driver - superblock related routines.
  31. */
  32. #include <linux/init.h>
  33. #include <linux/module.h>
  34. #include <linux/blkdev.h>
  35. #include <linux/fs.h>
  36. #include <linux/buffer_head.h>
  37. #include <linux/kernel.h>
  38. #include <linux/slab.h>
  39. #include <linux/smp_lock.h>
  40. #include <linux/stat.h>
  41. #include <linux/vfs.h>
  42. #include <linux/mount.h>
  43. #include "vxfs.h"
  44. #include "vxfs_extern.h"
  45. #include "vxfs_dir.h"
  46. #include "vxfs_inode.h"
  47. MODULE_AUTHOR("Christoph Hellwig");
  48. MODULE_DESCRIPTION("Veritas Filesystem (VxFS) driver");
  49. MODULE_LICENSE("Dual BSD/GPL");
  50. MODULE_ALIAS("vxfs"); /* makes mount -t vxfs autoload the module */
  51. static void vxfs_put_super(struct super_block *);
  52. static int vxfs_statfs(struct dentry *, struct kstatfs *);
  53. static int vxfs_remount(struct super_block *, int *, char *);
  54. static const struct super_operations vxfs_super_ops = {
  55. .clear_inode = vxfs_clear_inode,
  56. .put_super = vxfs_put_super,
  57. .statfs = vxfs_statfs,
  58. .remount_fs = vxfs_remount,
  59. };
  60. /**
  61. * vxfs_put_super - free superblock resources
  62. * @sbp: VFS superblock.
  63. *
  64. * Description:
  65. * vxfs_put_super frees all resources allocated for @sbp
  66. * after the last instance of the filesystem is unmounted.
  67. */
  68. static void
  69. vxfs_put_super(struct super_block *sbp)
  70. {
  71. struct vxfs_sb_info *infp = VXFS_SBI(sbp);
  72. lock_kernel();
  73. vxfs_put_fake_inode(infp->vsi_fship);
  74. vxfs_put_fake_inode(infp->vsi_ilist);
  75. vxfs_put_fake_inode(infp->vsi_stilist);
  76. brelse(infp->vsi_bp);
  77. kfree(infp);
  78. unlock_kernel();
  79. }
  80. /**
  81. * vxfs_statfs - get filesystem information
  82. * @dentry: VFS dentry to locate superblock
  83. * @bufp: output buffer
  84. *
  85. * Description:
  86. * vxfs_statfs fills the statfs buffer @bufp with information
  87. * about the filesystem described by @dentry.
  88. *
  89. * Returns:
  90. * Zero.
  91. *
  92. * Locking:
  93. * No locks held.
  94. *
  95. * Notes:
  96. * This is everything but complete...
  97. */
  98. static int
  99. vxfs_statfs(struct dentry *dentry, struct kstatfs *bufp)
  100. {
  101. struct vxfs_sb_info *infp = VXFS_SBI(dentry->d_sb);
  102. bufp->f_type = VXFS_SUPER_MAGIC;
  103. bufp->f_bsize = dentry->d_sb->s_blocksize;
  104. bufp->f_blocks = infp->vsi_raw->vs_dsize;
  105. bufp->f_bfree = infp->vsi_raw->vs_free;
  106. bufp->f_bavail = 0;
  107. bufp->f_files = 0;
  108. bufp->f_ffree = infp->vsi_raw->vs_ifree;
  109. bufp->f_namelen = VXFS_NAMELEN;
  110. return 0;
  111. }
  112. static int vxfs_remount(struct super_block *sb, int *flags, char *data)
  113. {
  114. *flags |= MS_RDONLY;
  115. return 0;
  116. }
  117. /**
  118. * vxfs_read_super - read superblock into memory and initalize filesystem
  119. * @sbp: VFS superblock (to fill)
  120. * @dp: fs private mount data
  121. * @silent: do not complain loudly when sth is wrong
  122. *
  123. * Description:
  124. * We are called on the first mount of a filesystem to read the
  125. * superblock into memory and do some basic setup.
  126. *
  127. * Returns:
  128. * The superblock on success, else %NULL.
  129. *
  130. * Locking:
  131. * We are under the bkl and @sbp->s_lock.
  132. */
  133. static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
  134. {
  135. struct vxfs_sb_info *infp;
  136. struct vxfs_sb *rsbp;
  137. struct buffer_head *bp = NULL;
  138. u_long bsize;
  139. struct inode *root;
  140. int ret = -EINVAL;
  141. sbp->s_flags |= MS_RDONLY;
  142. infp = kzalloc(sizeof(*infp), GFP_KERNEL);
  143. if (!infp) {
  144. printk(KERN_WARNING "vxfs: unable to allocate incore superblock\n");
  145. return -ENOMEM;
  146. }
  147. bsize = sb_min_blocksize(sbp, BLOCK_SIZE);
  148. if (!bsize) {
  149. printk(KERN_WARNING "vxfs: unable to set blocksize\n");
  150. goto out;
  151. }
  152. bp = sb_bread(sbp, 1);
  153. if (!bp || !buffer_mapped(bp)) {
  154. if (!silent) {
  155. printk(KERN_WARNING
  156. "vxfs: unable to read disk superblock\n");
  157. }
  158. goto out;
  159. }
  160. rsbp = (struct vxfs_sb *)bp->b_data;
  161. if (rsbp->vs_magic != VXFS_SUPER_MAGIC) {
  162. if (!silent)
  163. printk(KERN_NOTICE "vxfs: WRONG superblock magic\n");
  164. goto out;
  165. }
  166. if ((rsbp->vs_version < 2 || rsbp->vs_version > 4) && !silent) {
  167. printk(KERN_NOTICE "vxfs: unsupported VxFS version (%d)\n",
  168. rsbp->vs_version);
  169. goto out;
  170. }
  171. #ifdef DIAGNOSTIC
  172. printk(KERN_DEBUG "vxfs: supported VxFS version (%d)\n", rsbp->vs_version);
  173. printk(KERN_DEBUG "vxfs: blocksize: %d\n", rsbp->vs_bsize);
  174. #endif
  175. sbp->s_magic = rsbp->vs_magic;
  176. sbp->s_fs_info = infp;
  177. infp->vsi_raw = rsbp;
  178. infp->vsi_bp = bp;
  179. infp->vsi_oltext = rsbp->vs_oltext[0];
  180. infp->vsi_oltsize = rsbp->vs_oltsize;
  181. if (!sb_set_blocksize(sbp, rsbp->vs_bsize)) {
  182. printk(KERN_WARNING "vxfs: unable to set final block size\n");
  183. goto out;
  184. }
  185. if (vxfs_read_olt(sbp, bsize)) {
  186. printk(KERN_WARNING "vxfs: unable to read olt\n");
  187. goto out;
  188. }
  189. if (vxfs_read_fshead(sbp)) {
  190. printk(KERN_WARNING "vxfs: unable to read fshead\n");
  191. goto out;
  192. }
  193. sbp->s_op = &vxfs_super_ops;
  194. root = vxfs_iget(sbp, VXFS_ROOT_INO);
  195. if (IS_ERR(root)) {
  196. ret = PTR_ERR(root);
  197. goto out;
  198. }
  199. sbp->s_root = d_alloc_root(root);
  200. if (!sbp->s_root) {
  201. iput(root);
  202. printk(KERN_WARNING "vxfs: unable to get root dentry.\n");
  203. goto out_free_ilist;
  204. }
  205. return 0;
  206. out_free_ilist:
  207. vxfs_put_fake_inode(infp->vsi_fship);
  208. vxfs_put_fake_inode(infp->vsi_ilist);
  209. vxfs_put_fake_inode(infp->vsi_stilist);
  210. out:
  211. brelse(bp);
  212. kfree(infp);
  213. return ret;
  214. }
  215. /*
  216. * The usual module blurb.
  217. */
  218. static int vxfs_get_sb(struct file_system_type *fs_type,
  219. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  220. {
  221. return get_sb_bdev(fs_type, flags, dev_name, data, vxfs_fill_super,
  222. mnt);
  223. }
  224. static struct file_system_type vxfs_fs_type = {
  225. .owner = THIS_MODULE,
  226. .name = "vxfs",
  227. .get_sb = vxfs_get_sb,
  228. .kill_sb = kill_block_super,
  229. .fs_flags = FS_REQUIRES_DEV,
  230. };
  231. static int __init
  232. vxfs_init(void)
  233. {
  234. int rv;
  235. vxfs_inode_cachep = kmem_cache_create("vxfs_inode",
  236. sizeof(struct vxfs_inode_info), 0,
  237. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL);
  238. if (!vxfs_inode_cachep)
  239. return -ENOMEM;
  240. rv = register_filesystem(&vxfs_fs_type);
  241. if (rv < 0)
  242. kmem_cache_destroy(vxfs_inode_cachep);
  243. return rv;
  244. }
  245. static void __exit
  246. vxfs_cleanup(void)
  247. {
  248. unregister_filesystem(&vxfs_fs_type);
  249. kmem_cache_destroy(vxfs_inode_cachep);
  250. }
  251. module_init(vxfs_init);
  252. module_exit(vxfs_cleanup);