mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 20:06:43 +00:00
Improve formatting
This commit is contained in:
parent
8731550688
commit
527cdae1a6
4 changed files with 90 additions and 53 deletions
|
@ -6122,7 +6122,6 @@ FRESULT f_fdisk (
|
||||||
e_hd = (BYTE)(n - 1);
|
e_hd = (BYTE)(n - 1);
|
||||||
sz_cyl = 63 * n;
|
sz_cyl = 63 * n;
|
||||||
tot_cyl = sz_disk / sz_cyl;
|
tot_cyl = sz_disk / sz_cyl;
|
||||||
gfx_printf("tot_cyl: %d\nsz_disk: %d\nsz_cyl: %d\n", tot_cyl, sz_disk, sz_cyl);
|
|
||||||
|
|
||||||
/* Create partition table */
|
/* Create partition table */
|
||||||
mem_set(buf, 0, FF_MAX_SS);
|
mem_set(buf, 0, FF_MAX_SS);
|
||||||
|
|
|
@ -115,7 +115,7 @@ void viewbytes(char *path){
|
||||||
clearscreen();
|
clearscreen();
|
||||||
res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING);
|
res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING);
|
||||||
if (res != FR_OK){
|
if (res != FR_OK){
|
||||||
message("fuck", COLOR_RED);
|
message("File Opening Failed", COLOR_RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,8 @@ void viewbytes(char *path){
|
||||||
|
|
||||||
res = f_read(&in, &print, 2048 * sizeof(u8), &size);
|
res = f_read(&in, &print, 2048 * sizeof(u8), &size);
|
||||||
if (res != FR_OK){
|
if (res != FR_OK){
|
||||||
message("ohgod", COLOR_RED);
|
message("Reading Failed", COLOR_RED);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printbytes(print, size, offset * 16);
|
printbytes(print, size, offset * 16);
|
||||||
|
@ -145,6 +146,47 @@ void viewbytes(char *path){
|
||||||
f_close(&in);
|
f_close(&in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int copyfile(const char *locin, const char *locout, bool print){
|
||||||
|
FIL in, out;
|
||||||
|
u64 sizeoffile, sizecopied = 0;
|
||||||
|
UINT temp1, temp2;
|
||||||
|
u8 *buff;
|
||||||
|
|
||||||
|
if (!strcmp(locin, locout)){
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f_open(&in, locin, FA_READ | FA_OPEN_EXISTING)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
buff = malloc (BUFSIZE);
|
||||||
|
sizeoffile = f_size(&in);
|
||||||
|
|
||||||
|
while (sizeoffile > BUFSIZE){
|
||||||
|
if (f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))
|
||||||
|
return 3;
|
||||||
|
if (f_write(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
if (temp1 != temp2)
|
||||||
|
return 5;
|
||||||
|
|
||||||
|
sizeoffile -= temp1;
|
||||||
|
sizecopied += temp1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_close(&in);
|
||||||
|
f_close(&out);
|
||||||
|
free(buff);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void addobject(char* name, int spot, bool isfol, bool isarc){
|
void addobject(char* name, int spot, bool isfol, bool isarc){
|
||||||
size_t size = strlen(name) + 1;
|
size_t size = strlen(name) + 1;
|
||||||
fileobjects[spot].property = 0;
|
fileobjects[spot].property = 0;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#define OPERATION (1 << 1)
|
#define OPERATION (1 << 1)
|
||||||
|
|
||||||
|
#define BUFSIZE 32768
|
||||||
|
|
||||||
/* Bit table for property:
|
/* Bit table for property:
|
||||||
0000 0001: Directory bit
|
0000 0001: Directory bit
|
||||||
0000 0010: Archive bit
|
0000 0010: Archive bit
|
||||||
|
|
|
@ -7,15 +7,18 @@
|
||||||
#include "../utils/util.h"
|
#include "../utils/util.h"
|
||||||
#include "../utils/types.h"
|
#include "../utils/types.h"
|
||||||
#include "../libs/fatfs/diskio.h"
|
#include "../libs/fatfs/diskio.h"
|
||||||
|
#include "../storage/sdmmc.h"
|
||||||
|
|
||||||
extern bool sd_mount();
|
extern bool sd_mount();
|
||||||
extern void sd_unmount();
|
extern void sd_unmount();
|
||||||
|
extern sdmmc_storage_t sd_storage;
|
||||||
|
|
||||||
void displayinfo(){
|
void displayinfo(){
|
||||||
clearscreen();
|
clearscreen();
|
||||||
|
|
||||||
FATFS *fs;
|
FATFS *fs;
|
||||||
DWORD fre_clust, fre_sect, tot_sect, temp_sect, sz_disk;
|
DWORD fre_clust, fre_sect, tot_sect, temp_sect, sz_disk;
|
||||||
|
s64 capacity;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
gfx_printf("Getting storage info: please wait...");
|
gfx_printf("Getting storage info: please wait...");
|
||||||
|
@ -33,10 +36,10 @@ void displayinfo(){
|
||||||
|
|
||||||
gfx_printf("\n%k1st part: %d\n2nd part: 61145088\n\n%k", COLOR_RED, temp_sect, COLOR_WHITE);
|
gfx_printf("\n%k1st part: %d\n2nd part: 61145088\n\n%k", COLOR_RED, temp_sect, COLOR_WHITE);
|
||||||
|
|
||||||
disk_initialize(0);
|
capacity = sd_storage.csd.capacity;
|
||||||
disk_ioctl(0, GET_SECTOR_COUNT, &sz_disk);
|
capacity -= 61145088;
|
||||||
|
|
||||||
gfx_printf("total sectors: %d", sz_disk);
|
gfx_printf("\n%k1st part: %d\n2nd part: 61145088\n\n%k", COLOR_RED, capacity, COLOR_WHITE);
|
||||||
|
|
||||||
btn_wait();
|
btn_wait();
|
||||||
}
|
}
|
||||||
|
@ -65,47 +68,54 @@ void displaygpio(){
|
||||||
void format(){
|
void format(){
|
||||||
clearscreen();
|
clearscreen();
|
||||||
int res;
|
int res;
|
||||||
|
bool fatalerror = false;
|
||||||
|
|
||||||
u32 timer;
|
u32 timer, totalsectors;
|
||||||
FATFS *fs;
|
|
||||||
DWORD fre_clust, tot_sect, temp_sect;
|
|
||||||
BYTE work[FF_MAX_SS];
|
BYTE work[FF_MAX_SS];
|
||||||
DWORD plist[] = {188928257, 61145089, 0};
|
DWORD plist[] = {666, 61145088};
|
||||||
DWORD sectsize = 16 * 512;
|
DWORD clustsize = 16 * 512;
|
||||||
BYTE formatoptions = 0;
|
BYTE formatoptions = 0;
|
||||||
formatoptions |= (FM_FAT32);
|
formatoptions |= (FM_FAT32);
|
||||||
formatoptions |= (FM_SFD);
|
formatoptions |= (FM_SFD);
|
||||||
|
|
||||||
timer = get_tmr_s();
|
timer = get_tmr_s();
|
||||||
gfx_printf("Getting free cluster info from 1st partition");
|
|
||||||
|
|
||||||
if (res = f_getfree("sd:", &fre_clust, &fs))
|
totalsectors = sd_storage.csd.capacity;
|
||||||
gfx_printf("%kGetfree failed! errcode %d", COLOR_ORANGE, res);
|
|
||||||
else {
|
if (totalsectors < 61145088){
|
||||||
tot_sect = (fs->n_fatent - 2) * fs->csize;
|
gfx_printf("%k\nNot enough free space for emummc!", COLOR_RED);
|
||||||
temp_sect = tot_sect;
|
fatalerror = true;
|
||||||
temp_sect -= 61145089;
|
|
||||||
gfx_printf("Total sectors: %d\nFree after emummc: %d\n\n", tot_sect, temp_sect);
|
|
||||||
if (temp_sect < 0)
|
|
||||||
gfx_printf("%kNot enough space free!\n", COLOR_ORANGE);
|
|
||||||
else {
|
|
||||||
gfx_printf("Partitioning sd...\nPartition1 size: %d\nPartition2 size: %d\n", plist[0], plist[1]);
|
|
||||||
plist[0] = temp_sect;
|
|
||||||
if (res = f_fdisk(0, plist, &work))
|
|
||||||
gfx_printf("Partitioning failed! errcode %d\n", res);
|
|
||||||
else {
|
|
||||||
gfx_printf("\nFormatting FAT32 Partition:\n");
|
|
||||||
if (res = f_mkfs("0:", formatoptions, sectsize, &work, sizeof work))
|
|
||||||
gfx_printf("%kFormat failed! errcode %d\n", res);
|
|
||||||
else {
|
|
||||||
gfx_printf("Smells like a formatted SD\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res){
|
if (!fatalerror){
|
||||||
sd_unmount();
|
plist[0] = totalsectors - 61145088;
|
||||||
|
gfx_printf("\nStarting SD partitioning:\nTotalSectors: %d\nPartition1 (SD): %d\nPartition2 (EMUMMC): %d\n", totalsectors, plist[0], plist[1]);
|
||||||
|
gfx_printf("\nPartitioning SD...\n");
|
||||||
|
res = f_fdisk(0, plist, &work);
|
||||||
|
|
||||||
|
if (res){
|
||||||
|
gfx_printf("%kf_fdisk returned %d!\n", COLOR_RED, res);
|
||||||
|
fatalerror = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gfx_printf("Done!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fatalerror){
|
||||||
|
gfx_printf("\n\nFormatting Partition1...\n");
|
||||||
|
res = f_mkfs("0:", formatoptions, clustsize, &work, sizeof work);
|
||||||
|
|
||||||
|
if (res){
|
||||||
|
gfx_printf("%kf_mkfs returned %d!\n", COLOR_RED, res);
|
||||||
|
fatalerror = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gfx_printf("Smells like a formatted SD\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
sd_unmount();
|
||||||
|
|
||||||
|
if (!fatalerror){
|
||||||
if (!sd_mount())
|
if (!sd_mount())
|
||||||
gfx_printf("%kSd failed to mount!\n", COLOR_ORANGE);
|
gfx_printf("%kSd failed to mount!\n", COLOR_ORANGE);
|
||||||
else {
|
else {
|
||||||
|
@ -115,20 +125,4 @@ void format(){
|
||||||
|
|
||||||
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
gfx_printf("\nPress any button to return%k\nTotal time taken: %ds", COLOR_WHITE, (get_tmr_s() - timer));
|
||||||
btn_wait();
|
btn_wait();
|
||||||
|
|
||||||
/*
|
|
||||||
res = f_fdisk(0, plist, &work);
|
|
||||||
gfx_printf("f_fdisk partdrive: %d\n", res);
|
|
||||||
|
|
||||||
if (!res){
|
|
||||||
res = f_mkfs("0:", muhoptions, sectsize, &work, sizeof work);
|
|
||||||
gfx_printf("f_mkfs0 res: %d\n", res);
|
|
||||||
}
|
|
||||||
|
|
||||||
sd_unmount();
|
|
||||||
res = sd_mount();
|
|
||||||
|
|
||||||
gfx_printf("sd_mount res: %s", (res ? "1" : "0"));
|
|
||||||
btn_wait();
|
|
||||||
*/
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue