root/fs/ufs/ufs_super.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. init_ufs_fs
  2. init_module
  3. cleanup_module
  4. ufs_print_super_stuff
  5. ufs_read_super
  6. ufs_put_super
  7. ufs_statfs

   1 /*
   2  *  linux/fs/ufs/ufs_super.c
   3  *
   4  * Copyright (C) 1996
   5  * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
   6  * Laboratory for Computer Science Research Computing Facility
   7  * Rutgers, The State University of New Jersey
   8  *
   9  * $Id: ufs_super.c,v 1.3 1996/04/25 09:12:09 davem Exp $
  10  *
  11  */
  12 
  13 /*
  14  * Kernel module support added on 96/04/26 by
  15  * Stefan Reinauer <stepan@home.culture.mipt.ru>
  16  *
  17  * Module usage counts added on 96/04/29 by
  18  * Gertjan van Wingerde <gertjan@cs.vu.nl>
  19  */
  20 
  21 #include <linux/module.h>
  22 
  23 #include <linux/kernel.h>
  24 #include <linux/fs.h>
  25 #include <linux/ufs_fs.h>
  26 #include <linux/module.h>
  27 #include <linux/locks.h>
  28 
  29 #include <asm/segment.h>
  30 
  31 struct super_block * ufs_read_super(struct super_block * sb, void * data, int silent);
  32 void ufs_put_super (struct super_block * sb);
  33 void ufs_statfs(struct super_block * sb, struct statfs * buf, int bufsize);
  34 
  35 extern void ufs_read_inode(struct inode * inode);
  36 extern void ufs_put_inode(struct inode * inode);
  37 
  38 static struct super_operations ufs_super_ops = {
  39         ufs_read_inode,
  40         NULL,                   /* notify_change() */
  41         NULL,                   /* XXX - ufs_write_inode() */
  42         ufs_put_inode,
  43         ufs_put_super,
  44         NULL,                   /* XXX - ufs_write_super() */
  45         ufs_statfs,
  46         NULL,                   /* XXX - ufs_remount() */
  47 };
  48 
  49 static struct file_system_type ufs_fs_type = {
  50         ufs_read_super, "ufs", 1, NULL
  51 };
  52 
  53 int
  54 init_ufs_fs(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         return(register_filesystem(&ufs_fs_type));
  57 }
  58 
  59 #ifdef MODULE
  60 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  61 {
  62         int status;
  63 
  64         if ((status = init_ufs_fs()) == 0)
  65                 register_symtab(0);
  66         return status;
  67 }
  68 
  69 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71         unregister_filesystem(&ufs_fs_type);
  72 }
  73 #endif
  74 
  75 #if 0 /* unused */
  76 static void
  77 ufs_print_super_stuff(struct super_block * sb, struct ufs_superblock * usb)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 {
  79 
  80         printk("fs_sblkno: 0x%8.8x\n", usb->fs_sblkno);
  81         printk("fs_size: 0x%8.8x\n", usb->fs_size);
  82         printk("fs_ncg: 0x%8.8x\n", usb->fs_ncg);
  83         printk("fs_bsize: 0x%8.8x\n", usb->fs_bsize);
  84         printk("fs_frag: 0x%8.8x\n", usb->fs_frag);
  85         printk("fs_nindir: 0x%8.8x\n", usb->fs_nindir);
  86         printk("fs_inopb: 0x%8.8x\n", usb->fs_inopb);
  87         printk("fs_optim: 0x%8.8x\n", usb->fs_optim);
  88         printk("fs_ncyl: 0x%8.8x\n", usb->fs_ncyl);
  89         printk("fs_state: 0x%8.8x\n", usb->fs_state);
  90         printk("fs_magic: 0x%8.8x\n", usb->fs_magic);
  91         printk("fs_fsmnt: `%s'\n", usb->fs_fsmnt);
  92 
  93         return;
  94 }
  95 #endif
  96 
  97 struct super_block *
  98 ufs_read_super(struct super_block * sb, void * data, int silent)
     /* [previous][next][first][last][top][bottom][index][help] */
  99 {
 100         struct ufs_superblock * usb;
 101         struct buffer_head * bh1, *bh2;
 102 
 103         /* sb->s_dev and sb->s_flags are set by our caller
 104          * data is the mystery argument to sys_mount()
 105          *
 106          * Our caller also sets s_dev, s_covered, s_rd_only, s_dirt,
 107          *   and s_type when we return.
 108          */
 109 
 110         MOD_INC_USE_COUNT;
 111         lock_super (sb);
 112 
 113         /* XXX - make everything read only for testing */
 114         sb->s_flags |= MS_RDONLY;
 115 
 116         if (!(bh1 = bread(sb->s_dev, UFS_SBLOCK/BLOCK_SIZE, BLOCK_SIZE)) ||
 117             !(bh2 = bread(sb->s_dev, (UFS_SBLOCK + BLOCK_SIZE)/BLOCK_SIZE,
 118                           BLOCK_SIZE))) {
 119                 sb->s_dev = 0;
 120                 unlock_super (sb);
 121                 if (bh1) {
 122                         brelse(bh1);
 123                 }
 124                 printk ("ufs_read_super: unable to read superblock\n");
 125 
 126                 MOD_DEC_USE_COUNT;
 127                 return(NULL);
 128         }
 129         /* XXX - redo this so we can free it later... */
 130         usb = (struct ufs_superblock *)__get_free_page(GFP_KERNEL); 
 131         if (usb == NULL) {
 132                 printk ("ufs_read_super: get_free_page() failed\n");
 133         }
 134 
 135         memcpy((char *)usb, bh1->b_data, BLOCK_SIZE);
 136         memcpy((char *)usb + BLOCK_SIZE, bh2->b_data,
 137                sizeof(struct ufs_superblock) - BLOCK_SIZE);
 138 
 139         brelse(bh1);
 140         brelse(bh2);
 141 
 142         if (usb->fs_magic != UFS_MAGIC) {
 143                 /* XXX - replace hard-coded constant with a byte-swap macro */
 144                 if (usb->fs_magic == 0x54190100) {
 145                         printk ("ufs_read_super: can't grok byteswapped fs on dev %d/%d\n",
 146                                 MAJOR(sb->s_dev), MINOR(sb->s_dev));
 147                         silent = 1;
 148                 }
 149                 sb->s_dev = 0;
 150                 unlock_super (sb);
 151                 if (!silent)
 152                         printk ("ufs_read_super: bad magic number 0x%8.8x on dev %d/%d\n",
 153                                 usb->fs_magic, MAJOR(sb->s_dev),
 154                                 MINOR(sb->s_dev));
 155                 MOD_DEC_USE_COUNT;
 156                 return(NULL);
 157         }
 158 
 159         /* We found a UFS filesystem on this device. */
 160 
 161         /* XXX - parse args */
 162 
 163         if (usb->fs_bsize != UFS_BSIZE) {
 164                 printk("ufs_read_super: fs_bsize %d != %d\n", usb->fs_bsize,
 165                        UFS_BSIZE);
 166                 goto ufs_read_super_lose;
 167         }
 168 
 169         if (usb->fs_fsize != UFS_FSIZE) {
 170                 printk("ufs_read_super: fs_fsize %d != %d\n", usb->fs_fsize,
 171                        UFS_FSIZE);
 172                 goto ufs_read_super_lose;
 173         }
 174 
 175         if (usb->fs_nindir != UFS_NINDIR) {
 176                 printk("ufs_read_super: fs_nindir %d != %d\n", usb->fs_nindir,
 177                        UFS_NINDIR);
 178                 printk("ufs_read_super: fucking Sun blows me\n");
 179         }
 180 
 181         printk("ufs_read_super: fs last mounted on \"%s\"\n", usb->fs_fsmnt);
 182 
 183         if (usb->fs_state == UFS_FSOK - usb->fs_time) {
 184                 switch(usb->fs_clean) {
 185                         case UFS_FSCLEAN:
 186                           printk("ufs_read_super: fs is clean\n");
 187                           break;
 188                         case UFS_FSSTABLE:
 189                           printk("ufs_read_super: fs is stable\n");
 190                           break;
 191                         case UFS_FSACTIVE:
 192                           printk("ufs_read_super: fs is active\n");
 193                           sb->s_flags |= MS_RDONLY;
 194                           break;
 195                         case UFS_FSBAD:
 196                           printk("ufs_read_super: fs is bad\n");
 197                           sb->s_flags |= MS_RDONLY;
 198                           break;
 199                         default:
 200                           printk("ufs_read_super: can't grok fs_clean 0x%x\n",
 201                                  usb->fs_clean);
 202                           sb->s_flags |= MS_RDONLY;
 203                           break;
 204                 }
 205         } else {
 206                 printk("ufs_read_super: fs needs fsck\n");
 207                 sb->s_flags |= MS_RDONLY;
 208                 /* XXX - make it read only or barf if it's not (/, /usr) */
 209         }
 210 
 211         /* XXX - sanity check sb fields */
 212 
 213         sb->s_blocksize = usb->fs_fsize;
 214         sb->s_blocksize_bits = 10;  /* XXX */
 215         /* XXX - sb->s_lock */
 216         sb->s_op = &ufs_super_ops;
 217         sb->dq_op = 0; /* XXX */
 218         sb->s_magic = usb->fs_magic;
 219         /* sb->s_time */
 220         /* sb->s_wait */
 221         /* XXX - sb->u.ufs_sb */
 222         sb->u.ufs_sb.s_raw_sb = usb; /* XXX - maybe move this to the top */
 223         sb->u.ufs_sb.s_flags = 0;
 224         sb->u.ufs_sb.s_ncg = usb->fs_ncg;
 225         sb->u.ufs_sb.s_ipg = usb->fs_ipg;
 226         sb->u.ufs_sb.s_fpg = usb->fs_fpg;
 227         sb->u.ufs_sb.s_fsize = usb->fs_fsize;
 228         sb->u.ufs_sb.s_bsize = usb->fs_bsize;
 229         sb->u.ufs_sb.s_iblkno = usb->fs_iblkno;
 230         sb->u.ufs_sb.s_dblkno = usb->fs_dblkno;
 231         sb->u.ufs_sb.s_cgoffset = usb->fs_cgoffset;
 232         sb->u.ufs_sb.s_cgmask = usb->fs_cgmask;
 233         sb->u.ufs_sb.s_inopb = usb->fs_inopb;
 234         sb->u.ufs_sb.s_fsfrag = usb->fs_frag; /* XXX - rename this later */
 235         sb->s_mounted = iget(sb, UFS_ROOTINO);
 236 
 237         printk("ufs_read_super: inopb %u\n", sb->u.ufs_sb.s_inopb);
 238         /*
 239          * XXX - read cg structs?
 240          */
 241 
 242         unlock_super(sb);
 243         return(sb);
 244 
 245        ufs_read_super_lose:
 246         /* XXX - clean up */
 247         MOD_DEC_USE_COUNT;
 248         return(NULL);
 249 }
 250 
 251 void ufs_put_super (struct super_block * sb)
     /* [previous][next][first][last][top][bottom][index][help] */
 252 {
 253 
 254         printk("ufs_put_super\n"); /* XXX */
 255 
 256         lock_super (sb);
 257         /* XXX - sync fs data, set state to ok, and flush buffers */
 258         sb->s_dev = 0;
 259 
 260         /* XXX - free allocated kernel memory */
 261 
 262         unlock_super (sb);
 263         MOD_DEC_USE_COUNT;
 264 
 265         return;
 266 }
 267 
 268 void ufs_statfs(struct super_block * sb, struct statfs * buf, int bufsiz)
     /* [previous][next][first][last][top][bottom][index][help] */
 269 {
 270         struct statfs tmp;
 271 
 272         printk("ufs_statfs\n"); /* XXX */
 273         tmp.f_type = sb->s_magic;
 274         tmp.f_bsize = PAGE_SIZE;
 275         tmp.f_blocks = sb->u.ufs_sb.s_raw_sb->fs_dsize;
 276         tmp.f_bfree = sb->u.ufs_sb.s_raw_sb->fs_cstotal.cs_nbfree;
 277         tmp.f_bavail =  sb->u.ufs_sb.s_raw_sb->fs_cstotal.cs_nbfree; /* XXX */
 278         tmp.f_files = sb->u.ufs_sb.s_ncg * sb->u.ufs_sb.s_ipg;
 279         tmp.f_ffree = sb->u.ufs_sb.s_raw_sb->fs_cstotal.cs_nifree;
 280         tmp.f_fsid.val[0] = sb->u.ufs_sb.s_raw_sb->fs_id[0];
 281         tmp.f_fsid.val[1] = sb->u.ufs_sb.s_raw_sb->fs_id[1];
 282         tmp.f_namelen = MAXNAMLEN;
 283 /*        tmp.f_spare[6] */
 284 
 285         memcpy_tofs(buf, &tmp, bufsiz);
 286 
 287         return;
 288 }
 289 
 290 
 291 /*
 292  * Local Variables: ***
 293  * c-indent-level: 8 ***
 294  * c-continued-statement-offset: 8 ***
 295  * c-brace-offset: -8 ***
 296  * c-argdecl-indent: 0 ***
 297  * c-label-offset: -8 ***
 298  * End: ***
 299  */

/* [previous][next][first][last][top][bottom][index][help] */