29#define NEWLIB_PORT_AWARE
33#define PFS_ZONE_SIZE 8192
34#define PFS_FRAGMENT_OPT 0x00002d66
35#define PFS_FRAGMENT 0x00000000
37#if (PFS_FRAGMENT != 0)
38int pfsFormatArg[3] = { PFS_ZONE_SIZE, PFS_FRAGMENT_OPT, PFS_FRAGMENT };
40static int pfsFormatArg[1] = { PFS_ZONE_SIZE };
43#define _OMIT_SYSTEM_PARTITION
46static char *sizesString[9] = {
58static int sizesMB[9] = {
70static void hddUpdateInfo();
72static int hddStatusCurrent = 0;
73static u32 hddSize, hddFree, hddMaxPartitionSize;
82 rv = fileXioDevctl(
"hdd0:", HDIOC_STATUS, NULL, 0, NULL, 0);
84 if((rv >= 3) || (rv < 0))
90int hddCheckFormatted()
97 rv = fileXioDevctl(
"hdd0:", HDIOC_STATUS, NULL, 0, NULL, 0);
98 if((rv >= 1) || (rv < 0))
108 const char *partitionList[] = {
116 if(!hddStatusCurrent)
119 retVal = fileXioFormat(
"hdd0:", NULL, NULL, 0);
123 for(i = 0; partitionList[i] != NULL; i++)
125 retVal = fileXioFormat(
"pfs:", partitionList[i], (
const char*)&pfsFormatArg,
sizeof(pfsFormatArg));
143 if(!hddStatusCurrent)
146 hddFd = fileXioDopen(
"hdd0:");
151 rv = fileXioDread(hddFd, &dirEnt);
153 while((rv > 0) && (
count < maxEntries))
157 u32 zoneFree, zoneSize;
160 if((dirEnt.stat.attr & ATTR_SUB_PARTITION) || (dirEnt.stat.mode == FS_TYPE_EMPTY))
162 rv = fileXioDread(hddFd, &dirEnt);
167 snprintf(hddFs[
count].filename, 40,
"hdd0:%.34s", dirEnt.name);
170 if((dirEnt.name[0] ==
'_') && (dirEnt.name[1] ==
'_'))
173 strcpy(hddFs[
count].name, &dirEnt.name[2]);
175 else if(dirEnt.name[0] == FS_COMMON_PREFIX)
178 strcpy(hddFs[
count].name, &dirEnt.name[1]);
183 strcpy(hddFs[
count].name, dirEnt.name);
186#ifdef _OMIT_SYSTEM_PARTITION
187 if(hddFs[
count].fileSystemGroup == FS_GROUP_SYSTEM)
189 rv = fileXioDread(hddFd, &dirEnt);
195 printf(
"> Filename: %s\n> Name: %s\n> Type: %d\n", hddFs[
count].filename, hddFs[
count].name, hddFs[
count].fileSystemGroup);
199 partitionFd = fileXioOpen(hddFs[
count].filename, FIO_O_RDONLY);
206 rv = fileXioDread(hddFd, &dirEnt);
210 for(i = 0, size = 0; (
unsigned int)i < dirEnt.stat.
private_0 + 1; i++)
212 rv = fileXioIoctl2(partitionFd,
HIOCGETSIZE, &i, 4, NULL, 0);
213 size += (u32)rv / 2048;
216 fileXioClose(partitionFd);
224 if(dirEnt.stat.mode == FS_TYPE_PFS)
226 rv = fileXioMount(
"pfs0:", hddFs[
count].filename, FIO_MT_RDONLY);
230 zoneFree = fileXioDevctl(
"pfs0:", PDIOC_ZONEFREE, NULL, 0, NULL, 0);
231 zoneSize = fileXioDevctl(
"pfs0:", PDIOC_ZONESZ, NULL, 0, NULL, 0);
236 fileXioUmount(
"pfs0:");
241 printf(
"> Formatted: %d\n> Size: %d\n> Free: %d\n", hddFs[
count].formatted, (
int)hddFs[
count].size, (
int)hddFs[
count].freeSpace);
245 rv = fileXioDread(hddFd, &dirEnt);
248 fileXioDclose(hddFd);
257 info->hddSize = hddSize;
258 info->hddFree = hddFree;
259 info->hddMaxPartitionSize = hddMaxPartitionSize;
262static void hddUpdateInfo()
269 hddSize = (u32)fileXioDevctl(
"hdd0:",
HDIOC_TOTALSECTOR, NULL, 0, NULL, 0) / 2048;
275 hddFd = fileXioDopen(
"hdd0:");
279 rv = fileXioDread(hddFd, &infoDirEnt);
282 if(infoDirEnt.stat.mode != FS_TYPE_EMPTY)
283 hddUsed += infoDirEnt.stat.size / 2048;
285 rv = fileXioDread(hddFd, &infoDirEnt);
287 fileXioDclose(hddFd);
288 hddFree = hddSize - hddUsed;
290 hddMaxPartitionSize = (u32)fileXioDevctl(
"hdd0:",
HDIOC_MAXSECTOR, NULL, 0, NULL, 0) / 2048;
292 hddStatusCurrent = 1;
295int hddMakeFilesystem(
int fsSizeMB,
char *name,
int type)
300 int fsSizeLeft = fsSizeMB;
302 char openString[256];
306 if(!hddStatusCurrent)
314 case FS_GROUP_SYSTEM:
315 sprintf(fsName,
"__%s", name);
317 case FS_GROUP_COMMON:
318 sprintf(fsName,
"+%s", name);
321 strcpy(fsName, name);
326 sprintf(openString,
"hdd0:%s", fsName);
327 partFd = fileXioOpen(openString, FIO_O_RDONLY);
328 if(partFd > 0 || partFd == -
EACCES)
330 fileXioClose(partFd);
335 for(maxIndex = 0; maxIndex < 9; maxIndex++)
336 if((u32)(sizesMB[maxIndex]) == hddMaxPartitionSize)
340 for(useIndex = maxIndex; sizesMB[useIndex] > fsSizeMB; useIndex--);
342 for(partSize = sizesMB[useIndex]; useIndex >= 0; useIndex--,partSize = sizesMB[useIndex])
345 printf(
">>> Attempting to create main partition, size %d MB\n", partSize);
348 sprintf(openString,
"hdd0:%s,,,%s,PFS", fsName, sizesString[useIndex]);
350 printf(
">>> openString = %s\n", openString);
353 partFd = fileXioOpen(openString, FIO_O_RDWR | FIO_O_CREAT);
360 printf(
">>> Could not create Main Partition (error %d)!\n", partFd);
370 printf(
">>> Could not create Main Partition (no space)!\n");
375 fsSizeLeft -= partSize;
377 printf(
">>> Main partition of %d MB created!\n", partSize);
384 if(fsSizeLeft < partSize)
387 printf(
">>> Adjusting sub size: %d MB to ", sizesMB[useIndex]);
389 for(useIndex = maxIndex; sizesMB[useIndex] > fsSizeLeft; useIndex--);
390 partSize = sizesMB[useIndex];
393 printf(
"%d MB\n", sizesMB[useIndex]);
399 printf(
">>> Attempting to create sub partition of size %d MB\n", sizesMB[useIndex]);
401 retVal = fileXioIoctl2(partFd, HIOCADDSUB, sizesString[useIndex], strlen(sizesString[useIndex]) + 1, NULL, 0);
407 partSize = sizesMB[useIndex];
413 printf(
">>> Out of sizes to try. Giving up.\n");
418 printf(
">>> Subpartition alloc FAILED! Trying with size of %d MB\n", partSize);
424 else if(retVal == -
EFBIG)
429 printf(
">>> Sub creation successfull!\n");
435 printf(
">>> Unknown error while creating sub: %d\n", retVal);
439 fsSizeLeft -= sizesMB[useIndex];
442 fileXioClose(partFd);
444 sprintf(openString,
"hdd0:%s", fsName);
445 retVal = fileXioFormat(
"pfs:", openString, (
const char*)&pfsFormatArg,
sizeof(pfsFormatArg));
449 printf(
">>> Failed to format new partition: %d\n", retVal);
456 return fsSizeMB - fsSizeLeft;
463 if(!hddStatusCurrent)
478 int fsSizeLeft = extraMB;
482 if(!hddStatusCurrent)
489 for(maxIndex = 0; maxIndex < 9; maxIndex++)
490 if((u32)(sizesMB[maxIndex]) == hddMaxPartitionSize)
494 for(useIndex = maxIndex; sizesMB[useIndex] > extraMB; useIndex--);
496 partSize = sizesMB[useIndex];
499 partFd = fileXioOpen(fs->
filename, FIO_O_RDWR);
506 if(fsSizeLeft < partSize)
509 printf(
">>> Adjusting sub size: %d MB to ", sizesMB[useIndex]);
511 for(useIndex = maxIndex; sizesMB[useIndex] > fsSizeLeft; useIndex--);
512 partSize = sizesMB[useIndex];
515 printf(
"%d MB\n", sizesMB[useIndex]);
521 printf(
">>> Attempting to create sub partition of size %d MB\n", sizesMB[useIndex]);
523 retVal = fileXioIoctl2(partFd, HIOCADDSUB, sizesString[useIndex], strlen(sizesString[useIndex]) + 1, NULL, 0);
529 partSize = sizesMB[useIndex];
535 printf(
">>> Out of sizes to try. Giving up.\n");
540 printf(
">>> Subpartition alloc FAILED! Trying with size of %d MB\n", partSize);
546 else if(retVal == -
EFBIG)
551 printf(
">>> Sub creation successfull!\n");
557 printf(
">>> Unknown error while creating sub: %d\n", retVal);
561 fsSizeLeft -= sizesMB[useIndex];
564 fileXioClose(partFd);
568 return extraMB - fsSizeLeft;
#define HDIOC_TOTALSECTOR
u32 count
start sector of fragmented bd/file