1 /* Access.h v1.3 Definitions for file access routines */ 2 3 /* 4 This is part of ODS2 written by Paul Nankervis, 5 email address: Paulnank@au1.ibm.com 6 7 ODS2 is distributed freely for all members of the 8 VMS community to use. However all derived works 9 must maintain comments in their source to acknowledge 10 the contibution of the original author. 11 */ 12 13 #define NO_DOLLAR 14 #include "cache.h" 15 #include "vmstime.h" 16 17 #ifdef BIG_ENDIAN 18 #define VMSLONG(l) ((l & 0xff) << 24 | (l & 0xff00) << 8 | (l & 0xff0000) >> 8 | l >> 24) 19 #define VMSWORD(w) ((w & 0xff) << 8 | w >> 8) 20 #define VMSSWAP(l) ((l & 0xff0000) << 8 | (l & 0xff000000) >> 8 |(l & 0xff) << 8 | (l & 0xff00) >> 8) 21 #else 22 #define VMSLONG(l) l 23 #define VMSWORD(w) w 24 #define VMSSWAP(l) ((l & 0xffff) << 16 | l >> 16) 25 #endif 26 27 typedef unsigned char vmsbyte; 28 typedef unsigned short vmsword; 29 typedef unsigned int vmsswap; 30 typedef unsigned int vmslong; 31 32 #define FH2$M_NOBACKUP 0x2 33 #define FH2$M_CONTIG 0x80 34 #define FH2$M_DIRECTORY 0x2000 35 #define FH2$M_MARKDEL 0x8000 36 #define FH2$M_ERASE 0x20000 37 38 #ifdef __ALPHA 39 #pragma member_alignment save 40 #pragma nomember_alignment 41 #endif 42 43 struct UIC { 44 vmsword uic$w_mem; 45 vmsword uic$w_grp; 46 }; 47 48 49 struct fiddef { 50 vmsword fid$w_num; 51 vmsword fid$w_seq; 52 vmsbyte fid$b_rvn; 53 vmsbyte fid$b_nmx; 54 }; 55 56 57 struct RECATTR { 58 vmsbyte fat$b_rtype; 59 vmsbyte fat$b_rattrib; 60 vmsword fat$w_rsize; 61 vmsswap fat$l_hiblk; 62 vmsswap fat$l_efblk; 63 vmsword fat$w_ffbyte; 64 vmsbyte fat$b_bktsize; 65 vmsbyte fat$b_vfcsize; 66 vmsword fat$w_maxrec; 67 vmsword fat$w_defext; 68 vmsword fat$w_gbc; 69 vmsbyte fat$_UU0[8]; 70 vmsword fat$w_versions; 71 }; 72 73 74 struct HOME { 75 vmslong hm2$l_homelbn; 76 vmslong hm2$l_alhomelbn; 77 vmslong hm2$l_altidxlbn; 78 vmsword hm2$w_struclev; 79 vmsword hm2$w_cluster; 80 vmsword hm2$w_homevbn; 81 vmsword hm2$w_alhomevbn; 82 vmsword hm2$w_altidxvbn; 83 vmsword hm2$w_ibmapvbn; 84 vmslong hm2$l_ibmaplbn; 85 vmslong hm2$l_maxfiles; 86 vmsword hm2$w_ibmapsize; 87 vmsword hm2$w_resfiles; 88 vmsword hm2$w_devtype; 89 vmsword hm2$w_rvn; 90 vmsword hm2$w_setcount; 91 vmsword hm2$w_volchar; 92 struct UIC hm2$w_volowner; 93 vmslong hm2$l_reserved1; 94 vmsword hm2$w_protect; 95 vmsword hm2$w_fileprot; 96 vmsword hm2$w_reserved2; 97 vmsword hm2$w_checksum1; 98 VMSTIME hm2$q_credate; 99 vmsbyte hm2$b_window; 100 vmsbyte hm2$b_lru_lim; 101 vmsword hm2$w_extend; 102 VMSTIME hm2$q_retainmin; 103 VMSTIME hm2$q_retainmax; 104 VMSTIME hm2$q_revdate; 105 vmsbyte hm2$r_min_class[20]; 106 vmsbyte hm2$r_max_class[20]; 107 vmsbyte hm2$t_reserved3[320]; 108 vmslong hm2$l_serialnum; 109 char hm2$t_strucname[12]; 110 char hm2$t_volname[12]; 111 char hm2$t_ownername[12]; 112 char hm2$t_format[12]; 113 vmsword hm2$w_reserved4; 114 vmsword hm2$w_checksum2; 115 }; 116 117 118 struct IDENT { 119 char fi2$t_filename[20]; 120 vmsword fi2$w_revision; 121 VMSTIME fi2$q_credate; 122 VMSTIME fi2$q_revdate; 123 VMSTIME fi2$q_expdate; 124 VMSTIME fi2$q_bakdate; 125 char fi2$t_filenamext[66]; 126 }; 127 128 129 struct HEAD { 130 vmsbyte fh2$b_idoffset; 131 vmsbyte fh2$b_mpoffset; 132 vmsbyte fh2$b_acoffset; 133 vmsbyte fh2$b_rsoffset; 134 vmsword fh2$w_seg_num; 135 vmsword fh2$w_struclev; 136 struct fiddef fh2$w_fid; 137 struct fiddef fh2$w_ext_fid; 138 struct RECATTR fh2$w_recattr; 139 vmslong fh2$l_filechar; 140 vmsword fh2$w_reserved1; 141 vmsbyte fh2$b_map_inuse; 142 vmsbyte fh2$b_acc_mode; 143 struct UIC fh2$l_fileowner; 144 vmsword fh2$w_fileprot; 145 struct fiddef fh2$w_backlink; 146 vmsbyte fh2$b_journal; 147 vmsbyte fh2$b_ru_active; 148 vmsword fh2$w_reserved2; 149 vmslong fh2$l_highwater; 150 vmsbyte fh2$b_reserved3[8]; 151 vmsbyte fh2$r_class_prot[20]; 152 vmsbyte fh2$r_restofit[402]; 153 vmsword fh2$w_checksum; 154 }; 155 156 struct SCB { 157 vmsword scb$w_struclev; 158 vmsword scb$w_cluster; 159 vmslong scb$l_volsize; 160 vmslong scb$l_blksize; 161 vmslong scb$l_sectors; 162 vmslong scb$l_tracks; 163 vmslong scb$l_cylinders; 164 vmslong scb$l_status; 165 vmslong scb$l_status2; 166 vmsword scb$w_writecnt; 167 char scb$t_volockname[12]; 168 VMSTIME scb$q_mounttime; 169 vmsword scb$w_backrev; 170 vmslong scb$q_genernum[2]; 171 char scb$b_reserved[446]; 172 vmsword scb$w_checksum; 173 }; 174 175 #ifdef __ALPHA 176 #pragma member_alignment restore 177 #endif 178 179 #define EXTMAX 20 180 181 struct WCB { 182 struct CACHE cache; 183 unsigned loblk,hiblk; /* Range of window */ 184 unsigned hd_basevbn; /* File blocks prior to header */ 185 unsigned hd_seg_num; /* Header segment number */ 186 struct fiddef hd_fid; /* Header FID */ 187 unsigned short extcount; /* Extents in use */ 188 unsigned phylen[EXTMAX]; 189 unsigned phyblk[EXTMAX]; 190 unsigned char rvn[EXTMAX]; 191 }; /* Window control block */ 192 193 194 #define VIOC_CHUNKSIZE 4 195 196 struct VIOC { 197 struct CACHE cache; 198 struct FCB *fcb; /* File this chunk is for */ 199 unsigned wrtmask; /* Bit mask for writable blocks */ 200 unsigned modmask; /* Bit mask for modified blocks */ 201 char data[VIOC_CHUNKSIZE][512]; /* Chunk data */ 202 }; /* Chunk of a file */ 203 204 205 #define FCB_WRITE 1 /* FCB open for write... */ 206 207 struct FCB { 208 struct CACHE cache; 209 struct VCB *vcb; /* Volume this file is for */ 210 struct VIOC *headvioc; /* Index file chunk for file header */ 211 struct HEAD *head; /* Pointer to header block */ 212 struct WCB *wcb; /* Window control block tree */ 213 struct VIOC *vioc; /* Virtual I/O chunk tree */ 214 unsigned headvbn; /* vbn for file header */ 215 unsigned hiblock; /* Highest block mapped */ 216 unsigned highwater; /* First high water block */ 217 unsigned char status; /* FCB status bits */ 218 unsigned char rvn; /* Initial file relative volume */ 219 }; /* File control block */ 220 221 222 struct DIRCACHE { 223 struct CACHE cache; 224 int dirlen; /* Length of directory name */ 225 struct fiddef dirid; /* File ID of directory */ 226 char dirnam[1]; /* Directory name */ 227 }; /* Directory cache entry */ 228 229 230 #define VCB_WRITE 1 231 232 struct VCB { 233 unsigned status; /* Volume status */ 234 unsigned devices; /* Number of volumes in set */ 235 struct FCB *fcb; /* File control block tree */ 236 struct DIRCACHE *dircache; /* Directory cache tree */ 237 struct VCBDEV { 238 struct DEV *dev; /* Pointer to device info */ 239 struct FCB *idxfcb; /* Index file control block */ 240 struct FCB *mapfcb; /* Bitmap file control block */ 241 unsigned clustersize; /* Cluster size of the device */ 242 unsigned max_cluster; /* Total clusters on the device */ 243 unsigned free_clusters; /* Free clusters on disk volume */ 244 struct HOME home; /* Volume home block */ 245 } vcbdev[1]; /* List of volumes devices */ 246 }; /* Volume control block */ 247 248 249 struct DEV { 250 struct CACHE cache; 251 struct VCB *vcb; /* Pointer to volume (if mounted) */ 252 unsigned handle; /* Device physical I/O handle */ 253 unsigned status; /* Device physical status */ 254 unsigned sectors; /* Device physical sectors */ 255 unsigned sectorsize; /* Device physical sectorsize */ 256 char devnam[1]; /* Device name */ 257 }; /* Device information */ 258 259 void fid_copy(struct fiddef *dst,struct fiddef *src,unsigned rvn); 260 unsigned device_lookup(unsigned devlen,char *devnam,int create,struct DEV **retdev); 261 262 unsigned dismount(struct VCB *vcb); 263 unsigned mount(unsigned flags,unsigned devices,char *devnam[],char *label[],struct VCB **vcb); 264 265 unsigned accesserase(struct VCB *vcb,struct fiddef *fid); 266 unsigned deaccessfile(struct FCB *fcb); 267 unsigned accessfile(struct VCB *vcb,struct fiddef *fid, 268 struct FCB **fcb,unsigned wrtflg); 269 270 unsigned deaccesschunk(struct VIOC *vioc,unsigned wrtvbn,int wrtblks,int reuse); 271 unsigned accesschunk(struct FCB *fcb,unsigned vbn,struct VIOC **retvioc, 272 char **retbuff,unsigned *retblocks,unsigned wrtblks); 273 unsigned access_extend(struct FCB *fcb,unsigned blocks,unsigned contig); 274 unsigned update_freecount(struct VCBDEV *vcbdev,unsigned *retcount); 275 unsigned update_create(struct VCB *vcb,struct fiddef *did,char *filename, 276 struct fiddef *fid,struct FCB **fcb); 277 unsigned update_extend(struct FCB *fcb,unsigned blocks,unsigned contig); 278 unsigned short checksum(vmsword *block); 279