1 /* 2 adapted from dos.h in the mach dos emulator for the linux dosemu dos 3 emulator. 4 Andrew.Tridgell@anu.edu.au 30th March 1993 5 */ 6 7 8 /* ### Added by DH ### */ 9 #ifndef DOSEMU 10 # define DOSEMU 11 #endif 12 13 #include <unistd.h> /* for SEEK_END */ 14 15 /* ### End of addition ### */ 16 17 #ifdef DOSEMU 18 /* definitions to make mach emu code compatible with dosemu */ 19 20 /* ### Commented out by DH ### 21 * #include "emu.h" 22 */ 23 24 25 #ifndef SOLARIS 26 typedef unsigned char boolean_t; 27 #endif 28 29 /* ### Commented out by DH ### 30 * #define d_namlen d_reclen 31 */ 32 33 #ifndef MAX_DRIVE 34 #define MAX_DRIVE 26 35 #endif 36 37 #define USE_DF_AND_AFS_STUFF 38 39 /* ### Commented out by DH ### 40 * #define VOLUMELABEL "Linux" 41 * #define LINUX_RESOURCE "\\\\LINUX\\FS" 42 */ 43 44 /* ### Added by DH ### */ 45 46 #include "mfs_link.h" 47 48 extern char *sys_errlist[]; 49 50 #if !defined(__hpux) && !defined(SOLARIS) && !defined(SGI) && !defined(RS6000) 51 #define strerror(x) sys_errlist[x] 52 #endif 53 54 #ifdef RS6000 55 #define strerror(x) mstrerror(x) 56 #endif 57 58 #define VOLUMELABEL "PCEmu" 59 #define LINUX_RESOURCE "\\\\PCEMU\\FS" 60 61 #define Write2Bytes(d,x) (*(BYTE *)(d) = (x) & 0xff, \ 62 *((BYTE *)(d)+1) = ((x) >> 8) & 0xff) 63 #define Write4Bytes(d,x) (*(BYTE *)(d) = (x) & 0xff, \ 64 *((BYTE *)(d)+1) = ((x) >> 8) & 0xff, \ 65 *((BYTE *)(d)+2) = ((x) >> 16) & 0xff, \ 66 *((BYTE *)(d)+3) = ((x) >> 24) & 0xff) 67 68 #define Read2Bytes(t,x) (t)(*(BYTE *)(x) + (*((BYTE *)(x) + 1) << 8)) 69 #define Read4Bytes(t,x) (t)(*(BYTE *)(x) + ((u_long)*((BYTE *)(x) + 1) << 8) + \ 70 ((u_long)*((BYTE *)(x) + 2) << 16) + \ 71 ((u_long)*((BYTE *)(x) + 3) << 24)) 72 73 /* ### End of addition ### */ 74 75 /* ### Added by DH ### */ 76 #ifndef FALSE 77 #define FALSE 0 78 #endif 79 #ifndef TRUE 80 #define TRUE 1 81 #endif 82 /* ### End of addition ### */ 83 84 /* ### Commented out by DH 85 * #define FALSE 0 86 * #define TRUE 1 87 */ 88 89 #define UNCHANGED 2 90 #define REDIRECT 3 91 92 #define us_debug_level 10 93 #define Debug_Level_0 0 94 #define dbg_fd stderr 95 96 /* Some compilers cannot handle variable argument #defines 97 #define d_Stub(arg1, s, a...) d_printf("MFS: "s, ##a) 98 #define Debug0(args) d_Stub args 99 #define Debug1(args) d_Stub args 100 */ 101 102 #define Debug0(args) 103 #define Debug1(args) 104 105 typedef struct vm86_regs state_t; 106 107 #define uesp esp 108 109 /* ### Added '(&memory[ ... ])' to line below ### */ 110 #define Addr_8086(x,y) (&memory[(( ((x) & 0xffff) << 4) + ((y) & 0xffff))]) 111 #define Addr(s,x,y) Addr_8086(((s)->x), ((s)->y)) 112 #define MASK8(x) ((x) & 0xff) 113 #define MASK16(x) ((x) & 0xffff) 114 #define HIGH(x) MASK8((unsigned long)(x) >> 8) 115 #define LOW(x) MASK8((unsigned long)(x)) 116 #undef WORD 117 #define WORD(x) MASK16((unsigned long)(x)) 118 #define SETHIGH(x,y) (*(x) = (*(x) & ~0xff00) | ((MASK8(y))<<8)) 119 #define SETLOW(x,y) (*(x) = (*(x) & ~0xff) | (MASK8(y))) 120 #define SETWORD(x,y) (*(x) = (*(x) & ~0xffff) | (MASK16(y))) 121 #endif 122 123 /* 124 * Copyright (c) 1991 Carnegie Mellon University 125 * All Rights Reserved. 126 * 127 * Permission to use, copy, modify and distribute this software and its 128 * documentation is hereby granted, provided that both the copyright 129 * notice and this permission notice appear in all copies of the 130 * software, derivative works or modified versions, and any portions 131 * thereof, and that both notices appear in supporting documentation. 132 * 133 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 134 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 135 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 136 * 137 * Carnegie Mellon requests users of this software to return to 138 * 139 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 140 * School of Computer Science 141 * Carnegie Mellon University 142 * Pittsburgh PA 15213-3890 143 * 144 * any improvements or extensions that they make and grant Carnegie Mellon 145 * the rights to redistribute these changes. 146 */ 147 /* 148 * 149 * Purpose: 150 * V86 DOS disk emulation header file 151 * 152 * HISTORY: 153 * $Log: mfs.h,v $ 154 * Revision 1.6 1994/01/25 20:02:44 root 155 * Exchange stderr <-> stdout. 156 * 157 * Revision 1.5 1994/01/20 21:14:24 root 158 * Indent. 159 * 160 * Revision 1.4 1994/01/19 17:51:14 root 161 * Added CDS_FLAG_NOTNET = 0x80 for mfs.c 162 * 163 * Revision 1.3 1993/12/22 11:45:36 root 164 * Fixes for ftruncate 165 * 166 * Revision 1.2 1993/11/17 22:29:33 root 167 * *** empty log message *** 168 * 169 * Revision 1.1 1993/11/12 12:32:17 root 170 * Initial revision 171 * 172 * Revision 1.1 1993/07/07 00:49:06 root 173 * Initial revision 174 * 175 * Revision 1.3 1993/05/04 05:29:22 root 176 * added console switching, new parse commands, and serial emulation 177 * 178 * Revision 1.2 1993/04/07 21:04:26 root 179 * big move 180 * 181 * Revision 1.1 1993/04/05 17:25:13 root 182 * Initial revision 183 * 184 * Revision 2.3 91/12/06 15:29:23 grm 185 * Redefined sda_cur_psp, and added psp_parent_psp. The 186 * psp_parent_psp was used to find out what the psp of the parent of 187 * the command.com program was. It seems that it is undefined. 188 * [91/12/06 grm] 189 * 190 * Revision 2.2 91/12/05 16:42:08 grm 191 * Added sft_rel and _abs_cluster macros. Used to debug the 192 * MS-Write network drive problem. 193 * [91/12/04 grm] 194 * Added constants for Dos 4+ 195 * [91/07/16 17:47:20 grm] 196 * 197 * Changed to allow for usage with Dos v4.01 and 5.00. 198 * [91/06/28 18:53:42 grm] 199 * 200 * New Copyright 201 * [91/05/28 15:12:28 grm] 202 * 203 * Added structures for the dos_general routines. 204 * [91/04/30 13:43:58 grm] 205 * 206 * Structures and macros for the dos_fs.c 207 * network redirector interface. 208 * [91/04/30 13:36:42 grm] 209 * 210 * Name changed from dos_general.h to dos.h. 211 * Added external declarations for dos_foo.c files. 212 * [91/03/01 14:40:55 grm] 213 * 214 * Type works. Interrim changes. 215 * [91/02/11 18:22:47 grm] 216 * 217 * Fancy dir. 218 * [91/02/06 16:59:01 grm] 219 * 220 * Created. 221 * [91/02/06 14:29:39 grm] 222 * 223 */ 224 225 #include <sys/types.h> 226 227 /* 228 * Dos error codes 229 */ 230 /* MS-DOS version 2 error codes */ 231 #define FUNC_NUM_IVALID 0x01 232 #define FILE_NOT_FOUND 0x02 233 #define PATH_NOT_FOUND 0x03 234 #define TOO_MANY_OPEN_FILES 0x04 235 #define ACCESS_DENIED 0x05 236 #define HANDLE_INVALID 0x06 237 #define MEM_CB_DEST 0x07 238 #define INSUF_MEM 0x08 239 #define MEM_BLK_ADDR_IVALID 0x09 240 #define ENV_INVALID 0x0a 241 #define FORMAT_INVALID 0x0b 242 #define ACCESS_CODE_INVALID 0x0c 243 #define DATA_INVALID 0x0d 244 #define UNKNOWN_UNIT 0x0e 245 #define DISK_DRIVE_INVALID 0x0f 246 #define ATT_REM_CUR_DIR 0x10 247 #define NOT_SAME_DEV 0x11 248 #define NO_MORE_FILES 0x12 249 /* mappings to critical-error codes */ 250 #define WRITE_PROT_DISK 0x13 251 #define UNKNOWN_UNIT_CERR 0x14 252 #define DRIVE_NOT_READY 0x15 253 #define UNKNOWN_COMMAND 0x16 254 #define DATA_ERROR_CRC 0x17 255 #define BAD_REQ_STRUCT_LEN 0x18 256 #define SEEK_ERROR 0x19 257 #define UNKNOWN_MEDIA_TYPE 0x1a 258 #define SECTOR_NOT_FOUND 0x1b 259 #define PRINTER_OUT_OF_PAPER 0x1c 260 #define WRITE_FAULT 0x1d 261 #define READ_FAULT 0x1e 262 #define GENERAL_FAILURE 0x1f 263 264 /* MS-DOS version 3 and later extended error codes */ 265 #define SHARING_VIOLATION 0x20 266 #define FILE_LOCK_VIOLATION 0x21 267 #define DISK_CHANGE_INVALID 0x22 268 #define FCB_UNAVAILABLE 0x23 269 #define SHARING_BUF_EXCEEDED 0x24 270 271 #define NETWORK_NAME_NOT_FOUND 0x35 272 273 #define FILE_ALREADY_EXISTS 0x50 274 275 #define DUPLICATE_REDIR 0x55 276 277 struct dir_ent { 278 char name[8]; /* dos name and ext */ 279 char ext[3]; 280 u_short mode; /* unix st_mode value */ 281 long size; /* size of file */ 282 time_t time; /* st_mtime */ 283 struct dir_ent *next; 284 }; 285 286 struct dos_name { 287 char name[8]; 288 char ext[3]; 289 }; 290 291 typedef struct far_record { 292 u_short offset; 293 u_short segment; 294 } far_t; 295 296 #define DOSVER_31_33 1 297 #define DOSVER_41 2 298 #define DOSVER_50 3 299 #define DOSVER_60 4 300 301 typedef u_char *sdb_t; 302 303 /* ### Changed all *(u_short *)... to Read2Bytes(u_short,...) ### */ 304 /* ### Changed all *(u_long *)... to Read4Bytes(u_long,...) ### */ 305 #define sdb_drive_letter(sdb) (*(u_char *)&sdb[sdb_drive_letter_off]) 306 #define sdb_template_name(sdb) ((char *)&sdb[sdb_template_name_off]) 307 #define sdb_template_ext(sdb) ((char *)&sdb[sdb_template_ext_off]) 308 #define sdb_attribute(sdb) (*(u_char *)&sdb[sdb_attribute_off]) 309 /* ### Split next definition into read (..._r) and write (..._w) ### */ 310 #define sdb_dir_entry_r(sdb) (Read2Bytes(u_short,&sdb[sdb_dir_entry_off])) 311 #define sdb_dir_entry_w(sdb,x) (Write2Bytes(&sdb[sdb_dir_entry_off], x)) 312 #define sdb_p_cluster(sdb) (Read2Bytes(u_short,&sdb[sdb_p_cluster_off])) 313 #define sdb_file_name(sdb) ((char *)&sdb[sdb_file_name_off]) 314 #define sdb_file_ext(sdb) ((char *)&sdb[sdb_file_ext_off]) 315 #define sdb_file_attr(sdb) (*(u_char *)&sdb[sdb_file_attr_off]) 316 #define sdb_file_time(sdb) (*(u_short *)&sdb[sdb_file_time_off]) 317 #define sdb_file_date(sdb) (*(u_short *)&sdb[sdb_file_date_off]) 318 #define sdb_file_st_cluster(sdb)(Read2Bytes(u_short,&sdb[sdb_file_st_cluster_off])) 319 #define sdb_file_size(sdb,x) (Write4Bytes(&sdb[sdb_file_size_off],x)) 320 321 typedef u_char *sft_t; 322 323 /* ### Split next definition into read (..._r) and write (..._w) ### */ 324 #define sft_handle_cnt_r(sft) (Read2Bytes(u_short,&sft[sft_handle_cnt_off])) 325 #define sft_handle_cnt_w(sft,x) (Write2Bytes(&sft[sft_handle_cnt_off], x)) 326 /* ### Split next definition into read (..._r) and write (..._w) ### */ 327 #define sft_open_mode_r(sft) (Read2Bytes(u_short,&sft[sft_open_mode_off])) 328 #define sft_open_mode_w(sft,x) (Write2Bytes(&sft[sft_open_mode_off],x)) 329 #define sft_attribute_byte(sft) (*(u_char *)&sft[sft_attribute_byte_off]) 330 /* ### Split next definition into read (..._r) and write (..._w) ### */ 331 #define sft_device_info_r(sft) (Read2Bytes(u_short,&sft[sft_device_info_off])) 332 #define sft_device_info_w(sft,x) (Write2Bytes(&sft[sft_device_info_off], x)) 333 #define sft_dev_drive_ptr(sft,x) (Write4Bytes(&sft[sft_dev_drive_ptr_off], x)) 334 #define sft_start_cluster(sft) (Read2Bytes(u_short,&sft[sft_start_cluster_off])) 335 #define sft_time(sft) (*(u_short *)&sft[sft_time_off]) 336 #define sft_date(sft) (*(u_short *)&sft[sft_date_off]) 337 /* ### Split next definition into read (..._r) and write (..._w) ### */ 338 #define sft_size_r(sft) (Read4Bytes(u_long,&sft[sft_size_off])) 339 #define sft_size_w(sft, x) (Write4Bytes(&sft[sft_size_off], x)) 340 /* ### Split next definition into read (..._r) and write (..._w) ### */ 341 #define sft_position_r(sft) (Read4Bytes(u_long,&sft[sft_position_off])) 342 #define sft_position_w(sft,x) (Write4Bytes(&sft[sft_position_off],x)) 343 #define sft_rel_cluster(sft) (Read2Bytes(u_short,&sft[sft_rel_cluster_off])) 344 #define sft_abs_cluster(sft,x) (Write2Bytes(&sft[sft_abs_cluster_off], x)) 345 #define sft_directory_sector(sft,x) (Write2Bytes(&sft[sft_directory_sector_off],x)) 346 #define sft_directory_entry(sft) (*(u_char *)&sft[sft_directory_entry_off]) 347 #define sft_name(sft) ( (char *)&sft[sft_name_off]) 348 #define sft_ext(sft) ( (char *)&sft[sft_ext_off]) 349 350 /* ### Split next definition into read (..._r) and write (..._w) ### */ 351 #define sft_fd_r(sft) (Read2Bytes(u_short,&sft[sft_fd_off])) 352 #define sft_fd_w(sft,x) (Write2Bytes(&sft[sft_fd_off], x)) 353 354 typedef u_char *cds_t; 355 356 #define cds_current_path(cds) ((char *)&cds[cds_current_path_off]) 357 /* ### Split next definition into read (..._r) and write (..._w) ### */ 358 #define cds_flags_r(cds) (Read2Bytes(u_short,&cds[cds_flags_off])) 359 #define cds_flags_w(cds,x) (Write2Bytes(&cds[cds_flags_off], x)) 360 #define cds_DBP_pointer(cds) (Read4Bytes(u_long,&cds[cds_DBP_pointer_off])) 361 #define cds_cur_cluster(cds,x) (Write2Bytes(&cds[cds_cur_cluster_off],x)) 362 /* ### Split next difinition into read (..._r) and write (..._w) ### */ 363 #define cds_rootlen_r(cds) (Read2Bytes(u_short,&cds[cds_rootlen_off])) 364 #define cds_rootlen_w(cds,x) (Write2Bytes(&cds[cds_rootlen_off], x)) 365 #define drive_cds(dd) ((cds_t)(((int)cds_base)+(cds_record_size*(dd)))) 366 367 #define CDS_FLAG_REMOTE 0x8000 368 #define CDS_FLAG_READY 0x4000 369 #define CDS_FLAG_NOTNET 0x0080 370 #define CDS_FLAG_SUBST 0x1000 371 #define CDS_DEFAULT_ROOT_LEN 2 372 373 #define FAR(x) (Addr_8086(x.segment, x.offset)) 374 375 /* ### Commented out by DH ### 376 * #define FARPTR(x) (Addr_8086((x)->segment, (x)->offset)) 377 */ 378 379 /* ### Added by DH ### */ 380 #define FARPTR(x) &memory[Read2Bytes(u_short, (x)) + \ 381 (Read2Bytes(u_short, (BYTE *)(x)+2) << 4)] 382 /* ### End of addition ### */ 383 384 typedef u_short *psp_t; 385 386 #define PSPPTR(x) (Addr_8086(x, 0)) 387 388 typedef u_char *sda_t; 389 390 #define sda_current_dta(sda) ((char *)(FARPTR((far_t *)&sda[sda_current_dta_off]))) 391 #define sda_cur_psp(sda) (Read2Bytes(u_short,&sda[sda_cur_psp_off])) 392 #define sda_filename1(sda) ((char *)&sda[sda_filename1_off]) 393 #define sda_filename2(sda) ((char *)&sda[sda_filename2_off]) 394 #define sda_sdb(sda) ((sdb_t )&sda[sda_sdb_off]) 395 #define sda_cds(sda) ((cds_t)(FARPTR((far_t *)&sda[sda_cds_off]))) 396 #define sda_search_attribute(sda) (*(u_char *)&sda[sda_search_attribute_off]) 397 #define sda_open_mode(sda) (*(u_char *)&sda[sda_open_mode_off]) 398 #define sda_rename_source(sda) ((sdb_t )&sda[sda_rename_source_off]) 399 #define sda_user_stack(sda) ((char *)(FARPTR((far_t *)&sda[sda_user_stack_off]))) 400 401 /* 402 * Data for extended open/create operations, DOS 4 or greater: 403 */ 404 #define sda_ext_act(sda) (Read2Bytes(u_short,&sda[sda_ext_act_off])) 405 #define sda_ext_attr(sda) (Read2Bytes(u_short,&sda[sda_ext_attr_off])) 406 #define sda_ext_mode(sda) (Read2Bytes(u_short,&sda[sda_ext_mode_off])) 407 408 #define psp_parent_psp(psp) (Read2Bytes(u_short,&psp[0x16])) 409 #define psp_handles(psp) ((char *)(FARPTR((far_t *)&psp[0x34]))) 410 411 #define lol_cdsfarptr(lol) (Read4Bytes(u_long,&lol[lol_cdsfarptr_off])) 412 #define lol_last_drive(lol) (*(u_char *)&lol[lol_last_drive_off]) 413 414 typedef u_char *lol_t; 415 416 #ifdef OLD_OBSOLETE 417 typedef struct lol_record { 418 u_char filler1[22]; 419 far_t cdsfarptr; 420 u_char filler2[6]; 421 u_char last_drive; 422 } *lol_t; 423 424 #endif 425 426 /* dos attribute byte flags */ 427 #define REGULAR_FILE 0x00 428 #define READ_ONLY_FILE 0x01 429 #define HIDDEN_FILE 0x02 430 #define SYSTEM_FILE 0x04 431 #define VOLUME_LABEL 0x08 432 #define DIRECTORY 0x10 433 #define ARCHIVE_NEEDED 0x20 434 435 /* dos access mode constants */ 436 #define READ_ACC 0x00 437 #define WRITE_ACC 0x01 438 #define READ_WRITE_ACC 0x02 439 440 #define COMPAT_MODE 0x00 441 #define DENY_ALL 0x01 442 #define DENY_WRITE 0x02 443 #define DENY_READ 0x03 444 #define DENY_ANY 0x40 445 446 #define CHILD_INHERIT 0x00 447 #define NO_INHERIT 0x01 448 449 #define A_DRIVE 0x01 450 #define B_DRIVE 0x02 451 #define C_DRIVE 0x03 452 #define D_DRIVE 0x04 453 454 #define GET_REDIRECTION 2 455 #define REDIRECT_DEVICE 3 456 #define CANCEL_REDIRECTION 4 457 #define EXTENDED_GET_REDIRECTION 5 458