super.c (3263B)
1 /* $Id: //depot/blt/srv/vfs/drivers/ffs/super.c#4 $ 2 ** 3 ** Copyright 1999 Sidney Cammeresi 4 ** All rights reserved. 5 ** 6 ** Redistribution and use in source and binary forms, with or without 7 ** modification, are permitted provided that the following conditions 8 ** are met: 9 ** 1. Redistributions of source code must retain the above copyright 10 ** notice, this list of conditions, and the following disclaimer. 11 ** 2. Redistributions in binary form must reproduce the above copyright 12 ** notice, this list of conditions, and the following disclaimer in the 13 ** documentation and/or other materials provided with the distribution. 14 ** 3. The name of the author may not be used to endorse or promote products 15 ** derived from this software without specific prior written permission. 16 ** 17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <string.h> 32 #include "vfs-int.h" 33 34 #ifndef VFS_SANDBOX 35 #include <blt/blkdev.h> 36 #else 37 #include "../../sandbox/blkdev.h" 38 #endif 39 40 #include "ffs.h" 41 #include "ffs-blt.h" 42 #include "dinode.h" 43 44 static struct vnode_ops ffs_vnode_ops = 45 { 46 ffs_read_vnode, ffs_drop_vnode, NULL, NULL, ffs_walk, NULL, 47 ffs_mount, ffs_unmount, NULL, NULL, NULL, NULL, 48 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 49 ffs_opendir, ffs_closedir, ffs_free_dircookie, ffs_rewinddir, ffs_readdir, 50 ffs_open, ffs_close, ffs_free_cookie, ffs_read, NULL, NULL, NULL, 51 ffs_rstat, NULL, NULL, 52 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 53 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 54 NULL, NULL, NULL, NULL 55 }; 56 57 static struct fs_type ffs = { "ffs", &ffs_vnode_ops, NULL }; 58 59 int _init (void) 60 { 61 #ifdef FFS_DEBUG 62 printf ("ffs: registering driver\n"); 63 #endif 64 fs_register (&ffs); 65 return 0; 66 } 67 68 int ffs_mount (struct superblock *super, const char *data, int silent) 69 { 70 struct ffs_super_data *sbdata; 71 struct ffs_super *ds; 72 73 #ifdef FFS_DEBUG 74 printf ("ffs_mount, data `%s'\n", data); 75 #endif 76 sbdata = malloc (sizeof (struct ffs_super_data)); 77 blk_open (data, 0, &sbdata->dev); 78 super->sb_data = sbdata; 79 sbdata->sbbuf = ds = malloc (SBSIZE); 80 blk_read (sbdata->dev, ds, SBOFF / sbdata->dev->blksize, 81 SBSIZE / sbdata->dev->blksize); 82 super->sb_root = vget (super, ROOTINO); 83 super->sb_dev = malloc (strlen (data) + 1); 84 strcpy (super->sb_dev, data); 85 return 0; 86 } 87 88 void ffs_unmount (struct superblock *super) 89 { 90 struct ffs_super_data *sbdata; 91 92 #ifdef FFS_DEBUG 93 printf ("ffs_unmount\n"); 94 #endif 95 vput (super->sb_root); 96 sbdata = super->sb_data; 97 blk_close (sbdata->dev); 98 free (sbdata->sbbuf); 99 free (sbdata); 100 } 101