Jump to content




Recent Status Updates

  • Photo
      15 Nov
    duzamucha

    Hi, I am final year Interior Design Student from University of Huddersfield. I am currently working on my final major project which is going to be linked to coding. I was hoping that you could help me with my research. I have prepared a short survey, it would be a massive help if you could fill it in for me. It takes less than 2 minutes to complete, I promise. Here is the link: https://www.surveymonkey.com/s/73XLJKK Thank you so much in advance!

View All Updates

Developed by TechBiz Xccelerator
Photo
- - - - -

Making a Drive Full!

diskfree tfilestream

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 05 March 2013 - 08:41 AM

hey all my friends!
I've got a small and easy question! I want to full the Drive D with dummy file. I used the follwing code, but sometimes it works and sometimes not.
what's the problem???




 

var Dummy_File : TFileStream;
     Free_Space : Int64;
begin

Free_Space := DiskFree(4);

Dummy_File := TFileStream.Create('D:\Dummy_File.dum',fmCreate);

Dummy_File.Size := Free_Space;

//Even deleting the following line, wont change any thing
Dummy_File.Free;

end;
 

 


Edited by Roger, 05 March 2013 - 09:49 AM.
added code tags


#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,320 posts

Posted 05 March 2013 - 09:00 AM

Please enclose your codes with CODES tags (see button with pic like this: <>?). That would make your code easier to read.

 

On the topic, afaik setting TFileStream.size does not change the file's actual size. You need to use Write (and supply the data to be written) to "increase" the associated file's size. Actually it amazes me if you really found even just one occasion that the code successfully filled up a drive (unless the drive already full to begin with).


Edited by LuthfiHakim, 05 March 2013 - 09:01 AM.


#3 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 05 March 2013 - 10:08 AM

1- so, let say the code is wrong. but if we change the code to :

Dummy_File.Size := 40000;  

the code works and create a file with 40000 kb very fast.

-----

2- The "Write" method, writes to the file. it gives 2 arguments: first buffer and the next one counts. The "Count" is a Word variable and it seems that we should use a loop. Am I right?

--

however, do you have a better way?

Thanks.

 

 

 




#4 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,320 posts

Posted 05 March 2013 - 02:20 PM

1- so, let say the code is wrong. but if we change the code to :
Dummy_File.Size := 40000;  
the code works and create a file with 40000 kb very fast.

I never actually tested that before. But a peek into TFileStream told me that setting the size would execute windows api SetEndOfFile which can extend size of the file. So you are correct. That code can be used to increase size of a file, with random content.

It was my mistake. Sorry.

 

 

-----
2- The "Write" method, writes to the file. it gives 2 arguments: first buffer and the next one counts. The "Count" is a Word variable and it seems that we should use a loop. Am I right?
--
however, do you have a better way?
Thanks.

 

Since your "trick" is actually working, you should not try this. It would slow you down with buffer management.

 


There are two possible causes I can think of that might made your code failed.

 

  1. Your code would failed when the freespace size is over 232-2. Because the calling to SetFilePointer did not include lpDistanceToMoveHigh parameter. If you include this parameter, you can "create" file of size up to 264-2 (in theory, other limitations still apply). See this msdn page to see what they say about SetFilePointer.
     
  2. You freespace size exceeds maximum file size limitation imposed by WIndows or filesystem, e.g. FAT, FAT32, NTFS. See this page for more info of maximum file size.

My suggestion would be to use several files to fill the drive. Each with maximum size of 2GB or 4GB.


Edited by LuthfiHakim, 05 March 2013 - 07:36 PM.


#5 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 05 March 2013 - 03:18 PM

Now that you say I'm right with the Dummy_File.Size := Free_Space;

why It gives error: not enough space?????????

 

I did read the doc and there was no more info.

what's the problem???



#6 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,320 posts

Posted 05 March 2013 - 07:42 PM

First you need to compare freespace size reported by your code with one reported by other tool(s), like Windows Explorer or Command Prompt. Also files actually stored in block of sectors. There is a chance that your freespace size exceeds actual free available sectors. This is possible if the freespace size includes unused space inside sectors.

 

I think I will try this if I have more free time and small enough drive.



#7 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3,533 posts

Posted 05 March 2013 - 08:55 PM

Exactly as last Luthfi's answer. In addition Free space isn't a constant but a variable, there is many programs using temporary storage all the time, services too. so you might have some size now, and another different amount of free space the next second.



#8 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 06 March 2013 - 12:51 AM

Surely I compared it before posting my problem!
Even I wanted to create a dummy file on a drive that is not in use(like win drive) like D:\ or E:\
I checked the drive bu Unlocker to see if a program is using file on D:\ or E:\  but there was no program.
even I turned System Restore Service off, in order not to use Folder: System Volume information
I checked the free space every time before filling it with dumms!!

Microsoft MUST think about this issue!!



any idea?



#9 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,320 posts

Posted 07 March 2013 - 07:47 PM

I tried to compare freespace size returned by DiskFree and from GetDiskFree. The latter gives you detailed of free clusters, sectors per clusters, sector size, etc (need to do some arithmetic to get the actual freespace). And they both returned the same number. So we can forget the possibility of DiskFree returning freespaces inside used sectors.

However you haven't told us the average freespace size you've got for the disk. Perhaps you have just hit the maximum file size allowed for the disk?

#10 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 08 March 2013 - 01:13 AM

Hey LuthfiHakim what do you mean by clusters, sectors and other stuffs?

Delphi Doc about GetDiskFreeSpace:

The GetDiskFreeSpace function cannot report volume sizes that are greater than 2 gigabytes (GB). To ensure that your application works with large capacity hard drives, use the GetDiskFreeSpaceEx function.

 

I even switched to GetDiskFreeSpaceEx but again didn't work.

look at this:

www.swissdelphicenter.ch/torry/showcode.php?id=654

 

It gets more complicated!!

Finally, How do I fill a damn drive?!!



#11 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,320 posts

Posted 08 March 2013 - 05:26 AM

Hey LuthfiHakim what do you mean by clusters, sectors and other stuffs?

If you haven't already understand these, then it would take a while to explain this to you. Currently I am quite busy, and also I don't see it plays important role here. So I will explain these to you later.

[size=Delphi Doc about [b]GetDiskFreeSpace:

The GetDiskFreeSpace function cannot report volume sizes that are greater than 2 gigabytes (GB). To ensure that your application works with large capacity hard drives, use the GetDiskFreeSpaceEx function.
 
I even switched to GetDiskFreeSpaceEx but again didn't work.
look at this:
www.swissdelphicenter.ch/torry/showcode.php?id=654

I don't see why you need to try to switch to GetDiskFreeSpaceEx. DiskFree already provides you good information.

It gets more complicated!!

Not really.

Finally, How do I fill a damn drive?!!

You want serious answer or joking answer?
  • Serious answer:
    Go get a bucket of water and fill half of it with sand. If you can't fill the drive with this, I dont' know what.
  • Joking answer:
    Please let me know the average free space size you got from that d**n drive!


#12 Saeed7007

Saeed7007

    CC Regular

  • Member
  • PipPipPip
  • 39 posts

Posted 08 March 2013 - 06:03 AM

Surely I know what are clusters, sectors..
I mean this damn function:
GetDiskFreeSpace
plays with bytes, not cluster.

there is no serious answer or joking answer. there should be just a "answer".

average free space size: one drive 14 GIG, the other one 4 GIG






Powered by binpress