*Fix for ntfs writing

*Cache size reduced which results in a bit slower writing but is more stable
*Fix for the gameinstaller ProgressWindow
*Added NTFS unmount on exit

WARNING:
The USBLoaderGX installer seems to be broken in some places. There are sometimes random freezes or crashes even on fat32. Those arent bad on a fat32 filesystem but can damage the whole partition on ntfs. Using the installer on ntfs is still very risky. You have been warned!
This commit is contained in:
dimok321 2010-02-25 12:08:03 +00:00
parent ce5930f297
commit 0908027ad8
18 changed files with 1233 additions and 1280 deletions

View File

@ -2,8 +2,8 @@
<app version="1">
<name> USB Loader GX</name>
<coder>USB Loader GX Team</coder>
<version>1.0 r914</version>
<release_date>201002222228</release_date>
<version>1.0 r915</version>
<release_date>201002222143</release_date>
<short_description>Loads games from USB-devices</short_description>
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.

File diff suppressed because one or more lines are too long

View File

@ -6,15 +6,15 @@
#include <sdcard/wiisd_io.h>
#include <locale.h>
#include "usbloader/sdhc.h"
#include "usbloader/usbstorage2.h"
#include "usbloader/sdhc.h"
#include "usbloader/wbfs.h"
#include "libfat/fat.h"
#include "libntfs/ntfs.h"
#include "gecko.h"
//these are the only stable and speed is good
#define CACHE 32
#define CACHE 8
#define SECTORS 64
#define SECTORS_SD 32
@ -62,7 +62,7 @@ int USBDevice_Init() {
return -1;
}
// }
fat_usb_mount = 1;
fat_usb_sec = _FAT_startSector;
#ifdef DEBUG_FAT
@ -88,7 +88,7 @@ int WBFSDevice_Init(u32 sector) {
//right now mounts first FAT-partition
//try first mount with cIOS
// if (!fatMount("WBFS", &__io_wiiums, 0, CACHE, SECTORS)) {
// if (!fatMount("WBFS", &__io_wiiums, 0, CACHE, SECTORS)) {
//try now mount with libogc
if (!fatMount("WBFS", &__io_usbstorage2, 0, CACHE, SECTORS)) {
return -1;
@ -171,7 +171,7 @@ s32 MountNTFS(u32 sector)
_FAT_mem_init();
ntfsInit(); // Call ntfs init here, to prevent locale resets
// ntfsInit resets locale settings
// which breaks unicode in console
// so we change it back to C-UTF-8
@ -195,9 +195,9 @@ s32 MountNTFS(u32 sector)
// }
} else if (wbfsDev == WBFS_DEVICE_SDHC) {
if (sdhc_mode_sd == 0) {
ret = ntfsMount("NTFS", &__io_sdhc, 0, CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER);
ret = ntfsMount("NTFS", &__io_sdhc, 0, 8, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER);
} else {
ret = ntfsMount("NTFS", &__io_sdhc, 0, CACHE, SECTORS_SD, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER);
ret = ntfsMount("NTFS", &__io_sdhc, 0, 8, SECTORS_SD, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER);
}
if (!ret) {
return -5;
@ -206,7 +206,7 @@ s32 MountNTFS(u32 sector)
fs_ntfs_mount = 1;
fs_ntfs_sec = sector; //_FAT_startSector;
return 0;
}
@ -232,25 +232,10 @@ void* _FAT_mem_allocate(size_t size)
void* _FAT_mem_align(size_t size)
{
return memalign(32, size);
return memalign(32, size);
}
void _FAT_mem_free(void *mem)
{
free(mem);
}
void* ntfs_alloc (size_t size)
{
return _FAT_mem_allocate(size);
}
void* ntfs_align (size_t size)
{
return _FAT_mem_align(size);
}
void ntfs_free (void* mem)
{
_FAT_mem_free(mem);
}

View File

@ -111,8 +111,12 @@ void _NTFS_cache_destructor (NTFS_CACHE* cache) {
ntfs_free (cache);
}
static u32 accessCounter = 0;
static inline u64 accessTime(){ return gettime(); }
static u32 accessTime(){
accessCounter++;
return accessCounter;
}
static NTFS_CACHE_ENTRY* _NTFS_cache_getPage(NTFS_CACHE *cache,sec_t sector)
{
@ -305,22 +309,6 @@ bool _NTFS_cache_writeSectors (NTFS_CACHE* cache, sec_t sector, sec_t numSectors
while(numSectors>0)
{
/*
entry = _NTFS_cache_getPage(cache,sector);
if(entry==NULL) return false;
sec = sector - entry->sector;
secs_to_write = entry->count - sec;
if(secs_to_write>numSectors) secs_to_write = numSectors;
memcpy(entry->cache + (sec*BYTES_PER_READ),src,(secs_to_write*BYTES_PER_READ));
src += (secs_to_write*BYTES_PER_READ);
sector += secs_to_write;
numSectors -= secs_to_write;
entry->dirty = true;
*/
entry = _NTFS_cache_findPage(cache,sector,numSectors);
if(entry!=NULL) {

View File

@ -272,8 +272,7 @@ static s64 ntfs_device_gekko_io_pwrite(struct ntfs_device *dev, const void *buf,
*/
static s64 ntfs_device_gekko_io_readbytes(struct ntfs_device *dev, s64 offset, s64 count, void *buf)
{
//ntfs_log_trace("dev %p, offset %Li, count %Li\n", dev, offset, count);
ntfs_log_trace("dev %p, offset %d, count %d\n", dev, (u32)offset, (u32)count);
ntfs_log_trace("dev %p, offset %Li, count %Li\n", dev, offset, count);
// Get the device driver descriptor
gekko_fd *fd = DEV_FD(dev);
@ -294,16 +293,19 @@ static s64 ntfs_device_gekko_io_readbytes(struct ntfs_device *dev, s64 offset, s
sec_t sec_start = (sec_t) fd->startSector;
sec_t sec_count = 1;
u16 buffer_offset = 0;
u32 buffer_offset = 0;
u8 *buffer = NULL;
// Determine the range of sectors required for this read
if (offset > 0) {
sec_start += (sec_t) floor(offset / fd->sectorSize);
buffer_offset = (sec_t) offset % fd->sectorSize;
sec_start += (sec_t) floor((f64) offset/fd->sectorSize);
buffer_offset = (u32) (offset % fd->sectorSize);
}
if (count > fd->sectorSize) {
sec_count = (sec_t) ceil(count / (float)fd->sectorSize);
sec_count = (sec_t) ceil((f64) count/fd->sectorSize);
if(buffer_offset > 0)
sec_count += 1;
}
// If this read happens to be on the sector boundaries then do the read straight into the destination buffer
@ -319,7 +321,8 @@ static s64 ntfs_device_gekko_io_readbytes(struct ntfs_device *dev, s64 offset, s
}
// Else read into a buffer and copy over only what was requested
} else
}
else
{
// Allocate a buffer to hold the read data
@ -353,7 +356,7 @@ static s64 ntfs_device_gekko_io_readbytes(struct ntfs_device *dev, s64 offset, s
*/
static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset, s64 count, const void *buf)
{
ntfs_log_trace("dev %p, offset %Li, count %Li\n", dev, offset, count);
ntfs_log_trace("dev %p, offset %lli, count %lli\n", dev, offset, count);
// Get the device driver descriptor
gekko_fd *fd = DEV_FD(dev);
@ -385,11 +388,14 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
// Determine the range of sectors required for this write
if (offset > 0) {
sec_start += (sec_t) floor(offset / fd->sectorSize);
buffer_offset = (u32) ceil(offset % fd->sectorSize);
sec_start += (sec_t) floor((f64) offset/fd->sectorSize);
buffer_offset = (u32) (offset % fd->sectorSize);
}
if (count > fd->sectorSize) {
sec_count = (sec_t) ceil((float) count / (float)fd->sectorSize);
sec_count = (sec_t) ceil((f64) count/fd->sectorSize);
if(buffer_offset > 0)
sec_count += 1;
}
// If this write happens to be on the sector boundaries then do the write straight to disc
@ -407,7 +413,7 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
} else {
// Allocate a buffer to hold the write data
buffer = (u8*)ntfs_alloc((sec_count+1) * fd->sectorSize);
buffer = (u8 *) ntfs_alloc(sec_count * fd->sectorSize);
if (!buffer) {
errno = ENOMEM;
return -1;
@ -423,7 +429,7 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
return -1;
}
}
if(count % fd->sectorSize != 0) {
if((count % fd->sectorSize != 0) || buffer_offset > 0) {
if (!ntfs_device_gekko_io_readsectors(dev, sec_start + sec_count-1, 1, buffer + ((sec_count - 1) * fd->sectorSize))) {
ntfs_log_perror("read failure @ sector %d\n", sec_start + sec_count);
ntfs_free(buffer);
@ -446,7 +452,6 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
// Free the buffer
ntfs_free(buffer);
}
// Mark the device as dirty (if we actually wrote anything)

View File

@ -1129,8 +1129,6 @@ put_err_out:
*/
void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
{
return;
time_t now;
if (!ni) {

View File

@ -328,12 +328,12 @@ int ntfs_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf)
// Zero out the stat buffer
memset(buf, 0, sizeof(struct statvfs));
if(ntfs_volume_get_free_space(vd->vol) < 0)
{
ntfsUnlock(vd);
return -1;
}
if(ntfs_volume_get_free_space(vd->vol) < 0)
{
ntfsUnlock(vd);
return -1;
}
// File system block size
buf->f_bsize = vd->vol->cluster_size;

View File

@ -1,12 +1,13 @@
/**
* ntfsfile.c - devoptab file routines for NTFS-based devices.
*
* Copyright (c) 2010 Dimok
* Copyright (c) 2009 Rhys "Shareese" Koedijk
* Copyright (c) 2006 Michael "Chishm" Chisholm
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file is distributed in the hope that it will be
@ -52,23 +53,29 @@ void ntfsCloseFile (ntfs_file_state *file)
// Special case fix ups for compressed and/or encrypted files
if (file->compressed)
ntfs_attr_pclose(file->data_na);
#ifdef HAVE_SETXATTR
ntfs_attr_pclose(file->data_na);
#ifdef HAVE_SETXATTR
if (file->encrypted)
ntfs_efs_fixup_attribute(NULL, file->data_na);
#endif
#endif
// Close the file data attribute (if open)
if (file->data_na)
ntfs_attr_close(file->data_na);
// Sync the file (and its attributes) to disc
if(file->write)
{
ntfsSync(file->vd, file->ni);
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME | NTFS_UPDATE_CTIME);
}
if (file->read)
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
// Close the file (if open)
if (file->ni)
ntfsCloseEntry(file->vd, file->ni);
// Reset the file state
file->ni = NULL;
file->data_na = NULL;
@ -87,7 +94,7 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
ntfs_log_trace("fileStruct %p, path %s, flags %i, mode %i\n", fileStruct, path, flags, mode);
ntfs_file_state* file = STATE(fileStruct);
// Get the volume descriptor for this path
file->vd = ntfsGetVolume(path);
if (!file->vd) {
@ -117,7 +124,7 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
ntfsUnlock(file->vd);
return -1;
}
// Try and find the file and (if found) ensure that it is not a directory
file->ni = ntfsOpenEntry(file->vd, path);
if (file->ni && (file->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) {
@ -126,10 +133,10 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
r->_errno = EISDIR;
return -1;
}
// Are we creating this file?
if (flags & O_CREAT) {
// The file SHOULD NOT already exist
if (file->ni) {
ntfsCloseEntry(file->vd, file->ni);
@ -137,7 +144,7 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
r->_errno = EEXIST;
return -1;
}
// Create the file
file->ni = ntfsCreate(file->vd, path, S_IFREG, NULL);
if (!file->ni) {
@ -146,14 +153,14 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
}
}
// Sanity check, the file should be open by now
if (!file->ni) {
ntfsUnlock(file->vd);
r->_errno = ENOENT;
return -1;
}
// Open the files data attribute
file->data_na = ntfs_attr_open(file->ni, AT_DATA, AT_UNNAMED, 0);
if(!file->data_na) {
@ -165,7 +172,7 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
// Determine if this files data is compressed and/or encrypted
file->compressed = NAttrCompressed(file->data_na) || (file->ni->flags & FILE_ATTR_COMPRESSED);
file->encrypted = NAttrEncrypted(file->data_na) || (file->ni->flags & FILE_ATTR_ENCRYPTED);
// We cannot read/write encrypted files
if (file->encrypted) {
ntfs_attr_close(file->data_na);
@ -174,7 +181,7 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
r->_errno = EACCES;
return -1;
}
// Make sure we aren't trying to write to a read-only file
if ((file->ni->flags & FILE_ATTR_READONLY) && file->write) {
ntfs_attr_close(file->data_na);
@ -183,7 +190,7 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
r->_errno = EROFS;
return -1;
}
// Truncate the file if requested
if ((flags & O_TRUNC) && file->write) {
if (ntfs_attr_truncate(file->data_na, 0)) {
@ -194,16 +201,16 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
return -1;
}
}
// Set the files current position and length
file->pos = 0;
file->len = file->data_na->data_size;
ntfs_log_trace("file->len %d\n", file->len);
// Update file times
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
// Insert the file into the double-linked FILO list of open files
if (file->vd->firstOpenFile) {
file->nextOpenFile = file->vd->firstOpenFile;
@ -214,31 +221,31 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
file->prevOpenFile = NULL;
file->vd->firstOpenFile = file;
file->vd->openFileCount++;
// Unlock
ntfsUnlock(file->vd);
return (int)fileStruct;
}
int ntfs_close_r (struct _reent *r, int fd)
{
ntfs_log_trace("fd %p\n", fd);
ntfs_file_state* file = STATE(fd);
// Sanity check
if (!file || !file->vd) {
r->_errno = EBADF;
return -1;
}
// Lock
ntfsLock(file->vd);
// Close the file
ntfsCloseFile(file);
// Remove the file from the double-linked FILO list of open files
file->vd->openFileCount--;
if (file->nextOpenFile)
@ -250,45 +257,45 @@ int ntfs_close_r (struct _reent *r, int fd)
// Unlock
ntfsUnlock(file->vd);
return 0;
}
ssize_t ntfs_write_r (struct _reent *r, int fd, const char *ptr, size_t len)
{
ntfs_log_trace("fd %p, ptr %p, len %Li\n", fd, ptr, len);
ntfs_file_state* file = STATE(fd);
ssize_t written = 0;
off_t old_pos = 0;
// Sanity check
if (!file || !file->vd || !file->ni || !file->data_na) {
r->_errno = EINVAL;
return -1;
}
// Short circuit cases where we don't actually have to do anything
if (!ptr || len <= 0) {
return 0;
}
// Lock
ntfsLock(file->vd);
// Check that we are allowed to write to this file
if (!file->write) {
ntfsUnlock(file->vd);
r->_errno = EACCES;
return -1;
}
// If we are in append mode, backup the current position and move to the end of the file
if (file->append) {
old_pos = file->pos;
file->pos = file->len;
}
// Write to the files data atrribute
while (len) {
ssize_t ret = ntfs_attr_pwrite(file->data_na, file->pos, len, ptr);
@ -301,57 +308,53 @@ ssize_t ntfs_write_r (struct _reent *r, int fd, const char *ptr, size_t len)
file->pos += ret;
written += ret;
}
// If we are in append mode, restore the current position to were it was prior to this write
if (file->append) {
file->pos = old_pos;
}
// Mark the file for archiving (if we actually wrote something)
if (written)
file->ni->flags |= FILE_ATTR_ARCHIVE;
// Update file times (if we actually wrote something)
if (written)
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_MCTIME);
// Update the files data length
file->len = file->data_na->data_size;
// Unlock
// Unlock
ntfsUnlock(file->vd);
return written;
}
ssize_t ntfs_read_r (struct _reent *r, int fd, char *ptr, size_t len)
{
ntfs_log_trace("fd %p, ptr %p, len %Li\n", fd, ptr, len);
ntfs_file_state* file = STATE(fd);
ssize_t read = 0;
// Sanity check
if (!file || !file->vd || !file->ni || !file->data_na) {
r->_errno = EINVAL;
return -1;
}
// Short circuit cases where we don't actually have to do anything
if (!ptr || len <= 0) {
return 0;
}
// Lock
ntfsLock(file->vd);
// Check that we are allowed to read from this file
if (!file->read) {
ntfsUnlock(file->vd);
r->_errno = EACCES;
return -1;
}
// Don't read past the end of file
if (file->pos + len > file->len) {
r->_errno = EOVERFLOW;
@ -360,7 +363,7 @@ ssize_t ntfs_read_r (struct _reent *r, int fd, char *ptr, size_t len)
}
ntfs_log_trace("file->pos:%d, len:%d, file->len:%d \n", (u32)file->pos, (u32)len, (u32)file->len);
// Read from the files data attribute
while (len) {
ssize_t ret = ntfs_attr_pread(file->data_na, file->pos, len, ptr);
@ -376,41 +379,39 @@ ssize_t ntfs_read_r (struct _reent *r, int fd, char *ptr, size_t len)
}
//ntfs_log_trace("file->pos: %d \n", (u32)file->pos);
// Update file times (if we actually read something)
if (read)
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
// Unlock
// Unlock
ntfsUnlock(file->vd);
return read;
}
off_t ntfs_seek_r (struct _reent *r, int fd, off_t pos, int dir)
{
ntfs_log_trace("fd %p, pos %Li, dir %i\n", fd, pos, dir);
ntfs_file_state* file = STATE(fd);
off_t position = 0;
// Sanity check
if (!file || !file->vd || !file->ni || !file->data_na) {
r->_errno = EINVAL;
return -1;
}
// Lock
ntfsLock(file->vd);
// Set the files current position
switch(dir) {
case SEEK_SET: position = file->pos = MIN(MAX(pos, 0), file->len); break;
case SEEK_CUR: position = file->pos = MIN(MAX(file->pos + pos, 0), file->len); break;
case SEEK_END: position = file->pos = MIN(MAX(file->len + pos, 0), file->len); break;
}
// Unlock
// Unlock
ntfsUnlock(file->vd);
return position;
}
int ntfs_fstat_r (struct _reent *r, int fd, struct stat *st)
@ -419,47 +420,47 @@ int ntfs_fstat_r (struct _reent *r, int fd, struct stat *st)
ntfs_file_state* file = STATE(fd);
int ret = 0;
// Sanity check
if (!file || !file->vd || !file->ni || !file->data_na) {
r->_errno = EINVAL;
return -1;
}
// Short circuit cases were we don't actually have to do anything
if (!st)
return 0;
// Get the file stats
ret = ntfsStat(file->vd, file->ni, st);
if (ret)
r->_errno = errno;
return ret;
}
int ntfs_ftruncate_r (struct _reent *r, int fd, off_t len)
{
ntfs_log_trace("fd %p, len %Li\n", fd, len);
ntfs_file_state* file = STATE(fd);
// Sanity check
if (!file || !file->vd || !file->ni || !file->data_na) {
r->_errno = EINVAL;
return -1;
}
// Lock
ntfsLock(file->vd);
// Check that we are allowed to write to this file
if (!file->write) {
ntfsUnlock(file->vd);
r->_errno = EACCES;
return -1;
}
// For compressed files, only deleting and expanding contents are implemented
if (file->compressed &&
len > 0 &&
@ -488,20 +489,20 @@ int ntfs_ftruncate_r (struct _reent *r, int fd, off_t len)
// Mark the file for archiving (if we actually changed something)
if (file->len != file->data_na->data_size)
file->ni->flags |= FILE_ATTR_ARCHIVE;
// Update file times (if we actually changed something)
if (file->len != file->data_na->data_size)
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_MCTIME);
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_AMCTIME);
// Update the files data length
file->len = file->data_na->data_size;
// Sync the file (and its attributes) to disc
// Sync the file (and its attributes) to disc
ntfsSync(file->vd, file->ni);
// Unlock
ntfsUnlock(file->vd);
return 0;
}
@ -511,23 +512,23 @@ int ntfs_fsync_r (struct _reent *r, int fd)
ntfs_file_state* file = STATE(fd);
int ret = 0;
// Sanity check
if (!file || !file->vd || !file->ni || !file->data_na) {
r->_errno = EINVAL;
return -1;
}
// Lock
ntfsLock(file->vd);
// Sync the file (and its attributes) to disc
ret = ntfsSync(file->vd, file->ni);
if (ret)
r->_errno = errno;
// Unlock
ntfsUnlock(file->vd);
return ret;
}

View File

@ -34,6 +34,7 @@
#include <string.h>
#endif
#include "usbloader/usbstorage2.h"
#include "ntfsinternal.h"
#include "ntfsdir.h"
#include "ntfsfile.h"
@ -42,7 +43,6 @@
#include <sdcard/wiisd_io.h>
#include <sdcard/gcsd.h>
#include "usbloader/usbstorage2.h"
const INTERFACE_ID ntfs_disc_interfaces[] = {
{ "sd", &__io_wiisd },

View File

@ -67,7 +67,7 @@ typedef struct wbfs_disc_info
// callback definition. Return 1 on fatal error (callback is supposed to make retries until no hopes..)
typedef int (*rw_sector_callback_t)(void*fp,u32 lba,u32 count,void*iobuf);
typedef void (*progress_callback_t)(u32 status, u32 total);
typedef void (*progress_callback_t)(s64 status, s64 total);
typedef struct wbfs_s

View File

@ -17,7 +17,6 @@
#include "prompts/ProgressWindow.h"
#include "usbloader/wbfs.h"
#include "usbloader/utils.h"
#include "usbloader/spinner.h"
/*** Variables used only in this file ***/
static lwp_t progressthread = LWP_THREAD_NULL;
@ -33,8 +32,8 @@ static f32 progressDone = 0.0;
static bool showTime = false;
static bool showSize = false;
static bool changed = true;
static u32 gameinstalldone = 0;
static u32 gameinstalltotal = 0;
static s64 gameinstalldone = 0;
static s64 gameinstalltotal = -1;
static time_t start;
/*** Extern variables ***/
@ -46,20 +45,22 @@ extern void ResumeGui();
extern void HaltGui();
/****************************************************************************
* ProgressCallback mainly for gameinstallation. Can be used for other C app.
***************************************************************************/
extern "C" void ProgressCallback(s64 done, s64 total)
{
gameinstalldone = done;
gameinstalltotal = total;
}
/****************************************************************************
* GameInstallProgress
* GameInstallValue updating function
***************************************************************************/
static void GameInstallProgress() {
if (gameinstalltotal == 0)
return;
u32 oldinstalldone = gameinstalldone;
GetProgressValue(&gameinstalldone, &gameinstalltotal);
if((oldinstalldone == gameinstalldone) && (gameinstalldone > 0))
static void GameInstallProgress()
{
if (gameinstalltotal <= 0)
return;
if (gameinstalldone > gameinstalltotal)
@ -313,7 +314,7 @@ static void * ProgressThread (void *arg) {
***************************************************************************/
void ProgressStop() {
showProgress = 0;
gameinstalltotal = 0;
gameinstalltotal = -1;
// wait for thread to finish
while (!LWP_ThreadIsSuspended(progressthread))

View File

@ -15,4 +15,14 @@ void ShowProgress (const char *title, const char *msg1, char *dynmsg2,
f32 done, f32 total, bool swSize = false, bool swTime = false);
void ProgressStop();
#ifdef __cplusplus
extern "C" {
#endif
void ProgressCallback(s64 gameinstalldone, s64 gameinstalltotal);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -54,6 +54,7 @@ static void _ExitApp() {
StopGX();
ShutdownAudio();
UnmountNTFS();
SDCard_deInit();
USBDevice_deInit();
mload_set_ES_ioctlv_vector(NULL);
@ -68,23 +69,23 @@ void Sys_Reboot(void) {
int Sys_ChangeIos(int ios) {
s32 prevIos = IOS_GetVersion();
SDCard_deInit();
USBDevice_deInit();
WPAD_Flush(0);
WPAD_Disconnect(0);
WPAD_Shutdown();
WDVD_Close();
USBStorage2_Deinit();
s32 ret = IOS_ReloadIOSsafe(ios);
if (ret < 0) {
ios = prevIos;
}
SDCard_Init();
if (ios == 222 || ios == 223) {
@ -99,13 +100,13 @@ int Sys_ChangeIos(int ios) {
WBFS_Init(WBFS_DEVICE_USB);
Disc_Init();
if (Sys_IsHermes()) {
WBFS_OpenNamed((char *) &game_partition);
} else {
} else {
WBFS_Open();
}
return ret;
}
@ -228,34 +229,34 @@ s32 ios250rev = -69;
s32 IOS_ReloadIOSsafe(int ios)
{
if (ios==222)
{
{
if (ios222rev == -69)
ios222rev = getIOSrev(0x00000001000000dell);
if (ios222rev > 0 && (ios222rev != 4 && ios222rev != 5))return -2;
}
else if (ios==223)
{
{
if (ios223rev == -69)
ios223rev = getIOSrev(0x00000001000000dfll);
if (ios223rev > 0 && (ios223rev != 4 && ios223rev != 5))return -2;
}
else if (ios==249)
{
{
if (ios249rev == -69)
ios249rev = getIOSrev(0x00000001000000f9ll);
ios249rev = getIOSrev(0x00000001000000f9ll);
if (ios249rev >= 0 && !(ios249rev>=9 && ios249rev<65280))return -2;
}
else if (ios==250)
{
{
if (ios250rev == -69)
ios250rev = getIOSrev(0x00000001000000fall);
if (ios250rev >= 0 && !(ios250rev>=9 && ios250rev<65280))return -2;
}
s32 r = IOS_ReloadIOS(ios);
if (r >= 0) {
WII_Initialize();

View File

@ -1,17 +0,0 @@
#include <gccore.h>
#include "libwbfs/libwbfs.h"
static u32 done = 0;
static u32 total = 0;
void WBFS_Spinner(u32 d, u32 t)
{
done = d;
total = t;
}
void GetProgressValue(u32 * d, u32 * t)
{
*d = done;
*t = total;
}

View File

@ -1,15 +0,0 @@
#ifndef SPINNER_H_
#define SPINNER_H_
#ifdef __cplusplus
extern "C" {
#endif
void WBFS_Spinner(u32 d, u32 t);
void GetProgressValue(u32 * d, u32 * t);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -3,7 +3,7 @@
usbstorage_starlet.c -- USB mass storage support, inside starlet
Copyright (C) 2009 Kwiirk
If this driver is linked before libogc, this will replace the original
If this driver is linked before libogc, this will replace the original
usbstorage driver by svpe from libogc
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
@ -60,7 +60,7 @@ static char fs[] ATTRIBUTE_ALIGN(32) = "/dev/usb2";
static char fs2[] ATTRIBUTE_ALIGN(32) = "/dev/usb/ehc";
static char fsoff[] ATTRIBUTE_ALIGN(32) = "/dev/usb2/OFF";
static s32 hid = -1, fd = -1;
static u32 sector_size;
static int mounted=0;
@ -152,13 +152,13 @@ s32 USBStorage2_Init(void)
if (hid < 0) {
hid = iosCreateHeap(UMS_HEAPSIZE);
if (hid < 0)
return IPC_ENOMEM;
return IPC_ENOMEM;
}
/* Open USB device */
fd = IOS_Open(fs, 0);
if (fd < 0) fd = IOS_Open(fs2, 0);
if (fd < 0)
return fd;
@ -194,7 +194,7 @@ err:
IOS_Close(fd);
fd = -1;
}
return ret;
}
@ -257,7 +257,7 @@ s32 USBStorage2_WriteSectors(u32 sector, u32 numSectors, const void *buffer)
if (fd < 0)
return fd;
if(!mem2_ptr) mem2_ptr=SYS_AllocArena2MemLo(2048*256,32);
/* MEM1 buffer */
if (!__USBStorage2_isMEM2Buffer(buffer)) {
@ -273,17 +273,13 @@ s32 USBStorage2_WriteSectors(u32 sector, u32 numSectors, const void *buffer)
/* Write data */
ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_WRITE_SECTORS, "ii:d", sector, numSectors, buf, len);
/* Free memory */
if (buf != buffer)
iosFree(hid, buf);
return ret;
}
static bool __usbstorage_Startup(void)
{
return USBStorage2_Init()==0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,206 +1,206 @@
#include "wbfs_wbfs.h"
#include "../spinner.h"
#include "settings/cfg.h"
#include "wbfs_rw.h"
extern u32 sector_size;
s32 Wbfs_Wbfs::Open()
{
wbfs_t *part = NULL;
/* Open partition */
part = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 0);
if (!part) return -1;
/* Close current hard disk */
Close();
hdd = part;
// Save the new sector size, so it will be used in read and write calls
sector_size = 1 << hdd->head->hd_sec_sz_s;
return 0;
}
wbfs_disc_t* Wbfs_Wbfs::OpenDisc(u8 *discid)
{
/* No device open */
if (!hdd)
return NULL;
/* Open disc */
return wbfs_open_disc(hdd, discid);
}
void Wbfs_Wbfs::CloseDisc(wbfs_disc_t *disc)
{
/* No device open */
if (!hdd || !disc)
return;
/* Close disc */
wbfs_close_disc(disc);
}
s32 Wbfs_Wbfs::Format()
{
wbfs_t *partition = NULL;
/* Reset partition */
partition = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 1);
if (!partition)
return -1;
/* Free memory */
wbfs_close(partition);
return 0;
}
s32 Wbfs_Wbfs::GetCount(u32 *count)
{
/* No device open */
if (!hdd)
return -1;
/* Get list length */
*count = wbfs_count_discs(hdd);
return 0;
}
s32 Wbfs_Wbfs::GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len)
{
u32 idx, size;
s32 ret;
/* No device open */
if (!hdd)
return -1;
for (idx = 0; idx < cnt; idx++) {
u8 *ptr = ((u8 *)outbuf) + (idx * len);
/* Get header */
ret = wbfs_get_disc_info(hdd, idx, ptr, len, &size);
if (ret < 0)
return ret;
}
return 0;
}
s32 Wbfs_Wbfs::AddGame()
{
s32 ret;
/* No device open */
if (!hdd)
return -1;
/* Add game to device */
partition_selector_t part_sel;
int copy_1_1 = 0;
if (Settings.fullcopy) {
part_sel = ALL_PARTITIONS;
copy_1_1 = 1;
} else {
part_sel = Settings.partitions_to_install == install_game_only ? ONLY_GAME_PARTITION : ALL_PARTITIONS;
}
ret = wbfs_add_disc(hdd, __ReadDVD, NULL, WBFS_Spinner, part_sel, copy_1_1);
if (ret < 0)
return ret;
return 0;
}
s32 Wbfs_Wbfs::RemoveGame(u8 *discid)
{
s32 ret;
/* No device open */
if (!hdd)
return -1;
/* Remove game from USB device */
ret = wbfs_rm_disc(hdd, discid);
if (ret < 0)
return ret;
return 0;
}
s32 Wbfs_Wbfs::DiskSpace(f32 *used, f32 *free)
{
f32 ssize;
u32 cnt;
/* No device open */
if (!hdd)
return -1;
/* Count used blocks */
cnt = wbfs_count_usedblocks(hdd);
/* Sector size in GB */
ssize = hdd->wbfs_sec_sz / GB_SIZE;
/* Copy values */
*free = ssize * cnt;
*used = ssize * (hdd->n_wbfs_sec - cnt);
return 0;
}
s32 Wbfs_Wbfs::RenameGame(u8 *discid, const void *newname)
{
s32 ret;
/* No USB device open */
if (!hdd)
return -1;
ret = wbfs_ren_disc(hdd, discid,(u8*)newname);
if (ret < 0)
return ret;
return 0;
}
s32 Wbfs_Wbfs::ReIDGame(u8 *discid, const void *newID)
{
s32 ret;
/* No USB device open */
if (!hdd)
return -1;
ret = wbfs_rID_disc(hdd, discid,(u8*)newID);
if (ret < 0)
return ret;
return 0;
}
f32 Wbfs_Wbfs::EstimateGameSize()
{
partition_selector_t part_sel = ONLY_GAME_PARTITION;
if (Settings.fullcopy) {
part_sel = ALL_PARTITIONS;
} else {
switch(Settings.partitions_to_install)
{
case install_game_only:
part_sel = ONLY_GAME_PARTITION;
break;
case install_all:
part_sel = ALL_PARTITIONS;
break;
case install_all_but_update:
part_sel = REMOVE_UPDATE_PARTITION;
break;
}
}
return wbfs_estimate_disc(hdd, __ReadDVD, NULL, part_sel);
}
#include "wbfs_wbfs.h"
#include "prompts/ProgressWindow.h"
#include "settings/cfg.h"
#include "wbfs_rw.h"
extern u32 sector_size;
s32 Wbfs_Wbfs::Open()
{
wbfs_t *part = NULL;
/* Open partition */
part = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 0);
if (!part) return -1;
/* Close current hard disk */
Close();
hdd = part;
// Save the new sector size, so it will be used in read and write calls
sector_size = 1 << hdd->head->hd_sec_sz_s;
return 0;
}
wbfs_disc_t* Wbfs_Wbfs::OpenDisc(u8 *discid)
{
/* No device open */
if (!hdd)
return NULL;
/* Open disc */
return wbfs_open_disc(hdd, discid);
}
void Wbfs_Wbfs::CloseDisc(wbfs_disc_t *disc)
{
/* No device open */
if (!hdd || !disc)
return;
/* Close disc */
wbfs_close_disc(disc);
}
s32 Wbfs_Wbfs::Format()
{
wbfs_t *partition = NULL;
/* Reset partition */
partition = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 1);
if (!partition)
return -1;
/* Free memory */
wbfs_close(partition);
return 0;
}
s32 Wbfs_Wbfs::GetCount(u32 *count)
{
/* No device open */
if (!hdd)
return -1;
/* Get list length */
*count = wbfs_count_discs(hdd);
return 0;
}
s32 Wbfs_Wbfs::GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len)
{
u32 idx, size;
s32 ret;
/* No device open */
if (!hdd)
return -1;
for (idx = 0; idx < cnt; idx++) {
u8 *ptr = ((u8 *)outbuf) + (idx * len);
/* Get header */
ret = wbfs_get_disc_info(hdd, idx, ptr, len, &size);
if (ret < 0)
return ret;
}
return 0;
}
s32 Wbfs_Wbfs::AddGame()
{
s32 ret;
/* No device open */
if (!hdd)
return -1;
/* Add game to device */
partition_selector_t part_sel;
int copy_1_1 = 0;
if (Settings.fullcopy) {
part_sel = ALL_PARTITIONS;
copy_1_1 = 1;
} else {
part_sel = Settings.partitions_to_install == install_game_only ? ONLY_GAME_PARTITION : ALL_PARTITIONS;
}
ret = wbfs_add_disc(hdd, __ReadDVD, NULL, ProgressCallback, part_sel, copy_1_1);
if (ret < 0)
return ret;
return 0;
}
s32 Wbfs_Wbfs::RemoveGame(u8 *discid)
{
s32 ret;
/* No device open */
if (!hdd)
return -1;
/* Remove game from USB device */
ret = wbfs_rm_disc(hdd, discid);
if (ret < 0)
return ret;
return 0;
}
s32 Wbfs_Wbfs::DiskSpace(f32 *used, f32 *free)
{
f32 ssize;
u32 cnt;
/* No device open */
if (!hdd)
return -1;
/* Count used blocks */
cnt = wbfs_count_usedblocks(hdd);
/* Sector size in GB */
ssize = hdd->wbfs_sec_sz / GB_SIZE;
/* Copy values */
*free = ssize * cnt;
*used = ssize * (hdd->n_wbfs_sec - cnt);
return 0;
}
s32 Wbfs_Wbfs::RenameGame(u8 *discid, const void *newname)
{
s32 ret;
/* No USB device open */
if (!hdd)
return -1;
ret = wbfs_ren_disc(hdd, discid,(u8*)newname);
if (ret < 0)
return ret;
return 0;
}
s32 Wbfs_Wbfs::ReIDGame(u8 *discid, const void *newID)
{
s32 ret;
/* No USB device open */
if (!hdd)
return -1;
ret = wbfs_rID_disc(hdd, discid,(u8*)newID);
if (ret < 0)
return ret;
return 0;
}
f32 Wbfs_Wbfs::EstimateGameSize()
{
partition_selector_t part_sel = ONLY_GAME_PARTITION;
if (Settings.fullcopy) {
part_sel = ALL_PARTITIONS;
} else {
switch(Settings.partitions_to_install)
{
case install_game_only:
part_sel = ONLY_GAME_PARTITION;
break;
case install_all:
part_sel = ALL_PARTITIONS;
break;
case install_all_but_update:
part_sel = REMOVE_UPDATE_PARTITION;
break;
}
}
return wbfs_estimate_disc(hdd, __ReadDVD, NULL, part_sel);
}