*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"> <app version="1">
<name> USB Loader GX</name> <name> USB Loader GX</name>
<coder>USB Loader GX Team</coder> <coder>USB Loader GX Team</coder>
<version>1.0 r914</version> <version>1.0 r915</version>
<release_date>201002222228</release_date> <release_date>201002222143</release_date>
<short_description>Loads games from USB-devices</short_description> <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. <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. 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 <sdcard/wiisd_io.h>
#include <locale.h> #include <locale.h>
#include "usbloader/sdhc.h"
#include "usbloader/usbstorage2.h" #include "usbloader/usbstorage2.h"
#include "usbloader/sdhc.h"
#include "usbloader/wbfs.h" #include "usbloader/wbfs.h"
#include "libfat/fat.h" #include "libfat/fat.h"
#include "libntfs/ntfs.h" #include "libntfs/ntfs.h"
#include "gecko.h" #include "gecko.h"
//these are the only stable and speed is good //these are the only stable and speed is good
#define CACHE 32 #define CACHE 8
#define SECTORS 64 #define SECTORS 64
#define SECTORS_SD 32 #define SECTORS_SD 32
@ -62,7 +62,7 @@ int USBDevice_Init() {
return -1; return -1;
} }
// } // }
fat_usb_mount = 1; fat_usb_mount = 1;
fat_usb_sec = _FAT_startSector; fat_usb_sec = _FAT_startSector;
#ifdef DEBUG_FAT #ifdef DEBUG_FAT
@ -88,7 +88,7 @@ int WBFSDevice_Init(u32 sector) {
//right now mounts first FAT-partition //right now mounts first FAT-partition
//try first mount with cIOS //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 //try now mount with libogc
if (!fatMount("WBFS", &__io_usbstorage2, 0, CACHE, SECTORS)) { if (!fatMount("WBFS", &__io_usbstorage2, 0, CACHE, SECTORS)) {
return -1; return -1;
@ -171,7 +171,7 @@ s32 MountNTFS(u32 sector)
_FAT_mem_init(); _FAT_mem_init();
ntfsInit(); // Call ntfs init here, to prevent locale resets ntfsInit(); // Call ntfs init here, to prevent locale resets
// ntfsInit resets locale settings // ntfsInit resets locale settings
// which breaks unicode in console // which breaks unicode in console
// so we change it back to C-UTF-8 // so we change it back to C-UTF-8
@ -195,9 +195,9 @@ s32 MountNTFS(u32 sector)
// } // }
} else if (wbfsDev == WBFS_DEVICE_SDHC) { } else if (wbfsDev == WBFS_DEVICE_SDHC) {
if (sdhc_mode_sd == 0) { 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 { } 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) { if (!ret) {
return -5; return -5;
@ -206,7 +206,7 @@ s32 MountNTFS(u32 sector)
fs_ntfs_mount = 1; fs_ntfs_mount = 1;
fs_ntfs_sec = sector; //_FAT_startSector; fs_ntfs_sec = sector; //_FAT_startSector;
return 0; return 0;
} }
@ -232,25 +232,10 @@ void* _FAT_mem_allocate(size_t size)
void* _FAT_mem_align(size_t size) void* _FAT_mem_align(size_t size)
{ {
return memalign(32, size); return memalign(32, size);
} }
void _FAT_mem_free(void *mem) void _FAT_mem_free(void *mem)
{ {
free(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); 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) 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) 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); entry = _NTFS_cache_findPage(cache,sector,numSectors);
if(entry!=NULL) { 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) 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 %Li, count %Li\n", dev, offset, count);
ntfs_log_trace("dev %p, offset %d, count %d\n", dev, (u32)offset, (u32)count);
// Get the device driver descriptor // Get the device driver descriptor
gekko_fd *fd = DEV_FD(dev); 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_start = (sec_t) fd->startSector;
sec_t sec_count = 1; sec_t sec_count = 1;
u16 buffer_offset = 0; u32 buffer_offset = 0;
u8 *buffer = NULL; u8 *buffer = NULL;
// Determine the range of sectors required for this read // Determine the range of sectors required for this read
if (offset > 0) { if (offset > 0) {
sec_start += (sec_t) floor(offset / fd->sectorSize); sec_start += (sec_t) floor((f64) offset/fd->sectorSize);
buffer_offset = (sec_t) offset % fd->sectorSize; buffer_offset = (u32) (offset % fd->sectorSize);
} }
if (count > 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 // 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 read into a buffer and copy over only what was requested
} else }
else
{ {
// Allocate a buffer to hold the read data // 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) 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 // Get the device driver descriptor
gekko_fd *fd = DEV_FD(dev); 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 // Determine the range of sectors required for this write
if (offset > 0) { if (offset > 0) {
sec_start += (sec_t) floor(offset / fd->sectorSize); sec_start += (sec_t) floor((f64) offset/fd->sectorSize);
buffer_offset = (u32) ceil(offset % fd->sectorSize); buffer_offset = (u32) (offset % fd->sectorSize);
} }
if (count > 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 // 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 { } else {
// Allocate a buffer to hold the write data // 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) { if (!buffer) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
@ -423,7 +429,7 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
return -1; 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))) { 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_log_perror("read failure @ sector %d\n", sec_start + sec_count);
ntfs_free(buffer); ntfs_free(buffer);
@ -446,7 +452,6 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
// Free the buffer // Free the buffer
ntfs_free(buffer); ntfs_free(buffer);
} }
// Mark the device as dirty (if we actually wrote anything) // 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) void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
{ {
return;
time_t now; time_t now;
if (!ni) { 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 // Zero out the stat buffer
memset(buf, 0, sizeof(struct statvfs)); memset(buf, 0, sizeof(struct statvfs));
if(ntfs_volume_get_free_space(vd->vol) < 0) if(ntfs_volume_get_free_space(vd->vol) < 0)
{ {
ntfsUnlock(vd); ntfsUnlock(vd);
return -1; return -1;
} }
// File system block size // File system block size
buf->f_bsize = vd->vol->cluster_size; buf->f_bsize = vd->vol->cluster_size;

View File

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

View File

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

View File

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

View File

@ -54,6 +54,7 @@ static void _ExitApp() {
StopGX(); StopGX();
ShutdownAudio(); ShutdownAudio();
UnmountNTFS();
SDCard_deInit(); SDCard_deInit();
USBDevice_deInit(); USBDevice_deInit();
mload_set_ES_ioctlv_vector(NULL); mload_set_ES_ioctlv_vector(NULL);
@ -68,23 +69,23 @@ void Sys_Reboot(void) {
int Sys_ChangeIos(int ios) { int Sys_ChangeIos(int ios) {
s32 prevIos = IOS_GetVersion(); s32 prevIos = IOS_GetVersion();
SDCard_deInit(); SDCard_deInit();
USBDevice_deInit(); USBDevice_deInit();
WPAD_Flush(0); WPAD_Flush(0);
WPAD_Disconnect(0); WPAD_Disconnect(0);
WPAD_Shutdown(); WPAD_Shutdown();
WDVD_Close(); WDVD_Close();
USBStorage2_Deinit(); USBStorage2_Deinit();
s32 ret = IOS_ReloadIOSsafe(ios); s32 ret = IOS_ReloadIOSsafe(ios);
if (ret < 0) { if (ret < 0) {
ios = prevIos; ios = prevIos;
} }
SDCard_Init(); SDCard_Init();
if (ios == 222 || ios == 223) { if (ios == 222 || ios == 223) {
@ -99,13 +100,13 @@ int Sys_ChangeIos(int ios) {
WBFS_Init(WBFS_DEVICE_USB); WBFS_Init(WBFS_DEVICE_USB);
Disc_Init(); Disc_Init();
if (Sys_IsHermes()) { if (Sys_IsHermes()) {
WBFS_OpenNamed((char *) &game_partition); WBFS_OpenNamed((char *) &game_partition);
} else { } else {
WBFS_Open(); WBFS_Open();
} }
return ret; return ret;
} }
@ -228,34 +229,34 @@ s32 ios250rev = -69;
s32 IOS_ReloadIOSsafe(int ios) s32 IOS_ReloadIOSsafe(int ios)
{ {
if (ios==222) if (ios==222)
{ {
if (ios222rev == -69) if (ios222rev == -69)
ios222rev = getIOSrev(0x00000001000000dell); ios222rev = getIOSrev(0x00000001000000dell);
if (ios222rev > 0 && (ios222rev != 4 && ios222rev != 5))return -2; if (ios222rev > 0 && (ios222rev != 4 && ios222rev != 5))return -2;
} }
else if (ios==223) else if (ios==223)
{ {
if (ios223rev == -69) if (ios223rev == -69)
ios223rev = getIOSrev(0x00000001000000dfll); ios223rev = getIOSrev(0x00000001000000dfll);
if (ios223rev > 0 && (ios223rev != 4 && ios223rev != 5))return -2; if (ios223rev > 0 && (ios223rev != 4 && ios223rev != 5))return -2;
} }
else if (ios==249) else if (ios==249)
{ {
if (ios249rev == -69) if (ios249rev == -69)
ios249rev = getIOSrev(0x00000001000000f9ll); ios249rev = getIOSrev(0x00000001000000f9ll);
if (ios249rev >= 0 && !(ios249rev>=9 && ios249rev<65280))return -2; if (ios249rev >= 0 && !(ios249rev>=9 && ios249rev<65280))return -2;
} }
else if (ios==250) else if (ios==250)
{ {
if (ios250rev == -69) if (ios250rev == -69)
ios250rev = getIOSrev(0x00000001000000fall); ios250rev = getIOSrev(0x00000001000000fall);
if (ios250rev >= 0 && !(ios250rev>=9 && ios250rev<65280))return -2; if (ios250rev >= 0 && !(ios250rev>=9 && ios250rev<65280))return -2;
} }
s32 r = IOS_ReloadIOS(ios); s32 r = IOS_ReloadIOS(ios);
if (r >= 0) { if (r >= 0) {
WII_Initialize(); 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 usbstorage_starlet.c -- USB mass storage support, inside starlet
Copyright (C) 2009 Kwiirk 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 usbstorage driver by svpe from libogc
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any 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 fs2[] ATTRIBUTE_ALIGN(32) = "/dev/usb/ehc";
static char fsoff[] ATTRIBUTE_ALIGN(32) = "/dev/usb2/OFF"; static char fsoff[] ATTRIBUTE_ALIGN(32) = "/dev/usb2/OFF";
static s32 hid = -1, fd = -1; static s32 hid = -1, fd = -1;
static u32 sector_size; static u32 sector_size;
static int mounted=0; static int mounted=0;
@ -152,13 +152,13 @@ s32 USBStorage2_Init(void)
if (hid < 0) { if (hid < 0) {
hid = iosCreateHeap(UMS_HEAPSIZE); hid = iosCreateHeap(UMS_HEAPSIZE);
if (hid < 0) if (hid < 0)
return IPC_ENOMEM; return IPC_ENOMEM;
} }
/* Open USB device */ /* Open USB device */
fd = IOS_Open(fs, 0); fd = IOS_Open(fs, 0);
if (fd < 0) fd = IOS_Open(fs2, 0); if (fd < 0) fd = IOS_Open(fs2, 0);
if (fd < 0) if (fd < 0)
return fd; return fd;
@ -194,7 +194,7 @@ err:
IOS_Close(fd); IOS_Close(fd);
fd = -1; fd = -1;
} }
return ret; return ret;
} }
@ -257,7 +257,7 @@ s32 USBStorage2_WriteSectors(u32 sector, u32 numSectors, const void *buffer)
if (fd < 0) if (fd < 0)
return fd; return fd;
if(!mem2_ptr) mem2_ptr=SYS_AllocArena2MemLo(2048*256,32); if(!mem2_ptr) mem2_ptr=SYS_AllocArena2MemLo(2048*256,32);
/* MEM1 buffer */ /* MEM1 buffer */
if (!__USBStorage2_isMEM2Buffer(buffer)) { if (!__USBStorage2_isMEM2Buffer(buffer)) {
@ -273,17 +273,13 @@ s32 USBStorage2_WriteSectors(u32 sector, u32 numSectors, const void *buffer)
/* Write data */ /* Write data */
ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_WRITE_SECTORS, "ii:d", sector, numSectors, buf, len); 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; return ret;
} }
static bool __usbstorage_Startup(void) static bool __usbstorage_Startup(void)
{ {
return USBStorage2_Init()==0; 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 "wbfs_wbfs.h"
#include "../spinner.h" #include "prompts/ProgressWindow.h"
#include "settings/cfg.h" #include "settings/cfg.h"
#include "wbfs_rw.h" #include "wbfs_rw.h"
extern u32 sector_size; extern u32 sector_size;
s32 Wbfs_Wbfs::Open() s32 Wbfs_Wbfs::Open()
{ {
wbfs_t *part = NULL; wbfs_t *part = NULL;
/* Open partition */ /* Open partition */
part = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 0); part = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 0);
if (!part) return -1; if (!part) return -1;
/* Close current hard disk */ /* Close current hard disk */
Close(); Close();
hdd = part; hdd = part;
// Save the new sector size, so it will be used in read and write calls // Save the new sector size, so it will be used in read and write calls
sector_size = 1 << hdd->head->hd_sec_sz_s; sector_size = 1 << hdd->head->hd_sec_sz_s;
return 0; return 0;
} }
wbfs_disc_t* Wbfs_Wbfs::OpenDisc(u8 *discid) wbfs_disc_t* Wbfs_Wbfs::OpenDisc(u8 *discid)
{ {
/* No device open */ /* No device open */
if (!hdd) if (!hdd)
return NULL; return NULL;
/* Open disc */ /* Open disc */
return wbfs_open_disc(hdd, discid); return wbfs_open_disc(hdd, discid);
} }
void Wbfs_Wbfs::CloseDisc(wbfs_disc_t *disc) void Wbfs_Wbfs::CloseDisc(wbfs_disc_t *disc)
{ {
/* No device open */ /* No device open */
if (!hdd || !disc) if (!hdd || !disc)
return; return;
/* Close disc */ /* Close disc */
wbfs_close_disc(disc); wbfs_close_disc(disc);
} }
s32 Wbfs_Wbfs::Format() s32 Wbfs_Wbfs::Format()
{ {
wbfs_t *partition = NULL; wbfs_t *partition = NULL;
/* Reset partition */ /* Reset partition */
partition = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 1); partition = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 1);
if (!partition) if (!partition)
return -1; return -1;
/* Free memory */ /* Free memory */
wbfs_close(partition); wbfs_close(partition);
return 0; return 0;
} }
s32 Wbfs_Wbfs::GetCount(u32 *count) s32 Wbfs_Wbfs::GetCount(u32 *count)
{ {
/* No device open */ /* No device open */
if (!hdd) if (!hdd)
return -1; return -1;
/* Get list length */ /* Get list length */
*count = wbfs_count_discs(hdd); *count = wbfs_count_discs(hdd);
return 0; return 0;
} }
s32 Wbfs_Wbfs::GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len) s32 Wbfs_Wbfs::GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len)
{ {
u32 idx, size; u32 idx, size;
s32 ret; s32 ret;
/* No device open */ /* No device open */
if (!hdd) if (!hdd)
return -1; return -1;
for (idx = 0; idx < cnt; idx++) { for (idx = 0; idx < cnt; idx++) {
u8 *ptr = ((u8 *)outbuf) + (idx * len); u8 *ptr = ((u8 *)outbuf) + (idx * len);
/* Get header */ /* Get header */
ret = wbfs_get_disc_info(hdd, idx, ptr, len, &size); ret = wbfs_get_disc_info(hdd, idx, ptr, len, &size);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return 0; return 0;
} }
s32 Wbfs_Wbfs::AddGame() s32 Wbfs_Wbfs::AddGame()
{ {
s32 ret; s32 ret;
/* No device open */ /* No device open */
if (!hdd) if (!hdd)
return -1; return -1;
/* Add game to device */ /* Add game to device */
partition_selector_t part_sel; partition_selector_t part_sel;
int copy_1_1 = 0; int copy_1_1 = 0;
if (Settings.fullcopy) { if (Settings.fullcopy) {
part_sel = ALL_PARTITIONS; part_sel = ALL_PARTITIONS;
copy_1_1 = 1; copy_1_1 = 1;
} else { } else {
part_sel = Settings.partitions_to_install == install_game_only ? ONLY_GAME_PARTITION : ALL_PARTITIONS; 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); ret = wbfs_add_disc(hdd, __ReadDVD, NULL, ProgressCallback, part_sel, copy_1_1);
if (ret < 0) if (ret < 0)
return ret; return ret;
return 0; return 0;
} }
s32 Wbfs_Wbfs::RemoveGame(u8 *discid) s32 Wbfs_Wbfs::RemoveGame(u8 *discid)
{ {
s32 ret; s32 ret;
/* No device open */ /* No device open */
if (!hdd) if (!hdd)
return -1; return -1;
/* Remove game from USB device */ /* Remove game from USB device */
ret = wbfs_rm_disc(hdd, discid); ret = wbfs_rm_disc(hdd, discid);
if (ret < 0) if (ret < 0)
return ret; return ret;
return 0; return 0;
} }
s32 Wbfs_Wbfs::DiskSpace(f32 *used, f32 *free) s32 Wbfs_Wbfs::DiskSpace(f32 *used, f32 *free)
{ {
f32 ssize; f32 ssize;
u32 cnt; u32 cnt;
/* No device open */ /* No device open */
if (!hdd) if (!hdd)
return -1; return -1;
/* Count used blocks */ /* Count used blocks */
cnt = wbfs_count_usedblocks(hdd); cnt = wbfs_count_usedblocks(hdd);
/* Sector size in GB */ /* Sector size in GB */
ssize = hdd->wbfs_sec_sz / GB_SIZE; ssize = hdd->wbfs_sec_sz / GB_SIZE;
/* Copy values */ /* Copy values */
*free = ssize * cnt; *free = ssize * cnt;
*used = ssize * (hdd->n_wbfs_sec - cnt); *used = ssize * (hdd->n_wbfs_sec - cnt);
return 0; return 0;
} }
s32 Wbfs_Wbfs::RenameGame(u8 *discid, const void *newname) s32 Wbfs_Wbfs::RenameGame(u8 *discid, const void *newname)
{ {
s32 ret; s32 ret;
/* No USB device open */ /* No USB device open */
if (!hdd) if (!hdd)
return -1; return -1;
ret = wbfs_ren_disc(hdd, discid,(u8*)newname); ret = wbfs_ren_disc(hdd, discid,(u8*)newname);
if (ret < 0) if (ret < 0)
return ret; return ret;
return 0; return 0;
} }
s32 Wbfs_Wbfs::ReIDGame(u8 *discid, const void *newID) s32 Wbfs_Wbfs::ReIDGame(u8 *discid, const void *newID)
{ {
s32 ret; s32 ret;
/* No USB device open */ /* No USB device open */
if (!hdd) if (!hdd)
return -1; return -1;
ret = wbfs_rID_disc(hdd, discid,(u8*)newID); ret = wbfs_rID_disc(hdd, discid,(u8*)newID);
if (ret < 0) if (ret < 0)
return ret; return ret;
return 0; return 0;
} }
f32 Wbfs_Wbfs::EstimateGameSize() f32 Wbfs_Wbfs::EstimateGameSize()
{ {
partition_selector_t part_sel = ONLY_GAME_PARTITION; partition_selector_t part_sel = ONLY_GAME_PARTITION;
if (Settings.fullcopy) { if (Settings.fullcopy) {
part_sel = ALL_PARTITIONS; part_sel = ALL_PARTITIONS;
} else { } else {
switch(Settings.partitions_to_install) switch(Settings.partitions_to_install)
{ {
case install_game_only: case install_game_only:
part_sel = ONLY_GAME_PARTITION; part_sel = ONLY_GAME_PARTITION;
break; break;
case install_all: case install_all:
part_sel = ALL_PARTITIONS; part_sel = ALL_PARTITIONS;
break; break;
case install_all_but_update: case install_all_but_update:
part_sel = REMOVE_UPDATE_PARTITION; part_sel = REMOVE_UPDATE_PARTITION;
break; break;
} }
} }
return wbfs_estimate_disc(hdd, __ReadDVD, NULL, part_sel); return wbfs_estimate_disc(hdd, __ReadDVD, NULL, part_sel);
} }