Free Space on Flash0?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Free Space on Flash0?

Post by Art »

Hi Guys,
Is there a fix to this routine, or possibly another, that will give the amount
of available space on flash0, or flash1 for that matter?
I tried the obvious replacing the "ms0:" string, and I don't know what the
hex argument in the command is for, or what to try replacing it with.

Code: Select all

int i;

unsigned int buf[5];
unsigned int *pbuf = buf;
sceIoDevctl("ms0:", 0x02425818, &pbuf, sizeof(pbuf), 0, 0);

for &#40;i=0; i<5; i++&#41;;
pspDebugScreenPrintf&#40;"Free &#58; %d bytes\n", buf&#91;2&#93; * buf&#91;3&#93; * buf&#91;4&#93;&#41;;  
Any help appreciated.
Cheers, Art.
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

This devctl will not work for flash as it is a memory stick command. A devctl is a raw command sent to a device, so flash will definitively not have the same kind of commands as it is not the same type of device...
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

well that's a bummer.
I wonder if I could find it anywhere in a raw binary dump of all the
nand filesystems...
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

Surely you know the size of the NAND, since it is fixed.

So just subtract the size of all the files that are there?

It might not be 100% accurate, due to possible block inefficiency, and I don't know whether IdStorage counts in the NAND size specification, but it should be good enough for most purposes.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
User avatar
ryoko_no_usagi
Posts: 65
Joined: Tue Nov 29, 2005 4:47 pm

Post by ryoko_no_usagi »

flash0 is formatted as 24MB and flash1 as 4MB, as far as I recall. Might have changed in later fws (especially 3.00 I'm guessing).
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

So just subtract the size of all the files that are there?
That looks to be the only option.
A little messy, and slow, but if it's the only way...
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Well thanks fo rthe suggestions, I had already thought of other avenues,
but only as last resort.
I have a routine that counts the size of every file on flash0, and it accurate compared.
to a flash0 filedump size in Windows.

If I subtract the value from the 24Mb, there's a figure left that's apparently
considerably higher than the actual available space.

I suppose I need to approximate it based on the free space a 32Mb memory stick will
provide when partitioned
the same way (24Mb, 4Mb, 1Mb & 1Mb.), and with flash0 & 1 full of firmware files?????

I can't think of a better way..
kuroneko
Posts: 24
Joined: Thu Dec 08, 2005 11:32 am
Location: Chigasaki, Japan

Post by kuroneko »

Art wrote:... I have a routine that counts the size of every file on flash0, and it accurate compared to a flash0 filedump size in Windows.

If I subtract the value from the 24Mb, there's a figure left that's apparently
considerably higher than the actual available space.
If a file has non-zero size you have to take the cluster size into account. Meaning, a file with the logical size of 1 byte still allocates 16K in the NAND.

Also, directories occupy at least one cluster and after that it becomes a bit uncertain. Clearly the directory size depends on the number of entries in it (and on the length of those entries -> long name mapping), however, if you create say 1000 files which extends the directory to a size of N clusters, then you delete the first 999 files again, chances are that those N clusters are kept (rather then compacting the chain down to 1).

HTH
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Fortunately with the onofficial SE firmwares, people have recently had a
logical format performed by the app that writes the firmware to flash.

It is still very difficult.

Anyway, here's the routine I wrote for telling how much is used.
I started with the SDK sample that dumps a filesystem.
Any variables that aren't declared are global in my program.

Code: Select all

void add_file&#40;const char *read_loc, const char *write_loc, const char *name&#41; &#123;

	char readpath&#91;256&#93;;

	build_path&#40;readpath, read_loc, name, 0&#41;;

	int ffls;
	int filef_size = 0;

	ffls = sceIoOpen&#40;readpath, PSP_O_RDONLY, 0777&#41;;
	filef_size = sceIoLseek32&#40;ffls, 0, SEEK_END&#41;;
	sceIoClose&#40;ffls&#41;;

	flash_size = flash_size + filef_size;

mbflash_size = flash_size/1024;		// derive Kilobytes used
mbflash_size = mbflash_size/1024;	// derive Megabytes used
flashsi = mbflash_size;			// derive integer for counting display

	pspDebugScreenSetXY&#40;21, 28&#41;;
	printf&#40;"Flash0 Space Used&#58; %d",flashsi&#41;;
	pspDebugScreenSetXY&#40;44, 28&#41;;
	printf&#40;" Mb          "&#41;;
&#125;

void add_flash&#40;const char *root, const char *write_loc&#41; &#123;

	int dfd;
	char next_root&#91;256&#93;;
	char next_write&#91;256&#93;;

	dfd = sceIoDopen&#40;root&#41;;
	if&#40;dfd > 0&#41;
	&#123;
		SceIoDirent dir;

		while&#40;sceIoDread&#40;dfd, &dir&#41; > 0&#41;
		&#123;
			if&#40;dir.d_stat.st_attr & FIO_SO_IFDIR&#41;
			&#123;
				if&#40;dir.d_name&#91;0&#93; != '.'&#41;
				&#123;
					build_path&#40;next_write, write_loc, dir.d_name, 0&#41;;
					build_path&#40;next_root, root, dir.d_name, 1&#41;;
					add_flash&#40;next_root, next_write&#41;;
				&#125;
			&#125;
			else
			&#123;
				add_file&#40;root, write_loc, dir.d_name&#41;;
			&#125;
		&#125;
		sceIoDclose&#40;dfd&#41;;
	&#125;
&#125;
Cheers, Art.
Post Reply