> -----Original Message-----
> From: panamerica334 at uni.de [mailto:panamerica334 at uni.de]
> Sent: Wednesday, March 05, 2003 11:40 AM
> To: devl at freenetproject.org
> Subject: Re: [freenet-dev] Temp file problems
> 
> 
>  spake thusly:
> >> > Okay, it seems my original idea isn't as widely usable 
> as I had hoped.
> >> > So I have:
> >> 
> >> Regarding disk space management, is there any way for fred 
> to know how
> >> full the current partition is? Not just how much space it 
> is using for
> >> itself. I suspect not due to java and cross-platform 
> issues. But in my
> 
> >Nope. There is absolutely no way for java code to determine how much
> >disk space is available, apart from calling some sort of native code
> >helper. This is VERY annoying.
> 
> actually there IS a way to determine free disk space:
> 
> 
> megsfree=0;
> while(canCreateARandomFileWithThisSize(1024*1024))
>       megsfree++;
> deleteAllCreatedRandomFiles();
> System.out.println("disk free: "+megsfree+" megabytes");
> 
> 
> hehehe... it simply sucks... :D
> it
> - is slow
> - is cpu hungry
> - is hd access hungry
> - wipes any deleted file from your harddisk, so you cannot 
> undelete it (annoying)
> - will break concurrent programs writing large blocks of data 
> to the hd because the disk's full

I don't know how to translate this into English, but in Greek it's called
the "kobogianitiki" method! (e.g. eat until you puke to find out how much
you can eat without puking!)

It sucks first of all because it does not determine anything. What kind of
files does it create?
- If the contents are random, like some kind of encrypted data, then you
might just have a good guess of the minimum free space, assuming you haven't
run into some other limitation of the filesystem, like maximum files per
directory!
- If you don't write anything into the file some modern filesystems might
think you want a sparse file, and won't allocate hardly anything! That could
make a 30G disk appear as 3,000,000G disk
- If you write zeroes into the file, it might be compressed by a filesystem
that supports compression into perhaps a fifth of its apparent size (maybe
even less), and you would get entirely wrong results again.

Nowadays filesystems report less and less accurately their free space just
because they are optimized to reduce resource consumption when they are
actually doing something, depending on what and how they are asked. So the
free space you see is usually only something approximate just good enough
for human consumption. I guess that's mostly the reason Java developers
didn't want to mess with this gray (dark gray?) area.

> it's just to prove that there IS a way from java to determine 
> disk space. please delete this mail as soon as you get it :D

You haven't proved anything until you've done experiments! Try it on your
system and it might just prove a nice way to crash it!

Doc

_______________________________________________
devl mailing list
devl at freenetproject.org
http://hawk.freenetproject.org:8080/cgi-bin/mailman/listinfo/devl

Reply via email to