162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *   Copyright (C) International Business Machines Corp., 2000-2002
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#ifndef _H_JFS_XTREE
662306a36Sopenharmony_ci#define _H_JFS_XTREE
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci/*
962306a36Sopenharmony_ci *	jfs_xtree.h: extent allocation descriptor B+-tree manager
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include "jfs_btree.h"
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/*
1662306a36Sopenharmony_ci *	extent allocation descriptor (xad)
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_citypedef struct xad {
1962306a36Sopenharmony_ci	__u8 flag;	/* 1: flag */
2062306a36Sopenharmony_ci	__u8 rsvrd[2];	/* 2: reserved */
2162306a36Sopenharmony_ci	__u8 off1;	/* 1: offset in unit of fsblksize */
2262306a36Sopenharmony_ci	__le32 off2;	/* 4: offset in unit of fsblksize */
2362306a36Sopenharmony_ci	pxd_t loc;	/* 8: length and address in unit of fsblksize */
2462306a36Sopenharmony_ci} xad_t;			/* (16) */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define MAXXLEN		((1 << 24) - 1)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define XTSLOTSIZE	16
2962306a36Sopenharmony_ci#define L2XTSLOTSIZE	4
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* xad_t field construction */
3262306a36Sopenharmony_ci#define XADoffset(xad, offset64)\
3362306a36Sopenharmony_ci{\
3462306a36Sopenharmony_ci	(xad)->off1 = ((u64)offset64) >> 32;\
3562306a36Sopenharmony_ci	(xad)->off2 = __cpu_to_le32((offset64) & 0xffffffff);\
3662306a36Sopenharmony_ci}
3762306a36Sopenharmony_ci#define XADaddress(xad, address64) PXDaddress(&(xad)->loc, address64)
3862306a36Sopenharmony_ci#define XADlength(xad, length32) PXDlength(&(xad)->loc, length32)
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/* xad_t field extraction */
4162306a36Sopenharmony_ci#define offsetXAD(xad)\
4262306a36Sopenharmony_ci	( ((s64)((xad)->off1)) << 32 | __le32_to_cpu((xad)->off2))
4362306a36Sopenharmony_ci#define addressXAD(xad) addressPXD(&(xad)->loc)
4462306a36Sopenharmony_ci#define lengthXAD(xad) lengthPXD(&(xad)->loc)
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci/* xad list */
4762306a36Sopenharmony_cistruct xadlist {
4862306a36Sopenharmony_ci	s16 maxnxad;
4962306a36Sopenharmony_ci	s16 nxad;
5062306a36Sopenharmony_ci	xad_t *xad;
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* xad_t flags */
5462306a36Sopenharmony_ci#define XAD_NEW		0x01	/* new */
5562306a36Sopenharmony_ci#define XAD_EXTENDED	0x02	/* extended */
5662306a36Sopenharmony_ci#define XAD_COMPRESSED	0x04	/* compressed with recorded length */
5762306a36Sopenharmony_ci#define XAD_NOTRECORDED 0x08	/* allocated but not recorded */
5862306a36Sopenharmony_ci#define XAD_COW		0x10	/* copy-on-write */
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* possible values for maxentry */
6262306a36Sopenharmony_ci#define XTROOTINITSLOT_DIR 6
6362306a36Sopenharmony_ci#define XTROOTINITSLOT	10
6462306a36Sopenharmony_ci#define XTROOTMAXSLOT	18
6562306a36Sopenharmony_ci#define XTPAGEMAXSLOT	256
6662306a36Sopenharmony_ci#define XTENTRYSTART	2
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/*
6962306a36Sopenharmony_ci *	xtree page:
7062306a36Sopenharmony_ci */
7162306a36Sopenharmony_citypedef union {
7262306a36Sopenharmony_ci	struct xtheader {
7362306a36Sopenharmony_ci		__le64 next;	/* 8: */
7462306a36Sopenharmony_ci		__le64 prev;	/* 8: */
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci		u8 flag;	/* 1: */
7762306a36Sopenharmony_ci		u8 rsrvd1;	/* 1: */
7862306a36Sopenharmony_ci		__le16 nextindex;	/* 2: next index = number of entries */
7962306a36Sopenharmony_ci		__le16 maxentry;	/* 2: max number of entries */
8062306a36Sopenharmony_ci		__le16 rsrvd2;	/* 2: */
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci		pxd_t self;	/* 8: self */
8362306a36Sopenharmony_ci	} header;		/* (32) */
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	xad_t xad[XTROOTMAXSLOT];	/* 16 * maxentry: xad array */
8662306a36Sopenharmony_ci} xtpage_t;
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/*
8962306a36Sopenharmony_ci *	external declaration
9062306a36Sopenharmony_ci */
9162306a36Sopenharmony_ciextern int xtLookup(struct inode *ip, s64 lstart, s64 llen,
9262306a36Sopenharmony_ci		    int *pflag, s64 * paddr, int *plen, int flag);
9362306a36Sopenharmony_ciextern void xtInitRoot(tid_t tid, struct inode *ip);
9462306a36Sopenharmony_ciextern int xtInsert(tid_t tid, struct inode *ip,
9562306a36Sopenharmony_ci		    int xflag, s64 xoff, int xlen, s64 * xaddrp, int flag);
9662306a36Sopenharmony_ciextern int xtExtend(tid_t tid, struct inode *ip, s64 xoff, int xlen,
9762306a36Sopenharmony_ci		    int flag);
9862306a36Sopenharmony_ciextern int xtUpdate(tid_t tid, struct inode *ip, struct xad *nxad);
9962306a36Sopenharmony_ciextern s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int type);
10062306a36Sopenharmony_ciextern s64 xtTruncate_pmap(tid_t tid, struct inode *ip, s64 committed_size);
10162306a36Sopenharmony_ciextern int xtAppend(tid_t tid,
10262306a36Sopenharmony_ci		    struct inode *ip, int xflag, s64 xoff, int maxblocks,
10362306a36Sopenharmony_ci		    int *xlenp, s64 * xaddrp, int flag);
10462306a36Sopenharmony_ci#endif				/* !_H_JFS_XTREE */
105