PureBasic Interface to ImDisk

Share your advanced PureBasic knowledge/code with the community.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PureBasic Interface to ImDisk

Post by luis »

Cool stuff, not something I can try right now but wanted to say thanks for sharing it.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: PureBasic Interface to ImDisk

Post by Joakim Christiansen »

Might be cool for creating an encrypted cloud storage app. :D
I like logic, hence I dislike humans but love computers.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi luis, Joakim Christiansen,

You're welcome, and thank you for commenting.

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

Updated:
- added Constants, Structures, and Functions
- added folder: references
-- includes license and readme files from ImDisk

Made some minor improvements to the Service-Create/Delete scripts.

NB*: The new Functions and Structures have not been tested.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: PureBasic Interface to ImDisk

Post by RASHAD »

Hi
You did it as I expected :)
Did not test it yet but I expect again that it will be a very good stuff

Thanks JHPJHP
Egypt my love
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi RASHAD,

Thank you for the vote of confidence, I hope it meets your expectations. :mrgreen:

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

The entire list of available Functions have now been included, but I can't guarantee they've been correctly declared until I apply them to an example.

I've also added a couple new Procedures that include the option to hide the virtual drive.
- this is a rudimentary attempt to conceal the drive and is not very reliable

Some of the default options have been changed, most notably when removing the virtual device the folder and image file are not deleted.

NB*: It's worth noting that the device-driver service (imdisk.sys) is only needed for "Device" examples.
Last edited by JHPJHP on Mon Jan 12, 2015 5:52 pm, edited 2 times in total.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: PureBasic Interface to ImDisk

Post by heartbone »

That was some awesome detective and analytical work JHPJHP.
To help future sleuths I'm adding the word ramdisk to this thread. ;)

Because there are some who would try to run ricardo's program multiple times to attempt to recover the deleted video from the hard drive, this seems to be a better solution.
And don't forget to erase the RAM after use, although that wouldn't stop a determined hacker. ;)
Keep it BASIC.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi heartbone,

Thanks for the kudos.

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

Applied various updates to the package, but moving forward is slow due to a lack of API examples.
- added: References, Constants, Structures, and Macros

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

Updated the package with additional Constants and Structures, fixing various Function declarations.
- replaced the imdisk.lib file with a newer version (x86 / x64)
- updated the references with newer versions
- removed the i64 binaries
- added an additional test script (x86 / x64)

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

Updated:
- added 1 example
-- ExtendDevice.pb: extends the size of an image file

NB*: Various other improvements have been made to multiple examples.

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

Updated:
- CreateDevice.pb: added a simple GUI interface

If the created device is less then 32 MB then the format of the drive will be FAT otherwise it's NTFS.
- FAT file systems cannot be extended using ExtendDevice.pb, but the image file size will be increased


NB*: Update also includes some general improvements to the examples.
Last edited by JHPJHP on Mon Jan 19, 2015 5:10 pm, edited 1 time in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- fixed an inconsistency where the QUAD data type was required
- small update/patch to the example: ExtendDevice.pb
- removed the test scripts (didn't offer anything new)
- split the example: CreateMountPoint.pb
-- CreateMountPoint1.pb and CreateMountPoint2.pb
- split the example: RemoveMountPoint.pb
-- RemoveMountPoint1.pb and RemoveMountPoint2.pb

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

After some additional testing I noticed an issue with the DISK_GEOMETRY Structure and the LARGE_INTEGER datatype in the example: QueryDevice.pb. Even though the Structure matched the documentation I had to create an additional Structure: DISK_GEOMETRY_QUERY, modified to work with both 32bit and 64bit versions of PureBasic.

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

Updated
- added 5 examples
-- AdjustImageFileSize.pb: adjusts an image file size
-- SaveImageFile.pb: saves a device to an image file
-- SaveImageFileInteractive.pb: saves a device to an image file interactively
-- QueryDevice.pb: displays information about devices
-- GetFormattedGeometry.pb: displays information about disk drives with a valid boot record signature

AdjustImageFileSize.pb: This function is used to resize an image file to match the formatted size of the device and cannot be made larger. If the adjusted image file size is smaller then the format size, the next time it is "relinked" using the example: CreateDevice.pb the Windows Format tool will open.

SaveImageFileInteractive.pb: If the image file is saved using the built-in option: New MBR, when it is "linked" using the example: CreateDevice.pb the Windows Format tool will open.
Last edited by JHPJHP on Sat Jan 24, 2015 9:44 am, edited 3 times in total.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- added 2 examples
-- CreateDevice1.pb: creates a RAM Disk linked to the first available drive letter
-- RemoveDevice1.pb: removes the link between the drive and RAM Disk
- renamed 2 examples
-- CreateDevice.pb to CreateDevice2.pb
-- RemoveDevice.pb to RemoveDevice2.pb

I used the CrystalDiskMark tool to benchmark the speed of the RAM disk, receiving similar results to those in the following link.
- https://www.raymond.cc/blog/12-ram-disk ... ite-speed/
- these are the parameters I used to compare speed between my C:\ drive and a newly created RAM disk: 5 | 50 MB.
Last edited by JHPJHP on Tue Jan 20, 2015 4:41 am, edited 10 times in total.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: PureBasic Interface to ImDisk

Post by heartbone »

Thanks for putting this package together JHPJHP and making it better explained how to interface with it.
It is something that I am saving for probable future use,
and hope that I get to develop an application that will benefit greatly from using it.

As much as the hated Vista thrashes its C: drive, I've long wondered why the OS doesn't do more in RAM.
It sure would speed things along.
Using this really makes sense for any computationally intense work that relies on multiple file I/O, to save on wear and tear.

And thanks for the link.
It led me to this: Make Firefox Faster By Putting Profile and SQLite Database in RAMDisk something that I will try very soon.
If it makes a significant difference, I'm going to identify other areas to implement its use.
It's not the same as running the OS from a SSD, but it is cheaper, and possibly safer.
Keep it BASIC.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Hi heartbone,

You're welcome, I hope it can be of some use.

My own tests showed a speed increase from 80 MB/s ( C:\ ) to over 5000 MB/s ( RAM disk ).
- benchmark tool (5 | 50 MB): CrystalDiskMark

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

Updated:
- added the FlushFileBuffers function where appropriate.

Another option would have been to use the CreateFile function instead of the OpenFile function:

Code: Select all

CreateFile_(*lpFileName, #GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE, #Null, #OPEN_EXISTING, #FILE_FLAG_NO_BUFFERING, #Null)
I've set the max drive size (before extending) to 4GB, but if you have the RAM and would like to increase this:
- LARGE_INTEGER Structure handles QUAD type values, not to be confused with: LARGE_INTEGER union or ULARGE_INTEGER union

Code: Select all

DriveSize.LARGE_INTEGER
DriveSize\highpart = 1
DriveSize\lowpart = 1024 * 1024 * 1024
highpart.q = DriveSize\highpart * Pow(2, 32)
lowpart.q = DriveSize\lowpart * 4
Debug highpart
Debug lowpart
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- added 1 include
-- datasections.pbi
- added Constants, 1 Structure, Functions (Interfaces)
- added 2 reference files
-- imapi2fs.h, imapi2sample.cpp
- added 1 example
-- CreateMountableImage.pb: creates a mountable image file from either a device or folder location

The device examples have been updated to handle multiple links, a max size of 4 GB (ImDisk has no limit), including various other improvements.

CreateMountableImage.pb: I worked on this example for awhile, but kept hitting a wall when it came to declaring the various interfaces. Using the Microsoft site which lists the Functions alphabetically, I didn't realize my mistake until I found this post by bingo: http://www.purebasic.fr/english/viewtopic.php?t=29757.

NB*: A mountable image file cannot be created from a drive-root, or a circular reference.
JHPJHP
Addict
Addict
Posts: 2129
Joined: Sat Oct 09, 2010 3:47 am
Contact:

Re: PureBasic Interface to ImDisk

Post by JHPJHP »

Updated:
- CreateDevice2.pb: added a second button to mount an existing image file
-- an ISO video file, or a file created with the example: CreateMountableImage.pb can also be mounted
-- forcing ISO files to be mounted as a CD and IMG files to be mounted as a hard drive
- removed instances of the Function: ImDiskSetAPIFlags previously used to automatically force dismounting a drive and suppressing messages
-- RemoveDevice1.pb and RemoveDevice2.pb
--- if a drive lock cannot be established a messagebox will prompt with a "force dismount" option

NB*: Fixed a few issues in a couple examples, nothing worth documenting.
marroh
User
User
Posts: 72
Joined: Wed Aug 06, 2008 8:21 am

Re: PureBasic Interface to ImDisk

Post by marroh »

Thx! :mrgreen:
PureBASIC v5.41 LTS , Windows v8.1 x64
Forget UNICODE - Keep it BASIC !
Locked