Link to home
Start Free TrialLog in
Avatar of Okey
Okey

asked on

How to Lock a Drive from DOS on Windows

I wannted to do Direct Drive IO.
I can read directly but write is blocked!
Try to lock up Drive for so that Write to drive isn't blocked,
but the system is normally crashing then when I do any Direct Drive IO!
Ralph Brown has commented that Lock is only allocating 26 Bytes, but 32 Bytes Space using!
Saw someone doin it maybe over IOCTL-INT-API.

How to lock a drive in Pascal and assembler without causing a systemcrash through buggy Lock-command?
Avatar of dbrunton
dbrunton
Flag of New Zealand image

Avatar of Okey
Okey

ASKER

Links are very nice,
but I didn't got my program running!

OK I could do an EXEC(GETENV('COMSPEC'),'/C LOCK C:');
in TRUE TYPE DOS,
But in windows,
it seems that something is just obtaing an exclusive locklevel.

So can someone write a snippet which runs upwards WIN9X?

This is my testing snippet
(and I'am really not satisfied with!):

PROGRAM TEST_DIRECT_DRIVE_IO_BY_WRITING_VOLUMEID;
USES DOS;
TYPE
 T_FAT32_BS=RECORD
  BS_jmpBoot               :ARRAY[1..03] OF BYTE;
  BS_OEMName               :ARRAY[1..08] OF CHAR;
  BPB_BytsPerSec           :                WORD;
  BPB_SecPerClus           :                BYTE;
  BPB_RsvdSecCnt           :                WORD;
  BPB_NumFATs              :                BYTE;
  BPB_RootEntCnt           :                WORD;
  BPB_TotSec16             :                WORD;
  BPB_Media                :                BYTE;
  BPB_FATSz16              :                WORD;
  BPB_SecPerTrk            :                WORD;
  BPB_NumHeads             :                WORD;
  BPB_HiddSec              :             LONGINT;
  BPB_TotSec32             :             LONGINT;
  BPB_FATSz32              :             LONGINT;
  BPB_ExtFlags             :                WORD;
  BPB_FSVer                :                WORD;
  BPB_RootClus             :             LONGINT;
  BPB_FSInfo               :                WORD;
  BPB_BkBootSec            :                WORD;
  BPB_Reserved             :ARRAY[1..12] OF BYTE;
  BS_DrvNum                :                BYTE;
  BS_Reserved1             :                BYTE;
  BS_BootSig               :                BYTE;
  BS_VolID                 :             LONGINT;
  BS_VolLab                :ARRAY[1..11] OF CHAR;
  BS_FilSysType            :ARRAY[1..08] OF CHAR;
  Executable_Code          :ARRAY[1..356]OF BYTE;
  First_Partition          :ARRAY[1..$10]OF BYTE;
  Second_Partition         :ARRAY[1..$10]OF BYTE;
  Third_Partition          :ARRAY[1..$10]OF BYTE;
  Last_Partition           :ARRAY[1..$10]OF BYTE;
  Executable_Marker        :                Word;
 END;

 T_WIN95_SECTOR_IO_INFO_PARAMETER_BLOCK=RECORD
  No:LONGINT;
  Count :WORD;
  Buffer :POINTER
 END;
{____________________________________________________________________________
}
CONST
 READ_UNKOWN_SECTOR=0;
 WRITE_UNKOWN_SECTOR=1;
{____________________________________________________________________________
}
Function WIN95_SECTOR_IO(DRIVE:BYTE;INFOBUF:POINTER;FLAGS:WORD):BOOLEAN;
ASSEMBLER;
ASM
 PUSH  DS
 PUSHA
 MOV   AX,$7305
 MOV   CX,$FFFF
 MOV   DL,DRIVE
 MOV   SI,FLAGS
 LDS   BX,INFOBUF
 INT   21H
 POPA
 POP   DS
 JNC   @ENDE
 MOV   AX,FALSE
@ENDE:
END;
VAR
 BS32:T_FAT32_BS;
 WIN95_SECTOR_IO_INFO_PARAMETER_BLOCK:T_WIN95_SECTOR_IO_INFO_PARAMETER_BLOCK;
 PTR_W95_SEC_INF_PB:^T_WIN95_SECTOR_IO_INFO_PARAMETER_BLOCK;
CONST
 LOGIC_DRIVE_NO=3;
BEGIN

 {SET WIN95 DIRECT DRIVE SECTOR IO PARAMETERBLOCK}
 PTR_W95_SEC_INF_PB:=ADDR(WIN95_SECTOR_IO_INFO_PARAMETER_BLOCK);
 WITH WIN95_SECTOR_IO_INFO_PARAMETER_BLOCK
  DO BEGIN
      No:=0;
      Count:=1;
      Buffer:=ADDR(BS32);
     END;
 {
  READING THE MASTER BOOT RECORD AND
  OUTPUT TO SCREEN,
  IF SECTOR READING WAS SUCCESSFUL.
 }
 WRITELN('SECTOR IO:',
         WIN95_SECTOR_IO(LOGIC_DRIVE_NO,
                         PTR_W95_SEC_INF_PB,
                         READ_UNKOWN_SECTOR
                        )
        );
 {EXCHANGING THE VOLUME-ID-FIELD IN BS32 RECORD OF READ BOOT-SECTOR.}
 BS32.BS_VOLID:=0;

 {
  CALLING DOS LOCK-COMMAND
  THEN REWRITEING MASTER BOOT SECTOR
  AND CALLING DOS UNLOCK-COMMAND
  (
   THIS METHOD RUNS IN TRUE TYPE DOS WELL,
   BUT IN WIN98,
   THE UN/LOCK-COMMAND IS UNABLE TO DO A UN/LOCK,
   SO THAT THE USE OF THIS IO-METHOD CAUSES AN EXCEPTION CHAIN,
   UNTIL SYSTEM TOTALLY CRASHES!

   THE USE OF THIS IO-METHOD UNDER WIN98
   NORMALLY CAUSES AN ERROR/TRAP MESSAGE LIKE:
   ``OLD DOS PROGRAM IS ...oo
   ``TRYING DIRECTLY TO WRITE ON HARDDISK ...oo
   ``DO YOU WANT TO ...oo
   ``YES RUN ON WITHOUT WRITEoo<=|=>`` NO ABORT PROGRAM oo
   YOU CAN CONTINUE BUT WRITE OPPERATION WONT SUCCEED!
  )
 }
 
 SWAPVECTORS;
 EXEC(GETENV('COMSPEC'),'/c LOCK C:');
 SWAPVECTORS;

 WRITELN('SECTOR IO:',
          WIN95_SECTOR_IO(LOGIC_DRIVE_NO,
                          PTR_W95_SEC_INF_PB,
                          WRITE_UNKOWN_SECTOR
                         )
        );

 SWAPVECTORS;
 EXEC(GETENV('COMSPEC'),'/c UNLOCK C:');
 SWAPVECTORS;

 WRITELN('SECTOR IO:',WIN95_SECTOR_IO(LOGIC_DRIVE_NO,PTR_W95_SEC_INF_PB,READ_UNKOWN_SECTOR));
END.
Avatar of Okey

ASKER

Can someone maybe explain something about Volume locking?

I've heard,
that there is a tool for obtaining the right to access lock-levels under WIN9X!
Knows someone something about it?

How is this with obtaining lock levels under WIN.NT?
Knows someone something about it?

ASKER CERTIFIED SOLUTION
Avatar of dbrunton
dbrunton
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Okey

ASKER

Hmmhhhh,

I'm very sory but It seems that Ive written this fast and easy readable example somehow a little bit wrong! :-(
I won't place here any corrections to this,
because I think everyone who could answer this question somehow will know how this code has to look like and what it needs to be run propably.

Again a thanks to dbrunton!

If someone knows something I'll stay locked at this question,
but I'll give the points away and accept dbrunton's answer now!