Files
mars-nwe/include/nwnss/comnSA/fileHandle.h
2026-06-15 18:48:18 +02:00

314 lines
10 KiB
C

/****************************************************************************
|
| (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: taysom $
| $Date: 2007-02-13 21:40:53 +0530 (Tue, 13 Feb 2007) $
|
| $RCSfile$
| $Revision: 1853 $
|
|---------------------------------------------------------------------------
| This module is used to:
| This defines the interfaces into the PSS portion of the connection
| structure.
|
| 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 _FILEHANDLE_H_
#define _FILEHANDLE_H_
#ifndef _COMNPARAMS_H_
#include <comnParams.h>
#endif
#ifndef _NSS_MSG_H_
#include <msg.h>
#endif
#ifndef _FSMSG_H_
#include <fsmsg.h>
#endif
#ifndef _UTC_H_
#include <utc.h>
#endif
#ifndef _HARDLINK_H_
#include <hardLinkBeast.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_READAHEAD 8 /* Maximum number of blocks we can read ahead */
/* NOTE: if you make this bigger, you'll have
* to change the definition of blocksRead in
* FileHandle_s.
*/
#define MIN_READAHEAD 0 /* Level to trigger more readahead */
/* Pre-define struct(s) so Linux compiler doesn't complain */
struct Master_s;
/*-------------------------------------------------------------------------
* One of these structures are allocated for each open file in the system.
*-------------------------------------------------------------------------*/
struct FileHandle_s
{
mDoor_s door; /* A door object with a key */
DQlink_t bstLink; /* Linked list of handles for a specific beast */
File_s *file; /* the file for the open file */
HardLinkBeast_s *hlFile; /* if non-zero, pointer to hardlink beast that was parsed while opening this file */
NamedBeast_s *dataStream; /* the dataStream ptr for the open file */
RootBeast_s *compBeast; /* Compressed beast for this datastream
* Valid only when reading/writing compressed
* stream */
Zid_t fileParentZid; /* The ZID of the file's parent container */
NINT fileNameUniquifier; /* Name uniquifier for the dirFile */
// QUAD key; /* the key for this handle */
/* The key for this handle: fh->obj.door.key */
LONG taskID; /* task this file is assoicated with */
NINT grantedRights; /* rights granted for this opened file */
BYTE fileNameSpaceID; /* the nameSpace the file was looked up in */
BYTE fileNameType; /* The nameType the file was looked up in */
BYTE dataStreamNameSpaceID; /* the nameSpace the dataStream was opened in*/
BYTE dataStreamNameType; /* The nameType the dataStream was opened in*/
WORD fhState; /* state of the fileHandle */
WORD parentIsImmCompress; /* Immediate Compress flag is set on
* parent Directory */
// WORD cm_closeAction; /* Compression-related action to perform
// * on COMN_Close; Opcodes in cmNSS.h */
VirtInfo_s *virtInfo; /* pointer to info for a virtual file */
NSSConnection_s *pssConn; /* pss connection structure pointer */
LONG connID; /* Connection ID */
LONG semanticAgentID; /* semantic agent which owns this handle */
Blknum_t readAheadBlk; /* readahead block number */
Blknum_t lastBlkRead; /* are we doing sequential or random reads */
/* on this file */
Time_t openedTime; /* Time the file was opened */
struct SearchMap_s *smap; /* Search map */
struct OpLock_s *opLock; /* Callback info for opLocks */
NINT enterExitID; /* NEB uses this to send the exit event */
STATUS enterRetStatus; /* NEB uses this to send the exit event */
DQhead_t fhWaiters; /* open requests that is blocked because of */
/* conflicting file lock held by this handle*/
struct inode *fh_inode; /* Inode this fh got a count on */
struct CROAccessLease_s *FH_accessLease; /* If volume is a slave, then
* the access lease that this
* fH is using
*/
struct CsaVolumeDoor_s *FH_csaVolObj; /* When on Master and state
* is FH_CFS_OPEN, this
* points to the CSAVolObj
* identifying the slave that
* that opened this file.
*/
FsmLite_s FH_asyncCloseFsm; /* FSM used to do Async closes
* for Virtual opens from the
* slave
*/
};
#define FH_INIT_NEW_FILEHANDLE(_fh) \
{ \
DQ_INIT(&(_fh)->fhWaiters); \
(_fh)->FH_accessLease = NULL; \
(_fh)->FH_csaVolObj = NULL; \
(_fh)->virtInfo = NULL; \
(_fh)->smap = NULL; \
(_fh)->openedTime = GetUTCTime(); \
(_fh)->readAheadBlk = 0; \
(_fh)->lastBlkRead = 0; \
(_fh)->fhState = FH_NEW; \
(_fh)->compBeast = NULL; \
(_fh)->parentIsImmCompress = 0; \
(_fh)->hlFile = 0; \
(_fh)->fh_inode = 0; \
FSMLITE_INIT(&(_fh)->FH_asyncCloseFsm, MSGNot("Async Close FSM"), 0); \
}
/************************************************************************
* States of the fileHandle as set in fhState
***********************************************************************/
#define FH_NEW 0x00
#define FH_MODIFIED 0x01
#define FH_WRITE_SNAPSHOT 0x02
#define FH_READ_BACKUP 0x04
#define FH_NDS_OPEN 0x08
#define FH_CFS_OPEN 0x10 /* The open was done for a CFS slave on
* the master.
*/
#define FH_CFS_ASYNC_CLOSE 0x20 /* Pre-Close -- decrementing the
* the grantedRights counts has been
* done synchronously, now do the
* async part of the close
*/
/*
* Support for the file handle type
*/
typedef struct FileHandleType_s
{
mTypeHeader_s hdr;
statusfunc_t method[NSS_NUM_METHODS];
} FileHandleType_s;
extern FileHandleType_s NormalFileType;
extern FileHandleType_s InternalEAHandleType;
extern FileHandleType_s MigratedType;
extern FileHandleType_s VirtualType;
/*---------------------------------------------------------------------------
* Internal Common Layer Prototypes for working with file handles
*---------------------------------------------------------------------------*/
extern Key_t EA_Open(
struct Master_s *master,
struct File_s *eafile,
struct NamedBeast_s *eabeast,
NINT rights);
extern STATUS FH_msgOpenMigratedFile(
File_s *file,
NamedBeast_s *dateStream,
Key_t *retKey);
extern STATUS FH_OpenFile(
GeneralMsg_s *genMsg,
FileHandleIDP_s *fhIDP,
NamingMsg_s *nameMsg,
BYTE fhState);
extern STATUS FH_RemoveOpenFileFromList(
GeneralMsg_s *genMsg,
FileHandleIDP_s *fhIDP);
extern BOOL FH_FreeOpenFile(
FileHandle_s *fileHandle);
extern STATUS FH_SetOpenFileGrantedRights(
GeneralMsg_s *genMsg,
OpenMsg_s *openMsg,
FileHandleIDP_s *fhIDP,
NINT grantedRights);
extern void FH_DecrementRightCounts (
FileHandle_s *fileHandle);
extern void FH_CloseAllFilesOnConnectionTask(
GeneralMsg_s *genMsg,
NSSConnection_s *pssConn);
extern void FH_CloseAllFilesOnVolume(
Volume_s *vol);
extern void FH_CloseAllSAgentFilesOnVolume(
GeneralMsg_s *genMsg,
Volume_s *vol);
extern NINT FH_ListOpenSAgentFilesOnVolume(
GeneralMsg_s *genMsg,
Volume_s *vol);
extern void FH_FixupAllFileHandlesOnBeast(
GeneralMsg_s *genMsg,
NamedBeast_s *file,
NamedBeast_s *oldDir,
NamedBeast_s *newDir,
// cnt NINT oldNameUniquifier,
// cnt NINT newNameUniquifier,
NINT newNameType);
extern BOOL FH_OpenFileMayNotBeDeleted(
GeneralMsg_s *genMsg,
NamedBeast_s *file);
void FH_CloseAllFilesForTask(
struct Master_s *master,
NINT taskID);
BOOL FH_DenyWriteMandatory(
NamedBeast_s *beast);
void resumeOpen(
OpenWaiting_s *candidate);
void cancelOpen(
OpenWaiting_s **candidate);
BOOL FH_RequestedRightsInConflict(NINT fhRights, NINT rights);
BOOL FH_AreRightsCompatible(NamedBeast_s *dataStream, NINT rights);
void FH_AddRights(NamedBeast_s *dataStream, NINT rights);
void FH_DeleteRights(FileHandle_s *fileHandle);
extern Key_t hackKey(Key_t key);
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(_major, _minor, _patch) (((_major) << 16) + ((_minor) << 8) + (_patch))
#endif
#ifndef LINUX_VERSION_CODE
#define LINUX_VERSION_CODE KERNEL_VERSION(2,6,32)
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6))
#define CONN_KEY(_connNum, _nwHandle) ((((Key_t)(_connNum)) << 32) \
| (_nwHandle))
#else
#define MASK_HACK_KEY 0xfffffffe
#define CONN_KEY(_connNum, _nwHandle) ((((Key_t)(_connNum)) << 32) \
| ((_nwHandle) & MASK_HACK_KEY))
#endif
#define FH_HAS_DENY_WRITE_COUNT(_beast) \
(((NamedBeast_s *)(_beast))->NAMEDdenyWriterCount != 0) \
#define FILE_LOCK_ERROR(_status) \
(((_status) == zERR_CANT_DENY_READ_LOCK) || \
((_status) == zERR_FILE_READ_LOCKED) || \
((_status) == zERR_CANT_DENY_WRITE_LOCK) || \
((_status) == zERR_FILE_WRITE_LOCKED)) \
#ifdef __cplusplus
}
#endif
#endif /* _FILEHANDLE_H_ */