Recent

Author Topic: how to format a removeable disk  (Read 8233 times)

mas steindorff

  • Hero Member
  • *****
  • Posts: 533
how to format a removeable disk
« on: February 05, 2010, 09:50:24 pm »
Is there any way to format a disk in windows?  I've had to resort to using a tprocess to call format.com but the dos window makes the program look cheap and the user has to "hit enter" for the command to run correctly.  (I've tried using the process,input.write() but without success).

I'm trying to lay down files on a SD card in a continuous arrangement needed for some logging hardware to use.

I'm also looking for a way to get the "removable" status of the drive so I reduce the changes of the user selecting the wrong disk.

If there is a lowlevel call to read "blocks" or sector numbers from the disk, I know how the FAT32 system is layed out so I could write my own disk peeker code

any help will be appreciated.
thank you.
mas.
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: how to format a removeable disk
« Reply #1 on: February 05, 2010, 10:26:21 pm »
I'd suggest searching MSDN for these questions.

mas steindorff

  • Hero Member
  • *****
  • Posts: 533
Re: how to format a removeable disk
« Reply #2 on: February 05, 2010, 10:33:07 pm »
sorry. when I ask how do I... I meant how do I do it in a pascal program.
The web search comes up with programs 5 years old or older that are wrappers for NT or are in another lang.  I was hoping that Lazarus or freepascal had the wrappers already in place like the diskfree() and the disksize() functions.
« Last Edit: February 05, 2010, 10:37:42 pm by mas steindorff »
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: how to format a removeable disk
« Reply #3 on: February 05, 2010, 11:56:07 pm »
I was hoping that Lazarus or freepascal had the wrappers already in place like the diskfree() and the disksize() functions.

See the docs: http://www.freepascal.org/docs-html/rtl/sysutils/diskfree.html

mas steindorff

  • Hero Member
  • *****
  • Posts: 533
Re: how to format a removeable disk
« Reply #4 on: February 15, 2010, 10:43:43 pm »
Since I did not get a good answer from anyone I thought I would post the results of my research for other people with similar problem.
A simple answer is that Lazarus / free Pascal does not have a command to format USB devices at this time.  I searched through several of the include files and found lots of other disk utilities but the format command is missing.  This is most likely due to the nature of the format command being OS dependant.
The format command lives in fmifs.dll.  The trick to calling it is to make a wraper for it.

I found a Delphi object written by Magenta Systems located at http://www.magsys.co.uk/delphi/ that was very close to what I was looking for.  The object needs a little conversion to work under Lazarus which includes defining a pointer to a Boolean and specifying the keyword "pointer" in the GetProcAddress() calls.  Some of the debug printout utilities use a vaguely referenced TRIM() function call that confuses FP unless you include the "{$mode objfpc}{$H+}  " at the beginning of the unit to tell it to use Delphi defaults.

This object looks like it can format any drive so I made sure the device was removable by using the GetDriveType() function frist.
This object was written in 2005 but as far as my research can determine, the Windows DLL is still very much a part of the XP system.  It was already on my system.
Good luck  O:-)
Mas
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

 

TinyPortal © 2005-2018