Mounting a Virtual Disk

Everything else that doesn't fall into one of the other PB categories.
ShDancer
User
User
Posts: 51
Joined: Sat Apr 26, 2003 5:49 am

Mounting a Virtual Disk

Post by ShDancer »

Well i was looking for some kind of virtual disk when i found Virtul Bin.
Its very nice but i found another thing that i think it can be very usefull.
I was wondering if some one is interested in porting this to Purebasic?

Heres the link's
http://www.acc.umu.se/~bosse/
or if you whant to download
http://www.acc.umu.se/~bosse/filedisk.zip

then just run this to make a small empty file on your hard disk.

Code: Select all

Procedure makeSparse(Filename.s, FileSize.l)
  Protected FileHandle.l
  Protected ReturnValue.l
  FileHandle = CreateFile(#PB_Any, Filename)
  If ( FileHandle <> 0 )
    FileSeek(FileSize - 1)
    WriteByte(0)
    CloseFile(FileHandle)
  Else
    ReturnValue = -1
  EndIf
  ProcedureReturn ReturnValue
EndProcedure

makeSparse("C:\Test.txt", 30*1024*1024) ; 30 Mbytes
After that just install the downloaded software reboot your computer and mount the File Disk.

This will add a new disk (virtual) to your windows expolorer.

The only problem is that i can only test on NTFS, i don't have any FAT Operating System to test it on.
ShDancer
User
User
Posts: 51
Joined: Sat Apr 26, 2003 5:49 am

Post by ShDancer »

Did Anyone saw or tried this???
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

Looks very interesting. Gonna check it out the next days.
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
ShDancer
User
User
Posts: 51
Joined: Sat Apr 26, 2003 5:49 am

Post by ShDancer »

Thanks, as i said i would like to port this do purebasic, i think its very usefull.

You can make something like a secure and protected disk using password and encryptation.

Or just use it to store files something like VBin ( Not a Replacement ), its easy to import/export Files.

It has several uses.

But i need help on this, my knoledge of C or C++ is almost none.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Hi ShDancer,

I haven't tried the virtual disk thing but I did notice that your little procedure is not the correct way to create a sparce file.

Example, use this command to call your procedure:

Code: Select all

makeSparse("test1.txt", 100*1024*1024)
Then check the properties of the created file...
Size: 100 MB (104,857,600 bytes)
Size on Disk: 100 MB (104,857,600 bytes)


Now try this procedure:

Code: Select all

#FSCTL_SET_SPARSE=$900C4

Procedure MKSparce(FileName.s,FileSize)
  hFile=CreateFile_(FileName,#GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#CREATE_NEW,#FILE_FLAG_NO_BUFFERING,0)
  If FileHandle<>#INVALID_HANDLE_VALUE
    If DeviceIoControl_(hFile,#FSCTL_SET_SPARSE,0,0,0,0,@Bytes,0)
      If SetFilePointer_(hFile,FileSize,0,#FILE_BEGIN)
        SetEndOfFile_(hFile)
        Result=1
      EndIf
    EndIf
    CloseHandle_(hFile)
  EndIf
  ProcedureReturn Result
EndProcedure
And use this command to call the new procedure:

Code: Select all

MKSparse("test2.txt", 100*1024*1024)
Check the file size of the new file...
Size: 100 MB (104,857,600 bytes)
Size on Disk: 16 KB (16,384 bytes) <--- 16KB !!!


A true sparce file makes the OS think it is 100MB total but actually takes up only 16kb on the hard drive. Much more efficient if there is only a small amount of data stored in it when it's being used as a virtual disk. :)
Image Image
ShDancer
User
User
Posts: 51
Joined: Sat Apr 26, 2003 5:49 am

Post by ShDancer »

Thanks in advance for the reply Paul.

Did anyone try it?
Just 10 min and one reboot. (Well more or less :) )

Until today i was involved in a project in my company
and didn't had time for pb, so now i'm free to continue
this little utility.

Can someone help me porting this to pb?
I don't understand much of C or C++ Language.

I think it could be usefull, for the comunity.

Thanks once more.
User avatar
jqn
User
User
Posts: 97
Joined: Fri Oct 31, 2003 3:04 pm

Post by jqn »

Hi,
I've ported to PB and re-designed filedisk (only C) into this little example:

http://purebasic.myftp.org/?filename=fi ... TCData.zip

Regards,
JOAQUIN
Worm
User
User
Posts: 20
Joined: Wed Apr 14, 2004 2:32 am
Location: Grand Rapids, MI
Contact:

Post by Worm »

The zip file seems to be corrupt. Could you repost?
User avatar
jqn
User
User
Posts: 97
Joined: Fri Oct 31, 2003 3:04 pm

Post by jqn »

The zip file is correct, but I've changed the case in URL. Sorry.

Try this:

http://purebasic.myftp.org/?filename=fi ... TCdata.zip

JOAQUIN
Worm
User
User
Posts: 20
Joined: Wed Apr 14, 2004 2:32 am
Location: Grand Rapids, MI
Contact:

Post by Worm »

Thanks, seems to work for me now.
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Wow, thanks for sharing! I am going to go through and try this out over the next few days.

Have you two (or anyone else for that matter) gotten around to encrypting the data in the virtual drive? How about hiding the virtual drive (or can you do that with this code, I'll have to read through the file)?

Thanks for sharing!

*thumbs up*
Intrigued - Registered PureBasic, lifetime updates user
User avatar
jqn
User
User
Posts: 97
Joined: Fri Oct 31, 2003 3:04 pm

Post by jqn »

Hi,
About encryption, see:

http://www.scherrer.cc/crypt/

I've NOT TESTED it.

JOAQUIN
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

jqn wrote:Hi,
About encryption, see:

http://www.scherrer.cc/crypt/

I've NOT TESTED it.

JOAQUIN
Thanks for the link. I see that Win9x/ME is not supported. Here's what I would need:

Win98SE/ME/2000/XP

and...

I would prefer the use of 448-bit Blowfish. The product I have out now uses 448-bit Blowfish for encryption and thus my marketing compaign can be on the same level, when I tout comments like "448-bit Blowfish encryption used! Stronger than the standard SSL connection!", or something to that effect.

I do appreciate the quick post though and offer!
Intrigued - Registered PureBasic, lifetime updates user
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Re: Mounting a Virtual Disk

Post by dagcrack »

Sorry to revive this old thread but I was wondering if someone still had a copy of TCdata.zip since the URL is down. Seemed to be hosted by jqn's home ftp server through a freeddns account which has been down/inactive for a while.

In case nobody has it, are there any alternative solutions for Windows currently?

The original mentioned code in http://www.acc.umu.se/~bosse/ can be found (latest version) here: http://www.acc.umu.se/~bosse/filedisk/filedisk-21.zip

Thanks in advance.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply