Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I write to floppy disk sector?????

Posted on 1999-07-23
10
Medium Priority
?
1,518 Views
Last Modified: 2008-02-26
I am trying to write disk sectors of a floppy from Delphi 2.... When I use inline asm code to try this (int 13h) I get the dreaded 'Blue Screen of Death' eeeeeeeeek!

My asm code is correctly written because I can make a stand alone program that works using TASM 2.0 ... so what is wrong here? Is windows trying to keep me from using int13h? or is it a limitation of Delphi?  Could this be done from Delphi 1...someone told me that under D1 you could access memory and ports and stuff like that much easier than with D2???
I know that it IS possible to somehow write to the sectors of a floppy using a program running in Win98 because I can do it using the WinHex sector editor....Does anyone know of a free component that would allow me to write floppy sectors??????  or can anyone provide some code to do it myself???
0
Comment
Question by:Gwena
[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
10 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 1390757
Hi Gewna

There's a lot of difference when it comes to using direct hardware access under Win32. For starters, you cannot have INT calls in your Assembly programs (if they are designed for Win32).

If you're using Delphi 2, you must follow the guidelines outlined in the Win32 SDK. Topic #95 of the file 95guide.hlp (title = "Direct Access") will give you the basic information of how it works.

In short, you can only do direct disk write/read if you lock the volumes and if your function goes through Windows' VXD for that. In order to do so you must use the IOCTL functions. Here's what the SDK says:

"32-bit Windows-based applications must call the exclusive volume-locking IOCTL functions indirectly by opening VWIN32.VXD and using its DeviceIoControl interface.

In response, VWIN32.VXD issues the low-level disk I/O functions (Interrupt 13h, Interrupt 25h, and Interrupt 26h) as well as the MS-DOS Interrupt 21h file handle read, write, seek, and IOCTL functions in the context of the calling process.

32-bit Windows-based applications may safely call the Windows ReadFile, WriteFile, SetFilePointer, and DeviceIoControl functions within a level 3 lock. Other Windows or C run-time library functions should not be used while in the level 3 lock, because these functions may call other functions that are not safe inside a level 3 lock."

Has that been of any help?

Yours,

Alex
0
 
LVL 5

Author Comment

by:Gwena
ID: 1390758
Hi Alex...

Boo Hoo :'(
This is starting to sound like it's over my head (at least for the near future)
I don't have that file '95guide.hlp'  I wish I did so I could look at it.
The file 'VWIN32.VXD' does not seem to be anywhere in my windows dir (lots of other vxd's though)
I guess i'm just not going to be able to do this...unless someone can point me to
a component that can do it or point me to a complete working example that is
already coded.... I wish there was a site on the web that had all sorts of working delphi examples of low level I/O and other hard-to-do things so I could go look through them all.... I can  usually figure out a working example and adapt the code for my stuff....but I'm pretty much clueless wo the source code of a working example :'(


0
 
LVL 17

Expert Comment

by:inthe
ID: 1390759
hi Gwena,

Here is a little demo. It shows how to change the serial number
of a floppy disk.

This demo will only work under Windows 95/98.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics,
  Controls, Forms, Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

const
  VWin32_DIOC_DOS_Int25 = 2;   // direct read access
  VWin32_DIOC_DOS_Int26 = 3;  // direct write access

type
  TDevIoCtl_Reg = packed Record
  Reg_EBX   : DWord;
  Reg_EDX   : DWord;
  Reg_ECX   : DWord;
  Reg_EAX   : DWord;
  Reg_EDI   : DWord;
  Reg_ESI   : DWord;
  Reg_Flags : DWord;
end;

type
  TDiskIO = packed record
  StartSektor    : DWord;
  AnzahlSektoren : Word;
  PBuffer        : DWord;
end;

implementation

{$R *.DFM}

// read boot sector, change serial number, and
// write boot sector back

procedure TForm1.Button1Click(Sender: TObject);
var
  DevIoHandle   : THandle;
  BytesReturned : DWord;
  Reg           : TDevIoCtl_Reg;
  DiskIO        : TDiskIO;
  DatenBuffer   : Array [0..511] of Byte;   //  = 512 Bytes

  // The size of one sector can be found out with GetDiskFreeSpace
  // (normaly = 512 bytes, CD-ROMs = 2048 bytes).

begin
  // initialize DiskIO and Reg

  with DiskIO do
    begin
      StartSektor := 0;          // from sector 0
      AnzahlSektoren := 1;       //  read 1 sector
      PBuffer := DWord(@DatenBuffer);
    end;

  with Reg do
    begin
      Reg_EAX := 0;              //  drive: 0 = A, 1 = B etc.
      Reg_EBX := DWord(@DiskIO);
      Reg_ECX := $FFFF;          //  use DiskIO
    end;

  // retrieve handle for DeviceIoControl

  DevIoHandle := CreateFile(
                 '\\.\vwin32',
                 Generic_Read,
                 File_Share_Read or File_Share_Write,
                 nil,
                 Open_Existing,
                 File_Attribute_Normal,
                 0);
  // only proceed, if handle is valid

  if DevIoHandle <> Invalid_Handle_Value then
    begin
      // direct read access

      DeviceIoControl(DevIoHandle,
                      VWin32_DIOC_DOS_Int25,
                      @Reg,
                      SizeOf(Reg),
                      @Reg,
                      SizeOf(Reg),
                      BytesReturned,
                      nil);

      // new serial number = $12345678

      DatenBuffer[39] := $78;
      DatenBuffer[40] := $56;
      DatenBuffer[41] := $34;
      DatenBuffer[42] := $12;

      // direct write access

      DeviceIoControl(DevIoHandle,
                      VWin32_DIOC_DOS_Int26,
                      @Reg,
                      SizeOf(Reg),
                      @Reg,
                      SizeOf(Reg),
                      BytesReturned,
                      nil);

      // release handle

      CloseHandle(DevIoHandle);
    end;
end;

end.


Regards Barry
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Expert Comment

by:Madshi
ID: 1390760
I have some code for direct disk access under win9x (I once downloaded it from somewhere). If you are interested, give me your eMail address or write me to "madshi@gmx.net".

Regards, Madshi.
0
 
LVL 5

Author Comment

by:Gwena
ID: 1390761
Attn: Madshi :)

Yes Please send me the code!
send it to  gwena@gurlmail.com


0
 
LVL 5

Author Comment

by:Gwena
ID: 1390762
Hi inthe (Barry)

Eureka!
That code you posted WORKS....  :)
Did you write that???
I think I can pretty much just paste that into my project and get it to work...
I hope it's OK if I use it as is ??? I don't want the author of this demo to get p'd off at me ;-)
I sure wish I actually understood how this works... but as a delphi newbie it looks
very obscure... I think that I understand it enough that I can load/save any particular sector on a floppy...and that's all I needed....it would be cool if it could work under
NT as well...but maybe I can figure that out sometime later...what I'm trying to create is a delphi program that can read a floppy... then compress that data and
incorporate the data into a resource file so that you can have a stand-alone exe
that someone can run to re-create the original disk... kind of like that WinImage
program but a free version that only works with 1.44 floppies...it would be great for sending an image of a disk such as the boot up install disk for Windows 98....

Gwena
0
 
LVL 17

Expert Comment

by:inthe
ID: 1390763
Hi
>>WORKS....  :)
of course it works ;-)

>>Did you write that???
er id like to take credit but no i cant :-)
dont know the authors but it came from the swag files originally , and you can use as you wish the code could not really be wrote many other ways so you are not "stealing code" as such..
sadly i think nt needs quite a bit more work :-[
program sounds good idea,best o luck
Regards Barry
should i post a answer?

0
 
LVL 5

Author Comment

by:Gwena
ID: 1390764
ATTN Inthe (Barry)
YES! post an answer... I want you to get my 100 points :-)
You deserve them!
I have already written 2 small proggies that use the code you sent...and they work perfectly!   I could kiss you :)
0
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 1390765
lol
 >> I could kiss you :)

only if your a woman <g>

cheers glad it helped :-)
0
 

Expert Comment

by:ercanacar
ID: 1390766
can I get this example,
ercan@telebot.com ;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

704 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