OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/WINNT/afsd/cm_dir.h
00001 /*
00002  * Copyright 2000, International Business Machines Corporation and others.
00003  * All Rights Reserved.
00004  *
00005  * This software has been released under the terms of the IBM Public
00006  * License.  For details, see the LICENSE file in the top-level source
00007  * directory or online at http://www.openafs.org/dl/license10.html
00008  */
00009 
00010 #ifndef OPENAFS_WINNT_AFSD_CM_DIR_H
00011 #define OPENAFS_WINNT_AFSD_CM_DIR_H 1
00012 
00013 /* These data structures are derived from src/dir/dir.h and should not
00014  * be changed as they describe AFS3 wire protocol.
00015  *
00016  */
00017 
00018 #define CM_DIR_PAGESIZE         2048            /* bytes per page */
00019 #define CM_DIR_NHASHENT         128             /* entries in the dir hash tbl */
00020 #define CM_DIR_MAXPAGES         128             /* max pages in a dir */
00021 #define CM_DIR_BIGMAXPAGES      1023            /* new big max pages */
00022 #define CM_DIR_EPP              64              /* dir entries per page */
00023 #define CM_DIR_LEPP             6               /* log above */
00024 #define CM_DIR_CHUNKSIZE        32              /* bytes per dir entry chunk */
00025 
00026 /* When this next field changs, it is crucial to modify MakeDir, since the latter is
00027  * responsible for marking these entries as allocated.  Also change
00028  * the salvager.
00029  */
00030 #define CM_DIR_DHE              12              /* entries in a dir header above a pages
00031                                                  * header alone.
00032                                                  */
00033 
00034 #define CM_DIR_FFIRST           1
00035 #define CM_DIR_FNEXT            2
00036 
00037 typedef struct cm_dirFid {
00038         /* A file identifier. */
00039         afs_int32 vnode;        /* file's vnode slot */
00040         afs_int32 unique;       /* the slot incarnation number */
00041 } cm_dirFid_t;
00042 
00043 typedef struct cm_pageHeader {
00044         /* A page header entry. */
00045         unsigned short pgcount; /* number of pages, or 0 if old-style */
00046         unsigned short tag;             /* '1234' in network byte order */
00047         char freeCount; /* unused, info in dirHeader structure */
00048         char freeBitmap[CM_DIR_EPP/8];
00049         char padding[CM_DIR_CHUNKSIZE-(5+CM_DIR_EPP/8)];/* pad to one 32-byte entry */
00050 } cm_pageHeader_t;
00051 
00052 /* a total of 13 32-byte entries, 1 for the header that in all pages, and
00053  * 12 more special ones for the entries in a the first page.
00054  */
00055 typedef struct cm_dirHeader {
00056         /* A directory header object. */
00057         cm_pageHeader_t header;
00058         char alloMap[CM_DIR_MAXPAGES];    /* one byte per 2K page */
00059         unsigned short hashTable[CM_DIR_NHASHENT];
00060 } cm_dirHeader_t;
00061 
00062 /* this represents a directory entry.  We use strlen to find out how
00063  * many bytes are really in the dir entry; it is always a multiple of
00064  * 32.
00065  */
00066 typedef struct cm_dirEntry {
00067         /* A directory entry */
00068         char flag;      /* this must be FFIRST (1) */
00069         char length;    /* currently unused */
00070         unsigned short next;
00071         cm_dirFid_t fid;
00072         char name[1];   /* the real length is determined with strlen() */
00073 } cm_dirEntry_t;
00074 
00075 #ifdef UNUSED
00076 typedef struct cm_dirXEntry {
00077         /* A directory extension entry. */
00078         char name[32];
00079 } cm_dirXEntry_t;
00080 
00081 typedef struct cm_dirPage0 {
00082         /* A page in a directory. */
00083         cm_dirHeader_t header;
00084         cm_dirEntry_t entry[1];
00085 } cm_dirPage0_t;
00086 
00087 typedef struct cm_dirPage1 {
00088         /* A page in a directory. */
00089         cm_pageHeader_t header;
00090         cm_dirEntry_t entry[1];
00091 } cm_dirPage1_t;
00092 #endif /* UNUSED */
00093 
00094 #define CM_DIROP_MAXBUFFERS 8
00095 
00096 typedef struct cm_dirOpBuffer {
00097     int        flags;
00098     cm_buf_t * bufferp;
00099     int        refcount;
00100 } cm_dirOpBuffer_t;
00101 
00102 #define CM_DIROPBUFF_INUSE      0x1
00103 
00104 /* lock types */
00105 #define CM_DIRLOCK_NONE         0x0
00106 #define CM_DIRLOCK_READ         0x1
00107 #define CM_DIRLOCK_WRITE        0x2
00108 
00109 /* flags for cm_dirOp operations */
00110 #define CM_DIROP_FLAG_NONE         0x0000
00111 #define CM_DIROP_FLAG_NOBUILDTREE  0x0001
00112 
00113 /* Used for managing transactional directory operations.  Each
00114    instance should only be used by one thread. */
00115 typedef struct cm_dirOp {
00116     int           lockType;
00117     cm_scache_t * scp;
00118     cm_user_t *   userp;
00119     cm_req_t      req;
00120 
00121     osi_hyper_t   length;       /* scp->length at the time
00122                                    cm_BeginDirOp() was called.*/
00123     osi_hyper_t   newLength;    /* adjusted scp->length */
00124     afs_uint64    dataVersion;  /* scp->dataVersion when
00125                                    cm_BeginDirOp() was called.*/
00126     afs_uint64    newDataVersion; /* scp->dataVersion when
00127                                      cm_CheckDirOpForSingleChange()
00128                                      was called. */
00129 
00130     afs_uint64    dirtyBufCount;
00131 
00132     afs_uint64    nBuffers;     /* number of buffers below */
00133     cm_dirOpBuffer_t buffers[CM_DIROP_MAXBUFFERS];
00134 } cm_dirOp_t;
00135 
00136 extern long
00137 cm_BeginDirOp(cm_scache_t * scp, cm_user_t * userp, cm_req_t * reqp,
00138               afs_uint32 lockType, afs_uint32 flags, cm_dirOp_t * op);
00139 
00140 extern int
00141 cm_CheckDirOpForSingleChange(cm_dirOp_t * op);
00142 
00143 extern long
00144 cm_EndDirOp(cm_dirOp_t * op);
00145 
00146 extern long
00147 cm_NameEntries(char *namep, size_t *lenp);
00148 
00149 extern long
00150 cm_DirCreateEntry(cm_dirOp_t * op, char *entry, cm_fid_t * cfid);
00151 
00152 extern int
00153 cm_DirLength(cm_dirOp_t * op);
00154 
00155 extern int
00156 cm_DirDeleteEntry(cm_dirOp_t * op, char *entry);
00157 
00158 extern int
00159 cm_DirMakeDir(cm_dirOp_t * op, cm_fid_t * me, cm_fid_t * parent);
00160 
00161 extern int
00162 cm_DirLookup(cm_dirOp_t * op, char *entry, cm_fid_t * cfid);
00163 
00164 extern int
00165 cm_DirLookupOffset(cm_dirOp_t * op, char *entry, cm_fid_t *cfid, osi_hyper_t *offsetp);
00166 
00167 extern int
00168 cm_DirApply(cm_dirOp_t * op, int (*hookproc) (void *, char *, long, long), void *hook);
00169 
00170 extern int
00171 cm_DirIsEmpty(cm_dirOp_t * op);
00172 
00173 extern int
00174 cm_DirHash(char *string);
00175 
00176 /* Directory entry lists */
00177 typedef struct cm_dirEntryList {
00178     struct cm_dirEntryList * nextp;
00179     char   name[1];
00180 } cm_dirEntryList_t;
00181 
00182 extern void
00183 cm_DirEntryListAdd(char * namep, cm_dirEntryList_t ** list);
00184 
00185 extern void
00186 cm_DirEntryListFree(cm_dirEntryList_t ** list);
00187 
00188 extern void
00189 cm_DirDumpStats(void);
00190 
00191 extern int
00192 cm_MemDumpDirStats(FILE *outputFile, char *cookie, int lock);
00193 
00194 extern afs_uint64 dir_enums;
00195 
00196 #endif /*  OPENAFS_WINNT_AFSD_CM_DIR_H */
 All Data Structures Files Functions Variables