1N/A/*
1N/A * Copyright (c) International Business Machines Corp., 2000
1N/A *
1N/A * This program is free software; you can redistribute it and/or modify
1N/A * it under the terms of the GNU General Public License as published by
1N/A * the Free Software Foundation; either version 3 of the License, or
1N/A * (at your option) any later version.
1N/A *
1N/A * This program is distributed in the hope that it will be useful,
1N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
1N/A * the GNU General Public License for more details.
1N/A *
1N/A * You should have received a copy of the GNU General Public License
1N/A * along with this program. If not, see <http://www.gnu.org/licenses/>.
1N/A */
1N/A
1N/A#ifndef _H_JFS_TYPES
1N/A#define _H_JFS_TYPES
1N/A
1N/A/*
1N/A * jfs_types.h:
1N/A *
1N/A * basic type/utility definitions
1N/A *
1N/A * note: this header file must be the 1st include file
1N/A * of JFS include list in all JFS .c file.
1N/A */
1N/A
1N/A#ifdef _JFS_UTILITY
1N/A/* this is defined in asm/byteorder.h for i386, but
1N/A * is NOT defined in asm/byteorder.h for ppc (non-kernel).
1N/A * Until that is changed, we'll define it here. */
1N/A#define __BYTEORDER_HAS_U64__
1N/A
1N/A#include <sys/types.h>
1N/A//#include <asm/byteorder.h>
1N/Atypedef unsigned short UniChar;
1N/A#else
1N/A#include <linux/types.h>
1N/A#include <linux/jfs_fs.h>
1N/A#include <linux/nls.h>
1N/A
1N/A#ifndef _ULS_UNICHAR_DEFINED
1N/A#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0))
1N/Atypedef wchar_t UniChar;
1N/A#else
1N/Atypedef unsigned short UniChar;
1N/A#endif
1N/A#define _ULS_UNICHAR_DEFINED
1N/A#endif
1N/A#endif
1N/A/* #include "endian24.h" */
1N/A
1N/A/*
1N/A * primitive types
1N/A */
1N/A#ifdef _JFS_UTILITY
1N/Atypedef int8_t s8;
1N/Atypedef uint8_t u8;
1N/Atypedef int16_t s16;
1N/Atypedef uint16_t u16;
1N/Atypedef int32_t s32;
1N/Atypedef uint32_t u32;
1N/Atypedef int64_t s64;
1N/Atypedef uint64_t u64;
1N/A
1N/A#ifndef _UINT_TYPES
1N/A /* unicode includes also define these */
1N/Atypedef u16 uint16;
1N/Atypedef u32 uint32;
1N/A#define _UINT_TYPES
1N/A#endif
1N/A
1N/Atypedef s8 int8;
1N/Atypedef u8 uint8;
1N/Atypedef s16 int16;
1N/Atypedef s32 int32;
1N/Atypedef s64 int64;
1N/Atypedef u64 uint64;
1N/A
1N/A#endif /* _JFS_UTILITY */
1N/A/*
1N/A * Holdovers from OS/2. Try to get away from using these altogether.
1N/A */
1N/Atypedef unsigned long ULONG;
1N/Atypedef unsigned short USHORT;
1N/Atypedef unsigned char UCHAR;
1N/Atypedef void *PVOID;
1N/A#define MAXPATHLEN 255
1N/A
1N/A
1N/A/*
1N/A * Almost identical to Linux's timespec, but not quite
1N/A */
1N/Astruct timestruc_t {
1N/A u32 tv_sec;
1N/A u32 tv_nsec;
1N/A};
1N/A
1N/A/*
1N/A * handy
1N/A */
1N/A#undef MIN
1N/A#define MIN(a,b) (((a)<(b))?(a):(b))
1N/A#undef MAX
1N/A#define MAX(a,b) (((a)>(b))?(a):(b))
1N/A#undef ROUNDUP
1N/A#define ROUNDUP(x, y) ( ((x) + ((y) - 1)) & ~((y) - 1) )
1N/A
1N/A#define LEFTMOSTONE 0x80000000
1N/A#define HIGHORDER 0x80000000u /* high order bit on */
1N/A#define ONES 0xffffffffu /* all bit on */
1N/A
1N/A#if !defined(__sun)
1N/Atypedef int boolean_t;
1N/A#endif
1N/A
1N/A#define TRUE 1
1N/A#define FALSE 0
1N/A
1N/A/*
1N/A * logical xd (lxd)
1N/A */
1N/Atypedef struct {
1N/A unsigned len:24;
1N/A unsigned off1:8;
1N/A u32 off2;
1N/A} lxd_t;
1N/A
1N/A/* lxd_t field construction */
1N/A#define LXDlength(lxd, length32) ( (lxd)->len = length32 )
1N/A#define LXDoffset(lxd, offset64)\
1N/A{\
1N/A (lxd)->off1 = ((s64)offset64) >> 32;\
1N/A (lxd)->off2 = (offset64) & 0xffffffff;\
1N/A}
1N/A
1N/A/* lxd_t field extraction */
1N/A#define lengthLXD(lxd) ( (lxd)->len )
1N/A#define offsetLXD(lxd)\
1N/A ( ((s64)((lxd)->off1)) << 32 | (lxd)->off2 )
1N/A
1N/A/* lxd list */
1N/Atypedef struct {
1N/A s16 maxnlxd;
1N/A s16 nlxd;
1N/A lxd_t *lxd;
1N/A} lxdlist_t;
1N/A
1N/A/*
1N/A * physical xd (pxd)
1N/A */
1N/Atypedef struct {
1N/A unsigned len:24;
1N/A unsigned addr1:8;
1N/A u32 addr2;
1N/A} pxd_t;
1N/A
1N/A/* xd_t field construction */
1N/A
1N/A#define PXDlength(pxd, length32) ((pxd)->len = __cpu_to_le24(length32))
1N/A#define PXDaddress(pxd, address64)\
1N/A{\
1N/A (pxd)->addr1 = ((s64)address64) >> 32;\
1N/A (pxd)->addr2 = __cpu_to_le32((address64) & 0xffffffff);\
1N/A}
1N/A
1N/A/* xd_t field extraction */
1N/A#define lengthPXD(pxd) __le24_to_cpu((pxd)->len)
1N/A#define addressPXD(pxd)\
1N/A ( ((s64)((pxd)->addr1)) << 32 | __le32_to_cpu((pxd)->addr2))
1N/A
1N/A/* pxd list */
1N/Atypedef struct {
1N/A s16 maxnpxd;
1N/A s16 npxd;
1N/A pxd_t pxd[8];
1N/A} pxdlist_t;
1N/A
1N/A
1N/A/*
1N/A * data extent descriptor (dxd)
1N/A */
1N/Atypedef struct {
1N/A unsigned flag:8; /* 1: flags */
1N/A unsigned rsrvd:24; /* 3: */
1N/A u32 size; /* 4: size in byte */
1N/A unsigned len:24; /* 3: length in unit of fsblksize */
1N/A unsigned addr1:8; /* 1: address in unit of fsblksize */
1N/A u32 addr2; /* 4: address in unit of fsblksize */
1N/A} dxd_t; /* - 16 - */
1N/A
1N/A/* dxd_t flags */
1N/A#define DXD_INDEX 0x80 /* B+-tree index */
1N/A#define DXD_INLINE 0x40 /* in-line data extent */
1N/A#define DXD_EXTENT 0x20 /* out-of-line single extent */
1N/A#define DXD_FILE 0x10 /* out-of-line file (inode) */
1N/A#define DXD_CORRUPT 0x08 /* Inconsistency detected */
1N/A
1N/A/* dxd_t field construction
1N/A * Conveniently, the PXD macros work for DXD
1N/A */
1N/A#define DXDlength PXDlength
1N/A#define DXDaddress PXDaddress
1N/A#define lengthDXD lengthPXD
1N/A#define addressDXD addressPXD
1N/A
1N/A/*
1N/A * directory entry argument
1N/A */
1N/Atypedef struct component_name {
1N/A int namlen;
1N/A UniChar *name;
1N/A} component_t;
1N/A
1N/A
1N/A/*
1N/A * DASD limit information - stored in directory inode
1N/A */
1N/Atypedef struct dasd {
1N/A u8 thresh; /* Alert Threshold (in percent) */
1N/A u8 delta; /* Alert Threshold delta (in percent) */
1N/A u8 rsrvd1;
1N/A u8 limit_hi; /* DASD limit (in logical blocks) */
1N/A u32 limit_lo; /* DASD limit (in logical blocks) */
1N/A u8 rsrvd2[3];
1N/A u8 used_hi; /* DASD usage (in logical blocks) */
1N/A u32 used_lo; /* DASD usage (in logical blocks) */
1N/A} dasd_t;
1N/A
1N/A#define DASDLIMIT(dasdp) \
1N/A (((u64)((dasdp)->limit_hi) << 32) + __le32_to_cpu((dasdp)->limit_lo))
1N/A#define setDASDLIMIT(dasdp, limit)\
1N/A{\
1N/A (dasdp)->limit_hi = ((u64)limit) >> 32;\
1N/A (dasdp)->limit_lo = __cpu_to_le32(limit);\
1N/A}
1N/A#define DASDUSED(dasdp) \
1N/A (((u64)((dasdp)->used_hi) << 32) + __le32_to_cpu((dasdp)->used_lo))
1N/A#define setDASDUSED(dasdp, used)\
1N/A{\
1N/A (dasdp)->used_hi = ((u64)used) >> 32;\
1N/A (dasdp)->used_lo = __cpu_to_le32(used);\
1N/A}
1N/A
1N/A/*
1N/A * circular doubly-linked list (cdll)
1N/A *
1N/A * A circular doubly-linked list (cdll) is anchored by a pair of pointers,
1N/A * one to the head of the list and the other to the tail of the list.
1N/A * The elements are doubly linked so that an arbitrary element can be
1N/A * removed without a need to traverse the list.
1N/A * New elements can be added to the list before or after an existing element,
1N/A * at the head of the list, or at the tail of the list.
1N/A * A circle queue may be traversed in either direction.
1N/A *
1N/A * +----------+ +-------------------------------------+
1N/A * | | | |
1N/A * +->+-----+ | +->+-----+ +->+-----+ +->+-----+ |
1N/A * | | h +-+ | | h +--+ | n +----+ | n +--+
1N/A * | +-----+ | +-----+ | +-----+ | +-----+
1N/A * | | t +-+ +-----+ t | | | p +--+ | | p +--+
1N/A * | +-----+ | | | +-----+ | +-----+ | | +-----+ |
1N/A * +----------+ | +-----------------------+ | |
1N/A * | | | |
1N/A * | +-------------------------+
1N/A * | |
1N/A * +----------------------------+
1N/A */
1N/A/*
1N/A * define header
1N/A *
1N/A * list header field definition in header element:
1N/A *
1N/A * type - type of list element struct embedding the link field
1N/A */
1N/A#define CDLL_HEADER(type)\
1N/Astruct {\
1N/A struct type *head;\
1N/A struct type *tail;\
1N/A}
1N/A
1N/Astruct cdll_header {
1N/A struct cdll_header *head;
1N/A struct cdll_header *tail;
1N/A};
1N/A
1N/A/*
1N/A * define link
1N/A *
1N/A * list link field definition in list element:
1N/A *
1N/A * type - type of parent list element struct embedding the link field
1N/A */
1N/A#define CDLL_ENTRY(type)\
1N/Astruct {\
1N/A struct type *next;\
1N/A struct type *prev;\
1N/A}
1N/A
1N/Astruct cdll_entry {
1N/A struct cdll_entry *next;
1N/A struct cdll_entry *prev;
1N/A};
1N/A
1N/A/*
1N/A * initialize header
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A */
1N/A#define CDLL_INIT(header) {\
1N/A (header)->head = (void *)(header);\
1N/A (header)->tail = (void *)(header);\
1N/A}
1N/A
1N/A/*
1N/A * scan list
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A * elm - ptr to the element to be inserted
1N/A * field - name of the link field in the list element
1N/A *
1N/A * struct header_container *container;
1N/A * struct header_type *header;
1N/A * struct element_type *elm;
1N/A *
1N/A * header = &container->header_field;
1N/A * for (elm = header->head; elm != (void *)header; elm = elm->field.next)
1N/A */
1N/A
1N/A/*
1N/A * insert <elm> at head of list anchored at <header>
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A * elm - ptr to the list element to be inserted
1N/A * field - name of the link field in the list element
1N/A */
1N/A#define CDLL_INSERT_HEAD(header, elm, field) {\
1N/A (elm)->field.next = (header)->head;\
1N/A (elm)->field.prev = (void *)(header);\
1N/A if ((header)->tail == (void *)(header))\
1N/A (header)->tail = (elm);\
1N/A else\
1N/A (header)->head->field.prev = (elm);\
1N/A (header)->head = (elm);\
1N/A}
1N/A
1N/A/*
1N/A * insert <elm> at tail of list anchored at <header>
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A * elm - ptr to the list element to be inserted
1N/A * field - name of the link field in the list element
1N/A */
1N/A#define CDLL_INSERT_TAIL(header, elm, field) {\
1N/A (elm)->field.next = (void *)(header);\
1N/A (elm)->field.prev = (header)->tail;\
1N/A if ((header)->head == (void *)(header))\
1N/A (header)->head = (elm);\
1N/A else\
1N/A (header)->tail->field.next = (elm);\
1N/A (header)->tail = (elm);\
1N/A}
1N/A
1N/A/*
1N/A * insert <elm> after <listelm> of list anchored at <header>
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A * listelm - ptr to the list element at insertion point
1N/A * elm - ptr to the list element to be inserted
1N/A * field - name of the link field in the list element
1N/A */
1N/A#define CDLL_INSERT_AFTER(header, listelm, elm, field) {\
1N/A (elm)->field.next = (listelm)->field.next;\
1N/A (elm)->field.prev = (listelm);\
1N/A if ((listelm)->field.next == (void *)(header))\
1N/A (header)->tail = (elm);\
1N/A else\
1N/A (listelm)->field.next->field.prev = (elm);\
1N/A (listelm)->field.next = (elm);\
1N/A}
1N/A
1N/A/*
1N/A * insert <elm> before <listelm> of list anchored at <header>
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A * listelm - ptr to list element at insertion point
1N/A * elm - ptr to the element to be inserted
1N/A * field - name of the link field in the list element
1N/A */
1N/A#define CDLL_INSERT_BEFORE(header, listelm, elm, field) {\
1N/A (elm)->field.next = (listelm);\
1N/A (elm)->field.prev = (listelm)->field.prev;\
1N/A if ((listelm)->field.prev == (void *)(header))\
1N/A (header)->head = (elm);\
1N/A else\
1N/A (listelm)->field.prev->field.next = (elm);\
1N/A (listelm)->field.prev = (elm);\
1N/A}
1N/A
1N/A/*
1N/A * remove <elm> from list anchored at <header>
1N/A *
1N/A * header - ptr to the header field in the header element
1N/A * elm - ptr to the list element to be removed
1N/A * field - name of the link field in the list element
1N/A */
1N/A#define CDLL_REMOVE(header, elm, field) {\
1N/A if ((elm)->field.next == (void *)(header))\
1N/A (header)->tail = (elm)->field.prev;\
1N/A else\
1N/A (elm)->field.next->field.prev = (elm)->field.prev;\
1N/A if ((elm)->field.prev == (void *)(header))\
1N/A (header)->head = (elm)->field.next;\
1N/A else\
1N/A (elm)->field.prev->field.next = (elm)->field.next;\
1N/A}
1N/A
1N/A#define CDLL_MOVE_TO_HEAD(header, elm, field) {\
1N/A if ((elm)->field.prev != (void *)(header))\
1N/A {\
1N/A if ((elm)->field.next == (void *)(header))\
1N/A (header)->tail = (elm)->field.prev;\
1N/A else\
1N/A (elm)->field.next->field.prev = (elm)->field.prev;\
1N/A (elm)->field.prev->field.next = (elm)->field.next;\
1N/A (elm)->field.next = (header)->head;\
1N/A (elm)->field.prev = (void *)(header);\
1N/A (header)->head->field.prev = (elm);\
1N/A (header)->head = (elm);\
1N/A }\
1N/A}
1N/A
1N/A#define CDLL_MOVE_TO_TAIL(header, elm, field) {\
1N/A if ((elm)->field.next != (void *)(header))\
1N/A {\
1N/A (elm)->field.next->field.prev = (elm)->field.prev;\
1N/A if ((elm)->field.prev == (void *)(header))\
1N/A (header)->head = (elm)->field.next;\
1N/A else\
1N/A (elm)->field.prev->field.next = (elm)->field.next;\
1N/A (elm)->field.next = (void *)(header);\
1N/A (elm)->field.prev = (header)->tail;\
1N/A (header)->tail->field.next = (elm);\
1N/A (header)->tail = (elm);\
1N/A }\
1N/A}
1N/A
1N/A/*
1N/A * orphan list element
1N/A */
1N/A#define CDLL_SELF(elm, field)\
1N/A (elm)->field.next = (elm)->field.prev = (elm);
1N/A
1N/A
1N/A/*
1N/A * single head doubly-linked list
1N/A *
1N/A * A list is headed by a single head pointer.
1N/A * The elements are doubly linked so that an arbitrary element can be
1N/A * removed without a need to traverse the list.
1N/A * New elements can be added to the list at the head of the list, or
1N/A * after an existing element (NO insert at tail).
1N/A * A list may only be traversed in the forward direction.
1N/A * (note: the list is NULL terminated in next field.)
1N/A *
1N/A * +-----+ +->+-----+ +->+-----+ +->+-----+
1N/A * | NULL| | | h +--+ | n +----+ | NULL|
1N/A * +-----+ | +-----+ | +-----+ +-----+
1N/A * | | | p +--+ | p +--+
1N/A * | | +-----+ | +-----+ |
1N/A * +-----------------------+ |
1N/A * | |
1N/A * +-------------------------+
1N/A */
1N/A#define LIST_HEADER(type)\
1N/Astruct {\
1N/A struct type *head;\
1N/A}
1N/A
1N/A#define LIST_ENTRY(type)\
1N/Astruct {\
1N/A struct type *next;\
1N/A struct type **prev;\
1N/A}
1N/A
1N/A#define LIST_INIT(header) { (header)->head = NULL; }
1N/A
1N/A/*
1N/A * scan list
1N/A *
1N/A * header - ptr to the header (field in header element)
1N/A * elm - ptr to the element to be inserted
1N/A * field - name of the link field in list element
1N/A *
1N/A * struct header_container *container;
1N/A * struct header_type *header;
1N/A * struct element_type *elm;
1N/A *
1N/A * header = &container->header_field;
1N/A * for (elm = header->head; elm; elm = elm->field.next)
1N/A */
1N/A
1N/A#define LIST_INSERT_HEAD(header, elm, field) {\
1N/A if (((elm)->field.next = (header)->head) != NULL)\
1N/A (header)->head->field.prev = &(elm)->field.next;\
1N/A (header)->head = (elm);\
1N/A (elm)->field.prev = &(header)->head;\
1N/A}
1N/A
1N/A#define LIST_INSERT_AFTER(listelm, elm, field) {\
1N/A if (((elm)->field.next = (listelm)->field.next) != NULL)\
1N/A (listelm)->field.next->field.prev = &(elm)->field.next;\
1N/A (listelm)->field.next = (elm);\
1N/A (elm)->field.prev = &(listelm)->field.next;\
1N/A}
1N/A
1N/A#define LIST_REMOVE(elm, field) {\
1N/A if ((elm)->field.next != NULL)\
1N/A (elm)->field.next->field.prev = (elm)->field.prev;\
1N/A *(elm)->field.prev = (elm)->field.next;\
1N/A}
1N/A
1N/A#define LIST_SELF(elm, field) {\
1N/A (elm)->field.next = NULL;\
1N/A (elm)->field.prev = &(elm)->field.next;\
1N/A}
1N/A
1N/A#endif /* !_H_JFS_TYPES */