2009-12-19 16:47:12 +01:00
|
|
|
|
|
|
|
// Modified by oggzee
|
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
#ifndef LIBWBFS_H
|
|
|
|
#define LIBWBFS_H
|
|
|
|
|
|
|
|
#include "libwbfs_os.h" // this file is provided by the project wanting to compile libwbfs
|
|
|
|
#include "wiidisc.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2010-09-19 01:16:05 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
enum {
|
|
|
|
WBFS_DEVICE_USB = 1, /* USB device */
|
|
|
|
WBFS_DEVICE_SDHC /* SDHC device */
|
|
|
|
};
|
2010-02-15 00:22:52 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef u32 be32_t;
|
|
|
|
typedef u16 be16_t;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef struct wbfs_head
|
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
be32_t magic;
|
|
|
|
// parameters copied in the partition for easy dumping, and bug reports
|
2010-09-19 01:16:05 +02:00
|
|
|
be32_t n_hd_sec; // total number of hd_sec in this partition
|
2009-05-03 20:53:31 +02:00
|
|
|
u8 hd_sec_sz_s; // sector size in this partition
|
|
|
|
u8 wbfs_sec_sz_s; // size of a wbfs sec
|
|
|
|
u8 padding3[2];
|
2010-09-19 01:16:05 +02:00
|
|
|
u8 disc_table[0]; // size depends on hd sector size
|
|
|
|
} __attribute( ( packed ) ) wbfs_head_t ;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef struct wbfs_disc_info
|
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
u8 disc_header_copy[0x100];
|
|
|
|
be16_t wlba_table[0];
|
2010-09-19 01:16:05 +02:00
|
|
|
} wbfs_disc_info_t;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
// WBFS first wbfs_sector structure:
|
|
|
|
//
|
|
|
|
// -----------
|
|
|
|
// | wbfs_head | (hd_sec_sz)
|
|
|
|
// -----------
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// | disc_info |
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// -----------
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// | disc_info |
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// -----------
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// | ... |
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// -----------
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// | disc_info |
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// -----------
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// |freeblk_tbl|
|
2010-09-19 01:16:05 +02:00
|
|
|
// | |
|
2009-05-03 20:53:31 +02:00
|
|
|
// -----------
|
|
|
|
//
|
|
|
|
|
|
|
|
// callback definition. Return 1 on fatal error (callback is supposed to make retries until no hopes..)
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef int ( *rw_sector_callback_t )( void*fp, u32 lba, u32 count, void*iobuf );
|
|
|
|
typedef void ( *progress_callback_t )( s64 status, s64 total );
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef struct wbfs_s
|
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
wbfs_head_t *head;
|
|
|
|
|
|
|
|
/* hdsectors, the size of the sector provided by the hosting hard drive */
|
|
|
|
u32 hd_sec_sz;
|
|
|
|
u8 hd_sec_sz_s; // the power of two of the last number
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 n_hd_sec; // the number of hd sector in the wbfs partition
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
/* standard wii sector (0x8000 bytes) */
|
2010-02-22 22:29:47 +01:00
|
|
|
u32 wii_sec_sz;
|
2009-05-03 20:53:31 +02:00
|
|
|
u8 wii_sec_sz_s;
|
|
|
|
u32 n_wii_sec;
|
|
|
|
u32 n_wii_sec_per_disc;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
/* The size of a wbfs sector */
|
|
|
|
u32 wbfs_sec_sz;
|
2010-02-22 22:29:47 +01:00
|
|
|
u32 wbfs_sec_sz_s;
|
2009-05-03 20:53:31 +02:00
|
|
|
u16 n_wbfs_sec; // this must fit in 16 bit!
|
|
|
|
u16 n_wbfs_sec_per_disc; // size of the lookup table
|
|
|
|
|
|
|
|
u32 part_lba;
|
|
|
|
/* virtual methods to read write the partition */
|
|
|
|
rw_sector_callback_t read_hdsector;
|
|
|
|
rw_sector_callback_t write_hdsector;
|
|
|
|
void *callback_data;
|
|
|
|
|
|
|
|
u16 max_disc;
|
|
|
|
u32 freeblks_lba;
|
|
|
|
u32 *freeblks;
|
|
|
|
u16 disc_info_sz;
|
|
|
|
|
|
|
|
u8 *tmp_buffer; // pre-allocated buffer for unaligned read
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
u32 n_disc_open;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
} wbfs_t;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef struct wbfs_disc_s
|
|
|
|
{
|
2009-05-03 20:53:31 +02:00
|
|
|
wbfs_t *p;
|
2010-09-19 01:16:05 +02:00
|
|
|
wbfs_disc_info_t *header; // pointer to wii header
|
|
|
|
int i; // disc index in the wbfs header (disc_table)
|
|
|
|
} wbfs_disc_t;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
#define WBFS_MAGIC (('W'<<24)|('B'<<16)|('F'<<8)|('S'))
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/*! @brief open a MSDOS partitionned harddrive. This tries to find a wbfs partition into the harddrive
|
|
|
|
@param read_hdsector,write_hdsector: accessors to a harddrive
|
|
|
|
@hd_sector_size: size of the hd sector. Can be set to zero if the partition in already initialized
|
|
|
|
@num_hd_sector: number of sectors in this disc. Can be set to zero if the partition in already initialized
|
|
|
|
@reset: not implemented, This will format the whole harddrive with one wbfs partition that fits the whole disk.
|
|
|
|
calls wbfs_error() to have textual meaning of errors
|
|
|
|
@return NULL in case of error
|
|
|
|
*/
|
|
|
|
wbfs_t*wbfs_open_hd( rw_sector_callback_t read_hdsector,
|
|
|
|
rw_sector_callback_t write_hdsector,
|
|
|
|
void *callback_data,
|
|
|
|
int hd_sector_size, int num_hd_sector, int reset );
|
|
|
|
|
|
|
|
/*! @brief open a wbfs partition
|
|
|
|
@param read_hdsector,write_hdsector: accessors to the partition
|
|
|
|
@hd_sector_size: size of the hd sector. Can be set to zero if the partition in already initialized
|
|
|
|
@num_hd_sector: number of sectors in this partition. Can be set to zero if the partition in already initialized
|
|
|
|
@partition_lba: The partitio offset if you provided accessors to the whole disc.
|
|
|
|
@reset: initialize the partition with an empty wbfs.
|
|
|
|
calls wbfs_error() to have textual meaning of errors
|
|
|
|
@return NULL in case of error
|
|
|
|
*/
|
|
|
|
wbfs_t*wbfs_open_partition( rw_sector_callback_t read_hdsector,
|
|
|
|
rw_sector_callback_t write_hdsector,
|
|
|
|
void *callback_data,
|
|
|
|
int hd_sector_size, int num_hd_sector, u32 partition_lba, int reset );
|
|
|
|
|
|
|
|
|
|
|
|
/*! @brief close a wbfs partition, and sync the metadatas to the disc */
|
|
|
|
void wbfs_close( wbfs_t* );
|
|
|
|
|
|
|
|
/*! @brief open a disc inside a wbfs partition use a 6 char discid+vendorid
|
|
|
|
@return NULL if discid is not present
|
|
|
|
*/
|
|
|
|
wbfs_disc_t *wbfs_open_disc( wbfs_t* p, u8 *diskid );
|
|
|
|
|
|
|
|
/*! @brief close a already open disc inside a wbfs partition */
|
|
|
|
void wbfs_close_disc( wbfs_disc_t*d );
|
|
|
|
|
|
|
|
u32 wbfs_sector_used( wbfs_t *p, wbfs_disc_info_t *di );
|
|
|
|
u32 wbfs_sector_used2( wbfs_t *p, wbfs_disc_info_t *di, u32 *last_blk );
|
|
|
|
|
|
|
|
/*! @brief accessor to the wii disc
|
|
|
|
@param d: a pointer to already open disc
|
|
|
|
@param offset: an offset inside the disc, *points 32bit words*, allowing to access 16GB data
|
|
|
|
@param len: The length of the data to fetch, in *bytes*
|
|
|
|
*/
|
2009-05-03 20:53:31 +02:00
|
|
|
// offset is pointing 32bit words to address the whole dvd, although len is in bytes
|
2010-09-19 01:16:05 +02:00
|
|
|
int wbfs_disc_read( wbfs_disc_t*d, u32 offset, u32 len, u8 *data );
|
|
|
|
|
|
|
|
/*! @return the number of discs inside the partition */
|
|
|
|
u32 wbfs_count_discs( wbfs_t*p );
|
|
|
|
/*! get the disc info of ith disc inside the partition. It correspond to the first 0x100 bytes of the wiidvd
|
|
|
|
http://www.wiibrew.org/wiki/Wiidisc#Header
|
|
|
|
@param i: index of the disc inside the partition
|
|
|
|
@param header: pointer to 0x100 bytes to write the header
|
|
|
|
@size: optional pointer to a 32bit word that will get the size in 32bit words of the DVD taken on the partition.
|
|
|
|
*/
|
|
|
|
u32 wbfs_get_disc_info( wbfs_t*p, u32 i, u8 *header, int header_size, u32 *size );
|
|
|
|
|
|
|
|
/*! get the number of used block of the partition.
|
|
|
|
to be multiplied by p->wbfs_sec_sz (use 64bit multiplication) to have the number in bytes
|
|
|
|
*/
|
|
|
|
u32 wbfs_count_usedblocks( wbfs_t*p );
|
|
|
|
|
|
|
|
/******************* write access ******************/
|
|
|
|
|
|
|
|
/*! add a wii dvd inside the partition
|
|
|
|
@param read_src_wii_disc: a callback to access the wii dvd. offsets are in 32bit, len in bytes!
|
|
|
|
@callback_data: private data passed to the callback
|
|
|
|
@spinner: a pointer to a function that is regulary called to update a progress bar.
|
|
|
|
@sel: selects which partitions to copy.
|
|
|
|
@copy_1_1: makes a 1:1 copy, whenever a game would not use the wii disc format, and some data is hidden outside the filesystem.
|
|
|
|
*/
|
|
|
|
u32 wbfs_add_disc( wbfs_t*p, read_wiidisc_callback_t read_src_wii_disc, void *callback_data,
|
|
|
|
progress_callback_t spinner, partition_selector_t sel, int copy_1_1 );
|
|
|
|
|
|
|
|
|
|
|
|
/*! remove a wiidvd inside a partition */
|
|
|
|
u32 wbfs_rm_disc( wbfs_t*p, u8* discid );
|
|
|
|
|
|
|
|
/*! rename a game */
|
|
|
|
u32 wbfs_ren_disc( wbfs_t*p, u8* discid, u8* newname );
|
|
|
|
|
|
|
|
/* change ID of a game*/
|
|
|
|
u32 wbfs_rID_disc( wbfs_t*p, u8* discid, u8* newID );
|
|
|
|
/*! trim the file-system to its minimum size
|
|
|
|
This allows to use wbfs as a wiidisc container
|
|
|
|
*/
|
|
|
|
u32 wbfs_trim( wbfs_t*p );
|
|
|
|
|
|
|
|
/*! extract a disc from the wbfs, unused sectors are just untouched, allowing descent filesystem to only really usefull space to store the disc.
|
|
|
|
Even if the filesize is 4.7GB, the disc usage will be less.
|
|
|
|
*/
|
|
|
|
u32 wbfs_extract_disc( wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector, void *callback_data, progress_callback_t spinner );
|
|
|
|
|
|
|
|
/*! extract a file from the wii disc filesystem.
|
|
|
|
E.G. Allows to extract the opening.bnr to install a game as a system menu channel
|
|
|
|
*/
|
|
|
|
int wbfs_extract_file( wbfs_disc_t*d, char *path, void **data );
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
// remove some sanity checks
|
2010-09-19 01:16:05 +02:00
|
|
|
void wbfs_set_force_mode( int force );
|
2009-11-08 21:13:57 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
float wbfs_estimate_disc(
|
|
|
|
wbfs_t *p, read_wiidisc_callback_t read_src_wii_disc,
|
|
|
|
void *callback_data,
|
|
|
|
partition_selector_t sel );
|
2009-11-15 20:52:58 +01:00
|
|
|
// compressed and real size
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 wbfs_size_disc( wbfs_t*p, read_wiidisc_callback_t read_src_wii_disc,
|
|
|
|
void *callback_data, partition_selector_t sel,
|
|
|
|
u32 *comp_size, u32 *real_size );
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef int ( *_frag_append_t )( void *ff, u32 offset, u32 sector, u32 count );
|
|
|
|
int wbfs_get_fragments( wbfs_disc_t *d, _frag_append_t append_fragment, void *callback_data );
|
2009-12-19 15:05:31 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
extern wbfs_t wbfs_iso_file;
|
|
|
|
u32 wbfs_disc_sector_used( wbfs_disc_t *d, u32 *num_blk );
|
|
|
|
int wbfs_iso_file_read( wbfs_disc_t*d, u32 offset, u8 *data, u32 len );
|
2009-12-19 15:05:31 +01:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
#ifdef __cplusplus
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif
|