1. critical error handler - Craig Gilbert,
- Posted by Lee woo seob <wslee at HHI.CO.KR> Nov 11, 1997
- 590 views
Hi Craig Gilbert, Thanks you for your contribution on the critical error handling. i downloaded your routine from Eupho home page just before, and found it works fairly well even in my computer. anyway, i want to know if your routine is applicable also to the disk access for "writing" operation(opening file in "w" mode, for example), as well as "reading". if applicable, could you make a short example program for it? Bye! -- from Lee woo seob
2. Re: critical error handler - Craig Gilbert,
- Posted by Craig Gilbert <cgilbert at CENNET.MC.PEACHNET.EDU> Nov 11, 1997
- 599 views
At 06:11 PM 11/11/97 +0900, Lee woo seob wrote: >Hi Craig Gilbert, > >Thanks you for your contribution on the critical error handling. >i downloaded your routine from Eupho home page just before, >and found it works fairly well even in my computer. You're welcome. > >anyway, i want to know if your routine is applicable also to the disk >access for "writing" operation(opening file in "w" mode, for example), >as well as "reading". >if applicable, could you make a short example program for it? > >Bye! -- from Lee woo seob > > The routine at present just checks to see if the drive is ready in general. I assume you have in mind checking to see if the disk is write-protected. For that, add the following lines to the end of the file drive.e ( test code follows): ----------------------------------------------------------------------------- sequence mTestFileName procedure force_drive_write(integer letter) -- attempt disk write on the given drive atom f integer curletter -- clumsy way of getting unique filename mTestFileName = {letter} & ":\\z" curletter = 'z' while 1 do f = open(mTestFileName,"r") if f = -1 then exit else close(f) mTestFileName = mTestFileName & curletter if length(mTestFileName) > 8 then curletter = curletter - 1 if curletter < 'a' then -- unlikely that you will go through 248 names w/out finding -- one that is unique, but just in case . . . exit end if mTestFileName = {letter} & ":\\" & curletter end if end if end while f = open(mTestFileName, "w") if f != -1 then puts(f,"test") close(f) end if return end procedure ----------------------------------------------------------------------------- global function ready_for_write(integer letter) -- This function replaces the critical error handler with it's own, -- attempts to access drive 'letter', then restores the previous -- critical error handler. -- Returns 1 if drive ready for write, 0 if not -- Note that the drive failure may or may not be a write protect error; -- call critical_error_code() for more info on the drive failure, if any sequence new_hand, data_segment atom handler_addr, status_ptr, errcode_ptr integer drive_status drive_status = 0 if not drive_exist(letter) then return drive_status end if letter = upper(letter) data_segment = int_to_bytes( get_seg(1) ) -- create error code location, preloaded w/ #ff (code not used by DOS) errcode_ptr = mem_locked(2) -- high byte is ignored but needs space poke(errcode_ptr, #FF) -- create error flag location, preloaded w/ 1 for no error status_ptr = mem_locked(1) poke(status_ptr,1) -- construct new handler new_hand = { -- save stuff #1E, -- push ds #53, -- push ebx -- load data segment #BB} & data_segment & -- mov ebx, data segment value { #53, -- push ebx #1F} & -- pop ds -- do your thing { #FE, #0D } & int_to_bytes(status_ptr) & -- dec mem { #89, #3D } & int_to_bytes(errcode_ptr) & -- mov mem, di -- acknowledge interrupt w/ ignore (zero in al) { #32, #C0 } & -- xor eal,eal -- restore stuff { #5B, -- pop ebx #1F, -- pop ds #CF} -- iretd -- set up new handler handler_addr = install_handler(new_hand, #24) -- access the drive force_drive_write(letter) -- check error status drive_status = peek(status_ptr) if drive_status = 1 then system("del " & mTestFileName,2) -- clean up else drive_status = 0 end if -- get err code mCRITICAL_CODE = peek(errcode_ptr) -- reassign INT 24h to previous critical error handler reset_handler(#24) free(status_ptr) free(errcode_ptr) return drive_status end function ----------------------------------------------------------------------------- One way to test the above is like this: if ready_for_write('a') then puts(1,"Drive A is OK.\n") else if critical_error_code() = 00 then puts(1,"Drive A is write protected.\n") else printf(1,"Error code is %x\n",{critical_error_code()}) end if end if