/*---------------------------------------------------------------------------* Project: header for archiver for Revolution dvd File: darch.h Copyright (C) 2001-2006 Nintendo All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: darch.h,v $ Revision 1.1 2006/04/20 01:41:01 hiratsu Initial check-in. 1 7/02/01 11:34p Hashida Initial revision. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include typedef struct diskMap diskMap; struct diskMap { int fstPosition; int fstLength; int userFilePosition; int userFileLength; }; typedef struct FSTEntryInfo FSTEntryInfo; struct FSTEntryInfo { FSTEntryInfo* next; int entryNum; char pathName[FILENAME_MAX]; char* name; int nameOffset; BOOL isDir; int parentEntry; // dir only int nextEntry; // dir only: next entry under the same dir int filePosition; // file only int fileLength; // file only }; typedef struct FSTEntry FSTEntry; struct FSTEntry { unsigned int isDirAndStringOff; // the first byte is for isDir // the next 3bytes: name offset unsigned int parentOrPosition; // parent entry (dir entry) // position (file entry) unsigned int nextEntryOrLength; // next entry (dir entry) // length (file entry) }; typedef struct { char name[FILENAME_MAX]; int fid; int currEntry; int entryNum; int stringStartOffset; char* stringStart; FSTEntry* fst; int fileStart; } DarchHandle; #define roundUp4B(x) (((unsigned int)(x) + 4 - 1) & \ ~(4 - 1)) #define roundUp32B(x) (((unsigned int)(x) + 32 - 1) & \ ~(32 - 1)) /*---------------------------------------------------------------------------* Name: setData Description: macro to set data in big endian Arguments: addr address to set data data data to set offset data is set from addr+offset nbytes data length Returns: none *---------------------------------------------------------------------------*/ #define setData(addr, data, offset, nbytes) do { \ int ___i; \ for (___i = 0; ___i < nbytes; ___i++) \ { \ *( (char*)(addr) + offset + ___i ) \ = ( (data) >> (8*(nbytes - ___i - 1)) ) & 0xff; \ }\ } while(0) /* * 0 1 4 8 11 * +-----+-----------+----------------+-----------------+ * |ISDIR| STRINGOFF | PARENT or | Next Entry or | * | | | Position | Length | * +-----+-----------+----------------+-----------------+ */ #define ISDIR_OFFSET 0 #define ISDIR_LENGTH 1 #define STRINGOFF_OFFSET 1 #define STRINGOFF_LENGTH 3 #define PARENT_OFFSET 4 #define PARENT_LENGTH 4 #define POSITION_OFFSET 4 #define POSITION_LENGTH 4 #define NEXTENTRY_OFFSET 8 #define NEXTENTRY_LENGTH 4 #define LENGTH_OFFSET 8 #define LENGTH_LENGTH 4 #define setIsDir(eAddr, data) \ setData(eAddr, data, ISDIR_OFFSET, ISDIR_LENGTH) #define setStringOff(eAddr, data) \ setData(eAddr, data, STRINGOFF_OFFSET, STRINGOFF_LENGTH) #define setParent(eAddr, data) \ setData(eAddr, data, PARENT_OFFSET, PARENT_LENGTH) #define setPosition(eAddr, data) \ setData(eAddr, data, POSITION_OFFSET, POSITION_LENGTH) #define setNextEntry(eAddr, data) \ setData(eAddr, data, NEXTENTRY_OFFSET, NEXTENTRY_LENGTH) #define setLength(eAddr, data) \ setData(eAddr, data, LENGTH_OFFSET, LENGTH_LENGTH) #define set4BData(eAddr, data, offset) \ setData(eAddr, data, offset, 4) #define RoundUp32B(x) (((u32)(x) + 32 - 1) & ~(32 - 1)) #define RoundDown32B(x) (((u32)(x)) & ~(32 - 1)) #define RoundUp4B(x) (((u32)(x) + 4 - 1) & ~(4 - 1)) #define RoundDown4B(x) (((u32)(x)) & ~(4 - 1)) #define REV32(data) ( ( ((data) & 0xff000000) >> 24 ) | \ ( ((data) & 0x00ff0000) >> 8 ) | \ ( ((data) & 0x0000ff00) << 8 ) | \ ( ((data) & 0x000000ff) << 24 ) ) #define entryIsDir(entry) \ ( ( ( REV32((entry)->isDirAndStringOff) & 0xff000000 ) == 0 )? FALSE:TRUE ) #define stringOff(entry) \ ( REV32((entry)->isDirAndStringOff) & 0x00ffffff ) #define parentDir(entry) \ ( REV32((entry)->parentOrPosition) ) #define nextDir(entry) \ ( REV32((entry)->nextEntryOrLength) ) #define filePosition(entry) \ ( REV32((entry)->parentOrPosition) ) #define fileLength(entry) \ ( REV32((entry)->nextEntryOrLength) ) /* * FST max size ... 1M bytes * This is because bs2 assumes that. */ //#define FST_MAX_SIZE 0x00100000 #define MIN(x, y) (((x) < (y))? (x) : (y)) typedef struct { char* currDir; char** argStart; int argNum; } Arg_s; extern int makeFST(void); extern int makeOutFile(char* name); extern void makeTmpFileNames(void); extern void ListArc(char* name); extern void ListArcInDiscOrder(char* name); extern void ExtractArc(char* name, char* root); extern void DiffArc(char* name, char* root); extern void DeleteArc(char* arcFile, Arg_s* arg, int count); extern void ReplaceArc(char* arcFile, Arg_s* arg, int count); extern void CreateArc(char* arcFile, Arg_s* arg, int count); extern void CopyUtility(int srcfid, int srcoff, int dstfid, int dstoff, int size); extern BOOL DiffUtility(int fidA, int Aoff, int fidB, int Boff, int size); extern char fstFile[FILENAME_MAX]; extern char userFile[FILENAME_MAX]; extern char arcRoot[FILENAME_MAX]; extern diskMap map; extern char* progName; extern int debugMode; extern int verbose; extern void* BigBuffer; #define ALLOC_MEMSIZE (16*1024*1024)