?
Solved

How to Lock a Drive from DOS on Windows

Posted on 2003-03-23
5
Medium Priority
?
376 Views
Last Modified: 2008-03-10
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?
0
Comment
Question by:Okey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:Okey
ID: 8197160
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.
0
 
LVL 1

Author Comment

by:Okey
ID: 8204596
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?

0
 
LVL 49

Accepted Solution

by:
dbrunton earned 75 total points
ID: 8207616
May wish to post a zero point question in the Programming Section instead of the Pascal section.

Ask it there and point them to this question

http://www.experts-exchange.com/Programming/Programming_Languages/Pascal/Q_20560031.html

Tried your code and it crashed on me.
0
 
LVL 1

Author Comment

by:Okey
ID: 8233966
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!



0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question