linux/fs/ufs/ufs_fs.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 *  linux/include/linux/ufs_fs.h
 *
 * Copyright (C) 1996
 * Adrian Rodriguez ([email protected])
 * Laboratory for Computer Science Research Computing Facility
 * Rutgers, The State University of New Jersey
 *
 * Clean swab support by Fare <[email protected]>
 * just hope no one is using NNUUXXI on __?64 structure elements
 * 64-bit clean thanks to Maciej W. Rozycki <[email protected]>
 *
 * 4.4BSD (FreeBSD) support added on February 1st 1998 by
 * Niels Kristian Bech Jensen <[email protected]> partially based
 * on code by Martin von Loewis <[email protected]>.
 *
 * NeXTstep support added on February 5th 1998 by
 * Niels Kristian Bech Jensen <[email protected]>.
 *
 * Write support by Daniel Pirkl <[email protected]>
 *
 * HP/UX hfs filesystem support added by
 * Martin K. Petersen <[email protected]>, August 1999
 *
 * UFS2 (of FreeBSD 5.x) support added by
 * Niraj Kumar <[email protected]>  , Jan 2004
 *
 */

#ifndef __LINUX_UFS_FS_H
#define __LINUX_UFS_FS_H

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/stat.h>
#include <linux/fs.h>
#include <linux/workqueue.h>

#include <asm/div64.h>
__fs64;
__fs32;
__fs16;

#define UFS_BBLOCK
#define UFS_BBSIZE
#define UFS_SBLOCK
#define UFS_SBSIZE

#define UFS_SECTOR_SIZE
#define UFS_SECTOR_BITS
#define UFS_MAGIC
#define UFS_MAGIC_BW
#define UFS2_MAGIC
#define UFS_CIGAM

/* Copied from FreeBSD */
/*
 * Each disk drive contains some number of filesystems.
 * A filesystem consists of a number of cylinder groups.
 * Each cylinder group has inodes and data.
 *
 * A filesystem is described by its super-block, which in turn
 * describes the cylinder groups.  The super-block is critical
 * data and is replicated in each cylinder group to protect against
 * catastrophic loss.  This is done at `newfs' time and the critical
 * super-block data does not change, so the copies need not be
 * referenced further unless disaster strikes.
 *
 * For filesystem fs, the offsets of the various blocks of interest
 * are given in the super block as:
 *      [fs->fs_sblkno]         Super-block
 *      [fs->fs_cblkno]         Cylinder group block
 *      [fs->fs_iblkno]         Inode blocks
 *      [fs->fs_dblkno]         Data blocks
 * The beginning of cylinder group cg in fs, is given by
 * the ``cgbase(fs, cg)'' macro.
 *
 * Depending on the architecture and the media, the superblock may
 * reside in any one of four places. For tiny media where every block
 * counts, it is placed at the very front of the partition. Historically,
 * UFS1 placed it 8K from the front to leave room for the disk label and
 * a small bootstrap. For UFS2 it got moved to 64K from the front to leave
 * room for the disk label and a bigger bootstrap, and for really piggy
 * systems we check at 256K from the front if the first three fail. In
 * all cases the size of the superblock will be SBLOCKSIZE. All values are
 * given in byte-offset form, so they do not imply a sector size. The
 * SBLOCKSEARCH specifies the order in which the locations should be searched.
 */
#define SBLOCK_FLOPPY
#define SBLOCK_UFS1
#define SBLOCK_UFS2
#define SBLOCK_PIGGY
#define SBLOCKSIZE
#define SBLOCKSEARCH


/* HP specific MAGIC values */

#define UFS_MAGIC_LFN
#define UFS_CIGAM_LFN

#define UFS_MAGIC_SEC
#define UFS_CIGAM_SEC

#define UFS_MAGIC_FEA
#define UFS_CIGAM_FEA

#define UFS_MAGIC_4GB
#define UFS_CIGAM_4GB

/* Seems somebody at HP goofed here. B1 and lfs are both 0x2 !?! */
#define UFS_FSF_LFN
#define UFS_FSF_B1
#define UFS_FSF_LFS
#define UFS_FSF_LUID

/* End of HP stuff */


#define UFS_BSIZE
#define UFS_MINBSIZE
#define UFS_FSIZE
#define UFS_MAXFRAG

#define UFS_NDADDR
#define UFS_NINDIR

#define UFS_IND_BLOCK
#define UFS_DIND_BLOCK
#define UFS_TIND_BLOCK

#define UFS_NDIR_FRAGMENT
#define UFS_IND_FRAGMENT
#define UFS_DIND_FRAGMENT
#define UFS_TIND_FRAGMENT

#define UFS_ROOTINO
#define UFS_FIRST_INO

#define UFS_USEEFT

/* fs_clean values */
#define UFS_FSOK
#define UFS_FSACTIVE
#define UFS_FSCLEAN
#define UFS_FSSTABLE
#define UFS_FSOSF1
#define UFS_FSBAD

/* Solaris-specific fs_clean values */
#define UFS_FSSUSPEND
#define UFS_FSLOG
#define UFS_FSFIX

/* From here to next blank line, s_flags for ufs_sb_info */
/* directory entry encoding */
#define UFS_DE_MASK
#define UFS_DE_OLD
#define UFS_DE_44BSD
/* uid encoding */
#define UFS_UID_MASK
#define UFS_UID_OLD
#define UFS_UID_44BSD
#define UFS_UID_EFT
/* superblock state encoding */
#define UFS_ST_MASK
#define UFS_ST_OLD
#define UFS_ST_44BSD
#define UFS_ST_SUN
#define UFS_ST_SUNOS
#define UFS_ST_SUNx86
/*cylinder group encoding */
#define UFS_CG_MASK
#define UFS_CG_OLD
#define UFS_CG_44BSD
#define UFS_CG_SUN
/* filesystem type encoding */
#define UFS_TYPE_MASK
#define UFS_TYPE_UFS1
#define UFS_TYPE_UFS2


/* fs_inodefmt options */
#define UFS_42INODEFMT
#define UFS_44INODEFMT

/*
 * MINFREE gives the minimum acceptable percentage of file system
 * blocks which may be free. If the freelist drops below this level
 * only the superuser may continue to allocate blocks. This may
 * be set to 0 if no reserve of free blocks is deemed necessary,
 * however throughput drops by fifty percent if the file system
 * is run at between 95% and 100% full; thus the minimum default
 * value of fs_minfree is 5%. However, to get good clustering
 * performance, 10% is a better choice. hence we use 10% as our
 * default value. With 10% free space, fragmentation is not a
 * problem, so we choose to optimize for time.
 */
#define UFS_MINFREE
#define UFS_DEFAULTOPT

/*
 * Turn file system block numbers into disk block addresses.
 * This maps file system blocks to device size blocks.
 */
#define ufs_fsbtodb(uspi, b)
#define ufs_dbtofsb(uspi, b)

/*
 * Cylinder group macros to locate things in cylinder groups.
 * They calc file system addresses of cylinder group data structures.
 */
#define ufs_cgbase(c)
#define ufs_cgstart(c)
#define ufs_cgsblock(c)
#define ufs_cgcmin(c)
#define ufs_cgimin(c)
#define ufs_cgdmin(c)

/*
 * Macros for handling inode numbers:
 *     inode number to file system block offset.
 *     inode number to cylinder group number.
 *     inode number to file system block address.
 */
#define ufs_inotocg(x)
#define ufs_inotocgoff(x)
#define ufs_inotofsba(x)
#define ufs_inotofsbo(x)

/*
 * Compute the cylinder and rotational position of a cyl block addr.
 */
#define ufs_cbtocylno(bno)
#define ufs_cbtorpos(bno)

/*
 * The following macros optimize certain frequently calculated
 * quantities by using shifts and masks in place of divisions
 * modulos and multiplications.
 */
#define ufs_blkoff(loc)
#define ufs_fragoff(loc)
#define ufs_lblktosize(blk)
#define ufs_lblkno(loc)
#define ufs_numfrags(loc)
#define ufs_blkroundup(size)
#define ufs_fragroundup(size)
#define ufs_fragstoblks(frags)
#define ufs_blkstofrags(blks)
#define ufs_fragnum(fsb)
#define ufs_blknum(fsb)

#define UFS_MAXNAMLEN
#define UFS_MAXMNTLEN
#define UFS2_MAXMNTLEN
#define UFS2_MAXVOLLEN
#define UFS_MAXCSBUFS
#define UFS_LINK_MAX
/*
#define	UFS2_NOCSPTRS	((128 / sizeof(void *)) - 4)
*/
#define UFS2_NOCSPTRS

/*
 * UFS_DIR_PAD defines the directory entries boundaries
 * (must be a multiple of 4)
 */
#define UFS_DIR_PAD
#define UFS_DIR_ROUND
#define UFS_DIR_REC_LEN(name_len)

struct ufs_timeval {};

struct ufs_dir_entry {};

struct ufs_csum {};
struct ufs2_csum_total {};

struct ufs_csum_core {};

/*
 * File system flags
 */
#define UFS_UNCLEAN
#define UFS_DOSOFTDEP
#define UFS_NEEDSFSCK
#define UFS_INDEXDIRS
#define UFS_ACLS
#define UFS_MULTILABEL
#define UFS_FLAGS_UPDATED

#if 0
/*
 * This is the actual superblock, as it is laid out on the disk.
 * Do NOT use this structure, because of sizeof(ufs_super_block) > 512 and
 * it may occupy several blocks, use
 * struct ufs_super_block_(first,second,third) instead.
 */
struct ufs_super_block {
	union {
		struct {
			__fs32	fs_link;	/* UNUSED */
		} fs_42;
		struct {
			__fs32	fs_state;	/* file system state flag */
		} fs_sun;
	} fs_u0;
	__fs32	fs_rlink;	/* UNUSED */
	__fs32	fs_sblkno;	/* addr of super-block in filesys */
	__fs32	fs_cblkno;	/* offset of cyl-block in filesys */
	__fs32	fs_iblkno;	/* offset of inode-blocks in filesys */
	__fs32	fs_dblkno;	/* offset of first data after cg */
	__fs32	fs_cgoffset;	/* cylinder group offset in cylinder */
	__fs32	fs_cgmask;	/* used to calc mod fs_ntrak */
	__fs32	fs_time;	/* last time written -- time_t */
	__fs32	fs_size;	/* number of blocks in fs */
	__fs32	fs_dsize;	/* number of data blocks in fs */
	__fs32	fs_ncg;		/* number of cylinder groups */
	__fs32	fs_bsize;	/* size of basic blocks in fs */
	__fs32	fs_fsize;	/* size of frag blocks in fs */
	__fs32	fs_frag;	/* number of frags in a block in fs */
/* these are configuration parameters */
	__fs32	fs_minfree;	/* minimum percentage of free blocks */
	__fs32	fs_rotdelay;	/* num of ms for optimal next block */
	__fs32	fs_rps;		/* disk revolutions per second */
/* these fields can be computed from the others */
	__fs32	fs_bmask;	/* ``blkoff'' calc of blk offsets */
	__fs32	fs_fmask;	/* ``fragoff'' calc of frag offsets */
	__fs32	fs_bshift;	/* ``lblkno'' calc of logical blkno */
	__fs32	fs_fshift;	/* ``numfrags'' calc number of frags */
/* these are configuration parameters */
	__fs32	fs_maxcontig;	/* max number of contiguous blks */
	__fs32	fs_maxbpg;	/* max number of blks per cyl group */
/* these fields can be computed from the others */
	__fs32	fs_fragshift;	/* block to frag shift */
	__fs32	fs_fsbtodb;	/* fsbtodb and dbtofsb shift constant */
	__fs32	fs_sbsize;	/* actual size of super block */
	__fs32	fs_csmask;	/* csum block offset */
	__fs32	fs_csshift;	/* csum block number */
	__fs32	fs_nindir;	/* value of NINDIR */
	__fs32	fs_inopb;	/* value of INOPB */
	__fs32	fs_nspf;	/* value of NSPF */
/* yet another configuration parameter */
	__fs32	fs_optim;	/* optimization preference, see below */
/* these fields are derived from the hardware */
	union {
		struct {
			__fs32	fs_npsect;	/* # sectors/track including spares */
		} fs_sun;
		struct {
			__fs32	fs_state;	/* file system state time stamp */
		} fs_sunx86;
	} fs_u1;
	__fs32	fs_interleave;	/* hardware sector interleave */
	__fs32	fs_trackskew;	/* sector 0 skew, per track */
/* a unique id for this filesystem (currently unused and unmaintained) */
/* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
/* Neither of those fields is used in the Tahoe code right now but */
/* there could be problems if they are.                            */
	__fs32	fs_id[2];	/* file system id */
/* sizes determined by number of cylinder groups and their sizes */
	__fs32	fs_csaddr;	/* blk addr of cyl grp summary area */
	__fs32	fs_cssize;	/* size of cyl grp summary area */
	__fs32	fs_cgsize;	/* cylinder group size */
/* these fields are derived from the hardware */
	__fs32	fs_ntrak;	/* tracks per cylinder */
	__fs32	fs_nsect;	/* sectors per track */
	__fs32	fs_spc;		/* sectors per cylinder */
/* this comes from the disk driver partitioning */
	__fs32	fs_ncyl;	/* cylinders in file system */
/* these fields can be computed from the others */
	__fs32	fs_cpg;		/* cylinders per group */
	__fs32	fs_ipg;		/* inodes per cylinder group */
	__fs32	fs_fpg;		/* blocks per group * fs_frag */
/* this data must be re-computed after crashes */
	struct ufs_csum fs_cstotal;	/* cylinder summary information */
/* these fields are cleared at mount time */
	__s8	fs_fmod;	/* super block modified flag */
	__s8	fs_clean;	/* file system is clean flag */
	__s8	fs_ronly;	/* mounted read-only flag */
	__s8	fs_flags;
	union {
		struct {
			__s8	fs_fsmnt[UFS_MAXMNTLEN];/* name mounted on */
			__fs32	fs_cgrotor;	/* last cg searched */
			__fs32	fs_csp[UFS_MAXCSBUFS];/*list of fs_cs info buffers */
			__fs32	fs_maxcluster;
			__fs32	fs_cpc;		/* cyl per cycle in postbl */
			__fs16	fs_opostbl[16][8]; /* old rotation block list head */
		} fs_u1;
		struct {
			__s8  fs_fsmnt[UFS2_MAXMNTLEN];	/* name mounted on */
			__u8   fs_volname[UFS2_MAXVOLLEN]; /* volume name */
			__fs64  fs_swuid;		/* system-wide uid */
			__fs32  fs_pad;	/* due to alignment of fs_swuid */
			__fs32   fs_cgrotor;     /* last cg searched */
			__fs32   fs_ocsp[UFS2_NOCSPTRS]; /*list of fs_cs info buffers */
			__fs32   fs_contigdirs;/*# of contiguously allocated dirs */
			__fs32   fs_csp;	/* cg summary info buffer for fs_cs */
			__fs32   fs_maxcluster;
			__fs32   fs_active;/* used by snapshots to track fs */
			__fs32   fs_old_cpc;	/* cyl per cycle in postbl */
			__fs32   fs_maxbsize;/*maximum blocking factor permitted */
			__fs64   fs_sparecon64[17];/*old rotation block list head */
			__fs64   fs_sblockloc; /* byte offset of standard superblock */
			struct  ufs2_csum_total fs_cstotal;/*cylinder summary information*/
			struct  ufs_timeval    fs_time;		/* last time written */
			__fs64    fs_size;		/* number of blocks in fs */
			__fs64    fs_dsize;	/* number of data blocks in fs */
			__fs64   fs_csaddr;	/* blk addr of cyl grp summary area */
			__fs64    fs_pendingblocks;/* blocks in process of being freed */
			__fs32    fs_pendinginodes;/*inodes in process of being freed */
		} fs_u2;
	}  fs_u11;
	union {
		struct {
			__fs32	fs_sparecon[53];/* reserved for future constants */
			__fs32	fs_reclaim;
			__fs32	fs_sparecon2[1];
			__fs32	fs_state;	/* file system state time stamp */
			__fs32	fs_qbmask[2];	/* ~usb_bmask */
			__fs32	fs_qfmask[2];	/* ~usb_fmask */
		} fs_sun;
		struct {
			__fs32	fs_sparecon[53];/* reserved for future constants */
			__fs32	fs_reclaim;
			__fs32	fs_sparecon2[1];
			__fs32	fs_npsect;	/* # sectors/track including spares */
			__fs32	fs_qbmask[2];	/* ~usb_bmask */
			__fs32	fs_qfmask[2];	/* ~usb_fmask */
		} fs_sunx86;
		struct {
			__fs32	fs_sparecon[50];/* reserved for future constants */
			__fs32	fs_contigsumsize;/* size of cluster summary array */
			__fs32	fs_maxsymlinklen;/* max length of an internal symlink */
			__fs32	fs_inodefmt;	/* format of on-disk inodes */
			__fs32	fs_maxfilesize[2];	/* max representable file size */
			__fs32	fs_qbmask[2];	/* ~usb_bmask */
			__fs32	fs_qfmask[2];	/* ~usb_fmask */
			__fs32	fs_state;	/* file system state time stamp */
		} fs_44;
	} fs_u2;
	__fs32	fs_postblformat;	/* format of positional layout tables */
	__fs32	fs_nrpos;		/* number of rotational positions */
	__fs32	fs_postbloff;		/* (__s16) rotation block list head */
	__fs32	fs_rotbloff;		/* (__u8) blocks for each rotation */
	__fs32	fs_magic;		/* magic number */
	__u8	fs_space[1];		/* list of blocks for each rotation */
};
#endif/*struct ufs_super_block*/

/*
 * Preference for optimization.
 */
#define UFS_OPTTIME
#define UFS_OPTSPACE

/*
 * Rotational layout table format types
 */
#define UFS_42POSTBLFMT
#define UFS_DYNAMICPOSTBLFMT

/*
 * Convert cylinder group to base address of its global summary info.
 */
#define fs_cs(indx)

/*
 * Cylinder group block for a file system.
 *
 * Writable fields in the cylinder group are protected by the associated
 * super block lock fs->fs_lock.
 */
#define CG_MAGIC
#define ufs_cg_chkmagic(sb, ucg)
/*
 * Macros for access to old cylinder group array structures
 */
#define ufs_ocg_blktot(sb, ucg)
#define ufs_ocg_blks(sb, ucg, cylno)
#define ufs_ocg_inosused(sb, ucg)
#define ufs_ocg_blksfree(sb, ucg)
#define ufs_ocg_chkmagic(sb, ucg)

/*
 * size of this structure is 172 B
 */
struct	ufs_cylinder_group {};

/* Historic Cylinder group info */
struct ufs_old_cylinder_group {};

/*
 * structure of an on-disk inode
 */
struct ufs_inode {};

#define UFS_NXADDR
struct ufs2_inode {};


/* FreeBSD has these in sys/stat.h */
/* ui_flags that can be set by a file owner */
#define UFS_UF_SETTABLE
#define UFS_UF_NODUMP
#define UFS_UF_IMMUTABLE
#define UFS_UF_APPEND
#define UFS_UF_OPAQUE
#define UFS_UF_NOUNLINK
/* ui_flags that only root can set */
#define UFS_SF_SETTABLE
#define UFS_SF_ARCHIVED
#define UFS_SF_IMMUTABLE
#define UFS_SF_APPEND
#define UFS_SF_NOUNLINK

/*
 * This structure is used for reading disk structures larger
 * than the size of fragment.
 */
struct ufs_buffer_head {};

struct ufs_cg_private_info {};


struct ufs_sb_private_info {};

/*
 * Sizes of this structures are:
 *	ufs_super_block_first	512
 *	ufs_super_block_second	512
 *	ufs_super_block_third	356
 */
struct ufs_super_block_first {};

struct ufs_super_block_second {};

struct ufs_super_block_third {};

#endif /* __LINUX_UFS_FS_H */