From c9fe8bce173c034d4bbefb42b24c1704683b4f5b Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Fri, 12 Jun 2026 13:25:01 +0000 Subject: [PATCH] core: move imported NSS bitmap headers into libnwcore include --- include/core/bitmap.h | 62 ++++ include/core/omni.h | 756 ++++++++++++++++++++++++++++++++++++++++ include/core/size_t.h | 70 ++++ include/core/zOmni.h | 333 ++++++++++++++++++ include/core/zWhere.h | 68 ++++ src/core/CMakeLists.txt | 21 ++ src/core/bitmap.c | 2 + 7 files changed, 1312 insertions(+) create mode 100644 include/core/bitmap.h create mode 100644 include/core/omni.h create mode 100644 include/core/size_t.h create mode 100644 include/core/zOmni.h create mode 100644 include/core/zWhere.h diff --git a/include/core/bitmap.h b/include/core/bitmap.h new file mode 100644 index 0000000..d493534 --- /dev/null +++ b/include/core/bitmap.h @@ -0,0 +1,62 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: randys $ + | $Date: 2005-01-11 23:43:47 +0530 (Tue, 11 Jan 2005) $ + | + | $RCSfile$ + | $Revision: 511 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Function prototypes for NLMs friendly to NSS. + +-------------------------------------------------------------------------*/ +#ifndef _NSS_BITMAP_H_ +#define _NSS_BITMAP_H_ + +#ifndef _ZOMNI_H_ +# include +#endif + +typedef struct BitMap_s { + NINT *bits; + NINT max; + NINT start; +} BitMap_s; + +extern NINT getMaxBits (BitMap_s *bitMap); +extern BOOL testABit (BitMap_s *bitMap, NINT bitNum); +extern void setAbit (BitMap_s *bitMap, NINT bitNum); +extern void clearAbit(BitMap_s *bitMap, NINT bitNum); +extern void setBits(BitMap_s *bitMap, NINT startBit, NINT numBits); +extern void clearBits(BitMap_s *bitMap, NINT startBit, NINT numBits); +extern NINT countBits(BitMap_s *bitMap); +extern SNINT findBits(BitMap_s *bitMap, NINT bitsNeeded); + +extern BitMap_s *newBitMap(BitMap_s *bitMap, NINT numBits); +extern void freeBitMap(BitMap_s *bitMap); + +#endif diff --git a/include/core/omni.h b/include/core/omni.h new file mode 100644 index 0000000..cee3306 --- /dev/null +++ b/include/core/omni.h @@ -0,0 +1,756 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: vandana $ + | $Date: 2007-04-18 23:26:20 +0530 (Wed, 18 Apr 2007) $ + | + | $RCSfile$ + | $Revision: 1954 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | This is the base INTERNAL include file the contains all of the + | base definitions. This contains information NOT in the SDK. + | + | WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! + | + | This header file should ONLY be used for NSS internal development. + | This includes Semantic Agents (SA) and Loadable Storage Services (LSS). + | Any other use may cause conflicts which NSS will NOT fix. + +-------------------------------------------------------------------------*/ +#ifndef _OMNI_H_ +#define _OMNI_H_ + +#ifndef _ZOMNI_H_ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/*------------------------------------------------------------------------- + * The following conditionals define what OS is being built. + * _NWMOAB_ + * _NWGREENRIVER_ + * The following turns the language enabling macros on + * _LANGUAGEENABLED_ + *-------------------------------------------------------------------------*/ + +/*--------------------------------------------------------------------------- + * All of the #DEFINES that control conditional compilation in PSS are now + * defined in one place. All of these conditionals are controlled by the + * six main conditionals. One and only one of these conditionals should + * be set to ENABLE. Both uni and multi processor configurations are defined. + *---------------------------------------------------------------------------*/ +#ifdef UNOPT +#ifdef MPK +# define NSS_UNI_OPTIMAL DISABLE /* ENABLE for uni-processor production code*/ +# define NSS_UNI_DEBUG DISABLE //ENABLE /* ENABLE for development*/ +# define NSS_UNI_PREEMPT DISABLE /* ENABLE for uni-proc preemptive env*/ +# define NSS_MPK_OPTIMAL DISABLE /* ENABLE for multi-processor production*/ +# define NSS_MPK_DEBUG ENABLE /* ENABLE for multi-processor (MP) debugging*/ +# define NSS_MPK_FAKE DISABLE /* ENABLE to make a uni-processor fake MP*/ +# define NSS_MCCABE DISABLE /* ENABLE to change most macros to functions*/ +#else /*!MPK*/ +# define NSS_UNI_OPTIMAL DISABLE /* ENABLE for uni-processor production code*/ +# define NSS_UNI_DEBUG ENABLE //ENABLE /* ENABLE for development*/ +# define NSS_UNI_PREEMPT DISABLE /* ENABLE for uni-proc preemptive env*/ +# define NSS_MPK_OPTIMAL DISABLE /* ENABLE for multi-processor production*/ +# define NSS_MPK_DEBUG DISABLE /* ENABLE for multi-processor (MP) debugging*/ +# define NSS_MPK_FAKE DISABLE /* ENABLE to make a uni-processor fake MP*/ +# define NSS_MCCABE DISABLE /* ENABLE to change most macros to functions*/ +#endif /*MPK*/ +#else /*!UNOPT*/ +#ifdef MPK +# define NSS_UNI_OPTIMAL DISABLE //ENABLE /* ENABLE for uni-processor production code*/ +# define NSS_UNI_DEBUG DISABLE /* ENABLE for development*/ +# define NSS_UNI_PREEMPT DISABLE /* ENABLE for uni-proc preemptive env*/ +# define NSS_MPK_OPTIMAL ENABLE //DISABLE /* ENABLE for multi-processor production*/ +# define NSS_MPK_DEBUG DISABLE /* ENABLE for multi-processor (MP) debugging*/ +# define NSS_MPK_FAKE DISABLE /* ENABLE to make a uni-processor fake MP*/ +# define NSS_MCCABE DISABLE /* ENABLE to change most macros to functions*/ +#else /*!MPK*/ +# define NSS_UNI_OPTIMAL ENABLE //ENABLE /* ENABLE for uni-processor production code*/ +# define NSS_UNI_DEBUG DISABLE /* ENABLE for development*/ +# define NSS_UNI_PREEMPT DISABLE /* ENABLE for uni-proc preemptive env*/ +# define NSS_MPK_OPTIMAL DISABLE //DISABLE /* ENABLE for multi-processor production*/ +# define NSS_MPK_DEBUG DISABLE /* ENABLE for multi-processor (MP) debugging*/ +# define NSS_MPK_FAKE DISABLE /* ENABLE to make a uni-processor fake MP*/ +# define NSS_MCCABE DISABLE /* ENABLE to change most macros to functions*/ +#endif /*MPK*/ +#endif /*UNOPT*/ + + +#if NSS_UNI_OPTIMAL IS_ENABLED + /*** This is the Production/Release options ***/ + /*** Uni-processor only ***/ +# undef NSS_MCCABE +# define NSS_MCCABE DISABLE /* Make sure NSS_MCCABE options are disabled*/ +# define NSS_DEBUG DISABLE /* disable DEBUG code in NSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT DISABLE /* disable ASSERTS in PSS */ +# define LATCH_MACRO ENABLE /* use LATCH macros*/ +# define QUE_CHECK DISABLE /* remove QUE debug checks*/ +# define QUE_MACRO ENABLE /* use QUE macros*/ +# define MEM_KEEP_LIST DISABLE /* don't keep list of allocated memory*/ +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE DISABLE /* don't use fake multi-processor code*/ +# define MPK_REAL DISABLE /* don't use real multi-processor code*/ +# define HISTOGRAM DISABLE /* don't keep histograms*/ +# define LOG_TEST DISABLE /* Include undo/redo immediate code. This + * code causes ZLOG to ask for a undo/redo + * or redo/undo to be performed while the + * system is logging transactions. The + * results are then compared against the + * correct answer. If not correct ASSERTs + * are generated. + */ +# define ZLOG_DEBUG DISABLE /* Include ZLOG debug code. This code + * adds debug information to the ZLOG + * Beast and File. For performance reasons + * this should be turned off for release. + */ +# define ZLOG_TEST DISABLE /* Perform simple ZLOG unit tests. This + * must be turned off for release. These + * Tests are only run if /zlog if specified + * when loading the NSS NLM. + */ +# define FMAP_TEST DISABLE /* Test the filemap code by simulating + * large fragmented files. + */ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#elif NSS_UNI_DEBUG IS_ENABLED +# define NSS_DEBUG ENABLE /* enable DEBUG code in PSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT ENABLE /* enable ASSERTS in PSS*/ +# define LATCH_MACRO DISABLE /* use LATCH functions*/ +# define QUE_CHECK ENABLE /* enable QUE debug checks*/ +# define QUE_MACRO DISABLE /* use QUE functions*/ +# define EVENTQ_MACRO ENABLE /* use EVENTQ macros*/ +#if zLINUX +# define MEM_KEEP_LIST DISABLE /* keep list of allocated memory blocks*/ +#else +# define MEM_KEEP_LIST ENABLE /* keep list of allocated memory blocks*/ +#endif +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE DISABLE /* don't use fake multi-processor code*/ +# define MPK_REAL DISABLE /* don't use real multi-processor code*/ +# define HISTOGRAM ENABLE /* keep histograms*/ +# define LOG_TEST ENABLE /* Include undo/redo immediate code*/ +# define ZLOG_DEBUG ENABLE /* Include ZLOG debug code*/ +# define ZLOG_TEST ENABLE /* Perform simple ZLOG unit tests*/ +# define FMAP_TEST ENABLE /* Perform Filemap Btree tests*/ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#elif NSS_UNI_PREEMPT IS_ENABLED /* Still need to set flags correctly*/ + +# define NSS_DEBUG ENABLE /* enable DEBUG code in PSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT ENABLE /* enable ASSERTS in PSS*/ +# define LATCH_MACRO DISABLE /* use LATCH functions*/ +# define QUE_CHECK ENABLE /* enable QUE debug checks*/ +# define QUE_MACRO DISABLE /* use QUE functions*/ +# define EVENTQ_MACRO ENABLE /* use EVENTQ macros*/ +#if zLINUX +# define MEM_KEEP_LIST DISABLE /* keep list of allocated memory blocks*/ +#else +# define MEM_KEEP_LIST ENABLE /* keep list of allocated memory blocks*/ +#endif +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE DISABLE /* don't use fake multi-processor code*/ +# define MPK_REAL DISABLE /* don't use real multi-processor code*/ +# define HISTOGRAM ENABLE /* keep histograms*/ +# define LOG_TEST ENABLE /* Include undo/redo immediate code*/ +# define ZLOG_DEBUG ENABLE /* Include ZLOG debug code*/ +# define ZLOG_TEST ENABLE /* Perform simple ZLOG unit tests*/ +# define FMAP_TEST ENABLE /* Perform Filemap Btree tests*/ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#elif NSS_MPK_OPTIMAL IS_ENABLED + /*** This is the Production/Release options ***/ + /*** MPK only ***/ +# undef NSS_MCCABE +# define NSS_MCCABE DISABLE /* Make sure NSS_MCCABE options are disabled*/ +# define NSS_DEBUG DISABLE /* disable DEBUG code in PSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT DISABLE /* disable ASSERTS in PSS */ +# define LATCH_MACRO ENABLE /* use LATCH macros*/ +# define QUE_CHECK DISABLE /* remove QUE debug checks*/ +# define QUE_MACRO ENABLE /* use QUE macros*/ +# define EVENTQ_MACRO ENABLE /* use EVENTQ macros*/ +# define MEM_KEEP_LIST DISABLE /* don't keep list of allocated memory*/ +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE DISABLE /* don't use fake multi-processor code*/ +# define MPK_REAL ENABLE /* use real multi-processor code*/ +# define HISTOGRAM DISABLE /* don't keep histograms*/ +# define LOG_TEST DISABLE /* Include undo/redo immediate code*/ +# define ZLOG_DEBUG DISABLE /* Include ZLOG debug code*/ +# define ZLOG_TEST DISABLE /* Perform simple ZLOG unit tests*/ +# define FMAP_TEST DISABLE /* Perform Filemap Btree tests*/ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#elif NSS_MPK_DEBUG IS_ENABLED +# define NSS_DEBUG ENABLE /* enable DEBUG code in PSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT ENABLE /* enable ASSERTS in PSS*/ +# define LATCH_MACRO DISABLE /* use LATCH functions*/ +# define QUE_CHECK ENABLE /* enable QUE debug checks*/ +# define QUE_MACRO DISABLE /* use QUE functions*/ +# define EVENTQ_MACRO ENABLE /* use EVENTQ macros*/ +#if zLINUX +# define MEM_KEEP_LIST DISABLE /* keep list of allocated memory blocks*/ +#else +# define MEM_KEEP_LIST ENABLE /* keep list of allocated memory blocks*/ +#endif +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE DISABLE /* don't use fake multi-processor code*/ +# define MPK_REAL ENABLE /* use real multi-processor code*/ +# define HISTOGRAM ENABLE /* keep histograms*/ +# define LOG_TEST ENABLE /* Include undo/redo immediate code*/ +# define ZLOG_DEBUG ENABLE /* Include ZLOG debug code*/ +# define ZLOG_TEST ENABLE /* Perform simple ZLOG unit tests*/ +# define FMAP_TEST ENABLE /* Perform Filemap Btree tests*/ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#elif NSS_MPK_FAKE IS_ENABLED +# define NSS_DEBUG ENABLE /* enable DEBUG code in PSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT ENABLE /* enable ASSERTS in PSS*/ +# define LATCH_MACRO DISABLE /* use LATCH functions*/ +# define QUE_CHECK ENABLE /* enable QUE debug checks*/ +# define QUE_MACRO DISABLE /* use QUE functions*/ +# define EVENTQ_MACRO ENABLE /* use EVENTQ macros*/ +#if zLINUX +# define MEM_KEEP_LIST DISABLE /* keep list of allocated memory blocks*/ +#else +# define MEM_KEEP_LIST ENABLE /* keep list of allocated memory blocks*/ +#endif +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE ENABLE /* use fake multi-processor code*/ +# define MPK_REAL DISABLE /* don't use real multi-processor code*/ +# define HISTOGRAM ENABLE /* keep histograms*/ +# define LOG_TEST ENABLE /* Include undo/redo immediate code*/ +# define ZLOG_DEBUG ENABLE /* Include ZLOG debug code*/ +# define ZLOG_TEST ENABLE /* Perform simple ZLOG unit tests*/ +# define FMAP_TEST ENABLE /* Perform Filemap Btree tests*/ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#elif NSS_MCCABE IS_ENABLED +# define NSS_DEBUG DISABLE /* disable DEBUG code in PSS*/ +# define NSS_DEBUG_OPT ENABLE /* ENABLE for debugging optimised code*/ +# define NSS_ASSERT DISABLE /* disable ASSERTS in PSS*/ +# define LATCH_MACRO DISABLE /* use LATCH functions*/ +# define QUE_CHECK DISABLE /* remove QUE debug checks*/ +# define QUE_MACRO DISABLE /* use QUE functions*/ +# define EVENTQ_MACRO DISABLE /* use EVENTQ functions*/ +# define MEM_KEEP_LIST DISABLE /* don't keep list of allocated memory*/ +# define ZTREE_DEBUG DISABLE /* use only to debug ztree code*/ +# define MPK_FAKE DISABLE /* ignore multi-processor code*/ +# define MPK_REAL DISABLE /* ignore multi-processor code*/ +# define HISTOGRAM DISABLE /* don't keep histograms*/ +# define LOG_TEST DISABLE /* Include undo/redo immediate code*/ +# define ZLOG_DEBUG DISABLE /* don't include ZLOG debug code*/ +# define ZLOG_TEST DISABLE /* don't perform simple ZLOG unit tests*/ +# define FMAP_TEST DISABLE /* Perform Filemap Btree tests*/ +# define BLKNUM_64 DISABLE /* Use 64 bit block numbers*/ + +#else +#error "One and only one configuration should be enabled" +#endif + +/* Defining the following adds debug information to RootBeast to keep track + * of the useCounts of the beasts. This is useful in finding rogue useCounts. + */ +// #define DEBUG_BEAST_USE_COUNT + +/*--------------------------------------------------------------------------- + * Global settings that are independent of different builds + *---------------------------------------------------------------------------*/ +#ifdef __linux__ +#define _FSHOOKS DISABLE +#else +#define _FSHOOKS ENABLE +#endif + +#ifdef _LANGUAGEENABLED_ +# define NSS_MSG_TAGS ENABLE +#else +# define NSS_MSG_TAGS DISABLE +#endif + +/*------------------------------------------------------------------------- + * Global type definitions + *-------------------------------------------------------------------------*/ + +#undef TRUE +#undef FALSE +#undef NULL +#undef EOF +//#undef OK +//#undef FAILURE +//#undef SUCCESS +#undef zMIN +#undef zMAX +#undef SET_BIT +#undef CLR_BIT +#undef TST_BIT +#undef ALIGN +#undef UNUSED_PARAM +#undef PAGE_SHIFT +#undef PAGE_SIZE +#undef STATIC +#undef CONST + +#define TRUE 1 /* Though TRUE is really non-zero, we use this + * definition for pseudo boolean expressions + */ +#define FALSE 0 + +#define NULL 0 +#define EOF -1 + +#if NSS_DEBUG IS_ENABLED +#define STATIC /* don't really do "static" for now (messes up debugger)*/ +#else +#define STATIC /* Static makes it hard to profile code */ +#endif + +#define CONST /* don't really do "const" for now (it messes up the src debugger)*/ +#define UNUSED_PARAM(_x) (_x = _x) + + +#define QUAD_GT_LONG(quadValue) (quadValue > 0xffffffff) + +/*------------------------------------------------------------------------- + * Typedefs for basic types + *-------------------------------------------------------------------------*/ + +#ifndef unisizeof +# define unisizeof(buf) (sizeof((buf))/sizeof(unicode_t)) /* get size of buffer in UNICODE chars*/ +#endif + +#ifndef _CFS_T +#define _CFS_T +typedef NINT CFS_t; /* holds the Compressed File Size (CFS)*/ +#endif + +#ifndef _SIZE_T +# include +#endif + +#if BLKNUM_64 IS_ENABLED + typedef SQUAD Blknum_t; /* Block numbers */ + typedef QUAD uBlknum_t; /* Pool Block numbers */ +#else + typedef SLONG Blknum_t; /* Block numbers (cache code requires negative numbers) */ + typedef LONG uBlknum_t; /* Pool Block numbers ('area size' code requires 0x80000000 to be positive) */ +#endif +typedef Blknum_t Blkcnt_t; /* Used to hold a count of block numbers */ + +typedef char ObjName_t[16]; /* Used for name field in objects for debugging*/ + +/*--------------------------------------------------------------------------- + * Sequence Numbers have the property that they monotonically increase + * and can be compared even after they wrap. Zero, 0, has been reserved + * as invalid. They are used for transactions and log sequence numbers. + * + * Use the following macros to compare Sequence Numbers. + * They work correctly for numbers that wrap. + * + * SEQ_GT(x, y) is true if x comes after y by less than 0x80000000. + * 0x80000000 > 0x7fffffff + * 0x00000001 > 0xffffffff + *---------------------------------------------------------------------------*/ +#define SEQ_GT(_x, _y) (((Seq_t)((_x) - (_y))) > 0) +#define SEQ_LT(_x, _y) (((Seq_t)((_x) - (_y))) < 0) +#define SEQ_GE(_x, _y) (((Seq_t)((_x) - (_y))) >= 0) +#define SEQ_LE(_x, _y) (((Seq_t)((_x) - (_y))) <= 0) + +#define SEQ_INVALID 0 +#define SEQ_INC(_x) ((++(_x) == SEQ_INVALID) ? ((_x) = SEQ_INVALID + 1) : (_x)) + +/*--------------------------------------------------------------------------- + * Log sequence numbers are defined to never repeat + *---------------------------------------------------------------------------*/ + +typedef QUAD Lsn_t; + +#define MAX_LSN 0xffffffffffffffff /* All LSNs will be less than + * this (~(QUAD)0) + */ + +/*--------------------------------------------------------------------------- + * Event counters are synchronization primitives. They can only be incremented + * (never decremented). They are typically used in pairs, the reader incrementing + * one and the other incremented by the writer. They rely on atomic writes + * and if used with multiple readers/writers will need atomic increment. + * Even counters must be aligned on SNINT boundaries. Event counters use the + * same primitives for comparisons has sequence numbers but increment is + * the same as other integers unless we are in a multi-reader/writer environment + * where we will need an atomic increment. The first environment we are looking + * at is for a single reader/writer. + *---------------------------------------------------------------------------*/ +typedef struct EventCounter_s +{ + Seq_t in; /* The event counter incremented when entering a + * critical section. + */ + Seq_t out; /* Event counter incremented to synchronize */ +} EventCounter_s; + +#define EV_INIT(_x) ((_x).in = (_x).out = 1) +#define EV_IN(_x) (++((_x).in)) +#define EV_OUT(_x) (++((_x).out)) +#define EV_EQ(_x) ((_x).in == (_x).out) +#define EV_NE(_x) ((_x).in != (_x).out) +#define EV_CHG(_x) (((_x).in - (_x).out) == 1) /* If after doing an EV_IN + * this relation is still + * true, then we went from + * the empty to the not + * empty state and may + * want to do something + * about it. + * Could use == 0 if done + * before operation. + */ + +#define EV_GT(_x, _y) SEQ_GT(_x, _y) +#define EV_LT(_x, _y) SEQ_LT(_x, _y) +#define EV_GE(_x, _y) SEQ_GE(_x, _y) +#define EV_LE(_x, _y) SEQ_LE(_x, _y) + + +/*------------------------------------------------------------------------- + * Name_t is a standard way of assigning a name to an entity or object. + * The name is guaranteed to be null terminated. Need to include + * to use COPY_NAME. + *-------------------------------------------------------------------------*/ +#define MAX_NAME 16 + +typedef char Name_t[MAX_NAME]; + +#define COPY_NAME(_target, _name) \ +{ \ + strncpy((_target), (_name), MAX_NAME); \ + (_target)[MAX_NAME-1] = '\0'; \ +} + + +/*------------------------------------------------------------------------- + * Macros for finding min and max. Be careful that the values plugged in + * for x and y do not have any side affects. + *-------------------------------------------------------------------------*/ +#define zMIN(_x_, _y_) (((_x_) < (_y_)) ? (_x_) : (_y_)) +#define zMAX(_x_, _y_) (((_x_) > (_y_)) ? (_x_) : (_y_)) + +#define ALIGN(_x_, _p_) (((_x_) + (_p_) - 1) & ~((_p_) - 1)) +#define FLOOR(_x_, _p_) ((_x_) - ((_x_) % (_p_))) +#define FLOOR2(_x_, _shift_) (((_x_) >> (_shift_)) << (_shift_)) +#define CEILING(_x_, _p_) (FLOOR((_x_) - 1 + (_p_), (_p_))) +#define MASK(startbit, numbits) (((1 << (numbits)) - 1) << (startbit)) + +/*------------------------------------------------------------------------- + * Macro for determining number of elements in an array. Can only + * be used for 'local' arrays. Arrays that are only known by the + * EXTERN have an unknown sizeof. + *-------------------------------------------------------------------------*/ +#define NELEMS(_array) ( sizeof(_array) / sizeof(_array[0]) ) + +/*------------------------------------------------------------------------- + * Bitmap manipulation instructions. The macros take a bit vector that + * is composed of an array of NINTs for the first argument and a bit + * number in that array for the second argument. + * TST_BIT tests if the bit has been set + * SET_BIT sets the specified bit + * CLR_BIT clears the specified bit + * XOT_BIT complements the specified bit + *-------------------------------------------------------------------------*/ +#ifdef i386 +#define NINTBITS 5 /* log 2 bits per NINT */ +#endif + +#ifdef __x86_64__ +#define NINTBITS 6 /* log 2 bits per NINT */ +#endif + +#if (BITS_PER_NINT != (1 << NINTBITS)) +#error "BITS_PER_NINT doesn't match NINTBITS" +#endif +#define NINTMASK (BITS_PER_NINT - 1) + +#define TST_BIT(_v_, _n_) ((((NINT *)(_v_))[(_n_)>>NINTBITS]) \ + & ((NINT)1<<((_n_) & NINTMASK))) + +#define SET_BIT(_v_, _n_) ((((NINT *)(_v_))[(_n_)>>NINTBITS]) \ + |= ((NINT)1<<((_n_) & NINTMASK))) + +#define CLR_BIT(_v_, _n_) ((((NINT *)(_v_))[(_n_)>>NINTBITS]) \ + &= (~((NINT)1<<((_n_) & NINTMASK)))) + +#define XOR_BIT(_v_, _n_) ((((NINT *)(_v_))[(_n_)>>NINTBITS]) \ + ^= ((NINT)1<<((_n_) & NINTMASK))) + +#define SIZE_BIT_MAP(_n_) (CEILING(_n_, BITS_PER_NINT)/BITS_PER_NINT) + +/*------------------------------------------------------------------------- + * Macro for placing assertions in your code. + * ASSERT - if the expression is not true, AssertError is called which + * stops the system. + * WARN - same as assert but just prints a warning and only prints that + * warning once. Useful for problems that need to be fixed but + * are not fatal at this time. Unlike ASSERT, WARN can not be + * used in an expression. + *------------------------------------------------------------------------*/ +extern int DBG_AssertError(char *); +extern int DBG_AssertError_MP(char *); +extern int DBG_AssertErrorStub(void); +extern int DBG_AssertWarning(char *, int *); +extern void EnterDebugger(void); +extern int DBG_DebugBreak; + +void seedRandQuad (SQUAD x); + +#if NSS_ASSERT IS_ENABLED + +#if zNETWARE || (zLINUX && defined(__KERNEL__)) +#define zASSERT(_e_) \ + ((void)((_e_) || (DBG_AssertError(WHERE " (" # _e_ ")"), \ + (DBG_DebugBreak && (EnterDebugger(), DBG_AssertErrorStub()))))) + +#define ASSERTMP(_e_) \ + ((void)((_e_) || (DBG_AssertError_MP(WHERE " (" # _e_ ")"), \ + (DBG_DebugBreak && (EnterDebugger(), DBG_AssertErrorStub()))))) + +#define WARN(_e_) \ +{ \ + static int numWarnings = 0; \ + ((void)((_e_) || DBG_AssertWarning(WHERE " (" # _e_ ")", &numWarnings))); \ +} +#else + +/* Linux user space - use printf? */ +#define zASSERT(_e_) ((void) 0) +#define zASSERTMP(_e_) ((void) 0) +#define WARN(_e_) ((void) 0) + +#endif + +#else +#define zASSERT(_e_) ((void) 0) +#define zASSERTMP(_e_) ((void) 0) +#define WARN(_e_) ((void) 0) + +#endif + +/*------------------------------------------------------------------------- + * This macro will ASSERT if interrupts are not enabled. + *-------------------------------------------------------------------------*/ +#if ((MPK_REAL IS_DISABLED) && (NSS_DEBUG IS_ENABLED)) + #define CHECK_INTERRUPTS() zASSERT(IntsEnabled()); +#else + #define CHECK_INTERRUPTS() +#endif +/*--------------------------------------------------------------------------- + * This is a special macro we use to make variable length arrays visible + * in the source level debugger. + *---------------------------------------------------------------------------*/ +#if NSS_DEBUG IS_ENABLED +# define DEBUG_VISIBLE_IDX 128 +# define DEBUG_VISIBLE_VALUE 128 +#else +# ifdef __linux__ +# define DEBUG_VISIBLE_IDX 0 +# else +# define DEBUG_VISIBLE_IDX +# endif +# define DEBUG_VISIBLE_VALUE 0 +#endif + +/*------------------------------------------------------------------------- + * Page size definitions + *-------------------------------------------------------------------------*/ +#if defined(PAGE_SHIFT) || defined(PAGE_SIZE) || defined(PAGE_MASK) || defined(PAGES_PER_PAGE) +#undef PAGE_SHIFT +#undef PAGE_SIZE +#undef PAGE_MASK +#undef PAGES_PER_PAGE +#endif + +#define PAGE_SHIFT 12 /* this is for 4K pages*/ +#define PAGE_SIZE (1< +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __GNUC__ +#define NSS_MEDIA_STRUCTURE(_structure,_lastItem) __attribute__((packed)) +#define NSS_MEDIA_UNION(_union,_lastItem) __attribute__((packed)) +#else +#define NSS_MEDIA_STRUCTURE(_structure,_lastItem) +#define NSS_MEDIA_UNION(_union,_lastItem) +#endif + +/*------------------------------------------------------------------------- + * Used to enable/disable various pieces of code. These macros have + * the advantage over normal ifdefs in that you have to either + * specifically enable or disable the code, otherwise, you get a + * syntax error from the preprocessor. + * + * Example: (see que.h for an actual case) + * + * #define FEATURE ENABLE + * #if FEATURE IS_ENABLED + * ... code ... + * #endif + *-------------------------------------------------------------------------*/ +#define ENABLE (1 +#define DISABLE (0 +#define IS_ENABLED ==1) +#define IS_DISABLED ==0) + +/*--------------------------------------------------------------------------- + * Global settings that are independent of different builds + *---------------------------------------------------------------------------*/ +#define NSS_64BIT_SUPPORT ENABLE + +/*------------------------------------------------------------------------- + * Global type definitions + *-------------------------------------------------------------------------*/ +#undef BYTE +#undef WORD +#undef LONG +#undef SLONG +#undef QUAD +#undef ADDR + +#define zNILXID ((Xid_t)0) + +/*------------------------------------------------------------------------- + * Typedefs for quads. Had to add quad_t because UNIX uses _QUAD_T. + *-------------------------------------------------------------------------*/ +#ifndef _QUAD_T +#define _QUAD_T +# if NSS_64BIT_SUPPORT IS_ENABLED +# if defined(__GNUC__) || defined(__MWERKS__) + typedef unsigned long long QUAD; +# else + typedef unsigned __int64 QUAD; +# endif +# else + typedef unsigned int QUAD; +# endif +#endif +//#if !defined(__UQUAD_TYPE) && !defined(__u_char_defined) +// typedef QUAD quad_t; +//#endif + +#ifndef _SQUAD_T +#define _SQUAD_T +# if NSS_64BIT_SUPPORT IS_ENABLED +# if defined(__GNUC__) || defined(__MWERKS__) + typedef long long SQUAD; +# else + typedef __int64 SQUAD; +# endif +# else + typedef signed int SQUAD; +# endif +#endif + +/*------------------------------------------------------------------------- + * Typedefs for basic types + *-------------------------------------------------------------------------*/ +#ifndef _BYTE_T +#define _BYTE_T +#ifndef MPK_H +typedef unsigned char BYTE; /* 8 bit unsigned data item */ +#endif +#endif + +#ifndef _WORD_T +#define _WORD_T +#ifndef MPK_H +typedef unsigned short WORD; /* 16 bit unsigned data item */ +#endif +#endif + +#ifndef _LONG_T +#define _LONG_T +#ifndef MPK_H +typedef unsigned int LONG; /* 32 bit unsigned data item */ +#endif +#endif + +#ifndef _NINT_T +#define _NINT_T +typedef unsigned long NINT; /* Unsigned native data item */ +#endif + +#ifndef _SBYTE_T +#define _SBYTE_T +typedef signed char SBYTE; /* 8 bit signed data item */ +#endif + +#ifndef _SWORD_T +#define _SWORD_T +typedef signed short SWORD; /* 16 bit signed data item */ +#endif + +#ifndef _SLONG_T +#define _SLONG_T +typedef signed int SLONG; /* 32 bit signed data item */ +#endif + +#ifndef _SNINT_T +#define _SNINT_T +typedef signed long SNINT; /* Signed native data item */ +#endif + +#ifndef _ADDR_T +#define _ADDR_T +#ifndef MPK_H +typedef unsigned long ADDR; /* Arithmetic type that can hold a pointer */ +#endif +#endif + +#ifndef _SADDR_T +#define _SADDR_T +typedef long SADDR; /* Signed Arithmetic type for a pointer */ +#endif + + +#ifndef _BOOL_T +#define _BOOL_T +typedef NINT BOOL; /* 0 means FALSE, NON-0 means TRUE*/ +#endif + +#ifndef _UNICODE_T +#define _UNICODE_T +typedef unsigned short unicode_t; /* A UNICODE (UTF-16) character */ +#endif + +#ifndef _UTF8_T +#define _UTF8_T +typedef char utf8_t; /* a UTF-8 character */ +#endif + +#if defined(linux) || defined(__MWERKS__) +# define UI64_CONST(c) c##ULL +# define I64_CONST(c) c##LL +#else +# define UI64_CONST(c) c##UI64 +# define I64_CONST(c) c##I64 +#endif + + +/*------------------------------------------------------------------------- + * In NSS we have the model that functions do NOT return actual error codes. + * They only return zOK and zFAILURE. The real error status is returned in + * the "errno" field of the "GeneralMsg_s" structure. When looking at the + * function return value you must ONLY compare to zOK. Comparing to anything + * else is invalid. + *-------------------------------------------------------------------------*/ +typedef signed int STATUS; /* the type for return status values*/ +#define zOK 0 /* the operation succeeded.*/ +#define zFAILURE -1 /* the operation failed*/ + +/*--------------------------------------------------------------------------- + * Number of bits in each of the various base data sizes + *---------------------------------------------------------------------------*/ +#define BITS_PER_BYTE 8 +#define BITS_PER_WORD 16 +//PJT#define BITS_PER_LONG 32 +#define BITS_PER_QUAD 64 + +#ifdef i386 +#define BITS_PER_NINT 32 +#define BITS_PER_ADDR 32 +#endif + +#ifdef __x86_64__ +#define BITS_PER_NINT 64 +#define BITS_PER_ADDR 64 +#endif + +typedef QUAD Zid_t; /* Znode identifiers*/ + +typedef struct GUID_t /* holds GUIDs*/ +{ + LONG timeLow; + WORD timeMid; + WORD timeHighAndVersion; + BYTE clockSeqHighAndReserved; + BYTE clockSeqLow; + BYTE node[6]; +} NSS_MEDIA_STRUCTURE(GUID_t,node[6]) GUID_t; + +typedef unsigned long DomainID_t; /* domain for object ids from directory services */ +typedef GUID_t VolumeID_t; /* holds a volume ID*/ +typedef GUID_t NDSid_t; /* NDS 128 bit ID*/ +typedef NDSid_t UserID_t; +typedef SQUAD Key_t; /* holds a key */ + /* + * External representation of a token. A token or capability + * is a persistent ID for a file, directory, extended attribute, etc. + * Even though it is an array, we encapsulate it in a structure + * so when we pass it, we can take its address so that it looks + * like we are passing by reference. + */ +#define SIZE_TOKEN 8 /* Size is in QUADs so that it ends up + * quad aligned. + */ +typedef struct Token_t +{ + QUAD token[SIZE_TOKEN]; +} Token_t; + +typedef LONG Time_t; /* Universal Time Coordinated (UTC) + * Time in seconds from January 1, 1970 + * Time_t is placed on media so it must + * be a fixed size (ie LONG (4 bytes)). + * When time_t becomes 64 bits we will + * have to make changes + */ +typedef unsigned long DOSTime_t; /* Time in DOS format, kept in local time + * set to INVALID_TIME if not valid (must + * be converted from UTC time). + */ +typedef SQUAD MSTime_t; /* Time in CIFS SMB format, signed 64 bit + * value which stores the number of 100ns + * intervals from January 1, 1601 + */ + +typedef QUAD Xid_t; /* transaction ID*/ + +#ifdef __cplusplus +typedef void (*voidfunc_t)(...); /* generic void function definition*/ +typedef STATUS (*statusfunc_t)(...);/* generic STATUS return value function definitions*/ +typedef LONG (*longfunc_t)(...); /* generic LONG return value function definition*/ +typedef BOOL (*boolfunc_t)(...); /* generic BOOL return value function definition*/ +#else +typedef void (*voidfunc_t)(); /* generic void function definition*/ +typedef STATUS (*statusfunc_t)(); /* generic STATUS return value function definitions*/ +typedef LONG (*longfunc_t)(); /* generic LONG return value function definition*/ +typedef BOOL (*boolfunc_t)(); /* generic BOOL return value function definition*/ +#endif + +/*--------------------------------------------------------------------------- + * Sequence Numbers have the property that they monotonically increase + * and can be compared even after they wrap. Zero, 0, has been reserved + * as invalid. They are used for transactions and log sequence numbers. + * + * Use the following macros to compare Sequence Numbers. + * They work correctly for numbers that wrap. + * + * SEQ_GT(x, y) is true if x comes after y by less than 0x80000000. + * 0x80000000 > 0x7fffffff + * 0x00000001 > 0xffffffff + *---------------------------------------------------------------------------*/ +typedef SLONG Seq_t; /* Sequence number */ + +/*------------------------------------------------------------------------- + * This defines the sizes that name strings can be in the system. Note + * that these are the sizes of the buffers that hold these string which + * include room for a NULL. You should compare and individual string length + * with one less then these numbers. + *-------------------------------------------------------------------------*/ +#define zMAX_COMPONENT_NAME 256 /* maximum length of an individual component of + * a file name string (like a directory/file + * name) */ + +#define zMAX_FULL_NAME 1024 /* maximum length of a fully qualified file + * name string. This must be + * >= zMAX_COMPONENT_NAME */ + +#ifdef __cplusplus +} +#endif + +#endif /* _ZOMNI_H_ */ diff --git a/include/core/zWhere.h b/include/core/zWhere.h new file mode 100644 index 0000000..b4279ce --- /dev/null +++ b/include/core/zWhere.h @@ -0,0 +1,68 @@ +/**************************************************************************** + | + | (C) Copyright 2006 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | This program is distributed in the hope that it will be useful, + | but WITHOUT ANY WARRANTY; without even the implied warranty of + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + | GNU General Public License for more details. + | + | You should have received a copy of the GNU General Public License + | along with this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) module + | + |--------------------------------------------------------------------------- + | + | $Author: blarsen $ + | $Date: 2006-11-14 16:27:17 -0700 (Tue, 14 Nov 2006) $ + | + | $RCSfile$ + | $Revision: 1644 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Define the WHERE macro for printing file and line number. + +-------------------------------------------------------------------------*/ +#ifndef _ZWHERE_H_ +#define _ZWHERE_H_ 1 + +/*------------------------------------------------------------------------- + * MAGIC_STRING lets the preprocessor convert an integer to a string + * MAKE_STRING provides the level indirection need to fake out the + * the preprocessor + * WHERE a string with both the file name and line number concatenated + * into a single string + *-------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#undef MAGIC_STRING +#undef MAKE_STRING +#undef WHERE + +#define MAGIC_STRING(_x_) # _x_ +#define MAKE_STRING(_x_) MAGIC_STRING(_x_) +#ifdef FNAM_ +#define WHERE FNAM_ "[" MAKE_STRING(__LINE__) "]" +#else +#define WHERE __FILE__ "[" MAKE_STRING(__LINE__) "]" +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3eaf256..4a2831e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -31,6 +31,26 @@ configure_file( "${CMAKE_SOURCE_DIR}/include/core/core.h" "${NWCORE_BUILD_INCLUDE_DIR}/core.h" COPYONLY) +configure_file( + "${CMAKE_SOURCE_DIR}/include/core/zWhere.h" + "${NWCORE_BUILD_INCLUDE_DIR}/zWhere.h" + COPYONLY) +configure_file( + "${CMAKE_SOURCE_DIR}/include/core/zOmni.h" + "${NWCORE_BUILD_INCLUDE_DIR}/zOmni.h" + COPYONLY) +configure_file( + "${CMAKE_SOURCE_DIR}/include/core/omni.h" + "${NWCORE_BUILD_INCLUDE_DIR}/omni.h" + COPYONLY) +configure_file( + "${CMAKE_SOURCE_DIR}/include/core/bitmap.h" + "${NWCORE_BUILD_INCLUDE_DIR}/bitmap.h" + COPYONLY) +configure_file( + "${CMAKE_SOURCE_DIR}/include/core/size_t.h" + "${NWCORE_BUILD_INCLUDE_DIR}/size_t.h" + COPYONLY) configure_file( "${NWCORE_ZLOG_DIR}/src/zlog.h" "${NWCORE_BUILD_INCLUDE_DIR}/zlog.h" @@ -70,6 +90,7 @@ target_include_directories(nwcore "$" "$" PRIVATE + "${CMAKE_SOURCE_DIR}/include/core" "${NWCORE_ZLOG_DIR}/src" "${NWCORE_YYJSON_DIR}/src") diff --git a/src/core/bitmap.c b/src/core/bitmap.c index 446b587..b45de57 100644 --- a/src/core/bitmap.c +++ b/src/core/bitmap.c @@ -49,6 +49,8 @@ #define zalloc(_bytes) calloc(1, (_bytes)) #endif +/* Direct core imports of the original NSS headers; reference copies remain + * under include/nwfs/nss/sdk/... for SDK/source-audit compatibility. */ #include "omni.h" #include "bitmap.h"