int FileMkdir( const char *path ) { char *ptr; int c; if( (ptr = strchr( path, ':' )) == NULL ) { #ifdef _DEBUG printf("FileMkdir : Invalid Path (ptr = NULL)\n"); #endif return -1; } c = ptr - path; if( !strncmp( path, "pfs", 3 ) ) { return fileXioMkdir( path, O_RDWR | O_CREAT ); } else if( !strncmp( path, "mc0:", c ) || !strncmp( path, "mc1:", c ) ) { return fioMkdir( path ); } else if( !strncmp( path, "mass:", c ) ) { return fioMkdir( path ); } else if( !strncmp( path, "smb:", c ) ) { return smbc_mkdir( path, 0666 ); } return -1; }
int AsyncFio::mkdir(const char *name) { int res; WaitSema(_ioSema); checkSync(); fileXioMkdir(name, DEFAULT_MODE); fileXioWaitAsync(FXIO_WAIT, &res); SignalSema(_ioSema); return res; }
int real_copyRTEELF(void *arg) { FILE *fin; const char *filename = rteELF; uint32_t *magic = (uint32_t *) magic_string; uint32_t elfSize = 0; const char *outputfilename; uint32_t elfNumber = 1; copyRTEELF_param_t *param = (copyRTEELF_param_t *) arg; outputfilename = param->outputFilename; elfNumber = atoi(param->elfNumber); kprintf("elfNumber 0x%08x.\n", elfNumber); kprintf("Search for elf in \"%s\".\n", filename); graphic_setPercentage(0, filename); fin = fopen(filename, "rb"); if (fin != NULL) { char *buffer; uint32_t size; filename = NULL; fseek(fin, 0, SEEK_END); size = ftell(fin); fseek(fin, 0, SEEK_SET); buffer = malloc(size); if (buffer != NULL) { FILE *fout; char *addr; char *endaddr; if (fread(buffer, size, 1, fin) != 1) { fclose(fin); free(buffer); error_printf("Can't read file."); return -3; } fclose(fin); endaddr = (char *) (((uint32_t) buffer) + size); for (addr = buffer; addr < endaddr; addr += 4) { if (*((uint32_t *)addr) == *magic) { elfNumber--; if (elfNumber == 0) { break; } } } if (*((uint32_t *)addr) == *magic) { void *code; kprintf("Found elf at file offset 0x%08x.\n", ((uint32_t) addr) - ((uint32_t) buffer)); for (code = addr + 4; code < ((void *) endaddr); code += 4) { uint32_t value; value = *((uint32_t *)code); if (value == *magic) { /* memcopy gets SBIOS in register a1 and size in register a2. */ elfSize = ((uint32_t) code) - ((uint32_t) addr); kprintf("ELF size is 0x%08x (1).\n", elfSize); break; } } if (elfSize == 0) { elfSize = ((uint32_t) endaddr) - ((uint32_t) addr); kprintf("ELF size is 0x%08x (2).\n", elfSize); } fout = fopen(outputfilename, "wb"); if (fout == NULL) { fileXioMkdir(CONFIG_DIR, 0777); fout = fopen(outputfilename, "wb"); } if (fout != NULL) { if (fwrite(addr, elfSize, 1, fout) != 1) { fclose(fout); fioRemove(outputfilename); fioRmdir(outputfilename); /* Needed because of bug in fioRemove. */ free(buffer); error_printf("Failed to write \"%s\"", outputfilename); return -5; } fclose(fout); kprintf("\"%s\" written.\n", outputfilename); } else { error_printf("Failed to open \"%s\"", outputfilename); free(buffer); return -4; } } else { error_printf("Can't find ELF."); free(buffer); return -6; } free(buffer); buffer = NULL; } else { error_printf("out of memory"); return -2; } } else { error_printf("Failed to open file \"%s\"", filename); } return 0; }
bool_t FolderCreate(nodecontext *p,const tchar_t* Path) { return fileXioMkdir(Path,FIO_S_IRUSR | FIO_S_IWUSR | FIO_S_IXUSR | FIO_S_IRGRP | FIO_S_IWGRP | FIO_S_IXGRP | FIO_S_IROTH | FIO_S_IWOTH | FIO_S_IXOTH)==0; }