Home | History | Annotate | Line # | Download | only in boot_ufs
readufs_ffs.c revision 1.1.6.2
      1  1.1.6.2  thorpej /*	$Id: readufs_ffs.c,v 1.1.6.2 2002/01/10 19:50:29 thorpej Exp $	*/
      2  1.1.6.2  thorpej 
      3  1.1.6.2  thorpej /*
      4  1.1.6.2  thorpej  * FS specific support for 4.2BSD Fast Filesystem
      5  1.1.6.2  thorpej  *
      6  1.1.6.2  thorpej  * Written by ITOH, Yasufumi (itohy (at) netbsd.org).
      7  1.1.6.2  thorpej  * Public domain.
      8  1.1.6.2  thorpej  *
      9  1.1.6.2  thorpej  * Intended to be used for boot programs (first stage).
     10  1.1.6.2  thorpej  * DON'T ADD ANY FANCY FEATURE.  THIS SHALL BE COMPACT.
     11  1.1.6.2  thorpej  */
     12  1.1.6.2  thorpej 
     13  1.1.6.2  thorpej #include <sys/types.h>
     14  1.1.6.2  thorpej #include <sys/param.h>
     15  1.1.6.2  thorpej #include <ufs/ufs/dinode.h>
     16  1.1.6.2  thorpej #include <ufs/ffs/fs.h>
     17  1.1.6.2  thorpej 
     18  1.1.6.2  thorpej #include "readufs.h"
     19  1.1.6.2  thorpej 
     20  1.1.6.2  thorpej static int get_ffs_inode __P((ino_t ino, struct dinode *dibuf));
     21  1.1.6.2  thorpej 
     22  1.1.6.2  thorpej #define fsi	(*ufsinfo)
     23  1.1.6.2  thorpej #define fsi_ffs	fsi.fs_u.u_ffs
     24  1.1.6.2  thorpej 
     25  1.1.6.2  thorpej /*
     26  1.1.6.2  thorpej  * Read and check superblock.
     27  1.1.6.2  thorpej  * If it is an FFS, save information from the superblock.
     28  1.1.6.2  thorpej  */
     29  1.1.6.2  thorpej int
     30  1.1.6.2  thorpej try_ffs()
     31  1.1.6.2  thorpej {
     32  1.1.6.2  thorpej 	union {
     33  1.1.6.2  thorpej 		struct fs	sblk;
     34  1.1.6.2  thorpej 		unsigned char	pad[SBSIZE];
     35  1.1.6.2  thorpej 	} buf;
     36  1.1.6.2  thorpej 	struct ufs_info *ufsinfo = &ufs_info;
     37  1.1.6.2  thorpej 
     38  1.1.6.2  thorpej #ifdef DEBUG_WITH_STDIO
     39  1.1.6.2  thorpej 	printf("trying FFS\n");
     40  1.1.6.2  thorpej #endif
     41  1.1.6.2  thorpej 	/* read FFS superblock */
     42  1.1.6.2  thorpej 	RAW_READ(&buf, SBLOCK, SBSIZE);
     43  1.1.6.2  thorpej 
     44  1.1.6.2  thorpej #ifdef DEBUG_WITH_STDIO
     45  1.1.6.2  thorpej 	printf("FFS: sblk: magic: 0x%x\n", buf.sblk.fs_magic);
     46  1.1.6.2  thorpej #endif
     47  1.1.6.2  thorpej 
     48  1.1.6.2  thorpej 	if (buf.sblk.fs_magic != FS_MAGIC)
     49  1.1.6.2  thorpej 		return 1;
     50  1.1.6.2  thorpej 
     51  1.1.6.2  thorpej 	/* This partition looks like an FFS. */
     52  1.1.6.2  thorpej 	fsi.fstype = UFSTYPE_FFS;
     53  1.1.6.2  thorpej 	fsi.get_inode = get_ffs_inode;
     54  1.1.6.2  thorpej 	/* Disk addr in inode is in block --- need shifting. */
     55  1.1.6.2  thorpej 	fsi.iblkshift = buf.sblk.fs_fsbtodb;
     56  1.1.6.2  thorpej 
     57  1.1.6.2  thorpej 	/* Get information from the superblock. */
     58  1.1.6.2  thorpej 	fsi.bsize = buf.sblk.fs_bsize;
     59  1.1.6.2  thorpej 	fsi.fsbtodb = buf.sblk.fs_fsbtodb;
     60  1.1.6.2  thorpej 	fsi.nindir = buf.sblk.fs_nindir;
     61  1.1.6.2  thorpej 
     62  1.1.6.2  thorpej 	fsi_ffs.iblkno = buf.sblk.fs_iblkno;
     63  1.1.6.2  thorpej 	fsi_ffs.cgoffset = buf.sblk.fs_cgoffset;
     64  1.1.6.2  thorpej 	fsi_ffs.cgmask = buf.sblk.fs_cgmask;
     65  1.1.6.2  thorpej 	fsi_ffs.fragshift = buf.sblk.fs_fragshift;
     66  1.1.6.2  thorpej 	fsi_ffs.inopb = buf.sblk.fs_inopb;
     67  1.1.6.2  thorpej 	fsi_ffs.ipg = buf.sblk.fs_ipg;
     68  1.1.6.2  thorpej 	fsi_ffs.fpg = buf.sblk.fs_fpg;
     69  1.1.6.2  thorpej 
     70  1.1.6.2  thorpej 	return 0;
     71  1.1.6.2  thorpej }
     72  1.1.6.2  thorpej 
     73  1.1.6.2  thorpej /* for inode macros */
     74  1.1.6.2  thorpej #define fs_ipg		fs_u.u_ffs.ipg
     75  1.1.6.2  thorpej #define fs_iblkno	fs_u.u_ffs.iblkno
     76  1.1.6.2  thorpej #define fs_cgoffset	fs_u.u_ffs.cgoffset
     77  1.1.6.2  thorpej #define fs_cgmask	fs_u.u_ffs.cgmask
     78  1.1.6.2  thorpej #define fs_fpg		fs_u.u_ffs.fpg
     79  1.1.6.2  thorpej #define fs_inopb	fs_u.u_ffs.inopb
     80  1.1.6.2  thorpej #define fs_fragshift	fs_u.u_ffs.fragshift
     81  1.1.6.2  thorpej #define fs_fsbtodb	fsbtodb
     82  1.1.6.2  thorpej 
     83  1.1.6.2  thorpej /*
     84  1.1.6.2  thorpej  * Get inode from disk.
     85  1.1.6.2  thorpej  */
     86  1.1.6.2  thorpej static int
     87  1.1.6.2  thorpej get_ffs_inode(ino, dibuf)
     88  1.1.6.2  thorpej 	ino_t ino;
     89  1.1.6.2  thorpej 	struct dinode *dibuf;
     90  1.1.6.2  thorpej {
     91  1.1.6.2  thorpej 	struct ufs_info *ufsinfo = &ufs_info;
     92  1.1.6.2  thorpej 	struct dinode *buf = alloca((size_t) fsi.bsize);
     93  1.1.6.2  thorpej 	struct dinode *di;
     94  1.1.6.2  thorpej 
     95  1.1.6.2  thorpej 	RAW_READ(buf, (unsigned int) fsbtodb(&fsi, ino_to_fsba(&fsi, ino)),
     96  1.1.6.2  thorpej 			(size_t) fsi.bsize);
     97  1.1.6.2  thorpej 
     98  1.1.6.2  thorpej 	di = &buf[ino_to_fsbo(&fsi, ino)];
     99  1.1.6.2  thorpej #ifdef DEBUG_WITH_STDIO
    100  1.1.6.2  thorpej 	printf("FFS: dinode(%d): mode 0%o, nlink %d, size %d, uid %d, gid %d, db[0] %d\n",
    101  1.1.6.2  thorpej 		ino, di->di_mode, di->di_nlink, (int)di->di_size,
    102  1.1.6.2  thorpej 		di->di_uid, di->di_gid, di->di_db[0]);
    103  1.1.6.2  thorpej #endif
    104  1.1.6.2  thorpej 
    105  1.1.6.2  thorpej 	if (di->di_mode == 0)
    106  1.1.6.2  thorpej 		return 1;	/* unused inode (file is not found) */
    107  1.1.6.2  thorpej 
    108  1.1.6.2  thorpej 	*dibuf = *di;
    109  1.1.6.2  thorpej 
    110  1.1.6.2  thorpej 	return 0;
    111  1.1.6.2  thorpej }
    112  1.1.6.2  thorpej 
    113