1N/A/*
1N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#ifndef _GRUB_UFS_H
1N/A#define _GRUB_UFS_H_
1N/A
1N/A#ifdef FSYS_UFS
1N/A
1N/A/* ufs specific constants */
1N/A#define UFS_SBLOCK 16
1N/A#define UFS_SBSIZE 8192
1N/A#define UFS_MAGIC 0x011954
1N/A#define ROOTINO 2 /* i number of all roots */
1N/A#define UFS_NDADDR 12 /* direct blocks */
1N/A#define UFS_NIADDR 3 /* indirect blocks */
1N/A#define MAXMNTLEN 512
1N/A#define MAXCSBUFS 32
1N/A
1N/A/* file types */
1N/A#define IFMT 0xf000
1N/A#define IFREG 0x8000
1N/A#define IFDIR 0x4000
1N/A
1N/Atypedef unsigned char grub_uchar_t;
1N/Atypedef unsigned short grub_ushort_t;
1N/Atypedef unsigned short grub_o_mode_t;
1N/Atypedef unsigned short grub_o_uid_t;
1N/Atypedef unsigned short grub_o_gid_t;
1N/Atypedef long grub_ino_t;
1N/Atypedef long grub_int32_t;
1N/Atypedef long grub_uid_t;
1N/Atypedef long grub_gid_t;
1N/Atypedef unsigned long grub_uint32_t;
1N/Atypedef unsigned long grub_daddr32_t;
1N/Atypedef unsigned long grub_time32_t;
1N/Atypedef struct { int val[2]; } grub_quad_t;
1N/A
1N/Astruct timeval32 {
1N/A grub_time32_t tv_sec;
1N/A grub_int32_t tv_usec;
1N/A};
1N/A
1N/A/*
1N/A * Per cylinder group information; summarized in blocks allocated
1N/A * from first cylinder group data blocks. These blocks have to be
1N/A * read in from fs_csaddr (size fs_cssize) in addition to the
1N/A * super block.
1N/A *
1N/A * N.B. sizeof (struct csum) must be a power of two in order for
1N/A * the ``fs_cs'' macro to work (see below).
1N/A */
1N/Astruct csum {
1N/A grub_int32_t cs_ndir; /* number of directories */
1N/A grub_int32_t cs_nbfree; /* number of free blocks */
1N/A grub_int32_t cs_nifree; /* number of free inodes */
1N/A grub_int32_t cs_nffree; /* number of free frags */
1N/A};
1N/A
1N/A/* Ufs super block */
1N/Astruct fs {
1N/A grub_uint32_t fs_link; /* linked list of file systems */
1N/A grub_uint32_t fs_rolled; /* logging only: fs fully rolled */
1N/A grub_daddr32_t fs_sblkno; /* addr of super-block in filesys */
1N/A grub_daddr32_t fs_cblkno; /* offset of cyl-block in filesys */
1N/A grub_daddr32_t fs_iblkno; /* offset of inode-blocks in filesys */
1N/A grub_daddr32_t fs_dblkno; /* offset of first data after cg */
1N/A grub_int32_t fs_cgoffset; /* cylinder group offset in cylinder */
1N/A grub_int32_t fs_cgmask; /* used to calc mod fs_ntrak */
1N/A grub_time32_t fs_time; /* last time written */
1N/A grub_int32_t fs_size; /* number of blocks in fs */
1N/A grub_int32_t fs_dsize; /* number of data blocks in fs */
1N/A grub_int32_t fs_ncg; /* number of cylinder groups */
1N/A grub_int32_t fs_bsize; /* size of basic blocks in fs */
1N/A grub_int32_t fs_fsize; /* size of frag blocks in fs */
1N/A grub_int32_t fs_frag; /* number of frags in a block in fs */
1N/A /* these are configuration parameters */
1N/A grub_int32_t fs_minfree; /* minimum percentage of free blocks */
1N/A grub_int32_t fs_rotdelay; /* num of ms for optimal next block */
1N/A grub_int32_t fs_rps; /* disk revolutions per second */
1N/A /* these fields can be computed from the others */
1N/A grub_int32_t fs_bmask; /* ``blkoff'' calc of blk offsets */
1N/A grub_int32_t fs_fmask; /* ``fragoff'' calc of frag offsets */
1N/A grub_int32_t fs_bshift; /* ``lblkno'' calc of logical blkno */
1N/A grub_int32_t fs_fshift; /* ``numfrags'' calc number of frags */
1N/A /* these are configuration parameters */
1N/A grub_int32_t fs_maxcontig; /* max number of contiguous blks */
1N/A grub_int32_t fs_maxbpg; /* max number of blks per cyl group */
1N/A /* these fields can be computed from the others */
1N/A grub_int32_t fs_fragshift; /* block to frag shift */
1N/A grub_int32_t fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
1N/A grub_int32_t fs_sbsize; /* actual size of super block */
1N/A grub_int32_t fs_csmask; /* csum block offset */
1N/A grub_int32_t fs_csshift; /* csum block number */
1N/A grub_int32_t fs_nindir; /* value of NINDIR */
1N/A grub_int32_t fs_inopb; /* value of INOPB */
1N/A grub_int32_t fs_nspf; /* value of NSPF */
1N/A /* yet another configuration parameter */
1N/A grub_int32_t fs_optim; /* optimization preference, see below */
1N/A /* these fields are derived from the hardware */
1N/A /* USL SVR4 compatibility */
1N/A /*
1N/A * * USL SVR4 compatibility
1N/A *
1N/A * There was a significant divergence here between Solaris and
1N/A * SVR4 for x86. By swapping these two members in the superblock,
1N/A * we get read-only compatibility of SVR4 filesystems. Otherwise
1N/A * there would be no compatibility. This change was introduced
1N/A * during bootstrapping of Solaris on x86. By making this ifdef'ed
1N/A * on byte order, we provide ongoing compatibility across all
1N/A * platforms with the same byte order, the highest compatibility
1N/A * that can be achieved.
1N/A */
1N/A grub_int32_t fs_state; /* file system state time stamp */
1N/A grub_int32_t fs_si; /* summary info state - lufs only */
1N/A grub_int32_t fs_trackskew; /* sector 0 skew, per track */
1N/A /* unique id for this filesystem (currently unused and unmaintained) */
1N/A /* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
1N/A /* Neither of those fields is used in the Tahoe code right now but */
1N/A /* there could be problems if they are. */
1N/A grub_int32_t fs_id[2]; /* file system id */
1N/A /* sizes determined by number of cylinder groups and their sizes */
1N/A grub_daddr32_t fs_csaddr; /* blk addr of cyl grp summary area */
1N/A grub_int32_t fs_cssize; /* size of cyl grp summary area */
1N/A grub_int32_t fs_cgsize; /* cylinder group size */
1N/A /* these fields are derived from the hardware */
1N/A grub_int32_t fs_ntrak; /* tracks per cylinder */
1N/A grub_int32_t fs_nsect; /* sectors per track */
1N/A grub_int32_t fs_spc; /* sectors per cylinder */
1N/A /* this comes from the disk driver partitioning */
1N/A grub_int32_t fs_ncyl; /* cylinders in file system */
1N/A /* these fields can be computed from the others */
1N/A grub_int32_t fs_cpg; /* cylinders per group */
1N/A grub_int32_t fs_ipg; /* inodes per group */
1N/A grub_int32_t fs_fpg; /* blocks per group * fs_frag */
1N/A /* this data must be re-computed after crashes */
1N/A struct csum fs_cstotal; /* cylinder summary information */
1N/A /* these fields are cleared at mount time */
1N/A char fs_fmod; /* super block modified flag */
1N/A char fs_clean; /* file system state flag */
1N/A char fs_ronly; /* mounted read-only flag */
1N/A char fs_flags; /* largefiles flag, etc. */
1N/A char fs_fsmnt[MAXMNTLEN]; /* name mounted on */
1N/A /* these fields retain the current block allocation info */
1N/A grub_int32_t fs_cgrotor; /* last cg searched */
1N/A /*
1N/A * The following used to be fs_csp[MAXCSBUFS]. It was not
1N/A * used anywhere except in old utilities. We removed this
1N/A * in 5.6 and expect fs_u.fs_csp to be used instead.
1N/A * We no longer limit fs_cssize based on MAXCSBUFS.
1N/A */
1N/A union { /* fs_cs (csum) info */
1N/A grub_uint32_t fs_csp_pad[MAXCSBUFS];
1N/A struct csum *fs_csp;
1N/A } fs_u;
1N/A grub_int32_t fs_cpc; /* cyl per cycle in postbl */
1N/A short fs_opostbl[16][8]; /* old rotation block list head */
1N/A grub_int32_t fs_sparecon[51]; /* reserved for future constants */
1N/A grub_int32_t fs_version; /* minor version of MTB ufs */
1N/A grub_int32_t fs_logbno; /* block # of embedded log */
1N/A grub_int32_t fs_reclaim; /* reclaim open, deleted files */
1N/A grub_int32_t fs_sparecon2; /* reserved for future constant */
1N/A /* USL SVR4 compatibility */
1N/A grub_int32_t fs_npsect; /* # sectors/track including spares */
1N/A grub_quad_t fs_qbmask; /* ~fs_bmask - for use with quad size */
1N/A grub_quad_t fs_qfmask; /* ~fs_fmask - for use with quad size */
1N/A grub_int32_t fs_postblformat; /* fmt of positional layout tables */
1N/A grub_int32_t fs_nrpos; /* number of rotaional positions */
1N/A grub_int32_t fs_postbloff; /* (short) rotation block list head */
1N/A grub_int32_t fs_rotbloff; /* (grub_uchar_t) blocks for each */
1N/A /* rotation */
1N/A grub_int32_t fs_magic; /* magic number */
1N/A grub_uchar_t fs_space[1]; /* list of blocks for each rotation */
1N/A /* actually longer */
1N/A};
1N/A
1N/Astruct icommon {
1N/A grub_o_mode_t ic_smode; /* 0: mode and type of file */
1N/A short ic_nlink; /* 2: number of links to file */
1N/A grub_o_uid_t ic_suid; /* 4: owner's user id */
1N/A grub_o_gid_t ic_sgid; /* 6: owner's group id */
1N/A grub_uint32_t ic_sizelo; /* 8: number of bytes in file */
1N/A grub_uint32_t ic_sizehi; /* 12: number of bytes in file */
1N/A struct timeval32 ic_atime; /* 16: time last accessed */
1N/A struct timeval32 ic_mtime; /* 24: time last modified */
1N/A struct timeval32 ic_ctime; /* 32: last time inode changed */
1N/A grub_daddr32_t ic_db[UFS_NDADDR]; /* 40: disk block addresses */
1N/A grub_daddr32_t ic_ib[UFS_NIADDR]; /* 88: indirect blocks */
1N/A grub_int32_t ic_flags; /* 100: cflags */
1N/A grub_int32_t ic_blocks; /* 104: 512 byte blocks actually held */
1N/A grub_int32_t ic_gen; /* 108: generation number */
1N/A grub_int32_t ic_shadow; /* 112: shadow inode */
1N/A grub_uid_t ic_uid; /* 116: long EFT version of uid */
1N/A grub_gid_t ic_gid; /* 120: long EFT version of gid */
1N/A grub_uint32_t ic_oeftflag; /* 124: extended attr directory ino, */
1N/A /* 0 = none */
1N/A};
1N/A
1N/Astruct direct {
1N/A grub_ino_t d_ino;
1N/A grub_ushort_t d_reclen;
1N/A grub_ushort_t d_namelen;
1N/A char d_name[MAXNAMELEN + 1];
1N/A};
1N/A
1N/A/* inode macros */
1N/A#define INOPB(fs) ((fs)->fs_inopb)
1N/A#define itoo(fs, x) ((x) % (grub_uint32_t)INOPB(fs))
1N/A#define itog(fs, x) ((x) / (grub_uint32_t)(fs)->fs_ipg)
1N/A#define itod(fs, x) ((grub_daddr32_t)(cgimin(fs, itog(fs, x)) + \
1N/A (blkstofrags((fs), \
1N/A ((x) % (grub_uint32_t)(fs)->fs_ipg / (grub_uint32_t)INOPB(fs))))))
1N/A
1N/A/* block conversion macros */
1N/A#define UFS_NINDIR(fs) ((fs)->fs_nindir) /* # of indirects */
1N/A#define blkoff(fs, loc) ((int)((loc & ~(fs)->fs_bmask)))
1N/A#define lblkno(fs, loc) ((grub_int32_t)((loc) >> (fs)->fs_bshift))
1N/A/* frag to blk */
1N/A#define fsbtodb(fs, b) (((grub_daddr32_t)(b)) << (fs)->fs_fsbtodb)
1N/A#define blkstofrags(fs, b) ((b) << (fs)->fs_fragshift)
1N/A
1N/A/* cynlinder group macros */
1N/A#define cgbase(fs, c) ((grub_daddr32_t)((fs)->fs_fpg * (c)))
1N/A#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode block */
1N/A#define cgstart(fs, c) \
1N/A (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
1N/A
1N/A#endif /* FSYS_UFS */
1N/A
1N/A#endif /* !_GRUB_UFS_H */