2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #ifndef __CM_DIR_ENV__
11 #define __CM_DIR_ENV__ 1
13 /* These data structures are derived from src/dir/dir.h and should not
14 * be changed as they describe AFS3 wire protocol.
18 #define CM_DIR_PAGESIZE 2048 /* bytes per page */
19 #define CM_DIR_NHASHENT 128 /* entries in the dir hash tbl */
20 #define CM_DIR_MAXPAGES 128 /* max pages in a dir */
21 #define CM_DIR_BIGMAXPAGES 1023 /* new big max pages */
22 #define CM_DIR_EPP 64 /* dir entries per page */
23 #define CM_DIR_LEPP 6 /* log above */
24 #define CM_DIR_CHUNKSIZE 32 /* bytes per dir entry chunk */
26 /* When this next field changs, it is crucial to modify MakeDir, since the latter is
27 * responsible for marking these entries as allocated. Also change
30 #define CM_DIR_DHE 12 /* entries in a dir header above a pages
34 #define CM_DIR_FFIRST 1
35 #define CM_DIR_FNEXT 2
37 typedef struct cm_dirFid {
38 /* A file identifier. */
39 afs_int32 vnode; /* file's vnode slot */
40 afs_int32 unique; /* the slot incarnation number */
43 typedef struct cm_pageHeader {
44 /* A page header entry. */
45 unsigned short pgcount; /* number of pages, or 0 if old-style */
46 unsigned short tag; /* '1234' in network byte order */
47 char freeCount; /* unused, info in dirHeader structure */
48 char freeBitmap[CM_DIR_EPP/8];
49 char padding[CM_DIR_CHUNKSIZE-(5+CM_DIR_EPP/8)];/* pad to one 32-byte entry */
52 /* a total of 13 32-byte entries, 1 for the header that in all pages, and
53 * 12 more special ones for the entries in a the first page.
55 typedef struct cm_dirHeader {
56 /* A directory header object. */
57 cm_pageHeader_t header;
58 char alloMap[CM_DIR_MAXPAGES]; /* one byte per 2K page */
59 unsigned short hashTable[CM_DIR_NHASHENT];
62 /* this represents a directory entry. We use strlen to find out how
63 * many bytes are really in the dir entry; it is always a multiple of
66 typedef struct cm_dirEntry {
67 /* A directory entry */
68 char flag; /* this must be FFIRST (1) */
69 char length; /* currently unused */
72 char name[1]; /* the real length is determined with strlen() */
76 typedef struct cm_dirXEntry {
77 /* A directory extension entry. */
81 typedef struct cm_dirPage0 {
82 /* A page in a directory. */
83 cm_dirHeader_t header;
84 cm_dirEntry_t entry[1];
87 typedef struct cm_dirPage1 {
88 /* A page in a directory. */
89 cm_pageHeader_t header;
90 cm_dirEntry_t entry[1];
94 #define CM_DIROP_MAXBUFFERS 8
96 typedef struct cm_dirOpBuffer {
102 #define CM_DIROPBUFF_INUSE 0x1
104 #define CM_DIRLOCK_NONE 0x0
105 #define CM_DIRLOCK_READ 0x1
106 #define CM_DIRLOCK_WRITE 0x2
108 /* Used for managing transactional directory operations. Each
109 instance should only be used by one thread. */
110 typedef struct cm_dirOp {
116 osi_hyper_t length; /* scp->length at the time
117 cm_BeginDirOp() was called.*/
118 osi_hyper_t newLength; /* adjusted scp->length */
119 afs_uint64 dataVersion; /* scp->dataVersion when
120 cm_BeginDirOp() was called.*/
121 afs_uint64 newDataVersion; /* scp->dataVersion when
122 cm_CheckDirOpForSingleChange()
125 afs_uint64 dirtyBufCount;
127 afs_uint64 nBuffers; /* number of buffers below */
128 cm_dirOpBuffer_t buffers[CM_DIROP_MAXBUFFERS];
132 cm_BeginDirOp(cm_scache_t * scp, cm_user_t * userp, cm_req_t * reqp,
133 afs_uint32 lockType, cm_dirOp_t * op);
136 cm_CheckDirOpForSingleChange(cm_dirOp_t * op);
139 cm_EndDirOp(cm_dirOp_t * op);
142 cm_NameEntries(char *namep, long *lenp);
145 cm_DirCreateEntry(cm_dirOp_t * op, char *entry, cm_fid_t * cfid);
148 cm_DirLength(cm_dirOp_t * op);
151 cm_DirDeleteEntry(cm_dirOp_t * op, char *entry);
154 cm_DirMakeDir(cm_dirOp_t * op, cm_fid_t * me, cm_fid_t * parent);
157 cm_DirLookup(cm_dirOp_t * op, char *entry, cm_fid_t * cfid);
160 cm_DirLookupOffset(cm_dirOp_t * op, char *entry, cm_fid_t *cfid, osi_hyper_t *offsetp);
163 cm_DirApply(cm_dirOp_t * op, int (*hookproc) (void *, char *, long, long), void *hook);
166 cm_DirIsEmpty(cm_dirOp_t * op);
169 cm_DirHash(char *string);
171 /* Directory entry lists */
172 typedef struct cm_dirEntryList {
173 struct cm_dirEntryList * nextp;
178 cm_DirEntryListAdd(char * namep, cm_dirEntryList_t ** list);
181 cm_DirEntryListFree(cm_dirEntryList_t ** list);
184 cm_DirDumpStats(void);
187 cm_MemDumpDirStats(FILE *outputFile, char *cookie, int lock);
189 extern afs_uint64 dir_enums;
190 #endif /* __CM_DIR_ENV__ */