diff options
| author | 2024-04-25 21:24:10 +0100 | |
|---|---|---|
| committer | 2024-04-25 22:32:27 +0000 | |
| commit | 2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch) | |
| tree | 80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/DOS/IOCTL.ASM | |
| parent | Merge pull request #430 from jpbaltazar/typoptbr (diff) | |
| download | ms-dos-main.tar.gz ms-dos-main.tar.xz ms-dos-main.zip | |
Diffstat (limited to 'v4.0/src/DOS/IOCTL.ASM')
| -rw-r--r-- | v4.0/src/DOS/IOCTL.ASM | 745 |
1 files changed, 745 insertions, 0 deletions
diff --git a/v4.0/src/DOS/IOCTL.ASM b/v4.0/src/DOS/IOCTL.ASM new file mode 100644 index 0000000..8007244 --- /dev/null +++ b/v4.0/src/DOS/IOCTL.ASM | |||
| @@ -0,0 +1,745 @@ | |||
| 1 | ; SCCSID = @(#)IOCTL.INC 1.15 85/09/05 | ||
| 2 | TITLE IOCTL - IOCTL system call | ||
| 3 | NAME IOCTL | ||
| 4 | |||
| 5 | ; | ||
| 6 | ; | ||
| 7 | ; IOCTL system call. | ||
| 8 | ; | ||
| 9 | ; | ||
| 10 | ; $IOCTL | ||
| 11 | ; | ||
| 12 | ; Revision history: | ||
| 13 | ; | ||
| 14 | ; Created: ARR 4 April 1983 | ||
| 15 | ; | ||
| 16 | ; GenericIOCTL added: KGS 22 April 1985 | ||
| 17 | ; | ||
| 18 | ; A000 version 4.00 Jan. 1988 | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | .xlist | ||
| 23 | ; | ||
| 24 | ; get the appropriate segment definitions | ||
| 25 | ; | ||
| 26 | include dosseg.asm | ||
| 27 | |||
| 28 | CODE SEGMENT BYTE PUBLIC 'CODE' | ||
| 29 | ASSUME SS:DOSGROUP,CS:DOSGROUP | ||
| 30 | |||
| 31 | .xcref | ||
| 32 | INCLUDE DOSSYM.INC | ||
| 33 | INCLUDE DEVSYM.INC | ||
| 34 | include ioctl.inc | ||
| 35 | include ifssym.inc ;AN000; | ||
| 36 | .cref | ||
| 37 | .list | ||
| 38 | |||
| 39 | i_need THISCDS,DWORD | ||
| 40 | i_need IOCALL,BYTE | ||
| 41 | i_need IOMED,BYTE | ||
| 42 | i_need IOSCNT,WORD | ||
| 43 | i_need IOXAD,DWORD | ||
| 44 | I_need RetryCount,WORD | ||
| 45 | I_need RetryLoop,WORD | ||
| 46 | I_need EXTERR_LOCUS,BYTE | ||
| 47 | I_need OPENBUF,BYTE | ||
| 48 | I_need ExtErr,WORD | ||
| 49 | I_need DrvErr,BYTE | ||
| 50 | I_need USER_IN_AX,WORD ;AN000; | ||
| 51 | I_need Temp_Var2,WORD ;AN000; | ||
| 52 | |||
| 53 | BREAK <IOCTL - munge on a handle to do device specific stuff> | ||
| 54 | |||
| 55 | ; | ||
| 56 | ; Assembler usage: | ||
| 57 | ; MOV BX, Handle | ||
| 58 | ; MOV DX, Data | ||
| 59 | ; | ||
| 60 | ; (or LDS DX,BUF | ||
| 61 | ; MOV CX,COUNT) | ||
| 62 | ; | ||
| 63 | ; MOV AH, Ioctl | ||
| 64 | ; MOV AL, Request | ||
| 65 | ; INT 21h | ||
| 66 | ; | ||
| 67 | ; AH = 0 Return a combination of low byte of sf_flags and device driver | ||
| 68 | ; attribute word in DX, handle in BX: | ||
| 69 | ; DH = high word of device driver attributes | ||
| 70 | ; DL = low byte of sf_flags | ||
| 71 | ; 1 Set the bits contained in DX to sf_flags. DH MUST be 0. Handle | ||
| 72 | ; in BX. | ||
| 73 | ; 2 Read CX bytes from the device control channel for handle in BX | ||
| 74 | ; into DS:DX. Return number read in AX. | ||
| 75 | ; 3 Write CX bytes to the device control channel for handle in BX from | ||
| 76 | ; DS:DX. Return bytes written in AX. | ||
| 77 | ; 4 Read CX bytes from the device control channel for drive in BX | ||
| 78 | ; into DS:DX. Return number read in AX. | ||
| 79 | ; 5 Write CX bytes to the device control channel for drive in BX from | ||
| 80 | ; DS:DX. Return bytes written in AX. | ||
| 81 | ; 6 Return input status of handle in BX. If a read will go to the | ||
| 82 | ; device, AL = 0FFh, otherwise 0. | ||
| 83 | ; 7 Return output status of handle in BX. If a write will go to the | ||
| 84 | ; device, AL = 0FFh, otherwise 0. | ||
| 85 | ; 8 Given a drive in BX, return 1 if the device contains non- | ||
| 86 | ; removable media, 0 otherwise. | ||
| 87 | ; 9 Return the contents of the device attribute word in DX for the | ||
| 88 | ; drive in BX. 0200h is the bit for shared. 1000h is the bit for | ||
| 89 | ; network. 8000h is the bit for local use. | ||
| 90 | ; A Return 8000h if the handle in BX is for the network or not. | ||
| 91 | ; B Change the retry delay and the retry count for the system. BX is | ||
| 92 | ; the count and CX is the delay. | ||
| 93 | ; | ||
| 94 | ; Error returns: | ||
| 95 | ; AX = error_invalid_handle | ||
| 96 | ; = error_invalid_function | ||
| 97 | ; = error_invalid_data | ||
| 98 | ; | ||
| 99 | ;------------------------------------------------------------------------------- | ||
| 100 | ; | ||
| 101 | ; This is the documentation copied from DOS 4.0 it is much better | ||
| 102 | ; than the above | ||
| 103 | ; | ||
| 104 | ; There are several basic forms of IOCTL calls: | ||
| 105 | ; | ||
| 106 | ; | ||
| 107 | ; ** Get/Set device information: ** | ||
| 108 | ; | ||
| 109 | ; ENTRY (AL) = function code | ||
| 110 | ; 0 - Get device information | ||
| 111 | ; 1 - Set device information | ||
| 112 | ; (BX) = file handle | ||
| 113 | ; (DX) = info for "Set Device Information" | ||
| 114 | ; EXIT 'C' set if error | ||
| 115 | ; (AX) = error code | ||
| 116 | ; 'C' clear if OK | ||
| 117 | ; (DX) = info for "Get Device Information" | ||
| 118 | ; USES ALL | ||
| 119 | ; | ||
| 120 | ; | ||
| 121 | ; ** Read/Write Control Data From/To Handle ** | ||
| 122 | ; | ||
| 123 | ; ENTRY (AL) = function code | ||
| 124 | ; 2 - Read device control info | ||
| 125 | ; 3 - Write device control info | ||
| 126 | ; (BX) = file handle | ||
| 127 | ; (CX) = transfer count | ||
| 128 | ; (DS:DX) = address for data | ||
| 129 | ; EXIT 'C' set if error | ||
| 130 | ; (AX) = error code | ||
| 131 | ; 'C' clear if OK | ||
| 132 | ; (AX) = count of bytes transfered | ||
| 133 | ; USES ALL | ||
| 134 | ; | ||
| 135 | ; | ||
| 136 | ; ** Read/Write Control Data From/To Block Device ** | ||
| 137 | ; | ||
| 138 | ; ENTRY (AL) = function code | ||
| 139 | ; 4 - Read device control info | ||
| 140 | ; 5 - Write device control info | ||
| 141 | ; (BL) = Drive number (0=default, 1='A', 2='B', etc) | ||
| 142 | ; (CX) = transfer count | ||
| 143 | ; (DS:DX) = address for data | ||
| 144 | ; EXIT 'C' set if error | ||
| 145 | ; (AX) = error code | ||
| 146 | ; 'C' clear if OK | ||
| 147 | ; (AX) = count of bytes transfered | ||
| 148 | ; USES ALL | ||
| 149 | ; | ||
| 150 | ; | ||
| 151 | ; ** Get Input/Output Status ** | ||
| 152 | ; | ||
| 153 | ; ENTRY (AL) = function code | ||
| 154 | ; 6 - Get Input status | ||
| 155 | ; 7 - Get Output Status | ||
| 156 | ; (BX) = file handle | ||
| 157 | ; EXIT 'C' set if error | ||
| 158 | ; (AX) = error code | ||
| 159 | ; 'C' clear if OK | ||
| 160 | ; (AL) = 00 if not ready | ||
| 161 | ; (AL) = FF if ready | ||
| 162 | ; USES ALL | ||
| 163 | ; | ||
| 164 | ; | ||
| 165 | ; ** Get Drive Information ** | ||
| 166 | ; | ||
| 167 | ; ENTRY (AL) = function code | ||
| 168 | ; 8 - Check for removable media | ||
| 169 | ; 9 - Get device attributes | ||
| 170 | ; (BL) = Drive number (0=default, 1='A', 2='B', etc) | ||
| 171 | ; EXIT 'C' set if error | ||
| 172 | ; (AX) = error code | ||
| 173 | ; 'C' clear if OK | ||
| 174 | ; (AX) = 0/1 media is removable/fixed (func. 8) | ||
| 175 | ; (DX) = device attribute word (func. 9) | ||
| 176 | ; USES ALL | ||
| 177 | ; | ||
| 178 | ; | ||
| 179 | ; ** Get Redirected bit ** | ||
| 180 | ; | ||
| 181 | ; ENTRY (AL) = function code | ||
| 182 | ; 0Ah - Network stuff | ||
| 183 | ; (BX) = file handle | ||
| 184 | ; EXIT 'C' set if error | ||
| 185 | ; (AX) = error code | ||
| 186 | ; 'C' clear if OK | ||
| 187 | ; (DX) = SFT flags word, 8000h set if network file | ||
| 188 | ; USES ALL | ||
| 189 | ; | ||
| 190 | ; | ||
| 191 | ; ** Change sharer retry parameters ** | ||
| 192 | ; | ||
| 193 | ; ENTRY (AL) = function code | ||
| 194 | ; 0Bh - Set retry parameters | ||
| 195 | ; (CX) = retry loop count | ||
| 196 | ; (DX) = number of retries | ||
| 197 | ; EXIT 'C' set if error | ||
| 198 | ; (AX) = error code | ||
| 199 | ; 'C' clear if OK | ||
| 200 | ; USES ALL | ||
| 201 | ; | ||
| 202 | ; | ||
| 203 | ; ================================================================= | ||
| 204 | ; | ||
| 205 | ; ** New Standard Control ** | ||
| 206 | ; | ||
| 207 | ; ALL NEW IOCTL FACILITIES SHOULD USE THIS FORM. THE OTHER | ||
| 208 | ; FORMS ARE OBSOLETE. | ||
| 209 | ; | ||
| 210 | ; ================================================================= | ||
| 211 | ; | ||
| 212 | ; ENTRY (AL) = function code | ||
| 213 | ; 0Ch - Control Function subcode | ||
| 214 | ; (BX) = File Handle | ||
| 215 | ; (CH) = Category Indicator | ||
| 216 | ; (CL) = Function within category | ||
| 217 | ; (DS:DX) = address for data, if any | ||
| 218 | ; (SI) = Passed to device as argument, use depends upon function | ||
| 219 | ; (DI) = Passed to device as argument, use depends upon function | ||
| 220 | ; EXIT 'C' set if error | ||
| 221 | ; (AX) = error code | ||
| 222 | ; 'C' clear if OK | ||
| 223 | ; (SI) = Return value, meaning is function dependent | ||
| 224 | ; (DI) = Return value, meaning is function dependent | ||
| 225 | ; (DS:DX) = Return address, use is function dependent | ||
| 226 | ; USES ALL | ||
| 227 | ; | ||
| 228 | ; ============== Generic IOCTL Definitions for DOS 3.2 ============ | ||
| 229 | ; (See dos/ioctl.mac for more info) | ||
| 230 | ; | ||
| 231 | ; ENTRY (AL) = function code | ||
| 232 | ; 0Dh - Control Function subcode | ||
| 233 | ; (BL) = Drive Number (0 = Default, 1= 'A') | ||
| 234 | ; (CH) = Category Indicator | ||
| 235 | ; (CL) = Function within category | ||
| 236 | ; (DS:DX) = address for data, if any | ||
| 237 | ; (SI) = Passed to device as argument, use depends upon function | ||
| 238 | ; (DI) = Passed to device as argument, use depends upon function | ||
| 239 | ; | ||
| 240 | ; EXIT 'C' set if error | ||
| 241 | ; (AX) = error code | ||
| 242 | ; 'C' clear if OK | ||
| 243 | ; (DS:DX) = Return address, use is function dependent | ||
| 244 | ; USES ALL | ||
| 245 | ; | ||
| 246 | |||
| 247 | procedure $IOCTL,NEAR | ||
| 248 | ASSUME DS:NOTHING,ES:NOTHING | ||
| 249 | MOV SI,DS ; Stash DS for calls 2,3,4 and 5 | ||
| 250 | context DS | ||
| 251 | CMP AL,3 | ||
| 252 | JBE ioctl_check_char ; char device | ||
| 253 | JMP ioctl_check_block ; Block device | ||
| 254 | ioctl_check_char: | ||
| 255 | invoke SFFromHandle ; ES:DI -> SFT | ||
| 256 | JNC ioctl_check_permissions ; have valid handle | ||
| 257 | ioctl_bad_handle: | ||
| 258 | error error_invalid_handle | ||
| 259 | |||
| 260 | ioctl_check_permissions: | ||
| 261 | CMP AL,2 | ||
| 262 | JAE ioctl_control_string | ||
| 263 | CMP AL,0 | ||
| 264 | MOV AL,BYTE PTR ES:[DI.sf_flags]; Get low byte of flags | ||
| 265 | JZ ioctl_read ; read the byte | ||
| 266 | PUSH DX ;AN000;MS. | ||
| 267 | AND DH,0FEH ;AN000;MS.allow DH=01H | ||
| 268 | POP DX ;AN000;MS. | ||
| 269 | JZ ioctl_check_device ; can I set with this data? | ||
| 270 | error error_invalid_data ; no DH <> 0 | ||
| 271 | |||
| 272 | ioctl_bad_funj2: | ||
| 273 | JMP ioctl_bad_fun | ||
| 274 | |||
| 275 | ioctl_check_device: | ||
| 276 | TEST AL,devid_device ; can I set this handle? | ||
| 277 | JZ do_exception ; no, it is a file. | ||
| 278 | OR DL,devid_device ; Make sure user doesn't turn off the | ||
| 279 | ; device bit!! He can muck with the | ||
| 280 | ; others at will. | ||
| 281 | MOV [EXTERR_LOCUS],errLOC_SerDev | ||
| 282 | MOV BYTE PTR ES:[DI.sf_flags],DL ;AC000;MS.; Set flags | ||
| 283 | do_exception: | ||
| 284 | OR BYTE PTR ES:[DI.sf_flags+1],DH;AN000;MS.;set 100H bit for disk full | ||
| 285 | |||
| 286 | transfer SYS_RET_OK | ||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | |||
| 291 | |||
| 292 | ioctl_read: | ||
| 293 | MOV [EXTERR_LOCUS],errLOC_Disk | ||
| 294 | XOR AH,AH | ||
| 295 | TEST AL,devid_device ; Should I set high byte | ||
| 296 | JZ ioctl_no_high ; no | ||
| 297 | MOV [EXTERR_LOCUS],errLOC_SerDev | ||
| 298 | LES DI,ES:[DI.sf_devptr] ; Get device pointer | ||
| 299 | MOV AH,BYTE PTR ES:[DI.SDEVATT+1] ; Get high byte | ||
| 300 | ioctl_no_high: | ||
| 301 | MOV DX,AX | ||
| 302 | invoke get_user_stack | ||
| 303 | MOV [SI.user_DX],DX | ||
| 304 | transfer SYS_RET_OK | ||
| 305 | |||
| 306 | ioctl_control_string: | ||
| 307 | TEST ES:[DI.sf_flags],devid_device ; can I? | ||
| 308 | JNZ ioctl_ctl_str_1 | ||
| 309 | JMP ioctl_bad_fun ; No it is a file | ||
| 310 | ioctl_ctl_str_1: | ||
| 311 | TEST ES:[DI.sf_flags],sf_isnet ;AN000;IFS.; IFS ? | ||
| 312 | JZ localrw ;AN000;IFS.; no | ||
| 313 | JMP callifs ;AN000;IFS.; call IFS | ||
| 314 | localrw: | ||
| 315 | MOV [EXTERR_LOCUS],errLOC_SerDev | ||
| 316 | LES DI,ES:[DI.sf_devptr] ; Get device pointer | ||
| 317 | XOR BL,BL ; Unit number of char dev = 0 | ||
| 318 | JMP ioctl_do_string | ||
| 319 | |||
| 320 | ioctl_get_devj: | ||
| 321 | JMP ioctl_get_dev | ||
| 322 | |||
| 323 | ioctl_check_block: | ||
| 324 | DEC AL | ||
| 325 | DEC AL ; 4=2,5=3,6=4,7=5,8=6,9=7,10=8,11=9 | ||
| 326 | CMP AL,3 | ||
| 327 | JBE ioctl_get_devj | ||
| 328 | CMP AL,6 | ||
| 329 | JAE ioctl_rem_media_check | ||
| 330 | |||
| 331 | MOV AH,1 | ||
| 332 | SUB AL,4 ; 6=0,7=1 | ||
| 333 | JZ ioctl_get_status | ||
| 334 | MOV AH,3 | ||
| 335 | ioctl_get_status: | ||
| 336 | PUSH AX | ||
| 337 | invoke GET_IO_SFT | ||
| 338 | POP AX | ||
| 339 | JNC DO_IOFUNC | ||
| 340 | JMP ioctl_bad_handle ; invalid SFT | ||
| 341 | |||
| 342 | DO_IOFUNC: | ||
| 343 | invoke IOFUNC | ||
| 344 | MOV AH,AL | ||
| 345 | MOV AL,0FFH | ||
| 346 | JNZ ioctl_status_ret | ||
| 347 | INC AL | ||
| 348 | ioctl_status_ret: | ||
| 349 | transfer SYS_RET_OK | ||
| 350 | |||
| 351 | ioctl_rem_media_check: ; 4=2,5=3,6=4,7=5,8=6,9=7,10=8,11=9 | ||
| 352 | JE ioctl_rem_mediaj | ||
| 353 | |||
| 354 | SUB AL,7 ; 9=0,10=1,11=2,12=3,13=4,14=5,15=6 | ||
| 355 | JNZ Rem_med_chk_1 | ||
| 356 | JMP Ioctl_Drive_attr | ||
| 357 | |||
| 358 | ioctl_rem_mediaj: | ||
| 359 | jmp ioctl_rem_media | ||
| 360 | |||
| 361 | ioctl_bad_funj4: | ||
| 362 | jmp ioctl_bad_fun | ||
| 363 | |||
| 364 | Rem_med_chk_1: | ||
| 365 | |||
| 366 | DEC AL ; 10=0,11=1,12=2,13=3,14=4,15=5 | ||
| 367 | jnz Set_Retry_chk | ||
| 368 | Jmp Ioctl_Handle_redirj | ||
| 369 | |||
| 370 | Set_Retry_chk: | ||
| 371 | DEC AL ; 11=0,12=1,13=2,14=3,15=4 | ||
| 372 | JZ Set_Retry_Parameters | ||
| 373 | |||
| 374 | DEC AL ; 12=0,13=1,14=2,15=3 | ||
| 375 | JZ GENERICIOCTLHANDLE | ||
| 376 | |||
| 377 | DEC AL ; 13=0,14=1,15=2 | ||
| 378 | JZ GENERICIOCTL | ||
| 379 | |||
| 380 | CMP AL,2 | ||
| 381 | JA ioctl_bad_funj4 | ||
| 382 | JMP ioctl_drive_owner | ||
| 383 | Set_Retry_Parameters: | ||
| 384 | MOV RetryLoop,CX ; 0 retry loop count allowed | ||
| 385 | OR DX,DX ; zero retries not allowed | ||
| 386 | JNZ goodtr | ||
| 387 | JMP IoCtl_Bad_Fun | ||
| 388 | goodtr: | ||
| 389 | MOV RetryCount,DX ; Set new retry count | ||
| 390 | doneok: | ||
| 391 | transfer Sys_Ret_Ok ; Done | ||
| 392 | |||
| 393 | ; Generic IOCTL entry point. | ||
| 394 | ; here we invoke the Generic IOCTL using the IOCTL_Req structure. | ||
| 395 | ; SI:DX -> Users Device Parameter Table | ||
| 396 | ; IOCALL -> IOCTL_Req structure | ||
| 397 | GENERICIOCTLHANDLE: | ||
| 398 | invoke SFFromHandle ; Get SFT for device. | ||
| 399 | jnc goodh | ||
| 400 | JMP ioctl_bad_handlej | ||
| 401 | goodh: | ||
| 402 | ; test word ptr [DI.sf_flags],sf_isnet | ||
| 403 | CALL TEST_IFS_REMOTE ;AN000;;IFS. test if remote | ||
| 404 | JZ okokok ;AN000;;IFS. | ||
| 405 | jmp ioctl_bad_fun ; Cannot do this over net. | ||
| 406 | okokok: | ||
| 407 | TEST [DI.sf_flags],sf_isnet ;AN000;IFS.; local IFS | ||
| 408 | JNZ callifs ;AN000;IFS.; yes | ||
| 409 | |||
| 410 | |||
| 411 | mov [EXTERR_LOCUS],ErrLOC_Serdev | ||
| 412 | les di,es:[di.sf_devptr] ; Get pointer to device. | ||
| 413 | jmp short Do_GenIOCTL | ||
| 414 | |||
| 415 | GENERICIOCTL: | ||
| 416 | mov [EXTERR_LOCUS],ErrLOC_Disk | ||
| 417 | cmp ch,IOC_DC ; Only disk devices are allowed to use | ||
| 418 | jne ioctl_bad_fun ; no handles with Generic IOCTL. | ||
| 419 | CALL Check_If_Net ; ES:DI := Get_hdr_block of device in BL | ||
| 420 | JNZ ioctl_bad_fun ; There are no "net devices", and they | ||
| 421 | PUSH ES ; certainly don't know how to do this ;AN000; | ||
| 422 | PUSH DI ;AN000;IFS. | ||
| 423 | LES DI,[THISCDS] ;AN000;IFS. ; | ||
| 424 | TEST ES:[DI.curdir_flags],curdir_isnet;AN000;IFS. ; local IFS ? | ||
| 425 | POP DI ;AN000;IFS. | ||
| 426 | POP ES ;AN000;IFS. | ||
| 427 | JZ Do_GenIOCTL ;AN000;IFS. ; no | ||
| 428 | callifs: | ||
| 429 | CMP byte ptr [User_In_AX+1],69H ;AN000; ;IFS. | ||
| 430 | JNZ is44xx ;AN000; ;IFS. | ||
| 431 | MOV AX,440DH ;AN000; ;IFS. | ||
| 432 | PUSH AX ;AN000; ;IFS. | ||
| 433 | JMP SHORT callrose ;AN000; ;IFS. | ||
| 434 | is44xx: | ||
| 435 | PUSH [User_In_AX] ;AN000; ;IFS. call IFSFUNC | ||
| 436 | callrose: | ||
| 437 | MOV DS,SI ;AN000; ;IFS. | ||
| 438 | MOV AX,(multNET SHL 8) or 43 ;AN000; ;IFS. | ||
| 439 | INT 2FH ;AN000; ;IFS. | ||
| 440 | POP BX ;AN000; ;IFS. | ||
| 441 | JNC doneok ;AN000; ;IFS. | ||
| 442 | MOV DI,AX ;AN000; ;IFS. | ||
| 443 | JMP device_err ;AN000; ;IFS. | ||
| 444 | Do_GenIOCTL: | ||
| 445 | test ES:[DI.SDEVATT],DEV320 ; Can device handle Generic IOCTL funcs | ||
| 446 | jz ioctl_bad_fun | ||
| 447 | PUSH ES ; DEVIOCALL2 expects Device header block | ||
| 448 | PUSH DI ; in DS:SI | ||
| 449 | ;set up Generic IOCTL Request Block | ||
| 450 | MOV byte ptr IOCALL.ReqLen,(size IOCTL_Req) | ||
| 451 | MOV byte ptr IOCALL.ReqFunc,GENIOCTL | ||
| 452 | MOV byte ptr IOCALL.ReqUnit,BL | ||
| 453 | MOV byte ptr IOCALL.MajorFunction,CH | ||
| 454 | MOV byte ptr IOCALL.MinorFunction,CL | ||
| 455 | MOV word ptr IOCALL.Reg_SI,SI | ||
| 456 | MOV word ptr IOCALL.Reg_DI,DI | ||
| 457 | MOV word ptr IOCALL.GenericIOCTL_Packet,DX | ||
| 458 | MOV word ptr IOCALL.GenericIOCTL_Packet + 2,SI | ||
| 459 | |||
| 460 | MOV BX,offset DOSGROUP:IOCALL | ||
| 461 | |||
| 462 | PUSH SS | ||
| 463 | POP ES | ||
| 464 | |||
| 465 | ASSUME DS:NOTHING ; DS:SI -> Device header. | ||
| 466 | POP SI | ||
| 467 | POP DS | ||
| 468 | jmp ioctl_do_IO ; Perform Call to device driver | ||
| 469 | |||
| 470 | IOCtl_Handle_RedirJ: | ||
| 471 | JMP IOCTL_Handle_Redir | ||
| 472 | ioctl_bad_fun: | ||
| 473 | error error_invalid_function | ||
| 474 | |||
| 475 | ioctl_bad_handlej: | ||
| 476 | jmp ioctl_bad_handle | ||
| 477 | |||
| 478 | ; Function 8 | ||
| 479 | ioctl_rem_media: | ||
| 480 | CALL Check_If_Net | ||
| 481 | JNZ ioctl_bad_fun ; There are no "net devices", and they | ||
| 482 | ; certainly don't know how to do this | ||
| 483 | ; call. | ||
| 484 | TEST ES:[DI.SDEVATT],DEVOPCL ; See if device can | ||
| 485 | JZ ioctl_bad_fun ; NO | ||
| 486 | MOV [IOCALL.REQFUNC],DEVRMD | ||
| 487 | MOV AL,REMHL | ||
| 488 | MOV AH,BL ; Unit number | ||
| 489 | MOV WORD PTR [IOCALL.REQLEN],AX | ||
| 490 | XOR AX,AX | ||
| 491 | MOV [IOCALL.REQSTAT],AX | ||
| 492 | PUSH ES | ||
| 493 | POP DS | ||
| 494 | ASSUME DS:NOTHING | ||
| 495 | MOV SI,DI ; DS:SI -> driver | ||
| 496 | PUSH SS | ||
| 497 | POP ES | ||
| 498 | MOV BX,OFFSET DOSGROUP:IOCALL ; ES:BX -> Call header | ||
| 499 | SaveReg <DS,SI> | ||
| 500 | invoke DEVIOCALL2 | ||
| 501 | RestoreReg <SI,DS> | ||
| 502 | MOV AX,[IOCALL.REQSTAT] ; Get Status word | ||
| 503 | AND AX,STBUI ; Mask to busy bit | ||
| 504 | MOV CL,9 | ||
| 505 | SHR AX,CL ; Busy bit to bit 0 | ||
| 506 | transfer SYS_RET_OK | ||
| 507 | |||
| 508 | ; Function 9 | ||
| 509 | Ioctl_Drive_attr: | ||
| 510 | |||
| 511 | ;;;;; MOV AL,BL ;AC000;; Drive | ||
| 512 | ;;;;; invoke GETTHISDRV ;AC000; | ||
| 513 | ;;;;; ;AC000; | ||
| 514 | ;;;;; JC ioctl_drv_err ; drive not valid | ||
| 515 | call Get_Driver_BL | ||
| 516 | JC ioctl_drv_err ; drive not valid | ||
| 517 | MOV AX,[Temp_Var2] ;AN000;IFS. | ||
| 518 | mov dx,word ptr es:[di.SDEVATT] ; get device attribute word | ||
| 519 | MOV BL,AL ; Phys letter to BL (A=0) | ||
| 520 | LES DI,[THISCDS] | ||
| 521 | ;;;;; TEST ES:[DI.curdir_flags],curdir_isnet | ||
| 522 | CALL TEST_IFS_REMOTE2 ;AN000;IFS. test if remote | ||
| 523 | JZ IOCTLShare | ||
| 524 | OR DX,1000h | ||
| 525 | IOCTLShare: | ||
| 526 | Context DS | ||
| 527 | ASSUME DS:NOTHING | ||
| 528 | MOV SI,OFFSET DOSGROUP:OPENBUF | ||
| 529 | ADD BL,"A" | ||
| 530 | MOV [SI],BL | ||
| 531 | MOV WORD PTR [SI+1],003AH ; ":",0 | ||
| 532 | MOV AX,0300H | ||
| 533 | CLC | ||
| 534 | INT int_IBM | ||
| 535 | JNC ioctlLocal ; Not shared | ||
| 536 | OR DX,0200H ; Shared, bit 9 | ||
| 537 | IOCTLLocal: | ||
| 538 | TEST ES:[DI].curdir_flags,curdir_local | ||
| 539 | JZ ioctl_set_dx | ||
| 540 | OR DX,8000h | ||
| 541 | |||
| 542 | ioctl_set_DX: | ||
| 543 | invoke get_user_stack | ||
| 544 | MOV [SI.user_DX],DX | ||
| 545 | transfer SYS_RET_OK | ||
| 546 | |||
| 547 | ioctl_drv_err: | ||
| 548 | MOV AL,[DrvErr] ;AN000;IFS. DrvErr is saved in GetThisDrv | ||
| 549 | transfer SYS_RET_ERR ;AN000;IFS. | ||
| 550 | |||
| 551 | ; Function 10 | ||
| 552 | Ioctl_Handle_redir: | ||
| 553 | invoke SFFromHandle ; ES:DI -> SFT | ||
| 554 | JNC ioctl_got_sft ; have valid handle | ||
| 555 | error error_invalid_handle | ||
| 556 | |||
| 557 | ioctl_got_sft: | ||
| 558 | MOV DX,ES:[DI.sf_flags] ; Get flags | ||
| 559 | JMP ioctl_set_DX | ||
| 560 | |||
| 561 | ioctl_bad_funj: | ||
| 562 | JMP ioctl_bad_fun | ||
| 563 | |||
| 564 | ioctl_get_dev: | ||
| 565 | DOSAssume CS,<DS>,"IOCTL/IOCtl_Get_Dev" | ||
| 566 | CALL Check_If_Net | ||
| 567 | JNZ ioctl_bad_funj ; There are no "net devices", and they | ||
| 568 | ; certainly don't know how to do this | ||
| 569 | ; call. | ||
| 570 | ioctl_do_string: | ||
| 571 | TEST ES:[DI.SDEVATT],DEVIOCTL; See if device accepts control | ||
| 572 | JZ ioctl_bad_funj ; NO | ||
| 573 | DEC AL | ||
| 574 | DEC AL | ||
| 575 | JZ ioctl_control_read | ||
| 576 | MOV [IOCALL.REQFUNC],DEVWRIOCTL | ||
| 577 | JMP SHORT ioctl_control_call | ||
| 578 | ioctl_control_read: | ||
| 579 | MOV [IOCALL.REQFUNC],DEVRDIOCTL | ||
| 580 | ioctl_control_call: | ||
| 581 | MOV AL,DRDWRHL | ||
| 582 | ioctl_setup_pkt: | ||
| 583 | MOV AH,BL ; Unit number | ||
| 584 | MOV WORD PTR [IOCALL.REQLEN],AX | ||
| 585 | XOR AX,AX | ||
| 586 | MOV [IOCALL.REQSTAT],AX | ||
| 587 | MOV [IOMED],AL | ||
| 588 | MOV [IOSCNT],CX | ||
| 589 | MOV WORD PTR [IOXAD],DX | ||
| 590 | MOV WORD PTR [IOXAD+2],SI | ||
| 591 | PUSH ES | ||
| 592 | POP DS | ||
| 593 | ASSUME DS:NOTHING | ||
| 594 | MOV SI,DI ; DS:SI -> driver | ||
| 595 | PUSH SS | ||
| 596 | POP ES | ||
| 597 | MOV BX,OFFSET DOSGROUP:IOCALL ; ES:BX -> Call header | ||
| 598 | ioctl_do_IO: | ||
| 599 | invoke DEVIOCALL2 | ||
| 600 | TEST [IOCALL.REQSTAT],STERR ;Error? | ||
| 601 | JNZ Ioctl_string_err | ||
| 602 | MOV AX,[IOSCNT] ; Get actual bytes transferred | ||
| 603 | transfer SYS_RET_OK | ||
| 604 | |||
| 605 | Ioctl_string_err: | ||
| 606 | MOV DI,[IOCALL.REQSTAT] ;Get Error | ||
| 607 | device_err: | ||
| 608 | AND DI,STECODE ; mask out irrelevant bits | ||
| 609 | MOV AX,DI | ||
| 610 | invoke SET_I24_EXTENDED_ERROR | ||
| 611 | mov ax, cs:extErr | ||
| 612 | transfer SYS_RET_ERR | ||
| 613 | |||
| 614 | Get_Driver_BL: | ||
| 615 | DOSAssume CS,<DS>,"Get_Driver_BL" | ||
| 616 | ASSUME ES:NOTHING | ||
| 617 | ; BL is drive number (0=default) | ||
| 618 | ; Returns pointer to device in ES:DI, unit number in BL if carry clear | ||
| 619 | ; No regs modified | ||
| 620 | |||
| 621 | PUSH AX | ||
| 622 | MOV AL,BL ; Drive | ||
| 623 | invoke GETTHISDRV | ||
| 624 | JNC ioctl_goodrv ;AC000;IFS. | ||
| 625 | CMP AL,error_not_dos_disk ;AN000;IFS. if unknow media then | ||
| 626 | JZ ioctl_goodrv ;AN000;IFS. let it go | ||
| 627 | STC ;AN000;IFS. else | ||
| 628 | JMP SHORT ioctl_bad_drv ;AN000;IFS. error | ||
| 629 | ioctl_goodrv: | ||
| 630 | XOR BL,BL ; Unit zero on Net device | ||
| 631 | MOV [EXTERR_LOCUS],errLOC_Net | ||
| 632 | LES DI,[THISCDS] | ||
| 633 | ; TEST ES:[DI.curdir_flags],curdir_isnet | ||
| 634 | CALL TEST_IFS_REMOTE2 ;AN000;;IFS. test if remote | ||
| 635 | LES DI,ES:[DI.curdir_devptr]; ES:DI -> Dpb or net dev | ||
| 636 | JNZ got_dev_ptr ; Is net | ||
| 637 | MOV [EXTERR_LOCUS],errLOC_Disk | ||
| 638 | MOV BL,ES:[DI.dpb_UNIT] ; Unit number | ||
| 639 | LES DI,ES:[DI.dpb_driver_addr] ; Driver addr | ||
| 640 | got_dev_ptr: | ||
| 641 | CLC | ||
| 642 | MOV [Temp_Var2],AX ;AN000;IFS. | ||
| 643 | ioctl_bad_drv: | ||
| 644 | POP AX | ||
| 645 | return | ||
| 646 | |||
| 647 | ; | ||
| 648 | ; Checks if the device is over the net or not. Returns result in ZERO flag. | ||
| 649 | ; If no device is found, the return address is popped off the stack, and a | ||
| 650 | ; jump is made to ioctl_drv_err. | ||
| 651 | ; | ||
| 652 | ; On Entry: | ||
| 653 | ; Registers same as those for Get_Driver_BL | ||
| 654 | ; | ||
| 655 | ; On Exit: | ||
| 656 | ; ZERO flag - set if not a net device | ||
| 657 | ; - reset if net device | ||
| 658 | ; ES:DI -> the device | ||
| 659 | ; | ||
| 660 | Check_If_Net: | ||
| 661 | CALL Get_Driver_BL | ||
| 662 | JC ioctl_drv_err_pop ; invalid drive letter | ||
| 663 | entry TEST_IFS_REMOTE2 | ||
| 664 | PUSH ES | ||
| 665 | PUSH DI | ||
| 666 | LES DI,[THISCDS] | ||
| 667 | TEST ES:[DI.curdir_flags],curdir_isnet | ||
| 668 | JZ belocal ;AN000; ;IFS. | ||
| 669 | LES DI,ES:[DI.curdir_ifs_hdr] ;AN000; ;IFS. test if remote | ||
| 670 | TEST_REMOTE: ;AN000; | ||
| 671 | TEST ES:[DI.ifs_attribute],IFSREMOTE;AN000; ;IFS. | ||
| 672 | belocal: | ||
| 673 | POP DI | ||
| 674 | POP ES | ||
| 675 | ret | ||
| 676 | |||
| 677 | ioctl_drv_err_pop: | ||
| 678 | pop ax ; pop off return address | ||
| 679 | jmp ioctl_drv_err | ||
| 680 | |||
| 681 | ioctl_bad_funj3: | ||
| 682 | jmp ioctl_bad_fun | ||
| 683 | |||
| 684 | ioctl_string_errj: | ||
| 685 | jmp ioctl_string_err | ||
| 686 | |||
| 687 | ; Functions 14 and 15 | ||
| 688 | ioctl_drive_owner: | ||
| 689 | Call Check_If_Net | ||
| 690 | JNZ ioctl_bad_funj3 ; There are no "net devices", and they | ||
| 691 | ; certainly don't know how to do this | ||
| 692 | ; call. | ||
| 693 | TEST ES:[DI.SDEVATT],DEV320 ; See if device can handle this | ||
| 694 | JZ ioctl_bad_funj3 ; NO | ||
| 695 | dec al | ||
| 696 | jz GetOwner | ||
| 697 | MOV [IOCALL.REQFUNC],DEVSETOWN | ||
| 698 | jmp short ioctl_do_own | ||
| 699 | GetOwner: | ||
| 700 | MOV [IOCALL.REQFUNC],DEVGETOWN | ||
| 701 | ioctl_do_own: | ||
| 702 | MOV AL,OWNHL | ||
| 703 | MOV AH,BL ; Unit number | ||
| 704 | MOV WORD PTR [IOCALL.REQLEN],AX | ||
| 705 | XOR AX,AX | ||
| 706 | MOV [IOCALL.REQSTAT],AX | ||
| 707 | PUSH ES | ||
| 708 | POP DS | ||
| 709 | ASSUME DS:NOTHING | ||
| 710 | MOV SI,DI ; DS:SI -> driver | ||
| 711 | PUSH SS | ||
| 712 | POP ES | ||
| 713 | MOV BX,OFFSET DOSGROUP:IOCALL ; ES:BX -> Call header | ||
| 714 | SaveReg <DS,SI> | ||
| 715 | invoke DEVIOCALL2 | ||
| 716 | RestoreReg <SI,DS> | ||
| 717 | test [IOCALL.REQSTAT],STERR | ||
| 718 | jnz ioctl_string_errj | ||
| 719 | MOV AL,BYTE PTR [IOCALL.REQUNIT] ; Get owner returned by device | ||
| 720 | ; owner returned is 1-based. | ||
| 721 | transfer SYS_RET_OK | ||
| 722 | |||
| 723 | EndProc $IOCTL | ||
| 724 | |||
| 725 | |||
| 726 | ;Input: ES:DI -> SFT | ||
| 727 | ;Functions: test if a remote file | ||
| 728 | ;Output: Z flag set, local file | ||
| 729 | ; | ||
| 730 | |||
| 731 | procedure TEST_IFS_REMOTE,NEAR ;AN000; | ||
| 732 | ASSUME DS:NOTHING,ES:NOTHING ;AN000; | ||
| 733 | |||
| 734 | TEST ES:[DI.sf_flags],sf_isnet ;AN000;;IFS. ifs ? | ||
| 735 | JZ nonifs ;AN000;;IFS. no | ||
| 736 | PUSH ES ;AN000;;IFS. save regs | ||
| 737 | PUSH DI ;AN000;;IFS. | ||
| 738 | LES DI,ES:[DI.sf_IFS_hdr] ;AN000;;IFS. get ifs header | ||
| 739 | JMP TEST_REMOTE ;AN000;;IFS. | ||
| 740 | nonifs: ;AN000; | ||
| 741 | return ;AN000;;IFS. | ||
| 742 | EndProc TEST_IFS_REMOTE ;AN000; | ||
| 743 | |||
| 744 | CODE ENDS | ||
| 745 | END | ||