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/stat.h>
  40. #include <linux/vfs.h>
  41. #include <linux/mount.h>
  42. #include "vxfs.h"
  43. #include "vxfs_extern.h"
  44. #include "vxfs_dir.h"
  45. #include "vxfs_inode.h"
  46. MODULE_AUTHOR("Christoph Hellwig");
  47. MODULE_DESCRIPTION("Veritas Filesystem (VxFS) driver");
  48. MODULE_LICENSE("Dual BSD/GPL");
  49. static void vxfs_put_super(struct super_block *);
  50. static int vxfs_statfs(struct dentry *, struct kstatfs *);
  51. static int vxfs_remount(struct super_block *, int *, char *);
  52. static const struct super_operations vxfs_super_ops = {
  53. .evict_inode = vxfs_evict_inode,
  54. .put_super = vxfs_put_super,
  55. .statfs = vxfs_statfs,
  56. .remount_fs = vxfs_remount,
  57. };
  58. /**
  59. * vxfs_put_super - free superblock resources
  60. * @sbp: VFS superblock.
  61. *
  62. * Description:
  63. * vxfs_put_super frees all resources allocated for @sbp
  64. * after the last instance of the filesystem is unmounted.
  65. */
  66. static void
  67. vxfs_put_super(struct super_block *sbp)
  68. {
  69. struct vxfs_sb_info *infp = VXFS_SBI(sbp);
  70. vxfs_put_fake_inode(infp->vsi_fship);
  71. vxfs_put_fake_inode(infp->vsi_ilist);
  72. vxfs_put_fake_inode(infp->vsi_stilist);
  73. brelse(infp->vsi_bp);
  74. kfree(infp);
  75. }
  76. /**
  77. * vxfs_statfs - get filesystem information
  78. * @dentry: VFS dentry to locate superblock
  79. * @bufp: output buffer
  80. *
  81. * Description:
  82. * vxfs_statfs fills the statfs buffer @bufp with information
  83. * about the filesystem described by @dentry.
  84. *
  85. * Returns:
  86. * Zero.
  87. *
  88. * Locking:
  89. * No locks held.
  90. *
  91. * Notes:
  92. * This is everything but complete...
  93. */
  94. static int
  95. vxfs_statfs(struct dentry *dentry, struct kstatfs *bufp)
  96. {
  97. struct vxfs_sb_info *infp = VXFS_SBI(dentry->d_sb);
  98. bufp->f_type = VXFS_SUPER_MAGIC;
  99. bufp->f_bsize = dentry->d_sb->s_blocksize;
  100. bufp->f_blocks = infp->vsi_raw->vs_dsize;
  101. bufp->f_bfree = infp->vsi_raw->vs_free;
  102. bufp->f_bavail = 0;
  103. bufp->f_files = 0;
  104. bufp->f_ffree = infp->vsi_raw->vs_ifree;
  105. bufp->f_namelen = VXFS_NAMELEN;
  106. return 0;
  107. }
  108. static int vxfs_remount(struct super_block *sb, int *flags, char *data)
  109. {
  110. sync_filesystem(sb);
  111. *flags |= MS_RDONLY;
  112. return 0;
  113. }
  114. /**
  115. * vxfs_read_super - read superblock into memory and initialize filesystem
  116. * @sbp: VFS superblock (to fill)
  117. * @dp: fs private mount data
  118. * @silent: do not complain loudly when sth is wrong
  119. *
  120. * Description:
  121. * We are called on the first mount of a filesystem to read the
  122. * superblock into memory and do some basic setup.
  123. *
  124. * Returns:
  125. * The superblock on success, else %NULL.
  126. *
  127. * Locking:
  128. * We are under @sbp->s_lock.
  129. */
  130. static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)
  131. {
  132. struct vxfs_sb_info *infp;
  133. struct vxfs_sb *rsbp;
  134. struct buffer_head *bp = NULL;
  135. u_long bsize;
  136. struct inode *root;
  137. int ret = -EINVAL;
  138. sbp->s_flags |= MS_RDONLY;
  139. infp = kzalloc(sizeof(*infp), GFP_KERNEL);
  140. if (!infp) {
  141. printk(KERN_WARNING "vxfs: unable to allocate incore superblock\n");
  142. return -ENOMEM;
  143. }
  144. bsize = sb_min_blocksize(sbp, BLOCK_SIZE);
  145. if (!bsize) {
  146. printk(KERN_WARNING "vxfs: unable to set blocksize\n");
  147. goto out;
  148. }
  149. bp = sb_bread(sbp, 1);
  150. if (!bp || !buffer_mapped(bp)) {
  151. if (!silent) {
  152. printk(KERN_WARNING
  153. "vxfs: unable to read disk superblock\n");
  154. }
  155. goto out;
  156. }
  157. rsbp = (struct vxfs_sb *)bp->b_data;
  158. if (rsbp->vs_magic != VXFS_SUPER_MAGIC) {
  159. if (!silent)
  160. printk(KERN_NOTICE "vxfs: WRONG superblock magic\n");
  161. goto out;
  162. }
  163. if ((rsbp->vs_version < 2 || rsbp->vs_version > 4) && !silent) {
  164. printk(KERN_NOTICE "vxfs: unsupported VxFS version (%d)\n",
  165. rsbp->vs_version);
  166. goto out;
  167. }
  168. #ifdef DIAGNOSTIC
  169. printk(KERN_DEBUG "vxfs: supported VxFS version (%d)\n", rsbp->vs_version);
  170. printk(KERN_DEBUG "vxfs: blocksize: %d\n", rsbp->vs_bsize);
  171. #endif
  172. sbp->s_magic = rsbp->vs_magic;
  173. sbp->s_fs_info = infp;
  174. infp->vsi_raw = rsbp;
  175. infp->vsi_bp = bp;
  176. infp->vsi_oltext = rsbp->vs_oltext[0];
  177. infp->vsi_oltsize = rsbp->vs_oltsize;
  178. if (!sb_set_blocksize(sbp, rsbp->vs_bsize)) {
  179. printk(KERN_WARNING "vxfs: unable to set final block size\n");
  180. goto out;
  181. }
  182. if (vxfs_read_olt(sbp, bsize)) {
  183. printk(KERN_WARNING "vxfs: unable to read olt\n");
  184. goto out;
  185. }
  186. if (vxfs_read_fshead(sbp)) {
  187. printk(KERN_WARNING "vxfs: unable to read fshead\n");
  188. goto out;
  189. }
  190. sbp->s_op = &vxfs_super_ops;
  191. root = vxfs_iget(sbp, VXFS_ROOT_INO);
  192. if (IS_ERR(root)) {
  193. ret = PTR_ERR(root);
  194. goto out;
  195. }
  196. sbp->s_root = d_make_root(root);
  197. if (!sbp->s_root) {
  198. printk(KERN_WARNING "vxfs: unable to get root dentry.\n");
  199. goto out_free_ilist;
  200. }
  201. return 0;
  202. out_free_ilist:
  203. vxfs_put_fake_inode(infp->vsi_fship);
  204. vxfs_put_fake_inode(infp->vsi_ilist);
  205. vxfs_put_fake_inode(infp->vsi_stilist);
  206. out:
  207. brelse(bp);
  208. kfree(infp);
  209. return ret;
  210. }
  211. /*
  212. * The usual module blurb.
  213. */
  214. static struct dentry *vxfs_mount(struct file_system_type *fs_type,
  215. int flags, const char *dev_name, void *data)
  216. {
  217. return mount_bdev(fs_type, flags, dev_name, data, vxfs_fill_super);
  218. }
  219. static struct file_system_type vxfs_fs_type = {
  220. .owner = THIS_MODULE,
  221. .name = "vxfs",
  222. .mount = vxfs_mount,
  223. .kill_sb = kill_block_super,
  224. .fs_flags = FS_REQUIRES_DEV,
  225. };
  226. MODULE_ALIAS_FS("vxfs"); /* makes mount -t vxfs autoload the module */
  227. MODULE_ALIAS("vxfs");
  228. static int __init
  229. vxfs_init(void)
  230. {
  231. int rv;
  232. vxfs_inode_cachep = kmem_cache_create("vxfs_inode",
  233. sizeof(struct vxfs_inode_info), 0,
  234. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL);
  235. if (!vxfs_inode_cachep)
  236. return -ENOMEM;
  237. rv = register_filesystem(&vxfs_fs_type);
  238. if (rv < 0)
  239. kmem_cache_destroy(vxfs_inode_cachep);
  240. return rv;
  241. }
  242. static void __exit
  243. vxfs_cleanup(void)
  244. {
  245. unregister_filesystem(&vxfs_fs_type);
  246. /*
  247. * Make sure all delayed rcu free inodes are flushed before we
  248. * destroy cache.
  249. */
  250. rcu_barrier();
  251. kmem_cache_destroy(vxfs_inode_cachep);
  252. }
  253. module_init(vxfs_init);
  254. module_exit(vxfs_cleanup);