Home | History | Annotate | Line # | Download | only in boot_ufs
readufs_ffs.c revision 1.1.6.3
      1  1.1.6.3  jdolecek /*	from Id: readufs_ffs.c,v 1.5 2002/01/26 16:26:44 itohy 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 
     55  1.1.6.2   thorpej 	/* Get information from the superblock. */
     56  1.1.6.2   thorpej 	fsi.bsize = buf.sblk.fs_bsize;
     57  1.1.6.2   thorpej 	fsi.fsbtodb = buf.sblk.fs_fsbtodb;
     58  1.1.6.2   thorpej 	fsi.nindir = buf.sblk.fs_nindir;
     59  1.1.6.2   thorpej 
     60  1.1.6.2   thorpej 	fsi_ffs.iblkno = buf.sblk.fs_iblkno;
     61  1.1.6.2   thorpej 	fsi_ffs.cgoffset = buf.sblk.fs_cgoffset;
     62  1.1.6.2   thorpej 	fsi_ffs.cgmask = buf.sblk.fs_cgmask;
     63  1.1.6.2   thorpej 	fsi_ffs.fragshift = buf.sblk.fs_fragshift;
     64  1.1.6.2   thorpej 	fsi_ffs.inopb = buf.sblk.fs_inopb;
     65  1.1.6.2   thorpej 	fsi_ffs.ipg = buf.sblk.fs_ipg;
     66  1.1.6.2   thorpej 	fsi_ffs.fpg = buf.sblk.fs_fpg;
     67  1.1.6.2   thorpej 
     68  1.1.6.2   thorpej 	return 0;
     69  1.1.6.2   thorpej }
     70  1.1.6.2   thorpej 
     71  1.1.6.2   thorpej /* for inode macros */
     72  1.1.6.2   thorpej #define fs_ipg		fs_u.u_ffs.ipg
     73  1.1.6.2   thorpej #define fs_iblkno	fs_u.u_ffs.iblkno
     74  1.1.6.2   thorpej #define fs_cgoffset	fs_u.u_ffs.cgoffset
     75  1.1.6.2   thorpej #define fs_cgmask	fs_u.u_ffs.cgmask
     76  1.1.6.2   thorpej #define fs_fpg		fs_u.u_ffs.fpg
     77  1.1.6.2   thorpej #define fs_inopb	fs_u.u_ffs.inopb
     78  1.1.6.2   thorpej #define fs_fragshift	fs_u.u_ffs.fragshift
     79  1.1.6.2   thorpej #define fs_fsbtodb	fsbtodb
     80  1.1.6.2   thorpej 
     81  1.1.6.2   thorpej /*
     82  1.1.6.2   thorpej  * Get inode from disk.
     83  1.1.6.2   thorpej  */
     84  1.1.6.2   thorpej static int
     85  1.1.6.2   thorpej get_ffs_inode(ino, dibuf)
     86  1.1.6.2   thorpej 	ino_t ino;
     87  1.1.6.2   thorpej 	struct dinode *dibuf;
     88  1.1.6.2   thorpej {
     89  1.1.6.2   thorpej 	struct ufs_info *ufsinfo = &ufs_info;
     90  1.1.6.2   thorpej 	struct dinode *buf = alloca((size_t) fsi.bsize);
     91  1.1.6.2   thorpej 	struct dinode *di;
     92  1.1.6.2   thorpej 
     93  1.1.6.3  jdolecek 	RAW_READ(buf, fsbtodb(&fsi, ino_to_fsba(&fsi, ino)),
     94  1.1.6.2   thorpej 			(size_t) fsi.bsize);
     95  1.1.6.2   thorpej 
     96  1.1.6.2   thorpej 	di = &buf[ino_to_fsbo(&fsi, ino)];
     97  1.1.6.2   thorpej #ifdef DEBUG_WITH_STDIO
     98  1.1.6.2   thorpej 	printf("FFS: dinode(%d): mode 0%o, nlink %d, size %d, uid %d, gid %d, db[0] %d\n",
     99  1.1.6.2   thorpej 		ino, di->di_mode, di->di_nlink, (int)di->di_size,
    100  1.1.6.2   thorpej 		di->di_uid, di->di_gid, di->di_db[0]);
    101  1.1.6.2   thorpej #endif
    102  1.1.6.2   thorpej 
    103  1.1.6.2   thorpej 	if (di->di_mode == 0)
    104  1.1.6.2   thorpej 		return 1;	/* unused inode (file is not found) */
    105  1.1.6.2   thorpej 
    106  1.1.6.2   thorpej 	*dibuf = *di;
    107  1.1.6.2   thorpej 
    108  1.1.6.2   thorpej 	return 0;
    109  1.1.6.2   thorpej }
    110  1.1.6.2   thorpej 
    111