News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Format Floppy Drive using DeviceIOControl... Problem.

Started by travism, October 13, 2008, 01:35:05 AM

Previous topic - Next topic

travism

Im trying to write a program using DeviceIOControl to format the tracks of a floppy disk, Every time it seems to not be able to find the drive I read i was suppose to get the handle with CreateFile then call DeviceIOControl with the format tracks parameter.. is calling like \\.\A correct? Sorry about the horrible code.

.486
.model flat,stdcall
option casemap :none

;********************************************************
; Format Floppy Drive Program
;********************************************************

include \masm32\include\windows.inc
include \masm32\macros\macros.asm

include \masm32\include\msvcrt.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\msvcrt.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

;*******************************************************
; Prototypes for our functions
;*******************************************************

findDrive   PROTO :DWORD
formatDrive PROTO :DWORD

.data

formatParameter dd "\\.\",0
pgmTitle        db "Floppy Format Utility",13,10
                db "Written by Travis M 2008",13,10,13,10,0

.data?

inDrive DWORD ?

.code
start:
      print offset pgmTitle
     
      mov inDrive,input("Drive (EG: A,B,C): ",0)
      invoke findDrive, addr inDrive

;******************************************************
; Get a drive handle to use with DeviceIOControl
;******************************************************
findDrive proc theDrive:DWORD

      ;Copy drive letter to the ACTUAL paramter buffer
      invoke szCopy,addr theDrive,addr formatParameter
     

      invoke CreateFile,addr formatParameter,GENERIC_READ or GENERIC_WRITE,
                                                             NULL,
                                                             NULL,
                                                             OPEN_EXISTING,
                                                             FILE_ATTRIBUTE_NORMAL,NULL
      cmp eax,INVALID_HANDLE_VALUE
      je driveError
      jne fDrive

driveError:
      print chr$("Error finding drive!",13,10)
      inkey
      exit

fDrive:
     inkey
     ; invoke formatDrive,eax
findDrive endp

;******************************************************
; Function to actually format drive
;******************************************************
      exit
end start



Tedd

It's "\\.\A:" :wink

And you need to add "FILE_SHARE_READ or FILE_SHARE_WRITE" for dwShareMode

No snowflake in an avalanche feels responsible.

japheth


> Sorry about the horrible code.

The code IS horrible.

You should try to learn what a PROC is. This code


      invoke findDrive, addr inDrive

;******************************************************
; Get a drive handle to use with DeviceIOControl
;******************************************************
findDrive proc theDrive:DWORD




most likely won't do what it is supposed to do.

Additionally, your formatParameter variable should be declared with the DB directive, not with DD.