Announcement

Collapse
No announcement yet.

Direct Disk write

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tim Camarda
    replied
    Hi Amos,
    I have some source code that I can send you if you are still in need of these routines.
    BTW: My Company Omnitron, www.omnixray.com has a Disk and File Editor for FAT32 and NTFS file systems (xray1.2). Download demo here http://omnixray.com/demo.zip. NOTE: The demo only reads to disk and is limited to 35000 sectors. While I would like to pitch my product, I also would like to help with your request and like I said, send you some routines, and provide you with resources to accomplish such task's.

    keep in mind that the routines I will send are proven to work, afterall, We use em!


    ------------------

    Leave a comment:


  • Pierre Bellisle
    replied
    Hi Amos,
    To zap the partition table you need only to access Track 0, Head 0, Sector 1.
    This MBR sector contain the partition table, 64 bytes (16 * 4) at offset &H1BF.

    If you use FDisk to recreate partition then zapping those 64 bytes should
    be enough, if you want to recreate the partition programmatically then
    it is often necessary to zap the first sector of each partition
    depending of the DOS/FDisk-Format version you use.

    Since you are aware of the /autotest swicth, I'm sure you know
    the /MBR one to restore a fresh MBR.

    I did wrote a FDisk program, unfortunately, it is written in PDS/PDQ,
    it's not quite finished yet, but all the needed functions are in it...

    BootRecordInfo, ChsToLB, LbToChs,CsToInt, IntToChs, DrvParam
    PartTableRead, PartTableWrite, SectRead, SectWrite
    LockDrive (For acces under Win 9x), BootStar compatable.
    No problem with disk bigger than 8.4 gig.

    Just send me a mail if you are interested.
    Ciao.

    Also, some usefull links...
    http://www-cgi.cs.cmu.edu/afs/cs.cmu...WWW/files.html
    http://www.t13.org/
    http://www.rdlab.carnet.hr/NetLab/faq/ide.html
    http://www.vekoll.vein.hu/~cellux/pc...r_asm_eng.html
    http://www.fdisk.com/fdisk/
    http://home.teleport.com/~brainy/fat32.htm

    ------------------
    Pierre Bellisle
    eMail removed



    [This message has been edited by Pierre Bellisle (edited December 21, 2006).]

    Leave a comment:


  • Joep van Steen
    replied
    Hello,

    >At least starting with Mel's functions, I can see what is going
    >on and get a hang of it for possible other uses.

    Yes, as long as you intend to only read/write up to the first 1024 cylinders of a disk you're fine with Mel's routines. There used for MBRtool as well as it only reads/writes to the first track anyway.

    Something that may come in handy: The geometry of a disk depends up on how the BIOS translates it or if it is translated at all. Fro example, you may see your disk in the BIOS as:

    1024 cyl 255 heads 63 sector/track, or,
    1024 cyl 240 heads 63 sector/track, or untranslated,
    16000 cyl 15 heads 63 sector/track, or sometimes with SCSI,
    1024 cyl 240 heads, 32 sector/track

    If you want to read/write you have to be able to tell when to wrap to the next head or cylinder. The following function will return the drive geometry as it was detected by the BIOS:

    '=================
    sub readgeo (disk as byte,gcyl as integer,ghead as integer,gsect as integer)

    dim regc as local string
    dim regd as local string
    dim c as local string
    dim h as local string
    dim s as local string

    reg 1,2048
    reg 4,disk
    call interrupt &h13
    regc=bin$(reg(3))
    regd=bin$(reg(4))
    regc=string$(16-len(regc),48)+regc
    regd=string$(16-len(regd),48)+regd

    h=left$(regd,8)
    c=mid$(regc,9,2)+left$(regc,8)
    s=right$(regc,6)

    gcyl=val("&b"+c)
    ghead=val("&b"+h)
    gsect=val("&b"+s)

    if gcyl=1023 then gcyl=1024 'some BIOSes translate non standard, make up for that
    if ghead=254 then ghead=255 'some BIOSes translate non standard, make up for that

    end sub

    '=================

    Also handy, CHS to LBA conversion:

    '=================
    function calclba (cyl as dword,head as dword,sector as dword) as dword
    dim tmp as local dword
    if cyl=0 and head=0 and sector=0 then
    calclba=0
    else
    tmp=(((cyl * ghead) + head) * gsect) + sector - 1
    calclba=tmp
    end if
    end function
    '=================

    Good luck!
    Joep



    ------------------
    Joep

    http://www.diydatarecovery.nl

    Leave a comment:


  • Amos Vryhof
    Guest replied
    Thanks Joep,

    I do have a copy of that handy as a matter of fact!

    I still prefer to write my own code, mostly for the educational
    experience. It's easy to take someone else's software and use
    it, but still never really know how it works.

    At least starting with Mel's functions, I can see what is going
    on and get a hang of it for possible other uses. Most people
    ask, "Why reinvent the wheel?" I say "Why use your neighbor's
    wheel when you can have your own?"

    Finally, thank you to all who responded. It's great to see a
    friendly DOS community still exists.

    ------------------
    Amos
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Joep van Steen
    replied
    Hello,

    I can undertand the joy of writing this tool yourself
    However you may want to have a look at MBRtool that will do what you want as well.
    It is a command line tool that therefore can be 'batched'.

    Command line would look like: MBRtool /x /d:0 - will wipe track 0 on disk 0

    Note, MBRtool wipes the first track (normally 63 sectors) which is enough to get rid of all boot managers, hard disk overlays as EZ drive and Ontrack DDO etc ...
    Homepage for MBRtool: http://62.235.14.14/ti021213/

    Best regards,
    Joep

    ------------------
    Joep
    http://www.diydatarecovery.nl



    [This message has been edited by Joep van Steen (edited September 05, 2002).]

    Leave a comment:


  • Mel Bishop
    replied
    Originally posted by Amos Vryhof:
    .....
    I recall seeing that Int13 reads/writes won't work past 8Gb.
    .....
    You are partly right on this Amos. The routine in your original
    post will work up to 8gb. If you have a drive larger than 8gb,
    you will have to go the LBA route. LBA still uses int13 but in
    a different way. Sorry, I don't have code for this (yet).


    ------------------

    Leave a comment:


  • Amos Vryhof
    Guest replied
    I may use your unit in the future. I noticed it while doing my
    initial search. A friend and myself might be doing some drive
    imaging software, and it seems your unit would be more useful
    for this type of thing.

    Just out of curriosity, does your unit work on large hard drives
    (8Gb and larger)?

    I recall seeing that Int13 reads/writes won't work past 8Gb.

    ------------------
    Amos
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Sebastian Groeneveld
    replied
    I'd just like to mention this unit I wrote once for direct disk access under DOS (and Win9x for read-only). It's called DIRDISK, it's free to use (w/o source) and you can find it at:
    http://dracuul.tripod.com/pbdos/

    There's also a PBH help file with all the info on how to use the various routines. In my opinion they're very easy to use, but that's probably because I wrote them In case of problems or desperate need of source code, please contact me

    [edit]Hmm, since you're already in beta-testing phase, this might no longer apply to you Amos, but I leave this post because it fits well in this topic when people use the 'search forum' option[/edit]

    ------------------
    Sebastian Groeneveld
    mailto:[email protected][email protected]</A>

    [This message has been edited by Sebastian Groeneveld (edited September 04, 2002).]

    Leave a comment:


  • Amos Vryhof
    Guest replied
    The whole point of this utility is simply to make the drive
    appear unpartitioned so I can put it in a batch file to FDISK
    and format a hard drive unattended.

    FDISK will take a response file, but there is no real way to
    determine if all partitions are gone. Zeroing the first 575
    will do the trick and remove boot managers and such. Then I can
    do a simple response file for FDISK to create a single fresh
    partition, reboot the system, then run Format c: /autotest (for
    unattended format)

    Backing up the hard drive for this operation is pointless, as the
    goal is to simply wipe the MBR/Partiti8on table.

    Thanks for the help Mel, I will be beta testing in no time!



    ------------------
    Amos
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Mel Bishop
    replied
    As an added thought: If you are going to wipe the partition
    table, you might just as well go ahead and wipe the entire
    drive. Wiping the partition table means you will have to
    re-fdisk, re-format and re-install your operating system(s).
    Just as well to go with a "clean" drive right off the git-go.

    It's just a thought.


    ------------------

    Leave a comment:


  • Mel Bishop
    replied
    Originally posted by Amos Vryhof:
    Code:
    .....
    for sector%=0 to 575
      call write.hard(1,1,1,sector%,1,chr$(0))
    next
    I sure hope the hell you know what you are doing. Assuming you
    are, there are a couple of things you need to know.

    * * * * BACK UP YOUR HARD DRIVE * * * *

    The number of heads are referenced to 0. If you have 63 heads on
    the drive, they are numbered 0 to 62. Ditto on the number of
    tracks on the drive.

    Sectors per track, on the other hand, are numbered referenced to
    1. If you have 63 sectors per track, they are numbered 1 to 63.

    The code will work as advertised. However, you are apparently
    misunderstanding something:

    * * * * BACK UP YOUR HARD DRIVE * * * *

    function write.hard(d, t, h, s, n, d$)

    d = the drive number (0 thru 3). Your main boot drive is usually
    the "C" (drive 0). Partition(s) structure(s) on the drive are
    irrevellant. If your drive 0 has "C:\" & "D:\", it's all the same
    to this function. Both are treated as Drive=0.

    T, H, & S is the Track (Ref 0), Head (Ref 0) and Sector (Ref 1)

    N is the number of sectors to write to (1 to 63)

    D$ is the data you want to write. The size of the data buffer
    must be exactly 512 * N(umberOfSectors).

    PLEASE DO A BACKUP BEFORE YOU TRY WHAT YOU WANT TO TRY. One mistake
    and it's all over but the shouting.

    So to modify your code, I would suggest:

    * * * * BACK UP YOUR HARD DRIVE * * * *
    Code:
    d = 0                         ' Define the drive (0 to 3)
    n = 1                         ' Number of sectors to write
    d$ = string$(512 * n,chr$(0)) ' Data to write
                                  '
    for t = 0 to  1               ' First track only (Track 0)
      for h = 0 to 62             ' Assuming 63 heads on the drive
        for s = 1 to 63           ' Assuming 63 sectors per track
                                  '
      call write.hard(d, t, h, s, n, d$)
                                  '
        next s
      next h
    next t
    * * * * BACK UP YOUR HARD DRIVE * * * *

    --------------




    [This message has been edited by Mel Bishop (edited September 03, 2002).]

    Leave a comment:


  • Amos Vryhof
    Guest started a topic Direct Disk write

    Direct Disk write

    Hello, I am working on a program to wipe the partition table on
    a hard disk quickly.

    I found some code that Mel wrote for Int13 read/writes (below)

    I just need a little info on how to use it. The plan is to
    overwrite sector 0 - 575 with the Null character to wipe the
    Partition table and any of these boot managers that use the
    63 sector offset method. (EzDrive, GoBack, etc.)

    What I need to know is if the following code will work in theory.
    (I will test it in reality before deployment)

    Code:
    for sector%=0 to 575
      call write.hard(1,1,1,sector%,1,chr$(0))
    next
    
    OR
    
    call write.hard(1,1,1,0,575,1,string$(chr$(0),575)) 'I think this
                                                        'syntax is wrong
    Mel's code below here.

    Code:
    function read.hard$(d, t, h, s, n)     ' Read a hard drive sector
     d$ = string$(n * 512,65)               ' d = drive number (0-3)
     Reg 1, (2 * 256) + n                   ' t = track
     Reg 2, strptr(d$)                      ' h = head
     Reg 3, ((t and &hff) * 256) + s        ' s = sector
     Reg 3, Reg(3) or (t and &h300) \ &h4   ' n = number to read
     Reg 4, (h * 256) + (d or &h80)         '
     Reg 9, strseg(d$)                      '
     Call Interrupt &h13                    '
     read.hard$ = d$                        '
    end function                           '
    
    function write.hard(d, t, h, s, n, d$) ' Write a hard drive sector
     Reg 1, (3 * 256) + n                   ' d = drive (0-3)
     Reg 2, strptr(d$)                      ' t = track number
     Reg 3, ((t and &hff) * 256) + s        ' h = head number
     Reg 3, Reg(3) or (t and &h300) \ &h4   ' s = sector number
     Reg 4, (h * 256) + (d or &h80)         ' n = nbr sects to write
     Reg 9, strseg(d$)                      ' d$ = data to write
     Call Interrupt &h13                    ' Call the interrupt (13h)
    end function                           '
    ------------------
    Amos
    mailto:[email protected][email protected]</A>
Working...
X