diff --git a/HBC/META.XML b/HBC/META.XML deleted file mode 100644 index baacf47f..00000000 --- a/HBC/META.XML +++ /dev/null @@ -1,44 +0,0 @@ - - - USB Loader GX - USB Loader GX Team - 1.0 r1018 - 201012212002 - Loads games from USB-devices - 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. -Features are automatic widescreen detection, coverdownload, parental control, theme support and many more. - -Credits: -Coding: Dimok, nIxx, giantpune, ardi, Hungyip84, DrayX7, Lustar, r-win, WiiShizzza -Artworks: cyrex, NeoRame -WiiTDB / Hosting covers: Lustar -Hosting updates files: CorneliousJD -USBLoader sources: Waninkoko, Kwiirk, Hermes -Languages files updates: Kinyo and translaters -Hosting themes: Deak Phreak - -Libwiigui: Tantric -Libogc/Devkit: Shagkur and Wintermute -FreeTypeGX: Armin Tamzarian. - -Links: -USB Loader GX Project Page and Support Site: -http://code.google.com/p/usbloader-gui/ -Help Website: -http://usbloadergx.koureio.net/ -WiiTDB Site: -http://wiitdb.com -Themes Site: -http://wii.spiffy360.com -Languages Translaters Page: -http://gbatemp.net/index.php?showtopic=155252 - -Libwiigui Website: -http://wiibrew.org/wiki/Libwiigui/ -FreeTypeGX Project Page: -http://code.google.com/p/freetypegx/ -Gettext Official Page: -http://www.gnu.org/software/gettext/gettext.html - - diff --git a/HBC/icon.png b/HBC/icon.png deleted file mode 100644 index 951057cb..00000000 Binary files a/HBC/icon.png and /dev/null differ diff --git a/HBC/readMii.txt b/HBC/readMii.txt deleted file mode 100644 index c979922d..00000000 --- a/HBC/readMii.txt +++ /dev/null @@ -1,1078 +0,0 @@ - - __,,__, ,__wywyywvyyyyywvywvyam,,_, _,,_ - _uWB&#MBM$Wg&MQ$#$K&RMKMA0$&xNH&&MN@2W&#MM&#$KQg - JN&B&MM#MQ$gM#Q$N#R&&#N$M$#�E$##V$WKG###B&$&NW#b - j8W0##&M$W&$###�##&$0MN#BX&5&#$xA$A$#$#&#z$MNQWK#L - 3#$$& N$&WK& XN#$&~~ ^VM#&#A~`^`"~^~"'K###2$M - SQN$# 9MB#@) $$$# ***, $&mR _,_ NU#$M - &0N## #M$$M# NA4 ****** *$g# *0$Q&H! ]$N$# - M\w&F ##&#@$ #W8- ~v"&N8&*#$# 0QB#&$& !#&$K - $QNNC E&M$0# g&&&_ "*$&QM #$MN$# - j$$0L $M@WWK #W&#M&k,,_ ~&$$ _,_ $NQN( - i&M4( N$K2## M#NNF$&####& 0#$ *0$Q&H! W#$( - j$B#N V&#AMS SRW $8$0M& 3M$ 0QB#&$& #N$I - jQ0&NL ""^ JB&ML '~^ jQ*A ` j##KF - K#$##& _#B#WNKM_ ,vB&#M _ _wp#&QAF - "&NAQAN&#$&MW#&###B#x$3@&$BA#WWWH$#KMM&K&NK###g&$# - *WN$&$$8QWNMMM#MM&«&A#&M$K&#WK@QM5#&*A$N&$&WM#@2 - "M*^&N##&$W8$2B#&MB&DWR0#$$0#W»&&M$#QQMN#&"" - \eeee6 F**A1 - jM0$e4 ?**G\! - imw{Q- x%%%m \%z%%e mxx _%*%@& -ve/v mmm\ wvm - V3Q%m& /#0^0E&~/&\ $&E/&%1e^"E 55t7JcVsm0-\ &^#l@&}&-" $7MAE&&%/ - $%x/z Wc&&t7-w&E4^ %VVM~1^\&$&&} e$&$$%$zQMxw w-v-#^ Q\W44 %-/%/\QS - et-SC e^00^ iF&E$- !%%$$%A*v 5^^4 EEZ/0 )%%0%4fimmEt" "$S8V -(WJ^%i m&MM#} /%\%%L 4Q\w WQ/Q\ &m«wS \v"v1 \74~1zM%&%/6s wEw// -&ssSs?s%wt&&-~~MM#& e1/'m% &5^jW &mw&\ SmVw^ S1&mw \^A5FE j7F*5, ~S3m% -j3Q"/&-&w&M%& ^^4$w^7QSQ@ t&&&%-"5w&E} e8"&&&&/%\W &5%1\%V*\0M &&7M -~?VW^$ ?&\81? ?mQ&&&- 00%%^~EE4E \&00 ^M43^ ^'"#5&$-^ ~wEE} - __ ,_ - __ggggggggggggggg& jggggg#p gMMMMMMM - &MMMMMMMMMMMMMMMMMMF "MMMMMMM& j#MMMMMMP - #MMMMMMMMMMMMMMMMMMMF #MMMMM&g#MMMMMMP - #MMMMMF "MMMMMMMMMMM#^ - #MMMMML pgppggggggp $MMMMMMMMF - $MMMMML 4#M#NRMMMMMF jMMMMMMMMMQ - $MMMMMF #MMMMF pMMMMMMMMMMMMp - 4MMMMMMNNN#MMMMMMMMMF jMMMMMMF MMMMMM&_ - MMMMMMMMMMMMMMMMMM& #MMMMM@~ ~MMMMMM& - """""""""""""""" """""" """"""^ - - -Congratulations! You are one of the proud Beta Testers for USB Loader GX. That's right. Beta tester. This means that you are using Beta software. This program is still under heavy development. Not everything works perfectly. If you are expecting it to, stop and look elsewhere. Some of the features covered here may be removed in your version of the application. And likewise, there may be features in your revision that are not covered here. - -By using a Beta revision, you are agreeing to not be an idiot. Most of the features should be self explanatory. The rest of them can be figured out by clicking around a trying stuff out. There is no button or combination of buttons that you can click that will brick your wii or make irreparable changes to your wii. So please try out all the features to see which options need to be enabled for your WII + TV + game combination. - -This was written 6/15/2009 regarding revision 529 -Last update on 10/1/09 regarding rev 772, updated/added a few images, updated cover path info, and added MIOS Patcher to download links. - - -Features - -* The GUI is completely based on the awesome libwiigui by Tantric -* Game information: reads game info from wiitdb.zip in your config folder like publisher, developer, year, rating, genre etc. -* Widescreen support: Without any special themes for widescreen -* Alternative dol loading: Supports special dol files needed to launch some games (e.g. Mortal Kombat) -* Loading from USB: Loads files (images, configs etc.) from SD or USB (needs a FAT32 partition on the drive to be primary and active). -* Global Settings and "per game" settings -* Parental control: Set levels for each game, set a password for install/remove/etc. -* View modes: simple List Mode, Game Grid and Game Carousel. -* Supports Themes: Create your own theme and use it with the loader -* Cover download: Download "normal" covers, 3D covers and disc images for all the games on your HDD (International Covers are downloaded based on your global language setting) -* Look and feel like the original Wii Menu: Use rumble feature, button sounds, background music, disc slot lights up etc. (you can also turn it off in the settings) -* Loads all the needed files from your SD/USB -* Language file support: use your native language for the loader. -* Custom sounds: for now only ogg custom sounds possible. -* Playstats: shows you how many times you played the game -* List sorting, Game Search, & Favorites: you can sort the list by playstats or names, search by name, or display only your favorites! -* Update function: update to the latest revision from inside the gui (requires internet connection). -* Homebrew & Title Launcher: Launch you favorite homebrew apps and channels from within the loader. -* Full Alternate Dol Support: Alternate dols can be loaded from SD/USB or from the game itself. Most altdols can be automatically chosen by the loader. - - -Useful links & Downloads - -Official site & help site -http://code.google.com/p/usbloader-gui/ -http://usbloadergx.koureio.net/help - -Changelog -http://code.google.com/p/usbloader-gui/source/list - -Sourcecode checkout -http://usbloader-gui.googlecode.com/svn/trunk/ - -Game compatibility list -http://wiki.gbatemp.net/wiki/index.php?title=USB_Loader_v1.x_Game_Compatibility - -Devices compatibility list -http://wiki.gbatemp.net/wiki/index.php?title=USB_Devices_Compatibility_List - -List of WBFS managers -http://wiki.gbatemp.net/wiki/index.php?title=WBFS_Managers - -More questions? -http://forum.koureio.net/ - -cIOS installers -cIOS38r12: http://gbatemp.net/index.php?download=6093 -cIOS38r13: http://gbatemp.net/index.php?download=6133 -cIOS38r13b: http://gbatemp.net/index.php?download=6127 -cIOS38r14: http://gbatemp.net/index.php?download=6531 -Hermes cIOS222/223 rev3: http://www.4shared.com/file/125087683/2b7948f1/Hermes_cIOS_222_rev3_installer.html -Hermes cIOS222/223 rev4: http://www.4shared.com/file/129761844/53c80425/Hermes_cIOS_222_rev4_installer.html - -MIOS Patcher -WiiGator's cMIOS http://www.4shared.com/file/136843685/99990ffc/miospatcher.html - -Other -Wad manager 1.5: http://teknoconsolas.tv/wanin/WAD-Manager_v1.5.zip (mirror) -Forwarder dol for preloader: http://www.mediafire.com/download.php?nykt4zyndzq -Fat32Format: http://www.ridgecrop.demon.co.uk/download/fat32format.zip -HJSplit http://www.freebyte.net/download/hjsplit.zip (this joins 001, 002, ... files) - - - -Contents - - 1. [1] Prerequisites & setup - 1. [1a] Installation - 2. [1b] Channel & Forwarder - 3. [1c] [OPTIONAL]Autobooting and returning to USB loader GX - 4. [1d] Files & paths - 2. [2] Usage - 1. [2a] [OPTIONAL] Compiling the loader - 2. [2b] Adding games & changing GameID ***** - 3. [2c] Getting Covers & Wiitdb.zip ***** - 3. [3] Main menu - 1. [3a] Controls - 2. [3b] On the screen - 3. [3c] View - 4. [3d] Game Info - 5. [3e] Game Prompt - 4. [4] Exit Menu - 5. [5] Homebrew&Title Launcher ***** - 1. [5a] Homebrew Launcher - 2. [5b] Title Launcher - 3. [5c] (Un)Installing WADs over wifi - 6. [6] Settings - 1. [6a] Gui settings - 2. [6b] Game load - 3. [6c] Parental control - 4. [6d] Sound - 5. [6e] Custom paths ***** - 6. [6f] Update ***** - 7. [6g] Default settings ***** - 8. [6h] Credits - 7. [7] Game settings ***** - 1. [7a]Game load - 2. [7b]Ocarina - 3. [7c] Uninstall Menu - 4. [7d]Default settings - 8. [8]Cheating - 1. [8a] Using a Computer - 2. [8b] Using the USB loader - 9. [9]Themes - 10. [10]Special Games - 1. [10a]Wii Sports Resort - 2. [10b]Metroid Prime Trilogy - 11. [11]FAQ - -Everything in this Guide that is marked with ***** can not be used if the loader is locked! -Text in red is a little harder and for advanced users only! -Blue text is Important Info! - - -________________ -[1] Prerequisites & setup -[1a] Installation - -STEP 1 – Installing the HBC (Homebrew Channel) and a cIOS (custom Input/Output System «- ignore that). - -If you are COMPLETELY new to homebrew, this little guide will tell you how to install the homebrew channel on your wii. The guide can be used for every system menu (up to 4.1, so updating is recommended) and any serial (LU64+). Do not use it on a Korean wii! - -First, follow steps 1 and 2 of this guide: http://gbatemp.net/index.php?showtopic=155844 to get the HBC on your wii. The hackmii installer can also install bootmii for you if you need brick protection. Our next step is to get a cIOS installed that is needed for the loader. Try installing a cIOS with a cIOS installer (using IOS36). If this doesn't work (if you get an error while installing), you don't have a patched IOS (needed by the cIOS installer) and you have to use one of the two methods below. - - -Online method (Using wifi on the wii) -Get the Trucha bug restorer by wiipower and run it with the HBC. You will see a lot of white text on a black screen. This is how many installers/patchers look like. It has no nice banner and stuff to keep the filesize low. - - -1) Select IOS36 and press A. Even more text appears, read it if you want. Wait for the text at the bottom to appear and press 1. -2) Choose Downgrade IOS15. Then download from NUS (2 times). Follow instructions on the screen. -3) Now we can use the downgraded IOS15 to restore the Trucha in IOS36. Run TBR again. This time choose IOS15 and again press A then 1 when the text appears. -4) Go into the IOS36 menu. Use these configurations: 36 (this is in what IOS-slot the patched IOS36 will be placed.) YES YES NO (actually you can choose what you want for the last 2 options), then select Install patched IOS36 and press A. Choose Download from NUS once again and follow on screen instructions. -5) Now we have the patched IOS36, we can restore our IOS15 again. Load the TBR one last time. Choose IOS36,... .This time choose restore IOS15. Get the IOS from NUS and let the app finish everything. - -We are ready to install our cIOS. I will explain here how to get cIOS38r14 by waninkoko. You can also install another rev of this cIOS (don't go lower than r9) or a rev of IOS222/223 by hermes. All IOS have different uses and bugs. Its up to you to find out what these are. - -Get the installer here: http://gbatemp.net/index.php?download=6531 . Follow all the instructions at the link, but choose IOS36 instead of IOS249 (this is why we have patched IOS36). When you are asked to use wad install or online install, choose online install. You will then have the cIOS needed by the USB loader. - -Offline method (no wifi on the wii) -Wad files of IOS are not legal, so we can not give them to you. Here is how to get them anyway: - -Get the NUS downloader and Trucha bug restorer. - -First open NUS downloader and Click 'Generate certs' if it asks to. First check Pack-»Wad. Click Database and Go to IOS, IOS15, v257. Then click Nus Download. Repeat this proces for IOS15 v266 and IOS36 v3094. -Now go to the place where NUS downloader is and there will be 3 new folders. Copy the WAD of each folder to the SD card. - - -Now follow steps 1 – 5 from the Online guide, but instead of choosing “Download IOS from NUS”, choose “Load IOS from SD card”. - -We are ready to install our cIOS. I will explain here how to get cIOS38r14 by waninkoko. You can also install another rev of this cIOS (don't go lower than r9) or a rev of IOS222/223 by hermes. All IOS have different uses and bugs. Its up to you to find out what these are. - - -First we need one more file from the NUS: check Pack-»Wad. Get IOS38 v3610. Place the wad of the new folder at the root of the SD card. Download the cIOS installer: http://gbatemp.net/index.php?download=6531 . Follow the instructions at the link, but choose IOS36 instead of IOS249 (this is why we needed to patch IOS36). You have to choose wad installation. You will then have the cIOS needed by the USB loader. - -NOTES: --You can have cIOS36/38 and cIOS222/223 installed at the same time. Every version has its own (dis)advantages. - - --If your global cIOS is 249 and you set an individual game's cIOS to 222/223, it will not always work. On the other hand, if you set your global boot to 222 and set an individual boot to 249, it should work fine. - --If you change your global boot cIOS you need to completely exit out of the loader and restart it in order for the change to take effect. If you do not do this you will get a black screen. It is also necessary to delete your GXgamesettings.cfg file from your config folder on your SD/USB to prevent any setting conflicts since anything in GXgamesettings.cfg overrides the GXglobal.cfg file. - --Setting your global boot to 222 rev 3(installed as 37 merge 36) or 222 rev 4(installed as 38 merge 37) and setting your global 002fix to ANTI will result in 99% compatibility with no glitching/stuttering on IN REGION games. For OUT OF REGION games you need to also set the Video Mode to AUTOPATCH. The 1% non-compatibility is from the "please insert disc" games. However, those games are fully playable by simply inserting any dvd into your drive (I just stick a blank one in) OR by loading those specific games with cIOS 249 rev 12 or higher. - --Make sure you always delete the 00000001 folder from the root of your SD/USB before doing any network installation of cIOS 222/223. - -STEP 2 – Preparing your USB device - -Optional -The USB loader can load images and other info of the same usb device as where the games are stored on. To be able to use this function, you will need to make two partitions on the USB device. The partition for the images should have enough with 2GB. You can also make more partitions for other purposes. Use GOOGLE to find out how to make partitions. (Or go here: http://gbatemp.net/index.php?showtopic=179085). -For linux: http://gwht.wikidot.com/gparted - -Required -The partitions have to be formatted to FAT. Mark the partition you want to use for WBFS as Active. - -If you make multiple partitions, the First partition must be the one for image,... and the second one for WBFS (for Wii games) - - -STEP 3 – Preparing the SD card - -You can also use the USB device for this if you made a second partition in Step 2. - -Using the easy installer - -The fastest way of installing the USB loader GX is to download the Easy installer. Run this tool and click next (be sure to have an internet connection).You will be asked what files to put on the SD card/ USB device (dependant on where you run homebrew from). Recommended is to download everything except following things: --The languages that you won’t use (only one language can be checked), --If you already have images for the loader, don’t check cleanup, as it will remove the images. - -Next, you will be asked where to install the loader to. Advised is to install it to SD:\apps\usbloader_gx or USB:\apps\usbloader_gx (replace SD/USB by the drive letter of the card/device). If you’re done, click install. - -Without the easy installer - -Sometimes its not possible to use the easy installer. You will have to put on the files manually. -1) Download the newest dol from http://usbloadergx.koureio.net/downloads/revisions. -2) Create a new folder on your SD card (or USB) in the apps folder, called usbloader_gx. Place the dol in this folder and rename it to boot.dol . - -STEP 4 – Running the loader - -When you first boot up the Loader (using the HBC or another method of booting homebrew), you will be asked to format a partition to WBFS. Choose your partition and press A. If your partition is formatted, you are ready to use all functions of this app! - -NOTE: You can also format a partition to WBFS by using a WBFS manager. - - -################################### - -[1b] Channel & Forwarder -If you don't like going to the HBC to load the loader every time, you have to install the channel or forwarder of this loader. -Both Channel and forwarder appear in the wii menu as a new channel. But there is a very important difference between them! The channel contains the app and can boot it without the SD card. The forwarder however simply loads the loader from SD:/apps/usbloader_gx/. There are (dis)advantages to both. Go here for more info: http://usbloadergx.koureio.net/downloads/forwarders - -To install the forwarder or channel, you need an application called Wad manager. Get it here: http://teknoconsolas.tv/wanin/WAD-Manager_v1.5.zip -Place it in its own folder in the apps folder of the SD card (or USB). - -Download forwarder: http://www.mediafire.com/?jdmiykainlm -Download channel (R649c): http://www.mediafire.com/download.php?ntuexwmycby -Create a new folder on the SD card (or USB) called wad. It has to be in the root of the SD card (so not in the apps folder). Place your wad here. - -Run the wad manager. Choose IOS249. Then choose SD or USB (depending on where you placed the wads). Select the wad to install and press A to install it. When its done, keep pressing B to go back to the HBC. Then go to the wii menu. You will see your new channel/forwarder on one of the pages. You can move it by holding A and B. - -Changing the location the forwarder loads the dol from: To do this, simply change the update path (see [6e]) - - -[1c] [Optional]Autobooting and returning to USB Loader GX - -It is possible to boot your wii directly into the USB loader GX. The only thing you need for this is a wii app called preloader. First download the newest rev of the loader or even better, the forwarder (dol format, see downloads at the top of the readmii). Place the dol you get in the root of your SD card (no need to rename it to boot.dol). In the preloader menu, choose install file and choose the dol to install. When its done, go to the main menu of preloader (B) and then choose 'settings'. You have to change 2 options here: Autoboot=file and Return to=preloader. Save the settings, then launch the Wii menu in the main menu. It will boot into the USB loader GX! - -################################### - -[1d] Files & paths - -There are other files that are not necessary to the core functionality of this loader, but are used for extra features. The dev. team has defined the following paths, most of which are configurable in the settings. - -Update Path - SD:/config/ -This is where the application will create files to save settings and statistics. All the files it makes start with GX to make them easy to find. -GxGlobal.cfg is the main settings and configuration for the loader. -GXGameSettings.cfg contains individual settings for games. -GXGameCount.cfg stores the game play count and favorites choices. A database of information about each game can be stored in this folder as well. Get you hands on wiitdb.zip and put it here. - -Covers Path - SD:/images/ -This is where box art is downloaded to and displayed from. All images must be sized in multiples of 4 or they won't show up. Create separate folders for 2D and 3D covers. When you direct each path to the proper folder the default displays are 3D for the List and Carousel views and 2D for the Grid view. -Official sizes: -2D covers = 160x224 -3D covers = 176x248 - -Disc Image Path - SD:/images/disc/ -This is where pictures of the actual game discs are downloaded to and displayed from. All images must be sized in multiples of 4 or they won't show up. -Official size: -Discart = 160x160 - -Background Music Path - SD:/config/backgroundmusic/ -This is the default folder for custom background music. - -Theme Path - SD:/theme/(SD:/wtheme for widescreen wii) -This is the default theme location. - -Cheatcodes Path - SD:/codes/ -This is the folder to put your gct cheat files. - -TXT Cheatcodes Path - SD:/txtcodes/ -Here is where you can place the txt files needed by the code manager. Files must have the full game ID (6 chars.) as name. The downloaded txt files (with the code manager) will be placed here. - -DOL Path - SD:/ -This is where replacement dols (used to fix certain broken games) go. - -Homebrew Apps Path - SD:/apps/ -This is where you can place the Homebrew apps for the Homebrew Loader. - - -________________ -[2] Usage - -Using this application is simple. Launch it in the same way that you did in the initial setup, pick a game (if you have any installed), and play the game. This is open source software. You are free to modify it, distribute it, and do anything you want with it. All we demand is that you do not claim our work as yours. We worked long and hard on this and let you use it for free. It would be a real bitch move if you put your name on it and said it was your own. -You are also free to distribute the software/source code as you like as long as this file (or a similar one approved by the dev team) companies it. If you don't follow these guidelines, you are a douche-bag. - -################################### - -[2a] [Optional] Compiling the loader - -THIS IS COMPLETELY OPTIONAL. IF YOU ARE NOT INTERESTED IN PROGRAMMING OR COMPILING, OR IF YOU DON'T MIND WAITING FOR SOMEONE ELSE TO COMPILE THE NEWEST REV, YOU CAN SKIP TO [2b]. - -This loader gets updated very frequently. The newest revision will not be available all the time to download. When that happens, you will have to compile the loader yourself. GBAtemp members emupaul and giantpune have made a guide that shows you how to compile the loader.The full guide can be found at http://gbatemp.net/index.php?showtopic=169078 - -1)Download a svn client. Reccomended is Tortoisesvn. If you want the loader to show the rev# in the settings, you also need sliksvn. -2)Download and install Devkitpro -3)Reboot your system -4)Create a new folder (can be anywhere) and name it USBGX (or any other name, as long as you know what it contains) -5)Right click your folder and select SVN Checkout (this option is added by Tortoisesvn) -6)Enter the url http://usbloader-gui.googlecode.com/svn/trunk/. Leave all other options as they are and click OK -7)Download http://usbloader-gui.googlecode.com/files/...-08-07-2009.zip and extract to the libogc folder -8)After it has downloaded the source, all folders will show a green OK mark. Open the file gui.pnproj -9)You are now in the programmers notepad. This utility is used to program wii apps. Press ALT + 1 (the 1 thats not on the Numpad) to compile the source. -10)Copy the boot.dol (or elf) to the SD card and run it. - -[OPTIONAL] Changing the source for the channel: You have to make a small change in the code to let the USB loader know its a channel. -1)Open Gui.pnproj, it wil open with the Programmers notepad. -2)Time to make a little change in the code (maybe your first time doing this :) ). You should see the file structure (If not, go to view»windows»projects and enable it, then place it somewhere). Open the prompts folder (if it isn't open already) by clicking the white arrow in front of it. Then open PromptWindows.h (double click) -3)It will appear in a new window. At the top of the file you should see #define NOTFULLCHANNEL -4)Put your cursor before the # at this line and type //. The line will become green and will look like: //#define NOTFULLCHANNEL. This line is now a comment. Comments are just extra information and are not compiled. -5)Compile the source by pressing ALT+1. Now you have the correct boot.dol, which you can inject in the channel. - -################################### - -[2b] Adding games & changing GameID ***** - -To add a game to your drive using this program, click the install button on the main screen and follow the on screen prompts. Games are automatically scrubbed (shrunk) and brickblocked (update partition removed) when adding them to the drive. - -Because of the way WBFS and the application work, you are only allowed to install 1 game for each game ID. If you do use another application to install 2 games with the same 6 character ID, only the first one on the drive will be loaded by our program. If the installation freezes (doesn't move for over 2 minutes) you can simply hold the power button on the Wii to turn it off. There is no danger of bricking your wii. The data that was written during the failed install is still present on the drive, but not marked as active so it will be treated as free space. It does not get added into the used space displayed on the screen and it will be overwritten next time you install a game. - -To install games (ISO or cISO) with your computer, you need a WBFS manager. Most popular are WBFS manager 3.0 and WBFS intelligent GUI v6. Using these programs should be self-explanatory. - - -***The following feature is for advanced users only! Do not use this feature unless you know exactly what you are doing!*** -As of revision 719, it is now possible to edit GameIDs via the loader which is useful with different games using the same GameID (ie; Guitar Hero mods). When viewing the GUI in list mode, simply click on the GameID displayed underneath the targeted game's cover (if GameID isn't displayed, see section [6a]) to bring up the ID change prompt. Keep in mind that this will create a new save file for the targeted game and will no longer load a previous save file unless the GameID is restored to it's original ID. - -################################### - -[2c] Getting Covers & Wiitdb.zip ***** - -This loader can show the boxart and discart for every game. The images have to be placed in the correct folder and must have the correct name and size (more info at [1a]). To download covers with this loader, you need to press 1 at the main menu. You can choose what covers you want to download (2D or 3D). Discart can also be downloaded. - -It is also possible to show the info for each game. You can show the game info by highlighting a game (don't press A, just point) and pressing 2. The data for the game info is stored in wiitdb.zip. There are two ways to get this file: - --Update with the loader and select update all or update wiitdb, it will also be updated if you update the full channel. --If you have no wifi, go to the game info screen of any game. Press 1 and you will see the text at the bottom change. Go to the file it shows and copy the URL. Then open the url with a web browser to download the wiitdb.zip. Once you got wiitdb.zip , place it in the titles.txt path (see Custom paths) - -NOTE: All images and wiitdb.zip are downloaded from the site www.wiitdb.com . - -________________ -[3] Main menu - -This is the main screen, the first one you see when you start the program. It looks a lot like the Wii system menu. (Default theme) - -################################### - -[3a] Controls - -User input for the main menu is accepted through WiiMote, Nunchuk, Gamecube controller, and Classic controller. While input is accepted from all these methods, the fastest and easiest method is with a WiiMote. - -Wiimote -A --- Main action Button -B --- Back/Cancel/Scroll (list view) -- Button --- Left (Grid/Carousel/game prompt/settings) -Home --- Open Exit menu -+ Button --- Right (Grid/Carousel/game prompt/settings) -1 --- Download covers -2 --- Show game info (select a game first) -D-Pad --- Choose -Pointer --- Choose - -Nunchuck -Control stick --- Choose - -GC Controller -Control stick --- Choose -D-Pad --- Choose -A --- Main Action button -B --- Back/Cancel/Scroll (list view) - -Classic controller -Left control stick --- Choose -D-Pad --- Choose -A --- Main action button -B --- Back/Cancel/Scroll (list view) -X --- Game info -Y --- Download covers -- Button --- Left (Grid/Carousel/game prompt/settings) -Home --- Open Exit menu -+ Button --- Right (Grid/Carousel/game prompt/settings) - -################################### - - -[3b] On the screen - -1.Install ***** -- (+) button at the left -- Press to add games to your HDD from the Wii's DVD drive. - - -2.Settings -- Button with gear on the left -- Use it to access all the settings and options. - - -3.Exit -- Button with 'wii' on the right -- Press this to view the exit menu. - - -4.Power -- Button with power logo at the right -- I bet you can figure out what it does. - - -5.Download ***** -- Listview: cover -- When you are in the list view, click a game box to download stuff. You can also use the 1 button in any display mode. - - -6.Reload -- SD card button -- Press it to reload your SD contents (images, themes,…). - - -7.Homebrew Loader -- Button right of the HDD info -- Run the Homebrew Loader - - -8.Sort bar -- Bar at the top -- contains 9 - 16 from left to right - - - 9.Favorites --- Press it to hide all games that are not marked as a favorite. - - 10. Game Search --- Use this button to only list games that start with a certain letter. - - 11.Abc --- Your games will be sorted alphabetically. - - 12.Playcount --- Sort games by the number of times you have launched them from this application. Games with the same count are sorted alphabetically. - - 13.List --- Press it to see games listed by name and any available box art for 1 game at a time. - - 14.Grid --- Use this button to see your games arranged in a grid. The number of rows available depends on how many games are on you drive. 39 games can be seen at the most. - - 15.Carousel --- Press this to see you games arranged in a rotating fan array. 7 games can be seen at a time. - - 16. Load from Disc --- Boot the current game disc that is inserted in the Wii disc drive. cMIOS is required in order to play Gamecube backups. - -17.Clock -- Above the HDD info -- This looks like a digital clock. Coincidently, it functions like a clock. - -18.HDD Info -- In the middle, at the bottom -- This shows some information about your connected HDD (only the WBFS partition). Free & total space in GB as well as the game count. GB is defined here as 1024MB. When you bought your drive, the manufacturer probably used 1000MB for GB so the size displayed here will be less than what your drive was advertised as. The game count will reflect the games you are choosing to display, not the actual amount of games on your drive. If you are hiding games with parental controls/favorites, they will not be added into this total. - -################################### - -[3c] View - -There are 3 different ways to view your games. - -List --- Games are listed by name (up to 9 at a time) box art for the selected game is displayed. This is currently the only screen you can initiate a download for artwork from. Also on this screen The B button has a slightly different use. If there are scrollbars present on your gamelist, holding B and moving the cursor scrolls the list. - -Grid --- Games are arranged in a grid (up to 320). The number of rows available depends on how many games are on you drive. By default, it is 3X14 (with the last column hidden)if there aren’t enough games to fill all 42 spots, it changes to 2x8 (2x7 shown on screen). Again, if there aren’t enough games to fill it up, the number of rows decreases. - -Carousel --- Games are arranged in a rotating fan array (up to 320). Up to 7 games can be seen at a time. - -################################### - -[3d] Game Info - -Pressing 2 (or X on CC input) brings a prompt with information about the selected game. This info is read from the wiitdb.zip file discussed earlier. Among the displayed information are the following: - -Accessories --- The supported accessories for the game are shown in the lower left. The max number of players is shown on the image of the WiiMote. Any required accessories are shown in light blue. - -Rating system --- The rating for the game is shown in the lower left of the screen. It is converted internally between PEGI,ESRB, and CERO (though not used for anything yet). - -Wifi --- The number of online players is displayed to the right of the accessories. Any other wifi features are listed above the accessories. - -Synopsis --- If a synopsis is present in the file, it can be viewed by pressing A on the game info screen. You need to set the game language to the language of synopsis you want to view! - -Wiitdb.zip will get updated when you update all or update the full channel. Only the info for the games and language you have will be downloaded. If you do not have the possibility to update with the loader because you have no Wifi, go to the game info screen and press 1 (Rev637 or higher needed). It will store a link in a file as shown at the bottom. Open the file and copy the link. Then open it with a web browser to download the file. Place the Wiitdb.zip in the titles.txt path. - -################################### - -[3e] Game Prompt - -This is the prompt that comes up when a game is selected (if the quickboot option is disabled). - -Play --- Click the spinning disc to launch this game. - -Rename ***** --- Click the title of the game in the top of the prompt to rename it directly on the WBFS file system. If you are using titles.txt or wiitdb.zip, this will have no (visible) effect. - -Back --- Closes this prompt. - -Favorite --- Click the star to add/remove this game from your favorites. - -Size --- The amount of space that the game occupies on the WBFS. - -Count --- The number of times you have launched this game using this application. - -Settings ***** --- Here is where you go to enter settings that will be used for this game only. - - -________________ -[4] Exit Menu - -This is the screen that appears when you press the home button on the WiiMote or the exit button in the main screen. - -Return to loader --- if you launched USB Loader GX from HBC, LoadMii, or similar chain loading application, you will see this button. Pressing it will take you back to the application you came from. - -Homebrew Channel --- Brings you to the homebrew channel - -Wii Menu --- Exits to the Wii System Menu. - -Batteries --- Status for all connected WiiMotes is displayed here. - -Close --- Closes this screen and returns you to where you were in the application before this screen was called. - - -________________ -[5] Homebrew&Title Launcher ***** -[5a] Homebrew Launcher - - -New since rev627 is the Homebrew Launcher. You can activate this function by clicking on the icon right of the HDD info at the main screen (the button looks like the Homebrew channel). Just like the HBC, all apps of the specified folder will be shown in groups of 4. The images of the apps are shown on the left, and the name to the right. When you click an app, the info in the meta.xml will be shown. - -Folders of homebrew must contain a .dol or .elf . Unlike the HBC they do not have to be renamed to boot.dol or boot.elf . -The folder may also contain an icon.png (size 128x48), meta.xml and other data that the app needs to run. - -################################### - -[5b] Title Launcher - -Since rev648 it is also possible to load channels. To access the title (channel) launcher, go to the Homebrew launcher. There you will see two buttons in the bottom right. The first (left) button leads to the title launcher. -If you want the correct names of the channels to display, you need a database.txt found here: http://pastebin.com/f6fb1533b. Place it in the config folder. -You are free to edit this file online, but do not add Homebrew channels. These have title IDs that can be different on other wiis. - -################################### - -[5c] (Un)Installing WADs over wifi - -FOR ADVANCED USERS ONLY! - -EASY METHOD - -Guide by GBAtemp member NeoRame - -1) Download the wiiload installer found here -2) Connect the wii to wifi. Go to the Homebrew channel and press Home. You will find your wiis IP here. -3) Run the Installer and choose next. Enter the wii IP and choose install. -4) Launch the USB loader GX and go to the Homebrew Launcher, then go to the Title (channel) launcher. -5) On your PC, double click a .wad .dol or .elf to send it to the Wii (You can also right click and choose Send to wii). If you send a wad, you will be asked to (un)install it or not. - -NOTE: If you can't get it to work, reboot your computer and try again. - -DIFFICULT METHOD (Use if the easy one doesn't work) - -Guide made by GBAtemp member Logan -What you will need: - - - * Your Wii's IP address (see below for details) - * WiiLoad - * This guide is for Windows only. I don't use Linux - - -1) Download WiiLoad from the above link and extract the contents. -2) Copy/Move wiiload.exe to C:\Windows\System32\ -3) Open Notepad and copy the following into it: - -Windows Registry Editor Version 5.00 - -[HKEY_CLASSES_ROOT\.WAD] -@="" - -[HKEY_CLASSES_ROOT\.WAD\shell] - -[HKEY_CLASSES_ROOT\.WAD\shell\Send to Wii!] - -[HKEY_CLASSES_ROOT\.WAD\shell\Send to Wii!\command] -@="c:\\windows\\system32\\wiiload.exe \"%1\"" -4) Save the file as "wiiload.reg" -5) Double click the file and accept entering the entries into the registry. -6) Boot up your Wii and load the USB loader GX. Go to the Homebrew Launcher and hover over the WiFi Wii icon. A tooltip will pop up showing your IP address. Make a note of it. -7) Set the environment variable by going to your computer's Control Panel -» System -» Advanced -» Environment Variables, then click "new" under either category. The variable name is WIILOAD and the value is tcp:yourIP, where yourIP is the Wii's IP/hostname. Click "OK" here and in System Properties. -8) Now go to the title (channel) browser on your wii. On your PC, right click on a .WAD file and you should now see a "Send to Wii!" option. Click on this and watch the magic work at the Wii end of business. -9) [Optional] Double click on a .WAD file and choose c:\windows\system32\wiiload.exe as the application to open it. Now double clicking .WAD files will send them to your Wii. -10) To uninstall, simply send the same .WAD file to the Wii. - -Use your noggin when dealing with WAD's. I won't be held accountable for any misuse! - - -________________ -[6] Settings - -This is where you customize the behavior of the program. - -################################### - -[6a] Gui settings - -These are the settings that affect the behavior and feel of the GUI. Your settings are saved when exiting back to the main screen, change custom paths, change views in the main screen, and a few other times. - -App language ***** --- If you have a language file to translate this program, you can select it here. You can change the path by clicking it at the top of the screen. The button in the lower right will restore the default (English). -NOTE: Newest revs will automatically load your language if it is found. - -Display --- In the list view, you can chose to display the selected game's region and ID here. - -Clock --- Choose how you want the clock displayed. - -Tooltips --- Enable tooltip help you with the various buttons and options. - -Flip-X --- This changes the behavior of left and right on the game prompt and Grid/Carrousel. If it feels un-natural, change this setting. - -Prompts/Buttons --- Select whether or not to apply the widescreen fix to prompt windows and certain buttons in the GUI. - -Keyboard --- Choose between different layouts for the on-screen keyboard used in the GUI. - -Discimage Download --- Select what discimages have to be downloaded -Only Original: Always get original discart -Only Customs: Always get custom discart -Original/Customs: Get original discart. Get custom discart if original is not available -Customs/Original: Get custom discart. Get original discart if cutom is not available - -Wiilight --- Change the behavior of the disc slot light. - -Rumble --- Turn rumble on/off. - -Auto init. network --- Turn this ON to automatically initialize the network at boot. If a new update is available, you will be asked if you want to download it. -IMPORTANT: Turning on this function may cause malfunctioning of the loader and games! - -Titles from XML --- Choose if you want to ignore the titles stored on the xml file (in wiitdb.zip) or titles.txt and use the ones stored on the WBFS. - -Screensaver --- Set how long it will take to activate the screensaver in case of inactivity. The screensaver switches off the Wiimote. - -################################### - -[6b] Game load - -Change settings that have to do with the way games are booted. These will be use as default if you don't set any specific settings for that game. - -Video mode --- Select the video mode to use for games. Most games work with disc default. If this doesn't work, try console default. Then if you still need to, try forcing your region. - -vidTV patch --- Patches the signal after the game has rendered it in the mode selected in video mode. If none of the video modes work, try this. - -Game language --- The language that is passed to the game when it is booted. If the language is supported by the game, it will be used in game. - -Patch country strings --- Use this for Japanese imports. - -Ocarina-- Turn on/off the ocarina cheat engine. You need gct files in the cheatcode path mentioned earlier. - -Boot/standard ***** --- Select the cIOS that is used to boot the program into. - -Quickboot --- Choose if you want to skip the game prompt when starting games. - -Error 002 fix --- With certain IOS, some games show an error that says "blablabla, 002, blablabla. Don't be a pirate." Turn this on to fix it. -Anti: Some cIOS have 002fix build-in. Unfortunately, this makes some games unplayable (the reason for this is that there are 2 types of 002 fix, and some games won't play with the one found in some cIOS). Activate the Anti002fx to play these games. Known games that need Anti002fix (they use 002fix on with some cIOS): Burger Island, Diabolik The Original Sin, Ghostbusters, Indiana Jones and the Staff of Kings, MySims Racing, Nutrition Matters, Solitaire And Mahjong, Takt of Magic - -################################### - -[6c] Parental control - -Settings for parents to control what content their kids see. Everything in this document with ***** beside it is hidden/unusable when the application is locked. - -Console --- Click here to lock/unlock advanced features. Requires password to unlock. - -Password ***** --- Click here to set a password. When locked it's shown as ******** - -Control level ***** --- Set the level of parental control here. Games will be excluded from the game list based on this and the settings you have for them in the game-specific settings. Also shown as ******** when the loader is locked. - -################################### - -[6d] Sound - -Settings related to audio are here. - -Background music --- You can chose custom BG music to be heard in the application here. Click the path at the top to change it. Format is OGG. Keep in mind that bigger songs will result in decreased memory available for other functions. It is possible to completely crash the loader with big files. Try to keep it «3MB to be safe. If you want to rock out to your music, use a media player. This is a game loader. - -Music volume --- Pick the volume for the BG music within this application, not in the games that are booted. - -SFX volume --- Pick the volume for the sound effects within this application, not in the games that are booted. - -################################### - -[6e] Custom paths ***** - -Below paths the program uses are customizable. Click a path to browse for its new destination. - -3D Cover Path --- For 3D boxart. When properly defined, 3D cover art will display in List and Carousel views by default. - -2D Cover Path --- For 2D boxart. When properly defined, 2D cover art will display in Grid view by default. - -Discimage path --- For Discart. - -Theme path --- For themes. - -XMLpath ---For wiitdb.zip - -Update path --- Used for updating the dol. If you are using our forwarder, it loads dols from this path. - -Cheatcodes path --- For gct & ocarina use. - -Txtcheatcodes path --- For txt files holding the codes for the code manager - -Dol path --- Contains replacement dols (Alternate dols) for certain broken games. - -Homebrew apps path --- Where you place your homebrew apps for the Homebrew Loader. - -################################### - -[6f] Update ***** - -Click to get updates online. Just because there is a newer revision than what you are using does not mean that it will be on the update server. Also, you get the choice to update dol or update all. The last option will update the dol, HBC icon.png and meta.xml - -It is also possible to update the full channel (This will also download wiitdb.zip). The channel needs a small change in the code before it can be updated. If you have a channel and you see the update all button, you can not update the channel. You have to get another one. - -################################### - -[6g] Default settings ***** - -Click here to restore default settings. You can also delete GXGlobal.cfg to do this if you get an error at boot. - -################################### - -[6h] Credits - -Look at the people that made this application possible. You get to rock out to some cool music, too. In the upper right corner you can see your rev# and the cIOS that your are currently running. - - -________________ -[7] Game settings ***** - - -Settings are available on a per-game basis from the prompt window. These settings have the same effect as the global settings, but are only used for the selected game. -NOTE: If quickboot is enabled, you cannot change the settings. So make sure you configure them before enabling quickboot. - -################################### - -[7a]Game load -After making changes, you must click the save button for them to take effect! - -Videomode --- see [6b] Game load -vidTV patch --- see [6b] Game load -Game language --- see [6b] Game load -Ocarina --- see [6b] Game load -Ios --- see [6b] Game load -Parental control --- see [6b] Game load -Error002 fix --- see [6b] Game load -Patch country strings --- see [6b] Game load - -Alternate dol --- This is for advanced users only. There are certain games that do not run because they reload IOS and this causes the USB to be dropped. -Select a dol: Use the next option to browse for an alt dol on the WBFS partition -Dol from SD/USB: Extract the proper dol from the ISO (using wiiscrubber) and name it with the 6 character game ID and put in the dolpath. - -Selected dol --- If you put Alternate dol on 'Select a dol', this function can be used to do so. (Even if the box is empty, you can click it) - -Save --- Writes the settings that are on the screen right now to the GXGameSettings file, behind the current game ID. - -################################### - -[7b]Ocarina - -Opens the cheat manager. For more info, see [8]Cheating - -################################### - -[7c] Uninstall Menu -If you click this button, you will see a new menu. You can uninstall everything here: the game, boxart, discart and TXTcheat file. You can also reset the playcounter here. - -################################### - -[7d]Default settings - -Restore all default settings for the game. (The default settings can be changed in [6b]Game load) - - -________________ -[8]Cheating - -With the build in application called Ocarina, it is possible to cheat by using the USB loader GX. To enable cheats, you will need a gct file with the gameID of the game in the correct path. (The cheatcodes path, see custom paths) - -There are two ways to create a gct file. For both, you will need a txt file that contains all the codes for the game. - -################################### - -[8a] Using a Computer - -All needed txt files can be found on http://geckocodes.org/. If you cannot find codes for your game, it means there are no codes available for that game. -To turn the txt files in gct files, you need the codemgr. It is included in the Ocarina download (check wiibrew.org). - -Open the txt file with the codemgr. You will see all the codes that are in the txt file. Sometimes the txt file has errors. In that case you need to open it manually with a txt editor. You can select all the cheats you want to enable. - -Some codes require that you fill in an amount of XX or other letters to make the code work. The values can usually be found in the comments. Select the letters you want to change and type the correct value over them. Then click ‘store settings’. - -If you filled everything in and enabled all cheats you want, click the ‘export to gct’ button. Choose the SD/USB you want to store the file to. It will create a file in the map codes. If you changed the path in the settings of the loader, you have to place the gct file in the right direction. - -################################### - -[8b] Using the USB loader - -Go to the Game settings. There, choose ocarina. If it doesn’t find a txt file with the gameID of the current game, you will be asked if you want to download it. You can also manually download the txt file, but don’t forget to rename it to the correct title ID (and place it in the txtcodes path, see custom paths). After you downloaded it, use the same Ocarina button to go to the code manager. Select all codes you want to enable, then click 'create' if you’re done. NO LETTERS CAN BE CHANGED USING THIS METHOD. TO MAKE THE CODES WORK THAT CONTAIN THEM, EDIT THE TXT FILE OR USE THE CODEMGR! It will bring you back to the gamesettings screen. - -################################### - -After you used on of above methods to create your gct file, enable ocarina in the game settings (game load), save and boot the game. - - -________________ -[9]Themes - -It is possible to theme this program. Many of the images can be replaced and moved. Every theme must include a GXTheme.cfg in the same folder as where you put the images. Here is a list of what you can put into the GXtheme.cfg : -#################### GXTheme.cfg ##################### -## Copy to a txt file and rename it to GXTheme.cfg. ## -## Don't touch lines starting with # ## -## Values between [] are defaults ## -###################################################### - -#### coordinates: x and y are coordinates in pixels, width and height are also in pixels #### - -## battery1_coords = x,y -- [245,400] -- For battery indicator 1 (exit menu) -battery1_coords = 245,400 - -## battery2_coords = x,y -- [335,400] -- For battery indicator 2 (exit menu) -battery2_coords = 335,400 - -## battery3_coords = x,y -- [245,425] -- For battery indicator 3 (exit menu) -battery3_coords = 245,425 - -## battery4_coords = x,y -- [335,425] -- For battery indicator 4 (exit menu) -battery4_coords = 335,425 - -## clock_coords = x,y -- [0,335] -- For the clock -clock_coords = 0,335 - -## covers_coords = x,y -- [26,58] -- For the game covers (list view) -covers_coords = 26,58 - -## gamecarousel_coords = x,y,width,height -- [0,-20,640,400] -- For the carousel (carousel view) -gamecarousel_coords = 0,-20,640,400 - -## gamecarousel_favorite_coords = x, y -- for the favoriteIcon in game-carousel-mode -## gamecarousel_search_coords = x, y -- for the searchIcon in game-carousel-mode -## gamecarousel_abc_coords = x, y -- for the abcIcon in game-carousel-mode -## gamecarousel_count_coords = x, y -- for the countIcon in game-carousel-mode -## gamecarousel_list_coords = x, y -- for the listIcon in game-carousel-mode -## gamecarousel_grid_coords = x, y -- for the gridIcon in game-carousel-mode -## gamecarousel_carousel_coords = x, y -- for the carouselIcon game-carousel-mode -## gamecarousel_dvd_coords = x, y -- for the dvdIcon game-carousel-mode - -## gamecount_coords = x,y -- [0,430] -- For the gamecount (below HDD info) -gamecount_coords = 0,430 - -## gamegrid_coords = x,y,width,height -- [0,20,640,400] -- For the gamegrid (grid view) -gamegrid_coords = 0,20,640,400 - -## gamegrid_favorite_coords = x, y -- for the favoriteIcon in game-grid-mode -## gamegrid_search_coords = x, y -- for the searchIcon in game-grid-mode -## gamegrid_abc_coords = x, y -- for the abcIcon in game-grid-mode -## gamegrid_count_coords = x, y -- for the countIcon in game-grid-mode -## gamegrid_list_coords = x, y -- for the listIcon in game-grid-mode -## gamegrid_grid_coords = x, y -- for the gridIcon in game-grid-mode -## gamegrid_carousel_coords = x, y -- for the carouselIcon in game-grid-mode -## gamegrid_dvd_coords = x, y -- for the dvdIcon in game-grid-mode - -## gamelist_coords = x,y,width,height -- [200,49,396,280] -- For the list of games (list view) -gamelist_coords = 200,49,396,280 - -## gamelist_favorite_coords = x, y -- for the favoriteIcon in game-list-mode -## gamelist_search_coords = x, y -- for the searchIcon in game-list-mode -## gamelist_abc_coords = x, y -- for the abcIcon in game-list-mode -## gamelist_count_coords = x, y -- for the countIcon in game-list-mode -## gamelist_list_coords = x, y -- for the listIcon in game-list-mode -## gamelist_grid_coords = x, y -- for the gridIcon in game-list-mode -## gamelist_carousel_coords = x, y -- for the carouselIcon in game-list-mode -## gamelist_dvd_coords = x, y -- for the dvdIcon in game-list-mode - -## hddinfo_coords = x,y -- [0,410] -- For the HDD info -hddinfo_coords = 0,410 - -## home_coords = x,y -- [485,367] -- For the exit menu button -home_coords = 485,367 - -## homebrew_coords = x,y - [425,400] -- For the Homebrew launcher button -homebrew_coords = 425,400 - -## id_coords = x,y -- [68,305] -- For the game ID (list view) -id_coords = 68,305 - -## install_coords = x,y -- [16,355] -- For the install button -install_coords = 16,355 - -## power_coords = x,y -- [576,355] -- For the power button -power_coords = 576,355 - -## region_coords = x,y -- [68,30] -- For the region (list view) -region_coords = 68,30 - -## sdcard_coords = x,y -- [150,390] -- For the Reload SD button -sdcard_coords = 150,390 - -## setting_coords = x,y -- [60,367] -- For the settings button -setting_coords = 60,367 - -#### show: 0 = don't show, 1 = show #### - -## show_battery = show -- [1] -- Show the battery indicators -show_battery = 1 - -## show_gamecount = show -- [1] -- Show the gamecount -show_gamecount = 1 - -## show_hddinfo = show -- [1] -- Show the hdd info -show_hddinfo = 1 - -## show_id = show -- [1] -- Show the game ID -show_id = 1 - -## show_region = show -- [1] -- Show the region -show_region = 1 - -## show_tooltip = show -- [1] -- Show tooltips -show_tooltip = 1 - -#### colors: red, green and blue go from 0 to 255 #### - -## clock_color = red,green,blue(,alpha) -- [138,138,138(,255)] -- Color of the clock -clock_color = 138,138,138(,255) - -## gametext_color = red,green,blue(,alpha) -- [0,0,0(,255)] -- Color of the gametext -gametext_color = 0,0,0(,255) - -## info_color = red,green,blue(,alpha) -- [55,190,237(,255)] -- Color of info (like HDD info) -info_color = 55,190,237(,255) - -## prompttext_color = red,green,blue(,alpha) -- [0,0,0(,255)] -- Color of text in prompts -prompttext_color = 0,0,0(,255) - -## settingstext_color = red,green,blue(,alpha) -- [0,0,0(,255)] -- Color of the text in the settings -settingstext_color = 0,0,0(,255) - -#### transparency: Alpha = from 0 (fully transparent) to 255 (Not transparent) - -## batteryUnused = Alpha -- [70] -- Transparancy of Battery indicators that are not used -batteryUnused = 70 - -## tooltipAlpha = Alpha -- [255] -- Transparency of tootltips -tooltipAlpha = 255 - -#### Allign: Allign = left/centre/right #### - -## clock_allign = Allign -- [centre] -- For the clock -clock_allign = centre - -## gamecount_allign = Allign -- [centre] -- Allign of the gamecount -gamecount_allign = centre - -## hddinfo_allign = Allign -- [centre] -- Align of the HDD info -hddinfo_allign = centre - -#### others #### - -## maxcharacters = x -- [36] -- Amount of characters shown before text starts scrolling left. (long text) -maxcharacters = 36 - -## pagesize = x -- [9] -- Amount of games in the list (list view) -pagesize = 9 - -## sortBarOffset = x -- [1] -- Amount of pixels the sortbar jump right when going to grid/carousel -sortBarOffset = 100 - - -________________ -[10]Special Games - -This section will explain on how to run some games with special boot methods. -The methods for Alt-dol from SD are explained here. You can also use Alt-dol from disc (use the same dols). If you have to rename the dol, replace the X by E (NTSC-U), P (PAL) or J (NTSC-J)! - - -[10a]Wii Sports Resort - -IMPORTANT: Wii sports resort requires the WII MOTION PLUS. If you do not have it, you can not run this game! -Booting WSR isn't too difficult. But as its different from usual booting methods, it is listed here. - -1) When you boot it for the first time, Alt dol loading must be enabled. -Alt dol info: Extract the player.dol and rename it to RZTX01.dol -Depending on your cIOS, 002fix or Anti002fix may be needed. -2) Watch the WM+ instruction video. After you watched it, the Wii will crash, so reboot. -3) From now on, load the game with Alt-Dol OFF - - -[10b]Metroid Prime Trilogy -Remove the disc before starting MPT! - -Select a DOL -1) First time boot the game without alt-dol (If this doesn't work, enable Dol from disc and use rs5fe_p.dol). Create a save file and exit the game. -2) From now, always use dol from Disc and choose the dol of the game you want to play: -rs5mp1_p.dol for Metroid Prime 1 -re5mp2_p.dol for Metroid Prime 2 -rs5mp3_p.dol for Metroid prime 3 -Then save and boot the game. -You need to do this EVERY time you boot the game - -Load From SD/USB -This is one of the most difficult games to boot from USB. First, you need to extract 3 alt-dols: -rs5mp1_p.dol for Metroid Prime 1 -re5mp2_p.dol for Metroid Prime 2 -rs5mp3_p.dol for Metroid prime 3 - -1) First time boot the game without alt-dol (If this doesn't work, extract rs5fe_p.dol, rename it to R3MX01.dol and boot the game with this alt-dol). Create a save file and exit the game. -2) Now the difficult part: All 3 alt dols have to be named R3MX01.dol . For this to be possible, you have to make a folder for each one. Every time you want to change game, you have to change the alt-dol path. The alt-dol that is used decides which game is play-able in the trilogy. - -Method to get MP3 working (NOTE: some versions of MPT can't boot MP3, evn with this method): -1) Install Hermes cIOS222 -2) In global game load, set Boot/standard to cIOS222 and enable 002fix -3) In specific game load, use cIOS222 -4) Run the game with the MP3 alt-dol -5) If the you get a black screen or an error message (Please Insert Metroid Prime 3 Disc), try inserting ANY DVD into the drive. Blank DVDs are acceptable. - - -________________ - -[11]FAQ - - -Q: Does this loader work on system menu X ? -A: Yes, it works on any system menu - - -Q: The Usb loader can’t find my HDD. What do I do now? -A: Be sure to have cIOSr9 or above (Or one of Hermes’ cIOS). If you use cIOSr12 or greater you have to try both USB ports! If this doesn’t work, check if your drive is compatible (use the devices compatibility wiki at the top of this readmii) - -Q: How can I use other usb devices (like Wii speak) in my games? -A: Install cIOSr12 or above. One port will be for the HDD and the other one for the device you want to use. - -Q:Do I have to rename all my games manually? -A:No. You can use wiitdb.zip to rename games automatically. More info in [2c] - -Q: Can I use the titles.txt to rename my games -A: No. Support for titles.txt has been dropped. Use wiitdb.zip - - -Q: I saw there is a newer rev available. Why can't update with the loader (it says no update available)? -A: The updates for the loader are on a different server. Not every rev will be available for download. Most revs will be available from http://usbloadergx.koureio.net/downloads/revisions. - - -Q: What does update all do? -A: It updates the dol (the loader itself), the icon.png and meta.xml for HBC, the language files and wiitdb.zip - -Q: Can I update the full channel? -A: Yes. If you have the channel version installed, there will be no update all function. If you do see this button, the channel is not correctly modified (see [2a]) so you can’t update it (also check the rev# in the credits, it should end with the letter c). In that case get another channel. - - -Q: Where can I see my rev# ? -A: Go to the Credits. The rev# will be at the top right corner. If it ends with c you are using the full channel. - - -Q: Can I use this loader in my own language? -A: This loader currently supports: Chinese (simple and trad.), Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Russian, Spanish, Swedish, Thai and Turkish. -All languages are frequently updated by the GX language teams (I'm the Dutch translator). You can find us at http://gbatemp.net/index.php?showtopic=155252 - - -Q: I have a problem and the answer is not in this readmii. What do I do? -A: You can always ask questions at the GX forum: http://forum.koureio.net/ .You can find me (tj_cool) and the GX team there as well. \ No newline at end of file diff --git a/Languages/czech.lang b/Languages/czech.lang deleted file mode 100644 index 14f3cec0..00000000 --- a/Languages/czech.lang +++ /dev/null @@ -1,1483 +0,0 @@ -# USB Loader GX language source file. -# czech.lang - r828 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: David Jelinek (djelinek@hotmail.com) \n" -"Language-Team: r823 - last version on http://djelinek.sweb.cz/_USBLoderGX/czech.lang \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " WAD uložen jako:" - -msgid " could not be downloaded." -msgstr " nelze stáhnout." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " byl uložen. Soubor nebyl zkontrolován. Nekteré cásti kódu nemusí fungovat s ostaními. Pokud dojde k problémum, overte text v editoru." - -msgid " is not on the server." -msgstr " není na serveru" - -msgid "2D Cover Path" -msgstr "Cesta k 2D obalum" - -msgid "3D Cover Path" -msgstr "Cesta k 3D obalum" - -msgid "3D Covers" -msgstr "3D Obaly" - -msgid ">> Deleting tickets..." -msgstr ">> Odstraňuji tikety..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Odstraňuji tikety...CHYBA! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Odstraňuji tikety...Ok! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Odstraňuji titul...CHYBA! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Odstraňuji titul...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Odstraňuji obsah titulu..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Odstraňuji obsah titulu...CHYBA! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Odstraňuji obsah titulu...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Odstraňuji titul..." - -msgid ">> Finishing installation..." -msgstr ">> Ukoncuji instalaci..." - -msgid ">> Installing content #" -msgstr ">> Instaluji obsah #" - -msgid ">> Installing ticket..." -msgstr ">> Instaluji tiket..." - -msgid ">> Installing title..." -msgstr ">> Instaluji titul..." - -msgid ">> Reading WAD data..." -msgstr ">> Nacítám WAD data..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Nacítám WAD data...CHYBA! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Nacítám WAD data...Ok! " - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Všechny možnosti USB Loader GX jsou odemceny" - -msgid "Alternate DOL" -msgstr "Náhradní DOL" - -msgid "App Language" -msgstr "Jazyk aplikace" - -msgid "Apr" -msgstr "Dub" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Jste si jisti?" - -msgid "Aug" -msgstr "Srp" - -msgid "Author:" -msgstr "Autor:" - -msgid "AutoInit Network" -msgstr "Automatický start síte" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "Zpet" - -msgid "Back to HBC or Wii Menu" -msgstr "Zpet do HBC nebo Wii nabídky" - -msgid "Back to Loader" -msgstr "Zpet do spouštece" - -msgid "Backgroundmusic" -msgstr "Hudba na pozadí" - -msgid "Big thanks to:" -msgstr "Velké díky pro:" - -msgid "Block IOS Reload" -msgstr "Blokovat opetovné zavedení IOS" - -msgid "Boot/Standard" -msgstr "" - -msgid "Boot?" -msgstr "Spustit?" - -msgid "Can't be formatted" -msgstr "Nelze naformátovat" - -msgid "Can't create directory" -msgstr "Nelze vytvorit adresár" - -msgid "Can't create file" -msgstr "Nelze vytvořit soubor" - -msgid "Can't delete:" -msgstr "Nelze smazat:" - -msgid "Cancel" -msgstr "Zrušit" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "Soubor s cheaty je prázdný" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Kliknete pro stažení obalu" - -msgid "Click to change game ID" -msgstr "Kliknete pro zmenu ID hry" - -msgid "Clock" -msgstr "Hodiny" - -msgid "Close" -msgstr "zavrít" - -msgid "Code Download" -msgstr "Stažení kódu" - -#, c-format -msgid "Coded by: %s" -msgstr "Naprogramoval: %s" - -msgid "Coding:" -msgstr "Programování:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "Konzole" - -msgid "Console Locked" -msgstr "Konzole uzamcena" - -msgid "Console should be unlocked to modify it." -msgstr "Konzole musí být odemcena pro tuto zmenu" - -msgid "Continue to install game?" -msgstr "Pokracovat pri instalaci hry" - -msgid "Controllevel" -msgstr "Úroven rízení" - -msgid "Correct Password" -msgstr "Správné heslo" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Nelze vytvorit GCT soubor" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Nelze inicializovat DIP modul!" - -msgid "Could not initialize network!" -msgstr "Nelze inicializovat sítové pripojení" - -msgid "Could not open Disc" -msgstr "Nelze otevrít disk" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Nelze uložit." - -msgid "Cover Download" -msgstr "Stažení obalu" - -msgid "Create" -msgstr "Vytvorit" - -msgid "Credits" -msgstr "Zásluhy" - -msgid "Custom Paths" -msgstr "Vlastní cesty" - -msgid "DOL Path" -msgstr "Cesta k DOL" - -msgid "Dec" -msgstr "List" - -msgid "Default" -msgstr "Puvodní" - -msgid "Default Gamesettings" -msgstr "Puvodní nastavení her" - -msgid "Default Settings" -msgstr "Puvodní nastavení" - -msgid "Delete" -msgstr "Smazat" - -msgid "Delete ?" -msgstr "Smazat?" - -msgid "Delete Cheat GCT" -msgstr "Smazat Cheat GCT" - -msgid "Delete Cheat TXT" -msgstr "Smazat Cheat TXT" - -msgid "Delete Cover Artwork" -msgstr "Smazat obal krabicky" - -msgid "Delete Disc Artwork" -msgstr "Smazat potisk DVD" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "Vyvinul" - -msgid "Directory does not exist!" -msgstr "Adresár neexistuje!" - -msgid "Disc Artwork Download" -msgstr "Stažení potisku DVD" - -msgid "Disc Artwork Path" -msgstr "Cesta k potiskum DVD" - -msgid "Disc Images" -msgstr "Potisky DVD" - -msgid "Display" -msgstr "Zobrazení" - -msgid "Display as a carousel" -msgstr "Zobrazit jako karusel" - -msgid "Display as a grid" -msgstr "Zobrazit do mrížky" - -msgid "Display as a list" -msgstr "Zobrait jako seznam" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Opravdu smazat:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "Prejete si zmenit jazyk?" - -msgid "Do you want to download this theme?" -msgstr "Prejete si stáhnout toto téma?" - -msgid "Do you want to format:" -msgstr "Prejete si formátovat" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Prejete si použít jiný DOL, který je správný?" - -msgid "Do you wish to update/download all language files?" -msgstr "Prejete si zaktualizovat vsechny jazykové soubory?" - -msgid "Done!" -msgstr "Hotovo!" - -msgid "Download" -msgstr "Stažení" - -msgid "Download Boxart image?" -msgstr "Stáhnout obal krabicky?" - -msgid "Download Discart image?" -msgstr "Stáhnout potisk DVD?" - -msgid "Download Now" -msgstr "Stáhnout nyní" - -msgid "Download failed." -msgstr "Stažení selhalo." - -msgid "Download finished" -msgstr "Stažení dokonceno" - -msgid "Download request failed." -msgstr "Požadavek na stažení selhal." - -msgid "Downloading Page List:" -msgstr "Stahuji stránku seznamu:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Stahuji soubor" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Stahuji obrázek:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "CHYBA" - -msgid "ERROR:" -msgstr "CHYBA:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "Chyba" - -msgid "Error !" -msgstr "Chyba !" - -msgid "Error 002 fix" -msgstr "Oprava chyby 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Nelze císt disk" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Chyba behem prenosu dat." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Chyba..." - -msgid "Error:" -msgstr "Chyba:" - -msgid "Extracting files..." -msgstr "Rozbaluji soubory..." - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "Neúspešné formátování" - -msgid "Failed to extract." -msgstr "Nemohu rozbalit." - -msgid "Failed to open partition" -msgstr "Nelze otevrít diskový oddíl" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Ún" - -msgid "File not found." -msgstr "Soubor nenalezen" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Ukoncuji instalaci... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "" - -msgid "Format" -msgstr "Formát" - -msgid "Formatting, please wait..." -msgstr "Formátuji, cekejte prosím ..." - -msgid "Free Space" -msgstr "Volné místo" - -msgid "Full Shutdown" -msgstr "Úplné vypnutí" - -msgid "GCT Cheatcodes Path" -msgstr "Cesta pro cheat kódy" - -msgid "GCT File created" -msgstr "Soubor GCT vytvoren" - -msgid "GUI Settings" -msgstr "Nastavení GUI" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Jazyk hry" - -msgid "Game Load" -msgstr "Nahrání hry" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Velikost hry" - -msgid "Game Sound Mode" -msgstr "Zvukový mód hry" - -msgid "Game Sound Volume" -msgstr "Nastavení hlasitosti hry" - -msgid "Game is already installed:" -msgstr "Hra je již nainstalována:" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "Hry" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Hlavní menu" - -msgid "Homebrew Apps Path" -msgstr "Cesta pro Homebrew aplikace" - -msgid "Homebrew Launcher" -msgstr "Spouštec Homebrew" - -msgid "Hour" -msgstr "Hodina" - -msgid "How do you want to update?" -msgstr "Jak si prejete provést aktualizaci?" - -msgid "How to Shutdown?" -msgstr "Jakým zpusobem ukoncit?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Príchozí soubor %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Príchozí soubor %0.2fMB" - -msgid "Initializing Network" -msgstr "Inicializuji sítové pripojení" - -msgid "Insert Disk" -msgstr "Vložte disk" - -msgid "Insert a Wii Disc!" -msgstr "Vložte Wii disk" - -msgid "Insert an SD-Card to save." -msgstr "Vložte SD kartu pro uložení." - -msgid "Insert an SD-Card to use this option." -msgstr "Vložte SD kartu pro tuto možnost" - -msgid "Install" -msgstr "Instalace" - -msgid "Install Error!" -msgstr "Chyba pri instalaci" - -msgid "Install a game" -msgstr "Nainstalovat hru" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "Instaluji obsah... Ok!" - -msgid "Installing game:" -msgstr "Instalace hry:" - -msgid "Installing ticket... Ok!" -msgstr "Instaluji tiket... Ok!" - -msgid "Installing title... Ok!" -msgstr "Instaluji titul... Ok!" - -msgid "Installing wad" -msgstr "Instaluji WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Zdá se, že máte informace, které by pro nás mohly být užitecné. Odešlete prosím tuto informaci na náš DEV tým." - -msgid "Jan" -msgstr "Led" - -msgid "July" -msgstr "Cervenec" - -msgid "June" -msgstr "Cerven" - -msgid "Keep" -msgstr "Držet" - -msgid "Keyboard" -msgstr "Klávesnice" - -msgid "Language File" -msgstr "Jazykový soubor" - -msgid "Language change:" -msgstr "Zmena jazyka:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Cesta k jazykum zmenena" - -msgid "Load" -msgstr "Spustit" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Nahrát soubor z: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Spustit tento DOL jako náhradní DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Nahrávám puvodní jazyk" - -msgid "Loading standard music." -msgstr "Nahrávám puvodní hudbu" - -msgid "Lock Console" -msgstr "Zamcení konzole" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "Brez" - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "Kvet" - -msgid "Missing files" -msgstr "Chybející soubory" - -msgid "Mount DVD drive" -msgstr "Pripojit DVD mechaniku" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Hlasitost hudby" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Detekován nový disk" - -msgid "No" -msgstr "Ne" - -msgid "No Cheatfile found" -msgstr "Nebyl nalezen soubor s cheaty" - -msgid "No DOL file found on disc." -msgstr "Na disku nebyl nalezen DOL soubor." - -msgid "No SD-Card inserted!" -msgstr "Není vložena SD karta" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Nebyly vybrány žádné cheaty" - -msgid "No data could be read." -msgstr "Nelze císt data?" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Nechybí žádný soubor!" - -msgid "No new updates." -msgstr "Není dostupná žádná aktualizace." - -msgid "No themes found on the site." -msgstr "Žádné téma nebylo nalezeno na serveru." - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Toto není Wii disk" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Není dostatek volné pameti." - -msgid "Not enough free space!" -msgstr "Není dostatek volného místa!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Nepodporovaný formát!" - -msgid "Nov" -msgstr "List" - -msgid "OFF" -msgstr "Vypnuto" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Ríj" - -msgid "Official Site:" -msgstr "Oficiální místo:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Rodicovský zámek" - -msgid "Partition" -msgstr "Oddíl" - -msgid "Password" -msgstr "Heslo" - -msgid "Password Changed" -msgstr "Heslo zmeneno" - -msgid "Password has been changed" -msgstr "Heslo bylo zmeneno" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Napište toto URL do prohlížece pro stažení WiiTDB.zip." - -msgid "Patch Country Strings" -msgstr "Úprava nastvení zeme" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Vyberte ze seznamu" - -msgid "Play Count" -msgstr "Spušteno" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "Cekejte prosím..." - -msgid "Power off the Wii" -msgstr "Vypnout Wii" - -msgid "Prompts Buttons" -msgstr "Potvrzovací tlacítka" - -msgid "Published by" -msgstr "Publikoval " - -msgid "Quick Boot" -msgstr "Rychlé zavedení" - -msgid "Reading WAD data... Ok!" -msgstr "Nacítám WAD data... Ok!" - -msgid "Receiving file from:" -msgstr "Prijímám soubor z:" - -msgid "Released" -msgstr "Uvolnil" - -msgid "Reload SD" -msgstr "Znovunactení SD" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "Prejmenovat hru na WBFS" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Vynulovat cítac spuštení" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Restartuji..." - -msgid "Return" -msgstr "Návrat" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Návrat do Wii nabídky" - -msgid "Rumble" -msgstr "Vibrace" - -msgid "SFX Volume" -msgstr "Hlasitost SFX" - -msgid "Save" -msgstr "Uložit" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Uložit seznam her do" - -msgid "Saved" -msgstr "Uloženo" - -msgid "Screensaver" -msgstr "Sporic obrazovky" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Vyberte DOL" - -msgid "Sept" -msgstr "Zárí" - -msgid "Set Search-Filter" -msgstr "Nastavit vyhledávací filtr" - -msgid "Settings" -msgstr "Nastavení" - -msgid "Shutdown System" -msgstr "Ukoncit systém" - -msgid "Shutdown to Idle" -msgstr "Pauza" - -msgid "Sort alphabetically" -msgstr "Trídení dle abecedy" - -msgid "Sort by rank" -msgstr "Trídit podle hodnocení" - -msgid "Sort order by most played" -msgstr "Trídení podle spuštení" - -msgid "Sound" -msgstr "Zvuk" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Speciální podekování pro" - -msgid "Success" -msgstr "Úspešne" - -msgid "Success:" -msgstr "Úspešne:" - -msgid "Successfully Saved" -msgstr "Úspešne uloženo" - -msgid "Successfully Updated" -msgstr "Úspešne zaktualizováno" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Úspešne smazáno:" - -msgid "Successfully extracted theme." -msgstr "Úspešne rozbalené téma." - -msgid "Successfully installed:" -msgstr "Úspešne nainstalováno" - -msgid "TXT Cheatcodes Path" -msgstr "Cesta k TXT cheatum" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Zadaný adresár neexistuje. Chcete ho vytvorit?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Cesta pro uložení témat" - -msgid "Theme Downloader" -msgstr "Stahování témat" - -msgid "Theme Path" -msgstr "Cesta k tématum" - -msgid "Theme Title:" -msgstr "Název tématu" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Zbývající cas:" - -msgid "Title Launcher" -msgstr "Spouštec kanálu" - -msgid "Titles from WiiTDB" -msgstr "Názvy z WiiTDB" - -msgid "Tooltips" -msgstr "Popisky" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Prenos selhal" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB zarízení nenalezeno" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX je zabezpecen" - -msgid "Uninstall" -msgstr "Odinstalace" - -msgid "Uninstall Game" -msgstr "Odinstalace hry" - -msgid "Uninstall Menu" -msgstr "Menu odinstalací" - -msgid "Uninstalling wad" -msgstr "Odinstalace WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Odemknete konzoli pro tuto akci." - -msgid "Unsupported format, try to extract manually." -msgstr "Nepodporovaný formát" - -msgid "Update" -msgstr "Aktualizace" - -msgid "Update All" -msgstr "Plná aktualizace" - -msgid "Update DOL" -msgstr "Aktualizace DOL" - -msgid "Update Files" -msgstr "Zaktualizuj soubory" - -msgid "Update Path" -msgstr "Cesta pro aktualizaci" - -msgid "Update all Language Files" -msgstr "Zaktualizuj vsechny jazykové soubory" - -msgid "Update failed" -msgstr "Aktualizace selhala" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Aktualizuji jazykové soubory:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Odeslaný ZIP soubor nainstalován do adresáre homebrew" - -msgid "VIDTV Patch" -msgstr "VIDTV korekce" - -#, c-format -msgid "Version: %s" -msgstr "Verze: %s" - -msgid "Video Mode" -msgstr "Video mód" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "Cekám na zarízení USB" - -msgid "Waiting..." -msgstr "Cekám..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Co si prejete zaktualizovat?" - -msgid "WiFi Features" -msgstr "WiFi možnosti" - -msgid "Wii Menu" -msgstr "Wii menu" - -msgid "Wii Settings" -msgstr "Nastavení Wii" - -msgid "WiiTDB Files" -msgstr "WiiTDB Soubory" - -msgid "WiiTDB Path" -msgstr "Cesta k WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Wii svetlo" - -msgid "Wrong Password" -msgstr "Špatné heslo" - -msgid "Yes" -msgstr "Ano" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Vaše URL bylo uloženo v %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "a prekladatele pro aktualizaci jazykových souborů" - -msgid "available" -msgstr "dostupný" - -msgid "does not exist!" -msgstr "neexistuje!" - -msgid "does not exist! Loading game without cheats." -msgstr "neexistuje. Nahrávání hry bez cheatu." - -msgid "files left" -msgstr "souboru zbývá" - -msgid "files not found on the server!" -msgstr "souboru nenalezeno na serveru" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "za Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "za WiiTDB a hostování obalu / potisku DVD" - -msgid "for diverse patches" -msgstr "za ruzné opravy" - -msgid "for his awesome tool LibWiiGui" -msgstr "za jeho hrozný nástroj LibWiiGui" - -msgid "for hosting the themes" -msgstr "pro hostování témat" - -msgid "for hosting the update files" -msgstr "za umístení souboru pro aktualizaci " - -msgid "for the USB Loader source" -msgstr "za zdrojový kód pro USB Loader" - -msgid "formatted!" -msgstr "formátováno!" - -msgid "free" -msgstr "volné" - -msgid "not set" -msgstr "nenastaveno" - -msgid "of" -msgstr "z " - -msgid "seconds left" -msgstr "sekund zbývá" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Každý)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Díte 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 hodina" - -#~ msgid "10 min" -#~ msgstr "10 minut" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Mladistvý 12+)" - -#~ msgid "20 min" -#~ msgstr "20 minut" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Zralý 16+)" - -#~ msgid "3 min" -#~ msgstr "3 minuty" - -#~ msgid "30 min" -#~ msgstr "30 minut" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Pouze dospelí 18+)" - -#~ msgid "5 min" -#~ msgstr "5 minut" - -#~ msgid "An Error occured" -#~ msgstr "Došlo k chybe" - -#~ msgid "Both" -#~ msgstr "Oboje" - -#~ msgid "Checking for Updates" -#~ msgstr "Zjištuji dostupné aktualiazce" - -#~ msgid "Console Default" -#~ msgstr "Puvodní nastavení konzole" - -#~ msgid "Customs/Original" -#~ msgstr "Upravené/Originál" - -#~ msgid "Disc Default" -#~ msgstr "Puvodní nastavení disku" - -#~ msgid "Downloading" -#~ msgstr "Stahování" - -#~ msgid "Dutch" -#~ msgstr "Dánsky" - -#~ msgid "English" -#~ msgstr "Anglicky" - -#~ msgid "French" -#~ msgstr "Francouzky" - -#~ msgid "Game ID" -#~ msgstr "ID hry" - -#~ msgid "Game Region" -#~ msgstr "Region hry" - -#~ msgid "German" -#~ msgstr "Nemecky" - -#~ msgid "Italian" -#~ msgstr "Italsky" - -#~ msgid "Japanese" -#~ msgstr "Japonsky" - -#~ msgid "Korean" -#~ msgstr "Korejsky" - -#~ msgid "Left" -#~ msgstr "Vlevo" - -#~ msgid "Like SysMenu" -#~ msgstr "Jako hlavní menu" - -#~ msgid "Load From SD/USB" -#~ msgstr "Nahrát z SD/USB" - -#~ msgid "Locked" -#~ msgstr "Zamceno" - -#~ msgid "Loop Sound" -#~ msgstr "Zvuková smyčka" - -#~ msgid "Neither" -#~ msgstr "Žádný" - -#~ msgid "Next" -#~ msgstr "Další" - -#~ msgid "Normal" -#~ msgstr "Normální" - -#~ msgid "ON" -#~ msgstr "Zapnuto" - -#~ msgid "Only Customs" -#~ msgstr "Pouze Upravené" - -#~ msgid "Only Original" -#~ msgstr "Pouze originál" - -#~ msgid "Only for Install" -#~ msgstr "Pouze pro instalaci" - -#~ msgid "Original/Customs" -#~ msgstr "Originál/Upravené" - -#~ msgid "Prev" -#~ msgstr "Predchozí" - -#~ msgid "Right" -#~ msgstr "Vpravo" - -#~ msgid "SChinese" -#~ msgstr "Cínsky" - -#~ msgid "Sound+BGM" -#~ msgstr "Zvuk+BGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "Zvuk+ticho" - -#~ msgid "Spanish" -#~ msgstr "Španelsky" - -#~ msgid "System Default" -#~ msgstr "Puvodní nastavení systému" - -#~ msgid "TChinese" -#~ msgstr "Cínsky" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD soubor byl nainstalován, ale nelze smazat z SD karty" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Instalace WAD souboru selhala s chybou %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Nelze otevrít WAD, který byl nyní stažen (%s)." - -#~ msgid "Unlocked" -#~ msgstr "Odemceno" - -#~ msgid "Update to" -#~ msgstr "Aktualizováno na" - -#~ msgid "Updating" -#~ msgstr "Aktualizuji" - -#~ msgid "Updating Language Files..." -#~ msgstr "Aktualizuji jazykové soubory..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Aktualizuji WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Korekce širokoúhlé obrazovky" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Zpet do Wii nabídky" - -#~ msgid "Channels" -#~ msgstr "Kanály" - -#~ msgid "Checking existing artwork" -#~ msgstr "Kontroluji existující kresby" - -#~ msgid "Confirm" -#~ msgstr "Potvrdit" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Nemohu nalézt WBFS oddíl." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Nemohu otevrít WBFS oddíl." - -#~ msgid "Could not read the disc." -#~ msgstr "Nelze císt disk" - -#~ msgid "Could not set USB." -#~ msgstr "Nelze nastavit USB" - -#~ msgid "Cover Path Changed" -#~ msgstr "Cesta k obalum zmenena" - -#~ msgid "DOL path changed" -#~ msgstr "Cesta k DOL zmenena" - -#~ msgid "Disc Path Changed" -#~ msgstr "Cesta k diskum zmenena" - -#~ msgid "Display favorites" -#~ msgstr "Zobrazit oblíbené" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Chcete to zkusit znovu za 30 sekund?" - -#~ msgid "Force" -#~ msgstr "Síla" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Cesta pro cheat kódy zmenena" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Cesta pro Homebrew aplikace zmenena" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Vložte SD kartu pro stažení potisku DVD." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Nejspíše má velikost, která není delitelná 4." - -#~ msgid "Network init error" -#~ msgstr "Chyba pri inicializaci síte" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Nebyl nalezen .dol ani .elf soubor." - -#~ msgid "No Favorites" -#~ msgstr "Žádné oblíbené" - -#~ msgid "No USB Device" -#~ msgstr "Žádné zarízení USB" - -#~ msgid "No USB Device found." -#~ msgstr "Nebylo nalezeno zarízení USB" - -#~ msgid "Normal Covers" -#~ msgstr "Normální obaly" - -#~ msgid "Not Found" -#~ msgstr "Nenalezeno" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "To není DOL/ELF soubor." - -#~ msgid "Save Failed" -#~ msgstr "Uložení selhalo" - -#~ msgid "Selected DOL" -#~ msgstr "Vybraný DOL" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Cesta k TXT cheatum zmenena" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Cesta pro uložení témat zmenena" - -#~ msgid "Theme Path Changed" -#~ msgstr "Cesta k tématum zmenena" - -#~ msgid "Update Path changed." -#~ msgstr "Cesta pro aktualizaci zmenena" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Cesta k WiiTDB zmenena" - -#~ msgid "You are about to delete " -#~ msgstr "Pokoušíte se smazat " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Vybíráte zobrazení oblíbených, ale žádné jste dosud nevybral" - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Pokusili jste se nahrát špatný obraz" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "neexistuje. Neco jsi zvoral ty pako." - -#~ msgid "file left" -#~ msgstr "soubor zbývá" diff --git a/Languages/danish.lang b/Languages/danish.lang deleted file mode 100644 index 66573993..00000000 --- a/Languages/danish.lang +++ /dev/null @@ -1,1543 +0,0 @@ -# USB Loader GX language source file. -# danish.lang - r937 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: dorf[dk]\n" -"Language-Team: dorf[dk]\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " WAD gemt som:" - -msgid " could not be downloaded." -msgstr " kunne ikke downloades." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " er blevet gemt. Koderne er ikke blevet kontrolleret. Nogle af koderne virker måske ikke samtidigt. Hvis der er problemer, åbn da tekstfilen i en editor for at få mere information." - -msgid " is not on the server." -msgstr " er ikke på serveren." - -msgid "2D Cover Path" -msgstr "Sti til 2-d covers" - -msgid "3D Cover Path" -msgstr "Sti til 3-d covers" - -msgid "3D Covers" -msgstr "3D-Covers" - -msgid ">> Deleting tickets..." -msgstr ">> Sletter tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Sletter tickets...FEJL!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Sletter tickets...Ok!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Sletter titel...FEJL!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> Sletter titel...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Sletter titelindhold..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Sletter titelindhold...FEJL!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Sletter titelindhold...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Sletter titel..." - -msgid ">> Finishing installation..." -msgstr ">> Færdiggør installationen..." - -msgid ">> Installing content #" -msgstr ">> Installerer content #" - -msgid ">> Installing ticket..." -msgstr ">> Installerer ticket..." - -msgid ">> Installing title..." -msgstr ">> Installerer titel..." - -msgid ">> Reading WAD data..." -msgstr ">> Læser WAD-data" - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Læser WAD-data...FEJL!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Læser WAD-data...Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Alle partitioner" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Alle USB Loader GX's funktioner er låst op." - -msgid "Alternate DOL" -msgstr "Alternativ DOL" - -msgid "App Language" -msgstr "Programsprog" - -msgid "Apr" -msgstr "" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Er du sikker?" - -msgid "Aug" -msgstr "" - -msgid "Author:" -msgstr "Forfatter:" - -msgid "AutoInit Network" -msgstr "AutoInit net" - -msgid "BCA Codes Path" -msgstr "Sti til BCA koder" - -msgid "BETA revisions" -msgstr "BETA-versioner" - -msgid "Back" -msgstr "Tilbage" - -msgid "Back to HBC or Wii Menu" -msgstr "Tilbage til HBC eller Wii-menuen" - -msgid "Back to Loader" -msgstr "Tilbage til Loaderen" - -msgid "Backgroundmusic" -msgstr "Baggrundsmusik" - -msgid "Big thanks to:" -msgstr "En stor tak til:" - -msgid "Block IOS Reload" -msgstr "Blokér IOS-reload" - -msgid "Boot/Standard" -msgstr "" - -msgid "Boot?" -msgstr "Genstart?" - -msgid "Can't be formatted" -msgstr "Kan ikke formatteres" - -msgid "Can't create directory" -msgstr "Kan ikke lave ny mappe" - -msgid "Can't create file" -msgstr "Kan ikke oprette fil" - -msgid "Can't delete:" -msgstr "Kan ikke slettes:" - -msgid "Cancel" -msgstr "Annullér" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Ændre sti til musik" - -msgid "Cheatfile is blank" -msgstr "Cheatfilen er tom" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Klik for at downloade covers" - -msgid "Click to change game ID" -msgstr "Klik for at ændre spil-ID" - -msgid "Clock" -msgstr "Ur" - -msgid "Close" -msgstr "Luk" - -msgid "Code Download" -msgstr "Download af koder" - -#, c-format -msgid "Coded by: %s" -msgstr "Programmeret af: %s" - -msgid "Coding:" -msgstr "Programmering:" - -msgid "Connection lost..." -msgstr "Forbindelsen er væk..." - -msgid "Console" -msgstr "Konsol" - -msgid "Console Locked" -msgstr "Konsollen er låst" - -msgid "Console should be unlocked to modify it." -msgstr "Konsollen skal være låst op for ændre dette." - -msgid "Continue to install game?" -msgstr "Fortsæt med at installere spillet?" - -msgid "Controllevel" -msgstr "Kontrolniveau" - -msgid "Correct Password" -msgstr "Korrekt Password" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Kunne ikke oprette GCT-fil" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Kunne ikke initialisere DIP-modul!" - -msgid "Could not initialize network!" -msgstr "Kunne ikke initialisere netforbindelse!" - -msgid "Could not open Disc" -msgstr "Kunne ikke åbne DVD" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Kunne ikke gemme." - -msgid "Cover Download" -msgstr "Cover-download" - -msgid "Create" -msgstr "Opret" - -msgid "Credits" -msgstr "Lavet af:" - -msgid "Custom Paths" -msgstr "Sti-indstillinger" - -msgid "DOL Path" -msgstr "Stil til DOL" - -msgid "Dec" -msgstr "" - -msgid "Default" -msgstr "Standard" - -msgid "Default Gamesettings" -msgstr "Standard spil-indstillinger" - -msgid "Default Settings" -msgstr "Standardindstillinger" - -msgid "Delete" -msgstr "Slet" - -msgid "Delete ?" -msgstr "Slet?" - -msgid "Delete Cheat GCT" -msgstr "Slet cheat GCT" - -msgid "Delete Cheat TXT" -msgstr "Slet Cheat TXT" - -msgid "Delete Cover Artwork" -msgstr "Slet boxart" - -msgid "Delete Disc Artwork" -msgstr "Slet DVD-billede" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "Udviklet af" - -msgid "Directory does not exist!" -msgstr "Mappen eksisterer ikke!" - -msgid "Disc Artwork Download" -msgstr "Download DVD-billeder" - -msgid "Disc Artwork Path" -msgstr "Sti til DVD-billeder" - -msgid "Disc Images" -msgstr "DVD-billeder" - -msgid "Display" -msgstr "Spilinfo." - -msgid "Display as a carousel" -msgstr "Vis som karusel" - -msgid "Display as a grid" -msgstr "Vis som tabel" - -msgid "Display as a list" -msgstr "Vis som liste" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Vil du slette:" - -msgid "Do you want to apply it now?" -msgstr "Skal det aktiveres nu?" - -msgid "Do you want to change language?" -msgstr "Skal sproget ændres?" - -msgid "Do you want to download this theme?" -msgstr "Skal dette tema downloades?" - -msgid "Do you want to format:" -msgstr "Vil du formatere:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Skal den alternative DOL, der med sikkerhed er korrekt, bruges?" - -msgid "Do you wish to update/download all language files?" -msgstr "Skal alle sprogfiler opdateres/downloades?" - -msgid "Done!" -msgstr "Færdig!" - -msgid "Download" -msgstr "" - -msgid "Download Boxart image?" -msgstr "Download boxart-billede?" - -msgid "Download Discart image?" -msgstr "Download DVD-billede?" - -msgid "Download Now" -msgstr "Download nu" - -msgid "Download failed." -msgstr "Download mislykkedes." - -msgid "Download finished" -msgstr "Download færdig" - -msgid "Download request failed." -msgstr "Anmodning om download mislykkedes." - -msgid "Downloading Page List:" -msgstr "Downloader side:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Downloader fil" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Downloader billede:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "FEJL" - -msgid "ERROR:" -msgstr "FEJL:" - -msgid "ERROR: Can't set up theme." -msgstr "FEJL: Temaet kan ikke bruges." - -msgid "Error" -msgstr "Fejl" - -msgid "Error !" -msgstr "Fejl!" - -msgid "Error 002 fix" -msgstr "Error 002 fix" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "DVDen kunne ikke læses" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Fejl under overførsel af data." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Fejl..." - -msgid "Error:" -msgstr "Fejl:" - -msgid "Extracting files..." -msgstr "Pakker filer ud..." - -msgid "FAT: Use directories" -msgstr "FAT: Brug mapper" - -msgid "Failed formating" -msgstr "Formateringen mislykkedes" - -msgid "Failed to extract." -msgstr "Udpakningen mislykkedes." - -msgid "Failed to open partition" -msgstr "Kunne ikke åbne partition" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "Fil ikke fundet." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Afslutter installationen... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "" - -msgid "Format" -msgstr "Formater" - -msgid "Formatting, please wait..." -msgstr "Formaterer, vent venligst..." - -msgid "Free Space" -msgstr "Ledig plads" - -msgid "Full Shutdown" -msgstr "Sluk helt" - -msgid "GCT Cheatcodes Path" -msgstr "Sti til cheatcodes" - -msgid "GCT File created" -msgstr "GCT-fil oprettet" - -msgid "GUI Settings" -msgstr "Konfigurér GUI" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg blev ikke fundet i nogle undermapper" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Sprog" - -msgid "Game Load" -msgstr "Spilindstillinger" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Spilstørrelse" - -msgid "Game Sound Mode" -msgstr "Spillyd" - -msgid "Game Sound Volume" -msgstr "Spillyd lydstyrke" - -msgid "Game is already installed:" -msgstr "Dette spil er allerede installeret:" - -msgid "Game partition" -msgstr "Spilpartition" - -msgid "Games" -msgstr "Spil" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "" - -msgid "Homebrew Apps Path" -msgstr "Sti til homebrew-programmer" - -msgid "Homebrew Launcher" -msgstr "Homebrew-starter" - -msgid "Hour" -msgstr "timer" - -msgid "How do you want to update?" -msgstr "Hvordan skal der opdateres?" - -msgid "How to Shutdown?" -msgstr "Hvordan skal der slukkes?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Hvis der ikke er netforbindelse, tryk da på 1 for at få en URL til WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Henter fil %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Henter fil %0.2fMB" - -msgid "Initializing Network" -msgstr "Initialiserer netforbindelse" - -msgid "Insert Disk" -msgstr "Indsæt en DVD" - -msgid "Insert a Wii Disc!" -msgstr "Indsæt en Wii-DVD!" - -msgid "Insert an SD-Card to save." -msgstr "Indsæt et SD-kort for at gemme." - -msgid "Insert an SD-Card to use this option." -msgstr "Indsæt et SD-kort for at bruge denne indstilling." - -msgid "Install" -msgstr "Installér" - -msgid "Install Error!" -msgstr "Installationsfejl!" - -msgid "Install a game" -msgstr "Installér nyt spil" - -msgid "Install partitions" -msgstr "Installationspartitioner" - -msgid "Installing content... Ok!" -msgstr "Installerer indhold... Ok!" - -msgid "Installing game:" -msgstr "Installerer spillet:" - -msgid "Installing ticket... Ok!" -msgstr "Installerer ticket... Ok!" - -msgid "Installing title... Ok!" -msgstr "Installerer titel... Ok!" - -msgid "Installing wad" -msgstr "Installerer WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Det ser ud til, at du har information, der vil kunne hjælpe os. Vær rar at sende denne information til udviklerne." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Juli" - -msgid "June" -msgstr "Juni" - -msgid "Keep" -msgstr "Behold" - -msgid "Keyboard" -msgstr "Tastatur" - -msgid "Language File" -msgstr "Sprog Fil" - -msgid "Language change:" -msgstr "Skift sprog:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Sti til sprogfiler ændret." - -msgid "Load" -msgstr "Indlæs" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Indlæs fil fra %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Indlæs denne DOL som alternativ DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Indlæser standardsprog." - -msgid "Loading standard music." -msgstr "Indlæser standardmusik." - -msgid "Lock Console" -msgstr "Lås konsol" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "Makér nye spil" - -msgid "May" -msgstr "Maj" - -msgid "Missing files" -msgstr "Manglende filer" - -msgid "Mount DVD drive" -msgstr "Mount DVD-drev" - -msgid "Music Loop Mode" -msgstr "Musik i løkke" - -msgid "Music Volume" -msgstr "Lydstyrke" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Har opdaget ny DVD" - -msgid "No" -msgstr "Nej" - -msgid "No Cheatfile found" -msgstr "Cheat-fil ikke fundet" - -msgid "No DOL file found on disc." -msgstr "Der blev ikke fundet nogle DOL-filer på DVDen." - -msgid "No SD-Card inserted!" -msgstr "Intet SD-kort fundet!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Der blev ikke valgt nogle cheats" - -msgid "No data could be read." -msgstr "Data kunne ikke læses." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Ingen filer mangler!" - -msgid "No new updates." -msgstr "Ingen nye opdateringer." - -msgid "No themes found on the site." -msgstr "Der blev ikke fundet nogle temaer på denne site." - -msgid "Not a WAD file." -msgstr "Ikke en WAD-fil." - -msgid "Not a Wii Disc" -msgstr "Ikke en Wii-DVD" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Ikke nok fri hukommelse." - -msgid "Not enough free space!" -msgstr "Ikke nok ledig plads!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Ikke et understøttet format" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "Fra" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Okt" - -msgid "Official Site:" -msgstr "Officiel side:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Børnelås" - -msgid "Partition" -msgstr "Partition" - -msgid "Password" -msgstr "Password" - -msgid "Password Changed" -msgstr "Password ændret" - -msgid "Password has been changed" -msgstr "Passwordet er blevet ændret" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Brug den i en browser for at hente WiiTDB.zip." - -msgid "Patch Country Strings" -msgstr "Patch landeindstillinger" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Vælg fra en liste" - -msgid "Play Count" -msgstr "Spiltæller" - -msgid "Play Next" -msgstr "Afspil næste" - -msgid "Play Previous" -msgstr "Afspil forrige" - -msgid "Playing Music:" -msgstr "Afspiller musik:" - -msgid "Please wait..." -msgstr "Vent venligst..." - -msgid "Power off the Wii" -msgstr "Sluk Wiien" - -msgid "Prompts Buttons" -msgstr "Knaptekster" - -msgid "Published by" -msgstr "Udgivet af" - -msgid "Quick Boot" -msgstr "Hurtig opstart" - -msgid "Reading WAD data... Ok!" -msgstr "Læser WAD-data... Ok!" - -msgid "Receiving file from:" -msgstr "Henter fil fra:" - -msgid "Released" -msgstr "Udkommet" - -msgid "Reload SD" -msgstr "Genindlæs SD" - -msgid "Remove update" -msgstr "Fjern opdatering" - -msgid "Rename Game on WBFS" -msgstr "Omdøb spil på WBFS" - -msgid "Reset BG Music" -msgstr "Nulstil BG-musik" - -msgid "Reset Playcounter" -msgstr "Nulstil spiltæller" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Genstarter..." - -msgid "Return" -msgstr "Tilbage" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Tilbage til Wii-menuen" - -msgid "Rumble" -msgstr "Vibration" - -msgid "SFX Volume" -msgstr "Lydstyrke for effekter" - -msgid "Save" -msgstr "Gem" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Gem spilliste på" - -msgid "Saved" -msgstr "Gemt" - -msgid "Screensaver" -msgstr "Screensaver" - -msgid "Select" -msgstr "Vælg" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Vælg en DOL" - -msgid "Sept" -msgstr "" - -msgid "Set Search-Filter" -msgstr "Søgefilter" - -msgid "Settings" -msgstr "Indstillinger" - -msgid "Shutdown System" -msgstr "Sluk (rødt lys)" - -msgid "Shutdown to Idle" -msgstr "Standby" - -msgid "Sort alphabetically" -msgstr "Sortér alfabetisk" - -msgid "Sort by rank" -msgstr "Sortér efter favoritstatus" - -msgid "Sort order by most played" -msgstr "Sortér efter popularitet" - -msgid "Sound" -msgstr "Lyd" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Specielt tak til:" - -msgid "Success" -msgstr "Succes" - -msgid "Success:" -msgstr "Succes:" - -msgid "Successfully Saved" -msgstr "Gem lykkedes" - -msgid "Successfully Updated" -msgstr "Opdateringen lykkedes" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Opdateringen lykkedes takket været www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Sletningen lykkedes:" - -msgid "Successfully extracted theme." -msgstr "Udpakning af tema lykkedes." - -msgid "Successfully installed:" -msgstr "Installationen lykkedes:" - -msgid "TXT Cheatcodes Path" -msgstr "Sti til TXTCheatcodes" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Den angivne mappe eksisterer ikke. Skal den oprettes?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Sti til download af temaer" - -msgid "Theme Downloader" -msgstr "Tema-downloader" - -msgid "Theme Path" -msgstr "Sti til temaer" - -msgid "Theme Title:" -msgstr "Tematitel:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Tid tilbage:" - -msgid "Title Launcher" -msgstr "Titel-starter" - -msgid "Titles from WiiTDB" -msgstr "Titler fra WiiTDB" - -msgid "Tooltips" -msgstr "Værktøjstips" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Overførslen mislykkedes" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB-enhed ikke fundet" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX er beskyttet" - -msgid "Uninstall" -msgstr "Afinstallér" - -msgid "Uninstall Game" -msgstr "Afinstallér spil" - -msgid "Uninstall Menu" -msgstr "Afinstallationsmenu" - -msgid "Uninstalling wad" -msgstr "Afinstallerer WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Lås op for konsollen for at benytte denne indstilling." - -msgid "Unsupported format, try to extract manually." -msgstr "Formatet er ikke understøttet - prøv at udpakke manuelt." - -msgid "Update" -msgstr "Opdatér" - -msgid "Update All" -msgstr "Opdatér alt" - -msgid "Update DOL" -msgstr "Opdatér DOL" - -msgid "Update Files" -msgstr "Opdatér filer" - -msgid "Update Path" -msgstr "Sti til opdateringer" - -msgid "Update all Language Files" -msgstr "Opdatér alle sprogfiler" - -msgid "Update failed" -msgstr "Opdateringen mislykkedes" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Opdaterer sprogfiler:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Den uploadede ZIP-fil er installeret i homebrew-mappen." - -msgid "VIDTV Patch" -msgstr "VIDTV-patch" - -#, c-format -msgid "Version: %s" -msgstr "" - -msgid "Video Mode" -msgstr "Video-mode" - -msgid "WIP Patches Path" -msgstr "Sti til WIP patches" - -msgid "Waiting for USB Device" -msgstr "Venter på USB-enhed" - -msgid "Waiting..." -msgstr "Venter..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Hvad skal opdateres?" - -msgid "WiFi Features" -msgstr "WiFi-indstillinger" - -msgid "Wii Menu" -msgstr "" - -msgid "Wii Settings" -msgstr "Wii-indstillinger" - -msgid "WiiTDB Files" -msgstr "WiiTDB-filer" - -msgid "WiiTDB Path" -msgstr "Sti til WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "" - -msgid "Wrong Password" -msgstr "Forkert password" - -msgid "Yes" -msgstr "Ja" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Du skal vælge eller formattere en partition" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "URLen er blevet gemt som %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "og oversætterne for opdateringer til sprogfilerne" - -msgid "available" -msgstr "tilgængelig" - -msgid "does not exist!" -msgstr "eksisterer ikke!" - -msgid "does not exist! Loading game without cheats." -msgstr "eksisterer ikke! Indlæser spillet uden cheats." - -msgid "files left" -msgstr "filer tilbage" - -msgid "files not found on the server!" -msgstr "filer blev ikke fundet på serveren!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "for WiiTDB og for at hoste covers/DVD-billeder" - -msgid "for diverse patches" -msgstr "for diverse patches" - -msgid "for his awesome tool LibWiiGui" -msgstr "for hans seje værktøj LibWiiGui" - -msgid "for hosting the themes" -msgstr "for at hoste temaerne" - -msgid "for hosting the update files" -msgstr "for at hoste opdateringer" - -msgid "for the USB Loader source" -msgstr "for USB Loader sourcen" - -msgid "formatted!" -msgstr "formateret!" - -msgid "free" -msgstr "ledig" - -msgid "not set" -msgstr "ikke sat" - -msgid "of" -msgstr "af" - -msgid "seconds left" -msgstr "sekunder tilbage" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Installér 1:1-kopi" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Alle)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Børn 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 time" - -#~ msgid "10 min" -#~ msgstr "10 min." - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Unge teenagere 12+)" - -#~ msgid "20 min" -#~ msgstr "20 min." - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Modne teenagere 16+)" - -#~ msgid "3 min" -#~ msgstr "3 min." - -#~ msgid "30 min" -#~ msgstr "30 min." - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Voksne 18+)" - -#~ msgid "5 min" -#~ msgstr "5 min." - -#~ msgid "An Error occured" -#~ msgstr "Der skete en fejl" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Skal børnelåsen slås til?" - -#~ msgid "Both" -#~ msgstr "Begge" - -#~ msgid "Checking for Updates" -#~ msgstr "Leder efter opdateringer" - -#~ msgid "Console Default" -#~ msgstr "Konsol-standard" - -#~ msgid "Customs/Original" -#~ msgstr "Tilpassede/Originale" - -#~ msgid "Disc Default" -#~ msgstr "Spillets standard" - -#~ msgid "Downloading" -#~ msgstr "Downloader" - -#~ msgid "Dutch" -#~ msgstr "Hollandsk" - -#~ msgid "English" -#~ msgstr "Engelsk" - -#~ msgid "French" -#~ msgstr "Fransk" - -#~ msgid "Game ID" -#~ msgstr "Spil-ID" - -#~ msgid "Game Region" -#~ msgstr "Region" - -#~ msgid "German" -#~ msgstr "Tysk" - -#~ msgid "Invalid PIN code" -#~ msgstr "Forkert PIN-kode" - -#~ msgid "Italian" -#~ msgstr "Italiensk" - -#~ msgid "Japanese" -#~ msgstr "Japansk" - -#~ msgid "Korean" -#~ msgstr "Koreansk" - -#~ msgid "Left" -#~ msgstr "Venstre" - -#~ msgid "Like SysMenu" -#~ msgstr "Ligesom wii-menuen" - -#~ msgid "Load From SD/USB" -#~ msgstr "Indlæs fra SD/USB" - -#~ msgid "Locked" -#~ msgstr "Låst" - -#~ msgid "Loop Directory" -#~ msgstr "Afspil mappe i løkke" - -#~ msgid "Loop Music" -#~ msgstr "Afspil musik i løkke" - -#~ msgid "Loop Sound" -#~ msgstr "Afspil lyd i løkke" - -#~ msgid "Neither" -#~ msgstr "Ingen" - -#~ msgid "Next" -#~ msgstr "Næste" - -#~ msgid "None" -#~ msgstr "Ingen" - -#~ msgid "Normal" -#~ msgstr "Normal" - -#~ msgid "ON" -#~ msgstr "Til" - -#~ msgid "Only Customs" -#~ msgstr "Kun tilpassede" - -#~ msgid "Only Original" -#~ msgstr "Kun originaler" - -#~ msgid "Only for Install" -#~ msgstr "Kun til installering" - -#~ msgid "Original/Customs" -#~ msgstr "Originale/Tilpassede" - -#~ msgid "Parental Control disabled" -#~ msgstr "Børnelåsen er slået fra" - -#~ msgid "Play Once" -#~ msgstr "Afspil én gang" - -#~ msgid "Prev" -#~ msgstr "Forrige" - -#~ msgid "Random Directory Music" -#~ msgstr "Musik fra tilfældig mappe" - -#~ msgid "Right" -#~ msgstr "Højre" - -#~ msgid "SChinese" -#~ msgstr "Kinesisk (std.)" - -#~ msgid "Sound+BGM" -#~ msgstr "Lyd+BGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "Lyd+Stille" - -#~ msgid "Spanish" -#~ msgstr "Spansk" - -#~ msgid "System Default" -#~ msgstr "System-standard" - -#~ msgid "TChinese" -#~ msgstr "Kinesisk (trad.)" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD-filen blev installeret. Den kunne ikke slettes fra SD-kortet." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "WAD-installationen mislykkedes med fejl %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Ikke i stand til at åbne den WAD, der blev downloadet (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Lås børnelåsen op" - -#~ msgid "Unlocked" -#~ msgstr "Låst op" - -#~ msgid "Update to" -#~ msgstr "Opdatér til" - -#~ msgid "Updating" -#~ msgstr "Opdaterer..." - -#~ msgid "Updating Language Files..." -#~ msgstr "Opdaterer sprogfiler..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Opdaterer WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Bredformat-fix" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Børnelåsen er ikke slået til. Hvis børnelåsen skal bruges, skal den slås til i Wiiens indstillinger." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s booter måske ikke korrekt, hvis system menuen ikke er opdateret." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Sti til BCA koder ændret" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Tilbage til HBC" - -#~ msgid "Channels" -#~ msgstr "Kanaler" - -#~ msgid "Checking existing artwork" -#~ msgstr "Kontrollerer eksisterende billeder" - -#~ msgid "Confirm" -#~ msgstr "Bekræft" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Kunne ikke finde en WBFS-partition." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Kunne ikke åbne WBFS-partition" - -#~ msgid "Could not read the disc." -#~ msgstr "Kunne ikke læse DVD." - -#~ msgid "Could not set USB." -#~ msgstr "Kunne ikke sætte USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "Sti til covers ændret" - -#~ msgid "DOL path changed" -#~ msgstr "Sti til DOL ændret" - -#~ msgid "Disc Path Changed" -#~ msgstr "Sti til DVD-billeder" - -#~ msgid "Display favorites" -#~ msgstr "Vis favoritter" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Forsøg igen (i 30 sek.)?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Slå børnelåsen til" - -#~ msgid "Force" -#~ msgstr "Tving" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Sti til cheatcodes ændret" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Sti til homebrew-programmer ændret" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Indsæt et SD-kort for at downloade billeder." - -#~ msgid "Install not possible" -#~ msgstr "Kan ikke installere" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Sandsynligvis har det dimensioner, der ikke er delelige med fire." - -#~ msgid "Network init error" -#~ msgstr "Netforbindelsen kunne ikke intialiseres" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Der blev ikke fundet nogle .dol- eller .elf-filer." - -#~ msgid "No Favorites" -#~ msgstr "Ingen favoritter" - -#~ msgid "No USB Device" -#~ msgstr "Ingen USB-enhed tilsluttet" - -#~ msgid "No USB Device found." -#~ msgstr "Ingen USB-enhed fundet." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Der blev ikke fundet en WBFS- eller FAT/NTFS-partition" - -#~ msgid "Normal Covers" -#~ msgstr "Normale Covers" - -#~ msgid "Not Found" -#~ msgstr "Ikke fundet" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Ikke en DOL/ELF-fil." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Nulstil til standard-BGM" - -#~ msgid "Save Failed" -#~ msgstr "Gem mislykkedes" - -#~ msgid "Selected DOL" -#~ msgstr "Valgt DOL" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Sti til TXTCheatcodes ændret" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Sti til download af temaer ændret" - -#~ msgid "Theme Path Changed" -#~ msgstr "Sti til temaer ændret" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX fungerer kun med Hermes CIOS rev 4! Kontrollér, at revision 4 er installeret!" - -#~ msgid "Update Path changed." -#~ msgstr "Sti til opdateringer ændret." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Sti til WIP patches ændret" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Sti til WiiTDB ændret" - -#~ msgid "You are about to delete " -#~ msgstr "Du er ved at slette " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Du har valgt at vise favoritter, men ingen spil er markerede som favoritter." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Der bruges et NTFS filsystem. Da der kan forekomme skrivefejl på NTFS-partitioner, kan der ikke installeres spil." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Du har forsøgt at indlæse et dårligt billede" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "eksisterer ikke!" - -#~ msgid "file left" -#~ msgstr "fil tilbage" diff --git a/Languages/dutch.lang b/Languages/dutch.lang deleted file mode 100644 index c4e8a304..00000000 --- a/Languages/dutch.lang +++ /dev/null @@ -1,1540 +0,0 @@ -# USB Loader GX language source file. -# dutch.lang - r929 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2010-04-12 07:37+0100\n" -"Last-Translator: glowy\n" -"Language-Team: tj_cool, glowy\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad opgeslagen als:" - -msgid " could not be downloaded." -msgstr " kon niet worden gedownload." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " is opgeslagen. De tekst is niet gecontroleerd. Delen van de code kunnen elkaar tegenwerken. Als je moeilijkheden ondervind, open de tekst in een echte tekstverwerker voor meer informatie." - -msgid " is not on the server." -msgstr " staat niet op de server." - -msgid "2D Cover Path" -msgstr "Locatie 2D hoesjes" - -msgid "3D Cover Path" -msgstr "Locatie 3D hoesjes" - -msgid "3D Covers" -msgstr "3D Hoesjes" - -msgid ">> Deleting tickets..." -msgstr ">> Tickets verwijderen..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Tickets verwijderen...FOUT! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Tickets verwijderen...Ok! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Titel verwijderen ...FOUT! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Titel verwijderen ...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Titel inhoud verwijderen..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Titel inhoud verwijderen...FOUT! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Titel inhoud verwijderen...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Titel verwijderen..." - -msgid ">> Finishing installation..." -msgstr ">> Installatie afronden..." - -msgid ">> Installing content #" -msgstr ">> Installeren inhoud #" - -msgid ">> Installing ticket..." -msgstr ">> Ticket installeren..." - -msgid ">> Installing title..." -msgstr ">> Titel installeren..." - -msgid ">> Reading WAD data..." -msgstr ">> WAD data lezen..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> WAD data lezen...FOUT! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> WAD data lezen...Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Alle partities" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Alle functies van USB Loader GX zijn vrijgegeven." - -msgid "Alternate DOL" -msgstr "Alternatieve DOL" - -msgid "App Language" -msgstr "Applicatie Taal" - -msgid "Apr" -msgstr "" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Zeker weten?" - -msgid "Aug" -msgstr "" - -msgid "Author:" -msgstr "Auteur:" - -msgid "AutoInit Network" -msgstr "Netwerk Auto init." - -msgid "BCA Codes Path" -msgstr "Locatie BCA codes" - -msgid "BETA revisions" -msgstr "BETA revisies" - -msgid "Back" -msgstr "Terug" - -msgid "Back to HBC or Wii Menu" -msgstr "Terug naar HBC of Wii Menu" - -msgid "Back to Loader" -msgstr "Terug naar lader" - -msgid "Backgroundmusic" -msgstr "Achtergrondmuziek" - -msgid "Big thanks to:" -msgstr "Grote dank aan:" - -msgid "Block IOS Reload" -msgstr "Stop IOS herladen" - -msgid "Boot/Standard" -msgstr "Start/Standaard" - -msgid "Boot?" -msgstr "Start?" - -msgid "Can't be formatted" -msgstr "Kan niet geformatteerd worden" - -msgid "Can't create directory" -msgstr "Kan map niet aanmaken" - -msgid "Can't create file" -msgstr "Kan bestand niet aanmaken" - -msgid "Can't delete:" -msgstr "Kan niet verwijderen:" - -msgid "Cancel" -msgstr "Annuleren" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Verander afspeel locatie" - -msgid "Cheatfile is blank" -msgstr "Cheatbestand is leeg" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Klik om hoesjes te downloaden" - -msgid "Click to change game ID" -msgstr "Klik om het spel ID te wijzigen" - -msgid "Clock" -msgstr "Klok" - -msgid "Close" -msgstr "Sluiten" - -msgid "Code Download" -msgstr "" - -#, c-format -msgid "Coded by: %s" -msgstr "Geprogrammeerd door: %s" - -msgid "Coding:" -msgstr "Codering:" - -msgid "Connection lost..." -msgstr "Verbinding verbroken..." - -msgid "Console" -msgstr "" - -msgid "Console Locked" -msgstr "Console vergrendeld" - -msgid "Console should be unlocked to modify it." -msgstr "Console moet worden vrijgegeven om te wijzigen." - -msgid "Continue to install game?" -msgstr "Installatie spel voortzetten?" - -msgid "Controllevel" -msgstr "Controle niveau" - -msgid "Correct Password" -msgstr "Juiste Wachtwoord" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Kan GCT bestand niet aanmaken" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Kan DIP module niet initialiseren!" - -msgid "Could not initialize network!" -msgstr "Kan netwerk niet initialiseren!" - -msgid "Could not open Disc" -msgstr "Kan disk niet openen" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Kan niet opslaan." - -msgid "Cover Download" -msgstr "Download hoesjes" - -msgid "Create" -msgstr "Maak" - -msgid "Credits" -msgstr "" - -msgid "Custom Paths" -msgstr "Bestandslocaties" - -msgid "DOL Path" -msgstr "Locatie DOL" - -msgid "Dec" -msgstr "" - -msgid "Default" -msgstr "Standaard" - -msgid "Default Gamesettings" -msgstr "Standaard spel instellingen" - -msgid "Default Settings" -msgstr "Standaardinstellingen" - -msgid "Delete" -msgstr "Verwijderen" - -msgid "Delete ?" -msgstr "Verwijderen ?" - -msgid "Delete Cheat GCT" -msgstr "Cheat GCT verwijderen" - -msgid "Delete Cheat TXT" -msgstr "Cheat TXT verwijderen" - -msgid "Delete Cover Artwork" -msgstr "Hoesjes verwijderen" - -msgid "Delete Disc Artwork" -msgstr "Disk labels verwijderen" - -msgid "Design:" -msgstr "Ontwerp:" - -msgid "Developed by" -msgstr "Ontwikkeld door" - -msgid "Directory does not exist!" -msgstr "Map bestaat niet!" - -msgid "Disc Artwork Download" -msgstr "Download disk labels" - -msgid "Disc Artwork Path" -msgstr "Locatie disk labels" - -msgid "Disc Images" -msgstr "Disk labels" - -msgid "Display" -msgstr "Tonen" - -msgid "Display as a carousel" -msgstr "Carrouselweergave" - -msgid "Display as a grid" -msgstr "Rasterweergave" - -msgid "Display as a list" -msgstr "Lijstweergave" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Wil je echt verwijderen:" - -msgid "Do you want to apply it now?" -msgstr "Wil je dit nu toepassen?" - -msgid "Do you want to change language?" -msgstr "Wil je de taal wijzigen?" - -msgid "Do you want to download this theme?" -msgstr "Wil je dit thema downloaden?" - -msgid "Do you want to format:" -msgstr "Wil je formatteren:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Wil je de alt DOL gebruiken waarvan is bevestigd dat deze werkt?" - -msgid "Do you wish to update/download all language files?" -msgstr "Wil je alle taalbestanden updaten/downloaden?" - -msgid "Done!" -msgstr "Klaar!" - -msgid "Download" -msgstr "" - -msgid "Download Boxart image?" -msgstr "Hoesjes downloaden?" - -msgid "Download Discart image?" -msgstr "Disk label downloaden?" - -msgid "Download Now" -msgstr "Download nu" - -msgid "Download failed." -msgstr "Download mislukt." - -msgid "Download finished" -msgstr "Download voltooid" - -msgid "Download request failed." -msgstr "Download aanvraag mislukt." - -msgid "Downloading Page List:" -msgstr "Download pagina lijst:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Bestand downloaden" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Afbeelding downloaden:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "FOUT" - -msgid "ERROR:" -msgstr "FOUT:" - -msgid "ERROR: Can't set up theme." -msgstr "FOUT: Kan thema niet instellen" - -msgid "Error" -msgstr "Fout" - -msgid "Error !" -msgstr "Fout !" - -msgid "Error 002 fix" -msgstr "Herstel fout 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Fout bij lezen disk" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Fout bij overplaatsen van data." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Fout..." - -msgid "Error:" -msgstr "Fout:" - -msgid "Extracting files..." -msgstr "Bestanden uitpakken..." - -msgid "FAT: Use directories" -msgstr "FAT: gebruik directories" - -msgid "Failed formating" -msgstr "Formatteren mislukt" - -msgid "Failed to extract." -msgstr "Uitpakken mislukt." - -msgid "Failed to open partition" -msgstr "Partitie openen mislukt" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "Bestand niet gevonden." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Installatie afronden... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "X omwisselen" - -msgid "Format" -msgstr "Formatteer" - -msgid "Formatting, please wait..." -msgstr "Bezig met formatteren..." - -msgid "Free Space" -msgstr "Vrije ruimte" - -msgid "Full Shutdown" -msgstr "Volledig uitzetten" - -msgid "GCT Cheatcodes Path" -msgstr "Locatie GCT cheatcodes" - -msgid "GCT File created" -msgstr "GCT bestand aangemaakt" - -msgid "GUI Settings" -msgstr "Menu opties" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg in geen enkele submap gevonden." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Spel taal" - -msgid "Game Load" -msgstr "Spel opties" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Spel grootte" - -msgid "Game Sound Mode" -msgstr "Spel geluid mode" - -msgid "Game Sound Volume" -msgstr "Spel geluid volume" - -msgid "Game is already installed:" -msgstr "Spel is al geïnstalleerd:" - -msgid "Game partition" -msgstr "Spel partitie" - -msgid "Games" -msgstr "Spellen" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "" - -msgid "Homebrew Apps Path" -msgstr "Locatie homebrew apps" - -msgid "Homebrew Launcher" -msgstr "Homebrew starter" - -msgid "Hour" -msgstr "Uur" - -msgid "How do you want to update?" -msgstr "Hoe wil je updaten?" - -msgid "How to Shutdown?" -msgstr "Hoe uitzetten?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Als je geen WiFi hebt, druk dan op 1 om een URL voor je WiiTDB.zip te krijgen" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Binnenkomend bestand %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Binnenkomend bestand %0.2fMB" - -msgid "Initializing Network" -msgstr "Netwerk initialiseren" - -msgid "Insert Disk" -msgstr "Voer een disk in" - -msgid "Insert a Wii Disc!" -msgstr "Voer een Wii disk in!" - -msgid "Insert an SD-Card to save." -msgstr "Voer een SD kaart in om op te slaan." - -msgid "Insert an SD-Card to use this option." -msgstr "Voer een SD kaart in om deze optie te gebruiken." - -msgid "Install" -msgstr "Installeer" - -msgid "Install Error!" -msgstr "Installatiefout!" - -msgid "Install a game" -msgstr "Spel installeren" - -msgid "Install partitions" -msgstr "Installatie partitie" - -msgid "Installing content... Ok!" -msgstr "Installeren inhoud... Ok!" - -msgid "Installing game:" -msgstr "Bezig met installeren:" - -msgid "Installing ticket... Ok!" -msgstr "Ticket installeren... Ok!" - -msgid "Installing title... Ok!" -msgstr "Titel installeren... Ok!" - -msgid "Installing wad" -msgstr "Wad installeren" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Je hebt informatie gevonden die ons kan helpen. Geeft u alstublieft deze info door aan ons ontwikkelingsteam." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Jul" - -msgid "June" -msgstr "Jun" - -msgid "Keep" -msgstr "Bijhouden" - -msgid "Keyboard" -msgstr "Toetsenbord" - -msgid "Language File" -msgstr "Taal bestand" - -msgid "Language change:" -msgstr "Taal wijzigen:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Locatie taal gewijzigd." - -msgid "Load" -msgstr "Laad" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Laad bestand van %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Deze DOL als alt DOL gebruiken?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Standaardtaal laden." - -msgid "Loading standard music." -msgstr "Standaardmuziek laden." - -msgid "Lock Console" -msgstr "Console vergrendelen" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "Mrt" - -msgid "Mark new games" -msgstr "Markeer nieuwe spellen" - -msgid "May" -msgstr "Mei" - -msgid "Missing files" -msgstr "Missende bestanden" - -msgid "Mount DVD drive" -msgstr "DVD Laden" - -msgid "Music Loop Mode" -msgstr "Muziek Herhaal Mode" - -msgid "Music Volume" -msgstr "Muziekvolume" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Nieuwe disk gevonden" - -msgid "No" -msgstr "Nee" - -msgid "No Cheatfile found" -msgstr "Geen cheatbestand gevonden" - -msgid "No DOL file found on disc." -msgstr "Geen DOL bestand gevonden op disk." - -msgid "No SD-Card inserted!" -msgstr "Geen SD kaart gevonden!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Geen cheats geselecteerd" - -msgid "No data could be read." -msgstr "Data kon niet gelezen worden." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Geen missende bestanden!" - -msgid "No new updates." -msgstr "Geen nieuwe updates." - -msgid "No themes found on the site." -msgstr "Geen thema's gevonden op de site." - -msgid "Not a WAD file." -msgstr "Geen WAD bestand." - -msgid "Not a Wii Disc" -msgstr "Geen Wii disk" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Niet genoeg vrije ruimte." - -msgid "Not enough free space!" -msgstr "Niet genoeg vrije ruimte!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Formaat niet ondersteund!" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "Uit" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Okt" - -msgid "Official Site:" -msgstr "Officiële site:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Ouderlijk toezicht" - -msgid "Partition" -msgstr "Partitie" - -msgid "Password" -msgstr "Wachtwoord" - -msgid "Password Changed" -msgstr "Wachtwoord gewijzigd" - -msgid "Password has been changed" -msgstr "Wachtwoord is gewijzigd" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Plak het in je webbrowser om WiiTDB.zip te downloaden." - -msgid "Patch Country Strings" -msgstr "Regio's herstellen" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Kiezen van lijst" - -msgid "Play Count" -msgstr "Gespeeld" - -msgid "Play Next" -msgstr "Speel Volgende" - -msgid "Play Previous" -msgstr "Speel Vorige" - -msgid "Playing Music:" -msgstr "Speelt nu:" - -msgid "Please wait..." -msgstr "Even geduld..." - -msgid "Power off the Wii" -msgstr "Wii uitschakelen" - -msgid "Prompts Buttons" -msgstr "Weergave knoppen" - -msgid "Published by" -msgstr "Uitgegeven door" - -msgid "Quick Boot" -msgstr "Snelle start" - -msgid "Reading WAD data... Ok!" -msgstr "WAD data lezen... Ok!" - -msgid "Receiving file from:" -msgstr "Bestand ontvangen van:" - -msgid "Released" -msgstr "Uitgegeven" - -msgid "Reload SD" -msgstr "SD herladen" - -msgid "Remove update" -msgstr "Verwijder update" - -msgid "Rename Game on WBFS" -msgstr "Spel hernoemen op WBFS" - -msgid "Reset BG Music" -msgstr "Reset achtergrond muziek" - -msgid "Reset Playcounter" -msgstr "Speeltellers resetten" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Herstarten..." - -msgid "Return" -msgstr "Terug" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Terug naar Wii menu" - -msgid "Rumble" -msgstr "Trilfunctie" - -msgid "SFX Volume" -msgstr "Volume geluidseffecten" - -msgid "Save" -msgstr "Opslaan" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Spellenlijst opslaan in" - -msgid "Saved" -msgstr "Opgeslagen" - -msgid "Screensaver" -msgstr "Schermbeveiliging" - -msgid "Select" -msgstr "Selecteer" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Kies een DOL" - -msgid "Sept" -msgstr "Sep" - -msgid "Set Search-Filter" -msgstr "Zoekfilter instellen" - -msgid "Settings" -msgstr "Instellingen" - -msgid "Shutdown System" -msgstr "Systeem uitzetten" - -msgid "Shutdown to Idle" -msgstr "Slaapstand" - -msgid "Sort alphabetically" -msgstr "Alfabetisch sorteren" - -msgid "Sort by rank" -msgstr "Sorteren op rang" - -msgid "Sort order by most played" -msgstr "Sorteren op meest gespeeld" - -msgid "Sound" -msgstr "Geluid" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Speciale dank aan:" - -msgid "Success" -msgstr "Succes" - -msgid "Success:" -msgstr "Succes:" - -msgid "Successfully Saved" -msgstr "Met succes opgeslagen!" - -msgid "Successfully Updated" -msgstr "Met succes geüpdate!" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Met succes geüpdate met dank aan www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Met succes verwijderd:" - -msgid "Successfully extracted theme." -msgstr "Thema succesvol uitgepakt." - -msgid "Successfully installed:" -msgstr "Met succes geïnstalleerd:" - -msgid "TXT Cheatcodes Path" -msgstr "Locatie TXT cheats" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "De opgegeven map bestaat niet. Wil je deze aanmaken?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Thema download locatie" - -msgid "Theme Downloader" -msgstr "Thema downloader" - -msgid "Theme Path" -msgstr "Locatie thema" - -msgid "Theme Title:" -msgstr "Thema Titel:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Tijd over:" - -msgid "Title Launcher" -msgstr "Titel starter" - -msgid "Titles from WiiTDB" -msgstr "WiiTDB titels" - -msgid "Tooltips" -msgstr "Knopinfo" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Overdracht mislukt." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB Apparaat niet gevonden" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX is vergrendeld" - -msgid "Uninstall" -msgstr "Verwijderen" - -msgid "Uninstall Game" -msgstr "Spel verwijderen" - -msgid "Uninstall Menu" -msgstr "Verwijderen" - -msgid "Uninstalling wad" -msgstr "Wad verwijderen" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Console moet worden vrijgegeven." - -msgid "Unsupported format, try to extract manually." -msgstr "Niet ondersteund formaat, probeer handmatig uit te pakken." - -msgid "Update" -msgstr "Updaten" - -msgid "Update All" -msgstr "Alles updaten" - -msgid "Update DOL" -msgstr "DOL updaten" - -msgid "Update Files" -msgstr "Updaten" - -msgid "Update Path" -msgstr "Updatelocatie" - -msgid "Update all Language Files" -msgstr "Alle taalbestanden updaten" - -msgid "Update failed" -msgstr "Update mislukt" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Taalbestanden updaten:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Geuploade ZIP is geïnstalleerd in je homebrew locatie." - -msgid "VIDTV Patch" -msgstr "VIDTV patchen" - -#, c-format -msgid "Version: %s" -msgstr "Versie: %s" - -msgid "Video Mode" -msgstr "" - -msgid "WIP Patches Path" -msgstr "Locatie WIP patches" - -msgid "Waiting for USB Device" -msgstr "Wachten op USB apparaat" - -msgid "Waiting..." -msgstr "Wachten..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Wat wil je updaten?" - -msgid "WiFi Features" -msgstr "WiFi functies" - -msgid "Wii Menu" -msgstr "" - -msgid "Wii Settings" -msgstr "Wii instellingen" - -msgid "WiiTDB Files" -msgstr "WiiTDB bestanden" - -msgid "WiiTDB Path" -msgstr "Locatie WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Wii verlichting" - -msgid "Wrong Password" -msgstr "Fout wachtwoord" - -msgid "Yes" -msgstr "Ja" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Je moet een partitie selecteren of formatteren" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Je URL is opgeslagen in %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "en vertalers voor taalbestand updates" - -msgid "available" -msgstr "beschikbaar" - -msgid "does not exist!" -msgstr "bestaat niet!" - -msgid "does not exist! Loading game without cheats." -msgstr "bestaat niet! Spel laden zonder cheats." - -msgid "files left" -msgstr "Bestanden resterend" - -msgid "files not found on the server!" -msgstr "Bestanden niet gevonden op server!" - -msgid "for FAT/NTFS support" -msgstr "voor FAT/NTFS ondersteuning" - -msgid "for Ocarina" -msgstr "voor Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "voor WiiTDB en upload afbeeldingen" - -msgid "for diverse patches" -msgstr "voor diverse correcties" - -msgid "for his awesome tool LibWiiGui" -msgstr "voor zijn geweldige tool LibWiiGui" - -msgid "for hosting the themes" -msgstr "voor het hosten van de thema's" - -msgid "for hosting the update files" -msgstr "voor het hosten van update bestanden" - -msgid "for the USB Loader source" -msgstr "voor USB Loader source" - -msgid "formatted!" -msgstr "geformatteerd!" - -msgid "free" -msgstr "vrij" - -msgid "not set" -msgstr "niet ingesteld" - -msgid "of" -msgstr "van" - -msgid "seconds left" -msgstr "seconden over" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Installeer 1:1 kopie" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Iedereen 3+)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Kinderen 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 uur" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Tiener 12+)" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Adolescenten 16+)" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Volwassen 18+)" - -#~ msgid "An Error occured" -#~ msgstr "Er is een fout opgetreden" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Weet je zeker dat je ouderlijk toezicht wilt aanzetten?" - -#~ msgid "AutoPatch" -#~ msgstr "Automatisch patchen" - -#~ msgid "Both" -#~ msgstr "Beide" - -#~ msgid "Checking for Updates" -#~ msgstr "Controleren op updates" - -#~ msgid "Console Default" -#~ msgstr "Console standaard" - -#~ msgid "Customs/Original" -#~ msgstr "Aangepast/Origineel" - -#~ msgid "Disc Default" -#~ msgstr "Disk standaard" - -#~ msgid "Downloading" -#~ msgstr "Downloaden" - -#~ msgid "Dutch" -#~ msgstr "Nederlands" - -#~ msgid "English" -#~ msgstr "Engels" - -#~ msgid "French" -#~ msgstr "Frans" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "SPELID_Spelnaam" - -#~ msgid "Game ID" -#~ msgstr "Spel ID" - -#~ msgid "Game Region" -#~ msgstr "Spel Regio" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "Spelnaam [SPELID]" - -#~ msgid "German" -#~ msgstr "Duits" - -#~ msgid "Invalid PIN code" -#~ msgstr "Onjuiste PIN code" - -#~ msgid "Italian" -#~ msgstr "Italiaans" - -#~ msgid "Japanese" -#~ msgstr "Japans" - -#~ msgid "Korean" -#~ msgstr "Koreaans" - -#~ msgid "Left" -#~ msgstr "Links" - -#~ msgid "Like SysMenu" -#~ msgstr "Als SysteemMenu" - -#~ msgid "Load From SD/USB" -#~ msgstr "Laden van SD/USB" - -#~ msgid "Locked" -#~ msgstr "Vergrendeld" - -#~ msgid "Loop Directory" -#~ msgstr "Herhaal Map" - -#~ msgid "Loop Music" -#~ msgstr "Herhaal Muziek" - -#~ msgid "Loop Sound" -#~ msgstr "Geluid herhalen" - -#~ msgid "Neither" -#~ msgstr "Geen" - -#~ msgid "Next" -#~ msgstr "Volgende" - -#~ msgid "None" -#~ msgstr "Geen" - -#~ msgid "Normal" -#~ msgstr "Normaal" - -#~ msgid "ON" -#~ msgstr "Aan" - -#~ msgid "Only Customs" -#~ msgstr "Enkel aangepast" - -#~ msgid "Only Original" -#~ msgstr "Enkel origineel" - -#~ msgid "Only for Install" -#~ msgstr "Alleen bij installeren" - -#~ msgid "Original/Customs" -#~ msgstr "Origineel/Aangepast" - -#~ msgid "Parental Control disabled" -#~ msgstr "Ouderlijk toezicht uitgeschakeld" - -#~ msgid "Play Once" -#~ msgstr "Speel één maal" - -#~ msgid "Prev" -#~ msgstr "Vorige" - -#~ msgid "Random Directory Music" -#~ msgstr "Willekeurige Map Muziek" - -#~ msgid "Right" -#~ msgstr "Rechts" - -#~ msgid "SChinese" -#~ msgstr "SChinees" - -#~ msgid "Sound+BGM" -#~ msgstr "Geluid+Achtergrondmuziek" - -#~ msgid "Sound+Quiet" -#~ msgstr "Geluid+Stilte" - -#~ msgid "Spanish" -#~ msgstr "Spaans" - -#~ msgid "System Default" -#~ msgstr "Systeem standaard" - -#~ msgid "TChinese" -#~ msgstr "Chinees Trad." - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Het wad bestand is geïnstalleerd. Maar kon niet van de SD kaart verwijderd worden." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "De wad installatie is mislukt met fout %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Wad is gedownload maar kan niet worden geopend (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Ontgrendel ouderlijk toezicht" - -#~ msgid "Unlocked" -#~ msgstr "Vrijgegeven" - -#~ msgid "Update to" -#~ msgstr "Updaten naar" - -#~ msgid "Updating" -#~ msgstr "Updaten" - -#~ msgid "Updating Language Files..." -#~ msgstr "Taalbestanden updaten..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "WiiTDB.zip updaten" - -#~ msgid "Widescreen Fix" -#~ msgstr "Breedbeeld" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Je hebt ouderlijk toezicht niet ingeschakeld. Als je ouderlijk toezicht wilt gebruiken, zet het dan aan in de Wii instellingen." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Kan mogelijk niet goed opstarten als je Systeem Menu niet up to date is." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Locatie BCA codes gewijzigd" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Terug naar Wii Menu" - -#~ msgid "Channels" -#~ msgstr "Kanalen" - -#~ msgid "Checking existing artwork" -#~ msgstr "Bestaande afbeeldingen controleren" - -#~ msgid "Confirm" -#~ msgstr "Bevestigen" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Kan geen WBFS partitie vinden." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Kan WBFS partitie niet openen" - -#~ msgid "Could not read the disc." -#~ msgstr "Kan disk niet lezen." - -#~ msgid "Could not set USB." -#~ msgstr "Kan USB niet instellen." - -#~ msgid "Cover Path Changed" -#~ msgstr "Locatie hoesjes gewijzigd" - -#~ msgid "DOL path changed" -#~ msgstr "Locatie DOL gewijzigd" - -#~ msgid "Disc Path Changed" -#~ msgstr "Locatie disk labels gewijzigd" - -#~ msgid "Display favorites" -#~ msgstr "Favorieten" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Wil je 30 sec. lang opnieuw proberen?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Ouderlijk toezicht inschakelen" - -#~ msgid "Force" -#~ msgstr "Forceer" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Locatie GCT cheatcodes gewijzigd" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Locatie HB apps gewijzigd" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Voer een SD kaart in om afbeeldingen te downloaden." - -#~ msgid "Install not possible" -#~ msgstr "Installatie niet mogelijk" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Waarschijnlijk zijn de afmetingen niet deelbaar door 4." - -#~ msgid "Network init error" -#~ msgstr "Netwerk init. fout" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Geen .dol of .elf bestanden gevonden" - -#~ msgid "No Favorites" -#~ msgstr "Geen favorieten" - -#~ msgid "No USB Device" -#~ msgstr "Geen USB apparaat" - -#~ msgid "No USB Device found." -#~ msgstr "Geen USB apparaat gevonden." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Geen WBFS of FAT/NTFS partitie gevonden" - -#~ msgid "Normal Covers" -#~ msgstr "Gewone hoesjes" - -#~ msgid "Not Found" -#~ msgstr "Niet gevonden" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Geen DOL/ELF bestand." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Reset naar standaard achtergrond muziek?" - -#~ msgid "Save Failed" -#~ msgstr "Opslaan mislukt" - -#~ msgid "Selected DOL" -#~ msgstr "Gekozen DOL" - -#~ msgid "Standard" -#~ msgstr "Standaard" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Locatie TXT cheatcodes gewijzigd" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Thema download locatie gewijzigd" - -#~ msgid "Theme Path Changed" -#~ msgstr "Locatie thema gewijzigd" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX werkt alleen met Hermes cIOS rev 4! Zorg dat je revisie 4 hebt geïnstalleerd!" - -#~ msgid "Update Path changed." -#~ msgstr "Updatelocatie gewijzigd." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Locatie WIP Patches gewijzigd" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Locatie WiiTDB gewijzigd" - -#~ msgid "You are about to delete " -#~ msgstr "Je wilt nu verwijderen: " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Je wilt favorieten tonen, maar je hebt er geen ingesteld." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Je gebruikt het NTFS bestandssysteem. Door mogelijke schrijffouten naar een NTFS partitie, is een spel installeren niet mogelijk." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Je probeerde een slechte afbeelding te laden" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "bestaat niet! Je hebt iets fout gedaan, Idioot." - -#~ msgid "file left" -#~ msgstr "Bestand resterend" diff --git a/Languages/english.lang b/Languages/english.lang deleted file mode 100644 index 3f9c5141..00000000 --- a/Languages/english.lang +++ /dev/null @@ -1,1198 +0,0 @@ -# USB Loader GX language source file. -# english.lang - rxxx -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: \n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "" - -msgid " could not be downloaded." -msgstr "" - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "" - -msgid " is not on the server." -msgstr "" - -msgid "2D Cover Path" -msgstr "" - -msgid "3D Cover Path" -msgstr "" - -msgid "3D Covers" -msgstr "" - -msgid ">> Deleting tickets..." -msgstr "" - -msgid ">> Deleting tickets...ERROR! " -msgstr "" - -msgid ">> Deleting tickets...Ok! " -msgstr "" - -msgid ">> Deleting title ...ERROR! " -msgstr "" - -msgid ">> Deleting title ...Ok!" -msgstr "" - -msgid ">> Deleting title contents..." -msgstr "" - -msgid ">> Deleting title contents...ERROR! " -msgstr "" - -msgid ">> Deleting title contents...Ok!" -msgstr "" - -msgid ">> Deleting title..." -msgstr "" - -msgid ">> Finishing installation..." -msgstr "" - -msgid ">> Installing content #" -msgstr "" - -msgid ">> Installing ticket..." -msgstr "" - -msgid ">> Installing title..." -msgstr "" - -msgid ">> Reading WAD data..." -msgstr "" - -msgid ">> Reading WAD data...ERROR! " -msgstr "" - -msgid ">> Reading WAD data...Ok!" -msgstr "" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "" - -msgid "Alternate DOL" -msgstr "" - -msgid "App Language" -msgstr "" - -msgid "Apr" -msgstr "" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "" - -msgid "Aug" -msgstr "" - -msgid "Author:" -msgstr "" - -msgid "AutoInit Network" -msgstr "" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "" - -msgid "Back to HBC or Wii Menu" -msgstr "" - -msgid "Back to Loader" -msgstr "" - -msgid "Backgroundmusic" -msgstr "" - -msgid "Big thanks to:" -msgstr "" - -msgid "Block IOS Reload" -msgstr "" - -msgid "Boot/Standard" -msgstr "" - -msgid "Boot?" -msgstr "" - -msgid "Can't be formatted" -msgstr "" - -msgid "Can't create directory" -msgstr "" - -msgid "Can't create file" -msgstr "" - -msgid "Can't delete:" -msgstr "" - -msgid "Cancel" -msgstr "" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "" - -msgid "Click to change game ID" -msgstr "" - -msgid "Clock" -msgstr "" - -msgid "Close" -msgstr "" - -msgid "Code Download" -msgstr "" - -#, c-format -msgid "Coded by: %s" -msgstr "" - -msgid "Coding:" -msgstr "" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "" - -msgid "Console Locked" -msgstr "" - -msgid "Console should be unlocked to modify it." -msgstr "" - -msgid "Continue to install game?" -msgstr "" - -msgid "Controllevel" -msgstr "" - -msgid "Correct Password" -msgstr "" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "" - -msgid "Could not initialize network!" -msgstr "" - -msgid "Could not open Disc" -msgstr "" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "" - -msgid "Cover Download" -msgstr "" - -msgid "Create" -msgstr "" - -msgid "Credits" -msgstr "" - -msgid "Custom Paths" -msgstr "" - -msgid "DOL Path" -msgstr "" - -msgid "Dec" -msgstr "" - -msgid "Default" -msgstr "" - -msgid "Default Gamesettings" -msgstr "" - -msgid "Default Settings" -msgstr "" - -msgid "Delete" -msgstr "" - -msgid "Delete ?" -msgstr "" - -msgid "Delete Cheat GCT" -msgstr "" - -msgid "Delete Cheat TXT" -msgstr "" - -msgid "Delete Cover Artwork" -msgstr "" - -msgid "Delete Disc Artwork" -msgstr "" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "" - -msgid "Directory does not exist!" -msgstr "" - -msgid "Disc Artwork Download" -msgstr "" - -msgid "Disc Artwork Path" -msgstr "" - -msgid "Disc Images" -msgstr "" - -msgid "Display" -msgstr "" - -msgid "Display as a carousel" -msgstr "" - -msgid "Display as a grid" -msgstr "" - -msgid "Display as a list" -msgstr "" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "" - -msgid "Do you want to download this theme?" -msgstr "" - -msgid "Do you want to format:" -msgstr "" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "" - -msgid "Do you wish to update/download all language files?" -msgstr "" - -msgid "Done!" -msgstr "" - -msgid "Download" -msgstr "" - -msgid "Download Boxart image?" -msgstr "" - -msgid "Download Discart image?" -msgstr "" - -msgid "Download Now" -msgstr "" - -msgid "Download failed." -msgstr "" - -msgid "Download finished" -msgstr "" - -msgid "Download request failed." -msgstr "" - -msgid "Downloading Page List:" -msgstr "" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "" - -msgid "ERROR:" -msgstr "" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "" - -msgid "Error !" -msgstr "" - -msgid "Error 002 fix" -msgstr "" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "" - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "" - -msgid "Error:" -msgstr "" - -msgid "Extracting files..." -msgstr "" - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "" - -msgid "Failed to extract." -msgstr "" - -msgid "Failed to open partition" -msgstr "" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "" - -msgid "Format" -msgstr "" - -msgid "Formatting, please wait..." -msgstr "" - -msgid "Free Space" -msgstr "" - -msgid "Full Shutdown" -msgstr "" - -msgid "GCT Cheatcodes Path" -msgstr "" - -msgid "GCT File created" -msgstr "" - -msgid "GUI Settings" -msgstr "" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "" - -msgid "Game Load" -msgstr "" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "" - -msgid "Game Sound Mode" -msgstr "" - -msgid "Game Sound Volume" -msgstr "" - -msgid "Game is already installed:" -msgstr "" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "" - -msgid "Homebrew Apps Path" -msgstr "" - -msgid "Homebrew Launcher" -msgstr "" - -msgid "Hour" -msgstr "" - -msgid "How do you want to update?" -msgstr "" - -msgid "How to Shutdown?" -msgstr "" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "" - -msgid "Initializing Network" -msgstr "" - -msgid "Insert Disk" -msgstr "" - -msgid "Insert a Wii Disc!" -msgstr "" - -msgid "Insert an SD-Card to save." -msgstr "" - -msgid "Insert an SD-Card to use this option." -msgstr "" - -msgid "Install" -msgstr "" - -msgid "Install Error!" -msgstr "" - -msgid "Install a game" -msgstr "" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "" - -msgid "Installing game:" -msgstr "" - -msgid "Installing ticket... Ok!" -msgstr "" - -msgid "Installing title... Ok!" -msgstr "" - -msgid "Installing wad" -msgstr "" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "" - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "" - -msgid "June" -msgstr "" - -msgid "Keep" -msgstr "" - -msgid "Keyboard" -msgstr "" - -msgid "Language File" -msgstr "" - -msgid "Language change:" -msgstr "" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "" - -msgid "Load" -msgstr "" - -#, c-format -msgid "Load file from: %s ?" -msgstr "" - -msgid "Load this DOL as alternate DOL?" -msgstr "" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "" - -msgid "Loading standard music." -msgstr "" - -msgid "Lock Console" -msgstr "" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "" - -msgid "Missing files" -msgstr "" - -msgid "Mount DVD drive" -msgstr "" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "" - -msgid "No" -msgstr "" - -msgid "No Cheatfile found" -msgstr "" - -msgid "No DOL file found on disc." -msgstr "" - -msgid "No SD-Card inserted!" -msgstr "" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "" - -msgid "No data could be read." -msgstr "" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "" - -msgid "No new updates." -msgstr "" - -msgid "No themes found on the site." -msgstr "" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "" - -msgid "Not enough free space!" -msgstr "" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "" - -msgid "Official Site:" -msgstr "" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "" - -msgid "Partition" -msgstr "" - -msgid "Password" -msgstr "" - -msgid "Password Changed" -msgstr "" - -msgid "Password has been changed" -msgstr "" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "" - -msgid "Patch Country Strings" -msgstr "" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "" - -msgid "Play Count" -msgstr "" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "" - -msgid "Power off the Wii" -msgstr "" - -msgid "Prompts Buttons" -msgstr "" - -msgid "Published by" -msgstr "" - -msgid "Quick Boot" -msgstr "" - -msgid "Reading WAD data... Ok!" -msgstr "" - -msgid "Receiving file from:" -msgstr "" - -msgid "Released" -msgstr "" - -msgid "Reload SD" -msgstr "" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "" - -msgid "Return" -msgstr "" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "" - -msgid "Rumble" -msgstr "" - -msgid "SFX Volume" -msgstr "" - -msgid "Save" -msgstr "" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "" - -msgid "Saved" -msgstr "" - -msgid "Screensaver" -msgstr "" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "" - -msgid "Sept" -msgstr "" - -msgid "Set Search-Filter" -msgstr "" - -msgid "Settings" -msgstr "" - -msgid "Shutdown System" -msgstr "" - -msgid "Shutdown to Idle" -msgstr "" - -msgid "Sort alphabetically" -msgstr "" - -msgid "Sort by rank" -msgstr "" - -msgid "Sort order by most played" -msgstr "" - -msgid "Sound" -msgstr "" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "" - -msgid "Success" -msgstr "" - -msgid "Success:" -msgstr "" - -msgid "Successfully Saved" -msgstr "" - -msgid "Successfully Updated" -msgstr "" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "" - -msgid "Successfully extracted theme." -msgstr "" - -msgid "Successfully installed:" -msgstr "" - -msgid "TXT Cheatcodes Path" -msgstr "" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "" - -msgid "Theme Downloader" -msgstr "" - -msgid "Theme Path" -msgstr "" - -msgid "Theme Title:" -msgstr "" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "" - -msgid "Title Launcher" -msgstr "" - -msgid "Titles from WiiTDB" -msgstr "" - -msgid "Tooltips" -msgstr "" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "" - -msgid "USB Loader GX is protected" -msgstr "" - -msgid "Uninstall" -msgstr "" - -msgid "Uninstall Game" -msgstr "" - -msgid "Uninstall Menu" -msgstr "" - -msgid "Uninstalling wad" -msgstr "" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "" - -msgid "Unsupported format, try to extract manually." -msgstr "" - -msgid "Update" -msgstr "" - -msgid "Update All" -msgstr "" - -msgid "Update DOL" -msgstr "" - -msgid "Update Files" -msgstr "" - -msgid "Update Path" -msgstr "" - -msgid "Update all Language Files" -msgstr "" - -msgid "Update failed" -msgstr "" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "" - -msgid "VIDTV Patch" -msgstr "" - -#, c-format -msgid "Version: %s" -msgstr "" - -msgid "Video Mode" -msgstr "" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "" - -msgid "Waiting..." -msgstr "" - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "" - -msgid "WiFi Features" -msgstr "" - -msgid "Wii Menu" -msgstr "" - -msgid "Wii Settings" -msgstr "" - -msgid "WiiTDB Files" -msgstr "" - -msgid "WiiTDB Path" -msgstr "" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "" - -msgid "Wrong Password" -msgstr "" - -msgid "Yes" -msgstr "" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "" - -msgid "and translaters for language files updates" -msgstr "" - -msgid "available" -msgstr "" - -msgid "does not exist!" -msgstr "" - -msgid "does not exist! Loading game without cheats." -msgstr "" - -msgid "files left" -msgstr "" - -msgid "files not found on the server!" -msgstr "" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "" - -msgid "for diverse patches" -msgstr "" - -msgid "for his awesome tool LibWiiGui" -msgstr "" - -msgid "for hosting the themes" -msgstr "" - -msgid "for hosting the update files" -msgstr "" - -msgid "for the USB Loader source" -msgstr "" - -msgid "formatted!" -msgstr "" - -msgid "free" -msgstr "" - -msgid "not set" -msgstr "" - -msgid "of" -msgstr "" - -msgid "seconds left" -msgstr "" diff --git a/Languages/finnish.lang b/Languages/finnish.lang deleted file mode 100644 index 912ecf6f..00000000 --- a/Languages/finnish.lang +++ /dev/null @@ -1,1459 +0,0 @@ -# USB Loader GX language source file. -# finnish.lang - r740 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: c64rmx\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "Wad Tallennettu nimellä:" - -msgid " could not be downloaded." -msgstr "Latausta ei voitu suorittaa" - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "" - -msgid " is not on the server." -msgstr "Tiedostoa ei löydy serveriltä" - -msgid "2D Cover Path" -msgstr "2D Kansien polku" - -msgid "3D Cover Path" -msgstr "3D Kansien polku" - -msgid "3D Covers" -msgstr "3D Kannet" - -msgid ">> Deleting tickets..." -msgstr ">> Tuhotaan lipukkeita..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Tuhotaan lipukkeita...VIRHE!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Tuhotaan lipukkeita...Ok!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Tuhotaan nimikettä...VIRHE!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> Tuhotaan nimikettä...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Tuhotaan nimikkeen sisältöä..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Tuhotaan nimikkeen sisältöä...VIRHE!" - -msgid ">> Deleting title contents...Ok!" -msgstr "Tuhotaan nimikkeen sisältöä...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Tuhotaan nimikettä..." - -msgid ">> Finishing installation..." -msgstr ">> Viimeistellään asennusta..." - -msgid ">> Installing content #" -msgstr ">> Asennetaan sisältöä #" - -msgid ">> Installing ticket..." -msgstr ">> Asennetaan lipuketta..." - -msgid ">> Installing title..." -msgstr ">> Asennetaan nimikettä..." - -msgid ">> Reading WAD data..." -msgstr ">> Luetaan WAD:ia..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Luetaan WAD:ia...VIRHE!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Luetaan WAD:ia...Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Kaikki asetukset on nyt käytettävissä." - -msgid "Alternate DOL" -msgstr "Vaihtoehto DOL" - -msgid "App Language" -msgstr "Ohjelman kieli" - -msgid "Apr" -msgstr "huhti" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Oletko varma?" - -msgid "Aug" -msgstr "elo" - -msgid "Author:" -msgstr "" - -msgid "AutoInit Network" -msgstr "Autom. verkon käynnistys" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "Takaisin" - -msgid "Back to HBC or Wii Menu" -msgstr "Takaisin HBC:hen tai Wii Menuun" - -msgid "Back to Loader" -msgstr "HBC" - -msgid "Backgroundmusic" -msgstr "Taustamusiikki" - -msgid "Big thanks to:" -msgstr "Isot kiitokset:" - -msgid "Block IOS Reload" -msgstr "Blokkaa IOS:in uudelleenlataus" - -msgid "Boot/Standard" -msgstr "Käynnistys/Standardi" - -msgid "Boot?" -msgstr "Boottaa?" - -msgid "Can't be formatted" -msgstr "Ei voida formatoida" - -msgid "Can't create directory" -msgstr "Ei voi luoda kansiota" - -msgid "Can't create file" -msgstr "" - -msgid "Can't delete:" -msgstr "Ei voida poistaa:" - -msgid "Cancel" -msgstr "Peruuta" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "Kooditiedosto tyhjä" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Klikkaa ladataksesi kansia" - -msgid "Click to change game ID" -msgstr "Klikkaa vaihtaaksesi pelin ID" - -msgid "Clock" -msgstr "Kello" - -msgid "Close" -msgstr "Sulje" - -msgid "Code Download" -msgstr "Koodin lataus" - -#, c-format -msgid "Coded by: %s" -msgstr "Koodaus: %s" - -msgid "Coding:" -msgstr "Koodaus" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "Konsoli" - -msgid "Console Locked" -msgstr "Konsoli lukittu" - -msgid "Console should be unlocked to modify it." -msgstr "Avaa konsolin lukitus muokataksesi asetuksia." - -msgid "Continue to install game?" -msgstr "Jatka pelin asennusta?" - -msgid "Controllevel" -msgstr "Hallinta-aste" - -msgid "Correct Password" -msgstr "Oikea salasana" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "GCT tiedostoa ei voitu luoda" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "DIP Moduulia ei voitu alustaa!" - -msgid "Could not initialize network!" -msgstr "Verkkoon ei voitu yhdistää!" - -msgid "Could not open Disc" -msgstr "Levyä ei voitu avata" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "" - -msgid "Cover Download" -msgstr "Kansien lataus" - -msgid "Create" -msgstr "Luo" - -msgid "Credits" -msgstr "Tekijät" - -msgid "Custom Paths" -msgstr "Omat polut" - -msgid "DOL Path" -msgstr "DOL:in polku" - -msgid "Dec" -msgstr "joulu" - -msgid "Default" -msgstr "Oletus" - -msgid "Default Gamesettings" -msgstr "Oletus peliasetukset" - -msgid "Default Settings" -msgstr "Oletusasetukset" - -msgid "Delete" -msgstr "Tuhoa" - -msgid "Delete ?" -msgstr "Tuhoa ?" - -msgid "Delete Cheat GCT" -msgstr "Tuhoa Koodi GCT" - -msgid "Delete Cheat TXT" -msgstr "Tuhoa Koodi TXT" - -msgid "Delete Cover Artwork" -msgstr "Tuhoa kannet" - -msgid "Delete Disc Artwork" -msgstr "Tuhoa levykuvat" - -msgid "Design:" -msgstr "Suunnittelu" - -msgid "Developed by" -msgstr "Kehitys" - -msgid "Directory does not exist!" -msgstr "" - -msgid "Disc Artwork Download" -msgstr "Levykuvien lataus" - -msgid "Disc Artwork Path" -msgstr "Levykuvien polku" - -msgid "Disc Images" -msgstr "Levykuvat" - -msgid "Display" -msgstr "Näyttö" - -msgid "Display as a carousel" -msgstr "Näytä karusellina" - -msgid "Display as a grid" -msgstr "Näytä taulukkona" - -msgid "Display as a list" -msgstr "Näytä listana" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Haluatko varmasti formatoida:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "Haluatko vaihtaa kielen?" - -msgid "Do you want to download this theme?" -msgstr "" - -msgid "Do you want to format:" -msgstr "Haluatko formatoida:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Haluatko käyttää vaihtoehtoista DOL tiedostoa jonka tiedetään toimivan?" - -msgid "Do you wish to update/download all language files?" -msgstr "Haluatko päivittää/ladata kaikki kielitiedostot?" - -msgid "Done!" -msgstr "Valmis!" - -msgid "Download" -msgstr "" - -msgid "Download Boxart image?" -msgstr "Lataa kansikuva?" - -msgid "Download Discart image?" -msgstr "Lataa levykuva?" - -msgid "Download Now" -msgstr "Lataa nyt" - -msgid "Download failed." -msgstr "" - -msgid "Download finished" -msgstr "Lataus valmistunut" - -msgid "Download request failed." -msgstr "" - -msgid "Downloading Page List:" -msgstr "" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Lataa tiedostoa:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "VIRHE" - -msgid "ERROR:" -msgstr "VIRHE:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "Virhe" - -msgid "Error !" -msgstr "Virhe !" - -msgid "Error 002 fix" -msgstr "Virhe 002 fix" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Virhe luettaessa levyä" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Virhe siirrettäessä dataa." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Virhe..." - -msgid "Error:" -msgstr "Virhe:" - -msgid "Extracting files..." -msgstr "" - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "Formatointi ei onnistunut" - -msgid "Failed to extract." -msgstr "" - -msgid "Failed to open partition" -msgstr "Osion avaus epäonnistui" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "helmi" - -msgid "File not found." -msgstr "Tiedostoa ei löytynyt" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Viimeistelee asennusta... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Käännä-X" - -msgid "Format" -msgstr "Formatoi" - -msgid "Formatting, please wait..." -msgstr "Formatoi, odota..." - -msgid "Free Space" -msgstr "Vapaata tilaa" - -msgid "Full Shutdown" -msgstr "Täysi sammutus" - -msgid "GCT Cheatcodes Path" -msgstr "GCT Koodien polku" - -msgid "GCT File created" -msgstr "Gct tiedosto luotu" - -msgid "GUI Settings" -msgstr "GUI asetukset" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Kieli" - -msgid "Game Load" -msgstr "Pelin lataus" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Pelin koko" - -msgid "Game Sound Mode" -msgstr "" - -msgid "Game Sound Volume" -msgstr "" - -msgid "Game is already installed:" -msgstr "Peli on jo asennettu:" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "Pelejä" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "" - -msgid "Homebrew Apps Path" -msgstr "Homebrew Apps polku" - -msgid "Homebrew Launcher" -msgstr "" - -msgid "Hour" -msgstr "Tunti" - -msgid "How do you want to update?" -msgstr "Kuinka haluat päivittää?" - -msgid "How to Shutdown?" -msgstr "Miten sammutetaan?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Jos sinulla ei ole WiFi:ä, paina 1 saadaksesi URL josta voi ladata WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "" - -msgid "Initializing Network" -msgstr "Yhdistää verkkoon" - -msgid "Insert Disk" -msgstr "Aseta levy Wiihin" - -msgid "Insert a Wii Disc!" -msgstr "Aseta Wii-levy!" - -msgid "Insert an SD-Card to save." -msgstr "Aseta SD-kortti tallentaaksesi asetuksia." - -msgid "Insert an SD-Card to use this option." -msgstr "Aseta SD-kortti käyttääksesi tätä vaihtoehtoa" - -msgid "Install" -msgstr "Asenna" - -msgid "Install Error!" -msgstr "Asennusvirhe!" - -msgid "Install a game" -msgstr "Asenna peli" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "Asennetaan sisältöä... Ok!" - -msgid "Installing game:" -msgstr "Asentaa peliä:" - -msgid "Installing ticket... Ok!" -msgstr "" - -msgid "Installing title... Ok!" -msgstr "" - -msgid "Installing wad" -msgstr "Asennetaan wadia" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Näyttää että sinulla on tietoa joka on hyödyllistä meille. Ole ystävällinen ja välitä se kehitystiimille." - -msgid "Jan" -msgstr "tammi" - -msgid "July" -msgstr "heinä" - -msgid "June" -msgstr "kesä" - -msgid "Keep" -msgstr "Pidä" - -msgid "Keyboard" -msgstr "Näppäimistö" - -msgid "Language File" -msgstr "KieliTiedosto" - -msgid "Language change:" -msgstr "Kielen vaihto" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Kielen polku vaihdettu" - -msgid "Load" -msgstr "Lataa" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Lataa tiedosto: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Lataa tämä vaihtoehtoisesti tämä dol?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Ladataan standardia kieltä" - -msgid "Loading standard music." -msgstr "Ladataan standardia musiikkia" - -msgid "Lock Console" -msgstr "Lukitse konsoli" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "maalis" - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "touko" - -msgid "Missing files" -msgstr "tiedostoja puuttuu" - -msgid "Mount DVD drive" -msgstr "" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Voimakkuus" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "" - -msgid "No" -msgstr "Ei" - -msgid "No Cheatfile found" -msgstr "Kooditiedostoa ei löydy" - -msgid "No DOL file found on disc." -msgstr "Levyltä ei löydy dol tiedostoa" - -msgid "No SD-Card inserted!" -msgstr "SD-korttia ei ole asetettu wiihin!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "" - -msgid "No data could be read." -msgstr "Tietoa ei voitu lukea" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Ei tiedostoja kadoksissa!" - -msgid "No new updates." -msgstr "Ei uusia päivityksiä" - -msgid "No themes found on the site." -msgstr "" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Ei Wii-levy" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Ei tarpeeksi muistia." - -msgid "Not enough free space!" -msgstr "Ei tarpeeksi tilaa!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Ei tuettu formaatti!" - -msgid "Nov" -msgstr "marras" - -msgid "OFF" -msgstr "Pois" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "loka" - -msgid "Official Site:" -msgstr "Virallinen sivusto:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Valvonta" - -msgid "Partition" -msgstr "Osio" - -msgid "Password" -msgstr "Salasana" - -msgid "Password Changed" -msgstr "Salasana muutettu" - -msgid "Password has been changed" -msgstr "Salasana on muutettu" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Liitä se nettiselaimeesi saadaksesi WiiTDB.zip" - -msgid "Patch Country Strings" -msgstr "Patchaa maa merkkijonot" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Valitse listasta" - -msgid "Play Count" -msgstr "Pelauksen määrä" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "" - -msgid "Power off the Wii" -msgstr "Sammuta Wii" - -msgid "Prompts Buttons" -msgstr "Napit" - -msgid "Published by" -msgstr "Julkaisu:" - -msgid "Quick Boot" -msgstr "" - -msgid "Reading WAD data... Ok!" -msgstr "Luetaan WAD:ia... Ok!" - -msgid "Receiving file from:" -msgstr "Ladataan tiedostoa:" - -msgid "Released" -msgstr "Julkaistu" - -msgid "Reload SD" -msgstr "Uudelleenlataa SD" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "Uudelleennimeä peli" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Resetoi pelauksen määrä" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Boottaa..." - -msgid "Return" -msgstr "Palaa" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Palaa Wii menuun" - -msgid "Rumble" -msgstr "Värinä" - -msgid "SFX Volume" -msgstr "Ääniefektien voimakkuus" - -msgid "Save" -msgstr "Tallenna" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "" - -msgid "Saved" -msgstr "" - -msgid "Screensaver" -msgstr "Näytönsäästäjä" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Valitse DOL" - -msgid "Sept" -msgstr "syys" - -msgid "Set Search-Filter" -msgstr "" - -msgid "Settings" -msgstr "Asetukset" - -msgid "Shutdown System" -msgstr "Sammuta järjestelmä" - -msgid "Shutdown to Idle" -msgstr "Valmiustila" - -msgid "Sort alphabetically" -msgstr "Järjestä aakkosittain" - -msgid "Sort by rank" -msgstr "" - -msgid "Sort order by most played" -msgstr "Aseta 'pelattu eniten' järjestykseen" - -msgid "Sound" -msgstr "Ääni" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Erityiskiitokset" - -msgid "Success" -msgstr "Onnistui" - -msgid "Success:" -msgstr "Onnistui:" - -msgid "Successfully Saved" -msgstr "Tallennettu onnistuneesti" - -msgid "Successfully Updated" -msgstr "Päivitetty onnistuneesti" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Poistettu onnistuneesti:" - -msgid "Successfully extracted theme." -msgstr "" - -msgid "Successfully installed:" -msgstr "Asennettu onnistuneesti:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT koodien polku" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "" - -msgid "Theme Downloader" -msgstr "" - -msgid "Theme Path" -msgstr "Teeman sijainti" - -msgid "Theme Title:" -msgstr "" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Aikaa jäljellä:" - -msgid "Title Launcher" -msgstr "Nimilaukaisin" - -msgid "Titles from WiiTDB" -msgstr "Nimet WiiTDB:stä" - -msgid "Tooltips" -msgstr "Vinkit" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB-laitetta ei löytynyt" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX on suojattu." - -msgid "Uninstall" -msgstr "Poista" - -msgid "Uninstall Game" -msgstr "Poista peli" - -msgid "Uninstall Menu" -msgstr "Poistomenu" - -msgid "Uninstalling wad" -msgstr "Poistetaan wad:ia" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Avaa konsoli käyttääksesi tätä vaihtoehtoa" - -msgid "Unsupported format, try to extract manually." -msgstr "" - -msgid "Update" -msgstr "Päivitä" - -msgid "Update All" -msgstr "Päivitä kaikki" - -msgid "Update DOL" -msgstr "Päivitä DOL" - -msgid "Update Files" -msgstr "Päivitä tiedostot" - -msgid "Update Path" -msgstr "Päivityspolku" - -msgid "Update all Language Files" -msgstr "Päivitä kaikki kielitiedostot" - -msgid "Update failed" -msgstr "Päivitys epäonnistui" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Päivittää kielitiedostoja:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "" - -msgid "VIDTV Patch" -msgstr "VIDTV korjaus" - -#, c-format -msgid "Version: %s" -msgstr "Versio: %s" - -msgid "Video Mode" -msgstr "Videotila" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "Odottaa USB-laitetta..." - -msgid "Waiting..." -msgstr "Odottaa..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Mitä haluat päivittää?" - -msgid "WiFi Features" -msgstr "WiFi ominaisuudet" - -msgid "Wii Menu" -msgstr "Wii Menu" - -msgid "Wii Settings" -msgstr "Wii asetukset" - -msgid "WiiTDB Files" -msgstr "WiiTDB tiedostot" - -msgid "WiiTDB Path" -msgstr "WiiTDB polku" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "" - -msgid "Wrong Password" -msgstr "Väärä salasana" - -msgid "Yes" -msgstr "Kyllä" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "URL:si on tallennettu %WiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "" - -msgid "available" -msgstr "Saatavilla" - -msgid "does not exist!" -msgstr "Ei löydy!" - -msgid "does not exist! Loading game without cheats." -msgstr "Ei löydy! Ladataan peli ilman koodeja." - -msgid "files left" -msgstr "Tiedostoja jäljellä" - -msgid "files not found on the server!" -msgstr "tiedostoja ei löytynyt serveriltä!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "WiiTDB:stä ja kansien hostauksesta" - -msgid "for diverse patches" -msgstr "Erinäisistä patcheista" - -msgid "for his awesome tool LibWiiGui" -msgstr "Hänen hienosta ohjelmasta LibWiiGui" - -msgid "for hosting the themes" -msgstr "" - -msgid "for hosting the update files" -msgstr "Tiedostojen hostauksesta" - -msgid "for the USB Loader source" -msgstr "lähdekoodin julkaisemisesta" - -msgid "formatted!" -msgstr "formatoitu!" - -msgid "free" -msgstr "vapaana" - -msgid "not set" -msgstr "ei asetettu" - -msgid "of" -msgstr "josta" - -msgid "seconds left" -msgstr "sekuntia jäljellä" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Kaikille)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Lapset 7+)" - -#~ msgid "1 hour" -#~ msgstr " 1 tunti" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Teinit 12+)" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Teinit 16+)" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (K18)" - -#~ msgid "An Error occured" -#~ msgstr "Tapahtui virhe" - -#~ msgid "Both" -#~ msgstr "Molemmat" - -#~ msgid "Checking for Updates" -#~ msgstr "Tarkastetaan päivityksiä" - -#~ msgid "Console Default" -#~ msgstr "Konsolin oletus" - -#~ msgid "Customs/Original" -#~ msgstr "Omat/Alkuperäiset" - -#~ msgid "Disc Default" -#~ msgstr "Pelin oletus" - -#~ msgid "DiskFlip" -#~ msgstr "Levynvaihto" - -#~ msgid "Downloading" -#~ msgstr "Lataa" - -#~ msgid "Dutch" -#~ msgstr "Hollanti" - -#~ msgid "English" -#~ msgstr "Englanti" - -#~ msgid "French" -#~ msgstr "Ranska" - -#~ msgid "Game ID" -#~ msgstr "Peli ID" - -#~ msgid "Game Region" -#~ msgstr "Alue" - -#~ msgid "German" -#~ msgstr "Saksa" - -#~ msgid "Italian" -#~ msgstr "Italia" - -#~ msgid "Japanese" -#~ msgstr "Japani" - -#~ msgid "Korean" -#~ msgstr "Korea" - -#~ msgid "Left" -#~ msgstr "Vasen" - -#~ msgid "Like SysMenu" -#~ msgstr "Kuin wii-menu" - -#~ msgid "Load From SD/USB" -#~ msgstr "Lataa SD:ltä/USB:ltä" - -#~ msgid "Locked" -#~ msgstr "Lukittu" - -#~ msgid "Neither" -#~ msgstr "Ei kumpikaan" - -#~ msgid "Next" -#~ msgstr "Seuraava" - -#~ msgid "Normal" -#~ msgstr "Normaali" - -#~ msgid "ON" -#~ msgstr "Päälle" - -#~ msgid "Only Customs" -#~ msgstr "Vain omatekoiset" - -#~ msgid "Only Original" -#~ msgstr "Vain alkuperäinen" - -#~ msgid "Only for Install" -#~ msgstr "Ainoastaan asennusta varten" - -#~ msgid "Original/Customs" -#~ msgstr "Alkuperäinen/Omatekoinen" - -#~ msgid "Prev" -#~ msgstr "Edellinen" - -#~ msgid "Right" -#~ msgstr "Oikea" - -#~ msgid "SChinese" -#~ msgstr "SKiina" - -#~ msgid "Spanish" -#~ msgstr "Espanja" - -#~ msgid "System Default" -#~ msgstr "Wiin oletus" - -#~ msgid "TChinese" -#~ msgstr "TKiina" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Wad tiedostoa ei asennettu mutta sitä ei voitu tuhota SD-kortilta" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Wad asennus epäonnistui: %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Wadia (%s) jonka juuri latasit ei voitu avata." - -#~ msgid "Unlocked" -#~ msgstr "Avattu" - -#~ msgid "Update to" -#~ msgstr "Päivitä:" - -#~ msgid "Updating" -#~ msgstr "Päivittää" - -#~ msgid "Updating Language Files..." -#~ msgstr "Päivittää kielitiedostoja..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Päivittää WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Laajakuva korjaus" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Takaisin Wii Menuun" - -#~ msgid "Checking existing artwork" -#~ msgstr "Tutkitaan olemassa olevia kansia" - -#~ msgid "Confirm" -#~ msgstr "Varmista" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "WBFS osiota ei löytynyt." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "WBFS osiota ei voitu avata" - -#~ msgid "Could not read the disc." -#~ msgstr "Levyä ei voitu lukea" - -#~ msgid "Could not set USB." -#~ msgstr "USB:tä ei voitu asettaa" - -#~ msgid "Cover Path Changed" -#~ msgstr "Kansien polku muutettu" - -#~ msgid "DOL path changed" -#~ msgstr "DOL:in polku muutettu" - -#~ msgid "Disc Path Changed" -#~ msgstr "Levykuvien polku muutettu" - -#~ msgid "Display favorites" -#~ msgstr "Näytä suosikit" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Haluatko odottaa 30 sekuntia?" - -#~ msgid "Force" -#~ msgstr "Pakota" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "GCT Koodien polku muutettu" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Homebrew Apps polku vaihdettu" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Aseta SD-kortti ladataksesi kansia." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Todennäköisesti sisältää ulottuvuuksia jotka eivät ole jaollisia neljällä" - -#~ msgid "Network init error" -#~ msgstr "Verkon alustusvirhe" - -#~ msgid "No .dol or .elf files found." -#~ msgstr ".dol tai .elf tiedostoja ei löydy" - -#~ msgid "No Favorites" -#~ msgstr "Ei suosikkeja" - -#~ msgid "No USB Device" -#~ msgstr "Ei USB-laitetta" - -#~ msgid "No USB Device found." -#~ msgstr "USB-laitetta ei löytynyt." - -#~ msgid "Normal Covers" -#~ msgstr "Normaalit kannet" - -#~ msgid "Not Found" -#~ msgstr "Ei löytynyt" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Tiedosto ei ole DOL/ELF." - -#~ msgid "Save Failed" -#~ msgstr "Tallennus ei onnistunut" - -#~ msgid "Selected DOL" -#~ msgstr "Valittu DOL" - -#~ msgid "Standard" -#~ msgstr "Standardi" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXT koodien polku muutettu" - -#~ msgid "Theme Path Changed" -#~ msgstr "Teeman sijainti muutettu" - -#~ msgid "Update Path changed." -#~ msgstr "Päivityspolku muutettu" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB polku muutettu" - -#~ msgid "You are about to delete " -#~ msgstr "Olet tuhoamassa " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Olet valinnut näyttääksesi suosikit mutta sinulla ei ole valittuna yhtään." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Yritit ladata huonoa levykuvaa" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "Ei löydy! Kusit jotain, Typerys!" - -#~ msgid "file left" -#~ msgstr "Tiedosto jäljellä" diff --git a/Languages/french.lang b/Languages/french.lang deleted file mode 100644 index 06cbe4c4..00000000 --- a/Languages/french.lang +++ /dev/null @@ -1,1555 +0,0 @@ -# USB Loader GX language source file. -# French V13.1 r931 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: Kin8\n" -"Language-Team: Badablek, Amour, ikya & Kin8\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "WAD Sauvegardé sous:" - -msgid " could not be downloaded." -msgstr " ne peut pas être téléchargé." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " sauvegardé. Certains codes ne peuvent fonctionner conjointement. En cas de mauvais résultats, ouvrez-le avec un réel éditeur de texte pour obtenir plus d'informations." - -msgid " is not on the server." -msgstr " indisponible sur le serveur." - -msgid "2D Cover Path" -msgstr "Dossier Jaquettes 2D" - -msgid "3D Cover Path" -msgstr "Dossier Jaquettes 3D" - -msgid "3D Covers" -msgstr "Jaquettes 3D" - -msgid ">> Deleting tickets..." -msgstr ">> Suppression tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Suppression tickets...ERREUR!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Suppression tickets...OK!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Suppression titre...ERREUR!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> Suppression titre...OK!" - -msgid ">> Deleting title contents..." -msgstr ">> Suppression contenus titre..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Suppression contenus titre...ERREUR!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Suppression contenus titre...OK!" - -msgid ">> Deleting title..." -msgstr ">> Suppression titre..." - -msgid ">> Finishing installation..." -msgstr ">> Finalisation de l'installation..." - -msgid ">> Installing content #" -msgstr ">> Installation contenu #" - -msgid ">> Installing ticket..." -msgstr ">> Installation ticket..." - -msgid ">> Installing title..." -msgstr ">> Installation titre..." - -msgid ">> Reading WAD data..." -msgstr ">> Lecture données WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Lecture données WAD...ERREUR!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Lecture données WAD...OK!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Toutes partitions" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Toutes les fonctionnalités sont déverrouillées." - -msgid "Alternate DOL" -msgstr "DOL Alternatif" - -msgid "App Language" -msgstr "Langue d'interface" - -msgid "Apr" -msgstr "Avr" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Êtes-vous sûr ?" - -msgid "Aug" -msgstr "Août" - -msgid "Author:" -msgstr "Auteur:" - -msgid "AutoInit Network" -msgstr "AutoInit Réseau" - -msgid "BCA Codes Path" -msgstr "Dossier Codes BCA" - -msgid "BETA revisions" -msgstr "Révisions BETA" - -msgid "Back" -msgstr "Retour" - -msgid "Back to HBC or Wii Menu" -msgstr "Retour HBC / Menu Wii" - -msgid "Back to Loader" -msgstr "Chaîne Homebrew" - -msgid "Backgroundmusic" -msgstr "Fond sonore" - -msgid "Big thanks to:" -msgstr "Grand merci à:" - -msgid "Block IOS Reload" -msgstr "Bloquer IOS Reload" - -msgid "Boot/Standard" -msgstr "" - -msgid "Boot?" -msgstr "Lancer ?" - -msgid "Can't be formatted" -msgstr "Formatage impossible" - -msgid "Can't create directory" -msgstr "Création du répertoire impossible" - -msgid "Can't create file" -msgstr "Création du fichier impossible" - -msgid "Can't delete:" -msgstr "Impossible de supprimer:" - -msgid "Cancel" -msgstr "Annuler" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Changer Dossier" - -msgid "Cheatfile is blank" -msgstr "Fichier de triche vide" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Téléchargement des jaquettes" - -msgid "Click to change game ID" -msgstr "Changer l'ID du Jeu" - -msgid "Clock" -msgstr "Horloge" - -msgid "Close" -msgstr "Fermer" - -msgid "Code Download" -msgstr "Téléchargement Codes" - -#, c-format -msgid "Coded by: %s" -msgstr "Développé par: %s" - -msgid "Coding:" -msgstr "Développement:" - -msgid "Connection lost..." -msgstr "Connexion perdue..." - -msgid "Console" -msgstr "" - -msgid "Console Locked" -msgstr "Console verrouillée" - -msgid "Console should be unlocked to modify it." -msgstr "La console doit être déverrouillée." - -msgid "Continue to install game?" -msgstr "Continuer l'installation ?" - -msgid "Controllevel" -msgstr "Niveau moral" - -msgid "Correct Password" -msgstr "Mot de passe correct" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Impossible de créer le fichier GCT" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Initialisation module DIP impossible !" - -msgid "Could not initialize network!" -msgstr "Initialisation réseau impossible !" - -msgid "Could not open Disc" -msgstr "Ouverture DVD impossible" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Sauvegarde impossible" - -msgid "Cover Download" -msgstr "Téléchargement Jaquettes" - -msgid "Create" -msgstr "Créer" - -msgid "Credits" -msgstr "Crédits" - -msgid "Custom Paths" -msgstr "Personnalisation Dossiers" - -msgid "DOL Path" -msgstr "Dossier DOL Alternatif" - -msgid "Dec" -msgstr "Déc" - -msgid "Default" -msgstr "Par défaut" - -msgid "Default Gamesettings" -msgstr "Reset Paramètres Jeu" - -msgid "Default Settings" -msgstr "Reset Paramètres" - -msgid "Delete" -msgstr "Supprimer" - -msgid "Delete ?" -msgstr "Supprimer ?" - -msgid "Delete Cheat GCT" -msgstr "Supprimer GCT de Triche" - -msgid "Delete Cheat TXT" -msgstr "Supprimer TXT de Triche" - -msgid "Delete Cover Artwork" -msgstr "Supprimer la Jaquette" - -msgid "Delete Disc Artwork" -msgstr "Supprimer le Label DVD" - -msgid "Design:" -msgstr "Graphisme:" - -msgid "Developed by" -msgstr "Développé par" - -msgid "Directory does not exist!" -msgstr "Répertoire inexistant!" - -msgid "Disc Artwork Download" -msgstr "Téléch. Labels DVD" - -msgid "Disc Artwork Path" -msgstr "Dossier Labels DVD" - -msgid "Disc Images" -msgstr "Labels DVD" - -msgid "Display" -msgstr "Affichage" - -msgid "Display as a carousel" -msgstr "Carousselle" - -msgid "Display as a grid" -msgstr "Grille" - -msgid "Display as a list" -msgstr "Liste" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Voulez-vous vraiment supprimer ?" - -msgid "Do you want to apply it now?" -msgstr "L'appliquer maintenant ?" - -msgid "Do you want to change language?" -msgstr "Changer de langue ?" - -msgid "Do you want to download this theme?" -msgstr "Voulez-vous télécharger ce thème ?" - -msgid "Do you want to format:" -msgstr "Voulez-vous formater ?" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Voulez-vous utiliser le DOL Alternatif actuellement connu comme correct ?" - -msgid "Do you wish to update/download all language files?" -msgstr "Voulez-vous actualiser/télécharger tous les fichiers langue ?" - -msgid "Done!" -msgstr "Terminé!" - -msgid "Download" -msgstr "Télécharger" - -msgid "Download Boxart image?" -msgstr "Télécharger les jaquettes ?" - -msgid "Download Discart image?" -msgstr "Télécharger labels DVD ?" - -msgid "Download Now" -msgstr "Télécharger" - -msgid "Download failed." -msgstr "Téléchargement échoué." - -msgid "Download finished" -msgstr "Téléchargement terminé" - -msgid "Download request failed." -msgstr "Demande de téléchargement échouée" - -msgid "Downloading Page List:" -msgstr "Chargement Prévisualisations:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Téléchargement du fichier" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Téléchargement de l'image:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "ERREUR" - -msgid "ERROR:" -msgstr "ERREUR:" - -msgid "ERROR: Can't set up theme." -msgstr "ERREUR: Configuration thème impossible." - -msgid "Error" -msgstr "Erreur" - -msgid "Error !" -msgstr "Erreur !" - -msgid "Error 002 fix" -msgstr "Correctif Erreur 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Erreur à la lecture du disque" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Erreur durant le transfert de données." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Erreur..." - -msgid "Error:" -msgstr "Erreur:" - -msgid "Extracting files..." -msgstr "Extraction des fichiers..." - -msgid "FAT: Use directories" -msgstr "FAT: Utiliser dossiers" - -msgid "Failed formating" -msgstr "Échec du formatage" - -msgid "Failed to extract." -msgstr "Extraction échouée." - -msgid "Failed to open partition" -msgstr "Échec accès partition" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Fév" - -msgid "File not found." -msgstr "Fichier introuvable." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Finalisation de l'installation... OK!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Inversion-X" - -msgid "Format" -msgstr "Formater" - -msgid "Formatting, please wait..." -msgstr "Formatage en cours, veuillez patienter..." - -msgid "Free Space" -msgstr "Espace restant" - -msgid "Full Shutdown" -msgstr "Éteindre" - -msgid "GCT Cheatcodes Path" -msgstr "Dossier GCT de Triche" - -msgid "GCT File created" -msgstr "Fichier GCT créé" - -msgid "GUI Settings" -msgstr "Configuration GUI" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg non trouvé dans aucun sous-dossier." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Langue du jeu" - -msgid "Game Load" -msgstr "Chargement Jeux" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Taille du jeu" - -msgid "Game Sound Mode" -msgstr "Mode Son des Jeux" - -msgid "Game Sound Volume" -msgstr "Volume Son des Jeux" - -msgid "Game is already installed:" -msgstr "Le jeu est déjà installé:" - -msgid "Game partition" -msgstr "Partition Jeu" - -msgid "Games" -msgstr "Jeux" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Menu HOME" - -msgid "Homebrew Apps Path" -msgstr "Dossier Homebrew Apps" - -msgid "Homebrew Launcher" -msgstr "Menu Homebrew" - -msgid "Hour" -msgstr "heures" - -msgid "How do you want to update?" -msgstr "Comment faire la Mise à Jour ?" - -msgid "How to Shutdown?" -msgstr "Arrêt de la Wii ?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Pressez 1 pour obtenir un lien personnalisé pour votre WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Fichier entrant %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Fichier entrant %0.2fMB" - -msgid "Initializing Network" -msgstr "Initialisation du réseau" - -msgid "Insert Disk" -msgstr "Insérez un disque" - -msgid "Insert a Wii Disc!" -msgstr "Insérez un disque Wii !" - -msgid "Insert an SD-Card to save." -msgstr "Insérez une carte SD pour enregistrer." - -msgid "Insert an SD-Card to use this option." -msgstr "Insérez une carte SD pour utiliser cette option." - -msgid "Install" -msgstr "Installer" - -msgid "Install Error!" -msgstr "Erreur à l'installation !" - -msgid "Install a game" -msgstr "Installer un jeu" - -msgid "Install partitions" -msgstr "Installation" - -msgid "Installing content... Ok!" -msgstr "Installation contenu... OK!" - -msgid "Installing game:" -msgstr "Installation du jeu:" - -msgid "Installing ticket... Ok!" -msgstr "Installation ticket... OK!" - -msgid "Installing title... Ok!" -msgstr "Installation titre... OK!" - -msgid "Installing wad" -msgstr "Installation WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "SVP, faîtes passer cette information qui serait très utile à la Team USB Loader GX." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Juil" - -msgid "June" -msgstr "Juin" - -msgid "Keep" -msgstr "Garder" - -msgid "Keyboard" -msgstr "Clavier" - -msgid "Language File" -msgstr "Langues" - -msgid "Language change:" -msgstr "Changement Langue:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Dossier Langue changé" - -msgid "Load" -msgstr "Charger" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Charger le fichier de: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Charger comme DOL alternatif ?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Chargement langue par défaut." - -msgid "Loading standard music." -msgstr "Chargement musique standard." - -msgid "Lock Console" -msgstr "Verrouiller la console" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "Mars" - -msgid "Mark new games" -msgstr "Marqueur nouveau jeu" - -msgid "May" -msgstr "Mai" - -msgid "Missing files" -msgstr "Fichier(s) manquant(s)" - -msgid "Mount DVD drive" -msgstr "Lancer DVD" - -msgid "Music Loop Mode" -msgstr "Mode Boucle Musique" - -msgid "Music Volume" -msgstr "Volume Musique" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Nouveau DVD Détecté" - -msgid "No" -msgstr "Non" - -msgid "No Cheatfile found" -msgstr "Aucun fichier de triche trouvé" - -msgid "No DOL file found on disc." -msgstr "Aucun DOL trouvé dans ce jeu." - -msgid "No SD-Card inserted!" -msgstr "Aucune carte SD insérée !" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Aucune selection de triche" - -msgid "No data could be read." -msgstr "Lecture des données impossible." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Aucun fichier manquant !" - -msgid "No new updates." -msgstr "Pas de nouvelle Mise à Jour." - -msgid "No themes found on the site." -msgstr "Aucun thème trouvé sur le site." - -msgid "Not a WAD file." -msgstr "Ce n'est pas un fichier WAD" - -msgid "Not a Wii Disc" -msgstr "Ce n'est pas un jeu Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Mémoire libre insuffisante !" - -msgid "Not enough free space!" -msgstr "Espace libre insuffisant !" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Format non supporté !" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "Inactif" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "" - -msgid "Official Site:" -msgstr "Site Officiel:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Contrôle Parental" - -msgid "Partition" -msgstr "" - -msgid "Password" -msgstr "Mot de passe" - -msgid "Password Changed" -msgstr "Mot de passe modifié" - -msgid "Password has been changed" -msgstr "Le mot de passe a été modifié" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Collez ce lien dans votre navigateur pour télécharger." - -msgid "Patch Country Strings" -msgstr "Patch Jeux Import" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Sélectionner" - -msgid "Play Count" -msgstr "Utilisation" - -msgid "Play Next" -msgstr "Jouer Suiv." - -msgid "Play Previous" -msgstr "Jouer Précéd." - -msgid "Playing Music:" -msgstr "Musique Actuelle:" - -msgid "Please wait..." -msgstr "Veuillez patienter..." - -msgid "Power off the Wii" -msgstr "Éteindre la Wii" - -msgid "Prompts Buttons" -msgstr "Interface" - -msgid "Published by" -msgstr "Publié par" - -msgid "Quick Boot" -msgstr "Démarrage rapide" - -msgid "Reading WAD data... Ok!" -msgstr "Lecture données WAD... OK!" - -msgid "Receiving file from:" -msgstr "Réception du fichier de:" - -msgid "Released" -msgstr "Date de sortie" - -msgid "Reload SD" -msgstr "Recharger la SD" - -msgid "Remove update" -msgstr "Supprimer Mise à Jour" - -msgid "Rename Game on WBFS" -msgstr "Renommer un jeu" - -msgid "Reset BG Music" -msgstr "Reset" - -msgid "Reset Playcounter" -msgstr "Reset Utilisation du Jeu" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Redémarrage..." - -msgid "Return" -msgstr "Retour" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Retourner au menu Wii" - -msgid "Rumble" -msgstr "Vibrations" - -msgid "SFX Volume" -msgstr "Volume SFX" - -msgid "Save" -msgstr "Enregistrer" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Sauvegarder la liste des jeux sous" - -msgid "Saved" -msgstr "Sauvegardé" - -msgid "Screensaver" -msgstr "Économiseur d'écran" - -msgid "Select" -msgstr "Choisir" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Choisir un DOL" - -msgid "Sept" -msgstr "" - -msgid "Set Search-Filter" -msgstr "Filtre de Recherche" - -msgid "Settings" -msgstr "Paramètres" - -msgid "Shutdown System" -msgstr "Arrêt" - -msgid "Shutdown to Idle" -msgstr "Veille" - -msgid "Sort alphabetically" -msgstr "Ordre Alphabétique" - -msgid "Sort by rank" -msgstr "Classement Favoris" - -msgid "Sort order by most played" -msgstr "Les plus joués" - -msgid "Sound" -msgstr "Sons" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Remerciements spéciaux à:" - -msgid "Success" -msgstr "Succès" - -msgid "Success:" -msgstr "Succès:" - -msgid "Successfully Saved" -msgstr "Enregistré avec succès" - -msgid "Successfully Updated" -msgstr "Mise à Jour terminée" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Mise à Jour terminée. Merci www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Supprimé avec succès:" - -msgid "Successfully extracted theme." -msgstr "Succès de l'extraction du thème." - -msgid "Successfully installed:" -msgstr "Installé avec succès:" - -msgid "TXT Cheatcodes Path" -msgstr "Dossier TXT de Triche" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Répertoire indiqué inexistant. Souhaitez-vous le créer ?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Dossier Thèmes Téléch." - -msgid "Theme Downloader" -msgstr "Téléchargements Thèmes" - -msgid "Theme Path" -msgstr "Dossier Thème" - -msgid "Theme Title:" -msgstr "Titre du Thème:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Fini dans:" - -msgid "Title Launcher" -msgstr "Menu Chaînes" - -msgid "Titles from WiiTDB" -msgstr "Titres de WiiTDB" - -msgid "Tooltips" -msgstr "Info-bulles" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Echec Transfert" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "Périphérique USB introuvable" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX est verrouillé" - -msgid "Uninstall" -msgstr "Désinstaller" - -msgid "Uninstall Game" -msgstr "Désinstaller le Jeu" - -msgid "Uninstall Menu" -msgstr "Menu Suppression" - -msgid "Uninstalling wad" -msgstr "Désinstallation wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Cette option requiert le déverrouillage de l'interface." - -msgid "Unsupported format, try to extract manually." -msgstr "Format non supporté, essayez d'extraire manuellement." - -msgid "Update" -msgstr "Mise à Jour" - -msgid "Update All" -msgstr "Totale" - -msgid "Update DOL" -msgstr "DOL seul" - -msgid "Update Files" -msgstr "MàJ Fichiers" - -msgid "Update Path" -msgstr "Dossier Mise à Jour" - -msgid "Update all Language Files" -msgstr "Mise à Jour tous fichiers Langue" - -msgid "Update failed" -msgstr "Mise à Jour échouée" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Mise à Jour Fichiers Langue:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Fichier ZIP envoyé et installé dans le répertoire homebrew." - -msgid "VIDTV Patch" -msgstr "Patch VIDTV" - -#, c-format -msgid "Version: %s" -msgstr "" - -msgid "Video Mode" -msgstr "Mode vidéo" - -msgid "WIP Patches Path" -msgstr "Dossier Patchs WIP" - -msgid "Waiting for USB Device" -msgstr "Attente d'un périphérique USB" - -msgid "Waiting..." -msgstr "En attente..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Choix Mise à Jour" - -msgid "WiFi Features" -msgstr "Connexion WiFi" - -msgid "Wii Menu" -msgstr "Menu Wii" - -msgid "Wii Settings" -msgstr "Paramètres Wii" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "Dossier WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Illumination Wii" - -msgid "Wrong Password" -msgstr "Mot de passe incorrect" - -msgid "Yes" -msgstr "Oui" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Vous devez choisir ou formater une partition" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Sauvegarde de l'URL sous %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "et traducteurs pour les MàJ fichiers langues" - -msgid "available" -msgstr "disponible" - -msgid "does not exist!" -msgstr "inexistant!" - -msgid "does not exist! Loading game without cheats." -msgstr "inexistant! Chargement du jeu sans tricheries." - -msgid "files left" -msgstr "fichiers restants" - -msgid "files not found on the server!" -msgstr "fichiers introuvables sur le serveur !" - -msgid "for FAT/NTFS support" -msgstr "pour le support FAT/NTFS" - -msgid "for Ocarina" -msgstr "pour Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "pour WiiTDB et l'hébergement des jaquettes" - -msgid "for diverse patches" -msgstr "pour les divers patchs" - -msgid "for his awesome tool LibWiiGui" -msgstr "pour son outil impressionnant LibWiiGui" - -msgid "for hosting the themes" -msgstr "pour l'hébergement des thèmes" - -msgid "for hosting the update files" -msgstr "pour l'hébergement des Mises à Jour" - -msgid "for the USB Loader source" -msgstr "pour les sources USBLoader" - -msgid "formatted!" -msgstr "formaté !" - -msgid "free" -msgstr "libre" - -msgid "not set" -msgstr "non défini" - -msgid "of" -msgstr "sur" - -msgid "seconds left" -msgstr "secondes restantes" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Installer Copie 1:1" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Tous 3+)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Enfants 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 heure" - -#~ msgid "10 min" -#~ msgstr "10 min." - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Adolescents 12+)" - -#~ msgid "20 min" -#~ msgstr "20 min." - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Matures 16+)" - -#~ msgid "3 min" -#~ msgstr "3 min." - -#~ msgid "30 min" -#~ msgstr "30 min." - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Adultes 18+)" - -#~ msgid "5 min" -#~ msgstr "5 min." - -#~ msgid "An Error occured" -#~ msgstr "Une Erreur s'est produite" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Confirmation activation du Contrôle Parental ?" - -#~ msgid "Both" -#~ msgstr "Tous" - -#~ msgid "Checking for Updates" -#~ msgstr "Recherche de Mise à Jour" - -#~ msgid "Console Default" -#~ msgstr "Console par défaut" - -#~ msgid "Customs/Original" -#~ msgstr "Persos/Originaux" - -#~ msgid "Disc Default" -#~ msgstr "Disque par défaut" - -#~ msgid "DiskFlip" -#~ msgstr "Inversion Disque" - -#~ msgid "Downloading" -#~ msgstr "Téléchargement" - -#~ msgid "Dutch" -#~ msgstr "Néerlandais" - -#~ msgid "English" -#~ msgstr "Anglais" - -#~ msgid "French" -#~ msgstr "Français" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "IDJEU_NomJeu" - -#~ msgid "Game ID" -#~ msgstr "ID du jeu" - -#~ msgid "Game Region" -#~ msgstr "Région" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "NomJeu [IDJEU]" - -#~ msgid "German" -#~ msgstr "Allemand" - -#~ msgid "Invalid PIN code" -#~ msgstr "Code PIN invalide" - -#~ msgid "Italian" -#~ msgstr "Italien" - -#~ msgid "Japanese" -#~ msgstr "Japonais" - -#~ msgid "Korean" -#~ msgstr "Coréen" - -#~ msgid "Left" -#~ msgstr "Gauche" - -#~ msgid "Like SysMenu" -#~ msgstr "Menu système" - -#~ msgid "Load From SD/USB" -#~ msgstr "Charger sur SD/USB" - -#~ msgid "Locked" -#~ msgstr "Clic pour déverrouiller" - -#~ msgid "Loop Directory" -#~ msgstr "Répéter Dossier" - -#~ msgid "Loop Music" -#~ msgstr "Répéter Musique" - -#~ msgid "Loop Sound" -#~ msgstr "Son en boucle" - -#~ msgid "Neither" -#~ msgstr "Aucun" - -#~ msgid "Next" -#~ msgstr "Suivant" - -#~ msgid "None" -#~ msgstr "Aucun" - -#~ msgid "Normal" -#~ msgstr "4:3" - -#~ msgid "ON" -#~ msgstr "Actif" - -#~ msgid "Only Customs" -#~ msgstr "Personnalisés" - -#~ msgid "Only Original" -#~ msgstr "Originaux" - -#~ msgid "Only for Install" -#~ msgstr "Jeu installé seulement" - -#~ msgid "Original/Customs" -#~ msgstr "Originaux/Persos" - -#~ msgid "Parental Control disabled" -#~ msgstr "Contrôle Parental désactivé" - -#~ msgid "Play Once" -#~ msgstr "Jouer 1 fois" - -#~ msgid "Prev" -#~ msgstr "Précédent" - -#~ msgid "Random Directory Music" -#~ msgstr "Aléatoire" - -#~ msgid "Right" -#~ msgstr "Droite" - -#~ msgid "SChinese" -#~ msgstr "Chinois simplifié" - -#~ msgid "Sound+BGM" -#~ msgstr "Son + Fond sonore" - -#~ msgid "Sound+Quiet" -#~ msgstr "Son + Silence" - -#~ msgid "Spanish" -#~ msgstr "Espagnol" - -#~ msgid "System Default" -#~ msgstr "Système par défaut" - -#~ msgid "TChinese" -#~ msgstr "Chinois traditionnel" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Le Wad a été installé. Mais ne peut être supprimé de la carte SD." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "L'installation WAD a échoué avec erreur %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Ouverture du WAD impossible (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Déverrouiller Contrôle Parental" - -#~ msgid "Unlocked" -#~ msgstr "Clic pour verrouiller" - -#~ msgid "Update to" -#~ msgstr "vers la" - -#~ msgid "Updating" -#~ msgstr "Mise à Jour" - -#~ msgid "Updating Language Files..." -#~ msgstr "Mise à Jour Fichiers Langue..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Mise à Jour WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "16:9" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Contrôle Parental désactivé. Si vous voulez l'utiliser, activez-le dans les Paramètres de votre Wii." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Peut ne pas démarrer correctement si votre Menu Système n'est pas à jour." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Dossier Codes BCA modifié" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Retour Menu Wii" - -#~ msgid "Channels" -#~ msgstr "Chaînes" - -#~ msgid "Checking existing artwork" -#~ msgstr "Contrôle images existantes" - -#~ msgid "Confirm" -#~ msgstr "Confirmer" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Impossible de trouver une partition WBFS." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Ouverture partition WBFS impossible" - -#~ msgid "Could not read the disc." -#~ msgstr "Lecture impossible du DVD." - -#~ msgid "Could not set USB." -#~ msgstr "Accès USB impossible." - -#~ msgid "Cover Path Changed" -#~ msgstr "Dossier des jaquettes modifié" - -#~ msgid "DOL path changed" -#~ msgstr "Dossier DOL alternatif modifié" - -#~ msgid "Disc Path Changed" -#~ msgstr "Dossier des labels DVD modifié" - -#~ msgid "Display favorites" -#~ msgstr "Favoris" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Réessayer pendant 30 sec. ?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Contrôle Parental activé" - -#~ msgid "Force" -#~ msgstr "Forcer" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Dossier GCT de triche modifié" - -#~ msgid "Hermes CIOS" -#~ msgstr "CIOS d'Hermès" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Dossier Homebrew Apps modifié" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Insérez une carte SD pour télécharger les jaquettes." - -#~ msgid "Install not possible" -#~ msgstr "Installation impossible" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Il est fort probable que les dimensions ne soient pas des multiples de 4." - -#~ msgid "Network init error" -#~ msgstr "Erreur d'initialisation réseau" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Aucun fichier .dol ou .elf trouvé." - -#~ msgid "No Favorites" -#~ msgstr "Pas de favoris" - -#~ msgid "No USB Device" -#~ msgstr "Aucun périphérique USB" - -#~ msgid "No USB Device found." -#~ msgstr "Aucun périphérique USB trouvé." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Partition WBFS/FAT/NTFS introuvable" - -#~ msgid "Normal Covers" -#~ msgstr "Jaquettes 2D" - -#~ msgid "Not Found" -#~ msgstr "Non trouvé" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Ce n'est pas un fichier DOL/ELF" - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Restaurer fond sonore standard ?" - -#~ msgid "Save Failed" -#~ msgstr "Échec de sauvegarde" - -#~ msgid "Selected DOL" -#~ msgstr "Choix du DOL" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Dossier TXT de Triche modifié" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Dossier Thèmes Téléch. modifié" - -#~ msgid "Theme Path Changed" -#~ msgstr "Dossier du thème modifié" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX fonctionne avec le CIOS d'Hermès rev4 seulement! Assurez-vous qu'il soit installé!" - -#~ msgid "Update Path changed." -#~ msgstr "Dossier de Mise à Jour modifié." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Dossier Patchs WIP modifié" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Dossier de WiiTDB modifié" - -#~ msgid "You are about to delete " -#~ msgstr "Vous êtes sur le point de supprimer " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Vous choisissez d'afficher des favoris alors que vous n'en avez aucun." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Le système de fichier NTFS est utilisé. En raison à de possibles erreurs d'écriture sur une partition de NTFS, l'installation d'un jeu est impossible." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Vous avez tenté de charger une image érronée" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "Inexistant! Quelque chose vous a échappé!" - -#~ msgid "file left" -#~ msgstr "fichier restant" diff --git a/Languages/german.lang b/Languages/german.lang deleted file mode 100644 index a97ca3b8..00000000 --- a/Languages/german.lang +++ /dev/null @@ -1,1555 +0,0 @@ -# USB Loader GX language source file. -# german.lang - r931 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: ZEN.13\n" -"Language-Team: Snoozer, wishmasterf, Bertilax, ZEN.13\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " WAD gespeichert als:" - -msgid " could not be downloaded." -msgstr " konnte nicht heruntergeladen werden." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " wurde gespeichert. Möglicherweise funktionieren einige der Codes nicht richtig miteinander. Wenn du Probleme hast, öffne den Text in einem Texteditor um mehr Informationen zu erhalten." - -msgid " is not on the server." -msgstr " ist nicht auf dem Server." - -msgid "2D Cover Path" -msgstr "2D Cover" - -msgid "3D Cover Path" -msgstr "3D Cover" - -msgid "3D Covers" -msgstr "3D Cover" - -msgid ">> Deleting tickets..." -msgstr ">> Lösche Tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Lösche Tickets...FEHLER! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Lösche Tickets...OK! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Lösche Title...FEHLER! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Lösche Title...OK! " - -msgid ">> Deleting title contents..." -msgstr ">> Lösche Title Inhalte..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Lösche Title Inhalte...FEHLER! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Lösche Title Inhalte...OK!" - -msgid ">> Deleting title..." -msgstr ">> Lösche Title..." - -msgid ">> Finishing installation..." -msgstr ">> Beende Installation..." - -msgid ">> Installing content #" -msgstr ">> Installiere Inhalt #" - -msgid ">> Installing ticket..." -msgstr ">> Installiere Ticket..." - -msgid ">> Installing title..." -msgstr ">> Installiere Title..." - -msgid ">> Reading WAD data..." -msgstr ">> Lese WAD Daten..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Lese WAD Daten...FEHLER! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Lese WAD Daten...OK!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Alle Partitionen" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Alle Funktionen des USB Loader GX sind jetzt freigeschaltet." - -msgid "Alternate DOL" -msgstr "Alternative DOL" - -msgid "App Language" -msgstr "Sprache" - -msgid "Apr" -msgstr "April" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Bist du sicher?" - -msgid "Aug" -msgstr "August" - -msgid "Author:" -msgstr "Autor:" - -msgid "AutoInit Network" -msgstr "AutoInit Netzwerk" - -msgid "BCA Codes Path" -msgstr "BCA Codes" - -msgid "BETA revisions" -msgstr "BETA Revisionen" - -msgid "Back" -msgstr "Zurück" - -msgid "Back to HBC or Wii Menu" -msgstr "Zurück zum Homebrew Kanal oder Wii Menü" - -msgid "Back to Loader" -msgstr "Homebrew Kanal" - -msgid "Backgroundmusic" -msgstr "Hintergrundmusik" - -msgid "Big thanks to:" -msgstr "Großen Dank an:" - -msgid "Block IOS Reload" -msgstr "IOS Reload blocken" - -msgid "Boot/Standard" -msgstr "Bootstandard (cIOS)" - -msgid "Boot?" -msgstr "Kanal starten?" - -msgid "Can't be formatted" -msgstr "Kann nicht formatiert werden." - -msgid "Can't create directory" -msgstr "Verzeichnis kann nicht erstellt werden." - -msgid "Can't create file" -msgstr "Datei kann nicht erstellt werden." - -msgid "Can't delete:" -msgstr "Löschen fehlgeschlagen:" - -msgid "Cancel" -msgstr "Abbrechen" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Pfad ändern" - -msgid "Cheatfile is blank" -msgstr "Cheatdatei ist leer" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Cover herunterladen" - -msgid "Click to change game ID" -msgstr "Spiel ID ändern" - -msgid "Clock" -msgstr "Uhrformat" - -msgid "Close" -msgstr " Schließen" - -msgid "Code Download" -msgstr "Cheatcodes werden heruntergeladen" - -#, c-format -msgid "Coded by: %s" -msgstr "Programmiert von: %s" - -msgid "Coding:" -msgstr "Programmierung:" - -msgid "Connection lost..." -msgstr "Verbindung abgebrochen..." - -msgid "Console" -msgstr "Konsolenstatus" - -msgid "Console Locked" -msgstr "Konsole gesperrt" - -msgid "Console should be unlocked to modify it." -msgstr "Konsole muss zum Bearbeiten entsperrt werden." - -msgid "Continue to install game?" -msgstr "Fortfahren um Spiel zu installieren?" - -msgid "Controllevel" -msgstr "Alterseinstufung" - -msgid "Correct Password" -msgstr "Richtiges Passwort" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "GCT Datei konnte nicht erstellt werden." - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "DIP Modul konnte nicht initialisiert werden!" - -msgid "Could not initialize network!" -msgstr "Netzwerk konnte nicht initialisiert werden!" - -msgid "Could not open Disc" -msgstr "Disc konnte nicht geöffnet werden." - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Es konnte nicht gespeichert werden." - -msgid "Cover Download" -msgstr "Welche Cover herunterladen?" - -msgid "Create" -msgstr "Erstelle GCT" - -msgid "Credits" -msgstr "" - -msgid "Custom Paths" -msgstr "Pfade anpassen" - -msgid "DOL Path" -msgstr "Alternative DOL" - -msgid "Dec" -msgstr "Dezember" - -msgid "Default" -msgstr "Standard" - -msgid "Default Gamesettings" -msgstr "Spieleinstellungen zurücksetzen" - -msgid "Default Settings" -msgstr "Einstellungen zurücksetzen" - -msgid "Delete" -msgstr "Löschen" - -msgid "Delete ?" -msgstr "Wirklich löschen?" - -msgid "Delete Cheat GCT" -msgstr "Lösche GCT Cheatdatei" - -msgid "Delete Cheat TXT" -msgstr "Lösche TXT Cheatdatei" - -msgid "Delete Cover Artwork" -msgstr "Lösche Cover" - -msgid "Delete Disc Artwork" -msgstr "Lösche Disc Cover" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "Entwickelt von" - -msgid "Directory does not exist!" -msgstr "Verzeichnis existiert nicht!" - -msgid "Disc Artwork Download" -msgstr "Disc Cover Download" - -msgid "Disc Artwork Path" -msgstr "Disc Cover" - -msgid "Disc Images" -msgstr "Disc Cover" - -msgid "Display" -msgstr "Spielinfos anzeigen" - -msgid "Display as a carousel" -msgstr "Karussell-Ansicht" - -msgid "Display as a grid" -msgstr "Grid-Ansicht" - -msgid "Display as a list" -msgstr "Listen-Ansicht" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Löschvorgang bestätigen:" - -msgid "Do you want to apply it now?" -msgstr "Jetzt übernehmen?" - -msgid "Do you want to change language?" -msgstr "Sprache ändern?" - -msgid "Do you want to download this theme?" -msgstr "Dieses Theme herunterladen?" - -msgid "Do you want to format:" -msgstr "Formatieren:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Die bekannte Alternative DOL verwenden?" - -msgid "Do you wish to update/download all language files?" -msgstr "Alle Sprachdateien aktualisieren?" - -msgid "Done!" -msgstr "Fertig!" - -msgid "Download" -msgstr "Herunterladen" - -msgid "Download Boxart image?" -msgstr "Cover herunterladen?" - -msgid "Download Discart image?" -msgstr "Disc Cover herunterladen?" - -msgid "Download Now" -msgstr "Herunterladen" - -msgid "Download failed." -msgstr "Download fehlgeschlagen" - -msgid "Download finished" -msgstr "Download abgeschlossen" - -msgid "Download request failed." -msgstr "Downloadanfrage fehlgeschlagen" - -msgid "Downloading Page List:" -msgstr "Liste der nächsten Seite wird geladen:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Theme wird heruntergeladen" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Weitere Vorschaubilder werden geladen:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "FEHLER" - -msgid "ERROR:" -msgstr "FEHLER:" - -msgid "ERROR: Can't set up theme." -msgstr "FEHLER: Theme kann nicht konfiguriert werden." - -msgid "Error" -msgstr "Fehler" - -msgid "Error !" -msgstr "Fehler !" - -msgid "Error 002 fix" -msgstr "ERROR #002 beheben" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Fehler beim Lesen der Disc" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Fehler während der Datenübertragung." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Fehler..." - -msgid "Error:" -msgstr "Fehler:" - -msgid "Extracting files..." -msgstr "Entpacke Dateien..." - -msgid "FAT: Use directories" -msgstr "FAT: Unterverzeichnise" - -msgid "Failed formating" -msgstr "Formatieren fehlgeschlagen" - -msgid "Failed to extract." -msgstr "Entpacken fehlgeschlagen." - -msgid "Failed to open partition" -msgstr "Öffnen der Partition fehlgeschlagen" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Februar" - -msgid "File not found." -msgstr "Datei nicht gefunden" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Beende Installation... OK!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "" - -msgid "Format" -msgstr "Formatieren" - -msgid "Formatting, please wait..." -msgstr "Formatiere, bitte warten..." - -msgid "Free Space" -msgstr "Freier Speicher" - -msgid "Full Shutdown" -msgstr "WiiConnect24 aus" - -msgid "GCT Cheatcodes Path" -msgstr "GCT Cheatdateien" - -msgid "GCT File created" -msgstr "GCT Datei erstellt" - -msgid "GUI Settings" -msgstr "GUI Einstellungen" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg in keinem Unterordner gefunden." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Sprache" - -msgid "Game Load" -msgstr "Spieleinstellungen" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Größe" - -msgid "Game Sound Mode" -msgstr "Banner Modus" - -msgid "Game Sound Volume" -msgstr "Banner Lautstärke" - -msgid "Game is already installed:" -msgstr "Spiel ist bereits installiert:" - -msgid "Game partition" -msgstr "Spielpartition" - -msgid "Games" -msgstr "Spiele" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "HOME Menü" - -msgid "Homebrew Apps Path" -msgstr "Homebrew Apps" - -msgid "Homebrew Launcher" -msgstr "" - -msgid "Hour" -msgstr "Stunden" - -msgid "How do you want to update?" -msgstr "Was soll aktualisiert werden?" - -msgid "How to Shutdown?" -msgstr "Wie soll ausgeschaltet werden?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Wenn du kein WiFi hast, drücke 1 um eine URL zu generieren." - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Eingehende Datei %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Eingehende Datei %0.2fMB" - -msgid "Initializing Network" -msgstr "Initialisiere Netzwerk" - -msgid "Insert Disk" -msgstr "Disc einlegen" - -msgid "Insert a Wii Disc!" -msgstr "Eine Wii Disc einlegen!" - -msgid "Insert an SD-Card to save." -msgstr "SD Karte einlegen um zu Speichern." - -msgid "Insert an SD-Card to use this option." -msgstr "SD Karte einlegen um diese Option zu nutzen." - -msgid "Install" -msgstr "Installieren" - -msgid "Install Error!" -msgstr "Installationsfehler!" - -msgid "Install a game" -msgstr "Spiel installieren" - -msgid "Install partitions" -msgstr "Partitionen installieren" - -msgid "Installing content... Ok!" -msgstr "Installiere Inhalt... OK!" - -msgid "Installing game:" -msgstr "Installiere Spiel:" - -msgid "Installing ticket... Ok!" -msgstr "Installiere Ticket... OK!" - -msgid "Installing title... Ok!" -msgstr "Installiere Title... OK!" - -msgid "Installing wad" -msgstr "Installiere WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Es scheint als ob du Informationen hast, die hilfreich für uns sein könnten. Bitte sende diese Information ans DEV Team." - -msgid "Jan" -msgstr "Januar" - -msgid "July" -msgstr "Juli" - -msgid "June" -msgstr "Juni" - -msgid "Keep" -msgstr "Behalten" - -msgid "Keyboard" -msgstr "Tastatur" - -msgid "Language File" -msgstr "Sprachdatei" - -msgid "Language change:" -msgstr "Sprache ändern:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Pfad geändert" - -msgid "Load" -msgstr "Laden" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Datei von %s laden?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Diese DOL als Alternative DOL laden?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Lade Standardsprache." - -msgid "Loading standard music." -msgstr "Lade Standardmusik." - -msgid "Lock Console" -msgstr "Konsole sperren" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "März" - -msgid "Mark new games" -msgstr "Neue Spiele markieren" - -msgid "May" -msgstr "Mai" - -msgid "Missing files" -msgstr "Fehlende Dateien" - -msgid "Mount DVD drive" -msgstr "Spiel starten" - -msgid "Music Loop Mode" -msgstr "HGM Wiederholung" - -msgid "Music Volume" -msgstr "Musik Lautstärke" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Neu Disc im Laufwerk festgestellt" - -msgid "No" -msgstr "Nein" - -msgid "No Cheatfile found" -msgstr "Keine Cheatdatei gefunden." - -msgid "No DOL file found on disc." -msgstr "Keine DOL auf der Disc gefunden." - -msgid "No SD-Card inserted!" -msgstr "Keine SD Karte eingelegt!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Es wurden keine Cheats ausgewählt." - -msgid "No data could be read." -msgstr "Daten konnten nicht gelesen werden." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Keine Datei fehlt!" - -msgid "No new updates." -msgstr "Keine Updates verfügbar." - -msgid "No themes found on the site." -msgstr "Keine Themes auf der Seite gefunden." - -msgid "Not a WAD file." -msgstr "Das ist keine WAD Datei." - -msgid "Not a Wii Disc" -msgstr "Keine Wii Disc." - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Nicht genügend freier Speicher." - -msgid "Not enough free space!" -msgstr "Nicht genügend freier Speicher!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Nicht unterstütztes Format!" - -msgid "Nov" -msgstr "November" - -msgid "OFF" -msgstr "AUS" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Oktober" - -msgid "Official Site:" -msgstr "Offizielle Seite:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Altersbeschränkung" - -msgid "Partition" -msgstr "" - -msgid "Password" -msgstr "Passwort" - -msgid "Password Changed" -msgstr "Passwort geändert" - -msgid "Password has been changed" -msgstr "Passwort wurde geändert" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Füge sie in deinen Browser ein, um die WiiTDB.zip zu erhalten." - -msgid "Patch Country Strings" -msgstr "Country Strings patchen" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Wähle aus der Liste" - -msgid "Play Count" -msgstr "Spielzähler" - -msgid "Play Next" -msgstr "Nächster Titel" - -msgid "Play Previous" -msgstr "Vorheriger Titel" - -msgid "Playing Music:" -msgstr "Aktuelle Musik:" - -msgid "Please wait..." -msgstr "Bitte warten..." - -msgid "Power off the Wii" -msgstr "Wii ausschalten" - -msgid "Prompts Buttons" -msgstr "Anzeige" - -msgid "Published by" -msgstr "Veröffentlicht von" - -msgid "Quick Boot" -msgstr "Schnelles Laden" - -msgid "Reading WAD data... Ok!" -msgstr "Lese WAD Daten... OK!" - -msgid "Receiving file from:" -msgstr "Empfange Datei von:" - -msgid "Released" -msgstr "Erschienen am" - -msgid "Reload SD" -msgstr "SD Karte erneut laden" - -msgid "Remove update" -msgstr "Update entfernen" - -msgid "Rename Game on WBFS" -msgstr "Spiel umbenennen" - -msgid "Reset BG Music" -msgstr "Musik zurücksetzen" - -msgid "Reset Playcounter" -msgstr "Spielzähler zurücksetzen" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Starte neu..." - -msgid "Return" -msgstr "Zurück" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Zurück zum Wii Menü" - -msgid "Rumble" -msgstr "" - -msgid "SFX Volume" -msgstr "SFX Lautstärke" - -msgid "Save" -msgstr "Speichern" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Liste speicheren unter" - -msgid "Saved" -msgstr "Gespeichert" - -msgid "Screensaver" -msgstr "Bildschirmschoner" - -msgid "Select" -msgstr "Auswählen" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "wähle eine DOL" - -msgid "Sept" -msgstr "September" - -msgid "Set Search-Filter" -msgstr "Suche" - -msgid "Settings" -msgstr "Einstellungen" - -msgid "Shutdown System" -msgstr "System herunterfahren" - -msgid "Shutdown to Idle" -msgstr "WiiConnect24 an" - -msgid "Sort alphabetically" -msgstr "Alphabetisch ordnen" - -msgid "Sort by rank" -msgstr "nach Bewertungen ordnen" - -msgid "Sort order by most played" -msgstr "nach Spielzähler ordnen" - -msgid "Sound" -msgstr "Ton" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Besonderen Dank an:" - -msgid "Success" -msgstr "Erfolgreich" - -msgid "Success:" -msgstr "Erfolgreich:" - -msgid "Successfully Saved" -msgstr "Erfolgreich gespeichert" - -msgid "Successfully Updated" -msgstr "Erfolgreich aktualisiert" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Erfolgreich aktualisiert. Danke an www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Erfolgreich gelöscht:" - -msgid "Successfully extracted theme." -msgstr "Theme erfolgreich entpackt." - -msgid "Successfully installed:" -msgstr "Erfolgreich installiert:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT Cheatdateien" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Das eingegebene Verzeichnis existiert nicht. Möchtest du es erstellen?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Theme Downloader" - -msgid "Theme Downloader" -msgstr "" - -msgid "Theme Path" -msgstr "Theme" - -msgid "Theme Title:" -msgstr "Name:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Noch:" - -msgid "Title Launcher" -msgstr "Channel Launcher" - -msgid "Titles from WiiTDB" -msgstr "Namen aus WiiTDB" - -msgid "Tooltips" -msgstr "" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Übertragung fehlgeschlagen" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB Gerät nicht gefunden." - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX ist jetzt geschützt." - -msgid "Uninstall" -msgstr "Deinstallieren" - -msgid "Uninstall Game" -msgstr "Spiel deinstallieren" - -msgid "Uninstall Menu" -msgstr "Deinstallationsmenü" - -msgid "Uninstalling wad" -msgstr "Deinstalliere WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Entsperre den Loader, um diese Option zu nutzen." - -msgid "Unsupported format, try to extract manually." -msgstr "Nicht unterstütztes Format. Versuch es manuell zu Entpacken." - -msgid "Update" -msgstr "" - -msgid "Update All" -msgstr "Alles" - -msgid "Update DOL" -msgstr "Nur DOL" - -msgid "Update Files" -msgstr "Aktualisieren" - -msgid "Update Path" -msgstr "Updates" - -msgid "Update all Language Files" -msgstr "Sprachdateien aktualisieren" - -msgid "Update failed" -msgstr "Update fehlgeschlagen" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Aktualisiere Sprachdateien:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Die hochgeladene ZIP Datei wurde ins Homebrew Verzeichnis installiert." - -msgid "VIDTV Patch" -msgstr "" - -#, c-format -msgid "Version: %s" -msgstr "" - -msgid "Video Mode" -msgstr "Videomodus" - -msgid "WIP Patches Path" -msgstr "WIP Patches" - -msgid "Waiting for USB Device" -msgstr "Warte auf USB Gerät" - -msgid "Waiting..." -msgstr "Warte..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Was möchtest du aktualisieren?" - -msgid "WiFi Features" -msgstr "WiFi Fähigkeiten" - -msgid "Wii Menu" -msgstr "Wii Menü" - -msgid "Wii Settings" -msgstr "Wii Datenverwaltung" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Licht am Laufwerk" - -msgid "Wrong Password" -msgstr "Falsches Passwort" - -msgid "Yes" -msgstr "Ja" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Du must eine Partition auswählen oder formatieren." - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Deine URL wurde in %sWiiTDB_URL.txt gespeichert." - -msgid "and translaters for language files updates" -msgstr "und den Übersetzern der Sprachdateien" - -msgid "available" -msgstr "verfügbar" - -msgid "does not exist!" -msgstr "existiert nicht!" - -msgid "does not exist! Loading game without cheats." -msgstr "existiert nicht! Spiel wird ohne Cheats gestartet." - -msgid "files left" -msgstr "Dateien fehlen" - -msgid "files not found on the server!" -msgstr "Dateien auf dem Server nicht gefunden!" - -msgid "for FAT/NTFS support" -msgstr "für den FAT/NTFS Support" - -msgid "for Ocarina" -msgstr "für Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "für WiiTDB und dem Hosten der (Disc) Cover" - -msgid "for diverse patches" -msgstr "für diverse Patches" - -msgid "for his awesome tool LibWiiGui" -msgstr "für sein großartiges Tool LibWiiGui" - -msgid "for hosting the themes" -msgstr "für das Hosten der Themes" - -msgid "for hosting the update files" -msgstr "für das Hosten der Updates" - -msgid "for the USB Loader source" -msgstr "für die Veröffentlichung des USB Loader-Quellcodes" - -msgid "formatted!" -msgstr "formatiert!" - -msgid "free" -msgstr "frei" - -msgid "not set" -msgstr "nicht gesetzt" - -msgid "of" -msgstr "von" - -msgid "seconds left" -msgstr "Sekunden verbleiben" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "1:1 Kopie installieren" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Jeder)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Kinder 7+) " - -#~ msgid "1 hour" -#~ msgstr "1 Stunde" - -#~ msgid "10 min" -#~ msgstr "10 Minuten" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Jugendliche 12+)" - -#~ msgid "20 min" -#~ msgstr "20 Minuten" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Erwachsene 16+)" - -#~ msgid "3 min" -#~ msgstr "3 Minuten" - -#~ msgid "30 min" -#~ msgstr "30 Minuten" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Erwachsene 18+)" - -#~ msgid "5 min" -#~ msgstr "5 Minuten" - -#~ msgid "An Error occured" -#~ msgstr "Ein Fehler ist aufgetreten." - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Bist du sicher, das du die Altersbeschränkung aktivieren möchtest?" - -#~ msgid "Both" -#~ msgstr "ID und Region" - -#~ msgid "Checking for Updates" -#~ msgstr "Suche nach Updates" - -#~ msgid "Console Default" -#~ msgstr "Konsolenstandard" - -#~ msgid "Customs/Original" -#~ msgstr "Community/Original" - -#~ msgid "Disc Default" -#~ msgstr "Discstandard" - -#~ msgid "DiskFlip" -#~ msgstr "DiscFlip" - -#~ msgid "Downloading" -#~ msgstr "Dateien werden heruntergeladen" - -#~ msgid "Dutch" -#~ msgstr "Niederländisch" - -#~ msgid "English" -#~ msgstr "Englisch" - -#~ msgid "French" -#~ msgstr "Französisch" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "SPIELID_Spielname" - -#~ msgid "Game ID" -#~ msgstr "Spiel ID" - -#~ msgid "Game Region" -#~ msgstr "Region" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "Spielname [SPIELID]" - -#~ msgid "German" -#~ msgstr "Deutsch" - -#~ msgid "Invalid PIN code" -#~ msgstr "Ungültiger PIN Code" - -#~ msgid "Italian" -#~ msgstr "Italienisch" - -#~ msgid "Japanese" -#~ msgstr "Japanisch" - -#~ msgid "Korean" -#~ msgstr "Koreanisch" - -#~ msgid "Left" -#~ msgstr "Links" - -#~ msgid "Like SysMenu" -#~ msgstr "System Menü" - -#~ msgid "Load From SD/USB" -#~ msgstr "von SD/USB laden" - -#~ msgid "Locked" -#~ msgstr "Gesperrt" - -#~ msgid "Loop Directory" -#~ msgstr "Verzeichnis wiederholen" - -#~ msgid "Loop Music" -#~ msgstr "Scheife" - -#~ msgid "Loop Sound" -#~ msgstr "Wiederholung" - -#~ msgid "Neither" -#~ msgstr "Keine" - -#~ msgid "Next" -#~ msgstr "Weiter" - -#~ msgid "None" -#~ msgstr "Keine" - -#~ msgid "Normal" -#~ msgstr "Normal (4:3)" - -#~ msgid "ON" -#~ msgstr "AN" - -#~ msgid "Only Customs" -#~ msgstr "nur Community" - -#~ msgid "Only Original" -#~ msgstr "nur Originale" - -#~ msgid "Only for Install" -#~ msgstr "nur beim Installieren" - -#~ msgid "Original/Customs" -#~ msgstr "Original/Community" - -#~ msgid "Parental Control disabled" -#~ msgstr "Altersbeschränkung ausgeschaltet" - -#~ msgid "Play Once" -#~ msgstr "Einmal abspielen" - -#~ msgid "Prev" -#~ msgstr "Zurück" - -#~ msgid "Random Directory Music" -#~ msgstr "Zufällig" - -#~ msgid "Right" -#~ msgstr "Rechts" - -#~ msgid "SChinese" -#~ msgstr "Vereinfachtes Chinesisch" - -#~ msgid "Sound+BGM" -#~ msgstr "mit Hintergrundmusik" - -#~ msgid "Sound+Quiet" -#~ msgstr "ohne Hintergrundmusik" - -#~ msgid "Spanish" -#~ msgstr "Spanisch" - -#~ msgid "System Default" -#~ msgstr "Konsolenstandard" - -#~ msgid "TChinese" -#~ msgstr "Traditionelles Chinesisch" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Die WAD Datei wurde installiert. Sie konnte aber nicht von der SD Karte gelöscht werden." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Die WAD Installation schlug fehl durch Fehler %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Die WAD Datei, die gerade heruntergeladen wurde (%s), konnte nicht geöffnet werden." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Altersbeschränkung deaktivieren" - -#~ msgid "Unlocked" -#~ msgstr "Entsperrt" - -#~ msgid "Update to" -#~ msgstr "Aktualisiere auf" - -#~ msgid "Updating" -#~ msgstr "Aktualisiere" - -#~ msgid "Updating Language Files..." -#~ msgstr "Aktualisiere Sprachdateien..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Aktualisiere WiiTDB" - -#~ msgid "Widescreen Fix" -#~ msgstr "Breitbild (16:9)" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Du hast die Wii-Altersbeschränkung nicht aktiviert. Wenn du sie nutzen möchtest, aktiviere sie in den Wii-Systemeinstellungen." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s startet evtl. nicht richtig, falls dein System Menü nicht aktuell ist." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Wii Menü" - -#~ msgid "Channels" -#~ msgstr "Kanäle" - -#~ msgid "Checking existing artwork" -#~ msgstr "Prüfe existierende Artworks" - -#~ msgid "Confirm" -#~ msgstr "Bestätigen" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Es wurde keine WBFS Partition gefunden." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "WBFS Partition konnte nicht geöffnet werden." - -#~ msgid "Could not read the disc." -#~ msgstr "Disc konnte nicht gelesen werden." - -#~ msgid "Could not set USB." -#~ msgstr "USB konnte nicht gesetzt werden." - -#~ msgid "Cover Path Changed" -#~ msgstr "Pfad geändert" - -#~ msgid "DOL path changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Disc Path Changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Display favorites" -#~ msgstr "Favoriten anzeigen" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "30 Sekunden lang erneut versuchen?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Altersbeschränkung aktivieren" - -#~ msgid "Force" -#~ msgstr "Erzwinge" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Hermes CIOS" -#~ msgstr "Hermes' cIOS" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "SD Karte einlegen um Bilder herunterzuladen." - -#~ msgid "Install not possible" -#~ msgstr "Installation nicht möglich" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Höchstwahrscheinlich sind Breite und Höhe keine Vielfachen von 4." - -#~ msgid "Network init error" -#~ msgstr "Netzwerkinitialisierungsfehler" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Keine .dol oder .elf Dateien gefunden." - -#~ msgid "No Favorites" -#~ msgstr "Keine Favoriten" - -#~ msgid "No USB Device" -#~ msgstr "Kein USB Gerät" - -#~ msgid "No USB Device found." -#~ msgstr "Kein USB Gerät gefunden." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Keine WBFS oder FAT/NTFS Partition gefunden" - -#~ msgid "Normal Covers" -#~ msgstr "2D Cover" - -#~ msgid "Not Found" -#~ msgstr "Nicht gefunden" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Das ist keine DOL/ELF Datei." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Auf Standard zurücksetzen?" - -#~ msgid "Save Failed" -#~ msgstr "Speichern fehlgeschlagen" - -#~ msgid "Selected DOL" -#~ msgstr "Ausgewählte DOL" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Pfad geändert" - -#~ msgid "Theme Path Changed" -#~ msgstr "Pfad geändert" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "Hermes' cIOS funktioniert beim USB Loader GX nur mit rev4! Bitte versichere dich das du rev4 installiert hast!" - -#~ msgid "Update Path changed." -#~ msgstr "Pfad geändert" - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Pfad geändert" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Pfad geändert" - -#~ msgid "You are about to delete " -#~ msgstr "Du bist dabei zu löschen " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Du möchtest Favoriten anzeigen lassen, hast aber keine ausgewählt." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Du benutzt das NTFS Dateisystem. Wegen möglicher Schreibfehler auf einer NTFS Partition, ist das Installieren eines Spiels nicht möglich." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Du hast versucht ein 'schlechtes Bild' zu laden." - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "existiert nicht! Du hast was falsch gemacht, Idiot." - -#~ msgid "file left" -#~ msgstr "Datei fehlt" diff --git a/Languages/hungarian.lang b/Languages/hungarian.lang deleted file mode 100644 index 9a8425c1..00000000 --- a/Languages/hungarian.lang +++ /dev/null @@ -1,1531 +0,0 @@ -# USB Loader GX language source file. -# hungarian.lang - r878 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-12-29 11:05+0100\n" -"Last-Translator: Springdale\n" -"Language-Team: Tusk, Springdale\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "Wad elmentve mint:" - -msgid " could not be downloaded." -msgstr "nem letölthetõ." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "elmentve. A fájl nincs ellenõrizve, és egyes kódok nem feltétlenül működnek együtt. Probléma esetén további információért nyisd meg a fájlt szövegszerkesztõvel." - -msgid " is not on the server." -msgstr "nincs a szerveren." - -msgid "2D Cover Path" -msgstr "2D Boritó Útvonala" - -msgid "3D Cover Path" -msgstr "3D Boritó Útvonala" - -msgid "3D Covers" -msgstr "3D Borítók" - -msgid ">> Deleting tickets..." -msgstr ">> Ticket-ek törlése..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Ticket-ek törlése...HIBA!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Ticket-ek törlése...Ok!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Title törlése...HIBA!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> Title törlése...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Title tartalom törlése..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Title tartalom törlése...HIBA!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Title tartalom törlése...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Title törlése..." - -msgid ">> Finishing installation..." -msgstr ">> Telepítés befejezése..." - -msgid ">> Installing content #" -msgstr ">> Telepítés: tartalom #" - -msgid ">> Installing ticket..." -msgstr ">> Ticket telepítése" - -msgid ">> Installing title..." -msgstr ">> Title telepítése..." - -msgid ">> Reading WAD data..." -msgstr ">> WAD adatok olvasása..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> WAD adatok olvasása...HIBA!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> WAD adatok olvasása...Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Minden partíció" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Az USB Loader GX minden funkciója elérhetõ." - -msgid "Alternate DOL" -msgstr "Alternatív DOL" - -msgid "App Language" -msgstr "Nyelv" - -msgid "Apr" -msgstr "Ápr" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Biztos vagy benne?" - -msgid "Aug" -msgstr "" - -msgid "Author:" -msgstr "Készítõ:" - -msgid "AutoInit Network" -msgstr "Hálózat AutoInit" - -msgid "BCA Codes Path" -msgstr "BCA kód útvonal" - -msgid "BETA revisions" -msgstr "Béta változatok" - -msgid "Back" -msgstr "Vissza" - -msgid "Back to HBC or Wii Menu" -msgstr "Visszatérés a HBC-be vagy Wii Menübe" - -msgid "Back to Loader" -msgstr "HBC" - -msgid "Backgroundmusic" -msgstr "Háttérzene" - -msgid "Big thanks to:" -msgstr "Köszönet:" - -msgid "Block IOS Reload" -msgstr "IOS újratöltés blokkolása" - -msgid "Boot/Standard" -msgstr "Boot/Alapértelmezett" - -msgid "Boot?" -msgstr "" - -msgid "Can't be formatted" -msgstr "Nem Formázható" - -msgid "Can't create directory" -msgstr "Mappa nem hozható létre" - -msgid "Can't create file" -msgstr "A fájl nem hozható létre." - -msgid "Can't delete:" -msgstr "Nem törölhetõ" - -msgid "Cancel" -msgstr "Mégse" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "A cheat-fájl üres" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Kattints a borítók letöltéséhez" - -msgid "Click to change game ID" -msgstr "Kattints a játékID megváltoztatásához" - -msgid "Clock" -msgstr "Óra" - -msgid "Close" -msgstr "Bezárás" - -msgid "Code Download" -msgstr "Kód letöltés" - -#, c-format -msgid "Coded by: %s" -msgstr "Kódolás: %s" - -msgid "Coding:" -msgstr "Kódolás:" - -msgid "Connection lost..." -msgstr "A kapcsolat megszakadt..." - -msgid "Console" -msgstr "Konzol" - -msgid "Console Locked" -msgstr "Konzol Zárolva" - -msgid "Console should be unlocked to modify it." -msgstr "A konzol zárolva, ezért nem változtatható meg." - -msgid "Continue to install game?" -msgstr "Játék telepítésének folytatása?" - -msgid "Controllevel" -msgstr "Kontrollszint" - -msgid "Correct Password" -msgstr "Helyes Jelszó" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Nem hozható létre GCT fájl" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "DIP modul nem tölthetõ be!" - -msgid "Could not initialize network!" -msgstr "Kapcsolat nem hozható létre!" - -msgid "Could not open Disc" -msgstr "Lemez nem betölthetõ" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "A mentés nem sikerült." - -msgid "Cover Download" -msgstr "Boritó Letöltés" - -msgid "Create" -msgstr "Létrehozás" - -msgid "Credits" -msgstr "Készítõk" - -msgid "Custom Paths" -msgstr "Egyéni útvonalak" - -msgid "DOL Path" -msgstr "DOL Útvonal" - -msgid "Dec" -msgstr "" - -msgid "Default" -msgstr "Alapértelmezett" - -msgid "Default Gamesettings" -msgstr "Alapértelmezett beállítások" - -msgid "Default Settings" -msgstr "Alapértelmezett beállítások" - -msgid "Delete" -msgstr "Törlés" - -msgid "Delete ?" -msgstr "Törlés?" - -msgid "Delete Cheat GCT" -msgstr "Cheat GCT törlés" - -msgid "Delete Cheat TXT" -msgstr "Cheat TXT törlés" - -msgid "Delete Cover Artwork" -msgstr "Borító törlése" - -msgid "Delete Disc Artwork" -msgstr "Lemezfotó törlése" - -msgid "Design:" -msgstr "Felület:" - -msgid "Developed by" -msgstr "Készítette" - -msgid "Directory does not exist!" -msgstr "A könyvtár nem létezik!" - -msgid "Disc Artwork Download" -msgstr "Lemezfotó letöltése" - -msgid "Disc Artwork Path" -msgstr "Lemezképek Útvonala" - -msgid "Disc Images" -msgstr "Lemezfotók" - -msgid "Display" -msgstr "Játékinfo megj." - -msgid "Display as a carousel" -msgstr "Körhinta megjelenítés" - -msgid "Display as a grid" -msgstr "Rács megjelenítés" - -msgid "Display as a list" -msgstr "Lista megjelenítés" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Biztosan törlöd?" - -msgid "Do you want to apply it now?" -msgstr "Alkalmazás most?" - -msgid "Do you want to change language?" -msgstr "Nyelv megváltoztatása?" - -msgid "Do you want to download this theme?" -msgstr "Téma letöltése?" - -msgid "Do you want to format:" -msgstr "Formázás?" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Köztudottan működõ alternatív DOL használata?" - -msgid "Do you wish to update/download all language files?" -msgstr "Minden nyelvi fájl letöltése/frissítése?" - -msgid "Done!" -msgstr "Kész!" - -msgid "Download" -msgstr "Letöltés" - -msgid "Download Boxart image?" -msgstr "Borító letöltése?" - -msgid "Download Discart image?" -msgstr "Lemezfotó letöltése?" - -msgid "Download Now" -msgstr "Letöltés most" - -msgid "Download failed." -msgstr "Sikertelen letöltés." - -msgid "Download finished" -msgstr "Letöltés kész" - -msgid "Download request failed." -msgstr "Sikertelen letöltési kérelem." - -msgid "Downloading Page List:" -msgstr "Lista letöltése:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Fájl letöltése" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Kép letöltése:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "HIBA" - -msgid "ERROR:" -msgstr "HIBA:" - -msgid "ERROR: Can't set up theme." -msgstr "HIBA: Téma nem állítható be" - -msgid "Error" -msgstr "Hiba" - -msgid "Error !" -msgstr "Hiba !" - -msgid "Error 002 fix" -msgstr "Error 02 javítás" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Lemezolvasási hiba" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Adatátviteli hiba." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Hiba..." - -msgid "Error:" -msgstr "Hiba:" - -msgid "Extracting files..." -msgstr "Fájlok kicsomagolása..." - -msgid "FAT: Use directories" -msgstr "FAT: könyvtárak használata" - -msgid "Failed formating" -msgstr "Formázás sikertelen" - -msgid "Failed to extract." -msgstr "A kicsomagolás nem sikerült." - -msgid "Failed to open partition" -msgstr "Hiba a partíció megnyitásakor" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "Fájl nem található" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Telepítés befejezése...Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "" - -msgid "Format" -msgstr "Formázás" - -msgid "Formatting, please wait..." -msgstr "Formatálás folyamatban, kérlek várj..." - -msgid "Free Space" -msgstr "Szabad Hely" - -msgid "Full Shutdown" -msgstr "Teljes Kikapcsolás" - -msgid "GCT Cheatcodes Path" -msgstr "Kódok Útvonala" - -msgid "GCT File created" -msgstr "GCT Fájl létrehozva" - -msgid "GUI Settings" -msgstr "Kezelõfelület" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg nem található." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Játéknyelv" - -msgid "Game Load" -msgstr "Játék Betöltés" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Játék Méret" - -msgid "Game Sound Mode" -msgstr "Játék Banner hang" - -msgid "Game Sound Volume" -msgstr "Játék Banner hangerő" - -msgid "Game is already installed:" -msgstr "A játék már fel van telepítve:" - -msgid "Game partition" -msgstr "Játék partíció" - -msgid "Games" -msgstr "Játékok" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "HOME Menü" - -msgid "Homebrew Apps Path" -msgstr "Homebrew Útvonal" - -msgid "Homebrew Launcher" -msgstr "Homebrew indító" - -msgid "Hour" -msgstr "Óra" - -msgid "How do you want to update?" -msgstr "Hogyan szeretnél frissíteni?" - -msgid "How to Shutdown?" -msgstr "Hogyan kapcsoljon ki?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "WiFi hiánya esetén nyomj 1-es gombot a WiiTDB.zip URL-ért." - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Bejövõ fájl %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Bejövõ fájl %0.2fMB" - -msgid "Initializing Network" -msgstr "Hálózat inicializálása..." - -msgid "Insert Disk" -msgstr "Helyezz be egy lemezt" - -msgid "Insert a Wii Disc!" -msgstr "Helyezz be Wii lemezt!" - -msgid "Insert an SD-Card to save." -msgstr "Helyezz be egy SD Kártyát, hogy ments," - -msgid "Insert an SD-Card to use this option." -msgstr "Helyezz be egy SD Kártyát, hogy használhasd ezt a lehetõséget." - -msgid "Install" -msgstr "Telepítés" - -msgid "Install Error!" -msgstr "Telepítési Hiba!" - -msgid "Install a game" -msgstr "Játék telepítése" - -msgid "Install partitions" -msgstr "Partíciók telepítése" - -msgid "Installing content... Ok!" -msgstr "Tartalom telepítése... Ok!" - -msgid "Installing game:" -msgstr "Játék telepítése" - -msgid "Installing ticket... Ok!" -msgstr "Ticket telepítése... Ok!" - -msgid "Installing title... Ok!" -msgstr "Title telepítése... Ok!" - -msgid "Installing wad" -msgstr "Wad telepítése" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Számunkra segítõ információid lehetnek - kérlek továbbítsd ezeket a fejlesztõi csapat felé." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Júl" - -msgid "June" -msgstr "Jún" - -msgid "Keep" -msgstr "Megtartás" - -msgid "Keyboard" -msgstr "Billenyûzet" - -msgid "Language File" -msgstr "Nyelvi fájl" - -msgid "Language change:" -msgstr "Nyelv választás:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Nyelvek útvonala megváltozott." - -msgid "Load" -msgstr "Betöltés" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Fájl betöltése innen: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "DOL betöltése alternatív DOL-ként?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Alapnyelv betõltése" - -msgid "Loading standard music." -msgstr "Alapzene betõltése" - -msgid "Lock Console" -msgstr "Konzol Lezárása" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "Már" - -msgid "Mark new games" -msgstr "Új játékok megjelölése" - -msgid "May" -msgstr "Máj" - -msgid "Missing files" -msgstr "Hiányzó fájl" - -msgid "Mount DVD drive" -msgstr "DVD meghajtó felcsatolása" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Zene Hangerõ" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Új lemez észlelve" - -msgid "No" -msgstr "Nem" - -msgid "No Cheatfile found" -msgstr "Kód nem található" - -msgid "No DOL file found on disc." -msgstr "Nem található DOL fájl a lemezen." - -msgid "No SD-Card inserted!" -msgstr "Nincs SD kártya behelyezve!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Nincsenek kiválasztott cheat-ek" - -msgid "No data could be read." -msgstr "Adat nem olvasható." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Egy fájl sem hiányzik!" - -msgid "No new updates." -msgstr "Nincs elérhetõ frissítés." - -msgid "No themes found on the site." -msgstr "Nem találhatóak témák az oldalon." - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Nem Wii lemez" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Nincs elég memória." - -msgid "Not enough free space!" -msgstr "Nincs elég szabad hely" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Nem támogatott formátum" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "KI" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Okt" - -msgid "Official Site:" -msgstr "Hivatalos oldal:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Szülõi Felügyelet" - -msgid "Partition" -msgstr "Partició" - -msgid "Password" -msgstr "Jelszó" - -msgid "Password Changed" -msgstr "Jelszó Megváltozott" - -msgid "Password has been changed" -msgstr "A Jelszó megváltozott" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Másold be a böngészõbe a WiiTDB.zip letöltéséhez." - -msgid "Patch Country Strings" -msgstr "Country String Patch" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Válassz a listából" - -msgid "Play Count" -msgstr "Indítások" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "Kérlek várj..." - -msgid "Power off the Wii" -msgstr "Wii kikapcsolása" - -msgid "Prompts Buttons" -msgstr "Gyors Gombok" - -msgid "Published by" -msgstr "Kiadta" - -msgid "Quick Boot" -msgstr "Gyors Boot" - -msgid "Reading WAD data... Ok!" -msgstr "WAD adat olvasás... Ok!" - -msgid "Receiving file from:" -msgstr "Fájl fogadása innen:" - -msgid "Released" -msgstr "Kiadva" - -msgid "Reload SD" -msgstr "SD Újratöltése" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "WBFS játék átnevezése" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Elindítások nullázása" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Újraindítás..." - -msgid "Return" -msgstr "Vissza" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Vissza a Wii Menübe" - -msgid "Rumble" -msgstr "Rezgés" - -msgid "SFX Volume" -msgstr "Effekt Hangerõ" - -msgid "Save" -msgstr "Mentés" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Játéklista mentése ide:" - -msgid "Saved" -msgstr "Elmentve" - -msgid "Screensaver" -msgstr "Képernyõkimélõ" - -msgid "Select" -msgstr "Válassz" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "DOL kiválasztása" - -msgid "Sept" -msgstr "Szep" - -msgid "Set Search-Filter" -msgstr "Keresés" - -msgid "Settings" -msgstr "Beállítások" - -msgid "Shutdown System" -msgstr "Leállítás" - -msgid "Shutdown to Idle" -msgstr "Készenlét" - -msgid "Sort alphabetically" -msgstr "Rendezés ABC-sorrendben" - -msgid "Sort by rank" -msgstr "Rendezés rang szerint" - -msgid "Sort order by most played" -msgstr "Rendezés indítások száma szerint" - -msgid "Sound" -msgstr "Hang" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Külön Köszönet:" - -msgid "Success" -msgstr "Sikeres" - -msgid "Success:" -msgstr "Sikeres:" - -msgid "Successfully Saved" -msgstr "Sikeresen Mentve" - -msgid "Successfully Updated" -msgstr "Sikeres frissítés" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Sikeresen törölve:" - -msgid "Successfully extracted theme." -msgstr "Téma kicsomagolva." - -msgid "Successfully installed:" -msgstr "Sikeresen telepítve:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT Cheatkódok Útvonala" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "A megadott könyvtár nem létezik. Létrehozzuk?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Téma Letöltés Útvonal" - -msgid "Theme Downloader" -msgstr "Témák Letöltése" - -msgid "Theme Path" -msgstr "Témák Útvonala" - -msgid "Theme Title:" -msgstr "Téma címe:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Hátralevõ idõ" - -msgid "Title Launcher" -msgstr "Programindító" - -msgid "Titles from WiiTDB" -msgstr "Címek WiiTDB fájlból" - -msgid "Tooltips" -msgstr "Súgók" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Átviteli hiba." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB Meghajtó nem található" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX levédve" - -msgid "Uninstall" -msgstr "Törlés" - -msgid "Uninstall Game" -msgstr "Játék törlése" - -msgid "Uninstall Menu" -msgstr "Adatkezelés" - -msgid "Uninstalling wad" -msgstr "Wad törlése" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Zárolva a program, ezt nem használhatod." - -msgid "Unsupported format, try to extract manually." -msgstr "Nem támogatott formátum, próbáld manuálisan kicsomagolni." - -msgid "Update" -msgstr "Frissítés" - -msgid "Update All" -msgstr "Minden Frissítése" - -msgid "Update DOL" -msgstr "DOL Frissítése" - -msgid "Update Files" -msgstr "Fájlok frissítése" - -msgid "Update Path" -msgstr "Frissítés Útvonala" - -msgid "Update all Language Files" -msgstr "Minden nyelvi fájl frissítése" - -msgid "Update failed" -msgstr "Frissítési hiba" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Nyelvi fájlok frissítése:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Feltöltött ZIP fájl telepítve a Homebrew mappába." - -msgid "VIDTV Patch" -msgstr "" - -#, c-format -msgid "Version: %s" -msgstr "Verzió: %s" - -msgid "Video Mode" -msgstr "Videó Mód" - -msgid "WIP Patches Path" -msgstr "WIP Patch útvonal" - -msgid "Waiting for USB Device" -msgstr "Várakozás az USB Meghajtóra" - -msgid "Waiting..." -msgstr "Várakozás..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Mit szeretnél frissíteni?" - -msgid "WiFi Features" -msgstr "WiFi Sajátosságok" - -msgid "Wii Menu" -msgstr "Wii Menü" - -msgid "Wii Settings" -msgstr "Wii Beállítások" - -msgid "WiiTDB Files" -msgstr "WiiTDB fájlok" - -msgid "WiiTDB Path" -msgstr "WiiTDB Útvonala" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "WiiFény" - -msgid "Wrong Password" -msgstr "Hibás Jelszó" - -msgid "Yes" -msgstr "Igen" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Választanod vagy formáznod kell egy partíciót" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "URL elmentve itt: %sWiiTDB_URL.txt" - -msgid "and translaters for language files updates" -msgstr "valamint minden fordító" - -msgid "available" -msgstr "elérhetõ" - -msgid "does not exist!" -msgstr "nem létezik!" - -msgid "does not exist! Loading game without cheats." -msgstr "nem létezik! Játék betöltése kódok nélkül." - -msgid "files left" -msgstr "hátralévõ fájl" - -msgid "files not found on the server!" -msgstr "fájl nem található a szerveren" - -msgid "for FAT/NTFS support" -msgstr "FAT/NTFS támogatás" - -msgid "for Ocarina" -msgstr ": Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr ": WiiTDB és borítók/lemezfotók" - -msgid "for diverse patches" -msgstr ": többféle patch" - -msgid "for his awesome tool LibWiiGui" -msgstr "-nak kiváló eszközéért: LibWiiGui" - -msgid "for hosting the themes" -msgstr ": témák tárhelye" - -msgid "for hosting the update files" -msgstr ": frissítési fájlok tárhelye" - -msgid "for the USB Loader source" -msgstr ": USB Loader forráskód" - -msgid "formatted!" -msgstr "Formázva!" - -msgid "free" -msgstr "szabad" - -msgid "not set" -msgstr "nem beállított" - -msgid "of" -msgstr "./" - -msgid "seconds left" -msgstr "hátralévõ másodperc" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "1:1 másolat telepítése" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Mindenkinek)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Gyermekeknek 12+)" - -#~ msgid "1 hour" -#~ msgstr "1 óra" - -#~ msgid "10 min" -#~ msgstr "10 perc" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Tinédzserek 14+)" - -#~ msgid "20 min" -#~ msgstr "20 perc" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Kamaszok 16+)" - -#~ msgid "3 min" -#~ msgstr "3 perc" - -#~ msgid "30 min" -#~ msgstr "30 perc" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Felnõtteknek 18+)" - -#~ msgid "5 min" -#~ msgstr "5 perc" - -#~ msgid "An Error occured" -#~ msgstr "Hiba történt" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Szülõi felügyelet bekapcsolása?" - -#~ msgid "Both" -#~ msgstr "Mindkettõ" - -#~ msgid "Checking for Updates" -#~ msgstr "Frissitések keresése..." - -#~ msgid "Console Default" -#~ msgstr "Konzol Alapértelmezett" - -#~ msgid "Customs/Original" -#~ msgstr "Egyéni/Eredeti" - -#~ msgid "Disc Default" -#~ msgstr "Lemez Alapértelmezettje" - -#~ msgid "DiskFlip" -#~ msgstr "Lemezforgatás" - -#~ msgid "Downloading" -#~ msgstr "Letöltés" - -#~ msgid "Dutch" -#~ msgstr "Holland" - -#~ msgid "English" -#~ msgstr "Angol" - -#~ msgid "French" -#~ msgstr "Francia" - -#~ msgid "Game ID" -#~ msgstr "Játék ID" - -#~ msgid "Game Region" -#~ msgstr "Játék Régió" - -#~ msgid "German" -#~ msgstr "Német" - -#~ msgid "Invalid PIN code" -#~ msgstr "Hibás PIN kód" - -#~ msgid "Italian" -#~ msgstr "Olasz" - -#~ msgid "Japanese" -#~ msgstr "Japán" - -#~ msgid "Korean" -#~ msgstr "Koreai" - -#~ msgid "Left" -#~ msgstr "Balra" - -#~ msgid "Like SysMenu" -#~ msgstr "Mint a Rendszermenü" - -#~ msgid "Load From SD/USB" -#~ msgstr "Betöltés SD/USB-rõl" - -#~ msgid "Locked" -#~ msgstr "Lezárva" - -#~ msgid "Loop Sound" -#~ msgstr "Folyamatos hang" - -#~ msgid "Neither" -#~ msgstr "Egyik sem" - -#~ msgid "Next" -#~ msgstr "Következõ" - -#~ msgid "Normal" -#~ msgstr "Normális" - -#~ msgid "ON" -#~ msgstr "BE" - -#~ msgid "Only Customs" -#~ msgstr "Csak egyéni" - -#~ msgid "Only Original" -#~ msgstr "Csak eredeti" - -#~ msgid "Only for Install" -#~ msgstr "Csak telepítéshez" - -#~ msgid "Original/Customs" -#~ msgstr "Eredeti/Egyéni" - -#~ msgid "Parental Control disabled" -#~ msgstr "Szülõi felügyelet kikapcsolva" - -#~ msgid "Prev" -#~ msgstr "Elõzõ" - -#~ msgid "Right" -#~ msgstr "Jobb" - -#~ msgid "SChinese" -#~ msgstr "SKínai" - -#~ msgid "Sound+BGM" -#~ msgstr "Hang+háttérzene" - -#~ msgid "Sound+Quiet" -#~ msgstr "Csak hang" - -#~ msgid "Spanish" -#~ msgstr "Spanyol" - -#~ msgid "System Default" -#~ msgstr "Rendszer Alapértelmezett" - -#~ msgid "TChinese" -#~ msgstr "Tradicionális Kínai" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "A wad fájl telepítése megtörtént, de nem volt törölhetõ az SD kártyáról." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "A wad telepítés nem sikerült - hiba %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Az épp letöltött wad megnyitása nem sikerült (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Szülõi felügyelet feloldása" - -#~ msgid "Unlocked" -#~ msgstr "Feloldva" - -#~ msgid "Update to" -#~ msgstr "Frissítés ide: " - -#~ msgid "Updating" -#~ msgstr "Frissítés" - -#~ msgid "Updating Language Files..." -#~ msgstr "Nyelvi fájlok frissítése..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "WiiTDB.zip frissítése" - -#~ msgid "Widescreen Fix" -#~ msgstr "Szélesvászon Fix" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "A szülõi felügyelet nincs bekapcsolva - bekapcsolható a Wii Beállításokban." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Lehet, hogy nem fut megfelelõen, ha a System Menu nem a legfrissebb." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "BCA kód útvonal megváltozott" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Visszatérés a Wii Menübe" - -#~ msgid "Channels" -#~ msgstr "Csatornák" - -#~ msgid "Checking existing artwork" -#~ msgstr "Meglévõ képek ellenõrzése" - -#~ msgid "Confirm" -#~ msgstr "Megerõsítés" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "WBFS partíció nem található." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "WBFS partíció nem nyitható meg." - -#~ msgid "Could not read the disc." -#~ msgstr "A lemez nem olvasható." - -#~ msgid "Could not set USB." -#~ msgstr "USB beállítási hiba." - -#~ msgid "Cover Path Changed" -#~ msgstr "Boritó útvonala megváltozott" - -#~ msgid "DOL path changed" -#~ msgstr "DOL útvonal megváltozott" - -#~ msgid "Disc Path Changed" -#~ msgstr "Borítók útvonala megváltoztatva" - -#~ msgid "Display favorites" -#~ msgstr "Kedvencek megjelenítése" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "30 másodpercig szeretnéd még tovább próbálni?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Szülői felügyelet bekapcsolása" - -#~ msgid "Force" -#~ msgstr "Kényszerítés" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Kódok útvonala megváltozott" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Homebrew útvonal megváltoztatva" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Helyezz be egy SD Kártyát, hogy letöltsd a képeket." - -#~ msgid "Install not possible" -#~ msgstr "A telepítés nem lehetséges" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Vélhetõen méretei nem oszhatók 4-gyel." - -#~ msgid "Network init error" -#~ msgstr "Hálozat létrehozásában hiba történt" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Nem taláhatóak .dol vagy .elf fájlok." - -#~ msgid "No Favorites" -#~ msgstr "Nincsenek kedvencek" - -#~ msgid "No USB Device" -#~ msgstr "Nincs USB meghajtó" - -#~ msgid "No USB Device found." -#~ msgstr "Nincs USB meghajtó csatlakoztatva." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Nem található WBFS vagy FAT/NTFS partíció" - -#~ msgid "Normal Covers" -#~ msgstr "Sima Borítók" - -#~ msgid "Not Found" -#~ msgstr "Nem található" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Nem DOL/ELF fájl." - -#~ msgid "Save Failed" -#~ msgstr "Mentési hiba" - -#~ msgid "Selected DOL" -#~ msgstr "Kiválasztott DOL" - -#~ msgid "Standard" -#~ msgstr "Alap" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXT CheatKódok Útvonala megváltozott" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Téma letöltés útvonal megváltozott" - -#~ msgid "Theme Path Changed" -#~ msgstr "Témák útvonala megváltozott" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "Az USB Loader GX csak Hermes CIOS rev 4 mellett működik! Gyõződj meg róla, hogy telepítetted!" - -#~ msgid "Update Path changed." -#~ msgstr "Frissítés útvonala megváltozott." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "WIP Patch útvonal megváltozott" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB útvonal megváltozott." - -#~ msgid "You are about to delete " -#~ msgstr "Törölni készülsz: " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "A Kedvencek megjelenítését választottad, de egy játék sincs így megjelölve." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "NTFS fájlrendszert használata esetén a lehetséges írási hibák miatt játékok telepítése nem lehetséges." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Rossz képfájl próbáltál betõlteni" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "nem létezik! Valamit elcsesztéll :-)" - -#~ msgid "file left" -#~ msgstr "hátralévõ fájl" diff --git a/Languages/italian.lang b/Languages/italian.lang deleted file mode 100644 index 6082aa9e..00000000 --- a/Languages/italian.lang +++ /dev/null @@ -1,1561 +0,0 @@ -# USB Loader GX language source file. -# italian.lang - v61 - r926 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2010-02-21 08:00+0200\n" -"Last-Translator: Cambo \n" -"Language-Team: FoxeJoe, Cambo\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad salvato con il nome:" - -msgid " could not be downloaded." -msgstr " non può essere scaricato." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " è stato salvato. Parte del codice potrebbe non funzionare correttamente. In caso di problemi, aprire il testo con un editor per ottenere ulteriori informazioni." - -msgid " is not on the server." -msgstr " non è disponibile sul server." - -msgid "2D Cover Path" -msgstr "Percorso Copertine 2D" - -msgid "3D Cover Path" -msgstr "Percorso Copertine 3D" - -msgid "3D Covers" -msgstr "Copertine 3D" - -msgid ">> Deleting tickets..." -msgstr ">> Eliminazione ticket..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Eliminazione ticket...ERRORE! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Eliminazione ticket...OK! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Eliminazione titolo...ERRORE! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Eliminazione titolo...OK! " - -msgid ">> Deleting title contents..." -msgstr ">> Eliminazione contenuti..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Eliminazione contenuti...ERRORE! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Eliminazione contenuti...OK! " - -msgid ">> Deleting title..." -msgstr ">> Eliminazione titolo..." - -msgid ">> Finishing installation..." -msgstr ">> Sto terminando l'installazione..." - -msgid ">> Installing content #" -msgstr ">> Sto installando il contenuto #" - -msgid ">> Installing ticket..." -msgstr ">> Sto installando il ticket..." - -msgid ">> Installing title..." -msgstr ">> Sto installando il titolo..." - -msgid ">> Reading WAD data..." -msgstr ">> Lettura dati WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Lettura dati WAD...ERRORE! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Lettura dati WAD...OK!" - -msgid "AUTO" -msgstr "Automatico" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Tutte le partizioni" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Tutte le funzioni di USB Loader GX sono sbloccate." - -msgid "Alternate DOL" -msgstr "DOL Alternativo" - -msgid "App Language" -msgstr "Percorso Lingua" - -msgid "Apr" -msgstr "aprile" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Sei sicuro?" - -msgid "Aug" -msgstr "agosto" - -msgid "Author:" -msgstr "Autore:" - -msgid "AutoInit Network" -msgstr "Inizializz. Rete Automatica" - -msgid "BCA Codes Path" -msgstr "Percorso Codici BCA" - -msgid "BETA revisions" -msgstr "Versioni BETA" - -msgid "Back" -msgstr "Indietro" - -msgid "Back to HBC or Wii Menu" -msgstr "Torna a HBC/Menu Wii" - -msgid "Back to Loader" -msgstr "Canale HomeBrew" - -msgid "Backgroundmusic" -msgstr "Musica Sottofondo" - -msgid "Big thanks to:" -msgstr "Grazie mille a:" - -msgid "Block IOS Reload" -msgstr "Ricarica l'IOS" - -msgid "Boot/Standard" -msgstr "Riavvio/Standard" - -msgid "Boot?" -msgstr "Vuoi riavviare?" - -msgid "Can't be formatted" -msgstr "Non si può formattare" - -msgid "Can't create directory" -msgstr "Impossibile creare la cartella" - -msgid "Can't create file" -msgstr "Impossibile creare il file" - -msgid "Can't delete:" -msgstr "Impossibile eliminare:" - -msgid "Cancel" -msgstr "Annulla" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Modifica Percorso Suoni" - -msgid "Cheatfile is blank" -msgstr "il file dei trucchi è vuoto" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Premi per scaricare le Copertine" - -msgid "Click to change game ID" -msgstr "Premi per cambiare ID al gioco" - -msgid "Clock" -msgstr "Orologio" - -msgid "Close" -msgstr "Chiudi" - -msgid "Code Download" -msgstr "Scarico Codice" - -#, c-format -msgid "Coded by: %s" -msgstr "Sviluppato da: %s" - -msgid "Coding:" -msgstr "Sviluppo:" - -msgid "Connection lost..." -msgstr "Connessione persa..." - -msgid "Console" -msgstr "Terminale" - -msgid "Console Locked" -msgstr "Console Bloccata" - -msgid "Console should be unlocked to modify it." -msgstr "Sbloccare la Console per Modificarla." - -msgid "Continue to install game?" -msgstr "Continua ad Installare il gioco?" - -msgid "Controllevel" -msgstr "Livello Protezione" - -msgid "Correct Password" -msgstr "Password Corretta" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Non è stato possibile creare il file GCT" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Non è stato possibile inizializzare il modulo DIP!" - -msgid "Could not initialize network!" -msgstr "Non è stato possibile inizializzare la rete!" - -msgid "Could not open Disc" -msgstr "Non è stato possibile accedere al Disco" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Non è stato possibile salvare." - -msgid "Cover Download" -msgstr "Scaricamento Copertine" - -msgid "Create" -msgstr "Crea" - -msgid "Credits" -msgstr "" - -msgid "Custom Paths" -msgstr "Impostazione Percorsi (Directory)" - -msgid "DOL Path" -msgstr "Percorso File DOL" - -msgid "Dec" -msgstr "dicembre" - -msgid "Default" -msgstr "Default" - -msgid "Default Gamesettings" -msgstr "Impostaz. Predefinite Gioco" - -msgid "Default Settings" -msgstr "Impostazioni Predefinite" - -msgid "Delete" -msgstr "Elimina" - -msgid "Delete ?" -msgstr "Vuoi eliminare ?" - -msgid "Delete Cheat GCT" -msgstr "Elimina Trucchi GCT" - -msgid "Delete Cheat TXT" -msgstr "Elimina Trucchi TXT" - -msgid "Delete Cover Artwork" -msgstr "Elimina la copertina" - -msgid "Delete Disc Artwork" -msgstr "Elimina l'immagine disco" - -msgid "Design:" -msgstr "Grafica:" - -msgid "Developed by" -msgstr "Sviluppato da" - -msgid "Directory does not exist!" -msgstr "La cartella non esiste!" - -msgid "Disc Artwork Download" -msgstr "Scaricamento Imm. Disco" - -msgid "Disc Artwork Path" -msgstr "Percorso Imm. Disco" - -msgid "Disc Images" -msgstr "Immagini Disco" - -msgid "Display" -msgstr "Visualizza" - -msgid "Display as a carousel" -msgstr "Visualizzazione a Carosello" - -msgid "Display as a grid" -msgstr "Visualizzazione a Griglia" - -msgid "Display as a list" -msgstr "Visualizzazione a Elenco" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Vuoi veramente eliminare:" - -msgid "Do you want to apply it now?" -msgstr "Applicare immediatamente?" - -msgid "Do you want to change language?" -msgstr "Vuoi cambiare lingua?" - -msgid "Do you want to download this theme?" -msgstr "Vuoi scaricare questo tema?" - -msgid "Do you want to format:" -msgstr "Vuoi formattare:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Vuoi utilizzare il DOL alternativo funzionante?" - -msgid "Do you wish to update/download all language files?" -msgstr "Vuoi scaricare/aggiornare tutti i file delle lingue?" - -msgid "Done!" -msgstr "Fatto!" - -msgid "Download" -msgstr "Scarica" - -msgid "Download Boxart image?" -msgstr "Scarico la copertina?" - -msgid "Download Discart image?" -msgstr "Scarico l'immagine del disco?" - -msgid "Download Now" -msgstr "Scarica Adesso" - -msgid "Download failed." -msgstr "Download fallito." - -msgid "Download finished" -msgstr "Ho finito di scaricare" - -msgid "Download request failed." -msgstr "Richiesta di download fallita." - -msgid "Downloading Page List:" -msgstr "Sto scaricando l'elenco:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Sto scaricando il file" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Sto scaricando l'immagine:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "ERRORE" - -msgid "ERROR:" -msgstr "ERRORE:" - -msgid "ERROR: Can't set up theme." -msgstr "ERRORE: Impossibile configurare il tema." - -msgid "Error" -msgstr "Errore" - -msgid "Error !" -msgstr "Errore !" - -msgid "Error 002 fix" -msgstr "Correzione Error002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Errore Lettura Disco" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Errore durante il trasferimento dei dati." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Errore..." - -msgid "Error:" -msgstr "Errore:" - -msgid "Extracting files..." -msgstr "Sto scompattando i file..." - -msgid "FAT: Use directories" -msgstr "FAT: Utilizzare le cartelle" - -msgid "Failed formating" -msgstr "Errore Formattazione" - -msgid "Failed to extract." -msgstr "Scompattamento fallito." - -msgid "Failed to open partition" -msgstr "Non si accede alla partizione" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "febbraio" - -msgid "File not found." -msgstr "File non trovato." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Sto terminando l'installazione... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Scorrimento Dischi" - -msgid "Format" -msgstr "Formatta" - -msgid "Formatting, please wait..." -msgstr "Sto Formattando, prego attendere..." - -msgid "Free Space" -msgstr "Spazio libero" - -msgid "Full Shutdown" -msgstr "Completo" - -msgid "GCT Cheatcodes Path" -msgstr "Percorso Trucchi in GCT" - -msgid "GCT File created" -msgstr "File GCT creato" - -msgid "GUI Settings" -msgstr "Impostazioni Loader" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "Nessuna sottocartella contiene il file GXtheme.cfg." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Lingua Gioco" - -msgid "Game Load" -msgstr "Impostazioni Giochi" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Dimensione Gioco" - -msgid "Game Sound Mode" -msgstr "Modalità Suono Giochi" - -msgid "Game Sound Volume" -msgstr "Volume Suono Giochi" - -msgid "Game is already installed:" -msgstr "Gioco già installato:" - -msgid "Game partition" -msgstr "Partizione gioco" - -msgid "Games" -msgstr "Giochi" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Menu HOME" - -msgid "Homebrew Apps Path" -msgstr "Percorso Applic. Homebrew" - -msgid "Homebrew Launcher" -msgstr "Applicazioni Homebrew" - -msgid "Hour" -msgstr "ore" - -msgid "How do you want to update?" -msgstr "Come Vuoi Aggiornare ?" - -msgid "How to Shutdown?" -msgstr "Spegnimento Wii?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Se non hai una connessione WiFi, premi 1 per ottenere un URL dal quale ottenere il file WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Dimensione file %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Dimensione file %0.2fMB" - -msgid "Initializing Network" -msgstr "Inizializzazione Rete" - -msgid "Insert Disk" -msgstr "Inserisci Disco" - -msgid "Insert a Wii Disc!" -msgstr "Inserisci un Disco nella Wii!" - -msgid "Insert an SD-Card to save." -msgstr "Inserisci una scheda SD per Salvare." - -msgid "Insert an SD-Card to use this option." -msgstr "Inserire scheda SD per questa opzione" - -msgid "Install" -msgstr "Installa" - -msgid "Install Error!" -msgstr "Errore Installazione!" - -msgid "Install a game" -msgstr "Installa un gioco" - -msgid "Install partitions" -msgstr "Installa partizioni" - -msgid "Installing content... Ok!" -msgstr "Sto installando il contenuto... Ok!" - -msgid "Installing game:" -msgstr "Sto Installando il gioco:" - -msgid "Installing ticket... Ok!" -msgstr "Sto installando il ticket... Ok!" - -msgid "Installing title... Ok!" -msgstr "Sto installando il titolo... Ok!" - -msgid "Installing wad" -msgstr "Sto installando il WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Hai informazioni che potrebbero esserci utili. Per favore, comunicale al team di sviluppo." - -msgid "Jan" -msgstr "gennaio" - -msgid "July" -msgstr "luglio" - -msgid "June" -msgstr "giugno" - -msgid "Keep" -msgstr "Mantieni" - -msgid "Keyboard" -msgstr "Tastiera" - -msgid "Language File" -msgstr "File Lingue" - -msgid "Language change:" -msgstr "Modifica Lingua:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Percorso Lingue modificato" - -msgid "Load" -msgstr "Carica" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Vuoi caricare il file da: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Vuoi caricare questo DOL come DOL alternativo?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Caricamento Lingua Standard." - -msgid "Loading standard music." -msgstr "Caricamento Musica std." - -msgid "Lock Console" -msgstr "Blocco Console" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "marzo" - -msgid "Mark new games" -msgstr "Evidenzia i nuovi giochi" - -msgid "May" -msgstr "maggio" - -msgid "Missing files" -msgstr "File Mancante/i" - -msgid "Mount DVD drive" -msgstr "Avvia DVD" - -msgid "Music Loop Mode" -msgstr "Modalità Musica Ripetuta" - -msgid "Music Volume" -msgstr "Volume" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Trovato Nuovo Disco" - -msgid "No" -msgstr "" - -msgid "No Cheatfile found" -msgstr "Nessun file trucchi trovato" - -msgid "No DOL file found on disc." -msgstr "Nessun file DOL trovato sul disco." - -msgid "No SD-Card inserted!" -msgstr "Nessuna scheda SD inserita!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Non è stato selezionato alcun trucco" - -msgid "No data could be read." -msgstr "Non è stato possibile leggere alcun dato." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Nessun file mancante!" - -msgid "No new updates." -msgstr "Nessun Aggiornamento." - -msgid "No themes found on the site." -msgstr "Nessun tema trovato sul sito." - -msgid "Not a WAD file." -msgstr "Non è un file WAD." - -msgid "Not a Wii Disc" -msgstr "Non è un Disco Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Memoria insufficiente." - -msgid "Not enough free space!" -msgstr "Spazio Insufficiente!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Formato non supportato." - -msgid "Nov" -msgstr "novembre" - -msgid "OFF" -msgstr "Disattivato" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "ottobre" - -msgid "Official Site:" -msgstr "Sito Ufficiale:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Controllo Genitori" - -msgid "Partition" -msgstr "Partizione" - -msgid "Password" -msgstr "" - -msgid "Password Changed" -msgstr "Password modificata" - -msgid "Password has been changed" -msgstr "Password è stata modificata" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Copialo nel tuo browser per scaricare il file WiiTDB.zip." - -msgid "Patch Country Strings" -msgstr "Patch Regione" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Seleziona da un elenco" - -msgid "Play Count" -msgstr "Giocati" - -msgid "Play Next" -msgstr "Suona Successiva" - -msgid "Play Previous" -msgstr "Suona Precedente" - -msgid "Playing Music:" -msgstr "Sto suonando:" - -msgid "Please wait..." -msgstr "Attendere prego..." - -msgid "Power off the Wii" -msgstr "Spegnimento Wii" - -msgid "Prompts Buttons" -msgstr "Pulsanti" - -msgid "Published by" -msgstr "Pubblicato da" - -msgid "Quick Boot" -msgstr "Avvio Veloce" - -msgid "Reading WAD data... Ok!" -msgstr "Sto leggendo i dati del WAD... Ok!" - -msgid "Receiving file from:" -msgstr "Sto ricevendo il file da:" - -msgid "Released" -msgstr "Rilasciato" - -msgid "Reload SD" -msgstr "Ricarica SD" - -msgid "Remove update" -msgstr "Rimuovi aggiornamento" - -msgid "Rename Game on WBFS" -msgstr "Rinomina Gioco su WBFS" - -msgid "Reset BG Music" -msgstr "Azzera Musica BG" - -msgid "Reset Playcounter" -msgstr "Azzera contatore" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Premere OK per riavviare..." - -msgid "Return" -msgstr "Ritorna" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Torna al Menu Wii" - -msgid "Rumble" -msgstr "Vibrazione" - -msgid "SFX Volume" -msgstr "Volume SFX" - -msgid "Save" -msgstr "Salva" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Salvataggio Elenco Giochi in" - -msgid "Saved" -msgstr "Salvataggio Eseguito" - -msgid "Screensaver" -msgstr "Salvaschermo" - -msgid "Select" -msgstr "Seleziona" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Seleziona un file DOL" - -msgid "Sept" -msgstr "settembre" - -msgid "Set Search-Filter" -msgstr "Cerca Gioco" - -msgid "Settings" -msgstr "Impostazioni" - -msgid "Shutdown System" -msgstr "Spegnimento" - -msgid "Shutdown to Idle" -msgstr "Preaccensione" - -msgid "Sort alphabetically" -msgstr "Ordine alfabetico" - -msgid "Sort by rank" -msgstr "Ordine di preferenza" - -msgid "Sort order by most played" -msgstr "Mostra i più giocati" - -msgid "Sound" -msgstr "Audio" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Un ringraziamento speciale a:" - -msgid "Success" -msgstr "Successo" - -msgid "Success:" -msgstr "Successo:" - -msgid "Successfully Saved" -msgstr "Salvataggio Eseguito" - -msgid "Successfully Updated" -msgstr "Aggiornamento Eseguito" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Aggiornamento Eseguito grazie a www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Eliminato con successo:" - -msgid "Successfully extracted theme." -msgstr "Tema scompattato con successo." - -msgid "Successfully installed:" -msgstr "Installato con successo:" - -msgid "TXT Cheatcodes Path" -msgstr "Percorso Trucchi in TXT" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "La cartella indicata non esiste. Vuoi crearla?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Percorso Download Temi" - -msgid "Theme Downloader" -msgstr "Scaricamento Temi" - -msgid "Theme Path" -msgstr "Percorso Tema" - -msgid "Theme Title:" -msgstr "Titolo del tema:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Restante:" - -msgid "Title Launcher" -msgstr "Schermata Titoli" - -msgid "Titles from WiiTDB" -msgstr "Titoli dal file WiiTDB" - -msgid "Tooltips" -msgstr "Suggerimenti" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Trasferimento fallito." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "Dispositivo USB non Trovato" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX è Protetto" - -msgid "Uninstall" -msgstr "Disinstalla" - -msgid "Uninstall Game" -msgstr "Disinstalla il gioco" - -msgid "Uninstall Menu" -msgstr "Disinstalla Menu" - -msgid "Uninstalling wad" -msgstr "Disinstalla WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Sblocca la Console per usare questa opzione." - -msgid "Unsupported format, try to extract manually." -msgstr "Formato non supportato, provare a scompattare manualmente." - -msgid "Update" -msgstr "Aggiornamento" - -msgid "Update All" -msgstr "Tutti i files" - -msgid "Update DOL" -msgstr "Solo DOL" - -msgid "Update Files" -msgstr "Aggiorna File" - -msgid "Update Path" -msgstr "Percorso Aggiornamento" - -msgid "Update all Language Files" -msgstr "Aggiorna tutti i file delle lingue" - -msgid "Update failed" -msgstr "Aggiornamento Fallito" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Aggiornamento file delle lingue:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "File ZIP installato nella cartella Homebrew" - -msgid "VIDTV Patch" -msgstr "Video Forzato" - -#, c-format -msgid "Version: %s" -msgstr "Versione: %s" - -msgid "Video Mode" -msgstr "Modalità Video" - -msgid "WIP Patches Path" -msgstr "Percorso Patch WIP" - -msgid "Waiting for USB Device" -msgstr "Caricamento Dispositivo USB" - -msgid "Waiting..." -msgstr "Caricamento..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Che cosa vuoi aggiornare?" - -msgid "WiFi Features" -msgstr "Caratteristiche WiFi" - -msgid "Wii Menu" -msgstr "Menu Wii" - -msgid "Wii Settings" -msgstr "Impostazioni Wii" - -msgid "WiiTDB Files" -msgstr "File WiiTDB" - -msgid "WiiTDB Path" -msgstr "Percorso Archivio WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Illuminazione Wii" - -msgid "Wrong Password" -msgstr "Password Errata" - -msgid "Yes" -msgstr "Sì" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Occorre selezionare o formattare una partizione" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "L'indirizzo (URL) è stato salvato in %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "ed i traduttori per la localizzazione del loader" - -msgid "available" -msgstr "disponibile" - -msgid "does not exist!" -msgstr "non esiste!" - -msgid "does not exist! Loading game without cheats." -msgstr "non esiste! Carico il gioco senza i trucchi." - -msgid "files left" -msgstr "file mancanti" - -msgid "files not found on the server!" -msgstr "file non trovato/i sul server!" - -msgid "for FAT/NTFS support" -msgstr "per il supporto FAT/NTFS" - -msgid "for Ocarina" -msgstr "per Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "per l'archivio WiiTDB e le copertine online" - -msgid "for diverse patches" -msgstr "per le numerose correzioni" - -msgid "for his awesome tool LibWiiGui" -msgstr "per la fantastica libreria LibWiiGui" - -msgid "for hosting the themes" -msgstr "per i temi online" - -msgid "for hosting the update files" -msgstr "per gli aggiornamenti online" - -msgid "for the USB Loader source" -msgstr "per il rilascio del codice sorgente" - -msgid "formatted!" -msgstr "formattato!" - -msgid "free" -msgstr "liberi" - -msgid "not set" -msgstr "non inserita" - -msgid "of" -msgstr "di" - -msgid "seconds left" -msgstr "secondi mancanti" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Installa copia 1:1" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Tutti)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Bambini 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 ora" - -#~ msgid "10 min" -#~ msgstr "10 minuti" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Ragazzini 12+)" - -#~ msgid "20 min" -#~ msgstr "20 minuti" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Ragazzi 16+)" - -#~ msgid "3 min" -#~ msgstr "3 minuti" - -#~ msgid "30 min" -#~ msgstr "30 minuti" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Maggiorenni 18+)" - -#~ msgid "5 min" -#~ msgstr "5 minuti" - -#~ msgid "An Error occured" -#~ msgstr "C'è stato un errore" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Sei sicuro di voler attivare il Controllo Genitori?" - -#~ msgid "AutoPatch" -#~ msgstr "Correzione automatica" - -#~ msgid "Both" -#~ msgstr "Entrambi" - -#~ msgid "Checking for Updates" -#~ msgstr "Verifica Aggiornamenti" - -#~ msgid "Console Default" -#~ msgstr "Predefinita Console" - -#~ msgid "Customs/Original" -#~ msgstr "Modific./Origin." - -#~ msgid "Disc Default" -#~ msgstr "Predefinita Disco" - -#~ msgid "DiskFlip" -#~ msgstr "Gira i dischi" - -#~ msgid "Downloading" -#~ msgstr "Sto scaricando" - -#~ msgid "Dutch" -#~ msgstr "Olandese" - -#~ msgid "English" -#~ msgstr "Inglese" - -#~ msgid "French" -#~ msgstr "Francese" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "IDGIOCO_Nomegioco" - -#~ msgid "Game ID" -#~ msgstr "ID Gioco" - -#~ msgid "Game Region" -#~ msgstr "Regione Gioco" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "Nomegioco [IDGIOCO]" - -#~ msgid "German" -#~ msgstr "Tedesco" - -#~ msgid "Invalid PIN code" -#~ msgstr "Codice PIN non valido" - -#~ msgid "Italian" -#~ msgstr "Italiano" - -#~ msgid "Japanese" -#~ msgstr "Giapponese" - -#~ msgid "Korean" -#~ msgstr "Coreano" - -#~ msgid "Left" -#~ msgstr "Sinistra" - -#~ msgid "Like SysMenu" -#~ msgstr "Come SysMenu" - -#~ msgid "Load From SD/USB" -#~ msgstr "Caricamento da SD/USB" - -#~ msgid "Locked" -#~ msgstr "Bloccato" - -#~ msgid "Loop Directory" -#~ msgstr "Cartella Cicli" - -#~ msgid "Loop Music" -#~ msgstr "Musica Ripetuta" - -#~ msgid "Loop Sound" -#~ msgstr "Suono Ripetuto" - -#~ msgid "Neither" -#~ msgstr "Nessuno" - -#~ msgid "Next" -#~ msgstr "Avanti" - -#~ msgid "None" -#~ msgstr "Nessuno" - -#~ msgid "Normal" -#~ msgstr "Normale" - -#~ msgid "ON" -#~ msgstr "Attivato" - -#~ msgid "Only Customs" -#~ msgstr "Modificate" - -#~ msgid "Only Original" -#~ msgstr "Originali" - -#~ msgid "Only for Install" -#~ msgstr "Installa Solamente" - -#~ msgid "Original/Customs" -#~ msgstr "Origin./Modific." - -#~ msgid "Parental Control disabled" -#~ msgstr "Controllo Genitori disabilitato" - -#~ msgid "Play Once" -#~ msgstr "Suona una volta" - -#~ msgid "Prev" -#~ msgstr "Indietro" - -#~ msgid "Random Directory Music" -#~ msgstr "Cartella Musica Casuale" - -#~ msgid "Right" -#~ msgstr "Destra" - -#~ msgid "SChinese" -#~ msgstr "Cinese Moderno" - -#~ msgid "Sound+BGM" -#~ msgstr "Suono+BGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "Suono+Silenzio" - -#~ msgid "Spanish" -#~ msgstr "Spagnolo" - -#~ msgid "System Default" -#~ msgstr "Predefinita Sistema" - -#~ msgid "TChinese" -#~ msgstr "Cinese Tradizionale" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "File Wad installato. Non si può però eliminare dalla scheda SD." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "L'installazione del WAD è fallita con errore %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Non riesco ad aprire il wad da poco scaricato (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Sblocca Controllo Genitori" - -#~ msgid "Unlocked" -#~ msgstr "Sbloccato" - -#~ msgid "Update to" -#~ msgstr "Aggiornamento alla" - -#~ msgid "Updating" -#~ msgstr "Aggiornamento" - -#~ msgid "Updating Language Files..." -#~ msgstr "Aggiornamento file delle lingue..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Aggiornamento file WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Widescreen" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Il Controllo Genitori non è attivo. Se vuoi utilizzare il Controllo Genitori abilitalo nelle Impostazioni della Wii." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Potrebbe non essere caricato correttamente se il tuo System Menu non è aggiornato." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Percorso Codici BCA modificato" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Torna al Menu Wii" - -#~ msgid "Channels" -#~ msgstr "Canali" - -#~ msgid "Checking existing artwork" -#~ msgstr "Verifico le copertine presenti" - -#~ msgid "Confirm" -#~ msgstr "Confermare" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Non è stata trovata alcuna partizione WBFS." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Non è stato possibile accedere alla partizione WBFS" - -#~ msgid "Could not read the disc." -#~ msgstr "Non è stato possibile leggere il disco." - -#~ msgid "Could not set USB." -#~ msgstr "Non è stato possibile impostare la porta USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "Percorso Copertine Modificato" - -#~ msgid "DOL path changed" -#~ msgstr "Percorso File DOL Modificato" - -#~ msgid "Disc Path Changed" -#~ msgstr "Percorso Immagini Disco Modificato" - -#~ msgid "Display favorites" -#~ msgstr "Mostra i preferiti" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Vuoi riprovare per 30 sec?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Attiva Controllo Genitori" - -#~ msgid "Force" -#~ msgstr "Forza" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Percorso Trucchi in GCT modificato" - -#~ msgid "Hermes CIOS" -#~ msgstr "cIOS di Hermes" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Percorso app. Homebrew modificato" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Inserisci una scheda SD per scaricare le immagini." - -#~ msgid "Install not possible" -#~ msgstr "Impossibile installare" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Molto probabilmente le dimensioni non sono divisibili per 4." - -#~ msgid "Network init error" -#~ msgstr "Errore inizializzazione rete" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Non sono stati trovati file .dol o .elf" - -#~ msgid "No Favorites" -#~ msgstr "Nessun Preferito" - -#~ msgid "No USB Device" -#~ msgstr "Nessun Dispositivo USB" - -#~ msgid "No USB Device found." -#~ msgstr "Nessun Dispositivo USB trovato." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Non è stata trovata alcuna partizione WBFS o FAT/NTFS" - -#~ msgid "Normal Covers" -#~ msgstr "Copert. Normali" - -#~ msgid "Not Found" -#~ msgstr "Non Trovato" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Non è un file DOL/ELF." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Azzerare Musica BG?" - -#~ msgid "Save Failed" -#~ msgstr "Salvataggio Fallito" - -#~ msgid "Selected DOL" -#~ msgstr "File DOL selezionato" - -#~ msgid "Standard" -#~ msgstr "Standard" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Percorso Trucchi in TXT modificato" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Percorso Download Temi modificato" - -#~ msgid "Theme Path Changed" -#~ msgstr "Percorso Tema modificato" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX funziona solo con la rev 4 del cIOS di Hermes! Accertarsi di aver installato la rev 4!" - -#~ msgid "Update Path changed." -#~ msgstr "Perc. Aggiornamento Modificato" - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Percorso Patch WIP modificato" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Percorso archivio WiiTDB modificato." - -#~ msgid "You are about to delete " -#~ msgstr "Stai per eliminare " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Hai scelto di visualizzare i preferiti e non ne hai selezionato nessuno" - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "E' in uso una partizione NTFS. Poiché sono possibili errori in scrittura nelle partizioni NTFS, non è possibile installare alcun gioco." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Hai tentato di caricare un'immagine non valida" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "non esiste! Hai fatto qualche casino." - -#~ msgid "file left" -#~ msgstr "file mancante" diff --git a/Languages/japanese.lang b/Languages/japanese.lang deleted file mode 100644 index f58df13c..00000000 --- a/Languages/japanese.lang +++ /dev/null @@ -1,1564 +0,0 @@ -# USB Loader GX language source file. -# japanese.lang - r930 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: hosigumayuugi\n" -"Language-Team: hosigumayuugi\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "WADを保存しました:" - -msgid " could not be downloaded." -msgstr "ダウンロードできませんでした" - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "に保存されました。使用は 自己責任でお願いします。" - -msgid " is not on the server." -msgstr "はサーバーにありません" - -msgid "2D Cover Path" -msgstr "2Dカバーのパス" - -msgid "3D Cover Path" -msgstr "3Dカバーのパス" - -msgid "3D Covers" -msgstr "3Dカバー" - -msgid ">> Deleting tickets..." -msgstr ">> チケットを削除します" - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> チケットの削除...エラー" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> チケットの削除...成功!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> タイトルを削除...エラー" - -msgid ">> Deleting title ...Ok!" -msgstr ">> タイトルを削除...成功!" - -msgid ">> Deleting title contents..." -msgstr ">> タイトルコンテンツを削除します" - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> タイトルコンテンツを削除...エラー" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> タイトルコンテンツを削除...成功!" - -msgid ">> Deleting title..." -msgstr ">> タイトルを削除します" - -msgid ">> Finishing installation..." -msgstr ">> インストールを終了します" - -msgid ">> Installing content #" -msgstr ">> インストール コンテンツ #" - -msgid ">> Installing ticket..." -msgstr ">> チケットをインストール中…" - -msgid ">> Installing title..." -msgstr ">> タイトルをインストールします" - -msgid ">> Reading WAD data..." -msgstr ">> WADデータを読み込み中…" - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> WADデータの読み込み...エラー" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> WADデータの読み込み...成功!" - -msgid "AUTO" -msgstr "自動" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "全領域" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "GXの使用者制限が解除されました" - -msgid "Alternate DOL" -msgstr "代理DOL起動" - -msgid "App Language" -msgstr "使用言語" - -msgid "Apr" -msgstr "4月" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "よろしいですか?" - -msgid "Aug" -msgstr "8月" - -msgid "Author:" -msgstr "制作者:" - -msgid "AutoInit Network" -msgstr "自動接続機能" - -msgid "BCA Codes Path" -msgstr "BCAコードのパス" - -msgid "BETA revisions" -msgstr "β版" - -msgid "Back" -msgstr "もどる" - -msgid "Back to HBC or Wii Menu" -msgstr "HOMEボタンメニューへ" - -msgid "Back to Loader" -msgstr "HBCへ" - -msgid "Backgroundmusic" -msgstr "BGM" - -msgid "Big thanks to:" -msgstr "協力:" - -msgid "Block IOS Reload" -msgstr "IOSの再ロード禁止" - -msgid "Boot/Standard" -msgstr "使用するcIOS" - -msgid "Boot?" -msgstr "起動しますか?" - -msgid "Can't be formatted" -msgstr "初期化できません" - -msgid "Can't create directory" -msgstr "ディレクトリを作成できません" - -msgid "Can't create file" -msgstr "ファイルを作れませんでした" - -msgid "Can't delete:" -msgstr "削除できません" - -msgid "Cancel" -msgstr "キャンセル" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "プレイパスを変更" - -msgid "Cheatfile is blank" -msgstr "チートファイルがありません" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "クリックでカバーをダウンロード" - -msgid "Click to change game ID" -msgstr "クリックでゲームIDを変更" - -msgid "Clock" -msgstr "時計の表示" - -msgid "Close" -msgstr "とじる" - -msgid "Code Download" -msgstr "コードをダウンロード" - -#, c-format -msgid "Coded by: %s" -msgstr "開発: %s" - -msgid "Coding:" -msgstr "開発者:" - -msgid "Connection lost..." -msgstr "接続失敗・・・" - -msgid "Console" -msgstr "状態" - -msgid "Console Locked" -msgstr "GXはロックされています" - -msgid "Console should be unlocked to modify it." -msgstr "変更にはGXのロック解除が必要です" - -msgid "Continue to install game?" -msgstr "このゲームをインストールしますか?" - -msgid "Controllevel" -msgstr "制限レベル" - -msgid "Correct Password" -msgstr "正しい暗証番号です" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "GCTファイルを作成できませんでした" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "DIPモジュールを初期化できません!" - -msgid "Could not initialize network!" -msgstr "ネットワークを初期化できませんでした!" - -msgid "Could not open Disc" -msgstr "ディスクを開けませんでした" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "保存できませんでした" - -msgid "Cover Download" -msgstr "どれをダウンロードしますか" - -msgid "Create" -msgstr "作成" - -msgid "Credits" -msgstr "提供・協力" - -msgid "Custom Paths" -msgstr "パスを変更" - -msgid "DOL Path" -msgstr "DOLのパス" - -msgid "Dec" -msgstr "12月" - -msgid "Default" -msgstr "デフォルト" - -msgid "Default Gamesettings" -msgstr "設定を初期化" - -msgid "Default Settings" -msgstr "設定を初期化" - -msgid "Delete" -msgstr "削除しますか" - -msgid "Delete ?" -msgstr "削除しますか?" - -msgid "Delete Cheat GCT" -msgstr "GCTファイルを削除" - -msgid "Delete Cheat TXT" -msgstr "TXTコードを削除" - -msgid "Delete Cover Artwork" -msgstr "カバー画像を削除" - -msgid "Delete Disc Artwork" -msgstr "ディスク画像を削除" - -msgid "Design:" -msgstr "デザイン:" - -msgid "Developed by" -msgstr "開発者:" - -msgid "Directory does not exist!" -msgstr "ディレクトリがありません" - -msgid "Disc Artwork Download" -msgstr "使用するディスク画像" - -msgid "Disc Artwork Path" -msgstr "ディスク画像のパス" - -msgid "Disc Images" -msgstr "ディスク画像" - -msgid "Display" -msgstr "ゲーム情報" - -msgid "Display as a carousel" -msgstr "回転トレイ風に表示" - -msgid "Display as a grid" -msgstr "格子風に表示" - -msgid "Display as a list" -msgstr "リスト表示" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "本当に削除しますか?" - -msgid "Do you want to apply it now?" -msgstr "適用しますか?" - -msgid "Do you want to change language?" -msgstr "言語を変更しますか?" - -msgid "Do you want to download this theme?" -msgstr "ダウンロードしますか?" - -msgid "Do you want to format:" -msgstr "初期化しますか?" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "既知の代替DOLを利用しますか?" - -msgid "Do you wish to update/download all language files?" -msgstr "すべての言語をダウンロードしますか?" - -msgid "Done!" -msgstr "完了!" - -msgid "Download" -msgstr "ダウンロード" - -msgid "Download Boxart image?" -msgstr "画像をダウンロードしますか?" - -msgid "Download Discart image?" -msgstr "画像をダウンロードしますか?" - -msgid "Download Now" -msgstr "ダウンロード" - -msgid "Download failed." -msgstr "ダウンロードに失敗しました" - -msgid "Download finished" -msgstr "ダウンロードが終了しました" - -msgid "Download request failed." -msgstr "ダウンロードに失敗しました" - -msgid "Downloading Page List:" -msgstr "リストをダウンロード中" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "ファイルをダウンロード中" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "画像をダウンロード中" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "エラー" - -msgid "ERROR:" -msgstr "エラー:" - -msgid "ERROR: Can't set up theme." -msgstr "テーマを適用できませんでした" - -msgid "Error" -msgstr "エラー" - -msgid "Error !" -msgstr "エラー!" - -msgid "Error 002 fix" -msgstr "Error002対策" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "読み込みに失敗しました" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "転送中にエラーが発生しました" - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "エラー…" - -msgid "Error:" -msgstr "エラー:" - -msgid "Extracting files..." -msgstr "解凍中です…" - -msgid "FAT: Use directories" -msgstr "FATで階層を使用" - -msgid "Failed formating" -msgstr "初期化に失敗しました" - -msgid "Failed to extract." -msgstr "解凍に失敗しました" - -msgid "Failed to open partition" -msgstr "領域を開けませんでした" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "2月" - -msgid "File not found." -msgstr "ファイルが見つかりません" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "インストールの完了...完了しました" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "ゲームリストの回転" - -msgid "Format" -msgstr "初期化" - -msgid "Formatting, please wait..." -msgstr "初期化中です、暫くお待ち下さい..." - -msgid "Free Space" -msgstr "空き" - -msgid "Full Shutdown" -msgstr "シャットダウン" - -msgid "GCT Cheatcodes Path" -msgstr "GCTファイルのパス" - -msgid "GCT File created" -msgstr "GCTファイルを作成しました" - -msgid "GUI Settings" -msgstr "基本設定" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "設定ファイルが見つかりません" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "ゲームの言語" - -msgid "Game Load" -msgstr "読み込みの設定" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "サイズ" - -msgid "Game Sound Mode" -msgstr "サウンドモード" - -msgid "Game Sound Volume" -msgstr "サウンドの音量" - -msgid "Game is already installed:" -msgstr "このゲームは既にインストールされています:" - -msgid "Game partition" -msgstr "ゲーム領域のみ" - -msgid "Games" -msgstr "総ゲーム数" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "HOMEボタンメニュー" - -msgid "Homebrew Apps Path" -msgstr "Homebrewのパス" - -msgid "Homebrew Launcher" -msgstr "Homebrewランチャー" - -msgid "Hour" -msgstr "時間" - -msgid "How do you want to update?" -msgstr "どう更新しますか?" - -msgid "How to Shutdown?" -msgstr "どう終了しますか?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "1ボタンを押すと WiiTDB.zip のURLを保存します" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "ファイルを受信中 %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "ファイルを受信中 %0.2fMB" - -msgid "Initializing Network" -msgstr "接続中・・・" - -msgid "Insert Disk" -msgstr "ディスクを入れてください" - -msgid "Insert a Wii Disc!" -msgstr "Wiiディスクを挿入して下さい!" - -msgid "Insert an SD-Card to save." -msgstr "保存するためにSDを挿入して下さい" - -msgid "Insert an SD-Card to use this option." -msgstr "このオプションを使用するためSDカードを挿入して下さい" - -msgid "Install" -msgstr "インストール" - -msgid "Install Error!" -msgstr "インストールエラー!" - -msgid "Install a game" -msgstr "ゲームをインストール" - -msgid "Install partitions" -msgstr "保存する領域" - -msgid "Installing content... Ok!" -msgstr "コンテンツをインストール...成功!" - -msgid "Installing game:" -msgstr "ゲームをインストール中:" - -msgid "Installing ticket... Ok!" -msgstr "チケットをインストール...成功!" - -msgid "Installing title... Ok!" -msgstr "タイトルをインストール...成功!" - -msgid "Installing wad" -msgstr "WADをインストールします" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "この情報は開発者までお知らせください" - -msgid "Jan" -msgstr "1月" - -msgid "July" -msgstr "7月" - -msgid "June" -msgstr "6月" - -msgid "Keep" -msgstr "保存" - -msgid "Keyboard" -msgstr "キーボードのタイプ" - -msgid "Language File" -msgstr "言語ファイル" - -msgid "Language change:" -msgstr "言語の変更" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "言語のパスを変更しました" - -msgid "Load" -msgstr "はじめる" - -#, c-format -msgid "Load file from: %s ?" -msgstr "%sからファイルをロードしますか?" - -msgid "Load this DOL as alternate DOL?" -msgstr "このDOLを代替DOLとしてロードしますか?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "標準の言語に変更しますか" - -msgid "Loading standard music." -msgstr "初期設定に戻しますか" - -msgid "Lock Console" -msgstr "GXをロック" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "3月" - -msgid "Mark new games" -msgstr "Newマークの表示機能" - -msgid "May" -msgstr "5月" - -msgid "Missing files" -msgstr "個の画像" - -msgid "Mount DVD drive" -msgstr "DVDを起動" - -msgid "Music Loop Mode" -msgstr "ループ機能" - -msgid "Music Volume" -msgstr "BGMの音量" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "新しいディスクが検出されました" - -msgid "No" -msgstr "いいえ" - -msgid "No Cheatfile found" -msgstr "チートファイルが見つかりません" - -msgid "No DOL file found on disc." -msgstr "ディスク内に.DOLがありません" - -msgid "No SD-Card inserted!" -msgstr "SDカードが挿入されていません!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "何も選ばれていません" - -msgid "No data could be read." -msgstr "読み込みに失敗しました" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "必要ありません" - -msgid "No new updates." -msgstr "更新はありません" - -msgid "No themes found on the site." -msgstr "テーマが見つかりません" - -msgid "Not a WAD file." -msgstr "WADファイルではありません" - -msgid "Not a Wii Disc" -msgstr "Wiiディスクではありません" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "空メモリが不足しています" - -msgid "Not enough free space!" -msgstr "空容量が不足しています!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "対応していない形式です!" - -msgid "Nov" -msgstr "11月" - -msgid "OFF" -msgstr "使わない" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "10月" - -msgid "Official Site:" -msgstr "公式サイト:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "ペアレンタルコントロール" - -msgid "Partition" -msgstr "使用する領域" - -msgid "Password" -msgstr "暗証番号" - -msgid "Password Changed" -msgstr "暗証番号の変更" - -msgid "Password has been changed" -msgstr "暗証番号を変更しました" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "ブラウザに貼付けるとWiiTDB.zipをダウンロードできます。" - -msgid "Patch Country Strings" -msgstr "日本語パッチ" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "リストから選択" - -msgid "Play Count" -msgstr "プレイ回数" - -msgid "Play Next" -msgstr "次へ" - -msgid "Play Previous" -msgstr "前へ" - -msgid "Playing Music:" -msgstr "再生中" - -msgid "Please wait..." -msgstr "しばらくお待ちください" - -msgid "Power off the Wii" -msgstr "Wiiの電源を切る" - -msgid "Prompts Buttons" -msgstr "ウインドウサイズ" - -msgid "Published by" -msgstr "発売元:" - -msgid "Quick Boot" -msgstr "ワンボタン起動" - -msgid "Reading WAD data... Ok!" -msgstr "WADデータの読み込み...成功!" - -msgid "Receiving file from:" -msgstr "ファイルを受信中:" - -msgid "Released" -msgstr "発売日" - -msgid "Reload SD" -msgstr "SDを再読み込み" - -msgid "Remove update" -msgstr "更新を取り除く" - -msgid "Rename Game on WBFS" -msgstr "WBFS内のゲーム名を変更" - -msgid "Reset BG Music" -msgstr "BGMをリセット" - -msgid "Reset Playcounter" -msgstr "プレイ回数をリセット" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "再起動します" - -msgid "Return" -msgstr "もどる" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Wiiメニューへもどる" - -msgid "Rumble" -msgstr "Wiiリモコンの振動機能" - -msgid "SFX Volume" -msgstr "効果音の音量" - -msgid "Save" -msgstr "保存" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "リストを保存しますか" - -msgid "Saved" -msgstr "保存しました" - -msgid "Screensaver" -msgstr "画面焼け軽減機能" - -msgid "Select" -msgstr "選択" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "DOLを選択" - -msgid "Sept" -msgstr "9月" - -msgid "Set Search-Filter" -msgstr "検索" - -msgid "Settings" -msgstr "設定" - -msgid "Shutdown System" -msgstr "シャットダウン" - -msgid "Shutdown to Idle" -msgstr "スタンバイ" - -msgid "Sort alphabetically" -msgstr "名前順に並び替え" - -msgid "Sort by rank" -msgstr "ランク順に並び替え" - -msgid "Sort order by most played" -msgstr "プレイ回数が多い順に並び替え" - -msgid "Sound" -msgstr "サウンド" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "スペシャルサンクス:" - -msgid "Success" -msgstr "成功" - -msgid "Success:" -msgstr "成功:" - -msgid "Successfully Saved" -msgstr "保存に成功しました" - -msgid "Successfully Updated" -msgstr "更新しました" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "更新しました www.techjawa.comに感謝!" - -msgid "Successfully deleted:" -msgstr "削除に成功しました" - -msgid "Successfully extracted theme." -msgstr "テーマの解凍を完了しました." - -msgid "Successfully installed:" -msgstr "このゲームをインストールしました" - -msgid "TXT Cheatcodes Path" -msgstr "TXTコードのパス" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "ディレクトリがありません。作りますか?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "テーマを保存するパス" - -msgid "Theme Downloader" -msgstr "テーマをダウンロード" - -msgid "Theme Path" -msgstr "テーマのパス" - -msgid "Theme Title:" -msgstr "テーマ名:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "残り時間:" - -msgid "Title Launcher" -msgstr "チャンネルランチャー" - -msgid "Titles from WiiTDB" -msgstr "ゲーム名のリスト" - -msgid "Tooltips" -msgstr "ヒントバルーン" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "転送を失敗しました" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USBデバイスを検出できませんでした" - -msgid "USB Loader GX is protected" -msgstr "USB Loaderは保護されています" - -msgid "Uninstall" -msgstr "アンインストール" - -msgid "Uninstall Game" -msgstr "ゲームをアンインストール" - -msgid "Uninstall Menu" -msgstr "アンインストール" - -msgid "Uninstalling wad" -msgstr "WADをアンインストール" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "ロックを解除してください" - -msgid "Unsupported format, try to extract manually." -msgstr "非対応の形式なので自己解凍してください" - -msgid "Update" -msgstr "更新" - -msgid "Update All" -msgstr "全て" - -msgid "Update DOL" -msgstr "DOLのみ" - -msgid "Update Files" -msgstr "すべて更新" - -msgid "Update Path" -msgstr "GXのパス" - -msgid "Update all Language Files" -msgstr "全言語ファイルを更新" - -msgid "Update failed" -msgstr "更新に失敗しました" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "言語ファイルを更新中:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "インストール済みディレクトリにZIPを送信しました" - -msgid "VIDTV Patch" -msgstr "映像パッチ" - -#, c-format -msgid "Version: %s" -msgstr "バージョン: %s" - -msgid "Video Mode" -msgstr "映像の出力方法" - -msgid "WIP Patches Path" -msgstr "WIPパッチのパス" - -msgid "Waiting for USB Device" -msgstr "USBデバイスの応答待ち" - -msgid "Waiting..." -msgstr "待機中…" - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "何を更新しますか?" - -msgid "WiFi Features" -msgstr "ネットワーク対応" - -msgid "Wii Menu" -msgstr "Wiiメニューへ" - -msgid "Wii Settings" -msgstr "データ管理" - -msgid "WiiTDB Files" -msgstr "ゲーム名リスト" - -msgid "WiiTDB Path" -msgstr "ゲーム名リストのパス" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "スロット点灯機能" - -msgid "Wrong Password" -msgstr "暗証番号を間違えています" - -msgid "Yes" -msgstr "はい" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "領域を選択するか初期化してください" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "%sWiiTDB_URL.txtにURLを保存しました" - -msgid "and translaters for language files updates" -msgstr "/ K-M …日本語への翻訳" - -msgid "available" -msgstr "があります" - -msgid "does not exist!" -msgstr "存在しません!" - -msgid "does not exist! Loading game without cheats." -msgstr "存在しないので チートなしで起動します" - -msgid "files left" -msgstr "個未完了" - -msgid "files not found on the server!" -msgstr "個サーバーにありませんでした…" - -msgid "for FAT/NTFS support" -msgstr "…FATとNTFSへの対応" - -msgid "for Ocarina" -msgstr "…Ocarinaを制作" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "WiiTDB…様々な画像を配布" - -msgid "for diverse patches" -msgstr "…様々なパッチを制作" - -msgid "for his awesome tool LibWiiGui" -msgstr "…LibWiiGuiを制作" - -msgid "for hosting the themes" -msgstr "…テーマを配布" - -msgid "for hosting the update files" -msgstr "…更新ファイルを配布" - -msgid "for the USB Loader source" -msgstr "…ソースを制作" - -msgid "formatted!" -msgstr "初期化を完了しました!" - -msgid "free" -msgstr "空き" - -msgid "not set" -msgstr "セットされていません" - -msgid "of" -msgstr "中" - -msgid "seconds left" -msgstr "秒で完了" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "フルコピー" - -#~ msgid "0 (Everyone)" -#~ msgstr "0(セットしない)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1(C以上を制限)" - -#~ msgid "1 hour" -#~ msgstr "1時間" - -#~ msgid "10 min" -#~ msgstr "10分" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2(D以上を制限)" - -#~ msgid "20 min" -#~ msgstr "20分" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3(Z以上を制限)" - -#~ msgid "3 min" -#~ msgstr "3分" - -#~ msgid "30 min" -#~ msgstr "30分" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4(Zを制限)" - -#~ msgid "5 min" -#~ msgstr "5分" - -#~ msgid "An Error occured" -#~ msgstr "エラーが起きました" - -#~ msgid "Anti" -#~ msgstr "排除する" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "使用制限機能を使用しますか?" - -#~ msgid "AutoPatch" -#~ msgstr "自動パッチ" - -#~ msgid "Both" -#~ msgstr "IDとリージョンを表示" - -#~ msgid "Checking for Updates" -#~ msgstr "最新版を確認中" - -#~ msgid "Console Default" -#~ msgstr "GXのデフォルト" - -#~ msgid "Customs/Original" -#~ msgstr "カスタムを優先" - -#~ msgid "Disc Default" -#~ msgstr "ディスクのデフォルト" - -#~ msgid "DiskFlip" -#~ msgstr "ディスクの回転風" - -#~ msgid "Downloading" -#~ msgstr "ダウンロードします" - -#~ msgid "Dutch" -#~ msgstr "オランダ語" - -#~ msgid "English" -#~ msgstr "英語" - -#~ msgid "French" -#~ msgstr "フランス語" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "ゲームID_ゲーム名" - -#~ msgid "Game ID" -#~ msgstr "IDのみ" - -#~ msgid "Game Region" -#~ msgstr "リージョンのみ" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "ゲーム名 [ゲームID]" - -#~ msgid "German" -#~ msgstr "ドイツ語" - -#~ msgid "Invalid PIN code" -#~ msgstr "暗証番号を間違えています" - -#~ msgid "Italian" -#~ msgstr "イタリア語" - -#~ msgid "Japanese" -#~ msgstr "日本語" - -#~ msgid "Korean" -#~ msgstr "韓国語" - -#~ msgid "Left" -#~ msgstr "左ボタンで" - -#~ msgid "Like SysMenu" -#~ msgstr "Wiiメニュー風" - -#~ msgid "Load From SD/USB" -#~ msgstr "SD/USBからロード" - -#~ msgid "Locked" -#~ msgstr "ロックされています" - -#~ msgid "Loop Directory" -#~ msgstr "フォルダ内でループ" - -#~ msgid "Loop Music" -#~ msgstr "ループさせる" - -#~ msgid "Loop Sound" -#~ msgstr "ループさせる" - -#~ msgid "Neither" -#~ msgstr "非表示" - -#~ msgid "Next" -#~ msgstr "左へ" - -#~ msgid "None" -#~ msgstr "なし" - -#~ msgid "Normal" -#~ msgstr "ワイド" - -#~ msgid "ON" -#~ msgstr "使う" - -#~ msgid "Only Customs" -#~ msgstr "カスタムのみ" - -#~ msgid "Only Original" -#~ msgstr "公式のみ" - -#~ msgid "Only for Install" -#~ msgstr "インストール中のみ" - -#~ msgid "Original/Customs" -#~ msgstr "公式を優先" - -#~ msgid "Parental Control disabled" -#~ msgstr "使用制限機能を無効にしました" - -#~ msgid "Play Once" -#~ msgstr "一度だけ再生" - -#~ msgid "Prev" -#~ msgstr "左へ" - -#~ msgid "Random Directory Music" -#~ msgstr "フォルダ内でランダム再生" - -#~ msgid "Right" -#~ msgstr "右ボタンで" - -#~ msgid "SChinese" -#~ msgstr "簡体中国語" - -#~ msgid "Sound+BGM" -#~ msgstr "サウンドとBGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "サウンドのみ" - -#~ msgid "Spanish" -#~ msgstr "スペイン語" - -#~ msgid "System Default" -#~ msgstr "Wiiのデフォルト" - -#~ msgid "TChinese" -#~ msgstr "繁体中国語" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WADファイルをインストールしましたが、SDから削除できませんでした" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "WADのインストールはエラー:%ldで失敗しました" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "ダウンロード中のためWADを開けません (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "使用制限機能を解除" - -#~ msgid "Unlocked" -#~ msgstr "ロックされていません" - -#~ msgid "Update to" -#~ msgstr "最新版:" - -#~ msgid "Updating" -#~ msgstr "更新中 -" - -#~ msgid "Updating Language Files..." -#~ msgstr "言語ファイルを更新中..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "WiiTDB.zipを更新中" - -#~ msgid "Widescreen Fix" -#~ msgstr "普通" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Wii本体設定で使用制限機能を有効にしてください" - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Wiiが更新されていなければ正常に起動できない可能性があります" - -#~ msgid "BCA Codes Path changed" -#~ msgstr "BCAコードのパスを変更しました" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Wiiメニューへ" - -#~ msgid "Channels" -#~ msgstr "チャンネル" - -#~ msgid "Checking existing artwork" -#~ msgstr "カバーをチェックしています" - -#~ msgid "Confirm" -#~ msgstr "確認" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "WBFS領域が見つかりませんでした" - -#~ msgid "Could not open WBFS partition" -#~ msgstr "WBFS領域を開けませんでした" - -#~ msgid "Could not read the disc." -#~ msgstr "ディスクを読めませんでした" - -#~ msgid "Could not set USB." -#~ msgstr "USBをセットできません" - -#~ msgid "Cover Path Changed" -#~ msgstr "カバーのパスを変更しました" - -#~ msgid "DOL path changed" -#~ msgstr "DOLのパスが変更されました" - -#~ msgid "Disc Path Changed" -#~ msgstr "ディスク画像のパスを変更しました" - -#~ msgid "Display favorites" -#~ msgstr "お気に入りのみ表示" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "再試行しますか?" - -#~ msgid "Enable Parental Control" -#~ msgstr "使用制限機能を有効化" - -#~ msgid "Force" -#~ msgstr "強制" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "パスを変更しました" - -#~ msgid "Hermes CIOS" -#~ msgstr "注意事項" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Homebrewのパスを変更しました" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "画像を保存するためにSDを挿入して下さい" - -#~ msgid "Install not possible" -#~ msgstr "インストールできません" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "4で割り切れない寸法があります" - -#~ msgid "Network init error" -#~ msgstr "接続初期化エラー" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "DOL(ELF)ファイルがありません" - -#~ msgid "No Favorites" -#~ msgstr "お気に入りが選ばれていません" - -#~ msgid "No USB Device" -#~ msgstr "USB機器がありません" - -#~ msgid "No USB Device found." -#~ msgstr "USB機器が検出されていません" - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "WBFS/FAT/NTFS領域が見つかりません" - -#~ msgid "Normal Covers" -#~ msgstr "2Dカバー" - -#~ msgid "Not Found" -#~ msgstr "見つかりません" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "DOL(ELF)ファイルではありません" - -#~ msgid "Reset to standard BGM?" -#~ msgstr "BGMを初期状態に戻しますか?" - -#~ msgid "Save Failed" -#~ msgstr "保存に失敗しました" - -#~ msgid "Selected DOL" -#~ msgstr "DOLの場所" - -#~ msgid "Standard" -#~ msgstr "標準" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXTコードのパスを変更しました" - -#~ msgid "Theme Download Path changed" -#~ msgstr "パスを変更しました" - -#~ msgid "Theme Path Changed" -#~ msgstr "テーマのパスを変更しました" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "cIOS222と223はrev4の場合のみ 使用できます" - -#~ msgid "Update Path changed." -#~ msgstr "GXのパスを変更しました" - -#~ msgid "WIP Patches Path changed" -#~ msgstr "WIPパッチのパスを変更しました" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "ゲーム名リストのパスを変更しました." - -#~ msgid "You are about to delete " -#~ msgstr "削除していいですか " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "お気に入りの登録がありません" - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "NTFS領域にインストール中にエラーが発生するとインストールに失敗します" - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "読み込めない画像があります" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "存在しません!" - -#~ msgid "file left" -#~ msgstr "個未完了" diff --git a/Languages/korean.lang b/Languages/korean.lang deleted file mode 100644 index 8b9a467b..00000000 --- a/Languages/korean.lang +++ /dev/null @@ -1,1468 +0,0 @@ -# USB Loader GX language source file. -# korean.lang - r719 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: nextos@korea.com\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad 저장은:" - -msgid " could not be downloaded." -msgstr " 다운로드할수 없음." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " 저장됨. 문자는 검증되지 않았음. 몇몇의 코드는 정상동작을 안할수있음. 만약 문제가 있다면, 문서편집기로 문서를 확인하기 바람." - -msgid " is not on the server." -msgstr " 은 서버에 없어요." - -msgid "2D Cover Path" -msgstr "2D 표지 경로" - -msgid "3D Cover Path" -msgstr "3D 표지 경로" - -msgid "3D Covers" -msgstr "3D 커버" - -msgid ">> Deleting tickets..." -msgstr ">> 티켓 삭제중..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> 티켓 삭제 ...에러! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> 티켓 삭제 ...성공! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> 타이틀 삭제 ...에러! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> 타이틀 삭제 ...성공!" - -msgid ">> Deleting title contents..." -msgstr ">> 타이틀 내용 삭제중 ..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> 타이틀 내용 삭제 ...에러! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> 타이틀 내용 삭제 ...성공!" - -msgid ">> Deleting title..." -msgstr ">> 타이틀 삭제..." - -msgid ">> Finishing installation..." -msgstr ">> 인스톨 종료중..." - -msgid ">> Installing content #" -msgstr ">> 컨텐츠 인스톨중 #" - -msgid ">> Installing ticket..." -msgstr ">> 티켓 인스톨중..." - -msgid ">> Installing title..." -msgstr ">> 타이틀 인스톨중..." - -msgid ">> Reading WAD data..." -msgstr ">> WAD 데이터 읽는중..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> WAD 데이타 읽기...에러! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> WAD 데이터 읽기...성공!" - -msgid "AUTO" -msgstr "자동" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "모든 USB로더 GX 기능 잠금 해제." - -msgid "Alternate DOL" -msgstr "Alternate DOL" - -msgid "App Language" -msgstr "USB 로더 언어" - -msgid "Apr" -msgstr "4월" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "확실합니까?" - -msgid "Aug" -msgstr "8월" - -msgid "Author:" -msgstr "" - -msgid "AutoInit Network" -msgstr "자동네트웍설정" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "뒤로" - -msgid "Back to HBC or Wii Menu" -msgstr "홈브류 메뉴 또는 Wii 메뉴로" - -msgid "Back to Loader" -msgstr "로더로 돌아감" - -msgid "Backgroundmusic" -msgstr "배경음악" - -msgid "Big thanks to:" -msgstr "감사 :" - -msgid "Block IOS Reload" -msgstr "IOS 재로딩 막음" - -msgid "Boot/Standard" -msgstr "기본 부팅설정" - -msgid "Boot?" -msgstr "부팅?" - -msgid "Can't be formatted" -msgstr "포맷할 수 없습니다." - -msgid "Can't create directory" -msgstr "디렉토리를 만들 수 없습니다" - -msgid "Can't create file" -msgstr "" - -msgid "Can't delete:" -msgstr "삭제할 수 없습니다:" - -msgid "Cancel" -msgstr "취소" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "치트화일 내용없음" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "표지를 다운하려면 클릭하세요" - -msgid "Click to change game ID" -msgstr "게임 ID를 변경하려련 클릭하세요" - -msgid "Clock" -msgstr "시계" - -msgid "Close" -msgstr "닫기" - -msgid "Code Download" -msgstr "코드 다운로드" - -#, c-format -msgid "Coded by: %s" -msgstr "Coded by: %s" - -msgid "Coding:" -msgstr "코디:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "콘솔" - -msgid "Console Locked" -msgstr "콘솔 잠김" - -msgid "Console should be unlocked to modify it." -msgstr "변경하려면 콘솔 잠김을 해제하세요." - -msgid "Continue to install game?" -msgstr "계속 설치하겠습니까?" - -msgid "Controllevel" -msgstr "조정 레벨" - -msgid "Correct Password" -msgstr "올바른 비밀번호" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "GCT 파일을 생성할수 없음" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "DIP 모듈 초기화 실패!" - -msgid "Could not initialize network!" -msgstr "네트워크 초기화 실패!" - -msgid "Could not open Disc" -msgstr "디스크를 열 수 없습니다." - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "" - -msgid "Cover Download" -msgstr "표지 다운로드" - -msgid "Create" -msgstr "생성" - -msgid "Credits" -msgstr "Credits" - -msgid "Custom Paths" -msgstr "Custom Paths" - -msgid "DOL Path" -msgstr "DOL 패치" - -msgid "Dec" -msgstr "12월" - -msgid "Default" -msgstr "기본값" - -msgid "Default Gamesettings" -msgstr "기본 게임설정" - -msgid "Default Settings" -msgstr "기본 설정" - -msgid "Delete" -msgstr "삭제" - -msgid "Delete ?" -msgstr "삭제 ?" - -msgid "Delete Cheat GCT" -msgstr "" - -msgid "Delete Cheat TXT" -msgstr "치트문서 삭제" - -msgid "Delete Cover Artwork" -msgstr "박스아트 삭제" - -msgid "Delete Disc Artwork" -msgstr "삭제 Discart" - -msgid "Design:" -msgstr "디자인:" - -msgid "Developed by" -msgstr "디자인 by" - -msgid "Directory does not exist!" -msgstr "" - -msgid "Disc Artwork Download" -msgstr "디스크 이미지 다운로드" - -msgid "Disc Artwork Path" -msgstr "디스크 이미지 경로" - -msgid "Disc Images" -msgstr "디스크 이미지" - -msgid "Display" -msgstr "화면 표시" - -msgid "Display as a carousel" -msgstr "그림으로 표시" - -msgid "Display as a grid" -msgstr "격자 무니 표시" - -msgid "Display as a list" -msgstr "리스트로 표시" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "정말로 삭제하겠습니까:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "정말로 언어를 변경할까요?" - -msgid "Do you want to download this theme?" -msgstr "" - -msgid "Do you want to format:" -msgstr "포맷하겠습니까:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "정말로 Alt. DOL을 사용할까요?" - -msgid "Do you wish to update/download all language files?" -msgstr "정말로 모든 언어화일을 업데이트하고 다운로드 할까요?" - -msgid "Done!" -msgstr "완료!" - -msgid "Download" -msgstr "" - -msgid "Download Boxart image?" -msgstr "박스 이미지를 다운로드 할까요?" - -msgid "Download Discart image?" -msgstr "디스크이미지를 다운로드 할까요?" - -msgid "Download Now" -msgstr "다운로드 시작" - -msgid "Download failed." -msgstr "" - -msgid "Download finished" -msgstr "다운로드 완료" - -msgid "Download request failed." -msgstr "" - -msgid "Downloading Page List:" -msgstr "" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "파일 다운로드 중:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "에러" - -msgid "ERROR:" -msgstr "에러:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "에러" - -msgid "Error !" -msgstr "에러 !" - -msgid "Error 002 fix" -msgstr "Error 002 fix" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "디스크 읽기 오류" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "데이터 전송중 에러." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "에러..." - -msgid "Error:" -msgstr "에러:" - -msgid "Extracting files..." -msgstr "" - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "포맷 실패" - -msgid "Failed to extract." -msgstr "" - -msgid "Failed to open partition" -msgstr "파티션 열기 실패" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "2월" - -msgid "File not found." -msgstr "파일을 찾을수가 없네요." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "설치 종료중... 성공!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "좌/우 설정" - -msgid "Format" -msgstr "포맷" - -msgid "Formatting, please wait..." -msgstr "포맷 중. 기다려 주세요..." - -msgid "Free Space" -msgstr "여유 공간" - -msgid "Full Shutdown" -msgstr "완전히 끄기" - -msgid "GCT Cheatcodes Path" -msgstr "치트코드 경로" - -msgid "GCT File created" -msgstr "GCT 파일 생성됨" - -msgid "GUI Settings" -msgstr "GUI 설정" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "언어" - -msgid "Game Load" -msgstr "게임 로드" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "게임 용량" - -msgid "Game Sound Mode" -msgstr "" - -msgid "Game Sound Volume" -msgstr "" - -msgid "Game is already installed:" -msgstr "게임이 이미 설치되어 있습니다." - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "게임" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "HOME 메뉴" - -msgid "Homebrew Apps Path" -msgstr "홈브류 경로" - -msgid "Homebrew Launcher" -msgstr "홈브류 런처" - -msgid "Hour" -msgstr "시간" - -msgid "How do you want to update?" -msgstr "업데이트 할까요?" - -msgid "How to Shutdown?" -msgstr "어떻게 종료할까요?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "WiFi가 없다면 WiiTDB.zip을 없기위한 URL을 위하여 1을 누르세요" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "화일 수신중 %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "화일 수신중 %0.2fMB" - -msgid "Initializing Network" -msgstr "네트워크 초기화" - -msgid "Insert Disk" -msgstr "디스크를 넣어주세요" - -msgid "Insert a Wii Disc!" -msgstr "Wii 디스크를 넣으세요!" - -msgid "Insert an SD-Card to save." -msgstr "저장할 SD카드를 넣으세요." - -msgid "Insert an SD-Card to use this option." -msgstr "이 옵션을 사용할 SD카드를 넣으세요." - -msgid "Install" -msgstr "설치" - -msgid "Install Error!" -msgstr "설치 에러!" - -msgid "Install a game" -msgstr "게임을 설치할까요" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "컨텐츠 인스톨중...성공!" - -msgid "Installing game:" -msgstr "게임 설치 중:" - -msgid "Installing ticket... Ok!" -msgstr "티켓 설치중... Ok!" - -msgid "Installing title... Ok!" -msgstr "타이틀 설치중... Ok!" - -msgid "Installing wad" -msgstr "Wad 설치중" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "우리를 도울수 있는 정보를 가지고 있군요. 이정보를 DEV 팀에 전달해주세요." - -msgid "Jan" -msgstr "1월" - -msgid "July" -msgstr "7월" - -msgid "June" -msgstr "6월" - -msgid "Keep" -msgstr "보관" - -msgid "Keyboard" -msgstr "키보드" - -msgid "Language File" -msgstr "언어화일" - -msgid "Language change:" -msgstr "언어 변경:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "언어경로 변경됨." - -msgid "Load" -msgstr "로드" - -#, c-format -msgid "Load file from: %s ?" -msgstr "화일 로드는 %s 에서?" - -msgid "Load this DOL as alternate DOL?" -msgstr "이 DOL화일을 alternate DOL로 로딩할까요?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "표준 언어로 로딩." - -msgid "Loading standard music." -msgstr "표중 음악으로 로딩." - -msgid "Lock Console" -msgstr "콘솔 잠금" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "4월" - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "5월" - -msgid "Missing files" -msgstr "파일 누락" - -msgid "Mount DVD drive" -msgstr "" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "음량" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "" - -msgid "No" -msgstr "아니오" - -msgid "No Cheatfile found" -msgstr "치트화일 없음" - -msgid "No DOL file found on disc." -msgstr "디스크에 DOL화일이 없음." - -msgid "No SD-Card inserted!" -msgstr "SD카드가 없습니다!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "" - -msgid "No data could be read." -msgstr "데이터를 읽을수가 없음." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "누락 파일 없음!" - -msgid "No new updates." -msgstr "새로운 업데이트 없음." - -msgid "No themes found on the site." -msgstr "" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Wii 디스크가 아닙니다" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "메모리가 부족해요." - -msgid "Not enough free space!" -msgstr "여유 공간이 부족합니다!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "지원되는 포맷이 아니에요!" - -msgid "Nov" -msgstr "11월" - -msgid "OFF" -msgstr "꺼짐" - -msgid "OK" -msgstr "확인" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "10월" - -msgid "Official Site:" -msgstr "공식 사이트:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "자녀보호기능" - -msgid "Partition" -msgstr "파티션" - -msgid "Password" -msgstr "비밀번호" - -msgid "Password Changed" -msgstr "비밀번호 변경됨" - -msgid "Password has been changed" -msgstr "비밀번호가 변경되었습니다" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "WiiTDB.zip파일을 얻으려면 이것을 브라우져로 붙이세요." - -msgid "Patch Country Strings" -msgstr "패치 컨트리 스트링" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "리스트로 부터 고르기" - -msgid "Play Count" -msgstr "실행 횟수" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "" - -msgid "Power off the Wii" -msgstr "Wii 전원 끄기" - -msgid "Prompts Buttons" -msgstr "프롬프트/버튼" - -msgid "Published by" -msgstr "출판자" - -msgid "Quick Boot" -msgstr "게임 바로실행" - -msgid "Reading WAD data... Ok!" -msgstr "WAD 데이터 읽기... 성공!" - -msgid "Receiving file from:" -msgstr "파일 추출 :" - -msgid "Released" -msgstr "릴리즈됨" - -msgid "Reload SD" -msgstr "SD카드 읽기" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "WBFS에서 게임 이름 변경" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "실행횟수 리셋" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "재시작..." - -msgid "Return" -msgstr "돌아가기" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "위 메뉴로 돌아가기" - -msgid "Rumble" -msgstr "진동" - -msgid "SFX Volume" -msgstr "SFX 볼륨" - -msgid "Save" -msgstr "저장" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "" - -msgid "Saved" -msgstr "" - -msgid "Screensaver" -msgstr "화면보호기" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "" - -msgid "Sept" -msgstr "9월" - -msgid "Set Search-Filter" -msgstr "" - -msgid "Settings" -msgstr "설정" - -msgid "Shutdown System" -msgstr "시스템 종료" - -msgid "Shutdown to Idle" -msgstr "대기 상태로" - -msgid "Sort alphabetically" -msgstr "알파벳순으로 정렬" - -msgid "Sort by rank" -msgstr "" - -msgid "Sort order by most played" -msgstr "많이 실행한 횟수로 정렬" - -msgid "Sound" -msgstr "소리" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Special thanks to:" - -msgid "Success" -msgstr "성공" - -msgid "Success:" -msgstr "성공:" - -msgid "Successfully Saved" -msgstr "저장 성공" - -msgid "Successfully Updated" -msgstr "업데이트 성공" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "삭제 성공:" - -msgid "Successfully extracted theme." -msgstr "" - -msgid "Successfully installed:" -msgstr "설치 성공:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT 치트코드 경로" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "" - -msgid "Theme Downloader" -msgstr "" - -msgid "Theme Path" -msgstr "테마 경로" - -msgid "Theme Title:" -msgstr "" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "남은 시간:" - -msgid "Title Launcher" -msgstr "타이틀 런처" - -msgid "Titles from WiiTDB" -msgstr "WiiTDB에서 타이틀을" - -msgid "Tooltips" -msgstr "Tooltips" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB 장치가 없습니다." - -msgid "USB Loader GX is protected" -msgstr "USB 로더 GX 잠김 상태" - -msgid "Uninstall" -msgstr "제거" - -msgid "Uninstall Game" -msgstr "게임 언인스톨" - -msgid "Uninstall Menu" -msgstr "메뉴 언인스톨" - -msgid "Uninstalling wad" -msgstr "WAD 언인스톨" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "이 옵션을 사용하기 위해 콘솔을 잠금해제" - -msgid "Unsupported format, try to extract manually." -msgstr "" - -msgid "Update" -msgstr "업데이트" - -msgid "Update All" -msgstr "모두 업데이트" - -msgid "Update DOL" -msgstr "DOL 업데이트" - -msgid "Update Files" -msgstr "화일 업데이트" - -msgid "Update Path" -msgstr "업데이트 경로" - -msgid "Update all Language Files" -msgstr "모든 언어화일 업데이트" - -msgid "Update failed" -msgstr "업데이트 실패" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "언어화일 업데이트중:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "" - -msgid "VIDTV Patch" -msgstr "VIDTV 패치" - -#, c-format -msgid "Version: %s" -msgstr "버전: %s" - -msgid "Video Mode" -msgstr "비디오 모드" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "USB 장치를 기다리는 중" - -msgid "Waiting..." -msgstr "기다리는 중..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "무엇을 업데이트 할까요?" - -msgid "WiFi Features" -msgstr "WiFi 형태" - -msgid "Wii Menu" -msgstr "Wii 메뉴로" - -msgid "Wii Settings" -msgstr "위 설정" - -msgid "WiiTDB Files" -msgstr "WiiTDB 화일" - -msgid "WiiTDB Path" -msgstr "WiiTDB경로" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Wiilight" - -msgid "Wrong Password" -msgstr "잘못된 비밀번호" - -msgid "Yes" -msgstr "예" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "당신의 URL은 %sWiiTDB_URL.txt 에 저장되었어요." - -msgid "and translaters for language files updates" -msgstr "" - -msgid "available" -msgstr "가능함" - -msgid "does not exist!" -msgstr "없어요!" - -msgid "does not exist! Loading game without cheats." -msgstr "없어요! 치트없이 게임임을 로딩" - -msgid "files left" -msgstr "화일들이 남음" - -msgid "files not found on the server!" -msgstr "파일이 서버에 없습니다!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "Ocarina 위하여" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "WiiTDB, 커버, 디스크이미지를 위하여" - -msgid "for diverse patches" -msgstr "디버스 패치를 위하여" - -msgid "for his awesome tool LibWiiGui" -msgstr "LibWiiGui 훌륭한 툴를 위하여" - -msgid "for hosting the themes" -msgstr "" - -msgid "for hosting the update files" -msgstr "업데이트 화일 호스팅을 위하여" - -msgid "for the USB Loader source" -msgstr "USB 로더 소스를 위하여" - -msgid "formatted!" -msgstr "포맷 완료!" - -msgid "free" -msgstr "남음" - -msgid "not set" -msgstr "설정되지 않음" - -msgid "of" -msgstr "중" - -msgid "seconds left" -msgstr "초 남았습니다" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (모두다)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (7세 이상)" - -#~ msgid "1 hour" -#~ msgstr "1 시간" - -#~ msgid "10 min" -#~ msgstr "10 분" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (12세 이상)" - -#~ msgid "20 min" -#~ msgstr "20 분" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (16세 이상)" - -#~ msgid "3 min" -#~ msgstr "3 분" - -#~ msgid "30 min" -#~ msgstr "30 분" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (성인 18세 이상)" - -#~ msgid "5 min" -#~ msgstr "5 분" - -#~ msgid "An Error occured" -#~ msgstr "에러 발생" - -#~ msgid "AutoPatch" -#~ msgstr "자동 패치" - -#~ msgid "Both" -#~ msgstr "둘다" - -#~ msgid "Checking for Updates" -#~ msgstr "업데이트 확인" - -#~ msgid "Console Default" -#~ msgstr "콘솔 기본값" - -#~ msgid "Customs/Original" -#~ msgstr "커스텀/오리지널" - -#~ msgid "Disc Default" -#~ msgstr "디스크 기본값" - -#~ msgid "DiskFlip" -#~ msgstr "디스크 플립" - -#~ msgid "Downloading" -#~ msgstr "다운로딩중" - -#~ msgid "Dutch" -#~ msgstr "네덜란드어" - -#~ msgid "English" -#~ msgstr "영어" - -#~ msgid "French" -#~ msgstr "불어" - -#~ msgid "Game ID" -#~ msgstr "게임 ID" - -#~ msgid "Game Region" -#~ msgstr "지역" - -#~ msgid "German" -#~ msgstr "독일어" - -#~ msgid "Italian" -#~ msgstr "이태리어" - -#~ msgid "Japanese" -#~ msgstr "일본어" - -#~ msgid "Korean" -#~ msgstr "한국어" - -#~ msgid "Left" -#~ msgstr "왼쪽" - -#~ msgid "Like SysMenu" -#~ msgstr "시스템 메뉴처럼" - -#~ msgid "Locked" -#~ msgstr "잠김" - -#~ msgid "Neither" -#~ msgstr "표시 없음" - -#~ msgid "Next" -#~ msgstr "다음" - -#~ msgid "Normal" -#~ msgstr "일반" - -#~ msgid "ON" -#~ msgstr "켜짐" - -#~ msgid "Only Customs" -#~ msgstr "사용자 설정만" - -#~ msgid "Only Original" -#~ msgstr "원본만" - -#~ msgid "Only for Install" -#~ msgstr "인스톨만" - -#~ msgid "Original/Customs" -#~ msgstr "원본/사용자설정" - -#~ msgid "Prev" -#~ msgstr "이전" - -#~ msgid "Right" -#~ msgstr "오른쪽" - -#~ msgid "SChinese" -#~ msgstr "중국어(간체)" - -#~ msgid "Spanish" -#~ msgstr "스페인어" - -#~ msgid "System Default" -#~ msgstr "시스템 기본값" - -#~ msgid "TChinese" -#~ msgstr "중국어(번체)" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD화일이 인스톨됨. 하지만 SD 카드에서 삭제할수 없음." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "WAD 인스톨 실패 에러 %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "방금 다운로드한 wad화일(%s)을 열수가 없음." - -#~ msgid "Unlocked" -#~ msgstr "잠금해제" - -#~ msgid "Update to" -#~ msgstr "감사" - -#~ msgid "Updating" -#~ msgstr "업데이트중" - -#~ msgid "Updating Language Files..." -#~ msgstr "언어화일 업데이트중..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "WiiTDB.zip 업데이트중" - -#~ msgid "Widescreen Fix" -#~ msgstr "와이드 스크린에 맞춤" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Wii 메뉴로 놀아가기" - -#~ msgid "Confirm" -#~ msgstr "확인" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "WBFS 파티션이 없어요." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "WBFS 파티션을 열수가 없어요" - -#~ msgid "Could not read the disc." -#~ msgstr "디스크를 읽을수가 없어요." - -#~ msgid "Could not set USB." -#~ msgstr "USB 를 설정할수 없음." - -#~ msgid "Cover Path Changed" -#~ msgstr "표지 경로 변경됨" - -#~ msgid "DOL path changed" -#~ msgstr "DOL 경로 변경됨" - -#~ msgid "Disc Path Changed" -#~ msgstr "디스크 경로 변경됨" - -#~ msgid "Display favorites" -#~ msgstr "즐겨찾기 표시" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "30초간 재시도 할까요?" - -#~ msgid "Force" -#~ msgstr "강제" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "처트코드 경로 변경됨" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "홈브류 경로 변경됨" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "다운받은 이미지를 저장할 SD카드를 넣으세요." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "대부분 이미지는 4로 나누어져야 되요." - -#~ msgid "Network init error" -#~ msgstr "네트워크 초기화 에러" - -#~ msgid "No .dol or .elf files found." -#~ msgstr ".dol 혹은 .elf 파일이 없음." - -#~ msgid "No Favorites" -#~ msgstr "즐겨찾기 없음" - -#~ msgid "No USB Device" -#~ msgstr "USB 장치가 없습니다." - -#~ msgid "No USB Device found." -#~ msgstr "USB 장치가 없습니다." - -#~ msgid "Normal Covers" -#~ msgstr "일반 표지" - -#~ msgid "Not Found" -#~ msgstr "없음" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "DOL/ELF 파일이 아님." - -#~ msgid "Save Failed" -#~ msgstr "저장 실패" - -#~ msgid "Standard" -#~ msgstr "표중" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXT 치트코드 경로 변경됨" - -#~ msgid "Theme Path Changed" -#~ msgstr "테마 경로 변경됨" - -#~ msgid "Update Path changed." -#~ msgstr "업데이트 경로 변경됨" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB경로 변경됨." - -#~ msgid "You are about to delete " -#~ msgstr "삭제 하려고 합니다." - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "즐겨찾기를 선택했으나 선택된 즐겨찾기가 없네요." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "잘못된 이미지를 로딩하여 하군요." - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "없어요! 무언가 잘못했군요." - -#~ msgid "file left" -#~ msgstr "화일 남음" diff --git a/Languages/norwegian.lang b/Languages/norwegian.lang deleted file mode 100644 index 3e129289..00000000 --- a/Languages/norwegian.lang +++ /dev/null @@ -1,1465 +0,0 @@ -# USB Loader GX language source file. -# norwegian.lang - r813 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: raschi\n" -"Language-Team: raschi\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " WAD lagret som:" - -msgid " could not be downloaded." -msgstr " kan ikke lastes ned." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " har blitt lagret. Teksten har ikke blitt verifisert. Noe av koden vil kanskje ikke fungere riktig. Hvis du får problemer, åpne teksten i et ekte redigeringsprogram for mer informasjon." - -msgid " is not on the server." -msgstr " finnes ikke på serveren." - -msgid "2D Cover Path" -msgstr "2D Cover sti" - -msgid "3D Cover Path" -msgstr "3D Cover sti" - -msgid "3D Covers" -msgstr "3D cover" - -msgid ">> Deleting tickets..." -msgstr ">> Sletter tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Sletter tickets...FEIL! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Sletter tickets...OK! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Sletter tittel ...FEIL! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Sletter tittel ...OK!" - -msgid ">> Deleting title contents..." -msgstr ">> Sletter tittel innhold..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Sletter tittel innhold...FEIL! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Sletter tittel innhold...OK!" - -msgid ">> Deleting title..." -msgstr ">> Sletter tittel..." - -msgid ">> Finishing installation..." -msgstr ">> Sluttfører installasjon..." - -msgid ">> Installing content #" -msgstr ">> Installerer innhold #" - -msgid ">> Installing ticket..." -msgstr ">> Installerer ticket..." - -msgid ">> Installing title..." -msgstr ">> Installerer tittel..." - -msgid ">> Reading WAD data..." -msgstr ">> Leser WAD data..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Leser WAD data...FEIL! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Leser WAD data...OK!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Alle funksjonene til USB Loader GX er opplåst." - -msgid "Alternate DOL" -msgstr "Alternativ DOL" - -msgid "App Language" -msgstr "Program språk" - -msgid "Apr" -msgstr "" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Er du sikker?" - -msgid "Aug" -msgstr "" - -msgid "Author:" -msgstr "Forfatter:" - -msgid "AutoInit Network" -msgstr "Autostart nettverk" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "Tilbake" - -msgid "Back to HBC or Wii Menu" -msgstr "Tilbake til HBC eller Wii meny" - -msgid "Back to Loader" -msgstr "HBC/Loader" - -msgid "Backgroundmusic" -msgstr "Bakgrunnsmusikk" - -msgid "Big thanks to:" -msgstr "Stor takk til:" - -msgid "Block IOS Reload" -msgstr "Blokkér IOS Reload" - -msgid "Boot/Standard" -msgstr "Boot/Standard" - -msgid "Boot?" -msgstr "Start?" - -msgid "Can't be formatted" -msgstr "Kan ikke formateres" - -msgid "Can't create directory" -msgstr "Kan ikke opprette mappe" - -msgid "Can't create file" -msgstr "Kan ikke opprette fil" - -msgid "Can't delete:" -msgstr "Kan ikke slette:" - -msgid "Cancel" -msgstr "Avbryt" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "Juksefil er blank" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Klikk for å laste ned cover" - -msgid "Click to change game ID" -msgstr "Klikk for å endre spill ID" - -msgid "Clock" -msgstr "Klokke" - -msgid "Close" -msgstr "Lukk" - -msgid "Code Download" -msgstr "Kode nedlasting" - -#, c-format -msgid "Coded by: %s" -msgstr "Kodet av: %s" - -msgid "Coding:" -msgstr "Koding:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "Konsoll" - -msgid "Console Locked" -msgstr "Konsoll låst" - -msgid "Console should be unlocked to modify it." -msgstr "Konsoll må være opplåst for å modifisere." - -msgid "Continue to install game?" -msgstr "Fortsett å installere spill?" - -msgid "Controllevel" -msgstr "Kontrollnivå" - -msgid "Correct Password" -msgstr "Riktig passord" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Kan ikke opprette GCT fil" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Kan ikke initialisere DIP modul!" - -msgid "Could not initialize network!" -msgstr "Kan ikke initialisere nettverk!" - -msgid "Could not open Disc" -msgstr "Kan ikke åpne plate" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Kan ikke lagre." - -msgid "Cover Download" -msgstr "Cover nedlasting" - -msgid "Create" -msgstr "Opprett" - -msgid "Credits" -msgstr "Medvirkende" - -msgid "Custom Paths" -msgstr "Endre stier" - -msgid "DOL Path" -msgstr "DOL sti" - -msgid "Dec" -msgstr "Des" - -msgid "Default" -msgstr "Standard" - -msgid "Default Gamesettings" -msgstr "Standard innstillinger" - -msgid "Default Settings" -msgstr "Standard innstillinger" - -msgid "Delete" -msgstr "Slett" - -msgid "Delete ?" -msgstr "Slett ?" - -msgid "Delete Cheat GCT" -msgstr "Slett juksefil GCT" - -msgid "Delete Cheat TXT" -msgstr "Slett juksefil TXT" - -msgid "Delete Cover Artwork" -msgstr "Slett cover" - -msgid "Delete Disc Artwork" -msgstr "Slett platebilde" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "Utviklet av" - -msgid "Directory does not exist!" -msgstr "Mappestruktur finnes ikke!" - -msgid "Disc Artwork Download" -msgstr "Platebilde nedlasting" - -msgid "Disc Artwork Path" -msgstr "Platebilde sti" - -msgid "Disc Images" -msgstr "Plate bilder" - -msgid "Display" -msgstr "Vis" - -msgid "Display as a carousel" -msgstr "Vis som karusell" - -msgid "Display as a grid" -msgstr "Vis som rutemønster" - -msgid "Display as a list" -msgstr "Vis som liste" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Er du sikker på at du vil slette:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "Vil du endre språk?" - -msgid "Do you want to download this theme?" -msgstr "Vil du laste ned dette temaet?" - -msgid "Do you want to format:" -msgstr "Vil du formatere:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Vil du bruke alt DOL filen som er kjent for å være riktig?" - -msgid "Do you wish to update/download all language files?" -msgstr "Vil du oppdatere/laste ned alle språkfiler?" - -msgid "Done!" -msgstr "Ferdig!" - -msgid "Download" -msgstr "Last ned" - -msgid "Download Boxart image?" -msgstr "Last ned cover bilde?" - -msgid "Download Discart image?" -msgstr "Last ned plate bilde?" - -msgid "Download Now" -msgstr "Last ned nå" - -msgid "Download failed." -msgstr "Nedlasting feilet." - -msgid "Download finished" -msgstr "Nedlasting ferdig" - -msgid "Download request failed." -msgstr "Nedlast spørring feilet." - -msgid "Downloading Page List:" -msgstr "Laster ned side liste:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Laster ned fil" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Laster ned bilde:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "FEIL" - -msgid "ERROR:" -msgstr "FEIL:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "Feil" - -msgid "Error !" -msgstr "Feil !" - -msgid "Error 002 fix" -msgstr "Error 002 fiks" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Feil ved lesing av plate" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Feil ved overføring av data." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Feil..." - -msgid "Error:" -msgstr "Feil:" - -msgid "Extracting files..." -msgstr "Pakker ut filer..." - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "Feil ved formatering" - -msgid "Failed to extract." -msgstr "Utpakking feilet." - -msgid "Failed to open partition" -msgstr "Feil ved åpning av partisjon" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "Fil ikke funnet." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Sluttfører installasjon... OK!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "" - -msgid "Format" -msgstr "Formatér" - -msgid "Formatting, please wait..." -msgstr "Formaterer, vennligst vent..." - -msgid "Free Space" -msgstr "Ledig plass" - -msgid "Full Shutdown" -msgstr "Skru helt av" - -msgid "GCT Cheatcodes Path" -msgstr "GCT Juksekode sti" - -msgid "GCT File created" -msgstr "GCT fil opprettet" - -msgid "GUI Settings" -msgstr "GUI innstillinger" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Språk" - -msgid "Game Load" -msgstr "Lasting av spill" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Spill størrelse" - -msgid "Game Sound Mode" -msgstr "" - -msgid "Game Sound Volume" -msgstr "" - -msgid "Game is already installed:" -msgstr "Spillet er allerede installert:" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "Spill" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "HOME Meny" - -msgid "Homebrew Apps Path" -msgstr "Homebrew Apps sti" - -msgid "Homebrew Launcher" -msgstr "Homebrew Laster" - -msgid "Hour" -msgstr "Timer" - -msgid "How do you want to update?" -msgstr "Hvordan vil du oppdatere?" - -msgid "How to Shutdown?" -msgstr "Hvordan skru av?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Hvis du ikke har WiFi, klikk 1 for å få en URL til din WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Laster ned fil %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Laster ned fil %0.2fMB" - -msgid "Initializing Network" -msgstr "Initialiserer nettverk" - -msgid "Insert Disk" -msgstr "Sett inn plate" - -msgid "Insert a Wii Disc!" -msgstr "Sett inn en Wii plate!" - -msgid "Insert an SD-Card to save." -msgstr "Sett inn et SD-kort for å lagre." - -msgid "Insert an SD-Card to use this option." -msgstr "Sett inn et SD-kort for å bruke innstillingen." - -msgid "Install" -msgstr "Installér" - -msgid "Install Error!" -msgstr "Installasjonsfeil!" - -msgid "Install a game" -msgstr "Installér et spill" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "Installerer innhold... OK!" - -msgid "Installing game:" -msgstr "Installerer spill:" - -msgid "Installing ticket... Ok!" -msgstr "Installerer ticket... OK!" - -msgid "Installing title... Ok!" -msgstr "Installerer tittel... OK!" - -msgid "Installing wad" -msgstr "Installerer WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Det ser ut til at du har informasjon som kan være nyttig for oss. Vennligst videresend denne informasjonen til utviklerteamet." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Jul" - -msgid "June" -msgstr "Jun" - -msgid "Keep" -msgstr "Behold" - -msgid "Keyboard" -msgstr "Tastatur" - -msgid "Language File" -msgstr "Språk Fil" - -msgid "Language change:" -msgstr "Endre språk" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Språksti endret." - -msgid "Load" -msgstr "Start" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Start fil fra: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Last denne DOL som alternativ DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Laster standard språk." - -msgid "Loading standard music." -msgstr "Laster standard musikk." - -msgid "Lock Console" -msgstr "Lås konsoll" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "Mai" - -msgid "Missing files" -msgstr "Manglende filer" - -msgid "Mount DVD drive" -msgstr "Last DVD stasjon" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Musikk volum" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Ny plate oppdaget" - -msgid "No" -msgstr "Nei" - -msgid "No Cheatfile found" -msgstr "Ingen juksefil funnet" - -msgid "No DOL file found on disc." -msgstr "Ingen DOL fil funnet på plate." - -msgid "No SD-Card inserted!" -msgstr "Intet SD-kort satt i!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Ingen juksefiler valgt" - -msgid "No data could be read." -msgstr "Ingen data kan leses." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Ingen filer mangler!" - -msgid "No new updates." -msgstr "Ingen nye oppdateringer." - -msgid "No themes found on the site." -msgstr "Ingen temaer funnet på websiden." - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Ikke en Wii plate" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Ikke nok ledig minne." - -msgid "Not enough free space!" -msgstr "Ikke nok ledig plass!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Ikke et støttet format!" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "AV" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Okt" - -msgid "Official Site:" -msgstr "Offisiell nettside:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Foreldrekontroll" - -msgid "Partition" -msgstr "Partisjon" - -msgid "Password" -msgstr "Passord" - -msgid "Password Changed" -msgstr "Passord endret" - -msgid "Password has been changed" -msgstr "Passord har blitt endret" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Lim den inn i nettleseren din for å få WiiTDB.zip." - -msgid "Patch Country Strings" -msgstr "Patch land strenger" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Velg fra liste" - -msgid "Play Count" -msgstr "Ganger spilt" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "Vennligst vent..." - -msgid "Power off the Wii" -msgstr "Skru av Wii" - -msgid "Prompts Buttons" -msgstr "Dialog knapper" - -msgid "Published by" -msgstr "Publisert av" - -msgid "Quick Boot" -msgstr "Hurtig start" - -msgid "Reading WAD data... Ok!" -msgstr "Leser WAD data... OK!" - -msgid "Receiving file from:" -msgstr "Mottar fil fra:" - -msgid "Released" -msgstr "Utgitt" - -msgid "Reload SD" -msgstr "Les SD på nytt" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "Gi nytt navn til spill på WBFS" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Nullstill teller" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Starter på nytt..." - -msgid "Return" -msgstr "Gå tilbake" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Tilbake til Wii meny" - -msgid "Rumble" -msgstr "Vibrasjon" - -msgid "SFX Volume" -msgstr "Effekt volum" - -msgid "Save" -msgstr "Lagre" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Lagre spilliste som" - -msgid "Saved" -msgstr "Lagret" - -msgid "Screensaver" -msgstr "Skjermbeskytter" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Velg en DOL fil" - -msgid "Sept" -msgstr "Sep" - -msgid "Set Search-Filter" -msgstr "Angi søkefilter" - -msgid "Settings" -msgstr "Innstillinger" - -msgid "Shutdown System" -msgstr "Skru helt av" - -msgid "Shutdown to Idle" -msgstr "Skru av" - -msgid "Sort alphabetically" -msgstr "Sortér alfabetisk" - -msgid "Sort by rank" -msgstr "Sortér etter rangering" - -msgid "Sort order by most played" -msgstr "Sortér etter ganger spilt" - -msgid "Sound" -msgstr "Lyd" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Spesielt takk til:" - -msgid "Success" -msgstr "Suksess" - -msgid "Success:" -msgstr "Suksess:" - -msgid "Successfully Saved" -msgstr "Vellykket lagring" - -msgid "Successfully Updated" -msgstr "Vellykket oppdatering" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Vellykket sletting:" - -msgid "Successfully extracted theme." -msgstr "Vellykket utpakking av tema." - -msgid "Successfully installed:" -msgstr "Vellykket installering:" - -msgid "TXT Cheatcodes Path" -msgstr "TXTjuksekode sti" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Valgt mappe finnes ikke. Vil du opprette den?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Tema nedlasting sti" - -msgid "Theme Downloader" -msgstr "Tema Nedlaster" - -msgid "Theme Path" -msgstr "Tema sti" - -msgid "Theme Title:" -msgstr "Tema tittel:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Tid igjen:" - -msgid "Title Launcher" -msgstr "Tittel Laster" - -msgid "Titles from WiiTDB" -msgstr "Titler fra WiiTDB" - -msgid "Tooltips" -msgstr "Verktøystips" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Overføring feilet." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB enhet ikke funnet" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX er beskyttet" - -msgid "Uninstall" -msgstr "Avinstallér" - -msgid "Uninstall Game" -msgstr "Avinstallér spill" - -msgid "Uninstall Menu" -msgstr "Avinstallér Meny" - -msgid "Uninstalling wad" -msgstr "Avinstallerer WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Lås opp konsollen for å bruke denne innstillingen." - -msgid "Unsupported format, try to extract manually." -msgstr "Format ikke støttet, prøv å pakk ut manuelt." - -msgid "Update" -msgstr "Oppdater" - -msgid "Update All" -msgstr "Oppdater alt" - -msgid "Update DOL" -msgstr "Oppdater DOL" - -msgid "Update Files" -msgstr "Oppdater filer" - -msgid "Update Path" -msgstr "Oppdatering sti" - -msgid "Update all Language Files" -msgstr "Oppdater alle språkfiler" - -msgid "Update failed" -msgstr "Mislykket oppdatering" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Oppdaterer språkfiler:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Opplastet ZIP fil installert i homebrew mappen." - -msgid "VIDTV Patch" -msgstr "" - -#, c-format -msgid "Version: %s" -msgstr "Versjon: %s" - -msgid "Video Mode" -msgstr "Video modus" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "Venter på USB enhet" - -msgid "Waiting..." -msgstr "Venter..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Hva vil du oppdatere?" - -msgid "WiFi Features" -msgstr "WiFi egenskaper" - -msgid "Wii Menu" -msgstr "Wii Meny" - -msgid "Wii Settings" -msgstr "Wii Innstillinger" - -msgid "WiiTDB Files" -msgstr "WiiTDB filer" - -msgid "WiiTDB Path" -msgstr "WiiTDB sti" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Wii DVD lys" - -msgid "Wrong Password" -msgstr "Feil passord" - -msgid "Yes" -msgstr "Ja" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Din URL ble lagret i %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "og oversettere for språkfiler" - -msgid "available" -msgstr "tilgjengelig" - -msgid "does not exist!" -msgstr "finnes ikke!" - -msgid "does not exist! Loading game without cheats." -msgstr "finnes ikke! Laster spill uten juksekode." - -msgid "files left" -msgstr "filer gjenstår" - -msgid "files not found on the server!" -msgstr "filer ikke funnet på serveren!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "for WiiTDB og hosting av bilder" - -msgid "for diverse patches" -msgstr "for diverse patcher" - -msgid "for his awesome tool LibWiiGui" -msgstr "for hans råe verktøy LibWiiGui" - -msgid "for hosting the themes" -msgstr "for hosting av tema" - -msgid "for hosting the update files" -msgstr "for hosting av oppdateringer" - -msgid "for the USB Loader source" -msgstr "for kilden til USB Loader" - -msgid "formatted!" -msgstr "formatert!" - -msgid "free" -msgstr "ledig" - -msgid "not set" -msgstr "ikke satt" - -msgid "of" -msgstr "av" - -msgid "seconds left" -msgstr "sekunder gjenstår" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Alle)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Barn 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 time" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Ungdom 12+)" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Ungdom 16+)" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Voksen 18+)" - -#~ msgid "An Error occured" -#~ msgstr "En feil oppstod" - -#~ msgid "Both" -#~ msgstr "Begge" - -#~ msgid "Checking for Updates" -#~ msgstr "Søker etter oppdateringer" - -#~ msgid "Console Default" -#~ msgstr "Konsoll Standard" - -#~ msgid "Customs/Original" -#~ msgstr "Custom/Original" - -#~ msgid "Disc Default" -#~ msgstr "Spill Standard" - -#~ msgid "DiskFlip" -#~ msgstr "Snu plate" - -#~ msgid "Downloading" -#~ msgstr "Laster ned" - -#~ msgid "Dutch" -#~ msgstr "Nederlandsk" - -#~ msgid "English" -#~ msgstr "Engelsk" - -#~ msgid "French" -#~ msgstr "Fransk" - -#~ msgid "Game ID" -#~ msgstr "Spill ID" - -#~ msgid "Game Region" -#~ msgstr "Region" - -#~ msgid "German" -#~ msgstr "Tysk" - -#~ msgid "Italian" -#~ msgstr "Italiensk" - -#~ msgid "Japanese" -#~ msgstr "Japansk" - -#~ msgid "Korean" -#~ msgstr "Koreansk" - -#~ msgid "Left" -#~ msgstr "Venstre" - -#~ msgid "Like SysMenu" -#~ msgstr "Lik Systemmeny" - -#~ msgid "Load From SD/USB" -#~ msgstr "Start fra SD/USB" - -#~ msgid "Locked" -#~ msgstr "Låst" - -#~ msgid "Neither" -#~ msgstr "Ingen" - -#~ msgid "Next" -#~ msgstr "Neste" - -#~ msgid "ON" -#~ msgstr "PÅ" - -#~ msgid "Only Customs" -#~ msgstr "Kun custom" - -#~ msgid "Only Original" -#~ msgstr "Kun original" - -#~ msgid "Only for Install" -#~ msgstr "Kun for installering" - -#~ msgid "Original/Customs" -#~ msgstr "Original/Custom" - -#~ msgid "Prev" -#~ msgstr "Forrige" - -#~ msgid "Right" -#~ msgstr "Høyre" - -#~ msgid "SChinese" -#~ msgstr "S.Kinesisk" - -#~ msgid "Spanish" -#~ msgstr "Spansk" - -#~ msgid "System Default" -#~ msgstr "System Standard" - -#~ msgid "TChinese" -#~ msgstr "T.Kinesisk" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD filen ble installert. Men ble ikke slettet fra SD kort." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "WAD installasjonen feilet med feilkode %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Kan ikke åpne nedlastet WAD fil (%s)." - -#~ msgid "Unlocked" -#~ msgstr "Opplåst" - -#~ msgid "Update to" -#~ msgstr "Oppdater til" - -#~ msgid "Updating" -#~ msgstr "Oppdaterer" - -#~ msgid "Updating Language Files..." -#~ msgstr "Oppdaterer språkfiler..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Oppdaterer WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Widescreen fiks" - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s vil kanskje ikke starte riktig hvis System Menyen ikke er oppdatert." - -#~ msgid "Back to Wii Menu" -#~ msgstr "Wii meny" - -#~ msgid "Channels" -#~ msgstr "Kanaler" - -#~ msgid "Checking existing artwork" -#~ msgstr "Sjekker eksisterende bilder" - -#~ msgid "Confirm" -#~ msgstr "Bekreft" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Kan ikke finne en WBFS partisjon." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Kan ikke åpne WBFS partisjon" - -#~ msgid "Could not read the disc." -#~ msgstr "Kan ikke lese plate." - -#~ msgid "Could not set USB." -#~ msgstr "Kan ikke velge USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "Cover sti endret" - -#~ msgid "DOL path changed" -#~ msgstr "DOL sti endret" - -#~ msgid "Disc Path Changed" -#~ msgstr "Plate sti endret" - -#~ msgid "Display favorites" -#~ msgstr "Vis favoritter" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Vil du fortsette å prøve i 30 sekunder?" - -#~ msgid "Force" -#~ msgstr "Tving" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "GCT Juksekode sti endret" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Homebrew Apps sti endret" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Sett inn et SD-kort for å laste ned bilder." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Sannsynligvis har bildet dimensjoner som ikke kan deles med 4." - -#~ msgid "Network init error" -#~ msgstr "Nettverk init feil" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Ingen .dol eller .elf filer funnet." - -#~ msgid "No Favorites" -#~ msgstr "Ingen favoritter" - -#~ msgid "No USB Device" -#~ msgstr "Ingen USB enhet" - -#~ msgid "No USB Device found." -#~ msgstr "Ingen USB enhet funnet." - -#~ msgid "Normal Covers" -#~ msgstr "Normale cover" - -#~ msgid "Not Found" -#~ msgstr "Ikke funnet" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Ikke en DOL/ELF fil." - -#~ msgid "Save Failed" -#~ msgstr "Lagring feilet" - -#~ msgid "Selected DOL" -#~ msgstr "Valgt DOL fil" - -#~ msgid "Standard" -#~ msgstr "Standard" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXTjuksekode sti endret" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Tema nedlasting sti endret" - -#~ msgid "Theme Path Changed" -#~ msgstr "Tema sti endret" - -#~ msgid "Update Path changed." -#~ msgstr "Oppdatering sti endret." - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB sti endret." - -#~ msgid "You are about to delete " -#~ msgstr "Du er i ferd med å slette " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Du prøver å vise favoritter når du ikke har noen valgt." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Du har forsøkt å vise et korrupt bilde" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "finnes ikke! Du har gjort noe galt." - -#~ msgid "file left" -#~ msgstr "fil gjenstår" diff --git a/Languages/polish.lang b/Languages/polish.lang deleted file mode 100644 index 29ba4fec..00000000 --- a/Languages/polish.lang +++ /dev/null @@ -1,1519 +0,0 @@ -# USB Loader GX language source file. -# polish.lang - r899 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: ziom666 (zadania_prog@vp.pl)\n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad zapisano jako:" - -msgid " could not be downloaded." -msgstr " nie udalo sie pobrac" - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " zapisano. Plik tekstowy nie zostal zweryfikowany. Niektore z kodow, moga nie dzialac wlaeciwie z innymi. W razie problemow otworz plik tekstowy w edytorze na komputerze" - -msgid " is not on the server." -msgstr " nie istnieje na serwerze" - -msgid "2D Cover Path" -msgstr "Sciezka okladek 2D" - -msgid "3D Cover Path" -msgstr "Sciezka okladek 3D" - -msgid "3D Covers" -msgstr "Okladki 3D" - -msgid ">> Deleting tickets..." -msgstr ">> Usuwanie ticketu..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Usuwanie ticketu...ERROR! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Usuwanie ticketu...Ok! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Usuwanie tytulu ...ERROR! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Usuwanie tytulu ...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Usuwanie title contents..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Usuwanie title contents...ERROR! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Usuwanie title contents...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Usuwanie tytulu..." - -msgid ">> Finishing installation..." -msgstr ">> Konczenie instalacji" - -msgid ">> Installing content #" -msgstr ">> Instalowanie zawartoSci #" - -msgid ">> Installing ticket..." -msgstr ">> Instalowanie ticketu..." - -msgid ">> Installing title..." -msgstr ">> Instalowanie tytulu..." - -msgid ">> Reading WAD data..." -msgstr ">> Odczyt danych WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Odczyt danych WAD...ERROR! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Odczyt danych WAD...Ok!" - -msgid "AUTO" -msgstr "automatycznie" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Wszystkie partycje" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "USB Loader GX odblokowany" - -msgid "Alternate DOL" -msgstr "Alternatywny DOL" - -msgid "App Language" -msgstr "Jezyk" - -msgid "Apr" -msgstr "Kwiecien" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Na pewno?" - -msgid "Aug" -msgstr "Sierpien" - -msgid "Author:" -msgstr "Autor: " - -msgid "AutoInit Network" -msgstr "Autoinicjalizacja sieci" - -msgid "BCA Codes Path" -msgstr "Sciezka kodow BCA" - -msgid "BETA revisions" -msgstr "Wersje beta" - -msgid "Back" -msgstr "Cofnij" - -msgid "Back to HBC or Wii Menu" -msgstr "Powrot do HBC/Wii Menu" - -msgid "Back to Loader" -msgstr "Powrot do HBC" - -msgid "Backgroundmusic" -msgstr "Muzyka w tle" - -msgid "Big thanks to:" -msgstr "Podziekowania dla" - -msgid "Block IOS Reload" -msgstr "Blokoj przeladowanie IOS" - -msgid "Boot/Standard" -msgstr "" - -msgid "Boot?" -msgstr "" - -msgid "Can't be formatted" -msgstr "Nie mozna sformatowac" - -msgid "Can't create directory" -msgstr "Nie mozna utworzyc folderu" - -msgid "Can't create file" -msgstr "Nie mozna utworzyc pliku" - -msgid "Can't delete:" -msgstr "Nie mozna usunac" - -msgid "Cancel" -msgstr "Anuluj" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "Plik z kodami pusty" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Kliknij aby pobrac okladki" - -msgid "Click to change game ID" -msgstr "Kliknij zeby zmienic ID gry" - -msgid "Clock" -msgstr "Zegar" - -msgid "Close" -msgstr "Zamknij" - -msgid "Code Download" -msgstr "Pobierz kody" - -#, c-format -msgid "Coded by: %s" -msgstr "" - -msgid "Coding:" -msgstr "" - -msgid "Connection lost..." -msgstr "Utracono polaczenie..." - -msgid "Console" -msgstr "Konsola" - -msgid "Console Locked" -msgstr "Konsola zablokowana" - -msgid "Console should be unlocked to modify it." -msgstr "Aby zmodyfikowac, odblokuj konsole" - -msgid "Continue to install game?" -msgstr "Kontynuowac instalacje?" - -msgid "Controllevel" -msgstr "Poziom kontroli" - -msgid "Correct Password" -msgstr "Haslo poprawne" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Nie udalo sie stworzyc pliku GCT" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Nie zainicjalizowano modulu DIP!" - -msgid "Could not initialize network!" -msgstr "Nie zainicjalizowano sieci!" - -msgid "Could not open Disc" -msgstr "Nie udalo sie otworzyc dysku" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Nie mozna zapisac" - -msgid "Cover Download" -msgstr "Pobierz okladki" - -msgid "Create" -msgstr "Utworz" - -msgid "Credits" -msgstr "" - -msgid "Custom Paths" -msgstr "Sciezki" - -msgid "DOL Path" -msgstr "Sciezka plikow .DOL" - -msgid "Dec" -msgstr "Grudzien" - -msgid "Default" -msgstr "Ustawienia domyslne" - -msgid "Default Gamesettings" -msgstr "Domyslne ustawienia gier" - -msgid "Default Settings" -msgstr "Domyslne ustawienia" - -msgid "Delete" -msgstr "Usun" - -msgid "Delete ?" -msgstr "Usunac ?" - -msgid "Delete Cheat GCT" -msgstr "Usun plik z kodami GCT" - -msgid "Delete Cheat TXT" -msgstr "Usun plik z kodami TXT" - -msgid "Delete Cover Artwork" -msgstr "Usun obrazki box" - -msgid "Delete Disc Artwork" -msgstr "Usun obrazki plyt" - -msgid "Design:" -msgstr "Projekt:" - -msgid "Developed by" -msgstr "" - -msgid "Directory does not exist!" -msgstr "Katalog nie istnieje!" - -msgid "Disc Artwork Download" -msgstr "Pobierz obrazki" - -msgid "Disc Artwork Path" -msgstr "Sciezka do obrazkow plyt" - -msgid "Disc Images" -msgstr "Obrazki plyt" - -msgid "Display" -msgstr "Wyswietl" - -msgid "Display as a carousel" -msgstr "Wyswietl jako karuzele" - -msgid "Display as a grid" -msgstr "Wyswietl jako siatke" - -msgid "Display as a list" -msgstr "Wyswietl jako liste" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Na pewno usunac: " - -msgid "Do you want to apply it now?" -msgstr "Czy chcesz to teraz zastosowac?" - -msgid "Do you want to change language?" -msgstr "Zmienic jezyk?" - -msgid "Do you want to download this theme?" -msgstr "Pobrac temat?" - -msgid "Do you want to format:" -msgstr "Sformatowac:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Uzyc alternatywnego pliku DOL?" - -msgid "Do you wish to update/download all language files?" -msgstr "Zaktualizowac wszystkie pliki jezykowe?" - -msgid "Done!" -msgstr "Zakonczono!" - -msgid "Download" -msgstr "Pobierz" - -msgid "Download Boxart image?" -msgstr "Pobrac obrazki box?" - -msgid "Download Discart image?" -msgstr "Pobrac obrazki plyt?" - -msgid "Download Now" -msgstr "Pobierz teraz" - -msgid "Download failed." -msgstr "Nie udalo sie pobrac" - -msgid "Download finished" -msgstr "Zakonczono pobieranie" - -msgid "Download request failed." -msgstr "Prosba pobierania nieudana" - -msgid "Downloading Page List:" -msgstr "Pobieranie listy stron:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Pobieranie pliku" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Pobieranie obrazka:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "Blad" - -msgid "ERROR:" -msgstr "Blad:" - -msgid "ERROR: Can't set up theme." -msgstr "Blad: nie mozna ustawic tematu" - -msgid "Error" -msgstr "Blad" - -msgid "Error !" -msgstr "Blad !" - -msgid "Error 002 fix" -msgstr "Poprawka bledu 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Blad odczytu plyty" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Blad podczas transferu danych" - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Blad..." - -msgid "Error:" -msgstr "Blad:" - -msgid "Extracting files..." -msgstr "Rozpakowywanie plikow..." - -msgid "FAT: Use directories" -msgstr "FAT: uzyj katalogow" - -msgid "Failed formating" -msgstr "Nie udalo sie sformatowac" - -msgid "Failed to extract." -msgstr "Nie udalo sie rozpakowac" - -msgid "Failed to open partition" -msgstr "Nie udalo sie otworzyc partycji" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Luty" - -msgid "File not found." -msgstr "Nie znaleziono pliku." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Konczenie instalacji...Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Obrot na osi X" - -msgid "Format" -msgstr "Sformatuj" - -msgid "Formatting, please wait..." -msgstr "Formatowanie, prosze czekac..." - -msgid "Free Space" -msgstr "Wolnego miejsca" - -msgid "Full Shutdown" -msgstr "Pelne zamkniecie" - -msgid "GCT Cheatcodes Path" -msgstr "Sciezka kodow GCT" - -msgid "GCT File created" -msgstr "Utworzono plik GCT" - -msgid "GUI Settings" -msgstr "Ustawienia interfejsu graficznego" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "Nie znaleziono pliku GXtheme.cfg" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Jezyk gry" - -msgid "Game Load" -msgstr "Zaladuj gre" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Rozmiar gry" - -msgid "Game Sound Mode" -msgstr "Tryb dzwieku gry" - -msgid "Game Sound Volume" -msgstr "Gloscnosc dzwieku gry" - -msgid "Game is already installed:" -msgstr "Gra jest juz zainstalowana:" - -msgid "Game partition" -msgstr "Partycje z grami" - -msgid "Games" -msgstr "Liczba gier" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Menu" - -msgid "Homebrew Apps Path" -msgstr "Sciezka plikacji homebrew" - -msgid "Homebrew Launcher" -msgstr "" - -msgid "Hour" -msgstr "Godzina" - -msgid "How do you want to update?" -msgstr "Wybierz rodzaj aktualizacji" - -msgid "How to Shutdown?" -msgstr "Wybierz rodzaj zamkniecia" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "JeSli nie masz WiFi, wcisnij 1 aby otrzymac adres skad pobrac WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Przychodzacy plik %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Przychodzacy plik %0.2fMB" - -msgid "Initializing Network" -msgstr "Inicjalizacja sieci" - -msgid "Insert Disk" -msgstr "Wloz plyte" - -msgid "Insert a Wii Disc!" -msgstr "Wloz plyte Wii!" - -msgid "Insert an SD-Card to save." -msgstr "Wloz karte SD, aby zapisac" - -msgid "Insert an SD-Card to use this option." -msgstr "Wloz karte SD, aby uzyc tej opcji" - -msgid "Install" -msgstr "Zainstaluj" - -msgid "Install Error!" -msgstr "Blad instalacji" - -msgid "Install a game" -msgstr "Zainstaluj gre" - -msgid "Install partitions" -msgstr "Zainstaluj partycje" - -msgid "Installing content... Ok!" -msgstr "Instalowanie zawartosci...Ok!" - -msgid "Installing game:" -msgstr "Instalowanie gry:" - -msgid "Installing ticket... Ok!" -msgstr "Instalowanie ticketu... Ok!" - -msgid "Installing title... Ok!" -msgstr "Instalowanie tytulu... Ok!" - -msgid "Installing wad" -msgstr "Instalowanie wad" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "" - -msgid "Jan" -msgstr "Styczen" - -msgid "July" -msgstr "lipiec" - -msgid "June" -msgstr "czerwiec" - -msgid "Keep" -msgstr "Trzymaj" - -msgid "Keyboard" -msgstr "Klawiatura" - -msgid "Language File" -msgstr "Plik jezykowy" - -msgid "Language change:" -msgstr "Zmien jezyk" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Sciezka do plikow jezykowych zmieniona" - -msgid "Load" -msgstr "Zaladuj" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Zaladowac plik z: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Zaladowac ten DOL jako alternatywnt?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "ladowanie standardowego jezyka." - -msgid "Loading standard music." -msgstr "ladowanie standardowej muzyki" - -msgid "Lock Console" -msgstr "Zablokuj konsole" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "Marzec" - -msgid "Mark new games" -msgstr "Oznacz nowe gry" - -msgid "May" -msgstr "Maj" - -msgid "Missing files" -msgstr "Brakuje plikow" - -msgid "Mount DVD drive" -msgstr "Uruchom naped DVD" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Poziom glosnosci" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Wykryto nowy dysk" - -msgid "No" -msgstr "Nie" - -msgid "No Cheatfile found" -msgstr "Nie znaleziono plikow z kodami" - -msgid "No DOL file found on disc." -msgstr "Brak plikow DOL na dysku" - -msgid "No SD-Card inserted!" -msgstr "Nie wlozono karty SD!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Nie wybrano zadnych kodow" - -msgid "No data could be read." -msgstr "Blad odczytu" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Brak plikow do pobrania" - -msgid "No new updates." -msgstr "Posiadasz aktualna wersje" - -msgid "No themes found on the site." -msgstr "Nie znaleziono tematow na tej stronie" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "To nie jest plyta Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Brak wystarczajacej wolnej pamieci" - -msgid "Not enough free space!" -msgstr "Brak wystarczajacej wolnej pamieci" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Nieobslugiwany format" - -msgid "Nov" -msgstr "Listopad" - -msgid "OFF" -msgstr "Wylacz" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Pazdziernik" - -msgid "Official Site:" -msgstr "Strona oficjalna:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Kontrola rodzicielska" - -msgid "Partition" -msgstr "Partycja" - -msgid "Password" -msgstr "Haslo" - -msgid "Password Changed" -msgstr "Haslo zmieniono" - -msgid "Password has been changed" -msgstr "Haslo zostalo zmienione" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Wklej adres do przegladarki, aby pobrac WiiTDB.zip" - -msgid "Patch Country Strings" -msgstr "" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Wybierz z listy" - -msgid "Play Count" -msgstr "Licznik" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "Prosze czekac..." - -msgid "Power off the Wii" -msgstr "Wylacz Wii" - -msgid "Prompts Buttons" -msgstr "" - -msgid "Published by" -msgstr "" - -msgid "Quick Boot" -msgstr "Szybkie ladowanie" - -msgid "Reading WAD data... Ok!" -msgstr "Odczyt danych WAD...Ok!" - -msgid "Receiving file from:" -msgstr "Otrzymywanie pliku z:" - -msgid "Released" -msgstr "" - -msgid "Reload SD" -msgstr "Przeladuj SD" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "Zmien tytul gry na WBFS" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Zrestartuj licznik" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Restartowanie..." - -msgid "Return" -msgstr "Powrot" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Powrot do Wii Menu" - -msgid "Rumble" -msgstr "Wibracje" - -msgid "SFX Volume" -msgstr "Poziom glosnosci SFX" - -msgid "Save" -msgstr "Zapisz" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Zapisz liste gier do" - -msgid "Saved" -msgstr "Zapisano" - -msgid "Screensaver" -msgstr "Wygaszacz ekranu" - -msgid "Select" -msgstr "Wybierz" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Wybierz plik DOL" - -msgid "Sept" -msgstr "Wrzesien" - -msgid "Set Search-Filter" -msgstr "Ustaw filtr wyszukiwania" - -msgid "Settings" -msgstr "Ustawienia" - -msgid "Shutdown System" -msgstr "Wylacz" - -msgid "Shutdown to Idle" -msgstr "Przelacz w stan oczekiwania" - -msgid "Sort alphabetically" -msgstr "Sortuj alfabetycznie" - -msgid "Sort by rank" -msgstr "Sortuj wzgledem rankingu" - -msgid "Sort order by most played" -msgstr "Sortuj wg. liczby uruchomien" - -msgid "Sound" -msgstr "Dzwiek" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Specjalne podziekowania" - -msgid "Success" -msgstr "Sukces" - -msgid "Success:" -msgstr "Sukces:" - -msgid "Successfully Saved" -msgstr "Pomyslnie zapisano" - -msgid "Successfully Updated" -msgstr "Pomyslnie zaktualizowano" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Pomyslnie usunieto" - -msgid "Successfully extracted theme." -msgstr "Pomyslnie rozpakowano temat." - -msgid "Successfully installed:" -msgstr "Pomyslnie zainstalowano:" - -msgid "TXT Cheatcodes Path" -msgstr "Sciezka kodow TXT" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Katalog nie istnieje. Utworzyc?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Sciezka tematow" - -msgid "Theme Downloader" -msgstr "Pobieranie tematow" - -msgid "Theme Path" -msgstr "Sciezka skorek" - -msgid "Theme Title:" -msgstr "Tytul:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Czas pozostaly" - -msgid "Title Launcher" -msgstr "Uruchom tytul" - -msgid "Titles from WiiTDB" -msgstr "Tytuly z pliku WiiTDB" - -msgid "Tooltips" -msgstr "Chmurki z podpowiedziami" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Niepowodzenie." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "Nie znaleziono urzadzenia USB" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX zabezpieczony" - -msgid "Uninstall" -msgstr "Odinstaluj" - -msgid "Uninstall Game" -msgstr "Odinstaluj gre" - -msgid "Uninstall Menu" -msgstr "Odinstaluj Menu" - -msgid "Uninstalling wad" -msgstr "Odinstalowywanie wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Odblokuj konsole, aby uzyc tej opcji" - -msgid "Unsupported format, try to extract manually." -msgstr "Niewspierany format, sprobuj rozpakowac recznie" - -msgid "Update" -msgstr "Aktualizacja" - -msgid "Update All" -msgstr "Zaktualizuj wszystko" - -msgid "Update DOL" -msgstr "Zaktualizuj Dol" - -msgid "Update Files" -msgstr "Zaktualizuj pliki" - -msgid "Update Path" -msgstr "Sciezka aktualizacji" - -msgid "Update all Language Files" -msgstr "Zaktualizuj wszystkie pliki jezykowe" - -msgid "Update failed" -msgstr "Nie udalo sie zaktualizowac" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Aktualizacja plikow jezykowych:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Wyslany plik ZIP zainstalowano w katalogu homebrew" - -msgid "VIDTV Patch" -msgstr "" - -#, c-format -msgid "Version: %s" -msgstr "Wersja: %s" - -msgid "Video Mode" -msgstr "Tryb video" - -msgid "WIP Patches Path" -msgstr "Sciezka patchy WIP" - -msgid "Waiting for USB Device" -msgstr "Oczekiwanie na urzadzenie USB" - -msgid "Waiting..." -msgstr "Oczekiwanie..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Rodzaj aktualizacji" - -msgid "WiFi Features" -msgstr "Opcje WiFi" - -msgid "Wii Menu" -msgstr "" - -msgid "Wii Settings" -msgstr "Opcje Wii" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "Sciezka WiiTDBPath" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Dioda Wii" - -msgid "Wrong Password" -msgstr "Bledne haslo" - -msgid "Yes" -msgstr "Tak" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Musisz wybrac, lub sformatowac partycje" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Adres zostal zapisany w pliku %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "i tlumaczon za aktualizacjie plikow jezykowych" - -msgid "available" -msgstr "dostepne" - -msgid "does not exist!" -msgstr "nie istnieje!" - -msgid "does not exist! Loading game without cheats." -msgstr "nie istnieje! ladowanie gry bez kodow." - -msgid "files left" -msgstr "pozostalo" - -msgid "files not found on the server!" -msgstr "nie znaleziono na serwerze" - -msgid "for FAT/NTFS support" -msgstr "za pomoc przy FAT/NTFS" - -msgid "for Ocarina" -msgstr "dla Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "za WiiTDB i hostowanie okladek/obrazkow plyt" - -msgid "for diverse patches" -msgstr "za rozne poprawki" - -msgid "for his awesome tool LibWiiGui" -msgstr "za jego niesamowite narzedzie LibWiiGui" - -msgid "for hosting the themes" -msgstr "za hosting tematow" - -msgid "for hosting the update files" -msgstr "za hostowanie plikow aktualizacji" - -msgid "for the USB Loader source" -msgstr "za zrodla USB Loader" - -msgid "formatted!" -msgstr "sformatowano" - -msgid "free" -msgstr "wolnego" - -msgid "not set" -msgstr "nie ustawiono" - -msgid "of" -msgstr "z" - -msgid "seconds left" -msgstr "sekund pozostalo" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Zainstaluj kopie 1:1" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (dla kazdego)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (dziecko 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 godzina" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (mlodziez 12+)" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (dojrzaly 16+)" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (tylko dla doroslych 18+)" - -#~ msgid "An Error occured" -#~ msgstr "Wystapil blad" - -#~ msgid "Anti" -#~ msgstr "Anty" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Czy na pewno wlaczyc kontrole rodzicielska?" - -#~ msgid "AutoPatch" -#~ msgstr "Automatyczny patch" - -#~ msgid "Both" -#~ msgstr "Oba" - -#~ msgid "Checking for Updates" -#~ msgstr "Sprawdzanie aktualizacji" - -#~ msgid "Console Default" -#~ msgstr "Domyslne ustawienia konsoli" - -#~ msgid "Disc Default" -#~ msgstr "Domyslny dysk" - -#~ msgid "DiskFlip" -#~ msgstr "Obrot plytami" - -#~ msgid "Downloading" -#~ msgstr "Trwa pobieranie" - -#~ msgid "Dutch" -#~ msgstr "holenderski" - -#~ msgid "English" -#~ msgstr "angielski" - -#~ msgid "French" -#~ msgstr "francuski" - -#~ msgid "Game ID" -#~ msgstr "ID gry" - -#~ msgid "Game Region" -#~ msgstr "Region" - -#~ msgid "German" -#~ msgstr "niemiecki" - -#~ msgid "Invalid PIN code" -#~ msgstr "Bledny kod PIN" - -#~ msgid "Italian" -#~ msgstr "wloski" - -#~ msgid "Japanese" -#~ msgstr "japonski" - -#~ msgid "Korean" -#~ msgstr "koreanski" - -#~ msgid "Left" -#~ msgstr "Lewo" - -#~ msgid "Like SysMenu" -#~ msgstr "Podobnie do menu systemowego" - -#~ msgid "Load From SD/USB" -#~ msgstr "Zaladuj z SD/USB" - -#~ msgid "Locked" -#~ msgstr "Zablokowano" - -#~ msgid "Loop Sound" -#~ msgstr "Zapetl dzwieki" - -#~ msgid "Neither" -#~ msgstr "zadne" - -#~ msgid "Next" -#~ msgstr "nastepny" - -#~ msgid "Normal" -#~ msgstr "Standardowe" - -#~ msgid "ON" -#~ msgstr "Wlacz" - -#~ msgid "Only Customs" -#~ msgstr "Tylko nieoryginalne" - -#~ msgid "Only Original" -#~ msgstr "Tylko oryginalne" - -#~ msgid "Only for Install" -#~ msgstr "Tylko dla instalacji" - -#~ msgid "Original/Customs" -#~ msgstr "Mieszane" - -#~ msgid "Parental Control disabled" -#~ msgstr "Kontrola rodzicielska wylaczona" - -#~ msgid "Prev" -#~ msgstr "Poprzedni" - -#~ msgid "Right" -#~ msgstr "Prawo" - -#~ msgid "SChinese" -#~ msgstr "uproszczony chinski" - -#~ msgid "Sound+BGM" -#~ msgstr "Dzwieki i muzyka w tle" - -#~ msgid "Sound+Quiet" -#~ msgstr "Dzwieki i cisza" - -#~ msgid "Spanish" -#~ msgstr "hiszpanski" - -#~ msgid "System Default" -#~ msgstr "Domyslne ustawienia systemowe" - -#~ msgid "TChinese" -#~ msgstr "chinski" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Zainstalowano plik wad, ale nie mozna go usunac z karty SD" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Instalacja wad zakonczona bledek %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Nie udalo sie zainstalowac dopiero co pobranego pliku (%s)" - -#~ msgid "Unlock Parental Control" -#~ msgstr "Odblokuj kontrole rodzicielska" - -#~ msgid "Unlocked" -#~ msgstr "Odblokowano" - -#~ msgid "Update to" -#~ msgstr "Aktualizuj do" - -#~ msgid "Updating" -#~ msgstr "Aktualizowanie" - -#~ msgid "Updating Language Files..." -#~ msgstr "Aktualizacja plikow jezykowych..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Aktualizacja WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Popraw ekran panoramiczny" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Nie masz wlaczonej kontroli rodzicielskiej. Jesli chcesz jej uzywac, uruchom ja w ustawieniach Wii." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Moze nie ladowac sie poprawnie, jesli nie masz aktualnego menu systemowego" - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Zmieniono sciezke kodow BCA" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Powrit do Wii Menu" - -#~ msgid "Channels" -#~ msgstr "Kanaly" - -#~ msgid "Checking existing artwork" -#~ msgstr "Sprawdzam istniejace prace graficzne" - -#~ msgid "Confirm" -#~ msgstr "Potwierdz" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Nie znaleziono partycji WBFS" - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Nie udalo sie otworzyc partycji WBFS" - -#~ msgid "Could not read the disc." -#~ msgstr "Nie mozna odczytac dysku" - -#~ msgid "Could not set USB." -#~ msgstr "Nie mozna ustawic USB" - -#~ msgid "Cover Path Changed" -#~ msgstr "Sciezka do okladek zostala zmieniona" - -#~ msgid "DOL path changed" -#~ msgstr "Zmieniono sciezke plikow .DOL" - -#~ msgid "Disc Path Changed" -#~ msgstr "Sciezka do dysku zmieniona" - -#~ msgid "Display favorites" -#~ msgstr "Pokaz ulubione" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Powtorzyc za 30 sec?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Wlacz kontrole rodzicielska" - -#~ msgid "Force" -#~ msgstr "Wymuc" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Sciezka kodow GCT zmienona" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Sciezka aplikacji homebrew zmieniona" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Wloz karte SD, aby pobrac obrazki" - -#~ msgid "Install not possible" -#~ msgstr "Nie mozna zainstalowac" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Prawdopodobnie rozdzielczosc nie jest podzielna przez 4" - -#~ msgid "Network init error" -#~ msgstr "Problem inicjalizacji sieci" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Nie znaleziono plikow .dol ani .elf" - -#~ msgid "No Favorites" -#~ msgstr "Brak ulubionych" - -#~ msgid "No USB Device" -#~ msgstr "Nie wykryto urzadzenia USB" - -#~ msgid "No USB Device found." -#~ msgstr "Nie wykryto urzadzenia USB" - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Nie znaleziono partycji WBFS, ani FAT/NTFS" - -#~ msgid "Normal Covers" -#~ msgstr "Standardowe okladki" - -#~ msgid "Not Found" -#~ msgstr "Nie znaleziono" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "To nie jest plik DOL/ELF" - -#~ msgid "Save Failed" -#~ msgstr "Nie udalo sie zapisac" - -#~ msgid "Selected DOL" -#~ msgstr "Wybrano plik DOL" - -#~ msgid "Standard" -#~ msgstr "Standardowe" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Sciezka kodow TXT zmienona" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Zmieniono sciezke tematow" - -#~ msgid "Theme Path Changed" -#~ msgstr "Zmieniono sciezke skorek" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX dziala tylko z Hermes CIOS rev 4! Upewnij sie czy masz zainstalowana wersje 4!" - -#~ msgid "Update Path changed." -#~ msgstr "Zmieniono Sciezke aktualizacji" - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Zmieniono sciezke patchy WIP" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Sciezka WiiTDBPath zmieniona" - -#~ msgid "You are about to delete " -#~ msgstr "Zamierzasz usunac" - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "WybraleS wySwietlenie usubionych, ale zadnych nie wybraleS" - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Uzywasz partycji NTFS. Instalacja gier na tej partycji nie jest mozliwa." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Probujesz zaladowac zly obraz" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "Nie istnieje! Cos zepsules" - -#~ msgid "file left" -#~ msgstr "pozostalo" diff --git a/Languages/portuguese_br.lang b/Languages/portuguese_br.lang deleted file mode 100644 index b79b3d09..00000000 --- a/Languages/portuguese_br.lang +++ /dev/null @@ -1,1546 +0,0 @@ -# USB Loader GX language source file. -# portuguese_br.lang - r921 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-23 18:52+0200\n" -"Last-Translator: aniemotion\n" -"Language-Team: boto12, aniemotion\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad salvo como:" - -msgid " could not be downloaded." -msgstr " não foi baixado." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " foi salvo. O texto não foi verificado. Parte do código pode não funcionar corretamente. Se detectar algum problema, abra o texto com um editor de texto para mais informações." - -msgid " is not on the server." -msgstr " não está no servidor." - -msgid "2D Cover Path" -msgstr "Pasta Capas 2D" - -msgid "3D Cover Path" -msgstr "Pasta Capas 3D" - -msgid "3D Covers" -msgstr "Capas 3D" - -msgid ">> Deleting tickets..." -msgstr ">> Eliminando tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Eliminando tickets... ERRO! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Eliminando tickets... Ok! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Eliminando título... ERRO! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Eliminando título... Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Eliminando conteúdos do título..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Eliminando conteúdos do título... ERRO! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Eliminando conteúdos do título... Ok!" - -msgid ">> Deleting title..." -msgstr ">> Eliminando título..." - -msgid ">> Finishing installation..." -msgstr ">> Terminando instalação..." - -msgid ">> Installing content #" -msgstr ">> Instalando conteúdo #" - -msgid ">> Installing ticket..." -msgstr ">> Instalando ticket..." - -msgid ">> Installing title..." -msgstr ">> Instalando título..." - -msgid ">> Reading WAD data..." -msgstr ">> Lendo arquivo WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Lendo arquivo WAD... ERRO!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Lendo arquivo WAD... Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Todas as Partições" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "As configurações estão desbloqueadas." - -msgid "Alternate DOL" -msgstr "DOL alternativo" - -msgid "App Language" -msgstr "Idioma" - -msgid "Apr" -msgstr "Abr" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Tem certeza?" - -msgid "Aug" -msgstr "Ago" - -msgid "Author:" -msgstr "Autor:" - -msgid "AutoInit Network" -msgstr "Auto-iniciar Rede" - -msgid "BCA Codes Path" -msgstr "Caminho do BCA Codes" - -msgid "BETA revisions" -msgstr "Revisões BETA" - -msgid "Back" -msgstr "Voltar" - -msgid "Back to HBC or Wii Menu" -msgstr "Voltar ao Loader/Menu do Wii" - -msgid "Back to Loader" -msgstr "Loader" - -msgid "Backgroundmusic" -msgstr "Música de fundo" - -msgid "Big thanks to:" -msgstr "Agradecimentos:" - -msgid "Block IOS Reload" -msgstr "Bloquear reload do IOS" - -msgid "Boot/Standard" -msgstr "Carregar/Standard" - -msgid "Boot?" -msgstr "Carregar?" - -msgid "Can't be formatted" -msgstr "Não pode pode ser formatado" - -msgid "Can't create directory" -msgstr "Não foi possível criar a pasta" - -msgid "Can't create file" -msgstr "Não foi possivel criar o arquivo" - -msgid "Can't delete:" -msgstr "Não foi possível apagar:" - -msgid "Cancel" -msgstr "Cancelar" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Alterar Caminho para Play" - -msgid "Cheatfile is blank" -msgstr "arquivo de truques vazio" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Aperte para baixar capas" - -msgid "Click to change game ID" -msgstr "Alterar o ID do jogo" - -msgid "Clock" -msgstr "Relógio" - -msgid "Close" -msgstr "Fechar" - -msgid "Code Download" -msgstr "Download de Código" - -#, c-format -msgid "Coded by: %s" -msgstr "Programado por: %s" - -msgid "Coding:" -msgstr "Desenvolvimento:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "Configuração" - -msgid "Console Locked" -msgstr "Configuração Bloqueada" - -msgid "Console should be unlocked to modify it." -msgstr "É necessário desbloquear a configuração para poder modificar o parâmetro." - -msgid "Continue to install game?" -msgstr "Continuar instalação do jogo?" - -msgid "Controllevel" -msgstr "Nível de Controle" - -msgid "Correct Password" -msgstr "Password Correto" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Não foi possível criar o arquivo GCT" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Não foi possível inicializar o módulo DIP!" - -msgid "Could not initialize network!" -msgstr "Não foi possível incializar a Ligação de Rede!" - -msgid "Could not open Disc" -msgstr "Não foi possível abrir o Disco" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Não foi possível gravar." - -msgid "Cover Download" -msgstr "Download de Capas" - -msgid "Create" -msgstr "Criar" - -msgid "Credits" -msgstr "Créditos" - -msgid "Custom Paths" -msgstr "Personalização de Pastas" - -msgid "DOL Path" -msgstr "Pasta DOL" - -msgid "Dec" -msgstr "Dez" - -msgid "Default" -msgstr "Padrão" - -msgid "Default Gamesettings" -msgstr "Configuração do Jogo padrão" - -msgid "Default Settings" -msgstr "Configurações padrões" - -msgid "Delete" -msgstr "Eliminar" - -msgid "Delete ?" -msgstr "Eliminar ?" - -msgid "Delete Cheat GCT" -msgstr "Eliminar GCT Truques" - -msgid "Delete Cheat TXT" -msgstr "Eliminar TXT Truques" - -msgid "Delete Cover Artwork" -msgstr "Eliminar Capas" - -msgid "Delete Disc Artwork" -msgstr "Eliminar Img. Disco" - -msgid "Design:" -msgstr "Desenho:" - -msgid "Developed by" -msgstr "Desenvolvido por" - -msgid "Directory does not exist!" -msgstr "Diretorio não existe!" - -msgid "Disc Artwork Download" -msgstr "Baixar Imagens Disco" - -msgid "Disc Artwork Path" -msgstr "Pasta Imagens Disco" - -msgid "Disc Images" -msgstr "Imagens de Disco" - -msgid "Display" -msgstr "Mostrar" - -msgid "Display as a carousel" -msgstr "Mostrar como carrossel" - -msgid "Display as a grid" -msgstr "Mostrar como grelha" - -msgid "Display as a list" -msgstr "Mostrar como lista" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Tem a certeza que quer eliminar o jogo:" - -msgid "Do you want to apply it now?" -msgstr "Deseja aplicar agora?" - -msgid "Do you want to change language?" -msgstr "Deseja alterar o idioma?" - -msgid "Do you want to download this theme?" -msgstr "Deseja baixar este tema?" - -msgid "Do you want to format:" -msgstr "Deseja FORMATAR:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Deseja usar o DOL alternativo que pensa ser o correcto?" - -msgid "Do you wish to update/download all language files?" -msgstr "Deseja atualizar todos os arquivos de idioma?" - -msgid "Done!" -msgstr "Concluído!" - -msgid "Download" -msgstr "Baixar" - -msgid "Download Boxart image?" -msgstr "Baixar imagem da Caixa?" - -msgid "Download Discart image?" -msgstr "Baixar imagem do Disco?" - -msgid "Download Now" -msgstr "Baixar agora" - -msgid "Download failed." -msgstr "Download falhou" - -msgid "Download finished" -msgstr "Download Terminado" - -msgid "Download request failed." -msgstr "Download requerido falhou" - -msgid "Downloading Page List:" -msgstr "Baixando lista de paginas:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Baixando arquivo" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Baixando imagem:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "ERRO" - -msgid "ERROR:" -msgstr "ERRO:" - -msgid "ERROR: Can't set up theme." -msgstr "ERRO: Impossível aplicar tema" - -msgid "Error" -msgstr "Erro" - -msgid "Error !" -msgstr "Erro !" - -msgid "Error 002 fix" -msgstr "Correção Erro 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Erro ao ler o Disco" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Erro na transferência de dados." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Erro..." - -msgid "Error:" -msgstr "Erro:" - -msgid "Extracting files..." -msgstr "Extraindo arquivos..." - -msgid "FAT: Use directories" -msgstr "FAT: Usar Diretórios" - -msgid "Failed formating" -msgstr "Falha ao formatar" - -msgid "Failed to extract." -msgstr "Falha ao extrair" - -msgid "Failed to open partition" -msgstr "Falha ao abrir partição" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Fev" - -msgid "File not found." -msgstr "Arquivo não encontrado." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Terminando instalação... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Paginação Horizontal" - -msgid "Format" -msgstr "Formatar" - -msgid "Formatting, please wait..." -msgstr "Formatando, por favor aguarde..." - -msgid "Free Space" -msgstr "Espaço Livre" - -msgid "Full Shutdown" -msgstr "Desligar" - -msgid "GCT Cheatcodes Path" -msgstr "Pasta Truques" - -msgid "GCT File created" -msgstr "Arquivo GCT criado" - -msgid "GUI Settings" -msgstr "Definições de Interface" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg não encontrado em nenhuma subpasta" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Idioma" - -msgid "Game Load" -msgstr "Carregando Jogos" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Tamanho do Jogo" - -msgid "Game Sound Mode" -msgstr "Modo de Som do Jogo" - -msgid "Game Sound Volume" -msgstr "Volume dos Sons dos Jogos" - -msgid "Game is already installed:" -msgstr "Este jogo já está instalado:" - -msgid "Game partition" -msgstr "Partição de Game" - -msgid "Games" -msgstr "Jogos" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Menu Inicial" - -msgid "Homebrew Apps Path" -msgstr "Pasta Apps Homebrew" - -msgid "Homebrew Launcher" -msgstr "Launcher Homebrew" - -msgid "Hour" -msgstr "Horas" - -msgid "How do you want to update?" -msgstr "Como pretende atualizar o programa?" - -msgid "How to Shutdown?" -msgstr "Como desligar?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Se não tem conexão sem fios, pressione 1 para ver a URL onde se pode baixar o arquivo WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Recebendo arquivo %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Recebendo arquivo %0.2fMB" - -msgid "Initializing Network" -msgstr "Inicializando a Rede" - -msgid "Insert Disk" -msgstr "Insira o Disco" - -msgid "Insert a Wii Disc!" -msgstr "Insira um Disco do Wii!" - -msgid "Insert an SD-Card to save." -msgstr "Insira um cartão SD para salvar." - -msgid "Insert an SD-Card to use this option." -msgstr "Insira um cartão SD para usar esta funcionalidade." - -msgid "Install" -msgstr "Instalar" - -msgid "Install Error!" -msgstr "Erro de Instalação!" - -msgid "Install a game" -msgstr "Instalar um jogo" - -msgid "Install partitions" -msgstr "Instalare partições" - -msgid "Installing content... Ok!" -msgstr "Instalando conteúdo... Ok!" - -msgid "Installing game:" -msgstr "Instalando jogo:" - -msgid "Installing ticket... Ok!" -msgstr "Instalando ticket... Ok!" - -msgid "Installing title... Ok!" -msgstr "Instalando título... Ok!" - -msgid "Installing wad" -msgstr "Instalando wad" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Parece que tem uma informação que pode ser útil. Por favor envie esta informação a nossa equipe de desenvolvimento." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Jul" - -msgid "June" -msgstr "Jun" - -msgid "Keep" -msgstr "Manter" - -msgid "Keyboard" -msgstr "Teclado" - -msgid "Language File" -msgstr "Idiomas" - -msgid "Language change:" -msgstr "Alteração de idioma:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Caminho para o arquivo de Idioma alterado." - -msgid "Load" -msgstr "Carregar" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Carregar arquivo de: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Carregar este DOL como DOL alternativo?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Carregado idioma padrão." - -msgid "Loading standard music." -msgstr "Carregando música padrão." - -msgid "Lock Console" -msgstr "Bloquear Configurações" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "Marcar games novos" - -msgid "May" -msgstr "Mai" - -msgid "Missing files" -msgstr "Faltando arquivos" - -msgid "Mount DVD drive" -msgstr "Carregar leitor DVD" - -msgid "Music Loop Mode" -msgstr "Modo Repetição de Música" - -msgid "Music Volume" -msgstr "Volume da Música" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Detectado Novo Disco" - -msgid "No" -msgstr "Não" - -msgid "No Cheatfile found" -msgstr "Arquivo de truques não encontrado" - -msgid "No DOL file found on disc." -msgstr "Não foi encontrado nenhum arquivo dol no disco" - -msgid "No SD-Card inserted!" -msgstr "Cartão SD não inserido!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Nenhuma seleção de truques" - -msgid "No data could be read." -msgstr "Não foi possível ler dados." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Faltando nenhum arquivo" - -msgid "No new updates." -msgstr "Não existem novas atualizações." - -msgid "No themes found on the site." -msgstr "Nenhum tema encontrado no site" - -msgid "Not a WAD file." -msgstr "Não é um arquivo Wad" - -msgid "Not a Wii Disc" -msgstr "Não é um Disco do Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Não há memória livre suficiente." - -msgid "Not enough free space!" -msgstr "Não há espaço livre suficiente!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Formato não suportado!" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "Desligado" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Out" - -msgid "Official Site:" -msgstr "Site Oficial:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Controle de Pais" - -msgid "Partition" -msgstr "Partição" - -msgid "Password" -msgstr "Senha" - -msgid "Password Changed" -msgstr "Senha Alterada" - -msgid "Password has been changed" -msgstr "A Senha foi alterada" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Copie para o seu browser de Internet para baixar o WiiTDB.zip" - -msgid "Patch Country Strings" -msgstr "Patch Jogos Importados" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Escolher da lista" - -msgid "Play Count" -msgstr "Vezes jogadas" - -msgid "Play Next" -msgstr "Tocar Próximo" - -msgid "Play Previous" -msgstr "Tocar Anteior" - -msgid "Playing Music:" -msgstr "Tocando a Música:" - -msgid "Please wait..." -msgstr "Por favor aguarde..." - -msgid "Power off the Wii" -msgstr "Desligar o Wii" - -msgid "Prompts Buttons" -msgstr "Mensagens/Botões" - -msgid "Published by" -msgstr "Publicado por" - -msgid "Quick Boot" -msgstr "Inicialização Rápida" - -msgid "Reading WAD data... Ok!" -msgstr "Lendo dados do WAD... Ok!" - -msgid "Receiving file from:" -msgstr "Recebendo arquivo de:" - -msgid "Released" -msgstr "Lançamento" - -msgid "Reload SD" -msgstr "Atualizar do cartão SD" - -msgid "Remove update" -msgstr "Remover atualização" - -msgid "Rename Game on WBFS" -msgstr "Alterar nome do jogo na partição WBFS" - -msgid "Reset BG Music" -msgstr "Resetar Música de Fundo" - -msgid "Reset Playcounter" -msgstr "Limpar Contagem" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "O Wii irá reiniciar" - -msgid "Return" -msgstr "Voltar" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Voltar ao Menu do Wii" - -msgid "Rumble" -msgstr "Vibração" - -msgid "SFX Volume" -msgstr "Volume dos Efeitos" - -msgid "Save" -msgstr "Gravar" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Gravar a lista dos jogos sobre" - -msgid "Saved" -msgstr "Gravado" - -msgid "Screensaver" -msgstr "Proteção de tela" - -msgid "Select" -msgstr "selecionar" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Selecionar um DOL" - -msgid "Sept" -msgstr "Set" - -msgid "Set Search-Filter" -msgstr "Usar filtro de busca" - -msgid "Settings" -msgstr "Configurações" - -msgid "Shutdown System" -msgstr "Desligar" - -msgid "Shutdown to Idle" -msgstr "Standby" - -msgid "Sort alphabetically" -msgstr "Ordenar por ordem alfabética" - -msgid "Sort by rank" -msgstr "Ordenar por ranking" - -msgid "Sort order by most played" -msgstr "Ordenar por número de vezes jogadas" - -msgid "Sound" -msgstr "Audio" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Agradecimentos especiais para:" - -msgid "Success" -msgstr "Sucesso" - -msgid "Success:" -msgstr "Sucesso:" - -msgid "Successfully Saved" -msgstr "Gravado com Sucesso" - -msgid "Successfully Updated" -msgstr "Programa atualizado com Sucesso" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Atualizado com sucesso graças a www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Eliminado com Sucesso:" - -msgid "Successfully extracted theme." -msgstr "Tema extraido com sucesso." - -msgid "Successfully installed:" -msgstr "Instalado com Sucesso:" - -msgid "TXT Cheatcodes Path" -msgstr "Pasta Dicas" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "O diretorio não existe. Gostaria de cria-lo?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Pasta de Temas Baixados" - -msgid "Theme Downloader" -msgstr "Baixador de Temas" - -msgid "Theme Path" -msgstr "Pasta Temas" - -msgid "Theme Title:" -msgstr "Titulo do Tema:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Tempo restante:" - -msgid "Title Launcher" -msgstr "Laucher de Títulos" - -msgid "Titles from WiiTDB" -msgstr "Títulos do WiiTDB" - -msgid "Tooltips" -msgstr "Dicas" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Falhou a transferencia" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "Dispositivo USB não encontrado" - -msgid "USB Loader GX is protected" -msgstr "O USB Loader GX está bloqueado" - -msgid "Uninstall" -msgstr "Desinstalar" - -msgid "Uninstall Game" -msgstr "Desinstalar jogo" - -msgid "Uninstall Menu" -msgstr "Menu de Desinstalação" - -msgid "Uninstalling wad" -msgstr "Desinstalando wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Desbloquear configuração antes de usar esta opção." - -msgid "Unsupported format, try to extract manually." -msgstr "Formato não suportado, tente extrair manualmente." - -msgid "Update" -msgstr "Verificar Atualizações" - -msgid "Update All" -msgstr "Atualizar Tudo" - -msgid "Update DOL" -msgstr "Atualizar DOL" - -msgid "Update Files" -msgstr "Atualizar arquivos" - -msgid "Update Path" -msgstr "Pasta Atualizações" - -msgid "Update all Language Files" -msgstr "Atualizar todos os arquivos de Idioma" - -msgid "Update failed" -msgstr "Erro ao atualizar" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Atualizando arquivos de Idioma:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Arquivo ZIP enviado y instalado no diretório homebrew." - -msgid "VIDTV Patch" -msgstr "Patch VIDTV" - -#, c-format -msgid "Version: %s" -msgstr "Versão: %s" - -msgid "Video Mode" -msgstr "Modo de Vídeo" - -msgid "WIP Patches Path" -msgstr "Caminho WIP Patches" - -msgid "Waiting for USB Device" -msgstr "Aguardando pelo Dispositivo USB" - -msgid "Waiting..." -msgstr "Aguardando..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "O que deseja atualizar?" - -msgid "WiFi Features" -msgstr "Rede sem fios" - -msgid "Wii Menu" -msgstr "Menu do Wii" - -msgid "Wii Settings" -msgstr "Configuração do Wii" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "Pasta WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Iluminação Leitor" - -msgid "Wrong Password" -msgstr "Password Incorreto" - -msgid "Yes" -msgstr "Sim" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Você precisa selecionar ou formatar uma partição" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Sua URL foi salva em %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "e tradutores para atualizações de linguas" - -msgid "available" -msgstr "disponível" - -msgid "does not exist!" -msgstr "não existe!" - -msgid "does not exist! Loading game without cheats." -msgstr "não existe! Carregando jogo sem truques." - -msgid "files left" -msgstr "arquivos restantes" - -msgid "files not found on the server!" -msgstr "arquivos não encontrados no servidor!" - -msgid "for FAT/NTFS support" -msgstr "para suporte a FAT/NTFS" - -msgid "for Ocarina" -msgstr "pelo Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "por WiiTDB e hospedando img. capas / discos" - -msgid "for diverse patches" -msgstr "por diversos patches" - -msgid "for his awesome tool LibWiiGui" -msgstr "pela sua espetacular ferramenta LibWiiGui" - -msgid "for hosting the themes" -msgstr "por hospedar os temas" - -msgid "for hosting the update files" -msgstr "por hospedar atualizações" - -msgid "for the USB Loader source" -msgstr "pelo código do USB Loader" - -msgid "formatted!" -msgstr "formatado!" - -msgid "free" -msgstr "livres" - -msgid "not set" -msgstr "não definido" - -msgid "of" -msgstr "de" - -msgid "seconds left" -msgstr "segundos restantes" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Instalar 1:1 Copy" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Todos)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Crianças 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 hora" - -#~ msgid "10 min" -#~ msgstr "10 minutos" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Adolescente 12+)" - -#~ msgid "20 min" -#~ msgstr "20 minutos" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Adulto 16+)" - -#~ msgid "3 min" -#~ msgstr "3 minutos" - -#~ msgid "30 min" -#~ msgstr "30 minutos" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Adultos 18+)" - -#~ msgid "5 min" -#~ msgstr "5 minutos" - -#~ msgid "An Error occured" -#~ msgstr "Ocorreu um Erro" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Tem certeza que você deseja ligar o Controle de Pais?" - -#~ msgid "AutoPatch" -#~ msgstr "Patch automático" - -#~ msgid "Both" -#~ msgstr "Ambos" - -#~ msgid "Checking for Updates" -#~ msgstr "Procurando Atualizações" - -#~ msgid "Console Default" -#~ msgstr "Configurações padrões" - -#~ msgid "Customs/Original" -#~ msgstr "Alternativas/Originais" - -#~ msgid "Disc Default" -#~ msgstr "Disco Padrão" - -#~ msgid "DiskFlip" -#~ msgstr "Voltar Disco" - -#~ msgid "Downloading" -#~ msgstr "Baixando" - -#~ msgid "Dutch" -#~ msgstr "Holandês" - -#~ msgid "English" -#~ msgstr "Inglês" - -#~ msgid "French" -#~ msgstr "Francês" - -#~ msgid "Game ID" -#~ msgstr "ID do Jogo" - -#~ msgid "Game Region" -#~ msgstr "Região" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "Nome do Jogo [GAMEID]" - -#~ msgid "German" -#~ msgstr "Alemão" - -#~ msgid "Invalid PIN code" -#~ msgstr "Código PIN inválido" - -#~ msgid "Italian" -#~ msgstr "Italiano" - -#~ msgid "Japanese" -#~ msgstr "Japonês" - -#~ msgid "Korean" -#~ msgstr "Coreano" - -#~ msgid "Left" -#~ msgstr "Esquerda" - -#~ msgid "Like SysMenu" -#~ msgstr "Igual ao Menu do Wii" - -#~ msgid "Load From SD/USB" -#~ msgstr "Carregar do SD/USB" - -#~ msgid "Locked" -#~ msgstr "Bloqueado" - -#~ msgid "Loop Directory" -#~ msgstr "Repitir Diretório" - -#~ msgid "Loop Music" -#~ msgstr "Repitir Música" - -#~ msgid "Loop Sound" -#~ msgstr "Repitir Som" - -#~ msgid "Neither" -#~ msgstr "Nenhum" - -#~ msgid "Next" -#~ msgstr "Próximo" - -#~ msgid "None" -#~ msgstr "Nenhum" - -#~ msgid "ON" -#~ msgstr "Ligado" - -#~ msgid "Only Customs" -#~ msgstr "Apenas Alternativas" - -#~ msgid "Only Original" -#~ msgstr "Apenas Originais" - -#~ msgid "Only for Install" -#~ msgstr "Apenas na instalação" - -#~ msgid "Original/Customs" -#~ msgstr "Originais/Alternativas" - -#~ msgid "Parental Control disabled" -#~ msgstr "Controle dos Pais desligado" - -#~ msgid "Play Once" -#~ msgstr "Tocar uma só vez" - -#~ msgid "Prev" -#~ msgstr "Anterior" - -#~ msgid "Random Directory Music" -#~ msgstr "Diretótio Aleatório de Músicas" - -#~ msgid "Right" -#~ msgstr "Direita" - -#~ msgid "SChinese" -#~ msgstr "Chinês Simplificado" - -#~ msgid "Sound+BGM" -#~ msgstr "Som+Music de Fundo" - -#~ msgid "Sound+Quiet" -#~ msgstr "Som+Quieto" - -#~ msgid "Spanish" -#~ msgstr "Espanhol" - -#~ msgid "System Default" -#~ msgstr "Padrão do Sistema" - -#~ msgid "TChinese" -#~ msgstr "Chinês Tradicional" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "O arquivo wad foi instalado mas não foi possível eliminá-lo do cartão SD." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "A instalação do wad falhou com o seguinte erro: %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Não é possível abrir o arquivo wad baixado (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Desbloquear Controle de Pais" - -#~ msgid "Unlocked" -#~ msgstr "Desbloqueado" - -#~ msgid "Update to" -#~ msgstr "Atualizando para" - -#~ msgid "Updating" -#~ msgstr "Atualizando" - -#~ msgid "Updating Language Files..." -#~ msgstr "Atualizando arquivos de Idioma..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Atualizando WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Correção 16:9" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Você não tem o Controle de Pais ligado. Se você deseja usar o Controle de Pais, ligue-o nas Configurações do Wii." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Pode não carregar corretamente se seu sistema não estiver atualizado." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Caminho do BCA Codes alterado" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Menu do Wii" - -#~ msgid "Channels" -#~ msgstr "Canais" - -#~ msgid "Checking existing artwork" -#~ msgstr "Procurando artes existentes" - -#~ msgid "Confirm" -#~ msgstr "Confirmar" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Não foi encontrada nenhuma partição WBFS." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Não foi possível abrir a partição WBFS" - -#~ msgid "Could not read the disc." -#~ msgstr "Não foi possível ler o disco." - -#~ msgid "Could not set USB." -#~ msgstr "Não foi possível configurar a porta USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "Pasta das Capas alterada" - -#~ msgid "DOL path changed" -#~ msgstr "Pasta do DOL alterada" - -#~ msgid "Disc Path Changed" -#~ msgstr "Pasta das Imagens Disco alterada" - -#~ msgid "Display favorites" -#~ msgstr "Mostrar favoritos" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Deseja tentar novamente dentro de 30 segs?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Ligar Controle de Pais" - -#~ msgid "Force" -#~ msgstr "Forçar" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Pasta de Truques alterada" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Pasta Apps Homebrew alterada" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Insira um cartão SD para descarregar as imagens." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Provável que o tamanho não seja divisível por 4." - -#~ msgid "Network init error" -#~ msgstr "Erro ao inicializar ligação de rede" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Não foram encontrados nenhuns arquivos .dol ou .elf" - -#~ msgid "No Favorites" -#~ msgstr "Lista de favoritos vazia" - -#~ msgid "No USB Device" -#~ msgstr "Nenhum dispositivo USB" - -#~ msgid "No USB Device found." -#~ msgstr "Nenhum dispositivo USB encontrado." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Nenhuma partição WBFS o FAT/NTFS encontrada" - -#~ msgid "Normal Covers" -#~ msgstr "Capas Normais" - -#~ msgid "Not Found" -#~ msgstr "Não encontrado" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Não é um arquivo DOL/ELF válido." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Resetar para Música de Fundo padrão?" - -#~ msgid "Save Failed" -#~ msgstr "Falha ao Gravar" - -#~ msgid "Selected DOL" -#~ msgstr "DOL selecionado" - -#~ msgid "Standard" -#~ msgstr "Standard" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Pasta de Dicas alterada" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Pasta de Temas Baixados Alterado" - -#~ msgid "Theme Path Changed" -#~ msgstr "Pasta dos Temas alterada" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "O USB Loader GX será executado apenas com a Hermes CIOS rev 4! Por favor tenha certeza de que tem a revisão 4 instalada!" - -#~ msgid "Update Path changed." -#~ msgstr "A pasta das atualizações foi alterada." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Caminho WIP Patches alterado" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Pasta WiiTDB alterada." - -#~ msgid "You are about to delete " -#~ msgstr "Irá eliminar " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Está tentando visualizar os favoritos, mas não existe nenhum selecionado." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Você tentou carregar uma imagem corrompida" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "não existe! Estragou algo, idiota." - -#~ msgid "file left" -#~ msgstr "arquivo restante" diff --git a/Languages/portuguese_pt.lang b/Languages/portuguese_pt.lang deleted file mode 100644 index c3545a66..00000000 --- a/Languages/portuguese_pt.lang +++ /dev/null @@ -1,1564 +0,0 @@ -# USB Loader GX language source file. -# portuguese_pt.lang - r931 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2010-03-22 10:55-0000\n" -"Last-Translator: Sky8000\n" -"Language-Team: Sky8000 \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad guardado como:" - -msgid " could not be downloaded." -msgstr " não foi descarregado." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " foi guardado. O texto não foi verificado. Parte do código pode não funcionar correctamente. Se detectares problemas abre o texto com um editor de texto para obteres mais informação." - -msgid " is not on the server." -msgstr " não está no servidor." - -msgid "2D Cover Path" -msgstr "Pasta Capas 2D" - -msgid "3D Cover Path" -msgstr "Pasta Capas 3D" - -msgid "3D Covers" -msgstr "Capas 3D" - -msgid ">> Deleting tickets..." -msgstr ">> Eliminando tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Eliminando tickets... ERRO! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Eliminando tickets... Ok! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Eliminando título... ERRO! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Eliminando título... Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Eliminando conteúdos do título..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Eliminando conteúdos do título... ERRO! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Eliminando conteúdos do título... Ok!" - -msgid ">> Deleting title..." -msgstr ">> Eliminando título..." - -msgid ">> Finishing installation..." -msgstr ">> Terminando instalação..." - -msgid ">> Installing content #" -msgstr ">> Instalando conteúdo #" - -msgid ">> Installing ticket..." -msgstr ">> Instalando ticket..." - -msgid ">> Installing title..." -msgstr ">> Instalando título..." - -msgid ">> Reading WAD data..." -msgstr ">> Lendo ficheiro WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Lendo ficheiro WAD... ERRO!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Lendo ficheiro WAD... Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Todas as partições" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "As configurações estão desbloqueadas." - -msgid "Alternate DOL" -msgstr "DOL alternativo" - -msgid "App Language" -msgstr "Idioma" - -msgid "Apr" -msgstr "Abr" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Tem a certeza?" - -msgid "Aug" -msgstr "Ago" - -msgid "Author:" -msgstr "Autor:" - -msgid "AutoInit Network" -msgstr "Auto-iniciar Rede" - -msgid "BCA Codes Path" -msgstr "Pasta Códigos BCA" - -msgid "BETA revisions" -msgstr "Revisões BETA" - -msgid "Back" -msgstr "Voltar" - -msgid "Back to HBC or Wii Menu" -msgstr "Voltar ao Loader/Menu da Wii" - -msgid "Back to Loader" -msgstr "Loader" - -msgid "Backgroundmusic" -msgstr "Música de fundo" - -msgid "Big thanks to:" -msgstr "Agradecimentos:" - -msgid "Block IOS Reload" -msgstr "Bloquear Reload do IOS" - -msgid "Boot/Standard" -msgstr "Arranque/Standard" - -msgid "Boot?" -msgstr "Carregar?" - -msgid "Can't be formatted" -msgstr "Não pode ser formatado" - -msgid "Can't create directory" -msgstr "Não foi possível criar a pasta" - -msgid "Can't create file" -msgstr "Não é possível criar o ficheiro" - -msgid "Can't delete:" -msgstr "Não foi possível apagar:" - -msgid "Cancel" -msgstr "Cancelar" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Alterar Pasta de Músicas" - -msgid "Cheatfile is blank" -msgstr "Ficheiro de truques vazio" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Carregue para descarregar capas" - -msgid "Click to change game ID" -msgstr "Carregue para alterar o ID do jogo" - -msgid "Clock" -msgstr "Relógio" - -msgid "Close" -msgstr "Fechar" - -msgid "Code Download" -msgstr "Download de Código" - -#, c-format -msgid "Coded by: %s" -msgstr "Programado por: %s" - -msgid "Coding:" -msgstr "Desenvolvimento:" - -msgid "Connection lost..." -msgstr "Ligação perdida..." - -msgid "Console" -msgstr "Configuração" - -msgid "Console Locked" -msgstr "Configuração Bloqueada" - -msgid "Console should be unlocked to modify it." -msgstr "É necessário desbloquear a configuração para poder modificar o parâmetro." - -msgid "Continue to install game?" -msgstr "Continuar instalação do jogo?" - -msgid "Controllevel" -msgstr "Nível de Controle" - -msgid "Correct Password" -msgstr "Password Correcta" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Não foi possível criar o ficheiro GCT" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Não foi possível inicializar o módulo DIP!" - -msgid "Could not initialize network!" -msgstr "Não foi possível incializar a Ligação de Rede!" - -msgid "Could not open Disc" -msgstr "Não foi possível abrir o Disco" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Não foi possível gravar." - -msgid "Cover Download" -msgstr "Download de Capas" - -msgid "Create" -msgstr "Criar" - -msgid "Credits" -msgstr "Créditos" - -msgid "Custom Paths" -msgstr "Personalização de Pastas" - -msgid "DOL Path" -msgstr "Pasta DOL" - -msgid "Dec" -msgstr "Dez" - -msgid "Default" -msgstr "Predefinição" - -msgid "Default Gamesettings" -msgstr "Repor Configuração do Jogo" - -msgid "Default Settings" -msgstr "Repor Configurações" - -msgid "Delete" -msgstr "Eliminar" - -msgid "Delete ?" -msgstr "Eliminar ?" - -msgid "Delete Cheat GCT" -msgstr "Eliminar Truques (GCT)" - -msgid "Delete Cheat TXT" -msgstr "Eliminar Truques (TXT)" - -msgid "Delete Cover Artwork" -msgstr "Eliminar Capas" - -msgid "Delete Disc Artwork" -msgstr "Eliminar Img. Disco" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "Desenvolvido por" - -msgid "Directory does not exist!" -msgstr "A Pasta não existe!" - -msgid "Disc Artwork Download" -msgstr "Descaregar Imagens Disco" - -msgid "Disc Artwork Path" -msgstr "Pasta Imagens Disco" - -msgid "Disc Images" -msgstr "Imagens de Disco" - -msgid "Display" -msgstr "Mostrar" - -msgid "Display as a carousel" -msgstr "Mostrar como carrossel" - -msgid "Display as a grid" -msgstr "Mostrar como grelha" - -msgid "Display as a list" -msgstr "Mostrar como lista" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Tem a certeza que quer eliminar o jogo:" - -msgid "Do you want to apply it now?" -msgstr "Deseja aplicar agora?" - -msgid "Do you want to change language?" -msgstr "Deseja alterar o idioma?" - -msgid "Do you want to download this theme?" -msgstr "Deseja descarregar este tema?" - -msgid "Do you want to format:" -msgstr "Deseja FORMATAR:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Pretende usar o DOL alternativo que se pensa ser o correcto?" - -msgid "Do you wish to update/download all language files?" -msgstr "Queres actualizar todos os ficheiros de idioma?" - -msgid "Done!" -msgstr "Concluído!" - -msgid "Download" -msgstr "Descarregar" - -msgid "Download Boxart image?" -msgstr "Descarregar imagem da Caixa?" - -msgid "Download Discart image?" -msgstr "Descarregar imagem do Disco?" - -msgid "Download Now" -msgstr "Descarregar Agora" - -msgid "Download failed." -msgstr "O download falhou." - -msgid "Download finished" -msgstr "Download Terminado" - -msgid "Download request failed." -msgstr "O pedido de download falhou." - -msgid "Downloading Page List:" -msgstr "Descarregando Lista de Páginas:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Descarregando ficheiro:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Descarregando imagem:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "ERRO" - -msgid "ERROR:" -msgstr "ERRO:" - -msgid "ERROR: Can't set up theme." -msgstr "ERRO: Impossível configurar tema." - -msgid "Error" -msgstr "Erro" - -msgid "Error !" -msgstr "Erro !" - -msgid "Error 002 fix" -msgstr "Correcção Erro 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Erro ao ler o Disco" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Erro na transferência de dados." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Erro..." - -msgid "Error:" -msgstr "Erro:" - -msgid "Extracting files..." -msgstr "Extraindo ficheiros..." - -msgid "FAT: Use directories" -msgstr "FAT: Utilizar pastas" - -msgid "Failed formating" -msgstr "Falha ao formatar" - -msgid "Failed to extract." -msgstr "Falha ao extrair ficheiros." - -msgid "Failed to open partition" -msgstr "Falha ao abrir partição" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Fev" - -msgid "File not found." -msgstr "Ficheiro não encontrado." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Terminando instalação... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Paginação Horizontal" - -msgid "Format" -msgstr "Formatar" - -msgid "Formatting, please wait..." -msgstr "Formatando, por favor aguarde..." - -msgid "Free Space" -msgstr "Espaço Livre" - -msgid "Full Shutdown" -msgstr "Desligar" - -msgid "GCT Cheatcodes Path" -msgstr "Pasta ficheiros GCT" - -msgid "GCT File created" -msgstr "Ficheiro GCT criado" - -msgid "GUI Settings" -msgstr "Definições do Interface" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg não encontrado em nenhuma sub-pasta." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Idioma" - -msgid "Game Load" -msgstr "Carregamento de Jogos" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Tamanho do Jogo" - -msgid "Game Sound Mode" -msgstr "Definições de Audio Jogo" - -msgid "Game Sound Volume" -msgstr "Volume de Som do Jogo" - -msgid "Game is already installed:" -msgstr "O jogo já está instalado:" - -msgid "Game partition" -msgstr "Partição de Jogos" - -msgid "Games" -msgstr "Jogos" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Menú Inicial" - -msgid "Homebrew Apps Path" -msgstr "Pasta Apps Homebrew" - -msgid "Homebrew Launcher" -msgstr "Launcher Homebrew" - -msgid "Hour" -msgstr "Horas" - -msgid "How do you want to update?" -msgstr "O que deseja actualizar?" - -msgid "How to Shutdown?" -msgstr "Como desligar a consola?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Pressione 1 para ver o URL de onde pode descarregar o ficheiro WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "A receber ficheiro %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "A receber ficheiro %0.2fMB" - -msgid "Initializing Network" -msgstr "Inicializando Ligação de Rede" - -msgid "Insert Disk" -msgstr "Insira o Disco" - -msgid "Insert a Wii Disc!" -msgstr "Insira um Disco da Wii!" - -msgid "Insert an SD-Card to save." -msgstr "Insira um cartão SD para guardar." - -msgid "Insert an SD-Card to use this option." -msgstr "Insira um cartão SD para usar esta funcionalidade." - -msgid "Install" -msgstr "Instalar" - -msgid "Install Error!" -msgstr "Erro de Instalação!" - -msgid "Install a game" -msgstr "Instalar um jogo" - -msgid "Install partitions" -msgstr "Instalar partições" - -msgid "Installing content... Ok!" -msgstr "Instalando conteúdo... Ok!" - -msgid "Installing game:" -msgstr "Instalando jogo:" - -msgid "Installing ticket... Ok!" -msgstr "Instalando ticket... Ok!" - -msgid "Installing title... Ok!" -msgstr "Instalando título... Ok!" - -msgid "Installing wad" -msgstr "Instalando wad" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Parece que tem informação que pode ser útil. Por favor envie esta informação à equipa de desenvolvimento." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Jul" - -msgid "June" -msgstr "Jun" - -msgid "Keep" -msgstr "Manter" - -msgid "Keyboard" -msgstr "Teclado" - -msgid "Language File" -msgstr "Idiomas" - -msgid "Language change:" -msgstr "Alteração de idioma:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Pasta para o ficheiro de Idioma alterada." - -msgid "Load" -msgstr "Carregar" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Carregar ficheiro de: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Carregar este DOL como DOL alternativo?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Carregado idioma padrão." - -msgid "Loading standard music." -msgstr "Carregando música padrão." - -msgid "Lock Console" -msgstr "Bloquear Configurações" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "Marcar jogos novos" - -msgid "May" -msgstr "Mai" - -msgid "Missing files" -msgstr "Ficheiros em falta" - -msgid "Mount DVD drive" -msgstr "Montar Unidade de DVD" - -msgid "Music Loop Mode" -msgstr "Modo de Repetição" - -msgid "Music Volume" -msgstr "Volume Música" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Novo Disco Detectado" - -msgid "No" -msgstr "Não" - -msgid "No Cheatfile found" -msgstr "Ficheiro de truques não encontrado" - -msgid "No DOL file found on disc." -msgstr "Não foi encontrado nenhum ficheiro DOL no disco" - -msgid "No SD-Card inserted!" -msgstr "Cartão SD não inserido!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Não foram seleccionados truques" - -msgid "No data could be read." -msgstr "Não foi possível ler dados." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Nenhum ficheiro em falta!" - -msgid "No new updates." -msgstr "Não existem novas actualizações." - -msgid "No themes found on the site." -msgstr "Nenhum tema encontrado no site." - -msgid "Not a WAD file." -msgstr "Não é um ficheiro WAD." - -msgid "Not a Wii Disc" -msgstr "Não é um Disco da Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Não há memória livre suficiente." - -msgid "Not enough free space!" -msgstr "Não há espaço livre suficiente!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Formato não suportado!" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "Desligado" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Out" - -msgid "Official Site:" -msgstr "Site Oficial:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Controlo Parental" - -msgid "Partition" -msgstr "Partição" - -msgid "Password" -msgstr "" - -msgid "Password Changed" -msgstr "Password Alterada" - -msgid "Password has been changed" -msgstr "A Password foi alterada" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Copie para o seu browser de Internet para descarregar o WiiTDB.zip" - -msgid "Patch Country Strings" -msgstr "Patch Jogos Importados" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Escolher da lista" - -msgid "Play Count" -msgstr "Vezes jogadas" - -msgid "Play Next" -msgstr "Próxima" - -msgid "Play Previous" -msgstr "Anterior" - -msgid "Playing Music:" -msgstr "Reproduzindo:" - -msgid "Please wait..." -msgstr "Por favor aguarde..." - -msgid "Power off the Wii" -msgstr "Desligar a Wii" - -msgid "Prompts Buttons" -msgstr "Mensagens/Botões" - -msgid "Published by" -msgstr "Publicado por" - -msgid "Quick Boot" -msgstr "Arranque Rápido" - -msgid "Reading WAD data... Ok!" -msgstr "Lendo dados do WAD... Ok!" - -msgid "Receiving file from:" -msgstr "Recebendo ficheiro de:" - -msgid "Released" -msgstr "Lançamento" - -msgid "Reload SD" -msgstr "Actualizar do cartão SD" - -msgid "Remove update" -msgstr "Remover actualização" - -msgid "Rename Game on WBFS" -msgstr "Alterar nome do jogo (WBFS)" - -msgid "Reset BG Music" -msgstr "Repor Música de Fundo" - -msgid "Reset Playcounter" -msgstr "Limpar Contagem" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "A Wii irá reiniciar" - -msgid "Return" -msgstr "Voltar" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Voltar ao Menu da Wii" - -msgid "Rumble" -msgstr "Vibração" - -msgid "SFX Volume" -msgstr "Volume Efeitos" - -msgid "Save" -msgstr "Gravar" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Gravar lista de Jogos para" - -msgid "Saved" -msgstr "Gravado" - -msgid "Screensaver" -msgstr "Protecção de ecrã" - -msgid "Select" -msgstr "Seleccionar" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Seleccionar o DOL" - -msgid "Sept" -msgstr "Set" - -msgid "Set Search-Filter" -msgstr "Filtro de pesquisa" - -msgid "Settings" -msgstr "Configurações" - -msgid "Shutdown System" -msgstr "Desligar" - -msgid "Shutdown to Idle" -msgstr "Standby" - -msgid "Sort alphabetically" -msgstr "Ordenar por ordem alfabética" - -msgid "Sort by rank" -msgstr "Ordenar por classificação" - -msgid "Sort order by most played" -msgstr "Ordenar por número de vezes jogadas" - -msgid "Sound" -msgstr "Audio" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Agradecimentos especiais para:" - -msgid "Success" -msgstr "Exito" - -msgid "Success:" -msgstr "Sucesso:" - -msgid "Successfully Saved" -msgstr "Gravado com Sucesso" - -msgid "Successfully Updated" -msgstr "Actualização Concluída" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Actualizado com sucesso graças a www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Eliminado com Sucesso:" - -msgid "Successfully extracted theme." -msgstr "Tema extraído com sucesso." - -msgid "Successfully installed:" -msgstr "Instalado com Sucesso:" - -msgid "TXT Cheatcodes Path" -msgstr "Pasta Dicas" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "A pasta não existe, pretende criá-la?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Pasta Download Temas" - -msgid "Theme Downloader" -msgstr "Descarregar de Temas" - -msgid "Theme Path" -msgstr "Pasta Temas" - -msgid "Theme Title:" -msgstr "Título do Tema:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Tempo restante:" - -msgid "Title Launcher" -msgstr "Laucher de Títulos" - -msgid "Titles from WiiTDB" -msgstr "Títulos do WiiTDB" - -msgid "Tooltips" -msgstr "Dicas" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "A transferência falhou." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "Dispositivo USB não encontrado" - -msgid "USB Loader GX is protected" -msgstr "O USB Loader GX está bloqueado" - -msgid "Uninstall" -msgstr "Desinstalar" - -msgid "Uninstall Game" -msgstr "Desinstalar jogo" - -msgid "Uninstall Menu" -msgstr "Menu de Desinstalação" - -msgid "Uninstalling wad" -msgstr "Desinstalando wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Desbloquear configuração antes de usar esta opção." - -msgid "Unsupported format, try to extract manually." -msgstr "Formato não suportado, tente extrair manualmente." - -msgid "Update" -msgstr "Verificar Actualizações" - -msgid "Update All" -msgstr "Actualizar Tudo" - -msgid "Update DOL" -msgstr "Actualizar DOL" - -msgid "Update Files" -msgstr "Actualizar ficheiros" - -msgid "Update Path" -msgstr "Pasta Actualizações" - -msgid "Update all Language Files" -msgstr "Actualizar todos os ficheiros de Idioma" - -msgid "Update failed" -msgstr "Erro ao actualizar" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Actualizando ficheiros de Idioma:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Ficheiro ZIP instalado na pasta do Homebrew." - -msgid "VIDTV Patch" -msgstr "Patch VIDTV" - -#, c-format -msgid "Version: %s" -msgstr "Versão: %s" - -msgid "Video Mode" -msgstr "Modo de Vídeo" - -msgid "WIP Patches Path" -msgstr "Pasta Patches WIP" - -msgid "Waiting for USB Device" -msgstr "Aguardando pelo Dispositivo USB" - -msgid "Waiting..." -msgstr "Aguardando..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Que componente deseja actualizar?" - -msgid "WiFi Features" -msgstr "Rede sem fios" - -msgid "Wii Menu" -msgstr "Menu da Wii" - -msgid "Wii Settings" -msgstr "Configuração da Wii" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "Pasta WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Iluminação Leitor" - -msgid "Wrong Password" -msgstr "Password Incorrecta" - -msgid "Yes" -msgstr "Sim" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Necessita seleccionar ou formatar uma partição" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "O URL foi guardado em %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "e aos tradutores pela actualização dos idiomas" - -msgid "available" -msgstr "disponível" - -msgid "does not exist!" -msgstr "não existe!" - -msgid "does not exist! Loading game without cheats." -msgstr "não existe! Carregando jogo sem truques." - -msgid "files left" -msgstr "ficheiros restantes" - -msgid "files not found on the server!" -msgstr "ficheiros não encontrados no servidor!" - -msgid "for FAT/NTFS support" -msgstr "pelo suporte FAT/NTFS" - -msgid "for Ocarina" -msgstr "pelo Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "por WiiTDB e alojar img. capas / discos" - -msgid "for diverse patches" -msgstr "por diversos patches" - -msgid "for his awesome tool LibWiiGui" -msgstr "pela sua espectacular ferramenta LibWiiGui" - -msgid "for hosting the themes" -msgstr "por alojar os temas" - -msgid "for hosting the update files" -msgstr "por alojar actualizações" - -msgid "for the USB Loader source" -msgstr "pelo código do USB Loader" - -msgid "formatted!" -msgstr "formatado!" - -msgid "free" -msgstr "livres" - -msgid "not set" -msgstr "não definido" - -msgid "of" -msgstr "de" - -msgid "seconds left" -msgstr "segundos restantes" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Instalar Cópia 1:1" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Todos)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Crianças 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 hora" - -#~ msgid "10 min" -#~ msgstr "10 minutos" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Adolescente 12+)" - -#~ msgid "20 min" -#~ msgstr "20 minutos" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Adulto 16+)" - -#~ msgid "3 min" -#~ msgstr "3 minutos" - -#~ msgid "30 min" -#~ msgstr "30 minutos" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Adultos 18+)" - -#~ msgid "5 min" -#~ msgstr "5 minutos" - -#~ msgid "An Error occured" -#~ msgstr "Ocurreu um Erro" - -#~ msgid "Anti" -#~ msgstr "Anti" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Tem a certeza que pretende activar o Controlo Parental?" - -#~ msgid "AutoPatch" -#~ msgstr "Patch automático" - -#~ msgid "Both" -#~ msgstr "Ambos" - -#~ msgid "Checking for Updates" -#~ msgstr "Procurando Actualizações" - -#~ msgid "Console Default" -#~ msgstr "Predefinição Consola" - -#~ msgid "Customs/Original" -#~ msgstr "Alternativas/Originais" - -#~ msgid "Disc Default" -#~ msgstr "Predefinição Disco" - -#~ msgid "DiskFlip" -#~ msgstr "Voltar Disco" - -#~ msgid "Downloading" -#~ msgstr "Descarregando" - -#~ msgid "Dutch" -#~ msgstr "Holandês" - -#~ msgid "English" -#~ msgstr "Inglês" - -#~ msgid "French" -#~ msgstr "Francês" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "IDJOGO_NomeJogo" - -#~ msgid "Game ID" -#~ msgstr "ID do Jogo" - -#~ msgid "Game Region" -#~ msgstr "Região" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "NomeJogo [IDJOGO]" - -#~ msgid "German" -#~ msgstr "Alemão" - -#~ msgid "Invalid PIN code" -#~ msgstr "PIN inválido" - -#~ msgid "Italian" -#~ msgstr "Italiano" - -#~ msgid "Japanese" -#~ msgstr "Japonês" - -#~ msgid "Korean" -#~ msgstr "Coreano" - -#~ msgid "Left" -#~ msgstr "Esquerda" - -#~ msgid "Like SysMenu" -#~ msgstr "Igual ao Menu da Wii" - -#~ msgid "Load From SD/USB" -#~ msgstr "Carregar do SD/USB" - -#~ msgid "Locked" -#~ msgstr "Bloqueado" - -#~ msgid "Loop Directory" -#~ msgstr "Repetir Pasta" - -#~ msgid "Loop Music" -#~ msgstr "Repetir Música" - -#~ msgid "Loop Sound" -#~ msgstr "Repetir Sons" - -#~ msgid "Neither" -#~ msgstr "Nenhum" - -#~ msgid "Next" -#~ msgstr "Próximo" - -#~ msgid "None" -#~ msgstr "Nenhum" - -#~ msgid "Normal" -#~ msgstr "Normal" - -#~ msgid "ON" -#~ msgstr "Ligado" - -#~ msgid "Only Customs" -#~ msgstr "Apenas Alternativas" - -#~ msgid "Only Original" -#~ msgstr "Apenas Originais" - -#~ msgid "Only for Install" -#~ msgstr "Apenas na instalação" - -#~ msgid "Original/Customs" -#~ msgstr "Originais/Alternativas" - -#~ msgid "Parental Control disabled" -#~ msgstr "Controlo Parental inactivo" - -#~ msgid "Play Once" -#~ msgstr "Tocar uma vez" - -#~ msgid "Prev" -#~ msgstr "Anterior" - -#~ msgid "Random Directory Music" -#~ msgstr "Pasta de Música Aleatória" - -#~ msgid "Right" -#~ msgstr "Direita" - -#~ msgid "SChinese" -#~ msgstr "Chinês Simplificado" - -#~ msgid "Sound+BGM" -#~ msgstr "Efeitos+Musica" - -#~ msgid "Sound+Quiet" -#~ msgstr "Efeitos+Silêncio" - -#~ msgid "Spanish" -#~ msgstr "Espanhol" - -#~ msgid "System Default" -#~ msgstr "Predefinição Sistema" - -#~ msgid "TChinese" -#~ msgstr "Chinês Tradicional" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "O ficheiro wad foi instalado mas não foi possível eliminá-lo do cartão SD." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "A instalação do wad falhou com o seguinte erro: %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Não é possível abrir o ficheiro wad descarregado (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Desbloquear Controlo Parental" - -#~ msgid "Unlocked" -#~ msgstr "Desbloqueado" - -#~ msgid "Update to" -#~ msgstr "Actualizando para" - -#~ msgid "Updating" -#~ msgstr "Actualizando" - -#~ msgid "Updating Language Files..." -#~ msgstr "Actualizando ficheiros de Idioma..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Actualizando WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Correcção 16:9" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "O Controlo Parental não está activo. Se deseja utilizar o Controlo Parental active-o na configuração da Wii (Wii Settings)." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Pode não carregar correctamente se o System Menu estiver desactualizado." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Pasta de Códigos BCA alterada" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Menu da Wii" - -#~ msgid "Channels" -#~ msgstr "Canais" - -#~ msgid "Checking existing artwork" -#~ msgstr "Verificando imagens existentes" - -#~ msgid "Confirm" -#~ msgstr "Confirmar" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Não foi encontrada nenhuma partição WBFS." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Não foi possível abrir a partição WBFS" - -#~ msgid "Could not read the disc." -#~ msgstr "Não foi possível ler o disco." - -#~ msgid "Could not set USB." -#~ msgstr "Não foi possível configurar a porta USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "Pasta das Capas alterada" - -#~ msgid "DOL path changed" -#~ msgstr "Pasta DOL alterada" - -#~ msgid "Disc Path Changed" -#~ msgstr "Pasta das Imagens Disco Alterada" - -#~ msgid "Display favorites" -#~ msgstr "Mostrar favoritos" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Deseja tentar novamente dentro de 30 segs?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Activar Controlo Parental" - -#~ msgid "Force" -#~ msgstr "Forçar" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Pasta ficheiros GCT alterada" - -#~ msgid "Hermes CIOS" -#~ msgstr "CIOS Hermes" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Pasta Apps Homebrew alterada" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Insira um cartão SD para descarregar as imagens." - -#~ msgid "Install not possible" -#~ msgstr "Não é possível instalar" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "O mais provável é que o tamanho não seja divisível por 4." - -#~ msgid "Network init error" -#~ msgstr "Erro ao inicializar ligação de rede" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "No não foram encontrados nenhuns ficheiros .dol ou .elf" - -#~ msgid "No Favorites" -#~ msgstr "Lista de favoritos vazia" - -#~ msgid "No USB Device" -#~ msgstr "Nenhum dispositivo USB encontrado" - -#~ msgid "No USB Device found." -#~ msgstr "Nenhum dispositivo USB encontrado." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Nenhuma partição WBFS ou FAT/NTFS encontrada" - -#~ msgid "Normal Covers" -#~ msgstr "Capas Normais" - -#~ msgid "Not Found" -#~ msgstr "Não encontrado" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Não é um ficheiro DOL/ELF válido." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Repor Musica de Fundo predefinida?" - -#~ msgid "Save Failed" -#~ msgstr "Falha ao Gravar" - -#~ msgid "Selected DOL" -#~ msgstr "DOL Seleccionado" - -#~ msgid "Standard" -#~ msgstr "Standard" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Pasta de Dicas alterada" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Pasta para Download de Temas Alterada" - -#~ msgid "Theme Path Changed" -#~ msgstr "Pasta dos Temas alterada" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "O USB Loader GX só suporta o CIOS Hermes revisão 4! Verifique se esta é a revisão que tem instalada!" - -#~ msgid "Update Path changed." -#~ msgstr "A pasta das actualizações foi alterada." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Pasta dos Patches WIP alterada" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Pasta WiiTDB alterada." - -#~ msgid "You are about to delete " -#~ msgstr "Vais eliminar " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Está a tentar visualizar os favoritos mas não existe nenhum seleccionado." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Está a utilizar um sistema de ficheiros NTFS. Devido à possibilidade de ocorrerem erros na gravação não será possível instalar jogos." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Tentou carregar uma imagem corrompida" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "não existe! Estragaste algo, idiota." - -#~ msgid "file left" -#~ msgstr "ficheiro restante" diff --git a/Languages/russian.lang b/Languages/russian.lang deleted file mode 100644 index b60178bb..00000000 --- a/Languages/russian.lang +++ /dev/null @@ -1,1537 +0,0 @@ -# USB Loader GX language source file. -# russian.lang - r885 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: nikolai_ca\n" -"Language-Team: Kir, alendit, nikolai_ca\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Wad сохранен как:" - -msgid " could not be downloaded." -msgstr " не мог быть загружен" - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " был сохранен. Текст не был проверен. Некоторые части кода могут не работать успешно друг с другом. При обнаружении проблемы, загрузить текст в текстовый редактор чтобы получить дополнительную информацию." - -msgid " is not on the server." -msgstr " не найден на сервере" - -msgid "2D Cover Path" -msgstr "Путь к 2D обложкам" - -msgid "3D Cover Path" -msgstr "Путь к 3D обложкам" - -msgid "3D Covers" -msgstr "3D Обложки" - -msgid ">> Deleting tickets..." -msgstr ">> Удаление тикетов...." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Удаление тикетов...ОШИБКА! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Удаление тикетов...Успешно! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Удаление тайтла ...ОШИБКА! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Удаление тайтла ...Успешно!" - -msgid ">> Deleting title contents..." -msgstr ">> Удаление содержимого тайтла..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Удаление содержимого тайтла...ОШИБКА!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Удаление содержимого тайтла...Успешно!" - -msgid ">> Deleting title..." -msgstr ">> Удаление тайтла..." - -msgid ">> Finishing installation..." -msgstr ">> Заканчиваю установку..." - -msgid ">> Installing content #" -msgstr ">>Установка контента №" - -msgid ">> Installing ticket..." -msgstr ">>Установка тикета..." - -msgid ">> Installing title..." -msgstr ">>Установка тайтла" - -msgid ">> Reading WAD data..." -msgstr ">> Чтение данных WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Чтение данных WAD...ОШИБКА!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Чтение данных WAD...Успешно!" - -msgid "AUTO" -msgstr "АВТО" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Все разделы" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Все функции USB Loader GX разблокированы." - -msgid "Alternate DOL" -msgstr "Альтернативный DOL" - -msgid "App Language" -msgstr "Язык приложения" - -msgid "Apr" -msgstr "Апр" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Вы уверены ?" - -msgid "Aug" -msgstr "Авг" - -msgid "Author:" -msgstr "Автор:" - -msgid "AutoInit Network" -msgstr "АвтоИнициализация Сети" - -msgid "BCA Codes Path" -msgstr "Путь к кодам BCA" - -msgid "BETA revisions" -msgstr "BETA-версии" - -msgid "Back" -msgstr "Назад" - -msgid "Back to HBC or Wii Menu" -msgstr "Вернуться в HBC или меню Wii" - -msgid "Back to Loader" -msgstr "Вернуться в загрузчик" - -msgid "Backgroundmusic" -msgstr "Фоновая музыка" - -msgid "Big thanks to:" -msgstr "Большое спасибо:" - -msgid "Block IOS Reload" -msgstr "Блокировать перезагрузку IOS" - -msgid "Boot/Standard" -msgstr "Загрузка/Стандарт" - -msgid "Boot?" -msgstr "Загрузить?" - -msgid "Can't be formatted" -msgstr "Невозможно отформатировать" - -msgid "Can't create directory" -msgstr "Не могу создать папку" - -msgid "Can't create file" -msgstr "Не могу создать файл" - -msgid "Can't delete:" -msgstr "Невозможно удалить:" - -msgid "Cancel" -msgstr "Отмена" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "Файл с читами пустой" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Нажми, чтобы скачать обложки" - -msgid "Click to change game ID" -msgstr "Нажмите чтобы изменить ID игры" - -msgid "Clock" -msgstr "Часы" - -msgid "Close" -msgstr "Закрыть" - -msgid "Code Download" -msgstr "Скачивание кода" - -#, c-format -msgid "Coded by: %s" -msgstr "Создано: %s" - -msgid "Coding:" -msgstr "Создание:" - -msgid "Connection lost..." -msgstr "Связь потеряна..." - -msgid "Console" -msgstr "Консоль" - -msgid "Console Locked" -msgstr "Консоль заблокирована" - -msgid "Console should be unlocked to modify it." -msgstr "Для изменения консоль должна быть разблокирована." - -msgid "Continue to install game?" -msgstr "Продолжить установку игры ?" - -msgid "Controllevel" -msgstr "Уровень контроля" - -msgid "Correct Password" -msgstr "Правильный пароль" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Не могу создать GCT файл" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Не могу запустить модуль DIP!" - -msgid "Could not initialize network!" -msgstr "Не могу инициализировать сеть!" - -msgid "Could not open Disc" -msgstr "Не могу прочесть диск" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Не могу сохранить." - -msgid "Cover Download" -msgstr "Скачать обложку" - -msgid "Create" -msgstr "Создать" - -msgid "Credits" -msgstr "Об авторах" - -msgid "Custom Paths" -msgstr "Изменение путей" - -msgid "DOL Path" -msgstr "Путь к DOL" - -msgid "Dec" -msgstr "Дек" - -msgid "Default" -msgstr "По умолчанию" - -msgid "Default Gamesettings" -msgstr "Установки игры по умолчанию" - -msgid "Default Settings" -msgstr "Установки по умолчанию" - -msgid "Delete" -msgstr "Удалить" - -msgid "Delete ?" -msgstr "Удалить ?" - -msgid "Delete Cheat GCT" -msgstr "Удалить чит-код GCT" - -msgid "Delete Cheat TXT" -msgstr "Удалить чит-код TXT" - -msgid "Delete Cover Artwork" -msgstr "Удалить обложку" - -msgid "Delete Disc Artwork" -msgstr "Удалить картинку диска" - -msgid "Design:" -msgstr "Дизайн:" - -msgid "Developed by" -msgstr "Создано " - -msgid "Directory does not exist!" -msgstr "Каталог не существует!" - -msgid "Disc Artwork Download" -msgstr "Загрузка изображений диска" - -msgid "Disc Artwork Path" -msgstr "Путь к изображениям дисков" - -msgid "Disc Images" -msgstr "Изображения дисков" - -msgid "Display" -msgstr "Отображать" - -msgid "Display as a carousel" -msgstr "Покаказть в виде карусели" - -msgid "Display as a grid" -msgstr "Показать в виде сетки" - -msgid "Display as a list" -msgstr "Показать в виде списка" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Вы хотите удалить:" - -msgid "Do you want to apply it now?" -msgstr "Вы действительно хотите использовать это?" - -msgid "Do you want to change language?" -msgstr "Вы хотите сменить язык ?" - -msgid "Do you want to download this theme?" -msgstr "Вы действительно хотите загрузить эту тему?" - -msgid "Do you want to format:" -msgstr "Вы хотите отформатировать:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Вы хотите использовать DOL, который считается правильным?" - -msgid "Do you wish to update/download all language files?" -msgstr "Вы действительно хотите обновить/загрузить все языковые файлы?" - -msgid "Done!" -msgstr "Готово!" - -msgid "Download" -msgstr "Загрузка" - -msgid "Download Boxart image?" -msgstr "Скачать обложку диска?" - -msgid "Download Discart image?" -msgstr "Скачать изображение диска ?" - -msgid "Download Now" -msgstr "Скачать сейчас" - -msgid "Download failed." -msgstr "Загрузка завершилась с ошибкой." - -msgid "Download finished" -msgstr "Скачивание завершено" - -msgid "Download request failed." -msgstr "Запрос на загрузку завершился с ошибкоа." - -msgid "Downloading Page List:" -msgstr "Загружается список страниц:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Скачиваю файл:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Загружается картинка:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "ОШИБКА" - -msgid "ERROR:" -msgstr "ОШИБКА:" - -msgid "ERROR: Can't set up theme." -msgstr "ОШИБКА: Не удалось установить тему." - -msgid "Error" -msgstr "Ошибка" - -msgid "Error !" -msgstr "Ошибка !" - -msgid "Error 002 fix" -msgstr "Фикс ошибки 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Ошибка чтения диска" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Ошибка при передаче данных." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Ошибка..." - -msgid "Error:" -msgstr "Ошибка:" - -msgid "Extracting files..." -msgstr "Распаковка файлов..." - -msgid "FAT: Use directories" -msgstr "FAT: Использовать каталоги" - -msgid "Failed formating" -msgstr "Форматирование не удалось" - -msgid "Failed to extract." -msgstr "Не удалось распаковать." - -msgid "Failed to open partition" -msgstr "Не удалось открыть раздел" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Фев" - -msgid "File not found." -msgstr "Файл не найден" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Завершение установки... ОК!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Flip-X" - -msgid "Format" -msgstr "Форматировать" - -msgid "Formatting, please wait..." -msgstr "Форматирую, пожалуйста подождите..." - -msgid "Free Space" -msgstr "Свободное пространство" - -msgid "Full Shutdown" -msgstr "Полное отключение" - -msgid "GCT Cheatcodes Path" -msgstr "Путь к читам" - -msgid "GCT File created" -msgstr "Файл GCT создан" - -msgid "GUI Settings" -msgstr "Настройки интерфейса" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg не найден ни в одном каталоге." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Язык" - -msgid "Game Load" -msgstr "загрузка игры" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Размер игры" - -msgid "Game Sound Mode" -msgstr "Режим звука в игре" - -msgid "Game Sound Volume" -msgstr "Громкость звука в игре" - -msgid "Game is already installed:" -msgstr "Игра уже установлена:" - -msgid "Game partition" -msgstr "Раздел игры" - -msgid "Games" -msgstr "Игры" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Домашнее Меню" - -msgid "Homebrew Apps Path" -msgstr "Путь к хоумбрю-программам" - -msgid "Homebrew Launcher" -msgstr "Загрузчик хоумбрю" - -msgid "Hour" -msgstr "Час" - -msgid "How do you want to update?" -msgstr "Что вы хотите обновить ?" - -msgid "How to Shutdown?" -msgstr "Способ отключения?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Если у вас нет сети WiFi, нажмите 1 чтобы получить URL для доступа к вашему WiiTDB.ZIP" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Входящий файл размером в %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Входящий файл размером в %0.2fMB" - -msgid "Initializing Network" -msgstr "Инициализирую сеть" - -msgid "Insert Disk" -msgstr "Вставьте диск" - -msgid "Insert a Wii Disc!" -msgstr "Вставьте диск Wii!" - -msgid "Insert an SD-Card to save." -msgstr "Для сохранения вставьте SD карту." - -msgid "Insert an SD-Card to use this option." -msgstr "Для использования этой функции нужна SD карта" - -msgid "Install" -msgstr "Установка" - -msgid "Install Error!" -msgstr "Ошибка установки!" - -msgid "Install a game" -msgstr "Установить игру" - -msgid "Install partitions" -msgstr "Установить разделы" - -msgid "Installing content... Ok!" -msgstr "Установка контента... ОК!" - -msgid "Installing game:" -msgstr "Устанавливаю игру:" - -msgid "Installing ticket... Ok!" -msgstr "Установка тикета... ОК!" - -msgid "Installing title... Ok!" -msgstr "Установка тайтла... ОК!" - -msgid "Installing wad" -msgstr "Установка WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Возможно что у Вас есть информация полезная нам. Пожалуйста передайте эту информацию команде разработчиков." - -msgid "Jan" -msgstr "Янв" - -msgid "July" -msgstr "Июл" - -msgid "June" -msgstr "Июн" - -msgid "Keep" -msgstr "Сохранить" - -msgid "Keyboard" -msgstr "Клавиатура" - -msgid "Language File" -msgstr "Языковой файл" - -msgid "Language change:" -msgstr "Смена языка:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Путь к языкам изменен" - -msgid "Load" -msgstr "Загрузить" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Загрузить файл из %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Загрузить этот DOL в качестве альтернативного ?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Загрузка языка по умолчанию" - -msgid "Loading standard music." -msgstr "Загрузка стандартной музыки" - -msgid "Lock Console" -msgstr "Заблокировать консоль" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "Мар" - -msgid "Mark new games" -msgstr "Отметить новые игры" - -msgid "May" -msgstr "Май" - -msgid "Missing files" -msgstr "Отсутствующие файлы" - -msgid "Mount DVD drive" -msgstr "Монтировать DVD" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Громкость" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Обнаружен новый диск" - -msgid "No" -msgstr "Нет" - -msgid "No Cheatfile found" -msgstr "Не найден файл с читами" - -msgid "No DOL file found on disc." -msgstr "DOL-файл не найден на диске." - -msgid "No SD-Card inserted!" -msgstr "SD карта не вставлена!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Не было выбрано ни одного чит-кода" - -msgid "No data could be read." -msgstr "Невозможно считать данные." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Файл не найден!" - -msgid "No new updates." -msgstr "Нет обновлений" - -msgid "No themes found on the site." -msgstr "На сайте не найдено ни одной темы" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Это не диск Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Недостаточно памяти" - -msgid "Not enough free space!" -msgstr "Не хватает свободного места!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Формат не поддерживается" - -msgid "Nov" -msgstr "Ноя" - -msgid "OFF" -msgstr "ВЫКЛ" - -msgid "OK" -msgstr "OK" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Окт" - -msgid "Official Site:" -msgstr "Оф. сайт:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Родительский Контроль" - -msgid "Partition" -msgstr "Раздел" - -msgid "Password" -msgstr "Пароль" - -msgid "Password Changed" -msgstr "Пароль изменен" - -msgid "Password has been changed" -msgstr "Пароль был изменен" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Скопируйте это в Ваш браузер чтобы получить Ваш WiiTDB.zip" - -msgid "Patch Country Strings" -msgstr "Патчить строки страны" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Выберите из списка" - -msgid "Play Count" -msgstr "Запущено раз" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "Пожалуйста подождите..." - -msgid "Power off the Wii" -msgstr "Выключить Wii" - -msgid "Prompts Buttons" -msgstr "Кнопки приглашения" - -msgid "Published by" -msgstr "Опубликовано: " - -msgid "Quick Boot" -msgstr "Быстрая загрузка" - -msgid "Reading WAD data... Ok!" -msgstr "Чтение данных WAD... ОК!" - -msgid "Receiving file from:" -msgstr "Получение файлы из:" - -msgid "Released" -msgstr "Выпущено:" - -msgid "Reload SD" -msgstr "Перечитать SD карту" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "Переименовать игры в WBFS" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Сбросить счетчик запусков" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Перезапускаю..." - -msgid "Return" -msgstr "Вернуться" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Вернуться в меню Wii" - -msgid "Rumble" -msgstr "Вибрация" - -msgid "SFX Volume" -msgstr "Громкость эффектов" - -msgid "Save" -msgstr "Сохранить" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Сохранить список игр в" - -msgid "Saved" -msgstr "Сохранено" - -msgid "Screensaver" -msgstr "Скринсейвер" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Выберите DOL" - -msgid "Sept" -msgstr "Сен" - -msgid "Set Search-Filter" -msgstr "Установить фильтр для поиска" - -msgid "Settings" -msgstr "Установки" - -msgid "Shutdown System" -msgstr "Выключить систему" - -msgid "Shutdown to Idle" -msgstr "Перевести в режим сна" - -msgid "Sort alphabetically" -msgstr "Сортировать по алфавиту" - -msgid "Sort by rank" -msgstr "Сортировать по популярности" - -msgid "Sort order by most played" -msgstr "Сортировать по частоте проигрывания" - -msgid "Sound" -msgstr "Звук" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Отдельные благодарности" - -msgid "Success" -msgstr "Успех" - -msgid "Success:" -msgstr "Успех:" - -msgid "Successfully Saved" -msgstr "Успешно сохранено" - -msgid "Successfully Updated" -msgstr "Успешно обновлено" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Успешно удалено:" - -msgid "Successfully extracted theme." -msgstr "Успешно извлечена тема." - -msgid "Successfully installed:" -msgstr "Успешно установлено:" - -msgid "TXT Cheatcodes Path" -msgstr "Путь к TXT читкодам" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Заданный каталог не существует. Хотите создать его?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Путь для загрузки темы" - -msgid "Theme Downloader" -msgstr "Загрузчик тем" - -msgid "Theme Path" -msgstr "Путь к темам" - -msgid "Theme Title:" -msgstr "Заголовок темы:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Осталось времени:" - -msgid "Title Launcher" -msgstr "Загрузчик тайтла" - -msgid "Titles from WiiTDB" -msgstr "Названия из WiiTDB" - -msgid "Tooltips" -msgstr "Подсказки" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Передача не удалась." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB устройство не найдено" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX заблокирован" - -msgid "Uninstall" -msgstr "Деинсталлировать" - -msgid "Uninstall Game" -msgstr "Деинсталлировать игру" - -msgid "Uninstall Menu" -msgstr "Деинсталлировать меню" - -msgid "Uninstalling wad" -msgstr "Деинсталлируется wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Для изменения параметра разблокируйте консоль." - -msgid "Unsupported format, try to extract manually." -msgstr "Формат не поддерживается, попробуйте распаковать самостоятельно." - -msgid "Update" -msgstr "Обновление" - -msgid "Update All" -msgstr "Обновить всё" - -msgid "Update DOL" -msgstr "Обновить DOL" - -msgid "Update Files" -msgstr "Обновить файлы" - -msgid "Update Path" -msgstr "Путь к обновлениям" - -msgid "Update all Language Files" -msgstr "Обновить все языковые файлы" - -msgid "Update failed" -msgstr "Обновление не удалось" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Обновление языковых файлов:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Загруженный ZIP-файл установлен в каталог homebrew" - -msgid "VIDTV Patch" -msgstr "Патч VIDTV" - -#, c-format -msgid "Version: %s" -msgstr "Версия: %s" - -msgid "Video Mode" -msgstr "Видео режим" - -msgid "WIP Patches Path" -msgstr "Путь к патчам QIP" - -msgid "Waiting for USB Device" -msgstr "Ожидание USB устройства" - -msgid "Waiting..." -msgstr "Ожидание..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Что Вы хотите обновить?" - -msgid "WiFi Features" -msgstr "свойства WiFi" - -msgid "Wii Menu" -msgstr "Меню Wii" - -msgid "Wii Settings" -msgstr "Установки Wii" - -msgid "WiiTDB Files" -msgstr "Файлы WiiTDB" - -msgid "WiiTDB Path" -msgstr "Путь к WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Подсветка Wii" - -msgid "Wrong Password" -msgstr "Неверный пароль" - -msgid "Yes" -msgstr "Да" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Ваш URL был сохранен в %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "и переводчики для обновлений языковых файлов" - -msgid "available" -msgstr "доступно" - -msgid "does not exist!" -msgstr "не существует!" - -msgid "does not exist! Loading game without cheats." -msgstr "не существует! Загружаю игру без читов" - -msgid "files left" -msgstr "файлов осталось" - -msgid "files not found on the server!" -msgstr "файлы не найдены на сервере!" - -msgid "for FAT/NTFS support" -msgstr "для поддержки FAT/NTFS" - -msgid "for Ocarina" -msgstr "за Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "за WIITDB и хостинг изображений обложек/дисков" - -msgid "for diverse patches" -msgstr "за различные патчи" - -msgid "for his awesome tool LibWiiGui" -msgstr "за отличную утилиту LibWiiGui" - -msgid "for hosting the themes" -msgstr "за хостинг тем" - -msgid "for hosting the update files" -msgstr "за хостинг обновлений" - -msgid "for the USB Loader source" -msgstr "за выпуск и публикацию исходного кода" - -msgid "formatted!" -msgstr "форматирование завершено!" - -msgid "free" -msgstr "свободно" - -msgid "not set" -msgstr "не установлено" - -msgid "of" -msgstr "из" - -msgid "seconds left" -msgstr "секунд осталось" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Установка копии 1:1" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Для всех)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Дети 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 час" - -#~ msgid "10 min" -#~ msgstr "10 мин." - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Подростки 12+)" - -#~ msgid "20 min" -#~ msgstr "20 мин." - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Подростки 16+)" - -#~ msgid "3 min" -#~ msgstr "3 мин." - -#~ msgid "30 min" -#~ msgstr "30 мин." - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Взрослые 18+)" - -#~ msgid "5 min" -#~ msgstr "5 мин." - -#~ msgid "An Error occured" -#~ msgstr "Произошла ошибка" - -#~ msgid "Anti" -#~ msgstr "Анти" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Вы действительно хотите включить Родительский Контроль?" - -#~ msgid "AutoPatch" -#~ msgstr "Авто Патч" - -#~ msgid "Both" -#~ msgstr "Оба" - -#~ msgid "Checking for Updates" -#~ msgstr "Проверяю обновления" - -#~ msgid "Console Default" -#~ msgstr "По умолчанию (консоль)" - -#~ msgid "Customs/Original" -#~ msgstr "Измененный/Оригинальные" - -#~ msgid "Disc Default" -#~ msgstr "По умолчанию (диск)" - -#~ msgid "DiskFlip" -#~ msgstr "ДискФлип" - -#~ msgid "Downloading" -#~ msgstr "Скачиваю" - -#~ msgid "Dutch" -#~ msgstr "Голландский" - -#~ msgid "English" -#~ msgstr "Английский" - -#~ msgid "French" -#~ msgstr "Французский" - -#~ msgid "Game ID" -#~ msgstr "ID игры" - -#~ msgid "Game Region" -#~ msgstr "Регион игры" - -#~ msgid "German" -#~ msgstr "Немецкий" - -#~ msgid "Invalid PIN code" -#~ msgstr "Неправильный PIN-код" - -#~ msgid "Italian" -#~ msgstr "Итальянский" - -#~ msgid "Japanese" -#~ msgstr "Японский" - -#~ msgid "Korean" -#~ msgstr "Корейский" - -#~ msgid "Left" -#~ msgstr "Налево" - -#~ msgid "Like SysMenu" -#~ msgstr "как SysMenu" - -#~ msgid "Load From SD/USB" -#~ msgstr "Загрузка с SD/USB" - -#~ msgid "Locked" -#~ msgstr "Заблокировано" - -#~ msgid "Loop Sound" -#~ msgstr "Зациклить звут" - -#~ msgid "Neither" -#~ msgstr "Ни то, ни другое" - -#~ msgid "Next" -#~ msgstr "Следующий" - -#~ msgid "Normal" -#~ msgstr "Обычный" - -#~ msgid "ON" -#~ msgstr "ВКЛ" - -#~ msgid "Only Customs" -#~ msgstr "Только измененные" - -#~ msgid "Only Original" -#~ msgstr "Только оригинальные" - -#~ msgid "Only for Install" -#~ msgstr "Только при установке" - -#~ msgid "Original/Customs" -#~ msgstr "Измененные/Модифицированные" - -#~ msgid "Parental Control disabled" -#~ msgstr "Родительский Контроль выключен" - -#~ msgid "Prev" -#~ msgstr "Предыдущий" - -#~ msgid "Right" -#~ msgstr "Направо" - -#~ msgid "SChinese" -#~ msgstr "Упрощенный китайский" - -#~ msgid "Sound+BGM" -#~ msgstr "Звук и фоновая музыка" - -#~ msgid "Sound+Quiet" -#~ msgstr "Звук и тишина" - -#~ msgid "Spanish" -#~ msgstr "Испанский" - -#~ msgid "System Default" -#~ msgstr "По умолчанию" - -#~ msgid "TChinese" -#~ msgstr "Традиционный китайский" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD файл установлен, но он не может быть удален с карты SD." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Установка WAD не удалась, код ошибки %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Не могу открыть скачанный WAD (%s)" - -#~ msgid "Unlock Parental Control" -#~ msgstr "Разблокировать Родительский Контроль" - -#~ msgid "Unlocked" -#~ msgstr "Разблокировано" - -#~ msgid "Update to" -#~ msgstr "Обновить до" - -#~ msgid "Updating" -#~ msgstr "обновляю" - -#~ msgid "Updating Language Files..." -#~ msgstr "Обновление языковых файлов..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Обновление WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Широкоформатный фикс" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "У Вас не включен Родительский Контроль. Если вы хотите использовать Родительский Контроль, включите его в установках Wii." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s может не загрузиться правильно если ваше Системное Меню не последней версии" - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Путь к кодам BCA изменен" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Вернуться в меню Wii" - -#~ msgid "Channels" -#~ msgstr "Каналы" - -#~ msgid "Checking existing artwork" -#~ msgstr "Проверка существующей графики" - -#~ msgid "Confirm" -#~ msgstr "Подтвердить" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Не удалось найти раздел WBFS" - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Не могу открыть раздел WBFS" - -#~ msgid "Could not read the disc." -#~ msgstr "Не могу прочесть диск" - -#~ msgid "Could not set USB." -#~ msgstr "Не могу настроить USB" - -#~ msgid "Cover Path Changed" -#~ msgstr "Путь к обложкам был изменен." - -#~ msgid "DOL path changed" -#~ msgstr "Путь к DOL изменен" - -#~ msgid "Disc Path Changed" -#~ msgstr "Путь к изображениям дисков изменен" - -#~ msgid "Display favorites" -#~ msgstr "Показать закладки" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Хотите попробовать еще раз на 30 секунд?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Включить Родительский Контроль" - -#~ msgid "Force" -#~ msgstr "Принудительно" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Путь к читам изменен" - -#~ msgid "Hermes CIOS" -#~ msgstr "Hermes CIOS" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Путь к хоумбрю-программам изменен" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Для скачивания изображений вставьте SD карту." - -#~ msgid "Install not possible" -#~ msgstr "Установка невозможна" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Размеры картинки не делятся на 4. Поздравляю, блин." - -#~ msgid "Network init error" -#~ msgstr "Ошибка инициализации сети" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Не найдены файлы .dol или .elf" - -#~ msgid "No Favorites" -#~ msgstr "Нет избранных" - -#~ msgid "No USB Device" -#~ msgstr "Нет USB устройств" - -#~ msgid "No USB Device found." -#~ msgstr "USB устройств не обнаружено" - -#~ msgid "Normal Covers" -#~ msgstr "Обычные обложки" - -#~ msgid "Not Found" -#~ msgstr "Не найден" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Не является файлом DOL/ELF" - -#~ msgid "Save Failed" -#~ msgstr "Сохранение не удалось" - -#~ msgid "Selected DOL" -#~ msgstr "Выбранный DOL" - -#~ msgid "Standard" -#~ msgstr "Стандартный" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Путь к TXT читкодам изменен" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Путь для загрузки темы изменен" - -#~ msgid "Theme Path Changed" -#~ msgstr "путь к темам изменён" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX будет работать только с Hermes CIOS rev 4! Пожалуйста убедитесь что у вас установлена версия 4!" - -#~ msgid "Update Path changed." -#~ msgstr "Путь к обновлениям изменен" - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Путь к патчам QIP изменен" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Путь к WiiTDB изменен" - -#~ msgid "You are about to delete " -#~ msgstr "Вы хотите удалить " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Нельзя отобразить избранные, если вы их до этого не выбрали." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Вы используете файловую систему NTFS. Из-за возможных ошибок записи на раздел NTFS установка игры невозможна." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Вы попытались загрузить плохой образ" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "не существует! Ты облажался, идиот." - -#~ msgid "file left" -#~ msgstr "файл остался" diff --git a/Languages/schinese.lang b/Languages/schinese.lang deleted file mode 100644 index b1a28711..00000000 --- a/Languages/schinese.lang +++ /dev/null @@ -1,1483 +0,0 @@ -# USB Loader GX language source file. -# schinese.lang - r799 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: knife.hu kavid\n" -"Language-Team: kavid\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "WAD 保存为:" - -msgid " could not be downloaded." -msgstr "不能下载." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "已经被保存.内容尚未验证.部分代码可能无法作用.如果你遇到问题,请用文字编辑器打开文本文件以获得更多的信息." - -msgid " is not on the server." -msgstr "不在服务器上" - -msgid "2D Cover Path" -msgstr "2D封面路径" - -msgid "3D Cover Path" -msgstr "3D封面路径" - -msgid "3D Covers" -msgstr "3D 封面" - -msgid ">> Deleting tickets..." -msgstr ">> 删除 tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> 删除 tickets... 错误!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> 删除 tickets... 成功!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> 删除 title... 错误!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> 删除 title... 成功!" - -msgid ">> Deleting title contents..." -msgstr ">> 删除 title 内容..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> 删除 title 内容... 错误!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> 删除 title 内容... 成功!" - -msgid ">> Deleting title..." -msgstr ">> 删除 title..." - -msgid ">> Finishing installation..." -msgstr ">> 完成安装..." - -msgid ">> Installing content #" -msgstr ">> 安装程序主体#" - -msgid ">> Installing ticket..." -msgstr ">> 安装 ticket..." - -msgid ">> Installing title..." -msgstr ">> 安装 title..." - -msgid ">> Reading WAD data..." -msgstr ">> 读取 WAD 数据..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> 读取 WAD 数据... 错误!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> 读取 WAD 数据... 成功!" - -msgid "AUTO" -msgstr "自动" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "USB Loader GX 功能已解锁." - -msgid "Alternate DOL" -msgstr "可选择Alt DOL文件" - -msgid "App Language" -msgstr "语言设定" - -msgid "Apr" -msgstr "四月" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "确定?" - -msgid "Aug" -msgstr "八月" - -msgid "Author:" -msgstr "" - -msgid "AutoInit Network" -msgstr "自动检测网络" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "返回" - -msgid "Back to HBC or Wii Menu" -msgstr "返回 HBC 或 Wii 系统菜单" - -msgid "Back to Loader" -msgstr "返回 Loader" - -msgid "Backgroundmusic" -msgstr "背景音乐" - -msgid "Big thanks to:" -msgstr "非常感谢:" - -msgid "Block IOS Reload" -msgstr "阻止 IOS 重新载入" - -msgid "Boot/Standard" -msgstr "启动/标准" - -msgid "Boot?" -msgstr "启动?" - -msgid "Can't be formatted" -msgstr "无法格式化" - -msgid "Can't create directory" -msgstr "无法建立目录" - -msgid "Can't create file" -msgstr "" - -msgid "Can't delete:" -msgstr "无法删除:" - -msgid "Cancel" -msgstr "取消" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "作弊码文件是空的" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "点击下载封面" - -msgid "Click to change game ID" -msgstr "点击变更游戏 ID" - -msgid "Clock" -msgstr "时钟" - -msgid "Close" -msgstr "关闭" - -msgid "Code Download" -msgstr "作弊码下载" - -#, c-format -msgid "Coded by: %s" -msgstr "编程: %s" - -msgid "Coding:" -msgstr "编程:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "控制台" - -msgid "Console Locked" -msgstr "主机锁定" - -msgid "Console should be unlocked to modify it." -msgstr "需解锁以开启设定功能." - -msgid "Continue to install game?" -msgstr "继续安装游戏?" - -msgid "Controllevel" -msgstr "访问级别控制" - -msgid "Correct Password" -msgstr "密码正确" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "无法建立 GCT 文件" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "无法启动 DIP 模块!" - -msgid "Could not initialize network!" -msgstr "无法启动网络!" - -msgid "Could not open Disc" -msgstr "无法开启光盘" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "无法保存" - -msgid "Cover Download" -msgstr "下载封面" - -msgid "Create" -msgstr "创建" - -msgid "Credits" -msgstr "作者信息" - -msgid "Custom Paths" -msgstr "自定义路径" - -msgid "DOL Path" -msgstr "DOL 路径" - -msgid "Dec" -msgstr "十二月" - -msgid "Default" -msgstr "缺省" - -msgid "Default Gamesettings" -msgstr "缺省游戏设定" - -msgid "Default Settings" -msgstr "缺省设置" - -msgid "Delete" -msgstr "删除" - -msgid "Delete ?" -msgstr "删除?" - -msgid "Delete Cheat GCT" -msgstr "删除GCT金手指文件" - -msgid "Delete Cheat TXT" -msgstr "删除TXT金手指文件" - -msgid "Delete Cover Artwork" -msgstr "删除封面" - -msgid "Delete Disc Artwork" -msgstr "删除光盘图片" - -msgid "Design:" -msgstr "设计:" - -msgid "Developed by" -msgstr "开发" - -msgid "Directory does not exist!" -msgstr "目录不存在" - -msgid "Disc Artwork Download" -msgstr "光盘图片下载" - -msgid "Disc Artwork Path" -msgstr "光盘图片路径" - -msgid "Disc Images" -msgstr "光盘图片" - -msgid "Display" -msgstr "显示" - -msgid "Display as a carousel" -msgstr "走马灯模式" - -msgid "Display as a grid" -msgstr "封面墙模式" - -msgid "Display as a list" -msgstr "列表模式" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "确定删除:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "要变更语言么?" - -msgid "Do you want to download this theme?" -msgstr "" - -msgid "Do you want to format:" -msgstr "是否格式化:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "使用这个已知是正确的 Alt DOL 文件?" - -msgid "Do you wish to update/download all language files?" -msgstr "升级/下载语言文件?" - -msgid "Done!" -msgstr "完成" - -msgid "Download" -msgstr "" - -msgid "Download Boxart image?" -msgstr "下载封面图片?" - -msgid "Download Discart image?" -msgstr "下载光盘图片?" - -msgid "Download Now" -msgstr "现在下载" - -msgid "Download failed." -msgstr "" - -msgid "Download finished" -msgstr "下载完成" - -msgid "Download request failed." -msgstr "" - -msgid "Downloading Page List:" -msgstr "" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "下载文件:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "错误" - -msgid "ERROR:" -msgstr "错误:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "错误" - -msgid "Error !" -msgstr "错误 !" - -msgid "Error 002 fix" -msgstr "002 错误修正" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "读取光盘错误" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "传送数据错误." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "错误..." - -msgid "Error:" -msgstr "错误:" - -msgid "Extracting files..." -msgstr "" - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "格式化失败" - -msgid "Failed to extract." -msgstr "" - -msgid "Failed to open partition" -msgstr "打开分区失败" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "二月" - -msgid "File not found." -msgstr "找不到文件" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "正在完成安装...完成!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "按键规则" - -msgid "Format" -msgstr "格式化" - -msgid "Formatting, please wait..." -msgstr "格式化中, 请稍候..." - -msgid "Free Space" -msgstr "剩余空间" - -msgid "Full Shutdown" -msgstr "完全关机" - -msgid "GCT Cheatcodes Path" -msgstr "作弊码路径" - -msgid "GCT File created" -msgstr "GCT 文件已建立" - -msgid "GUI Settings" -msgstr "界面设置" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "游戏语言" - -msgid "Game Load" -msgstr "游戏载入" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "游戏容量" - -msgid "Game Sound Mode" -msgstr "" - -msgid "Game Sound Volume" -msgstr "" - -msgid "Game is already installed:" -msgstr "已安装的游戏:" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "游戏" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "主菜单" - -msgid "Homebrew Apps Path" -msgstr "自制程序路径" - -msgid "Homebrew Launcher" -msgstr "Homebrew 管理器" - -msgid "Hour" -msgstr "小时" - -msgid "How do you want to update?" -msgstr "你要升级哪些文件?" - -msgid "How to Shutdown?" -msgstr "如何关机?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "如果你没有联网,请按 1 键以获取一个WiiTDB.zip的下载链接." - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "正在接收文件 %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "正在接收文件 %0.2fMB" - -msgid "Initializing Network" -msgstr "正在启动网络" - -msgid "Insert Disk" -msgstr "插入光盘" - -msgid "Insert a Wii Disc!" -msgstr "插入 Wii 光盘!" - -msgid "Insert an SD-Card to save." -msgstr "插入 SD卡以保存." - -msgid "Insert an SD-Card to use this option." -msgstr "插入 SD 卡使用此功能." - -msgid "Install" -msgstr "安装" - -msgid "Install Error!" -msgstr "安装错误!" - -msgid "Install a game" -msgstr "安装游戏" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "正在安装程序主体... 完成!" - -msgid "Installing game:" -msgstr "正在安装游戏:" - -msgid "Installing ticket... Ok!" -msgstr "安装 ticket... 完成!" - -msgid "Installing title... Ok!" -msgstr "安装 title... 完成!" - -msgid "Installing wad" -msgstr "安裝 WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "看來你有一些能帮到我们的信息.请将这些信息发送给开发团队.%s - %i" - -msgid "Jan" -msgstr "一月" - -msgid "July" -msgstr "七月" - -msgid "June" -msgstr "六月" - -msgid "Keep" -msgstr "保持" - -msgid "Keyboard" -msgstr "键盘" - -msgid "Language File" -msgstr "语言文件" - -msgid "Language change:" -msgstr "变更语言:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "语言文件路径已变更" - -msgid "Load" -msgstr "载入" - -#, c-format -msgid "Load file from: %s ?" -msgstr "从%s 载入文件?" - -msgid "Load this DOL as alternate DOL?" -msgstr "载入这个 DOL 作为 ALT DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "载入标准语言" - -msgid "Loading standard music." -msgstr "载入标准音乐." - -msgid "Lock Console" -msgstr "锁定控制台" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "三月" - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "五月" - -msgid "Missing files" -msgstr "缺少的文件" - -msgid "Mount DVD drive" -msgstr "挂载DVD光驱" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "音量" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "新光盘已检测" - -msgid "No" -msgstr "否" - -msgid "No Cheatfile found" -msgstr "作弊码文件没找到" - -msgid "No DOL file found on disc." -msgstr "光盘中未找到 DOL 文件." - -msgid "No SD-Card inserted!" -msgstr "未插入 SD 卡!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "没有选择作弊码" - -msgid "No data could be read." -msgstr "无法读取数据" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "没有文件缺少!" - -msgid "No new updates." -msgstr "没有可用更新" - -msgid "No themes found on the site." -msgstr "" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "不是 Wii 的光盘" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "剩余内存不足." - -msgid "Not enough free space!" -msgstr "剩余空间不足!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "不支持的格式!" - -msgid "Nov" -msgstr "十一月" - -msgid "OFF" -msgstr "关闭" - -msgid "OK" -msgstr "确定" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "十月" - -msgid "Official Site:" -msgstr "官方网址:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "家长控制" - -msgid "Partition" -msgstr "分区" - -msgid "Password" -msgstr "密码" - -msgid "Password Changed" -msgstr "密码已变更" - -msgid "Password has been changed" -msgstr "密码已被变更" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "粘贴这个链接到浏览器来下载 WiiTDB.zip 文件." - -msgid "Patch Country Strings" -msgstr "设定区码" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "从列表中选取" - -msgid "Play Count" -msgstr "游戏计数" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "请等待..." - -msgid "Power off the Wii" -msgstr "关闭 Wii 主机" - -msgid "Prompts Buttons" -msgstr "显示校正" - -msgid "Published by" -msgstr "发行" - -msgid "Quick Boot" -msgstr "快速启动" - -msgid "Reading WAD data... Ok!" -msgstr "读取 WAD 数据... 完成!" - -msgid "Receiving file from:" -msgstr "接收文件:" - -msgid "Released" -msgstr "放出" - -msgid "Reload SD" -msgstr "重新载入 SD 卡" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "改变 WBFS (硬盘)上的游戏名称" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "重置游戏计数" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "重启中..." - -msgid "Return" -msgstr "返回" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "返回 Wii 主菜单" - -msgid "Rumble" -msgstr "震动" - -msgid "SFX Volume" -msgstr "SFX 音量" - -msgid "Save" -msgstr "保存" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "保存游戏列表到" - -msgid "Saved" -msgstr "已保存" - -msgid "Screensaver" -msgstr "屏幕保护" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "选择一个 DOL" - -msgid "Sept" -msgstr "九月" - -msgid "Set Search-Filter" -msgstr "设置搜索过滤器" - -msgid "Settings" -msgstr "设置" - -msgid "Shutdown System" -msgstr "关闭系统" - -msgid "Shutdown to Idle" -msgstr "进入待机状态" - -msgid "Sort alphabetically" -msgstr "按字母排序" - -msgid "Sort by rank" -msgstr "横排列" - -msgid "Sort order by most played" -msgstr "按玩过次数排序" - -msgid "Sound" -msgstr "声音" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "特别感谢" - -msgid "Success" -msgstr "成功" - -msgid "Success:" -msgstr "成功:" - -msgid "Successfully Saved" -msgstr "保存成功" - -msgid "Successfully Updated" -msgstr "升级成功!" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "成功删除:" - -msgid "Successfully extracted theme." -msgstr "" - -msgid "Successfully installed:" -msgstr "成功安装:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT 作弊码文件路径" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "已进入的目录不存在。你想要创建一个目录吗?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "" - -msgid "Theme Downloader" -msgstr "" - -msgid "Theme Path" -msgstr "主题路径" - -msgid "Theme Title:" -msgstr "" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "剩余时间:" - -msgid "Title Launcher" -msgstr "系统频道" - -msgid "Titles from WiiTDB" -msgstr "从 WiiTDB 中获取游戏名" - -msgid "Tooltips" -msgstr "提示信息" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "找不到 USB 设备" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX 被锁定" - -msgid "Uninstall" -msgstr "删除" - -msgid "Uninstall Game" -msgstr "删除游戏" - -msgid "Uninstall Menu" -msgstr "删除菜单" - -msgid "Uninstalling wad" -msgstr "卸载 WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "请解锁后使用此功能" - -msgid "Unsupported format, try to extract manually." -msgstr "" - -msgid "Update" -msgstr "升级" - -msgid "Update All" -msgstr "全部升级" - -msgid "Update DOL" -msgstr "仅升级主程序" - -msgid "Update Files" -msgstr "升级文件" - -msgid "Update Path" -msgstr "升级文件存放路径" - -msgid "Update all Language Files" -msgstr "升级全部语言文件" - -msgid "Update failed" -msgstr "升级失败" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "正在升级语言文件:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "上传已安装Zip文件到自制程序目录" - -msgid "VIDTV Patch" -msgstr "VIDTV 修改" - -#, c-format -msgid "Version: %s" -msgstr "版本: %s" - -msgid "Video Mode" -msgstr "视频制式" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "等待 USB 设备" - -msgid "Waiting..." -msgstr "等待中..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "要升级么?" - -msgid "WiFi Features" -msgstr "WiFi 功能" - -msgid "Wii Menu" -msgstr "Wii 系统菜单" - -msgid "Wii Settings" -msgstr "Wii 设置" - -msgid "WiiTDB Files" -msgstr "WiiTDB 文件" - -msgid "WiiTDB Path" -msgstr "WiiTDB 文件路径" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "光驱灯" - -msgid "Wrong Password" -msgstr "密码错误" - -msgid "Yes" -msgstr "是" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "链接已写入 %sWiiTDB_URL.txt 文件." - -msgid "and translaters for language files updates" -msgstr "和所有语言包更新的翻译者" - -msgid "available" -msgstr "允许" - -msgid "does not exist!" -msgstr "不存在!" - -msgid "does not exist! Loading game without cheats." -msgstr "不存在!游戏以无作弊码方式载入." - -msgid "files left" -msgstr "剩余文件" - -msgid "files not found on the server!" -msgstr "服务器中无此文件!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "的 Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "的 WiiTDB 和封面下载" - -msgid "for diverse patches" -msgstr "的多种修正" - -msgid "for his awesome tool LibWiiGui" -msgstr "的优秀工具 LibWiiGui" - -msgid "for hosting the themes" -msgstr "" - -msgid "for hosting the update files" -msgstr "的升级服务器" - -msgid "for the USB Loader source" -msgstr "放出源代码" - -msgid "formatted!" -msgstr "完成格式化!" - -msgid "free" -msgstr "剩余" - -msgid "not set" -msgstr "未设定" - -msgid "of" -msgstr "的" - -msgid "seconds left" -msgstr "剩余秒数" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (全年龄)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (7岁以上)" - -#~ msgid "1 hour" -#~ msgstr "1 小时" - -#~ msgid "10 min" -#~ msgstr "10 分钟" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (12岁以上)" - -#~ msgid "20 min" -#~ msgstr "20 分钟" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (16岁以上)" - -#~ msgid "3 min" -#~ msgstr "3 分钟" - -#~ msgid "30 min" -#~ msgstr "30 分钟" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (18岁以上成人)" - -#~ msgid "5 min" -#~ msgstr "5 分钟" - -#~ msgid "An Error occured" -#~ msgstr "发生一个错误" - -#~ msgid "Anti" -#~ msgstr "防止" - -#~ msgid "AutoPatch" -#~ msgstr "自动修改" - -#~ msgid "Both" -#~ msgstr "全部" - -#~ msgid "Checking for Updates" -#~ msgstr "检测软件最新版本" - -#~ msgid "Console Default" -#~ msgstr "主机默认" - -#~ msgid "Customs/Original" -#~ msgstr "自定义/官方" - -#~ msgid "Disc Default" -#~ msgstr "游戏默认" - -#~ msgid "DiskFlip" -#~ msgstr "光盘滑动" - -#~ msgid "Downloading" -#~ msgstr "下载" - -#~ msgid "Dutch" -#~ msgstr "荷文" - -#~ msgid "English" -#~ msgstr "英文" - -#~ msgid "French" -#~ msgstr "法文" - -#~ msgid "Game ID" -#~ msgstr "游戏 ID" - -#~ msgid "Game Region" -#~ msgstr "游戏区域" - -#~ msgid "German" -#~ msgstr "德文" - -#~ msgid "Italian" -#~ msgstr "意大利文" - -#~ msgid "Japanese" -#~ msgstr "日文" - -#~ msgid "Korean" -#~ msgstr "韩文" - -#~ msgid "Left" -#~ msgstr "左" - -#~ msgid "Like SysMenu" -#~ msgstr "同系统选单" - -#~ msgid "Load From SD/USB" -#~ msgstr "从 SD/USB 载入" - -#~ msgid "Locked" -#~ msgstr "已锁定" - -#~ msgid "Neither" -#~ msgstr "全不" - -#~ msgid "Next" -#~ msgstr "往后" - -#~ msgid "Normal" -#~ msgstr "一般" - -#~ msgid "ON" -#~ msgstr "开启" - -#~ msgid "Only Customs" -#~ msgstr "仅自定义" - -#~ msgid "Only Original" -#~ msgstr "仅官方" - -#~ msgid "Only for Install" -#~ msgstr "仅安装" - -#~ msgid "Original/Customs" -#~ msgstr "官方/自定义" - -#~ msgid "Prev" -#~ msgstr "往前" - -#~ msgid "Right" -#~ msgstr "右" - -#~ msgid "SChinese" -#~ msgstr "简体中文" - -#~ msgid "Spanish" -#~ msgstr "西班牙文" - -#~ msgid "System Default" -#~ msgstr "系统默认" - -#~ msgid "TChinese" -#~ msgstr "繁体中文" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD 已安装,但文件无法从 SD 卡中删除." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "WAD 安装失败,错误号 %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "不能打开刚下载的 WAD 文件 (%s)." - -#~ msgid "Unlocked" -#~ msgstr "已解锁" - -#~ msgid "Update to" -#~ msgstr "升级到" - -#~ msgid "Updating" -#~ msgstr "升级中" - -#~ msgid "Updating Language Files..." -#~ msgstr "升级语言文件..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "正在升级 WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "宽屏校正" - -#~ msgid "Back to Wii Menu" -#~ msgstr "返回 Wii 系统菜单" - -#~ msgid "Channels" -#~ msgstr "频道" - -#~ msgid "Checking existing artwork" -#~ msgstr "检测已存在的插图" - -#~ msgid "Confirm" -#~ msgstr "确定" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "找不到 WBFS 分区." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "无法打开 WBFS 分区" - -#~ msgid "Could not read the disc." -#~ msgstr "无法读取光盘." - -#~ msgid "Could not set USB." -#~ msgstr "无法设置 USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "封面路径已变更" - -#~ msgid "DOL path changed" -#~ msgstr "DOL 路径已变更" - -#~ msgid "Disc Path Changed" -#~ msgstr "光盘图片路径已变更" - -#~ msgid "Display favorites" -#~ msgstr "收藏夹模式" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "是否等待 30 秒后重试?" - -#~ msgid "Force" -#~ msgstr "强制" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "作弊码路径已变更" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "自制程序路径已变更" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "插入 SD 卡以下载封面." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "图片格式错误,可能它的尺寸不是 4 的倍数." - -#~ msgid "Network init error" -#~ msgstr "网络启动错误" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "找不到 .dol 或 .elf 文件" - -#~ msgid "No Favorites" -#~ msgstr "没有收藏记录" - -#~ msgid "No USB Device" -#~ msgstr "没有 USB 设备" - -#~ msgid "No USB Device found." -#~ msgstr "找不到 USB 设备." - -#~ msgid "Normal Covers" -#~ msgstr "普通封面" - -#~ msgid "Not Found" -#~ msgstr "没找到" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "不是 DOL/ELF 文件." - -#~ msgid "Save Failed" -#~ msgstr "保存失败" - -#~ msgid "Selected DOL" -#~ msgstr "已选择 DOL" - -#~ msgid "Standard" -#~ msgstr "标准" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXT 作弊码文件路径已变更" - -#~ msgid "Theme Path Changed" -#~ msgstr "主题路径已变更" - -#~ msgid "Update Path changed." -#~ msgstr "升级文件存放路径已变更" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB 路径已变更" - -#~ msgid "You are about to delete " -#~ msgstr "要删除" - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "你选择显示收藏夹但里面还没有任何收藏" - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "你在加载损坏的镜像" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "不存在!" - -#~ msgid "file left" -#~ msgstr "剩余文件" diff --git a/Languages/spanish.lang b/Languages/spanish.lang deleted file mode 100644 index 4c6f3a6a..00000000 --- a/Languages/spanish.lang +++ /dev/null @@ -1,1558 +0,0 @@ -# USB Loader GX language source file. -# spanish.lang - r921 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: SirPalax\n" -"Language-Team: Penn, SirPalax\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " WAD guardado como:" - -msgid " could not be downloaded." -msgstr " no se han podido descargar." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " ha sido Guardado. Algún código puede no funcionar correctamente. Si experimentas problemas, revisa el texto en un editor de texto para obtener más información." - -msgid " is not on the server." -msgstr " no existe en el servidor." - -msgid "2D Cover Path" -msgstr "Ruta Carátulas 2D" - -msgid "3D Cover Path" -msgstr "Ruta Carátulas 3D" - -msgid "3D Covers" -msgstr "3D" - -msgid ">> Deleting tickets..." -msgstr ">> Borrando tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Borrando tickets... ¡ERROR! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Borrando tickets... ¡Correcto! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Borrando título... ¡ERROR! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Borrando título... ¡Correcto!" - -msgid ">> Deleting title contents..." -msgstr ">> Borrando contenidos del título..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Borrando contenidos del título... ¡ERROR! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Borrando contenidos del título... ¡Correcto!" - -msgid ">> Deleting title..." -msgstr ">> Borrando título..." - -msgid ">> Finishing installation..." -msgstr ">> Finalizando instalación..." - -msgid ">> Installing content #" -msgstr ">> Instalando contenido #" - -msgid ">> Installing ticket..." -msgstr ">> Instalando ticket..." - -msgid ">> Installing title..." -msgstr ">> Instalando título..." - -msgid ">> Reading WAD data..." -msgstr ">> Leyendo datos del WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Leyendo datos del WAD... ¡ERROR!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Leyendo datos del WAD... ¡Correcto!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Todas las particiones" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Todas las características del USB Loader GX desbloqueadas." - -msgid "Alternate DOL" -msgstr "DOL Alternativo" - -msgid "App Language" -msgstr "Idioma Aplicación" - -msgid "Apr" -msgstr "Abr" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "¿Estás seguro?" - -msgid "Aug" -msgstr "Ago" - -msgid "Author:" -msgstr "Autor:" - -msgid "AutoInit Network" -msgstr "AutoIniciar la Red" - -msgid "BCA Codes Path" -msgstr "Ruta Códigos BCA" - -msgid "BETA revisions" -msgstr "Revisiones BETA" - -msgid "Back" -msgstr "Atrás" - -msgid "Back to HBC or Wii Menu" -msgstr "Volver a HBC o Menú Wii" - -msgid "Back to Loader" -msgstr "Volver al HBC" - -msgid "Backgroundmusic" -msgstr "Música de fondo" - -msgid "Big thanks to:" -msgstr "Gracias a:" - -msgid "Block IOS Reload" -msgstr "Impedir recarga IOS" - -msgid "Boot/Standard" -msgstr "Inicio/Estándar" - -msgid "Boot?" -msgstr "¿Ejecutar?" - -msgid "Can't be formatted" -msgstr "No se puede formatear" - -msgid "Can't create directory" -msgstr "No se creó la carpeta" - -msgid "Can't create file" -msgstr "No se creó el archivo" - -msgid "Can't delete:" -msgstr "No se eliminó:" - -msgid "Cancel" -msgstr "Cancelar" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Cambiar Ruta" - -msgid "Cheatfile is blank" -msgstr "El archivo de Trucos está vacio" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Clic para descargar Carátulas" - -msgid "Click to change game ID" -msgstr "Clic para cambiar la ID del juego" - -msgid "Clock" -msgstr "Reloj" - -msgid "Close" -msgstr "Salir" - -msgid "Code Download" -msgstr "Descargar Códigos" - -#, c-format -msgid "Coded by: %s" -msgstr "Programado por: %s" - -msgid "Coding:" -msgstr "Programación:" - -msgid "Connection lost..." -msgstr "Conexión perdida..." - -msgid "Console" -msgstr "Consola" - -msgid "Console Locked" -msgstr "Consola Bloqueada" - -msgid "Console should be unlocked to modify it." -msgstr "Debes desbloquear la consola para modificar." - -msgid "Continue to install game?" -msgstr "¿Continuar instalando juego?" - -msgid "Controllevel" -msgstr "Control de Nivel" - -msgid "Correct Password" -msgstr "Contraseña Correcta" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "¡No se pudo crear el archivo GCT!" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "¡No se pudo iniciar módulo DIP!" - -msgid "Could not initialize network!" -msgstr "¡No se pudo iniciar la Red!" - -msgid "Could not open Disc" -msgstr "¡No se pudo abrir el Disco!" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "¡No se pudo guardar!" - -msgid "Cover Download" -msgstr "Descarga de Carátulas" - -msgid "Create" -msgstr "Crear" - -msgid "Credits" -msgstr "Créditos" - -msgid "Custom Paths" -msgstr "Personalizar Rutas" - -msgid "DOL Path" -msgstr "Ruta del DOL" - -msgid "Dec" -msgstr "Dic" - -msgid "Default" -msgstr "Predeterminado" - -msgid "Default Gamesettings" -msgstr "Conf. Pred. de Juegos" - -msgid "Default Settings" -msgstr "Configuración Predeterminada" - -msgid "Delete" -msgstr "Borrar" - -msgid "Delete ?" -msgstr "¿Borrar?" - -msgid "Delete Cheat GCT" -msgstr "Borrar Trucos GCT" - -msgid "Delete Cheat TXT" -msgstr "Borrar Trucos TXT" - -msgid "Delete Cover Artwork" -msgstr "Borrar Carátula" - -msgid "Delete Disc Artwork" -msgstr "Borrar Imagen Disco" - -msgid "Design:" -msgstr "Diseño:" - -msgid "Developed by" -msgstr "Desarrollado por" - -msgid "Directory does not exist!" -msgstr "¡La carpeta no existe!" - -msgid "Disc Artwork Download" -msgstr "Descarga Imagen Discos" - -msgid "Disc Artwork Path" -msgstr "Ruta Imagen Discos" - -msgid "Disc Images" -msgstr "Imagen Discos" - -msgid "Display" -msgstr "Mostrar" - -msgid "Display as a carousel" -msgstr "Mostrar como carrusel" - -msgid "Display as a grid" -msgstr "Mostrar como rejilla" - -msgid "Display as a list" -msgstr "Mostrar como lista" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "¿Realmente quieres borrar?:" - -msgid "Do you want to apply it now?" -msgstr "¿Quieres aplicarlo ahora?" - -msgid "Do you want to change language?" -msgstr "¿Quieres cambiar el idioma?" - -msgid "Do you want to download this theme?" -msgstr "¿Quieres descargar este Tema?" - -msgid "Do you want to format:" -msgstr "Quieres formatear:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "¿Quieres usar el DOL Alternativo que se sabe es correcto?" - -msgid "Do you wish to update/download all language files?" -msgstr "¿Quieres actualizar/descargar todos los archivos de idiomas?" - -msgid "Done!" -msgstr "¡Listo!" - -msgid "Download" -msgstr "Descargar" - -msgid "Download Boxart image?" -msgstr "¿Descargar Imágenes?" - -msgid "Download Discart image?" -msgstr "¿Descargar la imagen del disco?" - -msgid "Download Now" -msgstr "Descargar ahora" - -msgid "Download failed." -msgstr "Error en la descarga." - -msgid "Download finished" -msgstr "Descarga completada" - -msgid "Download request failed." -msgstr "Error al solicitar la descarga." - -msgid "Downloading Page List:" -msgstr "Descargando Lista de Páginas:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Descargando archivo" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Descargando imagen:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "" - -msgid "ERROR:" -msgstr "" - -msgid "ERROR: Can't set up theme." -msgstr "ERROR: No se puede configurar el tema." - -msgid "Error" -msgstr "" - -msgid "Error !" -msgstr "¡Error!" - -msgid "Error 002 fix" -msgstr "Parchear Error 002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Error leyendo Disco" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Error durante la transferencia de datos." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "" - -msgid "Error:" -msgstr "" - -msgid "Extracting files..." -msgstr "Extrayendo archivos..." - -msgid "FAT: Use directories" -msgstr "Usar carpetas FAT" - -msgid "Failed formating" -msgstr "No se ha podido formatear" - -msgid "Failed to extract." -msgstr "No se ha podido extraer" - -msgid "Failed to open partition" -msgstr "No se ha podido abrir la partición" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "Archivo no encontrado." - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Finalizando instalación... ¡Correcto!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Desplazamiento X" - -msgid "Format" -msgstr "Formateo" - -msgid "Formatting, please wait..." -msgstr "Formateando, por favor espera..." - -msgid "Free Space" -msgstr "Espacio Libre" - -msgid "Full Shutdown" -msgstr "Apagado Total" - -msgid "GCT Cheatcodes Path" -msgstr "Ruta de Trucos GCT" - -msgid "GCT File created" -msgstr "Archivo GCT creado" - -msgid "GUI Settings" -msgstr "Configuración de la GUI" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "No se encuentra GXtheme.cfg en ninguna subcarpeta." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Idioma" - -msgid "Game Load" -msgstr "Configuración de los Juegos" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Tamaño del Juego" - -msgid "Game Sound Mode" -msgstr "Modo sonido del Juego" - -msgid "Game Sound Volume" -msgstr "Volumen sonido del Juego" - -msgid "Game is already installed:" -msgstr "El juego ya estaba instalado:" - -msgid "Game partition" -msgstr "Partición de Juegos" - -msgid "Games" -msgstr "Juegos" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Menú HOME" - -msgid "Homebrew Apps Path" -msgstr "Ruta Apps Homebrew" - -msgid "Homebrew Launcher" -msgstr "Ejecutar Homebrew" - -msgid "Hour" -msgstr "Horas" - -msgid "How do you want to update?" -msgstr "¿Cómo quieres actualizar?" - -msgid "How to Shutdown?" -msgstr "¿Cómo quieres apagar?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Si no tienes WiFi, pulsa 1 para ver la URL donde coger tu WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Archivo recibido %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Archivo recibido %0.2fMB" - -msgid "Initializing Network" -msgstr "Iniciando la Red" - -msgid "Insert Disk" -msgstr "Inserta el Disco" - -msgid "Insert a Wii Disc!" -msgstr "¡Inserta un Disco Wii!" - -msgid "Insert an SD-Card to save." -msgstr "Insertar SD para guardar." - -msgid "Insert an SD-Card to use this option." -msgstr "Insertar SD para usar esta opción" - -msgid "Install" -msgstr "Instalar" - -msgid "Install Error!" -msgstr "¡Error de Instalación!" - -msgid "Install a game" -msgstr "Instalar un juego" - -msgid "Install partitions" -msgstr "Instalar particiones" - -msgid "Installing content... Ok!" -msgstr "Instalando contenido... ¡Correcto!" - -msgid "Installing game:" -msgstr "Instalando juego:" - -msgid "Installing ticket... Ok!" -msgstr "Instalando ticket... ¡Correcto!" - -msgid "Installing title... Ok!" -msgstr "Instalando título... ¡Correcto!" - -msgid "Installing wad" -msgstr "Instalando el WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Parece que tienes alguna información que puede ser útil para nosotros. Por favor envía esta información al equipo desarrollador." - -msgid "Jan" -msgstr "Ene" - -msgid "July" -msgstr "Jul" - -msgid "June" -msgstr "Jun" - -msgid "Keep" -msgstr "Mantener" - -msgid "Keyboard" -msgstr "Teclado" - -msgid "Language File" -msgstr "Idiomas" - -msgid "Language change:" -msgstr "Cambio de Idioma:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Ruta de idioma cambiada." - -msgid "Load" -msgstr "Cargar" - -#, c-format -msgid "Load file from: %s ?" -msgstr "¿Cargar el archivo desde: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "¿Cargar este DOL como DOL Alternativo?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Cargando idioma estándar." - -msgid "Loading standard music." -msgstr "Cargando música estándar." - -msgid "Lock Console" -msgstr "Bloquear consola" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "Marcar juegos nuevos" - -msgid "May" -msgstr "" - -msgid "Missing files" -msgstr "Archivo(s) pendiente(s)" - -msgid "Mount DVD drive" -msgstr "Montar unidad DVD" - -msgid "Music Loop Mode" -msgstr "Modo Bucle Musical" - -msgid "Music Volume" -msgstr "Volumen de la Música" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Nuevo Disco Detectado" - -msgid "No" -msgstr "" - -msgid "No Cheatfile found" -msgstr "No se encontró el archivo de Trucos" - -msgid "No DOL file found on disc." -msgstr "No se encontró el archivo DOL en el Disco" - -msgid "No SD-Card inserted!" -msgstr "¡SD no insertada!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "No se seleccionaron trucos" - -msgid "No data could be read." -msgstr "No se dispone de datos para leer." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "¡No faltan archivos!" - -msgid "No new updates." -msgstr "No hay nuevas actualizaciones." - -msgid "No themes found on the site." -msgstr "No hay Temas en este sitio." - -msgid "Not a WAD file." -msgstr "No es un archivo WAD." - -msgid "Not a Wii Disc" -msgstr "No es un Disco Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "¡No hay suficiente memoria libre!" - -msgid "Not enough free space!" -msgstr "¡No hay suficiente espacio libre!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Formato no soportado." - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "Apagado" - -msgid "OK" -msgstr "Aceptar" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "" - -msgid "Official Site:" -msgstr "Página Oficial:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Control Parental" - -msgid "Partition" -msgstr "Partición" - -msgid "Password" -msgstr "Contraseña" - -msgid "Password Changed" -msgstr "Contraseña cambiada" - -msgid "Password has been changed" -msgstr "La contraseña ha sido cambiada" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Pégalo en tu navegador para obtener tu WiiTDB.zip." - -msgid "Patch Country Strings" -msgstr "Parchear País" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Elegir de una lista" - -msgid "Play Count" -msgstr "Partidas" - -msgid "Play Next" -msgstr "Oír Siguiente" - -msgid "Play Previous" -msgstr "Oír Anterior" - -msgid "Playing Music:" -msgstr "Reproducción Musical:" - -msgid "Please wait..." -msgstr "Por favor, espera..." - -msgid "Power off the Wii" -msgstr "Apagar la Wii" - -msgid "Prompts Buttons" -msgstr "Botones" - -msgid "Published by" -msgstr "Publicado por" - -msgid "Quick Boot" -msgstr "Inicio Rápido" - -msgid "Reading WAD data... Ok!" -msgstr "Leyendo datos del WAD... ¡Correcto!" - -msgid "Receiving file from:" -msgstr "Recibir archivo desde:" - -msgid "Released" -msgstr "Comercializado el" - -msgid "Reload SD" -msgstr "Recargar SD" - -msgid "Remove update" -msgstr "Quitar actualización" - -msgid "Rename Game on WBFS" -msgstr "Renombrar juego en WBFS" - -msgid "Reset BG Music" -msgstr "Reiniciar Música de Fondo" - -msgid "Reset Playcounter" -msgstr "Reiniciar Partidas" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Reiniciando..." - -msgid "Return" -msgstr "Volver" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Volver a Menú Wii" - -msgid "Rumble" -msgstr "Vibración" - -msgid "SFX Volume" -msgstr "Volumen de los Efectos" - -msgid "Save" -msgstr "Guardar" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "¿Guardar Lista de Juegos en" - -msgid "Saved" -msgstr "Guardado" - -msgid "Screensaver" -msgstr "Salvapantallas" - -msgid "Select" -msgstr "Seleccionar" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Seleccionar DOL" - -msgid "Sept" -msgstr "" - -msgid "Set Search-Filter" -msgstr "Usar filtro de búsqueda" - -msgid "Settings" -msgstr "Configuración" - -msgid "Shutdown System" -msgstr "Apagar Sistema" - -msgid "Shutdown to Idle" -msgstr "WiiConnect24" - -msgid "Sort alphabetically" -msgstr "Ordenar alfabéticamente" - -msgid "Sort by rank" -msgstr "Ordenar por clasificación" - -msgid "Sort order by most played" -msgstr "Ordenar por los más jugados" - -msgid "Sound" -msgstr "Sonido" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Agradecimientos especiales a:" - -msgid "Success" -msgstr "Conseguido" - -msgid "Success:" -msgstr "Conseguido:" - -msgid "Successfully Saved" -msgstr "Guardado correctamente" - -msgid "Successfully Updated" -msgstr "Actualización correcta" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "Actualización correcta gracias a www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "Borrado correctamente:" - -msgid "Successfully extracted theme." -msgstr "Tema extraido correctamente." - -msgid "Successfully installed:" -msgstr "Instalado correctamente:" - -msgid "TXT Cheatcodes Path" -msgstr "Ruta de Trucos TXT" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "La carpeta especificada no existe. ¿Quieres crearla?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Ruta Descarga Temas" - -msgid "Theme Downloader" -msgstr "Descarga de Temas" - -msgid "Theme Path" -msgstr "Ruta del Tema" - -msgid "Theme Title:" -msgstr "Título del Tema:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Quedan:" - -msgid "Title Launcher" -msgstr "Lanzador de Canales" - -msgid "Titles from WiiTDB" -msgstr "Títulos WiiTDB" - -msgid "Tooltips" -msgstr "InfoBurbujas" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Error en la transferencia." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB no encontrado" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX está protegido" - -msgid "Uninstall" -msgstr "Desinstalar" - -msgid "Uninstall Game" -msgstr "Borrar Juego" - -msgid "Uninstall Menu" -msgstr "Menú de Desinstalación" - -msgid "Uninstalling wad" -msgstr "Desinstalando el WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Desbloquea la consola para usar esta opción." - -msgid "Unsupported format, try to extract manually." -msgstr "Formato no soportado, prueba a extraer manualmente." - -msgid "Update" -msgstr "Actualizar" - -msgid "Update All" -msgstr "Actualizar Todo" - -msgid "Update DOL" -msgstr "Actualizar DOL" - -msgid "Update Files" -msgstr "Actualizar archivos" - -msgid "Update Path" -msgstr "Ruta Actualización" - -msgid "Update all Language Files" -msgstr "Actualizar todos los archivos de Idiomas" - -msgid "Update failed" -msgstr "Error en la Actualización" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Actualizando archivos de Idiomas:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Enviado archivo ZIP instalado en la carpeta homebrew." - -msgid "VIDTV Patch" -msgstr "Parche VIDTV" - -#, c-format -msgid "Version: %s" -msgstr "Versión: %s" - -msgid "Video Mode" -msgstr "Modo Vídeo" - -msgid "WIP Patches Path" -msgstr "Ruta Parches WIP" - -msgid "Waiting for USB Device" -msgstr "Esperando al Dispositivo USB" - -msgid "Waiting..." -msgstr "Esperando..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "¿Qué quieres actualizar?" - -msgid "WiFi Features" -msgstr "Características WiFi" - -msgid "Wii Menu" -msgstr "Menú de Wii" - -msgid "Wii Settings" -msgstr "Opciones de Wii" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "Ruta WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Iluminar lector" - -msgid "Wrong Password" -msgstr "Contraseña incorrecta" - -msgid "Yes" -msgstr "Sí" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Necesitas seleccionar o formatear una partición" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Tu URL se ha guardado en %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "y traductores por actualizar los idiomas" - -msgid "available" -msgstr "disponible" - -msgid "does not exist!" -msgstr "no existe" - -msgid "does not exist! Loading game without cheats." -msgstr "no existe. Ejecutando el juego sin trucos." - -msgid "files left" -msgstr "archivos pendientes" - -msgid "files not found on the server!" -msgstr "archivo(s) no encontrado(s) en el servidor." - -msgid "for FAT/NTFS support" -msgstr "por el soporte FAT/NTFS" - -msgid "for Ocarina" -msgstr "por Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "por WiiTB y alojar caráturas e imágenes" - -msgid "for diverse patches" -msgstr "por diversos parches" - -msgid "for his awesome tool LibWiiGui" -msgstr "por su increible herramienta LibWiiGui" - -msgid "for hosting the themes" -msgstr "por alojar los Temas" - -msgid "for hosting the update files" -msgstr "por alojar las actualizaciones" - -msgid "for the USB Loader source" -msgstr "por el código de USB Loader" - -msgid "formatted!" -msgstr "¡formateado!" - -msgid "free" -msgstr "libres" - -msgid "not set" -msgstr "sin contraseña" - -msgid "of" -msgstr "de" - -msgid "seconds left" -msgstr "segundos restantes" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Instalar Copias 1:1" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Todos)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Niños 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 hora" - -#~ msgid "10 min" -#~ msgstr "10 min." - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Adolescentes 12+)" - -#~ msgid "20 min" -#~ msgstr "20 min." - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Jóvenes 16+)" - -#~ msgid "3 min" -#~ msgstr "3 min." - -#~ msgid "30 min" -#~ msgstr "30 min." - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Sólo Adultos 18+)" - -#~ msgid "5 min" -#~ msgstr "5 min." - -#~ msgid "An Error occured" -#~ msgstr "Ocurrió un Error" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "¿Estás seguro de querer activar el Control Parental?" - -#~ msgid "AutoPatch" -#~ msgstr "AutoParchear" - -#~ msgid "Both" -#~ msgstr "Ambos" - -#~ msgid "Checking for Updates" -#~ msgstr "Comprobando actualizaciones" - -#~ msgid "Console Default" -#~ msgstr "Pred. Consola" - -#~ msgid "Customs/Original" -#~ msgstr "Artísticas/Originales" - -#~ msgid "Disc Default" -#~ msgstr "Pred. Disco" - -#~ msgid "DiskFlip" -#~ msgstr "GiraDiscos" - -#~ msgid "Downloading" -#~ msgstr "Descargando" - -#~ msgid "Dutch" -#~ msgstr "Holandés" - -#~ msgid "English" -#~ msgstr "Inglés" - -#~ msgid "French" -#~ msgstr "Francés" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "IDdelJuego_NombreDelJuego" - -#~ msgid "Game ID" -#~ msgstr "ID del Juego" - -#~ msgid "Game Region" -#~ msgstr "Región" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "NombreDelJuego [IDdelJuego]" - -#~ msgid "German" -#~ msgstr "Alemán" - -#~ msgid "Invalid PIN code" -#~ msgstr "Código PIN erróneo" - -#~ msgid "Italian" -#~ msgstr "Italiano" - -#~ msgid "Japanese" -#~ msgstr "Japonés" - -#~ msgid "Korean" -#~ msgstr "Coreano" - -#~ msgid "Left" -#~ msgstr "Izquierda" - -#~ msgid "Like SysMenu" -#~ msgstr "Como Menú Sist." - -#~ msgid "Load From SD/USB" -#~ msgstr "Cargar desde SD/USB" - -#~ msgid "Locked" -#~ msgstr "Bloqueada" - -#~ msgid "Loop Directory" -#~ msgstr "Carpeta de bucle" - -#~ msgid "Loop Music" -#~ msgstr "Bucle musical" - -#~ msgid "Loop Sound" -#~ msgstr "Bucle de sonido" - -#~ msgid "Neither" -#~ msgstr "Ninguno" - -#~ msgid "Next" -#~ msgstr "Siguiente" - -#~ msgid "None" -#~ msgstr "Ninguno" - -#~ msgid "ON" -#~ msgstr "Encendido" - -#~ msgid "Only Customs" -#~ msgstr "Sólo Artísticas" - -#~ msgid "Only Original" -#~ msgstr "Sólo Originales" - -#~ msgid "Only for Install" -#~ msgstr "Sólo al instalar" - -#~ msgid "Original/Customs" -#~ msgstr "Originales/Artísticas" - -#~ msgid "Parental Control disabled" -#~ msgstr "Control Parental desactivado" - -#~ msgid "Play Once" -#~ msgstr "Oir una vez" - -#~ msgid "Prev" -#~ msgstr "Ant." - -#~ msgid "Random Directory Music" -#~ msgstr "Aleatorio de la carpeta musical" - -#~ msgid "Right" -#~ msgstr "Derecha" - -#~ msgid "SChinese" -#~ msgstr "Chino S." - -#~ msgid "Sound+BGM" -#~ msgstr "Sonido+Música Fondo" - -#~ msgid "Sound+Quiet" -#~ msgstr "Sonido+Silencio" - -#~ msgid "Spanish" -#~ msgstr "Español" - -#~ msgid "System Default" -#~ msgstr "Pred. Sistema" - -#~ msgid "TChinese" -#~ msgstr "Chino T." - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "El archivo WAD se ha instalado. Pero no puede ser borrado de la tarjeta SD." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "La instalación del WAD falló con el error %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "No se puede abrir el WAD que acabas de descargar (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Desbloquear Control Parental" - -#~ msgid "Unlocked" -#~ msgstr "Desbloqueada" - -#~ msgid "Update to" -#~ msgstr "Descargando la" - -#~ msgid "Updating" -#~ msgstr "Actualizando" - -#~ msgid "Updating Language Files..." -#~ msgstr "Actualizando archivos de Idiomas..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Actualizando WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Ajuste panorámico" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "No tienes el Control Parental activado. Si quieres usar el Control Parental, actívalo en la Configuración de la Wii." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s No puede arrancar correctamente si el Menú de Sistema no está actualizado." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "Ruta de Códigos BCA cambiada" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Volver a Menú Wii" - -#~ msgid "Channels" -#~ msgstr "Canales" - -#~ msgid "Checking existing artwork" -#~ msgstr "Comprobando los archivos existentes" - -#~ msgid "Confirm" -#~ msgstr "Confirmar" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "¡No se encontró la partición WBFS!" - -#~ msgid "Could not open WBFS partition" -#~ msgstr "¡No se pudo abrir la partición WBFS!" - -#~ msgid "Could not read the disc." -#~ msgstr "¡No se pudo leer el Disco!" - -#~ msgid "Could not set USB." -#~ msgstr "¡No se pudo configurar el USB!" - -#~ msgid "Cover Path Changed" -#~ msgstr "Ruta de Carátulas cambiada" - -#~ msgid "DOL path changed" -#~ msgstr "Ruta del DOL cambiada" - -#~ msgid "Disc Path Changed" -#~ msgstr "Ruta Imagen Discos cambiada" - -#~ msgid "Display favorites" -#~ msgstr "Mostrar favoritos" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "¿Quieres reintentar por 30 segs.?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Activar Control Parental" - -#~ msgid "Force" -#~ msgstr "Forzar" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Ruta de Trucos GCT cambiada" - -#~ msgid "Hermes CIOS" -#~ msgstr "cIOS Hermes" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Ruta de Apps Homebrew cambiada" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Insertar SD para bajar imágenes." - -#~ msgid "Install not possible" -#~ msgstr "Imposible instalar" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Probablemente, las dimensiones no sean múltiplo de 4." - -#~ msgid "Network init error" -#~ msgstr "Error al iniciar la Red" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "No se encontró archivos .dol o .elf." - -#~ msgid "No Favorites" -#~ msgstr "No hay Favoritos" - -#~ msgid "No USB Device" -#~ msgstr "USB no encontrado" - -#~ msgid "No USB Device found." -#~ msgstr "USB no encontrado." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Partición WBFS o FAT/NTFS no encontrada" - -#~ msgid "Normal Covers" -#~ msgstr "Normales" - -#~ msgid "Not Found" -#~ msgstr "No encontrado" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "No es un archivo DOL/ELF." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "¿Poner la Música por defecto?" - -#~ msgid "Save Failed" -#~ msgstr "Error al guardar" - -#~ msgid "Selected DOL" -#~ msgstr "DOL Seleccionado" - -#~ msgid "Standard" -#~ msgstr "Estándar" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "Ruta del archivo de Trucos cambiada" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Ruta de Descarga del Tema cambiada" - -#~ msgid "Theme Path Changed" -#~ msgstr "Ruta de Tema cambiada" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "¡USB Loader GX sólo funciona con cIOS Hermes rev 4!. ¡Por favor, asegúrate de que tienes instalada la versión 4!" - -#~ msgid "Update Path changed." -#~ msgstr "Ruta Actualización cambiada." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "Ruta Parches WIP cambiada" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "Ruta WiiTDB cambiada." - -#~ msgid "You are about to delete " -#~ msgstr "Estás a punto de borrar " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Has seleccionado la vista de favoritos pero no tienes ninguno seleccionado." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Estás utilizando un sistema de archivos NTFS. Debido a posibles errores de escritura en la partición NTFS, la instalación del juego es imposible." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Has intentado cargar una imagen corrupta" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "no existe. Cometiste algún error al poner el DOL." - -#~ msgid "file left" -#~ msgstr "archivo pendiente" diff --git a/Languages/swedish.lang b/Languages/swedish.lang deleted file mode 100644 index 3af57706..00000000 --- a/Languages/swedish.lang +++ /dev/null @@ -1,1522 +0,0 @@ -# USB Loader GX language source file. -# swedish.lang - r898 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2010-01-19 17:39+0200\n" -"Last-Translator: Katsurou\n" -"Language-Team: Katsurou, pirateX\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "Wad sparad som:" - -msgid " could not be downloaded." -msgstr "Kunde inte laddas ner." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "har sparats. Texten har inte blivit varifierad. Några av koderna kanske inte fungerar riktigt med varandra. Om du upplever problem, öppna texten i en textredigerare för mer information." - -msgid " is not on the server." -msgstr "finns inte på servern." - -msgid "2D Cover Path" -msgstr "2D Omslagsmapp" - -msgid "3D Cover Path" -msgstr "3D Omslagsmapp" - -msgid "3D Covers" -msgstr "3D-Omslag" - -msgid ">> Deleting tickets..." -msgstr ">> Raderar biljetter..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Raderar biljetter...FEL! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Raderar biljetter...Ok! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Raderar titel ...FEL! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> Raderar titel ...Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Raderar titel innehåll..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Raderar titel innehåll...FEL! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Raderar titel innehåll...Ok!" - -msgid ">> Deleting title..." -msgstr ">> Raderar titel..." - -msgid ">> Finishing installation..." -msgstr ">> Gör klart installation..." - -msgid ">> Installing content #" -msgstr ">> Installerar innehåll #" - -msgid ">> Installing ticket..." -msgstr ">> Installerar biljett..." - -msgid ">> Installing title..." -msgstr ">> Installerar titel..." - -msgid ">> Reading WAD data..." -msgstr ">> Läser WAD data..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> Läser WAD data...FEL! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> Läser WAD data...Ok!" - -msgid "AUTO" -msgstr "" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "Alla partitioner" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "Alla funktioner i USB Loader GX är upplåsta." - -msgid "Alternate DOL" -msgstr "Alternativ DOL" - -msgid "App Language" -msgstr "Programspråk" - -msgid "Apr" -msgstr "Apr" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Är du säker?" - -msgid "Aug" -msgstr "" - -msgid "Author:" -msgstr "Utgivare:" - -msgid "AutoInit Network" -msgstr "Autoinitiera Nätverk" - -msgid "BCA Codes Path" -msgstr "BCA kodssökväg" - -msgid "BETA revisions" -msgstr "BETA version" - -msgid "Back" -msgstr "Tillbaka" - -msgid "Back to HBC or Wii Menu" -msgstr "Tillbaka till HBC eller Wii-Menyn" - -msgid "Back to Loader" -msgstr "Tillbaka till loader" - -msgid "Backgroundmusic" -msgstr "Bakgrundsmusik" - -msgid "Big thanks to:" -msgstr "Stort tack till:" - -msgid "Block IOS Reload" -msgstr "Blockera IOS omladdning" - -msgid "Boot/Standard" -msgstr "Boot/Standard" - -msgid "Boot?" -msgstr "Starta?" - -msgid "Can't be formatted" -msgstr "Kan inte formateras" - -msgid "Can't create directory" -msgstr "Kan inte skapa mapp" - -msgid "Can't create file" -msgstr "Kunde inte skapa fil" - -msgid "Can't delete:" -msgstr "Kunde inte radera:" - -msgid "Cancel" -msgstr "Avbryt" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "Ändra spel sökväg" - -msgid "Cheatfile is blank" -msgstr "Fuskfilen är blank" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Klicka för att ladda ner omslag" - -msgid "Click to change game ID" -msgstr "Klicka för att byta spel ID" - -msgid "Clock" -msgstr "Klocka" - -msgid "Close" -msgstr "Stäng" - -msgid "Code Download" -msgstr "Fusknedladdning" - -#, c-format -msgid "Coded by: %s" -msgstr "Kodad av: %s" - -msgid "Coding:" -msgstr "Kodning:" - -msgid "Connection lost..." -msgstr "Uppkoppling förlorad..." - -msgid "Console" -msgstr "Konsol" - -msgid "Console Locked" -msgstr "Konsol låst" - -msgid "Console should be unlocked to modify it." -msgstr "Konsolen måste vara upplåst för att kunna ändra det." - -msgid "Continue to install game?" -msgstr "Fortsätt installera spel?" - -msgid "Controllevel" -msgstr "Kontrollnivå" - -msgid "Correct Password" -msgstr "Rätt lösenord" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "Kunde inte skapa GCT fil" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "Kunde inte starta DIP-modul!" - -msgid "Could not initialize network!" -msgstr "Kunde inte starta nätverket!" - -msgid "Could not open Disc" -msgstr "Kunde inte öppna skivan" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Kunde inte spara." - -msgid "Cover Download" -msgstr "Omslagsnedladdning" - -msgid "Create" -msgstr "Skapa" - -msgid "Credits" -msgstr "Medverkande" - -msgid "Custom Paths" -msgstr "Anpassade sökvägar" - -msgid "DOL Path" -msgstr "DOL-sökväg" - -msgid "Dec" -msgstr "" - -msgid "Default" -msgstr "Standard" - -msgid "Default Gamesettings" -msgstr "Ställ till spelstandard" - -msgid "Default Settings" -msgstr "Standardinställningar" - -msgid "Delete" -msgstr "Radera" - -msgid "Delete ?" -msgstr "Radera?" - -msgid "Delete Cheat GCT" -msgstr "Radera fusk GCT" - -msgid "Delete Cheat TXT" -msgstr "Radera fusk TXT" - -msgid "Delete Cover Artwork" -msgstr "Radera omslag" - -msgid "Delete Disc Artwork" -msgstr "Radera skivbilder" - -msgid "Design:" -msgstr "" - -msgid "Developed by" -msgstr "Utvecklat av" - -msgid "Directory does not exist!" -msgstr "Katalog existerar inte!" - -msgid "Disc Artwork Download" -msgstr "Skivbildsnedladdning" - -msgid "Disc Artwork Path" -msgstr "Skivbildsmapp" - -msgid "Disc Images" -msgstr "Skivbilder" - -msgid "Display" -msgstr "Visning" - -msgid "Display as a carousel" -msgstr "Visa som en karusell" - -msgid "Display as a grid" -msgstr "Visa som ett rutnät" - -msgid "Display as a list" -msgstr "Visa som en lista" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Vill du verkligen radera:" - -msgid "Do you want to apply it now?" -msgstr "Vill du tillämpa det nu?" - -msgid "Do you want to change language?" -msgstr "Vill du byta språk?" - -msgid "Do you want to download this theme?" -msgstr "Vill du ladda ner detta tema?" - -msgid "Do you want to format:" -msgstr "Vill du formatera:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Vill du använda en alternativ DOL som är känd att fungera?" - -msgid "Do you wish to update/download all language files?" -msgstr "Vill du uppdatera/ladda ner alla språkfiler?" - -msgid "Done!" -msgstr "Klar!" - -msgid "Download" -msgstr "Ladda ner" - -msgid "Download Boxart image?" -msgstr "Ladda ner omslagsbild?" - -msgid "Download Discart image?" -msgstr "Ladda ner skivbild?" - -msgid "Download Now" -msgstr "Ladda ner nu" - -msgid "Download failed." -msgstr "Nedladdning misslyckades." - -msgid "Download finished" -msgstr "Nedladdning klar" - -msgid "Download request failed." -msgstr "Nedladdnings begäran misslyckades." - -msgid "Downloading Page List:" -msgstr "Laddar ner lista:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Laddar ner fil:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "Laddar ner bild:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "FEL" - -msgid "ERROR:" -msgstr "FEL:" - -msgid "ERROR: Can't set up theme." -msgstr "FEL: Kan inte ställa in tema" - -msgid "Error" -msgstr "Fel" - -msgid "Error !" -msgstr "Fel!" - -msgid "Error 002 fix" -msgstr "002 fel fix" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Fel vid läsning av skiva" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Fel vid överförning av data." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Fel..." - -msgid "Error:" -msgstr "Fel:" - -msgid "Extracting files..." -msgstr "Packar upp filer..." - -msgid "FAT: Use directories" -msgstr "FAT: Använd mappar" - -msgid "Failed formating" -msgstr "Formatering misslyckad" - -msgid "Failed to extract." -msgstr "Uppackning misslyckades." - -msgid "Failed to open partition" -msgstr "Misslyckades att öppna partition" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "" - -msgid "File not found." -msgstr "Kunde inte hitta fil" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Gör klart installation... Ok!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Vänd-X" - -msgid "Format" -msgstr "Formatera" - -msgid "Formatting, please wait..." -msgstr "Formaterar, Vänta..." - -msgid "Free Space" -msgstr "Ledigt utrymme" - -msgid "Full Shutdown" -msgstr "Stäng av helt" - -msgid "GCT Cheatcodes Path" -msgstr "Fusksökväg" - -msgid "GCT File created" -msgstr "GCT fil skapad" - -msgid "GUI Settings" -msgstr "GUI inställningar" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "GXtheme.cfg kunde inte hittas i några undermappar." - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Språk" - -msgid "Game Load" -msgstr "Spelinställningar" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Spelstorlek" - -msgid "Game Sound Mode" -msgstr "Spel ljuds läge" - -msgid "Game Sound Volume" -msgstr "Spel ljuds volym" - -msgid "Game is already installed:" -msgstr "Spelet är redan installerat:" - -msgid "Game partition" -msgstr "Spel partition" - -msgid "Games" -msgstr "Spel" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "Hemmeny" - -msgid "Homebrew Apps Path" -msgstr "Homebrew Apps" - -msgid "Homebrew Launcher" -msgstr "Homebrew Startare" - -msgid "Hour" -msgstr "Timmars" - -msgid "How do you want to update?" -msgstr "Hur vill du uppdatera?" - -msgid "How to Shutdown?" -msgstr "Hur vill du stänga av?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Om du inte har WiFi, tryck 1 för att få en URL till din WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Inkommande fil %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Inkommande fil %0.2fMB" - -msgid "Initializing Network" -msgstr "Startar nätverk" - -msgid "Insert Disk" -msgstr "Sätt i en skiva" - -msgid "Insert a Wii Disc!" -msgstr "Sätt i en Wii-skiva!" - -msgid "Insert an SD-Card to save." -msgstr "Sätt i ett SD-kort för att spara." - -msgid "Insert an SD-Card to use this option." -msgstr "Sätt i ett SD-kort för att använda denna inställning" - -msgid "Install" -msgstr "Installera" - -msgid "Install Error!" -msgstr "Fel vid installering!" - -msgid "Install a game" -msgstr "Installera ett spel" - -msgid "Install partitions" -msgstr "Installera partitioner" - -msgid "Installing content... Ok!" -msgstr "Installerar innehåll... Ok!" - -msgid "Installing game:" -msgstr "Installerar spel:" - -msgid "Installing ticket... Ok!" -msgstr "Installerar biljett... Ok!" - -msgid "Installing title... Ok!" -msgstr "Installerar titel... Ok!" - -msgid "Installing wad" -msgstr "Installerar wad" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "Det verkar som om du har information som kan vara till nytta för oss. Vänligen skicka informationen vidare till DEV team." - -msgid "Jan" -msgstr "" - -msgid "July" -msgstr "Juli" - -msgid "June" -msgstr "Juni" - -msgid "Keep" -msgstr "Behåll" - -msgid "Keyboard" -msgstr "Tangentbord" - -msgid "Language File" -msgstr "Språk fil" - -msgid "Language change:" -msgstr "Språkbyte:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Sökväg till språk ändrad" - -msgid "Load" -msgstr "Ladda" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Ladda fil från: %s?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Ladda denna DOL som alternativ DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Laddar standard språk." - -msgid "Loading standard music." -msgstr "Laddar standard musik." - -msgid "Lock Console" -msgstr "Lås konsol" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "Markera nya spel" - -msgid "May" -msgstr "Maj" - -msgid "Missing files" -msgstr "Filer som saknas" - -msgid "Mount DVD drive" -msgstr "Montera DVD läsare" - -msgid "Music Loop Mode" -msgstr "Musik Återuppspelningsläge" - -msgid "Music Volume" -msgstr "Volym" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Ny skiva upptäckt" - -msgid "No" -msgstr "Nej" - -msgid "No Cheatfile found" -msgstr "Ingen fuskfil hittades" - -msgid "No DOL file found on disc." -msgstr "Ingen DOL-fil hittades på skivan." - -msgid "No SD-Card inserted!" -msgstr "Inget SD-kort isatt!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Inga fusk har valda" - -msgid "No data could be read." -msgstr "Ingen data kunde läsas." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Inga filer saknas!" - -msgid "No new updates." -msgstr "Inga nya uppdateringar" - -msgid "No themes found on the site." -msgstr "Inga teman hittades på sidan." - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Inte en Wii-skiva" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Inte tillräckligt med ledigt minne." - -msgid "Not enough free space!" -msgstr "Inte tillräckligt med ledigt utrymme!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Formatet stöds inte!" - -msgid "Nov" -msgstr "" - -msgid "OFF" -msgstr "AV" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Okt" - -msgid "Official Site:" -msgstr "Officiell sida:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Föräldrakontroll" - -msgid "Partition" -msgstr "" - -msgid "Password" -msgstr "Lösenord" - -msgid "Password Changed" -msgstr "Lösenordet ändrat" - -msgid "Password has been changed" -msgstr "Lösenordet har ändrats" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "Klistra in det i din webbläsare för att hämta din WiiTDB.zip." - -msgid "Patch Country Strings" -msgstr "Ställ in landssträngar" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Välj från en lista" - -msgid "Play Count" -msgstr "Spelat" - -msgid "Play Next" -msgstr "Spela nästa" - -msgid "Play Previous" -msgstr "Spela förgående" - -msgid "Playing Music:" -msgstr "Spela musik:" - -msgid "Please wait..." -msgstr "Vänligen vänta..." - -msgid "Power off the Wii" -msgstr "Stäng av Wii" - -msgid "Prompts Buttons" -msgstr "Dialogknappar" - -msgid "Published by" -msgstr "Publicerat av" - -msgid "Quick Boot" -msgstr "Snabbstart" - -msgid "Reading WAD data... Ok!" -msgstr "Läser WAD data... Ok!" - -msgid "Receiving file from:" -msgstr "Tar emot filer från:" - -msgid "Released" -msgstr "Släppt" - -msgid "Reload SD" -msgstr "Ladda om SD" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "Döp om spel på WBFS" - -msgid "Reset BG Music" -msgstr "återställ BG musik" - -msgid "Reset Playcounter" -msgstr "Återställ spelat-räknaren" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Startar om..." - -msgid "Return" -msgstr "Återvänd" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Återvänd till Wii-menyn" - -msgid "Rumble" -msgstr "Vibration" - -msgid "SFX Volume" -msgstr "SFX Volym" - -msgid "Save" -msgstr "Spara" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Spara spel lista till" - -msgid "Saved" -msgstr "Sparat" - -msgid "Screensaver" -msgstr "Skärmsläckare" - -msgid "Select" -msgstr "Välj" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Välj en DOL" - -msgid "Sept" -msgstr "" - -msgid "Set Search-Filter" -msgstr "Ställ in sök-filter" - -msgid "Settings" -msgstr "Inställningar" - -msgid "Shutdown System" -msgstr "Stäng av helt" - -msgid "Shutdown to Idle" -msgstr "Försätt i viloläge" - -msgid "Sort alphabetically" -msgstr "Sortera alfabetiskt" - -msgid "Sort by rank" -msgstr "Sortera efter rank" - -msgid "Sort order by most played" -msgstr "Sortera efter mest spelade" - -msgid "Sound" -msgstr "Ljud" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Speciellt tack till:" - -msgid "Success" -msgstr "Lyckat" - -msgid "Success:" -msgstr "Lyckat:" - -msgid "Successfully Saved" -msgstr "Lyckad sparning" - -msgid "Successfully Updated" -msgstr "Uppdateringen lyckades" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Lyckad radering av:" - -msgid "Successfully extracted theme." -msgstr "Extrahering av tema lyckades." - -msgid "Successfully installed:" -msgstr "Lyckad installation av:" - -msgid "TXT Cheatcodes Path" -msgstr "Sökväg till txt koder" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Den angivna katalogen existerar inte. Vill du skapa den?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Tema-mapp nedladdade" - -msgid "Theme Downloader" -msgstr "Tema Nedladdare" - -msgid "Theme Path" -msgstr "Tema-mapp" - -msgid "Theme Title:" -msgstr "Tema titel:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Tid kvar:" - -msgid "Title Launcher" -msgstr "Titel startare" - -msgid "Titles from WiiTDB" -msgstr "Titlar från WiiTDB" - -msgid "Tooltips" -msgstr "Verktygstips" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Flytt misslyckades." - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB-enhet ej hittad" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX är skyddad" - -msgid "Uninstall" -msgstr "Avinstallera" - -msgid "Uninstall Game" -msgstr "Avinstallera spel" - -msgid "Uninstall Menu" -msgstr "Avinstallerings meny" - -msgid "Uninstalling wad" -msgstr "Avinstallerar wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Lås upp konsolen för denna inställning." - -msgid "Unsupported format, try to extract manually." -msgstr "Format stöds inte, försök extrahera manuelt." - -msgid "Update" -msgstr "Uppdatera" - -msgid "Update All" -msgstr "Uppdatera alla" - -msgid "Update DOL" -msgstr "Updatera DOL" - -msgid "Update Files" -msgstr "Uppdatera Filer" - -msgid "Update Path" -msgstr "Sökväg till uppdatering" - -msgid "Update all Language Files" -msgstr "Uppdatera alla språk-filer" - -msgid "Update failed" -msgstr "Uppdatering misslyckades" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Uppdatera språk-filer:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "Uppladdad ZIP fil installerad till homebrew-mappen" - -msgid "VIDTV Patch" -msgstr "VIDTV-Patch" - -#, c-format -msgid "Version: %s" -msgstr "" - -msgid "Video Mode" -msgstr "Video-läge" - -msgid "WIP Patches Path" -msgstr "WIP patchssökväg" - -msgid "Waiting for USB Device" -msgstr "Väntar på USB-enhet" - -msgid "Waiting..." -msgstr "Väntar..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Vad vill du uppdatera?" - -msgid "WiFi Features" -msgstr "WiFi funktioner" - -msgid "Wii Menu" -msgstr "Wii-meny" - -msgid "Wii Settings" -msgstr "Wii inställningar" - -msgid "WiiTDB Files" -msgstr "WiiTDB" - -msgid "WiiTDB Path" -msgstr "WiiTDB-sökväg" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "Wii-ljus" - -msgid "Wrong Password" -msgstr "Fel Lösenord" - -msgid "Yes" -msgstr "Ja" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Du måste välja eller formatera en partition" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "Din URL har sparats som %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "och översättarna." - -msgid "available" -msgstr "tillgänglig" - -msgid "does not exist!" -msgstr "existerar inte!" - -msgid "does not exist! Loading game without cheats." -msgstr "existerar inte! Laddar spel utan fusk." - -msgid "files left" -msgstr "filer kvar" - -msgid "files not found on the server!" -msgstr "filerna hittades inte på servern!" - -msgid "for FAT/NTFS support" -msgstr "för FAT/NTFS stöd" - -msgid "for Ocarina" -msgstr "för Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "för WiiTDB och lagring av omslag / skivbilder" - -msgid "for diverse patches" -msgstr "för diverse patcher" - -msgid "for his awesome tool LibWiiGui" -msgstr "för hans underbara verktyg LibWiiGui" - -msgid "for hosting the themes" -msgstr "för hostning av teman" - -msgid "for hosting the update files" -msgstr "för lagring av uppdateringar" - -msgid "for the USB Loader source" -msgstr "och släppet av källkoden" - -msgid "formatted!" -msgstr "formaterad!" - -msgid "free" -msgstr "ledigt" - -msgid "not set" -msgstr "Inget satt" - -msgid "of" -msgstr "av" - -msgid "seconds left" -msgstr "sekunder kvar" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "Installera 1:1 Kopia" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Alla)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Barn 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 timme" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Tonåringar 12+)" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Ungdomar 16+)" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Endast Vuxna 18+)" - -#~ msgid "An Error occured" -#~ msgstr "Ett fel har uppstått" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "Är du säker på att du vill aktivera Föräldrakontroll?" - -#~ msgid "AutoPatch" -#~ msgstr "Autopatch" - -#~ msgid "Both" -#~ msgstr "Båda" - -#~ msgid "Checking for Updates" -#~ msgstr "Letar efter uppdateringar" - -#~ msgid "Console Default" -#~ msgstr "Konsolestandard" - -#~ msgid "Customs/Original" -#~ msgstr "Anpassade/Original" - -#~ msgid "Disc Default" -#~ msgstr "Skivans standard" - -#~ msgid "DiskFlip" -#~ msgstr "Vänd Skiva" - -#~ msgid "Downloading" -#~ msgstr "Laddar ner" - -#~ msgid "Dutch" -#~ msgstr "Nederländska" - -#~ msgid "English" -#~ msgstr "Engelska" - -#~ msgid "French" -#~ msgstr "Franska" - -#~ msgid "Game ID" -#~ msgstr "Spel-ID" - -#~ msgid "Game Region" -#~ msgstr "Spelregion" - -#~ msgid "German" -#~ msgstr "Tyska" - -#~ msgid "Invalid PIN code" -#~ msgstr "Ogiltig PIN-kod" - -#~ msgid "Italian" -#~ msgstr "Italienska" - -#~ msgid "Japanese" -#~ msgstr "Japanska" - -#~ msgid "Korean" -#~ msgstr "Koreanska" - -#~ msgid "Left" -#~ msgstr "Vänster" - -#~ msgid "Like SysMenu" -#~ msgstr "Som System-menyn" - -#~ msgid "Load From SD/USB" -#~ msgstr "Ladda från SD/USB" - -#~ msgid "Locked" -#~ msgstr "Låst" - -#~ msgid "Loop Sound" -#~ msgstr "Loopa ljudet" - -#~ msgid "Neither" -#~ msgstr "Inget" - -#~ msgid "Next" -#~ msgstr "Nästa" - -#~ msgid "Normal" -#~ msgstr "Vanlig" - -#~ msgid "ON" -#~ msgstr "PÅ" - -#~ msgid "Only Customs" -#~ msgstr "Endast anpassade" - -#~ msgid "Only Original" -#~ msgstr "Endast original" - -#~ msgid "Only for Install" -#~ msgstr "Endast för installering" - -#~ msgid "Original/Customs" -#~ msgstr "Original/Anpassade" - -#~ msgid "Parental Control disabled" -#~ msgstr "Föräldrakontroll avaktiverad" - -#~ msgid "Prev" -#~ msgstr "Förra" - -#~ msgid "Right" -#~ msgstr "Höger" - -#~ msgid "SChinese" -#~ msgstr "SKinesiska" - -#~ msgid "Sound+BGM" -#~ msgstr "Ljud+BGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "Ljud+Tyst" - -#~ msgid "Spanish" -#~ msgstr "Spanska" - -#~ msgid "System Default" -#~ msgstr "Systemets standard" - -#~ msgid "TChinese" -#~ msgstr "TKinesiska" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Wad filen har blivit installerad. Men kunde inte raderas från SD-kortet." - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Wad installation misslyckades med fel %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Kunde inte öppna den nedladdade wad filen (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "Lås upp föräldrakontroll" - -#~ msgid "Unlocked" -#~ msgstr "Upplåst" - -#~ msgid "Update to" -#~ msgstr "Uppdatera till" - -#~ msgid "Updating" -#~ msgstr "Uppdaterar" - -#~ msgid "Updating Language Files..." -#~ msgstr "Uppdatera språk-filer..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "Uppdaterar WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "Bredbild 16/9 Fix" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "Du har inte föräldrakontroll aktiverad. Om du vill använda föräldrakontroll, aktivera det i Wii inställningar." - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s Kanske inte kan starta korrekt om din system meny inte är den nyaste versionen." - -#~ msgid "BCA Codes Path changed" -#~ msgstr "BCA kodssökväg ändrad" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Tillbaka till Wii-menyn" - -#~ msgid "Channels" -#~ msgstr "Kannaler" - -#~ msgid "Checking existing artwork" -#~ msgstr "Kontrollera befintliga konstverk" - -#~ msgid "Confirm" -#~ msgstr "Bekräfta" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "Kunde inte hitta WBFS partition." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "Kunde inte öppna WBFS partition" - -#~ msgid "Could not read the disc." -#~ msgstr "Kunde inte läsa skiva." - -#~ msgid "Could not set USB." -#~ msgstr "Kunde inte ställa in USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "Omslagsmapp ändrad" - -#~ msgid "DOL path changed" -#~ msgstr "DOL-sökväg ändrad" - -#~ msgid "Disc Path Changed" -#~ msgstr "Skivbildsmapp ändrad" - -#~ msgid "Display favorites" -#~ msgstr "Visa favoriter" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "Vill du försöka igen i 30 sekunder?" - -#~ msgid "Enable Parental Control" -#~ msgstr "Aktivera Föräldrakontroll" - -#~ msgid "Force" -#~ msgstr "Tvinga" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "Sökväg till fusk ändrad" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Homebrew Apps ändrad" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Sätt i ett SD-kort för att ladda ner bilder." - -#~ msgid "Install not possible" -#~ msgstr "Installation inte möjlig" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Troligtvis har den mått som inte är jämnt dividerade med 4." - -#~ msgid "Network init error" -#~ msgstr "Fel vid nätverksstart" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "Ingen .dol eller .elf fil hittades." - -#~ msgid "No Favorites" -#~ msgstr "Inga favoriter" - -#~ msgid "No USB Device" -#~ msgstr "Ingen USB-enhet" - -#~ msgid "No USB Device found." -#~ msgstr "Ingen USB-enhet hittad." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "Ingen WBFS eller FAT/NTFS partition hittad" - -#~ msgid "Normal Covers" -#~ msgstr "Vanliga omslag" - -#~ msgid "Not Found" -#~ msgstr "Hittades inte" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "Inte en DOL/ELF fil." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "Återställ till standard BGM?" - -#~ msgid "Save Failed" -#~ msgstr "Sparande misslyckat" - -#~ msgid "Selected DOL" -#~ msgstr "Vald DOL" - -#~ msgid "Standard" -#~ msgstr "Standard" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXTCheatcodes sökväg ändrad" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Tema-mapp nedladdade ändrad" - -#~ msgid "Theme Path Changed" -#~ msgstr "Tema-mapp ändrad" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX kommer endast köra med Hermes CIOS ver 4! Vänligen kontrollera att du har ver 4 installerad!" - -#~ msgid "Update Path changed." -#~ msgstr "Sökväg till uppdatering ändrad." - -#~ msgid "WIP Patches Path changed" -#~ msgstr "WIP patchssökväg ändrad" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB-sökväg ändrad." - -#~ msgid "You are about to delete " -#~ msgstr "Då håller på att radera " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Du har valt att visa favoriter men du har inga favoriter valda." - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "Du använder NTFS filsystem. Pågrund av möjliga skriv fel till en NTFS partition, så är det inte möjligt att installera spel." - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Du har försökt ladda en dålig bild" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "existerar inte! Du har gjort något fel." - -#~ msgid "file left" -#~ msgstr "fil kvar" diff --git a/Languages/tchinese.lang b/Languages/tchinese.lang deleted file mode 100644 index 1a7e089c..00000000 --- a/Languages/tchinese.lang +++ /dev/null @@ -1,1561 +0,0 @@ -# USB Loader GX language source file. -# tchinese.lang - r929 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2010-02-15 21:00+0800\n" -"Last-Translator: Jane.H\n" -"Language-Team: kyogc, Miller, Mika Li, Jane.H\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr "WAD 儲存為:" - -msgid " could not be downloaded." -msgstr "不能下載." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr "已經被儲存.內容尚未驗證.部分代碼可能無法作用.如果你遇到問題,請用文字編輯器打開文本文件以獲得更多的信息." - -msgid " is not on the server." -msgstr "不在伺服器上" - -msgid "2D Cover Path" -msgstr "2D封面路徑" - -msgid "3D Cover Path" -msgstr "3D封面路徑" - -msgid "3D Covers" -msgstr "3D 封面" - -msgid ">> Deleting tickets..." -msgstr ">> 刪除 tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> 刪除 tickets... 錯誤!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> 刪除 tickets... 成功!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> 刪除 title... 錯誤!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> 刪除 title... 成功!" - -msgid ">> Deleting title contents..." -msgstr ">> 刪除 title 內容..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> 刪除 title 內容... 錯誤!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> 刪除 title 內容... 成功!" - -msgid ">> Deleting title..." -msgstr ">> 刪除 title..." - -msgid ">> Finishing installation..." -msgstr ">> 完成安裝..." - -msgid ">> Installing content #" -msgstr ">> 安裝程式主體#" - -msgid ">> Installing ticket..." -msgstr ">> 安裝 ticket..." - -msgid ">> Installing title..." -msgstr ">> 安裝 title..." - -msgid ">> Reading WAD data..." -msgstr ">> 讀取 WAD 數據..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> 讀取 WAD 數據... 錯誤!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> 讀取 WAD 數據... 成功!" - -msgid "AUTO" -msgstr "自動" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "所有磁區" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "USB Loader GX 功能已解鎖." - -msgid "Alternate DOL" -msgstr "可選擇Alt DOL文件" - -msgid "App Language" -msgstr "語言設定" - -msgid "Apr" -msgstr "四月" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "確定?" - -msgid "Aug" -msgstr "八月" - -msgid "Author:" -msgstr "作者" - -msgid "AutoInit Network" -msgstr "自動檢查網路" - -msgid "BCA Codes Path" -msgstr "BAC 路徑" - -msgid "BETA revisions" -msgstr "測試版本" - -msgid "Back" -msgstr "返回" - -msgid "Back to HBC or Wii Menu" -msgstr "返回 HBC 或 Wii 系統目錄" - -msgid "Back to Loader" -msgstr "返回 Loader" - -msgid "Backgroundmusic" -msgstr "背景音樂" - -msgid "Big thanks to:" -msgstr "非常感謝:" - -msgid "Block IOS Reload" -msgstr "阻止 IOS 重新載入" - -msgid "Boot/Standard" -msgstr "啟動/標準" - -msgid "Boot?" -msgstr "啟動?" - -msgid "Can't be formatted" -msgstr "無法格式化" - -msgid "Can't create directory" -msgstr "無法建立目錄" - -msgid "Can't create file" -msgstr "不能建立檔案" - -msgid "Can't delete:" -msgstr "無法刪除:" - -msgid "Cancel" -msgstr "取消" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "變更路徑" - -msgid "Cheatfile is blank" -msgstr "金手指文件是空的" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "點擊下載封面" - -msgid "Click to change game ID" -msgstr "點擊變更遊戲 ID" - -msgid "Clock" -msgstr "時鐘" - -msgid "Close" -msgstr "關閉" - -msgid "Code Download" -msgstr "金手指下載" - -#, c-format -msgid "Coded by: %s" -msgstr "程式設計者: %s" - -msgid "Coding:" -msgstr "編譯:" - -msgid "Connection lost..." -msgstr "遺失連接..." - -msgid "Console" -msgstr "控制台" - -msgid "Console Locked" -msgstr "控制台已鎖定" - -msgid "Console should be unlocked to modify it." -msgstr "需解鎖以開啟設定功能." - -msgid "Continue to install game?" -msgstr "繼續安裝遊戲?" - -msgid "Controllevel" -msgstr "遊戲分級" - -msgid "Correct Password" -msgstr "密碼正確" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "無法建立 GCT 文件" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "無法啟動 DIP 模塊!" - -msgid "Could not initialize network!" -msgstr "無法啟動網路!" - -msgid "Could not open Disc" -msgstr "無法開啟光碟" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "無法儲存" - -msgid "Cover Download" -msgstr "下載封面" - -msgid "Create" -msgstr "產生" - -msgid "Credits" -msgstr "作者信息" - -msgid "Custom Paths" -msgstr "自定路徑" - -msgid "DOL Path" -msgstr "DOL 路徑" - -msgid "Dec" -msgstr "十二月" - -msgid "Default" -msgstr "預設值" - -msgid "Default Gamesettings" -msgstr "初始化遊戲設定" - -msgid "Default Settings" -msgstr "初始化設定" - -msgid "Delete" -msgstr "刪除" - -msgid "Delete ?" -msgstr "刪除?" - -msgid "Delete Cheat GCT" -msgstr "刪除GCT金手指文件" - -msgid "Delete Cheat TXT" -msgstr "刪除TXT金手指文件" - -msgid "Delete Cover Artwork" -msgstr "刪除封面" - -msgid "Delete Disc Artwork" -msgstr "刪除光碟圖片" - -msgid "Design:" -msgstr "設計者:" - -msgid "Developed by" -msgstr "開發者" - -msgid "Directory does not exist!" -msgstr "目錄不存在" - -msgid "Disc Artwork Download" -msgstr "下載光碟圖像" - -msgid "Disc Artwork Path" -msgstr "光碟圖像路徑" - -msgid "Disc Images" -msgstr "光碟圖像" - -msgid "Display" -msgstr "顯示" - -msgid "Display as a carousel" -msgstr "轉盤模式" - -msgid "Display as a grid" -msgstr "封面牆模式" - -msgid "Display as a list" -msgstr "表單模式" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "確定刪除:" - -msgid "Do you want to apply it now?" -msgstr "要套用設定嗎?" - -msgid "Do you want to change language?" -msgstr "要變更語言嗎?" - -msgid "Do you want to download this theme?" -msgstr "是否要下載這個佈景主題?" - -msgid "Do you want to format:" -msgstr "是否格式化:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "使用這個已知是正確的 Alt DOL 文件?" - -msgid "Do you wish to update/download all language files?" -msgstr "更新/下載語言文件?" - -msgid "Done!" -msgstr "完成" - -msgid "Download" -msgstr "下載" - -msgid "Download Boxart image?" -msgstr "下載封面圖片?" - -msgid "Download Discart image?" -msgstr "下載光碟圖片?" - -msgid "Download Now" -msgstr "現在下載" - -msgid "Download failed." -msgstr "下載失敗" - -msgid "Download finished" -msgstr "下載完成" - -msgid "Download request failed." -msgstr "下載請求失敗" - -msgid "Downloading Page List:" -msgstr "下載主題預覽圖片" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "檔案下載中" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "下載圖片" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "錯誤" - -msgid "ERROR:" -msgstr "錯誤:" - -msgid "ERROR: Can't set up theme." -msgstr "錯誤:無法設定佈景主題" - -msgid "Error" -msgstr "錯誤" - -msgid "Error !" -msgstr "錯誤 !" - -msgid "Error 002 fix" -msgstr "修正002錯誤" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "讀取光碟錯誤" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "檔案傳輸過程錯誤" - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "錯誤..." - -msgid "Error:" -msgstr "錯誤:" - -msgid "Extracting files..." -msgstr "提取文件..." - -msgid "FAT: Use directories" -msgstr "使用目錄" - -msgid "Failed formating" -msgstr "格式化失敗" - -msgid "Failed to extract." -msgstr "提取失敗" - -msgid "Failed to open partition" -msgstr "磁區開啟失敗" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "二月" - -msgid "File not found." -msgstr "找不到該檔案" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "正在完成安裝...完成!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "按鍵規則" - -msgid "Format" -msgstr "格式化" - -msgid "Formatting, please wait..." -msgstr "格式化中, 請稍候..." - -msgid "Free Space" -msgstr "剩餘空間" - -msgid "Full Shutdown" -msgstr "關機" - -msgid "GCT Cheatcodes Path" -msgstr "金手指檔案路徑" - -msgid "GCT File created" -msgstr "GCT 檔案已產生" - -msgid "GUI Settings" -msgstr "介面設定" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "無法在任何子目錄找到 GXtheme.cfg 檔案" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "遊戲語言" - -msgid "Game Load" -msgstr "遊戲載入設定" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "遊戲容量" - -msgid "Game Sound Mode" -msgstr "遊戲聲音模式" - -msgid "Game Sound Volume" -msgstr "遊戲聲音音量" - -msgid "Game is already installed:" -msgstr "已安裝過遊戲:" - -msgid "Game partition" -msgstr "遊戲磁區" - -msgid "Games" -msgstr "遊戲數量" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "主選單" - -msgid "Homebrew Apps Path" -msgstr "HBC 應用程式路徑" - -msgid "Homebrew Launcher" -msgstr "HBC 應用程式" - -msgid "Hour" -msgstr "小時制" - -msgid "How do you want to update?" -msgstr "是否執行更新?" - -msgid "How to Shutdown?" -msgstr "關機選項?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "若無WiFi連線,按1以取得WiiTDB.zip檔案之網址" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "正在接收文件 %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "正在接收文件 %0.2fMB" - -msgid "Initializing Network" -msgstr "正在啟動網路" - -msgid "Insert Disk" -msgstr "插入光碟" - -msgid "Insert a Wii Disc!" -msgstr "插入 Wii 光碟!" - -msgid "Insert an SD-Card to save." -msgstr "插入 SD 卡以儲存." - -msgid "Insert an SD-Card to use this option." -msgstr "插入 SD 卡使用此功能." - -msgid "Install" -msgstr "安裝" - -msgid "Install Error!" -msgstr "安裝錯誤!" - -msgid "Install a game" -msgstr "安裝遊戲" - -msgid "Install partitions" -msgstr "安裝磁區" - -msgid "Installing content... Ok!" -msgstr "正在安裝內容...完成" - -msgid "Installing game:" -msgstr "正在安裝遊戲:" - -msgid "Installing ticket... Ok!" -msgstr "安裝 ticket... 完成!" - -msgid "Installing title... Ok!" -msgstr "安裝 title... 完成!" - -msgid "Installing wad" -msgstr "安裝 WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "請將這些訊息傳送至開發小組以幫助本軟體開發" - -msgid "Jan" -msgstr "一月" - -msgid "July" -msgstr "七月" - -msgid "June" -msgstr "六月" - -msgid "Keep" -msgstr "保留" - -msgid "Keyboard" -msgstr "鍵盤" - -msgid "Language File" -msgstr "語言檔案" - -msgid "Language change:" -msgstr "變更語言為:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "語言路徑已變更" - -msgid "Load" -msgstr "載入" - -#, c-format -msgid "Load file from: %s ?" -msgstr "檔案載入位置: %s" - -msgid "Load this DOL as alternate DOL?" -msgstr "載入這個 DOL 作為替代 DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "正在載入預設語言" - -msgid "Loading standard music." -msgstr "正在載入預設音樂" - -msgid "Lock Console" -msgstr "鎖定控制台" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "三月" - -msgid "Mark new games" -msgstr "標示新遊戲" - -msgid "May" -msgstr "五月" - -msgid "Missing files" -msgstr "缺少的文件" - -msgid "Mount DVD drive" -msgstr "掛載DVD光碟" - -msgid "Music Loop Mode" -msgstr "音樂循環模式" - -msgid "Music Volume" -msgstr "音量" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "新光碟已檢查" - -msgid "No" -msgstr "否" - -msgid "No Cheatfile found" -msgstr "金手指文件沒找到" - -msgid "No DOL file found on disc." -msgstr "光碟中未找到 DOL 文件." - -msgid "No SD-Card inserted!" -msgstr "未插入 SD 卡!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "沒有選擇金手指" - -msgid "No data could be read." -msgstr "無法讀取數據" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "沒有文件缺少!" - -msgid "No new updates." -msgstr "沒有可用更新" - -msgid "No themes found on the site." -msgstr "在網站上找不到主題" - -msgid "Not a WAD file." -msgstr "不是 WAD 文件." - -msgid "Not a Wii Disc" -msgstr "不是 Wii 的光碟" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "剩餘記憶體不足." - -msgid "Not enough free space!" -msgstr "剩餘空間不足!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "未支援的格式" - -msgid "Nov" -msgstr "十一月" - -msgid "OFF" -msgstr "關閉" - -msgid "OK" -msgstr "確定" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "十月" - -msgid "Official Site:" -msgstr "官方網址:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "親子控制" - -msgid "Partition" -msgstr "磁區" - -msgid "Password" -msgstr "密碼" - -msgid "Password Changed" -msgstr "密碼已變更" - -msgid "Password has been changed" -msgstr "密碼已被變更" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "複製這個鏈接到瀏覽器來下載 WiiTDB.zip 文件." - -msgid "Patch Country Strings" -msgstr "修改國別設定" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "從列表中選取" - -msgid "Play Count" -msgstr "執行次數" - -msgid "Play Next" -msgstr "執行下一個" - -msgid "Play Previous" -msgstr "執行上一個" - -msgid "Playing Music:" -msgstr "播放音樂" - -msgid "Please wait..." -msgstr "請稍候..." - -msgid "Power off the Wii" -msgstr "關閉 Wii 主機" - -msgid "Prompts Buttons" -msgstr "顯示校正" - -msgid "Published by" -msgstr "發布者" - -msgid "Quick Boot" -msgstr "快速啟動" - -msgid "Reading WAD data... Ok!" -msgstr "讀取 WAD 數據... 完成!" - -msgid "Receiving file from:" -msgstr "正在接收檔案來源:" - -msgid "Released" -msgstr "發表" - -msgid "Reload SD" -msgstr "重新載入 SD 卡" - -msgid "Remove update" -msgstr "移除更新" - -msgid "Rename Game on WBFS" -msgstr "變更WBFS上的遊戲名稱" - -msgid "Reset BG Music" -msgstr "重置 BG 音樂" - -msgid "Reset Playcounter" -msgstr "重置執行次數" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "正在重新啟動" - -msgid "Return" -msgstr "返回" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "返回 Wii 主目錄" - -msgid "Rumble" -msgstr "震動" - -msgid "SFX Volume" -msgstr "音效音量" - -msgid "Save" -msgstr "儲存" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "儲存遊戲列表至" - -msgid "Saved" -msgstr "已儲存" - -msgid "Screensaver" -msgstr "螢幕保護" - -msgid "Select" -msgstr "選取" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "選擇一個 DOL" - -msgid "Sept" -msgstr "九月" - -msgid "Set Search-Filter" -msgstr "關鍵字篩選" - -msgid "Settings" -msgstr "設定" - -msgid "Shutdown System" -msgstr "關閉系統" - -msgid "Shutdown to Idle" -msgstr "進入待機狀態" - -msgid "Sort alphabetically" -msgstr "以字母順序排列" - -msgid "Sort by rank" -msgstr "按職級排序" - -msgid "Sort order by most played" -msgstr "以執行次數排列" - -msgid "Sound" -msgstr "音效設定" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "特別感謝" - -msgid "Success" -msgstr "成功" - -msgid "Success:" -msgstr "成功:" - -msgid "Successfully Saved" -msgstr "儲存成功" - -msgid "Successfully Updated" -msgstr "更新已完成" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "已更新成功,感謝 www.techjawa.com" - -msgid "Successfully deleted:" -msgstr "成功的刪除:" - -msgid "Successfully extracted theme." -msgstr "成功獲取主題." - -msgid "Successfully installed:" -msgstr "成功安裝:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT 金手指文件路徑" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "已進入的目錄不存在。你想要創建一個目錄嗎?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "佈景主題下載路徑" - -msgid "Theme Downloader" -msgstr "佈景主題下載" - -msgid "Theme Path" -msgstr "佈景主題路徑" - -msgid "Theme Title:" -msgstr "佈景主題標題" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "剩餘時間:" - -msgid "Title Launcher" -msgstr "系統頻道" - -msgid "Titles from WiiTDB" -msgstr "從 WiiTDB 中顯示遊戲名稱" - -msgid "Tooltips" -msgstr "提示信息" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "傳輸失敗" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "找不到 USB 設備" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX 被鎖定" - -msgid "Uninstall" -msgstr "移除" - -msgid "Uninstall Game" -msgstr "刪除遊戲" - -msgid "Uninstall Menu" -msgstr "刪除選單" - -msgid "Uninstalling wad" -msgstr "移除 WAD" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "解鎖以進行設定" - -msgid "Unsupported format, try to extract manually." -msgstr "不支援的格式,嘗試手動提取。" - -msgid "Update" -msgstr "更新" - -msgid "Update All" -msgstr "升級所有檔案" - -msgid "Update DOL" -msgstr "僅更新主程式" - -msgid "Update Files" -msgstr "更新檔案" - -msgid "Update Path" -msgstr "更新路徑" - -msgid "Update all Language Files" -msgstr "更新所有語言檔案" - -msgid "Update failed" -msgstr "更新失敗" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "正在更新語言檔案:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "已更新安裝在Homebrew目錄的ZIP檔案" - -msgid "VIDTV Patch" -msgstr "VIDTV 修改" - -#, c-format -msgid "Version: %s" -msgstr "版本: %s" - -msgid "Video Mode" -msgstr "影像格式" - -msgid "WIP Patches Path" -msgstr "WIP 補丁路徑" - -msgid "Waiting for USB Device" -msgstr "等待 USB 設備" - -msgid "Waiting..." -msgstr "等待中..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "更新何者?" - -msgid "WiFi Features" -msgstr "WiFi功能設定" - -msgid "Wii Menu" -msgstr "Wii系統選單" - -msgid "Wii Settings" -msgstr "Wii主機設定" - -msgid "WiiTDB Files" -msgstr "WiiTDB檔案" - -msgid "WiiTDB Path" -msgstr "WiiTDB路徑" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "光碟機藍光" - -msgid "Wrong Password" -msgstr "密碼錯誤" - -msgid "Yes" -msgstr "是" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "選擇你要格式化的磁區" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "鏈接已寫入 %sWiiTDB_URL.txt 文件." - -msgid "and translaters for language files updates" -msgstr "和所有語言包更新的翻譯者" - -msgid "available" -msgstr "可取得" - -msgid "does not exist!" -msgstr "不存在!" - -msgid "does not exist! Loading game without cheats." -msgstr "不存在!載入遊戲但不啟用金手指" - -msgid "files left" -msgstr "剩下的檔案" - -msgid "files not found on the server!" -msgstr "伺服器中無此檔案!" - -msgid "for FAT/NTFS support" -msgstr "FAT/NTFS 支持" - -msgid "for Ocarina" -msgstr "的 金手指" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "設置 WiiTDB 與封面檔案存放空間" - -msgid "for diverse patches" -msgstr "的多種修正" - -msgid "for his awesome tool LibWiiGui" -msgstr "的優秀工具 LibWiiGui" - -msgid "for hosting the themes" -msgstr "主要的主題" - -msgid "for hosting the update files" -msgstr "設置更新檔案存放空間" - -msgid "for the USB Loader source" -msgstr "與釋出的原始碼" - -msgid "formatted!" -msgstr "完成格式化!" - -msgid "free" -msgstr "剩餘" - -msgid "not set" -msgstr "未設定" - -msgid "of" -msgstr "的" - -msgid "seconds left" -msgstr "剩餘秒數" - -#~ msgid "Install 1:1 Copy" -#~ msgstr "安裝用 1:1 複製" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (全年齡)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (7歲以上)" - -#~ msgid "1 hour" -#~ msgstr "1 小時" - -#~ msgid "10 min" -#~ msgstr "10 分鐘" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (12歲以上)" - -#~ msgid "20 min" -#~ msgstr "20 分鐘" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (16歲以上)" - -#~ msgid "3 min" -#~ msgstr "3 分鐘" - -#~ msgid "30 min" -#~ msgstr "30 分鐘" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (18歲以上成人)" - -#~ msgid "5 min" -#~ msgstr "5 分鐘" - -#~ msgid "An Error occured" -#~ msgstr "發生一個錯誤" - -#~ msgid "Anti" -#~ msgstr "防止" - -#~ msgid "Are you sure you want to enable Parent Control?" -#~ msgstr "您確定要啟用家長控制?" - -#~ msgid "AutoPatch" -#~ msgstr "自動修改" - -#~ msgid "Both" -#~ msgstr "全部" - -#~ msgid "Checking for Updates" -#~ msgstr "檢查軟件最新版本" - -#~ msgid "Console Default" -#~ msgstr "主機預設值" - -#~ msgid "Customs/Original" -#~ msgstr "自製/原始" - -#~ msgid "Disc Default" -#~ msgstr "光碟預設" - -#~ msgid "DiskFlip" -#~ msgstr "光碟滑動" - -#~ msgid "Downloading" -#~ msgstr "正在下載" - -#~ msgid "Dutch" -#~ msgstr "荷蘭文" - -#~ msgid "English" -#~ msgstr "英文" - -#~ msgid "French" -#~ msgstr "法文" - -#~ msgid "GAMEID_Gamename" -#~ msgstr "GAMEID_遊戲名稱" - -#~ msgid "Game ID" -#~ msgstr "遊戲 ID" - -#~ msgid "Game Region" -#~ msgstr "遊戲區碼" - -#~ msgid "Gamename [GAMEID]" -#~ msgstr "遊戲名稱 [GAMEID]" - -#~ msgid "German" -#~ msgstr "德文" - -#~ msgid "Invalid PIN code" -#~ msgstr "無效的 PIN 碼" - -#~ msgid "Italian" -#~ msgstr "意大利文" - -#~ msgid "Japanese" -#~ msgstr "日文" - -#~ msgid "Korean" -#~ msgstr "韓文" - -#~ msgid "Left" -#~ msgstr "左" - -#~ msgid "Like SysMenu" -#~ msgstr "同系統選單" - -#~ msgid "Load From SD/USB" -#~ msgstr "從 SD/USB 載入" - -#~ msgid "Locked" -#~ msgstr "已鎖定" - -#~ msgid "Loop Directory" -#~ msgstr "重複路徑" - -#~ msgid "Loop Music" -#~ msgstr "重複音樂" - -#~ msgid "Loop Sound" -#~ msgstr "重複音樂" - -#~ msgid "Neither" -#~ msgstr "皆不顯示" - -#~ msgid "Next" -#~ msgstr "往後" - -#~ msgid "None" -#~ msgstr "沒有" - -#~ msgid "Normal" -#~ msgstr "一般" - -#~ msgid "ON" -#~ msgstr "開啟" - -#~ msgid "Only Customs" -#~ msgstr "只顯示自製" - -#~ msgid "Only Original" -#~ msgstr "只顯示原始" - -#~ msgid "Only for Install" -#~ msgstr "安裝遊戲時" - -#~ msgid "Original/Customs" -#~ msgstr "原始/自製" - -#~ msgid "Parental Control disabled" -#~ msgstr "關閉親子控制" - -#~ msgid "Play Once" -#~ msgstr "播放一次" - -#~ msgid "Prev" -#~ msgstr "往前" - -#~ msgid "Random Directory Music" -#~ msgstr "隨機選取音樂" - -#~ msgid "Right" -#~ msgstr "右" - -#~ msgid "SChinese" -#~ msgstr "簡體中文" - -#~ msgid "Sound+BGM" -#~ msgstr "音樂+音效" - -#~ msgid "Sound+Quiet" -#~ msgstr "音樂+靜音" - -#~ msgid "Spanish" -#~ msgstr "西班牙文" - -#~ msgid "System Default" -#~ msgstr "系統預設值" - -#~ msgid "TChinese" -#~ msgstr "繁體中文" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "WAD 已安裝,但文件無法從 SD 卡中刪除。" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "WAD 安裝失敗,錯誤號 %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "不能打開剛下載的 WAD 文件 (%s)." - -#~ msgid "Unlock Parental Control" -#~ msgstr "解鎖家長控制" - -#~ msgid "Unlocked" -#~ msgstr "已解鎖" - -#~ msgid "Update to" -#~ msgstr "升級至" - -#~ msgid "Updating" -#~ msgstr "正在更新" - -#~ msgid "Updating Language Files..." -#~ msgstr "正在更新語言檔案..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "正在更新 WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "寬螢幕校正" - -#~ msgid "You don't have Parental Control enabled. If you wish to use Parental Control, enable it in the Wii Settings." -#~ msgstr "家長控制已鎖定。如果要解除 Wii 被鎖住的功能,您必須要先至控制台解除家長控制。" - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s 可能無法正確啟動,也許您的系統目錄不是最新的。" - -#~ msgid "BCA Codes Path changed" -#~ msgstr "BAC 路徑已變更" - -#~ msgid "Back to Wii Menu" -#~ msgstr "返回 Wii 系統目錄" - -#~ msgid "Channels" -#~ msgstr "頻道" - -#~ msgid "Checking existing artwork" -#~ msgstr "檢查已存在的插圖" - -#~ msgid "Confirm" -#~ msgstr "確認" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "找不到 WBFS 磁區." - -#~ msgid "Could not open WBFS partition" -#~ msgstr "無法打開 WBFS 磁區" - -#~ msgid "Could not read the disc." -#~ msgstr "無法讀取光碟." - -#~ msgid "Could not set USB." -#~ msgstr "無法設置 USB." - -#~ msgid "Cover Path Changed" -#~ msgstr "封面路徑已變更" - -#~ msgid "DOL path changed" -#~ msgstr "DOL 路徑已變更" - -#~ msgid "Disc Path Changed" -#~ msgstr "光碟圖像路徑已變更" - -#~ msgid "Display favorites" -#~ msgstr "我的最愛模式" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "是否等待 30 秒後重試?" - -#~ msgid "Enable Parental Control" -#~ msgstr "啟用親子控制" - -#~ msgid "Force" -#~ msgstr "強制" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "金手指檔案路徑已變更" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "HBC 應用程式路徑已變更" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "插入 SD 卡以下載封面." - -#~ msgid "Install not possible" -#~ msgstr "無法安裝" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "圖片格式錯誤,可能它的尺寸不是 4 的倍數." - -#~ msgid "Network init error" -#~ msgstr "網路啟動錯誤" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "找不到 .dol 或 .elf 文件" - -#~ msgid "No Favorites" -#~ msgstr "沒有收藏記錄" - -#~ msgid "No USB Device" -#~ msgstr "沒有 USB 設備" - -#~ msgid "No USB Device found." -#~ msgstr "找不到 USB 設備." - -#~ msgid "No WBFS or FAT/NTFS partition found" -#~ msgstr "找不到 WBFS 和 FAT/NTFS 磁區中的遊戲" - -#~ msgid "Normal Covers" -#~ msgstr "普通封面" - -#~ msgid "Not Found" -#~ msgstr "沒找到" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "不是 DOL/ELF 文件." - -#~ msgid "Reset to standard BGM?" -#~ msgstr "重置回標準 BG 音樂" - -#~ msgid "Save Failed" -#~ msgstr "儲存失敗" - -#~ msgid "Selected DOL" -#~ msgstr "已選擇 DOL" - -#~ msgid "Standard" -#~ msgstr "預設" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXT 金手指文件路徑已變更" - -#~ msgid "Theme Download Path changed" -#~ msgstr "佈景主題下載路徑已變更" - -#~ msgid "Theme Path Changed" -#~ msgstr "佈景主題路徑已變更" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX 只能執行 Hermes CIO rev4!請確認您安裝的版本是 rev4!" - -#~ msgid "Update Path changed." -#~ msgstr "更新路徑已變更" - -#~ msgid "WIP Patches Path changed" -#~ msgstr "WIP 補丁路徑已更新" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB路徑已變更" - -#~ msgid "You are about to delete " -#~ msgstr "您即將刪除" - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "你選擇顯示收藏夾但裡面還沒有任何收藏" - -#~ msgid "You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible." -#~ msgstr "您正在使用 NTFS 文件系統。由於可能一個錯誤寫入到一個 NTFS 分區,這時候是無法安裝遊戲的。" - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "載入的影像有問題" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "不存在!檔案錯誤" - -#~ msgid "file left" -#~ msgstr "剩餘文件" diff --git a/Languages/thai.lang b/Languages/thai.lang deleted file mode 100644 index e6ed4bea..00000000 --- a/Languages/thai.lang +++ /dev/null @@ -1,1498 +0,0 @@ -# USB Loader GX language source file. -# thai.lang - r826 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: Nitro_subzero \n" -"Language-Team: Nitro_subzero\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " บันทึก Wad เป็น:" - -msgid " could not be downloaded." -msgstr " ไม่สามารถดาวน์โหลดได้" - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " ถูกบันทึกแล้ว ข้อความยังไม่ถูกตรวจสอบ บางส่วนของโค๊ดอาจไม่สามารถทำงานได้ ถ้าคุณพบปัญหา เปิดโปรแกรมแก้ไขข้อความ เพื่อข้อมูลเพิ่มเติม." - -msgid " is not on the server." -msgstr " ไม่อยู่บนแม่ข่าย" - -msgid "2D Cover Path" -msgstr "ที่เก็บ ปก 2D" - -msgid "3D Cover Path" -msgstr "ที่เก็บ ปก 3D" - -msgid "3D Covers" -msgstr "หน้าปก 3D" - -msgid ">> Deleting tickets..." -msgstr ">> ลบ Tickets..." - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> ลบ tickets...ผิดพลาด ! " - -msgid ">> Deleting tickets...Ok! " -msgstr ">> ลบ tickets...สำเร็จ ! " - -msgid ">> Deleting title ...ERROR! " -msgstr ">> ลบ Title...ผิดพลาด ! " - -msgid ">> Deleting title ...Ok!" -msgstr ">> ลบ Title...สำเร็จ ! " - -msgid ">> Deleting title contents..." -msgstr ">> ลบเนื้อหา Title..." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> ลบเนื้อหา Title...ผิดพลาด ! " - -msgid ">> Deleting title contents...Ok!" -msgstr ">> ลบเนื้อหา Title...สำเร็จ ! " - -msgid ">> Deleting title..." -msgstr ">> ลบ Title..." - -msgid ">> Finishing installation..." -msgstr ">> ติดตั้งเสร็จแล้ว..." - -msgid ">> Installing content #" -msgstr ">> กำลังติดตั้ง เนื้อหา #" - -msgid ">> Installing ticket..." -msgstr ">> กำลังติดตั้ง ticket..." - -msgid ">> Installing title..." -msgstr ">> กำลังติดตั้ง title..." - -msgid ">> Reading WAD data..." -msgstr ">> กำลังอ่านข้อมูล WAD..." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> กำลังอ่านข้อมูล WAD...ผิดพลาด ! " - -msgid ">> Reading WAD data...Ok!" -msgstr ">> กำลังอ่านข้อมูล WAD...สำเร็จ !" - -msgid "AUTO" -msgstr "อัตโนมัติ" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "ความสามารถทั้งหมดของ USB Loader GX ถูกเปิดให้ใช้." - -msgid "Alternate DOL" -msgstr "เปลี่ยน DOL " - -msgid "App Language" -msgstr "ภาษาของโปรแกรม" - -msgid "Apr" -msgstr "เมษ." - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "แน่ใจหรือไม่ ?" - -msgid "Aug" -msgstr "สค." - -msgid "Author:" -msgstr "ผู้แต่ง:" - -msgid "AutoInit Network" -msgstr "ทำการเชื่อมต่อเครือข่าย" - -msgid "BCA Codes Path" -msgstr "" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "ย้อนกลับ" - -msgid "Back to HBC or Wii Menu" -msgstr "กลับไป HBC หรือ เมนู Wii" - -msgid "Back to Loader" -msgstr "กลับไปที่ Loader" - -msgid "Backgroundmusic" -msgstr "ดนตรีเบื้องหลัง" - -msgid "Big thanks to:" -msgstr "ขอขอบคุณ:" - -msgid "Block IOS Reload" -msgstr "โหลดบล๊อค IOS อีกครั้ง" - -msgid "Boot/Standard" -msgstr "บูต/มาตราฐาน" - -msgid "Boot?" -msgstr "บูต?" - -msgid "Can't be formatted" -msgstr "ไม่สามารถฟอร์แมตได้" - -msgid "Can't create directory" -msgstr "ไม่สามารถสร้างไดเรคทอรี่ได้" - -msgid "Can't create file" -msgstr "สร้างไฟล์ไม่ได้" - -msgid "Can't delete:" -msgstr "ไม่สามารถลบได้:" - -msgid "Cancel" -msgstr "ยกเลิก" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "ไฟล์สูตรโกง ว่างเปล่า" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "กดเพื่อดาวน์โหลดหน้าปก" - -msgid "Click to change game ID" -msgstr "กดเพื่อเปลี่ยน ID เกมส์" - -msgid "Clock" -msgstr "นาฬิกา" - -msgid "Close" -msgstr "ปิด" - -msgid "Code Download" -msgstr "ดาวน์โหลดโค๊ด" - -#, c-format -msgid "Coded by: %s" -msgstr "โค๊ดโดย: %s" - -msgid "Coding:" -msgstr "โค๊ด:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "คอนโซล" - -msgid "Console Locked" -msgstr "คอนโซลถูกล๊อค" - -msgid "Console should be unlocked to modify it." -msgstr "ปลดล๊อคคอนโซลก่อน ถึงจะทำการเปลี่ยนแปลงได้" - -msgid "Continue to install game?" -msgstr "ทำต่อ เพื่อติดตั้งเกมส์?" - -msgid "Controllevel" -msgstr "ระดับการควบคุม" - -msgid "Correct Password" -msgstr "รหัสผ่านถูกต้อง" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "ไม่สามารถสร้างไฟล์ GCT" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "ไม่สามารถเปิดใช้โมดูล DIP ได้ !" - -msgid "Could not initialize network!" -msgstr "ไม่สามารถเชื่อมต่อกับเครือข่ายได้ !" - -msgid "Could not open Disc" -msgstr "เปิดจากแผ่นไม่ได้ !" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "บันทึกไม่ได้" - -msgid "Cover Download" -msgstr "ดาวน์โหลดปก" - -msgid "Create" -msgstr "สร้าง" - -msgid "Credits" -msgstr "เครดิต" - -msgid "Custom Paths" -msgstr "กำหนด ที่เก็บ" - -msgid "DOL Path" -msgstr "ที่เก็บ DOL" - -msgid "Dec" -msgstr "ธค." - -msgid "Default" -msgstr "ค่าแรกกำหนด" - -msgid "Default Gamesettings" -msgstr "ค่าแรกกำหนด" - -msgid "Default Settings" -msgstr "ค่าแรกกำหนด" - -msgid "Delete" -msgstr "ลบ" - -msgid "Delete ?" -msgstr "ลบ ?" - -msgid "Delete Cheat GCT" -msgstr "ลบไฟล์โกงเกมส์" - -msgid "Delete Cheat TXT" -msgstr "ลบ Cheat TXT" - -msgid "Delete Cover Artwork" -msgstr "ลบ ภาพกล่อง" - -msgid "Delete Disc Artwork" -msgstr "ลบ ภาพแผ่น" - -msgid "Design:" -msgstr "ออกแบบ:" - -msgid "Developed by" -msgstr "พัฒนาโดย " - -msgid "Directory does not exist!" -msgstr "ไม่พบไดเรคทอรี่นี้ !" - -msgid "Disc Artwork Download" -msgstr "ดาวน์โหลดภาพแผ่น" - -msgid "Disc Artwork Path" -msgstr "ที่เก็บ ภาพแผ่น" - -msgid "Disc Images" -msgstr "ภาพแผ่น" - -msgid "Display" -msgstr "การแสดงผล" - -msgid "Display as a carousel" -msgstr "แสดงผลแบบ ม้าหมุน" - -msgid "Display as a grid" -msgstr "แสดงผลแบบ ตาราง" - -msgid "Display as a list" -msgstr "แสดงผลแบบ รายการ" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "ต้องการที่จะลบใช่ไหม:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "ต้องการจะเปลี่ยนภาษา ?" - -msgid "Do you want to download this theme?" -msgstr "ต้องการดาวน์โหลดธีมนี้ ?" - -msgid "Do you want to format:" -msgstr "ต้องการฟอร์แมต:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "ต้องการจะใช้ alt DOL เฉพาะที่รู้ว่าถูกต้อง?" - -msgid "Do you wish to update/download all language files?" -msgstr "ต้องการอัพเดทหรือดาวน์โหลด ไฟล์ภาษา ทั้งหมด?" - -msgid "Done!" -msgstr "เสร็จ!" - -msgid "Download" -msgstr "ดาวน์โหลด" - -msgid "Download Boxart image?" -msgstr "ดาวน์โหลดภาพกล่อง ?" - -msgid "Download Discart image?" -msgstr "ดาวน์โหลดภาพแผ่น ?" - -msgid "Download Now" -msgstr "เริ่มการดาวน์โหลด" - -msgid "Download failed." -msgstr "ดาวน์โหลดไม่ได้" - -msgid "Download finished" -msgstr "ดาวน์โหลดเสร็จแล้ว" - -msgid "Download request failed." -msgstr "ดาวน์โหลดไม่ได้" - -msgid "Downloading Page List:" -msgstr "รายการที่กำลังดาวน์โหลด:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "กำลังดาวน์โหลดไฟล์:" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "ภาพที่กำลังดาวน์โหลด:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "ผิดพลาด" - -msgid "ERROR:" -msgstr "ผิดพลาด:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "ผิดพลาด" - -msgid "Error !" -msgstr "ผิดพลาด !" - -msgid "Error 002 fix" -msgstr "แก้ไข Error002" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "อ่านแผ่นไม่ได้" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "ผิดพลาดขณะรับส่งข้อมูล" - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "ผิดพลาด..." - -msgid "Error:" -msgstr "ผิดพลาด:" - -msgid "Extracting files..." -msgstr "กำลังขยายไฟล์..." - -msgid "FAT: Use directories" -msgstr "" - -msgid "Failed formating" -msgstr "ฟอร์แมตไม่ได้" - -msgid "Failed to extract." -msgstr "ขยายไฟล์ไม่ได้" - -msgid "Failed to open partition" -msgstr "ไม่สามารถเข้าถึงพาร์ทิชั่นได้" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "กพ." - -msgid "File not found." -msgstr "ไม่พบไฟล์" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "การติดตั้งเสร็จแล้ว !" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "กลับ-X" - -msgid "Format" -msgstr "ฟอร์แมต" - -msgid "Formatting, please wait..." -msgstr "กำลังฟอร์แมต,รอสักครู่..." - -msgid "Free Space" -msgstr "พื้นที่ว่าง" - -msgid "Full Shutdown" -msgstr "ปิดอย่างสมบรูณ์" - -msgid "GCT Cheatcodes Path" -msgstr "ที่เก็บ สูตรโกง" - -msgid "GCT File created" -msgstr "ไฟล์ GCT ถูกสร้าง" - -msgid "GUI Settings" -msgstr "ปรับแต่งหน้าจอ" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "ภาษาเกมส์" - -msgid "Game Load" -msgstr "โหลดเกมส์" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "ขนาดของเกมส์" - -msgid "Game Sound Mode" -msgstr "โหมดเสียงในเกมส์" - -msgid "Game Sound Volume" -msgstr "ระดับเสียงในเกมส์" - -msgid "Game is already installed:" -msgstr "เกมส์นี้ถูกติดตั้งอยู่แล้ว:" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "เกมส์" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "เมนู HOME" - -msgid "Homebrew Apps Path" -msgstr "ที่เก็บโปรแกรม Homebrew" - -msgid "Homebrew Launcher" -msgstr "Homebrew Launcher" - -msgid "Hour" -msgstr "ชั่วโมง" - -msgid "How do you want to update?" -msgstr "ต้องการอัพเดทแบบไหน ?" - -msgid "How to Shutdown?" -msgstr "ต้องการปิดแบบไหน ?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "ถ้าไม่มี Wifi กด 1 เพื่อแสดง URL สำหรับดาวน์โหลด WiiTDB.zip" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "ดาวน์โหลดไฟล์ %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "ดาวน์โหลดไฟล์ %0.2fMB" - -msgid "Initializing Network" -msgstr "เชื่อมต่อเครือข่าย" - -msgid "Insert Disk" -msgstr "ใส่แผ่น" - -msgid "Insert a Wii Disc!" -msgstr "ใส่แผ่น Wii !" - -msgid "Insert an SD-Card to save." -msgstr "ใส่ SD card เพื่อบันทึก" - -msgid "Insert an SD-Card to use this option." -msgstr "ใส่ SD card เพื่อใช้ตัวเลือกนี้ " - -msgid "Install" -msgstr "ติดตั้ง" - -msgid "Install Error!" -msgstr "ผิดพลาดขณะติดตั้ง!" - -msgid "Install a game" -msgstr "ติดตั้งเกมส์" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "ติดตั้งเนื้อหา... สำเร็จ!" - -msgid "Installing game:" -msgstr "กำลังติดตั้งเกมส์:" - -msgid "Installing ticket... Ok!" -msgstr "ติดตั้ง ticket... สำเร็จ!" - -msgid "Installing title... Ok!" -msgstr "ติดตั้ง Title... สำเร็จ!" - -msgid "Installing wad" -msgstr "ติดตั้ง WAD" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "ดูเหมือนว่าคุณมีข้อมูลที่จำเป็นต่อการพัฒนาโปรแกรม กรุณาส่งข้อมูลนั้นให้ทีมพัฒนาด้วย." - -msgid "Jan" -msgstr "มค." - -msgid "July" -msgstr "กค." - -msgid "June" -msgstr "มิย." - -msgid "Keep" -msgstr "เก็บ" - -msgid "Keyboard" -msgstr "แป้นพิมพ์" - -msgid "Language File" -msgstr "ไฟล์ภาษา" - -msgid "Language change:" -msgstr "เปลี่ยนภาษา:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "ที่เก็บไฟล์ภาษาถูกเปลี่ยนแปลง" - -msgid "Load" -msgstr "โหลด" - -#, c-format -msgid "Load file from: %s ?" -msgstr "โหลดไฟล์จาก: %s ?" - -msgid "Load this DOL as alternate DOL?" -msgstr "โหลด DOL นี้เป็น alternate DOL?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "โหลดภาษามาตราฐาน." - -msgid "Loading standard music." -msgstr "โหลดเพลงมาตราฐาน" - -msgid "Lock Console" -msgstr "ล๊อค Console" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "มีค." - -msgid "Mark new games" -msgstr "" - -msgid "May" -msgstr "พค." - -msgid "Missing files" -msgstr "ไฟล์ที่หาไม่พบ" - -msgid "Mount DVD drive" -msgstr "เชื่อม DVD ไดร์ฟ" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "ความดังเสียงเพลง" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "พบแผ่นเกมส์ใหม่" - -msgid "No" -msgstr "ไม่" - -msgid "No Cheatfile found" -msgstr "ไม่พบไฟล์โกงเกมส์" - -msgid "No DOL file found on disc." -msgstr "ไม่มีไฟล์ DOL ในแผ่น" - -msgid "No SD-Card inserted!" -msgstr "ไม่ได้เสียบ SD card!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "ไม่ได้เลือกการโกงเกมส์ไว้" - -msgid "No data could be read." -msgstr "ไม่มีข้อมูลที่อ่านไม่ได้" - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "ไม่มีไฟล์ที่หายไป" - -msgid "No new updates." -msgstr "ไม่มีไฟล์ Update ตัวใหม่" - -msgid "No themes found on the site." -msgstr "ไม่พบธีมบนเวบไซต์" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "ไม่ใช่แผ่นเกมส์ Wii" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "มีหน่วยความจำเหลือไม่พอ" - -msgid "Not enough free space!" -msgstr "มีที่ว่างเหลือไม่พอ !" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "ไม่รองรับรูปแบบไฟล์นี้" - -msgid "Nov" -msgstr "พย." - -msgid "OFF" -msgstr "ปิด" - -msgid "OK" -msgstr "ตกลง" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "ตค." - -msgid "Official Site:" -msgstr "เวบไซต์อย่างเป็นทางการ:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "กำหนดอายุ" - -msgid "Partition" -msgstr "พาร์ติชั่น" - -msgid "Password" -msgstr "รหัสผ่าน" - -msgid "Password Changed" -msgstr "รหัสผ่านถูกเปลี่ยนแปลง" - -msgid "Password has been changed" -msgstr "รหัสผ่านถูกเปลี่ยนแปลง" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "วางในเวบบราวเซอร์เพื่อดึงข้อมูล WiiTDB.zip" - -msgid "Patch Country Strings" -msgstr "แก้อักขระประเทศ" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "เลือกจากรายการ" - -msgid "Play Count" -msgstr "จำนวนที่เล่น" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "รอสักครู่" - -msgid "Power off the Wii" -msgstr "ปิดเครื่อง Wii" - -msgid "Prompts Buttons" -msgstr "ปุ่มเตรียมตัว" - -msgid "Published by" -msgstr "เผยแพร่โดย" - -msgid "Quick Boot" -msgstr "บูตแบบเร็ว" - -msgid "Reading WAD data... Ok!" -msgstr "อ่านข้อมูล WAD... สำเร็จ!" - -msgid "Receiving file from:" -msgstr "ได้รับไฟล์จาก:" - -msgid "Released" -msgstr "ปล่อย" - -msgid "Reload SD" -msgstr "โหลด SD ใหม่" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "เปลี่ยนชื่อเกมส์บน WBFS" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "เคลียร์การนับจำนวนที่เล่น" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "รีสตารท์..." - -msgid "Return" -msgstr "กลับ" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "กลับไปที่เมนู Wii" - -msgid "Rumble" -msgstr "สั่น" - -msgid "SFX Volume" -msgstr "ความดังของ SFX" - -msgid "Save" -msgstr "บันทึก" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "บันทึกรายชื่อเกมส์ไปที่" - -msgid "Saved" -msgstr "บันทึกแล้ว" - -msgid "Screensaver" -msgstr "รักษาหน้าจอ" - -msgid "Select" -msgstr "" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "เลือก DOL" - -msgid "Sept" -msgstr "กย." - -msgid "Set Search-Filter" -msgstr "กำหนดเงื่อนไขการค้นหา" - -msgid "Settings" -msgstr "กำหนดค่า" - -msgid "Shutdown System" -msgstr "ปิดระบบ" - -msgid "Shutdown to Idle" -msgstr "เข้าโหมด Idle" - -msgid "Sort alphabetically" -msgstr "เรียงตามตัวอักษร" - -msgid "Sort by rank" -msgstr "เรียงตามอันดับ" - -msgid "Sort order by most played" -msgstr "เรียงตามความถี่ในการเล่น" - -msgid "Sound" -msgstr "เสียง" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "ขอขอบคุณอย่างสูง:" - -msgid "Success" -msgstr "สำเร็จ" - -msgid "Success:" -msgstr "สำเร็จ:" - -msgid "Successfully Saved" -msgstr "บันทึกสำเร็จ" - -msgid "Successfully Updated" -msgstr "อัพเดทสำเร็จ" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "ลบสำเร็จ:" - -msgid "Successfully extracted theme." -msgstr "ขยายไฟล์ธีมสำเร็จ." - -msgid "Successfully installed:" -msgstr "ติดตั้งสำเร็จ:" - -msgid "TXT Cheatcodes Path" -msgstr "ที่เก็บ TXTCheatcodes" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "ไม่พบไดเรคทอรี่นี้ ต้องการสร้างใหม่รึไม่ ?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "ตำแหน่งที่ดาวน์โหลดธีม" - -msgid "Theme Downloader" -msgstr "ตัวช่วยดาวน์โหลดธีม" - -msgid "Theme Path" -msgstr "ที่อยู่ Theme" - -msgid "Theme Title:" -msgstr "ชื่อธีม:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "เหลือเวลาอีก:" - -msgid "Title Launcher" -msgstr "Title Launcher" - -msgid "Titles from WiiTDB" -msgstr "Title จาก WiiTDB" - -msgid "Tooltips" -msgstr "คำแนะนำ" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "ถ่ายโอนไม่ได้" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "ไม่พบอุปกรณ์ USB" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX 5 ถูกป้องกัน" - -msgid "Uninstall" -msgstr "ถอนการติดตั้ง" - -msgid "Uninstall Game" -msgstr "ถอนการติดตั้ง" - -msgid "Uninstall Menu" -msgstr "ถอนการติดตั้ง" - -msgid "Uninstalling wad" -msgstr "ถอนการติดตั้ง wad" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "ปลดล๊อค Console ก่อน เพื่อใช้ตัวเลือกนี้" - -msgid "Unsupported format, try to extract manually." -msgstr "ไม่สนับสนุนไฟล์นี้ ลองขยายไฟล์เอง" - -msgid "Update" -msgstr "อัพเดท" - -msgid "Update All" -msgstr "อัทเดททั้งหมด" - -msgid "Update DOL" -msgstr "อัพเดท DOL" - -msgid "Update Files" -msgstr "อัพเดทไฟล์" - -msgid "Update Path" -msgstr "ที่อยู่ Update" - -msgid "Update all Language Files" -msgstr "อัพเดทภาษาทั้งหมด" - -msgid "Update failed" -msgstr "อัพเดทล้มเหลว" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "กำลังอัพเดทไฟล์ภาษา:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "อัพโหลดไฟล์ zip ไปที่ไดเรคทอรี่ homebrew" - -msgid "VIDTV Patch" -msgstr "ปรับแก้ VIDTV" - -#, c-format -msgid "Version: %s" -msgstr "เวอร์ชั่น: %s" - -msgid "Video Mode" -msgstr "โหมดการแสดงผลภาพ" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "กำลังรออุปกรณ์ USB" - -msgid "Waiting..." -msgstr "กำลังรอ..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "คุณต้องการอัพเดทอะไร ?" - -msgid "WiFi Features" -msgstr "ความสามารถของ Wi Fi" - -msgid "Wii Menu" -msgstr "เมนู Wii" - -msgid "Wii Settings" -msgstr "การปรับแต่ง Wii" - -msgid "WiiTDB Files" -msgstr "ไฟล์ WiiTDB" - -msgid "WiiTDB Path" -msgstr "ที่อยู่ WiiTDB" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "ความสว่างของ Wii" - -msgid "Wrong Password" -msgstr "รหัสผ่านผิดพลาด" - -msgid "Yes" -msgstr "ใช่" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "URL ของคุณถูกบันทึกใน %sWiiTDB_URL.txt." - -msgid "and translaters for language files updates" -msgstr "และผู้แปลภาษาสำหรับการอัพเดท" - -msgid "available" -msgstr "ว่างอยู่" - -msgid "does not exist!" -msgstr "ไม่มี!" - -msgid "does not exist! Loading game without cheats." -msgstr "ไม่มี! โหลดเกมส์โดยไม่ใช้การโกงเกมส์." - -msgid "files left" -msgstr "ไฟล์ที่ยังเหลือ" - -msgid "files not found on the server!" -msgstr "ไม่พบไฟล์/i บนเซิฟเวอร์!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "สำหรับ Ocarina" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "สำหรับ WiiTDB และ ปก/รูปแผ่นดิสก์" - -msgid "for diverse patches" -msgstr "แก้ diverse" - -msgid "for his awesome tool LibWiiGui" -msgstr "สำหรับสุดยอด tool ของเค้า LibWiiGui" - -msgid "for hosting the themes" -msgstr "สำหรับให้ฝากธีม" - -msgid "for hosting the update files" -msgstr "สำหรับที่เก็บไฟล์อัพเดท" - -msgid "for the USB Loader source" -msgstr "สำหรับรหัสโปรแกรม USB Loader" - -msgid "formatted!" -msgstr "ฟอร์แมต!" - -msgid "free" -msgstr "ว่างอยู่" - -msgid "not set" -msgstr "ไม่ได้กำหนด" - -msgid "of" -msgstr "จาก" - -msgid "seconds left" -msgstr "วินาทีที่เหลือ" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (ทุกคน)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (เด็ก 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 ชม." - -#~ msgid "10 min" -#~ msgstr "10 นาที" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (วัยรุ่น 12+)" - -#~ msgid "20 min" -#~ msgstr "20 นาที" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (เต็มวัย 16+)" - -#~ msgid "3 min" -#~ msgstr "3 นาที" - -#~ msgid "30 min" -#~ msgstr "30 นาที" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (เฉพาะผู้ใหญ่ 18+)" - -#~ msgid "5 min" -#~ msgstr "5 นาที" - -#~ msgid "An Error occured" -#~ msgstr "พบความผิดพลาด" - -#~ msgid "Anti" -#~ msgstr "ต้าน" - -#~ msgid "AutoPatch" -#~ msgstr "แก้ไขอัตโนมัติ" - -#~ msgid "Both" -#~ msgstr "ทั้งคู่" - -#~ msgid "Checking for Updates" -#~ msgstr "ตรวจสอบหาอัพเดท" - -#~ msgid "Console Default" -#~ msgstr "ค่าตั้งต้นของคอนโซล" - -#~ msgid "Customs/Original" -#~ msgstr "กำหนดเอง/ดั้งเดิม" - -#~ msgid "Disc Default" -#~ msgstr "ค่าตั้งต้นแผ่น" - -#~ msgid "DiskFlip" -#~ msgstr "สลับด้านแผ่น" - -#~ msgid "Downloading" -#~ msgstr "กำลังดาวน์โหลด" - -#~ msgid "Dutch" -#~ msgstr "เนเธอร์แลนด์" - -#~ msgid "English" -#~ msgstr "อังกฤษ" - -#~ msgid "French" -#~ msgstr "ฝรั่งเศส" - -#~ msgid "Game ID" -#~ msgstr "เกมส์ ID" - -#~ msgid "Game Region" -#~ msgstr "โซนของเกมส์" - -#~ msgid "German" -#~ msgstr "เยอรมัน" - -#~ msgid "Italian" -#~ msgstr "อิตาลี" - -#~ msgid "Japanese" -#~ msgstr "ญี่ปุ่น" - -#~ msgid "Korean" -#~ msgstr "เกาหลี" - -#~ msgid "Left" -#~ msgstr "ซ้าย" - -#~ msgid "Like SysMenu" -#~ msgstr "คล้าย SysMenu" - -#~ msgid "Load From SD/USB" -#~ msgstr "โหลดจาก SD/USB" - -#~ msgid "Locked" -#~ msgstr "ล๊อค" - -#~ msgid "Loop Sound" -#~ msgstr "เล่นเสียงซ้ำ" - -#~ msgid "Neither" -#~ msgstr "ไม่ทั้งสอง" - -#~ msgid "Next" -#~ msgstr "ต่อไป" - -#~ msgid "Normal" -#~ msgstr "ปกติ" - -#~ msgid "ON" -#~ msgstr "เปิด" - -#~ msgid "Only Customs" -#~ msgstr "เฉพาะที่ดัดแปลง" - -#~ msgid "Only Original" -#~ msgstr "เฉพาะของแท้" - -#~ msgid "Only for Install" -#~ msgstr "เฉพาะติดตั้งเท่านั้น" - -#~ msgid "Original/Customs" -#~ msgstr "ของแท้/ดัดแปลง" - -#~ msgid "Prev" -#~ msgstr "ที่ผ่านมา" - -#~ msgid "Right" -#~ msgstr "ขวา" - -#~ msgid "SChinese" -#~ msgstr "จีน" - -#~ msgid "Sound+BGM" -#~ msgstr "เสียง+BGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "เสียง+เงียบ" - -#~ msgid "Spanish" -#~ msgstr "สเปน" - -#~ msgid "System Default" -#~ msgstr "ค่าเริ่มต้นของระบบ" - -#~ msgid "TChinese" -#~ msgstr "จีนโบราณ" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "ไฟล์ Wad ถูกติดตั้งแล้ว แต่ไม่สามารถลบจาก SD card ได้" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "การติดตั้งไฟล์ Wad ล้มเหลวด้วยข้อผิดพลาด %ld" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "ไม่สามารถเปิดไฟล์ Wad ที่เพิ่งดาวน์โหลดมาได้ (%s)." - -#~ msgid "Unlocked" -#~ msgstr "ปลดล๊อค" - -#~ msgid "Update to" -#~ msgstr "อัพเดทเป็น" - -#~ msgid "Updating" -#~ msgstr "กำลังอัพเดท" - -#~ msgid "Updating Language Files..." -#~ msgstr "กำลังอัพเดทไฟล์ภาษา..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "กำลังอัพเดทไฟล์ WiiTDB.zip" - -#~ msgid "Widescreen Fix" -#~ msgstr "จอกว้าง" - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s : %s อาจทำงานผิดปกติ ถ้าระบบของคุณไม่ทันสมัย" - -#~ msgid "Back to Wii Menu" -#~ msgstr "กลับไป เมนู Wii" - -#~ msgid "Channels" -#~ msgstr "แชนแนล" - -#~ msgid "Checking existing artwork" -#~ msgstr "ตรวจหาอาร์ตเวิรค์" - -#~ msgid "Confirm" -#~ msgstr "ยืนยัน" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "ไม่พบ WBFS พาร์ติชั่น" - -#~ msgid "Could not open WBFS partition" -#~ msgstr "ไม่สามารถเปิด WBFS พาร์ติชั่นได้" - -#~ msgid "Could not read the disc." -#~ msgstr "อ่านแผ่นไม่ได้ !" - -#~ msgid "Could not set USB." -#~ msgstr "ไม่สามารถตั้งค่า USB ได้" - -#~ msgid "Cover Path Changed" -#~ msgstr "ที่เก็บ ปก ถูกเปลี่ยนแปลง" - -#~ msgid "DOL path changed" -#~ msgstr "ที่เก็บ DOL ถูกเปลี่ยนแปลง" - -#~ msgid "Disc Path Changed" -#~ msgstr "ที่เก็บ ภาพแผ่น ถูกเปลี่ยนแปลง" - -#~ msgid "Display favorites" -#~ msgstr "แสดง แบบเกมส์ที่ชอบ" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "ต้องการลองใหม่ทุก 30 วินาที?" - -#~ msgid "Force" -#~ msgstr "บังคับ" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "ที่เก็บ สูตรโกง ถูกเปลี่ยนแปลง" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "ที่เก็บโปรแกรม Homebrew ถูกเปลี่ยนแปลง" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "ใส่ SD card เพื่อดาวน์โหลดภาพ" - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "ดูเหมือนว่าขนาดจะหารด้วย 4 ไม่ลงตัว" - -#~ msgid "Network init error" -#~ msgstr "การเชื่อมต่อเครือข่ายผิดพลาด" - -#~ msgid "No .dol or .elf files found." -#~ msgstr "ไม่พบไฟล์ .dol หรือ .elf" - -#~ msgid "No Favorites" -#~ msgstr "ไม่พบเกมส์ที่ชื่นชอบ" - -#~ msgid "No USB Device" -#~ msgstr "ไม่ได้เสียบอุปกรณ์ USB" - -#~ msgid "No USB Device found." -#~ msgstr "ไม่พบอุปกรณ์ USB" - -#~ msgid "Normal Covers" -#~ msgstr "หน้าปกแบบปกติ" - -#~ msgid "Not Found" -#~ msgstr "ไม่พบ" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "ไม่ใช่ไฟล์ DOL หรือ ELF" - -#~ msgid "Save Failed" -#~ msgstr "การบันทึกไม่สำเร็จ" - -#~ msgid "Selected DOL" -#~ msgstr "DOL ที่เลือก" - -#~ msgid "Standard" -#~ msgstr "มาตราฐาน" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "ที่เก็บ TXTCheatcodes ถูกเปลี่ยนแปลง" - -#~ msgid "Theme Download Path changed" -#~ msgstr "ตำแหน่งที่ดาวน์โหลดธีมเปลี่ยนแปลง" - -#~ msgid "Theme Path Changed" -#~ msgstr "ที่อยู่ Theme ถูกเปลี่ยนแปลง" - -#~ msgid "Update Path changed." -#~ msgstr "ที่อยู่ Update ถูกเปลี่ยน" - -#~ msgid "WiiTDB Path changed." -#~ msgstr "ที่อยู่ WiiTDB ถูกเปลี่ยนแปลง" - -#~ msgid "You are about to delete " -#~ msgstr "คุณกำลังจะลบ " - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "คุณเลือกจะแสดงเกมส์ที่ชอบ แต่คุณไม่ได้กำหนดเกมส์ที่ชื่นชอบไว้" - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "คุณพยายามที่จะโหลดรูปภาพที่เสียหาย" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "ไม่มี! คุณทำให้มันเละไปแล้ว ไอ้โง่ อิอิ." - -#~ msgid "file left" -#~ msgstr "ไฟล์ที่ยังเหลือ" diff --git a/Languages/turkish.lang b/Languages/turkish.lang deleted file mode 100644 index 66faabcd..00000000 --- a/Languages/turkish.lang +++ /dev/null @@ -1,1498 +0,0 @@ -# USB Loader GX language source file. -# turkish.lang - r848 -# don't delete/change this line (é). -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"Last-Translator: omercigingelini\n" -"Language-Team: omercigingelini\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" - -msgid " Wad Saved as:" -msgstr " Kaydedilen Wad:" - -msgid " could not be downloaded." -msgstr " indirilemedi." - -msgid " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." -msgstr " kaydedildi. Metin doğrulanmadı. Bazı kodlar birlikteyken doğru çalışmayabilir. Herhangi bir problem yaşarsanız, daha fazla bilgi için metin dosyasını gerçek bir metin editörüyle açın" - -msgid " is not on the server." -msgstr " sunucuda mevcut değil" - -msgid "2D Cover Path" -msgstr "2D Kapak Yolu" - -msgid "3D Cover Path" -msgstr "3D Kapak Yolu" - -msgid "3D Covers" -msgstr "3B Kapaklar" - -msgid ">> Deleting tickets..." -msgstr ">> Biletler siliniyor" - -msgid ">> Deleting tickets...ERROR! " -msgstr ">> Biletler siliniyor..HATA!" - -msgid ">> Deleting tickets...Ok! " -msgstr ">> Biletler siliniyor..OK!" - -msgid ">> Deleting title ...ERROR! " -msgstr ">> Başlık siliniyor ..HATA!" - -msgid ">> Deleting title ...Ok!" -msgstr ">> Başlık siliniyor ..Ok!" - -msgid ">> Deleting title contents..." -msgstr ">> Başlık içeriği siliniyor.." - -msgid ">> Deleting title contents...ERROR! " -msgstr ">> Başlık içeriği siliniyor..HATA!" - -msgid ">> Deleting title contents...Ok!" -msgstr ">> Başlık içeriği siliniyor..Ok!" - -msgid ">> Deleting title..." -msgstr ">> Başlık siliniyor.." - -msgid ">> Finishing installation..." -msgstr ">> Kurulum bitiriliyor.." - -msgid ">> Installing content #" -msgstr ">> Kurulan başlık # " - -msgid ">> Installing ticket..." -msgstr ">> Bilet kuruluyor.." - -msgid ">> Installing title..." -msgstr ">> Başlık kuruluyor.." - -msgid ">> Reading WAD data..." -msgstr ">> WAD Bilgisi okunuyor.." - -msgid ">> Reading WAD data...ERROR! " -msgstr ">> WAD Bilgisi okunuyor..HATA!" - -msgid ">> Reading WAD data...Ok!" -msgstr ">> WAD Bilgisi okunuyor..OK!" - -msgid "AUTO" -msgstr "OTOMATIK" - -msgid "All images downloaded successfully." -msgstr "" - -msgid "All partitions" -msgstr "" - -msgid "All the features of USB Loader GX are unlocked." -msgstr "USB Loader GX'in tüm özellikleri kilitli." - -msgid "Alternate DOL" -msgstr "Alternatif DOL" - -msgid "App Language" -msgstr "Program Lisani" - -msgid "Apr" -msgstr "Nis" - -msgid "Are you sure you want to lock USB Loader GX?" -msgstr "" - -msgid "Are you sure you want to reset?" -msgstr "" - -msgid "Are you sure?" -msgstr "Emin misiniz?" - -msgid "Aug" -msgstr "Ağu" - -msgid "Author:" -msgstr "Yazar:" - -msgid "AutoInit Network" -msgstr "Ağı ototanımla" - -msgid "BCA Codes Path" -msgstr "BCA Kod Yolu" - -msgid "BETA revisions" -msgstr "" - -msgid "Back" -msgstr "Geri" - -msgid "Back to HBC or Wii Menu" -msgstr "HBC veya Wii Menüye dönüş" - -msgid "Back to Loader" -msgstr "Yükleyiciye dönüş" - -msgid "Backgroundmusic" -msgstr "Arkaplan müziği" - -msgid "Big thanks to:" -msgstr "Teşekkürler:" - -msgid "Block IOS Reload" -msgstr "IOS Yüklemesini Engelle" - -msgid "Boot/Standard" -msgstr "Boot/Standart" - -msgid "Boot?" -msgstr "Başlat?" - -msgid "Can't be formatted" -msgstr "Biçimlendirilemiyor" - -msgid "Can't create directory" -msgstr "Klasör olusturulamiyor" - -msgid "Can't create file" -msgstr "Dosya oluşturulamıyor" - -msgid "Can't delete:" -msgstr "Silinemiyor" - -msgid "Cancel" -msgstr "Iptal" - -msgid "Cannot write to destination." -msgstr "" - -msgid "Change Play Path" -msgstr "" - -msgid "Cheatfile is blank" -msgstr "Hile dosyası boş" - -msgid "Clear" -msgstr "" - -msgid "Click to Download Covers" -msgstr "Kapak Indirmek için Tıklayın" - -msgid "Click to change game ID" -msgstr "Oyun ID sini değiştirmek için tıklayın" - -msgid "Clock" -msgstr "Saat" - -msgid "Close" -msgstr "Kapat" - -msgid "Code Download" -msgstr "Kod İndirme" - -#, c-format -msgid "Coded by: %s" -msgstr "%s tarafından kodlandı" - -msgid "Coding:" -msgstr "Kodlama:" - -msgid "Connection lost..." -msgstr "" - -msgid "Console" -msgstr "Konsol" - -msgid "Console Locked" -msgstr "Konsol Kilitli" - -msgid "Console should be unlocked to modify it." -msgstr "Degiştirmek için konsolun kilidini açmalısın." - -msgid "Continue to install game?" -msgstr "Oyunu kurmaya devam et?" - -msgid "Controllevel" -msgstr "Kontrol seviyesi" - -msgid "Correct Password" -msgstr "Doğru Şifre" - -msgid "Could not connect to the server." -msgstr "" - -msgid "Could not create GCT file" -msgstr "GCT dosyası oluşturulamadı" - -#, c-format -msgid "Could not create path: %s" -msgstr "" - -msgid "Could not find info for this game in the wiitdb.xml." -msgstr "" - -msgid "Could not initialize DIP module!" -msgstr "DIP modülü başlatılamadı!" - -msgid "Could not initialize network!" -msgstr "Ağa bağlanılamadı!" - -msgid "Could not open Disc" -msgstr "Disk açılamadı" - -msgid "Could not open wiitdb.xml." -msgstr "" - -msgid "Could not save." -msgstr "Kaydedilemedi" - -msgid "Cover Download" -msgstr "Kapak Indirme" - -msgid "Create" -msgstr "Oluştur" - -msgid "Credits" -msgstr "Emekçiler" - -msgid "Custom Paths" -msgstr "Kişisel Yollar" - -msgid "DOL Path" -msgstr "DOL Yolu" - -msgid "Dec" -msgstr "Ara" - -msgid "Default" -msgstr "Varsayılan" - -msgid "Default Gamesettings" -msgstr "Varsayılan Oyun ayarları" - -msgid "Default Settings" -msgstr "Varsayılan Ayarlar" - -msgid "Delete" -msgstr "Sil" - -msgid "Delete ?" -msgstr "Silinsin mi?" - -msgid "Delete Cheat GCT" -msgstr "GCT Hile sil" - -msgid "Delete Cheat TXT" -msgstr "TXT Hile sil" - -msgid "Delete Cover Artwork" -msgstr "Kapak Görselini Sil" - -msgid "Delete Disc Artwork" -msgstr "Disk Görselini Sil" - -msgid "Design:" -msgstr "Tasarım:" - -msgid "Developed by" -msgstr "Geliştirme" - -msgid "Directory does not exist!" -msgstr "Klasör bulunamadı!" - -msgid "Disc Artwork Download" -msgstr "Disk Görseli Indirme" - -msgid "Disc Artwork Path" -msgstr "Disk Görsel Yolu" - -msgid "Disc Images" -msgstr "Disk Resimleri" - -msgid "Display" -msgstr "Görüntü" - -msgid "Display as a carousel" -msgstr "Dönel görünüm" - -msgid "Display as a grid" -msgstr "Izgara görünümü" - -msgid "Display as a list" -msgstr "Liste görünümü" - -msgid "Display favorites only" -msgstr "" - -msgid "Do you really want to delete:" -msgstr "Gerçekten silmek istiyor musunuz:" - -msgid "Do you want to apply it now?" -msgstr "" - -msgid "Do you want to change language?" -msgstr "Dili değiştirmek istiyor musunuz?" - -msgid "Do you want to download this theme?" -msgstr "Bu temayı indirmek istiyor musunuz?" - -msgid "Do you want to format:" -msgstr "Formatlamak istiyor musunuz:" - -msgid "Do you want to load this theme?" -msgstr "" - -msgid "Do you want to use the alternate DOL that is known to be correct?" -msgstr "Doğru olduğu bilinen alternatif DOL ü kullanmak ister misiniz?" - -msgid "Do you wish to update/download all language files?" -msgstr "Tüm dil dosyalarını indirmek/güncellemek istiyor musunuz?" - -msgid "Done!" -msgstr "Tamam!" - -msgid "Download" -msgstr "İndir" - -msgid "Download Boxart image?" -msgstr "Kutu resmi indirilsin mi?" - -msgid "Download Discart image?" -msgstr "Disk resmi indirilsin mi?" - -msgid "Download Now" -msgstr "Şimdi indir" - -msgid "Download failed." -msgstr "İndirme başarısız" - -msgid "Download finished" -msgstr "Indirme tamamlandı" - -msgid "Download request failed." -msgstr "İndirme isteği başarısız" - -msgid "Downloading Page List:" -msgstr "İndirilen Sayfa Listesi:" - -msgid "Downloading covers" -msgstr "" - -msgid "Downloading custom Discarts" -msgstr "" - -msgid "Downloading file" -msgstr "Indirilen dosya" - -msgid "Downloading file..." -msgstr "" - -msgid "Downloading image:" -msgstr "İndirilen resim:" - -msgid "Downloading original Discarts" -msgstr "" - -msgid "ERROR" -msgstr "HATA" - -msgid "ERROR:" -msgstr "HATA:" - -msgid "ERROR: Can't set up theme." -msgstr "" - -msgid "Error" -msgstr "Hata" - -msgid "Error !" -msgstr "Hata !" - -msgid "Error 002 fix" -msgstr "Error 002 düzeltmesi" - -msgid "Error opening downloaded file" -msgstr "" - -msgid "Error reading Disc" -msgstr "Disk Okuma Hatası" - -msgid "Error while downloding file" -msgstr "" - -msgid "Error while opening the zip." -msgstr "" - -msgid "Error while transfering data." -msgstr "Veri iletiminde hata." - -msgid "Error while updating USB Loader GX." -msgstr "" - -msgid "Error writing the data." -msgstr "" - -msgid "Error..." -msgstr "Hata..." - -msgid "Error:" -msgstr "Hata:" - -msgid "Extracting files..." -msgstr "Dosyalar çıkarılıyor..." - -msgid "FAT: Use directories" -msgstr "FAT: Klasörleri kullanın" - -msgid "Failed formating" -msgstr "Biçimlendirme başarısız" - -msgid "Failed to extract." -msgstr "Çıkartma başarısız" - -msgid "Failed to open partition" -msgstr "Bölüm açılamadı" - -msgid "Failed updating" -msgstr "" - -msgid "Feb" -msgstr "Şub" - -msgid "File not found." -msgstr "Dosya bulunamadı" - -msgid "Filesize is 0 Byte." -msgstr "" - -msgid "Finishing installation... Ok!" -msgstr "Kurulum bitiriliyor.. OK!" - -msgid "Flat Covers" -msgstr "" - -msgid "Flip-X" -msgstr "Çevir-X" - -msgid "Format" -msgstr "Biçimlendir" - -msgid "Formatting, please wait..." -msgstr "Biçimlendiriliyor, bekleyiniz..." - -msgid "Free Space" -msgstr "Boş Yer" - -msgid "Full Shutdown" -msgstr "Tam Kapama" - -msgid "GCT Cheatcodes Path" -msgstr "GCT Hile Yolu" - -msgid "GCT File created" -msgstr "GCT Dosyası oluşturuldu" - -msgid "GUI Settings" -msgstr "GUI Ayarları" - -msgid "GXtheme.cfg not found in any subfolder." -msgstr "" - -msgid "Game IOS" -msgstr "" - -msgid "Game Language" -msgstr "Oyun Dili" - -msgid "Game Load" -msgstr "Oyun Yükle" - -msgid "Game Lock" -msgstr "" - -msgid "Game Size" -msgstr "Oyun Boyutu" - -msgid "Game Sound Mode" -msgstr "Oyun Ses Modu" - -msgid "Game Sound Volume" -msgstr "Oyun Ses Düzeyi" - -msgid "Game is already installed:" -msgstr "Oyun zaten kurulu:" - -msgid "Game partition" -msgstr "" - -msgid "Games" -msgstr "Oyunlar" - -msgid "GamesLevel" -msgstr "" - -msgid "Gerne:" -msgstr "" - -msgid "Global Settings" -msgstr "" - -msgid "HOME Menu" -msgstr "HOME Menü" - -msgid "Homebrew Apps Path" -msgstr "Homebrew Yazılımlarının Yolu" - -msgid "Homebrew Launcher" -msgstr "Homebrew Başlatıcı" - -msgid "Hour" -msgstr "Saat" - -msgid "How do you want to update?" -msgstr "Nasıl güncellemek istiyorsun?" - -msgid "How to Shutdown?" -msgstr "Nasıl Kapansın?" - -msgid "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" -msgstr "Eğer WiFi yoksa, WiiTDB.zip dosyasını alabileceğiniz URL için 1'e basın" - -#, c-format -msgid "Incoming file %0.2fKB" -msgstr "Gelen dosya %0.2fKB" - -#, c-format -msgid "Incoming file %0.2fMB" -msgstr "Gelen dosya %0.2fMB" - -msgid "Initializing Network" -msgstr "Ağa Bağlanıyor" - -msgid "Insert Disk" -msgstr "Diski Takın" - -msgid "Insert a Wii Disc!" -msgstr "Bir Wii Diski Takın!" - -msgid "Insert an SD-Card to save." -msgstr "Kaydedebilmek için SD takın." - -msgid "Insert an SD-Card to use this option." -msgstr "Bu seçeneği kullanmak için SD takın." - -msgid "Install" -msgstr "Kur" - -msgid "Install Error!" -msgstr "Kurulum Hatasi!" - -msgid "Install a game" -msgstr "Oyun kur" - -msgid "Install partitions" -msgstr "" - -msgid "Installing content... Ok!" -msgstr "İçerik kuruluyor.. OK!" - -msgid "Installing game:" -msgstr "Kurulan oyun:" - -msgid "Installing ticket... Ok!" -msgstr "Bilet kuruluyor.. OK!" - -msgid "Installing title... Ok!" -msgstr "Başlık kuruluyor.. OK!" - -msgid "Installing wad" -msgstr "Wad kuruluyor" - -msgid "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." -msgstr "İşimize yarabilecek bilgilere sahip gibi gözüküyorsunuz. Lütfen bu bilgiyi Geliştirme takımına iletin." - -msgid "Jan" -msgstr "Oca" - -msgid "July" -msgstr "Tem" - -msgid "June" -msgstr "Haz" - -msgid "Keep" -msgstr "Sakla" - -msgid "Keyboard" -msgstr "Klavye" - -msgid "Language File" -msgstr "Dil dosyası" - -msgid "Language change:" -msgstr "Dil değişimi:" - -msgid "Languagefiles Path" -msgstr "" - -msgid "Languagepath changed." -msgstr "Dil dosya yolu değişti." - -msgid "Load" -msgstr "Yükle" - -#, c-format -msgid "Load file from: %s ?" -msgstr "Dosya %s 'ten yüklensin mi?" - -msgid "Load this DOL as alternate DOL?" -msgstr "Bu DOL alternatif DOL olarak mı yüklensin?" - -msgid "Loading default theme." -msgstr "" - -msgid "Loading standard language." -msgstr "Standart dil yükleniyor." - -msgid "Loading standard music." -msgstr "Standart müzik yükleniyor." - -msgid "Lock Console" -msgstr "Konsolu Kilitle" - -msgid "Lock USB Loader GX" -msgstr "" - -msgid "Mar" -msgstr "" - -msgid "Mark new games" -msgstr "Yeni oyunlari imle" - -msgid "May" -msgstr "" - -msgid "Missing files" -msgstr "Kayıp dosyalar" - -msgid "Mount DVD drive" -msgstr "DVD sürücüsü bağla" - -msgid "Music Loop Mode" -msgstr "" - -msgid "Music Volume" -msgstr "Ses Seviyesi" - -msgid "Network is not initiated." -msgstr "" - -msgid "New Disc Detected" -msgstr "Yeni Disk Bulundu" - -msgid "No" -msgstr "Hayır" - -msgid "No Cheatfile found" -msgstr "Hile dosyası bulunamadı" - -msgid "No DOL file found on disc." -msgstr "Diskte DOL dosyası bulunamadı" - -msgid "No SD-Card inserted!" -msgstr "SD-Card takılı değil!" - -msgid "No URL or Path specified." -msgstr "" - -msgid "No WBFS or FAT/NTFS/EXT partition found" -msgstr "" - -msgid "No cheats were selected" -msgstr "Hile seçilmedi" - -msgid "No data could be read." -msgstr "Hiç veri okunamadı." - -msgid "No favorites selected." -msgstr "" - -msgid "No file missing!" -msgstr "Kayıp dosya yok!" - -msgid "No new updates." -msgstr "Güncelleme yok" - -msgid "No themes found on the site." -msgstr "Bu sitede tema bulunamadı" - -msgid "Not a WAD file." -msgstr "" - -msgid "Not a Wii Disc" -msgstr "Wii Diski Değil" - -msgid "Not a valid URL" -msgstr "" - -msgid "Not a valid URL path" -msgstr "" - -msgid "Not a valid domain" -msgstr "" - -msgid "Not enough free memory." -msgstr "Yeterli boş hafıza yok" - -msgid "Not enough free space!" -msgstr "Yeterli boş yer yok!" - -msgid "Not enough memory." -msgstr "" - -msgid "Not required" -msgstr "" - -msgid "Not supported format!" -msgstr "Desteklenmeyen format!" - -msgid "Nov" -msgstr "Kas" - -msgid "OFF" -msgstr "KAPALI" - -msgid "OK" -msgstr "" - -msgid "Ocarina" -msgstr "" - -msgid "Oct" -msgstr "Eki" - -msgid "Official Site:" -msgstr "Resmi Site:" - -msgid "Offset" -msgstr "" - -msgid "Parental Control" -msgstr "Ebeveyn kontrolü" - -msgid "Partition" -msgstr "Bölüm" - -msgid "Password" -msgstr "Parola" - -msgid "Password Changed" -msgstr "Parola degiştirildi" - -msgid "Password has been changed" -msgstr "Parola değiştirildi" - -msgid "Paste it into your browser to get your WiiTDB.zip." -msgstr "WiiTDP.zip için bu adresi tarayıcıya yapıştırın" - -msgid "Patch Country Strings" -msgstr "Ülke İsimlerini Yamala" - -msgid "Path Changed" -msgstr "" - -msgid "Pick from a list" -msgstr "Listeden seç" - -msgid "Play Count" -msgstr "Oynama Sayısı" - -msgid "Play Next" -msgstr "" - -msgid "Play Previous" -msgstr "" - -msgid "Playing Music:" -msgstr "" - -msgid "Please wait..." -msgstr "Lütfen bekleyin.." - -msgid "Power off the Wii" -msgstr "Wii'yi kapat" - -msgid "Prompts Buttons" -msgstr "Hız ve Butonlar" - -msgid "Published by" -msgstr "Yayıncı" - -msgid "Quick Boot" -msgstr "Hızlı Başlatma" - -msgid "Reading WAD data... Ok!" -msgstr "Wad verisi okunuyor..OK!" - -msgid "Receiving file from:" -msgstr "Dosyanın alındığı yer:" - -msgid "Released" -msgstr "Çıktı" - -msgid "Reload SD" -msgstr "SD'yi yeniden yükle" - -msgid "Remove update" -msgstr "" - -msgid "Rename Game on WBFS" -msgstr "WBFS'deki oyunu yeniden isimlendir" - -msgid "Reset BG Music" -msgstr "" - -msgid "Reset Playcounter" -msgstr "Sayacı sıfırla" - -msgid "Reset to default BGM?" -msgstr "" - -msgid "Restarting..." -msgstr "Yeniden başlatılıyor" - -msgid "Return" -msgstr "Dönüş" - -msgid "Return To" -msgstr "" - -msgid "Return to Wii Menu" -msgstr "Wii Menü ye Dön" - -msgid "Rumble" -msgstr "Titreşim" - -msgid "SFX Volume" -msgstr "Efekt Seviyesi" - -msgid "Save" -msgstr "Kaydet" - -msgid "Save Failed. No device inserted?" -msgstr "" - -msgid "Save Game List to" -msgstr "Oyun Listesini kaydet" - -msgid "Saved" -msgstr "Kaydedildi" - -msgid "Screensaver" -msgstr "Ekran Koruyucu" - -msgid "Select" -msgstr "Seç" - -msgid "Select DOL Offset" -msgstr "" - -msgid "Select a DOL" -msgstr "Bir DOL seç" - -msgid "Sept" -msgstr "Eyl" - -msgid "Set Search-Filter" -msgstr "Arama Filtresi Ayarla" - -msgid "Settings" -msgstr "Ayarlar" - -msgid "Shutdown System" -msgstr "Sistemi Kapat" - -msgid "Shutdown to Idle" -msgstr "Sistemi Beklemeye Al" - -msgid "Sort alphabetically" -msgstr "Alfabetik Diz" - -msgid "Sort by rank" -msgstr "Puana göre diz" - -msgid "Sort order by most played" -msgstr "En çok oynanana göre diz" - -msgid "Sound" -msgstr "Ses" - -msgid "Sound Settings" -msgstr "" - -msgid "Special thanks to:" -msgstr "Özel tesekkürler" - -msgid "Success" -msgstr "Başarılı" - -msgid "Success:" -msgstr "Başarılı:" - -msgid "Successfully Saved" -msgstr "Başarıyla Kaydedildi" - -msgid "Successfully Updated" -msgstr "Başarıyla Güncellendi" - -msgid "Successfully Updated thanks to www.techjawa.com" -msgstr "" - -msgid "Successfully deleted:" -msgstr "Başarıyla silindi:" - -msgid "Successfully extracted theme." -msgstr "Tema başarıyla çıkarıldı." - -msgid "Successfully installed:" -msgstr "Başarıyla kuruldu:" - -msgid "TXT Cheatcodes Path" -msgstr "TXT Hile Yolu" - -msgid "The entered directory does not exist. Would you like to create it?" -msgstr "Girilen klasör mevcut değil. Oluşturmak ister misin?" - -msgid "The wad file was installed" -msgstr "" - -#, c-format -msgid "The wad installation failed with error %i" -msgstr "" - -msgid "Theme Download Path" -msgstr "Tema İndirme Yolu" - -msgid "Theme Downloader" -msgstr "Tema İndirici" - -msgid "Theme Path" -msgstr "Tema Yolu" - -msgid "Theme Title:" -msgstr "Tema Başlığı:" - -msgid "Theme path is changed." -msgstr "" - -msgid "This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning." -msgstr "" - -msgid "This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning." -msgstr "" - -msgid "Time left:" -msgstr "Kalan zaman:" - -msgid "Title Launcher" -msgstr "Başlık Başlatıcı" - -msgid "Titles from WiiTDB" -msgstr "WiiTDB deki Başlıklar" - -msgid "Tooltips" -msgstr "Yardımlar" - -msgid "Transfer failed" -msgstr "" - -msgid "Transfer failed." -msgstr "Transfer başarısız" - -msgid "Trying custom Discarts" -msgstr "" - -msgid "Trying original Discarts" -msgstr "" - -msgid "USB Device not found" -msgstr "USB Aygıtı bulunamadı" - -msgid "USB Loader GX is protected" -msgstr "USB Loader GX koruma altında" - -msgid "Uninstall" -msgstr "Kaldır" - -msgid "Uninstall Game" -msgstr "Oyun Kaldır" - -msgid "Uninstall Menu" -msgstr "Kaldırma Menüsü" - -msgid "Uninstalling wad" -msgstr "Wad Kaldırılıyor" - -msgid "Unknown" -msgstr "" - -msgid "Unlock USB Loader GX" -msgstr "" - -msgid "Unlock console to use this option." -msgstr "Bu seçeneği kullanmak için konsol kilidini açın" - -msgid "Unsupported format, try to extract manually." -msgstr "Desteklenmeyen format,elle çıkartmayı deneyin" - -msgid "Update" -msgstr "Güncelleme" - -msgid "Update All" -msgstr "Hepsini Güncelle" - -msgid "Update DOL" -msgstr "DOL Güncelle" - -msgid "Update Files" -msgstr "Dosyaları Güncelle" - -msgid "Update Path" -msgstr "Güncelleme Yolu" - -msgid "Update all Language Files" -msgstr "Tüm Dil Dosyalarını Güncelle" - -msgid "Update failed" -msgstr "Güncelleme başarısız" - -msgid "Update successfull" -msgstr "" - -msgid "Updating Language Files:" -msgstr "Güncellenen Dil Dosyaları:" - -msgid "Uploaded ZIP file installed to homebrew directory." -msgstr "ZIp dosyası homebrew klasörüne kuruldu" - -msgid "VIDTV Patch" -msgstr "VIDTV Yaması" - -#, c-format -msgid "Version: %s" -msgstr "Vesiyon: %s" - -msgid "Video Mode" -msgstr "Video Modu" - -msgid "WIP Patches Path" -msgstr "" - -msgid "Waiting for USB Device" -msgstr "USB Aygıtı için Bekleniyor" - -msgid "Waiting..." -msgstr "Beklemede..." - -msgid "Warning:" -msgstr "" - -msgid "What do you want to update?" -msgstr "Neyi güncelleme istiyorsun?" - -msgid "WiFi Features" -msgstr "WiFi Özellikleri" - -msgid "Wii Menu" -msgstr "Wii Menü" - -msgid "Wii Settings" -msgstr "Wii Ayarları" - -msgid "WiiTDB Files" -msgstr "WiiTDB Dosyaları" - -msgid "WiiTDB Path" -msgstr "WiiTDB Yaması" - -msgid "WiiTDB is up to date." -msgstr "" - -msgid "Wiilight" -msgstr "" - -msgid "Wrong Password" -msgstr "Yanlış Parola" - -msgid "Yes" -msgstr "Evet" - -msgid "You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk." -msgstr "" - -msgid "You need to select or format a partition" -msgstr "Bir bölüm seçmeniz ya da formatlamanız gerekiyor" - -#, c-format -msgid "Your URL has been saved in %sWiiTDB_URL.txt." -msgstr "URL %sWiiTDB_URL.txt dosyasına kaydedildi" - -msgid "and translaters for language files updates" -msgstr "ve dil dosya güncellemelerinin çevirmenleri" - -msgid "available" -msgstr "mevcut" - -msgid "does not exist!" -msgstr "oluşturulmamış!" - -msgid "does not exist! Loading game without cheats." -msgstr "oluşturulmamış! Oyun hileler olmadan yükleniyor" - -msgid "files left" -msgstr "dosyalar kaldı" - -msgid "files not found on the server!" -msgstr "dosyalar sunucuda bulunamadı!" - -msgid "for FAT/NTFS support" -msgstr "" - -msgid "for Ocarina" -msgstr "Ocarina için" - -msgid "for WiiTDB and hosting covers / disc images" -msgstr "WiiTDB ve kapak/disk resimlerini sunduğu için" - -msgid "for diverse patches" -msgstr "çeşitli yamalar için" - -msgid "for his awesome tool LibWiiGui" -msgstr "LibWiiGui awesome tool için" - -msgid "for hosting the themes" -msgstr "tema sunucusu icin" - -msgid "for hosting the update files" -msgstr "güncelleme dosyalarını sunduğu için" - -msgid "for the USB Loader source" -msgstr "USB Loader kaynak kodu için" - -msgid "formatted!" -msgstr "biçimlendirildi!" - -msgid "free" -msgstr "boş" - -msgid "not set" -msgstr "ayarlanmadı" - -msgid "of" -msgstr "./" - -msgid "seconds left" -msgstr "saniye kaldı" - -#~ msgid "0 (Everyone)" -#~ msgstr "0 (Herkes)" - -#~ msgid "1 (Child 7+)" -#~ msgstr "1 (Çocuk 7+)" - -#~ msgid "1 hour" -#~ msgstr "1 saat" - -#~ msgid "10 min" -#~ msgstr "10 dakika" - -#~ msgid "2 (Teen 12+)" -#~ msgstr "2 (Genç 12+)" - -#~ msgid "20 min" -#~ msgstr "20 dakika" - -#~ msgid "3 (Mature 16+)" -#~ msgstr "3 (Yetişkin 16+)" - -#~ msgid "3 min" -#~ msgstr "3 dakika" - -#~ msgid "30 min" -#~ msgstr "30 dakika" - -#~ msgid "4 (Adults Only 18+)" -#~ msgstr "4 (Sadece Yetişkin 18+)" - -#~ msgid "5 min" -#~ msgstr "5 dakika" - -#~ msgid "An Error occured" -#~ msgstr "Bir Hata oluştu" - -#~ msgid "AutoPatch" -#~ msgstr "OtoYama" - -#~ msgid "Both" -#~ msgstr "İkisi de" - -#~ msgid "Checking for Updates" -#~ msgstr "Güncellemeler kontrol ediliyor" - -#~ msgid "Console Default" -#~ msgstr "Konsol Ayari" - -#~ msgid "Customs/Original" -#~ msgstr "Kişisel/Orjinal" - -#~ msgid "Disc Default" -#~ msgstr "Disk Varsayılanı" - -#~ msgid "DiskFlip" -#~ msgstr "DiskÇevir" - -#~ msgid "Downloading" -#~ msgstr "Indiriliyor" - -#~ msgid "Dutch" -#~ msgstr "Flaman" - -#~ msgid "English" -#~ msgstr "Ingilizce" - -#~ msgid "French" -#~ msgstr "Fransızca" - -#~ msgid "Game ID" -#~ msgstr "Oyun ID" - -#~ msgid "Game Region" -#~ msgstr "Oyun Bölgesi" - -#~ msgid "German" -#~ msgstr "Almanca" - -#~ msgid "Italian" -#~ msgstr "Italyanca" - -#~ msgid "Japanese" -#~ msgstr "Japonca" - -#~ msgid "Korean" -#~ msgstr "Korece" - -#~ msgid "Left" -#~ msgstr "Sol" - -#~ msgid "Like SysMenu" -#~ msgstr "Sistem Menüsü Gibi" - -#~ msgid "Load From SD/USB" -#~ msgstr "SD/USB den yükle" - -#~ msgid "Locked" -#~ msgstr "Kilitlendi" - -#~ msgid "Loop Sound" -#~ msgstr "Döngüdeki Ses" - -#~ msgid "Neither" -#~ msgstr "Hiçbiri" - -#~ msgid "Next" -#~ msgstr "Ileri" - -#~ msgid "ON" -#~ msgstr "AÇIK" - -#~ msgid "Only Customs" -#~ msgstr "Sadece Kişiseller" - -#~ msgid "Only Original" -#~ msgstr "Sadece Orjinal" - -#~ msgid "Only for Install" -#~ msgstr "Sadece Kurulum için" - -#~ msgid "Original/Customs" -#~ msgstr "Orjinal/Kişisel" - -#~ msgid "Prev" -#~ msgstr "Önceki" - -#~ msgid "Right" -#~ msgstr "Sağ" - -#~ msgid "SChinese" -#~ msgstr "Basitleştirilmis Çince" - -#~ msgid "Sound+BGM" -#~ msgstr "Ses+BGM" - -#~ msgid "Sound+Quiet" -#~ msgstr "Ses+Quiet" - -#~ msgid "Spanish" -#~ msgstr "Ispanyolca" - -#~ msgid "System Default" -#~ msgstr "Sistem Varsayılanı" - -#~ msgid "TChinese" -#~ msgstr "Geleneksel Çince" - -#~ msgid "The wad file was installed. But It could not be deleted from the SD card." -#~ msgstr "Wad dosyası kuruldu. Fakat SD den silinemedi" - -#~ msgid "The wad installation failed with error %ld" -#~ msgstr "Wad kurulumu %ld hatasıyla başarısız oldu" - -#~ msgid "Unable to open the wad that was just downloaded (%s)." -#~ msgstr "Az önce indirilen wad açılamıyor(%s)" - -#~ msgid "Unlocked" -#~ msgstr "Kilit açıldı" - -#~ msgid "Update to" -#~ msgstr "Güncellenecek" - -#~ msgid "Updating" -#~ msgstr "Güncelleniyor" - -#~ msgid "Updating Language Files..." -#~ msgstr "Dil Dosyaları Güncelleniyor..." - -#~ msgid "Updating WiiTDB.zip" -#~ msgstr "WiiTDB.zip güncelleniyor" - -#~ msgid "Widescreen Fix" -#~ msgstr "Genişekran Çözümü" - -#~ msgid "%s : %s May not boot correctly if your System Menu is not up to date." -#~ msgstr "%s: Sisteminiz güncel değil %s doğru şekilde başlatılamayabilir" - -#~ msgid "BCA Codes Path changed" -#~ msgstr "BCA Kod Yolu değişti" - -#~ msgid "Back to Wii Menu" -#~ msgstr "Wii Menüye dönüş" - -#~ msgid "Channels" -#~ msgstr "Kanallar" - -#~ msgid "Checking existing artwork" -#~ msgstr "Hazır görsel kontrol ediliyor" - -#~ msgid "Confirm" -#~ msgstr "Onayla" - -#~ msgid "Could not find a WBFS partition." -#~ msgstr "WBFS bölümü bulunamadı" - -#~ msgid "Could not open WBFS partition" -#~ msgstr "WBFS bölümü açılamadı" - -#~ msgid "Could not read the disc." -#~ msgstr "Disk okunamadı" - -#~ msgid "Could not set USB." -#~ msgstr "USB ayarlanamadı" - -#~ msgid "Cover Path Changed" -#~ msgstr "Kapak Yolu Değiştir" - -#~ msgid "DOL path changed" -#~ msgstr "DOL yolu değiştirildi" - -#~ msgid "Disc Path Changed" -#~ msgstr "Disk Yolu Değiştirildi" - -#~ msgid "Display favorites" -#~ msgstr "Görüntü favorileri" - -#~ msgid "Do you want to retry for 30 secs?" -#~ msgstr "30 saniye sonra denemek ister misiniz?" - -#~ msgid "Force" -#~ msgstr "Zorla" - -#~ msgid "GCT Cheatcodes Path changed" -#~ msgstr "GCT Hile Yolu değiştirildi" - -#~ msgid "Homebrew Appspath changed" -#~ msgstr "Homebrew Yazılım Yolu değişti" - -#~ msgid "Insert an SD-Card to download images." -#~ msgstr "Resimleri indirebilmek için SD takın." - -#~ msgid "Most likely it has dimensions that are not evenly divisible by 4." -#~ msgstr "Muhtemelen 4 ile tam bölünemeyen boyutları var." - -#~ msgid "Network init error" -#~ msgstr "Ag baslatma hatasi" - -#~ msgid "No .dol or .elf files found." -#~ msgstr ".dol veya .elf dosyası bulunamadı" - -#~ msgid "No Favorites" -#~ msgstr "Hiç Favori yok" - -#~ msgid "No USB Device" -#~ msgstr "USB Aygıtı yok" - -#~ msgid "No USB Device found." -#~ msgstr "USB Aygıtı bulunamadı" - -#~ msgid "Normal Covers" -#~ msgstr "Normal Kapaklar" - -#~ msgid "Not Found" -#~ msgstr "Bulunamadı" - -#~ msgid "Not a DOL/ELF file." -#~ msgstr "DOL/ELF dosyası değil" - -#~ msgid "Save Failed" -#~ msgstr "Kaydedilemedi" - -#~ msgid "Selected DOL" -#~ msgstr "Seçilen DOL" - -#~ msgid "Standard" -#~ msgstr "Standart" - -#~ msgid "TXT Cheatcodes Path changed" -#~ msgstr "TXT Hile Yolu değiştirildi" - -#~ msgid "Theme Download Path changed" -#~ msgstr "Tema İndirme Yolu değişti" - -#~ msgid "Theme Path Changed" -#~ msgstr "Tema Yolu Değişti" - -#~ msgid "USB Loader GX will only run with Hermes CIOS rev 4! Please make sure you have revision 4 installed!" -#~ msgstr "USB Loader GX sadece Hermes CIOS rev4 ile çalışır! Lütfen rev4 ün yüklü olduğundan emin olun!" - -#~ msgid "Update Path changed." -#~ msgstr "Güncelleme yolu değiştirildi." - -#~ msgid "WiiTDB Path changed." -#~ msgstr "WiiTDB Yolu değişti" - -#~ msgid "You are about to delete " -#~ msgstr "Silmek üzeresiniz" - -#~ msgid "You are choosing to display favorites and you do not have any selected." -#~ msgstr "Favorileri göstermeyi seçtiniz ama hiç seçili yok" - -#~ msgid "You have attempted to load a bad image" -#~ msgstr "Bozuk bir resim yüklemeye çalıştın" - -#~ msgid "does not exist! You Messed something up, Idiot." -#~ msgstr "oluşturulmamış! Saçmaladın, mal." - -#~ msgid "file left" -#~ msgstr "dosya kaldı" diff --git a/Make.config.default b/Make.config.default deleted file mode 100644 index 63e7993a..00000000 --- a/Make.config.default +++ /dev/null @@ -1,12 +0,0 @@ -# -# to use this file rename Make.config.default to Make.config -# or create a new Make.config -# -# you can here add defines -# -# in example i have included a switch to diseble -# the gecko-debug stuff. so also in source gecko.c+gecko.h -# -# NOTE when add, remove or change a define here then a "make clean" is needed -# -CFLAGS += -DNO_DEBUG DDEBUG_WBFS diff --git a/Makefile b/Makefile deleted file mode 100644 index 0582bbf0..00000000 --- a/Makefile +++ /dev/null @@ -1,279 +0,0 @@ -#--------------------------------------------------------------------------------- -# Clear the implicit built in rules -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") -endif - -include $(DEVKITPPC)/wii_rules -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := boot -BUILD := build -SOURCES := source \ - source/libwiigui \ - source/images \ - source/fonts \ - source/sounds \ - source/system \ - source/libs/libwbfs \ - source/language \ - source/mload \ - source/mload/modules \ - source/patches \ - source/usbloader \ - source/xml \ - source/network \ - source/settings \ - source/settings/menus \ - source/prompts \ - source/wad \ - source/banner \ - source/cheats \ - source/homebrewboot \ - source/themes \ - source/menu \ - source/memory \ - source/FileOperations \ - source/ImageOperations \ - source/SoundOperations \ - source/utils \ - source/utils/minizip \ - source/usbloader/wbfs -DATA := data -INCLUDES := source - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- - -CFLAGS = -g -O3 -Wall -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H -CXXFLAGS = -Xassembler -aln=$@.lst $(CFLAGS) -LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80B00000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size --include $(PROJECTDIR)/Make.config - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -lpngu -lpng -lgd -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -lvorbisidec \ - -lmad -lmxml -ljpeg -lzip -lcustomfat -lcustomntfs -lcustomext2fs -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(DEVKITPPC)/lib $(CURDIR) -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- -export PROJECTDIR := $(CURDIR) -export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) -export DEPSDIR := $(CURDIR)/$(BUILD) - -#--------------------------------------------------------------------------------- -# automatically build a list of object files for our project -#--------------------------------------------------------------------------------- -SVNREV := $(shell bash ./svnrev.sh) -export CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -export CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) -ELFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.elf))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin))) -TTFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ttf))) -PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png))) -OGGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.ogg))) -PCMFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.pcm))) -WAVFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.wav))) -DOLFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.dol))) -MP3FILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.mp3))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) - export LD := $(CC) -else - export LD := $(CXX) -endif - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ - $(sFILES:.s=.o) $(SFILES:.S=.o) \ - $(TTFFILES:.ttf=.ttf.o) $(PNGFILES:.png=.png.o) $(addsuffix .o,$(DOLFILES))\ - $(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o) $(MP3FILES:.mp3=.mp3.o) \ - $(WAVFILES:.wav=.wav.o) $(addsuffix .o,$(ELFFILES)) $(CURDIR)/data/magic_patcher.o - -#--------------------------------------------------------------------------------- -# build a list of include paths -#--------------------------------------------------------------------------------- -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(LIBOGC_INC) - -#--------------------------------------------------------------------------------- -# build a list of library paths -#--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) -L$(CURDIR)/source/libs/libfat/ \ - -L$(CURDIR)/source/libs/libntfs/ -L$(CURDIR)/source/libs/libext2fs/ \ - -L$(LIBOGC_LIB) - -export OUTPUT := $(CURDIR)/$(TARGET) -.PHONY: $(BUILD) lang all clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @/bin/bash ./buildtype.sh - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile -# @echo debug... -# start geckoreader.exe - -channel: - @[ -d build ] || mkdir -p build - @/bin/bash ./buildtype.sh FULLCHANNEL - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -lang: - @[ -d build ] || mkdir -p build - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile language - -#--------------------------------------------------------------------------------- -theme: - @[ -d build ] || mkdir -p build - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile language - -#--------------------------------------------------------------------------------- -all: - @[ -d build ] || mkdir -p build - @./buildtype.sh - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile language - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol -#--------------------------------------------------------------------------------- -run: - $(MAKE) - @echo Done building ... - @echo Now Run That Shit ... - - wiiload $(OUTPUT).dol - -#--------------------------------------------------------------------------------- -reload: - wiiload -r $(OUTPUT).dol - -#--------------------------------------------------------------------------------- -release: - $(MAKE) - cp boot.dol ./hbc/boot.dol - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).dol: $(OUTPUT).elf -$(OUTPUT).elf: $(OFILES) - -language: $(wildcard $(PROJECTDIR)/Languages/*.lang) $(wildcard $(PROJECTDIR)/Themes/*.them) -#--------------------------------------------------------------------------------- -# This rule links in binary data with .ttf, .png, and .mp3 extensions -#--------------------------------------------------------------------------------- - -%.elf.o : %.elf - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.dol.o : %.dol - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.ttf.o : %.ttf - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.png.o : %.png - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.ogg.o : %.ogg - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.pcm.o : %.pcm - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.wav.o : %.wav - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.mp3.o : %.mp3 - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.certs.o : %.certs - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.dat.o : %.dat - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.bin.o : %.bin - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.tik.o : %.tik - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - -%.tmd.o : %.tmd - @echo $(notdir $<) - @bin2s -a 32 $< | $(AS) -o $(@) - - - -export PATH := $(PROJECTDIR)/gettext-bin:$(PATH) - -%.pot: $(CFILES) $(CPPFILES) - @echo Updating Languagefiles ... - @touch $(PROJECTDIR)/Languages/$(TARGET).pot - @xgettext -C -cTRANSLATORS --from-code=utf-8 --sort-output --no-wrap --no-location -ktr -o$(PROJECTDIR)/Languages/$(TARGET).pot -p $@ $^ - @echo Updating Themefiles ... - @touch $(PROJECTDIR)/Themes/$(TARGET).pot - @xgettext -C -cTRANSLATORS --from-code=utf-8 -F --no-wrap --add-location -kthInt -kthColor -kthAlign -o$(PROJECTDIR)/Themes/$(TARGET).pot -p $@ $^ - -%.lang: $(PROJECTDIR)/Languages/$(TARGET).pot - @msgmerge -U -N --no-wrap --no-location --backup=none -q $@ $< - @touch $@ - -%.them: $(PROJECTDIR)/Themes/$(TARGET).pot - @msgmerge -U -N --no-wrap --no-location --backup=none -q $@ $< - @touch $@ - --include $(DEPENDS) - -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- diff --git a/Themes/Default.them b/Themes/Default.them deleted file mode 100644 index fafa6b55..00000000 --- a/Themes/Default.them +++ /dev/null @@ -1,405 +0,0 @@ -# USB Loader GX theme source file. -# don't delete/change this line (é). -# ONLY the value before the '-' char needs to be entered in msgstr "" -# not the complete text. -# It is important that the image folder is defined for the images to load. -# The image folder should be in the same folder as the .them file and include the theme images. -msgid "" -msgstr "" -"Project-Id-Version: USB Loader GX\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-26 16:16+0100\n" -"PO-Revision-Date: 2009-10-01 01:00+0200\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Image-Folder: Example\n" -"Last-Themer: Example\n" -"Theme-Team: Example\n" - -msgid "r=0 g=0 b=0 a=255 - prompt windows text color" -msgstr "" - -msgid "r=0 g=0 b=0 a=255 - settings text color" -msgstr "" - -msgid "9 - game list browser page size" -msgstr "" - -msgid "r=0 g=0 b=0 a=255 - game browser list text color" -msgstr "" - -msgid "r=0 g=0 b=0 a=255 - game browser list text color over" -msgstr "" - -msgid "r=55 g=190 b=237 a=255 - carousel game name text color" -msgstr "" - -msgid "0 - game grid layout pos x" -msgstr "" - -msgid "20 - game grid layout pos y" -msgstr "" - -msgid "255 - tooltip alpha" -msgstr "" - -msgid "r=55 g=190 b=237 a=255 - hdd info color" -msgstr "" - -msgid "center - hdd info align ver" -msgstr "" - -msgid "top - hdd info align hor" -msgstr "" - -msgid "0 - hdd info pos x" -msgstr "" - -msgid "400 - hdd info pos y" -msgstr "" - -msgid "r=55 g=190 b=237 a=255 - game count color" -msgstr "" - -msgid "center - game count align ver" -msgstr "" - -msgid "top - game count align hor" -msgstr "" - -msgid "0 - game count pos x" -msgstr "" - -msgid "420 - game count pos y" -msgstr "" - -msgid "16 - install btn pos x" -msgstr "" - -msgid "355 - install btn pos y" -msgstr "" - -msgid "371 - settings btn pos y" -msgstr "" - -msgid "64 - settings btn pos x" -msgstr "" - -msgid "371 - home menu btn pos x" -msgstr "" - -msgid "489 - home menu btn pos x" -msgstr "" - -msgid "355 - power off btn pos y" -msgstr "" - -msgid "576 - power off btn pos x" -msgstr "" - -msgid "160 - sd card btn pos x" -msgstr "" - -msgid "395 - sd card btn pos y" -msgstr "" - -msgid "405 - HBC btn pos y" -msgstr "" - -msgid "410 - HBC btn pos x" -msgstr "" - -msgid "26 - cover/download btn pos x" -msgstr "" - -msgid "58 - cover/download btn pos y" -msgstr "" - -msgid "305 - gameID btn pos y" -msgstr "" - -msgid "68 - gameID btn pos x" -msgstr "" - -msgid "r=138 g=138 b=138 a=240 - clock color" -msgstr "" - -msgid "left - clock align ver" -msgstr "" - -msgid "top - clock align hor" -msgstr "" - -msgid "275 - clock pos x" -msgstr "" - -msgid "275 - clock pos y" -msgstr "" - -msgid "260 - list layout favorite btn pos x" -msgstr "" - -msgid "288 - list layout favorite btn pos x widescreen" -msgstr "" - -msgid "13 - list layout favorite btn pos y" -msgstr "" - -msgid "300 - list layout search btn pos x" -msgstr "" - -msgid "320 - list layout search btn pos x widescreen" -msgstr "" - -msgid "13 - list layout search btn pos x" -msgstr "" - -msgid "340 - list layout abc/sort btn pos x" -msgstr "" - -msgid "352 - list layout abc/sort btn pos x widescreen" -msgstr "" - -msgid "13 - list layout abc/sort btn pos y" -msgstr "" - -msgid "380 - list layout list btn pos x" -msgstr "" - -msgid "384 - list layout list btn pos x widescreen" -msgstr "" - -msgid "13 - list layout list btn pos y" -msgstr "" - -msgid "416 - list layout grid btn pos x widescreen" -msgstr "" - -msgid "420 - list layout grid btn pos x" -msgstr "" - -msgid "13 - list layout grid btn pos y" -msgstr "" - -msgid "448 - list layout carousel btn pos x widescreen" -msgstr "" - -msgid "460 - list layout carousel btn pos x" -msgstr "" - -msgid "13 - list layout carousel btn pos y" -msgstr "" - -msgid "480 - list layout lock btn pos x widescreen" -msgstr "" - -msgid "500 - list layout lock btn pos x" -msgstr "" - -msgid "13 - list layout lock btn pos y" -msgstr "" - -msgid "512 - list layout dvd btn pos x widescreen" -msgstr "" - -msgid "540 - list layout dvd btn pos x" -msgstr "" - -msgid "13 - list layout dvd btn pos y" -msgstr "" - -msgid "280 - game list layout height" -msgstr "" - -msgid "396 - game list layout width" -msgstr "" - -msgid "200 - game list layout pos x" -msgstr "" - -msgid "49 - game list layout pos y" -msgstr "" - -msgid "200 - grid layout favorite btn pos x" -msgstr "" - -msgid "224 - grid layout favorite btn pos x widescreen" -msgstr "" - -msgid "13 - grid layout favorite btn pos y" -msgstr "" - -msgid "240 - grid layout search btn pos x" -msgstr "" - -msgid "256 - grid layout search btn pos x widescreen" -msgstr "" - -msgid "13 - grid layout search btn pos x" -msgstr "" - -msgid "280 - grid layout abc/sort btn pos x" -msgstr "" - -msgid "288 - grid layout abc/sort btn pos x widescreen" -msgstr "" - -msgid "13 - grid layout abc/sort btn pos y" -msgstr "" - -msgid "320 - grid layout list btn pos x" -msgstr "" - -msgid "320 - grid layout list btn pos x widescreen" -msgstr "" - -msgid "13 - grid layout list btn pos y" -msgstr "" - -msgid "352 - grid layout grid btn pos x widescreen" -msgstr "" - -msgid "360 - grid layout grid btn pos x" -msgstr "" - -msgid "13 - grid layout grid btn pos y" -msgstr "" - -msgid "384 - grid layout carousel btn pos x widescreen" -msgstr "" - -msgid "400 - grid layout carousel btn pos x" -msgstr "" - -msgid "13 - grid layout carousel btn pos y" -msgstr "" - -msgid "416 - grid layout lock btn pos x widescreen" -msgstr "" - -msgid "440 - grid layout lock btn pos x" -msgstr "" - -msgid "13 - grid layout lock btn pos y" -msgstr "" - -msgid "448 - grid layout dvd btn pos x widescreen" -msgstr "" - -msgid "480 - grid layout dvd btn pos x" -msgstr "" - -msgid "13 - grid layout dvd btn pos y" -msgstr "" - -msgid "400 - game grid layout height" -msgstr "" - -msgid "640 - game grid layout width" -msgstr "" - -msgid "200 - carousel layout favorite btn pos x" -msgstr "" - -msgid "224 - carousel layout favorite btn pos x widescreen" -msgstr "" - -msgid "13 - carousel layout favorite btn pos y" -msgstr "" - -msgid "240 - carousel layout search btn pos x" -msgstr "" - -msgid "256 - carousel layout search btn pos x widescreen" -msgstr "" - -msgid "13 - carousel layout search btn pos x" -msgstr "" - -msgid "280 - carousel layout abc/sort btn pos x" -msgstr "" - -msgid "288 - carousel layout abc/sort btn pos x widescreen" -msgstr "" - -msgid "13 - carousel layout abc/sort btn pos y" -msgstr "" - -msgid "320 - carousel layout list btn pos x" -msgstr "" - -msgid "320 - carousel layout list btn pos x widescreen" -msgstr "" - -msgid "13 - carousel layout list btn pos y" -msgstr "" - -msgid "352 - carousel layout grid btn pos x widescreen" -msgstr "" - -msgid "360 - carousel layout grid btn pos x" -msgstr "" - -msgid "13 - carousel layout grid btn pos y" -msgstr "" - -msgid "384 - carousel layout carousel btn pos x widescreen" -msgstr "" - -msgid "400 - carousel layout carousel btn pos x" -msgstr "" - -msgid "13 - carousel layout carousel btn pos y" -msgstr "" - -msgid "416 - carousel layout lock btn pos x widescreen" -msgstr "" - -msgid "440 - carousel layout lock btn pos x" -msgstr "" - -msgid "13 - carousel layout lock btn pos y" -msgstr "" - -msgid "448 - carousel layout dvd btn pos x widescreen" -msgstr "" - -msgid "480 - carousel layout dvd btn pos x" -msgstr "" - -msgid "13 - carousel layout dvd btn pos y" -msgstr "" - -msgid "400 - game carousel layout height" -msgstr "" - -msgid "640 - game carousel layout width" -msgstr "" - -msgid "-20 - game carousel layout pos y" -msgstr "" - -msgid "0 - game carousel layout pos x" -msgstr "" - -msgid "1 - show hdd info: 1 for on and 0 for off" -msgstr "" - -msgid "1 - show game count: 1 for on and 0 for off" -msgstr "" - -msgid "r=55 g=190 b=237 a=255 - game id text color" -msgstr "" - -msgid "r=55 g=190 b=237 a=255 - region info text color" -msgstr "" - -msgid "30 - region info text pos x" -msgstr "" - -msgid "68 - region info text pos x" -msgstr "" - -msgid "1 - Enable tooltips: 0 for off and 1 for on" -msgstr "" diff --git a/buildtype.sh b/buildtype.sh deleted file mode 100755 index 22066e27..00000000 --- a/buildtype.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -if [ ! -z "$1" ]; -then - if [ ! -s source/buildtype.h ]; - then - echo "#define $1" > source/buildtype.h - fi -else - if [[ ! -f source/buildtype.h || -s source/buildtype.h ]]; - then - cp /dev/null source/buildtype.h - fi -fi diff --git a/data/app_booter.dol b/data/app_booter.dol deleted file mode 100644 index 62c156fe..00000000 Binary files a/data/app_booter.dol and /dev/null differ diff --git a/data/certs.dat b/data/certs.dat deleted file mode 100644 index 2184107d..00000000 Binary files a/data/certs.dat and /dev/null differ diff --git a/data/haxx.certs b/data/haxx.certs deleted file mode 100644 index 32dd50ca..00000000 Binary files a/data/haxx.certs and /dev/null differ diff --git a/data/magic_patcher.o b/data/magic_patcher.o deleted file mode 100644 index a7de9a03..00000000 Binary files a/data/magic_patcher.o and /dev/null differ diff --git a/data/stub.bin b/data/stub.bin deleted file mode 100644 index 63a37a0b..00000000 Binary files a/data/stub.bin and /dev/null differ diff --git a/gettext-bin/libexpat.dll b/gettext-bin/libexpat.dll deleted file mode 100644 index 13bc7eec..00000000 Binary files a/gettext-bin/libexpat.dll and /dev/null differ diff --git a/gettext-bin/libgettextlib.dll b/gettext-bin/libgettextlib.dll deleted file mode 100644 index 6bc7525b..00000000 Binary files a/gettext-bin/libgettextlib.dll and /dev/null differ diff --git a/gettext-bin/libgettextpo.dll b/gettext-bin/libgettextpo.dll deleted file mode 100644 index 9a9aa3fe..00000000 Binary files a/gettext-bin/libgettextpo.dll and /dev/null differ diff --git a/gettext-bin/libgettextsrc.dll b/gettext-bin/libgettextsrc.dll deleted file mode 100644 index 0d5a5933..00000000 Binary files a/gettext-bin/libgettextsrc.dll and /dev/null differ diff --git a/gettext-bin/libiconv2.dll b/gettext-bin/libiconv2.dll deleted file mode 100644 index fb1ffba3..00000000 Binary files a/gettext-bin/libiconv2.dll and /dev/null differ diff --git a/gettext-bin/libintl3.dll b/gettext-bin/libintl3.dll deleted file mode 100644 index ec11e6b1..00000000 Binary files a/gettext-bin/libintl3.dll and /dev/null differ diff --git a/gettext-bin/msgmerge.exe b/gettext-bin/msgmerge.exe deleted file mode 100644 index dc5a3ffc..00000000 Binary files a/gettext-bin/msgmerge.exe and /dev/null differ diff --git a/gettext-bin/xgettext.exe b/gettext-bin/xgettext.exe deleted file mode 100644 index 590a19b0..00000000 Binary files a/gettext-bin/xgettext.exe and /dev/null differ diff --git a/gui.pnproj b/gui.pnproj deleted file mode 100644 index 55da86f4..00000000 --- a/gui.pnproj +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/gui.pnps b/gui.pnps deleted file mode 100644 index ce6765fe..00000000 --- a/gui.pnps +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/libcustomext2fs/AUTHORS b/libcustomext2fs/AUTHORS new file mode 100644 index 00000000..2291767c --- /dev/null +++ b/libcustomext2fs/AUTHORS @@ -0,0 +1,11 @@ + +Present author and main programmer of ext2fs in alphabetical order: + +Theodore Ts'o + +Many more are contributing to this project. Read it all up at http://e2fsprogs.sourceforge.net/ext2.html + + +Nintendo GameCube/Wii port author: + +Dimok diff --git a/libcustomext2fs/CREDITS b/libcustomext2fs/CREDITS new file mode 100644 index 00000000..32fb026f --- /dev/null +++ b/libcustomext2fs/CREDITS @@ -0,0 +1,9 @@ +First of all thanks goes to everyone who contributed to ext2fs directly or indirectly. +Visit the site to inform yourself who was involved in it http://e2fsprogs.sourceforge.net/ext2.html + +The following people have contributed directly or indirectly +to the Nintendo GameCube/Wii port of ext2fs. + +Michael "Chishm" Chisholm +rodries +Rhys "Shareese" Koedijk \ No newline at end of file diff --git a/libcustomext2fs/LICENSE b/libcustomext2fs/LICENSE new file mode 100644 index 00000000..623b6258 --- /dev/null +++ b/libcustomext2fs/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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 + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/libcustomext2fs/Makefile b/libcustomext2fs/Makefile new file mode 100644 index 00000000..8745416d --- /dev/null +++ b/libcustomext2fs/Makefile @@ -0,0 +1,31 @@ + +default: cube-release wii-release + +all: debug release + +debug: cube-debug wii-debug + +release: cube-release wii-release + +cube-debug: + $(MAKE) -C source PLATFORM=cube BUILD=cube_debug + +wii-debug: + $(MAKE) -C source PLATFORM=wii BUILD=wii_debug + +cube-release: + $(MAKE) -C source PLATFORM=cube BUILD=cube_release + +wii-release: + $(MAKE) -C source PLATFORM=wii BUILD=wii_release + +clean: + $(MAKE) -C source clean + +install: cube-release wii-release + $(MAKE) -C source install + +run: install + $(MAKE) -C example + $(MAKE) -C example run + diff --git a/libcustomext2fs/include/ext2.h b/libcustomext2fs/include/ext2.h new file mode 100644 index 00000000..059e18be --- /dev/null +++ b/libcustomext2fs/include/ext2.h @@ -0,0 +1,99 @@ + /** + * ext2.h - devoptab file routines for EXT2/3/4-based devices. + * + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __EXT2_H_ +#define __EXT2_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* EXT2 cache options */ +#define CACHE_DEFAULT_PAGE_COUNT 8 /* The default number of pages in the cache */ +#define CACHE_DEFAULT_PAGE_SIZE 128 /* The default number of sectors per cache page */ + +/* EXT2 mount flags */ +#define EXT2_FLAG_RW 0x00001 /* Open the filesystem for reading and writing. Without this flag, the filesystem is opened for reading only. */ +#define EXT2_FLAG_FORCE 0x00400 /* Open the filesystem regardless of the feature sets listed in the superblock */ +#define EXT2_FLAG_JOURNAL_DEV_OK 0x01000 /* Only open external journal devices if this flag is set (e.g. ext3/ext4) */ +#define EXT2_FLAG_64BITS 0x20000 /* Use the new style 64-Bit bitmaps. For more information see gen_bitmap64.c */ +#define EXT2_FLAG_PRINT_PROGRESS 0x40000 /* If this flag is set the progress of file operations will be printed to stdout */ +#define EXT2_FLAG_DEFAULT (EXT2_FLAG_RW | EXT2_FLAG_64BITS | EXT2_FLAG_JOURNAL_DEV_OK) + +/** + * Find all EXT2/3/4 partitions on a block device. + * + * @param INTERFACE The block device to search + * @param PARTITIONS (out) A pointer to receive the array of partition start sectors + * + * @return The number of entries in PARTITIONS or -1 if an error occurred (see errno) + * @note The caller is responsible for freeing PARTITIONS when finished with it + */ +int ext2FindPartitions(const DISC_INTERFACE *interface, sec_t **partitions); + +/** + * Mount a EXT2/3/4 partition from a specific sector on a block device. + * + * @param NAME The name to mount the device under (can then be accessed as "NAME:/") + * @param INTERFACE The block device to mount + * @param STARTSECTOR The sector the partition begins at + * @param CACHEPAGECOUNT The total number of pages in the device cache + * @param CACHEPAGESIZE The number of sectors per cache page + * @param FLAGS Additional mounting flags (see above) + * + * @return True if mount was successful, false if no partition was found or an error occurred (see errno) + */ +bool ext2Mount(const char *name, const DISC_INTERFACE *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags); + +/** + * Unmount a EXT2/3/4 partition. + * + * @param NAME The name of mount used in ext2Mount() + */ +void ext2Unmount(const char *name); + +/** + * Get the volume name of a mounted EXT2/3/4 partition. + * + * @param NAME The name of mount + * + * @return The volumes name if successful or NULL if an error occurred (see errno) + */ +const char *ext2GetVolumeName (const char *name); + +/** + * Set the volume name of a mounted EXT2/3/4 partition. + * + * @param NAME The name of mount + * @param VOLUMENAME The new volume name + * + * @return True if mount was successful, false if an error occurred (see errno) + * @note The mount must be write-enabled else this will fail + */ +bool ext2SetVolumeName (const char *name, const char *volumeName); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libcustomext2fs/source/Makefile b/libcustomext2fs/source/Makefile new file mode 100644 index 00000000..c2fabaa2 --- /dev/null +++ b/libcustomext2fs/source/Makefile @@ -0,0 +1,132 @@ +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +ifeq ($(PLATFORM),wii) +include $(DEVKITPPC)/wii_rules +endif + +ifeq ($(PLATFORM),cube) +include $(DEVKITPPC)/gamecube_rules +endif + +#--------------------------------------------------------------------------------- +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +BUILD ?= wii_release +SOURCES := . +INCLUDES := ../include +LIBDIR := ../lib + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +CFLAGS = -O3 -Wall $(MACHDEP) $(INCLUDE) -DGEKKO \ + -DHAVE_UNISTD_H -DHAVE_SYS_STAT_H -DHAVE_SYS_TYPES_H -DHAVE_UTIME_H -DWORDS_BIGENDIAN \ + -DHAVE_ERRNO_H -DHAVE_STRDUP -DHAVE_SYS_RESOURCE_H +CXXFLAGS = $(CFLAGS) +ASFLAGS := -g +export EXT2BIN := $(LIBDIR)/$(PLATFORM)/libext2fs.a + +ifeq ($(BUILD),cube_debug) +CFLAGS += -DDEBUG_GEKKO +CXXFLAGS += -DDEBUG_GEKKO +endif +ifeq ($(BUILD),wii_debug) +CFLAGS += -DDEBUG_GEKKO +CXXFLAGS += -DDEBUG_GEKKO +endif + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export DEPSDIR := $(CURDIR)/$(BUILD) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ + -L$(LIBOGC_LIB) + +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr wii_debug wii_release cube_debug cube_release $(LIBDIR) + +all: $(EXT2BIN) + +install: + cp ../include/ext2.h $(DEVKITPRO)/libogc/include + cp ../lib/wii/libext2fs.a $(DEVKITPRO)/libogc/lib/wii + cp ../lib/cube/libext2fs.a $(DEVKITPRO)/libogc/lib/cube + +wii-install: + cp ../include/ext2.h $(DEVKITPRO)/libogc/include + cp ../lib/wii/libext2fs.a $(DEVKITPRO)/libogc/lib/wii + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(EXT2BIN): $(OFILES) $(LIBDIR)/$(PLATFORM) + @rm -f "../$(EXT2BIN)" + @$(AR) rcs "../$(EXT2BIN)" $(OFILES) + @echo built ... $(notdir $@) + +$(LIBDIR)/$(PLATFORM): + mkdir -p ../$(LIBDIR)/$(PLATFORM) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- + diff --git a/libcustomext2fs/source/alloc.c b/libcustomext2fs/source/alloc.c new file mode 100644 index 00000000..3a8f3328 --- /dev/null +++ b/libcustomext2fs/source/alloc.c @@ -0,0 +1,308 @@ +/* + * alloc.c --- allocate new inodes, blocks for ext2fs + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * Check for uninit block bitmaps and deal with them appropriately + */ +static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, + dgrp_t group) +{ + blk_t i; + blk64_t blk, super_blk, old_desc_blk, new_desc_blk; + int old_desc_blocks; + + if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) || + !(ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT))) + return; + + blk = (group * fs->super->s_blocks_per_group) + + fs->super->s_first_data_block; + + ext2fs_super_and_bgd_loc2(fs, group, &super_blk, + &old_desc_blk, &new_desc_blk, 0); + + if (fs->super->s_feature_incompat & + EXT2_FEATURE_INCOMPAT_META_BG) + old_desc_blocks = fs->super->s_first_meta_bg; + else + old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; + + for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) { + if ((blk == super_blk) || + (old_desc_blk && old_desc_blocks && + (blk >= old_desc_blk) && + (blk < old_desc_blk + old_desc_blocks)) || + (new_desc_blk && (blk == new_desc_blk)) || + (blk == ext2fs_block_bitmap_loc(fs, group)) || + (blk == ext2fs_inode_bitmap_loc(fs, group)) || + (blk >= ext2fs_inode_table_loc(fs, group) && + (blk < ext2fs_inode_table_loc(fs, group) + + fs->inode_blocks_per_group))) + ext2fs_fast_mark_block_bitmap2(map, blk); + else + ext2fs_fast_unmark_block_bitmap2(map, blk); + } + ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); + ext2fs_group_desc_csum_set(fs, group); +} + +/* + * Check for uninit inode bitmaps and deal with them appropriately + */ +static void check_inode_uninit(ext2_filsys fs, ext2fs_inode_bitmap map, + dgrp_t group) +{ + ext2_ino_t i, ino; + + if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) || + !(ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT))) + return; + + ino = (group * fs->super->s_inodes_per_group) + 1; + for (i=0; i < fs->super->s_inodes_per_group; i++, ino++) + ext2fs_fast_unmark_inode_bitmap2(map, ino); + + ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT); + check_block_uninit(fs, fs->block_map, group); +} + +/* + * Right now, just search forward from the parent directory's block + * group to find the next free inode. + * + * Should have a special policy for directories. + */ +errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, + int mode EXT2FS_ATTR((unused)), + ext2fs_inode_bitmap map, ext2_ino_t *ret) +{ + ext2_ino_t dir_group = 0; + ext2_ino_t i; + ext2_ino_t start_inode; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!map) + map = fs->inode_map; + if (!map) + return EXT2_ET_NO_INODE_BITMAP; + + if (dir > 0) + dir_group = (dir - 1) / EXT2_INODES_PER_GROUP(fs->super); + + start_inode = (dir_group * EXT2_INODES_PER_GROUP(fs->super)) + 1; + if (start_inode < EXT2_FIRST_INODE(fs->super)) + start_inode = EXT2_FIRST_INODE(fs->super); + if (start_inode > fs->super->s_inodes_count) + return EXT2_ET_INODE_ALLOC_FAIL; + i = start_inode; + + do { + if (((i - 1) % EXT2_INODES_PER_GROUP(fs->super)) == 0) + check_inode_uninit(fs, map, (i - 1) / + EXT2_INODES_PER_GROUP(fs->super)); + + if (!ext2fs_fast_test_inode_bitmap2(map, i)) + break; + i++; + if (i > fs->super->s_inodes_count) + i = EXT2_FIRST_INODE(fs->super); + } while (i != start_inode); + + if (ext2fs_test_inode_bitmap2(map, i)) + return EXT2_ET_INODE_ALLOC_FAIL; + *ret = i; + return 0; +} + +/* + * Stupid algorithm --- we now just search forward starting from the + * goal. Should put in a smarter one someday.... + */ +errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, + ext2fs_block_bitmap map, blk64_t *ret) +{ + blk64_t i; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!map) + map = fs->block_map; + if (!map) + return EXT2_ET_NO_BLOCK_BITMAP; + if (!goal || (goal >= ext2fs_blocks_count(fs->super))) + goal = fs->super->s_first_data_block; + i = goal; + check_block_uninit(fs, map, + (i - fs->super->s_first_data_block) / + EXT2_BLOCKS_PER_GROUP(fs->super)); + do { + if (((i - fs->super->s_first_data_block) % + EXT2_BLOCKS_PER_GROUP(fs->super)) == 0) + check_block_uninit(fs, map, + (i - fs->super->s_first_data_block) / + EXT2_BLOCKS_PER_GROUP(fs->super)); + + if (!ext2fs_fast_test_block_bitmap2(map, i)) { + *ret = i; + return 0; + } + i++; + if (i >= ext2fs_blocks_count(fs->super)) + i = fs->super->s_first_data_block; + } while (i != goal); + return EXT2_ET_BLOCK_ALLOC_FAIL; +} + +errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, + ext2fs_block_bitmap map, blk_t *ret) +{ + errcode_t retval; + blk64_t val; + retval = ext2fs_new_block2(fs, goal, map, &val); + if (!retval) + *ret = (blk_t) val; + return retval; +} + +/* + * This function zeros out the allocated block, and updates all of the + * appropriate filesystem records. + */ +errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal, + char *block_buf, blk64_t *ret) +{ + errcode_t retval; + blk64_t block; + char *buf = 0; + + if (!block_buf) { + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + block_buf = buf; + } + memset(block_buf, 0, fs->blocksize); + + if (fs->get_alloc_block) { + retval = (fs->get_alloc_block)(fs, goal, &block); + if (retval) + goto fail; + } else { + if (!fs->block_map) { + retval = ext2fs_read_block_bitmap(fs); + if (retval) + goto fail; + } + + retval = ext2fs_new_block2(fs, goal, 0, &block); + if (retval) + goto fail; + } + + retval = io_channel_write_blk64(fs->io, block, 1, block_buf); + if (retval) + goto fail; + + ext2fs_block_alloc_stats2(fs, block, +1); + *ret = block; + +fail: + if (buf) + ext2fs_free_mem(&buf); + return retval; +} + +errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, + char *block_buf, blk_t *ret) +{ + errcode_t retval; + blk64_t val; + retval = ext2fs_alloc_block2(fs, goal, block_buf, &val); + if (!retval) + *ret = (blk_t) val; + return retval; +} + +errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, + int num, ext2fs_block_bitmap map, blk64_t *ret) +{ + blk64_t b = start; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!map) + map = fs->block_map; + if (!map) + return EXT2_ET_NO_BLOCK_BITMAP; + if (!b) + b = fs->super->s_first_data_block; + if (!finish) + finish = start; + if (!num) + num = 1; + do { + if (b+num-1 > ext2fs_blocks_count(fs->super)) + b = fs->super->s_first_data_block; + if (ext2fs_fast_test_block_bitmap_range2(map, b, num)) { + *ret = b; + return 0; + } + b++; + } while (b != finish); + return EXT2_ET_BLOCK_ALLOC_FAIL; +} + +errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish, + int num, ext2fs_block_bitmap map, blk_t *ret) +{ + errcode_t retval; + blk64_t val; + retval = ext2fs_get_free_blocks2(fs, start, finish, num, map, &val); + if(!retval) + *ret = (blk_t) val; + return retval; +} + +void ext2fs_set_alloc_block_callback(ext2_filsys fs, + errcode_t (*func)(ext2_filsys fs, + blk64_t goal, + blk64_t *ret), + errcode_t (**old)(ext2_filsys fs, + blk64_t goal, + blk64_t *ret)) +{ + if (!fs || fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS) + return; + + if (old) + *old = fs->get_alloc_block; + + fs->get_alloc_block = func; +} diff --git a/libcustomext2fs/source/alloc_sb.c b/libcustomext2fs/source/alloc_sb.c new file mode 100644 index 00000000..d5fca3b2 --- /dev/null +++ b/libcustomext2fs/source/alloc_sb.c @@ -0,0 +1,86 @@ +/* + * alloc_sb.c --- Allocate the superblock and block group descriptors for a + * newly initialized filesystem. Used by mke2fs when initializing a filesystem + * + * Copyright (C) 1994, 1995, 1996, 2003 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * This function reserves the superblock and block group descriptors + * for a given block group. It currently returns the number of free + * blocks assuming that inode table and allocation bitmaps will be in + * the group. This is not necessarily the case when the flex_bg + * feature is enabled, so callers should take care! It was only + * really intended for use by mke2fs, and even there it's not that + * useful. In the future, when we redo this function for 64-bit block + * numbers, we should probably return the number of blocks used by the + * super block and group descriptors instead. + * + * See also the comment for ext2fs_super_and_bgd_loc() + */ +int ext2fs_reserve_super_and_bgd(ext2_filsys fs, + dgrp_t group, + ext2fs_block_bitmap bmap) +{ + blk64_t super_blk, old_desc_blk, new_desc_blk; + blk_t used_blks; + int j, old_desc_blocks, num_blocks; + + ext2fs_super_and_bgd_loc2(fs, group, &super_blk, + &old_desc_blk, &new_desc_blk, &used_blks); + + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + old_desc_blocks = fs->super->s_first_meta_bg; + else + old_desc_blocks = + fs->desc_blocks + fs->super->s_reserved_gdt_blocks; + + if (super_blk || (group == 0)) + ext2fs_mark_block_bitmap2(bmap, super_blk); + + if (old_desc_blk) { + if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap) + ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); + for (j=0; j < old_desc_blocks; j++) + if (old_desc_blk + j < ext2fs_blocks_count(fs->super)) + ext2fs_mark_block_bitmap2(bmap, + old_desc_blk + j); + } + if (new_desc_blk) + ext2fs_mark_block_bitmap2(bmap, new_desc_blk); + + if (group == fs->group_desc_count-1) { + num_blocks = (ext2fs_blocks_count(fs->super) - + fs->super->s_first_data_block) % + fs->super->s_blocks_per_group; + if (!num_blocks) + num_blocks = fs->super->s_blocks_per_group; + } else + num_blocks = fs->super->s_blocks_per_group; + + num_blocks -= 2 + fs->inode_blocks_per_group + used_blks; + + return num_blocks ; +} diff --git a/libcustomext2fs/source/alloc_stats.c b/libcustomext2fs/source/alloc_stats.c new file mode 100644 index 00000000..0f276659 --- /dev/null +++ b/libcustomext2fs/source/alloc_stats.c @@ -0,0 +1,106 @@ +/* + * alloc_stats.c --- Update allocation statistics for ext2fs + * + * Copyright (C) 2001 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino, + int inuse, int isdir) +{ + int group = ext2fs_group_of_ino(fs, ino); + +#ifndef OMIT_COM_ERR + if (ino > fs->super->s_inodes_count) { + com_err("ext2fs_inode_alloc_stats2", 0, + "Illegal inode number: %lu", (unsigned long) ino); + return; + } +#endif + if (inuse > 0) + ext2fs_mark_inode_bitmap2(fs->inode_map, ino); + else + ext2fs_unmark_inode_bitmap2(fs->inode_map, ino); + ext2fs_bg_free_inodes_count_set(fs, group, ext2fs_bg_free_inodes_count(fs, group) - inuse); + if (isdir) + ext2fs_bg_used_dirs_count_set(fs, group, ext2fs_bg_used_dirs_count(fs, group) + inuse); + + /* We don't strictly need to be clearing the uninit flag if inuse < 0 + * (i.e. freeing inodes) but it also means something is bad. */ + ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT); + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { + ext2_ino_t first_unused_inode = fs->super->s_inodes_per_group - + ext2fs_bg_itable_unused(fs, group) + + group * fs->super->s_inodes_per_group + 1; + + if (ino >= first_unused_inode) + ext2fs_bg_itable_unused_set(fs, group, group * fs->super->s_inodes_per_group + fs->super->s_inodes_per_group - ino); + ext2fs_group_desc_csum_set(fs, group); + } + + fs->super->s_free_inodes_count -= inuse; + ext2fs_mark_super_dirty(fs); + ext2fs_mark_ib_dirty(fs); +} + +void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse) +{ + ext2fs_inode_alloc_stats2(fs, ino, inuse, 0); +} + +void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse) +{ + int group = ext2fs_group_of_blk2(fs, blk); + +#ifndef OMIT_COM_ERR + if (blk >= ext2fs_blocks_count(fs->super)) { + com_err("ext2fs_block_alloc_stats", 0, + "Illegal block number: %lu", (unsigned long) blk); + return; + } +#endif + if (inuse > 0) + ext2fs_mark_block_bitmap2(fs->block_map, blk); + else + ext2fs_unmark_block_bitmap2(fs->block_map, blk); + ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) - inuse); + ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); + ext2fs_group_desc_csum_set(fs, group); + + ext2fs_free_blocks_count_add(fs->super, -inuse); + ext2fs_mark_super_dirty(fs); + ext2fs_mark_bb_dirty(fs); + if (fs->block_alloc_stats) + (fs->block_alloc_stats)(fs, (blk64_t) blk, inuse); +} + +void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse) +{ + ext2fs_block_alloc_stats2(fs, blk, inuse); +} + +void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs, + void (*func)(ext2_filsys fs, + blk64_t blk, + int inuse), + void (**old)(ext2_filsys fs, + blk64_t blk, + int inuse)) +{ + if (!fs || fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS) + return; + if (old) + *old = fs->block_alloc_stats; + + fs->block_alloc_stats = func; +} diff --git a/libcustomext2fs/source/alloc_tables.c b/libcustomext2fs/source/alloc_tables.c new file mode 100644 index 00000000..1c4532b6 --- /dev/null +++ b/libcustomext2fs/source/alloc_tables.c @@ -0,0 +1,239 @@ +/* + * alloc_tables.c --- Allocate tables for a newly initialized + * filesystem. Used by mke2fs when initializing a filesystem + * + * Copyright (C) 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2fsP.h" + +/* + * This routine searches for free blocks that can allocate a full + * group of bitmaps or inode tables for a flexbg group. Returns the + * block number with a correct offset were the bitmaps and inode + * tables can be allocated continously and in order. + */ +static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, + ext2fs_block_bitmap bmap, int offset, int size, + int elem_size) +{ + int flexbg, flexbg_size; + blk64_t last_blk, first_free = 0; + dgrp_t last_grp; + + flexbg_size = 1 << fs->super->s_log_groups_per_flex; + flexbg = group / flexbg_size; + + if (size > (int) (fs->super->s_blocks_per_group / 8)) + size = (int) fs->super->s_blocks_per_group / 8; + + if (offset) + offset -= 1; + + /* + * Don't do a long search if the previous block + * search is still valid. + */ + if (start_blk && group % flexbg_size) { + if (ext2fs_test_block_bitmap_range2(bmap, start_blk + elem_size, + size)) + return start_blk + elem_size; + } + + start_blk = ext2fs_group_first_block2(fs, flexbg_size * flexbg); + last_grp = group | (flexbg_size - 1); + if (last_grp > fs->group_desc_count) + last_grp = fs->group_desc_count; + last_blk = ext2fs_group_last_block2(fs, last_grp); + + /* Find the first available block */ + if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, 1, bmap, + &first_free)) + return first_free; + + if (ext2fs_get_free_blocks2(fs, first_free + offset, last_blk, size, + bmap, &first_free)) + return first_free; + + return first_free; +} + +errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, + ext2fs_block_bitmap bmap) +{ + errcode_t retval; + blk64_t group_blk, start_blk, last_blk, new_blk, blk; + dgrp_t last_grp = 0; + int j, rem_grps = 0, flexbg_size = 0; + + group_blk = ext2fs_group_first_block2(fs, group); + last_blk = ext2fs_group_last_block2(fs, group); + + if (!bmap) + bmap = fs->block_map; + + if (EXT2_HAS_INCOMPAT_FEATURE(fs->super, + EXT4_FEATURE_INCOMPAT_FLEX_BG) && + fs->super->s_log_groups_per_flex) { + flexbg_size = 1 << fs->super->s_log_groups_per_flex; + last_grp = group | (flexbg_size - 1); + rem_grps = last_grp - group; + if (last_grp > fs->group_desc_count) + last_grp = fs->group_desc_count; + } + + /* + * Allocate the block and inode bitmaps, if necessary + */ + if (fs->stride) { + retval = ext2fs_get_free_blocks2(fs, group_blk, last_blk, + 1, bmap, &start_blk); + if (retval) + return retval; + start_blk += fs->inode_blocks_per_group; + start_blk += ((fs->stride * group) % + (last_blk - start_blk + 1)); + if (start_blk >= last_blk) + start_blk = group_blk; + } else + start_blk = group_blk; + + if (flexbg_size) { + blk64_t prev_block = 0; + + if (group && ext2fs_block_bitmap_loc(fs, group - 1)) + prev_block = ext2fs_block_bitmap_loc(fs, group - 1); + start_blk = flexbg_offset(fs, group, prev_block, bmap, + 0, rem_grps, 1); + last_blk = ext2fs_group_last_block2(fs, last_grp); + } + + if (!ext2fs_block_bitmap_loc(fs, group)) { + retval = ext2fs_get_free_blocks2(fs, start_blk, last_blk, + 1, bmap, &new_blk); + if (retval == EXT2_ET_BLOCK_ALLOC_FAIL) + retval = ext2fs_get_free_blocks2(fs, group_blk, + last_blk, 1, bmap, &new_blk); + if (retval) + return retval; + ext2fs_mark_block_bitmap2(bmap, new_blk); + ext2fs_block_bitmap_loc_set(fs, group, new_blk); + if (flexbg_size) { + dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk); + ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); + ext2fs_free_blocks_count_add(fs->super, -1); + ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT); + ext2fs_group_desc_csum_set(fs, gr); + } + } + + if (flexbg_size) { + blk64_t prev_block = 0; + if (group && ext2fs_inode_bitmap_loc(fs, group - 1)) + prev_block = ext2fs_inode_bitmap_loc(fs, group - 1); + start_blk = flexbg_offset(fs, group, prev_block, bmap, + flexbg_size, rem_grps, 1); + last_blk = ext2fs_group_last_block2(fs, last_grp); + } + + if (!ext2fs_inode_bitmap_loc(fs, group)) { + retval = ext2fs_get_free_blocks2(fs, start_blk, last_blk, + 1, bmap, &new_blk); + if (retval == EXT2_ET_BLOCK_ALLOC_FAIL) + retval = ext2fs_get_free_blocks2(fs, group_blk, + last_blk, 1, bmap, &new_blk); + if (retval) + return retval; + ext2fs_mark_block_bitmap2(bmap, new_blk); + ext2fs_inode_bitmap_loc_set(fs, group, new_blk); + if (flexbg_size) { + dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk); + ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); + ext2fs_free_blocks_count_add(fs->super, -1); + ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT); + ext2fs_group_desc_csum_set(fs, gr); + } + } + + /* + * Allocate the inode table + */ + if (flexbg_size) { + blk64_t prev_block = 0; + if (group && ext2fs_inode_table_loc(fs, group - 1)) + prev_block = ext2fs_inode_table_loc(fs, group - 1); + if (last_grp == fs->group_desc_count) + rem_grps = last_grp - group; + group_blk = flexbg_offset(fs, group, prev_block, bmap, + flexbg_size * 2, + fs->inode_blocks_per_group * + rem_grps, + fs->inode_blocks_per_group); + last_blk = ext2fs_group_last_block2(fs, last_grp); + } + + if (!ext2fs_inode_table_loc(fs, group)) { + retval = ext2fs_get_free_blocks2(fs, group_blk, last_blk, + fs->inode_blocks_per_group, + bmap, &new_blk); + if (retval) + return retval; + for (j=0, blk = new_blk; + j < fs->inode_blocks_per_group; + j++, blk++) { + ext2fs_mark_block_bitmap2(bmap, blk); + if (flexbg_size) { + dgrp_t gr = ext2fs_group_of_blk2(fs, blk); + ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); + ext2fs_free_blocks_count_add(fs->super, -1); + ext2fs_bg_flags_clear(fs, gr, + EXT2_BG_BLOCK_UNINIT); + ext2fs_group_desc_csum_set(fs, gr); + } + } + ext2fs_inode_table_loc_set(fs, group, new_blk); + } + ext2fs_group_desc_csum_set(fs, group); + return 0; +} + +errcode_t ext2fs_allocate_tables(ext2_filsys fs) +{ + errcode_t retval; + dgrp_t i; + struct ext2fs_numeric_progress_struct progress; + + ext2fs_numeric_progress_init(fs, &progress, NULL, + fs->group_desc_count); + + for (i = 0; i < fs->group_desc_count; i++) { + ext2fs_numeric_progress_update(fs, &progress, i); + retval = ext2fs_allocate_group_table(fs, i, fs->block_map); + if (retval) + return retval; + } + ext2fs_numeric_progress_close(fs, &progress, NULL); + return 0; +} + diff --git a/libcustomext2fs/source/badblocks.c b/libcustomext2fs/source/badblocks.c new file mode 100644 index 00000000..5eb28b78 --- /dev/null +++ b/libcustomext2fs/source/badblocks.c @@ -0,0 +1,327 @@ +/* + * badblocks.c --- routines to manipulate the bad block structure + * + * Copyright (C) 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" + +/* + * Helper function for making a badblocks list + */ +static errcode_t make_u32_list(int size, int num, __u32 *list, + ext2_u32_list *ret) +{ + ext2_u32_list bb; + errcode_t retval; + + retval = ext2fs_get_mem(sizeof(struct ext2_struct_u32_list), &bb); + if (retval) + return retval; + memset(bb, 0, sizeof(struct ext2_struct_u32_list)); + bb->magic = EXT2_ET_MAGIC_BADBLOCKS_LIST; + bb->size = size ? size : 10; + bb->num = num; + retval = ext2fs_get_array(bb->size, sizeof(blk_t), &bb->list); + if (retval) { + ext2fs_free_mem(&bb); + return retval; + } + if (list) + memcpy(bb->list, list, bb->size * sizeof(blk_t)); + else + memset(bb->list, 0, bb->size * sizeof(blk_t)); + *ret = bb; + return 0; +} + + +/* + * This procedure creates an empty u32 list. + */ +errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size) +{ + return make_u32_list(size, 0, 0, ret); +} + +/* + * This procedure creates an empty badblocks list. + */ +errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret, int size) +{ + return make_u32_list(size, 0, 0, (ext2_badblocks_list *) ret); +} + + +/* + * This procedure copies a badblocks list + */ +errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest) +{ + errcode_t retval; + + retval = make_u32_list(src->size, src->num, src->list, dest); + if (retval) + return retval; + (*dest)->badblocks_flags = src->badblocks_flags; + return 0; +} + +errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src, + ext2_badblocks_list *dest) +{ + return ext2fs_u32_copy((ext2_u32_list) src, + (ext2_u32_list *) dest); +} + +/* + * This procedure frees a badblocks list. + * + * (note: moved to closefs.c) + */ + + +/* + * This procedure adds a block to a badblocks list. + */ +errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk) +{ + errcode_t retval; + int i, j; + unsigned long old_size; + + EXT2_CHECK_MAGIC(bb, EXT2_ET_MAGIC_BADBLOCKS_LIST); + + if (bb->num >= bb->size) { + old_size = bb->size * sizeof(__u32); + bb->size += 100; + retval = ext2fs_resize_mem(old_size, bb->size * sizeof(__u32), + &bb->list); + if (retval) { + bb->size -= 100; + return retval; + } + } + + /* + * Add special case code for appending to the end of the list + */ + i = bb->num-1; + if ((bb->num != 0) && (bb->list[i] == blk)) + return 0; + if ((bb->num == 0) || (bb->list[i] < blk)) { + bb->list[bb->num++] = blk; + return 0; + } + + j = bb->num; + for (i=0; i < bb->num; i++) { + if (bb->list[i] == blk) + return 0; + if (bb->list[i] > blk) { + j = i; + break; + } + } + for (i=bb->num; i > j; i--) + bb->list[i] = bb->list[i-1]; + bb->list[j] = blk; + bb->num++; + return 0; +} + +errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, blk_t blk) +{ + return ext2fs_u32_list_add((ext2_u32_list) bb, (__u32) blk); +} + +/* + * This procedure finds a particular block is on a badblocks + * list. + */ +int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk) +{ + int low, high, mid; + + if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST) + return -1; + + if (bb->num == 0) + return -1; + + low = 0; + high = bb->num-1; + if (blk == bb->list[low]) + return low; + if (blk == bb->list[high]) + return high; + + while (low < high) { + mid = (low+high)/2; + if (mid == low || mid == high) + break; + if (blk == bb->list[mid]) + return mid; + if (blk < bb->list[mid]) + high = mid; + else + low = mid; + } + return -1; +} + +/* + * This procedure tests to see if a particular block is on a badblocks + * list. + */ +int ext2fs_u32_list_test(ext2_u32_list bb, __u32 blk) +{ + if (ext2fs_u32_list_find(bb, blk) < 0) + return 0; + else + return 1; +} + +int ext2fs_badblocks_list_test(ext2_badblocks_list bb, blk_t blk) +{ + return ext2fs_u32_list_test((ext2_u32_list) bb, (__u32) blk); +} + + +/* + * Remove a block from the badblock list + */ +int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk) +{ + int remloc, i; + + if (bb->num == 0) + return -1; + + remloc = ext2fs_u32_list_find(bb, blk); + if (remloc < 0) + return -1; + + for (i = remloc ; i < bb->num-1; i++) + bb->list[i] = bb->list[i+1]; + bb->num--; + return 0; +} + +void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk) +{ + ext2fs_u32_list_del(bb, blk); +} + +errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb, + ext2_u32_iterate *ret) +{ + ext2_u32_iterate iter; + errcode_t retval; + + EXT2_CHECK_MAGIC(bb, EXT2_ET_MAGIC_BADBLOCKS_LIST); + + retval = ext2fs_get_mem(sizeof(struct ext2_struct_u32_iterate), &iter); + if (retval) + return retval; + + iter->magic = EXT2_ET_MAGIC_BADBLOCKS_ITERATE; + iter->bb = bb; + iter->ptr = 0; + *ret = iter; + return 0; +} + +errcode_t ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb, + ext2_badblocks_iterate *ret) +{ + return ext2fs_u32_list_iterate_begin((ext2_u32_list) bb, + (ext2_u32_iterate *) ret); +} + + +int ext2fs_u32_list_iterate(ext2_u32_iterate iter, __u32 *blk) +{ + ext2_u32_list bb; + + if (iter->magic != EXT2_ET_MAGIC_BADBLOCKS_ITERATE) + return 0; + + bb = iter->bb; + + if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST) + return 0; + + if (iter->ptr < bb->num) { + *blk = bb->list[iter->ptr++]; + return 1; + } + *blk = 0; + return 0; +} + +int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter, blk_t *blk) +{ + return ext2fs_u32_list_iterate((ext2_u32_iterate) iter, + (__u32 *) blk); +} + + +void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter) +{ + if (!iter || (iter->magic != EXT2_ET_MAGIC_BADBLOCKS_ITERATE)) + return; + + iter->bb = 0; + ext2fs_free_mem(&iter); +} + +void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter) +{ + ext2fs_u32_list_iterate_end((ext2_u32_iterate) iter); +} + + +int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2) +{ + EXT2_CHECK_MAGIC(bb1, EXT2_ET_MAGIC_BADBLOCKS_LIST); + EXT2_CHECK_MAGIC(bb2, EXT2_ET_MAGIC_BADBLOCKS_LIST); + + if (bb1->num != bb2->num) + return 0; + + if (memcmp(bb1->list, bb2->list, bb1->num * sizeof(blk_t)) != 0) + return 0; + return 1; +} + +int ext2fs_badblocks_equal(ext2_badblocks_list bb1, ext2_badblocks_list bb2) +{ + return ext2fs_u32_list_equal((ext2_u32_list) bb1, + (ext2_u32_list) bb2); +} + +int ext2fs_u32_list_count(ext2_u32_list bb) +{ + return bb->num; +} diff --git a/libcustomext2fs/source/bb_compat.c b/libcustomext2fs/source/bb_compat.c new file mode 100644 index 00000000..a94e3e48 --- /dev/null +++ b/libcustomext2fs/source/bb_compat.c @@ -0,0 +1,63 @@ +/* + * bb_compat.c --- compatibility badblocks routines + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" + +errcode_t badblocks_list_create(badblocks_list *ret, int size) +{ + return ext2fs_badblocks_list_create(ret, size); +} + +void badblocks_list_free(badblocks_list bb) +{ + ext2fs_badblocks_list_free(bb); +} + +errcode_t badblocks_list_add(badblocks_list bb, blk_t blk) +{ + return ext2fs_badblocks_list_add(bb, blk); +} + +int badblocks_list_test(badblocks_list bb, blk_t blk) +{ + return ext2fs_badblocks_list_test(bb, blk); +} + +errcode_t badblocks_list_iterate_begin(badblocks_list bb, + badblocks_iterate *ret) +{ + return ext2fs_badblocks_list_iterate_begin(bb, ret); +} + +int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk) +{ + return ext2fs_badblocks_list_iterate(iter, blk); +} + +void badblocks_list_iterate_end(badblocks_iterate iter) +{ + ext2fs_badblocks_list_iterate_end(iter); +} diff --git a/libcustomext2fs/source/bb_inode.c b/libcustomext2fs/source/bb_inode.c new file mode 100644 index 00000000..0b79b164 --- /dev/null +++ b/libcustomext2fs/source/bb_inode.c @@ -0,0 +1,267 @@ +/* + * bb_inode.c --- routines to update the bad block inode. + * + * WARNING: This routine modifies a lot of state in the filesystem; if + * this routine returns an error, the bad block inode may be in an + * inconsistent state. + * + * Copyright (C) 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct set_badblock_record { + ext2_badblocks_iterate bb_iter; + int bad_block_count; + blk_t *ind_blocks; + int max_ind_blocks; + int ind_blocks_size; + int ind_blocks_ptr; + char *block_buf; + errcode_t err; +}; + +static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr, + e2_blkcnt_t blockcnt, + blk_t ref_block, int ref_offset, + void *priv_data); +static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr, + e2_blkcnt_t blockcnt, + blk_t ref_block, int ref_offset, + void *priv_data); + +/* + * Given a bad blocks bitmap, update the bad blocks inode to reflect + * the map. + */ +errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list) +{ + errcode_t retval; + struct set_badblock_record rec; + struct ext2_inode inode; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!fs->block_map) + return EXT2_ET_NO_BLOCK_BITMAP; + + rec.bad_block_count = 0; + rec.ind_blocks_size = rec.ind_blocks_ptr = 0; + rec.max_ind_blocks = 10; + retval = ext2fs_get_array(rec.max_ind_blocks, sizeof(blk_t), + &rec.ind_blocks); + if (retval) + return retval; + memset(rec.ind_blocks, 0, rec.max_ind_blocks * sizeof(blk_t)); + retval = ext2fs_get_mem(fs->blocksize, &rec.block_buf); + if (retval) + goto cleanup; + memset(rec.block_buf, 0, fs->blocksize); + rec.err = 0; + + /* + * First clear the old bad blocks (while saving the indirect blocks) + */ + retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, + BLOCK_FLAG_DEPTH_TRAVERSE, 0, + clear_bad_block_proc, &rec); + if (retval) + goto cleanup; + if (rec.err) { + retval = rec.err; + goto cleanup; + } + + /* + * Now set the bad blocks! + * + * First, mark the bad blocks as used. This prevents a bad + * block from being used as an indirecto block for the bad + * block inode (!). + */ + if (bb_list) { + retval = ext2fs_badblocks_list_iterate_begin(bb_list, + &rec.bb_iter); + if (retval) + goto cleanup; + retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, + BLOCK_FLAG_APPEND, 0, + set_bad_block_proc, &rec); + ext2fs_badblocks_list_iterate_end(rec.bb_iter); + if (retval) + goto cleanup; + if (rec.err) { + retval = rec.err; + goto cleanup; + } + } + + /* + * Update the bad block inode's mod time and block count + * field. + */ + retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode); + if (retval) + goto cleanup; + + inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(0); + if (!inode.i_ctime) + inode.i_ctime = fs->now ? fs->now : time(0); + ext2fs_iblk_set(fs, &inode, rec.bad_block_count); + inode.i_size = rec.bad_block_count * fs->blocksize; + + retval = ext2fs_write_inode(fs, EXT2_BAD_INO, &inode); + if (retval) + goto cleanup; + +cleanup: + ext2fs_free_mem(&rec.ind_blocks); + ext2fs_free_mem(&rec.block_buf); + return retval; +} + +/* + * Helper function for update_bb_inode() + * + * Clear the bad blocks in the bad block inode, while saving the + * indirect blocks. + */ +#ifdef __TURBOC__ + #pragma argsused +#endif +static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr, + e2_blkcnt_t blockcnt, + blk_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct set_badblock_record *rec = (struct set_badblock_record *) + priv_data; + errcode_t retval; + unsigned long old_size; + + if (!*block_nr) + return 0; + + /* + * If the block number is outrageous, clear it and ignore it. + */ + if (*block_nr >= ext2fs_blocks_count(fs->super) || + *block_nr < fs->super->s_first_data_block) { + *block_nr = 0; + return BLOCK_CHANGED; + } + + if (blockcnt < 0) { + if (rec->ind_blocks_size >= rec->max_ind_blocks) { + old_size = rec->max_ind_blocks * sizeof(blk_t); + rec->max_ind_blocks += 10; + retval = ext2fs_resize_mem(old_size, + rec->max_ind_blocks * sizeof(blk_t), + &rec->ind_blocks); + if (retval) { + rec->max_ind_blocks -= 10; + rec->err = retval; + return BLOCK_ABORT; + } + } + rec->ind_blocks[rec->ind_blocks_size++] = *block_nr; + } + + /* + * Mark the block as unused, and update accounting information + */ + ext2fs_block_alloc_stats2(fs, *block_nr, -1); + + *block_nr = 0; + return BLOCK_CHANGED; +} + + +/* + * Helper function for update_bb_inode() + * + * Set the block list in the bad block inode, using the supplied bitmap. + */ +#ifdef __TURBOC__ + #pragma argsused +#endif +static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr, + e2_blkcnt_t blockcnt, + blk_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct set_badblock_record *rec = (struct set_badblock_record *) + priv_data; + errcode_t retval; + blk_t blk; + + if (blockcnt >= 0) { + /* + * Get the next bad block. + */ + if (!ext2fs_badblocks_list_iterate(rec->bb_iter, &blk)) + return BLOCK_ABORT; + rec->bad_block_count++; + } else { + /* + * An indirect block; fetch a block from the + * previously used indirect block list. The block + * most be not marked as used; if so, get another one. + * If we run out of reserved indirect blocks, allocate + * a new one. + */ + retry: + if (rec->ind_blocks_ptr < rec->ind_blocks_size) { + blk = rec->ind_blocks[rec->ind_blocks_ptr++]; + if (ext2fs_test_block_bitmap2(fs->block_map, blk)) + goto retry; + } else { + retval = ext2fs_new_block(fs, 0, 0, &blk); + if (retval) { + rec->err = retval; + return BLOCK_ABORT; + } + } + retval = io_channel_write_blk64(fs->io, blk, 1, rec->block_buf); + if (retval) { + rec->err = retval; + return BLOCK_ABORT; + } + } + + /* + * Update block counts + */ + ext2fs_block_alloc_stats2(fs, blk, +1); + + *block_nr = blk; + return BLOCK_CHANGED; +} + + + + + + diff --git a/libcustomext2fs/source/bit_ops.h b/libcustomext2fs/source/bit_ops.h new file mode 100644 index 00000000..762be0b3 --- /dev/null +++ b/libcustomext2fs/source/bit_ops.h @@ -0,0 +1,57 @@ +/* + bit_ops.h + Functions for dealing with conversion of data between types + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _BIT_OPS_H +#define _BIT_OPS_H + +#include + +/*----------------------------------------------------------------- +Functions to deal with little endian values stored in uint8_t arrays +-----------------------------------------------------------------*/ +static inline uint16_t u8array_to_u16 (const uint8_t* item, int offset) { + return ( item[offset] | (item[offset + 1] << 8)); +} + +static inline uint32_t u8array_to_u32 (const uint8_t* item, int offset) { + return ( item[offset] | (item[offset + 1] << 8) | (item[offset + 2] << 16) | (item[offset + 3] << 24)); +} + +static inline void u16_to_u8array (uint8_t* item, int offset, uint16_t value) { + item[offset] = (uint8_t) value; + item[offset + 1] = (uint8_t)(value >> 8); +} + +static inline void u32_to_u8array (uint8_t* item, int offset, uint32_t value) { + item[offset] = (uint8_t) value; + item[offset + 1] = (uint8_t)(value >> 8); + item[offset + 2] = (uint8_t)(value >> 16); + item[offset + 3] = (uint8_t)(value >> 24); +} + +#endif // _BIT_OPS_H diff --git a/libcustomext2fs/source/bitmaps.c b/libcustomext2fs/source/bitmaps.c new file mode 100644 index 00000000..c53d61ec --- /dev/null +++ b/libcustomext2fs/source/bitmaps.c @@ -0,0 +1,256 @@ +/* + * bitmaps.c --- routines to read, write, and manipulate the inode and + * block bitmaps. + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2fsP.h" + +void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap) +{ + ext2fs_free_generic_bmap(bitmap); +} + +void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap) +{ + ext2fs_free_generic_bmap(bitmap); +} + +errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest) +{ + return (ext2fs_copy_generic_bmap(src, dest)); +} +void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map) +{ + ext2fs_set_generic_bmap_padding(map); +} + +errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, + const char *descr, + ext2fs_inode_bitmap *ret) +{ + __u64 start, end, real_end; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + fs->write_bitmaps = ext2fs_write_bitmaps; + + start = 1; + end = fs->super->s_inodes_count; + real_end = (EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count); + + /* Are we permitted to use new-style bitmaps? */ + if (fs->flags & EXT2_FLAG_64BITS) + return (ext2fs_alloc_generic_bmap(fs, + EXT2_ET_MAGIC_INODE_BITMAP64, + EXT2FS_BMAP64_BITARRAY, + start, end, real_end, descr, ret)); + + /* Otherwise, check to see if the file system is small enough + * to use old-style 32-bit bitmaps */ + if ((end > ~0U) || (real_end > ~0U)) + return EXT2_ET_CANT_USE_LEGACY_BITMAPS; + + return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, fs, + start, end, real_end, + descr, 0, + (ext2fs_generic_bitmap *) ret)); +} + +errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, + const char *descr, + ext2fs_block_bitmap *ret) +{ + __u64 start, end, real_end; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + fs->write_bitmaps = ext2fs_write_bitmaps; + + start = fs->super->s_first_data_block; + end = ext2fs_blocks_count(fs->super)-1; + real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super) + * (__u64) fs->group_desc_count)-1 + start; + + if (fs->flags & EXT2_FLAG_64BITS) + return (ext2fs_alloc_generic_bmap(fs, + EXT2_ET_MAGIC_BLOCK_BITMAP64, + EXT2FS_BMAP64_BITARRAY, + start, end, real_end, descr, ret)); + + if ((end > ~0U) || (real_end > ~0U)) + return EXT2_ET_CANT_USE_LEGACY_BITMAPS; + + return (ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, fs, + start, end, real_end, + descr, 0, + (ext2fs_generic_bitmap *) ret)); +} + +errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, + ext2_ino_t end, ext2_ino_t *oend) +{ + __u64 tmp_oend; + int retval; + + retval = ext2fs_fudge_generic_bmap_end((ext2fs_generic_bitmap) bitmap, + EXT2_ET_FUDGE_INODE_BITMAP_END, + end, &tmp_oend); + if (oend) + *oend = tmp_oend; + return retval; +} + +errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, + blk_t end, blk_t *oend) +{ + return (ext2fs_fudge_generic_bitmap_end(bitmap, + EXT2_ET_MAGIC_BLOCK_BITMAP, + EXT2_ET_FUDGE_BLOCK_BITMAP_END, + end, oend)); +} + +errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap, + blk64_t end, blk64_t *oend) +{ + return (ext2fs_fudge_generic_bmap_end(bitmap, + EXT2_ET_FUDGE_BLOCK_BITMAP_END, + end, oend)); +} + +void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap) +{ + ext2fs_clear_generic_bmap(bitmap); +} + +void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap) +{ + ext2fs_clear_generic_bmap(bitmap); +} + +errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, + ext2fs_inode_bitmap bmap) +{ + return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_INODE_BITMAP, + new_end, new_real_end, bmap)); +} + +errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, __u64 new_real_end, + ext2fs_inode_bitmap bmap) +{ + return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end)); +} + +errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, + ext2fs_block_bitmap bmap) +{ + return (ext2fs_resize_generic_bitmap(EXT2_ET_MAGIC_BLOCK_BITMAP, + new_end, new_real_end, bmap)); +} + +errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, __u64 new_real_end, + ext2fs_block_bitmap bmap) +{ + return (ext2fs_resize_generic_bmap(bmap, new_end, new_real_end)); +} + +errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, + ext2fs_block_bitmap bm2) +{ + return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_BLOCK_BITMAP, + bm1, bm2)); +} + +errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, + ext2fs_inode_bitmap bm2) +{ + return (ext2fs_compare_generic_bmap(EXT2_ET_NEQ_INODE_BITMAP, + bm1, bm2)); +} + +errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap, + ext2_ino_t start, unsigned int num, + void *in) +{ + return (ext2fs_set_generic_bitmap_range(bmap, + EXT2_ET_MAGIC_INODE_BITMAP, + start, num, in)); +} + +errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap, + __u64 start, size_t num, + void *in) +{ + return (ext2fs_set_generic_bmap_range(bmap, start, num, in)); +} + +errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap, + ext2_ino_t start, unsigned int num, + void *out) +{ + return (ext2fs_get_generic_bitmap_range(bmap, + EXT2_ET_MAGIC_INODE_BITMAP, + start, num, out)); +} + +errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap, + __u64 start, size_t num, + void *out) +{ + return (ext2fs_get_generic_bmap_range(bmap, start, num, out)); +} + +errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap, + blk_t start, unsigned int num, + void *in) +{ + return (ext2fs_set_generic_bitmap_range(bmap, + EXT2_ET_MAGIC_BLOCK_BITMAP, + start, num, in)); +} + +errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t start, size_t num, + void *in) +{ + return (ext2fs_set_generic_bmap_range(bmap, start, num, in)); +} + +errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap, + blk_t start, unsigned int num, + void *out) +{ + return (ext2fs_get_generic_bitmap_range(bmap, + EXT2_ET_MAGIC_BLOCK_BITMAP, + start, num, out)); +} + +errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t start, size_t num, + void *out) +{ + return (ext2fs_get_generic_bmap_range(bmap, start, num, out)); +} diff --git a/libcustomext2fs/source/bitops.c b/libcustomext2fs/source/bitops.c new file mode 100644 index 00000000..a3f72c31 --- /dev/null +++ b/libcustomext2fs/source/bitops.c @@ -0,0 +1,117 @@ +/* + * bitops.c --- Bitmap frobbing code. See bitops.h for the inlined + * routines. + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifndef _EXT2_HAVE_ASM_BITOPS_ + +/* + * For the benefit of those who are trying to port Linux to another + * architecture, here are some C-language equivalents. You should + * recode these in the native assmebly language, if at all possible. + * + * C language equivalents written by Theodore Ts'o, 9/26/92. + * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian + * systems, as well as non-32 bit systems. + */ + +int ext2fs_set_bit(unsigned int nr,void * addr) +{ + int mask, retval; + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + mask = 1 << (nr & 0x07); + retval = mask & *ADDR; + *ADDR |= mask; + return retval; +} + +int ext2fs_clear_bit(unsigned int nr, void * addr) +{ + int mask, retval; + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + mask = 1 << (nr & 0x07); + retval = mask & *ADDR; + *ADDR &= ~mask; + return retval; +} + +int ext2fs_test_bit(unsigned int nr, const void * addr) +{ + int mask; + const unsigned char *ADDR = (const unsigned char *) addr; + + ADDR += nr >> 3; + mask = 1 << (nr & 0x07); + return (mask & *ADDR); +} + +#endif /* !_EXT2_HAVE_ASM_BITOPS_ */ + +void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg, + const char *description) +{ +#ifndef OMIT_COM_ERR + if (description) + com_err(0, errcode, "#%lu for %s", arg, description); + else + com_err(0, errcode, "#%lu", arg); +#endif +} + +/* + * C-only 64 bit ops. + */ + +int ext2fs_set_bit64(__u64 nr, void * addr) +{ + int mask, retval; + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + mask = 1 << (nr & 0x07); + retval = mask & *ADDR; + *ADDR |= mask; + return retval; +} + +int ext2fs_clear_bit64(__u64 nr, void * addr) +{ + int mask, retval; + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + mask = 1 << (nr & 0x07); + retval = mask & *ADDR; + *ADDR &= ~mask; + return retval; +} + +int ext2fs_test_bit64(__u64 nr, const void * addr) +{ + int mask; + const unsigned char *ADDR = (const unsigned char *) addr; + + ADDR += nr >> 3; + mask = 1 << (nr & 0x07); + return (mask & *ADDR); +} + diff --git a/libcustomext2fs/source/bitops.h b/libcustomext2fs/source/bitops.h new file mode 100644 index 00000000..bf6ee82a --- /dev/null +++ b/libcustomext2fs/source/bitops.h @@ -0,0 +1,638 @@ +/* + * bitops.h --- Bitmap frobbing code. The byte swapping routines are + * also included here. + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ +#ifndef _BITOPS_H_ +#define _BITOPS_H_ + +extern int ext2fs_set_bit(unsigned int nr,void * addr); +extern int ext2fs_clear_bit(unsigned int nr, void * addr); +extern int ext2fs_test_bit(unsigned int nr, const void * addr); +extern void ext2fs_fast_set_bit(unsigned int nr,void * addr); +extern void ext2fs_fast_clear_bit(unsigned int nr, void * addr); +extern int ext2fs_set_bit64(__u64 nr,void * addr); +extern int ext2fs_clear_bit64(__u64 nr, void * addr); +extern int ext2fs_test_bit64(__u64 nr, const void * addr); +extern void ext2fs_fast_set_bit64(__u64 nr,void * addr); +extern void ext2fs_fast_clear_bit64(__u64 nr, void * addr); +extern __u16 ext2fs_swab16(__u16 val); +extern __u32 ext2fs_swab32(__u32 val); +extern __u64 ext2fs_swab64(__u64 val); + +#ifdef WORDS_BIGENDIAN +#define ext2fs_cpu_to_le64(x) ext2fs_swab64((x)) +#define ext2fs_le64_to_cpu(x) ext2fs_swab64((x)) +#define ext2fs_cpu_to_le32(x) ext2fs_swab32((x)) +#define ext2fs_le32_to_cpu(x) ext2fs_swab32((x)) +#define ext2fs_cpu_to_le16(x) ext2fs_swab16((x)) +#define ext2fs_le16_to_cpu(x) ext2fs_swab16((x)) +#define ext2fs_cpu_to_be32(x) ((__u32)(x)) +#define ext2fs_be32_to_cpu(x) ((__u32)(x)) +#define ext2fs_cpu_to_be16(x) ((__u16)(x)) +#define ext2fs_be16_to_cpu(x) ((__u16)(x)) +#else +#define ext2fs_cpu_to_le64(x) ((__u64)(x)) +#define ext2fs_le64_to_cpu(x) ((__u64)(x)) +#define ext2fs_cpu_to_le32(x) ((__u32)(x)) +#define ext2fs_le32_to_cpu(x) ((__u32)(x)) +#define ext2fs_cpu_to_le16(x) ((__u16)(x)) +#define ext2fs_le16_to_cpu(x) ((__u16)(x)) +#define ext2fs_cpu_to_be32(x) ext2fs_swab32((x)) +#define ext2fs_be32_to_cpu(x) ext2fs_swab32((x)) +#define ext2fs_cpu_to_be16(x) ext2fs_swab16((x)) +#define ext2fs_be16_to_cpu(x) ext2fs_swab16((x)) +#endif + +/* + * EXT2FS bitmap manipulation routines. + */ + +/* Support for sending warning messages from the inline subroutines */ +extern const char *ext2fs_block_string; +extern const char *ext2fs_inode_string; +extern const char *ext2fs_mark_string; +extern const char *ext2fs_unmark_string; +extern const char *ext2fs_test_string; +extern void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg, + const char *description); +extern void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap, + int code, unsigned long arg); + +extern int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block); +extern int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block); +extern int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, blk_t block); + +extern int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, ext2_ino_t inode); +extern int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, ext2_ino_t inode); + +extern void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block); +extern void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block); +extern int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block); + +extern void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap); +extern ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap); +extern blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap); +extern ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap); + +extern void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern int ext2fs_test_inode_bitmap_range(ext2fs_inode_bitmap bitmap, + ino_t inode, int num); +extern void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern void ext2fs_set_bitmap_padding(ext2fs_generic_bitmap map); + +/* These routines moved to gen_bitmap.c (actually, some of the above, too) */ +extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, + __u32 bitno); +extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, + blk_t bitno); +extern int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, + blk_t bitno); +extern int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num); +extern __u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap); +extern __u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap); + +/* 64-bit versions */ + +extern int ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block); +extern int ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block); +extern int ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block); + +extern int ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern int ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern int ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); + +extern void ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block); +extern void ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block); +extern int ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block); + +extern void ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern void ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern int ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode); +extern blk64_t ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap); +extern ext2_ino_t ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap); +extern blk64_t ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap); +extern ext2_ino_t ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap); + +extern int ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, + unsigned int num); +extern void ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, + unsigned int num); +extern void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, + unsigned int num); +/* These routines moved to gen_bitmap64.c */ +extern void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap); +extern errcode_t ext2fs_compare_generic_bmap(errcode_t neq, + ext2fs_generic_bitmap bm1, + ext2fs_generic_bitmap bm2); +extern void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap); +extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, + blk64_t bitno); +extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, + blk64_t bitno); +extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, + blk64_t bitno); +extern int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, unsigned int num); +extern __u64 ext2fs_get_generic_bmap_start(ext2fs_generic_bitmap bitmap); +extern __u64 ext2fs_get_generic_bmap_end(ext2fs_generic_bitmap bitmap); +extern int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, unsigned int num); +extern void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, unsigned int num); +extern void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, unsigned int num); + +/* + * The inline routines themselves... + * + * If NO_INLINE_FUNCS is defined, then we won't try to do inline + * functions at all; they will be included as normal functions in + * inline.c + */ +#ifdef NO_INLINE_FUNCS +#if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \ + defined(__i586__) || defined(__mc68000__))) + /* This prevents bitops.c from trying to include the C */ + /* function version of these functions */ +#define _EXT2_HAVE_ASM_BITOPS_ +#endif +#endif /* NO_INLINE_FUNCS */ + +#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) +#ifdef INCLUDE_INLINE_FUNCS +#define _INLINE_ extern +#else +#ifdef __GNUC__ +#define _INLINE_ extern __inline__ +#else /* For Watcom C */ +#define _INLINE_ extern inline +#endif +#endif + +/* + * Fast bit set/clear functions that doesn't need to return the + * previous bit value. + */ + +_INLINE_ void ext2fs_fast_set_bit(unsigned int nr,void * addr) +{ + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + *ADDR |= (1 << (nr & 0x07)); +} + +_INLINE_ void ext2fs_fast_clear_bit(unsigned int nr, void * addr) +{ + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + *ADDR &= ~(1 << (nr & 0x07)); +} + + +_INLINE_ void ext2fs_fast_set_bit64(__u64 nr, void * addr) +{ + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + *ADDR |= (1 << (nr & 0x07)); +} + +_INLINE_ void ext2fs_fast_clear_bit64(__u64 nr, void * addr) +{ + unsigned char *ADDR = (unsigned char *) addr; + + ADDR += nr >> 3; + *ADDR &= ~(1 << (nr & 0x07)); +} + + +#if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \ + (defined(__i386__) || defined(__i486__) || defined(__i586__))) + +#define _EXT2_HAVE_ASM_BITOPS_ +#define _EXT2_HAVE_ASM_SWAB_ + +/* + * These are done by inline assembly for speed reasons..... + * + * All bitoperations return 0 if the bit was cleared before the + * operation and != 0 if it was not. Bit 0 is the LSB of addr; bit 32 + * is the LSB of (addr+1). + */ + +/* + * Some hacks to defeat gcc over-optimizations.. + */ +struct __dummy_h { unsigned long a[100]; }; +#define EXT2FS_ADDR (*(struct __dummy_h *) addr) +#define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr) + +_INLINE_ int ext2fs_set_bit(unsigned int nr, void * addr) +{ + int oldbit; + + addr = (void *) (((unsigned char *) addr) + (nr >> 3)); + __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit),"+m" (EXT2FS_ADDR) + :"r" (nr & 7)); + return oldbit; +} + +_INLINE_ int ext2fs_clear_bit(unsigned int nr, void * addr) +{ + int oldbit; + + addr = (void *) (((unsigned char *) addr) + (nr >> 3)); + __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit),"+m" (EXT2FS_ADDR) + :"r" (nr & 7)); + return oldbit; +} + +_INLINE_ int ext2fs_test_bit(unsigned int nr, const void * addr) +{ + int oldbit; + + addr = (const void *) (((const unsigned char *) addr) + (nr >> 3)); + __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0" + :"=r" (oldbit) + :"m" (EXT2FS_CONST_ADDR),"r" (nr & 7)); + return oldbit; +} + +_INLINE_ __u32 ext2fs_swab32(__u32 val) +{ +#ifdef EXT2FS_REQUIRE_486 + __asm__("bswap %0" : "=r" (val) : "0" (val)); +#else + __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ + "rorl $16,%0\n\t" /* swap words */ + "xchgb %b0,%h0" /* swap higher bytes */ + :"=q" (val) + : "0" (val)); +#endif + return val; +} + +_INLINE_ __u16 ext2fs_swab16(__u16 val) +{ + __asm__("xchgb %b0,%h0" /* swap bytes */ \ + : "=q" (val) \ + : "0" (val)); \ + return val; +} + +#undef EXT2FS_ADDR + +#endif /* i386 */ + +#if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \ + (defined(__mc68000__))) + +#define _EXT2_HAVE_ASM_BITOPS_ + +_INLINE_ int ext2fs_set_bit(unsigned int nr,void * addr) +{ + char retval; + + __asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0" + : "=d" (retval) : "d" (nr^7), "a" (addr)); + + return retval; +} + +_INLINE_ int ext2fs_clear_bit(unsigned int nr, void * addr) +{ + char retval; + + __asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0" + : "=d" (retval) : "d" (nr^7), "a" (addr)); + + return retval; +} + +_INLINE_ int ext2fs_test_bit(unsigned int nr, const void * addr) +{ + char retval; + + __asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0" + : "=d" (retval) : "d" (nr^7), "a" (addr)); + + return retval; +} + +#endif /* __mc68000__ */ + + +#if !defined(_EXT2_HAVE_ASM_SWAB_) + +_INLINE_ __u16 ext2fs_swab16(__u16 val) +{ + return (val >> 8) | (val << 8); +} + +_INLINE_ __u32 ext2fs_swab32(__u32 val) +{ + return ((val>>24) | ((val>>8)&0xFF00) | + ((val<<8)&0xFF0000) | (val<<24)); +} + +#endif /* !_EXT2_HAVE_ASM_SWAB */ + +_INLINE_ __u64 ext2fs_swab64(__u64 val) +{ + return (ext2fs_swab32(val >> 32) | + (((__u64)ext2fs_swab32(val & 0xFFFFFFFFUL)) << 32)); +} + +_INLINE_ int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block) +{ + return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block) +{ + return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block) +{ + return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block) +{ + ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block); +} + +_INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block) +{ + ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, block); +} + +_INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap, + blk_t block) +{ + return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode); +} + +_INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, inode); +} + +_INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap) +{ + return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap) +{ + return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap) +{ + return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap) +{ + return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num) +{ + return ext2fs_test_block_bitmap_range(bitmap, block, num); +} + +_INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num) +{ + ext2fs_mark_block_bitmap_range(bitmap, block, num); +} + +_INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num) +{ + ext2fs_unmark_block_bitmap_range(bitmap, block, num); +} + +/* 64-bit versions */ + +_INLINE_ int ext2fs_mark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block) +{ + return ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ int ext2fs_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block) +{ + return ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, block); +} + +_INLINE_ int ext2fs_test_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block) +{ + return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ int ext2fs_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ int ext2fs_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ int ext2fs_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ void ext2fs_fast_mark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block) +{ + ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, block); +} + +_INLINE_ void ext2fs_fast_unmark_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block) +{ + ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, block); +} + +_INLINE_ int ext2fs_fast_test_block_bitmap2(ext2fs_block_bitmap bitmap, + blk64_t block) +{ + return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, + block); +} + +_INLINE_ void ext2fs_fast_mark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + ext2fs_mark_generic_bmap((ext2fs_generic_bitmap) bitmap, inode); +} + +_INLINE_ void ext2fs_fast_unmark_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + ext2fs_unmark_generic_bmap((ext2fs_generic_bitmap) bitmap, inode); +} + +_INLINE_ int ext2fs_fast_test_inode_bitmap2(ext2fs_inode_bitmap bitmap, + ext2_ino_t inode) +{ + return ext2fs_test_generic_bmap((ext2fs_generic_bitmap) bitmap, + inode); +} + +_INLINE_ blk64_t ext2fs_get_block_bitmap_start2(ext2fs_block_bitmap bitmap) +{ + return ext2fs_get_generic_bmap_start((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start2(ext2fs_inode_bitmap bitmap) +{ + return ext2fs_get_generic_bmap_start((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ blk64_t ext2fs_get_block_bitmap_end2(ext2fs_block_bitmap bitmap) +{ + return ext2fs_get_generic_bmap_end((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end2(ext2fs_inode_bitmap bitmap) +{ + return ext2fs_get_generic_bmap_end((ext2fs_generic_bitmap) bitmap); +} + +_INLINE_ int ext2fs_fast_test_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, + unsigned int num) +{ + return ext2fs_test_block_bitmap_range2(bitmap, block, num); +} + +_INLINE_ void ext2fs_fast_mark_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, + unsigned int num) +{ + ext2fs_mark_block_bitmap_range2(bitmap, block, num); +} + +_INLINE_ void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, + blk64_t block, + unsigned int num) +{ + ext2fs_unmark_block_bitmap_range2(bitmap, block, num); +} + +#undef _INLINE_ +#endif + +#endif diff --git a/libcustomext2fs/source/blkmap64_ba.c b/libcustomext2fs/source/blkmap64_ba.c new file mode 100644 index 00000000..395aba97 --- /dev/null +++ b/libcustomext2fs/source/blkmap64_ba.c @@ -0,0 +1,327 @@ +/* + * blkmap64_ba.c --- Simple bitarray implementation for bitmaps + * + * Copyright (C) 2008 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" +#include "bmap64.h" + +/* + * Private data for bit array implementation of bitmap ops. + * Currently, this is just a pointer to our big flat hunk of memory, + * exactly equivalent to the old-skool char * bitmap member. + */ + +struct ext2fs_ba_private_struct { + char *bitarray; +}; + +typedef struct ext2fs_ba_private_struct *ext2fs_ba_private; + +static errcode_t ba_alloc_private_data (ext2fs_generic_bitmap bitmap) +{ + ext2fs_ba_private bp; + errcode_t retval; + size_t size; + + /* + * Since we only have the one pointer, we could just shove our + * private data in the void *private field itself, but then + * we'd have to do a fair bit of rewriting if we ever added a + * field. I'm agnostic. + */ + retval = ext2fs_get_mem(sizeof (ext2fs_ba_private), &bp); + if (retval) + return retval; + + size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); + + retval = ext2fs_get_mem(size, &bp->bitarray); + if (retval) { + ext2fs_free_mem(&bp); + bp = 0; + return retval; + } + bitmap->private = (void *) bp; + return 0; +} + +static errcode_t ba_new_bmap(ext2_filsys fs EXT2FS_ATTR((unused)), + ext2fs_generic_bitmap bitmap) +{ + ext2fs_ba_private bp; + errcode_t retval; + size_t size; + + retval = ba_alloc_private_data (bitmap); + if (retval) + return retval; + + bp = (ext2fs_ba_private) bitmap->private; + size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); + memset(bp->bitarray, 0, size); + + return 0; +} + +static void ba_free_bmap(ext2fs_generic_bitmap bitmap) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + + if (!bp) + return; + + if (bp->bitarray) { + ext2fs_free_mem (&bp->bitarray); + bp->bitarray = 0; + } + ext2fs_free_mem (&bp); + bp = 0; +} + +static errcode_t ba_copy_bmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap dest) +{ + ext2fs_ba_private src_bp = (ext2fs_ba_private) src->private; + ext2fs_ba_private dest_bp; + errcode_t retval; + size_t size; + + retval = ba_alloc_private_data (dest); + if (retval) + return retval; + + dest_bp = (ext2fs_ba_private) dest->private; + + size = (size_t) (((src->real_end - src->start) / 8) + 1); + memcpy (dest_bp->bitarray, src_bp->bitarray, size); + + return 0; +} + +static errcode_t ba_resize_bmap(ext2fs_generic_bitmap bmap, + __u64 new_end, __u64 new_real_end) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bmap->private; + errcode_t retval; + size_t size, new_size; + __u64 bitno; + + /* + * If we're expanding the bitmap, make sure all of the new + * parts of the bitmap are zero. + */ + if (new_end > bmap->end) { + bitno = bmap->real_end; + if (bitno > new_end) + bitno = new_end; + for (; bitno > bmap->end; bitno--) + ext2fs_clear_bit64(bitno - bmap->start, bp->bitarray); + } + if (new_real_end == bmap->real_end) { + bmap->end = new_end; + return 0; + } + + size = ((bmap->real_end - bmap->start) / 8) + 1; + new_size = ((new_real_end - bmap->start) / 8) + 1; + + if (size != new_size) { + retval = ext2fs_resize_mem(size, new_size, &bp->bitarray); + if (retval) + return retval; + } + if (new_size > size) + memset(bp->bitarray + size, 0, new_size - size); + + bmap->end = new_end; + bmap->real_end = new_real_end; + return 0; + +} + +static int ba_mark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + blk64_t bitno = (blk64_t) arg; + + return ext2fs_set_bit64(bitno - bitmap->start, bp->bitarray); +} + +static int ba_unmark_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + blk64_t bitno = (blk64_t) arg; + + return ext2fs_clear_bit64(bitno - bitmap->start, bp->bitarray); +} + +static int ba_test_bmap(ext2fs_generic_bitmap bitmap, __u64 arg) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + blk64_t bitno = (blk64_t) arg; + + return ext2fs_test_bit64(bitno - bitmap->start, bp->bitarray); +} + +static void ba_mark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg, + unsigned int num) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + blk64_t bitno = (blk64_t) arg; + unsigned int i; + + for (i = 0; i < num; i++) + ext2fs_fast_set_bit64(bitno + i - bitmap->start, bp->bitarray); +} + +static void ba_unmark_bmap_extent(ext2fs_generic_bitmap bitmap, __u64 arg, + unsigned int num) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + blk64_t bitno = (blk64_t) arg; + unsigned int i; + + for (i = 0; i < num; i++) + ext2fs_fast_clear_bit64(bitno + i - bitmap->start, bp->bitarray); +} + +static int ba_test_clear_bmap_extent(ext2fs_generic_bitmap bitmap, + __u64 start, unsigned int len) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + __u64 start_byte, len_byte = len >> 3; + unsigned int start_bit, len_bit = len % 8; + unsigned int first_bit = 0; + unsigned int last_bit = 0; + int mark_count = 0; + int mark_bit = 0; + int i; + const char *ADDR; + + ADDR = bp->bitarray; + start -= bitmap->start; + start_byte = start >> 3; + start_bit = start % 8; + + if (start_bit != 0) { + /* + * The compared start block number or start inode number + * is not the first bit in a byte. + */ + mark_count = 8 - start_bit; + if (len < 8 - start_bit) { + mark_count = (int)len; + mark_bit = len + start_bit - 1; + } else + mark_bit = 7; + + for (i = mark_count; i > 0; i--, mark_bit--) + first_bit |= 1 << mark_bit; + + /* + * Compare blocks or inodes in the first byte. + * If there is any marked bit, this function returns 0. + */ + if (first_bit & ADDR[start_byte]) + return 0; + else if (len <= 8 - start_bit) + return 1; + + start_byte++; + len_bit = (len - mark_count) % 8; + len_byte = (len - mark_count) >> 3; + } + + /* + * The compared start block number or start inode number is + * the first bit in a byte. + */ + if (len_bit != 0) { + /* + * The compared end block number or end inode number is + * not the last bit in a byte. + */ + for (mark_bit = len_bit - 1; mark_bit >= 0; mark_bit--) + last_bit |= 1 << mark_bit; + + /* + * Compare blocks or inodes in the last byte. + * If there is any marked bit, this function returns 0. + */ + if (last_bit & ADDR[start_byte + len_byte]) + return 0; + else if (len_byte == 0) + return 1; + } + + /* Check whether all bytes are 0 */ + return ext2fs_mem_is_zero(ADDR + start_byte, len_byte); +} + + +static errcode_t ba_set_bmap_range(ext2fs_generic_bitmap bitmap, + __u64 start, size_t num, void *in) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + + memcpy (bp->bitarray + (start >> 3), in, (num + 7) >> 3); + + return 0; +} + +static errcode_t ba_get_bmap_range(ext2fs_generic_bitmap bitmap, + __u64 start, size_t num, void *out) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + + memcpy (out, bp->bitarray + (start >> 3), (num + 7) >> 3); + + return 0; +} + +static void ba_clear_bmap(ext2fs_generic_bitmap bitmap) +{ + ext2fs_ba_private bp = (ext2fs_ba_private) bitmap->private; + + memset(bp->bitarray, 0, + (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1)); +} + +struct ext2_bitmap_ops ext2fs_blkmap64_bitarray = { + .type = EXT2FS_BMAP64_BITARRAY, + .new_bmap = ba_new_bmap, + .free_bmap = ba_free_bmap, + .copy_bmap = ba_copy_bmap, + .resize_bmap = ba_resize_bmap, + .mark_bmap = ba_mark_bmap, + .unmark_bmap = ba_unmark_bmap, + .test_bmap = ba_test_bmap, + .test_clear_bmap_extent = ba_test_clear_bmap_extent, + .mark_bmap_extent = ba_mark_bmap_extent, + .unmark_bmap_extent = ba_unmark_bmap_extent, + .set_bmap_range = ba_set_bmap_range, + .get_bmap_range = ba_get_bmap_range, + .clear_bmap = ba_clear_bmap, +}; diff --git a/libcustomext2fs/source/blknum.c b/libcustomext2fs/source/blknum.c new file mode 100644 index 00000000..b3e6dcad --- /dev/null +++ b/libcustomext2fs/source/blknum.c @@ -0,0 +1,477 @@ +/* + * blknum.c --- Functions to handle blk64_t and high/low 64-bit block + * number. + * + * Copyright IBM Corporation, 2007 + * Author Jose R. Santos + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include "ext2fs.h" + +/* + * Return the group # of a block + */ +dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t blk) +{ + return (blk - fs->super->s_first_data_block) / + fs->super->s_blocks_per_group; +} + +/* + * Return the first block (inclusive) in a group + */ +blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group) +{ + return fs->super->s_first_data_block + + ((blk64_t)group * fs->super->s_blocks_per_group); +} + +/* + * Return the last block (inclusive) in a group + */ +blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group) +{ + return (group == fs->group_desc_count - 1 ? + ext2fs_blocks_count(fs->super) - 1 : + ext2fs_group_first_block2(fs, group) + + (fs->super->s_blocks_per_group - 1)); +} + +/* + * Return the inode data block count + */ +blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs, + struct ext2_inode *inode) +{ + return (inode->i_blocks | + ((fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ? + (__u64) inode->osd2.linux2.l_i_blocks_hi << 32 : 0)) - + (inode->i_file_acl ? fs->blocksize >> 9 : 0); +} + +/* + * Return the inode i_blocks count + */ +blk64_t ext2fs_inode_i_blocks(ext2_filsys fs, + struct ext2_inode *inode) +{ + return (inode->i_blocks | + ((fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ? + (__u64)inode->osd2.linux2.l_i_blocks_hi << 32 : 0)); +} + +/* + * Return the fs block count + */ +blk64_t ext2fs_blocks_count(struct ext2_super_block *super) +{ + return super->s_blocks_count | + (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) super->s_blocks_count_hi << 32 : 0); +} + +/* + * Set the fs block count + */ +void ext2fs_blocks_count_set(struct ext2_super_block *super, blk64_t blk) +{ + super->s_blocks_count = blk; + if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + super->s_blocks_count_hi = (__u64) blk >> 32; +} + +/* + * Add to the current fs block count + */ +void ext2fs_blocks_count_add(struct ext2_super_block *super, blk64_t blk) +{ + blk64_t tmp; + tmp = ext2fs_blocks_count(super) + blk; + ext2fs_blocks_count_set(super, tmp); +} + +/* + * Return the fs reserved block count + */ +blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super) +{ + return super->s_r_blocks_count | + (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) super->s_r_blocks_count_hi << 32 : 0); +} + +/* + * Set the fs reserved block count + */ +void ext2fs_r_blocks_count_set(struct ext2_super_block *super, blk64_t blk) +{ + super->s_r_blocks_count = blk; + if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + super->s_r_blocks_count_hi = (__u64) blk >> 32; +} + +/* + * Add to the current reserved fs block count + */ +void ext2fs_r_blocks_count_add(struct ext2_super_block *super, blk64_t blk) +{ + blk64_t tmp; + tmp = ext2fs_r_blocks_count(super) + blk; + ext2fs_r_blocks_count_set(super, tmp); +} + +/* + * Return the fs free block count + */ +blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super) +{ + return super->s_free_blocks_count | + (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) super->s_free_blocks_hi << 32 : 0); +} + +/* + * Set the fs free block count + */ +void ext2fs_free_blocks_count_set(struct ext2_super_block *super, blk64_t blk) +{ + super->s_free_blocks_count = blk; + if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + super->s_free_blocks_hi = (__u64) blk >> 32; +} + +/* + * Add to the current free fs block count + */ +void ext2fs_free_blocks_count_add(struct ext2_super_block *super, blk64_t blk) +{ + blk64_t tmp; + tmp = ext2fs_free_blocks_count(super) + blk; + ext2fs_free_blocks_count_set(super, tmp); +} + +/* + * Get a pointer to a block group descriptor. We need the explicit + * pointer to the group desc for code that swaps block group + * descriptors before writing them out, as it wants to make a copy and + * do the swap there. + */ +struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs, + struct opaque_ext2_group_desc *gdp, + dgrp_t group) +{ + if (fs->super->s_desc_size >= EXT2_MIN_DESC_SIZE_64BIT) + return (struct ext2_group_desc *) + ((struct ext4_group_desc *) gdp + group); + else + return (struct ext2_group_desc *) gdp + group; +} + +/* Do the same but as an ext4 group desc for internal use here */ +static struct ext4_group_desc *ext4fs_group_desc(ext2_filsys fs, + struct opaque_ext2_group_desc *gdp, + dgrp_t group) +{ + return (struct ext4_group_desc *)ext2fs_group_desc(fs, gdp, group); +} + +/* + * Return the block bitmap block of a group + */ +blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_block_bitmap | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64)gdp->bg_block_bitmap_hi << 32 : 0); +} + +/* + * Set the block bitmap block of a group + */ +void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_block_bitmap = blk; + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_block_bitmap_hi = (__u64) blk >> 32; +} + +/* + * Return the inode bitmap block of a group + */ +blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_inode_bitmap | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) gdp->bg_inode_bitmap_hi << 32 : 0); +} + +/* + * Set the inode bitmap block of a group + */ +void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_inode_bitmap = blk; + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_inode_bitmap_hi = (__u64) blk >> 32; +} + +/* + * Return the inode table block of a group + */ +blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_inode_table | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) gdp->bg_inode_table_hi << 32 : 0); +} + +/* + * Set the inode table block of a group + */ +void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group, blk64_t blk) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_inode_table = blk; + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_inode_table_hi = (__u64) blk >> 32; +} + +/* + * Return the free blocks count of a group + */ +__u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_free_blocks_count | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u32) gdp->bg_free_blocks_count_hi << 16 : 0); +} + +/* + * Set the free blocks count of a group + */ +void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group, __u32 n) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_free_blocks_count = n; + + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_free_blocks_count_hi = (__u32) n >> 16; +} + +/* + * Return the free inodes count of a group + */ +__u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_free_inodes_count | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u32) gdp->bg_free_inodes_count_hi << 16 : 0); +} + +/* + * Set the free inodes count of a group + */ +void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group, __u32 n) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_free_inodes_count = n; + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_free_inodes_count_hi = (__u32) n >> 16; +} + +/* + * Return the used dirs count of a group + */ +__u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_used_dirs_count | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u32) gdp->bg_used_dirs_count_hi << 16 : 0); +} + +/* + * Set the used dirs count of a group + */ +void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group, __u32 n) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_used_dirs_count = n; + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_used_dirs_count_hi = (__u32) n >> 16; +} + +/* + * Return the unused inodes count of a group + */ +__u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_itable_unused | + (fs->super->s_feature_incompat + & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u32) gdp->bg_itable_unused_hi << 16 : 0); +} + +/* + * Set the unused inodes count of a group + */ +void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group, __u32 n) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_itable_unused = n; + if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + gdp->bg_itable_unused_hi = (__u32) n >> 16; +} + +/* + * Get the flags for this block group + */ +__u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_flags; +} + +/* + * Zero out the flags for this block group + */ +void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_flags = 0; + return; +} + +/* + * Get the value of a particular flag for this block group + */ +int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_flags & bg_flag; +} + +/* + * Set a flag or set of flags for this block group + */ +void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_flags |= bg_flags; + return; +} + +/* + * Clear a flag or set of flags for this block group + */ +void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_flags &= ~bg_flags; + return; +} + +/* + * Get the checksum for this block group + */ +__u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + return gdp->bg_checksum; +} + +/* + * Set the checksum for this block group to a previously calculated value + */ +void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum) +{ + struct ext4_group_desc *gdp; + + gdp = ext4fs_group_desc(fs, fs->group_desc, group); + gdp->bg_checksum = checksum; + return; +} + +/* + * Get the acl block of a file + * + * XXX Ignoring 64-bit file system flag - most places where this is + * called don't have access to the fs struct, and the high bits should + * be 0 in the non-64-bit case anyway. + */ +blk64_t ext2fs_file_acl_block(const struct ext2_inode *inode) +{ + return (inode->i_file_acl | + (__u64) inode->osd2.linux2.l_i_file_acl_high << 32); +} + +/* + * Set the acl block of a file + */ +void ext2fs_file_acl_block_set(struct ext2_inode *inode, blk64_t blk) +{ + inode->i_file_acl = blk; + inode->osd2.linux2.l_i_file_acl_high = (__u64) blk >> 32; +} + diff --git a/libcustomext2fs/source/block.c b/libcustomext2fs/source/block.c new file mode 100644 index 00000000..ff0d8bd3 --- /dev/null +++ b/libcustomext2fs/source/block.c @@ -0,0 +1,622 @@ +/* + * block.c --- iterate over all blocks in an inode + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct block_context { + ext2_filsys fs; + int (*func)(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t bcount, + blk64_t ref_blk, + int ref_offset, + void *priv_data); + e2_blkcnt_t bcount; + int bsize; + int flags; + errcode_t errcode; + char *ind_buf; + char *dind_buf; + char *tind_buf; + void *priv_data; +}; + +#define check_for_ro_violation_return(ctx, ret) \ + do { \ + if (((ctx)->flags & BLOCK_FLAG_READ_ONLY) && \ + ((ret) & BLOCK_CHANGED)) { \ + (ctx)->errcode = EXT2_ET_RO_BLOCK_ITERATE; \ + ret |= BLOCK_ABORT | BLOCK_ERROR; \ + return ret; \ + } \ + } while (0) + +#define check_for_ro_violation_goto(ctx, ret, label) \ + do { \ + if (((ctx)->flags & BLOCK_FLAG_READ_ONLY) && \ + ((ret) & BLOCK_CHANGED)) { \ + (ctx)->errcode = EXT2_ET_RO_BLOCK_ITERATE; \ + ret |= BLOCK_ABORT | BLOCK_ERROR; \ + goto label; \ + } \ + } while (0) + +static int block_iterate_ind(blk_t *ind_block, blk_t ref_block, + int ref_offset, struct block_context *ctx) +{ + int ret = 0, changed = 0; + int i, flags, limit, offset; + blk_t *block_nr; + blk64_t blk64; + + limit = ctx->fs->blocksize >> 2; + if (!(ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && + !(ctx->flags & BLOCK_FLAG_DATA_ONLY)) { + blk64 = *ind_block; + ret = (*ctx->func)(ctx->fs, &blk64, + BLOCK_COUNT_IND, ref_block, + ref_offset, ctx->priv_data); + *ind_block = blk64; + } + check_for_ro_violation_return(ctx, ret); + if (!*ind_block || (ret & BLOCK_ABORT)) { + ctx->bcount += limit; + return ret; + } + if (*ind_block >= ext2fs_blocks_count(ctx->fs->super) || + *ind_block < ctx->fs->super->s_first_data_block) { + ctx->errcode = EXT2_ET_BAD_IND_BLOCK; + ret |= BLOCK_ERROR; + return ret; + } + ctx->errcode = ext2fs_read_ind_block(ctx->fs, *ind_block, + ctx->ind_buf); + if (ctx->errcode) { + ret |= BLOCK_ERROR; + return ret; + } + + block_nr = (blk_t *) ctx->ind_buf; + offset = 0; + if (ctx->flags & BLOCK_FLAG_APPEND) { + for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) { + blk64 = *block_nr; + flags = (*ctx->func)(ctx->fs, &blk64, ctx->bcount, + *ind_block, offset, + ctx->priv_data); + *block_nr = blk64; + changed |= flags; + if (flags & BLOCK_ABORT) { + ret |= BLOCK_ABORT; + break; + } + offset += sizeof(blk_t); + } + } else { + for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) { + if (*block_nr == 0) + continue; + blk64 = *block_nr; + flags = (*ctx->func)(ctx->fs, &blk64, ctx->bcount, + *ind_block, offset, + ctx->priv_data); + *block_nr = blk64; + changed |= flags; + if (flags & BLOCK_ABORT) { + ret |= BLOCK_ABORT; + break; + } + offset += sizeof(blk_t); + } + } + check_for_ro_violation_return(ctx, changed); + if (changed & BLOCK_CHANGED) { + ctx->errcode = ext2fs_write_ind_block(ctx->fs, *ind_block, + ctx->ind_buf); + if (ctx->errcode) + ret |= BLOCK_ERROR | BLOCK_ABORT; + } + if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && + !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && + !(ret & BLOCK_ABORT)) { + blk64 = *ind_block; + ret |= (*ctx->func)(ctx->fs, &blk64, + BLOCK_COUNT_IND, ref_block, + ref_offset, ctx->priv_data); + *ind_block = blk64; + } + check_for_ro_violation_return(ctx, ret); + return ret; +} + +static int block_iterate_dind(blk_t *dind_block, blk_t ref_block, + int ref_offset, struct block_context *ctx) +{ + int ret = 0, changed = 0; + int i, flags, limit, offset; + blk_t *block_nr; + blk64_t blk64; + + limit = ctx->fs->blocksize >> 2; + if (!(ctx->flags & (BLOCK_FLAG_DEPTH_TRAVERSE | + BLOCK_FLAG_DATA_ONLY))) { + blk64 = *dind_block; + ret = (*ctx->func)(ctx->fs, &blk64, + BLOCK_COUNT_DIND, ref_block, + ref_offset, ctx->priv_data); + *dind_block = blk64; + } + check_for_ro_violation_return(ctx, ret); + if (!*dind_block || (ret & BLOCK_ABORT)) { + ctx->bcount += limit*limit; + return ret; + } + if (*dind_block >= ext2fs_blocks_count(ctx->fs->super) || + *dind_block < ctx->fs->super->s_first_data_block) { + ctx->errcode = EXT2_ET_BAD_DIND_BLOCK; + ret |= BLOCK_ERROR; + return ret; + } + ctx->errcode = ext2fs_read_ind_block(ctx->fs, *dind_block, + ctx->dind_buf); + if (ctx->errcode) { + ret |= BLOCK_ERROR; + return ret; + } + + block_nr = (blk_t *) ctx->dind_buf; + offset = 0; + if (ctx->flags & BLOCK_FLAG_APPEND) { + for (i = 0; i < limit; i++, block_nr++) { + flags = block_iterate_ind(block_nr, + *dind_block, offset, + ctx); + changed |= flags; + if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { + ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); + break; + } + offset += sizeof(blk_t); + } + } else { + for (i = 0; i < limit; i++, block_nr++) { + if (*block_nr == 0) { + ctx->bcount += limit; + continue; + } + flags = block_iterate_ind(block_nr, + *dind_block, offset, + ctx); + changed |= flags; + if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { + ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); + break; + } + offset += sizeof(blk_t); + } + } + check_for_ro_violation_return(ctx, changed); + if (changed & BLOCK_CHANGED) { + ctx->errcode = ext2fs_write_ind_block(ctx->fs, *dind_block, + ctx->dind_buf); + if (ctx->errcode) + ret |= BLOCK_ERROR | BLOCK_ABORT; + } + if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && + !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && + !(ret & BLOCK_ABORT)) { + blk64 = *dind_block; + ret |= (*ctx->func)(ctx->fs, &blk64, + BLOCK_COUNT_DIND, ref_block, + ref_offset, ctx->priv_data); + *dind_block = blk64; + } + check_for_ro_violation_return(ctx, ret); + return ret; +} + +static int block_iterate_tind(blk_t *tind_block, blk_t ref_block, + int ref_offset, struct block_context *ctx) +{ + int ret = 0, changed = 0; + int i, flags, limit, offset; + blk_t *block_nr; + blk64_t blk64; + + limit = ctx->fs->blocksize >> 2; + if (!(ctx->flags & (BLOCK_FLAG_DEPTH_TRAVERSE | + BLOCK_FLAG_DATA_ONLY))) { + blk64 = *tind_block; + ret = (*ctx->func)(ctx->fs, &blk64, + BLOCK_COUNT_TIND, ref_block, + ref_offset, ctx->priv_data); + *tind_block = blk64; + } + check_for_ro_violation_return(ctx, ret); + if (!*tind_block || (ret & BLOCK_ABORT)) { + ctx->bcount += limit*limit*limit; + return ret; + } + if (*tind_block >= ext2fs_blocks_count(ctx->fs->super) || + *tind_block < ctx->fs->super->s_first_data_block) { + ctx->errcode = EXT2_ET_BAD_TIND_BLOCK; + ret |= BLOCK_ERROR; + return ret; + } + ctx->errcode = ext2fs_read_ind_block(ctx->fs, *tind_block, + ctx->tind_buf); + if (ctx->errcode) { + ret |= BLOCK_ERROR; + return ret; + } + + block_nr = (blk_t *) ctx->tind_buf; + offset = 0; + if (ctx->flags & BLOCK_FLAG_APPEND) { + for (i = 0; i < limit; i++, block_nr++) { + flags = block_iterate_dind(block_nr, + *tind_block, + offset, ctx); + changed |= flags; + if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { + ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); + break; + } + offset += sizeof(blk_t); + } + } else { + for (i = 0; i < limit; i++, block_nr++) { + if (*block_nr == 0) { + ctx->bcount += limit*limit; + continue; + } + flags = block_iterate_dind(block_nr, + *tind_block, + offset, ctx); + changed |= flags; + if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { + ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); + break; + } + offset += sizeof(blk_t); + } + } + check_for_ro_violation_return(ctx, changed); + if (changed & BLOCK_CHANGED) { + ctx->errcode = ext2fs_write_ind_block(ctx->fs, *tind_block, + ctx->tind_buf); + if (ctx->errcode) + ret |= BLOCK_ERROR | BLOCK_ABORT; + } + if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && + !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && + !(ret & BLOCK_ABORT)) { + blk64 = *tind_block; + ret |= (*ctx->func)(ctx->fs, &blk64, + BLOCK_COUNT_TIND, ref_block, + ref_offset, ctx->priv_data); + *tind_block = blk64; + } + check_for_ro_violation_return(ctx, ret); + return ret; +} + +errcode_t ext2fs_block_iterate3(ext2_filsys fs, + ext2_ino_t ino, + int flags, + char *block_buf, + int (*func)(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_blk, + int ref_offset, + void *priv_data), + void *priv_data) +{ + int i; + int r, ret = 0; + struct ext2_inode inode; + errcode_t retval; + struct block_context ctx; + int limit; + blk64_t blk64; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + ctx.errcode = ext2fs_read_inode(fs, ino, &inode); + if (ctx.errcode) + return ctx.errcode; + + /* + * Check to see if we need to limit large files + */ + if (flags & BLOCK_FLAG_NO_LARGE) { + if (!LINUX_S_ISDIR(inode.i_mode) && + (inode.i_size_high != 0)) + return EXT2_ET_FILE_TOO_BIG; + } + + limit = fs->blocksize >> 2; + + ctx.fs = fs; + ctx.func = func; + ctx.priv_data = priv_data; + ctx.flags = flags; + ctx.bcount = 0; + if (block_buf) { + ctx.ind_buf = block_buf; + } else { + retval = ext2fs_get_array(3, fs->blocksize, &ctx.ind_buf); + if (retval) + return retval; + } + ctx.dind_buf = ctx.ind_buf + fs->blocksize; + ctx.tind_buf = ctx.dind_buf + fs->blocksize; + + /* + * Iterate over the HURD translator block (if present) + */ + if ((fs->super->s_creator_os == EXT2_OS_HURD) && + !(flags & BLOCK_FLAG_DATA_ONLY)) { + if (inode.osd1.hurd1.h_i_translator) { + blk64 = inode.osd1.hurd1.h_i_translator; + ret |= (*ctx.func)(fs, &blk64, + BLOCK_COUNT_TRANSLATOR, + 0, 0, priv_data); + inode.osd1.hurd1.h_i_translator = (blk_t) blk64; + if (ret & BLOCK_ABORT) + goto abort_exit; + check_for_ro_violation_goto(&ctx, ret, abort_exit); + } + } + + if (inode.i_flags & EXT4_EXTENTS_FL) { + ext2_extent_handle_t handle; + struct ext2fs_extent extent; + e2_blkcnt_t blockcnt = 0; + blk64_t blk, new_blk; + int op = EXT2_EXTENT_ROOT; + int uninit; + unsigned int j; + + ctx.errcode = ext2fs_extent_open2(fs, ino, &inode, &handle); + if (ctx.errcode) + goto abort_exit; + + while (1) { + ctx.errcode = ext2fs_extent_get(handle, op, &extent); + if (ctx.errcode) { + if (ctx.errcode != EXT2_ET_EXTENT_NO_NEXT) + break; + ctx.errcode = 0; + if (!(flags & BLOCK_FLAG_APPEND)) + break; + next_block_set: + blk = 0; + r = (*ctx.func)(fs, &blk, blockcnt, + 0, 0, priv_data); + ret |= r; + check_for_ro_violation_goto(&ctx, ret, + extent_errout); + if (r & BLOCK_CHANGED) { + ctx.errcode = + ext2fs_extent_set_bmap(handle, + (blk64_t) blockcnt++, + (blk64_t) blk, 0); + if (ctx.errcode || (ret & BLOCK_ABORT)) + break; + if (blk) + goto next_block_set; + } + break; + } + + op = EXT2_EXTENT_NEXT; + blk = extent.e_pblk; + if (!(extent.e_flags & EXT2_EXTENT_FLAGS_LEAF)) { + if (ctx.flags & BLOCK_FLAG_DATA_ONLY) + continue; + if ((!(extent.e_flags & + EXT2_EXTENT_FLAGS_SECOND_VISIT) && + !(ctx.flags & BLOCK_FLAG_DEPTH_TRAVERSE)) || + ((extent.e_flags & + EXT2_EXTENT_FLAGS_SECOND_VISIT) && + (ctx.flags & BLOCK_FLAG_DEPTH_TRAVERSE))) { + ret |= (*ctx.func)(fs, &blk, + -1, 0, 0, priv_data); + if (ret & BLOCK_CHANGED) { + extent.e_pblk = blk; + ctx.errcode = + ext2fs_extent_replace(handle, 0, &extent); + if (ctx.errcode) + break; + } + } + continue; + } + uninit = 0; + if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + uninit = EXT2_EXTENT_SET_BMAP_UNINIT; + for (blockcnt = extent.e_lblk, j = 0; + j < extent.e_len; + blk++, blockcnt++, j++) { + new_blk = blk; + r = (*ctx.func)(fs, &new_blk, blockcnt, + 0, 0, priv_data); + ret |= r; + check_for_ro_violation_goto(&ctx, ret, + extent_errout); + if (r & BLOCK_CHANGED) { + ctx.errcode = + ext2fs_extent_set_bmap(handle, + (blk64_t) blockcnt, + new_blk, uninit); + if (ctx.errcode) + goto extent_errout; + } + if (ret & BLOCK_ABORT) + break; + } + } + + extent_errout: + ext2fs_extent_free(handle); + ret |= BLOCK_ERROR | BLOCK_ABORT; + goto errout; + } + + /* + * Iterate over normal data blocks + */ + for (i = 0; i < EXT2_NDIR_BLOCKS ; i++, ctx.bcount++) { + if (inode.i_block[i] || (flags & BLOCK_FLAG_APPEND)) { + blk64 = inode.i_block[i]; + ret |= (*ctx.func)(fs, &blk64, ctx.bcount, 0, i, + priv_data); + inode.i_block[i] = (blk_t) blk64; + if (ret & BLOCK_ABORT) + goto abort_exit; + } + } + check_for_ro_violation_goto(&ctx, ret, abort_exit); + if (inode.i_block[EXT2_IND_BLOCK] || (flags & BLOCK_FLAG_APPEND)) { + ret |= block_iterate_ind(&inode.i_block[EXT2_IND_BLOCK], + 0, EXT2_IND_BLOCK, &ctx); + if (ret & BLOCK_ABORT) + goto abort_exit; + } else + ctx.bcount += limit; + if (inode.i_block[EXT2_DIND_BLOCK] || (flags & BLOCK_FLAG_APPEND)) { + ret |= block_iterate_dind(&inode.i_block[EXT2_DIND_BLOCK], + 0, EXT2_DIND_BLOCK, &ctx); + if (ret & BLOCK_ABORT) + goto abort_exit; + } else + ctx.bcount += limit * limit; + if (inode.i_block[EXT2_TIND_BLOCK] || (flags & BLOCK_FLAG_APPEND)) { + ret |= block_iterate_tind(&inode.i_block[EXT2_TIND_BLOCK], + 0, EXT2_TIND_BLOCK, &ctx); + if (ret & BLOCK_ABORT) + goto abort_exit; + } + +abort_exit: + if (ret & BLOCK_CHANGED) { + retval = ext2fs_write_inode(fs, ino, &inode); + if (retval) { + ret |= BLOCK_ERROR; + ctx.errcode = retval; + } + } +errout: + if (!block_buf) + ext2fs_free_mem(&ctx.ind_buf); + + return (ret & BLOCK_ERROR) ? ctx.errcode : 0; +} + +/* + * Emulate the old ext2fs_block_iterate function! + */ + +struct xlate64 { + int (*func)(ext2_filsys fs, + blk_t *blocknr, + e2_blkcnt_t blockcnt, + blk_t ref_blk, + int ref_offset, + void *priv_data); + void *real_private; +}; + +static int xlate64_func(ext2_filsys fs, blk64_t *blocknr, + e2_blkcnt_t blockcnt, blk64_t ref_blk, + int ref_offset, void *priv_data) +{ + struct xlate64 *xl = (struct xlate64 *) priv_data; + int ret; + blk_t block32 = *blocknr; + + ret = (*xl->func)(fs, &block32, blockcnt, (blk_t) ref_blk, ref_offset, + xl->real_private); + *blocknr = block32; + return ret; +} + +errcode_t ext2fs_block_iterate2(ext2_filsys fs, + ext2_ino_t ino, + int flags, + char *block_buf, + int (*func)(ext2_filsys fs, + blk_t *blocknr, + e2_blkcnt_t blockcnt, + blk_t ref_blk, + int ref_offset, + void *priv_data), + void *priv_data) +{ + struct xlate64 xl; + + xl.real_private = priv_data; + xl.func = func; + + return ext2fs_block_iterate3(fs, ino, flags, block_buf, + xlate64_func, &xl); +} + + +struct xlate { + int (*func)(ext2_filsys fs, + blk_t *blocknr, + int bcount, + void *priv_data); + void *real_private; +}; + +#ifdef __TURBOC__ + #pragma argsused +#endif +static int xlate_func(ext2_filsys fs, blk_t *blocknr, e2_blkcnt_t blockcnt, + blk_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct xlate *xl = (struct xlate *) priv_data; + + return (*xl->func)(fs, blocknr, (int) blockcnt, xl->real_private); +} + +errcode_t ext2fs_block_iterate(ext2_filsys fs, + ext2_ino_t ino, + int flags, + char *block_buf, + int (*func)(ext2_filsys fs, + blk_t *blocknr, + int blockcnt, + void *priv_data), + void *priv_data) +{ + struct xlate xl; + + xl.real_private = priv_data; + xl.func = func; + + return ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_NO_LARGE | flags, + block_buf, xlate_func, &xl); +} + diff --git a/libcustomext2fs/source/bmap.c b/libcustomext2fs/source/bmap.c new file mode 100644 index 00000000..fbcb3753 --- /dev/null +++ b/libcustomext2fs/source/bmap.c @@ -0,0 +1,335 @@ +/* + * bmap.c --- logical to physical block mapping + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +#if defined(__GNUC__) && !defined(NO_INLINE_FUNCS) +#define _BMAP_INLINE_ __inline__ +#else +#define _BMAP_INLINE_ +#endif + +extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char *block_buf, int bmap_flags, + blk_t block, blk_t *phys_blk); + +#define inode_bmap(inode, nr) ((inode)->i_block[(nr)]) + +static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags, + blk_t ind, char *block_buf, + int *blocks_alloc, + blk_t nr, blk_t *ret_blk) +{ + errcode_t retval; + blk_t b; + + if (!ind) { + if (flags & BMAP_SET) + return EXT2_ET_SET_BMAP_NO_IND; + *ret_blk = 0; + return 0; + } + retval = io_channel_read_blk(fs->io, ind, 1, block_buf); + if (retval) + return retval; + + if (flags & BMAP_SET) { + b = *ret_blk; +#ifdef WORDS_BIGENDIAN + b = ext2fs_swab32(b); +#endif + ((blk_t *) block_buf)[nr] = b; + return io_channel_write_blk(fs->io, ind, 1, block_buf); + } + + b = ((blk_t *) block_buf)[nr]; + +#ifdef WORDS_BIGENDIAN + b = ext2fs_swab32(b); +#endif + + if (!b && (flags & BMAP_ALLOC)) { + b = nr ? ((blk_t *) block_buf)[nr-1] : 0; + retval = ext2fs_alloc_block(fs, b, + block_buf + fs->blocksize, &b); + if (retval) + return retval; + +#ifdef WORDS_BIGENDIAN + ((blk_t *) block_buf)[nr] = ext2fs_swab32(b); +#else + ((blk_t *) block_buf)[nr] = b; +#endif + + retval = io_channel_write_blk(fs->io, ind, 1, block_buf); + if (retval) + return retval; + + (*blocks_alloc)++; + } + + *ret_blk = b; + return 0; +} + +static _BMAP_INLINE_ errcode_t block_dind_bmap(ext2_filsys fs, int flags, + blk_t dind, char *block_buf, + int *blocks_alloc, + blk_t nr, blk_t *ret_blk) +{ + blk_t b; + errcode_t retval; + blk_t addr_per_block; + + addr_per_block = (blk_t) fs->blocksize >> 2; + + retval = block_ind_bmap(fs, flags & ~BMAP_SET, dind, block_buf, + blocks_alloc, nr / addr_per_block, &b); + if (retval) + return retval; + retval = block_ind_bmap(fs, flags, b, block_buf, blocks_alloc, + nr % addr_per_block, ret_blk); + return retval; +} + +static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, + blk_t tind, char *block_buf, + int *blocks_alloc, + blk_t nr, blk_t *ret_blk) +{ + blk_t b; + errcode_t retval; + blk_t addr_per_block; + + addr_per_block = (blk_t) fs->blocksize >> 2; + + retval = block_dind_bmap(fs, flags & ~BMAP_SET, tind, block_buf, + blocks_alloc, nr / addr_per_block, &b); + if (retval) + return retval; + retval = block_ind_bmap(fs, flags, b, block_buf, blocks_alloc, + nr % addr_per_block, ret_blk); + return retval; +} + +errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, + char *block_buf, int bmap_flags, blk64_t block, + int *ret_flags, blk64_t *phys_blk) +{ + struct ext2_inode inode_buf; + ext2_extent_handle_t handle = 0; + blk_t addr_per_block; + blk_t b, blk32; + char *buf = 0; + errcode_t retval = 0; + int blocks_alloc = 0, inode_dirty = 0; + + if (!(bmap_flags & BMAP_SET)) + *phys_blk = 0; + + if (ret_flags) + *ret_flags = 0; + + /* Read inode structure if necessary */ + if (!inode) { + retval = ext2fs_read_inode(fs, ino, &inode_buf); + if (retval) + return retval; + inode = &inode_buf; + } + addr_per_block = (blk_t) fs->blocksize >> 2; + + if (inode->i_flags & EXT4_EXTENTS_FL) { + struct ext2fs_extent extent; + unsigned int offset; + + retval = ext2fs_extent_open2(fs, ino, inode, &handle); + if (retval) + goto done; + if (bmap_flags & BMAP_SET) { + retval = ext2fs_extent_set_bmap(handle, block, + *phys_blk, 0); + goto done; + } + retval = ext2fs_extent_goto(handle, block); + if (retval) { + /* If the extent is not found, return phys_blk = 0 */ + if (retval == EXT2_ET_EXTENT_NOT_FOUND) + goto got_block; + goto done; + } + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + goto done; + offset = block - extent.e_lblk; + if (block >= extent.e_lblk && (offset <= extent.e_len)) { + *phys_blk = extent.e_pblk + offset; + if (ret_flags && extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + *ret_flags |= BMAP_RET_UNINIT; + } + got_block: + if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { + retval = ext2fs_alloc_block(fs, b, block_buf, &b); + if (retval) + goto done; + retval = ext2fs_extent_set_bmap(handle, block, + (blk64_t) b, 0); + if (retval) + goto done; + /* Update inode after setting extent */ + retval = ext2fs_read_inode(fs, ino, inode); + if (retval) + return retval; + blocks_alloc++; + *phys_blk = b; + } + retval = 0; + goto done; + } + + if (!block_buf) { + retval = ext2fs_get_array(2, fs->blocksize, &buf); + if (retval) + return retval; + block_buf = buf; + } + + if (block < EXT2_NDIR_BLOCKS) { + if (bmap_flags & BMAP_SET) { + b = *phys_blk; + inode_bmap(inode, block) = b; + inode_dirty++; + goto done; + } + + *phys_blk = inode_bmap(inode, block); + b = block ? inode_bmap(inode, block-1) : 0; + + if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { + retval = ext2fs_alloc_block(fs, b, block_buf, &b); + if (retval) + goto done; + inode_bmap(inode, block) = b; + blocks_alloc++; + *phys_blk = b; + } + goto done; + } + + /* Indirect block */ + block -= EXT2_NDIR_BLOCKS; + blk32 = *phys_blk; + if (block < addr_per_block) { + b = inode_bmap(inode, EXT2_IND_BLOCK); + if (!b) { + if (!(bmap_flags & BMAP_ALLOC)) { + if (bmap_flags & BMAP_SET) + retval = EXT2_ET_SET_BMAP_NO_IND; + goto done; + } + + b = inode_bmap(inode, EXT2_IND_BLOCK-1); + retval = ext2fs_alloc_block(fs, b, block_buf, &b); + if (retval) + goto done; + inode_bmap(inode, EXT2_IND_BLOCK) = b; + blocks_alloc++; + } + retval = block_ind_bmap(fs, bmap_flags, b, block_buf, + &blocks_alloc, block, &blk32); + if (retval == 0) + *phys_blk = blk32; + goto done; + } + + /* Doubly indirect block */ + block -= addr_per_block; + if (block < addr_per_block * addr_per_block) { + b = inode_bmap(inode, EXT2_DIND_BLOCK); + if (!b) { + if (!(bmap_flags & BMAP_ALLOC)) { + if (bmap_flags & BMAP_SET) + retval = EXT2_ET_SET_BMAP_NO_IND; + goto done; + } + + b = inode_bmap(inode, EXT2_IND_BLOCK); + retval = ext2fs_alloc_block(fs, b, block_buf, &b); + if (retval) + goto done; + inode_bmap(inode, EXT2_DIND_BLOCK) = b; + blocks_alloc++; + } + retval = block_dind_bmap(fs, bmap_flags, b, block_buf, + &blocks_alloc, block, &blk32); + if (retval == 0) + *phys_blk = blk32; + goto done; + } + + /* Triply indirect block */ + block -= addr_per_block * addr_per_block; + b = inode_bmap(inode, EXT2_TIND_BLOCK); + if (!b) { + if (!(bmap_flags & BMAP_ALLOC)) { + if (bmap_flags & BMAP_SET) + retval = EXT2_ET_SET_BMAP_NO_IND; + goto done; + } + + b = inode_bmap(inode, EXT2_DIND_BLOCK); + retval = ext2fs_alloc_block(fs, b, block_buf, &b); + if (retval) + goto done; + inode_bmap(inode, EXT2_TIND_BLOCK) = b; + blocks_alloc++; + } + retval = block_tind_bmap(fs, bmap_flags, b, block_buf, + &blocks_alloc, block, &blk32); + if (retval == 0) + *phys_blk = blk32; +done: + if (buf) + ext2fs_free_mem(&buf); + if (handle) + ext2fs_extent_free(handle); + if ((retval == 0) && (blocks_alloc || inode_dirty)) { + ext2fs_iblk_add_blocks(fs, inode, blocks_alloc); + retval = ext2fs_write_inode(fs, ino, inode); + } + return retval; +} + +errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, + char *block_buf, int bmap_flags, blk_t block, + blk_t *phys_blk) +{ + errcode_t ret; + blk64_t ret_blk = *phys_blk; + + ret = ext2fs_bmap2(fs, ino, inode, block_buf, bmap_flags, block, + 0, &ret_blk); + if (ret) + return ret; + if (ret_blk >= ((long long) 1 << 32)) + return EOVERFLOW; + *phys_blk = ret_blk; + return 0; +} diff --git a/libcustomext2fs/source/bmap64.h b/libcustomext2fs/source/bmap64.h new file mode 100644 index 00000000..b0aa84c1 --- /dev/null +++ b/libcustomext2fs/source/bmap64.h @@ -0,0 +1,61 @@ +/* + * bmap64.h --- 64-bit bitmap structure + * + * Copyright (C) 2007, 2008 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +struct ext2fs_struct_generic_bitmap { + errcode_t magic; + ext2_filsys fs; + struct ext2_bitmap_ops *bitmap_ops; + int flags; + __u64 start, end; + __u64 real_end; + char *description; + void *private; + errcode_t base_error_code; +}; + +#define EXT2FS_IS_32_BITMAP(bmap) \ + (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP) || \ + ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP) || \ + ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP)) + +#define EXT2FS_IS_64_BITMAP(bmap) \ + (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP64) || \ + ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP64) || \ + ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP64)) + +struct ext2_bitmap_ops { + int type; + /* Generic bmap operators */ + errcode_t (*new_bmap)(ext2_filsys fs, ext2fs_generic_bitmap bmap); + void (*free_bmap)(ext2fs_generic_bitmap bitmap); + errcode_t (*copy_bmap)(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap dest); + errcode_t (*resize_bmap)(ext2fs_generic_bitmap bitmap, + __u64 new_end, + __u64 new_real_end); + /* bit set/test operators */ + int (*mark_bmap)(ext2fs_generic_bitmap bitmap, __u64 arg); + int (*unmark_bmap)(ext2fs_generic_bitmap bitmap, __u64 arg); + int (*test_bmap)(ext2fs_generic_bitmap bitmap, __u64 arg); + void (*mark_bmap_extent)(ext2fs_generic_bitmap bitmap, __u64 arg, + unsigned int num); + void (*unmark_bmap_extent)(ext2fs_generic_bitmap bitmap, __u64 arg, + unsigned int num); + int (*test_clear_bmap_extent)(ext2fs_generic_bitmap bitmap, + __u64 arg, unsigned int num); + errcode_t (*set_bmap_range)(ext2fs_generic_bitmap bitmap, + __u64 start, size_t num, void *in); + errcode_t (*get_bmap_range)(ext2fs_generic_bitmap bitmap, + __u64 start, size_t num, void *out); + void (*clear_bmap)(ext2fs_generic_bitmap bitmap); +}; + +extern struct ext2_bitmap_ops ext2fs_blkmap64_bitarray; diff --git a/libcustomext2fs/source/bmove.c b/libcustomext2fs/source/bmove.c new file mode 100644 index 00000000..deabf38c --- /dev/null +++ b/libcustomext2fs/source/bmove.c @@ -0,0 +1,166 @@ +/* + * bmove.c --- Move blocks around to make way for a particular + * filesystem structure. + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_SYS_TIME_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" + +struct process_block_struct { + ext2_ino_t ino; + struct ext2_inode * inode; + ext2fs_block_bitmap reserve; + ext2fs_block_bitmap alloc_map; + errcode_t error; + char *buf; + int add_dir; + int flags; +}; + +static int process_block(ext2_filsys fs, blk64_t *block_nr, + e2_blkcnt_t blockcnt, blk64_t ref_block, + int ref_offset, void *priv_data) +{ + struct process_block_struct *pb; + errcode_t retval; + int ret; + blk64_t block, orig; + + pb = (struct process_block_struct *) priv_data; + block = orig = *block_nr; + ret = 0; + + /* + * Let's see if this is one which we need to relocate + */ + if (ext2fs_test_block_bitmap2(pb->reserve, block)) { + do { + if (++block >= ext2fs_blocks_count(fs->super)) + block = fs->super->s_first_data_block; + if (block == orig) { + pb->error = EXT2_ET_BLOCK_ALLOC_FAIL; + return BLOCK_ABORT; + } + } while (ext2fs_test_block_bitmap2(pb->reserve, block) || + ext2fs_test_block_bitmap2(pb->alloc_map, block)); + + retval = io_channel_read_blk64(fs->io, orig, 1, pb->buf); + if (retval) { + pb->error = retval; + return BLOCK_ABORT; + } + retval = io_channel_write_blk64(fs->io, block, 1, pb->buf); + if (retval) { + pb->error = retval; + return BLOCK_ABORT; + } + *block_nr = block; + ext2fs_mark_block_bitmap2(pb->alloc_map, block); + ret = BLOCK_CHANGED; + if (pb->flags & EXT2_BMOVE_DEBUG) + printf("ino=%u, blockcnt=%lld, %llu->%llu\n", + (unsigned) pb->ino, blockcnt, + (unsigned long long) orig, + (unsigned long long) block); + } + if (pb->add_dir) { + retval = ext2fs_add_dir_block2(fs->dblist, pb->ino, + block, blockcnt); + if (retval) { + pb->error = retval; + ret |= BLOCK_ABORT; + } + } + return ret; +} + +errcode_t ext2fs_move_blocks(ext2_filsys fs, + ext2fs_block_bitmap reserve, + ext2fs_block_bitmap alloc_map, + int flags) +{ + ext2_ino_t ino; + struct ext2_inode inode; + errcode_t retval; + struct process_block_struct pb; + ext2_inode_scan scan; + char *block_buf; + + retval = ext2fs_open_inode_scan(fs, 0, &scan); + if (retval) + return retval; + + pb.reserve = reserve; + pb.error = 0; + pb.alloc_map = alloc_map ? alloc_map : fs->block_map; + pb.flags = flags; + + retval = ext2fs_get_array(4, fs->blocksize, &block_buf); + if (retval) + return retval; + pb.buf = block_buf + fs->blocksize * 3; + + /* + * If GET_DBLIST is set in the flags field, then we should + * gather directory block information while we're doing the + * block move. + */ + if (flags & EXT2_BMOVE_GET_DBLIST) { + if (fs->dblist) { + ext2fs_free_dblist(fs->dblist); + fs->dblist = NULL; + } + retval = ext2fs_init_dblist(fs, 0); + if (retval) + return retval; + } + + retval = ext2fs_get_next_inode(scan, &ino, &inode); + if (retval) + return retval; + + while (ino) { + if ((inode.i_links_count == 0) || + !ext2fs_inode_has_valid_blocks(&inode)) + goto next; + + pb.ino = ino; + pb.inode = &inode; + + pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) && + flags & EXT2_BMOVE_GET_DBLIST); + + retval = ext2fs_block_iterate3(fs, ino, 0, block_buf, + process_block, &pb); + if (retval) + return retval; + if (pb.error) + return pb.error; + + next: + retval = ext2fs_get_next_inode(scan, &ino, &inode); + if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) + goto next; + } + return 0; +} + diff --git a/libcustomext2fs/source/brel.h b/libcustomext2fs/source/brel.h new file mode 100644 index 00000000..a0dd5b9c --- /dev/null +++ b/libcustomext2fs/source/brel.h @@ -0,0 +1,86 @@ +/* + * brel.h + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +struct ext2_block_relocate_entry { + blk_t new; + __s16 offset; + __u16 flags; + union { + blk_t block_ref; + ext2_ino_t inode_ref; + } owner; +}; + +#define RELOCATE_TYPE_REF 0x0007 +#define RELOCATE_BLOCK_REF 0x0001 +#define RELOCATE_INODE_REF 0x0002 + +typedef struct ext2_block_relocation_table *ext2_brel; + +struct ext2_block_relocation_table { + __u32 magic; + char *name; + blk_t current; + void *priv_data; + + /* + * Add a block relocation entry. + */ + errcode_t (*put)(ext2_brel brel, blk_t old, + struct ext2_block_relocate_entry *ent); + + /* + * Get a block relocation entry. + */ + errcode_t (*get)(ext2_brel brel, blk_t old, + struct ext2_block_relocate_entry *ent); + + /* + * Initialize for iterating over the block relocation entries. + */ + errcode_t (*start_iter)(ext2_brel brel); + + /* + * The iterator function for the inode relocation entries. + * Returns an inode number of 0 when out of entries. + */ + errcode_t (*next)(ext2_brel brel, blk_t *old, + struct ext2_block_relocate_entry *ent); + + /* + * Move the inode relocation table from one block number to + * another. + */ + errcode_t (*move)(ext2_brel brel, blk_t old, blk_t new); + + /* + * Remove a block relocation entry. + */ + errcode_t (*delete)(ext2_brel brel, blk_t old); + + + /* + * Free the block relocation table. + */ + errcode_t (*free)(ext2_brel brel); +}; + +errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block, + ext2_brel *brel); + +#define ext2fs_brel_put(brel, old, ent) ((brel)->put((brel), old, ent)) +#define ext2fs_brel_get(brel, old, ent) ((brel)->get((brel), old, ent)) +#define ext2fs_brel_start_iter(brel) ((brel)->start_iter((brel))) +#define ext2fs_brel_next(brel, old, ent) ((brel)->next((brel), old, ent)) +#define ext2fs_brel_move(brel, old, new) ((brel)->move((brel), old, new)) +#define ext2fs_brel_delete(brel, old) ((brel)->delete((brel), old)) +#define ext2fs_brel_free(brel) ((brel)->free((brel))) + diff --git a/libcustomext2fs/source/brel_ma.c b/libcustomext2fs/source/brel_ma.c new file mode 100644 index 00000000..1a55702b --- /dev/null +++ b/libcustomext2fs/source/brel_ma.c @@ -0,0 +1,198 @@ +/* + * brel_ma.c + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * TODO: rewrite to not use a direct array!!! (Fortunately this + * module isn't really used yet.) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "brel.h" + +static errcode_t bma_put(ext2_brel brel, blk_t old, + struct ext2_block_relocate_entry *ent); +static errcode_t bma_get(ext2_brel brel, blk_t old, + struct ext2_block_relocate_entry *ent); +static errcode_t bma_start_iter(ext2_brel brel); +static errcode_t bma_next(ext2_brel brel, blk_t *old, + struct ext2_block_relocate_entry *ent); +static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new); +static errcode_t bma_delete(ext2_brel brel, blk_t old); +static errcode_t bma_free(ext2_brel brel); + +struct brel_ma { + __u32 magic; + blk_t max_block; + struct ext2_block_relocate_entry *entries; +}; + +errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block, + ext2_brel *new_brel) +{ + ext2_brel brel = 0; + errcode_t retval; + struct brel_ma *ma = 0; + size_t size; + + *new_brel = 0; + + /* + * Allocate memory structures + */ + retval = ext2fs_get_mem(sizeof(struct ext2_block_relocation_table), + &brel); + if (retval) + goto errout; + memset(brel, 0, sizeof(struct ext2_block_relocation_table)); + + retval = ext2fs_get_mem(strlen(name)+1, &brel->name); + if (retval) + goto errout; + strcpy(brel->name, name); + + retval = ext2fs_get_mem(sizeof(struct brel_ma), &ma); + if (retval) + goto errout; + memset(ma, 0, sizeof(struct brel_ma)); + brel->priv_data = ma; + + size = (size_t) (sizeof(struct ext2_block_relocate_entry) * + (max_block+1)); + retval = ext2fs_get_array(max_block+1, + sizeof(struct ext2_block_relocate_entry), &ma->entries); + if (retval) + goto errout; + memset(ma->entries, 0, size); + ma->max_block = max_block; + + /* + * Fill in the brel data structure + */ + brel->put = bma_put; + brel->get = bma_get; + brel->start_iter = bma_start_iter; + brel->next = bma_next; + brel->move = bma_move; + brel->delete = bma_delete; + brel->free = bma_free; + + *new_brel = brel; + return 0; + +errout: + bma_free(brel); + return retval; +} + +static errcode_t bma_put(ext2_brel brel, blk_t old, + struct ext2_block_relocate_entry *ent) +{ + struct brel_ma *ma; + + ma = brel->priv_data; + if (old > ma->max_block) + return EXT2_ET_INVALID_ARGUMENT; + ma->entries[(unsigned)old] = *ent; + return 0; +} + +static errcode_t bma_get(ext2_brel brel, blk_t old, + struct ext2_block_relocate_entry *ent) +{ + struct brel_ma *ma; + + ma = brel->priv_data; + if (old > ma->max_block) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned)old].new == 0) + return ENOENT; + *ent = ma->entries[old]; + return 0; +} + +static errcode_t bma_start_iter(ext2_brel brel) +{ + brel->current = 0; + return 0; +} + +static errcode_t bma_next(ext2_brel brel, blk_t *old, + struct ext2_block_relocate_entry *ent) +{ + struct brel_ma *ma; + + ma = brel->priv_data; + while (++brel->current < ma->max_block) { + if (ma->entries[(unsigned)brel->current].new == 0) + continue; + *old = brel->current; + *ent = ma->entries[(unsigned)brel->current]; + return 0; + } + *old = 0; + return 0; +} + +static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new) +{ + struct brel_ma *ma; + + ma = brel->priv_data; + if ((old > ma->max_block) || (new > ma->max_block)) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned)old].new == 0) + return ENOENT; + ma->entries[(unsigned)new] = ma->entries[old]; + ma->entries[(unsigned)old].new = 0; + return 0; +} + +static errcode_t bma_delete(ext2_brel brel, blk_t old) +{ + struct brel_ma *ma; + + ma = brel->priv_data; + if (old > ma->max_block) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned)old].new == 0) + return ENOENT; + ma->entries[(unsigned)old].new = 0; + return 0; +} + +static errcode_t bma_free(ext2_brel brel) +{ + struct brel_ma *ma; + + if (!brel) + return 0; + + ma = brel->priv_data; + + if (ma) { + if (ma->entries) + ext2fs_free_mem(&ma->entries); + ext2fs_free_mem(&ma); + } + if (brel->name) + ext2fs_free_mem(&brel->name); + ext2fs_free_mem(&brel); + return 0; +} diff --git a/libcustomext2fs/source/check_desc.c b/libcustomext2fs/source/check_desc.c new file mode 100644 index 00000000..7929cd95 --- /dev/null +++ b/libcustomext2fs/source/check_desc.c @@ -0,0 +1,103 @@ +/* + * check_desc.c --- Check the group descriptors of an ext2 filesystem + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * This routine sanity checks the group descriptors + */ +errcode_t ext2fs_check_desc(ext2_filsys fs) +{ + ext2fs_block_bitmap bmap; + errcode_t retval; + dgrp_t i; + blk64_t first_block = fs->super->s_first_data_block; + blk64_t last_block = ext2fs_blocks_count(fs->super)-1; + blk64_t blk, b; + int j; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_allocate_block_bitmap(fs, "check_desc map", &bmap); + if (retval) + return retval; + + for (i = 0; i < fs->group_desc_count; i++) + ext2fs_reserve_super_and_bgd(fs, i, bmap); + + for (i = 0; i < fs->group_desc_count; i++) { + if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super, + EXT4_FEATURE_INCOMPAT_FLEX_BG)) { + first_block = ext2fs_group_first_block2(fs, i); + last_block = ext2fs_group_last_block2(fs, i); + if (i == (fs->group_desc_count - 1)) + last_block = ext2fs_blocks_count(fs->super)-1; + } + + /* + * Check to make sure the block bitmap for group is sane + */ + blk = ext2fs_block_bitmap_loc(fs, i); + if (blk < first_block || blk > last_block || + ext2fs_test_block_bitmap2(bmap, blk)) { + retval = EXT2_ET_GDESC_BAD_BLOCK_MAP; + goto errout; + } + ext2fs_mark_block_bitmap2(bmap, blk); + + /* + * Check to make sure the inode bitmap for group is sane + */ + blk = ext2fs_inode_bitmap_loc(fs, i); + if (blk < first_block || blk > last_block || + ext2fs_test_block_bitmap2(bmap, blk)) { + retval = EXT2_ET_GDESC_BAD_INODE_MAP; + goto errout; + } + ext2fs_mark_block_bitmap2(bmap, blk); + + /* + * Check to make sure the inode table for group is sane + */ + blk = ext2fs_inode_table_loc(fs, i); + if (blk < first_block || + ((blk + fs->inode_blocks_per_group - 1) > last_block)) { + retval = EXT2_ET_GDESC_BAD_INODE_TABLE; + goto errout; + } + for (j = 0, b = blk; j < fs->inode_blocks_per_group; + j++, b++) { + if (ext2fs_test_block_bitmap2(bmap, b)) { + retval = EXT2_ET_GDESC_BAD_INODE_TABLE; + goto errout; + } + ext2fs_mark_block_bitmap2(bmap, b); + } + } +errout: + ext2fs_free_block_bitmap(bmap); + return retval; +} diff --git a/libcustomext2fs/source/closefs.c b/libcustomext2fs/source/closefs.c new file mode 100644 index 00000000..8242622b --- /dev/null +++ b/libcustomext2fs/source/closefs.c @@ -0,0 +1,461 @@ +/* + * closefs.c --- close an ext2 filesystem + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fsP.h" + +static int test_root(int a, int b) +{ + if (a == 0) + return 1; + while (1) { + if (a == 1) + return 1; + if (a % b) + return 0; + a = a / b; + } +} + +int ext2fs_bg_has_super(ext2_filsys fs, int group_block) +{ + if (!(fs->super->s_feature_ro_compat & + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) + return 1; + + if (test_root(group_block, 3) || (test_root(group_block, 5)) || + test_root(group_block, 7)) + return 1; + + return 0; +} + +/* + * ext2fs_super_and_bgd_loc2() + * @fs: ext2 fs pointer + * @group given block group + * @ret_super_blk: if !NULL, returns super block location + * @ret_old_desc_blk: if !NULL, returns location of the old block + * group descriptor + * @ret_new_desc_blk: if !NULL, returns location of meta_bg block + * group descriptor + * @ret_used_blks: if !NULL, returns number of blocks used by + * super block and group_descriptors. + * + * Returns errcode_t of 0 + */ +errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs, + dgrp_t group, + blk64_t *ret_super_blk, + blk64_t *ret_old_desc_blk, + blk64_t *ret_new_desc_blk, + blk_t *ret_used_blks) +{ + blk64_t group_block, super_blk = 0, old_desc_blk = 0, new_desc_blk = 0; + unsigned int meta_bg, meta_bg_size; + blk_t numblocks = 0; + blk64_t old_desc_blocks; + int has_super; + + group_block = ext2fs_group_first_block2(fs, group); + + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + old_desc_blocks = fs->super->s_first_meta_bg; + else + old_desc_blocks = + fs->desc_blocks + fs->super->s_reserved_gdt_blocks; + + has_super = ext2fs_bg_has_super(fs, group); + + if (has_super) { + super_blk = group_block; + numblocks++; + } + meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super); + meta_bg = group / meta_bg_size; + + if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) || + (meta_bg < fs->super->s_first_meta_bg)) { + if (has_super) { + old_desc_blk = group_block + 1; + numblocks += old_desc_blocks; + } + } else { + if (((group % meta_bg_size) == 0) || + ((group % meta_bg_size) == 1) || + ((group % meta_bg_size) == (meta_bg_size-1))) { + if (has_super) + has_super = 1; + new_desc_blk = group_block + has_super; + numblocks++; + } + } + + if (ret_super_blk) + *ret_super_blk = super_blk; + if (ret_old_desc_blk) + *ret_old_desc_blk = old_desc_blk; + if (ret_new_desc_blk) + *ret_new_desc_blk = new_desc_blk; + if (ret_used_blks) + *ret_used_blks = numblocks; + + return 0; +} + +/* + * This function returns the location of the superblock, block group + * descriptors for a given block group. It currently returns the + * number of free blocks assuming that inode table and allocation + * bitmaps will be in the group. This is not necessarily the case + * when the flex_bg feature is enabled, so callers should take care! + * It was only really intended for use by mke2fs, and even there it's + * not that useful. + * + * The ext2fs_super_and_bgd_loc2() function is 64-bit block number + * capable and returns the number of blocks used by super block and + * group descriptors. + */ +int ext2fs_super_and_bgd_loc(ext2_filsys fs, + dgrp_t group, + blk_t *ret_super_blk, + blk_t *ret_old_desc_blk, + blk_t *ret_new_desc_blk, + int *ret_meta_bg) +{ + blk64_t ret_super_blk2; + blk64_t ret_old_desc_blk2; + blk64_t ret_new_desc_blk2; + blk_t ret_used_blks; + blk_t numblocks; + unsigned int meta_bg_size; + + ext2fs_super_and_bgd_loc2(fs, group, &ret_super_blk2, + &ret_old_desc_blk2, + &ret_new_desc_blk2, + &ret_used_blks); + + if (group == fs->group_desc_count-1) { + numblocks = (ext2fs_blocks_count(fs->super) - + (blk64_t) fs->super->s_first_data_block) % + (blk64_t) fs->super->s_blocks_per_group; + if (!numblocks) + numblocks = fs->super->s_blocks_per_group; + } else + numblocks = fs->super->s_blocks_per_group; + + if (ret_super_blk) + *ret_super_blk = (blk_t)ret_super_blk2; + if (ret_old_desc_blk) + *ret_old_desc_blk = (blk_t)ret_old_desc_blk2; + if (ret_new_desc_blk) + *ret_new_desc_blk = (blk_t)ret_new_desc_blk2; + if (ret_meta_bg) { + meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super); + *ret_meta_bg = group / meta_bg_size; + } + + numblocks -= 2 + fs->inode_blocks_per_group + ret_used_blks; + + return numblocks; +} + +/* + * This function forces out the primary superblock. We need to only + * write out those fields which we have changed, since if the + * filesystem is mounted, it may have changed some of the other + * fields. + * + * It takes as input a superblock which has already been byte swapped + * (if necessary). + * + */ +static errcode_t write_primary_superblock(ext2_filsys fs, + struct ext2_super_block *super) +{ + __u16 *old_super, *new_super; + int check_idx, write_idx, size; + errcode_t retval; + + if (!fs->io->manager->write_byte || !fs->orig_super) { + fallback: + io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET); + retval = io_channel_write_blk64(fs->io, 1, -SUPERBLOCK_SIZE, + super); + io_channel_set_blksize(fs->io, fs->blocksize); + return retval; + } + + old_super = (__u16 *) fs->orig_super; + new_super = (__u16 *) super; + + for (check_idx = 0; check_idx < SUPERBLOCK_SIZE/2; check_idx++) { + if (old_super[check_idx] == new_super[check_idx]) + continue; + write_idx = check_idx; + for (check_idx++; check_idx < SUPERBLOCK_SIZE/2; check_idx++) + if (old_super[check_idx] == new_super[check_idx]) + break; + size = 2 * (check_idx - write_idx); +#if 0 + printf("Writing %d bytes starting at %d\n", + size, write_idx*2); +#endif + retval = io_channel_write_byte(fs->io, + SUPERBLOCK_OFFSET + (2 * write_idx), size, + new_super + write_idx); + if (retval == EXT2_ET_UNIMPLEMENTED) + goto fallback; + if (retval) + return retval; + } + memcpy(fs->orig_super, super, SUPERBLOCK_SIZE); + return 0; +} + + +/* + * Updates the revision to EXT2_DYNAMIC_REV + */ +void ext2fs_update_dynamic_rev(ext2_filsys fs) +{ + struct ext2_super_block *sb = fs->super; + + if (sb->s_rev_level > EXT2_GOOD_OLD_REV) + return; + + sb->s_rev_level = EXT2_DYNAMIC_REV; + sb->s_first_ino = EXT2_GOOD_OLD_FIRST_INO; + sb->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE; + /* s_uuid is handled by e2fsck already */ + /* other fields should be left alone */ +} + +static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group, + blk_t group_block, + struct ext2_super_block *super_shadow) +{ + dgrp_t sgrp = group; + + if (sgrp > ((1 << 16) - 1)) + sgrp = (1 << 16) - 1; +#ifdef WORDS_BIGENDIAN + super_shadow->s_block_group_nr = ext2fs_swab16(sgrp); +#else + fs->super->s_block_group_nr = sgrp; +#endif + + return io_channel_write_blk64(fs->io, group_block, -SUPERBLOCK_SIZE, + super_shadow); +} + +errcode_t ext2fs_flush(ext2_filsys fs) +{ + dgrp_t i; + errcode_t retval; + unsigned long fs_state; + __u32 feature_incompat; + struct ext2_super_block *super_shadow = 0; + struct ext2_group_desc *group_shadow = 0; +#ifdef WORDS_BIGENDIAN + struct ext2_group_desc *gdp; + dgrp_t j; +#endif + char *group_ptr; + int old_desc_blocks; + struct ext2fs_numeric_progress_struct progress; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + fs_state = fs->super->s_state; + feature_incompat = fs->super->s_feature_incompat; + + fs->super->s_wtime = fs->now ? fs->now : time(NULL); + fs->super->s_block_group_nr = 0; +#ifdef WORDS_BIGENDIAN + retval = EXT2_ET_NO_MEMORY; + retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super_shadow); + if (retval) + goto errout; + retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, + &group_shadow); + if (retval) + goto errout; + memcpy(group_shadow, fs->group_desc, (size_t) fs->blocksize * + fs->desc_blocks); + + /* swap the group descriptors */ + for (j=0; j < fs->group_desc_count; j++) { + gdp = ext2fs_group_desc(fs, (struct opaque_ext2_group_desc *) group_shadow, j); + ext2fs_swap_group_desc2(fs, gdp); + } +#else + super_shadow = fs->super; + group_shadow = ext2fs_group_desc(fs, fs->group_desc, 0); +#endif + + /* + * Set the state of the FS to be non-valid. (The state has + * already been backed up earlier, and will be restored after + * we write out the backup superblocks.) + */ + fs->super->s_state &= ~EXT2_VALID_FS; + fs->super->s_feature_incompat &= ~EXT3_FEATURE_INCOMPAT_RECOVER; +#ifdef WORDS_BIGENDIAN + *super_shadow = *fs->super; + ext2fs_swap_super(super_shadow); +#endif + + /* + * If this is an external journal device, don't write out the + * block group descriptors or any of the backup superblocks + */ + if (fs->super->s_feature_incompat & + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) + goto write_primary_superblock_only; + + /* + * Write out the master group descriptors, and the backup + * superblocks and group descriptors. + */ + group_ptr = (char *) group_shadow; + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + old_desc_blocks = fs->super->s_first_meta_bg; + else + old_desc_blocks = fs->desc_blocks; + + ext2fs_numeric_progress_init(fs, &progress, NULL, + fs->group_desc_count); + + + for (i = 0; i < fs->group_desc_count; i++) { + blk64_t super_blk, old_desc_blk, new_desc_blk; + + ext2fs_numeric_progress_update(fs, &progress, i); + ext2fs_super_and_bgd_loc2(fs, i, &super_blk, &old_desc_blk, + &new_desc_blk, 0); + + if (!(fs->flags & EXT2_FLAG_MASTER_SB_ONLY) &&i && super_blk) { + retval = write_backup_super(fs, i, super_blk, + super_shadow); + if (retval) + goto errout; + } + if (fs->flags & EXT2_FLAG_SUPER_ONLY) + continue; + if ((old_desc_blk) && + (!(fs->flags & EXT2_FLAG_MASTER_SB_ONLY) || (i == 0))) { + retval = io_channel_write_blk64(fs->io, + old_desc_blk, old_desc_blocks, group_ptr); + if (retval) + goto errout; + } + if (new_desc_blk) { + int meta_bg = i / EXT2_DESC_PER_BLOCK(fs->super); + + retval = io_channel_write_blk64(fs->io, new_desc_blk, + 1, group_ptr + (meta_bg*fs->blocksize)); + if (retval) + goto errout; + } + } + + ext2fs_numeric_progress_close(fs, &progress, NULL); + + /* + * If the write_bitmaps() function is present, call it to + * flush the bitmaps. This is done this way so that a simple + * program that doesn't mess with the bitmaps doesn't need to + * drag in the bitmaps.c code. + */ + if (fs->write_bitmaps) { + retval = fs->write_bitmaps(fs); + if (retval) + goto errout; + } + +write_primary_superblock_only: + /* + * Write out master superblock. This has to be done + * separately, since it is located at a fixed location + * (SUPERBLOCK_OFFSET). We flush all other pending changes + * out to disk first, just to avoid a race condition with an + * insy-tinsy window.... + */ + + fs->super->s_block_group_nr = 0; + fs->super->s_state = fs_state; + fs->super->s_feature_incompat = feature_incompat; +#ifdef WORDS_BIGENDIAN + *super_shadow = *fs->super; + ext2fs_swap_super(super_shadow); +#endif + + retval = io_channel_flush(fs->io); + retval = write_primary_superblock(fs, super_shadow); + if (retval) + goto errout; + + fs->flags &= ~EXT2_FLAG_DIRTY; + + retval = io_channel_flush(fs->io); +errout: + fs->super->s_state = fs_state; +#ifdef WORDS_BIGENDIAN + if (super_shadow) + ext2fs_free_mem(&super_shadow); + if (group_shadow) + ext2fs_free_mem(&group_shadow); +#endif + return retval; +} + +errcode_t ext2fs_close(ext2_filsys fs) +{ + errcode_t retval; + int meta_blks; + io_stats stats = 0; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (fs->write_bitmaps) { + retval = fs->write_bitmaps(fs); + if (retval) + return retval; + } + if (fs->super->s_kbytes_written && + fs->io->manager->get_stats) + fs->io->manager->get_stats(fs->io, &stats); + if (stats && stats->bytes_written && (fs->flags & EXT2_FLAG_RW)) { + fs->super->s_kbytes_written += stats->bytes_written >> 10; + meta_blks = fs->desc_blocks + 1; + if (!(fs->flags & EXT2_FLAG_SUPER_ONLY)) + fs->super->s_kbytes_written += meta_blks / + (fs->blocksize / 1024); + if ((fs->flags & EXT2_FLAG_DIRTY) == 0) + fs->flags |= EXT2_FLAG_SUPER_ONLY | EXT2_FLAG_DIRTY; + } + if (fs->flags & EXT2_FLAG_DIRTY) { + retval = ext2fs_flush(fs); + if (retval) + return retval; + } + ext2fs_free(fs); + return 0; +} + diff --git a/libcustomext2fs/source/com_err.c b/libcustomext2fs/source/com_err.c new file mode 100644 index 00000000..c27853e7 --- /dev/null +++ b/libcustomext2fs/source/com_err.c @@ -0,0 +1,35 @@ +/* + * Copyright 1987, 1988 by MIT Student Information Processing Board. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose is hereby granted, provided that + * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. M.I.T. and the + * M.I.T. S.I.P.B. make no representations about the suitability of + * this software for any purpose. It is provided "as is" without + * express or implied warranty. + */ + +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2_internal.h" + +void com_err (const char *whoami, + errcode_t code, + const char *fmt, ...) +{ + if(whoami) + ext2_log_trace("%s: ", whoami); + + ext2_log_trace("error code: %i ", (int) code); + + if(fmt) + ext2_log_trace(fmt); + + ext2_log_trace("\n"); +} diff --git a/libcustomext2fs/source/com_err.h b/libcustomext2fs/source/com_err.h new file mode 100644 index 00000000..0c31a4ec --- /dev/null +++ b/libcustomext2fs/source/com_err.h @@ -0,0 +1,70 @@ +/* + * Header file for common error description library. + * + * Copyright 1988, Student Information Processing Board of the + * Massachusetts Institute of Technology. + * + * For copyright and distribution info, see the documentation supplied + * with this package. + */ + +#if !defined(__COM_ERR_H) && !defined(__COM_ERR_H__) + +#ifdef __GNUC__ +#define COM_ERR_ATTR(x) __attribute__(x) +#else +#define COM_ERR_ATTR(x) +#endif + +#ifndef DEBUG_GEKKO +#define OMIT_COM_ERR +#endif + +#include +#include + +typedef long errcode_t; + +struct error_table { + char const * const * msgs; + long base; + int n_msgs; +}; +struct et_list; + +extern void com_err (const char *, long, const char *, ...) + COM_ERR_ATTR((format(printf, 3, 4))); + +extern void com_err_va (const char *whoami, errcode_t code, const char *fmt, + va_list args) + COM_ERR_ATTR((format(printf, 3, 0))); + +extern char const *error_message (long); +extern void (*com_err_hook) (const char *, long, const char *, va_list); +extern void (*set_com_err_hook (void (*) (const char *, long, + const char *, va_list))) + (const char *, long, const char *, va_list); +extern void (*reset_com_err_hook (void)) (const char *, long, + const char *, va_list); +extern int init_error_table(const char * const *msgs, long base, int count); + +extern errcode_t add_error_table(const struct error_table * et); +extern errcode_t remove_error_table(const struct error_table * et); +extern void add_to_error_table(struct et_list *new_table); + +/* Provided for Heimdall compatibility */ +extern const char *com_right(struct et_list *list, long code); +extern const char *com_right_r(struct et_list *list, long code, char *str, size_t len); +extern void initialize_error_table_r(struct et_list **list, + const char **messages, + int num_errors, + long base); +extern void free_error_table(struct et_list *et); + +/* Provided for compatibility with other com_err libraries */ +extern int et_list_lock(void); +extern int et_list_unlock(void); + +#define __COM_ERR_H +#define __COM_ERR_H__ +#endif /* !defined(__COM_ERR_H) && !defined(__COM_ERR_H__)*/ diff --git a/libcustomext2fs/source/config.h b/libcustomext2fs/source/config.h new file mode 100644 index 00000000..be09663b --- /dev/null +++ b/libcustomext2fs/source/config.h @@ -0,0 +1,10 @@ + +#define HAVE_UNISTD_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_UTIME_H 1 +#define WORDS_BIGENDIAN 1 +#define HAVE_ERRNO_H 1 +#define EXT2_FLAT_INCLUDES 1 +#define HAVE_STRDUP 1 +#define HAVE_SYS_RESOURCE_H 1 diff --git a/libcustomext2fs/source/crc16.c b/libcustomext2fs/source/crc16.c new file mode 100644 index 00000000..02d81e44 --- /dev/null +++ b/libcustomext2fs/source/crc16.c @@ -0,0 +1,73 @@ +/* + * crc16.c + * + * This source code is licensed under the GNU General Public License, + * Version 2. See the file COPYING for more details. + */ + +#if HAVE_SYS_TYPES_H +#include +#endif +#include "ext2_types.h" + +#include "crc16.h" + +/** CRC table for the CRC-16. The poly is 0x8005 (x16 + x15 + x2 + 1) */ +static __u16 const crc16_table[256] = { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 +}; + +/** + * Compute the CRC-16 for the data buffer + * + * @param crc previous CRC value + * @param buffer data pointer + * @param len number of bytes in the buffer + * @return the updated CRC value + */ +crc16_t ext2fs_crc16(crc16_t crc, const void *buffer, unsigned int len) +{ + const unsigned char *cp = buffer; + + while (len--) + /* + * for an unknown reason, PPC treats __u16 as signed + * and keeps doing sign extension on the value. + * Instead, use only the low 16 bits of an unsigned + * int for holding the CRC value to avoid this. + */ + crc = (((crc >> 8) & 0xffU) ^ + crc16_table[(crc ^ *cp++) & 0xffU]) & 0x0000ffffU; + return crc; +} diff --git a/libcustomext2fs/source/crc16.h b/libcustomext2fs/source/crc16.h new file mode 100644 index 00000000..322e68dd --- /dev/null +++ b/libcustomext2fs/source/crc16.h @@ -0,0 +1,26 @@ +/* + * crc16.h - CRC-16 routine + * + * Implements the standard CRC-16: + * Width 16 + * Poly 0x8005 (x16 + x15 + x2 + 1) + * Init 0 + * + * Copyright (c) 2005 Ben Gardner + * + * This source code is licensed under the GNU General Public License, + * Version 2. See the file COPYING for more details. + */ + +#ifndef __CRC16_H +#define __CRC16_H + +/* for an unknown reason, PPC treats __u16 as signed and keeps doing sign + * extension on the value. Instead, use only the low 16 bits of an + * unsigned int for holding the CRC value to avoid this. + */ +typedef unsigned int crc16_t; + +extern crc16_t ext2fs_crc16(crc16_t crc, const void *buffer, unsigned int len); + +#endif /* __CRC16_H */ diff --git a/libcustomext2fs/source/csum.c b/libcustomext2fs/source/csum.c new file mode 100644 index 00000000..0ef9ade5 --- /dev/null +++ b/libcustomext2fs/source/csum.c @@ -0,0 +1,286 @@ +/* + * csum.c --- checksumming of ext3 structures + * + * Copyright (C) 2006 Cluster File Systems, Inc. + * Copyright (C) 2006, 2007 by Andreas Dilger + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "crc16.h" +#include + +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + +#ifdef DEBUG +#define STATIC +#else +#define STATIC static +#endif + +STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group) +{ + __u16 crc = 0; + struct ext2_group_desc *desc; + size_t size; + + size = fs->super->s_desc_size; + if (size < EXT2_MIN_DESC_SIZE) + size = EXT2_MIN_DESC_SIZE; + if (size > sizeof(struct ext4_group_desc)) { + printf("%s: illegal s_desc_size(%zd)\n", __func__, size); + size = sizeof(struct ext4_group_desc); + } + + desc = ext2fs_group_desc(fs, fs->group_desc, group); + + if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { + int offset = offsetof(struct ext2_group_desc, bg_checksum); + +#ifdef WORDS_BIGENDIAN + struct ext4_group_desc swabdesc; + + /* Have to swab back to little-endian to do the checksum */ + memcpy(&swabdesc, desc, size); + ext2fs_swap_group_desc2(fs, + (struct ext2_group_desc *) &swabdesc); + desc = (struct ext2_group_desc *) &swabdesc; + + group = ext2fs_swab32(group); +#endif + crc = ext2fs_crc16(~0, fs->super->s_uuid, + sizeof(fs->super->s_uuid)); + crc = ext2fs_crc16(crc, &group, sizeof(group)); + crc = ext2fs_crc16(crc, desc, offset); + offset += sizeof(desc->bg_checksum); /* skip checksum */ + /* for checksum of struct ext4_group_desc do the rest...*/ + if (offset < size) { + crc = ext2fs_crc16(crc, (char *)desc + offset, + size - offset); + } + } + + return crc; +} + +int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group) +{ + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM) && + (ext2fs_bg_checksum(fs, group) != + ext2fs_group_desc_csum(fs, group))) + return 0; + + return 1; +} + +void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group) +{ + if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) + return; + + /* ext2fs_bg_checksum_set() sets the actual checksum field but + * does not calculate the checksum itself. */ + ext2fs_bg_checksum_set(fs, group, ext2fs_group_desc_csum(fs, group)); +} + +static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap, + __u32 inodes_per_grp, dgrp_t grp_no) +{ + ext2_ino_t i, start_ino, end_ino; + + start_ino = grp_no * inodes_per_grp + 1; + end_ino = start_ino + inodes_per_grp - 1; + + for (i = end_ino; i >= start_ino; i--) { + if (ext2fs_fast_test_inode_bitmap2(bitmap, i)) + return i - start_ino + 1; + } + return inodes_per_grp; +} + +/* update the bitmap flags, set the itable high watermark, and calculate + * checksums for the group descriptors */ +errcode_t ext2fs_set_gdt_csum(ext2_filsys fs) +{ + struct ext2_super_block *sb = fs->super; + int dirty = 0; + dgrp_t i; + + if (!fs->inode_map) + return EXT2_ET_NO_INODE_BITMAP; + + if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) + return 0; + + for (i = 0; i < fs->group_desc_count; i++) { + unsigned int old_csum = ext2fs_bg_checksum(fs, i); + int old_unused = ext2fs_bg_itable_unused(fs, i); + unsigned int old_flags = ext2fs_bg_flags(fs, i); + int old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i); + + if (old_free_inodes_count == sb->s_inodes_per_group) { + ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); + ext2fs_bg_itable_unused_set(fs, i, sb->s_inodes_per_group); + } else { + int unused = + sb->s_inodes_per_group - + find_last_inode_ingrp(fs->inode_map, + sb->s_inodes_per_group, i); + + ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT); + ext2fs_bg_itable_unused_set(fs, i, unused); + } + + ext2fs_group_desc_csum_set(fs, i); + if (old_flags != ext2fs_bg_flags(fs, i)) + dirty = 1; + if (old_unused != ext2fs_bg_itable_unused(fs, i)) + dirty = 1; + if (old_csum != ext2fs_bg_checksum(fs, i)) + dirty = 1; + } + if (dirty) + ext2fs_mark_super_dirty(fs); + return 0; +} + +#ifdef DEBUG +void print_csum(const char *msg, ext2_filsys fs, dgrp_t group) +{ + __u16 crc1, crc2, crc3; + dgrp_t swabgroup; + struct ext2_group_desc *desc = ext2fs_group_desc(fs, fs->group_desc, group); + size_t size; + struct ext2_super_block *sb = fs->super; + int offset = offsetof(struct ext2_group_desc, bg_checksum); +#ifdef WORDS_BIGENDIAN + struct ext4_group_desc swabdesc; +#endif + + size = fs->super->s_desc_size; + if (size < EXT2_MIN_DESC_SIZE) + size = EXT2_MIN_DESC_SIZE; + if (size > sizeof(struct ext4_group_desc)) + size = sizeof(struct ext4_group_desc); +#ifdef WORDS_BIGENDIAN + /* Have to swab back to little-endian to do the checksum */ + memcpy(&swabdesc, desc, size); + ext2fs_swap_group_desc2(fs, (struct ext2_group_desc *) &swabdesc); + desc = (struct ext2_group_desc *) &swabdesc; + + swabgroup = ext2fs_swab32(group); +#else + swabgroup = group; +#endif + + crc1 = ext2fs_crc16(~0, sb->s_uuid, sizeof(fs->super->s_uuid)); + crc2 = ext2fs_crc16(crc1, &swabgroup, sizeof(swabgroup)); + crc3 = ext2fs_crc16(crc2, desc, offset); + offset += sizeof(desc->bg_checksum); /* skip checksum */ + /* for checksum of struct ext4_group_desc do the rest...*/ + if (offset < size) + crc3 = ext2fs_crc16(crc3, (char *)desc + offset, size - offset); + + printf("%s: UUID %016Lx%016Lx(%04x), grp %u(%04x): %04x=%04x\n", + msg, *(long long *)&sb->s_uuid, *(long long *)&sb->s_uuid[8], + crc1, group, crc2, crc3, ext2fs_group_desc_csum(fs, group)); +} + +unsigned char sb_uuid[16] = { 0x4f, 0x25, 0xe8, 0xcf, 0xe7, 0x97, 0x48, 0x23, + 0xbe, 0xfa, 0xa7, 0x88, 0x4b, 0xae, 0xec, 0xdb }; + +int main(int argc, char **argv) +{ + struct ext2_super_block param; + errcode_t retval; + ext2_filsys fs; + int i; + __u16 csum1, csum2, csum_known = 0xd3a4; + + memset(¶m, 0, sizeof(param)); + ext2fs_blocks_count_set(¶m, 32768); + + retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m, + test_io_manager, &fs); + if (retval) { + com_err("setup", retval, + "While initializing filesystem"); + exit(1); + } + memcpy(fs->super->s_uuid, sb_uuid, 16); + fs->super->s_feature_ro_compat = EXT4_FEATURE_RO_COMPAT_GDT_CSUM; + + for (i=0; i < fs->group_desc_count; i++) { + ext2fs_block_bitmap_loc_set(fs, i, 124); + ext2fs_inode_bitmap_loc_set(fs, i, 125); + ext2fs_inode_table_loc_set(fs, i, 126); + ext2fs_bg_free_blocks_count_set(fs, i, 31119); + ext2fs_bg_free_inodes_count_set(fs, i, 15701); + ext2fs_bg_used_dirs_count_set(fs, i, 2); + ext2fs_bg_flags_zap(fs, i); + }; + + csum1 = ext2fs_group_desc_csum(fs, 0); + print_csum("csum0000", fs, 0); + + if (csum1 != csum_known) { + printf("checksum for group 0 should be %04x\n", csum_known); + exit(1); + } + csum2 = ext2fs_group_desc_csum(fs, 1); + print_csum("csum0001", fs, 1); + if (csum1 == csum2) { + printf("checksums for different groups shouldn't match\n"); + exit(1); + } + csum2 = ext2fs_group_desc_csum(fs, 2); + print_csum("csumffff", fs, 2); + if (csum1 == csum2) { + printf("checksums for different groups shouldn't match\n"); + exit(1); + } + ext2fs_bg_checksum_set(fs, 0, csum1); + csum2 = ext2fs_group_desc_csum(fs, 0); + print_csum("csum_set", fs, 0); + if (csum1 != csum2) { + printf("checksums should not depend on checksum field\n"); + exit(1); + } + if (!ext2fs_group_desc_csum_verify(fs, 0)) { + printf("checksums should verify against gd_checksum\n"); + exit(1); + } + memset(fs->super->s_uuid, 0x30, sizeof(fs->super->s_uuid)); + print_csum("new_uuid", fs, 0); + if (ext2fs_group_desc_csum_verify(fs, 0) != 0) { + printf("checksums for different filesystems shouldn't match\n"); + exit(1); + } + csum1 = ext2fs_group_desc_csum(fs, 0); + ext2fs_bg_checksum_set(fs, 0, csum1); + print_csum("csum_new", fs, 0); + ext2fs_bg_free_blocks_count_set(fs, 0, 1); + csum2 = ext2fs_group_desc_csum(fs, 0); + print_csum("csum_blk", fs, 0); + if (csum1 == csum2) { + printf("checksums for different data shouldn't match\n"); + exit(1); + } + + return 0; +} +#endif diff --git a/libcustomext2fs/source/dblist.c b/libcustomext2fs/source/dblist.c new file mode 100644 index 00000000..8ee61b4c --- /dev/null +++ b/libcustomext2fs/source/dblist.c @@ -0,0 +1,414 @@ +/* + * dblist.c -- directory block list functions + * + * Copyright 1997 by Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fsP.h" + +static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b); +static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b); +static EXT2_QSORT_TYPE (*sortfunc32)(const void *a, const void *b); + +/* + * Returns the number of directories in the filesystem as reported by + * the group descriptors. Of course, the group descriptors could be + * wrong! + */ +errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs) +{ + dgrp_t i; + ext2_ino_t num_dirs, max_dirs; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + num_dirs = 0; + max_dirs = fs->super->s_inodes_per_group; + for (i = 0; i < fs->group_desc_count; i++) { + if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs) + num_dirs += max_dirs / 8; + else + num_dirs += ext2fs_bg_used_dirs_count(fs, i); + } + if (num_dirs > fs->super->s_inodes_count) + num_dirs = fs->super->s_inodes_count; + + *ret_num_dirs = num_dirs; + + return 0; +} + +/* + * helper function for making a new directory block list (for + * initialize and copy). + */ +static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, + ext2_ino_t count, + struct ext2_db_entry2 *list, + ext2_dblist *ret_dblist) +{ + ext2_dblist dblist; + errcode_t retval; + ext2_ino_t num_dirs; + size_t len; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if ((ret_dblist == 0) && fs->dblist && + (fs->dblist->magic == EXT2_ET_MAGIC_DBLIST)) + return 0; + + retval = ext2fs_get_mem(sizeof(struct ext2_struct_dblist), &dblist); + if (retval) + return retval; + memset(dblist, 0, sizeof(struct ext2_struct_dblist)); + + dblist->magic = EXT2_ET_MAGIC_DBLIST; + dblist->fs = fs; + if (size) + dblist->size = size; + else { + retval = ext2fs_get_num_dirs(fs, &num_dirs); + if (retval) + goto cleanup; + dblist->size = (num_dirs * 2) + 12; + } + len = (size_t) sizeof(struct ext2_db_entry2) * dblist->size; + dblist->count = count; + retval = ext2fs_get_array(dblist->size, sizeof(struct ext2_db_entry2), + &dblist->list); + if (retval) + goto cleanup; + + if (list) + memcpy(dblist->list, list, len); + else + memset(dblist->list, 0, len); + if (ret_dblist) + *ret_dblist = dblist; + else + fs->dblist = dblist; + return 0; +cleanup: + if (dblist) + ext2fs_free_mem(&dblist); + return retval; +} + +/* + * Initialize a directory block list + */ +errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist) +{ + ext2_dblist dblist; + errcode_t retval; + + retval = make_dblist(fs, 0, 0, 0, &dblist); + if (retval) + return retval; + + dblist->sorted = 1; + if (ret_dblist) + *ret_dblist = dblist; + else + fs->dblist = dblist; + + return 0; +} + +/* + * Copy a directory block list + */ +errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest) +{ + ext2_dblist dblist; + errcode_t retval; + + retval = make_dblist(src->fs, src->size, src->count, src->list, + &dblist); + if (retval) + return retval; + dblist->sorted = src->sorted; + *dest = dblist; + return 0; +} + +/* + * Close a directory block list + * + * (moved to closefs.c) + */ + + +/* + * Add a directory block to the directory block list + */ +errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, + blk64_t blk, e2_blkcnt_t blockcnt) +{ + struct ext2_db_entry2 *new_entry; + errcode_t retval; + unsigned long old_size; + + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + + if (dblist->count >= dblist->size) { + old_size = dblist->size * sizeof(struct ext2_db_entry2); + dblist->size += dblist->size > 200 ? dblist->size / 2 : 100; + retval = ext2fs_resize_mem(old_size, (size_t) dblist->size * + sizeof(struct ext2_db_entry2), + &dblist->list); + if (retval) { + dblist->size -= 100; + return retval; + } + } + new_entry = dblist->list + ( dblist->count++); + new_entry->blk = blk; + new_entry->ino = ino; + new_entry->blockcnt = blockcnt; + + dblist->sorted = 0; + + return 0; +} + +/* + * Change the directory block to the directory block list + */ +errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino, + blk64_t blk, e2_blkcnt_t blockcnt) +{ + dgrp_t i; + + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + + for (i=0; i < dblist->count; i++) { + if ((dblist->list[i].ino != ino) || + (dblist->list[i].blockcnt != blockcnt)) + continue; + dblist->list[i].blk = blk; + dblist->sorted = 0; + return 0; + } + return EXT2_ET_DB_NOT_FOUND; +} + +void ext2fs_dblist_sort2(ext2_dblist dblist, + EXT2_QSORT_TYPE (*sortfunc)(const void *, + const void *)) +{ + if (!sortfunc) + sortfunc = dir_block_cmp2; + qsort(dblist->list, (size_t) dblist->count, + sizeof(struct ext2_db_entry2), sortfunc); + dblist->sorted = 1; +} + +/* + * This function iterates over the directory block list + */ +errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist, + int (*func)(ext2_filsys fs, + struct ext2_db_entry2 *db_info, + void *priv_data), + void *priv_data) +{ + unsigned long long i; + int ret; + + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + + if (!dblist->sorted) + ext2fs_dblist_sort2(dblist, 0); + for (i=0; i < dblist->count; i++) { + ret = (*func)(dblist->fs, &dblist->list[i], priv_data); + if (ret & DBLIST_ABORT) + return 0; + } + return 0; +} + +static EXT2_QSORT_TYPE dir_block_cmp2(const void *a, const void *b) +{ + const struct ext2_db_entry2 *db_a = + (const struct ext2_db_entry2 *) a; + const struct ext2_db_entry2 *db_b = + (const struct ext2_db_entry2 *) b; + + if (db_a->blk != db_b->blk) + return (int) (db_a->blk - db_b->blk); + + if (db_a->ino != db_b->ino) + return (int) (db_a->ino - db_b->ino); + + return (db_a->blockcnt - db_b->blockcnt); +} + +blk64_t ext2fs_dblist_count2(ext2_dblist dblist) +{ + return dblist->count; +} + +errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist, + struct ext2_db_entry2 **entry) +{ + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + + if (dblist->count == 0) + return EXT2_ET_DBLIST_EMPTY; + + if (entry) + *entry = dblist->list + ( dblist->count-1); + return 0; +} + +errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist) +{ + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + + if (dblist->count == 0) + return EXT2_ET_DBLIST_EMPTY; + + dblist->count--; + return 0; +} + +/* + * Legacy 32-bit versions + */ + +/* + * Add a directory block to the directory block list + */ +errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, + int blockcnt) +{ + return ext2fs_add_dir_block2(dblist, ino, blk, blockcnt); +} + +/* + * Change the directory block to the directory block list + */ +errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, + int blockcnt) +{ + return ext2fs_set_dir_block2(dblist, ino, blk, blockcnt); +} + +void ext2fs_dblist_sort(ext2_dblist dblist, + EXT2_QSORT_TYPE (*sortfunc)(const void *, + const void *)) +{ + if (sortfunc) { + sortfunc32 = sortfunc; + sortfunc = dir_block_cmp; + } else + sortfunc = dir_block_cmp2; + qsort(dblist->list, (size_t) dblist->count, + sizeof(struct ext2_db_entry2), sortfunc); + dblist->sorted = 1; +} + +/* + * This function iterates over the directory block list + */ +struct iterate_passthrough { + int (*func)(ext2_filsys fs, + struct ext2_db_entry *db_info, + void *priv_data); + void *priv_data; +}; + +static int passthrough_func(ext2_filsys fs, + struct ext2_db_entry2 *db_info, + void *priv_data) +{ + struct iterate_passthrough *p = priv_data; + struct ext2_db_entry db; + int ret; + + db.ino = db_info->ino; + db.blk = (blk_t) db_info->blk; + db.blockcnt = (int) db_info->blockcnt; + ret = (p->func)(fs, &db, p->priv_data); + db_info->ino = db.ino; + db_info->blk = db.blk; + db_info->blockcnt = db.blockcnt; + return ret; +} + +errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, + int (*func)(ext2_filsys fs, + struct ext2_db_entry *db_info, + void *priv_data), + void *priv_data) +{ + struct iterate_passthrough pass; + + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + pass.func = func; + pass.priv_data = priv_data; + + return ext2fs_dblist_iterate2(dblist, passthrough_func, &pass); +} + +static EXT2_QSORT_TYPE dir_block_cmp(const void *a, const void *b) +{ + const struct ext2_db_entry2 *db_a = + (const struct ext2_db_entry2 *) a; + const struct ext2_db_entry2 *db_b = + (const struct ext2_db_entry2 *) b; + + struct ext2_db_entry a32, b32; + + a32.ino = db_a->ino; a32.blk = db_a->blk; + a32.blockcnt = db_a->blockcnt; + + b32.ino = db_b->ino; b32.blk = db_b->blk; + b32.blockcnt = db_b->blockcnt; + + return sortfunc32(&a32, &b32); +} + +int ext2fs_dblist_count(ext2_dblist dblist) +{ + return dblist->count; +} + +errcode_t ext2fs_dblist_get_last(ext2_dblist dblist, + struct ext2_db_entry **entry) +{ + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + static struct ext2_db_entry ret_entry; + struct ext2_db_entry2 *last; + + if (dblist->count == 0) + return EXT2_ET_DBLIST_EMPTY; + + if (!entry) + return 0; + + last = dblist->list + dblist->count -1; + + ret_entry.ino = last->ino; + ret_entry.blk = last->blk; + ret_entry.blockcnt = last->blockcnt; + *entry = &ret_entry; + + return 0; +} + diff --git a/libcustomext2fs/source/dblist_dir.c b/libcustomext2fs/source/dblist_dir.c new file mode 100644 index 00000000..07ed8afa --- /dev/null +++ b/libcustomext2fs/source/dblist_dir.c @@ -0,0 +1,79 @@ +/* + * dblist_dir.c --- iterate by directory entry + * + * Copyright 1997 by Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fsP.h" + +static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info, + void *priv_data); + +errcode_t ext2fs_dblist_dir_iterate(ext2_dblist dblist, + int flags, + char *block_buf, + int (*func)(ext2_ino_t dir, + int entry, + struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data) +{ + errcode_t retval; + struct dir_context ctx; + + EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST); + + ctx.dir = 0; + ctx.flags = flags; + if (block_buf) + ctx.buf = block_buf; + else { + retval = ext2fs_get_mem(dblist->fs->blocksize, &ctx.buf); + if (retval) + return retval; + } + ctx.func = func; + ctx.priv_data = priv_data; + ctx.errcode = 0; + + retval = ext2fs_dblist_iterate2(dblist, db_dir_proc, &ctx); + + if (!block_buf) + ext2fs_free_mem(&ctx.buf); + if (retval) + return retval; + return ctx.errcode; +} + +static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info, + void *priv_data) +{ + struct dir_context *ctx; + int ret; + + ctx = (struct dir_context *) priv_data; + ctx->dir = db_info->ino; + ctx->errcode = 0; + + ret = ext2fs_process_dir_block(fs, &db_info->blk, + db_info->blockcnt, 0, 0, priv_data); + if ((ret & BLOCK_ABORT) && !ctx->errcode) + return DBLIST_ABORT; + return 0; +} diff --git a/libcustomext2fs/source/dir_iterate.c b/libcustomext2fs/source/dir_iterate.c new file mode 100644 index 00000000..afe0f1a2 --- /dev/null +++ b/libcustomext2fs/source/dir_iterate.c @@ -0,0 +1,268 @@ +/* + * dir_iterate.c --- ext2fs directory iteration operations + * + * Copyright (C) 1993, 1994, 1994, 1995, 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" + +#define EXT4_MAX_REC_LEN ((1<<16)-1) + +errcode_t ext2fs_get_rec_len(ext2_filsys fs, + struct ext2_dir_entry *dirent, + unsigned int *rec_len) +{ + unsigned int len = dirent->rec_len; + + if (len == EXT4_MAX_REC_LEN || len == 0) + *rec_len = fs->blocksize; + else + *rec_len = (len & 65532) | ((len & 3) << 16); + return 0; +} + +errcode_t ext2fs_set_rec_len(ext2_filsys fs, + unsigned int len, + struct ext2_dir_entry *dirent) +{ + if ((len > fs->blocksize) || (fs->blocksize > (1 << 18)) || (len & 3)) + return EINVAL; + if (len < 65536) { + dirent->rec_len = len; + return 0; + } + if (len == fs->blocksize) { + if (fs->blocksize == 65536) + dirent->rec_len = EXT4_MAX_REC_LEN; + else + dirent->rec_len = 0; + } else + dirent->rec_len = (len & 65532) | ((len >> 16) & 3); + return 0; +} + +/* + * This function checks to see whether or not a potential deleted + * directory entry looks valid. What we do is check the deleted entry + * and each successive entry to make sure that they all look valid and + * that the last deleted entry ends at the beginning of the next + * undeleted entry. Returns 1 if the deleted entry looks valid, zero + * if not valid. + */ +static int ext2fs_validate_entry(ext2_filsys fs, char *buf, + unsigned int offset, + unsigned int final_offset) +{ + struct ext2_dir_entry *dirent; + unsigned int rec_len; +#define DIRENT_MIN_LENGTH 12 + + while ((offset < final_offset) && + (offset <= fs->blocksize - DIRENT_MIN_LENGTH)) { + dirent = (struct ext2_dir_entry *)(buf + offset); + if (ext2fs_get_rec_len(fs, dirent, &rec_len)) + return 0; + offset += rec_len; + if ((rec_len < 8) || + ((rec_len % 4) != 0) || + ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) + return 0; + } + return (offset == final_offset); +} + +errcode_t ext2fs_dir_iterate2(ext2_filsys fs, + ext2_ino_t dir, + int flags, + char *block_buf, + int (*func)(ext2_ino_t dir, + int entry, + struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data) +{ + struct dir_context ctx; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_check_directory(fs, dir); + if (retval) + return retval; + + ctx.dir = dir; + ctx.flags = flags; + if (block_buf) + ctx.buf = block_buf; + else { + retval = ext2fs_get_mem(fs->blocksize, &ctx.buf); + if (retval) + return retval; + } + ctx.func = func; + ctx.priv_data = priv_data; + ctx.errcode = 0; + retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY, 0, + ext2fs_process_dir_block, &ctx); + if (!block_buf) + ext2fs_free_mem(&ctx.buf); + if (retval) + return retval; + return ctx.errcode; +} + +struct xlate { + int (*func)(struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data); + void *real_private; +}; + +static int xlate_func(ext2_ino_t dir EXT2FS_ATTR((unused)), + int entry EXT2FS_ATTR((unused)), + struct ext2_dir_entry *dirent, int offset, + int blocksize, char *buf, void *priv_data) +{ + struct xlate *xl = (struct xlate *) priv_data; + + return (*xl->func)(dirent, offset, blocksize, buf, xl->real_private); +} + +extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, + ext2_ino_t dir, + int flags, + char *block_buf, + int (*func)(struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data) +{ + struct xlate xl; + + xl.real_private = priv_data; + xl.func = func; + + return ext2fs_dir_iterate2(fs, dir, flags, block_buf, + xlate_func, &xl); +} + + +/* + * Helper function which is private to this module. Used by + * ext2fs_dir_iterate() and ext2fs_dblist_dir_iterate() + */ +int ext2fs_process_dir_block(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct dir_context *ctx = (struct dir_context *) priv_data; + unsigned int offset = 0; + unsigned int next_real_entry = 0; + int ret = 0; + int changed = 0; + int do_abort = 0; + unsigned int rec_len, size; + int entry; + struct ext2_dir_entry *dirent; + + if (blockcnt < 0) + return 0; + + entry = blockcnt ? DIRENT_OTHER_FILE : DIRENT_DOT_FILE; + + ctx->errcode = ext2fs_read_dir_block3(fs, *blocknr, ctx->buf, 0); + if (ctx->errcode) + return BLOCK_ABORT; + + while (offset < fs->blocksize) { + dirent = (struct ext2_dir_entry *) (ctx->buf + offset); + if (ext2fs_get_rec_len(fs, dirent, &rec_len)) + return BLOCK_ABORT; + if (((offset + rec_len) > fs->blocksize) || + (rec_len < 8) || + ((rec_len % 4) != 0) || + ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) { + ctx->errcode = EXT2_ET_DIR_CORRUPTED; + return BLOCK_ABORT; + } + if (!dirent->inode && + !(ctx->flags & DIRENT_FLAG_INCLUDE_EMPTY)) + goto next; + + ret = (ctx->func)(ctx->dir, + (next_real_entry > offset) ? + DIRENT_DELETED_FILE : entry, + dirent, offset, + fs->blocksize, ctx->buf, + ctx->priv_data); + if (entry < DIRENT_OTHER_FILE) + entry++; + + if (ret & DIRENT_CHANGED) { + if (ext2fs_get_rec_len(fs, dirent, &rec_len)) + return BLOCK_ABORT; + changed++; + } + if (ret & DIRENT_ABORT) { + do_abort++; + break; + } +next: + if (next_real_entry == offset) + next_real_entry += rec_len; + + if (ctx->flags & DIRENT_FLAG_INCLUDE_REMOVED) { + size = ((dirent->name_len & 0xFF) + 11) & ~3; + + if (rec_len != size) { + unsigned int final_offset; + + final_offset = offset + rec_len; + offset += size; + while (offset < final_offset && + !ext2fs_validate_entry(fs, ctx->buf, + offset, + final_offset)) + offset += 4; + continue; + } + } + offset += rec_len; + } + + if (changed) { + ctx->errcode = ext2fs_write_dir_block3(fs, *blocknr, ctx->buf, + 0); + if (ctx->errcode) + return BLOCK_ABORT; + } + if (do_abort) + return BLOCK_ABORT; + return 0; +} + diff --git a/libcustomext2fs/source/dirblock.c b/libcustomext2fs/source/dirblock.c new file mode 100644 index 00000000..73e1f0ab --- /dev/null +++ b/libcustomext2fs/source/dirblock.c @@ -0,0 +1,126 @@ +/* + * dirblock.c --- directory block routines. + * + * Copyright (C) 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block, + void *buf, int flags EXT2FS_ATTR((unused))) +{ + errcode_t retval; + char *p, *end; + struct ext2_dir_entry *dirent; + unsigned int name_len, rec_len; + + + retval = io_channel_read_blk64(fs->io, block, 1, buf); + if (retval) + return retval; + + p = (char *) buf; + end = (char *) buf + fs->blocksize; + while (p < end-8) { + dirent = (struct ext2_dir_entry *) p; +#ifdef WORDS_BIGENDIAN + dirent->inode = ext2fs_swab32(dirent->inode); + dirent->rec_len = ext2fs_swab16(dirent->rec_len); + dirent->name_len = ext2fs_swab16(dirent->name_len); +#endif + name_len = dirent->name_len; +#ifdef WORDS_BIGENDIAN + if (flags & EXT2_DIRBLOCK_V2_STRUCT) + dirent->name_len = ext2fs_swab16(dirent->name_len); +#endif + if ((retval = ext2fs_get_rec_len(fs, dirent, &rec_len)) != 0) + return retval; + if ((rec_len < 8) || (rec_len % 4)) { + rec_len = 8; + retval = EXT2_ET_DIR_CORRUPTED; + } else if (((name_len & 0xFF) + 8) > rec_len) + retval = EXT2_ET_DIR_CORRUPTED; + p += rec_len; + } + return retval; +} + +errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block, + void *buf, int flags EXT2FS_ATTR((unused))) +{ + return ext2fs_read_dir_block3(fs, block, buf, flags); +} + +errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, + void *buf) +{ + return ext2fs_read_dir_block3(fs, block, buf, 0); +} + + +errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block, + void *inbuf, int flags EXT2FS_ATTR((unused))) +{ +#ifdef WORDS_BIGENDIAN + errcode_t retval; + char *p, *end; + char *buf = 0; + unsigned int rec_len; + struct ext2_dir_entry *dirent; + + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + memcpy(buf, inbuf, fs->blocksize); + p = buf; + end = buf + fs->blocksize; + while (p < end) { + dirent = (struct ext2_dir_entry *) p; + if ((retval = ext2fs_get_rec_len(fs, dirent, &rec_len)) != 0) + return retval; + if ((rec_len < 8) || + (rec_len % 4)) { + ext2fs_free_mem(&buf); + return (EXT2_ET_DIR_CORRUPTED); + } + p += rec_len; + dirent->inode = ext2fs_swab32(dirent->inode); + dirent->rec_len = ext2fs_swab16(dirent->rec_len); + dirent->name_len = ext2fs_swab16(dirent->name_len); + + if (flags & EXT2_DIRBLOCK_V2_STRUCT) + dirent->name_len = ext2fs_swab16(dirent->name_len); + } + retval = io_channel_write_blk64(fs->io, block, 1, buf); + ext2fs_free_mem(&buf); + return retval; +#else + return io_channel_write_blk64(fs->io, block, 1, (char *) inbuf); +#endif +} + +errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block, + void *inbuf, int flags EXT2FS_ATTR((unused))) +{ + return ext2fs_write_dir_block3(fs, block, inbuf, flags); +} + +errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, + void *inbuf) +{ + return ext2fs_write_dir_block3(fs, block, inbuf, 0); +} + diff --git a/libcustomext2fs/source/dirhash.c b/libcustomext2fs/source/dirhash.c new file mode 100644 index 00000000..a0697069 --- /dev/null +++ b/libcustomext2fs/source/dirhash.c @@ -0,0 +1,257 @@ +/* + * dirhash.c -- Calculate the hash of a directory entry + * + * Copyright (c) 2001 Daniel Phillips + * + * Copyright (c) 2002 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * Keyed 32-bit hash function using TEA in a Davis-Meyer function + * H0 = Key + * Hi = E Mi(Hi-1) + Hi-1 + * + * (see Applied Cryptography, 2nd edition, p448). + * + * Jeremy Fitzhardinge 1998 + * + * This code is made available under the terms of the GPL + */ +#define DELTA 0x9E3779B9 + +static void TEA_transform(__u32 buf[4], __u32 const in[]) +{ + __u32 sum = 0; + __u32 b0 = buf[0], b1 = buf[1]; + __u32 a = in[0], b = in[1], c = in[2], d = in[3]; + int n = 16; + + do { + sum += DELTA; + b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b); + b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d); + } while(--n); + + buf[0] += b0; + buf[1] += b1; +} + +/* F, G and H are basic MD4 functions: selection, majority, parity */ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) + +/* + * The generic round function. The application is so specific that + * we don't bother protecting all the arguments with parens, as is generally + * good macro practice, in favor of extra legibility. + * Rotation is separate from addition to prevent recomputation + */ +#define ROUND(f, a, b, c, d, x, s) \ + (a += f(b, c, d) + x, a = (a << s) | (a >> (32-s))) +#define K1 0 +#define K2 013240474631UL +#define K3 015666365641UL + +/* + * Basic cut-down MD4 transform. Returns only 32 bits of result. + */ +static void halfMD4Transform (__u32 buf[4], __u32 const in[]) +{ + __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3]; + + /* Round 1 */ + ROUND(F, a, b, c, d, in[0] + K1, 3); + ROUND(F, d, a, b, c, in[1] + K1, 7); + ROUND(F, c, d, a, b, in[2] + K1, 11); + ROUND(F, b, c, d, a, in[3] + K1, 19); + ROUND(F, a, b, c, d, in[4] + K1, 3); + ROUND(F, d, a, b, c, in[5] + K1, 7); + ROUND(F, c, d, a, b, in[6] + K1, 11); + ROUND(F, b, c, d, a, in[7] + K1, 19); + + /* Round 2 */ + ROUND(G, a, b, c, d, in[1] + K2, 3); + ROUND(G, d, a, b, c, in[3] + K2, 5); + ROUND(G, c, d, a, b, in[5] + K2, 9); + ROUND(G, b, c, d, a, in[7] + K2, 13); + ROUND(G, a, b, c, d, in[0] + K2, 3); + ROUND(G, d, a, b, c, in[2] + K2, 5); + ROUND(G, c, d, a, b, in[4] + K2, 9); + ROUND(G, b, c, d, a, in[6] + K2, 13); + + /* Round 3 */ + ROUND(H, a, b, c, d, in[3] + K3, 3); + ROUND(H, d, a, b, c, in[7] + K3, 9); + ROUND(H, c, d, a, b, in[2] + K3, 11); + ROUND(H, b, c, d, a, in[6] + K3, 15); + ROUND(H, a, b, c, d, in[1] + K3, 3); + ROUND(H, d, a, b, c, in[5] + K3, 9); + ROUND(H, c, d, a, b, in[0] + K3, 11); + ROUND(H, b, c, d, a, in[4] + K3, 15); + + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; +} + +#undef ROUND +#undef F +#undef G +#undef H +#undef K1 +#undef K2 +#undef K3 + +/* The old legacy hash */ +static ext2_dirhash_t dx_hack_hash (const char *name, int len, + int unsigned_flag) +{ + __u32 hash, hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9; + const unsigned char *ucp = (const unsigned char *) name; + const signed char *scp = (const signed char *) name; + int c; + + while (len--) { + if (unsigned_flag) + c = (int) *ucp++; + else + c = (int) *scp++; + hash = hash1 + (hash0 ^ (c * 7152373)); + + if (hash & 0x80000000) hash -= 0x7fffffff; + hash1 = hash0; + hash0 = hash; + } + return (hash0 << 1); +} + +static void str2hashbuf(const char *msg, int len, __u32 *buf, int num, + int unsigned_flag) +{ + __u32 pad, val; + int i, c; + const unsigned char *ucp = (const unsigned char *) msg; + const signed char *scp = (const signed char *) msg; + + pad = (__u32)len | ((__u32)len << 8); + pad |= pad << 16; + + val = pad; + if (len > num*4) + len = num * 4; + for (i=0; i < len; i++) { + if ((i % 4) == 0) + val = pad; + if (unsigned_flag) + c = (int) ucp[i]; + else + c = (int) scp[i]; + + val = c + (val << 8); + if ((i % 4) == 3) { + *buf++ = val; + val = pad; + num--; + } + } + if (--num >= 0) + *buf++ = val; + while (--num >= 0) + *buf++ = pad; +} + +/* + * Returns the hash of a filename. If len is 0 and name is NULL, then + * this function can be used to test whether or not a hash version is + * supported. + * + * The seed is an 4 longword (32 bits) "secret" which can be used to + * uniquify a hash. If the seed is all zero's, then some default seed + * may be used. + * + * A particular hash version specifies whether or not the seed is + * represented, and whether or not the returned hash is 32 bits or 64 + * bits. 32 bit hashes will return 0 for the minor hash. + */ +errcode_t ext2fs_dirhash(int version, const char *name, int len, + const __u32 *seed, + ext2_dirhash_t *ret_hash, + ext2_dirhash_t *ret_minor_hash) +{ + __u32 hash; + __u32 minor_hash = 0; + const char *p; + int i; + __u32 in[8], buf[4]; + int unsigned_flag = 0; + + /* Initialize the default seed for the hash checksum functions */ + buf[0] = 0x67452301; + buf[1] = 0xefcdab89; + buf[2] = 0x98badcfe; + buf[3] = 0x10325476; + + /* Check to see if the seed is all zero's */ + if (seed) { + for (i=0; i < 4; i++) { + if (seed[i]) + break; + } + if (i < 4) + memcpy(buf, seed, sizeof(buf)); + } + + switch (version) { + case EXT2_HASH_LEGACY_UNSIGNED: + unsigned_flag++; + case EXT2_HASH_LEGACY: + hash = dx_hack_hash(name, len, unsigned_flag); + break; + case EXT2_HASH_HALF_MD4_UNSIGNED: + unsigned_flag++; + case EXT2_HASH_HALF_MD4: + p = name; + while (len > 0) { + str2hashbuf(p, len, in, 8, unsigned_flag); + halfMD4Transform(buf, in); + len -= 32; + p += 32; + } + minor_hash = buf[2]; + hash = buf[1]; + break; + case EXT2_HASH_TEA_UNSIGNED: + unsigned_flag++; + case EXT2_HASH_TEA: + p = name; + while (len > 0) { + str2hashbuf(p, len, in, 4, unsigned_flag); + TEA_transform(buf, in); + len -= 16; + p += 16; + } + hash = buf[0]; + minor_hash = buf[1]; + break; + default: + *ret_hash = 0; + return EXT2_ET_DIRHASH_UNSUPP; + } + *ret_hash = hash & ~1; + if (ret_minor_hash) + *ret_minor_hash = minor_hash; + return 0; +} diff --git a/libcustomext2fs/source/disc_cache.c b/libcustomext2fs/source/disc_cache.c new file mode 100644 index 00000000..2a9ad05c --- /dev/null +++ b/libcustomext2fs/source/disc_cache.c @@ -0,0 +1,374 @@ +/* + cache.c + The cache is not visible to the user. It should be flushed + when any file is closed or changes are made to the filesystem. + + This cache implements a least-used-page replacement policy. This will + distribute sectors evenly over the pages, so if less than the maximum + pages are used at once, they should all eventually remain in the cache. + This also has the benefit of throwing out old sectors, so as not to keep + too many stale pages around. + + Copyright (c) 2006 Michael "Chishm" Chisholm + Copyright (c) 2009 shareese, rodries + Copyright (c) 2010 Dimok + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include + +#include "disc_cache.h" +#include "bit_ops.h" +#include "mem_allocate.h" + +#define CACHE_FREE UINT_MAX + +CACHE* cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition, sec_t sectorSize) { + CACHE* cache; + unsigned int i; + CACHE_ENTRY* cacheEntries; + + if(numberOfPages==0 || sectorsPerPage==0) return NULL; + + if (numberOfPages < 4) { + numberOfPages = 4; + } + + if (sectorsPerPage < 32) { + sectorsPerPage = 32; + } + + cache = (CACHE*) mem_alloc (sizeof(CACHE)); + if (cache == NULL) { + return NULL; + } + + cache->disc = discInterface; + cache->endOfPartition = endOfPartition; + cache->numberOfPages = numberOfPages; + cache->sectorsPerPage = sectorsPerPage; + cache->sectorSize = sectorSize; + + + cacheEntries = (CACHE_ENTRY*) mem_alloc ( sizeof(CACHE_ENTRY) * numberOfPages); + if (cacheEntries == NULL) { + mem_free (cache); + return NULL; + } + + for (i = 0; i < numberOfPages; i++) { + cacheEntries[i].sector = CACHE_FREE; + cacheEntries[i].count = 0; + cacheEntries[i].last_access = 0; + cacheEntries[i].dirty = false; + cacheEntries[i].cache = (uint8_t*) mem_align (32, sectorsPerPage * cache->sectorSize); + } + + cache->cacheEntries = cacheEntries; + + return cache; +} + +void cache_destructor (CACHE* cache) { + unsigned int i; + + if(cache==NULL) return; + + // Clear out cache before destroying it + cache_flush(cache); + + // Free memory in reverse allocation order + for (i = 0; i < cache->numberOfPages; i++) { + mem_free (cache->cacheEntries[i].cache); + } + mem_free (cache->cacheEntries); + mem_free (cache); +} + +static u32 accessCounter = 0; + +static u32 accessTime(){ + accessCounter++; + return accessCounter; +} + +static CACHE_ENTRY* cache_getPage(CACHE *cache,sec_t sector) +{ + unsigned int i; + CACHE_ENTRY* cacheEntries = cache->cacheEntries; + unsigned int numberOfPages = cache->numberOfPages; + unsigned int sectorsPerPage = cache->sectorsPerPage; + + bool foundFree = false; + unsigned int oldUsed = 0; + unsigned int oldAccess = UINT_MAX; + + for(i=0;i=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) { + cacheEntries[i].last_access = accessTime(); + return &(cacheEntries[i]); + } + + if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_accessdisc->writeSectors(cacheEntries[oldUsed].sector,cacheEntries[oldUsed].count,cacheEntries[oldUsed].cache)) return NULL; + cacheEntries[oldUsed].dirty = false; + } + sector = (sector/sectorsPerPage)*sectorsPerPage; // align base sector to page size + sec_t next_page = sector + sectorsPerPage; + if(next_page > cache->endOfPartition) next_page = cache->endOfPartition; + + if(!cache->disc->readSectors(sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL; + + cacheEntries[oldUsed].sector = sector; + cacheEntries[oldUsed].count = next_page-sector; + cacheEntries[oldUsed].last_access = accessTime(); + + return &(cacheEntries[oldUsed]); +} + +static CACHE_ENTRY* cache_findPage(CACHE *cache, sec_t sector, sec_t count) { + + unsigned int i; + CACHE_ENTRY* cacheEntries = cache->cacheEntries; + unsigned int numberOfPages = cache->numberOfPages; + CACHE_ENTRY *entry = NULL; + sec_t lowest = UINT_MAX; + + for(i=0;i cacheEntries[i].sector) { + intersect = sector - cacheEntries[i].sector < cacheEntries[i].count; + } else { + intersect = cacheEntries[i].sector - sector < count; + } + + if ( intersect && (cacheEntries[i].sector < lowest)) { + lowest = cacheEntries[i].sector; + entry = &cacheEntries[i]; + } + } + } + + return entry; +} + +bool cache_readSectors(CACHE *cache,sec_t sector,sec_t numSectors,void *buffer) +{ + sec_t sec; + sec_t secs_to_read; + CACHE_ENTRY *entry; + uint8_t *dest = buffer; + + while(numSectors>0) { + entry = cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + secs_to_read = entry->count - sec; + if(secs_to_read>numSectors) secs_to_read = numSectors; + + memcpy(dest,entry->cache + (sec*cache->sectorSize),(secs_to_read*cache->sectorSize)); + + dest += (secs_to_read*cache->sectorSize); + sector += secs_to_read; + numSectors -= secs_to_read; + } + + return true; +} + +/* +Reads some data from a cache page, determined by the sector number +*/ + +bool cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + CACHE_ENTRY *entry; + + if (offset + size > cache->sectorSize) return false; + + entry = cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memcpy(buffer,entry->cache + ((sec*cache->sectorSize) + offset),size); + + return true; +} + +bool cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes) { + uint8_t buf[4]; + if (!cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false; + + switch(num_bytes) { + case 1: *value = buf[0]; break; + case 2: *value = u8array_to_u16(buf,0); break; + case 4: *value = u8array_to_u32(buf,0); break; + default: return false; + } + return true; +} + +/* +Writes some data to a cache page, making sure it is loaded into memory first. +*/ + +bool cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + CACHE_ENTRY *entry; + + if (offset + size > cache->sectorSize) return false; + + entry = cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memcpy(entry->cache + ((sec*cache->sectorSize) + offset),buffer,size); + + entry->dirty = true; + return true; +} + +bool cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int size) { + uint8_t buf[4] = {0, 0, 0, 0}; + + switch(size) { + case 1: buf[0] = value; break; + case 2: u16_to_u8array(buf, 0, value); break; + case 4: u32_to_u8array(buf, 0, value); break; + default: return false; + } + + return cache_writePartialSector(cache, buf, sector, offset, size); +} + +/* +Writes some data to a cache page, zeroing out the page first +*/ + +bool cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + CACHE_ENTRY *entry; + + if (offset + size > cache->sectorSize) return false; + + entry = cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memset(entry->cache + (sec*cache->sectorSize),0,cache->sectorSize); + memcpy(entry->cache + ((sec*cache->sectorSize) + offset),buffer,size); + + entry->dirty = true; + return true; +} + +bool cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer) +{ + sec_t sec; + sec_t secs_to_write; + CACHE_ENTRY* entry; + const uint8_t *src = buffer; + + while(numSectors>0) + { + entry = cache_findPage(cache,sector,numSectors); + + if(entry!=NULL) { + + if ( entry->sector > sector) { + + secs_to_write = entry->sector - sector; + + cache->disc->writeSectors(sector,secs_to_write,src); + src += (secs_to_write*cache->sectorSize); + sector += secs_to_write; + numSectors -= secs_to_write; + } + + sec = sector - entry->sector; + secs_to_write = entry->count - sec; + + if(secs_to_write>numSectors) secs_to_write = numSectors; + + memcpy(entry->cache + (sec*cache->sectorSize),src,(secs_to_write*cache->sectorSize)); + + src += (secs_to_write*cache->sectorSize); + sector += secs_to_write; + numSectors -= secs_to_write; + + entry->dirty = true; + + } else { + cache->disc->writeSectors(sector,numSectors,src); + numSectors=0; + } + } + return true; +} + +/* +Flushes all dirty pages to disc, clearing the dirty flag. +*/ +bool cache_flush (CACHE* cache) { + unsigned int i; + if(cache==NULL) return true; + + for (i = 0; i < cache->numberOfPages; i++) { + if (cache->cacheEntries[i].dirty) { + if (!cache->disc->writeSectors (cache->cacheEntries[i].sector, cache->cacheEntries[i].count, cache->cacheEntries[i].cache)) { + return false; + } + } + cache->cacheEntries[i].dirty = false; + } + + return true; +} + +void cache_invalidate (CACHE* cache) { + unsigned int i; + if(cache==NULL) + return; + + cache_flush(cache); + for (i = 0; i < cache->numberOfPages; i++) { + cache->cacheEntries[i].sector = CACHE_FREE; + cache->cacheEntries[i].last_access = 0; + cache->cacheEntries[i].count = 0; + cache->cacheEntries[i].dirty = false; + } +} diff --git a/libcustomext2fs/source/disc_cache.h b/libcustomext2fs/source/disc_cache.h new file mode 100644 index 00000000..1d34c8c0 --- /dev/null +++ b/libcustomext2fs/source/disc_cache.h @@ -0,0 +1,118 @@ +/* + CACHE.h + The CACHE is not visible to the user. It should be flushed + when any file is closed or changes are made to the filesystem. + + This CACHE implements a least-used-page replacement policy. This will + distribute sectors evenly over the pages, so if less than the maximum + pages are used at once, they should all eventually remain in the CACHE. + This also has the benefit of throwing out old sectors, so as not to keep + too many stale pages around. + + Copyright (c) 2006 Michael "Chishm" Chisholm + Copyright (c) 2009 shareese, rodries + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _DISC_CACHE_H +#define _DISC_CACHE_H + +#include +#include +#include +#include +#include + +typedef struct +{ + sec_t sector; + unsigned int count; + u64 last_access; + bool dirty; + u8* cache; +} CACHE_ENTRY; + +typedef struct +{ + const DISC_INTERFACE* disc; + sec_t endOfPartition; + unsigned int numberOfPages; + unsigned int sectorsPerPage; + sec_t sectorSize; + CACHE_ENTRY* cacheEntries; +} CACHE; + +/* +Read data from a sector in the CACHE +If the sector is not in the CACHE, it will be swapped in +offset is the position to start reading from +size is the amount of data to read +Precondition: offset + size <= BYTES_PER_READ +*/ +/* +Write data to a sector in the CACHE +If the sector is not in the CACHE, it will be swapped in. +When the sector is swapped out, the data will be written to the disc +offset is the position to start writing to +size is the amount of data to write +Precondition: offset + size <= BYTES_PER_READ +*/ + +/* +Write data to a sector in the CACHE, zeroing the sector first +If the sector is not in the CACHE, it will be swapped in. +When the sector is swapped out, the data will be written to the disc +offset is the position to start writing to +size is the amount of data to write +Precondition: offset + size <= BYTES_PER_READ +*/ + +/* +Read several sectors from the CACHE +*/ +bool cache_readSectors (CACHE* DISC_CACHE, sec_t sector, sec_t numSectors, void* buffer); + +/* +Read a full sector from the CACHE +*/ +/* +Write a full sector to the CACHE +*/ +bool cache_writeSectors (CACHE* DISC_CACHE, sec_t sector, sec_t numSectors, const void* buffer); + +/* +Write any dirty sectors back to disc and clear out the contents of the CACHE +*/ +bool cache_flush (CACHE* DISC_CACHE); + +/* +Clear out the contents of the CACHE without writing any dirty sectors first +*/ +void cache_invalidate (CACHE* DISC_CACHE); + +CACHE* cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition, sec_t sectorSize); + +void cache_destructor (CACHE* DISC_CACHE); + +#endif // _CACHE_H + diff --git a/libcustomext2fs/source/dupfs.c b/libcustomext2fs/source/dupfs.c new file mode 100644 index 00000000..a9e2a976 --- /dev/null +++ b/libcustomext2fs/source/dupfs.c @@ -0,0 +1,96 @@ +/* + * dupfs.c --- duplicate a ext2 filesystem handle + * + * Copyright (C) 1997, 1998, 2001, 2003, 2005 by Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fsP.h" + +errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest) +{ + ext2_filsys fs; + errcode_t retval; + + EXT2_CHECK_MAGIC(src, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs); + if (retval) + return retval; + + *fs = *src; + fs->device_name = 0; + fs->super = 0; + fs->orig_super = 0; + fs->group_desc = 0; + fs->inode_map = 0; + fs->block_map = 0; + fs->badblocks = 0; + fs->dblist = 0; + + io_channel_bumpcount(fs->io); + if (fs->icache) + fs->icache->refcount++; + + retval = ext2fs_get_mem(strlen(src->device_name)+1, &fs->device_name); + if (retval) + goto errout; + strcpy(fs->device_name, src->device_name); + + retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->super); + if (retval) + goto errout; + memcpy(fs->super, src->super, SUPERBLOCK_SIZE); + + retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->orig_super); + if (retval) + goto errout; + memcpy(fs->orig_super, src->orig_super, SUPERBLOCK_SIZE); + + retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, + &fs->group_desc); + if (retval) + goto errout; + memcpy(fs->group_desc, src->group_desc, + (size_t) fs->desc_blocks * fs->blocksize); + + if (src->inode_map) { + retval = ext2fs_copy_bitmap(src->inode_map, &fs->inode_map); + if (retval) + goto errout; + } + if (src->block_map) { + retval = ext2fs_copy_bitmap(src->block_map, &fs->block_map); + if (retval) + goto errout; + } + if (src->badblocks) { + retval = ext2fs_badblocks_copy(src->badblocks, &fs->badblocks); + if (retval) + goto errout; + } + if (src->dblist) { + retval = ext2fs_copy_dblist(src->dblist, &fs->dblist); + if (retval) + goto errout; + } + *dest = fs; + return 0; +errout: + ext2fs_free(fs); + return retval; + +} + diff --git a/libcustomext2fs/source/e2image.h b/libcustomext2fs/source/e2image.h new file mode 100644 index 00000000..4de2c8d9 --- /dev/null +++ b/libcustomext2fs/source/e2image.h @@ -0,0 +1,51 @@ +/* + * e2image.h --- header file describing the ext2 image format + * + * Copyright (C) 2000 Theodore Ts'o. + * + * Note: this uses the POSIX IO interfaces, unlike most of the other + * functions in this library. So sue me. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + + +struct ext2_image_hdr { + __u32 magic_number; /* This must be EXT2_ET_MAGIC_E2IMAGE */ + char magic_descriptor[16]; /* "Ext2 Image 1.0", w/ null padding */ + char fs_hostname[64];/* Hostname of machine of image */ + char fs_netaddr[32]; /* Network address */ + __u32 fs_netaddr_type;/* 0 = IPV4, 1 = IPV6, etc. */ + __u32 fs_device; /* Device number of image */ + char fs_device_name[64]; /* Device name */ + char fs_uuid[16]; /* UUID of filesystem */ + __u32 fs_blocksize; /* Block size of the filesystem */ + __u32 fs_reserved[8]; + + __u32 image_device; /* Device number of image file */ + __u32 image_inode; /* Inode number of image file */ + __u32 image_time; /* Time of image creation */ + __u32 image_reserved[8]; + + __u32 offset_super; /* Byte offset of the sb and descriptors */ + __u32 offset_inode; /* Byte offset of the inode table */ + __u32 offset_inodemap; /* Byte offset of the inode bitmaps */ + __u32 offset_blockmap; /* Byte offset of the inode bitmaps */ + __u32 offset_reserved[8]; +}; + + + + + + + + + + + + + diff --git a/libcustomext2fs/source/e2p/e2p.h b/libcustomext2fs/source/e2p/e2p.h new file mode 100644 index 00000000..319c9bcd --- /dev/null +++ b/libcustomext2fs/source/e2p/e2p.h @@ -0,0 +1,74 @@ +/* + * e2p.h --- header file for the e2p library + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include /* Needed by dirent.h on netbsd */ +#include +#include + +#include "../ext2_fs.h" + +#define E2P_FEATURE_COMPAT 0 +#define E2P_FEATURE_INCOMPAT 1 +#define E2P_FEATURE_RO_INCOMPAT 2 +#define E2P_FEATURE_TYPE_MASK 0x03 + +#define E2P_FEATURE_NEGATE_FLAG 0x80 + +#define E2P_FS_FEATURE 0 +#define E2P_JOURNAL_FEATURE 1 + +/* `options' for print_flags() */ + +#define PFOPT_LONG 1 /* Must be 1 for compatibility with `int long_format'. */ + + +int fgetflags (const char * name, unsigned long * flags); +int fgetversion (const char * name, unsigned long * version); +int fsetflags (const char * name, unsigned long flags); +int fsetversion (const char * name, unsigned long version); +int getflags (int fd, unsigned long * flags); +int getversion (int fd, unsigned long * version); +int iterate_on_dir (const char * dir_name, + int (*func) (const char *, struct dirent *, void *), + void * private); +void list_super(struct ext2_super_block * s); +void list_super2(struct ext2_super_block * s, FILE *f); +void print_fs_errors (FILE * f, unsigned short errors); +void print_flags (FILE * f, unsigned long flags, unsigned options); +void print_fs_state (FILE * f, unsigned short state); +int setflags (int fd, unsigned long flags); +int setversion (int fd, unsigned long version); + +const char *e2p_feature2string(int compat, unsigned int mask); +const char *e2p_jrnl_feature2string(int compat, unsigned int mask); +int e2p_string2feature(char *string, int *compat, unsigned int *mask); +int e2p_jrnl_string2feature(char *string, int *compat_type, unsigned int *mask); +int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array); +int e2p_edit_feature2(const char *str, __u32 *compat_array, __u32 *ok_array, + __u32 *clear_ok_array, int *type_err, + unsigned int *mask_err); + +int e2p_is_null_uuid(void *uu); +void e2p_uuid_to_str(void *uu, char *out); +const char *e2p_uuid2str(void *uu); + +const char *e2p_hash2string(int num); +int e2p_string2hash(char *string); + +const char *e2p_mntopt2string(unsigned int mask); +int e2p_string2mntopt(char *string, unsigned int *mask); +int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok); + +unsigned long parse_num_blocks(const char *arg, int log_block_size); +unsigned long long parse_num_blocks2(const char *arg, int log_block_size); + +char *e2p_os2string(int os_type); +int e2p_string2os(char *str); + +unsigned int e2p_percent(int percent, unsigned int base); diff --git a/libcustomext2fs/source/e2p/feature.c b/libcustomext2fs/source/e2p/feature.c new file mode 100644 index 00000000..4806be50 --- /dev/null +++ b/libcustomext2fs/source/e2p/feature.c @@ -0,0 +1,385 @@ +/* + * feature.c --- convert between features and strings + * + * Copyright (C) 1999 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#include +#include + +#include "e2p.h" +#include +#include + +struct feature { + int compat; + unsigned int mask; + const char *string; +}; + +static struct feature feature_list[] = { + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_PREALLOC, + "dir_prealloc" }, + { E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL, + "has_journal" }, + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_IMAGIC_INODES, + "imagic_inodes" }, + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_EXT_ATTR, + "ext_attr" }, + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX, + "dir_index" }, + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_RESIZE_INODE, + "resize_inode" }, + { E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_LAZY_BG, + "lazy_bg" }, + + { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER, + "sparse_super" }, + { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_LARGE_FILE, + "large_file" }, + { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_HUGE_FILE, + "huge_file" }, + { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_GDT_CSUM, + "uninit_bg" }, + { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_GDT_CSUM, + "uninit_groups" }, + { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_DIR_NLINK, + "dir_nlink" }, + { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE, + "extra_isize" }, + + { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION, + "compression" }, + { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_FILETYPE, + "filetype" }, + { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_RECOVER, + "needs_recovery" }, + { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_JOURNAL_DEV, + "journal_dev" }, + { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS, + "extent" }, + { E2P_FEATURE_INCOMPAT, EXT3_FEATURE_INCOMPAT_EXTENTS, + "extents" }, + { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_META_BG, + "meta_bg" }, + { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_64BIT, + "64bit" }, + { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG, + "flex_bg"}, + { 0, 0, 0 }, +}; + +static struct feature jrnl_feature_list[] = { + { E2P_FEATURE_COMPAT, JFS_FEATURE_COMPAT_CHECKSUM, + "journal_checksum" }, + + { E2P_FEATURE_INCOMPAT, JFS_FEATURE_INCOMPAT_REVOKE, + "journal_incompat_revoke" }, + { E2P_FEATURE_INCOMPAT, JFS_FEATURE_INCOMPAT_ASYNC_COMMIT, + "journal_async_commit" }, + { 0, 0, 0 }, +}; + +const char *e2p_feature2string(int compat, unsigned int mask) +{ + struct feature *f; + static char buf[20]; + char fchar; + int fnum; + + for (f = feature_list; f->string; f++) { + if ((compat == f->compat) && + (mask == f->mask)) + return f->string; + } + switch (compat) { + case E2P_FEATURE_COMPAT: + fchar = 'C'; + break; + case E2P_FEATURE_INCOMPAT: + fchar = 'I'; + break; + case E2P_FEATURE_RO_INCOMPAT: + fchar = 'R'; + break; + default: + fchar = '?'; + break; + } + for (fnum = 0; mask >>= 1; fnum++); + sprintf(buf, "FEATURE_%c%d", fchar, fnum); + return buf; +} + +int e2p_string2feature(char *string, int *compat_type, unsigned int *mask) +{ + struct feature *f; + char *eptr; + int num; + + for (f = feature_list; f->string; f++) { + if (!strcasecmp(string, f->string)) { + *compat_type = f->compat; + *mask = f->mask; + return 0; + } + } + if (strncasecmp(string, "FEATURE_", 8)) + return 1; + + switch (string[8]) { + case 'c': + case 'C': + *compat_type = E2P_FEATURE_COMPAT; + break; + case 'i': + case 'I': + *compat_type = E2P_FEATURE_INCOMPAT; + break; + case 'r': + case 'R': + *compat_type = E2P_FEATURE_RO_INCOMPAT; + break; + default: + return 1; + } + if (string[9] == 0) + return 1; + num = strtol(string+9, &eptr, 10); + if (num > 32 || num < 0) + return 1; + if (*eptr) + return 1; + *mask = 1 << num; + return 0; +} + +const char *e2p_jrnl_feature2string(int compat, unsigned int mask) +{ + struct feature *f; + static char buf[20]; + char fchar; + int fnum; + + for (f = jrnl_feature_list; f->string; f++) { + if ((compat == f->compat) && + (mask == f->mask)) + return f->string; + } + switch (compat) { + case E2P_FEATURE_COMPAT: + fchar = 'C'; + break; + case E2P_FEATURE_INCOMPAT: + fchar = 'I'; + break; + case E2P_FEATURE_RO_INCOMPAT: + fchar = 'R'; + break; + default: + fchar = '?'; + break; + } + for (fnum = 0; mask >>= 1; fnum++); + sprintf(buf, "FEATURE_%c%d", fchar, fnum); + return buf; +} + +int e2p_jrnl_string2feature(char *string, int *compat_type, unsigned int *mask) +{ + struct feature *f; + char *eptr; + int num; + + for (f = jrnl_feature_list; f->string; f++) { + if (!strcasecmp(string, f->string)) { + *compat_type = f->compat; + *mask = f->mask; + return 0; + } + } + if (strncasecmp(string, "FEATURE_", 8)) + return 1; + + switch (string[8]) { + case 'c': + case 'C': + *compat_type = E2P_FEATURE_COMPAT; + break; + case 'i': + case 'I': + *compat_type = E2P_FEATURE_INCOMPAT; + break; + case 'r': + case 'R': + *compat_type = E2P_FEATURE_RO_INCOMPAT; + break; + default: + return 1; + } + if (string[9] == 0) + return 1; + num = strtol(string+9, &eptr, 10); + if (num > 32 || num < 0) + return 1; + if (*eptr) + return 1; + *mask = 1 << num; + return 0; +} +static char *skip_over_blanks(char *cp) +{ + while (*cp && isspace((int)*cp)) + cp++; + return cp; +} + +static char *skip_over_word(char *cp) +{ + while (*cp && !isspace((int)*cp) && *cp != ',') + cp++; + return cp; +} + +/* + * Edit a feature set array as requested by the user. The ok_array, + * if set, allows the application to limit what features the user is + * allowed to set or clear using this function. If clear_ok_array is set, + * then use it tell whether or not it is OK to clear a filesystem feature. + */ +int e2p_edit_feature2(const char *str, __u32 *compat_array, __u32 *ok_array, + __u32 *clear_ok_array, int *type_err, + unsigned int *mask_err) +{ + char *cp, *buf, *next; + int neg; + unsigned int mask; + int compat_type; + int rc = 0; + + if (!clear_ok_array) + clear_ok_array = ok_array; + + if (type_err) + *type_err = 0; + if (mask_err) + *mask_err = 0; + + buf = malloc(strlen(str)+1); + if (!buf) + return 1; + strcpy(buf, str); + for (cp = buf; cp && *cp; cp = next ? next+1 : 0) { + neg = 0; + cp = skip_over_blanks(cp); + next = skip_over_word(cp); + + if (*next == 0) + next = 0; + else + *next = 0; + + if ((strcasecmp(cp, "none") == 0) || + (strcasecmp(cp, "clear") == 0)) { + compat_array[0] = 0; + compat_array[1] = 0; + compat_array[2] = 0; + continue; + } + + switch (*cp) { + case '-': + case '^': + neg++; + case '+': + cp++; + break; + } + if (e2p_string2feature(cp, &compat_type, &mask)) { + rc = 1; + break; + } + if (neg) { + if (clear_ok_array && + !(clear_ok_array[compat_type] & mask)) { + rc = 1; + if (type_err) + *type_err = (compat_type | + E2P_FEATURE_NEGATE_FLAG); + if (mask_err) + *mask_err = mask; + break; + } + compat_array[compat_type] &= ~mask; + } else { + if (ok_array && !(ok_array[compat_type] & mask)) { + rc = 1; + if (type_err) + *type_err = compat_type; + if (mask_err) + *mask_err = mask; + break; + } + compat_array[compat_type] |= mask; + } + } + free(buf); + return rc; +} + +int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array) +{ + return e2p_edit_feature2(str, compat_array, ok_array, 0, 0, 0); +} + +#ifdef TEST_PROGRAM +int main(int argc, char **argv) +{ + int compat, compat2, i; + unsigned int mask, mask2; + const char *str; + struct feature *f; + + for (i = 0; i < 2; i++) { + if (i == 0) { + f = feature_list; + printf("Feature list:\n"); + } else { + printf("\nJournal feature list:\n"); + f = jrnl_feature_list; + } + for (; f->string; f++) { + if (i == 0) { + e2p_string2feature((char *)f->string, &compat, + &mask); + str = e2p_feature2string(compat, mask); + } else { + e2p_jrnl_string2feature((char *)f->string, + &compat, &mask); + str = e2p_jrnl_feature2string(compat, mask); + } + + printf("\tCompat = %d, Mask = %u, %s\n", + compat, mask, f->string); + if (strcmp(f->string, str)) { + if (e2p_string2feature((char *) str, &compat2, + &mask2) || + (compat2 != compat) || + (mask2 != mask)) { + fprintf(stderr, "Failure!\n"); + exit(1); + } + } + } + } + exit(0); +} +#endif diff --git a/libcustomext2fs/source/e2p/fgetflags.c b/libcustomext2fs/source/e2p/fgetflags.c new file mode 100644 index 00000000..282be320 --- /dev/null +++ b/libcustomext2fs/source/e2p/fgetflags.c @@ -0,0 +1,95 @@ +/* + * fgetflags.c - Get a file flags on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_EXT2_IOCTLS +#include +#include +#endif + +#include "e2p.h" + +#ifdef O_LARGEFILE +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) +#else +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) +#endif + +int fgetflags (const char * name, unsigned long * flags) +{ +#if HAVE_STAT_FLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS) + struct stat buf; + if (stat (name, &buf) == -1) + return -1; + + *flags = 0; +#ifdef UF_IMMUTABLE + if (buf.st_flags & UF_IMMUTABLE) + *flags |= EXT2_IMMUTABLE_FL; +#endif +#ifdef UF_APPEND + if (buf.st_flags & UF_APPEND) + *flags |= EXT2_APPEND_FL; +#endif +#ifdef UF_NODUMP + if (buf.st_flags & UF_NODUMP) + *flags |= EXT2_NODUMP_FL; +#endif + + return 0; +#else +#if HAVE_EXT2_IOCTLS + int fd, r, f, save_errno = 0; + + if (!lstat(name, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { + goto notsupp; + } +#if !APPLE_DARWIN + fd = open (name, OPEN_FLAGS); + if (fd == -1) + return -1; + r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); + if (r == -1) + save_errno = errno; + *flags = f; + close (fd); + if (save_errno) + errno = save_errno; + return r; +#else + f = -1; + save_errno = syscall(SYS_fsctl, name, EXT2_IOC_GETFLAGS, &f, 0); + *flags = f; + return (save_errno); +#endif +#endif /* HAVE_EXT2_IOCTLS */ +#endif + errno = EOPNOTSUPP; + return -1; +} diff --git a/libcustomext2fs/source/e2p/fgetversion.c b/libcustomext2fs/source/e2p/fgetversion.c new file mode 100644 index 00000000..97519d77 --- /dev/null +++ b/libcustomext2fs/source/e2p/fgetversion.c @@ -0,0 +1,69 @@ +/* + * fgetversion.c - Get a file version on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_EXT2_IOCTLS +#include +#include +#endif + +#include "e2p.h" + +#ifdef O_LARGEFILE +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) +#else +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) +#endif + +int fgetversion (const char * name, unsigned long * version) +{ +#if HAVE_EXT2_IOCTLS +#if !APPLE_DARWIN + int fd, r, ver, save_errno = 0; + + fd = open (name, OPEN_FLAGS); + if (fd == -1) + return -1; + r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); + if (r == -1) + save_errno = errno; + *version = ver; + close (fd); + if (save_errno) + errno = save_errno; + return r; +#else + int ver=-1, err; + err = syscall(SYS_fsctl, name, EXT2_IOC_GETVERSION, &ver, 0); + *version = ver; + return(err); +#endif +#else /* ! HAVE_EXT2_IOCTLS */ + extern int errno; + errno = EOPNOTSUPP; + return -1; +#endif /* ! HAVE_EXT2_IOCTLS */ +} diff --git a/libcustomext2fs/source/e2p/fsetflags.c b/libcustomext2fs/source/e2p/fsetflags.c new file mode 100644 index 00000000..0f39ee9c --- /dev/null +++ b/libcustomext2fs/source/e2p/fsetflags.c @@ -0,0 +1,100 @@ +/* + * fsetflags.c - Set a file flags on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_EXT2_IOCTLS +#include +#include +#endif + +#include "e2p.h" + +/* + * Deal with lame glibc's that define this function without actually + * implementing it. Can you say "attractive nuisance", boys and girls? + * I knew you could! + */ +#ifdef __linux__ +#undef HAVE_CHFLAGS +#endif + +#ifdef O_LARGEFILE +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) +#else +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) +#endif + +int fsetflags (const char * name, unsigned long flags) +{ +#if HAVE_CHFLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS) + struct stat buf; + unsigned long bsd_flags = 0; + +#ifdef UF_IMMUTABLE + if (flags & EXT2_IMMUTABLE_FL) + bsd_flags |= UF_IMMUTABLE; +#endif +#ifdef UF_APPEND + if (flags & EXT2_APPEND_FL) + bsd_flags |= UF_APPEND; +#endif +#ifdef UF_NODUMP + if (flags & EXT2_NODUMP_FL) + bsd_flags |= UF_NODUMP; +#endif + + return chflags (name, bsd_flags); +#else +#if HAVE_EXT2_IOCTLS + int fd, r, f, save_errno = 0; + + if (!lstat(name, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { + goto notsupp; + } +#if !APPLE_DARWIN + fd = open (name, OPEN_FLAGS); + if (fd == -1) + return -1; + f = (int) flags; + r = ioctl (fd, EXT2_IOC_SETFLAGS, &f); + if (r == -1) + save_errno = errno; + close (fd); + if (save_errno) + errno = save_errno; +#else + f = (int) flags; + return syscall(SYS_fsctl, name, EXT2_IOC_SETFLAGS, &f, 0); +#endif + return r; +#endif /* HAVE_EXT2_IOCTLS */ +#endif + errno = EOPNOTSUPP; + return -1; +} diff --git a/libcustomext2fs/source/e2p/fsetversion.c b/libcustomext2fs/source/e2p/fsetversion.c new file mode 100644 index 00000000..ee26f91e --- /dev/null +++ b/libcustomext2fs/source/e2p/fsetversion.c @@ -0,0 +1,67 @@ +/* + * fsetversion.c - Set a file version on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_EXT2_IOCTLS +#include +#include +#endif + +#include "e2p.h" + +#ifdef O_LARGEFILE +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE) +#else +#define OPEN_FLAGS (O_RDONLY|O_NONBLOCK) +#endif + +int fsetversion (const char * name, unsigned long version) +{ +#if HAVE_EXT2_IOCTLS +#if !APPLE_DARWIN + int fd, r, ver, save_errno = 0; + + fd = open (name, OPEN_FLAGS); + if (fd == -1) + return -1; + ver = (int) version; + r = ioctl (fd, EXT2_IOC_SETVERSION, &ver); + if (r == -1) + save_errno = errno; + close (fd); + if (save_errno) + errno = save_errno; + return r; +#else + int ver = (int)version; + return syscall(SYS_fsctl, name, EXT2_IOC_SETVERSION, &ver, 0); +#endif +#else /* ! HAVE_EXT2_IOCTLS */ + extern int errno; + errno = EOPNOTSUPP; + return -1; +#endif /* ! HAVE_EXT2_IOCTLS */ +} diff --git a/libcustomext2fs/source/e2p/getflags.c b/libcustomext2fs/source/e2p/getflags.c new file mode 100644 index 00000000..0cc768a8 --- /dev/null +++ b/libcustomext2fs/source/e2p/getflags.c @@ -0,0 +1,66 @@ +/* + * getflags.c - Get a file flags on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#include +#include +#if HAVE_EXT2_IOCTLS +#include +#endif + +#include "e2p.h" + +int getflags (int fd, unsigned long * flags) +{ +#if HAVE_STAT_FLAGS + struct stat buf; + if (fstat (fd, &buf) == -1) + return -1; + + *flags = 0; +#ifdef UF_IMMUTABLE + if (buf.st_flags & UF_IMMUTABLE) + *flags |= EXT2_IMMUTABLE_FL; +#endif +#ifdef UF_APPEND + if (buf.st_flags & UF_APPEND) + *flags |= EXT2_APPEND_FL; +#endif +#ifdef UF_NODUMP + if (buf.st_flags & UF_NODUMP) + *flags |= EXT2_NODUMP_FL; +#endif + + return 0; +#else +#if HAVE_EXT2_IOCTLS + int r, f; + + if (!fstat(fd, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) + goto notsupp; + r = ioctl (fd, EXT2_IOC_GETFLAGS, &f); + *flags = f; + return r; +#endif /* HAVE_EXT2_IOCTLS */ +#endif + errno = EOPNOTSUPP; + return -1; +} diff --git a/libcustomext2fs/source/e2p/getversion.c b/libcustomext2fs/source/e2p/getversion.c new file mode 100644 index 00000000..06adf6df --- /dev/null +++ b/libcustomext2fs/source/e2p/getversion.c @@ -0,0 +1,41 @@ +/* + * getversion.c - Get a file version on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_EXT2_IOCTLS +#include +#endif + +#include "e2p.h" + +int getversion (int fd, unsigned long * version) +{ +#if HAVE_EXT2_IOCTLS + int r, ver; + + r = ioctl (fd, EXT2_IOC_GETVERSION, &ver); + *version = ver; + return 0; +#else /* ! HAVE_EXT2_IOCTLS */ + extern int errno; + errno = EOPNOTSUPP; + return -1; +#endif /* ! HAVE_EXT2_IOCTLS */ +} diff --git a/libcustomext2fs/source/e2p/hashstr.c b/libcustomext2fs/source/e2p/hashstr.c new file mode 100644 index 00000000..5ee62370 --- /dev/null +++ b/libcustomext2fs/source/e2p/hashstr.c @@ -0,0 +1,71 @@ +/* + * feature.c --- convert between features and strings + * + * Copyright (C) 1999 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#include +#include + +#include "e2p.h" + +struct hash { + int num; + const char *string; +}; + +static struct hash hash_list[] = { + { EXT2_HASH_LEGACY, "legacy" }, + { EXT2_HASH_HALF_MD4, "half_md4" }, + { EXT2_HASH_TEA, "tea" }, + { 0, 0 }, +}; + +const char *e2p_hash2string(int num) +{ + struct hash *p; + static char buf[20]; + + for (p = hash_list; p->string; p++) { + if (num == p->num) + return p->string; + } + sprintf(buf, "HASHALG_%d", num); + return buf; +} + +/* + * Returns the hash algorithm, or -1 on error + */ +int e2p_string2hash(char *string) +{ + struct hash *p; + char *eptr; + int num; + + for (p = hash_list; p->string; p++) { + if (!strcasecmp(string, p->string)) { + return p->num; + } + } + if (strncasecmp(string, "HASHALG_", 8)) + return -1; + + if (string[8] == 0) + return -1; + num = strtol(string+8, &eptr, 10); + if (num > 255 || num < 0) + return -1; + if (*eptr) + return -1; + return num; +} + diff --git a/libcustomext2fs/source/e2p/iod.c b/libcustomext2fs/source/e2p/iod.c new file mode 100644 index 00000000..c53aafeb --- /dev/null +++ b/libcustomext2fs/source/e2p/iod.c @@ -0,0 +1,75 @@ +/* + * iod.c - Iterate a function on each entry of a directory + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#include "e2p.h" +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +int iterate_on_dir (const char * dir_name, + int (*func) (const char *, struct dirent *, void *), + void * private) +{ + DIR * dir; + struct dirent *de, *dep; + int max_len = -1, len, ret = 0; + +#if HAVE_PATHCONF && defined(_PC_NAME_MAX) + max_len = pathconf(dir_name, _PC_NAME_MAX); +#endif + if (max_len == -1) { +#ifdef _POSIX_NAME_MAX + max_len = _POSIX_NAME_MAX; +#else +#ifdef NAME_MAX + max_len = NAME_MAX; +#else + max_len = 256; +#endif /* NAME_MAX */ +#endif /* _POSIX_NAME_MAX */ + } + max_len += sizeof(struct dirent); + + de = malloc(max_len+1); + if (!de) + return -1; + memset(de, 0, max_len+1); + + dir = opendir (dir_name); + if (dir == NULL) { + free(de); + return -1; + } + while ((dep = readdir (dir))) { +#ifdef HAVE_RECLEN_DIRENT + len = dep->d_reclen; + if (len > max_len) + len = max_len; +#else + len = sizeof(struct dirent); +#endif + memcpy(de, dep, len); + if ((*func)(dir_name, de, private)) + ret++; + } + free(de); + closedir(dir); + return ret; +} diff --git a/libcustomext2fs/source/e2p/ls.c b/libcustomext2fs/source/e2p/ls.c new file mode 100644 index 00000000..20908a66 --- /dev/null +++ b/libcustomext2fs/source/e2p/ls.c @@ -0,0 +1,403 @@ +/* + * ls.c - List the contents of an ext2fs superblock + * + * Copyright (C) 1992, 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * Copyright (C) 1995, 1996, 1997 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "e2p.h" + +static void print_user (unsigned short uid, FILE *f) +{ + struct passwd *pw; + + fprintf(f, "%u ", uid); + pw = getpwuid (uid); + if (pw == NULL) + fprintf(f, "(user unknown)\n"); + else + fprintf(f, "(user %s)\n", pw->pw_name); +} + +static void print_group (unsigned short gid, FILE *f) +{ + struct group *gr; + + fprintf(f, "%u ", gid); + gr = getgrgid (gid); + if (gr == NULL) + fprintf(f, "(group unknown)\n"); + else + fprintf(f, "(group %s)\n", gr->gr_name); +} + +#define MONTH_INT (86400 * 30) +#define WEEK_INT (86400 * 7) +#define DAY_INT (86400) +#define HOUR_INT (60 * 60) +#define MINUTE_INT (60) + +static const char *interval_string(unsigned int secs) +{ + static char buf[256], tmp[80]; + int hr, min, num; + + buf[0] = 0; + + if (secs == 0) + return ""; + + if (secs >= MONTH_INT) { + num = secs / MONTH_INT; + secs -= num*MONTH_INT; + sprintf(buf, "%d month%s", num, (num>1) ? "s" : ""); + } + if (secs >= WEEK_INT) { + num = secs / WEEK_INT; + secs -= num*WEEK_INT; + sprintf(tmp, "%s%d week%s", buf[0] ? ", " : "", + num, (num>1) ? "s" : ""); + strcat(buf, tmp); + } + if (secs >= DAY_INT) { + num = secs / DAY_INT; + secs -= num*DAY_INT; + sprintf(tmp, "%s%d day%s", buf[0] ? ", " : "", + num, (num>1) ? "s" : ""); + strcat(buf, tmp); + } + if (secs > 0) { + hr = secs / HOUR_INT; + secs -= hr*HOUR_INT; + min = secs / MINUTE_INT; + secs -= min*MINUTE_INT; + sprintf(tmp, "%s%d:%02d:%02d", buf[0] ? ", " : "", + hr, min, secs); + strcat(buf, tmp); + } + return buf; +} + +static void print_features(struct ext2_super_block * s, FILE *f) +{ +#ifdef EXT2_DYNAMIC_REV + int i, j, printed=0; + __u32 *mask = &s->s_feature_compat, m; + + fprintf(f, "Filesystem features: "); + for (i=0; i <3; i++,mask++) { + for (j=0,m=1; j < 32; j++, m<<=1) { + if (*mask & m) { + fprintf(f, " %s", e2p_feature2string(i, m)); + printed++; + } + } + } + if (printed == 0) + fprintf(f, " (none)"); + fprintf(f, "\n"); +#endif +} + +static void print_mntopts(struct ext2_super_block * s, FILE *f) +{ +#ifdef EXT2_DYNAMIC_REV + int i, printed=0; + __u32 mask = s->s_default_mount_opts, m; + + fprintf(f, "Default mount options: "); + if (mask & EXT3_DEFM_JMODE) { + fprintf(f, " %s", e2p_mntopt2string(mask & EXT3_DEFM_JMODE)); + printed++; + } + for (i=0,m=1; i < 32; i++, m<<=1) { + if (m & EXT3_DEFM_JMODE) + continue; + if (mask & m) { + fprintf(f, " %s", e2p_mntopt2string(m)); + printed++; + } + } + if (printed == 0) + fprintf(f, " (none)"); + fprintf(f, "\n"); +#endif +} + +static void print_super_flags(struct ext2_super_block * s, FILE *f) +{ + int flags_found = 0; + + if (s->s_flags == 0) + return; + + fputs("Filesystem flags: ", f); + if (s->s_flags & EXT2_FLAGS_SIGNED_HASH) { + fputs("signed_directory_hash ", f); + flags_found++; + } + if (s->s_flags & EXT2_FLAGS_UNSIGNED_HASH) { + fputs("unsigned_directory_hash ", f); + flags_found++; + } + if (s->s_flags & EXT2_FLAGS_TEST_FILESYS) { + fputs("test_filesystem ", f); + flags_found++; + } + if (flags_found) + fputs("\n", f); + else + fputs("(none)\n", f); +} + +static __u64 e2p_blocks_count(struct ext2_super_block *super) +{ + return super->s_blocks_count | + (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) super->s_blocks_count_hi << 32 : 0); +} + +static __u64 e2p_r_blocks_count(struct ext2_super_block *super) +{ + return super->s_r_blocks_count | + (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) super->s_r_blocks_count_hi << 32 : 0); +} + +static __u64 e2p_free_blocks_count(struct ext2_super_block *super) +{ + return super->s_free_blocks_count | + (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ? + (__u64) super->s_free_blocks_hi << 32 : 0); +} + +#ifndef EXT2_INODE_SIZE +#define EXT2_INODE_SIZE(s) sizeof(struct ext2_inode) +#endif + +#ifndef EXT2_GOOD_OLD_REV +#define EXT2_GOOD_OLD_REV 0 +#endif + +void list_super2(struct ext2_super_block * sb, FILE *f) +{ + int inode_blocks_per_group; + char buf[80], *str; + time_t tm; + + inode_blocks_per_group = (((sb->s_inodes_per_group * + EXT2_INODE_SIZE(sb)) + + EXT2_BLOCK_SIZE(sb) - 1) / + EXT2_BLOCK_SIZE(sb)); + if (sb->s_volume_name[0]) { + memset(buf, 0, sizeof(buf)); + strncpy(buf, sb->s_volume_name, sizeof(sb->s_volume_name)); + } else + strcpy(buf, ""); + fprintf(f, "Filesystem volume name: %s\n", buf); + if (sb->s_last_mounted[0]) { + memset(buf, 0, sizeof(buf)); + strncpy(buf, sb->s_last_mounted, sizeof(sb->s_last_mounted)); + } else + strcpy(buf, ""); + fprintf(f, "Last mounted on: %s\n", buf); + fprintf(f, "Filesystem UUID: %s\n", e2p_uuid2str(sb->s_uuid)); + fprintf(f, "Filesystem magic number: 0x%04X\n", sb->s_magic); + fprintf(f, "Filesystem revision #: %d", sb->s_rev_level); + if (sb->s_rev_level == EXT2_GOOD_OLD_REV) { + fprintf(f, " (original)\n"); +#ifdef EXT2_DYNAMIC_REV + } else if (sb->s_rev_level == EXT2_DYNAMIC_REV) { + fprintf(f, " (dynamic)\n"); +#endif + } else + fprintf(f, " (unknown)\n"); + print_features(sb, f); + print_super_flags(sb, f); + print_mntopts(sb, f); + if (sb->s_mount_opts[0]) + fprintf(f, "Mount options: %s\n", sb->s_mount_opts); + fprintf(f, "Filesystem state: "); + print_fs_state (f, sb->s_state); + fprintf(f, "\n"); + fprintf(f, "Errors behavior: "); + print_fs_errors(f, sb->s_errors); + fprintf(f, "\n"); + str = e2p_os2string(sb->s_creator_os); + fprintf(f, "Filesystem OS type: %s\n", str); + free(str); + fprintf(f, "Inode count: %u\n", sb->s_inodes_count); + fprintf(f, "Block count: %llu\n", e2p_blocks_count(sb)); + fprintf(f, "Reserved block count: %llu\n", e2p_r_blocks_count(sb)); + fprintf(f, "Free blocks: %llu\n", e2p_free_blocks_count(sb)); + fprintf(f, "Free inodes: %u\n", sb->s_free_inodes_count); + fprintf(f, "First block: %u\n", sb->s_first_data_block); + fprintf(f, "Block size: %u\n", EXT2_BLOCK_SIZE(sb)); + fprintf(f, "Fragment size: %u\n", EXT2_FRAG_SIZE(sb)); + if (sb->s_reserved_gdt_blocks) + fprintf(f, "Reserved GDT blocks: %u\n", + sb->s_reserved_gdt_blocks); + fprintf(f, "Blocks per group: %u\n", sb->s_blocks_per_group); + fprintf(f, "Fragments per group: %u\n", sb->s_frags_per_group); + fprintf(f, "Inodes per group: %u\n", sb->s_inodes_per_group); + fprintf(f, "Inode blocks per group: %u\n", inode_blocks_per_group); + if (sb->s_raid_stride) + fprintf(f, "RAID stride: %u\n", + sb->s_raid_stride); + if (sb->s_raid_stripe_width) + fprintf(f, "RAID stripe width: %u\n", + sb->s_raid_stripe_width); + if (sb->s_first_meta_bg) + fprintf(f, "First meta block group: %u\n", + sb->s_first_meta_bg); + if (sb->s_log_groups_per_flex) + fprintf(f, "Flex block group size: %u\n", + 1 << sb->s_log_groups_per_flex); + if (sb->s_mkfs_time) { + tm = sb->s_mkfs_time; + fprintf(f, "Filesystem created: %s", ctime(&tm)); + } + tm = sb->s_mtime; + fprintf(f, "Last mount time: %s", + sb->s_mtime ? ctime(&tm) : "n/a\n"); + tm = sb->s_wtime; + fprintf(f, "Last write time: %s", ctime(&tm)); + fprintf(f, "Mount count: %u\n", sb->s_mnt_count); + fprintf(f, "Maximum mount count: %d\n", sb->s_max_mnt_count); + tm = sb->s_lastcheck; + fprintf(f, "Last checked: %s", ctime(&tm)); + fprintf(f, "Check interval: %u (%s)\n", sb->s_checkinterval, + interval_string(sb->s_checkinterval)); + if (sb->s_checkinterval) + { + time_t next; + + next = sb->s_lastcheck + sb->s_checkinterval; + fprintf(f, "Next check after: %s", ctime(&next)); + } +#define POW2(x) ((__u64) 1 << (x)) + if (sb->s_kbytes_written) { + fprintf(f, "Lifetime writes: "); + if (sb->s_kbytes_written < POW2(13)) + fprintf(f, "%llu kB\n", sb->s_kbytes_written); + else if (sb->s_kbytes_written < POW2(23)) + fprintf(f, "%llu MB\n", + (sb->s_kbytes_written + POW2(9)) >> 10); + else if (sb->s_kbytes_written < POW2(33)) + fprintf(f, "%llu GB\n", + (sb->s_kbytes_written + POW2(19)) >> 20); + else if (sb->s_kbytes_written < POW2(43)) + fprintf(f, "%llu TB\n", + (sb->s_kbytes_written + POW2(29)) >> 30); + else + fprintf(f, "%llu PB\n", + (sb->s_kbytes_written + POW2(39)) >> 40); + } + fprintf(f, "Reserved blocks uid: "); + print_user(sb->s_def_resuid, f); + fprintf(f, "Reserved blocks gid: "); + print_group(sb->s_def_resgid, f); + if (sb->s_rev_level >= EXT2_DYNAMIC_REV) { + fprintf(f, "First inode: %d\n", sb->s_first_ino); + fprintf(f, "Inode size: %d\n", sb->s_inode_size); + if (sb->s_min_extra_isize) + fprintf(f, "Required extra isize: %d\n", + sb->s_min_extra_isize); + if (sb->s_want_extra_isize) + fprintf(f, "Desired extra isize: %d\n", + sb->s_want_extra_isize); + } + if (!e2p_is_null_uuid(sb->s_journal_uuid)) + fprintf(f, "Journal UUID: %s\n", + e2p_uuid2str(sb->s_journal_uuid)); + if (sb->s_journal_inum) + fprintf(f, "Journal inode: %u\n", + sb->s_journal_inum); + if (sb->s_journal_dev) + fprintf(f, "Journal device: 0x%04x\n", + sb->s_journal_dev); + if (sb->s_last_orphan) + fprintf(f, "First orphan inode: %u\n", + sb->s_last_orphan); + if ((sb->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) || + sb->s_def_hash_version) + fprintf(f, "Default directory hash: %s\n", + e2p_hash2string(sb->s_def_hash_version)); + if (!e2p_is_null_uuid(sb->s_hash_seed)) + fprintf(f, "Directory Hash Seed: %s\n", + e2p_uuid2str(sb->s_hash_seed)); + if (sb->s_jnl_backup_type) { + fprintf(f, "Journal backup: "); + switch (sb->s_jnl_backup_type) { + case 1: + fprintf(f, "inode blocks\n"); + break; + default: + fprintf(f, "type %u\n", sb->s_jnl_backup_type); + } + } + if (sb->s_snapshot_inum) { + fprintf(f, "Snapshot inode: %u\n", + sb->s_snapshot_inum); + fprintf(f, "Snapshot ID: %u\n", + sb->s_snapshot_id); + fprintf(f, "Snapshot reserved blocks: %llu\n", + sb->s_snapshot_r_blocks_count); + } + if (sb->s_snapshot_list) + fprintf(f, "Snapshot list head: %u\n", + sb->s_snapshot_list); + if (sb->s_error_count) + fprintf(f, "FS Error count: %u\n", + sb->s_error_count); + if (sb->s_first_error_time) { + tm = sb->s_first_error_time; + fprintf(f, "First error time: %s", ctime(&tm)); + memset(buf, 0, sizeof(buf)); + strncpy(buf, (char *)sb->s_first_error_func, + sizeof(sb->s_first_error_func)); + fprintf(f, "First error function: %s\n", buf); + fprintf(f, "First error line #: %u\n", + sb->s_first_error_line); + fprintf(f, "First error inode #: %u\n", + sb->s_first_error_ino); + fprintf(f, "First error block #: %llu\n", + sb->s_first_error_block); + } + if (sb->s_last_error_time) { + tm = sb->s_last_error_time; + fprintf(f, "Last error time: %s", ctime(&tm)); + memset(buf, 0, sizeof(buf)); + strncpy(buf, (char *) sb->s_last_error_func, + sizeof(sb->s_last_error_func)); + fprintf(f, "Last error function: %s\n", buf); + fprintf(f, "Last error line #: %u\n", + sb->s_last_error_line); + fprintf(f, "Last error inode #: %u\n", + sb->s_last_error_ino); + fprintf(f, "Last error block #: %llu\n", + sb->s_last_error_block); + } +} + +void list_super (struct ext2_super_block * s) +{ + list_super2(s, stdout); +} + diff --git a/libcustomext2fs/source/e2p/mntopts.c b/libcustomext2fs/source/e2p/mntopts.c new file mode 100644 index 00000000..0903ad54 --- /dev/null +++ b/libcustomext2fs/source/e2p/mntopts.c @@ -0,0 +1,147 @@ +/* + * mountopts.c --- convert between default mount options and strings + * + * Copyright (C) 2002 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#include +#include + +#include "e2p.h" + +struct mntopt { + unsigned int mask; + const char *string; +}; + +static struct mntopt mntopt_list[] = { + { EXT2_DEFM_DEBUG, "debug" }, + { EXT2_DEFM_BSDGROUPS, "bsdgroups" }, + { EXT2_DEFM_XATTR_USER, "user_xattr" }, + { EXT2_DEFM_ACL, "acl" }, + { EXT2_DEFM_UID16, "uid16" }, + { EXT3_DEFM_JMODE_DATA, "journal_data" }, + { EXT3_DEFM_JMODE_ORDERED, "journal_data_ordered" }, + { EXT3_DEFM_JMODE_WBACK, "journal_data_writeback" }, + { EXT4_DEFM_NOBARRIER, "nobarrier" }, + { EXT4_DEFM_BLOCK_VALIDITY, "block_validity" }, + { EXT4_DEFM_DISCARD, "discard"}, + { EXT4_DEFM_NODELALLOC, "nodelalloc"}, + { 0, 0 }, +}; + +const char *e2p_mntopt2string(unsigned int mask) +{ + struct mntopt *f; + static char buf[20]; + int fnum; + + for (f = mntopt_list; f->string; f++) { + if (mask == f->mask) + return f->string; + } + for (fnum = 0; mask >>= 1; fnum++); + sprintf(buf, "MNTOPT_%d", fnum); + return buf; +} + +int e2p_string2mntopt(char *string, unsigned int *mask) +{ + struct mntopt *f; + char *eptr; + int num; + + for (f = mntopt_list; f->string; f++) { + if (!strcasecmp(string, f->string)) { + *mask = f->mask; + return 0; + } + } + if (strncasecmp(string, "MNTOPT_", 8)) + return 1; + + if (string[8] == 0) + return 1; + num = strtol(string+8, &eptr, 10); + if (num > 32 || num < 0) + return 1; + if (*eptr) + return 1; + *mask = 1 << num; + return 0; +} + +static char *skip_over_blanks(char *cp) +{ + while (*cp && isspace((int) *cp)) + cp++; + return cp; +} + +static char *skip_over_word(char *cp) +{ + while (*cp && !isspace((int) *cp) && *cp != ',') + cp++; + return cp; +} + +/* + * Edit a mntopt set array as requested by the user. The ok + * parameter, if non-zero, allows the application to limit what + * mntopts the user is allowed to set or clear using this function. + */ +int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok) +{ + char *cp, *buf, *next; + int neg; + unsigned int mask; + int rc = 0; + + buf = malloc(strlen(str)+1); + if (!buf) + return 1; + strcpy(buf, str); + cp = buf; + while (cp && *cp) { + neg = 0; + cp = skip_over_blanks(cp); + next = skip_over_word(cp); + if (*next == 0) + next = 0; + else + *next = 0; + switch (*cp) { + case '-': + case '^': + neg++; + case '+': + cp++; + break; + } + if (e2p_string2mntopt(cp, &mask)) { + rc = 1; + break; + } + if (ok && !(ok & mask)) { + rc = 1; + break; + } + if (mask & EXT3_DEFM_JMODE) + *mntopts &= ~EXT3_DEFM_JMODE; + if (neg) + *mntopts &= ~mask; + else + *mntopts |= mask; + cp = next ? next+1 : 0; + } + free(buf); + return rc; +} diff --git a/libcustomext2fs/source/e2p/ostype.c b/libcustomext2fs/source/e2p/ostype.c new file mode 100644 index 00000000..978315b8 --- /dev/null +++ b/libcustomext2fs/source/e2p/ostype.c @@ -0,0 +1,77 @@ +/* + * getostype.c - Get the Filesystem OS type + * + * Copyright (C) 2004,2005 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include "e2p.h" +#include +#include + +static const char *os_tab[] = + { "Linux", + "Hurd", + "Masix", + "FreeBSD", + "Lites", + 0 }; + +/* + * Convert an os_type to a string + */ +char *e2p_os2string(int os_type) +{ + const char *os; + char *ret; + + if (os_type <= EXT2_OS_LITES) + os = os_tab[os_type]; + else + os = "(unknown os)"; + + ret = malloc(strlen(os)+1); + if (ret) + strcpy(ret, os); + return ret; +} + +/* + * Convert an os_type to a string + */ +int e2p_string2os(char *str) +{ + const char **cpp; + int i = 0; + + for (cpp = os_tab; *cpp; cpp++, i++) { + if (!strcasecmp(str, *cpp)) + return i; + } + return -1; +} + +#ifdef TEST_PROGRAM +int main(int argc, char **argv) +{ + char *s; + int i, os; + + for (i=0; i <= EXT2_OS_LITES; i++) { + s = e2p_os2string(i); + os = e2p_string2os(s); + printf("%d: %s (%d)\n", i, s, os); + if (i != os) { + fprintf(stderr, "Failure!\n"); + exit(1); + } + } + exit(0); +} +#endif + + diff --git a/libcustomext2fs/source/e2p/parse_num.c b/libcustomext2fs/source/e2p/parse_num.c new file mode 100644 index 00000000..83a329ae --- /dev/null +++ b/libcustomext2fs/source/e2p/parse_num.c @@ -0,0 +1,71 @@ +/* + * parse_num.c - Parse the number of blocks + * + * Copyright (C) 2004,2005 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include "e2p.h" + +#include + +unsigned long long parse_num_blocks2(const char *arg, int log_block_size) +{ + char *p; + unsigned long long num; + + num = strtoull(arg, &p, 0); + + if (p[0] && p[1]) + return 0; + + switch (*p) { /* Using fall-through logic */ + case 'T': case 't': + num <<= 10; + case 'G': case 'g': + num <<= 10; + case 'M': case 'm': + num <<= 10; + case 'K': case 'k': + num >>= log_block_size; + break; + case 's': + num >>= (1+log_block_size); + break; + case '\0': + break; + default: + return 0; + } + return num; +} + +unsigned long parse_num_blocks(const char *arg, int log_block_size) +{ + return parse_num_blocks2(arg, log_block_size); +} + +#ifdef DEBUG +#include +#include + +main(int argc, char **argv) +{ + unsigned long num; + int log_block_size = 0; + + if (argc != 2) { + fprintf(stderr, "Usage: %s arg\n", argv[0]); + exit(1); + } + + num = parse_num_blocks(argv[1], log_block_size); + + printf("Parsed number: %lu\n", num); + exit(0); +} +#endif diff --git a/libcustomext2fs/source/e2p/pe.c b/libcustomext2fs/source/e2p/pe.c new file mode 100644 index 00000000..78c80993 --- /dev/null +++ b/libcustomext2fs/source/e2p/pe.c @@ -0,0 +1,39 @@ +/* + * pe.c - Print a second extended filesystem errors behavior + * + * Copyright (C) 1992, 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 94/01/09 - Creation + */ + +#include + +#include "e2p.h" + +void print_fs_errors (FILE * f, unsigned short errors) +{ + switch (errors) + { + case EXT2_ERRORS_CONTINUE: + fprintf (f, "Continue"); + break; + case EXT2_ERRORS_RO: + fprintf (f, "Remount read-only"); + break; + case EXT2_ERRORS_PANIC: + fprintf (f, "Panic"); + break; + default: + fprintf (f, "Unknown (continue)"); + } +} diff --git a/libcustomext2fs/source/e2p/percent.c b/libcustomext2fs/source/e2p/percent.c new file mode 100644 index 00000000..cfa7046e --- /dev/null +++ b/libcustomext2fs/source/e2p/percent.c @@ -0,0 +1,66 @@ +/* + * percent.c - Take percentage of a number + * + * Copyright (C) 2006 Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include "e2p.h" + +#include + +/* + * We work really hard to calculate this accurately, while avoiding + * an overflow. "Is there a hyphen in anal-retentive?" :-) + */ +unsigned int e2p_percent(int percent, unsigned int base) +{ + unsigned int mask = ~((1 << (sizeof(unsigned int) - 1) * 8) - 1); + + if (!percent) + return 0; + if (100 % percent == 0) + return base / (100 / percent); + if (mask & base) + return (base / 100) * percent; + return base * percent / 100; +} + +#ifdef DEBUG +#include +#include + +main(int argc, char **argv) +{ + unsigned int base; + int percent; + char *p; + int log_block_size = 0; + + if (argc != 3) { + fprintf(stderr, "Usage: %s percent base\n", argv[0]); + exit(1); + } + + percent = strtoul(argv[1], &p, 0); + if (p[0] && p[1]) { + fprintf(stderr, "Bad percent: %s\n", argv[1]); + exit(1); + } + + base = strtoul(argv[2], &p, 0); + if (p[0] && p[1]) { + fprintf(stderr, "Bad base: %s\n", argv[2]); + exit(1); + } + + printf("%d percent of %u is %u.\n", percent, base, + e2p_percent(percent, base)); + + exit(0); +} +#endif diff --git a/libcustomext2fs/source/e2p/pf.c b/libcustomext2fs/source/e2p/pf.c new file mode 100644 index 00000000..f34a5cc3 --- /dev/null +++ b/libcustomext2fs/source/e2p/pf.c @@ -0,0 +1,78 @@ +/* + * pf.c - Print file attributes on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#include + +#include "e2p.h" + +struct flags_name { + unsigned long flag; + const char *short_name; + const char *long_name; +}; + +static struct flags_name flags_array[] = { + { EXT2_SECRM_FL, "s", "Secure_Deletion" }, + { EXT2_UNRM_FL, "u" , "Undelete" }, + { EXT2_SYNC_FL, "S", "Synchronous_Updates" }, + { EXT2_DIRSYNC_FL, "D", "Synchronous_Directory_Updates" }, + { EXT2_IMMUTABLE_FL, "i", "Immutable" }, + { EXT2_APPEND_FL, "a", "Append_Only" }, + { EXT2_NODUMP_FL, "d", "No_Dump" }, + { EXT2_NOATIME_FL, "A", "No_Atime" }, + { EXT2_COMPR_FL, "c", "Compression_Requested" }, +#ifdef ENABLE_COMPRESSION + { EXT2_COMPRBLK_FL, "B", "Compressed_File" }, + { EXT2_DIRTY_FL, "Z", "Compressed_Dirty_File" }, + { EXT2_NOCOMPR_FL, "X", "Compression_Raw_Access" }, + { EXT2_ECOMPR_FL, "E", "Compression_Error" }, +#endif + { EXT3_JOURNAL_DATA_FL, "j", "Journaled_Data" }, + { EXT2_INDEX_FL, "I", "Indexed_directory" }, + { EXT2_NOTAIL_FL, "t", "No_Tailmerging" }, + { EXT2_TOPDIR_FL, "T", "Top_of_Directory_Hierarchies" }, + { EXT4_EXTENTS_FL, "e", "Extents" }, + { EXT4_HUGE_FILE_FL, "h", "Huge_file" }, + { 0, NULL, NULL } +}; + +void print_flags (FILE * f, unsigned long flags, unsigned options) +{ + int long_opt = (options & PFOPT_LONG); + struct flags_name *fp; + int first = 1; + + for (fp = flags_array; fp->flag != 0; fp++) { + if (flags & fp->flag) { + if (long_opt) { + if (first) + first = 0; + else + fputs(", ", f); + fputs(fp->long_name, f); + } else + fputs(fp->short_name, f); + } else { + if (!long_opt) + fputs("-", f); + } + } + if (long_opt && first) + fputs("---", f); +} + diff --git a/libcustomext2fs/source/e2p/ps.c b/libcustomext2fs/source/e2p/ps.c new file mode 100644 index 00000000..e6ad60ab --- /dev/null +++ b/libcustomext2fs/source/e2p/ps.c @@ -0,0 +1,31 @@ +/* + * ps.c - Print filesystem state + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/12/22 - Creation + */ + +#include + +#include "e2p.h" + +void print_fs_state (FILE * f, unsigned short state) +{ + if (state & EXT2_VALID_FS) + fprintf (f, " clean"); + else + fprintf (f, " not clean"); + if (state & EXT2_ERROR_FS) + fprintf (f, " with errors"); +} diff --git a/libcustomext2fs/source/e2p/setflags.c b/libcustomext2fs/source/e2p/setflags.c new file mode 100644 index 00000000..776300d3 --- /dev/null +++ b/libcustomext2fs/source/e2p/setflags.c @@ -0,0 +1,74 @@ +/* + * setflags.c - Set a file flags on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#include +#include +#if HAVE_EXT2_IOCTLS +#include +#endif + +#include "e2p.h" + +/* + * Deal with lame glibc's that define this function without actually + * implementing it. Can you say "attractive nuisance", boys and girls? + * I knew you could! + */ +#ifdef __linux__ +#undef HAVE_CHFLAGS +#endif + +int setflags (int fd, unsigned long flags) +{ +#if HAVE_CHFLAGS + struct stat buf; + unsigned long bsd_flags = 0; + +#ifdef UF_IMMUTABLE + if (flags & EXT2_IMMUTABLE_FL) + bsd_flags |= UF_IMMUTABLE; +#endif +#ifdef UF_APPEND + if (flags & EXT2_APPEND_FL) + bsd_flags |= UF_APPEND; +#endif +#ifdef UF_NODUMP + if (flags & EXT2_NODUMP_FL) + bsd_flags |= UF_NODUMP; +#endif + + return fchflags (fd, bsd_flags); +#else +#if HAVE_EXT2_IOCTLS + int f; + + if (!fstat(fd, &buf) && + !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) { + errno = EOPNOTSUPP; + return -1; + } + f = (int) flags; + return ioctl (fd, EXT2_IOC_SETFLAGS, &f); +#endif /* HAVE_EXT2_IOCTLS */ +#endif + errno = EOPNOTSUPP; + return -1; +} diff --git a/libcustomext2fs/source/e2p/setversion.c b/libcustomext2fs/source/e2p/setversion.c new file mode 100644 index 00000000..d7d41289 --- /dev/null +++ b/libcustomext2fs/source/e2p/setversion.c @@ -0,0 +1,40 @@ +/* + * setversion.c - Set a file version on an ext2 file system + * + * Copyright (C) 1993, 1994 Remy Card + * Laboratoire MASI, Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * History: + * 93/10/30 - Creation + */ + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_EXT2_IOCTLS +#include +#endif + +#include "e2p.h" + +int setversion (int fd, unsigned long version) +{ +#if HAVE_EXT2_IOCTLS + int ver; + + ver = (int) version; + return ioctl (fd, EXT2_IOC_SETVERSION, &ver); +#else /* ! HAVE_EXT2_IOCTLS */ + extern int errno; + errno = EOPNOTSUPP; + return -1; +#endif /* ! HAVE_EXT2_IOCTLS */ +} diff --git a/libcustomext2fs/source/e2p/uuid.c b/libcustomext2fs/source/e2p/uuid.c new file mode 100644 index 00000000..310b01de --- /dev/null +++ b/libcustomext2fs/source/e2p/uuid.c @@ -0,0 +1,84 @@ +/* + * uuid.c -- utility routines for manipulating UUID's. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include + +#include "e2p.h" + +struct uuid { + __u32 time_low; + __u16 time_mid; + __u16 time_hi_and_version; + __u16 clock_seq; + __u8 node[6]; +}; + +/* Returns 1 if the uuid is the NULL uuid */ +int e2p_is_null_uuid(void *uu) +{ + __u8 *cp; + int i; + + for (i=0, cp = uu; i < 16; i++) + if (*cp++) + return 0; + return 1; +} + +static void e2p_unpack_uuid(void *in, struct uuid *uu) +{ + __u8 *ptr = in; + __u32 tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_low = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_mid = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_hi_and_version = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->clock_seq = tmp; + + memcpy(uu->node, ptr, 6); +} + +void e2p_uuid_to_str(void *uu, char *out) +{ + struct uuid uuid; + + e2p_unpack_uuid(uu, &uuid); + sprintf(out, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, + uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, + uuid.node[0], uuid.node[1], uuid.node[2], + uuid.node[3], uuid.node[4], uuid.node[5]); +} + +const char *e2p_uuid2str(void *uu) +{ + static char buf[80]; + + if (e2p_is_null_uuid(uu)) + return ""; + e2p_uuid_to_str(uu, buf); + return buf; +} + diff --git a/libcustomext2fs/source/expanddir.c b/libcustomext2fs/source/expanddir.c new file mode 100644 index 00000000..7673a3bd --- /dev/null +++ b/libcustomext2fs/source/expanddir.c @@ -0,0 +1,126 @@ +/* + * expand.c --- expand an ext2fs directory + * + * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct expand_dir_struct { + int done; + int newblocks; + errcode_t err; +}; + +static int expand_dir_proc(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data; + blk64_t new_blk; + static blk64_t last_blk = 0; + char *block; + errcode_t retval; + + if (*blocknr) { + last_blk = *blocknr; + return 0; + } + retval = ext2fs_new_block2(fs, last_blk, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + if (blockcnt > 0) { + retval = ext2fs_new_dir_block(fs, 0, 0, &block); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + es->done = 1; + retval = ext2fs_write_dir_block(fs, new_blk, block); + } else { + retval = ext2fs_get_mem(fs->blocksize, &block); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + memset(block, 0, fs->blocksize); + retval = io_channel_write_blk64(fs->io, new_blk, 1, block); + } + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + ext2fs_free_mem(&block); + *blocknr = new_blk; + ext2fs_block_alloc_stats2(fs, new_blk, +1); + es->newblocks++; + + if (es->done) + return (BLOCK_CHANGED | BLOCK_ABORT); + else + return BLOCK_CHANGED; +} + +errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir) +{ + errcode_t retval; + struct expand_dir_struct es; + struct ext2_inode inode; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!fs->block_map) + return EXT2_ET_NO_BLOCK_BITMAP; + + retval = ext2fs_check_directory(fs, dir); + if (retval) + return retval; + + es.done = 0; + es.err = 0; + es.newblocks = 0; + + retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND, + 0, expand_dir_proc, &es); + + if (es.err) + return es.err; + if (!es.done) + return EXT2_ET_EXPAND_DIR_ERR; + + /* + * Update the size and block count fields in the inode. + */ + retval = ext2fs_read_inode(fs, dir, &inode); + if (retval) + return retval; + + inode.i_size += fs->blocksize; + ext2fs_iblk_add_blocks(fs, &inode, es.newblocks); + + retval = ext2fs_write_inode(fs, dir, &inode); + if (retval) + return retval; + + return 0; +} diff --git a/libcustomext2fs/source/ext2.c b/libcustomext2fs/source/ext2.c new file mode 100644 index 00000000..7cff7f3c --- /dev/null +++ b/libcustomext2fs/source/ext2.c @@ -0,0 +1,420 @@ +/** + * ext2file.c - devoptab file routines for EXT2-based devices. + * + * Copyright (c) 2006 Michael "Chishm" Chisholm + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2_internal.h" +#include "gekko_io.h" +#include "mem_allocate.h" +#include "partitions.h" + +bool ext2Mount(const char *name, const DISC_INTERFACE *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags) +{ + errcode_t retval = -1; + ext2_filsys fs = NULL; + io_channel io_chan = NULL; + gekko_fd *fd = NULL; + ext2_vd * vd = NULL; + + // Sanity check + if (!name || !interface) + { + errno = EINVAL; + return false; + } + + // Allocate the device driver descriptor + fd = (gekko_fd*) mem_alloc(sizeof(gekko_fd)); + if (!fd) + goto cleanup; + + memset(fd, 0, sizeof(gekko_fd)); + + // Setup the device driver descriptor + fd->interface = interface; + fd->startSector = startSector; + fd->sectorSize = 0; + fd->sectorCount = 0; + fd->cachePageCount = cachePageCount; + fd->cachePageSize = cachePageSize; + + fs = mem_alloc(sizeof(struct struct_ext2_filsys)); + if (!fs) + { + ext2_log_trace("no memory for fs\n"); + errno = ENOMEM; + goto cleanup; + } + + memset(fs, 0, sizeof(struct struct_ext2_filsys)); + + io_chan = mem_alloc(sizeof(struct struct_io_channel)); + if (!io_chan) + { + ext2_log_trace("no memory for io_chan\n"); + errno = ENOMEM; + goto cleanup; + } + + memset(io_chan, 0, sizeof(struct struct_io_channel)); + + io_chan->magic = EXT2_ET_MAGIC_IO_CHANNEL; + io_chan->manager = gekko_io_manager; + io_chan->name = strdup(name); + if(!io_chan->name) goto cleanup; + io_chan->block_size = 1024; + io_chan->read_error = 0; + io_chan->write_error = 0; + io_chan->refcount = 1; + io_chan->private_data = fd; + io_chan->flags = flags; + + retval = ext2fs_open2(io_chan->name, 0, io_chan->flags, 0, 0, &io_chan, &fs); + if(retval) + { + ext2_log_trace("error mounting %i\n", (int) retval); + goto cleanup; + } + + vd = mem_alloc(sizeof(ext2_vd)); + if(!vd) + { + ext2_log_trace("no memory for vd\n"); + goto cleanup; + } + + // Initialise the volume descriptor + ext2InitVolume(vd); + vd->fs = fs; + vd->io = io_chan; + vd->root = EXT2_ROOT_INO; + + // Add the device to the devoptab table + if (ext2AddDevice(name, vd)) { + ext2DeinitVolume(vd); + goto cleanup; + } + + return true; + +cleanup: + if(fd) + mem_free(fd); + if(io_chan) + mem_free(io_chan); + if(vd) + mem_free(vd); + if(fs) + { + ext2fs_close(fs); + ext2fs_free(fs); + } + + return false; +} + +void ext2Unmount(const char *name) +{ + ext2_vd *vd = NULL; + + // Get the devices volume descriptor + vd = ext2GetVolume(name); + if (!vd) + return; + + // Remove the device from the devoptab table + ext2RemoveDevice(name); + + // Deinitialise the volume descriptor + ext2DeinitVolume(vd); + + // Unmount the volume + ext2fs_close(vd->fs); + ext2fs_free(vd->fs); + + //Free the io manager + mem_free(vd->io->private_data); + mem_free(vd->io); + + // Free the volume descriptor + mem_free(vd); + + return; +} + + +const char *ext2GetVolumeName (const char *name) +{ + if (!name) { + errno = EINVAL; + return NULL; + } + + // Get the devices volume descriptor + ext2_vd *vd = ext2GetVolume(name); + if (!vd) { + errno = ENODEV; + return NULL; + } + + return vd->fs->super->s_volume_name; +} + +bool ext2SetVolumeName (const char *name, const char *volumeName) +{ + // Sanity check + if (!name || !volumeName) { + errno = EINVAL; + return false; + } + + // Get the devices volume descriptor + ext2_vd *vd = ext2GetVolume(name); + if (!vd) { + errno = ENODEV; + return false; + } + + // Lock + ext2Lock(vd); + int i; + for(i = 0; i < 15 && *volumeName != 0; ++i, volumeName++) + vd->fs->super->s_volume_name[i] = *volumeName; + + vd->fs->super->s_volume_name[i] = '\0'; + + ext2fs_mark_super_dirty(vd->fs); + + ext2Sync(vd, NULL); + + // Unlock + ext2Unlock(vd); + + return true; +} + +int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) +{ + MASTER_BOOT_RECORD mbr; + PARTITION_RECORD *partition = NULL; + int partition_count = 0, ret = -1; + sec_t part_lba = 0; + sec_t * partitions = NULL; + int i; + + union { + u8 buffer[512]; + MASTER_BOOT_RECORD mbr; + EXTENDED_BOOT_RECORD ebr; + } sector; + + // Sanity check + if (!interface) { + errno = EINVAL; + return -1; + } + + if(!out_partitions) { + errno = EINVAL; + return -1; + } + + // Start the device and check that it is inserted + if (!interface->startup()) { + errno = EIO; + return -1; + } + if (!interface->isInserted()) { + errno = EIO; + return 0; + } + + struct ext2_super_block * super = (struct ext2_super_block *) malloc(SUPERBLOCK_SIZE); //1024 bytes + if(!super) + { + ext2_log_trace("no memory for superblock"); + errno = ENOMEM; + return -1; + } + + partitions = (sec_t *) malloc(sizeof(sec_t)); + if(!partitions) + { + ext2_log_trace("no memory for partitions"); + errno = ENOMEM; + mem_free(super); + return -1; + } + // Read the first sector on the device + if (!interface->readSectors(0, 1, §or.buffer)) { + errno = EIO; + mem_free(partitions); + mem_free(super); + return -1; + } + + // If this is the devices master boot record + if (sector.mbr.signature == MBR_SIGNATURE) + { + memcpy(&mbr, §or, sizeof(MASTER_BOOT_RECORD)); + + // Search the partition table for all EXT2/3/4 partitions (max. 4 primary partitions) + for (i = 0; i < 4; i++) + { + partition = &mbr.partitions[i]; + part_lba = ext2fs_le32_to_cpu(mbr.partitions[i].lba_start); + + // Figure out what type of partition this is + switch (partition->type) + { + // Ignore empty partitions + case PARTITION_TYPE_EMPTY: + continue; + + // EXT2/3/4 partition + case PARTITION_TYPE_LINUX: + + // Read and validate the EXT partition + if (interface->readSectors(part_lba+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + { + if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) + { + partition_count++; + sec_t * tmp = (sec_t *) realloc(partitions, partition_count*sizeof(sec_t)); + if(!tmp) goto cleanup; + partitions = tmp; + partitions[partition_count-1] = part_lba; + } + } + + break; + + // DOS 3.3+ or Windows 95 extended partition + case PARTITION_TYPE_DOS33_EXTENDED: + case PARTITION_TYPE_WIN95_EXTENDED: + { + ext2_log_trace("Partition %i: Claims to be Extended\n", i + 1); + + // Walk the extended partition chain, finding all EXT partitions within it + sec_t ebr_lba = part_lba; + sec_t next_erb_lba = 0; + do { + // Read and validate the extended boot record + if (interface->readSectors(ebr_lba + next_erb_lba, 1, §or)) + { + if (sector.ebr.signature == EBR_SIGNATURE) + { + ext2_log_trace("Logical Partition @ %d: %s type 0x%x\n", ebr_lba + next_erb_lba, + sector.ebr.partition.status == PARTITION_STATUS_BOOTABLE ? "bootable (active)" : "non-bootable", + sector.ebr.partition.type); + + // Get the start sector of the current partition + // and the next extended boot record in the chain + part_lba = ebr_lba + next_erb_lba + ext2fs_le32_to_cpu(sector.ebr.partition.lba_start); + next_erb_lba = ext2fs_le32_to_cpu(sector.ebr.next_ebr.lba_start); + + // Check if this partition has a valid EXT boot record + if (interface->readSectors(part_lba+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + { + if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) + { + partition_count++; + sec_t * tmp = (sec_t *) realloc(partitions, partition_count*sizeof(sec_t)); + if(!tmp) goto cleanup; + partitions = tmp; + partitions[partition_count-1] = part_lba; + } + } + } + else + next_erb_lba = 0; + } + + } while (next_erb_lba); + + break; + + } + + // Unknown or unsupported partition type + default: + { + // Check if this partition has a valid EXT boot record anyway, + // it might be misrepresented due to a lazy partition editor + if (interface->readSectors(part_lba+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + { + if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) + { + partition_count++; + sec_t * tmp = (sec_t *) realloc(partitions, partition_count*sizeof(sec_t)); + if(!tmp) goto cleanup; + partitions = tmp; + partitions[partition_count-1] = part_lba; + } + } + break; + } + } + } + + // Else it is assumed this device has no master boot record + } + else + { + ext2_log_trace("No Master Boot Record was found!\n"); + + // As a last-ditched effort, search the first 64 sectors of the device for stray EXT partitions + for (i = 1; i < 64; i++) + { + if (interface->readSectors(i+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + { + if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) + { + partition_count++; + sec_t * tmp = (sec_t *) realloc(partitions, partition_count*sizeof(sec_t)); + if(!tmp) goto cleanup; + partitions = tmp; + partitions[partition_count-1] = i; + } + } + } + + } + + // Return the found partitions (if any) + if (partition_count > 0) + { + *out_partitions = partitions; + ret = partition_count; + } + +cleanup: + + if(partitions && partition_count == 0) + mem_free(partitions); + if(super) + mem_free(super); + + return ret; +} + diff --git a/libcustomext2fs/source/ext2_err.h b/libcustomext2fs/source/ext2_err.h new file mode 100644 index 00000000..4f127443 --- /dev/null +++ b/libcustomext2fs/source/ext2_err.h @@ -0,0 +1,152 @@ +// +// Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. +// +// This file may be redistributed under the terms of the GNU Public +// License. +#ifndef EXT2_ERR_H_ +#define EXT2_ERR_H_ + +#define EXT2_ET_OK 0 +#define EXT2_ET_BASE -1 +#define EXT2_ET_MAGIC_EXT2FS_FILSYS -2 +#define EXT2_ET_MAGIC_BADBLOCKS_LIST -3 +#define EXT2_ET_MAGIC_BADBLOCKS_ITERATE -4 +#define EXT2_ET_MAGIC_INODE_SCAN -5 +#define EXT2_ET_MAGIC_IO_CHANNEL -6 +#define EXT2_ET_MAGIC_UNIX_IO_CHANNEL -7 +#define EXT2_ET_MAGIC_IO_MANAGER -8 +#define EXT2_ET_MAGIC_BLOCK_BITMAP -9 +#define EXT2_ET_MAGIC_INODE_BITMAP -10 +#define EXT2_ET_MAGIC_GENERIC_BITMAP -11 +#define EXT2_ET_MAGIC_TEST_IO_CHANNEL -12 +#define EXT2_ET_MAGIC_DBLIST -13 +#define EXT2_ET_MAGIC_ICOUNT -14 +#define EXT2_ET_MAGIC_PQ_IO_CHANNEL -15 +#define EXT2_ET_MAGIC_EXT2_FILE -16 +#define EXT2_ET_MAGIC_E2IMAGE -17 +#define EXT2_ET_MAGIC_INODE_IO_CHANNEL -18 +#define EXT2_ET_MAGIC_EXTENT_HANDLE -19 +#define EXT2_ET_BAD_MAGIC -20 +#define EXT2_ET_REV_TOO_HIGH -21 +#define EXT2_ET_RO_FILSYS -22 +#define EXT2_ET_GDESC_READ -23 +#define EXT2_ET_GDESC_WRITE -24 +#define EXT2_ET_GDESC_BAD_BLOCK_MAP -25 +#define EXT2_ET_GDESC_BAD_INODE_MAP -26 +#define EXT2_ET_GDESC_BAD_INODE_TABLE -27 +#define EXT2_ET_INODE_BITMAP_WRITE -28 +#define EXT2_ET_INODE_BITMAP_READ -29 +#define EXT2_ET_BLOCK_BITMAP_WRITE -30 +#define EXT2_ET_BLOCK_BITMAP_READ -31 +#define EXT2_ET_INODE_TABLE_WRITE -32 +#define EXT2_ET_INODE_TABLE_READ -33 +#define EXT2_ET_NEXT_INODE_READ -34 +#define EXT2_ET_UNEXPECTED_BLOCK_SIZE -35 +#define EXT2_ET_DIR_CORRUPTED -36 +#define EXT2_ET_SHORT_READ -37 +#define EXT2_ET_SHORT_WRITE -38 +#define EXT2_ET_DIR_NO_SPACE -39 +#define EXT2_ET_NO_INODE_BITMAP -40 +#define EXT2_ET_NO_BLOCK_BITMAP -41 +#define EXT2_ET_BAD_INODE_NUM -42 +#define EXT2_ET_BAD_BLOCK_NUM -45 +#define EXT2_ET_EXPAND_DIR_ERR -46 +#define EXT2_ET_TOOSMALL -47 +#define EXT2_ET_BAD_BLOCK_MARK -48 +#define EXT2_ET_BAD_BLOCK_UNMARK -49 +#define EXT2_ET_BAD_BLOCK_TEST -50 +#define EXT2_ET_BAD_INODE_MARK -51 +#define EXT2_ET_BAD_INODE_UNMARK -52 +#define EXT2_ET_BAD_INODE_TEST -53 +#define EXT2_ET_FUDGE_BLOCK_BITMAP_END -54 +#define EXT2_ET_FUDGE_INODE_BITMAP_END -55 +#define EXT2_ET_BAD_IND_BLOCK -56 +#define EXT2_ET_BAD_DIND_BLOCK -57 +#define EXT2_ET_BAD_TIND_BLOCK -58 +#define EXT2_ET_NEQ_BLOCK_BITMAP -59 +#define EXT2_ET_NEQ_INODE_BITMAP -60 +#define EXT2_ET_BAD_DEVICE_NAME -61 +#define EXT2_ET_MISSING_INODE_TABLE -62 +#define EXT2_ET_CORRUPT_SUPERBLOCK -63 +#define EXT2_ET_BAD_GENERIC_MARK -64 +#define EXT2_ET_BAD_GENERIC_UNMARK -65 +#define EXT2_ET_BAD_GENERIC_TEST -66 +#define EXT2_ET_SYMLINK_LOOP -67 +#define EXT2_ET_CALLBACK_NOTHANDLED -68 +#define EXT2_ET_BAD_BLOCK_IN_INODE_TABLE -69 +#define EXT2_ET_UNSUPP_FEATURE -70 +#define EXT2_ET_RO_UNSUPP_FEATURE -71 +#define EXT2_ET_LLSEEK_FAILED -72 +#define EXT2_ET_NO_MEMORY -73 +#define EXT2_ET_INVALID_ARGUMENT -74 +#define EXT2_ET_BLOCK_ALLOC_FAIL -75 +#define EXT2_ET_INODE_ALLOC_FAIL -76 +#define EXT2_ET_NO_DIRECTORY -77 +#define EXT2_ET_TOO_MANY_REFS -78 +#define EXT2_ET_FILE_NOT_FOUND -79 +#define EXT2_ET_FILE_RO -80 +#define EXT2_ET_DB_NOT_FOUND -81 +#define EXT2_ET_DIR_EXISTS -82 +#define EXT2_ET_UNIMPLEMENTED -83 +#define EXT2_ET_CANCEL_REQUESTED -84 +#define EXT2_ET_FILE_TOO_BIG -85 +#define EXT2_ET_JOURNAL_NOT_BLOCK -86 +#define EXT2_ET_NO_JOURNAL_SB -87 +#define EXT2_ET_JOURNAL_TOO_SMALL -88 +#define EXT2_ET_JOURNAL_UNSUPP_VERSION -89 +#define EXT2_ET_LOAD_EXT_JOURNAL -90 +#define EXT2_ET_NO_JOURNAL -91 +#define EXT2_ET_DIRHASH_UNSUPP -92 +#define EXT2_ET_BAD_EA_BLOCK_NUM -93 +#define EXT2_ET_TOO_MANY_INODES -94 +#define EXT2_ET_NOT_IMAGE_FILE -95 +#define EXT2_ET_RES_GDT_BLOCKS -96 +#define EXT2_ET_RESIZE_INODE_CORRUPT -97 +#define EXT2_ET_SET_BMAP_NO_IND -98 +#define EXT2_ET_TDB_SUCCESS -99 +#define EXT2_ET_TDB_ERR_CORRUPT -100 +#define EXT2_ET_TDB_ERR_IO -101 +#define EXT2_ET_TDB_ERR_LOCK -102 +#define EXT2_ET_TDB_ERR_OOM -103 +#define EXT2_ET_TDB_ERR_EXISTS -104 +#define EXT2_ET_TDB_ERR_NOLOCK -105 +#define EXT2_ET_TDB_ERR_EINVAL -106 +#define EXT2_ET_TDB_ERR_NOEXIST -107 +#define EXT2_ET_TDB_ERR_RDONLY -108 +#define EXT2_ET_DBLIST_EMPTY -109 +#define EXT2_ET_RO_BLOCK_ITERATE -110 +#define EXT2_ET_MAGIC_EXTENT_PATH -111 +#define EXT2_ET_MAGIC_RESERVED_10 -112 +#define EXT2_ET_MAGIC_RESERVED_11 -113 +#define EXT2_ET_MAGIC_RESERVED_12 -114 +#define EXT2_ET_MAGIC_RESERVED_13 -115 +#define EXT2_ET_MAGIC_RESERVED_14 -116 +#define EXT2_ET_MAGIC_RESERVED_15 -117 +#define EXT2_ET_MAGIC_RESERVED_16 -118 +#define EXT2_ET_MAGIC_RESERVED_17 -119 +#define EXT2_ET_MAGIC_RESERVED_18 -120 +#define EXT2_ET_MAGIC_RESERVED_19 -121 +#define EXT2_ET_EXTENT_HEADER_BAD -122 +#define EXT2_ET_EXTENT_INDEX_BAD -123 +#define EXT2_ET_EXTENT_LEAF_BAD -124 +#define EXT2_ET_EXTENT_NO_SPACE -125 +#define EXT2_ET_INODE_NOT_EXTENT -126 +#define EXT2_ET_EXTENT_NO_NEXT -127 +#define EXT2_ET_EXTENT_NO_PREV -128 +#define EXT2_ET_EXTENT_NO_UP -129 +#define EXT2_ET_EXTENT_NO_DOWN -130 +#define EXT2_ET_NO_CURRENT_NODE -131 +#define EXT2_ET_OP_NOT_SUPPORTED -132 +#define EXT2_ET_CANT_INSERT_EXTENT -133 +#define EXT2_ET_CANT_SPLIT_EXTENT -134 +#define EXT2_ET_EXTENT_NOT_FOUND -135 +#define EXT2_ET_EXTENT_NOT_SUPPORTED -136 +#define EXT2_ET_EXTENT_INVALID_LENGTH -137 +#define EXT2_ET_IO_CHANNEL_NO_SUPPORT_64 -138 +#define EXT2_NO_MTAB_FILE -139 +#define EXT2_ET_MAGIC_GENERIC_BITMAP64 -140 +#define EXT2_ET_MAGIC_BLOCK_BITMAP64 -141 +#define EXT2_ET_MAGIC_INODE_BITMAP64 -142 +#define EXT2_ET_CANT_USE_LEGACY_BITMAPS -143 + +#endif diff --git a/libcustomext2fs/source/ext2_ext_attr.h b/libcustomext2fs/source/ext2_ext_attr.h new file mode 100644 index 00000000..ed548d12 --- /dev/null +++ b/libcustomext2fs/source/ext2_ext_attr.h @@ -0,0 +1,71 @@ +/* + File: linux/ext2_ext_attr.h + + On-disk format of extended attributes for the ext2 filesystem. + + (C) 2000 Andreas Gruenbacher, +*/ + +#ifndef _EXT2_EXT_ATTR_H +#define _EXT2_EXT_ATTR_H +/* Magic value in attribute blocks */ +#define EXT2_EXT_ATTR_MAGIC_v1 0xEA010000 +#define EXT2_EXT_ATTR_MAGIC 0xEA020000 + +/* Maximum number of references to one attribute block */ +#define EXT2_EXT_ATTR_REFCOUNT_MAX 1024 + +struct ext2_ext_attr_header { + __u32 h_magic; /* magic number for identification */ + __u32 h_refcount; /* reference count */ + __u32 h_blocks; /* number of disk blocks used */ + __u32 h_hash; /* hash value of all attributes */ + __u32 h_reserved[4]; /* zero right now */ +}; + +struct ext2_ext_attr_entry { + __u8 e_name_len; /* length of name */ + __u8 e_name_index; /* attribute name index */ + __u16 e_value_offs; /* offset in disk block of value */ + __u32 e_value_block; /* disk block attribute is stored on (n/i) */ + __u32 e_value_size; /* size of attribute value */ + __u32 e_hash; /* hash value of name and value */ +#if 0 + char e_name[0]; /* attribute name */ +#endif +}; + +#define EXT2_EXT_ATTR_PAD_BITS 2 +#define EXT2_EXT_ATTR_PAD ((unsigned) 1<e_name_len)) ) +#define EXT2_EXT_ATTR_SIZE(size) \ + (((size) + EXT2_EXT_ATTR_ROUND) & ~EXT2_EXT_ATTR_ROUND) +#define EXT2_EXT_IS_LAST_ENTRY(entry) (*((__u32 *)(entry)) == 0UL) +#define EXT2_EXT_ATTR_NAME(entry) \ + (((char *) (entry)) + sizeof(struct ext2_ext_attr_entry)) +#define EXT2_XATTR_LEN(name_len) \ + (((name_len) + EXT2_EXT_ATTR_ROUND + \ + sizeof(struct ext2_xattr_entry)) & ~EXT2_EXT_ATTR_ROUND) +#define EXT2_XATTR_SIZE(size) \ + (((size) + EXT2_EXT_ATTR_ROUND) & ~EXT2_EXT_ATTR_ROUND) + +#ifdef __KERNEL__ +# ifdef CONFIG_EXT2_FS_EXT_ATTR +extern int ext2_get_ext_attr(struct inode *, const char *, char *, size_t, int); +extern int ext2_set_ext_attr(struct inode *, const char *, char *, size_t, int); +extern void ext2_ext_attr_free_inode(struct inode *inode); +extern void ext2_ext_attr_put_super(struct super_block *sb); +extern int ext2_ext_attr_init(void); +extern void ext2_ext_attr_done(void); +# else +# define ext2_get_ext_attr NULL +# define ext2_set_ext_attr NULL +# endif +#endif /* __KERNEL__ */ +#endif /* _EXT2_EXT_ATTR_H */ diff --git a/libcustomext2fs/source/ext2_frag.c b/libcustomext2fs/source/ext2_frag.c new file mode 100644 index 00000000..e05a4bc7 --- /dev/null +++ b/libcustomext2fs/source/ext2_frag.c @@ -0,0 +1,60 @@ +#include "ext2_internal.h" +#include "ext2_frag.h" + +typedef struct _PrivData +{ + _ext2_frag_append_t append_fragment; + void * callback_data; +} PrivDataST; + +static int block_iter_callback(ext2_filsys fs, blk64_t *blocknr, e2_blkcnt_t blockcnt, blk64_t ref_block, int ref_offset, void *privateData) +{ + PrivDataST *priv = (PrivDataST *) privateData; + blk64_t block; + block = *blocknr; + + return priv->append_fragment(priv->callback_data, blockcnt*fs->io->block_size/512, block*fs->io->block_size/512, fs->io->block_size/512); +} + +int _EXT2_get_fragments(const char *in_path, _ext2_frag_append_t append_fragment, void *callback_data) +{ + ext2_inode_t *ni = NULL; + ext2_vd *vd; + + vd = ext2GetVolume(in_path); + + if(!vd) + { + errno = EXDEV; + return -1; + } + + // Get the actual path of the entry + const char * path = ext2RealPath(in_path); + if (!path) { + errno = EINVAL; + return -1; + } + + // Find the entry + ni = ext2OpenEntry(vd, path); + if (!ni) { + errno = ENOENT; + return -1; + } + + PrivDataST priv; + priv.callback_data = callback_data; + priv.append_fragment = append_fragment; + + int ret = ext2fs_block_iterate3(vd->fs, ni->ino, BLOCK_FLAG_DATA_ONLY, NULL, block_iter_callback, &priv); + + if(ret == 0) + ret = priv.append_fragment(callback_data, EXT2_I_SIZE(&ni->ni) >> 9, 0, 0); + + ext2UpdateTimes(vd, ni, EXT2_UPDATE_ATIME); + + ext2CloseEntry(vd, ni); + + return ret; +} diff --git a/source/libs/libext2fs/ext2_frag.h b/libcustomext2fs/source/ext2_frag.h similarity index 100% rename from source/libs/libext2fs/ext2_frag.h rename to libcustomext2fs/source/ext2_frag.h diff --git a/libcustomext2fs/source/ext2_fs.h b/libcustomext2fs/source/ext2_fs.h new file mode 100644 index 00000000..132663d3 --- /dev/null +++ b/libcustomext2fs/source/ext2_fs.h @@ -0,0 +1,798 @@ +/* + * linux/include/linux/ext2_fs.h + * + * Copyright (C) 1992, 1993, 1994, 1995 + * Remy Card (card@masi.ibp.fr) + * Laboratoire MASI - Institut Blaise Pascal + * Universite Pierre et Marie Curie (Paris VI) + * + * from + * + * linux/include/linux/minix_fs.h + * + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +#ifndef _LINUX_EXT2_FS_H +#define _LINUX_EXT2_FS_H + +#include "ext2_types.h" /* Changed from linux/types.h */ + +/* + * The second extended filesystem constants/structures + */ + +/* + * Define EXT2FS_DEBUG to produce debug messages + */ +#undef EXT2FS_DEBUG + +/* + * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files + */ +#define EXT2_PREALLOCATE +#define EXT2_DEFAULT_PREALLOC_BLOCKS 8 + +/* + * The second extended file system version + */ +#define EXT2FS_DATE "95/08/09" +#define EXT2FS_VERSION "0.5b" + +/* + * Special inode numbers + */ +#define EXT2_BAD_INO 1 /* Bad blocks inode */ +#define EXT2_ROOT_INO 2 /* Root inode */ +#define EXT2_ACL_IDX_INO 3 /* ACL inode */ +#define EXT2_ACL_DATA_INO 4 /* ACL inode */ +#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */ +#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */ +#define EXT2_RESIZE_INO 7 /* Reserved group descriptors inode */ +#define EXT2_JOURNAL_INO 8 /* Journal inode */ +#define EXT2_EXCLUDE_INO 9 /* The "exclude" inode, for snapshots */ + +/* First non-reserved inode for old ext2 filesystems */ +#define EXT2_GOOD_OLD_FIRST_INO 11 + +/* + * The second extended file system magic number + */ +#define EXT2_SUPER_MAGIC 0xEF53 + +#ifdef __KERNEL__ +#define EXT2_SB(sb) (&((sb)->u.ext2_sb)) +#else +/* Assume that user mode programs are passing in an ext2fs superblock, not + * a kernel struct super_block. This will allow us to call the feature-test + * macros from user land. */ +#define EXT2_SB(sb) (sb) +#endif + +/* + * Maximal count of links to a file + */ +#define EXT2_LINK_MAX 65000 + +/* + * Macro-instructions used to manage several block sizes + */ +#define EXT2_MIN_BLOCK_LOG_SIZE 10 /* 1024 */ +#define EXT2_MAX_BLOCK_LOG_SIZE 16 /* 65536 */ +#define EXT2_MIN_BLOCK_SIZE (1 << EXT2_MIN_BLOCK_LOG_SIZE) +#define EXT2_MAX_BLOCK_SIZE (1 << EXT2_MAX_BLOCK_LOG_SIZE) +#ifdef __KERNEL__ +#define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize) +#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits) +#define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->addr_per_block_bits) +#define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size) +#define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino) +#else +#define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size) +#define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10) +#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \ + EXT2_GOOD_OLD_INODE_SIZE : (s)->s_inode_size) +#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \ + EXT2_GOOD_OLD_FIRST_INO : (s)->s_first_ino) +#endif +#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(__u32)) + +/* + * Macro-instructions used to manage fragments + */ +#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE +#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE +#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE +#ifdef __KERNEL__ +# define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size) +# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block) +#else +# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size) +# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s)) +#endif + +/* + * ACL structures + */ +struct ext2_acl_header /* Header of Access Control Lists */ +{ + __u32 aclh_size; + __u32 aclh_file_count; + __u32 aclh_acle_count; + __u32 aclh_first_acle; +}; + +struct ext2_acl_entry /* Access Control List Entry */ +{ + __u32 acle_size; + __u16 acle_perms; /* Access permissions */ + __u16 acle_type; /* Type of entry */ + __u16 acle_tag; /* User or group identity */ + __u16 acle_pad1; + __u32 acle_next; /* Pointer on next entry for the */ + /* same inode or on next free entry */ +}; + +/* + * Structure of a blocks group descriptor + */ +struct ext2_group_desc +{ + __u32 bg_block_bitmap; /* Blocks bitmap block */ + __u32 bg_inode_bitmap; /* Inodes bitmap block */ + __u32 bg_inode_table; /* Inodes table block */ + __u16 bg_free_blocks_count; /* Free blocks count */ + __u16 bg_free_inodes_count; /* Free inodes count */ + __u16 bg_used_dirs_count; /* Directories count */ + __u16 bg_flags; + __u32 bg_reserved[2]; + __u16 bg_itable_unused; /* Unused inodes count */ + __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/ +}; + +/* + * Structure of a blocks group descriptor + */ +struct ext4_group_desc +{ + __u32 bg_block_bitmap; /* Blocks bitmap block */ + __u32 bg_inode_bitmap; /* Inodes bitmap block */ + __u32 bg_inode_table; /* Inodes table block */ + __u16 bg_free_blocks_count; /* Free blocks count */ + __u16 bg_free_inodes_count; /* Free inodes count */ + __u16 bg_used_dirs_count; /* Directories count */ + __u16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ + __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */ + __u16 bg_itable_unused; /* Unused inodes count */ + __u16 bg_checksum; /* crc16(sb_uuid+group+desc) */ + __u32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ + __u32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */ + __u32 bg_inode_table_hi; /* Inodes table block MSB */ + __u16 bg_free_blocks_count_hi;/* Free blocks count MSB */ + __u16 bg_free_inodes_count_hi;/* Free inodes count MSB */ + __u16 bg_used_dirs_count_hi; /* Directories count MSB */ + __u16 bg_itable_unused_hi; /* Unused inodes count MSB */ + __u32 bg_reserved2[3]; +}; + +#define EXT2_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not initialized */ +#define EXT2_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not initialized */ +#define EXT2_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ + +/* + * Data structures used by the directory indexing feature + * + * Note: all of the multibyte integer fields are little endian. + */ + +/* + * Note: dx_root_info is laid out so that if it should somehow get + * overlaid by a dirent the two low bits of the hash version will be + * zero. Therefore, the hash version mod 4 should never be 0. + * Sincerely, the paranoia department. + */ +struct ext2_dx_root_info { + __u32 reserved_zero; + __u8 hash_version; /* 0 now, 1 at release */ + __u8 info_length; /* 8 */ + __u8 indirect_levels; + __u8 unused_flags; +}; + +#define EXT2_HASH_LEGACY 0 +#define EXT2_HASH_HALF_MD4 1 +#define EXT2_HASH_TEA 2 +#define EXT2_HASH_LEGACY_UNSIGNED 3 /* reserved for userspace lib */ +#define EXT2_HASH_HALF_MD4_UNSIGNED 4 /* reserved for userspace lib */ +#define EXT2_HASH_TEA_UNSIGNED 5 /* reserved for userspace lib */ + +#define EXT2_HASH_FLAG_INCOMPAT 0x1 + +struct ext2_dx_entry { + __u32 hash; + __u32 block; +}; + +struct ext2_dx_countlimit { + __u16 limit; + __u16 count; +}; + + +/* + * Macro-instructions used to manage group descriptors + */ +#define EXT2_MIN_DESC_SIZE 32 +#define EXT2_MIN_DESC_SIZE_64BIT 64 +#define EXT2_MAX_DESC_SIZE EXT2_MIN_BLOCK_SIZE +#define EXT2_DESC_SIZE(s) \ + ((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \ + (s)->s_desc_size : EXT2_MIN_DESC_SIZE) + +#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group) +#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group) +#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s)) +/* limits imposed by 16-bit value gd_free_{blocks,inode}_count */ +#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8) +#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s)) +#ifdef __KERNEL__ +#define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block) +#define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits) +#else +#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_DESC_SIZE(s)) +#endif + +/* + * Constants relative to the data blocks + */ +#define EXT2_NDIR_BLOCKS 12 +#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS +#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1) +#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1) +#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1) + +/* + * Inode flags + */ +#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */ +#define EXT2_UNRM_FL 0x00000002 /* Undelete */ +#define EXT2_COMPR_FL 0x00000004 /* Compress file */ +#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */ +#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */ +#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */ +#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */ +#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */ +/* Reserved for compression usage... */ +#define EXT2_DIRTY_FL 0x00000100 +#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ +#define EXT2_NOCOMPR_FL 0x00000400 /* Access raw compressed data */ +#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */ +/* End compression flags --- maybe not all used */ +#define EXT2_BTREE_FL 0x00001000 /* btree format dir */ +#define EXT2_INDEX_FL 0x00001000 /* hash-indexed directory */ +#define EXT2_IMAGIC_FL 0x00002000 +#define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ +#define EXT2_NOTAIL_FL 0x00008000 /* file tail should not be merged */ +#define EXT2_DIRSYNC_FL 0x00010000 /* Synchronous directory modifications */ +#define EXT2_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ +#define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ +#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ +#define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */ +#define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */ +#define EXT4_SNAPFILE_FL 0x01000000 /* Inode is a snapshot */ +#define EXT4_SNAPFILE_DELETED_FL 0x04000000 /* Snapshot is being deleted */ +#define EXT4_SNAPFILE_SHRUNK_FL 0x08000000 /* Snapshot shrink has completed */ +#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ + +#define EXT2_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */ +#define EXT2_FL_USER_MODIFIABLE 0x004B80FF /* User modifiable flags */ + +/* + * ioctl commands + */ + +/* Used for online resize */ +struct ext2_new_group_input { + __u32 group; /* Group number for this data */ + __u32 block_bitmap; /* Absolute block number of block bitmap */ + __u32 inode_bitmap; /* Absolute block number of inode bitmap */ + __u32 inode_table; /* Absolute block number of inode table start */ + __u32 blocks_count; /* Total number of blocks in this group */ + __u16 reserved_blocks; /* Number of reserved blocks in this group */ + __u16 unused; /* Number of reserved GDT blocks in group */ +}; + +struct ext4_new_group_input { + __u32 group; /* Group number for this data */ + __u64 block_bitmap; /* Absolute block number of block bitmap */ + __u64 inode_bitmap; /* Absolute block number of inode bitmap */ + __u64 inode_table; /* Absolute block number of inode table start */ + __u32 blocks_count; /* Total number of blocks in this group */ + __u16 reserved_blocks; /* Number of reserved blocks in this group */ + __u16 unused; +}; + +#ifdef __GNU__ /* Needed for the Hurd */ +#define _IOT_ext2_new_group_input _IOT (_IOTS(__u32), 5, _IOTS(__u16), 2, 0, 0) +#endif + +#define EXT2_IOC_GETFLAGS _IOR('f', 1, long) +#define EXT2_IOC_SETFLAGS _IOW('f', 2, long) +#define EXT2_IOC_GETVERSION _IOR('v', 1, long) +#define EXT2_IOC_SETVERSION _IOW('v', 2, long) +#define EXT2_IOC_GETVERSION_NEW _IOR('f', 3, long) +#define EXT2_IOC_SETVERSION_NEW _IOW('f', 4, long) +#define EXT2_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) +#define EXT2_IOC_GROUP_ADD _IOW('f', 8,struct ext2_new_group_input) +#define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input) + +/* + * Structure of an inode on the disk + */ +struct ext2_inode { + __u16 i_mode; /* File mode */ + __u16 i_uid; /* Low 16 bits of Owner Uid */ + __u32 i_size; /* Size in bytes */ + __u32 i_atime; /* Access time */ + __u32 i_ctime; /* Inode change time */ + __u32 i_mtime; /* Modification time */ + __u32 i_dtime; /* Deletion Time */ + __u16 i_gid; /* Low 16 bits of Group Id */ + __u16 i_links_count; /* Links count */ + __u32 i_blocks; /* Blocks count */ + __u32 i_flags; /* File flags */ + union { + struct { + __u32 l_i_version; /* was l_i_reserved1 */ + } linux1; + struct { + __u32 h_i_translator; + } hurd1; + } osd1; /* OS dependent 1 */ + __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ + __u32 i_generation; /* File version (for NFS) */ + __u32 i_file_acl; /* File ACL */ + __u32 i_size_high; /* Formerly i_dir_acl, directory ACL */ + __u32 i_faddr; /* Fragment address */ + union { + struct { + __u16 l_i_blocks_hi; + __u16 l_i_file_acl_high; + __u16 l_i_uid_high; /* these 2 fields */ + __u16 l_i_gid_high; /* were reserved2[0] */ + __u32 l_i_reserved2; + } linux2; + struct { + __u8 h_i_frag; /* Fragment number */ + __u8 h_i_fsize; /* Fragment size */ + __u16 h_i_mode_high; + __u16 h_i_uid_high; + __u16 h_i_gid_high; + __u32 h_i_author; + } hurd2; + } osd2; /* OS dependent 2 */ +}; + +/* + * Permanent part of an large inode on the disk + */ +struct ext2_inode_large { + __u16 i_mode; /* File mode */ + __u16 i_uid; /* Low 16 bits of Owner Uid */ + __u32 i_size; /* Size in bytes */ + __u32 i_atime; /* Access time */ + __u32 i_ctime; /* Inode Change time */ + __u32 i_mtime; /* Modification time */ + __u32 i_dtime; /* Deletion Time */ + __u16 i_gid; /* Low 16 bits of Group Id */ + __u16 i_links_count; /* Links count */ + __u32 i_blocks; /* Blocks count */ + __u32 i_flags; /* File flags */ + union { + struct { + __u32 l_i_version; /* was l_i_reserved1 */ + } linux1; + struct { + __u32 h_i_translator; + } hurd1; + } osd1; /* OS dependent 1 */ + __u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */ + __u32 i_generation; /* File version (for NFS) */ + __u32 i_file_acl; /* File ACL */ + __u32 i_size_high; /* Formerly i_dir_acl, directory ACL */ + __u32 i_faddr; /* Fragment address */ + union { + struct { + __u16 l_i_blocks_hi; + __u16 l_i_file_acl_high; + __u16 l_i_uid_high; /* these 2 fields */ + __u16 l_i_gid_high; /* were reserved2[0] */ + __u32 l_i_reserved2; + } linux2; + struct { + __u8 h_i_frag; /* Fragment number */ + __u8 h_i_fsize; /* Fragment size */ + __u16 h_i_mode_high; + __u16 h_i_uid_high; + __u16 h_i_gid_high; + __u32 h_i_author; + } hurd2; + } osd2; /* OS dependent 2 */ + __u16 i_extra_isize; + __u16 i_pad1; + __u32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ + __u32 i_mtime_extra; /* extra Modification time (nsec << 2 | epoch) */ + __u32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ + __u32 i_crtime; /* File creation time */ + __u32 i_crtime_extra; /* extra File creation time (nsec << 2 | epoch)*/ + __u32 i_version_hi; /* high 32 bits for 64-bit version */ +}; + +#define i_dir_acl i_size_high + +#if defined(__KERNEL__) || defined(__linux__) +#define i_reserved1 osd1.linux1.l_i_reserved1 +#define i_frag osd2.linux2.l_i_frag +#define i_fsize osd2.linux2.l_i_fsize +#define i_uid_low i_uid +#define i_gid_low i_gid +#define i_uid_high osd2.linux2.l_i_uid_high +#define i_gid_high osd2.linux2.l_i_gid_high +#define i_reserved2 osd2.linux2.l_i_reserved2 +#else +#if defined(__GNU__) + +#define i_translator osd1.hurd1.h_i_translator +#define i_frag osd2.hurd2.h_i_frag; +#define i_fsize osd2.hurd2.h_i_fsize; +#define i_uid_high osd2.hurd2.h_i_uid_high +#define i_gid_high osd2.hurd2.h_i_gid_high +#define i_author osd2.hurd2.h_i_author + +#endif /* __GNU__ */ +#endif /* defined(__KERNEL__) || defined(__linux__) */ + +#define inode_uid(inode) ((inode).i_uid | (inode).osd2.linux2.l_i_uid_high << 16) +#define inode_gid(inode) ((inode).i_gid | (inode).osd2.linux2.l_i_gid_high << 16) +#define ext2fs_set_i_uid_high(inode,x) ((inode).osd2.linux2.l_i_uid_high = (x)) +#define ext2fs_set_i_gid_high(inode,x) ((inode).osd2.linux2.l_i_gid_high = (x)) + +/* + * File system states + */ +#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */ +#define EXT2_ERROR_FS 0x0002 /* Errors detected */ +#define EXT3_ORPHAN_FS 0x0004 /* Orphans being recovered */ + +/* + * Misc. filesystem flags + */ +#define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */ +#define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */ +#define EXT2_FLAGS_TEST_FILESYS 0x0004 /* OK for use on development code */ +#define EXT2_FLAGS_IS_SNAPSHOT 0x0010 /* This is a snapshot image */ +#define EXT2_FLAGS_FIX_SNAPSHOT 0x0020 /* Snapshot inodes corrupted */ +#define EXT2_FLAGS_FIX_EXCLUDE 0x0040 /* Exclude bitmaps corrupted */ + +/* + * Mount flags + */ +#define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */ +#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */ +#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */ +#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */ +#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */ +#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */ +#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */ +#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */ + +#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt +#define set_opt(o, opt) o |= EXT2_MOUNT_##opt +#define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \ + EXT2_MOUNT_##opt) +/* + * Maximal mount counts between two filesystem checks + */ +#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */ +#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */ + +/* + * Behaviour when detecting errors + */ +#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */ +#define EXT2_ERRORS_RO 2 /* Remount fs read-only */ +#define EXT2_ERRORS_PANIC 3 /* Panic */ +#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE + +#if (__GNUC__ >= 4) +#define ext4_offsetof(TYPE,MEMBER) __builtin_offsetof(TYPE,MEMBER) +#else +#define ext4_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + +/* + * Structure of the super block + */ +struct ext2_super_block { + __u32 s_inodes_count; /* Inodes count */ + __u32 s_blocks_count; /* Blocks count */ + __u32 s_r_blocks_count; /* Reserved blocks count */ + __u32 s_free_blocks_count; /* Free blocks count */ + __u32 s_free_inodes_count; /* Free inodes count */ + __u32 s_first_data_block; /* First Data Block */ + __u32 s_log_block_size; /* Block size */ + __s32 s_log_frag_size; /* Fragment size */ + __u32 s_blocks_per_group; /* # Blocks per group */ + __u32 s_frags_per_group; /* # Fragments per group */ + __u32 s_inodes_per_group; /* # Inodes per group */ + __u32 s_mtime; /* Mount time */ + __u32 s_wtime; /* Write time */ + __u16 s_mnt_count; /* Mount count */ + __s16 s_max_mnt_count; /* Maximal mount count */ + __u16 s_magic; /* Magic signature */ + __u16 s_state; /* File system state */ + __u16 s_errors; /* Behaviour when detecting errors */ + __u16 s_minor_rev_level; /* minor revision level */ + __u32 s_lastcheck; /* time of last check */ + __u32 s_checkinterval; /* max. time between checks */ + __u32 s_creator_os; /* OS */ + __u32 s_rev_level; /* Revision level */ + __u16 s_def_resuid; /* Default uid for reserved blocks */ + __u16 s_def_resgid; /* Default gid for reserved blocks */ + /* + * These fields are for EXT2_DYNAMIC_REV superblocks only. + * + * Note: the difference between the compatible feature set and + * the incompatible feature set is that if there is a bit set + * in the incompatible feature set that the kernel doesn't + * know about, it should refuse to mount the filesystem. + * + * e2fsck's requirements are more strict; if it doesn't know + * about a feature in either the compatible or incompatible + * feature set, it must abort and not try to meddle with + * things it doesn't understand... + */ + __u32 s_first_ino; /* First non-reserved inode */ + __u16 s_inode_size; /* size of inode structure */ + __u16 s_block_group_nr; /* block group # of this superblock */ + __u32 s_feature_compat; /* compatible feature set */ + __u32 s_feature_incompat; /* incompatible feature set */ + __u32 s_feature_ro_compat; /* readonly-compatible feature set */ + __u8 s_uuid[16]; /* 128-bit uuid for volume */ + char s_volume_name[16]; /* volume name */ + char s_last_mounted[64]; /* directory where last mounted */ + __u32 s_algorithm_usage_bitmap; /* For compression */ + /* + * Performance hints. Directory preallocation should only + * happen if the EXT2_FEATURE_COMPAT_DIR_PREALLOC flag is on. + */ + __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/ + __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */ + __u16 s_reserved_gdt_blocks; /* Per group table for online growth */ + /* + * Journaling support valid if EXT2_FEATURE_COMPAT_HAS_JOURNAL set. + */ + __u8 s_journal_uuid[16]; /* uuid of journal superblock */ + __u32 s_journal_inum; /* inode number of journal file */ + __u32 s_journal_dev; /* device number of journal file */ + __u32 s_last_orphan; /* start of list of inodes to delete */ + __u32 s_hash_seed[4]; /* HTREE hash seed */ + __u8 s_def_hash_version; /* Default hash version to use */ + __u8 s_jnl_backup_type; /* Default type of journal backup */ + __u16 s_desc_size; /* Group desc. size: INCOMPAT_64BIT */ + __u32 s_default_mount_opts; + __u32 s_first_meta_bg; /* First metablock group */ + __u32 s_mkfs_time; /* When the filesystem was created */ + __u32 s_jnl_blocks[17]; /* Backup of the journal inode */ + __u32 s_blocks_count_hi; /* Blocks count high 32bits */ + __u32 s_r_blocks_count_hi; /* Reserved blocks count high 32 bits*/ + __u32 s_free_blocks_hi; /* Free blocks count */ + __u16 s_min_extra_isize; /* All inodes have at least # bytes */ + __u16 s_want_extra_isize; /* New inodes should reserve # bytes */ + __u32 s_flags; /* Miscellaneous flags */ + __u16 s_raid_stride; /* RAID stride */ + __u16 s_mmp_interval; /* # seconds to wait in MMP checking */ + __u64 s_mmp_block; /* Block for multi-mount protection */ + __u32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ + __u8 s_log_groups_per_flex; /* FLEX_BG group size */ + __u8 s_reserved_char_pad; + __u16 s_reserved_pad; /* Padding to next 32bits */ + __u64 s_kbytes_written; /* nr of lifetime kilobytes written */ + __u32 s_snapshot_inum; /* Inode number of active snapshot */ + __u32 s_snapshot_id; /* sequential ID of active snapshot */ + __u64 s_snapshot_r_blocks_count; /* reserved blocks for active + snapshot's future use */ + __u32 s_snapshot_list; /* inode number of the head of the on-disk snapshot list */ +#define EXT4_S_ERR_START ext4_offsetof(struct ext2_super_block, s_error_count) + __u32 s_error_count; /* number of fs errors */ + __u32 s_first_error_time; /* first time an error happened */ + __u32 s_first_error_ino; /* inode involved in first error */ + __u64 s_first_error_block; /* block involved of first error */ + __u8 s_first_error_func[32]; /* function where the error happened */ + __u32 s_first_error_line; /* line number where error happened */ + __u32 s_last_error_time; /* most recent time of an error */ + __u32 s_last_error_ino; /* inode involved in last error */ + __u32 s_last_error_line; /* line number where error happened */ + __u64 s_last_error_block; /* block involved of last error */ + __u8 s_last_error_func[32]; /* function where the error happened */ +#define EXT4_S_ERR_END ext4_offsetof(struct ext2_super_block, s_mount_opts) + __u8 s_mount_opts[64]; + __u32 s_reserved[112]; /* Padding to the end of the block */ +}; + +#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) + +/* + * Codes for operating systems + */ +#define EXT2_OS_LINUX 0 +#define EXT2_OS_HURD 1 +#define EXT2_OBSO_OS_MASIX 2 +#define EXT2_OS_FREEBSD 3 +#define EXT2_OS_LITES 4 + +/* + * Revision levels + */ +#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */ +#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */ + +#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV +#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV + +#define EXT2_GOOD_OLD_INODE_SIZE 128 + +/* + * Journal inode backup types + */ +#define EXT3_JNL_BACKUP_BLOCKS 1 + +/* + * Feature set definitions + */ + +#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \ + ( EXT2_SB(sb)->s_feature_compat & (mask) ) +#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \ + ( EXT2_SB(sb)->s_feature_ro_compat & (mask) ) +#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \ + ( EXT2_SB(sb)->s_feature_incompat & (mask) ) + +#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001 +#define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002 +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 +#define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008 +#define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010 +#define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 +#define EXT2_FEATURE_COMPAT_LAZY_BG 0x0040 +#define EXT2_FEATURE_COMPAT_EXCLUDE_INODE 0x0080 + +#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 +#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 +/* #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 not used */ +#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008 +#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010 +#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020 +#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 +#define EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT 0x0080 + +#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 +#define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */ +#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */ +#define EXT2_FEATURE_INCOMPAT_META_BG 0x0010 +#define EXT3_FEATURE_INCOMPAT_EXTENTS 0x0040 +#define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 +#define EXT4_FEATURE_INCOMPAT_MMP 0x0100 +#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200 +#define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 +#define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 + + +#define EXT2_FEATURE_COMPAT_SUPP 0 +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE) +#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ + EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ + EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \ + EXT2_FEATURE_RO_COMPAT_BTREE_DIR) + +/* + * Default values for user and/or group using reserved blocks + */ +#define EXT2_DEF_RESUID 0 +#define EXT2_DEF_RESGID 0 + +/* + * Default mount options + */ +#define EXT2_DEFM_DEBUG 0x0001 +#define EXT2_DEFM_BSDGROUPS 0x0002 +#define EXT2_DEFM_XATTR_USER 0x0004 +#define EXT2_DEFM_ACL 0x0008 +#define EXT2_DEFM_UID16 0x0010 +#define EXT3_DEFM_JMODE 0x0060 +#define EXT3_DEFM_JMODE_DATA 0x0020 +#define EXT3_DEFM_JMODE_ORDERED 0x0040 +#define EXT3_DEFM_JMODE_WBACK 0x0060 +#define EXT4_DEFM_NOBARRIER 0x0100 +#define EXT4_DEFM_BLOCK_VALIDITY 0x0200 +#define EXT4_DEFM_DISCARD 0x0400 +#define EXT4_DEFM_NODELALLOC 0x0800 + +/* + * Structure of a directory entry + */ +#define EXT2_NAME_LEN 255 + +struct ext2_dir_entry { + __u32 inode; /* Inode number */ + __u16 rec_len; /* Directory entry length */ + __u16 name_len; /* Name length */ + char name[EXT2_NAME_LEN]; /* File name */ +}; + +/* + * The new version of the directory entry. Since EXT2 structures are + * stored in intel byte order, and the name_len field could never be + * bigger than 255 chars, it's safe to reclaim the extra byte for the + * file_type field. + */ +struct ext2_dir_entry_2 { + __u32 inode; /* Inode number */ + __u16 rec_len; /* Directory entry length */ + __u8 name_len; /* Name length */ + __u8 file_type; + char name[EXT2_NAME_LEN]; /* File name */ +}; + +/* + * Ext2 directory file types. Only the low 3 bits are used. The + * other bits are reserved for now. + */ +#define EXT2_FT_UNKNOWN 0 +#define EXT2_FT_REG_FILE 1 +#define EXT2_FT_DIR 2 +#define EXT2_FT_CHRDEV 3 +#define EXT2_FT_BLKDEV 4 +#define EXT2_FT_FIFO 5 +#define EXT2_FT_SOCK 6 +#define EXT2_FT_SYMLINK 7 + +#define EXT2_FT_MAX 8 + +/* + * EXT2_DIR_PAD defines the directory entries boundaries + * + * NOTE: It must be a multiple of 4 + */ +#define EXT2_DIR_PAD 4 +#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1) +#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \ + ~EXT2_DIR_ROUND) + +/* + * This structure will be used for multiple mount protection. It will be + * written into the block number saved in the s_mmp_block field in the + * superblock. + */ +#define EXT2_MMP_MAGIC 0x004D4D50 /* ASCII for MMP */ +#define EXT2_MMP_CLEAN 0xFF4D4D50 /* Value of mmp_seq for clean unmount */ +#define EXT2_MMP_FSCK_ON 0xE24D4D50 /* Value of mmp_seq when being fscked */ + +struct mmp_struct { + __u32 mmp_magic; + __u32 mmp_seq; + __u64 mmp_time; + char mmp_nodename[64]; + char mmp_bdevname[32]; + __u16 mmp_interval; + __u16 mmp_pad1; + __u32 mmp_pad2; +}; + +/* + * Interval in number of seconds to update the MMP sequence number. + */ +#define EXT2_MMP_DEF_INTERVAL 5 + +#endif /* _LINUX_EXT2_FS_H */ diff --git a/libcustomext2fs/source/ext2_internal.c b/libcustomext2fs/source/ext2_internal.c new file mode 100644 index 00000000..d75133a7 --- /dev/null +++ b/libcustomext2fs/source/ext2_internal.c @@ -0,0 +1,1076 @@ +/** + * ext2_internal.c - Internal support routines for EXT2-based devices. + * + * Copyright (c) 2006 Michael "Chishm" Chisholm + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include "ext2_internal.h" +#include "ext2dir.h" +#include "ext2file.h" +#include "gekko_io.h" + +// EXT2 device driver devoptab +static const devoptab_t devops_ext2 = +{ + NULL, /* Device name */ + sizeof(ext2_file_state), + ext2_open_r, + ext2_close_r, + ext2_write_r, + ext2_read_r, + ext2_seek_r, + ext2_fstat_r, + ext2_stat_r, + ext2_link_r, + ext2_unlink_r, + ext2_chdir_r, + ext2_rename_r, + ext2_mkdir_r, + sizeof(ext2_dir_state), + ext2_diropen_r, + ext2_dirreset_r, + ext2_dirnext_r, + ext2_dirclose_r, + ext2_statvfs_r, + ext2_ftruncate_r, + ext2_fsync_r, + NULL /* Device data */ +}; + + +const devoptab_t *ext2GetDevOpTab() +{ + return &devops_ext2; +} + +int ext2AddDevice (const char *name, void *deviceData) +{ + const devoptab_t *devoptab_ext2 = ext2GetDevOpTab(); + devoptab_t *dev = NULL; + char *devname = NULL; + int i; + + // Sanity check + if (!name || !deviceData || !devoptab_ext2) { + errno = EINVAL; + return -1; + } + + // Allocate a devoptab for this device + dev = (devoptab_t *) mem_alloc(sizeof(devoptab_t) + strlen(name) + 1); + if (!dev) { + errno = ENOMEM; + return -1; + } + + // Use the space allocated at the end of the devoptab for storing the device name + devname = (char*)(dev + 1); + strcpy(devname, name); + + // Setup the devoptab + memcpy(dev, devoptab_ext2, sizeof(devoptab_t)); + dev->name = devname; + dev->deviceData = deviceData; + + // Add the device to the devoptab table (if there is a free slot) + for (i = 0; i < STD_MAX; i++) { + if (devoptab_list[i] == devoptab_list[0] && i != 0) { + devoptab_list[i] = dev; + return 0; + } + } + + // If we reach here then there are no free slots in the devoptab table for this device + errno = EADDRNOTAVAIL; + return -1; +} + +void ext2RemoveDevice (const char *path) +{ + const devoptab_t *devoptab = NULL; + char name[128] = {0}; + int i; + + // Get the device name from the path + strncpy(name, path, 127); + strtok(name, ":/"); + + // Find and remove the specified device from the devoptab table + // NOTE: We do this manually due to a 'bug' in RemoveDevice + // which ignores names with suffixes + for (i = 0; i < STD_MAX; i++) { + devoptab = devoptab_list[i]; + if (devoptab && devoptab->name) { + if (strcmp(name, devoptab->name) == 0) { + devoptab_list[i] = devoptab_list[0]; + mem_free((devoptab_t*)devoptab); + break; + } + } + } + + return; +} + +const devoptab_t *ext2GetDevice (const char *path) +{ + const devoptab_t *devoptab = NULL; + char name[128] = {0}; + int i; + + // Get the device name from the path + strncpy(name, path, 127); + strtok(name, ":/"); + + // Search the devoptab table for the specified device name + // NOTE: We do this manually due to a 'bug' in GetDeviceOpTab + // which ignores names with suffixes + for (i = 0; i < STD_MAX; i++) { + devoptab = devoptab_list[i]; + if (devoptab && devoptab->name) { + if (strcmp(name, devoptab->name) == 0) { + return devoptab; + } + } + } + + return NULL; +} + +ext2_vd *ext2GetVolume (const char *path) +{ + // Get the volume descriptor from the paths associated devoptab (if found) + const devoptab_t *devoptab_ext2 = ext2GetDevOpTab(); + const devoptab_t *devoptab = ext2GetDevice(path); + if (devoptab && devoptab_ext2 && (devoptab->open_r == devoptab_ext2->open_r)) + return (ext2_vd*)devoptab->deviceData; + + return NULL; +} + +int ext2InitVolume (ext2_vd *vd) +{ + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + // Reset the volumes data + memset(vd, 0, sizeof(ext2_vd)); + + // Initialise the volume lock + LWP_MutexInit(&vd->lock, false); + + return 0; +} + +void ext2DeinitVolume (ext2_vd *vd) +{ + // Sanity check + if (!vd) { + errno = ENODEV; + return; + } + + // Lock + ext2Lock(vd); + + // Close any directories which are still open (lazy programmers!) + ext2_dir_state *nextDir = vd->firstOpenDir; + while (nextDir) { + ext2CloseDir(nextDir); + nextDir = nextDir->nextOpenDir; + } + + // Close any files which are still open (lazy programmers!) + ext2_file_state *nextFile = vd->firstOpenFile; + while (nextFile) { + ext2CloseFile(nextFile); + nextFile = nextFile->nextOpenFile; + } + + // Reset open directory and file stats + vd->openDirCount = 0; + vd->openFileCount = 0; + vd->firstOpenDir = NULL; + vd->firstOpenFile = NULL; + + // Force the underlying device to sync + ext2Sync(vd, NULL); + + // Unlock + ext2Unlock(vd); + + // Deinitialise the volume lock + LWP_MutexDestroy(vd->lock); +} + +static ext2_ino_t ext2PathToInode(ext2_vd *vd, const char * path) +{ + //Sanity check + if(!vd || !path) + return 0; + + char filename[EXT2_NAME_LEN]; + errcode_t errorcode = 0; + ext2_ino_t ino = 0, parent = vd->cwd_ni && *path != '/' && *path != '\0' ? vd->cwd_ni->ino : vd->root; + const char * ptr = path; + int i; + + while(*ptr == '/') ++ptr; + + if(*ptr == '\0') + return parent; + + while(*ptr != '\0') + { + for(i = 0; *ptr != '\0' && *ptr != '/' && (i < EXT2_NAME_LEN-1); ++ptr, ++i) + filename[i] = *ptr; + + filename[i] = '\0'; + + errorcode = ext2fs_namei(vd->fs, vd->root, parent, filename, &ino); + if(errorcode != EXT2_ET_OK) + return 0; + + parent = ino; + + while(*ptr == '/') ++ptr; + + } + + + return ino; +} + +ext2_inode_t *ext2OpenEntry (ext2_vd *vd, const char *path) +{ + errcode_t errorcode = 0; + ext2_inode_t * ni = 0; + + // Sanity check + if (!vd) { + errno = ENODEV; + return NULL; + } + + // Get the actual path of the entry + path = ext2RealPath(path); + if (!path) + { + errno = EINVAL; + return NULL; + } + + ni = mem_alloc(sizeof(ext2_inode_t)); + if(!ni) + { + errno = ENOMEM; + return NULL; + } + + memset(ni, 0, sizeof(ext2_inode_t)); + + // Find the entry, taking into account our current directory (if any) + ni->ino = ext2PathToInode(vd, path); + if(ni->ino == 0) + { + mem_free(ni); + return NULL; + } + + errorcode = ext2fs_read_inode(vd->fs, ni->ino, &ni->ni); + if(errorcode) + { + mem_free(ni); + return NULL; + } + + return ni; +} + +void ext2CloseEntry(ext2_vd *vd, ext2_inode_t * ni) +{ + // Sanity check + if (!vd || !ni) { + errno = ENODEV; + return; + } + + // Lock + ext2Lock(vd); + + // Sync the entry (if it is dirty) + if(ni && ni->dirty) + ext2fs_write_inode(vd->fs, ni->ino, &ni->ni); + + // Close the entry + if(ni) + mem_free(ni); + + // Unlock + ext2Unlock(vd); + + return; +} + +static ext2_ino_t ext2CreateSymlink(ext2_vd *vd, const char *path, const char * targetdir, const char * name, mode_t type) +{ + ext2_inode_t *target_ni = NULL; + ext2_ino_t newentry = 0; + ext2_ino_t ino = 0; + + // Check if it does exist + target_ni = ext2OpenEntry(vd, targetdir); + if (!target_ni) + goto cleanup; + + int err = ext2fs_new_inode(vd->fs, target_ni->ino, type, 0, &ino); + if (err) + goto cleanup; + + do + { + err = ext2fs_link(vd->fs, target_ni->ino, name, ino, EXT2_FT_SYMLINK); + if (err == EXT2_ET_DIR_NO_SPACE) + { + err = ext2fs_expand_dir(vd->fs, target_ni->ino); + if (err) + goto cleanup; + } + } + while(err == EXT2_ET_DIR_NO_SPACE); + + ext2fs_inode_alloc_stats2(vd->fs, ino, +1, 0); + + struct ext2_inode inode; + memset(&inode, 0, sizeof(inode)); + inode.i_mode = type; + inode.i_atime = inode.i_ctime = inode.i_mtime = time(NULL); + inode.i_links_count = 1; + inode.i_size = strlen(path); //initial size of file + inode.i_uid = target_ni->ni.i_uid; + inode.i_gid = target_ni->ni.i_gid; + + if (strlen(path) <= sizeof(inode.i_block)) + { + /* fast symlink */ + strncpy((char *)&(inode.i_block[0]),path,sizeof(inode.i_blocks)); + } + else + { + /* slow symlink */ + char * buffer = mem_alloc(vd->fs->blocksize); + if (buffer) + { + blk_t blk; + strncpy(buffer, path, vd->fs->blocksize); + err = ext2fs_new_block(vd->fs, 0, 0, &blk); + if (!err) + { + inode.i_block[0] = blk; + inode.i_blocks = vd->fs->blocksize / BYTES_PER_SECTOR; + vd->fs->io->manager->write_blk(vd->fs->io, blk, 1, buffer); + ext2fs_block_alloc_stats(vd->fs, blk, +1); + } + mem_free(buffer); + } + } + + if(ext2fs_write_new_inode(vd->fs, ino, &inode) != 0) + newentry = ino; + +cleanup: + + if(target_ni) + ext2CloseEntry(vd, target_ni); + + return newentry; +} + +static ext2_ino_t ext2CreateMkDir(ext2_vd *vd, ext2_inode_t * parent, int type, const char * name) +{ + ext2_ino_t newentry = 0; + ext2_ino_t existing; + + if(ext2fs_namei(vd->fs, vd->root, parent->ino, name, &existing) == 0) + return 0; + + errcode_t err = ext2fs_new_inode(vd->fs, parent->ino, type, 0, &newentry); + if(err != EXT2_ET_OK) + return 0; + + do + { + err = ext2fs_mkdir(vd->fs, parent->ino, newentry, name); + if(err == EXT2_ET_DIR_NO_SPACE) + { + if(ext2fs_expand_dir(vd->fs, parent->ino) != 0) + return 0; + } + } + while(err == EXT2_ET_DIR_NO_SPACE); + + if(err != EXT2_ET_OK) + return 0; + + struct ext2_inode inode; + if(ext2fs_read_inode(vd->fs, newentry, &inode) == EXT2_ET_OK) + { + inode.i_mode = type; + inode.i_uid = parent->ni.i_uid; + inode.i_gid = parent->ni.i_gid; + ext2fs_write_new_inode(vd->fs, newentry, &inode); + } + + return newentry; +} + + +static ext2_ino_t ext2CreateFile(ext2_vd *vd, ext2_inode_t * parent, int type, const char * name) +{ + errcode_t retval = -1; + ext2_ino_t newfile = 0; + ext2_ino_t existing; + + if(ext2fs_namei(vd->fs, vd->root, parent->ino, name, &existing) == 0) + return 0; + + retval = ext2fs_new_inode(vd->fs, parent->ino, type, 0, &newfile); + if (retval) + return 0; + + do + { + retval = ext2fs_link(vd->fs, parent->ino, name, newfile, EXT2_FT_REG_FILE); + if (retval == EXT2_ET_DIR_NO_SPACE) + { + if (ext2fs_expand_dir(vd->fs, parent->ino) != 0) + return 0; + } + } + while(retval == EXT2_ET_DIR_NO_SPACE); + + if (retval) + return 0; + + ext2fs_inode_alloc_stats2(vd->fs, newfile, +1, 0); + + struct ext2_inode inode; + memset(&inode, 0, sizeof(inode)); + inode.i_mode = type; + inode.i_atime = inode.i_ctime = inode.i_mtime = time(0); + inode.i_links_count = 1; + inode.i_size = 0; + inode.i_uid = parent->ni.i_uid; + inode.i_gid = parent->ni.i_gid; + + if (ext2fs_write_new_inode(vd->fs, newfile, &inode) != 0) + return 0; + + return newfile; +} + +ext2_inode_t *ext2Create(ext2_vd *vd, const char *path, mode_t type, const char *target) +{ + ext2_inode_t *dir_ni = NULL, *ni = NULL; + char *dir = NULL; + char *targetdir = NULL; + char *name = NULL; + ext2_ino_t newentry = 0; + + // Sanity check + if (!vd || !vd->fs) { + errno = ENODEV; + return NULL; + } + + if(!(vd->fs->flags & EXT2_FLAG_RW)) + return NULL; + + // You cannot link between devices + if(target) { + if(vd != ext2GetVolume(target)) { + errno = EXDEV; + return NULL; + } + // Check if existing + dir_ni = ext2OpenEntry(vd, target); + if (dir_ni) { + goto cleanup; + } + ext2CloseEntry(vd, dir_ni); + dir_ni = NULL; + targetdir = strdup(target); + if (!targetdir) { + errno = EINVAL; + goto cleanup; + } + } + + // Get the actual paths of the entry + path = ext2RealPath(path); + target = ext2RealPath(target); + if (!path) { + errno = EINVAL; + return NULL; + } + + // Lock + ext2Lock(vd); + + // Clean me + // NOTE: this looks horrible right now and need a cleanup + dir = strdup(path); + if (!dir) { + errno = EINVAL; + goto cleanup; + } + + char * tmp_path = (targetdir && (type == S_IFLNK)) ? targetdir : dir; + if (strrchr(tmp_path, '/') != NULL) + { + char * ptr = strrchr(tmp_path, '/'); + name = strdup(ptr+1); + *ptr = '\0'; + } + else + name = strdup(tmp_path); + + // Open the entries parent directory + dir_ni = ext2OpenEntry(vd, dir); + if (!dir_ni) { + goto cleanup; + } + + // If not yet read, read the inode and block bitmap + if(!vd->fs->inode_map || !vd->fs->block_map) + ext2fs_read_bitmaps(vd->fs); + + // Symbolic link + if(type == S_IFLNK) + { + if (!target) { + errno = EINVAL; + goto cleanup; + } + + newentry = ext2CreateSymlink(vd, path, targetdir, name, type); + } + // Directory + else if(type == S_IFDIR) + { + newentry = ext2CreateMkDir(vd, dir_ni, LINUX_S_IFDIR | (0755 & ~vd->fs->umask), name); + } + // File + else if(type == S_IFREG) + { + newentry = ext2CreateFile(vd, dir_ni, LINUX_S_IFREG | (0755 & ~vd->fs->umask), name); + } + + // If the entry was created + if (newentry != 0) + { + // Sync the entry to disc + ext2Sync(vd, NULL); + + ni = ext2OpenEntry(vd, target ? target : path); + } + +cleanup: + + if(dir_ni) + ext2CloseEntry(vd, dir_ni); + + if(name) + mem_free(name); + + if(dir) + mem_free(dir); + + if(targetdir) + mem_free(targetdir); + + // Unlock + ext2Unlock(vd); + + return ni; +} + +/* + * Given a mode, return the ext2 file type + */ +static int ext2_file_type(unsigned int mode) +{ + if (LINUX_S_ISREG(mode)) + return EXT2_FT_REG_FILE; + + if (LINUX_S_ISDIR(mode)) + return EXT2_FT_DIR; + + if (LINUX_S_ISCHR(mode)) + return EXT2_FT_CHRDEV; + + if (LINUX_S_ISBLK(mode)) + return EXT2_FT_BLKDEV; + + if (LINUX_S_ISLNK(mode)) + return EXT2_FT_SYMLINK; + + if (LINUX_S_ISFIFO(mode)) + return EXT2_FT_FIFO; + + if (LINUX_S_ISSOCK(mode)) + return EXT2_FT_SOCK; + + return 0; +} + +int ext2Link(ext2_vd *vd, const char *old_path, const char *new_path) +{ + ext2_inode_t *dir_ni = NULL, *ni = NULL; + char *dir = NULL; + char *name = NULL; + errcode_t err = 0; + + // Sanity check + if (!vd || !vd->fs) { + errno = ENODEV; + return -1; + } + + if(!(vd->fs->flags & EXT2_FLAG_RW)) + return -1; + + // You cannot link between devices + if(vd != ext2GetVolume(new_path)) { + errno = EXDEV; + return -1; + } + + // Get the actual paths of the entry + old_path = ext2RealPath(old_path); + new_path = ext2RealPath(new_path); + if (!old_path || !new_path) { + errno = EINVAL; + return -1; + } + + // Lock + ext2Lock(vd); + + //check for existing in new path + ni = ext2OpenEntry(vd, new_path); + if (ni) { + ext2CloseEntry(vd, ni); + ni = NULL; + errno = EINVAL; + return -1; + } + + dir = strdup(new_path); + if (!dir) { + errno = EINVAL; + err = -1; + goto cleanup; + } + char * ptr = strrchr(dir, '/'); + if (ptr) + { + name = strdup(ptr+1); + *ptr = 0; + } + else + name = strdup(dir); + + // Find the entry + ni = ext2OpenEntry(vd, old_path); + if (!ni) { + errno = ENOENT; + err = -1; + goto cleanup; + } + + // Open the entries new parent directory + dir_ni = ext2OpenEntry(vd, dir); + if (!dir_ni) { + errno = ENOENT; + err = -1; + goto cleanup; + } + + do + { + // Link the entry to its new parent + err = ext2fs_link(vd->fs, dir_ni->ino, name, ni->ino, ext2_file_type(ni->ni.i_mode)); + if (err == EXT2_ET_DIR_NO_SPACE) + { + if (ext2fs_expand_dir(vd->fs, dir_ni->ino) != 0) + goto cleanup; + } + else if(err != 0) + { + errno = ENOMEM; + goto cleanup; + } + } + while(err == EXT2_ET_DIR_NO_SPACE); + + ni->ni.i_links_count++; + + // Update entry times + ext2UpdateTimes(vd, ni, EXT2_UPDATE_MCTIME); + + // Sync the entry to disc + ext2Sync(vd, ni); + +cleanup: + + if(dir_ni) + ext2CloseEntry(vd, dir_ni); + + if(ni) + ext2CloseEntry(vd, ni); + + if(dir) + mem_free(dir); + + if(name) + mem_free(name); + + // Unlock + ext2Unlock(vd); + + return err; +} + +typedef struct _rd_struct +{ + ext2_ino_t parent; + int empty; +} rd_struct; + +static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr, int blockcnt EXT2FS_ATTR((unused)), void *private EXT2FS_ATTR((unused))) +{ + blk_t block; + + block = *blocknr; + ext2fs_block_alloc_stats(fs, block, -1); + *blocknr = 0; + return 0; +} + +static int unlink_proc(ext2_ino_t dir EXT2FS_ATTR((unused)), int entry EXT2FS_ATTR((unused)), + struct ext2_dir_entry *dirent, int offset EXT2FS_ATTR((unused)), + int blocksize EXT2FS_ATTR((unused)), char *buf EXT2FS_ATTR((unused)), + void *private_data) +{ + rd_struct *rds = (rd_struct *) private_data; + + if (dirent->inode == 0) + return 0; + if (((dirent->name_len & 0xFF) == 1) && (dirent->name[0] == '.')) + return 0; + if (((dirent->name_len & 0xFF) == 2) && (dirent->name[0] == '.') && + (dirent->name[1] == '.')) { + rds->parent = dirent->inode; + return 0; + } + + rds->empty = 0; + return 0; +} + +int ext2Unlink (ext2_vd *vd, const char *path) +{ + ext2_inode_t *dir_ni = NULL, *ni = NULL; + char *dir = NULL; + char *name = NULL; + errcode_t err = -1; + + // Sanity check + if (!vd || !vd->fs) { + errno = ENODEV; + return -1; + } + + if(!(vd->fs->flags & EXT2_FLAG_RW)) + return -1; + + // Get the actual path of the entry + path = ext2RealPath(path); + if (!path) { + errno = EINVAL; + return -1; + } + + // Lock + ext2Lock(vd); + + dir = strdup(path); + if (!dir) { + errno = EINVAL; + goto cleanup; + } + char * ptr = strrchr(dir, '/'); + if (ptr) + { + name = strdup(ptr+1); + *ptr = 0; + } + else + name = dir; + + // Find the entry + ni = ext2OpenEntry(vd, path); + if (!ni) { + errno = ENOENT; + goto cleanup; + } + + // Open the entries parent directory + dir_ni = ext2OpenEntry(vd, dir); + if (!dir_ni) { + errno = ENOENT; + goto cleanup; + } + + // Directory + if(LINUX_S_ISDIR(ni->ni.i_mode)) + { + rd_struct rds; + rds.parent = 0; + rds.empty = 1; + + if (ext2fs_dir_iterate2(vd->fs, ni->ino, 0, 0, unlink_proc, &rds) != 0) + goto cleanup; + + if(!rds.empty) + goto cleanup; + + if (rds.parent) + { + struct ext2_inode inode; + if (ext2fs_read_inode(vd->fs, rds.parent, &inode) == 0) + { + if(inode.i_links_count > 1) + inode.i_links_count--; + ext2fs_write_inode(vd->fs, rds.parent, &inode); + } + } + + // set link count 0 + ni->ni.i_links_count = 0; + } + // File + else + { + ni->ni.i_links_count--; + } + + if(ni->ni.i_links_count <= 0) + { + ni->ni.i_size = 0; + ni->ni.i_size_high = 0; + ni->ni.i_links_count = 0; + ni->ni.i_dtime = (u32) time(0); + } + + ext2fs_write_inode(vd->fs, ni->ino, &ni->ni); + + // Unlink the entry from its parent + if(ext2fs_unlink(vd->fs, dir_ni->ino, name, 0, 0) != 0) + goto cleanup; + + if (ext2fs_inode_has_valid_blocks(&ni->ni)) + { + ext2fs_block_iterate(vd->fs, ni->ino, 0, NULL, release_blocks_proc, NULL); + ext2fs_inode_alloc_stats2(vd->fs, ni->ino, -1, LINUX_S_ISDIR(ni->ni.i_mode)); + } + + if(ni->ni.i_links_count == 0) + { + // It's odd that i have to do this on my own and the lib is not doing that for me + blk64_t truncate_block = ((vd->fs->blocksize - 1) >> EXT2_BLOCK_SIZE_BITS(vd->fs->super)) + 1; + ext2fs_punch(vd->fs, ni->ino, &ni->ni, 0, truncate_block, ~0ULL); + } + + // Sync the entry to disc + ext2Sync(vd, NULL); + + err = 0; + +cleanup: + + if(dir_ni) + ext2CloseEntry(vd, dir_ni); + + if(ni) + ext2CloseEntry(vd, ni); + + if(name) + mem_free(name); + + if(dir) + mem_free(dir); + + // Unlock + ext2Unlock(vd); + + return err; +} + + +int ext2Sync(ext2_vd *vd, ext2_inode_t *ni) +{ + errcode_t res = 0; + + // Sanity check + if (!vd || !vd->fs) { + errno = ENODEV; + return -1; + } + + if(!(vd->fs->flags & EXT2_FLAG_RW)) + return -1; + + // Lock + ext2Lock(vd); + + if(ni && ni->dirty) + { + ext2fs_write_inode(vd->fs, ni->ino, &ni->ni); + ni->dirty = false; + } + + // Sync the entry + res = ext2fs_flush(vd->fs); + + // Force the underlying device to sync + vd->io->manager->flush(vd->io); + + // Unlock + ext2Unlock(vd); + + return res; + +} + +int ext2Stat (ext2_vd *vd, ext2_inode_t *ni_main, struct stat *st) +{ + int res = 0; + + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + struct ext2_inode * ni = ni_main ? &ni_main->ni : 0; + + // Sanity check + if (!ni) { + errno = ENOENT; + return -1; + } + + // Short circuit cases were we don't actually have to do anything + if (!st) + return 0; + + // Lock + ext2Lock(vd); + + // Zero out the stat buffer + memset(st, 0, sizeof(struct stat)); + + if(LINUX_S_ISDIR(ni->i_mode)) + { + st->st_nlink = 1; + st->st_size = ni->i_size; + } + else + { + st->st_nlink = ni->i_links_count; + st->st_size = EXT2_I_SIZE(ni); + } + + st->st_mode = ni->i_mode; + st->st_blocks = ni->i_blocks; + st->st_blksize = vd->fs->blocksize; + + // Fill in the generic entry stats + st->st_dev = (dev_t) ((long) vd->fs); + st->st_uid = ni->i_uid | (((u32) ni->osd2.linux2.l_i_uid_high) << 16); + st->st_gid = ni->i_gid | (((u32) ni->osd2.linux2.l_i_gid_high) << 16); + st->st_ino = ni_main->ino; + st->st_atime = ni->i_atime; + st->st_ctime = ni->i_ctime; + st->st_mtime = ni->i_mtime; + + // Update entry times + ext2UpdateTimes(vd, ni_main, EXT2_UPDATE_ATIME); + + // Unlock + ext2Unlock(vd); + + return res; +} + +void ext2UpdateTimes(ext2_vd *vd, ext2_inode_t *ni, ext2_time_update_flags mask) +{ + // Sanity check + if(!ni || !mask) + return; + + if(!(vd->fs->flags & EXT2_FLAG_RW)) + return; + + u32 now = (u32) time(0); + + if(mask & EXT2_UPDATE_ATIME) + ni->ni.i_atime = now; + if(mask & EXT2_UPDATE_MTIME) + ni->ni.i_mtime = now; + if(mask & EXT2_UPDATE_CTIME) + ni->ni.i_ctime = now; + + ni->dirty = true; +} + +const char *ext2RealPath (const char *path) +{ + // Sanity check + if (!path) + return NULL; + + // Move the path pointer to the start of the actual path + if (strchr(path, ':') != NULL) { + path = strchr(path, ':')+1; + } + if (strchr(path, ':') != NULL) { + return NULL; + } + + return path; +} diff --git a/libcustomext2fs/source/ext2_internal.h b/libcustomext2fs/source/ext2_internal.h new file mode 100644 index 00000000..24dd4a52 --- /dev/null +++ b/libcustomext2fs/source/ext2_internal.h @@ -0,0 +1,102 @@ +/** + * ext2_internal.h + * + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef EXT2_INTERNAL_H_ +#define EXT2_INTERNAL_H_ + +#include +#include +#include +#include "ext2fs.h" +#include "ext2_fs.h" +#include "mem_allocate.h" + +#ifdef DEBUG_GEKKO +#define ext2_log_trace printf +#else +#define ext2_log_trace(...) +#endif + +typedef struct _ext2_inode_t +{ + struct ext2_inode ni; + ext2_ino_t ino; + bool dirty; +} ext2_inode_t; + +/** + * ext2_vd - EXT2 volume descriptor + */ +typedef struct _ext2_vd +{ + io_channel io; /* EXT device handle */ + ext2_filsys fs; /* EXT volume handle */ + mutex_t lock; /* Volume lock mutex */ + ext2_inode_t *cwd_ni; /* Current directory */ + struct _ext2_dir_state *firstOpenDir; /* The start of a FILO linked list of currently opened directories */ + struct _ext2_file_state *firstOpenFile; /* The start of a FILO linked list of currently opened files */ + u16 openDirCount; /* The total number of directories currently open in this volume */ + u16 openFileCount; /* The total number of files currently open in this volume */ + ext2_ino_t root; /* Root node */ +} ext2_vd; + +typedef enum { + EXT2_UPDATE_ATIME = 0x01, + EXT2_UPDATE_MTIME = 0x02, + EXT2_UPDATE_CTIME = 0x04, + EXT2_UPDATE_AMTIME = EXT2_UPDATE_ATIME | EXT2_UPDATE_MTIME, + EXT2_UPDATE_ACTIME = EXT2_UPDATE_ATIME | EXT2_UPDATE_CTIME, + EXT2_UPDATE_MCTIME = EXT2_UPDATE_MTIME | EXT2_UPDATE_CTIME, + EXT2_UPDATE_AMCTIME = EXT2_UPDATE_ATIME | EXT2_UPDATE_MTIME | EXT2_UPDATE_CTIME, +} ext2_time_update_flags; + +/* Lock volume */ +static inline void ext2Lock (ext2_vd *vd) +{ + LWP_MutexLock(vd->lock); +} + +/* Unlock volume */ +static inline void ext2Unlock (ext2_vd *vd) +{ + LWP_MutexUnlock(vd->lock); +} + +const char *ext2RealPath (const char *path); +int ext2InitVolume (ext2_vd *vd); +void ext2DeinitVolume (ext2_vd *vd); +ext2_vd *ext2GetVolume (const char *path); + +int ext2AddDevice (const char *name, void *deviceData); +void ext2RemoveDevice (const char *path); +const devoptab_t *ext2GetDevice (const char *path); + +ext2_inode_t *ext2OpenEntry (ext2_vd *vd, const char *path); +void ext2CloseEntry (ext2_vd *vd, ext2_inode_t * ni); +int ext2Stat (ext2_vd *vd, ext2_inode_t * ni, struct stat *st); +int ext2Sync (ext2_vd *vd, ext2_inode_t * ni); + +ext2_inode_t *ext2Create (ext2_vd *vd, const char *path, mode_t type, const char *target); +int ext2Link (ext2_vd *vd, const char *old_path, const char *new_path); +int ext2Unlink (ext2_vd *vd, const char *path); + +void ext2UpdateTimes(ext2_vd *vd, ext2_inode_t *ni, ext2_time_update_flags mask); + +#endif diff --git a/libcustomext2fs/source/ext2_io.h b/libcustomext2fs/source/ext2_io.h new file mode 100644 index 00000000..10be1100 --- /dev/null +++ b/libcustomext2fs/source/ext2_io.h @@ -0,0 +1,141 @@ +/* + * io.h --- the I/O manager abstraction + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#ifndef _EXT2FS_EXT2_IO_H +#define _EXT2FS_EXT2_IO_H + +#include "ext2fs.h" + +/* + * ext2_loff_t is defined here since unix_io.c needs it. + */ +typedef long long ext2_loff_t; + +/* llseek.c */ +ext2_loff_t ext2fs_llseek (int, ext2_loff_t, int); + +typedef struct struct_io_manager *io_manager; +typedef struct struct_io_channel *io_channel; +typedef struct struct_io_stats *io_stats; + +#define CHANNEL_FLAGS_WRITETHROUGH 0x01 +#define CHANNEL_FLAGS_DISCARD_ZEROES 0x02 + +#define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES) + +struct struct_io_channel { + errcode_t magic; + io_manager manager; + char *name; + int block_size; + errcode_t (*read_error)(io_channel channel, + unsigned long block, + int count, + void *data, + size_t size, + int actual_bytes_read, + errcode_t error); + errcode_t (*write_error)(io_channel channel, + unsigned long block, + int count, + const void *data, + size_t size, + int actual_bytes_written, + errcode_t error); + int refcount; + int flags; + long reserved[14]; + void *private_data; + void *app_data; +}; + +struct struct_io_stats { + int num_fields; + int reserved; + unsigned long long bytes_read; + unsigned long long bytes_written; +}; + +struct struct_io_manager { + errcode_t magic; + const char *name; + errcode_t (*open)(const char *name, int flags, io_channel *channel); + errcode_t (*close)(io_channel channel); + errcode_t (*set_blksize)(io_channel channel, int blksize); + errcode_t (*read_blk)(io_channel channel, unsigned long block, + int count, void *data); + errcode_t (*write_blk)(io_channel channel, unsigned long block, + int count, const void *data); + errcode_t (*flush)(io_channel channel); + errcode_t (*write_byte)(io_channel channel, unsigned long offset, + int count, const void *data); + errcode_t (*set_option)(io_channel channel, const char *option, + const char *arg); + errcode_t (*get_stats)(io_channel channel, io_stats *io_stats); + errcode_t (*read_blk64)(io_channel channel, unsigned long long block, + int count, void *data); + errcode_t (*write_blk64)(io_channel channel, unsigned long long block, + int count, const void *data); + errcode_t (*discard)(io_channel channel, unsigned long long block, + unsigned long long count); + long reserved[16]; +}; + +#define IO_FLAG_RW 0x0001 +#define IO_FLAG_EXCLUSIVE 0x0002 +#define IO_FLAG_DIRECT_IO 0x0004 + +/* + * Convenience functions.... + */ +#define io_channel_close(c) ((c)->manager->close((c))) +#define io_channel_set_blksize(c,s) ((c)->manager->set_blksize((c),s)) +#define io_channel_read_blk(c,b,n,d) ((c)->manager->read_blk((c),b,n,d)) +#define io_channel_write_blk(c,b,n,d) ((c)->manager->write_blk((c),b,n,d)) +#define io_channel_flush(c) ((c)->manager->flush((c))) +#define io_channel_bumpcount(c) ((c)->refcount++) + +/* io_manager.c */ +extern errcode_t io_channel_set_options(io_channel channel, + const char *options); +extern errcode_t io_channel_write_byte(io_channel channel, + unsigned long offset, + int count, const void *data); +extern errcode_t io_channel_read_blk64(io_channel channel, + unsigned long long block, + int count, void *data); +extern errcode_t io_channel_write_blk64(io_channel channel, + unsigned long long block, + int count, const void *data); + +/* unix_io.c */ +extern io_manager unix_io_manager; + +/* undo_io.c */ +extern io_manager undo_io_manager; +extern errcode_t set_undo_io_backing_manager(io_manager manager); +extern errcode_t set_undo_io_backup_file(char *file_name); + +/* test_io.c */ +extern io_manager test_io_manager, test_io_backing_manager; +extern void (*test_io_cb_read_blk) + (unsigned long block, int count, errcode_t err); +extern void (*test_io_cb_write_blk) + (unsigned long block, int count, errcode_t err); +extern void (*test_io_cb_read_blk64) + (unsigned long long block, int count, errcode_t err); +extern void (*test_io_cb_write_blk64) + (unsigned long long block, int count, errcode_t err); +extern void (*test_io_cb_set_blksize) + (int blksize, errcode_t err); + +#endif /* _EXT2FS_EXT2_IO_H */ + diff --git a/libcustomext2fs/source/ext2_types.h b/libcustomext2fs/source/ext2_types.h new file mode 100644 index 00000000..5f5f7a57 --- /dev/null +++ b/libcustomext2fs/source/ext2_types.h @@ -0,0 +1,18 @@ +/* + * If linux/types.h is already been included, assume it has defined + * everything we need. (cross fingers) Other header files may have + * also defined the types that we need. + */ +#ifndef _EXT2_TYPES_H +#define _EXT2_TYPES_H + +typedef unsigned char __u8; +typedef signed char __s8; +typedef unsigned short __u16; +typedef short __s16; +typedef unsigned int __u32; +typedef int __s32; +typedef unsigned long long __u64; +typedef signed long long __s64; + +#endif /* _EXT2_TYPES_H */ diff --git a/libcustomext2fs/source/ext2dir.c b/libcustomext2fs/source/ext2dir.c new file mode 100644 index 00000000..ee7ce3c3 --- /dev/null +++ b/libcustomext2fs/source/ext2dir.c @@ -0,0 +1,657 @@ +/** + * ext2_dir.c - devoptab directory routines for EXT2-based devices. + * + * Copyright (c) 2006 Michael "Chishm" Chisholm + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "ext2_internal.h" +#include "ext2dir.h" +#include + +#define STATE(x) ((ext2_dir_state*)(x)->dirStruct) + +void ext2CloseDir (ext2_dir_state *dir) +{ + // Sanity check + if (!dir || !dir->vd) + return; + + // Free the directory entries (if any) + while (dir->first) { + ext2_dir_entry *next = dir->first->next; + mem_free(dir->first->name); + mem_free(dir->first); + dir->first = next; + } + + // Close the directory (if open) + if (dir->ni) + ext2CloseEntry(dir->vd, dir->ni); + + // Reset the directory state + dir->ni = NULL; + dir->first = NULL; + dir->current = NULL; + + return; +} + +int ext2_stat_r (struct _reent *r, const char *path, struct stat *st) +{ + // Short circuit cases were we don't actually have to do anything + if (!st || !path) + return 0; + + ext2_log_trace("path %s, st %p\n", path, st); + + ext2_vd *vd = NULL; + ext2_inode_t *ni = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(path); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + if(strcmp(path, ".") == 0 || strcmp(path, "..") == 0) + { + memset(st, 0, sizeof(struct stat)); + st->st_mode = S_IFDIR; + return 0; + } + + // Lock + ext2Lock(vd); + + // Find the entry + ni = ext2OpenEntry(vd, path); + if (!ni) { + r->_errno = errno; + ext2Unlock(vd); + return -1; + } + + // Get the entry stats + int ret = ext2Stat(vd, ni, st); + if (ret) + r->_errno = errno; + + // Close the entry + ext2CloseEntry(vd, ni); + + ext2Unlock(vd); + + return 0; +} + +int ext2_link_r (struct _reent *r, const char *existing, const char *newLink) +{ + ext2_log_trace("existing %s, newLink %s\n", existing, newLink); + + ext2_vd *vd = NULL; + ext2_inode_t *ni = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(existing); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ext2Lock(vd); + + // Create a symbolic link between the two paths + ni = ext2Create(vd, existing, S_IFLNK, newLink); + if (!ni) { + ext2Unlock(vd); + r->_errno = errno; + return -1; + } + + // Close the symbolic link + ext2CloseEntry(vd, ni); + + // Unlock + ext2Unlock(vd); + + return 0; +} + +int ext2_unlink_r (struct _reent *r, const char *name) +{ + ext2_log_trace("name %s\n", name); + + ext2_vd *vd = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(name); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Unlink the entry + int ret = ext2Unlink(vd, name); + if (ret) + r->_errno = errno; + + return ret; +} + +int ext2_chdir_r (struct _reent *r, const char *name) +{ + ext2_log_trace("name %s\n", name); + + ext2_vd *vd = NULL; + ext2_inode_t *ni = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(name); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ext2Lock(vd); + + // Find the directory + ni = ext2OpenEntry(vd, name); + if (!ni) { + ext2Unlock(vd); + r->_errno = ENOENT; + return -1; + } + + // Ensure that this directory is indeed a directory + if (!LINUX_S_ISDIR(ni->ni.i_mode)) { + ext2CloseEntry(vd, ni); + ext2Unlock(vd); + r->_errno = ENOTDIR; + return -1; + } + + // Close the old current directory (if any) + if (vd->cwd_ni) + ext2CloseEntry(vd, vd->cwd_ni); + + // Set the new current directory + vd->cwd_ni = ni; + + // Unlock + ext2Unlock(vd); + + return 0; +} + +int ext2_rename_r (struct _reent *r, const char *oldName, const char *newName) +{ + ext2_log_trace("oldName %s, newName %s\n", oldName, newName); + + ext2_vd *vd = NULL; + ext2_inode_t *ni = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(oldName); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ext2Lock(vd); + + // You cannot rename between devices + if(vd != ext2GetVolume(newName)) { + ext2Unlock(vd); + r->_errno = EXDEV; + return -1; + } + + // Check that there is no existing entry with the new name + ni = ext2OpenEntry(vd, newName); + if (ni) { + ext2CloseEntry(vd, ni); + ext2Unlock(vd); + r->_errno = EEXIST; + return -1; + } + + // Link the old entry with the new one + if (ext2Link(vd, oldName, newName)) { + ext2Unlock(vd); + return -1; + } + + // Unlink the old entry + if (ext2Unlink(vd, oldName)) { + if (ext2Unlink(vd, newName)) { + ext2Unlock(vd); + return -1; + } + ext2Unlock(vd); + return -1; + } + + // Unlock + ext2Unlock(vd); + + return 0; +} + +int ext2_mkdir_r (struct _reent *r, const char *path, int mode) +{ + ext2_log_trace("path %s, mode %i\n", path, mode); + + ext2_vd *vd = NULL; + ext2_inode_t *ni = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(path); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ext2Lock(vd); + + // Create the directory + ni = ext2Create(vd, path, S_IFDIR, NULL); + if (!ni) { + ext2Unlock(vd); + r->_errno = errno; + return -1; + } + + // Close the directory + ext2CloseEntry(vd, ni); + + // Unlock + ext2Unlock(vd); + + return 0; +} + +int ext2_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) +{ + ext2_log_trace("path %s, buf %p\n", path, buf); + + ext2_vd *vd = NULL; + + // Get the volume descriptor for this path + vd = ext2GetVolume(path); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Short circuit cases were we don't actually have to do anything + if (!buf) + return 0; + + // Lock + ext2Lock(vd); + + // Zero out the stat buffer + memset(buf, 0, sizeof(struct statvfs)); + + // File system block size + switch(vd->fs->super->s_log_block_size) + { + case 1: + buf->f_bsize = 2048; + break; + case 2: + buf->f_bsize = 4096; + break; + case 3: + buf->f_bsize = 8192; + break; + default: + case 0: + buf->f_bsize = 1024; + break; + } + + // Fundamental file system block size + buf->f_frsize = buf->f_bsize; + + // Total number of blocks on file system in units of f_frsize + buf->f_blocks = vd->fs->super->s_blocks_count | (((u64) vd->fs->super->s_blocks_count_hi) << 32); + + // Free blocks available for all and for non-privileged processes + buf->f_bfree = vd->fs->super->s_free_blocks_count | (((u64) vd->fs->super->s_free_blocks_hi) << 32); + + // Number of inodes at this point in time + buf->f_files = vd->fs->super->s_inodes_count; + + // Free inodes available for all and for non-privileged processes + buf->f_ffree = vd->fs->super->s_free_inodes_count; + + // File system id + buf->f_fsid = vd->fs->super->s_magic; + + // Bit mask of f_flag values. + buf->f_flag = vd->fs->super->s_flags; + + // Maximum length of filenames + buf->f_namemax = EXT2_NAME_LEN; + + // Unlock + ext2Unlock(vd); + + return 0; +} + +/** + * PRIVATE: Callback for directory walking + */ +static int DirIterateCallback(struct ext2_dir_entry *dirent, int offset, int blocksize, char *buf, void *dirState) +{ + // Sanity check + if(!dirent) + { + errno = EINVAL; + return -1; + } + + ext2_dir_state* dir = STATE(((DIR_ITER *) dirState)); + + // Sanity check + if (!dir || !dir->vd) { + errno = EINVAL; + return -1; + } + + //skip ".." on root directory + if(dir->ni->ino == dir->vd->root && strcmp(dirent->name, "..") == 0) + { + return EXT2_ET_OK; + } + + // Allocate a new directory entry + ext2_dir_entry *entry = (ext2_dir_entry *) mem_alloc(sizeof(ext2_dir_entry)); + if (!entry) + { + errno = ENOMEM; + return -1; + } + + memset(entry, 0, sizeof(ext2_dir_entry)); + + int stringlen = dirent->name_len & 0xFF; + + entry->name = mem_alloc(stringlen+1); + if(!entry->name) + { + mem_free(entry); + errno = ENOMEM; + return -1; + } + + // The null termination is not necessarily there in the fs, we gotta do it + int i; + for(i = 0; i < stringlen; ++i) + entry->name[i] = dirent->name[i]; + entry->name[i] = '\0'; + + // Link the entry to the directory + if (!dir->first) { + dir->first = entry; + dir->length = dirent->rec_len; + } else { + ext2_dir_entry *last = dir->first; + while (last->next) last = last->next; + last->next = entry; + } + + return EXT2_ET_OK; +} + +DIR_ITER *ext2_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path) +{ + ext2_log_trace("dirState %p, path %s\n", dirState, path); + + if(!dirState) + { + r->_errno = EINVAL; + return NULL; + } + + ext2_dir_state* dir = STATE(dirState); + + if(!dir) + { + r->_errno = EINVAL; + return NULL; + } + + // Get the volume descriptor for this path + dir->vd = ext2GetVolume(path); + if (!dir->vd) { + r->_errno = ENODEV; + return NULL; + } + + // Lock + ext2Lock(dir->vd); + + // Find the directory + dir->ni = ext2OpenEntry(dir->vd, path); + if (!dir->ni) { + ext2Unlock(dir->vd); + r->_errno = ENOENT; + return NULL; + } + + // Ensure that this directory is indeed a directory + if (!LINUX_S_ISDIR(dir->ni->ni.i_mode)) { + ext2CloseEntry(dir->vd, dir->ni); + ext2Unlock(dir->vd); + r->_errno = ENOTDIR; + return NULL; + } + + // Read the directory + dir->first = dir->current = NULL; + if (ext2fs_dir_iterate(dir->vd->fs, dir->ni->ino, 0, 0, DirIterateCallback, dirState) != EXT2_ET_OK) { + ext2CloseDir(dir); + ext2Unlock(dir->vd); + r->_errno = errno; + return NULL; + } + + // Move to the first entry in the directory + dir->current = dir->first; + + // Update directory times + ext2UpdateTimes(dir->vd, dir->ni, EXT2_UPDATE_ATIME); + + // Insert the directory into the double-linked FILO list of open directories + if (dir->vd->firstOpenDir) { + dir->nextOpenDir = dir->vd->firstOpenDir; + dir->vd->firstOpenDir->prevOpenDir = dir; + } else { + dir->nextOpenDir = NULL; + } + dir->prevOpenDir = NULL; + dir->vd->cwd_ni = dir->ni; + dir->vd->firstOpenDir = dir; + dir->vd->openDirCount++; + + // Unlock + ext2Unlock(dir->vd); + + return dirState; +} + +int ext2_dirreset_r (struct _reent *r, DIR_ITER *dirState) +{ + ext2_log_trace("dirState %p\n", dirState); + + if(!dirState) + { + r->_errno = EINVAL; + return -1; + } + + ext2_dir_state* dir = STATE(dirState); + + // Sanity check + if (!dir || !dir->vd || !dir->ni) { + r->_errno = EBADF; + return -1; + } + + // Lock + ext2Lock(dir->vd); + + // Move to the first entry in the directory + dir->current = dir->first; + + // Update directory times + ext2UpdateTimes(dir->vd, dir->ni, EXT2_UPDATE_ATIME); + + // Unlock + ext2Unlock(dir->vd); + + return 0; +} + +int ext2_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) +{ + ext2_log_trace("dirState %p, filename %p, filestat %p\n", dirState, filename, filestat); + + if(!dirState) + { + r->_errno = EINVAL; + return -1; + } + + ext2_dir_state* dir = STATE(dirState); + ext2_inode_t *ni = NULL; + + // Sanity check + if (!dir || !dir->vd || !dir->ni) { + r->_errno = EBADF; + return -1; + } + + // Lock + ext2Lock(dir->vd); + + // Check that there is a entry waiting to be fetched + if (!dir->current) { + ext2Unlock(dir->vd); + r->_errno = ENOENT; + return -1; + } + + // Fetch the current entry + strcpy(filename, dir->current->name); + if(filestat != NULL) + { + if(strcmp(dir->current->name, ".") == 0 || strcmp(dir->current->name, "..") == 0) + { + memset(filestat, 0, sizeof(struct stat)); + filestat->st_mode = S_IFDIR; + } + else + { + ni = ext2OpenEntry(dir->vd, dir->current->name); + if (ni) { + ext2Stat(dir->vd, ni, filestat); + ext2CloseEntry(dir->vd, ni); + } + } + } + + // Move to the next entry in the directory + dir->current = dir->current->next; + + // Update directory times + ext2UpdateTimes(dir->vd, dir->ni, EXT2_UPDATE_ATIME); + + // Unlock + ext2Unlock(dir->vd); + + return 0; +} + +int ext2_dirclose_r (struct _reent *r, DIR_ITER *dirState) +{ + ext2_log_trace("dirState %p\n", dirState); + + if(!dirState) + { + r->_errno = EINVAL; + return -1; + } + + ext2_dir_state* dir = STATE(dirState); + + // Sanity check + if (!dir || !dir->vd) { + r->_errno = EBADF; + return -1; + } + + // Lock + ext2Lock(dir->vd); + + // Close the directory + ext2CloseDir(dir); + + // Remove the directory from the double-linked FILO list of open directories + dir->vd->openDirCount--; + if (dir->nextOpenDir) + dir->nextOpenDir->prevOpenDir = dir->prevOpenDir; + if (dir->prevOpenDir) + dir->prevOpenDir->nextOpenDir = dir->nextOpenDir; + else + dir->vd->firstOpenDir = dir->nextOpenDir; + + // Unlock + ext2Unlock(dir->vd); + + return 0; +} diff --git a/libcustomext2fs/source/ext2dir.h b/libcustomext2fs/source/ext2dir.h new file mode 100644 index 00000000..26081bbf --- /dev/null +++ b/libcustomext2fs/source/ext2dir.h @@ -0,0 +1,69 @@ +/** + * ext2_dir.h - devoptab directory routines for EXT2-based devices. + * + * Copyright (c) 2006 Michael "Chishm" Chisholm + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _EXT2DIR_H +#define _EXT2DIR_H + +#include +#include "ext2_internal.h" + +/** + * ext2_dir_entry - Directory entry + */ +typedef struct _ext2_dir_entry { + char *name; + struct _ext2_dir_entry *next; +} ext2_dir_entry; + +/** + * ext2_dir_state - Directory state + */ +typedef struct _ext2_dir_state { + ext2_vd *vd; /* Volume this directory belongs to */ + ext2_inode_t *ni; /* Directory descriptor */ + unsigned short length; /* Directory length */ + ext2_dir_entry *first; /* The first entry in the directory */ + ext2_dir_entry *current; /* The current entry in the directory */ + struct _ext2_dir_state *prevOpenDir; /* The previous entry in a double-linked FILO list of open directories */ + struct _ext2_dir_state *nextOpenDir; /* The next entry in a double-linked FILO list of open directories */ +} ext2_dir_state; + +/* Directory state routines */ +void ext2CloseDir (ext2_dir_state *file); + +/* Gekko devoptab directory routines for EXT2-based devices */ +extern int ext2_stat_r (struct _reent *r, const char *path, struct stat *st); +extern int ext2_link_r (struct _reent *r, const char *existing, const char *newLink); +extern int ext2_unlink_r (struct _reent *r, const char *name); +extern int ext2_chdir_r (struct _reent *r, const char *name); +extern int ext2_rename_r (struct _reent *r, const char *oldName, const char *newName); +extern int ext2_mkdir_r (struct _reent *r, const char *path, int mode); +extern int ext2_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf); + +/* Gekko devoptab directory walking routines for EXT2-based devices */ +extern DIR_ITER *ext2_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path); +extern int ext2_dirreset_r (struct _reent *r, DIR_ITER *dirState); +extern int ext2_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); +extern int ext2_dirclose_r (struct _reent *r, DIR_ITER *dirState); + +#endif /* _EXT2DIR_H */ + diff --git a/libcustomext2fs/source/ext2file.c b/libcustomext2fs/source/ext2file.c new file mode 100644 index 00000000..6647466f --- /dev/null +++ b/libcustomext2fs/source/ext2file.c @@ -0,0 +1,413 @@ +/** + * ext2file.c - devoptab file routines for EXT2-based devices. + * + * Copyright (c) 2006 Michael "Chishm" Chisholm + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include + +#include "ext2_internal.h" +#include "ext2file.h" + +#define STATE(x) ((ext2_file_state*)x) + +void ext2CloseFile (ext2_file_state *file) +{ + // Sanity check + if (!file || !file->vd) + return; + + ext2fs_file_close(file->fd); + + // Sync the file (and its attributes) to disc + if(file->write) + { + // Read in node changes before writing them + ext2fs_read_inode(file->vd->fs, file->ni->ino, &file->ni->ni); + ext2UpdateTimes(file->vd, file->ni, EXT2_UPDATE_ACTIME); + } + + if (file->read) + ext2UpdateTimes(file->vd, file->ni, EXT2_UPDATE_ATIME); + + ext2Sync(file->vd, file->ni); + + // Close the file (if open) + if (file->ni) + ext2CloseEntry(file->vd, file->ni); + + // Reset the file state + file->ni = NULL; + file->fd = NULL; + file->flags = 0; + file->read = false; + file->write = false; + file->append = false; + + return; +} + +int ext2_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) +{ + ext2_log_trace("fileStruct %p, path %s, flags %i, mode %i\n", fileStruct, path, flags, mode); + + ext2_file_state* file = STATE(fileStruct); + + // Get the volume descriptor for this path + file->vd = ext2GetVolume(path); + if (!file->vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ext2Lock(file->vd); + + // Determine which mode the file is opened for + file->flags = flags; + if ((flags & 0x03) == O_RDONLY) { + file->read = true; + file->write = false; + file->append = false; + } else if ((flags & 0x03) == O_WRONLY) { + file->read = false; + file->write = true; + file->append = (flags & O_APPEND); + } else if ((flags & 0x03) == O_RDWR) { + file->read = true; + file->write = true; + file->append = (flags & O_APPEND); + } else { + r->_errno = EACCES; + ext2Unlock(file->vd); + return -1; + } + + // Try and find the file and (if found) ensure that it is not a directory + file->ni = ext2OpenEntry(file->vd, path); + if (file->ni && LINUX_S_ISDIR(file->ni->ni.i_mode)) + { + ext2CloseEntry(file->vd, file->ni); + ext2Unlock(file->vd); + r->_errno = EISDIR; + return -1; + } + + // Are we creating this file? + if ((flags & O_CREAT) && !file->ni) + // Create the file + file->ni = ext2Create(file->vd, path, S_IFREG, NULL); + + // Sanity check, the file should be open by now + if (!file->ni) { + ext2Unlock(file->vd); + r->_errno = ENOENT; + return -1; + } + + // Make sure we aren't trying to write to a read-only file + if (!(file->vd->fs->flags & EXT2_FLAG_RW) && file->write) + { + ext2CloseEntry(file->vd, file->ni); + ext2Unlock(file->vd); + r->_errno = EROFS; + return -1; + } + + errcode_t err = ext2fs_file_open2(file->vd->fs, file->ni->ino, &file->ni->ni, + file->write ? EXT2_FLAG_RW : 0, &file->fd); + if(err != 0) + { + ext2CloseEntry(file->vd, file->ni); + ext2Unlock(file->vd); + r->_errno = ENOENT; + return -1; + } + + + // Truncate the file if requested + if ((flags & O_TRUNC) && file->write) { + if (ext2fs_file_set_size2(file->fd, 0) != 0) { + ext2CloseEntry(file->vd, file->ni); + ext2Unlock(file->vd); + r->_errno = errno; + return -1; + } + file->ni->ni.i_size = file->ni->ni.i_size_high = 0; + } + + // Set the files current position + ext2fs_file_llseek(file->fd, file->append ? EXT2_I_SIZE(&file->ni->ni) : 0, SEEK_SET, 0); + + ext2_log_trace("file->len %lld\n", EXT2_I_SIZE(&file->ni->ni)); + + // Update file times + ext2UpdateTimes(file->vd, file->ni, EXT2_UPDATE_ATIME); + + // Insert the file into the double-linked FILO list of open files + if (file->vd->firstOpenFile) { + file->nextOpenFile = file->vd->firstOpenFile; + file->vd->firstOpenFile->prevOpenFile = file; + } else { + file->nextOpenFile = NULL; + } + file->prevOpenFile = NULL; + file->vd->firstOpenFile = file; + file->vd->openFileCount++; + + // Sync access time + ext2Sync(file->vd, file->ni); + + // Unlock + ext2Unlock(file->vd); + + return (int)fileStruct; +} + +int ext2_close_r (struct _reent *r, int fd) +{ + ext2_log_trace("fd %p\n", (void *) fd); + + ext2_file_state* file = STATE(fd); + + // Sanity check + if (!file || !file->vd) { + r->_errno = EBADF; + return -1; + } + + // Lock + ext2Lock(file->vd); + + // Close the file + ext2CloseFile(file); + + // Remove the file from the double-linked FILO list of open files + file->vd->openFileCount--; + if (file->nextOpenFile) + file->nextOpenFile->prevOpenFile = file->prevOpenFile; + if (file->prevOpenFile) + file->prevOpenFile->nextOpenFile = file->nextOpenFile; + else + file->vd->firstOpenFile = file->nextOpenFile; + + // Unlock + ext2Unlock(file->vd); + + return 0; +} + +ssize_t ext2_write_r (struct _reent *r, int fd, const char *ptr, size_t len) +{ + ext2_log_trace("fd %p, ptr %p, len %i\n", (void *) fd, ptr, len); + + ext2_file_state* file = STATE(fd); + + // Sanity check + if (!file || !file->vd || !file->fd) { + r->_errno = EINVAL; + return -1; + } + + // Short circuit cases where we don't actually have to do anything + if (!ptr || len <= 0) { + return 0; + } + + // Check that we are allowed to write to this file + if (!file->write) { + r->_errno = EACCES; + return -1; + } + + // Lock + ext2Lock(file->vd); + + u32 writen = 0; + + // Write to the files data atrribute + errcode_t err = ext2fs_file_write(file->fd, ptr, len, &writen); + if (writen <= 0 || err) { + ext2Unlock(file->vd); + r->_errno = errno; + return (err ? err : -1); + } + + // Unlock + ext2Unlock(file->vd); + + return (writen == 0 ? -1 : writen); +} + +ssize_t ext2_read_r (struct _reent *r, int fd, char *ptr, size_t len) +{ + ext2_log_trace("fd %p, ptr %p, len %i\n", (void *) fd, ptr, len); + + ext2_file_state* file = STATE(fd); + + // Sanity check + if (!file || !file->vd || !file->fd) { + r->_errno = EINVAL; + return -1; + } + + // Short circuit cases where we don't actually have to do anything + if (!ptr || len <= 0) { + return 0; + } + + // Lock + ext2Lock(file->vd); + + // Check that we are allowed to read from this file + if (!file->read) { + ext2Unlock(file->vd); + r->_errno = EACCES; + return -1; + } + + u32 read = 0; + errcode_t err = 0; + + // Read from the files data attribute + err = ext2fs_file_read(file->fd, ptr, len, &read); + if (err || read <= 0 || read > len) { + ext2Unlock(file->vd); + r->_errno = errno; + return err ? err : -1; + } + + // Unlock + ext2Unlock(file->vd); + + return (read == 0) ? -1 : read; +} + +off_t ext2_seek_r (struct _reent *r, int fd, off_t pos, int dir) +{ + ext2_log_trace("fd %p, pos %lli, dir %i\n", (void *) fd, pos, dir); + + ext2_file_state* file = STATE(fd); + + // Sanity check + if (!file || !file->fd) { + r->_errno = EINVAL; + return -1; + } + + u64 pos_loaded = 0; + + ext2fs_file_llseek(file->fd, pos, dir, &pos_loaded); + + return (off_t) pos_loaded; +} + +int ext2_fstat_r (struct _reent *r, int fd, struct stat *st) +{ + ext2_log_trace("fd %p\n", (void *) fd); + + ext2_file_state* file = STATE(fd); + int ret = 0; + + // Sanity check + if (!file || !file->vd || !file->ni || !file->fd) { + 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 = ext2Stat(file->vd, file->ni, st); + if (ret) + r->_errno = errno; + + return ret; +} + +int ext2_ftruncate_r (struct _reent *r, int fd, off_t len) +{ + ext2_log_trace("fd %p, len %Li\n", (void *) fd, len); + + ext2_file_state* file = STATE(fd); + errcode_t err = 0; + + // Sanity check + if (!file || !file->vd || !file->ni || !file->fd) { + r->_errno = EINVAL; + return -1; + } + + // Lock + ext2Lock(file->vd); + + // Check that we are allowed to write to this file + if (!file->write) { + ext2Unlock(file->vd); + r->_errno = EACCES; + return -1; + } + + err = ext2fs_file_set_size2(file->fd, len); + + // Sync the file (and its attributes) to disc + if(!err) + ext2Sync(file->vd, file->ni); + + // update times + ext2UpdateTimes(file->vd, file->ni, EXT2_UPDATE_AMTIME); + + // Unlock + ext2Unlock(file->vd); + + return err; +} + +int ext2_fsync_r (struct _reent *r, int fd) +{ + ext2_log_trace("fd %p\n", (void *) fd); + + ext2_file_state* file = STATE(fd); + int ret = 0; + + // Sanity check + if (!file || !file->fd) { + r->_errno = EINVAL; + return -1; + } + + // Lock + ext2Lock(file->vd); + + // Sync the file (and its attributes) to disc + ret = ext2fs_file_flush(file->fd); + if (ret) + r->_errno = ret; + + // Unlock + ext2Unlock(file->vd); + + return ret; +} diff --git a/libcustomext2fs/source/ext2file.h b/libcustomext2fs/source/ext2file.h new file mode 100644 index 00000000..249ba52a --- /dev/null +++ b/libcustomext2fs/source/ext2file.h @@ -0,0 +1,60 @@ +/** + * ext2file.c - devoptab file routines for EXT2-based devices. + * + * Copyright (c) 2006 Michael "Chishm" Chisholm + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _EXT2FILE_H +#define _EXT2FILE_H + +#include +#include "ext2_internal.h" + +/** + * ext2_file_state - File state + */ +typedef struct _ext2_file_state { + ext2_vd *vd; /* Volume this file belongs to */ + ext2_inode_t *ni; /* File inode */ + ext2_file_t fd; /* File descriptor */ + int flags; /* Opening flags */ + bool read; /* True if allowed to read from file */ + bool write; /* True if allowed to write to file */ + bool append; /* True if allowed to append to file */ +// bool compressed; /* True if file data is compressed */ +// bool encrypted; /* True if file data is encryted */ + struct _ext2_file_state *prevOpenFile; /* The previous entry in a double-linked FILO list of open files */ + struct _ext2_file_state *nextOpenFile; /* The next entry in a double-linked FILO list of open files */ +} ext2_file_state; + +/* File state routines */ +void ext2CloseFile (ext2_file_state *file); + +/* Gekko devoptab file routines for EXT2-based devices */ +extern int ext2_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode); +extern int ext2_close_r (struct _reent *r, int fd); +extern ssize_t ext2_write_r (struct _reent *r, int fd, const char *ptr, size_t len); +extern ssize_t ext2_read_r (struct _reent *r, int fd, char *ptr, size_t len); +extern off_t ext2_seek_r (struct _reent *r, int fd, off_t pos, int dir); +extern int ext2_fstat_r (struct _reent *r, int fd, struct stat *st); +extern int ext2_ftruncate_r (struct _reent *r, int fd, off_t len); +extern int ext2_fsync_r (struct _reent *r, int fd); + +#endif /* _EXT2FILE_H */ + diff --git a/libcustomext2fs/source/ext2fs.h b/libcustomext2fs/source/ext2fs.h new file mode 100644 index 00000000..ce3b88de --- /dev/null +++ b/libcustomext2fs/source/ext2fs.h @@ -0,0 +1,1572 @@ +/* + * ext2fs.h --- ext2fs + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#ifndef _EXT2FS_EXT2FS_H +#define _EXT2FS_EXT2FS_H + +#ifdef __GNUC__ +#define EXT2FS_ATTR(x) __attribute__(x) +#else +#define EXT2FS_ATTR(x) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Non-GNU C compilers won't necessarily understand inline + */ +#if (!defined(__GNUC__) && !defined(__WATCOMC__)) +#define NO_INLINE_FUNCS +#endif + +/* + * Where the master copy of the superblock is located, and how big + * superblocks are supposed to be. We define SUPERBLOCK_SIZE because + * the size of the superblock structure is not necessarily trustworthy + * (some versions have the padding set up so that the superblock is + * 1032 bytes long). + */ +#define SUPERBLOCK_OFFSET 1024 +#define SUPERBLOCK_SIZE 1024 + +/* + * The last ext2fs revision level that this version of the library is + * able to support. + */ +#define EXT2_LIB_CURRENT_REV EXT2_DYNAMIC_REV + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#include +#include +#include +#include + +#include "ext2_types.h" +#include "com_err.h" +#include "ext2_fs.h" +#include "ext3_extents.h" + +typedef __u32 ext2_ino_t; +typedef __u32 blk_t; +typedef __u64 blk64_t; +typedef __u32 dgrp_t; +typedef __u32 ext2_off_t; +typedef __u64 ext2_off64_t; +typedef __s64 e2_blkcnt_t; +typedef __u32 ext2_dirhash_t; + +#include "ext2_io.h" +#include "ext2_err.h" +#include "ext2_ext_attr.h" + +/* + * Portability help for Microsoft Visual C++ + */ +#ifdef _MSC_VER +#define EXT2_QSORT_TYPE int __cdecl +#else +#define EXT2_QSORT_TYPE int +#endif + +typedef struct struct_ext2_filsys *ext2_filsys; + +#define EXT2FS_MARK_ERROR 0 +#define EXT2FS_UNMARK_ERROR 1 +#define EXT2FS_TEST_ERROR 2 + +typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap; +typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap; +typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap; + +#define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s) + + +/* + * Badblocks list definitions + */ + +typedef struct ext2_struct_u32_list *ext2_badblocks_list; +typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate; + +typedef struct ext2_struct_u32_list *ext2_u32_list; +typedef struct ext2_struct_u32_iterate *ext2_u32_iterate; + +/* old */ +typedef struct ext2_struct_u32_list *badblocks_list; +typedef struct ext2_struct_u32_iterate *badblocks_iterate; + +#define BADBLOCKS_FLAG_DIRTY 1 + +/* + * ext2_dblist structure and abstractions (see dblist.c) + */ +struct ext2_db_entry2 { + ext2_ino_t ino; + blk64_t blk; + e2_blkcnt_t blockcnt; +}; + +/* Ye Olde 32-bit version */ +struct ext2_db_entry { + ext2_ino_t ino; + blk_t blk; + int blockcnt; +}; + +typedef struct ext2_struct_dblist *ext2_dblist; + +#define DBLIST_ABORT 1 + +/* + * ext2_fileio definitions + */ + +#define EXT2_FILE_WRITE 0x0001 +#define EXT2_FILE_CREATE 0x0002 + +#define EXT2_FILE_MASK 0x00FF + +#define EXT2_FILE_BUF_DIRTY 0x4000 +#define EXT2_FILE_BUF_VALID 0x2000 + +typedef struct ext2_file *ext2_file_t; + +#define EXT2_SEEK_SET 0 +#define EXT2_SEEK_CUR 1 +#define EXT2_SEEK_END 2 + +/* + * Flags for the ext2_filsys structure and for ext2fs_open() + */ +#define EXT2_FLAG_RW 0x01 +#define EXT2_FLAG_CHANGED 0x02 +#define EXT2_FLAG_DIRTY 0x04 +#define EXT2_FLAG_VALID 0x08 +#define EXT2_FLAG_IB_DIRTY 0x10 +#define EXT2_FLAG_BB_DIRTY 0x20 +#define EXT2_FLAG_SWAP_BYTES 0x40 +#define EXT2_FLAG_SWAP_BYTES_READ 0x80 +#define EXT2_FLAG_SWAP_BYTES_WRITE 0x100 +#define EXT2_FLAG_MASTER_SB_ONLY 0x200 +#define EXT2_FLAG_FORCE 0x400 +#define EXT2_FLAG_SUPER_ONLY 0x800 +#define EXT2_FLAG_JOURNAL_DEV_OK 0x1000 +#define EXT2_FLAG_IMAGE_FILE 0x2000 +#define EXT2_FLAG_EXCLUSIVE 0x4000 +#define EXT2_FLAG_SOFTSUPP_FEATURES 0x8000 +#define EXT2_FLAG_NOFREE_ON_ERROR 0x10000 +#define EXT2_FLAG_64BITS 0x20000 +#define EXT2_FLAG_PRINT_PROGRESS 0x40000 +#define EXT2_FLAG_DIRECT_IO 0x80000 + +/* + * Special flag in the ext2 inode i_flag field that means that this is + * a new inode. (So that ext2_write_inode() can clear extra fields.) + */ +#define EXT2_NEW_INODE_FL 0x80000000 + +/* + * Flags for mkjournal + * + * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock + */ +#define EXT2_MKJOURNAL_V1_SUPER 0x0000001 + +struct opaque_ext2_group_desc; + +struct struct_ext2_filsys { + errcode_t magic; + io_channel io; + int flags; + char * device_name; + struct ext2_super_block * super; + unsigned int blocksize; + int fragsize; + dgrp_t group_desc_count; + unsigned long desc_blocks; + struct opaque_ext2_group_desc * group_desc; + int inode_blocks_per_group; + ext2fs_inode_bitmap inode_map; + ext2fs_block_bitmap block_map; + /* XXX FIXME-64: not 64-bit safe, but not used? */ + errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks); + errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino); + errcode_t (*write_bitmaps)(ext2_filsys fs); + errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode); + errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode); + ext2_badblocks_list badblocks; + ext2_dblist dblist; + __u32 stride; /* for mke2fs */ + struct ext2_super_block * orig_super; + struct ext2_image_hdr * image_header; + __u32 umask; + time_t now; + /* + * Reserved for future expansion + */ + __u32 reserved[7]; + + /* + * Reserved for the use of the calling application. + */ + void * priv_data; + + /* + * Inode cache + */ + struct ext2_inode_cache *icache; + io_channel image_io; + + /* + * More callback functions + */ + errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal, + blk64_t *ret); + void (*block_alloc_stats)(ext2_filsys fs, blk64_t blk, int inuse); +}; + +#include "bitops.h" + +/* + * Return flags for the block iterator functions + */ +#define BLOCK_CHANGED 1 +#define BLOCK_ABORT 2 +#define BLOCK_ERROR 4 + +/* + * Block interate flags + * + * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator + * function should be called on blocks where the block number is zero. + * This is used by ext2fs_expand_dir() to be able to add a new block + * to an inode. It can also be used for programs that want to be able + * to deal with files that contain "holes". + * + * BLOCK_FLAG_DEPTH_TRAVERSE indicates that the iterator function for + * the indirect, doubly indirect, etc. blocks should be called after + * all of the blocks containined in the indirect blocks are processed. + * This is useful if you are going to be deallocating blocks from an + * inode. + * + * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be + * called for data blocks only. + * + * BLOCK_FLAG_READ_ONLY is a promise by the caller that it will not + * modify returned block number. + * + * BLOCK_FLAG_NO_LARGE is for internal use only. It informs + * ext2fs_block_iterate2 that large files won't be accepted. + */ +#define BLOCK_FLAG_APPEND 1 +#define BLOCK_FLAG_HOLE 1 +#define BLOCK_FLAG_DEPTH_TRAVERSE 2 +#define BLOCK_FLAG_DATA_ONLY 4 +#define BLOCK_FLAG_READ_ONLY 8 + +#define BLOCK_FLAG_NO_LARGE 0x1000 + +/* + * Magic "block count" return values for the block iterator function. + */ +#define BLOCK_COUNT_IND (-1) +#define BLOCK_COUNT_DIND (-2) +#define BLOCK_COUNT_TIND (-3) +#define BLOCK_COUNT_TRANSLATOR (-4) + +/* + * Flags for ext2fs_move_blocks + */ +#define EXT2_BMOVE_GET_DBLIST 0x0001 +#define EXT2_BMOVE_DEBUG 0x0002 + +/* + * Generic (non-filesystem layout specific) extents structure + */ + +#define EXT2_EXTENT_FLAGS_LEAF 0x0001 +#define EXT2_EXTENT_FLAGS_UNINIT 0x0002 +#define EXT2_EXTENT_FLAGS_SECOND_VISIT 0x0004 + +struct ext2fs_extent { + blk64_t e_pblk; /* first physical block */ + blk64_t e_lblk; /* first logical block extent covers */ + __u32 e_len; /* number of blocks covered by extent */ + __u32 e_flags; /* extent flags */ +}; + +typedef struct ext2_extent_handle *ext2_extent_handle_t; +typedef struct ext2_extent_path *ext2_extent_path_t; + +/* + * Flags used by ext2fs_extent_get() + */ +#define EXT2_EXTENT_CURRENT 0x0000 +#define EXT2_EXTENT_MOVE_MASK 0x000F +#define EXT2_EXTENT_ROOT 0x0001 +#define EXT2_EXTENT_LAST_LEAF 0x0002 +#define EXT2_EXTENT_FIRST_SIB 0x0003 +#define EXT2_EXTENT_LAST_SIB 0x0004 +#define EXT2_EXTENT_NEXT_SIB 0x0005 +#define EXT2_EXTENT_PREV_SIB 0x0006 +#define EXT2_EXTENT_NEXT_LEAF 0x0007 +#define EXT2_EXTENT_PREV_LEAF 0x0008 +#define EXT2_EXTENT_NEXT 0x0009 +#define EXT2_EXTENT_PREV 0x000A +#define EXT2_EXTENT_UP 0x000B +#define EXT2_EXTENT_DOWN 0x000C +#define EXT2_EXTENT_DOWN_AND_LAST 0x000D + +/* + * Flags used by ext2fs_extent_insert() + */ +#define EXT2_EXTENT_INSERT_AFTER 0x0001 /* insert after handle loc'n */ +#define EXT2_EXTENT_INSERT_NOSPLIT 0x0002 /* insert may not cause split */ + +/* + * Flags used by ext2fs_extent_delete() + */ +#define EXT2_EXTENT_DELETE_KEEP_EMPTY 0x001 /* keep node if last extnt gone */ + +/* + * Flags used by ext2fs_extent_set_bmap() + */ +#define EXT2_EXTENT_SET_BMAP_UNINIT 0x0001 + +/* + * Data structure returned by ext2fs_extent_get_info() + */ +struct ext2_extent_info { + int curr_entry; + int curr_level; + int num_entries; + int max_entries; + int max_depth; + int bytes_avail; + blk64_t max_lblk; + blk64_t max_pblk; + __u32 max_len; + __u32 max_uninit_len; +}; + +/* + * Flags for directory block reading and writing functions + */ +#define EXT2_DIRBLOCK_V2_STRUCT 0x0001 + +/* + * Return flags for the directory iterator functions + */ +#define DIRENT_CHANGED 1 +#define DIRENT_ABORT 2 +#define DIRENT_ERROR 3 + +/* + * Directory iterator flags + */ + +#define DIRENT_FLAG_INCLUDE_EMPTY 1 +#define DIRENT_FLAG_INCLUDE_REMOVED 2 + +#define DIRENT_DOT_FILE 1 +#define DIRENT_DOT_DOT_FILE 2 +#define DIRENT_OTHER_FILE 3 +#define DIRENT_DELETED_FILE 4 + +/* + * Inode scan definitions + */ +typedef struct ext2_struct_inode_scan *ext2_inode_scan; + +/* + * ext2fs_scan flags + */ +#define EXT2_SF_CHK_BADBLOCKS 0x0001 +#define EXT2_SF_BAD_INODE_BLK 0x0002 +#define EXT2_SF_BAD_EXTRA_BYTES 0x0004 +#define EXT2_SF_SKIP_MISSING_ITABLE 0x0008 +#define EXT2_SF_DO_LAZY 0x0010 + +/* + * ext2fs_check_if_mounted flags + */ +#define EXT2_MF_MOUNTED 1 +#define EXT2_MF_ISROOT 2 +#define EXT2_MF_READONLY 4 +#define EXT2_MF_SWAP 8 +#define EXT2_MF_BUSY 16 + +/* + * Ext2/linux mode flags. We define them here so that we don't need + * to depend on the OS's sys/stat.h, since we may be compiling on a + * non-Linux system. + */ +#define LINUX_S_IFMT 00170000 +#define LINUX_S_IFSOCK 0140000 +#define LINUX_S_IFLNK 0120000 +#define LINUX_S_IFREG 0100000 +#define LINUX_S_IFBLK 0060000 +#define LINUX_S_IFDIR 0040000 +#define LINUX_S_IFCHR 0020000 +#define LINUX_S_IFIFO 0010000 +#define LINUX_S_ISUID 0004000 +#define LINUX_S_ISGID 0002000 +#define LINUX_S_ISVTX 0001000 + +#define LINUX_S_IRWXU 00700 +#define LINUX_S_IRUSR 00400 +#define LINUX_S_IWUSR 00200 +#define LINUX_S_IXUSR 00100 + +#define LINUX_S_IRWXG 00070 +#define LINUX_S_IRGRP 00040 +#define LINUX_S_IWGRP 00020 +#define LINUX_S_IXGRP 00010 + +#define LINUX_S_IRWXO 00007 +#define LINUX_S_IROTH 00004 +#define LINUX_S_IWOTH 00002 +#define LINUX_S_IXOTH 00001 + +#define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK) +#define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG) +#define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR) +#define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR) +#define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK) +#define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO) +#define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK) + +/* + * ext2 size of an inode + */ +#define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32)) + +/* + * ext2_icount_t abstraction + */ +#define EXT2_ICOUNT_OPT_INCREMENT 0x01 + +typedef struct ext2_icount *ext2_icount_t; + +/* + * Flags for ext2fs_bmap + */ +#define BMAP_ALLOC 0x0001 +#define BMAP_SET 0x0002 + +/* + * Returned flags from ext2fs_bmap + */ +#define BMAP_RET_UNINIT 0x0001 + +/* + * Flags for imager.c functions + */ +#define IMAGER_FLAG_INODEMAP 1 +#define IMAGER_FLAG_SPARSEWRITE 2 + +/* + * For checking structure magic numbers... + */ + +#define EXT2_CHECK_MAGIC(struct, code) \ + if ((struct)->magic != (code)) return (code) + + +/* + * For ext2 compression support + */ +#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1) +#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR) + +/* + * Features supported by this version of the library + */ +#define EXT2_LIB_FEATURE_COMPAT_SUPP (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\ + EXT2_FEATURE_COMPAT_IMAGIC_INODES|\ + EXT3_FEATURE_COMPAT_HAS_JOURNAL|\ + EXT2_FEATURE_COMPAT_RESIZE_INODE|\ + EXT2_FEATURE_COMPAT_DIR_INDEX|\ + EXT2_FEATURE_COMPAT_EXT_ATTR) + +/* This #ifdef is temporary until compression is fully supported */ +#ifdef ENABLE_COMPRESSION +#ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL +/* If the below warning bugs you, then have + `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your + environment at configure time. */ + #warning "Compression support is experimental" +#endif +#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ + EXT2_FEATURE_INCOMPAT_COMPRESSION|\ + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\ + EXT2_FEATURE_INCOMPAT_META_BG|\ + EXT3_FEATURE_INCOMPAT_RECOVER|\ + EXT3_FEATURE_INCOMPAT_EXTENTS|\ + EXT4_FEATURE_INCOMPAT_FLEX_BG|\ + EXT4_FEATURE_INCOMPAT_64BIT) +#else +#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\ + EXT2_FEATURE_INCOMPAT_META_BG|\ + EXT3_FEATURE_INCOMPAT_RECOVER|\ + EXT3_FEATURE_INCOMPAT_EXTENTS|\ + EXT4_FEATURE_INCOMPAT_FLEX_BG|\ + EXT4_FEATURE_INCOMPAT_64BIT) +#endif +#define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ + EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\ + EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\ + EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\ + EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\ + EXT4_FEATURE_RO_COMPAT_GDT_CSUM) + +/* + * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed + * to ext2fs_openfs() + */ +#define EXT2_LIB_SOFTSUPP_INCOMPAT (0) +#define EXT2_LIB_SOFTSUPP_RO_COMPAT (0) + +/* + * function prototypes + */ + +/* alloc.c */ +extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode, + ext2fs_inode_bitmap map, ext2_ino_t *ret); +extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal, + ext2fs_block_bitmap map, blk_t *ret); +extern errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, + ext2fs_block_bitmap map, blk64_t *ret); +extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, + blk_t finish, int num, + ext2fs_block_bitmap map, + blk_t *ret); +extern errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, + blk64_t finish, int num, + ext2fs_block_bitmap map, + blk64_t *ret); +extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal, + char *block_buf, blk_t *ret); +extern errcode_t ext2fs_alloc_block2(ext2_filsys fs, blk64_t goal, + char *block_buf, blk64_t *ret); +extern void ext2fs_set_alloc_block_callback(ext2_filsys fs, + errcode_t (*func)(ext2_filsys fs, + blk64_t goal, + blk64_t *ret), + errcode_t (**old)(ext2_filsys fs, + blk64_t goal, + blk64_t *ret)); + +/* alloc_sb.c */ +extern int ext2fs_reserve_super_and_bgd(ext2_filsys fs, + dgrp_t group, + ext2fs_block_bitmap bmap); +extern void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs, + void (*func)(ext2_filsys fs, + blk64_t blk, + int inuse), + void (**old)(ext2_filsys fs, + blk64_t blk, + int inuse)); + +/* alloc_stats.c */ +void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse); +void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino, + int inuse, int isdir); +void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse); +void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse); + +/* alloc_tables.c */ +extern errcode_t ext2fs_allocate_tables(ext2_filsys fs); +extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, + ext2fs_block_bitmap bmap); + +/* badblocks.c */ +extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size); +extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk); +extern int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk); +extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk); +extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb, + ext2_u32_iterate *ret); +extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk); +extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter); +extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest); +extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2); + +extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret, + int size); +extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, + blk_t blk); +extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb, + blk_t blk); +extern int ext2fs_u32_list_del(ext2_u32_list bb, __u32 blk); +extern void ext2fs_badblocks_list_del(ext2_u32_list bb, __u32 blk); +extern errcode_t + ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb, + ext2_badblocks_iterate *ret); +extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter, + blk_t *blk); +extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter); +extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src, + ext2_badblocks_list *dest); +extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1, + ext2_badblocks_list bb2); +extern int ext2fs_u32_list_count(ext2_u32_list bb); + +/* bb_compat */ +extern errcode_t badblocks_list_create(badblocks_list *ret, int size); +extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk); +extern int badblocks_list_test(badblocks_list bb, blk_t blk); +extern errcode_t badblocks_list_iterate_begin(badblocks_list bb, + badblocks_iterate *ret); +extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk); +extern void badblocks_list_iterate_end(badblocks_iterate iter); +extern void badblocks_list_free(badblocks_list bb); + +/* bb_inode.c */ +extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs, + ext2_badblocks_list bb_list); + +/* bitmaps.c */ +extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap); +extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap); +extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest); +extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs); +extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs); +extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs); +extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs); +extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, + const char *descr, + ext2fs_block_bitmap *ret); +extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, + const char *descr, + ext2fs_inode_bitmap *ret); +extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, + ext2_ino_t end, ext2_ino_t *oend); +extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap, + blk_t end, blk_t *oend); +extern errcode_t ext2fs_fudge_block_bitmap_end2(ext2fs_block_bitmap bitmap, + blk64_t end, blk64_t *oend); +extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap); +extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap); +extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs); +extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs); +extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end, + ext2fs_inode_bitmap bmap); +extern errcode_t ext2fs_resize_inode_bitmap2(__u64 new_end, + __u64 new_real_end, + ext2fs_inode_bitmap bmap); +extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end, + ext2fs_block_bitmap bmap); +extern errcode_t ext2fs_resize_block_bitmap2(__u64 new_end, + __u64 new_real_end, + ext2fs_block_bitmap bmap); +extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1, + ext2fs_block_bitmap bm2); +extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1, + ext2fs_inode_bitmap bm2); +extern errcode_t ext2fs_set_inode_bitmap_range(ext2fs_inode_bitmap bmap, + ext2_ino_t start, unsigned int num, + void *in); +extern errcode_t ext2fs_set_inode_bitmap_range2(ext2fs_inode_bitmap bmap, + __u64 start, size_t num, + void *in); +extern errcode_t ext2fs_get_inode_bitmap_range(ext2fs_inode_bitmap bmap, + ext2_ino_t start, unsigned int num, + void *out); +extern errcode_t ext2fs_get_inode_bitmap_range2(ext2fs_inode_bitmap bmap, + __u64 start, size_t num, + void *out); +extern errcode_t ext2fs_set_block_bitmap_range(ext2fs_block_bitmap bmap, + blk_t start, unsigned int num, + void *in); +extern errcode_t ext2fs_set_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t start, size_t num, + void *in); +extern errcode_t ext2fs_get_block_bitmap_range(ext2fs_block_bitmap bmap, + blk_t start, unsigned int num, + void *out); +extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t start, size_t num, + void *out); + +/* blknum.c */ +extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t); +extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group); +extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group); +extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs, + struct ext2_inode *inode); +extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs, + struct ext2_inode *inode); +extern blk64_t ext2fs_blocks_count(struct ext2_super_block *super); +extern void ext2fs_blocks_count_set(struct ext2_super_block *super, + blk64_t blk); +extern void ext2fs_blocks_count_add(struct ext2_super_block *super, + blk64_t blk); +extern blk64_t ext2fs_r_blocks_count(struct ext2_super_block *super); +extern void ext2fs_r_blocks_count_set(struct ext2_super_block *super, + blk64_t blk); +extern void ext2fs_r_blocks_count_add(struct ext2_super_block *super, + blk64_t blk); +extern blk64_t ext2fs_free_blocks_count(struct ext2_super_block *super); +extern void ext2fs_free_blocks_count_set(struct ext2_super_block *super, + blk64_t blk); +extern void ext2fs_free_blocks_count_add(struct ext2_super_block *super, + blk64_t blk); +/* Block group descriptor accessor functions */ +extern struct ext2_group_desc *ext2fs_group_desc(ext2_filsys fs, + struct opaque_ext2_group_desc *gdp, + dgrp_t group); +extern blk64_t ext2fs_block_bitmap_loc(ext2_filsys fs, dgrp_t group); +extern void ext2fs_block_bitmap_loc_set(ext2_filsys fs, dgrp_t group, + blk64_t blk); +extern blk64_t ext2fs_inode_bitmap_loc(ext2_filsys fs, dgrp_t group); +extern void ext2fs_inode_bitmap_loc_set(ext2_filsys fs, dgrp_t group, + blk64_t blk); +extern blk64_t ext2fs_inode_table_loc(ext2_filsys fs, dgrp_t group); +extern void ext2fs_inode_table_loc_set(ext2_filsys fs, dgrp_t group, + blk64_t blk); +extern __u32 ext2fs_bg_free_blocks_count(ext2_filsys fs, dgrp_t group); +extern void ext2fs_bg_free_blocks_count_set(ext2_filsys fs, dgrp_t group, + __u32 n); +extern __u32 ext2fs_bg_free_inodes_count(ext2_filsys fs, dgrp_t group); +extern void ext2fs_bg_free_inodes_count_set(ext2_filsys fs, dgrp_t group, + __u32 n); +extern __u32 ext2fs_bg_used_dirs_count(ext2_filsys fs, dgrp_t group); +extern void ext2fs_bg_used_dirs_count_set(ext2_filsys fs, dgrp_t group, + __u32 n); +extern __u32 ext2fs_bg_itable_unused(ext2_filsys fs, dgrp_t group); +extern void ext2fs_bg_itable_unused_set(ext2_filsys fs, dgrp_t group, + __u32 n); +extern __u16 ext2fs_bg_flags(ext2_filsys fs, dgrp_t group); +extern void ext2fs_bg_flags_zap(ext2_filsys fs, dgrp_t group); +extern int ext2fs_bg_flags_test(ext2_filsys fs, dgrp_t group, __u16 bg_flag); +extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags); +extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags); +extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group); +extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum); +extern blk64_t ext2fs_file_acl_block(const struct ext2_inode *inode); +extern void ext2fs_file_acl_block_set(struct ext2_inode *inode, blk64_t blk); + +/* block.c */ +extern errcode_t ext2fs_block_iterate(ext2_filsys fs, + ext2_ino_t ino, + int flags, + char *block_buf, + int (*func)(ext2_filsys fs, + blk_t *blocknr, + int blockcnt, + void *priv_data), + void *priv_data); +errcode_t ext2fs_block_iterate2(ext2_filsys fs, + ext2_ino_t ino, + int flags, + char *block_buf, + int (*func)(ext2_filsys fs, + blk_t *blocknr, + e2_blkcnt_t blockcnt, + blk_t ref_blk, + int ref_offset, + void *priv_data), + void *priv_data); +errcode_t ext2fs_block_iterate3(ext2_filsys fs, + ext2_ino_t ino, + int flags, + char *block_buf, + int (*func)(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_blk, + int ref_offset, + void *priv_data), + void *priv_data); + +/* bmap.c */ +extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char *block_buf, int bmap_flags, + blk_t block, blk_t *phys_blk); +extern errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char *block_buf, int bmap_flags, blk64_t block, + int *ret_flags, blk64_t *phys_blk); + +#if 0 +/* bmove.c */ +extern errcode_t ext2fs_move_blocks(ext2_filsys fs, + ext2fs_block_bitmap reserve, + ext2fs_block_bitmap alloc_map, + int flags); +#endif + +/* check_desc.c */ +extern errcode_t ext2fs_check_desc(ext2_filsys fs); + +/* closefs.c */ +extern errcode_t ext2fs_close(ext2_filsys fs); +extern errcode_t ext2fs_flush(ext2_filsys fs); +extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block); +extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs, + dgrp_t group, + blk64_t *ret_super_blk, + blk64_t *ret_old_desc_blk, + blk64_t *ret_new_desc_blk, + blk_t *ret_used_blks); +extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, + dgrp_t group, + blk_t *ret_super_blk, + blk_t *ret_old_desc_blk, + blk_t *ret_new_desc_blk, + int *ret_meta_bg); +extern void ext2fs_update_dynamic_rev(ext2_filsys fs); + +/* csum.c */ +extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group); +extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group); +extern errcode_t ext2fs_set_gdt_csum(ext2_filsys fs); + +/* dblist.c */ + +extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs); +extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist); +extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, + blk_t blk, int blockcnt); +extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, + blk64_t blk, e2_blkcnt_t blockcnt); +extern void ext2fs_dblist_sort(ext2_dblist dblist, + EXT2_QSORT_TYPE (*sortfunc)(const void *, + const void *)); +extern void ext2fs_dblist_sort2(ext2_dblist dblist, + EXT2_QSORT_TYPE (*sortfunc)(const void *, + const void *)); +extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist, + int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info, + void *priv_data), + void *priv_data); +extern errcode_t ext2fs_dblist_iterate2(ext2_dblist dblist, + int (*func)(ext2_filsys fs, struct ext2_db_entry2 *db_info, + void *priv_data), + void *priv_data); +extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino, + blk_t blk, int blockcnt); +extern errcode_t ext2fs_set_dir_block2(ext2_dblist dblist, ext2_ino_t ino, + blk64_t blk, e2_blkcnt_t blockcnt); +extern errcode_t ext2fs_copy_dblist(ext2_dblist src, + ext2_dblist *dest); +extern int ext2fs_dblist_count(ext2_dblist dblist); +extern blk64_t ext2fs_dblist_count2(ext2_dblist dblist); +extern errcode_t ext2fs_dblist_get_last(ext2_dblist dblist, + struct ext2_db_entry **entry); +extern errcode_t ext2fs_dblist_get_last2(ext2_dblist dblist, + struct ext2_db_entry2 **entry); +extern errcode_t ext2fs_dblist_drop_last(ext2_dblist dblist); + +/* dblist_dir.c */ +extern errcode_t + ext2fs_dblist_dir_iterate(ext2_dblist dblist, + int flags, + char *block_buf, + int (*func)(ext2_ino_t dir, + int entry, + struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data); + +/* dirblock.c */ +extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block, + void *buf); +extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block, + void *buf, int flags); +extern errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block, + void *buf, int flags); +extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block, + void *buf); +extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block, + void *buf, int flags); +extern errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block, + void *buf, int flags); + +/* dirhash.c */ +extern errcode_t ext2fs_dirhash(int version, const char *name, int len, + const __u32 *seed, + ext2_dirhash_t *ret_hash, + ext2_dirhash_t *ret_minor_hash); + + +/* dir_iterate.c */ +extern errcode_t ext2fs_get_rec_len(ext2_filsys fs, + struct ext2_dir_entry *dirent, + unsigned int *rec_len); +extern errcode_t ext2fs_set_rec_len(ext2_filsys fs, + unsigned int len, + struct ext2_dir_entry *dirent); +extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, + ext2_ino_t dir, + int flags, + char *block_buf, + int (*func)(struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data); +extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs, + ext2_ino_t dir, + int flags, + char *block_buf, + int (*func)(ext2_ino_t dir, + int entry, + struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data), + void *priv_data); + +/* dupfs.c */ +extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest); + +/* expanddir.c */ +extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir); + +/* ext_attr.c */ +extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry, + void *data); +extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf); +extern errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block, + void *buf); +extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, + void *buf); +extern errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block, + void *buf); +extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk, + char *block_buf, + int adjust, __u32 *newcount); +extern errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk, + char *block_buf, + int adjust, __u32 *newcount); + +/* extent.c */ +extern errcode_t ext2fs_extent_header_verify(void *ptr, int size); +extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino, + ext2_extent_handle_t *handle); +extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + ext2_extent_handle_t *ret_handle); +extern void ext2fs_extent_free(ext2_extent_handle_t handle); +extern errcode_t ext2fs_extent_get(ext2_extent_handle_t handle, + int flags, struct ext2fs_extent *extent); +extern errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, int flags, + struct ext2fs_extent *extent); +extern errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags, + struct ext2fs_extent *extent); +extern errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle, + blk64_t logical, blk64_t physical, + int flags); +extern errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags); +extern errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle, + struct ext2_extent_info *info); +extern errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, + blk64_t blk); + +/* fileio.c */ +extern errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + int flags, ext2_file_t *ret); +extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino, + int flags, ext2_file_t *ret); +extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file); +struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file); +extern errcode_t ext2fs_file_close(ext2_file_t file); +extern errcode_t ext2fs_file_flush(ext2_file_t file); +extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf, + unsigned int wanted, unsigned int *got); +extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, + unsigned int nbytes, unsigned int *written); +extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset, + int whence, __u64 *ret_pos); +extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset, + int whence, ext2_off_t *ret_pos); +errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size); +extern ext2_off_t ext2fs_file_get_size(ext2_file_t file); +extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size); +extern errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size); + +/* finddev.c */ +extern char *ext2fs_find_block_device(dev_t device); + +/* flushb.c */ +extern errcode_t ext2fs_sync_device(int fd, int flushb); + +/* freefs.c */ +extern void ext2fs_free(ext2_filsys fs); +extern void ext2fs_free_dblist(ext2_dblist dblist); +extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb); +extern void ext2fs_u32_list_free(ext2_u32_list bb); + +/* gen_bitmap.c */ +extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap); +extern errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs, + __u32 start, __u32 end, + __u32 real_end, + const char *descr, char *init_map, + ext2fs_generic_bitmap *ret); +extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start, + __u32 end, + __u32 real_end, + const char *descr, + ext2fs_generic_bitmap *ret); +extern errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest); +extern void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap); +extern errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap, + errcode_t magic, + errcode_t neq, + ext2_ino_t end, + ext2_ino_t *oend); +extern void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map); +extern errcode_t ext2fs_resize_generic_bitmap(errcode_t magic, + __u32 new_end, + __u32 new_real_end, + ext2fs_generic_bitmap bmap); +extern errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq, + ext2fs_generic_bitmap bm1, + ext2fs_generic_bitmap bm2); +extern errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap, + errcode_t magic, + __u32 start, __u32 num, + void *out); +extern errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap, + errcode_t magic, + __u32 start, __u32 num, + void *in); + +/* gen_bitmap64.c */ +void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap); +errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, + int type, __u64 start, __u64 end, + __u64 real_end, + const char *descr, + ext2fs_generic_bitmap *ret); +errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest); +void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap); +errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap, + errcode_t neq, + __u64 end, __u64 *oend); +void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap); +errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, + __u64 new_end, + __u64 new_real_end); +errcode_t ext2fs_compare_generic_bmap(errcode_t neq, + ext2fs_generic_bitmap bm1, + ext2fs_generic_bitmap bm2); +errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap, + __u64 start, unsigned int num, + void *out); +errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap, + __u64 start, unsigned int num, + void *in); + +/* getsize.c */ +extern errcode_t ext2fs_get_device_size(const char *file, int blocksize, + blk_t *retblocks); +extern errcode_t ext2fs_get_device_size2(const char *file, int blocksize, + blk64_t *retblocks); + +/* getsectsize.c */ +errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize); +errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize); + +/* i_block.c */ +errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode, + blk64_t num_blocks); +errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode, + blk64_t num_blocks); +errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b); + +/* imager.c */ +extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags); +extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags); +extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags); +extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags); +extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags); +extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags); + +/* ind_block.c */ +errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf); +errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf); + +/* initialize.c */ +extern errcode_t ext2fs_initialize(const char *name, int flags, + struct ext2_super_block *param, + io_manager manager, ext2_filsys *ret_fs); + +/* icount.c */ +extern void ext2fs_free_icount(ext2_icount_t icount); +extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir, + int flags, ext2_icount_t *ret); +extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, + unsigned int size, + ext2_icount_t hint, ext2_icount_t *ret); +extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, + unsigned int size, + ext2_icount_t *ret); +extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino, + __u16 *ret); +extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, + __u16 *ret); +extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino, + __u16 *ret); +extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino, + __u16 count); +extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount); +errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *); + +/* inode.c */ +extern errcode_t ext2fs_flush_icache(ext2_filsys fs); +extern errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, + ext2_ino_t *ino, + struct ext2_inode *inode, + int bufsize); +extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, + ext2_inode_scan *ret_scan); +extern void ext2fs_close_inode_scan(ext2_inode_scan scan); +extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino, + struct ext2_inode *inode); +extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, + int group); +extern void ext2fs_set_inode_callback + (ext2_inode_scan scan, + errcode_t (*done_group)(ext2_filsys fs, + ext2_inode_scan scan, + dgrp_t group, + void * priv_data), + void *done_group_data); +extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags, + int clear_flags); +extern errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode, + int bufsize); +extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode); +extern errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode, + int bufsize); +extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode); +extern errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode); +extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks); +extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino); + +/* inode_io.c */ +extern io_manager inode_io_manager; +extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino, + char **name); +extern errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char **name); + +/* ismounted.c */ +extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags); +extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, + char *mtpt, int mtlen); + +/* punch.c */ +extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char *block_buf, blk64_t start, + blk64_t end); + +/* namei.c */ +extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name, + int namelen, char *buf, ext2_ino_t *inode); +extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, + const char *name, ext2_ino_t *inode); +errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, + const char *name, ext2_ino_t *inode); +extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, + ext2_ino_t inode, ext2_ino_t *res_inode); + +/* native.c */ +int ext2fs_native_flag(void); + +/* newdir.c */ +extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, + ext2_ino_t parent_ino, char **block); + +/* mkdir.c */ +extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, + const char *name); + +/* mkjournal.c */ +extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num, + blk_t *ret_blk, int *ret_count); +extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num, + blk64_t *ret_blk, int *ret_count); +extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, + __u32 size, int flags, + char **ret_jsb); +extern errcode_t ext2fs_add_journal_device(ext2_filsys fs, + ext2_filsys journal_dev); +extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, + int flags); +extern int ext2fs_default_journal_size(__u64 blocks); + +/* openfs.c */ +extern errcode_t ext2fs_open(const char *name, int flags, int superblock, + unsigned int block_size, io_channel * chan, + ext2_filsys *ret_fs); +extern errcode_t ext2fs_open2(const char *name, const char *io_options, + int flags, int superblock, + unsigned int block_size, io_channel * chan, + ext2_filsys *ret_fs); +extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, + blk64_t group_block, dgrp_t i); +extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, + dgrp_t i); +errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io); +errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io); +errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io); + +/* get_pathname.c */ +extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino, + char **name); + +/* link.c */ +errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name, + ext2_ino_t ino, int flags); +errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name, + ext2_ino_t ino, int flags); + +/* read_bb.c */ +extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs, + ext2_badblocks_list *bb_list); + +/* read_bb_file.c */ +extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, + ext2_badblocks_list *bb_list, + void *priv_data, + void (*invalid)(ext2_filsys fs, + blk_t blk, + char *badstr, + void *priv_data)); +extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, + ext2_badblocks_list *bb_list, + void (*invalid)(ext2_filsys fs, + blk_t blk)); + +/* res_gdt.c */ +extern errcode_t ext2fs_create_resize_inode(ext2_filsys fs); + +/* swapfs.c */ +extern void ext2fs_swap_ext_attr(char *to, char *from, int bufsize, + int has_header); +extern void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header, + struct ext2_ext_attr_header *from_hdr); +extern void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry, + struct ext2_ext_attr_entry *from_entry); +extern void ext2fs_swap_super(struct ext2_super_block * super); +extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp); +extern void ext2fs_swap_group_desc2(ext2_filsys, struct ext2_group_desc *gdp); +extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, + struct ext2_inode_large *f, int hostorder, + int bufsize); +extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t, + struct ext2_inode *f, int hostorder); + +/* valid_blk.c */ +extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode); + +/* version.c */ +extern int ext2fs_parse_version_string(const char *ver_string); +extern int ext2fs_get_library_version(const char **ver_string, + const char **date_string); + +/* write_bb_file.c */ +extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, + unsigned int flags, + FILE *f); + + +/* inline functions */ +extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr); +extern errcode_t ext2fs_get_memalign(unsigned long size, + unsigned long align, void *ptr); +extern errcode_t ext2fs_free_mem(void *ptr); +extern errcode_t ext2fs_resize_mem(unsigned long old_size, + unsigned long size, void *ptr); +extern void ext2fs_mark_super_dirty(ext2_filsys fs); +extern void ext2fs_mark_changed(ext2_filsys fs); +extern int ext2fs_test_changed(ext2_filsys fs); +extern void ext2fs_mark_valid(ext2_filsys fs); +extern void ext2fs_unmark_valid(ext2_filsys fs); +extern int ext2fs_test_valid(ext2_filsys fs); +extern void ext2fs_mark_ib_dirty(ext2_filsys fs); +extern void ext2fs_mark_bb_dirty(ext2_filsys fs); +extern int ext2fs_test_ib_dirty(ext2_filsys fs); +extern int ext2fs_test_bb_dirty(ext2_filsys fs); +extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk); +extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino); +extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group); +extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group); +extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, + struct ext2_inode *inode); +extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b); +extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b); + +/* + * The actual inlined functions definitions themselves... + * + * If NO_INLINE_FUNCS is defined, then we won't try to do inline + * functions at all! + */ +#if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) +#ifdef INCLUDE_INLINE_FUNCS +#define _INLINE_ extern +#else +#ifdef __GNUC__ +#define _INLINE_ extern __inline__ +#else /* For Watcom C */ +#define _INLINE_ extern inline +#endif +#endif + +#ifndef EXT2_CUSTOM_MEMORY_ROUTINES +#include +#include "mem_allocate.h" +/* + * Allocate memory + */ +_INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) +{ + void *pp; + + pp = mem_alloc(size); + if (!pp) + return EXT2_ET_NO_MEMORY; + memcpy(ptr, &pp, sizeof (pp)); + return 0; +} + +_INLINE_ errcode_t ext2fs_get_memalign(unsigned long size, + unsigned long align, void *ptr) +{ + void *pp; + + #ifdef HWRVL + pp = mem_align(32, size); + #else + pp = mem_alloc(size); + #endif + if (!pp) + return EXT2_ET_NO_MEMORY; + + memcpy(ptr, &pp, sizeof (pp)); + return 0; +} + +_INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr) +{ + if (count && (-1UL)/countflags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED; +} + +/* + * Mark a filesystem as changed + */ +_INLINE_ void ext2fs_mark_changed(ext2_filsys fs) +{ + fs->flags |= EXT2_FLAG_CHANGED; +} + +/* + * Check to see if a filesystem has changed + */ +_INLINE_ int ext2fs_test_changed(ext2_filsys fs) +{ + return (fs->flags & EXT2_FLAG_CHANGED); +} + +/* + * Mark a filesystem as valid + */ +_INLINE_ void ext2fs_mark_valid(ext2_filsys fs) +{ + fs->flags |= EXT2_FLAG_VALID; +} + +/* + * Mark a filesystem as NOT valid + */ +_INLINE_ void ext2fs_unmark_valid(ext2_filsys fs) +{ + fs->flags &= ~EXT2_FLAG_VALID; +} + +/* + * Check to see if a filesystem is valid + */ +_INLINE_ int ext2fs_test_valid(ext2_filsys fs) +{ + return (fs->flags & EXT2_FLAG_VALID); +} + +/* + * Mark the inode bitmap as dirty + */ +_INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs) +{ + fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED; +} + +/* + * Mark the block bitmap as dirty + */ +_INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs) +{ + fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED; +} + +/* + * Check to see if a filesystem's inode bitmap is dirty + */ +_INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs) +{ + return (fs->flags & EXT2_FLAG_IB_DIRTY); +} + +/* + * Check to see if a filesystem's block bitmap is dirty + */ +_INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs) +{ + return (fs->flags & EXT2_FLAG_BB_DIRTY); +} + +/* + * Return the group # of a block + */ +_INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) +{ + return ext2fs_group_of_blk2(fs, blk); +} +/* + * Return the group # of an inode number + */ +_INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) +{ + return (ino - 1) / fs->super->s_inodes_per_group; +} + +/* + * Return the first block (inclusive) in a group + */ +_INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group) +{ + return ext2fs_group_first_block2(fs, group); +} + +/* + * Return the last block (inclusive) in a group + */ +_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group) +{ + return ext2fs_group_last_block2(fs, group); +} + +_INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs, + struct ext2_inode *inode) +{ + return ext2fs_inode_data_blocks2(fs, inode); +} + +/* + * This is an efficient, overflow safe way of calculating ceil((1.0 * a) / b) + */ +_INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b) +{ + if (!a) + return 0; + return ((a - 1) / b) + 1; +} + +_INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b) +{ + if (!a) + return 0; + return ((a - 1) / b) + 1; +} + +#undef _INLINE_ +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _EXT2FS_EXT2FS_H */ diff --git a/libcustomext2fs/source/ext2fsP.h b/libcustomext2fs/source/ext2fsP.h new file mode 100644 index 00000000..ab9ee766 --- /dev/null +++ b/libcustomext2fs/source/ext2fsP.h @@ -0,0 +1,143 @@ +/* + * ext2fsP.h --- private header file for ext2 library + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include "ext2fs.h" + +/* + * Badblocks list + */ +struct ext2_struct_u32_list { + int magic; + int num; + int size; + __u32 *list; + int badblocks_flags; +}; + +struct ext2_struct_u32_iterate { + int magic; + ext2_u32_list bb; + int ptr; +}; + + +/* + * Directory block iterator definition + */ +struct ext2_struct_dblist { + int magic; + ext2_filsys fs; + unsigned long long size; + unsigned long long count; + int sorted; + struct ext2_db_entry2 * list; +}; + +/* + * For directory iterators + */ +struct dir_context { + ext2_ino_t dir; + int flags; + char *buf; + int (*func)(ext2_ino_t dir, + int entry, + struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data); + void *priv_data; + errcode_t errcode; +}; + +/* + * Inode cache structure + */ +struct ext2_inode_cache { + void * buffer; + blk_t buffer_blk; + int cache_last; + int cache_size; + int refcount; + struct ext2_inode_cache_ent *cache; +}; + +struct ext2_inode_cache_ent { + ext2_ino_t ino; + struct ext2_inode inode; +}; + +/* Function prototypes */ + +extern int ext2fs_process_dir_block(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_block, + int ref_offset, + void *priv_data); + +/* Generic numeric progress meter */ + +struct ext2fs_numeric_progress_struct { + __u64 max; + int log_max; + int skip_progress; +}; + +extern void ext2fs_numeric_progress_init(ext2_filsys fs, + struct ext2fs_numeric_progress_struct * progress, + const char *label, __u64 max); +extern void ext2fs_numeric_progress_update(ext2_filsys fs, + struct ext2fs_numeric_progress_struct * progress, + __u64 val); +extern void ext2fs_numeric_progress_close(ext2_filsys fs, + struct ext2fs_numeric_progress_struct * progress, + const char *message); + +/* + * 64-bit bitmap support + */ + +#define EXT2FS_BMAP64_BITARRAY 1 + +extern errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, + int type, __u64 start, __u64 end, + __u64 real_end, + const char * description, + ext2fs_generic_bitmap *bmap); + +extern void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap); + +extern errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest); + +extern errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, + __u64 new_end, + __u64 new_real_end); +extern errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap, + errcode_t neq, + __u64 end, __u64 *oend); +extern int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, + __u64 arg); +extern int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, + __u64 arg); +extern int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, + __u64 arg); +extern errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bitmap, + __u64 start, unsigned int num, + void *in); +extern errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bitmap, + __u64 start, unsigned int num, + void *out); +extern int ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap, const char *func); + +extern int ext2fs_mem_is_zero(const char *mem, size_t len); diff --git a/libcustomext2fs/source/ext3_extents.h b/libcustomext2fs/source/ext3_extents.h new file mode 100644 index 00000000..88fabc9d --- /dev/null +++ b/libcustomext2fs/source/ext3_extents.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2003,2004 Cluster File Systems, Inc, info@clusterfs.com + * Written by Alex Tomas + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#ifndef _LINUX_EXT3_EXTENTS +#define _LINUX_EXT3_EXTENTS + +/* + * ext3_inode has i_block array (total 60 bytes) + * first 4 bytes are used to store: + * - tree depth (0 mean there is no tree yet. all extents in the inode) + * - number of alive extents in the inode + */ + +/* + * this is extent on-disk structure + * it's used at the bottom of the tree + */ +struct ext3_extent { + __u32 ee_block; /* first logical block extent covers */ + __u16 ee_len; /* number of blocks covered by extent */ + __u16 ee_start_hi; /* high 16 bits of physical block */ + __u32 ee_start; /* low 32 bigs of physical block */ +}; + +/* + * this is index on-disk structure + * it's used at all the levels, but the bottom + */ +struct ext3_extent_idx { + __u32 ei_block; /* index covers logical blocks from 'block' */ + __u32 ei_leaf; /* pointer to the physical block of the next * + * level. leaf or next index could bet here */ + __u16 ei_leaf_hi; /* high 16 bits of physical block */ + __u16 ei_unused; +}; + +/* + * each block (leaves and indexes), even inode-stored has header + */ +struct ext3_extent_header { + __u16 eh_magic; /* probably will support different formats */ + __u16 eh_entries; /* number of valid entries */ + __u16 eh_max; /* capacity of store in entries */ + __u16 eh_depth; /* has tree real underlaying blocks? */ + __u32 eh_generation; /* generation of the tree */ +}; + +#define EXT3_EXT_MAGIC 0xf30a + +/* + * array of ext3_ext_path contains path to some extent + * creation/lookup routines use it for traversal/splitting/etc + * truncate uses it to simulate recursive walking + */ +struct ext3_ext_path { + __u32 p_block; + __u16 p_depth; + struct ext3_extent *p_ext; + struct ext3_extent_idx *p_idx; + struct ext3_extent_header *p_hdr; + struct buffer_head *p_bh; +}; + +/* + * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an + * initialized extent. This is 2^15 and not (2^16 - 1), since we use the + * MSB of ee_len field in the extent datastructure to signify if this + * particular extent is an initialized extent or an uninitialized (i.e. + * preallocated). + * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an + * uninitialized extent. + * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an + * uninitialized one. In other words, if MSB of ee_len is set, it is an + * uninitialized extent with only one special scenario when ee_len = 0x8000. + * In this case we can not have an uninitialized extent of zero length and + * thus we make it as a special case of initialized extent with 0x8000 length. + * This way we get better extent-to-group alignment for initialized extents. + * Hence, the maximum number of blocks we can have in an *initialized* + * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767). + */ +#define EXT_INIT_MAX_LEN (1UL << 15) +#define EXT_UNINIT_MAX_LEN (EXT_INIT_MAX_LEN - 1) + +#define EXT_FIRST_EXTENT(__hdr__) \ + ((struct ext3_extent *) (((char *) (__hdr__)) + \ + sizeof(struct ext3_extent_header))) +#define EXT_FIRST_INDEX(__hdr__) \ + ((struct ext3_extent_idx *) (((char *) (__hdr__)) + \ + sizeof(struct ext3_extent_header))) +#define EXT_HAS_FREE_INDEX(__path__) \ + ((__path__)->p_hdr->eh_entries < (__path__)->p_hdr->eh_max) +#define EXT_LAST_EXTENT(__hdr__) \ + (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_entries - 1) +#define EXT_LAST_INDEX(__hdr__) \ + (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_entries - 1) +#define EXT_MAX_EXTENT(__hdr__) \ + (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_max - 1) +#define EXT_MAX_INDEX(__hdr__) \ + (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_max - 1) + +#endif /* _LINUX_EXT3_EXTENTS */ + diff --git a/libcustomext2fs/source/ext_attr.c b/libcustomext2fs/source/ext_attr.c new file mode 100644 index 00000000..52664ebe --- /dev/null +++ b/libcustomext2fs/source/ext_attr.c @@ -0,0 +1,155 @@ +/* + * ext_attr.c --- extended attribute blocks + * + * Copyright (C) 2001 Andreas Gruenbacher, + * + * Copyright (C) 2002 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2_ext_attr.h" + +#include "ext2fs.h" + +#define NAME_HASH_SHIFT 5 +#define VALUE_HASH_SHIFT 16 + +/* + * ext2_xattr_hash_entry() + * + * Compute the hash of an extended attribute. + */ +__u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry, void *data) +{ + __u32 hash = 0; + char *name = ((char *) entry) + sizeof(struct ext2_ext_attr_entry); + int n; + + for (n = 0; n < entry->e_name_len; n++) { + hash = (hash << NAME_HASH_SHIFT) ^ + (hash >> (8*sizeof(hash) - NAME_HASH_SHIFT)) ^ + *name++; + } + + /* The hash needs to be calculated on the data in little-endian. */ + if (entry->e_value_block == 0 && entry->e_value_size != 0) { + __u32 *value = (__u32 *)data; + for (n = (entry->e_value_size + EXT2_EXT_ATTR_ROUND) >> + EXT2_EXT_ATTR_PAD_BITS; n; n--) { + hash = (hash << VALUE_HASH_SHIFT) ^ + (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^ + ext2fs_le32_to_cpu(*value++); + } + } + + return hash; +} + +#undef NAME_HASH_SHIFT +#undef VALUE_HASH_SHIFT + +errcode_t ext2fs_read_ext_attr2(ext2_filsys fs, blk64_t block, void *buf) +{ + errcode_t retval; + + retval = io_channel_read_blk64(fs->io, block, 1, buf); + if (retval) + return retval; +#ifdef WORDS_BIGENDIAN + ext2fs_swap_ext_attr(buf, buf, fs->blocksize, 1); +#endif + return 0; +} + +errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf) +{ + return ext2fs_read_ext_attr2(fs, block, buf); +} + +errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block, void *inbuf) +{ + errcode_t retval; + char *write_buf; + char *buf = NULL; + +#ifdef WORDS_BIGENDIAN + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + write_buf = buf; + ext2fs_swap_ext_attr(buf, inbuf, fs->blocksize, 1); +#else + write_buf = (char *) inbuf; +#endif + retval = io_channel_write_blk64(fs->io, block, 1, write_buf); + if (buf) + ext2fs_free_mem(&buf); + if (!retval) + ext2fs_mark_changed(fs); + return retval; +} + +errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *inbuf) +{ + return ext2fs_write_ext_attr2(fs, block, inbuf); +} + +/* + * This function adjusts the reference count of the EA block. + */ +errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk, + char *block_buf, int adjust, + __u32 *newcount) +{ + errcode_t retval; + struct ext2_ext_attr_header *header; + char *buf = 0; + + if ((blk >= ext2fs_blocks_count(fs->super)) || + (blk < fs->super->s_first_data_block)) + return EXT2_ET_BAD_EA_BLOCK_NUM; + + if (!block_buf) { + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + block_buf = buf; + } + + retval = ext2fs_read_ext_attr2(fs, blk, block_buf); + if (retval) + goto errout; + + header = (struct ext2_ext_attr_header *) block_buf; + header->h_refcount += adjust; + if (newcount) + *newcount = header->h_refcount; + + retval = ext2fs_write_ext_attr2(fs, blk, block_buf); + if (retval) + goto errout; + +errout: + if (buf) + ext2fs_free_mem(&buf); + return retval; +} + +errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk, + char *block_buf, int adjust, + __u32 *newcount) +{ + return ext2fs_adjust_ea_refcount(fs, blk, block_buf, adjust, newcount); +} diff --git a/libcustomext2fs/source/extent.c b/libcustomext2fs/source/extent.c new file mode 100644 index 00000000..5e070925 --- /dev/null +++ b/libcustomext2fs/source/extent.c @@ -0,0 +1,2007 @@ +/* + * extent.c --- routines to implement extents support + * + * Copyright (C) 2007 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" +#include "e2image.h" + +/* + * Definitions to be dropped in lib/ext2fs/ext2fs.h + */ + +/* + * Private definitions + */ + +struct extent_path { + char *buf; + int entries; + int max_entries; + int left; + int visit_num; + int flags; + blk64_t end_blk; + void *curr; +}; + + +struct ext2_extent_handle { + errcode_t magic; + ext2_filsys fs; + ext2_ino_t ino; + struct ext2_inode *inode; + struct ext2_inode inodebuf; + int type; + int level; + int max_depth; + struct extent_path *path; +}; + +struct ext2_extent_path { + errcode_t magic; + int leaf_height; + blk64_t lblk; +}; + +/* + * Useful Debugging stuff + */ + +#ifdef DEBUG +static void dbg_show_header(struct ext3_extent_header *eh) +{ + printf("header: magic=%x entries=%u max=%u depth=%u generation=%u\n", + ext2fs_le16_to_cpu(eh->eh_magic), + ext2fs_le16_to_cpu(eh->eh_entries), + ext2fs_le16_to_cpu(eh->eh_max), + ext2fs_le16_to_cpu(eh->eh_depth), + ext2fs_le32_to_cpu(eh->eh_generation)); +} + +static void dbg_show_index(struct ext3_extent_idx *ix) +{ + printf("index: block=%u leaf=%u leaf_hi=%u unused=%u\n", + ext2fs_le32_to_cpu(ix->ei_block), + ext2fs_le32_to_cpu(ix->ei_leaf), + ext2fs_le16_to_cpu(ix->ei_leaf_hi), + ext2fs_le16_to_cpu(ix->ei_unused)); +} + +static void dbg_show_extent(struct ext3_extent *ex) +{ + printf("extent: block=%u-%u len=%u start=%u start_hi=%u\n", + ext2fs_le32_to_cpu(ex->ee_block), + ext2fs_le32_to_cpu(ex->ee_block) + + ext2fs_le16_to_cpu(ex->ee_len) - 1, + ext2fs_le16_to_cpu(ex->ee_len), + ext2fs_le32_to_cpu(ex->ee_start), + ext2fs_le16_to_cpu(ex->ee_start_hi)); +} + +static void dbg_print_extent(char *desc, struct ext2fs_extent *extent) +{ + if (desc) + printf("%s: ", desc); + printf("extent: lblk %llu--%llu, len %u, pblk %llu, flags: ", + extent->e_lblk, extent->e_lblk + extent->e_len - 1, + extent->e_len, extent->e_pblk); + if (extent->e_flags & EXT2_EXTENT_FLAGS_LEAF) + fputs("LEAF ", stdout); + if (extent->e_flags & EXT2_EXTENT_FLAGS_UNINIT) + fputs("UNINIT ", stdout); + if (extent->e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) + fputs("2ND_VISIT ", stdout); + if (!extent->e_flags) + fputs("(none)", stdout); + fputc('\n', stdout); + +} + +#else +#define dbg_show_header(eh) do { } while (0) +#define dbg_show_index(ix) do { } while (0) +#define dbg_show_extent(ex) do { } while (0) +#define dbg_print_extent(desc, ex) do { } while (0) +#endif + +/* + * Verify the extent header as being sane + */ +errcode_t ext2fs_extent_header_verify(void *ptr, int size) +{ + int eh_max, entry_size; + struct ext3_extent_header *eh = ptr; + + dbg_show_header(eh); + if (ext2fs_le16_to_cpu(eh->eh_magic) != EXT3_EXT_MAGIC) + return EXT2_ET_EXTENT_HEADER_BAD; + if (ext2fs_le16_to_cpu(eh->eh_entries) > ext2fs_le16_to_cpu(eh->eh_max)) + return EXT2_ET_EXTENT_HEADER_BAD; + if (eh->eh_depth == 0) + entry_size = sizeof(struct ext3_extent); + else + entry_size = sizeof(struct ext3_extent_idx); + + eh_max = (size - sizeof(*eh)) / entry_size; + /* Allow two extent-sized items at the end of the block, for + * ext4_extent_tail with checksum in the future. */ + if ((ext2fs_le16_to_cpu(eh->eh_max) > eh_max) || + (ext2fs_le16_to_cpu(eh->eh_max) < (eh_max - 2))) + return EXT2_ET_EXTENT_HEADER_BAD; + + return 0; +} + + +/* + * Begin functions to handle an inode's extent information + */ +extern void ext2fs_extent_free(ext2_extent_handle_t handle) +{ + int i; + + if (!handle) + return; + + if (handle->path) { + for (i=1; i <= handle->max_depth; i++) { + if (handle->path[i].buf) + ext2fs_free_mem(&handle->path[i].buf); + } + ext2fs_free_mem(&handle->path); + } + ext2fs_free_mem(&handle); +} + +extern errcode_t ext2fs_extent_open(ext2_filsys fs, ext2_ino_t ino, + ext2_extent_handle_t *ret_handle) +{ + return ext2fs_extent_open2(fs, ino, NULL, ret_handle); +} + +extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + ext2_extent_handle_t *ret_handle) +{ + struct ext2_extent_handle *handle; + errcode_t retval; + int i; + struct ext3_extent_header *eh; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!inode) + if ((ino == 0) || (ino > fs->super->s_inodes_count)) + return EXT2_ET_BAD_INODE_NUM; + + retval = ext2fs_get_mem(sizeof(struct ext2_extent_handle), &handle); + if (retval) + return retval; + memset(handle, 0, sizeof(struct ext2_extent_handle)); + + handle->ino = ino; + handle->fs = fs; + + if (inode) { + handle->inode = inode; + } else { + handle->inode = &handle->inodebuf; + retval = ext2fs_read_inode(fs, ino, handle->inode); + if (retval) + goto errout; + } + + eh = (struct ext3_extent_header *) &handle->inode->i_block[0]; + + for (i=0; i < EXT2_N_BLOCKS; i++) + if (handle->inode->i_block[i]) + break; + if (i >= EXT2_N_BLOCKS) { + eh->eh_magic = ext2fs_cpu_to_le16(EXT3_EXT_MAGIC); + eh->eh_depth = 0; + eh->eh_entries = 0; + i = (sizeof(handle->inode->i_block) - sizeof(*eh)) / + sizeof(struct ext3_extent); + eh->eh_max = ext2fs_cpu_to_le16(i); + handle->inode->i_flags |= EXT4_EXTENTS_FL; + } + + if (!(handle->inode->i_flags & EXT4_EXTENTS_FL)) { + retval = EXT2_ET_INODE_NOT_EXTENT; + goto errout; + } + + retval = ext2fs_extent_header_verify(eh, sizeof(handle->inode->i_block)); + if (retval) + goto errout; + + handle->max_depth = ext2fs_le16_to_cpu(eh->eh_depth); + handle->type = ext2fs_le16_to_cpu(eh->eh_magic); + + retval = ext2fs_get_mem(((handle->max_depth+1) * + sizeof(struct extent_path)), + &handle->path); + memset(handle->path, 0, + (handle->max_depth+1) * sizeof(struct extent_path)); + handle->path[0].buf = (char *) handle->inode->i_block; + + handle->path[0].left = handle->path[0].entries = + ext2fs_le16_to_cpu(eh->eh_entries); + handle->path[0].max_entries = ext2fs_le16_to_cpu(eh->eh_max); + handle->path[0].curr = 0; + handle->path[0].end_blk = + ((((__u64) handle->inode->i_size_high << 32) + + handle->inode->i_size + (fs->blocksize - 1)) + >> EXT2_BLOCK_SIZE_BITS(fs->super)); + handle->path[0].visit_num = 1; + handle->level = 0; + handle->magic = EXT2_ET_MAGIC_EXTENT_HANDLE; + + *ret_handle = handle; + return 0; + +errout: + ext2fs_extent_free(handle); + return retval; +} + +/* + * This function is responsible for (optionally) moving through the + * extent tree and then returning the current extent + */ +errcode_t ext2fs_extent_get(ext2_extent_handle_t handle, + int flags, struct ext2fs_extent *extent) +{ + struct extent_path *path, *newpath; + struct ext3_extent_header *eh; + struct ext3_extent_idx *ix = 0; + struct ext3_extent *ex; + errcode_t retval; + blk64_t blk; + blk64_t end_blk; + int orig_op, op; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + + orig_op = op = flags & EXT2_EXTENT_MOVE_MASK; + +retry: + path = handle->path + handle->level; + if ((orig_op == EXT2_EXTENT_NEXT) || + (orig_op == EXT2_EXTENT_NEXT_LEAF)) { + if (handle->level < handle->max_depth) { + /* interior node */ + if (path->visit_num == 0) { + path->visit_num++; + op = EXT2_EXTENT_DOWN; + } else if (path->left > 0) + op = EXT2_EXTENT_NEXT_SIB; + else if (handle->level > 0) + op = EXT2_EXTENT_UP; + else + return EXT2_ET_EXTENT_NO_NEXT; + } else { + /* leaf node */ + if (path->left > 0) + op = EXT2_EXTENT_NEXT_SIB; + else if (handle->level > 0) + op = EXT2_EXTENT_UP; + else + return EXT2_ET_EXTENT_NO_NEXT; + } + if (op != EXT2_EXTENT_NEXT_SIB) { +#ifdef DEBUG_GET_EXTENT + printf("<<<< OP = %s\n", + (op == EXT2_EXTENT_DOWN) ? "down" : + ((op == EXT2_EXTENT_UP) ? "up" : "unknown")); +#endif + } + } + + if ((orig_op == EXT2_EXTENT_PREV) || + (orig_op == EXT2_EXTENT_PREV_LEAF)) { + if (handle->level < handle->max_depth) { + /* interior node */ + if (path->visit_num > 0 ) { + /* path->visit_num = 0; */ + op = EXT2_EXTENT_DOWN_AND_LAST; + } else if (path->left < path->entries-1) + op = EXT2_EXTENT_PREV_SIB; + else if (handle->level > 0) + op = EXT2_EXTENT_UP; + else + return EXT2_ET_EXTENT_NO_PREV; + } else { + /* leaf node */ + if (path->left < path->entries-1) + op = EXT2_EXTENT_PREV_SIB; + else if (handle->level > 0) + op = EXT2_EXTENT_UP; + else + return EXT2_ET_EXTENT_NO_PREV; + } + if (op != EXT2_EXTENT_PREV_SIB) { +#ifdef DEBUG_GET_EXTENT + printf("<<<< OP = %s\n", + (op == EXT2_EXTENT_DOWN_AND_LAST) ? "down/last" : + ((op == EXT2_EXTENT_UP) ? "up" : "unknown")); +#endif + } + } + + if (orig_op == EXT2_EXTENT_LAST_LEAF) { + if ((handle->level < handle->max_depth) && + (path->left == 0)) + op = EXT2_EXTENT_DOWN; + else + op = EXT2_EXTENT_LAST_SIB; +#ifdef DEBUG_GET_EXTENT + printf("<<<< OP = %s\n", + (op == EXT2_EXTENT_DOWN) ? "down" : "last_sib"); +#endif + } + + switch (op) { + case EXT2_EXTENT_CURRENT: + ix = path->curr; + break; + case EXT2_EXTENT_ROOT: + handle->level = 0; + path = handle->path + handle->level; + case EXT2_EXTENT_FIRST_SIB: + path->left = path->entries; + path->curr = 0; + case EXT2_EXTENT_NEXT_SIB: + if (path->left <= 0) + return EXT2_ET_EXTENT_NO_NEXT; + if (path->curr) { + ix = path->curr; + ix++; + } else { + eh = (struct ext3_extent_header *) path->buf; + ix = EXT_FIRST_INDEX(eh); + } + path->left--; + path->curr = ix; + path->visit_num = 0; + break; + case EXT2_EXTENT_PREV_SIB: + if (!path->curr || + path->left+1 >= path->entries) + return EXT2_ET_EXTENT_NO_PREV; + ix = path->curr; + ix--; + path->curr = ix; + path->left++; + if (handle->level < handle->max_depth) + path->visit_num = 1; + break; + case EXT2_EXTENT_LAST_SIB: + eh = (struct ext3_extent_header *) path->buf; + path->curr = EXT_LAST_EXTENT(eh); + ix = path->curr; + path->left = 0; + path->visit_num = 0; + break; + case EXT2_EXTENT_UP: + if (handle->level <= 0) + return EXT2_ET_EXTENT_NO_UP; + handle->level--; + path--; + ix = path->curr; + if ((orig_op == EXT2_EXTENT_PREV) || + (orig_op == EXT2_EXTENT_PREV_LEAF)) + path->visit_num = 0; + break; + case EXT2_EXTENT_DOWN: + case EXT2_EXTENT_DOWN_AND_LAST: + if (!path->curr ||(handle->level >= handle->max_depth)) + return EXT2_ET_EXTENT_NO_DOWN; + + ix = path->curr; + newpath = path + 1; + if (!newpath->buf) { + retval = ext2fs_get_mem(handle->fs->blocksize, + &newpath->buf); + if (retval) + return retval; + } + blk = ext2fs_le32_to_cpu(ix->ei_leaf) + + ((__u64) ext2fs_le16_to_cpu(ix->ei_leaf_hi) << 32); + if ((handle->fs->flags & EXT2_FLAG_IMAGE_FILE) && + (handle->fs->io != handle->fs->image_io)) + memset(newpath->buf, 0, handle->fs->blocksize); + else { + retval = io_channel_read_blk64(handle->fs->io, + blk, 1, newpath->buf); + if (retval) + return retval; + } + handle->level++; + + eh = (struct ext3_extent_header *) newpath->buf; + + retval = ext2fs_extent_header_verify(eh, handle->fs->blocksize); + if (retval) { + handle->level--; + return retval; + } + + newpath->left = newpath->entries = + ext2fs_le16_to_cpu(eh->eh_entries); + newpath->max_entries = ext2fs_le16_to_cpu(eh->eh_max); + + if (path->left > 0) { + ix++; + newpath->end_blk = ext2fs_le32_to_cpu(ix->ei_block); + } else + newpath->end_blk = path->end_blk; + + path = newpath; + if (op == EXT2_EXTENT_DOWN) { + ix = EXT_FIRST_INDEX((struct ext3_extent_header *) eh); + path->curr = ix; + path->left = path->entries - 1; + path->visit_num = 0; + } else { + ix = EXT_LAST_INDEX((struct ext3_extent_header *) eh); + path->curr = ix; + path->left = 0; + if (handle->level < handle->max_depth) + path->visit_num = 1; + } +#ifdef DEBUG_GET_EXTENT + printf("Down to level %d/%d, end_blk=%llu\n", + handle->level, handle->max_depth, + path->end_blk); +#endif + break; + default: + return EXT2_ET_OP_NOT_SUPPORTED; + } + + if (!ix) + return EXT2_ET_NO_CURRENT_NODE; + + extent->e_flags = 0; +#ifdef DEBUG_GET_EXTENT + printf("(Left %d)\n", path->left); +#endif + + if (handle->level == handle->max_depth) { + ex = (struct ext3_extent *) ix; + + extent->e_pblk = ext2fs_le32_to_cpu(ex->ee_start) + + ((__u64) ext2fs_le16_to_cpu(ex->ee_start_hi) << 32); + extent->e_lblk = ext2fs_le32_to_cpu(ex->ee_block); + extent->e_len = ext2fs_le16_to_cpu(ex->ee_len); + extent->e_flags |= EXT2_EXTENT_FLAGS_LEAF; + if (extent->e_len > EXT_INIT_MAX_LEN) { + extent->e_len -= EXT_INIT_MAX_LEN; + extent->e_flags |= EXT2_EXTENT_FLAGS_UNINIT; + } + } else { + extent->e_pblk = ext2fs_le32_to_cpu(ix->ei_leaf) + + ((__u64) ext2fs_le16_to_cpu(ix->ei_leaf_hi) << 32); + extent->e_lblk = ext2fs_le32_to_cpu(ix->ei_block); + if (path->left > 0) { + ix++; + end_blk = ext2fs_le32_to_cpu(ix->ei_block); + } else + end_blk = path->end_blk; + + extent->e_len = end_blk - extent->e_lblk; + } + if (path->visit_num) + extent->e_flags |= EXT2_EXTENT_FLAGS_SECOND_VISIT; + + if (((orig_op == EXT2_EXTENT_NEXT_LEAF) || + (orig_op == EXT2_EXTENT_PREV_LEAF)) && + (handle->level != handle->max_depth)) + goto retry; + + if ((orig_op == EXT2_EXTENT_LAST_LEAF) && + ((handle->level != handle->max_depth) || + (path->left != 0))) + goto retry; + + return 0; +} + +static errcode_t update_path(ext2_extent_handle_t handle) +{ + blk64_t blk; + errcode_t retval; + struct ext3_extent_idx *ix; + + if (handle->level == 0) { + retval = ext2fs_write_inode(handle->fs, handle->ino, + handle->inode); + } else { + ix = handle->path[handle->level - 1].curr; + blk = ext2fs_le32_to_cpu(ix->ei_leaf) + + ((__u64) ext2fs_le16_to_cpu(ix->ei_leaf_hi) << 32); + + retval = io_channel_write_blk64(handle->fs->io, + blk, 1, handle->path[handle->level].buf); + } + return retval; +} + +#if 0 +errcode_t ext2fs_extent_save_path(ext2_extent_handle_t handle, + ext2_extent_path_t *ret_path) +{ + ext2_extent_path_t save_path; + struct ext2fs_extent extent; + struct ext2_extent_info info; + errcode_t retval; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + return retval; + + retval = ext2fs_extent_get_info(handle, &info); + if (retval) + return retval; + + retval = ext2fs_get_mem(sizeof(struct ext2_extent_path), &save_path); + if (retval) + return retval; + memset(save_path, 0, sizeof(struct ext2_extent_path)); + + save_path->magic = EXT2_ET_MAGIC_EXTENT_PATH; + save_path->leaf_height = info.max_depth - info.curr_level - 1; + save_path->lblk = extent.e_lblk; + + *ret_path = save_path; + return 0; +} + +errcode_t ext2fs_extent_free_path(ext2_extent_path_t path) +{ + EXT2_CHECK_MAGIC(path, EXT2_ET_MAGIC_EXTENT_PATH); + + ext2fs_free_mem(&path); + return 0; +} +#endif + +/* + * Go to the node at leaf_level which contains logical block blk. + * + * leaf_level is height from the leaf node level, i.e. + * leaf_level 0 is at leaf node, leaf_level 1 is 1 above etc. + * + * If "blk" has no mapping (hole) then handle is left at last + * extent before blk. + */ +static errcode_t extent_goto(ext2_extent_handle_t handle, + int leaf_level, blk64_t blk) +{ + struct ext2fs_extent extent; + errcode_t retval; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent); + if (retval) { + if (retval == EXT2_ET_EXTENT_NO_NEXT) + retval = EXT2_ET_EXTENT_NOT_FOUND; + return retval; + } + + if (leaf_level > handle->max_depth) { +#ifdef DEBUG + printf("leaf level %d greater than tree depth %d\n", + leaf_level, handle->max_depth); +#endif + return EXT2_ET_OP_NOT_SUPPORTED; + } + +#ifdef DEBUG + printf("goto extent ino %u, level %d, %llu\n", handle->ino, + leaf_level, blk); +#endif + +#ifdef DEBUG_GOTO_EXTENTS + dbg_print_extent("root", &extent); +#endif + while (1) { + if (handle->max_depth - handle->level == leaf_level) { + /* block is in this &extent */ + if ((blk >= extent.e_lblk) && + (blk < extent.e_lblk + extent.e_len)) + return 0; + if (blk < extent.e_lblk) { + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_PREV_SIB, + &extent); + return EXT2_ET_EXTENT_NOT_FOUND; + } + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_NEXT_SIB, + &extent); + if (retval == EXT2_ET_EXTENT_NO_NEXT) + return EXT2_ET_EXTENT_NOT_FOUND; + if (retval) + return retval; + continue; + } + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_SIB, + &extent); + if (retval == EXT2_ET_EXTENT_NO_NEXT) + goto go_down; + if (retval) + return retval; + +#ifdef DEBUG_GOTO_EXTENTS + dbg_print_extent("next", &extent); +#endif + if (blk == extent.e_lblk) + goto go_down; + if (blk > extent.e_lblk) + continue; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_PREV_SIB, + &extent); + if (retval) + return retval; + +#ifdef DEBUG_GOTO_EXTENTS + dbg_print_extent("prev", &extent); +#endif + + go_down: + retval = ext2fs_extent_get(handle, EXT2_EXTENT_DOWN, + &extent); + if (retval) + return retval; + +#ifdef DEBUG_GOTO_EXTENTS + dbg_print_extent("down", &extent); +#endif + } +} + +errcode_t ext2fs_extent_goto(ext2_extent_handle_t handle, + blk64_t blk) +{ + return extent_goto(handle, 0, blk); +} + +/* + * Traverse back up to root fixing parents of current node as needed. + * + * If we changed start of first entry in a node, fix parent index start + * and so on. + * + * Safe to call for any position in node; if not at the first entry, + * will simply return. + */ +static errcode_t ext2fs_extent_fix_parents(ext2_extent_handle_t handle) +{ + int retval = 0; + blk64_t start; + struct extent_path *path; + struct ext2fs_extent extent; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + if (!(handle->fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + + path = handle->path + handle->level; + if (!path->curr) + return EXT2_ET_NO_CURRENT_NODE; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + goto done; + + /* modified node's start block */ + start = extent.e_lblk; + + /* traverse up until index not first, or startblk matches, or top */ + while (handle->level > 0 && + (path->left == path->entries - 1)) { + retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &extent); + if (retval) + goto done; + if (extent.e_lblk == start) + break; + path = handle->path + handle->level; + extent.e_len += (extent.e_lblk - start); + extent.e_lblk = start; + retval = ext2fs_extent_replace(handle, 0, &extent); + if (retval) + goto done; + update_path(handle); + } + + /* put handle back to where we started */ + retval = ext2fs_extent_goto(handle, start); +done: + return retval; +} + +errcode_t ext2fs_extent_replace(ext2_extent_handle_t handle, + int flags EXT2FS_ATTR((unused)), + struct ext2fs_extent *extent) +{ + struct extent_path *path; + struct ext3_extent_idx *ix; + struct ext3_extent *ex; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + if (!(handle->fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + + path = handle->path + handle->level; + if (!path->curr) + return EXT2_ET_NO_CURRENT_NODE; + +#ifdef DEBUG + printf("extent replace: %u ", handle->ino); + dbg_print_extent(0, extent); +#endif + + if (handle->level == handle->max_depth) { + ex = path->curr; + + ex->ee_block = ext2fs_cpu_to_le32(extent->e_lblk); + ex->ee_start = ext2fs_cpu_to_le32(extent->e_pblk & 0xFFFFFFFF); + ex->ee_start_hi = ext2fs_cpu_to_le16(extent->e_pblk >> 32); + if (extent->e_flags & EXT2_EXTENT_FLAGS_UNINIT) { + if (extent->e_len > EXT_UNINIT_MAX_LEN) + return EXT2_ET_EXTENT_INVALID_LENGTH; + ex->ee_len = ext2fs_cpu_to_le16(extent->e_len + + EXT_INIT_MAX_LEN); + } else { + if (extent->e_len > EXT_INIT_MAX_LEN) + return EXT2_ET_EXTENT_INVALID_LENGTH; + ex->ee_len = ext2fs_cpu_to_le16(extent->e_len); + } + } else { + ix = path->curr; + + ix->ei_leaf = ext2fs_cpu_to_le32(extent->e_pblk & 0xFFFFFFFF); + ix->ei_leaf_hi = ext2fs_cpu_to_le16(extent->e_pblk >> 32); + ix->ei_block = ext2fs_cpu_to_le32(extent->e_lblk); + ix->ei_unused = 0; + } + update_path(handle); + return 0; +} + +/* + * allocate a new block, move half the current node to it, and update parent + * + * handle will be left pointing at original record. + */ +static errcode_t extent_node_split(ext2_extent_handle_t handle) +{ + errcode_t retval = 0; + blk64_t new_node_pblk; + blk64_t new_node_start; + blk64_t orig_lblk; + blk64_t goal_blk = 0; + int orig_height; + char *block_buf = NULL; + struct ext2fs_extent extent; + struct extent_path *path, *newpath = 0; + struct ext3_extent_header *eh, *neweh; + int tocopy; + int new_root = 0; + struct ext2_extent_info info; + + /* basic sanity */ + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + if (!(handle->fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + +#ifdef DEBUG + printf("splitting node at level %d\n", handle->level); +#endif + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + goto done; + + retval = ext2fs_extent_get_info(handle, &info); + if (retval) + goto done; + + /* save the position we were originally splitting... */ + orig_height = info.max_depth - info.curr_level; + orig_lblk = extent.e_lblk; + + /* Is there room in the parent for a new entry? */ + if (handle->level && + (handle->path[handle->level - 1].entries >= + handle->path[handle->level - 1].max_entries)) { + +#ifdef DEBUG + printf("parent level %d full; splitting it too\n", + handle->level - 1); +#endif + /* split the parent */ + retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &extent); + if (retval) + goto done; + goal_blk = extent.e_pblk; + + retval = extent_node_split(handle); + if (retval) + goto done; + + /* get handle back to our original split position */ + retval = extent_goto(handle, orig_height, orig_lblk); + if (retval) + goto done; + } + + /* At this point, parent should have room for this split */ + path = handle->path + handle->level; + if (!path->curr) + return EXT2_ET_NO_CURRENT_NODE; + + /* extent header of the current node we'll split */ + eh = (struct ext3_extent_header *)path->buf; + + /* splitting root level means moving them all out */ + if (handle->level == 0) { + new_root = 1; + tocopy = ext2fs_le16_to_cpu(eh->eh_entries); + retval = ext2fs_get_mem(((handle->max_depth+2) * + sizeof(struct extent_path)), + &newpath); + if (retval) + goto done; + memset(newpath, 0, + ((handle->max_depth+2) * sizeof(struct extent_path))); + } else { + tocopy = ext2fs_le16_to_cpu(eh->eh_entries) / 2; + } + +#ifdef DEBUG + printf("will copy out %d of %d entries at level %d\n", + tocopy, ext2fs_le16_to_cpu(eh->eh_entries), + handle->level); +#endif + + if (!tocopy) { +#ifdef DEBUG + printf("Nothing to copy to new block!\n"); +#endif + retval = EXT2_ET_CANT_SPLIT_EXTENT; + goto done; + } + + /* first we need a new block, or can do nothing. */ + block_buf = malloc(handle->fs->blocksize); + if (!block_buf) { + retval = ENOMEM; + goto done; + } + + if (!goal_blk) { + dgrp_t group = ext2fs_group_of_ino(handle->fs, handle->ino); + __u8 log_flex = handle->fs->super->s_log_groups_per_flex; + + if (log_flex) + group = group & ~((1 << (log_flex)) - 1); + goal_blk = (group * handle->fs->super->s_blocks_per_group) + + handle->fs->super->s_first_data_block; + } + retval = ext2fs_alloc_block2(handle->fs, goal_blk, block_buf, + &new_node_pblk); + if (retval) + goto done; + +#ifdef DEBUG + printf("will copy to new node at block %lu\n", + (unsigned long) new_node_pblk); +#endif + + /* Copy data into new block buffer */ + /* First the header for the new block... */ + neweh = (struct ext3_extent_header *) block_buf; + memcpy(neweh, eh, sizeof(struct ext3_extent_header)); + neweh->eh_entries = ext2fs_cpu_to_le16(tocopy); + neweh->eh_max = ext2fs_cpu_to_le16((handle->fs->blocksize - + sizeof(struct ext3_extent_header)) / + sizeof(struct ext3_extent)); + + /* then the entries for the new block... */ + memcpy(EXT_FIRST_INDEX(neweh), + EXT_FIRST_INDEX(eh) + + (ext2fs_le16_to_cpu(eh->eh_entries) - tocopy), + sizeof(struct ext3_extent_idx) * tocopy); + + new_node_start = ext2fs_le32_to_cpu(EXT_FIRST_INDEX(neweh)->ei_block); + + /* ...and write the new node block out to disk. */ + retval = io_channel_write_blk64(handle->fs->io, new_node_pblk, 1, + block_buf); + + if (retval) + goto done; + + /* OK! we've created the new node; now adjust the tree */ + + /* current path now has fewer active entries, we copied some out */ + if (handle->level == 0) { + memcpy(newpath, path, + sizeof(struct extent_path) * (handle->max_depth+1)); + handle->path = newpath; + newpath = path; + path = handle->path; + path->entries = 1; + path->left = path->max_entries - 1; + handle->max_depth++; + eh->eh_depth = ext2fs_cpu_to_le16(handle->max_depth); + } else { + path->entries -= tocopy; + path->left -= tocopy; + } + + eh->eh_entries = ext2fs_cpu_to_le16(path->entries); + /* this writes out the node, incl. the modified header */ + retval = update_path(handle); + if (retval) + goto done; + + /* now go up and insert/replace index for new node we created */ + if (new_root) { + retval = ext2fs_extent_get(handle, EXT2_EXTENT_FIRST_SIB, &extent); + if (retval) + goto done; + + extent.e_lblk = new_node_start; + extent.e_pblk = new_node_pblk; + extent.e_len = handle->path[0].end_blk - extent.e_lblk; + retval = ext2fs_extent_replace(handle, 0, &extent); + if (retval) + goto done; + } else { + __u32 new_node_length; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, &extent); + /* will insert after this one; it's length is shorter now */ + new_node_length = new_node_start - extent.e_lblk; + extent.e_len -= new_node_length; + retval = ext2fs_extent_replace(handle, 0, &extent); + if (retval) + goto done; + + /* now set up the new extent and insert it */ + extent.e_lblk = new_node_start; + extent.e_pblk = new_node_pblk; + extent.e_len = new_node_length; + retval = ext2fs_extent_insert(handle, EXT2_EXTENT_INSERT_AFTER, &extent); + if (retval) + goto done; + } + + /* get handle back to our original position */ + retval = extent_goto(handle, orig_height, orig_lblk); + if (retval) + goto done; + + /* new node hooked in, so update inode block count (do this here?) */ + handle->inode->i_blocks += handle->fs->blocksize / 512; + retval = ext2fs_write_inode(handle->fs, handle->ino, + handle->inode); + if (retval) + goto done; + +done: + if (newpath) + ext2fs_free_mem(&newpath); + free(block_buf); + + return retval; +} + +errcode_t ext2fs_extent_insert(ext2_extent_handle_t handle, int flags, + struct ext2fs_extent *extent) +{ + struct extent_path *path; + struct ext3_extent_idx *ix; + struct ext3_extent_header *eh; + errcode_t retval; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + if (!(handle->fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + +#ifdef DEBUG + printf("extent insert: %u ", handle->ino); + dbg_print_extent(0, extent); +#endif + + path = handle->path + handle->level; + + if (path->entries >= path->max_entries) { + if (flags & EXT2_EXTENT_INSERT_NOSPLIT) { + return EXT2_ET_CANT_INSERT_EXTENT; + } else { +#ifdef DEBUG + printf("node full (level %d) - splitting\n", + handle->level); +#endif + retval = extent_node_split(handle); + if (retval) + return retval; + path = handle->path + handle->level; + } + } + + eh = (struct ext3_extent_header *) path->buf; + if (path->curr) { + ix = path->curr; + if (flags & EXT2_EXTENT_INSERT_AFTER) { + ix++; + path->left--; + } + } else + ix = EXT_FIRST_INDEX(eh); + + path->curr = ix; + + if (path->left >= 0) + memmove(ix + 1, ix, + (path->left+1) * sizeof(struct ext3_extent_idx)); + path->left++; + path->entries++; + + eh = (struct ext3_extent_header *) path->buf; + eh->eh_entries = ext2fs_cpu_to_le16(path->entries); + + retval = ext2fs_extent_replace(handle, 0, extent); + if (retval) + goto errout; + + retval = update_path(handle); + if (retval) + goto errout; + + return 0; + +errout: + ext2fs_extent_delete(handle, 0); + return retval; +} + +/* + * Sets the physical block for a logical file block in the extent tree. + * + * May: map unmapped, unmap mapped, or remap mapped blocks. + * + * Mapping an unmapped block adds a single-block extent. + * + * Unmapping first or last block modifies extent in-place + * - But may need to fix parent's starts too in first-block case + * + * Mapping any unmapped block requires adding a (single-block) extent + * and inserting into proper point in tree. + * + * Modifying (unmapping or remapping) a block in the middle + * of an extent requires splitting the extent. + * - Remapping case requires new single-block extent. + * + * Remapping first or last block adds an extent. + * + * We really need extent adding to be smart about merging. + */ + +errcode_t ext2fs_extent_set_bmap(ext2_extent_handle_t handle, + blk64_t logical, blk64_t physical, int flags) +{ + errcode_t ec, retval = 0; + int mapped = 1; /* logical is mapped? */ + int orig_height; + int extent_uninit = 0; + int prev_uninit = 0; + int next_uninit = 0; + int new_uninit = 0; + int max_len = EXT_INIT_MAX_LEN; + int has_prev, has_next; + blk64_t orig_lblk; + struct extent_path *path; + struct ext2fs_extent extent, next_extent, prev_extent; + struct ext2fs_extent newextent; + struct ext2_extent_info info; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + +#ifdef DEBUG + printf("set_bmap ino %u log %lld phys %lld flags %d\n", + handle->ino, logical, physical, flags); +#endif + + if (!(handle->fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + + path = handle->path + handle->level; + + if (flags & EXT2_EXTENT_SET_BMAP_UNINIT) { + new_uninit = 1; + max_len = EXT_UNINIT_MAX_LEN; + } + + /* if (re)mapping, set up new extent to insert */ + if (physical) { + newextent.e_len = 1; + newextent.e_pblk = physical; + newextent.e_lblk = logical; + newextent.e_flags = EXT2_EXTENT_FLAGS_LEAF; + if (new_uninit) + newextent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; + } + + /* special case if the extent tree is completely empty */ + if ((handle->max_depth == 0) && (path->entries == 0)) { + retval = ext2fs_extent_insert(handle, 0, &newextent); + return retval; + } + + /* save our original location in the extent tree */ + if ((retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, + &extent))) { + if (retval != EXT2_ET_NO_CURRENT_NODE) + return retval; + memset(&extent, 0, sizeof(extent)); + } + if ((retval = ext2fs_extent_get_info(handle, &info))) + return retval; + orig_height = info.max_depth - info.curr_level; + orig_lblk = extent.e_lblk; + + /* go to the logical spot we want to (re/un)map */ + retval = ext2fs_extent_goto(handle, logical); + if (retval) { + if (retval == EXT2_ET_EXTENT_NOT_FOUND) { + retval = 0; + mapped = 0; + if (!physical) { +#ifdef DEBUG + printf("block %llu already unmapped\n", + logical); +#endif + goto done; + } + } else + goto done; + } + + /* + * This may be the extent *before* the requested logical, + * if it's currently unmapped. + * + * Get the previous and next leaf extents, if they are present. + */ + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + goto done; + if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + extent_uninit = 1; + retval = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_LEAF, &next_extent); + if (retval) { + has_next = 0; + if (retval != EXT2_ET_EXTENT_NO_NEXT) + goto done; + } else { + dbg_print_extent("set_bmap: next_extent", + &next_extent); + has_next = 1; + if (next_extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + next_uninit = 1; + } + retval = ext2fs_extent_goto(handle, logical); + if (retval && retval != EXT2_ET_EXTENT_NOT_FOUND) + goto done; + retval = ext2fs_extent_get(handle, EXT2_EXTENT_PREV_LEAF, &prev_extent); + if (retval) { + has_prev = 0; + if (retval != EXT2_ET_EXTENT_NO_PREV) + goto done; + } else { + has_prev = 1; + dbg_print_extent("set_bmap: prev_extent", + &prev_extent); + if (prev_extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + prev_uninit = 1; + } + retval = ext2fs_extent_goto(handle, logical); + if (retval && retval != EXT2_ET_EXTENT_NOT_FOUND) + goto done; + + /* check if already pointing to the requested physical */ + if (mapped && (new_uninit == extent_uninit) && + (extent.e_pblk + (logical - extent.e_lblk) == physical)) { +#ifdef DEBUG + printf("physical block (at %llu) unchanged\n", logical); +#endif + goto done; + } + + if (!mapped) { +#ifdef DEBUG + printf("mapping unmapped logical block %llu\n", logical); +#endif + if ((logical == extent.e_lblk + extent.e_len) && + (physical == extent.e_pblk + extent.e_len) && + (new_uninit == extent_uninit) && + ((int) extent.e_len < max_len-1)) { + extent.e_len++; + retval = ext2fs_extent_replace(handle, 0, &extent); + } else if ((logical == extent.e_lblk - 1) && + (physical == extent.e_pblk - 1) && + (new_uninit == extent_uninit) && + ((int) extent.e_len < max_len - 1)) { + extent.e_len++; + extent.e_lblk--; + extent.e_pblk--; + retval = ext2fs_extent_replace(handle, 0, &extent); + } else if (has_next && + (logical == next_extent.e_lblk - 1) && + (physical == next_extent.e_pblk - 1) && + (new_uninit == next_uninit) && + ((int) next_extent.e_len < max_len - 1)) { + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_NEXT_LEAF, + &next_extent); + if (retval) + goto done; + next_extent.e_len++; + next_extent.e_lblk--; + next_extent.e_pblk--; + retval = ext2fs_extent_replace(handle, 0, &next_extent); + } else if (logical < extent.e_lblk) + retval = ext2fs_extent_insert(handle, 0, &newextent); + else + retval = ext2fs_extent_insert(handle, + EXT2_EXTENT_INSERT_AFTER, &newextent); + if (retval) + goto done; + retval = ext2fs_extent_fix_parents(handle); + if (retval) + goto done; + } else if ((logical == extent.e_lblk) && (extent.e_len == 1)) { +#ifdef DEBUG + printf("(re/un)mapping only block in extent\n"); +#endif + if (physical) { + retval = ext2fs_extent_replace(handle, 0, &newextent); + } else { + retval = ext2fs_extent_delete(handle, 0); + if (retval) + goto done; + ec = ext2fs_extent_fix_parents(handle); + if (ec != EXT2_ET_NO_CURRENT_NODE) + retval = ec; + } + + if (retval) + goto done; + } else if (logical == extent.e_lblk + extent.e_len - 1) { +#ifdef DEBUG + printf("(re/un)mapping last block in extent\n"); +#endif + if (physical) { + if (has_next && + (logical == (next_extent.e_lblk - 1)) && + (physical == (next_extent.e_pblk - 1)) && + (new_uninit == next_uninit) && + ((int) next_extent.e_len < max_len - 1)) { + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_NEXT_LEAF, &next_extent); + if (retval) + goto done; + next_extent.e_len++; + next_extent.e_lblk--; + next_extent.e_pblk--; + retval = ext2fs_extent_replace(handle, 0, + &next_extent); + if (retval) + goto done; + } else + retval = ext2fs_extent_insert(handle, + EXT2_EXTENT_INSERT_AFTER, &newextent); + if (retval) + goto done; + /* Now pointing at inserted extent; move back to prev */ + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_PREV_LEAF, + &extent); + if (retval) + goto done; + } + extent.e_len--; + retval = ext2fs_extent_replace(handle, 0, &extent); + if (retval) + goto done; + } else if (logical == extent.e_lblk) { +#ifdef DEBUG + printf("(re/un)mapping first block in extent\n"); +#endif + if (physical) { + if (has_prev && + (logical == (prev_extent.e_lblk + + prev_extent.e_len)) && + (physical == (prev_extent.e_pblk + + prev_extent.e_len)) && + (new_uninit == prev_uninit) && + ((int) prev_extent.e_len < max_len-1)) { + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_PREV_LEAF, &prev_extent); + if (retval) + goto done; + prev_extent.e_len++; + retval = ext2fs_extent_replace(handle, 0, + &prev_extent); + } else + retval = ext2fs_extent_insert(handle, + 0, &newextent); + if (retval) + goto done; + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_NEXT_LEAF, + &extent); + if (retval) + goto done; + } + extent.e_pblk++; + extent.e_lblk++; + extent.e_len--; + retval = ext2fs_extent_replace(handle, 0, &extent); + if (retval) + goto done; + } else { + __u32 orig_length; + +#ifdef DEBUG + printf("(re/un)mapping in middle of extent\n"); +#endif + /* need to split this extent; later */ + + orig_length = extent.e_len; + + /* shorten pre-split extent */ + extent.e_len = (logical - extent.e_lblk); + retval = ext2fs_extent_replace(handle, 0, &extent); + if (retval) + goto done; + /* insert our new extent, if any */ + if (physical) { + /* insert new extent after current */ + retval = ext2fs_extent_insert(handle, + EXT2_EXTENT_INSERT_AFTER, &newextent); + if (retval) + goto done; + } + /* add post-split extent */ + extent.e_pblk += extent.e_len + 1; + extent.e_lblk += extent.e_len + 1; + extent.e_len = orig_length - extent.e_len - 1; + retval = ext2fs_extent_insert(handle, + EXT2_EXTENT_INSERT_AFTER, &extent); + if (retval) + goto done; + } + +done: + /* get handle back to its position */ + if (orig_height > handle->max_depth) + orig_height = handle->max_depth; /* In case we shortened the tree */ + extent_goto(handle, orig_height, orig_lblk); + return retval; +} + +errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags) +{ + struct extent_path *path; + char *cp; + struct ext3_extent_header *eh; + errcode_t retval = 0; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + if (!(handle->fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (!handle->path) + return EXT2_ET_NO_CURRENT_NODE; + +#ifdef DEBUG + { + struct ext2fs_extent extent; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, + &extent); + if (retval == 0) { + printf("extent delete %u ", handle->ino); + dbg_print_extent(0, &extent); + } + } +#endif + + path = handle->path + handle->level; + if (!path->curr) + return EXT2_ET_NO_CURRENT_NODE; + + cp = path->curr; + + if (path->left) { + memmove(cp, cp + sizeof(struct ext3_extent_idx), + path->left * sizeof(struct ext3_extent_idx)); + path->left--; + } else { + struct ext3_extent_idx *ix = path->curr; + ix--; + path->curr = ix; + } + if (--path->entries == 0) + path->curr = 0; + + /* if non-root node has no entries left, remove it & parent ptr to it */ + if (path->entries == 0 && handle->level) { + if (!(flags & EXT2_EXTENT_DELETE_KEEP_EMPTY)) { + struct ext2fs_extent extent; + + retval = ext2fs_extent_get(handle, EXT2_EXTENT_UP, + &extent); + if (retval) + return retval; + + retval = ext2fs_extent_delete(handle, flags); + handle->inode->i_blocks -= handle->fs->blocksize / 512; + retval = ext2fs_write_inode(handle->fs, handle->ino, + handle->inode); + ext2fs_block_alloc_stats2(handle->fs, + extent.e_pblk, -1); + } + } else { + eh = (struct ext3_extent_header *) path->buf; + eh->eh_entries = ext2fs_cpu_to_le16(path->entries); + if ((path->entries == 0) && (handle->level == 0)) + eh->eh_depth = handle->max_depth = 0; + retval = update_path(handle); + } + return retval; +} + +errcode_t ext2fs_extent_get_info(ext2_extent_handle_t handle, + struct ext2_extent_info *info) +{ + struct extent_path *path; + + EXT2_CHECK_MAGIC(handle, EXT2_ET_MAGIC_EXTENT_HANDLE); + + memset(info, 0, sizeof(struct ext2_extent_info)); + + path = handle->path + handle->level; + if (path) { + if (path->curr) + info->curr_entry = ((char *) path->curr - path->buf) / + sizeof(struct ext3_extent_idx); + else + info->curr_entry = 0; + info->num_entries = path->entries; + info->max_entries = path->max_entries; + info->bytes_avail = (path->max_entries - path->entries) * + sizeof(struct ext3_extent); + } + + info->curr_level = handle->level; + info->max_depth = handle->max_depth; + info->max_lblk = ((__u64) 1 << 32) - 1; + info->max_pblk = ((__u64) 1 << 48) - 1; + info->max_len = (1UL << 15); + info->max_uninit_len = (1UL << 15) - 1; + + return 0; +} + +#ifdef DEBUG + +#include "ss/ss.h" + +#include "debugfs.h" + +/* + * Hook in new commands into debugfs + */ +const char *debug_prog_name = "tst_extents"; +extern ss_request_table extent_cmds; +ss_request_table *extra_cmds = &extent_cmds; + +ext2_ino_t current_ino = 0; +ext2_extent_handle_t current_handle; + +int common_extent_args_process(int argc, char *argv[], int min_argc, + int max_argc, const char *cmd, + const char *usage, int flags) +{ + if (common_args_process(argc, argv, min_argc, max_argc, cmd, + usage, flags)) + return 1; + + if (!current_handle) { + com_err(cmd, 0, "Extent handle not open"); + return 1; + } + return 0; +} + +void do_inode(int argc, char *argv[]) +{ + ext2_ino_t inode; + int i; + struct ext3_extent_header *eh; + errcode_t retval; + + if (check_fs_open(argv[0])) + return; + + if (argc == 1) { + if (current_ino) + printf("Current inode is %d\n", current_ino); + else + printf("No current inode\n"); + return; + } + + if (common_inode_args_process(argc, argv, &inode, 0)) { + return; + } + + current_ino = 0; + + retval = ext2fs_extent_open(current_fs, inode, ¤t_handle); + if (retval) { + com_err(argv[1], retval, "while opening extent handle"); + return; + } + + current_ino = inode; + + printf("Loaded inode %d\n", current_ino); + + return; +} + +void generic_goto_node(char *cmd_name, int op) +{ + struct ext2fs_extent extent; + errcode_t retval; + + if (check_fs_open(cmd_name)) + return; + + if (!current_handle) { + com_err(cmd_name, 0, "Extent handle not open"); + return; + } + + retval = ext2fs_extent_get(current_handle, op, &extent); + if (retval) { + com_err(cmd_name, retval, 0); + return; + } + dbg_print_extent(0, &extent); +} + +void do_current_node(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_CURRENT); +} + +void do_root_node(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_ROOT); +} + +void do_last_leaf(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_LAST_LEAF); +} + +void do_first_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_FIRST_SIB); +} + +void do_last_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_LAST_SIB); +} + +void do_next_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_NEXT_SIB); +} + +void do_prev_sib(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_PREV_SIB); +} + +void do_next_leaf(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_NEXT_LEAF); +} + +void do_prev_leaf(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_PREV_LEAF); +} + +void do_next(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_NEXT); +} + +void do_prev(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_PREV); +} + +void do_up(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_UP); +} + +void do_down(int argc, char *argv[]) +{ + generic_goto_node(argv[0], EXT2_EXTENT_DOWN); +} + +void do_delete_node(int argc, char *argv[]) +{ + errcode_t retval; + int err; + + if (common_extent_args_process(argc, argv, 1, 1, "delete_node", + "", CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + retval = ext2fs_extent_delete(current_handle, 0); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + if (current_handle->path && current_handle->path[0].curr) + do_current_node(argc, argv); +} + +void do_replace_node(int argc, char *argv[]) +{ + const char *usage = "[--uninit] "; + errcode_t retval; + struct ext2fs_extent extent; + int err; + + if (common_extent_args_process(argc, argv, 3, 5, "replace_node", + usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + extent.e_flags = 0; + + if (!strcmp(argv[1], "--uninit")) { + argc--; + argv++; + extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; + } + + if (argc != 4) { + fprintf(stderr, "Usage: %s %s\n", argv[0], usage); + return; + } + + extent.e_lblk = parse_ulong(argv[1], argv[0], "logical block", &err); + if (err) + return; + + extent.e_len = parse_ulong(argv[2], argv[0], "logical block", &err); + if (err) + return; + + extent.e_pblk = parse_ulong(argv[3], argv[0], "logical block", &err); + if (err) + return; + + retval = ext2fs_extent_replace(current_handle, 0, &extent); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + do_current_node(argc, argv); +} + +void do_split_node(int argc, char *argv[]) +{ + errcode_t retval; + struct ext2fs_extent extent; + int err; + + if (common_extent_args_process(argc, argv, 1, 1, "split_node", + "", CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + retval = extent_node_split(current_handle); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + do_current_node(argc, argv); +} + +void do_insert_node(int argc, char *argv[]) +{ + const char *usage = "[--after] [--uninit] "; + errcode_t retval; + struct ext2fs_extent extent; + char *cmd; + int err; + int flags = 0; + + if (common_extent_args_process(argc, argv, 3, 6, "insert_node", + usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + cmd = argv[0]; + + extent.e_flags = 0; + + while (argc > 2) { + if (!strcmp(argv[1], "--after")) { + argc--; + argv++; + flags |= EXT2_EXTENT_INSERT_AFTER; + continue; + } + if (!strcmp(argv[1], "--uninit")) { + argc--; + argv++; + extent.e_flags |= EXT2_EXTENT_FLAGS_UNINIT; + continue; + } + break; + } + + if (argc != 4) { + fprintf(stderr, "usage: %s %s\n", cmd, usage); + return; + } + + extent.e_lblk = parse_ulong(argv[1], cmd, + "logical block", &err); + if (err) + return; + + extent.e_len = parse_ulong(argv[2], cmd, + "length", &err); + if (err) + return; + + extent.e_pblk = parse_ulong(argv[3], cmd, + "pysical block", &err); + if (err) + return; + + retval = ext2fs_extent_insert(current_handle, flags, &extent); + if (retval) { + com_err(cmd, retval, 0); + return; + } + do_current_node(argc, argv); +} + +void do_set_bmap(int argc, char **argv) +{ + const char *usage = "[--uninit] "; + errcode_t retval; + blk_t logical; + blk_t physical; + char *cmd = argv[0]; + int flags = 0; + int err; + + if (common_extent_args_process(argc, argv, 3, 5, "set_bmap", + usage, CHECK_FS_RW | CHECK_FS_BITMAPS)) + return; + + if (argc > 2 && !strcmp(argv[1], "--uninit")) { + argc--; + argv++; + flags |= EXT2_EXTENT_SET_BMAP_UNINIT; + } + + if (argc != 3) { + fprintf(stderr, "Usage: %s %s\n", cmd, usage); + return; + } + + logical = parse_ulong(argv[1], cmd, + "logical block", &err); + if (err) + return; + + physical = parse_ulong(argv[2], cmd, + "physical block", &err); + if (err) + return; + + retval = ext2fs_extent_set_bmap(current_handle, logical, + (blk64_t) physical, flags); + if (retval) { + com_err(cmd, retval, 0); + return; + } + if (current_handle->path && current_handle->path[0].curr) + do_current_node(argc, argv); +} + +void do_print_all(int argc, char **argv) +{ + const char *usage = "[--leaf-only|--reverse|--reverse-leaf]"; + struct ext2fs_extent extent; + errcode_t retval; + errcode_t end_err = EXT2_ET_EXTENT_NO_NEXT; + int op = EXT2_EXTENT_NEXT; + int first_op = EXT2_EXTENT_ROOT; + + + if (common_extent_args_process(argc, argv, 1, 2, "print_all", + usage, 0)) + return; + + if (argc == 2) { + if (!strcmp(argv[1], "--leaf-only")) + op = EXT2_EXTENT_NEXT_LEAF; + else if (!strcmp(argv[1], "--reverse")) { + op = EXT2_EXTENT_PREV; + first_op = EXT2_EXTENT_LAST_LEAF; + end_err = EXT2_ET_EXTENT_NO_PREV; + } else if (!strcmp(argv[1], "--reverse-leaf")) { + op = EXT2_EXTENT_PREV_LEAF; + first_op = EXT2_EXTENT_LAST_LEAF; + end_err = EXT2_ET_EXTENT_NO_PREV; + } else { + fprintf(stderr, "Usage: %s %s\n", argv[0], usage); + return; + } + } + + retval = ext2fs_extent_get(current_handle, first_op, &extent); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + dbg_print_extent(0, &extent); + + while (1) { + retval = ext2fs_extent_get(current_handle, op, &extent); + if (retval == end_err) + break; + + if (retval) { + com_err(argv[0], retval, 0); + return; + } + dbg_print_extent(0, &extent); + } +} + +void do_info(int argc, char **argv) +{ + struct ext2fs_extent extent; + struct ext2_extent_info info; + errcode_t retval; + + if (common_extent_args_process(argc, argv, 1, 1, "info", "", 0)) + return; + + retval = ext2fs_extent_get_info(current_handle, &info); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + + retval = ext2fs_extent_get(current_handle, + EXT2_EXTENT_CURRENT, &extent); + if (retval) { + com_err(argv[0], retval, 0); + return; + } + + dbg_print_extent(0, &extent); + + printf("Current handle location: %d/%d (max: %d, bytes %d), level %d/%d\n", + info.curr_entry, info.num_entries, info.max_entries, + info.bytes_avail, info.curr_level, info.max_depth); + printf("\tmax lblk: %llu, max pblk: %llu\n", info.max_lblk, + info.max_pblk); + printf("\tmax_len: %u, max_uninit_len: %u\n", info.max_len, + info.max_uninit_len); +} + +void do_goto_block(int argc, char **argv) +{ + struct ext2fs_extent extent; + errcode_t retval; + int op = EXT2_EXTENT_NEXT_LEAF; + blk64_t blk; + int level = 0, err; + + if (common_extent_args_process(argc, argv, 2, 3, "goto_block", + "block [level]", 0)) + return; + + if (strtoblk(argv[0], argv[1], &blk)) + return; + + if (argc == 3) { + level = parse_ulong(argv[2], argv[0], "level", &err); + if (err) + return; + } + + retval = extent_goto(current_handle, level, (blk64_t) blk); + + if (retval) { + com_err(argv[0], retval, + "while trying to go to block %llu, level %d", + (unsigned long long) blk, level); + return; + } + + generic_goto_node(argv[0], EXT2_EXTENT_CURRENT); +} +#endif + diff --git a/libcustomext2fs/source/fiemap.h b/libcustomext2fs/source/fiemap.h new file mode 100644 index 00000000..30bf5555 --- /dev/null +++ b/libcustomext2fs/source/fiemap.h @@ -0,0 +1,68 @@ +/* + * FS_IOC_FIEMAP ioctl infrastructure. + * + * Some portions copyright (C) 2007 Cluster File Systems, Inc + * + * Authors: Mark Fasheh + * Kalpak Shah + * Andreas Dilger + */ + +#ifndef _LINUX_FIEMAP_H +#define _LINUX_FIEMAP_H + +struct fiemap_extent { + __u64 fe_logical; /* logical offset in bytes for the start of + * the extent from the beginning of the file */ + __u64 fe_physical; /* physical offset in bytes for the start + * of the extent from the beginning of the disk */ + __u64 fe_length; /* length in bytes for this extent */ + __u64 fe_reserved64[2]; + __u32 fe_flags; /* FIEMAP_EXTENT_* flags for this extent */ + __u32 fe_reserved[3]; +}; + +struct fiemap { + __u64 fm_start; /* logical offset (inclusive) at + * which to start mapping (in) */ + __u64 fm_length; /* logical length of mapping which + * userspace wants (in) */ + __u32 fm_flags; /* FIEMAP_FLAG_* flags for request (in/out) */ + __u32 fm_mapped_extents;/* number of extents that were mapped (out) */ + __u32 fm_extent_count; /* size of fm_extents array (in) */ + __u32 fm_reserved; + struct fiemap_extent fm_extents[0]; /* array of mapped extents (out) */ +}; + +#ifndef FS_IOC_FIEMAP +#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) +#endif + +#define FIEMAP_MAX_OFFSET (~0ULL) + +#define FIEMAP_FLAG_SYNC 0x00000001 /* sync file data before map */ +#define FIEMAP_FLAG_XATTR 0x00000002 /* map extended attribute tree */ + +#define FIEMAP_FLAGS_COMPAT (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR) + +#define FIEMAP_EXTENT_LAST 0x00000001 /* Last extent in file. */ +#define FIEMAP_EXTENT_UNKNOWN 0x00000002 /* Data location unknown. */ +#define FIEMAP_EXTENT_DELALLOC 0x00000004 /* Location still pending. + * Sets EXTENT_UNKNOWN. */ +#define FIEMAP_EXTENT_ENCODED 0x00000008 /* Data can not be read + * while fs is unmounted */ +#define FIEMAP_EXTENT_DATA_ENCRYPTED 0x00000080 /* Data is encrypted by fs. + * Sets EXTENT_NO_BYPASS. */ +#define FIEMAP_EXTENT_NOT_ALIGNED 0x00000100 /* Extent offsets may not be + * block aligned. */ +#define FIEMAP_EXTENT_DATA_INLINE 0x00000200 /* Data mixed with metadata. + * Sets EXTENT_NOT_ALIGNED.*/ +#define FIEMAP_EXTENT_DATA_TAIL 0x00000400 /* Multiple files in block. + * Sets EXTENT_NOT_ALIGNED.*/ +#define FIEMAP_EXTENT_UNWRITTEN 0x00000800 /* Space allocated, but + * no data (i.e. zero). */ +#define FIEMAP_EXTENT_MERGED 0x00001000 /* File does not natively + * support extents. Result + * merged for efficiency. */ + +#endif /* _LINUX_FIEMAP_H */ diff --git a/libcustomext2fs/source/fileio.c b/libcustomext2fs/source/fileio.c new file mode 100644 index 00000000..44c859b9 --- /dev/null +++ b/libcustomext2fs/source/fileio.c @@ -0,0 +1,412 @@ +/* + * fileio.c --- Simple file I/O routines + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct ext2_file { + errcode_t magic; + ext2_filsys fs; + ext2_ino_t ino; + struct ext2_inode inode; + int flags; + __u64 pos; + blk64_t blockno; + blk64_t physblock; + char *buf; +}; + +#define BMAP_BUFFER (file->buf + fs->blocksize) + +errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + int flags, ext2_file_t *ret) +{ + ext2_file_t file; + errcode_t retval; + + /* + * Don't let caller create or open a file for writing if the + * filesystem is read-only. + */ + if ((flags & (EXT2_FILE_WRITE | EXT2_FILE_CREATE)) && + !(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + retval = ext2fs_get_mem(sizeof(struct ext2_file), &file); + if (retval) + return retval; + + memset(file, 0, sizeof(struct ext2_file)); + file->magic = EXT2_ET_MAGIC_EXT2_FILE; + file->fs = fs; + file->ino = ino; + file->flags = flags & EXT2_FILE_MASK; + + if (inode) { + memcpy(&file->inode, inode, sizeof(struct ext2_inode)); + } else { + retval = ext2fs_read_inode(fs, ino, &file->inode); + if (retval) + goto fail; + } + + retval = ext2fs_get_array(3, fs->blocksize, &file->buf); + if (retval) + goto fail; + + *ret = file; + return 0; + +fail: + if (file->buf) + ext2fs_free_mem(&file->buf); + ext2fs_free_mem(&file); + return retval; +} + +errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino, + int flags, ext2_file_t *ret) +{ + return ext2fs_file_open2(fs, ino, NULL, flags, ret); +} + +/* + * This function returns the filesystem handle of a file from the structure + */ +ext2_filsys ext2fs_file_get_fs(ext2_file_t file) +{ + if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) + return 0; + return file->fs; +} + +/* + * This function returns the pointer to the inode of a file from the structure + */ +struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file) +{ + if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) + return NULL; + return &file->inode; +} + +/* + * This function flushes the dirty block buffer out to disk if + * necessary. + */ +errcode_t ext2fs_file_flush(ext2_file_t file) +{ + errcode_t retval; + ext2_filsys fs; + + EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); + fs = file->fs; + + if (!(file->flags & EXT2_FILE_BUF_VALID) || + !(file->flags & EXT2_FILE_BUF_DIRTY)) + return 0; + + // Flushing out the new size - Dimok + ext2fs_write_inode(file->fs, file->ino, &file->inode); + + /* + * OK, the physical block hasn't been allocated yet. + * Allocate it. + */ + if (!file->physblock) { + retval = ext2fs_bmap2(fs, file->ino, &file->inode, + BMAP_BUFFER, file->ino ? BMAP_ALLOC : 0, + file->blockno, 0, &file->physblock); + if (retval) + return retval; + } + + retval = io_channel_write_blk(fs->io, file->physblock, + 1, file->buf); + if (retval) + return retval; + + file->flags &= ~EXT2_FILE_BUF_DIRTY; + + return retval; +} + +/* + * This function synchronizes the file's block buffer and the current + * file position, possibly invalidating block buffer if necessary + */ +static errcode_t sync_buffer_position(ext2_file_t file) +{ + blk_t b; + errcode_t retval; + + b = file->pos / file->fs->blocksize; + if (b != file->blockno) { + retval = ext2fs_file_flush(file); + if (retval) + return retval; + file->flags &= ~EXT2_FILE_BUF_VALID; + } + file->blockno = b; + return 0; +} + +/* + * This function loads the file's block buffer with valid data from + * the disk as necessary. + * + * If dontfill is true, then skip initializing the buffer since we're + * going to be replacing its entire contents anyway. If set, then the + * function basically only sets file->physblock and EXT2_FILE_BUF_VALID + */ +#define DONTFILL 1 +static errcode_t load_buffer(ext2_file_t file, int dontfill) +{ + ext2_filsys fs = file->fs; + errcode_t retval; + + if (!(file->flags & EXT2_FILE_BUF_VALID)) { + retval = ext2fs_bmap2(fs, file->ino, &file->inode, + BMAP_BUFFER, 0, file->blockno, 0, + &file->physblock); + if (retval) + return retval; + if (!dontfill) { + if (file->physblock) { + retval = io_channel_read_blk(fs->io, + file->physblock, + 1, file->buf); + if (retval) + return retval; + } else + memset(file->buf, 0, fs->blocksize); + } + file->flags |= EXT2_FILE_BUF_VALID; + } + return 0; +} + + +errcode_t ext2fs_file_close(ext2_file_t file) +{ + errcode_t retval; + + EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); + + retval = ext2fs_file_flush(file); + + if (file->buf) + ext2fs_free_mem(&file->buf); + ext2fs_free_mem(&file); + + return retval; +} + + +errcode_t ext2fs_file_read(ext2_file_t file, void *buf, + unsigned int wanted, unsigned int *got) +{ + ext2_filsys fs; + errcode_t retval = 0; + unsigned int start, c, count = 0; + __u64 left; + char *ptr = (char *) buf; + + EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); + fs = file->fs; + + while ((file->pos < EXT2_I_SIZE(&file->inode)) && (wanted > 0)) { + retval = sync_buffer_position(file); + if (retval) + goto fail; + retval = load_buffer(file, 0); + if (retval) + goto fail; + + start = file->pos % fs->blocksize; + c = fs->blocksize - start; + if (c > wanted) + c = wanted; + left = EXT2_I_SIZE(&file->inode) - file->pos ; + if (c > left) + c = left; + + memcpy(ptr, file->buf+start, c); + file->pos += c; + ptr += c; + count += c; + wanted -= c; + } + +fail: + if (got) + *got = count; + return retval; +} + + +errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, + unsigned int nbytes, unsigned int *written) +{ + ext2_filsys fs; + errcode_t retval = 0; + unsigned int start, c, count = 0; + const char *ptr = (const char *) buf; + + EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); + fs = file->fs; + + if (!(file->flags & EXT2_FILE_WRITE)) + return EXT2_ET_FILE_RO; + + while (nbytes > 0) { + retval = sync_buffer_position(file); + if (retval) + goto fail; + + start = file->pos % fs->blocksize; + c = fs->blocksize - start; + if (c > nbytes) + c = nbytes; + + /* + * We only need to do a read-modify-update cycle if + * we're doing a partial write. + */ + retval = load_buffer(file, (c == fs->blocksize)); + if (retval) + goto fail; + + file->flags |= EXT2_FILE_BUF_DIRTY; + memcpy(file->buf+start, ptr, c); + file->pos += c; + ptr += c; + count += c; + nbytes -= c; + } + + // I don't see why changing size is my duty - Dimok + if(EXT2_I_SIZE(&file->inode) < file->pos) + { + file->inode.i_size = file->pos & 0xFFFFFFFF; + file->inode.i_size_high = (file->pos >> 32) & 0xFFFFFFFF; + } + +fail: + if (written) + *written = count; + return retval; +} + +errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset, + int whence, __u64 *ret_pos) +{ + EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); + + if (whence == EXT2_SEEK_SET) + file->pos = offset; + else if (whence == EXT2_SEEK_CUR) + file->pos += offset; + else if (whence == EXT2_SEEK_END) + file->pos = EXT2_I_SIZE(&file->inode) + offset; + else + return EXT2_ET_INVALID_ARGUMENT; + + if (ret_pos) + *ret_pos = file->pos; + + return 0; +} + +errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset, + int whence, ext2_off_t *ret_pos) +{ + __u64 loffset, ret_loffset = 0; + errcode_t retval; + + loffset = offset; + retval = ext2fs_file_llseek(file, loffset, whence, &ret_loffset); + if (ret_pos) + *ret_pos = (ext2_off_t) ret_loffset; + return retval; +} + + +/* + * This function returns the size of the file, according to the inode + */ +errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size) +{ + if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) + return EXT2_ET_MAGIC_EXT2_FILE; + *ret_size = EXT2_I_SIZE(&file->inode); + return 0; +} + +/* + * This function returns the size of the file, according to the inode + */ +ext2_off_t ext2fs_file_get_size(ext2_file_t file) +{ + __u64 size; + + if (ext2fs_file_get_lsize(file, &size)) + return 0; + if ((size >> 32) != 0) + return 0; + return size; +} + +/* + * This function sets the size of the file, truncating it if necessary + * + */ +errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size) +{ + ext2_off64_t old_size; + errcode_t retval; + blk64_t old_truncate, truncate_block; + + EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); + + truncate_block = ((size + file->fs->blocksize - 1) >> + EXT2_BLOCK_SIZE_BITS(file->fs->super)) + 1; + old_size = file->inode.i_size + + (((blk64_t) file->inode.i_size_high) << 32); + old_truncate = ((old_size + file->fs->blocksize - 1) >> + EXT2_BLOCK_SIZE_BITS(file->fs->super)) + 1; + + file->inode.i_size = size & 0xffffffff; + file->inode.i_size_high = (size >> 32); + if (file->ino) { + retval = ext2fs_write_inode(file->fs, file->ino, &file->inode); + if (retval) + return retval; + } + + if (truncate_block <= old_truncate) + return 0; + + return ext2fs_punch(file->fs, file->ino, &file->inode, 0, + truncate_block, ~0ULL); +} + +errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size) +{ + return ext2fs_file_set_size2(file, size); +} diff --git a/libcustomext2fs/source/finddev.c b/libcustomext2fs/source/finddev.c new file mode 100644 index 00000000..cc2029f2 --- /dev/null +++ b/libcustomext2fs/source/finddev.c @@ -0,0 +1,208 @@ +/* + * finddev.c -- this routine attempts to find a particular device in + * /dev + * + * Copyright (C) 2000 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_SYS_STAT_H +#include +#endif +#include +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_SYS_MKDEV_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct dir_list { + char *name; + struct dir_list *next; +}; + +/* + * This function adds an entry to the directory list + */ +static void add_to_dirlist(const char *name, struct dir_list **list) +{ + struct dir_list *dp; + + dp = malloc(sizeof(struct dir_list)); + if (!dp) + return; + dp->name = malloc(strlen(name)+1); + if (!dp->name) { + free(dp); + return; + } + strcpy(dp->name, name); + dp->next = *list; + *list = dp; +} + +/* + * This function frees a directory list + */ +static void free_dirlist(struct dir_list **list) +{ + struct dir_list *dp, *next; + + for (dp = *list; dp; dp = next) { + next = dp->next; + free(dp->name); + free(dp); + } + *list = 0; +} + +static int scan_dir(char *dirname, dev_t device, struct dir_list **list, + char **ret_path) +{ + DIR *dir; + struct dirent *dp; + char path[1024], *cp; + int dirlen; + struct stat st; + + dirlen = strlen(dirname); + if ((dir = opendir(dirname)) == NULL) + return errno; + dp = readdir(dir); + while (dp) { + if (dirlen + strlen(dp->d_name) + 2 >= sizeof(path)) + goto skip_to_next; + if (dp->d_name[0] == '.' && + ((dp->d_name[1] == 0) || + ((dp->d_name[1] == '.') && (dp->d_name[2] == 0)))) + goto skip_to_next; + sprintf(path, "%s/%s", dirname, dp->d_name); + if (stat(path, &st) < 0) + goto skip_to_next; + if (S_ISDIR(st.st_mode)) + add_to_dirlist(path, list); + if (S_ISBLK(st.st_mode) && st.st_rdev == device) { + cp = malloc(strlen(path)+1); + if (!cp) { + closedir(dir); + return ENOMEM; + } + strcpy(cp, path); + *ret_path = cp; + goto success; + } + skip_to_next: + dp = readdir(dir); + } +success: + closedir(dir); + return 0; +} + +/* + * This function finds the pathname to a block device with a given + * device number. It returns a pointer to allocated memory to the + * pathname on success, and NULL on failure. + */ +char *ext2fs_find_block_device(dev_t device) +{ + struct dir_list *list = 0, *new_list = 0; + struct dir_list *current; + char *ret_path = 0; + + /* + * Add the starting directories to search... + */ + add_to_dirlist("/devices", &list); + add_to_dirlist("/devfs", &list); + add_to_dirlist("/dev", &list); + + while (list) { + current = list; + list = list->next; +#ifdef DEBUG + printf("Scanning directory %s\n", current->name); +#endif + scan_dir(current->name, device, &new_list, &ret_path); + free(current->name); + free(current); + if (ret_path) + break; + /* + * If we're done checking at this level, descend to + * the next level of subdirectories. (breadth-first) + */ + if (list == 0) { + list = new_list; + new_list = 0; + } + } + free_dirlist(&list); + free_dirlist(&new_list); + return ret_path; +} + + +#ifdef DEBUG +int main(int argc, char** argv) +{ + char *devname, *tmp; + int major, minor; + dev_t device; + const char *errmsg = "Couldn't parse %s: %s\n"; + + if ((argc != 2) && (argc != 3)) { + fprintf(stderr, "Usage: %s device_number\n", argv[0]); + fprintf(stderr, "\t: %s major minor\n", argv[0]); + exit(1); + } + if (argc == 2) { + device = strtoul(argv[1], &tmp, 0); + if (*tmp) { + fprintf(stderr, errmsg, "device number", argv[1]); + exit(1); + } + } else { + major = strtoul(argv[1], &tmp, 0); + if (*tmp) { + fprintf(stderr, errmsg, "major number", argv[1]); + exit(1); + } + minor = strtoul(argv[2], &tmp, 0); + if (*tmp) { + fprintf(stderr, errmsg, "minor number", argv[2]); + exit(1); + } + device = makedev(major, minor); + printf("Looking for device 0x%04x (%d:%d)\n", device, + major, minor); + } + devname = ext2fs_find_block_device(device); + if (devname) { + printf("Found device! %s\n", devname); + free(devname); + } else { + printf("Couldn't find device.\n"); + } + return 0; +} + +#endif diff --git a/libcustomext2fs/source/flushb.c b/libcustomext2fs/source/flushb.c new file mode 100644 index 00000000..b6f161b6 --- /dev/null +++ b/libcustomext2fs/source/flushb.c @@ -0,0 +1,74 @@ +/* + * flushb.c --- Hides system-dependent information for both syncing a + * device to disk and to flush any buffers from disk cache. + * + * Copyright (C) 2000 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_SYS_IOCTL_H +#include +#endif +#if HAVE_SYS_MOUNT_H +#include +#include /* This may define BLKFLSBUF */ +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * For Linux, define BLKFLSBUF and FDFLUSH if necessary, since + * not all portable header file does so for us. This really should be + * fixed in the glibc header files. (Recent glibcs appear to define + * BLKFLSBUF in sys/mount.h, but FDFLUSH still doesn't seem to be + * defined anywhere portable.) Until then.... + */ +#ifdef __linux__ +#ifndef BLKFLSBUF +#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ +#endif +#ifndef FDFLUSH +#define FDFLUSH _IO(2,0x4b) /* flush floppy disk */ +#endif +#endif + +/* + * This function will sync a device/file, and optionally attempt to + * flush the buffer cache. The latter is basically only useful for + * system benchmarks and for torturing systems in burn-in tests. :) + */ +errcode_t ext2fs_sync_device(int fd, int flushb) +{ + /* + * We always sync the device in case we're running on old + * kernels for which we can lose data if we don't. (There + * still is a race condition for those kernels, but this + * reduces it greatly.) + */ + if (fsync (fd) == -1) + return errno; + + if (flushb) { + +#ifdef BLKFLSBUF + if (ioctl (fd, BLKFLSBUF, 0) == 0) + return 0; +#endif +#ifdef FDFLUSH + ioctl (fd, FDFLUSH, 0); /* In case this is a floppy */ +#endif + } + return 0; +} diff --git a/libcustomext2fs/source/freefs.c b/libcustomext2fs/source/freefs.c new file mode 100644 index 00000000..5c35bb68 --- /dev/null +++ b/libcustomext2fs/source/freefs.c @@ -0,0 +1,112 @@ +/* + * freefs.c --- free an ext2 filesystem + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" + +static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache); + +void ext2fs_free(ext2_filsys fs) +{ + if (!fs || (fs->magic != EXT2_ET_MAGIC_EXT2FS_FILSYS)) + return; + if (fs->image_io != fs->io) { + if (fs->image_io) + io_channel_close(fs->image_io); + } + if (fs->io) { + io_channel_close(fs->io); + } + if (fs->device_name) + ext2fs_free_mem(&fs->device_name); + if (fs->super) + ext2fs_free_mem(&fs->super); + if (fs->orig_super) + ext2fs_free_mem(&fs->orig_super); + if (fs->group_desc) + ext2fs_free_mem(&fs->group_desc); + if (fs->block_map) + ext2fs_free_block_bitmap(fs->block_map); + if (fs->inode_map) + ext2fs_free_inode_bitmap(fs->inode_map); + + if (fs->badblocks) + ext2fs_badblocks_list_free(fs->badblocks); + fs->badblocks = 0; + + if (fs->dblist) + ext2fs_free_dblist(fs->dblist); + + if (fs->icache) + ext2fs_free_inode_cache(fs->icache); + + fs->magic = 0; + + ext2fs_free_mem(&fs); +} + +/* + * Free the inode cache structure + */ +static void ext2fs_free_inode_cache(struct ext2_inode_cache *icache) +{ + if (--icache->refcount) + return; + if (icache->buffer) + ext2fs_free_mem(&icache->buffer); + if (icache->cache) + ext2fs_free_mem(&icache->cache); + icache->buffer_blk = 0; + ext2fs_free_mem(&icache); +} + +/* + * This procedure frees a badblocks list. + */ +void ext2fs_u32_list_free(ext2_u32_list bb) +{ + if (bb->magic != EXT2_ET_MAGIC_BADBLOCKS_LIST) + return; + + if (bb->list) + ext2fs_free_mem(&bb->list); + bb->list = 0; + ext2fs_free_mem(&bb); +} + +void ext2fs_badblocks_list_free(ext2_badblocks_list bb) +{ + ext2fs_u32_list_free((ext2_u32_list) bb); +} + + +/* + * Free a directory block list + */ +void ext2fs_free_dblist(ext2_dblist dblist) +{ + if (!dblist || (dblist->magic != EXT2_ET_MAGIC_DBLIST)) + return; + + if (dblist->list) + ext2fs_free_mem(&dblist->list); + dblist->list = 0; + if (dblist->fs && dblist->fs->dblist == dblist) + dblist->fs->dblist = 0; + dblist->magic = 0; + ext2fs_free_mem(&dblist); +} + diff --git a/libcustomext2fs/source/gekko_io.c b/libcustomext2fs/source/gekko_io.c new file mode 100644 index 00000000..97da1d9f --- /dev/null +++ b/libcustomext2fs/source/gekko_io.c @@ -0,0 +1,561 @@ +/** + * gekko_io.c - Gekko style disk io functions. + * + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gekko_io.h" +#include "bitops.h" +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2_internal.h" +#include "disc_cache.h" +#include "mem_allocate.h" + +#define DEV_FD(dev) ((gekko_fd *) dev->private_data) + +/* Prototypes */ +static s64 device_gekko_io_readbytes(io_channel dev, s64 offset, s64 count, void *buf); +static bool device_gekko_io_readsectors(io_channel dev, sec_t sector, sec_t numSectors, void* buffer); +static s64 device_gekko_io_writebytes(io_channel dev, s64 offset, s64 count, const void *buf); +static bool device_gekko_io_writesectors(io_channel dev, sec_t sector, sec_t numSectors, const void* buffer); + +/** + * + */ +static errcode_t device_gekko_io_open(const char *name, int flags, io_channel *dev) +{ + // Get the device driver descriptor + gekko_fd *fd = DEV_FD((*dev)); + if (!fd) { + errno = EBADF; + return -1; + } + + // Get the device interface + const DISC_INTERFACE* interface = fd->interface; + if (!interface) { + errno = ENODEV; + return -1; + } + + // Start the device interface and ensure that it is inserted + if (!interface->startup()) { + ext2_log_trace("device failed to start\n"); + errno = EIO; + return -1; + } + if (!interface->isInserted()) { + ext2_log_trace("device media is not inserted\n"); + errno = EIO; + return -1; + } + + struct ext2_super_block * super = (struct ext2_super_block *) mem_alloc(SUPERBLOCK_SIZE); //1024 bytes + if(!super) + { + ext2_log_trace("no memory for superblock"); + errno = ENOMEM; + return -1; + } + + // Check that there is a valid EXT boot sector at the start of the device + if (!interface->readSectors(fd->startSector+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + { + ext2_log_trace("read failure @ sector %d\n", fd->startSector); + errno = EROFS; + mem_free(super); + return -1; + } + + if(ext2fs_le16_to_cpu(super->s_magic) != EXT2_SUPER_MAGIC) + { + mem_free(super); + errno = EROFS; + return -1; + } + + // Parse the boot sector + fd->sectorSize = BYTES_PER_SECTOR; + fd->offset = 0; + fd->sectorCount = 0; + + switch(ext2fs_le32_to_cpu(super->s_log_block_size)) + { + case 1: + fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 2048 / (u64) BYTES_PER_SECTOR); + break; + case 2: + fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 4096 / (u64) BYTES_PER_SECTOR); + break; + case 3: + fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 8192 / (u64) BYTES_PER_SECTOR); + break; + default: + case 0: + fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 1024 / (u64) BYTES_PER_SECTOR); + break; + } + + mem_free(super); + + // Create the cache + fd->cache = cache_constructor(fd->cachePageCount, fd->cachePageSize, interface, fd->startSector + fd->sectorCount, fd->sectorSize); + + return 0; +} + +/** + * Flush data out and close volume + */ +static errcode_t device_gekko_io_close(io_channel dev) +{ + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + if(!(dev->flags & EXT2_FLAG_RW)) + return 0; + + // Flush and destroy the cache (if required) + if (fd->cache) { + cache_flush(fd->cache); + cache_destructor(fd->cache); + } + + return 0; +} + +/** + * + */ +static s64 device_gekko_io_readbytes(io_channel dev, s64 offset, s64 count, void *buf) +{ + ext2_log_trace("dev %p, offset %lli, count %lli\n", dev, offset, count); + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Get the device interface + const DISC_INTERFACE* interface = fd->interface; + if (!interface) { + errno = ENODEV; + return -1; + } + + if(offset < 0) + { + errno = EROFS; + return -1; + } + + if(!count) + return 0; + + sec_t sec_start = (sec_t) fd->startSector; + sec_t sec_count = 1; + u32 buffer_offset = (u32) (offset % fd->sectorSize); + u8 *buffer = NULL; + + // Determine the range of sectors required for this read + if (offset > 0) { + sec_start += (sec_t) floor((f64) offset / (f64) fd->sectorSize); + } + if (buffer_offset+count > fd->sectorSize) { + sec_count = (sec_t) ceil((f64) (buffer_offset+count) / (f64) fd->sectorSize); + } + + // Don't read over the partitions limit + if(sec_start+sec_count > fd->startSector+fd->sectorCount) + { + ext2_log_trace("Error: read requested up to sector %lli while partition goes up to %lli\n", (s64) (sec_start+sec_count), (s64) (fd->startSector+fd->sectorCount)); + errno = EROFS; + return -1; + } + + // If this read happens to be on the sector boundaries then do the read straight into the destination buffer + + if((buffer_offset == 0) && (count % fd->sectorSize == 0)) + { + // Read from the device + ext2_log_trace("direct read from sector %d (%d sector(s) long)\n", sec_start, sec_count); + if (!device_gekko_io_readsectors(dev, sec_start, sec_count, buf)) + { + ext2_log_trace("direct read failure @ sector %d (%d sector(s) long)\n", sec_start, sec_count); + errno = EIO; + return -1; + } + // Else read into a buffer and copy over only what was requested + } + else + { + + // Allocate a buffer to hold the read data + buffer = (u8*)mem_alloc(sec_count * fd->sectorSize); + if (!buffer) { + errno = ENOMEM; + return -1; + } + + // Read from the device + ext2_log_trace("buffered read from sector %d (%d sector(s) long)\n", sec_start, sec_count); + ext2_log_trace("count: %d sec_count:%d fd->sectorSize: %d )\n", (u32)count, (u32)sec_count,(u32)fd->sectorSize); + if (!device_gekko_io_readsectors(dev, sec_start, sec_count, buffer)) { + ext2_log_trace("buffered read failure @ sector %d (%d sector(s) long)\n", sec_start, sec_count); + mem_free(buffer); + errno = EIO; + return -1; + } + + // Copy what was requested to the destination buffer + memcpy(buf, buffer + buffer_offset, count); + mem_free(buffer); + + } + + return count; +} + +/** + * + */ +static s64 device_gekko_io_writebytes(io_channel dev, s64 offset, s64 count, const void *buf) +{ + ext2_log_trace("dev %p, offset %lli, count %lli\n", dev, offset, count); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + if(!(dev->flags & EXT2_FLAG_RW)) + return -1; + + // Get the device interface + const DISC_INTERFACE* interface = fd->interface; + if (!interface) { + errno = ENODEV; + return -1; + } + + if(count < 0 || offset < 0) { + errno = EROFS; + return -1; + } + + if(count == 0) + return 0; + + sec_t sec_start = (sec_t) fd->startSector; + sec_t sec_count = 1; + u32 buffer_offset = (u32) (offset % fd->sectorSize); + u8 *buffer = NULL; + + // Determine the range of sectors required for this write + if (offset > 0) { + sec_start += (sec_t) floor((f64) offset / (f64) fd->sectorSize); + } + if ((buffer_offset+count) > fd->sectorSize) { + sec_count = (sec_t) ceil((f64) (buffer_offset+count) / (f64) fd->sectorSize); + } + + // Don't write over the partitions limit + if(sec_start+sec_count > fd->startSector+fd->sectorCount) + { + ext2_log_trace("Error: write requested up to sector %lli while partition goes up to %lli\n", (s64) (sec_start+sec_count), (s64) (fd->startSector+fd->sectorCount)); + errno = EROFS; + return -1; + } + + // If this write happens to be on the sector boundaries then do the write straight to disc + if((buffer_offset == 0) && (count % fd->sectorSize == 0)) + { + // Write to the device + ext2_log_trace("direct write to sector %d (%d sector(s) long)\n", sec_start, sec_count); + if (!device_gekko_io_writesectors(dev, sec_start, sec_count, buf)) { + ext2_log_trace("direct write failure @ sector %d (%d sector(s) long)\n", sec_start, sec_count); + errno = EIO; + return -1; + } + // Else write from a buffer aligned to the sector boundaries + } + else + { + // Allocate a buffer to hold the write data + buffer = (u8 *) mem_alloc(sec_count * fd->sectorSize); + if (!buffer) { + errno = ENOMEM; + return -1; + } + // Read the first and last sectors of the buffer from disc (if required) + // NOTE: This is done because the data does not line up with the sector boundaries, + // we just read in the buffer edges where the data overlaps with the rest of the disc + if(buffer_offset != 0) + { + if (!device_gekko_io_readsectors(dev, sec_start, 1, buffer)) { + ext2_log_trace("read failure @ sector %d\n", sec_start); + mem_free(buffer); + errno = EIO; + return -1; + } + } + if((buffer_offset+count) % fd->sectorSize != 0) + { + if (!device_gekko_io_readsectors(dev, sec_start + sec_count - 1, 1, buffer + ((sec_count-1) * fd->sectorSize))) { + ext2_log_trace("read failure @ sector %d\n", sec_start + sec_count - 1); + mem_free(buffer); + errno = EIO; + return -1; + } + } + + // Copy the data into the write buffer + memcpy(buffer + buffer_offset, buf, count); + + // Write to the device + ext2_log_trace("buffered write to sector %d (%d sector(s) long)\n", sec_start, sec_count); + if (!device_gekko_io_writesectors(dev, sec_start, sec_count, buffer)) { + ext2_log_trace("buffered write failure @ sector %d\n", sec_start); + mem_free(buffer); + errno = EIO; + return -1; + } + + // Free the buffer + mem_free(buffer); + } + + return count; +} + + +/** + * Read function wrap for I/O manager + */ +static errcode_t device_gekko_io_read64(io_channel dev, unsigned long long block, int count, void *buf) +{ + gekko_fd *fd = DEV_FD(dev); + s64 size = (count < 0) ? -count : count * dev->block_size; + fd->io_stats.bytes_read += size; + ext2_loff_t location = ((ext2_loff_t) block * dev->block_size) + fd->offset; + + s64 read = device_gekko_io_readbytes(dev, location, size, buf); + if(read != size) + return EXT2_ET_SHORT_READ; + else if(read < 0) + return EXT2_ET_BLOCK_BITMAP_READ; + + return EXT2_ET_OK; +} + +static errcode_t device_gekko_io_read(io_channel dev, unsigned long block, int count, void *buf) +{ + return device_gekko_io_read64(dev, block, count, buf); +} + +/** + * Write function wrap for I/O manager + */ +static errcode_t device_gekko_io_write64(io_channel dev, unsigned long long block, int count, const void *buf) +{ + gekko_fd *fd = DEV_FD(dev); + s64 size = (count < 0) ? -count : count * dev->block_size; + fd->io_stats.bytes_written += size; + + ext2_loff_t location = ((ext2_loff_t) block * dev->block_size) + fd->offset; + + s64 writen = device_gekko_io_writebytes(dev, location, size, buf); + if(writen != size) + return EXT2_ET_SHORT_WRITE; + else if(writen < 0) + return EXT2_ET_BLOCK_BITMAP_WRITE; + + return EXT2_ET_OK; +} + +static errcode_t device_gekko_io_write(io_channel dev, unsigned long block, int count, const void *buf) +{ + return device_gekko_io_write64(dev, block, count, buf); +} + + +static bool device_gekko_io_readsectors(io_channel dev, sec_t sector, sec_t numSectors, void* buffer) +{ + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return false; + } + // Read the sectors from disc (or cache, if enabled) + if (fd->cache) + return cache_readSectors(fd->cache, sector, numSectors, buffer); + else + return fd->interface->readSectors(sector, numSectors, buffer); + + return false; +} + +static bool device_gekko_io_writesectors(io_channel dev, sec_t sector, sec_t numSectors, const void* buffer) +{ + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return false; + } + + // Write the sectors to disc (or cache, if enabled) + if (fd->cache) + return cache_writeSectors(fd->cache, sector, numSectors, buffer); + else + return fd->interface->writeSectors(sector, numSectors, buffer); + + return false; +} + +/** + * + */ +static errcode_t device_gekko_io_sync(io_channel dev) +{ + gekko_fd *fd = DEV_FD(dev); + ext2_log_trace("dev %p\n", dev); + + // Check that the device can be written to + if(!(dev->flags & EXT2_FLAG_RW)) + return -1; + + // Flush any sectors in the disc cache (if required) + if (fd->cache) { + if (!cache_flush(fd->cache)) { + errno = EIO; + return EXT2_ET_BLOCK_BITMAP_WRITE; + } + } + + return EXT2_ET_OK; +} + +/** + * + */ +static errcode_t device_gekko_io_stat(io_channel dev, io_stats *stats) +{ + EXT2_CHECK_MAGIC(dev, EXT2_ET_MAGIC_IO_CHANNEL); + gekko_fd *fd = DEV_FD(dev); + + if (stats) + *stats = &fd->io_stats; + + return EXT2_ET_OK; +} + +static errcode_t device_gekko_set_blksize(io_channel dev, int blksize) +{ + EXT2_CHECK_MAGIC(dev, EXT2_ET_MAGIC_IO_CHANNEL); + + if (dev->block_size != blksize) + { + dev->block_size = blksize; + + return device_gekko_io_sync(dev); + } + + return EXT2_ET_OK; +} + +/** + * Set options. + */ +static errcode_t device_gekko_set_option(io_channel dev, const char *option, const char *arg) +{ + unsigned long long tmp; + char *end; + + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + EXT2_CHECK_MAGIC(dev, EXT2_ET_MAGIC_IO_CHANNEL); + + if (!strcmp(option, "offset")) { + if (!arg) + return EXT2_ET_INVALID_ARGUMENT; + + tmp = strtoull(arg, &end, 0); + if (*end) + return EXT2_ET_INVALID_ARGUMENT; + fd->offset = tmp; + if (fd->offset < 0) + return EXT2_ET_INVALID_ARGUMENT; + return 0; + } + return EXT2_ET_INVALID_ARGUMENT; +} + +static errcode_t device_gekko_discard(io_channel channel, unsigned long long block, unsigned long long count) +{ + //!TODO as soon as it is implemented in the official lib + return 0; +} + +/** + * Device operations for working with gekko style devices and files. + */ +const struct struct_io_manager struct_gekko_io_manager = +{ + EXT2_ET_MAGIC_IO_MANAGER, + "Wii/GC I/O Manager", + device_gekko_io_open, + device_gekko_io_close, + device_gekko_set_blksize, + device_gekko_io_read, + device_gekko_io_write, + device_gekko_io_sync, + 0, + device_gekko_set_option, + device_gekko_io_stat, + device_gekko_io_read64, + device_gekko_io_write64, + device_gekko_discard, +}; + +io_manager gekko_io_manager = (io_manager) &struct_gekko_io_manager; diff --git a/libcustomext2fs/source/gekko_io.h b/libcustomext2fs/source/gekko_io.h new file mode 100644 index 00000000..16786c7c --- /dev/null +++ b/libcustomext2fs/source/gekko_io.h @@ -0,0 +1,53 @@ +/* +* gekko_io.h - Platform specifics for device io. +* + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok +* +* 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 +* (at your option) any later version. +* +* This program/include file is distributed in the hope that it will be +* useful, but WITHOUT ANY WARRANTY; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _GEKKO_IO_H +#define _GEKKO_IO_H + +#include +#include +#include "disc_cache.h" +#include "ext2fs.h" + +#define BYTES_PER_SECTOR 512 + +/** + * gekko_fd - Gekko device driver descriptor + */ +typedef struct _gekko_fd { + const DISC_INTERFACE* interface; /* Device disc interface */ + sec_t startSector; /* LBA of partition start */ + sec_t sectorCount; /* Total number of sectors in partition */ + u16 sectorSize; /* Device sector size (in bytes) */ + int flags; + int access_time; + ext2_loff_t offset; + struct struct_io_stats io_stats; + CACHE *cache; /* Cache */ + u32 cachePageCount; /* The number of pages in the cache */ + u32 cachePageSize; /* The number of sectors per cache page */ +} gekko_fd; + + +/* Gekko device driver i/o operations */ +extern io_manager gekko_io_manager; + +#endif /* _GEKKO_IO_H */ diff --git a/libcustomext2fs/source/gen_bitmap.c b/libcustomext2fs/source/gen_bitmap.c new file mode 100644 index 00000000..ca9cb284 --- /dev/null +++ b/libcustomext2fs/source/gen_bitmap.c @@ -0,0 +1,560 @@ +/* + * gen_bitmap.c --- Generic (32-bit) bitmap routines + * + * Copyright (C) 2001 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2fsP.h" + +struct ext2fs_struct_generic_bitmap { + errcode_t magic; + ext2_filsys fs; + __u32 start, end; + __u32 real_end; + char * description; + char * bitmap; + errcode_t base_error_code; + __u32 reserved[7]; +}; + +#define EXT2FS_IS_32_BITMAP(bmap) \ + (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP) || \ + ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP) || \ + ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP)) + +#define EXT2FS_IS_64_BITMAP(bmap) \ + (((bmap)->magic == EXT2_ET_MAGIC_GENERIC_BITMAP64) || \ + ((bmap)->magic == EXT2_ET_MAGIC_BLOCK_BITMAP64) || \ + ((bmap)->magic == EXT2_ET_MAGIC_INODE_BITMAP64)) + +/* + * Used by previously inlined function, so we have to export this and + * not change the function signature + */ +void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap, + int code, unsigned long arg) +{ +#ifndef OMIT_COM_ERR + if (bitmap->description) + com_err(0, bitmap->base_error_code+code, + "#%lu for %s", arg, bitmap->description); + else + com_err(0, bitmap->base_error_code + code, "#%lu", arg); +#endif +} + +static errcode_t check_magic(ext2fs_generic_bitmap bitmap) +{ + if (!bitmap || !((bitmap->magic == EXT2_ET_MAGIC_GENERIC_BITMAP) || + (bitmap->magic == EXT2_ET_MAGIC_INODE_BITMAP) || + (bitmap->magic == EXT2_ET_MAGIC_BLOCK_BITMAP))) + return EXT2_ET_MAGIC_GENERIC_BITMAP; + return 0; +} + +errcode_t ext2fs_make_generic_bitmap(errcode_t magic, ext2_filsys fs, + __u32 start, __u32 end, __u32 real_end, + const char *descr, char *init_map, + ext2fs_generic_bitmap *ret) +{ + ext2fs_generic_bitmap bitmap; + errcode_t retval; + size_t size; + + retval = ext2fs_get_mem(sizeof(struct ext2fs_struct_generic_bitmap), + &bitmap); + if (retval) + return retval; + + bitmap->magic = magic; + bitmap->fs = fs; + bitmap->start = start; + bitmap->end = end; + bitmap->real_end = real_end; + switch (magic) { + case EXT2_ET_MAGIC_INODE_BITMAP: + bitmap->base_error_code = EXT2_ET_BAD_INODE_MARK; + break; + case EXT2_ET_MAGIC_BLOCK_BITMAP: + bitmap->base_error_code = EXT2_ET_BAD_BLOCK_MARK; + break; + default: + bitmap->base_error_code = EXT2_ET_BAD_GENERIC_MARK; + } + if (descr) { + retval = ext2fs_get_mem(strlen(descr)+1, &bitmap->description); + if (retval) { + ext2fs_free_mem(&bitmap); + return retval; + } + strcpy(bitmap->description, descr); + } else + bitmap->description = 0; + + size = (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1); + /* Round up to allow for the BT x86 instruction */ + size = (size + 7) & ~3; + retval = ext2fs_get_mem(size, &bitmap->bitmap); + if (retval) { + ext2fs_free_mem(&bitmap->description); + ext2fs_free_mem(&bitmap); + return retval; + } + + if (init_map) + memcpy(bitmap->bitmap, init_map, size); + else + memset(bitmap->bitmap, 0, size); + *ret = bitmap; + return 0; +} + +errcode_t ext2fs_allocate_generic_bitmap(__u32 start, + __u32 end, + __u32 real_end, + const char *descr, + ext2fs_generic_bitmap *ret) +{ + return ext2fs_make_generic_bitmap(EXT2_ET_MAGIC_GENERIC_BITMAP, 0, + start, end, real_end, descr, 0, ret); +} + +errcode_t ext2fs_copy_generic_bitmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest) +{ + return (ext2fs_make_generic_bitmap(src->magic, src->fs, + src->start, src->end, + src->real_end, + src->description, src->bitmap, + dest)); +} + +void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap) +{ + if (check_magic(bitmap)) + return; + + bitmap->magic = 0; + if (bitmap->description) { + ext2fs_free_mem(&bitmap->description); + bitmap->description = 0; + } + if (bitmap->bitmap) { + ext2fs_free_mem(&bitmap->bitmap); + bitmap->bitmap = 0; + } + ext2fs_free_mem(&bitmap); +} + +int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, + blk_t bitno) +{ + if (!EXT2FS_IS_32_BITMAP(bitmap)) { + if (EXT2FS_IS_64_BITMAP(bitmap)) { + ext2fs_warn_bitmap32(bitmap, __func__); + return ext2fs_test_generic_bmap(bitmap, bitno); + } +#ifndef OMIT_COM_ERR + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "test_bitmap(%lu)", (unsigned long) bitno); + return 0; +#endif + } + + if ((bitno < bitmap->start) || (bitno > bitmap->end)) { + ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno); + return 0; + } + return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap); +} + +int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, + __u32 bitno) +{ + if (!EXT2FS_IS_32_BITMAP(bitmap)) { + if (EXT2FS_IS_64_BITMAP(bitmap)) { + ext2fs_warn_bitmap32(bitmap, __func__); + return ext2fs_mark_generic_bmap(bitmap, bitno); + } +#ifndef OMIT_COM_ERR + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "mark_bitmap(%lu)", (unsigned long) bitno); + return 0; +#endif + } + + if ((bitno < bitmap->start) || (bitno > bitmap->end)) { + ext2fs_warn_bitmap2(bitmap, EXT2FS_MARK_ERROR, bitno); + return 0; + } + return ext2fs_set_bit(bitno - bitmap->start, bitmap->bitmap); +} + +int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, + blk_t bitno) +{ + if (!EXT2FS_IS_32_BITMAP(bitmap)) { + if (EXT2FS_IS_64_BITMAP(bitmap)) { + ext2fs_warn_bitmap32(bitmap, __func__); + return ext2fs_mark_generic_bmap(bitmap, bitno); + } +#ifndef OMIT_COM_ERR + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "mark_bitmap(%lu)", (unsigned long) bitno); + return 0; +#endif + } + + if ((bitno < bitmap->start) || (bitno > bitmap->end)) { + ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR, bitno); + return 0; + } + return ext2fs_clear_bit(bitno - bitmap->start, bitmap->bitmap); +} + +__u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap) +{ + if (!EXT2FS_IS_32_BITMAP(bitmap)) { + if (EXT2FS_IS_64_BITMAP(bitmap)) { + ext2fs_warn_bitmap32(bitmap, __func__); + return ext2fs_get_generic_bmap_start(bitmap); + } +#ifndef OMIT_COM_ERR + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "get_bitmap_start"); + return 0; +#endif + } + + return bitmap->start; +} + +__u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap) +{ + if (!EXT2FS_IS_32_BITMAP(bitmap)) { + if (EXT2FS_IS_64_BITMAP(bitmap)) { + ext2fs_warn_bitmap32(bitmap, __func__); + return ext2fs_get_generic_bmap_end(bitmap); + } +#ifndef OMIT_COM_ERR + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "get_bitmap_end"); + return 0; +#endif + } + return bitmap->end; +} + +void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap) +{ + if (!EXT2FS_IS_32_BITMAP(bitmap)) { + if (EXT2FS_IS_64_BITMAP(bitmap)) { + ext2fs_warn_bitmap32(bitmap, __func__); + ext2fs_clear_generic_bmap(bitmap); + return; + } +#ifndef OMIT_COM_ERR + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "clear_generic_bitmap"); + return; +#endif + } + + memset(bitmap->bitmap, 0, + (size_t) (((bitmap->real_end - bitmap->start) / 8) + 1)); +} + +errcode_t ext2fs_fudge_generic_bitmap_end(ext2fs_inode_bitmap bitmap, + errcode_t magic, errcode_t neq, + ext2_ino_t end, ext2_ino_t *oend) +{ + EXT2_CHECK_MAGIC(bitmap, magic); + + if (end > bitmap->real_end) + return neq; + if (oend) + *oend = bitmap->end; + bitmap->end = end; + return 0; +} + +errcode_t ext2fs_resize_generic_bitmap(errcode_t magic, + __u32 new_end, __u32 new_real_end, + ext2fs_generic_bitmap bmap) +{ + errcode_t retval; + size_t size, new_size; + __u32 bitno; + + if (!bmap || (bmap->magic != magic)) + return magic; + + /* + * If we're expanding the bitmap, make sure all of the new + * parts of the bitmap are zero. + */ + if (new_end > bmap->end) { + bitno = bmap->real_end; + if (bitno > new_end) + bitno = new_end; + for (; bitno > bmap->end; bitno--) + ext2fs_clear_bit(bitno - bmap->start, bmap->bitmap); + } + if (new_real_end == bmap->real_end) { + bmap->end = new_end; + return 0; + } + + size = ((bmap->real_end - bmap->start) / 8) + 1; + new_size = ((new_real_end - bmap->start) / 8) + 1; + + if (size != new_size) { + retval = ext2fs_resize_mem(size, new_size, &bmap->bitmap); + if (retval) + return retval; + } + if (new_size > size) + memset(bmap->bitmap + size, 0, new_size - size); + + bmap->end = new_end; + bmap->real_end = new_real_end; + return 0; +} + +errcode_t ext2fs_compare_generic_bitmap(errcode_t magic, errcode_t neq, + ext2fs_generic_bitmap bm1, + ext2fs_generic_bitmap bm2) +{ + blk_t i; + + if (!bm1 || bm1->magic != magic) + return magic; + if (!bm2 || bm2->magic != magic) + return magic; + + if ((bm1->start != bm2->start) || + (bm1->end != bm2->end) || + (memcmp(bm1->bitmap, bm2->bitmap, + (size_t) (bm1->end - bm1->start)/8))) + return neq; + + for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++) + if (ext2fs_fast_test_block_bitmap(bm1, i) != + ext2fs_fast_test_block_bitmap(bm2, i)) + return neq; + + return 0; +} + +void ext2fs_set_generic_bitmap_padding(ext2fs_generic_bitmap map) +{ + __u32 i, j; + + /* Protect loop from wrap-around if map->real_end is maxed */ + for (i=map->end+1, j = i - map->start; + i <= map->real_end && i > map->end; + i++, j++) + ext2fs_set_bit(j, map->bitmap); +} + +errcode_t ext2fs_get_generic_bitmap_range(ext2fs_generic_bitmap bmap, + errcode_t magic, + __u32 start, __u32 num, + void *out) +{ + if (!bmap || (bmap->magic != magic)) + return magic; + + if ((start < bmap->start) || (start+num-1 > bmap->real_end)) + return EXT2_ET_INVALID_ARGUMENT; + + memcpy(out, bmap->bitmap + (start >> 3), (num+7) >> 3); + return 0; +} + +errcode_t ext2fs_set_generic_bitmap_range(ext2fs_generic_bitmap bmap, + errcode_t magic, + __u32 start, __u32 num, + void *in) +{ + if (!bmap || (bmap->magic != magic)) + return magic; + + if ((start < bmap->start) || (start+num-1 > bmap->real_end)) + return EXT2_ET_INVALID_ARGUMENT; + + memcpy(bmap->bitmap + (start >> 3), in, (num+7) >> 3); + return 0; +} + +/* + * Compare @mem to zero buffer by 256 bytes. + * Return 1 if @mem is zeroed memory, otherwise return 0. + */ +int ext2fs_mem_is_zero(const char *mem, size_t len) +{ + static const char zero_buf[256]; + + while (len >= sizeof(zero_buf)) { + if (memcmp(mem, zero_buf, sizeof(zero_buf))) + return 0; + len -= sizeof(zero_buf); + mem += sizeof(zero_buf); + } + /* Deal with leftover bytes. */ + if (len) + return !memcmp(mem, zero_buf, len); + return 1; +} + +/* + * Return true if all of the bits in a specified range are clear + */ +static int ext2fs_test_clear_generic_bitmap_range(ext2fs_generic_bitmap bitmap, + unsigned int start, + unsigned int len) +{ + size_t start_byte, len_byte = len >> 3; + unsigned int start_bit, len_bit = len % 8; + int first_bit = 0; + int last_bit = 0; + int mark_count = 0; + int mark_bit = 0; + int i; + const char *ADDR = bitmap->bitmap; + + start -= bitmap->start; + start_byte = start >> 3; + start_bit = start % 8; + + if (start_bit != 0) { + /* + * The compared start block number or start inode number + * is not the first bit in a byte. + */ + mark_count = 8 - start_bit; + if (len < 8 - start_bit) { + mark_count = (int)len; + mark_bit = len + start_bit - 1; + } else + mark_bit = 7; + + for (i = mark_count; i > 0; i--, mark_bit--) + first_bit |= 1 << mark_bit; + + /* + * Compare blocks or inodes in the first byte. + * If there is any marked bit, this function returns 0. + */ + if (first_bit & ADDR[start_byte]) + return 0; + else if (len <= 8 - start_bit) + return 1; + + start_byte++; + len_bit = (len - mark_count) % 8; + len_byte = (len - mark_count) >> 3; + } + + /* + * The compared start block number or start inode number is + * the first bit in a byte. + */ + if (len_bit != 0) { + /* + * The compared end block number or end inode number is + * not the last bit in a byte. + */ + for (mark_bit = len_bit - 1; mark_bit >= 0; mark_bit--) + last_bit |= 1 << mark_bit; + + /* + * Compare blocks or inodes in the last byte. + * If there is any marked bit, this function returns 0. + */ + if (last_bit & ADDR[start_byte + len_byte]) + return 0; + else if (len_byte == 0) + return 1; + } + + /* Check whether all bytes are 0 */ + return ext2fs_mem_is_zero(ADDR + start_byte, len_byte); +} + +int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num) +{ + EXT2_CHECK_MAGIC(bitmap, EXT2_ET_MAGIC_BLOCK_BITMAP); + if ((block < bitmap->start) || (block+num-1 > bitmap->real_end)) { + ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, + block, bitmap->description); + return 0; + } + return ext2fs_test_clear_generic_bitmap_range((ext2fs_generic_bitmap) + bitmap, block, num); +} + +int ext2fs_test_inode_bitmap_range(ext2fs_inode_bitmap bitmap, + ino_t inode, int num) +{ + EXT2_CHECK_MAGIC(bitmap, EXT2_ET_MAGIC_INODE_BITMAP); + if ((inode < bitmap->start) || (inode+num-1 > bitmap->real_end)) { + ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST, + inode, bitmap->description); + return 0; + } + return ext2fs_test_clear_generic_bitmap_range((ext2fs_generic_bitmap) + bitmap, inode, num); +} + +void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num) +{ + int i; + + if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { + ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, + bitmap->description); + return; + } + for (i=0; i < num; i++) + ext2fs_fast_set_bit(block + i - bitmap->start, bitmap->bitmap); +} + +void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, + blk_t block, int num) +{ + int i; + + if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { + ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, + bitmap->description); + return; + } + for (i=0; i < num; i++) + ext2fs_fast_clear_bit(block + i - bitmap->start, + bitmap->bitmap); +} diff --git a/libcustomext2fs/source/gen_bitmap64.c b/libcustomext2fs/source/gen_bitmap64.c new file mode 100644 index 00000000..8108f3d7 --- /dev/null +++ b/libcustomext2fs/source/gen_bitmap64.c @@ -0,0 +1,581 @@ +/* + * gen_bitmap64.c --- routines to read, write, and manipulate the new qinode and + * block bitmaps. + * + * Copyright (C) 2007, 2008 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" +#include "bmap64.h" + +/* + * Design of 64-bit bitmaps + * + * In order maintain ABI compatibility with programs that don't + * understand about 64-bit blocks/inodes, + * ext2fs_allocate_inode_bitmap() and ext2fs_allocate_block_bitmap() + * will create old-style bitmaps unless the application passes the + * flag EXT2_FLAG_64BITS to ext2fs_open(). If this flag is + * passed, then we know the application has been recompiled, so we can + * use the new-style bitmaps. If it is not passed, we have to return + * an error if trying to open a filesystem which needs 64-bit bitmaps. + * + * The new bitmaps use a new set of structure magic numbers, so that + * both the old-style and new-style interfaces can identify which + * version of the data structure was used. Both the old-style and + * new-style interfaces will support either type of bitmap, although + * of course 64-bit operation will only be possible when both the + * new-style interface and the new-style bitmap are used. + * + * For example, the new bitmap interfaces will check the structure + * magic numbers and so will be able to detect old-stype bitmap. If + * they see an old-style bitmap, they will pass it to the gen_bitmap.c + * functions for handling. The same will be true for the old + * interfaces as well. + * + * The new-style interfaces will have several different back-end + * implementations, so we can support different encodings that are + * appropriate for different applications. In general the default + * should be whatever makes sense, and what the application/library + * will use. However, e2fsck may need specialized implementations for + * its own uses. For example, when doing parent directory pointer + * loop detections in pass 3, the bitmap will *always* be sparse, so + * e2fsck can request an encoding which is optimized for that. + */ + +static void warn_bitmap(ext2fs_generic_bitmap bitmap, + int code, __u64 arg) +{ +#ifndef OMIT_COM_ERR + if (bitmap->description) + com_err(0, bitmap->base_error_code+code, + "#%llu for %s", arg, bitmap->description); + else + com_err(0, bitmap->base_error_code + code, "#%llu", arg); +#endif +} + + +errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, + int type, __u64 start, __u64 end, + __u64 real_end, + const char *descr, + ext2fs_generic_bitmap *ret) +{ + ext2fs_generic_bitmap bitmap; + struct ext2_bitmap_ops *ops; + errcode_t retval; + + switch (type) { + case EXT2FS_BMAP64_BITARRAY: + ops = &ext2fs_blkmap64_bitarray; + break; + default: + return EINVAL; + } + + retval = ext2fs_get_mem(sizeof(struct ext2fs_struct_generic_bitmap), + &bitmap); + if (retval) + return retval; + + /* XXX factor out, repeated in copy_bmap */ + bitmap->magic = magic; + bitmap->fs = fs; + bitmap->start = start; + bitmap->end = end; + bitmap->real_end = real_end; + bitmap->bitmap_ops = ops; + switch (magic) { + case EXT2_ET_MAGIC_INODE_BITMAP64: + bitmap->base_error_code = EXT2_ET_BAD_INODE_MARK; + break; + case EXT2_ET_MAGIC_BLOCK_BITMAP64: + bitmap->base_error_code = EXT2_ET_BAD_BLOCK_MARK; + break; + default: + bitmap->base_error_code = EXT2_ET_BAD_GENERIC_MARK; + } + if (descr) { + retval = ext2fs_get_mem(strlen(descr)+1, &bitmap->description); + if (retval) { + ext2fs_free_mem(&bitmap); + return retval; + } + strcpy(bitmap->description, descr); + } else + bitmap->description = 0; + + retval = bitmap->bitmap_ops->new_bmap(fs, bitmap); + if (retval) { + ext2fs_free_mem(&bitmap); + ext2fs_free_mem(&bitmap->description); + return retval; + } + + *ret = bitmap; + return 0; +} + +void ext2fs_free_generic_bmap(ext2fs_generic_bitmap bmap) +{ + if (!bmap) + return; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + ext2fs_free_generic_bitmap((ext2fs_generic_bitmap) bmap); + return; + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return; + + bmap->bitmap_ops->free_bmap(bmap); + + if (bmap->description) { + ext2fs_free_mem(&bmap->description); + bmap->description = 0; + } + bmap->magic = 0; +} + +errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, + ext2fs_generic_bitmap *dest) +{ + char *descr, *new_descr; + ext2fs_generic_bitmap new_bmap; + errcode_t retval; + + if (!src) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(src)) + return ext2fs_copy_generic_bitmap((ext2fs_generic_bitmap) src, + (ext2fs_generic_bitmap *) dest); + + if (!EXT2FS_IS_64_BITMAP(src)) + return EINVAL; + + /* Allocate a new bitmap struct */ + retval = ext2fs_get_mem(sizeof(struct ext2fs_struct_generic_bitmap), + &new_bmap); + if (retval) + return retval; + + /* Copy all the high-level parts over */ + new_bmap->magic = src->magic; + new_bmap->fs = src->fs; + new_bmap->start = src->start; + new_bmap->end = src->end; + new_bmap->real_end = src->real_end; + new_bmap->bitmap_ops = src->bitmap_ops; + new_bmap->base_error_code = src->base_error_code; + + descr = src->description; + if (descr) { + retval = ext2fs_get_mem(strlen(descr)+1, &new_descr); + if (retval) { + ext2fs_free_mem(&new_bmap); + return retval; + } + strcpy(new_descr, descr); + new_bmap->description = new_descr; + } + + retval = src->bitmap_ops->copy_bmap(src, new_bmap); + if (retval) { + ext2fs_free_mem(&new_bmap->description); + ext2fs_free_mem(&new_bmap); + return retval; + } + + *dest = new_bmap; + + return 0; +} + +errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap, + __u64 new_end, + __u64 new_real_end) +{ + if (!bmap) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + return ext2fs_resize_generic_bitmap(bmap->magic, + new_end, new_real_end, + (ext2fs_generic_bitmap) bmap); + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return EINVAL; + + return bmap->bitmap_ops->resize_bmap(bmap, new_end, new_real_end); +} + +errcode_t ext2fs_fudge_generic_bmap_end(ext2fs_generic_bitmap bitmap, + errcode_t neq, + __u64 end, __u64 *oend) +{ + if (!bitmap) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(bitmap)) { + ext2_ino_t tmp_oend; + int retval; + + retval = ext2fs_fudge_generic_bitmap_end((ext2fs_generic_bitmap) bitmap, + bitmap->magic, neq, + end, &tmp_oend); + if (oend) + *oend = tmp_oend; + return retval; + } + + if (!EXT2FS_IS_64_BITMAP(bitmap)) + return EINVAL; + + if (end > bitmap->real_end) + return neq; + if (oend) + *oend = bitmap->end; + bitmap->end = end; + return 0; +} + +__u64 ext2fs_get_generic_bmap_start(ext2fs_generic_bitmap bitmap) +{ + if (!bitmap) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(bitmap)) { + return ext2fs_get_generic_bitmap_start((ext2fs_generic_bitmap) + bitmap); + + } + + if (!EXT2FS_IS_64_BITMAP(bitmap)) + return EINVAL; + + return bitmap->start; +} + +__u64 ext2fs_get_generic_bmap_end(ext2fs_generic_bitmap bitmap) +{ + if (!bitmap) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(bitmap)) { + return ext2fs_get_generic_bitmap_end((ext2fs_generic_bitmap) + bitmap); + + } + + if (!EXT2FS_IS_64_BITMAP(bitmap)) + return EINVAL; + + return bitmap->end; +} + +void ext2fs_clear_generic_bmap(ext2fs_generic_bitmap bitmap) +{ + if (EXT2FS_IS_32_BITMAP(bitmap)) { + ext2fs_clear_generic_bitmap((ext2fs_generic_bitmap) bitmap); + return; + } + + bitmap->bitmap_ops->clear_bmap (bitmap); +} + +int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, + __u64 arg) +{ + if (!bitmap) + return 0; + + if (EXT2FS_IS_32_BITMAP(bitmap)) { + if (arg & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bitmap, + EXT2FS_MARK_ERROR, 0xffffffff); + return 0; + } + return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) + bitmap, arg); + } + + if (!EXT2FS_IS_64_BITMAP(bitmap)) + return 0; + + if ((arg < bitmap->start) || (arg > bitmap->end)) { + warn_bitmap(bitmap, EXT2FS_MARK_ERROR, arg); + return 0; + } + + return bitmap->bitmap_ops->mark_bmap(bitmap, arg); +} + +int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, + __u64 arg) +{ + if (!bitmap) + return 0; + + if (EXT2FS_IS_32_BITMAP(bitmap)) { + if (arg & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bitmap, + EXT2FS_UNMARK_ERROR, 0xffffffff); + return 0; + } + return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) + bitmap, arg); + } + + if (!EXT2FS_IS_64_BITMAP(bitmap)) + return 0; + + if ((arg < bitmap->start) || (arg > bitmap->end)) { + warn_bitmap(bitmap, EXT2FS_UNMARK_ERROR, arg); + return 0; + } + + return bitmap->bitmap_ops->unmark_bmap(bitmap, arg); +} + +int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, + __u64 arg) +{ + if (!bitmap) + return 0; + + if (EXT2FS_IS_32_BITMAP(bitmap)) { + if (arg & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bitmap, + EXT2FS_TEST_ERROR, 0xffffffff); + return 0; + } + return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) + bitmap, arg); + } + + if (!EXT2FS_IS_64_BITMAP(bitmap)) + return 0; + + if ((arg < bitmap->start) || (arg > bitmap->end)) { + warn_bitmap(bitmap, EXT2FS_TEST_ERROR, arg); + return 0; + } + + return bitmap->bitmap_ops->test_bmap(bitmap, arg); +} + +errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap, + __u64 start, unsigned int num, + void *in) +{ + if (!bmap) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + if ((start+num) & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, + EXT2FS_UNMARK_ERROR, 0xffffffff); + return EINVAL; + } + return ext2fs_set_generic_bitmap_range((ext2fs_generic_bitmap) bmap, + bmap->magic, start, num, + in); + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return EINVAL; + + return bmap->bitmap_ops->set_bmap_range(bmap, start, num, in); +} + +errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap, + __u64 start, unsigned int num, + void *out) +{ + if (!bmap) + return EINVAL; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + if ((start+num) & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, + EXT2FS_UNMARK_ERROR, 0xffffffff); + return EINVAL; + } + return ext2fs_get_generic_bitmap_range((ext2fs_generic_bitmap) bmap, + bmap->magic, start, num, + out); + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return EINVAL; + + return bmap->bitmap_ops->get_bmap_range(bmap, start, num, out); +} + +errcode_t ext2fs_compare_generic_bmap(errcode_t neq, + ext2fs_generic_bitmap bm1, + ext2fs_generic_bitmap bm2) +{ + blk64_t i; + + if (!bm1 || !bm2) + return EINVAL; + if (bm1->magic != bm2->magic) + return EINVAL; + + /* Now we know both bitmaps have the same magic */ + if (EXT2FS_IS_32_BITMAP(bm1)) + return ext2fs_compare_generic_bitmap(bm1->magic, neq, + (ext2fs_generic_bitmap) bm1, + (ext2fs_generic_bitmap) bm2); + + if (!EXT2FS_IS_64_BITMAP(bm1)) + return EINVAL; + + if ((bm1->start != bm2->start) || + (bm1->end != bm2->end)) + return neq; + + for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++) + if (ext2fs_test_generic_bmap(bm1, i) != + ext2fs_test_generic_bmap(bm2, i)) + return neq; + + return 0; +} + +void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap) +{ + __u64 start, num; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + ext2fs_set_generic_bitmap_padding((ext2fs_generic_bitmap) bmap); + return; + } + + start = bmap->end + 1; + num = bmap->real_end - bmap->end; + bmap->bitmap_ops->mark_bmap_extent(bmap, start, num); + /* XXX ought to warn on error */ +} + +int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t block, unsigned int num) +{ + if (!bmap) + return EINVAL; + + if (num == 1) + return !ext2fs_test_generic_bmap((ext2fs_generic_bitmap) + bmap, block); + + if (EXT2FS_IS_32_BITMAP(bmap)) { + if ((block+num) & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, + EXT2FS_UNMARK_ERROR, 0xffffffff); + return EINVAL; + } + return ext2fs_test_block_bitmap_range( + (ext2fs_generic_bitmap) bmap, block, num); + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return EINVAL; + + return bmap->bitmap_ops->test_clear_bmap_extent(bmap, block, num); +} + +void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t block, unsigned int num) +{ + if (!bmap) + return; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + if ((block+num) & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, + EXT2FS_UNMARK_ERROR, 0xffffffff); + return; + } + ext2fs_mark_block_bitmap_range((ext2fs_generic_bitmap) bmap, + block, num); + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return; + + if ((block < bmap->start) || (block+num-1 > bmap->end)) { + ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, + bmap->description); + return; + } + + bmap->bitmap_ops->mark_bmap_extent(bmap, block, num); +} + +void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap, + blk64_t block, unsigned int num) +{ + if (!bmap) + return; + + if (EXT2FS_IS_32_BITMAP(bmap)) { + if ((block+num) & ~0xffffffffULL) { + ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, + EXT2FS_UNMARK_ERROR, 0xffffffff); + return; + } + ext2fs_unmark_block_bitmap_range((ext2fs_generic_bitmap) bmap, + block, num); + } + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return; + + if ((block < bmap->start) || (block+num-1 > bmap->end)) { + ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, + bmap->description); + return; + } + + bmap->bitmap_ops->unmark_bmap_extent(bmap, block, num); +} + +int ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap, const char *func) +{ +#ifndef OMIT_COM_ERR + if (bitmap && bitmap->description) + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "called %s with 64-bit bitmap for %s", func, + bitmap->description); + else + com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, + "called %s with 64-bit bitmap", func); +#endif + return 0; +} diff --git a/libcustomext2fs/source/get_pathname.c b/libcustomext2fs/source/get_pathname.c new file mode 100644 index 00000000..7ac14db2 --- /dev/null +++ b/libcustomext2fs/source/get_pathname.c @@ -0,0 +1,160 @@ +/* + * get_pathname.c --- do directry/inode -> name translation + * + * Copyright (C) 1993, 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +/* + * + * ext2fs_get_pathname(fs, dir, ino, name) + * + * This function translates takes two inode numbers into a + * string, placing the result in . is the containing + * directory inode, and is the inode number itself. If + * is zero, then ext2fs_get_pathname will return pathname + * of the the directory . + * + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct get_pathname_struct { + ext2_ino_t search_ino; + ext2_ino_t parent; + char *name; + errcode_t errcode; +}; + +#ifdef __TURBOC__ + #pragma argsused +#endif +static int get_pathname_proc(struct ext2_dir_entry *dirent, + int offset EXT2FS_ATTR((unused)), + int blocksize EXT2FS_ATTR((unused)), + char *buf EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct get_pathname_struct *gp; + errcode_t retval; + + gp = (struct get_pathname_struct *) priv_data; + + if (((dirent->name_len & 0xFF) == 2) && + !strncmp(dirent->name, "..", 2)) + gp->parent = dirent->inode; + if (dirent->inode == gp->search_ino) { + retval = ext2fs_get_mem((dirent->name_len & 0xFF) + 1, + &gp->name); + if (retval) { + gp->errcode = retval; + return DIRENT_ABORT; + } + strncpy(gp->name, dirent->name, (dirent->name_len & 0xFF)); + gp->name[dirent->name_len & 0xFF] = '\0'; + return DIRENT_ABORT; + } + return 0; +} + +static errcode_t ext2fs_get_pathname_int(ext2_filsys fs, ext2_ino_t dir, + ext2_ino_t ino, int maxdepth, + char *buf, char **name) +{ + struct get_pathname_struct gp; + char *parent_name, *ret; + errcode_t retval; + + if (dir == ino) { + retval = ext2fs_get_mem(2, name); + if (retval) + return retval; + strcpy(*name, (dir == EXT2_ROOT_INO) ? "/" : "."); + return 0; + } + + if (!dir || (maxdepth < 0)) { + retval = ext2fs_get_mem(4, name); + if (retval) + return retval; + strcpy(*name, "..."); + return 0; + } + + gp.search_ino = ino; + gp.parent = 0; + gp.name = 0; + gp.errcode = 0; + + retval = ext2fs_dir_iterate(fs, dir, 0, buf, get_pathname_proc, &gp); + if (retval) + goto cleanup; + if (gp.errcode) { + retval = gp.errcode; + goto cleanup; + } + + retval = ext2fs_get_pathname_int(fs, gp.parent, dir, maxdepth-1, + buf, &parent_name); + if (retval) + goto cleanup; + if (!ino) { + *name = parent_name; + return 0; + } + + if (gp.name) + retval = ext2fs_get_mem(strlen(parent_name)+strlen(gp.name)+2, + &ret); + else + retval = ext2fs_get_mem(strlen(parent_name)+5, &ret); + if (retval) + goto cleanup; + + ret[0] = 0; + if (parent_name[1]) + strcat(ret, parent_name); + strcat(ret, "/"); + if (gp.name) + strcat(ret, gp.name); + else + strcat(ret, "???"); + *name = ret; + ext2fs_free_mem(&parent_name); + retval = 0; + +cleanup: + if (gp.name) + ext2fs_free_mem(&gp.name); + return retval; +} + +errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino, + char **name) +{ + char *buf; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + if (dir == ino) + ino = 0; + retval = ext2fs_get_pathname_int(fs, dir, ino, 32, buf, name); + ext2fs_free_mem(&buf); + return retval; + +} diff --git a/libcustomext2fs/source/getsectsize.c b/libcustomext2fs/source/getsectsize.c new file mode 100644 index 00000000..64f42a62 --- /dev/null +++ b/libcustomext2fs/source/getsectsize.c @@ -0,0 +1,91 @@ +/* + * getsectsize.c --- get the sector size of a device. + * + * Copyright (C) 1995, 1995 Theodore Ts'o. + * Copyright (C) 2003 VMware, Inc. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_LINUX_FD_H +#include +#include +#endif + +#if defined(__linux__) && defined(_IO) +#if !defined(BLKSSZGET) +#define BLKSSZGET _IO(0x12,104)/* get block device sector size */ +#endif +#if !defined(BLKPBSZGET) +#define BLKPBSZGET _IO(0x12,123)/* get block physical sector size */ +#endif +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * Returns the logical sector size of a device + */ +errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize) +{ + int fd; + +#ifdef HAVE_OPEN64 + fd = open64(file, O_RDONLY); +#else + fd = open(file, O_RDONLY); +#endif + if (fd < 0) + return errno; + +#ifdef BLKSSZGET + if (ioctl(fd, BLKSSZGET, sectsize) >= 0) { + close(fd); + return 0; + } +#endif + *sectsize = 0; + close(fd); + return 0; +} + +/* + * Returns the physical sector size of a device + */ +errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize) +{ + int fd; + +#ifdef HAVE_OPEN64 + fd = open64(file, O_RDONLY); +#else + fd = open(file, O_RDONLY); +#endif + if (fd < 0) + return errno; + +#ifdef BLKPBSZGET + if (ioctl(fd, BLKPBSZGET, sectsize) >= 0) { + close(fd); + return 0; + } +#endif + *sectsize = 0; + close(fd); + return 0; +} diff --git a/libcustomext2fs/source/getsize.c b/libcustomext2fs/source/getsize.c new file mode 100644 index 00000000..56ec4b69 --- /dev/null +++ b/libcustomext2fs/source/getsize.c @@ -0,0 +1,311 @@ +/* + * getsize.c --- get the size of a partition. + * + * Copyright (C) 1995, 1995 Theodore Ts'o. + * Copyright (C) 2003 VMware, Inc. + * + * Windows version of ext2fs_get_device_size by Chris Li, VMware. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_LINUX_FD_H +#include +#endif +#ifdef HAVE_SYS_DISKLABEL_H +#include +#endif +#ifdef HAVE_SYS_DISK_H +#ifdef HAVE_SYS_QUEUE_H +#include /* for LIST_HEAD */ +#endif +#include +#endif +#ifdef __linux__ +#include +#endif +#if HAVE_SYS_STAT_H +#include +#endif +#include + +#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE) +#define BLKGETSIZE _IO(0x12,96) /* return device size */ +#endif + +#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64) +#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ +#endif + +#ifdef APPLE_DARWIN +#define BLKGETSIZE DKIOCGETBLOCKCOUNT32 +#endif /* APPLE_DARWIN */ + +#include "ext2_fs.h" +#include "ext2fs.h" + +#if defined(__CYGWIN__) || defined (WIN32) +#include "windows.h" +#include "winioctl.h" + +#if (_WIN32_WINNT >= 0x0500) +#define HAVE_GET_FILE_SIZE_EX 1 +#endif + +errcode_t ext2fs_get_device_size(const char *file, int blocksize, + blk_t *retblocks) +{ + HANDLE dev; + PARTITION_INFORMATION pi; + DISK_GEOMETRY gi; + DWORD retbytes; +#ifdef HAVE_GET_FILE_SIZE_EX + LARGE_INTEGER filesize; +#else + DWORD filesize; +#endif /* HAVE_GET_FILE_SIZE_EX */ + + dev = CreateFile(file, GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE , + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (dev == INVALID_HANDLE_VALUE) + return EBADF; + if (DeviceIoControl(dev, IOCTL_DISK_GET_PARTITION_INFO, + &pi, sizeof(PARTITION_INFORMATION), + &pi, sizeof(PARTITION_INFORMATION), + &retbytes, NULL)) { + + *retblocks = pi.PartitionLength.QuadPart / blocksize; + + } else if (DeviceIoControl(dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, + &gi, sizeof(DISK_GEOMETRY), + &gi, sizeof(DISK_GEOMETRY), + &retbytes, NULL)) { + + *retblocks = gi.BytesPerSector * + gi.SectorsPerTrack * + gi.TracksPerCylinder * + gi.Cylinders.QuadPart / blocksize; + +#ifdef HAVE_GET_FILE_SIZE_EX + } else if (GetFileSizeEx(dev, &filesize)) { + *retblocks = filesize.QuadPart / blocksize; + } +#else + } else { + filesize = GetFileSize(dev, NULL); + if (INVALID_FILE_SIZE != filesize) { + *retblocks = filesize / blocksize; + } + } +#endif /* HAVE_GET_FILE_SIZE_EX */ + + CloseHandle(dev); + return 0; +} + +#else + +static int valid_offset (int fd, ext2_loff_t offset) +{ + char ch; + + if (ext2fs_llseek (fd, offset, 0) < 0) + return 0; + if (read (fd, &ch, 1) < 1) + return 0; + return 1; +} + +/* + * Returns the number of blocks in a partition + */ +errcode_t ext2fs_get_device_size2(const char *file, int blocksize, + blk64_t *retblocks) +{ + int fd, rc = 0; +#ifdef __linux__ + struct utsname ut; +#endif + unsigned long long size64; + ext2_loff_t high, low; +#ifdef FDGETPRM + struct floppy_struct this_floppy; +#endif +#ifdef HAVE_SYS_DISKLABEL_H + int part; + struct disklabel lab; + struct partition *pp; + char ch; +#endif /* HAVE_SYS_DISKLABEL_H */ + +#ifdef HAVE_OPEN64 + fd = open64(file, O_RDONLY); +#else + fd = open(file, O_RDONLY); +#endif + if (fd < 0) + return errno; + +#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */ + if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) { + *retblocks = size64 / (blocksize / 512); + goto out; + } +#endif + +#ifdef BLKGETSIZE64 +#ifdef __linux__ + if ((uname(&ut) == 0) && + ((ut.release[0] == '2') && (ut.release[1] == '.') && + (ut.release[2] < '6') && (ut.release[3] == '.'))) + valid_blkgetsize64 = 0; +#endif + if (valid_blkgetsize64 && + ioctl(fd, BLKGETSIZE64, &size64) >= 0) { + *retblocks = size64 / blocksize; + goto out; + } +#endif + +#ifdef BLKGETSIZE + if (ioctl(fd, BLKGETSIZE, &size) >= 0) { + *retblocks = size / (blocksize / 512); + goto out; + } +#endif + +#ifdef FDGETPRM + if (ioctl(fd, FDGETPRM, &this_floppy) >= 0) { + *retblocks = this_floppy.size / (blocksize / 512); + goto out; + } +#endif + +#ifdef HAVE_SYS_DISKLABEL_H +#if defined(DIOCGMEDIASIZE) + { + off_t ms; + u_int bs; + if (ioctl(fd, DIOCGMEDIASIZE, &ms) >= 0) { + *retblocks = ms / blocksize; + goto out; + } + } +#elif defined(DIOCGDINFO) + /* old disklabel interface */ + part = strlen(file) - 1; + if (part >= 0) { + ch = file[part]; + if (isdigit(ch)) + part = 0; + else if (ch >= 'a' && ch <= 'h') + part = ch - 'a'; + else + part = -1; + } + if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) { + pp = &lab.d_partitions[part]; + if (pp->p_size) { + *retblocks = pp->p_size / (blocksize / 512); + goto out; + } + } +#endif /* defined(DIOCG*) */ +#endif /* HAVE_SYS_DISKLABEL_H */ + + { +#ifdef HAVE_FSTAT64 + struct stat64 st; + if (fstat64(fd, &st) == 0) +#else + struct stat st; + if (fstat(fd, &st) == 0) +#endif + if (S_ISREG(st.st_mode)) { + *retblocks = st.st_size / blocksize; + goto out; + } + } + + /* + * OK, we couldn't figure it out by using a specialized ioctl, + * which is generally the best way. So do binary search to + * find the size of the partition. + */ + low = 0; + for (high = 1024; valid_offset (fd, high); high *= 2) + low = high; + while (low < high - 1) + { + const ext2_loff_t mid = (low + high) / 2; + + if (valid_offset (fd, mid)) + low = mid; + else + high = mid; + } + valid_offset (fd, 0); + size64 = low + 1; + *retblocks = size64 / blocksize; +out: + close(fd); + return rc; +} + +errcode_t ext2fs_get_device_size(const char *file, int blocksize, + blk_t *retblocks) +{ + errcode_t retval; + blk64_t blocks; + + retval = ext2fs_get_device_size2(file, blocksize, &blocks); + if (retval) + return retval; + if (blocks >= (1ULL << 32)) + return EFBIG; + *retblocks = (blk_t) blocks; + return 0; +} + +#endif /* WIN32 */ + +#ifdef DEBUG +int main(int argc, char **argv) +{ + blk_t blocks; + int retval; + + if (argc < 2) { + fprintf(stderr, "Usage: %s device\n", argv[0]); + exit(1); + } + + retval = ext2fs_get_device_size(argv[1], 1024, &blocks); + if (retval) { + com_err(argv[0], retval, + "while calling ext2fs_get_device_size"); + exit(1); + } + printf("Device %s has %u 1k blocks.\n", argv[1], blocks); + exit(0); +} +#endif diff --git a/libcustomext2fs/source/i_block.c b/libcustomext2fs/source/i_block.c new file mode 100644 index 00000000..39d93eec --- /dev/null +++ b/libcustomext2fs/source/i_block.c @@ -0,0 +1,89 @@ +/* + * i_block.c --- Manage the i_block field for i_blocks + * + * Copyright (C) 2008 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode, + blk64_t num_blocks) +{ + unsigned long long b = inode->i_blocks; + + if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32; + + if (!(fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || + !(inode->i_flags & EXT4_HUGE_FILE_FL)) + num_blocks *= fs->blocksize / 512; + + b += num_blocks; + + if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + inode->osd2.linux2.l_i_blocks_hi = b >> 32; + else if (b > 0xFFFFFFFF) + return EOVERFLOW; + inode->i_blocks = b & 0xFFFFFFFF; + return 0; +} + +errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode, + blk64_t num_blocks) +{ + unsigned long long b = inode->i_blocks; + + if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + b += ((long long) inode->osd2.linux2.l_i_blocks_hi) << 32; + + if (!(fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || + !(inode->i_flags & EXT4_HUGE_FILE_FL)) + num_blocks *= fs->blocksize / 512; + + if (num_blocks > b) + return EOVERFLOW; + + b -= num_blocks; + + if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + inode->osd2.linux2.l_i_blocks_hi = b >> 32; + inode->i_blocks = b & 0xFFFFFFFF; + return 0; +} + +errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b) +{ + if (!(fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || + !(inode->i_flags & EXT4_HUGE_FILE_FL)) + b *= fs->blocksize / 512; + + inode->i_blocks = b & 0xFFFFFFFF; + if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) + inode->osd2.linux2.l_i_blocks_hi = b >> 32; + else if (b >> 32) + return EOVERFLOW; + return 0; +} diff --git a/libcustomext2fs/source/icount.c b/libcustomext2fs/source/icount.c new file mode 100644 index 00000000..43cc53e1 --- /dev/null +++ b/libcustomext2fs/source/icount.c @@ -0,0 +1,862 @@ +/* + * icount.c --- an efficient inode count abstraction + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "tdb.h" + +/* + * The data storage strategy used by icount relies on the observation + * that most inode counts are either zero (for non-allocated inodes), + * one (for most files), and only a few that are two or more + * (directories and files that are linked to more than one directory). + * + * Also, e2fsck tends to load the icount data sequentially. + * + * So, we use an inode bitmap to indicate which inodes have a count of + * one, and then use a sorted list to store the counts for inodes + * which are greater than one. + * + * We also use an optional bitmap to indicate which inodes are already + * in the sorted list, to speed up the use of this abstraction by + * e2fsck's pass 2. Pass 2 increments inode counts as it finds them, + * so this extra bitmap avoids searching the sorted list to see if a + * particular inode is on the sorted list already. + */ + +struct ext2_icount_el { + ext2_ino_t ino; + __u32 count; +}; + +struct ext2_icount { + errcode_t magic; + ext2fs_inode_bitmap single; + ext2fs_inode_bitmap multiple; + ext2_ino_t count; + ext2_ino_t size; + ext2_ino_t num_inodes; + ext2_ino_t cursor; + struct ext2_icount_el *list; + struct ext2_icount_el *last_lookup; + char *tdb_fn; + TDB_CONTEXT *tdb; +}; + +/* + * We now use a 32-bit counter field because it doesn't cost us + * anything extra for the in-memory data structure, due to alignment + * padding. But there's no point changing the interface if most of + * the time we only care if the number is bigger than 65,000 or not. + * So use the following translation function to return a 16-bit count. + */ +#define icount_16_xlate(x) (((x) > 65500) ? 65500 : (x)) + +void ext2fs_free_icount(ext2_icount_t icount) +{ + if (!icount) + return; + + icount->magic = 0; + if (icount->list) + ext2fs_free_mem(&icount->list); + if (icount->single) + ext2fs_free_inode_bitmap(icount->single); + if (icount->multiple) + ext2fs_free_inode_bitmap(icount->multiple); + if (icount->tdb) + tdb_close(icount->tdb); + if (icount->tdb_fn) { + unlink(icount->tdb_fn); + free(icount->tdb_fn); + } + + ext2fs_free_mem(&icount); +} + +static errcode_t alloc_icount(ext2_filsys fs, int flags, ext2_icount_t *ret) +{ + ext2_icount_t icount; + errcode_t retval; + + *ret = 0; + + retval = ext2fs_get_mem(sizeof(struct ext2_icount), &icount); + if (retval) + return retval; + memset(icount, 0, sizeof(struct ext2_icount)); + + retval = ext2fs_allocate_inode_bitmap(fs, 0, &icount->single); + if (retval) + goto errout; + + if (flags & EXT2_ICOUNT_OPT_INCREMENT) { + retval = ext2fs_allocate_inode_bitmap(fs, 0, + &icount->multiple); + if (retval) + goto errout; + } else + icount->multiple = 0; + + icount->magic = EXT2_ET_MAGIC_ICOUNT; + icount->num_inodes = fs->super->s_inodes_count; + + *ret = icount; + return 0; + +errout: + ext2fs_free_icount(icount); + return(retval); +} + +struct uuid { + __u32 time_low; + __u16 time_mid; + __u16 time_hi_and_version; + __u16 clock_seq; + __u8 node[6]; +}; + +static void unpack_uuid(void *in, struct uuid *uu) +{ + __u8 *ptr = in; + __u32 tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_low = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_mid = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_hi_and_version = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->clock_seq = tmp; + + memcpy(uu->node, ptr, 6); +} + +static void uuid_unparse(void *uu, char *out) +{ + struct uuid uuid; + + unpack_uuid(uu, &uuid); + sprintf(out, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, + uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, + uuid.node[0], uuid.node[1], uuid.node[2], + uuid.node[3], uuid.node[4], uuid.node[5]); +} + +errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir, + int flags, ext2_icount_t *ret) +{ + ext2_icount_t icount; + errcode_t retval; + char *fn, uuid[40]; + int fd; + + retval = alloc_icount(fs, flags, &icount); + if (retval) + return retval; + + retval = ext2fs_get_mem(strlen(tdb_dir) + 64, &fn); + if (retval) + goto errout; + uuid_unparse(fs->super->s_uuid, uuid); + sprintf(fn, "%s/%s-icount-XXXXXX", tdb_dir, uuid); + fd = mkstemp(fn); + + icount->tdb_fn = fn; + icount->tdb = tdb_open(fn, 0, TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT | O_TRUNC, 0600); + if (icount->tdb) { + close(fd); + *ret = icount; + return 0; + } + + retval = errno; + close(fd); + +errout: + ext2fs_free_icount(icount); + return(retval); +} + +errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, unsigned int size, + ext2_icount_t hint, ext2_icount_t *ret) +{ + ext2_icount_t icount; + errcode_t retval; + size_t bytes; + ext2_ino_t i; + + if (hint) { + EXT2_CHECK_MAGIC(hint, EXT2_ET_MAGIC_ICOUNT); + if (hint->size > size) + size = (size_t) hint->size; + } + + retval = alloc_icount(fs, flags, &icount); + if (retval) + return retval; + + if (size) { + icount->size = size; + } else { + /* + * Figure out how many special case inode counts we will + * have. We know we will need one for each directory; + * we also need to reserve some extra room for file links + */ + retval = ext2fs_get_num_dirs(fs, &icount->size); + if (retval) + goto errout; + icount->size += fs->super->s_inodes_count / 50; + } + + bytes = (size_t) (icount->size * sizeof(struct ext2_icount_el)); +#if 0 + printf("Icount allocated %u entries, %d bytes.\n", + icount->size, bytes); +#endif + retval = ext2fs_get_array(icount->size, sizeof(struct ext2_icount_el), + &icount->list); + if (retval) + goto errout; + memset(icount->list, 0, bytes); + + icount->count = 0; + icount->cursor = 0; + + /* + * Populate the sorted list with those entries which were + * found in the hint icount (since those are ones which will + * likely need to be in the sorted list this time around). + */ + if (hint) { + for (i=0; i < hint->count; i++) + icount->list[i].ino = hint->list[i].ino; + icount->count = hint->count; + } + + *ret = icount; + return 0; + +errout: + ext2fs_free_icount(icount); + return(retval); +} + +errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, + unsigned int size, + ext2_icount_t *ret) +{ + return ext2fs_create_icount2(fs, flags, size, 0, ret); +} + +/* + * insert_icount_el() --- Insert a new entry into the sorted list at a + * specified position. + */ +static struct ext2_icount_el *insert_icount_el(ext2_icount_t icount, + ext2_ino_t ino, int pos) +{ + struct ext2_icount_el *el; + errcode_t retval; + ext2_ino_t new_size = 0; + int num; + + if (icount->last_lookup && icount->last_lookup->ino == ino) + return icount->last_lookup; + + if (icount->count >= icount->size) { + if (icount->count) { + new_size = icount->list[(unsigned)icount->count-1].ino; + new_size = (ext2_ino_t) (icount->count * + ((float) icount->num_inodes / new_size)); + } + if (new_size < (icount->size + 100)) + new_size = icount->size + 100; +#if 0 + printf("Reallocating icount %u entries...\n", new_size); +#endif + retval = ext2fs_resize_mem((size_t) icount->size * + sizeof(struct ext2_icount_el), + (size_t) new_size * + sizeof(struct ext2_icount_el), + &icount->list); + if (retval) + return 0; + icount->size = new_size; + } + num = (int) icount->count - pos; + if (num < 0) + return 0; /* should never happen */ + if (num) { + memmove(&icount->list[pos+1], &icount->list[pos], + sizeof(struct ext2_icount_el) * num); + } + icount->count++; + el = &icount->list[pos]; + el->count = 0; + el->ino = ino; + icount->last_lookup = el; + return el; +} + +/* + * get_icount_el() --- given an inode number, try to find icount + * information in the sorted list. If the create flag is set, + * and we can't find an entry, create one in the sorted list. + */ +static struct ext2_icount_el *get_icount_el(ext2_icount_t icount, + ext2_ino_t ino, int create) +{ + float range; + int low, high, mid; + ext2_ino_t lowval, highval; + + if (!icount || !icount->list) + return 0; + + if (create && ((icount->count == 0) || + (ino > icount->list[(unsigned)icount->count-1].ino))) { + return insert_icount_el(icount, ino, (unsigned) icount->count); + } + if (icount->count == 0) + return 0; + + if (icount->cursor >= icount->count) + icount->cursor = 0; + if (ino == icount->list[icount->cursor].ino) + return &icount->list[icount->cursor++]; +#if 0 + printf("Non-cursor get_icount_el: %u\n", ino); +#endif + low = 0; + high = (int) icount->count-1; + while (low <= high) { +#if 0 + mid = (low+high)/2; +#else + if (low == high) + mid = low; + else { + /* Interpolate for efficiency */ + lowval = icount->list[low].ino; + highval = icount->list[high].ino; + + if (ino < lowval) + range = 0; + else if (ino > highval) + range = 1; + else { + range = ((float) (ino - lowval)) / + (highval - lowval); + if (range > 0.9) + range = 0.9; + if (range < 0.1) + range = 0.1; + } + mid = low + ((int) (range * (high-low))); + } +#endif + if (ino == icount->list[mid].ino) { + icount->cursor = mid+1; + return &icount->list[mid]; + } + if (ino < icount->list[mid].ino) + high = mid-1; + else + low = mid+1; + } + /* + * If we need to create a new entry, it should be right at + * low (where high will be left at low-1). + */ + if (create) + return insert_icount_el(icount, ino, low); + return 0; +} + +static errcode_t set_inode_count(ext2_icount_t icount, ext2_ino_t ino, + __u32 count) +{ + struct ext2_icount_el *el; + TDB_DATA key, data; + + if (icount->tdb) { + key.dptr = (unsigned char *) &ino; + key.dsize = sizeof(ext2_ino_t); + data.dptr = (unsigned char *) &count; + data.dsize = sizeof(__u32); + if (count) { + if (tdb_store(icount->tdb, key, data, TDB_REPLACE)) + return tdb_error(icount->tdb) + + EXT2_ET_TDB_SUCCESS; + } else { + if (tdb_delete(icount->tdb, key)) + return tdb_error(icount->tdb) + + EXT2_ET_TDB_SUCCESS; + } + return 0; + } + + el = get_icount_el(icount, ino, 1); + if (!el) + return EXT2_ET_NO_MEMORY; + + el->count = count; + return 0; +} + +static errcode_t get_inode_count(ext2_icount_t icount, ext2_ino_t ino, + __u32 *count) +{ + struct ext2_icount_el *el; + TDB_DATA key, data; + + if (icount->tdb) { + key.dptr = (unsigned char *) &ino; + key.dsize = sizeof(ext2_ino_t); + + data = tdb_fetch(icount->tdb, key); + if (data.dptr == NULL) { + *count = 0; + return tdb_error(icount->tdb) + EXT2_ET_TDB_SUCCESS; + } + + *count = *((__u32 *) data.dptr); + free(data.dptr); + return 0; + } + el = get_icount_el(icount, ino, 0); + if (!el) { + *count = 0; + return ENOENT; + } + + *count = el->count; + return 0; +} + +errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *out) +{ + errcode_t ret = 0; + unsigned int i; + const char *bad = "bad icount"; + + EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); + + if (icount->count > icount->size) { + fprintf(out, "%s: count > size\n", bad); + return EXT2_ET_INVALID_ARGUMENT; + } + for (i=1; i < icount->count; i++) { + if (icount->list[i-1].ino >= icount->list[i].ino) { + fprintf(out, "%s: list[%d].ino=%u, list[%d].ino=%u\n", + bad, i-1, icount->list[i-1].ino, + i, icount->list[i].ino); + ret = EXT2_ET_INVALID_ARGUMENT; + } + } + return ret; +} + +errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino, __u16 *ret) +{ + __u32 val; + EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); + + if (!ino || (ino > icount->num_inodes)) + return EXT2_ET_INVALID_ARGUMENT; + + if (ext2fs_test_inode_bitmap2(icount->single, ino)) { + *ret = 1; + return 0; + } + if (icount->multiple && + !ext2fs_test_inode_bitmap2(icount->multiple, ino)) { + *ret = 0; + return 0; + } + get_inode_count(icount, ino, &val); + *ret = icount_16_xlate(val); + return 0; +} + +errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino, + __u16 *ret) +{ + __u32 curr_value; + + EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); + + if (!ino || (ino > icount->num_inodes)) + return EXT2_ET_INVALID_ARGUMENT; + + if (ext2fs_test_inode_bitmap2(icount->single, ino)) { + /* + * If the existing count is 1, then we know there is + * no entry in the list. + */ + if (set_inode_count(icount, ino, 2)) + return EXT2_ET_NO_MEMORY; + curr_value = 2; + ext2fs_unmark_inode_bitmap2(icount->single, ino); + } else if (icount->multiple) { + /* + * The count is either zero or greater than 1; if the + * inode is set in icount->multiple, then there should + * be an entry in the list, so we need to fix it. + */ + if (ext2fs_test_inode_bitmap2(icount->multiple, ino)) { + get_inode_count(icount, ino, &curr_value); + curr_value++; + if (set_inode_count(icount, ino, curr_value)) + return EXT2_ET_NO_MEMORY; + } else { + /* + * The count was zero; mark the single bitmap + * and return. + */ + ext2fs_mark_inode_bitmap2(icount->single, ino); + if (ret) + *ret = 1; + return 0; + } + } else { + /* + * The count is either zero or greater than 1; try to + * find an entry in the list to determine which. + */ + get_inode_count(icount, ino, &curr_value); + curr_value++; + if (set_inode_count(icount, ino, curr_value)) + return EXT2_ET_NO_MEMORY; + } + if (icount->multiple) + ext2fs_mark_inode_bitmap2(icount->multiple, ino); + if (ret) + *ret = icount_16_xlate(curr_value); + return 0; +} + +errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino, + __u16 *ret) +{ + __u32 curr_value; + + if (!ino || (ino > icount->num_inodes)) + return EXT2_ET_INVALID_ARGUMENT; + + EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); + + if (ext2fs_test_inode_bitmap2(icount->single, ino)) { + ext2fs_unmark_inode_bitmap2(icount->single, ino); + if (icount->multiple) + ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + else { + set_inode_count(icount, ino, 0); + } + if (ret) + *ret = 0; + return 0; + } + + if (icount->multiple && + !ext2fs_test_inode_bitmap2(icount->multiple, ino)) + return EXT2_ET_INVALID_ARGUMENT; + + get_inode_count(icount, ino, &curr_value); + if (!curr_value) + return EXT2_ET_INVALID_ARGUMENT; + curr_value--; + if (set_inode_count(icount, ino, curr_value)) + return EXT2_ET_NO_MEMORY; + + if (curr_value == 1) + ext2fs_mark_inode_bitmap2(icount->single, ino); + if ((curr_value == 0) && icount->multiple) + ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + + if (ret) + *ret = icount_16_xlate(curr_value); + return 0; +} + +errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino, + __u16 count) +{ + if (!ino || (ino > icount->num_inodes)) + return EXT2_ET_INVALID_ARGUMENT; + + EXT2_CHECK_MAGIC(icount, EXT2_ET_MAGIC_ICOUNT); + + if (count == 1) { + ext2fs_mark_inode_bitmap2(icount->single, ino); + if (icount->multiple) + ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + return 0; + } + if (count == 0) { + ext2fs_unmark_inode_bitmap2(icount->single, ino); + if (icount->multiple) { + /* + * If the icount->multiple bitmap is enabled, + * we can just clear both bitmaps and we're done + */ + ext2fs_unmark_inode_bitmap2(icount->multiple, ino); + } else + set_inode_count(icount, ino, 0); + return 0; + } + + if (set_inode_count(icount, ino, count)) + return EXT2_ET_NO_MEMORY; + ext2fs_unmark_inode_bitmap2(icount->single, ino); + if (icount->multiple) + ext2fs_mark_inode_bitmap2(icount->multiple, ino); + return 0; +} + +ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount) +{ + if (!icount || icount->magic != EXT2_ET_MAGIC_ICOUNT) + return 0; + + return icount->size; +} + +#ifdef DEBUG + +ext2_filsys test_fs; +ext2_icount_t icount; + +#define EXIT 0x00 +#define FETCH 0x01 +#define STORE 0x02 +#define INCREMENT 0x03 +#define DECREMENT 0x04 + +struct test_program { + int cmd; + ext2_ino_t ino; + __u16 arg; + __u16 expected; +}; + +struct test_program prog[] = { + { STORE, 42, 42, 42 }, + { STORE, 1, 1, 1 }, + { STORE, 2, 2, 2 }, + { STORE, 3, 3, 3 }, + { STORE, 10, 1, 1 }, + { STORE, 42, 0, 0 }, + { INCREMENT, 5, 0, 1 }, + { INCREMENT, 5, 0, 2 }, + { INCREMENT, 5, 0, 3 }, + { INCREMENT, 5, 0, 4 }, + { DECREMENT, 5, 0, 3 }, + { DECREMENT, 5, 0, 2 }, + { DECREMENT, 5, 0, 1 }, + { DECREMENT, 5, 0, 0 }, + { FETCH, 10, 0, 1 }, + { FETCH, 1, 0, 1 }, + { FETCH, 2, 0, 2 }, + { FETCH, 3, 0, 3 }, + { INCREMENT, 1, 0, 2 }, + { DECREMENT, 2, 0, 1 }, + { DECREMENT, 2, 0, 0 }, + { FETCH, 12, 0, 0 }, + { EXIT, 0, 0, 0 } +}; + +struct test_program extended[] = { + { STORE, 1, 1, 1 }, + { STORE, 2, 2, 2 }, + { STORE, 3, 3, 3 }, + { STORE, 4, 4, 4 }, + { STORE, 5, 5, 5 }, + { STORE, 6, 1, 1 }, + { STORE, 7, 2, 2 }, + { STORE, 8, 3, 3 }, + { STORE, 9, 4, 4 }, + { STORE, 10, 5, 5 }, + { STORE, 11, 1, 1 }, + { STORE, 12, 2, 2 }, + { STORE, 13, 3, 3 }, + { STORE, 14, 4, 4 }, + { STORE, 15, 5, 5 }, + { STORE, 16, 1, 1 }, + { STORE, 17, 2, 2 }, + { STORE, 18, 3, 3 }, + { STORE, 19, 4, 4 }, + { STORE, 20, 5, 5 }, + { STORE, 21, 1, 1 }, + { STORE, 22, 2, 2 }, + { STORE, 23, 3, 3 }, + { STORE, 24, 4, 4 }, + { STORE, 25, 5, 5 }, + { STORE, 26, 1, 1 }, + { STORE, 27, 2, 2 }, + { STORE, 28, 3, 3 }, + { STORE, 29, 4, 4 }, + { STORE, 30, 5, 5 }, + { EXIT, 0, 0, 0 } +}; + +/* + * Setup the variables for doing the inode scan test. + */ +static void setup(void) +{ + errcode_t retval; + struct ext2_super_block param; + + initialize_ext2_error_table(); + + memset(¶m, 0, sizeof(param)); + ext2fs_blocks_count_set(¶m, 12000); + + retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m, + test_io_manager, &test_fs); + if (retval) { + com_err("setup", retval, + "while initializing filesystem"); + exit(1); + } + retval = ext2fs_allocate_tables(test_fs); + if (retval) { + com_err("setup", retval, + "while allocating tables for test filesystem"); + exit(1); + } +} + +int run_test(int flags, int size, char *dir, struct test_program *prog) +{ + errcode_t retval; + ext2_icount_t icount; + struct test_program *pc; + __u16 result; + int problem = 0; + + if (dir) { + retval = ext2fs_create_icount_tdb(test_fs, dir, + flags, &icount); + if (retval) { + com_err("run_test", retval, + "while creating icount using tdb"); + exit(1); + } + } else { + retval = ext2fs_create_icount2(test_fs, flags, size, 0, + &icount); + if (retval) { + com_err("run_test", retval, "while creating icount"); + exit(1); + } + } + for (pc = prog; pc->cmd != EXIT; pc++) { + switch (pc->cmd) { + case FETCH: + printf("icount_fetch(%u) = ", pc->ino); + break; + case STORE: + retval = ext2fs_icount_store(icount, pc->ino, pc->arg); + if (retval) { + com_err("run_test", retval, + "while calling icount_store"); + exit(1); + } + printf("icount_store(%u, %u) = ", pc->ino, pc->arg); + break; + case INCREMENT: + retval = ext2fs_icount_increment(icount, pc->ino, 0); + if (retval) { + com_err("run_test", retval, + "while calling icount_increment"); + exit(1); + } + printf("icount_increment(%u) = ", pc->ino); + break; + case DECREMENT: + retval = ext2fs_icount_decrement(icount, pc->ino, 0); + if (retval) { + com_err("run_test", retval, + "while calling icount_decrement"); + exit(1); + } + printf("icount_decrement(%u) = ", pc->ino); + break; + } + retval = ext2fs_icount_fetch(icount, pc->ino, &result); + if (retval) { + com_err("run_test", retval, + "while calling icount_fetch"); + exit(1); + } + printf("%u (%s)\n", result, (result == pc->expected) ? + "OK" : "NOT OK"); + if (result != pc->expected) + problem++; + } + printf("icount size is %u\n", ext2fs_get_icount_size(icount)); + retval = ext2fs_icount_validate(icount, stdout); + if (retval) { + com_err("run_test", retval, "while calling icount_validate"); + exit(1); + } + ext2fs_free_icount(icount); + return problem; +} + + +int main(int argc, char **argv) +{ + int failed = 0; + + setup(); + printf("Standard icount run:\n"); + failed += run_test(0, 0, 0, prog); + printf("\nMultiple bitmap test:\n"); + failed += run_test(EXT2_ICOUNT_OPT_INCREMENT, 0, 0, prog); + printf("\nResizing icount:\n"); + failed += run_test(0, 3, 0, extended); + printf("\nStandard icount run with tdb:\n"); + failed += run_test(0, 0, ".", prog); + printf("\nMultiple bitmap test with tdb:\n"); + failed += run_test(EXT2_ICOUNT_OPT_INCREMENT, 0, ".", prog); + if (failed) + printf("FAILED!\n"); + return failed; +} +#endif diff --git a/libcustomext2fs/source/imager.c b/libcustomext2fs/source/imager.c new file mode 100644 index 00000000..5a6d0b95 --- /dev/null +++ b/libcustomext2fs/source/imager.c @@ -0,0 +1,408 @@ +/* + * image.c --- writes out the critical parts of the filesystem as a + * flat file. + * + * Copyright (C) 2000 Theodore Ts'o. + * + * Note: this uses the POSIX IO interfaces, unlike most of the other + * functions in this library. So sue me. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifndef HAVE_TYPE_SSIZE_T +typedef int ssize_t; +#endif + +/* + * This function returns 1 if the specified block is all zeros + */ +static int check_zero_block(char *buf, int blocksize) +{ + char *cp = buf; + int left = blocksize; + + while (left > 0) { + if (*cp++) + return 0; + left--; + } + return 1; +} + +/* + * Write the inode table out as a single block. + */ +#define BUF_BLOCKS 32 + +errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags) +{ + unsigned int group, left, c, d; + char *buf, *cp; + blk64_t blk; + ssize_t actual; + errcode_t retval; + + buf = malloc(fs->blocksize * BUF_BLOCKS); + if (!buf) + return ENOMEM; + + for (group = 0; group < fs->group_desc_count; group++) { + blk = ext2fs_inode_table_loc(fs, (unsigned)group); + if (!blk) { + retval = EXT2_ET_MISSING_INODE_TABLE; + goto errout; + } + left = fs->inode_blocks_per_group; + while (left) { + c = BUF_BLOCKS; + if (c > left) + c = left; + retval = io_channel_read_blk64(fs->io, blk, c, buf); + if (retval) + goto errout; + cp = buf; + while (c) { + if (!(flags & IMAGER_FLAG_SPARSEWRITE)) { + d = c; + goto skip_sparse; + } + /* Skip zero blocks */ + if (check_zero_block(cp, fs->blocksize)) { + c--; + blk++; + left--; + cp += fs->blocksize; + lseek(fd, fs->blocksize, SEEK_CUR); + continue; + } + /* Find non-zero blocks */ + for (d=1; d < c; d++) { + if (check_zero_block(cp + d*fs->blocksize, fs->blocksize)) + break; + } + skip_sparse: + actual = write(fd, cp, fs->blocksize * d); + if (actual == -1) { + retval = errno; + goto errout; + } + if (actual != (ssize_t) (fs->blocksize * d)) { + retval = EXT2_ET_SHORT_WRITE; + goto errout; + } + blk += d; + left -= d; + cp += fs->blocksize * d; + c -= d; + } + } + } + retval = 0; + +errout: + free(buf); + return retval; +} + +/* + * Read in the inode table and stuff it into place + */ +errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, + int flags EXT2FS_ATTR((unused))) +{ + unsigned int group, c, left; + char *buf; + blk64_t blk; + ssize_t actual; + errcode_t retval; + + buf = malloc(fs->blocksize * BUF_BLOCKS); + if (!buf) + return ENOMEM; + + for (group = 0; group < fs->group_desc_count; group++) { + blk = ext2fs_inode_table_loc(fs, (unsigned)group); + if (!blk) { + retval = EXT2_ET_MISSING_INODE_TABLE; + goto errout; + } + left = fs->inode_blocks_per_group; + while (left) { + c = BUF_BLOCKS; + if (c > left) + c = left; + actual = read(fd, buf, fs->blocksize * c); + if (actual == -1) { + retval = errno; + goto errout; + } + if (actual != (ssize_t) (fs->blocksize * c)) { + retval = EXT2_ET_SHORT_READ; + goto errout; + } + retval = io_channel_write_blk64(fs->io, blk, c, buf); + if (retval) + goto errout; + + blk += c; + left -= c; + } + } + retval = ext2fs_flush_icache(fs); + +errout: + free(buf); + return retval; +} + +/* + * Write out superblock and group descriptors + */ +errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, + int flags EXT2FS_ATTR((unused))) +{ + char *buf, *cp; + ssize_t actual; + errcode_t retval; + + buf = malloc(fs->blocksize); + if (!buf) + return ENOMEM; + + /* + * Write out the superblock + */ + memset(buf, 0, fs->blocksize); + memcpy(buf, fs->super, SUPERBLOCK_SIZE); + actual = write(fd, buf, fs->blocksize); + if (actual == -1) { + retval = errno; + goto errout; + } + if (actual != (ssize_t) fs->blocksize) { + retval = EXT2_ET_SHORT_WRITE; + goto errout; + } + + /* + * Now write out the block group descriptors + */ + cp = (char *) fs->group_desc; + actual = write(fd, cp, fs->blocksize * fs->desc_blocks); + if (actual == -1) { + retval = errno; + goto errout; + } + if (actual != (ssize_t) (fs->blocksize * fs->desc_blocks)) { + retval = EXT2_ET_SHORT_WRITE; + goto errout; + } + + retval = 0; + +errout: + free(buf); + return retval; +} + +/* + * Read the superblock and group descriptors and overwrite them. + */ +errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, + int flags EXT2FS_ATTR((unused))) +{ + char *buf; + ssize_t actual, size; + errcode_t retval; + + size = fs->blocksize * (fs->group_desc_count + 1); + buf = malloc(size); + if (!buf) + return ENOMEM; + + /* + * Read it all in. + */ + actual = read(fd, buf, size); + if (actual == -1) { + retval = errno; + goto errout; + } + if (actual != size) { + retval = EXT2_ET_SHORT_READ; + goto errout; + } + + /* + * Now copy in the superblock and group descriptors + */ + memcpy(fs->super, buf, SUPERBLOCK_SIZE); + + memcpy(fs->group_desc, buf + fs->blocksize, + fs->blocksize * fs->group_desc_count); + + retval = 0; + +errout: + free(buf); + return retval; +} + +/* + * Write the block/inode bitmaps. + */ +errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags) +{ + ext2fs_generic_bitmap bmap; + errcode_t err, retval; + ssize_t actual; + __u32 itr, cnt, size; + int c, total_size; + char buf[1024]; + + if (flags & IMAGER_FLAG_INODEMAP) { + if (!fs->inode_map) { + retval = ext2fs_read_inode_bitmap(fs); + if (retval) + return retval; + } + bmap = fs->inode_map; + err = EXT2_ET_MAGIC_INODE_BITMAP; + itr = 1; + cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; + size = (EXT2_INODES_PER_GROUP(fs->super) / 8); + } else { + if (!fs->block_map) { + retval = ext2fs_read_block_bitmap(fs); + if (retval) + return retval; + } + bmap = fs->block_map; + err = EXT2_ET_MAGIC_BLOCK_BITMAP; + itr = fs->super->s_first_data_block; + cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; + size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + } + total_size = size * fs->group_desc_count; + + while (cnt > 0) { + size = sizeof(buf); + if (size > (cnt >> 3)) + size = (cnt >> 3); + + retval = ext2fs_get_generic_bmap_range(bmap, itr, + size << 3, buf); + if (retval) + return retval; + + actual = write(fd, buf, size); + if (actual == -1) + return errno; + if (actual != (int) size) + return EXT2_ET_SHORT_READ; + + itr += size << 3; + cnt -= size << 3; + } + + size = total_size % fs->blocksize; + memset(buf, 0, sizeof(buf)); + if (size) { + size = fs->blocksize - size; + while (size) { + c = size; + if (c > (int) sizeof(buf)) + c = sizeof(buf); + actual = write(fd, buf, c); + if (actual == -1) + return errno; + if (actual != c) + return EXT2_ET_SHORT_WRITE; + size -= c; + } + } + return 0; +} + + +/* + * Read the block/inode bitmaps. + */ +errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags) +{ + ext2fs_generic_bitmap bmap; + errcode_t err, retval; + __u32 itr, cnt; + char buf[1024]; + unsigned int size; + ssize_t actual; + + if (flags & IMAGER_FLAG_INODEMAP) { + if (!fs->inode_map) { + retval = ext2fs_read_inode_bitmap(fs); + if (retval) + return retval; + } + bmap = fs->inode_map; + err = EXT2_ET_MAGIC_INODE_BITMAP; + itr = 1; + cnt = EXT2_INODES_PER_GROUP(fs->super) * fs->group_desc_count; + size = (EXT2_INODES_PER_GROUP(fs->super) / 8); + } else { + if (!fs->block_map) { + retval = ext2fs_read_block_bitmap(fs); + if (retval) + return retval; + } + bmap = fs->block_map; + err = EXT2_ET_MAGIC_BLOCK_BITMAP; + itr = fs->super->s_first_data_block; + cnt = EXT2_BLOCKS_PER_GROUP(fs->super) * fs->group_desc_count; + size = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + } + + while (cnt > 0) { + size = sizeof(buf); + if (size > (cnt >> 3)) + size = (cnt >> 3); + + actual = read(fd, buf, size); + if (actual == -1) + return errno; + if (actual != (int) size) + return EXT2_ET_SHORT_READ; + + retval = ext2fs_set_generic_bmap_range(bmap, itr, + size << 3, buf); + if (retval) + return retval; + + itr += size << 3; + cnt -= size << 3; + } + return 0; +} diff --git a/libcustomext2fs/source/ind_block.c b/libcustomext2fs/source/ind_block.c new file mode 100644 index 00000000..722d3bdc --- /dev/null +++ b/libcustomext2fs/source/ind_block.c @@ -0,0 +1,66 @@ +/* + * ind_block.c --- indirect block I/O routines + * + * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, + * 2001, 2002, 2003, 2004, 2005 by Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf) +{ + errcode_t retval; +#ifdef WORDS_BIGENDIAN + blk_t *block_nr; + int i; + int limit = fs->blocksize >> 2; +#endif + + if ((fs->flags & EXT2_FLAG_IMAGE_FILE) && + (fs->io != fs->image_io)) + memset(buf, 0, fs->blocksize); + else { + retval = io_channel_read_blk(fs->io, blk, 1, buf); + if (retval) + return retval; + } +#ifdef WORDS_BIGENDIAN + block_nr = (blk_t *) buf; + for (i = 0; i < limit; i++, block_nr++) + *block_nr = ext2fs_swab32(*block_nr); +#endif + return 0; +} + +errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf) +{ +#ifdef WORDS_BIGENDIAN + blk_t *block_nr; + int i; + int limit = fs->blocksize >> 2; +#endif + + if (fs->flags & EXT2_FLAG_IMAGE_FILE) + return 0; + +#ifdef WORDS_BIGENDIAN + block_nr = (blk_t *) buf; + for (i = 0; i < limit; i++, block_nr++) + *block_nr = ext2fs_swab32(*block_nr); +#endif + return io_channel_write_blk(fs->io, blk, 1, buf); +} + + diff --git a/libcustomext2fs/source/initialize.c b/libcustomext2fs/source/initialize.c new file mode 100644 index 00000000..7c389754 --- /dev/null +++ b/libcustomext2fs/source/initialize.c @@ -0,0 +1,460 @@ +/* + * initialize.c --- initialize a filesystem handle given superblock + * parameters. Used by mke2fs when initializing a filesystem. + * + * Copyright (C) 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#if defined(__linux__) && defined(EXT2_OS_LINUX) +#define CREATOR_OS EXT2_OS_LINUX +#else +#if defined(__GNU__) && defined(EXT2_OS_HURD) +#define CREATOR_OS EXT2_OS_HURD +#else +#if defined(__FreeBSD__) && defined(EXT2_OS_FREEBSD) +#define CREATOR_OS EXT2_OS_FREEBSD +#else +#if defined(LITES) && defined(EXT2_OS_LITES) +#define CREATOR_OS EXT2_OS_LITES +#else +#define CREATOR_OS EXT2_OS_LINUX /* by default */ +#endif /* defined(LITES) && defined(EXT2_OS_LITES) */ +#endif /* defined(__FreeBSD__) && defined(EXT2_OS_FREEBSD) */ +#endif /* defined(__GNU__) && defined(EXT2_OS_HURD) */ +#endif /* defined(__linux__) && defined(EXT2_OS_LINUX) */ + +/* + * Note we override the kernel include file's idea of what the default + * check interval (never) should be. It's a good idea to check at + * least *occasionally*, specially since servers will never rarely get + * to reboot, since Linux is so robust these days. :-) + * + * 180 days (six months) seems like a good value. + */ +#ifdef EXT2_DFL_CHECKINTERVAL +#undef EXT2_DFL_CHECKINTERVAL +#endif +#define EXT2_DFL_CHECKINTERVAL (86400L * 180L) + +/* + * Calculate the number of GDT blocks to reserve for online filesystem growth. + * The absolute maximum number of GDT blocks we can reserve is determined by + * the number of block pointers that can fit into a single block. + */ +static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) +{ + struct ext2_super_block *sb = fs->super; + unsigned long bpg = sb->s_blocks_per_group; + unsigned int gdpb = EXT2_DESC_PER_BLOCK(sb); + unsigned long max_blocks = 0xffffffff; + unsigned long rsv_groups; + unsigned int rsv_gdb; + + /* We set it at 1024x the current filesystem size, or + * the upper block count limit (2^32), whichever is lower. + */ + if (ext2fs_blocks_count(sb) < max_blocks / 1024) + max_blocks = ext2fs_blocks_count(sb) * 1024; + /* + * ext2fs_div64_ceil() is unnecessary because max_blocks is + * max _GDT_ blocks, which is limited to 32 bits. + */ + rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg); + rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks; + if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb)) + rsv_gdb = EXT2_ADDR_PER_BLOCK(sb); +#ifdef RES_GDT_DEBUG + printf("max_blocks %lu, rsv_groups = %lu, rsv_gdb = %u\n", + max_blocks, rsv_groups, rsv_gdb); +#endif + + return rsv_gdb; +} + +errcode_t ext2fs_initialize(const char *name, int flags, + struct ext2_super_block *param, + io_manager manager, ext2_filsys *ret_fs) +{ + ext2_filsys fs; + errcode_t retval; + struct ext2_super_block *super; + int frags_per_block; + unsigned int rem; + unsigned int overhead = 0; + unsigned int ipg; + dgrp_t i; + blk_t numblocks; + int rsv_gdt; + int csum_flag; + int io_flags; + char *buf = 0; + char c; + + if (!param || !ext2fs_blocks_count(param)) + return EXT2_ET_INVALID_ARGUMENT; + + retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs); + if (retval) + return retval; + + memset(fs, 0, sizeof(struct struct_ext2_filsys)); + fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS; + fs->flags = flags | EXT2_FLAG_RW; + fs->umask = 022; +#ifdef WORDS_BIGENDIAN + fs->flags |= EXT2_FLAG_SWAP_BYTES; +#endif + io_flags = IO_FLAG_RW; + if (flags & EXT2_FLAG_EXCLUSIVE) + io_flags |= IO_FLAG_EXCLUSIVE; + retval = manager->open(name, io_flags, &fs->io); + if (retval) + goto cleanup; + fs->image_io = fs->io; + fs->io->app_data = fs; + retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name); + if (retval) + goto cleanup; + + strcpy(fs->device_name, name); + retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &super); + if (retval) + goto cleanup; + fs->super = super; + + memset(super, 0, SUPERBLOCK_SIZE); + +#define set_field(field, default) (super->field = param->field ? \ + param->field : (default)) + + super->s_magic = EXT2_SUPER_MAGIC; + super->s_state = EXT2_VALID_FS; + + set_field(s_log_block_size, 0); /* default blocksize: 1024 bytes */ + set_field(s_log_frag_size, 0); /* default fragsize: 1024 bytes */ + set_field(s_first_data_block, super->s_log_block_size ? 0 : 1); + set_field(s_max_mnt_count, EXT2_DFL_MAX_MNT_COUNT); + set_field(s_errors, EXT2_ERRORS_DEFAULT); + set_field(s_feature_compat, 0); + set_field(s_feature_incompat, 0); + set_field(s_feature_ro_compat, 0); + set_field(s_first_meta_bg, 0); + set_field(s_raid_stride, 0); /* default stride size: 0 */ + set_field(s_raid_stripe_width, 0); /* default stripe width: 0 */ + set_field(s_log_groups_per_flex, 0); + set_field(s_flags, 0); + if (super->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { + retval = EXT2_ET_UNSUPP_FEATURE; + goto cleanup; + } + if (super->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) { + retval = EXT2_ET_RO_UNSUPP_FEATURE; + goto cleanup; + } + + set_field(s_rev_level, EXT2_GOOD_OLD_REV); + if (super->s_rev_level >= EXT2_DYNAMIC_REV) { + set_field(s_first_ino, EXT2_GOOD_OLD_FIRST_INO); + set_field(s_inode_size, EXT2_GOOD_OLD_INODE_SIZE); + if (super->s_inode_size >= sizeof(struct ext2_inode_large)) { + int extra_isize = sizeof(struct ext2_inode_large) - + EXT2_GOOD_OLD_INODE_SIZE; + set_field(s_min_extra_isize, extra_isize); + set_field(s_want_extra_isize, extra_isize); + } + } else { + super->s_first_ino = EXT2_GOOD_OLD_FIRST_INO; + super->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE; + } + + set_field(s_checkinterval, EXT2_DFL_CHECKINTERVAL); + super->s_mkfs_time = super->s_lastcheck = fs->now ? fs->now : time(NULL); + + super->s_creator_os = CREATOR_OS; + + fs->blocksize = EXT2_BLOCK_SIZE(super); + fs->fragsize = EXT2_FRAG_SIZE(super); + frags_per_block = fs->blocksize / fs->fragsize; + + /* default: (fs->blocksize*8) blocks/group, up to 2^16 (GDT limit) */ + set_field(s_blocks_per_group, fs->blocksize * 8); + if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) + super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super); + super->s_frags_per_group = super->s_blocks_per_group * frags_per_block; + + ext2fs_blocks_count_set(super, ext2fs_blocks_count(param)); + ext2fs_r_blocks_count_set(super, ext2fs_r_blocks_count(param)); + if (ext2fs_r_blocks_count(super) >= ext2fs_blocks_count(param)) { + retval = EXT2_ET_INVALID_ARGUMENT; + goto cleanup; + } + + /* + * If we're creating an external journal device, we don't need + * to bother with the rest. + */ + if (super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { + fs->group_desc_count = 0; + ext2fs_mark_super_dirty(fs); + *ret_fs = fs; + return 0; + } + +retry: + fs->group_desc_count = (blk_t) ext2fs_div64_ceil( + ext2fs_blocks_count(super) - super->s_first_data_block, + EXT2_BLOCKS_PER_GROUP(super)); + if (fs->group_desc_count == 0) { + retval = EXT2_ET_TOOSMALL; + goto cleanup; + } + + if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + super->s_desc_size = EXT2_MIN_DESC_SIZE_64BIT; + + fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, + EXT2_DESC_PER_BLOCK(super)); + + i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize; + + if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT && + (ext2fs_blocks_count(super) / i) > (1ULL << 32)) + set_field(s_inodes_count, ~0U); + else + set_field(s_inodes_count, ext2fs_blocks_count(super) / i); + + /* + * Make sure we have at least EXT2_FIRST_INO + 1 inodes, so + * that we have enough inodes for the filesystem(!) + */ + if (super->s_inodes_count < EXT2_FIRST_INODE(super)+1) + super->s_inodes_count = EXT2_FIRST_INODE(super)+1; + + /* + * There should be at least as many inodes as the user + * requested. Figure out how many inodes per group that + * should be. But make sure that we don't allocate more than + * one bitmap's worth of inodes each group. + */ + ipg = ext2fs_div_ceil(super->s_inodes_count, fs->group_desc_count); + if (ipg > fs->blocksize * 8) { + if (super->s_blocks_per_group >= 256) { + /* Try again with slightly different parameters */ + super->s_blocks_per_group -= 8; + ext2fs_blocks_count_set(super, + ext2fs_blocks_count(param)); + super->s_frags_per_group = super->s_blocks_per_group * + frags_per_block; + goto retry; + } else { + retval = EXT2_ET_TOO_MANY_INODES; + goto cleanup; + } + } + + if (ipg > (unsigned) EXT2_MAX_INODES_PER_GROUP(super)) + ipg = EXT2_MAX_INODES_PER_GROUP(super); + +ipg_retry: + super->s_inodes_per_group = ipg; + + /* + * Make sure the number of inodes per group completely fills + * the inode table blocks in the descriptor. If not, add some + * additional inodes/group. Waste not, want not... + */ + fs->inode_blocks_per_group = (((super->s_inodes_per_group * + EXT2_INODE_SIZE(super)) + + EXT2_BLOCK_SIZE(super) - 1) / + EXT2_BLOCK_SIZE(super)); + super->s_inodes_per_group = ((fs->inode_blocks_per_group * + EXT2_BLOCK_SIZE(super)) / + EXT2_INODE_SIZE(super)); + /* + * Finally, make sure the number of inodes per group is a + * multiple of 8. This is needed to simplify the bitmap + * splicing code. + */ + super->s_inodes_per_group &= ~7; + fs->inode_blocks_per_group = (((super->s_inodes_per_group * + EXT2_INODE_SIZE(super)) + + EXT2_BLOCK_SIZE(super) - 1) / + EXT2_BLOCK_SIZE(super)); + + /* + * adjust inode count to reflect the adjusted inodes_per_group + */ + if ((__u64)super->s_inodes_per_group * fs->group_desc_count > ~0U) { + ipg--; + goto ipg_retry; + } + super->s_inodes_count = super->s_inodes_per_group * + fs->group_desc_count; + super->s_free_inodes_count = super->s_inodes_count; + + /* + * check the number of reserved group descriptor table blocks + */ + if (super->s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) + rsv_gdt = calc_reserved_gdt_blocks(fs); + else + rsv_gdt = 0; + set_field(s_reserved_gdt_blocks, rsv_gdt); + if (super->s_reserved_gdt_blocks > EXT2_ADDR_PER_BLOCK(super)) { + retval = EXT2_ET_RES_GDT_BLOCKS; + goto cleanup; + } + + /* + * Calculate the maximum number of bookkeeping blocks per + * group. It includes the superblock, the block group + * descriptors, the block bitmap, the inode bitmap, the inode + * table, and the reserved gdt blocks. + */ + overhead = (int) (3 + fs->inode_blocks_per_group + + fs->desc_blocks + super->s_reserved_gdt_blocks); + + /* This can only happen if the user requested too many inodes */ + if (overhead > super->s_blocks_per_group) { + retval = EXT2_ET_TOO_MANY_INODES; + goto cleanup; + } + + /* + * See if the last group is big enough to support the + * necessary data structures. If not, we need to get rid of + * it. We need to recalculate the overhead for the last block + * group, since it might or might not have a superblock + * backup. + */ + overhead = (int) (2 + fs->inode_blocks_per_group); + if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1)) + overhead += 1 + fs->desc_blocks + super->s_reserved_gdt_blocks; + rem = ((ext2fs_blocks_count(super) - super->s_first_data_block) % + super->s_blocks_per_group); + if ((fs->group_desc_count == 1) && rem && (rem < overhead)) { + retval = EXT2_ET_TOOSMALL; + goto cleanup; + } + if (rem && (rem < overhead+50)) { + ext2fs_blocks_count_set(super, ext2fs_blocks_count(super) - + rem); + + goto retry; + } + + /* + * At this point we know how big the filesystem will be. So + * we can do any and all allocations that depend on the block + * count. + */ + + retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf); + if (retval) + goto cleanup; + + strcpy(buf, "block bitmap for "); + strcat(buf, fs->device_name); + retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map); + if (retval) + goto cleanup; + + strcpy(buf, "inode bitmap for "); + strcat(buf, fs->device_name); + retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map); + if (retval) + goto cleanup; + + ext2fs_free_mem(&buf); + + retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, + &fs->group_desc); + if (retval) + goto cleanup; + + memset(fs->group_desc, 0, (size_t) fs->desc_blocks * fs->blocksize); + + /* + * Reserve the superblock and group descriptors for each + * group, and fill in the correct group statistics for group. + * Note that although the block bitmap, inode bitmap, and + * inode table have not been allocated (and in fact won't be + * by this routine), they are accounted for nevertheless. + * + * If FLEX_BG meta-data grouping is used, only account for the + * superblock and group descriptors (the inode tables and + * bitmaps will be accounted for when allocated). + */ + ext2fs_free_blocks_count_set(super, 0); + csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM); + for (i = 0; i < fs->group_desc_count; i++) { + /* + * Don't set the BLOCK_UNINIT group for the last group + * because the block bitmap needs to be padded. + */ + if (csum_flag) { + if (i != fs->group_desc_count - 1) + ext2fs_bg_flags_set(fs, i, + EXT2_BG_BLOCK_UNINIT); + ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); + numblocks = super->s_inodes_per_group; + if (i == 0) + numblocks -= super->s_first_ino; + ext2fs_bg_itable_unused_set(fs, i, numblocks); + } + numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map); + if (fs->super->s_log_groups_per_flex) + numblocks += 2 + fs->inode_blocks_per_group; + + ext2fs_free_blocks_count_set(super, + ext2fs_free_blocks_count(super) + + numblocks); + ext2fs_bg_free_blocks_count_set(fs, i, numblocks); + ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group); + ext2fs_bg_used_dirs_count_set(fs, i, 0); + ext2fs_group_desc_csum_set(fs, i); + } + + c = (char) 255; + if (((int) c) == -1) { + super->s_flags |= EXT2_FLAGS_SIGNED_HASH; + } else { + super->s_flags |= EXT2_FLAGS_UNSIGNED_HASH; + } + + ext2fs_mark_super_dirty(fs); + ext2fs_mark_bb_dirty(fs); + ext2fs_mark_ib_dirty(fs); + + io_channel_set_blksize(fs->io, fs->blocksize); + + *ret_fs = fs; + return 0; +cleanup: + free(buf); + ext2fs_free(fs); + return retval; +} diff --git a/libcustomext2fs/source/inline.c b/libcustomext2fs/source/inline.c new file mode 100644 index 00000000..f9be368b --- /dev/null +++ b/libcustomext2fs/source/inline.c @@ -0,0 +1,32 @@ +/* + * inline.c --- Includes the inlined functions defined in the header + * files as standalone functions, in case the application program + * is compiled with inlining turned off. + * + * Copyright (C) 1993, 1994 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#define INCLUDE_INLINE_FUNCS +#include "ext2fs.h" + diff --git a/libcustomext2fs/source/inode.c b/libcustomext2fs/source/inode.c new file mode 100644 index 00000000..a762dbce --- /dev/null +++ b/libcustomext2fs/source/inode.c @@ -0,0 +1,834 @@ +/* + * inode.c --- utility routines to read and write inodes + * + * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" +#include "e2image.h" + +struct ext2_struct_inode_scan { + errcode_t magic; + ext2_filsys fs; + ext2_ino_t current_inode; + blk64_t current_block; + dgrp_t current_group; + ext2_ino_t inodes_left; + blk_t blocks_left; + dgrp_t groups_left; + blk_t inode_buffer_blocks; + char * inode_buffer; + int inode_size; + char * ptr; + int bytes_left; + char *temp_buffer; + errcode_t (*done_group)(ext2_filsys fs, + ext2_inode_scan scan, + dgrp_t group, + void * priv_data); + void * done_group_data; + int bad_block_ptr; + int scan_flags; + int reserved[6]; +}; + +/* + * This routine flushes the icache, if it exists. + */ +errcode_t ext2fs_flush_icache(ext2_filsys fs) +{ + int i; + + if (!fs->icache) + return 0; + + for (i=0; i < fs->icache->cache_size; i++) + fs->icache->cache[i].ino = 0; + + fs->icache->buffer_blk = 0; + return 0; +} + +static errcode_t create_icache(ext2_filsys fs) +{ + errcode_t retval; + + if (fs->icache) + return 0; + retval = ext2fs_get_mem(sizeof(struct ext2_inode_cache), &fs->icache); + if (retval) + return retval; + + memset(fs->icache, 0, sizeof(struct ext2_inode_cache)); + retval = ext2fs_get_mem(fs->blocksize, &fs->icache->buffer); + if (retval) { + ext2fs_free_mem(&fs->icache); + return retval; + } + fs->icache->buffer_blk = 0; + fs->icache->cache_last = -1; + fs->icache->cache_size = 4; + fs->icache->refcount = 1; + retval = ext2fs_get_array(fs->icache->cache_size, + sizeof(struct ext2_inode_cache_ent), + &fs->icache->cache); + if (retval) { + ext2fs_free_mem(&fs->icache->buffer); + ext2fs_free_mem(&fs->icache); + return retval; + } + ext2fs_flush_icache(fs); + return 0; +} + +errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, + ext2_inode_scan *ret_scan) +{ + ext2_inode_scan scan; + errcode_t retval; + errcode_t (*save_get_blocks)(ext2_filsys f, ext2_ino_t ino, blk_t *blocks); + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + /* + * If fs->badblocks isn't set, then set it --- since the inode + * scanning functions require it. + */ + if (fs->badblocks == 0) { + /* + * Temporarly save fs->get_blocks and set it to zero, + * for compatibility with old e2fsck's. + */ + save_get_blocks = fs->get_blocks; + fs->get_blocks = 0; + retval = ext2fs_read_bb_inode(fs, &fs->badblocks); + if (retval && fs->badblocks) { + ext2fs_badblocks_list_free(fs->badblocks); + fs->badblocks = 0; + } + fs->get_blocks = save_get_blocks; + } + + retval = ext2fs_get_mem(sizeof(struct ext2_struct_inode_scan), &scan); + if (retval) + return retval; + memset(scan, 0, sizeof(struct ext2_struct_inode_scan)); + + scan->magic = EXT2_ET_MAGIC_INODE_SCAN; + scan->fs = fs; + scan->inode_size = EXT2_INODE_SIZE(fs->super); + scan->bytes_left = 0; + scan->current_group = 0; + scan->groups_left = fs->group_desc_count - 1; + scan->inode_buffer_blocks = buffer_blocks ? buffer_blocks : 8; + scan->current_block = ext2fs_inode_table_loc(scan->fs, + scan->current_group); + scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super); + scan->blocks_left = scan->fs->inode_blocks_per_group; + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { + scan->inodes_left -= + ext2fs_bg_itable_unused(fs, scan->current_group); + scan->blocks_left = + (scan->inodes_left + + (fs->blocksize / scan->inode_size - 1)) * + scan->inode_size / fs->blocksize; + } + retval = ext2fs_get_memalign(scan->inode_buffer_blocks * fs->blocksize, + fs->blocksize, &scan->inode_buffer); + scan->done_group = 0; + scan->done_group_data = 0; + scan->bad_block_ptr = 0; + if (retval) { + ext2fs_free_mem(&scan); + return retval; + } + retval = ext2fs_get_mem(scan->inode_size, &scan->temp_buffer); + if (retval) { + ext2fs_free_mem(&scan->inode_buffer); + ext2fs_free_mem(&scan); + return retval; + } + if (scan->fs->badblocks && scan->fs->badblocks->num) + scan->scan_flags |= EXT2_SF_CHK_BADBLOCKS; + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) + scan->scan_flags |= EXT2_SF_DO_LAZY; + *ret_scan = scan; + return 0; +} + +void ext2fs_close_inode_scan(ext2_inode_scan scan) +{ + if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) + return; + + ext2fs_free_mem(&scan->inode_buffer); + scan->inode_buffer = NULL; + ext2fs_free_mem(&scan->temp_buffer); + scan->temp_buffer = NULL; + ext2fs_free_mem(&scan); + return; +} + +void ext2fs_set_inode_callback(ext2_inode_scan scan, + errcode_t (*done_group)(ext2_filsys fs, + ext2_inode_scan scan, + dgrp_t group, + void * priv_data), + void *done_group_data) +{ + if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) + return; + + scan->done_group = done_group; + scan->done_group_data = done_group_data; +} + +int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags, + int clear_flags) +{ + int old_flags; + + if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) + return 0; + + old_flags = scan->scan_flags; + scan->scan_flags &= ~clear_flags; + scan->scan_flags |= set_flags; + return old_flags; +} + +/* + * This function is called by ext2fs_get_next_inode when it needs to + * get ready to read in a new blockgroup. + */ +static errcode_t get_next_blockgroup(ext2_inode_scan scan) +{ + ext2_filsys fs = scan->fs; + + scan->current_group++; + scan->groups_left--; + + scan->current_block = ext2fs_inode_table_loc(scan->fs, + scan->current_group); + scan->current_inode = scan->current_group * + EXT2_INODES_PER_GROUP(fs->super); + + scan->bytes_left = 0; + scan->inodes_left = EXT2_INODES_PER_GROUP(fs->super); + scan->blocks_left = fs->inode_blocks_per_group; + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { + scan->inodes_left -= + ext2fs_bg_itable_unused(fs, scan->current_group); + scan->blocks_left = + (scan->inodes_left + + (fs->blocksize / scan->inode_size - 1)) * + scan->inode_size / fs->blocksize; + } + + return 0; +} + +errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, + int group) +{ + scan->current_group = group - 1; + scan->groups_left = scan->fs->group_desc_count - group; + return get_next_blockgroup(scan); +} + +/* + * This function is called by get_next_blocks() to check for bad + * blocks in the inode table. + * + * This function assumes that badblocks_list->list is sorted in + * increasing order. + */ +static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan, + blk_t *num_blocks) +{ + blk_t blk = scan->current_block; + badblocks_list bb = scan->fs->badblocks; + + /* + * If the inode table is missing, then obviously there are no + * bad blocks. :-) + */ + if (blk == 0) + return 0; + + /* + * If the current block is greater than the bad block listed + * in the bad block list, then advance the pointer until this + * is no longer the case. If we run out of bad blocks, then + * we don't need to do any more checking! + */ + while (blk > bb->list[scan->bad_block_ptr]) { + if (++scan->bad_block_ptr >= bb->num) { + scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS; + return 0; + } + } + + /* + * If the current block is equal to the bad block listed in + * the bad block list, then handle that one block specially. + * (We could try to handle runs of bad blocks, but that + * only increases CPU efficiency by a small amount, at the + * expense of a huge expense of code complexity, and for an + * uncommon case at that.) + */ + if (blk == bb->list[scan->bad_block_ptr]) { + scan->scan_flags |= EXT2_SF_BAD_INODE_BLK; + *num_blocks = 1; + if (++scan->bad_block_ptr >= bb->num) + scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS; + return 0; + } + + /* + * If there is a bad block in the range that we're about to + * read in, adjust the number of blocks to read so that we we + * don't read in the bad block. (Then the next block to read + * will be the bad block, which is handled in the above case.) + */ + if ((blk + *num_blocks) > bb->list[scan->bad_block_ptr]) + *num_blocks = (int) (bb->list[scan->bad_block_ptr] - blk); + + return 0; +} + +/* + * This function is called by ext2fs_get_next_inode when it needs to + * read in more blocks from the current blockgroup's inode table. + */ +static errcode_t get_next_blocks(ext2_inode_scan scan) +{ + blk_t num_blocks; + errcode_t retval; + + /* + * Figure out how many blocks to read; we read at most + * inode_buffer_blocks, and perhaps less if there aren't that + * many blocks left to read. + */ + num_blocks = scan->inode_buffer_blocks; + if (num_blocks > scan->blocks_left) + num_blocks = scan->blocks_left; + + /* + * If the past block "read" was a bad block, then mark the + * left-over extra bytes as also being bad. + */ + if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) { + if (scan->bytes_left) + scan->scan_flags |= EXT2_SF_BAD_EXTRA_BYTES; + scan->scan_flags &= ~EXT2_SF_BAD_INODE_BLK; + } + + /* + * Do inode bad block processing, if necessary. + */ + if (scan->scan_flags & EXT2_SF_CHK_BADBLOCKS) { + retval = check_for_inode_bad_blocks(scan, &num_blocks); + if (retval) + return retval; + } + + if ((scan->scan_flags & EXT2_SF_BAD_INODE_BLK) || + (scan->current_block == 0)) { + memset(scan->inode_buffer, 0, + (size_t) num_blocks * scan->fs->blocksize); + } else { + retval = io_channel_read_blk64(scan->fs->io, + scan->current_block, + (int) num_blocks, + scan->inode_buffer); + if (retval) + return EXT2_ET_NEXT_INODE_READ; + } + scan->ptr = scan->inode_buffer; + scan->bytes_left = num_blocks * scan->fs->blocksize; + + scan->blocks_left -= num_blocks; + if (scan->current_block) + scan->current_block += num_blocks; + return 0; +} + +#if 0 +/* + * Returns 1 if the entire inode_buffer has a non-zero size and + * contains all zeros. (Not just deleted inodes, since that means + * that part of the inode table was used at one point; we want all + * zeros, which means that the inode table is pristine.) + */ +static inline int is_empty_scan(ext2_inode_scan scan) +{ + int i; + + if (scan->bytes_left == 0) + return 0; + + for (i=0; i < scan->bytes_left; i++) + if (scan->ptr[i]) + return 0; + return 1; +} +#endif + +errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino, + struct ext2_inode *inode, int bufsize) +{ + errcode_t retval; + int extra_bytes = 0; + + EXT2_CHECK_MAGIC(scan, EXT2_ET_MAGIC_INODE_SCAN); + + /* + * Do we need to start reading a new block group? + */ + if (scan->inodes_left <= 0) { + force_new_group: + if (scan->done_group) { + retval = (scan->done_group) + (scan->fs, scan, scan->current_group, + scan->done_group_data); + if (retval) + return retval; + } + if (scan->groups_left <= 0) { + *ino = 0; + return 0; + } + retval = get_next_blockgroup(scan); + if (retval) + return retval; + } + /* + * These checks are done outside the above if statement so + * they can be done for block group #0. + */ + if ((scan->scan_flags & EXT2_SF_DO_LAZY) && + (ext2fs_bg_flags_test(scan->fs, scan->current_group, EXT2_BG_INODE_UNINIT) + )) + goto force_new_group; + if (scan->inodes_left == 0) + goto force_new_group; + if (scan->current_block == 0) { + if (scan->scan_flags & EXT2_SF_SKIP_MISSING_ITABLE) { + goto force_new_group; + } else + return EXT2_ET_MISSING_INODE_TABLE; + } + + + /* + * Have we run out of space in the inode buffer? If so, we + * need to read in more blocks. + */ + if (scan->bytes_left < scan->inode_size) { + memcpy(scan->temp_buffer, scan->ptr, scan->bytes_left); + extra_bytes = scan->bytes_left; + + retval = get_next_blocks(scan); + if (retval) + return retval; +#if 0 + /* + * XXX test Need check for used inode somehow. + * (Note: this is hard.) + */ + if (is_empty_scan(scan)) + goto force_new_group; +#endif + } + + retval = 0; + if (extra_bytes) { + memcpy(scan->temp_buffer+extra_bytes, scan->ptr, + scan->inode_size - extra_bytes); + scan->ptr += scan->inode_size - extra_bytes; + scan->bytes_left -= scan->inode_size - extra_bytes; + +#ifdef WORDS_BIGENDIAN + memset(inode, 0, bufsize); + ext2fs_swap_inode_full(scan->fs, + (struct ext2_inode_large *) inode, + (struct ext2_inode_large *) scan->temp_buffer, + 0, bufsize); +#else + *inode = *((struct ext2_inode *) scan->temp_buffer); +#endif + if (scan->scan_flags & EXT2_SF_BAD_EXTRA_BYTES) + retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE; + scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES; + } else { +#ifdef WORDS_BIGENDIAN + memset(inode, 0, bufsize); + ext2fs_swap_inode_full(scan->fs, + (struct ext2_inode_large *) inode, + (struct ext2_inode_large *) scan->ptr, + 0, bufsize); +#else + memcpy(inode, scan->ptr, bufsize); +#endif + scan->ptr += scan->inode_size; + scan->bytes_left -= scan->inode_size; + if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) + retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE; + } + + scan->inodes_left--; + scan->current_inode++; + *ino = scan->current_inode; + return retval; +} + +errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino, + struct ext2_inode *inode) +{ + return ext2fs_get_next_inode_full(scan, ino, inode, + sizeof(struct ext2_inode)); +} + +/* + * Functions to read and write a single inode. + */ +errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode, int bufsize) +{ + unsigned long group, block, block_nr, offset; + char *ptr; + errcode_t retval; + int clen, i, inodes_per_block, length; + io_channel io; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + /* Check to see if user has an override function */ + if (fs->read_inode) { + retval = (fs->read_inode)(fs, ino, inode); + if (retval != EXT2_ET_CALLBACK_NOTHANDLED) + return retval; + } + if ((ino == 0) || (ino > fs->super->s_inodes_count)) + return EXT2_ET_BAD_INODE_NUM; + /* Create inode cache if not present */ + if (!fs->icache) { + retval = create_icache(fs); + if (retval) + return retval; + } + /* Check to see if it's in the inode cache */ + if (bufsize == sizeof(struct ext2_inode)) { + /* only old good inode can be retrieved from the cache */ + for (i=0; i < fs->icache->cache_size; i++) { + if (fs->icache->cache[i].ino == ino) { + *inode = fs->icache->cache[i].inode; + return 0; + } + } + } + if (fs->flags & EXT2_FLAG_IMAGE_FILE) { + inodes_per_block = fs->blocksize / EXT2_INODE_SIZE(fs->super); + block_nr = fs->image_header->offset_inode / fs->blocksize; + block_nr += (ino - 1) / inodes_per_block; + offset = ((ino - 1) % inodes_per_block) * + EXT2_INODE_SIZE(fs->super); + io = fs->image_io; + } else { + group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); + if (group > fs->group_desc_count) + return EXT2_ET_BAD_INODE_NUM; + offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * + EXT2_INODE_SIZE(fs->super); + block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); + if (!ext2fs_inode_table_loc(fs, (unsigned) group)) + return EXT2_ET_MISSING_INODE_TABLE; + block_nr = ext2fs_inode_table_loc(fs, group) + + block; + io = fs->io; + } + offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); + + length = EXT2_INODE_SIZE(fs->super); + if (bufsize < length) + length = bufsize; + + ptr = (char *) inode; + while (length) { + clen = length; + if ((offset + length) > fs->blocksize) + clen = fs->blocksize - offset; + + if (block_nr != fs->icache->buffer_blk) { + retval = io_channel_read_blk64(io, block_nr, 1, + fs->icache->buffer); + if (retval) + return retval; + fs->icache->buffer_blk = block_nr; + } + + memcpy(ptr, ((char *) fs->icache->buffer) + (unsigned) offset, + clen); + + offset = 0; + length -= clen; + ptr += clen; + block_nr++; + } + +#ifdef WORDS_BIGENDIAN + ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode, + (struct ext2_inode_large *) inode, + 0, bufsize); +#endif + + /* Update the inode cache */ + fs->icache->cache_last = (fs->icache->cache_last + 1) % + fs->icache->cache_size; + fs->icache->cache[fs->icache->cache_last].ino = ino; + fs->icache->cache[fs->icache->cache_last].inode = *inode; + + return 0; +} + +errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode) +{ + return ext2fs_read_inode_full(fs, ino, inode, + sizeof(struct ext2_inode)); +} + +errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode * inode, int bufsize) +{ + unsigned long group, block, block_nr, offset; + errcode_t retval = 0; + struct ext2_inode_large temp_inode, *w_inode; + char *ptr; + int clen, i, length; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + /* Check to see if user provided an override function */ + if (fs->write_inode) { + retval = (fs->write_inode)(fs, ino, inode); + if (retval != EXT2_ET_CALLBACK_NOTHANDLED) + return retval; + } + + /* Check to see if the inode cache needs to be updated */ + if (fs->icache) { + for (i=0; i < fs->icache->cache_size; i++) { + if (fs->icache->cache[i].ino == ino) { + fs->icache->cache[i].inode = *inode; + break; + } + } + } else { + retval = create_icache(fs); + if (retval) + return retval; + } + + if (!(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if ((ino == 0) || (ino > fs->super->s_inodes_count)) + return EXT2_ET_BAD_INODE_NUM; + + length = bufsize; + if (length < EXT2_INODE_SIZE(fs->super)) + length = EXT2_INODE_SIZE(fs->super); + + if (length > (int) sizeof(struct ext2_inode_large)) { + w_inode = malloc(length); + if (!w_inode) + return ENOMEM; + } else + w_inode = &temp_inode; + memset(w_inode, 0, length); + +#ifdef WORDS_BIGENDIAN + ext2fs_swap_inode_full(fs, w_inode, + (struct ext2_inode_large *) inode, + 1, bufsize); +#else + memcpy(w_inode, inode, bufsize); +#endif + + group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); + offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * + EXT2_INODE_SIZE(fs->super); + block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); + if (!ext2fs_inode_table_loc(fs, (unsigned) group)) { + retval = EXT2_ET_MISSING_INODE_TABLE; + goto errout; + } + block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block; + + offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); + + length = EXT2_INODE_SIZE(fs->super); + if (length > bufsize) + length = bufsize; + + ptr = (char *) w_inode; + + while (length) { + clen = length; + if ((offset + length) > fs->blocksize) + clen = fs->blocksize - offset; + + if (fs->icache->buffer_blk != block_nr) { + retval = io_channel_read_blk64(fs->io, block_nr, 1, + fs->icache->buffer); + if (retval) + goto errout; + fs->icache->buffer_blk = block_nr; + } + + + memcpy((char *) fs->icache->buffer + (unsigned) offset, + ptr, clen); + + retval = io_channel_write_blk64(fs->io, block_nr, 1, + fs->icache->buffer); + if (retval) + goto errout; + + offset = 0; + ptr += clen; + length -= clen; + block_nr++; + } + + fs->flags |= EXT2_FLAG_CHANGED; +errout: + if (w_inode && w_inode != &temp_inode) + free(w_inode); + return retval; +} + +errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode) +{ + return ext2fs_write_inode_full(fs, ino, inode, + sizeof(struct ext2_inode)); +} + +/* + * This function should be called when writing a new inode. It makes + * sure that extra part of large inodes is initialized properly. + */ +errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode) +{ + struct ext2_inode *buf; + int size = EXT2_INODE_SIZE(fs->super); + struct ext2_inode_large *large_inode; + errcode_t retval; + __u32 t = fs->now ? fs->now : time(NULL); + + if (!inode->i_ctime) + inode->i_ctime = t; + if (!inode->i_mtime) + inode->i_mtime = t; + if (!inode->i_atime) + inode->i_atime = t; + + if (size == sizeof(struct ext2_inode)) + return ext2fs_write_inode_full(fs, ino, inode, + sizeof(struct ext2_inode)); + + buf = malloc(size); + if (!buf) + return ENOMEM; + + memset(buf, 0, size); + *buf = *inode; + + large_inode = (struct ext2_inode_large *) buf; + large_inode->i_extra_isize = sizeof(struct ext2_inode_large) - + EXT2_GOOD_OLD_INODE_SIZE; + if (!large_inode->i_crtime) + large_inode->i_crtime = t; + + retval = ext2fs_write_inode_full(fs, ino, buf, size); + free(buf); + return retval; +} + + +errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks) +{ + struct ext2_inode inode; + int i; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (ino > fs->super->s_inodes_count) + return EXT2_ET_BAD_INODE_NUM; + + if (fs->get_blocks) { + if (!(*fs->get_blocks)(fs, ino, blocks)) + return 0; + } + retval = ext2fs_read_inode(fs, ino, &inode); + if (retval) + return retval; + for (i=0; i < EXT2_N_BLOCKS; i++) + blocks[i] = inode.i_block[i]; + return 0; +} + +errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino) +{ + struct ext2_inode inode; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (ino > fs->super->s_inodes_count) + return EXT2_ET_BAD_INODE_NUM; + + if (fs->check_directory) { + retval = (fs->check_directory)(fs, ino); + if (retval != EXT2_ET_CALLBACK_NOTHANDLED) + return retval; + } + retval = ext2fs_read_inode(fs, ino, &inode); + if (retval) + return retval; + if (!LINUX_S_ISDIR(inode.i_mode)) + return EXT2_ET_NO_DIRECTORY; + return 0; +} + diff --git a/libcustomext2fs/source/inode_io.c b/libcustomext2fs/source/inode_io.c new file mode 100644 index 00000000..4faaa487 --- /dev/null +++ b/libcustomext2fs/source/inode_io.c @@ -0,0 +1,290 @@ +/* + * inode_io.c --- This is allows an inode in an ext2 filesystem image + * to be accessed via the I/O manager interface. + * + * Copyright (C) 2002 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * For checking structure magic numbers... + */ + +#define EXT2_CHECK_MAGIC(struct, code) \ + if ((struct)->magic != (code)) return (code) + +struct inode_private_data { + int magic; + char name[32]; + ext2_file_t file; + ext2_filsys fs; + ext2_ino_t ino; + struct ext2_inode inode; + int flags; + struct inode_private_data *next; +}; + +#define CHANNEL_HAS_INODE 0x8000 + +static struct inode_private_data *top_intern; +static int ino_unique = 0; + +static errcode_t inode_open(const char *name, int flags, io_channel *channel); +static errcode_t inode_close(io_channel channel); +static errcode_t inode_set_blksize(io_channel channel, int blksize); +static errcode_t inode_read_blk(io_channel channel, unsigned long block, + int count, void *data); +static errcode_t inode_write_blk(io_channel channel, unsigned long block, + int count, const void *data); +static errcode_t inode_flush(io_channel channel); +static errcode_t inode_write_byte(io_channel channel, unsigned long offset, + int size, const void *data); +static errcode_t inode_read_blk64(io_channel channel, + unsigned long long block, int count, void *data); +static errcode_t inode_write_blk64(io_channel channel, + unsigned long long block, int count, const void *data); + +static struct struct_io_manager struct_inode_manager = { + EXT2_ET_MAGIC_IO_MANAGER, + "Inode I/O Manager", + inode_open, + inode_close, + inode_set_blksize, + inode_read_blk, + inode_write_blk, + inode_flush, + inode_write_byte, + NULL, + NULL, + inode_read_blk64, + inode_write_blk64 +}; + +io_manager inode_io_manager = &struct_inode_manager; + +errcode_t ext2fs_inode_io_intern2(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char **name) +{ + struct inode_private_data *data; + errcode_t retval; + + if ((retval = ext2fs_get_mem(sizeof(struct inode_private_data), + &data))) + return retval; + data->magic = EXT2_ET_MAGIC_INODE_IO_CHANNEL; + sprintf(data->name, "%u:%d", ino, ino_unique++); + data->file = 0; + data->fs = fs; + data->ino = ino; + data->flags = 0; + if (inode) { + memcpy(&data->inode, inode, sizeof(struct ext2_inode)); + data->flags |= CHANNEL_HAS_INODE; + } + data->next = top_intern; + top_intern = data; + *name = data->name; + return 0; +} + +errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino, + char **name) +{ + return ext2fs_inode_io_intern2(fs, ino, NULL, name); +} + + +static errcode_t inode_open(const char *name, int flags, io_channel *channel) +{ + io_channel io = NULL; + struct inode_private_data *prev, *data = NULL; + errcode_t retval; + int open_flags; + + if (name == 0) + return EXT2_ET_BAD_DEVICE_NAME; + + for (data = top_intern, prev = NULL; data; + prev = data, data = data->next) + if (strcmp(name, data->name) == 0) + break; + if (!data) + return ENOENT; + if (prev) + prev->next = data->next; + else + top_intern = data->next; + + retval = ext2fs_get_mem(sizeof(struct struct_io_channel), &io); + if (retval) + goto cleanup; + memset(io, 0, sizeof(struct struct_io_channel)); + + io->magic = EXT2_ET_MAGIC_IO_CHANNEL; + io->manager = inode_io_manager; + retval = ext2fs_get_mem(strlen(name)+1, &io->name); + if (retval) + goto cleanup; + + strcpy(io->name, name); + io->private_data = data; + io->block_size = 1024; + io->read_error = 0; + io->write_error = 0; + io->refcount = 1; + + open_flags = (flags & IO_FLAG_RW) ? EXT2_FILE_WRITE : 0; + retval = ext2fs_file_open2(data->fs, data->ino, + (data->flags & CHANNEL_HAS_INODE) ? + &data->inode : 0, open_flags, + &data->file); + if (retval) + goto cleanup; + + *channel = io; + return 0; + +cleanup: + if (data) { + ext2fs_free_mem(&data); + } + if (io) + ext2fs_free_mem(&io); + return retval; +} + +static errcode_t inode_close(io_channel channel) +{ + struct inode_private_data *data; + errcode_t retval = 0; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + data = (struct inode_private_data *) channel->private_data; + EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL); + + if (--channel->refcount > 0) + return 0; + + retval = ext2fs_file_close(data->file); + + ext2fs_free_mem(&channel->private_data); + if (channel->name) + ext2fs_free_mem(&channel->name); + ext2fs_free_mem(&channel); + return retval; +} + +static errcode_t inode_set_blksize(io_channel channel, int blksize) +{ + struct inode_private_data *data; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + data = (struct inode_private_data *) channel->private_data; + EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL); + + channel->block_size = blksize; + return 0; +} + + +static errcode_t inode_read_blk64(io_channel channel, + unsigned long long block, int count, void *buf) +{ + struct inode_private_data *data; + errcode_t retval; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + data = (struct inode_private_data *) channel->private_data; + EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL); + + if ((retval = ext2fs_file_lseek(data->file, + block * channel->block_size, + EXT2_SEEK_SET, 0))) + return retval; + + count = (count < 0) ? -count : (count * channel->block_size); + + return ext2fs_file_read(data->file, buf, count, 0); +} + +static errcode_t inode_read_blk(io_channel channel, unsigned long block, + int count, void *buf) +{ + return inode_read_blk64(channel, block, count, buf); +} + +static errcode_t inode_write_blk64(io_channel channel, + unsigned long long block, int count, const void *buf) +{ + struct inode_private_data *data; + errcode_t retval; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + data = (struct inode_private_data *) channel->private_data; + EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL); + + if ((retval = ext2fs_file_lseek(data->file, + block * channel->block_size, + EXT2_SEEK_SET, 0))) + return retval; + + count = (count < 0) ? -count : (count * channel->block_size); + + return ext2fs_file_write(data->file, buf, count, 0); +} + +static errcode_t inode_write_blk(io_channel channel, unsigned long block, + int count, const void *buf) +{ + return inode_write_blk64(channel, block, count, buf); +} + +static errcode_t inode_write_byte(io_channel channel, unsigned long offset, + int size, const void *buf) +{ + struct inode_private_data *data; + errcode_t retval = 0; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + data = (struct inode_private_data *) channel->private_data; + EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL); + + if ((retval = ext2fs_file_lseek(data->file, offset, + EXT2_SEEK_SET, 0))) + return retval; + + return ext2fs_file_write(data->file, buf, size, 0); +} + +/* + * Flush data buffers to disk. + */ +static errcode_t inode_flush(io_channel channel) +{ + struct inode_private_data *data; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + data = (struct inode_private_data *) channel->private_data; + EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_INODE_IO_CHANNEL); + + return ext2fs_file_flush(data->file); +} + diff --git a/libcustomext2fs/source/io_manager.c b/libcustomext2fs/source/io_manager.c new file mode 100644 index 00000000..80f9dfcb --- /dev/null +++ b/libcustomext2fs/source/io_manager.c @@ -0,0 +1,112 @@ +/* + * io_manager.c --- the I/O manager abstraction + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +errcode_t io_channel_set_options(io_channel channel, const char *opts) +{ + errcode_t retval = 0; + char *next, *ptr, *options, *arg; + + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + + if (!opts) + return 0; + + if (!channel->manager->set_option) + return EXT2_ET_INVALID_ARGUMENT; + + options = malloc(strlen(opts)+1); + if (!options) + return EXT2_ET_NO_MEMORY; + strcpy(options, opts); + ptr = options; + + while (ptr && *ptr) { + next = strchr(ptr, '&'); + if (next) + *next++ = 0; + + arg = strchr(ptr, '='); + if (arg) + *arg++ = 0; + + retval = (channel->manager->set_option)(channel, ptr, arg); + if (retval) + break; + ptr = next; + } + free(options); + return retval; +} + +errcode_t io_channel_write_byte(io_channel channel, unsigned long offset, + int count, const void *data) +{ + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + + if (channel->manager->write_byte) + return channel->manager->write_byte(channel, offset, + count, data); + + return EXT2_ET_UNIMPLEMENTED; +} + +errcode_t io_channel_read_blk64(io_channel channel, unsigned long long block, + int count, void *data) +{ + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + + if (channel->manager->read_blk64) + return (channel->manager->read_blk64)(channel, block, + count, data); + + if ((block >> 32) != 0) + return EXT2_ET_IO_CHANNEL_NO_SUPPORT_64; + + return (channel->manager->read_blk)(channel, (unsigned long) block, + count, data); +} + +errcode_t io_channel_write_blk64(io_channel channel, unsigned long long block, + int count, const void *data) +{ + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + + if (channel->manager->write_blk64) + return (channel->manager->write_blk64)(channel, block, + count, data); + + if ((block >> 32) != 0) + return EXT2_ET_IO_CHANNEL_NO_SUPPORT_64; + + return (channel->manager->write_blk)(channel, (unsigned long) block, + count, data); +} + +errcode_t io_channel_discard(io_channel channel, unsigned long long block, + unsigned long long count) +{ + EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL); + + if (channel->manager->discard) + return (channel->manager->discard)(channel, block, count); + + return EXT2_ET_UNIMPLEMENTED; +} diff --git a/libcustomext2fs/source/irel.h b/libcustomext2fs/source/irel.h new file mode 100644 index 00000000..9a4958be --- /dev/null +++ b/libcustomext2fs/source/irel.h @@ -0,0 +1,114 @@ +/* + * irel.h + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +struct ext2_inode_reference { + blk_t block; + __u16 offset; +}; + +struct ext2_inode_relocate_entry { + ext2_ino_t new; + ext2_ino_t orig; + __u16 flags; + __u16 max_refs; +}; + +typedef struct ext2_inode_relocation_table *ext2_irel; + +struct ext2_inode_relocation_table { + __u32 magic; + char *name; + ext2_ino_t current; + void *priv_data; + + /* + * Add an inode relocation entry. + */ + errcode_t (*put)(ext2_irel irel, ext2_ino_t old, + struct ext2_inode_relocate_entry *ent); + /* + * Get an inode relocation entry. + */ + errcode_t (*get)(ext2_irel irel, ext2_ino_t old, + struct ext2_inode_relocate_entry *ent); + + /* + * Get an inode relocation entry by its original inode number + */ + errcode_t (*get_by_orig)(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old, + struct ext2_inode_relocate_entry *ent); + + /* + * Initialize for iterating over the inode relocation entries. + */ + errcode_t (*start_iter)(ext2_irel irel); + + /* + * The iterator function for the inode relocation entries. + * Returns an inode number of 0 when out of entries. + */ + errcode_t (*next)(ext2_irel irel, ext2_ino_t *old, + struct ext2_inode_relocate_entry *ent); + + /* + * Add an inode reference (i.e., note the fact that a + * particular block/offset contains a reference to an inode) + */ + errcode_t (*add_ref)(ext2_irel irel, ext2_ino_t ino, + struct ext2_inode_reference *ref); + + /* + * Initialize for iterating over the inode references for a + * particular inode. + */ + errcode_t (*start_iter_ref)(ext2_irel irel, ext2_ino_t ino); + + /* + * The iterator function for the inode references for an + * inode. The references for only one inode can be interator + * over at a time, as the iterator state is stored in ext2_irel. + */ + errcode_t (*next_ref)(ext2_irel irel, + struct ext2_inode_reference *ref); + + /* + * Move the inode relocation table from one inode number to + * another. Note that the inode references also must move. + */ + errcode_t (*move)(ext2_irel irel, ext2_ino_t old, ext2_ino_t new); + + /* + * Remove an inode relocation entry, along with all of the + * inode references. + */ + errcode_t (*delete)(ext2_irel irel, ext2_ino_t old); + + /* + * Free the inode relocation table. + */ + errcode_t (*free)(ext2_irel irel); +}; + +errcode_t ext2fs_irel_memarray_create(char *name, ext2_ino_t max_inode, + ext2_irel *irel); + +#define ext2fs_irel_put(irel, old, ent) ((irel)->put((irel), old, ent)) +#define ext2fs_irel_get(irel, old, ent) ((irel)->get((irel), old, ent)) +#define ext2fs_irel_get_by_orig(irel, orig, old, ent) \ + ((irel)->get_by_orig((irel), orig, old, ent)) +#define ext2fs_irel_start_iter(irel) ((irel)->start_iter((irel))) +#define ext2fs_irel_next(irel, old, ent) ((irel)->next((irel), old, ent)) +#define ext2fs_irel_add_ref(irel, ino, ref) ((irel)->add_ref((irel), ino, ref)) +#define ext2fs_irel_start_iter_ref(irel, ino) ((irel)->start_iter_ref((irel), ino)) +#define ext2fs_irel_next_ref(irel, ref) ((irel)->next_ref((irel), ref)) +#define ext2fs_irel_move(irel, old, new) ((irel)->move((irel), old, new)) +#define ext2fs_irel_delete(irel, old) ((irel)->delete((irel), old)) +#define ext2fs_irel_free(irel) ((irel)->free((irel))) diff --git a/libcustomext2fs/source/irel_ma.c b/libcustomext2fs/source/irel_ma.c new file mode 100644 index 00000000..b7eaf6b5 --- /dev/null +++ b/libcustomext2fs/source/irel_ma.c @@ -0,0 +1,372 @@ +/* + * irel_ma.c + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "irel.h" + +static errcode_t ima_put(ext2_irel irel, ext2_ino_t old, + struct ext2_inode_relocate_entry *ent); +static errcode_t ima_get(ext2_irel irel, ext2_ino_t old, + struct ext2_inode_relocate_entry *ent); +static errcode_t ima_get_by_orig(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old, + struct ext2_inode_relocate_entry *ent); +static errcode_t ima_start_iter(ext2_irel irel); +static errcode_t ima_next(ext2_irel irel, ext2_ino_t *old, + struct ext2_inode_relocate_entry *ent); +static errcode_t ima_add_ref(ext2_irel irel, ext2_ino_t ino, + struct ext2_inode_reference *ref); +static errcode_t ima_start_iter_ref(ext2_irel irel, ext2_ino_t ino); +static errcode_t ima_next_ref(ext2_irel irel, struct ext2_inode_reference *ref); +static errcode_t ima_move(ext2_irel irel, ext2_ino_t old, ext2_ino_t new); +static errcode_t ima_delete(ext2_irel irel, ext2_ino_t old); +static errcode_t ima_free(ext2_irel irel); + +/* + * This data structure stores the array of inode references; there is + * a structure for each inode. + */ +struct inode_reference_entry { + __u16 num; + struct ext2_inode_reference *refs; +}; + +struct irel_ma { + __u32 magic; + ext2_ino_t max_inode; + ext2_ino_t ref_current; + int ref_iter; + ext2_ino_t *orig_map; + struct ext2_inode_relocate_entry *entries; + struct inode_reference_entry *ref_entries; +}; + +errcode_t ext2fs_irel_memarray_create(char *name, ext2_ino_t max_inode, + ext2_irel *new_irel) +{ + ext2_irel irel = 0; + errcode_t retval; + struct irel_ma *ma = 0; + size_t size; + + *new_irel = 0; + + /* + * Allocate memory structures + */ + retval = ext2fs_get_mem(sizeof(struct ext2_inode_relocation_table), + &irel); + if (retval) + goto errout; + memset(irel, 0, sizeof(struct ext2_inode_relocation_table)); + + retval = ext2fs_get_mem(strlen(name)+1, &irel->name); + if (retval) + goto errout; + strcpy(irel->name, name); + + retval = ext2fs_get_mem(sizeof(struct irel_ma), &ma); + if (retval) + goto errout; + memset(ma, 0, sizeof(struct irel_ma)); + irel->priv_data = ma; + + size = (size_t) (sizeof(ext2_ino_t) * (max_inode+1)); + retval = ext2fs_get_array(max_inode+1, sizeof(ext2_ino_t), + &ma->orig_map); + if (retval) + goto errout; + memset(ma->orig_map, 0, size); + + size = (size_t) (sizeof(struct ext2_inode_relocate_entry) * (max_inode+1)); + retval = ext2fs_get_array((max_inode+1), sizeof(struct ext2_inode_relocate_entry), &ma->entries); + if (retval) + goto errout; + memset(ma->entries, 0, size); + + size = (size_t) (sizeof(struct inode_reference_entry) * (max_inode+1)); + retval = ext2fs_get_mem(size, &ma->ref_entries); + if (retval) + goto errout; + memset(ma->ref_entries, 0, size); + ma->max_inode = max_inode; + + /* + * Fill in the irel data structure + */ + irel->put = ima_put; + irel->get = ima_get; + irel->get_by_orig = ima_get_by_orig; + irel->start_iter = ima_start_iter; + irel->next = ima_next; + irel->add_ref = ima_add_ref; + irel->start_iter_ref = ima_start_iter_ref; + irel->next_ref = ima_next_ref; + irel->move = ima_move; + irel->delete = ima_delete; + irel->free = ima_free; + + *new_irel = irel; + return 0; + +errout: + ima_free(irel); + return retval; +} + +static errcode_t ima_put(ext2_irel irel, ext2_ino_t old, + struct ext2_inode_relocate_entry *ent) +{ + struct inode_reference_entry *ref_ent; + struct irel_ma *ma; + errcode_t retval; + size_t size, old_size; + + ma = irel->priv_data; + if (old > ma->max_inode) + return EXT2_ET_INVALID_ARGUMENT; + + /* + * Force the orig field to the correct value; the application + * program shouldn't be messing with this field. + */ + if (ma->entries[(unsigned) old].new == 0) + ent->orig = old; + else + ent->orig = ma->entries[(unsigned) old].orig; + + /* + * If max_refs has changed, reallocate the refs array + */ + ref_ent = ma->ref_entries + (unsigned) old; + if (ref_ent->refs && ent->max_refs != + ma->entries[(unsigned) old].max_refs) { + size = (sizeof(struct ext2_inode_reference) * ent->max_refs); + old_size = (sizeof(struct ext2_inode_reference) * + ma->entries[(unsigned) old].max_refs); + retval = ext2fs_resize_mem(old_size, size, &ref_ent->refs); + if (retval) + return retval; + } + + ma->entries[(unsigned) old] = *ent; + ma->orig_map[(unsigned) ent->orig] = old; + return 0; +} + +static errcode_t ima_get(ext2_irel irel, ext2_ino_t old, + struct ext2_inode_relocate_entry *ent) +{ + struct irel_ma *ma; + + ma = irel->priv_data; + if (old > ma->max_inode) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned) old].new == 0) + return ENOENT; + *ent = ma->entries[(unsigned) old]; + return 0; +} + +static errcode_t ima_get_by_orig(ext2_irel irel, ext2_ino_t orig, ext2_ino_t *old, + struct ext2_inode_relocate_entry *ent) +{ + struct irel_ma *ma; + ext2_ino_t ino; + + ma = irel->priv_data; + if (orig > ma->max_inode) + return EXT2_ET_INVALID_ARGUMENT; + ino = ma->orig_map[(unsigned) orig]; + if (ino == 0) + return ENOENT; + *old = ino; + *ent = ma->entries[(unsigned) ino]; + return 0; +} + +static errcode_t ima_start_iter(ext2_irel irel) +{ + irel->current = 0; + return 0; +} + +static errcode_t ima_next(ext2_irel irel, ext2_ino_t *old, + struct ext2_inode_relocate_entry *ent) +{ + struct irel_ma *ma; + + ma = irel->priv_data; + while (++irel->current < ma->max_inode) { + if (ma->entries[(unsigned) irel->current].new == 0) + continue; + *old = irel->current; + *ent = ma->entries[(unsigned) irel->current]; + return 0; + } + *old = 0; + return 0; +} + +static errcode_t ima_add_ref(ext2_irel irel, ext2_ino_t ino, + struct ext2_inode_reference *ref) +{ + struct irel_ma *ma; + size_t size; + struct inode_reference_entry *ref_ent; + struct ext2_inode_relocate_entry *ent; + errcode_t retval; + + ma = irel->priv_data; + if (ino > ma->max_inode) + return EXT2_ET_INVALID_ARGUMENT; + + ref_ent = ma->ref_entries + (unsigned) ino; + ent = ma->entries + (unsigned) ino; + + /* + * If the inode reference array doesn't exist, create it. + */ + if (ref_ent->refs == 0) { + size = (size_t) ((sizeof(struct ext2_inode_reference) * + ent->max_refs)); + retval = ext2fs_get_array(ent->max_refs, + sizeof(struct ext2_inode_reference), &ref_ent->refs); + if (retval) + return retval; + memset(ref_ent->refs, 0, size); + ref_ent->num = 0; + } + + if (ref_ent->num >= ent->max_refs) + return EXT2_ET_TOO_MANY_REFS; + + ref_ent->refs[(unsigned) ref_ent->num++] = *ref; + return 0; +} + +static errcode_t ima_start_iter_ref(ext2_irel irel, ext2_ino_t ino) +{ + struct irel_ma *ma; + + ma = irel->priv_data; + if (ino > ma->max_inode) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned) ino].new == 0) + return ENOENT; + ma->ref_current = ino; + ma->ref_iter = 0; + return 0; +} + +static errcode_t ima_next_ref(ext2_irel irel, + struct ext2_inode_reference *ref) +{ + struct irel_ma *ma; + struct inode_reference_entry *ref_ent; + + ma = irel->priv_data; + + ref_ent = ma->ref_entries + ma->ref_current; + + if ((ref_ent->refs == NULL) || + (ma->ref_iter >= ref_ent->num)) { + ref->block = 0; + ref->offset = 0; + return 0; + } + *ref = ref_ent->refs[ma->ref_iter++]; + return 0; +} + + +static errcode_t ima_move(ext2_irel irel, ext2_ino_t old, ext2_ino_t new) +{ + struct irel_ma *ma; + + ma = irel->priv_data; + if ((old > ma->max_inode) || (new > ma->max_inode)) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned) old].new == 0) + return ENOENT; + + ma->entries[(unsigned) new] = ma->entries[(unsigned) old]; + if (ma->ref_entries[(unsigned) new].refs) + ext2fs_free_mem(&ma->ref_entries[(unsigned) new].refs); + ma->ref_entries[(unsigned) new] = ma->ref_entries[(unsigned) old]; + + ma->entries[(unsigned) old].new = 0; + ma->ref_entries[(unsigned) old].num = 0; + ma->ref_entries[(unsigned) old].refs = 0; + + ma->orig_map[ma->entries[new].orig] = new; + return 0; +} + +static errcode_t ima_delete(ext2_irel irel, ext2_ino_t old) +{ + struct irel_ma *ma; + + ma = irel->priv_data; + if (old > ma->max_inode) + return EXT2_ET_INVALID_ARGUMENT; + if (ma->entries[(unsigned) old].new == 0) + return ENOENT; + + ma->entries[old].new = 0; + if (ma->ref_entries[(unsigned) old].refs) + ext2fs_free_mem(&ma->ref_entries[(unsigned) old].refs); + ma->orig_map[ma->entries[(unsigned) old].orig] = 0; + + ma->ref_entries[(unsigned) old].num = 0; + ma->ref_entries[(unsigned) old].refs = 0; + return 0; +} + +static errcode_t ima_free(ext2_irel irel) +{ + struct irel_ma *ma; + ext2_ino_t ino; + + if (!irel) + return 0; + + ma = irel->priv_data; + + if (ma) { + if (ma->orig_map) + ext2fs_free_mem(&ma->orig_map); + if (ma->entries) + ext2fs_free_mem(&ma->entries); + if (ma->ref_entries) { + for (ino = 0; ino <= ma->max_inode; ino++) { + if (ma->ref_entries[(unsigned) ino].refs) + ext2fs_free_mem(&ma->ref_entries[(unsigned) ino].refs); + } + ext2fs_free_mem(&ma->ref_entries); + } + ext2fs_free_mem(&ma); + } + if (irel->name) + ext2fs_free_mem(&irel->name); + ext2fs_free_mem(&irel); + return 0; +} diff --git a/libcustomext2fs/source/ismounted.c b/libcustomext2fs/source/ismounted.c new file mode 100644 index 00000000..bc1134fc --- /dev/null +++ b/libcustomext2fs/source/ismounted.c @@ -0,0 +1,383 @@ +/* + * ismounted.c --- Check to see if the filesystem was mounted + * + * Copyright (C) 1995,1996,1997,1998,1999,2000 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_LINUX_FD_H +#include +#endif +#ifdef HAVE_MNTENT_H +#include +#endif +#ifdef HAVE_GETMNTINFO +#include +#include +#include +#endif /* HAVE_GETMNTINFO */ +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifdef HAVE_MNTENT_H +/* + * Helper function which checks a file in /etc/mtab format to see if a + * filesystem is mounted. Returns an error if the file doesn't exist + * or can't be opened. + */ +static errcode_t check_mntent_file(const char *mtab_file, const char *file, + int *mount_flags, char *mtpt, int mtlen) +{ + struct mntent *mnt; + struct stat st_buf; + errcode_t retval = 0; + dev_t file_dev=0, file_rdev=0; + ino_t file_ino=0; + FILE *f; + int fd; + + *mount_flags = 0; + if ((f = setmntent (mtab_file, "r")) == NULL) + return (errno == ENOENT ? EXT2_NO_MTAB_FILE : errno); + if (stat(file, &st_buf) == 0) { + if (S_ISBLK(st_buf.st_mode)) { +#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ + file_rdev = st_buf.st_rdev; +#endif /* __GNU__ */ + } else { + file_dev = st_buf.st_dev; + file_ino = st_buf.st_ino; + } + } + while ((mnt = getmntent (f)) != NULL) { + if (mnt->mnt_fsname[0] != '/') + continue; + if (strcmp(file, mnt->mnt_fsname) == 0) + break; + if (stat(mnt->mnt_fsname, &st_buf) == 0) { + if (S_ISBLK(st_buf.st_mode)) { +#ifndef __GNU__ + if (file_rdev && (file_rdev == st_buf.st_rdev)) + break; +#endif /* __GNU__ */ + } else { + if (file_dev && ((file_dev == st_buf.st_dev) && + (file_ino == st_buf.st_ino))) + break; + } + } + } + + if (mnt == 0) { +#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ + /* + * Do an extra check to see if this is the root device. We + * can't trust /etc/mtab, and /proc/mounts will only list + * /dev/root for the root filesystem. Argh. Instead we + * check if the given device has the same major/minor number + * as the device that the root directory is on. + */ + if (file_rdev && stat("/", &st_buf) == 0) { + if (st_buf.st_dev == file_rdev) { + *mount_flags = EXT2_MF_MOUNTED; + if (mtpt) + strncpy(mtpt, "/", mtlen); + goto is_root; + } + } +#endif /* __GNU__ */ + goto errout; + } +#ifndef __GNU__ /* The GNU hurd is deficient; what else is new? */ + /* Validate the entry in case /etc/mtab is out of date */ + /* + * We need to be paranoid, because some broken distributions + * (read: Slackware) don't initialize /etc/mtab before checking + * all of the non-root filesystems on the disk. + */ + if (stat(mnt->mnt_dir, &st_buf) < 0) { + retval = errno; + if (retval == ENOENT) { +#ifdef DEBUG + printf("Bogus entry in %s! (%s does not exist)\n", + mtab_file, mnt->mnt_dir); +#endif /* DEBUG */ + retval = 0; + } + goto errout; + } + if (file_rdev && (st_buf.st_dev != file_rdev)) { +#ifdef DEBUG + printf("Bogus entry in %s! (%s not mounted on %s)\n", + mtab_file, file, mnt->mnt_dir); +#endif /* DEBUG */ + goto errout; + } +#endif /* __GNU__ */ + *mount_flags = EXT2_MF_MOUNTED; + +#ifdef MNTOPT_RO + /* Check to see if the ro option is set */ + if (hasmntopt(mnt, MNTOPT_RO)) + *mount_flags |= EXT2_MF_READONLY; +#endif + + if (mtpt) + strncpy(mtpt, mnt->mnt_dir, mtlen); + /* + * Check to see if we're referring to the root filesystem. + * If so, do a manual check to see if we can open /etc/mtab + * read/write, since if the root is mounted read/only, the + * contents of /etc/mtab may not be accurate. + */ + if (!strcmp(mnt->mnt_dir, "/")) { +is_root: +#define TEST_FILE "/.ismount-test-file" + *mount_flags |= EXT2_MF_ISROOT; + fd = open(TEST_FILE, O_RDWR|O_CREAT, 0600); + if (fd < 0) { + if (errno == EROFS) + *mount_flags |= EXT2_MF_READONLY; + } else + close(fd); + (void) unlink(TEST_FILE); + } + retval = 0; +errout: + endmntent (f); + return retval; +} + +static errcode_t check_mntent(const char *file, int *mount_flags, + char *mtpt, int mtlen) +{ + errcode_t retval; + +#ifdef DEBUG + retval = check_mntent_file("/tmp/mtab", file, mount_flags, + mtpt, mtlen); + if (retval == 0) + return 0; +#endif /* DEBUG */ +#ifdef __linux__ + retval = check_mntent_file("/proc/mounts", file, mount_flags, + mtpt, mtlen); + if (retval == 0 && (*mount_flags != 0)) + return 0; +#endif /* __linux__ */ +#if defined(MOUNTED) || defined(_PATH_MOUNTED) +#ifndef MOUNTED +#define MOUNTED _PATH_MOUNTED +#endif /* MOUNTED */ + retval = check_mntent_file(MOUNTED, file, mount_flags, mtpt, mtlen); + return retval; +#else + *mount_flags = 0; + return 0; +#endif /* defined(MOUNTED) || defined(_PATH_MOUNTED) */ +} + +#else +#if defined(HAVE_GETMNTINFO) + +static errcode_t check_getmntinfo(const char *file, int *mount_flags, + char *mtpt, int mtlen) +{ + struct statfs *mp; + int len, n; + const char *s1; + char *s2; + + n = getmntinfo(&mp, MNT_NOWAIT); + if (n == 0) + return errno; + + len = sizeof(_PATH_DEV) - 1; + s1 = file; + if (strncmp(_PATH_DEV, s1, len) == 0) + s1 += len; + + *mount_flags = 0; + while (--n >= 0) { + s2 = mp->f_mntfromname; + if (strncmp(_PATH_DEV, s2, len) == 0) { + s2 += len - 1; + *s2 = 'r'; + } + if (strcmp(s1, s2) == 0 || strcmp(s1, &s2[1]) == 0) { + *mount_flags = EXT2_MF_MOUNTED; + break; + } + ++mp; + } + if (mtpt) + strncpy(mtpt, mp->f_mntonname, mtlen); + return 0; +} +#endif /* HAVE_GETMNTINFO */ +#endif /* HAVE_MNTENT_H */ + +/* + * Check to see if we're dealing with the swap device. + */ +static int is_swap_device(const char *file) +{ + FILE *f; + char buf[1024], *cp; + dev_t file_dev; + struct stat st_buf; + int ret = 0; + + file_dev = 0; +#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */ + if ((stat(file, &st_buf) == 0) && + S_ISBLK(st_buf.st_mode)) + file_dev = st_buf.st_rdev; +#endif /* __GNU__ */ + + if (!(f = fopen("/proc/swaps", "r"))) + return 0; + /* Skip the first line */ + if (!fgets(buf, sizeof(buf), f)) + goto leave; + if (*buf && strncmp(buf, "Filename\t", 9)) + /* Linux <=2.6.19 contained a bug in the /proc/swaps + * code where the header would not be displayed + */ + goto valid_first_line; + + while (fgets(buf, sizeof(buf), f)) { +valid_first_line: + if ((cp = strchr(buf, ' ')) != NULL) + *cp = 0; + if ((cp = strchr(buf, '\t')) != NULL) + *cp = 0; + if (strcmp(buf, file) == 0) { + ret++; + break; + } +#ifndef __GNU__ + if (file_dev && (stat(buf, &st_buf) == 0) && + S_ISBLK(st_buf.st_mode) && + file_dev == st_buf.st_rdev) { + ret++; + break; + } +#endif /* __GNU__ */ + } + +leave: + fclose(f); + return ret; +} + + +/* + * ext2fs_check_mount_point() fills determines if the device is + * mounted or otherwise busy, and fills in mount_flags with one or + * more of the following flags: EXT2_MF_MOUNTED, EXT2_MF_ISROOT, + * EXT2_MF_READONLY, EXT2_MF_SWAP, and EXT2_MF_BUSY. If mtpt is + * non-NULL, the directory where the device is mounted is copied to + * where mtpt is pointing, up to mtlen characters. + */ +#ifdef __TURBOC__ + #pragma argsused +#endif +errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags, + char *mtpt, int mtlen) +{ + errcode_t retval = 0; + + if (is_swap_device(device)) { + *mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP; + strncpy(mtpt, "", mtlen); + } else { +#ifdef HAVE_MNTENT_H + retval = check_mntent(device, mount_flags, mtpt, mtlen); +#else +#ifdef HAVE_GETMNTINFO + retval = check_getmntinfo(device, mount_flags, mtpt, mtlen); +#else + *mount_flags = 0; +#endif /* HAVE_GETMNTINFO */ +#endif /* HAVE_MNTENT_H */ + } + if (retval) + return retval; + +#ifdef __linux__ /* This only works on Linux 2.6+ systems */ + if ((stat(device, &st_buf) != 0) || + !S_ISBLK(st_buf.st_mode)) + return 0; + fd = open(device, O_RDONLY | O_EXCL); + if (fd < 0) { + if (errno == EBUSY) + *mount_flags |= EXT2_MF_BUSY; + } else + close(fd); +#endif + + return 0; +} + +/* + * ext2fs_check_if_mounted() sets the mount_flags EXT2_MF_MOUNTED, + * EXT2_MF_READONLY, and EXT2_MF_ROOT + * + */ +errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags) +{ + return ext2fs_check_mount_point(file, mount_flags, NULL, 0); +} + +#ifdef DEBUG +int main(int argc, char **argv) +{ + int retval, mount_flags; + char mntpt[80]; + + if (argc < 2) { + fprintf(stderr, "Usage: %s device\n", argv[0]); + exit(1); + } + + add_error_table(&et_ext2_error_table); + mntpt[0] = 0; + retval = ext2fs_check_mount_point(argv[1], &mount_flags, + mntpt, sizeof(mntpt)); + if (retval) { + com_err(argv[0], retval, + "while calling ext2fs_check_if_mounted"); + exit(1); + } + printf("Device %s reports flags %02x\n", argv[1], mount_flags); + if (mount_flags & EXT2_MF_BUSY) + printf("\t%s is apparently in use.\n", argv[1]); + if (mount_flags & EXT2_MF_MOUNTED) + printf("\t%s is mounted.\n", argv[1]); + if (mount_flags & EXT2_MF_SWAP) + printf("\t%s is a swap device.\n", argv[1]); + if (mount_flags & EXT2_MF_READONLY) + printf("\t%s is read-only.\n", argv[1]); + if (mount_flags & EXT2_MF_ISROOT) + printf("\t%s is the root filesystem.\n", argv[1]); + if (mntpt[0]) + printf("\t%s is mounted on %s.\n", argv[1], mntpt); + exit(0); +} +#endif /* DEBUG */ diff --git a/libcustomext2fs/source/jfs_compat.h b/libcustomext2fs/source/jfs_compat.h new file mode 100644 index 00000000..7b8aafd7 --- /dev/null +++ b/libcustomext2fs/source/jfs_compat.h @@ -0,0 +1,68 @@ + +#ifndef _JFS_COMPAT_H +#define _JFS_COMPAT_H + +#include "kernel-list.h" +#include +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#define printk printf +#define KERN_ERR "" +#define KERN_DEBUG "" + +#define READ 0 +#define WRITE 1 + +#define cpu_to_be32(n) htonl(n) +#define be32_to_cpu(n) ntohl(n) + +typedef unsigned int tid_t; +typedef struct journal_s journal_t; + +struct buffer_head; +struct inode; + +struct journal_s +{ + unsigned long j_flags; + int j_errno; + struct buffer_head * j_sb_buffer; + struct journal_superblock_s *j_superblock; + int j_format_version; + unsigned long j_head; + unsigned long j_tail; + unsigned long j_free; + unsigned long j_first, j_last; + kdev_t j_dev; + kdev_t j_fs_dev; + int j_blocksize; + unsigned int j_blk_offset; + unsigned int j_maxlen; + struct inode * j_inode; + tid_t j_tail_sequence; + tid_t j_transaction_sequence; + __u8 j_uuid[16]; + struct jbd_revoke_table_s *j_revoke; + tid_t j_failed_commit; +}; + +#define J_ASSERT(assert) \ + do { if (!(assert)) { \ + printf ("Assertion failure in %s() at %s line %d: " \ + "\"%s\"\n", \ + __FUNCTION__, __FILE__, __LINE__, # assert); \ + fatal_error(e2fsck_global_ctx, 0); \ + } } while (0) + +#define is_journal_abort(x) 0 + +#define BUFFER_TRACE(bh, info) do {} while (0) + +/* Need this so we can compile with configure --enable-gcc-wall */ +#ifdef NO_INLINE_FUNCS +#define inline +#endif + +#endif /* _JFS_COMPAT_H */ diff --git a/libcustomext2fs/source/jfs_dat.h b/libcustomext2fs/source/jfs_dat.h new file mode 100644 index 00000000..62778c62 --- /dev/null +++ b/libcustomext2fs/source/jfs_dat.h @@ -0,0 +1,64 @@ +/* + * jfs_dat.h --- stripped down header file which only contains the JFS + * on-disk data structures + */ + +#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */ + +/* + * On-disk structures + */ + +/* + * Descriptor block types: + */ + +#define JFS_DESCRIPTOR_BLOCK 1 +#define JFS_COMMIT_BLOCK 2 +#define JFS_SUPERBLOCK 3 + +/* + * Standard header for all descriptor blocks: + */ +typedef struct journal_header_s +{ + __u32 h_magic; + __u32 h_blocktype; + __u32 h_sequence; +} journal_header_t; + + +/* + * The block tag: used to describe a single buffer in the journal + */ +typedef struct journal_block_tag_s +{ + __u32 t_blocknr; /* The on-disk block number */ + __u32 t_flags; /* See below */ +} journal_block_tag_t; + +/* Definitions for the journal tag flags word: */ +#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */ +#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */ +#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */ +#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */ + + +/* + * The journal superblock + */ +typedef struct journal_superblock_s +{ + journal_header_t s_header; + + /* Static information describing the journal */ + __u32 s_blocksize; /* journal device blocksize */ + __u32 s_maxlen; /* total blocks in journal file */ + __u32 s_first; /* first block of log information */ + + /* Dynamic information describing the current state of the log */ + __u32 s_sequence; /* first commit ID expected in log */ + __u32 s_start; /* blocknr of start of log */ + +} journal_superblock_t; + diff --git a/libcustomext2fs/source/jfs_user.h b/libcustomext2fs/source/jfs_user.h new file mode 100644 index 00000000..3a521230 --- /dev/null +++ b/libcustomext2fs/source/jfs_user.h @@ -0,0 +1,8 @@ +#ifndef _JFS_USER_H +#define _JFS_USER_H + +typedef unsigned short kdev_t; + +#include "kernel-jbd.h" + +#endif /* _JFS_USER_H */ diff --git a/libcustomext2fs/source/kernel-jbd.h b/libcustomext2fs/source/kernel-jbd.h new file mode 100644 index 00000000..066c031e --- /dev/null +++ b/libcustomext2fs/source/kernel-jbd.h @@ -0,0 +1,952 @@ +/* + * linux/include/linux/jbd.h + * + * Written by Stephen C. Tweedie + * + * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved + * + * This file is part of the Linux kernel and is made available under + * the terms of the GNU General Public License, version 2, or at your + * option, any later version, incorporated herein by reference. + * + * Definitions for transaction data structures for the buffer cache + * filesystem journaling support. + */ + +#ifndef _LINUX_JBD_H +#define _LINUX_JBD_H + +#if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || !defined(__KERNEL__) + +/* Allow this file to be included directly into e2fsprogs */ +#ifndef __KERNEL__ +#include "jfs_compat.h" +#define JFS_DEBUG +#define jfs_debug jbd_debug +#else + +#include +#include +#include +#endif + +#ifndef __GNUC__ +#define __FUNCTION__ "" +#endif + +#define journal_oom_retry 1 + +#ifdef __STDC__ +#ifdef CONFIG_JBD_DEBUG +/* + * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal + * consistency checks. By default we don't do this unless + * CONFIG_JBD_DEBUG is on. + */ +#define JBD_EXPENSIVE_CHECKING +extern int journal_enable_debug; + +#define jbd_debug(n, f, a...) \ + do { \ + if ((n) <= journal_enable_debug) { \ + printk (KERN_DEBUG "(%s, %d): %s: ", \ + __FILE__, __LINE__, __FUNCTION__); \ + printk (f, ## a); \ + } \ + } while (0) +#else +#ifdef __GNUC__ +#define jbd_debug(f, a...) /**/ +#else +#define jbd_debug(f, ...) /**/ +#endif +#endif +#else +#define jbd_debug(x) /* AIX doesn't do STDC */ +#endif + +extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry); +#define jbd_kmalloc(size, flags) \ + __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry) +#define jbd_rep_kmalloc(size, flags) \ + __jbd_kmalloc(__FUNCTION__, (size), (flags), 1) + +#define JFS_MIN_JOURNAL_BLOCKS 1024 + +#ifdef __KERNEL__ +typedef struct handle_s handle_t; /* Atomic operation type */ +typedef struct journal_s journal_t; /* Journal control structure */ +#endif + +/* + * Internal structures used by the logging mechanism: + */ + +#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */ + +/* + * On-disk structures + */ + +/* + * Descriptor block types: + */ + +#define JFS_DESCRIPTOR_BLOCK 1 +#define JFS_COMMIT_BLOCK 2 +#define JFS_SUPERBLOCK_V1 3 +#define JFS_SUPERBLOCK_V2 4 +#define JFS_REVOKE_BLOCK 5 + +/* + * Standard header for all descriptor blocks: + */ +typedef struct journal_header_s +{ + __u32 h_magic; + __u32 h_blocktype; + __u32 h_sequence; +} journal_header_t; + +/* + * Checksum types. + */ +#define JBD2_CRC32_CHKSUM 1 +#define JBD2_MD5_CHKSUM 2 +#define JBD2_SHA1_CHKSUM 3 + +#define JBD2_CRC32_CHKSUM_SIZE 4 + +#define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32)) +/* + * Commit block header for storing transactional checksums: + */ +struct commit_header { + __u32 h_magic; + __u32 h_blocktype; + __u32 h_sequence; + unsigned char h_chksum_type; + unsigned char h_chksum_size; + unsigned char h_padding[2]; + __u32 h_chksum[JBD2_CHECKSUM_BYTES]; + __u64 h_commit_sec; + __u32 h_commit_nsec; +}; + +/* + * The block tag: used to describe a single buffer in the journal + */ +typedef struct journal_block_tag_s +{ + __u32 t_blocknr; /* The on-disk block number */ + __u32 t_flags; /* See below */ + __u32 t_blocknr_high; /* most-significant high 32bits. */ +} journal_block_tag_t; + +#define JBD_TAG_SIZE64 (sizeof(journal_block_tag_t)) +#define JBD_TAG_SIZE32 (8) + +/* + * The revoke descriptor: used on disk to describe a series of blocks to + * be revoked from the log + */ +typedef struct journal_revoke_header_s +{ + journal_header_t r_header; + int r_count; /* Count of bytes used in the block */ +} journal_revoke_header_t; + + +/* Definitions for the journal tag flags word: */ +#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */ +#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */ +#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */ +#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */ + + +/* + * The journal superblock. All fields are in big-endian byte order. + */ +typedef struct journal_superblock_s +{ +/* 0x0000 */ + journal_header_t s_header; + +/* 0x000C */ + /* Static information describing the journal */ + __u32 s_blocksize; /* journal device blocksize */ + __u32 s_maxlen; /* total blocks in journal file */ + __u32 s_first; /* first block of log information */ + +/* 0x0018 */ + /* Dynamic information describing the current state of the log */ + __u32 s_sequence; /* first commit ID expected in log */ + __u32 s_start; /* blocknr of start of log */ + +/* 0x0020 */ + /* Error value, as set by journal_abort(). */ + __s32 s_errno; + +/* 0x0024 */ + /* Remaining fields are only valid in a version-2 superblock */ + __u32 s_feature_compat; /* compatible feature set */ + __u32 s_feature_incompat; /* incompatible feature set */ + __u32 s_feature_ro_compat; /* readonly-compatible feature set */ +/* 0x0030 */ + __u8 s_uuid[16]; /* 128-bit uuid for journal */ + +/* 0x0040 */ + __u32 s_nr_users; /* Nr of filesystems sharing log */ + + __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/ + +/* 0x0048 */ + __u32 s_max_transaction; /* Limit of journal blocks per trans.*/ + __u32 s_max_trans_data; /* Limit of data blocks per trans. */ + +/* 0x0050 */ + __u32 s_padding[44]; + +/* 0x0100 */ + __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ +/* 0x0400 */ +} journal_superblock_t; + +#define JFS_HAS_COMPAT_FEATURE(j,mask) \ + ((j)->j_format_version >= 2 && \ + ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask)))) +#define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \ + ((j)->j_format_version >= 2 && \ + ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask)))) +#define JFS_HAS_INCOMPAT_FEATURE(j,mask) \ + ((j)->j_format_version >= 2 && \ + ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) + +#define JFS_FEATURE_COMPAT_CHECKSUM 0x00000001 + +#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 + +#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 +#define JFS_FEATURE_INCOMPAT_64BIT 0x00000002 +#define JFS_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 + +/* Features known to this kernel version: */ +#define JFS_KNOWN_COMPAT_FEATURES 0 +#define JFS_KNOWN_ROCOMPAT_FEATURES 0 +#define JFS_KNOWN_INCOMPAT_FEATURES (JFS_FEATURE_INCOMPAT_REVOKE|\ + JFS_FEATURE_INCOMPAT_ASYNC_COMMIT|\ + JFS_FEATURE_INCOMPAT_64BIT) + +#ifdef __KERNEL__ + +#include +#include + +#define JBD_ASSERTIONS +#ifdef JBD_ASSERTIONS +#define J_ASSERT(assert) \ +do { \ + if (!(assert)) { \ + printk (KERN_EMERG \ + "Assertion failure in %s() at %s:%d: \"%s\"\n", \ + __FUNCTION__, __FILE__, __LINE__, # assert); \ + BUG(); \ + } \ +} while (0) + +#if defined(CONFIG_BUFFER_DEBUG) +void buffer_assertion_failure(struct buffer_head *bh); +#define J_ASSERT_BH(bh, expr) \ + do { \ + if (!(expr)) \ + buffer_assertion_failure(bh); \ + J_ASSERT(expr); \ + } while (0) +#define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr) +#else +#define J_ASSERT_BH(bh, expr) J_ASSERT(expr) +#define J_ASSERT_JH(jh, expr) J_ASSERT(expr) +#endif + +#else +#define J_ASSERT(assert) +#endif /* JBD_ASSERTIONS */ + +enum jbd_state_bits { + BH_JWrite + = BH_PrivateStart, /* 1 if being written to log (@@@ DEBUGGING) */ + BH_Freed, /* 1 if buffer has been freed (truncated) */ + BH_Revoked, /* 1 if buffer has been revoked from the log */ + BH_RevokeValid, /* 1 if buffer revoked flag is valid */ + BH_JBDDirty, /* 1 if buffer is dirty but journaled */ +}; + +/* Return true if the buffer is one which JBD is managing */ +static inline int buffer_jbd(struct buffer_head *bh) +{ + return __buffer_state(bh, JBD); +} + +static inline struct buffer_head *jh2bh(struct journal_head *jh) +{ + return jh->b_bh; +} + +static inline struct journal_head *bh2jh(struct buffer_head *bh) +{ + return bh->b_private; +} + +struct jbd_revoke_table_s; + +/* The handle_t type represents a single atomic update being performed + * by some process. All filesystem modifications made by the process go + * through this handle. Recursive operations (such as quota operations) + * are gathered into a single update. + * + * The buffer credits field is used to account for journaled buffers + * being modified by the running process. To ensure that there is + * enough log space for all outstanding operations, we need to limit the + * number of outstanding buffers possible at any time. When the + * operation completes, any buffer credits not used are credited back to + * the transaction, so that at all times we know how many buffers the + * outstanding updates on a transaction might possibly touch. */ + +struct handle_s +{ + /* Which compound transaction is this update a part of? */ + transaction_t * h_transaction; + + /* Number of remaining buffers we are allowed to dirty: */ + int h_buffer_credits; + + /* Reference count on this handle */ + int h_ref; + + /* Field for caller's use to track errors through large fs + operations */ + int h_err; + + /* Flags */ + unsigned int h_sync: 1; /* sync-on-close */ + unsigned int h_jdata: 1; /* force data journaling */ + unsigned int h_aborted: 1; /* fatal error on handle */ +}; + + +/* The transaction_t type is the guts of the journaling mechanism. It + * tracks a compound transaction through its various states: + * + * RUNNING: accepting new updates + * LOCKED: Updates still running but we don't accept new ones + * RUNDOWN: Updates are tidying up but have finished requesting + * new buffers to modify (state not used for now) + * FLUSH: All updates complete, but we are still writing to disk + * COMMIT: All data on disk, writing commit record + * FINISHED: We still have to keep the transaction for checkpointing. + * + * The transaction keeps track of all of the buffers modified by a + * running transaction, and all of the buffers committed but not yet + * flushed to home for finished transactions. + */ + +struct transaction_s +{ + /* Pointer to the journal for this transaction. */ + journal_t * t_journal; + + /* Sequence number for this transaction */ + tid_t t_tid; + + /* Transaction's current state */ + enum { + T_RUNNING, + T_LOCKED, + T_RUNDOWN, + T_FLUSH, + T_COMMIT, + T_FINISHED + } t_state; + + /* Where in the log does this transaction's commit start? */ + unsigned long t_log_start; + + /* Doubly-linked circular list of all inodes owned by this + transaction */ /* AKPM: unused */ + struct inode * t_ilist; + + /* Number of buffers on the t_buffers list */ + int t_nr_buffers; + + /* Doubly-linked circular list of all buffers reserved but not + yet modified by this transaction */ + struct journal_head * t_reserved_list; + + /* Doubly-linked circular list of all metadata buffers owned by this + transaction */ + struct journal_head * t_buffers; + + /* + * Doubly-linked circular list of all data buffers still to be + * flushed before this transaction can be committed. + * Protected by journal_datalist_lock. + */ + struct journal_head * t_sync_datalist; + + /* + * Doubly-linked circular list of all writepage data buffers + * still to be written before this transaction can be committed. + * Protected by journal_datalist_lock. + */ + struct journal_head * t_async_datalist; + + /* Doubly-linked circular list of all forget buffers (superceded + buffers which we can un-checkpoint once this transaction + commits) */ + struct journal_head * t_forget; + + /* + * Doubly-linked circular list of all buffers still to be + * flushed before this transaction can be checkpointed. + */ + /* Protected by journal_datalist_lock */ + struct journal_head * t_checkpoint_list; + + /* Doubly-linked circular list of temporary buffers currently + undergoing IO in the log */ + struct journal_head * t_iobuf_list; + + /* Doubly-linked circular list of metadata buffers being + shadowed by log IO. The IO buffers on the iobuf list and the + shadow buffers on this list match each other one for one at + all times. */ + struct journal_head * t_shadow_list; + + /* Doubly-linked circular list of control buffers being written + to the log. */ + struct journal_head * t_log_list; + + /* Number of outstanding updates running on this transaction */ + int t_updates; + + /* Number of buffers reserved for use by all handles in this + * transaction handle but not yet modified. */ + int t_outstanding_credits; + + /* + * Forward and backward links for the circular list of all + * transactions awaiting checkpoint. + */ + /* Protected by journal_datalist_lock */ + transaction_t *t_cpnext, *t_cpprev; + + /* When will the transaction expire (become due for commit), in + * jiffies ? */ + unsigned long t_expires; + + /* How many handles used this transaction? */ + int t_handle_count; +}; + + +/* The journal_t maintains all of the journaling state information for a + * single filesystem. It is linked to from the fs superblock structure. + * + * We use the journal_t to keep track of all outstanding transaction + * activity on the filesystem, and to manage the state of the log + * writing process. */ + +struct journal_s +{ + /* General journaling state flags */ + unsigned long j_flags; + + /* Is there an outstanding uncleared error on the journal (from + * a prior abort)? */ + int j_errno; + + /* The superblock buffer */ + struct buffer_head * j_sb_buffer; + journal_superblock_t * j_superblock; + + /* Version of the superblock format */ + int j_format_version; + + /* Number of processes waiting to create a barrier lock */ + int j_barrier_count; + + /* The barrier lock itself */ + struct semaphore j_barrier; + + /* Transactions: The current running transaction... */ + transaction_t * j_running_transaction; + + /* ... the transaction we are pushing to disk ... */ + transaction_t * j_committing_transaction; + + /* ... and a linked circular list of all transactions waiting + * for checkpointing. */ + /* Protected by journal_datalist_lock */ + transaction_t * j_checkpoint_transactions; + + /* Wait queue for waiting for a locked transaction to start + committing, or for a barrier lock to be released */ + wait_queue_head_t j_wait_transaction_locked; + + /* Wait queue for waiting for checkpointing to complete */ + wait_queue_head_t j_wait_logspace; + + /* Wait queue for waiting for commit to complete */ + wait_queue_head_t j_wait_done_commit; + + /* Wait queue to trigger checkpointing */ + wait_queue_head_t j_wait_checkpoint; + + /* Wait queue to trigger commit */ + wait_queue_head_t j_wait_commit; + + /* Wait queue to wait for updates to complete */ + wait_queue_head_t j_wait_updates; + + /* Semaphore for locking against concurrent checkpoints */ + struct semaphore j_checkpoint_sem; + + /* The main journal lock, used by lock_journal() */ + struct semaphore j_sem; + + /* Journal head: identifies the first unused block in the journal. */ + unsigned long j_head; + + /* Journal tail: identifies the oldest still-used block in the + * journal. */ + unsigned long j_tail; + + /* Journal free: how many free blocks are there in the journal? */ + unsigned long j_free; + + /* Journal start and end: the block numbers of the first usable + * block and one beyond the last usable block in the journal. */ + unsigned long j_first, j_last; + + /* Device, blocksize and starting block offset for the location + * where we store the journal. */ + kdev_t j_dev; + int j_blocksize; + unsigned int j_blk_offset; + + /* Device which holds the client fs. For internal journal this + * will be equal to j_dev. */ + kdev_t j_fs_dev; + + /* Total maximum capacity of the journal region on disk. */ + unsigned int j_maxlen; + + /* Optional inode where we store the journal. If present, all + * journal block numbers are mapped into this inode via + * bmap(). */ + struct inode * j_inode; + + /* Sequence number of the oldest transaction in the log */ + tid_t j_tail_sequence; + /* Sequence number of the next transaction to grant */ + tid_t j_transaction_sequence; + /* Sequence number of the most recently committed transaction */ + tid_t j_commit_sequence; + /* Sequence number of the most recent transaction wanting commit */ + tid_t j_commit_request; + + /* Journal uuid: identifies the object (filesystem, LVM volume + * etc) backed by this journal. This will eventually be + * replaced by an array of uuids, allowing us to index multiple + * devices within a single journal and to perform atomic updates + * across them. */ + + __u8 j_uuid[16]; + + /* Pointer to the current commit thread for this journal */ + struct task_struct * j_task; + + /* Maximum number of metadata buffers to allow in a single + * compound commit transaction */ + int j_max_transaction_buffers; + + /* What is the maximum transaction lifetime before we begin a + * commit? */ + unsigned long j_commit_interval; + + /* The timer used to wakeup the commit thread: */ + struct timer_list * j_commit_timer; + int j_commit_timer_active; + + /* Link all journals together - system-wide */ + struct list_head j_all_journals; + + /* The revoke table: maintains the list of revoked blocks in the + current transaction. */ + struct jbd_revoke_table_s *j_revoke; + + /* Failed journal commit ID */ + unsigned int j_failed_commit; +}; + +/* + * Journal flag definitions + */ +#define JFS_UNMOUNT 0x001 /* Journal thread is being destroyed */ +#define JFS_ABORT 0x002 /* Journaling has been aborted for errors. */ +#define JFS_ACK_ERR 0x004 /* The errno in the sb has been acked */ +#define JFS_FLUSHED 0x008 /* The journal superblock has been flushed */ +#define JFS_LOADED 0x010 /* The journal superblock has been loaded */ + +/* + * Function declarations for the journaling transaction and buffer + * management + */ + +/* Filing buffers */ +extern void __journal_unfile_buffer(struct journal_head *); +extern void journal_unfile_buffer(struct journal_head *); +extern void __journal_refile_buffer(struct journal_head *); +extern void journal_refile_buffer(struct journal_head *); +extern void __journal_file_buffer(struct journal_head *, transaction_t *, int); +extern void __journal_free_buffer(struct journal_head *bh); +extern void journal_file_buffer(struct journal_head *, transaction_t *, int); +extern void __journal_clean_data_list(transaction_t *transaction); + +/* Log buffer allocation */ +extern struct journal_head * journal_get_descriptor_buffer(journal_t *); +extern unsigned long journal_next_log_block(journal_t *); + +/* Commit management */ +extern void journal_commit_transaction(journal_t *); + +/* Checkpoint list management */ +int __journal_clean_checkpoint_list(journal_t *journal); +extern void journal_remove_checkpoint(struct journal_head *); +extern void __journal_remove_checkpoint(struct journal_head *); +extern void journal_insert_checkpoint(struct journal_head *, transaction_t *); +extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *); + +/* Buffer IO */ +extern int +journal_write_metadata_buffer(transaction_t *transaction, + struct journal_head *jh_in, + struct journal_head **jh_out, + int blocknr); + +/* Transaction locking */ +extern void __wait_on_journal (journal_t *); + +/* + * Journal locking. + * + * We need to lock the journal during transaction state changes so that + * nobody ever tries to take a handle on the running transaction while + * we are in the middle of moving it to the commit phase. + * + * Note that the locking is completely interrupt unsafe. We never touch + * journal structures from interrupts. + * + * In 2.2, the BKL was required for lock_journal. This is no longer + * the case. + */ + +static inline void lock_journal(journal_t *journal) +{ + down(&journal->j_sem); +} + +/* This returns zero if we acquired the semaphore */ +static inline int try_lock_journal(journal_t * journal) +{ + return down_trylock(&journal->j_sem); +} + +static inline void unlock_journal(journal_t * journal) +{ + up(&journal->j_sem); +} + + +static inline handle_t *journal_current_handle(void) +{ + return current->journal_info; +} + +/* The journaling code user interface: + * + * Create and destroy handles + * Register buffer modifications against the current transaction. + */ + +extern handle_t *journal_start(journal_t *, int nblocks); +extern handle_t *journal_try_start(journal_t *, int nblocks); +extern int journal_restart (handle_t *, int nblocks); +extern int journal_extend (handle_t *, int nblocks); +extern int journal_get_write_access (handle_t *, struct buffer_head *); +extern int journal_get_create_access (handle_t *, struct buffer_head *); +extern int journal_get_undo_access (handle_t *, struct buffer_head *); +extern int journal_dirty_data (handle_t *, + struct buffer_head *, int async); +extern int journal_dirty_metadata (handle_t *, struct buffer_head *); +extern void journal_release_buffer (handle_t *, struct buffer_head *); +extern void journal_forget (handle_t *, struct buffer_head *); +extern void journal_sync_buffer (struct buffer_head *); +extern int journal_flushpage(journal_t *, struct page *, unsigned long); +extern int journal_try_to_free_buffers(journal_t *, struct page *, int); +extern int journal_stop(handle_t *); +extern int journal_flush (journal_t *); + +extern void journal_lock_updates (journal_t *); +extern void journal_unlock_updates (journal_t *); + +extern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev, + int start, int len, int bsize); +extern journal_t * journal_init_inode (struct inode *); +extern int journal_update_format (journal_t *); +extern int journal_check_used_features + (journal_t *, unsigned long, unsigned long, unsigned long); +extern int journal_check_available_features + (journal_t *, unsigned long, unsigned long, unsigned long); +extern int journal_set_features + (journal_t *, unsigned long, unsigned long, unsigned long); +extern int journal_create (journal_t *); +extern int journal_load (journal_t *journal); +extern void journal_destroy (journal_t *); +extern int journal_recover (journal_t *journal); +extern int journal_wipe (journal_t *, int); +extern int journal_skip_recovery (journal_t *); +extern void journal_update_superblock (journal_t *, int); +extern void __journal_abort (journal_t *); +extern void journal_abort (journal_t *, int); +extern int journal_errno (journal_t *); +extern void journal_ack_err (journal_t *); +extern int journal_clear_err (journal_t *); +extern unsigned long journal_bmap(journal_t *journal, unsigned long blocknr); +extern int journal_force_commit(journal_t *journal); + +/* + * journal_head management + */ +extern struct journal_head + *journal_add_journal_head(struct buffer_head *bh); +extern void journal_remove_journal_head(struct buffer_head *bh); +extern void __journal_remove_journal_head(struct buffer_head *bh); +extern void journal_unlock_journal_head(struct journal_head *jh); + +/* Primary revoke support */ +#define JOURNAL_REVOKE_DEFAULT_HASH 256 +extern int journal_init_revoke(journal_t *, int); +extern void journal_destroy_revoke_caches(void); +extern int journal_init_revoke_caches(void); + +extern void journal_destroy_revoke(journal_t *); +extern int journal_revoke (handle_t *, + unsigned long, struct buffer_head *); +extern int journal_cancel_revoke(handle_t *, struct journal_head *); +extern void journal_write_revoke_records(journal_t *, transaction_t *); + +/* Recovery revoke support */ +extern int journal_set_revoke(journal_t *, unsigned long, tid_t); +extern int journal_test_revoke(journal_t *, unsigned long, tid_t); +extern void journal_clear_revoke(journal_t *); +extern void journal_brelse_array(struct buffer_head *b[], int n); + +/* The log thread user interface: + * + * Request space in the current transaction, and force transaction commit + * transitions on demand. + */ + +extern int log_space_left (journal_t *); /* Called with journal locked */ +extern tid_t log_start_commit (journal_t *, transaction_t *); +extern void log_wait_commit (journal_t *, tid_t); +extern int log_do_checkpoint (journal_t *, int); + +extern void log_wait_for_space(journal_t *, int nblocks); +extern void __journal_drop_transaction(journal_t *, transaction_t *); +extern int cleanup_journal_tail(journal_t *); + +/* Reduce journal memory usage by flushing */ +extern void shrink_journal_memory(void); + +/* Debugging code only: */ + +#define jbd_ENOSYS() \ +do { \ + printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \ + current->state = TASK_UNINTERRUPTIBLE; \ + schedule(); \ +} while (1) + +/* + * is_journal_abort + * + * Simple test wrapper function to test the JFS_ABORT state flag. This + * bit, when set, indicates that we have had a fatal error somewhere, + * either inside the journaling layer or indicated to us by the client + * (eg. ext3), and that we and should not commit any further + * transactions. + */ + +static inline int is_journal_aborted(journal_t *journal) +{ + return journal->j_flags & JFS_ABORT; +} + +static inline int is_handle_aborted(handle_t *handle) +{ + if (handle->h_aborted) + return 1; + return is_journal_aborted(handle->h_transaction->t_journal); +} + +static inline void journal_abort_handle(handle_t *handle) +{ + handle->h_aborted = 1; +} + +/* Not all architectures define BUG() */ +#ifndef BUG +#define BUG() do { \ + printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ + * ((char *) 0) = 0; \ + } while (0) +#endif /* BUG */ + +#else + +extern int journal_recover (journal_t *journal); +extern int journal_skip_recovery (journal_t *); + +/* Primary revoke support */ +extern int journal_init_revoke(journal_t *, int); +extern void journal_destroy_revoke_caches(void); +extern int journal_init_revoke_caches(void); + +/* Recovery revoke support */ +extern int journal_set_revoke(journal_t *, unsigned long, tid_t); +extern int journal_test_revoke(journal_t *, unsigned long, tid_t); +extern void journal_clear_revoke(journal_t *); +extern void journal_brelse_array(struct buffer_head *b[], int n); + +extern void journal_destroy_revoke(journal_t *); +#endif /* __KERNEL__ */ + +static inline int tid_gt(tid_t x, tid_t y) EXT2FS_ATTR((unused)); +static inline int tid_geq(tid_t x, tid_t y) EXT2FS_ATTR((unused)); + +/* Comparison functions for transaction IDs: perform comparisons using + * modulo arithmetic so that they work over sequence number wraps. */ + +static inline int tid_gt(tid_t x, tid_t y) +{ + int difference = (x - y); + return (difference > 0); +} + +static inline int tid_geq(tid_t x, tid_t y) +{ + int difference = (x - y); + return (difference >= 0); +} + +extern int journal_blocks_per_page(struct inode *inode); + +/* + * Definitions which augment the buffer_head layer + */ + +/* journaling buffer types */ +#define BJ_None 0 /* Not journaled */ +#define BJ_SyncData 1 /* Normal data: flush before commit */ +#define BJ_AsyncData 2 /* writepage data: wait on it before commit */ +#define BJ_Metadata 3 /* Normal journaled metadata */ +#define BJ_Forget 4 /* Buffer superceded by this transaction */ +#define BJ_IO 5 /* Buffer is for temporary IO use */ +#define BJ_Shadow 6 /* Buffer contents being shadowed to the log */ +#define BJ_LogCtl 7 /* Buffer contains log descriptors */ +#define BJ_Reserved 8 /* Buffer is reserved for access by journal */ +#define BJ_Types 9 + +extern int jbd_blocks_per_page(struct inode *inode); + +#ifdef __KERNEL__ + +extern spinlock_t jh_splice_lock; +/* + * Once `expr1' has been found true, take jh_splice_lock + * and then reevaluate everything. + */ +#define SPLICE_LOCK(expr1, expr2) \ + ({ \ + int ret = (expr1); \ + if (ret) { \ + spin_lock(&jh_splice_lock); \ + ret = (expr1) && (expr2); \ + spin_unlock(&jh_splice_lock); \ + } \ + ret; \ + }) + +/* + * A number of buffer state predicates. They test for + * buffer_jbd() because they are used in core kernel code. + * + * These will be racy on SMP unless we're *sure* that the + * buffer won't be detached from the journalling system + * in parallel. + */ + +/* Return true if the buffer is on journal list `list' */ +static inline int buffer_jlist_eq(struct buffer_head *bh, int list) +{ + return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list); +} + +/* Return true if this bufer is dirty wrt the journal */ +static inline int buffer_jdirty(struct buffer_head *bh) +{ + return buffer_jbd(bh) && __buffer_state(bh, JBDDirty); +} + +/* Return true if it's a data buffer which journalling is managing */ +static inline int buffer_jbd_data(struct buffer_head *bh) +{ + return SPLICE_LOCK(buffer_jbd(bh), + bh2jh(bh)->b_jlist == BJ_SyncData || + bh2jh(bh)->b_jlist == BJ_AsyncData); +} + +#ifdef CONFIG_SMP +#define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock)) +#else +#define assert_spin_locked(lock) do {} while(0) +#endif + +#define buffer_trace_init(bh) do {} while (0) +#define print_buffer_fields(bh) do {} while (0) +#define print_buffer_trace(bh) do {} while (0) +#define BUFFER_TRACE(bh, info) do {} while (0) +#define BUFFER_TRACE2(bh, bh2, info) do {} while (0) +#define JBUFFER_TRACE(jh, info) do {} while (0) + +#endif /* __KERNEL__ */ + +#endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */ + +/* + * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD + * go here. + */ + +#if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE)) + +#define J_ASSERT(expr) do {} while (0) +#define J_ASSERT_BH(bh, expr) do {} while (0) +#define buffer_jbd(bh) 0 +#define buffer_jlist_eq(bh, val) 0 +#define journal_buffer_journal_lru(bh) 0 + +#endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */ +#endif /* _LINUX_JBD_H */ diff --git a/libcustomext2fs/source/kernel-list.h b/libcustomext2fs/source/kernel-list.h new file mode 100644 index 00000000..e07d06b6 --- /dev/null +++ b/libcustomext2fs/source/kernel-list.h @@ -0,0 +1,112 @@ +#ifndef _LINUX_LIST_H +#define _LINUX_LIST_H + +/* + * Simple doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ + +struct list_head { + struct list_head *next, *prev; +}; + +#define LIST_HEAD_INIT(name) { &(name), &(name) } + +#define LIST_HEAD(name) \ + struct list_head name = { &name, &name } + +#define INIT_LIST_HEAD(ptr) do { \ + (ptr)->next = (ptr); (ptr)->prev = (ptr); \ +} while (0) + +#if (!defined(__GNUC__) && !defined(__WATCOMC__)) +#define __inline__ +#endif + +/* + * Insert a new entry between two known consecutive entries. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static __inline__ void __list_add(struct list_head * new, + struct list_head * prev, + struct list_head * next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +/* + * Insert a new entry after the specified head.. + */ +static __inline__ void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + +/* + * Insert a new entry at the tail + */ +static __inline__ void list_add_tail(struct list_head *new, struct list_head *head) +{ + __list_add(new, head->prev, head); +} + +/* + * Delete a list entry by making the prev/next entries + * point to each other. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! + */ +static __inline__ void __list_del(struct list_head * prev, + struct list_head * next) +{ + next->prev = prev; + prev->next = next; +} + +static __inline__ void list_del(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); +} + +static __inline__ int list_empty(struct list_head *head) +{ + return head->next == head; +} + +/* + * Splice in "list" into "head" + */ +static __inline__ void list_splice(struct list_head *list, struct list_head *head) +{ + struct list_head *first = list->next; + + if (first != list) { + struct list_head *last = list->prev; + struct list_head *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; + } +} + +#define list_entry(ptr, type, member) \ + ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + +#define list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +#endif diff --git a/libcustomext2fs/source/link.c b/libcustomext2fs/source/link.c new file mode 100644 index 00000000..4cc8426a --- /dev/null +++ b/libcustomext2fs/source/link.c @@ -0,0 +1,153 @@ +/* + * link.c --- create links in a ext2fs directory + * + * Copyright (C) 1993, 1994 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct link_struct { + ext2_filsys fs; + const char *name; + int namelen; + ext2_ino_t inode; + int flags; + int done; + unsigned int blocksize; + errcode_t err; + struct ext2_super_block *sb; +}; + +static int link_proc(struct ext2_dir_entry *dirent, + int offset, + int blocksize, + char *buf, + void *priv_data) +{ + struct link_struct *ls = (struct link_struct *) priv_data; + struct ext2_dir_entry *next; + unsigned int rec_len, min_rec_len, curr_rec_len; + int ret = 0; + + rec_len = EXT2_DIR_REC_LEN(ls->namelen); + + ls->err = ext2fs_get_rec_len(ls->fs, dirent, &curr_rec_len); + if (ls->err) + return DIRENT_ABORT; + + /* + * See if the following directory entry (if any) is unused; + * if so, absorb it into this one. + */ + next = (struct ext2_dir_entry *) (buf + offset + curr_rec_len); + if ((offset + curr_rec_len < blocksize - 8) && + (next->inode == 0) && + (offset + curr_rec_len + next->rec_len <= blocksize)) { + curr_rec_len += next->rec_len; + ls->err = ext2fs_set_rec_len(ls->fs, curr_rec_len, dirent); + if (ls->err) + return DIRENT_ABORT; + ret = DIRENT_CHANGED; + } + + /* + * If the directory entry is used, see if we can split the + * directory entry to make room for the new name. If so, + * truncate it and return. + */ + if (dirent->inode) { + min_rec_len = EXT2_DIR_REC_LEN(dirent->name_len & 0xFF); + if (curr_rec_len < (min_rec_len + rec_len)) + return ret; + rec_len = curr_rec_len - min_rec_len; + ls->err = ext2fs_set_rec_len(ls->fs, min_rec_len, dirent); + if (ls->err) + return DIRENT_ABORT; + next = (struct ext2_dir_entry *) (buf + offset + + dirent->rec_len); + next->inode = 0; + next->name_len = 0; + ls->err = ext2fs_set_rec_len(ls->fs, rec_len, next); + if (ls->err) + return DIRENT_ABORT; + return DIRENT_CHANGED; + } + + /* + * If we get this far, then the directory entry is not used. + * See if we can fit the request entry in. If so, do it. + */ + if (curr_rec_len < rec_len) + return ret; + dirent->inode = ls->inode; + dirent->name_len = ls->namelen; + strncpy(dirent->name, ls->name, ls->namelen); + if (ls->sb->s_feature_incompat & EXT2_FEATURE_INCOMPAT_FILETYPE) + dirent->name_len |= (ls->flags & 0x7) << 8; + + ls->done++; + return DIRENT_ABORT|DIRENT_CHANGED; +} + +/* + * Note: the low 3 bits of the flags field are used as the directory + * entry filetype. + */ +#ifdef __TURBOC__ + #pragma argsused +#endif +errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name, + ext2_ino_t ino, int flags) +{ + errcode_t retval; + struct link_struct ls; + struct ext2_inode inode; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + ls.fs = fs; + ls.name = name; + ls.namelen = name ? strlen(name) : 0; + ls.inode = ino; + ls.flags = flags; + ls.done = 0; + ls.sb = fs->super; + ls.blocksize = fs->blocksize; + ls.err = 0; + + retval = ext2fs_dir_iterate(fs, dir, DIRENT_FLAG_INCLUDE_EMPTY, + 0, link_proc, &ls); + if (retval) + return retval; + if (ls.err) + return ls.err; + + if (!ls.done) + return EXT2_ET_DIR_NO_SPACE; + + if ((retval = ext2fs_read_inode(fs, dir, &inode)) != 0) + return retval; + + if (inode.i_flags & EXT2_INDEX_FL) { + inode.i_flags &= ~EXT2_INDEX_FL; + if ((retval = ext2fs_write_inode(fs, dir, &inode)) != 0) + return retval; + } + + return 0; +} diff --git a/libcustomext2fs/source/llseek.c b/libcustomext2fs/source/llseek.c new file mode 100644 index 00000000..3b919bef --- /dev/null +++ b/libcustomext2fs/source/llseek.c @@ -0,0 +1,139 @@ +/* + * llseek.c -- stub calling the llseek system call + * + * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE + +#if HAVE_SYS_TYPES_H +#include +#endif + +#if HAVE_ERRNO_H +#include +#endif +#if HAVE_UNISTD_H +#include +#endif +#ifdef __MSDOS__ +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifdef __linux__ + +#if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) + +#define my_llseek lseek64 + +#else +#if defined(HAVE_LLSEEK) +#include + +#ifndef HAVE_LLSEEK_PROTOTYPE +extern long long llseek (int fd, long long offset, int origin); +#endif + +#define my_llseek llseek + +#else /* ! HAVE_LLSEEK */ + +#if SIZEOF_LONG == SIZEOF_LONG_LONG + +#define llseek lseek + +#else /* SIZEOF_LONG != SIZEOF_LONG_LONG */ + +#include + +#ifndef __NR__llseek +#define __NR__llseek 140 +#endif + +#ifndef __i386__ +static int _llseek (unsigned int, unsigned long, + unsigned long, ext2_loff_t *, unsigned int); + +static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high, + unsigned long, offset_low,ext2_loff_t *,result, + unsigned int, origin) +#endif + +static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin) +{ + ext2_loff_t result; + int retval; + +#ifndef __i386__ + retval = _llseek(fd, ((unsigned long long) offset) >> 32, +#else + retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32), +#endif + ((unsigned long long) offset) & 0xffffffff, + &result, origin); + return (retval == -1 ? (ext2_loff_t) retval : result); +} + +#endif /* __alpha__ || __ia64__ */ + +#endif /* HAVE_LLSEEK */ +#endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */ + +ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) +{ + ext2_loff_t result; + static int do_compat = 0; + + if ((sizeof(off_t) >= sizeof(ext2_loff_t)) || + (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) + return lseek(fd, (off_t) offset, origin); + + if (do_compat) { + errno = EINVAL; + return -1; + } + + result = my_llseek (fd, offset, origin); + if (result == -1 && errno == ENOSYS) { + /* + * Just in case this code runs on top of an old kernel + * which does not support the llseek system call + */ + do_compat++; + errno = EINVAL; + } + return result; +} + +#else /* !linux */ + +#ifndef EINVAL +#define EINVAL EXT2_ET_INVALID_ARGUMENT +#endif + +ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) +{ +#if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) + return lseek64 (fd, offset, origin); +#else + if ((sizeof(off_t) < sizeof(ext2_loff_t)) && + (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) { + errno = EINVAL; + return -1; + } + return lseek (fd, (off_t) offset, origin); +#endif +} + +#endif /* linux */ + + diff --git a/libcustomext2fs/source/lookup.c b/libcustomext2fs/source/lookup.c new file mode 100644 index 00000000..97aa0887 --- /dev/null +++ b/libcustomext2fs/source/lookup.c @@ -0,0 +1,69 @@ +/* + * lookup.c --- ext2fs directory lookup operations + * + * Copyright (C) 1993, 1994, 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct lookup_struct { + const char *name; + int len; + ext2_ino_t *inode; + int found; +}; + +#ifdef __TURBOC__ + #pragma argsused +#endif +static int lookup_proc(struct ext2_dir_entry *dirent, + int offset EXT2FS_ATTR((unused)), + int blocksize EXT2FS_ATTR((unused)), + char *buf EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct lookup_struct *ls = (struct lookup_struct *) priv_data; + + if (ls->len != (dirent->name_len & 0xFF)) + return 0; + if (strncmp(ls->name, dirent->name, (dirent->name_len & 0xFF))) + return 0; + *ls->inode = dirent->inode; + ls->found++; + return DIRENT_ABORT; +} + + +errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name, + int namelen, char *buf, ext2_ino_t *inode) +{ + errcode_t retval; + struct lookup_struct ls; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + ls.name = name; + ls.len = namelen; + ls.inode = inode; + ls.found = 0; + + retval = ext2fs_dir_iterate(fs, dir, 0, buf, lookup_proc, &ls); + if (retval) + return retval; + + return (ls.found) ? 0 : EXT2_ET_FILE_NOT_FOUND; +} + + diff --git a/source/memory/mem2.h b/libcustomext2fs/source/mem2.h similarity index 100% rename from source/memory/mem2.h rename to libcustomext2fs/source/mem2.h diff --git a/libcustomext2fs/source/mem_allocate.h b/libcustomext2fs/source/mem_allocate.h new file mode 100644 index 00000000..0d1132eb --- /dev/null +++ b/libcustomext2fs/source/mem_allocate.h @@ -0,0 +1,23 @@ +#ifndef _MEM_ALLOCATE_H +#define _MEM_ALLOCATE_H + +#include +#include "mem2.h" + +extern __inline__ void* mem_alloc (size_t size) { + return MEM2_alloc(size); +} + +extern __inline__ void* mem_realloc (void *p, size_t size) { + return MEM2_realloc(p, size); +} + +extern __inline__ void* mem_align (size_t a, size_t size) { + return MEM2_alloc(size); +} + +extern __inline__ void mem_free (void* mem) { + MEM2_free(mem); +} + +#endif /* _MEM_ALLOCATE_H */ diff --git a/libcustomext2fs/source/mkdir.c b/libcustomext2fs/source/mkdir.c new file mode 100644 index 00000000..86c65da9 --- /dev/null +++ b/libcustomext2fs/source/mkdir.c @@ -0,0 +1,142 @@ +/* + * mkdir.c --- make a directory in the filesystem + * + * Copyright (C) 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifndef EXT2_FT_DIR +#define EXT2_FT_DIR 2 +#endif + +errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, + const char *name) +{ + errcode_t retval; + struct ext2_inode parent_inode, inode; + ext2_ino_t ino = inum; + ext2_ino_t scratch_ino; + blk64_t blk; + char *block = 0; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + /* + * Allocate an inode, if necessary + */ + if (!ino) { + retval = ext2fs_new_inode(fs, parent, LINUX_S_IFDIR | 0755, + 0, &ino); + if (retval) + goto cleanup; + } + + /* + * Allocate a data block for the directory + */ + retval = ext2fs_new_block2(fs, 0, 0, &blk); + if (retval) + goto cleanup; + + /* + * Create a scratch template for the directory + */ + retval = ext2fs_new_dir_block(fs, ino, parent, &block); + if (retval) + goto cleanup; + + /* + * Get the parent's inode, if necessary + */ + if (parent != ino) { + retval = ext2fs_read_inode(fs, parent, &parent_inode); + if (retval) + goto cleanup; + } else + memset(&parent_inode, 0, sizeof(parent_inode)); + + /* + * Create the inode structure.... + */ + memset(&inode, 0, sizeof(struct ext2_inode)); + inode.i_mode = LINUX_S_IFDIR | (0777 & ~fs->umask); + inode.i_uid = inode.i_gid = 0; + ext2fs_iblk_set(fs, &inode, 1); + /* FIXME-64 */ + inode.i_block[0] = blk; + inode.i_links_count = 2; + inode.i_size = fs->blocksize; + + /* + * Write out the inode and inode data block + */ + retval = ext2fs_write_dir_block(fs, blk, block); + if (retval) + goto cleanup; + retval = ext2fs_write_new_inode(fs, ino, &inode); + if (retval) + goto cleanup; + + /* + * Link the directory into the filesystem hierarchy + */ + if (name) { + retval = ext2fs_lookup(fs, parent, name, strlen(name), 0, + &scratch_ino); + if (!retval) { + retval = EXT2_ET_DIR_EXISTS; + name = 0; + goto cleanup; + } + if (retval != EXT2_ET_FILE_NOT_FOUND) + goto cleanup; + retval = ext2fs_link(fs, parent, name, ino, EXT2_FT_DIR); + if (retval) + goto cleanup; + } + + /* + * Update parent inode's counts + */ + if (parent != ino) { + parent_inode.i_links_count++; + retval = ext2fs_write_inode(fs, parent, &parent_inode); + if (retval) + goto cleanup; + } + + /* + * Update accounting.... + */ + ext2fs_block_alloc_stats2(fs, blk, +1); + ext2fs_inode_alloc_stats2(fs, ino, +1, 1); + +cleanup: + if (block) + ext2fs_free_mem(&block); + return retval; + +} + + diff --git a/libcustomext2fs/source/mkjournal.c b/libcustomext2fs/source/mkjournal.c new file mode 100644 index 00000000..ce207ba3 --- /dev/null +++ b/libcustomext2fs/source/mkjournal.c @@ -0,0 +1,601 @@ +/* + * mkjournal.c --- make a journal for a filesystem + * + * Copyright (C) 2000 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_ERRNO_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_SYS_IOCTL_H +#include +#endif +#if HAVE_NETINET_IN_H +#include +#endif +#ifdef GEKKO +#include +#endif + +#include "ext2_fs.h" +#include "e2p/e2p.h" +#include "ext2fs.h" +#include "jfs_user.h" + +/* + * This function automatically sets up the journal superblock and + * returns it as an allocated block. + */ +errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, + __u32 size, int flags, + char **ret_jsb) +{ + errcode_t retval; + journal_superblock_t *jsb; + + if (size < 1024) + return EXT2_ET_JOURNAL_TOO_SMALL; + + if ((retval = ext2fs_get_mem(fs->blocksize, &jsb))) + return retval; + + memset (jsb, 0, fs->blocksize); + + jsb->s_header.h_magic = htonl(JFS_MAGIC_NUMBER); + if (flags & EXT2_MKJOURNAL_V1_SUPER) + jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V1); + else + jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2); + jsb->s_blocksize = htonl(fs->blocksize); + jsb->s_maxlen = htonl(size); + jsb->s_nr_users = htonl(1); + jsb->s_first = htonl(1); + jsb->s_sequence = htonl(1); + memcpy(jsb->s_uuid, fs->super->s_uuid, sizeof(fs->super->s_uuid)); + /* + * If we're creating an external journal device, we need to + * adjust these fields. + */ + if (fs->super->s_feature_incompat & + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { + jsb->s_nr_users = 0; + if (fs->blocksize == 1024) + jsb->s_first = htonl(3); + else + jsb->s_first = htonl(2); + } + + *ret_jsb = (char *) jsb; + return 0; +} + +/* + * This function writes a journal using POSIX routines. It is used + * for creating external journals and creating journals on live + * filesystems. + */ +static errcode_t write_journal_file(ext2_filsys fs, char *filename, + blk_t size, int flags) +{ + errcode_t retval; + char *buf = 0; + int fd, ret_size; + blk_t i; + + if ((retval = ext2fs_create_journal_superblock(fs, size, flags, &buf))) + return retval; + + /* Open the device or journal file */ + if ((fd = open(filename, O_WRONLY)) < 0) { + retval = errno; + goto errout; + } + + /* Write the superblock out */ + retval = EXT2_ET_SHORT_WRITE; + ret_size = write(fd, buf, fs->blocksize); + if (ret_size < 0) { + retval = errno; + goto errout; + } + if (ret_size != (int) fs->blocksize) + goto errout; + memset(buf, 0, fs->blocksize); + + for (i = 1; i < size; i++) { + ret_size = write(fd, buf, fs->blocksize); + if (ret_size < 0) { + retval = errno; + goto errout; + } + if (ret_size != (int) fs->blocksize) + goto errout; + } + close(fd); + + retval = 0; +errout: + ext2fs_free_mem(&buf); + return retval; +} + +/* + * Convenience function which zeros out _num_ blocks starting at + * _blk_. In case of an error, the details of the error is returned + * via _ret_blk_ and _ret_count_ if they are non-NULL pointers. + * Returns 0 on success, and an error code on an error. + * + * As a special case, if the first argument is NULL, then it will + * attempt to free the static zeroizing buffer. (This is to keep + * programs that check for memory leaks happy.) + */ +#define STRIDE_LENGTH 8 +errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num, + blk64_t *ret_blk, int *ret_count) +{ + int j, count; + static char *buf; + errcode_t retval; + + /* If fs is null, clean up the static buffer and return */ + if (!fs) { + if (buf) { + free(buf); + buf = 0; + } + return 0; + } + /* Allocate the zeroizing buffer if necessary */ + if (!buf) { + buf = malloc(fs->blocksize * STRIDE_LENGTH); + if (!buf) + return ENOMEM; + memset(buf, 0, fs->blocksize * STRIDE_LENGTH); + } + /* OK, do the write loop */ + j=0; + while (j < num) { + if (blk % STRIDE_LENGTH) { + count = STRIDE_LENGTH - (blk % STRIDE_LENGTH); + if (count > (num - j)) + count = num - j; + } else { + count = num - j; + if (count > STRIDE_LENGTH) + count = STRIDE_LENGTH; + } + retval = io_channel_write_blk64(fs->io, blk, count, buf); + if (retval) { + if (ret_count) + *ret_count = count; + if (ret_blk) + *ret_blk = blk; + return retval; + } + j += count; blk += count; + } + return 0; +} + +errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num, + blk_t *ret_blk, int *ret_count) +{ + blk64_t ret_blk2; + errcode_t retval; + + retval = ext2fs_zero_blocks2(fs, blk, num, &ret_blk2, ret_count); + if (retval) + *ret_blk = (blk_t) ret_blk2; + return retval; +} + +/* + * Helper function for creating the journal using direct I/O routines + */ +struct mkjournal_struct { + int num_blocks; + int newblocks; + blk64_t goal; + blk64_t blk_to_zero; + int zero_count; + char *buf; + errcode_t err; +}; + +static int mkjournal_proc(ext2_filsys fs, + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct mkjournal_struct *es = (struct mkjournal_struct *) priv_data; + blk64_t new_blk; + errcode_t retval; + + if (*blocknr) { + es->goal = *blocknr; + return 0; + } + retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + if (blockcnt >= 0) + es->num_blocks--; + + es->newblocks++; + retval = 0; + if (blockcnt <= 0) + retval = io_channel_write_blk64(fs->io, new_blk, 1, es->buf); + else { + if (es->zero_count) { + if ((es->blk_to_zero + es->zero_count == new_blk) && + (es->zero_count < 1024)) + es->zero_count++; + else { + retval = ext2fs_zero_blocks2(fs, + es->blk_to_zero, + es->zero_count, + 0, 0); + es->zero_count = 0; + } + } + if (es->zero_count == 0) { + es->blk_to_zero = new_blk; + es->zero_count = 1; + } + } + + if (blockcnt == 0) + memset(es->buf, 0, fs->blocksize); + + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + *blocknr = es->goal = new_blk; + ext2fs_block_alloc_stats2(fs, new_blk, +1); + + if (es->num_blocks == 0) + return (BLOCK_CHANGED | BLOCK_ABORT); + else + return BLOCK_CHANGED; + +} + +/* + * This function creates a journal using direct I/O routines. + */ +static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, + blk64_t size, int flags) +{ + char *buf; + dgrp_t group, start, end, i, log_flex; + errcode_t retval; + struct ext2_inode inode; + struct mkjournal_struct es; + + if ((retval = ext2fs_create_journal_superblock(fs, size, flags, &buf))) + return retval; + + if ((retval = ext2fs_read_bitmaps(fs))) + return retval; + + if ((retval = ext2fs_read_inode(fs, journal_ino, &inode))) + return retval; + + if (inode.i_blocks > 0) + return EEXIST; + + es.num_blocks = size; + es.newblocks = 0; + es.buf = buf; + es.err = 0; + es.zero_count = 0; + + if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) { + inode.i_flags |= EXT4_EXTENTS_FL; + if ((retval = ext2fs_write_inode(fs, journal_ino, &inode))) + return retval; + } + + /* + * Set the initial goal block to be roughly at the middle of + * the filesystem. Pick a group that has the largest number + * of free blocks. + */ + group = ext2fs_group_of_blk2(fs, (ext2fs_blocks_count(fs->super) - + fs->super->s_first_data_block) / 2); + log_flex = 1 << fs->super->s_log_groups_per_flex; + if (fs->super->s_log_groups_per_flex && (group > log_flex)) { + group = group & ~(log_flex - 1); + while ((group < fs->group_desc_count) && + ext2fs_bg_free_blocks_count(fs, group) == 0) + group++; + if (group == fs->group_desc_count) + group = 0; + start = group; + } else + start = (group > 0) ? group-1 : group; + end = ((group+1) < fs->group_desc_count) ? group+1 : group; + group = start; + for (i=start+1; i <= end; i++) + if (ext2fs_bg_free_blocks_count(fs, i) > + ext2fs_bg_free_blocks_count(fs, group)) + group = i; + + es.goal = (fs->super->s_blocks_per_group * group) + + fs->super->s_first_data_block; + + retval = ext2fs_block_iterate3(fs, journal_ino, BLOCK_FLAG_APPEND, + 0, mkjournal_proc, &es); + if (es.err) { + retval = es.err; + goto errout; + } + if (es.zero_count) { + retval = ext2fs_zero_blocks2(fs, es.blk_to_zero, + es.zero_count, 0, 0); + if (retval) + goto errout; + } + + if ((retval = ext2fs_read_inode(fs, journal_ino, &inode))) + goto errout; + + inode.i_size += fs->blocksize * size; + ext2fs_iblk_add_blocks(fs, &inode, es.newblocks); + inode.i_mtime = inode.i_ctime = fs->now ? fs->now : time(0); + inode.i_links_count = 1; + inode.i_mode = LINUX_S_IFREG | 0600; + + if ((retval = ext2fs_write_new_inode(fs, journal_ino, &inode))) + goto errout; + retval = 0; + + memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4); + fs->super->s_jnl_blocks[16] = inode.i_size; + fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS; + ext2fs_mark_super_dirty(fs); + +errout: + ext2fs_free_mem(&buf); + return retval; +} + +/* + * Find a reasonable journal file size (in blocks) given the number of blocks + * in the filesystem. For very small filesystems, it is not reasonable to + * have a journal that fills more than half of the filesystem. + */ +int ext2fs_default_journal_size(__u64 blocks) +{ + if (blocks < 2048) + return -1; + if (blocks < 32768) + return (1024); + if (blocks < 256*1024) + return (4096); + if (blocks < 512*1024) + return (8192); + if (blocks < 1024*1024) + return (16384); + return 32768; +} + +/* + * This function adds a journal device to a filesystem + */ +errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) +{ + struct stat st; + errcode_t retval; + char buf[1024]; + journal_superblock_t *jsb; + int start; + __u32 i, nr_users; + + /* Make sure the device exists and is a block device */ + if (stat(journal_dev->device_name, &st) < 0) + return errno; + + if (!S_ISBLK(st.st_mode)) + return EXT2_ET_JOURNAL_NOT_BLOCK; /* Must be a block device */ + + /* Get the journal superblock */ + start = 1; + if (journal_dev->blocksize == 1024) + start++; + if ((retval = io_channel_read_blk64(journal_dev->io, start, -1024, + buf))) + return retval; + + jsb = (journal_superblock_t *) buf; + if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) || + (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) + return EXT2_ET_NO_JOURNAL_SB; + + if (ntohl(jsb->s_blocksize) != (unsigned long) fs->blocksize) + return EXT2_ET_UNEXPECTED_BLOCK_SIZE; + + /* Check and see if this filesystem has already been added */ + nr_users = ntohl(jsb->s_nr_users); + for (i=0; i < nr_users; i++) { + if (memcmp(fs->super->s_uuid, + &jsb->s_users[i*16], 16) == 0) + break; + } + if (i >= nr_users) { + memcpy(&jsb->s_users[nr_users*16], + fs->super->s_uuid, 16); + jsb->s_nr_users = htonl(nr_users+1); + } + + /* Writeback the journal superblock */ + if ((retval = io_channel_write_blk64(journal_dev->io, start, -1024, buf))) + return retval; + + fs->super->s_journal_inum = 0; + fs->super->s_journal_dev = st.st_rdev; + memcpy(fs->super->s_journal_uuid, jsb->s_uuid, + sizeof(fs->super->s_journal_uuid)); + fs->super->s_feature_compat |= EXT3_FEATURE_COMPAT_HAS_JOURNAL; + ext2fs_mark_super_dirty(fs); + return 0; +} + +/* + * This function adds a journal inode to a filesystem, using either + * POSIX routines if the filesystem is mounted, or using direct I/O + * functions if it is not. + */ +errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags) +{ + errcode_t retval; + ext2_ino_t journal_ino; + struct stat st; + char jfile[1024]; + int mount_flags; + int fd = -1; + + if ((retval = ext2fs_check_mount_point(fs->device_name, &mount_flags, + jfile, sizeof(jfile)-10))) + return retval; + + if (mount_flags & EXT2_MF_MOUNTED) { + strcat(jfile, "/.journal"); + + /* + * If .../.journal already exists, make sure any + * immutable or append-only flags are cleared. + */ +#if defined(HAVE_CHFLAGS) && defined(UF_NODUMP) + (void) chflags (jfile, 0); +#else +#if HAVE_EXT2_IOCTLS + fd = open(jfile, O_RDONLY); + if (fd >= 0) { + f = 0; + ioctl(fd, EXT2_IOC_SETFLAGS, &f); + close(fd); + } +#endif +#endif + + /* Create the journal file */ + if ((fd = open(jfile, O_CREAT|O_WRONLY, 0600)) < 0) + return errno; + + if ((retval = write_journal_file(fs, jfile, size, flags))) + goto errout; + + /* Get inode number of the journal file */ + if (fstat(fd, &st) < 0) { + retval = errno; + goto errout; + } + +#if defined(HAVE_CHFLAGS) && defined(UF_NODUMP) + retval = fchflags (fd, UF_NODUMP|UF_IMMUTABLE); +#else +#if HAVE_EXT2_IOCTLS + if (ioctl(fd, EXT2_IOC_GETFLAGS, &f) < 0) { + retval = errno; + goto errout; + } + f |= EXT2_NODUMP_FL | EXT2_IMMUTABLE_FL; + retval = ioctl(fd, EXT2_IOC_SETFLAGS, &f); +#endif +#endif + if (retval) { + retval = errno; + goto errout; + } + + if (close(fd) < 0) { + retval = errno; + fd = -1; + goto errout; + } + journal_ino = st.st_ino; + } else { + if ((mount_flags & EXT2_MF_BUSY) && + !(fs->flags & EXT2_FLAG_EXCLUSIVE)) { + retval = EBUSY; + goto errout; + } + journal_ino = EXT2_JOURNAL_INO; + if ((retval = write_journal_inode(fs, journal_ino, + size, flags))) + return retval; + } + + fs->super->s_journal_inum = journal_ino; + fs->super->s_journal_dev = 0; + memset(fs->super->s_journal_uuid, 0, + sizeof(fs->super->s_journal_uuid)); + fs->super->s_feature_compat |= EXT3_FEATURE_COMPAT_HAS_JOURNAL; + + ext2fs_mark_super_dirty(fs); + return 0; +errout: + if (fd > 0) + close(fd); + return retval; +} + +#ifdef DEBUG +main(int argc, char **argv) +{ + errcode_t retval; + char *device_name; + ext2_filsys fs; + + if (argc < 2) { + fprintf(stderr, "Usage: %s filesystem\n", argv[0]); + exit(1); + } + device_name = argv[1]; + + retval = ext2fs_open (device_name, EXT2_FLAG_RW, 0, 0, + unix_io_manager, &fs); + if (retval) { + com_err(argv[0], retval, "while opening %s", device_name); + exit(1); + } + + retval = ext2fs_add_journal_inode(fs, 1024); + if (retval) { + com_err(argv[0], retval, "while adding journal to %s", + device_name); + exit(1); + } + retval = ext2fs_flush(fs); + if (retval) { + printf("Warning, had trouble writing out superblocks.\n"); + } + ext2fs_close(fs); + exit(0); + +} +#endif diff --git a/libcustomext2fs/source/namei.c b/libcustomext2fs/source/namei.c new file mode 100644 index 00000000..bc0ae61d --- /dev/null +++ b/libcustomext2fs/source/namei.c @@ -0,0 +1,206 @@ +/* + * namei.c --- ext2fs directory lookup operations + * + * Copyright (C) 1993, 1994, 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +/* #define NAMEI_DEBUG */ + +#include "ext2_fs.h" +#include "ext2fs.h" + +static errcode_t open_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t base, + const char *pathname, size_t pathlen, int follow, + int link_count, char *buf, ext2_ino_t *res_inode); + +static errcode_t follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t dir, + ext2_ino_t inode, int link_count, + char *buf, ext2_ino_t *res_inode) +{ + char *pathname; + char *buffer = 0; + errcode_t retval; + struct ext2_inode ei; + +#ifdef NAMEI_DEBUG + printf("follow_link: root=%lu, dir=%lu, inode=%lu, lc=%d\n", + root, dir, inode, link_count); + +#endif + retval = ext2fs_read_inode (fs, inode, &ei); + if (retval) return retval; + if (!LINUX_S_ISLNK (ei.i_mode)) { + *res_inode = inode; + return 0; + } + if (link_count++ > 5) { + return EXT2_ET_SYMLINK_LOOP; + } + /* FIXME-64: Actually, this is FIXME EXTENTS */ + if (ext2fs_inode_data_blocks(fs,&ei)) { + retval = ext2fs_get_mem(fs->blocksize, &buffer); + if (retval) + return retval; + retval = io_channel_read_blk(fs->io, ei.i_block[0], 1, buffer); + if (retval) { + ext2fs_free_mem(&buffer); + return retval; + } + pathname = buffer; + } else + pathname = (char *)&(ei.i_block[0]); + retval = open_namei(fs, root, dir, pathname, ei.i_size, 1, + link_count, buf, res_inode); + if (buffer) + ext2fs_free_mem(&buffer); + return retval; +} + +/* + * This routine interprets a pathname in the context of the current + * directory and the root directory, and returns the inode of the + * containing directory, and a pointer to the filename of the file + * (pointing into the pathname) and the length of the filename. + */ +static errcode_t dir_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t dir, + const char *pathname, int pathlen, + int link_count, char *buf, + const char **name, int *namelen, + ext2_ino_t *res_inode) +{ + char c; + const char *thisname; + int len; + ext2_ino_t inode; + errcode_t retval; + + if ((c = *pathname) == '/') { + dir = root; + pathname++; + pathlen--; + } + while (1) { + thisname = pathname; + for (len=0; --pathlen >= 0;len++) { + c = *(pathname++); + if (c == '/') + break; + } + if (pathlen < 0) + break; + retval = ext2fs_lookup (fs, dir, thisname, len, buf, &inode); + if (retval) return retval; + retval = follow_link (fs, root, dir, inode, + link_count, buf, &dir); + if (retval) return retval; + } + *name = thisname; + *namelen = len; + *res_inode = dir; + return 0; +} + +static errcode_t open_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t base, + const char *pathname, size_t pathlen, int follow, + int link_count, char *buf, ext2_ino_t *res_inode) +{ + const char *base_name; + int namelen; + ext2_ino_t dir, inode; + errcode_t retval; + +#ifdef NAMEI_DEBUG + printf("open_namei: root=%lu, dir=%lu, path=%*s, lc=%d\n", + root, base, pathlen, pathname, link_count); +#endif + retval = dir_namei(fs, root, base, pathname, pathlen, + link_count, buf, &base_name, &namelen, &dir); + if (retval) return retval; + if (!namelen) { /* special case: '/usr/' etc */ + *res_inode=dir; + return 0; + } + retval = ext2fs_lookup (fs, dir, base_name, namelen, buf, &inode); + if (retval) + return retval; + if (follow) { + retval = follow_link(fs, root, dir, inode, link_count, + buf, &inode); + if (retval) + return retval; + } +#ifdef NAMEI_DEBUG + printf("open_namei: (link_count=%d) returns %lu\n", + link_count, inode); +#endif + *res_inode = inode; + return 0; +} + +errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, + const char *name, ext2_ino_t *inode) +{ + char *buf; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + + retval = open_namei(fs, root, cwd, name, strlen(name), 0, 0, + buf, inode); + + ext2fs_free_mem(&buf); + return retval; +} + +errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, + const char *name, ext2_ino_t *inode) +{ + char *buf; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + + retval = open_namei(fs, root, cwd, name, strlen(name), 1, 0, + buf, inode); + + ext2fs_free_mem(&buf); + return retval; +} + +errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd, + ext2_ino_t inode, ext2_ino_t *res_inode) +{ + char *buf; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + + retval = follow_link(fs, root, cwd, inode, 0, buf, res_inode); + + ext2fs_free_mem(&buf); + return retval; +} + diff --git a/libcustomext2fs/source/native.c b/libcustomext2fs/source/native.c new file mode 100644 index 00000000..c71a95ee --- /dev/null +++ b/libcustomext2fs/source/native.c @@ -0,0 +1,27 @@ +/* + * native.c --- returns the ext2_flag for a native byte order + * + * Copyright (C) 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +int ext2fs_native_flag(void) +{ +#ifdef WORDS_BIGENDIAN + return EXT2_FLAG_SWAP_BYTES; +#else + return 0; +#endif +} + + + diff --git a/libcustomext2fs/source/newdir.c b/libcustomext2fs/source/newdir.c new file mode 100644 index 00000000..6bc57194 --- /dev/null +++ b/libcustomext2fs/source/newdir.c @@ -0,0 +1,77 @@ +/* + * newdir.c --- create a new directory block + * + * Copyright (C) 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +#ifndef EXT2_FT_DIR +#define EXT2_FT_DIR 2 +#endif + +/* + * Create new directory block + */ +errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino, + ext2_ino_t parent_ino, char **block) +{ + struct ext2_dir_entry *dir = NULL; + errcode_t retval; + char *buf; + int rec_len; + int filetype = 0; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + retval = ext2fs_get_mem(fs->blocksize, &buf); + if (retval) + return retval; + memset(buf, 0, fs->blocksize); + dir = (struct ext2_dir_entry *) buf; + + retval = ext2fs_set_rec_len(fs, fs->blocksize, dir); + if (retval) + return retval; + + if (dir_ino) { + if (fs->super->s_feature_incompat & + EXT2_FEATURE_INCOMPAT_FILETYPE) + filetype = EXT2_FT_DIR << 8; + /* + * Set up entry for '.' + */ + dir->inode = dir_ino; + dir->name_len = 1 | filetype; + dir->name[0] = '.'; + rec_len = fs->blocksize - EXT2_DIR_REC_LEN(1); + dir->rec_len = EXT2_DIR_REC_LEN(1); + + /* + * Set up entry for '..' + */ + dir = (struct ext2_dir_entry *) (buf + dir->rec_len); + retval = ext2fs_set_rec_len(fs, rec_len, dir); + if (retval) + return retval; + dir->inode = parent_ino; + dir->name_len = 2 | filetype; + dir->name[0] = '.'; + dir->name[1] = '.'; + + } + *block = buf; + return 0; +} diff --git a/libcustomext2fs/source/openfs.c b/libcustomext2fs/source/openfs.c new file mode 100644 index 00000000..a73164d5 --- /dev/null +++ b/libcustomext2fs/source/openfs.c @@ -0,0 +1,411 @@ +/* + * openfs.c --- open an ext2 filesystem + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" + + +#include "ext2fs.h" +#include "e2image.h" + +blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block, + dgrp_t i) +{ + int bg; + int has_super = 0; + blk64_t ret_blk; + + if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) || + (i < fs->super->s_first_meta_bg)) + return (group_block + i + 1); + + bg = EXT2_DESC_PER_BLOCK(fs->super) * i; + if (ext2fs_bg_has_super(fs, bg)) + has_super = 1; + ret_blk = ext2fs_group_first_block2(fs, bg) + has_super; + /* + * If group_block is not the normal value, we're trying to use + * the backup group descriptors and superblock --- so use the + * alternate location of the second block group in the + * metablock group. Ideally we should be testing each bg + * descriptor block individually for correctness, but we don't + * have the infrastructure in place to do that. + */ + if (group_block != fs->super->s_first_data_block && + ((ret_blk + fs->super->s_blocks_per_group) < + ext2fs_blocks_count(fs->super))) + ret_blk += fs->super->s_blocks_per_group; + return ret_blk; +} + +blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i) +{ + return ext2fs_descriptor_block_loc2(fs, group_block, i); +} + +errcode_t ext2fs_open(const char *name, int flags, int superblock, + unsigned int block_size, io_channel * io, + ext2_filsys *ret_fs) +{ + return ext2fs_open2(name, 0, flags, superblock, block_size, + io, ret_fs); +} + +/* + * Note: if superblock is non-zero, block-size must also be non-zero. + * Superblock and block_size can be zero to use the default size. + * + * Valid flags for ext2fs_open() + * + * EXT2_FLAG_RW - Open the filesystem for read/write. + * EXT2_FLAG_FORCE - Open the filesystem even if some of the + * features aren't supported. + * EXT2_FLAG_JOURNAL_DEV_OK - Open an ext3 journal device + */ +errcode_t ext2fs_open2(const char *name, const char *io_options, + int flags, int superblock, + unsigned int block_size, io_channel * io, + ext2_filsys *ret_fs) +{ + ext2_filsys fs; + io_manager manager = (*io)->manager; + errcode_t retval; + unsigned long i, first_meta_bg; + __u32 features; + int groups_per_block, blocks_per_group, io_flags; + blk64_t group_block, blk; + char *dest, *cp; +#ifdef WORDS_BIGENDIAN + struct ext2_group_desc *gdp; + int j; +#endif + + EXT2_CHECK_MAGIC(manager, EXT2_ET_MAGIC_IO_MANAGER); + + retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs); + if (retval) + return retval; + + memset(fs, 0, sizeof(struct struct_ext2_filsys)); + fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS; + fs->io = *io; + fs->flags = flags; + /* don't overwrite sb backups unless flag is explicitly cleared */ + fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; + fs->umask = 022; + retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name); + if (retval) + goto cleanup; + strcpy(fs->device_name, name); + cp = strchr(fs->device_name, '?'); + if (!io_options && cp) { + *cp++ = 0; + io_options = cp; + } + + io_flags = 0; + if (flags & EXT2_FLAG_RW) + io_flags |= IO_FLAG_RW; + if (flags & EXT2_FLAG_EXCLUSIVE) + io_flags |= IO_FLAG_EXCLUSIVE; + if (flags & EXT2_FLAG_DIRECT_IO) + io_flags |= IO_FLAG_DIRECT_IO; + retval = manager->open(fs->device_name, io_flags, &fs->io); + if (retval) + goto cleanup; + if (io_options && + (retval = io_channel_set_options(fs->io, io_options))) + goto cleanup; + fs->image_io = fs->io; + fs->io->app_data = fs; + retval = ext2fs_get_memalign(SUPERBLOCK_SIZE, 512, &fs->super); + if (retval) + goto cleanup; + if (flags & EXT2_FLAG_IMAGE_FILE) { + retval = ext2fs_get_mem(sizeof(struct ext2_image_hdr), + &fs->image_header); + if (retval) + goto cleanup; + retval = io_channel_read_blk(fs->io, 0, + -(int)sizeof(struct ext2_image_hdr), + fs->image_header); + if (retval) + goto cleanup; + if (fs->image_header->magic_number != EXT2_ET_MAGIC_E2IMAGE) + return EXT2_ET_MAGIC_E2IMAGE; + superblock = 1; + block_size = fs->image_header->fs_blocksize; + } + + /* + * If the user specifies a specific block # for the + * superblock, then he/she must also specify the block size! + * Otherwise, read the master superblock located at offset + * SUPERBLOCK_OFFSET from the start of the partition. + * + * Note: we only save a backup copy of the superblock if we + * are reading the superblock from the primary superblock location. + */ + if (superblock) { + if (!block_size) { + retval = EXT2_ET_INVALID_ARGUMENT; + goto cleanup; + } + io_channel_set_blksize(fs->io, block_size); + group_block = superblock; + fs->orig_super = 0; + } else { + io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET); + superblock = 1; + group_block = 0; + retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->orig_super); + if (retval) + goto cleanup; + } + retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE, + fs->super); + if (retval) + goto cleanup; + if (fs->orig_super) + memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE); + +#ifdef WORDS_BIGENDIAN + fs->flags |= EXT2_FLAG_SWAP_BYTES; + ext2fs_swap_super(fs->super); +#else + if (fs->flags & EXT2_FLAG_SWAP_BYTES) { + retval = EXT2_ET_UNIMPLEMENTED; + goto cleanup; + } +#endif + + if (fs->super->s_magic != EXT2_SUPER_MAGIC) { + retval = EXT2_ET_BAD_MAGIC; + goto cleanup; + } + if (fs->super->s_rev_level > EXT2_LIB_CURRENT_REV) { + retval = EXT2_ET_REV_TOO_HIGH; + goto cleanup; + } + + /* + * Check for feature set incompatibility + */ + if (!(flags & EXT2_FLAG_FORCE)) { + features = fs->super->s_feature_incompat; +#ifdef EXT2_LIB_SOFTSUPP_INCOMPAT + if (flags & EXT2_FLAG_SOFTSUPP_FEATURES) + features &= !EXT2_LIB_SOFTSUPP_INCOMPAT; +#endif + if (features & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { + retval = EXT2_ET_UNSUPP_FEATURE; + goto cleanup; + } + + features = fs->super->s_feature_ro_compat; +#ifdef EXT2_LIB_SOFTSUPP_RO_COMPAT + if (flags & EXT2_FLAG_SOFTSUPP_FEATURES) + features &= !EXT2_LIB_SOFTSUPP_RO_COMPAT; +#endif + if ((flags & EXT2_FLAG_RW) && + (features & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP)) { + retval = EXT2_ET_RO_UNSUPP_FEATURE; + goto cleanup; + } + + if (!(flags & EXT2_FLAG_JOURNAL_DEV_OK) && + (fs->super->s_feature_incompat & + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { + retval = EXT2_ET_UNSUPP_FEATURE; + goto cleanup; + } + } + + if ((fs->super->s_log_block_size + EXT2_MIN_BLOCK_LOG_SIZE) > + EXT2_MAX_BLOCK_LOG_SIZE) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } + fs->blocksize = EXT2_BLOCK_SIZE(fs->super); + if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } + fs->fragsize = EXT2_FRAG_SIZE(fs->super); + fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) * + EXT2_INODE_SIZE(fs->super) + + EXT2_BLOCK_SIZE(fs->super) - 1) / + EXT2_BLOCK_SIZE(fs->super)); + if (block_size) { + if (block_size != fs->blocksize) { + retval = EXT2_ET_UNEXPECTED_BLOCK_SIZE; + goto cleanup; + } + } + /* + * Set the blocksize to the filesystem's blocksize. + */ + io_channel_set_blksize(fs->io, fs->blocksize); + + /* + * If this is an external journal device, don't try to read + * the group descriptors, because they're not there. + */ + if (fs->super->s_feature_incompat & + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { + fs->group_desc_count = 0; + *ret_fs = fs; + return 0; + } + + if (EXT2_INODES_PER_GROUP(fs->super) == 0) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } + + /* + * Read group descriptors + */ + blocks_per_group = EXT2_BLOCKS_PER_GROUP(fs->super); + if (blocks_per_group == 0 || + blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(fs->super) || + fs->inode_blocks_per_group > EXT2_MAX_INODES_PER_GROUP(fs->super) || + EXT2_DESC_PER_BLOCK(fs->super) == 0 || + fs->super->s_first_data_block >= ext2fs_blocks_count(fs->super)) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } + fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) - + fs->super->s_first_data_block, + blocks_per_group); + if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != + fs->super->s_inodes_count) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } + fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, + EXT2_DESC_PER_BLOCK(fs->super)); + retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, + &fs->group_desc); + if (retval) + goto cleanup; + if (!group_block) + group_block = fs->super->s_first_data_block; + dest = (char *) fs->group_desc; + groups_per_block = EXT2_DESC_PER_BLOCK(fs->super); + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + first_meta_bg = fs->super->s_first_meta_bg; + else + first_meta_bg = fs->desc_blocks; + if (first_meta_bg) { + retval = io_channel_read_blk(fs->io, group_block+1, + first_meta_bg, dest); + if (retval) + goto cleanup; +#ifdef WORDS_BIGENDIAN + gdp = (struct ext2_group_desc *) dest; + for (j=0; j < groups_per_block*first_meta_bg; j++) { + gdp = ext2fs_group_desc(fs, fs->group_desc, j); + ext2fs_swap_group_desc2(fs, gdp); + } +#endif + dest += fs->blocksize*first_meta_bg; + } + for (i=first_meta_bg ; i < fs->desc_blocks; i++) { + blk = ext2fs_descriptor_block_loc2(fs, group_block, i); + retval = io_channel_read_blk64(fs->io, blk, 1, dest); + if (retval) + goto cleanup; +#ifdef WORDS_BIGENDIAN + for (j=0; j < groups_per_block; j++) { + /* The below happens to work... be careful. */ + gdp = ext2fs_group_desc(fs, fs->group_desc, j); + ext2fs_swap_group_desc2(fs, gdp); + } +#endif + dest += fs->blocksize; + } + + fs->stride = fs->super->s_raid_stride; + + /* + * If recovery is from backup superblock, Clear _UNININT flags & + * reset bg_itable_unused to zero + */ + if (superblock > 1 && EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { + dgrp_t group; + + for (group = 0; group < fs->group_desc_count; group++) { + ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); + ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT); + ext2fs_bg_itable_unused_set(fs, group, 0); + } + ext2fs_mark_super_dirty(fs); + } + + fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR; + *ret_fs = fs; + return 0; +cleanup: + if (flags & EXT2_FLAG_NOFREE_ON_ERROR) + *ret_fs = fs; + else + ext2fs_free(fs); + return retval; +} + +/* + * Set/get the filesystem data I/O channel. + * + * These functions are only valid if EXT2_FLAG_IMAGE_FILE is true. + */ +errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io) +{ + if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0) + return EXT2_ET_NOT_IMAGE_FILE; + if (old_io) { + *old_io = (fs->image_io == fs->io) ? 0 : fs->io; + } + return 0; +} + +errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io) +{ + if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0) + return EXT2_ET_NOT_IMAGE_FILE; + fs->io = new_io ? new_io : fs->image_io; + return 0; +} + +errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io) +{ + if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0) + return EXT2_ET_NOT_IMAGE_FILE; + fs->io = fs->image_io = new_io; + fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_RW | + EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY; + fs->flags &= ~EXT2_FLAG_IMAGE_FILE; + return 0; +} diff --git a/libcustomext2fs/source/partitions.h b/libcustomext2fs/source/partitions.h new file mode 100644 index 00000000..9bb1049b --- /dev/null +++ b/libcustomext2fs/source/partitions.h @@ -0,0 +1,49 @@ +#ifndef PARTITIONS_H_ +#define PARTITIONS_H_ + +#include +#include "bitops.h" + +#define MBR_SIGNATURE ext2fs_cpu_to_le16(0xAA55) +#define EBR_SIGNATURE ext2fs_cpu_to_le16(0xAA55) + +#define PARTITION_STATUS_BOOTABLE 0x80 /* Bootable (active) */ + +#define PARTITION_TYPE_EMPTY 0x00 /* Empty */ +#define PARTITION_TYPE_DOS33_EXTENDED 0x05 /* DOS 3.3+ extended partition */ +#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */ +#define PARTITION_TYPE_LINUX 0x83 /* EXT2/3/4 */ + +/** + * PRIMARY_PARTITION - Block device partition record + */ +typedef struct _PARTITION_RECORD { + u8 status; /* Partition status; see above */ + u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */ + u8 type; /* Partition type; see above */ + u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */ + u32 lba_start; /* Local block address to first sector of partition */ + u32 block_count; /* Number of blocks in partition */ +} __attribute__((__packed__)) PARTITION_RECORD; + +/** + * MASTER_BOOT_RECORD - Block device master boot record + */ +typedef struct _MASTER_BOOT_RECORD { + u8 code_area[446]; /* Code area; normally empty */ + PARTITION_RECORD partitions[4]; /* 4 primary partitions */ + u16 signature; /* MBR signature; 0xAA55 */ +} __attribute__((__packed__)) MASTER_BOOT_RECORD; + +/** + * EXTENDED_PARTITION - Block device extended boot record + */ +typedef struct _EXTENDED_BOOT_RECORD { + u8 code_area[446]; /* Code area; normally empty */ + PARTITION_RECORD partition; /* Primary partition */ + PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */ + u8 reserved[32]; /* Normally empty */ + u16 signature; /* EBR signature; 0xAA55 */ +} __attribute__((__packed__)) EXTENDED_BOOT_RECORD; + +#endif diff --git a/libcustomext2fs/source/progress.c b/libcustomext2fs/source/progress.c new file mode 100644 index 00000000..708df959 --- /dev/null +++ b/libcustomext2fs/source/progress.c @@ -0,0 +1,86 @@ +/* + * progress.c - Numeric progress meter + * + * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, + * 2003, 2004, 2005 by Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include "ext2fs.h" +#include "ext2fsP.h" + +static char spaces[80], backspaces[80]; + +static int int_log10(unsigned int arg) +{ + int l; + + for (l=0; arg ; l++) + arg = arg / 10; + return l; +} + +void ext2fs_numeric_progress_init(ext2_filsys fs, + struct ext2fs_numeric_progress_struct * progress, + const char *label, __u64 max) +{ + /* + * The PRINT_PROGRESS flag turns on or off ALL + * progress-related messages, whereas the SKIP_PROGRESS + * environment variable prints the start and end messages but + * not the numeric countdown in the middle. + */ + if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS)) + return; + + memset(spaces, ' ', sizeof(spaces)-1); + spaces[sizeof(spaces)-1] = 0; + memset(backspaces, '\b', sizeof(backspaces)-1); + spaces[sizeof(backspaces)-1] = 0; + progress->skip_progress = 0; + if (getenv("E2FSPROGS_SKIP_PROGRESS")) + progress->skip_progress++; + + memset(progress, 0, sizeof(*progress)); + + /* + * Figure out how many digits we need + */ + progress->max = max; + progress->log_max = int_log10(max); + + if (label) { + fputs(label, stdout); + fflush(stdout); + } +} + +void ext2fs_numeric_progress_update(ext2_filsys fs, + struct ext2fs_numeric_progress_struct * progress, + __u64 val) +{ + if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS)) + return; + if (progress->skip_progress) + return; + + fprintf(stdout, "%*llu/%*llu", progress->log_max, val, + progress->log_max, progress->max); + fprintf(stdout, "%.*s", (2*progress->log_max)+1, backspaces); +} + +void ext2fs_numeric_progress_close(ext2_filsys fs, + struct ext2fs_numeric_progress_struct * progress, + const char *message) +{ + if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS)) + return; + fprintf(stdout, "%.*s", (2*progress->log_max)+1, spaces); + fprintf(stdout, "%.*s", (2*progress->log_max)+1, backspaces); + if (message) + fputs(message, stdout); +} diff --git a/libcustomext2fs/source/punch.c b/libcustomext2fs/source/punch.c new file mode 100644 index 00000000..8c6ec549 --- /dev/null +++ b/libcustomext2fs/source/punch.c @@ -0,0 +1,324 @@ +/* + * punch.c --- deallocate blocks allocated to an inode + * + * Copyright (C) 2010 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +#undef PUNCH_DEBUG + +/* + * This function returns 1 if the specified block is all zeros + */ +static int check_zero_block(char *buf, int blocksize) +{ + char *cp = buf; + int left = blocksize; + + while (left > 0) { + if (*cp++) + return 0; + left--; + } + return 1; +} + +/* + * This clever recursive function handles i_blocks[] as well as + * indirect, double indirect, and triple indirect blocks. It iterates + * over the entries in the i_blocks array or indirect blocks, and for + * each one, will recursively handle any indirect blocks and then + * frees and deallocates the blocks. + */ +static errcode_t ind_punch(ext2_filsys fs, struct ext2_inode *inode, + char *block_buf, blk_t *p, int level, + blk_t start, blk_t count, int max) +{ + errcode_t retval; + blk_t b, offset; + int i, incr; + int freed = 0; + +#ifdef PUNCH_DEBUG + printf("Entering ind_punch, level %d, start %u, count %u, " + "max %d\n", level, start, count, max); +#endif + incr = 1 << ((EXT2_BLOCK_SIZE_BITS(fs->super)-2)*level); + for (i=0, offset=0; i < max; i++, p++, offset += incr) { + if (offset > count) + break; + if (*p == 0 || (offset+incr) <= start) + continue; + b = *p; + if (level > 0) { + blk_t start2; +#ifdef PUNCH_DEBUG + printf("Reading indirect block %u\n", b); +#endif + retval = ext2fs_read_ind_block(fs, b, block_buf); + if (retval) + return retval; + start2 = (start > offset) ? start - offset : 0; + retval = ind_punch(fs, inode, block_buf + fs->blocksize, + (blk_t *) block_buf, level - 1, + start2, count - offset, + fs->blocksize >> 2); + if (retval) + return retval; + retval = ext2fs_write_ind_block(fs, b, block_buf); + if (retval) + return retval; + if (!check_zero_block(block_buf, fs->blocksize)) + continue; + } +#ifdef PUNCH_DEBUG + printf("Freeing block %u (offset %d)\n", b, offset); +#endif + ext2fs_block_alloc_stats(fs, b, -1); + *p = 0; + freed++; + } +#ifdef PUNCH_DEBUG + printf("Freed %d blocks\n", freed); +#endif + return ext2fs_iblk_sub_blocks(fs, inode, freed); +} + +static errcode_t ext2fs_punch_ind(ext2_filsys fs, struct ext2_inode *inode, + char *block_buf, blk_t start, blk_t count) +{ + errcode_t retval; + char *buf = 0; + int level; + int num = EXT2_NDIR_BLOCKS; + blk_t *bp = inode->i_block; + blk_t addr_per_block; + blk_t max = EXT2_NDIR_BLOCKS; + + if (!block_buf) { + retval = ext2fs_get_array(3, fs->blocksize, &buf); + if (retval) + return retval; + block_buf = buf; + } + + addr_per_block = (blk_t) fs->blocksize >> 2; + + for (level=0; level < 4; level++, max *= addr_per_block) { +#ifdef PUNCH_DEBUG + printf("Main loop level %d, start %u count %u " + "max %d num %d\n", level, start, count, max, num); +#endif + if (start < max) { + retval = ind_punch(fs, inode, block_buf, bp, level, + start, count, num); + if (retval) + goto errout; + if (count > max) + count -= max - start; + else + break; + start = 0; + } else + start -= max; + bp += num; + if (level == 0) { + num = 1; + max = 1; + } + } + retval = 0; +errout: + if (buf) + ext2fs_free_mem(&buf); + return retval; +} + +#ifdef PUNCH_DEBUG + +#define dbg_printf(f, a...) printf(f, ## a) + +static void dbg_print_extent(char *desc, struct ext2fs_extent *extent) +{ + if (desc) + printf("%s: ", desc); + printf("extent: lblk %llu--%llu, len %u, pblk %llu, flags: ", + extent->e_lblk, extent->e_lblk + extent->e_len - 1, + extent->e_len, extent->e_pblk); + if (extent->e_flags & EXT2_EXTENT_FLAGS_LEAF) + fputs("LEAF ", stdout); + if (extent->e_flags & EXT2_EXTENT_FLAGS_UNINIT) + fputs("UNINIT ", stdout); + if (extent->e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT) + fputs("2ND_VISIT ", stdout); + if (!extent->e_flags) + fputs("(none)", stdout); + fputc('\n', stdout); + +} +#else +#define dbg_print_extent(desc, ex) do { } while (0) +#define dbg_printf(f, a...) do { } while (0) +#endif + +static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + blk64_t start, blk64_t end) +{ + ext2_extent_handle_t handle = 0; + struct ext2fs_extent extent; + errcode_t retval; + blk64_t free_start, next; + __u32 free_count, newlen; + int freed = 0; + + retval = ext2fs_extent_open2(fs, ino, inode, &handle); + if (retval) + return retval; + ext2fs_extent_goto(handle, start); + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + goto errout; + while (1) { + dbg_print_extent("main loop", &extent); + next = extent.e_lblk + extent.e_len; + dbg_printf("start %llu, end %llu, next %llu\n", + (unsigned long long) start, + (unsigned long long) end, + (unsigned long long) next); + if (start <= extent.e_lblk) { + if (end < extent.e_lblk) + goto next_extent; + dbg_printf("Case #1\n"); + /* Start of deleted region before extent; + adjust beginning of extent */ + free_start = extent.e_pblk; + if (next > end) + free_count = end - extent.e_lblk + 1; + else + free_count = extent.e_len; + extent.e_len -= free_count; + extent.e_lblk += free_count; + extent.e_pblk += free_count; + } else if (end >= next-1) { + if (start >= next) + break; + /* End of deleted region after extent; + adjust end of extent */ + dbg_printf("Case #2\n"); + newlen = start - extent.e_lblk; + free_start = extent.e_pblk + newlen; + free_count = extent.e_len - newlen; + extent.e_len = newlen; + } else { + struct ext2fs_extent newex; + + dbg_printf("Case #3\n"); + /* The hard case; we need to split the extent */ + newex.e_pblk = extent.e_pblk + + (end + 1 - extent.e_lblk); + newex.e_lblk = end + 1; + newex.e_len = next - end - 1; + newex.e_flags = extent.e_flags; + + extent.e_len = start - extent.e_lblk; + free_start = extent.e_pblk + extent.e_len; + free_count = end - start + 1; + + dbg_print_extent("inserting", &newex); + retval = ext2fs_extent_insert(handle, + EXT2_EXTENT_INSERT_AFTER, &newex); + if (retval) + goto errout; + /* Now pointing at inserted extent; so go back */ + retval = ext2fs_extent_get(handle, + EXT2_EXTENT_PREV_LEAF, + &newex); + if (retval) + goto errout; + } + if (extent.e_len) { + dbg_print_extent("replacing", &extent); + retval = ext2fs_extent_replace(handle, 0, &extent); + } else { + dbg_printf("deleting current extent\n"); + retval = ext2fs_extent_delete(handle, 0); + } + if (retval) + goto errout; + dbg_printf("Free start %llu, free count = %u\n", + free_start, free_count); + while (free_count-- > 0) { + ext2fs_block_alloc_stats(fs, free_start++, -1); + freed++; + } + next_extent: + retval = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT_LEAF, + &extent); + if (retval == EXT2_ET_EXTENT_NO_NEXT) + break; + if (retval) + goto errout; + } + dbg_printf("Freed %d blocks\n", freed); + retval = ext2fs_iblk_sub_blocks(fs, inode, freed); +errout: + ext2fs_extent_free(handle); + return retval; +} + +/* + * Deallocate all logical blocks starting at start to end, inclusive. + * If end is ~0, then this is effectively truncate. + */ +extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + char *block_buf, blk64_t start, + blk64_t end) +{ + errcode_t retval; + struct ext2_inode inode_buf; + + if (start > end) + return EINVAL; + + if (start == end) + return 0; + + /* Read inode structure if necessary */ + if (!inode) { + retval = ext2fs_read_inode(fs, ino, &inode_buf); + if (retval) + return retval; + inode = &inode_buf; + } + if (inode->i_flags & EXT4_EXTENTS_FL) + retval = ext2fs_punch_extent(fs, ino, inode, start, end); + else { + blk_t count; + + if (start > ~0U) + return 0; + count = ((end - start) < ~0U) ? (end - start) : ~0U; + retval = ext2fs_punch_ind(fs, inode, block_buf, + (blk_t) start, count); + } + if (retval) + return retval; + + return ext2fs_write_inode(fs, ino, inode); +} diff --git a/libcustomext2fs/source/read_bb.c b/libcustomext2fs/source/read_bb.c new file mode 100644 index 00000000..e5d63227 --- /dev/null +++ b/libcustomext2fs/source/read_bb.c @@ -0,0 +1,102 @@ +/* + * read_bb --- read the bad blocks inode + * + * Copyright (C) 1994 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct read_bb_record { + ext2_badblocks_list bb_list; + errcode_t err; +}; + +/* + * Helper function for ext2fs_read_bb_inode() + */ +#ifdef __TURBOC__ + #pragma argsused +#endif +static int mark_bad_block(ext2_filsys fs, blk_t *block_nr, + e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), + blk_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct read_bb_record *rb = (struct read_bb_record *) priv_data; + + if (blockcnt < 0) + return 0; + + if ((*block_nr < fs->super->s_first_data_block) || + (*block_nr >= ext2fs_blocks_count(fs->super))) + return 0; /* Ignore illegal blocks */ + + rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr); + if (rb->err) + return BLOCK_ABORT; + return 0; +} + +/* + * Reads the current bad blocks from the bad blocks inode. + */ +errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list) +{ + errcode_t retval; + struct read_bb_record rb; + struct ext2_inode inode; + blk_t numblocks; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!*bb_list) { + retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode); + if (retval) + return retval; + numblocks = inode.i_blocks; + if (!((fs->super->s_feature_ro_compat & + EXT4_FEATURE_RO_COMPAT_HUGE_FILE) && + (inode.i_flags & EXT4_HUGE_FILE_FL))) + numblocks = numblocks / (fs->blocksize / 512); + numblocks += 20; + if (numblocks < 50) + numblocks = 50; + if (numblocks > 50000) + numblocks = 500; + retval = ext2fs_badblocks_list_create(bb_list, numblocks); + if (retval) + return retval; + } + + rb.bb_list = *bb_list; + rb.err = 0; + retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, BLOCK_FLAG_READ_ONLY, + 0, mark_bad_block, &rb); + if (retval) + return retval; + + return rb.err; +} + + diff --git a/libcustomext2fs/source/read_bb_file.c b/libcustomext2fs/source/read_bb_file.c new file mode 100644 index 00000000..25454a87 --- /dev/null +++ b/libcustomext2fs/source/read_bb_file.c @@ -0,0 +1,105 @@ +/* + * read_bb_file.c --- read a list of bad blocks from a FILE * + * + * Copyright (C) 1994, 1995, 2000 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#if HAVE_SYS_STAT_H +#include +#endif +#if HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * Reads a list of bad blocks from a FILE * + */ +errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, + ext2_badblocks_list *bb_list, + void *priv_data, + void (*invalid)(ext2_filsys fs, + blk_t blk, + char *badstr, + void *priv_data)) +{ + errcode_t retval; + blk_t blockno; + int count; + char buf[128]; + + if (fs) + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!*bb_list) { + retval = ext2fs_badblocks_list_create(bb_list, 10); + if (retval) + return retval; + } + + while (!feof (f)) { + if (fgets(buf, sizeof(buf), f) == NULL) + break; + count = sscanf(buf, "%u", &blockno); + if (count <= 0) + continue; + if (fs && + ((blockno < fs->super->s_first_data_block) || + (blockno >= ext2fs_blocks_count(fs->super)))) { + if (invalid) + (invalid)(fs, blockno, buf, priv_data); + continue; + } + retval = ext2fs_badblocks_list_add(*bb_list, blockno); + if (retval) + return retval; + } + return 0; +} + +struct compat_struct { + void (*invalid)(ext2_filsys, blk_t); +}; + +static void call_compat_invalid(ext2_filsys fs, blk_t blk, + char *badstr EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct compat_struct *st; + + st = (struct compat_struct *) priv_data; + if (st->invalid) + (st->invalid)(fs, blk); +} + + +/* + * Reads a list of bad blocks from a FILE * + */ +errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, + ext2_badblocks_list *bb_list, + void (*invalid)(ext2_filsys fs, blk_t blk)) +{ + struct compat_struct st; + + st.invalid = invalid; + + return ext2fs_read_bb_FILE2(fs, f, bb_list, &st, + call_compat_invalid); +} + + diff --git a/libcustomext2fs/source/res_gdt.c b/libcustomext2fs/source/res_gdt.c new file mode 100644 index 00000000..0d988428 --- /dev/null +++ b/libcustomext2fs/source/res_gdt.c @@ -0,0 +1,220 @@ +/* + * res_gdt.c --- reserve blocks for growing the group descriptor table + * during online resizing. + * + * Copyright (C) 2002 Andreas Dilger + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * Iterate through the groups which hold BACKUP superblock/GDT copies in an + * ext3 filesystem. The counters should be initialized to 1, 5, and 7 before + * calling this for the first time. In a sparse filesystem it will be the + * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... + * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... + */ +static unsigned int list_backups(ext2_filsys fs, unsigned int *three, + unsigned int *five, unsigned int *seven) +{ + unsigned int *min = three; + int mult = 3; + unsigned int ret; + + if (!(fs->super->s_feature_ro_compat & + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) { + ret = *min; + *min += 1; + return ret; + } + + if (*five < *min) { + min = five; + mult = 5; + } + if (*seven < *min) { + min = seven; + mult = 7; + } + + ret = *min; + *min *= mult; + + return ret; +} + +/* + * This code assumes that the reserved blocks have already been marked in-use + * during ext2fs_initialize(), so that they are not allocated for other + * uses before we can add them to the resize inode (which has to come + * after the creation of the inode table). + */ +errcode_t ext2fs_create_resize_inode(ext2_filsys fs) +{ + errcode_t retval, retval2; + struct ext2_super_block *sb; + struct ext2_inode inode; + __u32 *dindir_buf = 0, *gdt_buf = 0; + unsigned long long apb, inode_size; + /* FIXME-64 - can't deal with extents */ + blk_t dindir_blk, rsv_off, gdt_off, gdt_blk; + int dindir_dirty = 0, inode_dirty = 0; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + sb = fs->super; + + retval = ext2fs_get_array(2, fs->blocksize, &dindir_buf); + if (retval) + goto out_free; + gdt_buf = (__u32 *)((char *)dindir_buf + fs->blocksize); + + retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode); + if (retval) + goto out_free; + + /* Maximum possible file size (we donly use the dindirect blocks) */ + apb = EXT2_ADDR_PER_BLOCK(sb); + if ((dindir_blk = inode.i_block[EXT2_DIND_BLOCK])) { +#ifdef RES_GDT_DEBUG + printf("reading GDT dindir %u\n", dindir_blk); +#endif + retval = ext2fs_read_ind_block(fs, dindir_blk, dindir_buf); + if (retval) + goto out_inode; + } else { + blk_t goal = sb->s_first_data_block + fs->desc_blocks + + sb->s_reserved_gdt_blocks + 2 + + fs->inode_blocks_per_group; + + retval = ext2fs_alloc_block(fs, goal, 0, &dindir_blk); + if (retval) + goto out_free; + inode.i_mode = LINUX_S_IFREG | 0600; + inode.i_links_count = 1; + inode.i_block[EXT2_DIND_BLOCK] = dindir_blk; + ext2fs_iblk_set(fs, &inode, 1); + memset(dindir_buf, 0, fs->blocksize); +#ifdef RES_GDT_DEBUG + printf("allocated GDT dindir %u\n", dindir_blk); +#endif + dindir_dirty = inode_dirty = 1; + inode_size = apb*apb + apb + EXT2_NDIR_BLOCKS; + inode_size *= fs->blocksize; + inode.i_size = inode_size & 0xFFFFFFFF; + inode.i_size_high = (inode_size >> 32) & 0xFFFFFFFF; + if(inode.i_size_high) { + sb->s_feature_ro_compat |= + EXT2_FEATURE_RO_COMPAT_LARGE_FILE; + } + inode.i_ctime = fs->now ? fs->now : time(0); + } + + for (rsv_off = 0, gdt_off = fs->desc_blocks, + gdt_blk = sb->s_first_data_block + 1 + fs->desc_blocks; + rsv_off < sb->s_reserved_gdt_blocks; + rsv_off++, gdt_off++, gdt_blk++) { + unsigned int three = 1, five = 5, seven = 7; + unsigned int grp, last = 0; + int gdt_dirty = 0; + + gdt_off %= apb; + if (!dindir_buf[gdt_off]) { + /* FIXME XXX XXX + blk_t new_blk; + + retval = ext2fs_new_block(fs, gdt_blk, 0, &new_blk); + if (retval) + goto out_free; + if (new_blk != gdt_blk) { + // XXX free block + retval = -1; // XXX + } + */ + gdt_dirty = dindir_dirty = inode_dirty = 1; + memset(gdt_buf, 0, fs->blocksize); + dindir_buf[gdt_off] = gdt_blk; + ext2fs_iblk_add_blocks(fs, &inode, 1); +#ifdef RES_GDT_DEBUG + printf("added primary GDT block %u at %u[%u]\n", + gdt_blk, dindir_blk, gdt_off); +#endif + } else if (dindir_buf[gdt_off] == gdt_blk) { +#ifdef RES_GDT_DEBUG + printf("reading primary GDT block %u\n", gdt_blk); +#endif + retval = ext2fs_read_ind_block(fs, gdt_blk, gdt_buf); + if (retval) + goto out_dindir; + } else { +#ifdef RES_GDT_DEBUG + printf("bad primary GDT %u != %u at %u[%u]\n", + dindir_buf[gdt_off], gdt_blk,dindir_blk,gdt_off); +#endif + retval = EXT2_ET_RESIZE_INODE_CORRUPT; + goto out_dindir; + } + + while ((grp = list_backups(fs, &three, &five, &seven)) < + fs->group_desc_count) { + blk_t expect = gdt_blk + grp * sb->s_blocks_per_group; + + if (!gdt_buf[last]) { +#ifdef RES_GDT_DEBUG + printf("added backup GDT %u grp %u@%u[%u]\n", + expect, grp, gdt_blk, last); +#endif + gdt_buf[last] = expect; + ext2fs_iblk_add_blocks(fs, &inode, 1); + gdt_dirty = inode_dirty = 1; + } else if (gdt_buf[last] != expect) { +#ifdef RES_GDT_DEBUG + printf("bad backup GDT %u != %u at %u[%u]\n", + gdt_buf[last], expect, gdt_blk, last); +#endif + retval = EXT2_ET_RESIZE_INODE_CORRUPT; + goto out_dindir; + } + last++; + } + if (gdt_dirty) { +#ifdef RES_GDT_DEBUG + printf("writing primary GDT block %u\n", gdt_blk); +#endif + retval = ext2fs_write_ind_block(fs, gdt_blk, gdt_buf); + if (retval) + goto out_dindir; + } + } + +out_dindir: + if (dindir_dirty) { + retval2 = ext2fs_write_ind_block(fs, dindir_blk, dindir_buf); + if (!retval) + retval = retval2; + } +out_inode: +#ifdef RES_GDT_DEBUG + printf("inode.i_blocks = %u, i_size = %u\n", inode.i_blocks, + inode.i_size); +#endif + if (inode_dirty) { + inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(0); + retval2 = ext2fs_write_new_inode(fs, EXT2_RESIZE_INO, &inode); + if (!retval) + retval = retval2; + } +out_free: + ext2fs_free_mem(&dindir_buf); + return retval; +} + diff --git a/libcustomext2fs/source/rw_bitmaps.c b/libcustomext2fs/source/rw_bitmaps.c new file mode 100644 index 00000000..7b74b421 --- /dev/null +++ b/libcustomext2fs/source/rw_bitmaps.c @@ -0,0 +1,351 @@ +/* + * rw_bitmaps.c --- routines to read and write the inode and block bitmaps. + * + * Copyright (C) 1993, 1994, 1994, 1996 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "e2image.h" + +static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) +{ + dgrp_t i; + unsigned int j; + int block_nbytes, inode_nbytes; + unsigned int nbits; + errcode_t retval; + char *block_buf = 0, *inode_buf = 0; + int csum_flag = 0; + blk64_t blk; + blk64_t blk_itr = fs->super->s_first_data_block; + ext2_ino_t ino_itr = 1; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) + csum_flag = 1; + + inode_nbytes = block_nbytes = 0; + if (do_block) { + block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize, + &block_buf); + if (retval) + return retval; + memset(block_buf, 0xff, fs->blocksize); + } + if (do_inode) { + inode_nbytes = (size_t) + ((EXT2_INODES_PER_GROUP(fs->super)+7) / 8); + retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize, + &inode_buf); + if (retval) + return retval; + memset(inode_buf, 0xff, fs->blocksize); + } + + for (i = 0; i < fs->group_desc_count; i++) { + if (!do_block) + goto skip_block_bitmap; + + if (csum_flag && ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) + ) + goto skip_this_block_bitmap; + + retval = ext2fs_get_block_bitmap_range2(fs->block_map, + blk_itr, block_nbytes << 3, block_buf); + if (retval) + return retval; + + if (i == fs->group_desc_count - 1) { + /* Force bitmap padding for the last group */ + nbits = ((ext2fs_blocks_count(fs->super) + - (__u64) fs->super->s_first_data_block) + % (__u64) EXT2_BLOCKS_PER_GROUP(fs->super)); + if (nbits) + for (j = nbits; j < fs->blocksize * 8; j++) + ext2fs_set_bit(j, block_buf); + } + blk = ext2fs_block_bitmap_loc(fs, i); + if (blk) { + retval = io_channel_write_blk64(fs->io, blk, 1, + block_buf); + if (retval) + return EXT2_ET_BLOCK_BITMAP_WRITE; + } + skip_this_block_bitmap: + blk_itr += block_nbytes << 3; + skip_block_bitmap: + + if (!do_inode) + continue; + + if (csum_flag && ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) + ) + goto skip_this_inode_bitmap; + + retval = ext2fs_get_inode_bitmap_range2(fs->inode_map, + ino_itr, inode_nbytes << 3, inode_buf); + if (retval) + return retval; + + blk = ext2fs_inode_bitmap_loc(fs, i); + if (blk) { + retval = io_channel_write_blk64(fs->io, blk, 1, + inode_buf); + if (retval) + return EXT2_ET_INODE_BITMAP_WRITE; + } + skip_this_inode_bitmap: + ino_itr += inode_nbytes << 3; + + } + if (do_block) { + fs->flags &= ~EXT2_FLAG_BB_DIRTY; + ext2fs_free_mem(&block_buf); + } + if (do_inode) { + fs->flags &= ~EXT2_FLAG_IB_DIRTY; + ext2fs_free_mem(&inode_buf); + } + return 0; +} + +static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) +{ + dgrp_t i; + char *block_bitmap = 0, *inode_bitmap = 0; + char *buf; + errcode_t retval; + int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; + int csum_flag = 0; + int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE; + unsigned int cnt; + blk64_t blk; + blk64_t blk_itr = fs->super->s_first_data_block; + blk64_t blk_cnt; + ext2_ino_t ino_itr = 1; + ext2_ino_t ino_cnt; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + fs->write_bitmaps = ext2fs_write_bitmaps; + + if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) + csum_flag = 1; + + retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf); + if (retval) + return retval; + if (do_block) { + if (fs->block_map) + ext2fs_free_block_bitmap(fs->block_map); + strcpy(buf, "block bitmap for "); + strcat(buf, fs->device_name); + retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map); + if (retval) + goto cleanup; + if (do_image) + retval = ext2fs_get_mem(fs->blocksize, &block_bitmap); + else + retval = ext2fs_get_memalign((unsigned) block_nbytes, + fs->blocksize, + &block_bitmap); + + if (retval) + goto cleanup; + } else + block_nbytes = 0; + if (do_inode) { + if (fs->inode_map) + ext2fs_free_inode_bitmap(fs->inode_map); + strcpy(buf, "inode bitmap for "); + strcat(buf, fs->device_name); + retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map); + if (retval) + goto cleanup; + retval = ext2fs_get_mem(do_image ? fs->blocksize : + (unsigned) inode_nbytes, &inode_bitmap); + if (retval) + goto cleanup; + } else + inode_nbytes = 0; + ext2fs_free_mem(&buf); + + if (fs->flags & EXT2_FLAG_IMAGE_FILE) { + blk = (fs->image_header->offset_inodemap / fs->blocksize); + ino_cnt = fs->super->s_inodes_count; + while (inode_nbytes > 0) { + retval = io_channel_read_blk64(fs->image_io, blk++, + 1, inode_bitmap); + if (retval) + goto cleanup; + cnt = fs->blocksize << 3; + if (cnt > ino_cnt) + cnt = ino_cnt; + retval = ext2fs_set_inode_bitmap_range2(fs->inode_map, + ino_itr, cnt, inode_bitmap); + if (retval) + goto cleanup; + ino_itr += fs->blocksize << 3; + ino_cnt -= fs->blocksize << 3; + inode_nbytes -= fs->blocksize; + } + blk = (fs->image_header->offset_blockmap / + fs->blocksize); + blk_cnt = (blk64_t)EXT2_BLOCKS_PER_GROUP(fs->super) * + fs->group_desc_count; + while (block_nbytes > 0) { + retval = io_channel_read_blk64(fs->image_io, blk++, + 1, block_bitmap); + if (retval) + goto cleanup; + cnt = fs->blocksize << 3; + if (cnt > blk_cnt) + cnt = blk_cnt; + retval = ext2fs_set_block_bitmap_range2(fs->block_map, + blk_itr, cnt, block_bitmap); + if (retval) + goto cleanup; + blk_itr += fs->blocksize << 3; + blk_cnt -= fs->blocksize << 3; + block_nbytes -= fs->blocksize; + } + goto success_cleanup; + } + + for (i = 0; i < fs->group_desc_count; i++) { + if (block_bitmap) { + blk = ext2fs_block_bitmap_loc(fs, i); + if (csum_flag && + ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) && + ext2fs_group_desc_csum_verify(fs, i)) + blk = 0; + if (blk) { + retval = io_channel_read_blk64(fs->io, blk, + -block_nbytes, block_bitmap); + if (retval) { + retval = EXT2_ET_BLOCK_BITMAP_READ; + goto cleanup; + } + } else + memset(block_bitmap, 0, block_nbytes); + cnt = block_nbytes << 3; + retval = ext2fs_set_block_bitmap_range2(fs->block_map, + blk_itr, cnt, block_bitmap); + if (retval) + goto cleanup; + blk_itr += block_nbytes << 3; + } + if (inode_bitmap) { + blk = ext2fs_inode_bitmap_loc(fs, i); + if (csum_flag && + ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) && + ext2fs_group_desc_csum_verify(fs, i)) + blk = 0; + if (blk) { + retval = io_channel_read_blk64(fs->io, blk, + -inode_nbytes, inode_bitmap); + if (retval) { + retval = EXT2_ET_INODE_BITMAP_READ; + goto cleanup; + } + } else + memset(inode_bitmap, 0, inode_nbytes); + cnt = inode_nbytes << 3; + retval = ext2fs_set_inode_bitmap_range2(fs->inode_map, + ino_itr, cnt, inode_bitmap); + if (retval) + goto cleanup; + ino_itr += inode_nbytes << 3; + } + } +success_cleanup: + if (inode_bitmap) + ext2fs_free_mem(&inode_bitmap); + if (block_bitmap) + ext2fs_free_mem(&block_bitmap); + return 0; + +cleanup: + if (do_block) { + ext2fs_free_mem(&fs->block_map); + fs->block_map = 0; + } + if (do_inode) { + ext2fs_free_mem(&fs->inode_map); + fs->inode_map = 0; + } + if (inode_bitmap) + ext2fs_free_mem(&inode_bitmap); + if (block_bitmap) + ext2fs_free_mem(&block_bitmap); + if (buf) + ext2fs_free_mem(&buf); + return retval; +} + +errcode_t ext2fs_read_inode_bitmap(ext2_filsys fs) +{ + return read_bitmaps(fs, 1, 0); +} + +errcode_t ext2fs_read_block_bitmap(ext2_filsys fs) +{ + return read_bitmaps(fs, 0, 1); +} + +errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs) +{ + return write_bitmaps(fs, 1, 0); +} + +errcode_t ext2fs_write_block_bitmap (ext2_filsys fs) +{ + return write_bitmaps(fs, 0, 1); +} + +errcode_t ext2fs_read_bitmaps(ext2_filsys fs) +{ + if (fs->inode_map && fs->block_map) + return 0; + + return read_bitmaps(fs, !fs->inode_map, !fs->block_map); +} + +errcode_t ext2fs_write_bitmaps(ext2_filsys fs) +{ + int do_inode = fs->inode_map && ext2fs_test_ib_dirty(fs); + int do_block = fs->block_map && ext2fs_test_bb_dirty(fs); + + if (!do_inode && !do_block) + return 0; + + return write_bitmaps(fs, do_inode, do_block); +} diff --git a/libcustomext2fs/source/sparse.c b/libcustomext2fs/source/sparse.c new file mode 100644 index 00000000..15ded0ae --- /dev/null +++ b/libcustomext2fs/source/sparse.c @@ -0,0 +1,52 @@ +/* + * sparse.c --- find the groups in an ext2 filesystem with metadata backups + * + * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. + * Copyright (C) 2002 Andreas Dilger. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include + +#include "ext2_fs.h" +#include "ext2fsP.h" + +/* + * Iterate through the groups which hold BACKUP superblock/GDT copies in an + * ext3 filesystem. The counters should be initialized to 1, 5, and 7 before + * calling this for the first time. In a sparse filesystem it will be the + * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... + * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ... + */ +unsigned int ext2fs_list_backups(ext2_filsys fs, unsigned int *three, + unsigned int *five, unsigned int *seven) +{ + unsigned int *min = three; + int mult = 3; + unsigned int ret; + + if (!(fs->super->s_feature_ro_compat & + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) { + ret = *min; + *min += 1; + return ret; + } + + if (*five < *min) { + min = five; + mult = 5; + } + if (*seven < *min) { + min = seven; + mult = 7; + } + + ret = *min; + *min *= mult; + + return ret; +} diff --git a/libcustomext2fs/source/swapfs.c b/libcustomext2fs/source/swapfs.c new file mode 100644 index 00000000..cd1b8087 --- /dev/null +++ b/libcustomext2fs/source/swapfs.c @@ -0,0 +1,313 @@ +/* + * swapfs.c --- swap ext2 filesystem data structures + * + * Copyright (C) 1995, 1996, 2002 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" +#include "ext2_ext_attr.h" + +#ifdef WORDS_BIGENDIAN +void ext2fs_swap_super(struct ext2_super_block * sb) +{ + int i; + sb->s_inodes_count = ext2fs_swab32(sb->s_inodes_count); + sb->s_blocks_count = ext2fs_swab32(sb->s_blocks_count); + sb->s_r_blocks_count = ext2fs_swab32(sb->s_r_blocks_count); + sb->s_free_blocks_count = ext2fs_swab32(sb->s_free_blocks_count); + sb->s_free_inodes_count = ext2fs_swab32(sb->s_free_inodes_count); + sb->s_first_data_block = ext2fs_swab32(sb->s_first_data_block); + sb->s_log_block_size = ext2fs_swab32(sb->s_log_block_size); + sb->s_log_frag_size = ext2fs_swab32(sb->s_log_frag_size); + sb->s_blocks_per_group = ext2fs_swab32(sb->s_blocks_per_group); + sb->s_frags_per_group = ext2fs_swab32(sb->s_frags_per_group); + sb->s_inodes_per_group = ext2fs_swab32(sb->s_inodes_per_group); + sb->s_mtime = ext2fs_swab32(sb->s_mtime); + sb->s_wtime = ext2fs_swab32(sb->s_wtime); + sb->s_mnt_count = ext2fs_swab16(sb->s_mnt_count); + sb->s_max_mnt_count = ext2fs_swab16(sb->s_max_mnt_count); + sb->s_magic = ext2fs_swab16(sb->s_magic); + sb->s_state = ext2fs_swab16(sb->s_state); + sb->s_errors = ext2fs_swab16(sb->s_errors); + sb->s_minor_rev_level = ext2fs_swab16(sb->s_minor_rev_level); + sb->s_lastcheck = ext2fs_swab32(sb->s_lastcheck); + sb->s_checkinterval = ext2fs_swab32(sb->s_checkinterval); + sb->s_creator_os = ext2fs_swab32(sb->s_creator_os); + sb->s_rev_level = ext2fs_swab32(sb->s_rev_level); + sb->s_def_resuid = ext2fs_swab16(sb->s_def_resuid); + sb->s_def_resgid = ext2fs_swab16(sb->s_def_resgid); + sb->s_first_ino = ext2fs_swab32(sb->s_first_ino); + sb->s_inode_size = ext2fs_swab16(sb->s_inode_size); + sb->s_block_group_nr = ext2fs_swab16(sb->s_block_group_nr); + sb->s_feature_compat = ext2fs_swab32(sb->s_feature_compat); + sb->s_feature_incompat = ext2fs_swab32(sb->s_feature_incompat); + sb->s_feature_ro_compat = ext2fs_swab32(sb->s_feature_ro_compat); + sb->s_algorithm_usage_bitmap = ext2fs_swab32(sb->s_algorithm_usage_bitmap); + sb->s_reserved_gdt_blocks = ext2fs_swab16(sb->s_reserved_gdt_blocks); + sb->s_journal_inum = ext2fs_swab32(sb->s_journal_inum); + sb->s_journal_dev = ext2fs_swab32(sb->s_journal_dev); + sb->s_last_orphan = ext2fs_swab32(sb->s_last_orphan); + sb->s_desc_size = ext2fs_swab16(sb->s_desc_size); + sb->s_default_mount_opts = ext2fs_swab32(sb->s_default_mount_opts); + sb->s_first_meta_bg = ext2fs_swab32(sb->s_first_meta_bg); + sb->s_mkfs_time = ext2fs_swab32(sb->s_mkfs_time); + sb->s_blocks_count_hi = ext2fs_swab32(sb->s_blocks_count_hi); + sb->s_r_blocks_count_hi = ext2fs_swab32(sb->s_r_blocks_count_hi); + sb->s_free_blocks_hi = ext2fs_swab32(sb->s_free_blocks_hi); + sb->s_min_extra_isize = ext2fs_swab16(sb->s_min_extra_isize); + sb->s_want_extra_isize = ext2fs_swab16(sb->s_want_extra_isize); + sb->s_flags = ext2fs_swab32(sb->s_flags); + sb->s_kbytes_written = ext2fs_swab64(sb->s_kbytes_written); + sb->s_snapshot_inum = ext2fs_swab32(sb->s_snapshot_inum); + sb->s_snapshot_id = ext2fs_swab32(sb->s_snapshot_id); + sb->s_snapshot_r_blocks_count = + ext2fs_swab64(sb->s_snapshot_r_blocks_count); + sb->s_snapshot_list = ext2fs_swab32(sb->s_snapshot_list); + + for (i=0; i < 4; i++) + sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]); + + /* if journal backup is for a valid extent-based journal... */ + if (!ext2fs_extent_header_verify(sb->s_jnl_blocks, + sizeof(sb->s_jnl_blocks))) { + /* ... swap only the journal i_size */ + sb->s_jnl_blocks[16] = ext2fs_swab32(sb->s_jnl_blocks[16]); + /* and the extent data is not swapped on read */ + return; + } + + /* direct/indirect journal: swap it all */ + for (i=0; i < 17; i++) + sb->s_jnl_blocks[i] = ext2fs_swab32(sb->s_jnl_blocks[i]); +} + +void ext2fs_swap_group_desc2(ext2_filsys fs, struct ext2_group_desc *gdp) +{ + /* Do the 32-bit parts first */ + gdp->bg_block_bitmap = ext2fs_swab32(gdp->bg_block_bitmap); + gdp->bg_inode_bitmap = ext2fs_swab32(gdp->bg_inode_bitmap); + gdp->bg_inode_table = ext2fs_swab32(gdp->bg_inode_table); + gdp->bg_free_blocks_count = ext2fs_swab16(gdp->bg_free_blocks_count); + gdp->bg_free_inodes_count = ext2fs_swab16(gdp->bg_free_inodes_count); + gdp->bg_used_dirs_count = ext2fs_swab16(gdp->bg_used_dirs_count); + gdp->bg_flags = ext2fs_swab16(gdp->bg_flags); + gdp->bg_itable_unused = ext2fs_swab16(gdp->bg_itable_unused); + gdp->bg_checksum = ext2fs_swab16(gdp->bg_checksum); + /* If we're 32-bit, we're done */ + if (fs && (!fs->super->s_desc_size || + (fs->super->s_desc_size < EXT2_MIN_DESC_SIZE_64BIT))) + return; + + /* Swap the 64-bit parts */ + struct ext4_group_desc *gdp4 = (struct ext4_group_desc *) gdp; + gdp4->bg_block_bitmap_hi = ext2fs_swab32(gdp4->bg_block_bitmap_hi); + gdp4->bg_inode_bitmap_hi = ext2fs_swab32(gdp4->bg_inode_bitmap_hi); + gdp4->bg_inode_table_hi = ext2fs_swab32(gdp4->bg_inode_table_hi); + gdp4->bg_free_blocks_count_hi = + ext2fs_swab16(gdp4->bg_free_blocks_count_hi); + gdp4->bg_free_inodes_count_hi = + ext2fs_swab16(gdp4->bg_free_inodes_count_hi); + gdp4->bg_used_dirs_count_hi = + ext2fs_swab16(gdp4->bg_used_dirs_count_hi); + gdp4->bg_itable_unused_hi = ext2fs_swab16(gdp4->bg_itable_unused_hi); +} + +void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) +{ + return ext2fs_swap_group_desc2(0, gdp); +} + + +void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header, + struct ext2_ext_attr_header *from_header) +{ + int n; + + to_header->h_magic = ext2fs_swab32(from_header->h_magic); + to_header->h_blocks = ext2fs_swab32(from_header->h_blocks); + to_header->h_refcount = ext2fs_swab32(from_header->h_refcount); + to_header->h_hash = ext2fs_swab32(from_header->h_hash); + for (n = 0; n < 4; n++) + to_header->h_reserved[n] = + ext2fs_swab32(from_header->h_reserved[n]); +} + +void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry, + struct ext2_ext_attr_entry *from_entry) +{ + to_entry->e_value_offs = ext2fs_swab16(from_entry->e_value_offs); + to_entry->e_value_block = ext2fs_swab32(from_entry->e_value_block); + to_entry->e_value_size = ext2fs_swab32(from_entry->e_value_size); + to_entry->e_hash = ext2fs_swab32(from_entry->e_hash); +} + +void ext2fs_swap_ext_attr(char *to, char *from, int bufsize, int has_header) +{ + struct ext2_ext_attr_header *from_header = + (struct ext2_ext_attr_header *)from; + struct ext2_ext_attr_header *to_header = + (struct ext2_ext_attr_header *)to; + struct ext2_ext_attr_entry *from_entry, *to_entry; + char *from_end = (char *)from_header + bufsize; + + if (to_header != from_header) + memcpy(to_header, from_header, bufsize); + + if (has_header) { + ext2fs_swap_ext_attr_header(to_header, from_header); + + from_entry = (struct ext2_ext_attr_entry *)(from_header+1); + to_entry = (struct ext2_ext_attr_entry *)(to_header+1); + } else { + from_entry = (struct ext2_ext_attr_entry *)from_header; + to_entry = (struct ext2_ext_attr_entry *)to_header; + } + + while ((char *)from_entry < from_end && *(__u32 *)from_entry) { + ext2fs_swap_ext_attr_entry(to_entry, from_entry); + from_entry = EXT2_EXT_ATTR_NEXT(from_entry); + to_entry = EXT2_EXT_ATTR_NEXT(to_entry); + } +} + +void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, + struct ext2_inode_large *f, int hostorder, + int bufsize) +{ + unsigned i, has_data_blocks = 0, extra_isize = 0, attr_magic = 0; + int has_extents = 0; + int islnk = 0; + __u32 *eaf, *eat; + + if (hostorder && LINUX_S_ISLNK(f->i_mode)) + islnk = 1; + t->i_mode = ext2fs_swab16(f->i_mode); + if (!hostorder && LINUX_S_ISLNK(t->i_mode)) + islnk = 1; + t->i_uid = ext2fs_swab16(f->i_uid); + t->i_size = ext2fs_swab32(f->i_size); + t->i_atime = ext2fs_swab32(f->i_atime); + t->i_ctime = ext2fs_swab32(f->i_ctime); + t->i_mtime = ext2fs_swab32(f->i_mtime); + t->i_dtime = ext2fs_swab32(f->i_dtime); + t->i_gid = ext2fs_swab16(f->i_gid); + t->i_links_count = ext2fs_swab16(f->i_links_count); + t->i_file_acl = ext2fs_swab32(f->i_file_acl); + if (hostorder) + has_data_blocks = ext2fs_inode_data_blocks(fs, + (struct ext2_inode *) f); + t->i_blocks = ext2fs_swab32(f->i_blocks); + if (!hostorder) + has_data_blocks = ext2fs_inode_data_blocks(fs, + (struct ext2_inode *) t); + if (hostorder && (f->i_flags & EXT4_EXTENTS_FL)) + has_extents = 1; + t->i_flags = ext2fs_swab32(f->i_flags); + if (!hostorder && (t->i_flags & EXT4_EXTENTS_FL)) + has_extents = 1; + t->i_dir_acl = ext2fs_swab32(f->i_dir_acl); + /* extent data are swapped on access, not here */ + if (!has_extents && (!islnk || has_data_blocks)) { + for (i = 0; i < EXT2_N_BLOCKS; i++) + t->i_block[i] = ext2fs_swab32(f->i_block[i]); + } else if (t != f) { + for (i = 0; i < EXT2_N_BLOCKS; i++) + t->i_block[i] = f->i_block[i]; + } + t->i_generation = ext2fs_swab32(f->i_generation); + t->i_faddr = ext2fs_swab32(f->i_faddr); + + switch (fs->super->s_creator_os) { + case EXT2_OS_LINUX: + t->osd1.linux1.l_i_version = + ext2fs_swab32(f->osd1.linux1.l_i_version); + t->osd2.linux2.l_i_blocks_hi = + ext2fs_swab16(f->osd2.linux2.l_i_blocks_hi); + t->osd2.linux2.l_i_file_acl_high = + ext2fs_swab16(f->osd2.linux2.l_i_file_acl_high); + t->osd2.linux2.l_i_uid_high = + ext2fs_swab16 (f->osd2.linux2.l_i_uid_high); + t->osd2.linux2.l_i_gid_high = + ext2fs_swab16 (f->osd2.linux2.l_i_gid_high); + t->osd2.linux2.l_i_reserved2 = + ext2fs_swab32(f->osd2.linux2.l_i_reserved2); + break; + case EXT2_OS_HURD: + t->osd1.hurd1.h_i_translator = + ext2fs_swab32 (f->osd1.hurd1.h_i_translator); + t->osd2.hurd2.h_i_frag = f->osd2.hurd2.h_i_frag; + t->osd2.hurd2.h_i_fsize = f->osd2.hurd2.h_i_fsize; + t->osd2.hurd2.h_i_mode_high = + ext2fs_swab16 (f->osd2.hurd2.h_i_mode_high); + t->osd2.hurd2.h_i_uid_high = + ext2fs_swab16 (f->osd2.hurd2.h_i_uid_high); + t->osd2.hurd2.h_i_gid_high = + ext2fs_swab16 (f->osd2.hurd2.h_i_gid_high); + t->osd2.hurd2.h_i_author = + ext2fs_swab32 (f->osd2.hurd2.h_i_author); + break; + default: + break; + } + + if (bufsize < (int) (sizeof(struct ext2_inode) + sizeof(__u16))) + return; /* no i_extra_isize field */ + + if (hostorder) + extra_isize = f->i_extra_isize; + t->i_extra_isize = ext2fs_swab16(f->i_extra_isize); + if (!hostorder) + extra_isize = t->i_extra_isize; + if (extra_isize > EXT2_INODE_SIZE(fs->super) - + sizeof(struct ext2_inode)) { + /* this is error case: i_extra_size is too large */ + return; + } + + i = sizeof(struct ext2_inode) + extra_isize + sizeof(__u32); + if (bufsize < (int) i) + return; /* no space for EA magic */ + + eaf = (__u32 *) (((char *) f) + sizeof(struct ext2_inode) + + extra_isize); + + attr_magic = *eaf; + if (!hostorder) + attr_magic = ext2fs_swab32(attr_magic); + + if (attr_magic != EXT2_EXT_ATTR_MAGIC) + return; /* it seems no magic here */ + + eat = (__u32 *) (((char *) t) + sizeof(struct ext2_inode) + + extra_isize); + *eat = ext2fs_swab32(*eaf); + + /* convert EA(s) */ + ext2fs_swap_ext_attr((char *) (eat + 1), (char *) (eaf + 1), + bufsize - sizeof(struct ext2_inode) - + extra_isize - sizeof(__u32), 0); + +} + +void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t, + struct ext2_inode *f, int hostorder) +{ + ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) t, + (struct ext2_inode_large *) f, hostorder, + sizeof(struct ext2_inode)); +} + +#endif diff --git a/libcustomext2fs/source/tdb.c b/libcustomext2fs/source/tdb.c new file mode 100644 index 00000000..0550f468 --- /dev/null +++ b/libcustomext2fs/source/tdb.c @@ -0,0 +1,4145 @@ +/* +URL: svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/tdb/common +Rev: 23590 +Last Changed Date: 2007-06-22 13:36:10 -0400 (Fri, 22 Jun 2007) +*/ + /* + trivial database library - standalone version + + Copyright (C) Andrew Tridgell 1999-2005 + Copyright (C) Jeremy Allison 2000-2006 + Copyright (C) Paul `Rusty' Russell 2000 + + ** NOTE! The following LGPL license applies to the tdb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef CONFIG_STAND_ALONE +#define HAVE_MMAP +#define HAVE_STRDUP +#define HAVE_SYS_MMAN_H +#define HAVE_UTIME_H +#define HAVE_UTIME +#endif +#define _XOPEN_SOURCE 600 + +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_SELECT_H +#include +#endif +#include +#include +#include +#ifdef HAVE_UTIME_H +#include +#endif +#include +#include +#include + +#ifdef HAVE_SYS_MMAN_H +#include +#endif + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +#ifndef HAVE_STRDUP +#define strdup rep_strdup +static char *rep_strdup(const char *s) +{ + char *ret; + int length; + if (!s) + return NULL; + + if (!length) + length = strlen(s); + + ret = malloc(length + 1); + if (ret) { + strncpy(ret, s, length); + ret[length] = '\0'; + } + return ret; +} +#endif + +#ifndef PRINTF_ATTRIBUTE +#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) +/** Use gcc attribute to check printf fns. a1 is the 1-based index of + * the parameter containing the format, and a2 the index of the first + * argument. Note that some gcc 2.x versions don't handle this + * properly **/ +#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) +#else +#define PRINTF_ATTRIBUTE(a1, a2) +#endif +#endif + +typedef int bool; + +#include "tdb.h" + +#ifndef u32 +#define u32 unsigned +#endif + +#ifndef HAVE_GETPAGESIZE +#define getpagesize() 0x2000 +#endif + +typedef u32 tdb_len_t; +typedef u32 tdb_off_t; + +#ifndef offsetof +#define offsetof(t,f) ((unsigned int)&((t *)0)->f) +#endif + +#define TDB_MAGIC_FOOD "TDB file\n" +#define TDB_VERSION (0x26011967 + 6) +#define TDB_MAGIC (0x26011999U) +#define TDB_FREE_MAGIC (~TDB_MAGIC) +#define TDB_DEAD_MAGIC (0xFEE1DEAD) +#define TDB_RECOVERY_MAGIC (0xf53bc0e7U) +#define TDB_ALIGNMENT 4 +#define MIN_REC_SIZE (2*sizeof(struct list_struct) + TDB_ALIGNMENT) +#define DEFAULT_HASH_SIZE 131 +#define FREELIST_TOP (sizeof(struct tdb_header)) +#define TDB_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1)) +#define TDB_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24)) +#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC) +#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r)) +#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t)) +#define TDB_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb_off_t)) +#define TDB_DATA_START(hash_size) TDB_HASH_TOP(hash_size-1) +#define TDB_RECOVERY_HEAD offsetof(struct tdb_header, recovery_start) +#define TDB_SEQNUM_OFS offsetof(struct tdb_header, sequence_number) +#define TDB_PAD_BYTE 0x42 +#define TDB_PAD_U32 0x42424242 + +/* NB assumes there is a local variable called "tdb" that is the + * current context, also takes doubly-parenthesized print-style + * argument. */ +#define TDB_LOG(x) tdb->log.log_fn x + +/* lock offsets */ +#define GLOBAL_LOCK 0 +#define ACTIVE_LOCK 4 +#define TRANSACTION_LOCK 8 + +/* free memory if the pointer is valid and zero the pointer */ +#ifndef SAFE_FREE +#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0) +#endif + +#define BUCKET(hash) ((hash) % tdb->header.hash_size) + +#define DOCONV() (tdb->flags & TDB_CONVERT) +#define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x) + + +/* the body of the database is made of one list_struct for the free space + plus a separate data list for each hash value */ +struct list_struct { + tdb_off_t next; /* offset of the next record in the list */ + tdb_len_t rec_len; /* total byte length of record */ + tdb_len_t key_len; /* byte length of key */ + tdb_len_t data_len; /* byte length of data */ + u32 full_hash; /* the full 32 bit hash of the key */ + u32 magic; /* try to catch errors */ + /* the following union is implied: + union { + char record[rec_len]; + struct { + char key[key_len]; + char data[data_len]; + } + u32 totalsize; (tailer) + } + */ +}; + + +/* this is stored at the front of every database */ +struct tdb_header { + char magic_food[32]; /* for /etc/magic */ + u32 version; /* version of the code */ + u32 hash_size; /* number of hash entries */ + tdb_off_t rwlocks; /* obsolete - kept to detect old formats */ + tdb_off_t recovery_start; /* offset of transaction recovery region */ + tdb_off_t sequence_number; /* used when TDB_SEQNUM is set */ + tdb_off_t reserved[29]; +}; + +struct tdb_lock_type { + int list; + u32 count; + u32 ltype; +}; + +struct tdb_traverse_lock { + struct tdb_traverse_lock *next; + u32 off; + u32 hash; + int lock_rw; +}; + + +struct tdb_methods { + int (*tdb_read)(struct tdb_context *, tdb_off_t , void *, tdb_len_t , int ); + int (*tdb_write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t); + void (*next_hash_chain)(struct tdb_context *, u32 *); + int (*tdb_oob)(struct tdb_context *, tdb_off_t , int ); + int (*tdb_expand_file)(struct tdb_context *, tdb_off_t , tdb_off_t ); + int (*tdb_brlock)(struct tdb_context *, tdb_off_t , int, int, int, size_t); +}; + +struct tdb_context { + char *name; /* the name of the database */ + void *map_ptr; /* where it is currently mapped */ + int fd; /* open file descriptor for the database */ + tdb_len_t map_size; /* how much space has been mapped */ + int read_only; /* opened read-only */ + int traverse_read; /* read-only traversal */ + struct tdb_lock_type global_lock; + int num_lockrecs; + struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */ + enum TDB_ERROR ecode; /* error code for last tdb error */ + struct tdb_header header; /* a cached copy of the header */ + u32 flags; /* the flags passed to tdb_open */ + struct tdb_traverse_lock travlocks; /* current traversal locks */ + struct tdb_context *next; /* all tdbs to avoid multiple opens */ + dev_t device; /* uniquely identifies this tdb */ + ino_t inode; /* uniquely identifies this tdb */ + struct tdb_logging_context log; + unsigned int (*hash_fn)(TDB_DATA *key); + int open_flags; /* flags used in the open - needed by reopen */ + unsigned int num_locks; /* number of chain locks held */ + const struct tdb_methods *methods; + struct tdb_transaction *transaction; + int page_size; + int max_dead_records; + bool have_transaction_lock; +}; + + +/* + internal prototypes +*/ +static int tdb_munmap(struct tdb_context *tdb); +static void tdb_mmap(struct tdb_context *tdb); +static int tdb_lock(struct tdb_context *tdb, int list, int ltype); +static int tdb_unlock(struct tdb_context *tdb, int list, int ltype); +static int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, int rw_type, int lck_type, int probe, size_t len); +static int tdb_transaction_lock(struct tdb_context *tdb, int ltype); +static int tdb_transaction_unlock(struct tdb_context *tdb); +static int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len); +static int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off); +static int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off); +static int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); +static int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); +static void *tdb_convert(void *buf, u32 size); +static int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec); +static tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct list_struct *rec); +static int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); +static int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); +static int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off); +static int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off); +static int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec); +static int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec); +static int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct *rec); +static unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len); +static int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key, + tdb_off_t offset, tdb_len_t len, + int (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); +static tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, int locktype, + struct list_struct *rec); +static void tdb_io_init(struct tdb_context *tdb); +static int tdb_expand(struct tdb_context *tdb, tdb_off_t size); +static int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, + struct list_struct *rec); + + +/* file: error.c */ + +enum TDB_ERROR tdb_error(struct tdb_context *tdb) +{ + return tdb->ecode; +} + +static struct tdb_errname { + enum TDB_ERROR ecode; const char *estring; +} emap[] = { {TDB_SUCCESS, "Success"}, + {TDB_ERR_CORRUPT, "Corrupt database"}, + {TDB_ERR_IO, "IO Error"}, + {TDB_ERR_LOCK, "Locking error"}, + {TDB_ERR_OOM, "Out of memory"}, + {TDB_ERR_EXISTS, "Record exists"}, + {TDB_ERR_NOLOCK, "Lock exists on other keys"}, + {TDB_ERR_EINVAL, "Invalid parameter"}, + {TDB_ERR_NOEXIST, "Record does not exist"}, + {TDB_ERR_RDONLY, "write not permitted"} }; + +/* Error string for the last tdb error */ +const char *tdb_errorstr(struct tdb_context *tdb) +{ + u32 i; + for (i = 0; i < sizeof(emap) / sizeof(struct tdb_errname); i++) + if (tdb->ecode == emap[i].ecode) + return emap[i].estring; + return "Invalid error code"; +} + +/* file: lock.c */ + +#define TDB_MARK_LOCK 0x80000000 + +/* a byte range locking function - return 0 on success + this functions locks/unlocks 1 byte at the specified offset. + + On error, errno is also set so that errors are passed back properly + through tdb_open(). + + note that a len of zero means lock to end of file +*/ +int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, + int rw_type, int lck_type, int probe, size_t len) +{ + struct flock fl; + int ret; + + if (tdb->flags & TDB_NOLOCK) { + return 0; + } + + if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) { + tdb->ecode = TDB_ERR_RDONLY; + return -1; + } + + fl.l_type = rw_type; + fl.l_whence = SEEK_SET; + fl.l_start = offset; + fl.l_len = len; + fl.l_pid = 0; + + do { + ret = fcntl(tdb->fd,lck_type,&fl); + } while (ret == -1 && errno == EINTR); + + if (ret == -1) { + /* Generic lock error. errno set by fcntl. + * EAGAIN is an expected return from non-blocking + * locks. */ + if (!probe && lck_type != F_SETLK) { + /* Ensure error code is set for log fun to examine. */ + tdb->ecode = TDB_ERR_LOCK; + TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n", + tdb->fd, offset, rw_type, lck_type, (int)len)); + } + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + return 0; +} + + +/* + upgrade a read lock to a write lock. This needs to be handled in a + special way as some OSes (such as solaris) have too conservative + deadlock detection and claim a deadlock when progress can be + made. For those OSes we may loop for a while. +*/ +int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len) +{ + int count = 1000; + while (count--) { + struct timeval tv; + if (tdb_brlock(tdb, offset, F_WRLCK, F_SETLKW, 1, len) == 0) { + return 0; + } + if (errno != EDEADLK) { + break; + } + /* sleep for as short a time as we can - more portable than usleep() */ + tv.tv_sec = 0; + tv.tv_usec = 1; +#ifdef HAVE_SYS_SELECT_H + select(0, NULL, NULL, NULL, &tv); +#endif + } + TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock_upgrade failed at offset %d\n", offset)); + return -1; +} + + +/* lock a list in the database. list -1 is the alloc list */ +static int _tdb_lock(struct tdb_context *tdb, int list, int ltype, int op) +{ + struct tdb_lock_type *new_lck; + int i; + bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK); + + ltype &= ~TDB_MARK_LOCK; + + /* a global lock allows us to avoid per chain locks */ + if (tdb->global_lock.count && + (ltype == tdb->global_lock.ltype || ltype == F_RDLCK)) { + return 0; + } + + if (tdb->global_lock.count) { + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + + if (list < -1 || list >= (int)tdb->header.hash_size) { + TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_lock: invalid list %d for ltype=%d\n", + list, ltype)); + return -1; + } + if (tdb->flags & TDB_NOLOCK) + return 0; + + for (i=0; inum_lockrecs; i++) { + if (tdb->lockrecs[i].list == list) { + if (tdb->lockrecs[i].count == 0) { + /* + * Can't happen, see tdb_unlock(). It should + * be an assert. + */ + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock: " + "lck->count == 0 for list %d", list)); + } + /* + * Just increment the in-memory struct, posix locks + * don't stack. + */ + tdb->lockrecs[i].count++; + return 0; + } + } + + new_lck = (struct tdb_lock_type *)realloc( + tdb->lockrecs, + sizeof(*tdb->lockrecs) * (tdb->num_lockrecs+1)); + if (new_lck == NULL) { + errno = ENOMEM; + return -1; + } + tdb->lockrecs = new_lck; + + /* Since fcntl locks don't nest, we do a lock for the first one, + and simply bump the count for future ones */ + if (!mark_lock && + tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list, ltype, op, + 0, 1)) { + return -1; + } + + tdb->num_locks++; + + tdb->lockrecs[tdb->num_lockrecs].list = list; + tdb->lockrecs[tdb->num_lockrecs].count = 1; + tdb->lockrecs[tdb->num_lockrecs].ltype = ltype; + tdb->num_lockrecs += 1; + + return 0; +} + +/* lock a list in the database. list -1 is the alloc list */ +int tdb_lock(struct tdb_context *tdb, int list, int ltype) +{ + int ret; + ret = _tdb_lock(tdb, list, ltype, F_SETLKW); + if (ret) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d " + "ltype=%d (%s)\n", list, ltype, strerror(errno))); + } + return ret; +} + +/* lock a list in the database. list -1 is the alloc list. non-blocking lock */ +int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype) +{ + return _tdb_lock(tdb, list, ltype, F_SETLK); +} + + +/* unlock the database: returns void because it's too late for errors. */ + /* changed to return int it may be interesting to know there + has been an error --simo */ +int tdb_unlock(struct tdb_context *tdb, int list, int ltype) +{ + int ret = -1; + int i; + struct tdb_lock_type *lck = NULL; + bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK); + + ltype &= ~TDB_MARK_LOCK; + + /* a global lock allows us to avoid per chain locks */ + if (tdb->global_lock.count && + (ltype == tdb->global_lock.ltype || ltype == F_RDLCK)) { + return 0; + } + + if (tdb->global_lock.count) { + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + + if (tdb->flags & TDB_NOLOCK) + return 0; + + /* Sanity checks */ + if (list < -1 || list >= (int)tdb->header.hash_size) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: list %d invalid (%d)\n", list, tdb->header.hash_size)); + return ret; + } + + for (i=0; inum_lockrecs; i++) { + if (tdb->lockrecs[i].list == list) { + lck = &tdb->lockrecs[i]; + break; + } + } + + if ((lck == NULL) || (lck->count == 0)) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: count is 0\n")); + return -1; + } + + if (lck->count > 1) { + lck->count--; + return 0; + } + + /* + * This lock has count==1 left, so we need to unlock it in the + * kernel. We don't bother with decrementing the in-memory array + * element, we're about to overwrite it with the last array element + * anyway. + */ + + if (mark_lock) { + ret = 0; + } else { + ret = tdb->methods->tdb_brlock(tdb, FREELIST_TOP+4*list, F_UNLCK, + F_SETLKW, 0, 1); + } + tdb->num_locks--; + + /* + * Shrink the array by overwriting the element just unlocked with the + * last array element. + */ + + if (tdb->num_lockrecs > 1) { + *lck = tdb->lockrecs[tdb->num_lockrecs-1]; + } + tdb->num_lockrecs -= 1; + + /* + * We don't bother with realloc when the array shrinks, but if we have + * a completely idle tdb we should get rid of the locked array. + */ + + if (tdb->num_lockrecs == 0) { + SAFE_FREE(tdb->lockrecs); + } + + if (ret) + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: An error occurred unlocking!\n")); + return ret; +} + +/* + get the transaction lock + */ +int tdb_transaction_lock(struct tdb_context *tdb, int ltype) +{ + if (tdb->have_transaction_lock || tdb->global_lock.count) { + return 0; + } + if (tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, ltype, + F_SETLKW, 0, 1) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_lock: failed to get transaction lock\n")); + tdb->ecode = TDB_ERR_LOCK; + return -1; + } + tdb->have_transaction_lock = 1; + return 0; +} + +/* + release the transaction lock + */ +int tdb_transaction_unlock(struct tdb_context *tdb) +{ + int ret; + if (!tdb->have_transaction_lock) { + return 0; + } + ret = tdb->methods->tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); + if (ret == 0) { + tdb->have_transaction_lock = 0; + } + return ret; +} + + + + +/* lock/unlock entire database */ +static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op) +{ + bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK); + + ltype &= ~TDB_MARK_LOCK; + + /* There are no locks on read-only dbs */ + if (tdb->read_only || tdb->traverse_read) + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + + if (tdb->global_lock.count && tdb->global_lock.ltype == ltype) { + tdb->global_lock.count++; + return 0; + } + + if (tdb->global_lock.count) { + /* a global lock of a different type exists */ + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + + if (tdb->num_locks != 0) { + /* can't combine global and chain locks */ + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + + if (!mark_lock && + tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, op, + 0, 4*tdb->header.hash_size)) { + if (op == F_SETLKW) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno))); + } + return -1; + } + + tdb->global_lock.count = 1; + tdb->global_lock.ltype = ltype; + + return 0; +} + + + +/* unlock entire db */ +static int _tdb_unlockall(struct tdb_context *tdb, int ltype) +{ + bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK); + + ltype &= ~TDB_MARK_LOCK; + + /* There are no locks on read-only dbs */ + if (tdb->read_only || tdb->traverse_read) { + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + + if (tdb->global_lock.ltype != ltype || tdb->global_lock.count == 0) { + return TDB_ERRCODE(TDB_ERR_LOCK, -1); + } + + if (tdb->global_lock.count > 1) { + tdb->global_lock.count--; + return 0; + } + + if (!mark_lock && + tdb->methods->tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, + 0, 4*tdb->header.hash_size)) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlockall failed (%s)\n", strerror(errno))); + return -1; + } + + tdb->global_lock.count = 0; + tdb->global_lock.ltype = 0; + + return 0; +} + +/* lock entire database with write lock */ +int tdb_lockall(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_WRLCK, F_SETLKW); +} + +/* lock entire database with write lock - mark only */ +int tdb_lockall_mark(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_WRLCK | TDB_MARK_LOCK, F_SETLKW); +} + +/* unlock entire database with write lock - unmark only */ +int tdb_lockall_unmark(struct tdb_context *tdb) +{ + return _tdb_unlockall(tdb, F_WRLCK | TDB_MARK_LOCK); +} + +/* lock entire database with write lock - nonblocking varient */ +int tdb_lockall_nonblock(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_WRLCK, F_SETLK); +} + +/* unlock entire database with write lock */ +int tdb_unlockall(struct tdb_context *tdb) +{ + return _tdb_unlockall(tdb, F_WRLCK); +} + +/* lock entire database with read lock */ +int tdb_lockall_read(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_RDLCK, F_SETLKW); +} + +/* lock entire database with read lock - nonblock varient */ +int tdb_lockall_read_nonblock(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_RDLCK, F_SETLK); +} + +/* unlock entire database with read lock */ +int tdb_unlockall_read(struct tdb_context *tdb) +{ + return _tdb_unlockall(tdb, F_RDLCK); +} + +/* lock/unlock one hash chain. This is meant to be used to reduce + contention - it cannot guarantee how many records will be locked */ +int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); +} + +/* lock/unlock one hash chain, non-blocking. This is meant to be used + to reduce contention - it cannot guarantee how many records will be + locked */ +int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); +} + +/* mark a chain as locked without actually locking it. Warning! use with great caution! */ +int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK | TDB_MARK_LOCK); +} + +/* unmark a chain as locked without actually locking it. Warning! use with great caution! */ +int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK | TDB_MARK_LOCK); +} + +int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); +} + +int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK); +} + +int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key) +{ + return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK); +} + + + +/* record lock stops delete underneath */ +int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off) +{ + return off ? tdb->methods->tdb_brlock(tdb, off, F_RDLCK, F_SETLKW, 0, 1) : 0; +} + +/* + Write locks override our own fcntl readlocks, so check it here. + Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not + an error to fail to get the lock here. +*/ +int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off) +{ + struct tdb_traverse_lock *i; + for (i = &tdb->travlocks; i; i = i->next) + if (i->off == off) + return -1; + return tdb->methods->tdb_brlock(tdb, off, F_WRLCK, F_SETLK, 1, 1); +} + +/* + Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not + an error to fail to get the lock here. +*/ +int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off) +{ + return tdb->methods->tdb_brlock(tdb, off, F_UNLCK, F_SETLK, 0, 1); +} + +/* fcntl locks don't stack: avoid unlocking someone else's */ +int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off) +{ + struct tdb_traverse_lock *i; + u32 count = 0; + + if (off == 0) + return 0; + for (i = &tdb->travlocks; i; i = i->next) + if (i->off == off) + count++; + return (count == 1 ? tdb->methods->tdb_brlock(tdb, off, F_UNLCK, F_SETLKW, 0, 1) : 0); +} + +/* file: io.c */ + +/* check for an out of bounds access - if it is out of bounds then + see if the database has been expanded by someone else and expand + if necessary + note that "len" is the minimum length needed for the db +*/ +static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, int probe) +{ + struct stat st; + if (len <= tdb->map_size) + return 0; + if (tdb->flags & TDB_INTERNAL) { + if (!probe) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob len %d beyond internal malloc size %d\n", + (int)len, (int)tdb->map_size)); + } + return TDB_ERRCODE(TDB_ERR_IO, -1); + } + + if (fstat(tdb->fd, &st) == -1) { + return TDB_ERRCODE(TDB_ERR_IO, -1); + } + + if (st.st_size < (size_t)len) { + if (!probe) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob len %d beyond eof at %d\n", + (int)len, (int)st.st_size)); + } + return TDB_ERRCODE(TDB_ERR_IO, -1); + } + + /* Unmap, update size, remap */ + if (tdb_munmap(tdb) == -1) + return TDB_ERRCODE(TDB_ERR_IO, -1); + tdb->map_size = st.st_size; + tdb_mmap(tdb); + return 0; +} + +/* write a lump of data at a specified offset */ +static int tdb_write(struct tdb_context *tdb, tdb_off_t off, + const void *buf, tdb_len_t len) +{ + if (len == 0) { + return 0; + } + + if (tdb->read_only || tdb->traverse_read) { + tdb->ecode = TDB_ERR_RDONLY; + return -1; + } + + if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0) + return -1; + + if (tdb->map_ptr) { + memcpy(off + (char *)tdb->map_ptr, buf, len); + } else if (pwrite(tdb->fd, buf, len, off) != (ssize_t)len) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d len=%d (%s)\n", + off, len, strerror(errno))); + return TDB_ERRCODE(TDB_ERR_IO, -1); + } + return 0; +} + +/* Endian conversion: we only ever deal with 4 byte quantities */ +void *tdb_convert(void *buf, u32 size) +{ + u32 i, *p = (u32 *)buf; + for (i = 0; i < size / 4; i++) + p[i] = TDB_BYTEREV(p[i]); + return buf; +} + + +/* read a lump of data at a specified offset, maybe convert */ +static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf, + tdb_len_t len, int cv) +{ + if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0) { + return -1; + } + + if (tdb->map_ptr) { + memcpy(buf, off + (char *)tdb->map_ptr, len); + } else { + ssize_t ret = pread(tdb->fd, buf, len, off); + if (ret != (ssize_t)len) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %d " + "len=%d ret=%d (%s) map_size=%d\n", + (int)off, (int)len, (int)ret, strerror(errno), + (int)tdb->map_size)); + return TDB_ERRCODE(TDB_ERR_IO, -1); + } + } + if (cv) { + tdb_convert(buf, len); + } + return 0; +} + + + +/* + do an unlocked scan of the hash table heads to find the next non-zero head. The value + will then be confirmed with the lock held +*/ +static void tdb_next_hash_chain(struct tdb_context *tdb, u32 *chain) +{ + u32 h = *chain; + if (tdb->map_ptr) { + for (;h < tdb->header.hash_size;h++) { + if (0 != *(u32 *)(TDB_HASH_TOP(h) + (unsigned char *)tdb->map_ptr)) { + break; + } + } + } else { + u32 off=0; + for (;h < tdb->header.hash_size;h++) { + if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &off) != 0 || off != 0) { + break; + } + } + } + (*chain) = h; +} + + +int tdb_munmap(struct tdb_context *tdb) +{ + if (tdb->flags & TDB_INTERNAL) + return 0; + +#ifdef HAVE_MMAP + if (tdb->map_ptr) { + int ret = munmap(tdb->map_ptr, tdb->map_size); + if (ret != 0) + return ret; + } +#endif + tdb->map_ptr = NULL; + return 0; +} + +void tdb_mmap(struct tdb_context *tdb) +{ + if (tdb->flags & TDB_INTERNAL) + return; + +#ifdef HAVE_MMAP + if (!(tdb->flags & TDB_NOMMAP)) { + tdb->map_ptr = mmap(NULL, tdb->map_size, + PROT_READ|(tdb->read_only? 0:PROT_WRITE), + MAP_SHARED|MAP_FILE, tdb->fd, 0); + + /* + * NB. When mmap fails it returns MAP_FAILED *NOT* NULL !!!! + */ + + if (tdb->map_ptr == MAP_FAILED) { + tdb->map_ptr = NULL; + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %d (%s)\n", + tdb->map_size, strerror(errno))); + } + } else { + tdb->map_ptr = NULL; + } +#else + tdb->map_ptr = NULL; +#endif +} + +/* expand a file. we prefer to use ftruncate, as that is what posix + says to use for mmap expansion */ +static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t addition) +{ + char buf[1024]; + + if (tdb->read_only || tdb->traverse_read) { + tdb->ecode = TDB_ERR_RDONLY; + return -1; + } + + if (ftruncate(tdb->fd, size+addition) == -1) { + char b = 0; + if (pwrite(tdb->fd, &b, 1, (size+addition) - 1) != 1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %d failed (%s)\n", + size+addition, strerror(errno))); + return -1; + } + } + + /* now fill the file with something. This ensures that the + file isn't sparse, which would be very bad if we ran out of + disk. This must be done with write, not via mmap */ + memset(buf, TDB_PAD_BYTE, sizeof(buf)); + while (addition) { + int n = addition>sizeof(buf)?sizeof(buf):addition; + int ret = pwrite(tdb->fd, buf, n, size); + if (ret != n) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of %d failed (%s)\n", + n, strerror(errno))); + return -1; + } + addition -= n; + size += n; + } + return 0; +} + + +/* expand the database at least size bytes by expanding the underlying + file and doing the mmap again if necessary */ +int tdb_expand(struct tdb_context *tdb, tdb_off_t size) +{ + struct list_struct rec; + tdb_off_t offset; + + if (tdb_lock(tdb, -1, F_WRLCK) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "lock failed in tdb_expand\n")); + return -1; + } + + /* must know about any previous expansions by another process */ + tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1); + + /* always make room for at least 10 more records, and round + the database up to a multiple of the page size */ + size = TDB_ALIGN(tdb->map_size + size*10, tdb->page_size) - tdb->map_size; + + if (!(tdb->flags & TDB_INTERNAL)) + tdb_munmap(tdb); + + /* + * We must ensure the file is unmapped before doing this + * to ensure consistency with systems like OpenBSD where + * writes and mmaps are not consistent. + */ + + /* expand the file itself */ + if (!(tdb->flags & TDB_INTERNAL)) { + if (tdb->methods->tdb_expand_file(tdb, tdb->map_size, size) != 0) + goto fail; + } + + tdb->map_size += size; + + if (tdb->flags & TDB_INTERNAL) { + char *new_map_ptr = (char *)realloc(tdb->map_ptr, + tdb->map_size); + if (!new_map_ptr) { + tdb->map_size -= size; + goto fail; + } + tdb->map_ptr = new_map_ptr; + } else { + /* + * We must ensure the file is remapped before adding the space + * to ensure consistency with systems like OpenBSD where + * writes and mmaps are not consistent. + */ + + /* We're ok if the mmap fails as we'll fallback to read/write */ + tdb_mmap(tdb); + } + + /* form a new freelist record */ + memset(&rec,'\0',sizeof(rec)); + rec.rec_len = size - sizeof(rec); + + /* link it into the free list */ + offset = tdb->map_size - size; + if (tdb_free(tdb, offset, &rec) == -1) + goto fail; + + tdb_unlock(tdb, -1, F_WRLCK); + return 0; + fail: + tdb_unlock(tdb, -1, F_WRLCK); + return -1; +} + +/* read/write a tdb_off_t */ +int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d) +{ + return tdb->methods->tdb_read(tdb, offset, (char*)d, sizeof(*d), DOCONV()); +} + +int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d) +{ + tdb_off_t off = *d; + return tdb->methods->tdb_write(tdb, offset, CONVERT(off), sizeof(*d)); +} + + +/* read a lump of data, allocating the space for it */ +unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len) +{ + unsigned char *buf; + + /* some systems don't like zero length malloc */ + if (len == 0) { + len = 1; + } + + if (!(buf = (unsigned char *)malloc(len))) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_OOM; + TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%d (%s)\n", + len, strerror(errno))); + return TDB_ERRCODE(TDB_ERR_OOM, buf); + } + if (tdb->methods->tdb_read(tdb, offset, buf, len, 0) == -1) { + SAFE_FREE(buf); + return NULL; + } + return buf; +} + +/* Give a piece of tdb data to a parser */ + +int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key, + tdb_off_t offset, tdb_len_t len, + int (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data) +{ + TDB_DATA data; + int result; + + data.dsize = len; + + if ((tdb->transaction == NULL) && (tdb->map_ptr != NULL)) { + /* + * Optimize by avoiding the malloc/memcpy/free, point the + * parser directly at the mmap area. + */ + if (tdb->methods->tdb_oob(tdb, offset+len, 0) != 0) { + return -1; + } + data.dptr = offset + (unsigned char *)tdb->map_ptr; + return parser(key, data, private_data); + } + + if (!(data.dptr = tdb_alloc_read(tdb, offset, len))) { + return -1; + } + + result = parser(key, data, private_data); + free(data.dptr); + return result; +} + +/* read/write a record */ +int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec) +{ + if (tdb->methods->tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1) + return -1; + if (TDB_BAD_MAGIC(rec)) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_CORRUPT; + TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset)); + return TDB_ERRCODE(TDB_ERR_CORRUPT, -1); + } + return tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0); +} + +int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec) +{ + struct list_struct r = *rec; + return tdb->methods->tdb_write(tdb, offset, CONVERT(r), sizeof(r)); +} + +static const struct tdb_methods io_methods = { + tdb_read, + tdb_write, + tdb_next_hash_chain, + tdb_oob, + tdb_expand_file, + tdb_brlock +}; + +/* + initialise the default methods table +*/ +void tdb_io_init(struct tdb_context *tdb) +{ + tdb->methods = &io_methods; +} + +/* file: transaction.c */ + +/* + transaction design: + + - only allow a single transaction at a time per database. This makes + using the transaction API simpler, as otherwise the caller would + have to cope with temporary failures in transactions that conflict + with other current transactions + + - keep the transaction recovery information in the same file as the + database, using a special 'transaction recovery' record pointed at + by the header. This removes the need for extra journal files as + used by some other databases + + - dynamically allocated the transaction recover record, re-using it + for subsequent transactions. If a larger record is needed then + tdb_free() the old record to place it on the normal tdb freelist + before allocating the new record + + - during transactions, keep a linked list of writes all that have + been performed by intercepting all tdb_write() calls. The hooked + transaction versions of tdb_read() and tdb_write() check this + linked list and try to use the elements of the list in preference + to the real database. + + - don't allow any locks to be held when a transaction starts, + otherwise we can end up with deadlock (plus lack of lock nesting + in posix locks would mean the lock is lost) + + - if the caller gains a lock during the transaction but doesn't + release it then fail the commit + + - allow for nested calls to tdb_transaction_start(), re-using the + existing transaction record. If the inner transaction is cancelled + then a subsequent commit will fail + + - keep a mirrored copy of the tdb hash chain heads to allow for the + fast hash heads scan on traverse, updating the mirrored copy in + the transaction version of tdb_write + + - allow callers to mix transaction and non-transaction use of tdb, + although once a transaction is started then an exclusive lock is + gained until the transaction is committed or cancelled + + - the commit stategy involves first saving away all modified data + into a linearised buffer in the transaction recovery area, then + marking the transaction recovery area with a magic value to + indicate a valid recovery record. In total 4 fsync/msync calls are + needed per commit to prevent race conditions. It might be possible + to reduce this to 3 or even 2 with some more work. + + - check for a valid recovery record on open of the tdb, while the + global lock is held. Automatically recover from the transaction + recovery area if needed, then continue with the open as + usual. This allows for smooth crash recovery with no administrator + intervention. + + - if TDB_NOSYNC is passed to flags in tdb_open then transactions are + still available, but no transaction recovery area is used and no + fsync/msync calls are made. + +*/ + +struct tdb_transaction_el { + struct tdb_transaction_el *next, *prev; + tdb_off_t offset; + tdb_len_t length; + unsigned char *data; +}; + +/* + hold the context of any current transaction +*/ +struct tdb_transaction { + /* we keep a mirrored copy of the tdb hash heads here so + tdb_next_hash_chain() can operate efficiently */ + u32 *hash_heads; + + /* the original io methods - used to do IOs to the real db */ + const struct tdb_methods *io_methods; + + /* the list of transaction elements. We use a doubly linked + list with a last pointer to allow us to keep the list + ordered, with first element at the front of the list. It + needs to be doubly linked as the read/write traversals need + to be backwards, while the commit needs to be forwards */ + struct tdb_transaction_el *elements, *elements_last; + + /* non-zero when an internal transaction error has + occurred. All write operations will then fail until the + transaction is ended */ + int transaction_error; + + /* when inside a transaction we need to keep track of any + nested tdb_transaction_start() calls, as these are allowed, + but don't create a new transaction */ + int nesting; + + /* old file size before transaction */ + tdb_len_t old_map_size; +}; + + +/* + read while in a transaction. We need to check first if the data is in our list + of transaction elements, then if not do a real read +*/ +static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf, + tdb_len_t len, int cv) +{ + struct tdb_transaction_el *el; + + /* we need to walk the list backwards to get the most recent data */ + for (el=tdb->transaction->elements_last;el;el=el->prev) { + tdb_len_t partial; + + if (off+len <= el->offset) { + continue; + } + if (off >= el->offset + el->length) { + continue; + } + + /* an overlapping read - needs to be split into up to + 2 reads and a memcpy */ + if (off < el->offset) { + partial = el->offset - off; + if (transaction_read(tdb, off, buf, partial, cv) != 0) { + goto fail; + } + len -= partial; + off += partial; + buf = (void *)(partial + (char *)buf); + } + if (off + len <= el->offset + el->length) { + partial = len; + } else { + partial = el->offset + el->length - off; + } + memcpy(buf, el->data + (off - el->offset), partial); + if (cv) { + tdb_convert(buf, len); + } + len -= partial; + off += partial; + buf = (void *)(partial + (char *)buf); + + if (len != 0 && transaction_read(tdb, off, buf, len, cv) != 0) { + goto fail; + } + + return 0; + } + + /* its not in the transaction elements - do a real read */ + return tdb->transaction->io_methods->tdb_read(tdb, off, buf, len, cv); + +fail: + TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%d len=%d\n", off, len)); + tdb->ecode = TDB_ERR_IO; + tdb->transaction->transaction_error = 1; + return -1; +} + + +/* + write while in a transaction +*/ +static int transaction_write(struct tdb_context *tdb, tdb_off_t off, + const void *buf, tdb_len_t len) +{ + struct tdb_transaction_el *el, *best_el=NULL; + + if (len == 0) { + return 0; + } + + /* if the write is to a hash head, then update the transaction + hash heads */ + if (len == sizeof(tdb_off_t) && off >= FREELIST_TOP && + off < FREELIST_TOP+TDB_HASHTABLE_SIZE(tdb)) { + u32 chain = (off-FREELIST_TOP) / sizeof(tdb_off_t); + memcpy(&tdb->transaction->hash_heads[chain], buf, len); + } + + /* first see if we can replace an existing entry */ + for (el=tdb->transaction->elements_last;el;el=el->prev) { + tdb_len_t partial; + + if (best_el == NULL && off == el->offset+el->length) { + best_el = el; + } + + if (off+len <= el->offset) { + continue; + } + if (off >= el->offset + el->length) { + continue; + } + + /* an overlapping write - needs to be split into up to + 2 writes and a memcpy */ + if (off < el->offset) { + partial = el->offset - off; + if (transaction_write(tdb, off, buf, partial) != 0) { + goto fail; + } + len -= partial; + off += partial; + buf = (const void *)(partial + (const char *)buf); + } + if (off + len <= el->offset + el->length) { + partial = len; + } else { + partial = el->offset + el->length - off; + } + memcpy(el->data + (off - el->offset), buf, partial); + len -= partial; + off += partial; + buf = (const void *)(partial + (const char *)buf); + + if (len != 0 && transaction_write(tdb, off, buf, len) != 0) { + goto fail; + } + + return 0; + } + + /* see if we can append the new entry to an existing entry */ + if (best_el && best_el->offset + best_el->length == off && + (off+len < tdb->transaction->old_map_size || + off > tdb->transaction->old_map_size)) { + unsigned char *data = best_el->data; + el = best_el; + el->data = (unsigned char *)realloc(el->data, + el->length + len); + if (el->data == NULL) { + tdb->ecode = TDB_ERR_OOM; + tdb->transaction->transaction_error = 1; + el->data = data; + return -1; + } + if (buf) { + memcpy(el->data + el->length, buf, len); + } else { + memset(el->data + el->length, TDB_PAD_BYTE, len); + } + el->length += len; + return 0; + } + + /* add a new entry at the end of the list */ + el = (struct tdb_transaction_el *)malloc(sizeof(*el)); + if (el == NULL) { + tdb->ecode = TDB_ERR_OOM; + tdb->transaction->transaction_error = 1; + return -1; + } + el->next = NULL; + el->prev = tdb->transaction->elements_last; + el->offset = off; + el->length = len; + el->data = (unsigned char *)malloc(len); + if (el->data == NULL) { + free(el); + tdb->ecode = TDB_ERR_OOM; + tdb->transaction->transaction_error = 1; + return -1; + } + if (buf) { + memcpy(el->data, buf, len); + } else { + memset(el->data, TDB_PAD_BYTE, len); + } + if (el->prev) { + el->prev->next = el; + } else { + tdb->transaction->elements = el; + } + tdb->transaction->elements_last = el; + return 0; + +fail: + TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%d len=%d\n", off, len)); + tdb->ecode = TDB_ERR_IO; + tdb->transaction->transaction_error = 1; + return -1; +} + +/* + accelerated hash chain head search, using the cached hash heads +*/ +static void transaction_next_hash_chain(struct tdb_context *tdb, u32 *chain) +{ + u32 h = *chain; + for (;h < tdb->header.hash_size;h++) { + /* the +1 takes account of the freelist */ + if (0 != tdb->transaction->hash_heads[h+1]) { + break; + } + } + (*chain) = h; +} + +/* + out of bounds check during a transaction +*/ +static int transaction_oob(struct tdb_context *tdb, tdb_off_t len, int probe) +{ + if (len <= tdb->map_size) { + return 0; + } + return TDB_ERRCODE(TDB_ERR_IO, -1); +} + +/* + transaction version of tdb_expand(). +*/ +static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size, + tdb_off_t addition) +{ + /* add a write to the transaction elements, so subsequent + reads see the zero data */ + if (transaction_write(tdb, size, NULL, addition) != 0) { + return -1; + } + + return 0; +} + +/* + brlock during a transaction - ignore them +*/ +static int transaction_brlock(struct tdb_context *tdb, tdb_off_t offset, + int rw_type, int lck_type, int probe, size_t len) +{ + return 0; +} + +static const struct tdb_methods transaction_methods = { + transaction_read, + transaction_write, + transaction_next_hash_chain, + transaction_oob, + transaction_expand_file, + transaction_brlock +}; + + +/* + start a tdb transaction. No token is returned, as only a single + transaction is allowed to be pending per tdb_context +*/ +int tdb_transaction_start(struct tdb_context *tdb) +{ + /* some sanity checks */ + if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n")); + tdb->ecode = TDB_ERR_EINVAL; + return -1; + } + + /* cope with nested tdb_transaction_start() calls */ + if (tdb->transaction != NULL) { + tdb->transaction->nesting++; + TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n", + tdb->transaction->nesting)); + return 0; + } + + if (tdb->num_locks != 0 || tdb->global_lock.count) { + /* the caller must not have any locks when starting a + transaction as otherwise we'll be screwed by lack + of nested locks in posix */ + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction with locks held\n")); + tdb->ecode = TDB_ERR_LOCK; + return -1; + } + + if (tdb->travlocks.next != NULL) { + /* you cannot use transactions inside a traverse (although you can use + traverse inside a transaction) as otherwise you can end up with + deadlock */ + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction within a traverse\n")); + tdb->ecode = TDB_ERR_LOCK; + return -1; + } + + tdb->transaction = (struct tdb_transaction *) + calloc(sizeof(struct tdb_transaction), 1); + if (tdb->transaction == NULL) { + tdb->ecode = TDB_ERR_OOM; + return -1; + } + + /* get the transaction write lock. This is a blocking lock. As + discussed with Volker, there are a number of ways we could + make this async, which we will probably do in the future */ + if (tdb_transaction_lock(tdb, F_WRLCK) == -1) { + SAFE_FREE(tdb->transaction); + return -1; + } + + /* get a read lock from the freelist to the end of file. This + is upgraded to a write lock during the commit */ + if (tdb_brlock(tdb, FREELIST_TOP, F_RDLCK, F_SETLKW, 0, 0) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n")); + tdb->ecode = TDB_ERR_LOCK; + goto fail; + } + + /* setup a copy of the hash table heads so the hash scan in + traverse can be fast */ + tdb->transaction->hash_heads = (u32 *) + calloc(tdb->header.hash_size+1, sizeof(u32)); + if (tdb->transaction->hash_heads == NULL) { + tdb->ecode = TDB_ERR_OOM; + goto fail; + } + if (tdb->methods->tdb_read(tdb, FREELIST_TOP, tdb->transaction->hash_heads, + TDB_HASHTABLE_SIZE(tdb), 0) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_start: failed to read hash heads\n")); + tdb->ecode = TDB_ERR_IO; + goto fail; + } + + /* make sure we know about any file expansions already done by + anyone else */ + tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1); + tdb->transaction->old_map_size = tdb->map_size; + + /* finally hook the io methods, replacing them with + transaction specific methods */ + tdb->transaction->io_methods = tdb->methods; + tdb->methods = &transaction_methods; + + /* by calling this transaction write here, we ensure that we don't grow the + transaction linked list due to hash table updates */ + if (transaction_write(tdb, FREELIST_TOP, tdb->transaction->hash_heads, + TDB_HASHTABLE_SIZE(tdb)) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_start: failed to prime hash table\n")); + tdb->ecode = TDB_ERR_IO; + tdb->methods = tdb->transaction->io_methods; + goto fail; + } + + return 0; + +fail: + tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0); + tdb_transaction_unlock(tdb); + SAFE_FREE(tdb->transaction->hash_heads); + SAFE_FREE(tdb->transaction); + return -1; +} + + +/* + cancel the current transaction +*/ +int tdb_transaction_cancel(struct tdb_context *tdb) +{ + if (tdb->transaction == NULL) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_cancel: no transaction\n")); + return -1; + } + + if (tdb->transaction->nesting != 0) { + tdb->transaction->transaction_error = 1; + tdb->transaction->nesting--; + return 0; + } + + tdb->map_size = tdb->transaction->old_map_size; + + /* free all the transaction elements */ + while (tdb->transaction->elements) { + struct tdb_transaction_el *el = tdb->transaction->elements; + tdb->transaction->elements = el->next; + free(el->data); + free(el); + } + + /* remove any global lock created during the transaction */ + if (tdb->global_lock.count != 0) { + tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 4*tdb->header.hash_size); + tdb->global_lock.count = 0; + } + + /* remove any locks created during the transaction */ + if (tdb->num_locks != 0) { + int i; + for (i=0;inum_lockrecs;i++) { + tdb_brlock(tdb,FREELIST_TOP+4*tdb->lockrecs[i].list, + F_UNLCK,F_SETLKW, 0, 1); + } + tdb->num_locks = 0; + tdb->num_lockrecs = 0; + SAFE_FREE(tdb->lockrecs); + } + + /* restore the normal io methods */ + tdb->methods = tdb->transaction->io_methods; + + tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0); + tdb_transaction_unlock(tdb); + SAFE_FREE(tdb->transaction->hash_heads); + SAFE_FREE(tdb->transaction); + + return 0; +} + +/* + sync to disk +*/ +static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length) +{ + if (fsync(tdb->fd) != 0) { + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n")); + return -1; + } +#ifdef MS_SYNC + if (tdb->map_ptr) { + tdb_off_t moffset = offset & ~(tdb->page_size-1); + if (msync(moffset + (char *)tdb->map_ptr, + length + (offset - moffset), MS_SYNC) != 0) { + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: msync failed - %s\n", + strerror(errno))); + return -1; + } + } +#endif + return 0; +} + + +/* + work out how much space the linearised recovery data will consume +*/ +static tdb_len_t tdb_recovery_size(struct tdb_context *tdb) +{ + struct tdb_transaction_el *el; + tdb_len_t recovery_size = 0; + + recovery_size = sizeof(u32); + for (el=tdb->transaction->elements;el;el=el->next) { + if (el->offset >= tdb->transaction->old_map_size) { + continue; + } + recovery_size += 2*sizeof(tdb_off_t) + el->length; + } + + return recovery_size; +} + +/* + allocate the recovery area, or use an existing recovery area if it is + large enough +*/ +static int tdb_recovery_allocate(struct tdb_context *tdb, + tdb_len_t *recovery_size, + tdb_off_t *recovery_offset, + tdb_len_t *recovery_max_size) +{ + struct list_struct rec; + const struct tdb_methods *methods = tdb->transaction->io_methods; + tdb_off_t recovery_head; + + if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to read recovery head\n")); + return -1; + } + + rec.rec_len = 0; + + if (recovery_head != 0 && + methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to read recovery record\n")); + return -1; + } + + *recovery_size = tdb_recovery_size(tdb); + + if (recovery_head != 0 && *recovery_size <= rec.rec_len) { + /* it fits in the existing area */ + *recovery_max_size = rec.rec_len; + *recovery_offset = recovery_head; + return 0; + } + + /* we need to free up the old recovery area, then allocate a + new one at the end of the file. Note that we cannot use + tdb_allocate() to allocate the new one as that might return + us an area that is being currently used (as of the start of + the transaction) */ + if (recovery_head != 0) { + if (tdb_free(tdb, recovery_head, &rec) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to free previous recovery area\n")); + return -1; + } + } + + /* the tdb_free() call might have increased the recovery size */ + *recovery_size = tdb_recovery_size(tdb); + + /* round up to a multiple of page size */ + *recovery_max_size = TDB_ALIGN(sizeof(rec) + *recovery_size, tdb->page_size) - sizeof(rec); + *recovery_offset = tdb->map_size; + recovery_head = *recovery_offset; + + if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size, + (tdb->map_size - tdb->transaction->old_map_size) + + sizeof(rec) + *recovery_max_size) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to create recovery area\n")); + return -1; + } + + /* remap the file (if using mmap) */ + methods->tdb_oob(tdb, tdb->map_size + 1, 1); + + /* we have to reset the old map size so that we don't try to expand the file + again in the transaction commit, which would destroy the recovery area */ + tdb->transaction->old_map_size = tdb->map_size; + + /* write the recovery header offset and sync - we can sync without a race here + as the magic ptr in the recovery record has not been set */ + CONVERT(recovery_head); + if (methods->tdb_write(tdb, TDB_RECOVERY_HEAD, + &recovery_head, sizeof(tdb_off_t)) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to write recovery head\n")); + return -1; + } + + return 0; +} + + +/* + setup the recovery data that will be used on a crash during commit +*/ +static int transaction_setup_recovery(struct tdb_context *tdb, + tdb_off_t *magic_offset) +{ + struct tdb_transaction_el *el; + tdb_len_t recovery_size; + unsigned char *data, *p; + const struct tdb_methods *methods = tdb->transaction->io_methods; + struct list_struct *rec; + tdb_off_t recovery_offset, recovery_max_size; + tdb_off_t old_map_size = tdb->transaction->old_map_size; + u32 magic, tailer; + + /* + check that the recovery area has enough space + */ + if (tdb_recovery_allocate(tdb, &recovery_size, + &recovery_offset, &recovery_max_size) == -1) { + return -1; + } + + data = (unsigned char *)malloc(recovery_size + sizeof(*rec)); + if (data == NULL) { + tdb->ecode = TDB_ERR_OOM; + return -1; + } + + rec = (struct list_struct *)data; + memset(rec, 0, sizeof(*rec)); + + rec->magic = 0; + rec->data_len = recovery_size; + rec->rec_len = recovery_max_size; + rec->key_len = old_map_size; + CONVERT(rec); + + /* build the recovery data into a single blob to allow us to do a single + large write, which should be more efficient */ + p = data + sizeof(*rec); + for (el=tdb->transaction->elements;el;el=el->next) { + if (el->offset >= old_map_size) { + continue; + } + if (el->offset + el->length > tdb->transaction->old_map_size) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: transaction data over new region boundary\n")); + free(data); + tdb->ecode = TDB_ERR_CORRUPT; + return -1; + } + memcpy(p, &el->offset, 4); + memcpy(p+4, &el->length, 4); + if (DOCONV()) { + tdb_convert(p, 8); + } + /* the recovery area contains the old data, not the + new data, so we have to call the original tdb_read + method to get it */ + if (methods->tdb_read(tdb, el->offset, p + 8, el->length, 0) != 0) { + free(data); + tdb->ecode = TDB_ERR_IO; + return -1; + } + p += 8 + el->length; + } + + /* and the tailer */ + tailer = sizeof(*rec) + recovery_max_size; + memcpy(p, &tailer, 4); + CONVERT(p); + + /* write the recovery data to the recovery area */ + if (methods->tdb_write(tdb, recovery_offset, data, sizeof(*rec) + recovery_size) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery data\n")); + free(data); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + /* as we don't have ordered writes, we have to sync the recovery + data before we update the magic to indicate that the recovery + data is present */ + if (transaction_sync(tdb, recovery_offset, sizeof(*rec) + recovery_size) == -1) { + free(data); + return -1; + } + + free(data); + + magic = TDB_RECOVERY_MAGIC; + CONVERT(magic); + + *magic_offset = recovery_offset + offsetof(struct list_struct, magic); + + if (methods->tdb_write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery magic\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + /* ensure the recovery magic marker is on disk */ + if (transaction_sync(tdb, *magic_offset, sizeof(magic)) == -1) { + return -1; + } + + return 0; +} + +/* + commit the current transaction +*/ +int tdb_transaction_commit(struct tdb_context *tdb) +{ + const struct tdb_methods *methods; + tdb_off_t magic_offset = 0; + u32 zero = 0; + + if (tdb->transaction == NULL) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: no transaction\n")); + return -1; + } + + if (tdb->transaction->transaction_error) { + tdb->ecode = TDB_ERR_IO; + tdb_transaction_cancel(tdb); + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: transaction error pending\n")); + return -1; + } + + if (tdb->transaction->nesting != 0) { + tdb->transaction->nesting--; + return 0; + } + + /* check for a null transaction */ + if (tdb->transaction->elements == NULL) { + tdb_transaction_cancel(tdb); + return 0; + } + + methods = tdb->transaction->io_methods; + + /* if there are any locks pending then the caller has not + nested their locks properly, so fail the transaction */ + if (tdb->num_locks || tdb->global_lock.count) { + tdb->ecode = TDB_ERR_LOCK; + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: locks pending on commit\n")); + tdb_transaction_cancel(tdb); + return -1; + } + + /* upgrade the main transaction lock region to a write lock */ + if (tdb_brlock_upgrade(tdb, FREELIST_TOP, 0) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to upgrade hash locks\n")); + tdb->ecode = TDB_ERR_LOCK; + tdb_transaction_cancel(tdb); + return -1; + } + + /* get the global lock - this prevents new users attaching to the database + during the commit */ + if (tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0, 1) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: failed to get global lock\n")); + tdb->ecode = TDB_ERR_LOCK; + tdb_transaction_cancel(tdb); + return -1; + } + + if (!(tdb->flags & TDB_NOSYNC)) { + /* write the recovery data to the end of the file */ + if (transaction_setup_recovery(tdb, &magic_offset) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: failed to setup recovery data\n")); + tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1); + tdb_transaction_cancel(tdb); + return -1; + } + } + + /* expand the file to the new size if needed */ + if (tdb->map_size != tdb->transaction->old_map_size) { + if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size, + tdb->map_size - + tdb->transaction->old_map_size) == -1) { + tdb->ecode = TDB_ERR_IO; + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: expansion failed\n")); + tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1); + tdb_transaction_cancel(tdb); + return -1; + } + tdb->map_size = tdb->transaction->old_map_size; + methods->tdb_oob(tdb, tdb->map_size + 1, 1); + } + + /* perform all the writes */ + while (tdb->transaction->elements) { + struct tdb_transaction_el *el = tdb->transaction->elements; + + if (methods->tdb_write(tdb, el->offset, el->data, el->length) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed during commit\n")); + + /* we've overwritten part of the data and + possibly expanded the file, so we need to + run the crash recovery code */ + tdb->methods = methods; + tdb_transaction_recover(tdb); + + tdb_transaction_cancel(tdb); + tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1); + + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed\n")); + return -1; + } + tdb->transaction->elements = el->next; + free(el->data); + free(el); + } + + if (!(tdb->flags & TDB_NOSYNC)) { + /* ensure the new data is on disk */ + if (transaction_sync(tdb, 0, tdb->map_size) == -1) { + return -1; + } + + /* remove the recovery marker */ + if (methods->tdb_write(tdb, magic_offset, &zero, 4) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: failed to remove recovery magic\n")); + return -1; + } + + /* ensure the recovery marker has been removed on disk */ + if (transaction_sync(tdb, magic_offset, 4) == -1) { + return -1; + } + } + + tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1); + + /* + TODO: maybe write to some dummy hdr field, or write to magic + offset without mmap, before the last sync, instead of the + utime() call + */ + + /* on some systems (like Linux 2.6.x) changes via mmap/msync + don't change the mtime of the file, this means the file may + not be backed up (as tdb rounding to block sizes means that + file size changes are quite rare too). The following forces + mtime changes when a transaction completes */ +#ifdef HAVE_UTIME + utime(tdb->name, NULL); +#endif + + /* use a transaction cancel to free memory and remove the + transaction locks */ + tdb_transaction_cancel(tdb); + return 0; +} + + +/* + recover from an aborted transaction. Must be called with exclusive + database write access already established (including the global + lock to prevent new processes attaching) +*/ +int tdb_transaction_recover(struct tdb_context *tdb) +{ + tdb_off_t recovery_head, recovery_eof; + unsigned char *data, *p; + u32 zero = 0; + struct list_struct rec; + + /* find the recovery area */ + if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery head\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + if (recovery_head == 0) { + /* we have never allocated a recovery record */ + return 0; + } + + /* read the recovery record */ + if (tdb->methods->tdb_read(tdb, recovery_head, &rec, + sizeof(rec), DOCONV()) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery record\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + if (rec.magic != TDB_RECOVERY_MAGIC) { + /* there is no valid recovery data */ + return 0; + } + + if (tdb->read_only) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: attempt to recover read only database\n")); + tdb->ecode = TDB_ERR_CORRUPT; + return -1; + } + + recovery_eof = rec.key_len; + + data = (unsigned char *)malloc(rec.data_len); + if (data == NULL) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to allocate recovery data\n")); + tdb->ecode = TDB_ERR_OOM; + return -1; + } + + /* read the full recovery data */ + if (tdb->methods->tdb_read(tdb, recovery_head + sizeof(rec), data, + rec.data_len, 0) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery data\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + /* recover the file data */ + p = data; + while (p+8 < data + rec.data_len) { + u32 ofs, len; + if (DOCONV()) { + tdb_convert(p, 8); + } + memcpy(&ofs, p, 4); + memcpy(&len, p+4, 4); + + if (tdb->methods->tdb_write(tdb, ofs, p+8, len) == -1) { + free(data); + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %d bytes at offset %d\n", len, ofs)); + tdb->ecode = TDB_ERR_IO; + return -1; + } + p += 8 + len; + } + + free(data); + + if (transaction_sync(tdb, 0, tdb->map_size) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync recovery\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + /* if the recovery area is after the recovered eof then remove it */ + if (recovery_eof <= recovery_head) { + if (tdb_ofs_write(tdb, TDB_RECOVERY_HEAD, &zero) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery head\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + } + + /* remove the recovery magic */ + if (tdb_ofs_write(tdb, recovery_head + offsetof(struct list_struct, magic), + &zero) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery magic\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + /* reduce the file size to the old size */ + tdb_munmap(tdb); + if (ftruncate(tdb->fd, recovery_eof) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to reduce to recovery size\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + tdb->map_size = recovery_eof; + tdb_mmap(tdb); + + if (transaction_sync(tdb, 0, recovery_eof) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync2 recovery\n")); + tdb->ecode = TDB_ERR_IO; + return -1; + } + + TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %d byte database\n", + recovery_eof)); + + /* all done */ + return 0; +} + +/* file: freelist.c */ + +/* read a freelist record and check for simple errors */ +static int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct list_struct *rec) +{ + if (tdb->methods->tdb_read(tdb, off, rec, sizeof(*rec),DOCONV()) == -1) + return -1; + + if (rec->magic == TDB_MAGIC) { + /* this happens when a app is showdown while deleting a record - we should + not completely fail when this happens */ + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%d - fixing\n", + rec->magic, off)); + rec->magic = TDB_FREE_MAGIC; + if (tdb->methods->tdb_write(tdb, off, rec, sizeof(*rec)) == -1) + return -1; + } + + if (rec->magic != TDB_FREE_MAGIC) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_CORRUPT; + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%d\n", + rec->magic, off)); + return TDB_ERRCODE(TDB_ERR_CORRUPT, -1); + } + if (tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0) != 0) + return -1; + return 0; +} + + + +/* Remove an element from the freelist. Must have alloc lock. */ +static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_t next) +{ + tdb_off_t last_ptr, i; + + /* read in the freelist top */ + last_ptr = FREELIST_TOP; + while (tdb_ofs_read(tdb, last_ptr, &i) != -1 && i != 0) { + if (i == off) { + /* We've found it! */ + return tdb_ofs_write(tdb, last_ptr, &next); + } + /* Follow chain (next offset is at start of record) */ + last_ptr = i; + } + TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%d\n", off)); + return TDB_ERRCODE(TDB_ERR_CORRUPT, -1); +} + + +/* update a record tailer (must hold allocation lock) */ +static int update_tailer(struct tdb_context *tdb, tdb_off_t offset, + const struct list_struct *rec) +{ + tdb_off_t totalsize; + + /* Offset of tailer from record header */ + totalsize = sizeof(*rec) + rec->rec_len; + return tdb_ofs_write(tdb, offset + totalsize - sizeof(tdb_off_t), + &totalsize); +} + +/* Add an element into the freelist. Merge adjacent records if + neccessary. */ +int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec) +{ + tdb_off_t right, left; + + /* Allocation and tailer lock */ + if (tdb_lock(tdb, -1, F_WRLCK) != 0) + return -1; + + /* set an initial tailer, so if we fail we don't leave a bogus record */ + if (update_tailer(tdb, offset, rec) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed!\n")); + goto fail; + } + + /* Look right first (I'm an Australian, dammit) */ + right = offset + sizeof(*rec) + rec->rec_len; + if (right + sizeof(*rec) <= tdb->map_size) { + struct list_struct r; + + if (tdb->methods->tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right read failed at %u\n", right)); + goto left; + } + + /* If it's free, expand to include it. */ + if (r.magic == TDB_FREE_MAGIC) { + if (remove_from_freelist(tdb, right, r.next) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right free failed at %u\n", right)); + goto left; + } + rec->rec_len += sizeof(r) + r.rec_len; + } + } + +left: + /* Look left */ + left = offset - sizeof(tdb_off_t); + if (left > TDB_DATA_START(tdb->header.hash_size)) { + struct list_struct l; + tdb_off_t leftsize; + + /* Read in tailer and jump back to header */ + if (tdb_ofs_read(tdb, left, &leftsize) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left offset read failed at %u\n", left)); + goto update; + } + + /* it could be uninitialised data */ + if (leftsize == 0 || leftsize == TDB_PAD_U32) { + goto update; + } + + left = offset - leftsize; + + /* Now read in record */ + if (tdb->methods->tdb_read(tdb, left, &l, sizeof(l), DOCONV()) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left read failed at %u (%u)\n", left, leftsize)); + goto update; + } + + /* If it's free, expand to include it. */ + if (l.magic == TDB_FREE_MAGIC) { + if (remove_from_freelist(tdb, left, l.next) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left free failed at %u\n", left)); + goto update; + } else { + offset = left; + rec->rec_len += leftsize; + } + } + } + +update: + if (update_tailer(tdb, offset, rec) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset)); + goto fail; + } + + /* Now, prepend to free list */ + rec->magic = TDB_FREE_MAGIC; + + if (tdb_ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 || + tdb_rec_write(tdb, offset, rec) == -1 || + tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%d\n", offset)); + goto fail; + } + + /* And we're done. */ + tdb_unlock(tdb, -1, F_WRLCK); + return 0; + + fail: + tdb_unlock(tdb, -1, F_WRLCK); + return -1; +} + + +/* + the core of tdb_allocate - called when we have decided which + free list entry to use + */ +static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb, tdb_len_t length, tdb_off_t rec_ptr, + struct list_struct *rec, tdb_off_t last_ptr) +{ + struct list_struct newrec; + tdb_off_t newrec_ptr; + + memset(&newrec, '\0', sizeof(newrec)); + + /* found it - now possibly split it up */ + if (rec->rec_len > length + MIN_REC_SIZE) { + /* Length of left piece */ + length = TDB_ALIGN(length, TDB_ALIGNMENT); + + /* Right piece to go on free list */ + newrec.rec_len = rec->rec_len - (sizeof(*rec) + length); + newrec_ptr = rec_ptr + sizeof(*rec) + length; + + /* And left record is shortened */ + rec->rec_len = length; + } else { + newrec_ptr = 0; + } + + /* Remove allocated record from the free list */ + if (tdb_ofs_write(tdb, last_ptr, &rec->next) == -1) { + return 0; + } + + /* Update header: do this before we drop alloc + lock, otherwise tdb_free() might try to + merge with us, thinking we're free. + (Thanks Jeremy Allison). */ + rec->magic = TDB_MAGIC; + if (tdb_rec_write(tdb, rec_ptr, rec) == -1) { + return 0; + } + + /* Did we create new block? */ + if (newrec_ptr) { + /* Update allocated record tailer (we + shortened it). */ + if (update_tailer(tdb, rec_ptr, rec) == -1) { + return 0; + } + + /* Free new record */ + if (tdb_free(tdb, newrec_ptr, &newrec) == -1) { + return 0; + } + } + + /* all done - return the new record offset */ + return rec_ptr; +} + +/* allocate some space from the free list. The offset returned points + to a unconnected list_struct within the database with room for at + least length bytes of total data + + 0 is returned if the space could not be allocated + */ +tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct list_struct *rec) +{ + tdb_off_t rec_ptr, last_ptr, newrec_ptr; + struct { + tdb_off_t rec_ptr, last_ptr; + tdb_len_t rec_len; + } bestfit; + + if (tdb_lock(tdb, -1, F_WRLCK) == -1) + return 0; + + /* Extra bytes required for tailer */ + length += sizeof(tdb_off_t); + + again: + last_ptr = FREELIST_TOP; + + /* read in the freelist top */ + if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1) + goto fail; + + bestfit.rec_ptr = 0; + bestfit.last_ptr = 0; + bestfit.rec_len = 0; + + /* + this is a best fit allocation strategy. Originally we used + a first fit strategy, but it suffered from massive fragmentation + issues when faced with a slowly increasing record size. + */ + while (rec_ptr) { + if (tdb_rec_free_read(tdb, rec_ptr, rec) == -1) { + goto fail; + } + + if (rec->rec_len >= length) { + if (bestfit.rec_ptr == 0 || + rec->rec_len < bestfit.rec_len) { + bestfit.rec_len = rec->rec_len; + bestfit.rec_ptr = rec_ptr; + bestfit.last_ptr = last_ptr; + /* consider a fit to be good enough if + we aren't wasting more than half + the space */ + if (bestfit.rec_len < 2*length) { + break; + } + } + } + + /* move to the next record */ + last_ptr = rec_ptr; + rec_ptr = rec->next; + } + + if (bestfit.rec_ptr != 0) { + if (tdb_rec_free_read(tdb, bestfit.rec_ptr, rec) == -1) { + goto fail; + } + + newrec_ptr = tdb_allocate_ofs(tdb, length, bestfit.rec_ptr, rec, bestfit.last_ptr); + tdb_unlock(tdb, -1, F_WRLCK); + return newrec_ptr; + } + + /* we didn't find enough space. See if we can expand the + database and if we can then try again */ + if (tdb_expand(tdb, length + sizeof(*rec)) == 0) + goto again; + fail: + tdb_unlock(tdb, -1, F_WRLCK); + return 0; +} + +/* file: freelistcheck.c */ + +/* Check the freelist is good and contains no loops. + Very memory intensive - only do this as a consistency + checker. Heh heh - uses an in memory tdb as the storage + for the "seen" record list. For some reason this strikes + me as extremely clever as I don't have to write another tree + data structure implementation :-). + */ + +static int seen_insert(struct tdb_context *mem_tdb, tdb_off_t rec_ptr) +{ + TDB_DATA key, data; + + memset(&data, '\0', sizeof(data)); + key.dptr = (unsigned char *)&rec_ptr; + key.dsize = sizeof(rec_ptr); + return tdb_store(mem_tdb, key, data, TDB_INSERT); +} + +int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries) +{ + struct tdb_context *mem_tdb = NULL; + struct list_struct rec; + tdb_off_t rec_ptr, last_ptr; + int ret = -1; + + *pnum_entries = 0; + + mem_tdb = tdb_open("flval", tdb->header.hash_size, + TDB_INTERNAL, O_RDWR, 0600); + if (!mem_tdb) { + return -1; + } + + if (tdb_lock(tdb, -1, F_WRLCK) == -1) { + tdb_close(mem_tdb); + return 0; + } + + last_ptr = FREELIST_TOP; + + /* Store the FREELIST_TOP record. */ + if (seen_insert(mem_tdb, last_ptr) == -1) { + ret = TDB_ERRCODE(TDB_ERR_CORRUPT, -1); + goto fail; + } + + /* read in the freelist top */ + if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1) { + goto fail; + } + + while (rec_ptr) { + + /* If we can't store this record (we've seen it + before) then the free list has a loop and must + be corrupt. */ + + if (seen_insert(mem_tdb, rec_ptr)) { + ret = TDB_ERRCODE(TDB_ERR_CORRUPT, -1); + goto fail; + } + + if (tdb_rec_free_read(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + + /* move to the next record */ + last_ptr = rec_ptr; + rec_ptr = rec.next; + *pnum_entries += 1; + } + + ret = 0; + + fail: + + tdb_close(mem_tdb); + tdb_unlock(tdb, -1, F_WRLCK); + return ret; +} + +/* file: traverse.c */ + +/* Uses traverse lock: 0 = finish, -1 = error, other = record offset */ +static int tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tlock, + struct list_struct *rec) +{ + int want_next = (tlock->off != 0); + + /* Lock each chain from the start one. */ + for (; tlock->hash < tdb->header.hash_size; tlock->hash++) { + if (!tlock->off && tlock->hash != 0) { + /* this is an optimisation for the common case where + the hash chain is empty, which is particularly + common for the use of tdb with ldb, where large + hashes are used. In that case we spend most of our + time in tdb_brlock(), locking empty hash chains. + + To avoid this, we do an unlocked pre-check to see + if the hash chain is empty before starting to look + inside it. If it is empty then we can avoid that + hash chain. If it isn't empty then we can't believe + the value we get back, as we read it without a + lock, so instead we get the lock and re-fetch the + value below. + + Notice that not doing this optimisation on the + first hash chain is critical. We must guarantee + that we have done at least one fcntl lock at the + start of a search to guarantee that memory is + coherent on SMP systems. If records are added by + others during the search then thats OK, and we + could possibly miss those with this trick, but we + could miss them anyway without this trick, so the + semantics don't change. + + With a non-indexed ldb search this trick gains us a + factor of around 80 in speed on a linux 2.6.x + system (testing using ldbtest). + */ + tdb->methods->next_hash_chain(tdb, &tlock->hash); + if (tlock->hash == tdb->header.hash_size) { + continue; + } + } + + if (tdb_lock(tdb, tlock->hash, tlock->lock_rw) == -1) + return -1; + + /* No previous record? Start at top of chain. */ + if (!tlock->off) { + if (tdb_ofs_read(tdb, TDB_HASH_TOP(tlock->hash), + &tlock->off) == -1) + goto fail; + } else { + /* Otherwise unlock the previous record. */ + if (tdb_unlock_record(tdb, tlock->off) != 0) + goto fail; + } + + if (want_next) { + /* We have offset of old record: grab next */ + if (tdb_rec_read(tdb, tlock->off, rec) == -1) + goto fail; + tlock->off = rec->next; + } + + /* Iterate through chain */ + while( tlock->off) { + tdb_off_t current; + if (tdb_rec_read(tdb, tlock->off, rec) == -1) + goto fail; + + /* Detect infinite loops. From "Shlomi Yaakobovich" . */ + if (tlock->off == rec->next) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_next_lock: loop detected.\n")); + goto fail; + } + + if (!TDB_DEAD(rec)) { + /* Woohoo: we found one! */ + if (tdb_lock_record(tdb, tlock->off) != 0) + goto fail; + return tlock->off; + } + + /* Try to clean dead ones from old traverses */ + current = tlock->off; + tlock->off = rec->next; + if (!(tdb->read_only || tdb->traverse_read) && + tdb_do_delete(tdb, current, rec) != 0) + goto fail; + } + tdb_unlock(tdb, tlock->hash, tlock->lock_rw); + want_next = 0; + } + /* We finished iteration without finding anything */ + return TDB_ERRCODE(TDB_SUCCESS, 0); + + fail: + tlock->off = 0; + if (tdb_unlock(tdb, tlock->hash, tlock->lock_rw) != 0) + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_next_lock: On error unlock failed!\n")); + return -1; +} + +/* traverse the entire database - calling fn(tdb, key, data) on each element. + return -1 on error or the record count traversed + if fn is NULL then it is not called + a non-zero return value from fn() indicates that the traversal should stop + */ +static int tdb_traverse_internal(struct tdb_context *tdb, + tdb_traverse_func fn, void *private_data, + struct tdb_traverse_lock *tl) +{ + TDB_DATA key, dbuf; + struct list_struct rec; + int ret, count = 0; + + /* This was in the initializaton, above, but the IRIX compiler + * did not like it. crh + */ + tl->next = tdb->travlocks.next; + + /* fcntl locks don't stack: beware traverse inside traverse */ + tdb->travlocks.next = tl; + + /* tdb_next_lock places locks on the record returned, and its chain */ + while ((ret = tdb_next_lock(tdb, tl, &rec)) > 0) { + count++; + /* now read the full record */ + key.dptr = tdb_alloc_read(tdb, tl->off + sizeof(rec), + rec.key_len + rec.data_len); + if (!key.dptr) { + ret = -1; + if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) + goto out; + if (tdb_unlock_record(tdb, tl->off) != 0) + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: key.dptr == NULL and unlock_record failed!\n")); + goto out; + } + key.dsize = rec.key_len; + dbuf.dptr = key.dptr + rec.key_len; + dbuf.dsize = rec.data_len; + + /* Drop chain lock, call out */ + if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) { + ret = -1; + SAFE_FREE(key.dptr); + goto out; + } + if (fn && fn(tdb, key, dbuf, private_data)) { + /* They want us to terminate traversal */ + ret = count; + if (tdb_unlock_record(tdb, tl->off) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: unlock_record failed!\n"));; + ret = -1; + } + SAFE_FREE(key.dptr); + goto out; + } + SAFE_FREE(key.dptr); + } +out: + tdb->travlocks.next = tl->next; + if (ret < 0) + return -1; + else + return count; +} + + +/* + a write style traverse - temporarily marks the db read only +*/ +int tdb_traverse_read(struct tdb_context *tdb, + tdb_traverse_func fn, void *private_data) +{ + struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK }; + int ret; + + /* we need to get a read lock on the transaction lock here to + cope with the lock ordering semantics of solaris10 */ + if (tdb_transaction_lock(tdb, F_RDLCK)) { + return -1; + } + + tdb->traverse_read++; + ret = tdb_traverse_internal(tdb, fn, private_data, &tl); + tdb->traverse_read--; + + tdb_transaction_unlock(tdb); + + return ret; +} + +/* + a write style traverse - needs to get the transaction lock to + prevent deadlocks +*/ +int tdb_traverse(struct tdb_context *tdb, + tdb_traverse_func fn, void *private_data) +{ + struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK }; + int ret; + + if (tdb->read_only || tdb->traverse_read) { + return tdb_traverse_read(tdb, fn, private_data); + } + + if (tdb_transaction_lock(tdb, F_WRLCK)) { + return -1; + } + + ret = tdb_traverse_internal(tdb, fn, private_data, &tl); + + tdb_transaction_unlock(tdb); + + return ret; +} + + +/* find the first entry in the database and return its key */ +TDB_DATA tdb_firstkey(struct tdb_context *tdb) +{ + TDB_DATA key; + struct list_struct rec; + + /* release any old lock */ + if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0) + return tdb_null; + tdb->travlocks.off = tdb->travlocks.hash = 0; + tdb->travlocks.lock_rw = F_RDLCK; + + /* Grab first record: locks chain and returned record. */ + if (tdb_next_lock(tdb, &tdb->travlocks, &rec) <= 0) + return tdb_null; + /* now read the key */ + key.dsize = rec.key_len; + key.dptr =tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),key.dsize); + + /* Unlock the hash chain of the record we just read. */ + if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_firstkey: error occurred while tdb_unlocking!\n")); + return key; +} + +/* find the next entry in the database, returning its key */ +TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey) +{ + u32 oldhash; + TDB_DATA key = tdb_null; + struct list_struct rec; + unsigned char *k = NULL; + + /* Is locked key the old key? If so, traverse will be reliable. */ + if (tdb->travlocks.off) { + if (tdb_lock(tdb,tdb->travlocks.hash,tdb->travlocks.lock_rw)) + return tdb_null; + if (tdb_rec_read(tdb, tdb->travlocks.off, &rec) == -1 + || !(k = tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec), + rec.key_len)) + || memcmp(k, oldkey.dptr, oldkey.dsize) != 0) { + /* No, it wasn't: unlock it and start from scratch */ + if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0) { + SAFE_FREE(k); + return tdb_null; + } + if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) { + SAFE_FREE(k); + return tdb_null; + } + tdb->travlocks.off = 0; + } + + SAFE_FREE(k); + } + + if (!tdb->travlocks.off) { + /* No previous element: do normal find, and lock record */ + tdb->travlocks.off = tdb_find_lock_hash(tdb, oldkey, tdb->hash_fn(&oldkey), tdb->travlocks.lock_rw, &rec); + if (!tdb->travlocks.off) + return tdb_null; + tdb->travlocks.hash = BUCKET(rec.full_hash); + if (tdb_lock_record(tdb, tdb->travlocks.off) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: lock_record failed (%s)!\n", strerror(errno))); + return tdb_null; + } + } + oldhash = tdb->travlocks.hash; + + /* Grab next record: locks chain and returned record, + unlocks old record */ + if (tdb_next_lock(tdb, &tdb->travlocks, &rec) > 0) { + key.dsize = rec.key_len; + key.dptr = tdb_alloc_read(tdb, tdb->travlocks.off+sizeof(rec), + key.dsize); + /* Unlock the chain of this new record */ + if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n")); + } + /* Unlock the chain of old record */ + if (tdb_unlock(tdb, BUCKET(oldhash), tdb->travlocks.lock_rw) != 0) + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n")); + return key; +} + +/* file: dump.c */ + +static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash, + tdb_off_t offset) +{ + struct list_struct rec; + tdb_off_t tailer_ofs, tailer; + + if (tdb->methods->tdb_read(tdb, offset, (char *)&rec, + sizeof(rec), DOCONV()) == -1) { + printf("ERROR: failed to read record at %u\n", offset); + return 0; + } + + printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d " + "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n", + hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len, + rec.full_hash, rec.magic); + + tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off_t); + + if (tdb_ofs_read(tdb, tailer_ofs, &tailer) == -1) { + printf("ERROR: failed to read tailer at %u\n", tailer_ofs); + return rec.next; + } + + if (tailer != rec.rec_len + sizeof(rec)) { + printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n", + (unsigned int)tailer, (unsigned int)(rec.rec_len + sizeof(rec))); + } + return rec.next; +} + +static int tdb_dump_chain(struct tdb_context *tdb, int i) +{ + tdb_off_t rec_ptr, top; + + top = TDB_HASH_TOP(i); + + if (tdb_lock(tdb, i, F_WRLCK) != 0) + return -1; + + if (tdb_ofs_read(tdb, top, &rec_ptr) == -1) + return tdb_unlock(tdb, i, F_WRLCK); + + if (rec_ptr) + printf("hash=%d\n", i); + + while (rec_ptr) { + rec_ptr = tdb_dump_record(tdb, i, rec_ptr); + } + + return tdb_unlock(tdb, i, F_WRLCK); +} + +void tdb_dump_all(struct tdb_context *tdb) +{ + int i; + for (i=0;iheader.hash_size;i++) { + tdb_dump_chain(tdb, i); + } + printf("freelist:\n"); + tdb_dump_chain(tdb, -1); +} + +int tdb_printfreelist(struct tdb_context *tdb) +{ + int ret; + long total_free = 0; + tdb_off_t offset, rec_ptr; + struct list_struct rec; + + if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0) + return ret; + + offset = FREELIST_TOP; + + /* read in the freelist top */ + if (tdb_ofs_read(tdb, offset, &rec_ptr) == -1) { + tdb_unlock(tdb, -1, F_WRLCK); + return 0; + } + + printf("freelist top=[0x%08x]\n", rec_ptr ); + while (rec_ptr) { + if (tdb->methods->tdb_read(tdb, rec_ptr, (char *)&rec, + sizeof(rec), DOCONV()) == -1) { + tdb_unlock(tdb, -1, F_WRLCK); + return -1; + } + + if (rec.magic != TDB_FREE_MAGIC) { + printf("bad magic 0x%08x in free list\n", rec.magic); + tdb_unlock(tdb, -1, F_WRLCK); + return -1; + } + + printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n", + rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len); + total_free += rec.rec_len; + + /* move to the next record */ + rec_ptr = rec.next; + } + printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, + (int)total_free); + + return tdb_unlock(tdb, -1, F_WRLCK); +} + +/* file: tdb.c */ + +TDB_DATA tdb_null; + +/* + non-blocking increment of the tdb sequence number if the tdb has been opened using + the TDB_SEQNUM flag +*/ +void tdb_increment_seqnum_nonblock(struct tdb_context *tdb) +{ + tdb_off_t seqnum=0; + + if (!(tdb->flags & TDB_SEQNUM)) { + return; + } + + /* we ignore errors from this, as we have no sane way of + dealing with them. + */ + tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum); + seqnum++; + tdb_ofs_write(tdb, TDB_SEQNUM_OFS, &seqnum); +} + +/* + increment the tdb sequence number if the tdb has been opened using + the TDB_SEQNUM flag +*/ +static void tdb_increment_seqnum(struct tdb_context *tdb) +{ + if (!(tdb->flags & TDB_SEQNUM)) { + return; + } + + if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) { + return; + } + + tdb_increment_seqnum_nonblock(tdb); + + tdb_brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1); +} + +static int tdb_key_compare(TDB_DATA key, TDB_DATA data, void *private_data) +{ + return memcmp(data.dptr, key.dptr, data.dsize); +} + +/* Returns 0 on fail. On success, return offset of record, and fills + in rec */ +static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, u32 hash, + struct list_struct *r) +{ + tdb_off_t rec_ptr; + + /* read in the hash top */ + if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) + return 0; + + /* keep looking until we find the right record */ + while (rec_ptr) { + if (tdb_rec_read(tdb, rec_ptr, r) == -1) + return 0; + + if (!TDB_DEAD(r) && hash==r->full_hash + && key.dsize==r->key_len + && tdb_parse_data(tdb, key, rec_ptr + sizeof(*r), + r->key_len, tdb_key_compare, + NULL) == 0) { + return rec_ptr; + } + rec_ptr = r->next; + } + return TDB_ERRCODE(TDB_ERR_NOEXIST, 0); +} + +/* As tdb_find, but if you succeed, keep the lock */ +tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, int locktype, + struct list_struct *rec) +{ + u32 rec_ptr; + + if (tdb_lock(tdb, BUCKET(hash), locktype) == -1) + return 0; + if (!(rec_ptr = tdb_find(tdb, key, hash, rec))) + tdb_unlock(tdb, BUCKET(hash), locktype); + return rec_ptr; +} + + +/* update an entry in place - this only works if the new data size + is <= the old data size and the key exists. + on failure return -1. +*/ +static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, TDB_DATA dbuf) +{ + struct list_struct rec; + tdb_off_t rec_ptr; + + /* find entry */ + if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) + return -1; + + /* must be long enough key, data and tailer */ + if (rec.rec_len < key.dsize + dbuf.dsize + sizeof(tdb_off_t)) { + tdb->ecode = TDB_SUCCESS; /* Not really an error */ + return -1; + } + + if (tdb->methods->tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len, + dbuf.dptr, dbuf.dsize) == -1) + return -1; + + if (dbuf.dsize != rec.data_len) { + /* update size */ + rec.data_len = dbuf.dsize; + return tdb_rec_write(tdb, rec_ptr, &rec); + } + + return 0; +} + +/* find an entry in the database given a key */ +/* If an entry doesn't exist tdb_err will be set to + * TDB_ERR_NOEXIST. If a key has no data attached + * then the TDB_DATA will have zero length but + * a non-zero pointer + */ +TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key) +{ + tdb_off_t rec_ptr; + struct list_struct rec; + TDB_DATA ret; + u32 hash; + + /* find which hash bucket it is in */ + hash = tdb->hash_fn(&key); + if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) + return tdb_null; + + ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len, + rec.data_len); + ret.dsize = rec.data_len; + tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); + return ret; +} + +/* + * Find an entry in the database and hand the record's data to a parsing + * function. The parsing function is executed under the chain read lock, so it + * should be fast and should not block on other syscalls. + * + * DONT CALL OTHER TDB CALLS FROM THE PARSER, THIS MIGHT LEAD TO SEGFAULTS. + * + * For mmapped tdb's that do not have a transaction open it points the parsing + * function directly at the mmap area, it avoids the malloc/memcpy in this + * case. If a transaction is open or no mmap is available, it has to do + * malloc/read/parse/free. + * + * This is interesting for all readers of potentially large data structures in + * the tdb records, ldb indexes being one example. + */ + +int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, + int (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data) +{ + tdb_off_t rec_ptr; + struct list_struct rec; + int ret; + u32 hash; + + /* find which hash bucket it is in */ + hash = tdb->hash_fn(&key); + + if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) { + return TDB_ERRCODE(TDB_ERR_NOEXIST, 0); + } + + ret = tdb_parse_data(tdb, key, rec_ptr + sizeof(rec) + rec.key_len, + rec.data_len, parser, private_data); + + tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); + + return ret; +} + +/* check if an entry in the database exists + + note that 1 is returned if the key is found and 0 is returned if not found + this doesn't match the conventions in the rest of this module, but is + compatible with gdbm +*/ +static int tdb_exists_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash) +{ + struct list_struct rec; + + if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0) + return 0; + tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); + return 1; +} + +int tdb_exists(struct tdb_context *tdb, TDB_DATA key) +{ + u32 hash = tdb->hash_fn(&key); + return tdb_exists_hash(tdb, key, hash); +} + +/* actually delete an entry in the database given the offset */ +int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct*rec) +{ + tdb_off_t last_ptr, i; + struct list_struct lastrec; + + if (tdb->read_only || tdb->traverse_read) return -1; + + if (tdb_write_lock_record(tdb, rec_ptr) == -1) { + /* Someone traversing here: mark it as dead */ + rec->magic = TDB_DEAD_MAGIC; + return tdb_rec_write(tdb, rec_ptr, rec); + } + if (tdb_write_unlock_record(tdb, rec_ptr) != 0) + return -1; + + /* find previous record in hash chain */ + if (tdb_ofs_read(tdb, TDB_HASH_TOP(rec->full_hash), &i) == -1) + return -1; + for (last_ptr = 0; i != rec_ptr; last_ptr = i, i = lastrec.next) + if (tdb_rec_read(tdb, i, &lastrec) == -1) + return -1; + + /* unlink it: next ptr is at start of record. */ + if (last_ptr == 0) + last_ptr = TDB_HASH_TOP(rec->full_hash); + if (tdb_ofs_write(tdb, last_ptr, &rec->next) == -1) + return -1; + + /* recover the space */ + if (tdb_free(tdb, rec_ptr, rec) == -1) + return -1; + return 0; +} + +static int tdb_count_dead(struct tdb_context *tdb, u32 hash) +{ + int res = 0; + tdb_off_t rec_ptr; + struct list_struct rec; + + /* read in the hash top */ + if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) + return 0; + + while (rec_ptr) { + if (tdb_rec_read(tdb, rec_ptr, &rec) == -1) + return 0; + + if (rec.magic == TDB_DEAD_MAGIC) { + res += 1; + } + rec_ptr = rec.next; + } + return res; +} + +/* + * Purge all DEAD records from a hash chain + */ +static int tdb_purge_dead(struct tdb_context *tdb, u32 hash) +{ + int res = -1; + struct list_struct rec; + tdb_off_t rec_ptr; + + if (tdb_lock(tdb, -1, F_WRLCK) == -1) { + return -1; + } + + /* read in the hash top */ + if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) + goto fail; + + while (rec_ptr) { + tdb_off_t next; + + if (tdb_rec_read(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + + next = rec.next; + + if (rec.magic == TDB_DEAD_MAGIC + && tdb_do_delete(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + rec_ptr = next; + } + res = 0; + fail: + tdb_unlock(tdb, -1, F_WRLCK); + return res; +} + +/* delete an entry in the database given a key */ +static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash) +{ + tdb_off_t rec_ptr; + struct list_struct rec; + int ret; + + if (tdb->max_dead_records != 0) { + + /* + * Allow for some dead records per hash chain, mainly for + * tdb's with a very high create/delete rate like locking.tdb. + */ + + if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1) + return -1; + + if (tdb_count_dead(tdb, hash) >= tdb->max_dead_records) { + /* + * Don't let the per-chain freelist grow too large, + * delete all existing dead records + */ + tdb_purge_dead(tdb, hash); + } + + if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) { + tdb_unlock(tdb, BUCKET(hash), F_WRLCK); + return -1; + } + + /* + * Just mark the record as dead. + */ + rec.magic = TDB_DEAD_MAGIC; + ret = tdb_rec_write(tdb, rec_ptr, &rec); + } + else { + if (!(rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK, + &rec))) + return -1; + + ret = tdb_do_delete(tdb, rec_ptr, &rec); + } + + if (ret == 0) { + tdb_increment_seqnum(tdb); + } + + if (tdb_unlock(tdb, BUCKET(rec.full_hash), F_WRLCK) != 0) + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_delete: WARNING tdb_unlock failed!\n")); + return ret; +} + +int tdb_delete(struct tdb_context *tdb, TDB_DATA key) +{ + u32 hash = tdb->hash_fn(&key); + return tdb_delete_hash(tdb, key, hash); +} + +/* + * See if we have a dead record around with enough space + */ +static tdb_off_t tdb_find_dead(struct tdb_context *tdb, u32 hash, + struct list_struct *r, tdb_len_t length) +{ + tdb_off_t rec_ptr; + + /* read in the hash top */ + if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) + return 0; + + /* keep looking until we find the right record */ + while (rec_ptr) { + if (tdb_rec_read(tdb, rec_ptr, r) == -1) + return 0; + + if (TDB_DEAD(r) && r->rec_len >= length) { + /* + * First fit for simple coding, TODO: change to best + * fit + */ + return rec_ptr; + } + rec_ptr = r->next; + } + return 0; +} + +/* store an element in the database, replacing any existing element + with the same key + + return 0 on success, -1 on failure +*/ +int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) +{ + struct list_struct rec; + u32 hash; + tdb_off_t rec_ptr; + char *p = NULL; + int ret = -1; + + if (tdb->read_only || tdb->traverse_read) { + tdb->ecode = TDB_ERR_RDONLY; + return -1; + } + + /* find which hash bucket it is in */ + hash = tdb->hash_fn(&key); + if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1) + return -1; + + /* check for it existing, on insert. */ + if (flag == TDB_INSERT) { + if (tdb_exists_hash(tdb, key, hash)) { + tdb->ecode = TDB_ERR_EXISTS; + goto fail; + } + } else { + /* first try in-place update, on modify or replace. */ + if (tdb_update_hash(tdb, key, hash, dbuf) == 0) { + goto done; + } + if (tdb->ecode == TDB_ERR_NOEXIST && + flag == TDB_MODIFY) { + /* if the record doesn't exist and we are in TDB_MODIFY mode then + we should fail the store */ + goto fail; + } + } + /* reset the error code potentially set by the tdb_update() */ + tdb->ecode = TDB_SUCCESS; + + /* delete any existing record - if it doesn't exist we don't + care. Doing this first reduces fragmentation, and avoids + coalescing with `allocated' block before it's updated. */ + if (flag != TDB_INSERT) + tdb_delete_hash(tdb, key, hash); + + /* Copy key+value *before* allocating free space in case malloc + fails and we are left with a dead spot in the tdb. */ + + if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) { + tdb->ecode = TDB_ERR_OOM; + goto fail; + } + + memcpy(p, key.dptr, key.dsize); + if (dbuf.dsize) + memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize); + + if (tdb->max_dead_records != 0) { + /* + * Allow for some dead records per hash chain, look if we can + * find one that can hold the new record. We need enough space + * for key, data and tailer. If we find one, we don't have to + * consult the central freelist. + */ + rec_ptr = tdb_find_dead( + tdb, hash, &rec, + key.dsize + dbuf.dsize + sizeof(tdb_off_t)); + + if (rec_ptr != 0) { + rec.key_len = key.dsize; + rec.data_len = dbuf.dsize; + rec.full_hash = hash; + rec.magic = TDB_MAGIC; + if (tdb_rec_write(tdb, rec_ptr, &rec) == -1 + || tdb->methods->tdb_write( + tdb, rec_ptr + sizeof(rec), + p, key.dsize + dbuf.dsize) == -1) { + goto fail; + } + goto done; + } + } + + /* + * We have to allocate some space from the freelist, so this means we + * have to lock it. Use the chance to purge all the DEAD records from + * the hash chain under the freelist lock. + */ + + if (tdb_lock(tdb, -1, F_WRLCK) == -1) { + goto fail; + } + + if ((tdb->max_dead_records != 0) + && (tdb_purge_dead(tdb, hash) == -1)) { + tdb_unlock(tdb, -1, F_WRLCK); + goto fail; + } + + /* we have to allocate some space */ + rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize, &rec); + + tdb_unlock(tdb, -1, F_WRLCK); + + if (rec_ptr == 0) { + goto fail; + } + + /* Read hash top into next ptr */ + if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1) + goto fail; + + rec.key_len = key.dsize; + rec.data_len = dbuf.dsize; + rec.full_hash = hash; + rec.magic = TDB_MAGIC; + + /* write out and point the top of the hash chain at it */ + if (tdb_rec_write(tdb, rec_ptr, &rec) == -1 + || tdb->methods->tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1 + || tdb_ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) { + /* Need to tdb_unallocate() here */ + goto fail; + } + + done: + ret = 0; + fail: + if (ret == 0) { + tdb_increment_seqnum(tdb); + } + + SAFE_FREE(p); + tdb_unlock(tdb, BUCKET(hash), F_WRLCK); + return ret; +} + + +/* Append to an entry. Create if not exist. */ +int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf) +{ + u32 hash; + TDB_DATA dbuf; + int ret = -1; + + /* find which hash bucket it is in */ + hash = tdb->hash_fn(&key); + if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1) + return -1; + + dbuf = tdb_fetch(tdb, key); + + if (dbuf.dptr == NULL) { + dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize); + } else { + unsigned char *new_dptr = (unsigned char *)realloc(dbuf.dptr, + dbuf.dsize + new_dbuf.dsize); + if (new_dptr == NULL) { + free(dbuf.dptr); + } + dbuf.dptr = new_dptr; + } + + if (dbuf.dptr == NULL) { + tdb->ecode = TDB_ERR_OOM; + goto failed; + } + + memcpy(dbuf.dptr + dbuf.dsize, new_dbuf.dptr, new_dbuf.dsize); + dbuf.dsize += new_dbuf.dsize; + + ret = tdb_store(tdb, key, dbuf, 0); + +failed: + tdb_unlock(tdb, BUCKET(hash), F_WRLCK); + SAFE_FREE(dbuf.dptr); + return ret; +} + + +/* + return the name of the current tdb file + useful for external logging functions +*/ +const char *tdb_name(struct tdb_context *tdb) +{ + return tdb->name; +} + +/* + return the underlying file descriptor being used by tdb, or -1 + useful for external routines that want to check the device/inode + of the fd +*/ +int tdb_fd(struct tdb_context *tdb) +{ + return tdb->fd; +} + +/* + return the current logging function + useful for external tdb routines that wish to log tdb errors +*/ +tdb_log_func tdb_log_fn(struct tdb_context *tdb) +{ + return tdb->log.log_fn; +} + + +/* + get the tdb sequence number. Only makes sense if the writers opened + with TDB_SEQNUM set. Note that this sequence number will wrap quite + quickly, so it should only be used for a 'has something changed' + test, not for code that relies on the count of the number of changes + made. If you want a counter then use a tdb record. + + The aim of this sequence number is to allow for a very lightweight + test of a possible tdb change. +*/ +int tdb_get_seqnum(struct tdb_context *tdb) +{ + tdb_off_t seqnum=0; + + tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum); + return seqnum; +} + +int tdb_hash_size(struct tdb_context *tdb) +{ + return tdb->header.hash_size; +} + +size_t tdb_map_size(struct tdb_context *tdb) +{ + return tdb->map_size; +} + +int tdb_get_flags(struct tdb_context *tdb) +{ + return tdb->flags; +} + + +/* + enable sequence number handling on an open tdb +*/ +void tdb_enable_seqnum(struct tdb_context *tdb) +{ + tdb->flags |= TDB_SEQNUM; +} + +/* file: open.c */ + +/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */ +static struct tdb_context *tdbs = NULL; + + +/* This is based on the hash algorithm from gdbm */ +static unsigned int default_tdb_hash(TDB_DATA *key) +{ + u32 value; /* Used to compute the hash value. */ + u32 i; /* Used to cycle through random values. */ + + /* Set the initial value from the key size. */ + for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++) + value = (value + (key->dptr[i] << (i*5 % 24))); + + return (1103515243 * value + 12345); +} + + +/* initialise a new database with a specified hash size */ +static int tdb_new_database(struct tdb_context *tdb, int hash_size) +{ + struct tdb_header *newdb; + int size, ret = -1; + + /* We make it up in memory, then write it out if not internal */ + size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off_t); + if (!(newdb = (struct tdb_header *)calloc(size, 1))) + return TDB_ERRCODE(TDB_ERR_OOM, -1); + + /* Fill in the header */ + newdb->version = TDB_VERSION; + newdb->hash_size = hash_size; + if (tdb->flags & TDB_INTERNAL) { + tdb->map_size = size; + tdb->map_ptr = (char *)newdb; + memcpy(&tdb->header, newdb, sizeof(tdb->header)); + /* Convert the `ondisk' version if asked. */ + CONVERT(*newdb); + return 0; + } + if (lseek(tdb->fd, 0, SEEK_SET) == -1) + goto fail; + + if (ftruncate(tdb->fd, 0) == -1) + goto fail; + + /* This creates an endian-converted header, as if read from disk */ + CONVERT(*newdb); + memcpy(&tdb->header, newdb, sizeof(tdb->header)); + /* Don't endian-convert the magic food! */ + memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1); + if (write(tdb->fd, newdb, size) != size) { + ret = -1; + } else { + ret = 0; + } + + fail: + SAFE_FREE(newdb); + return ret; +} + + + +static int tdb_already_open(dev_t device, + ino_t ino) +{ + struct tdb_context *i; + + for (i = tdbs; i; i = i->next) { + if (i->device == device && i->inode == ino) { + return 1; + } + } + + return 0; +} + +/* open the database, creating it if necessary + + The open_flags and mode are passed straight to the open call on the + database file. A flags value of O_WRONLY is invalid. The hash size + is advisory, use zero for a default value. + + Return is NULL on error, in which case errno is also set. Don't + try to call tdb_error or tdb_errname, just do strerror(errno). + + @param name may be NULL for internal databases. */ +struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode) +{ + return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL); +} + +/* a default logging function */ +static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); +static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) +{ +} + + +struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode, + const struct tdb_logging_context *log_ctx, + tdb_hash_func hash_fn) +{ + struct tdb_context *tdb; + struct stat st; + int rev = 0, locked = 0; + unsigned char *vp; + u32 vertest; + + if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) { + /* Can't log this */ + errno = ENOMEM; + goto fail; + } + tdb_io_init(tdb); + tdb->fd = -1; + tdb->name = NULL; + tdb->map_ptr = NULL; + tdb->flags = tdb_flags; + tdb->open_flags = open_flags; + if (log_ctx) { + tdb->log = *log_ctx; + } else { + tdb->log.log_fn = null_log_fn; + tdb->log.log_private = NULL; + } + tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; + + /* cache the page size */ + tdb->page_size = getpagesize(); + if (tdb->page_size <= 0) { + tdb->page_size = 0x2000; + } + + if ((open_flags & O_ACCMODE) == O_WRONLY) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't open tdb %s write-only\n", + name)); + errno = EINVAL; + goto fail; + } + + if (hash_size == 0) + hash_size = DEFAULT_HASH_SIZE; + if ((open_flags & O_ACCMODE) == O_RDONLY) { + tdb->read_only = 1; + /* read only databases don't do locking or clear if first */ + tdb->flags |= TDB_NOLOCK; + tdb->flags &= ~TDB_CLEAR_IF_FIRST; + } + + /* internal databases don't mmap or lock, and start off cleared */ + if (tdb->flags & TDB_INTERNAL) { + tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP); + tdb->flags &= ~TDB_CLEAR_IF_FIRST; + if (tdb_new_database(tdb, hash_size) != 0) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!")); + goto fail; + } + goto internal; + } + + if ((tdb->fd = open(name, open_flags, mode)) == -1) { + TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_open_ex: could not open file %s: %s\n", + name, strerror(errno))); + goto fail; /* errno set by open(2) */ + } + + /* ensure there is only one process initialising at once */ + if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_WRLCK, F_SETLKW, 0, 1) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to get global lock on %s: %s\n", + name, strerror(errno))); + goto fail; /* errno set by tdb_brlock */ + } + + /* we need to zero database if we are the only one with it open */ + if ((tdb_flags & TDB_CLEAR_IF_FIRST) && + (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))) { + open_flags |= O_CREAT; + if (ftruncate(tdb->fd, 0) == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " + "failed to truncate %s: %s\n", + name, strerror(errno))); + goto fail; /* errno set by ftruncate */ + } + } + + if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header) + || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0 + || (tdb->header.version != TDB_VERSION + && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION))))) { + /* its not a valid database - possibly initialise it */ + if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) { + errno = EIO; /* ie bad format or something */ + goto fail; + } + rev = (tdb->flags & TDB_CONVERT); + } + vp = (unsigned char *)&tdb->header.version; + vertest = (((u32)vp[0]) << 24) | (((u32)vp[1]) << 16) | + (((u32)vp[2]) << 8) | (u32)vp[3]; + tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0; + if (!rev) + tdb->flags &= ~TDB_CONVERT; + else { + tdb->flags |= TDB_CONVERT; + tdb_convert(&tdb->header, sizeof(tdb->header)); + } + if (fstat(tdb->fd, &st) == -1) + goto fail; + + if (tdb->header.rwlocks != 0) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: spinlocks no longer supported\n")); + goto fail; + } + + /* Is it already in the open list? If so, fail. */ + if (tdb_already_open(st.st_dev, st.st_ino)) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: " + "%s (%d,%d) is already open in this process\n", + name, (int)st.st_dev, (int)st.st_ino)); + errno = EBUSY; + goto fail; + } + + if (!(tdb->name = (char *)strdup(name))) { + errno = ENOMEM; + goto fail; + } + + tdb->map_size = st.st_size; + tdb->device = st.st_dev; + tdb->inode = st.st_ino; + tdb->max_dead_records = 0; + tdb_mmap(tdb); + if (locked) { + if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: " + "failed to take ACTIVE_LOCK on %s: %s\n", + name, strerror(errno))); + goto fail; + } + + } + + /* We always need to do this if the CLEAR_IF_FIRST flag is set, even if + we didn't get the initial exclusive lock as we need to let all other + users know we're using it. */ + + if (tdb_flags & TDB_CLEAR_IF_FIRST) { + /* leave this lock in place to indicate it's in use */ + if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1) + goto fail; + } + + /* if needed, run recovery */ + if (tdb_transaction_recover(tdb) == -1) { + goto fail; + } + + internal: + /* Internal (memory-only) databases skip all the code above to + * do with disk files, and resume here by releasing their + * global lock and hooking into the active list. */ + if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1) + goto fail; + tdb->next = tdbs; + tdbs = tdb; + return tdb; + + fail: + { int save_errno = errno; + + if (!tdb) + return NULL; + + if (tdb->map_ptr) { + if (tdb->flags & TDB_INTERNAL) + SAFE_FREE(tdb->map_ptr); + else + tdb_munmap(tdb); + } + SAFE_FREE(tdb->name); + if (tdb->fd != -1) + if (close(tdb->fd) != 0) + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to close tdb->fd on error!\n")); + SAFE_FREE(tdb); + errno = save_errno; + return NULL; + } +} + +/* + * Set the maximum number of dead records per hash chain + */ + +void tdb_set_max_dead(struct tdb_context *tdb, int max_dead) +{ + tdb->max_dead_records = max_dead; +} + +/** + * Close a database. + * + * @returns -1 for error; 0 for success. + **/ +int tdb_close(struct tdb_context *tdb) +{ + struct tdb_context **i; + int ret = 0; + + if (tdb->transaction) { + tdb_transaction_cancel(tdb); + } + + if (tdb->map_ptr) { + if (tdb->flags & TDB_INTERNAL) + SAFE_FREE(tdb->map_ptr); + else + tdb_munmap(tdb); + } + SAFE_FREE(tdb->name); + if (tdb->fd != -1) + ret = close(tdb->fd); + SAFE_FREE(tdb->lockrecs); + + /* Remove from contexts list */ + for (i = &tdbs; *i; i = &(*i)->next) { + if (*i == tdb) { + *i = tdb->next; + break; + } + } + + memset(tdb, 0, sizeof(*tdb)); + SAFE_FREE(tdb); + + return ret; +} + +/* register a loging function */ +void tdb_set_logging_function(struct tdb_context *tdb, + const struct tdb_logging_context *log_ctx) +{ + tdb->log = *log_ctx; +} + +void *tdb_get_logging_private(struct tdb_context *tdb) +{ + return tdb->log.log_private; +} + +/* reopen a tdb - this can be used after a fork to ensure that we have an independent + seek pointer from our parent and to re-establish locks */ +int tdb_reopen(struct tdb_context *tdb) +{ + struct stat st; + + if (tdb->flags & TDB_INTERNAL) { + return 0; /* Nothing to do. */ + } + + if (tdb->num_locks != 0 || tdb->global_lock.count) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed with locks held\n")); + goto fail; + } + + if (tdb->transaction != 0) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed inside a transaction\n")); + goto fail; + } + + if (tdb_munmap(tdb) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: munmap failed (%s)\n", strerror(errno))); + goto fail; + } + if (close(tdb->fd) != 0) + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: WARNING closing tdb->fd failed!\n")); + tdb->fd = open(tdb->name, tdb->open_flags & ~(O_CREAT|O_TRUNC), 0); + if (tdb->fd == -1) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: open failed (%s)\n", strerror(errno))); + goto fail; + } + if ((tdb->flags & TDB_CLEAR_IF_FIRST) && + (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n")); + goto fail; + } + if (fstat(tdb->fd, &st) != 0) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: fstat failed (%s)\n", strerror(errno))); + goto fail; + } + if (st.st_ino != tdb->inode || st.st_dev != tdb->device) { + TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: file dev/inode has changed!\n")); + goto fail; + } + tdb_mmap(tdb); + + return 0; + +fail: + tdb_close(tdb); + return -1; +} + +/* reopen all tdb's */ +int tdb_reopen_all(int parent_longlived) +{ + struct tdb_context *tdb; + + for (tdb=tdbs; tdb; tdb = tdb->next) { + /* + * If the parent is longlived (ie. a + * parent daemon architecture), we know + * it will keep it's active lock on a + * tdb opened with CLEAR_IF_FIRST. Thus + * for child processes we don't have to + * add an active lock. This is essential + * to improve performance on systems that + * keep POSIX locks as a non-scalable data + * structure in the kernel. + */ + if (parent_longlived) { + /* Ensure no clear-if-first. */ + tdb->flags &= ~TDB_CLEAR_IF_FIRST; + } + + if (tdb_reopen(tdb) != 0) + return -1; + } + + return 0; +} diff --git a/libcustomext2fs/source/tdb.h b/libcustomext2fs/source/tdb.h new file mode 100644 index 00000000..bfcd9436 --- /dev/null +++ b/libcustomext2fs/source/tdb.h @@ -0,0 +1,215 @@ +#ifndef __TDB_H__ +#define __TDB_H__ + +/* + Unix SMB/CIFS implementation. + + trivial database library + + Copyright (C) Andrew Tridgell 1999-2004 + + ** NOTE! The following LGPL license applies to the tdb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifdef __cplusplus +extern "C" { +#endif + + +/* flags to tdb_store() */ +#define TDB_REPLACE 1 +#define TDB_INSERT 2 +#define TDB_MODIFY 3 + +/* flags for tdb_open() */ +#define TDB_DEFAULT 0 /* just a readability place holder */ +#define TDB_CLEAR_IF_FIRST 1 +#define TDB_INTERNAL 2 /* don't store on disk */ +#define TDB_NOLOCK 4 /* don't do any locking */ +#define TDB_NOMMAP 8 /* don't use mmap */ +#define TDB_CONVERT 16 /* convert endian (internal use) */ +#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */ +#define TDB_NOSYNC 64 /* don't use synchronous transactions */ +#define TDB_SEQNUM 128 /* maintain a sequence number */ + +#define TDB_ERRCODE(code, ret) ((tdb->ecode = (code)), ret) + +/* error codes */ +enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, + TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT, + TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY}; + +/* debugging uses one of the following levels */ +enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, + TDB_DEBUG_WARNING, TDB_DEBUG_TRACE}; + +typedef struct TDB_DATA { + unsigned char *dptr; + size_t dsize; +} TDB_DATA; + +#ifndef PRINTF_ATTRIBUTE +#if (__GNUC__ >= 3) +/** Use gcc attribute to check printf fns. a1 is the 1-based index of + * the parameter containing the format, and a2 the index of the first + * argument. Note that some gcc 2.x versions don't handle this + * properly **/ +#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) +#else +#define PRINTF_ATTRIBUTE(a1, a2) +#endif +#endif + +/* ext2fs tdb renames */ +#define tdb_open ext2fs_tdb_open +#define tdb_open_ex ext2fs_tdb_open_ex +#define tdb_set_max_dead ext2fs_tdb_set_max_dead +#define tdb_reopen ext2fs_tdb_reopen +#define tdb_reopen_all ext2fs_tdb_reopen_all +#define tdb_set_logging_function ext2fs_tdb_set_logging_function +#define tdb_error ext2fs_tdb_error +#define tdb_errorstr ext2fs_tdb_errorstr +#define tdb_fetch ext2fs_tdb_fetch +#define tdb_parse_record ext2fs_tdb_parse_record +#define tdb_delete ext2fs_tdb_delete +#define tdb_store ext2fs_tdb_store +#define tdb_append ext2fs_tdb_append +#define tdb_close ext2fs_tdb_close +#define tdb_firstkey ext2fs_tdb_firstkey +#define tdb_nextkey ext2fs_tdb_nextkey +#define tdb_traverse ext2fs_tdb_traverse +#define tdb_traverse_read ext2fs_tdb_traverse_read +#define tdb_exists ext2fs_tdb_exists +#define tdb_lockall ext2fs_tdb_lockall +#define tdb_unlockall ext2fs_tdb_unlockall +#define tdb_lockall_read ext2fs_tdb_lockall_read +#define tdb_unlockall_read ext2fs_tdb_unlockall_read +#define tdb_name ext2fs_tdb_name +#define tdb_fd ext2fs_tdb_fd +#define tdb_log_fn ext2fs_tdb_log_fn +#define tdb_get_logging_private ext2fs_tdb_get_logging_private +#define tdb_transaction_start ext2fs_tdb_transaction_start +#define tdb_transaction_commit ext2fs_tdb_transaction_commit +#define tdb_transaction_cancel ext2fs_tdb_transaction_cancel +#define tdb_transaction_recover ext2fs_tdb_transaction_recover +#define tdb_get_seqnum ext2fs_tdb_get_seqnum +#define tdb_hash_size ext2fs_tdb_hash_size +#define tdb_map_size ext2fs_tdb_map_size +#define tdb_get_flags ext2fs_tdb_get_flags +#define tdb_chainlock ext2fs_tdb_chainlock +#define tdb_chainunlock ext2fs_tdb_chainunlock +#define tdb_chainlock_read ext2fs_tdb_chainlock_read +#define tdb_chainunlock_read ext2fs_tdb_chainunlock_read +#define tdb_dump_all ext2fs_tdb_dump_all +#define tdb_printfreelist ext2fs_tdb_printfreelist +#define tdb_validate_freelist ext2fs_tdb_validate_freelist +#define tdb_chainlock_mark ext2fs_tdb_chainlock_mark +#define tdb_chainlock_nonblock ext2fs_tdb_chainlock_nonblock +#define tdb_chainlock_unmark ext2fs_tdb_chainlock_unmark +#define tdb_enable_seqnum ext2fs_tdb_enable_seqnum +#define tdb_increment_seqnum_nonblock ext2fs_tdb_increment_seqnum_nonblock +#define tdb_lock_nonblock ext2fs_tdb_lock_nonblock +#define tdb_lockall_mark ext2fs_tdb_lockall_mark +#define tdb_lockall_nonblock ext2fs_tdb_lockall_nonblock +#define tdb_lockall_read_nonblock ext2fs_tdb_lockall_read_nonblock +#define tdb_lockall_unmark ext2fs_tdb_lockall_unmark + +/* this is the context structure that is returned from a db open */ +typedef struct tdb_context TDB_CONTEXT; + +typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *); +typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4); +typedef unsigned int (*tdb_hash_func)(TDB_DATA *key); + +struct tdb_logging_context { + tdb_log_func log_fn; + void *log_private; +}; + +struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode); +struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode, + const struct tdb_logging_context *log_ctx, + tdb_hash_func hash_fn); +void tdb_set_max_dead(struct tdb_context *tdb, int max_dead); + +int tdb_reopen(struct tdb_context *tdb); +int tdb_reopen_all(int parent_longlived); +void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx); +enum TDB_ERROR tdb_error(struct tdb_context *tdb); +const char *tdb_errorstr(struct tdb_context *tdb); +TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key); +int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, + int (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); +int tdb_delete(struct tdb_context *tdb, TDB_DATA key); +int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); +int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf); +int tdb_close(struct tdb_context *tdb); +TDB_DATA tdb_firstkey(struct tdb_context *tdb); +TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key); +int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *); +int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *); +int tdb_exists(struct tdb_context *tdb, TDB_DATA key); +int tdb_lockall(struct tdb_context *tdb); +int tdb_lockall_nonblock(struct tdb_context *tdb); +int tdb_unlockall(struct tdb_context *tdb); +int tdb_lockall_read(struct tdb_context *tdb); +int tdb_lockall_read_nonblock(struct tdb_context *tdb); +int tdb_unlockall_read(struct tdb_context *tdb); +int tdb_lockall_mark(struct tdb_context *tdb); +int tdb_lockall_unmark(struct tdb_context *tdb); +const char *tdb_name(struct tdb_context *tdb); +int tdb_fd(struct tdb_context *tdb); +tdb_log_func tdb_log_fn(struct tdb_context *tdb); +void *tdb_get_logging_private(struct tdb_context *tdb); +int tdb_transaction_start(struct tdb_context *tdb); +int tdb_transaction_commit(struct tdb_context *tdb); +int tdb_transaction_cancel(struct tdb_context *tdb); +int tdb_transaction_recover(struct tdb_context *tdb); +int tdb_get_seqnum(struct tdb_context *tdb); +int tdb_hash_size(struct tdb_context *tdb); +size_t tdb_map_size(struct tdb_context *tdb); +int tdb_get_flags(struct tdb_context *tdb); +void tdb_enable_seqnum(struct tdb_context *tdb); +void tdb_increment_seqnum_nonblock(struct tdb_context *tdb); + +/* Low level locking functions: use with care */ +int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key); + +/* Debug functions. Not used in production. */ +void tdb_dump_all(struct tdb_context *tdb); +int tdb_printfreelist(struct tdb_context *tdb); +int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries); + +extern TDB_DATA tdb_null; + +#ifdef __cplusplus +} +#endif + +#endif /* tdb.h */ diff --git a/libcustomext2fs/source/unlink.c b/libcustomext2fs/source/unlink.c new file mode 100644 index 00000000..7ffeb9e8 --- /dev/null +++ b/libcustomext2fs/source/unlink.c @@ -0,0 +1,99 @@ +/* + * unlink.c --- delete links in a ext2fs directory + * + * Copyright (C) 1993, 1994, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#if HAVE_UNISTD_H +#include +#endif + +#include "ext2_fs.h" +#include "ext2fs.h" + +struct link_struct { + const char *name; + int namelen; + ext2_ino_t inode; + int flags; + struct ext2_dir_entry *prev; + int done; +}; + +#ifdef __TURBOC__ + #pragma argsused +#endif +static int unlink_proc(struct ext2_dir_entry *dirent, + int offset, + int blocksize EXT2FS_ATTR((unused)), + char *buf EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct link_struct *ls = (struct link_struct *) priv_data; + struct ext2_dir_entry *prev; + + prev = ls->prev; + ls->prev = dirent; + + if (ls->name) { + if ((dirent->name_len & 0xFF) != ls->namelen) + return 0; + if (strncmp(ls->name, dirent->name, dirent->name_len & 0xFF)) + return 0; + } + if (ls->inode) { + if (dirent->inode != ls->inode) + return 0; + } else { + if (!dirent->inode) + return 0; + } + + if (offset) + prev->rec_len += dirent->rec_len; + else + dirent->inode = 0; + ls->done++; + return DIRENT_ABORT|DIRENT_CHANGED; +} + +#ifdef __TURBOC__ + #pragma argsused +#endif +errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, + const char *name, ext2_ino_t ino, + int flags EXT2FS_ATTR((unused))) +{ + errcode_t retval; + struct link_struct ls; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + if (!name && !ino) + return EXT2_ET_INVALID_ARGUMENT; + + if (!(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + ls.name = name; + ls.namelen = name ? strlen(name) : 0; + ls.inode = ino; + ls.flags = 0; + ls.done = 0; + ls.prev = 0; + + retval = ext2fs_dir_iterate(fs, dir, DIRENT_FLAG_INCLUDE_EMPTY, + 0, unlink_proc, &ls); + if (retval) + return retval; + + return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE; +} + diff --git a/libcustomext2fs/source/valid_blk.c b/libcustomext2fs/source/valid_blk.c new file mode 100644 index 00000000..ec3edd88 --- /dev/null +++ b/libcustomext2fs/source/valid_blk.c @@ -0,0 +1,55 @@ +/* + * valid_blk.c --- does the inode have valid blocks? + * + * Copyright 1997 by Theodore Ts'o + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#if HAVE_UNISTD_H +#include +#endif +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +/* + * This function returns 1 if the inode's block entries actually + * contain block entries. + */ +int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) +{ + /* + * Only directories, regular files, and some symbolic links + * have valid block entries. + */ + if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) && + !LINUX_S_ISLNK(inode->i_mode)) + return 0; + + /* + * If the symbolic link is a "fast symlink", then the symlink + * target is stored in the block entries. + */ + if (LINUX_S_ISLNK (inode->i_mode)) { + if (ext2fs_file_acl_block(inode) == 0) { + /* With no EA block, we can rely on i_blocks */ + if (inode->i_blocks == 0) + return 0; + } else { + /* With an EA block, life gets more tricky */ + if (inode->i_size >= EXT2_N_BLOCKS*4) + return 1; /* definitely using i_block[] */ + if (inode->i_size > 4 && inode->i_block[1] == 0) + return 1; /* definitely using i_block[] */ + return 0; /* Probably a fast symlink */ + } + } + return 1; +} diff --git a/libcustomext2fs/source/version.c b/libcustomext2fs/source/version.c new file mode 100644 index 00000000..e7f223bf --- /dev/null +++ b/libcustomext2fs/source/version.c @@ -0,0 +1,54 @@ +/* + * version.c --- Return the version of the ext2 library + * + * Copyright (C) 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#if HAVE_UNISTD_H +#include +#endif +#include +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +static const char *lib_version = ""; +static const char *lib_date = ""; + +int ext2fs_parse_version_string(const char *ver_string) +{ + const char *cp; + int version = 0, dot_count = 0; + + for (cp = ver_string; *cp; cp++) { + if (*cp == '.') { + if (dot_count++) + break; + else + continue; + } + if (!isdigit((int)*cp)) + break; + version = (version * 10) + (*cp - '0'); + } + return version; +} + + +int ext2fs_get_library_version(const char **ver_string, + const char **date_string) +{ + if (ver_string) + *ver_string = lib_version; + if (date_string) + *date_string = lib_date; + + return ext2fs_parse_version_string(lib_version); +} diff --git a/libcustomext2fs/source/write_bb_file.c b/libcustomext2fs/source/write_bb_file.c new file mode 100644 index 00000000..70bcf08e --- /dev/null +++ b/libcustomext2fs/source/write_bb_file.c @@ -0,0 +1,34 @@ +/* + * write_bb_file.c --- write a list of bad blocks to a FILE * + * + * Copyright (C) 1994, 1995 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, + unsigned int flags EXT2FS_ATTR((unused)), + FILE *f) +{ + badblocks_iterate bb_iter; + blk_t blk; + errcode_t retval; + + retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter); + if (retval) + return retval; + + while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) { + fprintf(f, "%u\n", blk); + } + ext2fs_badblocks_list_iterate_end(bb_iter); + return 0; +} diff --git a/libcustomfat/Makefile b/libcustomfat/Makefile new file mode 100644 index 00000000..5c081a6d --- /dev/null +++ b/libcustomfat/Makefile @@ -0,0 +1,32 @@ +# Quick'n'dirty makefile [BC] v2 + +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +include $(DEVKITPPC)/wii_rules + +LIBOGC_INC := $(DEVKITPRO)/libogc/include +LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii + +CFLAGS := -O3 $(MACHDEP) -I$(LIBOGC_INC) + +LIB := fat +CFILES := $(wildcard *.c) +OFILES := $(CFILES:.c=.o) +ARC := lib$(LIB).a +HDR := fat.h + +all : $(OFILES) + $(AR) -r $(ARC) $(OFILES) + +clean : + rm -f $(OFILES) $(ARC) + +install : + mkdir -p $(LIBOGC_LIB) $(LIBOGC_INC) + cp -f $(ARC) $(LIBOGC_LIB)/ + cp -f $(HDR) $(LIBOGC_INC)/ + +%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ \ No newline at end of file diff --git a/libcustomfat/bit_ops.h b/libcustomfat/bit_ops.h new file mode 100644 index 00000000..762be0b3 --- /dev/null +++ b/libcustomfat/bit_ops.h @@ -0,0 +1,57 @@ +/* + bit_ops.h + Functions for dealing with conversion of data between types + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _BIT_OPS_H +#define _BIT_OPS_H + +#include + +/*----------------------------------------------------------------- +Functions to deal with little endian values stored in uint8_t arrays +-----------------------------------------------------------------*/ +static inline uint16_t u8array_to_u16 (const uint8_t* item, int offset) { + return ( item[offset] | (item[offset + 1] << 8)); +} + +static inline uint32_t u8array_to_u32 (const uint8_t* item, int offset) { + return ( item[offset] | (item[offset + 1] << 8) | (item[offset + 2] << 16) | (item[offset + 3] << 24)); +} + +static inline void u16_to_u8array (uint8_t* item, int offset, uint16_t value) { + item[offset] = (uint8_t) value; + item[offset + 1] = (uint8_t)(value >> 8); +} + +static inline void u32_to_u8array (uint8_t* item, int offset, uint32_t value) { + item[offset] = (uint8_t) value; + item[offset + 1] = (uint8_t)(value >> 8); + item[offset + 2] = (uint8_t)(value >> 16); + item[offset + 3] = (uint8_t)(value >> 24); +} + +#endif // _BIT_OPS_H diff --git a/libcustomfat/cache.c b/libcustomfat/cache.c new file mode 100644 index 00000000..2b12b70b --- /dev/null +++ b/libcustomfat/cache.c @@ -0,0 +1,365 @@ +/* + cache.c + The cache is not visible to the user. It should be flushed + when any file is closed or changes are made to the filesystem. + + This cache implements a least-used-page replacement policy. This will + distribute sectors evenly over the pages, so if less than the maximum + pages are used at once, they should all eventually remain in the cache. + This also has the benefit of throwing out old sectors, so as not to keep + too many stale pages around. + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include + +#include "common.h" +#include "cache.h" +#include "disc.h" + +#include "mem_allocate.h" +#include "bit_ops.h" +#include "file_allocation_table.h" + +#define CACHE_FREE UINT_MAX + +CACHE* _FAT_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition) { + CACHE* cache; + unsigned int i; + CACHE_ENTRY* cacheEntries; + + if (numberOfPages < 2) { + numberOfPages = 2; + } + + if (sectorsPerPage < 8) { + sectorsPerPage = 8; + } + + cache = (CACHE*) _FAT_mem_allocate (sizeof(CACHE)); + if (cache == NULL) { + return NULL; + } + + cache->disc = discInterface; + cache->endOfPartition = endOfPartition; + cache->numberOfPages = numberOfPages; + cache->sectorsPerPage = sectorsPerPage; + + + cacheEntries = (CACHE_ENTRY*) _FAT_mem_allocate ( sizeof(CACHE_ENTRY) * numberOfPages); + if (cacheEntries == NULL) { + _FAT_mem_free (cache); + return NULL; + } + + for (i = 0; i < numberOfPages; i++) { + cacheEntries[i].sector = CACHE_FREE; + cacheEntries[i].count = 0; + cacheEntries[i].last_access = 0; + cacheEntries[i].dirty = false; + cacheEntries[i].cache = (uint8_t*) _FAT_mem_align ( sectorsPerPage * BYTES_PER_READ ); + } + + cache->cacheEntries = cacheEntries; + + return cache; +} + +void _FAT_cache_destructor (CACHE* cache) { + unsigned int i; + // Clear out cache before destroying it + _FAT_cache_flush(cache); + + // Free memory in reverse allocation order + for (i = 0; i < cache->numberOfPages; i++) { + _FAT_mem_free (cache->cacheEntries[i].cache); + } + _FAT_mem_free (cache->cacheEntries); + _FAT_mem_free (cache); +} + + +static u32 accessCounter = 0; + +static u32 accessTime(){ + accessCounter++; + return accessCounter; +} + + +static CACHE_ENTRY* _FAT_cache_getPage(CACHE *cache,sec_t sector) +{ + unsigned int i; + CACHE_ENTRY* cacheEntries = cache->cacheEntries; + unsigned int numberOfPages = cache->numberOfPages; + unsigned int sectorsPerPage = cache->sectorsPerPage; + + bool foundFree = false; + unsigned int oldUsed = 0; + unsigned int oldAccess = UINT_MAX; + + for(i=0;i=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) { + cacheEntries[i].last_access = accessTime(); + return &(cacheEntries[i]); + } + + if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_accessdisc,cacheEntries[oldUsed].sector,cacheEntries[oldUsed].count,cacheEntries[oldUsed].cache)) return NULL; + cacheEntries[oldUsed].dirty = false; + } + + sector = (sector/sectorsPerPage)*sectorsPerPage; // align base sector to page size + sec_t next_page = sector + sectorsPerPage; + if(next_page > cache->endOfPartition) next_page = cache->endOfPartition; + + if(!_FAT_disc_readSectors(cache->disc,sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL; + + cacheEntries[oldUsed].sector = sector; + cacheEntries[oldUsed].count = next_page-sector; + cacheEntries[oldUsed].last_access = accessTime(); + + return &(cacheEntries[oldUsed]); +} + +bool _FAT_cache_readSectors(CACHE *cache,sec_t sector,sec_t numSectors,void *buffer) +{ + sec_t sec; + sec_t secs_to_read; + CACHE_ENTRY *entry; + uint8_t *dest = (uint8_t *)buffer; + + while(numSectors>0) { + entry = _FAT_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + secs_to_read = entry->count - sec; + if(secs_to_read>numSectors) secs_to_read = numSectors; + + memcpy(dest,entry->cache + (sec*BYTES_PER_READ),(secs_to_read*BYTES_PER_READ)); + + dest += (secs_to_read*BYTES_PER_READ); + sector += secs_to_read; + numSectors -= secs_to_read; + } + + return true; +} + +/* +Reads some data from a cache page, determined by the sector number +*/ +bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + CACHE_ENTRY *entry; + + if (offset + size > BYTES_PER_READ) return false; + + entry = _FAT_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memcpy(buffer,entry->cache + ((sec*BYTES_PER_READ) + offset),size); + + return true; +} + +bool _FAT_cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes) { + uint8_t buf[4]; + if (!_FAT_cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false; + + switch(num_bytes) { + case 1: *value = buf[0]; break; + case 2: *value = u8array_to_u16(buf,0); break; + case 4: *value = u8array_to_u32(buf,0); break; + default: return false; + } + return true; +} + +/* +Writes some data to a cache page, making sure it is loaded into memory first. +*/ +bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + CACHE_ENTRY *entry; + + if (offset + size > BYTES_PER_READ) return false; + + entry = _FAT_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memcpy(entry->cache + ((sec*BYTES_PER_READ) + offset),buffer,size); + + entry->dirty = true; + return true; +} + +bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int size) { + uint8_t buf[4] = {0, 0, 0, 0}; + + switch(size) { + case 1: buf[0] = value; break; + case 2: u16_to_u8array(buf, 0, value); break; + case 4: u32_to_u8array(buf, 0, value); break; + default: return false; + } + + return _FAT_cache_writePartialSector(cache, buf, sector, offset, size); +} + +/* +Writes some data to a cache page, zeroing out the page first +*/ +bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + CACHE_ENTRY *entry; + + if (offset + size > BYTES_PER_READ) return false; + + entry = _FAT_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memset(entry->cache + (sec*BYTES_PER_READ),0,BYTES_PER_READ); + memcpy(entry->cache + ((sec*BYTES_PER_READ) + offset),buffer,size); + + entry->dirty = true; + return true; +} + +#ifndef GEKKO +static CACHE_ENTRY* _FAT_cache_findPage(CACHE *cache, sec_t sector, sec_t count) { + + unsigned int i; + CACHE_ENTRY* cacheEntries = cache->cacheEntries; + unsigned int numberOfPages = cache->numberOfPages; + CACHE_ENTRY *entry = NULL; + sec_t lowest = UINT_MAX; + + for(i=0;i cacheEntries[i].sector) { + intersect = sector - cacheEntries[i].sector < cacheEntries[i].count; + } else { + intersect = cacheEntries[i].sector - sector < count; + } + + if ( intersect && (cacheEntries[i].sector < lowest)) { + lowest = cacheEntries[i].sector; + entry = &cacheEntries[i]; + } + } + } + + return entry; +} +#endif + +bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer) +{ + sec_t sec; + sec_t secs_to_write; + CACHE_ENTRY* entry; + const uint8_t *src = (const uint8_t *)buffer; + + while(numSectors>0) + { +#ifdef GEKKO + entry = _FAT_cache_getPage(cache,sector); + if(entry==NULL) return false; +#else + entry = _FAT_cache_findPage(cache,sector,numSectors); + + if(entry==NULL) + return _FAT_disc_writeSectors(cache->disc,sector,numSectors,src); + + if ( entry->sector > sector) { + secs_to_write = entry->sector - sector; + + _FAT_disc_writeSectors(cache->disc,sector,secs_to_write,src); + src += (secs_to_write*BYTES_PER_READ); + sector += secs_to_write; + numSectors -= secs_to_write; + } +#endif + 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; + } + return true; +} + +/* +Flushes all dirty pages to disc, clearing the dirty flag. +*/ +bool _FAT_cache_flush (CACHE* cache) { + unsigned int i; + + for (i = 0; i < cache->numberOfPages; i++) { + if (cache->cacheEntries[i].dirty) { + if (!_FAT_disc_writeSectors (cache->disc, cache->cacheEntries[i].sector, cache->cacheEntries[i].count, cache->cacheEntries[i].cache)) { + return false; + } + } + cache->cacheEntries[i].dirty = false; + } + + return true; +} + +void _FAT_cache_invalidate (CACHE* cache) { + unsigned int i; + _FAT_cache_flush(cache); + for (i = 0; i < cache->numberOfPages; i++) { + cache->cacheEntries[i].sector = CACHE_FREE; + cache->cacheEntries[i].last_access = 0; + cache->cacheEntries[i].count = 0; + cache->cacheEntries[i].dirty = false; + } +} diff --git a/libcustomfat/cache.h b/libcustomfat/cache.h new file mode 100644 index 00000000..c6e48d07 --- /dev/null +++ b/libcustomfat/cache.h @@ -0,0 +1,130 @@ +/* + cache.h + The cache is not visible to the user. It should be flushed + when any file is closed or changes are made to the filesystem. + + This cache implements a least-used-page replacement policy. This will + distribute sectors evenly over the pages, so if less than the maximum + pages are used at once, they should all eventually remain in the cache. + This also has the benefit of throwing out old sectors, so as not to keep + too many stale pages around. + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _CACHE_H +#define _CACHE_H + +#include "common.h" +#include "disc.h" + +#define PAGE_SECTORS 64 +#define CACHE_PAGE_SIZE (BYTES_PER_READ * PAGE_SECTORS) + +typedef struct { + sec_t sector; + unsigned int count; + unsigned int last_access; + bool dirty; + uint8_t* cache; +} CACHE_ENTRY; + +typedef struct { + const DISC_INTERFACE* disc; + sec_t endOfPartition; + unsigned int numberOfPages; + unsigned int sectorsPerPage; + CACHE_ENTRY* cacheEntries; +} CACHE; + +/* +Read data from a sector in the cache +If the sector is not in the cache, it will be swapped in +offset is the position to start reading from +size is the amount of data to read +Precondition: offset + size <= BYTES_PER_READ +*/ +bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size); + +bool _FAT_cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes); + +/* +Write data to a sector in the cache +If the sector is not in the cache, it will be swapped in. +When the sector is swapped out, the data will be written to the disc +offset is the position to start writing to +size is the amount of data to write +Precondition: offset + size <= BYTES_PER_READ +*/ +bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size); + +bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int num_bytes); + +/* +Write data to a sector in the cache, zeroing the sector first +If the sector is not in the cache, it will be swapped in. +When the sector is swapped out, the data will be written to the disc +offset is the position to start writing to +size is the amount of data to write +Precondition: offset + size <= BYTES_PER_READ +*/ +bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size); + +/* +Read several sectors from the cache +*/ +bool _FAT_cache_readSectors (CACHE* cache, sec_t sector, sec_t numSectors, void* buffer); + +/* +Read a full sector from the cache +*/ +static inline bool _FAT_cache_readSector (CACHE* cache, void* buffer, sec_t sector) { + return _FAT_cache_readPartialSector (cache, buffer, sector, 0, BYTES_PER_READ); +} + +/* +Write a full sector to the cache +*/ +static inline bool _FAT_cache_writeSector (CACHE* cache, const void* buffer, sec_t sector) { + return _FAT_cache_writePartialSector (cache, buffer, sector, 0, BYTES_PER_READ); +} + +bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer); + +/* +Write any dirty sectors back to disc and clear out the contents of the cache +*/ +bool _FAT_cache_flush (CACHE* cache); + +/* +Clear out the contents of the cache without writing any dirty sectors first +*/ +void _FAT_cache_invalidate (CACHE* cache); + +CACHE* _FAT_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition); + +void _FAT_cache_destructor (CACHE* cache); + +#endif // _CACHE_H + diff --git a/libcustomfat/common.h b/libcustomfat/common.h new file mode 100644 index 00000000..b28e7033 --- /dev/null +++ b/libcustomfat/common.h @@ -0,0 +1,79 @@ +/* + common.h + Common definitions and included files for the FATlib + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _COMMON_H +#define _COMMON_H + +#define BYTES_PER_READ 512 +#include +#include +#include + +// When compiling for NDS, make sure NDS is defined +#ifndef NDS + #if defined ARM9 || defined ARM7 + #define NDS + #endif +#endif + +// Platform specific includes +#if defined(__gamecube__) || defined (__wii__) + #include + #include + #include +#elif defined(NDS) + #include + #include + #include +#elif defined(GBA) + #include + #include +#endif + +// Platform specific options +#if defined (__wii__) + #define DEFAULT_CACHE_PAGES 4 + #define DEFAULT_SECTORS_PAGE 64 + #define USE_LWP_LOCK + #define USE_RTC_TIME +#elif defined (__gamecube__) + #define DEFAULT_CACHE_PAGES 4 + #define DEFAULT_SECTORS_PAGE 64 + #define USE_LWP_LOCK + #define USE_RTC_TIME +#elif defined (NDS) + #define DEFAULT_CACHE_PAGES 4 + #define DEFAULT_SECTORS_PAGE 8 + #define USE_RTC_TIME +#elif defined (GBA) + #define DEFAULT_CACHE_PAGES 2 + #define DEFAULT_SECTORS_PAGE 8 + #define LIMIT_SECTORS 128 +#endif + +#endif // _COMMON_H diff --git a/libcustomfat/directory.c b/libcustomfat/directory.c new file mode 100644 index 00000000..c2d93131 --- /dev/null +++ b/libcustomfat/directory.c @@ -0,0 +1,1120 @@ +/* + directory.c + Reading, writing and manipulation of the directory structure on + a FAT partition + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include + +#include "directory.h" +#include "common.h" +#include "partition.h" +#include "file_allocation_table.h" +#include "bit_ops.h" +#include "filetime.h" + +// Directory entry codes +#define DIR_ENTRY_LAST 0x00 +#define DIR_ENTRY_FREE 0xE5 + +#define LAST_LFN_POS (19*13) +#define LAST_LFN_POS_CORRECTION (MAX_LFN_LENGTH-15) + +typedef unsigned short ucs2_t; + +// Long file name directory entry +enum LFN_offset { + LFN_offset_ordinal = 0x00, // Position within LFN + LFN_offset_char0 = 0x01, + LFN_offset_char1 = 0x03, + LFN_offset_char2 = 0x05, + LFN_offset_char3 = 0x07, + LFN_offset_char4 = 0x09, + LFN_offset_flag = 0x0B, // Should be equal to ATTRIB_LFN + LFN_offset_reserved1 = 0x0C, // Always 0x00 + LFN_offset_checkSum = 0x0D, // Checksum of short file name (alias) + LFN_offset_char5 = 0x0E, + LFN_offset_char6 = 0x10, + LFN_offset_char7 = 0x12, + LFN_offset_char8 = 0x14, + LFN_offset_char9 = 0x16, + LFN_offset_char10 = 0x18, + LFN_offset_reserved2 = 0x1A, // Always 0x0000 + LFN_offset_char11 = 0x1C, + LFN_offset_char12 = 0x1E +}; +static const int LFN_offset_table[13]={0x01,0x03,0x05,0x07,0x09,0x0E,0x10,0x12,0x14,0x16,0x18,0x1C,0x1E}; + +#define LFN_END 0x40 +#define LFN_DEL 0x80 + +static const char ILLEGAL_ALIAS_CHARACTERS[] = "\\/:;*?\"<>|&+,=[] "; +static const char ILLEGAL_LFN_CHARACTERS[] = "\\/:*?\"<>|"; + +/* +Returns number of UCS-2 characters needed to encode an LFN +Returns -1 if it is an invalid LFN +*/ +#define ABOVE_UCS_RANGE 0xF0 +static int _FAT_directory_lfnLength (const char* name) { + unsigned int i; + size_t nameLength; + int ucsLength; + const char* tempName = name; + + nameLength = strnlen(name, MAX_FILENAME_LENGTH); + // Make sure the name is short enough to be valid + if ( nameLength >= MAX_FILENAME_LENGTH) { + return -1; + } + // Make sure it doesn't contain any invalid characters + if (strpbrk (name, ILLEGAL_LFN_CHARACTERS) != NULL) { + return -1; + } + // Make sure the name doesn't contain any control codes or codes not representable in UCS-2 + for (i = 0; i < nameLength; i++) { + if (name[i] < 0x20 || name[i] >= ABOVE_UCS_RANGE) { + return -1; + } + } + // Convert to UCS-2 and get the resulting length + ucsLength = mbsrtowcs(NULL, &tempName, MAX_LFN_LENGTH, NULL); + if (ucsLength < 0 || ucsLength >= MAX_LFN_LENGTH) { + return -1; + } + + // Otherwise it is valid + return ucsLength; +} + +/* +Convert a multibyte encoded string into a NUL-terminated UCS-2 string, storing at most len characters +return number of characters stored +*/ +static size_t _FAT_directory_mbstoucs2 (ucs2_t* dst, const char* src, size_t len) { + mbstate_t ps = {0}; + wchar_t tempChar; + int bytes; + size_t count = 0; + + while (count < len-1 && src != '\0') { + bytes = mbrtowc (&tempChar, src, MB_CUR_MAX, &ps); + if (bytes > 0) { + *dst = (ucs2_t)tempChar; + src += bytes; + dst++; + count++; + } else if (bytes == 0) { + break; + } else { + return -1; + } + } + *dst = '\0'; + + return count; +} + +/* +Convert a UCS-2 string into a NUL-terminated multibyte string, storing at most len chars +return number of chars stored, or (size_t)-1 on error +*/ +static size_t _FAT_directory_ucs2tombs (char* dst, const ucs2_t* src, size_t len) { + mbstate_t ps = {0}; + size_t count = 0; + int bytes; + char buff[MB_CUR_MAX]; + int i; + + while (count < len - 1 && *src != '\0') { + bytes = wcrtomb (buff, *src, &ps); + if (bytes < 0) { + return -1; + } + if (count + bytes < len && bytes > 0) { + for (i = 0; i < bytes; i++) { + *dst++ = buff[i]; + } + src++; + count += bytes; + } else { + break; + } + } + *dst = L'\0'; + + return count; +} + +/* +Case-independent comparison of two multibyte encoded strings +*/ +static int _FAT_directory_mbsncasecmp (const char* s1, const char* s2, size_t len1) { + wchar_t wc1, wc2; + mbstate_t ps1 = {0}; + mbstate_t ps2 = {0}; + size_t b1 = 0; + size_t b2 = 0; + + if (len1 == 0) { + return 0; + } + + do { + s1 += b1; + s2 += b2; + b1 = mbrtowc(&wc1, s1, MB_CUR_MAX, &ps1); + b2 = mbrtowc(&wc2, s2, MB_CUR_MAX, &ps2); + if ((int)b1 < 0 || (int)b2 < 0) { + break; + } + len1 -= b1; + } while (len1 > 0 && towlower(wc1) == towlower(wc2) && wc1 != 0); + + return towlower(wc1) - towlower(wc2); +} + + +static bool _FAT_directory_entryGetAlias (const u8* entryData, char* destName) { + int i=0; + int j=0; + + destName[0] = '\0'; + if (entryData[0] != DIR_ENTRY_FREE) { + if (entryData[0] == '.') { + destName[0] = '.'; + if (entryData[1] == '.') { + destName[1] = '.'; + destName[2] = '\0'; + } else { + destName[1] = '\0'; + } + } else { + // Copy the filename from the dirEntry to the string + for (i = 0; (i < 8) && (entryData[DIR_ENTRY_name + i] != ' '); i++) { + destName[i] = entryData[DIR_ENTRY_name + i]; + } + // Copy the extension from the dirEntry to the string + if (entryData[DIR_ENTRY_extension] != ' ') { + destName[i++] = '.'; + for ( j = 0; (j < 3) && (entryData[DIR_ENTRY_extension + j] != ' '); j++) { + destName[i++] = entryData[DIR_ENTRY_extension + j]; + } + } + destName[i] = '\0'; + } + } + + return (destName[0] != '\0'); +} + +uint32_t _FAT_directory_entryGetCluster (PARTITION* partition, const uint8_t* entryData) { + if (partition->filesysType == FS_FAT32) { + // Only use high 16 bits of start cluster when we are certain they are correctly defined + return u8array_to_u16(entryData,DIR_ENTRY_cluster) | (u8array_to_u16(entryData, DIR_ENTRY_clusterHigh) << 16); + } else { + return u8array_to_u16(entryData,DIR_ENTRY_cluster); + } +} + +static bool _FAT_directory_incrementDirEntryPosition (PARTITION* partition, DIR_ENTRY_POSITION* entryPosition, bool extendDirectory) { + DIR_ENTRY_POSITION position = *entryPosition; + uint32_t tempCluster; + + // Increment offset, wrapping at the end of a sector + ++ position.offset; + if (position.offset == BYTES_PER_READ / DIR_ENTRY_DATA_SIZE) { + position.offset = 0; + // Increment sector when wrapping + ++ position.sector; + // But wrap at the end of a cluster + if ((position.sector == partition->sectorsPerCluster) && (position.cluster != FAT16_ROOT_DIR_CLUSTER)) { + position.sector = 0; + // Move onto the next cluster, making sure there is another cluster to go to + tempCluster = _FAT_fat_nextCluster(partition, position.cluster); + if (tempCluster == CLUSTER_EOF) { + if (extendDirectory) { + tempCluster = _FAT_fat_linkFreeClusterCleared (partition, position.cluster); + if (!_FAT_fat_isValidCluster(partition, tempCluster)) { + return false; // This will only happen if the disc is full + } + } else { + return false; // Got to the end of the directory, not extending it + } + } + position.cluster = tempCluster; + } else if ((position.cluster == FAT16_ROOT_DIR_CLUSTER) && (position.sector == (partition->dataStart - partition->rootDirStart))) { + return false; // Got to end of root directory, can't extend it + } + } + *entryPosition = position; + return true; +} + +bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry) { + DIR_ENTRY_POSITION entryStart; + DIR_ENTRY_POSITION entryEnd; + uint8_t entryData[0x20]; + ucs2_t lfn[MAX_LFN_LENGTH]; + bool notFound, found; + int lfnPos; + uint8_t lfnChkSum, chkSum; + bool lfnExists; + int i; + + lfnChkSum = 0; + + entryStart = entry->dataEnd; + + // Make sure we are using the correct root directory, in case of FAT32 + if (entryStart.cluster == FAT16_ROOT_DIR_CLUSTER) { + entryStart.cluster = partition->rootDirCluster; + } + + entryEnd = entryStart; + + lfnExists = false; + + found = false; + notFound = false; + + while (!found && !notFound) { + if (_FAT_directory_incrementDirEntryPosition (partition, &entryEnd, false) == false) { + notFound = true; + } + + _FAT_cache_readPartialSector (partition->cache, entryData, + _FAT_fat_clusterToSector(partition, entryEnd.cluster) + entryEnd.sector, + entryEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + + if (entryData[DIR_ENTRY_attributes] == ATTRIB_LFN) { + // It's an LFN + if (entryData[LFN_offset_ordinal] & LFN_DEL) { + lfnExists = false; + } else if (entryData[LFN_offset_ordinal] & LFN_END) { + // Last part of LFN, make sure it isn't deleted using previous if(Thanks MoonLight) + entryStart = entryEnd; // This is the start of a directory entry + lfnExists = true; + lfnPos = (entryData[LFN_offset_ordinal] & ~LFN_END) * 13; + if (lfnPos > MAX_LFN_LENGTH - 1) { + lfnPos = MAX_LFN_LENGTH - 1; + } + lfn[lfnPos] = '\0'; // Set end of lfn to null character + lfnChkSum = entryData[LFN_offset_checkSum]; + } + if (lfnChkSum != entryData[LFN_offset_checkSum]) { + lfnExists = false; + } + if (lfnExists) { + lfnPos = ((entryData[LFN_offset_ordinal] & ~LFN_END) - 1) * 13; + if (lfnPos > LAST_LFN_POS) { + // Force it within the buffer. Will corrupt the filename but prevent buffer overflows + lfnPos = LAST_LFN_POS; + } + for (i = 0; i < 13; i++) { + lfn[lfnPos + i] = entryData[LFN_offset_table[i]] | (entryData[LFN_offset_table[i]+1] << 8); + } + } + } else if (entryData[DIR_ENTRY_attributes] & ATTRIB_VOL) { + // This is a volume name, don't bother with it + } else if (entryData[0] == DIR_ENTRY_LAST) { + notFound = true; + } else if ((entryData[0] != DIR_ENTRY_FREE) && (entryData[0] > 0x20) && !(entryData[DIR_ENTRY_attributes] & ATTRIB_VOL)) { + if (lfnExists) { + // Calculate file checksum + chkSum = 0; + for (i=0; i < 11; i++) { + // NOTE: The operation is an unsigned char rotate right + chkSum = ((chkSum & 1) ? 0x80 : 0) + (chkSum >> 1) + entryData[i]; + } + if (chkSum != lfnChkSum) { + lfnExists = false; + entry->filename[0] = '\0'; + } + } + + if (lfnExists) { + if (_FAT_directory_ucs2tombs (entry->filename, lfn, MAX_FILENAME_LENGTH) == (size_t)-1) { + // Failed to convert the file name to UTF-8. Maybe the wrong locale is set? + return false; + } + } else { + entryStart = entryEnd; + _FAT_directory_entryGetAlias (entryData, entry->filename); + } + found = true; + } + } + + // If no file is found, return false + if (notFound) { + return false; + } else { + // Fill in the directory entry struct + entry->dataStart = entryStart; + entry->dataEnd = entryEnd; + memcpy (entry->entryData, entryData, DIR_ENTRY_DATA_SIZE); + return true; + } +} + +bool _FAT_directory_getFirstEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster) { + entry->dataStart.cluster = dirCluster; + entry->dataStart.sector = 0; + entry->dataStart.offset = -1; // Start before the beginning of the directory + + entry->dataEnd = entry->dataStart; + + return _FAT_directory_getNextEntry (partition, entry); +} + +bool _FAT_directory_getRootEntry (PARTITION* partition, DIR_ENTRY* entry) { + entry->dataStart.cluster = 0; + entry->dataStart.sector = 0; + entry->dataStart.offset = 0; + + entry->dataEnd = entry->dataStart; + + memset (entry->filename, '\0', MAX_FILENAME_LENGTH); + entry->filename[0] = '.'; + + memset (entry->entryData, 0, DIR_ENTRY_DATA_SIZE); + memset (entry->entryData, ' ', 11); + entry->entryData[0] = '.'; + + entry->entryData[DIR_ENTRY_attributes] = ATTRIB_DIR; + + u16_to_u8array (entry->entryData, DIR_ENTRY_cluster, partition->rootDirCluster); + u16_to_u8array (entry->entryData, DIR_ENTRY_clusterHigh, partition->rootDirCluster >> 16); + + return true; +} + +bool _FAT_directory_getVolumeLabel (PARTITION* partition, char *label) { + DIR_ENTRY entry; + DIR_ENTRY_POSITION entryEnd; + uint8_t entryData[DIR_ENTRY_DATA_SIZE]; + int i; + bool end; + + _FAT_directory_getRootEntry(partition, &entry); + + entryEnd = entry.dataEnd; + + // Make sure we are using the correct root directory, in case of FAT32 + if (entryEnd.cluster == FAT16_ROOT_DIR_CLUSTER) { + entryEnd.cluster = partition->rootDirCluster; + } + + label[0]='\0'; + label[11]='\0'; + end = false; + //this entry should be among the first 3 entries in the root directory table, if not, then system can have trouble displaying the right volume label + while(!end) { + if(!_FAT_cache_readPartialSector (partition->cache, entryData, + _FAT_fat_clusterToSector(partition, entryEnd.cluster) + entryEnd.sector, + entryEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE)) + { //error reading + return false; + } + + if (entryData[DIR_ENTRY_attributes] == ATTRIB_VOL && entryData[0] != DIR_ENTRY_FREE) { + for (i = 0; i < 11; i++) { + label[i] = entryData[DIR_ENTRY_name + i]; + } + return true; + } else if (entryData[0] == DIR_ENTRY_LAST) { + end = true; + } + + if (_FAT_directory_incrementDirEntryPosition (partition, &entryEnd, false) == false) { + end = true; + } + } + return false; +} + +bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry) { + DIR_ENTRY_POSITION entryStart = entry->dataStart; + DIR_ENTRY_POSITION entryEnd = entry->dataEnd; + bool entryStillValid; + bool finished; + ucs2_t lfn[MAX_LFN_LENGTH]; + int i; + int lfnPos; + uint8_t entryData[DIR_ENTRY_DATA_SIZE]; + + memset (entry->filename, '\0', MAX_FILENAME_LENGTH); + + // Create an empty directory entry to overwrite the old ones with + for ( entryStillValid = true, finished = false; + entryStillValid && !finished; + entryStillValid = _FAT_directory_incrementDirEntryPosition (partition, &entryStart, false)) + { + _FAT_cache_readPartialSector (partition->cache, entryData, + _FAT_fat_clusterToSector(partition, entryStart.cluster) + entryStart.sector, + entryStart.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + + if ((entryStart.cluster == entryEnd.cluster) + && (entryStart.sector == entryEnd.sector) + && (entryStart.offset == entryEnd.offset)) { + // Copy the entry data and stop, since this is the last section of the directory entry + memcpy (entry->entryData, entryData, DIR_ENTRY_DATA_SIZE); + finished = true; + } else { + // Copy the long file name data + lfnPos = ((entryData[LFN_offset_ordinal] & ~LFN_END) - 1) * 13; + if (lfnPos > LAST_LFN_POS) { + lfnPos = LAST_LFN_POS_CORRECTION; + } + for (i = 0; i < 13; i++) { + lfn[lfnPos + i] = entryData[LFN_offset_table[i]] | (entryData[LFN_offset_table[i]+1] << 8); + } + } + } + + if (!entryStillValid) { + return false; + } + + if ((entryStart.cluster == entryEnd.cluster) + && (entryStart.sector == entryEnd.sector) + && (entryStart.offset == entryEnd.offset)) { + // Since the entry doesn't have a long file name, extract the short filename + if (!_FAT_directory_entryGetAlias (entry->entryData, entry->filename)) { + return false; + } + } else { + // Encode the long file name into a multibyte string + if (_FAT_directory_ucs2tombs (entry->filename, lfn, MAX_FILENAME_LENGTH) == (size_t)-1) { + return false; + } + } + + return true; +} + + + +bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const char* path, const char* pathEnd) { + size_t dirnameLength; + const char* pathPosition; + const char* nextPathPosition; + uint32_t dirCluster; + bool foundFile; + char alias[MAX_ALIAS_LENGTH]; + bool found, notFound; + + pathPosition = path; + + found = false; + notFound = false; + + if (pathEnd == NULL) { + // Set pathEnd to the end of the path string + pathEnd = strchr (path, '\0'); + } + + if (pathPosition[0] == DIR_SEPARATOR) { + // Start at root directory + dirCluster = partition->rootDirCluster; + // Consume separator(s) + while (pathPosition[0] == DIR_SEPARATOR) { + pathPosition++; + } + // If the path is only specifying a directory in the form of "/" return it + if (pathPosition >= pathEnd) { + _FAT_directory_getRootEntry (partition, entry); + found = true; + } + } else { + // Start in current working directory + dirCluster = partition->cwdCluster; + } + + // If the path is only specifying a directory in the form "." + // and this is the root directory, return it + if ((dirCluster == partition->rootDirCluster) && (strcmp(".", pathPosition) == 0)) { + _FAT_directory_getRootEntry (partition, entry); + found = true; + } + + while (!found && !notFound) { + // Get the name of the next required subdirectory within the path + nextPathPosition = strchr (pathPosition, DIR_SEPARATOR); + if (nextPathPosition != NULL) { + dirnameLength = nextPathPosition - pathPosition; + } else { + dirnameLength = strlen(pathPosition); + } + + if (dirnameLength > MAX_FILENAME_LENGTH) { + // The path is too long to bother with + return false; + } + + // Look for the directory within the path + foundFile = _FAT_directory_getFirstEntry (partition, entry, dirCluster); + + while (foundFile && !found && !notFound) { // It hasn't already found the file + // Check if the filename matches + if ((dirnameLength == strnlen(entry->filename, MAX_FILENAME_LENGTH)) + && (_FAT_directory_mbsncasecmp(pathPosition, entry->filename, dirnameLength) == 0)) { + found = true; + } + + // Check if the alias matches + _FAT_directory_entryGetAlias (entry->entryData, alias); + if ((dirnameLength == strnlen(alias, MAX_ALIAS_LENGTH)) + && (strncasecmp(pathPosition, alias, dirnameLength) == 0)) { + found = true; + } + + if (found && !(entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) && (nextPathPosition != NULL)) { + // Make sure that we aren't trying to follow a file instead of a directory in the path + found = false; + } + + if (!found) { + foundFile = _FAT_directory_getNextEntry (partition, entry); + } + } + + if (!foundFile) { + // Check that the search didn't get to the end of the directory + notFound = true; + found = false; + } else if ((nextPathPosition == NULL) || (nextPathPosition >= pathEnd)) { + // Check that we reached the end of the path + found = true; + } else if (entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) { + dirCluster = _FAT_directory_entryGetCluster (partition, entry->entryData); + pathPosition = nextPathPosition; + // Consume separator(s) + while (pathPosition[0] == DIR_SEPARATOR) { + pathPosition++; + } + // The requested directory was found + if (pathPosition >= pathEnd) { + found = true; + } else { + found = false; + } + } + } + + if (found && !notFound) { + if (partition->filesysType == FS_FAT32 && (entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) && + _FAT_directory_entryGetCluster (partition, entry->entryData) == CLUSTER_ROOT) + { + // On FAT32 it should specify an actual cluster for the root entry, + // not cluster 0 as on FAT16 + _FAT_directory_getRootEntry (partition, entry); + } + return true; + } else { + return false; + } +} + +bool _FAT_directory_removeEntry (PARTITION* partition, DIR_ENTRY* entry) { + DIR_ENTRY_POSITION entryStart = entry->dataStart; + DIR_ENTRY_POSITION entryEnd = entry->dataEnd; + bool entryStillValid; + bool finished; + uint8_t entryData[DIR_ENTRY_DATA_SIZE]; + + // Create an empty directory entry to overwrite the old ones with + for ( entryStillValid = true, finished = false; + entryStillValid && !finished; + entryStillValid = _FAT_directory_incrementDirEntryPosition (partition, &entryStart, false)) + { + _FAT_cache_readPartialSector (partition->cache, entryData, _FAT_fat_clusterToSector(partition, entryStart.cluster) + entryStart.sector, entryStart.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + entryData[0] = DIR_ENTRY_FREE; + _FAT_cache_writePartialSector (partition->cache, entryData, _FAT_fat_clusterToSector(partition, entryStart.cluster) + entryStart.sector, entryStart.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + if ((entryStart.cluster == entryEnd.cluster) && (entryStart.sector == entryEnd.sector) && (entryStart.offset == entryEnd.offset)) { + finished = true; + } + } + + if (!entryStillValid) { + return false; + } + + return true; +} + +static bool _FAT_directory_findEntryGap (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster, size_t size) { + DIR_ENTRY_POSITION gapStart; + DIR_ENTRY_POSITION gapEnd; + uint8_t entryData[DIR_ENTRY_DATA_SIZE]; + size_t dirEntryRemain; + bool endOfDirectory, entryStillValid; + + // Scan Dir for free entry + gapEnd.offset = 0; + gapEnd.sector = 0; + gapEnd.cluster = dirCluster; + + gapStart = gapEnd; + + entryStillValid = true; + dirEntryRemain = size; + endOfDirectory = false; + + while (entryStillValid && !endOfDirectory && (dirEntryRemain > 0)) { + _FAT_cache_readPartialSector (partition->cache, entryData, + _FAT_fat_clusterToSector(partition, gapEnd.cluster) + gapEnd.sector, + gapEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + if (entryData[0] == DIR_ENTRY_LAST) { + gapStart = gapEnd; + -- dirEntryRemain; + endOfDirectory = true; + } else if (entryData[0] == DIR_ENTRY_FREE) { + if (dirEntryRemain == size) { + gapStart = gapEnd; + } + -- dirEntryRemain; + } else { + dirEntryRemain = size; + } + + if (!endOfDirectory && (dirEntryRemain > 0)) { + entryStillValid = _FAT_directory_incrementDirEntryPosition (partition, &gapEnd, true); + } + } + + // Make sure the scanning didn't fail + if (!entryStillValid) { + return false; + } + + // Save the start entry, since we know it is valid + entry->dataStart = gapStart; + + if (endOfDirectory) { + memset (entryData, DIR_ENTRY_LAST, DIR_ENTRY_DATA_SIZE); + dirEntryRemain += 1; // Increase by one to take account of End Of Directory Marker + while ((dirEntryRemain > 0) && entryStillValid) { + // Get the gapEnd before incrementing it, so the second to last one is saved + entry->dataEnd = gapEnd; + // Increment gapEnd, moving onto the next entry + entryStillValid = _FAT_directory_incrementDirEntryPosition (partition, &gapEnd, true); + -- dirEntryRemain; + // Fill the entry with blanks + _FAT_cache_writePartialSector (partition->cache, entryData, + _FAT_fat_clusterToSector(partition, gapEnd.cluster) + gapEnd.sector, + gapEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + } + if (!entryStillValid) { + return false; + } + } else { + entry->dataEnd = gapEnd; + } + + return true; +} + +static bool _FAT_directory_entryExists (PARTITION* partition, const char* name, uint32_t dirCluster) { + DIR_ENTRY tempEntry; + bool foundFile; + char alias[MAX_ALIAS_LENGTH]; + size_t dirnameLength; + + dirnameLength = strnlen(name, MAX_FILENAME_LENGTH); + + if (dirnameLength >= MAX_FILENAME_LENGTH) { + return false; + } + + // Make sure the entry doesn't already exist + foundFile = _FAT_directory_getFirstEntry (partition, &tempEntry, dirCluster); + + while (foundFile) { // It hasn't already found the file + // Check if the filename matches + if ((dirnameLength == strnlen(tempEntry.filename, MAX_FILENAME_LENGTH)) + && (_FAT_directory_mbsncasecmp(name, tempEntry.filename, dirnameLength) == 0)) { + return true; + } + + // Check if the alias matches + _FAT_directory_entryGetAlias (tempEntry.entryData, alias); + if ((strncasecmp(name, alias, MAX_ALIAS_LENGTH) == 0)) { + return true; + } + foundFile = _FAT_directory_getNextEntry (partition, &tempEntry); + } + return false; +} + +/* +Creates an alias for a long file name. If the alias is not an exact match for the +filename, it returns the number of characters in the alias. If the two names match, +it returns 0. If there was an error, it returns -1. +*/ +static int _FAT_directory_createAlias (char* alias, const char* lfn) { + bool lossyConversion = false; // Set when the alias had to be modified to be valid + int lfnPos = 0; + int aliasPos = 0; + wchar_t lfnChar; + int oemChar; + mbstate_t ps = {0}; + int bytesUsed = 0; + const char* lfnExt; + int aliasExtLen; + + // Strip leading periods + while (lfn[lfnPos] == '.') { + lfnPos ++; + lossyConversion = true; + } + + // Primary portion of alias + while (aliasPos < 8 && lfn[lfnPos] != '.' && lfn[lfnPos] != '\0') { + bytesUsed = mbrtowc(&lfnChar, lfn + lfnPos, MAX_FILENAME_LENGTH - lfnPos, &ps); + if (bytesUsed < 0) { + return -1; + } + oemChar = wctob(towupper((wint_t)lfnChar)); + if (wctob((wint_t)lfnChar) != oemChar) { + // Case of letter was changed + lossyConversion = true; + } + if (oemChar == ' ') { + // Skip spaces in filename + lossyConversion = true; + lfnPos += bytesUsed; + continue; + } + if (oemChar == EOF) { + oemChar = '_'; // Replace unconvertable characters with underscores + lossyConversion = true; + } + if (strchr (ILLEGAL_ALIAS_CHARACTERS, oemChar) != NULL) { + // Invalid Alias character + oemChar = '_'; // Replace illegal characters with underscores + lossyConversion = true; + } + + alias[aliasPos] = (char)oemChar; + aliasPos++; + lfnPos += bytesUsed; + } + + if (lfn[lfnPos] != '.' && lfn[lfnPos] != '\0') { + // Name was more than 8 characters long + lossyConversion = true; + } + + // Alias extension + lfnExt = strrchr (lfn, '.'); + if (lfnExt != NULL && lfnExt != strchr (lfn, '.')) { + // More than one period in name + lossyConversion = true; + } + if (lfnExt != NULL && lfnExt[1] != '\0') { + lfnExt++; + alias[aliasPos] = '.'; + aliasPos++; + memset (&ps, 0, sizeof(ps)); + for (aliasExtLen = 0; aliasExtLen < MAX_ALIAS_EXT_LENGTH && *lfnExt != '\0'; aliasExtLen++) { + bytesUsed = mbrtowc(&lfnChar, lfnExt, MAX_FILENAME_LENGTH - lfnPos, &ps); + if (bytesUsed < 0) { + return -1; + } + oemChar = wctob(towupper((wint_t)lfnChar)); + if (wctob((wint_t)lfnChar) != oemChar) { + // Case of letter was changed + lossyConversion = true; + } + if (oemChar == ' ') { + // Skip spaces in alias + lossyConversion = true; + lfnExt += bytesUsed; + continue; + } + if (oemChar == EOF) { + oemChar = '_'; // Replace unconvertable characters with underscores + lossyConversion = true; + } + if (strchr (ILLEGAL_ALIAS_CHARACTERS, oemChar) != NULL) { + // Invalid Alias character + oemChar = '_'; // Replace illegal characters with underscores + lossyConversion = true; + } + + alias[aliasPos] = (char)oemChar; + aliasPos++; + lfnExt += bytesUsed; + } + if (*lfnExt != '\0') { + // Extension was more than 3 characters long + lossyConversion = true; + } + } + + alias[aliasPos] = '\0'; + if (lossyConversion) { + return aliasPos; + } else { + return 0; + } +} + +bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster) { + size_t entrySize; + uint8_t lfnEntry[DIR_ENTRY_DATA_SIZE]; + int i,j; // Must be signed for use when decrementing in for loop + char *tmpCharPtr; + DIR_ENTRY_POSITION curEntryPos; + bool entryStillValid; + uint8_t aliasCheckSum = 0; + char alias [MAX_ALIAS_LENGTH]; + int aliasLen; + int lfnLen; + + // Make sure the filename is not 0 length + if (strnlen (entry->filename, MAX_FILENAME_LENGTH) < 1) { + return false; + } + + // Make sure the filename is at least a valid LFN + lfnLen = _FAT_directory_lfnLength (entry->filename); + if (lfnLen < 0) { + return false; + } + + // Remove trailing spaces + for (i = strlen (entry->filename) - 1; (i > 0) && (entry->filename[i] == ' '); --i) { + entry->filename[i] = '\0'; + } + // Remove leading spaces + for (i = 0; (i < (int)strlen (entry->filename)) && (entry->filename[i] == ' '); ++i) ; + if (i > 0) { + memmove (entry->filename, entry->filename + i, strlen (entry->filename + i)); + } + + // Remove junk in filename + i = strlen (entry->filename); + memset (entry->filename + i, '\0', MAX_FILENAME_LENGTH - i); + + // Make sure the entry doesn't already exist + if (_FAT_directory_entryExists (partition, entry->filename, dirCluster)) { + return false; + } + + // Clear out alias, so we can generate a new one + memset (entry->entryData, ' ', 11); + + if ( strncmp(entry->filename, ".", MAX_FILENAME_LENGTH) == 0) { + // "." entry + entry->entryData[0] = '.'; + entrySize = 1; + } else if ( strncmp(entry->filename, "..", MAX_FILENAME_LENGTH) == 0) { + // ".." entry + entry->entryData[0] = '.'; + entry->entryData[1] = '.'; + entrySize = 1; + } else { + // Normal file name + aliasLen = _FAT_directory_createAlias (alias, entry->filename); + if (aliasLen < 0) { + return false; + } else if (aliasLen == 0) { + // It's a normal short filename + entrySize = 1; + } else { + // It's a long filename with an alias + entrySize = ((lfnLen + LFN_ENTRY_LENGTH - 1) / LFN_ENTRY_LENGTH) + 1; + + // Generate full alias for all cases except when the alias is simply an upper case version of the LFN + // and there isn't already a file with that name + if (strncasecmp (alias, entry->filename, MAX_ALIAS_LENGTH) != 0 || + _FAT_directory_entryExists (partition, alias, dirCluster)) + { + // expand primary part to 8 characters long by padding the end with underscores + i = MAX_ALIAS_PRI_LENGTH - 1; + // Move extension to last 3 characters + while (alias[i] != '.' && i > 0) i--; + if (i > 0) { + j = MAX_ALIAS_LENGTH - MAX_ALIAS_EXT_LENGTH - 2; // 1 char for '.', one for NUL, 3 for extension + memmove (alias + j, alias + i, strlen(alias) - i); + // Pad primary component + memset (alias + i, '_', j - i); + alias[MAX_ALIAS_LENGTH-1]=0; + } + + // Generate numeric tail + for (i = 1; i <= MAX_NUMERIC_TAIL; i++) { + j = i; + tmpCharPtr = alias + MAX_ALIAS_PRI_LENGTH - 1; + while (j > 0) { + *tmpCharPtr = '0' + (j % 10); // ASCII numeric value + tmpCharPtr--; + j /= 10; + } + *tmpCharPtr = '~'; + if (!_FAT_directory_entryExists (partition, alias, dirCluster)) { + break; + } + } + if (i > MAX_NUMERIC_TAIL) { + // Couldn't get a valid alias + return false; + } + } + } + + // Copy alias or short file name into directory entry data + for (i = 0, j = 0; (j < 8) && (alias[i] != '.') && (alias[i] != '\0'); i++, j++) { + entry->entryData[j] = alias[i]; + } + while (j < 8) { + entry->entryData[j] = ' '; + ++ j; + } + if (alias[i] == '.') { + // Copy extension + ++ i; + while ((alias[i] != '\0') && (j < 11)) { + entry->entryData[j] = alias[i]; + ++ i; + ++ j; + } + } + while (j < 11) { + entry->entryData[j] = ' '; + ++ j; + } + + // Generate alias checksum + for (i=0; i < ALIAS_ENTRY_LENGTH; i++) { + // NOTE: The operation is an unsigned char rotate right + aliasCheckSum = ((aliasCheckSum & 1) ? 0x80 : 0) + (aliasCheckSum >> 1) + entry->entryData[i]; + } + } + + // Find or create space for the entry + if (_FAT_directory_findEntryGap (partition, entry, dirCluster, entrySize) == false) { + return false; + } + + // Write out directory entry + curEntryPos = entry->dataStart; + + { + // lfn is only pushed onto the stack here, reducing overall stack usage + ucs2_t lfn[MAX_LFN_LENGTH] = {0}; + _FAT_directory_mbstoucs2 (lfn, entry->filename, MAX_LFN_LENGTH); + + for (entryStillValid = true, i = entrySize; entryStillValid && i > 0; + entryStillValid = _FAT_directory_incrementDirEntryPosition (partition, &curEntryPos, false), -- i ) + { + if (i > 1) { + // Long filename entry + lfnEntry[LFN_offset_ordinal] = (i - 1) | ((size_t)i == entrySize ? LFN_END : 0); + for (j = 0; j < 13; j++) { + if (lfn [(i - 2) * 13 + j] == '\0') { + if ((j > 1) && (lfn [(i - 2) * 13 + (j-1)] == '\0')) { + u16_to_u8array (lfnEntry, LFN_offset_table[j], 0xffff); // Padding + } else { + u16_to_u8array (lfnEntry, LFN_offset_table[j], 0x0000); // Terminating null character + } + } else { + u16_to_u8array (lfnEntry, LFN_offset_table[j], lfn [(i - 2) * 13 + j]); + } + } + + lfnEntry[LFN_offset_checkSum] = aliasCheckSum; + lfnEntry[LFN_offset_flag] = ATTRIB_LFN; + lfnEntry[LFN_offset_reserved1] = 0; + u16_to_u8array (lfnEntry, LFN_offset_reserved2, 0); + _FAT_cache_writePartialSector (partition->cache, lfnEntry, _FAT_fat_clusterToSector(partition, curEntryPos.cluster) + curEntryPos.sector, curEntryPos.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + } else { + // Alias & file data + _FAT_cache_writePartialSector (partition->cache, entry->entryData, _FAT_fat_clusterToSector(partition, curEntryPos.cluster) + curEntryPos.sector, curEntryPos.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + } + } + } + + return true; +} + +bool _FAT_directory_chdir (PARTITION* partition, const char* path) { + DIR_ENTRY entry; + + if (!_FAT_directory_entryFromPath (partition, &entry, path, NULL)) { + return false; + } + + if (!(entry.entryData[DIR_ENTRY_attributes] & ATTRIB_DIR)) { + return false; + } + + partition->cwdCluster = _FAT_directory_entryGetCluster (partition, entry.entryData); + + return true; +} + +void _FAT_directory_entryStat (PARTITION* partition, DIR_ENTRY* entry, struct stat *st) { + // Fill in the stat struct + // Some of the values are faked for the sake of compatibility + st->st_dev = _FAT_disc_hostType(partition->disc); // The device is the 32bit ioType value + st->st_ino = (ino_t)(_FAT_directory_entryGetCluster(partition, entry->entryData)); // The file serial number is the start cluster + st->st_mode = (_FAT_directory_isDirectory(entry) ? S_IFDIR : S_IFREG) | + (S_IRUSR | S_IRGRP | S_IROTH) | + (_FAT_directory_isWritable (entry) ? (S_IWUSR | S_IWGRP | S_IWOTH) : 0); // Mode bits based on dirEntry ATTRIB byte + st->st_nlink = 1; // Always one hard link on a FAT file + st->st_uid = 1; // Faked for FAT + st->st_gid = 2; // Faked for FAT + st->st_rdev = st->st_dev; + st->st_size = u8array_to_u32 (entry->entryData, DIR_ENTRY_fileSize); // File size + st->st_atime = _FAT_filetime_to_time_t ( + 0, + u8array_to_u16 (entry->entryData, DIR_ENTRY_aDate) + ); + st->st_spare1 = 0; + st->st_mtime = _FAT_filetime_to_time_t ( + u8array_to_u16 (entry->entryData, DIR_ENTRY_mTime), + u8array_to_u16 (entry->entryData, DIR_ENTRY_mDate) + ); + st->st_spare2 = 0; + st->st_ctime = _FAT_filetime_to_time_t ( + u8array_to_u16 (entry->entryData, DIR_ENTRY_cTime), + u8array_to_u16 (entry->entryData, DIR_ENTRY_cDate) + ); + st->st_spare3 = 0; + st->st_blksize = BYTES_PER_READ; // Prefered file I/O block size + st->st_blocks = (st->st_size + BYTES_PER_READ - 1) / BYTES_PER_READ; // File size in blocks + st->st_spare4[0] = 0; + st->st_spare4[1] = 0; +} diff --git a/libcustomfat/directory.h b/libcustomfat/directory.h new file mode 100644 index 00000000..93429217 --- /dev/null +++ b/libcustomfat/directory.h @@ -0,0 +1,178 @@ +/* + directory.h + Reading, writing and manipulation of the directory structure on + a FAT partition + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _DIRECTORY_H +#define _DIRECTORY_H + +#include + +#include "common.h" +#include "partition.h" + +#define DIR_ENTRY_DATA_SIZE 0x20 +#define MAX_LFN_LENGTH 256 +#define MAX_FILENAME_LENGTH 768 // 256 UCS-2 characters encoded into UTF-8 can use up to 768 UTF-8 chars +#define MAX_ALIAS_LENGTH 13 +#define LFN_ENTRY_LENGTH 13 +#define ALIAS_ENTRY_LENGTH 11 +#define MAX_ALIAS_EXT_LENGTH 3 +#define MAX_ALIAS_PRI_LENGTH 8 +#define MAX_NUMERIC_TAIL 999999 +#define FAT16_ROOT_DIR_CLUSTER 0 + +#define DIR_SEPARATOR '/' + +// File attributes +#define ATTRIB_ARCH 0x20 // Archive +#define ATTRIB_DIR 0x10 // Directory +#define ATTRIB_LFN 0x0F // Long file name +#define ATTRIB_VOL 0x08 // Volume +#define ATTRIB_SYS 0x04 // System +#define ATTRIB_HID 0x02 // Hidden +#define ATTRIB_RO 0x01 // Read only + +typedef enum {FT_DIRECTORY, FT_FILE} FILE_TYPE; + +typedef struct { + uint32_t cluster; + sec_t sector; + int32_t offset; +} DIR_ENTRY_POSITION; + +typedef struct { + uint8_t entryData[DIR_ENTRY_DATA_SIZE]; + DIR_ENTRY_POSITION dataStart; // Points to the start of the LFN entries of a file, or the alias for no LFN + DIR_ENTRY_POSITION dataEnd; // Always points to the file/directory's alias entry + char filename[MAX_FILENAME_LENGTH]; +} DIR_ENTRY; + +// Directory entry offsets +enum DIR_ENTRY_offset { + DIR_ENTRY_name = 0x00, + DIR_ENTRY_extension = 0x08, + DIR_ENTRY_attributes = 0x0B, + DIR_ENTRY_reserved = 0x0C, + DIR_ENTRY_cTime_ms = 0x0D, + DIR_ENTRY_cTime = 0x0E, + DIR_ENTRY_cDate = 0x10, + DIR_ENTRY_aDate = 0x12, + DIR_ENTRY_clusterHigh = 0x14, + DIR_ENTRY_mTime = 0x16, + DIR_ENTRY_mDate = 0x18, + DIR_ENTRY_cluster = 0x1A, + DIR_ENTRY_fileSize = 0x1C +}; + +/* +Returns true if the file specified by entry is a directory +*/ +static inline bool _FAT_directory_isDirectory (DIR_ENTRY* entry) { + return ((entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) != 0); +} + +static inline bool _FAT_directory_isWritable (DIR_ENTRY* entry) { + return ((entry->entryData[DIR_ENTRY_attributes] & ATTRIB_RO) == 0); +} + +static inline bool _FAT_directory_isDot (DIR_ENTRY* entry) { + return ((entry->filename[0] == '.') && ((entry->filename[1] == '\0') || + ((entry->filename[1] == '.') && entry->filename[2] == '\0'))); +} + +/* +Reads the first directory entry from the directory starting at dirCluster +Places result in entry +entry will be destroyed even if no directory entry is found +Returns true on success, false on failure +*/ +bool _FAT_directory_getFirstEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster); + +/* +Reads the next directory entry after the one already pointed to by entry +Places result in entry +entry will be destroyed even if no directory entry is found +Returns true on success, false on failure +*/ +bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry); + +/* +Gets the directory entry corrsponding to the supplied path +entry will be destroyed even if no directory entry is found +pathEnd specifies the end of the path string, for cutting strings short if needed + specify NULL to use the full length of path + pathEnd is only a suggestion, and the path string will be searched up until the next PATH_SEPARATOR + after pathEND. +Returns true on success, false on failure +*/ +bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const char* path, const char* pathEnd); + +/* +Changes the current directory to the one specified by path +Returns true on success, false on failure +*/ +bool _FAT_directory_chdir (PARTITION* partition, const char* path); + +/* +Removes the directory entry specified by entry +Assumes that entry is valid +Returns true on success, false on failure +*/ +bool _FAT_directory_removeEntry (PARTITION* partition, DIR_ENTRY* entry); + +/* +Add a directory entry to the directory specified by dirCluster +The fileData, dataStart and dataEnd elements of the DIR_ENTRY struct are +updated with the new directory entry position and alias. +Returns true on success, false on failure +*/ +bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster); + +/* +Get the start cluster of a file from it's entry data +*/ +uint32_t _FAT_directory_entryGetCluster (PARTITION* partition, const uint8_t* entryData); + +/* +Fill in the file name and entry data of DIR_ENTRY* entry. +Assumes that the entry's dataStart and dataEnd are correct +Returns true on success, false on failure +*/ +bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry); + +/* +Fill in a stat struct based on a file entry +*/ +void _FAT_directory_entryStat (PARTITION* partition, DIR_ENTRY* entry, struct stat *st); + +/* +Get volume label +*/ +bool _FAT_directory_getVolumeLabel (PARTITION* partition, char *label); + +#endif // _DIRECTORY_H diff --git a/libcustomfat/disc.c b/libcustomfat/disc.c new file mode 100644 index 00000000..1fac0ed9 --- /dev/null +++ b/libcustomfat/disc.c @@ -0,0 +1,105 @@ +/* + disc.c + Interface to the low level disc functions. Used by the higher level + file system code. + + Copyright (c) 2008 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "disc.h" + +/* +The list of interfaces consists of a series of name/interface pairs. +The interface is returned via a simple function. This allows for +platforms where the interface has to be "assembled" before it can +be used, like DLDI on the NDS. For cases where a simple struct +is available, wrapper functions are used. +The list is terminated by a NULL/NULL entry. +*/ + +/* ====================== Wii ====================== */ +#if defined (__wii__) +#include +#include +#include + +static const DISC_INTERFACE* get_io_wiisd (void) { + return &__io_wiisd; +} +static const DISC_INTERFACE* get_io_usbstorage (void) { + return &__io_usbstorage; +} + +static const DISC_INTERFACE* get_io_gcsda (void) { + return &__io_gcsda; +} +static const DISC_INTERFACE* get_io_gcsdb (void) { + return &__io_gcsdb; +} + +const INTERFACE_ID _FAT_disc_interfaces[] = { + {"sd", get_io_wiisd}, + {"usb", get_io_usbstorage}, + {"carda", get_io_gcsda}, + {"cardb", get_io_gcsdb}, + {NULL, NULL} +}; + +/* ==================== Gamecube ==================== */ +#elif defined (__gamecube__) +#include + +static const DISC_INTERFACE* get_io_gcsda (void) { + return &__io_gcsda; +} +static const DISC_INTERFACE* get_io_gcsdb (void) { + return &__io_gcsdb; +} + +const INTERFACE_ID _FAT_disc_interfaces[] = { + {"carda", get_io_gcsda}, + {"cardb", get_io_gcsdb}, + {NULL, NULL} +}; + +/* ====================== NDS ====================== */ +#elif defined (NDS) +#include + +const INTERFACE_ID _FAT_disc_interfaces[] = { + {"fat", dldiGetInternal}, + {NULL, NULL} +}; + +/* ====================== GBA ====================== */ +#elif defined (GBA) +#include + +const INTERFACE_ID _FAT_disc_interfaces[] = { + {"fat", discGetInterface}, + {NULL, NULL} +}; + +#endif + diff --git a/libcustomfat/disc.h b/libcustomfat/disc.h new file mode 100644 index 00000000..5c955f90 --- /dev/null +++ b/libcustomfat/disc.h @@ -0,0 +1,110 @@ +/* + disc.h + Interface to the low level disc functions. Used by the higher level + file system code. + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef _DISC_H +#define _DISC_H + +#include "common.h" + +/* +A list of all default devices to try at startup, +terminated by a {NULL,NULL} entry. +*/ +typedef struct { + const char* name; + const DISC_INTERFACE* (*getInterface)(void); +} INTERFACE_ID; +extern const INTERFACE_ID _FAT_disc_interfaces[]; + +/* +Check if a disc is inserted +Return true if a disc is inserted and ready, false otherwise +*/ +static inline bool _FAT_disc_isInserted (const DISC_INTERFACE* disc) { + return disc->isInserted(); +} + +/* +Read numSectors sectors from a disc, starting at sector. +numSectors is between 1 and LIMIT_SECTORS if LIMIT_SECTORS is defined, +else it is at least 1 +sector is 0 or greater +buffer is a pointer to the memory to fill +*/ +static inline bool _FAT_disc_readSectors (const DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, void* buffer) { + return disc->readSectors (sector, numSectors, buffer); +} + +/* +Write numSectors sectors to a disc, starting at sector. +numSectors is between 1 and LIMIT_SECTORS if LIMIT_SECTORS is defined, +else it is at least 1 +sector is 0 or greater +buffer is a pointer to the memory to read from +*/ +static inline bool _FAT_disc_writeSectors (const DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, const void* buffer) { + return disc->writeSectors (sector, numSectors, buffer); +} + +/* +Reset the card back to a ready state +*/ +static inline bool _FAT_disc_clearStatus (const DISC_INTERFACE* disc) { + return disc->clearStatus(); +} + +/* +Initialise the disc to a state ready for data reading or writing +*/ +static inline bool _FAT_disc_startup (const DISC_INTERFACE* disc) { + return disc->startup(); +} + +/* +Put the disc in a state ready for power down. +Complete any pending writes and disable the disc if necessary +*/ +static inline bool _FAT_disc_shutdown (const DISC_INTERFACE* disc) { + return disc->shutdown(); +} + +/* +Return a 32 bit value unique to each type of interface +*/ +static inline uint32_t _FAT_disc_hostType (const DISC_INTERFACE* disc) { + return disc->ioType; +} + +/* +Return a 32 bit value that specifies the capabilities of the disc +*/ +static inline uint32_t _FAT_disc_features (const DISC_INTERFACE* disc) { + return disc->features; +} + +#endif // _DISC_H diff --git a/libcustomfat/fat.h b/libcustomfat/fat.h new file mode 100644 index 00000000..82c973d3 --- /dev/null +++ b/libcustomfat/fat.h @@ -0,0 +1,104 @@ +/* + fat.h + Simple functionality for startup, mounting and unmounting of FAT-based devices. + + Copyright (c) 2006 - 2009 + Michael "Chishm" Chisholm + Dave "WinterMute" Murphy + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _LIBFAT_H +#define _LIBFAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +// When compiling for NDS, make sure NDS is defined +#ifndef NDS + #if defined ARM9 || defined ARM7 + #define NDS + #endif +#endif + +#include + +#if defined(__gamecube__) || defined (__wii__) +# include +#else +# ifdef NDS +# include "nds/disc_io.h" +# else +# include "disc_io.h" +# endif +#endif + +/* +Initialise any inserted block-devices. +Add the fat device driver to the devoptab, making it available for standard file functions. +cacheSize: The number of pages to allocate for each inserted block-device +setAsDefaultDevice: if true, make this the default device driver for file operations +*/ +extern bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice); + +/* +Calls fatInit with setAsDefaultDevice = true and cacheSize optimised for the host system. +*/ +extern bool fatInitDefault (void); + +/* +Mount the device pointed to by interface, and set up a devoptab entry for it as "name:". +You can then access the filesystem using "name:/". +This will mount the active partition or the first valid partition on the disc, +and will use a cache size optimized for the host system. +*/ +extern bool fatMountSimple (const char* name, const DISC_INTERFACE* interface); + +/* +Mount the device pointed to by interface, and set up a devoptab entry for it as "name:". +You can then access the filesystem using "name:/". +If startSector = 0, it will mount the active partition of the first valid partition on +the disc. Otherwise it will try to mount the partition starting at startSector. +cacheSize specifies the number of pages to allocate for the cache. +This will not startup the disc, so you need to call interface->startup(); first. +*/ +extern bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage); + +/* +Unmount the partition specified by name. +If there are open files, it will attempt to synchronise them to disc. +*/ +extern void fatUnmount (const char* name); + +/* +Get Volume Label +*/ +extern void fatGetVolumeLabel (const char* name, char *label); + +#ifdef __cplusplus +} +#endif + +#endif // _LIBFAT_H diff --git a/libcustomfat/fatdir.c b/libcustomfat/fatdir.c new file mode 100644 index 00000000..55faa0b9 --- /dev/null +++ b/libcustomfat/fatdir.c @@ -0,0 +1,610 @@ +/* + fatdir.c + + Functions used by the newlib disc stubs to interface with + this library + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include + +#include "fatdir.h" + +#include "cache.h" +#include "file_allocation_table.h" +#include "partition.h" +#include "directory.h" +#include "bit_ops.h" +#include "filetime.h" +#include "lock.h" + + +int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st) { + PARTITION* partition = NULL; + DIR_ENTRY dirEntry; + + // Get the partition this file is on + partition = _FAT_partition_getPartitionFromPath (path); + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + // Move the path pointer to the start of the actual path + if (strchr (path, ':') != NULL) { + path = strchr (path, ':') + 1; + } + if (strchr (path, ':') != NULL) { + r->_errno = EINVAL; + return -1; + } + + _FAT_lock(&partition->lock); + + // Search for the file on the disc + if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, NULL)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOENT; + return -1; + } + + // Fill in the stat struct + _FAT_directory_entryStat (partition, &dirEntry, st); + + _FAT_unlock(&partition->lock); + return 0; +} + +int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink) { + r->_errno = ENOTSUP; + return -1; +} + +int _FAT_unlink_r (struct _reent *r, const char *path) { + PARTITION* partition = NULL; + DIR_ENTRY dirEntry; + DIR_ENTRY dirContents; + uint32_t cluster; + bool nextEntry; + bool errorOccured = false; + + // Get the partition this directory is on + partition = _FAT_partition_getPartitionFromPath (path); + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + // Make sure we aren't trying to write to a read-only disc + if (partition->readOnly) { + r->_errno = EROFS; + return -1; + } + + // Move the path pointer to the start of the actual path + if (strchr (path, ':') != NULL) { + path = strchr (path, ':') + 1; + } + if (strchr (path, ':') != NULL) { + r->_errno = EINVAL; + return -1; + } + + _FAT_lock(&partition->lock); + + // Search for the file on the disc + if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, NULL)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOENT; + return -1; + } + + cluster = _FAT_directory_entryGetCluster (partition, dirEntry.entryData); + + + // If this is a directory, make sure it is empty + if (_FAT_directory_isDirectory (&dirEntry)) { + nextEntry = _FAT_directory_getFirstEntry (partition, &dirContents, cluster); + + while (nextEntry) { + if (!_FAT_directory_isDot (&dirContents)) { + // The directory had something in it that isn't a reference to itself or it's parent + _FAT_unlock(&partition->lock); + r->_errno = EPERM; + return -1; + } + nextEntry = _FAT_directory_getNextEntry (partition, &dirContents); + } + } + + if (_FAT_fat_isValidCluster(partition, cluster)) { + // Remove the cluster chain for this file + if (!_FAT_fat_clearLinks (partition, cluster)) { + r->_errno = EIO; + errorOccured = true; + } + } + + // Remove the directory entry for this file + if (!_FAT_directory_removeEntry (partition, &dirEntry)) { + r->_errno = EIO; + errorOccured = true; + } + + // Flush any sectors in the disc cache + if (!_FAT_cache_flush(partition->cache)) { + r->_errno = EIO; + errorOccured = true; + } + + _FAT_unlock(&partition->lock); + if (errorOccured) { + return -1; + } else { + return 0; + } +} + +int _FAT_chdir_r (struct _reent *r, const char *path) { + PARTITION* partition = NULL; + + // Get the partition this directory is on + partition = _FAT_partition_getPartitionFromPath (path); + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + // Move the path pointer to the start of the actual path + if (strchr (path, ':') != NULL) { + path = strchr (path, ':') + 1; + } + if (strchr (path, ':') != NULL) { + r->_errno = EINVAL; + return -1; + } + + _FAT_lock(&partition->lock); + + // Try changing directory + if (_FAT_directory_chdir (partition, path)) { + // Successful + _FAT_unlock(&partition->lock); + return 0; + } else { + // Failed + _FAT_unlock(&partition->lock); + r->_errno = ENOTDIR; + return -1; + } +} + +int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName) { + PARTITION* partition = NULL; + DIR_ENTRY oldDirEntry; + DIR_ENTRY newDirEntry; + const char *pathEnd; + uint32_t dirCluster; + + // Get the partition this directory is on + partition = _FAT_partition_getPartitionFromPath (oldName); + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + _FAT_lock(&partition->lock); + + // Make sure the same partition is used for the old and new names + if (partition != _FAT_partition_getPartitionFromPath (newName)) { + _FAT_unlock(&partition->lock); + r->_errno = EXDEV; + return -1; + } + + // Make sure we aren't trying to write to a read-only disc + if (partition->readOnly) { + _FAT_unlock(&partition->lock); + r->_errno = EROFS; + return -1; + } + + // Move the path pointer to the start of the actual path + if (strchr (oldName, ':') != NULL) { + oldName = strchr (oldName, ':') + 1; + } + if (strchr (oldName, ':') != NULL) { + _FAT_unlock(&partition->lock); + r->_errno = EINVAL; + return -1; + } + if (strchr (newName, ':') != NULL) { + newName = strchr (newName, ':') + 1; + } + if (strchr (newName, ':') != NULL) { + _FAT_unlock(&partition->lock); + r->_errno = EINVAL; + return -1; + } + + // Search for the file on the disc + if (!_FAT_directory_entryFromPath (partition, &oldDirEntry, oldName, NULL)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOENT; + return -1; + } + + // Make sure there is no existing file / directory with the new name + if (_FAT_directory_entryFromPath (partition, &newDirEntry, newName, NULL)) { + _FAT_unlock(&partition->lock); + r->_errno = EEXIST; + return -1; + } + + // Create the new file entry + // Get the directory it has to go in + pathEnd = strrchr (newName, DIR_SEPARATOR); + if (pathEnd == NULL) { + // No path was specified + dirCluster = partition->cwdCluster; + pathEnd = newName; + } else { + // Path was specified -- get the right dirCluster + // Recycling newDirEntry, since it needs to be recreated anyway + if (!_FAT_directory_entryFromPath (partition, &newDirEntry, newName, pathEnd) || + !_FAT_directory_isDirectory(&newDirEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOTDIR; + return -1; + } + dirCluster = _FAT_directory_entryGetCluster (partition, newDirEntry.entryData); + // Move the pathEnd past the last DIR_SEPARATOR + pathEnd += 1; + } + + // Copy the entry data + memcpy (&newDirEntry, &oldDirEntry, sizeof(DIR_ENTRY)); + + // Set the new name + strncpy (newDirEntry.filename, pathEnd, MAX_FILENAME_LENGTH - 1); + + // Write the new entry + if (!_FAT_directory_addEntry (partition, &newDirEntry, dirCluster)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOSPC; + return -1; + } + + // Remove the old entry + if (!_FAT_directory_removeEntry (partition, &oldDirEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = EIO; + return -1; + } + + // Flush any sectors in the disc cache + if (!_FAT_cache_flush (partition->cache)) { + _FAT_unlock(&partition->lock); + r->_errno = EIO; + return -1; + } + + _FAT_unlock(&partition->lock); + return 0; +} + +int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) { + PARTITION* partition = NULL; + bool fileExists; + DIR_ENTRY dirEntry; + const char* pathEnd; + uint32_t parentCluster, dirCluster; + uint8_t newEntryData[DIR_ENTRY_DATA_SIZE]; + + partition = _FAT_partition_getPartitionFromPath (path); + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + // Move the path pointer to the start of the actual path + if (strchr (path, ':') != NULL) { + path = strchr (path, ':') + 1; + } + if (strchr (path, ':') != NULL) { + r->_errno = EINVAL; + return -1; + } + + _FAT_lock(&partition->lock); + + // Search for the file/directory on the disc + fileExists = _FAT_directory_entryFromPath (partition, &dirEntry, path, NULL); + + // Make sure it doesn't exist + if (fileExists) { + _FAT_unlock(&partition->lock); + r->_errno = EEXIST; + return -1; + } + + if (partition->readOnly) { + // We can't write to a read-only partition + _FAT_unlock(&partition->lock); + r->_errno = EROFS; + return -1; + } + + // Get the directory it has to go in + pathEnd = strrchr (path, DIR_SEPARATOR); + if (pathEnd == NULL) { + // No path was specified + parentCluster = partition->cwdCluster; + pathEnd = path; + } else { + // Path was specified -- get the right parentCluster + // Recycling dirEntry, since it needs to be recreated anyway + if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, pathEnd) || + !_FAT_directory_isDirectory(&dirEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOTDIR; + return -1; + } + parentCluster = _FAT_directory_entryGetCluster (partition, dirEntry.entryData); + // Move the pathEnd past the last DIR_SEPARATOR + pathEnd += 1; + } + // Create the entry data + strncpy (dirEntry.filename, pathEnd, MAX_FILENAME_LENGTH - 1); + memset (dirEntry.entryData, 0, DIR_ENTRY_DATA_SIZE); + + // Set the creation time and date + dirEntry.entryData[DIR_ENTRY_cTime_ms] = 0; + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cTime, _FAT_filetime_getTimeFromRTC()); + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cDate, _FAT_filetime_getDateFromRTC()); + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_mTime, _FAT_filetime_getTimeFromRTC()); + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_mDate, _FAT_filetime_getDateFromRTC()); + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_aDate, _FAT_filetime_getDateFromRTC()); + + // Set the directory attribute + dirEntry.entryData[DIR_ENTRY_attributes] = ATTRIB_DIR; + + // Get a cluster for the new directory + dirCluster = _FAT_fat_linkFreeClusterCleared (partition, CLUSTER_FREE); + if (!_FAT_fat_isValidCluster(partition, dirCluster)) { + // No space left on disc for the cluster + _FAT_unlock(&partition->lock); + r->_errno = ENOSPC; + return -1; + } + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cluster, dirCluster); + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_clusterHigh, dirCluster >> 16); + + // Write the new directory's entry to it's parent + if (!_FAT_directory_addEntry (partition, &dirEntry, parentCluster)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOSPC; + return -1; + } + + // Create the dot entry within the directory + memset (newEntryData, 0, DIR_ENTRY_DATA_SIZE); + memset (newEntryData, ' ', 11); + newEntryData[DIR_ENTRY_name] = '.'; + newEntryData[DIR_ENTRY_attributes] = ATTRIB_DIR; + u16_to_u8array (newEntryData, DIR_ENTRY_cluster, dirCluster); + u16_to_u8array (newEntryData, DIR_ENTRY_clusterHigh, dirCluster >> 16); + + // Write it to the directory, erasing that sector in the process + _FAT_cache_eraseWritePartialSector ( partition->cache, newEntryData, + _FAT_fat_clusterToSector (partition, dirCluster), 0, DIR_ENTRY_DATA_SIZE); + + + // Create the double dot entry within the directory + + // if ParentDir == Rootdir then ".."" always link to Cluster 0 + if(parentCluster == partition->rootDirCluster) + parentCluster = FAT16_ROOT_DIR_CLUSTER; + + newEntryData[DIR_ENTRY_name + 1] = '.'; + u16_to_u8array (newEntryData, DIR_ENTRY_cluster, parentCluster); + u16_to_u8array (newEntryData, DIR_ENTRY_clusterHigh, parentCluster >> 16); + + // Write it to the directory + _FAT_cache_writePartialSector ( partition->cache, newEntryData, + _FAT_fat_clusterToSector (partition, dirCluster), DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + + // Flush any sectors in the disc cache + if (!_FAT_cache_flush(partition->cache)) { + _FAT_unlock(&partition->lock); + r->_errno = EIO; + return -1; + } + + _FAT_unlock(&partition->lock); + return 0; +} + +int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) +{ + PARTITION* partition = NULL; + unsigned int freeClusterCount; + + // Get the partition of the requested path + partition = _FAT_partition_getPartitionFromPath (path); + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + _FAT_lock(&partition->lock); + + freeClusterCount = _FAT_fat_freeClusterCount (partition); + + // FAT clusters = POSIX blocks + buf->f_bsize = partition->bytesPerCluster; // File system block size. + buf->f_frsize = partition->bytesPerCluster; // Fundamental file system block size. + + buf->f_blocks = partition->fat.lastCluster - CLUSTER_FIRST + 1; // Total number of blocks on file system in units of f_frsize. + buf->f_bfree = freeClusterCount; // Total number of free blocks. + buf->f_bavail = freeClusterCount; // Number of free blocks available to non-privileged process. + + // Treat requests for info on inodes as clusters + buf->f_files = partition->fat.lastCluster - CLUSTER_FIRST + 1; // Total number of file serial numbers. + buf->f_ffree = freeClusterCount; // Total number of free file serial numbers. + buf->f_favail = freeClusterCount; // Number of file serial numbers available to non-privileged process. + + // File system ID. 32bit ioType value + buf->f_fsid = _FAT_disc_hostType(partition->disc); + + // Bit mask of f_flag values. + buf->f_flag = ST_NOSUID /* No support for ST_ISUID and ST_ISGID file mode bits */ + | (partition->readOnly ? ST_RDONLY /* Read only file system */ : 0 ) ; + // Maximum filename length. + buf->f_namemax = MAX_FILENAME_LENGTH; + + _FAT_unlock(&partition->lock); + return 0; +} + +DIR_ITER* _FAT_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path) { + DIR_ENTRY dirEntry; + DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct); + bool fileExists; + + state->partition = _FAT_partition_getPartitionFromPath (path); + if (state->partition == NULL) { + r->_errno = ENODEV; + return NULL; + } + + // Move the path pointer to the start of the actual path + if (strchr (path, ':') != NULL) { + path = strchr (path, ':') + 1; + } + if (strchr (path, ':') != NULL) { + r->_errno = EINVAL; + return NULL; + } + + _FAT_lock(&state->partition->lock); + + // Get the start cluster of the directory + fileExists = _FAT_directory_entryFromPath (state->partition, &dirEntry, path, NULL); + + if (!fileExists) { + _FAT_unlock(&state->partition->lock); + r->_errno = ENOENT; + return NULL; + } + + // Make sure it is a directory + if (! _FAT_directory_isDirectory (&dirEntry)) { + _FAT_unlock(&state->partition->lock); + r->_errno = ENOTDIR; + return NULL; + } + + // Save the start cluster for use when resetting the directory data + state->startCluster = _FAT_directory_entryGetCluster (state->partition, dirEntry.entryData); + + // Get the first entry for use with a call to dirnext + state->validEntry = + _FAT_directory_getFirstEntry (state->partition, &(state->currentEntry), state->startCluster); + + // We are now using this entry + state->inUse = true; + _FAT_unlock(&state->partition->lock); + return (DIR_ITER*) state; +} + +int _FAT_dirreset_r (struct _reent *r, DIR_ITER *dirState) { + DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct); + + _FAT_lock(&state->partition->lock); + + // Make sure we are still using this entry + if (!state->inUse) { + _FAT_unlock(&state->partition->lock); + r->_errno = EBADF; + return -1; + } + + // Get the first entry for use with a call to dirnext + state->validEntry = + _FAT_directory_getFirstEntry (state->partition, &(state->currentEntry), state->startCluster); + + _FAT_unlock(&state->partition->lock); + return 0; +} + +int _FAT_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) { + DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct); + + _FAT_lock(&state->partition->lock); + + // Make sure we are still using this entry + if (!state->inUse) { + _FAT_unlock(&state->partition->lock); + r->_errno = EBADF; + return -1; + } + + // Make sure there is another file to report on + if (! state->validEntry) { + _FAT_unlock(&state->partition->lock); + r->_errno = ENOENT; + return -1; + } + + // Get the filename + strncpy (filename, state->currentEntry.filename, MAX_FILENAME_LENGTH); + // Get the stats, if requested + if (filestat != NULL) { + _FAT_directory_entryStat (state->partition, &(state->currentEntry), filestat); + } + + // Look for the next entry for use next time + state->validEntry = + _FAT_directory_getNextEntry (state->partition, &(state->currentEntry)); + + _FAT_unlock(&state->partition->lock); + return 0; +} + +int _FAT_dirclose_r (struct _reent *r, DIR_ITER *dirState) { + DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct); + + // We are no longer using this entry + _FAT_lock(&state->partition->lock); + state->inUse = false; + _FAT_unlock(&state->partition->lock); + + return 0; +} diff --git a/libcustomfat/fatdir.h b/libcustomfat/fatdir.h new file mode 100644 index 00000000..426dd30b --- /dev/null +++ b/libcustomfat/fatdir.h @@ -0,0 +1,73 @@ +/* + fatdir.h + + Functions used by the newlib disc stubs to interface with + this library + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _FATDIR_H +#define _FATDIR_H + +#include +#include +#include +#include +#include "common.h" +#include "directory.h" + +typedef struct { + PARTITION* partition; + DIR_ENTRY currentEntry; + uint32_t startCluster; + bool inUse; + bool validEntry; +} DIR_STATE_STRUCT; + +extern int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st); + +extern int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink); + +extern int _FAT_unlink_r (struct _reent *r, const char *name); + +extern int _FAT_chdir_r (struct _reent *r, const char *name); + +extern int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName); + +extern int _FAT_mkdir_r (struct _reent *r, const char *path, int mode); + +extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf); + +/* +Directory iterator functions +*/ +extern DIR_ITER* _FAT_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path); +extern int _FAT_dirreset_r (struct _reent *r, DIR_ITER *dirState); +extern int _FAT_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); +extern int _FAT_dirclose_r (struct _reent *r, DIR_ITER *dirState); + + +#endif // _FATDIR_H diff --git a/libcustomfat/fatfile.c b/libcustomfat/fatfile.c new file mode 100644 index 00000000..293707c1 --- /dev/null +++ b/libcustomfat/fatfile.c @@ -0,0 +1,1132 @@ +/* + fatfile.c + + Functions used by the newlib disc stubs to interface with + this library + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + 2009-10-23 oggzee: fixes for cluster aligned file size (write, truncate, seek) +*/ + + +#include "fatfile.h" + +#include +#include +#include +#include +#include + +#include "cache.h" +#include "file_allocation_table.h" +#include "bit_ops.h" +#include "filetime.h" +#include "lock.h" + +int _FAT_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) { + PARTITION* partition = NULL; + bool fileExists; + DIR_ENTRY dirEntry; + const char* pathEnd; + uint32_t dirCluster; + FILE_STRUCT* file = (FILE_STRUCT*) fileStruct; + partition = _FAT_partition_getPartitionFromPath (path); + + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + // Move the path pointer to the start of the actual path + if (strchr (path, ':') != NULL) { + path = strchr (path, ':') + 1; + } + if (strchr (path, ':') != NULL) { + r->_errno = EINVAL; + return -1; + } + + // Determine which mode the file is openned for + if ((flags & 0x03) == O_RDONLY) { + // Open the file for read-only access + file->read = true; + file->write = false; + file->append = false; + } else if ((flags & 0x03) == O_WRONLY) { + // Open file for write only access + file->read = false; + file->write = true; + file->append = false; + } else if ((flags & 0x03) == O_RDWR) { + // Open file for read/write access + file->read = true; + file->write = true; + file->append = false; + } else { + r->_errno = EACCES; + return -1; + } + + // Make sure we aren't trying to write to a read-only disc + if (file->write && partition->readOnly) { + r->_errno = EROFS; + return -1; + } + + // Search for the file on the disc + _FAT_lock(&partition->lock); + fileExists = _FAT_directory_entryFromPath (partition, &dirEntry, path, NULL); + + // The file shouldn't exist if we are trying to create it + if ((flags & O_CREAT) && (flags & O_EXCL) && fileExists) { + _FAT_unlock(&partition->lock); + r->_errno = EEXIST; + return -1; + } + + // It should not be a directory if we're openning a file, + if (fileExists && _FAT_directory_isDirectory(&dirEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = EISDIR; + return -1; + } + + // We haven't modified the file yet + file->modified = false; + + // If the file doesn't exist, create it if we're allowed to + if (!fileExists) { + if (flags & O_CREAT) { + if (partition->readOnly) { + // We can't write to a read-only partition + _FAT_unlock(&partition->lock); + r->_errno = EROFS; + return -1; + } + // Create the file + // Get the directory it has to go in + pathEnd = strrchr (path, DIR_SEPARATOR); + if (pathEnd == NULL) { + // No path was specified + dirCluster = partition->cwdCluster; + pathEnd = path; + } else { + // Path was specified -- get the right dirCluster + // Recycling dirEntry, since it needs to be recreated anyway + if (!_FAT_directory_entryFromPath (partition, &dirEntry, path, pathEnd) || + !_FAT_directory_isDirectory(&dirEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOTDIR; + return -1; + } + dirCluster = _FAT_directory_entryGetCluster (partition, dirEntry.entryData); + // Move the pathEnd past the last DIR_SEPARATOR + pathEnd += 1; + } + // Create the entry data + strncpy (dirEntry.filename, pathEnd, MAX_FILENAME_LENGTH - 1); + memset (dirEntry.entryData, 0, DIR_ENTRY_DATA_SIZE); + + // Set the creation time and date + dirEntry.entryData[DIR_ENTRY_cTime_ms] = 0; + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cTime, _FAT_filetime_getTimeFromRTC()); + u16_to_u8array (dirEntry.entryData, DIR_ENTRY_cDate, _FAT_filetime_getDateFromRTC()); + + if (!_FAT_directory_addEntry (partition, &dirEntry, dirCluster)) { + _FAT_unlock(&partition->lock); + r->_errno = ENOSPC; + return -1; + } + + // File entry is modified + file->modified = true; + } else { + // file doesn't exist, and we aren't creating it + _FAT_unlock(&partition->lock); + r->_errno = ENOENT; + return -1; + } + } + + file->filesize = u8array_to_u32 (dirEntry.entryData, DIR_ENTRY_fileSize); + + /* Allow LARGEFILEs with undefined results + // Make sure that the file size can fit in the available space + if (!(flags & O_LARGEFILE) && (file->filesize >= (1<<31))) { + r->_errno = EFBIG; + return -1; + } + */ + + // Make sure we aren't trying to write to a read-only file + if (file->write && !_FAT_directory_isWritable(&dirEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = EROFS; + return -1; + } + + // Associate this file with a particular partition + file->partition = partition; + + file->startCluster = _FAT_directory_entryGetCluster (partition, dirEntry.entryData); + + // Truncate the file if requested + if ((flags & O_TRUNC) && file->write && (file->startCluster != 0)) { + _FAT_fat_clearLinks (partition, file->startCluster); + file->startCluster = CLUSTER_FREE; + file->filesize = 0; + // File is modified since we just cut it all off + file->modified = true; + } + + // Remember the position of this file's directory entry + file->dirEntryStart = dirEntry.dataStart; // Points to the start of the LFN entries of a file, or the alias for no LFN + file->dirEntryEnd = dirEntry.dataEnd; + + // Reset read/write pointer + file->currentPosition = 0; + file->rwPosition.cluster = file->startCluster; + file->rwPosition.sector = 0; + file->rwPosition.byte = 0; + + if (flags & O_APPEND) { + file->append = true; + + // Set append pointer to the end of the file + file->appendPosition.cluster = _FAT_fat_lastCluster (partition, file->startCluster); + file->appendPosition.sector = (file->filesize % partition->bytesPerCluster) / BYTES_PER_READ; + file->appendPosition.byte = file->filesize % BYTES_PER_READ; + + // Check if the end of the file is on the end of a cluster + if ( (file->filesize > 0) && ((file->filesize % partition->bytesPerCluster)==0) ){ + // Set flag to allocate a new cluster + file->appendPosition.sector = partition->sectorsPerCluster; + file->appendPosition.byte = 0; + } + } else { + file->append = false; + // Use something sane for the append pointer, so the whole file struct contains known values + file->appendPosition = file->rwPosition; + } + + file->inUse = true; + + // Insert this file into the double-linked list of open files + partition->openFileCount += 1; + if (partition->firstOpenFile) { + file->nextOpenFile = partition->firstOpenFile; + partition->firstOpenFile->prevOpenFile = file; + } else { + file->nextOpenFile = NULL; + } + file->prevOpenFile = NULL; + partition->firstOpenFile = file; + + _FAT_unlock(&partition->lock); + + return (int) file; +} + +/* +Synchronizes the file data to disc. +Does no locking of its own -- lock the partition before calling. +Returns 0 on success, an error code on failure. +*/ +int _FAT_syncToDisc (FILE_STRUCT* file) { + uint8_t dirEntryData[DIR_ENTRY_DATA_SIZE]; + + if (!file || !file->inUse) { + return EBADF; + } + + if (file->write && file->modified) { + // Load the old entry + _FAT_cache_readPartialSector (file->partition->cache, dirEntryData, + _FAT_fat_clusterToSector(file->partition, file->dirEntryEnd.cluster) + file->dirEntryEnd.sector, + file->dirEntryEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + + // Write new data to the directory entry + // File size + u32_to_u8array (dirEntryData, DIR_ENTRY_fileSize, file->filesize); + + // Start cluster + u16_to_u8array (dirEntryData, DIR_ENTRY_cluster, file->startCluster); + u16_to_u8array (dirEntryData, DIR_ENTRY_clusterHigh, file->startCluster >> 16); + + // Modification time and date + u16_to_u8array (dirEntryData, DIR_ENTRY_mTime, _FAT_filetime_getTimeFromRTC()); + u16_to_u8array (dirEntryData, DIR_ENTRY_mDate, _FAT_filetime_getDateFromRTC()); + + // Access date + u16_to_u8array (dirEntryData, DIR_ENTRY_aDate, _FAT_filetime_getDateFromRTC()); + + // Set archive attribute + dirEntryData[DIR_ENTRY_attributes] |= ATTRIB_ARCH; + + // Write the new entry + _FAT_cache_writePartialSector (file->partition->cache, dirEntryData, + _FAT_fat_clusterToSector(file->partition, file->dirEntryEnd.cluster) + file->dirEntryEnd.sector, + file->dirEntryEnd.offset * DIR_ENTRY_DATA_SIZE, DIR_ENTRY_DATA_SIZE); + + // Flush any sectors in the disc cache + if (!_FAT_cache_flush(file->partition->cache)) { + return EIO; + } + } + + file->modified = false; + + return 0; +} + + +int _FAT_close_r (struct _reent *r, int fd) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + int ret = 0; + + if (!file->inUse) { + r->_errno = EBADF; + return -1; + } + + _FAT_lock(&file->partition->lock); + + if (file->write) { + ret = _FAT_syncToDisc (file); + if (ret != 0) { + r->_errno = ret; + ret = -1; + } + } + + file->inUse = false; + + // Remove this file from the double-linked list of open files + file->partition->openFileCount -= 1; + if (file->nextOpenFile) { + file->nextOpenFile->prevOpenFile = file->prevOpenFile; + } + if (file->prevOpenFile) { + file->prevOpenFile->nextOpenFile = file->nextOpenFile; + } else { + file->partition->firstOpenFile = file->nextOpenFile; + } + + _FAT_unlock(&file->partition->lock); + + return ret; +} + +ssize_t _FAT_read_r (struct _reent *r, int fd, char *ptr, size_t len) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + PARTITION* partition; + CACHE* cache; + FILE_POSITION position; + uint32_t tempNextCluster; + unsigned int tempVar; + size_t remain; + bool flagNoError = true; + + // Short circuit cases where len is 0 (or less) + if (len <= 0) { + return 0; + } + + // Make sure we can actually read from the file + if ((file == NULL) || !file->inUse || !file->read) { + r->_errno = EBADF; + return -1; + } + + partition = file->partition; + _FAT_lock(&partition->lock); + + // Don't try to read if the read pointer is past the end of file + if (file->currentPosition >= file->filesize || file->startCluster == CLUSTER_FREE) { + r->_errno = EOVERFLOW; + _FAT_unlock(&partition->lock); + return 0; + } + + // Don't read past end of file + if (len + file->currentPosition > file->filesize) { + r->_errno = EOVERFLOW; + len = file->filesize - file->currentPosition; + } + + remain = len; + position = file->rwPosition; + cache = file->partition->cache; + + // Align to sector + tempVar = BYTES_PER_READ - position.byte; + if (tempVar > remain) { + tempVar = remain; + } + + if ((tempVar < BYTES_PER_READ) && flagNoError) + { + _FAT_cache_readPartialSector ( cache, ptr, _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, + position.byte, tempVar); + + remain -= tempVar; + ptr += tempVar; + + position.byte += tempVar; + if (position.byte >= BYTES_PER_READ) { + position.byte = 0; + position.sector++; + } + } + + // align to cluster + // tempVar is number of sectors to read + if (remain > (partition->sectorsPerCluster - position.sector) * BYTES_PER_READ) { + tempVar = partition->sectorsPerCluster - position.sector; + } else { + tempVar = remain / BYTES_PER_READ; + } + + if ((tempVar > 0) && flagNoError) { + if (! _FAT_cache_readSectors (cache, _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, + tempVar, ptr)) + { + flagNoError = false; + r->_errno = EIO; + } else { + ptr += tempVar * BYTES_PER_READ; + remain -= tempVar * BYTES_PER_READ; + position.sector += tempVar; + } + } + + // Move onto next cluster + // It should get to here without reading anything if a cluster is due to be allocated + if ((position.sector >= partition->sectorsPerCluster) && flagNoError) { + tempNextCluster = _FAT_fat_nextCluster(partition, position.cluster); + if ((remain == 0) && (tempNextCluster == CLUSTER_EOF)) { + position.sector = partition->sectorsPerCluster; + } else if (!_FAT_fat_isValidCluster(partition, tempNextCluster)) { + r->_errno = EIO; + flagNoError = false; + } else { + position.sector = 0; + position.cluster = tempNextCluster; + } + } + + // Read in whole clusters, contiguous blocks at a time + while ((remain >= partition->bytesPerCluster) && flagNoError) { + uint32_t chunkEnd; + uint32_t nextChunkStart = position.cluster; + size_t chunkSize = 0; + + do { + chunkEnd = nextChunkStart; + nextChunkStart = _FAT_fat_nextCluster (partition, chunkEnd); + chunkSize += partition->bytesPerCluster; + } while ((nextChunkStart == chunkEnd + 1) && +#ifdef LIMIT_SECTORS + (chunkSize + partition->bytesPerCluster <= LIMIT_SECTORS * BYTES_PER_READ) && +#endif + (chunkSize + partition->bytesPerCluster <= remain)); + + if (!_FAT_cache_readSectors (cache, _FAT_fat_clusterToSector (partition, position.cluster), + chunkSize / BYTES_PER_READ, ptr)) + { + flagNoError = false; + r->_errno = EIO; + break; + } + ptr += chunkSize; + remain -= chunkSize; + + // Advance to next cluster + if ((remain == 0) && (nextChunkStart == CLUSTER_EOF)) { + position.sector = partition->sectorsPerCluster; + position.cluster = chunkEnd; + } else if (!_FAT_fat_isValidCluster(partition, nextChunkStart)) { + r->_errno = EIO; + flagNoError = false; + } else { + position.sector = 0; + position.cluster = nextChunkStart; + } + } + + // Read remaining sectors + tempVar = remain / BYTES_PER_READ; // Number of sectors left + if ((tempVar > 0) && flagNoError) { + if (!_FAT_cache_readSectors (cache, _FAT_fat_clusterToSector (partition, position.cluster), + tempVar, ptr)) + { + flagNoError = false; + r->_errno = EIO; + } else { + ptr += tempVar * BYTES_PER_READ; + remain -= tempVar * BYTES_PER_READ; + position.sector += tempVar; + } + } + + // Last remaining sector + // Check if anything is left + if ((remain > 0) && flagNoError) { + _FAT_cache_readPartialSector ( cache, ptr, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, 0, remain); + position.byte += remain; + remain = 0; + } + + // Length read is the wanted length minus the stuff not read + len = len - remain; + + // Update file information + file->rwPosition = position; + file->currentPosition += len; + + _FAT_unlock(&partition->lock); + return len; +} + +// if current position is on the cluster border and more data has to be written +// then get next cluster or allocate next cluster +// this solves the over-allocation problems when file size is aligned to cluster size +// return true on succes, false on error +static bool _FAT_check_position_for_next_cluster(struct _reent *r, + FILE_POSITION *position, PARTITION* partition, size_t remain, bool *flagNoError) +{ + uint32_t tempNextCluster; + // do nothing if no more data to write + if (remain == 0) return true; + if (flagNoError && *flagNoError == false) return false; + if ((remain < 0) || (position->sector > partition->sectorsPerCluster)) { + // invalid arguments - internal error + r->_errno = EINVAL; + goto err; + } + if (position->sector == partition->sectorsPerCluster) { + // need to advance to next cluster + tempNextCluster = _FAT_fat_nextCluster(partition, position->cluster); + if ((tempNextCluster == CLUSTER_EOF) || (tempNextCluster == CLUSTER_FREE)) { + // Ran out of clusters so get a new one + tempNextCluster = _FAT_fat_linkFreeCluster(partition, position->cluster); + } + if (!_FAT_fat_isValidCluster(partition, tempNextCluster)) { + // Couldn't get a cluster, so abort + r->_errno = ENOSPC; + goto err; + } + position->sector = 0; + position->cluster = tempNextCluster; + } + return true; +err: + if (flagNoError) *flagNoError = false; + return false; +} + +/* +Extend a file so that the size is the same as the rwPosition +*/ +static bool _FAT_file_extend_r (struct _reent *r, FILE_STRUCT* file) { + PARTITION* partition = file->partition; + CACHE* cache = file->partition->cache; + FILE_POSITION position; + uint8_t zeroBuffer [BYTES_PER_READ] = {0}; + uint32_t remain; + uint32_t tempNextCluster; + unsigned int sector; + + position.byte = file->filesize % BYTES_PER_READ; + position.sector = (file->filesize % partition->bytesPerCluster) / BYTES_PER_READ; + // It is assumed that there is always a startCluster + // This will be true when _FAT_file_extend_r is called from _FAT_write_r + position.cluster = _FAT_fat_lastCluster (partition, file->startCluster); + + remain = file->currentPosition - file->filesize; + + if ((remain > 0) && (file->filesize > 0) && (position.sector == 0) && (position.byte == 0)) { + // Get a new cluster on the edge of a cluster boundary + tempNextCluster = _FAT_fat_linkFreeCluster(partition, position.cluster); + if (!_FAT_fat_isValidCluster(partition, tempNextCluster)) { + // Couldn't get a cluster, so abort + r->_errno = ENOSPC; + return false; + } + position.cluster = tempNextCluster; + position.sector = 0; + } + + if (remain + position.byte < BYTES_PER_READ) { + // Only need to clear to the end of the sector + _FAT_cache_writePartialSector (cache, zeroBuffer, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, position.byte, remain); + position.byte += remain; + } else { + if (position.byte > 0) { + _FAT_cache_writePartialSector (cache, zeroBuffer, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, position.byte, + BYTES_PER_READ - position.byte); + remain -= (BYTES_PER_READ - position.byte); + position.byte = 0; + position.sector ++; + } + + while (remain >= BYTES_PER_READ) { + if (position.sector >= partition->sectorsPerCluster) { + position.sector = 0; + // Ran out of clusters so get a new one + tempNextCluster = _FAT_fat_linkFreeCluster(partition, position.cluster); + if (!_FAT_fat_isValidCluster(partition, tempNextCluster)) { + // Couldn't get a cluster, so abort + r->_errno = ENOSPC; + return false; + } + position.cluster = tempNextCluster; + } + + sector = _FAT_fat_clusterToSector (partition, position.cluster) + position.sector; + _FAT_cache_writeSectors (cache, sector, 1, zeroBuffer); + + remain -= BYTES_PER_READ; + position.sector ++; + } + + if (!_FAT_check_position_for_next_cluster(r, &position, partition, remain, NULL)) { + // error already marked + return false; + } + + if (remain > 0) { + _FAT_cache_writePartialSector (cache, zeroBuffer, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, 0, remain); + position.byte = remain; + } + } + + file->rwPosition = position; + file->filesize = file->currentPosition; + return true; +} + +ssize_t _FAT_write_r (struct _reent *r, int fd, const char *ptr, size_t len) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + PARTITION* partition; + CACHE* cache; + FILE_POSITION position; + uint32_t tempNextCluster; + unsigned int tempVar; + size_t remain; + bool flagNoError = true; + bool flagAppending = false; + + // Make sure we can actually write to the file + if ((file == NULL) || !file->inUse || !file->write) { + r->_errno = EBADF; + return -1; + } + + partition = file->partition; + cache = file->partition->cache; + _FAT_lock(&partition->lock); + + // Only write up to the maximum file size, taking into account wrap-around of ints + if (len + file->filesize > FILE_MAX_SIZE || len + file->filesize < file->filesize) { + len = FILE_MAX_SIZE - file->filesize; + } + + // Short circuit cases where len is 0 (or less) + if (len <= 0) { + _FAT_unlock(&partition->lock); + return 0; + } + + remain = len; + + // Get a new cluster for the start of the file if required + if (file->startCluster == CLUSTER_FREE) { + tempNextCluster = _FAT_fat_linkFreeCluster (partition, CLUSTER_FREE); + if (!_FAT_fat_isValidCluster(partition, tempNextCluster)) { + // Couldn't get a cluster, so abort immediately + _FAT_unlock(&partition->lock); + r->_errno = ENOSPC; + return -1; + } + file->startCluster = tempNextCluster; + + // Appending starts at the begining for a 0 byte file + file->appendPosition.cluster = file->startCluster; + file->appendPosition.sector = 0; + file->appendPosition.byte = 0; + + file->rwPosition.cluster = file->startCluster; + file->rwPosition.sector = 0; + file->rwPosition.byte = 0; + } + + if (file->append) { + position = file->appendPosition; + flagAppending = true; + } else { + // If the write pointer is past the end of the file, extend the file to that size + if (file->currentPosition > file->filesize) { + if (!_FAT_file_extend_r (r, file)) { + _FAT_unlock(&partition->lock); + return -1; + } + } + + // Write at current read pointer + position = file->rwPosition; + + // If it is writing past the current end of file, set appending flag + if (len + file->currentPosition > file->filesize) { + flagAppending = true; + } + } + + // Move onto next cluster if needed + _FAT_check_position_for_next_cluster(r, &position, partition, remain, &flagNoError); + + // Align to sector + tempVar = BYTES_PER_READ - position.byte; + if (tempVar > remain) { + tempVar = remain; + } + + if ((tempVar < BYTES_PER_READ) && flagNoError) { + // Write partial sector to disk + _FAT_cache_writePartialSector (cache, ptr, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, position.byte, tempVar); + + remain -= tempVar; + ptr += tempVar; + position.byte += tempVar; + + + // Move onto next sector + if (position.byte >= BYTES_PER_READ) { + position.byte = 0; + position.sector ++; + } + } + + // Align to cluster + // tempVar is number of sectors to write + if (remain > (partition->sectorsPerCluster - position.sector) * BYTES_PER_READ) { + tempVar = partition->sectorsPerCluster - position.sector; + } else { + tempVar = remain / BYTES_PER_READ; + } + + if ((tempVar > 0 && tempVar < partition->sectorsPerCluster) && flagNoError) { + if (!_FAT_cache_writeSectors (cache, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, tempVar, ptr)) + { + flagNoError = false; + r->_errno = EIO; + } else { + ptr += tempVar * BYTES_PER_READ; + remain -= tempVar * BYTES_PER_READ; + position.sector += tempVar; + } + } + + // Write whole clusters + while ((remain >= partition->bytesPerCluster) && flagNoError) { + // allocate next cluster + _FAT_check_position_for_next_cluster(r, &position, partition, remain, &flagNoError); + if (!flagNoError) break; + // set indexes to the current position + uint32_t chunkEnd = position.cluster; + uint32_t nextChunkStart = position.cluster; + size_t chunkSize = partition->bytesPerCluster; + FILE_POSITION next_position = position; + + // group consecutive clusters + while (flagNoError && +#ifdef LIMIT_SECTORS + (chunkSize + partition->bytesPerCluster <= LIMIT_SECTORS * BYTES_PER_READ) && +#endif + (chunkSize + partition->bytesPerCluster < remain)) + { + // pretend to use up all sectors in next_position + next_position.sector = partition->sectorsPerCluster; + // get or allocate next cluster + _FAT_check_position_for_next_cluster(r, &next_position, partition, + remain - chunkSize, &flagNoError); + if (!flagNoError) break; // exit loop on error + nextChunkStart = next_position.cluster; + if (nextChunkStart != chunkEnd + 1) break; // exit loop if not consecutive + chunkEnd = nextChunkStart; + chunkSize += partition->bytesPerCluster; + } + + if ( !_FAT_cache_writeSectors (cache, + _FAT_fat_clusterToSector(partition, position.cluster), chunkSize / BYTES_PER_READ, ptr)) + { + flagNoError = false; + r->_errno = EIO; + break; + } + ptr += chunkSize; + remain -= chunkSize; + + if ((chunkEnd != nextChunkStart) && _FAT_fat_isValidCluster(partition, nextChunkStart)) { + // new cluster is already allocated (because it was not consecutive) + position.cluster = nextChunkStart; + position.sector = 0; + } else { + // Allocate a new cluster when next writing the file + position.cluster = chunkEnd; + position.sector = partition->sectorsPerCluster; + } + } + + // allocate next cluster if needed + _FAT_check_position_for_next_cluster(r, &position, partition, remain, &flagNoError); + + // Write remaining sectors + tempVar = remain / BYTES_PER_READ; // Number of sectors left + if ((tempVar > 0) && flagNoError) { + if (!_FAT_cache_writeSectors (cache, _FAT_fat_clusterToSector (partition, position.cluster), tempVar, ptr)) + { + flagNoError = false; + r->_errno = EIO; + } else { + ptr += tempVar * BYTES_PER_READ; + remain -= tempVar * BYTES_PER_READ; + position.sector += tempVar; + } + } + + // Last remaining sector + if ((remain > 0) && flagNoError) { + if (flagAppending) { + _FAT_cache_eraseWritePartialSector ( cache, ptr, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, 0, remain); + } else { + _FAT_cache_writePartialSector ( cache, ptr, + _FAT_fat_clusterToSector (partition, position.cluster) + position.sector, 0, remain); + } + position.byte += remain; + remain = 0; + } + + + // Amount written is the originally requested amount minus stuff remaining + len = len - remain; + + // Update file information + file->modified = true; + if (file->append) { + // Appending doesn't affect the read pointer + file->appendPosition = position; + file->filesize += len; + } else { + // Writing also shifts the read pointer + file->rwPosition = position; + file->currentPosition += len; + if (file->filesize < file->currentPosition) { + file->filesize = file->currentPosition; + } + } + _FAT_unlock(&partition->lock); + + return len; +} + + +off_t _FAT_seek_r (struct _reent *r, int fd, off_t pos, int dir) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + PARTITION* partition; + uint32_t cluster, nextCluster; + int clusCount; + off_t newPosition; + uint32_t position; + + if ((file == NULL) || (file->inUse == false)) { + // invalid file + r->_errno = EBADF; + return -1; + } + + partition = file->partition; + _FAT_lock(&partition->lock); + + switch (dir) { + case SEEK_SET: + newPosition = pos; + break; + case SEEK_CUR: + newPosition = (off_t)file->currentPosition + pos; + break; + case SEEK_END: + newPosition = (off_t)file->filesize + pos; + break; + default: + _FAT_unlock(&partition->lock); + r->_errno = EINVAL; + return -1; + } + + if ((pos > 0) && (newPosition < 0)) { + _FAT_unlock(&partition->lock); + r->_errno = EOVERFLOW; + return -1; + } + + // newPosition can only be larger than the FILE_MAX_SIZE on platforms where + // off_t is larger than 32 bits. + if (newPosition < 0 || ((sizeof(newPosition) > 4) && newPosition > (off_t)FILE_MAX_SIZE)) { + _FAT_unlock(&partition->lock); + r->_errno = EINVAL; + return -1; + } + + position = (uint32_t)newPosition; + + // Only change the read/write position if it is within the bounds of the current filesize, + // or at the very edge of the file + if (position <= file->filesize && file->startCluster != CLUSTER_FREE) { + // Calculate where the correct cluster is + // how many clusters from start of file + clusCount = position / partition->bytesPerCluster; + cluster = file->startCluster; + if (position >= file->currentPosition) { + // start from current cluster + int currentCount = file->currentPosition / partition->bytesPerCluster; + if (file->rwPosition.sector == partition->sectorsPerCluster) { + currentCount--; + } + clusCount -= currentCount; + cluster = file->rwPosition.cluster; + } + // Calculate the sector and byte of the current position, + // and store them + file->rwPosition.sector = (position % partition->bytesPerCluster) / BYTES_PER_READ; + file->rwPosition.byte = position % BYTES_PER_READ; + + nextCluster = _FAT_fat_nextCluster (partition, cluster); + while ((clusCount > 0) && (nextCluster != CLUSTER_FREE) && (nextCluster != CLUSTER_EOF)) { + clusCount--; + cluster = nextCluster; + nextCluster = _FAT_fat_nextCluster (partition, cluster); + } + + // Check if ran out of clusters and it needs to allocate a new one + if (clusCount > 0) { + if ((clusCount == 1) && (file->filesize == position) && (file->rwPosition.sector == 0)) { + // Set flag to allocate a new cluster + file->rwPosition.sector = partition->sectorsPerCluster; + file->rwPosition.byte = 0; + } else { + _FAT_unlock(&partition->lock); + r->_errno = EINVAL; + return -1; + } + } + + file->rwPosition.cluster = cluster; + } + + // Save position + file->currentPosition = position; + + _FAT_unlock(&partition->lock); + return position; +} + + + +int _FAT_fstat_r (struct _reent *r, int fd, struct stat *st) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + PARTITION* partition; + DIR_ENTRY fileEntry; + + if ((file == NULL) || (file->inUse == false)) { + // invalid file + r->_errno = EBADF; + return -1; + } + + partition = file->partition; + _FAT_lock(&partition->lock); + + // Get the file's entry data + fileEntry.dataStart = file->dirEntryStart; + fileEntry.dataEnd = file->dirEntryEnd; + + if (!_FAT_directory_entryFromPosition (partition, &fileEntry)) { + _FAT_unlock(&partition->lock); + r->_errno = EIO; + return -1; + } + + // Fill in the stat struct + _FAT_directory_entryStat (partition, &fileEntry, st); + + // Fix stats that have changed since the file was openned + st->st_ino = (ino_t)(file->startCluster); // The file serial number is the start cluster + st->st_size = file->filesize; // File size + + _FAT_unlock(&partition->lock); + return 0; +} + +int _FAT_ftruncate_r (struct _reent *r, int fd, off_t len) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + PARTITION* partition; + int ret=0; + uint32_t newSize = (uint32_t)len; + + if (len < 0) { + // Trying to truncate to a negative size + r->_errno = EINVAL; + return -1; + } + + if ((sizeof(len) > 4) && len > (off_t)FILE_MAX_SIZE) { + // Trying to extend the file beyond what FAT supports + r->_errno = EFBIG; + return -1; + } + + if (!file || !file->inUse) { + // invalid file + r->_errno = EBADF; + return -1; + } + + if (!file->write) { + // Read-only file + r->_errno = EINVAL; + return -1; + } + + partition = file->partition; + _FAT_lock(&partition->lock); + + if (newSize > file->filesize) { + // Expanding the file + FILE_POSITION savedPosition; + uint32_t savedOffset; + // Get a new cluster for the start of the file if required + if (file->startCluster == CLUSTER_FREE) { + uint32_t tempNextCluster = _FAT_fat_linkFreeCluster (partition, CLUSTER_FREE); + if (!_FAT_fat_isValidCluster(partition, tempNextCluster)) { + // Couldn't get a cluster, so abort immediately + _FAT_unlock(&partition->lock); + r->_errno = ENOSPC; + return -1; + } + file->startCluster = tempNextCluster; + + file->rwPosition.cluster = file->startCluster; + file->rwPosition.sector = 0; + file->rwPosition.byte = 0; + } + // Save the read/write pointer + savedPosition = file->rwPosition; + savedOffset = file->currentPosition; + // Set the position to the new size + file->currentPosition = newSize; + // Extend the file to the new position + if (!_FAT_file_extend_r (r, file)) { + ret = -1; + } + // Set the append position to the new rwPointer + if (file->append) { + file->appendPosition = file->rwPosition; + } + // Restore the old rwPointer; + file->rwPosition = savedPosition; + file->currentPosition = savedOffset; + } else if (newSize < file->filesize){ + // Shrinking the file + if (len == 0) { + // Cutting the file down to nothing, clear all clusters used + _FAT_fat_clearLinks (partition, file->startCluster); + file->startCluster = CLUSTER_FREE; + + file->appendPosition.cluster = CLUSTER_FREE; + file->appendPosition.sector = 0; + file->appendPosition.byte = 0; + } else { + // Trimming the file down to the required size + unsigned int chainLength; + uint32_t lastCluster; + + // Drop the unneeded end of the cluster chain. + // If the end falls on a cluster boundary, drop that cluster too, + // then set a flag to allocate a cluster as needed + chainLength = ((newSize-1) / partition->bytesPerCluster) + 1; + lastCluster = _FAT_fat_trimChain (partition, file->startCluster, chainLength); + + if (file->append) { + file->appendPosition.byte = newSize % BYTES_PER_READ; + // Does the end of the file fall on the edge of a cluster? + if (newSize % partition->bytesPerCluster == 0) { + // Set a flag to allocate a new cluster + file->appendPosition.sector = partition->sectorsPerCluster; + } else { + file->appendPosition.sector = (newSize % partition->bytesPerCluster) / BYTES_PER_READ; + } + file->appendPosition.cluster = lastCluster; + } + } + } else { + // Truncating to same length, so don't do anything + } + + file->filesize = newSize; + file->modified = true; + + _FAT_unlock(&partition->lock); + return ret; +} + +int _FAT_fsync_r (struct _reent *r, int fd) { + FILE_STRUCT* file = (FILE_STRUCT*) fd; + int ret = 0; + + if (!file->inUse) { + r->_errno = EBADF; + return -1; + } + + _FAT_lock(&file->partition->lock); + + ret = _FAT_syncToDisc (file); + if (ret != 0) { + r->_errno = ret; + ret = -1; + } + + _FAT_unlock(&file->partition->lock); + + return ret; +} diff --git a/libcustomfat/fatfile.h b/libcustomfat/fatfile.h new file mode 100644 index 00000000..5e4648df --- /dev/null +++ b/libcustomfat/fatfile.h @@ -0,0 +1,105 @@ +/* + fatfile.h + + Functions used by the newlib disc stubs to interface with + this library + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#ifndef _FATFILE_H +#define _FATFILE_H + +#include +#include + +#include "common.h" +#include "partition.h" +#include "directory.h" + +#define FILE_MAX_SIZE ((uint32_t)0xFFFFFFFF) // 4GiB - 1B + +typedef struct { + u32 cluster; + sec_t sector; + s32 byte; +} FILE_POSITION; + +struct _FILE_STRUCT; + +struct _FILE_STRUCT { + uint32_t filesize; + uint32_t startCluster; + uint32_t currentPosition; + FILE_POSITION rwPosition; + FILE_POSITION appendPosition; + DIR_ENTRY_POSITION dirEntryStart; // Points to the start of the LFN entries of a file, or the alias for no LFN + DIR_ENTRY_POSITION dirEntryEnd; // Always points to the file's alias entry + PARTITION* partition; + struct _FILE_STRUCT* prevOpenFile; // The previous entry in a double-linked list of open files + struct _FILE_STRUCT* nextOpenFile; // The next entry in a double-linked list of open files + bool read; + bool write; + bool append; + bool inUse; + bool modified; +}; + +typedef struct _FILE_STRUCT FILE_STRUCT; + +int _FAT_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode); + +int _FAT_close_r (struct _reent *r, int fd); + +ssize_t _FAT_write_r (struct _reent *r,int fd, const char *ptr, size_t len); + +ssize_t _FAT_read_r (struct _reent *r, int fd, char *ptr, size_t len); + +off_t _FAT_seek_r (struct _reent *r, int fd, off_t pos, int dir); + +int _FAT_fstat_r (struct _reent *r, int fd, struct stat *st); + +int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st); + +int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink); + +int _FAT_unlink_r (struct _reent *r, const char *name); + +int _FAT_chdir_r (struct _reent *r, const char *name); + +int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName); + +int _FAT_ftruncate_r (struct _reent *r, int fd, off_t len); + +int _FAT_fsync_r (struct _reent *r, int fd); + +/* +Synchronizes the file data to disc. +Does no locking of its own -- lock the partition before calling. +Returns 0 on success, an error code on failure. +*/ +extern int _FAT_syncToDisc (FILE_STRUCT* file); + +#endif // _FATFILE_H diff --git a/libcustomfat/fatfile_frag.c b/libcustomfat/fatfile_frag.c new file mode 100644 index 00000000..3ec65b21 --- /dev/null +++ b/libcustomfat/fatfile_frag.c @@ -0,0 +1,63 @@ +#include "fatfile.h" + +#include +#include +#include +#include +#include + +#include "cache.h" +#include "file_allocation_table.h" +#include "bit_ops.h" +#include "filetime.h" +#include "lock.h" +#include "fatfile_frag.h" + +int _FAT_get_fragments (const char *path, _fat_frag_append_t append_fragment, void *callback_data) +{ + struct _reent r; + FILE_STRUCT file; + PARTITION* partition; + u32 cluster; + u32 sector; + u32 offset; // in sectors + u32 size; // in sectors + int ret = -1; + int fd; + + fd = _FAT_open_r (&r, &file, path, O_RDONLY, 0); + if (fd == -1) return -1; + if (fd != (int)&file) return -1; + + partition = file.partition; + _FAT_lock(&partition->lock); + + size = file.filesize / BYTES_PER_READ; + cluster = file.startCluster; + offset = 0; + + do { + if (!_FAT_fat_isValidCluster(partition, cluster)) { + // invalid cluster + goto out; + } + // add cluster to fileinfo + sector = _FAT_fat_clusterToSector(partition, cluster); + if (append_fragment(callback_data, offset, sector, partition->sectorsPerCluster)) { + // too many fragments + goto out; + } + offset += partition->sectorsPerCluster; + cluster = _FAT_fat_nextCluster (partition, cluster); + } while (offset < size); + + // set size + append_fragment(callback_data, size, 0, 0); + // success + ret = 0; + + out: + _FAT_unlock(&partition->lock); + _FAT_close_r(&r, fd); + return ret; +} diff --git a/source/libs/libfat/fatfile_frag.h b/libcustomfat/fatfile_frag.h similarity index 100% rename from source/libs/libfat/fatfile_frag.h rename to libcustomfat/fatfile_frag.h diff --git a/libcustomfat/file_allocation_table.c b/libcustomfat/file_allocation_table.c new file mode 100644 index 00000000..7edd7cb1 --- /dev/null +++ b/libcustomfat/file_allocation_table.c @@ -0,0 +1,383 @@ +/* + file_allocation_table.c + Reading, writing and manipulation of the FAT structure on + a FAT partition + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "file_allocation_table.h" +#include "partition.h" +#include + +/* +Gets the cluster linked from input cluster +*/ +uint32_t _FAT_fat_nextCluster(PARTITION* partition, uint32_t cluster) +{ + uint32_t nextCluster = CLUSTER_FREE; + sec_t sector; + int offset; + + if (cluster == CLUSTER_FREE) { + return CLUSTER_FREE; + } + + switch (partition->filesysType) + { + case FS_UNKNOWN: + return CLUSTER_ERROR; + break; + + case FS_FAT12: + { + u32 nextCluster_h; + sector = partition->fat.fatStart + (((cluster * 3) / 2) / BYTES_PER_READ); + offset = ((cluster * 3) / 2) % BYTES_PER_READ; + + + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u8)); + + offset++; + + if (offset >= BYTES_PER_READ) { + offset = 0; + sector++; + } + nextCluster_h = 0; + + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster_h, sector, offset, sizeof(u8)); + nextCluster |= (nextCluster_h << 8); + + if (cluster & 0x01) { + nextCluster = nextCluster >> 4; + } else { + nextCluster &= 0x0FFF; + } + + if (nextCluster >= 0x0FF7) + { + nextCluster = CLUSTER_EOF; + } + + break; + } + case FS_FAT16: + sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ); + offset = (cluster % (BYTES_PER_READ >> 1)) << 1; + + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u16)); + + if (nextCluster >= 0xFFF7) { + nextCluster = CLUSTER_EOF; + } + break; + + case FS_FAT32: + sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ); + offset = (cluster % (BYTES_PER_READ >> 2)) << 2; + + _FAT_cache_readLittleEndianValue (partition->cache, &nextCluster, sector, offset, sizeof(u32)); + + if (nextCluster >= 0x0FFFFFF7) { + nextCluster = CLUSTER_EOF; + } + break; + + default: + return CLUSTER_ERROR; + break; + } + + return nextCluster; +} + +/* +writes value into the correct offset within a partition's FAT, based +on the cluster number. +*/ +static bool _FAT_fat_writeFatEntry (PARTITION* partition, uint32_t cluster, uint32_t value) { + sec_t sector; + int offset; + uint32_t oldValue; + + if ((cluster < CLUSTER_FIRST) || (cluster > partition->fat.lastCluster /* This will catch CLUSTER_ERROR */)) + { + return false; + } + + switch (partition->filesysType) + { + case FS_UNKNOWN: + return false; + break; + + case FS_FAT12: + sector = partition->fat.fatStart + (((cluster * 3) / 2) / BYTES_PER_READ); + offset = ((cluster * 3) / 2) % BYTES_PER_READ; + + if (cluster & 0x01) { + + _FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8)); + + value = (value << 4) | (oldValue & 0x0F); + + _FAT_cache_writeLittleEndianValue (partition->cache, value & 0xFF, sector, offset, sizeof(u8)); + + offset++; + if (offset >= BYTES_PER_READ) { + offset = 0; + sector++; + } + + _FAT_cache_writeLittleEndianValue (partition->cache, (value >> 8) & 0xFF, sector, offset, sizeof(u8)); + + } else { + + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8)); + + offset++; + if (offset >= BYTES_PER_READ) { + offset = 0; + sector++; + } + + _FAT_cache_readLittleEndianValue (partition->cache, &oldValue, sector, offset, sizeof(u8)); + + value = ((value >> 8) & 0x0F) | (oldValue & 0xF0); + + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u8)); + } + + break; + + case FS_FAT16: + sector = partition->fat.fatStart + ((cluster << 1) / BYTES_PER_READ); + offset = (cluster % (BYTES_PER_READ >> 1)) << 1; + + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u16)); + + break; + + case FS_FAT32: + sector = partition->fat.fatStart + ((cluster << 2) / BYTES_PER_READ); + offset = (cluster % (BYTES_PER_READ >> 2)) << 2; + + _FAT_cache_writeLittleEndianValue (partition->cache, value, sector, offset, sizeof(u32)); + + break; + + default: + return false; + break; + } + + return true; +} + +/*----------------------------------------------------------------- +gets the first available free cluster, sets it +to end of file, links the input cluster to it then returns the +cluster number +If an error occurs, return CLUSTER_ERROR +-----------------------------------------------------------------*/ +uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster) { + uint32_t firstFree; + uint32_t curLink; + uint32_t lastCluster; + bool loopedAroundFAT = false; + + lastCluster = partition->fat.lastCluster; + + if (cluster > lastCluster) { + return CLUSTER_ERROR; + } + + // Check if the cluster already has a link, and return it if so + curLink = _FAT_fat_nextCluster(partition, cluster); + if ((curLink >= CLUSTER_FIRST) && (curLink <= lastCluster)) { + return curLink; // Return the current link - don't allocate a new one + } + + // Get a free cluster + firstFree = partition->fat.firstFree; + // Start at first valid cluster + if (firstFree < CLUSTER_FIRST) { + firstFree = CLUSTER_FIRST; + } + + // Search until a free cluster is found + while (_FAT_fat_nextCluster(partition, firstFree) != CLUSTER_FREE) { + firstFree++; + if (firstFree > lastCluster) { + if (loopedAroundFAT) { + // If couldn't get a free cluster then return an error + partition->fat.firstFree = firstFree; + return CLUSTER_ERROR; + } else { + // Try looping back to the beginning of the FAT + // This was suggested by loopy + firstFree = CLUSTER_FIRST; + loopedAroundFAT = true; + } + } + } + partition->fat.firstFree = firstFree; + + if ((cluster >= CLUSTER_FIRST) && (cluster <= lastCluster)) + { + // Update the linked from FAT entry + _FAT_fat_writeFatEntry (partition, cluster, firstFree); + } + // Create the linked to FAT entry + _FAT_fat_writeFatEntry (partition, firstFree, CLUSTER_EOF); + + return firstFree; +} + +/*----------------------------------------------------------------- +gets the first available free cluster, sets it +to end of file, links the input cluster to it, clears the new +cluster to 0 valued bytes, then returns the cluster number +If an error occurs, return CLUSTER_ERROR +-----------------------------------------------------------------*/ +uint32_t _FAT_fat_linkFreeClusterCleared (PARTITION* partition, uint32_t cluster) { + uint32_t newCluster; + uint32_t i; + uint8_t emptySector[BYTES_PER_READ]; + + // Link the cluster + newCluster = _FAT_fat_linkFreeCluster(partition, cluster); + + if (newCluster == CLUSTER_FREE || newCluster == CLUSTER_ERROR) { + return CLUSTER_ERROR; + } + + // Clear all the sectors within the cluster + memset (emptySector, 0, BYTES_PER_READ); + for (i = 0; i < partition->sectorsPerCluster; i++) { + _FAT_cache_writeSectors (partition->cache, + _FAT_fat_clusterToSector (partition, newCluster) + i, + 1, emptySector); + } + + return newCluster; +} + + +/*----------------------------------------------------------------- +_FAT_fat_clearLinks +frees any cluster used by a file +-----------------------------------------------------------------*/ +bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster) { + uint32_t nextCluster; + + if ((cluster < CLUSTER_FIRST) || (cluster > partition->fat.lastCluster /* This will catch CLUSTER_ERROR */)) + return false; + + // If this clears up more space in the FAT before the current free pointer, move it backwards + if (cluster < partition->fat.firstFree) { + partition->fat.firstFree = cluster; + } + + while ((cluster != CLUSTER_EOF) && (cluster != CLUSTER_FREE) && (cluster != CLUSTER_ERROR)) { + // Store next cluster before erasing the link + nextCluster = _FAT_fat_nextCluster (partition, cluster); + + // Erase the link + _FAT_fat_writeFatEntry (partition, cluster, CLUSTER_FREE); + + // Move onto next cluster + cluster = nextCluster; + } + + return true; +} + +/*----------------------------------------------------------------- +_FAT_fat_trimChain +Drop all clusters past the chainLength. +If chainLength is 0, all clusters are dropped. +If chainLength is 1, the first cluster is kept and the rest are +dropped, and so on. +Return the last cluster left in the chain. +-----------------------------------------------------------------*/ +uint32_t _FAT_fat_trimChain (PARTITION* partition, uint32_t startCluster, unsigned int chainLength) { + uint32_t nextCluster; + + if (chainLength == 0) { + // Drop the entire chain + _FAT_fat_clearLinks (partition, startCluster); + return CLUSTER_FREE; + } else { + // Find the last cluster in the chain, and the one after it + chainLength--; + nextCluster = _FAT_fat_nextCluster (partition, startCluster); + while ((chainLength > 0) && (nextCluster != CLUSTER_FREE) && (nextCluster != CLUSTER_EOF)) { + chainLength--; + startCluster = nextCluster; + nextCluster = _FAT_fat_nextCluster (partition, startCluster); + } + + // Drop all clusters after the last in the chain + if (nextCluster != CLUSTER_FREE && nextCluster != CLUSTER_EOF) { + _FAT_fat_clearLinks (partition, nextCluster); + } + + // Mark the last cluster in the chain as the end of the file + _FAT_fat_writeFatEntry (partition, startCluster, CLUSTER_EOF); + + return startCluster; + } +} + +/*----------------------------------------------------------------- +_FAT_fat_lastCluster +Trace the cluster links until the last one is found +-----------------------------------------------------------------*/ +uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster) { + while ((_FAT_fat_nextCluster(partition, cluster) != CLUSTER_FREE) && (_FAT_fat_nextCluster(partition, cluster) != CLUSTER_EOF)) { + cluster = _FAT_fat_nextCluster(partition, cluster); + } + return cluster; +} + +/*----------------------------------------------------------------- +_FAT_fat_freeClusterCount +Return the number of free clusters available +-----------------------------------------------------------------*/ +unsigned int _FAT_fat_freeClusterCount (PARTITION* partition) { + unsigned int count = 0; + uint32_t curCluster; + + for (curCluster = CLUSTER_FIRST; curCluster <= partition->fat.lastCluster; curCluster++) { + if (_FAT_fat_nextCluster(partition, curCluster) == CLUSTER_FREE) { + count++; + } + } + + return count; +} + diff --git a/libcustomfat/file_allocation_table.h b/libcustomfat/file_allocation_table.h new file mode 100644 index 00000000..560c616d --- /dev/null +++ b/libcustomfat/file_allocation_table.h @@ -0,0 +1,70 @@ +/* + file_allocation_table.h + Reading, writing and manipulation of the FAT structure on + a FAT partition + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _FAT_H +#define _FAT_H + +#include "common.h" +#include "partition.h" + +#define CLUSTER_EOF_16 0xFFFF +#define CLUSTER_EOF 0x0FFFFFFF +#define CLUSTER_FREE 0x00000000 +#define CLUSTER_ROOT 0x00000000 +#define CLUSTER_FIRST 0x00000002 +#define CLUSTER_ERROR 0xFFFFFFFF + +#define CLUSTERS_PER_FAT12 4085 +#define CLUSTERS_PER_FAT16 65525 + + +uint32_t _FAT_fat_nextCluster(PARTITION* partition, uint32_t cluster); + +uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster); +uint32_t _FAT_fat_linkFreeClusterCleared (PARTITION* partition, uint32_t cluster); + +bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster); + +uint32_t _FAT_fat_trimChain (PARTITION* partition, uint32_t startCluster, unsigned int chainLength); + +uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster); + +unsigned int _FAT_fat_freeClusterCount (PARTITION* partition); + +static inline sec_t _FAT_fat_clusterToSector (PARTITION* partition, uint32_t cluster) { + return (cluster >= CLUSTER_FIRST) ? + ((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart : + partition->rootDirStart; +} + +static inline bool _FAT_fat_isValidCluster (PARTITION* partition, uint32_t cluster) { + return (cluster >= CLUSTER_FIRST) && (cluster <= partition->fat.lastCluster /* This will catch CLUSTER_ERROR */); +} + +#endif // _FAT_H diff --git a/libcustomfat/filetime.c b/libcustomfat/filetime.c new file mode 100644 index 00000000..d297bf64 --- /dev/null +++ b/libcustomfat/filetime.c @@ -0,0 +1,107 @@ +/* + filetime.c + Conversion of file time and date values to various other types + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include +#include "filetime.h" +#include "common.h" + +#define MAX_HOUR 23 +#define MAX_MINUTE 59 +#define MAX_SECOND 59 + +#define MAX_MONTH 11 +#define MIN_MONTH 0 +#define MAX_DAY 31 +#define MIN_DAY 1 + +uint16_t _FAT_filetime_getTimeFromRTC (void) { +#ifdef USE_RTC_TIME + struct tm timeParts; + time_t epochTime; + + if (time(&epochTime) == (time_t)-1) { + return 0; + } + localtime_r(&epochTime, &timeParts); + + // Check that the values are all in range. + // If they are not, return 0 (no timestamp) + if ((timeParts.tm_hour < 0) || (timeParts.tm_hour > MAX_HOUR)) return 0; + if ((timeParts.tm_min < 0) || (timeParts.tm_min > MAX_MINUTE)) return 0; + if ((timeParts.tm_sec < 0) || (timeParts.tm_sec > MAX_SECOND)) return 0; + + return ( + ((timeParts.tm_hour & 0x1F) << 11) | + ((timeParts.tm_min & 0x3F) << 5) | + ((timeParts.tm_sec >> 1) & 0x1F) + ); +#else + return 0; +#endif +} + + +uint16_t _FAT_filetime_getDateFromRTC (void) { +#ifdef USE_RTC_TIME + struct tm timeParts; + time_t epochTime; + + if (time(&epochTime) == (time_t)-1) { + return 0; + } + localtime_r(&epochTime, &timeParts); + + if ((timeParts.tm_mon < MIN_MONTH) || (timeParts.tm_mon > MAX_MONTH)) return 0; + if ((timeParts.tm_mday < MIN_DAY) || (timeParts.tm_mday > MAX_DAY)) return 0; + + return ( + (((timeParts.tm_year - 80) & 0x7F) <<9) | // Adjust for MS-FAT base year (1980 vs 1900 for tm_year) + (((timeParts.tm_mon + 1) & 0xF) << 5) | + (timeParts.tm_mday & 0x1F) + ); +#else + return 0; +#endif +} + +time_t _FAT_filetime_to_time_t (uint16_t t, uint16_t d) { + struct tm timeParts; + + timeParts.tm_hour = t >> 11; + timeParts.tm_min = (t >> 5) & 0x3F; + timeParts.tm_sec = (t & 0x1F) << 1; + + timeParts.tm_mday = d & 0x1F; + timeParts.tm_mon = ((d >> 5) & 0x0F) - 1; + timeParts.tm_year = (d >> 9) + 80; + + timeParts.tm_isdst = 0; + + return mktime(&timeParts); +} diff --git a/libcustomfat/filetime.h b/libcustomfat/filetime.h new file mode 100644 index 00000000..3bfd8ed8 --- /dev/null +++ b/libcustomfat/filetime.h @@ -0,0 +1,41 @@ +/* + filetime.h + Conversion of file time and date values to various other types + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _FILETIME_H +#define _FILETIME_H + +#include "common.h" +#include + +uint16_t _FAT_filetime_getTimeFromRTC (void); +uint16_t _FAT_filetime_getDateFromRTC (void); + +time_t _FAT_filetime_to_time_t (uint16_t t, uint16_t d); + + +#endif // _FILETIME_H diff --git a/libcustomfat/libfat.c b/libcustomfat/libfat.c new file mode 100644 index 00000000..9f8dd014 --- /dev/null +++ b/libcustomfat/libfat.c @@ -0,0 +1,249 @@ +/* + libfat.c + Simple functionality for startup, mounting and unmounting of FAT-based devices. + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include + +#include "common.h" +#include "partition.h" +#include "fatfile.h" +#include "fatdir.h" +#include "lock.h" +#include "mem_allocate.h" +#include "disc.h" + +static const devoptab_t dotab_fat = { + "fat", + sizeof (FILE_STRUCT), + _FAT_open_r, + _FAT_close_r, + _FAT_write_r, + _FAT_read_r, + _FAT_seek_r, + _FAT_fstat_r, + _FAT_stat_r, + _FAT_link_r, + _FAT_unlink_r, + _FAT_chdir_r, + _FAT_rename_r, + _FAT_mkdir_r, + sizeof (DIR_STATE_STRUCT), + _FAT_diropen_r, + _FAT_dirreset_r, + _FAT_dirnext_r, + _FAT_dirclose_r, + _FAT_statvfs_r, + _FAT_ftruncate_r, + _FAT_fsync_r, + NULL, /* Device data */ + NULL, + NULL +}; + +bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage) { + PARTITION* partition; + devoptab_t* devops; + char* nameCopy; + + if(!name || strlen(name) > 8 || !interface) + return false; + + if(!interface->startup()) + return false; + + if(!interface->isInserted()) + return false; + + char devname[10]; + sprintf(devname, "%s:", name); + if(FindDevice(devname) >= 0) + return true; + + devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1); + if (!devops) { + return false; + } + // Use the space allocated at the end of the devoptab struct for storing the name + nameCopy = (char*)(devops+1); + + // Initialize the file system + partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector); + if (!partition) { + _FAT_mem_free (devops); + return false; + } + + // Add an entry for this device to the devoptab table + memcpy (devops, &dotab_fat, sizeof(dotab_fat)); + strcpy (nameCopy, name); + devops->name = nameCopy; + devops->deviceData = partition; + + AddDevice (devops); + + return true; +} + +bool fatMountSimple (const char* name, const DISC_INTERFACE* interface) { + return fatMount (name, interface, 0, DEFAULT_CACHE_PAGES, DEFAULT_SECTORS_PAGE); +} + +void fatUnmount (const char* name) { + devoptab_t *devops; + PARTITION* partition; + + if(!name) + return; + + devops = (devoptab_t*)GetDeviceOpTab (name); + if (!devops) { + return; + } + + // Perform a quick check to make sure we're dealing with a libfat controlled device + if (devops->open_r != dotab_fat.open_r) { + return; + } + + if (RemoveDevice (name) == -1) { + return; + } + + partition = (PARTITION*)devops->deviceData; + _FAT_partition_destructor (partition); + _FAT_mem_free (devops); +} + +bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) { + int i; + int defaultDevice = -1; + const DISC_INTERFACE *disc; + + for (i = 0; + _FAT_disc_interfaces[i].name != NULL && _FAT_disc_interfaces[i].getInterface != NULL; + i++) + { + disc = _FAT_disc_interfaces[i].getInterface(); + if (fatMount (_FAT_disc_interfaces[i].name, disc, 0, cacheSize, DEFAULT_SECTORS_PAGE)) { + // The first device to successfully mount is set as the default + if (defaultDevice < 0) { + defaultDevice = i; + } + } + } + + if (defaultDevice < 0) { + // None of our devices mounted + return false; + } + + if (setAsDefaultDevice) { + char filePath[MAXPATHLEN * 2]; + strcpy (filePath, _FAT_disc_interfaces[defaultDevice].name); + strcat (filePath, ":/"); +#ifdef ARGV_MAGIC + if ( __system_argv->argvMagic == ARGV_MAGIC && __system_argv->argc >= 1 && strrchr( __system_argv->argv[0], '/' )!=NULL ) { + // Check the app's path against each of our mounted devices, to see + // if we can support it. If so, change to that path. + for (i = 0; + _FAT_disc_interfaces[i].name != NULL && _FAT_disc_interfaces[i].getInterface != NULL; + i++) + { + if ( !strncasecmp( __system_argv->argv[0], _FAT_disc_interfaces[i].name, + strlen(_FAT_disc_interfaces[i].name))) + { + char *lastSlash; + strcpy(filePath, __system_argv->argv[0]); + lastSlash = strrchr( filePath, '/' ); + + if ( NULL != lastSlash) { + if ( *(lastSlash - 1) == ':') lastSlash++; + *lastSlash = 0; + } + } + } + } +#endif + chdir (filePath); + } + + return true; +} + +bool fatInitDefault (void) { + return fatInit (DEFAULT_CACHE_PAGES, true); +} + +void fatGetVolumeLabel (const char* name, char *label) { + devoptab_t *devops; + PARTITION* partition; + char *buf; + int namelen,i; + + if(!name || !label) + return; + + namelen = strlen(name); + buf=(char*)_FAT_mem_allocate(sizeof(char)*namelen+2); + strcpy(buf,name); + + if (name[namelen-1] == '/') { + buf[namelen-1]='\0'; + namelen--; + } + + if (name[namelen-1] != ':') { + buf[namelen]=':'; + buf[namelen+1]='\0'; + } + + devops = (devoptab_t*)GetDeviceOpTab(buf); + + for(i=0;buf[i]!='\0' && buf[i]!=':';i++); + if (!devops || strncasecmp(buf,devops->name,i)) { + _FAT_mem_free(buf); + return; + } + + _FAT_mem_free(buf); + + // Perform a quick check to make sure we're dealing with a libfat controlled device + if (devops->open_r != dotab_fat.open_r) { + return; + } + + partition = (PARTITION*)devops->deviceData; + + if(!_FAT_directory_getVolumeLabel(partition, label)) { + strncpy(label,partition->label,11); + label[11]='\0'; + } + if(!strncmp(label, "NO NAME", 7)) label[0]='\0'; +} diff --git a/libcustomfat/lock.c b/libcustomfat/lock.c new file mode 100644 index 00000000..59c3444c --- /dev/null +++ b/libcustomfat/lock.c @@ -0,0 +1,29 @@ +#include "common.h" + +#ifndef USE_LWP_LOCK + +#ifndef mutex_t +typedef int mutex_t; +#endif + +void __attribute__ ((weak)) _FAT_lock_init(mutex_t *mutex) +{ + return; +} + +void __attribute__ ((weak)) _FAT_lock_deinit(mutex_t *mutex) +{ + return; +} + +void __attribute__ ((weak)) _FAT_lock(mutex_t *mutex) +{ + return; +} + +void __attribute__ ((weak)) _FAT_unlock(mutex_t *mutex) +{ + return; +} + +#endif // USE_LWP_LOCK diff --git a/libcustomfat/lock.h b/libcustomfat/lock.h new file mode 100644 index 00000000..de5723a9 --- /dev/null +++ b/libcustomfat/lock.h @@ -0,0 +1,72 @@ +/* + lock.h + + Copyright (c) 2008 Sven Peter + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef _LOCK_H +#define _LOCK_H + +#include "common.h" + +#ifdef USE_LWP_LOCK + +static inline void _FAT_lock_init(mutex_t *mutex) +{ + LWP_MutexInit(mutex, false); +} + +static inline void _FAT_lock_deinit(mutex_t *mutex) +{ + LWP_MutexDestroy(*mutex); +} + +static inline void _FAT_lock(mutex_t *mutex) +{ + LWP_MutexLock(*mutex); +} + +static inline void _FAT_unlock(mutex_t *mutex) +{ + LWP_MutexUnlock(*mutex); +} + +#else + +// We still need a blank lock type +#ifndef mutex_t +typedef int mutex_t; +#endif + +void _FAT_lock_init(mutex_t *mutex); +void _FAT_lock_deinit(mutex_t *mutex); +void _FAT_lock(mutex_t *mutex); +void _FAT_unlock(mutex_t *mutex); + +#endif // USE_LWP_LOCK + + +#endif // _LOCK_H + diff --git a/libcustomfat/mem2.h b/libcustomfat/mem2.h new file mode 100644 index 00000000..b8fa93cf --- /dev/null +++ b/libcustomfat/mem2.h @@ -0,0 +1,27 @@ +// 2 MEM2 allocators, one for general purpose, one for covers +// Aligned and padded to 32 bytes, as required by many functions + +#ifndef __MEM2_H_ +#define __MEM2_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +void MEM2_init(unsigned int mem2Size); +void MEM2_cleanup(void); +void MEM2_takeBigOnes(bool b); +void *MEM2_alloc(unsigned int s); +void *MEM2_realloc(void *p, unsigned int s); +void MEM2_free(void *p); +unsigned int MEM2_usableSize(void *p); +unsigned int MEM2_freesize(); + +#ifdef __cplusplus +} +#endif + +#endif // !defined(__MEM2_H_) diff --git a/libcustomfat/mem_allocate.h b/libcustomfat/mem_allocate.h new file mode 100644 index 00000000..bf478c2c --- /dev/null +++ b/libcustomfat/mem_allocate.h @@ -0,0 +1,49 @@ +/* + mem_allocate.h + Memory allocation and destruction calls + Replace these calls with custom allocators if + malloc is unavailable + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _MEM_ALLOCATE_H +#define _MEM_ALLOCATE_H + +#include +#include "mem2.h" + +static inline void* _FAT_mem_allocate (size_t size) { + return MEM2_alloc(size); +} + +static inline void* _FAT_mem_align (size_t size) { + return MEM2_alloc(size); +} + +static inline void _FAT_mem_free (void* mem) { + MEM2_free(mem); +} + +#endif // _MEM_ALLOCATE_H diff --git a/libcustomfat/partition.c b/libcustomfat/partition.c new file mode 100644 index 00000000..1f55ef5b --- /dev/null +++ b/libcustomfat/partition.c @@ -0,0 +1,311 @@ +/* + partition.c + Functions for mounting and dismounting partitions + on various block devices. + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "partition.h" +#include "bit_ops.h" +#include "file_allocation_table.h" +#include "directory.h" +#include "mem_allocate.h" +#include "fatfile.h" + +#include +#include +#include + +sec_t _FAT_startSector; + +/* +This device name, as known by devkitPro toolchains +*/ +const char* DEVICE_NAME = "fat"; + +/* +Data offsets +*/ + +// BIOS Parameter Block offsets +enum BPB { + BPB_jmpBoot = 0x00, + BPB_OEMName = 0x03, + // BIOS Parameter Block + BPB_bytesPerSector = 0x0B, + BPB_sectorsPerCluster = 0x0D, + BPB_reservedSectors = 0x0E, + BPB_numFATs = 0x10, + BPB_rootEntries = 0x11, + BPB_numSectorsSmall = 0x13, + BPB_mediaDesc = 0x15, + BPB_sectorsPerFAT = 0x16, + BPB_sectorsPerTrk = 0x18, + BPB_numHeads = 0x1A, + BPB_numHiddenSectors = 0x1C, + BPB_numSectors = 0x20, + // Ext BIOS Parameter Block for FAT16 + BPB_FAT16_driveNumber = 0x24, + BPB_FAT16_reserved1 = 0x25, + BPB_FAT16_extBootSig = 0x26, + BPB_FAT16_volumeID = 0x27, + BPB_FAT16_volumeLabel = 0x2B, + BPB_FAT16_fileSysType = 0x36, + // Bootcode + BPB_FAT16_bootCode = 0x3E, + // FAT32 extended block + BPB_FAT32_sectorsPerFAT32 = 0x24, + BPB_FAT32_extFlags = 0x28, + BPB_FAT32_fsVer = 0x2A, + BPB_FAT32_rootClus = 0x2C, + BPB_FAT32_fsInfo = 0x30, + BPB_FAT32_bkBootSec = 0x32, + // Ext BIOS Parameter Block for FAT32 + BPB_FAT32_driveNumber = 0x40, + BPB_FAT32_reserved1 = 0x41, + BPB_FAT32_extBootSig = 0x42, + BPB_FAT32_volumeID = 0x43, + BPB_FAT32_volumeLabel = 0x47, + BPB_FAT32_fileSysType = 0x52, + // Bootcode + BPB_FAT32_bootCode = 0x5A, + BPB_bootSig_55 = 0x1FE, + BPB_bootSig_AA = 0x1FF +}; + +static const char FAT_SIG[3] = {'F', 'A', 'T'}; + + +sec_t FindFirstValidPartition(const DISC_INTERFACE* disc) +{ + uint8_t part_table[16*4]; + uint8_t *ptr; + int i; + + uint8_t sectorBuffer[BYTES_PER_READ] = {0}; + + // Read first sector of disc + if (!_FAT_disc_readSectors (disc, 0, 1, sectorBuffer)) { + return 0; + } + + memcpy(part_table,sectorBuffer+0x1BE,16*4); + ptr = part_table; + + for(i=0;i<4;i++,ptr+=16) { + sec_t part_lba = u8array_to_u32(ptr, 0x8); + + if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) || + !memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) { + return part_lba; + } + + if(ptr[4]==0) continue; + + if(ptr[4]==0x0F) { + sec_t part_lba2=part_lba; + sec_t next_lba2=0; + int n; + + for(n=0;n<8;n++) // max 8 logic partitions + { + if(!_FAT_disc_readSectors (disc, part_lba+next_lba2, 1, sectorBuffer)) return 0; + + part_lba2 = part_lba + next_lba2 + u8array_to_u32(sectorBuffer, 0x1C6) ; + next_lba2 = u8array_to_u32(sectorBuffer, 0x1D6); + + if(!_FAT_disc_readSectors (disc, part_lba2, 1, sectorBuffer)) return 0; + + if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) || + !memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) + { + return part_lba2; + } + + if(next_lba2==0) break; + } + } else { + if(!_FAT_disc_readSectors (disc, part_lba, 1, sectorBuffer)) return 0; + if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) || + !memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) { + return part_lba; + } + } + } + return 0; +} + +PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t sectorsPerPage, sec_t startSector) { + PARTITION* partition; + uint8_t sectorBuffer[BYTES_PER_READ] = {0}; + + // Read first sector of disc + if (!_FAT_disc_readSectors (disc, startSector, 1, sectorBuffer)) { + return NULL; + } + + // Make sure it is a valid MBR or boot sector + if ( (sectorBuffer[BPB_bootSig_55] != 0x55) || (sectorBuffer[BPB_bootSig_AA] != 0xAA)) { + return NULL; + } + + if (startSector != 0) { + // We're told where to start the partition, so just accept it + } else if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG))) { + // Check if there is a FAT string, which indicates this is a boot sector + startSector = 0; + } else if (!memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) { + // Check for FAT32 + startSector = 0; + } else { + startSector = FindFirstValidPartition(disc); + if (!_FAT_disc_readSectors (disc, startSector, 1, sectorBuffer)) { + return NULL; + } + } + + // Now verify that this is indeed a FAT partition + if (memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG)) && + memcmp(sectorBuffer + BPB_FAT32_fileSysType, FAT_SIG, sizeof(FAT_SIG))) + { + return NULL; + } + + partition = (PARTITION*) _FAT_mem_allocate (sizeof(PARTITION)); + if (partition == NULL) { + return NULL; + } + + // Init the partition lock + _FAT_lock_init(&partition->lock); + + _FAT_startSector = startSector; + + if (!memcmp(sectorBuffer + BPB_FAT16_fileSysType, FAT_SIG, sizeof(FAT_SIG))) + strncpy(partition->label, (char*)(sectorBuffer + BPB_FAT16_volumeLabel), 11); + else + strncpy(partition->label, (char*)(sectorBuffer + BPB_FAT32_volumeLabel), 11); + partition->label[11] = '\0'; + + // Set partition's disc interface + partition->disc = disc; + + // Store required information about the file system + partition->fat.sectorsPerFat = u8array_to_u16(sectorBuffer, BPB_sectorsPerFAT); + if (partition->fat.sectorsPerFat == 0) { + partition->fat.sectorsPerFat = u8array_to_u32( sectorBuffer, BPB_FAT32_sectorsPerFAT32); + } + + partition->numberOfSectors = u8array_to_u16( sectorBuffer, BPB_numSectorsSmall); + if (partition->numberOfSectors == 0) { + partition->numberOfSectors = u8array_to_u32( sectorBuffer, BPB_numSectors); + } + + partition->bytesPerSector = BYTES_PER_READ; // Sector size is redefined to be 512 bytes + partition->sectorsPerCluster = sectorBuffer[BPB_sectorsPerCluster] * u8array_to_u16(sectorBuffer, BPB_bytesPerSector) / BYTES_PER_READ; + partition->bytesPerCluster = partition->bytesPerSector * partition->sectorsPerCluster; + partition->fat.fatStart = startSector + u8array_to_u16(sectorBuffer, BPB_reservedSectors); + + partition->rootDirStart = partition->fat.fatStart + (sectorBuffer[BPB_numFATs] * partition->fat.sectorsPerFat); + partition->dataStart = partition->rootDirStart + + (( u8array_to_u16(sectorBuffer, BPB_rootEntries) * DIR_ENTRY_DATA_SIZE) / partition->bytesPerSector); + + partition->totalSize = ((uint64_t)partition->numberOfSectors - (partition->dataStart - startSector)) * (uint64_t)partition->bytesPerSector; + + // Store info about FAT + uint32_t clusterCount = (partition->numberOfSectors - (uint32_t)(partition->dataStart - startSector)) / partition->sectorsPerCluster; + partition->fat.lastCluster = clusterCount + CLUSTER_FIRST - 1; + partition->fat.firstFree = CLUSTER_FIRST; + + if (clusterCount < CLUSTERS_PER_FAT12) { + partition->filesysType = FS_FAT12; // FAT12 volume + } else if (clusterCount < CLUSTERS_PER_FAT16) { + partition->filesysType = FS_FAT16; // FAT16 volume + } else { + partition->filesysType = FS_FAT32; // FAT32 volume + } + + if (partition->filesysType != FS_FAT32) { + partition->rootDirCluster = FAT16_ROOT_DIR_CLUSTER; + } else { + // Set up for the FAT32 way + partition->rootDirCluster = u8array_to_u32(sectorBuffer, BPB_FAT32_rootClus); + // Check if FAT mirroring is enabled + if (!(sectorBuffer[BPB_FAT32_extFlags] & 0x80)) { + // Use the active FAT + partition->fat.fatStart = partition->fat.fatStart + ( partition->fat.sectorsPerFat * (sectorBuffer[BPB_FAT32_extFlags] & 0x0F)); + } + } + + // Create a cache to use + partition->cache = _FAT_cache_constructor (cacheSize, sectorsPerPage, partition->disc, startSector+partition->numberOfSectors); + + // Set current directory to the root + partition->cwdCluster = partition->rootDirCluster; + + // Check if this disc is writable, and set the readOnly property appropriately + partition->readOnly = !(_FAT_disc_features(disc) & FEATURE_MEDIUM_CANWRITE); + + // There are currently no open files on this partition + partition->openFileCount = 0; + partition->firstOpenFile = NULL; + + return partition; +} + +void _FAT_partition_destructor (PARTITION* partition) { + FILE_STRUCT* nextFile; + + _FAT_lock(&partition->lock); + + // Synchronize open files + nextFile = partition->firstOpenFile; + while (nextFile) { + _FAT_syncToDisc (nextFile); + nextFile = nextFile->nextOpenFile; + } + + // Free memory used by the cache, writing it to disc at the same time + _FAT_cache_destructor (partition->cache); + + // Unlock the partition and destroy the lock + _FAT_unlock(&partition->lock); + _FAT_lock_deinit(&partition->lock); + + // Free memory used by the partition + _FAT_mem_free (partition); +} + +PARTITION* _FAT_partition_getPartitionFromPath (const char* path) { + const devoptab_t *devops; + + devops = GetDeviceOpTab (path); + + if (!devops) { + return NULL; + } + + return (PARTITION*)devops->deviceData; +} diff --git a/libcustomfat/partition.h b/libcustomfat/partition.h new file mode 100644 index 00000000..52e6648d --- /dev/null +++ b/libcustomfat/partition.h @@ -0,0 +1,89 @@ +/* + partition.h + Functions for mounting and dismounting partitions + on various block devices. + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _PARTITION_H +#define _PARTITION_H + +#include "common.h" +#include "cache.h" +#include "lock.h" + +// Device name +extern const char* DEVICE_NAME; + +// Filesystem type +typedef enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} FS_TYPE; + +typedef struct { + sec_t fatStart; + uint32_t sectorsPerFat; + uint32_t lastCluster; + uint32_t firstFree; +} FAT; + +typedef struct { + const DISC_INTERFACE* disc; + CACHE* cache; + // Info about the partition + FS_TYPE filesysType; + uint64_t totalSize; + sec_t rootDirStart; + uint32_t rootDirCluster; + uint32_t numberOfSectors; + sec_t dataStart; + uint32_t bytesPerSector; + uint32_t sectorsPerCluster; + uint32_t bytesPerCluster; + FAT fat; + // Values that may change after construction + uint32_t cwdCluster; // Current working directory cluster + int openFileCount; + struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files + mutex_t lock; // A lock for partition operations + bool readOnly; // If this is set, then do not try writing to the disc + char label[12]; // Volume label +} PARTITION; + +/* +Mount the supplied device and return a pointer to the struct necessary to use it +*/ +PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t SectorsPerPage, sec_t startSector); + +/* +Dismount the device and free all structures used. +Will also attempt to synchronise all open files to disc. +*/ +void _FAT_partition_destructor (PARTITION* partition); + +/* +Return the partition specified in a path, as taken from the devoptab. +*/ +PARTITION* _FAT_partition_getPartitionFromPath (const char* path); + +#endif // _PARTITION_H diff --git a/libcustomntfs/Makefile b/libcustomntfs/Makefile new file mode 100644 index 00000000..cad3aa6b --- /dev/null +++ b/libcustomntfs/Makefile @@ -0,0 +1,32 @@ +# Quick'n'dirty makefile [BC] v2 + +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +endif + +include $(DEVKITPPC)/wii_rules + +LIBOGC_INC := $(DEVKITPRO)/libogc/include +LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii + +CFLAGS := -O3 $(MACHDEP) -I$(LIBOGC_INC) -DHAVE_CONFIG_H + +LIB := ntfs +CFILES := $(wildcard *.c) +OFILES := $(CFILES:.c=.o) +ARC := lib$(LIB).a +HDR := ntfs.h + +all : $(OFILES) + $(AR) -r $(ARC) $(OFILES) + +clean : + rm -f $(OFILES) $(ARC) + +install : + mkdir -p $(LIBOGC_LIB) $(LIBOGC_INC) + cp -f $(ARC) $(LIBOGC_LIB)/ + cp -f $(HDR) $(LIBOGC_INC)/ + +%.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ \ No newline at end of file diff --git a/libcustomntfs/acls.c b/libcustomntfs/acls.c new file mode 100644 index 00000000..76cc6ce5 --- /dev/null +++ b/libcustomntfs/acls.c @@ -0,0 +1,4293 @@ +/** + * acls.c - General function to process NTFS ACLs + * + * This module is part of ntfs-3g library, but may also be + * integrated in tools running over Linux or Windows + * + * Copyright (c) 2007-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H + /* + * integration into ntfs-3g + */ +#include "config.h" + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_SYSLOG_H +#include +#endif +#include +#include +#include + +#include "types.h" +#include "layout.h" +#include "security.h" +#include "acls.h" +#include "misc.h" +#else + + /* + * integration into secaudit, check whether Win32, + * may have to be adapted to compiler or something else + */ + +#ifndef WIN32 +#if defined(__WIN32) | defined(__WIN32__) | defined(WNSC) +#define WIN32 1 +#endif +#endif + +#include +#include +#include +#include +#include +#include +#include + + /* + * integration into secaudit/Win32 + */ +#ifdef WIN32 +#include +#include +#define __LITTLE_ENDIAN 1234 +#define __BYTE_ORDER __LITTLE_ENDIAN +#else + /* + * integration into secaudit/STSC + */ +#ifdef STSC +#include +#undef __BYTE_ORDER +#define __BYTE_ORDER __BIG_ENDIAN +#else + /* + * integration into secaudit/Linux + */ +#include +#include +#include +#include +#endif /* STSC */ +#endif /* WIN32 */ +#include "secaudit.h" +#endif /* HAVE_CONFIG_H */ + +/* + * A few useful constants + */ + +/* + * null SID (S-1-0-0) + */ + +static const char nullsidbytes[] = { + 1, /* revision */ + 1, /* auth count */ + 0, 0, 0, 0, 0, 0, /* base */ + 0, 0, 0, 0 /* 1st level */ + }; + +static const SID *nullsid = (const SID*)nullsidbytes; + +/* + * SID for world (S-1-1-0) + */ + +static const char worldsidbytes[] = { + 1, /* revision */ + 1, /* auth count */ + 0, 0, 0, 0, 0, 1, /* base */ + 0, 0, 0, 0 /* 1st level */ +} ; + +const SID *worldsid = (const SID*)worldsidbytes; + +/* + * SID for administrator + */ + +static const char adminsidbytes[] = { + 1, /* revision */ + 2, /* auth count */ + 0, 0, 0, 0, 0, 5, /* base */ + 32, 0, 0, 0, /* 1st level */ + 32, 2, 0, 0 /* 2nd level */ +}; + +const SID *adminsid = (const SID*)adminsidbytes; + +/* + * SID for system + */ + +static const char systemsidbytes[] = { + 1, /* revision */ + 1, /* auth count */ + 0, 0, 0, 0, 0, 5, /* base */ + 18, 0, 0, 0 /* 1st level */ + }; + +static const SID *systemsid = (const SID*)systemsidbytes; + +/* + * SID for generic creator-owner + * S-1-3-0 + */ + +static const char ownersidbytes[] = { + 1, /* revision */ + 1, /* auth count */ + 0, 0, 0, 0, 0, 3, /* base */ + 0, 0, 0, 0 /* 1st level */ +} ; + +static const SID *ownersid = (const SID*)ownersidbytes; + +/* + * SID for generic creator-group + * S-1-3-1 + */ + +static const char groupsidbytes[] = { + 1, /* revision */ + 1, /* auth count */ + 0, 0, 0, 0, 0, 3, /* base */ + 1, 0, 0, 0 /* 1st level */ +} ; + +static const SID *groupsid = (const SID*)groupsidbytes; + +/* + * Determine the size of a SID + */ + +int ntfs_sid_size(const SID * sid) +{ + return (sid->sub_authority_count * 4 + 8); +} + +/* + * Test whether two SID are equal + */ + +BOOL ntfs_same_sid(const SID *first, const SID *second) +{ + int size; + + size = ntfs_sid_size(first); + return ((ntfs_sid_size(second) == size) + && !memcmp(first, second, size)); +} + +/* + * Test whether a SID means "world user" + * Local users group also recognized as world + */ + +static int is_world_sid(const SID * usid) +{ + return ( + /* check whether S-1-1-0 : world */ + ((usid->sub_authority_count == 1) + && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) + && (usid->identifier_authority.low_part == const_cpu_to_be32(1)) + && (usid->sub_authority[0] == const_cpu_to_le32(0))) + + /* check whether S-1-5-32-545 : local user */ + || ((usid->sub_authority_count == 2) + && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) + && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) + && (usid->sub_authority[0] == const_cpu_to_le32(32)) + && (usid->sub_authority[1] == const_cpu_to_le32(545))) + ); +} + +/* + * Test whether a SID means "some user (or group)" + * Currently we only check for S-1-5-21... but we should + * probably test for other configurations + */ + +BOOL ntfs_is_user_sid(const SID *usid) +{ + return ((usid->sub_authority_count == 5) + && (usid->identifier_authority.high_part == const_cpu_to_be16(0)) + && (usid->identifier_authority.low_part == const_cpu_to_be32(5)) + && (usid->sub_authority[0] == const_cpu_to_le32(21))); +} + +/* + * Determine the size of a security attribute + * whatever the order of fields + */ + +unsigned int ntfs_attr_size(const char *attr) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const ACL *pdacl; + const ACL *psacl; + const SID *psid; + unsigned int offdacl; + unsigned int offsacl; + unsigned int offowner; + unsigned int offgroup; + unsigned int endsid; + unsigned int endacl; + unsigned int attrsz; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)attr; + /* + * First check group, which is the last field in all descriptors + * we build, and in most descriptors built by Windows + */ + attrsz = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + offgroup = le32_to_cpu(phead->group); + if (offgroup >= attrsz) { + /* find end of GSID */ + psid = (const SID*)&attr[offgroup]; + endsid = offgroup + ntfs_sid_size(psid); + if (endsid > attrsz) attrsz = endsid; + } + offowner = le32_to_cpu(phead->owner); + if (offowner >= attrsz) { + /* find end of USID */ + psid = (const SID*)&attr[offowner]; + endsid = offowner + ntfs_sid_size(psid); + attrsz = endsid; + } + offsacl = le32_to_cpu(phead->sacl); + if (offsacl >= attrsz) { + /* find end of SACL */ + psacl = (const ACL*)&attr[offsacl]; + endacl = offsacl + le16_to_cpu(psacl->size); + if (endacl > attrsz) + attrsz = endacl; + } + + + /* find end of DACL */ + offdacl = le32_to_cpu(phead->dacl); + if (offdacl >= attrsz) { + pdacl = (const ACL*)&attr[offdacl]; + endacl = offdacl + le16_to_cpu(pdacl->size); + if (endacl > attrsz) + attrsz = endacl; + } + return (attrsz); +} + +/* + * Do sanity checks on a SID read from storage + * (just check revision and number of authorities) + */ + +BOOL ntfs_valid_sid(const SID *sid) +{ + return ((sid->revision == SID_REVISION) + && (sid->sub_authority_count >= 1) + && (sid->sub_authority_count <= 8)); +} + +/* + * Check whether a SID is acceptable for an implicit + * mapping pattern. + * It should have been already checked it is a valid user SID. + * + * The last authority reference has to be >= 1000 (Windows usage) + * and <= 0x7fffffff, so that 30 bits from a uid and 30 more bits + * from a gid an be inserted with no overflow. + */ + +BOOL ntfs_valid_pattern(const SID *sid) +{ + int cnt; + u32 auth; + le32 leauth; + + cnt = sid->sub_authority_count; + leauth = sid->sub_authority[cnt-1]; + auth = le32_to_cpu(leauth); + return ((auth >= 1000) && (auth <= 0x7fffffff)); +} + +/* + * Compute the uid or gid associated to a SID + * through an implicit mapping + * + * Returns 0 (root) if it does not match pattern + */ + +static u32 findimplicit(const SID *xsid, const SID *pattern, int parity) +{ + BIGSID defsid; + SID *psid; + u32 xid; /* uid or gid */ + int cnt; + u32 carry; + le32 leauth; + u32 uauth; + u32 xlast; + u32 rlast; + + memcpy(&defsid,pattern,ntfs_sid_size(pattern)); + psid = (SID*)&defsid; + cnt = psid->sub_authority_count; + xid = 0; + if (xsid->sub_authority_count == cnt) { + psid->sub_authority[cnt-1] = xsid->sub_authority[cnt-1]; + leauth = xsid->sub_authority[cnt-1]; + xlast = le32_to_cpu(leauth); + leauth = pattern->sub_authority[cnt-1]; + rlast = le32_to_cpu(leauth); + + if ((xlast > rlast) && !((xlast ^ rlast ^ parity) & 1)) { + /* direct check for basic situation */ + if (ntfs_same_sid(psid,xsid)) + xid = ((xlast - rlast) >> 1) & 0x3fffffff; + else { + /* + * check whether part of mapping had to be + * recorded in a higher level authority + */ + carry = 1; + do { + leauth = psid->sub_authority[cnt-2]; + uauth = le32_to_cpu(leauth) + 1; + psid->sub_authority[cnt-2] + = cpu_to_le32(uauth); + } while (!ntfs_same_sid(psid,xsid) + && (++carry < 4)); + if (carry < 4) + xid = (((xlast - rlast) >> 1) + & 0x3fffffff) | (carry << 30); + } + } + } + return (xid); +} + +/* + * Find usid mapped to a Linux user + * Returns NULL if not found + */ + +const SID *ntfs_find_usid(const struct MAPPING* usermapping, + uid_t uid, SID *defusid) +{ + const struct MAPPING *p; + const SID *sid; + le32 leauth; + u32 uauth; + int cnt; + + if (!uid) + sid = adminsid; + else { + p = usermapping; + while (p && p->xid && ((uid_t)p->xid != uid)) + p = p->next; + if (p && !p->xid) { + /* + * default pattern has been reached : + * build an implicit SID according to pattern + * (the pattern format was checked while reading + * the mapping file) + */ + memcpy(defusid, p->sid, ntfs_sid_size(p->sid)); + cnt = defusid->sub_authority_count; + leauth = defusid->sub_authority[cnt-1]; + uauth = le32_to_cpu(leauth) + 2*(uid & 0x3fffffff); + defusid->sub_authority[cnt-1] = cpu_to_le32(uauth); + if (uid & 0xc0000000) { + leauth = defusid->sub_authority[cnt-2]; + uauth = le32_to_cpu(leauth) + ((uid >> 30) & 3); + defusid->sub_authority[cnt-2] = cpu_to_le32(uauth); + } + sid = defusid; + } else + sid = (p ? p->sid : (const SID*)NULL); + } + return (sid); +} + +/* + * Find Linux group mapped to a gsid + * Returns 0 (root) if not found + */ + +const SID *ntfs_find_gsid(const struct MAPPING* groupmapping, + gid_t gid, SID *defgsid) +{ + const struct MAPPING *p; + const SID *sid; + le32 leauth; + u32 uauth; + int cnt; + + if (!gid) + sid = adminsid; + else { + p = groupmapping; + while (p && p->xid && ((gid_t)p->xid != gid)) + p = p->next; + if (p && !p->xid) { + /* + * default pattern has been reached : + * build an implicit SID according to pattern + * (the pattern format was checked while reading + * the mapping file) + */ + memcpy(defgsid, p->sid, ntfs_sid_size(p->sid)); + cnt = defgsid->sub_authority_count; + leauth = defgsid->sub_authority[cnt-1]; + uauth = le32_to_cpu(leauth) + 2*(gid & 0x3fffffff) + 1; + defgsid->sub_authority[cnt-1] = cpu_to_le32(uauth); + if (gid & 0xc0000000) { + leauth = defgsid->sub_authority[cnt-2]; + uauth = le32_to_cpu(leauth) + ((gid >> 30) & 3); + defgsid->sub_authority[cnt-2] = cpu_to_le32(uauth); + } + sid = defgsid; + } else + sid = (p ? p->sid : (const SID*)NULL); + } + return (sid); +} + +/* + * Find Linux owner mapped to a usid + * Returns 0 (root) if not found + */ + +uid_t ntfs_find_user(const struct MAPPING* usermapping, const SID *usid) +{ + uid_t uid; + const struct MAPPING *p; + + p = usermapping; + while (p && p->xid && !ntfs_same_sid(usid, p->sid)) + p = p->next; + if (p && !p->xid) + /* + * No explicit mapping found, try implicit mapping + */ + uid = findimplicit(usid,p->sid,0); + else + uid = (p ? p->xid : 0); + return (uid); +} + +/* + * Find Linux group mapped to a gsid + * Returns 0 (root) if not found + */ + +gid_t ntfs_find_group(const struct MAPPING* groupmapping, const SID * gsid) +{ + gid_t gid; + const struct MAPPING *p; + int gsidsz; + + gsidsz = ntfs_sid_size(gsid); + p = groupmapping; + while (p && p->xid && !ntfs_same_sid(gsid, p->sid)) + p = p->next; + if (p && !p->xid) + /* + * No explicit mapping found, try implicit mapping + */ + gid = findimplicit(gsid,p->sid,1); + else + gid = (p ? p->xid : 0); + return (gid); +} + +/* + * Check the validity of the ACEs in a DACL or SACL + */ + +static BOOL valid_acl(const ACL *pacl, unsigned int end) +{ + const ACCESS_ALLOWED_ACE *pace; + unsigned int offace; + unsigned int acecnt; + unsigned int acesz; + unsigned int nace; + BOOL ok; + + ok = TRUE; + acecnt = le16_to_cpu(pacl->ace_count); + offace = sizeof(ACL); + for (nace = 0; (nace < acecnt) && ok; nace++) { + /* be sure the beginning is within range */ + if ((offace + sizeof(ACCESS_ALLOWED_ACE)) > end) + ok = FALSE; + else { + pace = (const ACCESS_ALLOWED_ACE*) + &((const char*)pacl)[offace]; + acesz = le16_to_cpu(pace->size); + if (((offace + acesz) > end) + || !ntfs_valid_sid(&pace->sid) + || ((ntfs_sid_size(&pace->sid) + 8) != (int)acesz)) + ok = FALSE; + offace += acesz; + } + } + return (ok); +} + +/* + * Do sanity checks on security descriptors read from storage + * basically, we make sure that every field holds within + * allocated storage + * Should not be called with a NULL argument + * returns TRUE if considered safe + * if not, error should be logged by caller + */ + +BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const ACL *pdacl; + const ACL *psacl; + unsigned int offdacl; + unsigned int offsacl; + unsigned int offowner; + unsigned int offgroup; + BOOL ok; + + ok = TRUE; + + /* + * first check overall size if within allocation range + * and a DACL is present + * and owner and group SID are valid + */ + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + offsacl = le32_to_cpu(phead->sacl); + offowner = le32_to_cpu(phead->owner); + offgroup = le32_to_cpu(phead->group); + pdacl = (const ACL*)&securattr[offdacl]; + psacl = (const ACL*)&securattr[offsacl]; + + /* + * size check occurs before the above pointers are used + * + * "DR Watson" standard directory on WinXP has an + * old revision and no DACL though SE_DACL_PRESENT is set + */ + if ((attrsz >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) + && (phead->revision == SECURITY_DESCRIPTOR_REVISION) + && (offowner >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) + && ((offowner + 2) < attrsz) + && (offgroup >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) + && ((offgroup + 2) < attrsz) + && (!offdacl + || ((offdacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) + && (offdacl+sizeof(ACL) < attrsz))) + && (!offsacl + || ((offsacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE)) + && (offsacl+sizeof(ACL) < attrsz))) + && !(phead->owner & const_cpu_to_le32(3)) + && !(phead->group & const_cpu_to_le32(3)) + && !(phead->dacl & const_cpu_to_le32(3)) + && !(phead->sacl & const_cpu_to_le32(3)) + && (ntfs_attr_size(securattr) <= attrsz) + && ntfs_valid_sid((const SID*)&securattr[offowner]) + && ntfs_valid_sid((const SID*)&securattr[offgroup]) + /* + * if there is an ACL, as indicated by offdacl, + * require SE_DACL_PRESENT + * but "Dr Watson" has SE_DACL_PRESENT though no DACL + */ + && (!offdacl + || ((phead->control & SE_DACL_PRESENT) + && ((pdacl->revision == ACL_REVISION) + || (pdacl->revision == ACL_REVISION_DS)))) + /* same for SACL */ + && (!offsacl + || ((phead->control & SE_SACL_PRESENT) + && ((psacl->revision == ACL_REVISION) + || (psacl->revision == ACL_REVISION_DS))))) { + /* + * Check the DACL and SACL if present + */ + if ((offdacl && !valid_acl(pdacl,attrsz - offdacl)) + || (offsacl && !valid_acl(psacl,attrsz - offsacl))) + ok = FALSE; + } else + ok = FALSE; + return (ok); +} + +/* + * Copy the inheritable parts of an ACL + * + * Returns the size of the new ACL + * or zero if nothing is inheritable + */ + +int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, + const SID *usid, const SID *gsid, BOOL fordir) +{ + unsigned int src; + unsigned int dst; + int oldcnt; + int newcnt; + unsigned int selection; + int nace; + int acesz; + int usidsz; + int gsidsz; + const ACCESS_ALLOWED_ACE *poldace; + ACCESS_ALLOWED_ACE *pnewace; + + usidsz = ntfs_sid_size(usid); + gsidsz = ntfs_sid_size(gsid); + + /* ACL header */ + + newacl->revision = ACL_REVISION; + newacl->alignment1 = 0; + newacl->alignment2 = const_cpu_to_le16(0); + src = dst = sizeof(ACL); + + selection = (fordir ? CONTAINER_INHERIT_ACE : OBJECT_INHERIT_ACE); + newcnt = 0; + oldcnt = le16_to_cpu(oldacl->ace_count); + for (nace = 0; nace < oldcnt; nace++) { + poldace = (const ACCESS_ALLOWED_ACE*)((const char*)oldacl + src); + acesz = le16_to_cpu(poldace->size); + /* inheritance for access */ + if (poldace->flags & selection) { + pnewace = (ACCESS_ALLOWED_ACE*) + ((char*)newacl + dst); + memcpy(pnewace,poldace,acesz); + /* + * Replace generic creator-owner and + * creator-group by owner and group + */ + if (ntfs_same_sid(&pnewace->sid, ownersid)) { + memcpy(&pnewace->sid, usid, usidsz); + acesz = usidsz + 8; + pnewace->size = cpu_to_le16(acesz); + } + if (ntfs_same_sid(&pnewace->sid, groupsid)) { + memcpy(&pnewace->sid, gsid, gsidsz); + acesz = gsidsz + 8; + pnewace->size = cpu_to_le16(acesz); + } + if (pnewace->mask & GENERIC_ALL) { + pnewace->mask &= ~GENERIC_ALL; + if (fordir) + pnewace->mask |= OWNER_RIGHTS + | DIR_READ + | DIR_WRITE + | DIR_EXEC; + else + /* + * The last flag is not defined for a file, + * however Windows sets it, so do the same + */ + pnewace->mask |= OWNER_RIGHTS + | FILE_READ + | FILE_WRITE + | FILE_EXEC + | cpu_to_le32(0x40); + } + /* remove inheritance flags */ + pnewace->flags &= ~(OBJECT_INHERIT_ACE + | CONTAINER_INHERIT_ACE + | INHERIT_ONLY_ACE); + dst += acesz; + newcnt++; + } + /* inheritance for further inheritance */ + if (fordir + && (poldace->flags + & (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE))) { + pnewace = (ACCESS_ALLOWED_ACE*) + ((char*)newacl + dst); + memcpy(pnewace,poldace,acesz); + /* + * Replace generic creator-owner and + * creator-group by owner and group + */ + if (ntfs_same_sid(&pnewace->sid, ownersid)) { + memcpy(&pnewace->sid, usid, usidsz); + acesz = usidsz + 8; + } + if (ntfs_same_sid(&pnewace->sid, groupsid)) { + memcpy(&pnewace->sid, gsid, gsidsz); + acesz = gsidsz + 8; + } + dst += acesz; + newcnt++; + } + src += acesz; + } + /* + * Adjust header if something was inherited + */ + if (dst > sizeof(ACL)) { + newacl->ace_count = cpu_to_le16(newcnt); + newacl->size = cpu_to_le16(dst); + } else + dst = 0; + return (dst); +} + +#if POSIXACLS + +/* + * Do sanity checks on a Posix descriptor + * Should not be called with a NULL argument + * returns TRUE if considered safe + * if not, error should be logged by caller + */ + +BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc) +{ + const struct POSIX_ACL *pacl; + int i; + BOOL ok; + u16 tag; + u32 id; + int perms; + struct { + u16 previous; + u32 previousid; + u16 tagsset; + mode_t mode; + int owners; + int groups; + int others; + } checks[2], *pchk; + + for (i=0; i<2; i++) { + checks[i].mode = 0; + checks[i].tagsset = 0; + checks[i].owners = 0; + checks[i].groups = 0; + checks[i].others = 0; + checks[i].previous = 0; + checks[i].previousid = 0; + } + ok = TRUE; + pacl = &pxdesc->acl; + /* + * header (strict for now) + */ + if ((pacl->version != POSIX_VERSION) + || (pacl->flags != 0) + || (pacl->filler != 0)) + ok = FALSE; + /* + * Reject multiple owner, group or other + * but do not require them to be present + * Also check the ACEs are in correct order + * which implies there is no duplicates + */ + for (i=0; iacccnt + pxdesc->defcnt; i++) { + if (i >= pxdesc->firstdef) + pchk = &checks[1]; + else + pchk = &checks[0]; + perms = pacl->ace[i].perms; + tag = pacl->ace[i].tag; + pchk->tagsset |= tag; + id = pacl->ace[i].id; + if (perms & ~7) ok = FALSE; + if ((tag < pchk->previous) + || ((tag == pchk->previous) + && (id <= pchk->previousid))) + ok = FALSE; + pchk->previous = tag; + pchk->previousid = id; + switch (tag) { + case POSIX_ACL_USER_OBJ : + if (pchk->owners++) + ok = FALSE; + if (id != (u32)-1) + ok = FALSE; + pchk->mode |= perms << 6; + break; + case POSIX_ACL_GROUP_OBJ : + if (pchk->groups++) + ok = FALSE; + if (id != (u32)-1) + ok = FALSE; + pchk->mode = (pchk->mode & 07707) | (perms << 3); + break; + case POSIX_ACL_OTHER : + if (pchk->others++) + ok = FALSE; + if (id != (u32)-1) + ok = FALSE; + pchk->mode |= perms; + break; + case POSIX_ACL_USER : + case POSIX_ACL_GROUP : + if (id == (u32)-1) + ok = FALSE; + break; + case POSIX_ACL_MASK : + if (id != (u32)-1) + ok = FALSE; + pchk->mode = (pchk->mode & 07707) | (perms << 3); + break; + default : + ok = FALSE; + break; + } + } + if ((pxdesc->acccnt > 0) + && ((checks[0].owners != 1) || (checks[0].groups != 1) + || (checks[0].others != 1))) + ok = FALSE; + /* do not check owner, group or other are present in */ + /* the default ACL, Windows does not necessarily set them */ + /* descriptor */ + if (pxdesc->defcnt && (pxdesc->acccnt > pxdesc->firstdef)) + ok = FALSE; + if ((pxdesc->acccnt < 0) || (pxdesc->defcnt < 0)) + ok = FALSE; + /* check mode, unless null or no tag set */ + if (pxdesc->mode + && checks[0].tagsset + && (checks[0].mode != (pxdesc->mode & 0777))) + ok = FALSE; + /* check tagsset */ + if (pxdesc->tagsset != checks[0].tagsset) + ok = FALSE; + return (ok); +} + +/* + * Set standard header data into a Posix ACL + * The mode argument should provide the 3 upper bits of target mode + */ + +static mode_t posix_header(struct POSIX_SECURITY *pxdesc, mode_t basemode) +{ + mode_t mode; + u16 tagsset; + struct POSIX_ACE *pace; + int i; + + mode = basemode & 07000; + tagsset = 0; + for (i=0; iacccnt; i++) { + pace = &pxdesc->acl.ace[i]; + tagsset |= pace->tag; + switch(pace->tag) { + case POSIX_ACL_USER_OBJ : + mode |= (pace->perms & 7) << 6; + break; + case POSIX_ACL_GROUP_OBJ : + case POSIX_ACL_MASK : + mode = (mode & 07707) | ((pace->perms & 7) << 3); + break; + case POSIX_ACL_OTHER : + mode |= pace->perms & 7; + break; + default : + break; + } + } + pxdesc->tagsset = tagsset; + pxdesc->mode = mode; + pxdesc->acl.version = POSIX_VERSION; + pxdesc->acl.flags = 0; + pxdesc->acl.filler = 0; + return (mode); +} + +/* + * Sort ACEs in a Posix ACL + * This is useful for always getting reusable converted ACLs, + * it also helps in merging ACEs. + * Repeated tag+id are allowed and not merged here. + * + * Tags should be in ascending sequence and for a repeatable tag + * ids should be in ascending sequence. + */ + +void ntfs_sort_posix(struct POSIX_SECURITY *pxdesc) +{ + struct POSIX_ACL *pacl; + struct POSIX_ACE ace; + int i; + int offs; + BOOL done; + u16 tag; + u16 previous; + u32 id; + u32 previousid; + + + /* + * Check sequencing of tag+id in access ACE's + */ + pacl = &pxdesc->acl; + do { + done = TRUE; + previous = pacl->ace[0].tag; + previousid = pacl->ace[0].id; + for (i=1; iacccnt; i++) { + tag = pacl->ace[i].tag; + id = pacl->ace[i].id; + + if ((tag < previous) + || ((tag == previous) && (id < previousid))) { + done = FALSE; + memcpy(&ace,&pacl->ace[i-1],sizeof(struct POSIX_ACE)); + memcpy(&pacl->ace[i-1],&pacl->ace[i],sizeof(struct POSIX_ACE)); + memcpy(&pacl->ace[i],&ace,sizeof(struct POSIX_ACE)); + } else { + previous = tag; + previousid = id; + } + } + } while (!done); + /* + * Same for default ACEs + */ + do { + done = TRUE; + if ((pxdesc->defcnt) > 1) { + offs = pxdesc->firstdef; + previous = pacl->ace[offs].tag; + previousid = pacl->ace[offs].id; + for (i=offs+1; idefcnt; i++) { + tag = pacl->ace[i].tag; + id = pacl->ace[i].id; + + if ((tag < previous) + || ((tag == previous) && (id < previousid))) { + done = FALSE; + memcpy(&ace,&pacl->ace[i-1],sizeof(struct POSIX_ACE)); + memcpy(&pacl->ace[i-1],&pacl->ace[i],sizeof(struct POSIX_ACE)); + memcpy(&pacl->ace[i],&ace,sizeof(struct POSIX_ACE)); + } else { + previous = tag; + previousid = id; + } + } + } + } while (!done); +} + +/* + * Merge a new mode into a Posix descriptor + * The Posix descriptor is not reallocated, its size is unchanged + * + * returns 0 if ok + */ + +int ntfs_merge_mode_posix(struct POSIX_SECURITY *pxdesc, mode_t mode) +{ + int i; + BOOL maskfound; + struct POSIX_ACE *pace; + int todo; + + maskfound = FALSE; + todo = POSIX_ACL_USER_OBJ | POSIX_ACL_GROUP_OBJ | POSIX_ACL_OTHER; + for (i=pxdesc->acccnt-1; i>=0; i--) { + pace = &pxdesc->acl.ace[i]; + switch(pace->tag) { + case POSIX_ACL_USER_OBJ : + pace->perms = (mode >> 6) & 7; + todo &= ~POSIX_ACL_USER_OBJ; + break; + case POSIX_ACL_GROUP_OBJ : + if (!maskfound) + pace->perms = (mode >> 3) & 7; + todo &= ~POSIX_ACL_GROUP_OBJ; + break; + case POSIX_ACL_MASK : + pace->perms = (mode >> 3) & 7; + maskfound = TRUE; + break; + case POSIX_ACL_OTHER : + pace->perms = mode & 7; + todo &= ~POSIX_ACL_OTHER; + break; + default : + break; + } + } + pxdesc->mode = mode; + return (todo ? -1 : 0); +} + +/* + * Replace an access or default Posix ACL + * The resulting ACL is checked for validity + * + * Returns a new ACL or NULL if there is a problem + */ + +struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc, + const struct POSIX_ACL *newacl, int count, BOOL deflt) +{ + struct POSIX_SECURITY *newpxdesc; + size_t newsize; + int offset; + int oldoffset; + int i; + + if (deflt) + newsize = sizeof(struct POSIX_SECURITY) + + (oldpxdesc->acccnt + count)*sizeof(struct POSIX_ACE); + else + newsize = sizeof(struct POSIX_SECURITY) + + (oldpxdesc->defcnt + count)*sizeof(struct POSIX_ACE); + newpxdesc = (struct POSIX_SECURITY*)malloc(newsize); + if (newpxdesc) { + if (deflt) { + offset = oldpxdesc->acccnt; + newpxdesc->acccnt = oldpxdesc->acccnt; + newpxdesc->defcnt = count; + newpxdesc->firstdef = offset; + /* copy access ACEs */ + for (i=0; iacccnt; i++) + newpxdesc->acl.ace[i] = oldpxdesc->acl.ace[i]; + /* copy default ACEs */ + for (i=0; iacl.ace[i + offset] = newacl->ace[i]; + } else { + offset = count; + newpxdesc->acccnt = count; + newpxdesc->defcnt = oldpxdesc->defcnt; + newpxdesc->firstdef = count; + /* copy access ACEs */ + for (i=0; iacl.ace[i] = newacl->ace[i]; + /* copy default ACEs */ + oldoffset = oldpxdesc->firstdef; + for (i=0; idefcnt; i++) + newpxdesc->acl.ace[i + offset] = oldpxdesc->acl.ace[i + oldoffset]; + } + /* assume special flags unchanged */ + posix_header(newpxdesc, oldpxdesc->mode); + if (!ntfs_valid_posix(newpxdesc)) { + /* do not log, this is an application error */ + free(newpxdesc); + newpxdesc = (struct POSIX_SECURITY*)NULL; + errno = EINVAL; + } + } else + errno = ENOMEM; + return (newpxdesc); +} + +/* + * Build an inherited Posix descriptor from parent + * descriptor (if any) restricted to creation mode + * + * Returns the inherited descriptor or NULL if there is a problem + */ + +struct POSIX_SECURITY *ntfs_build_inherited_posix( + const struct POSIX_SECURITY *pxdesc, mode_t mode, + mode_t mask, BOOL isdir) +{ + struct POSIX_SECURITY *pydesc; + struct POSIX_ACE *pyace; + int count; + int defcnt; + int size; + int i; + s16 tagsset; + + if (pxdesc && pxdesc->defcnt) { + if (isdir) + count = 2*pxdesc->defcnt + 3; + else + count = pxdesc->defcnt + 3; + } else + count = 3; + pydesc = (struct POSIX_SECURITY*)malloc( + sizeof(struct POSIX_SECURITY) + count*sizeof(struct POSIX_ACE)); + if (pydesc) { + /* + * Copy inherited tags and adapt perms + * Use requested mode, ignoring umask + * (not possible with older versions of fuse) + */ + tagsset = 0; + defcnt = (pxdesc ? pxdesc->defcnt : 0); + for (i=defcnt-1; i>=0; i--) { + pyace = &pydesc->acl.ace[i]; + *pyace = pxdesc->acl.ace[pxdesc->firstdef + i]; + switch (pyace->tag) { + case POSIX_ACL_USER_OBJ : + pyace->perms &= (mode >> 6) & 7; + break; + case POSIX_ACL_GROUP_OBJ : + if (!(tagsset & POSIX_ACL_MASK)) + pyace->perms &= (mode >> 3) & 7; + break; + case POSIX_ACL_OTHER : + pyace->perms &= mode & 7; + break; + case POSIX_ACL_MASK : + pyace->perms &= (mode >> 3) & 7; + break; + default : + break; + } + tagsset |= pyace->tag; + } + pydesc->acccnt = defcnt; + /* + * If some standard tags were missing, append them from mode + * and sort the list + * Here we have to use the umask'ed mode + */ + if (~tagsset & (POSIX_ACL_USER_OBJ + | POSIX_ACL_GROUP_OBJ | POSIX_ACL_OTHER)) { + i = defcnt; + /* owner was missing */ + if (!(tagsset & POSIX_ACL_USER_OBJ)) { + pyace = &pydesc->acl.ace[i]; + pyace->tag = POSIX_ACL_USER_OBJ; + pyace->id = -1; + pyace->perms = ((mode & ~mask) >> 6) & 7; + tagsset |= POSIX_ACL_USER_OBJ; + i++; + } + /* owning group was missing */ + if (!(tagsset & POSIX_ACL_GROUP_OBJ)) { + pyace = &pydesc->acl.ace[i]; + pyace->tag = POSIX_ACL_GROUP_OBJ; + pyace->id = -1; + pyace->perms = ((mode & ~mask) >> 3) & 7; + tagsset |= POSIX_ACL_GROUP_OBJ; + i++; + } + /* other was missing */ + if (!(tagsset & POSIX_ACL_OTHER)) { + pyace = &pydesc->acl.ace[i]; + pyace->tag = POSIX_ACL_OTHER; + pyace->id = -1; + pyace->perms = mode & ~mask & 7; + tagsset |= POSIX_ACL_OTHER; + i++; + } + pydesc->acccnt = i; + pydesc->firstdef = i; + pydesc->defcnt = 0; + ntfs_sort_posix(pydesc); + } + + /* + * append as a default ACL if a directory + */ + pydesc->firstdef = pydesc->acccnt; + if (defcnt && isdir) { + size = sizeof(struct POSIX_ACE)*defcnt; + memcpy(&pydesc->acl.ace[pydesc->firstdef], + &pxdesc->acl.ace[pxdesc->firstdef],size); + pydesc->defcnt = defcnt; + } else { + pydesc->defcnt = 0; + } + /* assume special bits are not inherited */ + posix_header(pydesc, mode & 07000); + if (!ntfs_valid_posix(pydesc)) { + ntfs_log_error("Error building an inherited Posix desc\n"); + errno = EIO; + free(pydesc); + pydesc = (struct POSIX_SECURITY*)NULL; + } + } else + errno = ENOMEM; + return (pydesc); +} + +static int merge_lists_posix(struct POSIX_ACE *targetace, + const struct POSIX_ACE *firstace, + const struct POSIX_ACE *secondace, + int firstcnt, int secondcnt) +{ + int k; + + k = 0; + /* + * No list is exhausted : + * if same tag+id in both list : + * ignore ACE from second list + * else take the one with smaller tag+id + */ + while ((firstcnt > 0) && (secondcnt > 0)) + if ((firstace->tag == secondace->tag) + && (firstace->id == secondace->id)) { + secondace++; + secondcnt--; + } else + if ((firstace->tag < secondace->tag) + || ((firstace->tag == secondace->tag) + && (firstace->id < secondace->id))) { + targetace->tag = firstace->tag; + targetace->id = firstace->id; + targetace->perms = firstace->perms; + firstace++; + targetace++; + firstcnt--; + k++; + } else { + targetace->tag = secondace->tag; + targetace->id = secondace->id; + targetace->perms = secondace->perms; + secondace++; + targetace++; + secondcnt--; + k++; + } + /* + * One list is exhausted, copy the other one + */ + while (firstcnt > 0) { + targetace->tag = firstace->tag; + targetace->id = firstace->id; + targetace->perms = firstace->perms; + firstace++; + targetace++; + firstcnt--; + k++; + } + while (secondcnt > 0) { + targetace->tag = secondace->tag; + targetace->id = secondace->id; + targetace->perms = secondace->perms; + secondace++; + targetace++; + secondcnt--; + k++; + } + return (k); +} + +/* + * Merge two Posix ACLs + * The input ACLs have to be adequately sorted + * + * Returns the merged ACL, which is allocated and has to be freed by caller, + * or NULL if failed + */ + +struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first, + const struct POSIX_SECURITY *second) +{ + struct POSIX_SECURITY *pxdesc; + struct POSIX_ACE *targetace; + const struct POSIX_ACE *firstace; + const struct POSIX_ACE *secondace; + size_t size; + int k; + + size = sizeof(struct POSIX_SECURITY) + + (first->acccnt + first->defcnt + + second->acccnt + second->defcnt)*sizeof(struct POSIX_ACE); + pxdesc = (struct POSIX_SECURITY*)malloc(size); + if (pxdesc) { + /* + * merge access ACEs + */ + firstace = first->acl.ace; + secondace = second->acl.ace; + targetace = pxdesc->acl.ace; + k = merge_lists_posix(targetace,firstace,secondace, + first->acccnt,second->acccnt); + pxdesc->acccnt = k; + /* + * merge default ACEs + */ + pxdesc->firstdef = k; + firstace = &first->acl.ace[first->firstdef]; + secondace = &second->acl.ace[second->firstdef]; + targetace = &pxdesc->acl.ace[k]; + k = merge_lists_posix(targetace,firstace,secondace, + first->defcnt,second->defcnt); + pxdesc->defcnt = k; + /* + * build header + */ + pxdesc->acl.version = POSIX_VERSION; + pxdesc->acl.flags = 0; + pxdesc->acl.filler = 0; + pxdesc->mode = 0; + pxdesc->tagsset = 0; + } else + errno = ENOMEM; + return (pxdesc); +} + +struct BUILD_CONTEXT { + BOOL isdir; + BOOL adminowns; + BOOL groupowns; + u16 selfuserperms; + u16 selfgrpperms; + u16 grpperms; + u16 othperms; + u16 mask; + u16 designates; + u16 withmask; + u16 rootspecial; +} ; + + + +static BOOL build_user_denials(ACL *pacl, + const SID *usid, struct MAPPING* const mapping[], + ACE_FLAGS flags, const struct POSIX_ACE *pxace, + struct BUILD_CONTEXT *pset) +{ + BIGSID defsid; + ACCESS_ALLOWED_ACE *pdace; + const SID *sid; + int sidsz; + int pos; + int acecnt; + le32 grants; + le32 denials; + u16 perms; + u16 mixperms; + u16 tag; + BOOL rejected; + BOOL rootuser; + BOOL avoidmask; + + rejected = FALSE; + tag = pxace->tag; + perms = pxace->perms; + rootuser = FALSE; + pos = le16_to_cpu(pacl->size); + acecnt = le16_to_cpu(pacl->ace_count); + avoidmask = (pset->mask == (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X)) + && ((pset->designates && pset->withmask) + || (!pset->designates && !pset->withmask)); + if (tag == POSIX_ACL_USER_OBJ) { + sid = usid; + sidsz = ntfs_sid_size(sid); + grants = OWNER_RIGHTS; + } else { + if (pxace->id) { + sid = NTFS_FIND_USID(mapping[MAPUSERS], + pxace->id, (SID*)&defsid); + grants = WORLD_RIGHTS; + } else { + sid = adminsid; + rootuser = TRUE; + grants = WORLD_RIGHTS & ~ROOT_OWNER_UNMARK; + } + if (sid) { + sidsz = ntfs_sid_size(sid); + /* + * Insert denial of complement of mask for + * each designated user (except root) + * WRITE_OWNER is inserted so that + * the mask can be identified + */ + if (!avoidmask && !rootuser) { + denials = WRITE_OWNER; + pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; + if (pset->isdir) { + if (!(pset->mask & POSIX_PERM_X)) + denials |= DIR_EXEC; + if (!(pset->mask & POSIX_PERM_W)) + denials |= DIR_WRITE; + if (!(pset->mask & POSIX_PERM_R)) + denials |= DIR_READ; + } else { + if (!(pset->mask & POSIX_PERM_X)) + denials |= FILE_EXEC; + if (!(pset->mask & POSIX_PERM_W)) + denials |= FILE_WRITE; + if (!(pset->mask & POSIX_PERM_R)) + denials |= FILE_READ; + } + if (rootuser) + grants &= ~ROOT_OWNER_UNMARK; + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->flags = flags; + pdace->size = cpu_to_le16(sidsz + 8); + pdace->mask = denials; + memcpy((char*)&pdace->sid, sid, sidsz); + pos += sidsz + 8; + acecnt++; + } + } else + rejected = TRUE; + } + if (!rejected) { + if (pset->isdir) { + if (perms & POSIX_PERM_X) + grants |= DIR_EXEC; + if (perms & POSIX_PERM_W) + grants |= DIR_WRITE; + if (perms & POSIX_PERM_R) + grants |= DIR_READ; + } else { + if (perms & POSIX_PERM_X) + grants |= FILE_EXEC; + if (perms & POSIX_PERM_W) + grants |= FILE_WRITE; + if (perms & POSIX_PERM_R) + grants |= FILE_READ; + } + + /* a possible ACE to deny owner what he/she would */ + /* induely get from administrator, group or world */ + /* unless owner is administrator or group */ + + denials = const_cpu_to_le32(0); + pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; + if (!pset->adminowns && !rootuser) { + if (!pset->groupowns) { + mixperms = pset->grpperms | pset->othperms; + if (tag == POSIX_ACL_USER_OBJ) + mixperms |= pset->selfuserperms; + if (pset->isdir) { + if (mixperms & POSIX_PERM_X) + denials |= DIR_EXEC; + if (mixperms & POSIX_PERM_W) + denials |= DIR_WRITE; + if (mixperms & POSIX_PERM_R) + denials |= DIR_READ; + } else { + if (mixperms & POSIX_PERM_X) + denials |= FILE_EXEC; + if (mixperms & POSIX_PERM_W) + denials |= FILE_WRITE; + if (mixperms & POSIX_PERM_R) + denials |= FILE_READ; + } + } else { + mixperms = ~pset->grpperms & pset->othperms; + if (tag == POSIX_ACL_USER_OBJ) + mixperms |= pset->selfuserperms; + if (pset->isdir) { + if (mixperms & POSIX_PERM_X) + denials |= DIR_EXEC; + if (mixperms & POSIX_PERM_W) + denials |= DIR_WRITE; + if (mixperms & POSIX_PERM_R) + denials |= DIR_READ; + } else { + if (mixperms & POSIX_PERM_X) + denials |= FILE_EXEC; + if (mixperms & POSIX_PERM_W) + denials |= FILE_WRITE; + if (mixperms & POSIX_PERM_R) + denials |= FILE_READ; + } + } + denials &= ~grants; + if (denials) { + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->flags = flags; + pdace->size = cpu_to_le16(sidsz + 8); + pdace->mask = denials; + memcpy((char*)&pdace->sid, sid, sidsz); + pos += sidsz + 8; + acecnt++; + } + } + } + pacl->size = cpu_to_le16(pos); + pacl->ace_count = cpu_to_le16(acecnt); + return (!rejected); +} + +static BOOL build_user_grants(ACL *pacl, + const SID *usid, struct MAPPING* const mapping[], + ACE_FLAGS flags, const struct POSIX_ACE *pxace, + struct BUILD_CONTEXT *pset) +{ + BIGSID defsid; + ACCESS_ALLOWED_ACE *pgace; + const SID *sid; + int sidsz; + int pos; + int acecnt; + le32 grants; + u16 perms; + u16 tag; + BOOL rejected; + BOOL rootuser; + + rejected = FALSE; + tag = pxace->tag; + perms = pxace->perms; + rootuser = FALSE; + pos = le16_to_cpu(pacl->size); + acecnt = le16_to_cpu(pacl->ace_count); + if (tag == POSIX_ACL_USER_OBJ) { + sid = usid; + sidsz = ntfs_sid_size(sid); + grants = OWNER_RIGHTS; + } else { + if (pxace->id) { + sid = NTFS_FIND_USID(mapping[MAPUSERS], + pxace->id, (SID*)&defsid); + if (sid) + sidsz = ntfs_sid_size(sid); + else + rejected = TRUE; + grants = WORLD_RIGHTS; + } else { + sid = adminsid; + sidsz = ntfs_sid_size(sid); + rootuser = TRUE; + grants = WORLD_RIGHTS & ~ROOT_OWNER_UNMARK; + } + } + if (!rejected) { + if (pset->isdir) { + if (perms & POSIX_PERM_X) + grants |= DIR_EXEC; + if (perms & POSIX_PERM_W) + grants |= DIR_WRITE; + if (perms & POSIX_PERM_R) + grants |= DIR_READ; + } else { + if (perms & POSIX_PERM_X) + grants |= FILE_EXEC; + if (perms & POSIX_PERM_W) + grants |= FILE_WRITE; + if (perms & POSIX_PERM_R) + grants |= FILE_READ; + } + if (rootuser) + grants &= ~ROOT_OWNER_UNMARK; + pgace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->size = cpu_to_le16(sidsz + 8); + pgace->flags = flags; + pgace->mask = grants; + memcpy((char*)&pgace->sid, sid, sidsz); + pos += sidsz + 8; + acecnt = le16_to_cpu(pacl->ace_count) + 1; + pacl->ace_count = cpu_to_le16(acecnt); + pacl->size = cpu_to_le16(pos); + } + return (!rejected); +} + + + /* a grant ACE for group */ + /* unless group-obj has the same rights as world */ + /* but present if group is owner or owner is administrator */ + /* this ACE will be inserted after denials for group */ + +static BOOL build_group_denials_grant(ACL *pacl, + const SID *gsid, struct MAPPING* const mapping[], + ACE_FLAGS flags, const struct POSIX_ACE *pxace, + struct BUILD_CONTEXT *pset) +{ + BIGSID defsid; + ACCESS_ALLOWED_ACE *pdace; + ACCESS_ALLOWED_ACE *pgace; + const SID *sid; + int sidsz; + int pos; + int acecnt; + le32 grants; + le32 denials; + u16 perms; + u16 mixperms; + u16 tag; + BOOL avoidmask; + BOOL rootgroup; + BOOL rejected; + + rejected = FALSE; + tag = pxace->tag; + perms = pxace->perms; + pos = le16_to_cpu(pacl->size); + acecnt = le16_to_cpu(pacl->ace_count); + rootgroup = FALSE; + avoidmask = (pset->mask == (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X)) + && ((pset->designates && pset->withmask) + || (!pset->designates && !pset->withmask)); + if (tag == POSIX_ACL_GROUP_OBJ) + sid = gsid; + else + if (pxace->id) + sid = NTFS_FIND_GSID(mapping[MAPGROUPS], + pxace->id, (SID*)&defsid); + else { + sid = adminsid; + rootgroup = TRUE; + } + if (sid) { + sidsz = ntfs_sid_size(sid); + /* + * Insert denial of complement of mask for + * each group + * WRITE_OWNER is inserted so that + * the mask can be identified + * Note : this mask may lead on Windows to + * deny rights to administrators belonging + * to some user group + */ + if ((!avoidmask && !rootgroup) + || (pset->rootspecial + && (tag == POSIX_ACL_GROUP_OBJ))) { + denials = WRITE_OWNER; + pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; + if (pset->isdir) { + if (!(pset->mask & POSIX_PERM_X)) + denials |= DIR_EXEC; + if (!(pset->mask & POSIX_PERM_W)) + denials |= DIR_WRITE; + if (!(pset->mask & POSIX_PERM_R)) + denials |= DIR_READ; + } else { + if (!(pset->mask & POSIX_PERM_X)) + denials |= FILE_EXEC; + if (!(pset->mask & POSIX_PERM_W)) + denials |= FILE_WRITE; + if (!(pset->mask & POSIX_PERM_R)) + denials |= FILE_READ; + } + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->flags = flags; + pdace->size = cpu_to_le16(sidsz + 8); + pdace->mask = denials; + memcpy((char*)&pdace->sid, sid, sidsz); + pos += sidsz + 8; + acecnt++; + } + } else + rejected = TRUE; + if (!rejected + && (pset->adminowns + || pset->groupowns + || avoidmask + || rootgroup + || (perms != pset->othperms))) { + grants = WORLD_RIGHTS; + if (rootgroup) + grants &= ~ROOT_GROUP_UNMARK; + if (pset->isdir) { + if (perms & POSIX_PERM_X) + grants |= DIR_EXEC; + if (perms & POSIX_PERM_W) + grants |= DIR_WRITE; + if (perms & POSIX_PERM_R) + grants |= DIR_READ; + } else { + if (perms & POSIX_PERM_X) + grants |= FILE_EXEC; + if (perms & POSIX_PERM_W) + grants |= FILE_WRITE; + if (perms & POSIX_PERM_R) + grants |= FILE_READ; + } + + /* a possible ACE to deny group what it would get from world */ + /* or administrator, unless owner is administrator or group */ + + denials = const_cpu_to_le32(0); + pdace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; + if (!pset->adminowns + && !pset->groupowns + && !rootgroup) { + mixperms = pset->othperms; + if (tag == POSIX_ACL_GROUP_OBJ) + mixperms |= pset->selfgrpperms; + if (pset->isdir) { + if (mixperms & POSIX_PERM_X) + denials |= DIR_EXEC; + if (mixperms & POSIX_PERM_W) + denials |= DIR_WRITE; + if (mixperms & POSIX_PERM_R) + denials |= DIR_READ; + } else { + if (mixperms & POSIX_PERM_X) + denials |= FILE_EXEC; + if (mixperms & POSIX_PERM_W) + denials |= FILE_WRITE; + if (mixperms & POSIX_PERM_R) + denials |= FILE_READ; + } + denials &= ~(grants | OWNER_RIGHTS); + if (denials) { + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->flags = flags; + pdace->size = cpu_to_le16(sidsz + 8); + pdace->mask = denials; + memcpy((char*)&pdace->sid, sid, sidsz); + pos += sidsz + 8; + acecnt++; + } + } + + /* now insert grants to group if more than world */ + if (pset->adminowns + || pset->groupowns + || (avoidmask && (pset->designates || pset->withmask)) + || (perms & ~pset->othperms) + || (pset->rootspecial + && (tag == POSIX_ACL_GROUP_OBJ)) + || (tag == POSIX_ACL_GROUP)) { + if (rootgroup) + grants &= ~ROOT_GROUP_UNMARK; + pgace = (ACCESS_DENIED_ACE*)&((char*)pacl)[pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = flags; + pgace->size = cpu_to_le16(sidsz + 8); + pgace->mask = grants; + memcpy((char*)&pgace->sid, sid, sidsz); + pos += sidsz + 8; + acecnt++; + } + } + pacl->size = cpu_to_le16(pos); + pacl->ace_count = cpu_to_le16(acecnt); + return (!rejected); +} + + +/* + * Build an ACL composed of several ACE's + * returns size of ACL or zero if failed + * + * Three schemes are defined : + * + * 1) if root is neither owner nor group up to 7 ACE's are set up : + * - denials to owner (preventing grants to world or group to apply) + * + mask denials to designated user (unless mask allows all) + * + denials to designated user + * - grants to owner (always present - first grant) + * + grants to designated user + * + mask denial to group (unless mask allows all) + * - denials to group (preventing grants to world to apply) + * - grants to group (unless group has no more than world rights) + * + mask denials to designated group (unless mask allows all) + * + grants to designated group + * + denials to designated group + * - grants to world (unless none) + * - full privileges to administrator, always present + * - full privileges to system, always present + * + * The same scheme is applied for Posix ACLs, with the mask represented + * as denials prepended to grants for designated users and groups + * + * This is inspired by an Internet Draft from Marius Aamodt Eriksen + * for mapping NFSv4 ACLs to Posix ACLs (draft-ietf-nfsv4-acl-mapping-00.txt) + * More recent versions of the draft (draft-ietf-nfsv4-acl-mapping-05.txt) + * are not followed, as they ignore the Posix mask and lead to + * loss of compatibility with Linux implementations on other fs. + * + * Note that denials to group are located after grants to owner. + * This only occurs in the unfrequent situation where world + * has more rights than group and cannot be avoided if owner and other + * have some common right which is denied to group (eg for mode 745 + * executing has to be denied to group, but not to owner or world). + * This rare situation is processed by Windows correctly, but + * Windows utilities may want to change the order, with a + * consequence of applying the group denials to the Windows owner. + * The interpretation on Linux is not affected by the order change. + * + * 2) if root is either owner or group, two problems arise : + * - granting full rights to administrator (as needed to transpose + * to Windows rights bypassing granting to root) would imply + * Linux permissions to always be seen as rwx, no matter the chmod + * - there is no different SID to separate an administrator owner + * from an administrator group. Hence Linux permissions for owner + * would always be similar to permissions to group. + * + * as a work-around, up to 5 ACE's are set up if owner or group : + * - grants to owner, always present at first position + * - grants to group, always present + * - grants to world, unless none + * - full privileges to administrator, always present + * - full privileges to system, always present + * + * On Windows, these ACE's are processed normally, though they + * are redundant (owner, group and administrator are the same, + * as a consequence any denials would damage administrator rights) + * but on Linux, privileges to administrator are ignored (they + * are not needed as root has always full privileges), and + * neither grants to group are applied to owner, nor grants to + * world are applied to owner or group. + * + * 3) finally a similar situation arises when group is owner (they + * have the same SID), but is not root. + * In this situation up to 6 ACE's are set up : + * + * - denials to owner (preventing grants to world to apply) + * - grants to owner (always present) + * - grants to group (unless groups has same rights as world) + * - grants to world (unless none) + * - full privileges to administrator, always present + * - full privileges to system, always present + * + * On Windows, these ACE's are processed normally, though they + * are redundant (as owner and group are the same), but this has + * no impact on administrator rights + * + * Special flags (S_ISVTX, S_ISGID, S_ISUID) : + * an extra null ACE is inserted to hold these flags, using + * the same conventions as cygwin. + * + */ + +static int buildacls_posix(struct MAPPING* const mapping[], + char *secattr, int offs, const struct POSIX_SECURITY *pxdesc, + int isdir, const SID *usid, const SID *gsid) +{ + struct BUILD_CONTEXT aceset[2], *pset; + BOOL adminowns; + BOOL groupowns; + ACL *pacl; + ACCESS_ALLOWED_ACE *pgace; + ACCESS_ALLOWED_ACE *pdace; + const struct POSIX_ACE *pxace; + BOOL ok; + mode_t mode; + u16 tag; + u16 perms; + ACE_FLAGS flags; + int pos; + int i; + int k; + BIGSID defsid; + const SID *sid; + int acecnt; + int usidsz; + int gsidsz; + int wsidsz; + int asidsz; + int ssidsz; + int nsidsz; + le32 grants; + + usidsz = ntfs_sid_size(usid); + gsidsz = ntfs_sid_size(gsid); + wsidsz = ntfs_sid_size(worldsid); + asidsz = ntfs_sid_size(adminsid); + ssidsz = ntfs_sid_size(systemsid); + mode = pxdesc->mode; + /* adminowns and groupowns are used for both lists */ + adminowns = ntfs_same_sid(usid, adminsid) + || ntfs_same_sid(gsid, adminsid); + groupowns = !adminowns && ntfs_same_sid(usid, gsid); + + ok = TRUE; + + /* ACL header */ + pacl = (ACL*)&secattr[offs]; + pacl->revision = ACL_REVISION; + pacl->alignment1 = 0; + pacl->size = cpu_to_le16(sizeof(ACL) + usidsz + 8); + pacl->ace_count = const_cpu_to_le16(0); + pacl->alignment2 = const_cpu_to_le16(0); + + /* + * Determine what is allowed to some group or world + * to prevent designated users or other groups to get + * rights from groups or world + * Do the same if owner and group appear as designated + * user or group + * Also get global mask + */ + for (k=0; k<2; k++) { + pset = &aceset[k]; + pset->selfuserperms = 0; + pset->selfgrpperms = 0; + pset->grpperms = 0; + pset->othperms = 0; + pset->mask = (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X); + pset->designates = 0; + pset->withmask = 0; + pset->rootspecial = 0; + pset->adminowns = adminowns; + pset->groupowns = groupowns; + pset->isdir = isdir; + } + + for (i=pxdesc->acccnt+pxdesc->defcnt-1; i>=0; i--) { + if (i >= pxdesc->acccnt) { + pset = &aceset[1]; + pxace = &pxdesc->acl.ace[i + pxdesc->firstdef - pxdesc->acccnt]; + } else { + pset = &aceset[0]; + pxace = &pxdesc->acl.ace[i]; + } + switch (pxace->tag) { + case POSIX_ACL_USER : + pset->designates++; + if (pxace->id) { + sid = NTFS_FIND_USID(mapping[MAPUSERS], + pxace->id, (SID*)&defsid); + if (sid && ntfs_same_sid(sid,usid)) + pset->selfuserperms |= pxace->perms; + } else + /* root as designated user is processed apart */ + pset->rootspecial = TRUE; + break; + case POSIX_ACL_GROUP : + pset->designates++; + if (pxace->id) { + sid = NTFS_FIND_GSID(mapping[MAPUSERS], + pxace->id, (SID*)&defsid); + if (sid && ntfs_same_sid(sid,gsid)) + pset->selfgrpperms |= pxace->perms; + } else + /* root as designated group is processed apart */ + pset->rootspecial = TRUE; + /* fall through */ + case POSIX_ACL_GROUP_OBJ : + pset->grpperms |= pxace->perms; + break; + case POSIX_ACL_OTHER : + pset->othperms = pxace->perms; + break; + case POSIX_ACL_MASK : + pset->withmask++; + pset->mask = pxace->perms; + default : + break; + } + } + +if (pxdesc->defcnt && (pxdesc->firstdef != pxdesc->acccnt)) { +ntfs_log_error("** error : access and default not consecutive\n"); +return (0); +} + /* + * First insert all denials for owner and each + * designated user (with mask if needed) + */ + + pacl->ace_count = const_cpu_to_le16(0); + pacl->size = const_cpu_to_le16(sizeof(ACL)); + for (i=0; (i<(pxdesc->acccnt + pxdesc->defcnt)) && ok; i++) { + if (i >= pxdesc->acccnt) { + flags = INHERIT_ONLY_ACE + | OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + pset = &aceset[1]; + pxace = &pxdesc->acl.ace[i + pxdesc->firstdef - pxdesc->acccnt]; + } else { + if (pxdesc->defcnt) + flags = NO_PROPAGATE_INHERIT_ACE; + else + flags = (isdir ? DIR_INHERITANCE + : FILE_INHERITANCE); + pset = &aceset[0]; + pxace = &pxdesc->acl.ace[i]; + } + tag = pxace->tag; + perms = pxace->perms; + switch (tag) { + + /* insert denial ACEs for each owner or allowed user */ + + case POSIX_ACL_USER : + case POSIX_ACL_USER_OBJ : + + ok = build_user_denials(pacl, + usid, mapping, flags, pxace, pset); + break; + default : + break; + } + } + + /* + * for directories, insert a world execution denial + * inherited to plain files. + * This is to prevent Windows from granting execution + * of files through inheritance from parent directory + */ + + if (isdir && ok) { + pos = le16_to_cpu(pacl->size); + pdace = (ACCESS_DENIED_ACE*) &secattr[offs + pos]; + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->flags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE; + pdace->size = cpu_to_le16(wsidsz + 8); + pdace->mask = FILE_EXEC; + memcpy((char*)&pdace->sid, worldsid, wsidsz); + pos += wsidsz + 8; + acecnt = le16_to_cpu(pacl->ace_count) + 1; + pacl->ace_count = cpu_to_le16(acecnt); + pacl->size = cpu_to_le16(pos); + } + + /* + * now insert (if needed) + * - grants to owner and designated users + * - mask and denials for all groups + * - grants to other + */ + + for (i=0; (i<(pxdesc->acccnt + pxdesc->defcnt)) && ok; i++) { + if (i >= pxdesc->acccnt) { + flags = INHERIT_ONLY_ACE + | OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + pset = &aceset[1]; + pxace = &pxdesc->acl.ace[i + pxdesc->firstdef - pxdesc->acccnt]; + } else { + if (pxdesc->defcnt) + flags = NO_PROPAGATE_INHERIT_ACE; + else + flags = (isdir ? DIR_INHERITANCE + : FILE_INHERITANCE); + pset = &aceset[0]; + pxace = &pxdesc->acl.ace[i]; + } + tag = pxace->tag; + perms = pxace->perms; + switch (tag) { + + /* ACE for each owner or allowed user */ + + case POSIX_ACL_USER : + case POSIX_ACL_USER_OBJ : + ok = build_user_grants(pacl,usid, + mapping,flags,pxace,pset); + break; + + case POSIX_ACL_GROUP : + case POSIX_ACL_GROUP_OBJ : + + /* denials and grants for groups */ + + ok = build_group_denials_grant(pacl,gsid, + mapping,flags,pxace,pset); + break; + + case POSIX_ACL_OTHER : + + /* grants for other users */ + + pos = le16_to_cpu(pacl->size); + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + grants = WORLD_RIGHTS; + if (isdir) { + if (perms & POSIX_PERM_X) + grants |= DIR_EXEC; + if (perms & POSIX_PERM_W) + grants |= DIR_WRITE; + if (perms & POSIX_PERM_R) + grants |= DIR_READ; + } else { + if (perms & POSIX_PERM_X) + grants |= FILE_EXEC; + if (perms & POSIX_PERM_W) + grants |= FILE_WRITE; + if (perms & POSIX_PERM_R) + grants |= FILE_READ; + } + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = flags; + pgace->size = cpu_to_le16(wsidsz + 8); + pgace->mask = grants; + memcpy((char*)&pgace->sid, worldsid, wsidsz); + pos += wsidsz + 8; + acecnt = le16_to_cpu(pacl->ace_count) + 1; + pacl->ace_count = cpu_to_le16(acecnt); + pacl->size = cpu_to_le16(pos); + break; + } + } + + if (!ok) { + errno = EINVAL; + pos = 0; + } else { + /* an ACE for administrators */ + /* always full access */ + + pos = le16_to_cpu(pacl->size); + acecnt = le16_to_cpu(pacl->ace_count); + if (isdir) + flags = OBJECT_INHERIT_ACE + | CONTAINER_INHERIT_ACE; + else + flags = NO_PROPAGATE_INHERIT_ACE; + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = flags; + pgace->size = cpu_to_le16(asidsz + 8); + grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; + pgace->mask = grants; + memcpy((char*)&pgace->sid, adminsid, asidsz); + pos += asidsz + 8; + acecnt++; + + /* an ACE for system (needed ?) */ + /* always full access */ + + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = flags; + pgace->size = cpu_to_le16(ssidsz + 8); + grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; + pgace->mask = grants; + memcpy((char*)&pgace->sid, systemsid, ssidsz); + pos += ssidsz + 8; + acecnt++; + + /* a null ACE to hold special flags */ + /* using the same representation as cygwin */ + + if (mode & (S_ISVTX | S_ISGID | S_ISUID)) { + nsidsz = ntfs_sid_size(nullsid); + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = NO_PROPAGATE_INHERIT_ACE; + pgace->size = cpu_to_le16(nsidsz + 8); + grants = const_cpu_to_le32(0); + if (mode & S_ISUID) + grants |= FILE_APPEND_DATA; + if (mode & S_ISGID) + grants |= FILE_WRITE_DATA; + if (mode & S_ISVTX) + grants |= FILE_READ_DATA; + pgace->mask = grants; + memcpy((char*)&pgace->sid, nullsid, nsidsz); + pos += nsidsz + 8; + acecnt++; + } + + /* fix ACL header */ + pacl->size = cpu_to_le16(pos); + pacl->ace_count = cpu_to_le16(acecnt); + } + return (ok ? pos : 0); +} + +#endif /* POSIXACLS */ + +static int buildacls(char *secattr, int offs, mode_t mode, int isdir, + const SID * usid, const SID * gsid) +{ + ACL *pacl; + ACCESS_ALLOWED_ACE *pgace; + ACCESS_ALLOWED_ACE *pdace; + BOOL adminowns; + BOOL groupowns; + ACE_FLAGS gflags; + int pos; + int acecnt; + int usidsz; + int gsidsz; + int wsidsz; + int asidsz; + int ssidsz; + int nsidsz; + le32 grants; + le32 denials; + + usidsz = ntfs_sid_size(usid); + gsidsz = ntfs_sid_size(gsid); + wsidsz = ntfs_sid_size(worldsid); + asidsz = ntfs_sid_size(adminsid); + ssidsz = ntfs_sid_size(systemsid); + adminowns = ntfs_same_sid(usid, adminsid) + || ntfs_same_sid(gsid, adminsid); + groupowns = !adminowns && ntfs_same_sid(usid, gsid); + + /* ACL header */ + pacl = (ACL*)&secattr[offs]; + pacl->revision = ACL_REVISION; + pacl->alignment1 = 0; + pacl->size = cpu_to_le16(sizeof(ACL) + usidsz + 8); + pacl->ace_count = const_cpu_to_le16(1); + pacl->alignment2 = const_cpu_to_le16(0); + pos = sizeof(ACL); + acecnt = 0; + + /* compute a grant ACE for owner */ + /* this ACE will be inserted after denial for owner */ + + grants = OWNER_RIGHTS; + if (isdir) { + gflags = DIR_INHERITANCE; + if (mode & S_IXUSR) + grants |= DIR_EXEC; + if (mode & S_IWUSR) + grants |= DIR_WRITE; + if (mode & S_IRUSR) + grants |= DIR_READ; + } else { + gflags = FILE_INHERITANCE; + if (mode & S_IXUSR) + grants |= FILE_EXEC; + if (mode & S_IWUSR) + grants |= FILE_WRITE; + if (mode & S_IRUSR) + grants |= FILE_READ; + } + + /* a possible ACE to deny owner what he/she would */ + /* induely get from administrator, group or world */ + /* unless owner is administrator or group */ + + denials = const_cpu_to_le32(0); + pdace = (ACCESS_DENIED_ACE*) &secattr[offs + pos]; + if (!adminowns) { + if (!groupowns) { + if (isdir) { + pdace->flags = DIR_INHERITANCE; + if (mode & (S_IXGRP | S_IXOTH)) + denials |= DIR_EXEC; + if (mode & (S_IWGRP | S_IWOTH)) + denials |= DIR_WRITE; + if (mode & (S_IRGRP | S_IROTH)) + denials |= DIR_READ; + } else { + pdace->flags = FILE_INHERITANCE; + if (mode & (S_IXGRP | S_IXOTH)) + denials |= FILE_EXEC; + if (mode & (S_IWGRP | S_IWOTH)) + denials |= FILE_WRITE; + if (mode & (S_IRGRP | S_IROTH)) + denials |= FILE_READ; + } + } else { + if (isdir) { + pdace->flags = DIR_INHERITANCE; + if ((mode & S_IXOTH) && !(mode & S_IXGRP)) + denials |= DIR_EXEC; + if ((mode & S_IWOTH) && !(mode & S_IWGRP)) + denials |= DIR_WRITE; + if ((mode & S_IROTH) && !(mode & S_IRGRP)) + denials |= DIR_READ; + } else { + pdace->flags = FILE_INHERITANCE; + if ((mode & S_IXOTH) && !(mode & S_IXGRP)) + denials |= FILE_EXEC; + if ((mode & S_IWOTH) && !(mode & S_IWGRP)) + denials |= FILE_WRITE; + if ((mode & S_IROTH) && !(mode & S_IRGRP)) + denials |= FILE_READ; + } + } + denials &= ~grants; + if (denials) { + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->size = cpu_to_le16(usidsz + 8); + pdace->mask = denials; + memcpy((char*)&pdace->sid, usid, usidsz); + pos += usidsz + 8; + acecnt++; + } + } + /* + * for directories, a world execution denial + * inherited to plain files + */ + + if (isdir) { + pdace = (ACCESS_DENIED_ACE*) &secattr[offs + pos]; + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->flags = INHERIT_ONLY_ACE | OBJECT_INHERIT_ACE; + pdace->size = cpu_to_le16(wsidsz + 8); + pdace->mask = FILE_EXEC; + memcpy((char*)&pdace->sid, worldsid, wsidsz); + pos += wsidsz + 8; + acecnt++; + } + + + /* now insert grants to owner */ + pgace = (ACCESS_ALLOWED_ACE*) &secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->size = cpu_to_le16(usidsz + 8); + pgace->flags = gflags; + pgace->mask = grants; + memcpy((char*)&pgace->sid, usid, usidsz); + pos += usidsz + 8; + acecnt++; + + /* a grant ACE for group */ + /* unless group has the same rights as world */ + /* but present if group is owner or owner is administrator */ + /* this ACE will be inserted after denials for group */ + + if (adminowns + || groupowns + || (((mode >> 3) ^ mode) & 7)) { + grants = WORLD_RIGHTS; + if (isdir) { + gflags = DIR_INHERITANCE; + if (mode & S_IXGRP) + grants |= DIR_EXEC; + if (mode & S_IWGRP) + grants |= DIR_WRITE; + if (mode & S_IRGRP) + grants |= DIR_READ; + } else { + gflags = FILE_INHERITANCE; + if (mode & S_IXGRP) + grants |= FILE_EXEC; + if (mode & S_IWGRP) + grants |= FILE_WRITE; + if (mode & S_IRGRP) + grants |= FILE_READ; + } + + /* a possible ACE to deny group what it would get from world */ + /* or administrator, unless owner is administrator or group */ + + denials = const_cpu_to_le32(0); + pdace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + if (!adminowns && !groupowns) { + if (isdir) { + pdace->flags = DIR_INHERITANCE; + if (mode & S_IXOTH) + denials |= DIR_EXEC; + if (mode & S_IWOTH) + denials |= DIR_WRITE; + if (mode & S_IROTH) + denials |= DIR_READ; + } else { + pdace->flags = FILE_INHERITANCE; + if (mode & S_IXOTH) + denials |= FILE_EXEC; + if (mode & S_IWOTH) + denials |= FILE_WRITE; + if (mode & S_IROTH) + denials |= FILE_READ; + } + denials &= ~(grants | OWNER_RIGHTS); + if (denials) { + pdace->type = ACCESS_DENIED_ACE_TYPE; + pdace->size = cpu_to_le16(gsidsz + 8); + pdace->mask = denials; + memcpy((char*)&pdace->sid, gsid, gsidsz); + pos += gsidsz + 8; + acecnt++; + } + } + + if (adminowns + || groupowns + || ((mode >> 3) & ~mode & 7)) { + /* now insert grants to group */ + /* if more rights than other */ + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = gflags; + pgace->size = cpu_to_le16(gsidsz + 8); + pgace->mask = grants; + memcpy((char*)&pgace->sid, gsid, gsidsz); + pos += gsidsz + 8; + acecnt++; + } + } + + /* an ACE for world users */ + + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + grants = WORLD_RIGHTS; + if (isdir) { + pgace->flags = DIR_INHERITANCE; + if (mode & S_IXOTH) + grants |= DIR_EXEC; + if (mode & S_IWOTH) + grants |= DIR_WRITE; + if (mode & S_IROTH) + grants |= DIR_READ; + } else { + pgace->flags = FILE_INHERITANCE; + if (mode & S_IXOTH) + grants |= FILE_EXEC; + if (mode & S_IWOTH) + grants |= FILE_WRITE; + if (mode & S_IROTH) + grants |= FILE_READ; + } + pgace->size = cpu_to_le16(wsidsz + 8); + pgace->mask = grants; + memcpy((char*)&pgace->sid, worldsid, wsidsz); + pos += wsidsz + 8; + acecnt++; + + /* an ACE for administrators */ + /* always full access */ + + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + if (isdir) + pgace->flags = DIR_INHERITANCE; + else + pgace->flags = FILE_INHERITANCE; + pgace->size = cpu_to_le16(asidsz + 8); + grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; + pgace->mask = grants; + memcpy((char*)&pgace->sid, adminsid, asidsz); + pos += asidsz + 8; + acecnt++; + + /* an ACE for system (needed ?) */ + /* always full access */ + + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + if (isdir) + pgace->flags = DIR_INHERITANCE; + else + pgace->flags = FILE_INHERITANCE; + pgace->size = cpu_to_le16(ssidsz + 8); + grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC; + pgace->mask = grants; + memcpy((char*)&pgace->sid, systemsid, ssidsz); + pos += ssidsz + 8; + acecnt++; + + /* a null ACE to hold special flags */ + /* using the same representation as cygwin */ + + if (mode & (S_ISVTX | S_ISGID | S_ISUID)) { + nsidsz = ntfs_sid_size(nullsid); + pgace = (ACCESS_ALLOWED_ACE*)&secattr[offs + pos]; + pgace->type = ACCESS_ALLOWED_ACE_TYPE; + pgace->flags = NO_PROPAGATE_INHERIT_ACE; + pgace->size = cpu_to_le16(nsidsz + 8); + grants = const_cpu_to_le32(0); + if (mode & S_ISUID) + grants |= FILE_APPEND_DATA; + if (mode & S_ISGID) + grants |= FILE_WRITE_DATA; + if (mode & S_ISVTX) + grants |= FILE_READ_DATA; + pgace->mask = grants; + memcpy((char*)&pgace->sid, nullsid, nsidsz); + pos += nsidsz + 8; + acecnt++; + } + + /* fix ACL header */ + pacl->size = cpu_to_le16(pos); + pacl->ace_count = cpu_to_le16(acecnt); + return (pos); +} + +#if POSIXACLS + +/* + * Build a full security descriptor from a Posix ACL + * returns descriptor in allocated memory, must free() after use + */ + +char *ntfs_build_descr_posix(struct MAPPING* const mapping[], + struct POSIX_SECURITY *pxdesc, + int isdir, const SID *usid, const SID *gsid) +{ + int newattrsz; + SECURITY_DESCRIPTOR_RELATIVE *pnhead; + char *newattr; + int aclsz; + int usidsz; + int gsidsz; + int wsidsz; + int asidsz; + int ssidsz; + int k; + + usidsz = ntfs_sid_size(usid); + gsidsz = ntfs_sid_size(gsid); + wsidsz = ntfs_sid_size(worldsid); + asidsz = ntfs_sid_size(adminsid); + ssidsz = ntfs_sid_size(systemsid); + + /* allocate enough space for the new security attribute */ + newattrsz = sizeof(SECURITY_DESCRIPTOR_RELATIVE) /* header */ + + usidsz + gsidsz /* usid and gsid */ + + sizeof(ACL) /* acl header */ + + 2*(8 + usidsz) /* two possible ACE for user */ + + 3*(8 + gsidsz) /* three possible ACE for group and mask */ + + 8 + wsidsz /* one ACE for world */ + + 8 + asidsz /* one ACE for admin */ + + 8 + ssidsz; /* one ACE for system */ + if (isdir) /* a world denial for directories */ + newattrsz += 8 + wsidsz; + if (pxdesc->mode & 07000) /* a NULL ACE for special modes */ + newattrsz += 8 + ntfs_sid_size(nullsid); + /* account for non-owning users and groups */ + for (k=0; kacccnt; k++) { + if ((pxdesc->acl.ace[k].tag == POSIX_ACL_USER) + || (pxdesc->acl.ace[k].tag == POSIX_ACL_GROUP)) + newattrsz += 3*40; /* fixme : maximum size */ + } + /* account for default ACE's */ + newattrsz += 2*40*pxdesc->defcnt; /* fixme : maximum size */ + newattr = (char*)ntfs_malloc(newattrsz); + if (newattr) { + /* build the main header part */ + pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)newattr; + pnhead->revision = SECURITY_DESCRIPTOR_REVISION; + pnhead->alignment = 0; + /* + * The flag SE_DACL_PROTECTED prevents the ACL + * to be changed in an inheritance after creation + */ + pnhead->control = SE_DACL_PRESENT | SE_DACL_PROTECTED + | SE_SELF_RELATIVE; + /* + * Windows prefers ACL first, do the same to + * get the same hash value and avoid duplication + */ + /* build permissions */ + aclsz = buildacls_posix(mapping,newattr, + sizeof(SECURITY_DESCRIPTOR_RELATIVE), + pxdesc, isdir, usid, gsid); + if (aclsz && ((int)(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz + usidsz + gsidsz) <= newattrsz)) { + /* append usid and gsid */ + memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz], usid, usidsz); + memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz + usidsz], gsid, gsidsz); + /* positions of ACL, USID and GSID into header */ + pnhead->owner = + cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz); + pnhead->group = + cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz + usidsz); + pnhead->sacl = const_cpu_to_le32(0); + pnhead->dacl = + const_cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + } else { + /* ACL failure (errno set) or overflow */ + free(newattr); + newattr = (char*)NULL; + if (aclsz) { + /* hope error was detected before overflowing */ + ntfs_log_error("Security descriptor is longer than expected\n"); + errno = EIO; + } + } + } else + errno = ENOMEM; + return (newattr); +} + +#endif /* POSIXACLS */ + +/* + * Build a full security descriptor + * returns descriptor in allocated memory, must free() after use + */ + +char *ntfs_build_descr(mode_t mode, + int isdir, const SID * usid, const SID * gsid) +{ + int newattrsz; + SECURITY_DESCRIPTOR_RELATIVE *pnhead; + char *newattr; + int aclsz; + int usidsz; + int gsidsz; + int wsidsz; + int asidsz; + int ssidsz; + + usidsz = ntfs_sid_size(usid); + gsidsz = ntfs_sid_size(gsid); + wsidsz = ntfs_sid_size(worldsid); + asidsz = ntfs_sid_size(adminsid); + ssidsz = ntfs_sid_size(systemsid); + + /* allocate enough space for the new security attribute */ + newattrsz = sizeof(SECURITY_DESCRIPTOR_RELATIVE) /* header */ + + usidsz + gsidsz /* usid and gsid */ + + sizeof(ACL) /* acl header */ + + 2*(8 + usidsz) /* two possible ACE for user */ + + 2*(8 + gsidsz) /* two possible ACE for group */ + + 8 + wsidsz /* one ACE for world */ + + 8 + asidsz /* one ACE for admin */ + + 8 + ssidsz; /* one ACE for system */ + if (isdir) /* a world denial for directories */ + newattrsz += 8 + wsidsz; + if (mode & 07000) /* a NULL ACE for special modes */ + newattrsz += 8 + ntfs_sid_size(nullsid); + newattr = (char*)ntfs_malloc(newattrsz); + if (newattr) { + /* build the main header part */ + pnhead = (SECURITY_DESCRIPTOR_RELATIVE*) newattr; + pnhead->revision = SECURITY_DESCRIPTOR_REVISION; + pnhead->alignment = 0; + /* + * The flag SE_DACL_PROTECTED prevents the ACL + * to be changed in an inheritance after creation + */ + pnhead->control = SE_DACL_PRESENT | SE_DACL_PROTECTED + | SE_SELF_RELATIVE; + /* + * Windows prefers ACL first, do the same to + * get the same hash value and avoid duplication + */ + /* build permissions */ + aclsz = buildacls(newattr, + sizeof(SECURITY_DESCRIPTOR_RELATIVE), + mode, isdir, usid, gsid); + if (((int)sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz + usidsz + gsidsz) <= newattrsz) { + /* append usid and gsid */ + memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz], usid, usidsz); + memcpy(&newattr[sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz + usidsz], gsid, gsidsz); + /* positions of ACL, USID and GSID into header */ + pnhead->owner = + cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz); + pnhead->group = + cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE) + + aclsz + usidsz); + pnhead->sacl = const_cpu_to_le32(0); + pnhead->dacl = + const_cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + } else { + /* hope error was detected before overflowing */ + free(newattr); + newattr = (char*)NULL; + ntfs_log_error("Security descriptor is longer than expected\n"); + errno = EIO; + } + } else + errno = ENOMEM; + return (newattr); +} + +/* + * Create a mode_t permission set + * from owner, group and world grants as represented in ACEs + */ + +static int merge_permissions(BOOL isdir, + le32 owner, le32 group, le32 world, le32 special) + +{ + int perm; + + perm = 0; + /* build owner permission */ + if (owner) { + if (isdir) { + /* exec if any of list, traverse */ + if (owner & DIR_GEXEC) + perm |= S_IXUSR; + /* write if any of addfile, adddir, delchild */ + if (owner & DIR_GWRITE) + perm |= S_IWUSR; + /* read if any of list */ + if (owner & DIR_GREAD) + perm |= S_IRUSR; + } else { + /* exec if execute or generic execute */ + if (owner & FILE_GEXEC) + perm |= S_IXUSR; + /* write if any of writedata or generic write */ + if (owner & FILE_GWRITE) + perm |= S_IWUSR; + /* read if any of readdata or generic read */ + if (owner & FILE_GREAD) + perm |= S_IRUSR; + } + } + /* build group permission */ + if (group) { + if (isdir) { + /* exec if any of list, traverse */ + if (group & DIR_GEXEC) + perm |= S_IXGRP; + /* write if any of addfile, adddir, delchild */ + if (group & DIR_GWRITE) + perm |= S_IWGRP; + /* read if any of list */ + if (group & DIR_GREAD) + perm |= S_IRGRP; + } else { + /* exec if execute */ + if (group & FILE_GEXEC) + perm |= S_IXGRP; + /* write if any of writedata, appenddata */ + if (group & FILE_GWRITE) + perm |= S_IWGRP; + /* read if any of readdata */ + if (group & FILE_GREAD) + perm |= S_IRGRP; + } + } + /* build world permission */ + if (world) { + if (isdir) { + /* exec if any of list, traverse */ + if (world & DIR_GEXEC) + perm |= S_IXOTH; + /* write if any of addfile, adddir, delchild */ + if (world & DIR_GWRITE) + perm |= S_IWOTH; + /* read if any of list */ + if (world & DIR_GREAD) + perm |= S_IROTH; + } else { + /* exec if execute */ + if (world & FILE_GEXEC) + perm |= S_IXOTH; + /* write if any of writedata, appenddata */ + if (world & FILE_GWRITE) + perm |= S_IWOTH; + /* read if any of readdata */ + if (world & FILE_GREAD) + perm |= S_IROTH; + } + } + /* build special permission flags */ + if (special) { + if (special & FILE_APPEND_DATA) + perm |= S_ISUID; + if (special & FILE_WRITE_DATA) + perm |= S_ISGID; + if (special & FILE_READ_DATA) + perm |= S_ISVTX; + } + return (perm); +} + +#if POSIXACLS + +/* + * Normalize a Posix ACL either from a sorted raw set of + * access ACEs or default ACEs + * (standard case : different owner, group and administrator) + */ + +static int norm_std_permissions_posix(struct POSIX_SECURITY *posix_desc, + BOOL groupowns, int start, int count, int target) +{ + int j,k; + s32 id; + u16 tag; + u16 tagsset; + struct POSIX_ACE *pxace; + mode_t grantgrps; + mode_t grantwrld; + mode_t denywrld; + mode_t allow; + mode_t deny; + mode_t perms; + mode_t mode; + + mode = 0; + tagsset = 0; + /* + * Determine what is granted to some group or world + * Also get denials to world which are meant to prevent + * execution flags to be inherited by plain files + */ + pxace = posix_desc->acl.ace; + grantgrps = 0; + grantwrld = 0; + denywrld = 0; + for (j=start; j<(start + count); j++) { + if (pxace[j].perms & POSIX_PERM_DENIAL) { + /* deny world exec unless for default */ + if ((pxace[j].tag == POSIX_ACL_OTHER) + && !start) + denywrld = pxace[j].perms; + } else { + switch (pxace[j].tag) { + case POSIX_ACL_GROUP_OBJ : + grantgrps |= pxace[j].perms; + break; + case POSIX_ACL_GROUP : + if (pxace[j].id) + grantgrps |= pxace[j].perms; + break; + case POSIX_ACL_OTHER : + grantwrld = pxace[j].perms; + break; + default : + break; + } + } + } + /* + * Collect groups of ACEs related to the same id + * and determine what is granted and what is denied. + * It is important the ACEs have been sorted + */ + j = start; + k = target; + while (j < (start + count)) { + tag = pxace[j].tag; + id = pxace[j].id; + if (pxace[j].perms & POSIX_PERM_DENIAL) { + deny = pxace[j].perms | denywrld; + allow = 0; + } else { + deny = denywrld; + allow = pxace[j].perms; + } + j++; + while ((j < (start + count)) + && (pxace[j].tag == tag) + && (pxace[j].id == id)) { + if (pxace[j].perms & POSIX_PERM_DENIAL) + deny |= pxace[j].perms; + else + allow |= pxace[j].perms; + j++; + } + /* + * Build the permissions equivalent to grants and denials + */ + if (groupowns) { + if (tag == POSIX_ACL_MASK) + perms = ~deny; + else + perms = allow & ~deny; + } else + switch (tag) { + case POSIX_ACL_USER_OBJ : + perms = (allow | grantgrps | grantwrld) & ~deny; + break; + case POSIX_ACL_USER : + if (id) + perms = (allow | grantgrps | grantwrld) + & ~deny; + else + perms = allow; + break; + case POSIX_ACL_GROUP_OBJ : + perms = (allow | grantwrld) & ~deny; + break; + case POSIX_ACL_GROUP : + if (id) + perms = (allow | grantwrld) & ~deny; + else + perms = allow; + break; + case POSIX_ACL_MASK : + perms = ~deny; + break; + default : + perms = allow & ~deny; + break; + } + /* + * Store into a Posix ACE + */ + if (tag != POSIX_ACL_SPECIAL) { + pxace[k].tag = tag; + pxace[k].id = id; + pxace[k].perms = perms + & (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X); + tagsset |= tag; + k++; + } + switch (tag) { + case POSIX_ACL_USER_OBJ : + mode |= ((perms & 7) << 6); + break; + case POSIX_ACL_GROUP_OBJ : + case POSIX_ACL_MASK : + mode = (mode & 07707) | ((perms & 7) << 3); + break; + case POSIX_ACL_OTHER : + mode |= perms & 7; + break; + case POSIX_ACL_SPECIAL : + mode |= (perms & (S_ISVTX | S_ISUID | S_ISGID)); + break; + default : + break; + } + } + if (!start) { /* not satisfactory */ + posix_desc->mode = mode; + posix_desc->tagsset = tagsset; + } + return (k - target); +} + +#endif /* POSIXACLS */ + +/* + * Interpret an ACL and extract meaningful grants + * (standard case : different owner, group and administrator) + */ + +static int build_std_permissions(const char *securattr, + const SID *usid, const SID *gsid, BOOL isdir) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const ACL *pacl; + const ACCESS_ALLOWED_ACE *pace; + int offdacl; + int offace; + int acecnt; + int nace; + BOOL noown; + le32 special; + le32 allowown, allowgrp, allowall; + le32 denyown, denygrp, denyall; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + pacl = (const ACL*)&securattr[offdacl]; + special = const_cpu_to_le32(0); + allowown = allowgrp = allowall = const_cpu_to_le32(0); + denyown = denygrp = denyall = const_cpu_to_le32(0); + noown = TRUE; + if (offdacl) { + acecnt = le16_to_cpu(pacl->ace_count); + offace = offdacl + sizeof(ACL); + } else { + acecnt = 0; + offace = 0; + } + for (nace = 0; nace < acecnt; nace++) { + pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; + if (!(pace->flags & INHERIT_ONLY_ACE)) { + if (ntfs_same_sid(usid, &pace->sid) + || ntfs_same_sid(ownersid, &pace->sid)) { + noown = FALSE; + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + allowown |= pace->mask; + else if (pace->type == ACCESS_DENIED_ACE_TYPE) + denyown |= pace->mask; + } else + if (ntfs_same_sid(gsid, &pace->sid) + && !(pace->mask & WRITE_OWNER)) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + allowgrp |= pace->mask; + else if (pace->type == ACCESS_DENIED_ACE_TYPE) + denygrp |= pace->mask; + } else + if (is_world_sid((const SID*)&pace->sid)) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + allowall |= pace->mask; + else + if (pace->type == ACCESS_DENIED_ACE_TYPE) + denyall |= pace->mask; + } else + if ((ntfs_same_sid((const SID*)&pace->sid,nullsid)) + && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) + special |= pace->mask; + } + offace += le16_to_cpu(pace->size); + } + /* + * No indication about owner's rights : grant basic rights + * This happens for files created by Windows in directories + * created by Linux and owned by root, because Windows + * merges the admin ACEs + */ + if (noown) + allowown = (FILE_READ_DATA | FILE_WRITE_DATA | FILE_EXECUTE); + /* + * Add to owner rights granted to group or world + * unless denied personaly, and add to group rights + * granted to world unless denied specifically + */ + allowown |= (allowgrp | allowall); + allowgrp |= allowall; + return (merge_permissions(isdir, + allowown & ~(denyown | denyall), + allowgrp & ~(denygrp | denyall), + allowall & ~denyall, + special)); +} + +/* + * Interpret an ACL and extract meaningful grants + * (special case : owner and group are the same, + * and not administrator) + */ + +static int build_owngrp_permissions(const char *securattr, + const SID *usid, BOOL isdir) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const ACL *pacl; + const ACCESS_ALLOWED_ACE *pace; + int offdacl; + int offace; + int acecnt; + int nace; + le32 special; + BOOL grppresent; + le32 allowown, allowgrp, allowall; + le32 denyown, denygrp, denyall; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + pacl = (const ACL*)&securattr[offdacl]; + special = const_cpu_to_le32(0); + allowown = allowgrp = allowall = const_cpu_to_le32(0); + denyown = denygrp = denyall = const_cpu_to_le32(0); + grppresent = FALSE; + if (offdacl) { + acecnt = le16_to_cpu(pacl->ace_count); + offace = offdacl + sizeof(ACL); + } else + acecnt = 0; + for (nace = 0; nace < acecnt; nace++) { + pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; + if (!(pace->flags & INHERIT_ONLY_ACE)) { + if ((ntfs_same_sid(usid, &pace->sid) + || ntfs_same_sid(ownersid, &pace->sid)) + && (pace->mask & WRITE_OWNER)) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + allowown |= pace->mask; + } else + if (ntfs_same_sid(usid, &pace->sid) + && (!(pace->mask & WRITE_OWNER))) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { + allowgrp |= pace->mask; + grppresent = TRUE; + } + } else + if (is_world_sid((const SID*)&pace->sid)) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + allowall |= pace->mask; + else + if (pace->type == ACCESS_DENIED_ACE_TYPE) + denyall |= pace->mask; + } else + if ((ntfs_same_sid((const SID*)&pace->sid,nullsid)) + && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) + special |= pace->mask; + } + offace += le16_to_cpu(pace->size); + } + if (!grppresent) + allowgrp = allowall; + return (merge_permissions(isdir, + allowown & ~(denyown | denyall), + allowgrp & ~(denygrp | denyall), + allowall & ~denyall, + special)); +} + +#if POSIXACLS + +/* + * Normalize a Posix ACL either from a sorted raw set of + * access ACEs or default ACEs + * (special case : owner or/and group is administrator) + */ + +static int norm_ownadmin_permissions_posix(struct POSIX_SECURITY *posix_desc, + int start, int count, int target) +{ + int j,k; + s32 id; + u16 tag; + u16 tagsset; + struct POSIX_ACE *pxace; + int acccnt; + mode_t denywrld; + mode_t allow; + mode_t deny; + mode_t perms; + mode_t mode; + + mode = 0; + pxace = posix_desc->acl.ace; + acccnt = posix_desc->acccnt; + tagsset = 0; + denywrld = 0; + /* + * Get denials to world which are meant to prevent + * execution flags to be inherited by plain files + */ + for (j=start; j<(start + count); j++) { + if (pxace[j].perms & POSIX_PERM_DENIAL) { + /* deny world exec not for default */ + if ((pxace[j].tag == POSIX_ACL_OTHER) + && !start) + denywrld = pxace[j].perms; + } + } + /* + * Collect groups of ACEs related to the same id + * and determine what is granted (denials are ignored) + * It is important the ACEs have been sorted + */ + j = start; + k = target; + deny = 0; + while (j < (start + count)) { + allow = 0; + tag = pxace[j].tag; + id = pxace[j].id; + if (tag == POSIX_ACL_MASK) { + deny = pxace[j].perms; + j++; + while ((j < (start + count)) + && (pxace[j].tag == POSIX_ACL_MASK)) + j++; + } else { + if (!(pxace[j].perms & POSIX_PERM_DENIAL)) + allow = pxace[j].perms; + j++; + while ((j < (start + count)) + && (pxace[j].tag == tag) + && (pxace[j].id == id)) { + if (!(pxace[j].perms & POSIX_PERM_DENIAL)) + allow |= pxace[j].perms; + j++; + } + } + + /* + * Store the grants into a Posix ACE + */ + if (tag == POSIX_ACL_MASK) + perms = ~deny; + else + perms = allow & ~denywrld; + if (tag != POSIX_ACL_SPECIAL) { + pxace[k].tag = tag; + pxace[k].id = id; + pxace[k].perms = perms + & (POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X); + tagsset |= tag; + k++; + } + switch (tag) { + case POSIX_ACL_USER_OBJ : + mode |= ((perms & 7) << 6); + break; + case POSIX_ACL_GROUP_OBJ : + case POSIX_ACL_MASK : + mode = (mode & 07707) | ((perms & 7) << 3); + break; + case POSIX_ACL_OTHER : + mode |= perms & 7; + break; + case POSIX_ACL_SPECIAL : + mode |= perms & (S_ISVTX | S_ISUID | S_ISGID); + break; + default : + break; + } + } + if (!start) { /* not satisfactory */ + posix_desc->mode = mode; + posix_desc->tagsset = tagsset; + } + return (k - target); +} + +#endif /* POSIXACLS */ + +/* + * Interpret an ACL and extract meaningful grants + * (special case : owner or/and group is administrator) + */ + + +static int build_ownadmin_permissions(const char *securattr, + const SID *usid, const SID *gsid, BOOL isdir) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const ACL *pacl; + const ACCESS_ALLOWED_ACE *pace; + int offdacl; + int offace; + int acecnt; + int nace; + BOOL firstapply; + int isforeign; + le32 special; + le32 allowown, allowgrp, allowall; + le32 denyown, denygrp, denyall; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + pacl = (const ACL*)&securattr[offdacl]; + special = const_cpu_to_le32(0); + allowown = allowgrp = allowall = const_cpu_to_le32(0); + denyown = denygrp = denyall = const_cpu_to_le32(0); + if (offdacl) { + acecnt = le16_to_cpu(pacl->ace_count); + offace = offdacl + sizeof(ACL); + } else { + acecnt = 0; + offace = 0; + } + firstapply = TRUE; + isforeign = 3; + for (nace = 0; nace < acecnt; nace++) { + pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; + if (!(pace->flags & INHERIT_ONLY_ACE) + && !(~pace->mask & (ROOT_OWNER_UNMARK | ROOT_GROUP_UNMARK))) { + if ((ntfs_same_sid(usid, &pace->sid) + || ntfs_same_sid(ownersid, &pace->sid)) + && (((pace->mask & WRITE_OWNER) && firstapply))) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { + allowown |= pace->mask; + isforeign &= ~1; + } else + if (pace->type == ACCESS_DENIED_ACE_TYPE) + denyown |= pace->mask; + } else + if (ntfs_same_sid(gsid, &pace->sid) + && (!(pace->mask & WRITE_OWNER))) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { + allowgrp |= pace->mask; + isforeign &= ~2; + } else + if (pace->type == ACCESS_DENIED_ACE_TYPE) + denygrp |= pace->mask; + } else if (is_world_sid((const SID*)&pace->sid)) { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + allowall |= pace->mask; + else + if (pace->type == ACCESS_DENIED_ACE_TYPE) + denyall |= pace->mask; + } + firstapply = FALSE; + } else + if (!(pace->flags & INHERIT_ONLY_ACE)) + if ((ntfs_same_sid((const SID*)&pace->sid,nullsid)) + && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) + special |= pace->mask; + offace += le16_to_cpu(pace->size); + } + if (isforeign) { + allowown |= (allowgrp | allowall); + allowgrp |= allowall; + } + return (merge_permissions(isdir, + allowown & ~(denyown | denyall), + allowgrp & ~(denygrp | denyall), + allowall & ~denyall, + special)); +} + +#if OWNERFROMACL + +/* + * Define the owner of a file as the first user allowed + * to change the owner, instead of the user defined as owner. + * + * This produces better approximations for files written by a + * Windows user in an inheritable directory owned by another user, + * as the access rights are inheritable but the ownership is not. + * + * An important case is the directories "Documents and Settings/user" + * which the users must have access to, though Windows considers them + * as owned by administrator. + */ + +const SID *ntfs_acl_owner(const char *securattr) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const SID *usid; + const ACL *pacl; + const ACCESS_ALLOWED_ACE *pace; + int offdacl; + int offace; + int acecnt; + int nace; + BOOL found; + + found = FALSE; + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + if (offdacl) { + pacl = (const ACL*)&securattr[offdacl]; + acecnt = le16_to_cpu(pacl->ace_count); + offace = offdacl + sizeof(ACL); + nace = 0; + do { + pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; + if ((pace->mask & WRITE_OWNER) + && (pace->type == ACCESS_ALLOWED_ACE_TYPE) + && ntfs_is_user_sid(&pace->sid)) + found = TRUE; + offace += le16_to_cpu(pace->size); + } while (!found && (++nace < acecnt)); + } + if (found) + usid = &pace->sid; + else + usid = (const SID*)&securattr[le32_to_cpu(phead->owner)]; + return (usid); +} + +#else + +/* + * Special case for files owned by administrator with full + * access granted to a mapped user : consider this user as the tenant + * of the file. + * + * This situation cannot be represented with Linux concepts and can + * only be found for files or directories created by Windows. + * Typical situation : directory "Documents and Settings/user" which + * is on the path to user's files and must be given access to user + * only. + * + * Check file is owned by administrator and no user has rights before + * calling. + * Returns the uid of tenant or zero if none + */ + + +static uid_t find_tenant(struct MAPPING *const mapping[], + const char *securattr) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const ACL *pacl; + const ACCESS_ALLOWED_ACE *pace; + int offdacl; + int offace; + int acecnt; + int nace; + uid_t tid; + uid_t xid; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + pacl = (const ACL*)&securattr[offdacl]; + tid = 0; + if (offdacl) { + acecnt = le16_to_cpu(pacl->ace_count); + offace = offdacl + sizeof(ACL); + } else + acecnt = 0; + for (nace = 0; nace < acecnt; nace++) { + pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; + if ((pace->type == ACCESS_ALLOWED_ACE_TYPE) + && (pace->mask & DIR_WRITE)) { + xid = NTFS_FIND_USER(mapping[MAPUSERS], &pace->sid); + if (xid) tid = xid; + } + offace += le16_to_cpu(pace->size); + } + return (tid); +} + +#endif /* OWNERFROMACL */ + +#if POSIXACLS + +/* + * Build Posix permissions from an ACL + * returns a pointer to the requested permissions + * or a null pointer (with errno set) if there is a problem + * + * If the NTFS ACL was created according to our rules, the retrieved + * Posix ACL should be the exact ACL which was set. However if + * the NTFS ACL was built by a different tool, the result could + * be a a poor approximation of what was expected + */ + +struct POSIX_SECURITY *ntfs_build_permissions_posix( + struct MAPPING *const mapping[], + const char *securattr, + const SID *usid, const SID *gsid, BOOL isdir) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + struct POSIX_SECURITY *pxdesc; + const ACL *pacl; + const ACCESS_ALLOWED_ACE *pace; + struct POSIX_ACE *pxace; + struct { + uid_t prevuid; + gid_t prevgid; + int groupmasks; + s16 tagsset; + BOOL gotowner; + BOOL gotownermask; + BOOL gotgroup; + mode_t permswrld; + } ctx[2], *pctx; + int offdacl; + int offace; + int alloccnt; + int acecnt; + uid_t uid; + gid_t gid; + int i,j; + int k,l; + BOOL ignore; + BOOL adminowns; + BOOL groupowns; + BOOL firstinh; + BOOL genericinh; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + offdacl = le32_to_cpu(phead->dacl); + if (offdacl) { + pacl = (const ACL*)&securattr[offdacl]; + acecnt = le16_to_cpu(pacl->ace_count); + offace = offdacl + sizeof(ACL); + } else { + acecnt = 0; + offace = 0; + } + adminowns = FALSE; + groupowns = ntfs_same_sid(gsid,usid); + firstinh = FALSE; + genericinh = FALSE; + /* + * Build a raw posix security descriptor + * by just translating permissions and ids + * Add 2 to the count of ACE to be able to insert + * a group ACE later in access and default ACLs + * and add 2 more to be able to insert ACEs for owner + * and 2 more for other + */ + alloccnt = acecnt + 6; + pxdesc = (struct POSIX_SECURITY*)malloc( + sizeof(struct POSIX_SECURITY) + + alloccnt*sizeof(struct POSIX_ACE)); + k = 0; + l = alloccnt; + for (i=0; i<2; i++) { + pctx = &ctx[i]; + pctx->permswrld = 0; + pctx->prevuid = -1; + pctx->prevgid = -1; + pctx->groupmasks = 0; + pctx->tagsset = 0; + pctx->gotowner = FALSE; + pctx->gotgroup = FALSE; + pctx->gotownermask = FALSE; + } + for (j=0; jflags & INHERIT_ONLY_ACE) { + pxace = &pxdesc->acl.ace[l - 1]; + pctx = &ctx[1]; + } else { + pxace = &pxdesc->acl.ace[k]; + pctx = &ctx[0]; + } + ignore = FALSE; + /* + * grants for root as a designated user or group + */ + if ((~pace->mask & (ROOT_OWNER_UNMARK | ROOT_GROUP_UNMARK)) + && (pace->type == ACCESS_ALLOWED_ACE_TYPE) + && ntfs_same_sid(&pace->sid, adminsid)) { + pxace->tag = (pace->mask & ROOT_OWNER_UNMARK ? POSIX_ACL_GROUP : POSIX_ACL_USER); + pxace->id = 0; + if ((pace->mask & (GENERIC_ALL | WRITE_OWNER)) + && (pace->flags & INHERIT_ONLY_ACE)) + ignore = genericinh = TRUE; + } else + if (ntfs_same_sid(usid, &pace->sid)) { + pxace->id = -1; + /* + * Owner has no write-owner right : + * a group was defined same as owner + * or admin was owner or group : + * denials are meant to owner + * and grants are meant to group + */ + if (!(pace->mask & (WRITE_OWNER | GENERIC_ALL)) + && (pace->type == ACCESS_ALLOWED_ACE_TYPE)) { + if (ntfs_same_sid(gsid,usid)) { + pxace->tag = POSIX_ACL_GROUP_OBJ; + pxace->id = -1; + } else { + if (ntfs_same_sid(&pace->sid,usid)) + groupowns = TRUE; + gid = NTFS_FIND_GROUP(mapping[MAPGROUPS],&pace->sid); + if (gid) { + pxace->tag = POSIX_ACL_GROUP; + pxace->id = gid; + pctx->prevgid = gid; + } else { + uid = NTFS_FIND_USER(mapping[MAPUSERS],&pace->sid); + if (uid) { + pxace->tag = POSIX_ACL_USER; + pxace->id = uid; + } else + ignore = TRUE; + } + } + } else { + /* + * when group owns, late denials for owner + * mean group mask + */ + if ((pace->type == ACCESS_DENIED_ACE_TYPE) + && (pace->mask & WRITE_OWNER)) { + pxace->tag = POSIX_ACL_MASK; + pctx->gotownermask = TRUE; + if (pctx->gotowner) + pctx->groupmasks++; + } else { + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + pctx->gotowner = TRUE; + if (pctx->gotownermask && !pctx->gotowner) { + uid = NTFS_FIND_USER(mapping[MAPUSERS],&pace->sid); + pxace->id = uid; + pxace->tag = POSIX_ACL_USER; + } else + pxace->tag = POSIX_ACL_USER_OBJ; + /* system ignored, and admin */ + /* ignored at first position */ + if (pace->flags & INHERIT_ONLY_ACE) { + if ((firstinh && ntfs_same_sid(&pace->sid,adminsid)) + || ntfs_same_sid(&pace->sid,systemsid)) + ignore = TRUE; + if (!firstinh) { + firstinh = TRUE; + } + } else { + if ((adminowns && ntfs_same_sid(&pace->sid,adminsid)) + || ntfs_same_sid(&pace->sid,systemsid)) + ignore = TRUE; + if (ntfs_same_sid(usid,adminsid)) + adminowns = TRUE; + } + } + } + } else if (ntfs_same_sid(gsid, &pace->sid)) { + if ((pace->type == ACCESS_DENIED_ACE_TYPE) + && (pace->mask & WRITE_OWNER)) { + pxace->tag = POSIX_ACL_MASK; + pxace->id = -1; + if (pctx->gotowner) + pctx->groupmasks++; + } else { + if (pctx->gotgroup || (pctx->groupmasks > 1)) { + gid = NTFS_FIND_GROUP(mapping[MAPGROUPS],&pace->sid); + if (gid) { + pxace->id = gid; + pxace->tag = POSIX_ACL_GROUP; + pctx->prevgid = gid; + } else + ignore = TRUE; + } else { + pxace->id = -1; + pxace->tag = POSIX_ACL_GROUP_OBJ; + if (pace->type == ACCESS_ALLOWED_ACE_TYPE) + pctx->gotgroup = TRUE; + } + + if (ntfs_same_sid(gsid,adminsid) + || ntfs_same_sid(gsid,systemsid)) { + if (pace->mask & (WRITE_OWNER | GENERIC_ALL)) + ignore = TRUE; + if (ntfs_same_sid(gsid,adminsid)) + adminowns = TRUE; + else + genericinh = ignore; + } + } + } else if (is_world_sid((const SID*)&pace->sid)) { + pxace->id = -1; + pxace->tag = POSIX_ACL_OTHER; + if ((pace->type == ACCESS_DENIED_ACE_TYPE) + && (pace->flags & INHERIT_ONLY_ACE)) + ignore = TRUE; + } else if (ntfs_same_sid((const SID*)&pace->sid,nullsid)) { + pxace->id = -1; + pxace->tag = POSIX_ACL_SPECIAL; + } else { + uid = NTFS_FIND_USER(mapping[MAPUSERS],&pace->sid); + if (uid) { + if ((pace->type == ACCESS_DENIED_ACE_TYPE) + && (pace->mask & WRITE_OWNER) + && (pctx->prevuid != uid)) { + pxace->id = -1; + pxace->tag = POSIX_ACL_MASK; + } else { + pxace->id = uid; + pxace->tag = POSIX_ACL_USER; + } + pctx->prevuid = uid; + } else { + gid = NTFS_FIND_GROUP(mapping[MAPGROUPS],&pace->sid); + if (gid) { + if ((pace->type == ACCESS_DENIED_ACE_TYPE) + && (pace->mask & WRITE_OWNER) + && (pctx->prevgid != gid)) { + pxace->tag = POSIX_ACL_MASK; + pctx->groupmasks++; + } else { + pxace->tag = POSIX_ACL_GROUP; + } + pxace->id = gid; + pctx->prevgid = gid; + } else { + /* + * do not grant rights to unknown + * people and do not define root as a + * designated user or group + */ + ignore = TRUE; + } + } + } + if (!ignore) { + pxace->perms = 0; + /* specific decoding for vtx/uid/gid */ + if (pxace->tag == POSIX_ACL_SPECIAL) { + if (pace->mask & FILE_APPEND_DATA) + pxace->perms |= S_ISUID; + if (pace->mask & FILE_WRITE_DATA) + pxace->perms |= S_ISGID; + if (pace->mask & FILE_READ_DATA) + pxace->perms |= S_ISVTX; + } else + if (isdir) { + if (pace->mask & DIR_GEXEC) + pxace->perms |= POSIX_PERM_X; + if (pace->mask & DIR_GWRITE) + pxace->perms |= POSIX_PERM_W; + if (pace->mask & DIR_GREAD) + pxace->perms |= POSIX_PERM_R; + if ((pace->mask & GENERIC_ALL) + && (pace->flags & INHERIT_ONLY_ACE)) + pxace->perms |= POSIX_PERM_X + | POSIX_PERM_W + | POSIX_PERM_R; + } else { + if (pace->mask & FILE_GEXEC) + pxace->perms |= POSIX_PERM_X; + if (pace->mask & FILE_GWRITE) + pxace->perms |= POSIX_PERM_W; + if (pace->mask & FILE_GREAD) + pxace->perms |= POSIX_PERM_R; + } + + if (pace->type != ACCESS_ALLOWED_ACE_TYPE) + pxace->perms |= POSIX_PERM_DENIAL; + else + if (pxace->tag == POSIX_ACL_OTHER) + pctx->permswrld = pxace->perms; + pctx->tagsset |= pxace->tag; + if (pace->flags & INHERIT_ONLY_ACE) { + l--; + } else { + k++; + } + } + offace += le16_to_cpu(pace->size); + } + /* + * Create world perms if none (both lists) + */ + for (i=0; i<2; i++) + if ((genericinh || !i) + && !(ctx[i].tagsset & POSIX_ACL_OTHER)) { + if (i) + pxace = &pxdesc->acl.ace[--l]; + else + pxace = &pxdesc->acl.ace[k++]; + pxace->tag = POSIX_ACL_OTHER; + pxace->id = -1; + pxace->perms = 0; + ctx[i].tagsset |= POSIX_ACL_OTHER; + ctx[i].permswrld = 0; + } + /* + * Set basic owner perms if none (both lists) + * This happens for files created by Windows in directories + * created by Linux and owned by root, because Windows + * merges the admin ACEs + */ + for (i=0; i<2; i++) + if (!(ctx[i].tagsset & POSIX_ACL_USER_OBJ) + && (ctx[i].tagsset & POSIX_ACL_OTHER)) { + if (i) + pxace = &pxdesc->acl.ace[--l]; + else + pxace = &pxdesc->acl.ace[k++]; + pxace->tag = POSIX_ACL_USER_OBJ; + pxace->id = -1; + pxace->perms = POSIX_PERM_R | POSIX_PERM_W | POSIX_PERM_X; + ctx[i].tagsset |= POSIX_ACL_USER_OBJ; + } + /* + * Duplicate world perms as group_obj perms if none + */ + for (i=0; i<2; i++) + if ((ctx[i].tagsset & POSIX_ACL_OTHER) + && !(ctx[i].tagsset & POSIX_ACL_GROUP_OBJ)) { + if (i) + pxace = &pxdesc->acl.ace[--l]; + else + pxace = &pxdesc->acl.ace[k++]; + pxace->tag = POSIX_ACL_GROUP_OBJ; + pxace->id = -1; + pxace->perms = ctx[i].permswrld; + ctx[i].tagsset |= POSIX_ACL_GROUP_OBJ; + } + /* + * Also duplicate world perms as group perms if they + * were converted to mask and not followed by a group entry + */ + if (ctx[0].groupmasks) { + for (j=k-2; j>=0; j--) { + if ((pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) + && (pxdesc->acl.ace[j].id != -1) + && ((pxdesc->acl.ace[j+1].tag != POSIX_ACL_GROUP) + || (pxdesc->acl.ace[j+1].id + != pxdesc->acl.ace[j].id))) { + pxace = &pxdesc->acl.ace[k]; + pxace->tag = POSIX_ACL_GROUP; + pxace->id = pxdesc->acl.ace[j].id; + pxace->perms = ctx[0].permswrld; + ctx[0].tagsset |= POSIX_ACL_GROUP; + k++; + } + if (pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) + pxdesc->acl.ace[j].id = -1; + } + } + if (ctx[1].groupmasks) { + for (j=l; j<(alloccnt-1); j++) { + if ((pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) + && (pxdesc->acl.ace[j].id != -1) + && ((pxdesc->acl.ace[j+1].tag != POSIX_ACL_GROUP) + || (pxdesc->acl.ace[j+1].id + != pxdesc->acl.ace[j].id))) { + pxace = &pxdesc->acl.ace[l - 1]; + pxace->tag = POSIX_ACL_GROUP; + pxace->id = pxdesc->acl.ace[j].id; + pxace->perms = ctx[1].permswrld; + ctx[1].tagsset |= POSIX_ACL_GROUP; + l--; + } + if (pxdesc->acl.ace[j].tag == POSIX_ACL_MASK) + pxdesc->acl.ace[j].id = -1; + } + } + + /* + * Insert default mask if none present and + * there are designated users or groups + * (the space for it has not beed used) + */ + for (i=0; i<2; i++) + if ((ctx[i].tagsset & (POSIX_ACL_USER | POSIX_ACL_GROUP)) + && !(ctx[i].tagsset & POSIX_ACL_MASK)) { + if (i) + pxace = &pxdesc->acl.ace[--l]; + else + pxace = &pxdesc->acl.ace[k++]; + pxace->tag = POSIX_ACL_MASK; + pxace->id = -1; + pxace->perms = POSIX_PERM_DENIAL; + ctx[i].tagsset |= POSIX_ACL_MASK; + } + + if (k > l) { + ntfs_log_error("Posix descriptor is longer than expected\n"); + errno = EIO; + free(pxdesc); + pxdesc = (struct POSIX_SECURITY*)NULL; + } else { + pxdesc->acccnt = k; + pxdesc->defcnt = alloccnt - l; + pxdesc->firstdef = l; + pxdesc->tagsset = ctx[0].tagsset; + pxdesc->acl.version = POSIX_VERSION; + pxdesc->acl.flags = 0; + pxdesc->acl.filler = 0; + ntfs_sort_posix(pxdesc); + if (adminowns) { + k = norm_ownadmin_permissions_posix(pxdesc, + 0, pxdesc->acccnt, 0); + pxdesc->acccnt = k; + l = norm_ownadmin_permissions_posix(pxdesc, + pxdesc->firstdef, pxdesc->defcnt, k); + pxdesc->firstdef = k; + pxdesc->defcnt = l; + } else { + k = norm_std_permissions_posix(pxdesc,groupowns, + 0, pxdesc->acccnt, 0); + pxdesc->acccnt = k; + l = norm_std_permissions_posix(pxdesc,groupowns, + pxdesc->firstdef, pxdesc->defcnt, k); + pxdesc->firstdef = k; + pxdesc->defcnt = l; + } + } + if (pxdesc && !ntfs_valid_posix(pxdesc)) { + ntfs_log_error("Invalid Posix descriptor built\n"); + errno = EIO; + free(pxdesc); + pxdesc = (struct POSIX_SECURITY*)NULL; + } + return (pxdesc); +} + +#endif /* POSIXACLS */ + +/* + * Build unix-style (mode_t) permissions from an ACL + * returns the requested permissions + * or a negative result (with errno set) if there is a problem + */ + +int ntfs_build_permissions(const char *securattr, + const SID *usid, const SID *gsid, BOOL isdir) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + int perm; + BOOL adminowns; + BOOL groupowns; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + adminowns = ntfs_same_sid(usid,adminsid) + || ntfs_same_sid(gsid,adminsid); + groupowns = !adminowns && ntfs_same_sid(gsid,usid); + if (adminowns) + perm = build_ownadmin_permissions(securattr, usid, gsid, isdir); + else + if (groupowns) + perm = build_owngrp_permissions(securattr, usid, isdir); + else + perm = build_std_permissions(securattr, usid, gsid, isdir); + return (perm); +} + +/* + * The following must be in some library... + */ + +static unsigned long atoul(const char *p) +{ /* must be somewhere ! */ + unsigned long v; + + v = 0; + while ((*p >= '0') && (*p <= '9')) + v = v * 10 + (*p++) - '0'; + return (v); +} + +/* + * Build an internal representation of a SID + * Returns a copy in allocated memory if it succeeds + * The SID is checked to be a valid user one. + */ + +static SID *encodesid(const char *sidstr) +{ + SID *sid; + int cnt; + BIGSID bigsid; + SID *bsid; + u32 auth; + const char *p; + + sid = (SID*) NULL; + if (!strncmp(sidstr, "S-1-", 4)) { + bsid = (SID*)&bigsid; + bsid->revision = SID_REVISION; + p = &sidstr[4]; + auth = atoul(p); + bsid->identifier_authority.high_part = const_cpu_to_be16(0); + bsid->identifier_authority.low_part = cpu_to_be32(auth); + cnt = 0; + p = strchr(p, '-'); + while (p && (cnt < 8)) { + p++; + auth = atoul(p); + bsid->sub_authority[cnt] = cpu_to_le32(auth); + p = strchr(p, '-'); + cnt++; + } + bsid->sub_authority_count = cnt; + if ((cnt > 0) && ntfs_valid_sid(bsid) && ntfs_is_user_sid(bsid)) { + sid = (SID*) ntfs_malloc(4 * cnt + 8); + if (sid) + memcpy(sid, bsid, 4 * cnt + 8); + } + } + return (sid); +} + +/* + * Early logging before the logs are redirected + * + * (not quite satisfactory : this appears before the ntfs-g banner, + * and with a different pid) + */ + +static void log_early_error(const char *format, ...) + __attribute__((format(printf, 1, 2))); + +static void log_early_error(const char *format, ...) +{ + va_list args; + + va_start(args, format); +#ifdef HAVE_SYSLOG_H + openlog("ntfs-3g", LOG_PID, LOG_USER); + ntfs_log_handler_syslog(NULL, NULL, 0, + NTFS_LOG_LEVEL_ERROR, NULL, + format, args); +#else + vfprintf(stderr,format,args); +#endif + va_end(args); +} + + +/* + * Get a single mapping item from buffer + * + * Always reads a full line, truncating long lines + * Refills buffer when exhausted + * Returns pointer to item, or NULL when there is no more + */ + +static struct MAPLIST *getmappingitem(FILEREADER reader, void *fileid, + off_t *poffs, char *buf, int *psrc, s64 *psize) +{ + int src; + int dst; + char *p; + char *q; + char *pu; + char *pg; + int gotend; + struct MAPLIST *item; + + src = *psrc; + dst = 0; + /* allocate and get a full line */ + item = (struct MAPLIST*)ntfs_malloc(sizeof(struct MAPLIST)); + if (item) { + do { + gotend = 0; + while ((src < *psize) + && (buf[src] != '\n')) { + if (dst < LINESZ) + item->maptext[dst++] = buf[src]; + src++; + } + if (src >= *psize) { + *poffs += *psize; + *psize = reader(fileid, buf, (size_t)BUFSZ, *poffs); + src = 0; + } else { + gotend = 1; + src++; + item->maptext[dst] = '\0'; + dst = 0; + } + } while (*psize && ((item->maptext[0] == '#') || !gotend)); + if (gotend) { + pu = pg = (char*)NULL; + /* decompose into uid, gid and sid */ + p = item->maptext; + item->uidstr = item->maptext; + item->gidstr = strchr(item->uidstr, ':'); + if (item->gidstr) { + pu = item->gidstr++; + item->sidstr = strchr(item->gidstr, ':'); + if (item->sidstr) { + pg = item->sidstr++; + q = strchr(item->sidstr, ':'); + if (q) *q = 0; + } + } + if (pu && pg) + *pu = *pg = '\0'; + else { + log_early_error("Bad mapping item \"%s\"\n", + item->maptext); + free(item); + item = (struct MAPLIST*)NULL; + } + } else { + free(item); /* free unused item */ + item = (struct MAPLIST*)NULL; + } + } + *psrc = src; + return (item); +} + +/* + * Read user mapping file and split into their attribute. + * Parameters are kept as text in a chained list until logins + * are converted to uid. + * Returns the head of list, if any + * + * If an absolute path is provided, the mapping file is assumed + * to be located in another mounted file system, and plain read() + * are used to get its contents. + * If a relative path is provided, the mapping file is assumed + * to be located on the current file system, and internal IO + * have to be used since we are still mounting and we have not + * entered the fuse loop yet. + */ + +struct MAPLIST *ntfs_read_mapping(FILEREADER reader, void *fileid) +{ + char buf[BUFSZ]; + struct MAPLIST *item; + struct MAPLIST *firstitem; + struct MAPLIST *lastitem; + int src; + off_t offs; + s64 size; + + firstitem = (struct MAPLIST*)NULL; + lastitem = (struct MAPLIST*)NULL; + offs = 0; + size = reader(fileid, buf, (size_t)BUFSZ, (off_t)0); + if (size > 0) { + src = 0; + do { + item = getmappingitem(reader, fileid, &offs, + buf, &src, &size); + if (item) { + item->next = (struct MAPLIST*)NULL; + if (lastitem) + lastitem->next = item; + else + firstitem = item; + lastitem = item; + } + } while (item); + } + return (firstitem); +} + +/* + * Free memory used to store the user mapping + * The only purpose is to facilitate the detection of memory leaks + */ + +void ntfs_free_mapping(struct MAPPING *mapping[]) +{ + struct MAPPING *user; + struct MAPPING *group; + + /* free user mappings */ + while (mapping[MAPUSERS]) { + user = mapping[MAPUSERS]; + /* do not free SIDs used for group mappings */ + group = mapping[MAPGROUPS]; + while (group && (group->sid != user->sid)) + group = group->next; + if (!group) + free(user->sid); + /* free group list if any */ + if (user->grcnt) + free(user->groups); + /* unchain item and free */ + mapping[MAPUSERS] = user->next; + free(user); + } + /* free group mappings */ + while (mapping[MAPGROUPS]) { + group = mapping[MAPGROUPS]; + free(group->sid); + /* unchain item and free */ + mapping[MAPGROUPS] = group->next; + free(group); + } +} + + +/* + * Build the user mapping list + * user identification may be given in symbolic or numeric format + * + * ! Note ! : does getpwnam() read /etc/passwd or some other file ? + * if so there is a possible recursion into fuse if this + * file is on NTFS, and fuse is not recursion safe. + */ + +struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem) +{ + struct MAPLIST *item; + struct MAPPING *firstmapping; + struct MAPPING *lastmapping; + struct MAPPING *mapping; + struct passwd *pwd; + SID *sid; + int uid; + + firstmapping = (struct MAPPING*)NULL; + lastmapping = (struct MAPPING*)NULL; + for (item = firstitem; item; item = item->next) { + if ((item->uidstr[0] >= '0') && (item->uidstr[0] <= '9')) + uid = atoi(item->uidstr); + else { + uid = 0; + if (item->uidstr[0]) { + pwd = getpwnam(item->uidstr); + if (pwd) + uid = pwd->pw_uid; + else + log_early_error("Invalid user \"%s\"\n", + item->uidstr); + } + } + /* + * Records with no uid and no gid are inserted + * to define the implicit mapping pattern + */ + if (uid + || (!item->uidstr[0] && !item->gidstr[0])) { + sid = encodesid(item->sidstr); + if (sid && !item->uidstr[0] && !item->gidstr[0] + && !ntfs_valid_pattern(sid)) { + ntfs_log_error("Bad implicit SID pattern %s\n", + item->sidstr); + sid = (SID*)NULL; + } + if (sid) { + mapping = + (struct MAPPING*) + ntfs_malloc(sizeof(struct MAPPING)); + if (mapping) { + mapping->sid = sid; + mapping->xid = uid; + mapping->grcnt = 0; + mapping->next = (struct MAPPING*)NULL; + if (lastmapping) + lastmapping->next = mapping; + else + firstmapping = mapping; + lastmapping = mapping; + } + } + } + } + return (firstmapping); +} + +/* + * Build the group mapping list + * group identification may be given in symbolic or numeric format + * + * gid not associated to a uid are processed first in order + * to favour real groups + * + * ! Note ! : does getgrnam() read /etc/group or some other file ? + * if so there is a possible recursion into fuse if this + * file is on NTFS, and fuse is not recursion safe. + */ + +struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem) +{ + struct MAPLIST *item; + struct MAPPING *firstmapping; + struct MAPPING *lastmapping; + struct MAPPING *mapping; + struct group *grp; + BOOL secondstep; + BOOL ok; + int step; + SID *sid; + int gid; + + firstmapping = (struct MAPPING*)NULL; + lastmapping = (struct MAPPING*)NULL; + for (step=1; step<=2; step++) { + for (item = firstitem; item; item = item->next) { + secondstep = (item->uidstr[0] != '\0') + || !item->gidstr[0]; + ok = (step == 1 ? !secondstep : secondstep); + if ((item->gidstr[0] >= '0') + && (item->gidstr[0] <= '9')) + gid = atoi(item->gidstr); + else { + gid = 0; + if (item->gidstr[0]) { + grp = getgrnam(item->gidstr); + if (grp) + gid = grp->gr_gid; + else + log_early_error("Invalid group \"%s\"\n", + item->gidstr); + } + } + /* + * Records with no uid and no gid are inserted in the + * second step to define the implicit mapping pattern + */ + if (ok + && (gid + || (!item->uidstr[0] && !item->gidstr[0]))) { + sid = encodesid(item->sidstr); + if (sid && !item->uidstr[0] && !item->gidstr[0] + && !ntfs_valid_pattern(sid)) { + /* error already logged */ + sid = (SID*)NULL; + } + if (sid) { + mapping = (struct MAPPING*) + ntfs_malloc(sizeof(struct MAPPING)); + if (mapping) { + mapping->sid = sid; + mapping->xid = gid; + mapping->grcnt = 0; + mapping->next = (struct MAPPING*)NULL; + if (lastmapping) + lastmapping->next = mapping; + else + firstmapping = mapping; + lastmapping = mapping; + } + } + } + } + } + return (firstmapping); +} diff --git a/libcustomntfs/acls.h b/libcustomntfs/acls.h new file mode 100644 index 00000000..8a83d32d --- /dev/null +++ b/libcustomntfs/acls.h @@ -0,0 +1,199 @@ +/* + * + * Copyright (c) 2007-2008 Jean-Pierre Andre + * + */ + +/* + * This program 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef ACLS_H +#define ACLS_H + +/* + * JPA configuration modes for security.c / acls.c + * should be moved to some config file + */ + +#define BUFSZ 1024 /* buffer size to read mapping file */ +#define MAPPINGFILE ".NTFS-3G/UserMapping" /* default mapping file */ +#define LINESZ 120 /* maximum useful size of a mapping line */ +#define CACHE_PERMISSIONS_BITS 6 /* log2 of unitary allocation of permissions */ +#define CACHE_PERMISSIONS_SIZE 262144 /* max cacheable permissions */ + +/* + * JPA The following must be in some library... + * but did not found out where + */ + +#define endian_rev16(x) (((x >> 8) & 255) | ((x & 255) << 8)) +#define endian_rev32(x) (((x >> 24) & 255) | ((x >> 8) & 0xff00) \ + | ((x & 0xff00) << 8) | ((x & 255) << 24)) + +#define cpu_to_be16(x) endian_rev16(cpu_to_le16(x)) +#define cpu_to_be32(x) endian_rev32(cpu_to_le32(x)) + +/* + * Macro definitions needed to share code with secaudit + */ + +#define NTFS_FIND_USID(map,uid,buf) ntfs_find_usid(map,uid,buf) +#define NTFS_FIND_GSID(map,gid,buf) ntfs_find_gsid(map,gid,buf) +#define NTFS_FIND_USER(map,usid) ntfs_find_user(map,usid) +#define NTFS_FIND_GROUP(map,gsid) ntfs_find_group(map,gsid) + + +/* + * Matching of ntfs permissions to Linux permissions + * these constants are adapted to endianness + * when setting, set them all + * when checking, check one is present + */ + + /* flags which are set to mean exec, write or read */ + +#define FILE_READ (FILE_READ_DATA) +#define FILE_WRITE (FILE_WRITE_DATA | FILE_APPEND_DATA \ + | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA) +#define FILE_EXEC (FILE_EXECUTE) +#define DIR_READ FILE_LIST_DIRECTORY +#define DIR_WRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD \ + | READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA) +#define DIR_EXEC (FILE_TRAVERSE) + + /* flags tested for meaning exec, write or read */ + /* tests for write allow for interpretation of a sticky bit */ + +#define FILE_GREAD (FILE_READ_DATA | GENERIC_READ) +#define FILE_GWRITE (FILE_WRITE_DATA | FILE_APPEND_DATA | GENERIC_WRITE) +#define FILE_GEXEC (FILE_EXECUTE | GENERIC_EXECUTE) +#define DIR_GREAD (FILE_LIST_DIRECTORY | GENERIC_READ) +#define DIR_GWRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | GENERIC_WRITE) +#define DIR_GEXEC (FILE_TRAVERSE | GENERIC_EXECUTE) + + /* standard owner (and administrator) rights */ + +#define OWNER_RIGHTS (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER \ + | SYNCHRONIZE \ + | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES \ + | FILE_READ_EA | FILE_WRITE_EA) + + /* standard world rights */ + +#define WORLD_RIGHTS (READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA \ + | SYNCHRONIZE) + + /* inheritance flags for files and directories */ + +#define FILE_INHERITANCE NO_PROPAGATE_INHERIT_ACE +#define DIR_INHERITANCE (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE) + +/* + * To identify NTFS ACL meaning Posix ACL granted to root + * we use rights always granted to anybody, so they have no impact + * either on Windows or on Linux. + */ + +#define ROOT_OWNER_UNMARK SYNCHRONIZE /* ACL granted to root as owner */ +#define ROOT_GROUP_UNMARK FILE_READ_EA /* ACL granted to root as group */ + +/* + * A type large enough to hold any SID + */ + +typedef char BIGSID[40]; + +/* + * Struct to hold the input mapping file + * (private to this module) + */ + +struct MAPLIST { + struct MAPLIST *next; + char *uidstr; /* uid text from the same record */ + char *gidstr; /* gid text from the same record */ + char *sidstr; /* sid text from the same record */ + char maptext[LINESZ + 1]; +}; + +typedef int (*FILEREADER)(void *fileid, char *buf, size_t size, off_t pos); + +/* + * Constants defined in acls.c + */ + +extern const SID *adminsid; +extern const SID *worldsid; + +/* + * Functions defined in acls.c + */ + +BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz); +BOOL ntfs_valid_pattern(const SID *sid); +BOOL ntfs_valid_sid(const SID *sid); +BOOL ntfs_same_sid(const SID *first, const SID *second); + +BOOL ntfs_is_user_sid(const SID *usid); + + +int ntfs_sid_size(const SID * sid); +unsigned int ntfs_attr_size(const char *attr); + +const SID *ntfs_find_usid(const struct MAPPING *usermapping, + uid_t uid, SID *pdefsid); +const SID *ntfs_find_gsid(const struct MAPPING *groupmapping, + gid_t gid, SID *pdefsid); +uid_t ntfs_find_user(const struct MAPPING *usermapping, const SID *usid); +gid_t ntfs_find_group(const struct MAPPING *groupmapping, const SID * gsid); +const SID *ntfs_acl_owner(const char *secattr); + +#if POSIXACLS + +BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc); +void ntfs_sort_posix(struct POSIX_SECURITY *pxdesc); +int ntfs_merge_mode_posix(struct POSIX_SECURITY *pxdesc, mode_t mode); +struct POSIX_SECURITY *ntfs_build_inherited_posix( + const struct POSIX_SECURITY *pxdesc, mode_t mode, + mode_t umask, BOOL isdir); +struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc, + const struct POSIX_ACL *newacl, int count, BOOL deflt); +struct POSIX_SECURITY *ntfs_build_permissions_posix( + struct MAPPING* const mapping[], + const char *securattr, + const SID *usid, const SID *gsid, BOOL isdir); +struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first, + const struct POSIX_SECURITY *second); +char *ntfs_build_descr_posix(struct MAPPING* const mapping[], + struct POSIX_SECURITY *pxdesc, + int isdir, const SID *usid, const SID *gsid); + +#endif /* POSIXACLS */ + +int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, + const SID *usid, const SID *gsid, BOOL fordir); +int ntfs_build_permissions(const char *securattr, + const SID *usid, const SID *gsid, BOOL isdir); +char *ntfs_build_descr(mode_t mode, + int isdir, const SID * usid, const SID * gsid); +struct MAPLIST *ntfs_read_mapping(FILEREADER reader, void *fileid); +struct MAPPING *ntfs_do_user_mapping(struct MAPLIST *firstitem); +struct MAPPING *ntfs_do_group_mapping(struct MAPLIST *firstitem); +void ntfs_free_mapping(struct MAPPING *mapping[]); + +#endif /* ACLS_H */ + diff --git a/libcustomntfs/attrib.c b/libcustomntfs/attrib.c new file mode 100644 index 00000000..123c9a91 --- /dev/null +++ b/libcustomntfs/attrib.c @@ -0,0 +1,6401 @@ +/** + * attrib.c - Attribute handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2010 Anton Altaparmakov + * Copyright (c) 2002-2005 Richard Russon + * Copyright (c) 2002-2008 Szabolcs Szakacsits + * Copyright (c) 2004-2007 Yura Pakhuchiy + * Copyright (c) 2007-2010 Jean-Pierre Andre + * Copyright (c) 2010 Erik Larsson + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif + +#include "param.h" +#include "compat.h" +#include "attrib.h" +#include "attrlist.h" +#include "device.h" +#include "mft.h" +#include "debug.h" +#include "mst.h" +#include "volume.h" +#include "types.h" +#include "layout.h" +#include "inode.h" +#include "runlist.h" +#include "lcnalloc.h" +#include "dir.h" +#include "compress.h" +#include "bitmap.h" +#include "logging.h" +#include "misc.h" +#include "efs.h" + +ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') }; +ntfschar STREAM_SDS[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('S'), + const_cpu_to_le16('D'), + const_cpu_to_le16('S'), + const_cpu_to_le16('\0') }; + +ntfschar TXF_DATA[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('T'), + const_cpu_to_le16('X'), + const_cpu_to_le16('F'), + const_cpu_to_le16('_'), + const_cpu_to_le16('D'), + const_cpu_to_le16('A'), + const_cpu_to_le16('T'), + const_cpu_to_le16('A'), + const_cpu_to_le16('\0') }; + +static int NAttrFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) +{ + if (na->type == AT_DATA && na->name == AT_UNNAMED) + return (na->ni->flags & flag); + return 0; +} + +static void NAttrSetFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) +{ + if (na->type == AT_DATA && na->name == AT_UNNAMED) + na->ni->flags |= flag; + else + ntfs_log_trace("Denied setting flag %d for not unnamed data " + "attribute\n", flag); +} + +static void NAttrClearFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) +{ + if (na->type == AT_DATA && na->name == AT_UNNAMED) + na->ni->flags &= ~flag; +} + +#define GenNAttrIno(func_name, flag) \ +int NAttr##func_name(ntfs_attr *na) { return NAttrFlag (na, flag); } \ +void NAttrSet##func_name(ntfs_attr *na) { NAttrSetFlag (na, flag); } \ +void NAttrClear##func_name(ntfs_attr *na){ NAttrClearFlag(na, flag); } + +GenNAttrIno(Compressed, FILE_ATTR_COMPRESSED) +GenNAttrIno(Encrypted, FILE_ATTR_ENCRYPTED) +GenNAttrIno(Sparse, FILE_ATTR_SPARSE_FILE) + +/** + * ntfs_get_attribute_value_length - Find the length of an attribute + * @a: + * + * Description... + * + * Returns: + */ +s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a) +{ + if (!a) { + errno = EINVAL; + return 0; + } + errno = 0; + if (a->non_resident) + return sle64_to_cpu(a->data_size); + + return (s64)le32_to_cpu(a->value_length); +} + +/** + * ntfs_get_attribute_value - Get a copy of an attribute + * @vol: + * @a: + * @b: + * + * Description... + * + * Returns: + */ +s64 ntfs_get_attribute_value(const ntfs_volume *vol, + const ATTR_RECORD *a, u8 *b) +{ + runlist *rl; + s64 total, r; + int i; + + /* Sanity checks. */ + if (!vol || !a || !b) { + errno = EINVAL; + return 0; + } + /* Complex attribute? */ + /* + * Ignore the flags in case they are not zero for an attribute list + * attribute. Windows does not complain about invalid flags and chkdsk + * does not detect or fix them so we need to cope with it, too. + */ + if (a->type != AT_ATTRIBUTE_LIST && a->flags) { + ntfs_log_error("Non-zero (%04x) attribute flags. Cannot handle " + "this yet.\n", le16_to_cpu(a->flags)); + errno = EOPNOTSUPP; + return 0; + } + if (!a->non_resident) { + /* Attribute is resident. */ + + /* Sanity check. */ + if (le32_to_cpu(a->value_length) + le16_to_cpu(a->value_offset) + > le32_to_cpu(a->length)) { + return 0; + } + + memcpy(b, (const char*)a + le16_to_cpu(a->value_offset), + le32_to_cpu(a->value_length)); + errno = 0; + return (s64)le32_to_cpu(a->value_length); + } + + /* Attribute is not resident. */ + + /* If no data, return 0. */ + if (!(a->data_size)) { + errno = 0; + return 0; + } + /* + * FIXME: What about attribute lists?!? (AIA) + */ + /* Decompress the mapping pairs array into a runlist. */ + rl = ntfs_mapping_pairs_decompress(vol, a, NULL); + if (!rl) { + errno = EINVAL; + return 0; + } + /* + * FIXED: We were overflowing here in a nasty fashion when we + * reach the last cluster in the runlist as the buffer will + * only be big enough to hold data_size bytes while we are + * reading in allocated_size bytes which is usually larger + * than data_size, since the actual data is unlikely to have a + * size equal to a multiple of the cluster size! + * FIXED2: We were also overflowing here in the same fashion + * when the data_size was more than one run smaller than the + * allocated size which happens with Windows XP sometimes. + */ + /* Now load all clusters in the runlist into b. */ + for (i = 0, total = 0; rl[i].length; i++) { + if (total + (rl[i].length << vol->cluster_size_bits) >= + sle64_to_cpu(a->data_size)) { + unsigned char *intbuf = NULL; + /* + * We have reached the last run so we were going to + * overflow when executing the ntfs_pread() which is + * BAAAAAAAD! + * Temporary fix: + * Allocate a new buffer with size: + * rl[i].length << vol->cluster_size_bits, do the + * read into our buffer, then memcpy the correct + * amount of data into the caller supplied buffer, + * free our buffer, and continue. + * We have reached the end of data size so we were + * going to overflow in the same fashion. + * Temporary fix: same as above. + */ + intbuf = ntfs_malloc(rl[i].length << vol->cluster_size_bits); + if (!intbuf) { + free(rl); + return 0; + } + /* + * FIXME: If compressed file: Only read if lcn != -1. + * Otherwise, we are dealing with a sparse run and we + * just memset the user buffer to 0 for the length of + * the run, which should be 16 (= compression unit + * size). + * FIXME: Really only when file is compressed, or can + * we have sparse runs in uncompressed files as well? + * - Yes we can, in sparse files! But not necessarily + * size of 16, just run length. + */ + r = ntfs_pread(vol->dev, rl[i].lcn << + vol->cluster_size_bits, rl[i].length << + vol->cluster_size_bits, intbuf); + if (r != rl[i].length << vol->cluster_size_bits) { +#define ESTR "Error reading attribute value" + if (r == -1) + ntfs_log_perror(ESTR); + else if (r < rl[i].length << + vol->cluster_size_bits) { + ntfs_log_debug(ESTR ": Ran out of input data.\n"); + errno = EIO; + } else { + ntfs_log_debug(ESTR ": unknown error\n"); + errno = EIO; + } +#undef ESTR + free(rl); + free(intbuf); + return 0; + } + memcpy(b + total, intbuf, sle64_to_cpu(a->data_size) - + total); + free(intbuf); + total = sle64_to_cpu(a->data_size); + break; + } + /* + * FIXME: If compressed file: Only read if lcn != -1. + * Otherwise, we are dealing with a sparse run and we just + * memset the user buffer to 0 for the length of the run, which + * should be 16 (= compression unit size). + * FIXME: Really only when file is compressed, or can + * we have sparse runs in uncompressed files as well? + * - Yes we can, in sparse files! But not necessarily size of + * 16, just run length. + */ + r = ntfs_pread(vol->dev, rl[i].lcn << vol->cluster_size_bits, + rl[i].length << vol->cluster_size_bits, + b + total); + if (r != rl[i].length << vol->cluster_size_bits) { +#define ESTR "Error reading attribute value" + if (r == -1) + ntfs_log_perror(ESTR); + else if (r < rl[i].length << vol->cluster_size_bits) { + ntfs_log_debug(ESTR ": Ran out of input data.\n"); + errno = EIO; + } else { + ntfs_log_debug(ESTR ": unknown error\n"); + errno = EIO; + } +#undef ESTR + free(rl); + return 0; + } + total += r; + } + free(rl); + return total; +} + +/* Already cleaned up code below, but still look for FIXME:... */ + +/** + * __ntfs_attr_init - primary initialization of an ntfs attribute structure + * @na: ntfs attribute to initialize + * @ni: ntfs inode with which to initialize the ntfs attribute + * @type: attribute type + * @name: attribute name in little endian Unicode or NULL + * @name_len: length of attribute @name in Unicode characters (if @name given) + * + * Initialize the ntfs attribute @na with @ni, @type, @name, and @name_len. + */ +static void __ntfs_attr_init(ntfs_attr *na, ntfs_inode *ni, + const ATTR_TYPES type, ntfschar *name, const u32 name_len) +{ + na->rl = NULL; + na->ni = ni; + na->type = type; + na->name = name; + if (name) + na->name_len = name_len; + else + na->name_len = 0; +} + +/** + * ntfs_attr_init - initialize an ntfs_attr with data sizes and status + * @na: + * @non_resident: + * @compressed: + * @encrypted: + * @sparse: + * @allocated_size: + * @data_size: + * @initialized_size: + * @compressed_size: + * @compression_unit: + * + * Final initialization for an ntfs attribute. + */ +void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, + const ATTR_FLAGS data_flags, + const BOOL encrypted, const BOOL sparse, + const s64 allocated_size, const s64 data_size, + const s64 initialized_size, const s64 compressed_size, + const u8 compression_unit) +{ + if (!NAttrInitialized(na)) { + na->data_flags = data_flags; + if (non_resident) + NAttrSetNonResident(na); + if (data_flags & ATTR_COMPRESSION_MASK) + NAttrSetCompressed(na); + if (encrypted) + NAttrSetEncrypted(na); + if (sparse) + NAttrSetSparse(na); + na->allocated_size = allocated_size; + na->data_size = data_size; + na->initialized_size = initialized_size; + if ((data_flags & ATTR_COMPRESSION_MASK) || sparse) { + ntfs_volume *vol = na->ni->vol; + + na->compressed_size = compressed_size; + na->compression_block_clusters = 1 << compression_unit; + na->compression_block_size = 1 << (compression_unit + + vol->cluster_size_bits); + na->compression_block_size_bits = ffs( + na->compression_block_size) - 1; + } + NAttrSetInitialized(na); + } +} + +/** + * ntfs_attr_open - open an ntfs attribute for access + * @ni: open ntfs inode in which the ntfs attribute resides + * @type: attribute type + * @name: attribute name in little endian Unicode or AT_UNNAMED or NULL + * @name_len: length of attribute @name in Unicode characters (if @name given) + * + * Allocate a new ntfs attribute structure, initialize it with @ni, @type, + * @name, and @name_len, then return it. Return NULL on error with + * errno set to the error code. + * + * If @name is AT_UNNAMED look specifically for an unnamed attribute. If you + * do not care whether the attribute is named or not set @name to NULL. In + * both those cases @name_len is not used at all. + */ +ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len) +{ + ntfs_attr_search_ctx *ctx; + ntfs_attr *na = NULL; + ntfschar *newname = NULL; + ATTR_RECORD *a; + BOOL cs; + + ntfs_log_enter("Entering for inode %lld, attr 0x%x.\n", + (unsigned long long)ni->mft_no, type); + + if (!ni || !ni->vol || !ni->mrec) { + errno = EINVAL; + goto out; + } + na = ntfs_calloc(sizeof(ntfs_attr)); + if (!na) + goto out; + if (name && name != AT_UNNAMED && name != NTFS_INDEX_I30) { + name = ntfs_ucsndup(name, name_len); + if (!name) + goto err_out; + newname = name; + } + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + goto err_out; + + if (ntfs_attr_lookup(type, name, name_len, 0, 0, NULL, 0, ctx)) + goto put_err_out; + + a = ctx->attr; + + if (!name) { + if (a->name_length) { + name = ntfs_ucsndup((ntfschar*)((u8*)a + le16_to_cpu( + a->name_offset)), a->name_length); + if (!name) + goto put_err_out; + newname = name; + name_len = a->name_length; + } else { + name = AT_UNNAMED; + name_len = 0; + } + } + + __ntfs_attr_init(na, ni, type, name, name_len); + + /* + * Wipe the flags in case they are not zero for an attribute list + * attribute. Windows does not complain about invalid flags and chkdsk + * does not detect or fix them so we need to cope with it, too. + */ + if (type == AT_ATTRIBUTE_LIST) + a->flags = 0; + + if ((type == AT_DATA) && !a->initialized_size) { + /* + * Define/redefine the compression state if stream is + * empty, based on the compression mark on parent + * directory (for unnamed data streams) or on current + * inode (for named data streams). The compression mark + * may change any time, the compression state can only + * change when stream is wiped out. + * + * Also prevent compression on NTFS version < 3.0 + * or cluster size > 4K or compression is disabled + */ + a->flags &= ~ATTR_COMPRESSION_MASK; + if ((ni->flags & FILE_ATTR_COMPRESSED) + && (ni->vol->major_ver >= 3) + && NVolCompression(ni->vol) + && (ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE)) + a->flags |= ATTR_IS_COMPRESSED; + } + + cs = a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE); + + if (na->type == AT_DATA && na->name == AT_UNNAMED && + ((!(a->flags & ATTR_IS_SPARSE) != !NAttrSparse(na)) || + (!(a->flags & ATTR_IS_ENCRYPTED) != !NAttrEncrypted(na)))) { + errno = EIO; + ntfs_log_perror("Inode %lld has corrupt attribute flags " + "(0x%x <> 0x%x)",(unsigned long long)ni->mft_no, + a->flags, na->ni->flags); + goto put_err_out; + } + + if (a->non_resident) { + if ((a->flags & ATTR_COMPRESSION_MASK) + && !a->compression_unit) { + errno = EIO; + ntfs_log_perror("Compressed inode %lld attr 0x%x has " + "no compression unit", + (unsigned long long)ni->mft_no, type); + goto put_err_out; + } + ntfs_attr_init(na, TRUE, a->flags, + a->flags & ATTR_IS_ENCRYPTED, + a->flags & ATTR_IS_SPARSE, + sle64_to_cpu(a->allocated_size), + sle64_to_cpu(a->data_size), + sle64_to_cpu(a->initialized_size), + cs ? sle64_to_cpu(a->compressed_size) : 0, + cs ? a->compression_unit : 0); + } else { + s64 l = le32_to_cpu(a->value_length); + ntfs_attr_init(na, FALSE, a->flags, + a->flags & ATTR_IS_ENCRYPTED, + a->flags & ATTR_IS_SPARSE, (l + 7) & ~7, l, l, + cs ? (l + 7) & ~7 : 0, 0); + } + ntfs_attr_put_search_ctx(ctx); +out: + ntfs_log_leave("\n"); + return na; + +put_err_out: + ntfs_attr_put_search_ctx(ctx); +err_out: + free(newname); + free(na); + na = NULL; + goto out; +} + +/** + * ntfs_attr_close - free an ntfs attribute structure + * @na: ntfs attribute structure to free + * + * Release all memory associated with the ntfs attribute @na and then release + * @na itself. + */ +void ntfs_attr_close(ntfs_attr *na) +{ + if (!na) + return; + if (NAttrNonResident(na) && na->rl) + free(na->rl); + /* Don't release if using an internal constant. */ + if (na->name != AT_UNNAMED && na->name != NTFS_INDEX_I30 + && na->name != STREAM_SDS) + free(na->name); + free(na); +} + +/** + * ntfs_attr_map_runlist - map (a part of) a runlist of an ntfs attribute + * @na: ntfs attribute for which to map (part of) a runlist + * @vcn: map runlist part containing this vcn + * + * Map the part of a runlist containing the @vcn of the ntfs attribute @na. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn) +{ + LCN lcn; + ntfs_attr_search_ctx *ctx; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, (long long)vcn); + + lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); + if (lcn >= 0 || lcn == LCN_HOLE || lcn == LCN_ENOENT) + return 0; + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + + /* Find the attribute in the mft record. */ + if (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + vcn, NULL, 0, ctx)) { + runlist_element *rl; + + /* Decode the runlist. */ + rl = ntfs_mapping_pairs_decompress(na->ni->vol, ctx->attr, + na->rl); + if (rl) { + na->rl = rl; + ntfs_attr_put_search_ctx(ctx); + return 0; + } + } + + ntfs_attr_put_search_ctx(ctx); + return -1; +} + +/** + * ntfs_attr_map_whole_runlist - map the whole runlist of an ntfs attribute + * @na: ntfs attribute for which to map the runlist + * + * Map the whole runlist of the ntfs attribute @na. For an attribute made up + * of only one attribute extent this is the same as calling + * ntfs_attr_map_runlist(na, 0) but for an attribute with multiple extents this + * will map the runlist fragments from each of the extents thus giving access + * to the entirety of the disk allocation of an attribute. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_map_whole_runlist(ntfs_attr *na) +{ + VCN next_vcn, last_vcn, highest_vcn; + ntfs_attr_search_ctx *ctx; + ntfs_volume *vol = na->ni->vol; + ATTR_RECORD *a; + int ret = -1; + + ntfs_log_enter("Entering for inode %llu, attr 0x%x.\n", + (unsigned long long)na->ni->mft_no, na->type); + + /* avoid multiple full runlist mappings */ + if (NAttrFullyMapped(na)) { + ret = 0; + goto out; + } + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + goto out; + + /* Map all attribute extents one by one. */ + next_vcn = last_vcn = highest_vcn = 0; + a = NULL; + while (1) { + runlist_element *rl; + + int not_mapped = 0; + if (ntfs_rl_vcn_to_lcn(na->rl, next_vcn) == LCN_RL_NOT_MAPPED) + not_mapped = 1; + + if (ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, next_vcn, NULL, 0, ctx)) + break; + + a = ctx->attr; + + if (not_mapped) { + /* Decode the runlist. */ + rl = ntfs_mapping_pairs_decompress(na->ni->vol, + a, na->rl); + if (!rl) + goto err_out; + na->rl = rl; + } + + /* Are we in the first extent? */ + if (!next_vcn) { + if (a->lowest_vcn) { + errno = EIO; + ntfs_log_perror("First extent of inode %llu " + "attribute has non-zero lowest_vcn", + (unsigned long long)na->ni->mft_no); + goto err_out; + } + /* Get the last vcn in the attribute. */ + last_vcn = sle64_to_cpu(a->allocated_size) >> + vol->cluster_size_bits; + } + + /* Get the lowest vcn for the next extent. */ + highest_vcn = sle64_to_cpu(a->highest_vcn); + next_vcn = highest_vcn + 1; + + /* Only one extent or error, which we catch below. */ + if (next_vcn <= 0) { + errno = ENOENT; + break; + } + + /* Avoid endless loops due to corruption. */ + if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { + errno = EIO; + ntfs_log_perror("Inode %llu has corrupt attribute list", + (unsigned long long)na->ni->mft_no); + goto err_out; + } + } + if (!a) { + ntfs_log_perror("Couldn't find attribute for runlist mapping"); + goto err_out; + } + if (highest_vcn && highest_vcn != last_vcn - 1) { + errno = EIO; + ntfs_log_perror("Failed to load full runlist: inode: %llu " + "highest_vcn: 0x%llx last_vcn: 0x%llx", + (unsigned long long)na->ni->mft_no, + (long long)highest_vcn, (long long)last_vcn); + goto err_out; + } + if (errno == ENOENT) { + NAttrSetFullyMapped(na); + ret = 0; + } +err_out: + ntfs_attr_put_search_ctx(ctx); +out: + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_vcn_to_lcn - convert a vcn into a lcn given an ntfs attribute + * @na: ntfs attribute whose runlist to use for conversion + * @vcn: vcn to convert + * + * Convert the virtual cluster number @vcn of an attribute into a logical + * cluster number (lcn) of a device using the runlist @na->rl to map vcns to + * their corresponding lcns. + * + * If the @vcn is not mapped yet, attempt to map the attribute extent + * containing the @vcn and retry the vcn to lcn conversion. + * + * Since lcns must be >= 0, we use negative return values with special meaning: + * + * Return value Meaning / Description + * ========================================== + * -1 = LCN_HOLE Hole / not allocated on disk. + * -3 = LCN_ENOENT There is no such vcn in the attribute. + * -4 = LCN_EINVAL Input parameter error. + * -5 = LCN_EIO Corrupt fs, disk i/o error, or not enough memory. + */ +LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn) +{ + LCN lcn; + BOOL is_retry = FALSE; + + if (!na || !NAttrNonResident(na) || vcn < 0) + return (LCN)LCN_EINVAL; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); +retry: + /* Convert vcn to lcn. If that fails map the runlist and retry once. */ + lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); + if (lcn >= 0) + return lcn; + if (!is_retry && !ntfs_attr_map_runlist(na, vcn)) { + is_retry = TRUE; + goto retry; + } + /* + * If the attempt to map the runlist failed, or we are getting + * LCN_RL_NOT_MAPPED despite having mapped the attribute extent + * successfully, something is really badly wrong... + */ + if (!is_retry || lcn == (LCN)LCN_RL_NOT_MAPPED) + return (LCN)LCN_EIO; + /* lcn contains the appropriate error code. */ + return lcn; +} + +/** + * ntfs_attr_find_vcn - find a vcn in the runlist of an ntfs attribute + * @na: ntfs attribute whose runlist to search + * @vcn: vcn to find + * + * Find the virtual cluster number @vcn in the runlist of the ntfs attribute + * @na and return the the address of the runlist element containing the @vcn. + * + * Note you need to distinguish between the lcn of the returned runlist + * element being >= 0 and LCN_HOLE. In the later case you have to return zeroes + * on read and allocate clusters on write. You need to update the runlist, the + * attribute itself as well as write the modified mft record to disk. + * + * If there is an error return NULL with errno set to the error code. The + * following error codes are defined: + * EINVAL Input parameter error. + * ENOENT There is no such vcn in the runlist. + * ENOMEM Not enough memory. + * EIO I/O error or corrupt metadata. + */ +runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn) +{ + runlist_element *rl; + BOOL is_retry = FALSE; + + if (!na || !NAttrNonResident(na) || vcn < 0) { + errno = EINVAL; + return NULL; + } + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn %llx\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)vcn); +retry: + rl = na->rl; + if (!rl) + goto map_rl; + if (vcn < rl[0].vcn) + goto map_rl; + while (rl->length) { + if (vcn < rl[1].vcn) { + if (rl->lcn >= (LCN)LCN_HOLE) + return rl; + break; + } + rl++; + } + switch (rl->lcn) { + case (LCN)LCN_RL_NOT_MAPPED: + goto map_rl; + case (LCN)LCN_ENOENT: + errno = ENOENT; + break; + case (LCN)LCN_EINVAL: + errno = EINVAL; + break; + default: + errno = EIO; + break; + } + return NULL; +map_rl: + /* The @vcn is in an unmapped region, map the runlist and retry. */ + if (!is_retry && !ntfs_attr_map_runlist(na, vcn)) { + is_retry = TRUE; + goto retry; + } + /* + * If we already retried or the mapping attempt failed something has + * gone badly wrong. EINVAL and ENOENT coming from a failed mapping + * attempt are equivalent to errors for us as they should not happen + * in our code paths. + */ + if (is_retry || errno == EINVAL || errno == ENOENT) + errno = EIO; + return NULL; +} + +/** + * ntfs_attr_pread_i - see description at ntfs_attr_pread() + */ +static s64 ntfs_attr_pread_i(ntfs_attr *na, const s64 pos, s64 count, void *b) +{ + s64 br, to_read, ofs, total, total2, max_read, max_init; + ntfs_volume *vol; + runlist_element *rl; + u16 efs_padding_length; + + /* Sanity checking arguments is done in ntfs_attr_pread(). */ + + if ((na->data_flags & ATTR_COMPRESSION_MASK) && NAttrNonResident(na)) { + if ((na->data_flags & ATTR_COMPRESSION_MASK) + == ATTR_IS_COMPRESSED) + return ntfs_compressed_attr_pread(na, pos, count, b); + else { + /* compression mode not supported */ + errno = EOPNOTSUPP; + return -1; + } + } + /* + * Encrypted non-resident attributes are not supported. We return + * access denied, which is what Windows NT4 does, too. + * However, allow if mounted with efs_raw option + */ + vol = na->ni->vol; + if (!vol->efs_raw && NAttrEncrypted(na) && NAttrNonResident(na)) { + errno = EACCES; + return -1; + } + + if (!count) + return 0; + /* + * Truncate reads beyond end of attribute, + * but round to next 512 byte boundary for encrypted + * attributes with efs_raw mount option + */ + max_read = na->data_size; + max_init = na->initialized_size; + if (na->ni->vol->efs_raw + && (na->data_flags & ATTR_IS_ENCRYPTED) + && NAttrNonResident(na)) { + if (na->data_size != na->initialized_size) { + ntfs_log_error("uninitialized encrypted file not supported\n"); + errno = EINVAL; + return -1; + } + max_init = max_read = ((na->data_size + 511) & ~511) + 2; + } + if (pos + count > max_read) { + if (pos >= max_read) + return 0; + count = max_read - pos; + } + /* If it is a resident attribute, get the value from the mft record. */ + if (!NAttrNonResident(na)) { + ntfs_attr_search_ctx *ctx; + char *val; + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, + 0, NULL, 0, ctx)) { +res_err_out: + ntfs_attr_put_search_ctx(ctx); + return -1; + } + val = (char*)ctx->attr + le16_to_cpu(ctx->attr->value_offset); + if (val < (char*)ctx->attr || val + + le32_to_cpu(ctx->attr->value_length) > + (char*)ctx->mrec + vol->mft_record_size) { + errno = EIO; + ntfs_log_perror("%s: Sanity check failed", __FUNCTION__); + goto res_err_out; + } + memcpy(b, val + pos, count); + ntfs_attr_put_search_ctx(ctx); + return count; + } + total = total2 = 0; + /* Zero out reads beyond initialized size. */ + if (pos + count > max_init) { + if (pos >= max_init) { + memset(b, 0, count); + return count; + } + total2 = pos + count - max_init; + count -= total2; + memset((u8*)b + count, 0, total2); + } + /* + * for encrypted non-resident attributes with efs_raw set + * the last two bytes aren't read from disk but contain + * the number of padding bytes so original size can be + * restored + */ + if (na->ni->vol->efs_raw && + (na->data_flags & ATTR_IS_ENCRYPTED) && + ((pos + count) > max_init-2)) { + efs_padding_length = 511 - ((na->data_size - 1) & 511); + if (pos+count == max_init) { + if (count == 1) { + *((u8*)b+count-1) = (u8)(efs_padding_length >> 8); + count--; + total2++; + } else { + *(u16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); + count -= 2; + total2 +=2; + } + } else { + *((u8*)b+count-1) = (u8)(efs_padding_length & 0xff); + count--; + total2++; + } + } + + /* Find the runlist element containing the vcn. */ + rl = ntfs_attr_find_vcn(na, pos >> vol->cluster_size_bits); + if (!rl) { + /* + * If the vcn is not present it is an out of bounds read. + * However, we already truncated the read to the data_size, + * so getting this here is an error. + */ + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #1", __FUNCTION__); + } + return -1; + } + /* + * Gather the requested data into the linear destination buffer. Note, + * a partial final vcn is taken care of by the @count capping of read + * length. + */ + ofs = pos - (rl->vcn << vol->cluster_size_bits); + for (; count; rl++, ofs = 0) { + if (rl->lcn == LCN_RL_NOT_MAPPED) { + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl) { + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #2", + __FUNCTION__); + } + goto rl_err_out; + } + /* Needed for case when runs merged. */ + ofs = pos + total - (rl->vcn << vol->cluster_size_bits); + } + if (!rl->length) { + errno = EIO; + ntfs_log_perror("%s: Zero run length", __FUNCTION__); + goto rl_err_out; + } + if (rl->lcn < (LCN)0) { + if (rl->lcn != (LCN)LCN_HOLE) { + ntfs_log_perror("%s: Bad run (%lld)", + __FUNCTION__, + (long long)rl->lcn); + goto rl_err_out; + } + /* It is a hole, just zero the matching @b range. */ + to_read = min(count, (rl->length << + vol->cluster_size_bits) - ofs); + memset(b, 0, to_read); + /* Update progress counters. */ + total += to_read; + count -= to_read; + b = (u8*)b + to_read; + continue; + } + /* It is a real lcn, read it into @dst. */ + to_read = min(count, (rl->length << vol->cluster_size_bits) - + ofs); +retry: + ntfs_log_trace("Reading %lld bytes from vcn %lld, lcn %lld, ofs" + " %lld.\n", (long long)to_read, (long long)rl->vcn, + (long long )rl->lcn, (long long)ofs); + br = ntfs_pread(vol->dev, (rl->lcn << vol->cluster_size_bits) + + ofs, to_read, b); + /* If everything ok, update progress counters and continue. */ + if (br > 0) { + total += br; + count -= br; + b = (u8*)b + br; + } + if (br == to_read) + continue; + /* If the syscall was interrupted, try again. */ + if (br == (s64)-1 && errno == EINTR) + goto retry; + if (total) + return total; + if (!br) + errno = EIO; + ntfs_log_perror("%s: ntfs_pread failed", __FUNCTION__); + return -1; + } + /* Finally, return the number of bytes read. */ + return total + total2; +rl_err_out: + if (total) + return total; + errno = EIO; + return -1; +} + +/** + * ntfs_attr_pread - read from an attribute specified by an ntfs_attr structure + * @na: ntfs attribute to read from + * @pos: byte position in the attribute to begin reading from + * @count: number of bytes to read + * @b: output data buffer + * + * This function will read @count bytes starting at offset @pos from the ntfs + * attribute @na into the data buffer @b. + * + * On success, return the number of successfully read bytes. If this number is + * lower than @count this means that the read reached end of file or that an + * error was encountered during the read so that the read is partial. 0 means + * end of file or nothing was read (also return 0 when @count is 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of ntfs_pread(), or to EINVAL in case of invalid + * arguments. + */ +s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) +{ + s64 ret; + + if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("%s: na=%p b=%p pos=%lld count=%lld", + __FUNCTION__, na, b, (long long)pos, + (long long)count); + return -1; + } + + ntfs_log_enter("Entering for inode %lld attr 0x%x pos %lld count " + "%lld\n", (unsigned long long)na->ni->mft_no, + na->type, (long long)pos, (long long)count); + + ret = ntfs_attr_pread_i(na, pos, count, b); + + ntfs_log_leave("\n"); + return ret; +} + +static int ntfs_attr_fill_zero(ntfs_attr *na, s64 pos, s64 count) +{ + char *buf; + s64 written, size, end = pos + count; + s64 ofsi; + const runlist_element *rli; + ntfs_volume *vol; + int ret = -1; + + ntfs_log_trace("pos %lld, count %lld\n", (long long)pos, + (long long)count); + + if (!na || pos < 0 || count < 0) { + errno = EINVAL; + goto err_out; + } + + buf = ntfs_calloc(NTFS_BUF_SIZE); + if (!buf) + goto err_out; + + rli = na->rl; + ofsi = 0; + vol = na->ni->vol; + while (pos < end) { + while (rli->length && (ofsi + (rli->length << + vol->cluster_size_bits) <= pos)) { + ofsi += (rli->length << vol->cluster_size_bits); + rli++; + } + size = min(end - pos, NTFS_BUF_SIZE); + written = ntfs_rl_pwrite(vol, rli, ofsi, pos, size, buf); + if (written <= 0) { + ntfs_log_perror("Failed to zero space"); + goto err_free; + } + pos += written; + } + + ret = 0; +err_free: + free(buf); +err_out: + return ret; +} + +static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, + runlist_element **rl, VCN *update_from) +{ + s64 to_write; + s64 need; + ntfs_volume *vol = na->ni->vol; + int eo, ret = -1; + runlist *rlc; + LCN lcn_seek_from = -1; + VCN cur_vcn, from_vcn; + + to_write = min(count, ((*rl)->length << vol->cluster_size_bits) - *ofs); + + cur_vcn = (*rl)->vcn; + from_vcn = (*rl)->vcn + (*ofs >> vol->cluster_size_bits); + + ntfs_log_trace("count: %lld, cur_vcn: %lld, from: %lld, to: %lld, ofs: " + "%lld\n", (long long)count, (long long)cur_vcn, + (long long)from_vcn, (long long)to_write, (long long)*ofs); + + /* Map whole runlist to be able update mapping pairs later. */ + if (ntfs_attr_map_whole_runlist(na)) + goto err_out; + + /* Restore @*rl, it probably get lost during runlist mapping. */ + *rl = ntfs_attr_find_vcn(na, cur_vcn); + if (!*rl) { + ntfs_log_error("Failed to find run after mapping runlist. " + "Please report to %s.\n", NTFS_DEV_LIST); + errno = EIO; + goto err_out; + } + + /* Search backwards to find the best lcn to start seek from. */ + rlc = *rl; + while (rlc->vcn) { + rlc--; + if (rlc->lcn >= 0) { + /* + * avoid fragmenting a compressed file + * Windows does not do that, and that may + * not be desirable for files which can + * be updated + */ + if (na->data_flags & ATTR_COMPRESSION_MASK) + lcn_seek_from = rlc->lcn + rlc->length; + else + lcn_seek_from = rlc->lcn + (from_vcn - rlc->vcn); + break; + } + } + if (lcn_seek_from == -1) { + /* Backwards search failed, search forwards. */ + rlc = *rl; + while (rlc->length) { + rlc++; + if (rlc->lcn >= 0) { + lcn_seek_from = rlc->lcn - (rlc->vcn - from_vcn); + if (lcn_seek_from < -1) + lcn_seek_from = -1; + break; + } + } + } + + need = ((*ofs + to_write - 1) >> vol->cluster_size_bits) + + 1 + (*rl)->vcn - from_vcn; + if ((na->data_flags & ATTR_COMPRESSION_MASK) + && (need < na->compression_block_clusters)) { + /* + * for a compressed file, be sure to allocate the full + * compression block, as we may need space to decompress + * existing compressed data. + * So allocate the space common to compression block + * and existing hole. + */ + VCN alloc_vcn; + + if ((from_vcn & -na->compression_block_clusters) <= (*rl)->vcn) + alloc_vcn = (*rl)->vcn; + else + alloc_vcn = from_vcn & -na->compression_block_clusters; + need = (alloc_vcn | (na->compression_block_clusters - 1)) + + 1 - alloc_vcn; + if (need > (*rl)->length) { + ntfs_log_error("Cannot allocate %lld clusters" + " within a hole of %lld\n", + (long long)need, + (long long)(*rl)->length); + errno = EIO; + goto err_out; + } + rlc = ntfs_cluster_alloc(vol, alloc_vcn, need, + lcn_seek_from, DATA_ZONE); + } else + rlc = ntfs_cluster_alloc(vol, from_vcn, need, + lcn_seek_from, DATA_ZONE); + if (!rlc) + goto err_out; + if (na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) + na->compressed_size += need << vol->cluster_size_bits; + + *rl = ntfs_runlists_merge(na->rl, rlc); + /* + * For a compressed attribute, we must be sure there are two + * available entries, so reserve them before it gets too late. + */ + if (*rl && (na->data_flags & ATTR_COMPRESSION_MASK)) { + runlist_element *oldrl = na->rl; + na->rl = *rl; + *rl = ntfs_rl_extend(na,*rl,2); + if (!*rl) na->rl = oldrl; /* restore to original if failed */ + } + if (!*rl) { + eo = errno; + ntfs_log_perror("Failed to merge runlists"); + if (ntfs_cluster_free_from_rl(vol, rlc)) { + ntfs_log_perror("Failed to free hot clusters. " + "Please run chkdsk /f"); + } + errno = eo; + goto err_out; + } + na->unused_runs = 2; + na->rl = *rl; + if ((*update_from == -1) || (from_vcn < *update_from)) + *update_from = from_vcn; + *rl = ntfs_attr_find_vcn(na, cur_vcn); + if (!*rl) { + /* + * It's definitely a BUG, if we failed to find @cur_vcn, because + * we missed it during instantiating of the hole. + */ + ntfs_log_error("Failed to find run after hole instantiation. " + "Please report to %s.\n", NTFS_DEV_LIST); + errno = EIO; + goto err_out; + } + /* If leaved part of the hole go to the next run. */ + if ((*rl)->lcn < 0) + (*rl)++; + /* Now LCN shoudn't be less than 0. */ + if ((*rl)->lcn < 0) { + ntfs_log_error("BUG! LCN is lesser than 0. " + "Please report to the %s.\n", NTFS_DEV_LIST); + errno = EIO; + goto err_out; + } + if (*ofs) { + /* Clear non-sparse region from @cur_vcn to @*ofs. */ + if (ntfs_attr_fill_zero(na, cur_vcn << vol->cluster_size_bits, + *ofs)) + goto err_out; + } + if ((*rl)->vcn < cur_vcn) { + /* + * Clusters that replaced hole are merged with + * previous run, so we need to update offset. + */ + *ofs += (cur_vcn - (*rl)->vcn) << vol->cluster_size_bits; + } + if ((*rl)->vcn > cur_vcn) { + /* + * We left part of the hole, so we need to update offset + */ + *ofs -= ((*rl)->vcn - cur_vcn) << vol->cluster_size_bits; + } + + ret = 0; +err_out: + return ret; +} + +static int stuff_hole(ntfs_attr *na, const s64 pos); + +/* + * Split an existing hole for overwriting with data + * The hole may have to be split into two or three parts, so + * that the overwritten part fits within a single compression block + * + * No cluster allocation is needed, this will be done later in + * standard hole filling, hence no need to reserve runs for + * future needs. + * + * Returns the number of clusters with existing compressed data + * in the compression block to be written to + * (or the full block, if it was a full hole) + * -1 if there were an error + */ + +static int split_compressed_hole(ntfs_attr *na, runlist_element **prl, + s64 pos, s64 count, VCN *update_from) +{ + int compressed_part; + int cluster_size_bits = na->ni->vol->cluster_size_bits; + runlist_element *rl = *prl; + + compressed_part + = na->compression_block_clusters; + /* reserve entries in runlist if we have to split */ + if (rl->length > na->compression_block_clusters) { + *prl = ntfs_rl_extend(na,*prl,2); + if (!*prl) { + compressed_part = -1; + } else { + rl = *prl; + na->unused_runs = 2; + } + } + if (*prl && (rl->length > na->compression_block_clusters)) { + /* + * Locate the update part relative to beginning of + * current run + */ + int beginwrite = (pos >> cluster_size_bits) - rl->vcn; + s32 endblock = (((pos + count - 1) >> cluster_size_bits) + | (na->compression_block_clusters - 1)) + 1 - rl->vcn; + + compressed_part = na->compression_block_clusters + - (rl->length & (na->compression_block_clusters - 1)); + if ((beginwrite + compressed_part) >= na->compression_block_clusters) + compressed_part = na->compression_block_clusters; + /* + * if the run ends beyond end of needed block + * we have to split the run + */ + if (endblock < rl[0].length) { + runlist_element *xrl; + int n; + + /* + * we have to split into three parts if the run + * does not end within the first compression block. + * This means the hole begins before the + * compression block. + */ + if (endblock > na->compression_block_clusters) { + if (na->unused_runs < 2) { +ntfs_log_error("No free run, case 1\n"); + } + na->unused_runs -= 2; + xrl = rl; + n = 0; + while (xrl->length) { + xrl++; + n++; + } + do { + xrl[2] = *xrl; + xrl--; + } while (xrl != rl); + rl[1].length = na->compression_block_clusters; + rl[2].length = rl[0].length - endblock; + rl[0].length = endblock + - na->compression_block_clusters; + rl[1].lcn = LCN_HOLE; + rl[2].lcn = LCN_HOLE; + rl[1].vcn = rl[0].vcn + rl[0].length; + rl[2].vcn = rl[1].vcn + + na->compression_block_clusters; + rl = ++(*prl); + } else { + /* + * split into two parts and use the + * first one + */ + if (!na->unused_runs) { +ntfs_log_error("No free run, case 2\n"); + } + na->unused_runs--; + xrl = rl; + n = 0; + while (xrl->length) { + xrl++; + n++; + } + do { + xrl[1] = *xrl; + xrl--; + } while (xrl != rl); + if (beginwrite < endblock) { + /* we will write into the first part of hole */ + rl[1].length = rl[0].length - endblock; + rl[0].length = endblock; + rl[1].vcn = rl[0].vcn + rl[0].length; + rl[1].lcn = LCN_HOLE; + } else { + /* we will write into the second part of hole */ +// impossible ? + rl[1].length = rl[0].length - endblock; + rl[0].length = endblock; + rl[1].vcn = rl[0].vcn + rl[0].length; + rl[1].lcn = LCN_HOLE; + rl = ++(*prl); + } + } + } else { + if (rl[1].length) { + runlist_element *xrl; + int n; + + /* + * split into two parts and use the + * last one + */ + if (!na->unused_runs) { +ntfs_log_error("No free run, case 4\n"); + } + na->unused_runs--; + xrl = rl; + n = 0; + while (xrl->length) { + xrl++; + n++; + } + do { + xrl[1] = *xrl; + xrl--; + } while (xrl != rl); + } else { + rl[2].lcn = rl[1].lcn; + rl[2].vcn = rl[1].vcn; + rl[2].length = rl[1].length; + } + rl[1].vcn -= na->compression_block_clusters; + rl[1].lcn = LCN_HOLE; + rl[1].length = na->compression_block_clusters; + rl[0].length -= na->compression_block_clusters; + if (pos >= (rl[1].vcn << cluster_size_bits)) { + rl = ++(*prl); + } + } + if ((*update_from == -1) || ((*prl)->vcn < *update_from)) + *update_from = (*prl)->vcn; + } + return (compressed_part); +} + +/* + * Borrow space from adjacent hole for appending data + * The hole may have to be split so that the end of hole is not + * affected by cluster allocation and overwriting + * Cluster allocation is needed for the overwritten compression block + * + * Must always leave two unused entries in the runlist + * + * Returns the number of clusters with existing compressed data + * in the compression block to be written to + * -1 if there were an error + */ + +static int borrow_from_hole(ntfs_attr *na, runlist_element **prl, + s64 pos, s64 count, VCN *update_from, BOOL wasnonresident) +{ + int compressed_part = 0; + int cluster_size_bits = na->ni->vol->cluster_size_bits; + runlist_element *rl = *prl; + s32 endblock; + long long allocated; + runlist_element *zrl; + int irl; + BOOL undecided; + BOOL nothole; + + /* check whether the compression block is fully allocated */ + endblock = (((pos + count - 1) >> cluster_size_bits) | (na->compression_block_clusters - 1)) + 1 - rl->vcn; + allocated = 0; + zrl = rl; + irl = 0; + while (zrl->length && (zrl->lcn >= 0) && (allocated < endblock)) { + allocated += zrl->length; + zrl++; + irl++; + } + + undecided = (allocated < endblock) && (zrl->lcn == LCN_RL_NOT_MAPPED); + nothole = (allocated >= endblock) || (zrl->lcn != LCN_HOLE); + + if (undecided || nothole) { + runlist_element *orl = na->rl; + s64 olcn = (*prl)->lcn; + /* + * Map the full runlist (needed to compute the + * compressed size), unless the runlist has not + * yet been created (data just made non-resident) + */ + irl = *prl - na->rl; + if (!NAttrBeingNonResident(na) + && ntfs_attr_map_whole_runlist(na)) { + rl = (runlist_element*)NULL; + } else { + /* + * Mapping the runlist may cause its relocation, + * and relocation may be at the same place with + * relocated contents. + * Have to find the current run again when this + * happens. + */ + if ((na->rl != orl) || ((*prl)->lcn != olcn)) { + zrl = &na->rl[irl]; + while (zrl->length && (zrl->lcn != olcn)) + zrl++; + *prl = zrl; + } + if (!(*prl)->length) { + ntfs_log_error("Mapped run not found," + " inode %lld lcn 0x%llx\n", + (long long)na->ni->mft_no, + (long long)olcn); + rl = (runlist_element*)NULL; + } else { + rl = ntfs_rl_extend(na,*prl,2); + na->unused_runs = 2; + } + } + *prl = rl; + if (rl && undecided) { + allocated = 0; + zrl = rl; + irl = 0; + while (zrl->length && (zrl->lcn >= 0) + && (allocated < endblock)) { + allocated += zrl->length; + zrl++; + irl++; + } + } + } + /* + * compression block not fully allocated and followed + * by a hole : we must allocate in the hole. + */ + if (rl && (allocated < endblock) && (zrl->lcn == LCN_HOLE)) { + s64 xofs; + + /* + * split the hole if not fully needed + */ + if ((allocated + zrl->length) > endblock) { + runlist_element *xrl; + + *prl = ntfs_rl_extend(na,*prl,1); + if (*prl) { + /* beware : rl was reallocated */ + rl = *prl; + zrl = &rl[irl]; + na->unused_runs = 0; + xrl = zrl; + while (xrl->length) xrl++; + do { + xrl[1] = *xrl; + } while (xrl-- != zrl); + zrl->length = endblock - allocated; + zrl[1].length -= zrl->length; + zrl[1].vcn = zrl->vcn + zrl->length; + } + } + if (*prl) { + if (wasnonresident) + compressed_part = na->compression_block_clusters + - zrl->length; + xofs = 0; + if (ntfs_attr_fill_hole(na, + zrl->length << cluster_size_bits, + &xofs, &zrl, update_from)) + compressed_part = -1; + else { + /* go back to initial cluster, now reallocated */ + while (zrl->vcn > (pos >> cluster_size_bits)) + zrl--; + *prl = zrl; + } + } + } + if (!*prl) { + ntfs_log_error("No elements to borrow from a hole\n"); + compressed_part = -1; + } else + if ((*update_from == -1) || ((*prl)->vcn < *update_from)) + *update_from = (*prl)->vcn; + return (compressed_part); +} + +/** + * ntfs_attr_pwrite - positioned write to an ntfs attribute + * @na: ntfs attribute to write to + * @pos: position in the attribute to write to + * @count: number of bytes to write + * @b: data buffer to write to disk + * + * This function will write @count bytes from data buffer @b to ntfs attribute + * @na at position @pos. + * + * On success, return the number of successfully written bytes. If this number + * is lower than @count this means that an error was encountered during the + * write so that the write is partial. 0 means nothing was written (also return + * 0 when @count is 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of ntfs_pwrite(), or to EINVAL in case of + * invalid arguments. + */ +s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) +{ + s64 written, to_write, ofs, old_initialized_size, old_data_size; + s64 total = 0; + VCN update_from = -1; + ntfs_volume *vol; + s64 fullcount; + ntfs_attr_search_ctx *ctx = NULL; + runlist_element *rl; + s64 hole_end; + int eo; + int compressed_part; + struct { + unsigned int undo_initialized_size : 1; + unsigned int undo_data_size : 1; + } need_to = { 0, 0 }; + BOOL wasnonresident = FALSE; + BOOL compressed; + BOOL updatemap; + + ntfs_log_enter("Entering for inode %lld, attr 0x%x, pos 0x%llx, count " + "0x%llx.\n", (long long)na->ni->mft_no, na->type, + (long long)pos, (long long)count); + + if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + goto errno_set; + } + vol = na->ni->vol; + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + na->unused_runs = 0; /* prepare overflow checks */ + /* + * Encrypted attributes are only supported in raw mode. We return + * access denied, which is what Windows NT4 does, too. + * Moreover a file cannot be both encrypted and compressed. + */ + if ((na->data_flags & ATTR_IS_ENCRYPTED) + && (compressed || !vol->efs_raw)) { + errno = EACCES; + goto errno_set; + } + /* + * Fill the gap, when writing beyond the end of a compressed + * file. This will make recursive calls + */ + if (compressed + && (na->type == AT_DATA) + && (pos > na->initialized_size) + && stuff_hole(na,pos)) + goto errno_set; + /* If this is a compressed attribute it needs special treatment. */ + wasnonresident = NAttrNonResident(na) != 0; + /* + * Compression is restricted to data streams and + * only ATTR_IS_COMPRESSED compression mode is supported. + */ + if (compressed + && ((na->type != AT_DATA) + || ((na->data_flags & ATTR_COMPRESSION_MASK) + != ATTR_IS_COMPRESSED))) { + errno = EOPNOTSUPP; + goto errno_set; + } + + if (!count) + goto out; + /* for a compressed file, get prepared to reserve a full block */ + fullcount = count; + /* If the write reaches beyond the end, extend the attribute. */ + old_data_size = na->data_size; + if (pos + count > na->data_size) { + if (ntfs_attr_truncate(na, pos + count)) { + ntfs_log_perror("Failed to enlarge attribute"); + goto errno_set; + } + /* resizing may change the compression mode */ + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + need_to.undo_data_size = 1; + } + /* + * For compressed data, a single full block was allocated + * to deal with compression, possibly in a previous call. + * We are not able to process several blocks because + * some clusters are freed after compression and + * new allocations have to be done before proceeding, + * so truncate the requested count if needed (big buffers). + */ + if (compressed) { + fullcount = (pos | (na->compression_block_size - 1)) + 1 - pos; + if (count > fullcount) + count = fullcount; + } + old_initialized_size = na->initialized_size; + /* If it is a resident attribute, write the data to the mft record. */ + if (!NAttrNonResident(na)) { + char *val; + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + goto err_out; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, + 0, NULL, 0, ctx)) { + ntfs_log_perror("%s: lookup failed", __FUNCTION__); + goto err_out; + } + val = (char*)ctx->attr + le16_to_cpu(ctx->attr->value_offset); + if (val < (char*)ctx->attr || val + + le32_to_cpu(ctx->attr->value_length) > + (char*)ctx->mrec + vol->mft_record_size) { + errno = EIO; + ntfs_log_perror("%s: Sanity check failed", __FUNCTION__); + goto err_out; + } + memcpy(val + pos, b, count); + if (ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, + ctx->mrec)) { + /* + * NOTE: We are in a bad state at this moment. We have + * dirtied the mft record but we failed to commit it to + * disk. Since we have read the mft record ok before, + * it is unlikely to fail writing it, so is ok to just + * return error here... (AIA) + */ + ntfs_log_perror("%s: failed to write mft record", __FUNCTION__); + goto err_out; + } + ntfs_attr_put_search_ctx(ctx); + total = count; + goto out; + } + + /* Handle writes beyond initialized_size. */ + + if (pos + count > na->initialized_size) { + if (ntfs_attr_map_whole_runlist(na)) + goto err_out; + /* + * For a compressed attribute, we must be sure there is an + * available entry, and, when reopening a compressed file, + * we may need to split a hole. So reserve the entries + * before it gets too late. + */ + if (compressed) { + na->rl = ntfs_rl_extend(na,na->rl,2); + if (!na->rl) + goto err_out; + na->unused_runs = 2; + } + /* Set initialized_size to @pos + @count. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + goto err_out; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, + 0, NULL, 0, ctx)) + goto err_out; + + /* If write starts beyond initialized_size, zero the gap. */ + if (pos > na->initialized_size) + if (ntfs_attr_fill_zero(na, na->initialized_size, + pos - na->initialized_size)) + goto err_out; + + ctx->attr->initialized_size = cpu_to_sle64(pos + count); + /* fix data_size for compressed files */ + if (compressed) { + na->data_size = pos + count; + ctx->attr->data_size = ctx->attr->initialized_size; + } + if (ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, + ctx->mrec)) { + /* + * Undo the change in the in-memory copy and send it + * back for writing. + */ + ctx->attr->initialized_size = + cpu_to_sle64(old_initialized_size); + ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, + ctx->mrec); + goto err_out; + } + na->initialized_size = pos + count; +#if CACHE_NIDATA_SIZE + if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + ? na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30 + : na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + if ((compressed || NAttrSparse(na)) + && NAttrNonResident(na)) + na->ni->allocated_size = na->compressed_size; + else + na->ni->allocated_size = na->allocated_size; + set_nino_flag(na->ni,KnownSize); + } +#endif + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + /* + * NOTE: At this point the initialized_size in the mft record + * has been updated BUT there is random data on disk thus if + * we decide to abort, we MUST change the initialized_size + * again. + */ + need_to.undo_initialized_size = 1; + } + /* Find the runlist element containing the vcn. */ + rl = ntfs_attr_find_vcn(na, pos >> vol->cluster_size_bits); + if (!rl) { + /* + * If the vcn is not present it is an out of bounds write. + * However, we already extended the size of the attribute, + * so getting this here must be an error of some kind. + */ + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #3", __FUNCTION__); + } + goto err_out; + } + /* + * Determine if there is compressed data in the current + * compression block (when appending to an existing file). + * If so, decompression will be needed, and the full block + * must be allocated to be identified as uncompressed. + * This comes in two variants, depending on whether + * compression has saved at least one cluster. + * The compressed size can never be over full size by + * more than 485 (maximum for 15 compression blocks + * compressed to 4098 and the last 3640 bytes compressed + * to 3640 + 3640/8 = 4095, with 15*2 + 4095 - 3640 = 485) + * This is less than the smallest cluster, so the hole is + * is never beyond the cluster next to the position of + * the first uncompressed byte to write. + */ + compressed_part = 0; + if (compressed) { + if ((rl->lcn == (LCN)LCN_HOLE) + && wasnonresident) { + if (rl->length < na->compression_block_clusters) + /* + * the needed block is in a hole smaller + * than the compression block : we can use + * it fully + */ + compressed_part + = na->compression_block_clusters + - rl->length; + else { + /* + * the needed block is in a hole bigger + * than the compression block : we must + * split the hole and use it partially + */ + compressed_part = split_compressed_hole(na, + &rl, pos, count, &update_from); + } + } else { + if (rl->lcn >= 0) { + /* + * the needed block contains data, make + * sure the full compression block is + * allocated. Borrow from hole if needed + */ + compressed_part = borrow_from_hole(na, + &rl, pos, count, &update_from, + wasnonresident); + } + } + + if (compressed_part < 0) + goto err_out; + + /* just making non-resident, so not yet compressed */ + if (NAttrBeingNonResident(na) + && (compressed_part < na->compression_block_clusters)) + compressed_part = 0; + } + ofs = pos - (rl->vcn << vol->cluster_size_bits); + /* + * Scatter the data from the linear data buffer to the volume. Note, a + * partial final vcn is taken care of by the @count capping of write + * length. + */ + for (hole_end = 0; count; rl++, ofs = 0) { + if (rl->lcn == LCN_RL_NOT_MAPPED) { + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl) { + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN" + " #4", __FUNCTION__); + } + goto rl_err_out; + } + /* Needed for case when runs merged. */ + ofs = pos + total - (rl->vcn << vol->cluster_size_bits); + } + if (!rl->length) { + errno = EIO; + ntfs_log_perror("%s: Zero run length", __FUNCTION__); + goto rl_err_out; + } + if (rl->lcn < (LCN)0) { + hole_end = rl->vcn + rl->length; + + if (rl->lcn != (LCN)LCN_HOLE) { + errno = EIO; + ntfs_log_perror("%s: Unexpected LCN (%lld)", + __FUNCTION__, + (long long)rl->lcn); + goto rl_err_out; + } + if (ntfs_attr_fill_hole(na, fullcount, &ofs, &rl, + &update_from)) + goto err_out; + } + if (compressed) { + while (rl->length + && (ofs >= (rl->length << vol->cluster_size_bits))) { + ofs -= rl->length << vol->cluster_size_bits; + rl++; + } + } + + /* It is a real lcn, write it to the volume. */ + to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs); +retry: + ntfs_log_trace("Writing %lld bytes to vcn %lld, lcn %lld, ofs " + "%lld.\n", (long long)to_write, (long long)rl->vcn, + (long long)rl->lcn, (long long)ofs); + if (!NVolReadOnly(vol)) { + + s64 wpos = (rl->lcn << vol->cluster_size_bits) + ofs; + s64 wend = (rl->vcn << vol->cluster_size_bits) + ofs + to_write; + u32 bsize = vol->cluster_size; + /* Byte size needed to zero fill a cluster */ + s64 rounding = ((wend + bsize - 1) & ~(s64)(bsize - 1)) - wend; + /** + * Zero fill to cluster boundary if we're writing at the + * end of the attribute or into an ex-sparse cluster. + * This will cause the kernel not to seek and read disk + * blocks during write(2) to fill the end of the buffer + * which increases write speed by 2-10 fold typically. + * + * This is done even for compressed files, because + * data is generally first written uncompressed. + */ + if (rounding && ((wend == na->initialized_size) || + (wend < (hole_end << vol->cluster_size_bits)))){ + + char *cb; + + rounding += to_write; + + cb = ntfs_malloc(rounding); + if (!cb) + goto err_out; + + memcpy(cb, b, to_write); + memset(cb + to_write, 0, rounding - to_write); + + if (compressed) { + written = ntfs_compressed_pwrite(na, + rl, wpos, ofs, to_write, + rounding, cb, compressed_part, + &update_from); + } else { + written = ntfs_pwrite(vol->dev, wpos, + rounding, cb); + if (written == rounding) + written = to_write; + } + + free(cb); + } else { + if (compressed) { + written = ntfs_compressed_pwrite(na, + rl, wpos, ofs, to_write, + to_write, b, compressed_part, + &update_from); + } else + written = ntfs_pwrite(vol->dev, wpos, + to_write, b); + } + } else + written = to_write; + /* If everything ok, update progress counters and continue. */ + if (written > 0) { + total += written; + count -= written; + fullcount -= written; + b = (const u8*)b + written; + } + if (written != to_write) { + /* Partial write cannot be dealt with, stop there */ + /* If the syscall was interrupted, try again. */ + if (written == (s64)-1 && errno == EINTR) + goto retry; + if (!written) + errno = EIO; + goto rl_err_out; + } + compressed_part = 0; + } +done: + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* + * Update mapping pairs if needed. + * For a compressed file, we try to make a partial update + * of the mapping list. This makes a difference only if + * inode extents were needed. + */ + updatemap = (compressed + ? NAttrFullyMapped(na) != 0 : update_from != -1); + if (updatemap) + if (ntfs_attr_update_mapping_pairs(na, + (update_from < 0 ? 0 : update_from))) { + /* + * FIXME: trying to recover by goto rl_err_out; + * could cause driver hang by infinite looping. + */ + total = -1; + goto out; + } +out: + ntfs_log_leave("\n"); + return total; +rl_err_out: + eo = errno; + if (total) { + if (need_to.undo_initialized_size) { + if (pos + total > na->initialized_size) + goto done; + /* + * TODO: Need to try to change initialized_size. If it + * succeeds goto done, otherwise goto err_out. (AIA) + */ + goto err_out; + } + goto done; + } + errno = eo; +err_out: + eo = errno; + if (need_to.undo_initialized_size) { + int err; + + err = 0; + if (!ctx) { + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + err = 1; + } else + ntfs_attr_reinit_search_ctx(ctx); + if (!err) { + err = ntfs_attr_lookup(na->type, na->name, + na->name_len, 0, 0, NULL, 0, ctx); + if (!err) { + na->initialized_size = old_initialized_size; + ctx->attr->initialized_size = cpu_to_sle64( + old_initialized_size); + err = ntfs_mft_record_write(vol, + ctx->ntfs_ino->mft_no, + ctx->mrec); + } + } + if (err) { + /* + * FIXME: At this stage could try to recover by filling + * old_initialized_size -> new_initialized_size with + * data or at least zeroes. (AIA) + */ + ntfs_log_error("Eeek! Failed to recover from error. " + "Leaving metadata in inconsistent " + "state! Run chkdsk!\n"); + } + } + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + updatemap = (compressed + ? NAttrFullyMapped(na) != 0 : update_from != -1); + if (updatemap) + ntfs_attr_update_mapping_pairs(na, 0); + /* Restore original data_size if needed. */ + if (need_to.undo_data_size && ntfs_attr_truncate(na, old_data_size)) + ntfs_log_perror("Failed to restore data_size"); + errno = eo; +errno_set: + total = -1; + goto out; +} + +int ntfs_attr_pclose(ntfs_attr *na) +{ + s64 ofs; + int failed; + BOOL ok = TRUE; + VCN update_from = -1; + ntfs_volume *vol; + ntfs_attr_search_ctx *ctx = NULL; + runlist_element *rl; + int eo; + s64 hole; + int compressed_part; + BOOL compressed; + + ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x.\n", + na->ni->mft_no, na->type); + + if (!na || !na->ni || !na->ni->vol) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + goto errno_set; + } + vol = na->ni->vol; + na->unused_runs = 0; + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + /* + * Encrypted non-resident attributes are not supported. We return + * access denied, which is what Windows NT4 does, too. + */ + if (NAttrEncrypted(na) && NAttrNonResident(na)) { + errno = EACCES; + goto errno_set; + } + /* If this is not a compressed attribute get out */ + /* same if it is resident */ + if (!compressed || !NAttrNonResident(na)) + goto out; + + /* safety check : no recursion on close */ + if (NAttrComprClosing(na)) { + errno = EIO; + ntfs_log_error("Bad ntfs_attr_pclose" + " recursion on inode %lld\n", + (long long)na->ni->mft_no); + goto out; + } + NAttrSetComprClosing(na); + /* + * For a compressed attribute, we must be sure there are two + * available entries, so reserve them before it gets too late. + */ + if (ntfs_attr_map_whole_runlist(na)) + goto err_out; + na->rl = ntfs_rl_extend(na,na->rl,2); + if (!na->rl) + goto err_out; + na->unused_runs = 2; + /* Find the runlist element containing the terminal vcn. */ + rl = ntfs_attr_find_vcn(na, (na->initialized_size - 1) >> vol->cluster_size_bits); + if (!rl) { + /* + * If the vcn is not present it is an out of bounds write. + * However, we have already written the last byte uncompressed, + * so getting this here must be an error of some kind. + */ + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #5", __FUNCTION__); + } + goto err_out; + } + /* + * Scatter the data from the linear data buffer to the volume. Note, a + * partial final vcn is taken care of by the @count capping of write + * length. + */ + compressed_part = 0; + if (rl->lcn >= 0) { + runlist_element *xrl; + + xrl = rl; + do { + xrl++; + } while (xrl->lcn >= 0); + compressed_part = (-xrl->length) + & (na->compression_block_clusters - 1); + } else + if (rl->lcn == (LCN)LCN_HOLE) { + if (rl->length < na->compression_block_clusters) + compressed_part + = na->compression_block_clusters + - rl->length; + else + compressed_part + = na->compression_block_clusters; + } + /* done, if the last block set was compressed */ + if (compressed_part) + goto out; + + ofs = na->initialized_size - (rl->vcn << vol->cluster_size_bits); + + if (rl->lcn == LCN_RL_NOT_MAPPED) { + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl) { + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN" + " #6", __FUNCTION__); + } + goto rl_err_out; + } + /* Needed for case when runs merged. */ + ofs = na->initialized_size - (rl->vcn << vol->cluster_size_bits); + } + if (!rl->length) { + errno = EIO; + ntfs_log_perror("%s: Zero run length", __FUNCTION__); + goto rl_err_out; + } + if (rl->lcn < (LCN)0) { + hole = rl->vcn + rl->length; + if (rl->lcn != (LCN)LCN_HOLE) { + errno = EIO; + ntfs_log_perror("%s: Unexpected LCN (%lld)", + __FUNCTION__, + (long long)rl->lcn); + goto rl_err_out; + } + + if (ntfs_attr_fill_hole(na, (s64)0, &ofs, &rl, &update_from)) + goto err_out; + } + while (rl->length + && (ofs >= (rl->length << vol->cluster_size_bits))) { + ofs -= rl->length << vol->cluster_size_bits; + rl++; + } + +retry: + failed = 0; + if (update_from < 0) update_from = 0; + if (!NVolReadOnly(vol)) { + failed = ntfs_compressed_close(na, rl, ofs, &update_from); +#if CACHE_NIDATA_SIZE + if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + ? na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30 + : na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + na->ni->allocated_size = na->compressed_size; + set_nino_flag(na->ni,KnownSize); + } +#endif + } + if (failed) { + /* If the syscall was interrupted, try again. */ + if (errno == EINTR) + goto retry; + else + goto rl_err_out; + } + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + if (NAttrFullyMapped(na)) + if (ntfs_attr_update_mapping_pairs(na, update_from)) { + /* + * FIXME: trying to recover by goto rl_err_out; + * could cause driver hang by infinite looping. + */ + ok = FALSE; + goto out; + } +out: + ntfs_log_leave("\n"); + return (!ok); +rl_err_out: + /* + * need not restore old sizes, only compressed_size + * can have changed. It has been set according to + * the current runlist while updating the mapping pairs, + * and must be kept consistent with the runlists. + */ +err_out: + eo = errno; + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + if (NAttrFullyMapped(na)) + ntfs_attr_update_mapping_pairs(na, 0); + errno = eo; +errno_set: + ok = FALSE; + goto out; +} + +/** + * ntfs_attr_mst_pread - multi sector transfer protected ntfs attribute read + * @na: multi sector transfer protected ntfs attribute to read from + * @pos: byte position in the attribute to begin reading from + * @bk_cnt: number of mst protected blocks to read + * @bk_size: size of each mst protected block in bytes + * @dst: output data buffer + * + * This function will read @bk_cnt blocks of size @bk_size bytes each starting + * at offset @pos from the ntfs attribute @na into the data buffer @b. + * + * On success, the multi sector transfer fixups are applied and the number of + * read blocks is returned. If this number is lower than @bk_cnt this means + * that the read has either reached end of attribute or that an error was + * encountered during the read so that the read is partial. 0 means end of + * attribute or nothing to read (also return 0 when @bk_cnt or @bk_size are 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of ntfs_attr_pread() or to EINVAL in case of invalid + * arguments. + * + * NOTE: If an incomplete multi sector transfer is detected the magic is + * changed to BAAD but no error is returned, i.e. it is possible that any of + * the returned blocks have multi sector transfer errors. This should be + * detected by the caller by checking each block with is_baad_recordp(&block). + * The reasoning is that we want to fixup as many blocks as possible and we + * want to return even bad ones to the caller so, e.g. in case of ntfsck, the + * errors can be repaired. + */ +s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, + const u32 bk_size, void *dst) +{ + s64 br; + u8 *end; + + ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos); + if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + br = ntfs_attr_pread(na, pos, bk_cnt * bk_size, dst); + if (br <= 0) + return br; + br /= bk_size; + for (end = (u8*)dst + br * bk_size; (u8*)dst < end; dst = (u8*)dst + + bk_size) + ntfs_mst_post_read_fixup((NTFS_RECORD*)dst, bk_size); + /* Finally, return the number of blocks read. */ + return br; +} + +/** + * ntfs_attr_mst_pwrite - multi sector transfer protected ntfs attribute write + * @na: multi sector transfer protected ntfs attribute to write to + * @pos: position in the attribute to write to + * @bk_cnt: number of mst protected blocks to write + * @bk_size: size of each mst protected block in bytes + * @src: data buffer to write to disk + * + * This function will write @bk_cnt blocks of size @bk_size bytes each from + * data buffer @b to multi sector transfer (mst) protected ntfs attribute @na + * at position @pos. + * + * On success, return the number of successfully written blocks. If this number + * is lower than @bk_cnt this means that an error was encountered during the + * write so that the write is partial. 0 means nothing was written (also + * return 0 when @bk_cnt or @bk_size are 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of ntfs_attr_pwrite(), or to EINVAL in case + * of invalid arguments. + * + * NOTE: We mst protect the data, write it, then mst deprotect it using a quick + * deprotect algorithm (no checking). This saves us from making a copy before + * the write and at the same time causes the usn to be incremented in the + * buffer. This conceptually fits in better with the idea that cached data is + * always deprotected and protection is performed when the data is actually + * going to hit the disk and the cache is immediately deprotected again + * simulating an mst read on the written data. This way cache coherency is + * achieved. + */ +s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, + const u32 bk_size, void *src) +{ + s64 written, i; + + ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos); + if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { + errno = EINVAL; + return -1; + } + if (!bk_cnt) + return 0; + /* Prepare data for writing. */ + for (i = 0; i < bk_cnt; ++i) { + int err; + + err = ntfs_mst_pre_write_fixup((NTFS_RECORD*) + ((u8*)src + i * bk_size), bk_size); + if (err < 0) { + /* Abort write at this position. */ + ntfs_log_perror("%s #1", __FUNCTION__); + if (!i) + return err; + bk_cnt = i; + break; + } + } + /* Write the prepared data. */ + written = ntfs_attr_pwrite(na, pos, bk_cnt * bk_size, src); + if (written <= 0) { + ntfs_log_perror("%s: written=%lld", __FUNCTION__, + (long long)written); + } + /* Quickly deprotect the data again. */ + for (i = 0; i < bk_cnt; ++i) + ntfs_mst_post_write_fixup((NTFS_RECORD*)((u8*)src + i * + bk_size)); + if (written <= 0) + return written; + /* Finally, return the number of complete blocks written. */ + return written / bk_size; +} + +/** + * ntfs_attr_find - find (next) attribute in mft record + * @type: attribute type to find + * @name: attribute name to find (optional, i.e. NULL means don't care) + * @name_len: attribute name length (only needed if @name present) + * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) + * @val: attribute value to find (optional, resident attributes only) + * @val_len: attribute value length + * @ctx: search context with mft record and attribute to search from + * + * You shouldn't need to call this function directly. Use lookup_attr() instead. + * + * ntfs_attr_find() takes a search context @ctx as parameter and searches the + * mft record specified by @ctx->mrec, beginning at @ctx->attr, for an + * attribute of @type, optionally @name and @val. If found, ntfs_attr_find() + * returns 0 and @ctx->attr will point to the found attribute. + * + * If not found, ntfs_attr_find() returns -1, with errno set to ENOENT and + * @ctx->attr will point to the attribute before which the attribute being + * searched for would need to be inserted if such an action were to be desired. + * + * On actual error, ntfs_attr_find() returns -1 with errno set to the error + * code but not to ENOENT. In this case @ctx->attr is undefined and in + * particular do not rely on it not changing. + * + * If @ctx->is_first is TRUE, the search begins with @ctx->attr itself. If it + * is FALSE, the search begins after @ctx->attr. + * + * If @type is AT_UNUSED, return the first found attribute, i.e. one can + * enumerate all attributes by setting @type to AT_UNUSED and then calling + * ntfs_attr_find() repeatedly until it returns -1 with errno set to ENOENT to + * indicate that there are no more entries. During the enumeration, each + * successful call of ntfs_attr_find() will return the next attribute in the + * mft record @ctx->mrec. + * + * If @type is AT_END, seek to the end and return -1 with errno set to ENOENT. + * AT_END is not a valid attribute, its length is zero for example, thus it is + * safer to return error instead of success in this case. This also allows us + * to interoperate cleanly with ntfs_external_attr_find(). + * + * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present + * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, + * match both named and unnamed attributes. + * + * If @ic is IGNORE_CASE, the @name comparison is not case sensitive and + * @ctx->ntfs_ino must be set to the ntfs inode to which the mft record + * @ctx->mrec belongs. This is so we can get at the ntfs volume and hence at + * the upcase table. If @ic is CASE_SENSITIVE, the comparison is case + * sensitive. When @name is present, @name_len is the @name length in Unicode + * characters. + * + * If @name is not present (NULL), we assume that the unnamed attribute is + * being searched for. + * + * Finally, the resident attribute value @val is looked for, if present. + * If @val is not present (NULL), @val_len is ignored. + * + * ntfs_attr_find() only searches the specified mft record and it ignores the + * presence of an attribute list attribute (unless it is the one being searched + * for, obviously). If you need to take attribute lists into consideration, use + * ntfs_attr_lookup() instead (see below). This also means that you cannot use + * ntfs_attr_find() to search for extent records of non-resident attributes, as + * extents with lowest_vcn != 0 are usually described by the attribute list + * attribute only. - Note that it is possible that the first extent is only in + * the attribute list while the last extent is in the base mft record, so don't + * rely on being able to find the first extent in the base mft record. + * + * Warning: Never use @val when looking for attribute types which can be + * non-resident as this most likely will result in a crash! + */ +static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) +{ + ATTR_RECORD *a; + ntfs_volume *vol; + ntfschar *upcase; + u32 upcase_len; + + ntfs_log_trace("attribute type 0x%x.\n", type); + + if (ctx->ntfs_ino) { + vol = ctx->ntfs_ino->vol; + upcase = vol->upcase; + upcase_len = vol->upcase_len; + } else { + if (name && name != AT_UNNAMED) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + vol = NULL; + upcase = NULL; + upcase_len = 0; + } + /* + * Iterate over attributes in mft record starting at @ctx->attr, or the + * attribute following that, if @ctx->is_first is TRUE. + */ + if (ctx->is_first) { + a = ctx->attr; + ctx->is_first = FALSE; + } else + a = (ATTR_RECORD*)((char*)ctx->attr + + le32_to_cpu(ctx->attr->length)); + for (;; a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length))) { + if (p2n(a) < p2n(ctx->mrec) || (char*)a > (char*)ctx->mrec + + le32_to_cpu(ctx->mrec->bytes_allocated)) + break; + ctx->attr = a; + if (((type != AT_UNUSED) && (le32_to_cpu(a->type) > + le32_to_cpu(type))) || + (a->type == AT_END)) { + errno = ENOENT; + return -1; + } + if (!a->length) + break; + /* If this is an enumeration return this attribute. */ + if (type == AT_UNUSED) + return 0; + if (a->type != type) + continue; + /* + * If @name is AT_UNNAMED we want an unnamed attribute. + * If @name is present, compare the two names. + * Otherwise, match any attribute. + */ + if (name == AT_UNNAMED) { + /* The search failed if the found attribute is named. */ + if (a->name_length) { + errno = ENOENT; + return -1; + } + } else { + register int rc; + if (name && ((rc = ntfs_names_full_collate(name, + name_len, (ntfschar*)((char*)a + + le16_to_cpu(a->name_offset)), + a->name_length, ic, + upcase, upcase_len)))) { + /* + * If @name collates before a->name, + * there is no matching attribute. + */ + if (rc < 0) { + errno = ENOENT; + return -1; + } + /* If the strings are not equal, continue search. */ + continue; + } + } + /* + * The names match or @name not present and attribute is + * unnamed. If no @val specified, we have found the attribute + * and are done. + */ + if (!val) + return 0; + /* @val is present; compare values. */ + else { + register int rc; + + rc = memcmp(val, (char*)a +le16_to_cpu(a->value_offset), + min(val_len, + le32_to_cpu(a->value_length))); + /* + * If @val collates before the current attribute's + * value, there is no matching attribute. + */ + if (!rc) { + register u32 avl; + avl = le32_to_cpu(a->value_length); + if (val_len == avl) + return 0; + if (val_len < avl) { + errno = ENOENT; + return -1; + } + } else if (rc < 0) { + errno = ENOENT; + return -1; + } + } + } + errno = EIO; + ntfs_log_perror("%s: Corrupt inode (%lld)", __FUNCTION__, + ctx->ntfs_ino ? (long long)ctx->ntfs_ino->mft_no : -1); + return -1; +} + +void ntfs_attr_name_free(char **name) +{ + if (*name) { + free(*name); + *name = NULL; + } +} + +char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len) +{ + char *name = NULL; + int name_len; + + name_len = ntfs_ucstombs(uname, uname_len, &name, 0); + if (name_len < 0) { + ntfs_log_perror("ntfs_ucstombs"); + return NULL; + + } else if (name_len > 0) + return name; + + ntfs_attr_name_free(&name); + return NULL; +} + +/** + * ntfs_external_attr_find - find an attribute in the attribute list of an inode + * @type: attribute type to find + * @name: attribute name to find (optional, i.e. NULL means don't care) + * @name_len: attribute name length (only needed if @name present) + * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) + * @lowest_vcn: lowest vcn to find (optional, non-resident attributes only) + * @val: attribute value to find (optional, resident attributes only) + * @val_len: attribute value length + * @ctx: search context with mft record and attribute to search from + * + * You shouldn't need to call this function directly. Use ntfs_attr_lookup() + * instead. + * + * Find an attribute by searching the attribute list for the corresponding + * attribute list entry. Having found the entry, map the mft record for read + * if the attribute is in a different mft record/inode, find the attribute in + * there and return it. + * + * If @type is AT_UNUSED, return the first found attribute, i.e. one can + * enumerate all attributes by setting @type to AT_UNUSED and then calling + * ntfs_external_attr_find() repeatedly until it returns -1 with errno set to + * ENOENT to indicate that there are no more entries. During the enumeration, + * each successful call of ntfs_external_attr_find() will return the next + * attribute described by the attribute list of the base mft record described + * by the search context @ctx. + * + * If @type is AT_END, seek to the end of the base mft record ignoring the + * attribute list completely and return -1 with errno set to ENOENT. AT_END is + * not a valid attribute, its length is zero for example, thus it is safer to + * return error instead of success in this case. + * + * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present + * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, + * match both named and unnamed attributes. + * + * On first search @ctx->ntfs_ino must be the inode of the base mft record and + * @ctx must have been obtained from a call to ntfs_attr_get_search_ctx(). + * On subsequent calls, @ctx->ntfs_ino can be any extent inode, too + * (@ctx->base_ntfs_ino is then the base inode). + * + * After finishing with the attribute/mft record you need to call + * ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any + * mapped extent inodes, etc). + * + * Return 0 if the search was successful and -1 if not, with errno set to the + * error code. + * + * On success, @ctx->attr is the found attribute, it is in mft record + * @ctx->mrec, and @ctx->al_entry is the attribute list entry for this + * attribute with @ctx->base_* being the base mft record to which @ctx->attr + * belongs. + * + * On error ENOENT, i.e. attribute not found, @ctx->attr is set to the + * attribute which collates just after the attribute being searched for in the + * base ntfs inode, i.e. if one wants to add the attribute to the mft record + * this is the correct place to insert it into, and if there is not enough + * space, the attribute should be placed in an extent mft record. + * @ctx->al_entry points to the position within @ctx->base_ntfs_ino->attr_list + * at which the new attribute's attribute list entry should be inserted. The + * other @ctx fields, base_ntfs_ino, base_mrec, and base_attr are set to NULL. + * The only exception to this is when @type is AT_END, in which case + * @ctx->al_entry is set to NULL also (see above). + * + * The following error codes are defined: + * ENOENT Attribute not found, not an error as such. + * EINVAL Invalid arguments. + * EIO I/O error or corrupt data structures found. + * ENOMEM Not enough memory to allocate necessary buffers. + */ +static int ntfs_external_attr_find(ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const VCN lowest_vcn, const u8 *val, const u32 val_len, + ntfs_attr_search_ctx *ctx) +{ + ntfs_inode *base_ni, *ni; + ntfs_volume *vol; + ATTR_LIST_ENTRY *al_entry, *next_al_entry; + u8 *al_start, *al_end; + ATTR_RECORD *a; + ntfschar *al_name; + u32 al_name_len; + BOOL is_first_search = FALSE; + + ni = ctx->ntfs_ino; + base_ni = ctx->base_ntfs_ino; + ntfs_log_trace("Entering for inode %lld, attribute type 0x%x.\n", + (unsigned long long)ni->mft_no, type); + if (!base_ni) { + /* First call happens with the base mft record. */ + base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino; + ctx->base_mrec = ctx->mrec; + } + if (ni == base_ni) + ctx->base_attr = ctx->attr; + if (type == AT_END) + goto not_found; + vol = base_ni->vol; + al_start = base_ni->attr_list; + al_end = al_start + base_ni->attr_list_size; + if (!ctx->al_entry) { + ctx->al_entry = (ATTR_LIST_ENTRY*)al_start; + is_first_search = TRUE; + } + /* + * Iterate over entries in attribute list starting at @ctx->al_entry, + * or the entry following that, if @ctx->is_first is TRUE. + */ + if (ctx->is_first) { + al_entry = ctx->al_entry; + ctx->is_first = FALSE; + /* + * If an enumeration and the first attribute is higher than + * the attribute list itself, need to return the attribute list + * attribute. + */ + if ((type == AT_UNUSED) && is_first_search && + le32_to_cpu(al_entry->type) > + le32_to_cpu(AT_ATTRIBUTE_LIST)) + goto find_attr_list_attr; + } else { + al_entry = (ATTR_LIST_ENTRY*)((char*)ctx->al_entry + + le16_to_cpu(ctx->al_entry->length)); + /* + * If this is an enumeration and the attribute list attribute + * is the next one in the enumeration sequence, just return the + * attribute list attribute from the base mft record as it is + * not listed in the attribute list itself. + */ + if ((type == AT_UNUSED) && le32_to_cpu(ctx->al_entry->type) < + le32_to_cpu(AT_ATTRIBUTE_LIST) && + le32_to_cpu(al_entry->type) > + le32_to_cpu(AT_ATTRIBUTE_LIST)) { + int rc; +find_attr_list_attr: + + /* Check for bogus calls. */ + if (name || name_len || val || val_len || lowest_vcn) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + + /* We want the base record. */ + ctx->ntfs_ino = base_ni; + ctx->mrec = ctx->base_mrec; + ctx->is_first = TRUE; + /* Sanity checks are performed elsewhere. */ + ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + + /* Find the attribute list attribute. */ + rc = ntfs_attr_find(AT_ATTRIBUTE_LIST, NULL, 0, + IGNORE_CASE, NULL, 0, ctx); + + /* + * Setup the search context so the correct + * attribute is returned next time round. + */ + ctx->al_entry = al_entry; + ctx->is_first = TRUE; + + /* Got it. Done. */ + if (!rc) + return 0; + + /* Error! If other than not found return it. */ + if (errno != ENOENT) + return rc; + + /* Not found?!? Absurd! */ + errno = EIO; + ntfs_log_error("Attribute list wasn't found"); + return -1; + } + } + for (;; al_entry = next_al_entry) { + /* Out of bounds check. */ + if ((u8*)al_entry < base_ni->attr_list || + (u8*)al_entry > al_end) + break; /* Inode is corrupt. */ + ctx->al_entry = al_entry; + /* Catch the end of the attribute list. */ + if ((u8*)al_entry == al_end) + goto not_found; + if (!al_entry->length) + break; + if ((u8*)al_entry + 6 > al_end || (u8*)al_entry + + le16_to_cpu(al_entry->length) > al_end) + break; + next_al_entry = (ATTR_LIST_ENTRY*)((u8*)al_entry + + le16_to_cpu(al_entry->length)); + if (type != AT_UNUSED) { + if (le32_to_cpu(al_entry->type) > le32_to_cpu(type)) + goto not_found; + if (type != al_entry->type) + continue; + } + al_name_len = al_entry->name_length; + al_name = (ntfschar*)((u8*)al_entry + al_entry->name_offset); + /* + * If !@type we want the attribute represented by this + * attribute list entry. + */ + if (type == AT_UNUSED) + goto is_enumeration; + /* + * If @name is AT_UNNAMED we want an unnamed attribute. + * If @name is present, compare the two names. + * Otherwise, match any attribute. + */ + if (name == AT_UNNAMED) { + if (al_name_len) + goto not_found; + } else { + int rc; + + if (name && ((rc = ntfs_names_full_collate(name, + name_len, al_name, al_name_len, ic, + vol->upcase, vol->upcase_len)))) { + + /* + * If @name collates before al_name, + * there is no matching attribute. + */ + if (rc < 0) + goto not_found; + /* If the strings are not equal, continue search. */ + continue; + } + } + /* + * The names match or @name not present and attribute is + * unnamed. Now check @lowest_vcn. Continue search if the + * next attribute list entry still fits @lowest_vcn. Otherwise + * we have reached the right one or the search has failed. + */ + if (lowest_vcn && (u8*)next_al_entry >= al_start && + (u8*)next_al_entry + 6 < al_end && + (u8*)next_al_entry + le16_to_cpu( + next_al_entry->length) <= al_end && + sle64_to_cpu(next_al_entry->lowest_vcn) <= + lowest_vcn && + next_al_entry->type == al_entry->type && + next_al_entry->name_length == al_name_len && + ntfs_names_are_equal((ntfschar*)((char*) + next_al_entry + + next_al_entry->name_offset), + next_al_entry->name_length, + al_name, al_name_len, CASE_SENSITIVE, + vol->upcase, vol->upcase_len)) + continue; +is_enumeration: + if (MREF_LE(al_entry->mft_reference) == ni->mft_no) { + if (MSEQNO_LE(al_entry->mft_reference) != + le16_to_cpu( + ni->mrec->sequence_number)) { + ntfs_log_error("Found stale mft reference in " + "attribute list!\n"); + break; + } + } else { /* Mft references do not match. */ + /* Do we want the base record back? */ + if (MREF_LE(al_entry->mft_reference) == + base_ni->mft_no) { + ni = ctx->ntfs_ino = base_ni; + ctx->mrec = ctx->base_mrec; + } else { + /* We want an extent record. */ + ni = ntfs_extent_inode_open(base_ni, + al_entry->mft_reference); + if (!ni) + break; + ctx->ntfs_ino = ni; + ctx->mrec = ni->mrec; + } + } + a = ctx->attr = (ATTR_RECORD*)((char*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + /* + * ctx->ntfs_ino, ctx->mrec, and ctx->attr now point to the + * mft record containing the attribute represented by the + * current al_entry. + * + * We could call into ntfs_attr_find() to find the right + * attribute in this mft record but this would be less + * efficient and not quite accurate as ntfs_attr_find() ignores + * the attribute instance numbers for example which become + * important when one plays with attribute lists. Also, because + * a proper match has been found in the attribute list entry + * above, the comparison can now be optimized. So it is worth + * re-implementing a simplified ntfs_attr_find() here. + * + * Use a manual loop so we can still use break and continue + * with the same meanings as above. + */ +do_next_attr_loop: + if ((char*)a < (char*)ctx->mrec || (char*)a > (char*)ctx->mrec + + le32_to_cpu(ctx->mrec->bytes_allocated)) + break; + if (a->type == AT_END) + continue; + if (!a->length) + break; + if (al_entry->instance != a->instance) + goto do_next_attr; + /* + * If the type and/or the name are/is mismatched between the + * attribute list entry and the attribute record, there is + * corruption so we break and return error EIO. + */ + if (al_entry->type != a->type) + break; + if (!ntfs_names_are_equal((ntfschar*)((char*)a + + le16_to_cpu(a->name_offset)), + a->name_length, al_name, + al_name_len, CASE_SENSITIVE, + vol->upcase, vol->upcase_len)) + break; + ctx->attr = a; + /* + * If no @val specified or @val specified and it matches, we + * have found it! Also, if !@type, it is an enumeration, so we + * want the current attribute. + */ + if ((type == AT_UNUSED) || !val || (!a->non_resident && + le32_to_cpu(a->value_length) == val_len && + !memcmp((char*)a + le16_to_cpu(a->value_offset), + val, val_len))) { + return 0; + } +do_next_attr: + /* Proceed to the next attribute in the current mft record. */ + a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length)); + goto do_next_attr_loop; + } + if (ni != base_ni) { + ctx->ntfs_ino = base_ni; + ctx->mrec = ctx->base_mrec; + ctx->attr = ctx->base_attr; + } + errno = EIO; + ntfs_log_perror("Inode is corrupt (%lld)", (long long)base_ni->mft_no); + return -1; +not_found: + /* + * If we were looking for AT_END or we were enumerating and reached the + * end, we reset the search context @ctx and use ntfs_attr_find() to + * seek to the end of the base mft record. + */ + if (type == AT_UNUSED || type == AT_END) { + ntfs_attr_reinit_search_ctx(ctx); + return ntfs_attr_find(AT_END, name, name_len, ic, val, val_len, + ctx); + } + /* + * The attribute wasn't found. Before we return, we want to ensure + * @ctx->mrec and @ctx->attr indicate the position at which the + * attribute should be inserted in the base mft record. Since we also + * want to preserve @ctx->al_entry we cannot reinitialize the search + * context using ntfs_attr_reinit_search_ctx() as this would set + * @ctx->al_entry to NULL. Thus we do the necessary bits manually (see + * ntfs_attr_init_search_ctx() below). Note, we _only_ preserve + * @ctx->al_entry as the remaining fields (base_*) are identical to + * their non base_ counterparts and we cannot set @ctx->base_attr + * correctly yet as we do not know what @ctx->attr will be set to by + * the call to ntfs_attr_find() below. + */ + ctx->mrec = ctx->base_mrec; + ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + ctx->is_first = TRUE; + ctx->ntfs_ino = ctx->base_ntfs_ino; + ctx->base_ntfs_ino = NULL; + ctx->base_mrec = NULL; + ctx->base_attr = NULL; + /* + * In case there are multiple matches in the base mft record, need to + * keep enumerating until we get an attribute not found response (or + * another error), otherwise we would keep returning the same attribute + * over and over again and all programs using us for enumeration would + * lock up in a tight loop. + */ + { + int ret; + + do { + ret = ntfs_attr_find(type, name, name_len, ic, val, + val_len, ctx); + } while (!ret); + return ret; + } +} + +/** + * ntfs_attr_lookup - find an attribute in an ntfs inode + * @type: attribute type to find + * @name: attribute name to find (optional, i.e. NULL means don't care) + * @name_len: attribute name length (only needed if @name present) + * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) + * @lowest_vcn: lowest vcn to find (optional, non-resident attributes only) + * @val: attribute value to find (optional, resident attributes only) + * @val_len: attribute value length + * @ctx: search context with mft record and attribute to search from + * + * Find an attribute in an ntfs inode. On first search @ctx->ntfs_ino must + * be the base mft record and @ctx must have been obtained from a call to + * ntfs_attr_get_search_ctx(). + * + * This function transparently handles attribute lists and @ctx is used to + * continue searches where they were left off at. + * + * If @type is AT_UNUSED, return the first found attribute, i.e. one can + * enumerate all attributes by setting @type to AT_UNUSED and then calling + * ntfs_attr_lookup() repeatedly until it returns -1 with errno set to ENOENT + * to indicate that there are no more entries. During the enumeration, each + * successful call of ntfs_attr_lookup() will return the next attribute, with + * the current attribute being described by the search context @ctx. + * + * If @type is AT_END, seek to the end of the base mft record ignoring the + * attribute list completely and return -1 with errno set to ENOENT. AT_END is + * not a valid attribute, its length is zero for example, thus it is safer to + * return error instead of success in this case. It should never be needed to + * do this, but we implement the functionality because it allows for simpler + * code inside ntfs_external_attr_find(). + * + * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present + * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, + * match both named and unnamed attributes. + * + * After finishing with the attribute/mft record you need to call + * ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any + * mapped extent inodes, etc). + * + * Return 0 if the search was successful and -1 if not, with errno set to the + * error code. + * + * On success, @ctx->attr is the found attribute, it is in mft record + * @ctx->mrec, and @ctx->al_entry is the attribute list entry for this + * attribute with @ctx->base_* being the base mft record to which @ctx->attr + * belongs. If no attribute list attribute is present @ctx->al_entry and + * @ctx->base_* are NULL. + * + * On error ENOENT, i.e. attribute not found, @ctx->attr is set to the + * attribute which collates just after the attribute being searched for in the + * base ntfs inode, i.e. if one wants to add the attribute to the mft record + * this is the correct place to insert it into, and if there is not enough + * space, the attribute should be placed in an extent mft record. + * @ctx->al_entry points to the position within @ctx->base_ntfs_ino->attr_list + * at which the new attribute's attribute list entry should be inserted. The + * other @ctx fields, base_ntfs_ino, base_mrec, and base_attr are set to NULL. + * The only exception to this is when @type is AT_END, in which case + * @ctx->al_entry is set to NULL also (see above). + * + * + * The following error codes are defined: + * ENOENT Attribute not found, not an error as such. + * EINVAL Invalid arguments. + * EIO I/O error or corrupt data structures found. + * ENOMEM Not enough memory to allocate necessary buffers. + */ +int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const VCN lowest_vcn, const u8 *val, const u32 val_len, + ntfs_attr_search_ctx *ctx) +{ + ntfs_volume *vol; + ntfs_inode *base_ni; + int ret = -1; + + ntfs_log_enter("Entering for attribute type 0x%x\n", type); + + if (!ctx || !ctx->mrec || !ctx->attr || (name && name != AT_UNNAMED && + (!ctx->ntfs_ino || !(vol = ctx->ntfs_ino->vol) || + !vol->upcase || !vol->upcase_len))) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + goto out; + } + + if (ctx->base_ntfs_ino) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + if (!base_ni || !NInoAttrList(base_ni) || type == AT_ATTRIBUTE_LIST) + ret = ntfs_attr_find(type, name, name_len, ic, val, val_len, ctx); + else + ret = ntfs_external_attr_find(type, name, name_len, ic, + lowest_vcn, val, val_len, ctx); +out: + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_position - find given or next attribute type in an ntfs inode + * @type: attribute type to start lookup + * @ctx: search context with mft record and attribute to search from + * + * Find an attribute type in an ntfs inode or the next attribute which is not + * the AT_END attribute. Please see more details at ntfs_attr_lookup. + * + * Return 0 if the search was successful and -1 if not, with errno set to the + * error code. + * + * The following error codes are defined: + * EINVAL Invalid arguments. + * EIO I/O error or corrupt data structures found. + * ENOMEM Not enough memory to allocate necessary buffers. + * ENOSPC No attribute was found after 'type', only AT_END. + */ +int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) +{ + if (ntfs_attr_lookup(type, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (errno != ENOENT) + return -1; + if (ctx->attr->type == AT_END) { + errno = ENOSPC; + return -1; + } + } + return 0; +} + +/** + * ntfs_attr_init_search_ctx - initialize an attribute search context + * @ctx: attribute search context to initialize + * @ni: ntfs inode with which to initialize the search context + * @mrec: mft record with which to initialize the search context + * + * Initialize the attribute search context @ctx with @ni and @mrec. + */ +static void ntfs_attr_init_search_ctx(ntfs_attr_search_ctx *ctx, + ntfs_inode *ni, MFT_RECORD *mrec) +{ + if (!mrec) + mrec = ni->mrec; + ctx->mrec = mrec; + /* Sanity checks are performed elsewhere. */ + ctx->attr = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); + ctx->is_first = TRUE; + ctx->ntfs_ino = ni; + ctx->al_entry = NULL; + ctx->base_ntfs_ino = NULL; + ctx->base_mrec = NULL; + ctx->base_attr = NULL; +} + +/** + * ntfs_attr_reinit_search_ctx - reinitialize an attribute search context + * @ctx: attribute search context to reinitialize + * + * Reinitialize the attribute search context @ctx. + * + * This is used when a search for a new attribute is being started to reset + * the search context to the beginning. + */ +void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx) +{ + if (!ctx->base_ntfs_ino) { + /* No attribute list. */ + ctx->is_first = TRUE; + /* Sanity checks are performed elsewhere. */ + ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + /* + * This needs resetting due to ntfs_external_attr_find() which + * can leave it set despite having zeroed ctx->base_ntfs_ino. + */ + ctx->al_entry = NULL; + return; + } /* Attribute list. */ + ntfs_attr_init_search_ctx(ctx, ctx->base_ntfs_ino, ctx->base_mrec); + return; +} + +/** + * ntfs_attr_get_search_ctx - allocate/initialize a new attribute search context + * @ni: ntfs inode with which to initialize the search context + * @mrec: mft record with which to initialize the search context + * + * Allocate a new attribute search context, initialize it with @ni and @mrec, + * and return it. Return NULL on error with errno set. + * + * @mrec can be NULL, in which case the mft record is taken from @ni. + * + * Note: For low level utilities which know what they are doing we allow @ni to + * be NULL and @mrec to be set. Do NOT do this unless you understand the + * implications!!! For example it is no longer safe to call ntfs_attr_lookup(). + */ +ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec) +{ + ntfs_attr_search_ctx *ctx; + + if (!ni && !mrec) { + errno = EINVAL; + ntfs_log_perror("NULL arguments"); + return NULL; + } + ctx = ntfs_malloc(sizeof(ntfs_attr_search_ctx)); + if (ctx) + ntfs_attr_init_search_ctx(ctx, ni, mrec); + return ctx; +} + +/** + * ntfs_attr_put_search_ctx - release an attribute search context + * @ctx: attribute search context to free + * + * Release the attribute search context @ctx. + */ +void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx) +{ + // NOTE: save errno if it could change and function stays void! + free(ctx); +} + +/** + * ntfs_attr_find_in_attrdef - find an attribute in the $AttrDef system file + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to find + * + * Search for the attribute definition record corresponding to the attribute + * @type in the $AttrDef system file. + * + * Return the attribute type definition record if found and NULL if not found + * or an error occurred. On error the error code is stored in errno. The + * following error codes are defined: + * ENOENT - The attribute @type is not specified in $AttrDef. + * EINVAL - Invalid parameters (e.g. @vol is not valid). + */ +ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, + const ATTR_TYPES type) +{ + ATTR_DEF *ad; + + if (!vol || !vol->attrdef || !type) { + errno = EINVAL; + ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + return NULL; + } + for (ad = vol->attrdef; (u8*)ad - (u8*)vol->attrdef < + vol->attrdef_len && ad->type; ++ad) { + /* We haven't found it yet, carry on searching. */ + if (le32_to_cpu(ad->type) < le32_to_cpu(type)) + continue; + /* We found the attribute; return it. */ + if (ad->type == type) + return ad; + /* We have gone too far already. No point in continuing. */ + break; + } + errno = ENOENT; + ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + return NULL; +} + +/** + * ntfs_attr_size_bounds_check - check a size of an attribute type for validity + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to check + * @size: size which to check + * + * Check whether the @size in bytes is valid for an attribute of @type on the + * ntfs volume @vol. This information is obtained from $AttrDef system file. + * + * Return 0 if valid and -1 if not valid or an error occurred. On error the + * error code is stored in errno. The following error codes are defined: + * ERANGE - @size is not valid for the attribute @type. + * ENOENT - The attribute @type is not specified in $AttrDef. + * EINVAL - Invalid parameters (e.g. @size is < 0 or @vol is not valid). + */ +int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type, + const s64 size) +{ + ATTR_DEF *ad; + s64 min_size, max_size; + + if (size < 0) { + errno = EINVAL; + ntfs_log_perror("%s: size=%lld", __FUNCTION__, + (long long)size); + return -1; + } + + /* + * $ATTRIBUTE_LIST shouldn't be greater than 0x40000, otherwise + * Windows would crash. This is not listed in the AttrDef. + */ + if (type == AT_ATTRIBUTE_LIST && size > 0x40000) { + errno = ERANGE; + ntfs_log_perror("Too large attrlist (%lld)", (long long)size); + return -1; + } + + ad = ntfs_attr_find_in_attrdef(vol, type); + if (!ad) + return -1; + + min_size = sle64_to_cpu(ad->min_size); + max_size = sle64_to_cpu(ad->max_size); + + if ((min_size && (size < min_size)) || + ((max_size > 0) && (size > max_size))) { + errno = ERANGE; + ntfs_log_perror("Attr type %d size check failed (min,size,max=" + "%lld,%lld,%lld)", type, (long long)min_size, + (long long)size, (long long)max_size); + return -1; + } + return 0; +} + +/** + * ntfs_attr_can_be_non_resident - check if an attribute can be non-resident + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type to check + * @name: attribute name to check + * @name_len: attribute name length + * + * Check whether the attribute of @type and @name with name length @name_len on + * the ntfs volume @vol is allowed to be non-resident. This information is + * obtained from $AttrDef system file and is augmented by rules imposed by + * Microsoft (e.g. see http://support.microsoft.com/kb/974729/). + * + * Return 0 if the attribute is allowed to be non-resident and -1 if not or an + * error occurred. On error the error code is stored in errno. The following + * error codes are defined: + * EPERM - The attribute is not allowed to be non-resident. + * ENOENT - The attribute @type is not specified in $AttrDef. + * EINVAL - Invalid parameters (e.g. @vol is not valid). + */ +static int ntfs_attr_can_be_non_resident(const ntfs_volume *vol, const ATTR_TYPES type, + const ntfschar *name, int name_len) +{ + ATTR_DEF *ad; + BOOL allowed; + + /* + * Microsoft has decreed that $LOGGED_UTILITY_STREAM attributes with a + * name of $TXF_DATA must be resident despite the entry for + * $LOGGED_UTILITY_STREAM in $AttrDef allowing them to be non-resident. + * Failure to obey this on the root directory mft record of a volume + * causes Windows Vista and later to see the volume as a RAW volume and + * thus cannot mount it at all. + */ + if ((type == AT_LOGGED_UTILITY_STREAM) + && name + && ntfs_names_are_equal(TXF_DATA, 9, name, name_len, + CASE_SENSITIVE, vol->upcase, vol->upcase_len)) + allowed = FALSE; + else { + /* Find the attribute definition record in $AttrDef. */ + ad = ntfs_attr_find_in_attrdef(vol, type); + if (!ad) + return -1; + /* Check the flags and return the result. */ + allowed = !(ad->flags & ATTR_DEF_RESIDENT); + } + if (!allowed) { + errno = EPERM; + ntfs_log_trace("Attribute can't be non-resident\n"); + return -1; + } + return 0; +} + +/** + * ntfs_attr_can_be_resident - check if an attribute can be resident + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to check + * + * Check whether the attribute of @type on the ntfs volume @vol is allowed to + * be resident. This information is derived from our ntfs knowledge and may + * not be completely accurate, especially when user defined attributes are + * present. Basically we allow everything to be resident except for index + * allocation and extended attribute attributes. + * + * Return 0 if the attribute is allowed to be resident and -1 if not or an + * error occurred. On error the error code is stored in errno. The following + * error codes are defined: + * EPERM - The attribute is not allowed to be resident. + * EINVAL - Invalid parameters (e.g. @vol is not valid). + * + * Warning: In the system file $MFT the attribute $Bitmap must be non-resident + * otherwise windows will not boot (blue screen of death)! We cannot + * check for this here as we don't know which inode's $Bitmap is being + * asked about so the caller needs to special case this. + */ +int ntfs_attr_can_be_resident(const ntfs_volume *vol, const ATTR_TYPES type) +{ + if (!vol || !vol->attrdef || !type) { + errno = EINVAL; + return -1; + } + if (type != AT_INDEX_ALLOCATION) + return 0; + + ntfs_log_trace("Attribute can't be resident\n"); + errno = EPERM; + return -1; +} + +/** + * ntfs_make_room_for_attr - make room for an attribute inside an mft record + * @m: mft record + * @pos: position at which to make space + * @size: byte size to make available at this position + * + * @pos points to the attribute in front of which we want to make space. + * + * Return 0 on success or -1 on error. On error the error code is stored in + * errno. Possible error codes are: + * ENOSPC - There is not enough space available to complete operation. The + * caller has to make space before calling this. + * EINVAL - Input parameters were faulty. + */ +int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size) +{ + u32 biu; + + ntfs_log_trace("Entering for pos 0x%d, size %u.\n", + (int)(pos - (u8*)m), (unsigned) size); + + /* Make size 8-byte alignment. */ + size = (size + 7) & ~7; + + /* Rigorous consistency checks. */ + if (!m || !pos || pos < (u8*)m) { + errno = EINVAL; + ntfs_log_perror("%s: pos=%p m=%p", __FUNCTION__, pos, m); + return -1; + } + /* The -8 is for the attribute terminator. */ + if (pos - (u8*)m > (int)le32_to_cpu(m->bytes_in_use) - 8) { + errno = EINVAL; + return -1; + } + /* Nothing to do. */ + if (!size) + return 0; + + biu = le32_to_cpu(m->bytes_in_use); + /* Do we have enough space? */ + if (biu + size > le32_to_cpu(m->bytes_allocated) || + pos + size > (u8*)m + le32_to_cpu(m->bytes_allocated)) { + errno = ENOSPC; + ntfs_log_trace("No enough space in the MFT record\n"); + return -1; + } + /* Move everything after pos to pos + size. */ + memmove(pos + size, pos, biu - (pos - (u8*)m)); + /* Update mft record. */ + m->bytes_in_use = cpu_to_le32(biu + size); + return 0; +} + +/** + * ntfs_resident_attr_record_add - add resident attribute to inode + * @ni: opened ntfs inode to which MFT record add attribute + * @type: type of the new attribute + * @name: name of the new attribute + * @name_len: name length of the new attribute + * @val: value of the new attribute + * @size: size of new attribute (length of @val, if @val != NULL) + * @flags: flags of the new attribute + * + * Return offset to attribute from the beginning of the mft record on success + * and -1 on error. On error the error code is stored in errno. + * Possible error codes are: + * EINVAL - Invalid arguments passed to function. + * EEXIST - Attribute of such type and with same name already exists. + * EIO - I/O error occurred or damaged filesystem. + */ +int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, u8 *val, u32 size, + ATTR_FLAGS data_flags) +{ + ntfs_attr_search_ctx *ctx; + u32 length; + ATTR_RECORD *a; + MFT_RECORD *m; + int err, offset; + ntfs_inode *base_ni; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", + (long long) ni->mft_no, (unsigned) type, (unsigned) data_flags); + + if (!ni || (!name && name_len)) { + errno = EINVAL; + return -1; + } + + if (ntfs_attr_can_be_resident(ni->vol, type)) { + if (errno == EPERM) + ntfs_log_trace("Attribute can't be resident.\n"); + else + ntfs_log_trace("ntfs_attr_can_be_resident failed.\n"); + return -1; + } + + /* Locate place where record should be. */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + /* + * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for + * attribute in @ni->mrec, not any extent inode in case if @ni is base + * file record. + */ + if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, val, size, + ctx)) { + err = EEXIST; + ntfs_log_trace("Attribute already present.\n"); + goto put_err_out; + } + if (errno != ENOENT) { + err = EIO; + goto put_err_out; + } + a = ctx->attr; + m = ctx->mrec; + + /* Make room for attribute. */ + length = offsetof(ATTR_RECORD, resident_end) + + ((name_len * sizeof(ntfschar) + 7) & ~7) + + ((size + 7) & ~7); + if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { + err = errno; + ntfs_log_trace("Failed to make room for attribute.\n"); + goto put_err_out; + } + + /* Setup record fields. */ + offset = ((u8*)a - (u8*)m); + a->type = type; + a->length = cpu_to_le32(length); + a->non_resident = 0; + a->name_length = name_len; + a->name_offset = (name_len + ? cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) + : const_cpu_to_le16(0)); + a->flags = data_flags; + a->instance = m->next_attr_instance; + a->value_length = cpu_to_le32(size); + a->value_offset = cpu_to_le16(length - ((size + 7) & ~7)); + if (val) + memcpy((u8*)a + le16_to_cpu(a->value_offset), val, size); + else + memset((u8*)a + le16_to_cpu(a->value_offset), 0, size); + if (type == AT_FILE_NAME) + a->resident_flags = RESIDENT_ATTR_IS_INDEXED; + else + a->resident_flags = 0; + if (name_len) + memcpy((u8*)a + le16_to_cpu(a->name_offset), + name, sizeof(ntfschar) * name_len); + m->next_attr_instance = + cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); + if (ni->nr_extents == -1) + base_ni = ni->base_ni; + else + base_ni = ni; + if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { + if (ntfs_attrlist_entry_add(ni, a)) { + err = errno; + ntfs_attr_record_resize(m, a, 0); + ntfs_log_trace("Failed add attribute entry to " + "ATTRIBUTE_LIST.\n"); + goto put_err_out; + } + } + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + ? type == AT_INDEX_ROOT && name == NTFS_INDEX_I30 + : type == AT_DATA && name == AT_UNNAMED) { + ni->data_size = size; + ni->allocated_size = (size + 7) & ~7; + set_nino_flag(ni,KnownSize); + } + ntfs_inode_mark_dirty(ni); + ntfs_attr_put_search_ctx(ctx); + return offset; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_non_resident_attr_record_add - add extent of non-resident attribute + * @ni: opened ntfs inode to which MFT record add attribute + * @type: type of the new attribute extent + * @name: name of the new attribute extent + * @name_len: name length of the new attribute extent + * @lowest_vcn: lowest vcn of the new attribute extent + * @dataruns_size: dataruns size of the new attribute extent + * @flags: flags of the new attribute extent + * + * Return offset to attribute from the beginning of the mft record on success + * and -1 on error. On error the error code is stored in errno. + * Possible error codes are: + * EINVAL - Invalid arguments passed to function. + * EEXIST - Attribute of such type, with same lowest vcn and with same + * name already exists. + * EIO - I/O error occurred or damaged filesystem. + */ +int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, + ATTR_FLAGS flags) +{ + ntfs_attr_search_ctx *ctx; + u32 length; + ATTR_RECORD *a; + MFT_RECORD *m; + ntfs_inode *base_ni; + int err, offset; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " + "dataruns_size %d, flags 0x%x.\n", + (long long) ni->mft_no, (unsigned) type, + (long long) lowest_vcn, dataruns_size, (unsigned) flags); + + if (!ni || dataruns_size <= 0 || (!name && name_len)) { + errno = EINVAL; + return -1; + } + + if (ntfs_attr_can_be_non_resident(ni->vol, type, name, name_len)) { + if (errno == EPERM) + ntfs_log_perror("Attribute can't be non resident"); + else + ntfs_log_perror("ntfs_attr_can_be_non_resident failed"); + return -1; + } + + /* Locate place where record should be. */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + /* + * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for + * attribute in @ni->mrec, not any extent inode in case if @ni is base + * file record. + */ + if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, NULL, 0, + ctx)) { + err = EEXIST; + ntfs_log_perror("Attribute 0x%x already present", type); + goto put_err_out; + } + if (errno != ENOENT) { + ntfs_log_perror("ntfs_attr_find failed"); + err = EIO; + goto put_err_out; + } + a = ctx->attr; + m = ctx->mrec; + + /* Make room for attribute. */ + dataruns_size = (dataruns_size + 7) & ~7; + length = offsetof(ATTR_RECORD, compressed_size) + ((sizeof(ntfschar) * + name_len + 7) & ~7) + dataruns_size + + ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? + sizeof(a->compressed_size) : 0); + if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { + err = errno; + ntfs_log_perror("Failed to make room for attribute"); + goto put_err_out; + } + + /* Setup record fields. */ + a->type = type; + a->length = cpu_to_le32(length); + a->non_resident = 1; + a->name_length = name_len; + a->name_offset = cpu_to_le16(offsetof(ATTR_RECORD, compressed_size) + + ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? + sizeof(a->compressed_size) : 0)); + a->flags = flags; + a->instance = m->next_attr_instance; + a->lowest_vcn = cpu_to_sle64(lowest_vcn); + a->mapping_pairs_offset = cpu_to_le16(length - dataruns_size); + a->compression_unit = (flags & ATTR_IS_COMPRESSED) + ? STANDARD_COMPRESSION_UNIT : 0; + /* If @lowest_vcn == 0, than setup empty attribute. */ + if (!lowest_vcn) { + a->highest_vcn = cpu_to_sle64(-1); + a->allocated_size = 0; + a->data_size = 0; + a->initialized_size = 0; + /* Set empty mapping pairs. */ + *((u8*)a + le16_to_cpu(a->mapping_pairs_offset)) = 0; + } + if (name_len) + memcpy((u8*)a + le16_to_cpu(a->name_offset), + name, sizeof(ntfschar) * name_len); + m->next_attr_instance = + cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); + if (ni->nr_extents == -1) + base_ni = ni->base_ni; + else + base_ni = ni; + if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { + if (ntfs_attrlist_entry_add(ni, a)) { + err = errno; + ntfs_log_perror("Failed add attr entry to attrlist"); + ntfs_attr_record_resize(m, a, 0); + goto put_err_out; + } + } + ntfs_inode_mark_dirty(ni); + /* + * Locate offset from start of the MFT record where new attribute is + * placed. We need relookup it, because record maybe moved during + * update of attribute list. + */ + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, + lowest_vcn, NULL, 0, ctx)) { + ntfs_log_perror("%s: attribute lookup failed", __FUNCTION__); + ntfs_attr_put_search_ctx(ctx); + return -1; + + } + offset = (u8*)ctx->attr - (u8*)ctx->mrec; + ntfs_attr_put_search_ctx(ctx); + return offset; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_attr_record_rm - remove attribute extent + * @ctx: search context describing the attribute which should be removed + * + * If this function succeed, user should reinit search context if he/she wants + * use it anymore. + * + * Return 0 on success and -1 on error. On error the error code is stored in + * errno. Possible error codes are: + * EINVAL - Invalid arguments passed to function. + * EIO - I/O error occurred or damaged filesystem. + */ +int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) +{ + ntfs_inode *base_ni, *ni; + ATTR_TYPES type; + + if (!ctx || !ctx->ntfs_ino || !ctx->mrec || !ctx->attr) { + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) ctx->ntfs_ino->mft_no, + (unsigned) le32_to_cpu(ctx->attr->type)); + type = ctx->attr->type; + ni = ctx->ntfs_ino; + if (ctx->base_ntfs_ino) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + + /* Remove attribute itself. */ + if (ntfs_attr_record_resize(ctx->mrec, ctx->attr, 0)) { + ntfs_log_trace("Couldn't remove attribute record. Bug or damaged MFT " + "record.\n"); + if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) + if (ntfs_attrlist_entry_add(ni, ctx->attr)) + ntfs_log_trace("Rollback failed. Leaving inconstant " + "metadata.\n"); + errno = EIO; + return -1; + } + ntfs_inode_mark_dirty(ni); + + /* + * Remove record from $ATTRIBUTE_LIST if present and we don't want + * delete $ATTRIBUTE_LIST itself. + */ + if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) { + if (ntfs_attrlist_entry_rm(ctx)) { + ntfs_log_trace("Couldn't delete record from " + "$ATTRIBUTE_LIST.\n"); + return -1; + } + } + + /* Post $ATTRIBUTE_LIST delete setup. */ + if (type == AT_ATTRIBUTE_LIST) { + if (NInoAttrList(base_ni) && base_ni->attr_list) + free(base_ni->attr_list); + base_ni->attr_list = NULL; + NInoClearAttrList(base_ni); + NInoAttrListClearDirty(base_ni); + } + + /* Free MFT record, if it doesn't contain attributes. */ + if (le32_to_cpu(ctx->mrec->bytes_in_use) - + le16_to_cpu(ctx->mrec->attrs_offset) == 8) { + if (ntfs_mft_record_free(ni->vol, ni)) { + // FIXME: We need rollback here. + ntfs_log_trace("Couldn't free MFT record.\n"); + errno = EIO; + return -1; + } + /* Remove done if we freed base inode. */ + if (ni == base_ni) + return 0; + } + + if (type == AT_ATTRIBUTE_LIST || !NInoAttrList(base_ni)) + return 0; + + /* Remove attribute list if we don't need it any more. */ + if (!ntfs_attrlist_need(base_ni)) { + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + /* + * FIXME: Should we succeed here? Definitely something + * goes wrong because NInoAttrList(base_ni) returned + * that we have got attribute list. + */ + ntfs_log_trace("Couldn't find attribute list. Succeed " + "anyway.\n"); + return 0; + } + /* Deallocate clusters. */ + if (ctx->attr->non_resident) { + runlist *al_rl; + + al_rl = ntfs_mapping_pairs_decompress(base_ni->vol, + ctx->attr, NULL); + if (!al_rl) { + ntfs_log_trace("Couldn't decompress attribute list " + "runlist. Succeed anyway.\n"); + return 0; + } + if (ntfs_cluster_free_from_rl(base_ni->vol, al_rl)) { + ntfs_log_trace("Leaking clusters! Run chkdsk. " + "Couldn't free clusters from " + "attribute list runlist.\n"); + } + free(al_rl); + } + /* Remove attribute record itself. */ + if (ntfs_attr_record_rm(ctx)) { + /* + * FIXME: Should we succeed here? BTW, chkdsk doesn't + * complain if it find MFT record with attribute list, + * but without extents. + */ + ntfs_log_trace("Couldn't remove attribute list. Succeed " + "anyway.\n"); + return 0; + } + } + return 0; +} + +/** + * ntfs_attr_add - add attribute to inode + * @ni: opened ntfs inode to which add attribute + * @type: type of the new attribute + * @name: name in unicode of the new attribute + * @name_len: name length in unicode characters of the new attribute + * @val: value of new attribute + * @size: size of the new attribute / length of @val (if specified) + * + * @val should always be specified for always resident attributes (eg. FILE_NAME + * attribute), for attributes that can become non-resident @val can be NULL + * (eg. DATA attribute). @size can be specified even if @val is NULL, in this + * case data size will be equal to @size and initialized size will be equal + * to 0. + * + * If inode haven't got enough space to add attribute, add attribute to one of + * it extents, if no extents present or no one of them have enough space, than + * allocate new extent and add attribute to it. + * + * If on one of this steps attribute list is needed but not present, than it is + * added transparently to caller. So, this function should not be called with + * @type == AT_ATTRIBUTE_LIST, if you really need to add attribute list call + * ntfs_inode_add_attrlist instead. + * + * On success return 0. On error return -1 with errno set to the error code. + */ +int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, u8 *val, s64 size) +{ + u32 attr_rec_size; + int err, i, offset; + BOOL is_resident; + BOOL can_be_non_resident = FALSE; + ntfs_inode *attr_ni; + ntfs_attr *na; + ATTR_FLAGS data_flags; + + if (!ni || size < 0 || type == AT_ATTRIBUTE_LIST) { + errno = EINVAL; + ntfs_log_perror("%s: ni=%p size=%lld", __FUNCTION__, ni, + (long long)size); + return -1; + } + + ntfs_log_trace("Entering for inode %lld, attr %x, size %lld.\n", + (long long)ni->mft_no, type, (long long)size); + + if (ni->nr_extents == -1) + ni = ni->base_ni; + + /* Check the attribute type and the size. */ + if (ntfs_attr_size_bounds_check(ni->vol, type, size)) { + if (errno == ENOENT) + errno = EIO; + return -1; + } + + /* Sanity checks for always resident attributes. */ + if (ntfs_attr_can_be_non_resident(ni->vol, type, name, name_len)) { + if (errno != EPERM) { + err = errno; + ntfs_log_perror("ntfs_attr_can_be_non_resident failed"); + goto err_out; + } + /* @val is mandatory. */ + if (!val) { + errno = EINVAL; + ntfs_log_perror("val is mandatory for always resident " + "attributes"); + return -1; + } + if (size > ni->vol->mft_record_size) { + errno = ERANGE; + ntfs_log_perror("Attribute is too big"); + return -1; + } + } else + can_be_non_resident = TRUE; + + /* + * Determine resident or not will be new attribute. We add 8 to size in + * non resident case for mapping pairs. + */ + if (!ntfs_attr_can_be_resident(ni->vol, type)) { + is_resident = TRUE; + } else { + if (errno != EPERM) { + err = errno; + ntfs_log_perror("ntfs_attr_can_be_resident failed"); + goto err_out; + } + is_resident = FALSE; + } + /* Calculate attribute record size. */ + if (is_resident) + attr_rec_size = offsetof(ATTR_RECORD, resident_end) + + ((name_len * sizeof(ntfschar) + 7) & ~7) + + ((size + 7) & ~7); + else + attr_rec_size = offsetof(ATTR_RECORD, non_resident_end) + + ((name_len * sizeof(ntfschar) + 7) & ~7) + 8; + + /* + * If we have enough free space for the new attribute in the base MFT + * record, then add attribute to it. + */ + if (le32_to_cpu(ni->mrec->bytes_allocated) - + le32_to_cpu(ni->mrec->bytes_in_use) >= attr_rec_size) { + attr_ni = ni; + goto add_attr_record; + } + + /* Try to add to extent inodes. */ + if (ntfs_inode_attach_all_extents(ni)) { + err = errno; + ntfs_log_perror("Failed to attach all extents to inode"); + goto err_out; + } + for (i = 0; i < ni->nr_extents; i++) { + attr_ni = ni->extent_nis[i]; + if (le32_to_cpu(attr_ni->mrec->bytes_allocated) - + le32_to_cpu(attr_ni->mrec->bytes_in_use) >= + attr_rec_size) + goto add_attr_record; + } + + /* There is no extent that contain enough space for new attribute. */ + if (!NInoAttrList(ni)) { + /* Add attribute list not present, add it and retry. */ + if (ntfs_inode_add_attrlist(ni)) { + err = errno; + ntfs_log_perror("Failed to add attribute list"); + goto err_out; + } + return ntfs_attr_add(ni, type, name, name_len, val, size); + } + /* Allocate new extent. */ + attr_ni = ntfs_mft_record_alloc(ni->vol, ni); + if (!attr_ni) { + err = errno; + ntfs_log_perror("Failed to allocate extent record"); + goto err_out; + } + +add_attr_record: + if ((ni->flags & FILE_ATTR_COMPRESSED) + && (ni->vol->major_ver >= 3) + && NVolCompression(ni->vol) + && (ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) + && ((type == AT_DATA) + || ((type == AT_INDEX_ROOT) && (name == NTFS_INDEX_I30)))) + data_flags = ATTR_IS_COMPRESSED; + else + data_flags = const_cpu_to_le16(0); + if (is_resident) { + /* Add resident attribute. */ + offset = ntfs_resident_attr_record_add(attr_ni, type, name, + name_len, val, size, data_flags); + if (offset < 0) { + if (errno == ENOSPC && can_be_non_resident) + goto add_non_resident; + err = errno; + ntfs_log_perror("Failed to add resident attribute"); + goto free_err_out; + } + return 0; + } + +add_non_resident: + /* Add non resident attribute. */ + offset = ntfs_non_resident_attr_record_add(attr_ni, type, name, + name_len, 0, 8, data_flags); + if (offset < 0) { + err = errno; + ntfs_log_perror("Failed to add non resident attribute"); + goto free_err_out; + } + + /* If @size == 0, we are done. */ + if (!size) + return 0; + + /* Open new attribute and resize it. */ + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + err = errno; + ntfs_log_perror("Failed to open just added attribute"); + goto rm_attr_err_out; + } + /* Resize and set attribute value. */ + if (ntfs_attr_truncate(na, size) || + (val && (ntfs_attr_pwrite(na, 0, size, val) != size))) { + err = errno; + ntfs_log_perror("Failed to initialize just added attribute"); + if (ntfs_attr_rm(na)) + ntfs_log_perror("Failed to remove just added attribute"); + ntfs_attr_close(na); + goto err_out; + } + ntfs_attr_close(na); + return 0; + +rm_attr_err_out: + /* Remove just added attribute. */ + if (ntfs_attr_record_resize(attr_ni->mrec, + (ATTR_RECORD*)((u8*)attr_ni->mrec + offset), 0)) + ntfs_log_perror("Failed to remove just added attribute #2"); +free_err_out: + /* Free MFT record, if it doesn't contain attributes. */ + if (le32_to_cpu(attr_ni->mrec->bytes_in_use) - + le16_to_cpu(attr_ni->mrec->attrs_offset) == 8) + if (ntfs_mft_record_free(attr_ni->vol, attr_ni)) + ntfs_log_perror("Failed to free MFT record"); +err_out: + errno = err; + return -1; +} + +/* + * Change an attribute flag + */ + +int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask) +{ + ntfs_attr_search_ctx *ctx; + int res; + + res = -1; + /* Search for designated attribute */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (ctx) { + if (!ntfs_attr_lookup(type, name, name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + /* do the requested change (all small endian le16) */ + ctx->attr->flags = (ctx->attr->flags & ~mask) + | (flags & mask); + NInoSetDirty(ni); + res = 0; + } + ntfs_attr_put_search_ctx(ctx); + } + return (res); +} + + +/** + * ntfs_attr_rm - remove attribute from ntfs inode + * @na: opened ntfs attribute to delete + * + * Remove attribute and all it's extents from ntfs inode. If attribute was non + * resident also free all clusters allocated by attribute. + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +int ntfs_attr_rm(ntfs_attr *na) +{ + ntfs_attr_search_ctx *ctx; + int ret = 0; + + if (!na) { + ntfs_log_trace("Invalid arguments passed.\n"); + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) na->ni->mft_no, na->type); + + /* Free cluster allocation. */ + if (NAttrNonResident(na)) { + if (ntfs_attr_map_whole_runlist(na)) + return -1; + if (ntfs_cluster_free(na->ni->vol, na, 0, -1) < 0) { + ntfs_log_trace("Failed to free cluster allocation. Leaving " + "inconstant metadata.\n"); + ret = -1; + } + } + + /* Search for attribute extents and remove them all. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + while (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (ntfs_attr_record_rm(ctx)) { + ntfs_log_trace("Failed to remove attribute extent. Leaving " + "inconstant metadata.\n"); + ret = -1; + } + ntfs_attr_reinit_search_ctx(ctx); + } + ntfs_attr_put_search_ctx(ctx); + if (errno != ENOENT) { + ntfs_log_trace("Attribute lookup failed. Probably leaving inconstant " + "metadata.\n"); + ret = -1; + } + + return ret; +} + +/** + * ntfs_attr_record_resize - resize an attribute record + * @m: mft record containing attribute record + * @a: attribute record to resize + * @new_size: new size in bytes to which to resize the attribute record @a + * + * Resize the attribute record @a, i.e. the resident part of the attribute, in + * the mft record @m to @new_size bytes. + * + * Return 0 on success and -1 on error with errno set to the error code. + * The following error codes are defined: + * ENOSPC - Not enough space in the mft record @m to perform the resize. + * Note that on error no modifications have been performed whatsoever. + * + * Warning: If you make a record smaller without having copied all the data you + * are interested in the data may be overwritten! + */ +int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size) +{ + u32 old_size, alloc_size, attr_size; + + old_size = le32_to_cpu(m->bytes_in_use); + alloc_size = le32_to_cpu(m->bytes_allocated); + attr_size = le32_to_cpu(a->length); + + ntfs_log_trace("Sizes: old=%u alloc=%u attr=%u new=%u\n", + (unsigned)old_size, (unsigned)alloc_size, + (unsigned)attr_size, (unsigned)new_size); + + /* Align to 8 bytes, just in case the caller hasn't. */ + new_size = (new_size + 7) & ~7; + + /* If the actual attribute length has changed, move things around. */ + if (new_size != attr_size) { + + u32 new_muse = old_size - attr_size + new_size; + + /* Not enough space in this mft record. */ + if (new_muse > alloc_size) { + errno = ENOSPC; + ntfs_log_trace("Not enough space in the MFT record " + "(%u > %u)\n", new_muse, alloc_size); + return -1; + } + + if (a->type == AT_INDEX_ROOT && new_size > attr_size && + new_muse + 120 > alloc_size && old_size + 120 <= alloc_size) { + errno = ENOSPC; + ntfs_log_trace("Too big INDEX_ROOT (%u > %u)\n", + new_muse, alloc_size); + return STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT; + } + + /* Move attributes following @a to their new location. */ + memmove((u8 *)a + new_size, (u8 *)a + attr_size, + old_size - ((u8 *)a - (u8 *)m) - attr_size); + + /* Adjust @m to reflect the change in used space. */ + m->bytes_in_use = cpu_to_le32(new_muse); + + /* Adjust @a to reflect the new size. */ + if (new_size >= offsetof(ATTR_REC, length) + sizeof(a->length)) + a->length = cpu_to_le32(new_size); + } + return 0; +} + +/** + * ntfs_resident_attr_value_resize - resize the value of a resident attribute + * @m: mft record containing attribute record + * @a: attribute record whose value to resize + * @new_size: new size in bytes to which to resize the attribute value of @a + * + * Resize the value of the attribute @a in the mft record @m to @new_size bytes. + * If the value is made bigger, the newly "allocated" space is cleared. + * + * Return 0 on success and -1 on error with errno set to the error code. + * The following error codes are defined: + * ENOSPC - Not enough space in the mft record @m to perform the resize. + * Note that on error no modifications have been performed whatsoever. + */ +int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, + const u32 new_size) +{ + int ret; + + ntfs_log_trace("Entering for new size %u.\n", (unsigned)new_size); + + /* Resize the resident part of the attribute record. */ + if ((ret = ntfs_attr_record_resize(m, a, (le16_to_cpu(a->value_offset) + + new_size + 7) & ~7)) < 0) + return ret; + /* + * If we made the attribute value bigger, clear the area between the + * old size and @new_size. + */ + if (new_size > le32_to_cpu(a->value_length)) + memset((u8*)a + le16_to_cpu(a->value_offset) + + le32_to_cpu(a->value_length), 0, new_size - + le32_to_cpu(a->value_length)); + /* Finally update the length of the attribute value. */ + a->value_length = cpu_to_le32(new_size); + return 0; +} + +/** + * ntfs_attr_record_move_to - move attribute record to target inode + * @ctx: attribute search context describing the attribute record + * @ni: opened ntfs inode to which move attribute record + * + * If this function succeed, user should reinit search context if he/she wants + * use it anymore. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) +{ + ntfs_attr_search_ctx *nctx; + ATTR_RECORD *a; + int err; + + if (!ctx || !ctx->attr || !ctx->ntfs_ino || !ni) { + ntfs_log_trace("Invalid arguments passed.\n"); + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for ctx->attr->type 0x%x, ctx->ntfs_ino->mft_no " + "0x%llx, ni->mft_no 0x%llx.\n", + (unsigned) le32_to_cpu(ctx->attr->type), + (long long) ctx->ntfs_ino->mft_no, + (long long) ni->mft_no); + + if (ctx->ntfs_ino == ni) + return 0; + + if (!ctx->al_entry) { + ntfs_log_trace("Inode should contain attribute list to use this " + "function.\n"); + errno = EINVAL; + return -1; + } + + /* Find place in MFT record where attribute will be moved. */ + a = ctx->attr; + nctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!nctx) + return -1; + + /* + * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for + * attribute in @ni->mrec, not any extent inode in case if @ni is base + * file record. + */ + if (!ntfs_attr_find(a->type, (ntfschar*)((u8*)a + le16_to_cpu( + a->name_offset)), a->name_length, CASE_SENSITIVE, NULL, + 0, nctx)) { + ntfs_log_trace("Attribute of such type, with same name already " + "present in this MFT record.\n"); + err = EEXIST; + goto put_err_out; + } + if (errno != ENOENT) { + err = errno; + ntfs_log_debug("Attribute lookup failed.\n"); + goto put_err_out; + } + + /* Make space and move attribute. */ + if (ntfs_make_room_for_attr(ni->mrec, (u8*) nctx->attr, + le32_to_cpu(a->length))) { + err = errno; + ntfs_log_trace("Couldn't make space for attribute.\n"); + goto put_err_out; + } + memcpy(nctx->attr, a, le32_to_cpu(a->length)); + nctx->attr->instance = nctx->mrec->next_attr_instance; + nctx->mrec->next_attr_instance = cpu_to_le16( + (le16_to_cpu(nctx->mrec->next_attr_instance) + 1) & 0xffff); + ntfs_attr_record_resize(ctx->mrec, a, 0); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_inode_mark_dirty(ni); + + /* Update attribute list. */ + ctx->al_entry->mft_reference = + MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); + ctx->al_entry->instance = nctx->attr->instance; + ntfs_attrlist_mark_dirty(ni); + + ntfs_attr_put_search_ctx(nctx); + return 0; +put_err_out: + ntfs_attr_put_search_ctx(nctx); + errno = err; + return -1; +} + +/** + * ntfs_attr_record_move_away - move away attribute record from it's mft record + * @ctx: attribute search context describing the attribute record + * @extra: minimum amount of free space in the new holder of record + * + * New attribute record holder must have free @extra bytes after moving + * attribute record to it. + * + * If this function succeed, user should reinit search context if he/she wants + * use it anymore. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra) +{ + ntfs_inode *base_ni, *ni; + MFT_RECORD *m; + int i; + + if (!ctx || !ctx->attr || !ctx->ntfs_ino || extra < 0) { + errno = EINVAL; + ntfs_log_perror("%s: ctx=%p ctx->attr=%p extra=%d", __FUNCTION__, + ctx, ctx ? ctx->attr : NULL, extra); + return -1; + } + + ntfs_log_trace("Entering for attr 0x%x, inode %llu\n", + (unsigned) le32_to_cpu(ctx->attr->type), + (unsigned long long)ctx->ntfs_ino->mft_no); + + if (ctx->ntfs_ino->nr_extents == -1) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + + if (!NInoAttrList(base_ni)) { + errno = EINVAL; + ntfs_log_perror("Inode %llu has no attrlist", + (unsigned long long)base_ni->mft_no); + return -1; + } + + if (ntfs_inode_attach_all_extents(ctx->ntfs_ino)) { + ntfs_log_perror("Couldn't attach extents, inode=%llu", + (unsigned long long)base_ni->mft_no); + return -1; + } + + /* Walk through all extents and try to move attribute to them. */ + for (i = 0; i < base_ni->nr_extents; i++) { + ni = base_ni->extent_nis[i]; + m = ni->mrec; + + if (ctx->ntfs_ino->mft_no == ni->mft_no) + continue; + + if (le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use) < + le32_to_cpu(ctx->attr->length) + extra) + continue; + + /* + * ntfs_attr_record_move_to can fail if extent with other lowest + * VCN already present in inode we trying move record to. So, + * do not return error. + */ + if (!ntfs_attr_record_move_to(ctx, ni)) + return 0; + } + + /* + * Failed to move attribute to one of the current extents, so allocate + * new extent and move attribute to it. + */ + ni = ntfs_mft_record_alloc(base_ni->vol, base_ni); + if (!ni) { + ntfs_log_perror("Couldn't allocate MFT record"); + return -1; + } + if (ntfs_attr_record_move_to(ctx, ni)) { + ntfs_log_perror("Couldn't move attribute to MFT record"); + return -1; + } + return 0; +} + +/** + * ntfs_attr_make_non_resident - convert a resident to a non-resident attribute + * @na: open ntfs attribute to make non-resident + * @ctx: ntfs search context describing the attribute + * + * Convert a resident ntfs attribute to a non-resident one. + * + * Return 0 on success and -1 on error with errno set to the error code. The + * following error codes are defined: + * EPERM - The attribute is not allowed to be non-resident. + * TODO: others... + * + * NOTE to self: No changes in the attribute list are required to move from + * a resident to a non-resident attribute. + * + * Warning: We do not set the inode dirty and we do not write out anything! + * We expect the caller to do this as this is a fairly low level + * function and it is likely there will be further changes made. + */ +int ntfs_attr_make_non_resident(ntfs_attr *na, + ntfs_attr_search_ctx *ctx) +{ + s64 new_allocated_size, bw; + ntfs_volume *vol = na->ni->vol; + ATTR_REC *a = ctx->attr; + runlist *rl; + int mp_size, mp_ofs, name_ofs, arec_size, err; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); + + /* Some preliminary sanity checking. */ + if (NAttrNonResident(na)) { + ntfs_log_trace("Eeek! Trying to make non-resident attribute " + "non-resident. Aborting...\n"); + errno = EINVAL; + return -1; + } + + /* Check that the attribute is allowed to be non-resident. */ + if (ntfs_attr_can_be_non_resident(vol, na->type, na->name, na->name_len)) + return -1; + + new_allocated_size = (le32_to_cpu(a->value_length) + vol->cluster_size + - 1) & ~(vol->cluster_size - 1); + + if (new_allocated_size > 0) { + if ((a->flags & ATTR_COMPRESSION_MASK) + == ATTR_IS_COMPRESSED) { + /* must allocate full compression blocks */ + new_allocated_size = ((new_allocated_size - 1) + | ((1L << (STANDARD_COMPRESSION_UNIT + + vol->cluster_size_bits)) - 1)) + 1; + } + /* Start by allocating clusters to hold the attribute value. */ + rl = ntfs_cluster_alloc(vol, 0, new_allocated_size >> + vol->cluster_size_bits, -1, DATA_ZONE); + if (!rl) + return -1; + } else + rl = NULL; + /* + * Setup the in-memory attribute structure to be non-resident so that + * we can use ntfs_attr_pwrite(). + */ + NAttrSetNonResident(na); + NAttrSetBeingNonResident(na); + na->rl = rl; + na->allocated_size = new_allocated_size; + na->data_size = na->initialized_size = le32_to_cpu(a->value_length); + /* + * FIXME: For now just clear all of these as we don't support them when + * writing. + */ + NAttrClearSparse(na); + NAttrClearEncrypted(na); + if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { + /* set compression writing parameters */ + na->compression_block_size + = 1 << (STANDARD_COMPRESSION_UNIT + vol->cluster_size_bits); + na->compression_block_clusters = 1 << STANDARD_COMPRESSION_UNIT; + } + + if (rl) { + /* Now copy the attribute value to the allocated cluster(s). */ + bw = ntfs_attr_pwrite(na, 0, le32_to_cpu(a->value_length), + (u8*)a + le16_to_cpu(a->value_offset)); + if (bw != le32_to_cpu(a->value_length)) { + err = errno; + ntfs_log_debug("Eeek! Failed to write out attribute value " + "(bw = %lli, errno = %i). " + "Aborting...\n", (long long)bw, err); + if (bw >= 0) + err = EIO; + goto cluster_free_err_out; + } + } + /* Determine the size of the mapping pairs array. */ + mp_size = ntfs_get_size_for_mapping_pairs(vol, rl, 0, INT_MAX); + if (mp_size < 0) { + err = errno; + ntfs_log_debug("Eeek! Failed to get size for mapping pairs array. " + "Aborting...\n"); + goto cluster_free_err_out; + } + /* Calculate new offsets for the name and the mapping pairs array. */ + if (na->ni->flags & FILE_ATTR_COMPRESSED) + name_ofs = (sizeof(ATTR_REC) + 7) & ~7; + else + name_ofs = (sizeof(ATTR_REC) - sizeof(a->compressed_size) + 7) & ~7; + mp_ofs = (name_ofs + a->name_length * sizeof(ntfschar) + 7) & ~7; + /* + * Determine the size of the resident part of the non-resident + * attribute record. (Not compressed thus no compressed_size element + * present.) + */ + arec_size = (mp_ofs + mp_size + 7) & ~7; + + /* Resize the resident part of the attribute record. */ + if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { + err = errno; + goto cluster_free_err_out; + } + + /* + * Convert the resident part of the attribute record to describe a + * non-resident attribute. + */ + a->non_resident = 1; + + /* Move the attribute name if it exists and update the offset. */ + if (a->name_length) + memmove((u8*)a + name_ofs, (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + a->name_offset = cpu_to_le16(name_ofs); + + /* Setup the fields specific to non-resident attributes. */ + a->lowest_vcn = cpu_to_sle64(0); + a->highest_vcn = cpu_to_sle64((new_allocated_size - 1) >> + vol->cluster_size_bits); + + a->mapping_pairs_offset = cpu_to_le16(mp_ofs); + + /* + * Update the flags to match the in-memory ones. + * However cannot change the compression state if we had + * a fuse_file_info open with a mark for release. + * The decisions about compression can only be made when + * creating/recreating the stream, not when making non resident. + */ + a->flags &= ~(ATTR_IS_SPARSE | ATTR_IS_ENCRYPTED); + if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { + /* support only ATTR_IS_COMPRESSED compression mode */ + a->compression_unit = STANDARD_COMPRESSION_UNIT; + a->compressed_size = const_cpu_to_le64(0); + } else { + a->compression_unit = 0; + a->flags &= ~ATTR_COMPRESSION_MASK; + na->data_flags = a->flags; + } + + memset(&a->reserved1, 0, sizeof(a->reserved1)); + + a->allocated_size = cpu_to_sle64(new_allocated_size); + a->data_size = a->initialized_size = cpu_to_sle64(na->data_size); + + /* Generate the mapping pairs array in the attribute record. */ + if (ntfs_mapping_pairs_build(vol, (u8*)a + mp_ofs, arec_size - mp_ofs, + rl, 0, NULL) < 0) { + // FIXME: Eeek! We need rollback! (AIA) + ntfs_log_trace("Eeek! Failed to build mapping pairs. Leaving " + "corrupt attribute record on disk. In memory " + "runlist is still intact! Error code is %i. " + "FIXME: Need to rollback instead!\n", errno); + return -1; + } + + /* Done! */ + return 0; + +cluster_free_err_out: + if (rl && ntfs_cluster_free(vol, na, 0, -1) < 0) + ntfs_log_trace("Eeek! Failed to release allocated clusters in error " + "code path. Leaving inconsistent metadata...\n"); + NAttrClearNonResident(na); + na->allocated_size = na->data_size; + na->rl = NULL; + free(rl); + errno = err; + return -1; +} + + +static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize); + +/** + * ntfs_resident_attr_resize - resize a resident, open ntfs attribute + * @na: resident ntfs attribute to resize + * @newsize: new size (in bytes) to which to resize the attribute + * + * Change the size of a resident, open ntfs attribute @na to @newsize bytes. + * Can also be used to force an attribute non-resident. In this case, the + * size cannot be changed. + * + * On success return 0 + * On error return values are: + * STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT + * STATUS_ERROR - otherwise + * The following error codes are defined: + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + */ +static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize, + BOOL force_non_resident) +{ + ntfs_attr_search_ctx *ctx; + ntfs_volume *vol; + ntfs_inode *ni; + int err, ret = STATUS_ERROR; + + ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize); + + /* Get the attribute record that needs modification. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, + ctx)) { + err = errno; + ntfs_log_perror("ntfs_attr_lookup failed"); + goto put_err_out; + } + vol = na->ni->vol; + /* + * Check the attribute type and the corresponding minimum and maximum + * sizes against @newsize and fail if @newsize is out of bounds. + */ + if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { + err = errno; + if (err == ENOENT) + err = EIO; + ntfs_log_perror("%s: bounds check failed", __FUNCTION__); + goto put_err_out; + } + /* + * If @newsize is bigger than the mft record we need to make the + * attribute non-resident if the attribute type supports it. If it is + * smaller we can go ahead and attempt the resize. + */ + if ((newsize < vol->mft_record_size) && !force_non_resident) { + /* Perform the resize of the attribute record. */ + if (!(ret = ntfs_resident_attr_value_resize(ctx->mrec, ctx->attr, + newsize))) { + /* Update attribute size everywhere. */ + na->data_size = na->initialized_size = newsize; + na->allocated_size = (newsize + 7) & ~7; + if ((na->data_flags & ATTR_COMPRESSION_MASK) + || NAttrSparse(na)) + na->compressed_size = na->allocated_size; + if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + ? na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30 + : na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + if (((na->data_flags & ATTR_COMPRESSION_MASK) + || NAttrSparse(na)) + && NAttrNonResident(na)) + na->ni->allocated_size + = na->compressed_size; + else + na->ni->allocated_size + = na->allocated_size; + set_nino_flag(na->ni,KnownSize); + if (na->type == AT_DATA) + NInoFileNameSetDirty(na->ni); + } + goto resize_done; + } + /* Prefer AT_INDEX_ALLOCATION instead of AT_ATTRIBUTE_LIST */ + if (ret == STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT) { + err = errno; + goto put_err_out; + } + } + /* There is not enough space in the mft record to perform the resize. */ + + /* Make the attribute non-resident if possible. */ + if (!ntfs_attr_make_non_resident(na, ctx)) { + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + /* + * do not truncate when forcing non-resident, this + * could cause the attribute to be made resident again, + * so size changes are not allowed. + */ + if (force_non_resident) { + ret = 0; + if (newsize != na->data_size) { + ntfs_log_error("Cannot change size when" + " forcing non-resident\n"); + errno = EIO; + ret = STATUS_ERROR; + } + return (ret); + } + /* Resize non-resident attribute */ + return ntfs_attr_truncate(na, newsize); + } else if (errno != ENOSPC && errno != EPERM) { + err = errno; + ntfs_log_perror("Failed to make attribute non-resident"); + goto put_err_out; + } + + /* Try to make other attributes non-resident and retry each time. */ + ntfs_attr_init_search_ctx(ctx, NULL, na->ni->mrec); + while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { + ntfs_attr *tna; + ATTR_RECORD *a; + + a = ctx->attr; + if (a->non_resident) + continue; + + /* + * Check out whether convert is reasonable. Assume that mapping + * pairs will take 8 bytes. + */ + if (le32_to_cpu(a->length) <= offsetof(ATTR_RECORD, + compressed_size) + ((a->name_length * + sizeof(ntfschar) + 7) & ~7) + 8) + continue; + + tna = ntfs_attr_open(na->ni, a->type, (ntfschar*)((u8*)a + + le16_to_cpu(a->name_offset)), a->name_length); + if (!tna) { + err = errno; + ntfs_log_perror("Couldn't open attribute"); + goto put_err_out; + } + if (ntfs_attr_make_non_resident(tna, ctx)) { + ntfs_attr_close(tna); + continue; + } + if (((tna->data_flags & ATTR_COMPRESSION_MASK) + == ATTR_IS_COMPRESSED) + && ntfs_attr_pclose(tna)) { + err = errno; + ntfs_attr_close(tna); + goto put_err_out; + } + ntfs_inode_mark_dirty(tna->ni); + ntfs_attr_close(tna); + ntfs_attr_put_search_ctx(ctx); + return ntfs_resident_attr_resize_i(na, newsize, force_non_resident); + } + /* Check whether error occurred. */ + if (errno != ENOENT) { + err = errno; + ntfs_log_perror("%s: Attribute lookup failed 1", __FUNCTION__); + goto put_err_out; + } + + /* + * The standard information and attribute list attributes can't be + * moved out from the base MFT record, so try to move out others. + */ + if (na->type==AT_STANDARD_INFORMATION || na->type==AT_ATTRIBUTE_LIST) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_free_space(na->ni, offsetof(ATTR_RECORD, + non_resident_end) + 8)) { + ntfs_log_perror("Could not free space in MFT record"); + return -1; + } + return ntfs_resident_attr_resize_i(na, newsize, force_non_resident); + } + + /* + * Move the attribute to a new mft record, creating an attribute list + * attribute or modifying it if it is already present. + */ + + /* Point search context back to attribute which we need resize. */ + ntfs_attr_init_search_ctx(ctx, na->ni, NULL); + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + ntfs_log_perror("%s: Attribute lookup failed 2", __FUNCTION__); + err = errno; + goto put_err_out; + } + + /* + * Check whether attribute is already single in this MFT record. + * 8 added for the attribute terminator. + */ + if (le32_to_cpu(ctx->mrec->bytes_in_use) == + le16_to_cpu(ctx->mrec->attrs_offset) + + le32_to_cpu(ctx->attr->length) + 8) { + err = ENOSPC; + ntfs_log_trace("MFT record is filled with one attribute\n"); + ret = STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT; + goto put_err_out; + } + + /* Add attribute list if not present. */ + if (na->ni->nr_extents == -1) + ni = na->ni->base_ni; + else + ni = na->ni; + if (!NInoAttrList(ni)) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_add_attrlist(ni)) + return -1; + return ntfs_resident_attr_resize_i(na, newsize, force_non_resident); + } + /* Allocate new mft record. */ + ni = ntfs_mft_record_alloc(vol, ni); + if (!ni) { + err = errno; + ntfs_log_perror("Couldn't allocate new MFT record"); + goto put_err_out; + } + /* Move attribute to it. */ + if (ntfs_attr_record_move_to(ctx, ni)) { + err = errno; + ntfs_log_perror("Couldn't move attribute to new MFT record"); + goto put_err_out; + } + /* Update ntfs attribute. */ + if (na->ni->nr_extents == -1) + na->ni = ni; + + ntfs_attr_put_search_ctx(ctx); + /* Try to perform resize once again. */ + return ntfs_resident_attr_resize_i(na, newsize, force_non_resident); + +resize_done: + /* + * Set the inode (and its base inode if it exists) dirty so it is + * written out later. + */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + return 0; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return ret; +} + +static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_resident_attr_resize_i(na, newsize, FALSE); + ntfs_log_leave("\n"); + return ret; +} + +/* + * Force an attribute to be made non-resident without + * changing its size. + * + * This is particularly needed when the attribute has no data, + * as the non-resident variant requires more space in the MFT + * record, and may imply expelling some other attribute. + * + * As a consequence the existing ntfs_attr_search_ctx's have to + * be closed or reinitialized. + * + * returns 0 if successful, + * < 0 if failed, with errno telling why + */ + +int ntfs_attr_force_non_resident(ntfs_attr *na) +{ + int res; + + res = ntfs_resident_attr_resize_i(na, na->data_size, TRUE); + if (!res && !NAttrNonResident(na)) { + res = -1; + errno = EIO; + ntfs_log_error("Failed to force non-resident\n"); + } + return (res); +} + +/** + * ntfs_attr_make_resident - convert a non-resident to a resident attribute + * @na: open ntfs attribute to make resident + * @ctx: ntfs search context describing the attribute + * + * Convert a non-resident ntfs attribute to a resident one. + * + * Return 0 on success and -1 on error with errno set to the error code. The + * following error codes are defined: + * EINVAL - Invalid arguments passed. + * EPERM - The attribute is not allowed to be resident. + * EIO - I/O error, damaged inode or bug. + * ENOSPC - There is no enough space to perform conversion. + * EOPNOTSUPP - Requested conversion is not supported yet. + * + * Warning: We do not set the inode dirty and we do not write out anything! + * We expect the caller to do this as this is a fairly low level + * function and it is likely there will be further changes made. + */ +static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) +{ + ntfs_volume *vol = na->ni->vol; + ATTR_REC *a = ctx->attr; + int name_ofs, val_ofs, err = EIO; + s64 arec_size, bytes_read; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); + + /* Should be called for the first extent of the attribute. */ + if (sle64_to_cpu(a->lowest_vcn)) { + ntfs_log_trace("Eeek! Should be called for the first extent of the " + "attribute. Aborting...\n"); + errno = EINVAL; + return -1; + } + + /* Some preliminary sanity checking. */ + if (!NAttrNonResident(na)) { + ntfs_log_trace("Eeek! Trying to make resident attribute resident. " + "Aborting...\n"); + errno = EINVAL; + return -1; + } + + /* Make sure this is not $MFT/$BITMAP or Windows will not boot! */ + if (na->type == AT_BITMAP && na->ni->mft_no == FILE_MFT) { + errno = EPERM; + return -1; + } + + /* Check that the attribute is allowed to be resident. */ + if (ntfs_attr_can_be_resident(vol, na->type)) + return -1; + + if (na->data_flags & ATTR_IS_ENCRYPTED) { + ntfs_log_trace("Making encrypted streams resident is not " + "implemented yet.\n"); + errno = EOPNOTSUPP; + return -1; + } + + /* Work out offsets into and size of the resident attribute. */ + name_ofs = 24; /* = sizeof(resident_ATTR_REC); */ + val_ofs = (name_ofs + a->name_length * sizeof(ntfschar) + 7) & ~7; + arec_size = (val_ofs + na->data_size + 7) & ~7; + + /* Sanity check the size before we start modifying the attribute. */ + if (le32_to_cpu(ctx->mrec->bytes_in_use) - le32_to_cpu(a->length) + + arec_size > le32_to_cpu(ctx->mrec->bytes_allocated)) { + errno = ENOSPC; + ntfs_log_trace("Not enough space to make attribute resident\n"); + return -1; + } + + /* Read and cache the whole runlist if not already done. */ + if (ntfs_attr_map_whole_runlist(na)) + return -1; + + /* Move the attribute name if it exists and update the offset. */ + if (a->name_length) { + memmove((u8*)a + name_ofs, (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + } + a->name_offset = cpu_to_le16(name_ofs); + + /* Resize the resident part of the attribute record. */ + if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { + /* + * Bug, because ntfs_attr_record_resize should not fail (we + * already checked that attribute fits MFT record). + */ + ntfs_log_error("BUG! Failed to resize attribute record. " + "Please report to the %s. Aborting...\n", + NTFS_DEV_LIST); + errno = EIO; + return -1; + } + + /* Convert the attribute record to describe a resident attribute. */ + a->non_resident = 0; + a->flags = 0; + a->value_length = cpu_to_le32(na->data_size); + a->value_offset = cpu_to_le16(val_ofs); + /* + * If a data stream was wiped out, adjust the compression mode + * to current state of compression flag + */ + if (!na->data_size + && (na->type == AT_DATA) + && (na->ni->vol->major_ver >= 3) + && NVolCompression(na->ni->vol) + && (na->ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) + && (na->ni->flags & FILE_ATTR_COMPRESSED)) { + a->flags |= ATTR_IS_COMPRESSED; + na->data_flags = a->flags; + } + /* + * File names cannot be non-resident so we would never see this here + * but at least it serves as a reminder that there may be attributes + * for which we do need to set this flag. (AIA) + */ + if (a->type == AT_FILE_NAME) + a->resident_flags = RESIDENT_ATTR_IS_INDEXED; + else + a->resident_flags = 0; + a->reservedR = 0; + + /* Sanity fixup... Shouldn't really happen. (AIA) */ + if (na->initialized_size > na->data_size) + na->initialized_size = na->data_size; + + /* Copy data from run list to resident attribute value. */ + bytes_read = ntfs_rl_pread(vol, na->rl, 0, na->initialized_size, + (u8*)a + val_ofs); + if (bytes_read != na->initialized_size) { + if (bytes_read < 0) + err = errno; + ntfs_log_trace("Eeek! Failed to read attribute data. Leaving " + "inconstant metadata. Run chkdsk. " + "Aborting...\n"); + errno = err; + return -1; + } + + /* Clear memory in gap between initialized_size and data_size. */ + if (na->initialized_size < na->data_size) + memset((u8*)a + val_ofs + na->initialized_size, 0, + na->data_size - na->initialized_size); + + /* + * Deallocate clusters from the runlist. + * + * NOTE: We can use ntfs_cluster_free() because we have already mapped + * the whole run list and thus it doesn't matter that the attribute + * record is in a transiently corrupted state at this moment in time. + */ + if (ntfs_cluster_free(vol, na, 0, -1) < 0) { + err = errno; + ntfs_log_perror("Eeek! Failed to release allocated clusters"); + ntfs_log_trace("Ignoring error and leaving behind wasted " + "clusters.\n"); + } + + /* Throw away the now unused runlist. */ + free(na->rl); + na->rl = NULL; + + /* Update in-memory struct ntfs_attr. */ + NAttrClearNonResident(na); + NAttrClearSparse(na); + NAttrClearEncrypted(na); + na->initialized_size = na->data_size; + na->allocated_size = na->compressed_size = (na->data_size + 7) & ~7; + na->compression_block_size = 0; + na->compression_block_size_bits = na->compression_block_clusters = 0; + return 0; +} + +/* + * If we are in the first extent, then set/clean sparse bit, + * update allocated and compressed size. + */ +static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, + ntfs_attr_search_ctx *ctx) +{ + int sparse, ret = 0; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x\n", + (unsigned long long)na->ni->mft_no, na->type); + + if (a->lowest_vcn) + goto out; + + a->allocated_size = cpu_to_sle64(na->allocated_size); + + /* Update sparse bit. */ + sparse = ntfs_rl_sparse(na->rl); + if (sparse == -1) { + errno = EIO; + goto error; + } + + /* Attribute become sparse. */ + if (sparse && !(a->flags & (ATTR_IS_SPARSE | ATTR_IS_COMPRESSED))) { + /* + * Move attribute to another mft record, if attribute is too + * small to add compressed_size field to it and we have no + * free space in the current mft record. + */ + if ((le32_to_cpu(a->length) - + le16_to_cpu(a->mapping_pairs_offset) == 8) + && !(le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use))) { + + if (!NInoAttrList(na->ni)) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_add_attrlist(na->ni)) + goto leave; + goto retry; + } + if (ntfs_attr_record_move_away(ctx, 8)) { + ntfs_log_perror("Failed to move attribute"); + goto error; + } + ntfs_attr_put_search_ctx(ctx); + goto retry; + } + if (!(le32_to_cpu(a->length) - le16_to_cpu( + a->mapping_pairs_offset))) { + errno = EIO; + ntfs_log_perror("Mapping pairs space is 0"); + goto error; + } + + NAttrSetSparse(na); + a->flags |= ATTR_IS_SPARSE; + a->compression_unit = STANDARD_COMPRESSION_UNIT; /* Windows + set it so, even if attribute is not actually compressed. */ + + memmove((u8*)a + le16_to_cpu(a->name_offset) + 8, + (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + + a->name_offset = cpu_to_le16(le16_to_cpu(a->name_offset) + 8); + + a->mapping_pairs_offset = + cpu_to_le16(le16_to_cpu(a->mapping_pairs_offset) + 8); + } + + /* Attribute no longer sparse. */ + if (!sparse && (a->flags & ATTR_IS_SPARSE) && + !(a->flags & ATTR_IS_COMPRESSED)) { + + NAttrClearSparse(na); + a->flags &= ~ATTR_IS_SPARSE; + a->compression_unit = 0; + + memmove((u8*)a + le16_to_cpu(a->name_offset) - 8, + (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + + if (le16_to_cpu(a->name_offset) >= 8) + a->name_offset = cpu_to_le16(le16_to_cpu(a->name_offset) - 8); + + a->mapping_pairs_offset = + cpu_to_le16(le16_to_cpu(a->mapping_pairs_offset) - 8); + } + + /* Update compressed size if required. */ + if (sparse || (na->data_flags & ATTR_COMPRESSION_MASK)) { + s64 new_compr_size; + + new_compr_size = ntfs_rl_get_compressed_size(na->ni->vol, na->rl); + if (new_compr_size == -1) + goto error; + + na->compressed_size = new_compr_size; + a->compressed_size = cpu_to_sle64(new_compr_size); + } + /* + * Set FILE_NAME dirty flag, to update sparse bit and + * allocated size in the index. + */ + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + if (sparse || (na->data_flags & ATTR_COMPRESSION_MASK)) + na->ni->allocated_size = na->compressed_size; + else + na->ni->allocated_size = na->allocated_size; + NInoFileNameSetDirty(na->ni); + } +out: + return ret; +leave: ret = -1; goto out; /* return -1 */ +retry: ret = -2; goto out; +error: ret = -3; goto out; +} + +#define NTFS_VCN_DELETE_MARK -2 +/** + * ntfs_attr_update_mapping_pairs_i - see ntfs_attr_update_mapping_pairs + */ +static int ntfs_attr_update_mapping_pairs_i(ntfs_attr *na, VCN from_vcn) +{ + ntfs_attr_search_ctx *ctx; + ntfs_inode *ni, *base_ni; + MFT_RECORD *m; + ATTR_RECORD *a; + VCN stop_vcn; + const runlist_element *stop_rl; + int err, mp_size, cur_max_mp_size, exp_max_mp_size, ret = -1; + BOOL finished_build; + BOOL first_updated = FALSE; + +retry: + if (!na || !na->rl) { + errno = EINVAL; + ntfs_log_perror("%s: na=%p", __FUNCTION__, na); + return -1; + } + + ntfs_log_trace("Entering for inode %llu, attr 0x%x\n", + (unsigned long long)na->ni->mft_no, na->type); + + if (!NAttrNonResident(na)) { + errno = EINVAL; + ntfs_log_perror("%s: resident attribute", __FUNCTION__); + return -1; + } + + if (na->ni->nr_extents == -1) + base_ni = na->ni->base_ni; + else + base_ni = na->ni; + + ctx = ntfs_attr_get_search_ctx(base_ni, NULL); + if (!ctx) + return -1; + + /* Fill attribute records with new mapping pairs. */ + stop_vcn = 0; + stop_rl = na->rl; + finished_build = FALSE; + while (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, from_vcn, NULL, 0, ctx)) { + a = ctx->attr; + m = ctx->mrec; + if (!a->lowest_vcn) + first_updated = TRUE; + /* + * If runlist is updating not from the beginning, then set + * @stop_vcn properly, i.e. to the lowest vcn of record that + * contain @from_vcn. Also we do not need @from_vcn anymore, + * set it to 0 to make ntfs_attr_lookup enumerate attributes. + */ + if (from_vcn) { + LCN first_lcn; + + stop_vcn = sle64_to_cpu(a->lowest_vcn); + from_vcn = 0; + /* + * Check whether the first run we need to update is + * the last run in runlist, if so, then deallocate + * all attrubute extents starting this one. + */ + first_lcn = ntfs_rl_vcn_to_lcn(na->rl, stop_vcn); + if (first_lcn == LCN_EINVAL) { + errno = EIO; + ntfs_log_perror("Bad runlist"); + goto put_err_out; + } + if (first_lcn == LCN_ENOENT || + first_lcn == LCN_RL_NOT_MAPPED) + finished_build = TRUE; + } + + /* + * Check whether we finished mapping pairs build, if so mark + * extent as need to delete (by setting highest vcn to + * NTFS_VCN_DELETE_MARK (-2), we shall check it later and + * delete extent) and continue search. + */ + if (finished_build) { + ntfs_log_trace("Mark attr 0x%x for delete in inode " + "%lld.\n", (unsigned)le32_to_cpu(a->type), + (long long)ctx->ntfs_ino->mft_no); + a->highest_vcn = cpu_to_sle64(NTFS_VCN_DELETE_MARK); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + continue; + } + + switch (ntfs_attr_update_meta(a, na, m, ctx)) { + case -1: return -1; + case -2: goto retry; + case -3: goto put_err_out; + } + + /* + * Determine maximum possible length of mapping pairs, + * if we shall *not* expand space for mapping pairs. + */ + cur_max_mp_size = le32_to_cpu(a->length) - + le16_to_cpu(a->mapping_pairs_offset); + /* + * Determine maximum possible length of mapping pairs in the + * current mft record, if we shall expand space for mapping + * pairs. + */ + exp_max_mp_size = le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use) + cur_max_mp_size; + /* Get the size for the rest of mapping pairs array. */ + mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, stop_rl, + stop_vcn, exp_max_mp_size); + if (mp_size <= 0) { + ntfs_log_perror("%s: get MP size failed", __FUNCTION__); + goto put_err_out; + } + /* Test mapping pairs for fitting in the current mft record. */ + if (mp_size > exp_max_mp_size) { + /* + * Mapping pairs of $ATTRIBUTE_LIST attribute must fit + * in the base mft record. Try to move out other + * attributes and try again. + */ + if (na->type == AT_ATTRIBUTE_LIST) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_free_space(na->ni, mp_size - + cur_max_mp_size)) { + ntfs_log_perror("Attribute list is too " + "big. Defragment the " + "volume\n"); + return -1; + } + goto retry; + } + + /* Add attribute list if it isn't present, and retry. */ + if (!NInoAttrList(base_ni)) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_add_attrlist(base_ni)) { + ntfs_log_perror("Can not add attrlist"); + return -1; + } + goto retry; + } + + /* + * Set mapping pairs size to maximum possible for this + * mft record. We shall write the rest of mapping pairs + * to another MFT records. + */ + mp_size = exp_max_mp_size; + } + + /* Change space for mapping pairs if we need it. */ + if (((mp_size + 7) & ~7) != cur_max_mp_size) { + if (ntfs_attr_record_resize(m, a, + le16_to_cpu(a->mapping_pairs_offset) + + mp_size)) { + errno = EIO; + ntfs_log_perror("Failed to resize attribute"); + goto put_err_out; + } + } + + /* Update lowest vcn. */ + a->lowest_vcn = cpu_to_sle64(stop_vcn); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + if ((ctx->ntfs_ino->nr_extents == -1 || + NInoAttrList(ctx->ntfs_ino)) && + ctx->attr->type != AT_ATTRIBUTE_LIST) { + ctx->al_entry->lowest_vcn = cpu_to_sle64(stop_vcn); + ntfs_attrlist_mark_dirty(ctx->ntfs_ino); + } + + /* + * Generate the new mapping pairs array directly into the + * correct destination, i.e. the attribute record itself. + */ + if (!ntfs_mapping_pairs_build(na->ni->vol, (u8*)a + le16_to_cpu( + a->mapping_pairs_offset), mp_size, na->rl, + stop_vcn, &stop_rl)) + finished_build = TRUE; + if (stop_rl) + stop_vcn = stop_rl->vcn; + else + stop_vcn = 0; + if (!finished_build && errno != ENOSPC) { + ntfs_log_perror("Failed to build mapping pairs"); + goto put_err_out; + } + a->highest_vcn = cpu_to_sle64(stop_vcn - 1); + } + /* Check whether error occurred. */ + if (errno != ENOENT) { + ntfs_log_perror("%s: Attribute lookup failed", __FUNCTION__); + goto put_err_out; + } + /* + * If the base extent was skipped in the above process, + * we still may have to update the sizes. + */ + if (!first_updated) { + le16 spcomp; + + ntfs_attr_reinit_search_ctx(ctx); + if (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + a = ctx->attr; + a->allocated_size = cpu_to_sle64(na->allocated_size); + spcomp = na->data_flags + & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE); + if (spcomp) + a->compressed_size = cpu_to_sle64(na->compressed_size); + if ((na->type == AT_DATA) && (na->name == AT_UNNAMED)) { + na->ni->allocated_size + = (spcomp + ? na->compressed_size + : na->allocated_size); + NInoFileNameSetDirty(na->ni); + } + } else { + ntfs_log_error("Failed to update sizes in base extent\n"); + goto put_err_out; + } + } + + /* Deallocate not used attribute extents and return with success. */ + if (finished_build) { + ntfs_attr_reinit_search_ctx(ctx); + ntfs_log_trace("Deallocate marked extents.\n"); + while (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (sle64_to_cpu(ctx->attr->highest_vcn) != + NTFS_VCN_DELETE_MARK) + continue; + /* Remove unused attribute record. */ + if (ntfs_attr_record_rm(ctx)) { + ntfs_log_perror("Could not remove unused attr"); + goto put_err_out; + } + ntfs_attr_reinit_search_ctx(ctx); + } + if (errno != ENOENT) { + ntfs_log_perror("%s: Attr lookup failed", __FUNCTION__); + goto put_err_out; + } + ntfs_log_trace("Deallocate done.\n"); + ntfs_attr_put_search_ctx(ctx); + goto ok; + } + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + + /* Allocate new MFT records for the rest of mapping pairs. */ + while (1) { + /* Calculate size of rest mapping pairs. */ + mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, + na->rl, stop_vcn, INT_MAX); + if (mp_size <= 0) { + ntfs_log_perror("%s: get mp size failed", __FUNCTION__); + goto put_err_out; + } + /* Allocate new mft record. */ + ni = ntfs_mft_record_alloc(na->ni->vol, base_ni); + if (!ni) { + ntfs_log_perror("Could not allocate new MFT record"); + goto put_err_out; + } + m = ni->mrec; + /* + * If mapping size exceed available space, set them to + * possible maximum. + */ + cur_max_mp_size = le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use) - + (offsetof(ATTR_RECORD, compressed_size) + + (((na->data_flags & ATTR_COMPRESSION_MASK) + || NAttrSparse(na)) ? + sizeof(a->compressed_size) : 0)) - + ((sizeof(ntfschar) * na->name_len + 7) & ~7); + if (mp_size > cur_max_mp_size) + mp_size = cur_max_mp_size; + /* Add attribute extent to new record. */ + err = ntfs_non_resident_attr_record_add(ni, na->type, + na->name, na->name_len, stop_vcn, mp_size, + na->data_flags); + if (err == -1) { + err = errno; + ntfs_log_perror("Could not add attribute extent"); + if (ntfs_mft_record_free(na->ni->vol, ni)) + ntfs_log_perror("Could not free MFT record"); + errno = err; + goto put_err_out; + } + a = (ATTR_RECORD*)((u8*)m + err); + + err = ntfs_mapping_pairs_build(na->ni->vol, (u8*)a + + le16_to_cpu(a->mapping_pairs_offset), mp_size, na->rl, + stop_vcn, &stop_rl); + if (stop_rl) + stop_vcn = stop_rl->vcn; + else + stop_vcn = 0; + if (err < 0 && errno != ENOSPC) { + err = errno; + ntfs_log_perror("Failed to build MP"); + if (ntfs_mft_record_free(na->ni->vol, ni)) + ntfs_log_perror("Couldn't free MFT record"); + errno = err; + goto put_err_out; + } + a->highest_vcn = cpu_to_sle64(stop_vcn - 1); + ntfs_inode_mark_dirty(ni); + /* All mapping pairs has been written. */ + if (!err) + break; + } +ok: + ret = 0; +out: + return ret; +put_err_out: + if (ctx) + ntfs_attr_put_search_ctx(ctx); + goto out; +} +#undef NTFS_VCN_DELETE_MARK + +/** + * ntfs_attr_update_mapping_pairs - update mapping pairs for ntfs attribute + * @na: non-resident ntfs open attribute for which we need update + * @from_vcn: update runlist starting this VCN + * + * Build mapping pairs from @na->rl and write them to the disk. Also, this + * function updates sparse bit, allocated and compressed size (allocates/frees + * space for this field if required). + * + * @na->allocated_size should be set to correct value for the new runlist before + * call to this function. Vice-versa @na->compressed_size will be calculated and + * set to correct value during this function. + * + * FIXME: This function does not update sparse bit and compressed size correctly + * if called with @from_vcn != 0. + * + * FIXME: Rewrite without using NTFS_VCN_DELETE_MARK define. + * + * On success return 0 and on error return -1 with errno set to the error code. + * The following error codes are defined: + * EINVAL - Invalid arguments passed. + * ENOMEM - Not enough memory to complete operation. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST + * or there is no free MFT records left to allocate. + */ +int ntfs_attr_update_mapping_pairs(ntfs_attr *na, VCN from_vcn) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_attr_update_mapping_pairs_i(na, from_vcn); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_non_resident_attr_shrink - shrink a non-resident, open ntfs attribute + * @na: non-resident ntfs attribute to shrink + * @newsize: new size (in bytes) to which to shrink the attribute + * + * Reduce the size of a non-resident, open ntfs attribute @na to @newsize bytes. + * + * On success return 0 and on error return -1 with errno set to the error code. + * The following error codes are defined: + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + */ +static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) +{ + ntfs_volume *vol; + ntfs_attr_search_ctx *ctx; + VCN first_free_vcn; + s64 nr_freed_clusters; + int err; + + ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", (unsigned long long) + na->ni->mft_no, na->type, (long long)newsize); + + vol = na->ni->vol; + + /* + * Check the attribute type and the corresponding minimum size + * against @newsize and fail if @newsize is too small. + */ + if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { + if (errno == ERANGE) { + ntfs_log_trace("Eeek! Size bounds check failed. " + "Aborting...\n"); + } else if (errno == ENOENT) + errno = EIO; + return -1; + } + + /* The first cluster outside the new allocation. */ + if (na->data_flags & ATTR_COMPRESSION_MASK) + /* + * For compressed files we must keep full compressions blocks, + * but currently we do not decompress/recompress the last + * block to truncate the data, so we may leave more allocated + * clusters than really needed. + */ + first_free_vcn = (((newsize - 1) + | (na->compression_block_size - 1)) + 1) + >> vol->cluster_size_bits; + else + first_free_vcn = (newsize + vol->cluster_size - 1) >> + vol->cluster_size_bits; + /* + * Compare the new allocation with the old one and only deallocate + * clusters if there is a change. + */ + if ((na->allocated_size >> vol->cluster_size_bits) != first_free_vcn) { + if (ntfs_attr_map_whole_runlist(na)) { + ntfs_log_trace("Eeek! ntfs_attr_map_whole_runlist " + "failed.\n"); + return -1; + } + /* Deallocate all clusters starting with the first free one. */ + nr_freed_clusters = ntfs_cluster_free(vol, na, first_free_vcn, + -1); + if (nr_freed_clusters < 0) { + ntfs_log_trace("Eeek! Freeing of clusters failed. " + "Aborting...\n"); + return -1; + } + + /* Truncate the runlist itself. */ + if (ntfs_rl_truncate(&na->rl, first_free_vcn)) { + /* + * Failed to truncate the runlist, so just throw it + * away, it will be mapped afresh on next use. + */ + free(na->rl); + na->rl = NULL; + ntfs_log_trace("Eeek! Run list truncation failed.\n"); + return -1; + } + + /* Prepare to mapping pairs update. */ + na->allocated_size = first_free_vcn << vol->cluster_size_bits; + /* Write mapping pairs for new runlist. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*first_free_vcn*/)) { + ntfs_log_trace("Eeek! Mapping pairs update failed. " + "Leaving inconstant metadata. " + "Run chkdsk.\n"); + return -1; + } + } + + /* Get the first attribute record. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + err = errno; + if (err == ENOENT) + err = EIO; + ntfs_log_trace("Eeek! Lookup of first attribute extent failed. " + "Leaving inconstant metadata.\n"); + goto put_err_out; + } + + /* Update data and initialized size. */ + na->data_size = newsize; + ctx->attr->data_size = cpu_to_sle64(newsize); + if (newsize < na->initialized_size) { + na->initialized_size = newsize; + ctx->attr->initialized_size = cpu_to_sle64(newsize); + } + /* Update data size in the index. */ + if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30) { + na->ni->data_size = na->data_size; + na->ni->allocated_size = na->allocated_size; + set_nino_flag(na->ni,KnownSize); + } + } else { + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + NInoFileNameSetDirty(na->ni); + } + } + + /* If the attribute now has zero size, make it resident. */ + if (!newsize) { + if (ntfs_attr_make_resident(na, ctx)) { + /* If couldn't make resident, just continue. */ + if (errno != EPERM) + ntfs_log_error("Failed to make attribute " + "resident. Leaving as is...\n"); + } + } + + /* Set the inode dirty so it is written out later. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + /* Done! */ + ntfs_attr_put_search_ctx(ctx); + return 0; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_non_resident_attr_expand - expand a non-resident, open ntfs attribute + * @na: non-resident ntfs attribute to expand + * @newsize: new size (in bytes) to which to expand the attribute + * + * Expand the size of a non-resident, open ntfs attribute @na to @newsize bytes, + * by allocating new clusters. + * + * On success return 0 and on error return -1 with errno set to the error code. + * The following error codes are defined: + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + */ +static int ntfs_non_resident_attr_expand_i(ntfs_attr *na, const s64 newsize) +{ + LCN lcn_seek_from; + VCN first_free_vcn; + ntfs_volume *vol; + ntfs_attr_search_ctx *ctx; + runlist *rl, *rln; + s64 org_alloc_size; + int err; + + ntfs_log_trace("Inode %lld, attr 0x%x, new size %lld old size %lld\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize, (long long)na->data_size); + + vol = na->ni->vol; + + /* + * Check the attribute type and the corresponding maximum size + * against @newsize and fail if @newsize is too big. + */ + if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { + if (errno == ENOENT) + errno = EIO; + ntfs_log_perror("%s: bounds check failed", __FUNCTION__); + return -1; + } + + /* Save for future use. */ + org_alloc_size = na->allocated_size; + /* The first cluster outside the new allocation. */ + first_free_vcn = (newsize + vol->cluster_size - 1) >> + vol->cluster_size_bits; + /* + * Compare the new allocation with the old one and only allocate + * clusters if there is a change. + */ + if ((na->allocated_size >> vol->cluster_size_bits) < first_free_vcn) { + if (ntfs_attr_map_whole_runlist(na)) { + ntfs_log_perror("ntfs_attr_map_whole_runlist failed"); + return -1; + } + + /* + * If we extend $DATA attribute on NTFS 3+ volume, we can add + * sparse runs instead of real allocation of clusters. + */ + if (na->type == AT_DATA && vol->major_ver >= 3) { + rl = ntfs_malloc(0x1000); + if (!rl) + return -1; + + rl[0].vcn = (na->allocated_size >> + vol->cluster_size_bits); + rl[0].lcn = LCN_HOLE; + rl[0].length = first_free_vcn - + (na->allocated_size >> vol->cluster_size_bits); + rl[1].vcn = first_free_vcn; + rl[1].lcn = LCN_ENOENT; + rl[1].length = 0; + } else { + /* + * Determine first after last LCN of attribute. + * We will start seek clusters from this LCN to avoid + * fragmentation. If there are no valid LCNs in the + * attribute let the cluster allocator choose the + * starting LCN. + */ + lcn_seek_from = -1; + if (na->rl->length) { + /* Seek to the last run list element. */ + for (rl = na->rl; (rl + 1)->length; rl++) + ; + /* + * If the last LCN is a hole or similar seek + * back to last valid LCN. + */ + while (rl->lcn < 0 && rl != na->rl) + rl--; + /* + * Only set lcn_seek_from it the LCN is valid. + */ + if (rl->lcn >= 0) + lcn_seek_from = rl->lcn + rl->length; + } + + rl = ntfs_cluster_alloc(vol, na->allocated_size >> + vol->cluster_size_bits, first_free_vcn - + (na->allocated_size >> + vol->cluster_size_bits), lcn_seek_from, + DATA_ZONE); + if (!rl) { + ntfs_log_perror("Cluster allocation failed " + "(%lld)", + (long long)first_free_vcn - + ((long long)na->allocated_size >> + vol->cluster_size_bits)); + return -1; + } + } + + /* Append new clusters to attribute runlist. */ + rln = ntfs_runlists_merge(na->rl, rl); + if (!rln) { + /* Failed, free just allocated clusters. */ + err = errno; + ntfs_log_perror("Run list merge failed"); + ntfs_cluster_free_from_rl(vol, rl); + free(rl); + errno = err; + return -1; + } + na->rl = rln; + + /* Prepare to mapping pairs update. */ + na->allocated_size = first_free_vcn << vol->cluster_size_bits; + /* Write mapping pairs for new runlist. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*na->allocated_size >> + vol->cluster_size_bits*/)) { + err = errno; + ntfs_log_perror("Mapping pairs update failed"); + goto rollback; + } + } + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) { + err = errno; + if (na->allocated_size == org_alloc_size) { + errno = err; + return -1; + } else + goto rollback; + } + + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + err = errno; + ntfs_log_perror("Lookup of first attribute extent failed"); + if (err == ENOENT) + err = EIO; + if (na->allocated_size != org_alloc_size) { + ntfs_attr_put_search_ctx(ctx); + goto rollback; + } else + goto put_err_out; + } + + /* Update data size. */ + na->data_size = newsize; + ctx->attr->data_size = cpu_to_sle64(newsize); + /* Update data size in the index. */ + if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (na->type == AT_INDEX_ROOT && na->name == NTFS_INDEX_I30) { + na->ni->data_size = na->data_size; + na->ni->allocated_size = na->allocated_size; + set_nino_flag(na->ni,KnownSize); + } + } else { + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + NInoFileNameSetDirty(na->ni); + } + } + /* Set the inode dirty so it is written out later. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + /* Done! */ + ntfs_attr_put_search_ctx(ctx); + return 0; +rollback: + /* Free allocated clusters. */ + if (ntfs_cluster_free(vol, na, org_alloc_size >> + vol->cluster_size_bits, -1) < 0) { + err = EIO; + ntfs_log_perror("Leaking clusters"); + } + /* Now, truncate the runlist itself. */ + if (ntfs_rl_truncate(&na->rl, org_alloc_size >> + vol->cluster_size_bits)) { + /* + * Failed to truncate the runlist, so just throw it away, it + * will be mapped afresh on next use. + */ + free(na->rl); + na->rl = NULL; + ntfs_log_perror("Couldn't truncate runlist. Rollback failed"); + } else { + /* Prepare to mapping pairs update. */ + na->allocated_size = org_alloc_size; + /* Restore mapping pairs. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*na->allocated_size >> + vol->cluster_size_bits*/)) { + ntfs_log_perror("Failed to restore old mapping pairs"); + } + } + errno = err; + return -1; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + + +static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_non_resident_attr_expand_i(na, newsize); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_truncate - resize an ntfs attribute + * @na: open ntfs attribute to resize + * @newsize: new size (in bytes) to which to resize the attribute + * + * Change the size of an open ntfs attribute @na to @newsize bytes. If the + * attribute is made bigger and the attribute is resident the newly + * "allocated" space is cleared and if the attribute is non-resident the + * newly allocated space is marked as not initialised and no real allocation + * on disk is performed. + * + * On success return 0. + * On error return values are: + * STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT + * STATUS_ERROR - otherwise + * The following error codes are defined: + * EINVAL - Invalid arguments were passed to the function. + * EOPNOTSUPP - The desired resize is not implemented yet. + * EACCES - Encrypted attribute. + */ +int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize) +{ + int ret = STATUS_ERROR; + s64 fullsize; + BOOL compressed; + + if (!na || newsize < 0 || + (na->ni->mft_no == FILE_MFT && na->type == AT_DATA)) { + ntfs_log_trace("Invalid arguments passed.\n"); + errno = EINVAL; + return STATUS_ERROR; + } + + ntfs_log_enter("Entering for inode %lld, attr 0x%x, size %lld\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize); + + if (na->data_size == newsize) { + ntfs_log_trace("Size is already ok\n"); + ret = STATUS_OK; + goto out; + } + /* + * Encrypted attributes are not supported. We return access denied, + * which is what Windows NT4 does, too. + */ + if (na->data_flags & ATTR_IS_ENCRYPTED) { + errno = EACCES; + ntfs_log_trace("Cannot truncate encrypted attribute\n"); + goto out; + } + /* + * TODO: Implement making handling of compressed attributes. + * Currently we can only expand the attribute or delete it, + * and only for ATTR_IS_COMPRESSED. This is however possible + * for resident attributes when there is no open fuse context + * (important case : $INDEX_ROOT:$I30) + */ + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + if (compressed + && NAttrNonResident(na) + && ((na->data_flags & ATTR_COMPRESSION_MASK) != ATTR_IS_COMPRESSED)) { + errno = EOPNOTSUPP; + ntfs_log_perror("Failed to truncate compressed attribute"); + goto out; + } + if (NAttrNonResident(na)) { + /* + * For compressed data, the last block must be fully + * allocated, and we do not know the size of compression + * block until the attribute has been made non-resident. + * Moreover we can only process a single compression + * block at a time (from where we are about to write), + * so we silently do not allocate more. + * + * Note : do not request upsizing of compressed files + * unless being able to face the consequences ! + */ + if (compressed && newsize && (newsize > na->data_size)) + fullsize = (na->initialized_size + | (na->compression_block_size - 1)) + 1; + else + fullsize = newsize; + if (fullsize > na->data_size) + ret = ntfs_non_resident_attr_expand(na, fullsize); + else + ret = ntfs_non_resident_attr_shrink(na, fullsize); + } else + ret = ntfs_resident_attr_resize(na, newsize); +out: + ntfs_log_leave("Return status %d\n", ret); + return ret; +} + +/* + * Stuff a hole in a compressed file + * + * An unallocated hole must be aligned on compression block size. + * If needed current block and target block are stuffed with zeroes. + * + * Returns 0 if succeeded, + * -1 if it failed (as explained in errno) + */ + +static int stuff_hole(ntfs_attr *na, const s64 pos) +{ + s64 size; + s64 begin_size; + s64 end_size; + char *buf; + int ret; + + ret = 0; + /* + * If the attribute is resident, the compression block size + * is not defined yet and we can make no decision. + * So we first try resizing to the target and if the + * attribute is still resident, we're done + */ + if (!NAttrNonResident(na)) { + ret = ntfs_resident_attr_resize(na, pos); + if (!ret && !NAttrNonResident(na)) + na->initialized_size = na->data_size = pos; + } + if (!ret && NAttrNonResident(na)) { + /* does the hole span over several compression block ? */ + if ((pos ^ na->initialized_size) + & ~(na->compression_block_size - 1)) { + begin_size = ((na->initialized_size - 1) + | (na->compression_block_size - 1)) + + 1 - na->initialized_size; + end_size = pos & (na->compression_block_size - 1); + size = (begin_size > end_size ? begin_size : end_size); + } else { + /* short stuffing in a single compression block */ + begin_size = size = pos - na->initialized_size; + end_size = 0; + } + if (size) + buf = (char*)ntfs_malloc(size); + else + buf = (char*)NULL; + if (buf || !size) { + memset(buf,0,size); + /* stuff into current block */ + if (begin_size + && (ntfs_attr_pwrite(na, + na->initialized_size, begin_size, buf) + != begin_size)) + ret = -1; + /* create an unstuffed hole */ + if (!ret + && ((na->initialized_size + end_size) < pos) + && ntfs_non_resident_attr_expand(na, + pos - end_size)) + ret = -1; + else + na->initialized_size + = na->data_size = pos - end_size; + /* stuff into the target block */ + if (!ret && end_size + && (ntfs_attr_pwrite(na, + na->initialized_size, end_size, buf) + != end_size)) + ret = -1; + if (buf) + free(buf); + } else + ret = -1; + } + /* make absolutely sure we have reached the target */ + if (!ret && (na->initialized_size != pos)) { + ntfs_log_error("Failed to stuff a compressed file" + "target %lld reached %lld\n", + (long long)pos, (long long)na->initialized_size); + errno = EIO; + ret = -1; + } + return (ret); +} + +/** + * ntfs_attr_readall - read the entire data from an ntfs attribute + * @ni: open ntfs inode in which the ntfs attribute resides + * @type: attribute type + * @name: attribute name in little endian Unicode or AT_UNNAMED or NULL + * @name_len: length of attribute @name in Unicode characters (if @name given) + * @data_size: if non-NULL then store here the data size + * + * This function will read the entire content of an ntfs attribute. + * If @name is AT_UNNAMED then look specifically for an unnamed attribute. + * If @name is NULL then the attribute could be either named or not. + * In both those cases @name_len is not used at all. + * + * On success a buffer is allocated with the content of the attribute + * and which needs to be freed when it's not needed anymore. If the + * @data_size parameter is non-NULL then the data size is set there. + * + * On error NULL is returned with errno set to the error code. + */ +void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len, s64 *data_size) +{ + ntfs_attr *na; + void *data, *ret = NULL; + s64 size; + + ntfs_log_enter("Entering\n"); + + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + ntfs_log_perror("ntfs_attr_open failed"); + goto err_exit; + } + data = ntfs_malloc(na->data_size); + if (!data) + goto out; + + size = ntfs_attr_pread(na, 0, na->data_size, data); + if (size != na->data_size) { + ntfs_log_perror("ntfs_attr_pread failed"); + free(data); + goto out; + } + ret = data; + if (data_size) + *data_size = size; +out: + ntfs_attr_close(na); +err_exit: + ntfs_log_leave("\n"); + return ret; +} + + + +int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, + u32 name_len) +{ + ntfs_attr_search_ctx *ctx; + int ret; + + ntfs_log_trace("Entering\n"); + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return 0; + + ret = ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, 0, NULL, 0, + ctx); + + ntfs_attr_put_search_ctx(ctx); + + return !ret; +} + +int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, + u32 name_len) +{ + ntfs_attr *na; + int ret; + + ntfs_log_trace("Entering\n"); + + if (!ni) { + ntfs_log_error("%s: NULL inode pointer", __FUNCTION__); + errno = EINVAL; + return -1; + } + + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + /* do not log removal of non-existent stream */ + if (type != AT_DATA) { + ntfs_log_perror("Failed to open attribute 0x%02x of inode " + "0x%llx", type, (unsigned long long)ni->mft_no); + } + return -1; + } + + ret = ntfs_attr_rm(na); + if (ret) + ntfs_log_perror("Failed to remove attribute 0x%02x of inode " + "0x%llx", type, (unsigned long long)ni->mft_no); + ntfs_attr_close(na); + + return ret; +} + +/* Below macros are 32-bit ready. */ +#define BCX(x) ((x) - (((x) >> 1) & 0x77777777) - \ + (((x) >> 2) & 0x33333333) - \ + (((x) >> 3) & 0x11111111)) +#define BITCOUNT(x) (((BCX(x) + (BCX(x) >> 4)) & 0x0F0F0F0F) % 255) + +static u8 *ntfs_init_lut256(void) +{ + int i; + u8 *lut; + + lut = ntfs_malloc(256); + if (lut) + for(i = 0; i < 256; i++) + *(lut + i) = 8 - BITCOUNT(i); + return lut; +} + +s64 ntfs_attr_get_free_bits(ntfs_attr *na) +{ + u8 *buf, *lut; + s64 br = 0; + s64 total = 0; + s64 nr_free = 0; + + lut = ntfs_init_lut256(); + if (!lut) + return -1; + + buf = ntfs_malloc(65536); + if (!buf) + goto out; + + while (1) { + u32 *p; + br = ntfs_attr_pread(na, total, 65536, buf); + if (br <= 0) + break; + total += br; + p = (u32 *)buf + br / 4 - 1; + for (; (u8 *)p >= buf; p--) { + nr_free += lut[ *p & 255] + + lut[(*p >> 8) & 255] + + lut[(*p >> 16) & 255] + + lut[(*p >> 24) ]; + } + switch (br % 4) { + case 3: nr_free += lut[*(buf + br - 3)]; + case 2: nr_free += lut[*(buf + br - 2)]; + case 1: nr_free += lut[*(buf + br - 1)]; + } + } + free(buf); +out: + free(lut); + if (!total || br < 0) + return -1; + return nr_free; +} diff --git a/libcustomntfs/attrib.h b/libcustomntfs/attrib.h new file mode 100644 index 00000000..43ab7f53 --- /dev/null +++ b/libcustomntfs/attrib.h @@ -0,0 +1,375 @@ +/* + * attrib.h - Exports for attribute handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2004-2005 Yura Pakhuchiy + * Copyright (c) 2006-2007 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_ATTRIB_H +#define _NTFS_ATTRIB_H + +/* Forward declarations */ +typedef struct _ntfs_attr ntfs_attr; +typedef struct _ntfs_attr_search_ctx ntfs_attr_search_ctx; + +#include "types.h" +#include "inode.h" +#include "unistr.h" +#include "runlist.h" +#include "volume.h" +#include "debug.h" +#include "logging.h" + +extern ntfschar AT_UNNAMED[]; +extern ntfschar STREAM_SDS[]; + +/* The little endian Unicode string $TXF_DATA as a global constant. */ +extern ntfschar TXF_DATA[10]; + +/** + * enum ntfs_lcn_special_values - special return values for ntfs_*_vcn_to_lcn() + * + * Special return values for ntfs_rl_vcn_to_lcn() and ntfs_attr_vcn_to_lcn(). + * + * TODO: Describe them. + */ +typedef enum { + LCN_HOLE = -1, /* Keep this as highest value or die! */ + LCN_RL_NOT_MAPPED = -2, + LCN_ENOENT = -3, + LCN_EINVAL = -4, + LCN_EIO = -5, +} ntfs_lcn_special_values; + +/** + * struct ntfs_attr_search_ctx - search context used in attribute search functions + * @mrec: buffer containing mft record to search + * @attr: attribute record in @mrec where to begin/continue search + * @is_first: if true lookup_attr() begins search with @attr, else after @attr + * + * Structure must be initialized to zero before the first call to one of the + * attribute search functions. Initialize @mrec to point to the mft record to + * search, and @attr to point to the first attribute within @mrec (not necessary + * if calling the _first() functions), and set @is_first to TRUE (not necessary + * if calling the _first() functions). + * + * If @is_first is TRUE, the search begins with @attr. If @is_first is FALSE, + * the search begins after @attr. This is so that, after the first call to one + * of the search attribute functions, we can call the function again, without + * any modification of the search context, to automagically get the next + * matching attribute. + */ +struct _ntfs_attr_search_ctx { + MFT_RECORD *mrec; + ATTR_RECORD *attr; + BOOL is_first; + ntfs_inode *ntfs_ino; + ATTR_LIST_ENTRY *al_entry; + ntfs_inode *base_ntfs_ino; + MFT_RECORD *base_mrec; + ATTR_RECORD *base_attr; +}; + +extern void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx); +extern ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni, + MFT_RECORD *mrec); +extern void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx); + +extern int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const VCN lowest_vcn, const u8 *val, const u32 val_len, + ntfs_attr_search_ctx *ctx); + +extern int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx); + +extern ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, + const ATTR_TYPES type); + +/** + * ntfs_attrs_walk - syntactic sugar for walking all attributes in an inode + * @ctx: initialised attribute search context + * + * Syntactic sugar for walking attributes in an inode. + * + * Return 0 on success and -1 on error with errno set to the error code from + * ntfs_attr_lookup(). + * + * Example: When you want to enumerate all attributes in an open ntfs inode + * @ni, you can simply do: + * + * int err; + * ntfs_attr_search_ctx *ctx = ntfs_attr_get_search_ctx(ni, NULL); + * if (!ctx) + * // Error code is in errno. Handle this case. + * while (!(err = ntfs_attrs_walk(ctx))) { + * ATTR_RECORD *attr = ctx->attr; + * // attr now contains the next attribute. Do whatever you want + * // with it and then just continue with the while loop. + * } + * if (err && errno != ENOENT) + * // Ooops. An error occurred! You should handle this case. + * // Now finished with all attributes in the inode. + */ +static __inline__ int ntfs_attrs_walk(ntfs_attr_search_ctx *ctx) +{ + return ntfs_attr_lookup(AT_UNUSED, NULL, 0, CASE_SENSITIVE, 0, + NULL, 0, ctx); +} + +/** + * struct ntfs_attr - ntfs in memory non-resident attribute structure + * @rl: if not NULL, the decompressed runlist + * @ni: base ntfs inode to which this attribute belongs + * @type: attribute type + * @name: Unicode name of the attribute + * @name_len: length of @name in Unicode characters + * @state: NTFS attribute specific flags describing this attribute + * @allocated_size: copy from the attribute record + * @data_size: copy from the attribute record + * @initialized_size: copy from the attribute record + * @compressed_size: copy from the attribute record + * @compression_block_size: size of a compression block (cb) + * @compression_block_size_bits: log2 of the size of a cb + * @compression_block_clusters: number of clusters per cb + * + * This structure exists purely to provide a mechanism of caching the runlist + * of an attribute. If you want to operate on a particular attribute extent, + * you should not be using this structure at all. If you want to work with a + * resident attribute, you should not be using this structure at all. As a + * fail-safe check make sure to test NAttrNonResident() and if it is false, you + * know you shouldn't be using this structure. + * + * If you want to work on a resident attribute or on a specific attribute + * extent, you should use ntfs_lookup_attr() to retrieve the attribute (extent) + * record, edit that, and then write back the mft record (or set the + * corresponding ntfs inode dirty for delayed write back). + * + * @rl is the decompressed runlist of the attribute described by this + * structure. Obviously this only makes sense if the attribute is not resident, + * i.e. NAttrNonResident() is true. If the runlist hasn't been decompressed yet + * @rl is NULL, so be prepared to cope with @rl == NULL. + * + * @ni is the base ntfs inode of the attribute described by this structure. + * + * @type is the attribute type (see layout.h for the definition of ATTR_TYPES), + * @name and @name_len are the little endian Unicode name and the name length + * in Unicode characters of the attribute, respectively. + * + * @state contains NTFS attribute specific flags describing this attribute + * structure. See ntfs_attr_state_bits above. + */ +struct _ntfs_attr { + runlist_element *rl; + ntfs_inode *ni; + ATTR_TYPES type; + ATTR_FLAGS data_flags; + ntfschar *name; + u32 name_len; + unsigned long state; + s64 allocated_size; + s64 data_size; + s64 initialized_size; + s64 compressed_size; + u32 compression_block_size; + u8 compression_block_size_bits; + u8 compression_block_clusters; + s8 unused_runs; /* pre-reserved entries available */ +}; + +/** + * enum ntfs_attr_state_bits - bits for the state field in the ntfs_attr + * structure + */ +typedef enum { + NA_Initialized, /* 1: structure is initialized. */ + NA_NonResident, /* 1: Attribute is not resident. */ + NA_BeingNonResident, /* 1: Attribute is being made not resident. */ + NA_FullyMapped, /* 1: Attribute has been fully mapped */ + NA_ComprClosing, /* 1: Compressed attribute is being closed */ +} ntfs_attr_state_bits; + +#define test_nattr_flag(na, flag) test_bit(NA_##flag, (na)->state) +#define set_nattr_flag(na, flag) set_bit(NA_##flag, (na)->state) +#define clear_nattr_flag(na, flag) clear_bit(NA_##flag, (na)->state) + +#define NAttrInitialized(na) test_nattr_flag(na, Initialized) +#define NAttrSetInitialized(na) set_nattr_flag(na, Initialized) +#define NAttrClearInitialized(na) clear_nattr_flag(na, Initialized) + +#define NAttrNonResident(na) test_nattr_flag(na, NonResident) +#define NAttrSetNonResident(na) set_nattr_flag(na, NonResident) +#define NAttrClearNonResident(na) clear_nattr_flag(na, NonResident) + +#define NAttrBeingNonResident(na) test_nattr_flag(na, BeingNonResident) +#define NAttrSetBeingNonResident(na) set_nattr_flag(na, BeingNonResident) +#define NAttrClearBeingNonResident(na) clear_nattr_flag(na, BeingNonResident) + +#define NAttrFullyMapped(na) test_nattr_flag(na, FullyMapped) +#define NAttrSetFullyMapped(na) set_nattr_flag(na, FullyMapped) +#define NAttrClearFullyMapped(na) clear_nattr_flag(na, FullyMapped) + +#define NAttrComprClosing(na) test_nattr_flag(na, ComprClosing) +#define NAttrSetComprClosing(na) set_nattr_flag(na, ComprClosing) +#define NAttrClearComprClosing(na) clear_nattr_flag(na, ComprClosing) + +#define GenNAttrIno(func_name, flag) \ +extern int NAttr##func_name(ntfs_attr *na); \ +extern void NAttrSet##func_name(ntfs_attr *na); \ +extern void NAttrClear##func_name(ntfs_attr *na); + +GenNAttrIno(Compressed, FILE_ATTR_COMPRESSED) +GenNAttrIno(Encrypted, FILE_ATTR_ENCRYPTED) +GenNAttrIno(Sparse, FILE_ATTR_SPARSE_FILE) +#undef GenNAttrIno + +/** + * union attr_val - Union of all known attribute values + * + * For convenience. Used in the attr structure. + */ +typedef union { + u8 _default; /* Unnamed u8 to serve as default when just using + a_val without specifying any of the below. */ + STANDARD_INFORMATION std_inf; + ATTR_LIST_ENTRY al_entry; + FILE_NAME_ATTR filename; + OBJECT_ID_ATTR obj_id; + SECURITY_DESCRIPTOR_ATTR sec_desc; + VOLUME_NAME vol_name; + VOLUME_INFORMATION vol_inf; + DATA_ATTR data; + INDEX_ROOT index_root; + INDEX_BLOCK index_blk; + BITMAP_ATTR bmp; + REPARSE_POINT reparse; + EA_INFORMATION ea_inf; + EA_ATTR ea; + PROPERTY_SET property_set; + LOGGED_UTILITY_STREAM logged_util_stream; + EFS_ATTR_HEADER efs; +} attr_val; + +extern void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, + const ATTR_FLAGS data_flags, const BOOL encrypted, + const BOOL sparse, + const s64 allocated_size, const s64 data_size, + const s64 initialized_size, const s64 compressed_size, + const u8 compression_unit); + + /* warning : in the following "name" has to be freeable */ + /* or one of constants AT_UNNAMED, NTFS_INDEX_I30 or STREAM_SDS */ +extern ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len); +extern void ntfs_attr_close(ntfs_attr *na); + +extern s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, + void *b); +extern s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, + const void *b); +extern int ntfs_attr_pclose(ntfs_attr *na); + +extern void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len, s64 *data_size); + +extern s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, + const s64 bk_cnt, const u32 bk_size, void *dst); +extern s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, + s64 bk_cnt, const u32 bk_size, void *src); + +extern int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn); +extern int ntfs_attr_map_whole_runlist(ntfs_attr *na); + +extern LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn); +extern runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn); + +extern int ntfs_attr_size_bounds_check(const ntfs_volume *vol, + const ATTR_TYPES type, const s64 size); +extern int ntfs_attr_can_be_resident(const ntfs_volume *vol, + const ATTR_TYPES type); +int ntfs_attr_make_non_resident(ntfs_attr *na, + ntfs_attr_search_ctx *ctx); +int ntfs_attr_force_non_resident(ntfs_attr *na); +extern int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size); + +extern int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, u8 *val, u32 size, + ATTR_FLAGS flags); +extern int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, + ATTR_FLAGS flags); +extern int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx); + +extern int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, u8 *val, s64 size); +extern int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask); +extern int ntfs_attr_rm(ntfs_attr *na); + +extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size); + +extern int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, + const u32 new_size); + +extern int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni); +extern int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra); + +extern int ntfs_attr_update_mapping_pairs(ntfs_attr *na, VCN from_vcn); + +extern int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize); + +/** + * get_attribute_value_length - return the length of the value of an attribute + * @a: pointer to a buffer containing the attribute record + * + * Return the byte size of the attribute value of the attribute @a (as it + * would be after eventual decompression and filling in of holes if sparse). + * If we return 0, check errno. If errno is 0 the actual length was 0, + * otherwise errno describes the error. + * + * FIXME: Describe possible errnos. + */ +extern s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a); + +/** + * get_attribute_value - return the attribute value of an attribute + * @vol: volume on which the attribute is present + * @a: attribute to get the value of + * @b: destination buffer for the attribute value + * + * Make a copy of the attribute value of the attribute @a into the destination + * buffer @b. Note, that the size of @b has to be at least equal to the value + * returned by get_attribute_value_length(@a). + * + * Return number of bytes copied. If this is zero check errno. If errno is 0 + * then nothing was read due to a zero-length attribute value, otherwise + * errno describes the error. + */ +extern s64 ntfs_get_attribute_value(const ntfs_volume *vol, + const ATTR_RECORD *a, u8 *b); + +extern void ntfs_attr_name_free(char **name); +extern char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len); +extern int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len); +extern int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len); +extern s64 ntfs_attr_get_free_bits(ntfs_attr *na); + +#endif /* defined _NTFS_ATTRIB_H */ + diff --git a/libcustomntfs/attrib_frag.c b/libcustomntfs/attrib_frag.c new file mode 100644 index 00000000..ebde221b --- /dev/null +++ b/libcustomntfs/attrib_frag.c @@ -0,0 +1,5915 @@ +/** + * attrib.c - Attribute handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2005 Anton Altaparmakov + * Copyright (c) 2002-2005 Richard Russon + * Copyright (c) 2002-2008 Szabolcs Szakacsits + * Copyright (c) 2004-2007 Yura Pakhuchiy + * Copyright (c) 2007-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "compat.h" +#include "attrib.h" +#include "attrlist.h" +#include "device.h" +#include "mft.h" +#include "debug.h" +#include "mst.h" +#include "volume.h" +#include "types.h" +#include "layout.h" +#include "inode.h" +#include "runlist.h" +#include "lcnalloc.h" +#include "dir.h" +#include "compress.h" +#include "bitmap.h" +#include "logging.h" +#include "misc.h" +#include "efs.h" +#include "ntfs.h" +#include "ntfsfile_frag.h" + +#if 0 + +#define STANDARD_COMPRESSION_UNIT 4 + +ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') }; +ntfschar STREAM_SDS[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('S'), + const_cpu_to_le16('D'), + const_cpu_to_le16('S'), + const_cpu_to_le16('\0') }; + +static int NAttrFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) +{ + if (na->type == AT_DATA && na->name == AT_UNNAMED) + return (na->ni->flags & flag); + return 0; +} + +static void NAttrSetFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) +{ + if (na->type == AT_DATA && na->name == AT_UNNAMED) + na->ni->flags |= flag; + else + ntfs_log_trace("Denied setting flag %d for not unnamed data " + "attribute\n", flag); +} + +static void NAttrClearFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) +{ + if (na->type == AT_DATA && na->name == AT_UNNAMED) + na->ni->flags &= ~flag; +} + +#define GenNAttrIno(func_name, flag) \ +int NAttr##func_name(ntfs_attr *na) { return NAttrFlag (na, flag); } \ +void NAttrSet##func_name(ntfs_attr *na) { NAttrSetFlag (na, flag); } \ +void NAttrClear##func_name(ntfs_attr *na){ NAttrClearFlag(na, flag); } + +GenNAttrIno(Compressed, FILE_ATTR_COMPRESSED) +GenNAttrIno(Encrypted, FILE_ATTR_ENCRYPTED) +GenNAttrIno(Sparse, FILE_ATTR_SPARSE_FILE) + +/** + * ntfs_get_attribute_value_length - Find the length of an attribute + * @a: + * + * Description... + * + * Returns: + */ +s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a) +{ + if (!a) { + errno = EINVAL; + return 0; + } + errno = 0; + if (a->non_resident) + return sle64_to_cpu(a->data_size); + + return (s64)le32_to_cpu(a->value_length); +} + +/** + * ntfs_get_attribute_value - Get a copy of an attribute + * @vol: + * @a: + * @b: + * + * Description... + * + * Returns: + */ +s64 ntfs_get_attribute_value(const ntfs_volume *vol, + const ATTR_RECORD *a, u8 *b) +{ + runlist *rl; + s64 total, r; + int i; + + /* Sanity checks. */ + if (!vol || !a || !b) { + errno = EINVAL; + return 0; + } + /* Complex attribute? */ + /* + * Ignore the flags in case they are not zero for an attribute list + * attribute. Windows does not complain about invalid flags and chkdsk + * does not detect or fix them so we need to cope with it, too. + */ + if (a->type != AT_ATTRIBUTE_LIST && a->flags) { + ntfs_log_error("Non-zero (%04x) attribute flags. Cannot handle " + "this yet.\n", le16_to_cpu(a->flags)); + errno = EOPNOTSUPP; + return 0; + } + if (!a->non_resident) { + /* Attribute is resident. */ + + /* Sanity check. */ + if (le32_to_cpu(a->value_length) + le16_to_cpu(a->value_offset) + > le32_to_cpu(a->length)) { + return 0; + } + + memcpy(b, (const char*)a + le16_to_cpu(a->value_offset), + le32_to_cpu(a->value_length)); + errno = 0; + return (s64)le32_to_cpu(a->value_length); + } + + /* Attribute is not resident. */ + + /* If no data, return 0. */ + if (!(a->data_size)) { + errno = 0; + return 0; + } + /* + * FIXME: What about attribute lists?!? (AIA) + */ + /* Decompress the mapping pairs array into a runlist. */ + rl = ntfs_mapping_pairs_decompress(vol, a, NULL); + if (!rl) { + errno = EINVAL; + return 0; + } + /* + * FIXED: We were overflowing here in a nasty fashion when we + * reach the last cluster in the runlist as the buffer will + * only be big enough to hold data_size bytes while we are + * reading in allocated_size bytes which is usually larger + * than data_size, since the actual data is unlikely to have a + * size equal to a multiple of the cluster size! + * FIXED2: We were also overflowing here in the same fashion + * when the data_size was more than one run smaller than the + * allocated size which happens with Windows XP sometimes. + */ + /* Now load all clusters in the runlist into b. */ + for (i = 0, total = 0; rl[i].length; i++) { + if (total + (rl[i].length << vol->cluster_size_bits) >= + sle64_to_cpu(a->data_size)) { + unsigned char *intbuf = NULL; + /* + * We have reached the last run so we were going to + * overflow when executing the ntfs_pread() which is + * BAAAAAAAD! + * Temporary fix: + * Allocate a new buffer with size: + * rl[i].length << vol->cluster_size_bits, do the + * read into our buffer, then memcpy the correct + * amount of data into the caller supplied buffer, + * free our buffer, and continue. + * We have reached the end of data size so we were + * going to overflow in the same fashion. + * Temporary fix: same as above. + */ + intbuf = ntfs_malloc(rl[i].length << vol->cluster_size_bits); + if (!intbuf) { + free(rl); + return 0; + } + /* + * FIXME: If compressed file: Only read if lcn != -1. + * Otherwise, we are dealing with a sparse run and we + * just memset the user buffer to 0 for the length of + * the run, which should be 16 (= compression unit + * size). + * FIXME: Really only when file is compressed, or can + * we have sparse runs in uncompressed files as well? + * - Yes we can, in sparse files! But not necessarily + * size of 16, just run length. + */ + r = ntfs_pread(vol->dev, rl[i].lcn << + vol->cluster_size_bits, rl[i].length << + vol->cluster_size_bits, intbuf); + if (r != rl[i].length << vol->cluster_size_bits) { +#define ESTR "Error reading attribute value" + if (r == -1) + ntfs_log_perror(ESTR); + else if (r < rl[i].length << + vol->cluster_size_bits) { + ntfs_log_debug(ESTR ": Ran out of input data.\n"); + errno = EIO; + } else { + ntfs_log_debug(ESTR ": unknown error\n"); + errno = EIO; + } +#undef ESTR + free(rl); + free(intbuf); + return 0; + } + memcpy(b + total, intbuf, sle64_to_cpu(a->data_size) - + total); + free(intbuf); + total = sle64_to_cpu(a->data_size); + break; + } + /* + * FIXME: If compressed file: Only read if lcn != -1. + * Otherwise, we are dealing with a sparse run and we just + * memset the user buffer to 0 for the length of the run, which + * should be 16 (= compression unit size). + * FIXME: Really only when file is compressed, or can + * we have sparse runs in uncompressed files as well? + * - Yes we can, in sparse files! But not necessarily size of + * 16, just run length. + */ + r = ntfs_pread(vol->dev, rl[i].lcn << vol->cluster_size_bits, + rl[i].length << vol->cluster_size_bits, + b + total); + if (r != rl[i].length << vol->cluster_size_bits) { +#define ESTR "Error reading attribute value" + if (r == -1) + ntfs_log_perror(ESTR); + else if (r < rl[i].length << vol->cluster_size_bits) { + ntfs_log_debug(ESTR ": Ran out of input data.\n"); + errno = EIO; + } else { + ntfs_log_debug(ESTR ": unknown error\n"); + errno = EIO; + } +#undef ESTR + free(rl); + return 0; + } + total += r; + } + free(rl); + return total; +} + +/* Already cleaned up code below, but still look for FIXME:... */ + +/** + * __ntfs_attr_init - primary initialization of an ntfs attribute structure + * @na: ntfs attribute to initialize + * @ni: ntfs inode with which to initialize the ntfs attribute + * @type: attribute type + * @name: attribute name in little endian Unicode or NULL + * @name_len: length of attribute @name in Unicode characters (if @name given) + * + * Initialize the ntfs attribute @na with @ni, @type, @name, and @name_len. + */ +static void __ntfs_attr_init(ntfs_attr *na, ntfs_inode *ni, + const ATTR_TYPES type, ntfschar *name, const u32 name_len) +{ + na->rl = NULL; + na->ni = ni; + na->type = type; + na->name = name; + if (name) + na->name_len = name_len; + else + na->name_len = 0; +} + +/** + * ntfs_attr_init - initialize an ntfs_attr with data sizes and status + * @na: + * @non_resident: + * @compressed: + * @encrypted: + * @sparse: + * @allocated_size: + * @data_size: + * @initialized_size: + * @compressed_size: + * @compression_unit: + * + * Final initialization for an ntfs attribute. + */ +void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, + const ATTR_FLAGS data_flags, + const BOOL encrypted, const BOOL sparse, + const s64 allocated_size, const s64 data_size, + const s64 initialized_size, const s64 compressed_size, + const u8 compression_unit) +{ + if (!NAttrInitialized(na)) { + na->data_flags = data_flags; + if (non_resident) + NAttrSetNonResident(na); + if (data_flags & ATTR_COMPRESSION_MASK) + NAttrSetCompressed(na); + if (encrypted) + NAttrSetEncrypted(na); + if (sparse) + NAttrSetSparse(na); + na->allocated_size = allocated_size; + na->data_size = data_size; + na->initialized_size = initialized_size; + if ((data_flags & ATTR_COMPRESSION_MASK) || sparse) { + ntfs_volume *vol = na->ni->vol; + + na->compressed_size = compressed_size; + na->compression_block_clusters = 1 << compression_unit; + na->compression_block_size = 1 << (compression_unit + + vol->cluster_size_bits); + na->compression_block_size_bits = ffs( + na->compression_block_size) - 1; + } + NAttrSetInitialized(na); + } +} + +/** + * ntfs_attr_open - open an ntfs attribute for access + * @ni: open ntfs inode in which the ntfs attribute resides + * @type: attribute type + * @name: attribute name in little endian Unicode or AT_UNNAMED or NULL + * @name_len: length of attribute @name in Unicode characters (if @name given) + * + * Allocate a new ntfs attribute structure, initialize it with @ni, @type, + * @name, and @name_len, then return it. Return NULL on error with + * errno set to the error code. + * + * If @name is AT_UNNAMED look specifically for an unnamed attribute. If you + * do not care whether the attribute is named or not set @name to NULL. In + * both those cases @name_len is not used at all. + */ +ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len) +{ + ntfs_attr_search_ctx *ctx; + ntfs_attr *na = NULL; + ntfschar *newname = NULL; + ATTR_RECORD *a; + BOOL cs; + + ntfs_log_enter("Entering for inode %lld, attr 0x%x.\n", + (unsigned long long)ni->mft_no, type); + + if (!ni || !ni->vol || !ni->mrec) { + errno = EINVAL; + goto out; + } + na = ntfs_calloc(sizeof(ntfs_attr)); + if (!na) + goto out; + if (name && name != AT_UNNAMED && name != NTFS_INDEX_I30) { + name = ntfs_ucsndup(name, name_len); + if (!name) + goto err_out; + newname = name; + } + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + goto err_out; + + if (ntfs_attr_lookup(type, name, name_len, 0, 0, NULL, 0, ctx)) + goto put_err_out; + + a = ctx->attr; + + if (!name) { + if (a->name_length) { + name = ntfs_ucsndup((ntfschar*)((u8*)a + le16_to_cpu( + a->name_offset)), a->name_length); + if (!name) + goto put_err_out; + newname = name; + name_len = a->name_length; + } else { + name = AT_UNNAMED; + name_len = 0; + } + } + + __ntfs_attr_init(na, ni, type, name, name_len); + + /* + * Wipe the flags in case they are not zero for an attribute list + * attribute. Windows does not complain about invalid flags and chkdsk + * does not detect or fix them so we need to cope with it, too. + */ + if (type == AT_ATTRIBUTE_LIST) + a->flags = 0; + + if ((type == AT_DATA) && !a->initialized_size) { + /* + * Define/redefine the compression state if stream is + * empty, based on the compression mark on parent + * directory (for unnamed data streams) or on current + * inode (for named data streams). The compression mark + * may change any time, the compression state can only + * change when stream is wiped out. + */ + a->flags &= ~ATTR_COMPRESSION_MASK; + if (na->ni->flags & FILE_ATTR_COMPRESSED) + a->flags |= ATTR_IS_COMPRESSED; + } + + cs = a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE); + + if (na->type == AT_DATA && na->name == AT_UNNAMED && + ((!(a->flags & ATTR_IS_SPARSE) != !NAttrSparse(na)) || + (!(a->flags & ATTR_IS_ENCRYPTED) != !NAttrEncrypted(na)))) { + errno = EIO; + ntfs_log_perror("Inode %lld has corrupt attribute flags " + "(0x%x <> 0x%x)",(unsigned long long)ni->mft_no, + a->flags, na->ni->flags); + goto put_err_out; + } + + if (a->non_resident) { + if ((a->flags & ATTR_COMPRESSION_MASK) + && !a->compression_unit) { + errno = EIO; + ntfs_log_perror("Compressed inode %lld attr 0x%x has " + "no compression unit", + (unsigned long long)ni->mft_no, type); + goto put_err_out; + } + ntfs_attr_init(na, TRUE, a->flags, + a->flags & ATTR_IS_ENCRYPTED, + a->flags & ATTR_IS_SPARSE, + sle64_to_cpu(a->allocated_size), + sle64_to_cpu(a->data_size), + sle64_to_cpu(a->initialized_size), + cs ? sle64_to_cpu(a->compressed_size) : 0, + cs ? a->compression_unit : 0); + } else { + s64 l = le32_to_cpu(a->value_length); + ntfs_attr_init(na, FALSE, a->flags, + a->flags & ATTR_IS_ENCRYPTED, + a->flags & ATTR_IS_SPARSE, (l + 7) & ~7, l, l, + cs ? (l + 7) & ~7 : 0, 0); + } + ntfs_attr_put_search_ctx(ctx); +out: + ntfs_log_leave("\n"); + return na; + +put_err_out: + ntfs_attr_put_search_ctx(ctx); +err_out: + free(newname); + free(na); + na = NULL; + goto out; +} + +/** + * ntfs_attr_close - free an ntfs attribute structure + * @na: ntfs attribute structure to free + * + * Release all memory associated with the ntfs attribute @na and then release + * @na itself. + */ +void ntfs_attr_close(ntfs_attr *na) +{ + if (!na) + return; + if (NAttrNonResident(na) && na->rl) + free(na->rl); + /* Don't release if using an internal constant. */ + if (na->name != AT_UNNAMED && na->name != NTFS_INDEX_I30 + && na->name != STREAM_SDS) + free(na->name); + free(na); +} + +/** + * ntfs_attr_map_runlist - map (a part of) a runlist of an ntfs attribute + * @na: ntfs attribute for which to map (part of) a runlist + * @vcn: map runlist part containing this vcn + * + * Map the part of a runlist containing the @vcn of the ntfs attribute @na. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn) +{ + LCN lcn; + ntfs_attr_search_ctx *ctx; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, (long long)vcn); + + lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); + if (lcn >= 0 || lcn == LCN_HOLE || lcn == LCN_ENOENT) + return 0; + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + + /* Find the attribute in the mft record. */ + if (!ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + vcn, NULL, 0, ctx)) { + runlist_element *rl; + + /* Decode the runlist. */ + rl = ntfs_mapping_pairs_decompress(na->ni->vol, ctx->attr, + na->rl); + if (rl) { + na->rl = rl; + ntfs_attr_put_search_ctx(ctx); + return 0; + } + } + + ntfs_attr_put_search_ctx(ctx); + return -1; +} + +/** + * ntfs_attr_map_whole_runlist - map the whole runlist of an ntfs attribute + * @na: ntfs attribute for which to map the runlist + * + * Map the whole runlist of the ntfs attribute @na. For an attribute made up + * of only one attribute extent this is the same as calling + * ntfs_attr_map_runlist(na, 0) but for an attribute with multiple extents this + * will map the runlist fragments from each of the extents thus giving access + * to the entirety of the disk allocation of an attribute. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_map_whole_runlist(ntfs_attr *na) +{ + VCN next_vcn, last_vcn, highest_vcn; + ntfs_attr_search_ctx *ctx; + ntfs_volume *vol = na->ni->vol; + ATTR_RECORD *a; + int ret = -1; + + ntfs_log_enter("Entering for inode %llu, attr 0x%x.\n", + (unsigned long long)na->ni->mft_no, na->type); + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + goto out; + + /* Map all attribute extents one by one. */ + next_vcn = last_vcn = highest_vcn = 0; + a = NULL; + while (1) { + runlist_element *rl; + + int not_mapped = 0; + if (ntfs_rl_vcn_to_lcn(na->rl, next_vcn) == LCN_RL_NOT_MAPPED) + not_mapped = 1; + + if (ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, next_vcn, NULL, 0, ctx)) + break; + + a = ctx->attr; + + if (not_mapped) { + /* Decode the runlist. */ + rl = ntfs_mapping_pairs_decompress(na->ni->vol, + a, na->rl); + if (!rl) + goto err_out; + na->rl = rl; + } + + /* Are we in the first extent? */ + if (!next_vcn) { + if (a->lowest_vcn) { + errno = EIO; + ntfs_log_perror("First extent of inode %llu " + "attribute has non-zero lowest_vcn", + (unsigned long long)na->ni->mft_no); + goto err_out; + } + /* Get the last vcn in the attribute. */ + last_vcn = sle64_to_cpu(a->allocated_size) >> + vol->cluster_size_bits; + } + + /* Get the lowest vcn for the next extent. */ + highest_vcn = sle64_to_cpu(a->highest_vcn); + next_vcn = highest_vcn + 1; + + /* Only one extent or error, which we catch below. */ + if (next_vcn <= 0) { + errno = ENOENT; + break; + } + + /* Avoid endless loops due to corruption. */ + if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { + errno = EIO; + ntfs_log_perror("Inode %llu has corrupt attribute list", + (unsigned long long)na->ni->mft_no); + goto err_out; + } + } + if (!a) { + ntfs_log_perror("Couldn't find attribute for runlist mapping"); + goto err_out; + } + if (highest_vcn && highest_vcn != last_vcn - 1) { + errno = EIO; + ntfs_log_perror("Failed to load full runlist: inode: %llu " + "highest_vcn: 0x%llx last_vcn: 0x%llx", + (unsigned long long)na->ni->mft_no, + (long long)highest_vcn, (long long)last_vcn); + goto err_out; + } + if (errno == ENOENT) + ret = 0; +err_out: + ntfs_attr_put_search_ctx(ctx); +out: + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_vcn_to_lcn - convert a vcn into a lcn given an ntfs attribute + * @na: ntfs attribute whose runlist to use for conversion + * @vcn: vcn to convert + * + * Convert the virtual cluster number @vcn of an attribute into a logical + * cluster number (lcn) of a device using the runlist @na->rl to map vcns to + * their corresponding lcns. + * + * If the @vcn is not mapped yet, attempt to map the attribute extent + * containing the @vcn and retry the vcn to lcn conversion. + * + * Since lcns must be >= 0, we use negative return values with special meaning: + * + * Return value Meaning / Description + * ========================================== + * -1 = LCN_HOLE Hole / not allocated on disk. + * -3 = LCN_ENOENT There is no such vcn in the attribute. + * -4 = LCN_EINVAL Input parameter error. + * -5 = LCN_EIO Corrupt fs, disk i/o error, or not enough memory. + */ +LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn) +{ + LCN lcn; + BOOL is_retry = FALSE; + + if (!na || !NAttrNonResident(na) || vcn < 0) + return (LCN)LCN_EINVAL; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); +retry: + /* Convert vcn to lcn. If that fails map the runlist and retry once. */ + lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); + if (lcn >= 0) + return lcn; + if (!is_retry && !ntfs_attr_map_runlist(na, vcn)) { + is_retry = TRUE; + goto retry; + } + /* + * If the attempt to map the runlist failed, or we are getting + * LCN_RL_NOT_MAPPED despite having mapped the attribute extent + * successfully, something is really badly wrong... + */ + if (!is_retry || lcn == (LCN)LCN_RL_NOT_MAPPED) + return (LCN)LCN_EIO; + /* lcn contains the appropriate error code. */ + return lcn; +} + +/** + * ntfs_attr_find_vcn - find a vcn in the runlist of an ntfs attribute + * @na: ntfs attribute whose runlist to search + * @vcn: vcn to find + * + * Find the virtual cluster number @vcn in the runlist of the ntfs attribute + * @na and return the the address of the runlist element containing the @vcn. + * + * Note you need to distinguish between the lcn of the returned runlist + * element being >= 0 and LCN_HOLE. In the later case you have to return zeroes + * on read and allocate clusters on write. You need to update the runlist, the + * attribute itself as well as write the modified mft record to disk. + * + * If there is an error return NULL with errno set to the error code. The + * following error codes are defined: + * EINVAL Input parameter error. + * ENOENT There is no such vcn in the runlist. + * ENOMEM Not enough memory. + * EIO I/O error or corrupt metadata. + */ +runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn) +{ + runlist_element *rl; + BOOL is_retry = FALSE; + + if (!na || !NAttrNonResident(na) || vcn < 0) { + errno = EINVAL; + return NULL; + } + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn %llx\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)vcn); +retry: + rl = na->rl; + if (!rl) + goto map_rl; + if (vcn < rl[0].vcn) + goto map_rl; + while (rl->length) { + if (vcn < rl[1].vcn) { + if (rl->lcn >= (LCN)LCN_HOLE) + return rl; + break; + } + rl++; + } + switch (rl->lcn) { + case (LCN)LCN_RL_NOT_MAPPED: + goto map_rl; + case (LCN)LCN_ENOENT: + errno = ENOENT; + break; + case (LCN)LCN_EINVAL: + errno = EINVAL; + break; + default: + errno = EIO; + break; + } + return NULL; +map_rl: + /* The @vcn is in an unmapped region, map the runlist and retry. */ + if (!is_retry && !ntfs_attr_map_runlist(na, vcn)) { + is_retry = TRUE; + goto retry; + } + /* + * If we already retried or the mapping attempt failed something has + * gone badly wrong. EINVAL and ENOENT coming from a failed mapping + * attempt are equivalent to errors for us as they should not happen + * in our code paths. + */ + if (is_retry || errno == EINVAL || errno == ENOENT) + errno = EIO; + return NULL; +} + + +#endif + +/** + * ntfs_attr_pread_i - see description at ntfs_attr_pread() + */ +static s64 ntfs_attr_getfragments_i(ntfs_attr *na, const s64 pos, s64 count, u64 offset, + _ntfs_frag_append_t append_fragment, void *callback_data) +{ + u64 b = offset; + s64 br, to_read, ofs, total, total2, max_read, max_init; + ntfs_volume *vol; + runlist_element *rl; + //u16 efs_padding_length; + + /* Sanity checking arguments is done in ntfs_attr_pread(). */ + + if ((na->data_flags & ATTR_COMPRESSION_MASK) && NAttrNonResident(na)) + { + //return -1; // no compressed files + return -31; + /* + if ((na->data_flags & ATTR_COMPRESSION_MASK) + == ATTR_IS_COMPRESSED) + return ntfs_compressed_attr_pread(na, pos, count, b); + else { + // compression mode not supported + errno = EOPNOTSUPP; + return -1; + } + */ + } + /* + * Encrypted non-resident attributes are not supported. We return + * access denied, which is what Windows NT4 does, too. + * However, allow if mounted with efs_raw option + */ + vol = na->ni->vol; + if (!vol->efs_raw && NAttrEncrypted(na) && NAttrNonResident(na)) { + errno = EACCES; + //return -1; + return -32; + } + + if (!count) + return 0; + /* + * Truncate reads beyond end of attribute, + * but round to next 512 byte boundary for encrypted + * attributes with efs_raw mount option + */ + max_read = na->data_size; + max_init = na->initialized_size; + if (na->ni->vol->efs_raw + && (na->data_flags & ATTR_IS_ENCRYPTED) + && NAttrNonResident(na)) { + if (na->data_size != na->initialized_size) { + ntfs_log_error("uninitialized encrypted file not supported\n"); + errno = EINVAL; + //return -1; + return -33; + } + max_init = max_read = ((na->data_size + 511) & ~511) + 2; + } + if (pos + count > max_read) { + if (pos >= max_read) + return 0; + count = max_read - pos; + } + /* If it is a resident attribute, get the value from the mft record. */ + if (!NAttrNonResident(na)) + { + return -34; // No resident files + /* + ntfs_attr_search_ctx *ctx; + char *val; + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, + 0, NULL, 0, ctx)) { +res_err_out: + ntfs_attr_put_search_ctx(ctx); + return -1; + } + val = (char*)ctx->attr + le16_to_cpu(ctx->attr->value_offset); + if (val < (char*)ctx->attr || val + + le32_to_cpu(ctx->attr->value_length) > + (char*)ctx->mrec + vol->mft_record_size) { + errno = EIO; + ntfs_log_perror("%s: Sanity check failed", __FUNCTION__); + goto res_err_out; + } + memcpy(b, val + pos, count); + ntfs_attr_put_search_ctx(ctx); + return count; + */ + } + total = total2 = 0; + /* Zero out reads beyond initialized size. */ + if (pos + count > max_init) { + if (pos >= max_init) { + //memset(b, 0, count); + return count; + } + total2 = pos + count - max_init; + count -= total2; + //memset((u8*)b + count, 0, total2); + } + /* + * for encrypted non-resident attributes with efs_raw set + * the last two bytes aren't read from disk but contain + * the number of padding bytes so original size can be + * restored + */ + if (na->ni->vol->efs_raw && + (na->data_flags & ATTR_IS_ENCRYPTED) && + ((pos + count) > max_init-2)) + { + return -35; //No encrypted files + /* + efs_padding_length = 511 - ((na->data_size - 1) & 511); + if (pos+count == max_init) { + if (count == 1) { + *((u8*)b+count-1) = (u8)(efs_padding_length >> 8); + count--; + total2++; + } else { + *(u16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); + count -= 2; + total2 +=2; + } + } else { + *((u8*)b+count-1) = (u8)(efs_padding_length & 0xff); + count--; + total2++; + } + */ + } + + /* Find the runlist element containing the vcn. */ + rl = ntfs_attr_find_vcn(na, pos >> vol->cluster_size_bits); + if (!rl) { + /* + * If the vcn is not present it is an out of bounds read. + * However, we already truncated the read to the data_size, + * so getting this here is an error. + */ + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #1", __FUNCTION__); + } + //return -1; + return -36; + } + /* + * Gather the requested data into the linear destination buffer. Note, + * a partial final vcn is taken care of by the @count capping of read + * length. + */ + ofs = pos - (rl->vcn << vol->cluster_size_bits); + for (; count; rl++, ofs = 0) { + if (rl->lcn == LCN_RL_NOT_MAPPED) { + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl) { + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #2", + __FUNCTION__); + } + goto rl_err_out; + } + /* Needed for case when runs merged. */ + ofs = pos + total - (rl->vcn << vol->cluster_size_bits); + } + if (!rl->length) { + errno = EIO; + ntfs_log_perror("%s: Zero run length", __FUNCTION__); + goto rl_err_out; + } + if (rl->lcn < (LCN)0) { + if (rl->lcn != (LCN)LCN_HOLE) { + ntfs_log_perror("%s: Bad run (%lld)", + __FUNCTION__, + (long long)rl->lcn); + goto rl_err_out; + } + /* It is a hole, just zero the matching @b range. */ + to_read = min(count, (rl->length << + vol->cluster_size_bits) - ofs); + //memset(b, 0, to_read); + /* Update progress counters. */ + total += to_read; + count -= to_read; + b = b + to_read; + continue; + } + /* It is a real lcn, read it into @dst. */ + to_read = min(count, (rl->length << vol->cluster_size_bits) - + ofs); +retry: + ntfs_log_trace("Reading %lld bytes from vcn %lld, lcn %lld, ofs" + " %lld.\n", (long long)to_read, (long long)rl->vcn, + (long long )rl->lcn, (long long)ofs); + /* + br = ntfs_pread(vol->dev, (rl->lcn << vol->cluster_size_bits) + + ofs, to_read, b); + */ + br = to_read; + // convert to sectors unit + u32 off_sec = b >> 9; + u32 sector = ((rl->lcn << vol->cluster_size_bits) + ofs) >> 9; + u32 count_sec = to_read >> 9; + int ret; + ret = append_fragment(callback_data, off_sec, sector, count_sec); + if (ret) { + if (ret < 0) return ret; + return -50; + } + /* If everything ok, update progress counters and continue. */ + if (br > 0) { + total += br; + count -= br; + b = b + br; + } + if (br == to_read) + continue; + /* If the syscall was interrupted, try again. */ + if (br == (s64)-1 && errno == EINTR) + goto retry; + if (total) + return total; + if (!br) + errno = EIO; + ntfs_log_perror("%s: ntfs_pread failed", __FUNCTION__); + //return -1; + return -38; + } + /* Finally, return the number of bytes read. */ + return total + total2; +rl_err_out: + if (total) + return total; + errno = EIO; + //return -1; + return -39; +} + + +/** + * ntfs_attr_pread - read from an attribute specified by an ntfs_attr structure + * @na: ntfs attribute to read from + * @pos: byte position in the attribute to begin reading from + * @count: number of bytes to read + * @b: output data buffer + * + * This function will read @count bytes starting at offset @pos from the ntfs + * attribute @na into the data buffer @b. + * + * On success, return the number of successfully read bytes. If this number is + * lower than @count this means that the read reached end of file or that an + * error was encountered during the read so that the read is partial. 0 means + * end of file or nothing was read (also return 0 when @count is 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of ntfs_pread(), or to EINVAL in case of invalid + * arguments. + */ +s64 ntfs_attr_getfragments(ntfs_attr *na, const s64 pos, s64 count, u64 offset, + _ntfs_frag_append_t append_fragment, void *callback_data) +{ + s64 ret; + + if (!na || !na->ni || !na->ni->vol || !callback_data || pos < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("%s: na=%p b=%p pos=%lld count=%lld", + __FUNCTION__, na, callback_data, (long long)pos, + (long long)count); + //return -1; + return -21; + } + + /* + ntfs_log_enter("Entering for inode %lld attr 0x%x pos %lld count " + "%lld\n", (unsigned long long)na->ni->mft_no, + na->type, (long long)pos, (long long)count); + */ + + ret = ntfs_attr_getfragments_i(na, pos, count, offset, + append_fragment, callback_data); + + //ntfs_log_leave("\n"); + return ret; +} + +#if 0 + +static int ntfs_attr_fill_zero(ntfs_attr *na, s64 pos, s64 count) +{ + char *buf; + s64 written, size, end = pos + count; + s64 ofsi; + const runlist_element *rli; + ntfs_volume *vol; + int ret = -1; + + ntfs_log_trace("pos %lld, count %lld\n", (long long)pos, + (long long)count); + + if (!na || pos < 0 || count < 0) { + errno = EINVAL; + goto err_out; + } + + buf = ntfs_calloc(NTFS_BUF_SIZE); + if (!buf) + goto err_out; + + rli = na->rl; + ofsi = 0; + vol = na->ni->vol; + while (pos < end) { + while (rli->length && (ofsi + (rli->length << + vol->cluster_size_bits) <= pos)) { + ofsi += (rli->length << vol->cluster_size_bits); + rli++; + } + size = min(end - pos, NTFS_BUF_SIZE); + written = ntfs_rl_pwrite(vol, rli, ofsi, pos, size, buf); + if (written <= 0) { + ntfs_log_perror("Failed to zero space"); + goto err_free; + } + pos += written; + } + + ret = 0; +err_free: + free(buf); +err_out: + return ret; +} + +static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, + runlist_element **rl, VCN *update_from) +{ + s64 to_write; + s64 need; + ntfs_volume *vol = na->ni->vol; + int eo, ret = -1; + runlist *rlc; + LCN lcn_seek_from = -1; + VCN cur_vcn, from_vcn; + + to_write = min(count, ((*rl)->length << vol->cluster_size_bits) - *ofs); + + cur_vcn = (*rl)->vcn; + from_vcn = (*rl)->vcn + (*ofs >> vol->cluster_size_bits); + + ntfs_log_trace("count: %lld, cur_vcn: %lld, from: %lld, to: %lld, ofs: " + "%lld\n", (long long)count, (long long)cur_vcn, + (long long)from_vcn, (long long)to_write, (long long)*ofs); + + /* Map whole runlist to be able update mapping pairs later. */ + if (ntfs_attr_map_whole_runlist(na)) + goto err_out; + + /* Restore @*rl, it probably get lost during runlist mapping. */ + *rl = ntfs_attr_find_vcn(na, cur_vcn); + if (!*rl) { + ntfs_log_error("Failed to find run after mapping runlist. " + "Please report to %s.\n", NTFS_DEV_LIST); + errno = EIO; + goto err_out; + } + + /* Search backwards to find the best lcn to start seek from. */ + rlc = *rl; + while (rlc->vcn) { + rlc--; + if (rlc->lcn >= 0) { + /* + * avoid fragmenting a compressed file + * Windows does not do that, and that may + * not be desirable for files which can + * be updated + */ + if (na->data_flags & ATTR_COMPRESSION_MASK) + lcn_seek_from = rlc->lcn + rlc->length; + else + lcn_seek_from = rlc->lcn + (from_vcn - rlc->vcn); + break; + } + } + if (lcn_seek_from == -1) { + /* Backwards search failed, search forwards. */ + rlc = *rl; + while (rlc->length) { + rlc++; + if (rlc->lcn >= 0) { + lcn_seek_from = rlc->lcn - (rlc->vcn - from_vcn); + if (lcn_seek_from < -1) + lcn_seek_from = -1; + break; + } + } + } + + need = ((*ofs + to_write - 1) >> vol->cluster_size_bits) + + 1 + (*rl)->vcn - from_vcn; + if ((na->data_flags & ATTR_COMPRESSION_MASK) + && (need < na->compression_block_clusters)) { + /* + * for a compressed file, be sure to allocate the full hole. + * We may need space to decompress existing compressed data. + */ + rlc = ntfs_cluster_alloc(vol, (*rl)->vcn, (*rl)->length, + lcn_seek_from, DATA_ZONE); + } else + rlc = ntfs_cluster_alloc(vol, from_vcn, need, + lcn_seek_from, DATA_ZONE); + if (!rlc) + goto err_out; + + *rl = ntfs_runlists_merge(na->rl, rlc); + /* + * For a compressed attribute, we must be sure there is an + * available entry, so reserve it before it gets too late. + */ + if (*rl && (na->data_flags & ATTR_COMPRESSION_MASK)) + *rl = ntfs_rl_extend(*rl,1); + if (!*rl) { + eo = errno; + ntfs_log_perror("Failed to merge runlists"); + if (ntfs_cluster_free_from_rl(vol, rlc)) { + ntfs_log_perror("Failed to free hot clusters. " + "Please run chkdsk /f"); + } + errno = eo; + goto err_out; + } + na->rl = *rl; + if (*update_from == -1) + *update_from = from_vcn; + *rl = ntfs_attr_find_vcn(na, cur_vcn); + if (!*rl) { + /* + * It's definitely a BUG, if we failed to find @cur_vcn, because + * we missed it during instantiating of the hole. + */ + ntfs_log_error("Failed to find run after hole instantiation. " + "Please report to %s.\n", NTFS_DEV_LIST); + errno = EIO; + goto err_out; + } + /* If leaved part of the hole go to the next run. */ + if ((*rl)->lcn < 0) + (*rl)++; + /* Now LCN shoudn't be less than 0. */ + if ((*rl)->lcn < 0) { + ntfs_log_error("BUG! LCN is lesser than 0. " + "Please report to the %s.\n", NTFS_DEV_LIST); + errno = EIO; + goto err_out; + } + if (*ofs) { + /* Clear non-sparse region from @cur_vcn to @*ofs. */ + if (ntfs_attr_fill_zero(na, cur_vcn << vol->cluster_size_bits, + *ofs)) + goto err_out; + } + if ((*rl)->vcn < cur_vcn) { + /* + * Clusters that replaced hole are merged with + * previous run, so we need to update offset. + */ + *ofs += (cur_vcn - (*rl)->vcn) << vol->cluster_size_bits; + } + if ((*rl)->vcn > cur_vcn) { + /* + * We left part of the hole, so we need to update offset + */ + *ofs -= ((*rl)->vcn - cur_vcn) << vol->cluster_size_bits; + } + + ret = 0; +err_out: + return ret; +} + +static int stuff_hole(ntfs_attr *na, const s64 pos); + +/** + * ntfs_attr_pwrite - positioned write to an ntfs attribute + * @na: ntfs attribute to write to + * @pos: position in the attribute to write to + * @count: number of bytes to write + * @b: data buffer to write to disk + * + * This function will write @count bytes from data buffer @b to ntfs attribute + * @na at position @pos. + * + * On success, return the number of successfully written bytes. If this number + * is lower than @count this means that an error was encountered during the + * write so that the write is partial. 0 means nothing was written (also return + * 0 when @count is 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of ntfs_pwrite(), or to EINVAL in case of + * invalid arguments. + */ +s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) +{ + s64 written, to_write, ofs, old_initialized_size, old_data_size; + s64 total = 0; + VCN update_from = -1; + ntfs_volume *vol; + s64 fullcount; + ntfs_attr_search_ctx *ctx = NULL; + runlist_element *rl; + s64 hole_end; + int eo; + int compressed_part; + struct { + unsigned int undo_initialized_size : 1; + unsigned int undo_data_size : 1; + } need_to = { 0, 0 }; + BOOL makingnonresident = FALSE; + BOOL wasnonresident = FALSE; + BOOL compressed; + + ntfs_log_enter("Entering for inode %lld, attr 0x%x, pos 0x%llx, count " + "0x%llx.\n", (long long)na->ni->mft_no, na->type, + (long long)pos, (long long)count); + + if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + goto errno_set; + } + vol = na->ni->vol; + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + /* + * Encrypted attributes are only supported in raw mode. We return + * access denied, which is what Windows NT4 does, too. + * Moreover a file cannot be both encrypted and compressed. + */ + if ((na->data_flags & ATTR_IS_ENCRYPTED) + && (compressed || !vol->efs_raw)) { + errno = EACCES; + goto errno_set; + } + /* + * Fill the gap, when writing beyond the end of a compressed + * file. This will make recursive calls + */ + if (compressed + && (na->type == AT_DATA) + && (pos > na->initialized_size) + && stuff_hole(na,pos)) + goto errno_set; + /* If this is a compressed attribute it needs special treatment. */ + wasnonresident = NAttrNonResident(na) != 0; + makingnonresident = wasnonresident /* yes : already changed */ + && !pos && (count == na->initialized_size); + /* + * Writing to compressed files is currently restricted + * to appending data. However we have to accept + * recursive write calls to make the attribute non resident. + * These are writing at position 0 up to initialized_size. + * Compression is also restricted to data streams. + * Only ATTR_IS_COMPRESSED compression mode is supported. + */ + if (compressed + && ((na->type != AT_DATA) + || ((na->data_flags & ATTR_COMPRESSION_MASK) + != ATTR_IS_COMPRESSED) + || ((pos != na->initialized_size) + && (pos || (count != na->initialized_size))))) { + // TODO: Implement writing compressed attributes! (AIA) + errno = EOPNOTSUPP; + goto errno_set; + } + + if (!count) + goto out; + /* for a compressed file, get prepared to reserve a full block */ + fullcount = count; + /* If the write reaches beyond the end, extend the attribute. */ + old_data_size = na->data_size; + if (pos + count > na->data_size) { + if (ntfs_attr_truncate(na, pos + count)) { + ntfs_log_perror("Failed to enlarge attribute"); + goto errno_set; + } + /* resizing may change the compression mode */ + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + need_to.undo_data_size = 1; + } + /* + * For compressed data, a single full block was allocated + * to deal with compression, possibly in a previous call. + * We are not able to process several blocks because + * some clusters are freed after compression and + * new allocations have to be done before proceeding, + * so truncate the requested count if needed (big buffers). + */ + if (compressed) { + fullcount = na->data_size - pos; + if (count > fullcount) + count = fullcount; + } + old_initialized_size = na->initialized_size; + /* If it is a resident attribute, write the data to the mft record. */ + if (!NAttrNonResident(na)) { + char *val; + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + goto err_out; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, + 0, NULL, 0, ctx)) { + ntfs_log_perror("%s: lookup failed", __FUNCTION__); + goto err_out; + } + val = (char*)ctx->attr + le16_to_cpu(ctx->attr->value_offset); + if (val < (char*)ctx->attr || val + + le32_to_cpu(ctx->attr->value_length) > + (char*)ctx->mrec + vol->mft_record_size) { + errno = EIO; + ntfs_log_perror("%s: Sanity check failed", __FUNCTION__); + goto err_out; + } + memcpy(val + pos, b, count); + if (ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, + ctx->mrec)) { + /* + * NOTE: We are in a bad state at this moment. We have + * dirtied the mft record but we failed to commit it to + * disk. Since we have read the mft record ok before, + * it is unlikely to fail writing it, so is ok to just + * return error here... (AIA) + */ + ntfs_log_perror("%s: failed to write mft record", __FUNCTION__); + goto err_out; + } + ntfs_attr_put_search_ctx(ctx); + total = count; + goto out; + } + + /* Handle writes beyond initialized_size. */ + if (pos + count > na->initialized_size) { + if (ntfs_attr_map_whole_runlist(na)) + goto err_out; + /* + * For a compressed attribute, we must be sure there is an + * available entry, and, when reopening a compressed file, + * we may need to split a hole. So reserve the entries + * before it gets too late. + */ + if (compressed) { + na->rl = ntfs_rl_extend(na->rl,2); + if (!na->rl) + goto err_out; + } + /* Set initialized_size to @pos + @count. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + goto err_out; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, + 0, NULL, 0, ctx)) + goto err_out; + + /* If write starts beyond initialized_size, zero the gap. */ + if (pos > na->initialized_size) + if (ntfs_attr_fill_zero(na, na->initialized_size, + pos - na->initialized_size)) + goto err_out; + + ctx->attr->initialized_size = cpu_to_sle64(pos + count); + /* fix data_size for compressed files */ + if (compressed) + ctx->attr->data_size = ctx->attr->initialized_size; + if (ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, + ctx->mrec)) { + /* + * Undo the change in the in-memory copy and send it + * back for writing. + */ + ctx->attr->initialized_size = + cpu_to_sle64(old_initialized_size); + ntfs_mft_record_write(vol, ctx->ntfs_ino->mft_no, + ctx->mrec); + goto err_out; + } + na->initialized_size = pos + count; + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + /* + * NOTE: At this point the initialized_size in the mft record + * has been updated BUT there is random data on disk thus if + * we decide to abort, we MUST change the initialized_size + * again. + */ + need_to.undo_initialized_size = 1; + } + /* Find the runlist element containing the vcn. */ + rl = ntfs_attr_find_vcn(na, pos >> vol->cluster_size_bits); + if (!rl) { + /* + * If the vcn is not present it is an out of bounds write. + * However, we already extended the size of the attribute, + * so getting this here must be an error of some kind. + */ + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #3", __FUNCTION__); + } + goto err_out; + } + ofs = pos - (rl->vcn << vol->cluster_size_bits); + /* + * Determine if there is compressed data in the current + * compression block (when appending to an existing file). + * If so, decompression will be needed, and the full block + * must be allocated to be identified as uncompressed. + * This comes in two variants, depending on whether + * compression has saved at least one cluster. + * The compressed size can never be over full size by + * more than 485 (maximum for 15 compression blocks + * compressed to 4098 and the last 3640 bytes compressed + * to 3640 + 3640/8 = 4095, with 15*2 + 4095 - 3640 = 485) + * This is less than the smallest cluster, so the hole is + * is never beyond the cluster next to the position of + * the first uncompressed byte to write. + */ + compressed_part = 0; + if (compressed) { + if ((rl->lcn == (LCN)LCN_HOLE) + && wasnonresident) { + if (rl->length < na->compression_block_clusters) + compressed_part + = na->compression_block_clusters + - rl->length; + else { + compressed_part + = na->compression_block_clusters; + if (rl->length > na->compression_block_clusters) { + rl[2].lcn = rl[1].lcn; + rl[2].vcn = rl[1].vcn; + rl[2].length = rl[1].length; + rl[1].vcn -= compressed_part; + rl[1].lcn = LCN_HOLE; + rl[1].length = compressed_part; + rl[0].length -= compressed_part; + ofs -= rl->length << vol->cluster_size_bits; + rl++; + } + } + /* normal hole filling will do later */ + } else + if ((rl->lcn >= 0) && (rl[1].lcn == (LCN)LCN_HOLE)) { + s64 xofs; + + if (wasnonresident) + compressed_part = na->compression_block_clusters + - rl[1].length; + rl++; + xofs = 0; + if (ntfs_attr_fill_hole(na, + rl->length << vol->cluster_size_bits, + &xofs, &rl, &update_from)) + goto err_out; + /* the fist allocated cluster was not merged */ + if (!xofs) + rl--; + } + } + /* + * Scatter the data from the linear data buffer to the volume. Note, a + * partial final vcn is taken care of by the @count capping of write + * length. + */ + for (hole_end = 0; count; rl++, ofs = 0, hole_end = 0) { + if (rl->lcn == LCN_RL_NOT_MAPPED) { + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl) { + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN" + " #4", __FUNCTION__); + } + goto rl_err_out; + } + /* Needed for case when runs merged. */ + ofs = pos + total - (rl->vcn << vol->cluster_size_bits); + } + if (!rl->length) { + errno = EIO; + ntfs_log_perror("%s: Zero run length", __FUNCTION__); + goto rl_err_out; + } + if (rl->lcn < (LCN)0) { + hole_end = rl->vcn + rl->length; + + if (rl->lcn != (LCN)LCN_HOLE) { + errno = EIO; + ntfs_log_perror("%s: Unexpected LCN (%lld)", + __FUNCTION__, + (long long)rl->lcn); + goto rl_err_out; + } + if (ntfs_attr_fill_hole(na, fullcount, &ofs, &rl, + &update_from)) + goto err_out; + } + if (compressed) { + while (rl->length + && (ofs >= (rl->length << vol->cluster_size_bits))) { + ofs -= rl->length << vol->cluster_size_bits; + rl++; + } + } + + /* It is a real lcn, write it to the volume. */ + to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs); +retry: + ntfs_log_trace("Writing %lld bytes to vcn %lld, lcn %lld, ofs " + "%lld.\n", (long long)to_write, (long long)rl->vcn, + (long long)rl->lcn, (long long)ofs); + if (!NVolReadOnly(vol)) { + + s64 wpos = (rl->lcn << vol->cluster_size_bits) + ofs; + s64 wend = (rl->vcn << vol->cluster_size_bits) + ofs + to_write; + u32 bsize = vol->cluster_size; + /* Byte size needed to zero fill a cluster */ + s64 rounding = ((wend + bsize - 1) & ~(s64)(bsize - 1)) - wend; + /** + * Zero fill to cluster boundary if we're writing at the + * end of the attribute or into an ex-sparse cluster. + * This will cause the kernel not to seek and read disk + * blocks during write(2) to fill the end of the buffer + * which increases write speed by 2-10 fold typically. + * + * This is done even for compressed files, because + * data is generally first written uncompressed. + */ + if (rounding && ((wend == na->initialized_size) || + (wend < (hole_end << vol->cluster_size_bits)))){ + + char *cb; + + rounding += to_write; + + cb = ntfs_malloc(rounding); + if (!cb) + goto err_out; + + memcpy(cb, b, to_write); + memset(cb + to_write, 0, rounding - to_write); + + if (compressed) { + written = ntfs_compressed_pwrite(na, + rl, wpos, ofs, to_write, + rounding, b, compressed_part); + } else { + written = ntfs_pwrite(vol->dev, wpos, + rounding, cb); + if (written == rounding) + written = to_write; + } + + free(cb); + } else { + if (compressed) { + written = ntfs_compressed_pwrite(na, + rl, wpos, ofs, to_write, + to_write, b, compressed_part); + } else + written = ntfs_pwrite(vol->dev, wpos, + to_write, b); + } + } else + written = to_write; + /* If everything ok, update progress counters and continue. */ + if (written > 0) { + total += written; + count -= written; + fullcount -= written; + b = (const u8*)b + written; + } + if (written != to_write) { + /* Partial write cannot be dealt with, stop there */ + /* If the syscall was interrupted, try again. */ + if (written == (s64)-1 && errno == EINTR) + goto retry; + if (!written) + errno = EIO; + goto rl_err_out; + } + compressed_part = 0; + } +done: + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + if ((update_from != -1) + || (compressed && !makingnonresident)) + if (ntfs_attr_update_mapping_pairs(na, 0 /*update_from*/)) { + /* + * FIXME: trying to recover by goto rl_err_out; + * could cause driver hang by infinite looping. + */ + total = -1; + goto out; + } +out: + ntfs_log_leave("\n"); + return total; +rl_err_out: + eo = errno; + if (total) { + if (need_to.undo_initialized_size) { + if (pos + total > na->initialized_size) + goto done; + /* + * TODO: Need to try to change initialized_size. If it + * succeeds goto done, otherwise goto err_out. (AIA) + */ + goto err_out; + } + goto done; + } + errno = eo; +err_out: + eo = errno; + if (need_to.undo_initialized_size) { + int err; + + err = 0; + if (!ctx) { + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + err = 1; + } else + ntfs_attr_reinit_search_ctx(ctx); + if (!err) { + err = ntfs_attr_lookup(na->type, na->name, + na->name_len, 0, 0, NULL, 0, ctx); + if (!err) { + na->initialized_size = old_initialized_size; + ctx->attr->initialized_size = cpu_to_sle64( + old_initialized_size); + err = ntfs_mft_record_write(vol, + ctx->ntfs_ino->mft_no, + ctx->mrec); + } + } + if (err) { + /* + * FIXME: At this stage could try to recover by filling + * old_initialized_size -> new_initialized_size with + * data or at least zeroes. (AIA) + */ + ntfs_log_error("Eeek! Failed to recover from error. " + "Leaving metadata in inconsistent " + "state! Run chkdsk!\n"); + } + } + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + if (update_from != -1) + ntfs_attr_update_mapping_pairs(na, 0 /*update_from*/); + /* Restore original data_size if needed. */ + if (need_to.undo_data_size && ntfs_attr_truncate(na, old_data_size)) + ntfs_log_perror("Failed to restore data_size"); + errno = eo; +errno_set: + total = -1; + goto out; +} + +int ntfs_attr_pclose(ntfs_attr *na) +{ + s64 written, ofs; + BOOL ok = TRUE; + VCN update_from = -1; + ntfs_volume *vol; + ntfs_attr_search_ctx *ctx = NULL; + runlist_element *rl; + int eo; + s64 hole; + int compressed_part; + BOOL compressed; + + ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x.\n", + na->ni->mft_no, na->type); + + if (!na || !na->ni || !na->ni->vol) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + goto errno_set; + } + vol = na->ni->vol; + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + /* + * Encrypted non-resident attributes are not supported. We return + * access denied, which is what Windows NT4 does, too. + */ + if (NAttrEncrypted(na) && NAttrNonResident(na)) { + errno = EACCES; + goto errno_set; + } + /* If this is not a compressed attribute get out */ + /* same if it is resident */ + if (!compressed || !NAttrNonResident(na)) + goto out; + + /* + * For a compressed attribute, we must be sure there is an + * available entry, so reserve it before it gets too late. + */ + if (ntfs_attr_map_whole_runlist(na)) + goto err_out; + na->rl = ntfs_rl_extend(na->rl,1); + if (!na->rl) + goto err_out; + /* Find the runlist element containing the terminal vcn. */ + rl = ntfs_attr_find_vcn(na, (na->initialized_size - 1) >> vol->cluster_size_bits); + if (!rl) { + /* + * If the vcn is not present it is an out of bounds write. + * However, we have already written the last byte uncompressed, + * so getting this here must be an error of some kind. + */ + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN #5", __FUNCTION__); + } + goto err_out; + } + /* + * Scatter the data from the linear data buffer to the volume. Note, a + * partial final vcn is taken care of by the @count capping of write + * length. + */ + compressed_part = 0; + if ((rl->lcn >= 0) && (rl[1].lcn == (LCN)LCN_HOLE)) + compressed_part + = na->compression_block_clusters - rl[1].length; + else + if (rl->lcn == (LCN)LCN_HOLE) { + if (rl->length < na->compression_block_clusters) + compressed_part + = na->compression_block_clusters + - rl->length; + else + compressed_part + = na->compression_block_clusters; + } + /* done, if the last block set was compressed */ + if (compressed_part) + goto out; + + ofs = na->initialized_size - (rl->vcn << vol->cluster_size_bits); + + if (rl->lcn == LCN_RL_NOT_MAPPED) { + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl) { + if (errno == ENOENT) { + errno = EIO; + ntfs_log_perror("%s: Failed to find VCN" + " #6", __FUNCTION__); + } + goto rl_err_out; + } + /* Needed for case when runs merged. */ + ofs = na->initialized_size - (rl->vcn << vol->cluster_size_bits); + } + if (!rl->length) { + errno = EIO; + ntfs_log_perror("%s: Zero run length", __FUNCTION__); + goto rl_err_out; + } + if (rl->lcn < (LCN)0) { + hole = rl->vcn + rl->length; + if (rl->lcn != (LCN)LCN_HOLE) { + errno = EIO; + ntfs_log_perror("%s: Unexpected LCN (%lld)", + __FUNCTION__, + (long long)rl->lcn); + goto rl_err_out; + } + + if (ntfs_attr_fill_hole(na, (s64)0, &ofs, &rl, &update_from)) + goto err_out; + } + while (rl->length + && (ofs >= (rl->length << vol->cluster_size_bits))) { + ofs -= rl->length << vol->cluster_size_bits; + rl++; + } + +retry: + if (!NVolReadOnly(vol)) { + + written = ntfs_compressed_close(na, rl, ofs); + /* If everything ok, update progress counters and continue. */ + if (!written) + goto done; + } + /* If the syscall was interrupted, try again. */ + if (written == (s64)-1 && errno == EINTR) + goto retry; + if (!written) + errno = EIO; + goto rl_err_out; + +done: + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*update_from*/)) { + /* + * FIXME: trying to recover by goto rl_err_out; + * could cause driver hang by infinite looping. + */ + ok = FALSE; + goto out; + } +out: + ntfs_log_leave("\n"); + return (!ok); +rl_err_out: + /* + * need not restore old sizes, only compressed_size + * can have changed. It has been set according to + * the current runlist while updating the mapping pairs, + * and must be kept consistent with the runlists. + */ +err_out: + eo = errno; + if (ctx) + ntfs_attr_put_search_ctx(ctx); + /* Update mapping pairs if needed. */ + ntfs_attr_update_mapping_pairs(na, 0 /*update_from*/); + errno = eo; +errno_set: + ok = FALSE; + goto out; +} + +/** + * ntfs_attr_mst_pread - multi sector transfer protected ntfs attribute read + * @na: multi sector transfer protected ntfs attribute to read from + * @pos: byte position in the attribute to begin reading from + * @bk_cnt: number of mst protected blocks to read + * @bk_size: size of each mst protected block in bytes + * @dst: output data buffer + * + * This function will read @bk_cnt blocks of size @bk_size bytes each starting + * at offset @pos from the ntfs attribute @na into the data buffer @b. + * + * On success, the multi sector transfer fixups are applied and the number of + * read blocks is returned. If this number is lower than @bk_cnt this means + * that the read has either reached end of attribute or that an error was + * encountered during the read so that the read is partial. 0 means end of + * attribute or nothing to read (also return 0 when @bk_cnt or @bk_size are 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of ntfs_attr_pread() or to EINVAL in case of invalid + * arguments. + * + * NOTE: If an incomplete multi sector transfer is detected the magic is + * changed to BAAD but no error is returned, i.e. it is possible that any of + * the returned blocks have multi sector transfer errors. This should be + * detected by the caller by checking each block with is_baad_recordp(&block). + * The reasoning is that we want to fixup as many blocks as possible and we + * want to return even bad ones to the caller so, e.g. in case of ntfsck, the + * errors can be repaired. + */ +s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, + const u32 bk_size, void *dst) +{ + s64 br; + u8 *end; + + ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos); + if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + br = ntfs_attr_pread(na, pos, bk_cnt * bk_size, dst); + if (br <= 0) + return br; + br /= bk_size; + for (end = (u8*)dst + br * bk_size; (u8*)dst < end; dst = (u8*)dst + + bk_size) + ntfs_mst_post_read_fixup((NTFS_RECORD*)dst, bk_size); + /* Finally, return the number of blocks read. */ + return br; +} + +/** + * ntfs_attr_mst_pwrite - multi sector transfer protected ntfs attribute write + * @na: multi sector transfer protected ntfs attribute to write to + * @pos: position in the attribute to write to + * @bk_cnt: number of mst protected blocks to write + * @bk_size: size of each mst protected block in bytes + * @src: data buffer to write to disk + * + * This function will write @bk_cnt blocks of size @bk_size bytes each from + * data buffer @b to multi sector transfer (mst) protected ntfs attribute @na + * at position @pos. + * + * On success, return the number of successfully written blocks. If this number + * is lower than @bk_cnt this means that an error was encountered during the + * write so that the write is partial. 0 means nothing was written (also + * return 0 when @bk_cnt or @bk_size are 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of ntfs_attr_pwrite(), or to EINVAL in case + * of invalid arguments. + * + * NOTE: We mst protect the data, write it, then mst deprotect it using a quick + * deprotect algorithm (no checking). This saves us from making a copy before + * the write and at the same time causes the usn to be incremented in the + * buffer. This conceptually fits in better with the idea that cached data is + * always deprotected and protection is performed when the data is actually + * going to hit the disk and the cache is immediately deprotected again + * simulating an mst read on the written data. This way cache coherency is + * achieved. + */ +s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, + const u32 bk_size, void *src) +{ + s64 written, i; + + ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos); + if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { + errno = EINVAL; + return -1; + } + if (!bk_cnt) + return 0; + /* Prepare data for writing. */ + for (i = 0; i < bk_cnt; ++i) { + int err; + + err = ntfs_mst_pre_write_fixup((NTFS_RECORD*) + ((u8*)src + i * bk_size), bk_size); + if (err < 0) { + /* Abort write at this position. */ + ntfs_log_perror("%s #1", __FUNCTION__); + if (!i) + return err; + bk_cnt = i; + break; + } + } + /* Write the prepared data. */ + written = ntfs_attr_pwrite(na, pos, bk_cnt * bk_size, src); + if (written <= 0) { + ntfs_log_perror("%s: written=%lld", __FUNCTION__, + (long long)written); + } + /* Quickly deprotect the data again. */ + for (i = 0; i < bk_cnt; ++i) + ntfs_mst_post_write_fixup((NTFS_RECORD*)((u8*)src + i * + bk_size)); + if (written <= 0) + return written; + /* Finally, return the number of complete blocks written. */ + return written / bk_size; +} + +/** + * ntfs_attr_find - find (next) attribute in mft record + * @type: attribute type to find + * @name: attribute name to find (optional, i.e. NULL means don't care) + * @name_len: attribute name length (only needed if @name present) + * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) + * @val: attribute value to find (optional, resident attributes only) + * @val_len: attribute value length + * @ctx: search context with mft record and attribute to search from + * + * You shouldn't need to call this function directly. Use lookup_attr() instead. + * + * ntfs_attr_find() takes a search context @ctx as parameter and searches the + * mft record specified by @ctx->mrec, beginning at @ctx->attr, for an + * attribute of @type, optionally @name and @val. If found, ntfs_attr_find() + * returns 0 and @ctx->attr will point to the found attribute. + * + * If not found, ntfs_attr_find() returns -1, with errno set to ENOENT and + * @ctx->attr will point to the attribute before which the attribute being + * searched for would need to be inserted if such an action were to be desired. + * + * On actual error, ntfs_attr_find() returns -1 with errno set to the error + * code but not to ENOENT. In this case @ctx->attr is undefined and in + * particular do not rely on it not changing. + * + * If @ctx->is_first is TRUE, the search begins with @ctx->attr itself. If it + * is FALSE, the search begins after @ctx->attr. + * + * If @type is AT_UNUSED, return the first found attribute, i.e. one can + * enumerate all attributes by setting @type to AT_UNUSED and then calling + * ntfs_attr_find() repeatedly until it returns -1 with errno set to ENOENT to + * indicate that there are no more entries. During the enumeration, each + * successful call of ntfs_attr_find() will return the next attribute in the + * mft record @ctx->mrec. + * + * If @type is AT_END, seek to the end and return -1 with errno set to ENOENT. + * AT_END is not a valid attribute, its length is zero for example, thus it is + * safer to return error instead of success in this case. This also allows us + * to interoperate cleanly with ntfs_external_attr_find(). + * + * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present + * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, + * match both named and unnamed attributes. + * + * If @ic is IGNORE_CASE, the @name comparison is not case sensitive and + * @ctx->ntfs_ino must be set to the ntfs inode to which the mft record + * @ctx->mrec belongs. This is so we can get at the ntfs volume and hence at + * the upcase table. If @ic is CASE_SENSITIVE, the comparison is case + * sensitive. When @name is present, @name_len is the @name length in Unicode + * characters. + * + * If @name is not present (NULL), we assume that the unnamed attribute is + * being searched for. + * + * Finally, the resident attribute value @val is looked for, if present. + * If @val is not present (NULL), @val_len is ignored. + * + * ntfs_attr_find() only searches the specified mft record and it ignores the + * presence of an attribute list attribute (unless it is the one being searched + * for, obviously). If you need to take attribute lists into consideration, use + * ntfs_attr_lookup() instead (see below). This also means that you cannot use + * ntfs_attr_find() to search for extent records of non-resident attributes, as + * extents with lowest_vcn != 0 are usually described by the attribute list + * attribute only. - Note that it is possible that the first extent is only in + * the attribute list while the last extent is in the base mft record, so don't + * rely on being able to find the first extent in the base mft record. + * + * Warning: Never use @val when looking for attribute types which can be + * non-resident as this most likely will result in a crash! + */ +static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const u8 *val, const u32 val_len, ntfs_attr_search_ctx *ctx) +{ + ATTR_RECORD *a; + ntfs_volume *vol; + ntfschar *upcase; + u32 upcase_len; + + ntfs_log_trace("attribute type 0x%x.\n", type); + + if (ctx->ntfs_ino) { + vol = ctx->ntfs_ino->vol; + upcase = vol->upcase; + upcase_len = vol->upcase_len; + } else { + if (name && name != AT_UNNAMED) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + vol = NULL; + upcase = NULL; + upcase_len = 0; + } + /* + * Iterate over attributes in mft record starting at @ctx->attr, or the + * attribute following that, if @ctx->is_first is TRUE. + */ + if (ctx->is_first) { + a = ctx->attr; + ctx->is_first = FALSE; + } else + a = (ATTR_RECORD*)((char*)ctx->attr + + le32_to_cpu(ctx->attr->length)); + for (;; a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length))) { + if (p2n(a) < p2n(ctx->mrec) || (char*)a > (char*)ctx->mrec + + le32_to_cpu(ctx->mrec->bytes_allocated)) + break; + ctx->attr = a; + if (((type != AT_UNUSED) && (le32_to_cpu(a->type) > + le32_to_cpu(type))) || + (a->type == AT_END)) { + errno = ENOENT; + return -1; + } + if (!a->length) + break; + /* If this is an enumeration return this attribute. */ + if (type == AT_UNUSED) + return 0; + if (a->type != type) + continue; + /* + * If @name is AT_UNNAMED we want an unnamed attribute. + * If @name is present, compare the two names. + * Otherwise, match any attribute. + */ + if (name == AT_UNNAMED) { + /* The search failed if the found attribute is named. */ + if (a->name_length) { + errno = ENOENT; + return -1; + } + } else if (name && !ntfs_names_are_equal(name, name_len, + (ntfschar*)((char*)a + le16_to_cpu(a->name_offset)), + a->name_length, ic, upcase, upcase_len)) { + register int rc; + + rc = ntfs_names_collate(name, name_len, + (ntfschar*)((char*)a + + le16_to_cpu(a->name_offset)), + a->name_length, 1, IGNORE_CASE, + upcase, upcase_len); + /* + * If @name collates before a->name, there is no + * matching attribute. + */ + if (rc == -1) { + errno = ENOENT; + return -1; + } + /* If the strings are not equal, continue search. */ + if (rc) + continue; + rc = ntfs_names_collate(name, name_len, + (ntfschar*)((char*)a + + le16_to_cpu(a->name_offset)), + a->name_length, 1, CASE_SENSITIVE, + upcase, upcase_len); + if (rc == -1) { + errno = ENOENT; + return -1; + } + if (rc) + continue; + } + /* + * The names match or @name not present and attribute is + * unnamed. If no @val specified, we have found the attribute + * and are done. + */ + if (!val) + return 0; + /* @val is present; compare values. */ + else { + register int rc; + + rc = memcmp(val, (char*)a +le16_to_cpu(a->value_offset), + min(val_len, + le32_to_cpu(a->value_length))); + /* + * If @val collates before the current attribute's + * value, there is no matching attribute. + */ + if (!rc) { + register u32 avl; + avl = le32_to_cpu(a->value_length); + if (val_len == avl) + return 0; + if (val_len < avl) { + errno = ENOENT; + return -1; + } + } else if (rc < 0) { + errno = ENOENT; + return -1; + } + } + } + errno = EIO; + ntfs_log_perror("%s: Corrupt inode (%lld)", __FUNCTION__, + ctx->ntfs_ino ? (long long)ctx->ntfs_ino->mft_no : -1); + return -1; +} + +void ntfs_attr_name_free(char **name) +{ + if (*name) { + free(*name); + *name = NULL; + } +} + +char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len) +{ + char *name = NULL; + int name_len; + + name_len = ntfs_ucstombs(uname, uname_len, &name, 0); + if (name_len < 0) { + ntfs_log_perror("ntfs_ucstombs"); + return NULL; + + } else if (name_len > 0) + return name; + + ntfs_attr_name_free(&name); + return NULL; +} + +/** + * ntfs_external_attr_find - find an attribute in the attribute list of an inode + * @type: attribute type to find + * @name: attribute name to find (optional, i.e. NULL means don't care) + * @name_len: attribute name length (only needed if @name present) + * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) + * @lowest_vcn: lowest vcn to find (optional, non-resident attributes only) + * @val: attribute value to find (optional, resident attributes only) + * @val_len: attribute value length + * @ctx: search context with mft record and attribute to search from + * + * You shouldn't need to call this function directly. Use ntfs_attr_lookup() + * instead. + * + * Find an attribute by searching the attribute list for the corresponding + * attribute list entry. Having found the entry, map the mft record for read + * if the attribute is in a different mft record/inode, find the attribute in + * there and return it. + * + * If @type is AT_UNUSED, return the first found attribute, i.e. one can + * enumerate all attributes by setting @type to AT_UNUSED and then calling + * ntfs_external_attr_find() repeatedly until it returns -1 with errno set to + * ENOENT to indicate that there are no more entries. During the enumeration, + * each successful call of ntfs_external_attr_find() will return the next + * attribute described by the attribute list of the base mft record described + * by the search context @ctx. + * + * If @type is AT_END, seek to the end of the base mft record ignoring the + * attribute list completely and return -1 with errno set to ENOENT. AT_END is + * not a valid attribute, its length is zero for example, thus it is safer to + * return error instead of success in this case. + * + * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present + * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, + * match both named and unnamed attributes. + * + * On first search @ctx->ntfs_ino must be the inode of the base mft record and + * @ctx must have been obtained from a call to ntfs_attr_get_search_ctx(). + * On subsequent calls, @ctx->ntfs_ino can be any extent inode, too + * (@ctx->base_ntfs_ino is then the base inode). + * + * After finishing with the attribute/mft record you need to call + * ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any + * mapped extent inodes, etc). + * + * Return 0 if the search was successful and -1 if not, with errno set to the + * error code. + * + * On success, @ctx->attr is the found attribute, it is in mft record + * @ctx->mrec, and @ctx->al_entry is the attribute list entry for this + * attribute with @ctx->base_* being the base mft record to which @ctx->attr + * belongs. + * + * On error ENOENT, i.e. attribute not found, @ctx->attr is set to the + * attribute which collates just after the attribute being searched for in the + * base ntfs inode, i.e. if one wants to add the attribute to the mft record + * this is the correct place to insert it into, and if there is not enough + * space, the attribute should be placed in an extent mft record. + * @ctx->al_entry points to the position within @ctx->base_ntfs_ino->attr_list + * at which the new attribute's attribute list entry should be inserted. The + * other @ctx fields, base_ntfs_ino, base_mrec, and base_attr are set to NULL. + * The only exception to this is when @type is AT_END, in which case + * @ctx->al_entry is set to NULL also (see above). + * + * The following error codes are defined: + * ENOENT Attribute not found, not an error as such. + * EINVAL Invalid arguments. + * EIO I/O error or corrupt data structures found. + * ENOMEM Not enough memory to allocate necessary buffers. + */ +static int ntfs_external_attr_find(ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const VCN lowest_vcn, const u8 *val, const u32 val_len, + ntfs_attr_search_ctx *ctx) +{ + ntfs_inode *base_ni, *ni; + ntfs_volume *vol; + ATTR_LIST_ENTRY *al_entry, *next_al_entry; + u8 *al_start, *al_end; + ATTR_RECORD *a; + ntfschar *al_name; + u32 al_name_len; + BOOL is_first_search = FALSE; + + ni = ctx->ntfs_ino; + base_ni = ctx->base_ntfs_ino; + ntfs_log_trace("Entering for inode %lld, attribute type 0x%x.\n", + (unsigned long long)ni->mft_no, type); + if (!base_ni) { + /* First call happens with the base mft record. */ + base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino; + ctx->base_mrec = ctx->mrec; + } + if (ni == base_ni) + ctx->base_attr = ctx->attr; + if (type == AT_END) + goto not_found; + vol = base_ni->vol; + al_start = base_ni->attr_list; + al_end = al_start + base_ni->attr_list_size; + if (!ctx->al_entry) { + ctx->al_entry = (ATTR_LIST_ENTRY*)al_start; + is_first_search = TRUE; + } + /* + * Iterate over entries in attribute list starting at @ctx->al_entry, + * or the entry following that, if @ctx->is_first is TRUE. + */ + if (ctx->is_first) { + al_entry = ctx->al_entry; + ctx->is_first = FALSE; + /* + * If an enumeration and the first attribute is higher than + * the attribute list itself, need to return the attribute list + * attribute. + */ + if ((type == AT_UNUSED) && is_first_search && + le32_to_cpu(al_entry->type) > + le32_to_cpu(AT_ATTRIBUTE_LIST)) + goto find_attr_list_attr; + } else { + al_entry = (ATTR_LIST_ENTRY*)((char*)ctx->al_entry + + le16_to_cpu(ctx->al_entry->length)); + /* + * If this is an enumeration and the attribute list attribute + * is the next one in the enumeration sequence, just return the + * attribute list attribute from the base mft record as it is + * not listed in the attribute list itself. + */ + if ((type == AT_UNUSED) && le32_to_cpu(ctx->al_entry->type) < + le32_to_cpu(AT_ATTRIBUTE_LIST) && + le32_to_cpu(al_entry->type) > + le32_to_cpu(AT_ATTRIBUTE_LIST)) { + int rc; +find_attr_list_attr: + + /* Check for bogus calls. */ + if (name || name_len || val || val_len || lowest_vcn) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + + /* We want the base record. */ + ctx->ntfs_ino = base_ni; + ctx->mrec = ctx->base_mrec; + ctx->is_first = TRUE; + /* Sanity checks are performed elsewhere. */ + ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + + /* Find the attribute list attribute. */ + rc = ntfs_attr_find(AT_ATTRIBUTE_LIST, NULL, 0, + IGNORE_CASE, NULL, 0, ctx); + + /* + * Setup the search context so the correct + * attribute is returned next time round. + */ + ctx->al_entry = al_entry; + ctx->is_first = TRUE; + + /* Got it. Done. */ + if (!rc) + return 0; + + /* Error! If other than not found return it. */ + if (errno != ENOENT) + return rc; + + /* Not found?!? Absurd! */ + errno = EIO; + ntfs_log_error("Attribute list wasn't found"); + return -1; + } + } + for (;; al_entry = next_al_entry) { + /* Out of bounds check. */ + if ((u8*)al_entry < base_ni->attr_list || + (u8*)al_entry > al_end) + break; /* Inode is corrupt. */ + ctx->al_entry = al_entry; + /* Catch the end of the attribute list. */ + if ((u8*)al_entry == al_end) + goto not_found; + if (!al_entry->length) + break; + if ((u8*)al_entry + 6 > al_end || (u8*)al_entry + + le16_to_cpu(al_entry->length) > al_end) + break; + next_al_entry = (ATTR_LIST_ENTRY*)((u8*)al_entry + + le16_to_cpu(al_entry->length)); + if (type != AT_UNUSED) { + if (le32_to_cpu(al_entry->type) > le32_to_cpu(type)) + goto not_found; + if (type != al_entry->type) + continue; + } + al_name_len = al_entry->name_length; + al_name = (ntfschar*)((u8*)al_entry + al_entry->name_offset); + /* + * If !@type we want the attribute represented by this + * attribute list entry. + */ + if (type == AT_UNUSED) + goto is_enumeration; + /* + * If @name is AT_UNNAMED we want an unnamed attribute. + * If @name is present, compare the two names. + * Otherwise, match any attribute. + */ + if (name == AT_UNNAMED) { + if (al_name_len) + goto not_found; + } else if (name && !ntfs_names_are_equal(al_name, al_name_len, + name, name_len, ic, vol->upcase, + vol->upcase_len)) { + register int rc; + + rc = ntfs_names_collate(name, name_len, al_name, + al_name_len, 1, IGNORE_CASE, + vol->upcase, vol->upcase_len); + /* + * If @name collates before al_name, there is no + * matching attribute. + */ + if (rc == -1) + goto not_found; + /* If the strings are not equal, continue search. */ + if (rc) + continue; + /* + * FIXME: Reverse engineering showed 0, IGNORE_CASE but + * that is inconsistent with ntfs_attr_find(). The + * subsequent rc checks were also different. Perhaps I + * made a mistake in one of the two. Need to recheck + * which is correct or at least see what is going + * on... (AIA) + */ + rc = ntfs_names_collate(name, name_len, al_name, + al_name_len, 1, CASE_SENSITIVE, + vol->upcase, vol->upcase_len); + if (rc == -1) + goto not_found; + if (rc) + continue; + } + /* + * The names match or @name not present and attribute is + * unnamed. Now check @lowest_vcn. Continue search if the + * next attribute list entry still fits @lowest_vcn. Otherwise + * we have reached the right one or the search has failed. + */ + if (lowest_vcn && (u8*)next_al_entry >= al_start && + (u8*)next_al_entry + 6 < al_end && + (u8*)next_al_entry + le16_to_cpu( + next_al_entry->length) <= al_end && + sle64_to_cpu(next_al_entry->lowest_vcn) <= + lowest_vcn && + next_al_entry->type == al_entry->type && + next_al_entry->name_length == al_name_len && + ntfs_names_are_equal((ntfschar*)((char*) + next_al_entry + + next_al_entry->name_offset), + next_al_entry->name_length, + al_name, al_name_len, CASE_SENSITIVE, + vol->upcase, vol->upcase_len)) + continue; +is_enumeration: + if (MREF_LE(al_entry->mft_reference) == ni->mft_no) { + if (MSEQNO_LE(al_entry->mft_reference) != + le16_to_cpu( + ni->mrec->sequence_number)) { + ntfs_log_error("Found stale mft reference in " + "attribute list!\n"); + break; + } + } else { /* Mft references do not match. */ + /* Do we want the base record back? */ + if (MREF_LE(al_entry->mft_reference) == + base_ni->mft_no) { + ni = ctx->ntfs_ino = base_ni; + ctx->mrec = ctx->base_mrec; + } else { + /* We want an extent record. */ + ni = ntfs_extent_inode_open(base_ni, + al_entry->mft_reference); + if (!ni) + break; + ctx->ntfs_ino = ni; + ctx->mrec = ni->mrec; + } + } + a = ctx->attr = (ATTR_RECORD*)((char*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + /* + * ctx->ntfs_ino, ctx->mrec, and ctx->attr now point to the + * mft record containing the attribute represented by the + * current al_entry. + * + * We could call into ntfs_attr_find() to find the right + * attribute in this mft record but this would be less + * efficient and not quite accurate as ntfs_attr_find() ignores + * the attribute instance numbers for example which become + * important when one plays with attribute lists. Also, because + * a proper match has been found in the attribute list entry + * above, the comparison can now be optimized. So it is worth + * re-implementing a simplified ntfs_attr_find() here. + * + * Use a manual loop so we can still use break and continue + * with the same meanings as above. + */ +do_next_attr_loop: + if ((char*)a < (char*)ctx->mrec || (char*)a > (char*)ctx->mrec + + le32_to_cpu(ctx->mrec->bytes_allocated)) + break; + if (a->type == AT_END) + continue; + if (!a->length) + break; + if (al_entry->instance != a->instance) + goto do_next_attr; + /* + * If the type and/or the name are/is mismatched between the + * attribute list entry and the attribute record, there is + * corruption so we break and return error EIO. + */ + if (al_entry->type != a->type) + break; + if (!ntfs_names_are_equal((ntfschar*)((char*)a + + le16_to_cpu(a->name_offset)), + a->name_length, al_name, + al_name_len, CASE_SENSITIVE, + vol->upcase, vol->upcase_len)) + break; + ctx->attr = a; + /* + * If no @val specified or @val specified and it matches, we + * have found it! Also, if !@type, it is an enumeration, so we + * want the current attribute. + */ + if ((type == AT_UNUSED) || !val || (!a->non_resident && + le32_to_cpu(a->value_length) == val_len && + !memcmp((char*)a + le16_to_cpu(a->value_offset), + val, val_len))) { + return 0; + } +do_next_attr: + /* Proceed to the next attribute in the current mft record. */ + a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length)); + goto do_next_attr_loop; + } + if (ni != base_ni) { + ctx->ntfs_ino = base_ni; + ctx->mrec = ctx->base_mrec; + ctx->attr = ctx->base_attr; + } + errno = EIO; + ntfs_log_perror("Inode is corrupt (%lld)", (long long)base_ni->mft_no); + return -1; +not_found: + /* + * If we were looking for AT_END or we were enumerating and reached the + * end, we reset the search context @ctx and use ntfs_attr_find() to + * seek to the end of the base mft record. + */ + if (type == AT_UNUSED || type == AT_END) { + ntfs_attr_reinit_search_ctx(ctx); + return ntfs_attr_find(AT_END, name, name_len, ic, val, val_len, + ctx); + } + /* + * The attribute wasn't found. Before we return, we want to ensure + * @ctx->mrec and @ctx->attr indicate the position at which the + * attribute should be inserted in the base mft record. Since we also + * want to preserve @ctx->al_entry we cannot reinitialize the search + * context using ntfs_attr_reinit_search_ctx() as this would set + * @ctx->al_entry to NULL. Thus we do the necessary bits manually (see + * ntfs_attr_init_search_ctx() below). Note, we _only_ preserve + * @ctx->al_entry as the remaining fields (base_*) are identical to + * their non base_ counterparts and we cannot set @ctx->base_attr + * correctly yet as we do not know what @ctx->attr will be set to by + * the call to ntfs_attr_find() below. + */ + ctx->mrec = ctx->base_mrec; + ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + ctx->is_first = TRUE; + ctx->ntfs_ino = ctx->base_ntfs_ino; + ctx->base_ntfs_ino = NULL; + ctx->base_mrec = NULL; + ctx->base_attr = NULL; + /* + * In case there are multiple matches in the base mft record, need to + * keep enumerating until we get an attribute not found response (or + * another error), otherwise we would keep returning the same attribute + * over and over again and all programs using us for enumeration would + * lock up in a tight loop. + */ + { + int ret; + + do { + ret = ntfs_attr_find(type, name, name_len, ic, val, + val_len, ctx); + } while (!ret); + return ret; + } +} + +/** + * ntfs_attr_lookup - find an attribute in an ntfs inode + * @type: attribute type to find + * @name: attribute name to find (optional, i.e. NULL means don't care) + * @name_len: attribute name length (only needed if @name present) + * @ic: IGNORE_CASE or CASE_SENSITIVE (ignored if @name not present) + * @lowest_vcn: lowest vcn to find (optional, non-resident attributes only) + * @val: attribute value to find (optional, resident attributes only) + * @val_len: attribute value length + * @ctx: search context with mft record and attribute to search from + * + * Find an attribute in an ntfs inode. On first search @ctx->ntfs_ino must + * be the base mft record and @ctx must have been obtained from a call to + * ntfs_attr_get_search_ctx(). + * + * This function transparently handles attribute lists and @ctx is used to + * continue searches where they were left off at. + * + * If @type is AT_UNUSED, return the first found attribute, i.e. one can + * enumerate all attributes by setting @type to AT_UNUSED and then calling + * ntfs_attr_lookup() repeatedly until it returns -1 with errno set to ENOENT + * to indicate that there are no more entries. During the enumeration, each + * successful call of ntfs_attr_lookup() will return the next attribute, with + * the current attribute being described by the search context @ctx. + * + * If @type is AT_END, seek to the end of the base mft record ignoring the + * attribute list completely and return -1 with errno set to ENOENT. AT_END is + * not a valid attribute, its length is zero for example, thus it is safer to + * return error instead of success in this case. It should never be needed to + * do this, but we implement the functionality because it allows for simpler + * code inside ntfs_external_attr_find(). + * + * If @name is AT_UNNAMED search for an unnamed attribute. If @name is present + * but not AT_UNNAMED search for a named attribute matching @name. Otherwise, + * match both named and unnamed attributes. + * + * After finishing with the attribute/mft record you need to call + * ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any + * mapped extent inodes, etc). + * + * Return 0 if the search was successful and -1 if not, with errno set to the + * error code. + * + * On success, @ctx->attr is the found attribute, it is in mft record + * @ctx->mrec, and @ctx->al_entry is the attribute list entry for this + * attribute with @ctx->base_* being the base mft record to which @ctx->attr + * belongs. If no attribute list attribute is present @ctx->al_entry and + * @ctx->base_* are NULL. + * + * On error ENOENT, i.e. attribute not found, @ctx->attr is set to the + * attribute which collates just after the attribute being searched for in the + * base ntfs inode, i.e. if one wants to add the attribute to the mft record + * this is the correct place to insert it into, and if there is not enough + * space, the attribute should be placed in an extent mft record. + * @ctx->al_entry points to the position within @ctx->base_ntfs_ino->attr_list + * at which the new attribute's attribute list entry should be inserted. The + * other @ctx fields, base_ntfs_ino, base_mrec, and base_attr are set to NULL. + * The only exception to this is when @type is AT_END, in which case + * @ctx->al_entry is set to NULL also (see above). + * + * + * The following error codes are defined: + * ENOENT Attribute not found, not an error as such. + * EINVAL Invalid arguments. + * EIO I/O error or corrupt data structures found. + * ENOMEM Not enough memory to allocate necessary buffers. + */ +int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, + const u32 name_len, const IGNORE_CASE_BOOL ic, + const VCN lowest_vcn, const u8 *val, const u32 val_len, + ntfs_attr_search_ctx *ctx) +{ + ntfs_volume *vol; + ntfs_inode *base_ni; + int ret = -1; + + ntfs_log_enter("Entering for attribute type 0x%x\n", type); + + if (!ctx || !ctx->mrec || !ctx->attr || (name && name != AT_UNNAMED && + (!ctx->ntfs_ino || !(vol = ctx->ntfs_ino->vol) || + !vol->upcase || !vol->upcase_len))) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + goto out; + } + + if (ctx->base_ntfs_ino) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + if (!base_ni || !NInoAttrList(base_ni) || type == AT_ATTRIBUTE_LIST) + ret = ntfs_attr_find(type, name, name_len, ic, val, val_len, ctx); + else + ret = ntfs_external_attr_find(type, name, name_len, ic, + lowest_vcn, val, val_len, ctx); +out: + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_position - find given or next attribute type in an ntfs inode + * @type: attribute type to start lookup + * @ctx: search context with mft record and attribute to search from + * + * Find an attribute type in an ntfs inode or the next attribute which is not + * the AT_END attribute. Please see more details at ntfs_attr_lookup. + * + * Return 0 if the search was successful and -1 if not, with errno set to the + * error code. + * + * The following error codes are defined: + * EINVAL Invalid arguments. + * EIO I/O error or corrupt data structures found. + * ENOMEM Not enough memory to allocate necessary buffers. + * ENOSPC No attribute was found after 'type', only AT_END. + */ +int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) +{ + if (ntfs_attr_lookup(type, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (errno != ENOENT) + return -1; + if (ctx->attr->type == AT_END) { + errno = ENOSPC; + return -1; + } + } + return 0; +} + +/** + * ntfs_attr_init_search_ctx - initialize an attribute search context + * @ctx: attribute search context to initialize + * @ni: ntfs inode with which to initialize the search context + * @mrec: mft record with which to initialize the search context + * + * Initialize the attribute search context @ctx with @ni and @mrec. + */ +static void ntfs_attr_init_search_ctx(ntfs_attr_search_ctx *ctx, + ntfs_inode *ni, MFT_RECORD *mrec) +{ + if (!mrec) + mrec = ni->mrec; + ctx->mrec = mrec; + /* Sanity checks are performed elsewhere. */ + ctx->attr = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); + ctx->is_first = TRUE; + ctx->ntfs_ino = ni; + ctx->al_entry = NULL; + ctx->base_ntfs_ino = NULL; + ctx->base_mrec = NULL; + ctx->base_attr = NULL; +} + +/** + * ntfs_attr_reinit_search_ctx - reinitialize an attribute search context + * @ctx: attribute search context to reinitialize + * + * Reinitialize the attribute search context @ctx. + * + * This is used when a search for a new attribute is being started to reset + * the search context to the beginning. + */ +void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx) +{ + if (!ctx->base_ntfs_ino) { + /* No attribute list. */ + ctx->is_first = TRUE; + /* Sanity checks are performed elsewhere. */ + ctx->attr = (ATTR_RECORD*)((u8*)ctx->mrec + + le16_to_cpu(ctx->mrec->attrs_offset)); + /* + * This needs resetting due to ntfs_external_attr_find() which + * can leave it set despite having zeroed ctx->base_ntfs_ino. + */ + ctx->al_entry = NULL; + return; + } /* Attribute list. */ + ntfs_attr_init_search_ctx(ctx, ctx->base_ntfs_ino, ctx->base_mrec); + return; +} + +/** + * ntfs_attr_get_search_ctx - allocate/initialize a new attribute search context + * @ni: ntfs inode with which to initialize the search context + * @mrec: mft record with which to initialize the search context + * + * Allocate a new attribute search context, initialize it with @ni and @mrec, + * and return it. Return NULL on error with errno set. + * + * @mrec can be NULL, in which case the mft record is taken from @ni. + * + * Note: For low level utilities which know what they are doing we allow @ni to + * be NULL and @mrec to be set. Do NOT do this unless you understand the + * implications!!! For example it is no longer safe to call ntfs_attr_lookup(). + */ +ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec) +{ + ntfs_attr_search_ctx *ctx; + + if (!ni && !mrec) { + errno = EINVAL; + ntfs_log_perror("NULL arguments"); + return NULL; + } + ctx = ntfs_malloc(sizeof(ntfs_attr_search_ctx)); + if (ctx) + ntfs_attr_init_search_ctx(ctx, ni, mrec); + return ctx; +} + +/** + * ntfs_attr_put_search_ctx - release an attribute search context + * @ctx: attribute search context to free + * + * Release the attribute search context @ctx. + */ +void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx) +{ + // NOTE: save errno if it could change and function stays void! + free(ctx); +} + +/** + * ntfs_attr_find_in_attrdef - find an attribute in the $AttrDef system file + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to find + * + * Search for the attribute definition record corresponding to the attribute + * @type in the $AttrDef system file. + * + * Return the attribute type definition record if found and NULL if not found + * or an error occurred. On error the error code is stored in errno. The + * following error codes are defined: + * ENOENT - The attribute @type is not specified in $AttrDef. + * EINVAL - Invalid parameters (e.g. @vol is not valid). + */ +ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, + const ATTR_TYPES type) +{ + ATTR_DEF *ad; + + if (!vol || !vol->attrdef || !type) { + errno = EINVAL; + ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + return NULL; + } + for (ad = vol->attrdef; (u8*)ad - (u8*)vol->attrdef < + vol->attrdef_len && ad->type; ++ad) { + /* We haven't found it yet, carry on searching. */ + if (le32_to_cpu(ad->type) < le32_to_cpu(type)) + continue; + /* We found the attribute; return it. */ + if (ad->type == type) + return ad; + /* We have gone too far already. No point in continuing. */ + break; + } + errno = ENOENT; + ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + return NULL; +} + +/** + * ntfs_attr_size_bounds_check - check a size of an attribute type for validity + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to check + * @size: size which to check + * + * Check whether the @size in bytes is valid for an attribute of @type on the + * ntfs volume @vol. This information is obtained from $AttrDef system file. + * + * Return 0 if valid and -1 if not valid or an error occurred. On error the + * error code is stored in errno. The following error codes are defined: + * ERANGE - @size is not valid for the attribute @type. + * ENOENT - The attribute @type is not specified in $AttrDef. + * EINVAL - Invalid parameters (e.g. @size is < 0 or @vol is not valid). + */ +int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type, + const s64 size) +{ + ATTR_DEF *ad; + s64 min_size, max_size; + + if (size < 0) { + errno = EINVAL; + ntfs_log_perror("%s: size=%lld", __FUNCTION__, + (long long)size); + return -1; + } + + /* + * $ATTRIBUTE_LIST shouldn't be greater than 0x40000, otherwise + * Windows would crash. This is not listed in the AttrDef. + */ + if (type == AT_ATTRIBUTE_LIST && size > 0x40000) { + errno = ERANGE; + ntfs_log_perror("Too large attrlist (%lld)", (long long)size); + return -1; + } + + ad = ntfs_attr_find_in_attrdef(vol, type); + if (!ad) + return -1; + + min_size = sle64_to_cpu(ad->min_size); + max_size = sle64_to_cpu(ad->max_size); + + if ((min_size && (size < min_size)) || + ((max_size > 0) && (size > max_size))) { + errno = ERANGE; + ntfs_log_perror("Attr type %d size check failed (min,size,max=" + "%lld,%lld,%lld)", type, (long long)min_size, + (long long)size, (long long)max_size); + return -1; + } + return 0; +} + +/** + * ntfs_attr_can_be_non_resident - check if an attribute can be non-resident + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to check + * + * Check whether the attribute of @type on the ntfs volume @vol is allowed to + * be non-resident. This information is obtained from $AttrDef system file. + * + * Return 0 if the attribute is allowed to be non-resident and -1 if not or an + * error occurred. On error the error code is stored in errno. The following + * error codes are defined: + * EPERM - The attribute is not allowed to be non-resident. + * ENOENT - The attribute @type is not specified in $AttrDef. + * EINVAL - Invalid parameters (e.g. @vol is not valid). + */ +int ntfs_attr_can_be_non_resident(const ntfs_volume *vol, const ATTR_TYPES type) +{ + ATTR_DEF *ad; + + /* Find the attribute definition record in $AttrDef. */ + ad = ntfs_attr_find_in_attrdef(vol, type); + if (!ad) + return -1; + /* Check the flags and return the result. */ + if (ad->flags & ATTR_DEF_RESIDENT) { + errno = EPERM; + ntfs_log_trace("Attribute can't be non-resident\n"); + return -1; + } + return 0; +} + +/** + * ntfs_attr_can_be_resident - check if an attribute can be resident + * @vol: ntfs volume to which the attribute belongs + * @type: attribute type which to check + * + * Check whether the attribute of @type on the ntfs volume @vol is allowed to + * be resident. This information is derived from our ntfs knowledge and may + * not be completely accurate, especially when user defined attributes are + * present. Basically we allow everything to be resident except for index + * allocation and extended attribute attributes. + * + * Return 0 if the attribute is allowed to be resident and -1 if not or an + * error occurred. On error the error code is stored in errno. The following + * error codes are defined: + * EPERM - The attribute is not allowed to be resident. + * EINVAL - Invalid parameters (e.g. @vol is not valid). + * + * Warning: In the system file $MFT the attribute $Bitmap must be non-resident + * otherwise windows will not boot (blue screen of death)! We cannot + * check for this here as we don't know which inode's $Bitmap is being + * asked about so the caller needs to special case this. + */ +int ntfs_attr_can_be_resident(const ntfs_volume *vol, const ATTR_TYPES type) +{ + if (!vol || !vol->attrdef || !type) { + errno = EINVAL; + return -1; + } + if (type != AT_INDEX_ALLOCATION) + return 0; + + ntfs_log_trace("Attribute can't be resident\n"); + errno = EPERM; + return -1; +} + +/** + * ntfs_make_room_for_attr - make room for an attribute inside an mft record + * @m: mft record + * @pos: position at which to make space + * @size: byte size to make available at this position + * + * @pos points to the attribute in front of which we want to make space. + * + * Return 0 on success or -1 on error. On error the error code is stored in + * errno. Possible error codes are: + * ENOSPC - There is not enough space available to complete operation. The + * caller has to make space before calling this. + * EINVAL - Input parameters were faulty. + */ +int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size) +{ + u32 biu; + + ntfs_log_trace("Entering for pos 0x%d, size %u.\n", + (int)(pos - (u8*)m), (unsigned) size); + + /* Make size 8-byte alignment. */ + size = (size + 7) & ~7; + + /* Rigorous consistency checks. */ + if (!m || !pos || pos < (u8*)m) { + errno = EINVAL; + ntfs_log_perror("%s: pos=%p m=%p", __FUNCTION__, pos, m); + return -1; + } + /* The -8 is for the attribute terminator. */ + if (pos - (u8*)m > (int)le32_to_cpu(m->bytes_in_use) - 8) { + errno = EINVAL; + return -1; + } + /* Nothing to do. */ + if (!size) + return 0; + + biu = le32_to_cpu(m->bytes_in_use); + /* Do we have enough space? */ + if (biu + size > le32_to_cpu(m->bytes_allocated) || + pos + size > (u8*)m + le32_to_cpu(m->bytes_allocated)) { + errno = ENOSPC; + ntfs_log_trace("No enough space in the MFT record\n"); + return -1; + } + /* Move everything after pos to pos + size. */ + memmove(pos + size, pos, biu - (pos - (u8*)m)); + /* Update mft record. */ + m->bytes_in_use = cpu_to_le32(biu + size); + return 0; +} + +/** + * ntfs_resident_attr_record_add - add resident attribute to inode + * @ni: opened ntfs inode to which MFT record add attribute + * @type: type of the new attribute + * @name: name of the new attribute + * @name_len: name length of the new attribute + * @val: value of the new attribute + * @size: size of new attribute (length of @val, if @val != NULL) + * @flags: flags of the new attribute + * + * Return offset to attribute from the beginning of the mft record on success + * and -1 on error. On error the error code is stored in errno. + * Possible error codes are: + * EINVAL - Invalid arguments passed to function. + * EEXIST - Attribute of such type and with same name already exists. + * EIO - I/O error occurred or damaged filesystem. + */ +int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, u8 *val, u32 size, + ATTR_FLAGS data_flags) +{ + ntfs_attr_search_ctx *ctx; + u32 length; + ATTR_RECORD *a; + MFT_RECORD *m; + int err, offset; + ntfs_inode *base_ni; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", + (long long) ni->mft_no, (unsigned) type, (unsigned) data_flags); + + if (!ni || (!name && name_len)) { + errno = EINVAL; + return -1; + } + + if (ntfs_attr_can_be_resident(ni->vol, type)) { + if (errno == EPERM) + ntfs_log_trace("Attribute can't be resident.\n"); + else + ntfs_log_trace("ntfs_attr_can_be_resident failed.\n"); + return -1; + } + + /* Locate place where record should be. */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + /* + * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for + * attribute in @ni->mrec, not any extent inode in case if @ni is base + * file record. + */ + if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, val, size, + ctx)) { + err = EEXIST; + ntfs_log_trace("Attribute already present.\n"); + goto put_err_out; + } + if (errno != ENOENT) { + err = EIO; + goto put_err_out; + } + a = ctx->attr; + m = ctx->mrec; + + /* Make room for attribute. */ + length = offsetof(ATTR_RECORD, resident_end) + + ((name_len * sizeof(ntfschar) + 7) & ~7) + + ((size + 7) & ~7); + if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { + err = errno; + ntfs_log_trace("Failed to make room for attribute.\n"); + goto put_err_out; + } + + /* Setup record fields. */ + offset = ((u8*)a - (u8*)m); + a->type = type; + a->length = cpu_to_le32(length); + a->non_resident = 0; + a->name_length = name_len; + a->name_offset = (name_len + ? cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) + : const_cpu_to_le16(0)); + a->flags = data_flags; + a->instance = m->next_attr_instance; + a->value_length = cpu_to_le32(size); + a->value_offset = cpu_to_le16(length - ((size + 7) & ~7)); + if (val) + memcpy((u8*)a + le16_to_cpu(a->value_offset), val, size); + else + memset((u8*)a + le16_to_cpu(a->value_offset), 0, size); + if (type == AT_FILE_NAME) + a->resident_flags = RESIDENT_ATTR_IS_INDEXED; + else + a->resident_flags = 0; + if (name_len) + memcpy((u8*)a + le16_to_cpu(a->name_offset), + name, sizeof(ntfschar) * name_len); + m->next_attr_instance = + cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); + if (ni->nr_extents == -1) + base_ni = ni->base_ni; + else + base_ni = ni; + if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { + if (ntfs_attrlist_entry_add(ni, a)) { + err = errno; + ntfs_attr_record_resize(m, a, 0); + ntfs_log_trace("Failed add attribute entry to " + "ATTRIBUTE_LIST.\n"); + goto put_err_out; + } + } + if (type == AT_DATA && name == AT_UNNAMED) { + ni->data_size = size; + ni->allocated_size = (size + 7) & ~7; + } + ntfs_inode_mark_dirty(ni); + ntfs_attr_put_search_ctx(ctx); + return offset; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_non_resident_attr_record_add - add extent of non-resident attribute + * @ni: opened ntfs inode to which MFT record add attribute + * @type: type of the new attribute extent + * @name: name of the new attribute extent + * @name_len: name length of the new attribute extent + * @lowest_vcn: lowest vcn of the new attribute extent + * @dataruns_size: dataruns size of the new attribute extent + * @flags: flags of the new attribute extent + * + * Return offset to attribute from the beginning of the mft record on success + * and -1 on error. On error the error code is stored in errno. + * Possible error codes are: + * EINVAL - Invalid arguments passed to function. + * EEXIST - Attribute of such type, with same lowest vcn and with same + * name already exists. + * EIO - I/O error occurred or damaged filesystem. + */ +int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size, + ATTR_FLAGS flags) +{ + ntfs_attr_search_ctx *ctx; + u32 length; + ATTR_RECORD *a; + MFT_RECORD *m; + ntfs_inode *base_ni; + int err, offset; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " + "dataruns_size %d, flags 0x%x.\n", + (long long) ni->mft_no, (unsigned) type, + (long long) lowest_vcn, dataruns_size, (unsigned) flags); + + if (!ni || dataruns_size <= 0 || (!name && name_len)) { + errno = EINVAL; + return -1; + } + + if (ntfs_attr_can_be_non_resident(ni->vol, type)) { + if (errno == EPERM) + ntfs_log_perror("Attribute can't be non resident"); + else + ntfs_log_perror("ntfs_attr_can_be_non_resident failed"); + return -1; + } + + /* Locate place where record should be. */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + /* + * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for + * attribute in @ni->mrec, not any extent inode in case if @ni is base + * file record. + */ + if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, NULL, 0, + ctx)) { + err = EEXIST; + ntfs_log_perror("Attribute 0x%x already present", type); + goto put_err_out; + } + if (errno != ENOENT) { + ntfs_log_perror("ntfs_attr_find failed"); + err = EIO; + goto put_err_out; + } + a = ctx->attr; + m = ctx->mrec; + + /* Make room for attribute. */ + dataruns_size = (dataruns_size + 7) & ~7; + length = offsetof(ATTR_RECORD, compressed_size) + ((sizeof(ntfschar) * + name_len + 7) & ~7) + dataruns_size + + ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? + sizeof(a->compressed_size) : 0); + if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { + err = errno; + ntfs_log_perror("Failed to make room for attribute"); + goto put_err_out; + } + + /* Setup record fields. */ + a->type = type; + a->length = cpu_to_le32(length); + a->non_resident = 1; + a->name_length = name_len; + a->name_offset = cpu_to_le16(offsetof(ATTR_RECORD, compressed_size) + + ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? + sizeof(a->compressed_size) : 0)); + a->flags = flags; + a->instance = m->next_attr_instance; + a->lowest_vcn = cpu_to_sle64(lowest_vcn); + a->mapping_pairs_offset = cpu_to_le16(length - dataruns_size); + a->compression_unit = (flags & ATTR_IS_COMPRESSED) + ? STANDARD_COMPRESSION_UNIT : 0; + /* If @lowest_vcn == 0, than setup empty attribute. */ + if (!lowest_vcn) { + a->highest_vcn = cpu_to_sle64(-1); + a->allocated_size = 0; + a->data_size = 0; + a->initialized_size = 0; + /* Set empty mapping pairs. */ + *((u8*)a + le16_to_cpu(a->mapping_pairs_offset)) = 0; + } + if (name_len) + memcpy((u8*)a + le16_to_cpu(a->name_offset), + name, sizeof(ntfschar) * name_len); + m->next_attr_instance = + cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); + if (ni->nr_extents == -1) + base_ni = ni->base_ni; + else + base_ni = ni; + if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { + if (ntfs_attrlist_entry_add(ni, a)) { + err = errno; + ntfs_log_perror("Failed add attr entry to attrlist"); + ntfs_attr_record_resize(m, a, 0); + goto put_err_out; + } + } + ntfs_inode_mark_dirty(ni); + /* + * Locate offset from start of the MFT record where new attribute is + * placed. We need relookup it, because record maybe moved during + * update of attribute list. + */ + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, + lowest_vcn, NULL, 0, ctx)) { + ntfs_log_perror("%s: attribute lookup failed", __FUNCTION__); + ntfs_attr_put_search_ctx(ctx); + return -1; + + } + offset = (u8*)ctx->attr - (u8*)ctx->mrec; + ntfs_attr_put_search_ctx(ctx); + return offset; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_attr_record_rm - remove attribute extent + * @ctx: search context describing the attribute which should be removed + * + * If this function succeed, user should reinit search context if he/she wants + * use it anymore. + * + * Return 0 on success and -1 on error. On error the error code is stored in + * errno. Possible error codes are: + * EINVAL - Invalid arguments passed to function. + * EIO - I/O error occurred or damaged filesystem. + */ +int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) +{ + ntfs_inode *base_ni, *ni; + ATTR_TYPES type; + int err; + + if (!ctx || !ctx->ntfs_ino || !ctx->mrec || !ctx->attr) { + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) ctx->ntfs_ino->mft_no, + (unsigned) le32_to_cpu(ctx->attr->type)); + type = ctx->attr->type; + ni = ctx->ntfs_ino; + if (ctx->base_ntfs_ino) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + + /* Remove attribute itself. */ + if (ntfs_attr_record_resize(ctx->mrec, ctx->attr, 0)) { + ntfs_log_trace("Couldn't remove attribute record. Bug or damaged MFT " + "record.\n"); + if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) + if (ntfs_attrlist_entry_add(ni, ctx->attr)) + ntfs_log_trace("Rollback failed. Leaving inconstant " + "metadata.\n"); + err = EIO; + return -1; + } + ntfs_inode_mark_dirty(ni); + + /* + * Remove record from $ATTRIBUTE_LIST if present and we don't want + * delete $ATTRIBUTE_LIST itself. + */ + if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) { + if (ntfs_attrlist_entry_rm(ctx)) { + ntfs_log_trace("Couldn't delete record from " + "$ATTRIBUTE_LIST.\n"); + return -1; + } + } + + /* Post $ATTRIBUTE_LIST delete setup. */ + if (type == AT_ATTRIBUTE_LIST) { + if (NInoAttrList(base_ni) && base_ni->attr_list) + free(base_ni->attr_list); + base_ni->attr_list = NULL; + NInoClearAttrList(base_ni); + NInoAttrListClearDirty(base_ni); + } + + /* Free MFT record, if it doesn't contain attributes. */ + if (le32_to_cpu(ctx->mrec->bytes_in_use) - + le16_to_cpu(ctx->mrec->attrs_offset) == 8) { + if (ntfs_mft_record_free(ni->vol, ni)) { + // FIXME: We need rollback here. + ntfs_log_trace("Couldn't free MFT record.\n"); + errno = EIO; + return -1; + } + /* Remove done if we freed base inode. */ + if (ni == base_ni) + return 0; + } + + if (type == AT_ATTRIBUTE_LIST || !NInoAttrList(base_ni)) + return 0; + + /* Remove attribute list if we don't need it any more. */ + if (!ntfs_attrlist_need(base_ni)) { + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + /* + * FIXME: Should we succeed here? Definitely something + * goes wrong because NInoAttrList(base_ni) returned + * that we have got attribute list. + */ + ntfs_log_trace("Couldn't find attribute list. Succeed " + "anyway.\n"); + return 0; + } + /* Deallocate clusters. */ + if (ctx->attr->non_resident) { + runlist *al_rl; + + al_rl = ntfs_mapping_pairs_decompress(base_ni->vol, + ctx->attr, NULL); + if (!al_rl) { + ntfs_log_trace("Couldn't decompress attribute list " + "runlist. Succeed anyway.\n"); + return 0; + } + if (ntfs_cluster_free_from_rl(base_ni->vol, al_rl)) { + ntfs_log_trace("Leaking clusters! Run chkdsk. " + "Couldn't free clusters from " + "attribute list runlist.\n"); + } + free(al_rl); + } + /* Remove attribute record itself. */ + if (ntfs_attr_record_rm(ctx)) { + /* + * FIXME: Should we succeed here? BTW, chkdsk doesn't + * complain if it find MFT record with attribute list, + * but without extents. + */ + ntfs_log_trace("Couldn't remove attribute list. Succeed " + "anyway.\n"); + return 0; + } + } + return 0; +} + +/** + * ntfs_attr_add - add attribute to inode + * @ni: opened ntfs inode to which add attribute + * @type: type of the new attribute + * @name: name in unicode of the new attribute + * @name_len: name length in unicode characters of the new attribute + * @val: value of new attribute + * @size: size of the new attribute / length of @val (if specified) + * + * @val should always be specified for always resident attributes (eg. FILE_NAME + * attribute), for attributes that can become non-resident @val can be NULL + * (eg. DATA attribute). @size can be specified even if @val is NULL, in this + * case data size will be equal to @size and initialized size will be equal + * to 0. + * + * If inode haven't got enough space to add attribute, add attribute to one of + * it extents, if no extents present or no one of them have enough space, than + * allocate new extent and add attribute to it. + * + * If on one of this steps attribute list is needed but not present, than it is + * added transparently to caller. So, this function should not be called with + * @type == AT_ATTRIBUTE_LIST, if you really need to add attribute list call + * ntfs_inode_add_attrlist instead. + * + * On success return 0. On error return -1 with errno set to the error code. + */ +int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, u8 *val, s64 size) +{ + u32 attr_rec_size; + int err, i, offset; + BOOL is_resident; + BOOL can_be_non_resident = FALSE; + ntfs_inode *attr_ni; + ntfs_attr *na; + ATTR_FLAGS data_flags; + + if (!ni || size < 0 || type == AT_ATTRIBUTE_LIST) { + errno = EINVAL; + ntfs_log_perror("%s: ni=%p size=%lld", __FUNCTION__, ni, + (long long)size); + return -1; + } + + ntfs_log_trace("Entering for inode %lld, attr %x, size %lld.\n", + (long long)ni->mft_no, type, (long long)size); + + if (ni->nr_extents == -1) + ni = ni->base_ni; + + /* Check the attribute type and the size. */ + if (ntfs_attr_size_bounds_check(ni->vol, type, size)) { + if (errno == ENOENT) + errno = EIO; + return -1; + } + + /* Sanity checks for always resident attributes. */ + if (ntfs_attr_can_be_non_resident(ni->vol, type)) { + if (errno != EPERM) { + err = errno; + ntfs_log_perror("ntfs_attr_can_be_non_resident failed"); + goto err_out; + } + /* @val is mandatory. */ + if (!val) { + errno = EINVAL; + ntfs_log_perror("val is mandatory for always resident " + "attributes"); + return -1; + } + if (size > ni->vol->mft_record_size) { + errno = ERANGE; + ntfs_log_perror("Attribute is too big"); + return -1; + } + } else + can_be_non_resident = TRUE; + + /* + * Determine resident or not will be new attribute. We add 8 to size in + * non resident case for mapping pairs. + */ + if (!ntfs_attr_can_be_resident(ni->vol, type)) { + is_resident = TRUE; + } else { + if (errno != EPERM) { + err = errno; + ntfs_log_perror("ntfs_attr_can_be_resident failed"); + goto err_out; + } + is_resident = FALSE; + } + /* Calculate attribute record size. */ + if (is_resident) + attr_rec_size = offsetof(ATTR_RECORD, resident_end) + + ((name_len * sizeof(ntfschar) + 7) & ~7) + + ((size + 7) & ~7); + else + attr_rec_size = offsetof(ATTR_RECORD, non_resident_end) + + ((name_len * sizeof(ntfschar) + 7) & ~7) + 8; + + /* + * If we have enough free space for the new attribute in the base MFT + * record, then add attribute to it. + */ + if (le32_to_cpu(ni->mrec->bytes_allocated) - + le32_to_cpu(ni->mrec->bytes_in_use) >= attr_rec_size) { + attr_ni = ni; + goto add_attr_record; + } + + /* Try to add to extent inodes. */ + if (ntfs_inode_attach_all_extents(ni)) { + err = errno; + ntfs_log_perror("Failed to attach all extents to inode"); + goto err_out; + } + for (i = 0; i < ni->nr_extents; i++) { + attr_ni = ni->extent_nis[i]; + if (le32_to_cpu(attr_ni->mrec->bytes_allocated) - + le32_to_cpu(attr_ni->mrec->bytes_in_use) >= + attr_rec_size) + goto add_attr_record; + } + + /* There is no extent that contain enough space for new attribute. */ + if (!NInoAttrList(ni)) { + /* Add attribute list not present, add it and retry. */ + if (ntfs_inode_add_attrlist(ni)) { + err = errno; + ntfs_log_perror("Failed to add attribute list"); + goto err_out; + } + return ntfs_attr_add(ni, type, name, name_len, val, size); + } + /* Allocate new extent. */ + attr_ni = ntfs_mft_record_alloc(ni->vol, ni); + if (!attr_ni) { + err = errno; + ntfs_log_perror("Failed to allocate extent record"); + goto err_out; + } + +add_attr_record: + if ((ni->flags & FILE_ATTR_COMPRESSED) + && ((type == AT_DATA) + || ((type == AT_INDEX_ROOT) && (name == NTFS_INDEX_I30)))) + data_flags = ATTR_IS_COMPRESSED; + else + data_flags = const_cpu_to_le16(0); + if (is_resident) { + /* Add resident attribute. */ + offset = ntfs_resident_attr_record_add(attr_ni, type, name, + name_len, val, size, data_flags); + if (offset < 0) { + if (errno == ENOSPC && can_be_non_resident) + goto add_non_resident; + err = errno; + ntfs_log_perror("Failed to add resident attribute"); + goto free_err_out; + } + return 0; + } + +add_non_resident: + /* Add non resident attribute. */ + offset = ntfs_non_resident_attr_record_add(attr_ni, type, name, + name_len, 0, 8, data_flags); + if (offset < 0) { + err = errno; + ntfs_log_perror("Failed to add non resident attribute"); + goto free_err_out; + } + + /* If @size == 0, we are done. */ + if (!size) + return 0; + + /* Open new attribute and resize it. */ + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + err = errno; + ntfs_log_perror("Failed to open just added attribute"); + goto rm_attr_err_out; + } + /* Resize and set attribute value. */ + if (ntfs_attr_truncate(na, size) || + (val && (ntfs_attr_pwrite(na, 0, size, val) != size))) { + err = errno; + ntfs_log_perror("Failed to initialize just added attribute"); + if (ntfs_attr_rm(na)) + ntfs_log_perror("Failed to remove just added attribute"); + ntfs_attr_close(na); + goto err_out; + } + ntfs_attr_close(na); + return 0; + +rm_attr_err_out: + /* Remove just added attribute. */ + if (ntfs_attr_record_resize(attr_ni->mrec, + (ATTR_RECORD*)((u8*)attr_ni->mrec + offset), 0)) + ntfs_log_perror("Failed to remove just added attribute #2"); +free_err_out: + /* Free MFT record, if it doesn't contain attributes. */ + if (le32_to_cpu(attr_ni->mrec->bytes_in_use) - + le16_to_cpu(attr_ni->mrec->attrs_offset) == 8) + if (ntfs_mft_record_free(attr_ni->vol, attr_ni)) + ntfs_log_perror("Failed to free MFT record"); +err_out: + errno = err; + return -1; +} + +/* + * Change an attribute flag + */ + +int ntfs_attr_set_flags(ntfs_inode *ni, ATTR_TYPES type, + ntfschar *name, u8 name_len, ATTR_FLAGS flags, ATTR_FLAGS mask) +{ + ntfs_attr_search_ctx *ctx; + int res; + + res = -1; + /* Search for designated attribute */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (ctx) { + if (!ntfs_attr_lookup(type, name, name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + /* do the requested change (all small endian le16) */ + ctx->attr->flags = (ctx->attr->flags & ~mask) + | (flags & mask); + NInoSetDirty(ni); + res = 0; + } + ntfs_attr_put_search_ctx(ctx); + } + return (res); +} + + +/** + * ntfs_attr_rm - remove attribute from ntfs inode + * @na: opened ntfs attribute to delete + * + * Remove attribute and all it's extents from ntfs inode. If attribute was non + * resident also free all clusters allocated by attribute. + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +int ntfs_attr_rm(ntfs_attr *na) +{ + ntfs_attr_search_ctx *ctx; + int ret = 0; + + if (!na) { + ntfs_log_trace("Invalid arguments passed.\n"); + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) na->ni->mft_no, na->type); + + /* Free cluster allocation. */ + if (NAttrNonResident(na)) { + if (ntfs_attr_map_whole_runlist(na)) + return -1; + if (ntfs_cluster_free(na->ni->vol, na, 0, -1) < 0) { + ntfs_log_trace("Failed to free cluster allocation. Leaving " + "inconstant metadata.\n"); + ret = -1; + } + } + + /* Search for attribute extents and remove them all. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + while (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (ntfs_attr_record_rm(ctx)) { + ntfs_log_trace("Failed to remove attribute extent. Leaving " + "inconstant metadata.\n"); + ret = -1; + } + ntfs_attr_reinit_search_ctx(ctx); + } + ntfs_attr_put_search_ctx(ctx); + if (errno != ENOENT) { + ntfs_log_trace("Attribute lookup failed. Probably leaving inconstant " + "metadata.\n"); + ret = -1; + } + + return ret; +} + +/** + * ntfs_attr_record_resize - resize an attribute record + * @m: mft record containing attribute record + * @a: attribute record to resize + * @new_size: new size in bytes to which to resize the attribute record @a + * + * Resize the attribute record @a, i.e. the resident part of the attribute, in + * the mft record @m to @new_size bytes. + * + * Return 0 on success and -1 on error with errno set to the error code. + * The following error codes are defined: + * ENOSPC - Not enough space in the mft record @m to perform the resize. + * Note that on error no modifications have been performed whatsoever. + * + * Warning: If you make a record smaller without having copied all the data you + * are interested in the data may be overwritten! + */ +int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size) +{ + u32 old_size, alloc_size, attr_size; + + old_size = le32_to_cpu(m->bytes_in_use); + alloc_size = le32_to_cpu(m->bytes_allocated); + attr_size = le32_to_cpu(a->length); + + ntfs_log_trace("Sizes: old=%u alloc=%u attr=%u new=%u\n", + (unsigned)old_size, (unsigned)alloc_size, + (unsigned)attr_size, (unsigned)new_size); + + /* Align to 8 bytes, just in case the caller hasn't. */ + new_size = (new_size + 7) & ~7; + + /* If the actual attribute length has changed, move things around. */ + if (new_size != attr_size) { + + u32 new_muse = old_size - attr_size + new_size; + + /* Not enough space in this mft record. */ + if (new_muse > alloc_size) { + errno = ENOSPC; + ntfs_log_trace("Not enough space in the MFT record " + "(%u > %u)\n", new_muse, alloc_size); + return -1; + } + + if (a->type == AT_INDEX_ROOT && new_size > attr_size && + new_muse + 120 > alloc_size && old_size + 120 <= alloc_size) { + errno = ENOSPC; + ntfs_log_trace("Too big INDEX_ROOT (%u > %u)\n", + new_muse, alloc_size); + return STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT; + } + + /* Move attributes following @a to their new location. */ + memmove((u8 *)a + new_size, (u8 *)a + attr_size, + old_size - ((u8 *)a - (u8 *)m) - attr_size); + + /* Adjust @m to reflect the change in used space. */ + m->bytes_in_use = cpu_to_le32(new_muse); + + /* Adjust @a to reflect the new size. */ + if (new_size >= offsetof(ATTR_REC, length) + sizeof(a->length)) + a->length = cpu_to_le32(new_size); + } + return 0; +} + +/** + * ntfs_resident_attr_value_resize - resize the value of a resident attribute + * @m: mft record containing attribute record + * @a: attribute record whose value to resize + * @new_size: new size in bytes to which to resize the attribute value of @a + * + * Resize the value of the attribute @a in the mft record @m to @new_size bytes. + * If the value is made bigger, the newly "allocated" space is cleared. + * + * Return 0 on success and -1 on error with errno set to the error code. + * The following error codes are defined: + * ENOSPC - Not enough space in the mft record @m to perform the resize. + * Note that on error no modifications have been performed whatsoever. + */ +int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a, + const u32 new_size) +{ + int ret; + + ntfs_log_trace("Entering for new size %u.\n", (unsigned)new_size); + + /* Resize the resident part of the attribute record. */ + if ((ret = ntfs_attr_record_resize(m, a, (le16_to_cpu(a->value_offset) + + new_size + 7) & ~7)) < 0) + return ret; + /* + * If we made the attribute value bigger, clear the area between the + * old size and @new_size. + */ + if (new_size > le32_to_cpu(a->value_length)) + memset((u8*)a + le16_to_cpu(a->value_offset) + + le32_to_cpu(a->value_length), 0, new_size - + le32_to_cpu(a->value_length)); + /* Finally update the length of the attribute value. */ + a->value_length = cpu_to_le32(new_size); + return 0; +} + +/** + * ntfs_attr_record_move_to - move attribute record to target inode + * @ctx: attribute search context describing the attribute record + * @ni: opened ntfs inode to which move attribute record + * + * If this function succeed, user should reinit search context if he/she wants + * use it anymore. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni) +{ + ntfs_attr_search_ctx *nctx; + ATTR_RECORD *a; + int err; + + if (!ctx || !ctx->attr || !ctx->ntfs_ino || !ni) { + ntfs_log_trace("Invalid arguments passed.\n"); + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for ctx->attr->type 0x%x, ctx->ntfs_ino->mft_no " + "0x%llx, ni->mft_no 0x%llx.\n", + (unsigned) le32_to_cpu(ctx->attr->type), + (long long) ctx->ntfs_ino->mft_no, + (long long) ni->mft_no); + + if (ctx->ntfs_ino == ni) + return 0; + + if (!ctx->al_entry) { + ntfs_log_trace("Inode should contain attribute list to use this " + "function.\n"); + errno = EINVAL; + return -1; + } + + /* Find place in MFT record where attribute will be moved. */ + a = ctx->attr; + nctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!nctx) + return -1; + + /* + * Use ntfs_attr_find instead of ntfs_attr_lookup to find place for + * attribute in @ni->mrec, not any extent inode in case if @ni is base + * file record. + */ + if (!ntfs_attr_find(a->type, (ntfschar*)((u8*)a + le16_to_cpu( + a->name_offset)), a->name_length, CASE_SENSITIVE, NULL, + 0, nctx)) { + ntfs_log_trace("Attribute of such type, with same name already " + "present in this MFT record.\n"); + err = EEXIST; + goto put_err_out; + } + if (errno != ENOENT) { + err = errno; + ntfs_log_debug("Attribute lookup failed.\n"); + goto put_err_out; + } + + /* Make space and move attribute. */ + if (ntfs_make_room_for_attr(ni->mrec, (u8*) nctx->attr, + le32_to_cpu(a->length))) { + err = errno; + ntfs_log_trace("Couldn't make space for attribute.\n"); + goto put_err_out; + } + memcpy(nctx->attr, a, le32_to_cpu(a->length)); + nctx->attr->instance = nctx->mrec->next_attr_instance; + nctx->mrec->next_attr_instance = cpu_to_le16( + (le16_to_cpu(nctx->mrec->next_attr_instance) + 1) & 0xffff); + ntfs_attr_record_resize(ctx->mrec, a, 0); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_inode_mark_dirty(ni); + + /* Update attribute list. */ + ctx->al_entry->mft_reference = + MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); + ctx->al_entry->instance = nctx->attr->instance; + ntfs_attrlist_mark_dirty(ni); + + ntfs_attr_put_search_ctx(nctx); + return 0; +put_err_out: + ntfs_attr_put_search_ctx(nctx); + errno = err; + return -1; +} + +/** + * ntfs_attr_record_move_away - move away attribute record from it's mft record + * @ctx: attribute search context describing the attribute record + * @extra: minimum amount of free space in the new holder of record + * + * New attribute record holder must have free @extra bytes after moving + * attribute record to it. + * + * If this function succeed, user should reinit search context if he/she wants + * use it anymore. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra) +{ + ntfs_inode *base_ni, *ni; + MFT_RECORD *m; + int i; + + if (!ctx || !ctx->attr || !ctx->ntfs_ino || extra < 0) { + errno = EINVAL; + ntfs_log_perror("%s: ctx=%p ctx->attr=%p extra=%d", __FUNCTION__, + ctx, ctx ? ctx->attr : NULL, extra); + return -1; + } + + ntfs_log_trace("Entering for attr 0x%x, inode %llu\n", + (unsigned) le32_to_cpu(ctx->attr->type), + (unsigned long long)ctx->ntfs_ino->mft_no); + + if (ctx->ntfs_ino->nr_extents == -1) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + + if (!NInoAttrList(base_ni)) { + errno = EINVAL; + ntfs_log_perror("Inode %llu has no attrlist", + (unsigned long long)base_ni->mft_no); + return -1; + } + + if (ntfs_inode_attach_all_extents(ctx->ntfs_ino)) { + ntfs_log_perror("Couldn't attach extents, inode=%llu", + (unsigned long long)base_ni->mft_no); + return -1; + } + + /* Walk through all extents and try to move attribute to them. */ + for (i = 0; i < base_ni->nr_extents; i++) { + ni = base_ni->extent_nis[i]; + m = ni->mrec; + + if (ctx->ntfs_ino->mft_no == ni->mft_no) + continue; + + if (le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use) < + le32_to_cpu(ctx->attr->length) + extra) + continue; + + /* + * ntfs_attr_record_move_to can fail if extent with other lowest + * VCN already present in inode we trying move record to. So, + * do not return error. + */ + if (!ntfs_attr_record_move_to(ctx, ni)) + return 0; + } + + /* + * Failed to move attribute to one of the current extents, so allocate + * new extent and move attribute to it. + */ + ni = ntfs_mft_record_alloc(base_ni->vol, base_ni); + if (!ni) { + ntfs_log_perror("Couldn't allocate MFT record"); + return -1; + } + if (ntfs_attr_record_move_to(ctx, ni)) { + ntfs_log_perror("Couldn't move attribute to MFT record"); + return -1; + } + return 0; +} + +/** + * ntfs_attr_make_non_resident - convert a resident to a non-resident attribute + * @na: open ntfs attribute to make non-resident + * @ctx: ntfs search context describing the attribute + * + * Convert a resident ntfs attribute to a non-resident one. + * + * Return 0 on success and -1 on error with errno set to the error code. The + * following error codes are defined: + * EPERM - The attribute is not allowed to be non-resident. + * TODO: others... + * + * NOTE to self: No changes in the attribute list are required to move from + * a resident to a non-resident attribute. + * + * Warning: We do not set the inode dirty and we do not write out anything! + * We expect the caller to do this as this is a fairly low level + * function and it is likely there will be further changes made. + */ +int ntfs_attr_make_non_resident(ntfs_attr *na, + ntfs_attr_search_ctx *ctx) +{ + s64 new_allocated_size, bw; + ntfs_volume *vol = na->ni->vol; + ATTR_REC *a = ctx->attr; + runlist *rl; + int mp_size, mp_ofs, name_ofs, arec_size, err; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); + + /* Some preliminary sanity checking. */ + if (NAttrNonResident(na)) { + ntfs_log_trace("Eeek! Trying to make non-resident attribute " + "non-resident. Aborting...\n"); + errno = EINVAL; + return -1; + } + + /* Check that the attribute is allowed to be non-resident. */ + if (ntfs_attr_can_be_non_resident(vol, na->type)) + return -1; + + new_allocated_size = (le32_to_cpu(a->value_length) + vol->cluster_size + - 1) & ~(vol->cluster_size - 1); + + if (new_allocated_size > 0) { + /* Start by allocating clusters to hold the attribute value. */ + rl = ntfs_cluster_alloc(vol, 0, new_allocated_size >> + vol->cluster_size_bits, -1, DATA_ZONE); + if (!rl) + return -1; + } else + rl = NULL; + /* + * Setup the in-memory attribute structure to be non-resident so that + * we can use ntfs_attr_pwrite(). + */ + NAttrSetNonResident(na); + na->rl = rl; + na->allocated_size = new_allocated_size; + na->data_size = na->initialized_size = le32_to_cpu(a->value_length); + /* + * FIXME: For now just clear all of these as we don't support them when + * writing. + */ + NAttrClearSparse(na); + NAttrClearEncrypted(na); + if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { + /* set compression writing parameters */ + na->compression_block_size + = 1 << (STANDARD_COMPRESSION_UNIT + vol->cluster_size_bits); + na->compression_block_clusters = 1 << STANDARD_COMPRESSION_UNIT; + } + + if (rl) { + /* Now copy the attribute value to the allocated cluster(s). */ + bw = ntfs_attr_pwrite(na, 0, le32_to_cpu(a->value_length), + (u8*)a + le16_to_cpu(a->value_offset)); + if (bw != le32_to_cpu(a->value_length)) { + err = errno; + ntfs_log_debug("Eeek! Failed to write out attribute value " + "(bw = %lli, errno = %i). " + "Aborting...\n", (long long)bw, err); + if (bw >= 0) + err = EIO; + goto cluster_free_err_out; + } + } + /* Determine the size of the mapping pairs array. */ + mp_size = ntfs_get_size_for_mapping_pairs(vol, rl, 0, INT_MAX); + if (mp_size < 0) { + err = errno; + ntfs_log_debug("Eeek! Failed to get size for mapping pairs array. " + "Aborting...\n"); + goto cluster_free_err_out; + } + /* Calculate new offsets for the name and the mapping pairs array. */ + if (na->ni->flags & FILE_ATTR_COMPRESSED) + name_ofs = (sizeof(ATTR_REC) + 7) & ~7; + else + name_ofs = (sizeof(ATTR_REC) - sizeof(a->compressed_size) + 7) & ~7; + mp_ofs = (name_ofs + a->name_length * sizeof(ntfschar) + 7) & ~7; + /* + * Determine the size of the resident part of the non-resident + * attribute record. (Not compressed thus no compressed_size element + * present.) + */ + arec_size = (mp_ofs + mp_size + 7) & ~7; + + /* Resize the resident part of the attribute record. */ + if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { + err = errno; + goto cluster_free_err_out; + } + + /* + * Convert the resident part of the attribute record to describe a + * non-resident attribute. + */ + a->non_resident = 1; + + /* Move the attribute name if it exists and update the offset. */ + if (a->name_length) + memmove((u8*)a + name_ofs, (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + a->name_offset = cpu_to_le16(name_ofs); + + /* Setup the fields specific to non-resident attributes. */ + a->lowest_vcn = cpu_to_sle64(0); + a->highest_vcn = cpu_to_sle64((new_allocated_size - 1) >> + vol->cluster_size_bits); + + a->mapping_pairs_offset = cpu_to_le16(mp_ofs); + + /* + * Update the flags to match the in-memory ones. + * However cannot change the compression state if we had + * a fuse_file_info open with a mark for release. + * The decisions about compression can only be made when + * creating/recreating the stream, not when making non resident. + */ + a->flags &= ~(ATTR_IS_SPARSE | ATTR_IS_ENCRYPTED); + if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { + /* support only ATTR_IS_COMPRESSED compression mode */ + a->compression_unit = STANDARD_COMPRESSION_UNIT; + a->compressed_size = const_cpu_to_le64(0); + } else { + a->compression_unit = 0; + a->flags &= ~ATTR_COMPRESSION_MASK; + na->data_flags = a->flags; + } + + memset(&a->reserved1, 0, sizeof(a->reserved1)); + + a->allocated_size = cpu_to_sle64(new_allocated_size); + a->data_size = a->initialized_size = cpu_to_sle64(na->data_size); + + /* Generate the mapping pairs array in the attribute record. */ + if (ntfs_mapping_pairs_build(vol, (u8*)a + mp_ofs, arec_size - mp_ofs, + rl, 0, NULL) < 0) { + // FIXME: Eeek! We need rollback! (AIA) + ntfs_log_trace("Eeek! Failed to build mapping pairs. Leaving " + "corrupt attribute record on disk. In memory " + "runlist is still intact! Error code is %i. " + "FIXME: Need to rollback instead!\n", errno); + return -1; + } + + /* Done! */ + return 0; + +cluster_free_err_out: + if (rl && ntfs_cluster_free(vol, na, 0, -1) < 0) + ntfs_log_trace("Eeek! Failed to release allocated clusters in error " + "code path. Leaving inconsistent metadata...\n"); + NAttrClearNonResident(na); + na->allocated_size = na->data_size; + na->rl = NULL; + free(rl); + errno = err; + return -1; +} + + +static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize); + +/** + * ntfs_resident_attr_resize - resize a resident, open ntfs attribute + * @na: resident ntfs attribute to resize + * @newsize: new size (in bytes) to which to resize the attribute + * + * Change the size of a resident, open ntfs attribute @na to @newsize bytes. + * + * On success return 0 + * On error return values are: + * STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT + * STATUS_ERROR - otherwise + * The following error codes are defined: + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + */ +static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize) +{ + ntfs_attr_search_ctx *ctx; + ntfs_volume *vol; + ntfs_inode *ni; + int err, ret = STATUS_ERROR; + + ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize); + + /* Get the attribute record that needs modification. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + if (ntfs_attr_lookup(na->type, na->name, na->name_len, 0, 0, NULL, 0, + ctx)) { + err = errno; + ntfs_log_perror("ntfs_attr_lookup failed"); + goto put_err_out; + } + vol = na->ni->vol; + /* + * Check the attribute type and the corresponding minimum and maximum + * sizes against @newsize and fail if @newsize is out of bounds. + */ + if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { + err = errno; + if (err == ENOENT) + err = EIO; + ntfs_log_perror("%s: bounds check failed", __FUNCTION__); + goto put_err_out; + } + /* + * If @newsize is bigger than the mft record we need to make the + * attribute non-resident if the attribute type supports it. If it is + * smaller we can go ahead and attempt the resize. + */ + if (newsize < vol->mft_record_size) { + /* Perform the resize of the attribute record. */ + if (!(ret = ntfs_resident_attr_value_resize(ctx->mrec, ctx->attr, + newsize))) { + /* Update attribute size everywhere. */ + na->data_size = na->initialized_size = newsize; + na->allocated_size = (newsize + 7) & ~7; + if ((na->data_flags & ATTR_COMPRESSION_MASK) + || NAttrSparse(na)) + na->compressed_size = na->allocated_size; + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + na->ni->allocated_size = na->allocated_size; + NInoFileNameSetDirty(na->ni); + } + goto resize_done; + } + /* Prefer AT_INDEX_ALLOCATION instead of AT_ATTRIBUTE_LIST */ + if (ret == STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT) { + err = errno; + goto put_err_out; + } + } + /* There is not enough space in the mft record to perform the resize. */ + + /* Make the attribute non-resident if possible. */ + if (!ntfs_attr_make_non_resident(na, ctx)) { + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + /* Resize non-resident attribute */ + return ntfs_attr_truncate(na, newsize); + } else if (errno != ENOSPC && errno != EPERM) { + err = errno; + ntfs_log_perror("Failed to make attribute non-resident"); + goto put_err_out; + } + + /* Try to make other attributes non-resident and retry each time. */ + ntfs_attr_init_search_ctx(ctx, NULL, na->ni->mrec); + while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { + ntfs_attr *tna; + ATTR_RECORD *a; + + a = ctx->attr; + if (a->non_resident) + continue; + + /* + * Check out whether convert is reasonable. Assume that mapping + * pairs will take 8 bytes. + */ + if (le32_to_cpu(a->length) <= offsetof(ATTR_RECORD, + compressed_size) + ((a->name_length * + sizeof(ntfschar) + 7) & ~7) + 8) + continue; + + tna = ntfs_attr_open(na->ni, a->type, (ntfschar*)((u8*)a + + le16_to_cpu(a->name_offset)), a->name_length); + if (!tna) { + err = errno; + ntfs_log_perror("Couldn't open attribute"); + goto put_err_out; + } + if (ntfs_attr_make_non_resident(tna, ctx)) { + ntfs_attr_close(tna); + continue; + } + ntfs_inode_mark_dirty(tna->ni); + ntfs_attr_close(tna); + ntfs_attr_put_search_ctx(ctx); + return ntfs_resident_attr_resize(na, newsize); + } + /* Check whether error occurred. */ + if (errno != ENOENT) { + err = errno; + ntfs_log_perror("%s: Attribute lookup failed 1", __FUNCTION__); + goto put_err_out; + } + + /* + * The standard information and attribute list attributes can't be + * moved out from the base MFT record, so try to move out others. + */ + if (na->type==AT_STANDARD_INFORMATION || na->type==AT_ATTRIBUTE_LIST) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_free_space(na->ni, offsetof(ATTR_RECORD, + non_resident_end) + 8)) { + ntfs_log_perror("Could not free space in MFT record"); + return -1; + } + return ntfs_resident_attr_resize(na, newsize); + } + + /* + * Move the attribute to a new mft record, creating an attribute list + * attribute or modifying it if it is already present. + */ + + /* Point search context back to attribute which we need resize. */ + ntfs_attr_init_search_ctx(ctx, na->ni, NULL); + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + ntfs_log_perror("%s: Attribute lookup failed 2", __FUNCTION__); + err = errno; + goto put_err_out; + } + + /* + * Check whether attribute is already single in this MFT record. + * 8 added for the attribute terminator. + */ + if (le32_to_cpu(ctx->mrec->bytes_in_use) == + le16_to_cpu(ctx->mrec->attrs_offset) + + le32_to_cpu(ctx->attr->length) + 8) { + err = ENOSPC; + ntfs_log_trace("MFT record is filled with one attribute\n"); + ret = STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT; + goto put_err_out; + } + + /* Add attribute list if not present. */ + if (na->ni->nr_extents == -1) + ni = na->ni->base_ni; + else + ni = na->ni; + if (!NInoAttrList(ni)) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_add_attrlist(ni)) + return -1; + return ntfs_resident_attr_resize(na, newsize); + } + /* Allocate new mft record. */ + ni = ntfs_mft_record_alloc(vol, ni); + if (!ni) { + err = errno; + ntfs_log_perror("Couldn't allocate new MFT record"); + goto put_err_out; + } + /* Move attribute to it. */ + if (ntfs_attr_record_move_to(ctx, ni)) { + err = errno; + ntfs_log_perror("Couldn't move attribute to new MFT record"); + goto put_err_out; + } + /* Update ntfs attribute. */ + if (na->ni->nr_extents == -1) + na->ni = ni; + + ntfs_attr_put_search_ctx(ctx); + /* Try to perform resize once again. */ + return ntfs_resident_attr_resize(na, newsize); + +resize_done: + /* + * Set the inode (and its base inode if it exists) dirty so it is + * written out later. + */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + return 0; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return ret; +} + +static int ntfs_resident_attr_resize(ntfs_attr *na, const s64 newsize) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_resident_attr_resize_i(na, newsize); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_make_resident - convert a non-resident to a resident attribute + * @na: open ntfs attribute to make resident + * @ctx: ntfs search context describing the attribute + * + * Convert a non-resident ntfs attribute to a resident one. + * + * Return 0 on success and -1 on error with errno set to the error code. The + * following error codes are defined: + * EINVAL - Invalid arguments passed. + * EPERM - The attribute is not allowed to be resident. + * EIO - I/O error, damaged inode or bug. + * ENOSPC - There is no enough space to perform conversion. + * EOPNOTSUPP - Requested conversion is not supported yet. + * + * Warning: We do not set the inode dirty and we do not write out anything! + * We expect the caller to do this as this is a fairly low level + * function and it is likely there will be further changes made. + */ +static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) +{ + ntfs_volume *vol = na->ni->vol; + ATTR_REC *a = ctx->attr; + int name_ofs, val_ofs, err = EIO; + s64 arec_size, bytes_read; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long + long)na->ni->mft_no, na->type); + + /* Should be called for the first extent of the attribute. */ + if (sle64_to_cpu(a->lowest_vcn)) { + ntfs_log_trace("Eeek! Should be called for the first extent of the " + "attribute. Aborting...\n"); + err = EINVAL; + return -1; + } + + /* Some preliminary sanity checking. */ + if (!NAttrNonResident(na)) { + ntfs_log_trace("Eeek! Trying to make resident attribute resident. " + "Aborting...\n"); + errno = EINVAL; + return -1; + } + + /* Make sure this is not $MFT/$BITMAP or Windows will not boot! */ + if (na->type == AT_BITMAP && na->ni->mft_no == FILE_MFT) { + errno = EPERM; + return -1; + } + + /* Check that the attribute is allowed to be resident. */ + if (ntfs_attr_can_be_resident(vol, na->type)) + return -1; + + if (na->data_flags & ATTR_IS_ENCRYPTED) { + ntfs_log_trace("Making encrypted streams resident is not " + "implemented yet.\n"); + errno = EOPNOTSUPP; + return -1; + } + + /* Work out offsets into and size of the resident attribute. */ + name_ofs = 24; /* = sizeof(resident_ATTR_REC); */ + val_ofs = (name_ofs + a->name_length * sizeof(ntfschar) + 7) & ~7; + arec_size = (val_ofs + na->data_size + 7) & ~7; + + /* Sanity check the size before we start modifying the attribute. */ + if (le32_to_cpu(ctx->mrec->bytes_in_use) - le32_to_cpu(a->length) + + arec_size > le32_to_cpu(ctx->mrec->bytes_allocated)) { + errno = ENOSPC; + ntfs_log_trace("Not enough space to make attribute resident\n"); + return -1; + } + + /* Read and cache the whole runlist if not already done. */ + if (ntfs_attr_map_whole_runlist(na)) + return -1; + + /* Move the attribute name if it exists and update the offset. */ + if (a->name_length) { + memmove((u8*)a + name_ofs, (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + } + a->name_offset = cpu_to_le16(name_ofs); + + /* Resize the resident part of the attribute record. */ + if (ntfs_attr_record_resize(ctx->mrec, a, arec_size) < 0) { + /* + * Bug, because ntfs_attr_record_resize should not fail (we + * already checked that attribute fits MFT record). + */ + ntfs_log_error("BUG! Failed to resize attribute record. " + "Please report to the %s. Aborting...\n", + NTFS_DEV_LIST); + errno = EIO; + return -1; + } + + /* Convert the attribute record to describe a resident attribute. */ + a->non_resident = 0; + a->flags = 0; + a->value_length = cpu_to_le32(na->data_size); + a->value_offset = cpu_to_le16(val_ofs); + /* + * If a data stream was wiped out, adjust the compression mode + * to current state of compression flag + */ + if (!na->data_size + && (na->type == AT_DATA) + && (na->ni->flags & FILE_ATTR_COMPRESSED)) { + a->flags |= ATTR_IS_COMPRESSED; + na->data_flags = a->flags; + } + /* + * File names cannot be non-resident so we would never see this here + * but at least it serves as a reminder that there may be attributes + * for which we do need to set this flag. (AIA) + */ + if (a->type == AT_FILE_NAME) + a->resident_flags = RESIDENT_ATTR_IS_INDEXED; + else + a->resident_flags = 0; + a->reservedR = 0; + + /* Sanity fixup... Shouldn't really happen. (AIA) */ + if (na->initialized_size > na->data_size) + na->initialized_size = na->data_size; + + /* Copy data from run list to resident attribute value. */ + bytes_read = ntfs_rl_pread(vol, na->rl, 0, na->initialized_size, + (u8*)a + val_ofs); + if (bytes_read != na->initialized_size) { + if (bytes_read < 0) + err = errno; + ntfs_log_trace("Eeek! Failed to read attribute data. Leaving " + "inconstant metadata. Run chkdsk. " + "Aborting...\n"); + errno = err; + return -1; + } + + /* Clear memory in gap between initialized_size and data_size. */ + if (na->initialized_size < na->data_size) + memset((u8*)a + val_ofs + na->initialized_size, 0, + na->data_size - na->initialized_size); + + /* + * Deallocate clusters from the runlist. + * + * NOTE: We can use ntfs_cluster_free() because we have already mapped + * the whole run list and thus it doesn't matter that the attribute + * record is in a transiently corrupted state at this moment in time. + */ + if (ntfs_cluster_free(vol, na, 0, -1) < 0) { + err = errno; + ntfs_log_perror("Eeek! Failed to release allocated clusters"); + ntfs_log_trace("Ignoring error and leaving behind wasted " + "clusters.\n"); + } + + /* Throw away the now unused runlist. */ + free(na->rl); + na->rl = NULL; + + /* Update in-memory struct ntfs_attr. */ + NAttrClearNonResident(na); + NAttrClearSparse(na); + NAttrClearEncrypted(na); + na->initialized_size = na->data_size; + na->allocated_size = na->compressed_size = (na->data_size + 7) & ~7; + na->compression_block_size = 0; + na->compression_block_size_bits = na->compression_block_clusters = 0; + return 0; +} + +/* + * If we are in the first extent, then set/clean sparse bit, + * update allocated and compressed size. + */ +static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, + ntfs_attr_search_ctx *ctx) +{ + int sparse, ret = 0; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x\n", + (unsigned long long)na->ni->mft_no, na->type); + + if (a->lowest_vcn) + goto out; + + a->allocated_size = cpu_to_sle64(na->allocated_size); + + /* Update sparse bit. */ + sparse = ntfs_rl_sparse(na->rl); + if (sparse == -1) { + errno = EIO; + goto error; + } + + /* Attribute become sparse. */ + if (sparse && !(a->flags & (ATTR_IS_SPARSE | ATTR_IS_COMPRESSED))) { + /* + * Move attribute to another mft record, if attribute is too + * small to add compressed_size field to it and we have no + * free space in the current mft record. + */ + if ((le32_to_cpu(a->length) - + le16_to_cpu(a->mapping_pairs_offset) == 8) + && !(le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use))) { + + if (!NInoAttrList(na->ni)) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_add_attrlist(na->ni)) + goto leave; + goto retry; + } + if (ntfs_attr_record_move_away(ctx, 8)) { + ntfs_log_perror("Failed to move attribute"); + goto error; + } + ntfs_attr_put_search_ctx(ctx); + goto retry; + } + if (!(le32_to_cpu(a->length) - le16_to_cpu( + a->mapping_pairs_offset))) { + errno = EIO; + ntfs_log_perror("Mapping pairs space is 0"); + goto error; + } + + NAttrSetSparse(na); + a->flags |= ATTR_IS_SPARSE; + a->compression_unit = STANDARD_COMPRESSION_UNIT; /* Windows + set it so, even if attribute is not actually compressed. */ + + memmove((u8*)a + le16_to_cpu(a->name_offset) + 8, + (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + + a->name_offset = cpu_to_le16(le16_to_cpu(a->name_offset) + 8); + + a->mapping_pairs_offset = + cpu_to_le16(le16_to_cpu(a->mapping_pairs_offset) + 8); + } + + /* Attribute no longer sparse. */ + if (!sparse && (a->flags & ATTR_IS_SPARSE) && + !(a->flags & ATTR_IS_COMPRESSED)) { + + NAttrClearSparse(na); + a->flags &= ~ATTR_IS_SPARSE; + a->compression_unit = 0; + + memmove((u8*)a + le16_to_cpu(a->name_offset) - 8, + (u8*)a + le16_to_cpu(a->name_offset), + a->name_length * sizeof(ntfschar)); + + if (le16_to_cpu(a->name_offset) >= 8) + a->name_offset = cpu_to_le16(le16_to_cpu(a->name_offset) - 8); + + a->mapping_pairs_offset = + cpu_to_le16(le16_to_cpu(a->mapping_pairs_offset) - 8); + } + + /* Update compressed size if required. */ + if (sparse || (na->data_flags & ATTR_COMPRESSION_MASK)) { + s64 new_compr_size; + + new_compr_size = ntfs_rl_get_compressed_size(na->ni->vol, na->rl); + if (new_compr_size == -1) + goto error; + + na->compressed_size = new_compr_size; + a->compressed_size = cpu_to_sle64(new_compr_size); + } + /* + * Set FILE_NAME dirty flag, to update sparse bit and + * allocated size in the index. + */ + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + if (sparse) + na->ni->allocated_size = na->compressed_size; + else + na->ni->allocated_size = na->allocated_size; + NInoFileNameSetDirty(na->ni); + } +out: + return ret; +leave: ret = -1; goto out; /* return -1 */ +retry: ret = -2; goto out; +error: ret = -3; goto out; +} + +#define NTFS_VCN_DELETE_MARK -2 +/** + * ntfs_attr_update_mapping_pairs_i - see ntfs_attr_update_mapping_pairs + */ +static int ntfs_attr_update_mapping_pairs_i(ntfs_attr *na, VCN from_vcn) +{ + ntfs_attr_search_ctx *ctx; + ntfs_inode *ni, *base_ni; + MFT_RECORD *m; + ATTR_RECORD *a; + VCN stop_vcn; + const runlist_element *stop_rl; + int err, mp_size, cur_max_mp_size, exp_max_mp_size, ret = -1; + BOOL finished_build; + +retry: + if (!na || !na->rl || from_vcn) { + errno = EINVAL; + ntfs_log_perror("%s: na=%p", __FUNCTION__, na); + return -1; + } + + ntfs_log_trace("Entering for inode %llu, attr 0x%x\n", + (unsigned long long)na->ni->mft_no, na->type); + + if (!NAttrNonResident(na)) { + errno = EINVAL; + ntfs_log_perror("%s: resident attribute", __FUNCTION__); + return -1; + } + + if (na->ni->nr_extents == -1) + base_ni = na->ni->base_ni; + else + base_ni = na->ni; + + ctx = ntfs_attr_get_search_ctx(base_ni, NULL); + if (!ctx) + return -1; + + /* Fill attribute records with new mapping pairs. */ + stop_vcn = 0; + stop_rl = na->rl; + finished_build = FALSE; + while (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, from_vcn, NULL, 0, ctx)) { + a = ctx->attr; + m = ctx->mrec; + /* + * If runlist is updating not from the beginning, then set + * @stop_vcn properly, i.e. to the lowest vcn of record that + * contain @from_vcn. Also we do not need @from_vcn anymore, + * set it to 0 to make ntfs_attr_lookup enumerate attributes. + */ + if (from_vcn) { + LCN first_lcn; + + stop_vcn = sle64_to_cpu(a->lowest_vcn); + from_vcn = 0; + /* + * Check whether the first run we need to update is + * the last run in runlist, if so, then deallocate + * all attrubute extents starting this one. + */ + first_lcn = ntfs_rl_vcn_to_lcn(na->rl, stop_vcn); + if (first_lcn == LCN_EINVAL) { + errno = EIO; + ntfs_log_perror("Bad runlist"); + goto put_err_out; + } + if (first_lcn == LCN_ENOENT || + first_lcn == LCN_RL_NOT_MAPPED) + finished_build = TRUE; + } + + /* + * Check whether we finished mapping pairs build, if so mark + * extent as need to delete (by setting highest vcn to + * NTFS_VCN_DELETE_MARK (-2), we shall check it later and + * delete extent) and continue search. + */ + if (finished_build) { + ntfs_log_trace("Mark attr 0x%x for delete in inode " + "%lld.\n", (unsigned)le32_to_cpu(a->type), + (long long)ctx->ntfs_ino->mft_no); + a->highest_vcn = cpu_to_sle64(NTFS_VCN_DELETE_MARK); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + continue; + } + + switch (ntfs_attr_update_meta(a, na, m, ctx)) { + case -1: return -1; + case -2: goto retry; + case -3: goto put_err_out; + } + + /* + * Determine maximum possible length of mapping pairs, + * if we shall *not* expand space for mapping pairs. + */ + cur_max_mp_size = le32_to_cpu(a->length) - + le16_to_cpu(a->mapping_pairs_offset); + /* + * Determine maximum possible length of mapping pairs in the + * current mft record, if we shall expand space for mapping + * pairs. + */ + exp_max_mp_size = le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use) + cur_max_mp_size; + /* Get the size for the rest of mapping pairs array. */ + mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, stop_rl, + stop_vcn, exp_max_mp_size); + if (mp_size <= 0) { + ntfs_log_perror("%s: get MP size failed", __FUNCTION__); + goto put_err_out; + } + /* Test mapping pairs for fitting in the current mft record. */ + if (mp_size > exp_max_mp_size) { + /* + * Mapping pairs of $ATTRIBUTE_LIST attribute must fit + * in the base mft record. Try to move out other + * attributes and try again. + */ + if (na->type == AT_ATTRIBUTE_LIST) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_free_space(na->ni, mp_size - + cur_max_mp_size)) { + ntfs_log_perror("Attribute list is too " + "big. Defragment the " + "volume\n"); + return -1; + } + goto retry; + } + + /* Add attribute list if it isn't present, and retry. */ + if (!NInoAttrList(base_ni)) { + ntfs_attr_put_search_ctx(ctx); + if (ntfs_inode_add_attrlist(base_ni)) { + ntfs_log_perror("Can not add attrlist"); + return -1; + } + goto retry; + } + + /* + * Set mapping pairs size to maximum possible for this + * mft record. We shall write the rest of mapping pairs + * to another MFT records. + */ + mp_size = exp_max_mp_size; + } + + /* Change space for mapping pairs if we need it. */ + if (((mp_size + 7) & ~7) != cur_max_mp_size) { + if (ntfs_attr_record_resize(m, a, + le16_to_cpu(a->mapping_pairs_offset) + + mp_size)) { + errno = EIO; + ntfs_log_perror("Failed to resize attribute"); + goto put_err_out; + } + } + + /* Update lowest vcn. */ + a->lowest_vcn = cpu_to_sle64(stop_vcn); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + if ((ctx->ntfs_ino->nr_extents == -1 || + NInoAttrList(ctx->ntfs_ino)) && + ctx->attr->type != AT_ATTRIBUTE_LIST) { + ctx->al_entry->lowest_vcn = cpu_to_sle64(stop_vcn); + ntfs_attrlist_mark_dirty(ctx->ntfs_ino); + } + + /* + * Generate the new mapping pairs array directly into the + * correct destination, i.e. the attribute record itself. + */ + if (!ntfs_mapping_pairs_build(na->ni->vol, (u8*)a + le16_to_cpu( + a->mapping_pairs_offset), mp_size, na->rl, + stop_vcn, &stop_rl)) + finished_build = TRUE; + if (stop_rl) + stop_vcn = stop_rl->vcn; + else + stop_vcn = 0; + if (!finished_build && errno != ENOSPC) { + ntfs_log_perror("Failed to build mapping pairs"); + goto put_err_out; + } + a->highest_vcn = cpu_to_sle64(stop_vcn - 1); + } + /* Check whether error occurred. */ + if (errno != ENOENT) { + ntfs_log_perror("%s: Attribute lookup failed", __FUNCTION__); + goto put_err_out; + } + + /* Deallocate not used attribute extents and return with success. */ + if (finished_build) { + ntfs_attr_reinit_search_ctx(ctx); + ntfs_log_trace("Deallocate marked extents.\n"); + while (!ntfs_attr_lookup(na->type, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (sle64_to_cpu(ctx->attr->highest_vcn) != + NTFS_VCN_DELETE_MARK) + continue; + /* Remove unused attribute record. */ + if (ntfs_attr_record_rm(ctx)) { + ntfs_log_perror("Could not remove unused attr"); + goto put_err_out; + } + ntfs_attr_reinit_search_ctx(ctx); + } + if (errno != ENOENT) { + ntfs_log_perror("%s: Attr lookup failed", __FUNCTION__); + goto put_err_out; + } + ntfs_log_trace("Deallocate done.\n"); + ntfs_attr_put_search_ctx(ctx); + goto ok; + } + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + + /* Allocate new MFT records for the rest of mapping pairs. */ + while (1) { + /* Calculate size of rest mapping pairs. */ + mp_size = ntfs_get_size_for_mapping_pairs(na->ni->vol, + na->rl, stop_vcn, INT_MAX); + if (mp_size <= 0) { + ntfs_log_perror("%s: get mp size failed", __FUNCTION__); + goto put_err_out; + } + /* Allocate new mft record. */ + ni = ntfs_mft_record_alloc(na->ni->vol, base_ni); + if (!ni) { + ntfs_log_perror("Could not allocate new MFT record"); + goto put_err_out; + } + m = ni->mrec; + /* + * If mapping size exceed available space, set them to + * possible maximum. + */ + cur_max_mp_size = le32_to_cpu(m->bytes_allocated) - + le32_to_cpu(m->bytes_in_use) - + (offsetof(ATTR_RECORD, compressed_size) + + (((na->data_flags & ATTR_COMPRESSION_MASK) + || NAttrSparse(na)) ? + sizeof(a->compressed_size) : 0)) - + ((sizeof(ntfschar) * na->name_len + 7) & ~7); + if (mp_size > cur_max_mp_size) + mp_size = cur_max_mp_size; + /* Add attribute extent to new record. */ + err = ntfs_non_resident_attr_record_add(ni, na->type, + na->name, na->name_len, stop_vcn, mp_size, + na->data_flags); + if (err == -1) { + err = errno; + ntfs_log_perror("Could not add attribute extent"); + if (ntfs_mft_record_free(na->ni->vol, ni)) + ntfs_log_perror("Could not free MFT record"); + errno = err; + goto put_err_out; + } + a = (ATTR_RECORD*)((u8*)m + err); + + err = ntfs_mapping_pairs_build(na->ni->vol, (u8*)a + + le16_to_cpu(a->mapping_pairs_offset), mp_size, na->rl, + stop_vcn, &stop_rl); + if (stop_rl) + stop_vcn = stop_rl->vcn; + else + stop_vcn = 0; + if (err < 0 && errno != ENOSPC) { + err = errno; + ntfs_log_perror("Failed to build MP"); + if (ntfs_mft_record_free(na->ni->vol, ni)) + ntfs_log_perror("Couldn't free MFT record"); + errno = err; + goto put_err_out; + } + a->highest_vcn = cpu_to_sle64(stop_vcn - 1); + ntfs_inode_mark_dirty(ni); + /* All mapping pairs has been written. */ + if (!err) + break; + } +ok: + ret = 0; +out: + return ret; +put_err_out: + if (ctx) + ntfs_attr_put_search_ctx(ctx); + goto out; +} +#undef NTFS_VCN_DELETE_MARK + +/** + * ntfs_attr_update_mapping_pairs - update mapping pairs for ntfs attribute + * @na: non-resident ntfs open attribute for which we need update + * @from_vcn: update runlist starting this VCN + * + * Build mapping pairs from @na->rl and write them to the disk. Also, this + * function updates sparse bit, allocated and compressed size (allocates/frees + * space for this field if required). + * + * @na->allocated_size should be set to correct value for the new runlist before + * call to this function. Vice-versa @na->compressed_size will be calculated and + * set to correct value during this function. + * + * FIXME: This function does not update sparse bit and compressed size correctly + * if called with @from_vcn != 0. + * + * FIXME: Rewrite without using NTFS_VCN_DELETE_MARK define. + * + * On success return 0 and on error return -1 with errno set to the error code. + * The following error codes are defined: + * EINVAL - Invalid arguments passed. + * ENOMEM - Not enough memory to complete operation. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST + * or there is no free MFT records left to allocate. + */ +int ntfs_attr_update_mapping_pairs(ntfs_attr *na, VCN from_vcn) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_attr_update_mapping_pairs_i(na, from_vcn); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_non_resident_attr_shrink - shrink a non-resident, open ntfs attribute + * @na: non-resident ntfs attribute to shrink + * @newsize: new size (in bytes) to which to shrink the attribute + * + * Reduce the size of a non-resident, open ntfs attribute @na to @newsize bytes. + * + * On success return 0 and on error return -1 with errno set to the error code. + * The following error codes are defined: + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + */ +static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) +{ + ntfs_volume *vol; + ntfs_attr_search_ctx *ctx; + VCN first_free_vcn; + s64 nr_freed_clusters; + int err; + + ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", (unsigned long long) + na->ni->mft_no, na->type, (long long)newsize); + + vol = na->ni->vol; + + /* + * Check the attribute type and the corresponding minimum size + * against @newsize and fail if @newsize is too small. + */ + if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { + if (errno == ERANGE) { + ntfs_log_trace("Eeek! Size bounds check failed. " + "Aborting...\n"); + } else if (errno == ENOENT) + errno = EIO; + return -1; + } + + /* The first cluster outside the new allocation. */ + first_free_vcn = (newsize + vol->cluster_size - 1) >> + vol->cluster_size_bits; + /* + * Compare the new allocation with the old one and only deallocate + * clusters if there is a change. + */ + if ((na->allocated_size >> vol->cluster_size_bits) != first_free_vcn) { + if (ntfs_attr_map_whole_runlist(na)) { + ntfs_log_trace("Eeek! ntfs_attr_map_whole_runlist " + "failed.\n"); + return -1; + } + /* Deallocate all clusters starting with the first free one. */ + nr_freed_clusters = ntfs_cluster_free(vol, na, first_free_vcn, + -1); + if (nr_freed_clusters < 0) { + ntfs_log_trace("Eeek! Freeing of clusters failed. " + "Aborting...\n"); + return -1; + } + + /* Truncate the runlist itself. */ + if (ntfs_rl_truncate(&na->rl, first_free_vcn)) { + /* + * Failed to truncate the runlist, so just throw it + * away, it will be mapped afresh on next use. + */ + free(na->rl); + na->rl = NULL; + ntfs_log_trace("Eeek! Run list truncation failed.\n"); + return -1; + } + + /* Prepare to mapping pairs update. */ + na->allocated_size = first_free_vcn << vol->cluster_size_bits; + /* Write mapping pairs for new runlist. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*first_free_vcn*/)) { + ntfs_log_trace("Eeek! Mapping pairs update failed. " + "Leaving inconstant metadata. " + "Run chkdsk.\n"); + return -1; + } + } + + /* Get the first attribute record. */ + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) + return -1; + + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + err = errno; + if (err == ENOENT) + err = EIO; + ntfs_log_trace("Eeek! Lookup of first attribute extent failed. " + "Leaving inconstant metadata.\n"); + goto put_err_out; + } + + /* Update data and initialized size. */ + na->data_size = newsize; + ctx->attr->data_size = cpu_to_sle64(newsize); + if (newsize < na->initialized_size) { + na->initialized_size = newsize; + ctx->attr->initialized_size = cpu_to_sle64(newsize); + } + /* Update data size in the index. */ + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + NInoFileNameSetDirty(na->ni); + } + + /* If the attribute now has zero size, make it resident. */ + if (!newsize) { + if (ntfs_attr_make_resident(na, ctx)) { + /* If couldn't make resident, just continue. */ + if (errno != EPERM) + ntfs_log_error("Failed to make attribute " + "resident. Leaving as is...\n"); + } + } + + /* Set the inode dirty so it is written out later. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + /* Done! */ + ntfs_attr_put_search_ctx(ctx); + return 0; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_non_resident_attr_expand - expand a non-resident, open ntfs attribute + * @na: non-resident ntfs attribute to expand + * @newsize: new size (in bytes) to which to expand the attribute + * + * Expand the size of a non-resident, open ntfs attribute @na to @newsize bytes, + * by allocating new clusters. + * + * On success return 0 and on error return -1 with errno set to the error code. + * The following error codes are defined: + * ENOMEM - Not enough memory to complete operation. + * ERANGE - @newsize is not valid for the attribute type of @na. + * ENOSPC - There is no enough space in base mft to resize $ATTRIBUTE_LIST. + */ +static int ntfs_non_resident_attr_expand_i(ntfs_attr *na, const s64 newsize) +{ + LCN lcn_seek_from; + VCN first_free_vcn; + ntfs_volume *vol; + ntfs_attr_search_ctx *ctx; + runlist *rl, *rln; + s64 org_alloc_size; + int err; + + ntfs_log_trace("Inode %lld, attr 0x%x, new size %lld old size %lld\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize, (long long)na->data_size); + + vol = na->ni->vol; + + /* + * Check the attribute type and the corresponding maximum size + * against @newsize and fail if @newsize is too big. + */ + if (ntfs_attr_size_bounds_check(vol, na->type, newsize) < 0) { + if (errno == ENOENT) + errno = EIO; + ntfs_log_perror("%s: bounds check failed", __FUNCTION__); + return -1; + } + + /* Save for future use. */ + org_alloc_size = na->allocated_size; + /* The first cluster outside the new allocation. */ + first_free_vcn = (newsize + vol->cluster_size - 1) >> + vol->cluster_size_bits; + /* + * Compare the new allocation with the old one and only allocate + * clusters if there is a change. + */ + if ((na->allocated_size >> vol->cluster_size_bits) < first_free_vcn) { + if (ntfs_attr_map_whole_runlist(na)) { + ntfs_log_perror("ntfs_attr_map_whole_runlist failed"); + return -1; + } + + /* + * If we extend $DATA attribute on NTFS 3+ volume, we can add + * sparse runs instead of real allocation of clusters. + */ + if (na->type == AT_DATA && vol->major_ver >= 3) { + rl = ntfs_malloc(0x1000); + if (!rl) + return -1; + + rl[0].vcn = (na->allocated_size >> + vol->cluster_size_bits); + rl[0].lcn = LCN_HOLE; + rl[0].length = first_free_vcn - + (na->allocated_size >> vol->cluster_size_bits); + rl[1].vcn = first_free_vcn; + rl[1].lcn = LCN_ENOENT; + rl[1].length = 0; + } else { + /* + * Determine first after last LCN of attribute. + * We will start seek clusters from this LCN to avoid + * fragmentation. If there are no valid LCNs in the + * attribute let the cluster allocator choose the + * starting LCN. + */ + lcn_seek_from = -1; + if (na->rl->length) { + /* Seek to the last run list element. */ + for (rl = na->rl; (rl + 1)->length; rl++) + ; + /* + * If the last LCN is a hole or similar seek + * back to last valid LCN. + */ + while (rl->lcn < 0 && rl != na->rl) + rl--; + /* + * Only set lcn_seek_from it the LCN is valid. + */ + if (rl->lcn >= 0) + lcn_seek_from = rl->lcn + rl->length; + } + + rl = ntfs_cluster_alloc(vol, na->allocated_size >> + vol->cluster_size_bits, first_free_vcn - + (na->allocated_size >> + vol->cluster_size_bits), lcn_seek_from, + DATA_ZONE); + if (!rl) { + ntfs_log_perror("Cluster allocation failed " + "(%lld)", + (long long)first_free_vcn - + ((long long)na->allocated_size >> + vol->cluster_size_bits)); + return -1; + } + } + + /* Append new clusters to attribute runlist. */ + rln = ntfs_runlists_merge(na->rl, rl); + if (!rln) { + /* Failed, free just allocated clusters. */ + err = errno; + ntfs_log_perror("Run list merge failed"); + ntfs_cluster_free_from_rl(vol, rl); + free(rl); + errno = err; + return -1; + } + na->rl = rln; + + /* Prepare to mapping pairs update. */ + na->allocated_size = first_free_vcn << vol->cluster_size_bits; + /* Write mapping pairs for new runlist. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*na->allocated_size >> + vol->cluster_size_bits*/)) { + err = errno; + ntfs_log_perror("Mapping pairs update failed"); + goto rollback; + } + } + + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) { + err = errno; + if (na->allocated_size == org_alloc_size) { + errno = err; + return -1; + } else + goto rollback; + } + + if (ntfs_attr_lookup(na->type, na->name, na->name_len, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + err = errno; + ntfs_log_perror("Lookup of first attribute extent failed"); + if (err == ENOENT) + err = EIO; + if (na->allocated_size != org_alloc_size) { + ntfs_attr_put_search_ctx(ctx); + goto rollback; + } else + goto put_err_out; + } + + /* Update data size. */ + na->data_size = newsize; + ctx->attr->data_size = cpu_to_sle64(newsize); + /* Update data size in the index. */ + if (na->type == AT_DATA && na->name == AT_UNNAMED) { + na->ni->data_size = na->data_size; + NInoFileNameSetDirty(na->ni); + } + /* Set the inode dirty so it is written out later. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + /* Done! */ + ntfs_attr_put_search_ctx(ctx); + return 0; +rollback: + /* Free allocated clusters. */ + if (ntfs_cluster_free(vol, na, org_alloc_size >> + vol->cluster_size_bits, -1) < 0) { + err = EIO; + ntfs_log_perror("Leaking clusters"); + } + /* Now, truncate the runlist itself. */ + if (ntfs_rl_truncate(&na->rl, org_alloc_size >> + vol->cluster_size_bits)) { + /* + * Failed to truncate the runlist, so just throw it away, it + * will be mapped afresh on next use. + */ + free(na->rl); + na->rl = NULL; + ntfs_log_perror("Couldn't truncate runlist. Rollback failed"); + } else { + /* Prepare to mapping pairs update. */ + na->allocated_size = org_alloc_size; + /* Restore mapping pairs. */ + if (ntfs_attr_update_mapping_pairs(na, 0 /*na->allocated_size >> + vol->cluster_size_bits*/)) { + ntfs_log_perror("Failed to restore old mapping pairs"); + } + } + errno = err; + return -1; +put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + + +static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_non_resident_attr_expand_i(na, newsize); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_attr_truncate - resize an ntfs attribute + * @na: open ntfs attribute to resize + * @newsize: new size (in bytes) to which to resize the attribute + * + * Change the size of an open ntfs attribute @na to @newsize bytes. If the + * attribute is made bigger and the attribute is resident the newly + * "allocated" space is cleared and if the attribute is non-resident the + * newly allocated space is marked as not initialised and no real allocation + * on disk is performed. + * + * On success return 0. + * On error return values are: + * STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT + * STATUS_ERROR - otherwise + * The following error codes are defined: + * EINVAL - Invalid arguments were passed to the function. + * EOPNOTSUPP - The desired resize is not implemented yet. + * EACCES - Encrypted attribute. + */ +int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize) +{ + int ret = STATUS_ERROR; + s64 fullsize; + BOOL compressed; + + if (!na || newsize < 0 || + (na->ni->mft_no == FILE_MFT && na->type == AT_DATA)) { + ntfs_log_trace("Invalid arguments passed.\n"); + errno = EINVAL; + return STATUS_ERROR; + } + + ntfs_log_enter("Entering for inode %lld, attr 0x%x, size %lld\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize); + + if (na->data_size == newsize) { + ntfs_log_trace("Size is already ok\n"); + ret = STATUS_OK; + goto out; + } + /* + * Encrypted attributes are not supported. We return access denied, + * which is what Windows NT4 does, too. + */ + if (na->data_flags & ATTR_IS_ENCRYPTED) { + errno = EACCES; + ntfs_log_info("Failed to truncate encrypted attribute"); + goto out; + } + /* + * TODO: Implement making handling of compressed attributes. + * Currently we can only expand the attribute or delete it, + * and only for ATTR_IS_COMPRESSED. This is however possible + * for resident attributes when there is no open fuse context + * (important case : $INDEX_ROOT:$I30) + */ + compressed = (na->data_flags & ATTR_COMPRESSION_MASK) + != const_cpu_to_le16(0); + if (compressed + && NAttrNonResident(na) + && (((na->data_flags & ATTR_COMPRESSION_MASK) != ATTR_IS_COMPRESSED) + || (newsize && (newsize < na->data_size)))) { + errno = EOPNOTSUPP; + ntfs_log_perror("Failed to truncate compressed attribute"); + goto out; + } + if (NAttrNonResident(na)) { + /* + * For compressed data, the last block must be fully + * allocated, and we do not known the size of compression + * block until the attribute has been made non-resident. + * Moreover we can only process a single compression + * block at a time (from where we are about to write), + * so we silently do not allocate more. + * + * Note : do not request truncate on compressed files + * unless being able to face the consequences ! + */ + if (compressed && newsize) + fullsize = (na->initialized_size + | (na->compression_block_size - 1)) + 1; + else + fullsize = newsize; + if (fullsize > na->data_size) + ret = ntfs_non_resident_attr_expand(na, fullsize); + else + ret = ntfs_non_resident_attr_shrink(na, fullsize); + } else + ret = ntfs_resident_attr_resize(na, newsize); +out: + ntfs_log_leave("Return status %d\n", ret); + return ret; +} + +/* + * Stuff a hole in a compressed file + * + * An unallocated hole must be aligned on compression block size. + * If needed current block and target block are stuffed with zeroes. + * + * Returns 0 if succeeded, + * -1 if it failed (as explained in errno) + */ + +static int stuff_hole(ntfs_attr *na, const s64 pos) +{ + s64 size; + s64 begin_size; + s64 end_size; + char *buf; + int ret; + + ret = 0; + /* + * If the attribute is resident, the compression block size + * is not defined yet and we can make no decision. + * So we first try resizing to the target and if the + * attribute is still resident, we're done + */ + if (!NAttrNonResident(na)) { + ret = ntfs_resident_attr_resize(na, pos); + if (!ret && !NAttrNonResident(na)) + na->initialized_size = na->data_size = pos; + } + if (!ret && NAttrNonResident(na)) { + /* does the hole span over several compression block ? */ + if ((pos ^ na->initialized_size) + & ~(na->compression_block_size - 1)) { + begin_size = ((na->initialized_size - 1) + | (na->compression_block_size - 1)) + + 1 - na->initialized_size; + end_size = pos & (na->compression_block_size - 1); + size = (begin_size > end_size ? begin_size : end_size); + } else { + /* short stuffing in a single compression block */ + begin_size = size = pos - na->initialized_size; + end_size = 0; + } + if (size) + buf = (char*)ntfs_malloc(size); + else + buf = (char*)NULL; + if (buf || !size) { + memset(buf,0,size); + /* stuff into current block */ + if (begin_size + && (ntfs_attr_pwrite(na, + na->initialized_size, begin_size, buf) + != begin_size)) + ret = -1; + /* create an unstuffed hole */ + if (!ret + && ((na->initialized_size + end_size) < pos) + && ntfs_non_resident_attr_expand(na, + pos - end_size)) + ret = -1; + else + na->initialized_size + = na->data_size = pos - end_size; + /* stuff into the target block */ + if (!ret && end_size + && (ntfs_attr_pwrite(na, + na->initialized_size, end_size, buf) + != end_size)) + ret = -1; + if (buf) + free(buf); + } else + ret = -1; + } + /* make absolutely sure we have reached the target */ + if (!ret && (na->initialized_size != pos)) { + ntfs_log_error("Failed to stuff a compressed file" + "target %lld reached %lld\n", + (long long)pos, (long long)na->initialized_size); + errno = EIO; + ret = -1; + } + return (ret); +} + +/** + * ntfs_attr_readall - read the entire data from an ntfs attribute + * @ni: open ntfs inode in which the ntfs attribute resides + * @type: attribute type + * @name: attribute name in little endian Unicode or AT_UNNAMED or NULL + * @name_len: length of attribute @name in Unicode characters (if @name given) + * @data_size: if non-NULL then store here the data size + * + * This function will read the entire content of an ntfs attribute. + * If @name is AT_UNNAMED then look specifically for an unnamed attribute. + * If @name is NULL then the attribute could be either named or not. + * In both those cases @name_len is not used at all. + * + * On success a buffer is allocated with the content of the attribute + * and which needs to be freed when it's not needed anymore. If the + * @data_size parameter is non-NULL then the data size is set there. + * + * On error NULL is returned with errno set to the error code. + */ +void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len, s64 *data_size) +{ + ntfs_attr *na; + void *data, *ret = NULL; + s64 size; + + ntfs_log_enter("Entering\n"); + + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + ntfs_log_perror("ntfs_attr_open failed"); + goto err_exit; + } + data = ntfs_malloc(na->data_size); + if (!data) + goto out; + + size = ntfs_attr_pread(na, 0, na->data_size, data); + if (size != na->data_size) { + ntfs_log_perror("ntfs_attr_pread failed"); + free(data); + goto out; + } + ret = data; + if (data_size) + *data_size = size; +out: + ntfs_attr_close(na); +err_exit: + ntfs_log_leave("\n"); + return ret; +} + + + +int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, + u32 name_len) +{ + ntfs_attr_search_ctx *ctx; + int ret; + + ntfs_log_trace("Entering\n"); + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return 0; + + ret = ntfs_attr_lookup(type, name, name_len, CASE_SENSITIVE, 0, NULL, 0, + ctx); + + ntfs_attr_put_search_ctx(ctx); + + return !ret; +} + +int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, + u32 name_len) +{ + ntfs_attr *na; + int ret; + + ntfs_log_trace("Entering\n"); + + if (!ni) { + ntfs_log_error("%s: NULL inode pointer", __FUNCTION__); + errno = EINVAL; + return -1; + } + + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + /* do not log removal of non-existent stream */ + if (type != AT_DATA) { + ntfs_log_perror("Failed to open attribute 0x%02x of inode " + "0x%llx", type, (unsigned long long)ni->mft_no); + } + return -1; + } + + ret = ntfs_attr_rm(na); + if (ret) + ntfs_log_perror("Failed to remove attribute 0x%02x of inode " + "0x%llx", type, (unsigned long long)ni->mft_no); + ntfs_attr_close(na); + + return ret; +} + +/* Below macros are 32-bit ready. */ +#define BCX(x) ((x) - (((x) >> 1) & 0x77777777) - \ + (((x) >> 2) & 0x33333333) - \ + (((x) >> 3) & 0x11111111)) +#define BITCOUNT(x) (((BCX(x) + (BCX(x) >> 4)) & 0x0F0F0F0F) % 255) + +static u8 *ntfs_init_lut256(void) +{ + int i; + u8 *lut; + + lut = ntfs_malloc(256); + if (lut) + for(i = 0; i < 256; i++) + *(lut + i) = 8 - BITCOUNT(i); + return lut; +} + +s64 ntfs_attr_get_free_bits(ntfs_attr *na) +{ + u8 *buf, *lut; + s64 br = 0; + s64 total = 0; + s64 nr_free = 0; + + lut = ntfs_init_lut256(); + if (!lut) + return -1; + + buf = ntfs_malloc(65536); + if (!buf) + goto out; + + while (1) { + u32 *p; + br = ntfs_attr_pread(na, total, 65536, buf); + if (br <= 0) + break; + total += br; + p = (u32 *)buf + br / 4 - 1; + for (; (u8 *)p >= buf; p--) { + nr_free += lut[ *p & 255] + + lut[(*p >> 8) & 255] + + lut[(*p >> 16) & 255] + + lut[(*p >> 24) ]; + } + switch (br % 4) { + case 3: nr_free += lut[*(buf + br - 3)]; + case 2: nr_free += lut[*(buf + br - 2)]; + case 1: nr_free += lut[*(buf + br - 1)]; + } + } + free(buf); +out: + free(lut); + if (!total || br < 0) + return -1; + return nr_free; +} + +#endif + diff --git a/libcustomntfs/attrlist.c b/libcustomntfs/attrlist.c new file mode 100644 index 00000000..9c62f316 --- /dev/null +++ b/libcustomntfs/attrlist.c @@ -0,0 +1,314 @@ +/** + * attrlist.c - Attribute list attribute handling code. Originated from the Linux-NTFS + * project. + * + * Copyright (c) 2004-2005 Anton Altaparmakov + * Copyright (c) 2004-2005 Yura Pakhuchiy + * Copyright (c) 2006 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "types.h" +#include "layout.h" +#include "attrib.h" +#include "attrlist.h" +#include "debug.h" +#include "unistr.h" +#include "logging.h" +#include "misc.h" + +/** + * ntfs_attrlist_need - check whether inode need attribute list + * @ni: opened ntfs inode for which perform check + * + * Check whether all are attributes belong to one MFT record, in that case + * attribute list is not needed. + * + * Return 1 if inode need attribute list, 0 if not, -1 on error with errno set + * to the error code. If function succeed errno set to 0. The following error + * codes are defined: + * EINVAL - Invalid arguments passed to function or attribute haven't got + * attribute list. + */ +int ntfs_attrlist_need(ntfs_inode *ni) +{ + ATTR_LIST_ENTRY *ale; + + if (!ni) { + ntfs_log_trace("Invalid arguments.\n"); + errno = EINVAL; + return -1; + } + + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); + + if (!NInoAttrList(ni)) { + ntfs_log_trace("Inode haven't got attribute list.\n"); + errno = EINVAL; + return -1; + } + + if (!ni->attr_list) { + ntfs_log_trace("Corrupt in-memory struct.\n"); + errno = EINVAL; + return -1; + } + + errno = 0; + ale = (ATTR_LIST_ENTRY *)ni->attr_list; + while ((u8*)ale < ni->attr_list + ni->attr_list_size) { + if (MREF_LE(ale->mft_reference) != ni->mft_no) + return 1; + ale = (ATTR_LIST_ENTRY *)((u8*)ale + le16_to_cpu(ale->length)); + } + return 0; +} + +/** + * ntfs_attrlist_entry_add - add an attribute list attribute entry + * @ni: opened ntfs inode, which contains that attribute + * @attr: attribute record to add to attribute list + * + * Return 0 on success and -1 on error with errno set to the error code. The + * following error codes are defined: + * EINVAL - Invalid arguments passed to function. + * ENOMEM - Not enough memory to allocate necessary buffers. + * EIO - I/O error occurred or damaged filesystem. + * EEXIST - Such attribute already present in attribute list. + */ +int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) +{ + ATTR_LIST_ENTRY *ale; + MFT_REF mref; + ntfs_attr *na = NULL; + ntfs_attr_search_ctx *ctx; + u8 *new_al; + int entry_len, entry_offset, err; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", + (long long) ni->mft_no, + (unsigned) le32_to_cpu(attr->type)); + + if (!ni || !attr) { + ntfs_log_trace("Invalid arguments.\n"); + errno = EINVAL; + return -1; + } + + mref = MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); + + if (ni->nr_extents == -1) + ni = ni->base_ni; + + if (!NInoAttrList(ni)) { + ntfs_log_trace("Attribute list isn't present.\n"); + errno = ENOENT; + return -1; + } + + /* Determine size and allocate memory for new attribute list. */ + entry_len = (sizeof(ATTR_LIST_ENTRY) + sizeof(ntfschar) * + attr->name_length + 7) & ~7; + new_al = ntfs_calloc(ni->attr_list_size + entry_len); + if (!new_al) + return -1; + + /* Find place for the new entry. */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) { + err = errno; + goto err_out; + } + if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*) + ((u8*)attr + le16_to_cpu(attr->name_offset)) : + AT_UNNAMED, attr->name_length, CASE_SENSITIVE, + (attr->non_resident) ? le64_to_cpu(attr->lowest_vcn) : + 0, (attr->non_resident) ? NULL : ((u8*)attr + + le16_to_cpu(attr->value_offset)), (attr->non_resident) ? + 0 : le32_to_cpu(attr->value_length), ctx)) { + /* Found some extent, check it to be before new extent. */ + if (ctx->al_entry->lowest_vcn == attr->lowest_vcn) { + err = EEXIST; + ntfs_log_trace("Such attribute already present in the " + "attribute list.\n"); + ntfs_attr_put_search_ctx(ctx); + goto err_out; + } + /* Add new entry after this extent. */ + ale = (ATTR_LIST_ENTRY*)((u8*)ctx->al_entry + + le16_to_cpu(ctx->al_entry->length)); + } else { + /* Check for real errors. */ + if (errno != ENOENT) { + err = errno; + ntfs_log_trace("Attribute lookup failed.\n"); + ntfs_attr_put_search_ctx(ctx); + goto err_out; + } + /* No previous extents found. */ + ale = ctx->al_entry; + } + /* Don't need it anymore, @ctx->al_entry points to @ni->attr_list. */ + ntfs_attr_put_search_ctx(ctx); + + /* Determine new entry offset. */ + entry_offset = ((u8 *)ale - ni->attr_list); + /* Set pointer to new entry. */ + ale = (ATTR_LIST_ENTRY *)(new_al + entry_offset); + /* Zero it to fix valgrind warning. */ + memset(ale, 0, entry_len); + /* Form new entry. */ + ale->type = attr->type; + ale->length = cpu_to_le16(entry_len); + ale->name_length = attr->name_length; + ale->name_offset = offsetof(ATTR_LIST_ENTRY, name); + if (attr->non_resident) + ale->lowest_vcn = attr->lowest_vcn; + else + ale->lowest_vcn = 0; + ale->mft_reference = mref; + ale->instance = attr->instance; + memcpy(ale->name, (u8 *)attr + le16_to_cpu(attr->name_offset), + attr->name_length * sizeof(ntfschar)); + + /* Resize $ATTRIBUTE_LIST to new length. */ + na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); + if (!na) { + err = errno; + ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n"); + goto err_out; + } + if (ntfs_attr_truncate(na, ni->attr_list_size + entry_len)) { + err = errno; + ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n"); + goto err_out; + } + + /* Copy entries from old attribute list to new. */ + memcpy(new_al, ni->attr_list, entry_offset); + memcpy(new_al + entry_offset + entry_len, ni->attr_list + + entry_offset, ni->attr_list_size - entry_offset); + + /* Set new runlist. */ + free(ni->attr_list); + ni->attr_list = new_al; + ni->attr_list_size = ni->attr_list_size + entry_len; + NInoAttrListSetDirty(ni); + /* Done! */ + ntfs_attr_close(na); + return 0; +err_out: + if (na) + ntfs_attr_close(na); + free(new_al); + errno = err; + return -1; +} + +/** + * ntfs_attrlist_entry_rm - remove an attribute list attribute entry + * @ctx: attribute search context describing the attribute list entry + * + * Remove the attribute list entry @ctx->al_entry from the attribute list. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) +{ + u8 *new_al; + int new_al_len; + ntfs_inode *base_ni; + ntfs_attr *na; + ATTR_LIST_ENTRY *ale; + int err; + + if (!ctx || !ctx->ntfs_ino || !ctx->al_entry) { + ntfs_log_trace("Invalid arguments.\n"); + errno = EINVAL; + return -1; + } + + if (ctx->base_ntfs_ino) + base_ni = ctx->base_ntfs_ino; + else + base_ni = ctx->ntfs_ino; + ale = ctx->al_entry; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld.\n", + (long long) ctx->ntfs_ino->mft_no, + (unsigned) le32_to_cpu(ctx->al_entry->type), + (long long) le64_to_cpu(ctx->al_entry->lowest_vcn)); + + if (!NInoAttrList(base_ni)) { + ntfs_log_trace("Attribute list isn't present.\n"); + errno = ENOENT; + return -1; + } + + /* Allocate memory for new attribute list. */ + new_al_len = base_ni->attr_list_size - le16_to_cpu(ale->length); + new_al = ntfs_calloc(new_al_len); + if (!new_al) + return -1; + + /* Reisze $ATTRIBUTE_LIST to new length. */ + na = ntfs_attr_open(base_ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); + if (!na) { + err = errno; + ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n"); + goto err_out; + } + if (ntfs_attr_truncate(na, new_al_len)) { + err = errno; + ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n"); + goto err_out; + } + + /* Copy entries from old attribute list to new. */ + memcpy(new_al, base_ni->attr_list, (u8*)ale - base_ni->attr_list); + memcpy(new_al + ((u8*)ale - base_ni->attr_list), (u8*)ale + le16_to_cpu( + ale->length), new_al_len - ((u8*)ale - base_ni->attr_list)); + + /* Set new runlist. */ + free(base_ni->attr_list); + base_ni->attr_list = new_al; + base_ni->attr_list_size = new_al_len; + NInoAttrListSetDirty(base_ni); + /* Done! */ + ntfs_attr_close(na); + return 0; +err_out: + if (na) + ntfs_attr_close(na); + free(new_al); + errno = err; + return -1; +} diff --git a/libcustomntfs/attrlist.h b/libcustomntfs/attrlist.h new file mode 100644 index 00000000..2952e48b --- /dev/null +++ b/libcustomntfs/attrlist.h @@ -0,0 +1,51 @@ +/* + * attrlist.h - Exports for attribute list attribute handling. + * Originated from Linux-NTFS project. + * + * Copyright (c) 2004 Anton Altaparmakov + * Copyright (c) 2004 Yura Pakhuchiy + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_ATTRLIST_H +#define _NTFS_ATTRLIST_H + +#include "attrib.h" + +extern int ntfs_attrlist_need(ntfs_inode *ni); + +extern int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr); +extern int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx); + +/** + * ntfs_attrlist_mark_dirty - set the attribute list dirty + * @ni: ntfs inode which base inode contain dirty attribute list + * + * Set the attribute list dirty so it is written out later (at the latest at + * ntfs_inode_close() time). + * + * This function cannot fail. + */ +static __inline__ void ntfs_attrlist_mark_dirty(ntfs_inode *ni) +{ + if (ni->nr_extents == -1) + NInoAttrListSetDirty(ni->base_ni); + else + NInoAttrListSetDirty(ni); +} + +#endif /* defined _NTFS_ATTRLIST_H */ diff --git a/libcustomntfs/bit_ops.h b/libcustomntfs/bit_ops.h new file mode 100644 index 00000000..762be0b3 --- /dev/null +++ b/libcustomntfs/bit_ops.h @@ -0,0 +1,57 @@ +/* + bit_ops.h + Functions for dealing with conversion of data between types + + Copyright (c) 2006 Michael "Chishm" Chisholm + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _BIT_OPS_H +#define _BIT_OPS_H + +#include + +/*----------------------------------------------------------------- +Functions to deal with little endian values stored in uint8_t arrays +-----------------------------------------------------------------*/ +static inline uint16_t u8array_to_u16 (const uint8_t* item, int offset) { + return ( item[offset] | (item[offset + 1] << 8)); +} + +static inline uint32_t u8array_to_u32 (const uint8_t* item, int offset) { + return ( item[offset] | (item[offset + 1] << 8) | (item[offset + 2] << 16) | (item[offset + 3] << 24)); +} + +static inline void u16_to_u8array (uint8_t* item, int offset, uint16_t value) { + item[offset] = (uint8_t) value; + item[offset + 1] = (uint8_t)(value >> 8); +} + +static inline void u32_to_u8array (uint8_t* item, int offset, uint32_t value) { + item[offset] = (uint8_t) value; + item[offset + 1] = (uint8_t)(value >> 8); + item[offset + 2] = (uint8_t)(value >> 16); + item[offset + 3] = (uint8_t)(value >> 24); +} + +#endif // _BIT_OPS_H diff --git a/libcustomntfs/bitmap.c b/libcustomntfs/bitmap.c new file mode 100644 index 00000000..65162a29 --- /dev/null +++ b/libcustomntfs/bitmap.c @@ -0,0 +1,300 @@ +/** + * bitmap.c - Bitmap handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2006 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2004-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "types.h" +#include "attrib.h" +#include "bitmap.h" +#include "debug.h" +#include "logging.h" +#include "misc.h" + +/** + * ntfs_bit_set - set a bit in a field of bits + * @bitmap: field of bits + * @bit: bit to set + * @new_value: value to set bit to (0 or 1) + * + * Set the bit @bit in the @bitmap to @new_value. Ignore all errors. + */ +void ntfs_bit_set(u8 *bitmap, const u64 bit, const u8 new_value) +{ + if (!bitmap || new_value > 1) + return; + if (!new_value) + bitmap[bit >> 3] &= ~(1 << (bit & 7)); + else + bitmap[bit >> 3] |= (1 << (bit & 7)); +} + +/** + * ntfs_bit_get - get value of a bit in a field of bits + * @bitmap: field of bits + * @bit: bit to get + * + * Get and return the value of the bit @bit in @bitmap (0 or 1). + * Return -1 on error. + */ +char ntfs_bit_get(const u8 *bitmap, const u64 bit) +{ + if (!bitmap) + return -1; + return (bitmap[bit >> 3] >> (bit & 7)) & 1; +} + +/** + * ntfs_bit_get_and_set - get value of a bit in a field of bits and set it + * @bitmap: field of bits + * @bit: bit to get/set + * @new_value: value to set bit to (0 or 1) + * + * Return the value of the bit @bit and set it to @new_value (0 or 1). + * Return -1 on error. + */ +char ntfs_bit_get_and_set(u8 *bitmap, const u64 bit, const u8 new_value) +{ + register u8 old_bit, shift; + + if (!bitmap || new_value > 1) + return -1; + shift = bit & 7; + old_bit = (bitmap[bit >> 3] >> shift) & 1; + if (new_value != old_bit) + bitmap[bit >> 3] ^= 1 << shift; + return old_bit; +} + +/** + * ntfs_bitmap_set_bits_in_run - set a run of bits in a bitmap to a value + * @na: attribute containing the bitmap + * @start_bit: first bit to set + * @count: number of bits to set + * @value: value to set the bits to (i.e. 0 or 1) + * + * Set @count bits starting at bit @start_bit in the bitmap described by the + * attribute @na to @value, where @value is either 0 or 1. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +static int ntfs_bitmap_set_bits_in_run(ntfs_attr *na, s64 start_bit, + s64 count, int value) +{ + s64 bufsize, br; + u8 *buf, *lastbyte_buf; + int bit, firstbyte, lastbyte, lastbyte_pos, tmp, ret = -1; + + if (!na || start_bit < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("%s: Invalid argument (%p, %lld, %lld)", + __FUNCTION__, na, (long long)start_bit, (long long)count); + return -1; + } + + bit = start_bit & 7; + if (bit) + firstbyte = 1; + else + firstbyte = 0; + + /* Calculate the required buffer size in bytes, capping it at 8kiB. */ + bufsize = ((count - (bit ? 8 - bit : 0) + 7) >> 3) + firstbyte; + if (bufsize > 8192) + bufsize = 8192; + + buf = ntfs_malloc(bufsize); + if (!buf) + return -1; + + /* Depending on @value, zero or set all bits in the allocated buffer. */ + memset(buf, value ? 0xff : 0, bufsize); + + /* If there is a first partial byte... */ + if (bit) { + /* read it in... */ + br = ntfs_attr_pread(na, start_bit >> 3, 1, buf); + if (br != 1) { + if (br >= 0) + errno = EIO; + goto free_err_out; + } + /* and set or clear the appropriate bits in it. */ + while ((bit & 7) && count--) { + if (value) + *buf |= 1 << bit++; + else + *buf &= ~(1 << bit++); + } + /* Update @start_bit to the new position. */ + start_bit = (start_bit + 7) & ~7; + } + + /* Loop until @count reaches zero. */ + lastbyte = 0; + lastbyte_buf = NULL; + bit = count & 7; + do { + /* If there is a last partial byte... */ + if (count > 0 && bit) { + lastbyte_pos = ((count + 7) >> 3) + firstbyte; + if (!lastbyte_pos) { + // FIXME: Eeek! BUG! + ntfs_log_error("Lastbyte is zero. Leaving " + "inconsistent metadata.\n"); + errno = EIO; + goto free_err_out; + } + /* and it is in the currently loaded bitmap window... */ + if (lastbyte_pos <= bufsize) { + lastbyte_buf = buf + lastbyte_pos - 1; + + /* read the byte in... */ + br = ntfs_attr_pread(na, (start_bit + count) >> + 3, 1, lastbyte_buf); + if (br != 1) { + // FIXME: Eeek! We need rollback! (AIA) + if (br >= 0) + errno = EIO; + ntfs_log_perror("Reading of last byte " + "failed (%lld). Leaving inconsistent " + "metadata", (long long)br); + goto free_err_out; + } + /* and set/clear the appropriate bits in it. */ + while (bit && count--) { + if (value) + *lastbyte_buf |= 1 << --bit; + else + *lastbyte_buf &= ~(1 << --bit); + } + /* We don't want to come back here... */ + bit = 0; + /* We have a last byte that we have handled. */ + lastbyte = 1; + } + } + + /* Write the prepared buffer to disk. */ + tmp = (start_bit >> 3) - firstbyte; + br = ntfs_attr_pwrite(na, tmp, bufsize, buf); + if (br != bufsize) { + // FIXME: Eeek! We need rollback! (AIA) + if (br >= 0) + errno = EIO; + ntfs_log_perror("Failed to write buffer to bitmap " + "(%lld != %lld). Leaving inconsistent metadata", + (long long)br, (long long)bufsize); + goto free_err_out; + } + + /* Update counters. */ + tmp = (bufsize - firstbyte - lastbyte) << 3; + if (firstbyte) { + firstbyte = 0; + /* + * Re-set the partial first byte so a subsequent write + * of the buffer does not have stale, incorrect bits. + */ + *buf = value ? 0xff : 0; + } + start_bit += tmp; + count -= tmp; + if (bufsize > (tmp = (count + 7) >> 3)) + bufsize = tmp; + + if (lastbyte && count != 0) { + // FIXME: Eeek! BUG! + ntfs_log_error("Last buffer but count is not zero " + "(%lld). Leaving inconsistent metadata.\n", + (long long)count); + errno = EIO; + goto free_err_out; + } + } while (count > 0); + + ret = 0; + +free_err_out: + free(buf); + return ret; +} + +/** + * ntfs_bitmap_set_run - set a run of bits in a bitmap + * @na: attribute containing the bitmap + * @start_bit: first bit to set + * @count: number of bits to set + * + * Set @count bits starting at bit @start_bit in the bitmap described by the + * attribute @na. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +int ntfs_bitmap_set_run(ntfs_attr *na, s64 start_bit, s64 count) +{ + int ret; + + ntfs_log_enter("Set from bit %lld, count %lld\n", + (long long)start_bit, (long long)count); + ret = ntfs_bitmap_set_bits_in_run(na, start_bit, count, 1); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_bitmap_clear_run - clear a run of bits in a bitmap + * @na: attribute containing the bitmap + * @start_bit: first bit to clear + * @count: number of bits to clear + * + * Clear @count bits starting at bit @start_bit in the bitmap described by the + * attribute @na. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +int ntfs_bitmap_clear_run(ntfs_attr *na, s64 start_bit, s64 count) +{ + int ret; + + ntfs_log_enter("Clear from bit %lld, count %lld\n", + (long long)start_bit, (long long)count); + ret = ntfs_bitmap_set_bits_in_run(na, start_bit, count, 0); + ntfs_log_leave("\n"); + return ret; +} + diff --git a/libcustomntfs/bitmap.h b/libcustomntfs/bitmap.h new file mode 100644 index 00000000..10b5f6c5 --- /dev/null +++ b/libcustomntfs/bitmap.h @@ -0,0 +1,96 @@ +/* + * bitmap.h - Exports for bitmap handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_BITMAP_H +#define _NTFS_BITMAP_H + +#include "types.h" +#include "attrib.h" + +/* + * NOTES: + * + * - Operations are 8-bit only to ensure the functions work both on little + * and big endian machines! So don't make them 32-bit ops! + * - bitmap starts at bit = 0 and ends at bit = bitmap size - 1. + * - _Caller_ has to make sure that the bit to operate on is less than the + * size of the bitmap. + */ + +extern void ntfs_bit_set(u8 *bitmap, const u64 bit, const u8 new_value); +extern char ntfs_bit_get(const u8 *bitmap, const u64 bit); +extern char ntfs_bit_get_and_set(u8 *bitmap, const u64 bit, const u8 new_value); +extern int ntfs_bitmap_set_run(ntfs_attr *na, s64 start_bit, s64 count); +extern int ntfs_bitmap_clear_run(ntfs_attr *na, s64 start_bit, s64 count); + +/** + * ntfs_bitmap_set_bit - set a bit in a bitmap + * @na: attribute containing the bitmap + * @bit: bit to set + * + * Set the @bit in the bitmap described by the attribute @na. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +static __inline__ int ntfs_bitmap_set_bit(ntfs_attr *na, s64 bit) +{ + return ntfs_bitmap_set_run(na, bit, 1); +} + +/** + * ntfs_bitmap_clear_bit - clear a bit in a bitmap + * @na: attribute containing the bitmap + * @bit: bit to clear + * + * Clear @bit in the bitmap described by the attribute @na. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +static __inline__ int ntfs_bitmap_clear_bit(ntfs_attr *na, s64 bit) +{ + return ntfs_bitmap_clear_run(na, bit, 1); +} + +/* + * rol32 - rotate a 32-bit value left + * + * @word: value to rotate + * @shift: bits to roll + */ +static __inline__ u32 ntfs_rol32(u32 word, unsigned int shift) +{ + return (word << shift) | (word >> (32 - shift)); +} + +/* + * ror32 - rotate a 32-bit value right + * + * @word: value to rotate + * @shift: bits to roll + */ +static __inline__ u32 ntfs_ror32(u32 word, unsigned int shift) +{ + return (word >> shift) | (word << (32 - shift)); +} + +#endif /* defined _NTFS_BITMAP_H */ + diff --git a/libcustomntfs/bootsect.c b/libcustomntfs/bootsect.c new file mode 100644 index 00000000..e9bea370 --- /dev/null +++ b/libcustomntfs/bootsect.c @@ -0,0 +1,285 @@ +/** + * bootsect.c - Boot sector handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2006 Anton Altaparmakov + * Copyright (c) 2003-2008 Szabolcs Szakacsits + * Copyright (c) 2005 Yura Pakhuchiy + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "compat.h" +#include "bootsect.h" +#include "debug.h" +#include "logging.h" + +/** + * ntfs_boot_sector_is_ntfs - check if buffer contains a valid ntfs boot sector + * @b: buffer containing putative boot sector to analyze + * @silent: if zero, output progress messages to stderr + * + * Check if the buffer @b contains a valid ntfs boot sector. The buffer @b + * must be at least 512 bytes in size. + * + * If @silent is zero, output progress messages to stderr. Otherwise, do not + * output any messages (except when configured with --enable-debug in which + * case warning/debug messages may be displayed). + * + * Return TRUE if @b contains a valid ntfs boot sector and FALSE if not. + */ +BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) +{ + u32 i; + BOOL ret = FALSE; + + ntfs_log_debug("Beginning bootsector check.\n"); + + ntfs_log_debug("Checking OEMid, NTFS signature.\n"); + if (b->oem_id != cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ + ntfs_log_error("NTFS signature is missing.\n"); + goto not_ntfs; + } + + ntfs_log_debug("Checking bytes per sector.\n"); + if (le16_to_cpu(b->bpb.bytes_per_sector) < 256 || + le16_to_cpu(b->bpb.bytes_per_sector) > 4096) { + ntfs_log_error("Unexpected bytes per sector value (%d).\n", + le16_to_cpu(b->bpb.bytes_per_sector)); + goto not_ntfs; + } + + ntfs_log_debug("Checking sectors per cluster.\n"); + switch (b->bpb.sectors_per_cluster) { + case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: + break; + default: + ntfs_log_error("Unexpected sectors per cluster value (%d).\n", + b->bpb.sectors_per_cluster); + goto not_ntfs; + } + + ntfs_log_debug("Checking cluster size.\n"); + i = (u32)le16_to_cpu(b->bpb.bytes_per_sector) * + b->bpb.sectors_per_cluster; + if (i > 65536) { + ntfs_log_error("Unexpected cluster size (%d).\n", i); + goto not_ntfs; + } + + ntfs_log_debug("Checking reserved fields are zero.\n"); + if (le16_to_cpu(b->bpb.reserved_sectors) || + le16_to_cpu(b->bpb.root_entries) || + le16_to_cpu(b->bpb.sectors) || + le16_to_cpu(b->bpb.sectors_per_fat) || + le32_to_cpu(b->bpb.large_sectors) || + b->bpb.fats) { + ntfs_log_error("Reserved fields aren't zero " + "(%d, %d, %d, %d, %d, %d).\n", + le16_to_cpu(b->bpb.reserved_sectors), + le16_to_cpu(b->bpb.root_entries), + le16_to_cpu(b->bpb.sectors), + le16_to_cpu(b->bpb.sectors_per_fat), + le32_to_cpu(b->bpb.large_sectors), + b->bpb.fats); + goto not_ntfs; + } + + ntfs_log_debug("Checking clusters per mft record.\n"); + if ((u8)b->clusters_per_mft_record < 0xe1 || + (u8)b->clusters_per_mft_record > 0xf7) { + switch (b->clusters_per_mft_record) { + case 1: case 2: case 4: case 8: case 0x10: case 0x20: case 0x40: + break; + default: + ntfs_log_error("Unexpected clusters per mft record " + "(%d).\n", b->clusters_per_mft_record); + goto not_ntfs; + } + } + + ntfs_log_debug("Checking clusters per index block.\n"); + if ((u8)b->clusters_per_index_record < 0xe1 || + (u8)b->clusters_per_index_record > 0xf7) { + switch (b->clusters_per_index_record) { + case 1: case 2: case 4: case 8: case 0x10: case 0x20: case 0x40: + break; + default: + ntfs_log_error("Unexpected clusters per index record " + "(%d).\n", b->clusters_per_index_record); + goto not_ntfs; + } + } + + if (b->end_of_sector_marker != cpu_to_le16(0xaa55)) + ntfs_log_debug("Warning: Bootsector has invalid end of sector " + "marker.\n"); + + ntfs_log_debug("Bootsector check completed successfully.\n"); + + ret = TRUE; +not_ntfs: + return ret; +} + +static const char *last_sector_error = +"HINTS: Either the volume is a RAID/LDM but it wasn't setup yet,\n" +" or it was not setup correctly (e.g. by not using mdadm --build ...),\n" +" or a wrong device is tried to be mounted,\n" +" or the partition table is corrupt (partition is smaller than NTFS),\n" +" or the NTFS boot sector is corrupt (NTFS size is not valid).\n"; + +/** + * ntfs_boot_sector_parse - setup an ntfs volume from an ntfs boot sector + * @vol: ntfs_volume to setup + * @bs: buffer containing ntfs boot sector to parse + * + * Parse the ntfs bootsector @bs and setup the ntfs volume @vol with the + * obtained values. + * + * Return 0 on success or -1 on error with errno set to the error code EINVAL. + */ +int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs) +{ + s64 sectors; + u8 sectors_per_cluster; + s8 c; + + /* We return -1 with errno = EINVAL on error. */ + errno = EINVAL; + + vol->sector_size = le16_to_cpu(bs->bpb.bytes_per_sector); + vol->sector_size_bits = ffs(vol->sector_size) - 1; + ntfs_log_debug("SectorSize = 0x%x\n", vol->sector_size); + ntfs_log_debug("SectorSizeBits = %u\n", vol->sector_size_bits); + /* + * The bounds checks on mft_lcn and mft_mirr_lcn (i.e. them being + * below or equal the number_of_clusters) really belong in the + * ntfs_boot_sector_is_ntfs but in this way we can just do this once. + */ + sectors_per_cluster = bs->bpb.sectors_per_cluster; + ntfs_log_debug("SectorsPerCluster = 0x%x\n", sectors_per_cluster); + if (sectors_per_cluster & (sectors_per_cluster - 1)) { + ntfs_log_error("sectors_per_cluster (%d) is not a power of 2." + "\n", sectors_per_cluster); + return -1; + } + + sectors = sle64_to_cpu(bs->number_of_sectors); + ntfs_log_debug("NumberOfSectors = %lld\n", (long long)sectors); + if (!sectors) { + ntfs_log_error("Volume size is set to zero.\n"); + return -1; + } + if (vol->dev->d_ops->seek(vol->dev, + (sectors - 1) << vol->sector_size_bits, + SEEK_SET) == -1) { + ntfs_log_perror("Failed to read last sector (%lld)", + (long long)sectors); + ntfs_log_error("%s", last_sector_error); + return -1; + } + + vol->nr_clusters = sectors >> (ffs(sectors_per_cluster) - 1); + + vol->mft_lcn = sle64_to_cpu(bs->mft_lcn); + vol->mftmirr_lcn = sle64_to_cpu(bs->mftmirr_lcn); + ntfs_log_debug("MFT LCN = %lld\n", (long long)vol->mft_lcn); + ntfs_log_debug("MFTMirr LCN = %lld\n", (long long)vol->mftmirr_lcn); + if (vol->mft_lcn > vol->nr_clusters || + vol->mftmirr_lcn > vol->nr_clusters) { + ntfs_log_error("$MFT LCN (%lld) or $MFTMirr LCN (%lld) is " + "greater than the number of clusters (%lld).\n", + (long long)vol->mft_lcn, (long long)vol->mftmirr_lcn, + (long long)vol->nr_clusters); + return -1; + } + + vol->cluster_size = sectors_per_cluster * vol->sector_size; + if (vol->cluster_size & (vol->cluster_size - 1)) { + ntfs_log_error("cluster_size (%d) is not a power of 2.\n", + vol->cluster_size); + return -1; + } + vol->cluster_size_bits = ffs(vol->cluster_size) - 1; + /* + * Need to get the clusters per mft record and handle it if it is + * negative. Then calculate the mft_record_size. A value of 0x80 is + * illegal, thus signed char is actually ok! + */ + c = bs->clusters_per_mft_record; + ntfs_log_debug("ClusterSize = 0x%x\n", (unsigned)vol->cluster_size); + ntfs_log_debug("ClusterSizeBits = %u\n", vol->cluster_size_bits); + ntfs_log_debug("ClustersPerMftRecord = 0x%x\n", c); + /* + * When clusters_per_mft_record is negative, it means that it is to + * be taken to be the negative base 2 logarithm of the mft_record_size + * min bytes. Then: + * mft_record_size = 2^(-clusters_per_mft_record) bytes. + */ + if (c < 0) + vol->mft_record_size = 1 << -c; + else + vol->mft_record_size = c << vol->cluster_size_bits; + if (vol->mft_record_size & (vol->mft_record_size - 1)) { + ntfs_log_error("mft_record_size (%d) is not a power of 2.\n", + vol->mft_record_size); + return -1; + } + vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; + ntfs_log_debug("MftRecordSize = 0x%x\n", (unsigned)vol->mft_record_size); + ntfs_log_debug("MftRecordSizeBits = %u\n", vol->mft_record_size_bits); + /* Same as above for INDX record. */ + c = bs->clusters_per_index_record; + ntfs_log_debug("ClustersPerINDXRecord = 0x%x\n", c); + if (c < 0) + vol->indx_record_size = 1 << -c; + else + vol->indx_record_size = c << vol->cluster_size_bits; + vol->indx_record_size_bits = ffs(vol->indx_record_size) - 1; + ntfs_log_debug("INDXRecordSize = 0x%x\n", (unsigned)vol->indx_record_size); + ntfs_log_debug("INDXRecordSizeBits = %u\n", vol->indx_record_size_bits); + /* + * Work out the size of the MFT mirror in number of mft records. If the + * cluster size is less than or equal to the size taken by four mft + * records, the mft mirror stores the first four mft records. If the + * cluster size is bigger than the size taken by four mft records, the + * mft mirror contains as many mft records as will fit into one + * cluster. + */ + if (vol->cluster_size <= 4 * vol->mft_record_size) + vol->mftmirr_size = 4; + else + vol->mftmirr_size = vol->cluster_size / vol->mft_record_size; + return 0; +} + diff --git a/libcustomntfs/bootsect.h b/libcustomntfs/bootsect.h new file mode 100644 index 00000000..a299e821 --- /dev/null +++ b/libcustomntfs/bootsect.h @@ -0,0 +1,42 @@ +/* + * bootsect.h - Exports for bootsector record handling. + * Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2002 Anton Altaparmakov + * Copyright (c) 2006 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_BOOTSECT_H +#define _NTFS_BOOTSECT_H + +#include "types.h" +#include "volume.h" +#include "layout.h" + +/** + * ntfs_boot_sector_is_ntfs - check a boot sector for describing an ntfs volume + * @b: buffer containing the boot sector + * + * This function checks the boot sector in @b for describing a valid ntfs + * volume. Return TRUE if @b is a valid NTFS boot sector or FALSE otherwise. + */ +extern BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b); +extern int ntfs_boot_sector_parse(ntfs_volume *vol, const NTFS_BOOT_SECTOR *bs); + +#endif /* defined _NTFS_BOOTSECT_H */ + diff --git a/libcustomntfs/cache.c b/libcustomntfs/cache.c new file mode 100644 index 00000000..dd147672 --- /dev/null +++ b/libcustomntfs/cache.c @@ -0,0 +1,609 @@ +/** + * cache.c : deal with LRU caches + * + * Copyright (c) 2008-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "types.h" +#include "security.h" +#include "cache.h" +#include "misc.h" +#include "logging.h" + +/* + * General functions to deal with LRU caches + * + * The cached data have to be organized in a structure in which + * the first fields must follow a mandatory pattern and further + * fields may contain any fixed size data. They are stored in an + * LRU list. + * + * A compare function must be provided for finding a wanted entry + * in the cache. Another function may be provided for invalidating + * an entry to facilitate multiple invalidation. + * + * These functions never return error codes. When there is a + * shortage of memory, data is simply not cached. + * When there is a hashing bug, hashing is dropped, and sequential + * searches are used. + */ + +/* + * Enter a new hash index, after a new record has been inserted + * + * Do not call when a record has been modified (with no key change) + */ + +static void inserthashindex(struct CACHE_HEADER *cache, + struct CACHED_GENERIC *current) +{ + int h; + struct HASH_ENTRY *link; + struct HASH_ENTRY *first; + + if (cache->dohash) { + h = cache->dohash(current); + if ((h >= 0) && (h < cache->max_hash)) { + /* get a free link and insert at top of hash list */ + link = cache->free_hash; + if (link) { + cache->free_hash = link->next; + first = cache->first_hash[h]; + if (first) + link->next = first; + else + link->next = NULL; + link->entry = current; + cache->first_hash[h] = link; + } else { + ntfs_log_error("No more hash entries," + " cache %s hashing dropped\n", + cache->name); + cache->dohash = (cache_hash)NULL; + } + } else { + ntfs_log_error("Illegal hash value," + " cache %s hashing dropped\n", + cache->name); + cache->dohash = (cache_hash)NULL; + } + } +} + +/* + * Drop a hash index when a record is about to be deleted + */ + +static void drophashindex(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *current, int hash) +{ + struct HASH_ENTRY *link; + struct HASH_ENTRY *previous; + + if (cache->dohash) { + if ((hash >= 0) && (hash < cache->max_hash)) { + /* find the link and unlink */ + link = cache->first_hash[hash]; + previous = (struct HASH_ENTRY*)NULL; + while (link && (link->entry != current)) { + previous = link; + link = link->next; + } + if (link) { + if (previous) + previous->next = link->next; + else + cache->first_hash[hash] = link->next; + link->next = cache->free_hash; + cache->free_hash = link; + } else { + ntfs_log_error("Bad hash list," + " cache %s hashing dropped\n", + cache->name); + cache->dohash = (cache_hash)NULL; + } + } else { + ntfs_log_error("Illegal hash value," + " cache %s hashing dropped\n", + cache->name); + cache->dohash = (cache_hash)NULL; + } + } +} + +/* + * Fetch an entry from cache + * + * returns the cache entry, or NULL if not available + * The returned entry may be modified, but not freed + */ + +struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *wanted, cache_compare compare) +{ + struct CACHED_GENERIC *current; + struct CACHED_GENERIC *previous; + struct HASH_ENTRY *link; + int h; + + current = (struct CACHED_GENERIC*)NULL; + if (cache) { + if (cache->dohash) { + /* + * When possible, use the hash table to + * locate the entry if present + */ + h = cache->dohash(wanted); + link = cache->first_hash[h]; + while (link && compare(link->entry, wanted)) + link = link->next; + if (link) + current = link->entry; + } + if (!cache->dohash) { + /* + * Search sequentially in LRU list if no hash table + * or if hashing has just failed + */ + current = cache->most_recent_entry; + while (current + && compare(current, wanted)) { + current = current->next; + } + } + if (current) { + previous = current->previous; + cache->hits++; + if (previous) { + /* + * found and not at head of list, unlink from current + * position and relink as head of list + */ + previous->next = current->next; + if (current->next) + current->next->previous + = current->previous; + else + cache->oldest_entry + = current->previous; + current->next = cache->most_recent_entry; + current->previous + = (struct CACHED_GENERIC*)NULL; + cache->most_recent_entry->previous = current; + cache->most_recent_entry = current; + } + } + cache->reads++; + } + return (current); +} + +/* + * Enter an inode number into cache + * returns the cache entry or NULL if not possible + */ + +struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *item, + cache_compare compare) +{ + struct CACHED_GENERIC *current; + struct CACHED_GENERIC *before; + struct HASH_ENTRY *link; + int h; + + current = (struct CACHED_GENERIC*)NULL; + if (cache) { + if (cache->dohash) { + /* + * When possible, use the hash table to + * find out whether the entry if present + */ + h = cache->dohash(item); + link = cache->first_hash[h]; + while (link && compare(link->entry, item)) + link = link->next; + if (link) { + current = link->entry; + } + } + if (!cache->dohash) { + /* + * Search sequentially in LRU list to locate the end, + * and find out whether the entry is already in list + * As we normally go to the end, no statistics is + * kept. + */ + current = cache->most_recent_entry; + while (current + && compare(current, item)) { + current = current->next; + } + } + + if (!current) { + /* + * Not in list, get a free entry or reuse the + * last entry, and relink as head of list + * Note : we assume at least three entries, so + * before, previous and first are different when + * an entry is reused. + */ + + if (cache->free_entry) { + current = cache->free_entry; + cache->free_entry = cache->free_entry->next; + if (item->varsize) { + current->variable = ntfs_malloc( + item->varsize); + } else + current->variable = (void*)NULL; + current->varsize = item->varsize; + if (!cache->oldest_entry) + cache->oldest_entry = current; + } else { + /* reusing the oldest entry */ + current = cache->oldest_entry; + before = current->previous; + before->next = (struct CACHED_GENERIC*)NULL; + if (cache->dohash) + drophashindex(cache,current, + cache->dohash(current)); + if (cache->dofree) + cache->dofree(current); + cache->oldest_entry = current->previous; + if (item->varsize) { + if (current->varsize) + current->variable = realloc( + current->variable, + item->varsize); + else + current->variable = ntfs_malloc( + item->varsize); + } else { + if (current->varsize) + free(current->variable); + current->variable = (void*)NULL; + } + current->varsize = item->varsize; + } + current->next = cache->most_recent_entry; + current->previous = (struct CACHED_GENERIC*)NULL; + if (cache->most_recent_entry) + cache->most_recent_entry->previous = current; + cache->most_recent_entry = current; + memcpy(current->fixed, item->fixed, cache->fixed_size); + if (item->varsize) { + if (current->variable) { + memcpy(current->variable, + item->variable, item->varsize); + } else { + /* + * no more memory for variable part + * recycle entry in free list + * not an error, just uncacheable + */ + cache->most_recent_entry = current->next; + current->next = cache->free_entry; + cache->free_entry = current; + current = (struct CACHED_GENERIC*)NULL; + } + } else { + current->variable = (void*)NULL; + current->varsize = 0; + } + if (cache->dohash && current) + inserthashindex(cache,current); + } + cache->writes++; + } + return (current); +} + +/* + * Invalidate a cache entry + * The entry is moved to the free entry list + * A specific function may be called for entry deletion + */ + +static void do_invalidate(struct CACHE_HEADER *cache, + struct CACHED_GENERIC *current, int flags) +{ + struct CACHED_GENERIC *previous; + + previous = current->previous; + if ((flags & CACHE_FREE) && cache->dofree) + cache->dofree(current); + /* + * Relink into free list + */ + if (current->next) + current->next->previous = current->previous; + else + cache->oldest_entry = current->previous; + if (previous) + previous->next = current->next; + else + cache->most_recent_entry = current->next; + current->next = cache->free_entry; + cache->free_entry = current; + if (current->variable) + free(current->variable); + current->varsize = 0; + } + + +/* + * Invalidate entries in cache + * + * Several entries may have to be invalidated (at least for inodes + * associated to directories which have been renamed), a different + * compare function may be provided to select entries to invalidate + * + * Returns the number of deleted entries, this can be used by + * the caller to signal a cache corruption if the entry was + * supposed to be found. + */ + +int ntfs_invalidate_cache(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *item, cache_compare compare, + int flags) +{ + struct CACHED_GENERIC *current; + struct CACHED_GENERIC *previous; + struct CACHED_GENERIC *next; + struct HASH_ENTRY *link; + int count; + int h; + + current = (struct CACHED_GENERIC*)NULL; + count = 0; + if (cache) { + if (!(flags & CACHE_NOHASH) && cache->dohash) { + /* + * When possible, use the hash table to + * find out whether the entry if present + */ + h = cache->dohash(item); + link = cache->first_hash[h]; + while (link) { + if (compare(link->entry, item)) + link = link->next; + else { + current = link->entry; + link = link->next; + if (current) { + drophashindex(cache,current,h); + do_invalidate(cache, + current,flags); + count++; + } + } + } + } + if ((flags & CACHE_NOHASH) || !cache->dohash) { + /* + * Search sequentially in LRU list + */ + current = cache->most_recent_entry; + previous = (struct CACHED_GENERIC*)NULL; + while (current) { + if (!compare(current, item)) { + next = current->next; + if (cache->dohash) + drophashindex(cache,current, + cache->dohash(current)); + do_invalidate(cache,current,flags); + current = next; + count++; + } else { + previous = current; + current = current->next; + } + } + } + } + return (count); +} + +int ntfs_remove_cache(struct CACHE_HEADER *cache, + struct CACHED_GENERIC *item, int flags) +{ + int count; + + count = 0; + if (cache) { + if (cache->dohash) + drophashindex(cache,item,cache->dohash(item)); + do_invalidate(cache,item,flags); + count++; + } + return (count); +} + +/* + * Free memory allocated to a cache + */ + +static void ntfs_free_cache(struct CACHE_HEADER *cache) +{ + struct CACHED_GENERIC *entry; + + if (cache) { + for (entry=cache->most_recent_entry; entry; entry=entry->next) { + if (cache->dofree) + cache->dofree(entry); + if (entry->variable) + free(entry->variable); + } + free(cache); + } +} + +/* + * Create a cache + * + * Returns the cache header, or NULL if the cache could not be created + */ + +static struct CACHE_HEADER *ntfs_create_cache(const char *name, + cache_free dofree, cache_hash dohash, + int full_item_size, + int item_count, int max_hash) +{ + struct CACHE_HEADER *cache; + struct CACHED_GENERIC *pc; + struct CACHED_GENERIC *qc; + struct HASH_ENTRY *ph; + struct HASH_ENTRY *qh; + struct HASH_ENTRY **px; + size_t size; + int i; + + size = sizeof(struct CACHE_HEADER) + item_count*full_item_size; + if (max_hash) + size += item_count*sizeof(struct HASH_ENTRY) + + max_hash*sizeof(struct HASH_ENTRY*); + cache = (struct CACHE_HEADER*)ntfs_malloc(size); + if (cache) { + /* header */ + cache->name = name; + cache->dofree = dofree; + if (dohash && max_hash) { + cache->dohash = dohash; + cache->max_hash = max_hash; + } else { + cache->dohash = (cache_hash)NULL; + cache->max_hash = 0; + } + cache->fixed_size = full_item_size - sizeof(struct CACHED_GENERIC); + cache->reads = 0; + cache->writes = 0; + cache->hits = 0; + /* chain the data entries, and mark an invalid entry */ + cache->most_recent_entry = (struct CACHED_GENERIC*)NULL; + cache->oldest_entry = (struct CACHED_GENERIC*)NULL; + cache->free_entry = &cache->entry[0]; + pc = &cache->entry[0]; + for (i=0; i<(item_count - 1); i++) { + qc = (struct CACHED_GENERIC*)((char*)pc + + full_item_size); + pc->next = qc; + pc->variable = (void*)NULL; + pc->varsize = 0; + pc = qc; + } + /* special for the last entry */ + pc->next = (struct CACHED_GENERIC*)NULL; + pc->variable = (void*)NULL; + pc->varsize = 0; + + if (max_hash) { + /* chain the hash entries */ + ph = (struct HASH_ENTRY*)(((char*)pc) + full_item_size); + cache->free_hash = ph; + for (i=0; i<(item_count - 1); i++) { + qh = &ph[1]; + ph->next = qh; + ph = qh; + } + /* special for the last entry */ + if (item_count) { + ph->next = (struct HASH_ENTRY*)NULL; + } + /* create and initialize the hash indexes */ + px = (struct HASH_ENTRY**)&ph[1]; + cache->first_hash = px; + for (i=0; ifree_hash = (struct HASH_ENTRY*)NULL; + cache->first_hash = (struct HASH_ENTRY**)NULL; + } + } + return (cache); +} + +/* + * Create all LRU caches + * + * No error return, if creation is not possible, cacheing will + * just be not available + */ + +void ntfs_create_lru_caches(ntfs_volume *vol) +{ +#if CACHE_INODE_SIZE + /* inode cache */ + vol->xinode_cache = ntfs_create_cache("inode",(cache_free)NULL, + ntfs_dir_inode_hash, sizeof(struct CACHED_INODE), + CACHE_INODE_SIZE, 2*CACHE_INODE_SIZE); +#endif +#if CACHE_NIDATA_SIZE + /* idata cache */ + vol->nidata_cache = ntfs_create_cache("nidata", + ntfs_inode_nidata_free, ntfs_inode_nidata_hash, + sizeof(struct CACHED_NIDATA), + CACHE_NIDATA_SIZE, 2*CACHE_NIDATA_SIZE); +#endif +#if CACHE_LOOKUP_SIZE + /* lookup cache */ + vol->lookup_cache = ntfs_create_cache("lookup", + (cache_free)NULL, ntfs_dir_lookup_hash, + sizeof(struct CACHED_LOOKUP), + CACHE_LOOKUP_SIZE, 2*CACHE_LOOKUP_SIZE); +#endif + vol->securid_cache = ntfs_create_cache("securid",(cache_free)NULL, + (cache_hash)NULL,sizeof(struct CACHED_SECURID), CACHE_SECURID_SIZE, 0); +#if CACHE_LEGACY_SIZE + vol->legacy_cache = ntfs_create_cache("legacy",(cache_free)NULL, + (cache_hash)NULL, sizeof(struct CACHED_PERMISSIONS_LEGACY), CACHE_LEGACY_SIZE, 0); +#endif +} + +/* + * Free all LRU caches + */ + +void ntfs_free_lru_caches(ntfs_volume *vol) +{ +#if CACHE_INODE_SIZE + ntfs_free_cache(vol->xinode_cache); +#endif +#if CACHE_NIDATA_SIZE + ntfs_free_cache(vol->nidata_cache); +#endif +#if CACHE_LOOKUP_SIZE + ntfs_free_cache(vol->lookup_cache); +#endif + ntfs_free_cache(vol->securid_cache); +#if CACHE_LEGACY_SIZE + ntfs_free_cache(vol->legacy_cache); +#endif +} diff --git a/libcustomntfs/cache.h b/libcustomntfs/cache.h new file mode 100644 index 00000000..67e4f9da --- /dev/null +++ b/libcustomntfs/cache.h @@ -0,0 +1,119 @@ +/* + * cache.h : deal with indexed LRU caches + * + * Copyright (c) 2008-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_CACHE_H_ +#define _NTFS_CACHE_H_ + +#include "volume.h" + +struct CACHED_GENERIC { + struct CACHED_GENERIC *next; + struct CACHED_GENERIC *previous; + void *variable; + size_t varsize; + union { + /* force alignment for pointers and u64 */ + u64 u64align; + void *ptralign; + } fixed[0]; +} ; + +struct CACHED_INODE { + struct CACHED_INODE *next; + struct CACHED_INODE *previous; + const char *pathname; + size_t varsize; + /* above fields must match "struct CACHED_GENERIC" */ + u64 inum; +} ; + +struct CACHED_NIDATA { + struct CACHED_NIDATA *next; + struct CACHED_NIDATA *previous; + const char *pathname; /* not used */ + size_t varsize; /* not used */ + /* above fields must match "struct CACHED_GENERIC" */ + u64 inum; + ntfs_inode *ni; +} ; + +struct CACHED_LOOKUP { + struct CACHED_LOOKUP *next; + struct CACHED_LOOKUP *previous; + const char *name; + size_t namesize; + /* above fields must match "struct CACHED_GENERIC" */ + u64 parent; + u64 inum; +} ; + +enum { + CACHE_FREE = 1, + CACHE_NOHASH = 2 +} ; + +typedef int (*cache_compare)(const struct CACHED_GENERIC *cached, + const struct CACHED_GENERIC *item); +typedef void (*cache_free)(const struct CACHED_GENERIC *cached); +typedef int (*cache_hash)(const struct CACHED_GENERIC *cached); + +struct HASH_ENTRY { + struct HASH_ENTRY *next; + struct CACHED_GENERIC *entry; +} ; + +struct CACHE_HEADER { + const char *name; + struct CACHED_GENERIC *most_recent_entry; + struct CACHED_GENERIC *oldest_entry; + struct CACHED_GENERIC *free_entry; + struct HASH_ENTRY *free_hash; + struct HASH_ENTRY **first_hash; + cache_free dofree; + cache_hash dohash; + unsigned long reads; + unsigned long writes; + unsigned long hits; + int fixed_size; + int max_hash; + struct CACHED_GENERIC entry[0]; +} ; + + /* cast to generic, avoiding gcc warnings */ +#define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr)) + +struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *wanted, + cache_compare compare); +struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *item, + cache_compare compare); +int ntfs_invalidate_cache(struct CACHE_HEADER *cache, + const struct CACHED_GENERIC *item, + cache_compare compare, int flags); +int ntfs_remove_cache(struct CACHE_HEADER *cache, + struct CACHED_GENERIC *item, int flags); + +void ntfs_create_lru_caches(ntfs_volume *vol); +void ntfs_free_lru_caches(ntfs_volume *vol); + +#endif /* _NTFS_CACHE_H_ */ + diff --git a/libcustomntfs/cache2.c b/libcustomntfs/cache2.c new file mode 100644 index 00000000..872f1a57 --- /dev/null +++ b/libcustomntfs/cache2.c @@ -0,0 +1,374 @@ +/* + cache.c + The cache is not visible to the user. It should be flushed + when any file is closed or changes are made to the filesystem. + + This cache implements a least-used-page replacement policy. This will + distribute sectors evenly over the pages, so if less than the maximum + pages are used at once, they should all eventually remain in the cache. + This also has the benefit of throwing out old sectors, so as not to keep + too many stale pages around. + + Copyright (c) 2006 Michael "Chishm" Chisholm + Copyright (c) 2009 shareese, rodries + Copyright (c) 2010 Dimok + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include + +#include "cache2.h" +#include "bit_ops.h" +#include "mem_allocate.h" + +#define CACHE_FREE UINT_MAX + +NTFS_CACHE* _NTFS_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition, sec_t sectorSize) { + NTFS_CACHE* cache; + unsigned int i; + NTFS_CACHE_ENTRY* cacheEntries; + + if(numberOfPages==0 || sectorsPerPage==0) return NULL; + + if (numberOfPages < 4) { + numberOfPages = 4; + } + + if (sectorsPerPage < 32) { + sectorsPerPage = 32; + } + + cache = (NTFS_CACHE*) ntfs_alloc (sizeof(NTFS_CACHE)); + if (cache == NULL) { + return NULL; + } + + cache->disc = discInterface; + cache->endOfPartition = endOfPartition; + cache->numberOfPages = numberOfPages; + cache->sectorsPerPage = sectorsPerPage; + cache->sectorSize = sectorSize; + + + cacheEntries = (NTFS_CACHE_ENTRY*) ntfs_alloc ( sizeof(NTFS_CACHE_ENTRY) * numberOfPages); + if (cacheEntries == NULL) { + ntfs_free (cache); + return NULL; + } + + for (i = 0; i < numberOfPages; i++) { + cacheEntries[i].sector = CACHE_FREE; + cacheEntries[i].count = 0; + cacheEntries[i].last_access = 0; + cacheEntries[i].dirty = false; + cacheEntries[i].cache = (uint8_t*) ntfs_align ( sectorsPerPage * cache->sectorSize ); + } + + cache->cacheEntries = cacheEntries; + + return cache; +} + +void _NTFS_cache_destructor (NTFS_CACHE* cache) { + unsigned int i; + + if(cache==NULL) return; + + // Clear out cache before destroying it + _NTFS_cache_flush(cache); + + // Free memory in reverse allocation order + for (i = 0; i < cache->numberOfPages; i++) { + ntfs_free (cache->cacheEntries[i].cache); + } + ntfs_free (cache->cacheEntries); + ntfs_free (cache); +} + +static u32 accessCounter = 0; + +static u32 accessTime(){ + accessCounter++; + return accessCounter; +} + +static NTFS_CACHE_ENTRY* _NTFS_cache_getPage(NTFS_CACHE *cache,sec_t sector) +{ + unsigned int i; + NTFS_CACHE_ENTRY* cacheEntries = cache->cacheEntries; + unsigned int numberOfPages = cache->numberOfPages; + unsigned int sectorsPerPage = cache->sectorsPerPage; + + bool foundFree = false; + unsigned int oldUsed = 0; + unsigned int oldAccess = UINT_MAX; + + for(i=0;i=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) { + cacheEntries[i].last_access = accessTime(); + return &(cacheEntries[i]); + } + + if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_accessdisc->writeSectors(cacheEntries[oldUsed].sector,cacheEntries[oldUsed].count,cacheEntries[oldUsed].cache)) return NULL; + cacheEntries[oldUsed].dirty = false; + } + sector = (sector/sectorsPerPage)*sectorsPerPage; // align base sector to page size + sec_t next_page = sector + sectorsPerPage; + if(next_page > cache->endOfPartition) next_page = cache->endOfPartition; + + if(!cache->disc->readSectors(sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL; + + cacheEntries[oldUsed].sector = sector; + cacheEntries[oldUsed].count = next_page-sector; + cacheEntries[oldUsed].last_access = accessTime(); + + return &(cacheEntries[oldUsed]); +} + +static NTFS_CACHE_ENTRY* _NTFS_cache_findPage(NTFS_CACHE *cache, sec_t sector, sec_t count) { + + unsigned int i; + NTFS_CACHE_ENTRY* cacheEntries = cache->cacheEntries; + unsigned int numberOfPages = cache->numberOfPages; + NTFS_CACHE_ENTRY *entry = NULL; + sec_t lowest = UINT_MAX; + + for(i=0;i cacheEntries[i].sector) { + intersect = sector - cacheEntries[i].sector < cacheEntries[i].count; + } else { + intersect = cacheEntries[i].sector - sector < count; + } + + if ( intersect && (cacheEntries[i].sector < lowest)) { + lowest = cacheEntries[i].sector; + entry = &cacheEntries[i]; + } + } + } + + return entry; +} + +bool _NTFS_cache_readSectors(NTFS_CACHE *cache,sec_t sector,sec_t numSectors,void *buffer) +{ + sec_t sec; + sec_t secs_to_read; + NTFS_CACHE_ENTRY *entry; + uint8_t *dest = buffer; + + while(numSectors>0) { + entry = _NTFS_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + secs_to_read = entry->count - sec; + if(secs_to_read>numSectors) secs_to_read = numSectors; + + memcpy(dest,entry->cache + (sec*cache->sectorSize),(secs_to_read*cache->sectorSize)); + + dest += (secs_to_read*cache->sectorSize); + sector += secs_to_read; + numSectors -= secs_to_read; + } + + return true; +} + +/* +Reads some data from a cache page, determined by the sector number +*/ + +bool _NTFS_cache_readPartialSector (NTFS_CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + NTFS_CACHE_ENTRY *entry; + + if (offset + size > cache->sectorSize) return false; + + entry = _NTFS_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memcpy(buffer,entry->cache + ((sec*cache->sectorSize) + offset),size); + + return true; +} + +bool _NTFS_cache_readLittleEndianValue (NTFS_CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes) { + uint8_t buf[4]; + if (!_NTFS_cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false; + + switch(num_bytes) { + case 1: *value = buf[0]; break; + case 2: *value = u8array_to_u16(buf,0); break; + case 4: *value = u8array_to_u32(buf,0); break; + default: return false; + } + return true; +} + +/* +Writes some data to a cache page, making sure it is loaded into memory first. +*/ + +bool _NTFS_cache_writePartialSector (NTFS_CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + NTFS_CACHE_ENTRY *entry; + + if (offset + size > cache->sectorSize) return false; + + entry = _NTFS_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memcpy(entry->cache + ((sec*cache->sectorSize) + offset),buffer,size); + + entry->dirty = true; + return true; +} + +bool _NTFS_cache_writeLittleEndianValue (NTFS_CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int size) { + uint8_t buf[4] = {0, 0, 0, 0}; + + switch(size) { + case 1: buf[0] = value; break; + case 2: u16_to_u8array(buf, 0, value); break; + case 4: u32_to_u8array(buf, 0, value); break; + default: return false; + } + + return _NTFS_cache_writePartialSector(cache, buf, sector, offset, size); +} + +/* +Writes some data to a cache page, zeroing out the page first +*/ + +bool _NTFS_cache_eraseWritePartialSector (NTFS_CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) +{ + sec_t sec; + NTFS_CACHE_ENTRY *entry; + + if (offset + size > cache->sectorSize) return false; + + entry = _NTFS_cache_getPage(cache,sector); + if(entry==NULL) return false; + + sec = sector - entry->sector; + memset(entry->cache + (sec*cache->sectorSize),0,cache->sectorSize); + memcpy(entry->cache + ((sec*cache->sectorSize) + offset),buffer,size); + + entry->dirty = true; + return true; +} + +bool _NTFS_cache_writeSectors (NTFS_CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer) +{ + sec_t sec; + sec_t secs_to_write; + NTFS_CACHE_ENTRY* entry; + const uint8_t *src = buffer; + + while(numSectors>0) + { + entry = _NTFS_cache_findPage(cache,sector,numSectors); + + if(entry!=NULL) { + + if ( entry->sector > sector) { + + secs_to_write = entry->sector - sector; + + cache->disc->writeSectors(sector,secs_to_write,src); + src += (secs_to_write*cache->sectorSize); + sector += secs_to_write; + numSectors -= secs_to_write; + } + + sec = sector - entry->sector; + secs_to_write = entry->count - sec; + + if(secs_to_write>numSectors) secs_to_write = numSectors; + + memcpy(entry->cache + (sec*cache->sectorSize),src,(secs_to_write*cache->sectorSize)); + + src += (secs_to_write*cache->sectorSize); + sector += secs_to_write; + numSectors -= secs_to_write; + + entry->dirty = true; + + } else { + cache->disc->writeSectors(sector,numSectors,src); + numSectors=0; + } + } + return true; +} + +/* +Flushes all dirty pages to disc, clearing the dirty flag. +*/ +bool _NTFS_cache_flush (NTFS_CACHE* cache) { + unsigned int i; + if(cache==NULL) return true; + + for (i = 0; i < cache->numberOfPages; i++) { + if (cache->cacheEntries[i].dirty) { + if (!cache->disc->writeSectors (cache->cacheEntries[i].sector, cache->cacheEntries[i].count, cache->cacheEntries[i].cache)) { + return false; + } + } + cache->cacheEntries[i].dirty = false; + } + + return true; +} + +void _NTFS_cache_invalidate (NTFS_CACHE* cache) { + unsigned int i; + if(cache==NULL) + return; + + _NTFS_cache_flush(cache); + for (i = 0; i < cache->numberOfPages; i++) { + cache->cacheEntries[i].sector = CACHE_FREE; + cache->cacheEntries[i].last_access = 0; + cache->cacheEntries[i].count = 0; + cache->cacheEntries[i].dirty = false; + } +} diff --git a/libcustomntfs/cache2.h b/libcustomntfs/cache2.h new file mode 100644 index 00000000..21daca7c --- /dev/null +++ b/libcustomntfs/cache2.h @@ -0,0 +1,135 @@ +/* + NTFS_CACHE.h + The NTFS_CACHE is not visible to the user. It should be flushed + when any file is closed or changes are made to the filesystem. + + This NTFS_CACHE implements a least-used-page replacement policy. This will + distribute sectors evenly over the pages, so if less than the maximum + pages are used at once, they should all eventually remain in the NTFS_CACHE. + This also has the benefit of throwing out old sectors, so as not to keep + too many stale pages around. + + Copyright (c) 2006 Michael "Chishm" Chisholm + Copyright (c) 2009 shareese, rodries + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef _CACHE2_H +#define _CACHE2_H + +//#include "common.h" +//#include "disc.h" + +#include +#include +#include +#include +#include + +typedef struct { + sec_t sector; + unsigned int count; + u64 last_access; + bool dirty; + u8* cache; +} NTFS_CACHE_ENTRY; + +typedef struct { + const DISC_INTERFACE* disc; + sec_t endOfPartition; + unsigned int numberOfPages; + unsigned int sectorsPerPage; + sec_t sectorSize; + NTFS_CACHE_ENTRY* cacheEntries; +} NTFS_CACHE; + +/* +Read data from a sector in the NTFS_CACHE +If the sector is not in the NTFS_CACHE, it will be swapped in +offset is the position to start reading from +size is the amount of data to read +Precondition: offset + size <= BYTES_PER_READ +*/ +//bool _NTFS_cache_readPartialSector (NTFS_CACHE* NTFS_CACHE, void* buffer, sec_t sector, unsigned int offset, size_t size); + +//bool _NTFS_cache_readLittleEndianValue (NTFS_CACHE* NTFS_CACHE, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes); + +/* +Write data to a sector in the NTFS_CACHE +If the sector is not in the NTFS_CACHE, it will be swapped in. +When the sector is swapped out, the data will be written to the disc +offset is the position to start writing to +size is the amount of data to write +Precondition: offset + size <= BYTES_PER_READ +*/ +//bool _NTFS_cache_writePartialSector (NTFS_CACHE* NTFS_CACHE, const void* buffer, sec_t sector, unsigned int offset, size_t size); + +//bool _NTFS_cache_writeLittleEndianValue (NTFS_CACHE* NTFS_CACHE, const uint32_t value, sec_t sector, unsigned int offset, int num_bytes); + +/* +Write data to a sector in the NTFS_CACHE, zeroing the sector first +If the sector is not in the NTFS_CACHE, it will be swapped in. +When the sector is swapped out, the data will be written to the disc +offset is the position to start writing to +size is the amount of data to write +Precondition: offset + size <= BYTES_PER_READ +*/ +//bool _NTFS_cache_eraseWritePartialSector (NTFS_CACHE* NTFS_CACHE, const void* buffer, sec_t sector, unsigned int offset, size_t size); + +/* +Read several sectors from the NTFS_CACHE +*/ +bool _NTFS_cache_readSectors (NTFS_CACHE* NTFS_CACHE, sec_t sector, sec_t numSectors, void* buffer); + +/* +Read a full sector from the NTFS_CACHE +*/ +//static inline bool _NTFS_cache_readSector (NTFS_CACHE* NTFS_CACHE, void* buffer, sec_t sector) { +// return _NTFS_cache_readPartialSector (NTFS_CACHE, buffer, sector, 0, BYTES_PER_READ); +//} + +/* +Write a full sector to the NTFS_CACHE +*/ +//static inline bool _NTFS_cache_writeSector (NTFS_CACHE* NTFS_CACHE, const void* buffer, sec_t sector) { +// return _NTFS_cache_writePartialSector (NTFS_CACHE, buffer, sector, 0, BYTES_PER_READ); +//} + +bool _NTFS_cache_writeSectors (NTFS_CACHE* NTFS_CACHE, sec_t sector, sec_t numSectors, const void* buffer); + +/* +Write any dirty sectors back to disc and clear out the contents of the NTFS_CACHE +*/ +bool _NTFS_cache_flush (NTFS_CACHE* NTFS_CACHE); + +/* +Clear out the contents of the NTFS_CACHE without writing any dirty sectors first +*/ +void _NTFS_cache_invalidate (NTFS_CACHE* NTFS_CACHE); + +NTFS_CACHE* _NTFS_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition, sec_t sectorSize); + +void _NTFS_cache_destructor (NTFS_CACHE* NTFS_CACHE); + +#endif // _CACHE_H + diff --git a/libcustomntfs/collate.c b/libcustomntfs/collate.c new file mode 100644 index 00000000..5f7a015a --- /dev/null +++ b/libcustomntfs/collate.c @@ -0,0 +1,271 @@ +/** + * collate.c - NTFS collation handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2004 Anton Altaparmakov + * Copyright (c) 2005 Yura Pakhuchiy + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "attrib.h" +#include "index.h" +#include "collate.h" +#include "debug.h" +#include "unistr.h" +#include "logging.h" + +/** + * ntfs_collate_binary - Which of two binary objects should be listed first + * @vol: unused + * @data1: + * @data1_len: + * @data2: + * @data2_len: + * + * Description... + * + * Returns: + */ +static int ntfs_collate_binary(ntfs_volume *vol __attribute__((unused)), + const void *data1, const int data1_len, + const void *data2, const int data2_len) +{ + int rc; + + ntfs_log_trace("Entering.\n"); + rc = memcmp(data1, data2, min(data1_len, data2_len)); + if (!rc && (data1_len != data2_len)) { + if (data1_len < data2_len) + rc = -1; + else + rc = 1; + } + ntfs_log_trace("Done, returning %i.\n", rc); + return rc; +} + +/** + * ntfs_collate_ntofs_ulong - Which of two long ints should be listed first + * @vol: unused + * @data1: + * @data1_len: + * @data2: + * @data2_len: + * + * Description... + * + * Returns: + */ +static int ntfs_collate_ntofs_ulong(ntfs_volume *vol __attribute__((unused)), + const void *data1, const int data1_len, + const void *data2, const int data2_len) +{ + int rc; + u32 d1, d2; + + ntfs_log_trace("Entering.\n"); + if (data1_len != data2_len || data1_len != 4) { + ntfs_log_error("data1_len or/and data2_len not equal to 4.\n"); + return NTFS_COLLATION_ERROR; + } + d1 = le32_to_cpup(data1); + d2 = le32_to_cpup(data2); + if (d1 < d2) + rc = -1; + else { + if (d1 == d2) + rc = 0; + else + rc = 1; + } + ntfs_log_trace("Done, returning %i.\n", rc); + return rc; +} + +/** + * ntfs_collate_ntofs_ulongs - Which of two le32 arrays should be listed first + * + * Returns: -1, 0 or 1 depending of how the arrays compare + */ + +static int ntfs_collate_ntofs_ulongs(ntfs_volume *vol __attribute__((unused)), + const void *data1, const int data1_len, + const void *data2, const int data2_len) +{ + int rc; + int len; + const le32 *p1, *p2; + u32 d1, d2; + + ntfs_log_trace("Entering.\n"); + if ((data1_len != data2_len) || (data1_len <= 0) || (data1_len & 3)) { + ntfs_log_error("data1_len or data2_len not valid\n"); + return NTFS_COLLATION_ERROR; + } + p1 = (const le32*)data1; + p2 = (const le32*)data2; + len = data1_len; + do { + d1 = le32_to_cpup(p1); + p1++; + d2 = le32_to_cpup(p2); + p2++; + } while ((d1 == d2) && ((len -= 4) > 0)); + if (d1 < d2) + rc = -1; + else { + if (d1 == d2) + rc = 0; + else + rc = 1; + } + ntfs_log_trace("Done, returning %i.\n", rc); + return rc; +} + +/** + * ntfs_collate_ntofs_security_hash - Which of two security descriptors + * should be listed first + * @vol: unused + * @data1: + * @data1_len: + * @data2: + * @data2_len: + * + * JPA compare two security hash keys made of two unsigned le32 + * + * Returns: -1, 0 or 1 depending of how the keys compare + */ +static int ntfs_collate_ntofs_security_hash(ntfs_volume *vol __attribute__((unused)), + const void *data1, const int data1_len, + const void *data2, const int data2_len) +{ + int rc; + u32 d1, d2; + const le32 *p1, *p2; + + ntfs_log_trace("Entering.\n"); + if (data1_len != data2_len || data1_len != 8) { + ntfs_log_error("data1_len or/and data2_len not equal to 8.\n"); + return NTFS_COLLATION_ERROR; + } + p1 = (const le32*)data1; + p2 = (const le32*)data2; + d1 = le32_to_cpup(p1); + d2 = le32_to_cpup(p2); + if (d1 < d2) + rc = -1; + else { + if (d1 > d2) + rc = 1; + else { + p1++; + p2++; + d1 = le32_to_cpup(p1); + d2 = le32_to_cpup(p2); + if (d1 < d2) + rc = -1; + else { + if (d1 > d2) + rc = 1; + else + rc = 0; + } + } + } + ntfs_log_trace("Done, returning %i.\n", rc); + return rc; +} + +/** + * ntfs_collate_file_name - Which of two filenames should be listed first + * @vol: + * @data1: + * @data1_len: unused + * @data2: + * @data2_len: unused + * + * Description... + * + * Returns: + */ +static int ntfs_collate_file_name(ntfs_volume *vol, + const void *data1, const int data1_len __attribute__((unused)), + const void *data2, const int data2_len __attribute__((unused))) +{ + const FILE_NAME_ATTR *file_name_attr1; + const FILE_NAME_ATTR *file_name_attr2; + int rc; + + ntfs_log_trace("Entering.\n"); + file_name_attr1 = (const FILE_NAME_ATTR*)data1; + file_name_attr2 = (const FILE_NAME_ATTR*)data2; + rc = ntfs_names_full_collate( + (ntfschar*)&file_name_attr1->file_name, + file_name_attr1->file_name_length, + (ntfschar*)&file_name_attr2->file_name, + file_name_attr2->file_name_length, + CASE_SENSITIVE, vol->upcase, vol->upcase_len); + ntfs_log_trace("Done, returning %i.\n", rc); + return rc; +} + +/* + * Get a pointer to appropriate collation function. + * + * Returns NULL if the needed function is not implemented + */ + +COLLATE ntfs_get_collate_function(COLLATION_RULES cr) +{ + COLLATE collate; + + switch (cr) { + case COLLATION_BINARY : + collate = ntfs_collate_binary; + break; + case COLLATION_FILE_NAME : + collate = ntfs_collate_file_name; + break; + case COLLATION_NTOFS_SECURITY_HASH : + collate = ntfs_collate_ntofs_security_hash; + break; + case COLLATION_NTOFS_ULONG : + collate = ntfs_collate_ntofs_ulong; + break; + case COLLATION_NTOFS_ULONGS : + collate = ntfs_collate_ntofs_ulongs; + break; + default : + errno = EOPNOTSUPP; + collate = (COLLATE)NULL; + break; + } + return (collate); +} diff --git a/libcustomntfs/collate.h b/libcustomntfs/collate.h new file mode 100644 index 00000000..fe383835 --- /dev/null +++ b/libcustomntfs/collate.h @@ -0,0 +1,34 @@ +/* + * collate.h - Defines for NTFS collation handling. Originated from the Linux-NTFS + * project. + * + * Copyright (c) 2004 Anton Altaparmakov + * Copyright (c) 2005 Yura Pakhuchiy + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_COLLATE_H +#define _NTFS_COLLATE_H + +#include "types.h" +#include "volume.h" + +#define NTFS_COLLATION_ERROR -2 + +extern COLLATE ntfs_get_collate_function(COLLATION_RULES); + +#endif /* _NTFS_COLLATE_H */ diff --git a/libcustomntfs/compat.c b/libcustomntfs/compat.c new file mode 100644 index 00000000..63114a48 --- /dev/null +++ b/libcustomntfs/compat.c @@ -0,0 +1,250 @@ +/** + * compat.c - Tweaks for Windows compatibility + * + * Copyright (c) 2002 Richard Russon + * Copyright (c) 2002-2004 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "compat.h" + +#ifndef HAVE_FFS +/** + * ffs - Find the first set bit in an int + * @x: + * + * Description... + * + * Returns: + */ +int ffs(int x) +{ + int r = 1; + + if (!x) + return 0; + if (!(x & 0xffff)) { + x >>= 16; + r += 16; + } + if (!(x & 0xff)) { + x >>= 8; + r += 8; + } + if (!(x & 0xf)) { + x >>= 4; + r += 4; + } + if (!(x & 3)) { + x >>= 2; + r += 2; + } + if (!(x & 1)) { + x >>= 1; + r += 1; + } + return r; +} +#endif /* HAVE_FFS */ + +#ifndef HAVE_DAEMON +/* ************************************************************ + * From: src.opensolaris.org + * src/lib/libresolv2/common/bsd/daemon.c + */ +/* + * Copyright (c) 1997-2000 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; +static const char rcsid[] = "$Id: compat.c,v 1.1.1.1.2.1 2008-08-16 15:17:44 jpandre Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +int daemon(int nochdir, int noclose) { + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) + (void)chdir("/"); + + if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { + (void)dup2(fd, 0); + (void)dup2(fd, 1); + (void)dup2(fd, 2); + if (fd > 2) + (void)close (fd); + } + return (0); +} +/* + * End: src/lib/libresolv2/common/bsd/daemon.c + *************************************************************/ +#endif /* HAVE_DAEMON */ + +#ifndef HAVE_STRSEP +/* ************************************************************ + * From: src.opensolaris.org + * src/lib/libresolv2/common/bsd/strsep.c + */ +/* + * Copyright (c) 1997, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char sccsid[] = "strsep.c 8.1 (Berkeley) 6/4/93"; +static const char rcsid[] = "$Id: compat.c,v 1.1.1.1.2.1 2008-08-16 15:17:44 jpandre Exp $"; +#endif /* LIBC_SCCS and not lint */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif + +/* + * Get next token from string *stringp, where tokens are possibly-empty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, strsep returns NULL. + */ +char *strsep(char **stringp, const char *delim) { + char *s; + const char *spanp; + int c, sc; + char *tok; + + if ((s = *stringp) == NULL) + return (NULL); + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return (tok); + } + } while (sc != 0); + } + /* NOTREACHED */ +} + +/* + * End: src/lib/libresolv2/common/bsd/strsep.c + *************************************************************/ +#endif /* HAVE_STRSEP */ + diff --git a/libcustomntfs/compat.h b/libcustomntfs/compat.h new file mode 100644 index 00000000..957752a0 --- /dev/null +++ b/libcustomntfs/compat.h @@ -0,0 +1,86 @@ +/* + * compat.h - Tweaks for Windows compatibility. + * + * Copyright (c) 2002 Richard Russon + * Copyright (c) 2002-2004 Anton Altaparmakov + * Copyright (c) 2008-2009 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_COMPAT_H +#define _NTFS_COMPAT_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef HAVE_FFS +extern int ffs(int i); +#endif /* HAVE_FFS */ + +#ifndef HAVE_DAEMON +extern int daemon(int nochdir, int noclose); +#endif /* HAVE_DAEMON */ + +#ifndef HAVE_STRSEP +extern char *strsep(char **stringp, const char *delim); +#endif /* HAVE_STRSEP */ + +#ifdef WINDOWS + +#define HAVE_STDIO_H /* mimic config.h */ +#define HAVE_STDARG_H + +#define atoll _atoi64 +#define fdatasync commit +#define __inline__ inline +#define __attribute__(X) /*nothing*/ + +#else /* !defined WINDOWS */ + +#ifndef O_BINARY +#define O_BINARY 0 /* unix is binary by default */ +#endif + +#ifdef GEKKO + +#include "mem_allocate.h" + +#define XATTR_CREATE 1 +#define XATTR_REPLACE 2 + +#define MINORBITS 20 +#define MINORMASK ((1U << MINORBITS) - 1) + +#define major(dev) ((unsigned int) ((dev) >> MINORBITS)) +#define minor(dev) ((unsigned int) ((dev) & MINORMASK)) +#define mkdev(ma,mi) (((ma) << MINORBITS) | (mi)) +#define random rand + +#endif /* defined GEKKO */ + +#endif /* defined WINDOWS */ + +#endif /* defined _NTFS_COMPAT_H */ + diff --git a/libcustomntfs/compress.c b/libcustomntfs/compress.c new file mode 100644 index 00000000..fbd30ba9 --- /dev/null +++ b/libcustomntfs/compress.c @@ -0,0 +1,1831 @@ +/** + * compress.c - Compressed attribute handling code. Originated from the Linux-NTFS + * project. + * + * Copyright (c) 2004-2005 Anton Altaparmakov + * Copyright (c) 2004-2006 Szabolcs Szakacsits + * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2009-2010 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A part of the compression algorithm is based on lzhuf.c whose header + * describes the roles of the original authors (with no apparent copyright + * notice, and according to http://home.earthlink.net/~neilbawd/pall.html + * this was put into public domain in 1988 by Haruhiko OKUMURA). + * + * LZHUF.C English version 1.0 + * Based on Japanese version 29-NOV-1988 + * LZSS coded by Haruhiko OKUMURA + * Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI + * Edited and translated to English by Kenji RIKITAKE + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "attrib.h" +#include "debug.h" +#include "volume.h" +#include "types.h" +#include "layout.h" +#include "runlist.h" +#include "compress.h" +#include "lcnalloc.h" +#include "logging.h" +#include "misc.h" + +/** + * enum ntfs_compression_constants - constants used in the compression code + */ +typedef enum { + /* Token types and access mask. */ + NTFS_SYMBOL_TOKEN = 0, + NTFS_PHRASE_TOKEN = 1, + NTFS_TOKEN_MASK = 1, + + /* Compression sub-block constants. */ + NTFS_SB_SIZE_MASK = 0x0fff, + NTFS_SB_SIZE = 0x1000, + NTFS_SB_IS_COMPRESSED = 0x8000, +} ntfs_compression_constants; + +#define THRESHOLD 3 /* minimal match length for compression */ +#define NIL NTFS_SB_SIZE /* End of tree's node */ + +struct COMPRESS_CONTEXT { + const unsigned char *inbuf; + unsigned int len; + unsigned int nbt; + int match_position; + unsigned int match_length; + u16 lson[NTFS_SB_SIZE + 1]; + u16 rson[NTFS_SB_SIZE + 257]; + u16 dad[NTFS_SB_SIZE + 1]; +} ; + +/* + * Initialize the match tree + */ + +static void ntfs_init_compress_tree(struct COMPRESS_CONTEXT *pctx) +{ + int i; + + for (i = NTFS_SB_SIZE + 1; i <= NTFS_SB_SIZE + 256; i++) + pctx->rson[i] = NIL; /* root */ + for (i = 0; i < NTFS_SB_SIZE; i++) + pctx->dad[i] = NIL; /* node */ +} + +/* + * Insert a new node into match tree for quickly locating + * further similar strings + */ + +static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx, + unsigned int r) +{ + unsigned int pp; + BOOL less; + BOOL done; + const unsigned char *key; + int c; + unsigned long mxi; + unsigned int mxl; + + mxl = (1 << (16 - pctx->nbt)) + 2; + less = FALSE; + done = FALSE; + key = &pctx->inbuf[r]; + pp = NTFS_SB_SIZE + 1 + key[0]; + pctx->rson[r] = pctx->lson[r] = NIL; + pctx->match_length = 0; + do { + if (!less) { + if (pctx->rson[pp] != NIL) + pp = pctx->rson[pp]; + else { + pctx->rson[pp] = r; + pctx->dad[r] = pp; + done = TRUE; + } + } else { + if (pctx->lson[pp] != NIL) + pp = pctx->lson[pp]; + else { + pctx->lson[pp] = r; + pctx->dad[r] = pp; + done = TRUE; + } + } + if (!done) { + register unsigned long i; + register const unsigned char *p1,*p2; + + i = 1; + mxi = NTFS_SB_SIZE - r; + if (mxi < 2) + less = FALSE; + else { + p1 = key; + p2 = &pctx->inbuf[pp]; + /* this loop has a significant impact on performances */ + do { + } while ((p1[i] == p2[i]) && (++i < mxi)); + less = (i < mxi) && (p1[i] < p2[i]); + } + if (i >= THRESHOLD) { + if (i > pctx->match_length) { + pctx->match_position = + r - pp + 2*NTFS_SB_SIZE - 1; + if ((pctx->match_length = i) > mxl) { + i = pctx->rson[pp]; + pctx->rson[r] = i; + pctx->dad[i] = r; + i = pctx->lson[pp]; + pctx->lson[r] = i; + pctx->dad[i] = r; + i = pctx->dad[pp]; + pctx->dad[r] = i; + if (pctx->rson[i] == pp) + pctx->rson[i] = r; + else + pctx->lson[i] = r; + /* remove pp */ + pctx->dad[pp] = NIL; + done = TRUE; + pctx->match_length = mxl; + } + } else + if ((i == pctx->match_length) + && ((c = (r - pp + 2*NTFS_SB_SIZE - 1)) + < pctx->match_position)) + pctx->match_position = c; + } + } + } while (!done); +} + +/* + * Search for the longest previous string matching the + * current one + * + * Returns the end of the longest current string which matched + * or zero if there was a bug + */ + +static unsigned int ntfs_nextmatch(struct COMPRESS_CONTEXT *pctx, + unsigned int rr, int dd) +{ + unsigned int bestlen = 0; + + do { + rr++; + if (pctx->match_length > 0) + pctx->match_length--; + if (!pctx->len) { + ntfs_log_error("compress bug : void run\n"); + goto bug; + } + if (--pctx->len) { + if (rr >= NTFS_SB_SIZE) { + ntfs_log_error("compress bug : buffer overflow\n"); + goto bug; + } + if (((rr + bestlen) < NTFS_SB_SIZE)) { + while ((unsigned int)(1 << pctx->nbt) + <= (rr - 1)) + pctx->nbt++; + ntfs_new_node(pctx,rr); + if (pctx->match_length > bestlen) + bestlen = pctx->match_length; + } else + if (dd > 0) { + rr += dd; + if ((int)pctx->match_length > dd) + pctx->match_length -= dd; + else + pctx->match_length = 0; + if ((int)pctx->len < dd) { + ntfs_log_error("compress bug : run overflows\n"); + goto bug; + } + pctx->len -= dd; + dd = 0; + } + } + } while (dd-- > 0); + return (rr); +bug : + return (0); +} + +/* + * Compress an input block + * + * Returns the size of the compressed block (including header) + * or zero if there was an error + */ + +static unsigned int ntfs_compress_block(const char *inbuf, + unsigned int size, char *outbuf) +{ + struct COMPRESS_CONTEXT *pctx; + char *ptag; + int dd; + unsigned int rr; + unsigned int last_match_length; + unsigned int q; + unsigned int xout; + unsigned int ntag; + + pctx = (struct COMPRESS_CONTEXT*)malloc(sizeof(struct COMPRESS_CONTEXT)); + if (pctx) { + pctx->inbuf = (const unsigned char*)inbuf; + ntfs_init_compress_tree(pctx); + xout = 2; + ntag = 0; + ptag = &outbuf[xout++]; + *ptag = 0; + rr = 0; + pctx->nbt = 4; + pctx->len = size; + pctx->match_length = 0; + ntfs_new_node(pctx,0); + do { + if (pctx->match_length > pctx->len) + pctx->match_length = pctx->len; + if (pctx->match_length < THRESHOLD) { + pctx->match_length = 1; + if (ntag >= 8) { + ntag = 0; + ptag = &outbuf[xout++]; + *ptag = 0; + } + outbuf[xout++] = inbuf[rr]; + ntag++; + } else { + while ((unsigned int)(1 << pctx->nbt) + <= (rr - 1)) + pctx->nbt++; + q = (pctx->match_position << (16 - pctx->nbt)) + + pctx->match_length - THRESHOLD; + if (ntag >= 8) { + ntag = 0; + ptag = &outbuf[xout++]; + *ptag = 0; + } + *ptag |= 1 << ntag++; + outbuf[xout++] = q & 255; + outbuf[xout++] = (q >> 8) & 255; + } + last_match_length = pctx->match_length; + dd = last_match_length; + if (dd-- > 0) { + rr = ntfs_nextmatch(pctx,rr,dd); + if (!rr) + goto bug; + } + /* + * stop if input is exhausted or output has exceeded + * the maximum size. Two extra bytes have to be + * reserved in output buffer, as 3 bytes may be + * output in a loop. + */ + } while ((pctx->len > 0) + && (rr < size) && (xout < (NTFS_SB_SIZE + 2))); + /* uncompressed must be full size, so accept if better */ + if (xout < (NTFS_SB_SIZE + 2)) { + outbuf[0] = (xout - 3) & 255; + outbuf[1] = 0xb0 + (((xout - 3) >> 8) & 15); + } else { + memcpy(&outbuf[2],inbuf,size); + if (size < NTFS_SB_SIZE) + memset(&outbuf[size+2],0,NTFS_SB_SIZE - size); + outbuf[0] = 0xff; + outbuf[1] = 0x3f; + xout = NTFS_SB_SIZE + 2; + } + free(pctx); + } else { + xout = 0; + errno = ENOMEM; + } + return (xout); /* 0 for an error, > size if cannot compress */ +bug : + return (0); +} + +/** + * ntfs_decompress - decompress a compression block into an array of pages + * @dest: buffer to which to write the decompressed data + * @dest_size: size of buffer @dest in bytes + * @cb_start: compression block to decompress + * @cb_size: size of compression block @cb_start in bytes + * + * This decompresses the compression block @cb_start into the destination + * buffer @dest. + * + * @cb_start is a pointer to the compression block which needs decompressing + * and @cb_size is the size of @cb_start in bytes (8-64kiB). + * + * Return 0 if success or -EOVERFLOW on error in the compressed stream. + */ +static int ntfs_decompress(u8 *dest, const u32 dest_size, + u8 *const cb_start, const u32 cb_size) +{ + /* + * Pointers into the compressed data, i.e. the compression block (cb), + * and the therein contained sub-blocks (sb). + */ + u8 *cb_end = cb_start + cb_size; /* End of cb. */ + u8 *cb = cb_start; /* Current position in cb. */ + u8 *cb_sb_start = cb; /* Beginning of the current sb in the cb. */ + u8 *cb_sb_end; /* End of current sb / beginning of next sb. */ + /* Variables for uncompressed data / destination. */ + u8 *dest_end = dest + dest_size; /* End of dest buffer. */ + u8 *dest_sb_start; /* Start of current sub-block in dest. */ + u8 *dest_sb_end; /* End of current sb in dest. */ + /* Variables for tag and token parsing. */ + u8 tag; /* Current tag. */ + int token; /* Loop counter for the eight tokens in tag. */ + + ntfs_log_trace("Entering, cb_size = 0x%x.\n", (unsigned)cb_size); +do_next_sb: + ntfs_log_debug("Beginning sub-block at offset = %d in the cb.\n", + (int)(cb - cb_start)); + /* + * Have we reached the end of the compression block or the end of the + * decompressed data? The latter can happen for example if the current + * position in the compression block is one byte before its end so the + * first two checks do not detect it. + */ + if (cb == cb_end || !le16_to_cpup((le16*)cb) || dest == dest_end) { + ntfs_log_debug("Completed. Returning success (0).\n"); + return 0; + } + /* Setup offset for the current sub-block destination. */ + dest_sb_start = dest; + dest_sb_end = dest + NTFS_SB_SIZE; + /* Check that we are still within allowed boundaries. */ + if (dest_sb_end > dest_end) + goto return_overflow; + /* Does the minimum size of a compressed sb overflow valid range? */ + if (cb + 6 > cb_end) + goto return_overflow; + /* Setup the current sub-block source pointers and validate range. */ + cb_sb_start = cb; + cb_sb_end = cb_sb_start + (le16_to_cpup((le16*)cb) & NTFS_SB_SIZE_MASK) + + 3; + if (cb_sb_end > cb_end) + goto return_overflow; + /* Now, we are ready to process the current sub-block (sb). */ + if (!(le16_to_cpup((le16*)cb) & NTFS_SB_IS_COMPRESSED)) { + ntfs_log_debug("Found uncompressed sub-block.\n"); + /* This sb is not compressed, just copy it into destination. */ + /* Advance source position to first data byte. */ + cb += 2; + /* An uncompressed sb must be full size. */ + if (cb_sb_end - cb != NTFS_SB_SIZE) + goto return_overflow; + /* Copy the block and advance the source position. */ + memcpy(dest, cb, NTFS_SB_SIZE); + cb += NTFS_SB_SIZE; + /* Advance destination position to next sub-block. */ + dest += NTFS_SB_SIZE; + goto do_next_sb; + } + ntfs_log_debug("Found compressed sub-block.\n"); + /* This sb is compressed, decompress it into destination. */ + /* Forward to the first tag in the sub-block. */ + cb += 2; +do_next_tag: + if (cb == cb_sb_end) { + /* Check if the decompressed sub-block was not full-length. */ + if (dest < dest_sb_end) { + int nr_bytes = dest_sb_end - dest; + + ntfs_log_debug("Filling incomplete sub-block with zeroes.\n"); + /* Zero remainder and update destination position. */ + memset(dest, 0, nr_bytes); + dest += nr_bytes; + } + /* We have finished the current sub-block. */ + goto do_next_sb; + } + /* Check we are still in range. */ + if (cb > cb_sb_end || dest > dest_sb_end) + goto return_overflow; + /* Get the next tag and advance to first token. */ + tag = *cb++; + /* Parse the eight tokens described by the tag. */ + for (token = 0; token < 8; token++, tag >>= 1) { + u16 lg, pt, length, max_non_overlap; + register u16 i; + u8 *dest_back_addr; + + /* Check if we are done / still in range. */ + if (cb >= cb_sb_end || dest > dest_sb_end) + break; + /* Determine token type and parse appropriately.*/ + if ((tag & NTFS_TOKEN_MASK) == NTFS_SYMBOL_TOKEN) { + /* + * We have a symbol token, copy the symbol across, and + * advance the source and destination positions. + */ + *dest++ = *cb++; + /* Continue with the next token. */ + continue; + } + /* + * We have a phrase token. Make sure it is not the first tag in + * the sb as this is illegal and would confuse the code below. + */ + if (dest == dest_sb_start) + goto return_overflow; + /* + * Determine the number of bytes to go back (p) and the number + * of bytes to copy (l). We use an optimized algorithm in which + * we first calculate log2(current destination position in sb), + * which allows determination of l and p in O(1) rather than + * O(n). We just need an arch-optimized log2() function now. + */ + lg = 0; + for (i = dest - dest_sb_start - 1; i >= 0x10; i >>= 1) + lg++; + /* Get the phrase token into i. */ + pt = le16_to_cpup((le16*)cb); + /* + * Calculate starting position of the byte sequence in + * the destination using the fact that p = (pt >> (12 - lg)) + 1 + * and make sure we don't go too far back. + */ + dest_back_addr = dest - (pt >> (12 - lg)) - 1; + if (dest_back_addr < dest_sb_start) + goto return_overflow; + /* Now calculate the length of the byte sequence. */ + length = (pt & (0xfff >> lg)) + 3; + /* Verify destination is in range. */ + if (dest + length > dest_sb_end) + goto return_overflow; + /* The number of non-overlapping bytes. */ + max_non_overlap = dest - dest_back_addr; + if (length <= max_non_overlap) { + /* The byte sequence doesn't overlap, just copy it. */ + memcpy(dest, dest_back_addr, length); + /* Advance destination pointer. */ + dest += length; + } else { + /* + * The byte sequence does overlap, copy non-overlapping + * part and then do a slow byte by byte copy for the + * overlapping part. Also, advance the destination + * pointer. + */ + memcpy(dest, dest_back_addr, max_non_overlap); + dest += max_non_overlap; + dest_back_addr += max_non_overlap; + length -= max_non_overlap; + while (length--) + *dest++ = *dest_back_addr++; + } + /* Advance source position and continue with the next token. */ + cb += 2; + } + /* No tokens left in the current tag. Continue with the next tag. */ + goto do_next_tag; +return_overflow: + errno = EOVERFLOW; + ntfs_log_perror("Failed to decompress file"); + return -1; +} + +/** + * ntfs_is_cb_compressed - internal function, do not use + * + * This is a very specialised function determining if a cb is compressed or + * uncompressed. It is assumed that checking for a sparse cb has already been + * performed and that the cb is not sparse. It makes all sorts of other + * assumptions as well and hence it is not useful anywhere other than where it + * is used at the moment. Please, do not make this function available for use + * outside of compress.c as it is bound to confuse people and not do what they + * want. + * + * Return TRUE on errors so that the error will be detected later on in the + * code. Might be a bit confusing to debug but there really should never be + * errors coming from here. + */ +static BOOL ntfs_is_cb_compressed(ntfs_attr *na, runlist_element *rl, + VCN cb_start_vcn, int cb_clusters) +{ + /* + * The simplest case: the run starting at @cb_start_vcn contains + * @cb_clusters clusters which are all not sparse, thus the cb is not + * compressed. + */ +restart: + cb_clusters -= rl->length - (cb_start_vcn - rl->vcn); + while (cb_clusters > 0) { + /* Go to the next run. */ + rl++; + /* Map the next runlist fragment if it is not mapped. */ + if (rl->lcn < LCN_HOLE || !rl->length) { + cb_start_vcn = rl->vcn; + rl = ntfs_attr_find_vcn(na, rl->vcn); + if (!rl || rl->lcn < LCN_HOLE || !rl->length) + return TRUE; + /* + * If the runs were merged need to deal with the + * resulting partial run so simply restart. + */ + if (rl->vcn < cb_start_vcn) + goto restart; + } + /* If the current run is sparse, the cb is compressed. */ + if (rl->lcn == LCN_HOLE) + return TRUE; + /* If the whole cb is not sparse, it is not compressed. */ + if (rl->length >= cb_clusters) + return FALSE; + cb_clusters -= rl->length; + }; + /* All cb_clusters were not sparse thus the cb is not compressed. */ + return FALSE; +} + +/** + * ntfs_compressed_attr_pread - read from a compressed attribute + * @na: ntfs attribute to read from + * @pos: byte position in the attribute to begin reading from + * @count: number of bytes to read + * @b: output data buffer + * + * NOTE: You probably want to be using attrib.c::ntfs_attr_pread() instead. + * + * This function will read @count bytes starting at offset @pos from the + * compressed ntfs attribute @na into the data buffer @b. + * + * On success, return the number of successfully read bytes. If this number + * is lower than @count this means that the read reached end of file or that + * an error was encountered during the read so that the read is partial. + * 0 means end of file or nothing was read (also return 0 when @count is 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of ntfs_pread(), or to EINVAL in case of invalid + * arguments. + */ +s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b) +{ + s64 br, to_read, ofs, total, total2; + u64 cb_size_mask; + VCN start_vcn, vcn, end_vcn; + ntfs_volume *vol; + runlist_element *rl; + u8 *dest, *cb, *cb_pos, *cb_end; + u32 cb_size; + int err; + ATTR_FLAGS data_flags; + FILE_ATTR_FLAGS compression; + unsigned int nr_cbs, cb_clusters; + + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count 0x%llx.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)pos, (long long)count); + data_flags = na->data_flags; + compression = na->ni->flags & FILE_ATTR_COMPRESSED; + if (!na || !na->ni || !na->ni->vol || !b + || ((data_flags & ATTR_COMPRESSION_MASK) + != ATTR_IS_COMPRESSED) + || pos < 0 || count < 0) { + errno = EINVAL; + return -1; + } + /* + * Encrypted attributes are not supported. We return access denied, + * which is what Windows NT4 does, too. + */ + if (NAttrEncrypted(na)) { + errno = EACCES; + return -1; + } + if (!count) + return 0; + /* Truncate reads beyond end of attribute. */ + if (pos + count > na->data_size) { + if (pos >= na->data_size) { + return 0; + } + count = na->data_size - pos; + } + /* If it is a resident attribute, simply use ntfs_attr_pread(). */ + if (!NAttrNonResident(na)) + return ntfs_attr_pread(na, pos, count, b); + total = total2 = 0; + /* Zero out reads beyond initialized size. */ + if (pos + count > na->initialized_size) { + if (pos >= na->initialized_size) { + memset(b, 0, count); + return count; + } + total2 = pos + count - na->initialized_size; + count -= total2; + memset((u8*)b + count, 0, total2); + } + vol = na->ni->vol; + cb_size = na->compression_block_size; + cb_size_mask = cb_size - 1UL; + cb_clusters = na->compression_block_clusters; + + /* Need a temporary buffer for each loaded compression block. */ + cb = (u8*)ntfs_malloc(cb_size); + if (!cb) + return -1; + + /* Need a temporary buffer for each uncompressed block. */ + dest = (u8*)ntfs_malloc(cb_size); + if (!dest) { + free(cb); + return -1; + } + /* + * The first vcn in the first compression block (cb) which we need to + * decompress. + */ + start_vcn = (pos & ~cb_size_mask) >> vol->cluster_size_bits; + /* Offset in the uncompressed cb at which to start reading data. */ + ofs = pos & cb_size_mask; + /* + * The first vcn in the cb after the last cb which we need to + * decompress. + */ + end_vcn = ((pos + count + cb_size - 1) & ~cb_size_mask) >> + vol->cluster_size_bits; + /* Number of compression blocks (cbs) in the wanted vcn range. */ + nr_cbs = (end_vcn - start_vcn) << vol->cluster_size_bits >> + na->compression_block_size_bits; + cb_end = cb + cb_size; +do_next_cb: + nr_cbs--; + cb_pos = cb; + vcn = start_vcn; + start_vcn += cb_clusters; + + /* Check whether the compression block is sparse. */ + rl = ntfs_attr_find_vcn(na, vcn); + if (!rl || rl->lcn < LCN_HOLE) { + free(cb); + free(dest); + if (total) + return total; + /* FIXME: Do we want EIO or the error code? (AIA) */ + errno = EIO; + return -1; + } + if (rl->lcn == LCN_HOLE) { + /* Sparse cb, zero out destination range overlapping the cb. */ + ntfs_log_debug("Found sparse compression block.\n"); + to_read = min(count, cb_size - ofs); + memset(b, 0, to_read); + ofs = 0; + total += to_read; + count -= to_read; + b = (u8*)b + to_read; + } else if (!ntfs_is_cb_compressed(na, rl, vcn, cb_clusters)) { + s64 tdata_size, tinitialized_size; + /* + * Uncompressed cb, read it straight into the destination range + * overlapping the cb. + */ + ntfs_log_debug("Found uncompressed compression block.\n"); + /* + * Read the uncompressed data into the destination buffer. + * NOTE: We cheat a little bit here by marking the attribute as + * not compressed in the ntfs_attr structure so that we can + * read the data by simply using ntfs_attr_pread(). (-8 + * NOTE: we have to modify data_size and initialized_size + * temporarily as well... + */ + to_read = min(count, cb_size - ofs); + ofs += vcn << vol->cluster_size_bits; + NAttrClearCompressed(na); + na->data_flags &= ~ATTR_COMPRESSION_MASK; + tdata_size = na->data_size; + tinitialized_size = na->initialized_size; + na->data_size = na->initialized_size = na->allocated_size; + do { + br = ntfs_attr_pread(na, ofs, to_read, b); + if (br <= 0) { + if (!br) { + ntfs_log_error("Failed to read an" + " uncompressed cluster," + " inode %lld offs 0x%llx\n", + (long long)na->ni->mft_no, + (long long)ofs); + errno = EIO; + } + err = errno; + na->data_size = tdata_size; + na->initialized_size = tinitialized_size; + na->ni->flags |= compression; + na->data_flags = data_flags; + free(cb); + free(dest); + if (total) + return total; + errno = err; + return br; + } + total += br; + count -= br; + b = (u8*)b + br; + to_read -= br; + ofs += br; + } while (to_read > 0); + na->data_size = tdata_size; + na->initialized_size = tinitialized_size; + na->ni->flags |= compression; + na->data_flags = data_flags; + ofs = 0; + } else { + s64 tdata_size, tinitialized_size; + + /* + * Compressed cb, decompress it into the temporary buffer, then + * copy the data to the destination range overlapping the cb. + */ + ntfs_log_debug("Found compressed compression block.\n"); + /* + * Read the compressed data into the temporary buffer. + * NOTE: We cheat a little bit here by marking the attribute as + * not compressed in the ntfs_attr structure so that we can + * read the raw, compressed data by simply using + * ntfs_attr_pread(). (-8 + * NOTE: We have to modify data_size and initialized_size + * temporarily as well... + */ + to_read = cb_size; + NAttrClearCompressed(na); + na->data_flags &= ~ATTR_COMPRESSION_MASK; + tdata_size = na->data_size; + tinitialized_size = na->initialized_size; + na->data_size = na->initialized_size = na->allocated_size; + do { + br = ntfs_attr_pread(na, + (vcn << vol->cluster_size_bits) + + (cb_pos - cb), to_read, cb_pos); + if (br <= 0) { + if (!br) { + ntfs_log_error("Failed to read a" + " compressed cluster, " + " inode %lld offs 0x%llx\n", + (long long)na->ni->mft_no, + (long long)(vcn << vol->cluster_size_bits)); + errno = EIO; + } + err = errno; + na->data_size = tdata_size; + na->initialized_size = tinitialized_size; + na->ni->flags |= compression; + na->data_flags = data_flags; + free(cb); + free(dest); + if (total) + return total; + errno = err; + return br; + } + cb_pos += br; + to_read -= br; + } while (to_read > 0); + na->data_size = tdata_size; + na->initialized_size = tinitialized_size; + na->ni->flags |= compression; + na->data_flags = data_flags; + /* Just a precaution. */ + if (cb_pos + 2 <= cb_end) + *(u16*)cb_pos = 0; + ntfs_log_debug("Successfully read the compression block.\n"); + if (ntfs_decompress(dest, cb_size, cb, cb_size) < 0) { + err = errno; + free(cb); + free(dest); + if (total) + return total; + errno = err; + return -1; + } + to_read = min(count, cb_size - ofs); + memcpy(b, dest + ofs, to_read); + total += to_read; + count -= to_read; + b = (u8*)b + to_read; + ofs = 0; + } + /* Do we have more work to do? */ + if (nr_cbs) + goto do_next_cb; + /* We no longer need the buffers. */ + free(cb); + free(dest); + /* Return number of bytes read. */ + return total + total2; +} + +/* + * Read data from a set of clusters + * + * Returns the amount of data read + */ + +static u32 read_clusters(ntfs_volume *vol, const runlist_element *rl, + s64 offs, u32 to_read, char *inbuf) +{ + u32 count; + int xgot; + u32 got; + s64 xpos; + BOOL first; + char *xinbuf; + const runlist_element *xrl; + + got = 0; + xrl = rl; + xinbuf = inbuf; + first = TRUE; + do { + count = xrl->length << vol->cluster_size_bits; + xpos = xrl->lcn << vol->cluster_size_bits; + if (first) { + count -= offs; + xpos += offs; + } + if ((to_read - got) < count) + count = to_read - got; + xgot = ntfs_pread(vol->dev, xpos, count, xinbuf); + if (xgot == (int)count) { + got += count; + xpos += count; + xinbuf += count; + xrl++; + } + first = FALSE; + } while ((xgot == (int)count) && (got < to_read)); + return (got); +} + +/* + * Write data to a set of clusters + * + * Returns the amount of data written + */ + +static s32 write_clusters(ntfs_volume *vol, const runlist_element *rl, + s64 offs, s32 to_write, const char *outbuf) +{ + s32 count; + s32 put, xput; + s64 xpos; + BOOL first; + const char *xoutbuf; + const runlist_element *xrl; + + put = 0; + xrl = rl; + xoutbuf = outbuf; + first = TRUE; + do { + count = xrl->length << vol->cluster_size_bits; + xpos = xrl->lcn << vol->cluster_size_bits; + if (first) { + count -= offs; + xpos += offs; + } + if ((to_write - put) < count) + count = to_write - put; + xput = ntfs_pwrite(vol->dev, xpos, count, xoutbuf); + if (xput == count) { + put += count; + xpos += count; + xoutbuf += count; + xrl++; + } + first = FALSE; + } while ((xput == count) && (put < to_write)); + return (put); +} + + +/* + * Compress and write a set of blocks + * + * returns the size actually written (rounded to a full cluster) + * or 0 if all zeroes (nothing is written) + * or -1 if could not compress (nothing is written) + * or -2 if there were an irrecoverable error (errno set) + */ + +static s32 ntfs_comp_set(ntfs_attr *na, runlist_element *rl, + s64 offs, u32 insz, const char *inbuf) +{ + ntfs_volume *vol; + char *outbuf; + char *pbuf; + u32 compsz; + s32 written; + s32 rounded; + unsigned int clsz; + u32 p; + unsigned int sz; + unsigned int bsz; + BOOL fail; + BOOL allzeroes; + /* a single compressed zero */ + static char onezero[] = { 0x01, 0xb0, 0x00, 0x00 } ; + /* a couple of compressed zeroes */ + static char twozeroes[] = { 0x02, 0xb0, 0x00, 0x00, 0x00 } ; + /* more compressed zeroes, to be followed by some count */ + static char morezeroes[] = { 0x03, 0xb0, 0x02, 0x00 } ; + + vol = na->ni->vol; + written = -1; /* default return */ + clsz = 1 << vol->cluster_size_bits; + /* may need 2 extra bytes per block and 2 more bytes */ + outbuf = (char*)ntfs_malloc(na->compression_block_size + + 2*(na->compression_block_size/NTFS_SB_SIZE) + + 2); + if (outbuf) { + fail = FALSE; + compsz = 0; + allzeroes = TRUE; + for (p=0; (p na->compression_block_size)) + fail = TRUE; + else { + if (allzeroes) { + /* check whether this is all zeroes */ + switch (sz) { + case 4 : + allzeroes = !memcmp( + pbuf,onezero,4); + break; + case 5 : + allzeroes = !memcmp( + pbuf,twozeroes,5); + break; + case 6 : + allzeroes = !memcmp( + pbuf,morezeroes,4); + break; + default : + allzeroes = FALSE; + break; + } + } + compsz += sz; + } + } + if (!fail && !allzeroes) { + /* add a couple of null bytes, space has been checked */ + outbuf[compsz++] = 0; + outbuf[compsz++] = 0; + /* write a full cluster, to avoid partial reading */ + rounded = ((compsz - 1) | (clsz - 1)) + 1; + written = write_clusters(vol, rl, offs, rounded, outbuf); + if (written != rounded) { + /* + * TODO : previously written text has been + * spoilt, should return a specific error + */ + ntfs_log_error("error writing compressed data\n"); + errno = EIO; + written = -2; + } + } else + if (!fail) + written = 0; + free(outbuf); + } + return (written); +} + +/* + * Check the validity of a compressed runlist + * The check starts at the beginning of current run and ends + * at the end of runlist + * errno is set if the runlist is not valid + */ + +static BOOL valid_compressed_run(ntfs_attr *na, runlist_element *rl, + BOOL fullcheck, const char *text) +{ + runlist_element *xrl; + const char *err; + BOOL ok = TRUE; + + xrl = rl; + while (xrl->vcn & (na->compression_block_clusters - 1)) + xrl--; + err = (const char*)NULL; + while (xrl->length) { + if ((xrl->vcn + xrl->length) != xrl[1].vcn) + err = "Runs not adjacent"; + if (xrl->lcn == LCN_HOLE) { + if ((xrl->vcn + xrl->length) + & (na->compression_block_clusters - 1)) { + err = "Invalid hole"; + } + if (fullcheck && (xrl[1].lcn == LCN_HOLE)) { + err = "Adjacent holes"; + } + } + if (err) { + ntfs_log_error("%s at %s index %ld inode %lld\n", + err, text, (long)(xrl - na->rl), + (long long)na->ni->mft_no); + errno = EIO; + ok = FALSE; + err = (const char*)NULL; + } + xrl++; + } + return (ok); +} + +/* + * Free unneeded clusters after overwriting compressed data + * + * This generally requires one or two empty slots at the end of runlist, + * but we do not want to reallocate the runlist here because + * there are many pointers to it. + * So the empty slots have to be reserved beforehand + * + * Returns zero unless some error occurred (described by errno) + * + * +======= start of block =====+ + * 0 |A chunk may overflow | <-- rl usedcnt : A + B + * |A on previous block | then B + * |A | + * +-- end of allocated chunk --+ freelength : C + * |B | (incl overflow) + * +== end of compressed data ==+ + * |C | <-- freerl freecnt : C + D + * |C chunk may overflow | + * |C on next block | + * +-- end of allocated chunk --+ + * |D | + * |D chunk may overflow | + * 15 |D on next block | + * +======== end of block ======+ + * + */ + +static int ntfs_compress_overwr_free(ntfs_attr *na, runlist_element *rl, + s32 usedcnt, s32 freecnt, VCN *update_from) +{ + BOOL beginhole; + BOOL mergeholes; + s32 oldlength; + s32 freelength; + s64 freelcn; + s64 freevcn; + runlist_element *freerl; + ntfs_volume *vol; + s32 carry; + int res; + + vol = na->ni->vol; + res = 0; + freelcn = rl->lcn + usedcnt; + freevcn = rl->vcn + usedcnt; + freelength = rl->length - usedcnt; + beginhole = !usedcnt && !rl->vcn; + /* can merge with hole before ? */ + mergeholes = !usedcnt + && rl[0].vcn + && (rl[-1].lcn == LCN_HOLE); + /* truncate current run, carry to subsequent hole */ + carry = freelength; + oldlength = rl->length; + if (mergeholes) { + /* merging with a hole before */ + freerl = rl; + } else { + rl->length -= freelength; /* warning : can be zero */ + freerl = ++rl; + } + if (!mergeholes && (usedcnt || beginhole)) { + s32 freed; + runlist_element *frl; + runlist_element *erl; + int holes = 0; + BOOL threeparts; + + /* free the unneeded clusters from initial run, then freerl */ + threeparts = (freelength > freecnt); + freed = 0; + frl = freerl; + if (freelength) { + res = ntfs_cluster_free_basic(vol,freelcn, + (threeparts ? freecnt : freelength)); + if (!res) + freed += (threeparts ? freecnt : freelength); + if (!usedcnt) { + holes++; + freerl--; + freerl->length += (threeparts + ? freecnt : freelength); + if (freerl->vcn < *update_from) + *update_from = freerl->vcn; + } + } + while (!res && frl->length && (freed < freecnt)) { + if (frl->length <= (freecnt - freed)) { + res = ntfs_cluster_free_basic(vol, frl->lcn, + frl->length); + if (!res) { + freed += frl->length; + frl->lcn = LCN_HOLE; + frl->length += carry; + carry = 0; + holes++; + } + } else { + res = ntfs_cluster_free_basic(vol, frl->lcn, + freecnt - freed); + if (!res) { + frl->lcn += freecnt - freed; + frl->vcn += freecnt - freed; + frl->length -= freecnt - freed; + freed = freecnt; + } + } + frl++; + } + na->compressed_size -= freed << vol->cluster_size_bits; + switch (holes) { + case 0 : + /* there are no hole, must insert one */ + /* space for hole has been prereserved */ + if (freerl->lcn == LCN_HOLE) { + if (threeparts) { + erl = freerl; + while (erl->length) + erl++; + do { + erl[2] = *erl; + } while (erl-- != freerl); + + freerl[1].length = freelength - freecnt; + freerl->length = freecnt; + freerl[1].lcn = freelcn + freecnt; + freerl[1].vcn = freevcn + freecnt; + freerl[2].lcn = LCN_HOLE; + freerl[2].vcn = freerl[1].vcn + + freerl[1].length; + freerl->vcn = freevcn; + } else { + freerl->vcn = freevcn; + freerl->length += freelength; + } + } else { + erl = freerl; + while (erl->length) + erl++; + if (threeparts) { + do { + erl[2] = *erl; + } while (erl-- != freerl); + freerl[1].lcn = freelcn + freecnt; + freerl[1].vcn = freevcn + freecnt; + freerl[1].length = oldlength - usedcnt - freecnt; + } else { + do { + erl[1] = *erl; + } while (erl-- != freerl); + } + freerl->lcn = LCN_HOLE; + freerl->vcn = freevcn; + freerl->length = freecnt; + } + break; + case 1 : + /* there is a single hole, may have to merge */ + freerl->vcn = freevcn; + if (freerl[1].lcn == LCN_HOLE) { + freerl->length += freerl[1].length; + erl = freerl; + do { + erl++; + *erl = erl[1]; + } while (erl->length); + } + break; + default : + /* there were several holes, must merge them */ + freerl->lcn = LCN_HOLE; + freerl->vcn = freevcn; + freerl->length = freecnt; + if (freerl[holes].lcn == LCN_HOLE) { + freerl->length += freerl[holes].length; + holes++; + } + erl = freerl; + do { + erl++; + *erl = erl[holes - 1]; + } while (erl->length); + break; + } + } else { + s32 freed; + runlist_element *frl; + runlist_element *xrl; + + freed = 0; + frl = freerl--; + if (freerl->vcn < *update_from) + *update_from = freerl->vcn; + while (!res && frl->length && (freed < freecnt)) { + if (frl->length <= (freecnt - freed)) { + freerl->length += frl->length; + freed += frl->length; + res = ntfs_cluster_free_basic(vol, frl->lcn, + frl->length); + frl++; + } else { + freerl->length += freecnt - freed; + res = ntfs_cluster_free_basic(vol, frl->lcn, + freecnt - freed); + frl->lcn += freecnt - freed; + frl->vcn += freecnt - freed; + frl->length -= freecnt - freed; + freed = freecnt; + } + } + /* remove unneded runlist entries */ + xrl = freerl; + /* group with next run if also a hole */ + if (frl->length && (frl->lcn == LCN_HOLE)) { + xrl->length += frl->length; + frl++; + } + while (frl->length) { + *++xrl = *frl++; + } + *++xrl = *frl; /* terminator */ + na->compressed_size -= freed << vol->cluster_size_bits; + } + return (res); +} + + +/* + * Free unneeded clusters after compression + * + * This generally requires one or two empty slots at the end of runlist, + * but we do not want to reallocate the runlist here because + * there are many pointers to it. + * So the empty slots have to be reserved beforehand + * + * Returns zero unless some error occurred (described by errno) + */ + +static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl, + s64 used, s64 reserved, BOOL appending, + VCN *update_from) +{ + s32 freecnt; + s32 usedcnt; + int res; + s64 freelcn; + s64 freevcn; + s32 freelength; + BOOL mergeholes; + BOOL beginhole; + ntfs_volume *vol; + runlist_element *freerl; + + res = -1; /* default return */ + vol = na->ni->vol; + freecnt = (reserved - used) >> vol->cluster_size_bits; + usedcnt = (reserved >> vol->cluster_size_bits) - freecnt; + if (rl->vcn < *update_from) + *update_from = rl->vcn; + /* skip entries fully used, if any */ + while (rl->length && (rl->length < usedcnt)) { + usedcnt -= rl->length; /* must be > 0 */ + rl++; + } + if (rl->length) { + /* + * Splitting the current allocation block requires + * an extra runlist element to create the hole. + * The required entry has been prereserved when + * mapping the runlist. + */ + /* get the free part in initial run */ + freelcn = rl->lcn + usedcnt; + freevcn = rl->vcn + usedcnt; + /* new count of allocated clusters */ + if (!((freevcn + freecnt) + & (na->compression_block_clusters - 1))) { + if (!appending) + res = ntfs_compress_overwr_free(na,rl, + usedcnt,freecnt,update_from); + else { + freelength = rl->length - usedcnt; + beginhole = !usedcnt && !rl->vcn; + mergeholes = !usedcnt + && rl[0].vcn + && (rl[-1].lcn == LCN_HOLE); + if (mergeholes) { + s32 carry; + + /* shorten the runs which have free space */ + carry = freecnt; + freerl = rl; + while (freerl->length < carry) { + carry -= freerl->length; + freerl++; + } + freerl->length = carry; + freerl = rl; + } else { + rl->length = usedcnt; /* can be zero ? */ + freerl = ++rl; + } + if ((freelength > 0) + && !mergeholes + && (usedcnt || beginhole)) { + /* + * move the unused part to the end. Doing so, + * the vcn will be out of order. This does + * not harm, the vcn are meaningless now, and + * only the lcn are meaningful for freeing. + */ + /* locate current end */ + while (rl->length) + rl++; + /* new terminator relocated */ + rl[1].vcn = rl->vcn; + rl[1].lcn = LCN_ENOENT; + rl[1].length = 0; + /* hole, currently allocated */ + rl->vcn = freevcn; + rl->lcn = freelcn; + rl->length = freelength; + } else { + /* why is this different from the begin hole case ? */ + if ((freelength > 0) + && !mergeholes + && !usedcnt) { + freerl--; + freerl->length = freelength; + if (freerl->vcn < *update_from) + *update_from + = freerl->vcn; + } + } + /* free the hole */ + res = ntfs_cluster_free_from_rl(vol,freerl); + if (!res) { + na->compressed_size -= freecnt + << vol->cluster_size_bits; + if (mergeholes) { + /* merge with adjacent hole */ + freerl--; + freerl->length += freecnt; + } else { + if (beginhole) + freerl--; + /* mark hole as free */ + freerl->lcn = LCN_HOLE; + freerl->vcn = freevcn; + freerl->length = freecnt; + } + if (freerl->vcn < *update_from) + *update_from = freerl->vcn; + /* and set up the new end */ + freerl[1].lcn = LCN_ENOENT; + freerl[1].vcn = freevcn + freecnt; + freerl[1].length = 0; + } + } + } else { + ntfs_log_error("Bad end of a compression block set\n"); + errno = EIO; + } + } else { + ntfs_log_error("No cluster to free after compression\n"); + errno = EIO; + } + return (res); +} + +/* + * Read existing data, decompress and append buffer + * Do nothing if something fails + */ + +static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl, + s64 offs, u32 compsz, s32 pos, BOOL appending, + char *outbuf, s64 to_write, const void *b) +{ + int fail = 1; + char *compbuf; + u32 decompsz; + u32 got; + + if (compsz == na->compression_block_size) { + /* if the full block was requested, it was a hole */ + memset(outbuf,0,compsz); + memcpy(&outbuf[pos],b,to_write); + fail = 0; + } else { + compbuf = (char*)ntfs_malloc(compsz); + if (compbuf) { + /* must align to full block for decompression */ + if (appending) + decompsz = ((pos - 1) | (NTFS_SB_SIZE - 1)) + 1; + else + decompsz = na->compression_block_size; + got = read_clusters(na->ni->vol, rl, offs, + compsz, compbuf); + if ((got == compsz) + && !ntfs_decompress((u8*)outbuf,decompsz, + (u8*)compbuf,compsz)) { + memcpy(&outbuf[pos],b,to_write); + fail = 0; + } + free(compbuf); + } + } + return (fail); +} + +/* + * Flush a full compression block + * + * returns the size actually written (rounded to a full cluster) + * or 0 if could not compress (and written uncompressed) + * or -1 if there were an irrecoverable error (errno set) + */ + +static int ntfs_flush(ntfs_attr *na, runlist_element *rl, s64 offs, + const char *outbuf, s32 count, BOOL compress, + BOOL appending, VCN *update_from) +{ + int rounded; + int written; + int clsz; + + if (compress) { + written = ntfs_comp_set(na, rl, offs, count, outbuf); + if (written == -1) + compress = FALSE; + if ((written >= 0) + && ntfs_compress_free(na,rl,offs + written, + offs + na->compression_block_size, appending, + update_from)) + written = -1; + } else + written = 0; + if (!compress) { + clsz = 1 << na->ni->vol->cluster_size_bits; + rounded = ((count - 1) | (clsz - 1)) + 1; + written = write_clusters(na->ni->vol, rl, + offs, rounded, outbuf); + if (written != rounded) + written = -1; + } + return (written); +} + +/* + * Write some data to be compressed. + * Compression only occurs when a few clusters (usually 16) are + * full. When this occurs an extra runlist slot may be needed, so + * it has to be reserved beforehand. + * + * Returns the size of uncompressed data written, + * or negative if an error occurred. + * When the returned size is less than requested, new clusters have + * to be allocated before the function is called again. + */ + +s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos, + s64 offs, s64 to_write, s64 rounded, + const void *b, int compressed_part, + VCN *update_from) +{ + ntfs_volume *vol; + runlist_element *brl; /* entry containing the beginning of block */ + int compression_length; + s64 written; + s64 to_read; + s64 to_flush; + s64 roffs; + s64 got; + s64 start_vcn; + s64 nextblock; + s64 endwrite; + u32 compsz; + char *inbuf; + char *outbuf; + BOOL fail; + BOOL done; + BOOL compress; + BOOL appending; + + if (!valid_compressed_run(na,wrl,FALSE,"begin compressed write")) { + return (-1); + } + if ((*update_from < 0) + || (compressed_part < 0) + || (compressed_part > (int)na->compression_block_clusters)) { + ntfs_log_error("Bad update vcn or compressed_part %d for compressed write\n", + compressed_part); + errno = EIO; + return (-1); + } + /* make sure there are two unused entries in runlist */ + if (na->unused_runs < 2) { + ntfs_log_error("No unused runs for compressed write\n"); + errno = EIO; + return (-1); + } + if (wrl->vcn < *update_from) + *update_from = wrl->vcn; + written = -1; /* default return */ + vol = na->ni->vol; + compression_length = na->compression_block_clusters; + compress = FALSE; + done = FALSE; + /* + * Cannot accept writing beyond the current compression set + * because when compression occurs, clusters are freed + * and have to be reallocated. + * (cannot happen with standard fuse 4K buffers) + * Caller has to avoid this situation, or face consequences. + */ + nextblock = ((offs + (wrl->vcn << vol->cluster_size_bits)) + | (na->compression_block_size - 1)) + 1; + /* determine whether we are appending to file */ + endwrite = offs + to_write + (wrl->vcn << vol->cluster_size_bits); + appending = endwrite >= na->initialized_size; + if (endwrite >= nextblock) { + /* it is time to compress */ + compress = TRUE; + /* only process what we can */ + to_write = rounded = nextblock + - (offs + (wrl->vcn << vol->cluster_size_bits)); + } + start_vcn = 0; + fail = FALSE; + brl = wrl; + roffs = 0; + /* + * If we are about to compress or we need to decompress + * existing data, we have to process a full set of blocks. + * So relocate the parameters to the beginning of allocation + * containing the first byte of the set of blocks. + */ + if (compress || compressed_part) { + /* find the beginning of block */ + start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits)) + & -compression_length; + if (start_vcn < *update_from) + *update_from = start_vcn; + while (brl->vcn && (brl->vcn > start_vcn)) { + /* jumping back a hole means big trouble */ + if (brl->lcn == (LCN)LCN_HOLE) { + ntfs_log_error("jump back over a hole when appending\n"); + fail = TRUE; + errno = EIO; + } + brl--; + offs += brl->length << vol->cluster_size_bits; + } + roffs = (start_vcn - brl->vcn) << vol->cluster_size_bits; + } + if (compressed_part && !fail) { + /* + * The set of compression blocks contains compressed data + * (we are reopening an existing file to append to it) + * Decompress the data and append + */ + compsz = compressed_part << vol->cluster_size_bits; + outbuf = (char*)ntfs_malloc(na->compression_block_size); + if (outbuf) { + if (appending) { + to_read = offs - roffs; + to_flush = to_read + to_write; + } else { + to_read = na->data_size + - (brl->vcn << vol->cluster_size_bits); + if (to_read > na->compression_block_size) + to_read = na->compression_block_size; + to_flush = to_read; + } + if (!ntfs_read_append(na, brl, roffs, compsz, + (s32)(offs - roffs), appending, + outbuf, to_write, b)) { + written = ntfs_flush(na, brl, roffs, + outbuf, to_flush, compress, appending, + update_from); + if (written >= 0) { + written = to_write; + done = TRUE; + } + } + free(outbuf); + } + } else { + if (compress && !fail) { + /* + * we are filling up a block, read the full set + * of blocks and compress it + */ + inbuf = (char*)ntfs_malloc(na->compression_block_size); + if (inbuf) { + to_read = offs - roffs; + if (to_read) + got = read_clusters(vol, brl, roffs, + to_read, inbuf); + else + got = 0; + if (got == to_read) { + memcpy(&inbuf[to_read],b,to_write); + written = ntfs_comp_set(na, brl, roffs, + to_read + to_write, inbuf); + /* + * if compression was not successful, + * only write the part which was requested + */ + if ((written >= 0) + /* free the unused clusters */ + && !ntfs_compress_free(na,brl, + written + roffs, + na->compression_block_size + + roffs, + appending, update_from)) { + done = TRUE; + written = to_write; + } + } + free(inbuf); + } + } + if (!done) { + /* + * if the compression block is not full, or + * if compression failed for whatever reason, + * write uncompressed + */ + /* check we are not overflowing current allocation */ + if ((wpos + rounded) + > ((wrl->lcn + wrl->length) + << vol->cluster_size_bits)) { + ntfs_log_error("writing on unallocated clusters\n"); + errno = EIO; + } else { + written = ntfs_pwrite(vol->dev, wpos, + rounded, b); + if (written == rounded) + written = to_write; + } + } + } + if ((written >= 0) + && !valid_compressed_run(na,wrl,TRUE,"end compressed write")) + written = -1; + return (written); +} + +/* + * Close a file written compressed. + * This compresses the last partial compression block of the file. + * Two empty runlist slots have to be reserved beforehand. + * + * Returns zero if closing is successful. + */ + +int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs, + VCN *update_from) +{ + ntfs_volume *vol; + runlist_element *brl; /* entry containing the beginning of block */ + int compression_length; + s64 written; + s64 to_read; + s64 roffs; + s64 got; + s64 start_vcn; + char *inbuf; + BOOL fail; + BOOL done; + + if (na->unused_runs < 2) { + ntfs_log_error("No unused runs for compressed close\n"); + errno = EIO; + return (-1); + } + if (*update_from < 0) { + ntfs_log_error("Bad update vcn for compressed close\n"); + errno = EIO; + return (-1); + } + if (wrl->vcn < *update_from) + *update_from = wrl->vcn; + vol = na->ni->vol; + compression_length = na->compression_block_clusters; + done = FALSE; + /* + * There generally is an uncompressed block at end of file, + * read the full block and compress it + */ + inbuf = (char*)ntfs_malloc(na->compression_block_size); + if (inbuf) { + start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits)) + & -compression_length; + if (start_vcn < *update_from) + *update_from = start_vcn; + to_read = offs + ((wrl->vcn - start_vcn) + << vol->cluster_size_bits); + brl = wrl; + fail = FALSE; + while (brl->vcn && (brl->vcn > start_vcn)) { + if (brl->lcn == (LCN)LCN_HOLE) { + ntfs_log_error("jump back over a hole when closing\n"); + fail = TRUE; + errno = EIO; + } + brl--; + } + if (!fail) { + /* roffs can be an offset from another uncomp block */ + roffs = (start_vcn - brl->vcn) + << vol->cluster_size_bits; + if (to_read) { + got = read_clusters(vol, brl, roffs, to_read, + inbuf); + if (got == to_read) { + written = ntfs_comp_set(na, brl, roffs, + to_read, inbuf); + if ((written >= 0) + /* free the unused clusters */ + && !ntfs_compress_free(na,brl, + written + roffs, + na->compression_block_size + roffs, + TRUE, update_from)) { + done = TRUE; + } else + /* if compression failed, leave uncompressed */ + if (written == -1) + done = TRUE; + } + } else + done = TRUE; + free(inbuf); + } + } + if (done && !valid_compressed_run(na,wrl,TRUE,"end compressed close")) + done = FALSE; + return (!done); +} diff --git a/libcustomntfs/compress.h b/libcustomntfs/compress.h new file mode 100644 index 00000000..c2569321 --- /dev/null +++ b/libcustomntfs/compress.h @@ -0,0 +1,41 @@ +/* + * compress.h - Exports for compressed attribute handling. + * Originated from the Linux-NTFS project. + * + * Copyright (c) 2004 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_COMPRESS_H +#define _NTFS_COMPRESS_H + +#include "types.h" +#include "attrib.h" + +extern s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, + void *b); + +extern s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *brl, s64 wpos, + s64 offs, s64 to_write, s64 rounded, + const void *b, int compressed_part, + VCN *update_from); + +extern int ntfs_compressed_close(ntfs_attr *na, runlist_element *brl, + s64 offs, VCN *update_from); + +#endif /* defined _NTFS_COMPRESS_H */ + diff --git a/libcustomntfs/config.h b/libcustomntfs/config.h new file mode 100644 index 00000000..ba0168e1 --- /dev/null +++ b/libcustomntfs/config.h @@ -0,0 +1,374 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if debug should be enabled */ +#undef ENABLE_DEBUG + +/* Define to 1 if the nfconv patch should be enabled */ +#undef ENABLE_NFCONV + +/* Define to 1 if using internal fuse */ +#undef FUSE_INTERNAL + +/* Define to 1 if you have the `atexit' function. */ +#define HAVE_ATEXIT 1 + +/* Define to 1 if you have the `basename' function. */ +#undef HAVE_BASENAME + +/* Define to 1 if you have the header file. */ +#undef HAVE_BYTESWAP_H + +/* Define to 1 if you have the `clock_gettime' function. */ +#undef HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the header file. */ +#define HAVE_CTYPE_H 1 + +/* Define to 1 if you have the `daemon' function. */ +#undef HAVE_DAEMON + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +#undef HAVE_DOPRNT + +/* Define to 1 if you have the `dup2' function. */ +#undef HAVE_DUP2 + +/* Define to 1 if you have the header file. */ +#undef HAVE_ENDIAN_H + +/* Define to 1 if you have the header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the `fdatasync' function. */ +#undef HAVE_FDATASYNC + +/* Define to 1 if you have the header file. */ +#undef HAVE_FEATURES_H + +/* Define to 1 if you have the `ffs' function. */ +#define HAVE_FFS 1 + +/* Define to 1 if you have the `fork' function. */ +#define HAVE_FORK 1 + +/* Define to 1 if you have the `getmntent' function. */ +#undef HAVE_GETMNTENT + +/* Define to 1 if you have the header file. */ +#define HAVE_GETOPT_H 1 + +/* Define to 1 if you have the `getopt_long' function. */ +#define HAVE_GETOPT_LONG 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#undef HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the `hasmntopt' function. */ +#undef HAVE_HASMNTOPT + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIBGEN_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_LIBINTL_H + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_FD_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_HDREG_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_MAJOR_H + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MACHINE_ENDIAN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MATH_H 1 + +/* Define to 1 if mbrtowc and mbstate_t are properly declared. */ +#define HAVE_MBRTOWC 1 + +/* Define to 1 if you have the `mbsinit' function. */ +#define HAVE_MBSINIT 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `memset' function. */ +#define HAVE_MEMSET 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_MNTENT_H + +/* Define to 1 if you have the `realpath' function. */ +#undef HAVE_REALPATH + +/* Define to 1 if you have the `regcomp' function. */ +#undef HAVE_REGCOMP + +/* Define to 1 if you have the `setlocale' function. */ +#define HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `setxattr' function. */ +#undef HAVE_SETXATTR + +/* Define to 1 if `stat' has the bug that it succeeds when given the + zero-length file name argument. */ +#define HAVE_STAT_EMPTY_STRING_BUG 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDARG_H 1 + +/* Define to 1 if stdbool.h conforms to C99. */ +#define HAVE_STDBOOL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the `strchr' function. */ +#define HAVE_STRCHR 1 + +/* Define to 1 if you have the `strdup' function. */ +#define HAVE_STRDUP 1 + +/* Define to 1 if you have the `strerror' function. */ +#define HAVE_STRERROR 1 + +/* Define to 1 if you have the `strftime' function. */ +#define HAVE_STRFTIME 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strnlen' function. */ +#define HAVE_STRNLEN 1 + +/* Define to 1 if you have the `strsep' function. */ +#define HAVE_STRSEP 1 + +/* Define to 1 if you have the `strtol' function. */ +#define HAVE_STRTOL 1 + +/* Define to 1 if you have the `strtoul' function. */ +#define HAVE_STRTOUL 1 + +/* Define to 1 if `st_atim' is member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_ATIM + +/* Define to 1 if `st_atimensec' is member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_ATIMENSEC + +/* Define to 1 if `st_atimespec' is member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_ATIMESPEC + +/* Define to 1 if `st_blocks' is member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_BLOCKS + +/* Define to 1 if `st_rdev' is member of `struct stat'. */ +#undef HAVE_STRUCT_STAT_ST_RDEV + +/* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use + `HAVE_STRUCT_STAT_ST_BLOCKS' instead. */ +#undef HAVE_ST_BLOCKS + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSLOG_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_BYTEORDER_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_ENDIAN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_IOCTL_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_MKDEV_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_MOUNT_H + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STATVFS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_SYSMACROS_H + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_VFS_H + +/* Define to 1 if you have the header file. */ +#define HAVE_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `utime' function. */ +#undef HAVE_UTIME + +/* Define to 1 if you have the `utimensat' function. */ +#undef HAVE_UTIMENSAT + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if `utime(file, NULL)' sets file's timestamp to the present. */ +#undef HAVE_UTIME_NULL + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_WCHAR_H 1 + +/* Define to 1 if you have the header file. */ +#undef HAVE_WINDOWS_H + +/* Define to 1 if the system has the type `_Bool'. */ +#undef HAVE__BOOL + +/* Don't update /etc/mtab */ +#undef IGNORE_MTAB + +/* Define to 1 if `lstat' dereferences a symlink specified with a trailing + slash. */ +#undef LSTAT_FOLLOWS_SLASHED_SYMLINK + +/* Define to 1 if your C compiler doesn't accept -c and -o together. */ +#undef NO_MINUS_C_MINUS_O + +/* Don't use default IO ops */ +#undef NO_NTFS_DEVICE_DEFAULT_IO_OPS + +/* Name of package */ +#define PACKAGE "ntfs-3g" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "ntfs-3g-devel@lists.sf.net" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "ntfs-3g" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "ntfs-3g 2010.8.8" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "ntfs-3g" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "2010.8.8" + +/* POSIX ACL support */ +#undef POSIXACLS + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + +/* Version number of package */ +#define VERSION "2010.8.8" + +/* Define to 1 if this is a Windows OS */ +#undef WINDOWS + +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +#define WORDS_BIGENDIAN 1 + +/* Define to 1 if your processor stores words with the least significant byte + first (like Intel and VAX, unlike Motorola and SPARC). */ +#undef WORDS_LITTLEENDIAN + +/* Number of bits in a file offset, on hosts where this is settable. */ +#define _FILE_OFFSET_BITS 64 + +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif + +/* Define for large files, on AIX-style hosts. */ +#define _LARGE_FILES 1 + +/* Required define if using POSIX threads */ +#undef _REENTRANT + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +#define inline __inline__ +#endif + +/* Define to `long int' if does not define. */ +#undef off_t + +/* Define to `unsigned int' if does not define. */ +#undef size_t diff --git a/libcustomntfs/debug.c b/libcustomntfs/debug.c new file mode 100644 index 00000000..f1934833 --- /dev/null +++ b/libcustomntfs/debug.c @@ -0,0 +1,79 @@ +/** + * debug.c - Debugging output functions. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2004 Anton Altaparmakov + * Copyright (c) 2004-2006 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "types.h" +#include "runlist.h" +#include "debug.h" +#include "logging.h" + +#ifdef DEBUG +/** + * ntfs_debug_runlist_dump - Dump a runlist. + * @rl: + * + * Description... + * + * Returns: + */ +void ntfs_debug_runlist_dump(const runlist_element *rl) +{ + int i = 0; + const char *lcn_str[5] = { "LCN_HOLE ", "LCN_RL_NOT_MAPPED", + "LCN_ENOENT ", "LCN_EINVAL ", + "LCN_unknown " }; + + ntfs_log_debug("NTFS-fs DEBUG: Dumping runlist (values in hex):\n"); + if (!rl) { + ntfs_log_debug("Run list not present.\n"); + return; + } + ntfs_log_debug("VCN LCN Run length\n"); + do { + LCN lcn = (rl + i)->lcn; + + if (lcn < (LCN)0) { + int idx = -lcn - 1; + + if (idx > -LCN_EINVAL - 1) + idx = 4; + ntfs_log_debug("%-16lld %s %-16lld%s\n", + (long long)rl[i].vcn, lcn_str[idx], + (long long)rl[i].length, + rl[i].length ? "" : " (runlist end)"); + } else + ntfs_log_debug("%-16lld %-16lld %-16lld%s\n", + (long long)rl[i].vcn, (long long)rl[i].lcn, + (long long)rl[i].length, + rl[i].length ? "" : " (runlist end)"); + } while (rl[i++].length); +} + +#endif + diff --git a/libcustomntfs/debug.h b/libcustomntfs/debug.h new file mode 100644 index 00000000..cf39b625 --- /dev/null +++ b/libcustomntfs/debug.h @@ -0,0 +1,47 @@ +/* + * debug.h - Debugging output functions. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2004 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_DEBUG_H +#define _NTFS_DEBUG_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "logging.h" + +struct _runlist_element; + +#ifdef DEBUG +extern void ntfs_debug_runlist_dump(const struct _runlist_element *rl); +#else +static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl __attribute__((unused))) {} +#endif + +#define NTFS_BUG(msg) \ +{ \ + int ___i; \ + ntfs_log_critical("Bug in %s(): %s\n", __FUNCTION__, msg); \ + ntfs_log_debug("Forcing segmentation fault!"); \ + ___i = ((int*)NULL)[1]; \ +} + +#endif /* defined _NTFS_DEBUG_H */ diff --git a/libcustomntfs/device.c b/libcustomntfs/device.c new file mode 100644 index 00000000..c77d8f95 --- /dev/null +++ b/libcustomntfs/device.c @@ -0,0 +1,730 @@ +/** + * device.c - Low level device io functions. Originated from the Linux-NTFS project. + * + * Copyright (c) 2004-2006 Anton Altaparmakov + * Copyright (c) 2004-2006 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_LINUX_FD_H +#include +#endif +#ifdef HAVE_LINUX_HDREG_H +#include +#endif + +#include "types.h" +#include "mst.h" +#include "debug.h" +#include "device.h" +#include "logging.h" +#include "misc.h" + +#if defined(linux) && defined(_IO) && !defined(BLKGETSIZE) +#define BLKGETSIZE _IO(0x12,96) /* Get device size in 512-byte blocks. */ +#endif +#if defined(linux) && defined(_IOR) && !defined(BLKGETSIZE64) +#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* Get device size in bytes. */ +#endif +#if defined(linux) && !defined(HDIO_GETGEO) +#define HDIO_GETGEO 0x0301 /* Get device geometry. */ +#endif +#if defined(linux) && defined(_IO) && !defined(BLKSSZGET) +# define BLKSSZGET _IO(0x12,104) /* Get device sector size in bytes. */ +#endif +#if defined(linux) && defined(_IO) && !defined(BLKBSZSET) +# define BLKBSZSET _IOW(0x12,113,size_t) /* Set device block size in bytes. */ +#endif + +/** + * ntfs_device_alloc - allocate an ntfs device structure and pre-initialize it + * @name: name of the device (must be present) + * @state: initial device state (usually zero) + * @dops: ntfs device operations to use with the device (must be present) + * @priv_data: pointer to private data (optional) + * + * Allocate an ntfs device structure and pre-initialize it with the user- + * specified device operations @dops, device state @state, device name @name, + * and optional private data @priv_data. + * + * Note, @name is copied and can hence be freed after this functions returns. + * + * On success return a pointer to the allocated ntfs device structure and on + * error return NULL with errno set to the error code returned by ntfs_malloc(). + */ +struct ntfs_device *ntfs_device_alloc(const char *name, const long state, + struct ntfs_device_operations *dops, void *priv_data) +{ + struct ntfs_device *dev; + + if (!name) { + errno = EINVAL; + return NULL; + } + + dev = ntfs_malloc(sizeof(struct ntfs_device)); + if (dev) { + if (!(dev->d_name = strdup(name))) { + int eo = errno; + free(dev); + errno = eo; + return NULL; + } + dev->d_ops = dops; + dev->d_state = state; + dev->d_private = priv_data; + } + return dev; +} + +/** + * ntfs_device_free - free an ntfs device structure + * @dev: ntfs device structure to free + * + * Free the ntfs device structure @dev. + * + * Return 0 on success or -1 on error with errno set to the error code. The + * following error codes are defined: + * EINVAL Invalid pointer @dev. + * EBUSY Device is still open. Close it before freeing it! + */ +int ntfs_device_free(struct ntfs_device *dev) +{ + if (!dev) { + errno = EINVAL; + return -1; + } + if (NDevOpen(dev)) { + errno = EBUSY; + return -1; + } + free(dev->d_name); + free(dev); + return 0; +} + +/** + * ntfs_pread - positioned read from disk + * @dev: device to read from + * @pos: position in device to read from + * @count: number of bytes to read + * @b: output data buffer + * + * This function will read @count bytes from device @dev at position @pos into + * the data buffer @b. + * + * On success, return the number of successfully read bytes. If this number is + * lower than @count this means that we have either reached end of file or + * encountered an error during the read so that the read is partial. 0 means + * end of file or nothing to read (@count is 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of either seek, read, or set to EINVAL in case of + * invalid arguments. + */ +s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b) +{ + s64 br, total; + struct ntfs_device_operations *dops; + + ntfs_log_trace("pos %lld, count %lld\n",(long long)pos,(long long)count); + + if (!b || count < 0 || pos < 0) { + errno = EINVAL; + return -1; + } + if (!count) + return 0; + + dops = dev->d_ops; + + for (total = 0; count; count -= br, total += br) { + br = dops->pread(dev, (char*)b + total, count, pos + total); + /* If everything ok, continue. */ + if (br > 0) + continue; + /* If EOF or error return number of bytes read. */ + if (!br || total) + return total; + /* Nothing read and error, return error status. */ + return br; + } + /* Finally, return the number of bytes read. */ + return total; +} + +/** + * ntfs_pwrite - positioned write to disk + * @dev: device to write to + * @pos: position in file descriptor to write to + * @count: number of bytes to write + * @b: data buffer to write to disk + * + * This function will write @count bytes from data buffer @b to the device @dev + * at position @pos. + * + * On success, return the number of successfully written bytes. If this number + * is lower than @count this means that the write has been interrupted in + * flight or that an error was encountered during the write so that the write + * is partial. 0 means nothing was written (also return 0 when @count is 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of either seek, write, or set + * to EINVAL in case of invalid arguments. + */ +s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, + const void *b) +{ + s64 written, total, ret = -1; + struct ntfs_device_operations *dops; + + ntfs_log_trace("pos %lld, count %lld\n",(long long)pos,(long long)count); + + if (!b || count < 0 || pos < 0) { + errno = EINVAL; + goto out; + } + if (!count) + return 0; + if (NDevReadOnly(dev)) { + errno = EROFS; + goto out; + } + + dops = dev->d_ops; + + NDevSetDirty(dev); + for (total = 0; count; count -= written, total += written) { + written = dops->pwrite(dev, (const char*)b + total, count, + pos + total); + /* If everything ok, continue. */ + if (written > 0) + continue; + /* + * If nothing written or error return number of bytes written. + */ + if (!written || total) + break; + /* Nothing written and error, return error status. */ + total = written; + break; + } + ret = total; +out: + return ret; +} + +/** + * ntfs_mst_pread - multi sector transfer (mst) positioned read + * @dev: device to read from + * @pos: position in file descriptor to read from + * @count: number of blocks to read + * @bksize: size of each block that needs mst deprotecting + * @b: output data buffer + * + * Multi sector transfer (mst) positioned read. This function will read @count + * blocks of size @bksize bytes each from device @dev at position @pos into the + * the data buffer @b. + * + * On success, return the number of successfully read blocks. If this number is + * lower than @count this means that we have reached end of file, that the read + * was interrupted, or that an error was encountered during the read so that + * the read is partial. 0 means end of file or nothing was read (also return 0 + * when @count or @bksize are 0). + * + * On error and nothing was read, return -1 with errno set appropriately to the + * return code of either seek, read, or set to EINVAL in case of invalid + * arguments. + * + * NOTE: If an incomplete multi sector transfer has been detected the magic + * will have been changed to magic_BAAD but no error will be returned. Thus it + * is possible that we return count blocks as being read but that any number + * (between zero and count!) of these blocks is actually subject to a multi + * sector transfer error. This should be detected by the caller by checking for + * the magic being "BAAD". + */ +s64 ntfs_mst_pread(struct ntfs_device *dev, const s64 pos, s64 count, + const u32 bksize, void *b) +{ + s64 br, i; + + if (bksize & (bksize - 1) || bksize % NTFS_BLOCK_SIZE) { + errno = EINVAL; + return -1; + } + /* Do the read. */ + br = ntfs_pread(dev, pos, count * bksize, b); + if (br < 0) + return br; + /* + * Apply fixups to successfully read data, disregarding any errors + * returned from the MST fixup function. This is because we want to + * fixup everything possible and we rely on the fact that the "BAAD" + * magic will be detected later on. + */ + count = br / bksize; + for (i = 0; i < count; ++i) + ntfs_mst_post_read_fixup((NTFS_RECORD*) + ((u8*)b + i * bksize), bksize); + /* Finally, return the number of complete blocks read. */ + return count; +} + +/** + * ntfs_mst_pwrite - multi sector transfer (mst) positioned write + * @dev: device to write to + * @pos: position in file descriptor to write to + * @count: number of blocks to write + * @bksize: size of each block that needs mst protecting + * @b: data buffer to write to disk + * + * Multi sector transfer (mst) positioned write. This function will write + * @count blocks of size @bksize bytes each from data buffer @b to the device + * @dev at position @pos. + * + * On success, return the number of successfully written blocks. If this number + * is lower than @count this means that the write has been interrupted or that + * an error was encountered during the write so that the write is partial. 0 + * means nothing was written (also return 0 when @count or @bksize are 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of either seek, write, or set + * to EINVAL in case of invalid arguments. + * + * NOTE: We mst protect the data, write it, then mst deprotect it using a quick + * deprotect algorithm (no checking). This saves us from making a copy before + * the write and at the same time causes the usn to be incremented in the + * buffer. This conceptually fits in better with the idea that cached data is + * always deprotected and protection is performed when the data is actually + * going to hit the disk and the cache is immediately deprotected again + * simulating an mst read on the written data. This way cache coherency is + * achieved. + */ +s64 ntfs_mst_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, + const u32 bksize, void *b) +{ + s64 written, i; + + if (count < 0 || bksize % NTFS_BLOCK_SIZE) { + errno = EINVAL; + return -1; + } + if (!count) + return 0; + /* Prepare data for writing. */ + for (i = 0; i < count; ++i) { + int err; + + err = ntfs_mst_pre_write_fixup((NTFS_RECORD*) + ((u8*)b + i * bksize), bksize); + if (err < 0) { + /* Abort write at this position. */ + if (!i) + return err; + count = i; + break; + } + } + /* Write the prepared data. */ + written = ntfs_pwrite(dev, pos, count * bksize, b); + /* Quickly deprotect the data again. */ + for (i = 0; i < count; ++i) + ntfs_mst_post_write_fixup((NTFS_RECORD*)((u8*)b + i * bksize)); + if (written <= 0) + return written; + /* Finally, return the number of complete blocks written. */ + return written / bksize; +} + +/** + * ntfs_cluster_read - read ntfs clusters + * @vol: volume to read from + * @lcn: starting logical cluster number + * @count: number of clusters to read + * @b: output data buffer + * + * Read @count ntfs clusters starting at logical cluster number @lcn from + * volume @vol into buffer @b. Return number of clusters read or -1 on error, + * with errno set to the error code. + */ +s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, const s64 count, + void *b) +{ + s64 br; + + if (!vol || lcn < 0 || count < 0) { + errno = EINVAL; + return -1; + } + if (vol->nr_clusters < lcn + count) { + errno = ESPIPE; + ntfs_log_perror("Trying to read outside of volume " + "(%lld < %lld)", (long long)vol->nr_clusters, + (long long)lcn + count); + return -1; + } + br = ntfs_pread(vol->dev, lcn << vol->cluster_size_bits, + count << vol->cluster_size_bits, b); + if (br < 0) { + ntfs_log_perror("Error reading cluster(s)"); + return br; + } + return br >> vol->cluster_size_bits; +} + +/** + * ntfs_cluster_write - write ntfs clusters + * @vol: volume to write to + * @lcn: starting logical cluster number + * @count: number of clusters to write + * @b: data buffer to write to disk + * + * Write @count ntfs clusters starting at logical cluster number @lcn from + * buffer @b to volume @vol. Return the number of clusters written or -1 on + * error, with errno set to the error code. + */ +s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, + const s64 count, const void *b) +{ + s64 bw; + + if (!vol || lcn < 0 || count < 0) { + errno = EINVAL; + return -1; + } + if (vol->nr_clusters < lcn + count) { + errno = ESPIPE; + ntfs_log_perror("Trying to write outside of volume " + "(%lld < %lld)", (long long)vol->nr_clusters, + (long long)lcn + count); + return -1; + } + if (!NVolReadOnly(vol)) + bw = ntfs_pwrite(vol->dev, lcn << vol->cluster_size_bits, + count << vol->cluster_size_bits, b); + else + bw = count << vol->cluster_size_bits; + if (bw < 0) { + ntfs_log_perror("Error writing cluster(s)"); + return bw; + } + return bw >> vol->cluster_size_bits; +} + +/** + * ntfs_device_offset_valid - test if a device offset is valid + * @dev: open device + * @ofs: offset to test for validity + * + * Test if the offset @ofs is an existing location on the device described + * by the open device structure @dev. + * + * Return 0 if it is valid and -1 if it is not valid. + */ +static int ntfs_device_offset_valid(struct ntfs_device *dev, s64 ofs) +{ + char ch; + + if (dev->d_ops->seek(dev, ofs, SEEK_SET) >= 0 && + dev->d_ops->read(dev, &ch, 1) == 1) + return 0; + return -1; +} + +/** + * ntfs_device_size_get - return the size of a device in blocks + * @dev: open device + * @block_size: block size in bytes in which to return the result + * + * Return the number of @block_size sized blocks in the device described by the + * open device @dev. + * + * Adapted from e2fsutils-1.19, Copyright (C) 1995 Theodore Ts'o. + * + * On error return -1 with errno set to the error code. + */ +s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size) +{ + s64 high, low; + + if (!dev || block_size <= 0 || (block_size - 1) & block_size) { + errno = EINVAL; + return -1; + } +#ifdef BLKGETSIZE64 + { u64 size; + + if (dev->d_ops->ioctl(dev, BLKGETSIZE64, &size) >= 0) { + ntfs_log_debug("BLKGETSIZE64 nr bytes = %llu (0x%llx)\n", + (unsigned long long)size, + (unsigned long long)size); + return (s64)size / block_size; + } + } +#endif +#ifdef BLKGETSIZE + { unsigned long size; + + if (dev->d_ops->ioctl(dev, BLKGETSIZE, &size) >= 0) { + ntfs_log_debug("BLKGETSIZE nr 512 byte blocks = %lu (0x%lx)\n", + size, size); + return (s64)size * 512 / block_size; + } + } +#endif +#ifdef FDGETPRM + { struct floppy_struct this_floppy; + + if (dev->d_ops->ioctl(dev, FDGETPRM, &this_floppy) >= 0) { + ntfs_log_debug("FDGETPRM nr 512 byte blocks = %lu (0x%lx)\n", + (unsigned long)this_floppy.size, + (unsigned long)this_floppy.size); + return (s64)this_floppy.size * 512 / block_size; + } + } +#endif + /* + * We couldn't figure it out by using a specialized ioctl, + * so do binary search to find the size of the device. + */ + low = 0LL; + for (high = 1024LL; !ntfs_device_offset_valid(dev, high); high <<= 1) + low = high; + while (low < high - 1LL) { + const s64 mid = (low + high) / 2; + + if (!ntfs_device_offset_valid(dev, mid)) + low = mid; + else + high = mid; + } + dev->d_ops->seek(dev, 0LL, SEEK_SET); + return (low + 1LL) / block_size; +} + +/** + * ntfs_device_partition_start_sector_get - get starting sector of a partition + * @dev: open device + * + * On success, return the starting sector of the partition @dev in the parent + * block device of @dev. On error return -1 with errno set to the error code. + * + * The following error codes are defined: + * EINVAL Input parameter error + * EOPNOTSUPP System does not support HDIO_GETGEO ioctl + * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO + */ +s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev) +{ + if (!dev) { + errno = EINVAL; + return -1; + } +#ifdef HDIO_GETGEO + { struct hd_geometry geo; + + if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { + ntfs_log_debug("HDIO_GETGEO start_sect = %lu (0x%lx)\n", + geo.start, geo.start); + return geo.start; + } + } +#else + errno = EOPNOTSUPP; +#endif + return -1; +} + +/** + * ntfs_device_heads_get - get number of heads of device + * @dev: open device + * + * On success, return the number of heads on the device @dev. On error return + * -1 with errno set to the error code. + * + * The following error codes are defined: + * EINVAL Input parameter error + * EOPNOTSUPP System does not support HDIO_GETGEO ioctl + * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO + */ +int ntfs_device_heads_get(struct ntfs_device *dev) +{ + if (!dev) { + errno = EINVAL; + return -1; + } +#ifdef HDIO_GETGEO + { struct hd_geometry geo; + + if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { + ntfs_log_debug("HDIO_GETGEO heads = %u (0x%x)\n", + (unsigned)geo.heads, + (unsigned)geo.heads); + return geo.heads; + } + } +#else + errno = EOPNOTSUPP; +#endif + return -1; +} + +/** + * ntfs_device_sectors_per_track_get - get number of sectors per track of device + * @dev: open device + * + * On success, return the number of sectors per track on the device @dev. On + * error return -1 with errno set to the error code. + * + * The following error codes are defined: + * EINVAL Input parameter error + * EOPNOTSUPP System does not support HDIO_GETGEO ioctl + * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO + */ +int ntfs_device_sectors_per_track_get(struct ntfs_device *dev) +{ + if (!dev) { + errno = EINVAL; + return -1; + } +#ifdef HDIO_GETGEO + { struct hd_geometry geo; + + if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { + ntfs_log_debug("HDIO_GETGEO sectors_per_track = %u (0x%x)\n", + (unsigned)geo.sectors, + (unsigned)geo.sectors); + return geo.sectors; + } + } +#else + errno = EOPNOTSUPP; +#endif + return -1; +} + +/** + * ntfs_device_sector_size_get - get sector size of a device + * @dev: open device + * + * On success, return the sector size in bytes of the device @dev. + * On error return -1 with errno set to the error code. + * + * The following error codes are defined: + * EINVAL Input parameter error + * EOPNOTSUPP System does not support BLKSSZGET ioctl + * ENOTTY @dev is a file or a device not supporting BLKSSZGET + */ +int ntfs_device_sector_size_get(struct ntfs_device *dev) +{ + if (!dev) { + errno = EINVAL; + return -1; + } +#ifdef BLKSSZGET + { + int sect_size = 0; + + if (!dev->d_ops->ioctl(dev, BLKSSZGET, §_size)) { + ntfs_log_debug("BLKSSZGET sector size = %d bytes\n", + sect_size); + return sect_size; + } + } +#else + errno = EOPNOTSUPP; +#endif + return -1; +} + +/** + * ntfs_device_block_size_set - set block size of a device + * @dev: open device + * @block_size: block size to set @dev to + * + * On success, return 0. + * On error return -1 with errno set to the error code. + * + * The following error codes are defined: + * EINVAL Input parameter error + * EOPNOTSUPP System does not support BLKBSZSET ioctl + * ENOTTY @dev is a file or a device not supporting BLKBSZSET + */ +int ntfs_device_block_size_set(struct ntfs_device *dev, + int block_size __attribute__((unused))) +{ + if (!dev) { + errno = EINVAL; + return -1; + } +#ifdef BLKBSZSET + { + size_t s_block_size = block_size; + if (!dev->d_ops->ioctl(dev, BLKBSZSET, &s_block_size)) { + ntfs_log_debug("Used BLKBSZSET to set block size to " + "%d bytes.\n", block_size); + return 0; + } + /* If not a block device, pretend it was successful. */ + if (!NDevBlock(dev)) + return 0; + } +#else + /* If not a block device, pretend it was successful. */ + if (!NDevBlock(dev)) + return 0; + errno = EOPNOTSUPP; +#endif + return -1; +} diff --git a/libcustomntfs/device.h b/libcustomntfs/device.h new file mode 100644 index 00000000..a19d29c4 --- /dev/null +++ b/libcustomntfs/device.h @@ -0,0 +1,128 @@ +/* + * device.h - Exports for low level device io. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2006 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_DEVICE_H +#define _NTFS_DEVICE_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "device_io.h" +#include "types.h" +#include "support.h" +#include "volume.h" + +/** + * enum ntfs_device_state_bits - + * + * Defined bits for the state field in the ntfs_device structure. + */ +typedef enum { + ND_Open, /* 1: Device is open. */ + ND_ReadOnly, /* 1: Device is read-only. */ + ND_Dirty, /* 1: Device is dirty, needs sync. */ + ND_Block, /* 1: Device is a block device. */ +} ntfs_device_state_bits; + +#define test_ndev_flag(nd, flag) test_bit(ND_##flag, (nd)->d_state) +#define set_ndev_flag(nd, flag) set_bit(ND_##flag, (nd)->d_state) +#define clear_ndev_flag(nd, flag) clear_bit(ND_##flag, (nd)->d_state) + +#define NDevOpen(nd) test_ndev_flag(nd, Open) +#define NDevSetOpen(nd) set_ndev_flag(nd, Open) +#define NDevClearOpen(nd) clear_ndev_flag(nd, Open) + +#define NDevReadOnly(nd) test_ndev_flag(nd, ReadOnly) +#define NDevSetReadOnly(nd) set_ndev_flag(nd, ReadOnly) +#define NDevClearReadOnly(nd) clear_ndev_flag(nd, ReadOnly) + +#define NDevDirty(nd) test_ndev_flag(nd, Dirty) +#define NDevSetDirty(nd) set_ndev_flag(nd, Dirty) +#define NDevClearDirty(nd) clear_ndev_flag(nd, Dirty) + +#define NDevBlock(nd) test_ndev_flag(nd, Block) +#define NDevSetBlock(nd) set_ndev_flag(nd, Block) +#define NDevClearBlock(nd) clear_ndev_flag(nd, Block) + +/** + * struct ntfs_device - + * + * The ntfs device structure defining all operations needed to access the low + * level device underlying the ntfs volume. + */ +struct ntfs_device { + struct ntfs_device_operations *d_ops; /* Device operations. */ + unsigned long d_state; /* State of the device. */ + char *d_name; /* Name of device. */ + void *d_private; /* Private data used by the + device operations. */ +}; + +struct stat; + +/** + * struct ntfs_device_operations - + * + * The ntfs device operations defining all operations that can be performed on + * the low level device described by an ntfs device structure. + */ +struct ntfs_device_operations { + int (*open)(struct ntfs_device *dev, int flags); + int (*close)(struct ntfs_device *dev); + s64 (*seek)(struct ntfs_device *dev, s64 offset, int whence); + s64 (*read)(struct ntfs_device *dev, void *buf, s64 count); + s64 (*write)(struct ntfs_device *dev, const void *buf, s64 count); + s64 (*pread)(struct ntfs_device *dev, void *buf, s64 count, s64 offset); + s64 (*pwrite)(struct ntfs_device *dev, const void *buf, s64 count, + s64 offset); + int (*sync)(struct ntfs_device *dev); + int (*stat)(struct ntfs_device *dev, struct stat *buf); + int (*ioctl)(struct ntfs_device *dev, int request, void *argp); +}; + +extern struct ntfs_device *ntfs_device_alloc(const char *name, const long state, + struct ntfs_device_operations *dops, void *priv_data); +extern int ntfs_device_free(struct ntfs_device *dev); + +extern s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, + void *b); +extern s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, + const void *b); + +extern s64 ntfs_mst_pread(struct ntfs_device *dev, const s64 pos, s64 count, + const u32 bksize, void *b); +extern s64 ntfs_mst_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, + const u32 bksize, void *b); + +extern s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, + const s64 count, void *b); +extern s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, + const s64 count, const void *b); + +extern s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size); +extern s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev); +extern int ntfs_device_heads_get(struct ntfs_device *dev); +extern int ntfs_device_sectors_per_track_get(struct ntfs_device *dev); +extern int ntfs_device_sector_size_get(struct ntfs_device *dev); +extern int ntfs_device_block_size_set(struct ntfs_device *dev, int block_size); + +#endif /* defined _NTFS_DEVICE_H */ diff --git a/libcustomntfs/device_io.c b/libcustomntfs/device_io.c new file mode 100644 index 00000000..f76bf703 --- /dev/null +++ b/libcustomntfs/device_io.c @@ -0,0 +1,40 @@ +/* + * device_io.c - Default device io operations. Originated from the Linux-NTFS project. + * + * Copyright (c) 2003 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" + +#ifndef GEKKO +#ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS + +#ifndef __CYGWIN32__ + +/* Not on Cygwin; use standard Unix style low level device operations. */ +#include "unix_io.c" + +#else /* __CYGWIN32__ */ + +/* On Cygwin; use Win32 low level device operations. */ +#include "win32_io.c" + +#endif /* __CYGWIN32__ */ + +#endif /* NO_NTFS_DEVICE_DEFAULT_IO_OPS */ +#endif /* GEKKO */ diff --git a/libcustomntfs/device_io.h b/libcustomntfs/device_io.h new file mode 100644 index 00000000..fad4d85f --- /dev/null +++ b/libcustomntfs/device_io.h @@ -0,0 +1,82 @@ +/* + * device_io.h - Exports for default device io. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2006 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_DEVICE_IO_H +#define _NTFS_DEVICE_IO_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS + +#ifndef __CYGWIN32__ + +#ifndef GEKKO +/* Not on Cygwin; use standard Unix style low level device operations. */ +#define ntfs_device_default_io_ops ntfs_device_unix_io_ops +#else +/* Wii i/o device. */ +#define ntfs_device_default_io_ops ntfs_device_gekko_io_ops +#endif + +#else /* __CYGWIN32__ */ + +#ifndef HDIO_GETGEO +# define HDIO_GETGEO 0x301 +/** + * struct hd_geometry - + */ +struct hd_geometry { + unsigned char heads; + unsigned char sectors; + unsigned short cylinders; + unsigned long start; +}; +#endif +#ifndef BLKGETSIZE +# define BLKGETSIZE 0x1260 +#endif +#ifndef BLKSSZGET +# define BLKSSZGET 0x1268 +#endif +#ifndef BLKGETSIZE64 +# define BLKGETSIZE64 0x80041272 +#endif +#ifndef BLKBSZSET +# define BLKBSZSET 0x40041271 +#endif + +/* On Cygwin; use Win32 low level device operations. */ +#define ntfs_device_default_io_ops ntfs_device_win32_io_ops + +#endif /* __CYGWIN32__ */ + + +/* Forward declaration. */ +struct ntfs_device_operations; + +extern struct ntfs_device_operations ntfs_device_default_io_ops; + +#endif /* NO_NTFS_DEVICE_DEFAULT_IO_OPS */ + +#endif /* defined _NTFS_DEVICE_IO_H */ + diff --git a/libcustomntfs/dir.c b/libcustomntfs/dir.c new file mode 100644 index 00000000..2372f3f8 --- /dev/null +++ b/libcustomntfs/dir.c @@ -0,0 +1,2660 @@ +/** + * dir.c - Directory handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2005 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2004-2008 Szabolcs Szakacsits + * Copyright (c) 2005-2007 Yura Pakhuchiy + * Copyright (c) 2008-2010 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif + +#include "param.h" +#include "types.h" +#include "debug.h" +#include "attrib.h" +#include "inode.h" +#include "dir.h" +#include "volume.h" +#include "mft.h" +#include "index.h" +#include "ntfstime.h" +#include "lcnalloc.h" +#include "logging.h" +#include "cache.h" +#include "misc.h" +#include "security.h" +#include "reparse.h" +#include "object_id.h" + +#ifdef HAVE_SETXATTR +#include +#endif + +/* + * The little endian Unicode strings "$I30", "$SII", "$SDH", "$O" + * and "$Q" as global constants. + */ +ntfschar NTFS_INDEX_I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'), + const_cpu_to_le16('3'), const_cpu_to_le16('0'), + const_cpu_to_le16('\0') }; +ntfschar NTFS_INDEX_SII[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), + const_cpu_to_le16('I'), const_cpu_to_le16('I'), + const_cpu_to_le16('\0') }; +ntfschar NTFS_INDEX_SDH[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'), + const_cpu_to_le16('D'), const_cpu_to_le16('H'), + const_cpu_to_le16('\0') }; +ntfschar NTFS_INDEX_O[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('O'), + const_cpu_to_le16('\0') }; +ntfschar NTFS_INDEX_Q[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('Q'), + const_cpu_to_le16('\0') }; +ntfschar NTFS_INDEX_R[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('R'), + const_cpu_to_le16('\0') }; + +#if CACHE_INODE_SIZE + +/* + * Pathname hashing + * + * Based on first char and second char (which may be '\0') + */ + +int ntfs_dir_inode_hash(const struct CACHED_GENERIC *cached) +{ + const char *path; + const unsigned char *name; + + path = (const char*)cached->variable; + if (!path) { + ntfs_log_error("Bad inode cache entry\n"); + return (-1); + } + name = (const unsigned char*)strrchr(path,'/'); + if (!name) + name = (const unsigned char*)path; + return (((name[0] << 1) + name[1] + strlen((const char*)name)) + % (2*CACHE_INODE_SIZE)); +} + +/* + * Pathname comparing for entering/fetching from cache + */ + +static int inode_cache_compare(const struct CACHED_GENERIC *cached, + const struct CACHED_GENERIC *wanted) +{ + return (!cached->variable + || strcmp(cached->variable, wanted->variable)); +} + +/* + * Pathname comparing for invalidating entries in cache + * + * A partial path is compared in order to invalidate all paths + * related to a renamed directory + * inode numbers are also checked, as deleting a long name may + * imply deleting a short name and conversely + * + * Only use associated with a CACHE_NOHASH flag + */ + +static int inode_cache_inv_compare(const struct CACHED_GENERIC *cached, + const struct CACHED_GENERIC *wanted) +{ + int len; + BOOL different; + const struct CACHED_INODE *w; + const struct CACHED_INODE *c; + + w = (const struct CACHED_INODE*)wanted; + c = (const struct CACHED_INODE*)cached; + if (w->pathname) { + len = strlen(w->pathname); + different = !cached->variable + || ((w->inum != MREF(c->inum)) + && (strncmp(c->pathname, w->pathname, len) + || ((c->pathname[len] != '\0') + && (c->pathname[len] != '/')))); + } else + different = !c->pathname + || (w->inum != MREF(c->inum)); + return (different); +} + +#endif + +#if CACHE_LOOKUP_SIZE + +/* + * File name comparing for entering/fetching from lookup cache + */ + +static int lookup_cache_compare(const struct CACHED_GENERIC *cached, + const struct CACHED_GENERIC *wanted) +{ + const struct CACHED_LOOKUP *c = (const struct CACHED_LOOKUP*) cached; + const struct CACHED_LOOKUP *w = (const struct CACHED_LOOKUP*) wanted; + return (!c->name + || (c->parent != w->parent) + || (c->namesize != w->namesize) + || memcmp(c->name, w->name, c->namesize)); +} + +/* + * Inode number comparing for invalidating lookup cache + * + * All entries with designated inode number are invalidated + * + * Only use associated with a CACHE_NOHASH flag + */ + +static int lookup_cache_inv_compare(const struct CACHED_GENERIC *cached, + const struct CACHED_GENERIC *wanted) +{ + const struct CACHED_LOOKUP *c = (const struct CACHED_LOOKUP*) cached; + const struct CACHED_LOOKUP *w = (const struct CACHED_LOOKUP*) wanted; + return (!c->name + || (c->parent != w->parent) + || (MREF(c->inum) != MREF(w->inum))); +} + +/* + * Lookup hashing + * + * Based on first, second and and last char + */ + +int ntfs_dir_lookup_hash(const struct CACHED_GENERIC *cached) +{ + const unsigned char *name; + int count; + unsigned int val; + + name = (const unsigned char*)cached->variable; + count = cached->varsize; + if (!name || !count) { + ntfs_log_error("Bad lookup cache entry\n"); + return (-1); + } + val = (name[0] << 2) + (name[1] << 1) + name[count - 1] + count; + return (val % (2*CACHE_LOOKUP_SIZE)); +} + +#endif + +/** + * ntfs_inode_lookup_by_name - find an inode in a directory given its name + * @dir_ni: ntfs inode of the directory in which to search for the name + * @uname: Unicode name for which to search in the directory + * @uname_len: length of the name @uname in Unicode characters + * + * Look for an inode with name @uname in the directory with inode @dir_ni. + * ntfs_inode_lookup_by_name() walks the contents of the directory looking for + * the Unicode name. If the name is found in the directory, the corresponding + * inode number (>= 0) is returned as a mft reference in cpu format, i.e. it + * is a 64-bit number containing the sequence number. + * + * On error, return -1 with errno set to the error code. If the inode is is not + * found errno is ENOENT. + * + * Note, @uname_len does not include the (optional) terminating NULL character. + * + * Note, we look for a case sensitive match first but we also look for a case + * insensitive match at the same time. If we find a case insensitive match, we + * save that for the case that we don't find an exact match, where we return + * the mft reference of the case insensitive match. + * + * If the volume is mounted with the case sensitive flag set, then we only + * allow exact matches. + */ +u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, + const ntfschar *uname, const int uname_len) +{ + VCN vcn; + u64 mref = 0; + s64 br; + ntfs_volume *vol = dir_ni->vol; + ntfs_attr_search_ctx *ctx; + INDEX_ROOT *ir; + INDEX_ENTRY *ie; + INDEX_ALLOCATION *ia; + IGNORE_CASE_BOOL case_sensitivity; + u8 *index_end; + ntfs_attr *ia_na; + int eo, rc; + u32 index_block_size, index_vcn_size; + u8 index_vcn_size_bits; + + ntfs_log_trace("Entering\n"); + + if (!dir_ni || !dir_ni->mrec || !uname || uname_len <= 0) { + errno = EINVAL; + return -1; + } + + ctx = ntfs_attr_get_search_ctx(dir_ni, NULL); + if (!ctx) + return -1; + + /* Find the index root attribute in the mft record. */ + if (ntfs_attr_lookup(AT_INDEX_ROOT, NTFS_INDEX_I30, 4, CASE_SENSITIVE, 0, NULL, + 0, ctx)) { + ntfs_log_perror("Index root attribute missing in directory inode " + "%lld", (unsigned long long)dir_ni->mft_no); + goto put_err_out; + } + case_sensitivity = (NVolCaseSensitive(vol) ? CASE_SENSITIVE : IGNORE_CASE); + /* Get to the index root value. */ + ir = (INDEX_ROOT*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + index_block_size = le32_to_cpu(ir->index_block_size); + if (index_block_size < NTFS_BLOCK_SIZE || + index_block_size & (index_block_size - 1)) { + ntfs_log_error("Index block size %u is invalid.\n", + (unsigned)index_block_size); + goto put_err_out; + } + index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length); + /* The first index entry. */ + ie = (INDEX_ENTRY*)((u8*)&ir->index + + le32_to_cpu(ir->index.entries_offset)); + /* + * Loop until we exceed valid memory (corruption case) or until we + * reach the last entry. + */ + for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { + /* Bounds checks. */ + if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie + + sizeof(INDEX_ENTRY_HEADER) > index_end || + (u8*)ie + le16_to_cpu(ie->key_length) > + index_end) { + ntfs_log_error("Index entry out of bounds in inode %lld" + "\n", (unsigned long long)dir_ni->mft_no); + goto put_err_out; + } + /* + * The last entry cannot contain a name. It can however contain + * a pointer to a child node in the B+tree so we just break out. + */ + if (ie->ie_flags & INDEX_ENTRY_END) + break; + + if (!le16_to_cpu(ie->length)) { + ntfs_log_error("Zero length index entry in inode %lld" + "\n", (unsigned long long)dir_ni->mft_no); + goto put_err_out; + } + /* + * Not a perfect match, need to do full blown collation so we + * know which way in the B+tree we have to go. + */ + rc = ntfs_names_full_collate(uname, uname_len, + (ntfschar*)&ie->key.file_name.file_name, + ie->key.file_name.file_name_length, + case_sensitivity, vol->upcase, vol->upcase_len); + /* + * If uname collates before the name of the current entry, there + * is definitely no such name in this index but we might need to + * descend into the B+tree so we just break out of the loop. + */ + if (rc == -1) + break; + /* The names are not equal, continue the search. */ + if (rc) + continue; + /* + * Perfect match, this will never happen as the + * ntfs_are_names_equal() call will have gotten a match but we + * still treat it correctly. + */ + mref = le64_to_cpu(ie->indexed_file); + ntfs_attr_put_search_ctx(ctx); + return mref; + } + /* + * We have finished with this index without success. Check for the + * presence of a child node and if not present return error code + * ENOENT, unless we have got the mft reference of a matching name + * cached in mref in which case return mref. + */ + if (!(ie->ie_flags & INDEX_ENTRY_NODE)) { + ntfs_attr_put_search_ctx(ctx); + if (mref) + return mref; + ntfs_log_debug("Entry not found.\n"); + errno = ENOENT; + return -1; + } /* Child node present, descend into it. */ + + /* Open the index allocation attribute. */ + ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); + if (!ia_na) { + ntfs_log_perror("Failed to open index allocation (inode %lld)", + (unsigned long long)dir_ni->mft_no); + goto put_err_out; + } + + /* Allocate a buffer for the current index block. */ + ia = ntfs_malloc(index_block_size); + if (!ia) { + ntfs_attr_close(ia_na); + goto put_err_out; + } + + /* Determine the size of a vcn in the directory index. */ + if (vol->cluster_size <= index_block_size) { + index_vcn_size = vol->cluster_size; + index_vcn_size_bits = vol->cluster_size_bits; + } else { + index_vcn_size = vol->sector_size; + index_vcn_size_bits = vol->sector_size_bits; + } + + /* Get the starting vcn of the index_block holding the child node. */ + vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8); + +descend_into_child_node: + + /* Read the index block starting at vcn. */ + br = ntfs_attr_mst_pread(ia_na, vcn << index_vcn_size_bits, 1, + index_block_size, ia); + if (br != 1) { + if (br != -1) + errno = EIO; + ntfs_log_perror("Failed to read vcn 0x%llx", + (unsigned long long)vcn); + goto close_err_out; + } + + if (sle64_to_cpu(ia->index_block_vcn) != vcn) { + ntfs_log_error("Actual VCN (0x%llx) of index buffer is different " + "from expected VCN (0x%llx).\n", + (long long)sle64_to_cpu(ia->index_block_vcn), + (long long)vcn); + errno = EIO; + goto close_err_out; + } + if (le32_to_cpu(ia->index.allocated_size) + 0x18 != index_block_size) { + ntfs_log_error("Index buffer (VCN 0x%llx) of directory inode 0x%llx " + "has a size (%u) differing from the directory " + "specified size (%u).\n", (long long)vcn, + (unsigned long long)dir_ni->mft_no, + (unsigned) le32_to_cpu(ia->index.allocated_size) + 0x18, + (unsigned)index_block_size); + errno = EIO; + goto close_err_out; + } + index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); + if (index_end > (u8*)ia + index_block_size) { + ntfs_log_error("Size of index buffer (VCN 0x%llx) of directory inode " + "0x%llx exceeds maximum size.\n", + (long long)vcn, (unsigned long long)dir_ni->mft_no); + errno = EIO; + goto close_err_out; + } + + /* The first index entry. */ + ie = (INDEX_ENTRY*)((u8*)&ia->index + + le32_to_cpu(ia->index.entries_offset)); + /* + * Iterate similar to above big loop but applied to index buffer, thus + * loop until we exceed valid memory (corruption case) or until we + * reach the last entry. + */ + for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { + /* Bounds check. */ + if ((u8*)ie < (u8*)ia || (u8*)ie + + sizeof(INDEX_ENTRY_HEADER) > index_end || + (u8*)ie + le16_to_cpu(ie->key_length) > + index_end) { + ntfs_log_error("Index entry out of bounds in directory " + "inode %lld.\n", + (unsigned long long)dir_ni->mft_no); + errno = EIO; + goto close_err_out; + } + /* + * The last entry cannot contain a name. It can however contain + * a pointer to a child node in the B+tree so we just break out. + */ + if (ie->ie_flags & INDEX_ENTRY_END) + break; + + if (!le16_to_cpu(ie->length)) { + errno = EIO; + ntfs_log_error("Zero length index entry in inode %lld" + "\n", (unsigned long long)dir_ni->mft_no); + goto close_err_out; + } + /* + * Not a perfect match, need to do full blown collation so we + * know which way in the B+tree we have to go. + */ + rc = ntfs_names_full_collate(uname, uname_len, + (ntfschar*)&ie->key.file_name.file_name, + ie->key.file_name.file_name_length, + case_sensitivity, vol->upcase, vol->upcase_len); + /* + * If uname collates before the name of the current entry, there + * is definitely no such name in this index but we might need to + * descend into the B+tree so we just break out of the loop. + */ + if (rc == -1) + break; + /* The names are not equal, continue the search. */ + if (rc) + continue; + mref = le64_to_cpu(ie->indexed_file); + free(ia); + ntfs_attr_close(ia_na); + ntfs_attr_put_search_ctx(ctx); + return mref; + } + /* + * We have finished with this index buffer without success. Check for + * the presence of a child node. + */ + if (ie->ie_flags & INDEX_ENTRY_NODE) { + if ((ia->index.ih_flags & NODE_MASK) == LEAF_NODE) { + ntfs_log_error("Index entry with child node found in a leaf " + "node in directory inode %lld.\n", + (unsigned long long)dir_ni->mft_no); + errno = EIO; + goto close_err_out; + } + /* Child node present, descend into it. */ + vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8); + if (vcn >= 0) + goto descend_into_child_node; + ntfs_log_error("Negative child node vcn in directory inode " + "0x%llx.\n", (unsigned long long)dir_ni->mft_no); + errno = EIO; + goto close_err_out; + } + free(ia); + ntfs_attr_close(ia_na); + ntfs_attr_put_search_ctx(ctx); + /* + * No child node present, return error code ENOENT, unless we have got + * the mft reference of a matching name cached in mref in which case + * return mref. + */ + if (mref) + return mref; + ntfs_log_debug("Entry not found.\n"); + errno = ENOENT; + return -1; +put_err_out: + eo = EIO; + ntfs_log_debug("Corrupt directory. Aborting lookup.\n"); +eo_put_err_out: + ntfs_attr_put_search_ctx(ctx); + errno = eo; + return -1; +close_err_out: + eo = errno; + free(ia); + ntfs_attr_close(ia_na); + goto eo_put_err_out; +} + +/* + * Lookup a file in a directory from its UTF-8 name + * + * The name is first fetched from cache if one is defined + * + * Returns the inode number + * or -1 if not possible (errno tells why) + */ + +u64 ntfs_inode_lookup_by_mbsname(ntfs_inode *dir_ni, const char *name) +{ + int uname_len; + ntfschar *uname = (ntfschar*)NULL; + u64 inum; + char *cached_name; + const char *const_name; + + if (!NVolCaseSensitive(dir_ni->vol)) { + cached_name = ntfs_uppercase_mbs(name, + dir_ni->vol->upcase, dir_ni->vol->upcase_len); + const_name = cached_name; + } else { + cached_name = (char*)NULL; + const_name = name; + } + if (const_name) { +#if CACHE_LOOKUP_SIZE + + /* + * fetch inode from cache + */ + + if (dir_ni->vol->lookup_cache) { + struct CACHED_LOOKUP item; + struct CACHED_LOOKUP *cached; + + item.name = const_name; + item.namesize = strlen(const_name) + 1; + item.parent = dir_ni->mft_no; + cached = (struct CACHED_LOOKUP*)ntfs_fetch_cache( + dir_ni->vol->lookup_cache, + GENERIC(&item), lookup_cache_compare); + if (cached) { + inum = cached->inum; + if (inum == (u64)-1) + errno = ENOENT; + } else { + /* Generate unicode name. */ + uname_len = ntfs_mbstoucs(name, &uname); + if (uname_len >= 0) { + inum = ntfs_inode_lookup_by_name(dir_ni, + uname, uname_len); + item.inum = inum; + /* enter into cache, even if not found */ + ntfs_enter_cache(dir_ni->vol->lookup_cache, + GENERIC(&item), + lookup_cache_compare); + free(uname); + } else + inum = (s64)-1; + } + } else +#endif + { + /* Generate unicode name. */ + uname_len = ntfs_mbstoucs(cached_name, &uname); + if (uname_len >= 0) + inum = ntfs_inode_lookup_by_name(dir_ni, + uname, uname_len); + else + inum = (s64)-1; + } + if (cached_name) + free(cached_name); + } else + inum = (s64)-1; + return (inum); +} + +/* + * Update a cache lookup record when a name has been defined + * + * The UTF-8 name is required + */ + +void ntfs_inode_update_mbsname(ntfs_inode *dir_ni, const char *name, u64 inum) +{ +#if CACHE_LOOKUP_SIZE + struct CACHED_LOOKUP item; + struct CACHED_LOOKUP *cached; + char *cached_name; + + if (dir_ni->vol->lookup_cache) { + if (!NVolCaseSensitive(dir_ni->vol)) { + cached_name = ntfs_uppercase_mbs(name, + dir_ni->vol->upcase, dir_ni->vol->upcase_len); + item.name = cached_name; + } else { + cached_name = (char*)NULL; + item.name = name; + } + if (item.name) { + item.namesize = strlen(item.name) + 1; + item.parent = dir_ni->mft_no; + item.inum = inum; + cached = (struct CACHED_LOOKUP*)ntfs_enter_cache( + dir_ni->vol->lookup_cache, + GENERIC(&item), lookup_cache_compare); + if (cached) + cached->inum = inum; + if (cached_name) + free(cached_name); + } + } +#endif +} + +/** + * ntfs_pathname_to_inode - Find the inode which represents the given pathname + * @vol: An ntfs volume obtained from ntfs_mount + * @parent: A directory inode to begin the search (may be NULL) + * @pathname: Pathname to be located + * + * Take an ASCII pathname and find the inode that represents it. The function + * splits the path and then descends the directory tree. If @parent is NULL, + * then the root directory '.' will be used as the base for the search. + * + * Return: inode Success, the pathname was valid + * NULL Error, the pathname was invalid, or some other error occurred + */ +ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, + const char *pathname) +{ + u64 inum; + int len, err = 0; + char *p, *q; + ntfs_inode *ni; + ntfs_inode *result = NULL; + ntfschar *unicode = NULL; + char *ascii = NULL; +#if CACHE_INODE_SIZE + struct CACHED_INODE item; + struct CACHED_INODE *cached; + char *fullname; +#endif + + if (!vol || !pathname) { + errno = EINVAL; + return NULL; + } + + ntfs_log_trace("path: '%s'\n", pathname); + + ascii = strdup(pathname); + if (!ascii) { + ntfs_log_error("Out of memory.\n"); + err = ENOMEM; + goto out; + } + + p = ascii; + /* Remove leading /'s. */ + while (p && *p && *p == PATH_SEP) + p++; +#if CACHE_INODE_SIZE + fullname = p; + if (p[0] && (p[strlen(p)-1] == PATH_SEP)) + ntfs_log_error("Unnormalized path %s\n",ascii); +#endif + if (parent) { + ni = parent; + } else { +#if CACHE_INODE_SIZE + /* + * fetch inode for full path from cache + */ + if (*fullname) { + item.pathname = fullname; + item.varsize = strlen(fullname) + 1; + cached = (struct CACHED_INODE*)ntfs_fetch_cache( + vol->xinode_cache, GENERIC(&item), + inode_cache_compare); + } else + cached = (struct CACHED_INODE*)NULL; + if (cached) { + /* + * return opened inode if found in cache + */ + inum = MREF(cached->inum); + ni = ntfs_inode_open(vol, inum); + if (!ni) { + ntfs_log_debug("Cannot open inode %llu: %s.\n", + (unsigned long long)inum, p); + err = EIO; + } + result = ni; + goto out; + } +#endif + ni = ntfs_inode_open(vol, FILE_root); + if (!ni) { + ntfs_log_debug("Couldn't open the inode of the root " + "directory.\n"); + err = EIO; + result = (ntfs_inode*)NULL; + goto out; + } + } + + while (p && *p) { + /* Find the end of the first token. */ + q = strchr(p, PATH_SEP); + if (q != NULL) { + *q = '\0'; + } +#if CACHE_INODE_SIZE + /* + * fetch inode for partial path from cache + */ + cached = (struct CACHED_INODE*)NULL; + if (!parent) { + item.pathname = fullname; + item.varsize = strlen(fullname) + 1; + cached = (struct CACHED_INODE*)ntfs_fetch_cache( + vol->xinode_cache, GENERIC(&item), + inode_cache_compare); + if (cached) { + inum = cached->inum; + } + } + /* + * if not in cache, translate, search, then + * insert into cache if found + */ + if (!cached) { + len = ntfs_mbstoucs(p, &unicode); + if (len < 0) { + ntfs_log_perror("Could not convert filename to Unicode:" + " '%s'", p); + err = errno; + goto close; + } else if (len > NTFS_MAX_NAME_LEN) { + err = ENAMETOOLONG; + goto close; + } + inum = ntfs_inode_lookup_by_name(ni, unicode, len); + if (!parent && (inum != (u64) -1)) { + item.inum = inum; + ntfs_enter_cache(vol->xinode_cache, + GENERIC(&item), + inode_cache_compare); + } + } +#else + len = ntfs_mbstoucs(p, &unicode); + if (len < 0) { + ntfs_log_perror("Could not convert filename to Unicode:" + " '%s'", p); + err = errno; + goto close; + } else if (len > NTFS_MAX_NAME_LEN) { + err = ENAMETOOLONG; + goto close; + } + inum = ntfs_inode_lookup_by_name(ni, unicode, len); +#endif + if (inum == (u64) -1) { + ntfs_log_debug("Couldn't find name '%s' in pathname " + "'%s'.\n", p, pathname); + err = ENOENT; + goto close; + } + + if (ni != parent) + if (ntfs_inode_close(ni)) { + err = errno; + goto out; + } + + inum = MREF(inum); + ni = ntfs_inode_open(vol, inum); + if (!ni) { + ntfs_log_debug("Cannot open inode %llu: %s.\n", + (unsigned long long)inum, p); + err = EIO; + goto close; + } + + free(unicode); + unicode = NULL; + + if (q) *q++ = PATH_SEP; /* JPA */ + p = q; + while (p && *p && *p == PATH_SEP) + p++; + } + + result = ni; + ni = NULL; +close: + if (ni && (ni != parent)) + if (ntfs_inode_close(ni) && !err) + err = errno; +out: + free(ascii); + free(unicode); + if (err) + errno = err; + return result; +} + +/* + * The little endian Unicode string ".." for ntfs_readdir(). + */ +static const ntfschar dotdot[3] = { const_cpu_to_le16('.'), + const_cpu_to_le16('.'), + const_cpu_to_le16('\0') }; + +/* + * union index_union - + * More helpers for ntfs_readdir(). + */ +typedef union { + INDEX_ROOT *ir; + INDEX_ALLOCATION *ia; +} index_union __attribute__((__transparent_union__)); + +/** + * enum INDEX_TYPE - + * More helpers for ntfs_readdir(). + */ +typedef enum { + INDEX_TYPE_ROOT, /* index root */ + INDEX_TYPE_ALLOCATION, /* index allocation */ +} INDEX_TYPE; + +/** + * ntfs_filldir - ntfs specific filldir method + * @dir_ni: ntfs inode of current directory + * @pos: current position in directory + * @ivcn_bits: log(2) of index vcn size + * @index_type: specifies whether @iu is an index root or an index allocation + * @iu: index root or index block to which @ie belongs + * @ie: current index entry + * @dirent: context for filldir callback supplied by the caller + * @filldir: filldir callback supplied by the caller + * + * Pass information specifying the current directory entry @ie to the @filldir + * callback. + */ +static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits, + const INDEX_TYPE index_type, index_union iu, INDEX_ENTRY *ie, + void *dirent, ntfs_filldir_t filldir) +{ + FILE_NAME_ATTR *fn = &ie->key.file_name; + unsigned dt_type; + BOOL metadata; + ntfschar *loname; + int res; + MFT_REF mref; + + ntfs_log_trace("Entering.\n"); + + /* Advance the position even if going to skip the entry. */ + if (index_type == INDEX_TYPE_ALLOCATION) + *pos = (u8*)ie - (u8*)iu.ia + (sle64_to_cpu( + iu.ia->index_block_vcn) << ivcn_bits) + + dir_ni->vol->mft_record_size; + else /* if (index_type == INDEX_TYPE_ROOT) */ + *pos = (u8*)ie - (u8*)iu.ir; + /* Skip root directory self reference entry. */ + if (MREF_LE(ie->indexed_file) == FILE_root) + return 0; + if (ie->key.file_name.file_attributes & FILE_ATTR_I30_INDEX_PRESENT) + dt_type = NTFS_DT_DIR; + else if (fn->file_attributes & FILE_ATTR_SYSTEM) + dt_type = NTFS_DT_UNKNOWN; + else + dt_type = NTFS_DT_REG; + + /* return metadata files and hidden files if requested */ + mref = le64_to_cpu(ie->indexed_file); + metadata = (MREF(mref) != FILE_root) && (MREF(mref) < FILE_first_user); + if ((!metadata && (NVolShowHidFiles(dir_ni->vol) + || !(fn->file_attributes & FILE_ATTR_HIDDEN))) + || (NVolShowSysFiles(dir_ni->vol) && (NVolShowHidFiles(dir_ni->vol) + || metadata))) { + if (NVolCaseSensitive(dir_ni->vol)) { + res = filldir(dirent, fn->file_name, + fn->file_name_length, + fn->file_name_type, *pos, + mref, dt_type); + } else { + loname = (ntfschar*)ntfs_malloc(2*fn->file_name_length); + if (loname) { + memcpy(loname, fn->file_name, + 2*fn->file_name_length); + ntfs_name_locase(loname, fn->file_name_length, + dir_ni->vol->locase, + dir_ni->vol->upcase_len); + res = filldir(dirent, loname, + fn->file_name_length, + fn->file_name_type, *pos, + mref, dt_type); + free(loname); + } else + res = -1; + } + } else + res = 0; + return (res); +} + +/** + * ntfs_mft_get_parent_ref - find mft reference of parent directory of an inode + * @ni: ntfs inode whose parent directory to find + * + * Find the parent directory of the ntfs inode @ni. To do this, find the first + * file name attribute in the mft record of @ni and return the parent mft + * reference from that. + * + * Note this only makes sense for directories, since files can be hard linked + * from multiple directories and there is no way for us to tell which one is + * being looked for. + * + * Technically directories can have hard links, too, but we consider that as + * illegal as Linux/UNIX do not support directory hard links. + * + * Return the mft reference of the parent directory on success or -1 on error + * with errno set to the error code. + */ +static MFT_REF ntfs_mft_get_parent_ref(ntfs_inode *ni) +{ + MFT_REF mref; + ntfs_attr_search_ctx *ctx; + FILE_NAME_ATTR *fn; + int eo; + + ntfs_log_trace("Entering.\n"); + + if (!ni) { + errno = EINVAL; + return ERR_MREF(-1); + } + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return ERR_MREF(-1); + if (ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { + ntfs_log_error("No file name found in inode %lld\n", + (unsigned long long)ni->mft_no); + goto err_out; + } + if (ctx->attr->non_resident) { + ntfs_log_error("File name attribute must be resident (inode " + "%lld)\n", (unsigned long long)ni->mft_no); + goto io_err_out; + } + fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + if ((u8*)fn + le32_to_cpu(ctx->attr->value_length) > + (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) { + ntfs_log_error("Corrupt file name attribute in inode %lld.\n", + (unsigned long long)ni->mft_no); + goto io_err_out; + } + mref = le64_to_cpu(fn->parent_directory); + ntfs_attr_put_search_ctx(ctx); + return mref; +io_err_out: + errno = EIO; +err_out: + eo = errno; + ntfs_attr_put_search_ctx(ctx); + errno = eo; + return ERR_MREF(-1); +} + +/** + * ntfs_readdir - read the contents of an ntfs directory + * @dir_ni: ntfs inode of current directory + * @pos: current position in directory + * @dirent: context for filldir callback supplied by the caller + * @filldir: filldir callback supplied by the caller + * + * Parse the index root and the index blocks that are marked in use in the + * index bitmap and hand each found directory entry to the @filldir callback + * supplied by the caller. + * + * Return 0 on success or -1 on error with errno set to the error code. + * + * Note: Index blocks are parsed in ascending vcn order, from which follows + * that the directory entries are not returned sorted. + */ +int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, + void *dirent, ntfs_filldir_t filldir) +{ + s64 i_size, br, ia_pos, bmp_pos, ia_start; + ntfs_volume *vol; + ntfs_attr *ia_na, *bmp_na = NULL; + ntfs_attr_search_ctx *ctx = NULL; + u8 *index_end, *bmp = NULL; + INDEX_ROOT *ir; + INDEX_ENTRY *ie; + INDEX_ALLOCATION *ia = NULL; + int rc, ir_pos, bmp_buf_size, bmp_buf_pos, eo; + u32 index_block_size, index_vcn_size; + u8 index_block_size_bits, index_vcn_size_bits; + + ntfs_log_trace("Entering.\n"); + + if (!dir_ni || !pos || !filldir) { + errno = EINVAL; + return -1; + } + + if (!(dir_ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { + errno = ENOTDIR; + return -1; + } + + vol = dir_ni->vol; + + ntfs_log_trace("Entering for inode %lld, *pos 0x%llx.\n", + (unsigned long long)dir_ni->mft_no, (long long)*pos); + + /* Open the index allocation attribute. */ + ia_na = ntfs_attr_open(dir_ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); + if (!ia_na) { + if (errno != ENOENT) { + ntfs_log_perror("Failed to open index allocation attribute. " + "Directory inode %lld is corrupt or bug", + (unsigned long long)dir_ni->mft_no); + return -1; + } + i_size = 0; + } else + i_size = ia_na->data_size; + + rc = 0; + + /* Are we at end of dir yet? */ + if (*pos >= i_size + vol->mft_record_size) + goto done; + + /* Emulate . and .. for all directories. */ + if (!*pos) { + rc = filldir(dirent, dotdot, 1, FILE_NAME_POSIX, *pos, + MK_MREF(dir_ni->mft_no, + le16_to_cpu(dir_ni->mrec->sequence_number)), + NTFS_DT_DIR); + if (rc) + goto err_out; + ++*pos; + } + if (*pos == 1) { + MFT_REF parent_mref; + + parent_mref = ntfs_mft_get_parent_ref(dir_ni); + if (parent_mref == ERR_MREF(-1)) { + ntfs_log_perror("Parent directory not found"); + goto dir_err_out; + } + + rc = filldir(dirent, dotdot, 2, FILE_NAME_POSIX, *pos, + parent_mref, NTFS_DT_DIR); + if (rc) + goto err_out; + ++*pos; + } + + ctx = ntfs_attr_get_search_ctx(dir_ni, NULL); + if (!ctx) + goto err_out; + + /* Get the offset into the index root attribute. */ + ir_pos = (int)*pos; + /* Find the index root attribute in the mft record. */ + if (ntfs_attr_lookup(AT_INDEX_ROOT, NTFS_INDEX_I30, 4, CASE_SENSITIVE, 0, NULL, + 0, ctx)) { + ntfs_log_perror("Index root attribute missing in directory inode " + "%lld", (unsigned long long)dir_ni->mft_no); + goto dir_err_out; + } + /* Get to the index root value. */ + ir = (INDEX_ROOT*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + + /* Determine the size of a vcn in the directory index. */ + index_block_size = le32_to_cpu(ir->index_block_size); + if (index_block_size < NTFS_BLOCK_SIZE || + index_block_size & (index_block_size - 1)) { + ntfs_log_error("Index block size %u is invalid.\n", + (unsigned)index_block_size); + goto dir_err_out; + } + index_block_size_bits = ffs(index_block_size) - 1; + if (vol->cluster_size <= index_block_size) { + index_vcn_size = vol->cluster_size; + index_vcn_size_bits = vol->cluster_size_bits; + } else { + index_vcn_size = vol->sector_size; + index_vcn_size_bits = vol->sector_size_bits; + } + + /* Are we jumping straight into the index allocation attribute? */ + if (*pos >= vol->mft_record_size) { + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + goto skip_index_root; + } + + index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length); + /* The first index entry. */ + ie = (INDEX_ENTRY*)((u8*)&ir->index + + le32_to_cpu(ir->index.entries_offset)); + /* + * Loop until we exceed valid memory (corruption case) or until we + * reach the last entry or until filldir tells us it has had enough + * or signals an error (both covered by the rc test). + */ + for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { + ntfs_log_debug("In index root, offset %d.\n", (int)((u8*)ie - (u8*)ir)); + /* Bounds checks. */ + if ((u8*)ie < (u8*)ctx->mrec || (u8*)ie + + sizeof(INDEX_ENTRY_HEADER) > index_end || + (u8*)ie + le16_to_cpu(ie->key_length) > + index_end) + goto dir_err_out; + /* The last entry cannot contain a name. */ + if (ie->ie_flags & INDEX_ENTRY_END) + break; + + if (!le16_to_cpu(ie->length)) + goto dir_err_out; + + /* Skip index root entry if continuing previous readdir. */ + if (ir_pos > (u8*)ie - (u8*)ir) + continue; + /* + * Submit the directory entry to ntfs_filldir(), which will + * invoke the filldir() callback as appropriate. + */ + rc = ntfs_filldir(dir_ni, pos, index_vcn_size_bits, + INDEX_TYPE_ROOT, ir, ie, dirent, filldir); + if (rc) { + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + goto err_out; + } + } + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + + /* If there is no index allocation attribute we are finished. */ + if (!ia_na) + goto EOD; + + /* Advance *pos to the beginning of the index allocation. */ + *pos = vol->mft_record_size; + +skip_index_root: + + if (!ia_na) + goto done; + + /* Allocate a buffer for the current index block. */ + ia = ntfs_malloc(index_block_size); + if (!ia) + goto err_out; + + bmp_na = ntfs_attr_open(dir_ni, AT_BITMAP, NTFS_INDEX_I30, 4); + if (!bmp_na) { + ntfs_log_perror("Failed to open index bitmap attribute"); + goto dir_err_out; + } + + /* Get the offset into the index allocation attribute. */ + ia_pos = *pos - vol->mft_record_size; + + bmp_pos = ia_pos >> index_block_size_bits; + if (bmp_pos >> 3 >= bmp_na->data_size) { + ntfs_log_error("Current index position exceeds index bitmap " + "size.\n"); + goto dir_err_out; + } + + bmp_buf_size = min(bmp_na->data_size - (bmp_pos >> 3), 4096); + bmp = ntfs_malloc(bmp_buf_size); + if (!bmp) + goto err_out; + + br = ntfs_attr_pread(bmp_na, bmp_pos >> 3, bmp_buf_size, bmp); + if (br != bmp_buf_size) { + if (br != -1) + errno = EIO; + ntfs_log_perror("Failed to read from index bitmap attribute"); + goto err_out; + } + + bmp_buf_pos = 0; + /* If the index block is not in use find the next one that is. */ + while (!(bmp[bmp_buf_pos >> 3] & (1 << (bmp_buf_pos & 7)))) { +find_next_index_buffer: + bmp_pos++; + bmp_buf_pos++; + /* If we have reached the end of the bitmap, we are done. */ + if (bmp_pos >> 3 >= bmp_na->data_size) + goto EOD; + ia_pos = bmp_pos << index_block_size_bits; + if (bmp_buf_pos >> 3 < bmp_buf_size) + continue; + /* Read next chunk from the index bitmap. */ + bmp_buf_pos = 0; + if ((bmp_pos >> 3) + bmp_buf_size > bmp_na->data_size) + bmp_buf_size = bmp_na->data_size - (bmp_pos >> 3); + br = ntfs_attr_pread(bmp_na, bmp_pos >> 3, bmp_buf_size, bmp); + if (br != bmp_buf_size) { + if (br != -1) + errno = EIO; + ntfs_log_perror("Failed to read from index bitmap attribute"); + goto err_out; + } + } + + ntfs_log_debug("Handling index block 0x%llx.\n", (long long)bmp_pos); + + /* Read the index block starting at bmp_pos. */ + br = ntfs_attr_mst_pread(ia_na, bmp_pos << index_block_size_bits, 1, + index_block_size, ia); + if (br != 1) { + if (br != -1) + errno = EIO; + ntfs_log_perror("Failed to read index block"); + goto err_out; + } + + ia_start = ia_pos & ~(s64)(index_block_size - 1); + if (sle64_to_cpu(ia->index_block_vcn) != ia_start >> + index_vcn_size_bits) { + ntfs_log_error("Actual VCN (0x%llx) of index buffer is different " + "from expected VCN (0x%llx) in inode 0x%llx.\n", + (long long)sle64_to_cpu(ia->index_block_vcn), + (long long)ia_start >> index_vcn_size_bits, + (unsigned long long)dir_ni->mft_no); + goto dir_err_out; + } + if (le32_to_cpu(ia->index.allocated_size) + 0x18 != index_block_size) { + ntfs_log_error("Index buffer (VCN 0x%llx) of directory inode %lld " + "has a size (%u) differing from the directory " + "specified size (%u).\n", (long long)ia_start >> + index_vcn_size_bits, + (unsigned long long)dir_ni->mft_no, + (unsigned) le32_to_cpu(ia->index.allocated_size) + + 0x18, (unsigned)index_block_size); + goto dir_err_out; + } + index_end = (u8*)&ia->index + le32_to_cpu(ia->index.index_length); + if (index_end > (u8*)ia + index_block_size) { + ntfs_log_error("Size of index buffer (VCN 0x%llx) of directory inode " + "%lld exceeds maximum size.\n", + (long long)ia_start >> index_vcn_size_bits, + (unsigned long long)dir_ni->mft_no); + goto dir_err_out; + } + /* The first index entry. */ + ie = (INDEX_ENTRY*)((u8*)&ia->index + + le32_to_cpu(ia->index.entries_offset)); + /* + * Loop until we exceed valid memory (corruption case) or until we + * reach the last entry or until ntfs_filldir tells us it has had + * enough or signals an error (both covered by the rc test). + */ + for (;; ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length))) { + ntfs_log_debug("In index allocation, offset 0x%llx.\n", + (long long)ia_start + ((u8*)ie - (u8*)ia)); + /* Bounds checks. */ + if ((u8*)ie < (u8*)ia || (u8*)ie + + sizeof(INDEX_ENTRY_HEADER) > index_end || + (u8*)ie + le16_to_cpu(ie->key_length) > + index_end) { + ntfs_log_error("Index entry out of bounds in directory inode " + "%lld.\n", (unsigned long long)dir_ni->mft_no); + goto dir_err_out; + } + /* The last entry cannot contain a name. */ + if (ie->ie_flags & INDEX_ENTRY_END) + break; + + if (!le16_to_cpu(ie->length)) + goto dir_err_out; + + /* Skip index entry if continuing previous readdir. */ + if (ia_pos - ia_start > (u8*)ie - (u8*)ia) + continue; + /* + * Submit the directory entry to ntfs_filldir(), which will + * invoke the filldir() callback as appropriate. + */ + rc = ntfs_filldir(dir_ni, pos, index_vcn_size_bits, + INDEX_TYPE_ALLOCATION, ia, ie, dirent, filldir); + if (rc) + goto err_out; + } + goto find_next_index_buffer; +EOD: + /* We are finished, set *pos to EOD. */ + *pos = i_size + vol->mft_record_size; +done: + free(ia); + free(bmp); + if (bmp_na) + ntfs_attr_close(bmp_na); + if (ia_na) + ntfs_attr_close(ia_na); + ntfs_log_debug("EOD, *pos 0x%llx, returning 0.\n", (long long)*pos); + return 0; +dir_err_out: + errno = EIO; +err_out: + eo = errno; + ntfs_log_trace("failed.\n"); + if (ctx) + ntfs_attr_put_search_ctx(ctx); + free(ia); + free(bmp); + if (bmp_na) + ntfs_attr_close(bmp_na); + if (ia_na) + ntfs_attr_close(ia_na); + errno = eo; + return -1; +} + + +/** + * __ntfs_create - create object on ntfs volume + * @dir_ni: ntfs inode for directory in which create new object + * @securid: id of inheritable security descriptor, 0 if none + * @name: unicode name of new object + * @name_len: length of the name in unicode characters + * @type: type of the object to create + * @dev: major and minor device numbers (obtained from makedev()) + * @target: target in unicode (only for symlinks) + * @target_len: length of target in unicode characters + * + * Internal, use ntfs_create{,_device,_symlink} wrappers instead. + * + * @type can be: + * S_IFREG to create regular file + * S_IFDIR to create directory + * S_IFBLK to create block device + * S_IFCHR to create character device + * S_IFLNK to create symbolic link + * S_IFIFO to create FIFO + * S_IFSOCK to create socket + * other values are invalid. + * + * @dev is used only if @type is S_IFBLK or S_IFCHR, in other cases its value + * ignored. + * + * @target and @target_len are used only if @type is S_IFLNK, in other cases + * their value ignored. + * + * Return opened ntfs inode that describes created object on success or NULL + * on error with errno set to the error code. + */ +static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, + ntfschar *name, u8 name_len, mode_t type, dev_t dev, + ntfschar *target, int target_len) +{ + ntfs_inode *ni; + int rollback_data = 0, rollback_sd = 0; + FILE_NAME_ATTR *fn = NULL; + STANDARD_INFORMATION *si = NULL; + int err, fn_len, si_len; + + ntfs_log_trace("Entering.\n"); + + /* Sanity checks. */ + if (!dir_ni || !name || !name_len) { + ntfs_log_error("Invalid arguments.\n"); + errno = EINVAL; + return NULL; + } + + if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { + errno = EOPNOTSUPP; + return NULL; + } + + ni = ntfs_mft_record_alloc(dir_ni->vol, NULL); + if (!ni) + return NULL; +#if CACHE_NIDATA_SIZE + ntfs_inode_invalidate(dir_ni->vol, ni->mft_no); +#endif + /* + * Create STANDARD_INFORMATION attribute. + * JPA Depending on available inherited security descriptor, + * Write STANDARD_INFORMATION v1.2 (no inheritance) or v3 + */ + if (securid) + si_len = sizeof(STANDARD_INFORMATION); + else + si_len = offsetof(STANDARD_INFORMATION, v1_end); + si = ntfs_calloc(si_len); + if (!si) { + err = errno; + goto err_out; + } + si->creation_time = ni->creation_time; + si->last_data_change_time = ni->last_data_change_time; + si->last_mft_change_time = ni->last_mft_change_time; + si->last_access_time = ni->last_access_time; + if (securid) { + set_nino_flag(ni, v3_Extensions); + ni->owner_id = si->owner_id = 0; + ni->security_id = si->security_id = securid; + ni->quota_charged = si->quota_charged = const_cpu_to_le64(0); + ni->usn = si->usn = const_cpu_to_le64(0); + } else + clear_nino_flag(ni, v3_Extensions); + if (!S_ISREG(type) && !S_ISDIR(type)) { + si->file_attributes = FILE_ATTR_SYSTEM; + ni->flags = FILE_ATTR_SYSTEM; + } + ni->flags |= FILE_ATTR_ARCHIVE; + if (NVolHideDotFiles(dir_ni->vol) + && (name_len > 1) + && (name[0] == const_cpu_to_le16('.')) + && (name[1] != const_cpu_to_le16('.'))) + ni->flags |= FILE_ATTR_HIDDEN; + /* + * Set compression flag according to parent directory + * unless NTFS version < 3.0 or cluster size > 4K + * or compression has been disabled + */ + if ((dir_ni->flags & FILE_ATTR_COMPRESSED) + && (dir_ni->vol->major_ver >= 3) + && NVolCompression(dir_ni->vol) + && (dir_ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) + && (S_ISREG(type) || S_ISDIR(type))) + ni->flags |= FILE_ATTR_COMPRESSED; + /* Add STANDARD_INFORMATION to inode. */ + if (ntfs_attr_add(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0, + (u8*)si, si_len)) { + err = errno; + ntfs_log_error("Failed to add STANDARD_INFORMATION " + "attribute.\n"); + goto err_out; + } + + if (!securid) { + if (ntfs_sd_add_everyone(ni)) { + err = errno; + goto err_out; + } + } + rollback_sd = 1; + + if (S_ISDIR(type)) { + INDEX_ROOT *ir = NULL; + INDEX_ENTRY *ie; + int ir_len, index_len; + + /* Create INDEX_ROOT attribute. */ + index_len = sizeof(INDEX_HEADER) + sizeof(INDEX_ENTRY_HEADER); + ir_len = offsetof(INDEX_ROOT, index) + index_len; + ir = ntfs_calloc(ir_len); + if (!ir) { + err = errno; + goto err_out; + } + ir->type = AT_FILE_NAME; + ir->collation_rule = COLLATION_FILE_NAME; + ir->index_block_size = cpu_to_le32(ni->vol->indx_record_size); + if (ni->vol->cluster_size <= ni->vol->indx_record_size) + ir->clusters_per_index_block = + ni->vol->indx_record_size >> + ni->vol->cluster_size_bits; + else + ir->clusters_per_index_block = + ni->vol->indx_record_size >> + ni->vol->sector_size_bits; + ir->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER)); + ir->index.index_length = cpu_to_le32(index_len); + ir->index.allocated_size = cpu_to_le32(index_len); + ie = (INDEX_ENTRY*)((u8*)ir + sizeof(INDEX_ROOT)); + ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); + ie->key_length = 0; + ie->ie_flags = INDEX_ENTRY_END; + /* Add INDEX_ROOT attribute to inode. */ + if (ntfs_attr_add(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4, + (u8*)ir, ir_len)) { + err = errno; + free(ir); + ntfs_log_error("Failed to add INDEX_ROOT attribute.\n"); + goto err_out; + } + free(ir); + } else { + INTX_FILE *data; + int data_len; + + switch (type) { + case S_IFBLK: + case S_IFCHR: + data_len = offsetof(INTX_FILE, device_end); + data = ntfs_malloc(data_len); + if (!data) { + err = errno; + goto err_out; + } + data->major = cpu_to_le64(major(dev)); + data->minor = cpu_to_le64(minor(dev)); + if (type == S_IFBLK) + data->magic = INTX_BLOCK_DEVICE; + if (type == S_IFCHR) + data->magic = INTX_CHARACTER_DEVICE; + break; + case S_IFLNK: + data_len = sizeof(INTX_FILE_TYPES) + + target_len * sizeof(ntfschar); + data = ntfs_malloc(data_len); + if (!data) { + err = errno; + goto err_out; + } + data->magic = INTX_SYMBOLIC_LINK; + memcpy(data->target, target, + target_len * sizeof(ntfschar)); + break; + case S_IFSOCK: + data = NULL; + data_len = 1; + break; + default: /* FIFO or regular file. */ + data = NULL; + data_len = 0; + break; + } + /* Add DATA attribute to inode. */ + if (ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, (u8*)data, + data_len)) { + err = errno; + ntfs_log_error("Failed to add DATA attribute.\n"); + free(data); + goto err_out; + } + rollback_data = 1; + free(data); + } + /* Create FILE_NAME attribute. */ + fn_len = sizeof(FILE_NAME_ATTR) + name_len * sizeof(ntfschar); + fn = ntfs_calloc(fn_len); + if (!fn) { + err = errno; + goto err_out; + } + fn->parent_directory = MK_LE_MREF(dir_ni->mft_no, + le16_to_cpu(dir_ni->mrec->sequence_number)); + fn->file_name_length = name_len; + fn->file_name_type = FILE_NAME_POSIX; + if (S_ISDIR(type)) + fn->file_attributes = FILE_ATTR_I30_INDEX_PRESENT; + if (!S_ISREG(type) && !S_ISDIR(type)) + fn->file_attributes = FILE_ATTR_SYSTEM; + else + fn->file_attributes |= ni->flags & FILE_ATTR_COMPRESSED; + fn->file_attributes |= FILE_ATTR_ARCHIVE; + fn->file_attributes |= ni->flags & FILE_ATTR_HIDDEN; + fn->creation_time = ni->creation_time; + fn->last_data_change_time = ni->last_data_change_time; + fn->last_mft_change_time = ni->last_mft_change_time; + fn->last_access_time = ni->last_access_time; + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + fn->data_size = fn->allocated_size = const_cpu_to_le64(0); + else { + fn->data_size = cpu_to_sle64(ni->data_size); + fn->allocated_size = cpu_to_sle64(ni->allocated_size); + } + memcpy(fn->file_name, name, name_len * sizeof(ntfschar)); + /* Add FILE_NAME attribute to inode. */ + if (ntfs_attr_add(ni, AT_FILE_NAME, AT_UNNAMED, 0, (u8*)fn, fn_len)) { + err = errno; + ntfs_log_error("Failed to add FILE_NAME attribute.\n"); + goto err_out; + } + /* Add FILE_NAME attribute to index. */ + if (ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, + le16_to_cpu(ni->mrec->sequence_number)))) { + err = errno; + ntfs_log_perror("Failed to add entry to the index"); + goto err_out; + } + /* Set hard links count and directory flag. */ + ni->mrec->link_count = cpu_to_le16(1); + if (S_ISDIR(type)) + ni->mrec->flags |= MFT_RECORD_IS_DIRECTORY; + ntfs_inode_mark_dirty(ni); + /* Done! */ + free(fn); + free(si); + ntfs_log_trace("Done.\n"); + return ni; +err_out: + ntfs_log_trace("Failed.\n"); + + if (rollback_sd) + ntfs_attr_remove(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); + + if (rollback_data) + ntfs_attr_remove(ni, AT_DATA, AT_UNNAMED, 0); + /* + * Free extent MFT records (should not exist any with current + * ntfs_create implementation, but for any case if something will be + * changed in the future). + */ + while (ni->nr_extents) + if (ntfs_mft_record_free(ni->vol, *(ni->extent_nis))) { + err = errno; + ntfs_log_error("Failed to free extent MFT record. " + "Leaving inconsistent metadata.\n"); + } + if (ntfs_mft_record_free(ni->vol, ni)) + ntfs_log_error("Failed to free MFT record. " + "Leaving inconsistent metadata. Run chkdsk.\n"); + free(fn); + free(si); + errno = err; + return NULL; +} + +/** + * Some wrappers around __ntfs_create() ... + */ + +ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, ntfschar *name, + u8 name_len, mode_t type) +{ + if (type != S_IFREG && type != S_IFDIR && type != S_IFIFO && + type != S_IFSOCK) { + ntfs_log_error("Invalid arguments.\n"); + return NULL; + } + return __ntfs_create(dir_ni, securid, name, name_len, type, 0, NULL, 0); +} + +ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, + ntfschar *name, u8 name_len, mode_t type, dev_t dev) +{ + if (type != S_IFCHR && type != S_IFBLK) { + ntfs_log_error("Invalid arguments.\n"); + return NULL; + } + return __ntfs_create(dir_ni, securid, name, name_len, type, dev, NULL, 0); +} + +ntfs_inode *ntfs_create_symlink(ntfs_inode *dir_ni, le32 securid, + ntfschar *name, u8 name_len, ntfschar *target, int target_len) +{ + if (!target || !target_len) { + ntfs_log_error("%s: Invalid argument (%p, %d)\n", __FUNCTION__, + target, target_len); + return NULL; + } + return __ntfs_create(dir_ni, securid, name, name_len, S_IFLNK, 0, + target, target_len); +} + +int ntfs_check_empty_dir(ntfs_inode *ni) +{ + ntfs_attr *na; + int ret = 0; + + if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) + return 0; + + na = ntfs_attr_open(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4); + if (!na) { + errno = EIO; + ntfs_log_perror("Failed to open directory"); + return -1; + } + + /* Non-empty directory? */ + if ((na->data_size != sizeof(INDEX_ROOT) + sizeof(INDEX_ENTRY_HEADER))){ + /* Both ENOTEMPTY and EEXIST are ok. We use the more common. */ + errno = ENOTEMPTY; + ntfs_log_debug("Directory is not empty\n"); + ret = -1; + } + + ntfs_attr_close(na); + return ret; +} + +static int ntfs_check_unlinkable_dir(ntfs_inode *ni, FILE_NAME_ATTR *fn) +{ + int link_count = le16_to_cpu(ni->mrec->link_count); + int ret; + + ret = ntfs_check_empty_dir(ni); + if (!ret || errno != ENOTEMPTY) + return ret; + /* + * Directory is non-empty, so we can unlink only if there is more than + * one "real" hard link, i.e. links aren't different DOS and WIN32 names + */ + if ((link_count == 1) || + (link_count == 2 && fn->file_name_type == FILE_NAME_DOS)) { + errno = ENOTEMPTY; + ntfs_log_debug("Non-empty directory without hard links\n"); + goto no_hardlink; + } + + ret = 0; +no_hardlink: + return ret; +} + +/** + * ntfs_delete - delete file or directory from ntfs volume + * @ni: ntfs inode for object to delte + * @dir_ni: ntfs inode for directory in which delete object + * @name: unicode name of the object to delete + * @name_len: length of the name in unicode characters + * + * @ni is always closed after the call to this function (even if it failed), + * user does not need to call ntfs_inode_close himself. + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +int ntfs_delete(ntfs_volume *vol, const char *pathname, + ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) +{ + ntfs_attr_search_ctx *actx = NULL; + FILE_NAME_ATTR *fn = NULL; + BOOL looking_for_dos_name = FALSE, looking_for_win32_name = FALSE; + BOOL case_sensitive_match = TRUE; + int err = 0; +#if CACHE_NIDATA_SIZE + int i; +#endif +#if CACHE_INODE_SIZE + struct CACHED_INODE item; + const char *p; + u64 inum = (u64)-1; + int count; +#endif +#if CACHE_LOOKUP_SIZE + struct CACHED_LOOKUP lkitem; +#endif + + ntfs_log_trace("Entering.\n"); + + if (!ni || !dir_ni || !name || !name_len) { + ntfs_log_error("Invalid arguments.\n"); + errno = EINVAL; + goto err_out; + } + if (ni->nr_extents == -1) + ni = ni->base_ni; + if (dir_ni->nr_extents == -1) + dir_ni = dir_ni->base_ni; + /* + * Search for FILE_NAME attribute with such name. If it's in POSIX or + * WIN32_AND_DOS namespace, then simply remove it from index and inode. + * If filename in DOS or in WIN32 namespace, then remove DOS name first, + * only then remove WIN32 name. + */ + actx = ntfs_attr_get_search_ctx(ni, NULL); + if (!actx) + goto err_out; +search: + while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, + 0, NULL, 0, actx)) { + char *s; + BOOL case_sensitive = IGNORE_CASE; + + errno = 0; + fn = (FILE_NAME_ATTR*)((u8*)actx->attr + + le16_to_cpu(actx->attr->value_offset)); + s = ntfs_attr_name_get(fn->file_name, fn->file_name_length); + ntfs_log_trace("name: '%s' type: %d dos: %d win32: %d " + "case: %d\n", s, fn->file_name_type, + looking_for_dos_name, looking_for_win32_name, + case_sensitive_match); + ntfs_attr_name_free(&s); + if (looking_for_dos_name) { + if (fn->file_name_type == FILE_NAME_DOS) + break; + else + continue; + } + if (looking_for_win32_name) { + if (fn->file_name_type == FILE_NAME_WIN32) + break; + else + continue; + } + + /* Ignore hard links from other directories */ + if (dir_ni->mft_no != MREF_LE(fn->parent_directory)) { + ntfs_log_debug("MFT record numbers don't match " + "(%llu != %llu)\n", + (long long unsigned)dir_ni->mft_no, + (long long unsigned)MREF_LE(fn->parent_directory)); + continue; + } + + if (fn->file_name_type == FILE_NAME_POSIX || case_sensitive_match) + case_sensitive = CASE_SENSITIVE; + + if (ntfs_names_are_equal(fn->file_name, fn->file_name_length, + name, name_len, case_sensitive, + ni->vol->upcase, ni->vol->upcase_len)){ + + if (fn->file_name_type == FILE_NAME_WIN32) { + looking_for_dos_name = TRUE; + ntfs_attr_reinit_search_ctx(actx); + continue; + } + if (fn->file_name_type == FILE_NAME_DOS) + looking_for_dos_name = TRUE; + break; + } + } + if (errno) { + /* + * If case sensitive search failed, then try once again + * ignoring case. + */ + if (errno == ENOENT && case_sensitive_match) { + case_sensitive_match = FALSE; + ntfs_attr_reinit_search_ctx(actx); + goto search; + } + goto err_out; + } + + if (ntfs_check_unlinkable_dir(ni, fn) < 0) + goto err_out; + + if (ntfs_index_remove(dir_ni, ni, fn, le32_to_cpu(actx->attr->value_length))) + goto err_out; + + if (ntfs_attr_record_rm(actx)) + goto err_out; + + ni->mrec->link_count = cpu_to_le16(le16_to_cpu( + ni->mrec->link_count) - 1); + + ntfs_inode_mark_dirty(ni); + if (looking_for_dos_name) { + looking_for_dos_name = FALSE; + looking_for_win32_name = TRUE; + ntfs_attr_reinit_search_ctx(actx); + goto search; + } + /* TODO: Update object id, quota and securiry indexes if required. */ + /* + * If hard link count is not equal to zero then we are done. In other + * case there are no reference to this inode left, so we should free all + * non-resident attributes and mark all MFT record as not in use. + */ +#if CACHE_LOOKUP_SIZE + /* invalidate entry in lookup cache */ + lkitem.name = (const char*)NULL; + lkitem.namesize = 0; + lkitem.inum = ni->mft_no; + lkitem.parent = dir_ni->mft_no; + ntfs_invalidate_cache(vol->lookup_cache, GENERIC(&lkitem), + lookup_cache_inv_compare, CACHE_NOHASH); +#endif +#if CACHE_INODE_SIZE + inum = ni->mft_no; + if (pathname) { + /* invalide cache entry, even if there was an error */ + /* Remove leading /'s. */ + p = pathname; + while (*p == PATH_SEP) + p++; + if (p[0] && (p[strlen(p)-1] == PATH_SEP)) + ntfs_log_error("Unnormalized path %s\n",pathname); + item.pathname = p; + item.varsize = strlen(p); + } else { + item.pathname = (const char*)NULL; + item.varsize = 0; + } + item.inum = inum; + count = ntfs_invalidate_cache(vol->xinode_cache, GENERIC(&item), + inode_cache_inv_compare, CACHE_NOHASH); + if (pathname && !count) + ntfs_log_error("Could not delete inode cache entry for %s\n", + pathname); +#endif + if (ni->mrec->link_count) { + ntfs_inode_update_times(ni, NTFS_UPDATE_CTIME); + goto ok; + } + if (ntfs_delete_reparse_index(ni)) { + /* + * Failed to remove the reparse index : proceed anyway + * This is not a critical error, the entry is useless + * because of sequence_number, and stopping file deletion + * would be much worse as the file is not referenced now. + */ + err = errno; + } + if (ntfs_delete_object_id_index(ni)) { + /* + * Failed to remove the object id index : proceed anyway + * This is not a critical error. + */ + err = errno; + } + ntfs_attr_reinit_search_ctx(actx); + while (!ntfs_attrs_walk(actx)) { + if (actx->attr->non_resident) { + runlist *rl; + + rl = ntfs_mapping_pairs_decompress(ni->vol, actx->attr, + NULL); + if (!rl) { + err = errno; + ntfs_log_error("Failed to decompress runlist. " + "Leaving inconsistent metadata.\n"); + continue; + } + if (ntfs_cluster_free_from_rl(ni->vol, rl)) { + err = errno; + ntfs_log_error("Failed to free clusters. " + "Leaving inconsistent metadata.\n"); + continue; + } + free(rl); + } + } + if (errno != ENOENT) { + err = errno; + ntfs_log_error("Attribute enumeration failed. " + "Probably leaving inconsistent metadata.\n"); + } + /* All extents should be attached after attribute walk. */ +#if CACHE_NIDATA_SIZE + /* + * Disconnect extents before deleting them, so they are + * not wrongly moved to cache through the chainings + */ + for (i=ni->nr_extents-1; i>=0; i--) { + ni->extent_nis[i]->base_ni = (ntfs_inode*)NULL; + ni->extent_nis[i]->nr_extents = 0; + if (ntfs_mft_record_free(ni->vol, ni->extent_nis[i])) { + err = errno; + ntfs_log_error("Failed to free extent MFT record. " + "Leaving inconsistent metadata.\n"); + } + } + free(ni->extent_nis); + ni->nr_extents = 0; + ni->extent_nis = (ntfs_inode**)NULL; +#else + while (ni->nr_extents) + if (ntfs_mft_record_free(ni->vol, *(ni->extent_nis))) { + err = errno; + ntfs_log_error("Failed to free extent MFT record. " + "Leaving inconsistent metadata.\n"); + } +#endif + if (ntfs_mft_record_free(ni->vol, ni)) { + err = errno; + ntfs_log_error("Failed to free base MFT record. " + "Leaving inconsistent metadata.\n"); + } + ni = NULL; +ok: + ntfs_inode_update_times(dir_ni, NTFS_UPDATE_MCTIME); +out: + if (actx) + ntfs_attr_put_search_ctx(actx); + if (ntfs_inode_close(dir_ni) && !err) + err = errno; + if (ntfs_inode_close(ni) && !err) + err = errno; + if (err) { + errno = err; + ntfs_log_debug("Could not delete file: %s\n", strerror(errno)); + return -1; + } + ntfs_log_trace("Done.\n"); + return 0; +err_out: + err = errno; + goto out; +} + +/** + * ntfs_link - create hard link for file or directory + * @ni: ntfs inode for object to create hard link + * @dir_ni: ntfs inode for directory in which new link should be placed + * @name: unicode name of the new link + * @name_len: length of the name in unicode characters + * + * NOTE: At present we allow creating hardlinks to directories, we use them + * in a temporary state during rename. But it's defenitely bad idea to have + * hard links to directories as a result of operation. + * FIXME: Create internal __ntfs_link that allows hard links to a directories + * and external ntfs_link that do not. Write ntfs_rename that uses __ntfs_link. + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, + u8 name_len, FILE_NAME_TYPE_FLAGS nametype) +{ + FILE_NAME_ATTR *fn = NULL; + int fn_len, err; + + ntfs_log_trace("Entering.\n"); + + if (!ni || !dir_ni || !name || !name_len || + ni->mft_no == dir_ni->mft_no) { + err = EINVAL; + ntfs_log_perror("ntfs_link wrong arguments"); + goto err_out; + } + + if ((ni->flags & FILE_ATTR_REPARSE_POINT) + && !ntfs_possible_symlink(ni)) { + err = EOPNOTSUPP; + goto err_out; + } + + /* Create FILE_NAME attribute. */ + fn_len = sizeof(FILE_NAME_ATTR) + name_len * sizeof(ntfschar); + fn = ntfs_calloc(fn_len); + if (!fn) { + err = errno; + goto err_out; + } + fn->parent_directory = MK_LE_MREF(dir_ni->mft_no, + le16_to_cpu(dir_ni->mrec->sequence_number)); + fn->file_name_length = name_len; + fn->file_name_type = nametype; + fn->file_attributes = ni->flags; + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + fn->file_attributes |= FILE_ATTR_I30_INDEX_PRESENT; + fn->data_size = fn->allocated_size = const_cpu_to_le64(0); + } else { + fn->allocated_size = cpu_to_sle64(ni->allocated_size); + fn->data_size = cpu_to_sle64(ni->data_size); + } + fn->creation_time = ni->creation_time; + fn->last_data_change_time = ni->last_data_change_time; + fn->last_mft_change_time = ni->last_mft_change_time; + fn->last_access_time = ni->last_access_time; + memcpy(fn->file_name, name, name_len * sizeof(ntfschar)); + /* Add FILE_NAME attribute to index. */ + if (ntfs_index_add_filename(dir_ni, fn, MK_MREF(ni->mft_no, + le16_to_cpu(ni->mrec->sequence_number)))) { + err = errno; + ntfs_log_perror("Failed to add filename to the index"); + goto err_out; + } + /* Add FILE_NAME attribute to inode. */ + if (ntfs_attr_add(ni, AT_FILE_NAME, AT_UNNAMED, 0, (u8*)fn, fn_len)) { + ntfs_log_error("Failed to add FILE_NAME attribute.\n"); + err = errno; + /* Try to remove just added attribute from index. */ + if (ntfs_index_remove(dir_ni, ni, fn, fn_len)) + goto rollback_failed; + goto err_out; + } + /* Increment hard links count. */ + ni->mrec->link_count = cpu_to_le16(le16_to_cpu( + ni->mrec->link_count) + 1); + /* Done! */ + ntfs_inode_mark_dirty(ni); + free(fn); + ntfs_log_trace("Done.\n"); + return 0; +rollback_failed: + ntfs_log_error("Rollback failed. Leaving inconsistent metadata.\n"); +err_out: + free(fn); + errno = err; + return -1; +} + +int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) +{ + return (ntfs_link_i(ni, dir_ni, name, name_len, FILE_NAME_POSIX)); +} + +/* + * Get a parent directory from an inode entry + * + * This is only used in situations where the path used to access + * the current file is not known for sure. The result may be different + * from the path when the file is linked in several parent directories. + * + * Currently this is only used for translating ".." in the target + * of a Vista relative symbolic link + */ + +ntfs_inode *ntfs_dir_parent_inode(ntfs_inode *ni) +{ + ntfs_inode *dir_ni = (ntfs_inode*)NULL; + u64 inum; + FILE_NAME_ATTR *fn; + ntfs_attr_search_ctx *ctx; + + if (ni->mft_no != FILE_root) { + /* find the name in the attributes */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return ((ntfs_inode*)NULL); + + if (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + /* We know this will always be resident. */ + fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + inum = le64_to_cpu(fn->parent_directory); + if (inum != (u64)-1) { + dir_ni = ntfs_inode_open(ni->vol, MREF(inum)); + } + } + ntfs_attr_put_search_ctx(ctx); + } + return (dir_ni); +} + +#ifdef HAVE_SETXATTR + +#define MAX_DOS_NAME_LENGTH 12 + +/* + * Get a DOS name for a file in designated directory + * + * Returns size if found + * 0 if not found + * -1 if there was an error (described by errno) + */ + +static int get_dos_name(ntfs_inode *ni, u64 dnum, ntfschar *dosname) +{ + size_t outsize = 0; + FILE_NAME_ATTR *fn; + ntfs_attr_search_ctx *ctx; + + /* find the name in the attributes */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + + while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + /* We know this will always be resident. */ + fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + + if ((fn->file_name_type & FILE_NAME_DOS) + && (MREF_LE(fn->parent_directory) == dnum)) { + /* + * Found a DOS or WIN32+DOS name for the entry + * copy name, after truncation for safety + */ + outsize = fn->file_name_length; +/* TODO : reject if name is too long ? */ + if (outsize > MAX_DOS_NAME_LENGTH) + outsize = MAX_DOS_NAME_LENGTH; + memcpy(dosname,fn->file_name,outsize*sizeof(ntfschar)); + } + } + ntfs_attr_put_search_ctx(ctx); + return (outsize); +} + + +/* + * Get a long name for a file in designated directory + * + * Returns size if found + * 0 if not found + * -1 if there was an error (described by errno) + */ + +static int get_long_name(ntfs_inode *ni, u64 dnum, ntfschar *longname) +{ + size_t outsize = 0; + FILE_NAME_ATTR *fn; + ntfs_attr_search_ctx *ctx; + + /* find the name in the attributes */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + + /* first search for WIN32 or DOS+WIN32 names */ + while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + /* We know this will always be resident. */ + fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + + if ((fn->file_name_type & FILE_NAME_WIN32) + && (MREF_LE(fn->parent_directory) == dnum)) { + /* + * Found a WIN32 or WIN32+DOS name for the entry + * copy name + */ + outsize = fn->file_name_length; + memcpy(longname,fn->file_name,outsize*sizeof(ntfschar)); + } + } + /* if not found search for POSIX names */ + if (!outsize) { + ntfs_attr_reinit_search_ctx(ctx); + while (!ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + /* We know this will always be resident. */ + fn = (FILE_NAME_ATTR*)((u8*)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + + if ((fn->file_name_type == FILE_NAME_POSIX) + && (MREF_LE(fn->parent_directory) == dnum)) { + /* + * Found a POSIX name for the entry + * copy name + */ + outsize = fn->file_name_length; + memcpy(longname,fn->file_name,outsize*sizeof(ntfschar)); + } + } + } + ntfs_attr_put_search_ctx(ctx); + return (outsize); +} + + +/* + * Get the ntfs DOS name into an extended attribute + */ + +int ntfs_get_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, + char *value, size_t size) +{ + int outsize = 0; + char *outname = (char*)NULL; + u64 dnum; + int doslen; + ntfschar dosname[MAX_DOS_NAME_LENGTH]; + + dnum = dir_ni->mft_no; + doslen = get_dos_name(ni, dnum, dosname); + if (doslen > 0) { + /* + * Found a DOS name for the entry, make + * uppercase and encode into the buffer + * if there is enough space + */ + ntfs_name_upcase(dosname, doslen, + ni->vol->upcase, ni->vol->upcase_len); + if (ntfs_ucstombs(dosname, doslen, &outname, size) < 0) { + ntfs_log_error("Cannot represent dosname in current locale.\n"); + outsize = -errno; + } else { + outsize = strlen(outname); + if (value && (outsize <= (int)size)) + memcpy(value, outname, outsize); + else + if (size && (outsize > (int)size)) + outsize = -ERANGE; + free(outname); + } + } else { + if (doslen == 0) + errno = ENODATA; + outsize = -errno; + } + return (outsize); +} + +/* + * Change the name space of an existing file or directory + * + * Returns the old namespace if successful + * -1 if an error occurred (described by errno) + */ + +static int set_namespace(ntfs_inode *ni, ntfs_inode *dir_ni, + ntfschar *name, int len, + FILE_NAME_TYPE_FLAGS nametype) +{ + ntfs_attr_search_ctx *actx; + ntfs_index_context *icx; + FILE_NAME_ATTR *fnx; + FILE_NAME_ATTR *fn = NULL; + BOOL found; + int lkup; + int ret; + + ret = -1; + actx = ntfs_attr_get_search_ctx(ni, NULL); + if (actx) { + found = FALSE; + do { + lkup = ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, + CASE_SENSITIVE, 0, NULL, 0, actx); + if (!lkup) { + fn = (FILE_NAME_ATTR*)((u8*)actx->attr + + le16_to_cpu(actx->attr->value_offset)); + found = (MREF_LE(fn->parent_directory) + == dir_ni->mft_no) + && !memcmp(fn->file_name, name, + len*sizeof(ntfschar)); + } + } while (!lkup && !found); + if (found) { + icx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4); + if (icx) { + lkup = ntfs_index_lookup((char*)fn, len, icx); + if (!lkup && icx->data && icx->data_len) { + fnx = (FILE_NAME_ATTR*)icx->data; + ret = fn->file_name_type; + fn->file_name_type = nametype; + fnx->file_name_type = nametype; + ntfs_inode_mark_dirty(ni); + ntfs_index_entry_mark_dirty(icx); + } + ntfs_index_ctx_put(icx); + } + } + ntfs_attr_put_search_ctx(actx); + } + return (ret); +} + +/* + * Set a DOS name to a file and adjust name spaces + * + * If the new names are collapsible (same uppercased chars) : + * + * - the existing DOS name or DOS+Win32 name is made Posix + * - if it was a real DOS name, the existing long name is made DOS+Win32 + * and the existing DOS name is deleted + * - finally the existing long name is made DOS+Win32 unless already done + * + * If the new names are not collapsible : + * + * - insert the short name as a DOS name + * - delete the old long name or existing short name + * - insert the new long name (as a Win32 or DOS+Win32 name) + * + * Deleting the old long name will not delete the file + * provided the old name was in the Posix name space, + * because the alternate name has been set before. + * + * The inodes of file and parent directory are always closed + * + * Returns 0 if successful + * -1 if failed + */ + +static int set_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, + ntfschar *shortname, int shortlen, + ntfschar *longname, int longlen, + ntfschar *deletename, int deletelen, BOOL existed) +{ + unsigned int linkcount; + ntfs_volume *vol; + BOOL collapsible; + BOOL deleted; + BOOL done; + FILE_NAME_TYPE_FLAGS oldnametype; + u64 dnum; + u64 fnum; + int res; + + res = -1; + vol = ni->vol; + dnum = dir_ni->mft_no; + fnum = ni->mft_no; + /* save initial link count */ + linkcount = le16_to_cpu(ni->mrec->link_count); + + /* check whether the same name may be used as DOS and WIN32 */ + collapsible = ntfs_collapsible_chars(ni->vol, shortname, shortlen, + longname, longlen); + if (collapsible) { + deleted = FALSE; + done = FALSE; + if (existed) { + oldnametype = set_namespace(ni, dir_ni, deletename, + deletelen, FILE_NAME_POSIX); + if (oldnametype == FILE_NAME_DOS) { + if (set_namespace(ni, dir_ni, longname, longlen, + FILE_NAME_WIN32_AND_DOS) >= 0) { + if (!ntfs_delete(vol, + (const char*)NULL, ni, dir_ni, + deletename, deletelen)) + res = 0; + deleted = TRUE; + } else + done = TRUE; + } + } + if (!deleted) { + if (!done && (set_namespace(ni, dir_ni, + longname, longlen, + FILE_NAME_WIN32_AND_DOS) >= 0)) + res = 0; + ntfs_inode_update_times(ni, NTFS_UPDATE_CTIME); + ntfs_inode_update_times(dir_ni, NTFS_UPDATE_MCTIME); + if (ntfs_inode_close_in_dir(ni,dir_ni) && !res) + res = -1; + if (ntfs_inode_close(dir_ni) && !res) + res = -1; + } + } else { + if (!ntfs_link_i(ni, dir_ni, shortname, shortlen, + FILE_NAME_DOS) + /* make sure a new link was recorded */ + && (le16_to_cpu(ni->mrec->link_count) > linkcount)) { + /* delete the existing long name or short name */ +// is it ok to not provide the path ? + if (!ntfs_delete(vol, (char*)NULL, ni, dir_ni, + deletename, deletelen)) { + /* delete closes the inodes, so have to open again */ + dir_ni = ntfs_inode_open(vol, dnum); + if (dir_ni) { + ni = ntfs_inode_open(vol, fnum); + if (ni) { + if (!ntfs_link_i(ni, dir_ni, + longname, longlen, + FILE_NAME_WIN32)) + res = 0; + if (ntfs_inode_close_in_dir(ni, + dir_ni) + && !res) + res = -1; + } + if (ntfs_inode_close(dir_ni) && !res) + res = -1; + } + } + } else { + ntfs_inode_close_in_dir(ni,dir_ni); + ntfs_inode_close(dir_ni); + } + } + return (res); +} + + +/* + * Set the ntfs DOS name into an extended attribute + * + * The DOS name will be added as another file name attribute + * using the existing file name information from the original + * name or overwriting the DOS Name if one exists. + * + * The inode of the file is always closed + */ + +int ntfs_set_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, + const char *value, size_t size, int flags) +{ + int res = 0; + int longlen = 0; + int shortlen = 0; + char newname[MAX_DOS_NAME_LENGTH + 1]; + ntfschar oldname[MAX_DOS_NAME_LENGTH]; + int oldlen; + ntfs_volume *vol; + u64 fnum; + u64 dnum; + BOOL closed = FALSE; + ntfschar *shortname = NULL; + ntfschar longname[NTFS_MAX_NAME_LEN]; + + vol = ni->vol; + fnum = ni->mft_no; + /* convert the string to the NTFS wide chars */ + if (size > MAX_DOS_NAME_LENGTH) + size = MAX_DOS_NAME_LENGTH; + strncpy(newname, value, size); + newname[size] = 0; + shortlen = ntfs_mbstoucs(newname, &shortname); + /* make sure the short name has valid chars */ + if ((shortlen < 0) || ntfs_forbidden_chars(shortname,shortlen)) { + ntfs_inode_close_in_dir(ni,dir_ni); + ntfs_inode_close(dir_ni); + res = -errno; + return res; + } + dnum = dir_ni->mft_no; + longlen = get_long_name(ni, dnum, longname); + if (longlen > 0) { + oldlen = get_dos_name(ni, dnum, oldname); + if ((oldlen >= 0) + && !ntfs_forbidden_chars(longname, longlen)) { + if (oldlen > 0) { + if (flags & XATTR_CREATE) { + res = -1; + errno = EEXIST; + } else + if ((shortlen == oldlen) + && !memcmp(shortname,oldname, + oldlen*sizeof(ntfschar))) + /* already set, done */ + res = 0; + else { + res = set_dos_name(ni, dir_ni, + shortname, shortlen, + longname, longlen, + oldname, oldlen, TRUE); + closed = TRUE; + } + } else { + if (flags & XATTR_REPLACE) { + res = -1; + errno = ENODATA; + } else { + res = set_dos_name(ni, dir_ni, + shortname, shortlen, + longname, longlen, + longname, longlen, FALSE); + closed = TRUE; + } + } + } else + res = -1; + } else { + res = -1; + errno = ENOENT; + } + free(shortname); + if (!closed) { + ntfs_inode_close_in_dir(ni,dir_ni); + ntfs_inode_close(dir_ni); + } + return (res ? -1 : 0); +} + +/* + * Delete the ntfs DOS name + */ + +int ntfs_remove_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni) +{ + int res; + int oldnametype; + int longlen = 0; + int shortlen; + u64 dnum; + ntfs_volume *vol; + BOOL deleted = FALSE; + ntfschar shortname[MAX_DOS_NAME_LENGTH]; + ntfschar longname[NTFS_MAX_NAME_LEN]; + + res = -1; + vol = ni->vol; + dnum = dir_ni->mft_no; + longlen = get_long_name(ni, dnum, longname); + if (longlen > 0) { + shortlen = get_dos_name(ni, dnum, shortname); + if (shortlen >= 0) { + /* migrate the long name as Posix */ + oldnametype = set_namespace(ni,dir_ni,longname,longlen, + FILE_NAME_POSIX); + switch (oldnametype) { + case FILE_NAME_WIN32_AND_DOS : + /* name was Win32+DOS : done */ + res = 0; + break; + case FILE_NAME_DOS : + /* name was DOS, make it back to DOS */ + set_namespace(ni,dir_ni,longname,longlen, + FILE_NAME_DOS); + errno = ENOENT; + break; + case FILE_NAME_WIN32 : + /* name was Win32, make it Posix and delete */ + if (set_namespace(ni,dir_ni,shortname,shortlen, + FILE_NAME_POSIX) >= 0) { + if (!ntfs_delete(vol, + (const char*)NULL, ni, + dir_ni, shortname, + shortlen)) + res = 0; + deleted = TRUE; + } else { + /* + * DOS name has been found, but cannot + * migrate to Posix : something bad + * has happened + */ + errno = EIO; + ntfs_log_error("Could not change" + " DOS name of inode %lld to Posix\n", + (long long)ni->mft_no); + } + break; + default : + /* name was Posix or not found : error */ + errno = ENOENT; + break; + } + } + } else { + errno = ENOENT; + res = -1; + } + if (!deleted) { + ntfs_inode_close_in_dir(ni,dir_ni); + ntfs_inode_close(dir_ni); + } + return (res); +} + +#endif diff --git a/libcustomntfs/dir.h b/libcustomntfs/dir.h new file mode 100644 index 00000000..56e76fe7 --- /dev/null +++ b/libcustomntfs/dir.h @@ -0,0 +1,128 @@ +/* + * dir.h - Exports for directory handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002 Anton Altaparmakov + * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2005-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_DIR_H +#define _NTFS_DIR_H + +#include "types.h" + +#define PATH_SEP '/' + +/* + * We do not have these under DJGPP, so define our version that do not conflict + * with other S_IFs defined under DJGPP. + */ +#ifdef DJGPP +#ifndef S_IFLNK +#define S_IFLNK 0120000 +#endif +#ifndef S_ISLNK +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#endif +#ifndef S_IFSOCK +#define S_IFSOCK 0140000 +#endif +#ifndef S_ISSOCK +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +#endif +#endif + +/* + * The little endian Unicode strings $I30, $SII, $SDH, $O, $Q, $R + * as a global constant. + */ +extern ntfschar NTFS_INDEX_I30[5]; +extern ntfschar NTFS_INDEX_SII[5]; +extern ntfschar NTFS_INDEX_SDH[5]; +extern ntfschar NTFS_INDEX_O[3]; +extern ntfschar NTFS_INDEX_Q[3]; +extern ntfschar NTFS_INDEX_R[3]; + +extern u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, + const ntfschar *uname, const int uname_len); +extern u64 ntfs_inode_lookup_by_mbsname(ntfs_inode *dir_ni, const char *name); +extern void ntfs_inode_update_mbsname(ntfs_inode *dir_ni, const char *name, + u64 inum); + +extern ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, + const char *pathname); +extern ntfs_inode *ntfs_create(ntfs_inode *dir_ni, le32 securid, + ntfschar *name, u8 name_len, mode_t type); +extern ntfs_inode *ntfs_create_device(ntfs_inode *dir_ni, le32 securid, + ntfschar *name, u8 name_len, mode_t type, dev_t dev); +extern ntfs_inode *ntfs_create_symlink(ntfs_inode *dir_ni, le32 securid, + ntfschar *name, u8 name_len, ntfschar *target, int target_len); +extern int ntfs_check_empty_dir(ntfs_inode *ni); +extern int ntfs_delete(ntfs_volume *vol, const char *path, + ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, + u8 name_len); + +extern int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, + u8 name_len); + +/* + * File types (adapted from include ) + */ +#define NTFS_DT_UNKNOWN 0 +#define NTFS_DT_FIFO 1 +#define NTFS_DT_CHR 2 +#define NTFS_DT_DIR 4 +#define NTFS_DT_BLK 6 +#define NTFS_DT_REG 8 +#define NTFS_DT_LNK 10 +#define NTFS_DT_SOCK 12 +#define NTFS_DT_WHT 14 + +/* + * This is the "ntfs_filldir" function type, used by ntfs_readdir() to let + * the caller specify what kind of dirent layout it wants to have. + * This allows the caller to read directories into their application or + * to have different dirent layouts depending on the binary type. + */ +typedef int (*ntfs_filldir_t)(void *dirent, const ntfschar *name, + const int name_len, const int name_type, const s64 pos, + const MFT_REF mref, const unsigned dt_type); + +extern int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, + void *dirent, ntfs_filldir_t filldir); + +ntfs_inode *ntfs_dir_parent_inode(ntfs_inode *ni); + +int ntfs_get_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, + char *value, size_t size); +int ntfs_set_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni, + const char *value, size_t size, int flags); +int ntfs_remove_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni); + +#if CACHE_INODE_SIZE + +struct CACHED_GENERIC; + +extern int ntfs_dir_inode_hash(const struct CACHED_GENERIC *cached); +extern int ntfs_dir_lookup_hash(const struct CACHED_GENERIC *cached); + +#endif + +#endif /* defined _NTFS_DIR_H */ + diff --git a/libcustomntfs/efs.c b/libcustomntfs/efs.c new file mode 100644 index 00000000..6ccec20a --- /dev/null +++ b/libcustomntfs/efs.c @@ -0,0 +1,439 @@ +/** + * efs.c - Limited processing of encrypted files + * + * This module is part of ntfs-3g library + * + * Copyright (c) 2009 Martin Bene + * Copyright (c) 2009-2010 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_SETXATTR +#include +#endif + +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif + +#include "types.h" +#include "debug.h" +#include "attrib.h" +#include "inode.h" +#include "dir.h" +#include "efs.h" +#include "index.h" +#include "logging.h" +#include "misc.h" +#include "efs.h" + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +static ntfschar logged_utility_stream_name[] = { + const_cpu_to_le16('$'), + const_cpu_to_le16('E'), + const_cpu_to_le16('F'), + const_cpu_to_le16('S'), + const_cpu_to_le16(0) +} ; + + +/* + * Get the ntfs EFS info into an extended attribute + */ + +int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size) +{ + EFS_ATTR_HEADER *efs_info; + s64 attr_size = 0; + + if (ni) { + if (ni->flags & FILE_ATTR_ENCRYPTED) { + efs_info = (EFS_ATTR_HEADER*)ntfs_attr_readall(ni, + AT_LOGGED_UTILITY_STREAM,(ntfschar*)NULL, 0, + &attr_size); + if (efs_info + && (le32_to_cpu(efs_info->length) == attr_size)) { + if (attr_size <= (s64)size) { + if (value) + memcpy(value,efs_info,attr_size); + else { + errno = EFAULT; + attr_size = 0; + } + } else + if (size) { + errno = ERANGE; + attr_size = 0; + } + free (efs_info); + } else { + if (efs_info) { + free(efs_info); + ntfs_log_error("Bad efs_info for inode %lld\n", + (long long)ni->mft_no); + } else { + ntfs_log_error("Could not get efsinfo" + " for inode %lld\n", + (long long)ni->mft_no); + } + errno = EIO; + attr_size = 0; + } + } else { + errno = ENODATA; + ntfs_log_trace("Inode %lld is not encrypted\n", + (long long)ni->mft_no); + } + } + return (attr_size ? (int)attr_size : -errno); +} + +/* + * Fix all encrypted AT_DATA attributes of an inode + * + * The fix may require making an attribute non resident, which + * requires more space in the MFT record, and may cause some + * attribute to be expelled and the full record to be reorganized. + * When this happens, the search for data attributes has to be + * reinitialized. + * + * Returns zero if successful. + * -1 if there is a problem. + */ + +static int fixup_loop(ntfs_inode *ni) +{ + ntfs_attr_search_ctx *ctx; + ntfs_attr *na; + ATTR_RECORD *a; + BOOL restart; + BOOL first; + int cnt; + int maxcnt; + int res = 0; + + maxcnt = 0; + do { + restart = FALSE; + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) { + ntfs_log_error("Failed to get ctx for efs\n"); + res = -1; + } + cnt = 0; + while (!restart && !res + && !ntfs_attr_lookup(AT_DATA, NULL, 0, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + cnt++; + a = ctx->attr; + na = ntfs_attr_open(ctx->ntfs_ino, AT_DATA, + (ntfschar*)((u8*)a + le16_to_cpu(a->name_offset)), + a->name_length); + if (!na) { + ntfs_log_error("can't open DATA Attribute\n"); + res = -1; + } + if (na && !(ctx->attr->flags & ATTR_IS_ENCRYPTED)) { + if (!NAttrNonResident(na) + && ntfs_attr_make_non_resident(na, ctx)) { + /* + * ntfs_attr_make_non_resident fails if there + * is not enough space in the MFT record. + * When this happens, force making non-resident + * so that some other attribute is expelled. + */ + if (ntfs_attr_force_non_resident(na)) { + res = -1; + } else { + /* make sure there is some progress */ + if (cnt <= maxcnt) { + errno = EIO; + ntfs_log_error("Multiple failure" + " making non resident\n"); + res = -1; + } else { + ntfs_attr_put_search_ctx(ctx); + ctx = (ntfs_attr_search_ctx*)NULL; + restart = TRUE; + maxcnt = cnt; + } + } + } + if (!restart && !res + && ntfs_efs_fixup_attribute(ctx, na)) { + ntfs_log_error("Error in efs fixup of AT_DATA Attribute\n"); + res = -1; + } + } + if (na) + ntfs_attr_close(na); + } + first = FALSE; + } while (restart && !res); + if (ctx) + ntfs_attr_put_search_ctx(ctx); + return (res); +} + +/* + * Set the efs data from an extended attribute + * Warning : the new data is not checked + * Returns 0, or -1 if there is a problem + */ + +int ntfs_set_efs_info(ntfs_inode *ni, const char *value, size_t size, + int flags) + +{ + int res; + int written; + ntfs_attr *na; + const EFS_ATTR_HEADER *info_header; + + res = 0; + if (ni && value && size) { + if (ni->flags & (FILE_ATTR_ENCRYPTED | FILE_ATTR_COMPRESSED)) { + if (ni->flags & FILE_ATTR_ENCRYPTED) { + ntfs_log_trace("Inode %lld already encrypted\n", + (long long)ni->mft_no); + errno = EEXIST; + } else { + /* + * Possible problem : if encrypted file was + * restored in a compressed directory, it was + * restored as compressed. + * TODO : decompress first. + */ + ntfs_log_error("Inode %lld cannot be encrypted and compressed\n", + (long long)ni->mft_no); + errno = EIO; + } + return -1; + } + info_header = (const EFS_ATTR_HEADER*)value; + /* make sure we get a likely efsinfo */ + if (le32_to_cpu(info_header->length) != size) { + errno = EINVAL; + return (-1); + } + if (!ntfs_attr_exist(ni,AT_LOGGED_UTILITY_STREAM, + (ntfschar*)NULL,0)) { + if (!(flags & XATTR_REPLACE)) { + /* + * no logged_utility_stream attribute : add one, + * apparently, this does not feed the new value in + */ + res = ntfs_attr_add(ni,AT_LOGGED_UTILITY_STREAM, + logged_utility_stream_name,4, + (u8*)NULL,(s64)size); + } else { + errno = ENODATA; + res = -1; + } + } else { + errno = EEXIST; + res = -1; + } + if (!res) { + /* + * open and update the existing efs data + */ + na = ntfs_attr_open(ni, AT_LOGGED_UTILITY_STREAM, + logged_utility_stream_name, 4); + if (na) { + /* resize attribute */ + res = ntfs_attr_truncate(na, (s64)size); + /* overwrite value if any */ + if (!res && value) { + written = (int)ntfs_attr_pwrite(na, + (s64)0, (s64)size, value); + if (written != (s64)size) { + ntfs_log_error("Failed to " + "update efs data\n"); + errno = EIO; + res = -1; + } + } + ntfs_attr_close(na); + } else + res = -1; + } + if (!res) { + /* Don't handle AT_DATA Attribute(s) if inode is a directory */ + if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { + /* iterate over AT_DATA attributes */ + /* set encrypted flag, truncate attribute to match padding bytes */ + + if (fixup_loop(ni)) + return -1; + } + ni->flags |= FILE_ATTR_ENCRYPTED; + NInoSetDirty(ni); + NInoFileNameSetDirty(ni); + } + } else { + errno = EINVAL; + res = -1; + } + return (res ? -1 : 0); +} + +/* + * Fixup raw encrypted AT_DATA Attribute + * read padding length from last two bytes + * truncate attribute, make non-resident, + * set data size to match padding length + * set ATTR_IS_ENCRYPTED flag on attribute + * + * Return 0 if successful + * -1 if failed (errno tells why) + */ + +int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na) +{ + u64 newsize; + u64 oldsize; + le16 appended_bytes; + u16 padding_length; + ntfs_inode *ni; + BOOL close_ctx = FALSE; + + if (!na) { + ntfs_log_error("no na specified for efs_fixup_attribute\n"); + goto err_out; + } + if (!ctx) { + ctx = ntfs_attr_get_search_ctx(na->ni, NULL); + if (!ctx) { + ntfs_log_error("Failed to get ctx for efs\n"); + goto err_out; + } + close_ctx = TRUE; + if (ntfs_attr_lookup(AT_DATA, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + ntfs_log_error("attr lookup for AT_DATA attribute failed in efs fixup\n"); + goto err_out; + } + } else { + if (!NAttrNonResident(na)) { + ntfs_log_error("Cannot make non resident" + " when a context has been allocated\n"); + goto err_out; + } + } + + /* no extra bytes are added to void attributes */ + oldsize = na->data_size; + if (oldsize) { + /* make sure size is valid for a raw encrypted stream */ + if ((oldsize & 511) != 2) { + ntfs_log_error("Bad raw encrypted stream\n"); + goto err_out; + } + /* read padding length from last two bytes of attribute */ + if (ntfs_attr_pread(na, oldsize - 2, 2, &appended_bytes) != 2) { + ntfs_log_error("Error reading padding length\n"); + goto err_out; + } + padding_length = le16_to_cpu(appended_bytes); + if (padding_length > 511 || padding_length > na->data_size-2) { + errno = EINVAL; + ntfs_log_error("invalid padding length %d for data_size %lld\n", + padding_length, (long long)oldsize); + goto err_out; + } + newsize = oldsize - padding_length - 2; + /* + * truncate attribute to possibly free clusters allocated + * for the last two bytes, but do not truncate to new size + * to avoid losing useful data + */ + if (ntfs_attr_truncate(na, oldsize - 2)) { + ntfs_log_error("Error truncating attribute\n"); + goto err_out; + } + } else + newsize = 0; + + /* + * Encrypted AT_DATA Attributes MUST be non-resident + * This has to be done after the attribute is resized, as + * resizing down to zero may cause the attribute to be made + * resident. + */ + if (!NAttrNonResident(na) + && ntfs_attr_make_non_resident(na, ctx)) { + if (!close_ctx + || ntfs_attr_force_non_resident(na)) { + ntfs_log_error("Error making DATA attribute non-resident\n"); + goto err_out; + } else { + /* + * must reinitialize context after forcing + * non-resident. We need a context for updating + * the state, and at this point, we are sure + * the context is not used elsewhere. + */ + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(AT_DATA, na->name, na->name_len, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + ntfs_log_error("attr lookup for AT_DATA attribute failed in efs fixup\n"); + goto err_out; + } + } + } + ni = na->ni; + if (!na->name_len) { + ni->data_size = newsize; + ni->allocated_size = na->allocated_size; + } + NInoSetDirty(ni); + NInoFileNameSetDirty(ni); + + ctx->attr->data_size = cpu_to_le64(newsize); + if (le64_to_cpu(ctx->attr->initialized_size) > newsize) + ctx->attr->initialized_size = ctx->attr->data_size; + ctx->attr->flags |= ATTR_IS_ENCRYPTED; + if (close_ctx) + ntfs_attr_put_search_ctx(ctx); + + return (0); +err_out: + if (close_ctx && ctx) + ntfs_attr_put_search_ctx(ctx); + return (-1); +} + +#endif /* HAVE_SETXATTR */ diff --git a/libcustomntfs/efs.h b/libcustomntfs/efs.h new file mode 100644 index 00000000..6eada067 --- /dev/null +++ b/libcustomntfs/efs.h @@ -0,0 +1,30 @@ +/* + * + * Copyright (c) 2009 Martin Bene + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef EFS_H +#define EFS_H + +int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size); + +int ntfs_set_efs_info(ntfs_inode *ni, + const char *value, size_t size, int flags); +int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na); + +#endif /* EFS_H */ diff --git a/libcustomntfs/endians.h b/libcustomntfs/endians.h new file mode 100644 index 00000000..397f1c20 --- /dev/null +++ b/libcustomntfs/endians.h @@ -0,0 +1,203 @@ +/* + * endians.h - Definitions related to handling of byte ordering. + * Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2005 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_ENDIANS_H +#define _NTFS_ENDIANS_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* + * Notes: + * We define the conversion functions including typecasts since the + * defaults don't necessarily perform appropriate typecasts. + * Also, using our own functions means that we can change them if it + * turns out that we do need to use the unaligned access macros on + * architectures requiring aligned memory accesses... + */ + +#ifdef HAVE_ENDIAN_H +#include +#endif +#ifdef HAVE_SYS_ENDIAN_H +#include +#endif +#ifdef HAVE_MACHINE_ENDIAN_H +#include +#endif +#ifdef HAVE_SYS_BYTEORDER_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifndef __BYTE_ORDER +# if defined(_BYTE_ORDER) +# define __BYTE_ORDER _BYTE_ORDER +# define __LITTLE_ENDIAN _LITTLE_ENDIAN +# define __BIG_ENDIAN _BIG_ENDIAN +# elif defined(BYTE_ORDER) +# define __BYTE_ORDER BYTE_ORDER +# define __LITTLE_ENDIAN LITTLE_ENDIAN +# define __BIG_ENDIAN BIG_ENDIAN +# elif defined(__BYTE_ORDER__) +# define __BYTE_ORDER __BYTE_ORDER__ +# define __LITTLE_ENDIAN __LITTLE_ENDIAN__ +# define __BIG_ENDIAN __BIG_ENDIAN__ +# elif (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || \ + defined(WORDS_LITTLEENDIAN) +# define __BYTE_ORDER 1 +# define __LITTLE_ENDIAN 1 +# define __BIG_ENDIAN 0 +# elif (!defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)) || \ + defined(WORDS_BIGENDIAN) +# define __BYTE_ORDER 0 +# define __LITTLE_ENDIAN 1 +# define __BIG_ENDIAN 0 +# else +# error "__BYTE_ORDER is not defined." +# endif +#endif + +#define __ntfs_bswap_constant_16(x) \ + (u16)((((u16)(x) & 0xff00) >> 8) | \ + (((u16)(x) & 0x00ff) << 8)) + +#define __ntfs_bswap_constant_32(x) \ + (u32)((((u32)(x) & 0xff000000u) >> 24) | \ + (((u32)(x) & 0x00ff0000u) >> 8) | \ + (((u32)(x) & 0x0000ff00u) << 8) | \ + (((u32)(x) & 0x000000ffu) << 24)) + +#define __ntfs_bswap_constant_64(x) \ + (u64)((((u64)(x) & 0xff00000000000000ull) >> 56) | \ + (((u64)(x) & 0x00ff000000000000ull) >> 40) | \ + (((u64)(x) & 0x0000ff0000000000ull) >> 24) | \ + (((u64)(x) & 0x000000ff00000000ull) >> 8) | \ + (((u64)(x) & 0x00000000ff000000ull) << 8) | \ + (((u64)(x) & 0x0000000000ff0000ull) << 24) | \ + (((u64)(x) & 0x000000000000ff00ull) << 40) | \ + (((u64)(x) & 0x00000000000000ffull) << 56)) + +#ifdef HAVE_BYTESWAP_H +# include +#else +# define bswap_16(x) __ntfs_bswap_constant_16(x) +# define bswap_32(x) __ntfs_bswap_constant_32(x) +# define bswap_64(x) __ntfs_bswap_constant_64(x) +#endif + +#if defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) + +#define __le16_to_cpu(x) (x) +#define __le32_to_cpu(x) (x) +#define __le64_to_cpu(x) (x) + +#define __cpu_to_le16(x) (x) +#define __cpu_to_le32(x) (x) +#define __cpu_to_le64(x) (x) + +#define __constant_le16_to_cpu(x) (x) +#define __constant_le32_to_cpu(x) (x) +#define __constant_le64_to_cpu(x) (x) + +#define __constant_cpu_to_le16(x) (x) +#define __constant_cpu_to_le32(x) (x) +#define __constant_cpu_to_le64(x) (x) + +#elif defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) + +#define __le16_to_cpu(x) bswap_16(x) +#define __le32_to_cpu(x) bswap_32(x) +#define __le64_to_cpu(x) bswap_64(x) + +#define __cpu_to_le16(x) bswap_16(x) +#define __cpu_to_le32(x) bswap_32(x) +#define __cpu_to_le64(x) bswap_64(x) + +#define __constant_le16_to_cpu(x) __ntfs_bswap_constant_16((u16)(x)) +#define __constant_le32_to_cpu(x) __ntfs_bswap_constant_32((u32)(x)) +#define __constant_le64_to_cpu(x) __ntfs_bswap_constant_64((u64)(x)) + +#define __constant_cpu_to_le16(x) __ntfs_bswap_constant_16((u16)(x)) +#define __constant_cpu_to_le32(x) __ntfs_bswap_constant_32((u32)(x)) +#define __constant_cpu_to_le64(x) __ntfs_bswap_constant_64((u64)(x)) + +#else + +#error "You must define __BYTE_ORDER to be __LITTLE_ENDIAN or __BIG_ENDIAN." + +#endif + +/* Unsigned from LE to CPU conversion. */ + +#define le16_to_cpu(x) (u16)__le16_to_cpu((u16)(x)) +#define le32_to_cpu(x) (u32)__le32_to_cpu((u32)(x)) +#define le64_to_cpu(x) (u64)__le64_to_cpu((u64)(x)) + +#define le16_to_cpup(x) (u16)__le16_to_cpu(*(const u16*)(x)) +#define le32_to_cpup(x) (u32)__le32_to_cpu(*(const u32*)(x)) +#define le64_to_cpup(x) (u64)__le64_to_cpu(*(const u64*)(x)) + +/* Signed from LE to CPU conversion. */ + +#define sle16_to_cpu(x) (s16)__le16_to_cpu((s16)(x)) +#define sle32_to_cpu(x) (s32)__le32_to_cpu((s32)(x)) +#define sle64_to_cpu(x) (s64)__le64_to_cpu((s64)(x)) + +#define sle16_to_cpup(x) (s16)__le16_to_cpu(*(s16*)(x)) +#define sle32_to_cpup(x) (s32)__le32_to_cpu(*(s32*)(x)) +#define sle64_to_cpup(x) (s64)__le64_to_cpu(*(s64*)(x)) + +/* Unsigned from CPU to LE conversion. */ + +#define cpu_to_le16(x) (u16)__cpu_to_le16((u16)(x)) +#define cpu_to_le32(x) (u32)__cpu_to_le32((u32)(x)) +#define cpu_to_le64(x) (u64)__cpu_to_le64((u64)(x)) + +#define cpu_to_le16p(x) (u16)__cpu_to_le16(*(u16*)(x)) +#define cpu_to_le32p(x) (u32)__cpu_to_le32(*(u32*)(x)) +#define cpu_to_le64p(x) (u64)__cpu_to_le64(*(u64*)(x)) + +/* Signed from CPU to LE conversion. */ + +#define cpu_to_sle16(x) (s16)__cpu_to_le16((s16)(x)) +#define cpu_to_sle32(x) (s32)__cpu_to_le32((s32)(x)) +#define cpu_to_sle64(x) (s64)__cpu_to_le64((s64)(x)) + +#define cpu_to_sle16p(x) (s16)__cpu_to_le16(*(s16*)(x)) +#define cpu_to_sle32p(x) (s32)__cpu_to_le32(*(s32*)(x)) +#define cpu_to_sle64p(x) (s64)__cpu_to_le64(*(s64*)(x)) + +/* Constant endianness conversion defines. */ + +#define const_le16_to_cpu(x) __constant_le16_to_cpu(x) +#define const_le32_to_cpu(x) __constant_le32_to_cpu(x) +#define const_le64_to_cpu(x) __constant_le64_to_cpu(x) + +#define const_cpu_to_le16(x) __constant_cpu_to_le16(x) +#define const_cpu_to_le32(x) __constant_cpu_to_le32(x) +#define const_cpu_to_le64(x) __constant_cpu_to_le64(x) + +#endif /* defined _NTFS_ENDIANS_H */ diff --git a/libcustomntfs/gekko_io.c b/libcustomntfs/gekko_io.c new file mode 100644 index 00000000..48ca90d4 --- /dev/null +++ b/libcustomntfs/gekko_io.c @@ -0,0 +1,647 @@ +/** + * gekko_io.c - Gekko style disk io functions. + * + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * Copyright (c) 2010 Dimok + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_MATH_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_LOCALE_H +#include +#endif + +#include "ntfs.h" +#include "types.h" +#include "logging.h" +#include "device_io.h" +#include "gekko_io.h" +#include "cache.h" +#include "device.h" +#include "bootsect.h" + +#define DEV_FD(dev) ((gekko_fd *)dev->d_private) + +/* Prototypes */ +static s64 ntfs_device_gekko_io_readbytes(struct ntfs_device *dev, s64 offset, s64 count, void *buf); +static bool ntfs_device_gekko_io_readsectors(struct ntfs_device *dev, sec_t sector, sec_t numSectors, void* buffer); +static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset, s64 count, const void *buf); +static bool ntfs_device_gekko_io_writesectors(struct ntfs_device *dev, sec_t sector, sec_t numSectors, const void* buffer); + +/** + * + */ +static int ntfs_device_gekko_io_open(struct ntfs_device *dev, int flags) +{ + ntfs_log_trace("dev %p, flags %i\n", dev, flags); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Get the device interface + const DISC_INTERFACE* interface = fd->interface; + if (!interface) { + errno = ENODEV; + return -1; + } + + // Start the device interface and ensure that it is inserted + if (!interface->startup()) { + ntfs_log_perror("device failed to start\n"); + errno = EIO; + return -1; + } + if (!interface->isInserted()) { + ntfs_log_perror("device media is not inserted\n"); + errno = EIO; + return -1; + } + + // Check that the device isn't already open (used by another volume?) + if (NDevOpen(dev)) { + ntfs_log_perror("device is busy (already open)\n"); + errno = EBUSY; + return -1; + } + + // Check that there is a valid NTFS boot sector at the start of the device + NTFS_BOOT_SECTOR boot; + if (interface->readSectors(fd->startSector, 1, &boot)) { + if (!ntfs_boot_sector_is_ntfs(&boot)) { + errno = EINVALPART; + return -1; + } + } else { + ntfs_log_perror("read failure @ sector %d\n", fd->startSector); + errno = EIO; + return -1; + } + + // Parse the boot sector + fd->hiddenSectors = le32_to_cpu(boot.bpb.hidden_sectors); + fd->sectorSize = le16_to_cpu(boot.bpb.bytes_per_sector); + fd->sectorCount = sle64_to_cpu(boot.number_of_sectors); + fd->pos = 0; + fd->len = (fd->sectorCount * fd->sectorSize); + fd->ino = le64_to_cpu(boot.volume_serial_number); + + // Mark the device as read-only (if required) + if (flags & O_RDONLY) { + NDevSetReadOnly(dev); + } + + // Create the cache + fd->cache = _NTFS_cache_constructor(fd->cachePageCount, fd->cachePageSize, interface, fd->startSector + fd->sectorCount, fd->sectorSize); + + // Mark the device as open + NDevSetBlock(dev); + NDevSetOpen(dev); + + return 0; +} + +/** + * + */ +static int ntfs_device_gekko_io_close(struct ntfs_device *dev) +{ + ntfs_log_trace("dev %p\n", dev); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Check that the device is actually open + if (!NDevOpen(dev)) { + ntfs_log_perror("device is not open\n"); + errno = EIO; + return -1; + } + + // Mark the device as closed + NDevClearOpen(dev); + NDevClearBlock(dev); + + // Flush the device (if dirty and not read-only) + if (NDevDirty(dev) && !NDevReadOnly(dev)) { + ntfs_log_debug("device is dirty, will now sync\n"); + + // ...? + + // Mark the device as clean + NDevClearDirty(dev); + + } + + // Flush and destroy the cache (if required) + if (fd->cache) { + _NTFS_cache_flush(fd->cache); + _NTFS_cache_destructor(fd->cache); + } + + // Shutdown the device interface + /*const DISC_INTERFACE* interface = fd->interface; + if (interface) { + interface->shutdown(); + }*/ + + // Free the device driver private data + ntfs_free(dev->d_private); + dev->d_private = NULL; + + return 0; +} + +/** + * + */ +static s64 ntfs_device_gekko_io_seek(struct ntfs_device *dev, s64 offset, int whence) +{ + ntfs_log_trace("dev %p, offset %Li, whence %i\n", dev, offset, whence); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Set the current position on the device (in bytes) + switch(whence) { + case SEEK_SET: fd->pos = MIN(MAX(offset, 0), fd->len); break; + case SEEK_CUR: fd->pos = MIN(MAX(fd->pos + offset, 0), fd->len); break; + case SEEK_END: fd->pos = MIN(MAX(fd->len + offset, 0), fd->len); break; + } + + return 0; +} + +/** + * + */ +static s64 ntfs_device_gekko_io_read(struct ntfs_device *dev, void *buf, s64 count) +{ + return ntfs_device_gekko_io_readbytes(dev, DEV_FD(dev)->pos, count, buf); +} + +/** + * + */ +static s64 ntfs_device_gekko_io_write(struct ntfs_device *dev, const void *buf, s64 count) +{ + return ntfs_device_gekko_io_writebytes(dev, DEV_FD(dev)->pos, count, buf); +} + +/** + * + */ +static s64 ntfs_device_gekko_io_pread(struct ntfs_device *dev, void *buf, s64 count, s64 offset) +{ + return ntfs_device_gekko_io_readbytes(dev, offset, count, buf); +} + +/** + * + */ +static s64 ntfs_device_gekko_io_pwrite(struct ntfs_device *dev, const void *buf, s64 count, s64 offset) +{ + return ntfs_device_gekko_io_writebytes(dev, offset, count, 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); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Get the device interface + const DISC_INTERFACE* interface = fd->interface; + if (!interface) { + errno = ENODEV; + return -1; + } + + if(offset < 0) + { + errno = EROFS; + return -1; + } + + if(!count) + return 0; + + sec_t sec_start = (sec_t) fd->startSector; + sec_t sec_count = 1; + u32 buffer_offset = (u32) (offset % fd->sectorSize); + u8 *buffer = NULL; + + // Determine the range of sectors required for this read + if (offset > 0) { + sec_start += (sec_t) floor((f64) offset / (f64) fd->sectorSize); + } + if (buffer_offset+count > fd->sectorSize) { + sec_count = (sec_t) ceil((f64) (buffer_offset+count) / (f64) fd->sectorSize); + } + + // If this read happens to be on the sector boundaries then do the read straight into the destination buffer + + if((buffer_offset == 0) && (count % fd->sectorSize == 0)) { + + // Read from the device + ntfs_log_trace("direct read from sector %d (%d sector(s) long)\n", sec_start, sec_count); + if (!ntfs_device_gekko_io_readsectors(dev, sec_start, sec_count, buf)) { + ntfs_log_perror("direct read failure @ sector %d (%d sector(s) long)\n", sec_start, sec_count); + errno = EIO; + return -1; + } + + // Else read into a buffer and copy over only what was requested + } + else + { + + // Allocate a buffer to hold the read data + buffer = (u8*)ntfs_alloc(sec_count * fd->sectorSize); + if (!buffer) { + errno = ENOMEM; + return -1; + } + + // Read from the device + ntfs_log_trace("buffered read from sector %d (%d sector(s) long)\n", sec_start, sec_count); + ntfs_log_trace("count: %d sec_count:%d fd->sectorSize: %d )\n", (u32)count, (u32)sec_count,(u32)fd->sectorSize); + if (!ntfs_device_gekko_io_readsectors(dev, sec_start, sec_count, buffer)) { + ntfs_log_perror("buffered read failure @ sector %d (%d sector(s) long)\n", sec_start, sec_count); + ntfs_free(buffer); + errno = EIO; + return -1; + } + + // Copy what was requested to the destination buffer + memcpy(buf, buffer + buffer_offset, count); + ntfs_free(buffer); + + } + + return count; +} + +/** + * + */ +static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset, s64 count, const void *buf) +{ + ntfs_log_trace("dev %p, offset %lli, count %lli\n", dev, offset, count); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Get the device interface + const DISC_INTERFACE* interface = fd->interface; + if (!interface) { + errno = ENODEV; + return -1; + } + + // Check that the device can be written to + if (NDevReadOnly(dev)) { + errno = EROFS; + return -1; + } + + if(count < 0 || offset < 0) { + errno = EROFS; + return -1; + } + + if(count == 0) + return 0; + + sec_t sec_start = (sec_t) fd->startSector; + sec_t sec_count = 1; + u32 buffer_offset = (u32) (offset % fd->sectorSize); + u8 *buffer = NULL; + + // Determine the range of sectors required for this write + if (offset > 0) { + sec_start += (sec_t) floor((f64) offset / (f64) fd->sectorSize); + } + if ((buffer_offset+count) > fd->sectorSize) { + sec_count = (sec_t) ceil((f64) (buffer_offset+count) / (f64) fd->sectorSize); + } + + // If this write happens to be on the sector boundaries then do the write straight to disc + if((buffer_offset == 0) && (count % fd->sectorSize == 0)) + { + // Write to the device + ntfs_log_trace("direct write to sector %d (%d sector(s) long)\n", sec_start, sec_count); + if (!ntfs_device_gekko_io_writesectors(dev, sec_start, sec_count, buf)) { + ntfs_log_perror("direct write failure @ sector %d (%d sector(s) long)\n", sec_start, sec_count); + errno = EIO; + return -1; + } + // Else write from a buffer aligned to the sector boundaries + } + else + { + // Allocate a buffer to hold the write data + buffer = (u8 *) ntfs_alloc(sec_count * fd->sectorSize); + if (!buffer) { + errno = ENOMEM; + return -1; + } + // Read the first and last sectors of the buffer from disc (if required) + // NOTE: This is done because the data does not line up with the sector boundaries, + // we just read in the buffer edges where the data overlaps with the rest of the disc + if(buffer_offset != 0) + { + if (!ntfs_device_gekko_io_readsectors(dev, sec_start, 1, buffer)) { + ntfs_log_perror("read failure @ sector %d\n", sec_start); + ntfs_free(buffer); + errno = EIO; + return -1; + } + } + if((buffer_offset+count) % fd->sectorSize != 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 - 1); + ntfs_free(buffer); + errno = EIO; + return -1; + } + } + + // Copy the data into the write buffer + memcpy(buffer + buffer_offset, buf, count); + + // Write to the device + ntfs_log_trace("buffered write to sector %d (%d sector(s) long)\n", sec_start, sec_count); + if (!ntfs_device_gekko_io_writesectors(dev, sec_start, sec_count, buffer)) { + ntfs_log_perror("buffered write failure @ sector %d\n", sec_start); + ntfs_free(buffer); + errno = EIO; + return -1; + } + + // Free the buffer + ntfs_free(buffer); + } + + // Mark the device as dirty (if we actually wrote anything) + NDevSetDirty(dev); + + return count; +} + +static bool ntfs_device_gekko_io_readsectors(struct ntfs_device *dev, sec_t sector, sec_t numSectors, void* buffer) +{ + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return false; + } + // Read the sectors from disc (or cache, if enabled) + if (fd->cache) + return _NTFS_cache_readSectors(fd->cache, sector, numSectors, buffer); + else + return fd->interface->readSectors(sector, numSectors, buffer); + + return false; +} + +static bool ntfs_device_gekko_io_writesectors(struct ntfs_device *dev, sec_t sector, sec_t numSectors, const void* buffer) +{ + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return false; + } + + // Write the sectors to disc (or cache, if enabled) + if (fd->cache) + return _NTFS_cache_writeSectors(fd->cache, sector, numSectors, buffer); + else + return fd->interface->writeSectors(sector, numSectors, buffer); + + return false; +} + +/** + * + */ +static int ntfs_device_gekko_io_sync(struct ntfs_device *dev) +{ + gekko_fd *fd = DEV_FD(dev); + ntfs_log_trace("dev %p\n", dev); + + // Check that the device can be written to + if (NDevReadOnly(dev)) { + errno = EROFS; + return -1; + } + + // Mark the device as clean + NDevClearDirty(dev); + + // Flush any sectors in the disc cache (if required) + if (fd->cache) { + if (!_NTFS_cache_flush(fd->cache)) { + errno = EIO; + return -1; + } + } + + return 0; +} + +/** + * + */ +static int ntfs_device_gekko_io_stat(struct ntfs_device *dev, struct stat *buf) +{ + ntfs_log_trace("dev %p, buf %p\n", dev, buf); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Short circuit cases were we don't actually have to do anything + if (!buf) + return 0; + + // Build the device mode + mode_t mode = (S_IFBLK) | + (S_IRUSR | S_IRGRP | S_IROTH) | + ((!NDevReadOnly(dev)) ? (S_IWUSR | S_IWGRP | S_IWOTH) : 0); + + // Zero out the stat buffer + memset(buf, 0, sizeof(struct stat)); + + // Build the device stats + buf->st_dev = fd->interface->ioType; + buf->st_ino = fd->ino; + buf->st_mode = mode; + buf->st_rdev = fd->interface->ioType; + buf->st_blksize = fd->sectorSize; + buf->st_blocks = fd->sectorCount; + + return 0; +} + +/** + * + */ +static int ntfs_device_gekko_io_ioctl(struct ntfs_device *dev, int request, void *argp) +{ + ntfs_log_trace("dev %p, request %i, argp %p\n", dev, request, argp); + + // Get the device driver descriptor + gekko_fd *fd = DEV_FD(dev); + if (!fd) { + errno = EBADF; + return -1; + } + + // Figure out which i/o control was requested + switch (request) { + + // Get block device size (sectors) + #if defined(BLKGETSIZE) + case BLKGETSIZE: { + *(u32*)argp = fd->sectorCount; + return 0; + } + #endif + + // Get block device size (bytes) + #if defined(BLKGETSIZE64) + case BLKGETSIZE64: { + *(u64*)argp = (fd->sectorCount * fd->sectorSize); + return 0; + } + #endif + + // Get hard drive geometry + #if defined(HDIO_GETGEO) + case HDIO_GETGEO: { + struct hd_geometry *geo = (struct hd_geometry*)argp; + geo->sectors = 0; + geo->heads = 0; + geo->cylinders = 0; + geo->start = fd->hiddenSectors; + return -1; + } + #endif + + // Get block device sector size (bytes) + #if defined(BLKSSZGET) + case BLKSSZGET: { + *(int*)argp = fd->sectorSize; + return 0; + } + #endif + + // Set block device block size (bytes) + #if defined(BLKBSZSET) + case BLKBSZSET: { + int sectorSize = *(int*)argp; + fd->sectorSize = sectorSize; + return 0; + } + #endif + + // Unimplemented ioctrl + default: { + ntfs_log_perror("Unimplemented ioctrl %i\n", request); + errno = EOPNOTSUPP; + return -1; + } + + } + + return 0; +} + +/** + * Device operations for working with gekko style devices and files. + */ +struct ntfs_device_operations ntfs_device_gekko_io_ops = { + .open = ntfs_device_gekko_io_open, + .close = ntfs_device_gekko_io_close, + .seek = ntfs_device_gekko_io_seek, + .read = ntfs_device_gekko_io_read, + .write = ntfs_device_gekko_io_write, + .pread = ntfs_device_gekko_io_pread, + .pwrite = ntfs_device_gekko_io_pwrite, + .sync = ntfs_device_gekko_io_sync, + .stat = ntfs_device_gekko_io_stat, + .ioctl = ntfs_device_gekko_io_ioctl, +}; diff --git a/libcustomntfs/gekko_io.h b/libcustomntfs/gekko_io.h new file mode 100644 index 00000000..d5018e89 --- /dev/null +++ b/libcustomntfs/gekko_io.h @@ -0,0 +1,56 @@ +/* +* gekko_io.h - Platform specifics for device io. +* +* Copyright (c) 2009 Rhys "Shareese" Koedijk +* +* 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 +* (at your option) any later version. +* +* This program/include file is distributed in the hope that it will be +* useful, but WITHOUT ANY WARRANTY; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _GEKKO_IO_H +#define _GEKKO_IO_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "types.h" +#include "cache2.h" +#include +#include + +/** + * gekko_fd - Gekko device driver descriptor + */ +typedef struct _gekko_fd { + const DISC_INTERFACE* interface; /* Device disc interface */ + sec_t startSector; /* LBA of partition start */ + sec_t hiddenSectors; /* LBA offset to true partition start (as described by boot sector) */ + u16 sectorSize; /* Device sector size (in bytes) */ + u64 sectorCount; /* Total number of sectors in partition */ + u64 pos; /* Current position within the partition (in bytes) */ + u64 len; /* Total length of partition (in bytes) */ + ino_t ino; /* Device identifier */ + NTFS_CACHE *cache; /* Cache */ + u32 cachePageCount; /* The number of pages in the cache */ + u32 cachePageSize; /* The number of sectors per cache page */ +} gekko_fd; + +/* Forward declarations */ +struct ntfs_device_operations; + +/* Gekko device driver i/o operations */ +extern struct ntfs_device_operations ntfs_device_gekko_io_ops; + +#endif /* _GEKKO_IO_H */ diff --git a/libcustomntfs/index.c b/libcustomntfs/index.c new file mode 100644 index 00000000..7df0deec --- /dev/null +++ b/libcustomntfs/index.c @@ -0,0 +1,2063 @@ +/** + * index.c - NTFS index handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2004-2005 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2005-2008 Szabolcs Szakacsits + * Copyright (c) 2007 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "attrib.h" +#include "debug.h" +#include "index.h" +#include "collate.h" +#include "mst.h" +#include "dir.h" +#include "logging.h" +#include "bitmap.h" +#include "reparse.h" +#include "misc.h" + +/** + * ntfs_index_entry_mark_dirty - mark an index entry dirty + * @ictx: ntfs index context describing the index entry + * + * Mark the index entry described by the index entry context @ictx dirty. + * + * If the index entry is in the index root attribute, simply mark the inode + * containing the index root attribute dirty. This ensures the mftrecord, and + * hence the index root attribute, will be written out to disk later. + * + * If the index entry is in an index block belonging to the index allocation + * attribute, set ib_dirty to TRUE, thus index block will be updated during + * ntfs_index_ctx_put. + */ +void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx) +{ + if (ictx->is_in_root) + ntfs_inode_mark_dirty(ictx->actx->ntfs_ino); + else + ictx->ib_dirty = TRUE; +} + +static s64 ntfs_ib_vcn_to_pos(ntfs_index_context *icx, VCN vcn) +{ + return vcn << icx->vcn_size_bits; +} + +static VCN ntfs_ib_pos_to_vcn(ntfs_index_context *icx, s64 pos) +{ + return pos >> icx->vcn_size_bits; +} + +static int ntfs_ib_write(ntfs_index_context *icx, INDEX_BLOCK *ib) +{ + s64 ret, vcn = sle64_to_cpu(ib->index_block_vcn); + + ntfs_log_trace("vcn: %lld\n", (long long)vcn); + + ret = ntfs_attr_mst_pwrite(icx->ia_na, ntfs_ib_vcn_to_pos(icx, vcn), + 1, icx->block_size, ib); + if (ret != 1) { + ntfs_log_perror("Failed to write index block %lld, inode %llu", + (long long)vcn, (unsigned long long)icx->ni->mft_no); + return STATUS_ERROR; + } + + return STATUS_OK; +} + +static int ntfs_icx_ib_write(ntfs_index_context *icx) +{ + if (ntfs_ib_write(icx, icx->ib)) + return STATUS_ERROR; + + icx->ib_dirty = FALSE; + + return STATUS_OK; +} + +/** + * ntfs_index_ctx_get - allocate and initialize a new index context + * @ni: ntfs inode with which to initialize the context + * @name: name of the which context describes + * @name_len: length of the index name + * + * Allocate a new index context, initialize it with @ni and return it. + * Return NULL if allocation failed. + */ +ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, + ntfschar *name, u32 name_len) +{ + ntfs_index_context *icx; + + ntfs_log_trace("Entering\n"); + + if (!ni) { + errno = EINVAL; + return NULL; + } + if (ni->nr_extents == -1) + ni = ni->base_ni; + icx = ntfs_calloc(sizeof(ntfs_index_context)); + if (icx) + *icx = (ntfs_index_context) { + .ni = ni, + .name = name, + .name_len = name_len, + }; + return icx; +} + +static void ntfs_index_ctx_free(ntfs_index_context *icx) +{ + ntfs_log_trace("Entering\n"); + + if (!icx->entry) + return; + + if (icx->actx) + ntfs_attr_put_search_ctx(icx->actx); + + if (!icx->is_in_root) { + if (icx->ib_dirty) { + /* FIXME: Error handling!!! */ + ntfs_ib_write(icx, icx->ib); + } + free(icx->ib); + } + + ntfs_attr_close(icx->ia_na); +} + +/** + * ntfs_index_ctx_put - release an index context + * @icx: index context to free + * + * Release the index context @icx, releasing all associated resources. + */ +void ntfs_index_ctx_put(ntfs_index_context *icx) +{ + ntfs_index_ctx_free(icx); + free(icx); +} + +/** + * ntfs_index_ctx_reinit - reinitialize an index context + * @icx: index context to reinitialize + * + * Reinitialize the index context @icx so it can be used for ntfs_index_lookup. + */ +void ntfs_index_ctx_reinit(ntfs_index_context *icx) +{ + ntfs_log_trace("Entering\n"); + + ntfs_index_ctx_free(icx); + + *icx = (ntfs_index_context) { + .ni = icx->ni, + .name = icx->name, + .name_len = icx->name_len, + }; +} + +static VCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie) +{ + return (VCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(VCN)); +} + +/** + * Get the subnode vcn to which the index entry refers. + */ +VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie) +{ + return sle64_to_cpup(ntfs_ie_get_vcn_addr(ie)); +} + +static INDEX_ENTRY *ntfs_ie_get_first(INDEX_HEADER *ih) +{ + return (INDEX_ENTRY *)((u8 *)ih + le32_to_cpu(ih->entries_offset)); +} + +static INDEX_ENTRY *ntfs_ie_get_next(INDEX_ENTRY *ie) +{ + return (INDEX_ENTRY *)((char *)ie + le16_to_cpu(ie->length)); +} + +static u8 *ntfs_ie_get_end(INDEX_HEADER *ih) +{ + /* FIXME: check if it isn't overflowing the index block size */ + return (u8 *)ih + le32_to_cpu(ih->index_length); +} + +static int ntfs_ie_end(INDEX_ENTRY *ie) +{ + return ie->ie_flags & INDEX_ENTRY_END || !ie->length; +} + +/** + * Find the last entry in the index block + */ +static INDEX_ENTRY *ntfs_ie_get_last(INDEX_ENTRY *ie, char *ies_end) +{ + ntfs_log_trace("Entering\n"); + + while ((char *)ie < ies_end && !ntfs_ie_end(ie)) + ie = ntfs_ie_get_next(ie); + + return ie; +} + +static INDEX_ENTRY *ntfs_ie_get_by_pos(INDEX_HEADER *ih, int pos) +{ + INDEX_ENTRY *ie; + + ntfs_log_trace("pos: %d\n", pos); + + ie = ntfs_ie_get_first(ih); + + while (pos-- > 0) + ie = ntfs_ie_get_next(ie); + + return ie; +} + +static INDEX_ENTRY *ntfs_ie_prev(INDEX_HEADER *ih, INDEX_ENTRY *ie) +{ + INDEX_ENTRY *ie_prev = NULL; + INDEX_ENTRY *tmp; + + ntfs_log_trace("Entering\n"); + + tmp = ntfs_ie_get_first(ih); + + while (tmp != ie) { + ie_prev = tmp; + tmp = ntfs_ie_get_next(tmp); + } + + return ie_prev; +} + +char *ntfs_ie_filename_get(INDEX_ENTRY *ie) +{ + FILE_NAME_ATTR *fn; + + fn = (FILE_NAME_ATTR *)&ie->key; + return ntfs_attr_name_get(fn->file_name, fn->file_name_length); +} + +void ntfs_ie_filename_dump(INDEX_ENTRY *ie) +{ + char *s; + + s = ntfs_ie_filename_get(ie); + ntfs_log_debug("'%s' ", s); + ntfs_attr_name_free(&s); +} + +void ntfs_ih_filename_dump(INDEX_HEADER *ih) +{ + INDEX_ENTRY *ie; + + ntfs_log_trace("Entering\n"); + + ie = ntfs_ie_get_first(ih); + while (!ntfs_ie_end(ie)) { + ntfs_ie_filename_dump(ie); + ie = ntfs_ie_get_next(ie); + } +} + +static int ntfs_ih_numof_entries(INDEX_HEADER *ih) +{ + int n; + INDEX_ENTRY *ie; + u8 *end; + + ntfs_log_trace("Entering\n"); + + end = ntfs_ie_get_end(ih); + ie = ntfs_ie_get_first(ih); + for (n = 0; !ntfs_ie_end(ie) && (u8 *)ie < end; n++) + ie = ntfs_ie_get_next(ie); + return n; +} + +static int ntfs_ih_one_entry(INDEX_HEADER *ih) +{ + return (ntfs_ih_numof_entries(ih) == 1); +} + +static int ntfs_ih_zero_entry(INDEX_HEADER *ih) +{ + return (ntfs_ih_numof_entries(ih) == 0); +} + +static void ntfs_ie_delete(INDEX_HEADER *ih, INDEX_ENTRY *ie) +{ + u32 new_size; + + ntfs_log_trace("Entering\n"); + + new_size = le32_to_cpu(ih->index_length) - le16_to_cpu(ie->length); + ih->index_length = cpu_to_le32(new_size); + memmove(ie, (u8 *)ie + le16_to_cpu(ie->length), + new_size - ((u8 *)ie - (u8 *)ih)); +} + +static void ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn) +{ + *ntfs_ie_get_vcn_addr(ie) = cpu_to_le64(vcn); +} + +/** + * Insert @ie index entry at @pos entry. Used @ih values should be ok already. + */ +static void ntfs_ie_insert(INDEX_HEADER *ih, INDEX_ENTRY *ie, INDEX_ENTRY *pos) +{ + int ie_size = le16_to_cpu(ie->length); + + ntfs_log_trace("Entering\n"); + + ih->index_length = cpu_to_le32(le32_to_cpu(ih->index_length) + ie_size); + memmove((u8 *)pos + ie_size, pos, + le32_to_cpu(ih->index_length) - ((u8 *)pos - (u8 *)ih) - ie_size); + memcpy(pos, ie, ie_size); +} + +static INDEX_ENTRY *ntfs_ie_dup(INDEX_ENTRY *ie) +{ + INDEX_ENTRY *dup; + + ntfs_log_trace("Entering\n"); + + dup = ntfs_malloc(le16_to_cpu(ie->length)); + if (dup) + memcpy(dup, ie, le16_to_cpu(ie->length)); + + return dup; +} + +static INDEX_ENTRY *ntfs_ie_dup_novcn(INDEX_ENTRY *ie) +{ + INDEX_ENTRY *dup; + int size = le16_to_cpu(ie->length); + + ntfs_log_trace("Entering\n"); + + if (ie->ie_flags & INDEX_ENTRY_NODE) + size -= sizeof(VCN); + + dup = ntfs_malloc(size); + if (dup) { + memcpy(dup, ie, size); + dup->ie_flags &= ~INDEX_ENTRY_NODE; + dup->length = cpu_to_le16(size); + } + return dup; +} + +static int ntfs_ia_check(ntfs_index_context *icx, INDEX_BLOCK *ib, VCN vcn) +{ + u32 ib_size = (unsigned)le32_to_cpu(ib->index.allocated_size) + 0x18; + + ntfs_log_trace("Entering\n"); + + if (!ntfs_is_indx_record(ib->magic)) { + + ntfs_log_error("Corrupt index block signature: vcn %lld inode " + "%llu\n", (long long)vcn, + (unsigned long long)icx->ni->mft_no); + return -1; + } + + if (sle64_to_cpu(ib->index_block_vcn) != vcn) { + + ntfs_log_error("Corrupt index block: VCN (%lld) is different " + "from expected VCN (%lld) in inode %llu\n", + (long long)sle64_to_cpu(ib->index_block_vcn), + (long long)vcn, + (unsigned long long)icx->ni->mft_no); + return -1; + } + + if (ib_size != icx->block_size) { + + ntfs_log_error("Corrupt index block : VCN (%lld) of inode %llu " + "has a size (%u) differing from the index " + "specified size (%u)\n", (long long)vcn, + (unsigned long long)icx->ni->mft_no, ib_size, + icx->block_size); + return -1; + } + return 0; +} + +static INDEX_ROOT *ntfs_ir_lookup(ntfs_inode *ni, ntfschar *name, + u32 name_len, ntfs_attr_search_ctx **ctx) +{ + ATTR_RECORD *a; + INDEX_ROOT *ir = NULL; + + ntfs_log_trace("Entering\n"); + + *ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!*ctx) + return NULL; + + if (ntfs_attr_lookup(AT_INDEX_ROOT, name, name_len, CASE_SENSITIVE, + 0, NULL, 0, *ctx)) { + ntfs_log_perror("Failed to lookup $INDEX_ROOT"); + goto err_out; + } + + a = (*ctx)->attr; + if (a->non_resident) { + errno = EINVAL; + ntfs_log_perror("Non-resident $INDEX_ROOT detected"); + goto err_out; + } + + ir = (INDEX_ROOT *)((char *)a + le16_to_cpu(a->value_offset)); +err_out: + if (!ir) { + ntfs_attr_put_search_ctx(*ctx); + *ctx = NULL; + } + return ir; +} + +static INDEX_ROOT *ntfs_ir_lookup2(ntfs_inode *ni, ntfschar *name, u32 len) +{ + ntfs_attr_search_ctx *ctx; + INDEX_ROOT *ir; + + ir = ntfs_ir_lookup(ni, name, len, &ctx); + if (ir) + ntfs_attr_put_search_ctx(ctx); + return ir; +} + +/** + * Find a key in the index block. + * + * Return values: + * STATUS_OK with errno set to ESUCCESS if we know for sure that the + * entry exists and @ie_out points to this entry. + * STATUS_NOT_FOUND with errno set to ENOENT if we know for sure the + * entry doesn't exist and @ie_out is the insertion point. + * STATUS_KEEP_SEARCHING if we can't answer the above question and + * @vcn will contain the node index block. + * STATUS_ERROR with errno set if on unexpected error during lookup. + */ +static int ntfs_ie_lookup(const void *key, const int key_len, + ntfs_index_context *icx, INDEX_HEADER *ih, + VCN *vcn, INDEX_ENTRY **ie_out) +{ + INDEX_ENTRY *ie; + u8 *index_end; + int rc, item = 0; + + ntfs_log_trace("Entering\n"); + + index_end = ntfs_ie_get_end(ih); + + /* + * Loop until we exceed valid memory (corruption case) or until we + * reach the last entry. + */ + for (ie = ntfs_ie_get_first(ih); ; ie = ntfs_ie_get_next(ie)) { + /* Bounds checks. */ + if ((u8 *)ie + sizeof(INDEX_ENTRY_HEADER) > index_end || + (u8 *)ie + le16_to_cpu(ie->length) > index_end) { + errno = ERANGE; + ntfs_log_error("Index entry out of bounds in inode " + "%llu.\n", + (unsigned long long)icx->ni->mft_no); + return STATUS_ERROR; + } + /* + * The last entry cannot contain a key. It can however contain + * a pointer to a child node in the B+tree so we just break out. + */ + if (ntfs_ie_end(ie)) + break; + /* + * Not a perfect match, need to do full blown collation so we + * know which way in the B+tree we have to go. + */ + if (!icx->collate) { + ntfs_log_error("Collation function not defined\n"); + errno = EOPNOTSUPP; + return STATUS_ERROR; + } + rc = icx->collate(icx->ni->vol, key, key_len, + &ie->key, le16_to_cpu(ie->key_length)); + if (rc == NTFS_COLLATION_ERROR) { + ntfs_log_error("Collation error. Perhaps a filename " + "contains invalid characters?\n"); + errno = ERANGE; + return STATUS_ERROR; + } + /* + * If @key collates before the key of the current entry, there + * is definitely no such key in this index but we might need to + * descend into the B+tree so we just break out of the loop. + */ + if (rc == -1) + break; + + if (!rc) { + *ie_out = ie; + errno = 0; + icx->parent_pos[icx->pindex] = item; + return STATUS_OK; + } + + item++; + } + /* + * We have finished with this index block without success. Check for the + * presence of a child node and if not present return with errno ENOENT, + * otherwise we will keep searching in another index block. + */ + if (!(ie->ie_flags & INDEX_ENTRY_NODE)) { + ntfs_log_debug("Index entry wasn't found.\n"); + *ie_out = ie; + errno = ENOENT; + return STATUS_NOT_FOUND; + } + + /* Get the starting vcn of the index_block holding the child node. */ + *vcn = ntfs_ie_get_vcn(ie); + if (*vcn < 0) { + errno = EINVAL; + ntfs_log_perror("Negative vcn in inode %llu", + (unsigned long long)icx->ni->mft_no); + return STATUS_ERROR; + } + + ntfs_log_trace("Parent entry number %d\n", item); + icx->parent_pos[icx->pindex] = item; + + return STATUS_KEEP_SEARCHING; +} + +static ntfs_attr *ntfs_ia_open(ntfs_index_context *icx, ntfs_inode *ni) +{ + ntfs_attr *na; + + na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, icx->name, icx->name_len); + if (!na) { + ntfs_log_perror("Failed to open index allocation of inode " + "%llu", (unsigned long long)ni->mft_no); + return NULL; + } + + return na; +} + +static int ntfs_ib_read(ntfs_index_context *icx, VCN vcn, INDEX_BLOCK *dst) +{ + s64 pos, ret; + + ntfs_log_trace("vcn: %lld\n", (long long)vcn); + + pos = ntfs_ib_vcn_to_pos(icx, vcn); + + ret = ntfs_attr_mst_pread(icx->ia_na, pos, 1, icx->block_size, (u8 *)dst); + if (ret != 1) { + if (ret == -1) + ntfs_log_perror("Failed to read index block"); + else + ntfs_log_error("Failed to read full index block at " + "%lld\n", (long long)pos); + return -1; + } + + if (ntfs_ia_check(icx, dst, vcn)) + return -1; + + return 0; +} + +static int ntfs_icx_parent_inc(ntfs_index_context *icx) +{ + icx->pindex++; + if (icx->pindex >= MAX_PARENT_VCN) { + errno = EOPNOTSUPP; + ntfs_log_perror("Index is over %d level deep", MAX_PARENT_VCN); + return STATUS_ERROR; + } + return STATUS_OK; +} + +static int ntfs_icx_parent_dec(ntfs_index_context *icx) +{ + icx->pindex--; + if (icx->pindex < 0) { + errno = EINVAL; + ntfs_log_perror("Corrupt index pointer (%d)", icx->pindex); + return STATUS_ERROR; + } + return STATUS_OK; +} + +/** + * ntfs_index_lookup - find a key in an index and return its index entry + * @key: [IN] key for which to search in the index + * @key_len: [IN] length of @key in bytes + * @icx: [IN/OUT] context describing the index and the returned entry + * + * Before calling ntfs_index_lookup(), @icx must have been obtained from a + * call to ntfs_index_ctx_get(). + * + * Look for the @key in the index specified by the index lookup context @icx. + * ntfs_index_lookup() walks the contents of the index looking for the @key. + * + * If the @key is found in the index, 0 is returned and @icx is setup to + * describe the index entry containing the matching @key. @icx->entry is the + * index entry and @icx->data and @icx->data_len are the index entry data and + * its length in bytes, respectively. + * + * If the @key is not found in the index, -1 is returned, errno = ENOENT and + * @icx is setup to describe the index entry whose key collates immediately + * after the search @key, i.e. this is the position in the index at which + * an index entry with a key of @key would need to be inserted. + * + * If an error occurs return -1, set errno to error code and @icx is left + * untouched. + * + * When finished with the entry and its data, call ntfs_index_ctx_put() to free + * the context and other associated resources. + * + * If the index entry was modified, call ntfs_index_entry_mark_dirty() before + * the call to ntfs_index_ctx_put() to ensure that the changes are written + * to disk. + */ +int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *icx) +{ + VCN old_vcn, vcn; + ntfs_inode *ni = icx->ni; + INDEX_ROOT *ir; + INDEX_ENTRY *ie; + INDEX_BLOCK *ib = NULL; + int ret, err = 0; + + ntfs_log_trace("Entering\n"); + + if (!key || key_len <= 0) { + errno = EINVAL; + ntfs_log_perror("key: %p key_len: %d", key, key_len); + return -1; + } + + ir = ntfs_ir_lookup(ni, icx->name, icx->name_len, &icx->actx); + if (!ir) { + if (errno == ENOENT) + errno = EIO; + return -1; + } + + icx->block_size = le32_to_cpu(ir->index_block_size); + if (icx->block_size < NTFS_BLOCK_SIZE) { + errno = EINVAL; + ntfs_log_perror("Index block size (%d) is smaller than the " + "sector size (%d)", icx->block_size, NTFS_BLOCK_SIZE); + goto err_out; + } + + if (ni->vol->cluster_size <= icx->block_size) + icx->vcn_size_bits = ni->vol->cluster_size_bits; + else + icx->vcn_size_bits = ni->vol->sector_size_bits; + /* get the appropriate collation function */ + icx->collate = ntfs_get_collate_function(ir->collation_rule); + if (!icx->collate) { + err = errno = EOPNOTSUPP; + ntfs_log_perror("Unknown collation rule 0x%x", + (unsigned)le32_to_cpu(ir->collation_rule)); + goto err_out; + } + + old_vcn = VCN_INDEX_ROOT_PARENT; + /* + * FIXME: check for both ir and ib that the first index entry is + * within the index block. + */ + ret = ntfs_ie_lookup(key, key_len, icx, &ir->index, &vcn, &ie); + if (ret == STATUS_ERROR) { + err = errno; + goto err_out; + } + + icx->ir = ir; + + if (ret != STATUS_KEEP_SEARCHING) { + /* STATUS_OK or STATUS_NOT_FOUND */ + err = errno; + icx->is_in_root = TRUE; + icx->parent_vcn[icx->pindex] = old_vcn; + goto done; + } + + /* Child node present, descend into it. */ + + icx->ia_na = ntfs_ia_open(icx, ni); + if (!icx->ia_na) + goto err_out; + + ib = ntfs_malloc(icx->block_size); + if (!ib) { + err = errno; + goto err_out; + } + +descend_into_child_node: + + icx->parent_vcn[icx->pindex] = old_vcn; + if (ntfs_icx_parent_inc(icx)) { + err = errno; + goto err_out; + } + old_vcn = vcn; + + ntfs_log_debug("Descend into node with VCN %lld\n", (long long)vcn); + + if (ntfs_ib_read(icx, vcn, ib)) + goto err_out; + + ret = ntfs_ie_lookup(key, key_len, icx, &ib->index, &vcn, &ie); + if (ret != STATUS_KEEP_SEARCHING) { + err = errno; + if (ret == STATUS_ERROR) + goto err_out; + + /* STATUS_OK or STATUS_NOT_FOUND */ + icx->is_in_root = FALSE; + icx->ib = ib; + icx->parent_vcn[icx->pindex] = vcn; + goto done; + } + + if ((ib->index.ih_flags & NODE_MASK) == LEAF_NODE) { + ntfs_log_error("Index entry with child node found in a leaf " + "node in inode 0x%llx.\n", + (unsigned long long)ni->mft_no); + goto err_out; + } + + goto descend_into_child_node; +err_out: + free(ib); + if (!err) + err = EIO; + errno = err; + return -1; +done: + icx->entry = ie; + icx->data = (u8 *)ie + offsetof(INDEX_ENTRY, key); + icx->data_len = le16_to_cpu(ie->key_length); + ntfs_log_trace("Done.\n"); + if (err) { + errno = err; + return -1; + } + return 0; + +} + +static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, + INDEX_HEADER_FLAGS node_type) +{ + INDEX_BLOCK *ib; + int ih_size = sizeof(INDEX_HEADER); + + ntfs_log_trace("ib_vcn: %lld ib_size: %u\n", (long long)ib_vcn, ib_size); + + ib = ntfs_calloc(ib_size); + if (!ib) + return NULL; + + ib->magic = magic_INDX; + ib->usa_ofs = cpu_to_le16(sizeof(INDEX_BLOCK)); + ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1); + /* Set USN to 1 */ + *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = cpu_to_le16(1); + ib->lsn = cpu_to_le64(0); + + ib->index_block_vcn = cpu_to_sle64(ib_vcn); + + ib->index.entries_offset = cpu_to_le32((ih_size + + le16_to_cpu(ib->usa_count) * 2 + 7) & ~7); + ib->index.index_length = 0; + ib->index.allocated_size = cpu_to_le32(ib_size - + (sizeof(INDEX_BLOCK) - ih_size)); + ib->index.ih_flags = node_type; + + return ib; +} + +/** + * Find the median by going through all the entries + */ +static INDEX_ENTRY *ntfs_ie_get_median(INDEX_HEADER *ih) +{ + INDEX_ENTRY *ie, *ie_start; + u8 *ie_end; + int i = 0, median; + + ntfs_log_trace("Entering\n"); + + ie = ie_start = ntfs_ie_get_first(ih); + ie_end = (u8 *)ntfs_ie_get_end(ih); + + while ((u8 *)ie < ie_end && !ntfs_ie_end(ie)) { + ie = ntfs_ie_get_next(ie); + i++; + } + /* + * NOTE: this could be also the entry at the half of the index block. + */ + median = i / 2 - 1; + + ntfs_log_trace("Entries: %d median: %d\n", i, median); + + for (i = 0, ie = ie_start; i <= median; i++) + ie = ntfs_ie_get_next(ie); + + return ie; +} + +static s64 ntfs_ibm_vcn_to_pos(ntfs_index_context *icx, VCN vcn) +{ + return ntfs_ib_vcn_to_pos(icx, vcn) / icx->block_size; +} + +static s64 ntfs_ibm_pos_to_vcn(ntfs_index_context *icx, s64 pos) +{ + return ntfs_ib_pos_to_vcn(icx, pos * icx->block_size); +} + +static int ntfs_ibm_add(ntfs_index_context *icx) +{ + u8 bmp[8]; + + ntfs_log_trace("Entering\n"); + + if (ntfs_attr_exist(icx->ni, AT_BITMAP, icx->name, icx->name_len)) + return STATUS_OK; + /* + * AT_BITMAP must be at least 8 bytes. + */ + memset(bmp, 0, sizeof(bmp)); + if (ntfs_attr_add(icx->ni, AT_BITMAP, icx->name, icx->name_len, + bmp, sizeof(bmp))) { + ntfs_log_perror("Failed to add AT_BITMAP"); + return STATUS_ERROR; + } + + return STATUS_OK; +} + +static int ntfs_ibm_modify(ntfs_index_context *icx, VCN vcn, int set) +{ + u8 byte; + s64 pos = ntfs_ibm_vcn_to_pos(icx, vcn); + u32 bpos = pos / 8; + u32 bit = 1 << (pos % 8); + ntfs_attr *na; + int ret = STATUS_ERROR; + + ntfs_log_trace("%s vcn: %lld\n", set ? "set" : "clear", (long long)vcn); + + na = ntfs_attr_open(icx->ni, AT_BITMAP, icx->name, icx->name_len); + if (!na) { + ntfs_log_perror("Failed to open $BITMAP attribute"); + return -1; + } + + if (set) { + if (na->data_size < bpos + 1) { + if (ntfs_attr_truncate(na, (na->data_size + 8) & ~7)) { + ntfs_log_perror("Failed to truncate AT_BITMAP"); + goto err_na; + } + } + } + + if (ntfs_attr_pread(na, bpos, 1, &byte) != 1) { + ntfs_log_perror("Failed to read $BITMAP"); + goto err_na; + } + + if (set) + byte |= bit; + else + byte &= ~bit; + + if (ntfs_attr_pwrite(na, bpos, 1, &byte) != 1) { + ntfs_log_perror("Failed to write $Bitmap"); + goto err_na; + } + + ret = STATUS_OK; +err_na: + ntfs_attr_close(na); + return ret; +} + + +static int ntfs_ibm_set(ntfs_index_context *icx, VCN vcn) +{ + return ntfs_ibm_modify(icx, vcn, 1); +} + +static int ntfs_ibm_clear(ntfs_index_context *icx, VCN vcn) +{ + return ntfs_ibm_modify(icx, vcn, 0); +} + +static VCN ntfs_ibm_get_free(ntfs_index_context *icx) +{ + u8 *bm; + int bit; + s64 vcn, byte, size; + + ntfs_log_trace("Entering\n"); + + bm = ntfs_attr_readall(icx->ni, AT_BITMAP, icx->name, icx->name_len, + &size); + if (!bm) + return (VCN)-1; + + for (byte = 0; byte < size; byte++) { + + if (bm[byte] == 255) + continue; + + for (bit = 0; bit < 8; bit++) { + if (!(bm[byte] & (1 << bit))) { + vcn = ntfs_ibm_pos_to_vcn(icx, byte * 8 + bit); + goto out; + } + } + } + + vcn = ntfs_ibm_pos_to_vcn(icx, size * 8); +out: + ntfs_log_trace("allocated vcn: %lld\n", (long long)vcn); + + if (ntfs_ibm_set(icx, vcn)) + vcn = (VCN)-1; + + free(bm); + return vcn; +} + +static INDEX_BLOCK *ntfs_ir_to_ib(INDEX_ROOT *ir, VCN ib_vcn) +{ + INDEX_BLOCK *ib; + INDEX_ENTRY *ie_last; + char *ies_start, *ies_end; + int i; + + ntfs_log_trace("Entering\n"); + + ib = ntfs_ib_alloc(ib_vcn, le32_to_cpu(ir->index_block_size), LEAF_NODE); + if (!ib) + return NULL; + + ies_start = (char *)ntfs_ie_get_first(&ir->index); + ies_end = (char *)ntfs_ie_get_end(&ir->index); + ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); + /* + * Copy all entries, including the termination entry + * as well, which can never have any data. + */ + i = (char *)ie_last - ies_start + le16_to_cpu(ie_last->length); + memcpy(ntfs_ie_get_first(&ib->index), ies_start, i); + + ib->index.ih_flags = ir->index.ih_flags; + ib->index.index_length = cpu_to_le32(i + + le32_to_cpu(ib->index.entries_offset)); + return ib; +} + +static void ntfs_ir_nill(INDEX_ROOT *ir) +{ + INDEX_ENTRY *ie_last; + char *ies_start, *ies_end; + + ntfs_log_trace("Entering\n"); + /* + * TODO: This function could be much simpler. + */ + ies_start = (char *)ntfs_ie_get_first(&ir->index); + ies_end = (char *)ntfs_ie_get_end(&ir->index); + ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); + /* + * Move the index root termination entry forward + */ + if ((char *)ie_last > ies_start) { + memmove(ies_start, (char *)ie_last, le16_to_cpu(ie_last->length)); + ie_last = (INDEX_ENTRY *)ies_start; + } +} + +static int ntfs_ib_copy_tail(ntfs_index_context *icx, INDEX_BLOCK *src, + INDEX_ENTRY *median, VCN new_vcn) +{ + u8 *ies_end; + INDEX_ENTRY *ie_head; /* first entry after the median */ + int tail_size, ret; + INDEX_BLOCK *dst; + + ntfs_log_trace("Entering\n"); + + dst = ntfs_ib_alloc(new_vcn, icx->block_size, + src->index.ih_flags & NODE_MASK); + if (!dst) + return STATUS_ERROR; + + ie_head = ntfs_ie_get_next(median); + + ies_end = (u8 *)ntfs_ie_get_end(&src->index); + tail_size = ies_end - (u8 *)ie_head; + memcpy(ntfs_ie_get_first(&dst->index), ie_head, tail_size); + + dst->index.index_length = cpu_to_le32(tail_size + + le32_to_cpu(dst->index.entries_offset)); + ret = ntfs_ib_write(icx, dst); + + free(dst); + return ret; +} + +static int ntfs_ib_cut_tail(ntfs_index_context *icx, INDEX_BLOCK *ib, + INDEX_ENTRY *ie) +{ + char *ies_start, *ies_end; + INDEX_ENTRY *ie_last; + + ntfs_log_trace("Entering\n"); + + ies_start = (char *)ntfs_ie_get_first(&ib->index); + ies_end = (char *)ntfs_ie_get_end(&ib->index); + + ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); + if (ie_last->ie_flags & INDEX_ENTRY_NODE) + ntfs_ie_set_vcn(ie_last, ntfs_ie_get_vcn(ie)); + + memcpy(ie, ie_last, le16_to_cpu(ie_last->length)); + + ib->index.index_length = cpu_to_le32(((char *)ie - ies_start) + + le16_to_cpu(ie->length) + le32_to_cpu(ib->index.entries_offset)); + + if (ntfs_ib_write(icx, ib)) + return STATUS_ERROR; + + return STATUS_OK; +} + +static int ntfs_ia_add(ntfs_index_context *icx) +{ + ntfs_log_trace("Entering\n"); + + if (ntfs_ibm_add(icx)) + return -1; + + if (!ntfs_attr_exist(icx->ni, AT_INDEX_ALLOCATION, icx->name, icx->name_len)) { + + if (ntfs_attr_add(icx->ni, AT_INDEX_ALLOCATION, icx->name, + icx->name_len, NULL, 0)) { + ntfs_log_perror("Failed to add AT_INDEX_ALLOCATION"); + return -1; + } + } + + icx->ia_na = ntfs_ia_open(icx, icx->ni); + if (!icx->ia_na) + return -1; + + return 0; +} + +static int ntfs_ir_reparent(ntfs_index_context *icx) +{ + ntfs_attr_search_ctx *ctx = NULL; + INDEX_ROOT *ir; + INDEX_ENTRY *ie; + INDEX_BLOCK *ib = NULL; + VCN new_ib_vcn; + int ret = STATUS_ERROR; + + ntfs_log_trace("Entering\n"); + + ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); + if (!ir) + goto out; + + if ((ir->index.ih_flags & NODE_MASK) == SMALL_INDEX) + if (ntfs_ia_add(icx)) + goto out; + + new_ib_vcn = ntfs_ibm_get_free(icx); + if (new_ib_vcn == -1) + goto out; + + ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); + if (!ir) + goto clear_bmp; + + ib = ntfs_ir_to_ib(ir, new_ib_vcn); + if (ib == NULL) { + ntfs_log_perror("Failed to move index root to index block"); + goto clear_bmp; + } + + if (ntfs_ib_write(icx, ib)) + goto clear_bmp; + + ir = ntfs_ir_lookup(icx->ni, icx->name, icx->name_len, &ctx); + if (!ir) + goto clear_bmp; + + ntfs_ir_nill(ir); + + ie = ntfs_ie_get_first(&ir->index); + ie->ie_flags |= INDEX_ENTRY_NODE; + ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN)); + + ir->index.ih_flags = LARGE_INDEX; + ir->index.index_length = cpu_to_le32(le32_to_cpu(ir->index.entries_offset) + + le16_to_cpu(ie->length)); + ir->index.allocated_size = ir->index.index_length; + + if (ntfs_resident_attr_value_resize(ctx->mrec, ctx->attr, + sizeof(INDEX_ROOT) - sizeof(INDEX_HEADER) + + le32_to_cpu(ir->index.allocated_size))) + /* FIXME: revert index root */ + goto clear_bmp; + /* + * FIXME: do it earlier if we have enough space in IR (should always), + * so in error case we wouldn't lose the IB. + */ + ntfs_ie_set_vcn(ie, new_ib_vcn); + + ret = STATUS_OK; +err_out: + free(ib); + ntfs_attr_put_search_ctx(ctx); +out: + return ret; +clear_bmp: + ntfs_ibm_clear(icx, new_ib_vcn); + goto err_out; +} + +/** + * ntfs_ir_truncate - Truncate index root attribute + * + * Returns STATUS_OK, STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT or STATUS_ERROR. + */ +static int ntfs_ir_truncate(ntfs_index_context *icx, int data_size) +{ + ntfs_attr *na; + int ret; + + ntfs_log_trace("Entering\n"); + + na = ntfs_attr_open(icx->ni, AT_INDEX_ROOT, icx->name, icx->name_len); + if (!na) { + ntfs_log_perror("Failed to open INDEX_ROOT"); + return STATUS_ERROR; + } + /* + * INDEX_ROOT must be resident and its entries can be moved to + * INDEX_BLOCK, so ENOSPC isn't a real error. + */ + ret = ntfs_attr_truncate(na, data_size + offsetof(INDEX_ROOT, index)); + if (ret == STATUS_OK) { + + icx->ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); + if (!icx->ir) + return STATUS_ERROR; + + icx->ir->index.allocated_size = cpu_to_le32(data_size); + + } else if (ret == STATUS_ERROR) + ntfs_log_perror("Failed to truncate INDEX_ROOT"); + + ntfs_attr_close(na); + return ret; +} + +/** + * ntfs_ir_make_space - Make more space for the index root attribute + * + * On success return STATUS_OK or STATUS_KEEP_SEARCHING. + * On error return STATUS_ERROR. + */ +static int ntfs_ir_make_space(ntfs_index_context *icx, int data_size) +{ + int ret; + + ntfs_log_trace("Entering\n"); + + ret = ntfs_ir_truncate(icx, data_size); + if (ret == STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT) { + + ret = ntfs_ir_reparent(icx); + if (ret == STATUS_OK) + ret = STATUS_KEEP_SEARCHING; + else + ntfs_log_perror("Failed to nodify INDEX_ROOT"); + } + + return ret; +} + +/* + * NOTE: 'ie' must be a copy of a real index entry. + */ +static int ntfs_ie_add_vcn(INDEX_ENTRY **ie) +{ + INDEX_ENTRY *p, *old = *ie; + + old->length = cpu_to_le16(le16_to_cpu(old->length) + sizeof(VCN)); + p = realloc(old, le16_to_cpu(old->length)); + if (!p) + return STATUS_ERROR; + + p->ie_flags |= INDEX_ENTRY_NODE; + *ie = p; + + return STATUS_OK; +} + +static int ntfs_ih_insert(INDEX_HEADER *ih, INDEX_ENTRY *orig_ie, VCN new_vcn, + int pos) +{ + INDEX_ENTRY *ie_node, *ie; + int ret = STATUS_ERROR; + VCN old_vcn; + + ntfs_log_trace("Entering\n"); + + ie = ntfs_ie_dup(orig_ie); + if (!ie) + return STATUS_ERROR; + + if (!(ie->ie_flags & INDEX_ENTRY_NODE)) + if (ntfs_ie_add_vcn(&ie)) + goto out; + + ie_node = ntfs_ie_get_by_pos(ih, pos); + old_vcn = ntfs_ie_get_vcn(ie_node); + ntfs_ie_set_vcn(ie_node, new_vcn); + + ntfs_ie_insert(ih, ie, ie_node); + ntfs_ie_set_vcn(ie_node, old_vcn); + ret = STATUS_OK; +out: + free(ie); + + return ret; +} + +static VCN ntfs_icx_parent_vcn(ntfs_index_context *icx) +{ + return icx->parent_vcn[icx->pindex]; +} + +static VCN ntfs_icx_parent_pos(ntfs_index_context *icx) +{ + return icx->parent_pos[icx->pindex]; +} + + +static int ntfs_ir_insert_median(ntfs_index_context *icx, INDEX_ENTRY *median, + VCN new_vcn) +{ + u32 new_size; + int ret; + + ntfs_log_trace("Entering\n"); + + icx->ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); + if (!icx->ir) + return STATUS_ERROR; + + new_size = le32_to_cpu(icx->ir->index.index_length) + + le16_to_cpu(median->length); + if (!(median->ie_flags & INDEX_ENTRY_NODE)) + new_size += sizeof(VCN); + + ret = ntfs_ir_make_space(icx, new_size); + if (ret != STATUS_OK) + return ret; + + icx->ir = ntfs_ir_lookup2(icx->ni, icx->name, icx->name_len); + if (!icx->ir) + return STATUS_ERROR; + + return ntfs_ih_insert(&icx->ir->index, median, new_vcn, + ntfs_icx_parent_pos(icx)); +} + +static int ntfs_ib_split(ntfs_index_context *icx, INDEX_BLOCK *ib); + +/** + * On success return STATUS_OK or STATUS_KEEP_SEARCHING. + * On error return STATUS_ERROR. + */ +static int ntfs_ib_insert(ntfs_index_context *icx, INDEX_ENTRY *ie, VCN new_vcn) +{ + INDEX_BLOCK *ib; + u32 idx_size, allocated_size; + int err = STATUS_ERROR; + VCN old_vcn; + + ntfs_log_trace("Entering\n"); + + ib = ntfs_malloc(icx->block_size); + if (!ib) + return -1; + + old_vcn = ntfs_icx_parent_vcn(icx); + + if (ntfs_ib_read(icx, old_vcn, ib)) + goto err_out; + + idx_size = le32_to_cpu(ib->index.index_length); + allocated_size = le32_to_cpu(ib->index.allocated_size); + /* FIXME: sizeof(VCN) should be included only if ie has no VCN */ + if (idx_size + le16_to_cpu(ie->length) + sizeof(VCN) > allocated_size) { + err = ntfs_ib_split(icx, ib); + if (err == STATUS_OK) + err = STATUS_KEEP_SEARCHING; + goto err_out; + } + + if (ntfs_ih_insert(&ib->index, ie, new_vcn, ntfs_icx_parent_pos(icx))) + goto err_out; + + if (ntfs_ib_write(icx, ib)) + goto err_out; + + err = STATUS_OK; +err_out: + free(ib); + return err; +} + +/** + * ntfs_ib_split - Split an index block + * + * On success return STATUS_OK or STATUS_KEEP_SEARCHING. + * On error return is STATUS_ERROR. + */ +static int ntfs_ib_split(ntfs_index_context *icx, INDEX_BLOCK *ib) +{ + INDEX_ENTRY *median; + VCN new_vcn; + int ret; + + ntfs_log_trace("Entering\n"); + + if (ntfs_icx_parent_dec(icx)) + return STATUS_ERROR; + + median = ntfs_ie_get_median(&ib->index); + new_vcn = ntfs_ibm_get_free(icx); + if (new_vcn == -1) + return STATUS_ERROR; + + if (ntfs_ib_copy_tail(icx, ib, median, new_vcn)) { + ntfs_ibm_clear(icx, new_vcn); + return STATUS_ERROR; + } + + if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) + ret = ntfs_ir_insert_median(icx, median, new_vcn); + else + ret = ntfs_ib_insert(icx, median, new_vcn); + + if (ret != STATUS_OK) { + ntfs_ibm_clear(icx, new_vcn); + return ret; + } + + ret = ntfs_ib_cut_tail(icx, ib, median); + + return ret; +} + +/* JPA static */ +int ntfs_ie_add(ntfs_index_context *icx, INDEX_ENTRY *ie) +{ + INDEX_HEADER *ih; + int allocated_size, new_size; + int ret = STATUS_ERROR; + +#ifdef DEBUG +/* removed by JPA to make function usable for security indexes + char *fn; + fn = ntfs_ie_filename_get(ie); + ntfs_log_trace("file: '%s'\n", fn); + ntfs_attr_name_free(&fn); +*/ +#endif + + while (1) { + + if (!ntfs_index_lookup(&ie->key, le16_to_cpu(ie->key_length), icx)) { + errno = EEXIST; + ntfs_log_perror("Index already have such entry"); + goto err_out; + } + if (errno != ENOENT) { + ntfs_log_perror("Failed to find place for new entry"); + goto err_out; + } + + if (icx->is_in_root) + ih = &icx->ir->index; + else + ih = &icx->ib->index; + + allocated_size = le32_to_cpu(ih->allocated_size); + new_size = le32_to_cpu(ih->index_length) + le16_to_cpu(ie->length); + + if (new_size <= allocated_size) + break; + + ntfs_log_trace("index block sizes: allocated: %d needed: %d\n", + allocated_size, new_size); + + if (icx->is_in_root) { + if (ntfs_ir_make_space(icx, new_size) == STATUS_ERROR) + goto err_out; + } else { + if (ntfs_ib_split(icx, icx->ib) == STATUS_ERROR) + goto err_out; + } + + ntfs_inode_mark_dirty(icx->actx->ntfs_ino); + ntfs_index_ctx_reinit(icx); + } + + ntfs_ie_insert(ih, ie, icx->entry); + ntfs_index_entry_mark_dirty(icx); + + ret = STATUS_OK; +err_out: + ntfs_log_trace("%s\n", ret ? "Failed" : "Done"); + return ret; +} + +/** + * ntfs_index_add_filename - add filename to directory index + * @ni: ntfs inode describing directory to which index add filename + * @fn: FILE_NAME attribute to add + * @mref: reference of the inode which @fn describes + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, MFT_REF mref) +{ + INDEX_ENTRY *ie; + ntfs_index_context *icx; + int fn_size, ie_size, err, ret = -1; + + ntfs_log_trace("Entering\n"); + + if (!ni || !fn) { + ntfs_log_error("Invalid arguments.\n"); + errno = EINVAL; + return -1; + } + + fn_size = (fn->file_name_length * sizeof(ntfschar)) + + sizeof(FILE_NAME_ATTR); + ie_size = (sizeof(INDEX_ENTRY_HEADER) + fn_size + 7) & ~7; + + ie = ntfs_calloc(ie_size); + if (!ie) + return -1; + + ie->indexed_file = cpu_to_le64(mref); + ie->length = cpu_to_le16(ie_size); + ie->key_length = cpu_to_le16(fn_size); + memcpy(&ie->key, fn, fn_size); + + icx = ntfs_index_ctx_get(ni, NTFS_INDEX_I30, 4); + if (!icx) + goto out; + + ret = ntfs_ie_add(icx, ie); + err = errno; + ntfs_index_ctx_put(icx); + errno = err; +out: + free(ie); + return ret; +} + +static int ntfs_ih_takeout(ntfs_index_context *icx, INDEX_HEADER *ih, + INDEX_ENTRY *ie, INDEX_BLOCK *ib) +{ + INDEX_ENTRY *ie_roam; + int ret = STATUS_ERROR; + + ntfs_log_trace("Entering\n"); + + ie_roam = ntfs_ie_dup_novcn(ie); + if (!ie_roam) + return STATUS_ERROR; + + ntfs_ie_delete(ih, ie); + + if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) + ntfs_inode_mark_dirty(icx->actx->ntfs_ino); + else + if (ntfs_ib_write(icx, ib)) + goto out; + + ntfs_index_ctx_reinit(icx); + + ret = ntfs_ie_add(icx, ie_roam); +out: + free(ie_roam); + return ret; +} + +/** + * Used if an empty index block to be deleted has END entry as the parent + * in the INDEX_ROOT which is the only one there. + */ +static void ntfs_ir_leafify(ntfs_index_context *icx, INDEX_HEADER *ih) +{ + INDEX_ENTRY *ie; + + ntfs_log_trace("Entering\n"); + + ie = ntfs_ie_get_first(ih); + ie->ie_flags &= ~INDEX_ENTRY_NODE; + ie->length = cpu_to_le16(le16_to_cpu(ie->length) - sizeof(VCN)); + + ih->index_length = cpu_to_le32(le32_to_cpu(ih->index_length) - sizeof(VCN)); + ih->ih_flags &= ~LARGE_INDEX; + + /* Not fatal error */ + ntfs_ir_truncate(icx, le32_to_cpu(ih->index_length)); +} + +/** + * Used if an empty index block to be deleted has END entry as the parent + * in the INDEX_ROOT which is not the only one there. + */ +static int ntfs_ih_reparent_end(ntfs_index_context *icx, INDEX_HEADER *ih, + INDEX_BLOCK *ib) +{ + INDEX_ENTRY *ie, *ie_prev; + + ntfs_log_trace("Entering\n"); + + ie = ntfs_ie_get_by_pos(ih, ntfs_icx_parent_pos(icx)); + ie_prev = ntfs_ie_prev(ih, ie); + + ntfs_ie_set_vcn(ie, ntfs_ie_get_vcn(ie_prev)); + + return ntfs_ih_takeout(icx, ih, ie_prev, ib); +} + +static int ntfs_index_rm_leaf(ntfs_index_context *icx) +{ + INDEX_BLOCK *ib = NULL; + INDEX_HEADER *parent_ih; + INDEX_ENTRY *ie; + int ret = STATUS_ERROR; + + ntfs_log_trace("pindex: %d\n", icx->pindex); + + if (ntfs_icx_parent_dec(icx)) + return STATUS_ERROR; + + if (ntfs_ibm_clear(icx, icx->parent_vcn[icx->pindex + 1])) + return STATUS_ERROR; + + if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) + parent_ih = &icx->ir->index; + else { + ib = ntfs_malloc(icx->block_size); + if (!ib) + return STATUS_ERROR; + + if (ntfs_ib_read(icx, ntfs_icx_parent_vcn(icx), ib)) + goto out; + + parent_ih = &ib->index; + } + + ie = ntfs_ie_get_by_pos(parent_ih, ntfs_icx_parent_pos(icx)); + if (!ntfs_ie_end(ie)) { + ret = ntfs_ih_takeout(icx, parent_ih, ie, ib); + goto out; + } + + if (ntfs_ih_zero_entry(parent_ih)) { + + if (ntfs_icx_parent_vcn(icx) == VCN_INDEX_ROOT_PARENT) { + ntfs_ir_leafify(icx, parent_ih); + goto ok; + } + + ret = ntfs_index_rm_leaf(icx); + goto out; + } + + if (ntfs_ih_reparent_end(icx, parent_ih, ib)) + goto out; +ok: + ret = STATUS_OK; +out: + free(ib); + return ret; +} + +static int ntfs_index_rm_node(ntfs_index_context *icx) +{ + int entry_pos, pindex; + VCN vcn; + INDEX_BLOCK *ib = NULL; + INDEX_ENTRY *ie_succ, *ie, *entry = icx->entry; + INDEX_HEADER *ih; + u32 new_size; + int delta, ret = STATUS_ERROR; + + ntfs_log_trace("Entering\n"); + + if (!icx->ia_na) { + icx->ia_na = ntfs_ia_open(icx, icx->ni); + if (!icx->ia_na) + return STATUS_ERROR; + } + + ib = ntfs_malloc(icx->block_size); + if (!ib) + return STATUS_ERROR; + + ie_succ = ntfs_ie_get_next(icx->entry); + entry_pos = icx->parent_pos[icx->pindex]++; + pindex = icx->pindex; +descend: + vcn = ntfs_ie_get_vcn(ie_succ); + if (ntfs_ib_read(icx, vcn, ib)) + goto out; + + ie_succ = ntfs_ie_get_first(&ib->index); + + if (ntfs_icx_parent_inc(icx)) + goto out; + + icx->parent_vcn[icx->pindex] = vcn; + icx->parent_pos[icx->pindex] = 0; + + if ((ib->index.ih_flags & NODE_MASK) == INDEX_NODE) + goto descend; + + if (ntfs_ih_zero_entry(&ib->index)) { + errno = EIO; + ntfs_log_perror("Empty index block"); + goto out; + } + + ie = ntfs_ie_dup(ie_succ); + if (!ie) + goto out; + + if (ntfs_ie_add_vcn(&ie)) + goto out2; + + ntfs_ie_set_vcn(ie, ntfs_ie_get_vcn(icx->entry)); + + if (icx->is_in_root) + ih = &icx->ir->index; + else + ih = &icx->ib->index; + + delta = le16_to_cpu(ie->length) - le16_to_cpu(icx->entry->length); + new_size = le32_to_cpu(ih->index_length) + delta; + if (delta > 0) { + if (icx->is_in_root) { + ret = ntfs_ir_make_space(icx, new_size); + if (ret != STATUS_OK) + goto out2; + + ih = &icx->ir->index; + entry = ntfs_ie_get_by_pos(ih, entry_pos); + + } else if (new_size > le32_to_cpu(ih->allocated_size)) { + icx->pindex = pindex; + ret = ntfs_ib_split(icx, icx->ib); + if (ret == STATUS_OK) + ret = STATUS_KEEP_SEARCHING; + goto out2; + } + } + + ntfs_ie_delete(ih, entry); + ntfs_ie_insert(ih, ie, entry); + + if (icx->is_in_root) { + if (ntfs_ir_truncate(icx, new_size)) + goto out2; + } else + if (ntfs_icx_ib_write(icx)) + goto out2; + + ntfs_ie_delete(&ib->index, ie_succ); + + if (ntfs_ih_zero_entry(&ib->index)) { + if (ntfs_index_rm_leaf(icx)) + goto out2; + } else + if (ntfs_ib_write(icx, ib)) + goto out2; + + ret = STATUS_OK; +out2: + free(ie); +out: + free(ib); + return ret; +} + +/** + * ntfs_index_rm - remove entry from the index + * @icx: index context describing entry to delete + * + * Delete entry described by @icx from the index. Index context is always + * reinitialized after use of this function, so it can be used for index + * lookup once again. + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +/*static JPA*/ +int ntfs_index_rm(ntfs_index_context *icx) +{ + INDEX_HEADER *ih; + int err, ret = STATUS_OK; + + ntfs_log_trace("Entering\n"); + + if (!icx || (!icx->ib && !icx->ir) || ntfs_ie_end(icx->entry)) { + ntfs_log_error("Invalid arguments.\n"); + errno = EINVAL; + goto err_out; + } + if (icx->is_in_root) + ih = &icx->ir->index; + else + ih = &icx->ib->index; + + if (icx->entry->ie_flags & INDEX_ENTRY_NODE) { + + ret = ntfs_index_rm_node(icx); + + } else if (icx->is_in_root || !ntfs_ih_one_entry(ih)) { + + ntfs_ie_delete(ih, icx->entry); + + if (icx->is_in_root) { + err = ntfs_ir_truncate(icx, le32_to_cpu(ih->index_length)); + if (err != STATUS_OK) + goto err_out; + } else + if (ntfs_icx_ib_write(icx)) + goto err_out; + } else { + if (ntfs_index_rm_leaf(icx)) + goto err_out; + } +out: + return ret; +err_out: + ret = STATUS_ERROR; + goto out; +} + +int ntfs_index_remove(ntfs_inode *dir_ni, ntfs_inode *ni, + const void *key, const int keylen) +{ + int ret = STATUS_ERROR; + ntfs_index_context *icx; + + icx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4); + if (!icx) + return -1; + + while (1) { + + if (ntfs_index_lookup(key, keylen, icx)) + goto err_out; + + if ((((FILE_NAME_ATTR *)icx->data)->file_attributes & + FILE_ATTR_REPARSE_POINT) + && !ntfs_possible_symlink(ni)) { + errno = EOPNOTSUPP; + goto err_out; + } + + ret = ntfs_index_rm(icx); + if (ret == STATUS_ERROR) + goto err_out; + else if (ret == STATUS_OK) + break; + + ntfs_inode_mark_dirty(icx->actx->ntfs_ino); + ntfs_index_ctx_reinit(icx); + } + + ntfs_inode_mark_dirty(icx->actx->ntfs_ino); +out: + ntfs_index_ctx_put(icx); + return ret; +err_out: + ret = STATUS_ERROR; + ntfs_log_perror("Delete failed"); + goto out; +} + +/** + * ntfs_index_root_get - read the index root of an attribute + * @ni: open ntfs inode in which the ntfs attribute resides + * @attr: attribute for which we want its index root + * + * This function will read the related index root an ntfs attribute. + * + * On success a buffer is allocated with the content of the index root + * and which needs to be freed when it's not needed anymore. + * + * On error NULL is returned with errno set to the error code. + */ +INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr) +{ + ntfs_attr_search_ctx *ctx; + ntfschar *name; + INDEX_ROOT *root = NULL; + + name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)); + + if (!ntfs_ir_lookup(ni, name, attr->name_length, &ctx)) + return NULL; + + root = ntfs_malloc(sizeof(INDEX_ROOT)); + if (!root) + goto out; + + *root = *((INDEX_ROOT *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset))); +out: + ntfs_attr_put_search_ctx(ctx); + return root; +} + + +/* + * Walk down the index tree (leaf bound) + * until there are no subnode in the first index entry + * returns the entry at the bottom left in subnode + */ + +static INDEX_ENTRY *ntfs_index_walk_down(INDEX_ENTRY *ie, + ntfs_index_context *ictx) +{ + INDEX_ENTRY *entry; + s64 vcn; + + entry = ie; + do { + vcn = ntfs_ie_get_vcn(entry); + if (ictx->is_in_root) { + + /* down from level zero */ + + ictx->ir = (INDEX_ROOT*)NULL; + ictx->ib = (INDEX_BLOCK*)ntfs_malloc(ictx->block_size); + ictx->pindex = 1; + ictx->is_in_root = FALSE; + } else { + + /* down from non-zero level */ + + ictx->pindex++; + } + ictx->parent_pos[ictx->pindex] = 0; + ictx->parent_vcn[ictx->pindex] = vcn; + if (!ntfs_ib_read(ictx,vcn,ictx->ib)) { + ictx->entry = ntfs_ie_get_first(&ictx->ib->index); + entry = ictx->entry; + } else + entry = (INDEX_ENTRY*)NULL; + } while (entry && (entry->ie_flags & INDEX_ENTRY_NODE)); + return (entry); +} + +/* + * Walk up the index tree (root bound) + * until there is a valid data entry in parent + * returns the parent entry or NULL if no more parent + */ + +static INDEX_ENTRY *ntfs_index_walk_up(INDEX_ENTRY *ie, + ntfs_index_context *ictx) +{ + INDEX_ENTRY *entry; + s64 vcn; + + entry = ie; + if (ictx->pindex > 0) { + do { + ictx->pindex--; + if (!ictx->pindex) { + + /* we have reached the root */ + + free(ictx->ib); + ictx->ib = (INDEX_BLOCK*)NULL; + ictx->is_in_root = TRUE; + /* a new search context is to be allocated */ + if (ictx->actx) + free(ictx->actx); + ictx->ir = ntfs_ir_lookup(ictx->ni, + ictx->name, ictx->name_len, + &ictx->actx); + if (ictx->ir) + entry = ntfs_ie_get_by_pos( + &ictx->ir->index, + ictx->parent_pos[ictx->pindex]); + else + entry = (INDEX_ENTRY*)NULL; + } else { + /* up into non-root node */ + vcn = ictx->parent_vcn[ictx->pindex]; + if (!ntfs_ib_read(ictx,vcn,ictx->ib)) { + entry = ntfs_ie_get_by_pos( + &ictx->ib->index, + ictx->parent_pos[ictx->pindex]); + } else + entry = (INDEX_ENTRY*)NULL; + } + ictx->entry = entry; + } while (entry && (ictx->pindex > 0) + && (entry->ie_flags & INDEX_ENTRY_END)); + } else + entry = (INDEX_ENTRY*)NULL; + return (entry); +} + +/* + * Get next entry in an index according to collating sequence. + * Must be initialized through a ntfs_index_lookup() + * + * Returns next entry or NULL if none + * + * Sample layout : + * + * +---+---+---+---+---+---+---+---+ n ptrs to subnodes + * | | | 10| 25| 33| | | | n-1 keys in between + * +---+---+---+---+---+---+---+---+ no key in last entry + * | A | A + * | | | +-------------------------------+ + * +--------------------------+ | +-----+ | + * | +--+ | | + * V | V | + * +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ + * | 11| 12| 13| 14| 15| 16| 17| | | | 26| 27| 28| 29| 30| 31| 32| | + * +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ + * | | + * +-----------------------+ | + * | | + * +---+---+---+---+---+---+---+---+ + * | 18| 19| 20| 21| 22| 23| 24| | + * +---+---+---+---+---+---+---+---+ + */ + +INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx) +{ + INDEX_ENTRY *next; + int flags; + + /* + * lookup() may have returned an invalid node + * when searching for a partial key + * if this happens, walk up + */ + + if (ie->ie_flags & INDEX_ENTRY_END) + next = ntfs_index_walk_up(ie, ictx); + else { + /* + * get next entry in same node + * there is always one after any entry with data + */ + + next = (INDEX_ENTRY*)((char*)ie + le16_to_cpu(ie->length)); + ++ictx->parent_pos[ictx->pindex]; + flags = next->ie_flags; + + /* walk down if it has a subnode */ + + if (flags & INDEX_ENTRY_NODE) { + next = ntfs_index_walk_down(next,ictx); + } else { + + /* walk up it has no subnode, nor data */ + + if (flags & INDEX_ENTRY_END) { + next = ntfs_index_walk_up(next, ictx); + } + } + } + /* return NULL if stuck at end of a block */ + + if (next && (next->ie_flags & INDEX_ENTRY_END)) + next = (INDEX_ENTRY*)NULL; + return (next); +} + + diff --git a/libcustomntfs/index.h b/libcustomntfs/index.h new file mode 100644 index 00000000..c0e76180 --- /dev/null +++ b/libcustomntfs/index.h @@ -0,0 +1,167 @@ +/* + * index.h - Defines for NTFS index handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2004 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2006-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_INDEX_H +#define _NTFS_INDEX_H + +/* Convenience macros to test the versions of gcc. + * Use them like this: + * #if __GNUC_PREREQ (2,8) + * ... code requiring gcc 2.8 or later ... + * #endif + * Note - they won't work for gcc1 or glibc1, since the _MINOR macros + * were not defined then. + */ + +#ifndef __GNUC_PREREQ +# if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +# else +# define __GNUC_PREREQ(maj, min) 0 +# endif +#endif + +/* allows us to warn about unused results of certain function calls */ +#ifndef __attribute_warn_unused_result__ +# if __GNUC_PREREQ (3,4) +# define __attribute_warn_unused_result__ \ + __attribute__ ((__warn_unused_result__)) +# else +# define __attribute_warn_unused_result__ /* empty */ +# endif +#endif + +#include "attrib.h" +#include "types.h" +#include "layout.h" +#include "inode.h" +#include "mft.h" + +#define VCN_INDEX_ROOT_PARENT ((VCN)-2) + +#define MAX_PARENT_VCN 32 + +typedef int (*COLLATE)(ntfs_volume *vol, const void *data1, int len1, + const void *data2, int len2); + +/** + * struct ntfs_index_context - + * @ni: inode containing the @entry described by this context + * @name: name of the index described by this context + * @name_len: length of the index name + * @entry: index entry (points into @ir or @ia) + * @data: index entry data (points into @entry) + * @data_len: length in bytes of @data + * @is_in_root: TRUE if @entry is in @ir or FALSE if it is in @ia + * @ir: index root if @is_in_root or NULL otherwise + * @actx: attribute search context if in root or NULL otherwise + * @ia: index block if @is_in_root is FALSE or NULL otherwise + * @ia_na: opened INDEX_ALLOCATION attribute + * @parent_pos: parent entries' positions in the index block + * @parent_vcn: entry's parent node or VCN_INDEX_ROOT_PARENT + * @new_vcn: new VCN if we need to create a new index block + * @median: move to the parent if splitting index blocks + * @ib_dirty: TRUE if index block was changed + * @block_size: index block size + * @vcn_size_bits: VCN size bits for this index block + * + * @ni is the inode this context belongs to. + * + * @entry is the index entry described by this context. @data and @data_len + * are the index entry data and its length in bytes, respectively. @data + * simply points into @entry. This is probably what the user is interested in. + * + * If @is_in_root is TRUE, @entry is in the index root attribute @ir described + * by the attribute search context @actx and inode @ni. @ia and + * @ib_dirty are undefined in this case. + * + * If @is_in_root is FALSE, @entry is in the index allocation attribute and @ia + * point to the index allocation block and VCN where it's placed, + * respectively. @ir and @actx are NULL in this case. @ia_na is opened + * INDEX_ALLOCATION attribute. @ib_dirty is TRUE if index block was changed and + * FALSE otherwise. + * + * To obtain a context call ntfs_index_ctx_get(). + * + * When finished with the @entry and its @data, call ntfs_index_ctx_put() to + * free the context and other associated resources. + * + * If the index entry was modified, call ntfs_index_entry_mark_dirty() before + * the call to ntfs_index_ctx_put() to ensure that the changes are written + * to disk. + */ +typedef struct { + ntfs_inode *ni; + ntfschar *name; + u32 name_len; + INDEX_ENTRY *entry; + void *data; + u16 data_len; + COLLATE collate; + BOOL is_in_root; + INDEX_ROOT *ir; + ntfs_attr_search_ctx *actx; + INDEX_BLOCK *ib; + ntfs_attr *ia_na; + int parent_pos[MAX_PARENT_VCN]; /* parent entries' positions */ + VCN parent_vcn[MAX_PARENT_VCN]; /* entry's parent nodes */ + int pindex; /* maximum it's the number of the parent nodes */ + BOOL ib_dirty; + u32 block_size; + u8 vcn_size_bits; +} ntfs_index_context; + +extern ntfs_index_context *ntfs_index_ctx_get(ntfs_inode *ni, + ntfschar *name, u32 name_len); +extern void ntfs_index_ctx_put(ntfs_index_context *ictx); +extern void ntfs_index_ctx_reinit(ntfs_index_context *ictx); + +extern int ntfs_index_lookup(const void *key, const int key_len, + ntfs_index_context *ictx) __attribute_warn_unused_result__; + +extern INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, + ntfs_index_context *ictx); + +extern int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn, + MFT_REF mref); +extern int ntfs_index_remove(ntfs_inode *dir_ni, ntfs_inode *ni, + const void *key, const int keylen); + +extern INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr); + +extern VCN ntfs_ie_get_vcn(INDEX_ENTRY *ie); + +extern void ntfs_index_entry_mark_dirty(ntfs_index_context *ictx); + +extern char *ntfs_ie_filename_get(INDEX_ENTRY *ie); +extern void ntfs_ie_filename_dump(INDEX_ENTRY *ie); +extern void ntfs_ih_filename_dump(INDEX_HEADER *ih); + +/* the following was added by JPA for use in security.c */ +extern int ntfs_ie_add(ntfs_index_context *icx, INDEX_ENTRY *ie); +extern int ntfs_index_rm(ntfs_index_context *icx); + +#endif /* _NTFS_INDEX_H */ + diff --git a/libcustomntfs/inode.c b/libcustomntfs/inode.c new file mode 100644 index 00000000..6f3fa060 --- /dev/null +++ b/libcustomntfs/inode.c @@ -0,0 +1,1566 @@ +/** + * inode.c - Inode handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2005 Anton Altaparmakov + * Copyright (c) 2002-2008 Szabolcs Szakacsits + * Copyright (c) 2004-2007 Yura Pakhuchiy + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2009-2010 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_SETXATTR +#include +#endif + +#include "param.h" +#include "compat.h" +#include "types.h" +#include "volume.h" +#include "cache.h" +#include "inode.h" +#include "attrib.h" +#include "debug.h" +#include "mft.h" +#include "attrlist.h" +#include "runlist.h" +#include "lcnalloc.h" +#include "index.h" +#include "dir.h" +#include "ntfstime.h" +#include "logging.h" +#include "misc.h" + +ntfs_inode *ntfs_inode_base(ntfs_inode *ni) +{ + if (ni->nr_extents == -1) + return ni->base_ni; + return ni; +} + +/** + * ntfs_inode_mark_dirty - set the inode (and its base inode if it exists) dirty + * @ni: ntfs inode to set dirty + * + * Set the inode @ni dirty so it is written out later (at the latest at + * ntfs_inode_close() time). If @ni is an extent inode, set the base inode + * dirty, too. + * + * This function cannot fail. + */ +void ntfs_inode_mark_dirty(ntfs_inode *ni) +{ + NInoSetDirty(ni); + if (ni->nr_extents == -1) + NInoSetDirty(ni->base_ni); +} + +/** + * __ntfs_inode_allocate - Create and initialise an NTFS inode object + * @vol: + * + * Description... + * + * Returns: + */ +static ntfs_inode *__ntfs_inode_allocate(ntfs_volume *vol) +{ + ntfs_inode *ni; + + ni = (ntfs_inode*)ntfs_calloc(sizeof(ntfs_inode)); + if (ni) + ni->vol = vol; + return ni; +} + +/** + * ntfs_inode_allocate - Create an NTFS inode object + * @vol: + * + * Description... + * + * Returns: + */ +ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol) +{ + return __ntfs_inode_allocate(vol); +} + +/** + * __ntfs_inode_release - Destroy an NTFS inode object + * @ni: + * + * Description... + * + * Returns: + */ +static void __ntfs_inode_release(ntfs_inode *ni) +{ + if (NInoDirty(ni)) + ntfs_log_error("Releasing dirty inode %lld!\n", + (long long)ni->mft_no); + if (NInoAttrList(ni) && ni->attr_list) + free(ni->attr_list); + free(ni->mrec); + free(ni); + return; +} + +/** + * ntfs_inode_open - open an inode ready for access + * @vol: volume to get the inode from + * @mref: inode number / mft record number to open + * + * Allocate an ntfs_inode structure and initialize it for the given inode + * specified by @mref. @mref specifies the inode number / mft record to read, + * including the sequence number, which can be 0 if no sequence number checking + * is to be performed. + * + * Then, allocate a buffer for the mft record, read the mft record from the + * volume @vol, and attach it to the ntfs_inode structure (->mrec). The + * mft record is mst deprotected and sanity checked for validity and we abort + * if deprotection or checks fail. + * + * Finally, search for an attribute list attribute in the mft record and if one + * is found, load the attribute list attribute value and attach it to the + * ntfs_inode structure (->attr_list). Also set the NI_AttrList bit to indicate + * this. + * + * Return a pointer to the ntfs_inode structure on success or NULL on error, + * with errno set to the error code. + */ +static ntfs_inode *ntfs_inode_real_open(ntfs_volume *vol, const MFT_REF mref) +{ + s64 l; + ntfs_inode *ni = NULL; + ntfs_attr_search_ctx *ctx; + STANDARD_INFORMATION *std_info; + le32 lthle; + int olderrno; + + ntfs_log_enter("Entering for inode %lld\n", (long long)MREF(mref)); + if (!vol) { + errno = EINVAL; + goto out; + } + ni = __ntfs_inode_allocate(vol); + if (!ni) + goto out; + if (ntfs_file_record_read(vol, mref, &ni->mrec, NULL)) + goto err_out; + if (!(ni->mrec->flags & MFT_RECORD_IN_USE)) { + errno = ENOENT; + goto err_out; + } + ni->mft_no = MREF(mref); + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + goto err_out; + /* Receive some basic information about inode. */ + if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, + 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (!ni->mrec->base_mft_record) + ntfs_log_perror("No STANDARD_INFORMATION in base record" + " %lld", (long long)MREF(mref)); + goto put_err_out; + } + std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + ni->flags = std_info->file_attributes; + ni->creation_time = std_info->creation_time; + ni->last_data_change_time = std_info->last_data_change_time; + ni->last_mft_change_time = std_info->last_mft_change_time; + ni->last_access_time = std_info->last_access_time; + /* JPA insert v3 extensions if present */ + /* length may be seen as 72 (v1.x) or 96 (v3.x) */ + lthle = ctx->attr->length; + if (le32_to_cpu(lthle) > sizeof(STANDARD_INFORMATION)) { + set_nino_flag(ni, v3_Extensions); + ni->owner_id = std_info->owner_id; + ni->security_id = std_info->security_id; + ni->quota_charged = std_info->quota_charged; + ni->usn = std_info->usn; + } else { + clear_nino_flag(ni, v3_Extensions); + ni->owner_id = const_cpu_to_le32(0); + ni->security_id = const_cpu_to_le32(0); + } + /* Set attribute list information. */ + olderrno = errno; + if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (errno != ENOENT) + goto put_err_out; + /* Attribute list attribute does not present. */ + /* restore previous errno to avoid misinterpretation */ + errno = olderrno; + goto get_size; + } + NInoSetAttrList(ni); + l = ntfs_get_attribute_value_length(ctx->attr); + if (!l) + goto put_err_out; + if (l > 0x40000) { + errno = EIO; + ntfs_log_perror("Too large attrlist attribute (%lld), inode " + "%lld", (long long)l, (long long)MREF(mref)); + goto put_err_out; + } + ni->attr_list_size = l; + ni->attr_list = ntfs_malloc(ni->attr_list_size); + if (!ni->attr_list) + goto put_err_out; + l = ntfs_get_attribute_value(vol, ctx->attr, ni->attr_list); + if (!l) + goto put_err_out; + if (l != ni->attr_list_size) { + errno = EIO; + ntfs_log_perror("Unexpected attrlist size (%lld <> %u), inode " + "%lld", (long long)l, ni->attr_list_size, + (long long)MREF(mref)); + goto put_err_out; + } +get_size: + olderrno = errno; + if (ntfs_attr_lookup(AT_DATA, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) { + if (errno != ENOENT) + goto put_err_out; + /* Directory or special file. */ + /* restore previous errno to avoid misinterpretation */ + errno = olderrno; + ni->data_size = ni->allocated_size = 0; + } else { + if (ctx->attr->non_resident) { + ni->data_size = sle64_to_cpu(ctx->attr->data_size); + if (ctx->attr->flags & + (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) + ni->allocated_size = sle64_to_cpu( + ctx->attr->compressed_size); + else + ni->allocated_size = sle64_to_cpu( + ctx->attr->allocated_size); + } else { + ni->data_size = le32_to_cpu(ctx->attr->value_length); + ni->allocated_size = (ni->data_size + 7) & ~7; + } + set_nino_flag(ni,KnownSize); + } + ntfs_attr_put_search_ctx(ctx); +out: + ntfs_log_leave("\n"); + return ni; + +put_err_out: + ntfs_attr_put_search_ctx(ctx); +err_out: + __ntfs_inode_release(ni); + ni = NULL; + goto out; +} + +/** + * ntfs_inode_close - close an ntfs inode and free all associated memory + * @ni: ntfs inode to close + * + * Make sure the ntfs inode @ni is clean. + * + * If the ntfs inode @ni is a base inode, close all associated extent inodes, + * then deallocate all memory attached to it, and finally free the ntfs inode + * structure itself. + * + * If it is an extent inode, we disconnect it from its base inode before we + * destroy it. + * + * It is OK to pass NULL to this function, it is just noop in this case. + * + * Return 0 on success or -1 on error with errno set to the error code. On + * error, @ni has not been freed. The user should attempt to handle the error + * and call ntfs_inode_close() again. The following error codes are defined: + * + * EBUSY @ni and/or its attribute list runlist is/are dirty and the + * attempt to write it/them to disk failed. + * EINVAL @ni is invalid (probably it is an extent inode). + * EIO I/O error while trying to write inode to disk. + */ + +int ntfs_inode_real_close(ntfs_inode *ni) +{ + int ret = -1; + + if (!ni) + return 0; + + ntfs_log_enter("Entering for inode %lld\n", (long long)ni->mft_no); + + /* If we have dirty metadata, write it out. */ + if (NInoDirty(ni) || NInoAttrListDirty(ni)) { + if (ntfs_inode_sync(ni)) { + if (errno != EIO) + errno = EBUSY; + goto err; + } + } + /* Is this a base inode with mapped extent inodes? */ + if (ni->nr_extents > 0) { + while (ni->nr_extents > 0) { + if (ntfs_inode_real_close(ni->extent_nis[0])) { + if (errno != EIO) + errno = EBUSY; + goto err; + } + } + } else if (ni->nr_extents == -1) { + ntfs_inode **tmp_nis; + ntfs_inode *base_ni; + s32 i; + + /* + * If the inode is an extent inode, disconnect it from the + * base inode before destroying it. + */ + base_ni = ni->base_ni; + for (i = 0; i < base_ni->nr_extents; ++i) { + tmp_nis = base_ni->extent_nis; + if (tmp_nis[i] != ni) + continue; + /* Found it. Disconnect. */ + memmove(tmp_nis + i, tmp_nis + i + 1, + (base_ni->nr_extents - i - 1) * + sizeof(ntfs_inode *)); + /* Buffer should be for multiple of four extents. */ + if ((--base_ni->nr_extents) & 3) { + i = -1; + break; + } + /* + * ElectricFence is unhappy with realloc(x,0) as free(x) + * thus we explicitly separate these two cases. + */ + if (base_ni->nr_extents) { + /* Resize the memory buffer. */ + tmp_nis = realloc(tmp_nis, base_ni->nr_extents * + sizeof(ntfs_inode *)); + /* Ignore errors, they don't really matter. */ + if (tmp_nis) + base_ni->extent_nis = tmp_nis; + } else if (tmp_nis) { + free(tmp_nis); + base_ni->extent_nis = (ntfs_inode**)NULL; + } + /* Allow for error checking. */ + i = -1; + break; + } + + /* + * We could successfully sync, so only log this error + * and try to sync other inode extents too. + */ + if (i != -1) + ntfs_log_error("Extent inode %lld was not found\n", + (long long)ni->mft_no); + } + + __ntfs_inode_release(ni); + ret = 0; +err: + ntfs_log_leave("\n"); + return ret; +} + +#if CACHE_NIDATA_SIZE + +/* + * Free an inode structure when there is not more space + * in the cache + */ + +void ntfs_inode_nidata_free(const struct CACHED_GENERIC *cached) +{ + ntfs_inode_real_close(((const struct CACHED_NIDATA*)cached)->ni); +} + +/* + * Compute a hash value for an inode entry + */ + +int ntfs_inode_nidata_hash(const struct CACHED_GENERIC *item) +{ + return (((const struct CACHED_NIDATA*)item)->inum + % (2*CACHE_NIDATA_SIZE)); +} + +/* + * inum comparing for entering/fetching from cache + */ + +static int idata_cache_compare(const struct CACHED_GENERIC *cached, + const struct CACHED_GENERIC *wanted) +{ + return (((const struct CACHED_NIDATA*)cached)->inum + != ((const struct CACHED_NIDATA*)wanted)->inum); +} + +/* + * Invalidate an inode entry when not needed anymore. + * The entry should have been synced, it may be reused later, + * if it is requested before it is dropped from cache. + */ + +void ntfs_inode_invalidate(ntfs_volume *vol, const MFT_REF mref) +{ + struct CACHED_NIDATA item; + int count; + + item.inum = MREF(mref); + item.ni = (ntfs_inode*)NULL; + item.pathname = (const char*)NULL; + item.varsize = 0; + count = ntfs_invalidate_cache(vol->nidata_cache, + GENERIC(&item),idata_cache_compare,CACHE_FREE); +} + +#endif + +/* + * Open an inode + * + * When possible, an entry recorded in the cache is reused + * + * **NEVER REOPEN** an inode, this can lead to a duplicated + * cache entry (hard to detect), and to an obsolete one being + * reused. System files are however protected from being cached. + */ + +ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref) +{ + ntfs_inode *ni; +#if CACHE_NIDATA_SIZE + struct CACHED_NIDATA item; + struct CACHED_NIDATA *cached; + + /* fetch idata from cache */ + item.inum = MREF(mref); + debug_double_inode(item.inum,1); + item.pathname = (const char*)NULL; + item.varsize = 0; + cached = (struct CACHED_NIDATA*)ntfs_fetch_cache(vol->nidata_cache, + GENERIC(&item),idata_cache_compare); + if (cached) { + ni = cached->ni; + /* do not keep open entries in cache */ + ntfs_remove_cache(vol->nidata_cache, + (struct CACHED_GENERIC*)cached,0); + } else { + ni = ntfs_inode_real_open(vol, mref); + } +#else + ni = ntfs_inode_real_open(vol, mref); +#endif + return (ni); +} + +/* + * Close an inode entry + * + * If cacheing is in use, the entry is synced and kept available + * in cache for further use. + * + * System files (inode < 16 or having the IS_4 flag) are protected + * against being cached. + */ + +int ntfs_inode_close(ntfs_inode *ni) +{ + int res; +#if CACHE_NIDATA_SIZE + BOOL dirty; + struct CACHED_NIDATA item; + + if (ni) { + debug_double_inode(ni->mft_no,0); + /* do not cache system files : could lead to double entries */ + if (ni->vol && ni->vol->nidata_cache + && ((ni->mft_no == FILE_root) + || ((ni->mft_no >= FILE_first_user) + && !(ni->mrec->flags & MFT_RECORD_IS_4)))) { + /* If we have dirty metadata, write it out. */ + dirty = NInoDirty(ni) || NInoAttrListDirty(ni); + if (dirty) { + res = ntfs_inode_sync(ni); + /* do a real close if sync failed */ + if (res) + ntfs_inode_real_close(ni); + } else + res = 0; + + if (!res) { + /* feed idata into cache */ + item.inum = ni->mft_no; + item.ni = ni; + item.pathname = (const char*)NULL; + item.varsize = 0; + debug_cached_inode(ni); + ntfs_enter_cache(ni->vol->nidata_cache, + GENERIC(&item), idata_cache_compare); + } + } else { + /* cache not ready or system file, really close */ + res = ntfs_inode_real_close(ni); + } + } else + res = 0; +#else + res = ntfs_inode_real_close(ni); +#endif + return (res); +} + +/** + * ntfs_extent_inode_open - load an extent inode and attach it to its base + * @base_ni: base ntfs inode + * @mref: mft reference of the extent inode to load (in little endian) + * + * First check if the extent inode @mref is already attached to the base ntfs + * inode @base_ni, and if so, return a pointer to the attached extent inode. + * + * If the extent inode is not already attached to the base inode, allocate an + * ntfs_inode structure and initialize it for the given inode @mref. @mref + * specifies the inode number / mft record to read, including the sequence + * number, which can be 0 if no sequence number checking is to be performed. + * + * Then, allocate a buffer for the mft record, read the mft record from the + * volume @base_ni->vol, and attach it to the ntfs_inode structure (->mrec). + * The mft record is mst deprotected and sanity checked for validity and we + * abort if deprotection or checks fail. + * + * Finally attach the ntfs inode to its base inode @base_ni and return a + * pointer to the ntfs_inode structure on success or NULL on error, with errno + * set to the error code. + * + * Note, extent inodes are never closed directly. They are automatically + * disposed off by the closing of the base inode. + */ +ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref) +{ + u64 mft_no = MREF_LE(mref); + ntfs_inode *ni = NULL; + ntfs_inode **extent_nis; + int i; + + if (!base_ni) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return NULL; + } + + ntfs_log_enter("Opening extent inode %lld (base mft record %lld).\n", + (unsigned long long)mft_no, + (unsigned long long)base_ni->mft_no); + + /* Is the extent inode already open and attached to the base inode? */ + if (base_ni->nr_extents > 0) { + extent_nis = base_ni->extent_nis; + for (i = 0; i < base_ni->nr_extents; i++) { + u16 seq_no; + + ni = extent_nis[i]; + if (mft_no != ni->mft_no) + continue; + /* Verify the sequence number if given. */ + seq_no = MSEQNO_LE(mref); + if (seq_no && seq_no != le16_to_cpu( + ni->mrec->sequence_number)) { + errno = EIO; + ntfs_log_perror("Found stale extent mft " + "reference mft=%lld", + (long long)ni->mft_no); + goto out; + } + goto out; + } + } + /* Wasn't there, we need to load the extent inode. */ + ni = __ntfs_inode_allocate(base_ni->vol); + if (!ni) + goto out; + if (ntfs_file_record_read(base_ni->vol, le64_to_cpu(mref), &ni->mrec, NULL)) + goto err_out; + ni->mft_no = mft_no; + ni->nr_extents = -1; + ni->base_ni = base_ni; + /* Attach extent inode to base inode, reallocating memory if needed. */ + if (!(base_ni->nr_extents & 3)) { + i = (base_ni->nr_extents + 4) * sizeof(ntfs_inode *); + + extent_nis = ntfs_malloc(i); + if (!extent_nis) + goto err_out; + if (base_ni->nr_extents) { + memcpy(extent_nis, base_ni->extent_nis, + i - 4 * sizeof(ntfs_inode *)); + free(base_ni->extent_nis); + } + base_ni->extent_nis = extent_nis; + } + base_ni->extent_nis[base_ni->nr_extents++] = ni; +out: + ntfs_log_leave("\n"); + return ni; +err_out: + __ntfs_inode_release(ni); + ni = NULL; + goto out; +} + +/** + * ntfs_inode_attach_all_extents - attach all extents for target inode + * @ni: opened ntfs inode for which perform attach + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +int ntfs_inode_attach_all_extents(ntfs_inode *ni) +{ + ATTR_LIST_ENTRY *ale; + u64 prev_attached = 0; + + if (!ni) { + ntfs_log_trace("Invalid arguments.\n"); + errno = EINVAL; + return -1; + } + + if (ni->nr_extents == -1) + ni = ni->base_ni; + + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); + + /* Inode haven't got attribute list, thus nothing to attach. */ + if (!NInoAttrList(ni)) + return 0; + + if (!ni->attr_list) { + ntfs_log_trace("Corrupt in-memory struct.\n"); + errno = EINVAL; + return -1; + } + + /* Walk through attribute list and attach all extents. */ + errno = 0; + ale = (ATTR_LIST_ENTRY *)ni->attr_list; + while ((u8*)ale < ni->attr_list + ni->attr_list_size) { + if (ni->mft_no != MREF_LE(ale->mft_reference) && + prev_attached != MREF_LE(ale->mft_reference)) { + if (!ntfs_extent_inode_open(ni, ale->mft_reference)) { + ntfs_log_trace("Couldn't attach extent inode.\n"); + return -1; + } + prev_attached = MREF_LE(ale->mft_reference); + } + ale = (ATTR_LIST_ENTRY *)((u8*)ale + le16_to_cpu(ale->length)); + } + return 0; +} + +/** + * ntfs_inode_sync_standard_information - update standard information attribute + * @ni: ntfs inode to update standard information + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +static int ntfs_inode_sync_standard_information(ntfs_inode *ni) +{ + ntfs_attr_search_ctx *ctx; + STANDARD_INFORMATION *std_info; + u32 lth; + le32 lthle; + + ntfs_log_trace("Entering for inode %lld\n", (long long)ni->mft_no); + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, + 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { + ntfs_log_perror("Failed to sync standard info (inode %lld)", + (long long)ni->mft_no); + ntfs_attr_put_search_ctx(ctx); + return -1; + } + std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + std_info->file_attributes = ni->flags; + if (!test_nino_flag(ni, TimesSet)) { + std_info->creation_time = ni->creation_time; + std_info->last_data_change_time = ni->last_data_change_time; + std_info->last_mft_change_time = ni->last_mft_change_time; + std_info->last_access_time = ni->last_access_time; + } + + /* JPA update v3.x extensions, ensuring consistency */ + + lthle = ctx->attr->length; + lth = le32_to_cpu(lthle); + if (test_nino_flag(ni, v3_Extensions) + && (lth <= sizeof(STANDARD_INFORMATION))) + ntfs_log_error("bad sync of standard information\n"); + + if (lth > sizeof(STANDARD_INFORMATION)) { + std_info->owner_id = ni->owner_id; + std_info->security_id = ni->security_id; + std_info->quota_charged = ni->quota_charged; + std_info->usn = ni->usn; + } + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + return 0; +} + +/** + * ntfs_inode_sync_file_name - update FILE_NAME attributes + * @ni: ntfs inode to update FILE_NAME attributes + * + * Update all FILE_NAME attributes for inode @ni in the index. + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) +{ + ntfs_attr_search_ctx *ctx = NULL; + ntfs_index_context *ictx; + ntfs_inode *index_ni; + FILE_NAME_ATTR *fn; + FILE_NAME_ATTR *fnx; + REPARSE_POINT *rpp; + le32 reparse_tag; + int err = 0; + + ntfs_log_trace("Entering for inode %lld\n", (long long)ni->mft_no); + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) { + err = errno; + goto err_out; + } + /* Collect the reparse tag, if any */ + reparse_tag = cpu_to_le32(0); + if (ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!ntfs_attr_lookup(AT_REPARSE_POINT, NULL, + 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { + rpp = (REPARSE_POINT*)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + reparse_tag = rpp->reparse_tag; + } + ntfs_attr_reinit_search_ctx(ctx); + } + /* Walk through all FILE_NAME attributes and update them. */ + while (!ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) { + fn = (FILE_NAME_ATTR *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + if (MREF_LE(fn->parent_directory) == ni->mft_no) { + /* + * WARNING: We cheat here and obtain 2 attribute + * search contexts for one inode (first we obtained + * above, second will be obtained inside + * ntfs_index_lookup), it's acceptable for library, + * but will deadlock in the kernel. + */ + index_ni = ni; + } else + if (dir_ni) + index_ni = dir_ni; + else + index_ni = ntfs_inode_open(ni->vol, + le64_to_cpu(fn->parent_directory)); + if (!index_ni) { + if (!err) + err = errno; + ntfs_log_perror("Failed to open inode %lld with index", + (long long)le64_to_cpu(fn->parent_directory)); + continue; + } + ictx = ntfs_index_ctx_get(index_ni, NTFS_INDEX_I30, 4); + if (!ictx) { + if (!err) + err = errno; + ntfs_log_perror("Failed to get index ctx, inode %lld", + (long long)index_ni->mft_no); + if ((ni != index_ni) && !dir_ni + && ntfs_inode_close(index_ni) && !err) + err = errno; + continue; + } + if (ntfs_index_lookup(fn, sizeof(FILE_NAME_ATTR), ictx)) { + if (!err) { + if (errno == ENOENT) + err = EIO; + else + err = errno; + } + ntfs_log_perror("Index lookup failed, inode %lld", + (long long)index_ni->mft_no); + ntfs_index_ctx_put(ictx); + if (ni != index_ni && ntfs_inode_close(index_ni) && !err) + err = errno; + continue; + } + /* Update flags and file size. */ + fnx = (FILE_NAME_ATTR *)ictx->data; + fnx->file_attributes = + (fnx->file_attributes & ~FILE_ATTR_VALID_FLAGS) | + (ni->flags & FILE_ATTR_VALID_FLAGS); + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + fnx->data_size = fnx->allocated_size + = const_cpu_to_le64(0); + else { + fnx->allocated_size = cpu_to_sle64(ni->allocated_size); + fnx->data_size = cpu_to_sle64(ni->data_size); + } + /* update or clear the reparse tag in the index */ + fnx->reparse_point_tag = reparse_tag; + if (!test_nino_flag(ni, TimesSet)) { + fnx->creation_time = ni->creation_time; + fnx->last_data_change_time = ni->last_data_change_time; + fnx->last_mft_change_time = ni->last_mft_change_time; + fnx->last_access_time = ni->last_access_time; + } else { + fnx->creation_time = fn->creation_time; + fnx->last_data_change_time = fn->last_data_change_time; + fnx->last_mft_change_time = fn->last_mft_change_time; + fnx->last_access_time = fn->last_access_time; + } + ntfs_index_entry_mark_dirty(ictx); + ntfs_index_ctx_put(ictx); + if ((ni != index_ni) && !dir_ni + && ntfs_inode_close(index_ni) && !err) + err = errno; + } + /* Check for real error occurred. */ + if (errno != ENOENT) { + err = errno; + ntfs_log_perror("Attribute lookup failed, inode %lld", + (long long)ni->mft_no); + goto err_out; + } + ntfs_attr_put_search_ctx(ctx); + if (err) { + errno = err; + return -1; + } + return 0; +err_out: + if (ctx) + ntfs_attr_put_search_ctx(ctx); + errno = err; + return -1; +} + +/** + * ntfs_inode_sync - write the inode (and its dirty extents) to disk + * @ni: ntfs inode to write + * + * Write the inode @ni to disk as well as its dirty extent inodes if such + * exist and @ni is a base inode. If @ni is an extent inode, only @ni is + * written completely disregarding its base inode and any other extent inodes. + * + * For a base inode with dirty extent inodes if any writes fail for whatever + * reason, the failing inode is skipped and the sync process is continued. At + * the end the error condition that brought about the failure is returned. Thus + * the smallest amount of data loss possible occurs. + * + * Return 0 on success or -1 on error with errno set to the error code. + * The following error codes are defined: + * EINVAL - Invalid arguments were passed to the function. + * EBUSY - Inode and/or one of its extents is busy, try again later. + * EIO - I/O error while writing the inode (or one of its extents). + */ +static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) +{ + int ret = 0; + int err = 0; + if (!ni) { + errno = EINVAL; + ntfs_log_error("Failed to sync NULL inode\n"); + return -1; + } + + ntfs_log_enter("Entering for inode %lld\n", (long long)ni->mft_no); + + /* Update STANDARD_INFORMATION. */ + if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && + ntfs_inode_sync_standard_information(ni)) { + if (!err || errno == EIO) { + err = errno; + if (err != EIO) + err = EBUSY; + } + } + + /* Update FILE_NAME's in the index. */ + if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && + NInoFileNameTestAndClearDirty(ni) && + ntfs_inode_sync_file_name(ni, dir_ni)) { + if (!err || errno == EIO) { + err = errno; + if (err != EIO) + err = EBUSY; + } + ntfs_log_perror("Failed to sync FILE_NAME (inode %lld)", + (long long)ni->mft_no); + NInoFileNameSetDirty(ni); + } + + /* Write out attribute list from cache to disk. */ + if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && + NInoAttrList(ni) && NInoAttrListTestAndClearDirty(ni)) { + ntfs_attr *na; + + na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); + if (!na) { + if (!err || errno == EIO) { + err = errno; + if (err != EIO) + err = EBUSY; + ntfs_log_perror("Attribute list sync failed " + "(open, inode %lld)", + (long long)ni->mft_no); + } + NInoAttrListSetDirty(ni); + goto sync_inode; + } + + if (na->data_size == ni->attr_list_size) { + if (ntfs_attr_pwrite(na, 0, ni->attr_list_size, + ni->attr_list) != ni->attr_list_size) { + if (!err || errno == EIO) { + err = errno; + if (err != EIO) + err = EBUSY; + ntfs_log_perror("Attribute list sync " + "failed (write, inode %lld)", + (long long)ni->mft_no); + } + NInoAttrListSetDirty(ni); + } + } else { + err = EIO; + ntfs_log_error("Attribute list sync failed (bad size, " + "inode %lld)\n", (long long)ni->mft_no); + NInoAttrListSetDirty(ni); + } + ntfs_attr_close(na); + } + +sync_inode: + /* Write this inode out to the $MFT (and $MFTMirr if applicable). */ + if (NInoTestAndClearDirty(ni)) { + if (ntfs_mft_record_write(ni->vol, ni->mft_no, ni->mrec)) { + if (!err || errno == EIO) { + err = errno; + if (err != EIO) + err = EBUSY; + } + NInoSetDirty(ni); + ntfs_log_perror("MFT record sync failed, inode %lld", + (long long)ni->mft_no); + } + } + + /* If this is a base inode with extents write all dirty extents, too. */ + if (ni->nr_extents > 0) { + s32 i; + + for (i = 0; i < ni->nr_extents; ++i) { + ntfs_inode *eni; + + eni = ni->extent_nis[i]; + if (!NInoTestAndClearDirty(eni)) + continue; + + if (ntfs_mft_record_write(eni->vol, eni->mft_no, + eni->mrec)) { + if (!err || errno == EIO) { + err = errno; + if (err != EIO) + err = EBUSY; + } + NInoSetDirty(eni); + ntfs_log_perror("Extent MFT record sync failed," + " inode %lld/%lld", + (long long)ni->mft_no, + (long long)eni->mft_no); + } + } + } + + if (err) { + errno = err; + ret = -1; + } + + ntfs_log_leave("\n"); + return ret; +} + +int ntfs_inode_sync(ntfs_inode *ni) +{ + return (ntfs_inode_sync_in_dir(ni, (ntfs_inode*)NULL)); +} + +/* + * Close an inode with an open parent inode + */ + +int ntfs_inode_close_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) +{ + int res; + + res = ntfs_inode_sync_in_dir(ni, dir_ni); + if (res) { + if (errno != EIO) + errno = EBUSY; + } else + res = ntfs_inode_close(ni); + return (res); +} + +/** + * ntfs_inode_add_attrlist - add attribute list to inode and fill it + * @ni: opened ntfs inode to which add attribute list + * + * Return 0 on success or -1 on error with errno set to the error code. + * The following error codes are defined: + * EINVAL - Invalid arguments were passed to the function. + * EEXIST - Attribute list already exist. + * EIO - Input/Ouput error occurred. + * ENOMEM - Not enough memory to perform add. + */ +int ntfs_inode_add_attrlist(ntfs_inode *ni) +{ + int err; + ntfs_attr_search_ctx *ctx; + u8 *al = NULL, *aln; + int al_len = 0; + ATTR_LIST_ENTRY *ale = NULL; + ntfs_attr *na; + + if (!ni) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + + ntfs_log_trace("inode %llu\n", (unsigned long long) ni->mft_no); + + if (NInoAttrList(ni) || ni->nr_extents) { + errno = EEXIST; + ntfs_log_perror("Inode already has attribute list"); + return -1; + } + + /* Form attribute list. */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) { + err = errno; + goto err_out; + } + /* Walk through all attributes. */ + while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) { + + int ale_size; + + if (ctx->attr->type == AT_ATTRIBUTE_LIST) { + err = EIO; + ntfs_log_perror("Attribute list already present"); + goto put_err_out; + } + + ale_size = (sizeof(ATTR_LIST_ENTRY) + sizeof(ntfschar) * + ctx->attr->name_length + 7) & ~7; + al_len += ale_size; + + aln = realloc(al, al_len); + if (!aln) { + err = errno; + ntfs_log_perror("Failed to realloc %d bytes", al_len); + goto put_err_out; + } + ale = (ATTR_LIST_ENTRY *)(aln + ((u8 *)ale - al)); + al = aln; + + memset(ale, 0, ale_size); + + /* Add attribute to attribute list. */ + ale->type = ctx->attr->type; + ale->length = cpu_to_le16((sizeof(ATTR_LIST_ENTRY) + + sizeof(ntfschar) * ctx->attr->name_length + 7) & ~7); + ale->name_length = ctx->attr->name_length; + ale->name_offset = (u8 *)ale->name - (u8 *)ale; + if (ctx->attr->non_resident) + ale->lowest_vcn = ctx->attr->lowest_vcn; + else + ale->lowest_vcn = 0; + ale->mft_reference = MK_LE_MREF(ni->mft_no, + le16_to_cpu(ni->mrec->sequence_number)); + ale->instance = ctx->attr->instance; + memcpy(ale->name, (u8 *)ctx->attr + + le16_to_cpu(ctx->attr->name_offset), + ctx->attr->name_length * sizeof(ntfschar)); + ale = (ATTR_LIST_ENTRY *)(al + al_len); + } + /* Check for real error occurred. */ + if (errno != ENOENT) { + err = errno; + ntfs_log_perror("%s: Attribute lookup failed, inode %lld", + __FUNCTION__, (long long)ni->mft_no); + goto put_err_out; + } + + /* Set in-memory attribute list. */ + ni->attr_list = al; + ni->attr_list_size = al_len; + NInoSetAttrList(ni); + NInoAttrListSetDirty(ni); + + /* Free space if there is not enough it for $ATTRIBUTE_LIST. */ + if (le32_to_cpu(ni->mrec->bytes_allocated) - + le32_to_cpu(ni->mrec->bytes_in_use) < + offsetof(ATTR_RECORD, resident_end)) { + if (ntfs_inode_free_space(ni, + offsetof(ATTR_RECORD, resident_end))) { + /* Failed to free space. */ + err = errno; + ntfs_log_perror("Failed to free space for attrlist"); + goto rollback; + } + } + + /* Add $ATTRIBUTE_LIST to mft record. */ + if (ntfs_resident_attr_record_add(ni, + AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, 0) < 0) { + err = errno; + ntfs_log_perror("Couldn't add $ATTRIBUTE_LIST to MFT"); + goto rollback; + } + + /* Resize it. */ + na = ntfs_attr_open(ni, AT_ATTRIBUTE_LIST, AT_UNNAMED, 0); + if (!na) { + err = errno; + ntfs_log_perror("Failed to open just added $ATTRIBUTE_LIST"); + goto remove_attrlist_record; + } + if (ntfs_attr_truncate(na, al_len)) { + err = errno; + ntfs_log_perror("Failed to resize just added $ATTRIBUTE_LIST"); + ntfs_attr_close(na); + goto remove_attrlist_record;; + } + + ntfs_attr_put_search_ctx(ctx); + ntfs_attr_close(na); + return 0; + +remove_attrlist_record: + /* Prevent ntfs_attr_recorm_rm from freeing attribute list. */ + ni->attr_list = NULL; + NInoClearAttrList(ni); + /* Remove $ATTRIBUTE_LIST record. */ + ntfs_attr_reinit_search_ctx(ctx); + if (!ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, + CASE_SENSITIVE, 0, NULL, 0, ctx)) { + if (ntfs_attr_record_rm(ctx)) + ntfs_log_perror("Rollback failed to remove attrlist"); + } else + ntfs_log_perror("Rollback failed to find attrlist"); + /* Setup back in-memory runlist. */ + ni->attr_list = al; + ni->attr_list_size = al_len; + NInoSetAttrList(ni); +rollback: + /* + * Scan attribute list for attributes that placed not in the base MFT + * record and move them to it. + */ + ntfs_attr_reinit_search_ctx(ctx); + ale = (ATTR_LIST_ENTRY*)al; + while ((u8*)ale < al + al_len) { + if (MREF_LE(ale->mft_reference) != ni->mft_no) { + if (!ntfs_attr_lookup(ale->type, ale->name, + ale->name_length, + CASE_SENSITIVE, + sle64_to_cpu(ale->lowest_vcn), + NULL, 0, ctx)) { + if (ntfs_attr_record_move_to(ctx, ni)) + ntfs_log_perror("Rollback failed to " + "move attribute"); + } else + ntfs_log_perror("Rollback failed to find attr"); + ntfs_attr_reinit_search_ctx(ctx); + } + ale = (ATTR_LIST_ENTRY*)((u8*)ale + le16_to_cpu(ale->length)); + } + /* Remove in-memory attribute list. */ + ni->attr_list = NULL; + ni->attr_list_size = 0; + NInoClearAttrList(ni); + NInoAttrListClearDirty(ni); +put_err_out: + ntfs_attr_put_search_ctx(ctx); +err_out: + free(al); + errno = err; + return -1; +} + +/** + * ntfs_inode_free_space - free space in the MFT record of an inode + * @ni: ntfs inode in which MFT record needs more free space + * @size: amount of space needed to free + * + * Return 0 on success or -1 on error with errno set to the error code. + */ +int ntfs_inode_free_space(ntfs_inode *ni, int size) +{ + ntfs_attr_search_ctx *ctx; + int freed; + + if (!ni || size < 0) { + errno = EINVAL; + ntfs_log_perror("%s: ni=%p size=%d", __FUNCTION__, ni, size); + return -1; + } + + ntfs_log_trace("Entering for inode %lld, size %d\n", + (unsigned long long)ni->mft_no, size); + + freed = (le32_to_cpu(ni->mrec->bytes_allocated) - + le32_to_cpu(ni->mrec->bytes_in_use)); + + if (size <= freed) + return 0; + + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (!ctx) + return -1; + /* + * $STANDARD_INFORMATION and $ATTRIBUTE_LIST must stay in the base MFT + * record, so position search context on the first attribute after them. + */ + if (ntfs_attr_position(AT_FILE_NAME, ctx)) + goto put_err_out; + + while (1) { + int record_size; + /* + * Check whether attribute is from different MFT record. If so, + * find next, because we don't need such. + */ + while (ctx->ntfs_ino->mft_no != ni->mft_no) { +retry: + if (ntfs_attr_position(AT_UNUSED, ctx)) + goto put_err_out; + } + + if (ntfs_inode_base(ctx->ntfs_ino)->mft_no == FILE_MFT && + ctx->attr->type == AT_DATA) + goto retry; + + if (ctx->attr->type == AT_INDEX_ROOT) + goto retry; + + record_size = le32_to_cpu(ctx->attr->length); + + if (ntfs_attr_record_move_away(ctx, 0)) { + ntfs_log_perror("Failed to move out attribute #2"); + break; + } + freed += record_size; + + /* Check whether we are done. */ + if (size <= freed) { + ntfs_attr_put_search_ctx(ctx); + return 0; + } + /* + * Reposition to first attribute after $STANDARD_INFORMATION + * and $ATTRIBUTE_LIST instead of simply skipping this attribute + * because in the case when we have got only in-memory attribute + * list then ntfs_attr_lookup will fail when it tries to find + * $ATTRIBUTE_LIST. + */ + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_position(AT_FILE_NAME, ctx)) + break; + } +put_err_out: + ntfs_attr_put_search_ctx(ctx); + if (errno == ENOSPC) + ntfs_log_trace("No attributes left that could be moved out.\n"); + return -1; +} + +/** + * ntfs_inode_update_times - update selected time fields for ntfs inode + * @ni: ntfs inode for which update time fields + * @mask: select which time fields should be updated + * + * This function updates time fields to current time. Fields to update are + * selected using @mask (see enum @ntfs_time_update_flags for posssible values). + */ +void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) +{ + ntfs_time now; + + if (!ni) { + ntfs_log_error("%s(): Invalid arguments.\n", __FUNCTION__); + return; + } + + if ((ni->mft_no < FILE_first_user && ni->mft_no != FILE_root) || + NVolReadOnly(ni->vol) || !mask) + return; + + now = ntfs_current_time(); + if (mask & NTFS_UPDATE_ATIME) + ni->last_access_time = now; + if (mask & NTFS_UPDATE_MTIME) + ni->last_data_change_time = now; + if (mask & NTFS_UPDATE_CTIME) + ni->last_mft_change_time = now; + + NInoFileNameSetDirty(ni); + NInoSetDirty(ni); +} + +/** + * ntfs_inode_badclus_bad - check for $Badclus:$Bad data attribute + * @mft_no: mft record number where @attr is present + * @attr: attribute record used to check for the $Bad attribute + * + * Check if the mft record given by @mft_no and @attr contains the bad sector + * list. Please note that mft record numbers describing $Badclus extent inodes + * will not match the current $Badclus:$Bad check. + * + * On success return 1 if the file is $Badclus:$Bad, otherwise return 0. + * On error return -1 with errno set to the error code. + */ +int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr) +{ + int len, ret = 0; + ntfschar *ustr; + + if (!attr) { + ntfs_log_error("Invalid argument.\n"); + errno = EINVAL; + return -1; + } + + if (mft_no != FILE_BadClus) + return 0; + + if (attr->type != AT_DATA) + return 0; + + if ((ustr = ntfs_str2ucs("$Bad", &len)) == NULL) { + ntfs_log_perror("Couldn't convert '$Bad' to Unicode"); + return -1; + } + + if (ustr && ntfs_names_are_equal(ustr, len, + (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)), + attr->name_length, 0, NULL, 0)) + ret = 1; + + ntfs_ucsfree(ustr); + + return ret; +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Get high precision NTFS times + * + * They are returned in following order : create, update, access, change + * provided they fit in requested size. + * + * Returns the modified size if successfull (or 32 if buffer size is null) + * -errno if failed + */ + +int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size) +{ + ntfs_attr_search_ctx *ctx; + STANDARD_INFORMATION *std_info; + u64 *times; + int ret; + + ret = 0; + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (ctx) { + if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, + 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { + ntfs_log_perror("Failed to get standard info (inode %lld)", + (long long)ni->mft_no); + } else { + std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + if (value && (size >= 8)) { + times = (u64*)value; + times[0] = le64_to_cpu(std_info->creation_time); + ret = 8; + if (size >= 16) { + times[1] = le64_to_cpu(std_info->last_data_change_time); + ret = 16; + } + if (size >= 24) { + times[2] = le64_to_cpu(std_info->last_access_time); + ret = 24; + } + if (size >= 32) { + times[3] = le64_to_cpu(std_info->last_mft_change_time); + ret = 32; + } + } else + if (!size) + ret = 32; + else + ret = -ERANGE; + } + ntfs_attr_put_search_ctx(ctx); + } + return (ret ? ret : -errno); +} + +/* + * Set high precision NTFS times + * + * They are expected in this order : create, update, access + * provided they are present in input. The change time is set to + * current time. + * + * The times are inserted directly in the standard_information and + * file names attributes to avoid manipulating low precision times + * + * Returns 0 if success + * -1 if there were an error (described by errno) + */ + +int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, + int flags) +{ + ntfs_attr_search_ctx *ctx; + STANDARD_INFORMATION *std_info; + FILE_NAME_ATTR *fn; + const u64 *times; + ntfs_time now; + int cnt; + int ret; + + ret = -1; + if ((size >= 8) && !(flags & XATTR_CREATE)) { + times = (const u64*)value; + now = ntfs_current_time(); + /* update the standard information attribute */ + ctx = ntfs_attr_get_search_ctx(ni, NULL); + if (ctx) { + if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, + AT_UNNAMED, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + ntfs_log_perror("Failed to get standard info (inode %lld)", + (long long)ni->mft_no); + } else { + std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + /* + * Mark times set to avoid overwriting + * them when the inode is closed. + * The inode structure must also be updated + * (with loss of precision) because of cacheing. + * TODO : use NTFS precision in inode, and + * return sub-second times in getattr() + */ + set_nino_flag(ni, TimesSet); + std_info->creation_time = cpu_to_le64(times[0]); + ni->creation_time + = std_info->creation_time; + if (size >= 16) { + std_info->last_data_change_time = cpu_to_le64(times[1]); + ni->last_data_change_time + = std_info->last_data_change_time; + } + if (size >= 24) { + std_info->last_access_time = cpu_to_le64(times[2]); + ni->last_access_time + = std_info->last_access_time; + } + std_info->last_mft_change_time = now; + ni->last_mft_change_time = now; + ntfs_inode_mark_dirty(ctx->ntfs_ino); + NInoFileNameSetDirty(ni); + + /* update the file names attributes */ + ntfs_attr_reinit_search_ctx(ctx); + cnt = 0; + while (!ntfs_attr_lookup(AT_FILE_NAME, + AT_UNNAMED, 0, CASE_SENSITIVE, + 0, NULL, 0, ctx)) { + fn = (FILE_NAME_ATTR*)((u8 *)ctx->attr + + le16_to_cpu(ctx->attr->value_offset)); + fn->creation_time + = cpu_to_le64(times[0]); + if (size >= 16) + fn->last_data_change_time + = cpu_to_le64(times[1]); + if (size >= 24) + fn->last_access_time + = cpu_to_le64(times[2]); + fn->last_mft_change_time = now; + cnt++; + } + if (cnt) + ret = 0; + else { + ntfs_log_perror("Failed to get file names (inode %lld)", + (long long)ni->mft_no); + } + } + ntfs_attr_put_search_ctx(ctx); + } + } else + if (size < 8) + errno = ERANGE; + else + errno = EEXIST; + return (ret); +} + +#endif /* HAVE_SETXATTR */ diff --git a/libcustomntfs/inode.h b/libcustomntfs/inode.h new file mode 100644 index 00000000..5a6f7da6 --- /dev/null +++ b/libcustomntfs/inode.h @@ -0,0 +1,225 @@ +/* + * inode.h - Defines for NTFS inode handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2001-2004 Anton Altaparmakov + * Copyright (c) 2004-2007 Yura Pakhuchiy + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2006-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_INODE_H +#define _NTFS_INODE_H + +/* Forward declaration */ +typedef struct _ntfs_inode ntfs_inode; + +#include "types.h" +#include "layout.h" +#include "support.h" +#include "volume.h" +#include "ntfstime.h" + +/** + * enum ntfs_inode_state_bits - + * + * Defined bits for the state field in the ntfs_inode structure. + * (f) = files only, (d) = directories only + */ +typedef enum { + NI_Dirty, /* 1: Mft record needs to be written to disk. */ + + /* The NI_AttrList* tests only make sense for base inodes. */ + NI_AttrList, /* 1: Mft record contains an attribute list. */ + NI_AttrListDirty, /* 1: Attribute list needs to be written to the + mft record and then to disk. */ + NI_FileNameDirty, /* 1: FILE_NAME attributes need to be updated + in the index. */ + NI_v3_Extensions, /* 1: JPA v3.x extensions present. */ + NI_TimesSet, /* 1: Use times which were set */ + NI_KnownSize, /* 1: Set if sizes are meaningful */ +} ntfs_inode_state_bits; + +#define test_nino_flag(ni, flag) test_bit(NI_##flag, (ni)->state) +#define set_nino_flag(ni, flag) set_bit(NI_##flag, (ni)->state) +#define clear_nino_flag(ni, flag) clear_bit(NI_##flag, (ni)->state) + +#define test_and_set_nino_flag(ni, flag) \ + test_and_set_bit(NI_##flag, (ni)->state) +#define test_and_clear_nino_flag(ni, flag) \ + test_and_clear_bit(NI_##flag, (ni)->state) + +#define NInoDirty(ni) test_nino_flag(ni, Dirty) +#define NInoSetDirty(ni) set_nino_flag(ni, Dirty) +#define NInoClearDirty(ni) clear_nino_flag(ni, Dirty) +#define NInoTestAndSetDirty(ni) test_and_set_nino_flag(ni, Dirty) +#define NInoTestAndClearDirty(ni) test_and_clear_nino_flag(ni, Dirty) + +#define NInoAttrList(ni) test_nino_flag(ni, AttrList) +#define NInoSetAttrList(ni) set_nino_flag(ni, AttrList) +#define NInoClearAttrList(ni) clear_nino_flag(ni, AttrList) + + +#define test_nino_al_flag(ni, flag) test_nino_flag(ni, AttrList##flag) +#define set_nino_al_flag(ni, flag) set_nino_flag(ni, AttrList##flag) +#define clear_nino_al_flag(ni, flag) clear_nino_flag(ni, AttrList##flag) + +#define test_and_set_nino_al_flag(ni, flag) \ + test_and_set_nino_flag(ni, AttrList##flag) +#define test_and_clear_nino_al_flag(ni, flag) \ + test_and_clear_nino_flag(ni, AttrList##flag) + +#define NInoAttrListDirty(ni) test_nino_al_flag(ni, Dirty) +#define NInoAttrListSetDirty(ni) set_nino_al_flag(ni, Dirty) +#define NInoAttrListClearDirty(ni) clear_nino_al_flag(ni, Dirty) +#define NInoAttrListTestAndSetDirty(ni) test_and_set_nino_al_flag(ni, Dirty) +#define NInoAttrListTestAndClearDirty(ni) test_and_clear_nino_al_flag(ni, Dirty) + +#define NInoFileNameDirty(ni) test_nino_flag(ni, FileNameDirty) +#define NInoFileNameSetDirty(ni) set_nino_flag(ni, FileNameDirty) +#define NInoFileNameClearDirty(ni) clear_nino_flag(ni, FileNameDirty) +#define NInoFileNameTestAndSetDirty(ni) \ + test_and_set_nino_flag(ni, FileNameDirty) +#define NInoFileNameTestAndClearDirty(ni) \ + test_and_clear_nino_flag(ni, FileNameDirty) + +/** + * struct _ntfs_inode - The NTFS in-memory inode structure. + * + * It is just used as an extension to the fields already provided in the VFS + * inode. + */ +struct _ntfs_inode { + u64 mft_no; /* Inode / mft record number. */ + MFT_RECORD *mrec; /* The actual mft record of the inode. */ + ntfs_volume *vol; /* Pointer to the ntfs volume of this inode. */ + unsigned long state; /* NTFS specific flags describing this inode. + See ntfs_inode_state_bits above. */ + FILE_ATTR_FLAGS flags; /* Flags describing the file. + (Copy from STANDARD_INFORMATION) */ + /* + * Attribute list support (for use by the attribute lookup functions). + * Setup during ntfs_open_inode() for all inodes with attribute lists. + * Only valid if NI_AttrList is set in state. + */ + u32 attr_list_size; /* Length of attribute list value in bytes. */ + u8 *attr_list; /* Attribute list value itself. */ + /* Below fields are always valid. */ + s32 nr_extents; /* For a base mft record, the number of + attached extent inodes (0 if none), for + extent records this is -1. */ + union { /* This union is only used if nr_extents != 0. */ + ntfs_inode **extent_nis;/* For nr_extents > 0, array of the + ntfs inodes of the extent mft + records belonging to this base + inode which have been loaded. */ + ntfs_inode *base_ni; /* For nr_extents == -1, the ntfs + inode of the base mft record. */ + }; + + /* Below fields are valid only for base inode. */ + + /* + * These two fields are used to sync filename index and guaranteed to be + * correct, however value in index itself maybe wrong (windows itself + * do not update them properly). + * For directories, they hold the index size, provided the + * flag KnownSize is set. + */ + s64 data_size; /* Data size of unnamed DATA attribute + (or INDEX_ROOT for directories) */ + s64 allocated_size; /* Allocated size stored in the filename + index. (NOTE: Equal to allocated size of + the unnamed data attribute for normal or + encrypted files and to compressed size + of the unnamed data attribute for sparse or + compressed files.) */ + + /* + * These four fields are copy of relevant fields from + * STANDARD_INFORMATION attribute and used to sync it and FILE_NAME + * attribute in the index. + */ + ntfs_time creation_time; + ntfs_time last_data_change_time; + ntfs_time last_mft_change_time; + ntfs_time last_access_time; + /* NTFS 3.x extensions added by JPA */ + /* only if NI_v3_Extensions is set in state */ + le32 owner_id; + le32 security_id; + le64 quota_charged; + le64 usn; +}; + +typedef enum { + NTFS_UPDATE_ATIME = 1 << 0, + NTFS_UPDATE_MTIME = 1 << 1, + NTFS_UPDATE_CTIME = 1 << 2, +} ntfs_time_update_flags; + +#define NTFS_UPDATE_MCTIME (NTFS_UPDATE_MTIME | NTFS_UPDATE_CTIME) +#define NTFS_UPDATE_AMCTIME (NTFS_UPDATE_ATIME | NTFS_UPDATE_MCTIME) + +extern ntfs_inode *ntfs_inode_base(ntfs_inode *ni); + +extern ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol); + +extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref); + +extern int ntfs_inode_close(ntfs_inode *ni); +extern int ntfs_inode_close_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni); + +#if CACHE_NIDATA_SIZE + +struct CACHED_GENERIC; + +extern int ntfs_inode_real_close(ntfs_inode *ni); +extern void ntfs_inode_invalidate(ntfs_volume *vol, const MFT_REF mref); +extern void ntfs_inode_nidata_free(const struct CACHED_GENERIC *cached); +extern int ntfs_inode_nidata_hash(const struct CACHED_GENERIC *item); + +#endif + + +extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, + const MFT_REF mref); + +extern int ntfs_inode_attach_all_extents(ntfs_inode *ni); + +extern void ntfs_inode_mark_dirty(ntfs_inode *ni); + +extern void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask); + +extern int ntfs_inode_sync(ntfs_inode *ni); + +extern int ntfs_inode_add_attrlist(ntfs_inode *ni); + +extern int ntfs_inode_free_space(ntfs_inode *ni, int size); + +extern int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *a); + +extern int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size); + +extern int ntfs_inode_set_times(ntfs_inode *ni, const char *value, + size_t size, int flags); + +/* debugging */ +#define debug_double_inode(num, type) +#define debug_cached_inode(ni) + +#endif /* defined _NTFS_INODE_H */ diff --git a/libcustomntfs/layout.h b/libcustomntfs/layout.h new file mode 100644 index 00000000..8670557e --- /dev/null +++ b/libcustomntfs/layout.h @@ -0,0 +1,2661 @@ +/* + * layout.h - Ntfs on-disk layout structures. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2005 Anton Altaparmakov + * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2005-2006 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_LAYOUT_H +#define _NTFS_LAYOUT_H + +#include "types.h" +#include "endians.h" +#include "support.h" + +/* The NTFS oem_id */ +#define magicNTFS const_cpu_to_le64(0x202020205346544e) /* "NTFS " */ +#define NTFS_SB_MAGIC 0x5346544e /* 'NTFS' */ + +/* + * Location of bootsector on partition: + * The standard NTFS_BOOT_SECTOR is on sector 0 of the partition. + * On NT4 and above there is one backup copy of the boot sector to + * be found on the last sector of the partition (not normally accessible + * from within Windows as the bootsector contained number of sectors + * value is one less than the actual value!). + * On versions of NT 3.51 and earlier, the backup copy was located at + * number of sectors/2 (integer divide), i.e. in the middle of the volume. + */ + +/** + * struct BIOS_PARAMETER_BLOCK - BIOS parameter block (bpb) structure. + */ +typedef struct { + u16 bytes_per_sector; /* Size of a sector in bytes. */ + u8 sectors_per_cluster; /* Size of a cluster in sectors. */ + u16 reserved_sectors; /* zero */ + u8 fats; /* zero */ + u16 root_entries; /* zero */ + u16 sectors; /* zero */ + u8 media_type; /* 0xf8 = hard disk */ + u16 sectors_per_fat; /* zero */ +/*0x0d*/u16 sectors_per_track; /* Required to boot Windows. */ +/*0x0f*/u16 heads; /* Required to boot Windows. */ +/*0x11*/u32 hidden_sectors; /* Offset to the start of the partition + relative to the disk in sectors. + Required to boot Windows. */ +/*0x15*/u32 large_sectors; /* zero */ +/* sizeof() = 25 (0x19) bytes */ +} __attribute__((__packed__)) BIOS_PARAMETER_BLOCK; + +/** + * struct NTFS_BOOT_SECTOR - NTFS boot sector structure. + */ +typedef struct { + u8 jump[3]; /* Irrelevant (jump to boot up code).*/ + u64 oem_id; /* Magic "NTFS ". */ +/*0x0b*/BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */ + u8 physical_drive; /* 0x00 floppy, 0x80 hard disk */ + u8 current_head; /* zero */ + u8 extended_boot_signature; /* 0x80 */ + u8 reserved2; /* zero */ +/*0x28*/s64 number_of_sectors; /* Number of sectors in volume. Gives + maximum volume size of 2^63 sectors. + Assuming standard sector size of 512 + bytes, the maximum byte size is + approx. 4.7x10^21 bytes. (-; */ + s64 mft_lcn; /* Cluster location of mft data. */ + s64 mftmirr_lcn; /* Cluster location of copy of mft. */ + s8 clusters_per_mft_record; /* Mft record size in clusters. */ + u8 reserved0[3]; /* zero */ + s8 clusters_per_index_record; /* Index block size in clusters. */ + u8 reserved1[3]; /* zero */ + u64 volume_serial_number; /* Irrelevant (serial number). */ + u32 checksum; /* Boot sector checksum. */ +/*0x54*/u8 bootstrap[426]; /* Irrelevant (boot up code). */ + u16 end_of_sector_marker; /* End of bootsector magic. Always is + 0xaa55 in little endian. */ +/* sizeof() = 512 (0x200) bytes */ +} __attribute__((__packed__)) NTFS_BOOT_SECTOR; + +/** + * enum NTFS_RECORD_TYPES - + * + * Magic identifiers present at the beginning of all ntfs record containing + * records (like mft records for example). + */ +typedef enum { + /* Found in $MFT/$DATA. */ + magic_FILE = const_cpu_to_le32(0x454c4946), /* Mft entry. */ + magic_INDX = const_cpu_to_le32(0x58444e49), /* Index buffer. */ + magic_HOLE = const_cpu_to_le32(0x454c4f48), /* ? (NTFS 3.0+?) */ + + /* Found in $LogFile/$DATA. */ + magic_RSTR = const_cpu_to_le32(0x52545352), /* Restart page. */ + magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */ + + /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */ + magic_CHKD = const_cpu_to_le32(0x444b4843), /* Modified by chkdsk. */ + + /* Found in all ntfs record containing records. */ + magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector + transfer was detected. */ + + /* + * Found in $LogFile/$DATA when a page is full or 0xff bytes and is + * thus not initialized. User has to initialize the page before using + * it. + */ + magic_empty = const_cpu_to_le32(0xffffffff),/* Record is empty and has + to be initialized before + it can be used. */ +} NTFS_RECORD_TYPES; + +/* + * Generic magic comparison macros. Finally found a use for the ## preprocessor + * operator! (-8 + */ +#define ntfs_is_magic(x, m) ( (u32)(x) == (u32)magic_##m ) +#define ntfs_is_magicp(p, m) ( *(u32*)(p) == (u32)magic_##m ) + +/* + * Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above. + */ +#define ntfs_is_file_record(x) ( ntfs_is_magic (x, FILE) ) +#define ntfs_is_file_recordp(p) ( ntfs_is_magicp(p, FILE) ) +#define ntfs_is_mft_record(x) ( ntfs_is_file_record(x) ) +#define ntfs_is_mft_recordp(p) ( ntfs_is_file_recordp(p) ) +#define ntfs_is_indx_record(x) ( ntfs_is_magic (x, INDX) ) +#define ntfs_is_indx_recordp(p) ( ntfs_is_magicp(p, INDX) ) +#define ntfs_is_hole_record(x) ( ntfs_is_magic (x, HOLE) ) +#define ntfs_is_hole_recordp(p) ( ntfs_is_magicp(p, HOLE) ) + +#define ntfs_is_rstr_record(x) ( ntfs_is_magic (x, RSTR) ) +#define ntfs_is_rstr_recordp(p) ( ntfs_is_magicp(p, RSTR) ) +#define ntfs_is_rcrd_record(x) ( ntfs_is_magic (x, RCRD) ) +#define ntfs_is_rcrd_recordp(p) ( ntfs_is_magicp(p, RCRD) ) + +#define ntfs_is_chkd_record(x) ( ntfs_is_magic (x, CHKD) ) +#define ntfs_is_chkd_recordp(p) ( ntfs_is_magicp(p, CHKD) ) + +#define ntfs_is_baad_record(x) ( ntfs_is_magic (x, BAAD) ) +#define ntfs_is_baad_recordp(p) ( ntfs_is_magicp(p, BAAD) ) + +#define ntfs_is_empty_record(x) ( ntfs_is_magic (x, empty) ) +#define ntfs_is_empty_recordp(p) ( ntfs_is_magicp(p, empty) ) + + +#define NTFS_BLOCK_SIZE 512 +#define NTFS_BLOCK_SIZE_BITS 9 + +/** + * struct NTFS_RECORD - + * + * The Update Sequence Array (usa) is an array of the u16 values which belong + * to the end of each sector protected by the update sequence record in which + * this array is contained. Note that the first entry is the Update Sequence + * Number (usn), a cyclic counter of how many times the protected record has + * been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All + * last u16's of each sector have to be equal to the usn (during reading) or + * are set to it (during writing). If they are not, an incomplete multi sector + * transfer has occurred when the data was written. + * The maximum size for the update sequence array is fixed to: + * maximum size = usa_ofs + (usa_count * 2) = 510 bytes + * The 510 bytes comes from the fact that the last u16 in the array has to + * (obviously) finish before the last u16 of the first 512-byte sector. + * This formula can be used as a consistency check in that usa_ofs + + * (usa_count * 2) has to be less than or equal to 510. + */ +typedef struct { + NTFS_RECORD_TYPES magic;/* A four-byte magic identifying the + record type and/or status. */ + u16 usa_ofs; /* Offset to the Update Sequence Array (usa) + from the start of the ntfs record. */ + u16 usa_count; /* Number of u16 sized entries in the usa + including the Update Sequence Number (usn), + thus the number of fixups is the usa_count + minus 1. */ +} __attribute__((__packed__)) NTFS_RECORD; + +/** + * enum NTFS_SYSTEM_FILES - System files mft record numbers. + * + * All these files are always marked as used in the bitmap attribute of the + * mft; presumably in order to avoid accidental allocation for random other + * mft records. Also, the sequence number for each of the system files is + * always equal to their mft record number and it is never modified. + */ +typedef enum { + FILE_MFT = 0, /* Master file table (mft). Data attribute + contains the entries and bitmap attribute + records which ones are in use (bit==1). */ + FILE_MFTMirr = 1, /* Mft mirror: copy of first four mft records + in data attribute. If cluster size > 4kiB, + copy of first N mft records, with + N = cluster_size / mft_record_size. */ + FILE_LogFile = 2, /* Journalling log in data attribute. */ + FILE_Volume = 3, /* Volume name attribute and volume information + attribute (flags and ntfs version). Windows + refers to this file as volume DASD (Direct + Access Storage Device). */ + FILE_AttrDef = 4, /* Array of attribute definitions in data + attribute. */ + FILE_root = 5, /* Root directory. */ + FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in + data attribute. */ + FILE_Boot = 7, /* Boot sector (always at cluster 0) in data + attribute. */ + FILE_BadClus = 8, /* Contains all bad clusters in the non-resident + data attribute. */ + FILE_Secure = 9, /* Shared security descriptors in data attribute + and two indexes into the descriptors. + Appeared in Windows 2000. Before that, this + file was named $Quota but was unused. */ + FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode + characters in data attribute. */ + FILE_Extend = 11, /* Directory containing other system files (eg. + $ObjId, $Quota, $Reparse and $UsnJrnl). This + is new to NTFS3.0. */ + FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */ + FILE_reserved13 = 13, + FILE_reserved14 = 14, + FILE_reserved15 = 15, + FILE_first_user = 16, /* First user file, used as test limit for + whether to allow opening a file or not. */ +} NTFS_SYSTEM_FILES; + +/** + * enum MFT_RECORD_FLAGS - + * + * These are the so far known MFT_RECORD_* flags (16-bit) which contain + * information about the mft record in which they are present. + * + * MFT_RECORD_IS_4 exists on all $Extend sub-files. + * It seems that it marks it is a metadata file with MFT record >24, however, + * it is unknown if it is limited to metadata files only. + * + * MFT_RECORD_IS_VIEW_INDEX exists on every metafile with a non directory + * index, that means an INDEX_ROOT and an INDEX_ALLOCATION with a name other + * than "$I30". It is unknown if it is limited to metadata files only. + */ +typedef enum { + MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001), + MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002), + MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004), + MFT_RECORD_IS_VIEW_INDEX = const_cpu_to_le16(0x0008), + MFT_REC_SPACE_FILLER = 0xffff, /* Just to make flags + 16-bit. */ +} __attribute__((__packed__)) MFT_RECORD_FLAGS; + +/* + * mft references (aka file references or file record segment references) are + * used whenever a structure needs to refer to a record in the mft. + * + * A reference consists of a 48-bit index into the mft and a 16-bit sequence + * number used to detect stale references. + * + * For error reporting purposes we treat the 48-bit index as a signed quantity. + * + * The sequence number is a circular counter (skipping 0) describing how many + * times the referenced mft record has been (re)used. This has to match the + * sequence number of the mft record being referenced, otherwise the reference + * is considered stale and removed (FIXME: only ntfsck or the driver itself?). + * + * If the sequence number is zero it is assumed that no sequence number + * consistency checking should be performed. + * + * FIXME: Since inodes are 32-bit as of now, the driver needs to always check + * for high_part being 0 and if not either BUG(), cause a panic() or handle + * the situation in some other way. This shouldn't be a problem as a volume has + * to become HUGE in order to need more than 32-bits worth of mft records. + * Assuming the standard mft record size of 1kb only the records (never mind + * the non-resident attributes, etc.) would require 4Tb of space on their own + * for the first 32 bits worth of records. This is only if some strange person + * doesn't decide to foul play and make the mft sparse which would be a really + * horrible thing to do as it would trash our current driver implementation. )-: + * Do I hear screams "we want 64-bit inodes!" ?!? (-; + * + * FIXME: The mft zone is defined as the first 12% of the volume. This space is + * reserved so that the mft can grow contiguously and hence doesn't become + * fragmented. Volume free space includes the empty part of the mft zone and + * when the volume's free 88% are used up, the mft zone is shrunk by a factor + * of 2, thus making more space available for more files/data. This process is + * repeated every time there is no more free space except for the mft zone until + * there really is no more free space. + */ + +/* + * Typedef the MFT_REF as a 64-bit value for easier handling. + * Also define two unpacking macros to get to the reference (MREF) and + * sequence number (MSEQNO) respectively. + * The _LE versions are to be applied on little endian MFT_REFs. + * Note: The _LE versions will return a CPU endian formatted value! + */ +#define MFT_REF_MASK_CPU 0x0000ffffffffffffULL +#define MFT_REF_MASK_LE const_cpu_to_le64(MFT_REF_MASK_CPU) + +typedef u64 MFT_REF; + +#define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ + ((MFT_REF)(m) & MFT_REF_MASK_CPU))) +#define MK_LE_MREF(m, s) const_cpu_to_le64(((MFT_REF)(((MFT_REF)(s) << 48) | \ + ((MFT_REF)(m) & MFT_REF_MASK_CPU)))) + +#define MREF(x) ((u64)((x) & MFT_REF_MASK_CPU)) +#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff)) +#define MREF_LE(x) ((u64)(const_le64_to_cpu(x) & MFT_REF_MASK_CPU)) +#define MSEQNO_LE(x) ((u16)((const_le64_to_cpu(x) >> 48) & 0xffff)) + +#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? 1 : 0) +#define ERR_MREF(x) ((u64)((s64)(x))) +#define MREF_ERR(x) ((int)((s64)(x))) + +/** + * struct MFT_RECORD - An MFT record layout (NTFS 3.1+) + * + * The mft record header present at the beginning of every record in the mft. + * This is followed by a sequence of variable length attribute records which + * is terminated by an attribute of type AT_END which is a truncated attribute + * in that it only consists of the attribute type code AT_END and none of the + * other members of the attribute structure are present. + */ +typedef struct { +/*Ofs*/ +/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ + NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */ + u16 usa_ofs; /* See NTFS_RECORD definition above. */ + u16 usa_count; /* See NTFS_RECORD definition above. */ + +/* 8*/ LSN lsn; /* $LogFile sequence number for this record. + Changed every time the record is modified. */ +/* 16*/ u16 sequence_number; /* Number of times this mft record has been + reused. (See description for MFT_REF + above.) NOTE: The increment (skipping zero) + is done when the file is deleted. NOTE: If + this is zero it is left zero. */ +/* 18*/ u16 link_count; /* Number of hard links, i.e. the number of + directory entries referencing this record. + NOTE: Only used in mft base records. + NOTE: When deleting a directory entry we + check the link_count and if it is 1 we + delete the file. Otherwise we delete the + FILE_NAME_ATTR being referenced by the + directory entry from the mft record and + decrement the link_count. + FIXME: Careful with Win32 + DOS names! */ +/* 20*/ u16 attrs_offset; /* Byte offset to the first attribute in this + mft record from the start of the mft record. + NOTE: Must be aligned to 8-byte boundary. */ +/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file + is deleted, the MFT_RECORD_IN_USE flag is + set to zero. */ +/* 24*/ u32 bytes_in_use; /* Number of bytes used in this mft record. + NOTE: Must be aligned to 8-byte boundary. */ +/* 28*/ u32 bytes_allocated; /* Number of bytes allocated for this mft + record. This should be equal to the mft + record size. */ +/* 32*/ MFT_REF base_mft_record; /* This is zero for base mft records. + When it is not zero it is a mft reference + pointing to the base mft record to which + this record belongs (this is then used to + locate the attribute list attribute present + in the base record which describes this + extension record and hence might need + modification when the extension record + itself is modified, also locating the + attribute list also means finding the other + potential extents, belonging to the non-base + mft record). */ +/* 40*/ u16 next_attr_instance; /* The instance number that will be + assigned to the next attribute added to this + mft record. NOTE: Incremented each time + after it is used. NOTE: Every time the mft + record is reused this number is set to zero. + NOTE: The first instance number is always 0. + */ +/* The below fields are specific to NTFS 3.1+ (Windows XP and above): */ +/* 42*/ u16 reserved; /* Reserved/alignment. */ +/* 44*/ u32 mft_record_number; /* Number of this mft record. */ +/* sizeof() = 48 bytes */ +/* + * When (re)using the mft record, we place the update sequence array at this + * offset, i.e. before we start with the attributes. This also makes sense, + * otherwise we could run into problems with the update sequence array + * containing in itself the last two bytes of a sector which would mean that + * multi sector transfer protection wouldn't work. As you can't protect data + * by overwriting it since you then can't get it back... + * When reading we obviously use the data from the ntfs record header. + */ +} __attribute__((__packed__)) MFT_RECORD; + +/** + * struct MFT_RECORD_OLD - An MFT record layout (NTFS <=3.0) + * + * This is the version without the NTFS 3.1+ specific fields. + */ +typedef struct { +/*Ofs*/ +/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ + NTFS_RECORD_TYPES magic;/* Usually the magic is "FILE". */ + u16 usa_ofs; /* See NTFS_RECORD definition above. */ + u16 usa_count; /* See NTFS_RECORD definition above. */ + +/* 8*/ LSN lsn; /* $LogFile sequence number for this record. + Changed every time the record is modified. */ +/* 16*/ u16 sequence_number; /* Number of times this mft record has been + reused. (See description for MFT_REF + above.) NOTE: The increment (skipping zero) + is done when the file is deleted. NOTE: If + this is zero it is left zero. */ +/* 18*/ u16 link_count; /* Number of hard links, i.e. the number of + directory entries referencing this record. + NOTE: Only used in mft base records. + NOTE: When deleting a directory entry we + check the link_count and if it is 1 we + delete the file. Otherwise we delete the + FILE_NAME_ATTR being referenced by the + directory entry from the mft record and + decrement the link_count. + FIXME: Careful with Win32 + DOS names! */ +/* 20*/ u16 attrs_offset; /* Byte offset to the first attribute in this + mft record from the start of the mft record. + NOTE: Must be aligned to 8-byte boundary. */ +/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file + is deleted, the MFT_RECORD_IN_USE flag is + set to zero. */ +/* 24*/ u32 bytes_in_use; /* Number of bytes used in this mft record. + NOTE: Must be aligned to 8-byte boundary. */ +/* 28*/ u32 bytes_allocated; /* Number of bytes allocated for this mft + record. This should be equal to the mft + record size. */ +/* 32*/ MFT_REF base_mft_record; /* This is zero for base mft records. + When it is not zero it is a mft reference + pointing to the base mft record to which + this record belongs (this is then used to + locate the attribute list attribute present + in the base record which describes this + extension record and hence might need + modification when the extension record + itself is modified, also locating the + attribute list also means finding the other + potential extents, belonging to the non-base + mft record). */ +/* 40*/ u16 next_attr_instance; /* The instance number that will be + assigned to the next attribute added to this + mft record. NOTE: Incremented each time + after it is used. NOTE: Every time the mft + record is reused this number is set to zero. + NOTE: The first instance number is always 0. + */ +/* sizeof() = 42 bytes */ +/* + * When (re)using the mft record, we place the update sequence array at this + * offset, i.e. before we start with the attributes. This also makes sense, + * otherwise we could run into problems with the update sequence array + * containing in itself the last two bytes of a sector which would mean that + * multi sector transfer protection wouldn't work. As you can't protect data + * by overwriting it since you then can't get it back... + * When reading we obviously use the data from the ntfs record header. + */ +} __attribute__((__packed__)) MFT_RECORD_OLD; + +/** + * enum ATTR_TYPES - System defined attributes (32-bit). + * + * Each attribute type has a corresponding attribute name (Unicode string of + * maximum 64 character length) as described by the attribute definitions + * present in the data attribute of the $AttrDef system file. + * + * On NTFS 3.0 volumes the names are just as the types are named in the below + * enum exchanging AT_ for the dollar sign ($). If that isn't a revealing + * choice of symbol... (-; + */ +typedef enum { + AT_UNUSED = const_cpu_to_le32( 0), + AT_STANDARD_INFORMATION = const_cpu_to_le32( 0x10), + AT_ATTRIBUTE_LIST = const_cpu_to_le32( 0x20), + AT_FILE_NAME = const_cpu_to_le32( 0x30), + AT_OBJECT_ID = const_cpu_to_le32( 0x40), + AT_SECURITY_DESCRIPTOR = const_cpu_to_le32( 0x50), + AT_VOLUME_NAME = const_cpu_to_le32( 0x60), + AT_VOLUME_INFORMATION = const_cpu_to_le32( 0x70), + AT_DATA = const_cpu_to_le32( 0x80), + AT_INDEX_ROOT = const_cpu_to_le32( 0x90), + AT_INDEX_ALLOCATION = const_cpu_to_le32( 0xa0), + AT_BITMAP = const_cpu_to_le32( 0xb0), + AT_REPARSE_POINT = const_cpu_to_le32( 0xc0), + AT_EA_INFORMATION = const_cpu_to_le32( 0xd0), + AT_EA = const_cpu_to_le32( 0xe0), + AT_PROPERTY_SET = const_cpu_to_le32( 0xf0), + AT_LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100), + AT_FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000), + AT_END = const_cpu_to_le32(0xffffffff), +} ATTR_TYPES; + +/** + * enum COLLATION_RULES - The collation rules for sorting views/indexes/etc + * (32-bit). + * + * COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary + * Unicode values, except that when a character can be uppercased, the + * upper case value collates before the lower case one. + * COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation + * is done very much like COLLATION_UNICODE_STRING. In fact I have no idea + * what the difference is. Perhaps the difference is that file names + * would treat some special characters in an odd way (see + * unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[] + * for what I mean but COLLATION_UNICODE_STRING would not give any special + * treatment to any characters at all, but this is speculation. + * COLLATION_NTOFS_ULONG - Sorting is done according to ascending u32 key + * values. E.g. used for $SII index in FILE_Secure, which sorts by + * security_id (u32). + * COLLATION_NTOFS_SID - Sorting is done according to ascending SID values. + * E.g. used for $O index in FILE_Extend/$Quota. + * COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash + * values and second by ascending security_id values. E.g. used for $SDH + * index in FILE_Secure. + * COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending + * u32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which + * sorts by object_id (16-byte), by splitting up the object_id in four + * u32 values and using them as individual keys. E.g. take the following + * two security_ids, stored as follows on disk: + * 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59 + * 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45 + * To compare them, they are split into four u32 values each, like so: + * 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081 + * 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179 + * Now, it is apparent why the 2nd object_id collates after the 1st: the + * first u32 value of the 1st object_id is less than the first u32 of + * the 2nd object_id. If the first u32 values of both object_ids were + * equal then the second u32 values would be compared, etc. + */ +typedef enum { + COLLATION_BINARY = const_cpu_to_le32(0), /* Collate by binary + compare where the first byte is most + significant. */ + COLLATION_FILE_NAME = const_cpu_to_le32(1), /* Collate file names + as Unicode strings. */ + COLLATION_UNICODE_STRING = const_cpu_to_le32(2), /* Collate Unicode + strings by comparing their binary + Unicode values, except that when a + character can be uppercased, the upper + case value collates before the lower + case one. */ + COLLATION_NTOFS_ULONG = const_cpu_to_le32(16), + COLLATION_NTOFS_SID = const_cpu_to_le32(17), + COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(18), + COLLATION_NTOFS_ULONGS = const_cpu_to_le32(19), +} COLLATION_RULES; + +/** + * enum ATTR_DEF_FLAGS - + * + * The flags (32-bit) describing attribute properties in the attribute + * definition structure. FIXME: This information is based on Regis's + * information and, according to him, it is not certain and probably + * incomplete. The INDEXABLE flag is fairly certainly correct as only the file + * name attribute has this flag set and this is the only attribute indexed in + * NT4. + */ +typedef enum { + ATTR_DEF_INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be + indexed. */ + ATTR_DEF_MULTIPLE = const_cpu_to_le32(0x04), /* Attribute type + can be present multiple times in the + mft records of an inode. */ + ATTR_DEF_NOT_ZERO = const_cpu_to_le32(0x08), /* Attribute value + must contain at least one non-zero + byte. */ + ATTR_DEF_INDEXED_UNIQUE = const_cpu_to_le32(0x10), /* Attribute must be + indexed and the attribute value must be + unique for the attribute type in all of + the mft records of an inode. */ + ATTR_DEF_NAMED_UNIQUE = const_cpu_to_le32(0x20), /* Attribute must be + named and the name must be unique for + the attribute type in all of the mft + records of an inode. */ + ATTR_DEF_RESIDENT = const_cpu_to_le32(0x40), /* Attribute must be + resident. */ + ATTR_DEF_ALWAYS_LOG = const_cpu_to_le32(0x80), /* Always log + modifications to this attribute, + regardless of whether it is resident or + non-resident. Without this, only log + modifications if the attribute is + resident. */ +} ATTR_DEF_FLAGS; + +/** + * struct ATTR_DEF - + * + * The data attribute of FILE_AttrDef contains a sequence of attribute + * definitions for the NTFS volume. With this, it is supposed to be safe for an + * older NTFS driver to mount a volume containing a newer NTFS version without + * damaging it (that's the theory. In practice it's: not damaging it too much). + * Entries are sorted by attribute type. The flags describe whether the + * attribute can be resident/non-resident and possibly other things, but the + * actual bits are unknown. + */ +typedef struct { +/*hex ofs*/ +/* 0*/ ntfschar name[0x40]; /* Unicode name of the attribute. Zero + terminated. */ +/* 80*/ ATTR_TYPES type; /* Type of the attribute. */ +/* 84*/ u32 display_rule; /* Default display rule. + FIXME: What does it mean? (AIA) */ +/* 88*/ COLLATION_RULES collation_rule; /* Default collation rule. */ +/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */ +/* 90*/ s64 min_size; /* Optional minimum attribute size. */ +/* 98*/ s64 max_size; /* Maximum size of attribute. */ +/* sizeof() = 0xa0 or 160 bytes */ +} __attribute__((__packed__)) ATTR_DEF; + +/** + * enum ATTR_FLAGS - Attribute flags (16-bit). + */ +typedef enum { + ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001), + ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression + method mask. Also, first + illegal value. */ + ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000), + ATTR_IS_SPARSE = const_cpu_to_le16(0x8000), +} __attribute__((__packed__)) ATTR_FLAGS; + +/* + * Attribute compression. + * + * Only the data attribute is ever compressed in the current ntfs driver in + * Windows. Further, compression is only applied when the data attribute is + * non-resident. Finally, to use compression, the maximum allowed cluster size + * on a volume is 4kib. + * + * The compression method is based on independently compressing blocks of X + * clusters, where X is determined from the compression_unit value found in the + * non-resident attribute record header (more precisely: X = 2^compression_unit + * clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4). + * + * There are three different cases of how a compression block of X clusters + * can be stored: + * + * 1) The data in the block is all zero (a sparse block): + * This is stored as a sparse block in the runlist, i.e. the runlist + * entry has length = X and lcn = -1. The mapping pairs array actually + * uses a delta_lcn value length of 0, i.e. delta_lcn is not present at + * all, which is then interpreted by the driver as lcn = -1. + * NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then + * the same principles apply as above, except that the length is not + * restricted to being any particular value. + * + * 2) The data in the block is not compressed: + * This happens when compression doesn't reduce the size of the block + * in clusters. I.e. if compression has a small effect so that the + * compressed data still occupies X clusters, then the uncompressed data + * is stored in the block. + * This case is recognised by the fact that the runlist entry has + * length = X and lcn >= 0. The mapping pairs array stores this as + * normal with a run length of X and some specific delta_lcn, i.e. + * delta_lcn has to be present. + * + * 3) The data in the block is compressed: + * The common case. This case is recognised by the fact that the run + * list entry has length L < X and lcn >= 0. The mapping pairs array + * stores this as normal with a run length of X and some specific + * delta_lcn, i.e. delta_lcn has to be present. This runlist entry is + * immediately followed by a sparse entry with length = X - L and + * lcn = -1. The latter entry is to make up the vcn counting to the + * full compression block size X. + * + * In fact, life is more complicated because adjacent entries of the same type + * can be coalesced. This means that one has to keep track of the number of + * clusters handled and work on a basis of X clusters at a time being one + * block. An example: if length L > X this means that this particular runlist + * entry contains a block of length X and part of one or more blocks of length + * L - X. Another example: if length L < X, this does not necessarily mean that + * the block is compressed as it might be that the lcn changes inside the block + * and hence the following runlist entry describes the continuation of the + * potentially compressed block. The block would be compressed if the + * following runlist entry describes at least X - L sparse clusters, thus + * making up the compression block length as described in point 3 above. (Of + * course, there can be several runlist entries with small lengths so that the + * sparse entry does not follow the first data containing entry with + * length < X.) + * + * NOTE: At the end of the compressed attribute value, there most likely is not + * just the right amount of data to make up a compression block, thus this data + * is not even attempted to be compressed. It is just stored as is, unless + * the number of clusters it occupies is reduced when compressed in which case + * it is stored as a compressed compression block, complete with sparse + * clusters at the end. + */ + +/** + * enum RESIDENT_ATTR_FLAGS - Flags of resident attributes (8-bit). + */ +typedef enum { + RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index + (has implications for deleting and + modifying the attribute). */ +} __attribute__((__packed__)) RESIDENT_ATTR_FLAGS; + +/** + * struct ATTR_RECORD - Attribute record header. + * + * Always aligned to 8-byte boundary. + */ +typedef struct { +/*Ofs*/ +/* 0*/ ATTR_TYPES type; /* The (32-bit) type of the attribute. */ +/* 4*/ u32 length; /* Byte size of the resident part of the + attribute (aligned to 8-byte boundary). + Used to get to the next attribute. */ +/* 8*/ u8 non_resident; /* If 0, attribute is resident. + If 1, attribute is non-resident. */ +/* 9*/ u8 name_length; /* Unicode character size of name of attribute. + 0 if unnamed. */ +/* 10*/ u16 name_offset; /* If name_length != 0, the byte offset to the + beginning of the name from the attribute + record. Note that the name is stored as a + Unicode string. When creating, place offset + just at the end of the record header. Then, + follow with attribute value or mapping pairs + array, resident and non-resident attributes + respectively, aligning to an 8-byte + boundary. */ +/* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */ +/* 14*/ u16 instance; /* The instance of this attribute record. This + number is unique within this mft record (see + MFT_RECORD/next_attribute_instance notes + above for more details). */ +/* 16*/ union { + /* Resident attributes. */ + struct { +/* 16 */ u32 value_length; /* Byte size of attribute value. */ +/* 20 */ u16 value_offset; /* Byte offset of the attribute + value from the start of the + attribute record. When creating, + align to 8-byte boundary if we + have a name present as this might + not have a length of a multiple + of 8-bytes. */ +/* 22 */ RESIDENT_ATTR_FLAGS resident_flags; /* See above. */ +/* 23 */ s8 reservedR; /* Reserved/alignment to 8-byte + boundary. */ +/* 24 */ void *resident_end[0]; /* Use offsetof(ATTR_RECORD, + resident_end) to get size of + a resident attribute. */ + } __attribute__((__packed__)); + /* Non-resident attributes. */ + struct { +/* 16*/ VCN lowest_vcn; /* Lowest valid virtual cluster number + for this portion of the attribute value or + 0 if this is the only extent (usually the + case). - Only when an attribute list is used + does lowest_vcn != 0 ever occur. */ +/* 24*/ VCN highest_vcn; /* Highest valid vcn of this extent of + the attribute value. - Usually there is only one + portion, so this usually equals the attribute + value size in clusters minus 1. Can be -1 for + zero length files. Can be 0 for "single extent" + attributes. */ +/* 32*/ u16 mapping_pairs_offset; /* Byte offset from the + beginning of the structure to the mapping pairs + array which contains the mappings between the + vcns and the logical cluster numbers (lcns). + When creating, place this at the end of this + record header aligned to 8-byte boundary. */ +/* 34*/ u8 compression_unit; /* The compression unit expressed + as the log to the base 2 of the number of + clusters in a compression unit. 0 means not + compressed. (This effectively limits the + compression unit size to be a power of two + clusters.) WinNT4 only uses a value of 4. */ +/* 35*/ u8 reserved1[5]; /* Align to 8-byte boundary. */ +/* The sizes below are only used when lowest_vcn is zero, as otherwise it would + be difficult to keep them up-to-date.*/ +/* 40*/ s64 allocated_size; /* Byte size of disk space + allocated to hold the attribute value. Always + is a multiple of the cluster size. When a file + is compressed, this field is a multiple of the + compression block size (2^compression_unit) and + it represents the logically allocated space + rather than the actual on disk usage. For this + use the compressed_size (see below). */ +/* 48*/ s64 data_size; /* Byte size of the attribute + value. Can be larger than allocated_size if + attribute value is compressed or sparse. */ +/* 56*/ s64 initialized_size; /* Byte size of initialized + portion of the attribute value. Usually equals + data_size. */ +/* 64 */ void *non_resident_end[0]; /* Use offsetof(ATTR_RECORD, + non_resident_end) to get + size of a non resident + attribute. */ +/* sizeof(uncompressed attr) = 64*/ +/* 64*/ s64 compressed_size; /* Byte size of the attribute + value after compression. Only present when + compressed. Always is a multiple of the + cluster size. Represents the actual amount of + disk space being used on the disk. */ +/* 72 */ void *compressed_end[0]; + /* Use offsetof(ATTR_RECORD, compressed_end) to + get size of a compressed attribute. */ +/* sizeof(compressed attr) = 72*/ + } __attribute__((__packed__)); + } __attribute__((__packed__)); +} __attribute__((__packed__)) ATTR_RECORD; + +typedef ATTR_RECORD ATTR_REC; + +/** + * enum FILE_ATTR_FLAGS - File attribute flags (32-bit). + */ +typedef enum { + /* + * These flags are only present in the STANDARD_INFORMATION attribute + * (in the field file_attributes). + */ + FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001), + FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002), + FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004), + /* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */ + + FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010), + /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved + for the DOS SUBDIRECTORY flag. */ + FILE_ATTR_ARCHIVE = const_cpu_to_le32(0x00000020), + FILE_ATTR_DEVICE = const_cpu_to_le32(0x00000040), + FILE_ATTR_NORMAL = const_cpu_to_le32(0x00000080), + + FILE_ATTR_TEMPORARY = const_cpu_to_le32(0x00000100), + FILE_ATTR_SPARSE_FILE = const_cpu_to_le32(0x00000200), + FILE_ATTR_REPARSE_POINT = const_cpu_to_le32(0x00000400), + FILE_ATTR_COMPRESSED = const_cpu_to_le32(0x00000800), + + FILE_ATTR_OFFLINE = const_cpu_to_le32(0x00001000), + FILE_ATTR_NOT_CONTENT_INDEXED = const_cpu_to_le32(0x00002000), + FILE_ATTR_ENCRYPTED = const_cpu_to_le32(0x00004000), + + FILE_ATTR_VALID_FLAGS = const_cpu_to_le32(0x00007fb7), + /* FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the + FILE_ATTR_DEVICE and preserves everything else. This mask + is used to obtain all flags that are valid for reading. */ + FILE_ATTR_VALID_SET_FLAGS = const_cpu_to_le32(0x000031a7), + /* FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the + FILE_ATTR_DEVICE, FILE_ATTR_DIRECTORY, FILE_ATTR_SPARSE_FILE, + FILE_ATTR_REPARSE_POINT, FILE_ATRE_COMPRESSED and FILE_ATTR_ENCRYPTED + and preserves the rest. This mask is used to to obtain all flags that + are valid for setting. */ + + /** + * FILE_ATTR_I30_INDEX_PRESENT - Is it a directory? + * + * This is a copy of the MFT_RECORD_IS_DIRECTORY bit from the mft + * record, telling us whether this is a directory or not, i.e. whether + * it has an index root attribute named "$I30" or not. + * + * This flag is only present in the FILE_NAME attribute (in the + * file_attributes field). + */ + FILE_ATTR_I30_INDEX_PRESENT = const_cpu_to_le32(0x10000000), + + /** + * FILE_ATTR_VIEW_INDEX_PRESENT - Does have a non-directory index? + * + * This is a copy of the MFT_RECORD_IS_VIEW_INDEX bit from the mft + * record, telling us whether this file has a view index present (eg. + * object id index, quota index, one of the security indexes and the + * reparse points index). + * + * This flag is only present in the $STANDARD_INFORMATION and + * $FILE_NAME attributes. + */ + FILE_ATTR_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000), +} __attribute__((__packed__)) FILE_ATTR_FLAGS; + +/* + * NOTE on times in NTFS: All times are in MS standard time format, i.e. they + * are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00 + * universal coordinated time (UTC). (In Linux time starts 1st January 1970, + * 00:00:00 UTC and is stored as the number of 1-second intervals since then.) + */ + +/** + * struct STANDARD_INFORMATION - Attribute: Standard information (0x10). + * + * NOTE: Always resident. + * NOTE: Present in all base file records on a volume. + * NOTE: There is conflicting information about the meaning of each of the time + * fields but the meaning as defined below has been verified to be + * correct by practical experimentation on Windows NT4 SP6a and is hence + * assumed to be the one and only correct interpretation. + */ +typedef struct { +/*Ofs*/ +/* 0*/ s64 creation_time; /* Time file was created. Updated when + a filename is changed(?). */ +/* 8*/ s64 last_data_change_time; /* Time the data attribute was last + modified. */ +/* 16*/ s64 last_mft_change_time; /* Time this mft record was last + modified. */ +/* 24*/ s64 last_access_time; /* Approximate time when the file was + last accessed (obviously this is not + updated on read-only volumes). In + Windows this is only updated when + accessed if some time delta has + passed since the last update. Also, + last access times updates can be + disabled altogether for speed. */ +/* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ +/* 36*/ union { + /* NTFS 1.2 (and previous, presumably) */ + struct { + /* 36 */ u8 reserved12[12]; /* Reserved/alignment to 8-byte + boundary. */ + /* 48 */ void *v1_end[0]; /* Marker for offsetof(). */ + } __attribute__((__packed__)); +/* sizeof() = 48 bytes */ + /* NTFS 3.0 */ + struct { +/* + * If a volume has been upgraded from a previous NTFS version, then these + * fields are present only if the file has been accessed since the upgrade. + * Recognize the difference by comparing the length of the resident attribute + * value. If it is 48, then the following fields are missing. If it is 72 then + * the fields are present. Maybe just check like this: + * if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) { + * Assume NTFS 1.2- format. + * If (volume version is 3.0+) + * Upgrade attribute to NTFS 3.0 format. + * else + * Use NTFS 1.2- format for access. + * } else + * Use NTFS 3.0 format for access. + * Only problem is that it might be legal to set the length of the value to + * arbitrarily large values thus spoiling this check. - But chkdsk probably + * views that as a corruption, assuming that it behaves like this for all + * attributes. + */ + /* 36*/ u32 maximum_versions; /* Maximum allowed versions for + file. Zero if version numbering is disabled. */ + /* 40*/ u32 version_number; /* This file's version (if any). + Set to zero if maximum_versions is zero. */ + /* 44*/ u32 class_id; /* Class id from bidirectional + class id index (?). */ + /* 48*/ u32 owner_id; /* Owner_id of the user owning + the file. Translate via $Q index in FILE_Extend + /$Quota to the quota control entry for the user + owning the file. Zero if quotas are disabled. */ + /* 52*/ u32 security_id; /* Security_id for the file. + Translate via $SII index and $SDS data stream + in FILE_Secure to the security descriptor. */ + /* 56*/ u64 quota_charged; /* Byte size of the charge to + the quota for all streams of the file. Note: Is + zero if quotas are disabled. */ + /* 64*/ u64 usn; /* Last update sequence number + of the file. This is a direct index into the + change (aka usn) journal file. It is zero if + the usn journal is disabled. + NOTE: To disable the journal need to delete + the journal file itself and to then walk the + whole mft and set all Usn entries in all mft + records to zero! (This can take a while!) + The journal is FILE_Extend/$UsnJrnl. Win2k + will recreate the journal and initiate + logging if necessary when mounting the + partition. This, in contrast to disabling the + journal is a very fast process, so the user + won't even notice it. */ + /* 72*/ void *v3_end[0]; /* Marker for offsetof(). */ + } __attribute__((__packed__)); + } __attribute__((__packed__)); +/* sizeof() = 72 bytes (NTFS 3.0) */ +} __attribute__((__packed__)) STANDARD_INFORMATION; + +/** + * struct ATTR_LIST_ENTRY - Attribute: Attribute list (0x20). + * + * - Can be either resident or non-resident. + * - Value consists of a sequence of variable length, 8-byte aligned, + * ATTR_LIST_ENTRY records. + * - The attribute list attribute contains one entry for each attribute of + * the file in which the list is located, except for the list attribute + * itself. The list is sorted: first by attribute type, second by attribute + * name (if present), third by instance number. The extents of one + * non-resident attribute (if present) immediately follow after the initial + * extent. They are ordered by lowest_vcn and have their instance set to zero. + * It is not allowed to have two attributes with all sorting keys equal. + * - Further restrictions: + * - If not resident, the vcn to lcn mapping array has to fit inside the + * base mft record. + * - The attribute list attribute value has a maximum size of 256kb. This + * is imposed by the Windows cache manager. + * - Attribute lists are only used when the attributes of mft record do not + * fit inside the mft record despite all attributes (that can be made + * non-resident) having been made non-resident. This can happen e.g. when: + * - File has a large number of hard links (lots of file name + * attributes present). + * - The mapping pairs array of some non-resident attribute becomes so + * large due to fragmentation that it overflows the mft record. + * - The security descriptor is very complex (not applicable to + * NTFS 3.0 volumes). + * - There are many named streams. + */ +typedef struct { +/*Ofs*/ +/* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */ +/* 4*/ u16 length; /* Byte size of this entry. */ +/* 6*/ u8 name_length; /* Size in Unicode chars of the name of the + attribute or 0 if unnamed. */ +/* 7*/ u8 name_offset; /* Byte offset to beginning of attribute name + (always set this to where the name would + start even if unnamed). */ +/* 8*/ VCN lowest_vcn; /* Lowest virtual cluster number of this portion + of the attribute value. This is usually 0. It + is non-zero for the case where one attribute + does not fit into one mft record and thus + several mft records are allocated to hold + this attribute. In the latter case, each mft + record holds one extent of the attribute and + there is one attribute list entry for each + extent. NOTE: This is DEFINITELY a signed + value! The windows driver uses cmp, followed + by jg when comparing this, thus it treats it + as signed. */ +/* 16*/ MFT_REF mft_reference; /* The reference of the mft record holding + the ATTR_RECORD for this portion of the + attribute value. */ +/* 24*/ u16 instance; /* If lowest_vcn = 0, the instance of the + attribute being referenced; otherwise 0. */ +/* 26*/ ntfschar name[0]; /* Use when creating only. When reading use + name_offset to determine the location of the + name. */ +/* sizeof() = 26 + (attribute_name_length * 2) bytes */ +} __attribute__((__packed__)) ATTR_LIST_ENTRY; + +/* + * The maximum allowed length for a file name. + */ +#define NTFS_MAX_NAME_LEN 255 + +/** + * enum FILE_NAME_TYPE_FLAGS - Possible namespaces for filenames in ntfs. + * (8-bit). + */ +typedef enum { + FILE_NAME_POSIX = 0x00, + /* This is the largest namespace. It is case sensitive and + allows all Unicode characters except for: '\0' and '/'. + Beware that in WinNT/2k files which eg have the same name + except for their case will not be distinguished by the + standard utilities and thus a "del filename" will delete + both "filename" and "fileName" without warning. */ + FILE_NAME_WIN32 = 0x01, + /* The standard WinNT/2k NTFS long filenames. Case insensitive. + All Unicode chars except: '\0', '"', '*', '/', ':', '<', + '>', '?', '\' and '|'. Further, names cannot end with a '.' + or a space. */ + FILE_NAME_DOS = 0x02, + /* The standard DOS filenames (8.3 format). Uppercase only. + All 8-bit characters greater space, except: '"', '*', '+', + ',', '/', ':', ';', '<', '=', '>', '?' and '\'. */ + FILE_NAME_WIN32_AND_DOS = 0x03, + /* 3 means that both the Win32 and the DOS filenames are + identical and hence have been saved in this single filename + record. */ +} __attribute__((__packed__)) FILE_NAME_TYPE_FLAGS; + +/** + * struct FILE_NAME_ATTR - Attribute: Filename (0x30). + * + * NOTE: Always resident. + * NOTE: All fields, except the parent_directory, are only updated when the + * filename is changed. Until then, they just become out of sync with + * reality and the more up to date values are present in the standard + * information attribute. + * NOTE: There is conflicting information about the meaning of each of the time + * fields but the meaning as defined below has been verified to be + * correct by practical experimentation on Windows NT4 SP6a and is hence + * assumed to be the one and only correct interpretation. + */ +typedef struct { +/*hex ofs*/ +/* 0*/ MFT_REF parent_directory; /* Directory this filename is + referenced from. */ +/* 8*/ s64 creation_time; /* Time file was created. */ +/* 10*/ s64 last_data_change_time; /* Time the data attribute was last + modified. */ +/* 18*/ s64 last_mft_change_time; /* Time this mft record was last + modified. */ +/* 20*/ s64 last_access_time; /* Last time this mft record was + accessed. */ +/* 28*/ s64 allocated_size; /* Byte size of on-disk allocated space + for the data attribute. So for + normal $DATA, this is the + allocated_size from the unnamed + $DATA attribute and for compressed + and/or sparse $DATA, this is the + compressed_size from the unnamed + $DATA attribute. NOTE: This is a + multiple of the cluster size. */ +/* 30*/ s64 data_size; /* Byte size of actual data in data + attribute. */ +/* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */ +/* 3c*/ union { + /* 3c*/ struct { + /* 3c*/ u16 packed_ea_size; /* Size of the buffer needed to + pack the extended attributes + (EAs), if such are present.*/ + /* 3e*/ u16 reserved; /* Reserved for alignment. */ + } __attribute__((__packed__)); + /* 3c*/ u32 reparse_point_tag; /* Type of reparse point, + present only in reparse + points and only if there are + no EAs. */ + } __attribute__((__packed__)); +/* 40*/ u8 file_name_length; /* Length of file name in + (Unicode) characters. */ +/* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/ +/* 42*/ ntfschar file_name[0]; /* File name in Unicode. */ +} __attribute__((__packed__)) FILE_NAME_ATTR; + +/** + * struct GUID - GUID structures store globally unique identifiers (GUID). + * + * A GUID is a 128-bit value consisting of one group of eight hexadecimal + * digits, followed by three groups of four hexadecimal digits each, followed + * by one group of twelve hexadecimal digits. GUIDs are Microsoft's + * implementation of the distributed computing environment (DCE) universally + * unique identifier (UUID). + * + * Example of a GUID: + * 1F010768-5A73-BC91-0010-A52216A7227B + */ +typedef struct { + u32 data1; /* The first eight hexadecimal digits of the GUID. */ + u16 data2; /* The first group of four hexadecimal digits. */ + u16 data3; /* The second group of four hexadecimal digits. */ + u8 data4[8]; /* The first two bytes are the third group of four + hexadecimal digits. The remaining six bytes are the + final 12 hexadecimal digits. */ +} __attribute__((__packed__)) GUID; + +/** + * struct OBJ_ID_INDEX_DATA - FILE_Extend/$ObjId contains an index named $O. + * + * This index contains all object_ids present on the volume as the index keys + * and the corresponding mft_record numbers as the index entry data parts. + * + * The data part (defined below) also contains three other object_ids: + * birth_volume_id - object_id of FILE_Volume on which the file was first + * created. Optional (i.e. can be zero). + * birth_object_id - object_id of file when it was first created. Usually + * equals the object_id. Optional (i.e. can be zero). + * domain_id - Reserved (always zero). + */ +typedef struct { + MFT_REF mft_reference; /* Mft record containing the object_id in + the index entry key. */ + union { + struct { + GUID birth_volume_id; + GUID birth_object_id; + GUID domain_id; + } __attribute__((__packed__)); + u8 extended_info[48]; + } __attribute__((__packed__)); +} __attribute__((__packed__)) OBJ_ID_INDEX_DATA; + +/** + * struct OBJECT_ID_ATTR - Attribute: Object id (NTFS 3.0+) (0x40). + * + * NOTE: Always resident. + */ +typedef struct { + GUID object_id; /* Unique id assigned to the + file.*/ + /* The following fields are optional. The attribute value size is 16 + bytes, i.e. sizeof(GUID), if these are not present at all. Note, + the entries can be present but one or more (or all) can be zero + meaning that that particular value(s) is(are) not defined. Note, + when the fields are missing here, it is well possible that they are + to be found within the $Extend/$ObjId system file indexed under the + above object_id. */ + union { + struct { + GUID birth_volume_id; /* Unique id of volume on which + the file was first created.*/ + GUID birth_object_id; /* Unique id of file when it was + first created. */ + GUID domain_id; /* Reserved, zero. */ + } __attribute__((__packed__)); + u8 extended_info[48]; + } __attribute__((__packed__)); +} __attribute__((__packed__)) OBJECT_ID_ATTR; + +#if 0 +/** + * enum IDENTIFIER_AUTHORITIES - + * + * The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in + * the SID structure (see below). + */ +typedef enum { /* SID string prefix. */ + SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */ + SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */ + SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */ + SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */ + SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */ + SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */ +} IDENTIFIER_AUTHORITIES; +#endif + +/** + * enum RELATIVE_IDENTIFIERS - + * + * These relative identifiers (RIDs) are used with the above identifier + * authorities to make up universal well-known SIDs. + * + * Note: The relative identifier (RID) refers to the portion of a SID, which + * identifies a user or group in relation to the authority that issued the SID. + * For example, the universal well-known SID Creator Owner ID (S-1-3-0) is + * made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and + * the relative identifier SECURITY_CREATOR_OWNER_RID (0). + */ +typedef enum { /* Identifier authority. */ + SECURITY_NULL_RID = 0, /* S-1-0 */ + SECURITY_WORLD_RID = 0, /* S-1-1 */ + SECURITY_LOCAL_RID = 0, /* S-1-2 */ + + SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */ + SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */ + + SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */ + SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */ + + SECURITY_DIALUP_RID = 1, + SECURITY_NETWORK_RID = 2, + SECURITY_BATCH_RID = 3, + SECURITY_INTERACTIVE_RID = 4, + SECURITY_SERVICE_RID = 6, + SECURITY_ANONYMOUS_LOGON_RID = 7, + SECURITY_PROXY_RID = 8, + SECURITY_ENTERPRISE_CONTROLLERS_RID=9, + SECURITY_SERVER_LOGON_RID = 9, + SECURITY_PRINCIPAL_SELF_RID = 0xa, + SECURITY_AUTHENTICATED_USER_RID = 0xb, + SECURITY_RESTRICTED_CODE_RID = 0xc, + SECURITY_TERMINAL_SERVER_RID = 0xd, + + SECURITY_LOGON_IDS_RID = 5, + SECURITY_LOGON_IDS_RID_COUNT = 3, + + SECURITY_LOCAL_SYSTEM_RID = 0x12, + + SECURITY_NT_NON_UNIQUE = 0x15, + + SECURITY_BUILTIN_DOMAIN_RID = 0x20, + + /* + * Well-known domain relative sub-authority values (RIDs). + */ + + /* Users. */ + DOMAIN_USER_RID_ADMIN = 0x1f4, + DOMAIN_USER_RID_GUEST = 0x1f5, + DOMAIN_USER_RID_KRBTGT = 0x1f6, + + /* Groups. */ + DOMAIN_GROUP_RID_ADMINS = 0x200, + DOMAIN_GROUP_RID_USERS = 0x201, + DOMAIN_GROUP_RID_GUESTS = 0x202, + DOMAIN_GROUP_RID_COMPUTERS = 0x203, + DOMAIN_GROUP_RID_CONTROLLERS = 0x204, + DOMAIN_GROUP_RID_CERT_ADMINS = 0x205, + DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206, + DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207, + DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208, + + /* Aliases. */ + DOMAIN_ALIAS_RID_ADMINS = 0x220, + DOMAIN_ALIAS_RID_USERS = 0x221, + DOMAIN_ALIAS_RID_GUESTS = 0x222, + DOMAIN_ALIAS_RID_POWER_USERS = 0x223, + + DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224, + DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225, + DOMAIN_ALIAS_RID_PRINT_OPS = 0x226, + DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227, + + DOMAIN_ALIAS_RID_REPLICATOR = 0x228, + DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229, + DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a, +} RELATIVE_IDENTIFIERS; + +/* + * The universal well-known SIDs: + * + * NULL_SID S-1-0-0 + * WORLD_SID S-1-1-0 + * LOCAL_SID S-1-2-0 + * CREATOR_OWNER_SID S-1-3-0 + * CREATOR_GROUP_SID S-1-3-1 + * CREATOR_OWNER_SERVER_SID S-1-3-2 + * CREATOR_GROUP_SERVER_SID S-1-3-3 + * + * (Non-unique IDs) S-1-4 + * + * NT well-known SIDs: + * + * NT_AUTHORITY_SID S-1-5 + * DIALUP_SID S-1-5-1 + * + * NETWORD_SID S-1-5-2 + * BATCH_SID S-1-5-3 + * INTERACTIVE_SID S-1-5-4 + * SERVICE_SID S-1-5-6 + * ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session) + * PROXY_SID S-1-5-8 + * SERVER_LOGON_SID S-1-5-9 (aka domain controller account) + * SELF_SID S-1-5-10 (self RID) + * AUTHENTICATED_USER_SID S-1-5-11 + * RESTRICTED_CODE_SID S-1-5-12 (running restricted code) + * TERMINAL_SERVER_SID S-1-5-13 (running on terminal server) + * + * (Logon IDs) S-1-5-5-X-Y + * + * (NT non-unique IDs) S-1-5-0x15-... + * + * (Built-in domain) S-1-5-0x20 + */ + +/** + * union SID_IDENTIFIER_AUTHORITY - A 48-bit value used in the SID structure + * + * NOTE: This is stored as a big endian number. + */ +typedef union { + struct { + u16 high_part; /* High 16-bits. */ + u32 low_part; /* Low 32-bits. */ + } __attribute__((__packed__)); + u8 value[6]; /* Value as individual bytes. */ +} __attribute__((__packed__)) SID_IDENTIFIER_AUTHORITY; + +/** + * struct SID - + * + * The SID structure is a variable-length structure used to uniquely identify + * users or groups. SID stands for security identifier. + * + * The standard textual representation of the SID is of the form: + * S-R-I-S-S... + * Where: + * - The first "S" is the literal character 'S' identifying the following + * digits as a SID. + * - R is the revision level of the SID expressed as a sequence of digits + * in decimal. + * - I is the 48-bit identifier_authority, expressed as digits in decimal, + * if I < 2^32, or hexadecimal prefixed by "0x", if I >= 2^32. + * - S... is one or more sub_authority values, expressed as digits in + * decimal. + * + * Example SID; the domain-relative SID of the local Administrators group on + * Windows NT/2k: + * S-1-5-32-544 + * This translates to a SID with: + * revision = 1, + * sub_authority_count = 2, + * identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY + * sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID + * sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS + */ +typedef struct { + u8 revision; + u8 sub_authority_count; + SID_IDENTIFIER_AUTHORITY identifier_authority; + u32 sub_authority[1]; /* At least one sub_authority. */ +} __attribute__((__packed__)) SID; + +/** + * enum SID_CONSTANTS - Current constants for SIDs. + */ +typedef enum { + SID_REVISION = 1, /* Current revision level. */ + SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */ + SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in + a future revision. */ +} SID_CONSTANTS; + +/** + * enum ACE_TYPES - The predefined ACE types (8-bit, see below). + */ +typedef enum { + ACCESS_MIN_MS_ACE_TYPE = 0, + ACCESS_ALLOWED_ACE_TYPE = 0, + ACCESS_DENIED_ACE_TYPE = 1, + SYSTEM_AUDIT_ACE_TYPE = 2, + SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */ + ACCESS_MAX_MS_V2_ACE_TYPE = 3, + + ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4, + ACCESS_MAX_MS_V3_ACE_TYPE = 4, + + /* The following are Win2k only. */ + ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5, + ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5, + ACCESS_DENIED_OBJECT_ACE_TYPE = 6, + SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7, + SYSTEM_ALARM_OBJECT_ACE_TYPE = 8, + ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8, + + ACCESS_MAX_MS_V4_ACE_TYPE = 8, + + /* This one is for WinNT&2k. */ + ACCESS_MAX_MS_ACE_TYPE = 8, +} __attribute__((__packed__)) ACE_TYPES; + +/** + * enum ACE_FLAGS - The ACE flags (8-bit) for audit and inheritance. + * + * SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE + * types to indicate that a message is generated (in Windows!) for successful + * accesses. + * + * FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types + * to indicate that a message is generated (in Windows!) for failed accesses. + */ +typedef enum { + /* The inheritance flags. */ + OBJECT_INHERIT_ACE = 0x01, + CONTAINER_INHERIT_ACE = 0x02, + NO_PROPAGATE_INHERIT_ACE = 0x04, + INHERIT_ONLY_ACE = 0x08, + INHERITED_ACE = 0x10, /* Win2k only. */ + VALID_INHERIT_FLAGS = 0x1f, + + /* The audit flags. */ + SUCCESSFUL_ACCESS_ACE_FLAG = 0x40, + FAILED_ACCESS_ACE_FLAG = 0x80, +} __attribute__((__packed__)) ACE_FLAGS; + +/** + * struct ACE_HEADER - + * + * An ACE is an access-control entry in an access-control list (ACL). + * An ACE defines access to an object for a specific user or group or defines + * the types of access that generate system-administration messages or alarms + * for a specific user or group. The user or group is identified by a security + * identifier (SID). + * + * Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary), + * which specifies the type and size of the ACE. The format of the subsequent + * data depends on the ACE type. + */ +typedef struct { + ACE_TYPES type; /* Type of the ACE. */ + ACE_FLAGS flags; /* Flags describing the ACE. */ + u16 size; /* Size in bytes of the ACE. */ +} __attribute__((__packed__)) ACE_HEADER; + +/** + * enum ACCESS_MASK - The access mask (32-bit). + * + * Defines the access rights. + */ +typedef enum { + /* + * The specific rights (bits 0 to 15). Depend on the type of the + * object being secured by the ACE. + */ + + /* Specific rights for files and directories are as follows: */ + + /* Right to read data from the file. (FILE) */ + FILE_READ_DATA = const_cpu_to_le32(0x00000001), + /* Right to list contents of a directory. (DIRECTORY) */ + FILE_LIST_DIRECTORY = const_cpu_to_le32(0x00000001), + + /* Right to write data to the file. (FILE) */ + FILE_WRITE_DATA = const_cpu_to_le32(0x00000002), + /* Right to create a file in the directory. (DIRECTORY) */ + FILE_ADD_FILE = const_cpu_to_le32(0x00000002), + + /* Right to append data to the file. (FILE) */ + FILE_APPEND_DATA = const_cpu_to_le32(0x00000004), + /* Right to create a subdirectory. (DIRECTORY) */ + FILE_ADD_SUBDIRECTORY = const_cpu_to_le32(0x00000004), + + /* Right to read extended attributes. (FILE/DIRECTORY) */ + FILE_READ_EA = const_cpu_to_le32(0x00000008), + + /* Right to write extended attributes. (FILE/DIRECTORY) */ + FILE_WRITE_EA = const_cpu_to_le32(0x00000010), + + /* Right to execute a file. (FILE) */ + FILE_EXECUTE = const_cpu_to_le32(0x00000020), + /* Right to traverse the directory. (DIRECTORY) */ + FILE_TRAVERSE = const_cpu_to_le32(0x00000020), + + /* + * Right to delete a directory and all the files it contains (its + * children), even if the files are read-only. (DIRECTORY) + */ + FILE_DELETE_CHILD = const_cpu_to_le32(0x00000040), + + /* Right to read file attributes. (FILE/DIRECTORY) */ + FILE_READ_ATTRIBUTES = const_cpu_to_le32(0x00000080), + + /* Right to change file attributes. (FILE/DIRECTORY) */ + FILE_WRITE_ATTRIBUTES = const_cpu_to_le32(0x00000100), + + /* + * The standard rights (bits 16 to 23). Are independent of the type of + * object being secured. + */ + + /* Right to delete the object. */ + DELETE = const_cpu_to_le32(0x00010000), + + /* + * Right to read the information in the object's security descriptor, + * not including the information in the SACL. I.e. right to read the + * security descriptor and owner. + */ + READ_CONTROL = const_cpu_to_le32(0x00020000), + + /* Right to modify the DACL in the object's security descriptor. */ + WRITE_DAC = const_cpu_to_le32(0x00040000), + + /* Right to change the owner in the object's security descriptor. */ + WRITE_OWNER = const_cpu_to_le32(0x00080000), + + /* + * Right to use the object for synchronization. Enables a process to + * wait until the object is in the signalled state. Some object types + * do not support this access right. + */ + SYNCHRONIZE = const_cpu_to_le32(0x00100000), + + /* + * The following STANDARD_RIGHTS_* are combinations of the above for + * convenience and are defined by the Win32 API. + */ + + /* These are currently defined to READ_CONTROL. */ + STANDARD_RIGHTS_READ = const_cpu_to_le32(0x00020000), + STANDARD_RIGHTS_WRITE = const_cpu_to_le32(0x00020000), + STANDARD_RIGHTS_EXECUTE = const_cpu_to_le32(0x00020000), + + /* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */ + STANDARD_RIGHTS_REQUIRED = const_cpu_to_le32(0x000f0000), + + /* + * Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and + * SYNCHRONIZE access. + */ + STANDARD_RIGHTS_ALL = const_cpu_to_le32(0x001f0000), + + /* + * The access system ACL and maximum allowed access types (bits 24 to + * 25, bits 26 to 27 are reserved). + */ + ACCESS_SYSTEM_SECURITY = const_cpu_to_le32(0x01000000), + MAXIMUM_ALLOWED = const_cpu_to_le32(0x02000000), + + /* + * The generic rights (bits 28 to 31). These map onto the standard and + * specific rights. + */ + + /* Read, write, and execute access. */ + GENERIC_ALL = const_cpu_to_le32(0x10000000), + + /* Execute access. */ + GENERIC_EXECUTE = const_cpu_to_le32(0x20000000), + + /* + * Write access. For files, this maps onto: + * FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | + * FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE + * For directories, the mapping has the same numerical value. See + * above for the descriptions of the rights granted. + */ + GENERIC_WRITE = const_cpu_to_le32(0x40000000), + + /* + * Read access. For files, this maps onto: + * FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA | + * STANDARD_RIGHTS_READ | SYNCHRONIZE + * For directories, the mapping has the same numerical value. See + * above for the descriptions of the rights granted. + */ + GENERIC_READ = const_cpu_to_le32(0x80000000), +} ACCESS_MASK; + +/** + * struct GENERIC_MAPPING - + * + * The generic mapping array. Used to denote the mapping of each generic + * access right to a specific access mask. + * + * FIXME: What exactly is this and what is it for? (AIA) + */ +typedef struct { + ACCESS_MASK generic_read; + ACCESS_MASK generic_write; + ACCESS_MASK generic_execute; + ACCESS_MASK generic_all; +} __attribute__((__packed__)) GENERIC_MAPPING; + +/* + * The predefined ACE type structures are as defined below. + */ + +/** + * struct ACCESS_DENIED_ACE - + * + * ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE + */ +typedef struct { +/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ + ACE_TYPES type; /* Type of the ACE. */ + ACE_FLAGS flags; /* Flags describing the ACE. */ + u16 size; /* Size in bytes of the ACE. */ + +/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ +/* 8*/ SID sid; /* The SID associated with the ACE. */ +} __attribute__((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, + SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE; + +/** + * enum OBJECT_ACE_FLAGS - The object ACE flags (32-bit). + */ +typedef enum { + ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1), + ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2), +} OBJECT_ACE_FLAGS; + +/** + * struct ACCESS_ALLOWED_OBJECT_ACE - + */ +typedef struct { +/* 0 ACE_HEADER; -- Unfolded here as gcc doesn't like unnamed structs. */ + ACE_TYPES type; /* Type of the ACE. */ + ACE_FLAGS flags; /* Flags describing the ACE. */ + u16 size; /* Size in bytes of the ACE. */ + +/* 4*/ ACCESS_MASK mask; /* Access mask associated with the ACE. */ +/* 8*/ OBJECT_ACE_FLAGS object_flags; /* Flags describing the object ACE. */ +/* 12*/ GUID object_type; +/* 28*/ GUID inherited_object_type; +/* 44*/ SID sid; /* The SID associated with the ACE. */ +} __attribute__((__packed__)) ACCESS_ALLOWED_OBJECT_ACE, + ACCESS_DENIED_OBJECT_ACE, + SYSTEM_AUDIT_OBJECT_ACE, + SYSTEM_ALARM_OBJECT_ACE; + +/** + * struct ACL - An ACL is an access-control list (ACL). + * + * An ACL starts with an ACL header structure, which specifies the size of + * the ACL and the number of ACEs it contains. The ACL header is followed by + * zero or more access control entries (ACEs). The ACL as well as each ACE + * are aligned on 4-byte boundaries. + */ +typedef struct { + u8 revision; /* Revision of this ACL. */ + u8 alignment1; + u16 size; /* Allocated space in bytes for ACL. Includes this + header, the ACEs and the remaining free space. */ + u16 ace_count; /* Number of ACEs in the ACL. */ + u16 alignment2; +/* sizeof() = 8 bytes */ +} __attribute__((__packed__)) ACL; + +/** + * enum ACL_CONSTANTS - Current constants for ACLs. + */ +typedef enum { + /* Current revision. */ + ACL_REVISION = 2, + ACL_REVISION_DS = 4, + + /* History of revisions. */ + ACL_REVISION1 = 1, + MIN_ACL_REVISION = 2, + ACL_REVISION2 = 2, + ACL_REVISION3 = 3, + ACL_REVISION4 = 4, + MAX_ACL_REVISION = 4, +} ACL_CONSTANTS; + +/** + * enum SECURITY_DESCRIPTOR_CONTROL - + * + * The security descriptor control flags (16-bit). + * + * SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the + * SID pointed to by the Owner field was provided by a + * defaulting mechanism rather than explicitly provided by the + * original provider of the security descriptor. This may + * affect the treatment of the SID with respect to inheritance + * of an owner. + * + * SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the + * SID in the Group field was provided by a defaulting mechanism + * rather than explicitly provided by the original provider of + * the security descriptor. This may affect the treatment of + * the SID with respect to inheritance of a primary group. + * + * SE_DACL_PRESENT - This boolean flag, when set, indicates that the + * security descriptor contains a discretionary ACL. If this + * flag is set and the Dacl field of the SECURITY_DESCRIPTOR is + * null, then a null ACL is explicitly being specified. + * + * SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the + * ACL pointed to by the Dacl field was provided by a defaulting + * mechanism rather than explicitly provided by the original + * provider of the security descriptor. This may affect the + * treatment of the ACL with respect to inheritance of an ACL. + * This flag is ignored if the DaclPresent flag is not set. + * + * SE_SACL_PRESENT - This boolean flag, when set, indicates that the + * security descriptor contains a system ACL pointed to by the + * Sacl field. If this flag is set and the Sacl field of the + * SECURITY_DESCRIPTOR is null, then an empty (but present) + * ACL is being specified. + * + * SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the + * ACL pointed to by the Sacl field was provided by a defaulting + * mechanism rather than explicitly provided by the original + * provider of the security descriptor. This may affect the + * treatment of the ACL with respect to inheritance of an ACL. + * This flag is ignored if the SaclPresent flag is not set. + * + * SE_SELF_RELATIVE - This boolean flag, when set, indicates that the + * security descriptor is in self-relative form. In this form, + * all fields of the security descriptor are contiguous in memory + * and all pointer fields are expressed as offsets from the + * beginning of the security descriptor. + */ +typedef enum { + SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001), + SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002), + SE_DACL_PRESENT = const_cpu_to_le16(0x0004), + SE_DACL_DEFAULTED = const_cpu_to_le16(0x0008), + SE_SACL_PRESENT = const_cpu_to_le16(0x0010), + SE_SACL_DEFAULTED = const_cpu_to_le16(0x0020), + SE_DACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0100), + SE_SACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0200), + SE_DACL_AUTO_INHERITED = const_cpu_to_le16(0x0400), + SE_SACL_AUTO_INHERITED = const_cpu_to_le16(0x0800), + SE_DACL_PROTECTED = const_cpu_to_le16(0x1000), + SE_SACL_PROTECTED = const_cpu_to_le16(0x2000), + SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000), + SE_SELF_RELATIVE = const_cpu_to_le16(0x8000), +} __attribute__((__packed__)) SECURITY_DESCRIPTOR_CONTROL; + +/** + * struct SECURITY_DESCRIPTOR_RELATIVE - + * + * Self-relative security descriptor. Contains the owner and group SIDs as well + * as the sacl and dacl ACLs inside the security descriptor itself. + */ +typedef struct { + u8 revision; /* Revision level of the security descriptor. */ + u8 alignment; + SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of + the descriptor as well as the following fields. */ + u32 owner; /* Byte offset to a SID representing an object's + owner. If this is NULL, no owner SID is present in + the descriptor. */ + u32 group; /* Byte offset to a SID representing an object's + primary group. If this is NULL, no primary group + SID is present in the descriptor. */ + u32 sacl; /* Byte offset to a system ACL. Only valid, if + SE_SACL_PRESENT is set in the control field. If + SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL + is specified. */ + u32 dacl; /* Byte offset to a discretionary ACL. Only valid, if + SE_DACL_PRESENT is set in the control field. If + SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL + (unconditionally granting access) is specified. */ +/* sizeof() = 0x14 bytes */ +} __attribute__((__packed__)) SECURITY_DESCRIPTOR_RELATIVE; + +/** + * struct SECURITY_DESCRIPTOR - Absolute security descriptor. + * + * Does not contain the owner and group SIDs, nor the sacl and dacl ACLs inside + * the security descriptor. Instead, it contains pointers to these structures + * in memory. Obviously, absolute security descriptors are only useful for in + * memory representations of security descriptors. + * + * On disk, a self-relative security descriptor is used. + */ +typedef struct { + u8 revision; /* Revision level of the security descriptor. */ + u8 alignment; + SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of + the descriptor as well as the following fields. */ + SID *owner; /* Points to a SID representing an object's owner. If + this is NULL, no owner SID is present in the + descriptor. */ + SID *group; /* Points to a SID representing an object's primary + group. If this is NULL, no primary group SID is + present in the descriptor. */ + ACL *sacl; /* Points to a system ACL. Only valid, if + SE_SACL_PRESENT is set in the control field. If + SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL + is specified. */ + ACL *dacl; /* Points to a discretionary ACL. Only valid, if + SE_DACL_PRESENT is set in the control field. If + SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL + (unconditionally granting access) is specified. */ +} __attribute__((__packed__)) SECURITY_DESCRIPTOR; + +/** + * enum SECURITY_DESCRIPTOR_CONSTANTS - + * + * Current constants for security descriptors. + */ +typedef enum { + /* Current revision. */ + SECURITY_DESCRIPTOR_REVISION = 1, + SECURITY_DESCRIPTOR_REVISION1 = 1, + + /* The sizes of both the absolute and relative security descriptors is + the same as pointers, at least on ia32 architecture are 32-bit. */ + SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR), +} SECURITY_DESCRIPTOR_CONSTANTS; + +/* + * Attribute: Security descriptor (0x50). + * + * A standard self-relative security descriptor. + * + * NOTE: Can be resident or non-resident. + * NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally + * in FILE_Secure and the correct descriptor is found using the security_id + * from the standard information attribute. + */ +typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR; + +/* + * On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one + * referenced instance of each unique security descriptor is stored. + * + * FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It + * does, however, contain two indexes ($SDH and $SII) as well as a named data + * stream ($SDS). + * + * Every unique security descriptor is assigned a unique security identifier + * (security_id, not to be confused with a SID). The security_id is unique for + * the NTFS volume and is used as an index into the $SII index, which maps + * security_ids to the security descriptor's storage location within the $SDS + * data attribute. The $SII index is sorted by ascending security_id. + * + * A simple hash is computed from each security descriptor. This hash is used + * as an index into the $SDH index, which maps security descriptor hashes to + * the security descriptor's storage location within the $SDS data attribute. + * The $SDH index is sorted by security descriptor hash and is stored in a B+ + * tree. When searching $SDH (with the intent of determining whether or not a + * new security descriptor is already present in the $SDS data stream), if a + * matching hash is found, but the security descriptors do not match, the + * search in the $SDH index is continued, searching for a next matching hash. + * + * When a precise match is found, the security_id corresponding to the security + * descriptor in the $SDS attribute is read from the found $SDH index entry and + * is stored in the $STANDARD_INFORMATION attribute of the file/directory to + * which the security descriptor is being applied. The $STANDARD_INFORMATION + * attribute is present in all base mft records (i.e. in all files and + * directories). + * + * If a match is not found, the security descriptor is assigned a new unique + * security_id and is added to the $SDS data attribute. Then, entries + * referencing the this security descriptor in the $SDS data attribute are + * added to the $SDH and $SII indexes. + * + * Note: Entries are never deleted from FILE_Secure, even if nothing + * references an entry any more. + */ + +/** + * struct SECURITY_DESCRIPTOR_HEADER - + * + * This header precedes each security descriptor in the $SDS data stream. + * This is also the index entry data part of both the $SII and $SDH indexes. + */ +typedef struct { + u32 hash; /* Hash of the security descriptor. */ + u32 security_id; /* The security_id assigned to the descriptor. */ + u64 offset; /* Byte offset of this entry in the $SDS stream. */ + u32 length; /* Size in bytes of this entry in $SDS stream. */ +} __attribute__((__packed__)) SECURITY_DESCRIPTOR_HEADER; + +/** + * struct SDH_INDEX_DATA - + */ +typedef struct { + u32 hash; /* Hash of the security descriptor. */ + u32 security_id; /* The security_id assigned to the descriptor. */ + u64 offset; /* Byte offset of this entry in the $SDS stream. */ + u32 length; /* Size in bytes of this entry in $SDS stream. */ + u32 reserved_II; /* Padding - always unicode "II" or zero. This field + isn't counted in INDEX_ENTRY's data_length. */ +} __attribute__((__packed__)) SDH_INDEX_DATA; + +/** + * struct SII_INDEX_DATA - + */ +typedef SECURITY_DESCRIPTOR_HEADER SII_INDEX_DATA; + +/** + * struct SDS_ENTRY - + * + * The $SDS data stream contains the security descriptors, aligned on 16-byte + * boundaries, sorted by security_id in a B+ tree. Security descriptors cannot + * cross 256kib boundaries (this restriction is imposed by the Windows cache + * manager). Each security descriptor is contained in a SDS_ENTRY structure. + * Also, each security descriptor is stored twice in the $SDS stream with a + * fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size) + * between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the + * the first copy of the security descriptor will be at offset 0x51d0 in the + * $SDS data stream and the second copy will be at offset 0x451d0. + */ +typedef struct { +/* 0 SECURITY_DESCRIPTOR_HEADER; -- Unfolded here as gcc doesn't like + unnamed structs. */ + u32 hash; /* Hash of the security descriptor. */ + u32 security_id; /* The security_id assigned to the descriptor. */ + u64 offset; /* Byte offset of this entry in the $SDS stream. */ + u32 length; /* Size in bytes of this entry in $SDS stream. */ +/* 20*/ SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security + descriptor. */ +} __attribute__((__packed__)) SDS_ENTRY; + +/** + * struct SII_INDEX_KEY - The index entry key used in the $SII index. + * + * The collation type is COLLATION_NTOFS_ULONG. + */ +typedef struct { + u32 security_id; /* The security_id assigned to the descriptor. */ +} __attribute__((__packed__)) SII_INDEX_KEY; + +/** + * struct SDH_INDEX_KEY - The index entry key used in the $SDH index. + * + * The keys are sorted first by hash and then by security_id. + * The collation rule is COLLATION_NTOFS_SECURITY_HASH. + */ +typedef struct { + u32 hash; /* Hash of the security descriptor. */ + u32 security_id; /* The security_id assigned to the descriptor. */ +} __attribute__((__packed__)) SDH_INDEX_KEY; + +/** + * struct VOLUME_NAME - Attribute: Volume name (0x60). + * + * NOTE: Always resident. + * NOTE: Present only in FILE_Volume. + */ +typedef struct { + ntfschar name[0]; /* The name of the volume in Unicode. */ +} __attribute__((__packed__)) VOLUME_NAME; + +/** + * enum VOLUME_FLAGS - Possible flags for the volume (16-bit). + */ +typedef enum { + VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001), + VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002), + VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004), + VOLUME_MOUNTED_ON_NT4 = const_cpu_to_le16(0x0008), + VOLUME_DELETE_USN_UNDERWAY = const_cpu_to_le16(0x0010), + VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020), + VOLUME_CHKDSK_UNDERWAY = const_cpu_to_le16(0x4000), + VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000), + VOLUME_FLAGS_MASK = const_cpu_to_le16(0xc03f), +} __attribute__((__packed__)) VOLUME_FLAGS; + +/** + * struct VOLUME_INFORMATION - Attribute: Volume information (0x70). + * + * NOTE: Always resident. + * NOTE: Present only in FILE_Volume. + * NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses + * NTFS 1.2. I haven't personally seen other values yet. + */ +typedef struct { + u64 reserved; /* Not used (yet?). */ + u8 major_ver; /* Major version of the ntfs format. */ + u8 minor_ver; /* Minor version of the ntfs format. */ + VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */ +} __attribute__((__packed__)) VOLUME_INFORMATION; + +/** + * struct DATA_ATTR - Attribute: Data attribute (0x80). + * + * NOTE: Can be resident or non-resident. + * + * Data contents of a file (i.e. the unnamed stream) or of a named stream. + */ +typedef struct { + u8 data[0]; /* The file's data contents. */ +} __attribute__((__packed__)) DATA_ATTR; + +/** + * enum INDEX_HEADER_FLAGS - Index header flags (8-bit). + */ +typedef enum { + /* When index header is in an index root attribute: */ + SMALL_INDEX = 0, /* The index is small enough to fit inside the + index root attribute and there is no index + allocation attribute present. */ + LARGE_INDEX = 1, /* The index is too large to fit in the index + root attribute and/or an index allocation + attribute is present. */ + /* + * When index header is in an index block, i.e. is part of index + * allocation attribute: + */ + LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more + nodes branching off it. */ + INDEX_NODE = 1, /* This node indexes other nodes, i.e. is not a + leaf node. */ + NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */ +} __attribute__((__packed__)) INDEX_HEADER_FLAGS; + +/** + * struct INDEX_HEADER - + * + * This is the header for indexes, describing the INDEX_ENTRY records, which + * follow the INDEX_HEADER. Together the index header and the index entries + * make up a complete index. + * + * IMPORTANT NOTE: The offset, length and size structure members are counted + * relative to the start of the index header structure and not relative to the + * start of the index root or index allocation structures themselves. + */ +typedef struct { +/* 0*/ u32 entries_offset; /* Byte offset from the INDEX_HEADER to first + INDEX_ENTRY, aligned to 8-byte boundary. */ +/* 4*/ u32 index_length; /* Data size in byte of the INDEX_ENTRY's, + including the INDEX_HEADER, aligned to 8. */ +/* 8*/ u32 allocated_size; /* Allocated byte size of this index (block), + multiple of 8 bytes. See more below. */ + /* + For the index root attribute, the above two numbers are always + equal, as the attribute is resident and it is resized as needed. + + For the index allocation attribute, the attribute is not resident + and the allocated_size is equal to the index_block_size specified + by the corresponding INDEX_ROOT attribute minus the INDEX_BLOCK + size not counting the INDEX_HEADER part (i.e. minus -24). + */ +/* 12*/ INDEX_HEADER_FLAGS ih_flags; /* Bit field of INDEX_HEADER_FLAGS. */ +/* 13*/ u8 reserved[3]; /* Reserved/align to 8-byte boundary.*/ +/* sizeof() == 16 */ +} __attribute__((__packed__)) INDEX_HEADER; + +/** + * struct INDEX_ROOT - Attribute: Index root (0x90). + * + * NOTE: Always resident. + * + * This is followed by a sequence of index entries (INDEX_ENTRY structures) + * as described by the index header. + * + * When a directory is small enough to fit inside the index root then this + * is the only attribute describing the directory. When the directory is too + * large to fit in the index root, on the other hand, two additional attributes + * are present: an index allocation attribute, containing sub-nodes of the B+ + * directory tree (see below), and a bitmap attribute, describing which virtual + * cluster numbers (vcns) in the index allocation attribute are in use by an + * index block. + * + * NOTE: The root directory (FILE_root) contains an entry for itself. Other + * directories do not contain entries for themselves, though. + */ +typedef struct { +/* 0*/ ATTR_TYPES type; /* Type of the indexed attribute. Is + $FILE_NAME for directories, zero + for view indexes. No other values + allowed. */ +/* 4*/ COLLATION_RULES collation_rule; /* Collation rule used to sort the + index entries. If type is $FILE_NAME, + this must be COLLATION_FILE_NAME. */ +/* 8*/ u32 index_block_size; /* Size of index block in bytes (in + the index allocation attribute). */ +/* 12*/ s8 clusters_per_index_block; /* Size of index block in clusters (in + the index allocation attribute), when + an index block is >= than a cluster, + otherwise sectors per index block. */ +/* 13*/ u8 reserved[3]; /* Reserved/align to 8-byte boundary. */ +/* 16*/ INDEX_HEADER index; /* Index header describing the + following index entries. */ +/* sizeof()= 32 bytes */ +} __attribute__((__packed__)) INDEX_ROOT; + +/** + * struct INDEX_BLOCK - Attribute: Index allocation (0xa0). + * + * NOTE: Always non-resident (doesn't make sense to be resident anyway!). + * + * This is an array of index blocks. Each index block starts with an + * INDEX_BLOCK structure containing an index header, followed by a sequence of + * index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER. + */ +typedef struct { +/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ + NTFS_RECORD_TYPES magic;/* Magic is "INDX". */ + u16 usa_ofs; /* See NTFS_RECORD definition. */ + u16 usa_count; /* See NTFS_RECORD definition. */ + +/* 8*/ LSN lsn; /* $LogFile sequence number of the last + modification of this index block. */ +/* 16*/ VCN index_block_vcn; /* Virtual cluster number of the index block. */ +/* 24*/ INDEX_HEADER index; /* Describes the following index entries. */ +/* sizeof()= 40 (0x28) bytes */ +/* + * When creating the index block, we place the update sequence array at this + * offset, i.e. before we start with the index entries. This also makes sense, + * otherwise we could run into problems with the update sequence array + * containing in itself the last two bytes of a sector which would mean that + * multi sector transfer protection wouldn't work. As you can't protect data + * by overwriting it since you then can't get it back... + * When reading use the data from the ntfs record header. + */ +} __attribute__((__packed__)) INDEX_BLOCK; + +typedef INDEX_BLOCK INDEX_ALLOCATION; + +/** + * struct REPARSE_INDEX_KEY - + * + * The system file FILE_Extend/$Reparse contains an index named $R listing + * all reparse points on the volume. The index entry keys are as defined + * below. Note, that there is no index data associated with the index entries. + * + * The index entries are sorted by the index key file_id. The collation rule is + * COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the + * primary key / is not a key at all. (AIA) + */ +typedef struct { + u32 reparse_tag; /* Reparse point type (inc. flags). */ + MFT_REF file_id; /* Mft record of the file containing the + reparse point attribute. */ +} __attribute__((__packed__)) REPARSE_INDEX_KEY; + +/** + * enum QUOTA_FLAGS - Quota flags (32-bit). + */ +typedef enum { + /* The user quota flags. Names explain meaning. */ + QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001), + QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002), + QUOTA_FLAG_ID_DELETED = const_cpu_to_le32(0x00000004), + + QUOTA_FLAG_USER_MASK = const_cpu_to_le32(0x00000007), + /* Bit mask for user quota flags. */ + + /* These flags are only present in the quota defaults index entry, + i.e. in the entry where owner_id = QUOTA_DEFAULTS_ID. */ + QUOTA_FLAG_TRACKING_ENABLED = const_cpu_to_le32(0x00000010), + QUOTA_FLAG_ENFORCEMENT_ENABLED = const_cpu_to_le32(0x00000020), + QUOTA_FLAG_TRACKING_REQUESTED = const_cpu_to_le32(0x00000040), + QUOTA_FLAG_LOG_THRESHOLD = const_cpu_to_le32(0x00000080), + QUOTA_FLAG_LOG_LIMIT = const_cpu_to_le32(0x00000100), + QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200), + QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400), + QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800), +} QUOTA_FLAGS; + +/** + * struct QUOTA_CONTROL_ENTRY - + * + * The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas + * are on a per volume and per user basis. + * + * The $Q index contains one entry for each existing user_id on the volume. The + * index key is the user_id of the user/group owning this quota control entry, + * i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the + * owner_id, is found in the standard information attribute. The collation rule + * for $Q is COLLATION_NTOFS_ULONG. + * + * The $O index contains one entry for each user/group who has been assigned + * a quota on that volume. The index key holds the SID of the user_id the + * entry belongs to, i.e. the owner_id. The collation rule for $O is + * COLLATION_NTOFS_SID. + * + * The $O index entry data is the user_id of the user corresponding to the SID. + * This user_id is used as an index into $Q to find the quota control entry + * associated with the SID. + * + * The $Q index entry data is the quota control entry and is defined below. + */ +typedef struct { + u32 version; /* Currently equals 2. */ + QUOTA_FLAGS flags; /* Flags describing this quota entry. */ + u64 bytes_used; /* How many bytes of the quota are in use. */ + s64 change_time; /* Last time this quota entry was changed. */ + s64 threshold; /* Soft quota (-1 if not limited). */ + s64 limit; /* Hard quota (-1 if not limited). */ + s64 exceeded_time; /* How long the soft quota has been exceeded. */ +/* The below field is NOT present for the quota defaults entry. */ + SID sid; /* The SID of the user/object associated with + this quota entry. If this field is missing + then the INDEX_ENTRY is padded with zeros + to multiply of 8 which are not counted in + the data_length field. If the sid is present + then this structure is padded with zeros to + multiply of 8 and the padding is counted in + the INDEX_ENTRY's data_length. */ +} __attribute__((__packed__)) QUOTA_CONTROL_ENTRY; + +/** + * struct QUOTA_O_INDEX_DATA - + */ +typedef struct { + u32 owner_id; + u32 unknown; /* Always 32. Seems to be padding and it's not + counted in the INDEX_ENTRY's data_length. + This field shouldn't be really here. */ +} __attribute__((__packed__)) QUOTA_O_INDEX_DATA; + +/** + * enum PREDEFINED_OWNER_IDS - Predefined owner_id values (32-bit). + */ +typedef enum { + QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000), + QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001), + QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100), +} PREDEFINED_OWNER_IDS; + +/** + * enum INDEX_ENTRY_FLAGS - Index entry flags (16-bit). + */ +typedef enum { + INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a + sub-node, i.e. a reference to an index + block in form of a virtual cluster + number (see below). */ + INDEX_ENTRY_END = const_cpu_to_le16(2), /* This signifies the last + entry in an index block. The index + entry does not represent a file but it + can point to a sub-node. */ + INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */ +} __attribute__((__packed__)) INDEX_ENTRY_FLAGS; + +/** + * struct INDEX_ENTRY_HEADER - This the index entry header (see below). + * + * ========================================================== + * !!!!! SEE DESCRIPTION OF THE FIELDS AT INDEX_ENTRY !!!!! + * ========================================================== + */ +typedef struct { +/* 0*/ union { + MFT_REF indexed_file; + struct { + u16 data_offset; + u16 data_length; + u32 reservedV; + } __attribute__((__packed__)); + } __attribute__((__packed__)); +/* 8*/ u16 length; +/* 10*/ u16 key_length; +/* 12*/ INDEX_ENTRY_FLAGS flags; +/* 14*/ u16 reserved; +/* sizeof() = 16 bytes */ +} __attribute__((__packed__)) INDEX_ENTRY_HEADER; + +/** + * struct INDEX_ENTRY - This is an index entry. + * + * A sequence of such entries follows each INDEX_HEADER structure. Together + * they make up a complete index. The index follows either an index root + * attribute or an index allocation attribute. + * + * NOTE: Before NTFS 3.0 only filename attributes were indexed. + */ +typedef struct { +/* 0 INDEX_ENTRY_HEADER; -- Unfolded here as gcc dislikes unnamed structs. */ + union { /* Only valid when INDEX_ENTRY_END is not set. */ + MFT_REF indexed_file; /* The mft reference of the file + described by this index + entry. Used for directory + indexes. */ + struct { /* Used for views/indexes to find the entry's data. */ + u16 data_offset; /* Data byte offset from this + INDEX_ENTRY. Follows the + index key. */ + u16 data_length; /* Data length in bytes. */ + u32 reservedV; /* Reserved (zero). */ + } __attribute__((__packed__)); + } __attribute__((__packed__)); +/* 8*/ u16 length; /* Byte size of this index entry, multiple of + 8-bytes. Size includes INDEX_ENTRY_HEADER + and the optional subnode VCN. See below. */ +/* 10*/ u16 key_length; /* Byte size of the key value, which is in the + index entry. It follows field reserved. Not + multiple of 8-bytes. */ +/* 12*/ INDEX_ENTRY_FLAGS ie_flags; /* Bit field of INDEX_ENTRY_* flags. */ +/* 14*/ u16 reserved; /* Reserved/align to 8-byte boundary. */ +/* End of INDEX_ENTRY_HEADER */ +/* 16*/ union { /* The key of the indexed attribute. NOTE: Only present + if INDEX_ENTRY_END bit in flags is not set. NOTE: On + NTFS versions before 3.0 the only valid key is the + FILE_NAME_ATTR. On NTFS 3.0+ the following + additional index keys are defined: */ + FILE_NAME_ATTR file_name;/* $I30 index in directories. */ + SII_INDEX_KEY sii; /* $SII index in $Secure. */ + SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */ + GUID object_id; /* $O index in FILE_Extend/$ObjId: The + object_id of the mft record found in + the data part of the index. */ + REPARSE_INDEX_KEY reparse; /* $R index in + FILE_Extend/$Reparse. */ + SID sid; /* $O index in FILE_Extend/$Quota: + SID of the owner of the user_id. */ + u32 owner_id; /* $Q index in FILE_Extend/$Quota: + user_id of the owner of the quota + control entry in the data part of + the index. */ + } __attribute__((__packed__)) key; + /* The (optional) index data is inserted here when creating. + VCN vcn; If INDEX_ENTRY_NODE bit in ie_flags is set, the last + eight bytes of this index entry contain the virtual + cluster number of the index block that holds the + entries immediately preceding the current entry. + + If the key_length is zero, then the vcn immediately + follows the INDEX_ENTRY_HEADER. + + The address of the vcn of "ie" INDEX_ENTRY is given by + (char*)ie + le16_to_cpu(ie->length) - sizeof(VCN) + */ +} __attribute__((__packed__)) INDEX_ENTRY; + +/** + * struct BITMAP_ATTR - Attribute: Bitmap (0xb0). + * + * Contains an array of bits (aka a bitfield). + * + * When used in conjunction with the index allocation attribute, each bit + * corresponds to one index block within the index allocation attribute. Thus + * the number of bits in the bitmap * index block size / cluster size is the + * number of clusters in the index allocation attribute. + */ +typedef struct { + u8 bitmap[0]; /* Array of bits. */ +} __attribute__((__packed__)) BITMAP_ATTR; + +/** + * enum PREDEFINED_REPARSE_TAGS - + * + * The reparse point tag defines the type of the reparse point. It also + * includes several flags, which further describe the reparse point. + * + * The reparse point tag is an unsigned 32-bit value divided in three parts: + * + * 1. The least significant 16 bits (i.e. bits 0 to 15) specify the type of + * the reparse point. + * 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use. + * 3. The most significant three bits are flags describing the reparse point. + * They are defined as follows: + * bit 29: Name surrogate bit. If set, the filename is an alias for + * another object in the system. + * bit 30: High-latency bit. If set, accessing the first byte of data will + * be slow. (E.g. the data is stored on a tape drive.) + * bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User + * defined tags have to use zero here. + */ +typedef enum { + IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000), + IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000), + IO_REPARSE_TAG_IS_MICROSOFT = const_cpu_to_le32(0x80000000), + + IO_REPARSE_TAG_RESERVED_ZERO = const_cpu_to_le32(0x00000000), + IO_REPARSE_TAG_RESERVED_ONE = const_cpu_to_le32(0x00000001), + IO_REPARSE_TAG_RESERVED_RANGE = const_cpu_to_le32(0x00000001), + + IO_REPARSE_TAG_NSS = const_cpu_to_le32(0x68000005), + IO_REPARSE_TAG_NSS_RECOVER = const_cpu_to_le32(0x68000006), + IO_REPARSE_TAG_SIS = const_cpu_to_le32(0x68000007), + IO_REPARSE_TAG_DFS = const_cpu_to_le32(0x68000008), + + IO_REPARSE_TAG_MOUNT_POINT = const_cpu_to_le32(0x88000003), + + IO_REPARSE_TAG_HSM = const_cpu_to_le32(0xa8000004), + + IO_REPARSE_TAG_SYMBOLIC_LINK = const_cpu_to_le32(0xe8000000), + + IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xe000ffff), +} PREDEFINED_REPARSE_TAGS; + +/** + * struct REPARSE_POINT - Attribute: Reparse point (0xc0). + * + * NOTE: Can be resident or non-resident. + */ +typedef struct { + u32 reparse_tag; /* Reparse point type (inc. flags). */ + u16 reparse_data_length; /* Byte size of reparse data. */ + u16 reserved; /* Align to 8-byte boundary. */ + u8 reparse_data[0]; /* Meaning depends on reparse_tag. */ +} __attribute__((__packed__)) REPARSE_POINT; + +/** + * struct EA_INFORMATION - Attribute: Extended attribute information (0xd0). + * + * NOTE: Always resident. + */ +typedef struct { + u16 ea_length; /* Byte size of the packed extended + attributes. */ + u16 need_ea_count; /* The number of extended attributes which have + the NEED_EA bit set. */ + u32 ea_query_length; /* Byte size of the buffer required to query + the extended attributes when calling + ZwQueryEaFile() in Windows NT/2k. I.e. the + byte size of the unpacked extended + attributes. */ +} __attribute__((__packed__)) EA_INFORMATION; + +/** + * enum EA_FLAGS - Extended attribute flags (8-bit). + */ +typedef enum { + NEED_EA = 0x80, /* Indicate that the file to which the EA + belongs cannot be interpreted without + understanding the associated extended + attributes. */ +} __attribute__((__packed__)) EA_FLAGS; + +/** + * struct EA_ATTR - Attribute: Extended attribute (EA) (0xe0). + * + * Like the attribute list and the index buffer list, the EA attribute value is + * a sequence of EA_ATTR variable length records. + * + * FIXME: It appears weird that the EA name is not Unicode. Is it true? + * FIXME: It seems that name is always uppercased. Is it true? + */ +typedef struct { + u32 next_entry_offset; /* Offset to the next EA_ATTR. */ + EA_FLAGS flags; /* Flags describing the EA. */ + u8 name_length; /* Length of the name of the extended + attribute in bytes. */ + u16 value_length; /* Byte size of the EA's value. */ + u8 name[0]; /* Name of the EA. */ + u8 value[0]; /* The value of the EA. Immediately + follows the name. */ +} __attribute__((__packed__)) EA_ATTR; + +/** + * struct PROPERTY_SET - Attribute: Property set (0xf0). + * + * Intended to support Native Structure Storage (NSS) - a feature removed from + * NTFS 3.0 during beta testing. + */ +typedef struct { + /* Irrelevant as feature unused. */ +} __attribute__((__packed__)) PROPERTY_SET; + +/** + * struct LOGGED_UTILITY_STREAM - Attribute: Logged utility stream (0x100). + * + * NOTE: Can be resident or non-resident. + * + * Operations on this attribute are logged to the journal ($LogFile) like + * normal metadata changes. + * + * Used by the Encrypting File System (EFS). All encrypted files have this + * attribute with the name $EFS. See below for the relevant structures. + */ +typedef struct { + /* Can be anything the creator chooses. */ +} __attribute__((__packed__)) LOGGED_UTILITY_STREAM; + +/* + * $EFS Data Structure: + * + * The following information is about the data structures that are contained + * inside a logged utility stream (0x100) with a name of "$EFS". + * + * The stream starts with an instance of EFS_ATTR_HEADER. + * + * Next, at offsets offset_to_ddf_array and offset_to_drf_array (unless any of + * them is 0) there is a EFS_DF_ARRAY_HEADER immediately followed by a sequence + * of multiple data decryption/recovery fields. + * + * Each data decryption/recovery field starts with a EFS_DF_HEADER and the next + * one (if it exists) can be found by adding EFS_DF_HEADER->df_length bytes to + * the offset of the beginning of the current EFS_DF_HEADER. + * + * The data decryption/recovery field contains an EFS_DF_CERTIFICATE_HEADER, a + * SID, an optional GUID, an optional container name, a non-optional user name, + * and the encrypted FEK. + * + * Note all the below are best guesses so may have mistakes/inaccuracies. + * Corrections/clarifications/additions are always welcome! + * + * Ntfs.sys takes an EFS value length of <= 0x54 or > 0x40000 to BSOD, i.e. it + * is invalid. + */ + +/** + * struct EFS_ATTR_HEADER - "$EFS" header. + * + * The header of the Logged utility stream (0x100) attribute named "$EFS". + */ +typedef struct { +/* 0*/ u32 length; /* Length of EFS attribute in bytes. */ + u32 state; /* Always 0? */ + u32 version; /* Efs version. Always 2? */ + u32 crypto_api_version; /* Always 0? */ +/* 16*/ u8 unknown4[16]; /* MD5 hash of decrypted FEK? This field is + created with a call to UuidCreate() so is + unlikely to be an MD5 hash and is more + likely to be GUID of this encrytped file + or something like that. */ +/* 32*/ u8 unknown5[16]; /* MD5 hash of DDFs? */ +/* 48*/ u8 unknown6[16]; /* MD5 hash of DRFs? */ +/* 64*/ u32 offset_to_ddf_array;/* Offset in bytes to the array of data + decryption fields (DDF), see below. Zero if + no DDFs are present. */ + u32 offset_to_drf_array;/* Offset in bytes to the array of data + recovery fields (DRF), see below. Zero if + no DRFs are present. */ + u32 reserved; /* Reserved. */ +} __attribute__((__packed__)) EFS_ATTR_HEADER; + +/** + * struct EFS_DF_ARRAY_HEADER - + */ +typedef struct { + u32 df_count; /* Number of data decryption/recovery fields in + the array. */ +} __attribute__((__packed__)) EFS_DF_ARRAY_HEADER; + +/** + * struct EFS_DF_HEADER - + */ +typedef struct { +/* 0*/ u32 df_length; /* Length of this data decryption/recovery + field in bytes. */ + u32 cred_header_offset; /* Offset in bytes to the credential header. */ + u32 fek_size; /* Size in bytes of the encrypted file + encryption key (FEK). */ + u32 fek_offset; /* Offset in bytes to the FEK from the start of + the data decryption/recovery field. */ +/* 16*/ u32 unknown1; /* always 0? Might be just padding. */ +} __attribute__((__packed__)) EFS_DF_HEADER; + +/** + * struct EFS_DF_CREDENTIAL_HEADER - + */ +typedef struct { +/* 0*/ u32 cred_length; /* Length of this credential in bytes. */ + u32 sid_offset; /* Offset in bytes to the user's sid from start + of this structure. Zero if no sid is + present. */ +/* 8*/ u32 type; /* Type of this credential: + 1 = CryptoAPI container. + 2 = Unexpected type. + 3 = Certificate thumbprint. + other = Unknown type. */ + union { + /* CryptoAPI container. */ + struct { +/* 12*/ u32 container_name_offset; /* Offset in bytes to + the name of the container from start of this + structure (may not be zero). */ +/* 16*/ u32 provider_name_offset; /* Offset in bytes to + the name of the provider from start of this + structure (may not be zero). */ + u32 public_key_blob_offset; /* Offset in bytes to + the public key blob from start of this + structure. */ +/* 24*/ u32 public_key_blob_size; /* Size in bytes of + public key blob. */ + } __attribute__((__packed__)); + /* Certificate thumbprint. */ + struct { +/* 12*/ u32 cert_thumbprint_header_size; /* Size in + bytes of the header of the certificate + thumbprint. */ +/* 16*/ u32 cert_thumbprint_header_offset; /* Offset in + bytes to the header of the certificate + thumbprint from start of this structure. */ + u32 unknown1; /* Always 0? Might be padding... */ + u32 unknown2; /* Always 0? Might be padding... */ + } __attribute__((__packed__)); + } __attribute__((__packed__)); +} __attribute__((__packed__)) EFS_DF_CREDENTIAL_HEADER; + +typedef EFS_DF_CREDENTIAL_HEADER EFS_DF_CRED_HEADER; + +/** + * struct EFS_DF_CERTIFICATE_THUMBPRINT_HEADER - + */ +typedef struct { +/* 0*/ u32 thumbprint_offset; /* Offset in bytes to the thumbprint. */ + u32 thumbprint_size; /* Size of thumbprint in bytes. */ +/* 8*/ u32 container_name_offset; /* Offset in bytes to the name of the + container from start of this + structure or 0 if no name present. */ + u32 provider_name_offset; /* Offset in bytes to the name of the + cryptographic provider from start of + this structure or 0 if no name + present. */ +/* 16*/ u32 user_name_offset; /* Offset in bytes to the user name + from start of this structure or 0 if + no user name present. (This is also + known as lpDisplayInformation.) */ +} __attribute__((__packed__)) EFS_DF_CERTIFICATE_THUMBPRINT_HEADER; + +typedef EFS_DF_CERTIFICATE_THUMBPRINT_HEADER EFS_DF_CERT_THUMBPRINT_HEADER; + +typedef enum { + INTX_SYMBOLIC_LINK = + const_cpu_to_le64(0x014B4E4C78746E49ULL), /* "IntxLNK\1" */ + INTX_CHARACTER_DEVICE = + const_cpu_to_le64(0x0052484378746E49ULL), /* "IntxCHR\0" */ + INTX_BLOCK_DEVICE = + const_cpu_to_le64(0x004B4C4278746E49ULL), /* "IntxBLK\0" */ +} INTX_FILE_TYPES; + +typedef struct { + INTX_FILE_TYPES magic; /* Intx file magic. */ + union { + /* For character and block devices. */ + struct { + u64 major; /* Major device number. */ + u64 minor; /* Minor device number. */ + void *device_end[0]; /* Marker for offsetof(). */ + } __attribute__((__packed__)); + /* For symbolic links. */ + ntfschar target[0]; + } __attribute__((__packed__)); +} __attribute__((__packed__)) INTX_FILE; + +#endif /* defined _NTFS_LAYOUT_H */ diff --git a/libcustomntfs/lcnalloc.c b/libcustomntfs/lcnalloc.c new file mode 100644 index 00000000..e84d2431 --- /dev/null +++ b/libcustomntfs/lcnalloc.c @@ -0,0 +1,771 @@ +/** + * lcnalloc.c - Cluster (de)allocation code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2004 Anton Altaparmakov + * Copyright (c) 2004 Yura Pakhuchiy + * Copyright (c) 2004-2008 Szabolcs Szakacsits + * Copyright (c) 2008-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "types.h" +#include "attrib.h" +#include "bitmap.h" +#include "debug.h" +#include "runlist.h" +#include "volume.h" +#include "lcnalloc.h" +#include "logging.h" +#include "misc.h" + +/* + * Plenty possibilities for big optimizations all over in the cluster + * allocation, however at the moment the dominant bottleneck (~ 90%) is + * the update of the mapping pairs which converges to the cubic Faulhaber's + * formula as the function of the number of extents (fragments, runs). + */ +#define NTFS_LCNALLOC_BSIZE 4096 +#define NTFS_LCNALLOC_SKIP NTFS_LCNALLOC_BSIZE + +enum { + ZONE_MFT = 1, + ZONE_DATA1 = 2, + ZONE_DATA2 = 4 +} ; + +static void ntfs_cluster_set_zone_pos(LCN start, LCN end, LCN *pos, LCN tc) +{ + ntfs_log_trace("pos: %lld tc: %lld\n", (long long)*pos, (long long)tc); + + if (tc >= end) + *pos = start; + else if (tc >= start) + *pos = tc; +} + +static void ntfs_cluster_update_zone_pos(ntfs_volume *vol, u8 zone, LCN tc) +{ + ntfs_log_trace("tc = %lld, zone = %d\n", (long long)tc, zone); + + if (zone == ZONE_MFT) + ntfs_cluster_set_zone_pos(vol->mft_lcn, vol->mft_zone_end, + &vol->mft_zone_pos, tc); + else if (zone == ZONE_DATA1) + ntfs_cluster_set_zone_pos(vol->mft_zone_end, vol->nr_clusters, + &vol->data1_zone_pos, tc); + else /* zone == ZONE_DATA2 */ + ntfs_cluster_set_zone_pos(0, vol->mft_zone_start, + &vol->data2_zone_pos, tc); +} + +/* + * Unmark full zones when a cluster has been freed in a full zone + * + * Next allocation will reuse the freed cluster + */ + +static void update_full_status(ntfs_volume *vol, LCN lcn) +{ + if (lcn >= vol->mft_zone_end) { + if (vol->full_zones & ZONE_DATA1) { + ntfs_cluster_update_zone_pos(vol, ZONE_DATA1, lcn); + vol->full_zones &= ~ZONE_DATA1; + } + } else + if (lcn < vol->mft_zone_start) { + if (vol->full_zones & ZONE_DATA2) { + ntfs_cluster_update_zone_pos(vol, ZONE_DATA2, lcn); + vol->full_zones &= ~ZONE_DATA2; + } + } else { + if (vol->full_zones & ZONE_MFT) { + ntfs_cluster_update_zone_pos(vol, ZONE_MFT, lcn); + vol->full_zones &= ~ZONE_MFT; + } + } +} + +static s64 max_empty_bit_range(unsigned char *buf, int size) +{ + int i, j, run = 0; + int max_range = 0; + s64 start_pos = -1; + + ntfs_log_trace("Entering\n"); + + i = 0; + while (i < size) { + switch (*buf) { + case 0 : + do { + buf++; + run += 8; + i++; + } while ((i < size) && !*buf); + break; + case 255 : + if (run > max_range) { + max_range = run; + start_pos = (s64)i * 8 - run; + } + run = 0; + do { + buf++; + i++; + } while ((i < size) && (*buf == 255)); + break; + default : + for (j = 0; j < 8; j++) { + + int bit = *buf & (1 << j); + + if (bit) { + if (run > max_range) { + max_range = run; + start_pos = (s64)i * 8 + (j - run); + } + run = 0; + } else + run++; + } + i++; + buf++; + + } + } + + if (run > max_range) + start_pos = (s64)i * 8 - run; + + return start_pos; +} + +static int bitmap_writeback(ntfs_volume *vol, s64 pos, s64 size, void *b, + u8 *writeback) +{ + s64 written; + + ntfs_log_trace("Entering\n"); + + if (!*writeback) + return 0; + + *writeback = 0; + + written = ntfs_attr_pwrite(vol->lcnbmp_na, pos, size, b); + if (written != size) { + if (!written) + errno = EIO; + ntfs_log_perror("Bitmap write error (%lld, %lld)", + (long long)pos, (long long)size); + return -1; + } + + return 0; +} + +/** + * ntfs_cluster_alloc - allocate clusters on an ntfs volume + * @vol: mounted ntfs volume on which to allocate the clusters + * @start_vcn: vcn to use for the first allocated cluster + * @count: number of clusters to allocate + * @start_lcn: starting lcn at which to allocate the clusters (or -1 if none) + * @zone: zone from which to allocate the clusters + * + * Allocate @count clusters preferably starting at cluster @start_lcn or at the + * current allocator position if @start_lcn is -1, on the mounted ntfs volume + * @vol. @zone is either DATA_ZONE for allocation of normal clusters and + * MFT_ZONE for allocation of clusters for the master file table, i.e. the + * $MFT/$DATA attribute. + * + * On success return a runlist describing the allocated cluster(s). + * + * On error return NULL with errno set to the error code. + * + * Notes on the allocation algorithm + * ================================= + * + * There are two data zones. First is the area between the end of the mft zone + * and the end of the volume, and second is the area between the start of the + * volume and the start of the mft zone. On unmodified/standard NTFS 1.x + * volumes, the second data zone doesn't exist due to the mft zone being + * expanded to cover the start of the volume in order to reserve space for the + * mft bitmap attribute. + * + * The complexity stems from the need of implementing the mft vs data zoned + * approach and from the fact that we have access to the lcn bitmap via up to + * NTFS_LCNALLOC_BSIZE bytes at a time, so we need to cope with crossing over + * boundaries of two buffers. Further, the fact that the allocator allows for + * caller supplied hints as to the location of where allocation should begin + * and the fact that the allocator keeps track of where in the data zones the + * next natural allocation should occur, contribute to the complexity of the + * function. But it should all be worthwhile, because this allocator: + * 1) implements MFT zone reservation + * 2) causes reduction in fragmentation. + * The code is not optimized for speed. + */ +runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, + LCN start_lcn, const NTFS_CLUSTER_ALLOCATION_ZONES zone) +{ + LCN zone_start, zone_end; /* current search range */ + LCN last_read_pos, lcn; + LCN bmp_pos; /* current bit position inside the bitmap */ + LCN prev_lcn = 0, prev_run_len = 0; + s64 clusters, br; + runlist *rl = NULL, *trl; + u8 *buf, *byte, bit, writeback; + u8 pass = 1; /* 1: inside zone; 2: start of zone */ + u8 search_zone; /* 4: data2 (start) 1: mft (middle) 2: data1 (end) */ + u8 done_zones = 0; + u8 has_guess, used_zone_pos; + int err = 0, rlpos, rlsize, buf_size; + + ntfs_log_enter("Entering with count = 0x%llx, start_lcn = 0x%llx, " + "zone = %s_ZONE.\n", (long long)count, (long long) + start_lcn, zone == MFT_ZONE ? "MFT" : "DATA"); + + if (!vol || count < 0 || start_lcn < -1 || !vol->lcnbmp_na || + (s8)zone < FIRST_ZONE || zone > LAST_ZONE) { + errno = EINVAL; + ntfs_log_perror("%s: vcn: %lld, count: %lld, lcn: %lld", + __FUNCTION__, (long long)start_vcn, + (long long)count, (long long)start_lcn); + goto out; + } + + /* Return empty runlist if @count == 0 */ + if (!count) { + rl = ntfs_malloc(0x1000); + if (rl) { + rl[0].vcn = start_vcn; + rl[0].lcn = LCN_RL_NOT_MAPPED; + rl[0].length = 0; + } + goto out; + } + + buf = ntfs_malloc(NTFS_LCNALLOC_BSIZE); + if (!buf) + goto out; + /* + * If no @start_lcn was requested, use the current zone + * position otherwise use the requested @start_lcn. + */ + has_guess = 1; + zone_start = start_lcn; + + if (zone_start < 0) { + if (zone == DATA_ZONE) + zone_start = vol->data1_zone_pos; + else + zone_start = vol->mft_zone_pos; + has_guess = 0; + } + + used_zone_pos = has_guess ? 0 : 1; + + if (!zone_start || zone_start == vol->mft_zone_start || + zone_start == vol->mft_zone_end) + pass = 2; + + if (zone_start < vol->mft_zone_start) { + zone_end = vol->mft_zone_start; + search_zone = ZONE_DATA2; + } else if (zone_start < vol->mft_zone_end) { + zone_end = vol->mft_zone_end; + search_zone = ZONE_MFT; + } else { + zone_end = vol->nr_clusters; + search_zone = ZONE_DATA1; + } + + bmp_pos = zone_start; + + /* Loop until all clusters are allocated. */ + clusters = count; + rlpos = rlsize = 0; + while (1) { + /* check whether we have exhausted the current zone */ + if (search_zone & vol->full_zones) + goto zone_pass_done; + last_read_pos = bmp_pos >> 3; + br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos, + NTFS_LCNALLOC_BSIZE, buf); + if (br <= 0) { + if (!br) + goto zone_pass_done; + err = errno; + ntfs_log_perror("Reading $BITMAP failed"); + goto err_ret; + } + /* + * We might have read less than NTFS_LCNALLOC_BSIZE bytes + * if we are close to the end of the attribute. + */ + buf_size = (int)br << 3; + lcn = bmp_pos & 7; + bmp_pos &= ~7; + writeback = 0; + + while (lcn < buf_size) { + byte = buf + (lcn >> 3); + bit = 1 << (lcn & 7); + if (has_guess) { + if (*byte & bit) { + has_guess = 0; + break; + } + } else { + lcn = max_empty_bit_range(buf, br); + if (lcn < 0) + break; + has_guess = 1; + continue; + } + + /* First free bit is at lcn + bmp_pos. */ + + /* Reallocate memory if necessary. */ + if ((rlpos + 2) * (int)sizeof(runlist) >= rlsize) { + rlsize += 4096; + trl = realloc(rl, rlsize); + if (!trl) { + err = ENOMEM; + ntfs_log_perror("realloc() failed"); + goto wb_err_ret; + } + rl = trl; + } + + /* Allocate the bitmap bit. */ + *byte |= bit; + writeback = 1; + if (vol->free_clusters <= 0) + ntfs_log_error("Non-positive free clusters " + "(%lld)!\n", + (long long)vol->free_clusters); + else + vol->free_clusters--; + + /* + * Coalesce with previous run if adjacent LCNs. + * Otherwise, append a new run. + */ + if (prev_lcn == lcn + bmp_pos - prev_run_len && rlpos) { + ntfs_log_debug("Cluster coalesce: prev_lcn: " + "%lld lcn: %lld bmp_pos: %lld " + "prev_run_len: %lld\n", + (long long)prev_lcn, + (long long)lcn, (long long)bmp_pos, + (long long)prev_run_len); + rl[rlpos - 1].length = ++prev_run_len; + } else { + if (rlpos) + rl[rlpos].vcn = rl[rlpos - 1].vcn + + prev_run_len; + else { + rl[rlpos].vcn = start_vcn; + ntfs_log_debug("Start_vcn: %lld\n", + (long long)start_vcn); + } + + rl[rlpos].lcn = prev_lcn = lcn + bmp_pos; + rl[rlpos].length = prev_run_len = 1; + rlpos++; + } + + ntfs_log_debug("RUN: %-16lld %-16lld %-16lld\n", + (long long)rl[rlpos - 1].vcn, + (long long)rl[rlpos - 1].lcn, + (long long)rl[rlpos - 1].length); + /* Done? */ + if (!--clusters) { + if (used_zone_pos) + ntfs_cluster_update_zone_pos(vol, + search_zone, lcn + bmp_pos + 1 + + NTFS_LCNALLOC_SKIP); + goto done_ret; + } + + lcn++; + } + + if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) { + err = errno; + goto err_ret; + } + + if (!used_zone_pos) { + + used_zone_pos = 1; + + if (search_zone == ZONE_MFT) + zone_start = vol->mft_zone_pos; + else if (search_zone == ZONE_DATA1) + zone_start = vol->data1_zone_pos; + else + zone_start = vol->data2_zone_pos; + + if (!zone_start || zone_start == vol->mft_zone_start || + zone_start == vol->mft_zone_end) + pass = 2; + bmp_pos = zone_start; + } else + bmp_pos += buf_size; + + if (bmp_pos < zone_end) + continue; + +zone_pass_done: + ntfs_log_trace("Finished current zone pass(%i).\n", pass); + if (pass == 1) { + pass = 2; + zone_end = zone_start; + + if (search_zone == ZONE_MFT) + zone_start = vol->mft_zone_start; + else if (search_zone == ZONE_DATA1) + zone_start = vol->mft_zone_end; + else + zone_start = 0; + + /* Sanity check. */ + if (zone_end < zone_start) + zone_end = zone_start; + + bmp_pos = zone_start; + + continue; + } + /* pass == 2 */ +done_zones_check: + done_zones |= search_zone; + vol->full_zones |= search_zone; + if (done_zones < (ZONE_MFT + ZONE_DATA1 + ZONE_DATA2)) { + ntfs_log_trace("Switching zone.\n"); + pass = 1; + if (rlpos) { + LCN tc = rl[rlpos - 1].lcn + + rl[rlpos - 1].length + NTFS_LCNALLOC_SKIP; + + if (used_zone_pos) + ntfs_cluster_update_zone_pos(vol, + search_zone, tc); + } + + switch (search_zone) { + case ZONE_MFT: + ntfs_log_trace("Zone switch: mft -> data1\n"); +switch_to_data1_zone: search_zone = ZONE_DATA1; + zone_start = vol->data1_zone_pos; + zone_end = vol->nr_clusters; + if (zone_start == vol->mft_zone_end) + pass = 2; + break; + case ZONE_DATA1: + ntfs_log_trace("Zone switch: data1 -> data2\n"); + search_zone = ZONE_DATA2; + zone_start = vol->data2_zone_pos; + zone_end = vol->mft_zone_start; + if (!zone_start) + pass = 2; + break; + case ZONE_DATA2: + if (!(done_zones & ZONE_DATA1)) { + ntfs_log_trace("data2 -> data1\n"); + goto switch_to_data1_zone; + } + ntfs_log_trace("Zone switch: data2 -> mft\n"); + search_zone = ZONE_MFT; + zone_start = vol->mft_zone_pos; + zone_end = vol->mft_zone_end; + if (zone_start == vol->mft_zone_start) + pass = 2; + break; + } + + bmp_pos = zone_start; + + if (zone_start == zone_end) { + ntfs_log_trace("Empty zone, skipped.\n"); + goto done_zones_check; + } + + continue; + } + + ntfs_log_trace("All zones are finished, no space on device.\n"); + err = ENOSPC; + goto err_ret; + } +done_ret: + ntfs_log_debug("At done_ret.\n"); + /* Add runlist terminator element. */ + rl[rlpos].vcn = rl[rlpos - 1].vcn + rl[rlpos - 1].length; + rl[rlpos].lcn = LCN_RL_NOT_MAPPED; + rl[rlpos].length = 0; + if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) { + err = errno; + goto err_ret; + } +done_err_ret: + free(buf); + if (err) { + errno = err; + ntfs_log_perror("Failed to allocate clusters"); + rl = NULL; + } +out: + ntfs_log_leave("\n"); + return rl; + +wb_err_ret: + ntfs_log_trace("At wb_err_ret.\n"); + if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) + err = errno; +err_ret: + ntfs_log_trace("At err_ret.\n"); + if (rl) { + /* Add runlist terminator element. */ + rl[rlpos].vcn = rl[rlpos - 1].vcn + rl[rlpos - 1].length; + rl[rlpos].lcn = LCN_RL_NOT_MAPPED; + rl[rlpos].length = 0; + ntfs_debug_runlist_dump(rl); + ntfs_cluster_free_from_rl(vol, rl); + free(rl); + rl = NULL; + } + goto done_err_ret; +} + +/** + * ntfs_cluster_free_from_rl - free clusters from runlist + * @vol: mounted ntfs volume on which to free the clusters + * @rl: runlist from which deallocate clusters + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +int ntfs_cluster_free_from_rl(ntfs_volume *vol, runlist *rl) +{ + s64 nr_freed = 0; + int ret = -1; + + ntfs_log_trace("Entering.\n"); + + for (; rl->length; rl++) { + + ntfs_log_trace("Dealloc lcn 0x%llx, len 0x%llx.\n", + (long long)rl->lcn, (long long)rl->length); + + if (rl->lcn >= 0) { + update_full_status(vol,rl->lcn); + if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn, + rl->length)) { + ntfs_log_perror("Cluster deallocation failed " + "(%lld, %lld)", + (long long)rl->lcn, + (long long)rl->length); + goto out; + } + nr_freed += rl->length ; + } + } + + ret = 0; +out: + vol->free_clusters += nr_freed; + if (vol->free_clusters > vol->nr_clusters) + ntfs_log_error("Too many free clusters (%lld > %lld)!", + (long long)vol->free_clusters, + (long long)vol->nr_clusters); + return ret; +} + +/* + * Basic cluster run free + * Returns 0 if successful + */ + +int ntfs_cluster_free_basic(ntfs_volume *vol, s64 lcn, s64 count) +{ + s64 nr_freed = 0; + int ret = -1; + + ntfs_log_trace("Entering.\n"); + ntfs_log_trace("Dealloc lcn 0x%llx, len 0x%llx.\n", + (long long)lcn, (long long)count); + + if (lcn >= 0) { + update_full_status(vol,lcn); + if (ntfs_bitmap_clear_run(vol->lcnbmp_na, lcn, + count)) { + ntfs_log_perror("Cluster deallocation failed " + "(%lld, %lld)", + (long long)lcn, + (long long)count); + goto out; + } + nr_freed += count; + } + ret = 0; +out: + vol->free_clusters += nr_freed; + if (vol->free_clusters > vol->nr_clusters) + ntfs_log_error("Too many free clusters (%lld > %lld)!", + (long long)vol->free_clusters, + (long long)vol->nr_clusters); + return ret; +} + +/** + * ntfs_cluster_free - free clusters on an ntfs volume + * @vol: mounted ntfs volume on which to free the clusters + * @na: attribute whose runlist describes the clusters to free + * @start_vcn: vcn in @rl at which to start freeing clusters + * @count: number of clusters to free or -1 for all clusters + * + * Free @count clusters starting at the cluster @start_vcn in the runlist + * described by the attribute @na from the mounted ntfs volume @vol. + * + * If @count is -1, all clusters from @start_vcn to the end of the runlist + * are deallocated. + * + * On success return the number of deallocated clusters (not counting sparse + * clusters) and on error return -1 with errno set to the error code. + */ +int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) +{ + runlist *rl; + s64 delta, to_free, nr_freed = 0; + int ret = -1; + + if (!vol || !vol->lcnbmp_na || !na || start_vcn < 0 || + (count < 0 && count != -1)) { + ntfs_log_trace("Invalid arguments!\n"); + errno = EINVAL; + return -1; + } + + ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x, count 0x%llx, " + "vcn 0x%llx.\n", (unsigned long long)na->ni->mft_no, + na->type, (long long)count, (long long)start_vcn); + + rl = ntfs_attr_find_vcn(na, start_vcn); + if (!rl) { + if (errno == ENOENT) + ret = 0; + goto leave; + } + + if (rl->lcn < 0 && rl->lcn != LCN_HOLE) { + errno = EIO; + ntfs_log_perror("%s: Unexpected lcn (%lld)", __FUNCTION__, + (long long)rl->lcn); + goto leave; + } + + /* Find the starting cluster inside the run that needs freeing. */ + delta = start_vcn - rl->vcn; + + /* The number of clusters in this run that need freeing. */ + to_free = rl->length - delta; + if (count >= 0 && to_free > count) + to_free = count; + + if (rl->lcn != LCN_HOLE) { + /* Do the actual freeing of the clusters in this run. */ + update_full_status(vol,rl->lcn + delta); + if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn + delta, + to_free)) + goto leave; + nr_freed = to_free; + } + + /* Go to the next run and adjust the number of clusters left to free. */ + ++rl; + if (count >= 0) + count -= to_free; + + /* + * Loop over the remaining runs, using @count as a capping value, and + * free them. + */ + for (; rl->length && count != 0; ++rl) { + // FIXME: Need to try ntfs_attr_map_runlist() for attribute + // list support! (AIA) + if (rl->lcn < 0 && rl->lcn != LCN_HOLE) { + // FIXME: Eeek! We need rollback! (AIA) + errno = EIO; + ntfs_log_perror("%s: Invalid lcn (%lli)", + __FUNCTION__, (long long)rl->lcn); + goto out; + } + + /* The number of clusters in this run that need freeing. */ + to_free = rl->length; + if (count >= 0 && to_free > count) + to_free = count; + + if (rl->lcn != LCN_HOLE) { + update_full_status(vol,rl->lcn); + if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn, + to_free)) { + // FIXME: Eeek! We need rollback! (AIA) + ntfs_log_perror("%s: Clearing bitmap run failed", + __FUNCTION__); + goto out; + } + nr_freed += to_free; + } + + if (count >= 0) + count -= to_free; + } + + if (count != -1 && count != 0) { + // FIXME: Eeek! BUG() + errno = EIO; + ntfs_log_perror("%s: count still not zero (%lld)", __FUNCTION__, + (long long)count); + goto out; + } + + ret = nr_freed; +out: + vol->free_clusters += nr_freed ; + if (vol->free_clusters > vol->nr_clusters) + ntfs_log_error("Too many free clusters (%lld > %lld)!", + (long long)vol->free_clusters, + (long long)vol->nr_clusters); +leave: + ntfs_log_leave("\n"); + return ret; +} diff --git a/libcustomntfs/lcnalloc.h b/libcustomntfs/lcnalloc.h new file mode 100644 index 00000000..cbf4c5cd --- /dev/null +++ b/libcustomntfs/lcnalloc.h @@ -0,0 +1,51 @@ +/* + * lcnalloc.h - Exports for cluster (de)allocation. Originated from the Linux-NTFS + * project. + * + * Copyright (c) 2002 Anton Altaparmakov + * Copyright (c) 2004 Yura Pakhuchiy + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_LCNALLOC_H +#define _NTFS_LCNALLOC_H + +#include "types.h" +#include "runlist.h" +#include "volume.h" + +/** + * enum NTFS_CLUSTER_ALLOCATION_ZONES - + */ +typedef enum { + FIRST_ZONE = 0, /* For sanity checking. */ + MFT_ZONE = 0, /* Allocate from $MFT zone. */ + DATA_ZONE = 1, /* Allocate from $DATA zone. */ + LAST_ZONE = 1, /* For sanity checking. */ +} NTFS_CLUSTER_ALLOCATION_ZONES; + +extern runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count, + LCN start_lcn, const NTFS_CLUSTER_ALLOCATION_ZONES zone); + +extern int ntfs_cluster_free_from_rl(ntfs_volume *vol, runlist *rl); +extern int ntfs_cluster_free_basic(ntfs_volume *vol, s64 lcn, s64 count); + +extern int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, + s64 count); + +#endif /* defined _NTFS_LCNALLOC_H */ + diff --git a/libcustomntfs/logfile.c b/libcustomntfs/logfile.c new file mode 100644 index 00000000..277ad142 --- /dev/null +++ b/libcustomntfs/logfile.c @@ -0,0 +1,737 @@ +/** + * logfile.c - NTFS journal handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2005 Anton Altaparmakov + * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2005-2009 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "attrib.h" +#include "debug.h" +#include "logfile.h" +#include "volume.h" +#include "mst.h" +#include "logging.h" +#include "misc.h" + +/** + * ntfs_check_restart_page_header - check the page header for consistency + * @rp: restart page header to check + * @pos: position in logfile at which the restart page header resides + * + * Check the restart page header @rp for consistency and return TRUE if it is + * consistent and FALSE otherwise. + * + * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not + * require the full restart page. + */ +static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) +{ + u32 logfile_system_page_size, logfile_log_page_size; + u16 ra_ofs, usa_count, usa_ofs, usa_end = 0; + BOOL have_usa = TRUE; + + ntfs_log_trace("Entering.\n"); + /* + * If the system or log page sizes are smaller than the ntfs block size + * or either is not a power of 2 we cannot handle this log file. + */ + logfile_system_page_size = le32_to_cpu(rp->system_page_size); + logfile_log_page_size = le32_to_cpu(rp->log_page_size); + if (logfile_system_page_size < NTFS_BLOCK_SIZE || + logfile_log_page_size < NTFS_BLOCK_SIZE || + logfile_system_page_size & + (logfile_system_page_size - 1) || + logfile_log_page_size & (logfile_log_page_size - 1)) { + ntfs_log_error("$LogFile uses unsupported page size.\n"); + return FALSE; + } + /* + * We must be either at !pos (1st restart page) or at pos = system page + * size (2nd restart page). + */ + if (pos && pos != logfile_system_page_size) { + ntfs_log_error("Found restart area in incorrect " + "position in $LogFile.\n"); + return FALSE; + } + /* We only know how to handle version 1.1. */ + if (sle16_to_cpu(rp->major_ver) != 1 || + sle16_to_cpu(rp->minor_ver) != 1) { + ntfs_log_error("$LogFile version %i.%i is not " + "supported. (This driver supports version " + "1.1 only.)\n", (int)sle16_to_cpu(rp->major_ver), + (int)sle16_to_cpu(rp->minor_ver)); + return FALSE; + } + /* + * If chkdsk has been run the restart page may not be protected by an + * update sequence array. + */ + if (ntfs_is_chkd_record(rp->magic) && !le16_to_cpu(rp->usa_count)) { + have_usa = FALSE; + goto skip_usa_checks; + } + /* Verify the size of the update sequence array. */ + usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS); + if (usa_count != le16_to_cpu(rp->usa_count)) { + ntfs_log_error("$LogFile restart page specifies " + "inconsistent update sequence array count.\n"); + return FALSE; + } + /* Verify the position of the update sequence array. */ + usa_ofs = le16_to_cpu(rp->usa_ofs); + usa_end = usa_ofs + usa_count * sizeof(u16); + if (usa_ofs < sizeof(RESTART_PAGE_HEADER) || + usa_end > NTFS_BLOCK_SIZE - sizeof(u16)) { + ntfs_log_error("$LogFile restart page specifies " + "inconsistent update sequence array offset.\n"); + return FALSE; + } +skip_usa_checks: + /* + * Verify the position of the restart area. It must be: + * - aligned to 8-byte boundary, + * - after the update sequence array, and + * - within the system page size. + */ + ra_ofs = le16_to_cpu(rp->restart_area_offset); + if (ra_ofs & 7 || (have_usa ? ra_ofs < usa_end : + ra_ofs < sizeof(RESTART_PAGE_HEADER)) || + ra_ofs > logfile_system_page_size) { + ntfs_log_error("$LogFile restart page specifies " + "inconsistent restart area offset.\n"); + return FALSE; + } + /* + * Only restart pages modified by chkdsk are allowed to have chkdsk_lsn + * set. + */ + if (!ntfs_is_chkd_record(rp->magic) && sle64_to_cpu(rp->chkdsk_lsn)) { + ntfs_log_error("$LogFile restart page is not modified " + "by chkdsk but a chkdsk LSN is specified.\n"); + return FALSE; + } + ntfs_log_trace("Done.\n"); + return TRUE; +} + +/** + * ntfs_check_restart_area - check the restart area for consistency + * @rp: restart page whose restart area to check + * + * Check the restart area of the restart page @rp for consistency and return + * TRUE if it is consistent and FALSE otherwise. + * + * This function assumes that the restart page header has already been + * consistency checked. + * + * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not + * require the full restart page. + */ +static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp) +{ + u64 file_size; + RESTART_AREA *ra; + u16 ra_ofs, ra_len, ca_ofs; + u8 fs_bits; + + ntfs_log_trace("Entering.\n"); + ra_ofs = le16_to_cpu(rp->restart_area_offset); + ra = (RESTART_AREA*)((u8*)rp + ra_ofs); + /* + * Everything before ra->file_size must be before the first word + * protected by an update sequence number. This ensures that it is + * safe to access ra->client_array_offset. + */ + if (ra_ofs + offsetof(RESTART_AREA, file_size) > + NTFS_BLOCK_SIZE - sizeof(u16)) { + ntfs_log_error("$LogFile restart area specifies " + "inconsistent file offset.\n"); + return FALSE; + } + /* + * Now that we can access ra->client_array_offset, make sure everything + * up to the log client array is before the first word protected by an + * update sequence number. This ensures we can access all of the + * restart area elements safely. Also, the client array offset must be + * aligned to an 8-byte boundary. + */ + ca_ofs = le16_to_cpu(ra->client_array_offset); + if (((ca_ofs + 7) & ~7) != ca_ofs || + ra_ofs + ca_ofs > (u16)(NTFS_BLOCK_SIZE - + sizeof(u16))) { + ntfs_log_error("$LogFile restart area specifies " + "inconsistent client array offset.\n"); + return FALSE; + } + /* + * The restart area must end within the system page size both when + * calculated manually and as specified by ra->restart_area_length. + * Also, the calculated length must not exceed the specified length. + */ + ra_len = ca_ofs + le16_to_cpu(ra->log_clients) * + sizeof(LOG_CLIENT_RECORD); + if ((u32)(ra_ofs + ra_len) > le32_to_cpu(rp->system_page_size) || + (u32)(ra_ofs + le16_to_cpu(ra->restart_area_length)) > + le32_to_cpu(rp->system_page_size) || + ra_len > le16_to_cpu(ra->restart_area_length)) { + ntfs_log_error("$LogFile restart area is out of bounds " + "of the system page size specified by the " + "restart page header and/or the specified " + "restart area length is inconsistent.\n"); + return FALSE; + } + /* + * The ra->client_free_list and ra->client_in_use_list must be either + * LOGFILE_NO_CLIENT or less than ra->log_clients or they are + * overflowing the client array. + */ + if ((ra->client_free_list != LOGFILE_NO_CLIENT && + le16_to_cpu(ra->client_free_list) >= + le16_to_cpu(ra->log_clients)) || + (ra->client_in_use_list != LOGFILE_NO_CLIENT && + le16_to_cpu(ra->client_in_use_list) >= + le16_to_cpu(ra->log_clients))) { + ntfs_log_error("$LogFile restart area specifies " + "overflowing client free and/or in use lists.\n"); + return FALSE; + } + /* + * Check ra->seq_number_bits against ra->file_size for consistency. + * We cannot just use ffs() because the file size is not a power of 2. + */ + file_size = (u64)sle64_to_cpu(ra->file_size); + fs_bits = 0; + while (file_size) { + file_size >>= 1; + fs_bits++; + } + if (le32_to_cpu(ra->seq_number_bits) != (u32)(67 - fs_bits)) { + ntfs_log_error("$LogFile restart area specifies " + "inconsistent sequence number bits.\n"); + return FALSE; + } + /* The log record header length must be a multiple of 8. */ + if (((le16_to_cpu(ra->log_record_header_length) + 7) & ~7) != + le16_to_cpu(ra->log_record_header_length)) { + ntfs_log_error("$LogFile restart area specifies " + "inconsistent log record header length.\n"); + return FALSE; + } + /* Ditto for the log page data offset. */ + if (((le16_to_cpu(ra->log_page_data_offset) + 7) & ~7) != + le16_to_cpu(ra->log_page_data_offset)) { + ntfs_log_error("$LogFile restart area specifies " + "inconsistent log page data offset.\n"); + return FALSE; + } + ntfs_log_trace("Done.\n"); + return TRUE; +} + +/** + * ntfs_check_log_client_array - check the log client array for consistency + * @rp: restart page whose log client array to check + * + * Check the log client array of the restart page @rp for consistency and + * return TRUE if it is consistent and FALSE otherwise. + * + * This function assumes that the restart page header and the restart area have + * already been consistency checked. + * + * Unlike ntfs_check_restart_page_header() and ntfs_check_restart_area(), this + * function needs @rp->system_page_size bytes in @rp, i.e. it requires the full + * restart page and the page must be multi sector transfer deprotected. + */ +static BOOL ntfs_check_log_client_array(RESTART_PAGE_HEADER *rp) +{ + RESTART_AREA *ra; + LOG_CLIENT_RECORD *ca, *cr; + u16 nr_clients, idx; + BOOL in_free_list, idx_is_first; + + ntfs_log_trace("Entering.\n"); + ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); + ca = (LOG_CLIENT_RECORD*)((u8*)ra + + le16_to_cpu(ra->client_array_offset)); + /* + * Check the ra->client_free_list first and then check the + * ra->client_in_use_list. Check each of the log client records in + * each of the lists and check that the array does not overflow the + * ra->log_clients value. Also keep track of the number of records + * visited as there cannot be more than ra->log_clients records and + * that way we detect eventual loops in within a list. + */ + nr_clients = le16_to_cpu(ra->log_clients); + idx = le16_to_cpu(ra->client_free_list); + in_free_list = TRUE; +check_list: + for (idx_is_first = TRUE; idx != LOGFILE_NO_CLIENT_CPU; nr_clients--, + idx = le16_to_cpu(cr->next_client)) { + if (!nr_clients || idx >= le16_to_cpu(ra->log_clients)) + goto err_out; + /* Set @cr to the current log client record. */ + cr = ca + idx; + /* The first log client record must not have a prev_client. */ + if (idx_is_first) { + if (cr->prev_client != LOGFILE_NO_CLIENT) + goto err_out; + idx_is_first = FALSE; + } + } + /* Switch to and check the in use list if we just did the free list. */ + if (in_free_list) { + in_free_list = FALSE; + idx = le16_to_cpu(ra->client_in_use_list); + goto check_list; + } + ntfs_log_trace("Done.\n"); + return TRUE; +err_out: + ntfs_log_error("$LogFile log client array is corrupt.\n"); + return FALSE; +} + +/** + * ntfs_check_and_load_restart_page - check the restart page for consistency + * @log_na: opened ntfs attribute for journal $LogFile + * @rp: restart page to check + * @pos: position in @log_na at which the restart page resides + * @wrp: [OUT] copy of the multi sector transfer deprotected restart page + * @lsn: [OUT] set to the current logfile lsn on success + * + * Check the restart page @rp for consistency and return 0 if it is consistent + * and errno otherwise. The restart page may have been modified by chkdsk in + * which case its magic is CHKD instead of RSTR. + * + * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not + * require the full restart page. + * + * If @wrp is not NULL, on success, *@wrp will point to a buffer containing a + * copy of the complete multi sector transfer deprotected page. On failure, + * *@wrp is undefined. + * + * Similarly, if @lsn is not NULL, on success *@lsn will be set to the current + * logfile lsn according to this restart page. On failure, *@lsn is undefined. + * + * The following error codes are defined: + * EINVAL - The restart page is inconsistent. + * ENOMEM - Not enough memory to load the restart page. + * EIO - Failed to reading from $LogFile. + */ +static int ntfs_check_and_load_restart_page(ntfs_attr *log_na, + RESTART_PAGE_HEADER *rp, s64 pos, RESTART_PAGE_HEADER **wrp, + LSN *lsn) +{ + RESTART_AREA *ra; + RESTART_PAGE_HEADER *trp; + int err; + + ntfs_log_trace("Entering.\n"); + /* Check the restart page header for consistency. */ + if (!ntfs_check_restart_page_header(rp, pos)) { + /* Error output already done inside the function. */ + return EINVAL; + } + /* Check the restart area for consistency. */ + if (!ntfs_check_restart_area(rp)) { + /* Error output already done inside the function. */ + return EINVAL; + } + ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); + /* + * Allocate a buffer to store the whole restart page so we can multi + * sector transfer deprotect it. + */ + trp = ntfs_malloc(le32_to_cpu(rp->system_page_size)); + if (!trp) + return errno; + /* + * Read the whole of the restart page into the buffer. If it fits + * completely inside @rp, just copy it from there. Otherwise read it + * from disk. + */ + if (le32_to_cpu(rp->system_page_size) <= NTFS_BLOCK_SIZE) + memcpy(trp, rp, le32_to_cpu(rp->system_page_size)); + else if (ntfs_attr_pread(log_na, pos, + le32_to_cpu(rp->system_page_size), trp) != + le32_to_cpu(rp->system_page_size)) { + err = errno; + ntfs_log_error("Failed to read whole restart page into the " + "buffer.\n"); + if (err != ENOMEM) + err = EIO; + goto err_out; + } + /* + * Perform the multi sector transfer deprotection on the buffer if the + * restart page is protected. + */ + if ((!ntfs_is_chkd_record(trp->magic) || le16_to_cpu(trp->usa_count)) + && ntfs_mst_post_read_fixup((NTFS_RECORD*)trp, + le32_to_cpu(rp->system_page_size))) { + /* + * A multi sector tranfer error was detected. We only need to + * abort if the restart page contents exceed the multi sector + * transfer fixup of the first sector. + */ + if (le16_to_cpu(rp->restart_area_offset) + + le16_to_cpu(ra->restart_area_length) > + NTFS_BLOCK_SIZE - (int)sizeof(u16)) { + ntfs_log_error("Multi sector transfer error " + "detected in $LogFile restart page.\n"); + err = EINVAL; + goto err_out; + } + } + /* + * If the restart page is modified by chkdsk or there are no active + * logfile clients, the logfile is consistent. Otherwise, need to + * check the log client records for consistency, too. + */ + err = 0; + if (ntfs_is_rstr_record(rp->magic) && + ra->client_in_use_list != LOGFILE_NO_CLIENT) { + if (!ntfs_check_log_client_array(trp)) { + err = EINVAL; + goto err_out; + } + } + if (lsn) { + if (ntfs_is_rstr_record(rp->magic)) + *lsn = sle64_to_cpu(ra->current_lsn); + else /* if (ntfs_is_chkd_record(rp->magic)) */ + *lsn = sle64_to_cpu(rp->chkdsk_lsn); + } + ntfs_log_trace("Done.\n"); + if (wrp) + *wrp = trp; + else { +err_out: + free(trp); + } + return err; +} + +/** + * ntfs_check_logfile - check in the journal if the volume is consistent + * @log_na: ntfs attribute of loaded journal $LogFile to check + * @rp: [OUT] on success this is a copy of the current restart page + * + * Check the $LogFile journal for consistency and return TRUE if it is + * consistent and FALSE if not. On success, the current restart page is + * returned in *@rp. Caller must call ntfs_free(*@rp) when finished with it. + * + * At present we only check the two restart pages and ignore the log record + * pages. + * + * Note that the MstProtected flag is not set on the $LogFile inode and hence + * when reading pages they are not deprotected. This is because we do not know + * if the $LogFile was created on a system with a different page size to ours + * yet and mst deprotection would fail if our page size is smaller. + */ +BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp) +{ + s64 size, pos; + LSN rstr1_lsn, rstr2_lsn; + ntfs_volume *vol = log_na->ni->vol; + u8 *kaddr = NULL; + RESTART_PAGE_HEADER *rstr1_ph = NULL; + RESTART_PAGE_HEADER *rstr2_ph = NULL; + int log_page_size, log_page_mask, err; + BOOL logfile_is_empty = TRUE; + u8 log_page_bits; + + ntfs_log_trace("Entering.\n"); + /* An empty $LogFile must have been clean before it got emptied. */ + if (NVolLogFileEmpty(vol)) + goto is_empty; + size = log_na->data_size; + /* Make sure the file doesn't exceed the maximum allowed size. */ + if (size > (s64)MaxLogFileSize) + size = MaxLogFileSize; + log_page_size = DefaultLogPageSize; + log_page_mask = log_page_size - 1; + /* + * Use generic_ffs() instead of ffs() to enable the compiler to + * optimize log_page_size and log_page_bits into constants. + */ + log_page_bits = ffs(log_page_size) - 1; + size &= ~(log_page_size - 1); + + /* + * Ensure the log file is big enough to store at least the two restart + * pages and the minimum number of log record pages. + */ + if (size < log_page_size * 2 || (size - log_page_size * 2) >> + log_page_bits < MinLogRecordPages) { + ntfs_log_error("$LogFile is too small.\n"); + return FALSE; + } + /* Allocate memory for restart page. */ + kaddr = ntfs_malloc(NTFS_BLOCK_SIZE); + if (!kaddr) + return FALSE; + /* + * Read through the file looking for a restart page. Since the restart + * page header is at the beginning of a page we only need to search at + * what could be the beginning of a page (for each page size) rather + * than scanning the whole file byte by byte. If all potential places + * contain empty and uninitialized records, the log file can be assumed + * to be empty. + */ + for (pos = 0; pos < size; pos <<= 1) { + /* + * Read first NTFS_BLOCK_SIZE bytes of potential restart page. + */ + if (ntfs_attr_pread(log_na, pos, NTFS_BLOCK_SIZE, kaddr) != + NTFS_BLOCK_SIZE) { + ntfs_log_error("Failed to read first NTFS_BLOCK_SIZE " + "bytes of potential restart page.\n"); + goto err_out; + } + + /* + * A non-empty block means the logfile is not empty while an + * empty block after a non-empty block has been encountered + * means we are done. + */ + if (!ntfs_is_empty_recordp((le32*)kaddr)) + logfile_is_empty = FALSE; + else if (!logfile_is_empty) + break; + /* + * A log record page means there cannot be a restart page after + * this so no need to continue searching. + */ + if (ntfs_is_rcrd_recordp((le32*)kaddr)) + break; + /* If not a (modified by chkdsk) restart page, continue. */ + if (!ntfs_is_rstr_recordp((le32*)kaddr) && + !ntfs_is_chkd_recordp((le32*)kaddr)) { + if (!pos) + pos = NTFS_BLOCK_SIZE >> 1; + continue; + } + /* + * Check the (modified by chkdsk) restart page for consistency + * and get a copy of the complete multi sector transfer + * deprotected restart page. + */ + err = ntfs_check_and_load_restart_page(log_na, + (RESTART_PAGE_HEADER*)kaddr, pos, + !rstr1_ph ? &rstr1_ph : &rstr2_ph, + !rstr1_ph ? &rstr1_lsn : &rstr2_lsn); + if (!err) { + /* + * If we have now found the first (modified by chkdsk) + * restart page, continue looking for the second one. + */ + if (!pos) { + pos = NTFS_BLOCK_SIZE >> 1; + continue; + } + /* + * We have now found the second (modified by chkdsk) + * restart page, so we can stop looking. + */ + break; + } + /* + * Error output already done inside the function. Note, we do + * not abort if the restart page was invalid as we might still + * find a valid one further in the file. + */ + if (err != EINVAL) + goto err_out; + /* Continue looking. */ + if (!pos) + pos = NTFS_BLOCK_SIZE >> 1; + } + if (kaddr) { + free(kaddr); + kaddr = NULL; + } + if (logfile_is_empty) { + NVolSetLogFileEmpty(vol); +is_empty: + ntfs_log_trace("Done. ($LogFile is empty.)\n"); + return TRUE; + } + if (!rstr1_ph) { + if (rstr2_ph) + ntfs_log_error("BUG: rstr2_ph isn't NULL!\n"); + ntfs_log_error("Did not find any restart pages in " + "$LogFile and it was not empty.\n"); + return FALSE; + } + /* If both restart pages were found, use the more recent one. */ + if (rstr2_ph) { + /* + * If the second restart area is more recent, switch to it. + * Otherwise just throw it away. + */ + if (rstr2_lsn > rstr1_lsn) { + ntfs_log_debug("Using second restart page as it is more " + "recent.\n"); + free(rstr1_ph); + rstr1_ph = rstr2_ph; + /* rstr1_lsn = rstr2_lsn; */ + } else { + ntfs_log_debug("Using first restart page as it is more " + "recent.\n"); + free(rstr2_ph); + } + rstr2_ph = NULL; + } + /* All consistency checks passed. */ + if (rp) + *rp = rstr1_ph; + else + free(rstr1_ph); + ntfs_log_trace("Done.\n"); + return TRUE; +err_out: + free(kaddr); + free(rstr1_ph); + free(rstr2_ph); + return FALSE; +} + +/** + * ntfs_is_logfile_clean - check in the journal if the volume is clean + * @log_na: ntfs attribute of loaded journal $LogFile to check + * @rp: copy of the current restart page + * + * Analyze the $LogFile journal and return TRUE if it indicates the volume was + * shutdown cleanly and FALSE if not. + * + * At present we only look at the two restart pages and ignore the log record + * pages. This is a little bit crude in that there will be a very small number + * of cases where we think that a volume is dirty when in fact it is clean. + * This should only affect volumes that have not been shutdown cleanly but did + * not have any pending, non-check-pointed i/o, i.e. they were completely idle + * at least for the five seconds preceding the unclean shutdown. + * + * This function assumes that the $LogFile journal has already been consistency + * checked by a call to ntfs_check_logfile() and in particular if the $LogFile + * is empty this function requires that NVolLogFileEmpty() is true otherwise an + * empty volume will be reported as dirty. + */ +BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp) +{ + RESTART_AREA *ra; + + ntfs_log_trace("Entering.\n"); + /* An empty $LogFile must have been clean before it got emptied. */ + if (NVolLogFileEmpty(log_na->ni->vol)) { + ntfs_log_trace("$LogFile is empty\n"); + return TRUE; + } + if (!rp) { + ntfs_log_error("Restart page header is NULL\n"); + return FALSE; + } + if (!ntfs_is_rstr_record(rp->magic) && + !ntfs_is_chkd_record(rp->magic)) { + ntfs_log_error("Restart page buffer is invalid\n"); + return FALSE; + } + + ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); + /* + * If the $LogFile has active clients, i.e. it is open, and we do not + * have the RESTART_VOLUME_IS_CLEAN bit set in the restart area flags, + * we assume there was an unclean shutdown. + */ + if (ra->client_in_use_list != LOGFILE_NO_CLIENT && + !(ra->flags & RESTART_VOLUME_IS_CLEAN)) { + ntfs_log_error("The disk contains an unclean file system (%d, " + "%d).\n", le16_to_cpu(ra->client_in_use_list), + le16_to_cpu(ra->flags)); + return FALSE; + } + /* $LogFile indicates a clean shutdown. */ + ntfs_log_trace("$LogFile indicates a clean shutdown\n"); + return TRUE; +} + +/** + * ntfs_empty_logfile - empty the contents of the $LogFile journal + * @na: ntfs attribute of journal $LogFile to empty + * + * Empty the contents of the $LogFile journal @na and return 0 on success and + * -1 on error. + * + * This function assumes that the $LogFile journal has already been consistency + * checked by a call to ntfs_check_logfile() and that ntfs_is_logfile_clean() + * has been used to ensure that the $LogFile is clean. + */ +int ntfs_empty_logfile(ntfs_attr *na) +{ + s64 pos, count; + char buf[NTFS_BUF_SIZE]; + + ntfs_log_trace("Entering.\n"); + + if (NVolLogFileEmpty(na->ni->vol)) + return 0; + + if (!NAttrNonResident(na)) { + errno = EIO; + ntfs_log_perror("Resident $LogFile $DATA attribute"); + return -1; + } + + memset(buf, -1, NTFS_BUF_SIZE); + + pos = 0; + while ((count = na->data_size - pos) > 0) { + + if (count > NTFS_BUF_SIZE) + count = NTFS_BUF_SIZE; + + count = ntfs_attr_pwrite(na, pos, count, buf); + if (count <= 0) { + ntfs_log_perror("Failed to reset $LogFile"); + if (count != -1) + errno = EIO; + return -1; + } + pos += count; + } + + NVolSetLogFileEmpty(na->ni->vol); + + return 0; +} diff --git a/libcustomntfs/logfile.h b/libcustomntfs/logfile.h new file mode 100644 index 00000000..798d562d --- /dev/null +++ b/libcustomntfs/logfile.h @@ -0,0 +1,394 @@ +/* + * logfile.h - Exports for $LogFile handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2005 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_LOGFILE_H +#define _NTFS_LOGFILE_H + +#include "types.h" +#include "endians.h" +#include "layout.h" + +/* + * Journal ($LogFile) organization: + * + * Two restart areas present in the first two pages (restart pages, one restart + * area in each page). When the volume is dismounted they should be identical, + * except for the update sequence array which usually has a different update + * sequence number. + * + * These are followed by log records organized in pages headed by a log record + * header going up to log file size. Not all pages contain log records when a + * volume is first formatted, but as the volume ages, all records will be used. + * When the log file fills up, the records at the beginning are purged (by + * modifying the oldest_lsn to a higher value presumably) and writing begins + * at the beginning of the file. Effectively, the log file is viewed as a + * circular entity. + * + * NOTE: Windows NT, 2000, and XP all use log file version 1.1 but they accept + * versions <= 1.x, including 0.-1. (Yes, that is a minus one in there!) We + * probably only want to support 1.1 as this seems to be the current version + * and we don't know how that differs from the older versions. The only + * exception is if the journal is clean as marked by the two restart pages + * then it doesn't matter whether we are on an earlier version. We can just + * reinitialize the logfile and start again with version 1.1. + */ + +/* Some $LogFile related constants. */ +#define MaxLogFileSize 0x100000000ULL +#define DefaultLogPageSize 4096 +#define MinLogRecordPages 48 + +/** + * struct RESTART_PAGE_HEADER - Log file restart page header. + * + * Begins the restart area. + */ +typedef struct { +/*Ofs*/ +/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ +/* 0*/ NTFS_RECORD_TYPES magic;/* The magic is "RSTR". */ +/* 4*/ le16 usa_ofs; /* See NTFS_RECORD definition in layout.h. + When creating, set this to be immediately + after this header structure (without any + alignment). */ +/* 6*/ le16 usa_count; /* See NTFS_RECORD definition in layout.h. */ + +/* 8*/ leLSN chkdsk_lsn; /* The last log file sequence number found by + chkdsk. Only used when the magic is changed + to "CHKD". Otherwise this is zero. */ +/* 16*/ le32 system_page_size; /* Byte size of system pages when the log file + was created, has to be >= 512 and a power of + 2. Use this to calculate the required size + of the usa (usa_count) and add it to usa_ofs. + Then verify that the result is less than the + value of the restart_area_offset. */ +/* 20*/ le32 log_page_size; /* Byte size of log file pages, has to be >= + 512 and a power of 2. The default is 4096 + and is used when the system page size is + between 4096 and 8192. Otherwise this is + set to the system page size instead. */ +/* 24*/ le16 restart_area_offset;/* Byte offset from the start of this header to + the RESTART_AREA. Value has to be aligned + to 8-byte boundary. When creating, set this + to be after the usa. */ +/* 26*/ sle16 minor_ver; /* Log file minor version. Only check if major + version is 1. */ +/* 28*/ sle16 major_ver; /* Log file major version. We only support + version 1.1. */ +/* sizeof() = 30 (0x1e) bytes */ +} __attribute__((__packed__)) RESTART_PAGE_HEADER; + +/* + * Constant for the log client indices meaning that there are no client records + * in this particular client array. Also inside the client records themselves, + * this means that there are no client records preceding or following this one. + */ +#define LOGFILE_NO_CLIENT const_cpu_to_le16(0xffff) +#define LOGFILE_NO_CLIENT_CPU 0xffff + +/* + * These are the so far known RESTART_AREA_* flags (16-bit) which contain + * information about the log file in which they are present. + */ +enum { + RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002), + RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */ +} __attribute__((__packed__)); + +typedef le16 RESTART_AREA_FLAGS; + +/** + * struct RESTART_AREA - Log file restart area record. + * + * The offset of this record is found by adding the offset of the + * RESTART_PAGE_HEADER to the restart_area_offset value found in it. + * See notes at restart_area_offset above. + */ +typedef struct { +/*Ofs*/ +/* 0*/ leLSN current_lsn; /* The current, i.e. last LSN inside the log + when the restart area was last written. + This happens often but what is the interval? + Is it just fixed time or is it every time a + check point is written or something else? + On create set to 0. */ +/* 8*/ le16 log_clients; /* Number of log client records in the array of + log client records which follows this + restart area. Must be 1. */ +/* 10*/ le16 client_free_list; /* The index of the first free log client record + in the array of log client records. + LOGFILE_NO_CLIENT means that there are no + free log client records in the array. + If != LOGFILE_NO_CLIENT, check that + log_clients > client_free_list. On Win2k + and presumably earlier, on a clean volume + this is != LOGFILE_NO_CLIENT, and it should + be 0, i.e. the first (and only) client + record is free and thus the logfile is + closed and hence clean. A dirty volume + would have left the logfile open and hence + this would be LOGFILE_NO_CLIENT. On WinXP + and presumably later, the logfile is always + open, even on clean shutdown so this should + always be LOGFILE_NO_CLIENT. */ +/* 12*/ le16 client_in_use_list;/* The index of the first in-use log client + record in the array of log client records. + LOGFILE_NO_CLIENT means that there are no + in-use log client records in the array. If + != LOGFILE_NO_CLIENT check that log_clients + > client_in_use_list. On Win2k and + presumably earlier, on a clean volume this + is LOGFILE_NO_CLIENT, i.e. there are no + client records in use and thus the logfile + is closed and hence clean. A dirty volume + would have left the logfile open and hence + this would be != LOGFILE_NO_CLIENT, and it + should be 0, i.e. the first (and only) + client record is in use. On WinXP and + presumably later, the logfile is always + open, even on clean shutdown so this should + always be 0. */ +/* 14*/ RESTART_AREA_FLAGS flags;/* Flags modifying LFS behaviour. On Win2k + and presumably earlier this is always 0. On + WinXP and presumably later, if the logfile + was shutdown cleanly, the second bit, + RESTART_VOLUME_IS_CLEAN, is set. This bit + is cleared when the volume is mounted by + WinXP and set when the volume is dismounted, + thus if the logfile is dirty, this bit is + clear. Thus we don't need to check the + Windows version to determine if the logfile + is clean. Instead if the logfile is closed, + we know it must be clean. If it is open and + this bit is set, we also know it must be + clean. If on the other hand the logfile is + open and this bit is clear, we can be almost + certain that the logfile is dirty. */ +/* 16*/ le32 seq_number_bits; /* How many bits to use for the sequence + number. This is calculated as 67 - the + number of bits required to store the logfile + size in bytes and this can be used in with + the specified file_size as a consistency + check. */ +/* 20*/ le16 restart_area_length;/* Length of the restart area including the + client array. Following checks required if + version matches. Otherwise, skip them. + restart_area_offset + restart_area_length + has to be <= system_page_size. Also, + restart_area_length has to be >= + client_array_offset + (log_clients * + sizeof(log client record)). */ +/* 22*/ le16 client_array_offset;/* Offset from the start of this record to + the first log client record if versions are + matched. When creating, set this to be + after this restart area structure, aligned + to 8-bytes boundary. If the versions do not + match, this is ignored and the offset is + assumed to be (sizeof(RESTART_AREA) + 7) & + ~7, i.e. rounded up to first 8-byte + boundary. Either way, client_array_offset + has to be aligned to an 8-byte boundary. + Also, restart_area_offset + + client_array_offset has to be <= 510. + Finally, client_array_offset + (log_clients + * sizeof(log client record)) has to be <= + system_page_size. On Win2k and presumably + earlier, this is 0x30, i.e. immediately + following this record. On WinXP and + presumably later, this is 0x40, i.e. there + are 16 extra bytes between this record and + the client array. This probably means that + the RESTART_AREA record is actually bigger + in WinXP and later. */ +/* 24*/ sle64 file_size; /* Usable byte size of the log file. If the + restart_area_offset + the offset of the + file_size are > 510 then corruption has + occurred. This is the very first check when + starting with the restart_area as if it + fails it means that some of the above values + will be corrupted by the multi sector + transfer protection. The file_size has to + be rounded down to be a multiple of the + log_page_size in the RESTART_PAGE_HEADER and + then it has to be at least big enough to + store the two restart pages and 48 (0x30) + log record pages. */ +/* 32*/ le32 last_lsn_data_length;/* Length of data of last LSN, not including + the log record header. On create set to + 0. */ +/* 36*/ le16 log_record_header_length;/* Byte size of the log record header. + If the version matches then check that the + value of log_record_header_length is a + multiple of 8, i.e. + (log_record_header_length + 7) & ~7 == + log_record_header_length. When creating set + it to sizeof(LOG_RECORD_HEADER), aligned to + 8 bytes. */ +/* 38*/ le16 log_page_data_offset;/* Offset to the start of data in a log record + page. Must be a multiple of 8. On create + set it to immediately after the update + sequence array of the log record page. */ +/* 40*/ le32 restart_log_open_count;/* A counter that gets incremented every + time the logfile is restarted which happens + at mount time when the logfile is opened. + When creating set to a random value. Win2k + sets it to the low 32 bits of the current + system time in NTFS format (see time.h). */ +/* 44*/ le32 reserved; /* Reserved/alignment to 8-byte boundary. */ +/* sizeof() = 48 (0x30) bytes */ +} __attribute__((__packed__)) RESTART_AREA; + +/** + * struct LOG_CLIENT_RECORD - Log client record. + * + * The offset of this record is found by adding the offset of the + * RESTART_AREA to the client_array_offset value found in it. + */ +typedef struct { +/*Ofs*/ +/* 0*/ leLSN oldest_lsn; /* Oldest LSN needed by this client. On create + set to 0. */ +/* 8*/ leLSN client_restart_lsn;/* LSN at which this client needs to restart + the volume, i.e. the current position within + the log file. At present, if clean this + should = current_lsn in restart area but it + probably also = current_lsn when dirty most + of the time. At create set to 0. */ +/* 16*/ le16 prev_client; /* The offset to the previous log client record + in the array of log client records. + LOGFILE_NO_CLIENT means there is no previous + client record, i.e. this is the first one. + This is always LOGFILE_NO_CLIENT. */ +/* 18*/ le16 next_client; /* The offset to the next log client record in + the array of log client records. + LOGFILE_NO_CLIENT means there are no next + client records, i.e. this is the last one. + This is always LOGFILE_NO_CLIENT. */ +/* 20*/ le16 seq_number; /* On Win2k and presumably earlier, this is set + to zero every time the logfile is restarted + and it is incremented when the logfile is + closed at dismount time. Thus it is 0 when + dirty and 1 when clean. On WinXP and + presumably later, this is always 0. */ +/* 22*/ u8 reserved[6]; /* Reserved/alignment. */ +/* 28*/ le32 client_name_length;/* Length of client name in bytes. Should + always be 8. */ +/* 32*/ ntfschar client_name[64];/* Name of the client in Unicode. Should + always be "NTFS" with the remaining bytes + set to 0. */ +/* sizeof() = 160 (0xa0) bytes */ +} __attribute__((__packed__)) LOG_CLIENT_RECORD; + +/** + * struct RECORD_PAGE_HEADER - Log page record page header. + * + * Each log page begins with this header and is followed by several LOG_RECORD + * structures, starting at offset 0x40 (the size of this structure and the + * following update sequence array and then aligned to 8 byte boundary, but is + * this specified anywhere?). + */ +typedef struct { +/* 0 NTFS_RECORD; -- Unfolded here as gcc doesn't like unnamed structs. */ + NTFS_RECORD_TYPES magic;/* Usually the magic is "RCRD". */ + u16 usa_ofs; /* See NTFS_RECORD definition in layout.h. + When creating, set this to be immediately + after this header structure (without any + alignment). */ + u16 usa_count; /* See NTFS_RECORD definition in layout.h. */ + + union { + LSN last_lsn; + s64 file_offset; + } __attribute__((__packed__)) copy; + u32 flags; + u16 page_count; + u16 page_position; + union { + struct { + u16 next_record_offset; + u8 reserved[6]; + LSN last_end_lsn; + } __attribute__((__packed__)) packed; + } __attribute__((__packed__)) header; +} __attribute__((__packed__)) RECORD_PAGE_HEADER; + +/** + * enum LOG_RECORD_FLAGS - Possible 16-bit flags for log records. + * + * (Or is it log record pages?) + */ +typedef enum { + LOG_RECORD_MULTI_PAGE = const_cpu_to_le16(0x0001), /* ??? */ + LOG_RECORD_SIZE_PLACE_HOLDER = 0xffff, + /* This has nothing to do with the log record. It is only so + gcc knows to make the flags 16-bit. */ +} __attribute__((__packed__)) LOG_RECORD_FLAGS; + +/** + * struct LOG_CLIENT_ID - The log client id structure identifying a log client. + */ +typedef struct { + u16 seq_number; + u16 client_index; +} __attribute__((__packed__)) LOG_CLIENT_ID; + +/** + * struct LOG_RECORD - Log record header. + * + * Each log record seems to have a constant size of 0x70 bytes. + */ +typedef struct { + LSN this_lsn; + LSN client_previous_lsn; + LSN client_undo_next_lsn; + u32 client_data_length; + LOG_CLIENT_ID client_id; + u32 record_type; + u32 transaction_id; + u16 flags; + u16 reserved_or_alignment[3]; +/* Now are at ofs 0x30 into struct. */ + u16 redo_operation; + u16 undo_operation; + u16 redo_offset; + u16 redo_length; + u16 undo_offset; + u16 undo_length; + u16 target_attribute; + u16 lcns_to_follow; /* Number of lcn_list entries + following this entry. */ +/* Now at ofs 0x40. */ + u16 record_offset; + u16 attribute_offset; + u32 alignment_or_reserved; + VCN target_vcn; +/* Now at ofs 0x50. */ + struct { /* Only present if lcns_to_follow + is not 0. */ + LCN lcn; + } __attribute__((__packed__)) lcn_list[0]; +} __attribute__((__packed__)) LOG_RECORD; + +extern BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp); +extern BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp); +extern int ntfs_empty_logfile(ntfs_attr *na); + +#endif /* defined _NTFS_LOGFILE_H */ diff --git a/libcustomntfs/logging.c b/libcustomntfs/logging.c new file mode 100644 index 00000000..385bcaa6 --- /dev/null +++ b/libcustomntfs/logging.c @@ -0,0 +1,613 @@ +/** + * logging.c - Centralised logging. Originated from the Linux-NTFS project. + * + * Copyright (c) 2005 Richard Russon + * Copyright (c) 2005-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDARG_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_SYSLOG_H +#include +#endif + +#include "logging.h" +#include "misc.h" + +#ifndef PATH_SEP +#define PATH_SEP '/' +#endif + +#ifdef DEBUG +static int tab; +#endif + +/* Some gcc 3.x, 4.[01].X crash with internal compiler error. */ +#if __GNUC__ <= 3 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 1) +# define BROKEN_GCC_FORMAT_ATTRIBUTE +#else +# define BROKEN_GCC_FORMAT_ATTRIBUTE __attribute__((format(printf, 6, 0))) +#endif + +/** + * struct ntfs_logging - Control info for the logging system + * @levels: Bitfield of logging levels + * @flags: Flags which affect the output style + * @handler: Function to perform the actual logging + */ +struct ntfs_logging { + u32 levels; + u32 flags; + ntfs_log_handler *handler BROKEN_GCC_FORMAT_ATTRIBUTE; +}; + +/** + * ntfs_log + * This struct controls all the logging within the library and tools. + */ +static struct ntfs_logging ntfs_log = { +#ifdef DEBUG + NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE | NTFS_LOG_LEVEL_ENTER | + NTFS_LOG_LEVEL_LEAVE | +#endif + NTFS_LOG_LEVEL_INFO | NTFS_LOG_LEVEL_QUIET | NTFS_LOG_LEVEL_WARNING | + NTFS_LOG_LEVEL_ERROR | NTFS_LOG_LEVEL_PERROR | NTFS_LOG_LEVEL_CRITICAL | + NTFS_LOG_LEVEL_PROGRESS, + NTFS_LOG_FLAG_ONLYNAME, +#ifdef DEBUG + ntfs_log_handler_outerr +#else + ntfs_log_handler_null +#endif +}; + + +/** + * ntfs_log_get_levels - Get a list of the current logging levels + * + * Find out which logging levels are enabled. + * + * Returns: Log levels in a 32-bit field + */ +u32 ntfs_log_get_levels(void) +{ + return ntfs_log.levels; +} + +/** + * ntfs_log_set_levels - Enable extra logging levels + * @levels: 32-bit field of log levels to set + * + * Enable one or more logging levels. + * The logging levels are named: NTFS_LOG_LEVEL_*. + * + * Returns: Log levels that were enabled before the call + */ +u32 ntfs_log_set_levels(u32 levels) +{ + u32 old; + old = ntfs_log.levels; + ntfs_log.levels |= levels; + return old; +} + +/** + * ntfs_log_clear_levels - Disable some logging levels + * @levels: 32-bit field of log levels to clear + * + * Disable one or more logging levels. + * The logging levels are named: NTFS_LOG_LEVEL_*. + * + * Returns: Log levels that were enabled before the call + */ +u32 ntfs_log_clear_levels(u32 levels) +{ + u32 old; + old = ntfs_log.levels; + ntfs_log.levels &= (~levels); + return old; +} + + +/** + * ntfs_log_get_flags - Get a list of logging style flags + * + * Find out which logging flags are enabled. + * + * Returns: Logging flags in a 32-bit field + */ +u32 ntfs_log_get_flags(void) +{ + return ntfs_log.flags; +} + +/** + * ntfs_log_set_flags - Enable extra logging style flags + * @flags: 32-bit field of logging flags to set + * + * Enable one or more logging flags. + * The log flags are named: NTFS_LOG_LEVEL_*. + * + * Returns: Logging flags that were enabled before the call + */ +u32 ntfs_log_set_flags(u32 flags) +{ + u32 old; + old = ntfs_log.flags; + ntfs_log.flags |= flags; + return old; +} + +/** + * ntfs_log_clear_flags - Disable some logging styles + * @flags: 32-bit field of logging flags to clear + * + * Disable one or more logging flags. + * The log flags are named: NTFS_LOG_LEVEL_*. + * + * Returns: Logging flags that were enabled before the call + */ +u32 ntfs_log_clear_flags(u32 flags) +{ + u32 old; + old = ntfs_log.flags; + ntfs_log.flags &= (~flags); + return old; +} + + +/** + * ntfs_log_get_stream - Default output streams for logging levels + * @level: Log level + * + * By default, urgent messages are sent to "stderr". + * Other messages are sent to "stdout". + * + * Returns: "string" Prefix to be used + */ +static FILE * ntfs_log_get_stream(u32 level) +{ + FILE *stream; + + switch (level) { + case NTFS_LOG_LEVEL_INFO: + case NTFS_LOG_LEVEL_QUIET: + case NTFS_LOG_LEVEL_PROGRESS: + case NTFS_LOG_LEVEL_VERBOSE: + stream = stdout; + break; + + case NTFS_LOG_LEVEL_DEBUG: + case NTFS_LOG_LEVEL_TRACE: + case NTFS_LOG_LEVEL_ENTER: + case NTFS_LOG_LEVEL_LEAVE: + case NTFS_LOG_LEVEL_WARNING: + case NTFS_LOG_LEVEL_ERROR: + case NTFS_LOG_LEVEL_CRITICAL: + case NTFS_LOG_LEVEL_PERROR: + default: + stream = stderr; + break; + } + + return stream; +} + +/** + * ntfs_log_get_prefix - Default prefixes for logging levels + * @level: Log level to be prefixed + * + * Prefixing the logging output can make it easier to parse. + * + * Returns: "string" Prefix to be used + */ +static const char * ntfs_log_get_prefix(u32 level) +{ + const char *prefix; + + switch (level) { + case NTFS_LOG_LEVEL_DEBUG: + prefix = "DEBUG: "; + break; + case NTFS_LOG_LEVEL_TRACE: + prefix = "TRACE: "; + break; + case NTFS_LOG_LEVEL_QUIET: + prefix = "QUIET: "; + break; + case NTFS_LOG_LEVEL_INFO: + prefix = "INFO: "; + break; + case NTFS_LOG_LEVEL_VERBOSE: + prefix = "VERBOSE: "; + break; + case NTFS_LOG_LEVEL_PROGRESS: + prefix = "PROGRESS: "; + break; + case NTFS_LOG_LEVEL_WARNING: + prefix = "WARNING: "; + break; + case NTFS_LOG_LEVEL_ERROR: + prefix = "ERROR: "; + break; + case NTFS_LOG_LEVEL_PERROR: + prefix = "ERROR: "; + break; + case NTFS_LOG_LEVEL_CRITICAL: + prefix = "CRITICAL: "; + break; + default: + prefix = ""; + break; + } + + return prefix; +} + + +/** + * ntfs_log_set_handler - Provide an alternate logging handler + * @handler: function to perform the logging + * + * This alternate handler will be called for all future logging requests. + * If no @handler is specified, logging will revert to the default handler. + */ +void ntfs_log_set_handler(ntfs_log_handler *handler) +{ + if (handler) { + ntfs_log.handler = handler; +#ifdef HAVE_SYSLOG_H + if (handler == ntfs_log_handler_syslog) + openlog("ntfs-3g", LOG_PID, LOG_USER); +#endif + } else + ntfs_log.handler = ntfs_log_handler_null; +} + +/** + * ntfs_log_redirect - Pass on the request to the real handler + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @...: Arguments to be formatted + * + * This is just a redirector function. The arguments are simply passed to the + * main logging handler (as defined in the global logging struct @ntfs_log). + * + * Returns: -1 Error occurred + * 0 Message wasn't logged + * num Number of output characters + */ +int ntfs_log_redirect(const char *function, const char *file, + int line, u32 level, void *data, const char *format, ...) +{ + int olderr = errno; + int ret; + va_list args; + + if (!(ntfs_log.levels & level)) /* Don't log this message */ + return 0; + + va_start(args, format); + errno = olderr; + ret = ntfs_log.handler(function, file, line, level, data, format, args); + va_end(args); + + errno = olderr; + return ret; +} + + +/** + * ntfs_log_handler_syslog - syslog logging handler + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @args: Arguments to be formatted + * + * A simple syslog logging handler. Ignores colors. + * + * Returns: -1 Error occurred + * 0 Message wasn't logged + * num Number of output characters + */ + + +#ifdef HAVE_SYSLOG_H + +#define LOG_LINE_LEN 512 + +int ntfs_log_handler_syslog(const char *function __attribute__((unused)), + const char *file __attribute__((unused)), + int line __attribute__((unused)), u32 level, + void *data __attribute__((unused)), + const char *format, va_list args) +{ + char logbuf[LOG_LINE_LEN]; + int ret, olderr = errno; + +#ifndef DEBUG + if ((level & NTFS_LOG_LEVEL_PERROR) && errno == ENOSPC) + return 1; +#endif + ret = vsnprintf(logbuf, LOG_LINE_LEN, format, args); + if (ret < 0) { + vsyslog(LOG_NOTICE, format, args); + ret = 1; + goto out; + } + + if ((LOG_LINE_LEN > ret + 3) && (level & NTFS_LOG_LEVEL_PERROR)) { + strncat(logbuf, ": ", LOG_LINE_LEN - ret - 1); + strncat(logbuf, strerror(olderr), LOG_LINE_LEN - (ret + 3)); + ret = strlen(logbuf); + } + + syslog(LOG_NOTICE, "%s", logbuf); +out: + errno = olderr; + return ret; +} +#endif + +/** + * ntfs_log_handler_fprintf - Basic logging handler + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @args: Arguments to be formatted + * + * A simple logging handler. This is where the log line is finally displayed. + * It is more likely that you will want to set the handler to either + * ntfs_log_handler_outerr or ntfs_log_handler_stderr. + * + * Note: For this handler, @data is a pointer to a FILE output stream. + * If @data is NULL, nothing will be displayed. + * + * Returns: -1 Error occurred + * 0 Message wasn't logged + * num Number of output characters + */ +int ntfs_log_handler_fprintf(const char *function, const char *file, + int line, u32 level, void *data, const char *format, va_list args) +{ +#ifdef DEBUG + int i; +#endif + int ret = 0; + int olderr = errno; + FILE *stream; + + if (!data) /* Interpret data as a FILE stream. */ + return 0; /* If it's NULL, we can't do anything. */ + stream = (FILE*)data; + +#ifdef DEBUG + if (level == NTFS_LOG_LEVEL_LEAVE) { + if (tab) + tab--; + return 0; + } + + for (i = 0; i < tab; i++) + ret += fprintf(stream, " "); +#endif + if ((ntfs_log.flags & NTFS_LOG_FLAG_ONLYNAME) && + (strchr(file, PATH_SEP))) /* Abbreviate the filename */ + file = strrchr(file, PATH_SEP) + 1; + + if (ntfs_log.flags & NTFS_LOG_FLAG_PREFIX) /* Prefix the output */ + ret += fprintf(stream, "%s", ntfs_log_get_prefix(level)); + + if (ntfs_log.flags & NTFS_LOG_FLAG_FILENAME) /* Source filename */ + ret += fprintf(stream, "%s ", file); + + if (ntfs_log.flags & NTFS_LOG_FLAG_LINE) /* Source line number */ + ret += fprintf(stream, "(%d) ", line); + + if ((ntfs_log.flags & NTFS_LOG_FLAG_FUNCTION) || /* Source function */ + (level & NTFS_LOG_LEVEL_TRACE) || (level & NTFS_LOG_LEVEL_ENTER)) + ret += fprintf(stream, "%s(): ", function); + + ret += vfprintf(stream, format, args); + + if (level & NTFS_LOG_LEVEL_PERROR) + ret += fprintf(stream, ": %s\n", strerror(olderr)); + +#ifdef DEBUG + if (level == NTFS_LOG_LEVEL_ENTER) + tab++; +#endif + fflush(stream); + errno = olderr; + return ret; +} + +/** + * ntfs_log_handler_null - Null logging handler (no output) + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @args: Arguments to be formatted + * + * This handler produces no output. It provides a way to temporarily disable + * logging, without having to change the levels and flags. + * + * Returns: 0 Message wasn't logged + */ +int ntfs_log_handler_null(const char *function __attribute__((unused)), const char *file __attribute__((unused)), + int line __attribute__((unused)), u32 level __attribute__((unused)), void *data __attribute__((unused)), + const char *format __attribute__((unused)), va_list args __attribute__((unused))) +{ + return 0; +} + +/** + * ntfs_log_handler_stdout - All logs go to stdout + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @args: Arguments to be formatted + * + * Display a log message to stdout. + * + * Note: For this handler, @data is a pointer to a FILE output stream. + * If @data is NULL, then stdout will be used. + * + * Note: This function calls ntfs_log_handler_fprintf to do the main work. + * + * Returns: -1 Error occurred + * 0 Message wasn't logged + * num Number of output characters + */ +int ntfs_log_handler_stdout(const char *function, const char *file, + int line, u32 level, void *data, const char *format, va_list args) +{ + if (!data) + data = stdout; + + return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); +} + +/** + * ntfs_log_handler_outerr - Logs go to stdout/stderr depending on level + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @args: Arguments to be formatted + * + * Display a log message. The output stream will be determined by the log + * level. + * + * Note: For this handler, @data is a pointer to a FILE output stream. + * If @data is NULL, the function ntfs_log_get_stream will be called + * + * Note: This function calls ntfs_log_handler_fprintf to do the main work. + * + * Returns: -1 Error occurred + * 0 Message wasn't logged + * num Number of output characters + */ +int ntfs_log_handler_outerr(const char *function, const char *file, + int line, u32 level, void *data, const char *format, va_list args) +{ + if (!data) + data = ntfs_log_get_stream(level); + + return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); +} + +/** + * ntfs_log_handler_stderr - All logs go to stderr + * @function: Function in which the log line occurred + * @file: File in which the log line occurred + * @line: Line number on which the log line occurred + * @level: Level at which the line is logged + * @data: User specified data, possibly specific to a handler + * @format: printf-style formatting string + * @args: Arguments to be formatted + * + * Display a log message to stderr. + * + * Note: For this handler, @data is a pointer to a FILE output stream. + * If @data is NULL, then stdout will be used. + * + * Note: This function calls ntfs_log_handler_fprintf to do the main work. + * + * Returns: -1 Error occurred + * 0 Message wasn't logged + * num Number of output characters + */ +int ntfs_log_handler_stderr(const char *function, const char *file, + int line, u32 level, void *data, const char *format, va_list args) +{ + if (!data) + data = stderr; + + return ntfs_log_handler_fprintf(function, file, line, level, data, format, args); +} + + +/** + * ntfs_log_parse_option - Act upon command line options + * @option: Option flag + * + * Delegate some of the work of parsing the command line. All the options begin + * with "--log-". Options cause log levels to be enabled in @ntfs_log (the + * global logging structure). + * + * Note: The "colour" option changes the logging handler. + * + * Returns: TRUE Option understood + * FALSE Invalid log option + */ +BOOL ntfs_log_parse_option(const char *option) +{ + if (strcmp(option, "--log-debug") == 0) { + ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG); + return TRUE; + } else if (strcmp(option, "--log-verbose") == 0) { + ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE); + return TRUE; + } else if (strcmp(option, "--log-quiet") == 0) { + ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET); + return TRUE; + } else if (strcmp(option, "--log-trace") == 0) { + ntfs_log_set_levels(NTFS_LOG_LEVEL_TRACE); + return TRUE; + } + + ntfs_log_debug("Unknown logging option '%s'\n", option); + return FALSE; +} + diff --git a/libcustomntfs/logging.h b/libcustomntfs/logging.h new file mode 100644 index 00000000..401f5c97 --- /dev/null +++ b/libcustomntfs/logging.h @@ -0,0 +1,118 @@ +/* + * logging.h - Centralised logging. Originated from the Linux-NTFS project. + * + * Copyright (c) 2005 Richard Russon + * Copyright (c) 2007-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _LOGGING_H_ +#define _LOGGING_H_ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDARG_H +#include +#endif + +#include "types.h" + +/* Function prototype for the logging handlers */ +typedef int (ntfs_log_handler)(const char *function, const char *file, int line, + u32 level, void *data, const char *format, va_list args); + +/* Set the logging handler from one of the functions, below. */ +void ntfs_log_set_handler(ntfs_log_handler *handler + __attribute__((format(printf, 6, 0)))); + +/* Logging handlers */ +ntfs_log_handler ntfs_log_handler_syslog __attribute__((format(printf, 6, 0))); +ntfs_log_handler ntfs_log_handler_fprintf __attribute__((format(printf, 6, 0))); +ntfs_log_handler ntfs_log_handler_null __attribute__((format(printf, 6, 0))); +ntfs_log_handler ntfs_log_handler_stdout __attribute__((format(printf, 6, 0))); +ntfs_log_handler ntfs_log_handler_outerr __attribute__((format(printf, 6, 0))); +ntfs_log_handler ntfs_log_handler_stderr __attribute__((format(printf, 6, 0))); + +/* Enable/disable certain log levels */ +u32 ntfs_log_set_levels(u32 levels); +u32 ntfs_log_clear_levels(u32 levels); +u32 ntfs_log_get_levels(void); + +/* Enable/disable certain log flags */ +u32 ntfs_log_set_flags(u32 flags); +u32 ntfs_log_clear_flags(u32 flags); +u32 ntfs_log_get_flags(void); + +/* Turn command-line options into logging flags */ +BOOL ntfs_log_parse_option(const char *option); + +int ntfs_log_redirect(const char *function, const char *file, int line, + u32 level, void *data, const char *format, ...) + __attribute__((format(printf, 6, 7))); + +/* Logging levels - Determine what gets logged */ +#define NTFS_LOG_LEVEL_DEBUG (1 << 0) /* x = 42 */ +#define NTFS_LOG_LEVEL_TRACE (1 << 1) /* Entering function x() */ +#define NTFS_LOG_LEVEL_QUIET (1 << 2) /* Quietable output */ +#define NTFS_LOG_LEVEL_INFO (1 << 3) /* Volume needs defragmenting */ +#define NTFS_LOG_LEVEL_VERBOSE (1 << 4) /* Forced to continue */ +#define NTFS_LOG_LEVEL_PROGRESS (1 << 5) /* 54% complete */ +#define NTFS_LOG_LEVEL_WARNING (1 << 6) /* You should backup before starting */ +#define NTFS_LOG_LEVEL_ERROR (1 << 7) /* Operation failed, no damage done */ +#define NTFS_LOG_LEVEL_PERROR (1 << 8) /* Message : standard error description */ +#define NTFS_LOG_LEVEL_CRITICAL (1 << 9) /* Operation failed,damage may have occurred */ +#define NTFS_LOG_LEVEL_ENTER (1 << 10) /* Enter a function */ +#define NTFS_LOG_LEVEL_LEAVE (1 << 11) /* Leave a function */ + +/* Logging style flags - Manage the style of the output */ +#define NTFS_LOG_FLAG_PREFIX (1 << 0) /* Prefix messages with "ERROR: ", etc */ +#define NTFS_LOG_FLAG_FILENAME (1 << 1) /* Show the file origin of the message */ +#define NTFS_LOG_FLAG_LINE (1 << 2) /* Show the line number of the message */ +#define NTFS_LOG_FLAG_FUNCTION (1 << 3) /* Show the function name containing the message */ +#define NTFS_LOG_FLAG_ONLYNAME (1 << 4) /* Only display the filename, not the pathname */ + +/* Macros to simplify logging. One for each level defined above. + * Note, ntfs_log_debug/trace have effect only if DEBUG is defined. + */ +#define ntfs_log_critical(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_CRITICAL,NULL,FORMAT,##ARGS) +#define ntfs_log_error(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ERROR,NULL,FORMAT,##ARGS) +#define ntfs_log_info(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_INFO,NULL,FORMAT,##ARGS) +#define ntfs_log_perror(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PERROR,NULL,FORMAT,##ARGS) +#define ntfs_log_progress(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_PROGRESS,NULL,FORMAT,##ARGS) +#define ntfs_log_quiet(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_QUIET,NULL,FORMAT,##ARGS) +#define ntfs_log_verbose(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_VERBOSE,NULL,FORMAT,##ARGS) +#define ntfs_log_warning(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_WARNING,NULL,FORMAT,##ARGS) + +/* By default debug and trace messages are compiled into the program, + * but not displayed. + */ +#ifdef DEBUG +#define ntfs_log_debug(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_DEBUG,NULL,FORMAT,##ARGS) +#define ntfs_log_trace(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_TRACE,NULL,FORMAT,##ARGS) +#define ntfs_log_enter(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_ENTER,NULL,FORMAT,##ARGS) +#define ntfs_log_leave(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_LEAVE,NULL,FORMAT,##ARGS) +#else +#define ntfs_log_debug(FORMAT, ARGS...)do {} while (0) +#define ntfs_log_trace(FORMAT, ARGS...)do {} while (0) +#define ntfs_log_enter(FORMAT, ARGS...)do {} while (0) +#define ntfs_log_leave(FORMAT, ARGS...)do {} while (0) +#endif /* DEBUG */ + +#endif /* _LOGGING_H_ */ + diff --git a/libcustomntfs/mem2.h b/libcustomntfs/mem2.h new file mode 100644 index 00000000..b8fa93cf --- /dev/null +++ b/libcustomntfs/mem2.h @@ -0,0 +1,27 @@ +// 2 MEM2 allocators, one for general purpose, one for covers +// Aligned and padded to 32 bytes, as required by many functions + +#ifndef __MEM2_H_ +#define __MEM2_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +void MEM2_init(unsigned int mem2Size); +void MEM2_cleanup(void); +void MEM2_takeBigOnes(bool b); +void *MEM2_alloc(unsigned int s); +void *MEM2_realloc(void *p, unsigned int s); +void MEM2_free(void *p); +unsigned int MEM2_usableSize(void *p); +unsigned int MEM2_freesize(); + +#ifdef __cplusplus +} +#endif + +#endif // !defined(__MEM2_H_) diff --git a/libcustomntfs/mem_allocate.h b/libcustomntfs/mem_allocate.h new file mode 100644 index 00000000..f7c4ad2d --- /dev/null +++ b/libcustomntfs/mem_allocate.h @@ -0,0 +1,44 @@ +/** + * mem_allocate.h - Memory allocation and destruction calls. + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _MEM_ALLOCATE_H +#define _MEM_ALLOCATE_H + +#include +#include "mem2.h" + + +static inline void* ntfs_alloc (size_t size) +{ + return MEM2_alloc(size); +} + +static inline void* ntfs_align (size_t size) +{ + return MEM2_alloc(size); +} + +static inline void ntfs_free (void* mem) +{ + MEM2_free(mem); +} + +#endif /* _MEM_ALLOCATE_H */ diff --git a/libcustomntfs/mft.c b/libcustomntfs/mft.c new file mode 100644 index 00000000..e93c6646 --- /dev/null +++ b/libcustomntfs/mft.c @@ -0,0 +1,1909 @@ +/** + * mft.c - Mft record handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2004-2008 Szabolcs Szakacsits + * Copyright (c) 2005 Yura Pakhuchiy + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#include + +#include "compat.h" +#include "types.h" +#include "device.h" +#include "debug.h" +#include "bitmap.h" +#include "attrib.h" +#include "inode.h" +#include "volume.h" +#include "layout.h" +#include "lcnalloc.h" +#include "mft.h" +#include "logging.h" +#include "misc.h" + +/** + * ntfs_mft_records_read - read records from the mft from disk + * @vol: volume to read from + * @mref: starting mft record number to read + * @count: number of mft records to read + * @b: output data buffer + * + * Read @count mft records starting at @mref from volume @vol into buffer + * @b. Return 0 on success or -1 on error, with errno set to the error + * code. + * + * If any of the records exceed the initialized size of the $MFT/$DATA + * attribute, i.e. they cannot possibly be allocated mft records, assume this + * is a bug and return error code ESPIPE. + * + * The read mft records are mst deprotected and are hence ready to use. The + * caller should check each record with is_baad_record() in case mst + * deprotection failed. + * + * NOTE: @b has to be at least of size @count * vol->mft_record_size. + */ +int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, + const s64 count, MFT_RECORD *b) +{ + s64 br; + VCN m; + + ntfs_log_trace("inode %llu\n", (unsigned long long)MREF(mref)); + + if (!vol || !vol->mft_na || !b || count < 0) { + errno = EINVAL; + ntfs_log_perror("%s: b=%p count=%lld mft=%llu", __FUNCTION__, + b, (long long)count, (unsigned long long)MREF(mref)); + return -1; + } + m = MREF(mref); + /* Refuse to read non-allocated mft records. */ + if (m + count > vol->mft_na->initialized_size >> + vol->mft_record_size_bits) { + errno = ESPIPE; + ntfs_log_perror("Trying to read non-allocated mft records " + "(%lld > %lld)", (long long)m + count, + (long long)vol->mft_na->initialized_size >> + vol->mft_record_size_bits); + return -1; + } + br = ntfs_attr_mst_pread(vol->mft_na, m << vol->mft_record_size_bits, + count, vol->mft_record_size, b); + if (br != count) { + if (br != -1) + errno = EIO; + ntfs_log_perror("Failed to read of MFT, mft=%llu count=%lld " + "br=%lld", (long long)m, (long long)count, + (long long)br); + return -1; + } + return 0; +} + +/** + * ntfs_mft_records_write - write mft records to disk + * @vol: volume to write to + * @mref: starting mft record number to write + * @count: number of mft records to write + * @b: data buffer containing the mft records to write + * + * Write @count mft records starting at @mref from data buffer @b to volume + * @vol. Return 0 on success or -1 on error, with errno set to the error code. + * + * If any of the records exceed the initialized size of the $MFT/$DATA + * attribute, i.e. they cannot possibly be allocated mft records, assume this + * is a bug and return error code ESPIPE. + * + * Before the mft records are written, they are mst protected. After the write, + * they are deprotected again, thus resulting in an increase in the update + * sequence number inside the data buffer @b. + * + * If any mft records are written which are also represented in the mft mirror + * $MFTMirr, we make a copy of the relevant parts of the data buffer @b into a + * temporary buffer before we do the actual write. Then if at least one mft + * record was successfully written, we write the appropriate mft records from + * the copied buffer to the mft mirror, too. + */ +int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, + const s64 count, MFT_RECORD *b) +{ + s64 bw; + VCN m; + void *bmirr = NULL; + int cnt = 0, res = 0; + + if (!vol || !vol->mft_na || vol->mftmirr_size <= 0 || !b || count < 0) { + errno = EINVAL; + return -1; + } + m = MREF(mref); + /* Refuse to write non-allocated mft records. */ + if (m + count > vol->mft_na->initialized_size >> + vol->mft_record_size_bits) { + errno = ESPIPE; + ntfs_log_perror("Trying to write non-allocated mft records " + "(%lld > %lld)", (long long)m + count, + (long long)vol->mft_na->initialized_size >> + vol->mft_record_size_bits); + return -1; + } + if (m < vol->mftmirr_size) { + if (!vol->mftmirr_na) { + errno = EINVAL; + return -1; + } + cnt = vol->mftmirr_size - m; + if (cnt > count) + cnt = count; + bmirr = ntfs_malloc(cnt * vol->mft_record_size); + if (!bmirr) + return -1; + memcpy(bmirr, b, cnt * vol->mft_record_size); + } + bw = ntfs_attr_mst_pwrite(vol->mft_na, m << vol->mft_record_size_bits, + count, vol->mft_record_size, b); + if (bw != count) { + if (bw != -1) + errno = EIO; + if (bw >= 0) + ntfs_log_debug("Error: partial write while writing $Mft " + "record(s)!\n"); + else + ntfs_log_perror("Error writing $Mft record(s)"); + res = errno; + } + if (bmirr && bw > 0) { + if (bw < cnt) + cnt = bw; + bw = ntfs_attr_mst_pwrite(vol->mftmirr_na, + m << vol->mft_record_size_bits, cnt, + vol->mft_record_size, bmirr); + if (bw != cnt) { + if (bw != -1) + errno = EIO; + ntfs_log_debug("Error: failed to sync $MFTMirr! Run " + "chkdsk.\n"); + res = errno; + } + } + free(bmirr); + if (!res) + return res; + errno = res; + return -1; +} + +int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref, + MFT_RECORD *m) +{ + ATTR_RECORD *a; + int ret = -1; + + if (!ntfs_is_file_record(m->magic)) { + ntfs_log_error("Record %llu has no FILE magic (0x%x)\n", + (unsigned long long)MREF(mref), *(le32 *)m); + goto err_out; + } + + if (le32_to_cpu(m->bytes_allocated) != vol->mft_record_size) { + ntfs_log_error("Record %llu has corrupt allocation size " + "(%u <> %u)\n", (unsigned long long)MREF(mref), + vol->mft_record_size, + le32_to_cpu(m->bytes_allocated)); + goto err_out; + } + + a = (ATTR_RECORD *)((char *)m + le16_to_cpu(m->attrs_offset)); + if (p2n(a) < p2n(m) || (char *)a > (char *)m + vol->mft_record_size) { + ntfs_log_error("Record %llu is corrupt\n", + (unsigned long long)MREF(mref)); + goto err_out; + } + + ret = 0; +err_out: + if (ret) + errno = EIO; + return ret; +} + +/** + * ntfs_file_record_read - read a FILE record from the mft from disk + * @vol: volume to read from + * @mref: mft reference specifying mft record to read + * @mrec: address of pointer in which to return the mft record + * @attr: address of pointer in which to return the first attribute + * + * Read a FILE record from the mft of @vol from the storage medium. @mref + * specifies the mft record to read, including the sequence number, which can + * be 0 if no sequence number checking is to be performed. + * + * The function allocates a buffer large enough to hold the mft record and + * reads the record into the buffer (mst deprotecting it in the process). + * *@mrec is then set to point to the buffer. + * + * If @attr is not NULL, *@attr is set to point to the first attribute in the + * mft record, i.e. *@attr is a pointer into *@mrec. + * + * Return 0 on success, or -1 on error, with errno set to the error code. + * + * The read mft record is checked for having the magic FILE, + * and for having a matching sequence number (if MSEQNO(*@mref) != 0). + * If either of these fails, -1 is returned and errno is set to EIO. If you get + * this, but you still want to read the mft record (e.g. in order to correct + * it), use ntfs_mft_record_read() directly. + * + * Note: Caller has to free *@mrec when finished. + * + * Note: We do not check if the mft record is flagged in use. The caller can + * check if desired. + */ +int ntfs_file_record_read(const ntfs_volume *vol, const MFT_REF mref, + MFT_RECORD **mrec, ATTR_RECORD **attr) +{ + MFT_RECORD *m; + + if (!vol || !mrec) { + errno = EINVAL; + ntfs_log_perror("%s: mrec=%p", __FUNCTION__, mrec); + return -1; + } + + m = *mrec; + if (!m) { + m = ntfs_malloc(vol->mft_record_size); + if (!m) + return -1; + } + if (ntfs_mft_record_read(vol, mref, m)) + goto err_out; + + if (ntfs_mft_record_check(vol, mref, m)) + goto err_out; + + if (MSEQNO(mref) && MSEQNO(mref) != le16_to_cpu(m->sequence_number)) { + ntfs_log_error("Record %llu has wrong SeqNo (%d <> %d)\n", + (unsigned long long)MREF(mref), MSEQNO(mref), + le16_to_cpu(m->sequence_number)); + errno = EIO; + goto err_out; + } + *mrec = m; + if (attr) + *attr = (ATTR_RECORD*)((char*)m + le16_to_cpu(m->attrs_offset)); + return 0; +err_out: + if (m != *mrec) + free(m); + return -1; +} + +/** + * ntfs_mft_record_layout - layout an mft record into a memory buffer + * @vol: volume to which the mft record will belong + * @mref: mft reference specifying the mft record number + * @mrec: destination buffer of size >= @vol->mft_record_size bytes + * + * Layout an empty, unused mft record with the mft reference @mref into the + * buffer @m. The volume @vol is needed because the mft record structure was + * modified in NTFS 3.1 so we need to know which volume version this mft record + * will be used on. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, + MFT_RECORD *mrec) +{ + ATTR_RECORD *a; + + if (!vol || !mrec) { + errno = EINVAL; + ntfs_log_perror("%s: mrec=%p", __FUNCTION__, mrec); + return -1; + } + /* Aligned to 2-byte boundary. */ + if (vol->major_ver < 3 || (vol->major_ver == 3 && !vol->minor_ver)) + mrec->usa_ofs = cpu_to_le16((sizeof(MFT_RECORD_OLD) + 1) & ~1); + else { + /* Abort if mref is > 32 bits. */ + if (MREF(mref) & 0x0000ffff00000000ull) { + errno = ERANGE; + ntfs_log_perror("Mft reference exceeds 32 bits"); + return -1; + } + mrec->usa_ofs = cpu_to_le16((sizeof(MFT_RECORD) + 1) & ~1); + /* + * Set the NTFS 3.1+ specific fields while we know that the + * volume version is 3.1+. + */ + mrec->reserved = cpu_to_le16(0); + mrec->mft_record_number = cpu_to_le32(MREF(mref)); + } + mrec->magic = magic_FILE; + if (vol->mft_record_size >= NTFS_BLOCK_SIZE) + mrec->usa_count = cpu_to_le16(vol->mft_record_size / + NTFS_BLOCK_SIZE + 1); + else { + mrec->usa_count = cpu_to_le16(1); + ntfs_log_error("Sector size is bigger than MFT record size. " + "Setting usa_count to 1. If Windows chkdsk " + "reports this as corruption, please email %s " + "stating that you saw this message and that " + "the file system created was corrupt. " + "Thank you.\n", NTFS_DEV_LIST); + } + /* Set the update sequence number to 1. */ + *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = cpu_to_le16(1); + mrec->lsn = cpu_to_le64(0ull); + mrec->sequence_number = cpu_to_le16(1); + mrec->link_count = cpu_to_le16(0); + /* Aligned to 8-byte boundary. */ + mrec->attrs_offset = cpu_to_le16((le16_to_cpu(mrec->usa_ofs) + + (le16_to_cpu(mrec->usa_count) << 1) + 7) & ~7); + mrec->flags = cpu_to_le16(0); + /* + * Using attrs_offset plus eight bytes (for the termination attribute), + * aligned to 8-byte boundary. + */ + mrec->bytes_in_use = cpu_to_le32((le16_to_cpu(mrec->attrs_offset) + 8 + + 7) & ~7); + mrec->bytes_allocated = cpu_to_le32(vol->mft_record_size); + mrec->base_mft_record = cpu_to_le64((MFT_REF)0); + mrec->next_attr_instance = cpu_to_le16(0); + a = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); + a->type = AT_END; + a->length = cpu_to_le32(0); + /* Finally, clear the unused part of the mft record. */ + memset((u8*)a + 8, 0, vol->mft_record_size - ((u8*)a + 8 - (u8*)mrec)); + return 0; +} + +/** + * ntfs_mft_record_format - format an mft record on an ntfs volume + * @vol: volume on which to format the mft record + * @mref: mft reference specifying mft record to format + * + * Format the mft record with the mft reference @mref in $MFT/$DATA, i.e. lay + * out an empty, unused mft record in memory and write it to the volume @vol. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +int ntfs_mft_record_format(const ntfs_volume *vol, const MFT_REF mref) +{ + MFT_RECORD *m; + int ret = -1; + + ntfs_log_enter("Entering\n"); + + m = ntfs_calloc(vol->mft_record_size); + if (!m) + goto out; + + if (ntfs_mft_record_layout(vol, mref, m)) + goto free_m; + + if (ntfs_mft_record_write(vol, mref, m)) + goto free_m; + + ret = 0; +free_m: + free(m); +out: + ntfs_log_leave("\n"); + return ret; +} + +static const char *es = " Leaving inconsistent metadata. Run chkdsk."; + +/** + * ntfs_ffz - Find the first unset (zero) bit in a word + * @word: + * + * Description... + * + * Returns: + */ +static inline unsigned int ntfs_ffz(unsigned int word) +{ + return ffs(~word) - 1; +} + +static int ntfs_is_mft(ntfs_inode *ni) +{ + if (ni && ni->mft_no == FILE_MFT) + return 1; + return 0; +} + +#ifndef PAGE_SIZE +#define PAGE_SIZE 4096 +#endif + +#define RESERVED_MFT_RECORDS 64 + +/** + * ntfs_mft_bitmap_find_free_rec - find a free mft record in the mft bitmap + * @vol: volume on which to search for a free mft record + * @base_ni: open base inode if allocating an extent mft record or NULL + * + * Search for a free mft record in the mft bitmap attribute on the ntfs volume + * @vol. + * + * If @base_ni is NULL start the search at the default allocator position. + * + * If @base_ni is not NULL start the search at the mft record after the base + * mft record @base_ni. + * + * Return the free mft record on success and -1 on error with errno set to the + * error code. An error code of ENOSPC means that there are no free mft + * records in the currently initialized mft bitmap. + */ +static int ntfs_mft_bitmap_find_free_rec(ntfs_volume *vol, ntfs_inode *base_ni) +{ + s64 pass_end, ll, data_pos, pass_start, ofs, bit; + ntfs_attr *mftbmp_na; + u8 *buf, *byte; + unsigned int size; + u8 pass, b; + int ret = -1; + + ntfs_log_enter("Entering\n"); + + mftbmp_na = vol->mftbmp_na; + /* + * Set the end of the pass making sure we do not overflow the mft + * bitmap. + */ + size = PAGE_SIZE; + pass_end = vol->mft_na->allocated_size >> vol->mft_record_size_bits; + ll = mftbmp_na->initialized_size << 3; + if (pass_end > ll) + pass_end = ll; + pass = 1; + if (!base_ni) + data_pos = vol->mft_data_pos; + else + data_pos = base_ni->mft_no + 1; + if (data_pos < RESERVED_MFT_RECORDS) + data_pos = RESERVED_MFT_RECORDS; + if (data_pos >= pass_end) { + data_pos = RESERVED_MFT_RECORDS; + pass = 2; + /* This happens on a freshly formatted volume. */ + if (data_pos >= pass_end) { + errno = ENOSPC; + goto leave; + } + } + if (ntfs_is_mft(base_ni)) { + data_pos = 0; + pass = 2; + } + pass_start = data_pos; + buf = ntfs_malloc(PAGE_SIZE); + if (!buf) + goto leave; + + ntfs_log_debug("Starting bitmap search: pass %u, pass_start 0x%llx, " + "pass_end 0x%llx, data_pos 0x%llx.\n", pass, + (long long)pass_start, (long long)pass_end, + (long long)data_pos); +#ifdef DEBUG + byte = NULL; + b = 0; +#endif + /* Loop until a free mft record is found. */ + for (; pass <= 2; size = PAGE_SIZE) { + /* Cap size to pass_end. */ + ofs = data_pos >> 3; + ll = ((pass_end + 7) >> 3) - ofs; + if (size > ll) + size = ll; + ll = ntfs_attr_pread(mftbmp_na, ofs, size, buf); + if (ll < 0) { + ntfs_log_perror("Failed to read $MFT bitmap"); + free(buf); + goto leave; + } + ntfs_log_debug("Read 0x%llx bytes.\n", (long long)ll); + /* If we read at least one byte, search @buf for a zero bit. */ + if (ll) { + size = ll << 3; + bit = data_pos & 7; + data_pos &= ~7ull; + ntfs_log_debug("Before inner for loop: size 0x%x, " + "data_pos 0x%llx, bit 0x%llx, " + "*byte 0x%hhx, b %u.\n", size, + (long long)data_pos, (long long)bit, + byte ? *byte : -1, b); + for (; bit < size && data_pos + bit < pass_end; + bit &= ~7ull, bit += 8) { + /* + * If we're extending $MFT and running out of the first + * mft record (base record) then give up searching since + * no guarantee that the found record will be accessible. + */ + if (ntfs_is_mft(base_ni) && bit > 400) + goto out; + + byte = buf + (bit >> 3); + if (*byte == 0xff) + continue; + + /* Note: ffz() result must be zero based. */ + b = ntfs_ffz((unsigned long)*byte); + if (b < 8 && b >= (bit & 7)) { + free(buf); + ret = data_pos + (bit & ~7ull) + b; + goto leave; + } + } + ntfs_log_debug("After inner for loop: size 0x%x, " + "data_pos 0x%llx, bit 0x%llx, " + "*byte 0x%hhx, b %u.\n", size, + (long long)data_pos, (long long)bit, + byte ? *byte : -1, b); + data_pos += size; + /* + * If the end of the pass has not been reached yet, + * continue searching the mft bitmap for a zero bit. + */ + if (data_pos < pass_end) + continue; + } + /* Do the next pass. */ + pass++; + if (pass == 2) { + /* + * Starting the second pass, in which we scan the first + * part of the zone which we omitted earlier. + */ + pass_end = pass_start; + data_pos = pass_start = RESERVED_MFT_RECORDS; + ntfs_log_debug("pass %i, pass_start 0x%llx, pass_end " + "0x%llx.\n", pass, (long long)pass_start, + (long long)pass_end); + if (data_pos >= pass_end) + break; + } + } + /* No free mft records in currently initialized mft bitmap. */ +out: + free(buf); + errno = ENOSPC; +leave: + ntfs_log_leave("\n"); + return ret; +} + +static int ntfs_mft_attr_extend(ntfs_attr *na) +{ + int ret = STATUS_ERROR; + ntfs_log_enter("Entering\n"); + + if (!NInoAttrList(na->ni)) { + if (ntfs_inode_add_attrlist(na->ni)) { + ntfs_log_perror("%s: Can not add attrlist #3", __FUNCTION__); + goto out; + } + /* We can't sync the $MFT inode since its runlist is bogus. */ + ret = STATUS_KEEP_SEARCHING; + goto out; + } + + if (ntfs_attr_update_mapping_pairs(na, 0)) { + ntfs_log_perror("%s: MP update failed", __FUNCTION__); + goto out; + } + + ret = STATUS_OK; +out: + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_mft_bitmap_extend_allocation_i - see ntfs_mft_bitmap_extend_allocation + */ +static int ntfs_mft_bitmap_extend_allocation_i(ntfs_volume *vol) +{ + LCN lcn; + s64 ll = 0; /* silence compiler warning */ + ntfs_attr *mftbmp_na; + runlist_element *rl, *rl2 = NULL; /* silence compiler warning */ + ntfs_attr_search_ctx *ctx; + MFT_RECORD *m = NULL; /* silence compiler warning */ + ATTR_RECORD *a = NULL; /* silence compiler warning */ + int err, mp_size; + int ret = STATUS_ERROR; + u32 old_alen = 0; /* silence compiler warning */ + BOOL mp_rebuilt = FALSE; + BOOL update_mp = FALSE; + + mftbmp_na = vol->mftbmp_na; + /* + * Determine the last lcn of the mft bitmap. The allocated size of the + * mft bitmap cannot be zero so we are ok to do this. + */ + rl = ntfs_attr_find_vcn(mftbmp_na, (mftbmp_na->allocated_size - 1) >> + vol->cluster_size_bits); + if (!rl || !rl->length || rl->lcn < 0) { + ntfs_log_error("Failed to determine last allocated " + "cluster of mft bitmap attribute.\n"); + if (rl) + errno = EIO; + return STATUS_ERROR; + } + lcn = rl->lcn + rl->length; + + rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE); + if (!rl2) { + ntfs_log_error("Failed to allocate a cluster for " + "the mft bitmap.\n"); + return STATUS_ERROR; + } + rl = ntfs_runlists_merge(mftbmp_na->rl, rl2); + if (!rl) { + err = errno; + ntfs_log_error("Failed to merge runlists for mft " + "bitmap.\n"); + if (ntfs_cluster_free_from_rl(vol, rl2)) + ntfs_log_error("Failed to deallocate " + "cluster.%s\n", es); + free(rl2); + errno = err; + return STATUS_ERROR; + } + mftbmp_na->rl = rl; + ntfs_log_debug("Adding one run to mft bitmap.\n"); + /* Find the last run in the new runlist. */ + for (; rl[1].length; rl++) + ; + /* + * Update the attribute record as well. Note: @rl is the last + * (non-terminator) runlist element of mft bitmap. + */ + ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); + if (!ctx) + goto undo_alloc; + + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, + mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { + ntfs_log_error("Failed to find last attribute extent of " + "mft bitmap attribute.\n"); + goto undo_alloc; + } + m = ctx->mrec; + a = ctx->attr; + ll = sle64_to_cpu(a->lowest_vcn); + rl2 = ntfs_attr_find_vcn(mftbmp_na, ll); + if (!rl2 || !rl2->length) { + ntfs_log_error("Failed to determine previous last " + "allocated cluster of mft bitmap attribute.\n"); + if (rl2) + errno = EIO; + goto undo_alloc; + } + /* Get the size for the new mapping pairs array for this extent. */ + mp_size = ntfs_get_size_for_mapping_pairs(vol, rl2, ll, INT_MAX); + if (mp_size <= 0) { + ntfs_log_error("Get size for mapping pairs failed for " + "mft bitmap attribute extent.\n"); + goto undo_alloc; + } + /* Expand the attribute record if necessary. */ + old_alen = le32_to_cpu(a->length); + if (ntfs_attr_record_resize(m, a, mp_size + + le16_to_cpu(a->mapping_pairs_offset))) { + ntfs_log_info("extending $MFT bitmap\n"); + ret = ntfs_mft_attr_extend(vol->mftbmp_na); + if (ret == STATUS_OK) + goto ok; + if (ret == STATUS_ERROR) { + ntfs_log_perror("%s: ntfs_mft_attr_extend failed", __FUNCTION__); + update_mp = TRUE; + } + goto undo_alloc; + } + mp_rebuilt = TRUE; + /* Generate the mapping pairs array directly into the attr record. */ + if (ntfs_mapping_pairs_build(vol, (u8*)a + + le16_to_cpu(a->mapping_pairs_offset), mp_size, rl2, ll, + NULL)) { + ntfs_log_error("Failed to build mapping pairs array for " + "mft bitmap attribute.\n"); + errno = EIO; + goto undo_alloc; + } + /* Update the highest_vcn. */ + a->highest_vcn = cpu_to_sle64(rl[1].vcn - 1); + /* + * We now have extended the mft bitmap allocated_size by one cluster. + * Reflect this in the ntfs_attr structure and the attribute record. + */ + if (a->lowest_vcn) { + /* + * We are not in the first attribute extent, switch to it, but + * first ensure the changes will make it to disk later. + */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, + mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { + ntfs_log_error("Failed to find first attribute " + "extent of mft bitmap attribute.\n"); + goto restore_undo_alloc; + } + a = ctx->attr; + } +ok: + mftbmp_na->allocated_size += vol->cluster_size; + a->allocated_size = cpu_to_sle64(mftbmp_na->allocated_size); + /* Ensure the changes make it to disk. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + return STATUS_OK; + +restore_undo_alloc: + err = errno; + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, + mftbmp_na->name_len, 0, rl[1].vcn, NULL, 0, ctx)) { + ntfs_log_error("Failed to find last attribute extent of " + "mft bitmap attribute.%s\n", es); + ntfs_attr_put_search_ctx(ctx); + mftbmp_na->allocated_size += vol->cluster_size; + /* + * The only thing that is now wrong is ->allocated_size of the + * base attribute extent which chkdsk should be able to fix. + */ + errno = err; + return STATUS_ERROR; + } + m = ctx->mrec; + a = ctx->attr; + a->highest_vcn = cpu_to_sle64(rl[1].vcn - 2); + errno = err; +undo_alloc: + err = errno; + + /* Remove the last run from the runlist. */ + lcn = rl->lcn; + rl->lcn = rl[1].lcn; + rl->length = 0; + + /* FIXME: use an ntfs_cluster_free_* function */ + if (ntfs_bitmap_clear_bit(vol->lcnbmp_na, lcn)) + ntfs_log_error("Failed to free cluster.%s\n", es); + else + vol->free_clusters++; + if (mp_rebuilt) { + if (ntfs_mapping_pairs_build(vol, (u8*)a + + le16_to_cpu(a->mapping_pairs_offset), + old_alen - le16_to_cpu(a->mapping_pairs_offset), + rl2, ll, NULL)) + ntfs_log_error("Failed to restore mapping " + "pairs array.%s\n", es); + if (ntfs_attr_record_resize(m, a, old_alen)) + ntfs_log_error("Failed to restore attribute " + "record.%s\n", es); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + } + if (update_mp) { + if (ntfs_attr_update_mapping_pairs(vol->mftbmp_na, 0)) + ntfs_log_perror("%s: MP update failed", __FUNCTION__); + } + if (ctx) + ntfs_attr_put_search_ctx(ctx); + errno = err; + return ret; +} + +/** + * ntfs_mft_bitmap_extend_allocation - extend mft bitmap attribute by a cluster + * @vol: volume on which to extend the mft bitmap attribute + * + * Extend the mft bitmap attribute on the ntfs volume @vol by one cluster. + * + * Note: Only changes allocated_size, i.e. does not touch initialized_size or + * data_size. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +static int ntfs_mft_bitmap_extend_allocation(ntfs_volume *vol) +{ + int ret; + + ntfs_log_enter("Entering\n"); + ret = ntfs_mft_bitmap_extend_allocation_i(vol); + ntfs_log_leave("\n"); + return ret; +} +/** + * ntfs_mft_bitmap_extend_initialized - extend mft bitmap initialized data + * @vol: volume on which to extend the mft bitmap attribute + * + * Extend the initialized portion of the mft bitmap attribute on the ntfs + * volume @vol by 8 bytes. + * + * Note: Only changes initialized_size and data_size, i.e. requires that + * allocated_size is big enough to fit the new initialized_size. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +static int ntfs_mft_bitmap_extend_initialized(ntfs_volume *vol) +{ + s64 old_data_size, old_initialized_size, ll; + ntfs_attr *mftbmp_na; + ntfs_attr_search_ctx *ctx; + ATTR_RECORD *a; + int err; + int ret = -1; + + ntfs_log_enter("Entering\n"); + + mftbmp_na = vol->mftbmp_na; + ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); + if (!ctx) + goto out; + + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, + mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { + ntfs_log_error("Failed to find first attribute extent of " + "mft bitmap attribute.\n"); + err = errno; + goto put_err_out; + } + a = ctx->attr; + old_data_size = mftbmp_na->data_size; + old_initialized_size = mftbmp_na->initialized_size; + mftbmp_na->initialized_size += 8; + a->initialized_size = cpu_to_sle64(mftbmp_na->initialized_size); + if (mftbmp_na->initialized_size > mftbmp_na->data_size) { + mftbmp_na->data_size = mftbmp_na->initialized_size; + a->data_size = cpu_to_sle64(mftbmp_na->data_size); + } + /* Ensure the changes make it to disk. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + /* Initialize the mft bitmap attribute value with zeroes. */ + ll = 0; + ll = ntfs_attr_pwrite(mftbmp_na, old_initialized_size, 8, &ll); + if (ll == 8) { + ntfs_log_debug("Wrote eight initialized bytes to mft bitmap.\n"); + vol->free_mft_records += (8 * 8); + ret = 0; + goto out; + } + ntfs_log_error("Failed to write to mft bitmap.\n"); + err = errno; + if (ll >= 0) + err = EIO; + /* Try to recover from the error. */ + ctx = ntfs_attr_get_search_ctx(mftbmp_na->ni, NULL); + if (!ctx) + goto err_out; + + if (ntfs_attr_lookup(mftbmp_na->type, mftbmp_na->name, + mftbmp_na->name_len, 0, 0, NULL, 0, ctx)) { + ntfs_log_error("Failed to find first attribute extent of " + "mft bitmap attribute.%s\n", es); +put_err_out: + ntfs_attr_put_search_ctx(ctx); + goto err_out; + } + a = ctx->attr; + mftbmp_na->initialized_size = old_initialized_size; + a->initialized_size = cpu_to_sle64(old_initialized_size); + if (mftbmp_na->data_size != old_data_size) { + mftbmp_na->data_size = old_data_size; + a->data_size = cpu_to_sle64(old_data_size); + } + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + ntfs_log_debug("Restored status of mftbmp: allocated_size 0x%llx, " + "data_size 0x%llx, initialized_size 0x%llx.\n", + (long long)mftbmp_na->allocated_size, + (long long)mftbmp_na->data_size, + (long long)mftbmp_na->initialized_size); +err_out: + errno = err; +out: + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_mft_data_extend_allocation - extend mft data attribute + * @vol: volume on which to extend the mft data attribute + * + * Extend the mft data attribute on the ntfs volume @vol by 16 mft records + * worth of clusters or if not enough space for this by one mft record worth + * of clusters. + * + * Note: Only changes allocated_size, i.e. does not touch initialized_size or + * data_size. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +static int ntfs_mft_data_extend_allocation(ntfs_volume *vol) +{ + LCN lcn; + VCN old_last_vcn; + s64 min_nr, nr, ll = 0; /* silence compiler warning */ + ntfs_attr *mft_na; + runlist_element *rl, *rl2; + ntfs_attr_search_ctx *ctx; + MFT_RECORD *m = NULL; /* silence compiler warning */ + ATTR_RECORD *a = NULL; /* silence compiler warning */ + int err, mp_size; + int ret = STATUS_ERROR; + u32 old_alen = 0; /* silence compiler warning */ + BOOL mp_rebuilt = FALSE; + BOOL update_mp = FALSE; + + ntfs_log_enter("Extending mft data allocation.\n"); + + mft_na = vol->mft_na; + /* + * Determine the preferred allocation location, i.e. the last lcn of + * the mft data attribute. The allocated size of the mft data + * attribute cannot be zero so we are ok to do this. + */ + rl = ntfs_attr_find_vcn(mft_na, + (mft_na->allocated_size - 1) >> vol->cluster_size_bits); + + if (!rl || !rl->length || rl->lcn < 0) { + ntfs_log_error("Failed to determine last allocated " + "cluster of mft data attribute.\n"); + if (rl) + errno = EIO; + goto out; + } + + lcn = rl->lcn + rl->length; + ntfs_log_debug("Last lcn of mft data attribute is 0x%llx.\n", (long long)lcn); + /* Minimum allocation is one mft record worth of clusters. */ + min_nr = vol->mft_record_size >> vol->cluster_size_bits; + if (!min_nr) + min_nr = 1; + /* Want to allocate 16 mft records worth of clusters. */ + nr = vol->mft_record_size << 4 >> vol->cluster_size_bits; + if (!nr) + nr = min_nr; + + old_last_vcn = rl[1].vcn; + do { + rl2 = ntfs_cluster_alloc(vol, old_last_vcn, nr, lcn, MFT_ZONE); + if (rl2) + break; + if (errno != ENOSPC || nr == min_nr) { + ntfs_log_perror("Failed to allocate (%lld) clusters " + "for $MFT", (long long)nr); + goto out; + } + /* + * There is not enough space to do the allocation, but there + * might be enough space to do a minimal allocation so try that + * before failing. + */ + nr = min_nr; + ntfs_log_debug("Retrying mft data allocation with minimal cluster " + "count %lli.\n", (long long)nr); + } while (1); + + ntfs_log_debug("Allocated %lld clusters.\n", (long long)nr); + + rl = ntfs_runlists_merge(mft_na->rl, rl2); + if (!rl) { + err = errno; + ntfs_log_error("Failed to merge runlists for mft data " + "attribute.\n"); + if (ntfs_cluster_free_from_rl(vol, rl2)) + ntfs_log_error("Failed to deallocate clusters " + "from the mft data attribute.%s\n", es); + free(rl2); + errno = err; + goto out; + } + mft_na->rl = rl; + + /* Find the last run in the new runlist. */ + for (; rl[1].length; rl++) + ; + /* Update the attribute record as well. */ + ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); + if (!ctx) + goto undo_alloc; + + if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, + rl[1].vcn, NULL, 0, ctx)) { + ntfs_log_error("Failed to find last attribute extent of " + "mft data attribute.\n"); + goto undo_alloc; + } + m = ctx->mrec; + a = ctx->attr; + ll = sle64_to_cpu(a->lowest_vcn); + rl2 = ntfs_attr_find_vcn(mft_na, ll); + if (!rl2 || !rl2->length) { + ntfs_log_error("Failed to determine previous last " + "allocated cluster of mft data attribute.\n"); + if (rl2) + errno = EIO; + goto undo_alloc; + } + /* Get the size for the new mapping pairs array for this extent. */ + mp_size = ntfs_get_size_for_mapping_pairs(vol, rl2, ll, INT_MAX); + if (mp_size <= 0) { + ntfs_log_error("Get size for mapping pairs failed for " + "mft data attribute extent.\n"); + goto undo_alloc; + } + /* Expand the attribute record if necessary. */ + old_alen = le32_to_cpu(a->length); + if (ntfs_attr_record_resize(m, a, + mp_size + le16_to_cpu(a->mapping_pairs_offset))) { + ret = ntfs_mft_attr_extend(vol->mft_na); + if (ret == STATUS_OK) + goto ok; + if (ret == STATUS_ERROR) { + ntfs_log_perror("%s: ntfs_mft_attr_extend failed", __FUNCTION__); + update_mp = TRUE; + } + goto undo_alloc; + } + mp_rebuilt = TRUE; + /* + * Generate the mapping pairs array directly into the attribute record. + */ + if (ntfs_mapping_pairs_build(vol, + (u8*)a + le16_to_cpu(a->mapping_pairs_offset), mp_size, + rl2, ll, NULL)) { + ntfs_log_error("Failed to build mapping pairs array of " + "mft data attribute.\n"); + errno = EIO; + goto undo_alloc; + } + /* Update the highest_vcn. */ + a->highest_vcn = cpu_to_sle64(rl[1].vcn - 1); + /* + * We now have extended the mft data allocated_size by nr clusters. + * Reflect this in the ntfs_attr structure and the attribute record. + * @rl is the last (non-terminator) runlist element of mft data + * attribute. + */ + if (a->lowest_vcn) { + /* + * We are not in the first attribute extent, switch to it, but + * first ensure the changes will make it to disk later. + */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(mft_na->type, mft_na->name, + mft_na->name_len, 0, 0, NULL, 0, ctx)) { + ntfs_log_error("Failed to find first attribute " + "extent of mft data attribute.\n"); + goto restore_undo_alloc; + } + a = ctx->attr; + } +ok: + mft_na->allocated_size += nr << vol->cluster_size_bits; + a->allocated_size = cpu_to_sle64(mft_na->allocated_size); + /* Ensure the changes make it to disk. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + ret = STATUS_OK; +out: + ntfs_log_leave("\n"); + return ret; + +restore_undo_alloc: + err = errno; + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, + rl[1].vcn, NULL, 0, ctx)) { + ntfs_log_error("Failed to find last attribute extent of " + "mft data attribute.%s\n", es); + ntfs_attr_put_search_ctx(ctx); + mft_na->allocated_size += nr << vol->cluster_size_bits; + /* + * The only thing that is now wrong is ->allocated_size of the + * base attribute extent which chkdsk should be able to fix. + */ + errno = err; + ret = STATUS_ERROR; + goto out; + } + m = ctx->mrec; + a = ctx->attr; + a->highest_vcn = cpu_to_sle64(old_last_vcn - 1); + errno = err; +undo_alloc: + err = errno; + if (ntfs_cluster_free(vol, mft_na, old_last_vcn, -1) < 0) + ntfs_log_error("Failed to free clusters from mft data " + "attribute.%s\n", es); + if (ntfs_rl_truncate(&mft_na->rl, old_last_vcn)) + ntfs_log_error("Failed to truncate mft data attribute " + "runlist.%s\n", es); + if (mp_rebuilt) { + if (ntfs_mapping_pairs_build(vol, (u8*)a + + le16_to_cpu(a->mapping_pairs_offset), + old_alen - le16_to_cpu(a->mapping_pairs_offset), + rl2, ll, NULL)) + ntfs_log_error("Failed to restore mapping pairs " + "array.%s\n", es); + if (ntfs_attr_record_resize(m, a, old_alen)) + ntfs_log_error("Failed to restore attribute " + "record.%s\n", es); + ntfs_inode_mark_dirty(ctx->ntfs_ino); + } + if (update_mp) { + if (ntfs_attr_update_mapping_pairs(vol->mft_na, 0)) + ntfs_log_perror("%s: MP update failed", __FUNCTION__); + } + if (ctx) + ntfs_attr_put_search_ctx(ctx); + errno = err; + goto out; +} + + +static int ntfs_mft_record_init(ntfs_volume *vol, s64 size) +{ + int ret = -1; + ntfs_attr *mft_na, *mftbmp_na; + s64 old_data_initialized, old_data_size; + ntfs_attr_search_ctx *ctx; + + ntfs_log_enter("Entering\n"); + + /* NOTE: Caller must sanity check vol, vol->mft_na and vol->mftbmp_na */ + + mft_na = vol->mft_na; + mftbmp_na = vol->mftbmp_na; + + /* + * The mft record is outside the initialized data. Extend the mft data + * attribute until it covers the allocated record. The loop is only + * actually traversed more than once when a freshly formatted volume + * is first written to so it optimizes away nicely in the common case. + */ + ntfs_log_debug("Status of mft data before extension: " + "allocated_size 0x%llx, data_size 0x%llx, " + "initialized_size 0x%llx.\n", + (long long)mft_na->allocated_size, + (long long)mft_na->data_size, + (long long)mft_na->initialized_size); + while (size > mft_na->allocated_size) { + if (ntfs_mft_data_extend_allocation(vol) == STATUS_ERROR) + goto out; + ntfs_log_debug("Status of mft data after allocation extension: " + "allocated_size 0x%llx, data_size 0x%llx, " + "initialized_size 0x%llx.\n", + (long long)mft_na->allocated_size, + (long long)mft_na->data_size, + (long long)mft_na->initialized_size); + } + + old_data_initialized = mft_na->initialized_size; + old_data_size = mft_na->data_size; + + /* + * Extend mft data initialized size (and data size of course) to reach + * the allocated mft record, formatting the mft records along the way. + * Note: We only modify the ntfs_attr structure as that is all that is + * needed by ntfs_mft_record_format(). We will update the attribute + * record itself in one fell swoop later on. + */ + while (size > mft_na->initialized_size) { + s64 ll2 = mft_na->initialized_size >> vol->mft_record_size_bits; + mft_na->initialized_size += vol->mft_record_size; + if (mft_na->initialized_size > mft_na->data_size) + mft_na->data_size = mft_na->initialized_size; + ntfs_log_debug("Initializing mft record 0x%llx.\n", (long long)ll2); + if (ntfs_mft_record_format(vol, ll2) < 0) { + ntfs_log_perror("Failed to format mft record"); + goto undo_data_init; + } + } + + /* Update the mft data attribute record to reflect the new sizes. */ + ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); + if (!ctx) + goto undo_data_init; + + if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, + 0, NULL, 0, ctx)) { + ntfs_log_error("Failed to find first attribute extent of " + "mft data attribute.\n"); + ntfs_attr_put_search_ctx(ctx); + goto undo_data_init; + } + ctx->attr->initialized_size = cpu_to_sle64(mft_na->initialized_size); + ctx->attr->data_size = cpu_to_sle64(mft_na->data_size); + ctx->attr->allocated_size = cpu_to_sle64(mft_na->allocated_size); + + /* Ensure the changes make it to disk. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + ntfs_log_debug("Status of mft data after mft record initialization: " + "allocated_size 0x%llx, data_size 0x%llx, " + "initialized_size 0x%llx.\n", + (long long)mft_na->allocated_size, + (long long)mft_na->data_size, + (long long)mft_na->initialized_size); + + /* Sanity checks. */ + if (mft_na->data_size > mft_na->allocated_size || + mft_na->initialized_size > mft_na->data_size) + NTFS_BUG("mft_na sanity checks failed"); + + /* Sync MFT to minimize data loss if there won't be clean unmount. */ + if (ntfs_inode_sync(mft_na->ni)) + goto undo_data_init; + + ret = 0; +out: + ntfs_log_leave("\n"); + return ret; + +undo_data_init: + mft_na->initialized_size = old_data_initialized; + mft_na->data_size = old_data_size; + goto out; +} + +static int ntfs_mft_rec_init(ntfs_volume *vol, s64 size) +{ + int ret = -1; + ntfs_attr *mft_na, *mftbmp_na; + s64 old_data_initialized, old_data_size; + ntfs_attr_search_ctx *ctx; + + ntfs_log_enter("Entering\n"); + + mft_na = vol->mft_na; + mftbmp_na = vol->mftbmp_na; + + if (size > mft_na->allocated_size || size > mft_na->initialized_size) { + errno = EIO; + ntfs_log_perror("%s: unexpected $MFT sizes, see below", __FUNCTION__); + ntfs_log_error("$MFT: size=%lld allocated_size=%lld " + "data_size=%lld initialized_size=%lld\n", + (long long)size, + (long long)mft_na->allocated_size, + (long long)mft_na->data_size, + (long long)mft_na->initialized_size); + goto out; + } + + old_data_initialized = mft_na->initialized_size; + old_data_size = mft_na->data_size; + + /* Update the mft data attribute record to reflect the new sizes. */ + ctx = ntfs_attr_get_search_ctx(mft_na->ni, NULL); + if (!ctx) + goto undo_data_init; + + if (ntfs_attr_lookup(mft_na->type, mft_na->name, mft_na->name_len, 0, + 0, NULL, 0, ctx)) { + ntfs_log_error("Failed to find first attribute extent of " + "mft data attribute.\n"); + ntfs_attr_put_search_ctx(ctx); + goto undo_data_init; + } + ctx->attr->initialized_size = cpu_to_sle64(mft_na->initialized_size); + ctx->attr->data_size = cpu_to_sle64(mft_na->data_size); + + /* CHECKME: ctx->attr->allocation_size is already ok? */ + + /* Ensure the changes make it to disk. */ + ntfs_inode_mark_dirty(ctx->ntfs_ino); + ntfs_attr_put_search_ctx(ctx); + + /* Sanity checks. */ + if (mft_na->data_size > mft_na->allocated_size || + mft_na->initialized_size > mft_na->data_size) + NTFS_BUG("mft_na sanity checks failed"); +out: + ntfs_log_leave("\n"); + return ret; + +undo_data_init: + mft_na->initialized_size = old_data_initialized; + mft_na->data_size = old_data_size; + goto out; +} + +static ntfs_inode *ntfs_mft_rec_alloc(ntfs_volume *vol) +{ + s64 ll, bit; + ntfs_attr *mft_na, *mftbmp_na; + MFT_RECORD *m; + ntfs_inode *ni = NULL; + ntfs_inode *base_ni; + int err; + le16 seq_no, usn; + + ntfs_log_enter("Entering\n"); + + mft_na = vol->mft_na; + mftbmp_na = vol->mftbmp_na; + + base_ni = mft_na->ni; + + bit = ntfs_mft_bitmap_find_free_rec(vol, base_ni); + if (bit >= 0) + goto found_free_rec; + + if (errno != ENOSPC) + goto out; + + errno = ENOSPC; + /* strerror() is intentionally used below, we want to log this error. */ + ntfs_log_error("No free mft record for $MFT: %s\n", strerror(errno)); + goto err_out; + +found_free_rec: + if (ntfs_bitmap_set_bit(mftbmp_na, bit)) { + ntfs_log_error("Failed to allocate bit in mft bitmap #2\n"); + goto err_out; + } + + ll = (bit + 1) << vol->mft_record_size_bits; + if (ll > mft_na->initialized_size) + if (ntfs_mft_rec_init(vol, ll) < 0) + goto undo_mftbmp_alloc; + /* + * We now have allocated and initialized the mft record. Need to read + * it from disk and re-format it, preserving the sequence number if it + * is not zero as well as the update sequence number if it is not zero + * or -1 (0xffff). + */ + m = ntfs_malloc(vol->mft_record_size); + if (!m) + goto undo_mftbmp_alloc; + + if (ntfs_mft_record_read(vol, bit, m)) { + free(m); + goto undo_mftbmp_alloc; + } + /* Sanity check that the mft record is really not in use. */ + if (ntfs_is_file_record(m->magic) && (m->flags & MFT_RECORD_IN_USE)) { + ntfs_log_error("Inode %lld is used but it wasn't marked in " + "$MFT bitmap. Fixed.\n", (long long)bit); + free(m); + goto undo_mftbmp_alloc; + } + + seq_no = m->sequence_number; + usn = *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)); + if (ntfs_mft_record_layout(vol, bit, m)) { + ntfs_log_error("Failed to re-format mft record.\n"); + free(m); + goto undo_mftbmp_alloc; + } + if (seq_no) + m->sequence_number = seq_no; + seq_no = usn; + if (seq_no && seq_no != const_cpu_to_le16(0xffff)) + *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn; + /* Set the mft record itself in use. */ + m->flags |= MFT_RECORD_IN_USE; + /* Now need to open an ntfs inode for the mft record. */ + ni = ntfs_inode_allocate(vol); + if (!ni) { + ntfs_log_error("Failed to allocate buffer for inode.\n"); + free(m); + goto undo_mftbmp_alloc; + } + ni->mft_no = bit; + ni->mrec = m; + /* + * If we are allocating an extent mft record, make the opened inode an + * extent inode and attach it to the base inode. Also, set the base + * mft record reference in the extent inode. + */ + ni->nr_extents = -1; + ni->base_ni = base_ni; + m->base_mft_record = MK_LE_MREF(base_ni->mft_no, + le16_to_cpu(base_ni->mrec->sequence_number)); + /* + * Attach the extent inode to the base inode, reallocating + * memory if needed. + */ + if (!(base_ni->nr_extents & 3)) { + ntfs_inode **extent_nis; + int i; + + i = (base_ni->nr_extents + 4) * sizeof(ntfs_inode *); + extent_nis = ntfs_malloc(i); + if (!extent_nis) { + free(m); + free(ni); + goto undo_mftbmp_alloc; + } + if (base_ni->nr_extents) { + memcpy(extent_nis, base_ni->extent_nis, + i - 4 * sizeof(ntfs_inode *)); + free(base_ni->extent_nis); + } + base_ni->extent_nis = extent_nis; + } + base_ni->extent_nis[base_ni->nr_extents++] = ni; + + /* Make sure the allocated inode is written out to disk later. */ + ntfs_inode_mark_dirty(ni); + /* Initialize time, allocated and data size in ntfs_inode struct. */ + ni->data_size = ni->allocated_size = 0; + ni->flags = 0; + ni->creation_time = ni->last_data_change_time = + ni->last_mft_change_time = + ni->last_access_time = ntfs_current_time(); + /* Update the default mft allocation position if it was used. */ + if (!base_ni) + vol->mft_data_pos = bit + 1; + /* Return the opened, allocated inode of the allocated mft record. */ + ntfs_log_error("allocated %sinode %lld\n", + base_ni ? "extent " : "", (long long)bit); +out: + ntfs_log_leave("\n"); + return ni; + +undo_mftbmp_alloc: + err = errno; + if (ntfs_bitmap_clear_bit(mftbmp_na, bit)) + ntfs_log_error("Failed to clear bit in mft bitmap.%s\n", es); + errno = err; +err_out: + if (!errno) + errno = EIO; + ni = NULL; + goto out; +} + +/** + * ntfs_mft_record_alloc - allocate an mft record on an ntfs volume + * @vol: volume on which to allocate the mft record + * @base_ni: open base inode if allocating an extent mft record or NULL + * + * Allocate an mft record in $MFT/$DATA of an open ntfs volume @vol. + * + * If @base_ni is NULL make the mft record a base mft record and allocate it at + * the default allocator position. + * + * If @base_ni is not NULL make the allocated mft record an extent record, + * allocate it starting at the mft record after the base mft record and attach + * the allocated and opened ntfs inode to the base inode @base_ni. + * + * On success return the now opened ntfs (extent) inode of the mft record. + * + * On error return NULL with errno set to the error code. + * + * To find a free mft record, we scan the mft bitmap for a zero bit. To + * optimize this we start scanning at the place specified by @base_ni or if + * @base_ni is NULL we start where we last stopped and we perform wrap around + * when we reach the end. Note, we do not try to allocate mft records below + * number 24 because numbers 0 to 15 are the defined system files anyway and 16 + * to 24 are special in that they are used for storing extension mft records + * for the $DATA attribute of $MFT. This is required to avoid the possibility + * of creating a run list with a circular dependence which once written to disk + * can never be read in again. Windows will only use records 16 to 24 for + * normal files if the volume is completely out of space. We never use them + * which means that when the volume is really out of space we cannot create any + * more files while Windows can still create up to 8 small files. We can start + * doing this at some later time, it does not matter much for now. + * + * When scanning the mft bitmap, we only search up to the last allocated mft + * record. If there are no free records left in the range 24 to number of + * allocated mft records, then we extend the $MFT/$DATA attribute in order to + * create free mft records. We extend the allocated size of $MFT/$DATA by 16 + * records at a time or one cluster, if cluster size is above 16kiB. If there + * is not sufficient space to do this, we try to extend by a single mft record + * or one cluster, if cluster size is above the mft record size, but we only do + * this if there is enough free space, which we know from the values returned + * by the failed cluster allocation function when we tried to do the first + * allocation. + * + * No matter how many mft records we allocate, we initialize only the first + * allocated mft record, incrementing mft data size and initialized size + * accordingly, open an ntfs_inode for it and return it to the caller, unless + * there are less than 24 mft records, in which case we allocate and initialize + * mft records until we reach record 24 which we consider as the first free mft + * record for use by normal files. + * + * If during any stage we overflow the initialized data in the mft bitmap, we + * extend the initialized size (and data size) by 8 bytes, allocating another + * cluster if required. The bitmap data size has to be at least equal to the + * number of mft records in the mft, but it can be bigger, in which case the + * superfluous bits are padded with zeroes. + * + * Thus, when we return successfully (return value non-zero), we will have: + * - initialized / extended the mft bitmap if necessary, + * - initialized / extended the mft data if necessary, + * - set the bit corresponding to the mft record being allocated in the + * mft bitmap, + * - open an ntfs_inode for the allocated mft record, and we will + * - return the ntfs_inode. + * + * On error (return value zero), nothing will have changed. If we had changed + * anything before the error occurred, we will have reverted back to the + * starting state before returning to the caller. Thus, except for bugs, we + * should always leave the volume in a consistent state when returning from + * this function. + * + * Note, this function cannot make use of most of the normal functions, like + * for example for attribute resizing, etc, because when the run list overflows + * the base mft record and an attribute list is used, it is very important that + * the extension mft records used to store the $DATA attribute of $MFT can be + * reached without having to read the information contained inside them, as + * this would make it impossible to find them in the first place after the + * volume is dismounted. $MFT/$BITMAP probably does not need to follow this + * rule because the bitmap is not essential for finding the mft records, but on + * the other hand, handling the bitmap in this special way would make life + * easier because otherwise there might be circular invocations of functions + * when reading the bitmap but if we are careful, we should be able to avoid + * all problems. + */ +ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni) +{ + s64 ll, bit; + ntfs_attr *mft_na, *mftbmp_na; + MFT_RECORD *m; + ntfs_inode *ni = NULL; + int err; + le16 seq_no, usn; + + if (base_ni) + ntfs_log_enter("Entering (allocating an extent mft record for " + "base mft record %lld).\n", + (long long)base_ni->mft_no); + else + ntfs_log_enter("Entering (allocating a base mft record)\n"); + if (!vol || !vol->mft_na || !vol->mftbmp_na) { + errno = EINVAL; + goto out; + } + + if (ntfs_is_mft(base_ni)) { + ni = ntfs_mft_rec_alloc(vol); + goto out; + } + + mft_na = vol->mft_na; + mftbmp_na = vol->mftbmp_na; +retry: + bit = ntfs_mft_bitmap_find_free_rec(vol, base_ni); + if (bit >= 0) { + ntfs_log_debug("found free record (#1) at %lld\n", + (long long)bit); + goto found_free_rec; + } + if (errno != ENOSPC) + goto out; + /* + * No free mft records left. If the mft bitmap already covers more + * than the currently used mft records, the next records are all free, + * so we can simply allocate the first unused mft record. + * Note: We also have to make sure that the mft bitmap at least covers + * the first 24 mft records as they are special and whilst they may not + * be in use, we do not allocate from them. + */ + ll = mft_na->initialized_size >> vol->mft_record_size_bits; + if (mftbmp_na->initialized_size << 3 > ll && + mftbmp_na->initialized_size > RESERVED_MFT_RECORDS / 8) { + bit = ll; + if (bit < RESERVED_MFT_RECORDS) + bit = RESERVED_MFT_RECORDS; + ntfs_log_debug("found free record (#2) at %lld\n", + (long long)bit); + goto found_free_rec; + } + /* + * The mft bitmap needs to be expanded until it covers the first unused + * mft record that we can allocate. + * Note: The smallest mft record we allocate is mft record 24. + */ + ntfs_log_debug("Status of mftbmp before extension: allocated_size 0x%llx, " + "data_size 0x%llx, initialized_size 0x%llx.\n", + (long long)mftbmp_na->allocated_size, + (long long)mftbmp_na->data_size, + (long long)mftbmp_na->initialized_size); + if (mftbmp_na->initialized_size + 8 > mftbmp_na->allocated_size) { + + int ret = ntfs_mft_bitmap_extend_allocation(vol); + + if (ret == STATUS_ERROR) + goto err_out; + if (ret == STATUS_KEEP_SEARCHING) { + ret = ntfs_mft_bitmap_extend_allocation(vol); + if (ret != STATUS_OK) + goto err_out; + } + + ntfs_log_debug("Status of mftbmp after allocation extension: " + "allocated_size 0x%llx, data_size 0x%llx, " + "initialized_size 0x%llx.\n", + (long long)mftbmp_na->allocated_size, + (long long)mftbmp_na->data_size, + (long long)mftbmp_na->initialized_size); + } + /* + * We now have sufficient allocated space, extend the initialized_size + * as well as the data_size if necessary and fill the new space with + * zeroes. + */ + bit = mftbmp_na->initialized_size << 3; + if (ntfs_mft_bitmap_extend_initialized(vol)) + goto err_out; + ntfs_log_debug("Status of mftbmp after initialized extension: " + "allocated_size 0x%llx, data_size 0x%llx, " + "initialized_size 0x%llx.\n", + (long long)mftbmp_na->allocated_size, + (long long)mftbmp_na->data_size, + (long long)mftbmp_na->initialized_size); + ntfs_log_debug("found free record (#3) at %lld\n", (long long)bit); +found_free_rec: + /* @bit is the found free mft record, allocate it in the mft bitmap. */ + if (ntfs_bitmap_set_bit(mftbmp_na, bit)) { + ntfs_log_error("Failed to allocate bit in mft bitmap.\n"); + goto err_out; + } + + /* The mft bitmap is now uptodate. Deal with mft data attribute now. */ + ll = (bit + 1) << vol->mft_record_size_bits; + if (ll > mft_na->initialized_size) + if (ntfs_mft_record_init(vol, ll) < 0) + goto undo_mftbmp_alloc; + + /* + * We now have allocated and initialized the mft record. Need to read + * it from disk and re-format it, preserving the sequence number if it + * is not zero as well as the update sequence number if it is not zero + * or -1 (0xffff). + */ + m = ntfs_malloc(vol->mft_record_size); + if (!m) + goto undo_mftbmp_alloc; + + if (ntfs_mft_record_read(vol, bit, m)) { + free(m); + goto undo_mftbmp_alloc; + } + /* Sanity check that the mft record is really not in use. */ + if (ntfs_is_file_record(m->magic) && (m->flags & MFT_RECORD_IN_USE)) { + ntfs_log_error("Inode %lld is used but it wasn't marked in " + "$MFT bitmap. Fixed.\n", (long long)bit); + free(m); + goto retry; + } + seq_no = m->sequence_number; + usn = *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)); + if (ntfs_mft_record_layout(vol, bit, m)) { + ntfs_log_error("Failed to re-format mft record.\n"); + free(m); + goto undo_mftbmp_alloc; + } + if (seq_no) + m->sequence_number = seq_no; + seq_no = usn; + if (seq_no && seq_no != const_cpu_to_le16(0xffff)) + *(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn; + /* Set the mft record itself in use. */ + m->flags |= MFT_RECORD_IN_USE; + /* Now need to open an ntfs inode for the mft record. */ + ni = ntfs_inode_allocate(vol); + if (!ni) { + ntfs_log_error("Failed to allocate buffer for inode.\n"); + free(m); + goto undo_mftbmp_alloc; + } + ni->mft_no = bit; + ni->mrec = m; + /* + * If we are allocating an extent mft record, make the opened inode an + * extent inode and attach it to the base inode. Also, set the base + * mft record reference in the extent inode. + */ + if (base_ni) { + ni->nr_extents = -1; + ni->base_ni = base_ni; + m->base_mft_record = MK_LE_MREF(base_ni->mft_no, + le16_to_cpu(base_ni->mrec->sequence_number)); + /* + * Attach the extent inode to the base inode, reallocating + * memory if needed. + */ + if (!(base_ni->nr_extents & 3)) { + ntfs_inode **extent_nis; + int i; + + i = (base_ni->nr_extents + 4) * sizeof(ntfs_inode *); + extent_nis = ntfs_malloc(i); + if (!extent_nis) { + free(m); + free(ni); + goto undo_mftbmp_alloc; + } + if (base_ni->nr_extents) { + memcpy(extent_nis, base_ni->extent_nis, + i - 4 * sizeof(ntfs_inode *)); + free(base_ni->extent_nis); + } + base_ni->extent_nis = extent_nis; + } + base_ni->extent_nis[base_ni->nr_extents++] = ni; + } + /* Make sure the allocated inode is written out to disk later. */ + ntfs_inode_mark_dirty(ni); + /* Initialize time, allocated and data size in ntfs_inode struct. */ + ni->data_size = ni->allocated_size = 0; + ni->flags = 0; + ni->creation_time = ni->last_data_change_time = + ni->last_mft_change_time = + ni->last_access_time = ntfs_current_time(); + /* Update the default mft allocation position if it was used. */ + if (!base_ni) + vol->mft_data_pos = bit + 1; + /* Return the opened, allocated inode of the allocated mft record. */ + ntfs_log_debug("allocated %sinode 0x%llx.\n", + base_ni ? "extent " : "", (long long)bit); + vol->free_mft_records--; +out: + ntfs_log_leave("\n"); + return ni; + +undo_mftbmp_alloc: + err = errno; + if (ntfs_bitmap_clear_bit(mftbmp_na, bit)) + ntfs_log_error("Failed to clear bit in mft bitmap.%s\n", es); + errno = err; +err_out: + if (!errno) + errno = EIO; + ni = NULL; + goto out; +} + +/** + * ntfs_mft_record_free - free an mft record on an ntfs volume + * @vol: volume on which to free the mft record + * @ni: open ntfs inode of the mft record to free + * + * Free the mft record of the open inode @ni on the mounted ntfs volume @vol. + * Note that this function calls ntfs_inode_close() internally and hence you + * cannot use the pointer @ni any more after this function returns success. + * + * On success return 0 and on error return -1 with errno set to the error code. + */ +int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni) +{ + u64 mft_no; + int err; + u16 seq_no; + le16 old_seq_no; + + ntfs_log_trace("Entering for inode 0x%llx.\n", (long long) ni->mft_no); + + if (!vol || !vol->mftbmp_na || !ni) { + errno = EINVAL; + return -1; + } + + /* Cache the mft reference for later. */ + mft_no = ni->mft_no; + + /* Mark the mft record as not in use. */ + ni->mrec->flags &= ~MFT_RECORD_IN_USE; + + /* Increment the sequence number, skipping zero, if it is not zero. */ + old_seq_no = ni->mrec->sequence_number; + seq_no = le16_to_cpu(old_seq_no); + if (seq_no == 0xffff) + seq_no = 1; + else if (seq_no) + seq_no++; + ni->mrec->sequence_number = cpu_to_le16(seq_no); + + /* Set the inode dirty and write it out. */ + ntfs_inode_mark_dirty(ni); + if (ntfs_inode_sync(ni)) { + err = errno; + goto sync_rollback; + } + + /* Clear the bit in the $MFT/$BITMAP corresponding to this record. */ + if (ntfs_bitmap_clear_bit(vol->mftbmp_na, mft_no)) { + err = errno; + // FIXME: If ntfs_bitmap_clear_run() guarantees rollback on + // error, this could be changed to goto sync_rollback; + goto bitmap_rollback; + } + + /* Throw away the now freed inode. */ +#if CACHE_NIDATA_SIZE + if (!ntfs_inode_real_close(ni)) { +#else + if (!ntfs_inode_close(ni)) { +#endif + vol->free_mft_records++; + return 0; + } + err = errno; + + /* Rollback what we did... */ +bitmap_rollback: + if (ntfs_bitmap_set_bit(vol->mftbmp_na, mft_no)) + ntfs_log_debug("Eeek! Rollback failed in ntfs_mft_record_free(). " + "Leaving inconsistent metadata!\n"); +sync_rollback: + ni->mrec->flags |= MFT_RECORD_IN_USE; + ni->mrec->sequence_number = old_seq_no; + ntfs_inode_mark_dirty(ni); + errno = err; + return -1; +} + +/** + * ntfs_mft_usn_dec - Decrement USN by one + * @mrec: pointer to an mft record + * + * On success return 0 and on error return -1 with errno set. + */ +int ntfs_mft_usn_dec(MFT_RECORD *mrec) +{ + u16 usn; + le16 *usnp; + + if (!mrec) { + errno = EINVAL; + return -1; + } + usnp = (le16*)((char*)mrec + le16_to_cpu(mrec->usa_ofs)); + usn = le16_to_cpup(usnp); + if (usn-- <= 1) + usn = 0xfffe; + *usnp = cpu_to_le16(usn); + + return 0; +} + diff --git a/libcustomntfs/mft.h b/libcustomntfs/mft.h new file mode 100644 index 00000000..bb15f0f3 --- /dev/null +++ b/libcustomntfs/mft.h @@ -0,0 +1,132 @@ +/* + * mft.h - Exports for MFT record handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2002 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2006-2008 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_MFT_H +#define _NTFS_MFT_H + +#include "volume.h" +#include "inode.h" +#include "layout.h" +#include "logging.h" + +extern int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref, + const s64 count, MFT_RECORD *b); + +/** + * ntfs_mft_record_read - read a record from the mft + * @vol: volume to read from + * @mref: mft record number to read + * @b: output data buffer + * + * Read the mft record specified by @mref from volume @vol into buffer @b. + * Return 0 on success or -1 on error, with errno set to the error code. + * + * The read mft record is mst deprotected and is hence ready to use. The caller + * should check the record with is_baad_record() in case mst deprotection + * failed. + * + * NOTE: @b has to be at least of size vol->mft_record_size. + */ +static __inline__ int ntfs_mft_record_read(const ntfs_volume *vol, + const MFT_REF mref, MFT_RECORD *b) +{ + int ret; + + ntfs_log_enter("Entering for inode %lld\n", (long long)MREF(mref)); + ret = ntfs_mft_records_read(vol, mref, 1, b); + ntfs_log_leave("\n"); + return ret; +} + +extern int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref, + MFT_RECORD *m); + +extern int ntfs_file_record_read(const ntfs_volume *vol, const MFT_REF mref, + MFT_RECORD **mrec, ATTR_RECORD **attr); + +extern int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref, + const s64 count, MFT_RECORD *b); + +/** + * ntfs_mft_record_write - write an mft record to disk + * @vol: volume to write to + * @mref: mft record number to write + * @b: data buffer containing the mft record to write + * + * Write the mft record specified by @mref from buffer @b to volume @vol. + * Return 0 on success or -1 on error, with errno set to the error code. + * + * Before the mft record is written, it is mst protected. After the write, it + * is deprotected again, thus resulting in an increase in the update sequence + * number inside the buffer @b. + * + * NOTE: @b has to be at least of size vol->mft_record_size. + */ +static __inline__ int ntfs_mft_record_write(const ntfs_volume *vol, + const MFT_REF mref, MFT_RECORD *b) +{ + int ret; + + ntfs_log_enter("Entering for inode %lld\n", (long long)MREF(mref)); + ret = ntfs_mft_records_write(vol, mref, 1, b); + ntfs_log_leave("\n"); + return ret; +} + +/** + * ntfs_mft_record_get_data_size - return number of bytes used in mft record @b + * @m: mft record to get the data size of + * + * Takes the mft record @m and returns the number of bytes used in the record + * or 0 on error (i.e. @m is not a valid mft record). Zero is not a valid size + * for an mft record as it at least has to have the MFT_RECORD itself and a + * zero length attribute of type AT_END, thus making the minimum size 56 bytes. + * + * Aside: The size is independent of NTFS versions 1.x/3.x because the 8-byte + * alignment of the first attribute mask the difference in MFT_RECORD size + * between NTFS 1.x and 3.x. Also, you would expect every mft record to + * contain an update sequence array as well but that could in theory be + * non-existent (don't know if Windows' NTFS driver/chkdsk wouldn't view this + * as corruption in itself though). + */ +static __inline__ u32 ntfs_mft_record_get_data_size(const MFT_RECORD *m) +{ + if (!m || !ntfs_is_mft_record(m->magic)) + return 0; + /* Get the number of used bytes and return it. */ + return le32_to_cpu(m->bytes_in_use); +} + +extern int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, + MFT_RECORD *mrec); + +extern int ntfs_mft_record_format(const ntfs_volume *vol, const MFT_REF mref); + +extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni); + +extern int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni); + +extern int ntfs_mft_usn_dec(MFT_RECORD *mrec); + +#endif /* defined _NTFS_MFT_H */ + diff --git a/libcustomntfs/misc.c b/libcustomntfs/misc.c new file mode 100644 index 00000000..b2e17cbf --- /dev/null +++ b/libcustomntfs/misc.c @@ -0,0 +1,61 @@ +/** + * misc.c : miscellaneous : + * - dealing with errors in memory allocation + * + * Copyright (c) 2008 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "types.h" +#include "misc.h" +#include "logging.h" + +/** + * ntfs_calloc + * + * Return a pointer to the allocated memory or NULL if the request fails. + */ +void *ntfs_calloc(size_t size) +{ + void *p; + + p = calloc(1, size); + if (!p) + ntfs_log_perror("Failed to calloc %lld bytes", (long long)size); + return p; +} + +void *ntfs_malloc(size_t size) +{ + void *p; + + p = malloc(size); + if (!p) + ntfs_log_perror("Failed to malloc %lld bytes", (long long)size); + return p; +} diff --git a/libcustomntfs/misc.h b/libcustomntfs/misc.h new file mode 100644 index 00000000..a03e964e --- /dev/null +++ b/libcustomntfs/misc.h @@ -0,0 +1,30 @@ +/* + * misc.h : miscellaneous exports + * - memory allocation + * + * Copyright (c) 2008 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_MISC_H_ +#define _NTFS_MISC_H_ + +void *ntfs_calloc(size_t size); +void *ntfs_malloc(size_t size); + +#endif /* _NTFS_MISC_H_ */ + diff --git a/libcustomntfs/mst.c b/libcustomntfs/mst.c new file mode 100644 index 00000000..470942d6 --- /dev/null +++ b/libcustomntfs/mst.c @@ -0,0 +1,231 @@ +/** + * mst.c - Multi sector fixup handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2006-2009 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "mst.h" +#include "logging.h" + +/** + * ntfs_mst_post_read_fixup - deprotect multi sector transfer protected data + * @b: pointer to the data to deprotect + * @size: size in bytes of @b + * + * Perform the necessary post read multi sector transfer fixups and detect the + * presence of incomplete multi sector transfers. - In that case, overwrite the + * magic of the ntfs record header being processed with "BAAD" (in memory only!) + * and abort processing. + * + * Return 0 on success and -1 on error, with errno set to the error code. The + * following error codes are defined: + * EINVAL Invalid arguments or invalid NTFS record in buffer @b. + * EIO Multi sector transfer error was detected. Magic of the NTFS + * record in @b will have been set to "BAAD". + */ +int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size) +{ + u16 usa_ofs, usa_count, usn; + u16 *usa_pos, *data_pos; + + ntfs_log_trace("Entering\n"); + + /* Setup the variables. */ + usa_ofs = le16_to_cpu(b->usa_ofs); + /* Decrement usa_count to get number of fixups. */ + usa_count = le16_to_cpu(b->usa_count) - 1; + /* Size and alignment checks. */ + if (size & (NTFS_BLOCK_SIZE - 1) || usa_ofs & 1 || + (u32)(usa_ofs + (usa_count * 2)) > size || + (size >> NTFS_BLOCK_SIZE_BITS) != usa_count) { + errno = EINVAL; + ntfs_log_perror("%s: magic: 0x%08x size: %d usa_ofs: %d " + "usa_count: %d", __FUNCTION__, *(le32 *)b, + size, usa_ofs, usa_count); + return -1; + } + /* Position of usn in update sequence array. */ + usa_pos = (u16*)b + usa_ofs/sizeof(u16); + /* + * The update sequence number which has to be equal to each of the + * u16 values before they are fixed up. Note no need to care for + * endianness since we are comparing and moving data for on disk + * structures which means the data is consistent. - If it is + * consistency the wrong endianness it doesn't make any difference. + */ + usn = *usa_pos; + /* + * Position in protected data of first u16 that needs fixing up. + */ + data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + /* + * Check for incomplete multi sector transfer(s). + */ + while (usa_count--) { + if (*data_pos != usn) { + /* + * Incomplete multi sector transfer detected! )-: + * Set the magic to "BAAD" and return failure. + * Note that magic_BAAD is already converted to le32. + */ + errno = EIO; + ntfs_log_perror("Incomplete multi-sector transfer: " + "magic: 0x%08x size: %d usa_ofs: %d usa_count:" + " %d data: %d usn: %d", *(le32 *)b, size, + usa_ofs, usa_count, *data_pos, usn); + b->magic = magic_BAAD; + return -1; + } + data_pos += NTFS_BLOCK_SIZE/sizeof(u16); + } + /* Re-setup the variables. */ + usa_count = le16_to_cpu(b->usa_count) - 1; + data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + /* Fixup all sectors. */ + while (usa_count--) { + /* + * Increment position in usa and restore original data from + * the usa into the data buffer. + */ + *data_pos = *(++usa_pos); + /* Increment position in data as well. */ + data_pos += NTFS_BLOCK_SIZE/sizeof(u16); + } + return 0; +} + +/** + * ntfs_mst_pre_write_fixup - apply multi sector transfer protection + * @b: pointer to the data to protect + * @size: size in bytes of @b + * + * Perform the necessary pre write multi sector transfer fixup on the data + * pointer to by @b of @size. + * + * Return 0 if fixups applied successfully or -1 if no fixups were performed + * due to errors. In that case errno i set to the error code (EINVAL). + * + * NOTE: We consider the absence / invalidity of an update sequence array to + * mean error. This means that you have to create a valid update sequence + * array header in the ntfs record before calling this function, otherwise it + * will fail (the header needs to contain the position of the update sequence + * array together with the number of elements in the array). You also need to + * initialise the update sequence number before calling this function + * otherwise a random word will be used (whatever was in the record at that + * position at that time). + */ +int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) +{ + u16 usa_ofs, usa_count, usn; + u16 *usa_pos, *data_pos; + + ntfs_log_trace("Entering\n"); + + /* Sanity check + only fixup if it makes sense. */ + if (!b || ntfs_is_baad_record(b->magic) || + ntfs_is_hole_record(b->magic)) { + errno = EINVAL; + ntfs_log_perror("%s: bad argument", __FUNCTION__); + return -1; + } + /* Setup the variables. */ + usa_ofs = le16_to_cpu(b->usa_ofs); + /* Decrement usa_count to get number of fixups. */ + usa_count = le16_to_cpu(b->usa_count) - 1; + /* Size and alignment checks. */ + if (size & (NTFS_BLOCK_SIZE - 1) || usa_ofs & 1 || + (u32)(usa_ofs + (usa_count * 2)) > size || + (size >> NTFS_BLOCK_SIZE_BITS) != usa_count) { + errno = EINVAL; + ntfs_log_perror("%s", __FUNCTION__); + return -1; + } + /* Position of usn in update sequence array. */ + usa_pos = (u16*)((u8*)b + usa_ofs); + /* + * Cyclically increment the update sequence number + * (skipping 0 and -1, i.e. 0xffff). + */ + usn = le16_to_cpup(usa_pos) + 1; + if (usn == 0xffff || !usn) + usn = 1; + usn = cpu_to_le16(usn); + *usa_pos = usn; + /* Position in data of first u16 that needs fixing up. */ + data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + /* Fixup all sectors. */ + while (usa_count--) { + /* + * Increment the position in the usa and save the + * original data from the data buffer into the usa. + */ + *(++usa_pos) = *data_pos; + /* Apply fixup to data. */ + *data_pos = usn; + /* Increment position in data as well. */ + data_pos += NTFS_BLOCK_SIZE/sizeof(u16); + } + return 0; +} + +/** + * ntfs_mst_post_write_fixup - deprotect multi sector transfer protected data + * @b: pointer to the data to deprotect + * + * Perform the necessary post write multi sector transfer fixup, not checking + * for any errors, because we assume we have just used + * ntfs_mst_pre_write_fixup(), thus the data will be fine or we would never + * have gotten here. + */ +void ntfs_mst_post_write_fixup(NTFS_RECORD *b) +{ + u16 *usa_pos, *data_pos; + + u16 usa_ofs = le16_to_cpu(b->usa_ofs); + u16 usa_count = le16_to_cpu(b->usa_count) - 1; + + ntfs_log_trace("Entering\n"); + + /* Position of usn in update sequence array. */ + usa_pos = (u16*)b + usa_ofs/sizeof(u16); + + /* Position in protected data of first u16 that needs fixing up. */ + data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + + /* Fixup all sectors. */ + while (usa_count--) { + /* + * Increment position in usa and restore original data from + * the usa into the data buffer. + */ + *data_pos = *(++usa_pos); + + /* Increment position in data as well. */ + data_pos += NTFS_BLOCK_SIZE/sizeof(u16); + } +} + diff --git a/libcustomntfs/mst.h b/libcustomntfs/mst.h new file mode 100644 index 00000000..ca813821 --- /dev/null +++ b/libcustomntfs/mst.h @@ -0,0 +1,34 @@ +/* + * mst.h - Exports for multi sector transfer fixup functions. + * Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2002 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_MST_H +#define _NTFS_MST_H + +#include "types.h" +#include "layout.h" + +extern int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size); +extern int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size); +extern void ntfs_mst_post_write_fixup(NTFS_RECORD *b); + +#endif /* defined _NTFS_MST_H */ + diff --git a/libcustomntfs/ntfs.c b/libcustomntfs/ntfs.c new file mode 100644 index 00000000..c2421c25 --- /dev/null +++ b/libcustomntfs/ntfs.c @@ -0,0 +1,726 @@ +/** + * ntfs.c - Simple functionality for startup, mounting and unmounting of NTFS-based devices. + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "ntfs.h" +#include "ntfsinternal.h" +#include "ntfsfile.h" +#include "ntfsdir.h" +#include "gekko_io.h" +#include "cache.h" + +// NTFS device driver devoptab +static const devoptab_t devops_ntfs = { + NULL, /* Device name */ + sizeof (ntfs_file_state), + ntfs_open_r, + ntfs_close_r, + ntfs_write_r, + ntfs_read_r, + ntfs_seek_r, + ntfs_fstat_r, + ntfs_stat_r, + ntfs_link_r, + ntfs_unlink_r, + ntfs_chdir_r, + ntfs_rename_r, + ntfs_mkdir_r, + sizeof (ntfs_dir_state), + ntfs_diropen_r, + ntfs_dirreset_r, + ntfs_dirnext_r, + ntfs_dirclose_r, + ntfs_statvfs_r, + ntfs_ftruncate_r, + ntfs_fsync_r, + NULL /* Device data */ +}; + +void ntfsInit (void) +{ + static bool isInit = false; + + // Initialise ntfs-3g (if not already done so) + if (!isInit) { + isInit = true; + + // Set the log handler + #ifdef NTFS_ENABLE_LOG + ntfs_log_set_handler(ntfs_log_handler_stderr); + #else + ntfs_log_set_handler(ntfs_log_handler_null); + #endif + // Set our current local + ntfs_set_locale(); + + } + + return; +} + +int ntfsFindPartitions (const DISC_INTERFACE *interface, sec_t **partitions) +{ + MASTER_BOOT_RECORD mbr; + PARTITION_RECORD *partition = NULL; + sec_t partition_starts[NTFS_MAX_PARTITIONS] = {0}; + int partition_count = 0; + sec_t part_lba = 0; + int i; + + union { + u8 buffer[512]; + MASTER_BOOT_RECORD mbr; + EXTENDED_BOOT_RECORD ebr; + NTFS_BOOT_SECTOR boot; + } sector; + + // Sanity check + if (!interface) { + errno = EINVAL; + return -1; + } + if (!partitions) + return 0; + + // Initialise ntfs-3g + ntfsInit(); + + // Start the device and check that it is inserted + if (!interface->startup()) { + errno = EIO; + return -1; + } + if (!interface->isInserted()) { + return 0; + } + + // Read the first sector on the device + if (!interface->readSectors(0, 1, §or.buffer)) { + errno = EIO; + return -1; + } + + // If this is the devices master boot record + if (sector.mbr.signature == MBR_SIGNATURE) { + memcpy(&mbr, §or, sizeof(MASTER_BOOT_RECORD)); + ntfs_log_debug("Valid Master Boot Record found\n"); + + // Search the partition table for all NTFS partitions (max. 4 primary partitions) + for (i = 0; i < 4; i++) { + partition = &mbr.partitions[i]; + part_lba = le32_to_cpu(mbr.partitions[i].lba_start); + + ntfs_log_debug("Partition %i: %s, sector %d, type 0x%x\n", i + 1, + partition->status == PARTITION_STATUS_BOOTABLE ? "bootable (active)" : "non-bootable", + part_lba, partition->type); + + // Figure out what type of partition this is + switch (partition->type) { + + // Ignore empty partitions + case PARTITION_TYPE_EMPTY: + continue; + + // NTFS partition + case PARTITION_TYPE_NTFS: { + ntfs_log_debug("Partition %i: Claims to be NTFS\n", i + 1); + + // Read and validate the NTFS partition + if (interface->readSectors(part_lba, 1, §or)) { + if (sector.boot.oem_id == NTFS_OEM_ID) { + ntfs_log_debug("Partition %i: Valid NTFS boot sector found\n", i + 1); + if (partition_count < NTFS_MAX_PARTITIONS) { + partition_starts[partition_count] = part_lba; + partition_count++; + } + } else { + ntfs_log_debug("Partition %i: Invalid NTFS boot sector, not actually NTFS\n", i + 1); + } + } + + break; + + } + + // DOS 3.3+ or Windows 95 extended partition + case PARTITION_TYPE_DOS33_EXTENDED: + case PARTITION_TYPE_WIN95_EXTENDED: { + ntfs_log_debug("Partition %i: Claims to be Extended\n", i + 1); + + // Walk the extended partition chain, finding all NTFS partitions within it + sec_t ebr_lba = part_lba; + sec_t next_erb_lba = 0; + do { + + // Read and validate the extended boot record + if (interface->readSectors(ebr_lba + next_erb_lba, 1, §or)) { + if (sector.ebr.signature == EBR_SIGNATURE) { + ntfs_log_debug("Logical Partition @ %d: type 0x%x\n", ebr_lba + next_erb_lba, + sector.ebr.partition.status == PARTITION_STATUS_BOOTABLE ? "bootable (active)" : "non-bootable", + sector.ebr.partition.type); + + // Get the start sector of the current partition + // and the next extended boot record in the chain + part_lba = ebr_lba + next_erb_lba + le32_to_cpu(sector.ebr.partition.lba_start); + next_erb_lba = le32_to_cpu(sector.ebr.next_ebr.lba_start); + + // Check if this partition has a valid NTFS boot record + if (interface->readSectors(part_lba, 1, §or)) { + if (sector.boot.oem_id == NTFS_OEM_ID) { + ntfs_log_debug("Logical Partition @ %d: Valid NTFS boot sector found\n", part_lba); + if(sector.ebr.partition.type != PARTITION_TYPE_NTFS) { + ntfs_log_warning("Logical Partition @ %d: Is NTFS but type is 0x%x; 0x%x was expected\n", part_lba, sector.ebr.partition.type, PARTITION_TYPE_NTFS); + } + if (partition_count < NTFS_MAX_PARTITIONS) { + partition_starts[partition_count] = part_lba; + partition_count++; + } + } + } + + } else { + next_erb_lba = 0; + } + } + + } while (next_erb_lba); + + break; + + } + + // Unknown or unsupported partition type + default: { + + // Check if this partition has a valid NTFS boot record anyway, + // it might be misrepresented due to a lazy partition editor + if (interface->readSectors(part_lba, 1, §or)) { + if (sector.boot.oem_id == NTFS_OEM_ID) { + ntfs_log_debug("Partition %i: Valid NTFS boot sector found\n", i + 1); + if(partition->type != PARTITION_TYPE_NTFS) { + ntfs_log_warning("Partition %i: Is NTFS but type is 0x%x; 0x%x was expected\n", i + 1, partition->type, PARTITION_TYPE_NTFS); + } + if (partition_count < NTFS_MAX_PARTITIONS) { + partition_starts[partition_count] = part_lba; + partition_count++; + } + } + } + + break; + + } + + } + + } + + // Else it is assumed this device has no master boot record + } else { + ntfs_log_debug("No Master Boot Record was found!\n"); + + // As a last-ditched effort, search the first 64 sectors of the device for stray NTFS partitions + for (i = 0; i < 64; i++) { + if (interface->readSectors(i, 1, §or)) { + if (sector.boot.oem_id == NTFS_OEM_ID) { + ntfs_log_debug("Valid NTFS boot sector found at sector %d!\n", i); + if (partition_count < NTFS_MAX_PARTITIONS) { + partition_starts[partition_count] = i; + partition_count++; + } + } + } + } + + } + + // Shutdown the device + /*interface->shutdown();*/ + + // Return the found partitions (if any) + if (partition_count > 0) { + *partitions = (sec_t*)ntfs_alloc(sizeof(sec_t) * partition_count); + if (*partitions) { + memcpy(*partitions, &partition_starts, sizeof(sec_t) * partition_count); + return partition_count; + } + } + + return 0; +} + +int ntfsMountAll (ntfs_md **mounts, u32 flags) +{ + const INTERFACE_ID *discs = ntfsGetDiscInterfaces(); + const INTERFACE_ID *disc = NULL; + ntfs_md mount_points[NTFS_MAX_MOUNTS]; + sec_t *partitions = NULL; + int mount_count = 0; + int partition_count = 0; + char name[128]; + int i, j, k; + + // Initialise ntfs-3g + ntfsInit(); + + // Find and mount all NTFS partitions on all known devices + for (i = 0; discs[i].name != NULL && discs[i].interface != NULL; i++) { + disc = &discs[i]; + partition_count = ntfsFindPartitions(disc->interface, &partitions); + if (partition_count > 0 && partitions) { + for (j = 0, k = 0; j < partition_count; j++) { + + // Find the next unused mount name + do { + sprintf(name, "%s%i", NTFS_MOUNT_PREFIX, k++); + if (k >= NTFS_MAX_MOUNTS) { + ntfs_free(partitions); + errno = EADDRNOTAVAIL; + return -1; + } + } while (ntfsGetDevice(name, false)); + + // Mount the partition + if (mount_count < NTFS_MAX_MOUNTS) { + if (ntfsMount(name, disc->interface, partitions[j], CACHE_DEFAULT_PAGE_SIZE, CACHE_DEFAULT_PAGE_COUNT, flags)) { + strcpy(mount_points[mount_count].name, name); + mount_points[mount_count].interface = disc->interface; + mount_points[mount_count].startSector = partitions[j]; + mount_count++; + } + } + + } + ntfs_free(partitions); + } + } + + // Return the mounts (if any) + if (mount_count > 0 && mounts) { + *mounts = (ntfs_md*)ntfs_alloc(sizeof(ntfs_md) * mount_count); + if (*mounts) { + memcpy(*mounts, &mount_points, sizeof(ntfs_md) * mount_count); + return mount_count; + } + } + + return 0; +} + +int ntfsMountDevice (const DISC_INTERFACE *interface, ntfs_md **mounts, u32 flags) +{ + const INTERFACE_ID *discs = ntfsGetDiscInterfaces(); + const INTERFACE_ID *disc = NULL; + ntfs_md mount_points[NTFS_MAX_MOUNTS]; + sec_t *partitions = NULL; + int mount_count = 0; + int partition_count = 0; + char name[128]; + int i, j, k; + + // Sanity check + if (!interface) { + errno = EINVAL; + return -1; + } + + // Initialise ntfs-3g + ntfsInit(); + + // Find the specified device then find and mount all NTFS partitions on it + for (i = 0; discs[i].name != NULL && discs[i].interface != NULL; i++) { + if (discs[i].interface == interface) { + disc = &discs[i]; + partition_count = ntfsFindPartitions(disc->interface, &partitions); + if (partition_count > 0 && partitions) { + for (j = 0, k = 0; j < partition_count; j++) { + + // Find the next unused mount name + do { + sprintf(name, "%s%i", NTFS_MOUNT_PREFIX, k++); + if (k >= NTFS_MAX_MOUNTS) { + ntfs_free(partitions); + errno = EADDRNOTAVAIL; + return -1; + } + } while (ntfsGetDevice(name, false)); + + // Mount the partition + if (mount_count < NTFS_MAX_MOUNTS) { + if (ntfsMount(name, disc->interface, partitions[j], CACHE_DEFAULT_PAGE_SIZE, CACHE_DEFAULT_PAGE_COUNT, flags)) { + strcpy(mount_points[mount_count].name, name); + mount_points[mount_count].interface = disc->interface; + mount_points[mount_count].startSector = partitions[j]; + mount_count++; + } + } + + } + ntfs_free(partitions); + } + break; + } + } + + // If we couldn't find the device then return with error status + if (!disc) { + errno = ENODEV; + return -1; + } + + // Return the mounts (if any) + if (mount_count > 0 && mounts) { + *mounts = (ntfs_md*)ntfs_alloc(sizeof(ntfs_md) * mount_count); + if (*mounts) { + memcpy(*mounts, &mount_points, sizeof(ntfs_md) * mount_count); + return mount_count; + } + } + + return 0; +} + +bool ntfsMount (const char *name, const DISC_INTERFACE *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags) +{ + ntfs_vd *vd = NULL; + gekko_fd *fd = NULL; + + // Sanity check + if (!name || !interface) { + errno = EINVAL; + return false; + } + + // Initialise ntfs-3g + ntfsInit(); + + // Check that the requested mount name is free + if (ntfsGetDevice(name, false)) { + errno = EADDRINUSE; + return false; + } + + // Check that we can at least read from this device + if (!(interface->features & FEATURE_MEDIUM_CANREAD)) { + errno = EPERM; + return false; + } + + // Allocate the volume descriptor + vd = (ntfs_vd*)ntfs_alloc(sizeof(ntfs_vd)); + if (!vd) { + errno = ENOMEM; + return false; + } + + // Setup the volume descriptor + vd->id = interface->ioType; + vd->flags = 0; + vd->uid = 0; + vd->gid = 0; + vd->fmask = 0; + vd->dmask = 0; + vd->atime = ((flags & NTFS_UPDATE_ACCESS_TIMES) ? ATIME_ENABLED : ATIME_DISABLED); + vd->showHiddenFiles = (flags & NTFS_SHOW_HIDDEN_FILES); + vd->showSystemFiles = (flags & NTFS_SHOW_SYSTEM_FILES); + + // Allocate the device driver descriptor + fd = (gekko_fd*)ntfs_alloc(sizeof(gekko_fd)); + if (!fd) { + ntfs_free(vd); + errno = ENOMEM; + return false; + } + + // Setup the device driver descriptor + fd->interface = interface; + fd->startSector = startSector; + fd->sectorSize = 0; + fd->sectorCount = 0; + fd->cachePageCount = cachePageCount; + fd->cachePageSize = cachePageSize; + + // Allocate the device driver + vd->dev = ntfs_device_alloc(name, 0, &ntfs_device_gekko_io_ops, fd); + if (!vd->dev) { + ntfs_free(fd); + ntfs_free(vd); + return false; + } + + // Build the mount flags + if (flags & NTFS_READ_ONLY) + vd->flags |= MS_RDONLY; + else + { + if (!(interface->features & FEATURE_MEDIUM_CANWRITE)) + vd->flags |= MS_RDONLY; + if ((interface->features & FEATURE_MEDIUM_CANREAD) && (interface->features & FEATURE_MEDIUM_CANWRITE)) + vd->flags |= MS_EXCLUSIVE; + } + if (flags & NTFS_RECOVER) + vd->flags |= MS_RECOVER; + if (flags & NTFS_IGNORE_HIBERFILE) + vd->flags |= MS_IGNORE_HIBERFILE; + + if (vd->flags & MS_RDONLY) + ntfs_log_debug("Mounting \"%s\" as read-only\n", name); + + // Mount the device + vd->vol = ntfs_device_mount(vd->dev, vd->flags); + if (!vd->vol) { + switch(ntfs_volume_error(errno)) { + case NTFS_VOLUME_NOT_NTFS: errno = EINVALPART; break; + case NTFS_VOLUME_CORRUPT: errno = EINVALPART; break; + case NTFS_VOLUME_HIBERNATED: errno = EHIBERNATED; break; + case NTFS_VOLUME_UNCLEAN_UNMOUNT: errno = EDIRTY; break; + default: errno = EINVAL; break; + } + ntfs_device_free(vd->dev); + ntfs_free(vd); + return false; + } + + if (flags & NTFS_IGNORE_CASE) + ntfs_set_ignore_case(vd->vol); + + // Initialise the volume descriptor + if (ntfsInitVolume(vd)) { + ntfs_umount(vd->vol, true); + ntfs_free(vd); + return false; + } + + // Add the device to the devoptab table + if (ntfsAddDevice(name, vd)) { + ntfsDeinitVolume(vd); + ntfs_umount(vd->vol, true); + ntfs_free(vd); + return false; + } + + return true; +} + +void ntfsUnmount (const char *name, bool force) +{ + ntfs_vd *vd = NULL; + + // Get the devices volume descriptor + vd = ntfsGetVolume(name); + if (!vd) + return; + + // Remove the device from the devoptab table + ntfsRemoveDevice(name); + + // Deinitialise the volume descriptor + ntfsDeinitVolume(vd); + + // Unmount the volume + ntfs_umount(vd->vol, force); + + // Free the volume descriptor + ntfs_free(vd); + + return; +} + +const char *ntfsGetVolumeName (const char *name) +{ + ntfs_vd *vd = NULL; + //ntfs_attr *na = NULL; + //ntfschar *ulabel = NULL; + //char *volumeName = NULL; + + // Sanity check + if (!name) { + errno = EINVAL; + return NULL; + } + + // Get the devices volume descriptor + vd = ntfsGetVolume(name); + if (!vd) { + errno = ENODEV; + return NULL; + } + return vd->vol->vol_name; +/* + + // If the volume name has already been cached then just use that + if (vd->name[0]) + return vd->name; + + // Lock + ntfsLock(vd); + + // Check if the volume name attribute exists + na = ntfs_attr_open(vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0); + if (!na) { + ntfsUnlock(vd); + errno = ENOENT; + return false; + } + + // Allocate a buffer to store the raw volume name + ulabel = ntfs_alloc(na->data_size * sizeof(ntfschar)); + if (!ulabel) { + ntfsUnlock(vd); + errno = ENOMEM; + return false; + } + + // Read the volume name + if (ntfs_attr_pread(na, 0, na->data_size, ulabel) != na->data_size) { + ntfs_free(ulabel); + ntfsUnlock(vd); + errno = EIO; + return false; + } + + // Convert the volume name to the current local + if (ntfsUnicodeToLocal(ulabel, na->data_size, &volumeName, 0) < 0) { + errno = EINVAL; + ntfs_free(ulabel); + ntfsUnlock(vd); + return false; + } + + // If the volume name was read then cache it (for future fetches) + if (volumeName) + strcpy(vd->name, volumeName); + + // Close the volume name attribute + if (na) + ntfs_attr_close(na); + + // Clean up + ntfs_free(volumeName); + ntfs_free(ulabel); + + // Unlock + ntfsUnlock(vd); + + return vd->name; +*/ +} + +bool ntfsSetVolumeName (const char *name, const char *volumeName) +{ + ntfs_vd *vd = NULL; + ntfs_attr *na = NULL; + ntfschar *ulabel = NULL; + int ulabel_len; + + // Sanity check + if (!name) { + errno = EINVAL; + return false; + } + + // Get the devices volume descriptor + vd = ntfsGetVolume(name); + if (!vd) { + errno = ENODEV; + return false; + } + + // Lock + ntfsLock(vd); + + // Convert the new volume name to unicode + ulabel_len = ntfsLocalToUnicode(volumeName, &ulabel) * sizeof(ntfschar); + if (ulabel_len < 0) { + ntfsUnlock(vd); + errno = EINVAL; + return false; + } + + // Check if the volume name attribute exists + na = ntfs_attr_open(vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0); + if (na) { + + // It does, resize it to match the length of the new volume name + if (ntfs_attr_truncate(na, ulabel_len)) { + ntfs_free(ulabel); + ntfsUnlock(vd); + return false; + } + + // Write the new volume name + if (ntfs_attr_pwrite(na, 0, ulabel_len, ulabel) != ulabel_len) { + ntfs_free(ulabel); + ntfsUnlock(vd); + return false; + } + + } else { + + // It doesn't, create it now + if (ntfs_attr_add(vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0, (u8*)ulabel, ulabel_len)) { + ntfs_free(ulabel); + ntfsUnlock(vd); + return false; + } + + } + + // Reset the volumes name cache (as it has now been changed) + vd->name[0] = '\0'; + + // Close the volume name attribute + if (na) + ntfs_attr_close(na); + + // Sync the volume node + if (ntfs_inode_sync(vd->vol->vol_ni)) { + ntfs_free(ulabel); + ntfsUnlock(vd); + return false; + } + + // Clean up + ntfs_free(ulabel); + + // Unlock + ntfsUnlock(vd); + + return true; +} + +const devoptab_t *ntfsGetDevOpTab (void) +{ + return &devops_ntfs; +} diff --git a/libcustomntfs/ntfs.h b/libcustomntfs/ntfs.h new file mode 100644 index 00000000..22474232 --- /dev/null +++ b/libcustomntfs/ntfs.h @@ -0,0 +1,147 @@ +/** + * ntfs.h - Simple functionality for startup, mounting and unmounting of NTFS-based devices. + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _LIBNTFS_H +#define _LIBNTFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* NTFS errno values */ +#define ENOPART 3000 /* No partition was found */ +#define EINVALPART 3001 /* Specified partition is invalid or not supported */ +#define EDIRTY 3002 /* Volume is dirty and NTFS_RECOVER was not specified during mount */ +#define EHIBERNATED 3003 /* Volume is hibernated and NTFS_IGNORE_HIBERFILE was not specified during mount */ + +/* NTFS cache options */ +#define CACHE_DEFAULT_PAGE_COUNT 8 /* The default number of pages in the cache */ +#define CACHE_DEFAULT_PAGE_SIZE 128 /* The default number of sectors per cache page */ + +/* NTFS mount flags */ +#define NTFS_DEFAULT 0x00000000 /* Standard mount, expects a clean, non-hibernated volume */ +#define NTFS_SHOW_HIDDEN_FILES 0x00000001 /* Display hidden files when enumerating directories */ +#define NTFS_SHOW_SYSTEM_FILES 0x00000002 /* Display system files when enumerating directories */ +#define NTFS_UPDATE_ACCESS_TIMES 0x00000004 /* Update file and directory access times */ +#define NTFS_RECOVER 0x00000008 /* Reset $LogFile if dirty (i.e. from unclean disconnect) */ +#define NTFS_IGNORE_HIBERFILE 0x00000010 /* Mount even if volume is hibernated */ +#define NTFS_READ_ONLY 0x00000020 /* Mount in read only mode */ +#define NTFS_IGNORE_CASE 0x00000040 /* Ignore case sensitivity. Everything must be and will be provided in lowercase. */ +#define NTFS_SU NTFS_SHOW_HIDDEN_FILES | NTFS_SHOW_SYSTEM_FILES +#define NTFS_FORCE NTFS_RECOVER | NTFS_IGNORE_HIBERFILE + +/** + * ntfs_md - NTFS mount descriptor + */ +typedef struct _ntfs_md { + char name[32]; /* Mount name (can be accessed as "name:/") */ + const DISC_INTERFACE *interface; /* Block device containing the mounted partition */ + sec_t startSector; /* Local block address to first sector of partition */ +} ntfs_md; + +/** + * Find all NTFS partitions on a block device. + * + * @param INTERFACE The block device to search + * @param PARTITIONS (out) A pointer to receive the array of partition start sectors + * + * @return The number of entries in PARTITIONS or -1 if an error occurred (see errno) + * @note The caller is responsible for freeing PARTITIONS when finished with it + */ +extern int ntfsFindPartitions (const DISC_INTERFACE *interface, sec_t **partitions); + +/** + * Mount all NTFS partitions on all inserted block devices. + * + * @param MOUNTS (out) A pointer to receive the array of mount descriptors + * @param FLAGS Additional mounting flags. (see above) + * + * @return The number of entries in MOUNTS or -1 if an error occurred (see errno) + * @note The caller is responsible for freeing MOUNTS when finished with it + * @note All device caches are setup using default values (see above) + */ +extern int ntfsMountAll (ntfs_md **mounts, u32 flags); + +/** + * Mount all NTFS partitions on a block devices. + * + * @param INTERFACE The block device to mount. + * @param MOUNTS (out) A pointer to receive the array of mount descriptors + * @param FLAGS Additional mounting flags. (see above) + * + * @return The number of entries in MOUNTS or -1 if an error occurred (see errno) + * @note The caller is responsible for freeing MOUNTS when finished with it + * @note The device cache is setup using default values (see above) + */ +extern int ntfsMountDevice (const DISC_INTERFACE* interface, ntfs_md **mounts, u32 flags); + +/** + * Mount a NTFS partition from a specific sector on a block device. + * + * @param NAME The name to mount the device under (can then be accessed as "NAME:/") + * @param INTERFACE The block device to mount + * @param STARTSECTOR The sector the partition begins at (see @ntfsFindPartitions) + * @param CACHEPAGECOUNT The total number of pages in the device cache + * @param CACHEPAGESIZE The number of sectors per cache page + * @param FLAGS Additional mounting flags (see above) + * + * @return True if mount was successful, false if no partition was found or an error occurred (see errno) + * @note ntfsFindPartitions should be used first to locate the partitions start sector + */ +extern bool ntfsMount (const char *name, const DISC_INTERFACE *interface, sec_t startSector, u32 cachePageCount, u32 cachePageSize, u32 flags); + +/** + * Unmount a NTFS partition. + * + * @param NAME The name of mount used in ntfsMountSimple() and ntfsMount() + * @param FORCE If true unmount even if the device is busy (may lead to data lose) + */ +extern void ntfsUnmount (const char *name, bool force); + +/** + * Get the volume name of a mounted NTFS partition. + * + * @param NAME The name of mount (see @ntfsMountAll, @ntfsMountDevice, and @ntfsMount) + * + * @return The volumes name if successful or NULL if an error occurred (see errno) + */ +extern const char *ntfsGetVolumeName (const char *name); + +/** + * Set the volume name of a mounted NTFS partition. + * + * @param NAME The name of mount (see @ntfsMountAll, @ntfsMountDevice, and @ntfsMount) + * @param VOLUMENAME The new volume name + * + * @return True if mount was successful, false if an error occurred (see errno) + * @note The mount must be write-enabled else this will fail + */ +extern bool ntfsSetVolumeName (const char *name, const char *volumeName); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBNTFS_H */ diff --git a/libcustomntfs/ntfsdir.c b/libcustomntfs/ntfsdir.c new file mode 100644 index 00000000..ad54b514 --- /dev/null +++ b/libcustomntfs/ntfsdir.c @@ -0,0 +1,636 @@ +/** + * ntfs_dir.c - devoptab directory 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "ntfsinternal.h" +#include "ntfsdir.h" +#include "device.h" +#include + +#define STATE(x) ((ntfs_dir_state*)(x)->dirStruct) + +void ntfsCloseDir (ntfs_dir_state *dir) +{ + // Sanity check + if (!dir || !dir->vd) + return; + + // Free the directory entries (if any) + while (dir->first) { + ntfs_dir_entry *next = dir->first->next; + ntfs_free(dir->first->name); + ntfs_free(dir->first); + dir->first = next; + } + + // Close the directory (if open) + if (dir->ni) + ntfsCloseEntry(dir->vd, dir->ni); + + // Reset the directory state + dir->ni = NULL; + dir->first = NULL; + dir->current = NULL; + + return; +} + +int ntfs_stat_r (struct _reent *r, const char *path, struct stat *st) +{ + // Short circuit cases were we don't actually have to do anything + if (!st || !path) + return 0; + + ntfs_log_trace("path %s, st %p\n", path, st); + + ntfs_vd *vd = NULL; + ntfs_inode *ni = NULL; + + // Get the volume descriptor for this path + vd = ntfsGetVolume(path); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + if(strcmp(path, ".") == 0 || strcmp(path, "..") == 0) + { + memset(st, 0, sizeof(struct stat)); + st->st_mode = S_IFDIR; + return 0; + } + + // Lock + ntfsLock(vd); + + // Find the entry + ni = ntfsOpenEntry(vd, path); + if (!ni) { + r->_errno = errno; + ntfsUnlock(vd); + return -1; + } + + // Get the entry stats + int ret = ntfsStat(vd, ni, st); + if (ret) + r->_errno = errno; + + // Close the entry + ntfsCloseEntry(vd, ni); + + ntfsUnlock(vd); + + return 0; +} + +int ntfs_link_r (struct _reent *r, const char *existing, const char *newLink) +{ + ntfs_log_trace("existing %s, newLink %s\n", existing, newLink); + + ntfs_vd *vd = NULL; + ntfs_inode *ni = NULL; + + // Get the volume descriptor for this path + vd = ntfsGetVolume(existing); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ntfsLock(vd); + + // Create a symbolic link between the two paths + ni = ntfsCreate(vd, existing, S_IFLNK, newLink); + if (!ni) { + ntfsUnlock(vd); + r->_errno = errno; + return -1; + } + + // Close the symbolic link + ntfsCloseEntry(vd, ni); + + // Unlock + ntfsUnlock(vd); + + return 0; +} + +int ntfs_unlink_r (struct _reent *r, const char *name) +{ + ntfs_log_trace("name %s\n", name); + + // Unlink the entry + int ret = ntfsUnlink(ntfsGetVolume(name), name); + if (ret) + r->_errno = errno; + + return ret; +} + +int ntfs_chdir_r (struct _reent *r, const char *name) +{ + ntfs_log_trace("name %s\n", name); + + ntfs_vd *vd = NULL; + ntfs_inode *ni = NULL; + + // Get the volume descriptor for this path + vd = ntfsGetVolume(name); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ntfsLock(vd); + + // Find the directory + ni = ntfsOpenEntry(vd, name); + if (!ni) { + ntfsUnlock(vd); + r->_errno = ENOENT; + return -1; + } + + // Ensure that this directory is indeed a directory + if (!(ni->mrec->flags && MFT_RECORD_IS_DIRECTORY)) { + ntfsCloseEntry(vd, ni); + ntfsUnlock(vd); + r->_errno = ENOTDIR; + return -1; + } + + // Close the old current directory (if any) + if (vd->cwd_ni) + ntfsCloseEntry(vd, vd->cwd_ni); + + // Set the new current directory + vd->cwd_ni = ni; + + // Unlock + ntfsUnlock(vd); + + return 0; +} + +int ntfs_rename_r (struct _reent *r, const char *oldName, const char *newName) +{ + ntfs_log_trace("oldName %s, newName %s\n", oldName, newName); + + ntfs_vd *vd = NULL; + ntfs_inode *ni = NULL; + + // Get the volume descriptor for this path + vd = ntfsGetVolume(oldName); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ntfsLock(vd); + + // You cannot rename between devices + if(vd != ntfsGetVolume(newName)) { + ntfsUnlock(vd); + r->_errno = EXDEV; + return -1; + } + + // Check that there is no existing entry with the new name + ni = ntfsOpenEntry(vd, newName); + if (ni) { + ntfsCloseEntry(vd, ni); + ntfsUnlock(vd); + r->_errno = EEXIST; + return -1; + } + + // Link the old entry with the new one + if (ntfsLink(vd, oldName, newName)) { + ntfsUnlock(vd); + return -1; + } + + // Unlink the old entry + if (ntfsUnlink(vd, oldName)) { + if (ntfsUnlink(vd, newName)) { + ntfsUnlock(vd); + return -1; + } + ntfsUnlock(vd); + return -1; + } + + // Unlock + ntfsUnlock(vd); + + return 0; +} + +int ntfs_mkdir_r (struct _reent *r, const char *path, int mode) +{ + ntfs_log_trace("path %s, mode %i\n", path, mode); + + ntfs_vd *vd = NULL; + ntfs_inode *ni = NULL; + + // Get the volume descriptor for this path + vd = ntfsGetVolume(path); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ntfsLock(vd); + + // Create the directory + ni = ntfsCreate(vd, path, S_IFDIR, NULL); + if (!ni) { + ntfsUnlock(vd); + r->_errno = errno; + return -1; + } + + // Close the directory + ntfsCloseEntry(vd, ni); + + // Unlock + ntfsUnlock(vd); + + return 0; +} + +int ntfs_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) +{ + ntfs_log_trace("path %s, buf %p\n", path, buf); + + ntfs_vd *vd = NULL; + s64 size; + int delta_bits; + + // Get the volume descriptor for this path + vd = ntfsGetVolume(path); + if (!vd) { + r->_errno = ENODEV; + return -1; + } + + // Short circuit cases were we don't actually have to do anything + if (!buf) + return 0; + + // Lock + ntfsLock(vd); + + // Zero out the stat buffer + memset(buf, 0, sizeof(struct statvfs)); + + if(ntfs_volume_get_free_space(vd->vol) < 0) + { + ntfsUnlock(vd); + return -1; + } + + // File system block size + buf->f_bsize = vd->vol->cluster_size; + + // Fundamental file system block size + buf->f_frsize = vd->vol->cluster_size; + + // Total number of blocks on file system in units of f_frsize + buf->f_blocks = vd->vol->nr_clusters; + + // Free blocks available for all and for non-privileged processes + size = MAX(vd->vol->free_clusters, 0); + buf->f_bfree = buf->f_bavail = size; + + // Free inodes on the free space + delta_bits = vd->vol->cluster_size_bits - vd->vol->mft_record_size_bits; + if (delta_bits >= 0) + size <<= delta_bits; + else + size >>= -delta_bits; + + // Number of inodes at this point in time + buf->f_files = (vd->vol->mftbmp_na->allocated_size << 3) + size; + + // Free inodes available for all and for non-privileged processes + size += vd->vol->free_mft_records; + buf->f_ffree = buf->f_favail = MAX(size, 0); + + // File system id + buf->f_fsid = vd->id; + + // Bit mask of f_flag values. + buf->f_flag = (NVolReadOnly(vd->vol) ? ST_RDONLY : 0); + + // Maximum length of filenames + buf->f_namemax = NTFS_MAX_NAME_LEN; + + // Unlock + ntfsUnlock(vd); + + return 0; +} + +/** + * PRIVATE: Callback for directory walking + */ +int ntfs_readdir_filler (DIR_ITER *dirState, const ntfschar *name, const int name_len, const int name_type, + const s64 pos, const MFT_REF mref, const unsigned dt_type) +{ + ntfs_dir_state *dir = STATE(dirState); + ntfs_dir_entry *entry = NULL; + char *entry_name = NULL; + + // Sanity check + if (!dir || !dir->vd) { + errno = EINVAL; + return -1; + } + + // Ignore DOS file names + if (name_type == FILE_NAME_DOS) { + return 0; + } + + // Preliminary check that this entry can be enumerated (as described by the volume descriptor) + if (MREF(mref) == FILE_root || MREF(mref) >= FILE_first_user || dir->vd->showSystemFiles) { + + // Convert the entry name to our current local + if (ntfsUnicodeToLocal(name, name_len, &entry_name, 0) < 0) { + return -1; + } + + if(dir->first && dir->first->mref == FILE_root && + MREF(mref) == FILE_root && strcmp(entry_name, "..") == 0) + { + return 0; + } + + // If this is not the parent or self directory reference + if ((strcmp(entry_name, ".") != 0) && (strcmp(entry_name, "..") != 0)) { + + // Open the entry + ntfs_inode *ni = ntfs_pathname_to_inode(dir->vd->vol, dir->ni, entry_name); + if (!ni) + return -1; + + // Double check that this entry can be emuerated (as described by the volume descriptor) + if (((ni->flags & FILE_ATTR_HIDDEN) && !dir->vd->showHiddenFiles) || + ((ni->flags & FILE_ATTR_SYSTEM) && !dir->vd->showSystemFiles)) { + ntfs_inode_close(ni); + return 0; + } + + // Close the entry + ntfs_inode_close(ni); + + } + + // Allocate a new directory entry + entry = (ntfs_dir_entry *) ntfs_alloc(sizeof(ntfs_dir_entry)); + if (!entry) + return -1; + + // Setup the entry + entry->name = entry_name; + entry->next = NULL; + entry->mref = MREF(mref); + + // Link the entry to the directory + if (!dir->first) { + dir->first = entry; + } else { + ntfs_dir_entry *last = dir->first; + while (last->next) last = last->next; + last->next = entry; + } + + } + + return 0; +} + +DIR_ITER *ntfs_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path) +{ + ntfs_log_trace("dirState %p, path %s\n", dirState, path); + + ntfs_dir_state* dir = STATE(dirState); + s64 position = 0; + + // Get the volume descriptor for this path + dir->vd = ntfsGetVolume(path); + if (!dir->vd) { + r->_errno = ENODEV; + return NULL; + } + + // Lock + ntfsLock(dir->vd); + + // Find the directory + dir->ni = ntfsOpenEntry(dir->vd, path); + if (!dir->ni) { + ntfsUnlock(dir->vd); + r->_errno = ENOENT; + return NULL; + } + + // Ensure that this directory is indeed a directory + if (!(dir->ni->mrec->flags && MFT_RECORD_IS_DIRECTORY)) { + ntfsCloseEntry(dir->vd, dir->ni); + ntfsUnlock(dir->vd); + r->_errno = ENOTDIR; + return NULL; + } + + // Read the directory + dir->first = dir->current = NULL; + if (ntfs_readdir(dir->ni, &position, dirState, (ntfs_filldir_t)ntfs_readdir_filler)) { + ntfsCloseDir(dir); + ntfsUnlock(dir->vd); + r->_errno = errno; + return NULL; + } + + // Move to the first entry in the directory + dir->current = dir->first; + + // Update directory times + ntfsUpdateTimes(dir->vd, dir->ni, NTFS_UPDATE_ATIME); + + // Insert the directory into the double-linked FILO list of open directories + if (dir->vd->firstOpenDir) { + dir->nextOpenDir = dir->vd->firstOpenDir; + dir->vd->firstOpenDir->prevOpenDir = dir; + } else { + dir->nextOpenDir = NULL; + } + dir->prevOpenDir = NULL; + dir->vd->cwd_ni = dir->ni; + dir->vd->firstOpenDir = dir; + dir->vd->openDirCount++; + + // Unlock + ntfsUnlock(dir->vd); + + return dirState; +} + +int ntfs_dirreset_r (struct _reent *r, DIR_ITER *dirState) +{ + ntfs_log_trace("dirState %p\n", dirState); + + ntfs_dir_state* dir = STATE(dirState); + + // Sanity check + if (!dir || !dir->vd || !dir->ni) { + r->_errno = EBADF; + return -1; + } + + // Lock + ntfsLock(dir->vd); + + // Move to the first entry in the directory + dir->current = dir->first; + + // Update directory times + ntfsUpdateTimes(dir->vd, dir->ni, NTFS_UPDATE_ATIME); + + // Unlock + ntfsUnlock(dir->vd); + + return 0; +} + +int ntfs_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) +{ + ntfs_log_trace("dirState %p, filename %p, filestat %p\n", dirState, filename, filestat); + + ntfs_dir_state* dir = STATE(dirState); + ntfs_inode *ni = NULL; + + // Sanity check + if (!dir || !dir->vd || !dir->ni) { + r->_errno = EBADF; + return -1; + } + + // Lock + ntfsLock(dir->vd); + + // Check that there is a entry waiting to be fetched + if (!dir->current) { + ntfsUnlock(dir->vd); + r->_errno = ENOENT; + return -1; + } + + // Fetch the current entry + strcpy(filename, dir->current->name); + if(filestat != NULL) + { + if(strcmp(dir->current->name, ".") == 0 || strcmp(dir->current->name, "..") == 0) + { + memset(filestat, 0, sizeof(struct stat)); + filestat->st_mode = S_IFDIR; + } + else + { + ni = ntfsOpenEntry(dir->vd, dir->current->name); + if (ni) { + ntfsStat(dir->vd, ni, filestat); + ntfsCloseEntry(dir->vd, ni); + } + } + } + + // Move to the next entry in the directory + dir->current = dir->current->next; + + // Update directory times + ntfsUpdateTimes(dir->vd, dir->ni, NTFS_UPDATE_ATIME); + + // Unlock + ntfsUnlock(dir->vd); + + return 0; +} + +int ntfs_dirclose_r (struct _reent *r, DIR_ITER *dirState) +{ + ntfs_log_trace("dirState %p\n", dirState); + + ntfs_dir_state* dir = STATE(dirState); + + // Sanity check + if (!dir || !dir->vd) { + r->_errno = EBADF; + return -1; + } + + // Lock + ntfsLock(dir->vd); + + // Close the directory + ntfsCloseDir(dir); + + // Remove the directory from the double-linked FILO list of open directories + dir->vd->openDirCount--; + if (dir->nextOpenDir) + dir->nextOpenDir->prevOpenDir = dir->prevOpenDir; + if (dir->prevOpenDir) + dir->prevOpenDir->nextOpenDir = dir->nextOpenDir; + else + dir->vd->firstOpenDir = dir->nextOpenDir; + + // Unlock + ntfsUnlock(dir->vd); + + return 0; +} diff --git a/libcustomntfs/ntfsdir.h b/libcustomntfs/ntfsdir.h new file mode 100644 index 00000000..0550592f --- /dev/null +++ b/libcustomntfs/ntfsdir.h @@ -0,0 +1,68 @@ +/** + * ntfs_dir.c - devoptab directory routines for NTFS-based devices. + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFSDIR_H +#define _NTFSDIR_H + +#include "ntfsinternal.h" +#include + +/** + * ntfs_dir_entry - Directory entry + */ +typedef struct _ntfs_dir_entry { + char *name; + u64 mref; + struct _ntfs_dir_entry *next; +} ntfs_dir_entry; + +/** + * ntfs_dir_state - Directory state + */ +typedef struct _ntfs_dir_state { + ntfs_vd *vd; /* Volume this directory belongs to */ + ntfs_inode *ni; /* Directory descriptor */ + ntfs_dir_entry *first; /* The first entry in the directory */ + ntfs_dir_entry *current; /* The current entry in the directory */ + struct _ntfs_dir_state *prevOpenDir; /* The previous entry in a double-linked FILO list of open directories */ + struct _ntfs_dir_state *nextOpenDir; /* The next entry in a double-linked FILO list of open directories */ +} ntfs_dir_state; + +/* Directory state routines */ +void ntfsCloseDir (ntfs_dir_state *file); + +/* Gekko devoptab directory routines for NTFS-based devices */ +extern int ntfs_stat_r (struct _reent *r, const char *path, struct stat *st); +extern int ntfs_link_r (struct _reent *r, const char *existing, const char *newLink); +extern int ntfs_unlink_r (struct _reent *r, const char *name); +extern int ntfs_chdir_r (struct _reent *r, const char *name); +extern int ntfs_rename_r (struct _reent *r, const char *oldName, const char *newName); +extern int ntfs_mkdir_r (struct _reent *r, const char *path, int mode); +extern int ntfs_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf); + +/* Gekko devoptab directory walking routines for NTFS-based devices */ +extern DIR_ITER *ntfs_diropen_r (struct _reent *r, DIR_ITER *dirState, const char *path); +extern int ntfs_dirreset_r (struct _reent *r, DIR_ITER *dirState); +extern int ntfs_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); +extern int ntfs_dirclose_r (struct _reent *r, DIR_ITER *dirState); + +#endif /* _NTFSDIR_H */ + diff --git a/libcustomntfs/ntfsfile.c b/libcustomntfs/ntfsfile.c new file mode 100644 index 00000000..84aa5372 --- /dev/null +++ b/libcustomntfs/ntfsfile.c @@ -0,0 +1,526 @@ +/** + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "ntfsinternal.h" +#include "ntfsfile.h" + +#define STATE(x) ((ntfs_file_state*)x) + +void ntfsCloseFile (ntfs_file_state *file) +{ + // Sanity check + if (!file || !file->vd) + return; + + // Special case fix ups for compressed and/or encrypted files + if (file->compressed) + ntfs_attr_pclose(file->data_na); +#ifdef HAVE_SETXATTR + if (file->encrypted) + ntfs_efs_fixup_attribute(NULL, file->data_na); +#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) + { + ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME | NTFS_UPDATE_CTIME); + ntfsSync(file->vd, file->ni); + } + + 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; + file->flags = 0; + file->read = false; + file->write = false; + file->append = false; + file->pos = 0; + file->len = 0; + + return; +} + +int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) +{ + 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) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ntfsLock(file->vd); + + // Determine which mode the file is opened for + file->flags = flags; + if ((flags & 0x03) == O_RDONLY) { + file->read = true; + file->write = false; + file->append = false; + } else if ((flags & 0x03) == O_WRONLY) { + file->read = false; + file->write = true; + file->append = (flags & O_APPEND); + } else if ((flags & 0x03) == O_RDWR) { + file->read = true; + file->write = true; + file->append = (flags & O_APPEND); + } else { + r->_errno = EACCES; + 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)) { + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + r->_errno = EISDIR; + return -1; + } + + // Are we creating this file? + if ((flags & O_CREAT) && !file->ni) { + + // Create the file + file->ni = ntfsCreate(file->vd, path, S_IFREG, NULL); + if (!file->ni) { + ntfsUnlock(file->vd); + return -1; + } + + } + + // 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) { + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + return -1; + } + + // 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); + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + 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); + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + r->_errno = EROFS; + return -1; + } + + // Truncate the file if requested + if ((flags & O_TRUNC) && file->write) { + if (ntfs_attr_truncate(file->data_na, 0)) { + ntfs_attr_close(file->data_na); + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + r->_errno = errno; + 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; + file->vd->firstOpenFile->prevOpenFile = file; + } else { + file->nextOpenFile = NULL; + } + 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) + file->nextOpenFile->prevOpenFile = file->prevOpenFile; + if (file->prevOpenFile) + file->prevOpenFile->nextOpenFile = file->nextOpenFile; + else + file->vd->firstOpenFile = file->nextOpenFile; + + // 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); + if (ret <= 0) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + len -= ret; + 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 the files data length + file->len = file->data_na->data_size; + + // 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; + len = file->len - file->pos; + ntfs_log_trace("EOVERFLOW"); + } + + 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); + if (ret <= 0 || ret > len) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + ptr += ret; + len -= ret; + file->pos += ret; + read += ret; + } + //ntfs_log_trace("file->pos: %d \n", (u32)file->pos); + // Update file times (if we actually read something) + + // 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 + ntfsUnlock(file->vd); + + return position; +} +int ntfs_fstat_r (struct _reent *r, int fd, struct stat *st) +{ + ntfs_log_trace("fd %p\n", 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; + } + + // 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 && + len < file->data_na->initialized_size) { + ntfsUnlock(file->vd); + r->_errno = EOPNOTSUPP; + return -1; + } + + // Resize the files data attribute, either by expanding or truncating + if (file->compressed && len > file->data_na->initialized_size) { + char zero = 0; + if (ntfs_attr_pwrite(file->data_na, len - 1, 1, &zero) <= 0) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + } else { + if (ntfs_attr_truncate(file->data_na, len)) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + } + + // 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_AMCTIME); + + // Update the files data length + file->len = file->data_na->data_size; + + // Sync the file (and its attributes) to disc + ntfsSync(file->vd, file->ni); + + // Unlock + ntfsUnlock(file->vd); + + return 0; +} + +int ntfs_fsync_r (struct _reent *r, int fd) +{ + ntfs_log_trace("fd %p\n", 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; +} diff --git a/libcustomntfs/ntfsfile.h b/libcustomntfs/ntfsfile.h new file mode 100644 index 00000000..8e5ffcc6 --- /dev/null +++ b/libcustomntfs/ntfsfile.h @@ -0,0 +1,65 @@ +/** + * ntfsfile.c - devoptab file routines for NTFS-based devices. + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFSFILE_H +#define _NTFSFILE_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "ntfsinternal.h" +#include + +/** + * ntfs_file_state - File state + */ +typedef struct _ntfs_file_state { + ntfs_vd *vd; /* Volume this file belongs to */ + ntfs_inode *ni; /* File descriptor */ + ntfs_attr *data_na; /* File data descriptor */ + int flags; /* Opening flags */ + bool read; /* True if allowed to read from file */ + bool write; /* True if allowed to write to file */ + bool append; /* True if allowed to append to file */ + bool compressed; /* True if file data is compressed */ + bool encrypted; /* True if file data is encryted */ + off_t pos; /* Current position within the file (in bytes) */ + u64 len; /* Total length of the file (in bytes) */ + struct _ntfs_file_state *prevOpenFile; /* The previous entry in a double-linked FILO list of open files */ + struct _ntfs_file_state *nextOpenFile; /* The next entry in a double-linked FILO list of open files */ +} ntfs_file_state; + +/* File state routines */ +void ntfsCloseFile (ntfs_file_state *file); + +/* Gekko devoptab file routines for NTFS-based devices */ +extern int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode); +extern int ntfs_close_r (struct _reent *r, int fd); +extern ssize_t ntfs_write_r (struct _reent *r, int fd, const char *ptr, size_t len); +extern ssize_t ntfs_read_r (struct _reent *r, int fd, char *ptr, size_t len); +extern off_t ntfs_seek_r (struct _reent *r, int fd, off_t pos, int dir); +extern int ntfs_fstat_r (struct _reent *r, int fd, struct stat *st); +extern int ntfs_ftruncate_r (struct _reent *r, int fd, off_t len); +extern int ntfs_fsync_r (struct _reent *r, int fd); + +#endif /* _NTFSFILE_H */ + diff --git a/libcustomntfs/ntfsfile_frag.c b/libcustomntfs/ntfsfile_frag.c new file mode 100644 index 00000000..a9eb572c --- /dev/null +++ b/libcustomntfs/ntfsfile_frag.c @@ -0,0 +1,580 @@ +/** + * ntfsfile.c - devoptab file routines for NTFS-based devices. + * Copyright (c) 2010 Miigotu + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "ntfsinternal.h" +#include "ntfsfile.h" +#include "ntfs.h" +#include "ntfsfile_frag.h" + +#define STATE(x) ((ntfs_file_state*)x) + +// for easier comparision of ntfsfile.c against ntfsfile_frag.c +// everything is included but ifdef-ed out + +#if 0 + +void ntfsCloseFile (ntfs_file_state *file) +{ + // Sanity check + if (!file || !file->vd) + return; + + // Special case fix ups for compressed and/or encrypted files + if (file->compressed) + ntfs_attr_pclose(file->data_na); +#ifdef HAVE_SETXATTR + if (file->encrypted) + ntfs_efs_fixup_attribute(NULL, file->data_na); +#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) + { + ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME | NTFS_UPDATE_CTIME); + ntfsSync(file->vd, file->ni); + } + + 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; + file->flags = 0; + file->read = false; + file->write = false; + file->append = false; + file->pos = 0; + file->len = 0; + + return; +} + +int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode) +{ + 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) { + r->_errno = ENODEV; + return -1; + } + + // Lock + ntfsLock(file->vd); + + // Determine which mode the file is opened for + file->flags = flags; + if ((flags & 0x03) == O_RDONLY) { + file->read = true; + file->write = false; + file->append = false; + } else if ((flags & 0x03) == O_WRONLY) { + file->read = false; + file->write = true; + file->append = (flags & O_APPEND); + } else if ((flags & 0x03) == O_RDWR) { + file->read = true; + file->write = true; + file->append = (flags & O_APPEND); + } else { + r->_errno = EACCES; + 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)) { + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + 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); + ntfsUnlock(file->vd); + r->_errno = EEXIST; + return -1; + } + + // Create the file + file->ni = ntfsCreate(file->vd, path, S_IFREG, NULL); + if (!file->ni) { + ntfsUnlock(file->vd); + return -1; + } + + } + + // 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) { + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + return -1; + } + + // 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); + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + 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); + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + r->_errno = EROFS; + return -1; + } + + // Truncate the file if requested + if ((flags & O_TRUNC) && file->write) { + if (ntfs_attr_truncate(file->data_na, 0)) { + ntfs_attr_close(file->data_na); + ntfsCloseEntry(file->vd, file->ni); + ntfsUnlock(file->vd); + r->_errno = errno; + 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; + file->vd->firstOpenFile->prevOpenFile = file; + } else { + file->nextOpenFile = NULL; + } + 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) + file->nextOpenFile->prevOpenFile = file->prevOpenFile; + if (file->prevOpenFile) + file->prevOpenFile->nextOpenFile = file->nextOpenFile; + else + file->vd->firstOpenFile = file->nextOpenFile; + + // 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); + if (ret <= 0) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + len -= ret; + 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 the files data length + file->len = file->data_na->data_size; + + // Unlock + ntfsUnlock(file->vd); + + return written; +} + +#endif + +s64 ntfs_attr_getfragments(ntfs_attr *na, const s64 pos, s64 count, u64 offset, + _ntfs_frag_append_t append_fragment, void *callback_data); + +int _NTFS_get_fragments (const char *path, + _ntfs_frag_append_t append_fragment, void *callback_data) +{ + struct _reent r; + ntfs_file_state file_st, *file = &file_st; + ssize_t read = 0; + int ret_val = -11; + + // Open File + r._errno = 0; + int fd = ntfs_open_r(&r, file, path, O_RDONLY, 0); + if (fd != (int)file) return -12; + + + + + + // Sanity check + if (!file || !file->vd || !file->ni || !file->data_na) { + //r->_errno = EINVAL; + return -13; + } + /* + // 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; + len = file->len - file->pos; + ntfs_log_trace("EOVERFLOW"); + } + */ + + u64 offset = 0; + u64 len = file->len; + + // Read from the files data attribute + while (len) { + s64 ret = ntfs_attr_getfragments(file->data_na, file->pos, + len, offset, append_fragment, callback_data); + if (ret <= 0 || ret > len) { + ntfsUnlock(file->vd); + //r->_errno = errno; + ret_val = -14; + if (ret < 0) ret_val = ret; + goto out; + } + offset += ret; + len -= ret; + file->pos += ret; + read += ret; + } + + // set file size + append_fragment(callback_data, file->len >> 9, 0, 0); + // success + ret_val = 0; + + /* + //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); + */ + +out: + // Unlock + ntfsUnlock(file->vd); + // Close the file + ntfs_close_r (&r, fd); + + return ret_val; +} + +#if 0 + +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 + ntfsUnlock(file->vd); + + return position; +} +int ntfs_fstat_r (struct _reent *r, int fd, struct stat *st) +{ + ntfs_log_trace("fd %p\n", 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; + } + + // 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 && + len < file->data_na->initialized_size) { + ntfsUnlock(file->vd); + r->_errno = EOPNOTSUPP; + return -1; + } + + // Resize the files data attribute, either by expanding or truncating + if (file->compressed && len > file->data_na->initialized_size) { + char zero = 0; + if (ntfs_attr_pwrite(file->data_na, len - 1, 1, &zero) <= 0) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + } else { + if (ntfs_attr_truncate(file->data_na, len)) { + ntfsUnlock(file->vd); + r->_errno = errno; + return -1; + } + } + + // 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_AMCTIME); + + // Update the files data length + file->len = file->data_na->data_size; + + // Sync the file (and its attributes) to disc + ntfsSync(file->vd, file->ni); + + // Unlock + ntfsUnlock(file->vd); + + return 0; +} + +int ntfs_fsync_r (struct _reent *r, int fd) +{ + ntfs_log_trace("fd %p\n", 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; +} + +#endif + diff --git a/source/libs/libntfs/ntfsfile_frag.h b/libcustomntfs/ntfsfile_frag.h similarity index 100% rename from source/libs/libntfs/ntfsfile_frag.h rename to libcustomntfs/ntfsfile_frag.h diff --git a/libcustomntfs/ntfsinternal.c b/libcustomntfs/ntfsinternal.c new file mode 100644 index 00000000..fed15bce --- /dev/null +++ b/libcustomntfs/ntfsinternal.c @@ -0,0 +1,846 @@ +/** + * ntfsinternal.h - Internal support 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "ntfsinternal.h" +#include "ntfsdir.h" +#include "ntfsfile.h" + +#if defined(__wii__) +#include +#include +#include + +const INTERFACE_ID ntfs_disc_interfaces[] = { + { "sd", &__io_wiisd }, + { "usb", &__io_usbstorage }, + { "carda", &__io_gcsda }, + { "cardb", &__io_gcsdb }, + { NULL, NULL } +}; + +#elif defined(__gamecube__) +#include + +const INTERFACE_ID ntfs_disc_interfaces[] = { + { "carda", &__io_gcsda }, + { "cardb", &__io_gcsdb }, + { NULL, NULL } +}; + +#endif + +int ntfsAddDevice (const char *name, void *deviceData) +{ + const devoptab_t *devoptab_ntfs = ntfsGetDevOpTab(); + devoptab_t *dev = NULL; + char *devname = NULL; + int i; + + // Sanity check + if (!name || !deviceData || !devoptab_ntfs) { + errno = EINVAL; + return -1; + } + + // Allocate a devoptab for this device + dev = (devoptab_t *) ntfs_alloc(sizeof(devoptab_t) + strlen(name) + 1); + if (!dev) { + errno = ENOMEM; + return false; + } + + // Use the space allocated at the end of the devoptab for storing the device name + devname = (char*)(dev + 1); + strcpy(devname, name); + + // Setup the devoptab + memcpy(dev, devoptab_ntfs, sizeof(devoptab_t)); + dev->name = devname; + dev->deviceData = deviceData; + + // Add the device to the devoptab table (if there is a free slot) + for (i = 0; i < STD_MAX; i++) { + if (devoptab_list[i] == devoptab_list[0] && i != 0) { + devoptab_list[i] = dev; + return 0; + } + } + + // If we reach here then there are no free slots in the devoptab table for this device + errno = EADDRNOTAVAIL; + return -1; +} + +void ntfsRemoveDevice (const char *path) +{ + const devoptab_t *devoptab = NULL; + char name[128] = {0}; + int i; + + // Get the device name from the path + strncpy(name, path, 127); + strtok(name, ":/"); + + // Find and remove the specified device from the devoptab table + // NOTE: We do this manually due to a 'bug' in RemoveDevice + // which ignores names with suffixes and causes names + // like "ntfs" and "ntfs1" to be seen as equals + for (i = 0; i < STD_MAX; i++) { + devoptab = devoptab_list[i]; + if (devoptab && devoptab->name) { + if (strcmp(name, devoptab->name) == 0) { + devoptab_list[i] = devoptab_list[0]; + ntfs_free((devoptab_t*)devoptab); + break; + } + } + } + + return; +} + +const devoptab_t *ntfsGetDevice (const char *path, bool useDefaultDevice) +{ + const devoptab_t *devoptab = NULL; + char name[128] = {0}; + int i; + + // Get the device name from the path + strncpy(name, path, 127); + strtok(name, ":/"); + + // Search the devoptab table for the specified device name + // NOTE: We do this manually due to a 'bug' in GetDeviceOpTab + // which ignores names with suffixes and causes names + // like "ntfs" and "ntfs1" to be seen as equals + for (i = 0; i < STD_MAX; i++) { + devoptab = devoptab_list[i]; + if (devoptab && devoptab->name) { + if (strcmp(name, devoptab->name) == 0) { + return devoptab; + } + } + } + + // If we reach here then we couldn't find the device name, + // chances are that this path has no device name in it. + // Call GetDeviceOpTab to get our default device (chdir). + if (useDefaultDevice) + return GetDeviceOpTab(""); + + return NULL; +} + +const INTERFACE_ID *ntfsGetDiscInterfaces (void) +{ + // Get all know disc interfaces on the host system + return ntfs_disc_interfaces; +} + +ntfs_vd *ntfsGetVolume (const char *path) +{ + // Get the volume descriptor from the paths associated devoptab (if found) + const devoptab_t *devoptab_ntfs = ntfsGetDevOpTab(); + const devoptab_t *devoptab = ntfsGetDevice(path, true); + if (devoptab && devoptab_ntfs && (devoptab->open_r == devoptab_ntfs->open_r)) + return (ntfs_vd*)devoptab->deviceData; + + return NULL; +} + +int ntfsInitVolume (ntfs_vd *vd) +{ + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + // Initialise the volume lock + LWP_MutexInit(&vd->lock, false); + + // Reset the volumes name cache + vd->name[0] = '\0'; + + // Reset the volumes current directory + vd->cwd_ni = NULL; + + // Reset open directory and file stats + vd->openDirCount = 0; + vd->openFileCount = 0; + vd->firstOpenDir = NULL; + vd->firstOpenFile = NULL; + + return 0; +} + +void ntfsDeinitVolume (ntfs_vd *vd) +{ + // Sanity check + if (!vd) { + errno = ENODEV; + return; + } + + // Lock + ntfsLock(vd); + + // Close any directories which are still open (lazy programmers!) + ntfs_dir_state *nextDir = vd->firstOpenDir; + while (nextDir) { + ntfs_log_warning("Cleaning up orphaned directory @ %p\n", nextDir); + ntfsCloseDir(nextDir); + nextDir = nextDir->nextOpenDir; + } + + // Close any files which are still open (lazy programmers!) + ntfs_file_state *nextFile = vd->firstOpenFile; + while (nextFile) { + ntfs_log_warning("Cleaning up orphaned file @ %p\n", nextFile); + ntfsCloseFile(nextFile); + nextFile = nextFile->nextOpenFile; + } + + // Reset open directory and file stats + vd->openDirCount = 0; + vd->openFileCount = 0; + vd->firstOpenDir = NULL; + vd->firstOpenFile = NULL; + + // Close the volumes current directory (if any) + //if (vd->cwd_ni) { + //ntfsCloseEntry(vd, vd->cwd_ni); + //vd->cwd_ni = NULL; + //} + + // Force the underlying device to sync + vd->dev->d_ops->sync(vd->dev); + + // Unlock + ntfsUnlock(vd); + + // Deinitialise the volume lock + LWP_MutexDestroy(vd->lock); + + return; +} + +ntfs_inode *ntfsOpenEntry (ntfs_vd *vd, const char *path) +{ + return ntfsParseEntry(vd, path, 1); +} + +ntfs_inode *ntfsParseEntry (ntfs_vd *vd, const char *path, int reparseLevel) +{ + ntfs_inode *ni = NULL; + char *target = NULL; + int attr_size; + + // Sanity check + if (!vd) { + errno = ENODEV; + return NULL; + } + + // Get the actual path of the entry + path = ntfsRealPath(path); + if (!path) { + errno = EINVAL; + return NULL; + } else if (path[0] == '\0') { + path = "."; + } + + // Find the entry, taking into account our current directory (if any) + if (path[0] != PATH_SEP) + ni = ntfs_pathname_to_inode(vd->vol, vd->cwd_ni, path++); + else + ni = ntfs_pathname_to_inode(vd->vol, NULL, path); + + // If the entry was found and it has reparse data then parse its true path; + // this resolves the true location of symbolic links and directory junctions + if (ni && (ni->flags & FILE_ATTR_REPARSE_POINT)) { + if (ntfs_possible_symlink(ni)) { + + // Sanity check, give up if we are parsing to deep + if (reparseLevel > NTFS_MAX_SYMLINK_DEPTH) { + ntfsCloseEntry(vd, ni); + errno = ELOOP; + return NULL; + } + + // Get the target path of this entry + target = ntfs_make_symlink(ni, path, &attr_size); + if (!target) { + ntfsCloseEntry(vd, ni); + return NULL; + } + + // Close the entry (we are no longer interested in it) + ntfsCloseEntry(vd, ni); + + // Parse the entries target + ni = ntfsParseEntry(vd, target, reparseLevel++); + + // Clean up + ntfs_free(target); + + } + } + + return ni; +} + +void ntfsCloseEntry (ntfs_vd *vd, ntfs_inode *ni) +{ + // Sanity check + if (!vd) { + errno = ENODEV; + return; + } + + // Lock + ntfsLock(vd); + + // Sync the entry (if it is dirty) + if (NInoDirty(ni)) + ntfsSync(vd, ni); + + // Close the entry + ntfs_inode_close(ni); + + // Unlock + ntfsUnlock(vd); + + return; +} + + +ntfs_inode *ntfsCreate (ntfs_vd *vd, const char *path, mode_t type, const char *target) +{ + ntfs_inode *dir_ni = NULL, *ni = NULL; + char *dir = NULL; + char *name = NULL; + ntfschar *uname = NULL, *utarget = NULL; + int uname_len, utarget_len; + + // Sanity check + if (!vd) { + errno = ENODEV; + return NULL; + } + + // You cannot link between devices + if(target) { + if(vd != ntfsGetVolume(target)) { + errno = EXDEV; + return NULL; + } + } + + // Get the actual paths of the entry + path = ntfsRealPath(path); + target = ntfsRealPath(target); + if (!path) { + errno = EINVAL; + return NULL; + } + + // Lock + ntfsLock(vd); + + // Get the unicode name for the entry and find its parent directory + // TODO: This looks horrible, clean it up + dir = strdup(path); + if (!dir) { + errno = EINVAL; + goto cleanup; + } + name = strrchr(dir, '/'); + if (name) + name++; + else + name = dir; + uname_len = ntfsLocalToUnicode(name, &uname); + if (uname_len < 0) { + errno = EINVAL; + goto cleanup; + } + name = strrchr(dir, '/'); + if(name) + { + name++; + name[0] = 0; + } + + // Open the entries parent directory + dir_ni = ntfsOpenEntry(vd, dir); + if (!dir_ni) { + goto cleanup; + } + + // Create the entry + switch (type) { + + // Symbolic link + case S_IFLNK: + if (!target) { + errno = EINVAL; + goto cleanup; + } + utarget_len = ntfsLocalToUnicode(target, &utarget); + if (utarget_len < 0) { + errno = EINVAL; + goto cleanup; + } + ni = ntfs_create_symlink(dir_ni, 0, uname, uname_len, utarget, utarget_len); + break; + + // Directory or file + case S_IFDIR: + case S_IFREG: + ni = ntfs_create(dir_ni, 0, uname, uname_len, type); + break; + + } + + // If the entry was created + if (ni) { + + // Mark the entry for archiving + ni->flags |= FILE_ATTR_ARCHIVE; + + // Mark the entry as dirty + NInoSetDirty(ni); + + // Sync the entry to disc + ntfsSync(vd, ni); + + // Update parent directories times + ntfsUpdateTimes(vd, dir_ni, NTFS_UPDATE_MCTIME); + + } + +cleanup: + + if(dir_ni) + ntfsCloseEntry(vd, dir_ni); + + if(utarget) + ntfs_free(utarget); + + if(uname) + ntfs_free(uname); + + if(dir) + ntfs_free(dir); + + // Unlock + ntfsUnlock(vd); + + return ni; +} + +int ntfsLink (ntfs_vd *vd, const char *old_path, const char *new_path) +{ + ntfs_inode *dir_ni = NULL, *ni = NULL; + char *dir = NULL; + char *name = NULL; + ntfschar *uname = NULL; + int uname_len; + int res = 0; + + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + // You cannot link between devices + if(vd != ntfsGetVolume(new_path)) { + errno = EXDEV; + return -1; + } + + // Get the actual paths of the entry + old_path = ntfsRealPath(old_path); + new_path = ntfsRealPath(new_path); + if (!old_path || !new_path) { + errno = EINVAL; + return -1; + } + + // Lock + ntfsLock(vd); + + // Get the unicode name for the entry and find its parent directory + // TODO: This looks horrible, clean it up + dir = strdup(new_path); + if (!dir) { + errno = EINVAL; + goto cleanup; + } + name = strrchr(dir, '/'); + if (name) + name++; + else + name = dir; + uname_len = ntfsLocalToUnicode(name, &uname); + if (uname_len < 0) { + errno = EINVAL; + goto cleanup; + } + *name = 0; + + // Find the entry + ni = ntfsOpenEntry(vd, old_path); + if (!ni) { + errno = ENOENT; + res = -1; + goto cleanup; + } + + // Open the entries new parent directory + dir_ni = ntfsOpenEntry(vd, dir); + if (!dir_ni) { + errno = ENOENT; + res = -1; + goto cleanup; + } + + // Link the entry to its new parent + if (ntfs_link(ni, dir_ni, uname, uname_len)) { + res = -1; + goto cleanup; + } + + // Update entry times + ntfsUpdateTimes(vd, dir_ni, NTFS_UPDATE_MCTIME); + + // Sync the entry to disc + ntfsSync(vd, ni); + +cleanup: + + if(dir_ni) + ntfsCloseEntry(vd, dir_ni); + + if(ni) + ntfsCloseEntry(vd, ni); + + if(uname) + ntfs_free(uname); + + if(dir) + ntfs_free(dir); + + // Unlock + ntfsUnlock(vd); + + return res; +} + +int ntfsUnlink (ntfs_vd *vd, const char *path) +{ + ntfs_inode *dir_ni = NULL, *ni = NULL; + char *dir = NULL; + char *name = NULL; + ntfschar *uname = NULL; + int uname_len; + int res = 0; + + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + // Get the actual path of the entry + path = ntfsRealPath(path); + if (!path) { + errno = EINVAL; + return -1; + } + + // Lock + ntfsLock(vd); + + // Get the unicode name for the entry and find its parent directory + // TODO: This looks horrible + dir = strdup(path); + if (!dir) { + errno = EINVAL; + goto cleanup; + } + name = strrchr(dir, '/'); + if (name) + name++; + else + name = dir; + uname_len = ntfsLocalToUnicode(name, &uname); + if (uname_len < 0) { + errno = EINVAL; + goto cleanup; + } + name = strrchr(dir, '/'); + if(name) + { + name++; + name[0] = 0; + } + + // Find the entry + ni = ntfsOpenEntry(vd, path); + if (!ni) { + errno = ENOENT; + res = -1; + goto cleanup; + } + + // Open the entries parent directory + dir_ni = ntfsOpenEntry(vd, dir); + if (!dir_ni) { + errno = ENOENT; + res = -1; + goto cleanup; + } + + // Unlink the entry from its parent + if (ntfs_delete(vd->vol, path, ni, dir_ni, uname, uname_len)) { + res = -1; + } + + // Force the underlying device to sync + vd->dev->d_ops->sync(vd->dev); + + // ntfs_delete() ALWAYS closes ni and dir_ni; so no need for us to anymore + dir_ni = ni = NULL; + +cleanup: + + if(dir_ni) + ntfsCloseEntry(vd, dir_ni); + + if(ni) + ntfsCloseEntry(vd, ni); + + if(uname) + ntfs_free(uname); + + if(dir) + ntfs_free(dir); + + // Unlock + ntfsUnlock(vd); + + return 0; +} + +int ntfsSync (ntfs_vd *vd, ntfs_inode *ni) +{ + int res = 0; + + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + // Sanity check + if (!ni) { + errno = ENOENT; + return -1; + } + + // Lock + ntfsLock(vd); + + // Sync the entry + res = ntfs_inode_sync(ni); + + // Force the underlying device to sync + vd->dev->d_ops->sync(vd->dev); + + // Unlock + ntfsUnlock(vd); + + return res; + +} + +int ntfsStat (ntfs_vd *vd, ntfs_inode *ni, struct stat *st) +{ + ntfs_attr *na = NULL; + int res = 0; + + // Sanity check + if (!vd) { + errno = ENODEV; + return -1; + } + + // Sanity check + if (!ni) { + errno = ENOENT; + return -1; + } + + // Short circuit cases were we don't actually have to do anything + if (!st) + return 0; + + // Lock + ntfsLock(vd); + + // Zero out the stat buffer + memset(st, 0, sizeof(struct stat)); + + // Is this entry a directory + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + st->st_mode = S_IFDIR | (0777 & ~vd->dmask); + st->st_nlink = 1; + + // Open the directories index allocation table attribute + na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); + if (na) { + st->st_size = na->data_size; + st->st_blocks = na->allocated_size >> 9; + ntfs_attr_close(na); + } + + // Else it must be a file + } else { + st->st_mode = S_IFREG | (0777 & ~vd->fmask); + st->st_size = ni->data_size; + st->st_blocks = (ni->allocated_size + 511) >> 9; + st->st_nlink = le16_to_cpu(ni->mrec->link_count); + } + + // Fill in the generic entry stats + st->st_dev = vd->id; + st->st_uid = vd->uid; + st->st_gid = vd->gid; + st->st_ino = ni->mft_no; + st->st_atime = ni->last_access_time; + st->st_ctime = ni->last_mft_change_time; + st->st_mtime = ni->last_data_change_time; + + // Update entry times + ntfsUpdateTimes(vd, ni, NTFS_UPDATE_ATIME); + + // Unlock + ntfsUnlock(vd); + + return res; +} + +void ntfsUpdateTimes (ntfs_vd *vd, ntfs_inode *ni, ntfs_time_update_flags mask) +{ + // Run the access time update strategy against the device driver settings first + if (vd && vd->atime == ATIME_DISABLED) + mask &= ~NTFS_UPDATE_ATIME; + + // Update entry times + if (ni && mask) + ntfs_inode_update_times(ni, mask); + + return; +} + +const char *ntfsRealPath (const char *path) +{ + // Sanity check + if (!path) + return NULL; + + // Move the path pointer to the start of the actual path + if (strchr(path, ':') != NULL) { + path = strchr(path, ':') + 1; + } + if (strchr(path, ':') != NULL) { + return NULL; + } + + return path; +} + +int ntfsUnicodeToLocal (const ntfschar *ins, const int ins_len, char **outs, int outs_len) +{ + int len = 0; + int i; + + // Sanity check + if (!ins || !ins_len || !outs) + return 0; + + // Convert the unicode string to our current local + len = ntfs_ucstombs(ins, ins_len, outs, outs_len); + if (len == -1 && errno == EILSEQ) { + + // The string could not be converted to the current local, + // do it manually by replacing non-ASCII characters with underscores + if (!*outs || outs_len >= ins_len) { + if (!*outs) { + *outs = (char *) ntfs_alloc(ins_len + 1); + if (!*outs) { + errno = ENOMEM; + return -1; + } + } + for (i = 0; i < ins_len; i++) { + ntfschar uc = le16_to_cpu(ins[i]); + if (uc > 0xff) + uc = (ntfschar)'_'; + *outs[i] = (char)uc; + } + *outs[ins_len] = (ntfschar)'\0'; + len = ins_len; + } + + } + + return len; +} + +int ntfsLocalToUnicode (const char *ins, ntfschar **outs) +{ + // Sanity check + if (!ins || !outs) + return 0; + + // Convert the local string to unicode + return ntfs_mbstoucs(ins, outs); +} diff --git a/libcustomntfs/ntfsinternal.h b/libcustomntfs/ntfsinternal.h new file mode 100644 index 00000000..11dfb8fd --- /dev/null +++ b/libcustomntfs/ntfsinternal.h @@ -0,0 +1,178 @@ +/** + * ntfsinternal.h - Internal support routines for NTFS-based devices. + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFSINTERNAL_H +#define _NTFSINTERNAL_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "types.h" +#include "compat.h" +#include "logging.h" +#include "layout.h" +#include "device.h" +#include "volume.h" +#include "dir.h" +#include "inode.h" +#include "attrib.h" +#include "reparse.h" +#include "security.h" +#include "efs.h" +#include "unistr.h" + +#include +#include +#include + +#define NTFS_MOUNT_PREFIX "ntfs" /* Device name prefix to use when auto-mounting */ +#define NTFS_MAX_PARTITIONS 32 /* Maximum number of partitions that can be found */ +#define NTFS_MAX_MOUNTS 10 /* Maximum number of mounts available at one time */ +#define NTFS_MAX_SYMLINK_DEPTH 10 /* Maximum search depth when resolving symbolic links */ + +#define NTFS_OEM_ID cpu_to_le64(0x202020205346544eULL) /* "NTFS " */ + +#define MBR_SIGNATURE cpu_to_le16(0xAA55) +#define EBR_SIGNATURE cpu_to_le16(0xAA55) + +#define PARTITION_STATUS_NONBOOTABLE 0x00 /* Non-bootable */ +#define PARTITION_STATUS_BOOTABLE 0x80 /* Bootable (active) */ + +#define PARTITION_TYPE_EMPTY 0x00 /* Empty */ +#define PARTITION_TYPE_DOS33_EXTENDED 0x05 /* DOS 3.3+ extended partition */ +#define PARTITION_TYPE_NTFS 0x07 /* Windows NT NTFS */ +#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */ + +/* Forward declarations */ +struct _ntfs_file_state; +struct _ntfs_dir_state; + +/** + * PRIMARY_PARTITION - Block device partition record + */ +typedef struct _PARTITION_RECORD { + u8 status; /* Partition status; see above */ + u8 chs_start[3]; /* Cylinder-head-sector address to first block of partition */ + u8 type; /* Partition type; see above */ + u8 chs_end[3]; /* Cylinder-head-sector address to last block of partition */ + u32 lba_start; /* Local block address to first sector of partition */ + u32 block_count; /* Number of blocks in partition */ +} __attribute__((__packed__)) PARTITION_RECORD; + +/** + * MASTER_BOOT_RECORD - Block device master boot record + */ +typedef struct _MASTER_BOOT_RECORD { + u8 code_area[446]; /* Code area; normally empty */ + PARTITION_RECORD partitions[4]; /* 4 primary partitions */ + u16 signature; /* MBR signature; 0xAA55 */ +} __attribute__((__packed__)) MASTER_BOOT_RECORD; + +/** + * EXTENDED_PARTITION - Block device extended boot record + */ +typedef struct _EXTENDED_BOOT_RECORD { + u8 code_area[446]; /* Code area; normally empty */ + PARTITION_RECORD partition; /* Primary partition */ + PARTITION_RECORD next_ebr; /* Next extended boot record in the chain */ + u8 reserved[32]; /* Normally empty */ + u16 signature; /* EBR signature; 0xAA55 */ +} __attribute__((__packed__)) EXTENDED_BOOT_RECORD; + +/** + * INTERFACE_ID - Disc interface identifier + */ +typedef struct _INTERFACE_ID { + const char *name; /* Interface name */ + const DISC_INTERFACE *interface; /* Disc interface */ +} INTERFACE_ID; + +/** + * ntfs_atime_t - File access time update strategies + */ +typedef enum { + ATIME_ENABLED, /* Update access times */ + ATIME_DISABLED /* Don't update access times */ +} ntfs_atime_t; + +/** + * ntfs_vd - NTFS volume descriptor + */ +typedef struct _ntfs_vd { + struct ntfs_device *dev; /* NTFS device handle */ + ntfs_volume *vol; /* NTFS volume handle */ + mutex_t lock; /* Volume lock mutex */ + s64 id; /* Filesystem id */ + u32 flags; /* Mount flags */ + char name[128]; /* Volume name (cached) */ + u16 uid; /* User id for entry creation */ + u16 gid; /* Group id for entry creation */ + u16 fmask; /* Unix style permission mask for file creation */ + u16 dmask; /* Unix style permission mask for directory creation */ + ntfs_atime_t atime; /* Entry access time update strategy */ + bool showHiddenFiles; /* If true, show hidden files when enumerating directories */ + bool showSystemFiles; /* If true, show system files when enumerating directories */ + ntfs_inode *cwd_ni; /* Current directory */ + struct _ntfs_dir_state *firstOpenDir; /* The start of a FILO linked list of currently opened directories */ + struct _ntfs_file_state *firstOpenFile; /* The start of a FILO linked list of currently opened files */ + u16 openDirCount; /* The total number of directories currently open in this volume */ + u16 openFileCount; /* The total number of files currently open in this volume */ +} ntfs_vd; + +/* Lock volume */ +static inline void ntfsLock (ntfs_vd *vd) +{ + LWP_MutexLock(vd->lock); +} + +/* Unlock volume */ +static inline void ntfsUnlock (ntfs_vd *vd) +{ + LWP_MutexUnlock(vd->lock); +} + +/* Gekko device related routines */ +int ntfsAddDevice (const char *name, void *deviceData); +void ntfsRemoveDevice (const char *path); +const devoptab_t *ntfsGetDevice (const char *path, bool useDefaultDevice); +const devoptab_t *ntfsGetDevOpTab (void); +const INTERFACE_ID* ntfsGetDiscInterfaces (void); + +/* Miscellaneous helper/support routines */ +int ntfsInitVolume (ntfs_vd *vd); +void ntfsDeinitVolume (ntfs_vd *vd); +ntfs_vd *ntfsGetVolume (const char *path); +ntfs_inode *ntfsOpenEntry (ntfs_vd *vd, const char *path); +ntfs_inode *ntfsParseEntry (ntfs_vd *vd, const char *path, int reparseLevel); +void ntfsCloseEntry (ntfs_vd *vd, ntfs_inode *ni); +ntfs_inode *ntfsCreate (ntfs_vd *vd, const char *path, mode_t type, const char *target); +int ntfsLink (ntfs_vd *vd, const char *old_path, const char *new_path); +int ntfsUnlink (ntfs_vd *vd, const char *path); +int ntfsSync (ntfs_vd *vd, ntfs_inode *ni); +int ntfsStat (ntfs_vd *vd, ntfs_inode *ni, struct stat *st); +void ntfsUpdateTimes (ntfs_vd *vd, ntfs_inode *ni, ntfs_time_update_flags mask); + +const char *ntfsRealPath (const char *path); +int ntfsUnicodeToLocal (const ntfschar *ins, const int ins_len, char **outs, int outs_len); +int ntfsLocalToUnicode (const char *ins, ntfschar **outs); + +#endif /* _NTFSINTERNAL_H */ diff --git a/libcustomntfs/ntfstime.h b/libcustomntfs/ntfstime.h new file mode 100644 index 00000000..426269d7 --- /dev/null +++ b/libcustomntfs/ntfstime.h @@ -0,0 +1,121 @@ +/* + * ntfstime.h - NTFS time related functions. Originated from the Linux-NTFS project. + * + * Copyright (c) 2005 Anton Altaparmakov + * Copyright (c) 2005 Yura Pakhuchiy + * Copyright (c) 2010 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_NTFSTIME_H +#define _NTFS_NTFSTIME_H + +#ifdef HAVE_TIME_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_GETTIMEOFDAY +#include +#endif + +#include "types.h" + +/* + * There are four times more conversions of internal representation + * to ntfs representation than any other conversion, so the most + * efficient internal representation is ntfs representation + * (with low endianness) + */ +typedef sle64 ntfs_time; + +#define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000) + +/** + * ntfs2timespec - Convert an NTFS time to Unix time + * @ntfs_time: An NTFS time in 100ns units since 1601 + * + * NTFS stores times as the number of 100ns intervals since January 1st 1601 at + * 00:00 UTC. This system will not suffer from Y2K problems until ~57000AD. + * + * Return: A Unix time (number of seconds since 1970, and nanoseconds) + */ +static __inline__ struct timespec ntfs2timespec(ntfs_time ntfstime) +{ + struct timespec spec; + s64 cputime; + + cputime = sle64_to_cpu(ntfstime); + spec.tv_sec = (cputime - (NTFS_TIME_OFFSET)) / 10000000; + spec.tv_nsec = (cputime - (NTFS_TIME_OFFSET) + - (s64)spec.tv_sec*10000000)*100; + /* force zero nsec for overflowing dates */ + if ((spec.tv_nsec < 0) || (spec.tv_nsec > 999999999)) + spec.tv_nsec = 0; + return (spec); +} + +/** + * timespec2ntfs - Convert Linux time to NTFS time + * @utc_time: Linux time to convert to NTFS + * + * Convert the Linux time @utc_time to its corresponding NTFS time. + * + * Linux stores time in a long at present and measures it as the number of + * 1-second intervals since 1st January 1970, 00:00:00 UTC + * with a separated non-negative nanosecond value + * + * NTFS uses Microsoft's standard time format which is stored in a sle64 and is + * measured as the number of 100 nano-second intervals since 1st January 1601, + * 00:00:00 UTC. + * + * Return: An NTFS time (100ns units since Jan 1601) + */ +static __inline__ ntfs_time timespec2ntfs(struct timespec spec) +{ + s64 units; + + units = (s64)spec.tv_sec * 10000000 + + NTFS_TIME_OFFSET + spec.tv_nsec/100; + return (cpu_to_le64(units)); +} + +/* + * Return the current time in ntfs format + */ + +static __inline__ ntfs_time ntfs_current_time(void) +{ + struct timespec now; + +#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_SYS_CLOCK_GETTIME) + clock_gettime(CLOCK_REALTIME, &now); +#elif defined(HAVE_GETTIMEOFDAY) + struct timeval microseconds; + + gettimeofday(µseconds, (struct timezone*)NULL); + now.tv_sec = microseconds.tv_sec; + now.tv_nsec = microseconds.tv_usec*1000; +#else + now.tv_sec = time((time_t*)NULL); + now.tv_nsec = 0; +#endif + return (timespec2ntfs(now)); +} + +#endif /* _NTFS_NTFSTIME_H */ diff --git a/libcustomntfs/object_id.c b/libcustomntfs/object_id.c new file mode 100644 index 00000000..555dd137 --- /dev/null +++ b/libcustomntfs/object_id.c @@ -0,0 +1,637 @@ +/** + * object_id.c - Processing of object ids + * + * This module is part of ntfs-3g library + * + * Copyright (c) 2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_SETXATTR +#include +#endif + +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif + +#include "types.h" +#include "debug.h" +#include "attrib.h" +#include "inode.h" +#include "dir.h" +#include "volume.h" +#include "mft.h" +#include "index.h" +#include "lcnalloc.h" +#include "object_id.h" +#include "logging.h" +#include "misc.h" + +/* + * Endianness considerations + * + * According to RFC 4122, GUIDs should be printed with the most + * significant byte first, and the six fields be compared individually + * for ordering. RFC 4122 does not define the internal representation. + * + * Here we always copy disk images with no endianness change, + * and, for indexing, GUIDs are compared as if they were a sequence + * of four unsigned 32 bit integers. + * + * --------------------- begin from RFC 4122 ---------------------- + * Consider each field of the UUID to be an unsigned integer as shown + * in the table in section Section 4.1.2. Then, to compare a pair of + * UUIDs, arithmetically compare the corresponding fields from each + * UUID in order of significance and according to their data type. + * Two UUIDs are equal if and only if all the corresponding fields + * are equal. + * + * UUIDs, as defined in this document, can also be ordered + * lexicographically. For a pair of UUIDs, the first one follows the + * second if the most significant field in which the UUIDs differ is + * greater for the first UUID. The second precedes the first if the + * most significant field in which the UUIDs differ is greater for + * the second UUID. + * + * The fields are encoded as 16 octets, with the sizes and order of the + * fields defined above, and with each field encoded with the Most + * Significant Byte first (known as network byte order). Note that the + * field names, particularly for multiplexed fields, follow historical + * practice. + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | time_low | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | time_mid | time_hi_and_version | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |clk_seq_hi_res | clk_seq_low | node (0-1) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | node (2-5) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * ---------------------- end from RFC 4122 ----------------------- + */ + +typedef struct { + GUID object_id; +} OBJECT_ID_INDEX_KEY; + +typedef struct { + le64 file_id; + GUID birth_volume_id; + GUID birth_object_id; + GUID domain_id; +} OBJECT_ID_INDEX_DATA; // known as OBJ_ID_INDEX_DATA + +struct OBJECT_ID_INDEX { /* index entry in $Extend/$ObjId */ + INDEX_ENTRY_HEADER header; + OBJECT_ID_INDEX_KEY key; + OBJECT_ID_INDEX_DATA data; +} ; + +static ntfschar objid_index_name[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('O') }; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Set the index for a new object id + * + * Returns 0 if success + * -1 if failure, explained by errno + */ + +static int set_object_id_index(ntfs_inode *ni, ntfs_index_context *xo, + const OBJECT_ID_ATTR *object_id) +{ + struct OBJECT_ID_INDEX indx; + u64 file_id_cpu; + le64 file_id; + le16 seqn; + + seqn = ni->mrec->sequence_number; + file_id_cpu = MK_MREF(ni->mft_no,le16_to_cpu(seqn)); + file_id = cpu_to_le64(file_id_cpu); + indx.header.data_offset = const_cpu_to_le16( + sizeof(INDEX_ENTRY_HEADER) + + sizeof(OBJECT_ID_INDEX_KEY)); + indx.header.data_length = const_cpu_to_le16( + sizeof(OBJECT_ID_INDEX_DATA)); + indx.header.reservedV = const_cpu_to_le32(0); + indx.header.length = const_cpu_to_le16( + sizeof(struct OBJECT_ID_INDEX)); + indx.header.key_length = const_cpu_to_le16( + sizeof(OBJECT_ID_INDEX_KEY)); + indx.header.flags = const_cpu_to_le16(0); + indx.header.reserved = const_cpu_to_le16(0); + + memcpy(&indx.key.object_id,object_id,sizeof(GUID)); + + indx.data.file_id = file_id; + memcpy(&indx.data.birth_volume_id, + &object_id->birth_volume_id,sizeof(GUID)); + memcpy(&indx.data.birth_object_id, + &object_id->birth_object_id,sizeof(GUID)); + memcpy(&indx.data.domain_id, + &object_id->domain_id,sizeof(GUID)); + ntfs_index_ctx_reinit(xo); + return (ntfs_ie_add(xo,(INDEX_ENTRY*)&indx)); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Open the $Extend/$ObjId file and its index + * + * Return the index context if opened + * or NULL if an error occurred (errno tells why) + * + * The index has to be freed and inode closed when not needed any more. + */ + +static ntfs_index_context *open_object_id_index(ntfs_volume *vol) +{ + u64 inum; + ntfs_inode *ni; + ntfs_inode *dir_ni; + ntfs_index_context *xo; + + /* do not use path_name_to inode - could reopen root */ + dir_ni = ntfs_inode_open(vol, FILE_Extend); + ni = (ntfs_inode*)NULL; + if (dir_ni) { + inum = ntfs_inode_lookup_by_mbsname(dir_ni,"$ObjId"); + if (inum != (u64)-1) + ni = ntfs_inode_open(vol, inum); + ntfs_inode_close(dir_ni); + } + if (ni) { + xo = ntfs_index_ctx_get(ni, objid_index_name, 2); + if (!xo) { + ntfs_inode_close(ni); + } + } else + xo = (ntfs_index_context*)NULL; + return (xo); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Merge object_id data stored in the index into + * a full object_id struct. + * + * returns 0 if merging successful + * -1 if no data could be merged. This is generally not an error + */ + +static int merge_index_data(ntfs_inode *ni, + const OBJECT_ID_ATTR *objectid_attr, + OBJECT_ID_ATTR *full_objectid) +{ + OBJECT_ID_INDEX_KEY key; + struct OBJECT_ID_INDEX *entry; + ntfs_index_context *xo; + ntfs_inode *xoni; + int res; + + res = -1; + xo = open_object_id_index(ni->vol); + if (xo) { + memcpy(&key.object_id,objectid_attr,sizeof(GUID)); + if (!ntfs_index_lookup(&key, + sizeof(OBJECT_ID_INDEX_KEY), xo)) { + entry = (struct OBJECT_ID_INDEX*)xo->entry; + /* make sure inode numbers match */ + if (entry + && (MREF(le64_to_cpu(entry->data.file_id)) + == ni->mft_no)) { + memcpy(&full_objectid->birth_volume_id, + &entry->data.birth_volume_id, + sizeof(GUID)); + memcpy(&full_objectid->birth_object_id, + &entry->data.birth_object_id, + sizeof(GUID)); + memcpy(&full_objectid->domain_id, + &entry->data.domain_id, + sizeof(GUID)); + res = 0; + } + } + xoni = xo->ni; + ntfs_index_ctx_put(xo); + ntfs_inode_close(xoni); + } + return (res); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Remove an object id index entry if attribute present + * + * Returns the size of existing object id + * (the existing object_d is returned) + * -1 if failure, explained by errno + */ + +static int remove_object_id_index(ntfs_attr *na, ntfs_index_context *xo, + OBJECT_ID_ATTR *old_attr) +{ + OBJECT_ID_INDEX_KEY key; + struct OBJECT_ID_INDEX *entry; + s64 size; + int ret; + + ret = na->data_size; + if (ret) { + /* read the existing object id attribute */ + size = ntfs_attr_pread(na, 0, sizeof(GUID), old_attr); + if (size >= (s64)sizeof(GUID)) { + memcpy(&key.object_id, + &old_attr->object_id,sizeof(GUID)); + size = sizeof(GUID); + if (!ntfs_index_lookup(&key, + sizeof(OBJECT_ID_INDEX_KEY), xo)) { + entry = (struct OBJECT_ID_INDEX*)xo->entry; + memcpy(&old_attr->birth_volume_id, + &entry->data.birth_volume_id, + sizeof(GUID)); + memcpy(&old_attr->birth_object_id, + &entry->data.birth_object_id, + sizeof(GUID)); + memcpy(&old_attr->domain_id, + &entry->data.domain_id, + sizeof(GUID)); + size = sizeof(OBJECT_ID_ATTR); + if (ntfs_index_rm(xo)) + ret = -1; + } + } else { + ret = -1; + errno = ENODATA; + } + } + return (ret); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Update the object id and index + * + * The object_id attribute should have been created and the + * non-duplication of the GUID should have been checked before. + * + * Returns 0 if success + * -1 if failure, explained by errno + * If could not remove the existing index, nothing is done, + * If could not write the new data, no index entry is inserted + * If failed to insert the index, data is removed + */ + +static int update_object_id(ntfs_inode *ni, ntfs_index_context *xo, + const OBJECT_ID_ATTR *value, size_t size) +{ + OBJECT_ID_ATTR old_attr; + ntfs_attr *na; + int oldsize; + int written; + int res; + + res = 0; + + na = ntfs_attr_open(ni, AT_OBJECT_ID, AT_UNNAMED, 0); + if (na) { + + /* remove the existing index entry */ + oldsize = remove_object_id_index(na,xo,&old_attr); + if (oldsize < 0) + res = -1; + else { + /* resize attribute */ + res = ntfs_attr_truncate(na, (s64)sizeof(GUID)); + /* write the object_id in attribute */ + if (!res && value) { + written = (int)ntfs_attr_pwrite(na, + (s64)0, (s64)sizeof(GUID), + &value->object_id); + if (written != (s64)sizeof(GUID)) { + ntfs_log_error("Failed to update " + "object id\n"); + errno = EIO; + res = -1; + } + } + /* write index part if provided */ + if (!res + && ((size < sizeof(OBJECT_ID_ATTR)) + || set_object_id_index(ni,xo,value))) { + /* + * If cannot index, try to remove the object + * id and log the error. There will be an + * inconsistency if removal fails. + */ + ntfs_attr_rm(na); + ntfs_log_error("Failed to index object id." + " Possible corruption.\n"); + } + } + ntfs_attr_close(na); + NInoSetDirty(ni); + } else + res = -1; + return (res); +} + +/* + * Add a (dummy) object id to an inode if it does not exist + * + * returns 0 if attribute was inserted (or already present) + * -1 if adding failed (explained by errno) + */ + +static int add_object_id(ntfs_inode *ni, int flags) +{ + int res; + u8 dummy; + + res = -1; /* default return */ + if (!ntfs_attr_exist(ni,AT_OBJECT_ID, AT_UNNAMED,0)) { + if (!(flags & XATTR_REPLACE)) { + /* + * no object id attribute : add one, + * apparently, this does not feed the new value in + * Note : NTFS version must be >= 3 + */ + if (ni->vol->major_ver >= 3) { + res = ntfs_attr_add(ni, AT_OBJECT_ID, + AT_UNNAMED, 0, &dummy, (s64)0); + NInoSetDirty(ni); + } else + errno = EOPNOTSUPP; + } else + errno = ENODATA; + } else { + if (flags & XATTR_CREATE) + errno = EEXIST; + else + res = 0; + } + return (res); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Delete an object_id index entry + * + * Returns 0 if success + * -1 if failure, explained by errno + */ + +int ntfs_delete_object_id_index(ntfs_inode *ni) +{ + ntfs_index_context *xo; + ntfs_inode *xoni; + ntfs_attr *na; + OBJECT_ID_ATTR old_attr; + int res; + + res = 0; + na = ntfs_attr_open(ni, AT_OBJECT_ID, AT_UNNAMED, 0); + if (na) { + /* + * read the existing object id + * and un-index it + */ + xo = open_object_id_index(ni->vol); + if (xo) { + if (remove_object_id_index(na,xo,&old_attr) < 0) + res = -1; + xoni = xo->ni; + ntfs_index_entry_mark_dirty(xo); + NInoSetDirty(xoni); + ntfs_index_ctx_put(xo); + ntfs_inode_close(xoni); + } + ntfs_attr_close(na); + } + return (res); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Get the ntfs object id into an extended attribute + * + * If present, the object_id from the attribute and the GUIDs + * from the index are returned (formatted as OBJECT_ID_ATTR) + * + * Returns the global size (can be 0, 16 or 64) + * and the buffer is updated if it is long enough + */ + +int ntfs_get_ntfs_object_id(ntfs_inode *ni, char *value, size_t size) +{ + OBJECT_ID_ATTR full_objectid; + OBJECT_ID_ATTR *objectid_attr; + s64 attr_size; + int full_size; + + full_size = 0; /* default to no data and some error to be defined */ + if (ni) { + objectid_attr = (OBJECT_ID_ATTR*)ntfs_attr_readall(ni, + AT_OBJECT_ID,(ntfschar*)NULL, 0, &attr_size); + if (objectid_attr) { + /* restrict to only GUID present in attr */ + if (attr_size == sizeof(GUID)) { + memcpy(&full_objectid.object_id, + objectid_attr,sizeof(GUID)); + full_size = sizeof(GUID); + /* get data from index, if any */ + if (!merge_index_data(ni, objectid_attr, + &full_objectid)) { + full_size = sizeof(OBJECT_ID_ATTR); + } + if (full_size <= (s64)size) { + if (value) + memcpy(value,&full_objectid, + full_size); + else + errno = EINVAL; + } + } else { + /* unexpected size, better return unsupported */ + errno = EOPNOTSUPP; + full_size = 0; + } + free(objectid_attr); + } else + errno = ENODATA; + } + return (full_size ? (int)full_size : -errno); +} + +/* + * Set the object id from an extended attribute + * + * If the size is 64, the attribute and index are set. + * else if the size is not less than 16 only the attribute is set. + * The object id index is set accordingly. + * + * Returns 0, or -1 if there is a problem + */ + +int ntfs_set_ntfs_object_id(ntfs_inode *ni, + const char *value, size_t size, int flags) +{ + OBJECT_ID_INDEX_KEY key; + ntfs_inode *xoni; + ntfs_index_context *xo; + int res; + + res = 0; + if (ni && value && (size >= sizeof(GUID))) { + xo = open_object_id_index(ni->vol); + if (xo) { + /* make sure the GUID was not used somewhere */ + memcpy(&key.object_id, value, sizeof(GUID)); + if (ntfs_index_lookup(&key, + sizeof(OBJECT_ID_INDEX_KEY), xo)) { + ntfs_index_ctx_reinit(xo); + res = add_object_id(ni, flags); + if (!res) { + /* update value and index */ + res = update_object_id(ni,xo, + (const OBJECT_ID_ATTR*)value, + size); + } + } else { + /* GUID is present elsewhere */ + res = -1; + errno = EEXIST; + } + xoni = xo->ni; + ntfs_index_entry_mark_dirty(xo); + NInoSetDirty(xoni); + ntfs_index_ctx_put(xo); + ntfs_inode_close(xoni); + } else { + res = -1; + } + } else { + errno = EINVAL; + res = -1; + } + return (res ? -1 : 0); +} + +/* + * Remove the object id + * + * Returns 0, or -1 if there is a problem + */ + +int ntfs_remove_ntfs_object_id(ntfs_inode *ni) +{ + int res; + int olderrno; + ntfs_attr *na; + ntfs_inode *xoni; + ntfs_index_context *xo; + int oldsize; + OBJECT_ID_ATTR old_attr; + + res = 0; + if (ni) { + /* + * open and delete the object id + */ + na = ntfs_attr_open(ni, AT_OBJECT_ID, + AT_UNNAMED,0); + if (na) { + /* first remove index (old object id needed) */ + xo = open_object_id_index(ni->vol); + if (xo) { + oldsize = remove_object_id_index(na,xo, + &old_attr); + if (oldsize < 0) { + res = -1; + } else { + /* now remove attribute */ + res = ntfs_attr_rm(na); + if (res + && (oldsize > (int)sizeof(GUID))) { + /* + * If we could not remove the + * attribute, try to restore the + * index and log the error. There + * will be an inconsistency if + * the reindexing fails. + */ + set_object_id_index(ni, xo, + &old_attr); + ntfs_log_error( + "Failed to remove object id." + " Possible corruption.\n"); + } + } + + xoni = xo->ni; + ntfs_index_entry_mark_dirty(xo); + NInoSetDirty(xoni); + ntfs_index_ctx_put(xo); + ntfs_inode_close(xoni); + } + olderrno = errno; + ntfs_attr_close(na); + /* avoid errno pollution */ + if (errno == ENOENT) + errno = olderrno; + } else { + errno = ENODATA; + res = -1; + } + NInoSetDirty(ni); + } else { + errno = EINVAL; + res = -1; + } + return (res ? -1 : 0); +} + +#endif /* HAVE_SETXATTR */ diff --git a/libcustomntfs/object_id.h b/libcustomntfs/object_id.h new file mode 100644 index 00000000..31af9fd8 --- /dev/null +++ b/libcustomntfs/object_id.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2008 Jean-Pierre Andre + * + */ + +/* + * This program 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef OBJECT_ID_H +#define OBJECT_ID_H + +int ntfs_get_ntfs_object_id(ntfs_inode *ni, char *value, size_t size); + +int ntfs_set_ntfs_object_id(ntfs_inode *ni, const char *value, + size_t size, int flags); +int ntfs_remove_ntfs_object_id(ntfs_inode *ni); + +int ntfs_delete_object_id_index(ntfs_inode *ni); + +#endif /* OBJECT_ID_H */ diff --git a/libcustomntfs/param.h b/libcustomntfs/param.h new file mode 100644 index 00000000..f21bd653 --- /dev/null +++ b/libcustomntfs/param.h @@ -0,0 +1,82 @@ +/* + * param.h - Parameter values for ntfs-3g + * + * Copyright (c) 2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_PARAM_H +#define _NTFS_PARAM_H + +#define CACHE_INODE_SIZE 32 /* inode cache, zero or >= 3 and not too big */ +#define CACHE_NIDATA_SIZE 64 /* idata cache, zero or >= 3 and not too big */ +#define CACHE_LOOKUP_SIZE 64 /* lookup cache, zero or >= 3 and not too big */ +#define CACHE_SECURID_SIZE 16 /* securid cache, zero or >= 3 and not too big */ +#define CACHE_LEGACY_SIZE 8 /* legacy cache size, zero or >= 3 and not too big */ + +#define FORCE_FORMAT_v1x 0 /* Insert security data as in NTFS v1.x */ +#define OWNERFROMACL 1 /* Get the owner from ACL (not Windows owner) */ + + /* default security sub-authorities */ +enum { + DEFSECAUTH1 = -1153374643, /* 3141592653 */ + DEFSECAUTH2 = 589793238, + DEFSECAUTH3 = 462843383, + DEFSECBASE = 10000 +}; + +/* + * Parameters for compression + */ + + /* default option for compression */ +#define DEFAULT_COMPRESSION FALSE + /* (log2 of) number of clusters in a compression block for new files */ +#define STANDARD_COMPRESSION_UNIT 4 + /* maximum cluster size for allowing compression for new files */ +#define MAX_COMPRESSION_CLUSTER_SIZE 4096 + +/* + * Permission checking modes for high level and low level + * + * The choices for high and low lowel are independent, they have + * no effect on the library + * + * Stick to the recommended values unless you understand the consequences + * on protection and performances. Use of cacheing is good for + * performances, but bad on security. + * + * Possible values for high level : + * 1 : no cache, kernel control (recommended) + * 4 : no cache, file system control + * 7 : no cache, kernel control for ACLs + * + * Possible values for low level : + * 2 : no cache, kernel control + * 3 : use kernel/fuse cache, kernel control + * 5 : no cache, file system control (recommended) + * 8 : no cache, kernel control for ACLs + * + * Use of options 7 and 8 requires a patch to fuse + * When Posix ACLs are selected in the configure options, a value + * of 6 is added in the mount report. + */ + +#define HPERMSCONFIG 1 +#define LPERMSCONFIG 5 + +#endif /* defined _NTFS_PARAM_H */ diff --git a/libcustomntfs/reparse.c b/libcustomntfs/reparse.c new file mode 100644 index 00000000..0f6360e1 --- /dev/null +++ b/libcustomntfs/reparse.c @@ -0,0 +1,1222 @@ +/** + * reparse.c - Processing of reparse points + * + * This module is part of ntfs-3g library + * + * Copyright (c) 2008-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#ifdef HAVE_SETXATTR +#include +#endif + +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif + +#include "types.h" +#include "debug.h" +#include "attrib.h" +#include "inode.h" +#include "dir.h" +#include "volume.h" +#include "mft.h" +#include "index.h" +#include "lcnalloc.h" +#include "logging.h" +#include "misc.h" +#include "reparse.h" + +/* the definitions in layout.h are wrong, we use names defined in + http://msdn.microsoft.com/en-us/library/aa365740(VS.85).aspx +*/ + +#define IO_REPARSE_TAG_DFS const_cpu_to_le32(0x8000000A) +#define IO_REPARSE_TAG_DFSR const_cpu_to_le32(0x80000012) +#define IO_REPARSE_TAG_HSM const_cpu_to_le32(0xC0000004) +#define IO_REPARSE_TAG_HSM2 const_cpu_to_le32(0x80000006) +#define IO_REPARSE_TAG_MOUNT_POINT const_cpu_to_le32(0xA0000003) +#define IO_REPARSE_TAG_SIS const_cpu_to_le32(0x80000007) +#define IO_REPARSE_TAG_SYMLINK const_cpu_to_le32(0xA000000C) + +struct MOUNT_POINT_REPARSE_DATA { /* reparse data for junctions */ + le16 subst_name_offset; + le16 subst_name_length; + le16 print_name_offset; + le16 print_name_length; + char path_buffer[0]; /* above data assume this is char array */ +} ; + +struct SYMLINK_REPARSE_DATA { /* reparse data for symlinks */ + le16 subst_name_offset; + le16 subst_name_length; + le16 print_name_offset; + le16 print_name_length; + le32 flags; /* 1 for full target, otherwise 0 */ + char path_buffer[0]; /* above data assume this is char array */ +} ; + +struct REPARSE_INDEX { /* index entry in $Extend/$Reparse */ + INDEX_ENTRY_HEADER header; + REPARSE_INDEX_KEY key; + le32 filling; +} ; + +static const ntfschar dir_junction_head[] = { + const_cpu_to_le16('\\'), + const_cpu_to_le16('?'), + const_cpu_to_le16('?'), + const_cpu_to_le16('\\') +} ; + +static const ntfschar vol_junction_head[] = { + const_cpu_to_le16('\\'), + const_cpu_to_le16('?'), + const_cpu_to_le16('?'), + const_cpu_to_le16('\\'), + const_cpu_to_le16('V'), + const_cpu_to_le16('o'), + const_cpu_to_le16('l'), + const_cpu_to_le16('u'), + const_cpu_to_le16('m'), + const_cpu_to_le16('e'), + const_cpu_to_le16('{'), +} ; + +static ntfschar reparse_index_name[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('R') }; + +static const char mappingdir[] = ".NTFS-3G/"; + +/* + * Fix a file name with doubtful case in some directory index + * and return the name with the casing used in directory. + * + * Should only be used to translate paths stored with case insensitivity + * (such as directory junctions) when no case conflict is expected. + * If there some ambiguity, the name which collates first is returned. + * + * The name is converted to upper case and searched the usual way. + * The collation rules for file names are such that we should get the + * first candidate if any. + */ + +static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname, + int uname_len) +{ + ntfs_volume *vol = dir_ni->vol; + ntfs_index_context *icx; + u64 mref; + le64 lemref; + int lkup; + int olderrno; + int i; + u32 cpuchar; + INDEX_ENTRY *entry; + FILE_NAME_ATTR *found; + struct { + FILE_NAME_ATTR attr; + ntfschar file_name[NTFS_MAX_NAME_LEN + 1]; + } find; + + mref = (u64)-1; /* default return (not found) */ + icx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4); + if (icx) { + if (uname_len > NTFS_MAX_NAME_LEN) + uname_len = NTFS_MAX_NAME_LEN; + find.attr.file_name_length = uname_len; + for (i=0; iupcase_len) + && (le16_to_cpu(vol->upcase[cpuchar]) < cpuchar)) + find.attr.file_name[i] = vol->upcase[cpuchar]; + else + find.attr.file_name[i] = uname[i]; + } + olderrno = errno; + lkup = ntfs_index_lookup((char*)&find, uname_len, icx); + if (errno == ENOENT) + errno = olderrno; + /* + * We generally only get the first matching candidate, + * so we still have to check whether this is a real match + */ + if (icx->entry && (icx->entry->ie_flags & INDEX_ENTRY_END)) + /* get next entry if reaching end of block */ + entry = ntfs_index_next(icx->entry, icx); + else + entry = icx->entry; + if (entry) { + found = &entry->key.file_name; + if (lkup + && ntfs_names_are_equal(find.attr.file_name, + find.attr.file_name_length, + found->file_name, found->file_name_length, + IGNORE_CASE, + vol->upcase, vol->upcase_len)) + lkup = 0; + if (!lkup) { + /* + * name found : + * fix original name and return inode + */ + lemref = entry->indexed_file; + mref = le64_to_cpu(lemref); + for (i=0; ifile_name_length; i++) + uname[i] = found->file_name[i]; + } + } + ntfs_index_ctx_put(icx); + } + return (mref); +} + +/* + * Search for a directory junction or a symbolic link + * along the target path, with target defined as a full absolute path + * + * Returns the path translated to a Linux path + * or NULL if the path is not valid + */ + +static char *search_absolute(ntfs_volume *vol, ntfschar *path, + int count, BOOL isdir) +{ + ntfs_inode *ni; + u64 inum; + char *target; + int start; + int len; + + target = (char*)NULL; /* default return */ + ni = ntfs_inode_open(vol, (MFT_REF)FILE_root); + if (ni) { + start = 0; + do { + len = 0; + while (((start + len) < count) + && (path[start + len] != const_cpu_to_le16('\\'))) + len++; + inum = ntfs_fix_file_name(ni, &path[start], len); + ntfs_inode_close(ni); + ni = (ntfs_inode*)NULL; + if (inum != (u64)-1) { + inum = MREF(inum); + ni = ntfs_inode_open(vol, inum); + start += len; + if (start < count) + path[start++] = const_cpu_to_le16('/'); + } + } while (ni + && (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + && (start < count)); + if (ni + && (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? isdir : !isdir)) + if (ntfs_ucstombs(path, count, &target, 0) < 0) { + if (target) { + free(target); + target = (char*)NULL; + } + } + if (ni) + ntfs_inode_close(ni); + } + return (target); +} + +/* + * Search for a symbolic link along the target path, + * with the target defined as a relative path + * + * Note : the path used to access the current inode, may be + * different from the one implied in the target definition, + * when an inode has names in several directories. + * + * Returns the path translated to a Linux path + * or NULL if the path is not valid + */ + +static char *search_relative(ntfs_inode *ni, ntfschar *path, int count) +{ + char *target = (char*)NULL; + ntfs_inode *curni; + ntfs_inode *newni; + u64 inum; + int pos; + int lth; + BOOL ok; + int max = 32; /* safety */ + + pos = 0; + ok = TRUE; + curni = ntfs_dir_parent_inode(ni); + while (curni && ok && (pos < (count - 1)) && --max) { + if ((count >= (pos + 2)) + && (path[pos] == const_cpu_to_le16('.')) + && (path[pos+1] == const_cpu_to_le16('\\'))) { + path[1] = const_cpu_to_le16('/'); + pos += 2; + } else { + if ((count >= (pos + 3)) + && (path[pos] == const_cpu_to_le16('.')) + &&(path[pos+1] == const_cpu_to_le16('.')) + && (path[pos+2] == const_cpu_to_le16('\\'))) { + path[2] = const_cpu_to_le16('/'); + pos += 3; + newni = ntfs_dir_parent_inode(curni); + if (curni != ni) + ntfs_inode_close(curni); + curni = newni; + if (!curni) + ok = FALSE; + } else { + lth = 0; + while (((pos + lth) < count) + && (path[pos + lth] != const_cpu_to_le16('\\'))) + lth++; + if (lth > 0) + inum = ntfs_fix_file_name(curni,&path[pos],lth); + else + inum = (u64)-1; + if (!lth + || ((curni != ni) + && ntfs_inode_close(curni)) + || (inum == (u64)-1)) + ok = FALSE; + else { + curni = ntfs_inode_open(ni->vol, MREF(inum)); + if (!curni) + ok = FALSE; + else { + if (ok && ((pos + lth) < count)) { + path[pos + lth] = const_cpu_to_le16('/'); + pos += lth + 1; + } else { + pos += lth; + if ((ni->mrec->flags ^ curni->mrec->flags) + & MFT_RECORD_IS_DIRECTORY) + ok = FALSE; + if (ntfs_inode_close(curni)) + ok = FALSE; + } + } + } + } + } + } + + if (ok && (ntfs_ucstombs(path, count, &target, 0) < 0)) { + free(target); // needed ? + target = (char*)NULL; + } + return (target); +} + +/* + * Check whether a drive letter has been defined in .NTFS-3G + * + * Returns 1 if found, + * 0 if not found, + * -1 if there was an error (described by errno) + */ + +static int ntfs_drive_letter(ntfs_volume *vol, ntfschar letter) +{ + char defines[NTFS_MAX_NAME_LEN + 5]; + char *drive; + int ret; + int sz; + int olderrno; + ntfs_inode *ni; + + ret = -1; + drive = (char*)NULL; + sz = ntfs_ucstombs(&letter, 1, &drive, 0); + if (sz > 0) { + strcpy(defines,mappingdir); + if ((*drive >= 'a') && (*drive <= 'z')) + *drive += 'A' - 'a'; + strcat(defines,drive); + strcat(defines,":"); + olderrno = errno; + ni = ntfs_pathname_to_inode(vol, NULL, defines); + if (ni && !ntfs_inode_close(ni)) + ret = 1; + else + if (errno == ENOENT) { + ret = 0; + /* avoid errno pollution */ + errno = olderrno; + } + } + if (drive) + free(drive); + return (ret); +} + +/* + * Do some sanity checks on reparse data + * + * The only general check is about the size (at least the tag must + * be present) + * If the reparse data looks like a junction point or symbolic + * link, more checks can be done. + * + */ + +static BOOL valid_reparse_data(ntfs_inode *ni, + const REPARSE_POINT *reparse_attr, size_t size) +{ + BOOL ok; + unsigned int offs; + unsigned int lth; + const struct MOUNT_POINT_REPARSE_DATA *mount_point_data; + const struct SYMLINK_REPARSE_DATA *symlink_data; + + ok = ni && reparse_attr + && (size >= sizeof(REPARSE_POINT)) + && (((size_t)le16_to_cpu(reparse_attr->reparse_data_length) + + sizeof(REPARSE_POINT)) == size); + if (ok) { + switch (reparse_attr->reparse_tag) { + case IO_REPARSE_TAG_MOUNT_POINT : + mount_point_data = (const struct MOUNT_POINT_REPARSE_DATA*) + reparse_attr->reparse_data; + offs = le16_to_cpu(mount_point_data->subst_name_offset); + lth = le16_to_cpu(mount_point_data->subst_name_length); + /* consistency checks */ + if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + || ((size_t)((sizeof(REPARSE_POINT) + + sizeof(struct MOUNT_POINT_REPARSE_DATA) + + offs + lth)) > size)) + ok = FALSE; + break; + case IO_REPARSE_TAG_SYMLINK : + symlink_data = (const struct SYMLINK_REPARSE_DATA*) + reparse_attr->reparse_data; + offs = le16_to_cpu(symlink_data->subst_name_offset); + lth = le16_to_cpu(symlink_data->subst_name_length); + if ((size_t)((sizeof(REPARSE_POINT) + + sizeof(struct SYMLINK_REPARSE_DATA) + + offs + lth)) > size) + ok = FALSE; + break; + default : + break; + } + } + if (!ok) + errno = EINVAL; + return (ok); +} + +/* + * Check and translate the target of a junction point or + * a full absolute symbolic link. + * + * A full target definition begins with "\??\" or "\\?\" + * + * The fully defined target is redefined as a relative link, + * - either to the target if found on the same device. + * - or into the /.NTFS-3G directory for the user to define + * In the first situation, the target is translated to case-sensitive path. + * + * returns the target converted to a relative symlink + * or NULL if there were some problem, as described by errno + */ + +static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction, + int count, const char *mnt_point, BOOL isdir) +{ + char *target; + char *fulltarget; + int sz; + char *q; + enum { DIR_JUNCTION, VOL_JUNCTION, NO_JUNCTION } kind; + + target = (char*)NULL; + fulltarget = (char*)NULL; + /* + * For a valid directory junction we want \??\x:\ + * where \ is an individual char and x a non-null char + */ + if ((count >= 7) + && !memcmp(junction,dir_junction_head,8) + && junction[4] + && (junction[5] == const_cpu_to_le16(':')) + && (junction[6] == const_cpu_to_le16('\\'))) + kind = DIR_JUNCTION; + else + /* + * For a valid volume junction we want \\?\Volume{ + * and a final \ (where \ is an individual char) + */ + if ((count >= 12) + && !memcmp(junction,vol_junction_head,22) + && (junction[count-1] == const_cpu_to_le16('\\'))) + kind = VOL_JUNCTION; + else + kind = NO_JUNCTION; + /* + * Directory junction with an explicit path and + * no specific definition for the drive letter : + * try to interpret as a target on the same volume + */ + if ((kind == DIR_JUNCTION) + && (count >= 7) + && junction[7] + && !ntfs_drive_letter(vol, junction[4])) { + target = search_absolute(vol,&junction[7],count - 7, isdir); + if (target) { + fulltarget = (char*)ntfs_malloc(strlen(mnt_point) + + strlen(target) + 2); + if (fulltarget) { + strcpy(fulltarget,mnt_point); + strcat(fulltarget,"/"); + strcat(fulltarget,target); + } + free(target); + } + } + /* + * Volume junctions or directory junctions with + * target not found on current volume : + * link to /.NTFS-3G/target which the user can + * define as a symbolic link to the real target + */ + if (((kind == DIR_JUNCTION) && !fulltarget) + || (kind == VOL_JUNCTION)) { + sz = ntfs_ucstombs(&junction[4], + (kind == VOL_JUNCTION ? count - 5 : count - 4), + &target, 0); + if ((sz > 0) && target) { + /* reverse slashes */ + for (q=target; *q; q++) + if (*q == '\\') + *q = '/'; + /* force uppercase drive letter */ + if ((target[1] == ':') + && (target[0] >= 'a') + && (target[0] <= 'z')) + target[0] += 'A' - 'a'; + fulltarget = (char*)ntfs_malloc(strlen(mnt_point) + + sizeof(mappingdir) + strlen(target) + 1); + if (fulltarget) { + strcpy(fulltarget,mnt_point); + strcat(fulltarget,"/"); + strcat(fulltarget,mappingdir); + strcat(fulltarget,target); + } + } + if (target) + free(target); + } + return (fulltarget); +} + +/* + * Check and translate the target of an absolute symbolic link. + * + * An absolute target definition begins with "\" or "x:\" + * + * The absolute target is redefined as a relative link, + * - either to the target if found on the same device. + * - or into the /.NTFS-3G directory for the user to define + * In the first situation, the target is translated to case-sensitive path. + * + * returns the target converted to a relative symlink + * or NULL if there were some problem, as described by errno + */ + +static char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction, + int count, const char *mnt_point, BOOL isdir) +{ + char *target; + char *fulltarget; + int sz; + char *q; + enum { FULL_PATH, ABS_PATH, REJECTED_PATH } kind; + + target = (char*)NULL; + fulltarget = (char*)NULL; + /* + * For a full valid path we want x:\ + * where \ is an individual char and x a non-null char + */ + if ((count >= 3) + && junction[0] + && (junction[1] == const_cpu_to_le16(':')) + && (junction[2] == const_cpu_to_le16('\\'))) + kind = FULL_PATH; + else + /* + * For an absolute path we want an initial \ + */ + if ((count >= 0) + && (junction[0] == const_cpu_to_le16('\\'))) + kind = ABS_PATH; + else + kind = REJECTED_PATH; + /* + * Full path, with a drive letter and + * no specific definition for the drive letter : + * try to interpret as a target on the same volume. + * Do the same for an abs path with no drive letter. + */ + if (((kind == FULL_PATH) + && (count >= 3) + && junction[3] + && !ntfs_drive_letter(vol, junction[0])) + || (kind == ABS_PATH)) { + if (kind == ABS_PATH) + target = search_absolute(vol, &junction[1], + count - 1, isdir); + else + target = search_absolute(vol, &junction[3], + count - 3, isdir); + if (target) { + fulltarget = (char*)ntfs_malloc(strlen(mnt_point) + + strlen(target) + 2); + if (fulltarget) { + strcpy(fulltarget,mnt_point); + strcat(fulltarget,"/"); + strcat(fulltarget,target); + } + free(target); + } + } + /* + * full path with target not found on current volume : + * link to /.NTFS-3G/target which the user can + * define as a symbolic link to the real target + */ + if ((kind == FULL_PATH) && !fulltarget) { + sz = ntfs_ucstombs(&junction[0], + count,&target, 0); + if ((sz > 0) && target) { + /* reverse slashes */ + for (q=target; *q; q++) + if (*q == '\\') + *q = '/'; + /* force uppercase drive letter */ + if ((target[1] == ':') + && (target[0] >= 'a') + && (target[0] <= 'z')) + target[0] += 'A' - 'a'; + fulltarget = (char*)ntfs_malloc(strlen(mnt_point) + + sizeof(mappingdir) + strlen(target) + 1); + if (fulltarget) { + strcpy(fulltarget,mnt_point); + strcat(fulltarget,"/"); + strcat(fulltarget,mappingdir); + strcat(fulltarget,target); + } + } + if (target) + free(target); + } + return (fulltarget); +} + +/* + * Check and translate the target of a relative symbolic link. + * + * A relative target definition does not begin with "\" + * + * The original definition of relative target is kept, it is just + * translated to a case-sensitive path. + * + * returns the target converted to a relative symlink + * or NULL if there were some problem, as described by errno + */ + +static char *ntfs_get_rellink(ntfs_inode *ni, ntfschar *junction, int count) +{ + char *target; + + target = search_relative(ni,junction,count); + return (target); +} + +/* + * Get the target for a junction point or symbolic link + * Should only be called for files or directories with reparse data + * + * returns the target converted to a relative path, or NULL + * if some error occurred, as described by errno + * errno is EOPNOTSUPP if the reparse point is not a valid + * symbolic link or directory junction + */ + +char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point, + int *pattr_size) +{ + s64 attr_size = 0; + char *target; + unsigned int offs; + unsigned int lth; + ntfs_volume *vol; + REPARSE_POINT *reparse_attr; + struct MOUNT_POINT_REPARSE_DATA *mount_point_data; + struct SYMLINK_REPARSE_DATA *symlink_data; + enum { FULL_TARGET, ABS_TARGET, REL_TARGET } kind; + ntfschar *p; + BOOL bad; + BOOL isdir; + + target = (char*)NULL; + bad = TRUE; + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + vol = ni->vol; + reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, + AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); + if (reparse_attr && attr_size + && valid_reparse_data(ni, reparse_attr, attr_size)) { + switch (reparse_attr->reparse_tag) { + case IO_REPARSE_TAG_MOUNT_POINT : + mount_point_data = (struct MOUNT_POINT_REPARSE_DATA*) + reparse_attr->reparse_data; + offs = le16_to_cpu(mount_point_data->subst_name_offset); + lth = le16_to_cpu(mount_point_data->subst_name_length); + /* reparse data consistency has been checked */ + target = ntfs_get_fulllink(vol, + (ntfschar*)&mount_point_data->path_buffer[offs], + lth/2, mnt_point, isdir); + if (target) + bad = FALSE; + break; + case IO_REPARSE_TAG_SYMLINK : + symlink_data = (struct SYMLINK_REPARSE_DATA*) + reparse_attr->reparse_data; + offs = le16_to_cpu(symlink_data->subst_name_offset); + lth = le16_to_cpu(symlink_data->subst_name_length); + p = (ntfschar*)&symlink_data->path_buffer[offs]; + /* + * Predetermine the kind of target, + * the called function has to make a full check + */ + if (*p++ == const_cpu_to_le16('\\')) { + if ((*p == const_cpu_to_le16('?')) + || (*p == const_cpu_to_le16('\\'))) + kind = FULL_TARGET; + else + kind = ABS_TARGET; + } else + if (*p == const_cpu_to_le16(':')) + kind = ABS_TARGET; + else + kind = REL_TARGET; + p--; + /* reparse data consistency has been checked */ + switch (kind) { + case FULL_TARGET : + if (!(symlink_data->flags + & const_cpu_to_le32(1))) { + target = ntfs_get_fulllink(vol, + p, lth/2, + mnt_point, isdir); + if (target) + bad = FALSE; + } + break; + case ABS_TARGET : + if (symlink_data->flags + & const_cpu_to_le32(1)) { + target = ntfs_get_abslink(vol, + p, lth/2, + mnt_point, isdir); + if (target) + bad = FALSE; + } + break; + case REL_TARGET : + if (symlink_data->flags + & const_cpu_to_le32(1)) { + target = ntfs_get_rellink(ni, + p, lth/2); + if (target) + bad = FALSE; + } + break; + } + break; + } + free(reparse_attr); + } + *pattr_size = attr_size; + if (bad) + errno = EOPNOTSUPP; + return (target); +} + +/* + * Check whether a reparse point looks like a junction point + * or a symbolic link. + * Should only be called for files or directories with reparse data + * + * The validity of the target is not checked. + */ + +BOOL ntfs_possible_symlink(ntfs_inode *ni) +{ + s64 attr_size = 0; + REPARSE_POINT *reparse_attr; + BOOL possible; + + possible = FALSE; + reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, + AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); + if (reparse_attr && attr_size) { + switch (reparse_attr->reparse_tag) { + case IO_REPARSE_TAG_MOUNT_POINT : + case IO_REPARSE_TAG_SYMLINK : + possible = TRUE; + default : ; + } + free(reparse_attr); + } + return (possible); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Set the index for new reparse data + * + * Returns 0 if success + * -1 if failure, explained by errno + */ + +static int set_reparse_index(ntfs_inode *ni, ntfs_index_context *xr, + le32 reparse_tag) +{ + struct REPARSE_INDEX indx; + u64 file_id_cpu; + le64 file_id; + le16 seqn; + + seqn = ni->mrec->sequence_number; + file_id_cpu = MK_MREF(ni->mft_no,le16_to_cpu(seqn)); + file_id = cpu_to_le64(file_id_cpu); + indx.header.data_offset = const_cpu_to_le16( + sizeof(INDEX_ENTRY_HEADER) + + sizeof(REPARSE_INDEX_KEY)); + indx.header.data_length = const_cpu_to_le16(0); + indx.header.reservedV = const_cpu_to_le32(0); + indx.header.length = const_cpu_to_le16( + sizeof(struct REPARSE_INDEX)); + indx.header.key_length = const_cpu_to_le16( + sizeof(REPARSE_INDEX_KEY)); + indx.header.flags = const_cpu_to_le16(0); + indx.header.reserved = const_cpu_to_le16(0); + indx.key.reparse_tag = reparse_tag; + /* danger on processors which require proper alignment ! */ + memcpy(&indx.key.file_id, &file_id, 8); + indx.filling = const_cpu_to_le32(0); + ntfs_index_ctx_reinit(xr); + return (ntfs_ie_add(xr,(INDEX_ENTRY*)&indx)); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Remove a reparse data index entry if attribute present + * + * Returns the size of existing reparse data + * (the existing reparse tag is returned) + * -1 if failure, explained by errno + */ + +static int remove_reparse_index(ntfs_attr *na, ntfs_index_context *xr, + le32 *preparse_tag) +{ + REPARSE_INDEX_KEY key; + u64 file_id_cpu; + le64 file_id; + s64 size; + le16 seqn; + int ret; + + ret = na->data_size; + if (ret) { + /* read the existing reparse_tag */ + size = ntfs_attr_pread(na, 0, 4, preparse_tag); + if (size == 4) { + seqn = na->ni->mrec->sequence_number; + file_id_cpu = MK_MREF(na->ni->mft_no,le16_to_cpu(seqn)); + file_id = cpu_to_le64(file_id_cpu); + key.reparse_tag = *preparse_tag; + /* danger on processors which require proper alignment ! */ + memcpy(&key.file_id, &file_id, 8); + if (!ntfs_index_lookup(&key, sizeof(REPARSE_INDEX_KEY), xr) + && ntfs_index_rm(xr)) + ret = -1; + } else { + ret = -1; + errno = ENODATA; + } + } + return (ret); +} + +/* + * Open the $Extend/$Reparse file and its index + * + * Return the index context if opened + * or NULL if an error occurred (errno tells why) + * + * The index has to be freed and inode closed when not needed any more. + */ + +static ntfs_index_context *open_reparse_index(ntfs_volume *vol) +{ + u64 inum; + ntfs_inode *ni; + ntfs_inode *dir_ni; + ntfs_index_context *xr; + + /* do not use path_name_to inode - could reopen root */ + dir_ni = ntfs_inode_open(vol, FILE_Extend); + ni = (ntfs_inode*)NULL; + if (dir_ni) { + inum = ntfs_inode_lookup_by_mbsname(dir_ni,"$Reparse"); + if (inum != (u64)-1) + ni = ntfs_inode_open(vol, inum); + ntfs_inode_close(dir_ni); + } + if (ni) { + xr = ntfs_index_ctx_get(ni, reparse_index_name, 2); + if (!xr) { + ntfs_inode_close(ni); + } + } else + xr = (ntfs_index_context*)NULL; + return (xr); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Update the reparse data and index + * + * The reparse data attribute should have been created, and + * an existing index is expected if there is an existing value. + * + * Returns 0 if success + * -1 if failure, explained by errno + * If could not remove the existing index, nothing is done, + * If could not write the new data, no index entry is inserted + * If failed to insert the index, data is removed + */ + +static int update_reparse_data(ntfs_inode *ni, ntfs_index_context *xr, + const char *value, size_t size) +{ + int res; + int written; + int oldsize; + ntfs_attr *na; + le32 reparse_tag; + + res = 0; + na = ntfs_attr_open(ni, AT_REPARSE_POINT, AT_UNNAMED, 0); + if (na) { + /* remove the existing reparse data */ + oldsize = remove_reparse_index(na,xr,&reparse_tag); + if (oldsize < 0) + res = -1; + else { + /* resize attribute */ + res = ntfs_attr_truncate(na, (s64)size); + /* overwrite value if any */ + if (!res && value) { + written = (int)ntfs_attr_pwrite(na, + (s64)0, (s64)size, value); + if (written != (s64)size) { + ntfs_log_error("Failed to update " + "reparse data\n"); + errno = EIO; + res = -1; + } + } + if (!res + && set_reparse_index(ni,xr, + ((const REPARSE_POINT*)value)->reparse_tag) + && (oldsize > 0)) { + /* + * If cannot index, try to remove the reparse + * data and log the error. There will be an + * inconsistency if removal fails. + */ + ntfs_attr_rm(na); + ntfs_log_error("Failed to index reparse data." + " Possible corruption.\n"); + } + } + ntfs_attr_close(na); + NInoSetDirty(ni); + } else + res = -1; + return (res); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Delete a reparse index entry + * + * Returns 0 if success + * -1 if failure, explained by errno + */ + +int ntfs_delete_reparse_index(ntfs_inode *ni) +{ + ntfs_index_context *xr; + ntfs_inode *xrni; + ntfs_attr *na; + le32 reparse_tag; + int res; + + res = 0; + na = ntfs_attr_open(ni, AT_REPARSE_POINT, AT_UNNAMED, 0); + if (na) { + /* + * read the existing reparse data (the tag is enough) + * and un-index it + */ + xr = open_reparse_index(ni->vol); + if (xr) { + if (remove_reparse_index(na,xr,&reparse_tag) < 0) + res = -1; + xrni = xr->ni; + ntfs_index_entry_mark_dirty(xr); + NInoSetDirty(xrni); + ntfs_index_ctx_put(xr); + ntfs_inode_close(xrni); + } + ntfs_attr_close(na); + } + return (res); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Get the ntfs reparse data into an extended attribute + * + * Returns the reparse data size + * and the buffer is updated if it is long enough + */ + +int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size) +{ + REPARSE_POINT *reparse_attr; + s64 attr_size; + + attr_size = 0; /* default to no data and no error */ + if (ni) { + if (ni->flags & FILE_ATTR_REPARSE_POINT) { + reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, + AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); + if (reparse_attr) { + if (attr_size <= (s64)size) { + if (value) + memcpy(value,reparse_attr, + attr_size); + else + errno = EINVAL; + } + free(reparse_attr); + } + } else + errno = ENODATA; + } + return (attr_size ? (int)attr_size : -errno); +} + +/* + * Set the reparse data from an extended attribute + * + * Warning : the new data is not checked + * + * Returns 0, or -1 if there is a problem + */ + +int ntfs_set_ntfs_reparse_data(ntfs_inode *ni, + const char *value, size_t size, int flags) +{ + int res; + u8 dummy; + ntfs_inode *xrni; + ntfs_index_context *xr; + + res = 0; + if (ni && valid_reparse_data(ni, (const REPARSE_POINT*)value, size)) { + xr = open_reparse_index(ni->vol); + if (xr) { + if (!ntfs_attr_exist(ni,AT_REPARSE_POINT, + AT_UNNAMED,0)) { + if (!(flags & XATTR_REPLACE)) { + /* + * no reparse data attribute : add one, + * apparently, this does not feed the new value in + * Note : NTFS version must be >= 3 + */ + if (ni->vol->major_ver >= 3) { + res = ntfs_attr_add(ni, + AT_REPARSE_POINT, + AT_UNNAMED,0,&dummy, + (s64)0); + if (!res) { + ni->flags |= + FILE_ATTR_REPARSE_POINT; + NInoFileNameSetDirty(ni); + } + NInoSetDirty(ni); + } else { + errno = EOPNOTSUPP; + res = -1; + } + } else { + errno = ENODATA; + res = -1; + } + } else { + if (flags & XATTR_CREATE) { + errno = EEXIST; + res = -1; + } + } + if (!res) { + /* update value and index */ + res = update_reparse_data(ni,xr,value,size); + } + xrni = xr->ni; + ntfs_index_entry_mark_dirty(xr); + NInoSetDirty(xrni); + ntfs_index_ctx_put(xr); + ntfs_inode_close(xrni); + } else { + res = -1; + } + } else { + errno = EINVAL; + res = -1; + } + return (res ? -1 : 0); +} + +/* + * Remove the reparse data + * + * Returns 0, or -1 if there is a problem + */ + +int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni) +{ + int res; + int olderrno; + ntfs_attr *na; + ntfs_inode *xrni; + ntfs_index_context *xr; + le32 reparse_tag; + + res = 0; + if (ni) { + /* + * open and delete the reparse data + */ + na = ntfs_attr_open(ni, AT_REPARSE_POINT, + AT_UNNAMED,0); + if (na) { + /* first remove index (reparse data needed) */ + xr = open_reparse_index(ni->vol); + if (xr) { + if (remove_reparse_index(na,xr, + &reparse_tag) < 0) { + res = -1; + } else { + /* now remove attribute */ + res = ntfs_attr_rm(na); + if (!res) { + ni->flags &= + ~FILE_ATTR_REPARSE_POINT; + NInoFileNameSetDirty(ni); + } else { + /* + * If we could not remove the + * attribute, try to restore the + * index and log the error. There + * will be an inconsistency if + * the reindexing fails. + */ + set_reparse_index(ni, xr, + reparse_tag); + ntfs_log_error( + "Failed to remove reparse data." + " Possible corruption.\n"); + } + } + xrni = xr->ni; + ntfs_index_entry_mark_dirty(xr); + NInoSetDirty(xrni); + ntfs_index_ctx_put(xr); + ntfs_inode_close(xrni); + } + olderrno = errno; + ntfs_attr_close(na); + /* avoid errno pollution */ + if (errno == ENOENT) + errno = olderrno; + } else { + errno = ENODATA; + res = -1; + } + NInoSetDirty(ni); + } else { + errno = EINVAL; + res = -1; + } + return (res ? -1 : 0); +} + +#endif /* HAVE_SETXATTR */ diff --git a/libcustomntfs/reparse.h b/libcustomntfs/reparse.h new file mode 100644 index 00000000..35f4aa45 --- /dev/null +++ b/libcustomntfs/reparse.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2008 Jean-Pierre Andre + * + */ + +/* + * This program 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef REPARSE_H +#define REPARSE_H + +char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point, + int *pattr_size); +BOOL ntfs_possible_symlink(ntfs_inode *ni); + +int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size); + +int ntfs_set_ntfs_reparse_data(ntfs_inode *ni, const char *value, + size_t size, int flags); +int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni); + +int ntfs_delete_reparse_index(ntfs_inode *ni); + +#endif /* REPARSE_H */ diff --git a/libcustomntfs/runlist.c b/libcustomntfs/runlist.c new file mode 100644 index 00000000..cea24672 --- /dev/null +++ b/libcustomntfs/runlist.c @@ -0,0 +1,2181 @@ +/** + * runlist.c - Run list handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002-2005 Anton Altaparmakov + * Copyright (c) 2002-2005 Richard Russon + * Copyright (c) 2002-2008 Szabolcs Szakacsits + * Copyright (c) 2004 Yura Pakhuchiy + * Copyright (c) 2007-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif + +#include "compat.h" +#include "types.h" +#include "volume.h" +#include "layout.h" +#include "debug.h" +#include "device.h" +#include "logging.h" +#include "misc.h" + +/** + * ntfs_rl_mm - runlist memmove + * @base: + * @dst: + * @src: + * @size: + * + * Description... + * + * Returns: + */ +static void ntfs_rl_mm(runlist_element *base, int dst, int src, int size) +{ + if ((dst != src) && (size > 0)) + memmove(base + dst, base + src, size * sizeof(*base)); +} + +/** + * ntfs_rl_mc - runlist memory copy + * @dstbase: + * @dst: + * @srcbase: + * @src: + * @size: + * + * Description... + * + * Returns: + */ +static void ntfs_rl_mc(runlist_element *dstbase, int dst, + runlist_element *srcbase, int src, int size) +{ + if (size > 0) + memcpy(dstbase + dst, srcbase + src, size * sizeof(*dstbase)); +} + +/** + * ntfs_rl_realloc - Reallocate memory for runlists + * @rl: original runlist + * @old_size: number of runlist elements in the original runlist @rl + * @new_size: number of runlist elements we need space for + * + * As the runlists grow, more memory will be required. To prevent large + * numbers of small reallocations of memory, this function returns a 4kiB block + * of memory. + * + * N.B. If the new allocation doesn't require a different number of 4kiB + * blocks in memory, the function will return the original pointer. + * + * On success, return a pointer to the newly allocated, or recycled, memory. + * On error, return NULL with errno set to the error code. + */ +static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size, + int new_size) +{ + old_size = (old_size * sizeof(runlist_element) + 0xfff) & ~0xfff; + new_size = (new_size * sizeof(runlist_element) + 0xfff) & ~0xfff; + if (old_size == new_size) + return rl; + return realloc(rl, new_size); +} + +/* + * Extend a runlist by some entry count + * The runlist may have to be reallocated + * + * Returns the reallocated runlist + * or NULL if reallocation was not possible (with errno set) + * the runlist is left unchanged if the reallocation fails + */ + +runlist_element *ntfs_rl_extend(ntfs_attr *na, runlist_element *rl, + int more_entries) +{ + runlist_element *newrl; + int last; + int irl; + + if (na->rl && rl) { + irl = (int)(rl - na->rl); + last = irl; + while (na->rl[last].length) + last++; + newrl = ntfs_rl_realloc(na->rl,last+1,last+more_entries+1); + if (!newrl) { + errno = ENOMEM; + rl = (runlist_element*)NULL; + } else + na->rl = newrl; + rl = &newrl[irl]; + } else { + ntfs_log_error("Cannot extend unmapped runlist"); + errno = EIO; + rl = (runlist_element*)NULL; + } + return (rl); +} + +/** + * ntfs_rl_are_mergeable - test if two runlists can be joined together + * @dst: original runlist + * @src: new runlist to test for mergeability with @dst + * + * Test if two runlists can be joined together. For this, their VCNs and LCNs + * must be adjacent. + * + * Return: TRUE Success, the runlists can be merged. + * FALSE Failure, the runlists cannot be merged. + */ +static BOOL ntfs_rl_are_mergeable(runlist_element *dst, runlist_element *src) +{ + if (!dst || !src) { + ntfs_log_debug("Eeek. ntfs_rl_are_mergeable() invoked with NULL " + "pointer!\n"); + return FALSE; + } + + /* We can merge unmapped regions even if they are misaligned. */ + if ((dst->lcn == LCN_RL_NOT_MAPPED) && (src->lcn == LCN_RL_NOT_MAPPED)) + return TRUE; + /* If the runs are misaligned, we cannot merge them. */ + if ((dst->vcn + dst->length) != src->vcn) + return FALSE; + /* If both runs are non-sparse and contiguous, we can merge them. */ + if ((dst->lcn >= 0) && (src->lcn >= 0) && + ((dst->lcn + dst->length) == src->lcn)) + return TRUE; + /* If we are merging two holes, we can merge them. */ + if ((dst->lcn == LCN_HOLE) && (src->lcn == LCN_HOLE)) + return TRUE; + /* Cannot merge. */ + return FALSE; +} + +/** + * __ntfs_rl_merge - merge two runlists without testing if they can be merged + * @dst: original, destination runlist + * @src: new runlist to merge with @dst + * + * Merge the two runlists, writing into the destination runlist @dst. The + * caller must make sure the runlists can be merged or this will corrupt the + * destination runlist. + */ +static void __ntfs_rl_merge(runlist_element *dst, runlist_element *src) +{ + dst->length += src->length; +} + +/** + * ntfs_rl_append - append a runlist after a given element + * @dst: original runlist to be worked on + * @dsize: number of elements in @dst (including end marker) + * @src: runlist to be inserted into @dst + * @ssize: number of elements in @src (excluding end marker) + * @loc: append the new runlist @src after this element in @dst + * + * Append the runlist @src after element @loc in @dst. Merge the right end of + * the new runlist, if necessary. Adjust the size of the hole before the + * appended runlist. + * + * On success, return a pointer to the new, combined, runlist. Note, both + * runlists @dst and @src are deallocated before returning so you cannot use + * the pointers for anything any more. (Strictly speaking the returned runlist + * may be the same as @dst but this is irrelevant.) + * + * On error, return NULL, with errno set to the error code. Both runlists are + * left unmodified. + */ +static runlist_element *ntfs_rl_append(runlist_element *dst, int dsize, + runlist_element *src, int ssize, int loc) +{ + BOOL right = FALSE; /* Right end of @src needs merging */ + int marker; /* End of the inserted runs */ + + if (!dst || !src) { + ntfs_log_debug("Eeek. ntfs_rl_append() invoked with NULL " + "pointer!\n"); + errno = EINVAL; + return NULL; + } + + /* First, check if the right hand end needs merging. */ + if ((loc + 1) < dsize) + right = ntfs_rl_are_mergeable(src + ssize - 1, dst + loc + 1); + + /* Space required: @dst size + @src size, less one if we merged. */ + dst = ntfs_rl_realloc(dst, dsize, dsize + ssize - right); + if (!dst) + return NULL; + /* + * We are guaranteed to succeed from here so can start modifying the + * original runlists. + */ + + /* First, merge the right hand end, if necessary. */ + if (right) + __ntfs_rl_merge(src + ssize - 1, dst + loc + 1); + + /* marker - First run after the @src runs that have been inserted */ + marker = loc + ssize + 1; + + /* Move the tail of @dst out of the way, then copy in @src. */ + ntfs_rl_mm(dst, marker, loc + 1 + right, dsize - loc - 1 - right); + ntfs_rl_mc(dst, loc + 1, src, 0, ssize); + + /* Adjust the size of the preceding hole. */ + dst[loc].length = dst[loc + 1].vcn - dst[loc].vcn; + + /* We may have changed the length of the file, so fix the end marker */ + if (dst[marker].lcn == LCN_ENOENT) + dst[marker].vcn = dst[marker-1].vcn + dst[marker-1].length; + + return dst; +} + +/** + * ntfs_rl_insert - insert a runlist into another + * @dst: original runlist to be worked on + * @dsize: number of elements in @dst (including end marker) + * @src: new runlist to be inserted + * @ssize: number of elements in @src (excluding end marker) + * @loc: insert the new runlist @src before this element in @dst + * + * Insert the runlist @src before element @loc in the runlist @dst. Merge the + * left end of the new runlist, if necessary. Adjust the size of the hole + * after the inserted runlist. + * + * On success, return a pointer to the new, combined, runlist. Note, both + * runlists @dst and @src are deallocated before returning so you cannot use + * the pointers for anything any more. (Strictly speaking the returned runlist + * may be the same as @dst but this is irrelevant.) + * + * On error, return NULL, with errno set to the error code. Both runlists are + * left unmodified. + */ +static runlist_element *ntfs_rl_insert(runlist_element *dst, int dsize, + runlist_element *src, int ssize, int loc) +{ + BOOL left = FALSE; /* Left end of @src needs merging */ + BOOL disc = FALSE; /* Discontinuity between @dst and @src */ + int marker; /* End of the inserted runs */ + + if (!dst || !src) { + ntfs_log_debug("Eeek. ntfs_rl_insert() invoked with NULL " + "pointer!\n"); + errno = EINVAL; + return NULL; + } + + /* disc => Discontinuity between the end of @dst and the start of @src. + * This means we might need to insert a "notmapped" run. + */ + if (loc == 0) + disc = (src[0].vcn > 0); + else { + s64 merged_length; + + left = ntfs_rl_are_mergeable(dst + loc - 1, src); + + merged_length = dst[loc - 1].length; + if (left) + merged_length += src->length; + + disc = (src[0].vcn > dst[loc - 1].vcn + merged_length); + } + + /* Space required: @dst size + @src size, less one if we merged, plus + * one if there was a discontinuity. + */ + dst = ntfs_rl_realloc(dst, dsize, dsize + ssize - left + disc); + if (!dst) + return NULL; + /* + * We are guaranteed to succeed from here so can start modifying the + * original runlist. + */ + + if (left) + __ntfs_rl_merge(dst + loc - 1, src); + + /* + * marker - First run after the @src runs that have been inserted + * Nominally: marker = @loc + @ssize (location + number of runs in @src) + * If "left", then the first run in @src has been merged with one in @dst. + * If "disc", then @dst and @src don't meet and we need an extra run to fill the gap. + */ + marker = loc + ssize - left + disc; + + /* Move the tail of @dst out of the way, then copy in @src. */ + ntfs_rl_mm(dst, marker, loc, dsize - loc); + ntfs_rl_mc(dst, loc + disc, src, left, ssize - left); + + /* Adjust the VCN of the first run after the insertion ... */ + dst[marker].vcn = dst[marker - 1].vcn + dst[marker - 1].length; + /* ... and the length. */ + if (dst[marker].lcn == LCN_HOLE || dst[marker].lcn == LCN_RL_NOT_MAPPED) + dst[marker].length = dst[marker + 1].vcn - dst[marker].vcn; + + /* Writing beyond the end of the file and there's a discontinuity. */ + if (disc) { + if (loc > 0) { + dst[loc].vcn = dst[loc - 1].vcn + dst[loc - 1].length; + dst[loc].length = dst[loc + 1].vcn - dst[loc].vcn; + } else { + dst[loc].vcn = 0; + dst[loc].length = dst[loc + 1].vcn; + } + dst[loc].lcn = LCN_RL_NOT_MAPPED; + } + return dst; +} + +/** + * ntfs_rl_replace - overwrite a runlist element with another runlist + * @dst: original runlist to be worked on + * @dsize: number of elements in @dst (including end marker) + * @src: new runlist to be inserted + * @ssize: number of elements in @src (excluding end marker) + * @loc: index in runlist @dst to overwrite with @src + * + * Replace the runlist element @dst at @loc with @src. Merge the left and + * right ends of the inserted runlist, if necessary. + * + * On success, return a pointer to the new, combined, runlist. Note, both + * runlists @dst and @src are deallocated before returning so you cannot use + * the pointers for anything any more. (Strictly speaking the returned runlist + * may be the same as @dst but this is irrelevant.) + * + * On error, return NULL, with errno set to the error code. Both runlists are + * left unmodified. + */ +static runlist_element *ntfs_rl_replace(runlist_element *dst, int dsize, + runlist_element *src, int ssize, + int loc) +{ + signed delta; + BOOL left = FALSE; /* Left end of @src needs merging */ + BOOL right = FALSE; /* Right end of @src needs merging */ + int tail; /* Start of tail of @dst */ + int marker; /* End of the inserted runs */ + + if (!dst || !src) { + ntfs_log_debug("Eeek. ntfs_rl_replace() invoked with NULL " + "pointer!\n"); + errno = EINVAL; + return NULL; + } + + /* First, see if the left and right ends need merging. */ + if ((loc + 1) < dsize) + right = ntfs_rl_are_mergeable(src + ssize - 1, dst + loc + 1); + if (loc > 0) + left = ntfs_rl_are_mergeable(dst + loc - 1, src); + + /* Allocate some space. We'll need less if the left, right, or both + * ends get merged. The -1 accounts for the run being replaced. + */ + delta = ssize - 1 - left - right; + if (delta > 0) { + dst = ntfs_rl_realloc(dst, dsize, dsize + delta); + if (!dst) + return NULL; + } + /* + * We are guaranteed to succeed from here so can start modifying the + * original runlists. + */ + + /* First, merge the left and right ends, if necessary. */ + if (right) + __ntfs_rl_merge(src + ssize - 1, dst + loc + 1); + if (left) + __ntfs_rl_merge(dst + loc - 1, src); + + /* + * tail - Offset of the tail of @dst + * Nominally: @tail = @loc + 1 (location, skipping the replaced run) + * If "right", then one of @dst's runs is already merged into @src. + */ + tail = loc + right + 1; + + /* + * marker - First run after the @src runs that have been inserted + * Nominally: @marker = @loc + @ssize (location + number of runs in @src) + * If "left", then the first run in @src has been merged with one in @dst. + */ + marker = loc + ssize - left; + + /* Move the tail of @dst out of the way, then copy in @src. */ + ntfs_rl_mm(dst, marker, tail, dsize - tail); + ntfs_rl_mc(dst, loc, src, left, ssize - left); + + /* We may have changed the length of the file, so fix the end marker */ + if (((dsize - tail) > 0) && (dst[marker].lcn == LCN_ENOENT)) + dst[marker].vcn = dst[marker - 1].vcn + dst[marker - 1].length; + + return dst; +} + +/** + * ntfs_rl_split - insert a runlist into the centre of a hole + * @dst: original runlist to be worked on + * @dsize: number of elements in @dst (including end marker) + * @src: new runlist to be inserted + * @ssize: number of elements in @src (excluding end marker) + * @loc: index in runlist @dst at which to split and insert @src + * + * Split the runlist @dst at @loc into two and insert @new in between the two + * fragments. No merging of runlists is necessary. Adjust the size of the + * holes either side. + * + * On success, return a pointer to the new, combined, runlist. Note, both + * runlists @dst and @src are deallocated before returning so you cannot use + * the pointers for anything any more. (Strictly speaking the returned runlist + * may be the same as @dst but this is irrelevant.) + * + * On error, return NULL, with errno set to the error code. Both runlists are + * left unmodified. + */ +static runlist_element *ntfs_rl_split(runlist_element *dst, int dsize, + runlist_element *src, int ssize, int loc) +{ + if (!dst || !src) { + ntfs_log_debug("Eeek. ntfs_rl_split() invoked with NULL pointer!\n"); + errno = EINVAL; + return NULL; + } + + /* Space required: @dst size + @src size + one new hole. */ + dst = ntfs_rl_realloc(dst, dsize, dsize + ssize + 1); + if (!dst) + return dst; + /* + * We are guaranteed to succeed from here so can start modifying the + * original runlists. + */ + + /* Move the tail of @dst out of the way, then copy in @src. */ + ntfs_rl_mm(dst, loc + 1 + ssize, loc, dsize - loc); + ntfs_rl_mc(dst, loc + 1, src, 0, ssize); + + /* Adjust the size of the holes either size of @src. */ + dst[loc].length = dst[loc+1].vcn - dst[loc].vcn; + dst[loc+ssize+1].vcn = dst[loc+ssize].vcn + dst[loc+ssize].length; + dst[loc+ssize+1].length = dst[loc+ssize+2].vcn - dst[loc+ssize+1].vcn; + + return dst; +} + + +/** + * ntfs_runlists_merge_i - see ntfs_runlists_merge + */ +static runlist_element *ntfs_runlists_merge_i(runlist_element *drl, + runlist_element *srl) +{ + int di, si; /* Current index into @[ds]rl. */ + int sstart; /* First index with lcn > LCN_RL_NOT_MAPPED. */ + int dins; /* Index into @drl at which to insert @srl. */ + int dend, send; /* Last index into @[ds]rl. */ + int dfinal, sfinal; /* The last index into @[ds]rl with + lcn >= LCN_HOLE. */ + int marker = 0; + VCN marker_vcn = 0; + + ntfs_log_debug("dst:\n"); + ntfs_debug_runlist_dump(drl); + ntfs_log_debug("src:\n"); + ntfs_debug_runlist_dump(srl); + + /* Check for silly calling... */ + if (!srl) + return drl; + + /* Check for the case where the first mapping is being done now. */ + if (!drl) { + drl = srl; + /* Complete the source runlist if necessary. */ + if (drl[0].vcn) { + /* Scan to the end of the source runlist. */ + for (dend = 0; drl[dend].length; dend++) + ; + dend++; + drl = ntfs_rl_realloc(drl, dend, dend + 1); + if (!drl) + return drl; + /* Insert start element at the front of the runlist. */ + ntfs_rl_mm(drl, 1, 0, dend); + drl[0].vcn = 0; + drl[0].lcn = LCN_RL_NOT_MAPPED; + drl[0].length = drl[1].vcn; + } + goto finished; + } + + si = di = 0; + + /* Skip any unmapped start element(s) in the source runlist. */ + while (srl[si].length && srl[si].lcn < (LCN)LCN_HOLE) + si++; + + /* Can't have an entirely unmapped source runlist. */ + if (!srl[si].length) { + errno = EINVAL; + ntfs_log_perror("%s: unmapped source runlist", __FUNCTION__); + return NULL; + } + + /* Record the starting points. */ + sstart = si; + + /* + * Skip forward in @drl until we reach the position where @srl needs to + * be inserted. If we reach the end of @drl, @srl just needs to be + * appended to @drl. + */ + for (; drl[di].length; di++) { + if (drl[di].vcn + drl[di].length > srl[sstart].vcn) + break; + } + dins = di; + + /* Sanity check for illegal overlaps. */ + if ((drl[di].vcn == srl[si].vcn) && (drl[di].lcn >= 0) && + (srl[si].lcn >= 0)) { + errno = ERANGE; + ntfs_log_perror("Run lists overlap. Cannot merge"); + return NULL; + } + + /* Scan to the end of both runlists in order to know their sizes. */ + for (send = si; srl[send].length; send++) + ; + for (dend = di; drl[dend].length; dend++) + ; + + if (srl[send].lcn == (LCN)LCN_ENOENT) + marker_vcn = srl[marker = send].vcn; + + /* Scan to the last element with lcn >= LCN_HOLE. */ + for (sfinal = send; sfinal >= 0 && srl[sfinal].lcn < LCN_HOLE; sfinal--) + ; + for (dfinal = dend; dfinal >= 0 && drl[dfinal].lcn < LCN_HOLE; dfinal--) + ; + + { + BOOL start; + BOOL finish; + int ds = dend + 1; /* Number of elements in drl & srl */ + int ss = sfinal - sstart + 1; + + start = ((drl[dins].lcn < LCN_RL_NOT_MAPPED) || /* End of file */ + (drl[dins].vcn == srl[sstart].vcn)); /* Start of hole */ + finish = ((drl[dins].lcn >= LCN_RL_NOT_MAPPED) && /* End of file */ + ((drl[dins].vcn + drl[dins].length) <= /* End of hole */ + (srl[send - 1].vcn + srl[send - 1].length))); + + /* Or we'll lose an end marker */ + if (finish && !drl[dins].length) + ss++; + if (marker && (drl[dins].vcn + drl[dins].length > srl[send - 1].vcn)) + finish = FALSE; + + ntfs_log_debug("dfinal = %i, dend = %i\n", dfinal, dend); + ntfs_log_debug("sstart = %i, sfinal = %i, send = %i\n", sstart, sfinal, send); + ntfs_log_debug("start = %i, finish = %i\n", start, finish); + ntfs_log_debug("ds = %i, ss = %i, dins = %i\n", ds, ss, dins); + + if (start) { + if (finish) + drl = ntfs_rl_replace(drl, ds, srl + sstart, ss, dins); + else + drl = ntfs_rl_insert(drl, ds, srl + sstart, ss, dins); + } else { + if (finish) + drl = ntfs_rl_append(drl, ds, srl + sstart, ss, dins); + else + drl = ntfs_rl_split(drl, ds, srl + sstart, ss, dins); + } + if (!drl) { + ntfs_log_perror("Merge failed"); + return drl; + } + free(srl); + if (marker) { + ntfs_log_debug("Triggering marker code.\n"); + for (ds = dend; drl[ds].length; ds++) + ; + /* We only need to care if @srl ended after @drl. */ + if (drl[ds].vcn <= marker_vcn) { + int slots = 0; + + if (drl[ds].vcn == marker_vcn) { + ntfs_log_debug("Old marker = %lli, replacing with " + "LCN_ENOENT.\n", + (long long)drl[ds].lcn); + drl[ds].lcn = (LCN)LCN_ENOENT; + goto finished; + } + /* + * We need to create an unmapped runlist element in + * @drl or extend an existing one before adding the + * ENOENT terminator. + */ + if (drl[ds].lcn == (LCN)LCN_ENOENT) { + ds--; + slots = 1; + } + if (drl[ds].lcn != (LCN)LCN_RL_NOT_MAPPED) { + /* Add an unmapped runlist element. */ + if (!slots) { + /* FIXME/TODO: We need to have the + * extra memory already! (AIA) + */ + drl = ntfs_rl_realloc(drl, ds, ds + 2); + if (!drl) + goto critical_error; + slots = 2; + } + ds++; + /* Need to set vcn if it isn't set already. */ + if (slots != 1) + drl[ds].vcn = drl[ds - 1].vcn + + drl[ds - 1].length; + drl[ds].lcn = (LCN)LCN_RL_NOT_MAPPED; + /* We now used up a slot. */ + slots--; + } + drl[ds].length = marker_vcn - drl[ds].vcn; + /* Finally add the ENOENT terminator. */ + ds++; + if (!slots) { + /* FIXME/TODO: We need to have the extra + * memory already! (AIA) + */ + drl = ntfs_rl_realloc(drl, ds, ds + 1); + if (!drl) + goto critical_error; + } + drl[ds].vcn = marker_vcn; + drl[ds].lcn = (LCN)LCN_ENOENT; + drl[ds].length = (s64)0; + } + } + } + +finished: + /* The merge was completed successfully. */ + ntfs_log_debug("Merged runlist:\n"); + ntfs_debug_runlist_dump(drl); + return drl; + +critical_error: + /* Critical error! We cannot afford to fail here. */ + ntfs_log_perror("libntfs: Critical error"); + ntfs_log_debug("Forcing segmentation fault!\n"); + marker_vcn = ((runlist*)NULL)->lcn; + return drl; +} + +/** + * ntfs_runlists_merge - merge two runlists into one + * @drl: original runlist to be worked on + * @srl: new runlist to be merged into @drl + * + * First we sanity check the two runlists @srl and @drl to make sure that they + * are sensible and can be merged. The runlist @srl must be either after the + * runlist @drl or completely within a hole (or unmapped region) in @drl. + * + * Merging of runlists is necessary in two cases: + * 1. When attribute lists are used and a further extent is being mapped. + * 2. When new clusters are allocated to fill a hole or extend a file. + * + * There are four possible ways @srl can be merged. It can: + * - be inserted at the beginning of a hole, + * - split the hole in two and be inserted between the two fragments, + * - be appended at the end of a hole, or it can + * - replace the whole hole. + * It can also be appended to the end of the runlist, which is just a variant + * of the insert case. + * + * On success, return a pointer to the new, combined, runlist. Note, both + * runlists @drl and @srl are deallocated before returning so you cannot use + * the pointers for anything any more. (Strictly speaking the returned runlist + * may be the same as @dst but this is irrelevant.) + * + * On error, return NULL, with errno set to the error code. Both runlists are + * left unmodified. The following error codes are defined: + * ENOMEM Not enough memory to allocate runlist array. + * EINVAL Invalid parameters were passed in. + * ERANGE The runlists overlap and cannot be merged. + */ +runlist_element *ntfs_runlists_merge(runlist_element *drl, + runlist_element *srl) +{ + runlist_element *rl; + + ntfs_log_enter("Entering\n"); + rl = ntfs_runlists_merge_i(drl, srl); + ntfs_log_leave("\n"); + return rl; +} + +/** + * ntfs_mapping_pairs_decompress - convert mapping pairs array to runlist + * @vol: ntfs volume on which the attribute resides + * @attr: attribute record whose mapping pairs array to decompress + * @old_rl: optional runlist in which to insert @attr's runlist + * + * Decompress the attribute @attr's mapping pairs array into a runlist. On + * success, return the decompressed runlist. + * + * If @old_rl is not NULL, decompressed runlist is inserted into the + * appropriate place in @old_rl and the resultant, combined runlist is + * returned. The original @old_rl is deallocated. + * + * On error, return NULL with errno set to the error code. @old_rl is left + * unmodified in that case. + * + * The following error codes are defined: + * ENOMEM Not enough memory to allocate runlist array. + * EIO Corrupt runlist. + * EINVAL Invalid parameters were passed in. + * ERANGE The two runlists overlap. + * + * FIXME: For now we take the conceptionally simplest approach of creating the + * new runlist disregarding the already existing one and then splicing the + * two into one, if that is possible (we check for overlap and discard the new + * runlist if overlap present before returning NULL, with errno = ERANGE). + */ +static runlist_element *ntfs_mapping_pairs_decompress_i(const ntfs_volume *vol, + const ATTR_RECORD *attr, runlist_element *old_rl) +{ + VCN vcn; /* Current vcn. */ + LCN lcn; /* Current lcn. */ + s64 deltaxcn; /* Change in [vl]cn. */ + runlist_element *rl; /* The output runlist. */ + const u8 *buf; /* Current position in mapping pairs array. */ + const u8 *attr_end; /* End of attribute. */ + int err, rlsize; /* Size of runlist buffer. */ + u16 rlpos; /* Current runlist position in units of + runlist_elements. */ + u8 b; /* Current byte offset in buf. */ + + ntfs_log_trace("Entering for attr 0x%x.\n", + (unsigned)le32_to_cpu(attr->type)); + /* Make sure attr exists and is non-resident. */ + if (!attr || !attr->non_resident || + sle64_to_cpu(attr->lowest_vcn) < (VCN)0) { + errno = EINVAL; + return NULL; + } + /* Start at vcn = lowest_vcn and lcn 0. */ + vcn = sle64_to_cpu(attr->lowest_vcn); + lcn = 0; + /* Get start of the mapping pairs array. */ + buf = (const u8*)attr + le16_to_cpu(attr->mapping_pairs_offset); + attr_end = (const u8*)attr + le32_to_cpu(attr->length); + if (buf < (const u8*)attr || buf > attr_end) { + ntfs_log_debug("Corrupt attribute.\n"); + errno = EIO; + return NULL; + } + /* Current position in runlist array. */ + rlpos = 0; + /* Allocate first 4kiB block and set current runlist size to 4kiB. */ + rlsize = 0x1000; + rl = ntfs_malloc(rlsize); + if (!rl) + return NULL; + /* Insert unmapped starting element if necessary. */ + if (vcn) { + rl->vcn = (VCN)0; + rl->lcn = (LCN)LCN_RL_NOT_MAPPED; + rl->length = vcn; + rlpos++; + } + while (buf < attr_end && *buf) { + /* + * Allocate more memory if needed, including space for the + * not-mapped and terminator elements. + */ + if ((int)((rlpos + 3) * sizeof(*old_rl)) > rlsize) { + runlist_element *rl2; + + rlsize += 0x1000; + rl2 = realloc(rl, rlsize); + if (!rl2) { + int eo = errno; + free(rl); + errno = eo; + return NULL; + } + rl = rl2; + } + /* Enter the current vcn into the current runlist element. */ + rl[rlpos].vcn = vcn; + /* + * Get the change in vcn, i.e. the run length in clusters. + * Doing it this way ensures that we signextend negative values. + * A negative run length doesn't make any sense, but hey, I + * didn't make up the NTFS specs and Windows NT4 treats the run + * length as a signed value so that's how it is... + */ + b = *buf & 0xf; + if (b) { + if (buf + b > attr_end) + goto io_error; + for (deltaxcn = (s8)buf[b--]; b; b--) + deltaxcn = (deltaxcn << 8) + buf[b]; + } else { /* The length entry is compulsory. */ + ntfs_log_debug("Missing length entry in mapping pairs " + "array.\n"); + deltaxcn = (s64)-1; + } + /* + * Assume a negative length to indicate data corruption and + * hence clean-up and return NULL. + */ + if (deltaxcn < 0) { + ntfs_log_debug("Invalid length in mapping pairs array.\n"); + goto err_out; + } + /* + * Enter the current run length into the current runlist + * element. + */ + rl[rlpos].length = deltaxcn; + /* Increment the current vcn by the current run length. */ + vcn += deltaxcn; + /* + * There might be no lcn change at all, as is the case for + * sparse clusters on NTFS 3.0+, in which case we set the lcn + * to LCN_HOLE. + */ + if (!(*buf & 0xf0)) + rl[rlpos].lcn = (LCN)LCN_HOLE; + else { + /* Get the lcn change which really can be negative. */ + u8 b2 = *buf & 0xf; + b = b2 + ((*buf >> 4) & 0xf); + if (buf + b > attr_end) + goto io_error; + for (deltaxcn = (s8)buf[b--]; b > b2; b--) + deltaxcn = (deltaxcn << 8) + buf[b]; + /* Change the current lcn to it's new value. */ + lcn += deltaxcn; +#ifdef DEBUG + /* + * On NTFS 1.2-, apparently can have lcn == -1 to + * indicate a hole. But we haven't verified ourselves + * whether it is really the lcn or the deltaxcn that is + * -1. So if either is found give us a message so we + * can investigate it further! + */ + if (vol->major_ver < 3) { + if (deltaxcn == (LCN)-1) + ntfs_log_debug("lcn delta == -1\n"); + if (lcn == (LCN)-1) + ntfs_log_debug("lcn == -1\n"); + } +#endif + /* Check lcn is not below -1. */ + if (lcn < (LCN)-1) { + ntfs_log_debug("Invalid LCN < -1 in mapping pairs " + "array.\n"); + goto err_out; + } + /* Enter the current lcn into the runlist element. */ + rl[rlpos].lcn = lcn; + } + /* Get to the next runlist element. */ + rlpos++; + /* Increment the buffer position to the next mapping pair. */ + buf += (*buf & 0xf) + ((*buf >> 4) & 0xf) + 1; + } + if (buf >= attr_end) + goto io_error; + /* + * If there is a highest_vcn specified, it must be equal to the final + * vcn in the runlist - 1, or something has gone badly wrong. + */ + deltaxcn = sle64_to_cpu(attr->highest_vcn); + if (deltaxcn && vcn - 1 != deltaxcn) { +mpa_err: + ntfs_log_debug("Corrupt mapping pairs array in non-resident " + "attribute.\n"); + goto err_out; + } + /* Setup not mapped runlist element if this is the base extent. */ + if (!attr->lowest_vcn) { + VCN max_cluster; + + max_cluster = ((sle64_to_cpu(attr->allocated_size) + + vol->cluster_size - 1) >> + vol->cluster_size_bits) - 1; + /* + * A highest_vcn of zero means this is a single extent + * attribute so simply terminate the runlist with LCN_ENOENT). + */ + if (deltaxcn) { + /* + * If there is a difference between the highest_vcn and + * the highest cluster, the runlist is either corrupt + * or, more likely, there are more extents following + * this one. + */ + if (deltaxcn < max_cluster) { + ntfs_log_debug("More extents to follow; deltaxcn = " + "0x%llx, max_cluster = 0x%llx\n", + (long long)deltaxcn, + (long long)max_cluster); + rl[rlpos].vcn = vcn; + vcn += rl[rlpos].length = max_cluster - deltaxcn; + rl[rlpos].lcn = (LCN)LCN_RL_NOT_MAPPED; + rlpos++; + } else if (deltaxcn > max_cluster) { + ntfs_log_debug("Corrupt attribute. deltaxcn = " + "0x%llx, max_cluster = 0x%llx\n", + (long long)deltaxcn, + (long long)max_cluster); + goto mpa_err; + } + } + rl[rlpos].lcn = (LCN)LCN_ENOENT; + } else /* Not the base extent. There may be more extents to follow. */ + rl[rlpos].lcn = (LCN)LCN_RL_NOT_MAPPED; + + /* Setup terminating runlist element. */ + rl[rlpos].vcn = vcn; + rl[rlpos].length = (s64)0; + /* If no existing runlist was specified, we are done. */ + if (!old_rl) { + ntfs_log_debug("Mapping pairs array successfully decompressed:\n"); + ntfs_debug_runlist_dump(rl); + return rl; + } + /* Now combine the new and old runlists checking for overlaps. */ + old_rl = ntfs_runlists_merge(old_rl, rl); + if (old_rl) + return old_rl; + err = errno; + free(rl); + ntfs_log_debug("Failed to merge runlists.\n"); + errno = err; + return NULL; +io_error: + ntfs_log_debug("Corrupt attribute.\n"); +err_out: + free(rl); + errno = EIO; + return NULL; +} + +runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, + const ATTR_RECORD *attr, runlist_element *old_rl) +{ + runlist_element *rle; + + ntfs_log_enter("Entering\n"); + rle = ntfs_mapping_pairs_decompress_i(vol, attr, old_rl); + ntfs_log_leave("\n"); + return rle; +} + +/** + * ntfs_rl_vcn_to_lcn - convert a vcn into a lcn given a runlist + * @rl: runlist to use for conversion + * @vcn: vcn to convert + * + * Convert the virtual cluster number @vcn of an attribute into a logical + * cluster number (lcn) of a device using the runlist @rl to map vcns to their + * corresponding lcns. + * + * Since lcns must be >= 0, we use negative return values with special meaning: + * + * Return value Meaning / Description + * ================================================== + * -1 = LCN_HOLE Hole / not allocated on disk. + * -2 = LCN_RL_NOT_MAPPED This is part of the runlist which has not been + * inserted into the runlist yet. + * -3 = LCN_ENOENT There is no such vcn in the attribute. + * -4 = LCN_EINVAL Input parameter error. + */ +LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn) +{ + int i; + + if (vcn < (VCN)0) + return (LCN)LCN_EINVAL; + /* + * If rl is NULL, assume that we have found an unmapped runlist. The + * caller can then attempt to map it and fail appropriately if + * necessary. + */ + if (!rl) + return (LCN)LCN_RL_NOT_MAPPED; + + /* Catch out of lower bounds vcn. */ + if (vcn < rl[0].vcn) + return (LCN)LCN_ENOENT; + + for (i = 0; rl[i].length; i++) { + if (vcn < rl[i+1].vcn) { + if (rl[i].lcn >= (LCN)0) + return rl[i].lcn + (vcn - rl[i].vcn); + return rl[i].lcn; + } + } + /* + * The terminator element is setup to the correct value, i.e. one of + * LCN_HOLE, LCN_RL_NOT_MAPPED, or LCN_ENOENT. + */ + if (rl[i].lcn < (LCN)0) + return rl[i].lcn; + /* Just in case... We could replace this with BUG() some day. */ + return (LCN)LCN_ENOENT; +} + +/** + * ntfs_rl_pread - gather read from disk + * @vol: ntfs volume to read from + * @rl: runlist specifying where to read the data from + * @pos: byte position within runlist @rl at which to begin the read + * @count: number of bytes to read + * @b: data buffer into which to read from disk + * + * This function will read @count bytes from the volume @vol to the data buffer + * @b gathering the data as specified by the runlist @rl. The read begins at + * offset @pos into the runlist @rl. + * + * On success, return the number of successfully read bytes. If this number is + * lower than @count this means that the read reached end of file or that an + * error was encountered during the read so that the read is partial. 0 means + * nothing was read (also return 0 when @count is 0). + * + * On error and nothing has been read, return -1 with errno set appropriately + * to the return code of ntfs_pread(), or to EINVAL in case of invalid + * arguments. + * + * NOTE: If we encounter EOF while reading we return EIO because we assume that + * the run list must point to valid locations within the ntfs volume. + */ +s64 ntfs_rl_pread(const ntfs_volume *vol, const runlist_element *rl, + const s64 pos, s64 count, void *b) +{ + s64 bytes_read, to_read, ofs, total; + int err = EIO; + + if (!vol || !rl || pos < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("Failed to read runlist [vol: %p rl: %p " + "pos: %lld count: %lld]", vol, rl, + (long long)pos, (long long)count); + return -1; + } + if (!count) + return count; + /* Seek in @rl to the run containing @pos. */ + for (ofs = 0; rl->length && (ofs + (rl->length << + vol->cluster_size_bits) <= pos); rl++) + ofs += (rl->length << vol->cluster_size_bits); + /* Offset in the run at which to begin reading. */ + ofs = pos - ofs; + for (total = 0LL; count; rl++, ofs = 0) { + if (!rl->length) + goto rl_err_out; + if (rl->lcn < (LCN)0) { + if (rl->lcn != (LCN)LCN_HOLE) + goto rl_err_out; + /* It is a hole. Just fill buffer @b with zeroes. */ + to_read = min(count, (rl->length << + vol->cluster_size_bits) - ofs); + memset(b, 0, to_read); + /* Update counters and proceed with next run. */ + total += to_read; + count -= to_read; + b = (u8*)b + to_read; + continue; + } + /* It is a real lcn, read it from the volume. */ + to_read = min(count, (rl->length << vol->cluster_size_bits) - + ofs); +retry: + bytes_read = ntfs_pread(vol->dev, (rl->lcn << + vol->cluster_size_bits) + ofs, to_read, b); + /* If everything ok, update progress counters and continue. */ + if (bytes_read > 0) { + total += bytes_read; + count -= bytes_read; + b = (u8*)b + bytes_read; + continue; + } + /* If the syscall was interrupted, try again. */ + if (bytes_read == (s64)-1 && errno == EINTR) + goto retry; + if (bytes_read == (s64)-1) + err = errno; + goto rl_err_out; + } + /* Finally, return the number of bytes read. */ + return total; +rl_err_out: + if (total) + return total; + errno = err; + return -1; +} + +/** + * ntfs_rl_pwrite - scatter write to disk + * @vol: ntfs volume to write to + * @rl: runlist entry specifying where to write the data to + * @ofs: offset in file for runlist element indicated in @rl + * @pos: byte position from runlist beginning at which to begin the write + * @count: number of bytes to write + * @b: data buffer to write to disk + * + * This function will write @count bytes from data buffer @b to the volume @vol + * scattering the data as specified by the runlist @rl. The write begins at + * offset @pos into the runlist @rl. If a run is sparse then the related buffer + * data is ignored which means that the caller must ensure they are consistent. + * + * On success, return the number of successfully written bytes. If this number + * is lower than @count this means that the write has been interrupted in + * flight or that an error was encountered during the write so that the write + * is partial. 0 means nothing was written (also return 0 when @count is 0). + * + * On error and nothing has been written, return -1 with errno set + * appropriately to the return code of ntfs_pwrite(), or to to EINVAL in case + * of invalid arguments. + */ +s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl, + s64 ofs, const s64 pos, s64 count, void *b) +{ + s64 written, to_write, total = 0; + int err = EIO; + + if (!vol || !rl || pos < 0 || count < 0) { + errno = EINVAL; + ntfs_log_perror("Failed to write runlist [vol: %p rl: %p " + "pos: %lld count: %lld]", vol, rl, + (long long)pos, (long long)count); + goto errno_set; + } + if (!count) + goto out; + /* Seek in @rl to the run containing @pos. */ + while (rl->length && (ofs + (rl->length << + vol->cluster_size_bits) <= pos)) { + ofs += (rl->length << vol->cluster_size_bits); + rl++; + } + /* Offset in the run at which to begin writing. */ + ofs = pos - ofs; + for (total = 0LL; count; rl++, ofs = 0) { + if (!rl->length) + goto rl_err_out; + if (rl->lcn < (LCN)0) { + + if (rl->lcn != (LCN)LCN_HOLE) + goto rl_err_out; + + to_write = min(count, (rl->length << + vol->cluster_size_bits) - ofs); + + total += to_write; + count -= to_write; + b = (u8*)b + to_write; + continue; + } + /* It is a real lcn, write it to the volume. */ + to_write = min(count, (rl->length << vol->cluster_size_bits) - + ofs); +retry: + if (!NVolReadOnly(vol)) + written = ntfs_pwrite(vol->dev, (rl->lcn << + vol->cluster_size_bits) + ofs, + to_write, b); + else + written = to_write; + /* If everything ok, update progress counters and continue. */ + if (written > 0) { + total += written; + count -= written; + b = (u8*)b + written; + continue; + } + /* If the syscall was interrupted, try again. */ + if (written == (s64)-1 && errno == EINTR) + goto retry; + if (written == (s64)-1) + err = errno; + goto rl_err_out; + } +out: + return total; +rl_err_out: + if (total) + goto out; + errno = err; +errno_set: + total = -1; + goto out; +} + +/** + * ntfs_get_nr_significant_bytes - get number of bytes needed to store a number + * @n: number for which to get the number of bytes for + * + * Return the number of bytes required to store @n unambiguously as + * a signed number. + * + * This is used in the context of the mapping pairs array to determine how + * many bytes will be needed in the array to store a given logical cluster + * number (lcn) or a specific run length. + * + * Return the number of bytes written. This function cannot fail. + */ +int ntfs_get_nr_significant_bytes(const s64 n) +{ + u64 l; + int i; + + l = (n < 0 ? ~n : n); + i = 1; + if (l >= 128) { + l >>= 7; + do { + i++; + l >>= 8; + } while (l); + } + return i; +} + +/** + * ntfs_get_size_for_mapping_pairs - get bytes needed for mapping pairs array + * @vol: ntfs volume (needed for the ntfs version) + * @rl: runlist for which to determine the size of the mapping pairs + * @start_vcn: vcn at which to start the mapping pairs array + * + * Walk the runlist @rl and calculate the size in bytes of the mapping pairs + * array corresponding to the runlist @rl, starting at vcn @start_vcn. This + * for example allows us to allocate a buffer of the right size when building + * the mapping pairs array. + * + * If @rl is NULL, just return 1 (for the single terminator byte). + * + * Return the calculated size in bytes on success. On error, return -1 with + * errno set to the error code. The following error codes are defined: + * EINVAL - Run list contains unmapped elements. Make sure to only pass + * fully mapped runlists to this function. + * - @start_vcn is invalid. + * EIO - The runlist is corrupt. + */ +int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol, + const runlist_element *rl, const VCN start_vcn, int max_size) +{ + LCN prev_lcn; + int rls; + + if (start_vcn < 0) { + ntfs_log_trace("start_vcn %lld (should be >= 0)\n", + (long long) start_vcn); + errno = EINVAL; + goto errno_set; + } + if (!rl) { + if (start_vcn) { + ntfs_log_trace("rl NULL, start_vcn %lld (should be > 0)\n", + (long long) start_vcn); + errno = EINVAL; + goto errno_set; + } + rls = 1; + goto out; + } + /* Skip to runlist element containing @start_vcn. */ + while (rl->length && start_vcn >= rl[1].vcn) + rl++; + if ((!rl->length && start_vcn > rl->vcn) || start_vcn < rl->vcn) { + errno = EINVAL; + goto errno_set; + } + prev_lcn = 0; + /* Always need the terminating zero byte. */ + rls = 1; + /* Do the first partial run if present. */ + if (start_vcn > rl->vcn) { + s64 delta; + + /* We know rl->length != 0 already. */ + if (rl->length < 0 || rl->lcn < LCN_HOLE) + goto err_out; + delta = start_vcn - rl->vcn; + /* Header byte + length. */ + rls += 1 + ntfs_get_nr_significant_bytes(rl->length - delta); + /* + * If the logical cluster number (lcn) denotes a hole and we + * are on NTFS 3.0+, we don't store it at all, i.e. we need + * zero space. On earlier NTFS versions we just store the lcn. + * Note: this assumes that on NTFS 1.2-, holes are stored with + * an lcn of -1 and not a delta_lcn of -1 (unless both are -1). + */ + if (rl->lcn >= 0 || vol->major_ver < 3) { + prev_lcn = rl->lcn; + if (rl->lcn >= 0) + prev_lcn += delta; + /* Change in lcn. */ + rls += ntfs_get_nr_significant_bytes(prev_lcn); + } + /* Go to next runlist element. */ + rl++; + } + /* Do the full runs. */ + for (; rl->length && (rls <= max_size); rl++) { + if (rl->length < 0 || rl->lcn < LCN_HOLE) + goto err_out; + /* Header byte + length. */ + rls += 1 + ntfs_get_nr_significant_bytes(rl->length); + /* + * If the logical cluster number (lcn) denotes a hole and we + * are on NTFS 3.0+, we don't store it at all, i.e. we need + * zero space. On earlier NTFS versions we just store the lcn. + * Note: this assumes that on NTFS 1.2-, holes are stored with + * an lcn of -1 and not a delta_lcn of -1 (unless both are -1). + */ + if (rl->lcn >= 0 || vol->major_ver < 3) { + /* Change in lcn. */ + rls += ntfs_get_nr_significant_bytes(rl->lcn - + prev_lcn); + prev_lcn = rl->lcn; + } + } +out: + return rls; +err_out: + if (rl->lcn == LCN_RL_NOT_MAPPED) + errno = EINVAL; + else + errno = EIO; +errno_set: + rls = -1; + goto out; +} + +/** + * ntfs_write_significant_bytes - write the significant bytes of a number + * @dst: destination buffer to write to + * @dst_max: pointer to last byte of destination buffer for bounds checking + * @n: number whose significant bytes to write + * + * Store in @dst, the minimum bytes of the number @n which are required to + * identify @n unambiguously as a signed number, taking care not to exceed + * @dest_max, the maximum position within @dst to which we are allowed to + * write. + * + * This is used when building the mapping pairs array of a runlist to compress + * a given logical cluster number (lcn) or a specific run length to the minimum + * size possible. + * + * Return the number of bytes written on success. On error, i.e. the + * destination buffer @dst is too small, return -1 with errno set ENOSPC. + */ +int ntfs_write_significant_bytes(u8 *dst, const u8 *dst_max, const s64 n) +{ + s64 l = n; + int i; + s8 j; + + i = 0; + do { + if (dst > dst_max) + goto err_out; + *dst++ = l & 0xffLL; + l >>= 8; + i++; + } while (l != 0LL && l != -1LL); + j = (n >> 8 * (i - 1)) & 0xff; + /* If the sign bit is wrong, we need an extra byte. */ + if (n < 0LL && j >= 0) { + if (dst > dst_max) + goto err_out; + i++; + *dst = (u8)-1; + } else if (n > 0LL && j < 0) { + if (dst > dst_max) + goto err_out; + i++; + *dst = 0; + } + return i; +err_out: + errno = ENOSPC; + return -1; +} + +/** + * ntfs_mapping_pairs_build - build the mapping pairs array from a runlist + * @vol: ntfs volume (needed for the ntfs version) + * @dst: destination buffer to which to write the mapping pairs array + * @dst_len: size of destination buffer @dst in bytes + * @rl: runlist for which to build the mapping pairs array + * @start_vcn: vcn at which to start the mapping pairs array + * @stop_vcn: first vcn outside destination buffer on success or ENOSPC error + * + * Create the mapping pairs array from the runlist @rl, starting at vcn + * @start_vcn and save the array in @dst. @dst_len is the size of @dst in + * bytes and it should be at least equal to the value obtained by calling + * ntfs_get_size_for_mapping_pairs(). + * + * If @rl is NULL, just write a single terminator byte to @dst. + * + * On success or ENOSPC error, if @stop_vcn is not NULL, *@stop_vcn is set to + * the first vcn outside the destination buffer. Note that on error @dst has + * been filled with all the mapping pairs that will fit, thus it can be treated + * as partial success, in that a new attribute extent needs to be created or the + * next extent has to be used and the mapping pairs build has to be continued + * with @start_vcn set to *@stop_vcn. + * + * Return 0 on success. On error, return -1 with errno set to the error code. + * The following error codes are defined: + * EINVAL - Run list contains unmapped elements. Make sure to only pass + * fully mapped runlists to this function. + * - @start_vcn is invalid. + * EIO - The runlist is corrupt. + * ENOSPC - The destination buffer is too small. + */ +int ntfs_mapping_pairs_build(const ntfs_volume *vol, u8 *dst, + const int dst_len, const runlist_element *rl, + const VCN start_vcn, runlist_element const **stop_rl) +{ + LCN prev_lcn; + u8 *dst_max, *dst_next; + s8 len_len, lcn_len; + int ret = 0; + + if (start_vcn < 0) + goto val_err; + if (!rl) { + if (start_vcn) + goto val_err; + if (stop_rl) + *stop_rl = rl; + if (dst_len < 1) + goto nospc_err; + goto ok; + } + /* Skip to runlist element containing @start_vcn. */ + while (rl->length && start_vcn >= rl[1].vcn) + rl++; + if ((!rl->length && start_vcn > rl->vcn) || start_vcn < rl->vcn) + goto val_err; + /* + * @dst_max is used for bounds checking in + * ntfs_write_significant_bytes(). + */ + dst_max = dst + dst_len - 1; + prev_lcn = 0; + /* Do the first partial run if present. */ + if (start_vcn > rl->vcn) { + s64 delta; + + /* We know rl->length != 0 already. */ + if (rl->length < 0 || rl->lcn < LCN_HOLE) + goto err_out; + delta = start_vcn - rl->vcn; + /* Write length. */ + len_len = ntfs_write_significant_bytes(dst + 1, dst_max, + rl->length - delta); + if (len_len < 0) + goto size_err; + /* + * If the logical cluster number (lcn) denotes a hole and we + * are on NTFS 3.0+, we don't store it at all, i.e. we need + * zero space. On earlier NTFS versions we just write the lcn + * change. FIXME: Do we need to write the lcn change or just + * the lcn in that case? Not sure as I have never seen this + * case on NT4. - We assume that we just need to write the lcn + * change until someone tells us otherwise... (AIA) + */ + if (rl->lcn >= 0 || vol->major_ver < 3) { + prev_lcn = rl->lcn; + if (rl->lcn >= 0) + prev_lcn += delta; + /* Write change in lcn. */ + lcn_len = ntfs_write_significant_bytes(dst + 1 + + len_len, dst_max, prev_lcn); + if (lcn_len < 0) + goto size_err; + } else + lcn_len = 0; + dst_next = dst + len_len + lcn_len + 1; + if (dst_next > dst_max) + goto size_err; + /* Update header byte. */ + *dst = lcn_len << 4 | len_len; + /* Position at next mapping pairs array element. */ + dst = dst_next; + /* Go to next runlist element. */ + rl++; + } + /* Do the full runs. */ + for (; rl->length; rl++) { + if (rl->length < 0 || rl->lcn < LCN_HOLE) + goto err_out; + /* Write length. */ + len_len = ntfs_write_significant_bytes(dst + 1, dst_max, + rl->length); + if (len_len < 0) + goto size_err; + /* + * If the logical cluster number (lcn) denotes a hole and we + * are on NTFS 3.0+, we don't store it at all, i.e. we need + * zero space. On earlier NTFS versions we just write the lcn + * change. FIXME: Do we need to write the lcn change or just + * the lcn in that case? Not sure as I have never seen this + * case on NT4. - We assume that we just need to write the lcn + * change until someone tells us otherwise... (AIA) + */ + if (rl->lcn >= 0 || vol->major_ver < 3) { + /* Write change in lcn. */ + lcn_len = ntfs_write_significant_bytes(dst + 1 + + len_len, dst_max, rl->lcn - prev_lcn); + if (lcn_len < 0) + goto size_err; + prev_lcn = rl->lcn; + } else + lcn_len = 0; + dst_next = dst + len_len + lcn_len + 1; + if (dst_next > dst_max) + goto size_err; + /* Update header byte. */ + *dst = lcn_len << 4 | len_len; + /* Position at next mapping pairs array element. */ + dst += 1 + len_len + lcn_len; + } + /* Set stop vcn. */ + if (stop_rl) + *stop_rl = rl; +ok: + /* Add terminator byte. */ + *dst = 0; +out: + return ret; +size_err: + /* Set stop vcn. */ + if (stop_rl) + *stop_rl = rl; + /* Add terminator byte. */ + *dst = 0; +nospc_err: + errno = ENOSPC; + goto errno_set; +val_err: + errno = EINVAL; + goto errno_set; +err_out: + if (rl->lcn == LCN_RL_NOT_MAPPED) + errno = EINVAL; + else + errno = EIO; +errno_set: + ret = -1; + goto out; +} + +/** + * ntfs_rl_truncate - truncate a runlist starting at a specified vcn + * @arl: address of runlist to truncate + * @start_vcn: first vcn which should be cut off + * + * Truncate the runlist *@arl starting at vcn @start_vcn as well as the memory + * buffer holding the runlist. + * + * Return 0 on success and -1 on error with errno set to the error code. + * + * NOTE: @arl is the address of the runlist. We need the address so we can + * modify the pointer to the runlist with the new, reallocated memory buffer. + */ +int ntfs_rl_truncate(runlist **arl, const VCN start_vcn) +{ + runlist *rl; + BOOL is_end = FALSE; + + if (!arl || !*arl) { + errno = EINVAL; + if (!arl) + ntfs_log_perror("rl_truncate error: arl: %p", arl); + else + ntfs_log_perror("rl_truncate error:" + " arl: %p *arl: %p", arl, *arl); + return -1; + } + + rl = *arl; + + if (start_vcn < rl->vcn) { + errno = EINVAL; + ntfs_log_perror("Start_vcn lies outside front of runlist"); + return -1; + } + + /* Find the starting vcn in the run list. */ + while (rl->length) { + if (start_vcn < rl[1].vcn) + break; + rl++; + } + + if (!rl->length) { + errno = EIO; + ntfs_log_trace("Truncating already truncated runlist?\n"); + return -1; + } + + /* Truncate the run. */ + rl->length = start_vcn - rl->vcn; + + /* + * If a run was partially truncated, make the following runlist + * element a terminator instead of the truncated runlist + * element itself. + */ + if (rl->length) { + ++rl; + if (!rl->length) + is_end = TRUE; + rl->vcn = start_vcn; + rl->length = 0; + } + rl->lcn = (LCN)LCN_ENOENT; + /** + * Reallocate memory if necessary. + * FIXME: Below code is broken, because runlist allocations must be + * a multiply of 4096. The code caused crashes and corruptions. + */ +/* + if (!is_end) { + size_t new_size = (rl - *arl + 1) * sizeof(runlist_element); + rl = realloc(*arl, new_size); + if (rl) + *arl = rl; + } +*/ + return 0; +} + +/** + * ntfs_rl_sparse - check whether runlist have sparse regions or not. + * @rl: runlist to check + * + * Return 1 if have, 0 if not, -1 on error with errno set to the error code. + */ +int ntfs_rl_sparse(runlist *rl) +{ + runlist *rlc; + + if (!rl) { + errno = EINVAL; + ntfs_log_perror("%s: ", __FUNCTION__); + return -1; + } + + for (rlc = rl; rlc->length; rlc++) + if (rlc->lcn < 0) { + if (rlc->lcn != LCN_HOLE) { + errno = EINVAL; + ntfs_log_perror("%s: bad runlist", __FUNCTION__); + return -1; + } + return 1; + } + return 0; +} + +/** + * ntfs_rl_get_compressed_size - calculate length of non sparse regions + * @vol: ntfs volume (need for cluster size) + * @rl: runlist to calculate for + * + * Return compressed size or -1 on error with errno set to the error code. + */ +s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl) +{ + runlist *rlc; + s64 ret = 0; + + if (!rl) { + errno = EINVAL; + ntfs_log_perror("%s: ", __FUNCTION__); + return -1; + } + + for (rlc = rl; rlc->length; rlc++) { + if (rlc->lcn < 0) { + if (rlc->lcn != LCN_HOLE) { + errno = EINVAL; + ntfs_log_perror("%s: bad runlist", __FUNCTION__); + return -1; + } + } else + ret += rlc->length; + } + return ret << vol->cluster_size_bits; +} + + +#ifdef NTFS_TEST +/** + * test_rl_helper + */ +#define MKRL(R,V,L,S) \ + (R)->vcn = V; \ + (R)->lcn = L; \ + (R)->length = S; +/* +} +*/ +/** + * test_rl_dump_runlist - Runlist test: Display the contents of a runlist + * @rl: + * + * Description... + * + * Returns: + */ +static void test_rl_dump_runlist(const runlist_element *rl) +{ + int abbr = 0; /* abbreviate long lists */ + int len = 0; + int i; + const char *lcn_str[5] = { "HOLE", "NOTMAP", "ENOENT", "XXXX" }; + + if (!rl) { + printf(" Run list not present.\n"); + return; + } + + if (abbr) + for (len = 0; rl[len].length; len++) ; + + printf(" VCN LCN len\n"); + for (i = 0; ; i++, rl++) { + LCN lcn = rl->lcn; + + if ((abbr) && (len > 20)) { + if (i == 4) + printf(" ...\n"); + if ((i > 3) && (i < (len - 3))) + continue; + } + + if (lcn < (LCN)0) { + int ind = -lcn - 1; + + if (ind > -LCN_ENOENT - 1) + ind = 3; + printf("%8lld %8s %8lld\n", + rl->vcn, lcn_str[ind], rl->length); + } else + printf("%8lld %8lld %8lld\n", + rl->vcn, rl->lcn, rl->length); + if (!rl->length) + break; + } + if ((abbr) && (len > 20)) + printf(" (%d entries)\n", len+1); + printf("\n"); +} + +/** + * test_rl_runlists_merge - Runlist test: Merge two runlists + * @drl: + * @srl: + * + * Description... + * + * Returns: + */ +static runlist_element * test_rl_runlists_merge(runlist_element *drl, runlist_element *srl) +{ + runlist_element *res = NULL; + + printf("dst:\n"); + test_rl_dump_runlist(drl); + printf("src:\n"); + test_rl_dump_runlist(srl); + + res = ntfs_runlists_merge(drl, srl); + + printf("res:\n"); + test_rl_dump_runlist(res); + + return res; +} + +/** + * test_rl_read_buffer - Runlist test: Read a file containing a runlist + * @file: + * @buf: + * @bufsize: + * + * Description... + * + * Returns: + */ +static int test_rl_read_buffer(const char *file, u8 *buf, int bufsize) +{ + FILE *fptr; + + fptr = fopen(file, "r"); + if (!fptr) { + printf("open %s\n", file); + return 0; + } + + if (fread(buf, bufsize, 1, fptr) == 99) { + printf("read %s\n", file); + return 0; + } + + fclose(fptr); + return 1; +} + +/** + * test_rl_pure_src - Runlist test: Complicate the simple tests a little + * @contig: + * @multi: + * @vcn: + * @len: + * + * Description... + * + * Returns: + */ +static runlist_element * test_rl_pure_src(BOOL contig, BOOL multi, int vcn, int len) +{ + runlist_element *result; + int fudge; + + if (contig) + fudge = 0; + else + fudge = 999; + + result = ntfs_malloc(4096); + if (!result) + return NULL; + + if (multi) { + MKRL(result+0, vcn + (0*len/4), fudge + vcn + 1000 + (0*len/4), len / 4) + MKRL(result+1, vcn + (1*len/4), fudge + vcn + 1000 + (1*len/4), len / 4) + MKRL(result+2, vcn + (2*len/4), fudge + vcn + 1000 + (2*len/4), len / 4) + MKRL(result+3, vcn + (3*len/4), fudge + vcn + 1000 + (3*len/4), len / 4) + MKRL(result+4, vcn + (4*len/4), LCN_RL_NOT_MAPPED, 0) + } else { + MKRL(result+0, vcn, fudge + vcn + 1000, len) + MKRL(result+1, vcn + len, LCN_RL_NOT_MAPPED, 0) + } + return result; +} + +/** + * test_rl_pure_test - Runlist test: Perform tests using simple runlists + * @test: + * @contig: + * @multi: + * @vcn: + * @len: + * @file: + * @size: + * + * Description... + * + * Returns: + */ +static void test_rl_pure_test(int test, BOOL contig, BOOL multi, int vcn, int len, runlist_element *file, int size) +{ + runlist_element *src; + runlist_element *dst; + runlist_element *res; + + src = test_rl_pure_src(contig, multi, vcn, len); + dst = ntfs_malloc(4096); + if (!src || !dst) { + printf("Test %2d ---------- FAILED! (no free memory?)\n", test); + return; + } + + memcpy(dst, file, size); + + printf("Test %2d ----------\n", test); + res = test_rl_runlists_merge(dst, src); + + free(res); +} + +/** + * test_rl_pure - Runlist test: Create tests using simple runlists + * @contig: + * @multi: + * + * Description... + * + * Returns: + */ +static void test_rl_pure(char *contig, char *multi) +{ + /* VCN, LCN, len */ + static runlist_element file1[] = { + { 0, -1, 100 }, /* HOLE */ + { 100, 1100, 100 }, /* DATA */ + { 200, -1, 100 }, /* HOLE */ + { 300, 1300, 100 }, /* DATA */ + { 400, -1, 100 }, /* HOLE */ + { 500, -3, 0 } /* NOENT */ + }; + static runlist_element file2[] = { + { 0, 1000, 100 }, /* DATA */ + { 100, -1, 100 }, /* HOLE */ + { 200, -3, 0 } /* NOENT */ + }; + static runlist_element file3[] = { + { 0, 1000, 100 }, /* DATA */ + { 100, -3, 0 } /* NOENT */ + }; + static runlist_element file4[] = { + { 0, -3, 0 } /* NOENT */ + }; + static runlist_element file5[] = { + { 0, -2, 100 }, /* NOTMAP */ + { 100, 1100, 100 }, /* DATA */ + { 200, -2, 100 }, /* NOTMAP */ + { 300, 1300, 100 }, /* DATA */ + { 400, -2, 100 }, /* NOTMAP */ + { 500, -3, 0 } /* NOENT */ + }; + static runlist_element file6[] = { + { 0, 1000, 100 }, /* DATA */ + { 100, -2, 100 }, /* NOTMAP */ + { 200, -3, 0 } /* NOENT */ + }; + BOOL c, m; + + if (strcmp(contig, "contig") == 0) + c = TRUE; + else if (strcmp(contig, "noncontig") == 0) + c = FALSE; + else { + printf("rl pure [contig|noncontig] [single|multi]\n"); + return; + } + if (strcmp(multi, "multi") == 0) + m = TRUE; + else if (strcmp(multi, "single") == 0) + m = FALSE; + else { + printf("rl pure [contig|noncontig] [single|multi]\n"); + return; + } + + test_rl_pure_test(1, c, m, 0, 40, file1, sizeof(file1)); + test_rl_pure_test(2, c, m, 40, 40, file1, sizeof(file1)); + test_rl_pure_test(3, c, m, 60, 40, file1, sizeof(file1)); + test_rl_pure_test(4, c, m, 0, 100, file1, sizeof(file1)); + test_rl_pure_test(5, c, m, 200, 40, file1, sizeof(file1)); + test_rl_pure_test(6, c, m, 240, 40, file1, sizeof(file1)); + test_rl_pure_test(7, c, m, 260, 40, file1, sizeof(file1)); + test_rl_pure_test(8, c, m, 200, 100, file1, sizeof(file1)); + test_rl_pure_test(9, c, m, 400, 40, file1, sizeof(file1)); + test_rl_pure_test(10, c, m, 440, 40, file1, sizeof(file1)); + test_rl_pure_test(11, c, m, 460, 40, file1, sizeof(file1)); + test_rl_pure_test(12, c, m, 400, 100, file1, sizeof(file1)); + test_rl_pure_test(13, c, m, 160, 100, file2, sizeof(file2)); + test_rl_pure_test(14, c, m, 100, 140, file2, sizeof(file2)); + test_rl_pure_test(15, c, m, 200, 40, file2, sizeof(file2)); + test_rl_pure_test(16, c, m, 240, 40, file2, sizeof(file2)); + test_rl_pure_test(17, c, m, 100, 40, file3, sizeof(file3)); + test_rl_pure_test(18, c, m, 140, 40, file3, sizeof(file3)); + test_rl_pure_test(19, c, m, 0, 40, file4, sizeof(file4)); + test_rl_pure_test(20, c, m, 40, 40, file4, sizeof(file4)); + test_rl_pure_test(21, c, m, 0, 40, file5, sizeof(file5)); + test_rl_pure_test(22, c, m, 40, 40, file5, sizeof(file5)); + test_rl_pure_test(23, c, m, 60, 40, file5, sizeof(file5)); + test_rl_pure_test(24, c, m, 0, 100, file5, sizeof(file5)); + test_rl_pure_test(25, c, m, 200, 40, file5, sizeof(file5)); + test_rl_pure_test(26, c, m, 240, 40, file5, sizeof(file5)); + test_rl_pure_test(27, c, m, 260, 40, file5, sizeof(file5)); + test_rl_pure_test(28, c, m, 200, 100, file5, sizeof(file5)); + test_rl_pure_test(29, c, m, 400, 40, file5, sizeof(file5)); + test_rl_pure_test(30, c, m, 440, 40, file5, sizeof(file5)); + test_rl_pure_test(31, c, m, 460, 40, file5, sizeof(file5)); + test_rl_pure_test(32, c, m, 400, 100, file5, sizeof(file5)); + test_rl_pure_test(33, c, m, 160, 100, file6, sizeof(file6)); + test_rl_pure_test(34, c, m, 100, 140, file6, sizeof(file6)); +} + +/** + * test_rl_zero - Runlist test: Merge a zero-length runlist + * + * Description... + * + * Returns: + */ +static void test_rl_zero(void) +{ + runlist_element *jim = NULL; + runlist_element *bob = NULL; + + bob = calloc(3, sizeof(runlist_element)); + if (!bob) + return; + + MKRL(bob+0, 10, 99, 5) + MKRL(bob+1, 15, LCN_RL_NOT_MAPPED, 0) + + jim = test_rl_runlists_merge(jim, bob); + if (!jim) + return; + + free(jim); +} + +/** + * test_rl_frag_combine - Runlist test: Perform tests using fragmented files + * @vol: + * @attr1: + * @attr2: + * @attr3: + * + * Description... + * + * Returns: + */ +static void test_rl_frag_combine(ntfs_volume *vol, ATTR_RECORD *attr1, ATTR_RECORD *attr2, ATTR_RECORD *attr3) +{ + runlist_element *run1; + runlist_element *run2; + runlist_element *run3; + + run1 = ntfs_mapping_pairs_decompress(vol, attr1, NULL); + if (!run1) + return; + + run2 = ntfs_mapping_pairs_decompress(vol, attr2, NULL); + if (!run2) + return; + + run1 = test_rl_runlists_merge(run1, run2); + + run3 = ntfs_mapping_pairs_decompress(vol, attr3, NULL); + if (!run3) + return; + + run1 = test_rl_runlists_merge(run1, run3); + + free(run1); +} + +/** + * test_rl_frag - Runlist test: Create tests using very fragmented files + * @test: + * + * Description... + * + * Returns: + */ +static void test_rl_frag(char *test) +{ + ntfs_volume vol; + ATTR_RECORD *attr1 = ntfs_malloc(1024); + ATTR_RECORD *attr2 = ntfs_malloc(1024); + ATTR_RECORD *attr3 = ntfs_malloc(1024); + + if (!attr1 || !attr2 || !attr3) + goto out; + + vol.sb = NULL; + vol.sector_size_bits = 9; + vol.cluster_size = 2048; + vol.cluster_size_bits = 11; + vol.major_ver = 3; + + if (!test_rl_read_buffer("runlist-data/attr1.bin", (u8*) attr1, 1024)) + goto out; + if (!test_rl_read_buffer("runlist-data/attr2.bin", (u8*) attr2, 1024)) + goto out; + if (!test_rl_read_buffer("runlist-data/attr3.bin", (u8*) attr3, 1024)) + goto out; + + if (strcmp(test, "123") == 0) test_rl_frag_combine(&vol, attr1, attr2, attr3); + else if (strcmp(test, "132") == 0) test_rl_frag_combine(&vol, attr1, attr3, attr2); + else if (strcmp(test, "213") == 0) test_rl_frag_combine(&vol, attr2, attr1, attr3); + else if (strcmp(test, "231") == 0) test_rl_frag_combine(&vol, attr2, attr3, attr1); + else if (strcmp(test, "312") == 0) test_rl_frag_combine(&vol, attr3, attr1, attr2); + else if (strcmp(test, "321") == 0) test_rl_frag_combine(&vol, attr3, attr2, attr1); + else + printf("Frag: No such test '%s'\n", test); + +out: + free(attr1); + free(attr2); + free(attr3); +} + +/** + * test_rl_main - Runlist test: Program start (main) + * @argc: + * @argv: + * + * Description... + * + * Returns: + */ +int test_rl_main(int argc, char *argv[]) +{ + if ((argc == 2) && (strcmp(argv[1], "zero") == 0)) test_rl_zero(); + else if ((argc == 3) && (strcmp(argv[1], "frag") == 0)) test_rl_frag(argv[2]); + else if ((argc == 4) && (strcmp(argv[1], "pure") == 0)) test_rl_pure(argv[2], argv[3]); + else + printf("rl [zero|frag|pure] {args}\n"); + + return 0; +} + +#endif + diff --git a/libcustomntfs/runlist.h b/libcustomntfs/runlist.h new file mode 100644 index 00000000..4b73af9f --- /dev/null +++ b/libcustomntfs/runlist.h @@ -0,0 +1,90 @@ +/* + * runlist.h - Exports for runlist handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2002 Anton Altaparmakov + * Copyright (c) 2002 Richard Russon + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_RUNLIST_H +#define _NTFS_RUNLIST_H + +#include "types.h" + +/* Forward declarations */ +typedef struct _runlist_element runlist_element; +typedef runlist_element runlist; + +#include "attrib.h" +#include "volume.h" + +/** + * struct _runlist_element - in memory vcn to lcn mapping array element. + * @vcn: starting vcn of the current array element + * @lcn: starting lcn of the current array element + * @length: length in clusters of the current array element + * + * The last vcn (in fact the last vcn + 1) is reached when length == 0. + * + * When lcn == -1 this means that the count vcns starting at vcn are not + * physically allocated (i.e. this is a hole / data is sparse). + */ +struct _runlist_element {/* In memory vcn to lcn mapping structure element. */ + VCN vcn; /* vcn = Starting virtual cluster number. */ + LCN lcn; /* lcn = Starting logical cluster number. */ + s64 length; /* Run length in clusters. */ +}; + +extern runlist_element *ntfs_rl_extend(ntfs_attr *na, runlist_element *rl, + int more_entries); + +extern LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn); + +extern s64 ntfs_rl_pread(const ntfs_volume *vol, const runlist_element *rl, + const s64 pos, s64 count, void *b); +extern s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl, + s64 ofs, const s64 pos, s64 count, void *b); + +extern runlist_element *ntfs_runlists_merge(runlist_element *drl, + runlist_element *srl); + +extern runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, + const ATTR_RECORD *attr, runlist_element *old_rl); + +extern int ntfs_get_nr_significant_bytes(const s64 n); + +extern int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol, + const runlist_element *rl, const VCN start_vcn, int max_size); + +extern int ntfs_write_significant_bytes(u8 *dst, const u8 *dst_max, + const s64 n); + +extern int ntfs_mapping_pairs_build(const ntfs_volume *vol, u8 *dst, + const int dst_len, const runlist_element *rl, + const VCN start_vcn, runlist_element const **stop_rl); + +extern int ntfs_rl_truncate(runlist **arl, const VCN start_vcn); + +extern int ntfs_rl_sparse(runlist *rl); +extern s64 ntfs_rl_get_compressed_size(ntfs_volume *vol, runlist *rl); + +#ifdef NTFS_TEST +int test_rl_main(int argc, char *argv[]); +#endif + +#endif /* defined _NTFS_RUNLIST_H */ + diff --git a/libcustomntfs/security.c b/libcustomntfs/security.c new file mode 100644 index 00000000..138764ba --- /dev/null +++ b/libcustomntfs/security.c @@ -0,0 +1,5184 @@ +/** + * security.c - Handling security/ACLs in NTFS. Originated from the Linux-NTFS project. + * + * Copyright (c) 2004 Anton Altaparmakov + * Copyright (c) 2005-2006 Szabolcs Szakacsits + * Copyright (c) 2006 Yura Pakhuchiy + * Copyright (c) 2007-2009 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_SETXATTR +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif + +#include +#include +#include + +#include "param.h" +#include "types.h" +#include "layout.h" +#include "attrib.h" +#include "index.h" +#include "dir.h" +#include "bitmap.h" +#include "security.h" +#include "acls.h" +#include "cache.h" +#include "misc.h" + +/* + * JPA NTFS constants or structs + * should be moved to layout.h + */ + +#define ALIGN_SDS_BLOCK 0x40000 /* Alignment for a $SDS block */ +#define ALIGN_SDS_ENTRY 16 /* Alignment for a $SDS entry */ +#define STUFFSZ 0x4000 /* unitary stuffing size for $SDS */ +#define FIRST_SECURITY_ID 0x100 /* Lowest security id */ + + /* Mask for attributes which can be forced */ +#define FILE_ATTR_SETTABLE ( FILE_ATTR_READONLY \ + | FILE_ATTR_HIDDEN \ + | FILE_ATTR_SYSTEM \ + | FILE_ATTR_ARCHIVE \ + | FILE_ATTR_TEMPORARY \ + | FILE_ATTR_OFFLINE \ + | FILE_ATTR_NOT_CONTENT_INDEXED ) + +struct SII { /* this is an image of an $SII index entry */ + le16 offs; + le16 size; + le32 fill1; + le16 indexsz; + le16 indexksz; + le16 flags; + le16 fill2; + le32 keysecurid; + + /* did not find official description for the following */ + le32 hash; + le32 securid; + le32 dataoffsl; /* documented as badly aligned */ + le32 dataoffsh; + le32 datasize; +} ; + +struct SDH { /* this is an image of an $SDH index entry */ + le16 offs; + le16 size; + le32 fill1; + le16 indexsz; + le16 indexksz; + le16 flags; + le16 fill2; + le32 keyhash; + le32 keysecurid; + + /* did not find official description for the following */ + le32 hash; + le32 securid; + le32 dataoffsl; + le32 dataoffsh; + le32 datasize; + le32 fill3; + } ; + +/* + * A few useful constants + */ + +static ntfschar sii_stream[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('S'), + const_cpu_to_le16('I'), + const_cpu_to_le16('I'), + const_cpu_to_le16(0) }; +static ntfschar sdh_stream[] = { const_cpu_to_le16('$'), + const_cpu_to_le16('S'), + const_cpu_to_le16('D'), + const_cpu_to_le16('H'), + const_cpu_to_le16(0) }; + +/* + * null SID (S-1-0-0) + */ + +extern const SID *nullsid; + +/* + * The zero GUID. + */ + +static const GUID __zero_guid = { const_cpu_to_le32(0), const_cpu_to_le16(0), + const_cpu_to_le16(0), { 0, 0, 0, 0, 0, 0, 0, 0 } }; +static const GUID *const zero_guid = &__zero_guid; + +/** + * ntfs_guid_is_zero - check if a GUID is zero + * @guid: [IN] guid to check + * + * Return TRUE if @guid is a valid pointer to a GUID and it is the zero GUID + * and FALSE otherwise. + */ +BOOL ntfs_guid_is_zero(const GUID *guid) +{ + return (memcmp(guid, zero_guid, sizeof(*zero_guid))); +} + +/** + * ntfs_guid_to_mbs - convert a GUID to a multi byte string + * @guid: [IN] guid to convert + * @guid_str: [OUT] string in which to return the GUID (optional) + * + * Convert the GUID pointed to by @guid to a multi byte string of the form + * "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX". Therefore, @guid_str (if not NULL) + * needs to be able to store at least 37 bytes. + * + * If @guid_str is not NULL it will contain the converted GUID on return. If + * it is NULL a string will be allocated and this will be returned. The caller + * is responsible for free()ing the string in that case. + * + * On success return the converted string and on failure return NULL with errno + * set to the error code. + */ +char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str) +{ + char *_guid_str; + int res; + + if (!guid) { + errno = EINVAL; + return NULL; + } + _guid_str = guid_str; + if (!_guid_str) { + _guid_str = (char*)ntfs_malloc(37); + if (!_guid_str) + return _guid_str; + } + res = snprintf(_guid_str, 37, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + (unsigned int)le32_to_cpu(guid->data1), + le16_to_cpu(guid->data2), le16_to_cpu(guid->data3), + guid->data4[0], guid->data4[1], + guid->data4[2], guid->data4[3], guid->data4[4], + guid->data4[5], guid->data4[6], guid->data4[7]); + if (res == 36) + return _guid_str; + if (!guid_str) + free(_guid_str); + errno = EINVAL; + return NULL; +} + +/** + * ntfs_sid_to_mbs_size - determine maximum size for the string of a SID + * @sid: [IN] SID for which to determine the maximum string size + * + * Determine the maximum multi byte string size in bytes which is needed to + * store the standard textual representation of the SID pointed to by @sid. + * See ntfs_sid_to_mbs(), below. + * + * On success return the maximum number of bytes needed to store the multi byte + * string and on failure return -1 with errno set to the error code. + */ +int ntfs_sid_to_mbs_size(const SID *sid) +{ + int size, i; + + if (!ntfs_sid_is_valid(sid)) { + errno = EINVAL; + return -1; + } + /* Start with "S-". */ + size = 2; + /* + * Add the SID_REVISION. Hopefully the compiler will optimize this + * away as SID_REVISION is a constant. + */ + for (i = SID_REVISION; i > 0; i /= 10) + size++; + /* Add the "-". */ + size++; + /* + * Add the identifier authority. If it needs to be in decimal, the + * maximum is 2^32-1 = 4294967295 = 10 characters. If it needs to be + * in hexadecimal, then maximum is 0x665544332211 = 14 characters. + */ + if (!sid->identifier_authority.high_part) + size += 10; + else + size += 14; + /* + * Finally, add the sub authorities. For each we have a "-" followed + * by a decimal which can be up to 2^32-1 = 4294967295 = 10 characters. + */ + size += (1 + 10) * sid->sub_authority_count; + /* We need the zero byte at the end, too. */ + size++; + return size * sizeof(char); +} + +/** + * ntfs_sid_to_mbs - convert a SID to a multi byte string + * @sid: [IN] SID to convert + * @sid_str: [OUT] string in which to return the SID (optional) + * @sid_str_size: [IN] size in bytes of @sid_str + * + * Convert the SID pointed to by @sid to its standard textual representation. + * @sid_str (if not NULL) needs to be able to store at least + * ntfs_sid_to_mbs_size() bytes. @sid_str_size is the size in bytes of + * @sid_str if @sid_str is not NULL. + * + * The standard textual representation of the SID is of the form: + * S-R-I-S-S... + * Where: + * - The first "S" is the literal character 'S' identifying the following + * digits as a SID. + * - R is the revision level of the SID expressed as a sequence of digits + * in decimal. + * - I is the 48-bit identifier_authority, expressed as digits in decimal, + * if I < 2^32, or hexadecimal prefixed by "0x", if I >= 2^32. + * - S... is one or more sub_authority values, expressed as digits in + * decimal. + * + * If @sid_str is not NULL it will contain the converted SUID on return. If it + * is NULL a string will be allocated and this will be returned. The caller is + * responsible for free()ing the string in that case. + * + * On success return the converted string and on failure return NULL with errno + * set to the error code. + */ +char *ntfs_sid_to_mbs(const SID *sid, char *sid_str, size_t sid_str_size) +{ + u64 u; + le32 leauth; + char *s; + int i, j, cnt; + + /* + * No need to check @sid if !@sid_str since ntfs_sid_to_mbs_size() will + * check @sid, too. 8 is the minimum SID string size. + */ + if (sid_str && (sid_str_size < 8 || !ntfs_sid_is_valid(sid))) { + errno = EINVAL; + return NULL; + } + /* Allocate string if not provided. */ + if (!sid_str) { + cnt = ntfs_sid_to_mbs_size(sid); + if (cnt < 0) + return NULL; + s = (char*)ntfs_malloc(cnt); + if (!s) + return s; + sid_str = s; + /* So we know we allocated it. */ + sid_str_size = 0; + } else { + s = sid_str; + cnt = sid_str_size; + } + /* Start with "S-R-". */ + i = snprintf(s, cnt, "S-%hhu-", (unsigned char)sid->revision); + if (i < 0 || i >= cnt) + goto err_out; + s += i; + cnt -= i; + /* Add the identifier authority. */ + for (u = i = 0, j = 40; i < 6; i++, j -= 8) + u += (u64)sid->identifier_authority.value[i] << j; + if (!sid->identifier_authority.high_part) + i = snprintf(s, cnt, "%lu", (unsigned long)u); + else + i = snprintf(s, cnt, "0x%llx", (unsigned long long)u); + if (i < 0 || i >= cnt) + goto err_out; + s += i; + cnt -= i; + /* Finally, add the sub authorities. */ + for (j = 0; j < sid->sub_authority_count; j++) { + leauth = sid->sub_authority[j]; + i = snprintf(s, cnt, "-%u", (unsigned int) + le32_to_cpu(leauth)); + if (i < 0 || i >= cnt) + goto err_out; + s += i; + cnt -= i; + } + return sid_str; +err_out: + if (i >= cnt) + i = EMSGSIZE; + else + i = errno; + if (!sid_str_size) + free(sid_str); + errno = i; + return NULL; +} + +/** + * ntfs_generate_guid - generatates a random current guid. + * @guid: [OUT] pointer to a GUID struct to hold the generated guid. + * + * perhaps not a very good random number generator though... + */ +void ntfs_generate_guid(GUID *guid) +{ + unsigned int i; + u8 *p = (u8 *)guid; + + for (i = 0; i < sizeof(GUID); i++) { + p[i] = (u8)(random() & 0xFF); + if (i == 7) + p[7] = (p[7] & 0x0F) | 0x40; + if (i == 8) + p[8] = (p[8] & 0x3F) | 0x80; + } +} + +/** + * ntfs_security_hash - calculate the hash of a security descriptor + * @sd: self-relative security descriptor whose hash to calculate + * @length: size in bytes of the security descritor @sd + * + * Calculate the hash of the self-relative security descriptor @sd of length + * @length bytes. + * + * This hash is used in the $Secure system file as the primary key for the $SDH + * index and is also stored in the header of each security descriptor in the + * $SDS data stream as well as in the index data of both the $SII and $SDH + * indexes. In all three cases it forms part of the SDS_ENTRY_HEADER + * structure. + * + * Return the calculated security hash in little endian. + */ +le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, const u32 len) +{ + const le32 *pos = (const le32*)sd; + const le32 *end = pos + (len >> 2); + u32 hash = 0; + + while (pos < end) { + hash = le32_to_cpup(pos) + ntfs_rol32(hash, 3); + pos++; + } + return cpu_to_le32(hash); +} + +/* + * Internal read + * copied and pasted from ntfs_fuse_read() and made independent + * of fuse context + */ + +static int ntfs_local_read(ntfs_inode *ni, + ntfschar *stream_name, int stream_name_len, + char *buf, size_t size, off_t offset) +{ + ntfs_attr *na = NULL; + int res, total = 0; + + na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); + if (!na) { + res = -errno; + goto exit; + } + if ((size_t)offset < (size_t)na->data_size) { + if (offset + size > (size_t)na->data_size) + size = na->data_size - offset; + while (size) { + res = ntfs_attr_pread(na, offset, size, buf); + if ((off_t)res < (off_t)size) + ntfs_log_perror("ntfs_attr_pread partial read " + "(%lld : %lld <> %d)", + (long long)offset, + (long long)size, res); + if (res <= 0) { + res = -errno; + goto exit; + } + size -= res; + offset += res; + total += res; + } + } + res = total; +exit: + if (na) + ntfs_attr_close(na); + return res; +} + + +/* + * Internal write + * copied and pasted from ntfs_fuse_write() and made independent + * of fuse context + */ + +static int ntfs_local_write(ntfs_inode *ni, + ntfschar *stream_name, int stream_name_len, + char *buf, size_t size, off_t offset) +{ + ntfs_attr *na = NULL; + int res, total = 0; + + na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); + if (!na) { + res = -errno; + goto exit; + } + while (size) { + res = ntfs_attr_pwrite(na, offset, size, buf); + if (res < (s64)size) + ntfs_log_perror("ntfs_attr_pwrite partial write (%lld: " + "%lld <> %d)", (long long)offset, + (long long)size, res); + if (res <= 0) { + res = -errno; + goto exit; + } + size -= res; + offset += res; + total += res; + } + res = total; +exit: + if (na) + ntfs_attr_close(na); + return res; +} + + +/* + * Get the first entry of current index block + * cut and pasted form ntfs_ie_get_first() in index.c + */ + +static INDEX_ENTRY *ntfs_ie_get_first(INDEX_HEADER *ih) +{ + return (INDEX_ENTRY*)((u8*)ih + le32_to_cpu(ih->entries_offset)); +} + +/* + * Stuff a 256KB block into $SDS before writing descriptors + * into the block. + * + * This prevents $SDS from being automatically declared as sparse + * when the second copy of the first security descriptor is written + * 256KB further ahead. + * + * Having $SDS declared as a sparse file is not wrong by itself + * and chkdsk leaves it as a sparse file. It does however complain + * and add a sparse flag (0x0200) into field file_attributes of + * STANDARD_INFORMATION of $Secure. This probably means that a + * sparse attribute (ATTR_IS_SPARSE) is only allowed in sparse + * files (FILE_ATTR_SPARSE_FILE). + * + * Windows normally does not convert to sparse attribute or sparse + * file. Stuffing is just a way to get to the same result. + */ + +static int entersecurity_stuff(ntfs_volume *vol, off_t offs) +{ + int res; + int written; + unsigned long total; + char *stuff; + + res = 0; + total = 0; + stuff = (char*)ntfs_malloc(STUFFSZ); + if (stuff) { + memset(stuff, 0, STUFFSZ); + do { + written = ntfs_local_write(vol->secure_ni, + STREAM_SDS, 4, stuff, STUFFSZ, offs); + if (written == STUFFSZ) { + total += STUFFSZ; + offs += STUFFSZ; + } else { + errno = ENOSPC; + res = -1; + } + } while (!res && (total < ALIGN_SDS_BLOCK)); + free(stuff); + } else { + errno = ENOMEM; + res = -1; + } + return (res); +} + +/* + * Enter a new security descriptor into $Secure (data only) + * it has to be written twice with an offset of 256KB + * + * Should only be called by entersecurityattr() to ensure consistency + * + * Returns zero if sucessful + */ + +static int entersecurity_data(ntfs_volume *vol, + const SECURITY_DESCRIPTOR_RELATIVE *attr, s64 attrsz, + le32 hash, le32 keyid, off_t offs, int gap) +{ + int res; + int written1; + int written2; + char *fullattr; + int fullsz; + SECURITY_DESCRIPTOR_HEADER *phsds; + + res = -1; + fullsz = attrsz + gap + sizeof(SECURITY_DESCRIPTOR_HEADER); + fullattr = (char*)ntfs_malloc(fullsz); + if (fullattr) { + /* + * Clear the gap from previous descriptor + * this could be useful for appending the second + * copy to the end of file. When creating a new + * 256K block, the gap is cleared while writing + * the first copy + */ + if (gap) + memset(fullattr,0,gap); + memcpy(&fullattr[gap + sizeof(SECURITY_DESCRIPTOR_HEADER)], + attr,attrsz); + phsds = (SECURITY_DESCRIPTOR_HEADER*)&fullattr[gap]; + phsds->hash = hash; + phsds->security_id = keyid; + phsds->offset = cpu_to_le64(offs); + phsds->length = cpu_to_le32(fullsz - gap); + written1 = ntfs_local_write(vol->secure_ni, + STREAM_SDS, 4, fullattr, fullsz, + offs - gap); + written2 = ntfs_local_write(vol->secure_ni, + STREAM_SDS, 4, fullattr, fullsz, + offs - gap + ALIGN_SDS_BLOCK); + if ((written1 == fullsz) + && (written2 == written1)) + res = 0; + else + errno = ENOSPC; + free(fullattr); + } else + errno = ENOMEM; + return (res); +} + +/* + * Enter a new security descriptor in $Secure (indexes only) + * + * Should only be called by entersecurityattr() to ensure consistency + * + * Returns zero if sucessful + */ + +static int entersecurity_indexes(ntfs_volume *vol, s64 attrsz, + le32 hash, le32 keyid, off_t offs) +{ + union { + struct { + le32 dataoffsl; + le32 dataoffsh; + } parts; + le64 all; + } realign; + int res; + ntfs_index_context *xsii; + ntfs_index_context *xsdh; + struct SII newsii; + struct SDH newsdh; + + res = -1; + /* enter a new $SII record */ + + xsii = vol->secure_xsii; + ntfs_index_ctx_reinit(xsii); + newsii.offs = const_cpu_to_le16(20); + newsii.size = const_cpu_to_le16(sizeof(struct SII) - 20); + newsii.fill1 = const_cpu_to_le32(0); + newsii.indexsz = const_cpu_to_le16(sizeof(struct SII)); + newsii.indexksz = const_cpu_to_le16(sizeof(SII_INDEX_KEY)); + newsii.flags = const_cpu_to_le16(0); + newsii.fill2 = const_cpu_to_le16(0); + newsii.keysecurid = keyid; + newsii.hash = hash; + newsii.securid = keyid; + realign.all = cpu_to_le64(offs); + newsii.dataoffsh = realign.parts.dataoffsh; + newsii.dataoffsl = realign.parts.dataoffsl; + newsii.datasize = cpu_to_le32(attrsz + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + if (!ntfs_ie_add(xsii,(INDEX_ENTRY*)&newsii)) { + + /* enter a new $SDH record */ + + xsdh = vol->secure_xsdh; + ntfs_index_ctx_reinit(xsdh); + newsdh.offs = const_cpu_to_le16(24); + newsdh.size = const_cpu_to_le16( + sizeof(SECURITY_DESCRIPTOR_HEADER)); + newsdh.fill1 = const_cpu_to_le32(0); + newsdh.indexsz = const_cpu_to_le16( + sizeof(struct SDH)); + newsdh.indexksz = const_cpu_to_le16( + sizeof(SDH_INDEX_KEY)); + newsdh.flags = const_cpu_to_le16(0); + newsdh.fill2 = const_cpu_to_le16(0); + newsdh.keyhash = hash; + newsdh.keysecurid = keyid; + newsdh.hash = hash; + newsdh.securid = keyid; + newsdh.dataoffsh = realign.parts.dataoffsh; + newsdh.dataoffsl = realign.parts.dataoffsl; + newsdh.datasize = cpu_to_le32(attrsz + + sizeof(SECURITY_DESCRIPTOR_HEADER)); + /* special filler value, Windows generally */ + /* fills with 0x00490049, sometimes with zero */ + newsdh.fill3 = const_cpu_to_le32(0x00490049); + if (!ntfs_ie_add(xsdh,(INDEX_ENTRY*)&newsdh)) + res = 0; + } + return (res); +} + +/* + * Enter a new security descriptor in $Secure (data and indexes) + * Returns id of entry, or zero if there is a problem. + * (should not be called for NTFS version < 3.0) + * + * important : calls have to be serialized, however no locking is + * needed while fuse is not multithreaded + */ + +static le32 entersecurityattr(ntfs_volume *vol, + const SECURITY_DESCRIPTOR_RELATIVE *attr, s64 attrsz, + le32 hash) +{ + union { + struct { + le32 dataoffsl; + le32 dataoffsh; + } parts; + le64 all; + } realign; + le32 securid; + le32 keyid; + u32 newkey; + off_t offs; + int gap; + int size; + BOOL found; + struct SII *psii; + INDEX_ENTRY *entry; + INDEX_ENTRY *next; + ntfs_index_context *xsii; + int retries; + ntfs_attr *na; + int olderrno; + + /* find the first available securid beyond the last key */ + /* in $Secure:$SII. This also determines the first */ + /* available location in $Secure:$SDS, as this stream */ + /* is always appended to and the id's are allocated */ + /* in sequence */ + + securid = const_cpu_to_le32(0); + xsii = vol->secure_xsii; + ntfs_index_ctx_reinit(xsii); + offs = size = 0; + keyid = const_cpu_to_le32(-1); + olderrno = errno; + found = !ntfs_index_lookup((char*)&keyid, + sizeof(SII_INDEX_KEY), xsii); + if (!found && (errno != ENOENT)) { + ntfs_log_perror("Inconsistency in index $SII"); + psii = (struct SII*)NULL; + } else { + /* restore errno to avoid misinterpretation */ + errno = olderrno; + entry = xsii->entry; + psii = (struct SII*)xsii->entry; + } + if (psii) { + /* + * Get last entry in block, but must get first one + * one first, as we should already be beyond the + * last one. For some reason the search for the last + * entry sometimes does not return the last block... + * we assume this can only happen in root block + */ + if (xsii->is_in_root) + entry = ntfs_ie_get_first + ((INDEX_HEADER*)&xsii->ir->index); + else + entry = ntfs_ie_get_first + ((INDEX_HEADER*)&xsii->ib->index); + /* + * All index blocks should be at least half full + * so there always is a last entry but one, + * except when creating the first entry in index root. + * This was however found not to be true : chkdsk + * sometimes deletes all the (unused) keys in the last + * index block without rebalancing the tree. + * When this happens, a new search is restarted from + * the smallest key. + */ + keyid = const_cpu_to_le32(0); + retries = 0; + while (entry) { + next = ntfs_index_next(entry,xsii); + if (next) { + psii = (struct SII*)next; + /* save last key and */ + /* available position */ + keyid = psii->keysecurid; + realign.parts.dataoffsh + = psii->dataoffsh; + realign.parts.dataoffsl + = psii->dataoffsl; + offs = le64_to_cpu(realign.all); + size = le32_to_cpu(psii->datasize); + } + entry = next; + if (!entry && !keyid && !retries) { + /* search failed, retry from smallest key */ + ntfs_index_ctx_reinit(xsii); + found = !ntfs_index_lookup((char*)&keyid, + sizeof(SII_INDEX_KEY), xsii); + if (!found && (errno != ENOENT)) { + ntfs_log_perror("Index $SII is broken"); + } else { + /* restore errno */ + errno = olderrno; + entry = xsii->entry; + } + retries++; + } + } + } + if (!keyid) { + /* + * could not find any entry, before creating the first + * entry, make a double check by making sure size of $SII + * is less than needed for one entry + */ + securid = const_cpu_to_le32(0); + na = ntfs_attr_open(vol->secure_ni,AT_INDEX_ROOT,sii_stream,4); + if (na) { + if ((size_t)na->data_size < sizeof(struct SII)) { + ntfs_log_error("Creating the first security_id\n"); + securid = const_cpu_to_le32(FIRST_SECURITY_ID); + } + ntfs_attr_close(na); + } + if (!securid) { + ntfs_log_error("Error creating a security_id\n"); + errno = EIO; + } + } else { + newkey = le32_to_cpu(keyid) + 1; + securid = cpu_to_le32(newkey); + } + /* + * The security attr has to be written twice 256KB + * apart. This implies that offsets like + * 0x40000*odd_integer must be left available for + * the second copy. So align to next block when + * the last byte overflows on a wrong block. + */ + + if (securid) { + gap = (-size) & (ALIGN_SDS_ENTRY - 1); + offs += gap + size; + if ((offs + attrsz + sizeof(SECURITY_DESCRIPTOR_HEADER) - 1) + & ALIGN_SDS_BLOCK) { + offs = ((offs + attrsz + + sizeof(SECURITY_DESCRIPTOR_HEADER) - 1) + | (ALIGN_SDS_BLOCK - 1)) + 1; + } + if (!(offs & (ALIGN_SDS_BLOCK - 1))) + entersecurity_stuff(vol, offs); + /* + * now write the security attr to storage : + * first data, then SII, then SDH + * If failure occurs while writing SDS, data will never + * be accessed through indexes, and will be overwritten + * by the next allocated descriptor + * If failure occurs while writing SII, the id has not + * recorded and will be reallocated later + * If failure occurs while writing SDH, the space allocated + * in SDS or SII will not be reused, an inconsistency + * will persist with no significant consequence + */ + if (entersecurity_data(vol, attr, attrsz, hash, securid, offs, gap) + || entersecurity_indexes(vol, attrsz, hash, securid, offs)) + securid = const_cpu_to_le32(0); + } + /* inode now is dirty, synchronize it all */ + ntfs_index_entry_mark_dirty(vol->secure_xsii); + ntfs_index_ctx_reinit(vol->secure_xsii); + ntfs_index_entry_mark_dirty(vol->secure_xsdh); + ntfs_index_ctx_reinit(vol->secure_xsdh); + NInoSetDirty(vol->secure_ni); + if (ntfs_inode_sync(vol->secure_ni)) + ntfs_log_perror("Could not sync $Secure\n"); + return (securid); +} + +/* + * Find a matching security descriptor in $Secure, + * if none, allocate a new id and write the descriptor to storage + * Returns id of entry, or zero if there is a problem. + * + * important : calls have to be serialized, however no locking is + * needed while fuse is not multithreaded + */ + +static le32 setsecurityattr(ntfs_volume *vol, + const SECURITY_DESCRIPTOR_RELATIVE *attr, s64 attrsz) +{ + struct SDH *psdh; /* this is an image of index (le) */ + union { + struct { + le32 dataoffsl; + le32 dataoffsh; + } parts; + le64 all; + } realign; + BOOL found; + BOOL collision; + size_t size; + size_t rdsize; + s64 offs; + int res; + ntfs_index_context *xsdh; + char *oldattr; + SDH_INDEX_KEY key; + INDEX_ENTRY *entry; + le32 securid; + le32 hash; + int olderrno; + + hash = ntfs_security_hash(attr,attrsz); + oldattr = (char*)NULL; + securid = const_cpu_to_le32(0); + res = 0; + xsdh = vol->secure_xsdh; + if (vol->secure_ni && xsdh && !vol->secure_reentry++) { + ntfs_index_ctx_reinit(xsdh); + /* + * find the nearest key as (hash,0) + * (do not search for partial key : in case of collision, + * it could return a key which is not the first one which + * collides) + */ + key.hash = hash; + key.security_id = const_cpu_to_le32(0); + olderrno = errno; + found = !ntfs_index_lookup((char*)&key, + sizeof(SDH_INDEX_KEY), xsdh); + if (!found && (errno != ENOENT)) + ntfs_log_perror("Inconsistency in index $SDH"); + else { + /* restore errno to avoid misinterpretation */ + errno = olderrno; + entry = xsdh->entry; + found = FALSE; + /* + * lookup() may return a node with no data, + * if so get next + */ + if (entry->ie_flags & INDEX_ENTRY_END) + entry = ntfs_index_next(entry,xsdh); + do { + collision = FALSE; + psdh = (struct SDH*)entry; + if (psdh) + size = (size_t) le32_to_cpu(psdh->datasize) + - sizeof(SECURITY_DESCRIPTOR_HEADER); + else size = 0; + /* if hash is not the same, the key is not present */ + if (psdh && (size > 0) + && (psdh->keyhash == hash)) { + /* if hash is the same */ + /* check the whole record */ + realign.parts.dataoffsh = psdh->dataoffsh; + realign.parts.dataoffsl = psdh->dataoffsl; + offs = le64_to_cpu(realign.all) + + sizeof(SECURITY_DESCRIPTOR_HEADER); + oldattr = (char*)ntfs_malloc(size); + if (oldattr) { + rdsize = ntfs_local_read( + vol->secure_ni, + STREAM_SDS, 4, + oldattr, size, offs); + found = (rdsize == size) + && !memcmp(oldattr,attr,size); + free(oldattr); + /* if the records do not compare */ + /* (hash collision), try next one */ + if (!found) { + entry = ntfs_index_next( + entry,xsdh); + collision = TRUE; + } + } else + res = ENOMEM; + } + } while (collision && entry); + if (found) + securid = psdh->keysecurid; + else { + if (res) { + errno = res; + securid = const_cpu_to_le32(0); + } else { + /* + * no matching key : + * have to build a new one + */ + securid = entersecurityattr(vol, + attr, attrsz, hash); + } + } + } + } + if (--vol->secure_reentry) + ntfs_log_perror("Reentry error, check no multithreading\n"); + return (securid); +} + + +/* + * Update the security descriptor of a file + * Either as an attribute (complying with pre v3.x NTFS version) + * or, when possible, as an entry in $Secure (for NTFS v3.x) + * + * returns 0 if success + */ + +static int update_secur_descr(ntfs_volume *vol, + char *newattr, ntfs_inode *ni) +{ + int newattrsz; + int written; + int res; + ntfs_attr *na; + + newattrsz = ntfs_attr_size(newattr); + +#if !FORCE_FORMAT_v1x + if ((vol->major_ver < 3) || !vol->secure_ni) { +#endif + + /* update for NTFS format v1.x */ + + /* update the old security attribute */ + na = ntfs_attr_open(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); + if (na) { + /* resize attribute */ + res = ntfs_attr_truncate(na, (s64) newattrsz); + /* overwrite value */ + if (!res) { + written = (int)ntfs_attr_pwrite(na, (s64) 0, + (s64) newattrsz, newattr); + if (written != newattrsz) { + ntfs_log_error("Failed to update " + "a v1.x security descriptor\n"); + errno = EIO; + res = -1; + } + } + + ntfs_attr_close(na); + /* if old security attribute was found, also */ + /* truncate standard information attribute to v1.x */ + /* this is needed when security data is wanted */ + /* as v1.x though volume is formatted for v3.x */ + na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, + AT_UNNAMED, 0); + if (na) { + clear_nino_flag(ni, v3_Extensions); + /* + * Truncating the record does not sweep extensions + * from copy in memory. Clear security_id to be safe + */ + ni->security_id = const_cpu_to_le32(0); + res = ntfs_attr_truncate(na, (s64)48); + ntfs_attr_close(na); + clear_nino_flag(ni, v3_Extensions); + } + } else { + /* + * insert the new security attribute if there + * were none + */ + res = ntfs_attr_add(ni, AT_SECURITY_DESCRIPTOR, + AT_UNNAMED, 0, (u8*)newattr, + (s64) newattrsz); + } +#if !FORCE_FORMAT_v1x + } else { + + /* update for NTFS format v3.x */ + + le32 securid; + + securid = setsecurityattr(vol, + (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, + (s64)newattrsz); + if (securid) { + na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, + AT_UNNAMED, 0); + if (na) { + res = 0; + if (!test_nino_flag(ni, v3_Extensions)) { + /* expand standard information attribute to v3.x */ + res = ntfs_attr_truncate(na, + (s64)sizeof(STANDARD_INFORMATION)); + ni->owner_id = const_cpu_to_le32(0); + ni->quota_charged = const_cpu_to_le64(0); + ni->usn = const_cpu_to_le64(0); + ntfs_attr_remove(ni, + AT_SECURITY_DESCRIPTOR, + AT_UNNAMED, 0); + } + set_nino_flag(ni, v3_Extensions); + ni->security_id = securid; + ntfs_attr_close(na); + } else { + ntfs_log_error("Failed to update " + "standard informations\n"); + errno = EIO; + res = -1; + } + } else + res = -1; + } +#endif + + /* mark node as dirty */ + NInoSetDirty(ni); + return (res); +} + +/* + * Upgrade the security descriptor of a file + * This is intended to allow graceful upgrades for files which + * were created in previous versions, with a security attributes + * and no security id. + * + * It will allocate a security id and replace the individual + * security attribute by a reference to the global one + * + * Special files are not upgraded (currently / and files in + * directories /$*) + * + * Though most code is similar to update_secur_desc() it has + * been kept apart to facilitate the further processing of + * special cases or even to remove it if found dangerous. + * + * returns 0 if success, + * 1 if not upgradable. This is not an error. + * -1 if there is a problem + */ + +static int upgrade_secur_desc(ntfs_volume *vol, + const char *attr, ntfs_inode *ni) +{ + int attrsz; + int res; + le32 securid; + ntfs_attr *na; + + /* + * upgrade requires NTFS format v3.x + * also refuse upgrading for special files + * whose number is less than FILE_first_user + */ + + if ((vol->major_ver >= 3) + && (ni->mft_no >= FILE_first_user)) { + attrsz = ntfs_attr_size(attr); + securid = setsecurityattr(vol, + (const SECURITY_DESCRIPTOR_RELATIVE*)attr, + (s64)attrsz); + if (securid) { + na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, + AT_UNNAMED, 0); + if (na) { + res = 0; + /* expand standard information attribute to v3.x */ + res = ntfs_attr_truncate(na, + (s64)sizeof(STANDARD_INFORMATION)); + ni->owner_id = const_cpu_to_le32(0); + ni->quota_charged = const_cpu_to_le64(0); + ni->usn = const_cpu_to_le64(0); + ntfs_attr_remove(ni, AT_SECURITY_DESCRIPTOR, + AT_UNNAMED, 0); + set_nino_flag(ni, v3_Extensions); + ni->security_id = securid; + ntfs_attr_close(na); + } else { + ntfs_log_error("Failed to upgrade " + "standard informations\n"); + errno = EIO; + res = -1; + } + } else + res = -1; + /* mark node as dirty */ + NInoSetDirty(ni); + } else + res = 1; + + return (res); +} + +/* + * Optional simplified checking of group membership + * + * This only takes into account the groups defined in + * /etc/group at initialization time. + * It does not take into account the groups dynamically set by + * setgroups() nor the changes in /etc/group since initialization + * + * This optional method could be useful if standard checking + * leads to a performance concern. + * + * Should not be called for user root, however the group may be root + * + */ + +static BOOL staticgroupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid) +{ + BOOL ingroup; + int grcnt; + gid_t *groups; + struct MAPPING *user; + + ingroup = FALSE; + if (uid) { + user = scx->mapping[MAPUSERS]; + while (user && ((uid_t)user->xid != uid)) + user = user->next; + if (user) { + groups = user->groups; + grcnt = user->grcnt; + while ((--grcnt >= 0) && (groups[grcnt] != gid)) { } + ingroup = (grcnt >= 0); + } + } + return (ingroup); +} + + +/* + * Check whether current thread owner is member of file group + * + * Should not be called for user root, however the group may be root + * + * As indicated by Miklos Szeredi : + * + * The group list is available in + * + * /proc/$PID/task/$TID/status + * + * and fuse supplies TID in get_fuse_context()->pid. The only problem is + * finding out PID, for which I have no good solution, except to iterate + * through all processes. This is rather slow, but may be speeded up + * with caching and heuristics (for single threaded programs PID = TID). + * + * The following implementation gets the group list from + * /proc/$TID/task/$TID/status which apparently exists and + * contains the same data. + */ + +static BOOL groupmember(struct SECURITY_CONTEXT *scx, uid_t uid, gid_t gid) +{ + static char key[] = "\nGroups:"; + char buf[BUFSZ+1]; + char filename[64]; + enum { INKEY, INSEP, INNUM, INEND } state; + int fd; + char c; + int matched; + BOOL ismember; + int got; + char *p; + gid_t grp; + pid_t tid; + + if (scx->vol->secure_flags & (1 << SECURITY_STATICGRPS)) + ismember = staticgroupmember(scx, uid, gid); + else { + ismember = FALSE; /* default return */ + tid = scx->tid; + sprintf(filename,"/proc/%u/task/%u/status",tid,tid); + fd = open(filename,O_RDONLY); + if (fd >= 0) { + got = read(fd, buf, BUFSZ); + buf[got] = 0; + state = INKEY; + matched = 0; + p = buf; + grp = 0; + /* + * A simple automaton to process lines like + * Groups: 14 500 513 + */ + do { + c = *p++; + if (!c) { + /* refill buffer */ + got = read(fd, buf, BUFSZ); + buf[got] = 0; + p = buf; + c = *p++; /* 0 at end of file */ + } + switch (state) { + case INKEY : + if (key[matched] == c) { + if (!key[++matched]) + state = INSEP; + } else + if (key[0] == c) + matched = 1; + else + matched = 0; + break; + case INSEP : + if ((c >= '0') && (c <= '9')) { + grp = c - '0'; + state = INNUM; + } else + if ((c != ' ') && (c != '\t')) + state = INEND; + break; + case INNUM : + if ((c >= '0') && (c <= '9')) + grp = grp*10 + c - '0'; + else { + ismember = (grp == gid); + if ((c != ' ') && (c != '\t')) + state = INEND; + else + state = INSEP; + } + default : + break; + } + } while (!ismember && c && (state != INEND)); + close(fd); + if (!c) + ntfs_log_error("No group record found in %s\n",filename); + } else + ntfs_log_error("Could not open %s\n",filename); + } + return (ismember); +} + +/* + * Cacheing is done two-way : + * - from uid, gid and perm to securid (CACHED_SECURID) + * - from a securid to uid, gid and perm (CACHED_PERMISSIONS) + * + * CACHED_SECURID data is kept in a most-recent-first list + * which should not be too long to be efficient. Its optimal + * size is depends on usage and is hard to determine. + * + * CACHED_PERMISSIONS data is kept in a two-level indexed array. It + * is optimal at the expense of storage. Use of a most-recent-first + * list would save memory and provide similar performances for + * standard usage, but not for file servers with too many file + * owners + * + * CACHED_PERMISSIONS_LEGACY is a special case for CACHED_PERMISSIONS + * for legacy directories which were not allocated a security_id + * it is organized in a most-recent-first list. + * + * In main caches, data is never invalidated, as the meaning of + * a security_id only changes when user mapping is changed, which + * current implies remounting. However returned entries may be + * overwritten at next update, so data has to be copied elsewhere + * before another cache update is made. + * In legacy cache, data has to be invalidated when protection is + * changed. + * + * Though the same data may be found in both list, they + * must be kept separately : the interpretation of ACL + * in both direction are approximations which could be non + * reciprocal for some configuration of the user mapping data + * + * During the process of recompiling ntfs-3g from a tgz archive, + * security processing added 7.6% to the cpu time used by ntfs-3g + * and 30% if the cache is disabled. + */ + +static struct PERMISSIONS_CACHE *create_caches(struct SECURITY_CONTEXT *scx, + u32 securindex) +{ + struct PERMISSIONS_CACHE *cache; + unsigned int index1; + unsigned int i; + + cache = (struct PERMISSIONS_CACHE*)NULL; + /* create the first permissions blocks */ + index1 = securindex >> CACHE_PERMISSIONS_BITS; + cache = (struct PERMISSIONS_CACHE*) + ntfs_malloc(sizeof(struct PERMISSIONS_CACHE) + + index1*sizeof(struct CACHED_PERMISSIONS*)); + if (cache) { + cache->head.last = index1; + cache->head.p_reads = 0; + cache->head.p_hits = 0; + cache->head.p_writes = 0; + *scx->pseccache = cache; + for (i=0; i<=index1; i++) + cache->cachetable[i] + = (struct CACHED_PERMISSIONS*)NULL; + } + return (cache); +} + +/* + * Free memory used by caches + * The only purpose is to facilitate the detection of memory leaks + */ + +static void free_caches(struct SECURITY_CONTEXT *scx) +{ + unsigned int index1; + struct PERMISSIONS_CACHE *pseccache; + + pseccache = *scx->pseccache; + if (pseccache) { + for (index1=0; index1<=pseccache->head.last; index1++) + if (pseccache->cachetable[index1]) { +#if POSIXACLS + struct CACHED_PERMISSIONS *cacheentry; + unsigned int index2; + + for (index2=0; index2<(1<< CACHE_PERMISSIONS_BITS); index2++) { + cacheentry = &pseccache->cachetable[index1][index2]; + if (cacheentry->valid + && cacheentry->pxdesc) + free(cacheentry->pxdesc); + } +#endif + free(pseccache->cachetable[index1]); + } + free(pseccache); + } +} + +static int compare(const struct CACHED_SECURID *cached, + const struct CACHED_SECURID *item) +{ +#if POSIXACLS + size_t csize; + size_t isize; + + /* only compare data and sizes */ + csize = (cached->variable ? + sizeof(struct POSIX_ACL) + + (((struct POSIX_SECURITY*)cached->variable)->acccnt + + ((struct POSIX_SECURITY*)cached->variable)->defcnt) + *sizeof(struct POSIX_ACE) : + 0); + isize = (item->variable ? + sizeof(struct POSIX_ACL) + + (((struct POSIX_SECURITY*)item->variable)->acccnt + + ((struct POSIX_SECURITY*)item->variable)->defcnt) + *sizeof(struct POSIX_ACE) : + 0); + return ((cached->uid != item->uid) + || (cached->gid != item->gid) + || (cached->dmode != item->dmode) + || (csize != isize) + || (csize + && isize + && memcmp(&((struct POSIX_SECURITY*)cached->variable)->acl, + &((struct POSIX_SECURITY*)item->variable)->acl, csize))); +#else + return ((cached->uid != item->uid) + || (cached->gid != item->gid) + || (cached->dmode != item->dmode)); +#endif +} + +static int leg_compare(const struct CACHED_PERMISSIONS_LEGACY *cached, + const struct CACHED_PERMISSIONS_LEGACY *item) +{ + return (cached->mft_no != item->mft_no); +} + +/* + * Resize permission cache table + * do not call unless resizing is needed + * + * If allocation fails, the cache size is not updated + * Lack of memory is not considered as an error, the cache is left + * consistent and errno is not set. + */ + +static void resize_cache(struct SECURITY_CONTEXT *scx, + u32 securindex) +{ + struct PERMISSIONS_CACHE *oldcache; + struct PERMISSIONS_CACHE *newcache; + int newcnt; + int oldcnt; + unsigned int index1; + unsigned int i; + + oldcache = *scx->pseccache; + index1 = securindex >> CACHE_PERMISSIONS_BITS; + newcnt = index1 + 1; + if (newcnt <= ((CACHE_PERMISSIONS_SIZE + + (1 << CACHE_PERMISSIONS_BITS) + - 1) >> CACHE_PERMISSIONS_BITS)) { + /* expand cache beyond current end, do not use realloc() */ + /* to avoid losing data when there is no more memory */ + oldcnt = oldcache->head.last + 1; + newcache = (struct PERMISSIONS_CACHE*) + ntfs_malloc( + sizeof(struct PERMISSIONS_CACHE) + + (newcnt - 1)*sizeof(struct CACHED_PERMISSIONS*)); + if (newcache) { + memcpy(newcache,oldcache, + sizeof(struct PERMISSIONS_CACHE) + + (oldcnt - 1)*sizeof(struct CACHED_PERMISSIONS*)); + free(oldcache); + /* mark new entries as not valid */ + for (i=newcache->head.last+1; i<=index1; i++) + newcache->cachetable[i] + = (struct CACHED_PERMISSIONS*)NULL; + newcache->head.last = index1; + *scx->pseccache = newcache; + } + } +} + +/* + * Enter uid, gid and mode into cache, if possible + * + * returns the updated or created cache entry, + * or NULL if not possible (typically if there is no + * security id associated) + */ + +#if POSIXACLS +static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, + struct POSIX_SECURITY *pxdesc) +#else +static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode) +#endif +{ + struct CACHED_PERMISSIONS *cacheentry; + struct CACHED_PERMISSIONS *cacheblock; + struct PERMISSIONS_CACHE *pcache; + u32 securindex; +#if POSIXACLS + int pxsize; + struct POSIX_SECURITY *pxcached; +#endif + unsigned int index1; + unsigned int index2; + int i; + + /* cacheing is only possible if a security_id has been defined */ + if (test_nino_flag(ni, v3_Extensions) + && ni->security_id) { + /* + * Immediately test the most frequent situation + * where the entry exists + */ + securindex = le32_to_cpu(ni->security_id); + index1 = securindex >> CACHE_PERMISSIONS_BITS; + index2 = securindex & ((1 << CACHE_PERMISSIONS_BITS) - 1); + pcache = *scx->pseccache; + if (pcache + && (pcache->head.last >= index1) + && pcache->cachetable[index1]) { + cacheentry = &pcache->cachetable[index1][index2]; + cacheentry->uid = uid; + cacheentry->gid = gid; +#if POSIXACLS + if (cacheentry->valid && cacheentry->pxdesc) + free(cacheentry->pxdesc); + if (pxdesc) { + pxsize = sizeof(struct POSIX_SECURITY) + + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); + pxcached = (struct POSIX_SECURITY*)malloc(pxsize); + if (pxcached) { + memcpy(pxcached, pxdesc, pxsize); + cacheentry->pxdesc = pxcached; + } else { + cacheentry->valid = 0; + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + } + cacheentry->mode = pxdesc->mode & 07777; + } else + cacheentry->pxdesc = (struct POSIX_SECURITY*)NULL; +#else + cacheentry->mode = mode & 07777; +#endif + cacheentry->inh_fileid = const_cpu_to_le32(0); + cacheentry->inh_dirid = const_cpu_to_le32(0); + cacheentry->valid = 1; + pcache->head.p_writes++; + } else { + if (!pcache) { + /* create the first cache block */ + pcache = create_caches(scx, securindex); + } else { + if (index1 > pcache->head.last) { + resize_cache(scx, securindex); + pcache = *scx->pseccache; + } + } + /* allocate block, if cache table was allocated */ + if (pcache && (index1 <= pcache->head.last)) { + cacheblock = (struct CACHED_PERMISSIONS*) + malloc(sizeof(struct CACHED_PERMISSIONS) + << CACHE_PERMISSIONS_BITS); + pcache->cachetable[index1] = cacheblock; + for (i=0; i<(1 << CACHE_PERMISSIONS_BITS); i++) + cacheblock[i].valid = 0; + cacheentry = &cacheblock[index2]; + if (cacheentry) { + cacheentry->uid = uid; + cacheentry->gid = gid; +#if POSIXACLS + if (pxdesc) { + pxsize = sizeof(struct POSIX_SECURITY) + + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); + pxcached = (struct POSIX_SECURITY*)malloc(pxsize); + if (pxcached) { + memcpy(pxcached, pxdesc, pxsize); + cacheentry->pxdesc = pxcached; + } else { + cacheentry->valid = 0; + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + } + cacheentry->mode = pxdesc->mode & 07777; + } else + cacheentry->pxdesc = (struct POSIX_SECURITY*)NULL; +#else + cacheentry->mode = mode & 07777; +#endif + cacheentry->inh_fileid = const_cpu_to_le32(0); + cacheentry->inh_dirid = const_cpu_to_le32(0); + cacheentry->valid = 1; + pcache->head.p_writes++; + } + } else + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + } + } else { + cacheentry = (struct CACHED_PERMISSIONS*)NULL; +#if CACHE_LEGACY_SIZE + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + struct CACHED_PERMISSIONS_LEGACY wanted; + struct CACHED_PERMISSIONS_LEGACY *legacy; + + wanted.perm.uid = uid; + wanted.perm.gid = gid; +#if POSIXACLS + wanted.perm.mode = pxdesc->mode & 07777; + wanted.perm.inh_fileid = const_cpu_to_le32(0); + wanted.perm.inh_dirid = const_cpu_to_le32(0); + wanted.mft_no = ni->mft_no; + wanted.variable = (void*)pxdesc; + wanted.varsize = sizeof(struct POSIX_SECURITY) + + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); +#else + wanted.perm.mode = mode & 07777; + wanted.perm.inh_fileid = const_cpu_to_le32(0); + wanted.perm.inh_dirid = const_cpu_to_le32(0); + wanted.mft_no = ni->mft_no; + wanted.variable = (void*)NULL; + wanted.varsize = 0; +#endif + legacy = (struct CACHED_PERMISSIONS_LEGACY*)ntfs_enter_cache( + scx->vol->legacy_cache, GENERIC(&wanted), + (cache_compare)leg_compare); + if (legacy) { + cacheentry = &legacy->perm; +#if POSIXACLS + /* + * give direct access to the cached pxdesc + * in the permissions structure + */ + cacheentry->pxdesc = legacy->variable; +#endif + } + } +#endif + } + return (cacheentry); +} + +/* + * Fetch owner, group and permission of a file, if cached + * + * Beware : do not use the returned entry after a cache update : + * the cache may be relocated making the returned entry meaningless + * + * returns the cache entry, or NULL if not available + */ + +static struct CACHED_PERMISSIONS *fetch_cache(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni) +{ + struct CACHED_PERMISSIONS *cacheentry; + struct PERMISSIONS_CACHE *pcache; + u32 securindex; + unsigned int index1; + unsigned int index2; + + /* cacheing is only possible if a security_id has been defined */ + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + if (test_nino_flag(ni, v3_Extensions) + && (ni->security_id)) { + securindex = le32_to_cpu(ni->security_id); + index1 = securindex >> CACHE_PERMISSIONS_BITS; + index2 = securindex & ((1 << CACHE_PERMISSIONS_BITS) - 1); + pcache = *scx->pseccache; + if (pcache + && (pcache->head.last >= index1) + && pcache->cachetable[index1]) { + cacheentry = &pcache->cachetable[index1][index2]; + /* reject if entry is not valid */ + if (!cacheentry->valid) + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + else + pcache->head.p_hits++; + if (pcache) + pcache->head.p_reads++; + } + } +#if CACHE_LEGACY_SIZE + else { + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + struct CACHED_PERMISSIONS_LEGACY wanted; + struct CACHED_PERMISSIONS_LEGACY *legacy; + + wanted.mft_no = ni->mft_no; + wanted.variable = (void*)NULL; + wanted.varsize = 0; + legacy = (struct CACHED_PERMISSIONS_LEGACY*)ntfs_fetch_cache( + scx->vol->legacy_cache, GENERIC(&wanted), + (cache_compare)leg_compare); + if (legacy) cacheentry = &legacy->perm; + } + } +#endif +#if POSIXACLS + if (cacheentry && !cacheentry->pxdesc) { + ntfs_log_error("No Posix descriptor in cache\n"); + cacheentry = (struct CACHED_PERMISSIONS*)NULL; + } +#endif + return (cacheentry); +} + +/* + * Retrieve a security attribute from $Secure + */ + +static char *retrievesecurityattr(ntfs_volume *vol, SII_INDEX_KEY id) +{ + struct SII *psii; + union { + struct { + le32 dataoffsl; + le32 dataoffsh; + } parts; + le64 all; + } realign; + int found; + size_t size; + size_t rdsize; + s64 offs; + ntfs_inode *ni; + ntfs_index_context *xsii; + char *securattr; + + securattr = (char*)NULL; + ni = vol->secure_ni; + xsii = vol->secure_xsii; + if (ni && xsii) { + ntfs_index_ctx_reinit(xsii); + found = + !ntfs_index_lookup((char*)&id, + sizeof(SII_INDEX_KEY), xsii); + if (found) { + psii = (struct SII*)xsii->entry; + size = + (size_t) le32_to_cpu(psii->datasize) + - sizeof(SECURITY_DESCRIPTOR_HEADER); + /* work around bad alignment problem */ + realign.parts.dataoffsh = psii->dataoffsh; + realign.parts.dataoffsl = psii->dataoffsl; + offs = le64_to_cpu(realign.all) + + sizeof(SECURITY_DESCRIPTOR_HEADER); + + securattr = (char*)ntfs_malloc(size); + if (securattr) { + rdsize = ntfs_local_read( + ni, STREAM_SDS, 4, + securattr, size, offs); + if ((rdsize != size) + || !ntfs_valid_descr(securattr, + rdsize)) { + /* error to be logged by caller */ + free(securattr); + securattr = (char*)NULL; + } + } + } else + if (errno != ENOENT) + ntfs_log_perror("Inconsistency in index $SII"); + } + if (!securattr) { + ntfs_log_error("Failed to retrieve a security descriptor\n"); + errno = EIO; + } + return (securattr); +} + +/* + * Get the security descriptor associated to a file + * + * Either : + * - read the security descriptor attribute (v1.x format) + * - or find the descriptor in $Secure:$SDS (v3.x format) + * + * in both case, sanity checks are done on the attribute and + * the descriptor can be assumed safe + * + * The returned descriptor is dynamically allocated and has to be freed + */ + +static char *getsecurityattr(ntfs_volume *vol, ntfs_inode *ni) +{ + SII_INDEX_KEY securid; + char *securattr; + s64 readallsz; + + /* + * Warning : in some situations, after fixing by chkdsk, + * v3_Extensions are marked present (long standard informations) + * with a default security descriptor inserted in an + * attribute + */ + if (test_nino_flag(ni, v3_Extensions) + && vol->secure_ni && ni->security_id) { + /* get v3.x descriptor in $Secure */ + securid.security_id = ni->security_id; + securattr = retrievesecurityattr(vol,securid); + if (!securattr) + ntfs_log_error("Bad security descriptor for 0x%lx\n", + (long)le32_to_cpu(ni->security_id)); + } else { + /* get v1.x security attribute */ + readallsz = 0; + securattr = ntfs_attr_readall(ni, AT_SECURITY_DESCRIPTOR, + AT_UNNAMED, 0, &readallsz); + if (securattr && !ntfs_valid_descr(securattr, readallsz)) { + ntfs_log_error("Bad security descriptor for inode %lld\n", + (long long)ni->mft_no); + free(securattr); + securattr = (char*)NULL; + } + } + if (!securattr) { + /* + * in some situations, there is no security + * descriptor, and chkdsk does not detect or fix + * anything. This could be a normal situation. + * When this happens, simulate a descriptor with + * minimum rights, so that a real descriptor can + * be created by chown or chmod + */ + ntfs_log_error("No security descriptor found for inode %lld\n", + (long long)ni->mft_no); + securattr = ntfs_build_descr(0, 0, adminsid, adminsid); + } + return (securattr); +} + +#if POSIXACLS + +/* + * Determine which access types to a file are allowed + * according to the relation of current process to the file + * + * Do not call if default_permissions is set + */ + +static int access_check_posix(struct SECURITY_CONTEXT *scx, + struct POSIX_SECURITY *pxdesc, mode_t request, + uid_t uid, gid_t gid) +{ + struct POSIX_ACE *pxace; + int userperms; + int groupperms; + int mask; + BOOL somegroup; + BOOL needgroups; + mode_t perms; + int i; + + perms = pxdesc->mode; + /* owner and root access */ + if (!scx->uid || (uid == scx->uid)) { + if (!scx->uid) { + /* root access if owner or other execution */ + if (perms & 0101) + perms = 07777; + else { + /* root access if some group execution */ + groupperms = 0; + mask = 7; + for (i=pxdesc->acccnt-1; i>=0 ; i--) { + pxace = &pxdesc->acl.ace[i]; + switch (pxace->tag) { + case POSIX_ACL_USER_OBJ : + case POSIX_ACL_GROUP_OBJ : + case POSIX_ACL_GROUP : + groupperms |= pxace->perms; + break; + case POSIX_ACL_MASK : + mask = pxace->perms & 7; + break; + default : + break; + } + } + perms = (groupperms & mask & 1) | 6; + } + } else + perms &= 07700; + } else { + /* + * analyze designated users, get mask + * and identify whether we need to check + * the group memberships. The groups are + * not needed when all groups have the + * same permissions as other for the + * requested modes. + */ + userperms = -1; + groupperms = -1; + needgroups = FALSE; + mask = 7; + for (i=pxdesc->acccnt-1; i>=0 ; i--) { + pxace = &pxdesc->acl.ace[i]; + switch (pxace->tag) { + case POSIX_ACL_USER : + if ((uid_t)pxace->id == scx->uid) + userperms = pxace->perms; + break; + case POSIX_ACL_MASK : + mask = pxace->perms & 7; + break; + case POSIX_ACL_GROUP_OBJ : + case POSIX_ACL_GROUP : + if (((pxace->perms & mask) ^ perms) + & (request >> 6) & 7) + needgroups = TRUE; + break; + default : + break; + } + } + /* designated users */ + if (userperms >= 0) + perms = (perms & 07000) + (userperms & mask); + else if (!needgroups) + perms &= 07007; + else { + /* owning group */ + if (!(~(perms >> 3) & request & mask) + && ((gid == scx->gid) + || groupmember(scx, scx->uid, gid))) + perms &= 07070; + else { + /* other groups */ + groupperms = -1; + somegroup = FALSE; + for (i=pxdesc->acccnt-1; i>=0 ; i--) { + pxace = &pxdesc->acl.ace[i]; + if ((pxace->tag == POSIX_ACL_GROUP) + && groupmember(scx, uid, pxace->id)) { + if (!(~pxace->perms & request & mask)) + groupperms = pxace->perms; + somegroup = TRUE; + } + } + if (groupperms >= 0) + perms = (perms & 07000) + (groupperms & mask); + else + if (somegroup) + perms = 0; + else + perms &= 07007; + } + } + } + return (perms); +} + +/* + * Get permissions to access a file + * Takes into account the relation of user to file (owner, group, ...) + * Do no use as mode of the file + * Do no call if default_permissions is set + * + * returns -1 if there is a problem + */ + +static int ntfs_get_perm(struct SECURITY_CONTEXT *scx, + ntfs_inode * ni, mode_t request) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const struct CACHED_PERMISSIONS *cached; + char *securattr; + const SID *usid; /* owner of file/directory */ + const SID *gsid; /* group of file/directory */ + uid_t uid; + gid_t gid; + int perm; + BOOL isdir; + struct POSIX_SECURITY *pxdesc; + + if (!scx->mapping[MAPUSERS]) + perm = 07777; + else { + /* check whether available in cache */ + cached = fetch_cache(scx,ni); + if (cached) { + uid = cached->uid; + gid = cached->gid; + perm = access_check_posix(scx,cached->pxdesc,request,uid,gid); + } else { + perm = 0; /* default to no permission */ + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + securattr = getsecurityattr(scx->vol, ni); + if (securattr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*) + securattr; + gsid = (const SID*)& + securattr[le32_to_cpu(phead->group)]; + gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); +#if OWNERFROMACL + usid = ntfs_acl_owner(securattr); + pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, + usid, gsid, isdir); + if (pxdesc) + perm = pxdesc->mode & 07777; + else + perm = -1; + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#else + usid = (const SID*)& + securattr[le32_to_cpu(phead->owner)]; + pxdesc = ntfs_build_permissions_posix(scx,securattr, + usid, gsid, isdir); + if (pxdesc) + perm = pxdesc->mode & 07777; + else + perm = -1; + if (!perm && ntfs_same_sid(usid, adminsid)) { + uid = find_tenant(scx, securattr); + if (uid) + perm = 0700; + } else + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#endif + /* + * Create a security id if there were none + * and upgrade option is selected + */ + if (!test_nino_flag(ni, v3_Extensions) + && (perm >= 0) + && (scx->vol->secure_flags + & (1 << SECURITY_ADDSECURIDS))) { + upgrade_secur_desc(scx->vol, + securattr, ni); + /* + * fetch owner and group for cacheing + * if there is a securid + */ + } + if (test_nino_flag(ni, v3_Extensions) + && (perm >= 0)) { + enter_cache(scx, ni, uid, + gid, pxdesc); + } + if (pxdesc) { + perm = access_check_posix(scx,pxdesc,request,uid,gid); + free(pxdesc); + } + free(securattr); + } else { + perm = -1; + uid = gid = 0; + } + } + } + return (perm); +} + +/* + * Get a Posix ACL + * + * returns size or -errno if there is a problem + * if size was too small, no copy is done and errno is not set, + * the caller is expected to issue a new call + */ + +int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *name, char *value, size_t size) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + struct POSIX_SECURITY *pxdesc; + const struct CACHED_PERMISSIONS *cached; + char *securattr; + const SID *usid; /* owner of file/directory */ + const SID *gsid; /* group of file/directory */ + uid_t uid; + gid_t gid; + int perm; + BOOL isdir; + size_t outsize; + + outsize = 0; /* default to error */ + if (!scx->mapping[MAPUSERS]) + errno = ENOTSUP; + else { + /* check whether available in cache */ + cached = fetch_cache(scx,ni); + if (cached) + pxdesc = cached->pxdesc; + else { + securattr = getsecurityattr(scx->vol, ni); + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + if (securattr) { + phead = + (const SECURITY_DESCRIPTOR_RELATIVE*) + securattr; + gsid = (const SID*)& + securattr[le32_to_cpu(phead->group)]; +#if OWNERFROMACL + usid = ntfs_acl_owner(securattr); +#else + usid = (const SID*)& + securattr[le32_to_cpu(phead->owner)]; +#endif + pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, + usid, gsid, isdir); + + /* + * fetch owner and group for cacheing + */ + if (pxdesc) { + perm = pxdesc->mode & 07777; + /* + * Create a security id if there were none + * and upgrade option is selected + */ + if (!test_nino_flag(ni, v3_Extensions) + && (scx->vol->secure_flags + & (1 << SECURITY_ADDSECURIDS))) { + upgrade_secur_desc(scx->vol, + securattr, ni); + } +#if OWNERFROMACL + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#else + if (!perm && ntfs_same_sid(usid, adminsid)) { + uid = find_tenant(scx, + securattr); + if (uid) + perm = 0700; + } else + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#endif + gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); + if (pxdesc->tagsset & POSIX_ACL_EXTENSIONS) + enter_cache(scx, ni, uid, + gid, pxdesc); + } + free(securattr); + } else + pxdesc = (struct POSIX_SECURITY*)NULL; + } + + if (pxdesc) { + if (ntfs_valid_posix(pxdesc)) { + if (!strcmp(name,"system.posix_acl_default")) { + if (ni->mrec->flags + & MFT_RECORD_IS_DIRECTORY) + outsize = sizeof(struct POSIX_ACL) + + pxdesc->defcnt*sizeof(struct POSIX_ACE); + else { + /* + * getting default ACL from plain file : + * return EACCES if size > 0 as + * indicated in the man, but return ok + * if size == 0, so that ls does not + * display an error + */ + if (size > 0) { + outsize = 0; + errno = EACCES; + } else + outsize = sizeof(struct POSIX_ACL); + } + if (outsize && (outsize <= size)) { + memcpy(value,&pxdesc->acl,sizeof(struct POSIX_ACL)); + memcpy(&value[sizeof(struct POSIX_ACL)], + &pxdesc->acl.ace[pxdesc->firstdef], + outsize-sizeof(struct POSIX_ACL)); + } + } else { + outsize = sizeof(struct POSIX_ACL) + + pxdesc->acccnt*sizeof(struct POSIX_ACE); + if (outsize <= size) + memcpy(value,&pxdesc->acl,outsize); + } + } else { + outsize = 0; + errno = EIO; + ntfs_log_error("Invalid Posix ACL built\n"); + } + if (!cached) + free(pxdesc); + } else + outsize = 0; + } + return (outsize ? (int)outsize : -errno); +} + +#else /* POSIXACLS */ + + +/* + * Get permissions to access a file + * Takes into account the relation of user to file (owner, group, ...) + * Do no use as mode of the file + * + * returns -1 if there is a problem + */ + +static int ntfs_get_perm(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, mode_t request) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const struct CACHED_PERMISSIONS *cached; + char *securattr; + const SID *usid; /* owner of file/directory */ + const SID *gsid; /* group of file/directory */ + BOOL isdir; + uid_t uid; + gid_t gid; + int perm; + + if (!scx->mapping[MAPUSERS] || (!scx->uid && !(request & S_IEXEC))) + perm = 07777; + else { + /* check whether available in cache */ + cached = fetch_cache(scx,ni); + if (cached) { + perm = cached->mode; + uid = cached->uid; + gid = cached->gid; + } else { + perm = 0; /* default to no permission */ + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + securattr = getsecurityattr(scx->vol, ni); + if (securattr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*) + securattr; + gsid = (const SID*)& + securattr[le32_to_cpu(phead->group)]; + gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); +#if OWNERFROMACL + usid = ntfs_acl_owner(securattr); + perm = ntfs_build_permissions(securattr, + usid, gsid, isdir); + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#else + usid = (const SID*)& + securattr[le32_to_cpu(phead->owner)]; + perm = ntfs_build_permissions(securattr, + usid, gsid, isdir); + if (!perm && ntfs_same_sid(usid, adminsid)) { + uid = find_tenant(scx, securattr); + if (uid) + perm = 0700; + } else + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#endif + /* + * Create a security id if there were none + * and upgrade option is selected + */ + if (!test_nino_flag(ni, v3_Extensions) + && (perm >= 0) + && (scx->vol->secure_flags + & (1 << SECURITY_ADDSECURIDS))) { + upgrade_secur_desc(scx->vol, + securattr, ni); + /* + * fetch owner and group for cacheing + * if there is a securid + */ + } + if (test_nino_flag(ni, v3_Extensions) + && (perm >= 0)) { + enter_cache(scx, ni, uid, + gid, perm); + } + free(securattr); + } else { + perm = -1; + uid = gid = 0; + } + } + if (perm >= 0) { + if (!scx->uid) { + /* root access and execution */ + if (perm & 0111) + perm = 07777; + else + perm = 0; + } else + if (uid == scx->uid) + perm &= 07700; + else + /* + * avoid checking group membership + * when the requested perms for group + * are the same as perms for other + */ + if ((gid == scx->gid) + || ((((perm >> 3) ^ perm) + & (request >> 6) & 7) + && groupmember(scx, scx->uid, gid))) + perm &= 07070; + else + perm &= 07007; + } + } + return (perm); +} + +#endif /* POSIXACLS */ + +/* + * Get an NTFS ACL + * + * Returns size or -errno if there is a problem + * if size was too small, no copy is done and errno is not set, + * the caller is expected to issue a new call + */ + +int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + char *value, size_t size) +{ + char *securattr; + size_t outsize; + + outsize = 0; /* default to no data and no error */ + securattr = getsecurityattr(scx->vol, ni); + if (securattr) { + outsize = ntfs_attr_size(securattr); + if (outsize <= size) { + memcpy(value,securattr,outsize); + } + free(securattr); + } + return (outsize ? (int)outsize : -errno); +} + +/* + * Get owner, group and permissions in an stat structure + * returns permissions, or -1 if there is a problem + */ + +int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx, + ntfs_inode * ni, struct stat *stbuf) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + char *securattr; + const SID *usid; /* owner of file/directory */ + const SID *gsid; /* group of file/directory */ + const struct CACHED_PERMISSIONS *cached; + int perm; + BOOL isdir; +#if POSIXACLS + struct POSIX_SECURITY *pxdesc; +#endif + + if (!scx->mapping[MAPUSERS]) + perm = 07777; + else { + /* check whether available in cache */ + cached = fetch_cache(scx,ni); + if (cached) { + perm = cached->mode; + stbuf->st_uid = cached->uid; + stbuf->st_gid = cached->gid; + stbuf->st_mode = (stbuf->st_mode & ~07777) + perm; + } else { + perm = -1; /* default to error */ + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + securattr = getsecurityattr(scx->vol, ni); + if (securattr) { + phead = + (const SECURITY_DESCRIPTOR_RELATIVE*) + securattr; + gsid = (const SID*)& + securattr[le32_to_cpu(phead->group)]; +#if OWNERFROMACL + usid = ntfs_acl_owner(securattr); +#else + usid = (const SID*)& + securattr[le32_to_cpu(phead->owner)]; +#endif +#if POSIXACLS + pxdesc = ntfs_build_permissions_posix(scx->mapping, securattr, + usid, gsid, isdir); + if (pxdesc) + perm = pxdesc->mode & 07777; + else + perm = -1; +#else + perm = ntfs_build_permissions(securattr, + usid, gsid, isdir); +#endif + /* + * fetch owner and group for cacheing + */ + if (perm >= 0) { + /* + * Create a security id if there were none + * and upgrade option is selected + */ + if (!test_nino_flag(ni, v3_Extensions) + && (scx->vol->secure_flags + & (1 << SECURITY_ADDSECURIDS))) { + upgrade_secur_desc(scx->vol, + securattr, ni); + } +#if OWNERFROMACL + stbuf->st_uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#else + if (!perm && ntfs_same_sid(usid, adminsid)) { + stbuf->st_uid = + find_tenant(scx, + securattr); + if (stbuf->st_uid) + perm = 0700; + } else + stbuf->st_uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#endif + stbuf->st_gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); + stbuf->st_mode = + (stbuf->st_mode & ~07777) + perm; +#if POSIXACLS + enter_cache(scx, ni, stbuf->st_uid, + stbuf->st_gid, pxdesc); + free(pxdesc); +#else + enter_cache(scx, ni, stbuf->st_uid, + stbuf->st_gid, perm); +#endif + } + free(securattr); + } + } + } + return (perm); +} + +#if POSIXACLS + +/* + * Get the base for a Posix inheritance and + * build an inherited Posix descriptor + */ + +static struct POSIX_SECURITY *inherit_posix(struct SECURITY_CONTEXT *scx, + ntfs_inode *dir_ni, mode_t mode, BOOL isdir) +{ + const struct CACHED_PERMISSIONS *cached; + const SECURITY_DESCRIPTOR_RELATIVE *phead; + struct POSIX_SECURITY *pxdesc; + struct POSIX_SECURITY *pydesc; + char *securattr; + const SID *usid; + const SID *gsid; + uid_t uid; + gid_t gid; + + pydesc = (struct POSIX_SECURITY*)NULL; + /* check whether parent directory is available in cache */ + cached = fetch_cache(scx,dir_ni); + if (cached) { + uid = cached->uid; + gid = cached->gid; + pxdesc = cached->pxdesc; + if (pxdesc) { + pydesc = ntfs_build_inherited_posix(pxdesc,mode, + scx->umask,isdir); + } + } else { + securattr = getsecurityattr(scx->vol, dir_ni); + if (securattr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*) + securattr; + gsid = (const SID*)& + securattr[le32_to_cpu(phead->group)]; + gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); +#if OWNERFROMACL + usid = ntfs_acl_owner(securattr); + pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, + usid, gsid, TRUE); + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#else + usid = (const SID*)& + securattr[le32_to_cpu(phead->owner)]; + pxdesc = ntfs_build_permissions_posix(scx->mapping,securattr, + usid, gsid, TRUE); + if (pxdesc && ntfs_same_sid(usid, adminsid)) { + uid = find_tenant(scx, securattr); + } else + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); +#endif + if (pxdesc) { + /* + * Create a security id if there were none + * and upgrade option is selected + */ + if (!test_nino_flag(dir_ni, v3_Extensions) + && (scx->vol->secure_flags + & (1 << SECURITY_ADDSECURIDS))) { + upgrade_secur_desc(scx->vol, + securattr, dir_ni); + /* + * fetch owner and group for cacheing + * if there is a securid + */ + } + if (test_nino_flag(dir_ni, v3_Extensions)) { + enter_cache(scx, dir_ni, uid, + gid, pxdesc); + } + pydesc = ntfs_build_inherited_posix(pxdesc, + mode, scx->umask, isdir); + free(pxdesc); + } + free(securattr); + } + } + return (pydesc); +} + +/* + * Allocate a security_id for a file being created + * + * Returns zero if not possible (NTFS v3.x required) + */ + +le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, + uid_t uid, gid_t gid, ntfs_inode *dir_ni, + mode_t mode, BOOL isdir) +{ +#if !FORCE_FORMAT_v1x + const struct CACHED_SECURID *cached; + struct CACHED_SECURID wanted; + struct POSIX_SECURITY *pxdesc; + char *newattr; + int newattrsz; + const SID *usid; + const SID *gsid; + BIGSID defusid; + BIGSID defgsid; + le32 securid; +#endif + + securid = const_cpu_to_le32(0); + +#if !FORCE_FORMAT_v1x + + pxdesc = inherit_posix(scx, dir_ni, mode, isdir); + if (pxdesc) { + /* check whether target securid is known in cache */ + + wanted.uid = uid; + wanted.gid = gid; + wanted.dmode = pxdesc->mode & mode & 07777; + if (isdir) wanted.dmode |= 0x10000; + wanted.variable = (void*)pxdesc; + wanted.varsize = sizeof(struct POSIX_SECURITY) + + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); + cached = (const struct CACHED_SECURID*)ntfs_fetch_cache( + scx->vol->securid_cache, GENERIC(&wanted), + (cache_compare)compare); + /* quite simple, if we are lucky */ + if (cached) + securid = cached->securid; + + /* not in cache : make sure we can create ids */ + + if (!cached && (scx->vol->major_ver >= 3)) { + usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); + gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); + if (!usid || !gsid) { + ntfs_log_error("File created by an unmapped user/group %d/%d\n", + (int)uid, (int)gid); + usid = gsid = adminsid; + } + newattr = ntfs_build_descr_posix(scx->mapping, pxdesc, + isdir, usid, gsid); + if (newattr) { + newattrsz = ntfs_attr_size(newattr); + securid = setsecurityattr(scx->vol, + (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, + newattrsz); + if (securid) { + /* update cache, for subsequent use */ + wanted.securid = securid; + ntfs_enter_cache(scx->vol->securid_cache, + GENERIC(&wanted), + (cache_compare)compare); + } + free(newattr); + } else { + /* + * could not build new security attribute + * errno set by ntfs_build_descr() + */ + } + } + free(pxdesc); + } +#endif + return (securid); +} + +/* + * Apply Posix inheritance to a newly created file + * (for NTFS 1.x only : no securid) + */ + +int ntfs_set_inherited_posix(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, + ntfs_inode *dir_ni, mode_t mode) +{ + struct POSIX_SECURITY *pxdesc; + char *newattr; + const SID *usid; + const SID *gsid; + BIGSID defusid; + BIGSID defgsid; + BOOL isdir; + int res; + + res = -1; + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); + pxdesc = inherit_posix(scx, dir_ni, mode, isdir); + if (pxdesc) { + usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); + gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); + if (!usid || !gsid) { + ntfs_log_error("File created by an unmapped user/group %d/%d\n", + (int)uid, (int)gid); + usid = gsid = adminsid; + } + newattr = ntfs_build_descr_posix(scx->mapping, pxdesc, + isdir, usid, gsid); + if (newattr) { + /* Adjust Windows read-only flag */ + res = update_secur_descr(scx->vol, newattr, ni); + if (!res && !isdir) { + if (mode & S_IWUSR) + ni->flags &= ~FILE_ATTR_READONLY; + else + ni->flags |= FILE_ATTR_READONLY; + } +#if CACHE_LEGACY_SIZE + /* also invalidate legacy cache */ + if (isdir && !ni->security_id) { + struct CACHED_PERMISSIONS_LEGACY legacy; + + legacy.mft_no = ni->mft_no; + legacy.variable = pxdesc; + legacy.varsize = sizeof(struct POSIX_SECURITY) + + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); + ntfs_invalidate_cache(scx->vol->legacy_cache, + GENERIC(&legacy), + (cache_compare)leg_compare,0); + } +#endif + free(newattr); + + } else { + /* + * could not build new security attribute + * errno set by ntfs_build_descr() + */ + } + } + return (res); +} + +#else + +le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, + uid_t uid, gid_t gid, mode_t mode, BOOL isdir) +{ +#if !FORCE_FORMAT_v1x + const struct CACHED_SECURID *cached; + struct CACHED_SECURID wanted; + char *newattr; + int newattrsz; + const SID *usid; + const SID *gsid; + BIGSID defusid; + BIGSID defgsid; + le32 securid; +#endif + + securid = const_cpu_to_le32(0); + +#if !FORCE_FORMAT_v1x + /* check whether target securid is known in cache */ + + wanted.uid = uid; + wanted.gid = gid; + wanted.dmode = mode & 07777; + if (isdir) wanted.dmode |= 0x10000; + wanted.variable = (void*)NULL; + wanted.varsize = 0; + cached = (const struct CACHED_SECURID*)ntfs_fetch_cache( + scx->vol->securid_cache, GENERIC(&wanted), + (cache_compare)compare); + /* quite simple, if we are lucky */ + if (cached) + securid = cached->securid; + + /* not in cache : make sure we can create ids */ + + if (!cached && (scx->vol->major_ver >= 3)) { + usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); + gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); + if (!usid || !gsid) { + ntfs_log_error("File created by an unmapped user/group %d/%d\n", + (int)uid, (int)gid); + usid = gsid = adminsid; + } + newattr = ntfs_build_descr(mode, isdir, usid, gsid); + if (newattr) { + newattrsz = ntfs_attr_size(newattr); + securid = setsecurityattr(scx->vol, + (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, + newattrsz); + if (securid) { + /* update cache, for subsequent use */ + wanted.securid = securid; + ntfs_enter_cache(scx->vol->securid_cache, + GENERIC(&wanted), + (cache_compare)compare); + } + free(newattr); + } else { + /* + * could not build new security attribute + * errno set by ntfs_build_descr() + */ + } + } +#endif + return (securid); +} + +#endif + +/* + * Update ownership and mode of a file, reusing an existing + * security descriptor when possible + * + * Returns zero if successful + */ + +#if POSIXACLS +int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + uid_t uid, gid_t gid, mode_t mode, + struct POSIX_SECURITY *pxdesc) +#else +int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + uid_t uid, gid_t gid, mode_t mode) +#endif +{ + int res; + const struct CACHED_SECURID *cached; + struct CACHED_SECURID wanted; + char *newattr; + const SID *usid; + const SID *gsid; + BIGSID defusid; + BIGSID defgsid; + BOOL isdir; + + res = 0; + + /* check whether target securid is known in cache */ + + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); + wanted.uid = uid; + wanted.gid = gid; + wanted.dmode = mode & 07777; + if (isdir) wanted.dmode |= 0x10000; +#if POSIXACLS + wanted.variable = (void*)pxdesc; + if (pxdesc) + wanted.varsize = sizeof(struct POSIX_SECURITY) + + (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE); + else + wanted.varsize = 0; +#else + wanted.variable = (void*)NULL; + wanted.varsize = 0; +#endif + if (test_nino_flag(ni, v3_Extensions)) { + cached = (const struct CACHED_SECURID*)ntfs_fetch_cache( + scx->vol->securid_cache, GENERIC(&wanted), + (cache_compare)compare); + /* quite simple, if we are lucky */ + if (cached) { + ni->security_id = cached->securid; + NInoSetDirty(ni); + } + } else cached = (struct CACHED_SECURID*)NULL; + + if (!cached) { + /* + * Do not use usid and gsid from former attributes, + * but recompute them to get repeatable results + * which can be kept in cache. + */ + usid = ntfs_find_usid(scx->mapping[MAPUSERS],uid,(SID*)&defusid); + gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS],gid,(SID*)&defgsid); + if (!usid || !gsid) { + ntfs_log_error("File made owned by an unmapped user/group %d/%d\n", + uid, gid); + usid = gsid = adminsid; + } +#if POSIXACLS + if (pxdesc) + newattr = ntfs_build_descr_posix(scx->mapping, pxdesc, + isdir, usid, gsid); + else + newattr = ntfs_build_descr(mode, + isdir, usid, gsid); +#else + newattr = ntfs_build_descr(mode, + isdir, usid, gsid); +#endif + if (newattr) { + res = update_secur_descr(scx->vol, newattr, ni); + if (!res) { + /* adjust Windows read-only flag */ + if (!isdir) { + if (mode & S_IWUSR) + ni->flags &= ~FILE_ATTR_READONLY; + else + ni->flags |= FILE_ATTR_READONLY; + NInoFileNameSetDirty(ni); + } + /* update cache, for subsequent use */ + if (test_nino_flag(ni, v3_Extensions)) { + wanted.securid = ni->security_id; + ntfs_enter_cache(scx->vol->securid_cache, + GENERIC(&wanted), + (cache_compare)compare); + } +#if CACHE_LEGACY_SIZE + /* also invalidate legacy cache */ + if (isdir && !ni->security_id) { + struct CACHED_PERMISSIONS_LEGACY legacy; + + legacy.mft_no = ni->mft_no; +#if POSIXACLS + legacy.variable = wanted.variable; + legacy.varsize = wanted.varsize; +#else + legacy.variable = (void*)NULL; + legacy.varsize = 0; +#endif + ntfs_invalidate_cache(scx->vol->legacy_cache, + GENERIC(&legacy), + (cache_compare)leg_compare,0); + } +#endif + } + free(newattr); + } else { + /* + * could not build new security attribute + * errno set by ntfs_build_descr() + */ + res = -1; + } + } + return (res); +} + +/* + * Check whether user has ownership rights on a file + * + * Returns TRUE if allowed + * if not, errno tells why + */ + +BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni) +{ + const struct CACHED_PERMISSIONS *cached; + char *oldattr; + const SID *usid; + uid_t processuid; + uid_t uid; + BOOL gotowner; + int allowed; + + processuid = scx->uid; +/* TODO : use CAP_FOWNER process capability */ + /* + * Always allow for root + * Also always allow if no mapping has been defined + */ + if (!scx->mapping[MAPUSERS] || !processuid) + allowed = TRUE; + else { + gotowner = FALSE; /* default */ + /* get the owner, either from cache or from old attribute */ + cached = fetch_cache(scx, ni); + if (cached) { + uid = cached->uid; + gotowner = TRUE; + } else { + oldattr = getsecurityattr(scx->vol, ni); + if (oldattr) { +#if OWNERFROMACL + usid = ntfs_acl_owner(oldattr); +#else + const SECURITY_DESCRIPTOR_RELATIVE *phead; + + phead = (const SECURITY_DESCRIPTOR_RELATIVE*) + oldattr; + usid = (const SID*)&oldattr + [le32_to_cpu(phead->owner)]; +#endif + uid = ntfs_find_user(scx->mapping[MAPUSERS], + usid); + gotowner = TRUE; + free(oldattr); + } + } + allowed = FALSE; + if (gotowner) { +/* TODO : use CAP_FOWNER process capability */ + if (!processuid || (processuid == uid)) + allowed = TRUE; + else + errno = EPERM; + } + } + return (allowed); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +#if POSIXACLS + +/* + * Set a new access or default Posix ACL to a file + * (or remove ACL if no input data) + * Validity of input data is checked after merging + * + * Returns 0, or -1 if there is a problem which errno describes + */ + +int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *name, const char *value, size_t size, + int flags) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const struct CACHED_PERMISSIONS *cached; + char *oldattr; + uid_t processuid; + const SID *usid; + const SID *gsid; + uid_t uid; + uid_t gid; + int res; + mode_t mode; + BOOL isdir; + BOOL deflt; + BOOL exist; + int count; + struct POSIX_SECURITY *oldpxdesc; + struct POSIX_SECURITY *newpxdesc; + + /* get the current pxsec, either from cache or from old attribute */ + res = -1; + deflt = !strcmp(name,"system.posix_acl_default"); + if (size) + count = (size - sizeof(struct POSIX_ACL)) / sizeof(struct POSIX_ACE); + else + count = 0; + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); + newpxdesc = (struct POSIX_SECURITY*)NULL; + if ((!value + || (((const struct POSIX_ACL*)value)->version == POSIX_VERSION)) + && (!deflt || isdir || (!size && !value))) { + cached = fetch_cache(scx, ni); + if (cached) { + uid = cached->uid; + gid = cached->gid; + oldpxdesc = cached->pxdesc; + if (oldpxdesc) { + mode = oldpxdesc->mode; + newpxdesc = ntfs_replace_acl(oldpxdesc, + (const struct POSIX_ACL*)value,count,deflt); + } + } else { + oldattr = getsecurityattr(scx->vol, ni); + if (oldattr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)oldattr; +#if OWNERFROMACL + usid = ntfs_acl_owner(oldattr); +#else + usid = (const SID*)&oldattr[le32_to_cpu(phead->owner)]; +#endif + gsid = (const SID*)&oldattr[le32_to_cpu(phead->group)]; + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); + gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); + oldpxdesc = ntfs_build_permissions_posix(scx->mapping, + oldattr, usid, gsid, isdir); + if (oldpxdesc) { + if (deflt) + exist = oldpxdesc->defcnt > 0; + else + exist = oldpxdesc->acccnt > 3; + if ((exist && (flags & XATTR_CREATE)) + || (!exist && (flags & XATTR_REPLACE))) { + errno = (exist ? EEXIST : ENODATA); + } else { + mode = oldpxdesc->mode; + newpxdesc = ntfs_replace_acl(oldpxdesc, + (const struct POSIX_ACL*)value,count,deflt); + } + free(oldpxdesc); + } + free(oldattr); + } + } + } else + errno = EINVAL; + + if (newpxdesc) { + processuid = scx->uid; +/* TODO : use CAP_FOWNER process capability */ + if (!processuid || (uid == processuid)) { + /* + * clear setgid if file group does + * not match process group + */ + if (processuid && (gid != scx->gid) + && !groupmember(scx, scx->uid, gid)) { + newpxdesc->mode &= ~S_ISGID; + } + res = ntfs_set_owner_mode(scx, ni, uid, gid, + newpxdesc->mode, newpxdesc); + } else + errno = EPERM; + free(newpxdesc); + } + return (res ? -1 : 0); +} + +/* + * Remove a default Posix ACL from a file + * + * Returns 0, or -1 if there is a problem which errno describes + */ + +int ntfs_remove_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *name) +{ + return (ntfs_set_posix_acl(scx, ni, name, + (const char*)NULL, 0, 0)); +} + +#endif + +/* + * Set a new NTFS ACL to a file + * + * Returns 0, or -1 if there is a problem + */ + +int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *value, size_t size, int flags) +{ + char *attr; + int res; + + res = -1; + if ((size > 0) + && !(flags & XATTR_CREATE) + && ntfs_valid_descr(value,size) + && (ntfs_attr_size(value) == size)) { + /* need copying in order to write */ + attr = (char*)ntfs_malloc(size); + if (attr) { + memcpy(attr,value,size); + res = update_secur_descr(scx->vol, attr, ni); + /* + * No need to invalidate standard caches : + * the relation between a securid and + * the associated protection is unchanged, + * only the relation between a file and + * its securid and protection is changed. + */ +#if CACHE_LEGACY_SIZE + /* + * we must however invalidate the legacy + * cache, which is based on inode numbers. + * For safety, invalidate even if updating + * failed. + */ + if ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + && !ni->security_id) { + struct CACHED_PERMISSIONS_LEGACY legacy; + + legacy.mft_no = ni->mft_no; + legacy.variable = (char*)NULL; + legacy.varsize = 0; + ntfs_invalidate_cache(scx->vol->legacy_cache, + GENERIC(&legacy), + (cache_compare)leg_compare,0); + } +#endif + free(attr); + } else + errno = ENOMEM; + } else + errno = EINVAL; + return (res ? -1 : 0); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Set new permissions to a file + * Checks user mapping has been defined before request for setting + * + * rejected if request is not originated by owner or root + * + * returns 0 on success + * -1 on failure, with errno = EIO + */ + +int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const struct CACHED_PERMISSIONS *cached; + char *oldattr; + const SID *usid; + const SID *gsid; + uid_t processuid; + uid_t uid; + uid_t gid; + int res; +#if POSIXACLS + BOOL isdir; + int pxsize; + const struct POSIX_SECURITY *oldpxdesc; + struct POSIX_SECURITY *newpxdesc = (struct POSIX_SECURITY*)NULL; +#endif + + /* get the current owner, either from cache or from old attribute */ + res = 0; + cached = fetch_cache(scx, ni); + if (cached) { + uid = cached->uid; + gid = cached->gid; +#if POSIXACLS + oldpxdesc = cached->pxdesc; + if (oldpxdesc) { + /* must copy before merging */ + pxsize = sizeof(struct POSIX_SECURITY) + + (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE); + newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize); + if (newpxdesc) { + memcpy(newpxdesc, oldpxdesc, pxsize); + if (ntfs_merge_mode_posix(newpxdesc, mode)) + res = -1; + } else + res = -1; + } else + newpxdesc = (struct POSIX_SECURITY*)NULL; +#endif + } else { + oldattr = getsecurityattr(scx->vol, ni); + if (oldattr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)oldattr; +#if OWNERFROMACL + usid = ntfs_acl_owner(oldattr); +#else + usid = (const SID*)&oldattr[le32_to_cpu(phead->owner)]; +#endif + gsid = (const SID*)&oldattr[le32_to_cpu(phead->group)]; + uid = ntfs_find_user(scx->mapping[MAPUSERS],usid); + gid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); +#if POSIXACLS + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0); + newpxdesc = ntfs_build_permissions_posix(scx->mapping, + oldattr, usid, gsid, isdir); + if (!newpxdesc || ntfs_merge_mode_posix(newpxdesc, mode)) + res = -1; +#endif + free(oldattr); + } else + res = -1; + } + + if (!res) { + processuid = scx->uid; +/* TODO : use CAP_FOWNER process capability */ + if (!processuid || (uid == processuid)) { + /* + * clear setgid if file group does + * not match process group + */ + if (processuid && (gid != scx->gid) + && !groupmember(scx, scx->uid, gid)) + mode &= ~S_ISGID; +#if POSIXACLS + if (newpxdesc) { + newpxdesc->mode = mode; + res = ntfs_set_owner_mode(scx, ni, uid, gid, + mode, newpxdesc); + } else + res = ntfs_set_owner_mode(scx, ni, uid, gid, + mode, newpxdesc); +#else + res = ntfs_set_owner_mode(scx, ni, uid, gid, mode); +#endif + } else { + errno = EPERM; + res = -1; /* neither owner nor root */ + } + } else { + /* + * Should not happen : a default descriptor is generated + * by getsecurityattr() when there are none + */ + ntfs_log_error("File has no security descriptor\n"); + res = -1; + errno = EIO; + } +#if POSIXACLS + if (newpxdesc) free(newpxdesc); +#endif + return (res ? -1 : 0); +} + +/* + * Create a default security descriptor for files whose descriptor + * cannot be inherited + */ + +int ntfs_sd_add_everyone(ntfs_inode *ni) +{ + /* JPA SECURITY_DESCRIPTOR_ATTR *sd; */ + SECURITY_DESCRIPTOR_RELATIVE *sd; + ACL *acl; + ACCESS_ALLOWED_ACE *ace; + SID *sid; + int ret, sd_len; + + /* Create SECURITY_DESCRIPTOR attribute (everyone has full access). */ + /* + * Calculate security descriptor length. We have 2 sub-authorities in + * owner and group SIDs, but structure SID contain only one, so add + * 4 bytes to every SID. + */ + sd_len = sizeof(SECURITY_DESCRIPTOR_ATTR) + 2 * (sizeof(SID) + 4) + + sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE); + sd = (SECURITY_DESCRIPTOR_RELATIVE*)ntfs_calloc(sd_len); + if (!sd) + return -1; + + sd->revision = SECURITY_DESCRIPTOR_REVISION; + sd->control = SE_DACL_PRESENT | SE_SELF_RELATIVE; + + sid = (SID*)((u8*)sd + sizeof(SECURITY_DESCRIPTOR_ATTR)); + sid->revision = SID_REVISION; + sid->sub_authority_count = 2; + sid->sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = const_cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + sid->identifier_authority.value[5] = 5; + sd->owner = cpu_to_le32((u8*)sid - (u8*)sd); + + sid = (SID*)((u8*)sid + sizeof(SID) + 4); + sid->revision = SID_REVISION; + sid->sub_authority_count = 2; + sid->sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID); + sid->sub_authority[1] = const_cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS); + sid->identifier_authority.value[5] = 5; + sd->group = cpu_to_le32((u8*)sid - (u8*)sd); + + acl = (ACL*)((u8*)sid + sizeof(SID) + 4); + acl->revision = ACL_REVISION; + acl->size = const_cpu_to_le16(sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE)); + acl->ace_count = const_cpu_to_le16(1); + sd->dacl = cpu_to_le32((u8*)acl - (u8*)sd); + + ace = (ACCESS_ALLOWED_ACE*)((u8*)acl + sizeof(ACL)); + ace->type = ACCESS_ALLOWED_ACE_TYPE; + ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + ace->size = const_cpu_to_le16(sizeof(ACCESS_ALLOWED_ACE)); + ace->mask = const_cpu_to_le32(0x1f01ff); /* FIXME */ + ace->sid.revision = SID_REVISION; + ace->sid.sub_authority_count = 1; + ace->sid.sub_authority[0] = const_cpu_to_le32(0); + ace->sid.identifier_authority.value[5] = 1; + + ret = ntfs_attr_add(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0, (u8*)sd, + sd_len); + if (ret) + ntfs_log_perror("Failed to add initial SECURITY_DESCRIPTOR"); + + free(sd); + return ret; +} + +/* + * Check whether user can access a file in a specific way + * + * Returns 1 if access is allowed, including user is root or no + * user mapping defined + * 2 if sticky and accesstype is S_IWRITE + S_IEXEC + S_ISVTX + * 0 and sets errno if there is a problem or if access + * is not allowed + * + * This is used for Posix ACL and checking creation of DOS file names + */ + +int ntfs_allowed_access(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, + int accesstype) /* access type required (S_Ixxx values) */ +{ + int perm; + int res; + int allow; + struct stat stbuf; + + /* + * Always allow for root unless execution is requested. + * (was checked by fuse until kernel 2.6.29) + * Also always allow if no mapping has been defined + */ + if (!scx->mapping[MAPUSERS] + || (!scx->uid + && (!(accesstype & S_IEXEC) + || (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)))) + allow = 1; + else { + perm = ntfs_get_perm(scx, ni, accesstype); + if (perm >= 0) { + res = EACCES; + switch (accesstype) { + case S_IEXEC: + allow = (perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0; + break; + case S_IWRITE: + allow = (perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0; + break; + case S_IWRITE + S_IEXEC: + allow = ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) + && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); + break; + case S_IREAD: + allow = (perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0; + break; + case S_IREAD + S_IEXEC: + allow = ((perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) + && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); + break; + case S_IREAD + S_IWRITE: + allow = ((perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) + && ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0); + break; + case S_IWRITE + S_IEXEC + S_ISVTX: + if (perm & S_ISVTX) { + if ((ntfs_get_owner_mode(scx,ni,&stbuf) >= 0) + && (stbuf.st_uid == scx->uid)) + allow = 1; + else + allow = 2; + } else + allow = ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) + && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); + break; + case S_IREAD + S_IWRITE + S_IEXEC: + allow = ((perm & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) + && ((perm & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) + && ((perm & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0); + break; + default : + res = EINVAL; + allow = 0; + break; + } + if (!allow) + errno = res; + } else + allow = 0; + } + return (allow); +} + +#if 0 /* not needed any more */ + +/* + * Check whether user can access the parent directory + * of a file in a specific way + * + * Returns true if access is allowed, including user is root and + * no user mapping defined + * + * Sets errno if there is a problem or if not allowed + * + * This is used for Posix ACL and checking creation of DOS file names + */ + +BOOL old_ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, + const char *path, int accesstype) +{ + int allow; + char *dirpath; + char *name; + ntfs_inode *ni; + ntfs_inode *dir_ni; + struct stat stbuf; + + allow = 0; + dirpath = strdup(path); + if (dirpath) { + /* the root of file system is seen as a parent of itself */ + /* is that correct ? */ + name = strrchr(dirpath, '/'); + *name = 0; + dir_ni = ntfs_pathname_to_inode(scx->vol, NULL, dirpath); + if (dir_ni) { + allow = ntfs_allowed_access(scx, + dir_ni, accesstype); + ntfs_inode_close(dir_ni); + /* + * for an not-owned sticky directory, have to + * check whether file itself is owned + */ + if ((accesstype == (S_IWRITE + S_IEXEC + S_ISVTX)) + && (allow == 2)) { + ni = ntfs_pathname_to_inode(scx->vol, NULL, + path); + allow = FALSE; + if (ni) { + allow = (ntfs_get_owner_mode(scx,ni,&stbuf) >= 0) + && (stbuf.st_uid == scx->uid); + ntfs_inode_close(ni); + } + } + } + free(dirpath); + } + return (allow); /* errno is set if not allowed */ +} + +#endif + +/* + * Define a new owner/group to a file + * + * returns zero if successful + */ + +int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + uid_t uid, gid_t gid) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const struct CACHED_PERMISSIONS *cached; + char *oldattr; + const SID *usid; + const SID *gsid; + uid_t fileuid; + uid_t filegid; + mode_t mode; + int perm; + BOOL isdir; + int res; +#if POSIXACLS + struct POSIX_SECURITY *pxdesc; + BOOL pxdescbuilt = FALSE; +#endif + + res = 0; + /* get the current owner and mode from cache or security attributes */ + oldattr = (char*)NULL; + cached = fetch_cache(scx,ni); + if (cached) { + fileuid = cached->uid; + filegid = cached->gid; + mode = cached->mode; +#if POSIXACLS + pxdesc = cached->pxdesc; + if (!pxdesc) + res = -1; +#endif + } else { + fileuid = 0; + filegid = 0; + mode = 0; + oldattr = getsecurityattr(scx->vol, ni); + if (oldattr) { + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + phead = (const SECURITY_DESCRIPTOR_RELATIVE*) + oldattr; + gsid = (const SID*) + &oldattr[le32_to_cpu(phead->group)]; +#if OWNERFROMACL + usid = ntfs_acl_owner(oldattr); +#else + usid = (const SID*) + &oldattr[le32_to_cpu(phead->owner)]; +#endif +#if POSIXACLS + pxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr, + usid, gsid, isdir); + if (pxdesc) { + pxdescbuilt = TRUE; + fileuid = ntfs_find_user(scx->mapping[MAPUSERS],usid); + filegid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); + mode = perm = pxdesc->mode; + } else + res = -1; +#else + mode = perm = ntfs_build_permissions(oldattr, + usid, gsid, isdir); + if (perm >= 0) { + fileuid = ntfs_find_user(scx->mapping[MAPUSERS],usid); + filegid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); + } else + res = -1; +#endif + free(oldattr); + } else + res = -1; + } + if (!res) { + /* check requested by root */ + /* or chgrp requested by owner to an owned group */ + if (!scx->uid + || ((((int)uid < 0) || (uid == fileuid)) + && ((gid == scx->gid) || groupmember(scx, scx->uid, gid)) + && (fileuid == scx->uid))) { + /* replace by the new usid and gsid */ + /* or reuse old gid and sid for cacheing */ + if ((int)uid < 0) + uid = fileuid; + if ((int)gid < 0) + gid = filegid; + /* clear setuid and setgid if owner has changed */ + /* unless request originated by root */ + if (uid && (fileuid != uid)) + mode &= 01777; +#if POSIXACLS + res = ntfs_set_owner_mode(scx, ni, uid, gid, + mode, pxdesc); +#else + res = ntfs_set_owner_mode(scx, ni, uid, gid, mode); +#endif + } else { + res = -1; /* neither owner nor root */ + errno = EPERM; + } +#if POSIXACLS + if (pxdescbuilt) + free(pxdesc); +#endif + } else { + /* + * Should not happen : a default descriptor is generated + * by getsecurityattr() when there are none + */ + ntfs_log_error("File has no security descriptor\n"); + res = -1; + errno = EIO; + } + return (res ? -1 : 0); +} + +/* + * Define new owner/group and mode to a file + * + * returns zero if successful + */ + +int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + uid_t uid, gid_t gid, const mode_t mode) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + const struct CACHED_PERMISSIONS *cached; + char *oldattr; + const SID *usid; + const SID *gsid; + uid_t fileuid; + uid_t filegid; + BOOL isdir; + int res; +#if POSIXACLS + const struct POSIX_SECURITY *oldpxdesc; + struct POSIX_SECURITY *newpxdesc = (struct POSIX_SECURITY*)NULL; + int pxsize; +#endif + + res = 0; + /* get the current owner and mode from cache or security attributes */ + oldattr = (char*)NULL; + cached = fetch_cache(scx,ni); + if (cached) { + fileuid = cached->uid; + filegid = cached->gid; +#if POSIXACLS + oldpxdesc = cached->pxdesc; + if (oldpxdesc) { + /* must copy before merging */ + pxsize = sizeof(struct POSIX_SECURITY) + + (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE); + newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize); + if (newpxdesc) { + memcpy(newpxdesc, oldpxdesc, pxsize); + if (ntfs_merge_mode_posix(newpxdesc, mode)) + res = -1; + } else + res = -1; + } +#endif + } else { + fileuid = 0; + filegid = 0; + oldattr = getsecurityattr(scx->vol, ni); + if (oldattr) { + isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + != const_cpu_to_le16(0); + phead = (const SECURITY_DESCRIPTOR_RELATIVE*) + oldattr; + gsid = (const SID*) + &oldattr[le32_to_cpu(phead->group)]; +#if OWNERFROMACL + usid = ntfs_acl_owner(oldattr); +#else + usid = (const SID*) + &oldattr[le32_to_cpu(phead->owner)]; +#endif +#if POSIXACLS + newpxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr, + usid, gsid, isdir); + if (!newpxdesc || ntfs_merge_mode_posix(newpxdesc, mode)) + res = -1; + else { + fileuid = ntfs_find_user(scx->mapping[MAPUSERS],usid); + filegid = ntfs_find_group(scx->mapping[MAPGROUPS],gsid); + } +#endif + free(oldattr); + } else + res = -1; + } + if (!res) { + /* check requested by root */ + /* or chgrp requested by owner to an owned group */ + if (!scx->uid + || ((((int)uid < 0) || (uid == fileuid)) + && ((gid == scx->gid) || groupmember(scx, scx->uid, gid)) + && (fileuid == scx->uid))) { + /* replace by the new usid and gsid */ + /* or reuse old gid and sid for cacheing */ + if ((int)uid < 0) + uid = fileuid; + if ((int)gid < 0) + gid = filegid; +#if POSIXACLS + res = ntfs_set_owner_mode(scx, ni, uid, gid, + mode, newpxdesc); +#else + res = ntfs_set_owner_mode(scx, ni, uid, gid, mode); +#endif + } else { + res = -1; /* neither owner nor root */ + errno = EPERM; + } + } else { + /* + * Should not happen : a default descriptor is generated + * by getsecurityattr() when there are none + */ + ntfs_log_error("File has no security descriptor\n"); + res = -1; + errno = EIO; + } +#if POSIXACLS + free(newpxdesc); +#endif + return (res ? -1 : 0); +} + +/* + * Build a security id for a descriptor inherited from + * parent directory the Windows way + */ + +static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, + const char *parentattr, BOOL fordir) +{ + const SECURITY_DESCRIPTOR_RELATIVE *pphead; + const ACL *ppacl; + const SID *usid; + const SID *gsid; + BIGSID defusid; + BIGSID defgsid; + int offpacl; + int offowner; + int offgroup; + SECURITY_DESCRIPTOR_RELATIVE *pnhead; + ACL *pnacl; + int parentattrsz; + char *newattr; + int newattrsz; + int aclsz; + int usidsz; + int gsidsz; + int pos; + le32 securid; + + parentattrsz = ntfs_attr_size(parentattr); + pphead = (const SECURITY_DESCRIPTOR_RELATIVE*)parentattr; + if (scx->mapping[MAPUSERS]) { + usid = ntfs_find_usid(scx->mapping[MAPUSERS], scx->uid, (SID*)&defusid); + gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS], scx->gid, (SID*)&defgsid); + if (!usid) + usid = adminsid; + if (!gsid) + gsid = adminsid; + } else { + /* + * If there is no user mapping, we have to copy owner + * and group from parent directory. + * Windows never has to do that, because it can always + * rely on a user mapping + */ + offowner = le32_to_cpu(pphead->owner); + usid = (const SID*)&parentattr[offowner]; + offgroup = le32_to_cpu(pphead->group); + gsid = (const SID*)&parentattr[offgroup]; + } + /* + * new attribute is smaller than parent's + * except for differences in SIDs which appear in + * owner, group and possible grants and denials in + * generic creator-owner and creator-group ACEs. + * For directories, an ACE may be duplicated for + * access and inheritance, so we double the count. + */ + usidsz = ntfs_sid_size(usid); + gsidsz = ntfs_sid_size(gsid); + newattrsz = parentattrsz + 3*usidsz + 3*gsidsz; + if (fordir) + newattrsz *= 2; + newattr = (char*)ntfs_malloc(newattrsz); + if (newattr) { + pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)newattr; + pnhead->revision = SECURITY_DESCRIPTOR_REVISION; + pnhead->alignment = 0; + pnhead->control = SE_SELF_RELATIVE; + pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + /* + * locate and inherit DACL + * do not test SE_DACL_PRESENT (wrong for "DR Watson") + */ + pnhead->dacl = const_cpu_to_le32(0); + if (pphead->dacl) { + offpacl = le32_to_cpu(pphead->dacl); + ppacl = (const ACL*)&parentattr[offpacl]; + pnacl = (ACL*)&newattr[pos]; + aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid, fordir); + if (aclsz) { + pnhead->dacl = cpu_to_le32(pos); + pos += aclsz; + pnhead->control |= SE_DACL_PRESENT; + } + } + /* + * locate and inherit SACL + */ + pnhead->sacl = const_cpu_to_le32(0); + if (pphead->sacl) { + offpacl = le32_to_cpu(pphead->sacl); + ppacl = (const ACL*)&parentattr[offpacl]; + pnacl = (ACL*)&newattr[pos]; + aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid, fordir); + if (aclsz) { + pnhead->sacl = cpu_to_le32(pos); + pos += aclsz; + pnhead->control |= SE_SACL_PRESENT; + } + } + /* + * inherit or redefine owner + */ + memcpy(&newattr[pos],usid,usidsz); + pnhead->owner = cpu_to_le32(pos); + pos += usidsz; + /* + * inherit or redefine group + */ + memcpy(&newattr[pos],gsid,gsidsz); + pnhead->group = cpu_to_le32(pos); + pos += usidsz; + securid = setsecurityattr(scx->vol, + (SECURITY_DESCRIPTOR_RELATIVE*)newattr, pos); + free(newattr); + } else + securid = const_cpu_to_le32(0); + return (securid); +} + +/* + * Get an inherited security id + * + * For Windows compatibility, the normal initial permission setting + * may be inherited from the parent directory instead of being + * defined by the creation arguments. + * + * The following creates an inherited id for that purpose. + * + * Note : the owner and group of parent directory are also + * inherited (which is not the case on Windows) if no user mapping + * is defined. + * + * Returns the inherited id, or zero if not possible (eg on NTFS 1.x) + */ + +le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx, + ntfs_inode *dir_ni, BOOL fordir) +{ + struct CACHED_PERMISSIONS *cached; + char *parentattr; + le32 securid; + + securid = const_cpu_to_le32(0); + cached = (struct CACHED_PERMISSIONS*)NULL; + /* + * Try to get inherited id from cache + */ + if (test_nino_flag(dir_ni, v3_Extensions) + && dir_ni->security_id) { + cached = fetch_cache(scx, dir_ni); + if (cached) + securid = (fordir ? cached->inh_dirid + : cached->inh_fileid); + } + /* + * Not cached or not available in cache, compute it all + * Note : if parent directory has no id, it is not cacheable + */ + if (!securid) { + parentattr = getsecurityattr(scx->vol, dir_ni); + if (parentattr) { + securid = build_inherited_id(scx, + parentattr, fordir); + free(parentattr); + /* + * Store the result into cache for further use + */ + if (securid) { + cached = fetch_cache(scx, dir_ni); + if (cached) { + if (fordir) + cached->inh_dirid = securid; + else + cached->inh_fileid = securid; + } + } + } + } + return (securid); +} + +/* + * Link a group to a member of group + * + * Returns 0 if OK, -1 (and errno set) if error + */ + +static int link_single_group(struct MAPPING *usermapping, struct passwd *user, + gid_t gid) +{ + struct group *group; + char **grmem; + int grcnt; + gid_t *groups; + int res; + + res = 0; + group = getgrgid(gid); + if (group && group->gr_mem) { + grcnt = usermapping->grcnt; + groups = usermapping->groups; + grmem = group->gr_mem; + while (*grmem && strcmp(user->pw_name, *grmem)) + grmem++; + if (*grmem) { + if (!grcnt) + groups = (gid_t*)malloc(sizeof(gid_t)); + else + groups = (gid_t*)realloc(groups, + (grcnt+1)*sizeof(gid_t)); + if (groups) + groups[grcnt++] = gid; + else { + res = -1; + errno = ENOMEM; + } + } + usermapping->grcnt = grcnt; + usermapping->groups = groups; + } + return (res); +} + + +/* + * Statically link group to users + * This is based on groups defined in /etc/group and does not take + * the groups dynamically set by setgroups() nor any changes in + * /etc/group into account + * + * Only mapped groups and root group are linked to mapped users + * + * Returns 0 if OK, -1 (and errno set) if error + * + */ + +static int link_group_members(struct SECURITY_CONTEXT *scx) +{ + struct MAPPING *usermapping; + struct MAPPING *groupmapping; + struct passwd *user; + int res; + + res = 0; + for (usermapping=scx->mapping[MAPUSERS]; usermapping && !res; + usermapping=usermapping->next) { + usermapping->grcnt = 0; + usermapping->groups = (gid_t*)NULL; + user = getpwuid(usermapping->xid); + if (user && user->pw_name) { + for (groupmapping=scx->mapping[MAPGROUPS]; + groupmapping && !res; + groupmapping=groupmapping->next) { + if (link_single_group(usermapping, user, + groupmapping->xid)) + res = -1; + } + if (!res && link_single_group(usermapping, + user, (gid_t)0)) + res = -1; + } + } + return (res); +} + +/* + * Apply default single user mapping + * returns zero if successful + */ + +static int ntfs_do_default_mapping(struct SECURITY_CONTEXT *scx, + uid_t uid, gid_t gid, const SID *usid) +{ + struct MAPPING *usermapping; + struct MAPPING *groupmapping; + SID *sid; + int sidsz; + int res; + + res = -1; + sidsz = ntfs_sid_size(usid); + sid = (SID*)ntfs_malloc(sidsz); + if (sid) { + memcpy(sid,usid,sidsz); + usermapping = (struct MAPPING*)ntfs_malloc(sizeof(struct MAPPING)); + if (usermapping) { + groupmapping = (struct MAPPING*)ntfs_malloc(sizeof(struct MAPPING)); + if (groupmapping) { + usermapping->sid = sid; + usermapping->xid = uid; + usermapping->next = (struct MAPPING*)NULL; + groupmapping->sid = sid; + groupmapping->xid = gid; + groupmapping->next = (struct MAPPING*)NULL; + scx->mapping[MAPUSERS] = usermapping; + scx->mapping[MAPGROUPS] = groupmapping; + res = 0; + } + } + } + return (res); +} + +/* + * Make sure there are no ambiguous mapping + * Ambiguous mapping may lead to undesired configurations and + * we had rather be safe until the consequences are understood + */ + +#if 0 /* not activated for now */ + +static BOOL check_mapping(const struct MAPPING *usermapping, + const struct MAPPING *groupmapping) +{ + const struct MAPPING *mapping1; + const struct MAPPING *mapping2; + BOOL ambiguous; + + ambiguous = FALSE; + for (mapping1=usermapping; mapping1; mapping1=mapping1->next) + for (mapping2=mapping1->next; mapping2; mapping1=mapping2->next) + if (ntfs_same_sid(mapping1->sid,mapping2->sid)) { + if (mapping1->xid != mapping2->xid) + ambiguous = TRUE; + } else { + if (mapping1->xid == mapping2->xid) + ambiguous = TRUE; + } + for (mapping1=groupmapping; mapping1; mapping1=mapping1->next) + for (mapping2=mapping1->next; mapping2; mapping1=mapping2->next) + if (ntfs_same_sid(mapping1->sid,mapping2->sid)) { + if (mapping1->xid != mapping2->xid) + ambiguous = TRUE; + } else { + if (mapping1->xid == mapping2->xid) + ambiguous = TRUE; + } + return (ambiguous); +} + +#endif + +#if 0 /* not used any more */ + +/* + * Try and apply default single user mapping + * returns zero if successful + */ + +static int ntfs_default_mapping(struct SECURITY_CONTEXT *scx) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + ntfs_inode *ni; + char *securattr; + const SID *usid; + int res; + + res = -1; + ni = ntfs_pathname_to_inode(scx->vol, NULL, "/."); + if (ni) { + securattr = getsecurityattr(scx->vol, ni); + if (securattr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr; + usid = (SID*)&securattr[le32_to_cpu(phead->owner)]; + if (ntfs_is_user_sid(usid)) + res = ntfs_do_default_mapping(scx, + scx->uid, scx->gid, usid); + free(securattr); + } + ntfs_inode_close(ni); + } + return (res); +} + +#endif + +/* + * Basic read from a user mapping file on another volume + */ + +static int basicread(void *fileid, char *buf, size_t size, off_t offs __attribute__((unused))) +{ + return (read(*(int*)fileid, buf, size)); +} + + +/* + * Read from a user mapping file on current NTFS partition + */ + +static int localread(void *fileid, char *buf, size_t size, off_t offs) +{ + return (ntfs_local_read((ntfs_inode*)fileid, + AT_UNNAMED, 0, buf, size, offs)); +} + +/* + * Build the user mapping + * - according to a mapping file if defined (or default present), + * - or try default single user mapping if possible + * + * The mapping is specific to a mounted device + * No locking done, mounting assumed non multithreaded + * + * returns zero if mapping is successful + * (failure should not be interpreted as an error) + */ + +int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path, + BOOL allowdef) +{ + struct MAPLIST *item; + struct MAPLIST *firstitem; + struct MAPPING *usermapping; + struct MAPPING *groupmapping; + ntfs_inode *ni; + int fd; + static struct { + u8 revision; + u8 levels; + be16 highbase; + be32 lowbase; + le32 level1; + le32 level2; + le32 level3; + le32 level4; + le32 level5; + } defmap = { + 1, 5, const_cpu_to_be16(0), const_cpu_to_be32(5), + const_cpu_to_le32(21), + const_cpu_to_le32(DEFSECAUTH1), const_cpu_to_le32(DEFSECAUTH2), + const_cpu_to_le32(DEFSECAUTH3), const_cpu_to_le32(DEFSECBASE) + } ; + + /* be sure not to map anything until done */ + scx->mapping[MAPUSERS] = (struct MAPPING*)NULL; + scx->mapping[MAPGROUPS] = (struct MAPPING*)NULL; + + if (!usermap_path) usermap_path = MAPPINGFILE; + if (usermap_path[0] == '/') { + fd = open(usermap_path,O_RDONLY); + if (fd > 0) { + firstitem = ntfs_read_mapping(basicread, (void*)&fd); + close(fd); + } else + firstitem = (struct MAPLIST*)NULL; + } else { + ni = ntfs_pathname_to_inode(scx->vol, NULL, usermap_path); + if (ni) { + firstitem = ntfs_read_mapping(localread, ni); + ntfs_inode_close(ni); + } else + firstitem = (struct MAPLIST*)NULL; + } + + + if (firstitem) { + usermapping = ntfs_do_user_mapping(firstitem); + groupmapping = ntfs_do_group_mapping(firstitem); + if (usermapping && groupmapping) { + scx->mapping[MAPUSERS] = usermapping; + scx->mapping[MAPGROUPS] = groupmapping; + } else + ntfs_log_error("There were no valid user or no valid group\n"); + /* now we can free the memory copy of input text */ + /* and rely on internal representation */ + while (firstitem) { + item = firstitem->next; + free(firstitem); + firstitem = item; + } + } else { + /* no mapping file, try a default mapping */ + if (allowdef) { + if (!ntfs_do_default_mapping(scx, + 0, 0, (const SID*)&defmap)) + ntfs_log_info("Using default user mapping\n"); + } + } + return (!scx->mapping[MAPUSERS] || link_group_members(scx)); +} + +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + +/* + * Get the ntfs attribute into an extended attribute + * The attribute is returned according to cpu endianness + */ + +int ntfs_get_ntfs_attrib(ntfs_inode *ni, char *value, size_t size) +{ + u32 attrib; + size_t outsize; + + outsize = 0; /* default to no data and no error */ + if (ni) { + attrib = le32_to_cpu(ni->flags); + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY); + else + attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY); + if (!attrib) + attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL); + outsize = sizeof(FILE_ATTR_FLAGS); + if (size >= outsize) { + if (value) + memcpy(value,&attrib,outsize); + else + errno = EINVAL; + } + } + return (outsize ? (int)outsize : -errno); +} + +/* + * Return the ntfs attribute into an extended attribute + * The attribute is expected according to cpu endianness + * + * Returns 0, or -1 if there is a problem + */ + +int ntfs_set_ntfs_attrib(ntfs_inode *ni, + const char *value, size_t size, int flags) +{ + u32 attrib; + le32 settable; + ATTR_FLAGS dirflags; + int res; + + res = -1; + if (ni && value && (size >= sizeof(FILE_ATTR_FLAGS))) { + if (!(flags & XATTR_CREATE)) { + /* copy to avoid alignment problems */ + memcpy(&attrib,value,sizeof(FILE_ATTR_FLAGS)); + settable = FILE_ATTR_SETTABLE; + res = 0; + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + /* + * Accept changing compression for a directory + * and set index root accordingly + */ + settable |= FILE_ATTR_COMPRESSED; + if ((ni->flags ^ cpu_to_le32(attrib)) + & FILE_ATTR_COMPRESSED) { + if (ni->flags & FILE_ATTR_COMPRESSED) + dirflags = const_cpu_to_le16(0); + else + dirflags = ATTR_IS_COMPRESSED; + res = ntfs_attr_set_flags(ni, + AT_INDEX_ROOT, + NTFS_INDEX_I30, 4, + dirflags, + ATTR_COMPRESSION_MASK); + } + } + if (!res) { + ni->flags = (ni->flags & ~settable) + | (cpu_to_le32(attrib) & settable); + NInoFileNameSetDirty(ni); + NInoSetDirty(ni); + } + } else + errno = EEXIST; + } else + errno = EINVAL; + return (res ? -1 : 0); +} + +#endif /* HAVE_SETXATTR */ + +/* + * Open $Secure once for all + * returns zero if it succeeds + * non-zero if it fails. This is not an error (on NTFS v1.x) + */ + + +int ntfs_open_secure(ntfs_volume *vol) +{ + ntfs_inode *ni; + int res; + + res = -1; + vol->secure_ni = (ntfs_inode*)NULL; + vol->secure_xsii = (ntfs_index_context*)NULL; + vol->secure_xsdh = (ntfs_index_context*)NULL; + if (vol->major_ver >= 3) { + /* make sure this is a genuine $Secure inode 9 */ + ni = ntfs_pathname_to_inode(vol, NULL, "$Secure"); + if (ni && (ni->mft_no == 9)) { + vol->secure_reentry = 0; + vol->secure_xsii = ntfs_index_ctx_get(ni, + sii_stream, 4); + vol->secure_xsdh = ntfs_index_ctx_get(ni, + sdh_stream, 4); + if (ni && vol->secure_xsii && vol->secure_xsdh) { + vol->secure_ni = ni; + res = 0; + } + } + } + return (res); +} + +/* + * Final cleaning + * Allocated memory is freed to facilitate the detection of memory leaks + */ + +void ntfs_close_secure(struct SECURITY_CONTEXT *scx) +{ + ntfs_volume *vol; + + vol = scx->vol; + if (vol->secure_ni) { + ntfs_index_ctx_put(vol->secure_xsii); + ntfs_index_ctx_put(vol->secure_xsdh); + ntfs_inode_close(vol->secure_ni); + + } + ntfs_free_mapping(scx->mapping); + free_caches(scx); +} + +/* + * API for direct access to security descriptors + * based on Win32 API + */ + + +/* + * Selective feeding of a security descriptor into user buffer + * + * Returns TRUE if successful + */ + +static BOOL feedsecurityattr(const char *attr, u32 selection, + char *buf, u32 buflen, u32 *psize) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + SECURITY_DESCRIPTOR_RELATIVE *pnhead; + const ACL *pdacl; + const ACL *psacl; + const SID *pusid; + const SID *pgsid; + unsigned int offdacl; + unsigned int offsacl; + unsigned int offowner; + unsigned int offgroup; + unsigned int daclsz; + unsigned int saclsz; + unsigned int usidsz; + unsigned int gsidsz; + unsigned int size; /* size of requested attributes */ + BOOL ok; + unsigned int pos; + unsigned int avail; + le16 control; + + avail = 0; + control = SE_SELF_RELATIVE; + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)attr; + size = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + + /* locate DACL if requested and available */ + if (phead->dacl && (selection & DACL_SECURITY_INFORMATION)) { + offdacl = le32_to_cpu(phead->dacl); + pdacl = (const ACL*)&attr[offdacl]; + daclsz = le16_to_cpu(pdacl->size); + size += daclsz; + avail |= DACL_SECURITY_INFORMATION; + } else + offdacl = daclsz = 0; + + /* locate owner if requested and available */ + offowner = le32_to_cpu(phead->owner); + if (offowner && (selection & OWNER_SECURITY_INFORMATION)) { + /* find end of USID */ + pusid = (const SID*)&attr[offowner]; + usidsz = ntfs_sid_size(pusid); + size += usidsz; + avail |= OWNER_SECURITY_INFORMATION; + } else + offowner = usidsz = 0; + + /* locate group if requested and available */ + offgroup = le32_to_cpu(phead->group); + if (offgroup && (selection & GROUP_SECURITY_INFORMATION)) { + /* find end of GSID */ + pgsid = (const SID*)&attr[offgroup]; + gsidsz = ntfs_sid_size(pgsid); + size += gsidsz; + avail |= GROUP_SECURITY_INFORMATION; + } else + offgroup = gsidsz = 0; + + /* locate SACL if requested and available */ + if (phead->sacl && (selection & SACL_SECURITY_INFORMATION)) { + /* find end of SACL */ + offsacl = le32_to_cpu(phead->sacl); + psacl = (const ACL*)&attr[offsacl]; + saclsz = le16_to_cpu(psacl->size); + size += saclsz; + avail |= SACL_SECURITY_INFORMATION; + } else + offsacl = saclsz = 0; + + /* + * Check having enough size in destination buffer + * (required size is returned nevertheless so that + * the request can be reissued with adequate size) + */ + if (size > buflen) { + *psize = size; + errno = EINVAL; + ok = FALSE; + } else { + if (selection & OWNER_SECURITY_INFORMATION) + control |= phead->control & SE_OWNER_DEFAULTED; + if (selection & GROUP_SECURITY_INFORMATION) + control |= phead->control & SE_GROUP_DEFAULTED; + if (selection & DACL_SECURITY_INFORMATION) + control |= phead->control + & (SE_DACL_PRESENT + | SE_DACL_DEFAULTED + | SE_DACL_AUTO_INHERITED + | SE_DACL_PROTECTED); + if (selection & SACL_SECURITY_INFORMATION) + control |= phead->control + & (SE_SACL_PRESENT + | SE_SACL_DEFAULTED + | SE_SACL_AUTO_INHERITED + | SE_SACL_PROTECTED); + /* + * copy header and feed new flags, even if no detailed data + */ + memcpy(buf,attr,sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)buf; + pnhead->control = control; + pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + + /* copy DACL if requested and available */ + if (selection & avail & DACL_SECURITY_INFORMATION) { + pnhead->dacl = cpu_to_le32(pos); + memcpy(&buf[pos],&attr[offdacl],daclsz); + pos += daclsz; + } else + pnhead->dacl = const_cpu_to_le32(0); + + /* copy SACL if requested and available */ + if (selection & avail & SACL_SECURITY_INFORMATION) { + pnhead->sacl = cpu_to_le32(pos); + memcpy(&buf[pos],&attr[offsacl],saclsz); + pos += saclsz; + } else + pnhead->sacl = const_cpu_to_le32(0); + + /* copy owner if requested and available */ + if (selection & avail & OWNER_SECURITY_INFORMATION) { + pnhead->owner = cpu_to_le32(pos); + memcpy(&buf[pos],&attr[offowner],usidsz); + pos += usidsz; + } else + pnhead->owner = const_cpu_to_le32(0); + + /* copy group if requested and available */ + if (selection & avail & GROUP_SECURITY_INFORMATION) { + pnhead->group = cpu_to_le32(pos); + memcpy(&buf[pos],&attr[offgroup],gsidsz); + pos += gsidsz; + } else + pnhead->group = const_cpu_to_le32(0); + if (pos != size) + ntfs_log_error("Error in security descriptor size\n"); + *psize = size; + ok = TRUE; + } + + return (ok); +} + +/* + * Merge a new security descriptor into the old one + * and assign to designated file + * + * Returns TRUE if successful + */ + +static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, + const char *newattr, u32 selection, ntfs_inode *ni) +{ + const SECURITY_DESCRIPTOR_RELATIVE *oldhead; + const SECURITY_DESCRIPTOR_RELATIVE *newhead; + SECURITY_DESCRIPTOR_RELATIVE *targhead; + const ACL *pdacl; + const ACL *psacl; + const SID *powner; + const SID *pgroup; + int offdacl; + int offsacl; + int offowner; + int offgroup; + unsigned int size; + le16 control; + char *target; + int pos; + int oldattrsz; + int newattrsz; + BOOL ok; + + ok = FALSE; /* default return */ + oldhead = (const SECURITY_DESCRIPTOR_RELATIVE*)oldattr; + newhead = (const SECURITY_DESCRIPTOR_RELATIVE*)newattr; + oldattrsz = ntfs_attr_size(oldattr); + newattrsz = ntfs_attr_size(newattr); + target = (char*)ntfs_malloc(oldattrsz + newattrsz); + if (target) { + targhead = (SECURITY_DESCRIPTOR_RELATIVE*)target; + pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE); + control = SE_SELF_RELATIVE; + /* + * copy new DACL if selected + * or keep old DACL if any + */ + if ((selection & DACL_SECURITY_INFORMATION) ? + newhead->dacl : oldhead->dacl) { + if (selection & DACL_SECURITY_INFORMATION) { + offdacl = le32_to_cpu(newhead->dacl); + pdacl = (const ACL*)&newattr[offdacl]; + } else { + offdacl = le32_to_cpu(oldhead->dacl); + pdacl = (const ACL*)&oldattr[offdacl]; + } + size = le16_to_cpu(pdacl->size); + memcpy(&target[pos], pdacl, size); + targhead->dacl = cpu_to_le32(pos); + pos += size; + } else + targhead->dacl = const_cpu_to_le32(0); + if (selection & DACL_SECURITY_INFORMATION) { + control |= newhead->control + & (SE_DACL_PRESENT + | SE_DACL_DEFAULTED + | SE_DACL_PROTECTED); + if (newhead->control & SE_DACL_AUTO_INHERIT_REQ) + control |= SE_DACL_AUTO_INHERITED; + } else + control |= oldhead->control + & (SE_DACL_PRESENT + | SE_DACL_DEFAULTED + | SE_DACL_AUTO_INHERITED + | SE_DACL_PROTECTED); + /* + * copy new SACL if selected + * or keep old SACL if any + */ + if ((selection & SACL_SECURITY_INFORMATION) ? + newhead->sacl : oldhead->sacl) { + if (selection & SACL_SECURITY_INFORMATION) { + offsacl = le32_to_cpu(newhead->sacl); + psacl = (const ACL*)&newattr[offsacl]; + } else { + offsacl = le32_to_cpu(oldhead->sacl); + psacl = (const ACL*)&oldattr[offsacl]; + } + size = le16_to_cpu(psacl->size); + memcpy(&target[pos], psacl, size); + targhead->sacl = cpu_to_le32(pos); + pos += size; + } else + targhead->sacl = const_cpu_to_le32(0); + if (selection & SACL_SECURITY_INFORMATION) { + control |= newhead->control + & (SE_SACL_PRESENT + | SE_SACL_DEFAULTED + | SE_SACL_PROTECTED); + if (newhead->control & SE_SACL_AUTO_INHERIT_REQ) + control |= SE_SACL_AUTO_INHERITED; + } else + control |= oldhead->control + & (SE_SACL_PRESENT + | SE_SACL_DEFAULTED + | SE_SACL_AUTO_INHERITED + | SE_SACL_PROTECTED); + /* + * copy new OWNER if selected + * or keep old OWNER if any + */ + if ((selection & OWNER_SECURITY_INFORMATION) ? + newhead->owner : oldhead->owner) { + if (selection & OWNER_SECURITY_INFORMATION) { + offowner = le32_to_cpu(newhead->owner); + powner = (const SID*)&newattr[offowner]; + } else { + offowner = le32_to_cpu(oldhead->owner); + powner = (const SID*)&oldattr[offowner]; + } + size = ntfs_sid_size(powner); + memcpy(&target[pos], powner, size); + targhead->owner = cpu_to_le32(pos); + pos += size; + } else + targhead->owner = const_cpu_to_le32(0); + if (selection & OWNER_SECURITY_INFORMATION) + control |= newhead->control & SE_OWNER_DEFAULTED; + else + control |= oldhead->control & SE_OWNER_DEFAULTED; + /* + * copy new GROUP if selected + * or keep old GROUP if any + */ + if ((selection & GROUP_SECURITY_INFORMATION) ? + newhead->group : oldhead->group) { + if (selection & GROUP_SECURITY_INFORMATION) { + offgroup = le32_to_cpu(newhead->group); + pgroup = (const SID*)&newattr[offgroup]; + control |= newhead->control + & SE_GROUP_DEFAULTED; + } else { + offgroup = le32_to_cpu(oldhead->group); + pgroup = (const SID*)&oldattr[offgroup]; + control |= oldhead->control + & SE_GROUP_DEFAULTED; + } + size = ntfs_sid_size(pgroup); + memcpy(&target[pos], pgroup, size); + targhead->group = cpu_to_le32(pos); + pos += size; + } else + targhead->group = const_cpu_to_le32(0); + if (selection & GROUP_SECURITY_INFORMATION) + control |= newhead->control & SE_GROUP_DEFAULTED; + else + control |= oldhead->control & SE_GROUP_DEFAULTED; + targhead->revision = SECURITY_DESCRIPTOR_REVISION; + targhead->alignment = 0; + targhead->control = control; + ok = !update_secur_descr(vol, target, ni); + free(target); + } + return (ok); +} + +/* + * Return the security descriptor of a file + * This is intended to be similar to GetFileSecurity() from Win32 + * in order to facilitate the development of portable tools + * + * returns zero if unsuccessful (following Win32 conventions) + * -1 if no securid + * the securid if any + * + * The Win32 API is : + * + * BOOL WINAPI GetFileSecurity( + * __in LPCTSTR lpFileName, + * __in SECURITY_INFORMATION RequestedInformation, + * __out_opt PSECURITY_DESCRIPTOR pSecurityDescriptor, + * __in DWORD nLength, + * __out LPDWORD lpnLengthNeeded + * ); + * + */ + +int ntfs_get_file_security(struct SECURITY_API *scapi, + const char *path, u32 selection, + char *buf, u32 buflen, u32 *psize) +{ + ntfs_inode *ni; + char *attr; + int res; + + res = 0; /* default return */ + if (scapi && (scapi->magic == MAGIC_API)) { + ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); + if (ni) { + attr = getsecurityattr(scapi->security.vol, ni); + if (attr) { + if (feedsecurityattr(attr,selection, + buf,buflen,psize)) { + if (test_nino_flag(ni, v3_Extensions) + && ni->security_id) + res = le32_to_cpu( + ni->security_id); + else + res = -1; + } + free(attr); + } + ntfs_inode_close(ni); + } else + errno = ENOENT; + if (!res) *psize = 0; + } else + errno = EINVAL; /* do not clear *psize */ + return (res); +} + + +/* + * Set the security descriptor of a file or directory + * This is intended to be similar to SetFileSecurity() from Win32 + * in order to facilitate the development of portable tools + * + * returns zero if unsuccessful (following Win32 conventions) + * -1 if no securid + * the securid if any + * + * The Win32 API is : + * + * BOOL WINAPI SetFileSecurity( + * __in LPCTSTR lpFileName, + * __in SECURITY_INFORMATION SecurityInformation, + * __in PSECURITY_DESCRIPTOR pSecurityDescriptor + * ); + */ + +int ntfs_set_file_security(struct SECURITY_API *scapi, + const char *path, u32 selection, const char *attr) +{ + const SECURITY_DESCRIPTOR_RELATIVE *phead; + ntfs_inode *ni; + int attrsz; + BOOL missing; + char *oldattr; + int res; + + res = 0; /* default return */ + if (scapi && (scapi->magic == MAGIC_API) && attr) { + phead = (const SECURITY_DESCRIPTOR_RELATIVE*)attr; + attrsz = ntfs_attr_size(attr); + /* if selected, owner and group must be present or defaulted */ + missing = ((selection & OWNER_SECURITY_INFORMATION) + && !phead->owner + && !(phead->control & SE_OWNER_DEFAULTED)) + || ((selection & GROUP_SECURITY_INFORMATION) + && !phead->group + && !(phead->control & SE_GROUP_DEFAULTED)); + if (!missing + && (phead->control & SE_SELF_RELATIVE) + && ntfs_valid_descr(attr, attrsz)) { + ni = ntfs_pathname_to_inode(scapi->security.vol, + NULL, path); + if (ni) { + oldattr = getsecurityattr(scapi->security.vol, + ni); + if (oldattr) { + if (mergesecurityattr( + scapi->security.vol, + oldattr, attr, + selection, ni)) { + if (test_nino_flag(ni, + v3_Extensions)) + res = le32_to_cpu( + ni->security_id); + else + res = -1; + } + free(oldattr); + } + ntfs_inode_close(ni); + } + } else + errno = EINVAL; + } else + errno = EINVAL; + return (res); +} + + +/* + * Return the attributes of a file + * This is intended to be similar to GetFileAttributes() from Win32 + * in order to facilitate the development of portable tools + * + * returns -1 if unsuccessful (Win32 : INVALID_FILE_ATTRIBUTES) + * + * The Win32 API is : + * + * DWORD WINAPI GetFileAttributes( + * __in LPCTSTR lpFileName + * ); + */ + +int ntfs_get_file_attributes(struct SECURITY_API *scapi, const char *path) +{ + ntfs_inode *ni; + s32 attrib; + + attrib = -1; /* default return */ + if (scapi && (scapi->magic == MAGIC_API) && path) { + ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); + if (ni) { + attrib = le32_to_cpu(ni->flags); + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY); + else + attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY); + if (!attrib) + attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL); + + ntfs_inode_close(ni); + } else + errno = ENOENT; + } else + errno = EINVAL; /* do not clear *psize */ + return (attrib); +} + + +/* + * Set attributes to a file or directory + * This is intended to be similar to SetFileAttributes() from Win32 + * in order to facilitate the development of portable tools + * + * Only a few flags can be set (same list as Win32) + * + * returns zero if unsuccessful (following Win32 conventions) + * nonzero if successful + * + * The Win32 API is : + * + * BOOL WINAPI SetFileAttributes( + * __in LPCTSTR lpFileName, + * __in DWORD dwFileAttributes + * ); + */ + +BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi, + const char *path, s32 attrib) +{ + ntfs_inode *ni; + le32 settable; + ATTR_FLAGS dirflags; + int res; + + res = 0; /* default return */ + if (scapi && (scapi->magic == MAGIC_API) && path) { + ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); + if (ni) { + settable = FILE_ATTR_SETTABLE; + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + /* + * Accept changing compression for a directory + * and set index root accordingly + */ + settable |= FILE_ATTR_COMPRESSED; + if ((ni->flags ^ cpu_to_le32(attrib)) + & FILE_ATTR_COMPRESSED) { + if (ni->flags & FILE_ATTR_COMPRESSED) + dirflags = const_cpu_to_le16(0); + else + dirflags = ATTR_IS_COMPRESSED; + res = ntfs_attr_set_flags(ni, + AT_INDEX_ROOT, + NTFS_INDEX_I30, 4, + dirflags, + ATTR_COMPRESSION_MASK); + } + } + if (!res) { + ni->flags = (ni->flags & ~settable) + | (cpu_to_le32(attrib) & settable); + NInoSetDirty(ni); + } + if (!ntfs_inode_close(ni)) + res = -1; + } else + errno = ENOENT; + } + return (res); +} + + +BOOL ntfs_read_directory(struct SECURITY_API *scapi, + const char *path, ntfs_filldir_t callback, void *context) +{ + ntfs_inode *ni; + BOOL ok; + s64 pos; + + ok = FALSE; /* default return */ + if (scapi && (scapi->magic == MAGIC_API) && callback) { + ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); + if (ni) { + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + pos = 0; + ntfs_readdir(ni,&pos,context,callback); + ok = !ntfs_inode_close(ni); + } else { + ntfs_inode_close(ni); + errno = ENOTDIR; + } + } else + errno = ENOENT; + } else + errno = EINVAL; /* do not clear *psize */ + return (ok); +} + +/* + * read $SDS (for auditing security data) + * + * Returns the number or read bytes, or -1 if there is an error + */ + +int ntfs_read_sds(struct SECURITY_API *scapi, + char *buf, u32 size, u32 offset) +{ + int got; + + got = -1; /* default return */ + if (scapi && (scapi->magic == MAGIC_API)) { + if (scapi->security.vol->secure_ni) + got = ntfs_local_read(scapi->security.vol->secure_ni, + STREAM_SDS, 4, buf, size, offset); + else + errno = EOPNOTSUPP; + } else + errno = EINVAL; + return (got); +} + +/* + * read $SII (for auditing security data) + * + * Returns next entry, or NULL if there is an error + */ + +INDEX_ENTRY *ntfs_read_sii(struct SECURITY_API *scapi, + INDEX_ENTRY *entry) +{ + SII_INDEX_KEY key; + INDEX_ENTRY *ret; + BOOL found; + ntfs_index_context *xsii; + + ret = (INDEX_ENTRY*)NULL; /* default return */ + if (scapi && (scapi->magic == MAGIC_API)) { + xsii = scapi->security.vol->secure_xsii; + if (xsii) { + if (!entry) { + key.security_id = const_cpu_to_le32(0); + found = !ntfs_index_lookup((char*)&key, + sizeof(SII_INDEX_KEY), xsii); + /* not supposed to find */ + if (!found && (errno == ENOENT)) + ret = xsii->entry; + } else + ret = ntfs_index_next(entry,xsii); + if (!ret) + errno = ENODATA; + } else + errno = EOPNOTSUPP; + } else + errno = EINVAL; + return (ret); +} + +/* + * read $SDH (for auditing security data) + * + * Returns next entry, or NULL if there is an error + */ + +INDEX_ENTRY *ntfs_read_sdh(struct SECURITY_API *scapi, + INDEX_ENTRY *entry) +{ + SDH_INDEX_KEY key; + INDEX_ENTRY *ret; + BOOL found; + ntfs_index_context *xsdh; + + ret = (INDEX_ENTRY*)NULL; /* default return */ + if (scapi && (scapi->magic == MAGIC_API)) { + xsdh = scapi->security.vol->secure_xsdh; + if (xsdh) { + if (!entry) { + key.hash = const_cpu_to_le32(0); + key.security_id = const_cpu_to_le32(0); + found = !ntfs_index_lookup((char*)&key, + sizeof(SDH_INDEX_KEY), xsdh); + /* not supposed to find */ + if (!found && (errno == ENOENT)) + ret = xsdh->entry; + } else + ret = ntfs_index_next(entry,xsdh); + if (!ret) + errno = ENODATA; + } else errno = ENOTSUP; + } else + errno = EINVAL; + return (ret); +} + +/* + * Get the mapped user SID + * A buffer of 40 bytes has to be supplied + * + * returns the size of the SID, or zero and errno set if not found + */ + +int ntfs_get_usid(struct SECURITY_API *scapi, uid_t uid, char *buf) +{ + const SID *usid; + BIGSID defusid; + int size; + + size = 0; + if (scapi && (scapi->magic == MAGIC_API)) { + usid = ntfs_find_usid(scapi->security.mapping[MAPUSERS], uid, (SID*)&defusid); + if (usid) { + size = ntfs_sid_size(usid); + memcpy(buf,usid,size); + } else + errno = ENODATA; + } else + errno = EINVAL; + return (size); +} + +/* + * Get the mapped group SID + * A buffer of 40 bytes has to be supplied + * + * returns the size of the SID, or zero and errno set if not found + */ + +int ntfs_get_gsid(struct SECURITY_API *scapi, gid_t gid, char *buf) +{ + const SID *gsid; + BIGSID defgsid; + int size; + + size = 0; + if (scapi && (scapi->magic == MAGIC_API)) { + gsid = ntfs_find_gsid(scapi->security.mapping[MAPGROUPS], gid, (SID*)&defgsid); + if (gsid) { + size = ntfs_sid_size(gsid); + memcpy(buf,gsid,size); + } else + errno = ENODATA; + } else + errno = EINVAL; + return (size); +} + +/* + * Get the user mapped to a SID + * + * returns the uid, or -1 if not found + */ + +int ntfs_get_user(struct SECURITY_API *scapi, const SID *usid) +{ + int uid; + + uid = -1; + if (scapi && (scapi->magic == MAGIC_API) && ntfs_valid_sid(usid)) { + if (ntfs_same_sid(usid,adminsid)) + uid = 0; + else { + uid = ntfs_find_user(scapi->security.mapping[MAPUSERS], usid); + if (!uid) { + uid = -1; + errno = ENODATA; + } + } + } else + errno = EINVAL; + return (uid); +} + +/* + * Get the group mapped to a SID + * + * returns the uid, or -1 if not found + */ + +int ntfs_get_group(struct SECURITY_API *scapi, const SID *gsid) +{ + int gid; + + gid = -1; + if (scapi && (scapi->magic == MAGIC_API) && ntfs_valid_sid(gsid)) { + if (ntfs_same_sid(gsid,adminsid)) + gid = 0; + else { + gid = ntfs_find_group(scapi->security.mapping[MAPGROUPS], gsid); + if (!gid) { + gid = -1; + errno = ENODATA; + } + } + } else + errno = EINVAL; + return (gid); +} + +/* + * Initializations before calling ntfs_get_file_security() + * ntfs_set_file_security() and ntfs_read_directory() + * + * Only allowed for root + * + * Returns an (obscured) struct SECURITY_API* needed for further calls + * NULL if not root (EPERM) or device is mounted (EBUSY) + */ + +struct SECURITY_API *ntfs_initialize_file_security(const char *device, + int flags) +{ + ntfs_volume *vol; + unsigned long mntflag; + int mnt; + struct SECURITY_API *scapi; + struct SECURITY_CONTEXT *scx; + + scapi = (struct SECURITY_API*)NULL; + mnt = ntfs_check_if_mounted(device, &mntflag); + if (!mnt && !(mntflag & NTFS_MF_MOUNTED) && !getuid()) { + vol = ntfs_mount(device, flags); + if (vol) { + scapi = (struct SECURITY_API*) + ntfs_malloc(sizeof(struct SECURITY_API)); + if (!ntfs_volume_get_free_space(vol) + && scapi) { + scapi->magic = MAGIC_API; + scapi->seccache = (struct PERMISSIONS_CACHE*)NULL; + scx = &scapi->security; + scx->vol = vol; + scx->uid = getuid(); + scx->gid = getgid(); + scx->pseccache = &scapi->seccache; + scx->vol->secure_flags = 0; + /* accept no mapping and no $Secure */ + ntfs_build_mapping(scx,(const char*)NULL,TRUE); + ntfs_open_secure(vol); + } else { + if (scapi) + free(scapi); + else + errno = ENOMEM; + mnt = ntfs_umount(vol,FALSE); + scapi = (struct SECURITY_API*)NULL; + } + } + } else + if (getuid()) + errno = EPERM; + else + errno = EBUSY; + return (scapi); +} + +/* + * Leaving after ntfs_initialize_file_security() + * + * Returns FALSE if FAILED + */ + +BOOL ntfs_leave_file_security(struct SECURITY_API *scapi) +{ + int ok; + ntfs_volume *vol; + + ok = FALSE; + if (scapi && (scapi->magic == MAGIC_API) && scapi->security.vol) { + vol = scapi->security.vol; + ntfs_close_secure(&scapi->security); + free(scapi); + if (!ntfs_umount(vol, 0)) + ok = TRUE; + } + return (ok); +} + diff --git a/libcustomntfs/security.h b/libcustomntfs/security.h new file mode 100644 index 00000000..83d7c0e1 --- /dev/null +++ b/libcustomntfs/security.h @@ -0,0 +1,357 @@ +/* + * security.h - Exports for handling security/ACLs in NTFS. + * Originated from the Linux-NTFS project. + * + * Copyright (c) 2004 Anton Altaparmakov + * Copyright (c) 2005-2006 Szabolcs Szakacsits + * Copyright (c) 2007-2008 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_SECURITY_H +#define _NTFS_SECURITY_H + +#include "types.h" +#include "layout.h" +#include "inode.h" +#include "dir.h" + +#ifndef POSIXACLS +#define POSIXACLS 0 +#endif + +typedef u16 be16; +typedef u32 be32; + +#if __BYTE_ORDER == __LITTLE_ENDIAN +#define const_cpu_to_be16(x) ((((x) & 255L) << 8) + (((x) >> 8) & 255L)) +#define const_cpu_to_be32(x) ((((x) & 255L) << 24) + (((x) & 0xff00L) << 8) \ + + (((x) >> 8) & 0xff00L) + (((x) >> 24) & 255L)) +#else +#define const_cpu_to_be16(x) (x) +#define const_cpu_to_be32(x) (x) +#endif + +/* + * item in the mapping list + */ + +struct MAPPING { + struct MAPPING *next; + int xid; /* linux id : uid or gid */ + SID *sid; /* Windows id : usid or gsid */ + int grcnt; /* group count (for users only) */ + gid_t *groups; /* groups which the user is member of */ +}; + +/* + * Entry in the permissions cache + * Note : this cache is not organized as a generic cache + */ + +struct CACHED_PERMISSIONS { + uid_t uid; + gid_t gid; + le32 inh_fileid; + le32 inh_dirid; +#if POSIXACLS + struct POSIX_SECURITY *pxdesc; + unsigned int pxdescsize:16; +#endif + unsigned int mode:12; + unsigned int valid:1; +} ; + +/* + * Entry in the permissions cache for directories with no security_id + */ + +struct CACHED_PERMISSIONS_LEGACY { + struct CACHED_PERMISSIONS_LEGACY *next; + struct CACHED_PERMISSIONS_LEGACY *previous; + void *variable; + size_t varsize; + /* above fields must match "struct CACHED_GENERIC" */ + u64 mft_no; + struct CACHED_PERMISSIONS perm; +} ; + +/* + * Entry in the securid cache + */ + +struct CACHED_SECURID { + struct CACHED_SECURID *next; + struct CACHED_SECURID *previous; + void *variable; + size_t varsize; + /* above fields must match "struct CACHED_GENERIC" */ + uid_t uid; + gid_t gid; + unsigned int dmode; + le32 securid; +} ; + +/* + * Header of the security cache + * (has no cache structure by itself) + */ + +struct CACHED_PERMISSIONS_HEADER { + unsigned int last; + /* statistics for permissions */ + unsigned long p_writes; + unsigned long p_reads; + unsigned long p_hits; +} ; + +/* + * The whole permissions cache + */ + +struct PERMISSIONS_CACHE { + struct CACHED_PERMISSIONS_HEADER head; + struct CACHED_PERMISSIONS *cachetable[1]; /* array of variable size */ +} ; + +/* + * Security flags values + */ + +enum { + SECURITY_DEFAULT, /* rely on fuse for permissions checking */ + SECURITY_RAW, /* force same ownership/permissions on files */ + SECURITY_ADDSECURIDS, /* upgrade old security descriptors */ + SECURITY_STATICGRPS, /* use static groups for access control */ + SECURITY_WANTED /* a security related option was present */ +} ; + +/* + * Security context, needed by most security functions + */ + +enum { MAPUSERS, MAPGROUPS, MAPCOUNT } ; + +struct SECURITY_CONTEXT { + ntfs_volume *vol; + struct MAPPING *mapping[MAPCOUNT]; + struct PERMISSIONS_CACHE **pseccache; + uid_t uid; /* uid of user requesting (not the mounter) */ + gid_t gid; /* gid of user requesting (not the mounter) */ + pid_t tid; /* thread id of thread requesting */ + mode_t umask; /* umask of requesting thread */ + } ; + +#if POSIXACLS + +/* + * Posix ACL structures + */ + +struct POSIX_ACE { + u16 tag; + u16 perms; + s32 id; +} __attribute__((__packed__)); + +struct POSIX_ACL { + u8 version; + u8 flags; + u16 filler; + struct POSIX_ACE ace[0]; +} __attribute__((__packed__)); + +struct POSIX_SECURITY { + mode_t mode; + int acccnt; + int defcnt; + int firstdef; + u16 tagsset; + struct POSIX_ACL acl; +} ; + +/* + * Posix tags, cpu-endian 16 bits + */ + +enum { + POSIX_ACL_USER_OBJ = 1, + POSIX_ACL_USER = 2, + POSIX_ACL_GROUP_OBJ = 4, + POSIX_ACL_GROUP = 8, + POSIX_ACL_MASK = 16, + POSIX_ACL_OTHER = 32, + POSIX_ACL_SPECIAL = 64 /* internal use only */ +} ; + +#define POSIX_ACL_EXTENSIONS (POSIX_ACL_USER | POSIX_ACL_GROUP | POSIX_ACL_MASK) + +/* + * Posix permissions, cpu-endian 16 bits + */ + +enum { + POSIX_PERM_X = 1, + POSIX_PERM_W = 2, + POSIX_PERM_R = 4, + POSIX_PERM_DENIAL = 64 /* internal use only */ +} ; + +#define POSIX_VERSION 2 + +#endif + +extern BOOL ntfs_guid_is_zero(const GUID *guid); +extern char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str); + +/** + * ntfs_sid_is_valid - determine if a SID is valid + * @sid: SID for which to determine if it is valid + * + * Determine if the SID pointed to by @sid is valid. + * + * Return TRUE if it is valid and FALSE otherwise. + */ +static __inline__ BOOL ntfs_sid_is_valid(const SID *sid) +{ + if (!sid || sid->revision != SID_REVISION || + sid->sub_authority_count > SID_MAX_SUB_AUTHORITIES) + return FALSE; + return TRUE; +} + +extern int ntfs_sid_to_mbs_size(const SID *sid); +extern char *ntfs_sid_to_mbs(const SID *sid, char *sid_str, + size_t sid_str_size); +extern void ntfs_generate_guid(GUID *guid); +extern int ntfs_sd_add_everyone(ntfs_inode *ni); + +extern le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, + const u32 len); + +int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path, + BOOL allowdef); +int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, struct stat*); +int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode); +BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni); +int ntfs_allowed_access(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, int accesstype); +BOOL old_ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, + const char *path, int accesstype); + +#if POSIXACLS +le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, + uid_t uid, gid_t gid, ntfs_inode *dir_ni, + mode_t mode, BOOL isdir); +#else +le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, + uid_t uid, gid_t gid, mode_t mode, BOOL isdir); +#endif +int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + uid_t uid, gid_t gid); +int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode); +#if POSIXACLS +int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, + mode_t mode, struct POSIX_SECURITY *pxdesc); +#else +int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode); +#endif +le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx, + ntfs_inode *dir_ni, BOOL fordir); +int ntfs_open_secure(ntfs_volume *vol); +void ntfs_close_secure(struct SECURITY_CONTEXT *scx); + +#if POSIXACLS + +int ntfs_set_inherited_posix(struct SECURITY_CONTEXT *scx, + ntfs_inode *ni, uid_t uid, gid_t gid, + ntfs_inode *dir_ni, mode_t mode); +int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *name, char *value, size_t size); +int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *name, const char *value, size_t size, + int flags); +int ntfs_remove_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *name); +#endif + +int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + char *value, size_t size); +int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, + const char *value, size_t size, int flags); + +int ntfs_get_ntfs_attrib(ntfs_inode *ni, char *value, size_t size); +int ntfs_set_ntfs_attrib(ntfs_inode *ni, + const char *value, size_t size, int flags); + + +/* + * Security API for direct access to security descriptors + * based on Win32 API + */ + +#define MAGIC_API 0x09042009 + +struct SECURITY_API { + u32 magic; + struct SECURITY_CONTEXT security; + struct PERMISSIONS_CACHE *seccache; +} ; + +/* + * The following constants are used in interfacing external programs. + * They are not to be stored on disk and must be defined in their + * native cpu representation. + * When disk representation (le) is needed, use SE_DACL_PRESENT, etc. + */ +enum { OWNER_SECURITY_INFORMATION = 1, + GROUP_SECURITY_INFORMATION = 2, + DACL_SECURITY_INFORMATION = 4, + SACL_SECURITY_INFORMATION = 8 +} ; + +int ntfs_get_file_security(struct SECURITY_API *scapi, + const char *path, u32 selection, + char *buf, u32 buflen, u32 *psize); +int ntfs_set_file_security(struct SECURITY_API *scapi, + const char *path, u32 selection, const char *attr); +int ntfs_get_file_attributes(struct SECURITY_API *scapi, + const char *path); +BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi, + const char *path, s32 attrib); +BOOL ntfs_read_directory(struct SECURITY_API *scapi, + const char *path, ntfs_filldir_t callback, void *context); +int ntfs_read_sds(struct SECURITY_API *scapi, + char *buf, u32 size, u32 offset); +INDEX_ENTRY *ntfs_read_sii(struct SECURITY_API *scapi, + INDEX_ENTRY *entry); +INDEX_ENTRY *ntfs_read_sdh(struct SECURITY_API *scapi, + INDEX_ENTRY *entry); +struct SECURITY_API *ntfs_initialize_file_security(const char *device, + int flags); +BOOL ntfs_leave_file_security(struct SECURITY_API *scx); + +int ntfs_get_usid(struct SECURITY_API *scapi, uid_t uid, char *buf); +int ntfs_get_gsid(struct SECURITY_API *scapi, gid_t gid, char *buf); +int ntfs_get_user(struct SECURITY_API *scapi, const SID *usid); +int ntfs_get_group(struct SECURITY_API *scapi, const SID *gsid); + +#endif /* defined _NTFS_SECURITY_H */ diff --git a/libcustomntfs/support.h b/libcustomntfs/support.h new file mode 100644 index 00000000..6af4761e --- /dev/null +++ b/libcustomntfs/support.h @@ -0,0 +1,85 @@ +/* + * support.h - Useful definitions and macros. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_SUPPORT_H +#define _NTFS_SUPPORT_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDDEF_H +#include +#endif + +/* + * Our mailing list. Use this define to prevent typos in email address. + */ +#define NTFS_DEV_LIST "ntfs-3g-devel@lists.sf.net" + +/* + * Generic macro to convert pointers to values for comparison purposes. + */ +#ifndef p2n +#define p2n(p) ((ptrdiff_t)((ptrdiff_t*)(p))) +#endif + +/* + * The classic min and max macros. + */ +#ifndef min +#define min(a,b) ((a) <= (b) ? (a) : (b)) +#endif + +#ifndef max +#define max(a,b) ((a) >= (b) ? (a) : (b)) +#endif + +/* + * Useful macro for determining the offset of a struct member. + */ +#ifndef offsetof +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +#endif + +/* + * Simple bit operation macros. NOTE: These are NOT atomic. + */ +#define test_bit(bit, var) ((var) & (1 << (bit))) +#define set_bit(bit, var) (var) |= 1 << (bit) +#define clear_bit(bit, var) (var) &= ~(1 << (bit)) + +#define test_and_set_bit(bit, var) \ +({ \ + const BOOL old_state = test_bit(bit, var); \ + set_bit(bit, var); \ + old_state; \ +}) + +#define test_and_clear_bit(bit, var) \ +({ \ + const BOOL old_state = test_bit(bit, var); \ + clear_bit(bit, var); \ + old_state; \ +}) + +#endif /* defined _NTFS_SUPPORT_H */ + diff --git a/libcustomntfs/types.h b/libcustomntfs/types.h new file mode 100644 index 00000000..3fafe8a7 --- /dev/null +++ b/libcustomntfs/types.h @@ -0,0 +1,133 @@ +/* + * types.h - Misc type definitions not related to on-disk structure. + * Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_TYPES_H +#define _NTFS_TYPES_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if HAVE_STDINT_H || !HAVE_CONFIG_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef GEKKO +#include +#include "compat.h" +#else /* GEKKO */ + +typedef uint8_t u8; /* Unsigned types of an exact size */ +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef int8_t s8; /* Signed types of an exact size */ +typedef int16_t s16; +typedef int32_t s32; +typedef int64_t s64; + +#endif /* GEKKO */ + +typedef u16 le16; +typedef u32 le32; +typedef u64 le64; + +/* + * Declare sle{16,32,64} to be unsigned because we do not want sign extension + * on BE architectures. + */ +typedef u16 sle16; +typedef u32 sle32; +typedef u64 sle64; + +typedef u16 ntfschar; /* 2-byte Unicode character type. */ +#define UCHAR_T_SIZE_BITS 1 + +/* + * Clusters are signed 64-bit values on NTFS volumes. We define two types, LCN + * and VCN, to allow for type checking and better code readability. + */ +typedef s64 VCN; +typedef sle64 leVCN; +typedef s64 LCN; +typedef sle64 leLCN; + +/* + * The NTFS journal $LogFile uses log sequence numbers which are signed 64-bit + * values. We define our own type LSN, to allow for type checking and better + * code readability. + */ +typedef s64 LSN; +typedef sle64 leLSN; + +/* + * Cygwin has a collision between our BOOL and 's + * As long as this file will be included after were fine. + */ +#ifndef GEKKO +#ifndef _WINDEF_H +/** + * enum BOOL - These are just to make the code more readable... + */ +typedef enum { +#ifndef FALSE + FALSE = 0, +#endif +#ifndef NO + NO = 0, +#endif +#ifndef ZERO + ZERO = 0, +#endif +#ifndef TRUE + TRUE = 1, +#endif +#ifndef YES + YES = 1, +#endif +#ifndef ONE + ONE = 1, +#endif +} BOOL; +#endif /* defined _WINDEF_H */ +#endif /* defined GECKO */ + +/** + * enum IGNORE_CASE_BOOL - + */ +typedef enum { + CASE_SENSITIVE = 0, + IGNORE_CASE = 1, +} IGNORE_CASE_BOOL; + +#define STATUS_OK (0) +#define STATUS_ERROR (-1) +#define STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT (-2) +#define STATUS_KEEP_SEARCHING (-3) +#define STATUS_NOT_FOUND (-4) + +#endif /* defined _NTFS_TYPES_H */ + diff --git a/libcustomntfs/unistr.c b/libcustomntfs/unistr.c new file mode 100644 index 00000000..eb72f0ff --- /dev/null +++ b/libcustomntfs/unistr.c @@ -0,0 +1,1438 @@ +/** + * unistr.c - Unicode string handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2002-2009 Szabolcs Szakacsits + * Copyright (c) 2008-2009 Jean-Pierre Andre + * Copyright (c) 2008 Bernhard Kaindl + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_WCHAR_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LOCALE_H +#include +#endif + +#if defined(__APPLE__) || defined(__DARWIN__) +#ifdef ENABLE_NFCONV +#include +#endif /* ENABLE_NFCONV */ +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + +#include "compat.h" +#include "attrib.h" +#include "types.h" +#include "unistr.h" +#include "debug.h" +#include "logging.h" +#include "misc.h" + +#define NOREVBOM 0 /* JPA rejecting U+FFFE and U+FFFF, open to debate */ + +/* + * IMPORTANT + * ========= + * + * All these routines assume that the Unicode characters are in little endian + * encoding inside the strings!!! + */ + +static int use_utf8 = 1; /* use UTF-8 encoding for file names */ + +#if defined(__APPLE__) || defined(__DARWIN__) +#ifdef ENABLE_NFCONV +/** + * This variable controls whether or not automatic normalization form conversion + * should be performed when translating NTFS unicode file names to UTF-8. + * Defaults to on, but can be controlled from the outside using the function + * int ntfs_macosx_normalize_filenames(int normalize); + */ +static int nfconvert_utf8 = 1; +#endif /* ENABLE_NFCONV */ +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + +/* + * This is used by the name collation functions to quickly determine what + * characters are (in)valid. + */ +#if 0 +static const u8 legal_ansi_char_array[0x40] = { + 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + + 0x17, 0x07, 0x18, 0x17, 0x17, 0x17, 0x17, 0x17, + 0x17, 0x17, 0x18, 0x16, 0x16, 0x17, 0x07, 0x00, + + 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, + 0x17, 0x17, 0x04, 0x16, 0x18, 0x16, 0x18, 0x18, +}; +#endif + +/** + * ntfs_names_are_equal - compare two Unicode names for equality + * @s1: name to compare to @s2 + * @s1_len: length in Unicode characters of @s1 + * @s2: name to compare to @s1 + * @s2_len: length in Unicode characters of @s2 + * @ic: ignore case bool + * @upcase: upcase table (only if @ic == IGNORE_CASE) + * @upcase_size: length in Unicode characters of @upcase (if present) + * + * Compare the names @s1 and @s2 and return TRUE (1) if the names are + * identical, or FALSE (0) if they are not identical. If @ic is IGNORE_CASE, + * the @upcase table is used to perform a case insensitive comparison. + */ +BOOL ntfs_names_are_equal(const ntfschar *s1, size_t s1_len, + const ntfschar *s2, size_t s2_len, + const IGNORE_CASE_BOOL ic, + const ntfschar *upcase, const u32 upcase_size) +{ + if (s1_len != s2_len) + return FALSE; + if (!s1_len) + return TRUE; + if (ic == CASE_SENSITIVE) + return ntfs_ucsncmp(s1, s2, s1_len) ? FALSE: TRUE; + return ntfs_ucsncasecmp(s1, s2, s1_len, upcase, upcase_size) ? FALSE: + TRUE; +} + +/* + * ntfs_names_full_collate() fully collate two Unicode names + * + * @name1: first Unicode name to compare + * @name1_len: length of first Unicode name to compare + * @name2: second Unicode name to compare + * @name2_len: length of second Unicode name to compare + * @ic: either CASE_SENSITIVE or IGNORE_CASE + * @upcase: upcase table (ignored if @ic is CASE_SENSITIVE) + * @upcase_len: upcase table size (ignored if @ic is CASE_SENSITIVE) + * + * -1 if the first name collates before the second one, + * 0 if the names match, + * 1 if the second name collates before the first one, or + * + */ +int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len, + const ntfschar *name2, const u32 name2_len, + const IGNORE_CASE_BOOL ic, const ntfschar *upcase, + const u32 upcase_len) +{ + u32 cnt; + u16 c1, c2; + u16 u1, u2; + +#ifdef DEBUG + if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) { + ntfs_log_debug("ntfs_names_collate received NULL pointer!\n"); + exit(1); + } +#endif + cnt = min(name1_len, name2_len); + if (cnt > 0) { + if (ic == CASE_SENSITIVE) { + do { + c1 = le16_to_cpu(*name1); + name1++; + c2 = le16_to_cpu(*name2); + name2++; + } while (--cnt && (c1 == c2)); + u1 = c1; + u2 = c2; + if (u1 < upcase_len) + u1 = le16_to_cpu(upcase[u1]); + if (u2 < upcase_len) + u2 = le16_to_cpu(upcase[u2]); + if ((u1 == u2) && cnt) + do { + u1 = le16_to_cpu(*name1); + name1++; + u2 = le16_to_cpu(*name2); + name2++; + if (u1 < upcase_len) + u1 = le16_to_cpu(upcase[u1]); + if (u2 < upcase_len) + u2 = le16_to_cpu(upcase[u2]); + } while ((u1 == u2) && --cnt); + if (u1 < u2) + return -1; + if (u1 > u2) + return 1; + if (name1_len < name2_len) + return -1; + if (name1_len > name2_len) + return 1; + if (c1 < c2) + return -1; + if (c1 > c2) + return 1; + } else { + do { + u1 = c1 = le16_to_cpu(*name1); + name1++; + u2 = c2 = le16_to_cpu(*name2); + name2++; + if (u1 < upcase_len) + u1 = le16_to_cpu(upcase[u1]); + if (u2 < upcase_len) + u2 = le16_to_cpu(upcase[u2]); + } while ((u1 == u2) && --cnt); + if (u1 < u2) + return -1; + if (u1 > u2) + return 1; + if (name1_len < name2_len) + return -1; + if (name1_len > name2_len) + return 1; + } + } else { + if (name1_len < name2_len) + return -1; + if (name1_len > name2_len) + return 1; + } + return 0; +} + +/** + * ntfs_ucsncmp - compare two little endian Unicode strings + * @s1: first string + * @s2: second string + * @n: maximum unicode characters to compare + * + * Compare the first @n characters of the Unicode strings @s1 and @s2, + * The strings in little endian format and appropriate le16_to_cpu() + * conversion is performed on non-little endian machines. + * + * The function returns an integer less than, equal to, or greater than zero + * if @s1 (or the first @n Unicode characters thereof) is found, respectively, + * to be less than, to match, or be greater than @s2. + */ +int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n) +{ + ntfschar c1, c2; + size_t i; + +#ifdef DEBUG + if (!s1 || !s2) { + ntfs_log_debug("ntfs_wcsncmp() received NULL pointer!\n"); + exit(1); + } +#endif + for (i = 0; i < n; ++i) { + c1 = le16_to_cpu(s1[i]); + c2 = le16_to_cpu(s2[i]); + if (c1 < c2) + return -1; + if (c1 > c2) + return 1; + if (!c1) + break; + } + return 0; +} + +/** + * ntfs_ucsncasecmp - compare two little endian Unicode strings, ignoring case + * @s1: first string + * @s2: second string + * @n: maximum unicode characters to compare + * @upcase: upcase table + * @upcase_size: upcase table size in Unicode characters + * + * Compare the first @n characters of the Unicode strings @s1 and @s2, + * ignoring case. The strings in little endian format and appropriate + * le16_to_cpu() conversion is performed on non-little endian machines. + * + * Each character is uppercased using the @upcase table before the comparison. + * + * The function returns an integer less than, equal to, or greater than zero + * if @s1 (or the first @n Unicode characters thereof) is found, respectively, + * to be less than, to match, or be greater than @s2. + */ +int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n, + const ntfschar *upcase, const u32 upcase_size) +{ + u16 c1, c2; + size_t i; + +#ifdef DEBUG + if (!s1 || !s2 || !upcase) { + ntfs_log_debug("ntfs_wcsncasecmp() received NULL pointer!\n"); + exit(1); + } +#endif + for (i = 0; i < n; ++i) { + if ((c1 = le16_to_cpu(s1[i])) < upcase_size) + c1 = le16_to_cpu(upcase[c1]); + if ((c2 = le16_to_cpu(s2[i])) < upcase_size) + c2 = le16_to_cpu(upcase[c2]); + if (c1 < c2) + return -1; + if (c1 > c2) + return 1; + if (!c1) + break; + } + return 0; +} + +/** + * ntfs_ucsnlen - determine the length of a little endian Unicode string + * @s: pointer to Unicode string + * @maxlen: maximum length of string @s + * + * Return the number of Unicode characters in the little endian Unicode + * string @s up to a maximum of maxlen Unicode characters, not including + * the terminating (ntfschar)'\0'. If there is no (ntfschar)'\0' between @s + * and @s + @maxlen, @maxlen is returned. + * + * This function never looks beyond @s + @maxlen. + */ +u32 ntfs_ucsnlen(const ntfschar *s, u32 maxlen) +{ + u32 i; + + for (i = 0; i < maxlen; i++) { + if (!le16_to_cpu(s[i])) + break; + } + return i; +} + +/** + * ntfs_ucsndup - duplicate little endian Unicode string + * @s: pointer to Unicode string + * @maxlen: maximum length of string @s + * + * Return a pointer to a new little endian Unicode string which is a duplicate + * of the string s. Memory for the new string is obtained with ntfs_malloc(3), + * and can be freed with free(3). + * + * A maximum of @maxlen Unicode characters are copied and a terminating + * (ntfschar)'\0' little endian Unicode character is added. + * + * This function never looks beyond @s + @maxlen. + * + * Return a pointer to the new little endian Unicode string on success and NULL + * on failure with errno set to the error code. + */ +ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen) +{ + ntfschar *dst; + u32 len; + + len = ntfs_ucsnlen(s, maxlen); + dst = ntfs_malloc((len + 1) * sizeof(ntfschar)); + if (dst) { + memcpy(dst, s, len * sizeof(ntfschar)); + dst[len] = cpu_to_le16(L'\0'); + } + return dst; +} + +/** + * ntfs_name_upcase - Map an Unicode name to its uppercase equivalent + * @name: + * @name_len: + * @upcase: + * @upcase_len: + * + * Description... + * + * Returns: + */ +void ntfs_name_upcase(ntfschar *name, u32 name_len, const ntfschar *upcase, + const u32 upcase_len) +{ + u32 i; + u16 u; + + for (i = 0; i < name_len; i++) + if ((u = le16_to_cpu(name[i])) < upcase_len) + name[i] = upcase[u]; +} + +/** + * ntfs_name_locase - Map a Unicode name to its lowercase equivalent + */ +void ntfs_name_locase(ntfschar *name, u32 name_len, const ntfschar *locase, + const u32 locase_len) +{ + u32 i; + u16 u; + + if (locase) + for (i = 0; i < name_len; i++) + if ((u = le16_to_cpu(name[i])) < locase_len) + name[i] = locase[u]; +} + +/** + * ntfs_file_value_upcase - Convert a filename to upper case + * @file_name_attr: + * @upcase: + * @upcase_len: + * + * Description... + * + * Returns: + */ +void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr, + const ntfschar *upcase, const u32 upcase_len) +{ + ntfs_name_upcase((ntfschar*)&file_name_attr->file_name, + file_name_attr->file_name_length, upcase, upcase_len); +} + +/* + NTFS uses Unicode (UTF-16LE [NTFS-3G uses UCS-2LE, which is enough + for now]) for path names, but the Unicode code points need to be + converted before a path can be accessed under NTFS. For 7 bit ASCII/ANSI, + glibc does this even without a locale in a hard-coded fashion as that + appears to be is easy because the low 7-bit ASCII range appears to be + available in all charsets but it does not convert anything if + there was some error with the locale setup or none set up like + when mount is called during early boot where he (by policy) do + not use locales (and may be not available if /usr is not yet mounted), + so this patch fixes the resulting issues for systems which use + UTF-8 and for others, specifying the locale in fstab brings them + the encoding which they want. + + If no locale is defined or there was a problem with setting one + up and whenever nl_langinfo(CODESET) returns a sting starting with + "ANSI", use an internal UCS-2LE <-> UTF-8 codeset converter to fix + the bug where NTFS-3G does not show any path names which include + international characters!!! (and also fails on creating them) as result. + + Author: Bernhard Kaindl + Jean-Pierre Andre made it compliant with RFC3629/RFC2781. +*/ + +/* + * Return the amount of 8-bit elements in UTF-8 needed (without the terminating + * null) to store a given UTF-16LE string. + * + * Return -1 with errno set if string has invalid byte sequence or too long. + */ +static int utf16_to_utf8_size(const ntfschar *ins, const int ins_len, int outs_len) +{ + int i, ret = -1; + int count = 0; + BOOL surrog; + + surrog = FALSE; + for (i = 0; i < ins_len && ins[i]; i++) { + unsigned short c = le16_to_cpu(ins[i]); + if (surrog) { + if ((c >= 0xdc00) && (c < 0xe000)) { + surrog = FALSE; + count += 4; + } else + goto fail; + } else + if (c < 0x80) + count++; + else if (c < 0x800) + count += 2; + else if (c < 0xd800) + count += 3; + else if (c < 0xdc00) + surrog = TRUE; +#if NOREVBOM + else if ((c >= 0xe000) && (c < 0xfffe)) +#else + else if (c >= 0xe000) +#endif + count += 3; + else + goto fail; + if (count > outs_len) { + errno = ENAMETOOLONG; + goto out; + } + } + if (surrog) + goto fail; + + ret = count; +out: + return ret; +fail: + errno = EILSEQ; + goto out; +} + +/* + * ntfs_utf16_to_utf8 - convert a little endian UTF16LE string to an UTF-8 string + * @ins: input utf16 string buffer + * @ins_len: length of input string in utf16 characters + * @outs: on return contains the (allocated) output multibyte string + * @outs_len: length of output buffer in bytes + * + * Return -1 with errno set if string has invalid byte sequence or too long. + */ +static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len, + char **outs, int outs_len) +{ +#if defined(__APPLE__) || defined(__DARWIN__) +#ifdef ENABLE_NFCONV + char *original_outs_value = *outs; + int original_outs_len = outs_len; +#endif /* ENABLE_NFCONV */ +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + + char *t; + int i, size, ret = -1; + int halfpair; + + halfpair = 0; + if (!*outs) + outs_len = PATH_MAX; + + size = utf16_to_utf8_size(ins, ins_len, outs_len); + + if (size < 0) + goto out; + + if (!*outs) { + outs_len = size + 1; + *outs = ntfs_malloc(outs_len); + if (!*outs) + goto out; + } + + t = *outs; + + for (i = 0; i < ins_len && ins[i]; i++) { + unsigned short c = le16_to_cpu(ins[i]); + /* size not double-checked */ + if (halfpair) { + if ((c >= 0xdc00) && (c < 0xe000)) { + *t++ = 0xf0 + (((halfpair + 64) >> 8) & 7); + *t++ = 0x80 + (((halfpair + 64) >> 2) & 63); + *t++ = 0x80 + ((c >> 6) & 15) + ((halfpair & 3) << 4); + *t++ = 0x80 + (c & 63); + halfpair = 0; + } else + goto fail; + } else if (c < 0x80) { + *t++ = c; + } else { + if (c < 0x800) { + *t++ = (0xc0 | ((c >> 6) & 0x3f)); + *t++ = 0x80 | (c & 0x3f); + } else if (c < 0xd800) { + *t++ = 0xe0 | (c >> 12); + *t++ = 0x80 | ((c >> 6) & 0x3f); + *t++ = 0x80 | (c & 0x3f); + } else if (c < 0xdc00) + halfpair = c; + else if (c >= 0xe000) { + *t++ = 0xe0 | (c >> 12); + *t++ = 0x80 | ((c >> 6) & 0x3f); + *t++ = 0x80 | (c & 0x3f); + } else + goto fail; + } + } + *t = '\0'; + +#if defined(__APPLE__) || defined(__DARWIN__) +#ifdef ENABLE_NFCONV + if(nfconvert_utf8 && (t - *outs) > 0) { + char *new_outs = NULL; + int new_outs_len = ntfs_macosx_normalize_utf8(*outs, &new_outs, 0); // Normalize to decomposed form + if(new_outs_len >= 0 && new_outs != NULL) { + if(original_outs_value != *outs) { + // We have allocated outs ourselves. + free(*outs); + *outs = new_outs; + t = *outs + new_outs_len; + } + else { + // We need to copy new_outs into the fixed outs buffer. + memset(*outs, 0, original_outs_len); + strncpy(*outs, new_outs, original_outs_len-1); + t = *outs + original_outs_len; + free(new_outs); + } + } + else { + ntfs_log_error("Failed to normalize NTFS string to UTF-8 NFD: %s\n", *outs); + ntfs_log_error(" new_outs=0x%p\n", new_outs); + ntfs_log_error(" new_outs_len=%d\n", new_outs_len); + } + } +#endif /* ENABLE_NFCONV */ +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + + ret = t - *outs; +out: + return ret; +fail: + errno = EILSEQ; + goto out; +} + +/* + * Return the amount of 16-bit elements in UTF-16LE needed + * (without the terminating null) to store given UTF-8 string. + * + * Return -1 with errno set if it's longer than PATH_MAX or string is invalid. + * + * Note: This does not check whether the input sequence is a valid utf8 string, + * and should be used only in context where such check is made! + */ +static int utf8_to_utf16_size(const char *s) +{ + int ret = -1; + unsigned int byte; + size_t count = 0; + + while ((byte = *((const unsigned char *)s++))) { + if (++count >= PATH_MAX) + goto fail; + if (byte >= 0xc0) { + if (byte >= 0xF5) { + errno = EILSEQ; + goto out; + } + if (!*s) + break; + if (byte >= 0xC0) + s++; + if (!*s) + break; + if (byte >= 0xE0) + s++; + if (!*s) + break; + if (byte >= 0xF0) { + s++; + if (++count >= PATH_MAX) + goto fail; + } + } + } + ret = count; +out: + return ret; +fail: + errno = ENAMETOOLONG; + goto out; +} +/* + * This converts one UTF-8 sequence to cpu-endian Unicode value + * within range U+0 .. U+10ffff and excluding U+D800 .. U+DFFF + * + * Return the number of used utf8 bytes or -1 with errno set + * if sequence is invalid. + */ +static int utf8_to_unicode(u32 *wc, const char *s) +{ + unsigned int byte = *((const unsigned char *)s); + + /* single byte */ + if (byte == 0) { + *wc = (u32) 0; + return 0; + } else if (byte < 0x80) { + *wc = (u32) byte; + return 1; + /* double byte */ + } else if (byte < 0xc2) { + goto fail; + } else if (byte < 0xE0) { + if ((s[1] & 0xC0) == 0x80) { + *wc = ((u32)(byte & 0x1F) << 6) + | ((u32)(s[1] & 0x3F)); + return 2; + } else + goto fail; + /* three-byte */ + } else if (byte < 0xF0) { + if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80)) { + *wc = ((u32)(byte & 0x0F) << 12) + | ((u32)(s[1] & 0x3F) << 6) + | ((u32)(s[2] & 0x3F)); + /* Check valid ranges */ +#if NOREVBOM + if (((*wc >= 0x800) && (*wc <= 0xD7FF)) + || ((*wc >= 0xe000) && (*wc <= 0xFFFD))) + return 3; +#else + if (((*wc >= 0x800) && (*wc <= 0xD7FF)) + || ((*wc >= 0xe000) && (*wc <= 0xFFFF))) + return 3; +#endif + } + goto fail; + /* four-byte */ + } else if (byte < 0xF5) { + if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80) + && ((s[3] & 0xC0) == 0x80)) { + *wc = ((u32)(byte & 0x07) << 18) + | ((u32)(s[1] & 0x3F) << 12) + | ((u32)(s[2] & 0x3F) << 6) + | ((u32)(s[3] & 0x3F)); + /* Check valid ranges */ + if ((*wc <= 0x10ffff) && (*wc >= 0x10000)) + return 4; + } + goto fail; + } +fail: + errno = EILSEQ; + return -1; +} + +/** + * ntfs_utf8_to_utf16 - convert a UTF-8 string to a UTF-16LE string + * @ins: input multibyte string buffer + * @outs: on return contains the (allocated) output utf16 string + * @outs_len: length of output buffer in utf16 characters + * + * Return -1 with errno set. + */ +static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs) +{ +#if defined(__APPLE__) || defined(__DARWIN__) +#ifdef ENABLE_NFCONV + char *new_ins = NULL; + if(nfconvert_utf8) { + int new_ins_len; + new_ins_len = ntfs_macosx_normalize_utf8(ins, &new_ins, 1); // Normalize to composed form + if(new_ins_len >= 0) + ins = new_ins; + else + ntfs_log_error("Failed to normalize NTFS string to UTF-8 NFC: %s\n", ins); + } +#endif /* ENABLE_NFCONV */ +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + const char *t = ins; + u32 wc; + BOOL allocated; + ntfschar *outpos; + int shorts, ret = -1; + + shorts = utf8_to_utf16_size(ins); + if (shorts < 0) + goto fail; + + allocated = FALSE; + if (!*outs) { + *outs = ntfs_malloc((shorts + 1) * sizeof(ntfschar)); + if (!*outs) + goto fail; + allocated = TRUE; + } + + outpos = *outs; + + while(1) { + int m = utf8_to_unicode(&wc, t); + if (m <= 0) { + if (m < 0) { + /* do not leave space allocated if failed */ + if (allocated) { + free(*outs); + *outs = (ntfschar*)NULL; + } + goto fail; + } + *outpos++ = const_cpu_to_le16(0); + break; + } + if (wc < 0x10000) + *outpos++ = cpu_to_le16(wc); + else { + wc -= 0x10000; + *outpos++ = cpu_to_le16((wc >> 10) + 0xd800); + *outpos++ = cpu_to_le16((wc & 0x3ff) + 0xdc00); + } + t += m; + } + + ret = --outpos - *outs; +fail: +#if defined(__APPLE__) || defined(__DARWIN__) +#ifdef ENABLE_NFCONV + if(new_ins != NULL) + free(new_ins); +#endif /* ENABLE_NFCONV */ +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + return ret; +} + +/** + * ntfs_ucstombs - convert a little endian Unicode string to a multibyte string + * @ins: input Unicode string buffer + * @ins_len: length of input string in Unicode characters + * @outs: on return contains the (allocated) output multibyte string + * @outs_len: length of output buffer in bytes + * + * Convert the input little endian, 2-byte Unicode string @ins, of length + * @ins_len into the multibyte string format dictated by the current locale. + * + * If *@outs is NULL, the function allocates the string and the caller is + * responsible for calling free(*@outs); when finished with it. + * + * On success the function returns the number of bytes written to the output + * string *@outs (>= 0), not counting the terminating NULL byte. If the output + * string buffer was allocated, *@outs is set to it. + * + * On error, -1 is returned, and errno is set to the error code. The following + * error codes can be expected: + * EINVAL Invalid arguments (e.g. @ins or @outs is NULL). + * EILSEQ The input string cannot be represented as a multibyte + * sequence according to the current locale. + * ENAMETOOLONG Destination buffer is too small for input string. + * ENOMEM Not enough memory to allocate destination buffer. + */ +int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs, + int outs_len) +{ + char *mbs; + int mbs_len; +#ifdef MB_CUR_MAX + wchar_t wc; + int i, o; + int cnt = 0; +#ifdef HAVE_MBSINIT + mbstate_t mbstate; +#endif +#endif /* MB_CUR_MAX */ + + if (!ins || !outs) { + errno = EINVAL; + return -1; + } + mbs = *outs; + mbs_len = outs_len; + if (mbs && !mbs_len) { + errno = ENAMETOOLONG; + return -1; + } + if (use_utf8) + return ntfs_utf16_to_utf8(ins, ins_len, outs, outs_len); +#ifdef MB_CUR_MAX + if (!mbs) { + mbs_len = (ins_len + 1) * MB_CUR_MAX; + mbs = ntfs_malloc(mbs_len); + if (!mbs) + return -1; + } +#ifdef HAVE_MBSINIT + memset(&mbstate, 0, sizeof(mbstate)); +#else + wctomb(NULL, 0); +#endif + for (i = o = 0; i < ins_len; i++) { + /* Reallocate memory if necessary or abort. */ + if ((int)(o + MB_CUR_MAX) > mbs_len) { + char *tc; + if (mbs == *outs) { + errno = ENAMETOOLONG; + return -1; + } + tc = ntfs_malloc((mbs_len + 64) & ~63); + if (!tc) + goto err_out; + memcpy(tc, mbs, mbs_len); + mbs_len = (mbs_len + 64) & ~63; + free(mbs); + mbs = tc; + } + /* Convert the LE Unicode character to a CPU wide character. */ + wc = (wchar_t)le16_to_cpu(ins[i]); + if (!wc) + break; + /* Convert the CPU endian wide character to multibyte. */ +#ifdef HAVE_MBSINIT + cnt = wcrtomb(mbs + o, wc, &mbstate); +#else + cnt = wctomb(mbs + o, wc); +#endif + if (cnt == -1) + goto err_out; + if (cnt <= 0) { + ntfs_log_debug("Eeek. cnt <= 0, cnt = %i\n", cnt); + errno = EINVAL; + goto err_out; + } + o += cnt; + } +#ifdef HAVE_MBSINIT + /* Make sure we are back in the initial state. */ + if (!mbsinit(&mbstate)) { + ntfs_log_debug("Eeek. mbstate not in initial state!\n"); + errno = EILSEQ; + goto err_out; + } +#endif + /* Now write the NULL character. */ + mbs[o] = '\0'; + if (*outs != mbs) + *outs = mbs; + return o; +err_out: + if (mbs != *outs) { + int eo = errno; + free(mbs); + errno = eo; + } +#else /* MB_CUR_MAX */ + errno = EILSEQ; +#endif /* MB_CUR_MAX */ + return -1; +} + +/** + * ntfs_mbstoucs - convert a multibyte string to a little endian Unicode string + * @ins: input multibyte string buffer + * @outs: on return contains the (allocated) output Unicode string + * + * Convert the input multibyte string @ins, from the current locale into the + * corresponding little endian, 2-byte Unicode string. + * + * The function allocates the string and the caller is responsible for calling + * free(*@outs); when finished with it. + * + * On success the function returns the number of Unicode characters written to + * the output string *@outs (>= 0), not counting the terminating Unicode NULL + * character. + * + * On error, -1 is returned, and errno is set to the error code. The following + * error codes can be expected: + * EINVAL Invalid arguments (e.g. @ins or @outs is NULL). + * EILSEQ The input string cannot be represented as a Unicode + * string according to the current locale. + * ENAMETOOLONG Destination buffer is too small for input string. + * ENOMEM Not enough memory to allocate destination buffer. + */ +int ntfs_mbstoucs(const char *ins, ntfschar **outs) +{ +#ifdef MB_CUR_MAX + ntfschar *ucs; + const char *s; + wchar_t wc; + int i, o, cnt, ins_len, ucs_len, ins_size; +#ifdef HAVE_MBSINIT + mbstate_t mbstate; +#endif +#endif /* MB_CUR_MAX */ + + if (!ins || !outs) { + errno = EINVAL; + return -1; + } + + if (use_utf8) + return ntfs_utf8_to_utf16(ins, outs); + +#ifdef MB_CUR_MAX + /* Determine the size of the multi-byte string in bytes. */ + ins_size = strlen(ins); + /* Determine the length of the multi-byte string. */ + s = ins; +#if defined(HAVE_MBSINIT) + memset(&mbstate, 0, sizeof(mbstate)); + ins_len = mbsrtowcs(NULL, (const char **)&s, 0, &mbstate); +#ifdef __CYGWIN32__ + if (!ins_len && *ins) { + /* Older Cygwin had broken mbsrtowcs() implementation. */ + ins_len = strlen(ins); + } +#endif +#elif !defined(DJGPP) + ins_len = mbstowcs(NULL, s, 0); +#else + /* Eeek!!! DJGPP has broken mbstowcs() implementation!!! */ + ins_len = strlen(ins); +#endif + if (ins_len == -1) + return ins_len; +#ifdef HAVE_MBSINIT + if ((s != ins) || !mbsinit(&mbstate)) { +#else + if (s != ins) { +#endif + errno = EILSEQ; + return -1; + } + /* Add the NULL terminator. */ + ins_len++; + ucs_len = ins_len; + ucs = ntfs_malloc(ucs_len * sizeof(ntfschar)); + if (!ucs) + return -1; +#ifdef HAVE_MBSINIT + memset(&mbstate, 0, sizeof(mbstate)); +#else + mbtowc(NULL, NULL, 0); +#endif + for (i = o = cnt = 0; i < ins_size; i += cnt, o++) { + /* Reallocate memory if necessary. */ + if (o >= ucs_len) { + ntfschar *tc; + ucs_len = (ucs_len * sizeof(ntfschar) + 64) & ~63; + tc = realloc(ucs, ucs_len); + if (!tc) + goto err_out; + ucs = tc; + ucs_len /= sizeof(ntfschar); + } + /* Convert the multibyte character to a wide character. */ +#ifdef HAVE_MBSINIT + cnt = mbrtowc(&wc, ins + i, ins_size - i, &mbstate); +#else + cnt = mbtowc(&wc, ins + i, ins_size - i); +#endif + if (!cnt) + break; + if (cnt == -1) + goto err_out; + if (cnt < -1) { + ntfs_log_trace("Eeek. cnt = %i\n", cnt); + errno = EINVAL; + goto err_out; + } + /* Make sure we are not overflowing the NTFS Unicode set. */ + if ((unsigned long)wc >= (unsigned long)(1 << + (8 * sizeof(ntfschar)))) { + errno = EILSEQ; + goto err_out; + } + /* Convert the CPU wide character to a LE Unicode character. */ + ucs[o] = cpu_to_le16(wc); + } +#ifdef HAVE_MBSINIT + /* Make sure we are back in the initial state. */ + if (!mbsinit(&mbstate)) { + ntfs_log_trace("Eeek. mbstate not in initial state!\n"); + errno = EILSEQ; + goto err_out; + } +#endif + /* Now write the NULL character. */ + ucs[o] = cpu_to_le16(L'\0'); + *outs = ucs; + return o; +err_out: + free(ucs); +#else /* MB_CUR_MAX */ + errno = EILSEQ; +#endif /* MB_CUR_MAX */ + return -1; +} + +/* + * Turn a UTF8 name uppercase + * + * Returns an allocated uppercase name which has to be freed by caller + * or NULL if there is an error (described by errno) + */ + +char *ntfs_uppercase_mbs(const char *low, + const ntfschar *upcase, u32 upcase_size) +{ + int size; + char *upp; + u32 wc; + int n; + const char *s; + char *t; + + size = strlen(low); + upp = (char*)ntfs_malloc(3*size + 1); + if (upp) { + s = low; + t = upp; + do { + n = utf8_to_unicode(&wc, s); + if (n > 0) { + if (wc < upcase_size) + wc = le16_to_cpu(upcase[wc]); + if (wc < 0x80) + *t++ = wc; + else if (wc < 0x800) { + *t++ = (0xc0 | ((wc >> 6) & 0x3f)); + *t++ = 0x80 | (wc & 0x3f); + } else if (wc < 0x10000) { + *t++ = 0xe0 | (wc >> 12); + *t++ = 0x80 | ((wc >> 6) & 0x3f); + *t++ = 0x80 | (wc & 0x3f); + } else { + *t++ = 0xf0 | ((wc >> 18) & 7); + *t++ = 0x80 | ((wc >> 12) & 63); + *t++ = 0x80 | ((wc >> 6) & 0x3f); + *t++ = 0x80 | (wc & 0x3f); + } + s += n; + } + } while (n > 0); + if (n < 0) { + free(upp); + upp = (char*)NULL; + errno = EILSEQ; + } + *t = 0; + } + return (upp); +} + +/** + * ntfs_upcase_table_build - build the default upcase table for NTFS + * @uc: destination buffer where to store the built table + * @uc_len: size of destination buffer in bytes + * + * ntfs_upcase_table_build() builds the default upcase table for NTFS and + * stores it in the caller supplied buffer @uc of size @uc_len. + * + * Note, @uc_len must be at least 128kiB in size or bad things will happen! + */ +void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len) +{ + static int uc_run_table[][3] = { /* Start, End, Add */ + {0x0061, 0x007B, -32}, {0x0451, 0x045D, -80}, {0x1F70, 0x1F72, 74}, + {0x00E0, 0x00F7, -32}, {0x045E, 0x0460, -80}, {0x1F72, 0x1F76, 86}, + {0x00F8, 0x00FF, -32}, {0x0561, 0x0587, -48}, {0x1F76, 0x1F78, 100}, + {0x0256, 0x0258, -205}, {0x1F00, 0x1F08, 8}, {0x1F78, 0x1F7A, 128}, + {0x028A, 0x028C, -217}, {0x1F10, 0x1F16, 8}, {0x1F7A, 0x1F7C, 112}, + {0x03AC, 0x03AD, -38}, {0x1F20, 0x1F28, 8}, {0x1F7C, 0x1F7E, 126}, + {0x03AD, 0x03B0, -37}, {0x1F30, 0x1F38, 8}, {0x1FB0, 0x1FB2, 8}, + {0x03B1, 0x03C2, -32}, {0x1F40, 0x1F46, 8}, {0x1FD0, 0x1FD2, 8}, + {0x03C2, 0x03C3, -31}, {0x1F51, 0x1F52, 8}, {0x1FE0, 0x1FE2, 8}, + {0x03C3, 0x03CC, -32}, {0x1F53, 0x1F54, 8}, {0x1FE5, 0x1FE6, 7}, + {0x03CC, 0x03CD, -64}, {0x1F55, 0x1F56, 8}, {0x2170, 0x2180, -16}, + {0x03CD, 0x03CF, -63}, {0x1F57, 0x1F58, 8}, {0x24D0, 0x24EA, -26}, + {0x0430, 0x0450, -32}, {0x1F60, 0x1F68, 8}, {0xFF41, 0xFF5B, -32}, + {0} + }; + static int uc_dup_table[][2] = { /* Start, End */ + {0x0100, 0x012F}, {0x01A0, 0x01A6}, {0x03E2, 0x03EF}, {0x04CB, 0x04CC}, + {0x0132, 0x0137}, {0x01B3, 0x01B7}, {0x0460, 0x0481}, {0x04D0, 0x04EB}, + {0x0139, 0x0149}, {0x01CD, 0x01DD}, {0x0490, 0x04BF}, {0x04EE, 0x04F5}, + {0x014A, 0x0178}, {0x01DE, 0x01EF}, {0x04BF, 0x04BF}, {0x04F8, 0x04F9}, + {0x0179, 0x017E}, {0x01F4, 0x01F5}, {0x04C1, 0x04C4}, {0x1E00, 0x1E95}, + {0x018B, 0x018B}, {0x01FA, 0x0218}, {0x04C7, 0x04C8}, {0x1EA0, 0x1EF9}, + {0} + }; + static int uc_byte_table[][2] = { /* Offset, Value */ + {0x00FF, 0x0178}, {0x01AD, 0x01AC}, {0x01F3, 0x01F1}, {0x0269, 0x0196}, + {0x0183, 0x0182}, {0x01B0, 0x01AF}, {0x0253, 0x0181}, {0x026F, 0x019C}, + {0x0185, 0x0184}, {0x01B9, 0x01B8}, {0x0254, 0x0186}, {0x0272, 0x019D}, + {0x0188, 0x0187}, {0x01BD, 0x01BC}, {0x0259, 0x018F}, {0x0275, 0x019F}, + {0x018C, 0x018B}, {0x01C6, 0x01C4}, {0x025B, 0x0190}, {0x0283, 0x01A9}, + {0x0192, 0x0191}, {0x01C9, 0x01C7}, {0x0260, 0x0193}, {0x0288, 0x01AE}, + {0x0199, 0x0198}, {0x01CC, 0x01CA}, {0x0263, 0x0194}, {0x0292, 0x01B7}, + {0x01A8, 0x01A7}, {0x01DD, 0x018E}, {0x0268, 0x0197}, + {0} + }; + int i, r; + int k, off; + + memset((char*)uc, 0, uc_len); + uc_len >>= 1; + if (uc_len > 65536) + uc_len = 65536; + for (i = 0; (u32)i < uc_len; i++) + uc[i] = cpu_to_le16(i); + for (r = 0; uc_run_table[r][0]; r++) { + off = uc_run_table[r][2]; + for (i = uc_run_table[r][0]; i < uc_run_table[r][1]; i++) + uc[i] = cpu_to_le16(i + off); + } + for (r = 0; uc_dup_table[r][0]; r++) + for (i = uc_dup_table[r][0]; i < uc_dup_table[r][1]; i += 2) + uc[i + 1] = cpu_to_le16(i); + for (r = 0; uc_byte_table[r][0]; r++) { + k = uc_byte_table[r][1]; + uc[uc_byte_table[r][0]] = cpu_to_le16(k); + } +} + +/* + * Build a table for converting to lower case + * + * This is only meaningful when there is a single lower case + * character leading to an upper case one, and currently the + * only exception is the greek letter sigma which has a single + * upper case glyph (code U+03A3), but two lower case glyphs + * (code U+03C3 and U+03C2, the latter to be used at the end + * of a word). In the following implementation the upper case + * sigma will be lowercased as U+03C3. + */ + +ntfschar *ntfs_locase_table_build(const ntfschar *uc, u32 uc_cnt) +{ + ntfschar *lc; + u32 upp; + u32 i; + + lc = (ntfschar*)ntfs_malloc(uc_cnt*sizeof(ntfschar)); + if (lc) { + for (i=0; i NTFS_MAX_NAME_LEN) { + free(ucs); + errno = ENAMETOOLONG; + return NULL; + } + if (!ucs || !*len) { + ucs = AT_UNNAMED; + *len = 0; + } + return ucs; +} + +/** + * ntfs_ucsfree - free memory allocated by ntfs_str2ucs() + * @ucs input string to be freed + * + * Free memory at @ucs and which was allocated by ntfs_str2ucs. + * + * Return value: none. + */ +void ntfs_ucsfree(ntfschar *ucs) +{ + if (ucs && (ucs != AT_UNNAMED)) + free(ucs); +} + +/* + * Check whether a name contains no chars forbidden + * for DOS or Win32 use + * + * If there is a bad char, errno is set to EINVAL + */ + +BOOL ntfs_forbidden_chars(const ntfschar *name, int len) +{ + BOOL forbidden; + int ch; + int i; + u32 mainset = (1L << ('\"' - 0x20)) + | (1L << ('*' - 0x20)) + | (1L << ('/' - 0x20)) + | (1L << (':' - 0x20)) + | (1L << ('<' - 0x20)) + | (1L << ('>' - 0x20)) + | (1L << ('?' - 0x20)); + + forbidden = (len == 0) + || (le16_to_cpu(name[len-1]) == ' ') + || (le16_to_cpu(name[len-1]) == '.'); + for (i=0; i= vol->upcase_len) + || ((shortname[i] != longname[i]) + && (shortname[i] != vol->upcase[ch]))) + collapsible = FALSE; + } + return (collapsible); +} + +/* + * Define the character encoding to be used. + * Use UTF-8 unless specified otherwise. + */ + +int ntfs_set_char_encoding(const char *locale) +{ + use_utf8 = 0; + if (!locale || strstr(locale,"utf8") || strstr(locale,"UTF8") + || strstr(locale,"utf-8") || strstr(locale,"UTF-8")) + use_utf8 = 1; + else + if (setlocale(LC_ALL, locale)) + use_utf8 = 0; + else { + ntfs_log_error("Invalid locale, encoding to UTF-8\n"); + use_utf8 = 1; + } + return 0; /* always successful */ +} + +#if defined(__APPLE__) || defined(__DARWIN__) + +int ntfs_macosx_normalize_filenames(int normalize) { +#ifdef ENABLE_NFCONV + if(normalize == 0 || normalize == 1) { + nfconvert_utf8 = normalize; + return 0; + } + else + return -1; +#else + return -1; +#endif /* ENABLE_NFCONV */ +} + +int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target, + int composed) { +#ifdef ENABLE_NFCONV + /* For this code to compile, the CoreFoundation framework must be fed to the linker. */ + CFStringRef cfSourceString; + CFMutableStringRef cfMutableString; + CFRange rangeToProcess; + CFIndex requiredBufferLength; + char *result = NULL; + int resultLength = -1; + + /* Convert the UTF-8 string to a CFString. */ + cfSourceString = CFStringCreateWithCString(kCFAllocatorDefault, utf8_string, kCFStringEncodingUTF8); + if(cfSourceString == NULL) { + ntfs_log_error("CFStringCreateWithCString failed!\n"); + return -2; + } + + /* Create a mutable string from cfSourceString that we are free to modify. */ + cfMutableString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, cfSourceString); + CFRelease(cfSourceString); /* End-of-life. */ + if(cfMutableString == NULL) { + ntfs_log_error("CFStringCreateMutableCopy failed!\n"); + return -3; + } + + /* Normalize the mutable string to the desired normalization form. */ + CFStringNormalize(cfMutableString, (composed != 0 ? kCFStringNormalizationFormC : kCFStringNormalizationFormD)); + + /* Store the resulting string in a '\0'-terminated UTF-8 encoded char* buffer. */ + rangeToProcess = CFRangeMake(0, CFStringGetLength(cfMutableString)); + if(CFStringGetBytes(cfMutableString, rangeToProcess, kCFStringEncodingUTF8, 0, false, NULL, 0, &requiredBufferLength) > 0) { + resultLength = sizeof(char)*(requiredBufferLength + 1); + result = ntfs_calloc(resultLength); + + if(result != NULL) { + if(CFStringGetBytes(cfMutableString, rangeToProcess, kCFStringEncodingUTF8, + 0, false, (UInt8*)result, resultLength-1, &requiredBufferLength) <= 0) { + ntfs_log_error("Could not perform UTF-8 conversion of normalized CFMutableString.\n"); + free(result); + result = NULL; + } + } + else + ntfs_log_error("Could not perform a ntfs_calloc of %d bytes for char *result.\n", resultLength); + } + else + ntfs_log_error("Could not perform check for required length of UTF-8 conversion of normalized CFMutableString.\n"); + + + CFRelease(cfMutableString); + + if(result != NULL) { + *target = result; + return resultLength - 1; + } + else + return -1; +#else + return -1; +#endif /* ENABLE_NFCONV */ +} +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ diff --git a/libcustomntfs/unistr.h b/libcustomntfs/unistr.h new file mode 100644 index 00000000..639c5033 --- /dev/null +++ b/libcustomntfs/unistr.h @@ -0,0 +1,118 @@ +/* + * unistr.h - Exports for Unicode string handling. Originated from the Linux-NTFS + * project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_UNISTR_H +#define _NTFS_UNISTR_H + +#include "types.h" +#include "layout.h" + +extern BOOL ntfs_names_are_equal(const ntfschar *s1, size_t s1_len, + const ntfschar *s2, size_t s2_len, const IGNORE_CASE_BOOL ic, + const ntfschar *upcase, const u32 upcase_size); + +extern int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len, + const ntfschar *name2, const u32 name2_len, + const IGNORE_CASE_BOOL ic, + const ntfschar *upcase, const u32 upcase_len); + +extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n); + +extern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n, + const ntfschar *upcase, const u32 upcase_size); + +extern u32 ntfs_ucsnlen(const ntfschar *s, u32 maxlen); + +extern ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen); + +extern void ntfs_name_upcase(ntfschar *name, u32 name_len, + const ntfschar *upcase, const u32 upcase_len); + +extern void ntfs_name_locase(ntfschar *name, u32 name_len, + const ntfschar *locase, const u32 locase_len); + +extern void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr, + const ntfschar *upcase, const u32 upcase_len); + +extern int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs, + int outs_len); +extern int ntfs_mbstoucs(const char *ins, ntfschar **outs); + +extern char *ntfs_uppercase_mbs(const char *low, + const ntfschar *upcase, u32 upcase_len); + +extern void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len); +extern ntfschar *ntfs_locase_table_build(const ntfschar *uc, u32 uc_cnt); + +extern ntfschar *ntfs_str2ucs(const char *s, int *len); + +extern void ntfs_ucsfree(ntfschar *ucs); + +extern BOOL ntfs_forbidden_chars(const ntfschar *name, int len); +extern BOOL ntfs_collapsible_chars(ntfs_volume *vol, + const ntfschar *shortname, int shortlen, + const ntfschar *longname, int longlen); + +extern int ntfs_set_char_encoding(const char *locale); + +#if defined(__APPLE__) || defined(__DARWIN__) +/** + * Mac OS X only. + * + * Sets file name Unicode normalization form conversion on or off. + * normalize=0 : Off + * normalize=1 : On + * If set to on, all filenames returned by ntfs-3g will be converted to the NFD + * normalization form, while all filenames recieved by ntfs-3g will be converted to the NFC + * normalization form. Since Windows and most other OS:es use the NFC form while Mac OS X + * mostly uses NFD, this conversion increases compatibility between Mac applications and + * NTFS-3G. + * + * @param normalize decides whether or not the string functions will do automatic filename + * normalization when converting to and from UTF-8. 0 means normalization is disabled, + * 1 means it is enabled. + * @return -1 if the argument was invalid or an error occurred, 0 if all went well. + */ +extern int ntfs_macosx_normalize_filenames(int normalize); + +/** + * Mac OS X only. + * + * Normalizes the input string "utf8_string" to one of the normalization forms NFD or NFC. + * The parameter "composed" decides whether output should be in composed, NFC, form + * (composed == 1) or decomposed, NFD, form (composed == 0). + * Input is assumed to be properly UTF-8 encoded and null-terminated. Output will be a newly + * ntfs_calloc'ed string encoded in UTF-8. It is the callers responsibility to free(...) the + * allocated string when it's no longer needed. + * + * @param utf8_string the input string, which may be in any normalization form. + * @param target a pointer where the resulting string will be stored. + * @param composed decides which composition form to normalize the input string to. 0 means + * composed form (NFC), 1 means decomposed form (NFD). + * @return -1 if the normalization failed for some reason, otherwise the length of the + * normalized string stored in target. + */ +extern int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target, int composed); +#endif /* defined(__APPLE__) || defined(__DARWIN__) */ + +#endif /* defined _NTFS_UNISTR_H */ + diff --git a/libcustomntfs/volume.c b/libcustomntfs/volume.c new file mode 100644 index 00000000..629ec92c --- /dev/null +++ b/libcustomntfs/volume.c @@ -0,0 +1,1723 @@ +/** + * volume.c - NTFS volume handling code. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2006 Anton Altaparmakov + * Copyright (c) 2002-2009 Szabolcs Szakacsits + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2010 Jean-Pierre Andre + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_LOCALE_H +#include +#endif + +#include "compat.h" +#include "volume.h" +#include "attrib.h" +#include "mft.h" +#include "bootsect.h" +#include "device.h" +#include "debug.h" +#include "inode.h" +#include "runlist.h" +#include "logfile.h" +#include "dir.h" +#include "logging.h" +#include "cache.h" +#include "misc.h" + +const char *ntfs_home = +"Ntfs-3g news, support and information: http://ntfs-3g.org\n"; + +static const char *invalid_ntfs_msg = +"The device '%s' doesn't seem to have a valid NTFS.\n" +"Maybe the wrong device is used? Or the whole disk instead of a\n" +"partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?\n"; + +static const char *corrupt_volume_msg = +"NTFS is either inconsistent, or there is a hardware fault, or it's a\n" +"SoftRAID/FakeRAID hardware. In the first case run chkdsk /f on Windows\n" +"then reboot into Windows twice. The usage of the /f parameter is very\n" +"important! If the device is a SoftRAID/FakeRAID then first activate\n" +"it and mount a different device under the /dev/mapper/ directory, (e.g.\n" +"/dev/mapper/nvidia_eahaabcc1). Please see the 'dmraid' documentation\n" +"for more details.\n"; + +static const char *hibernated_volume_msg = +"The NTFS partition is hibernated. Please resume and shutdown Windows\n" +"properly, or mount the volume read-only with the 'ro' mount option, or\n" +"mount the volume read-write with the 'remove_hiberfile' mount option.\n" +"For example type on the command line:\n" +"\n" +" mount -t ntfs-3g -o remove_hiberfile %s %s\n" +"\n"; + +static const char *unclean_journal_msg = +"Write access is denied because the disk wasn't safely powered\n" +"off and the 'norecover' mount option was specified.\n"; + +static const char *opened_volume_msg = +"Mount is denied because the NTFS volume is already exclusively opened.\n" +"The volume may be already mounted, or another software may use it which\n" +"could be identified for example by the help of the 'fuser' command.\n"; + +static const char *fakeraid_msg = +"Either the device is missing or it's powered down, or you have\n" +"SoftRAID hardware and must use an activated, different device under\n" +"/dev/mapper/, (e.g. /dev/mapper/nvidia_eahaabcc1) to mount NTFS.\n" +"Please see the 'dmraid' documentation for help.\n"; + +static const char *access_denied_msg = +"Please check '%s' and the ntfs-3g binary permissions,\n" +"and the mounting user ID. More explanation is provided at\n" +"http://ntfs-3g.org/support.html#unprivileged\n"; + +/** + * ntfs_volume_alloc - Create an NTFS volume object and initialise it + * + * Description... + * + * Returns: + */ +ntfs_volume *ntfs_volume_alloc(void) +{ + return ntfs_calloc(sizeof(ntfs_volume)); +} + +static void ntfs_attr_free(ntfs_attr **na) +{ + if (na && *na) { + ntfs_attr_close(*na); + *na = NULL; + } +} + +static int ntfs_inode_free(ntfs_inode **ni) +{ + int ret = -1; + + if (ni && *ni) { + ret = ntfs_inode_close(*ni); + *ni = NULL; + } + + return ret; +} + +static void ntfs_error_set(int *err) +{ + if (!*err) + *err = errno; +} + +/** + * __ntfs_volume_release - Destroy an NTFS volume object + * @v: + * + * Description... + * + * Returns: + */ +static int __ntfs_volume_release(ntfs_volume *v) +{ + int err = 0; + + if (ntfs_inode_free(&v->vol_ni)) + ntfs_error_set(&err); + /* + * FIXME: Inodes must be synced before closing + * attributes, otherwise unmount could fail. + */ + if (v->lcnbmp_ni && NInoDirty(v->lcnbmp_ni)) + ntfs_inode_sync(v->lcnbmp_ni); + ntfs_attr_free(&v->lcnbmp_na); + if (ntfs_inode_free(&v->lcnbmp_ni)) + ntfs_error_set(&err); + + if (v->mft_ni && NInoDirty(v->mft_ni)) + ntfs_inode_sync(v->mft_ni); + ntfs_attr_free(&v->mftbmp_na); + ntfs_attr_free(&v->mft_na); + if (ntfs_inode_free(&v->mft_ni)) + ntfs_error_set(&err); + + if (v->mftmirr_ni && NInoDirty(v->mftmirr_ni)) + ntfs_inode_sync(v->mftmirr_ni); + ntfs_attr_free(&v->mftmirr_na); + if (ntfs_inode_free(&v->mftmirr_ni)) + ntfs_error_set(&err); + + if (v->dev) { + struct ntfs_device *dev = v->dev; + + if (dev->d_ops->sync(dev)) + ntfs_error_set(&err); + if (dev->d_ops->close(dev)) + ntfs_error_set(&err); + } + + ntfs_free_lru_caches(v); + free(v->vol_name); + free(v->upcase); + if (v->locase) free(v->locase); + free(v->attrdef); + free(v); + + errno = err; + return errno ? -1 : 0; +} + +static void ntfs_attr_setup_flag(ntfs_inode *ni) +{ + STANDARD_INFORMATION *si; + + si = ntfs_attr_readall(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0, NULL); + if (si) { + ni->flags = si->file_attributes; + free(si); + } +} + +/** + * ntfs_mft_load - load the $MFT and setup the ntfs volume with it + * @vol: ntfs volume whose $MFT to load + * + * Load $MFT from @vol and setup @vol with it. After calling this function the + * volume @vol is ready for use by all read access functions provided by the + * ntfs library. + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +static int ntfs_mft_load(ntfs_volume *vol) +{ + VCN next_vcn, last_vcn, highest_vcn; + s64 l; + MFT_RECORD *mb = NULL; + ntfs_attr_search_ctx *ctx = NULL; + ATTR_RECORD *a; + int eo; + + /* Manually setup an ntfs_inode. */ + vol->mft_ni = ntfs_inode_allocate(vol); + mb = ntfs_malloc(vol->mft_record_size); + if (!vol->mft_ni || !mb) { + ntfs_log_perror("Error allocating memory for $MFT"); + goto error_exit; + } + vol->mft_ni->mft_no = 0; + vol->mft_ni->mrec = mb; + /* Can't use any of the higher level functions yet! */ + l = ntfs_mst_pread(vol->dev, vol->mft_lcn << vol->cluster_size_bits, 1, + vol->mft_record_size, mb); + if (l != 1) { + if (l != -1) + errno = EIO; + ntfs_log_perror("Error reading $MFT"); + goto error_exit; + } + + if (ntfs_mft_record_check(vol, 0, mb)) + goto error_exit; + + ctx = ntfs_attr_get_search_ctx(vol->mft_ni, NULL); + if (!ctx) + goto error_exit; + + /* Find the $ATTRIBUTE_LIST attribute in $MFT if present. */ + if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, 0, 0, NULL, 0, + ctx)) { + if (errno != ENOENT) { + ntfs_log_error("$MFT has corrupt attribute list.\n"); + goto io_error_exit; + } + goto mft_has_no_attr_list; + } + NInoSetAttrList(vol->mft_ni); + l = ntfs_get_attribute_value_length(ctx->attr); + if (l <= 0 || l > 0x40000) { + ntfs_log_error("$MFT/$ATTR_LIST invalid length (%lld).\n", + (long long)l); + goto io_error_exit; + } + vol->mft_ni->attr_list_size = l; + vol->mft_ni->attr_list = ntfs_malloc(l); + if (!vol->mft_ni->attr_list) + goto error_exit; + + l = ntfs_get_attribute_value(vol, ctx->attr, vol->mft_ni->attr_list); + if (!l) { + ntfs_log_error("Failed to get value of $MFT/$ATTR_LIST.\n"); + goto io_error_exit; + } + if (l != vol->mft_ni->attr_list_size) { + ntfs_log_error("Partial read of $MFT/$ATTR_LIST (%lld != " + "%u).\n", (long long)l, + vol->mft_ni->attr_list_size); + goto io_error_exit; + } + +mft_has_no_attr_list: + + ntfs_attr_setup_flag(vol->mft_ni); + + /* We now have a fully setup ntfs inode for $MFT in vol->mft_ni. */ + + /* Get an ntfs attribute for $MFT/$DATA and set it up, too. */ + vol->mft_na = ntfs_attr_open(vol->mft_ni, AT_DATA, AT_UNNAMED, 0); + if (!vol->mft_na) { + ntfs_log_perror("Failed to open ntfs attribute"); + goto error_exit; + } + /* Read all extents from the $DATA attribute in $MFT. */ + ntfs_attr_reinit_search_ctx(ctx); + last_vcn = vol->mft_na->allocated_size >> vol->cluster_size_bits; + highest_vcn = next_vcn = 0; + a = NULL; + while (!ntfs_attr_lookup(AT_DATA, AT_UNNAMED, 0, 0, next_vcn, NULL, 0, + ctx)) { + runlist_element *nrl; + + a = ctx->attr; + /* $MFT must be non-resident. */ + if (!a->non_resident) { + ntfs_log_error("$MFT must be non-resident.\n"); + goto io_error_exit; + } + /* $MFT must be uncompressed and unencrypted. */ + if (a->flags & ATTR_COMPRESSION_MASK || + a->flags & ATTR_IS_ENCRYPTED) { + ntfs_log_error("$MFT must be uncompressed and " + "unencrypted.\n"); + goto io_error_exit; + } + /* + * Decompress the mapping pairs array of this extent and merge + * the result into the existing runlist. No need for locking + * as we have exclusive access to the inode at this time and we + * are a mount in progress task, too. + */ + nrl = ntfs_mapping_pairs_decompress(vol, a, vol->mft_na->rl); + if (!nrl) { + ntfs_log_perror("ntfs_mapping_pairs_decompress() failed"); + goto error_exit; + } + vol->mft_na->rl = nrl; + + /* Get the lowest vcn for the next extent. */ + highest_vcn = sle64_to_cpu(a->highest_vcn); + next_vcn = highest_vcn + 1; + + /* Only one extent or error, which we catch below. */ + if (next_vcn <= 0) + break; + + /* Avoid endless loops due to corruption. */ + if (next_vcn < sle64_to_cpu(a->lowest_vcn)) { + ntfs_log_error("$MFT has corrupt attribute list.\n"); + goto io_error_exit; + } + } + if (!a) { + ntfs_log_error("$MFT/$DATA attribute not found.\n"); + goto io_error_exit; + } + if (highest_vcn && highest_vcn != last_vcn - 1) { + ntfs_log_error("Failed to load runlist for $MFT/$DATA.\n"); + ntfs_log_error("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx\n", + (long long)highest_vcn, (long long)last_vcn - 1); + goto io_error_exit; + } + /* Done with the $Mft mft record. */ + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + /* + * The volume is now setup so we can use all read access functions. + */ + vol->mftbmp_na = ntfs_attr_open(vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); + if (!vol->mftbmp_na) { + ntfs_log_perror("Failed to open $MFT/$BITMAP"); + goto error_exit; + } + return 0; +io_error_exit: + errno = EIO; +error_exit: + eo = errno; + if (ctx) + ntfs_attr_put_search_ctx(ctx); + if (vol->mft_na) { + ntfs_attr_close(vol->mft_na); + vol->mft_na = NULL; + } + if (vol->mft_ni) { + ntfs_inode_close(vol->mft_ni); + vol->mft_ni = NULL; + } + errno = eo; + return -1; +} + +/** + * ntfs_mftmirr_load - load the $MFTMirr and setup the ntfs volume with it + * @vol: ntfs volume whose $MFTMirr to load + * + * Load $MFTMirr from @vol and setup @vol with it. After calling this function + * the volume @vol is ready for use by all write access functions provided by + * the ntfs library (assuming ntfs_mft_load() has been called successfully + * beforehand). + * + * Return 0 on success and -1 on error with errno set to the error code. + */ +static int ntfs_mftmirr_load(ntfs_volume *vol) +{ + int err; + + vol->mftmirr_ni = ntfs_inode_open(vol, FILE_MFTMirr); + if (!vol->mftmirr_ni) { + ntfs_log_perror("Failed to open inode $MFTMirr"); + return -1; + } + + vol->mftmirr_na = ntfs_attr_open(vol->mftmirr_ni, AT_DATA, AT_UNNAMED, 0); + if (!vol->mftmirr_na) { + ntfs_log_perror("Failed to open $MFTMirr/$DATA"); + goto error_exit; + } + + if (ntfs_attr_map_runlist(vol->mftmirr_na, 0) < 0) { + ntfs_log_perror("Failed to map runlist of $MFTMirr/$DATA"); + goto error_exit; + } + + return 0; + +error_exit: + err = errno; + if (vol->mftmirr_na) { + ntfs_attr_close(vol->mftmirr_na); + vol->mftmirr_na = NULL; + } + ntfs_inode_close(vol->mftmirr_ni); + vol->mftmirr_ni = NULL; + errno = err; + return -1; +} + +/** + * ntfs_volume_startup - allocate and setup an ntfs volume + * @dev: device to open + * @flags: optional mount flags + * + * Load, verify, and parse bootsector; load and setup $MFT and $MFTMirr. After + * calling this function, the volume is setup sufficiently to call all read + * and write access functions provided by the library. + * + * Return the allocated volume structure on success and NULL on error with + * errno set to the error code. + */ +ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags) +{ + LCN mft_zone_size, mft_lcn; + s64 br; + ntfs_volume *vol; + NTFS_BOOT_SECTOR *bs; + int eo; + + if (!dev || !dev->d_ops || !dev->d_name) { + errno = EINVAL; + ntfs_log_perror("%s: dev = %p", __FUNCTION__, dev); + return NULL; + } + + bs = ntfs_malloc(sizeof(NTFS_BOOT_SECTOR)); + if (!bs) + return NULL; + + /* Allocate the volume structure. */ + vol = ntfs_volume_alloc(); + if (!vol) + goto error_exit; + + /* Create the default upcase table. */ + vol->upcase_len = 65536; + vol->upcase = ntfs_malloc(vol->upcase_len * sizeof(ntfschar)); + if (!vol->upcase) + goto error_exit; + + ntfs_upcase_table_build(vol->upcase, + vol->upcase_len * sizeof(ntfschar)); + /* Default with no locase table and case sensitive file names */ + vol->locase = (ntfschar*)NULL; + NVolSetCaseSensitive(vol); + + /* by default, all files are shown and not marked hidden */ + NVolSetShowSysFiles(vol); + NVolSetShowHidFiles(vol); + NVolClearHideDotFiles(vol); + if (flags & MS_RDONLY) + NVolSetReadOnly(vol); + + /* ...->open needs bracketing to compile with glibc 2.7 */ + if ((dev->d_ops->open)(dev, NVolReadOnly(vol) ? O_RDONLY: O_RDWR)) { + ntfs_log_perror("Error opening '%s'", dev->d_name); + goto error_exit; + } + /* Attach the device to the volume. */ + vol->dev = dev; + + /* Now read the bootsector. */ + br = ntfs_pread(dev, 0, sizeof(NTFS_BOOT_SECTOR), bs); + if (br != sizeof(NTFS_BOOT_SECTOR)) { + if (br != -1) + errno = EINVAL; + if (!br) + ntfs_log_error("Failed to read bootsector (size=0)\n"); + else + ntfs_log_perror("Error reading bootsector"); + goto error_exit; + } + if (!ntfs_boot_sector_is_ntfs(bs)) { + errno = EINVAL; + goto error_exit; + } + if (ntfs_boot_sector_parse(vol, bs) < 0) + goto error_exit; + + free(bs); + bs = NULL; + /* Now set the device block size to the sector size. */ + if (ntfs_device_block_size_set(vol->dev, vol->sector_size)) + ntfs_log_debug("Failed to set the device block size to the " + "sector size. This may affect performance " + "but should be harmless otherwise. Error: " + "%s\n", strerror(errno)); + + /* We now initialize the cluster allocator. */ + vol->full_zones = 0; + mft_zone_size = vol->nr_clusters >> 3; /* 12.5% */ + + /* Setup the mft zone. */ + vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; + ntfs_log_debug("mft_zone_pos = 0x%llx\n", (long long)vol->mft_zone_pos); + + /* + * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs + * source) and if the actual mft_lcn is in the expected place or even + * further to the front of the volume, extend the mft_zone to cover the + * beginning of the volume as well. This is in order to protect the + * area reserved for the mft bitmap as well within the mft_zone itself. + * On non-standard volumes we don't protect it as the overhead would be + * higher than the speed increase we would get by doing it. + */ + mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size; + if (mft_lcn * vol->cluster_size < 16 * 1024) + mft_lcn = (16 * 1024 + vol->cluster_size - 1) / + vol->cluster_size; + if (vol->mft_zone_start <= mft_lcn) + vol->mft_zone_start = 0; + ntfs_log_debug("mft_zone_start = 0x%llx\n", (long long)vol->mft_zone_start); + + /* + * Need to cap the mft zone on non-standard volumes so that it does + * not point outside the boundaries of the volume. We do this by + * halving the zone size until we are inside the volume. + */ + vol->mft_zone_end = vol->mft_lcn + mft_zone_size; + while (vol->mft_zone_end >= vol->nr_clusters) { + mft_zone_size >>= 1; + vol->mft_zone_end = vol->mft_lcn + mft_zone_size; + } + ntfs_log_debug("mft_zone_end = 0x%llx\n", (long long)vol->mft_zone_end); + + /* + * Set the current position within each data zone to the start of the + * respective zone. + */ + vol->data1_zone_pos = vol->mft_zone_end; + ntfs_log_debug("data1_zone_pos = %lld\n", (long long)vol->data1_zone_pos); + vol->data2_zone_pos = 0; + ntfs_log_debug("data2_zone_pos = %lld\n", (long long)vol->data2_zone_pos); + + /* Set the mft data allocation position to mft record 24. */ + vol->mft_data_pos = 24; + + /* + * The cluster allocator is now fully operational. + */ + + /* Need to setup $MFT so we can use the library read functions. */ + if (ntfs_mft_load(vol) < 0) { + ntfs_log_perror("Failed to load $MFT"); + goto error_exit; + } + + /* Need to setup $MFTMirr so we can use the write functions, too. */ + if (ntfs_mftmirr_load(vol) < 0) { + ntfs_log_perror("Failed to load $MFTMirr"); + goto error_exit; + } + return vol; +error_exit: + eo = errno; + free(bs); + if (vol) + __ntfs_volume_release(vol); + errno = eo; + return NULL; +} + +/** + * ntfs_volume_check_logfile - check logfile on target volume + * @vol: volume on which to check logfile + * + * Return 0 on success and -1 on error with errno set error code. + */ +static int ntfs_volume_check_logfile(ntfs_volume *vol) +{ + ntfs_inode *ni; + ntfs_attr *na = NULL; + RESTART_PAGE_HEADER *rp = NULL; + int err = 0; + + ni = ntfs_inode_open(vol, FILE_LogFile); + if (!ni) { + ntfs_log_perror("Failed to open inode FILE_LogFile"); + errno = EIO; + return -1; + } + + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); + if (!na) { + ntfs_log_perror("Failed to open $FILE_LogFile/$DATA"); + err = EIO; + goto out; + } + + if (!ntfs_check_logfile(na, &rp) || !ntfs_is_logfile_clean(na, rp)) + err = EOPNOTSUPP; + free(rp); + ntfs_attr_close(na); +out: + if (ntfs_inode_close(ni)) + ntfs_error_set(&err); + if (err) { + errno = err; + return -1; + } + return 0; +} + +/** + * ntfs_hiberfile_open - Find and open '/hiberfil.sys' + * @vol: An ntfs volume obtained from ntfs_mount + * + * Return: inode Success, hiberfil.sys is valid + * NULL hiberfil.sys doesn't exist or some other error occurred + */ +static ntfs_inode *ntfs_hiberfile_open(ntfs_volume *vol) +{ + u64 inode; + ntfs_inode *ni_root; + ntfs_inode *ni_hibr = NULL; + ntfschar *unicode = NULL; + int unicode_len; + const char *hiberfile = "hiberfil.sys"; + + if (!vol) { + errno = EINVAL; + return NULL; + } + + ni_root = ntfs_inode_open(vol, FILE_root); + if (!ni_root) { + ntfs_log_debug("Couldn't open the root directory.\n"); + return NULL; + } + + unicode_len = ntfs_mbstoucs(hiberfile, &unicode); + if (unicode_len < 0) { + ntfs_log_perror("Couldn't convert 'hiberfil.sys' to Unicode"); + goto out; + } + + inode = ntfs_inode_lookup_by_name(ni_root, unicode, unicode_len); + if (inode == (u64)-1) { + ntfs_log_debug("Couldn't find file '%s'.\n", hiberfile); + goto out; + } + + inode = MREF(inode); + ni_hibr = ntfs_inode_open(vol, inode); + if (!ni_hibr) { + ntfs_log_debug("Couldn't open inode %lld.\n", (long long)inode); + goto out; + } +out: + if (ntfs_inode_close(ni_root)) { + ntfs_inode_close(ni_hibr); + ni_hibr = NULL; + } + free(unicode); + return ni_hibr; +} + + +#define NTFS_HIBERFILE_HEADER_SIZE 4096 + +/** + * ntfs_volume_check_hiberfile - check hiberfil.sys whether Windows is + * hibernated on the target volume + * @vol: volume on which to check hiberfil.sys + * + * Return: 0 if Windows isn't hibernated for sure + * -1 otherwise and errno is set to the appropriate value + */ +int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose) +{ + ntfs_inode *ni; + ntfs_attr *na = NULL; + int bytes_read, err; + char *buf = NULL; + + ni = ntfs_hiberfile_open(vol); + if (!ni) { + if (errno == ENOENT) + return 0; + return -1; + } + + buf = ntfs_malloc(NTFS_HIBERFILE_HEADER_SIZE); + if (!buf) + goto out; + + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); + if (!na) { + ntfs_log_perror("Failed to open hiberfil.sys data attribute"); + goto out; + } + + bytes_read = ntfs_attr_pread(na, 0, NTFS_HIBERFILE_HEADER_SIZE, buf); + if (bytes_read == -1) { + ntfs_log_perror("Failed to read hiberfil.sys"); + goto out; + } + if (bytes_read < NTFS_HIBERFILE_HEADER_SIZE) { + if (verbose) + ntfs_log_error("Hibernated non-system partition, " + "refused to mount.\n"); + errno = EPERM; + goto out; + } + if (memcmp(buf, "hibr", 4) == 0) { + if (verbose) + ntfs_log_error("Windows is hibernated, refused to mount.\n"); + errno = EPERM; + goto out; + } + /* All right, all header bytes are zero */ + errno = 0; +out: + if (na) + ntfs_attr_close(na); + free(buf); + err = errno; + if (ntfs_inode_close(ni)) + ntfs_error_set(&err); + errno = err; + return errno ? -1 : 0; +} + +/* + * Make sure a LOGGED_UTILITY_STREAM attribute named "$TXF_DATA" + * on the root directory is resident. + * When it is non-resident, the partition cannot be mounted on Vista + * (see http://support.microsoft.com/kb/974729) + * + * We take care to avoid this situation, however this can be a + * consequence of having used an older version (including older + * Windows version), so we had better fix it. + * + * Returns 0 if unneeded or successful + * -1 if there was an error, explained by errno + */ + +static int fix_txf_data(ntfs_volume *vol) +{ + void *txf_data; + s64 txf_data_size; + ntfs_inode *ni; + ntfs_attr *na; + int res; + + res = 0; + ntfs_log_debug("Loading root directory\n"); + ni = ntfs_inode_open(vol, FILE_root); + if (!ni) { + ntfs_log_perror("Failed to open root directory"); + res = -1; + } else { + /* Get the $TXF_DATA attribute */ + na = ntfs_attr_open(ni, AT_LOGGED_UTILITY_STREAM, TXF_DATA, 9); + if (na) { + if (NAttrNonResident(na)) { + /* + * Fix the attribute by truncating, then + * rewriting it. + */ + ntfs_log_debug("Making $TXF_DATA resident\n"); + txf_data = ntfs_attr_readall(ni, + AT_LOGGED_UTILITY_STREAM, + TXF_DATA, 9, &txf_data_size); + if (txf_data) { + if (ntfs_attr_truncate(na, 0) + || (ntfs_attr_pwrite(na, 0, + txf_data_size, txf_data) + != txf_data_size)) + res = -1; + free(txf_data); + } + if (res) + ntfs_log_error("Failed to make $TXF_DATA resident\n"); + else + ntfs_log_error("$TXF_DATA made resident\n"); + } + ntfs_attr_close(na); + } + if (ntfs_inode_close(ni)) { + ntfs_log_perror("Failed to close root"); + res = -1; + } + } + return (res); +} + +/** + * ntfs_device_mount - open ntfs volume + * @dev: device to open + * @flags: optional mount flags + * + * This function mounts an ntfs volume. @dev should describe the device which + * to mount as the ntfs volume. + * + * @flags is an optional second parameter. The same flags are used as for + * the mount system call (man 2 mount). Currently only the following flag + * is implemented: + * MS_RDONLY - mount volume read-only + * + * The function opens the device @dev and verifies that it contains a valid + * bootsector. Then, it allocates an ntfs_volume structure and initializes + * some of the values inside the structure from the information stored in the + * bootsector. It proceeds to load the necessary system files and completes + * setting up the structure. + * + * Return the allocated volume structure on success and NULL on error with + * errno set to the error code. + */ +ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags) +{ + s64 l; + ntfs_volume *vol; + u8 *m = NULL, *m2 = NULL; + ntfs_attr_search_ctx *ctx = NULL; + ntfs_inode *ni; + ntfs_attr *na; + ATTR_RECORD *a; + VOLUME_INFORMATION *vinf; + ntfschar *vname; + int i, j, eo; + u32 u; + + vol = ntfs_volume_startup(dev, flags); + if (!vol) + return NULL; + + /* Load data from $MFT and $MFTMirr and compare the contents. */ + m = ntfs_malloc(vol->mftmirr_size << vol->mft_record_size_bits); + m2 = ntfs_malloc(vol->mftmirr_size << vol->mft_record_size_bits); + if (!m || !m2) + goto error_exit; + + l = ntfs_attr_mst_pread(vol->mft_na, 0, vol->mftmirr_size, + vol->mft_record_size, m); + if (l != vol->mftmirr_size) { + if (l == -1) + ntfs_log_perror("Failed to read $MFT"); + else { + ntfs_log_error("Failed to read $MFT, unexpected length " + "(%lld != %d).\n", (long long)l, + vol->mftmirr_size); + errno = EIO; + } + goto error_exit; + } + l = ntfs_attr_mst_pread(vol->mftmirr_na, 0, vol->mftmirr_size, + vol->mft_record_size, m2); + if (l != vol->mftmirr_size) { + if (l == -1) { + ntfs_log_perror("Failed to read $MFTMirr"); + goto error_exit; + } + vol->mftmirr_size = l; + } + ntfs_log_debug("Comparing $MFTMirr to $MFT...\n"); + for (i = 0; i < vol->mftmirr_size; ++i) { + MFT_RECORD *mrec, *mrec2; + const char *ESTR[12] = { "$MFT", "$MFTMirr", "$LogFile", + "$Volume", "$AttrDef", "root directory", "$Bitmap", + "$Boot", "$BadClus", "$Secure", "$UpCase", "$Extend" }; + const char *s; + + if (i < 12) + s = ESTR[i]; + else if (i < 16) + s = "system file"; + else + s = "mft record"; + + mrec = (MFT_RECORD*)(m + i * vol->mft_record_size); + if (mrec->flags & MFT_RECORD_IN_USE) { + if (ntfs_is_baad_recordp(mrec)) { + ntfs_log_error("$MFT error: Incomplete multi " + "sector transfer detected in " + "'%s'.\n", s); + goto io_error_exit; + } + if (!ntfs_is_mft_recordp(mrec)) { + ntfs_log_error("$MFT error: Invalid mft " + "record for '%s'.\n", s); + goto io_error_exit; + } + } + mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size); + if (mrec2->flags & MFT_RECORD_IN_USE) { + if (ntfs_is_baad_recordp(mrec2)) { + ntfs_log_error("$MFTMirr error: Incomplete " + "multi sector transfer " + "detected in '%s'.\n", s); + goto io_error_exit; + } + if (!ntfs_is_mft_recordp(mrec2)) { + ntfs_log_error("$MFTMirr error: Invalid mft " + "record for '%s'.\n", s); + goto io_error_exit; + } + } + if (memcmp(mrec, mrec2, ntfs_mft_record_get_data_size(mrec))) { + ntfs_log_error("$MFTMirr does not match $MFT (record " + "%d).\n", i); + goto io_error_exit; + } + } + + free(m2); + free(m); + m = m2 = NULL; + + /* Now load the bitmap from $Bitmap. */ + ntfs_log_debug("Loading $Bitmap...\n"); + vol->lcnbmp_ni = ntfs_inode_open(vol, FILE_Bitmap); + if (!vol->lcnbmp_ni) { + ntfs_log_perror("Failed to open inode FILE_Bitmap"); + goto error_exit; + } + + vol->lcnbmp_na = ntfs_attr_open(vol->lcnbmp_ni, AT_DATA, AT_UNNAMED, 0); + if (!vol->lcnbmp_na) { + ntfs_log_perror("Failed to open ntfs attribute"); + goto error_exit; + } + + if (vol->lcnbmp_na->data_size > vol->lcnbmp_na->allocated_size) { + ntfs_log_error("Corrupt cluster map size (%lld > %lld)\n", + (long long)vol->lcnbmp_na->data_size, + (long long)vol->lcnbmp_na->allocated_size); + goto io_error_exit; + } + + /* Now load the upcase table from $UpCase. */ + ntfs_log_debug("Loading $UpCase...\n"); + ni = ntfs_inode_open(vol, FILE_UpCase); + if (!ni) { + ntfs_log_perror("Failed to open inode FILE_UpCase"); + goto error_exit; + } + /* Get an ntfs attribute for $UpCase/$DATA. */ + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); + if (!na) { + ntfs_log_perror("Failed to open ntfs attribute"); + goto error_exit; + } + /* + * Note: Normally, the upcase table has a length equal to 65536 + * 2-byte Unicode characters but allow for different cases, so no + * checks done. Just check we don't overflow 32-bits worth of Unicode + * characters. + */ + if (na->data_size & ~0x1ffffffffULL) { + ntfs_log_error("Error: Upcase table is too big (max 32-bit " + "allowed).\n"); + errno = EINVAL; + goto error_exit; + } + if (vol->upcase_len != na->data_size >> 1) { + vol->upcase_len = na->data_size >> 1; + /* Throw away default table. */ + free(vol->upcase); + vol->upcase = ntfs_malloc(na->data_size); + if (!vol->upcase) + goto error_exit; + } + /* Read in the $DATA attribute value into the buffer. */ + l = ntfs_attr_pread(na, 0, na->data_size, vol->upcase); + if (l != na->data_size) { + ntfs_log_error("Failed to read $UpCase, unexpected length " + "(%lld != %lld).\n", (long long)l, + (long long)na->data_size); + errno = EIO; + goto error_exit; + } + /* Done with the $UpCase mft record. */ + ntfs_attr_close(na); + if (ntfs_inode_close(ni)) { + ntfs_log_perror("Failed to close $UpCase"); + goto error_exit; + } + + /* + * Now load $Volume and set the version information and flags in the + * vol structure accordingly. + */ + ntfs_log_debug("Loading $Volume...\n"); + vol->vol_ni = ntfs_inode_open(vol, FILE_Volume); + if (!vol->vol_ni) { + ntfs_log_perror("Failed to open inode FILE_Volume"); + goto error_exit; + } + /* Get a search context for the $Volume/$VOLUME_INFORMATION lookup. */ + ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); + if (!ctx) + goto error_exit; + + /* Find the $VOLUME_INFORMATION attribute. */ + if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, + 0, ctx)) { + ntfs_log_perror("$VOLUME_INFORMATION attribute not found in " + "$Volume"); + goto error_exit; + } + a = ctx->attr; + /* Has to be resident. */ + if (a->non_resident) { + ntfs_log_error("Attribute $VOLUME_INFORMATION must be " + "resident but it isn't.\n"); + errno = EIO; + goto error_exit; + } + /* Get a pointer to the value of the attribute. */ + vinf = (VOLUME_INFORMATION*)(le16_to_cpu(a->value_offset) + (char*)a); + /* Sanity checks. */ + if ((char*)vinf + le32_to_cpu(a->value_length) > (char*)ctx->mrec + + le32_to_cpu(ctx->mrec->bytes_in_use) || + le16_to_cpu(a->value_offset) + le32_to_cpu( + a->value_length) > le32_to_cpu(a->length)) { + ntfs_log_error("$VOLUME_INFORMATION in $Volume is corrupt.\n"); + errno = EIO; + goto error_exit; + } + /* Setup vol from the volume information attribute value. */ + vol->major_ver = vinf->major_ver; + vol->minor_ver = vinf->minor_ver; + /* Do not use le16_to_cpu() macro here as our VOLUME_FLAGS are + defined using cpu_to_le16() macro and hence are consistent. */ + vol->flags = vinf->flags; + /* + * Reinitialize the search context for the $Volume/$VOLUME_NAME lookup. + */ + ntfs_attr_reinit_search_ctx(ctx); + if (ntfs_attr_lookup(AT_VOLUME_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, + ctx)) { + if (errno != ENOENT) { + ntfs_log_perror("Failed to lookup of $VOLUME_NAME in " + "$Volume failed"); + goto error_exit; + } + /* + * Attribute not present. This has been seen in the field. + * Treat this the same way as if the attribute was present but + * had zero length. + */ + vol->vol_name = ntfs_malloc(1); + if (!vol->vol_name) + goto error_exit; + vol->vol_name[0] = '\0'; + } else { + a = ctx->attr; + /* Has to be resident. */ + if (a->non_resident) { + ntfs_log_error("$VOLUME_NAME must be resident.\n"); + errno = EIO; + goto error_exit; + } + /* Get a pointer to the value of the attribute. */ + vname = (ntfschar*)(le16_to_cpu(a->value_offset) + (char*)a); + u = le32_to_cpu(a->value_length) / 2; + /* + * Convert Unicode volume name to current locale multibyte + * format. + */ + vol->vol_name = NULL; + if (ntfs_ucstombs(vname, u, &vol->vol_name, 0) == -1) { + ntfs_log_perror("Volume name could not be converted " + "to current locale"); + ntfs_log_debug("Forcing name into ASCII by replacing " + "non-ASCII characters with underscores.\n"); + vol->vol_name = ntfs_malloc(u + 1); + if (!vol->vol_name) + goto error_exit; + + for (j = 0; j < (s32)u; j++) { + u16 uc = le16_to_cpu(vname[j]); + if (uc > 0xff) + uc = (u16)'_'; + vol->vol_name[j] = (char)uc; + } + vol->vol_name[u] = '\0'; + } + } + ntfs_attr_put_search_ctx(ctx); + ctx = NULL; + /* Now load the attribute definitions from $AttrDef. */ + ntfs_log_debug("Loading $AttrDef...\n"); + ni = ntfs_inode_open(vol, FILE_AttrDef); + if (!ni) { + ntfs_log_perror("Failed to open $AttrDef"); + goto error_exit; + } + /* Get an ntfs attribute for $AttrDef/$DATA. */ + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); + if (!na) { + ntfs_log_perror("Failed to open ntfs attribute"); + goto error_exit; + } + /* Check we don't overflow 32-bits. */ + if (na->data_size > 0xffffffffLL) { + ntfs_log_error("Attribute definition table is too big (max " + "32-bit allowed).\n"); + errno = EINVAL; + goto error_exit; + } + vol->attrdef_len = na->data_size; + vol->attrdef = ntfs_malloc(na->data_size); + if (!vol->attrdef) + goto error_exit; + /* Read in the $DATA attribute value into the buffer. */ + l = ntfs_attr_pread(na, 0, na->data_size, vol->attrdef); + if (l != na->data_size) { + ntfs_log_error("Failed to read $AttrDef, unexpected length " + "(%lld != %lld).\n", (long long)l, + (long long)na->data_size); + errno = EIO; + goto error_exit; + } + /* Done with the $AttrDef mft record. */ + ntfs_attr_close(na); + if (ntfs_inode_close(ni)) { + ntfs_log_perror("Failed to close $AttrDef"); + goto error_exit; + } + /* + * Check for dirty logfile and hibernated Windows. + * We care only about read-write mounts. + */ + if (!(flags & MS_RDONLY)) { + if (!(flags & MS_IGNORE_HIBERFILE) && + ntfs_volume_check_hiberfile(vol, 1) < 0) + goto error_exit; + if (ntfs_volume_check_logfile(vol) < 0) { + if (!(flags & MS_RECOVER)) + goto error_exit; + ntfs_log_info("The file system wasn't safely " + "closed on Windows. Fixing.\n"); + if (ntfs_logfile_reset(vol)) + goto error_exit; + } + } + /* make $TXF_DATA resident if present on the root directory */ + if (!NVolReadOnly(vol) && fix_txf_data(vol)) + goto error_exit; + + return vol; +io_error_exit: + errno = EIO; +error_exit: + eo = errno; + if (ctx) + ntfs_attr_put_search_ctx(ctx); + free(m); + free(m2); + __ntfs_volume_release(vol); + errno = eo; + return NULL; +} + +/* + * Set appropriate flags for showing NTFS metafiles + * or files marked as hidden. + * Not set in ntfs_mount() to avoid breaking existing tools. + */ + +int ntfs_set_shown_files(ntfs_volume *vol, + BOOL show_sys_files, BOOL show_hid_files, + BOOL hide_dot_files) +{ + int res; + + res = -1; + if (vol) { + NVolClearShowSysFiles(vol); + NVolClearShowHidFiles(vol); + NVolClearHideDotFiles(vol); + if (show_sys_files) + NVolSetShowSysFiles(vol); + if (show_hid_files) + NVolSetShowHidFiles(vol); + if (hide_dot_files) + NVolSetHideDotFiles(vol); + res = 0; + } + if (res) + ntfs_log_error("Failed to set file visibility\n"); + return (res); +} + +/* + * Set ignore case mode + */ + +int ntfs_set_ignore_case(ntfs_volume *vol) +{ + int res; + + res = -1; + if (vol && vol->upcase) { + vol->locase = ntfs_locase_table_build(vol->upcase, + vol->upcase_len); + if (vol->locase) { + NVolClearCaseSensitive(vol); + res = 0; + } + } + if (res) + ntfs_log_error("Failed to set ignore_case mode\n"); + return (res); +} + +/** + * ntfs_mount - open ntfs volume + * @name: name of device/file to open + * @flags: optional mount flags + * + * This function mounts an ntfs volume. @name should contain the name of the + * device/file to mount as the ntfs volume. + * + * @flags is an optional second parameter. The same flags are used as for + * the mount system call (man 2 mount). Currently only the following flags + * is implemented: + * MS_RDONLY - mount volume read-only + * + * The function opens the device or file @name and verifies that it contains a + * valid bootsector. Then, it allocates an ntfs_volume structure and initializes + * some of the values inside the structure from the information stored in the + * bootsector. It proceeds to load the necessary system files and completes + * setting up the structure. + * + * Return the allocated volume structure on success and NULL on error with + * errno set to the error code. + * + * Note, that a copy is made of @name, and hence it can be discarded as + * soon as the function returns. + */ +ntfs_volume *ntfs_mount(const char *name __attribute__((unused)), + unsigned long flags __attribute__((unused))) +{ +#ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS + struct ntfs_device *dev; + ntfs_volume *vol; + + /* Allocate an ntfs_device structure. */ + dev = ntfs_device_alloc(name, 0, &ntfs_device_default_io_ops, NULL); + if (!dev) + return NULL; + /* Call ntfs_device_mount() to do the actual mount. */ + vol = ntfs_device_mount(dev, flags); + if (!vol) { + int eo = errno; + ntfs_device_free(dev); + errno = eo; + } else + ntfs_create_lru_caches(vol); + return vol; +#else + /* + * ntfs_mount() makes no sense if NO_NTFS_DEVICE_DEFAULT_IO_OPS is + * defined as there are no device operations available in libntfs in + * this case. + */ + errno = EOPNOTSUPP; + return NULL; +#endif +} + +/** + * ntfs_umount - close ntfs volume + * @vol: address of ntfs_volume structure of volume to close + * @force: if true force close the volume even if it is busy + * + * Deallocate all structures (including @vol itself) associated with the ntfs + * volume @vol. + * + * Return 0 on success. On error return -1 with errno set appropriately + * (most likely to one of EAGAIN, EBUSY or EINVAL). The EAGAIN error means that + * an operation is in progress and if you try the close later the operation + * might be completed and the close succeed. + * + * If @force is true (i.e. not zero) this function will close the volume even + * if this means that data might be lost. + * + * @vol must have previously been returned by a call to ntfs_mount(). + * + * @vol itself is deallocated and should no longer be dereferenced after this + * function returns success. If it returns an error then nothing has been done + * so it is safe to continue using @vol. + */ +int ntfs_umount(ntfs_volume *vol, const BOOL force __attribute__((unused))) +{ + struct ntfs_device *dev; + int ret; + + if (!vol) { + errno = EINVAL; + return -1; + } + dev = vol->dev; + ret = __ntfs_volume_release(vol); + ntfs_device_free(dev); + return ret; +} + +#ifdef HAVE_MNTENT_H + +#ifndef HAVE_REALPATH +/** + * realpath - If there is no realpath on the system + */ +static char *realpath(const char *path, char *resolved_path) +{ + strncpy(resolved_path, path, PATH_MAX); + resolved_path[PATH_MAX] = '\0'; + return resolved_path; +} +#endif + +/** + * ntfs_mntent_check - desc + * + * If you are wanting to use this, you actually wanted to use + * ntfs_check_if_mounted(), you just didn't realize. (-: + * + * See description of ntfs_check_if_mounted(), below. + */ +static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags) +{ + struct mntent *mnt; + char *real_file = NULL, *real_fsname = NULL; + FILE *f; + int err = 0; + + real_file = ntfs_malloc(PATH_MAX + 1); + if (!real_file) + return -1; + real_fsname = ntfs_malloc(PATH_MAX + 1); + if (!real_fsname) { + err = errno; + goto exit; + } + if (!realpath(file, real_file)) { + err = errno; + goto exit; + } + if (!(f = setmntent(MOUNTED, "r"))) { + err = errno; + goto exit; + } + while ((mnt = getmntent(f))) { + if (!realpath(mnt->mnt_fsname, real_fsname)) + continue; + if (!strcmp(real_file, real_fsname)) + break; + } + endmntent(f); + if (!mnt) + goto exit; + *mnt_flags = NTFS_MF_MOUNTED; + if (!strcmp(mnt->mnt_dir, "/")) + *mnt_flags |= NTFS_MF_ISROOT; +#ifdef HAVE_HASMNTOPT + if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw")) + *mnt_flags |= NTFS_MF_READONLY; +#endif +exit: + free(real_file); + free(real_fsname); + if (err) { + errno = err; + return -1; + } + return 0; +} +#endif /* HAVE_MNTENT_H */ + +/** + * ntfs_check_if_mounted - check if an ntfs volume is currently mounted + * @file: device file to check + * @mnt_flags: pointer into which to return the ntfs mount flags (see volume.h) + * + * If the running system does not support the {set,get,end}mntent() calls, + * just return 0 and set *@mnt_flags to zero. + * + * When the system does support the calls, ntfs_check_if_mounted() first tries + * to find the device @file in /etc/mtab (or wherever this is kept on the + * running system). If it is not found, assume the device is not mounted and + * return 0 and set *@mnt_flags to zero. + * + * If the device @file is found, set the NTFS_MF_MOUNTED flags in *@mnt_flags. + * + * Further if @file is mounted as the file system root ("/"), set the flag + * NTFS_MF_ISROOT in *@mnt_flags. + * + * Finally, check if the file system is mounted read-only, and if so set the + * NTFS_MF_READONLY flag in *@mnt_flags. + * + * On success return 0 with *@mnt_flags set to the ntfs mount flags. + * + * On error return -1 with errno set to the error code. + */ +int ntfs_check_if_mounted(const char *file __attribute__((unused)), + unsigned long *mnt_flags) +{ + *mnt_flags = 0; +#ifdef HAVE_MNTENT_H + return ntfs_mntent_check(file, mnt_flags); +#else + return 0; +#endif +} + +/** + * ntfs_version_is_supported - check if NTFS version is supported. + * @vol: ntfs volume whose version we're interested in. + * + * The function checks if the NTFS volume version is known or not. + * Version 1.1 and 1.2 are used by Windows NT3.x and NT4. + * Version 2.x is used by Windows 2000 Betas. + * Version 3.0 is used by Windows 2000. + * Version 3.1 is used by Windows XP, Windows Server 2003 and Longhorn. + * + * Return 0 if NTFS version is supported otherwise -1 with errno set. + * + * The following error codes are defined: + * EOPNOTSUPP - Unknown NTFS version + * EINVAL - Invalid argument + */ +int ntfs_version_is_supported(ntfs_volume *vol) +{ + u8 major, minor; + + if (!vol) { + errno = EINVAL; + return -1; + } + + major = vol->major_ver; + minor = vol->minor_ver; + + if (NTFS_V1_1(major, minor) || NTFS_V1_2(major, minor)) + return 0; + + if (NTFS_V2_X(major, minor)) + return 0; + + if (NTFS_V3_0(major, minor) || NTFS_V3_1(major, minor)) + return 0; + + errno = EOPNOTSUPP; + return -1; +} + +/** + * ntfs_logfile_reset - "empty" $LogFile data attribute value + * @vol: ntfs volume whose $LogFile we intend to reset. + * + * Fill the value of the $LogFile data attribute, i.e. the contents of + * the file, with 0xff's, thus marking the journal as empty. + * + * FIXME(?): We might need to zero the LSN field of every single mft + * record as well. (But, first try without doing that and see what + * happens, since chkdsk might pickup the pieces and do it for us...) + * + * On success return 0. + * + * On error return -1 with errno set to the error code. + */ +int ntfs_logfile_reset(ntfs_volume *vol) +{ + ntfs_inode *ni; + ntfs_attr *na; + int eo; + + if (!vol) { + errno = EINVAL; + return -1; + } + + ni = ntfs_inode_open(vol, FILE_LogFile); + if (!ni) { + ntfs_log_perror("Failed to open inode FILE_LogFile"); + return -1; + } + + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); + if (!na) { + eo = errno; + ntfs_log_perror("Failed to open $FILE_LogFile/$DATA"); + goto error_exit; + } + + if (ntfs_empty_logfile(na)) { + eo = errno; + ntfs_attr_close(na); + goto error_exit; + } + + ntfs_attr_close(na); + return ntfs_inode_close(ni); + +error_exit: + ntfs_inode_close(ni); + errno = eo; + return -1; +} + +/** + * ntfs_volume_write_flags - set the flags of an ntfs volume + * @vol: ntfs volume where we set the volume flags + * @flags: new flags + * + * Set the on-disk volume flags in the mft record of $Volume and + * on volume @vol to @flags. + * + * Return 0 if successful and -1 if not with errno set to the error code. + */ +int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags) +{ + ATTR_RECORD *a; + VOLUME_INFORMATION *c; + ntfs_attr_search_ctx *ctx; + int ret = -1; /* failure */ + + if (!vol || !vol->vol_ni) { + errno = EINVAL; + return -1; + } + /* Get a pointer to the volume information attribute. */ + ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL); + if (!ctx) + return -1; + + if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, + 0, ctx)) { + ntfs_log_error("Attribute $VOLUME_INFORMATION was not found " + "in $Volume!\n"); + goto err_out; + } + a = ctx->attr; + /* Sanity check. */ + if (a->non_resident) { + ntfs_log_error("Attribute $VOLUME_INFORMATION must be resident " + "but it isn't.\n"); + errno = EIO; + goto err_out; + } + /* Get a pointer to the value of the attribute. */ + c = (VOLUME_INFORMATION*)(le16_to_cpu(a->value_offset) + (char*)a); + /* Sanity checks. */ + if ((char*)c + le32_to_cpu(a->value_length) > (char*)ctx->mrec + + le32_to_cpu(ctx->mrec->bytes_in_use) || + le16_to_cpu(a->value_offset) + + le32_to_cpu(a->value_length) > le32_to_cpu(a->length)) { + ntfs_log_error("Attribute $VOLUME_INFORMATION in $Volume is " + "corrupt!\n"); + errno = EIO; + goto err_out; + } + /* Set the volume flags. */ + vol->flags = c->flags = flags & VOLUME_FLAGS_MASK; + /* Write them to disk. */ + ntfs_inode_mark_dirty(vol->vol_ni); + if (ntfs_inode_sync(vol->vol_ni)) + goto err_out; + + ret = 0; /* success */ +err_out: + ntfs_attr_put_search_ctx(ctx); + return ret; +} + +int ntfs_volume_error(int err) +{ + int ret; + + switch (err) { + case 0: + ret = NTFS_VOLUME_OK; + break; + case EINVAL: + ret = NTFS_VOLUME_NOT_NTFS; + break; + case EIO: + ret = NTFS_VOLUME_CORRUPT; + break; + case EPERM: + ret = NTFS_VOLUME_HIBERNATED; + break; + case EOPNOTSUPP: + ret = NTFS_VOLUME_UNCLEAN_UNMOUNT; + break; + case EBUSY: + ret = NTFS_VOLUME_LOCKED; + break; + case ENXIO: + ret = NTFS_VOLUME_RAID; + break; + case EACCES: + ret = NTFS_VOLUME_NO_PRIVILEGE; + break; + default: + ret = NTFS_VOLUME_UNKNOWN_REASON; + break; + } + return ret; +} + + +void ntfs_mount_error(const char *volume, const char *mntpoint, int err) +{ + switch (err) { + case NTFS_VOLUME_NOT_NTFS: + ntfs_log_error(invalid_ntfs_msg, volume); + break; + case NTFS_VOLUME_CORRUPT: + ntfs_log_error("%s", corrupt_volume_msg); + break; + case NTFS_VOLUME_HIBERNATED: + ntfs_log_error(hibernated_volume_msg, volume, mntpoint); + break; + case NTFS_VOLUME_UNCLEAN_UNMOUNT: + ntfs_log_error("%s", unclean_journal_msg); + break; + case NTFS_VOLUME_LOCKED: + ntfs_log_error("%s", opened_volume_msg); + break; + case NTFS_VOLUME_RAID: + ntfs_log_error("%s", fakeraid_msg); + break; + case NTFS_VOLUME_NO_PRIVILEGE: + ntfs_log_error(access_denied_msg, volume); + break; + } +} + +int ntfs_set_locale(void) +{ + const char *locale; + + locale = setlocale(LC_ALL, ""); + if (!locale) { + locale = setlocale(LC_ALL, NULL); + ntfs_log_error("Couldn't set local environment, using default " + "'%s'.\n", locale); + return 1; + } + return 0; +} + +/* + * Feed the counts of free clusters and free mft records + */ + +int ntfs_volume_get_free_space(ntfs_volume *vol) +{ + ntfs_attr *na; + int ret; + + ret = -1; /* default return */ + vol->free_clusters = ntfs_attr_get_free_bits(vol->lcnbmp_na); + if (vol->free_clusters < 0) { + ntfs_log_perror("Failed to read NTFS $Bitmap"); + } else { + na = vol->mftbmp_na; + vol->free_mft_records = ntfs_attr_get_free_bits(na); + + if (vol->free_mft_records >= 0) + vol->free_mft_records += (na->allocated_size - na->data_size) << 3; + + if (vol->free_mft_records < 0) + ntfs_log_perror("Failed to calculate free MFT records"); + else + ret = 0; + } + return (ret); +} diff --git a/libcustomntfs/volume.h b/libcustomntfs/volume.h new file mode 100644 index 00000000..79193c53 --- /dev/null +++ b/libcustomntfs/volume.h @@ -0,0 +1,303 @@ +/* + * volume.h - Exports for NTFS volume handling. Originated from the Linux-NTFS project. + * + * Copyright (c) 2000-2004 Anton Altaparmakov + * Copyright (c) 2004-2005 Richard Russon + * Copyright (c) 2005-2006 Yura Pakhuchiy + * Copyright (c) 2005-2009 Szabolcs Szakacsits + * + * 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 + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the NTFS-3G + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_VOLUME_H +#define _NTFS_VOLUME_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_MNTENT_H +#include +#endif + +/* + * Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY, + * so we define them ourselves. + */ +#ifndef MS_RDONLY +#define MS_RDONLY 1 +#endif + +#define MS_EXCLUSIVE 0x08000000 + +#ifndef MS_RECOVER +#define MS_RECOVER 0x10000000 +#endif + +#define MS_IGNORE_HIBERFILE 0x20000000 + +/* Forward declaration */ +typedef struct _ntfs_volume ntfs_volume; + +#include "param.h" +#include "types.h" +#include "support.h" +#include "device.h" +#include "inode.h" +#include "attrib.h" +#include "index.h" + +/** + * enum ntfs_mount_flags - + * + * Flags returned by the ntfs_check_if_mounted() function. + */ +typedef enum { + NTFS_MF_MOUNTED = 1, /* Device is mounted. */ + NTFS_MF_ISROOT = 2, /* Device is mounted as system root. */ + NTFS_MF_READONLY = 4, /* Device is mounted read-only. */ +} ntfs_mount_flags; + +extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags); + +typedef enum { + NTFS_VOLUME_OK = 0, + NTFS_VOLUME_SYNTAX_ERROR = 11, + NTFS_VOLUME_NOT_NTFS = 12, + NTFS_VOLUME_CORRUPT = 13, + NTFS_VOLUME_HIBERNATED = 14, + NTFS_VOLUME_UNCLEAN_UNMOUNT = 15, + NTFS_VOLUME_LOCKED = 16, + NTFS_VOLUME_RAID = 17, + NTFS_VOLUME_UNKNOWN_REASON = 18, + NTFS_VOLUME_NO_PRIVILEGE = 19, + NTFS_VOLUME_OUT_OF_MEMORY = 20, + NTFS_VOLUME_FUSE_ERROR = 21, + NTFS_VOLUME_INSECURE = 22 +} ntfs_volume_status; + +/** + * enum ntfs_volume_state_bits - + * + * Defined bits for the state field in the ntfs_volume structure. + */ +typedef enum { + NV_ReadOnly, /* 1: Volume is read-only. */ + NV_CaseSensitive, /* 1: Volume is mounted case-sensitive. */ + NV_LogFileEmpty, /* 1: $logFile journal is empty. */ + NV_ShowSysFiles, /* 1: Show NTFS metafiles. */ + NV_ShowHidFiles, /* 1: Show files marked hidden. */ + NV_HideDotFiles, /* 1: Set hidden flag on dot files */ + NV_Compression, /* 1: allow compression */ +} ntfs_volume_state_bits; + +#define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state) +#define set_nvol_flag(nv, flag) set_bit(NV_##flag, (nv)->state) +#define clear_nvol_flag(nv, flag) clear_bit(NV_##flag, (nv)->state) + +#define NVolReadOnly(nv) test_nvol_flag(nv, ReadOnly) +#define NVolSetReadOnly(nv) set_nvol_flag(nv, ReadOnly) +#define NVolClearReadOnly(nv) clear_nvol_flag(nv, ReadOnly) + +#define NVolCaseSensitive(nv) test_nvol_flag(nv, CaseSensitive) +#define NVolSetCaseSensitive(nv) set_nvol_flag(nv, CaseSensitive) +#define NVolClearCaseSensitive(nv) clear_nvol_flag(nv, CaseSensitive) + +#define NVolLogFileEmpty(nv) test_nvol_flag(nv, LogFileEmpty) +#define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty) +#define NVolClearLogFileEmpty(nv) clear_nvol_flag(nv, LogFileEmpty) + +#define NVolShowSysFiles(nv) test_nvol_flag(nv, ShowSysFiles) +#define NVolSetShowSysFiles(nv) set_nvol_flag(nv, ShowSysFiles) +#define NVolClearShowSysFiles(nv) clear_nvol_flag(nv, ShowSysFiles) + +#define NVolShowHidFiles(nv) test_nvol_flag(nv, ShowHidFiles) +#define NVolSetShowHidFiles(nv) set_nvol_flag(nv, ShowHidFiles) +#define NVolClearShowHidFiles(nv) clear_nvol_flag(nv, ShowHidFiles) + +#define NVolHideDotFiles(nv) test_nvol_flag(nv, HideDotFiles) +#define NVolSetHideDotFiles(nv) set_nvol_flag(nv, HideDotFiles) +#define NVolClearHideDotFiles(nv) clear_nvol_flag(nv, HideDotFiles) + +#define NVolCompression(nv) test_nvol_flag(nv, Compression) +#define NVolSetCompression(nv) set_nvol_flag(nv, Compression) +#define NVolClearCompression(nv) clear_nvol_flag(nv, Compression) + +/* + * NTFS version 1.1 and 1.2 are used by Windows NT4. + * NTFS version 2.x is used by Windows 2000 Beta + * NTFS version 3.0 is used by Windows 2000. + * NTFS version 3.1 is used by Windows XP, 2003 and Vista. + */ + +#define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1) +#define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2) +#define NTFS_V2_X(major, minor) ((major) == 2) +#define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0) +#define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1) + +#define NTFS_BUF_SIZE 8192 + +/** + * struct _ntfs_volume - structure describing an open volume in memory. + */ +struct _ntfs_volume { + union { + struct ntfs_device *dev; /* NTFS device associated with + the volume. */ + void *sb; /* For kernel porting compatibility. */ + }; + char *vol_name; /* Name of the volume. */ + unsigned long state; /* NTFS specific flags describing this volume. + See ntfs_volume_state_bits above. */ + + ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */ + u8 major_ver; /* Ntfs major version of volume. */ + u8 minor_ver; /* Ntfs minor version of volume. */ + le16 flags; /* Bit array of VOLUME_* flags. */ + + u16 sector_size; /* Byte size of a sector. */ + u8 sector_size_bits; /* Log(2) of the byte size of a sector. */ + u32 cluster_size; /* Byte size of a cluster. */ + u32 mft_record_size; /* Byte size of a mft record. */ + u32 indx_record_size; /* Byte size of a INDX record. */ + u8 cluster_size_bits; /* Log(2) of the byte size of a cluster. */ + u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */ + u8 indx_record_size_bits;/* Log(2) of the byte size of a INDX record. */ + + /* Variables used by the cluster and mft allocators. */ + u8 mft_zone_multiplier; /* Initial mft zone multiplier. */ + u8 full_zones; /* cluster zones which are full */ + s64 mft_data_pos; /* Mft record number at which to allocate the + next mft record. */ + LCN mft_zone_start; /* First cluster of the mft zone. */ + LCN mft_zone_end; /* First cluster beyond the mft zone. */ + LCN mft_zone_pos; /* Current position in the mft zone. */ + LCN data1_zone_pos; /* Current position in the first data zone. */ + LCN data2_zone_pos; /* Current position in the second data zone. */ + + s64 nr_clusters; /* Volume size in clusters, hence also the + number of bits in lcn_bitmap. */ + ntfs_inode *lcnbmp_ni; /* ntfs_inode structure for FILE_Bitmap. */ + ntfs_attr *lcnbmp_na; /* ntfs_attr structure for the data attribute + of FILE_Bitmap. Each bit represents a + cluster on the volume, bit 0 representing + lcn 0 and so on. A set bit means that the + cluster and vice versa. */ + + LCN mft_lcn; /* Logical cluster number of the data attribute + for FILE_MFT. */ + ntfs_inode *mft_ni; /* ntfs_inode structure for FILE_MFT. */ + ntfs_attr *mft_na; /* ntfs_attr structure for the data attribute + of FILE_MFT. */ + ntfs_attr *mftbmp_na; /* ntfs_attr structure for the bitmap attribute + of FILE_MFT. Each bit represents an mft + record in the $DATA attribute, bit 0 + representing mft record 0 and so on. A set + bit means that the mft record is in use and + vice versa. */ + + ntfs_inode *secure_ni; /* ntfs_inode structure for FILE $Secure */ + ntfs_index_context *secure_xsii; /* index for using $Secure:$SII */ + ntfs_index_context *secure_xsdh; /* index for using $Secure:$SDH */ + int secure_reentry; /* check for non-rentries */ + unsigned int secure_flags; /* flags, see security.h for values */ + + int mftmirr_size; /* Size of the FILE_MFTMirr in mft records. */ + LCN mftmirr_lcn; /* Logical cluster number of the data attribute + for FILE_MFTMirr. */ + ntfs_inode *mftmirr_ni; /* ntfs_inode structure for FILE_MFTMirr. */ + ntfs_attr *mftmirr_na; /* ntfs_attr structure for the data attribute + of FILE_MFTMirr. */ + + ntfschar *upcase; /* Upper case equivalents of all 65536 2-byte + Unicode characters. Obtained from + FILE_UpCase. */ + u32 upcase_len; /* Length in Unicode characters of the upcase + table. */ + ntfschar *locase; /* Lower case equivalents of all 65536 2-byte + Unicode characters. Only if option + case_ignore is set. */ + + ATTR_DEF *attrdef; /* Attribute definitions. Obtained from + FILE_AttrDef. */ + s32 attrdef_len; /* Size of the attribute definition table in + bytes. */ + + s64 free_clusters; /* Track the number of free clusters which + greatly improves statfs() performance */ + s64 free_mft_records; /* Same for free mft records (see above) */ + BOOL efs_raw; /* volume is mounted for raw access to + efs-encrypted files */ + +#if CACHE_INODE_SIZE + struct CACHE_HEADER *xinode_cache; +#endif +#if CACHE_NIDATA_SIZE + struct CACHE_HEADER *nidata_cache; +#endif +#if CACHE_LOOKUP_SIZE + struct CACHE_HEADER *lookup_cache; +#endif +#if CACHE_SECURID_SIZE + struct CACHE_HEADER *securid_cache; +#endif +#if CACHE_LEGACY_SIZE + struct CACHE_HEADER *legacy_cache; +#endif + +}; + +extern const char *ntfs_home; + +extern ntfs_volume *ntfs_volume_alloc(void); + +extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, + unsigned long flags); + +extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, + unsigned long flags); + +extern ntfs_volume *ntfs_mount(const char *name, unsigned long flags); +extern int ntfs_umount(ntfs_volume *vol, const BOOL force); + +extern int ntfs_version_is_supported(ntfs_volume *vol); +extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose); +extern int ntfs_logfile_reset(ntfs_volume *vol); + +extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags); + +extern int ntfs_volume_error(int err); +extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err); + +extern int ntfs_volume_get_free_space(ntfs_volume *vol); + +extern int ntfs_set_shown_files(ntfs_volume *vol, + BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files); +extern int ntfs_set_locale(void); +extern int ntfs_set_ignore_case(ntfs_volume *vol); + +#endif /* defined _NTFS_VOLUME_H */ + diff --git a/source/FileOperations/DirList.cpp b/source/FileOperations/DirList.cpp deleted file mode 100644 index 14cd42bc..00000000 --- a/source/FileOperations/DirList.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * DirList Class - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include - -#include "utils/StringTools.h" -#include "DirList.h" - -DirList::DirList(const char * path, const char *filter, u32 flags) -{ - this->LoadPath(path, filter, flags); - this->SortList(); -} - -DirList::~DirList() -{ - ClearList(); -} - -bool DirList::LoadPath(const char * folder, const char *filter, u32 flags) -{ - if(!folder) - return false; - - struct stat st; - DIR_ITER *dir = NULL; - std::string folderpath = folder; - - if(folderpath[folderpath.size()-1] == '/') - folderpath.erase(folderpath.size()-1, 1); - - const char * notRoot = strchr(folderpath.c_str(), '/'); - if(!notRoot) - folderpath += '/'; - - dir = diropen(folderpath.c_str()); - if (dir == NULL) - return false; - - char * filename = new (std::nothrow) char[1024]; - if(!filename) - { - dirclose(dir); - return false; - } - - while (dirnext(dir,filename,&st) == 0) - { - if(st.st_mode & S_IFDIR) - { - if(!(flags & Dirs)) - continue; - - if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) - continue; - - if(flags & CheckSubfolders) - { - std::string newFolder = folderpath; - if(notRoot) newFolder += '/'; - newFolder += filename; - LoadPath(newFolder.c_str(), filter, flags); - } - } - else - { - if(!(flags & Files)) - continue; - } - - if(filter) - { - char * fileext = strrchr(filename, '.'); - if(!fileext) - continue; - - if(strtokcmp(fileext, filter, ",") == 0) - AddEntrie(folderpath.c_str(), filename, st.st_size, (st.st_mode & S_IFDIR) ? true : false); - } - else - { - AddEntrie(folderpath.c_str(), filename, st.st_size, (st.st_mode & S_IFDIR) ? true : false); - } - } - dirclose(dir); - delete [] filename; - - return true; -} - -void DirList::AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir) -{ - if(!folderpath || !filename) - return; - - int pos = FileInfo.size(); - - FileInfo.resize(pos+1); - - FileInfo[pos].FilePath = new (std::nothrow) char[strlen(folderpath)+strlen(filename)+2]; - if(FileInfo[pos].FilePath) - sprintf(FileInfo[pos].FilePath, "%s/%s", folderpath, filename); - FileInfo[pos].FileSize = filesize; - FileInfo[pos].isDir = isDir; -} - -void DirList::ClearList() -{ - for(u32 i = 0; i < FileInfo.size(); ++i) - { - if(FileInfo[i].FilePath) - delete [] FileInfo[i].FilePath; - } - - FileInfo.clear(); - std::vector().swap(FileInfo); -} - -const char * DirList::GetFilename(int ind) -{ - if (!valid(ind)) - return NULL; - - return FullpathToFilename(FileInfo[ind].FilePath); -} - -static bool SortCallback(const FileInfos & f1, const FileInfos & f2) -{ - if(f1.isDir && !(f2.isDir)) return true; - if(!(f1.isDir) && f2.isDir) return false; - - const char * Filename1 = FullpathToFilename(f1.FilePath); - const char * Filename2 = FullpathToFilename(f2.FilePath); - - if(Filename1 && !Filename2) return true; - if(!Filename1 && Filename2) return false; - - if(strcasecmp(Filename1, Filename2) > 0) - return false; - - return true; -} - -void DirList::SortList() -{ - std::sort(FileInfo.begin(), FileInfo.end(), SortCallback); -} - -int DirList::GetFileIndex(const char *filename) -{ - if(!filename) - return -1; - - for (u32 i = 0; i < FileInfo.size(); ++i) - { - if (strcasecmp(GetFilename(i), filename) == 0) - return i; - } - - return -1; -} diff --git a/source/FileOperations/DirList.h b/source/FileOperations/DirList.h deleted file mode 100644 index 5d2c6d08..00000000 --- a/source/FileOperations/DirList.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * DirList Class - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef ___DIRLIST_H_ -#define ___DIRLIST_H_ - -#include -#include - -typedef struct -{ - char * FilePath; - u64 FileSize; - bool isDir; -} FileInfos; - -class DirList -{ - public: - //!Constructor - //!\param path Path from where to load the filelist of all files - //!\param filter A fileext that needs to be filtered - //!\param flags search/filter flags from the enum - DirList(const char * path, const char *filter = NULL, u32 flags = Files | Dirs); - //!Destructor - ~DirList(); - //! Load all the files from a directory - bool LoadPath(const char * path, const char *filter = NULL, u32 flags = Files | Dirs); - //! Get a filename of the list - //!\param list index - const char * GetFilename(int index); - //! Get the a filepath of the list - //!\param list index - const char * GetFilepath(int index) { if(!valid(index)) return NULL; return FileInfo[index].FilePath; }; - //! Get the a filesize of the list - //!\param list index - u64 GetFilesize(int index) { if(!valid(index)) return 0; return FileInfo[index].FileSize; }; - //! Is index a dir or a file - //!\param list index - bool IsDir(int index) { if(!valid(index)) return 0; return FileInfo[index].isDir; }; - //! Get the filecount of the whole list - int GetFilecount() { return FileInfo.size(); }; - //! Sort list by filepath - void SortList(); - //! Get the index of the specified filename - int GetFileIndex(const char *filename); - //! Enum for search/filter flags - enum - { - Files = 0x01, - Dirs = 0x02, - CheckSubfolders = 0x08, - }; - protected: - //!Add a list entrie - void AddEntrie(const char * folderpath, const char * filename, u64 filesize, bool isDir); - //! Clear the list - void ClearList(); - //! Check if valid pos is requested - inline bool valid(int pos) { return (pos >= 0 && pos < (int) FileInfo.size()); }; - - std::vector FileInfo; -}; - -#endif diff --git a/source/FileOperations/File.cpp b/source/FileOperations/File.cpp deleted file mode 100644 index ce68add3..00000000 --- a/source/FileOperations/File.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include "File.hpp" - -CFile::CFile() -{ - file_fd = NULL; - mem_file = NULL; - filesize = 0; - Pos = 0; -} - -CFile::CFile(const char * filepath, const char * mode) -{ - file_fd = NULL; - open(filepath, mode); -} - -CFile::CFile(const u8 * mem, int size) -{ - file_fd = NULL; - open(mem, size); -} - -CFile::~CFile() -{ - close(); -} - -int CFile::open(const char * filepath, const char * mode) -{ - close(); - - file_fd = fopen(filepath, mode); - if(!file_fd) - return -1; - - fseek(file_fd, 0, SEEK_END); - filesize = ftell(file_fd); - rewind(); - - return 0; -} - -int CFile::open(const u8 * mem, int size) -{ - close(); - - mem_file = mem; - filesize = size; - - return 0; -} - -void CFile::close() -{ - if(file_fd) - fclose(file_fd); - - file_fd = NULL; - mem_file = NULL; - filesize = 0; - Pos = 0; -} - -int CFile::read(u8 * ptr, size_t size) -{ - if(file_fd) - { - int ret = fread(ptr, 1, size, file_fd); - if(ret > 0) - Pos += ret; - return ret; - } - - int readsize = size; - - if(readsize > (long int) filesize-Pos) - readsize = filesize-Pos; - - if(readsize <= 0) - return readsize; - - if(mem_file != NULL) - { - memcpy(ptr, mem_file+Pos, readsize); - Pos += readsize; - return readsize; - } - - return -1; -} - -int CFile::write(const u8 * ptr, size_t size) -{ - if(size < 0) - return size; - - if(file_fd) - { - int ret = fwrite(ptr, 1, size, file_fd); - if(ret > 0) - Pos += ret; - return ret; - } - - return -1; -} - -int CFile::seek(long int offset, int origin) -{ - int ret = 0; - - if(origin == SEEK_SET) - { - Pos = offset; - } - else if(origin == SEEK_CUR) - { - Pos += offset; - } - else if(origin == SEEK_END) - { - Pos = filesize+offset; - } - if(Pos < 0) - { - Pos = 0; - return -1; - } - - if(file_fd) - ret = fseek(file_fd, Pos, SEEK_SET); - - if(mem_file != NULL) - { - if(Pos > (long int) filesize) - { - Pos = filesize; - return -1; - } - } - - return ret; -} - diff --git a/source/FileOperations/File.hpp b/source/FileOperations/File.hpp deleted file mode 100644 index b5e1af75..00000000 --- a/source/FileOperations/File.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef FILE_HPP_ -#define FILE_HPP_ - -#include -#include - -class CFile -{ - public: - CFile(); - CFile(const char * filepath, const char * mode); - CFile(const u8 * memory, int memsize); - ~CFile(); - int open(const char * filepath, const char * mode); - int open(const u8 * memory, int memsize); - void close(); - int read(u8 * ptr, size_t size); - int write(const u8 * ptr, size_t size); - int seek(long int offset, int origin); - long int tell() { return Pos; }; - long int size() { return filesize; }; - void rewind() { seek(0, SEEK_SET); }; - protected: - FILE * file_fd; - const u8 * mem_file; - u64 filesize; - long int Pos; -}; - -#endif diff --git a/source/FileOperations/fileops.cpp b/source/FileOperations/fileops.cpp deleted file mode 100644 index 1b135c04..00000000 --- a/source/FileOperations/fileops.cpp +++ /dev/null @@ -1,913 +0,0 @@ - /*************************************************************************** - * Copyright (C) 2009 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * fileops.cpp - * File operations for the WiiXplorer - * Handling all the needed file operations - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fileops.h" - -#define BLOCKSIZE 70*1024 //70KB -#define VectorResize(List) if(List.capacity()-List.size() == 0) List.reserve(List.size()+100) - - -static bool actioncanceled = false; - -/**************************************************************************** - * FindFile - * - * Check if file is available in the given directory - ***************************************************************************/ -extern "C" bool FindFile(const char * filename, const char * path) -{ - if(!filename || ! path) - return false; - - DIR_ITER *dir = NULL; - struct stat st; - char currfilename[MAXPATHLEN]; - - dir = diropen(path); - if(!dir) - { - dirclose(dir); - return false; - } - - while (dirnext(dir,currfilename,&st) == 0) - { - if (strcasecmp(currfilename, filename) == 0) - { - dirclose(dir); - return true; - } - } - dirclose(dir); - return false; -} - -/**************************************************************************** - * SearchFile - * - * Search for a file recursive through all subdirectories - ***************************************************************************/ -extern "C" bool SearchFile(const char * searchpath, const char * searched_filename, char * outfilepath) -{ - struct stat st; - DIR_ITER *dir = NULL; - bool result = false; - - char filename[MAXPATHLEN]; - char pathptr[strlen(searchpath)+2]; - snprintf(pathptr, sizeof(pathptr), "%s", searchpath); - - if(pathptr[strlen(pathptr)-1] == '/') - { - pathptr[strlen(pathptr)-1] = '\0'; - } - - char * notRoot = strrchr(pathptr, '/'); - if(!notRoot) - { - strcat(pathptr, "/"); - } - - dir = diropen(pathptr); - if(!dir) - return false; - - while (dirnext(dir,filename,&st) == 0 && result == false) - { - if(strcasecmp(filename, searched_filename) == 0) - { - if(outfilepath) - { - sprintf(outfilepath, "%s/%s", pathptr, filename); - } - result = true; - } - else if((st.st_mode & S_IFDIR) != 0) - { - if(strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) - { - char newpath[1024]; - snprintf(newpath, sizeof(newpath), "%s/%s", pathptr, filename); - result = SearchFile(newpath, searched_filename, outfilepath); - } - } - } - dirclose(dir); - - return result; -} - -/**************************************************************************** - * CheckFile - * - * Check if file is existing - ***************************************************************************/ -extern "C" bool CheckFile(const char * filepath) -{ - if(!filepath) - return false; - - struct stat filestat; - - char dirnoslash[strlen(filepath)+2]; - snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); - - if(dirnoslash[strlen(dirnoslash)-1] == '/') - dirnoslash[strlen(dirnoslash)-1] = '\0'; - - char * notRoot = strrchr(dirnoslash, '/'); - if(!notRoot) - { - strcat(dirnoslash, "/"); - } - - if (stat(dirnoslash, &filestat) == 0) - return true; - - return false; -} - -/**************************************************************************** - * FileSize - * - * Get filesize in bytes. u64 for files bigger than 4GB - ***************************************************************************/ -extern "C" u64 FileSize(const char * filepath) -{ - struct stat filestat; - - if (stat(filepath, &filestat) != 0) - return 0; - - return filestat.st_size; -} - -/**************************************************************************** - * LoadFileToMem - * - * Load up the file into a block of memory - ***************************************************************************/ -extern "C" int LoadFileToMem(const char *filepath, u8 **inbuffer, u64 *size) -{ - int ret = -1; - u64 filesize = FileSize(filepath); - char * filename = strrchr(filepath, '/'); - if(filename) - filename++; - - *inbuffer = NULL; - *size = 0; - - FILE *file = fopen(filepath, "rb"); - - if (file == NULL) - return -1; - - u8 *buffer = (u8 *) malloc(filesize); - if (buffer == NULL) - { - fclose(file); - return -2; - } - - u64 done = 0; - u32 blocksize = BLOCKSIZE; - - do - { - if(actioncanceled) - { - free(buffer); - fclose(file); - return -10; - } - - if(blocksize > filesize-done) - blocksize = filesize-done; - - ret = fread(buffer+done, 1, blocksize, file); - if(ret < 0) - { - free(buffer); - fclose(file); - return -3; - } - else if(ret == 0) - { - //we are done - break; - } - - done += ret; - - } - while(done < filesize); - - fclose(file); - - if (done != filesize) - { - free(buffer); - return -3; - } - - *inbuffer = buffer; - *size = filesize; - - return 1; -} - -/**************************************************************************** - * LoadFileToMemWithProgress - * - * Load up the file into a block of memory, while showing a progress dialog - ***************************************************************************/ -extern "C" int LoadFileToMemWithProgress(const char *progressText, const char *filepath, u8 **inbuffer, u64 *size) -{ - - int ret = LoadFileToMem(filepath, inbuffer, size); - - return ret; -} - -/**************************************************************************** - * CreateSubfolder - * - * Create recursive all subfolders to the given path - ***************************************************************************/ -extern "C" bool CreateSubfolder(const char * fullpath) -{ - if(!fullpath) - return false; - - bool result = false; - - char dirnoslash[strlen(fullpath)+1]; - strcpy(dirnoslash, fullpath); - - int pos = strlen(dirnoslash)-1; - while(dirnoslash[pos] == '/') - { - dirnoslash[pos] = '\0'; - pos--; - } - - if(CheckFile(dirnoslash)) - { - return true; - } - else - { - char parentpath[strlen(dirnoslash)+2]; - strcpy(parentpath, dirnoslash); - char * ptr = strrchr(parentpath, '/'); - - if(!ptr) - { - //!Device root directory (must be with '/') - strcat(parentpath, "/"); - struct stat filestat; - if (stat(parentpath, &filestat) == 0) - return true; - - return false; - } - - ptr++; - ptr[0] = '\0'; - - result = CreateSubfolder(parentpath); - } - - if(!result) - return false; - - if (mkdir(dirnoslash, 0777) == -1) - { - return false; - } - - return true; -} - -/**************************************************************************** - * CompareDevices - * - * Compare if its the devices are equal - ***************************************************************************/ -static bool CompareDevices(const char *src, const char *dest) -{ - if(!src || !dest) - return false; - - char *device1 = strchr(src, ':'); - char *device2 = strchr(dest, ':'); - - if(!device1 || !device2) - return false; - - int position1 = device1-src+1; - int position2 = device2-dest+1; - - char temp1[50]; - char temp2[50]; - - snprintf(temp1, position1, "%s", src); - snprintf(temp2, position2, "%s", dest); - - if(strcasecmp(temp1, temp2) == 0) - return true; - - return false; -} - -/**************************************************************************** - * CopyFile - * - * Copy the file from source filepath to destination filepath - ***************************************************************************/ -extern "C" int CopyFile(const char * src, const char * dest) -{ - u32 read = 1; - u32 wrote = 1; - - char * filename = strrchr(src, '/'); - if(filename) - filename++; - else - return -1; - - u64 sizesrc = FileSize(src); - - FILE * source = fopen(src, "rb"); - - if(!source) - return -2; - - u32 blksize = BLOCKSIZE; - - u8 * buffer = (u8 *) malloc(blksize); - - if(buffer == NULL){ - //no memory - fclose(source); - return -1; - } - - FILE * destination = fopen(dest, "wb"); - - if(destination == NULL) - { - free(buffer); - fclose(source); - return -3; - } - - u64 done = 0; - - do - { - if(actioncanceled) - { - fclose(source); - fclose(destination); - free(buffer); - RemoveFile((char *) dest); - return -10; - } - - if(blksize > sizesrc - done) - blksize = sizesrc - done; - - //Display progress - read = fread(buffer, 1, blksize, source); - if(read < 0) - { - fclose(source); - fclose(destination); - free(buffer); - RemoveFile((char *) dest); - return -3; - } - - wrote = fwrite(buffer, 1, read, destination); - if(wrote < 0) - { - fclose(source); - fclose(destination); - free(buffer); - RemoveFile((char *) dest); - return -3; - } - - done += wrote; - } - while (read > 0); - - free(buffer); - fclose(source); - fclose(destination); - - if(sizesrc != done) - return -4; - - return 1; -} - -/**************************************************************************** -* ClearList -* -* Clearing a vector list -****************************************************************************/ -static inline void ClearList(std::vector &List) -{ - for(u32 i = 0; i < List.size(); ++i) - { - if(List[i]) - free(List[i]); - List[i] = NULL; - } - List.clear(); - std::vector().swap(List); -} - -/**************************************************************************** - * CopyDirectory - * - * Copy recursive a complete source path to destination path - ***************************************************************************/ -extern "C" int CopyDirectory(const char * src, const char * dest) -{ - struct stat st; - DIR_ITER *dir = NULL; - - dir = diropen(src); - if(dir == NULL) - return -1; - - char *filename = (char *) malloc(MAXPATHLEN); - if(!filename) - { - dirclose(dir); - return -2; - } - - std::vector DirList; - std::vector FileList; - - while (dirnext(dir,filename,&st) == 0) - { - if(actioncanceled) - { - free(filename); - ClearList(DirList); - ClearList(FileList); - dirclose(dir); - return -10; - } - - if(st.st_mode & S_IFDIR) - { - if(strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) - { - VectorResize(DirList); - DirList.push_back(strdup(filename)); - } - } - else - { - VectorResize(FileList); - FileList.push_back(strdup(filename)); - } - } - dirclose(dir); - free(filename); - filename = NULL; - - //! Ensure that empty directories are created - CreateSubfolder(dest); - - for(u32 i = 0; i < FileList.size(); ++i) - { - if(actioncanceled) - { - ClearList(DirList); - ClearList(FileList); - return -10; - } - - if(FileList[i]) - { - u32 strsize = strlen(src)+strlen(FileList[i])+1; - char currentname[strsize]; - char destname[strsize]; - sprintf(currentname, "%s%s", src, FileList[i]); - sprintf(destname, "%s%s", dest, FileList[i]); - free(FileList[i]); - FileList[i] = NULL; - CopyFile(currentname, destname); - } - } - - FileList.clear(); - ClearList(FileList); - - for(u32 i = 0; i < DirList.size(); ++i) - { - if(actioncanceled) - { - ClearList(DirList); - ClearList(FileList); - return -10; - } - - if(DirList[i]) - { - u32 strsize = strlen(src)+strlen(DirList[i])+2; - char currentname[strsize]; - char destname[strsize]; - sprintf(currentname, "%s%s/", src, DirList[i]); - sprintf(destname, "%s%s/", dest, DirList[i]); - free(DirList[i]); - DirList[i] = NULL; - CopyDirectory(currentname, destname); - } - } - - DirList.clear(); - ClearList(DirList); - - if(actioncanceled) - return -10; - - return 1; -} - -/**************************************************************************** - * MoveDirectory - * - * Move recursive a complete source path to destination path - ***************************************************************************/ -extern "C" int MoveDirectory(char * src, const char * dest) -{ - struct stat st; - DIR_ITER *dir = NULL; - - dir = diropen(src); - if(dir == NULL) - return -1; - - char *filename = (char *) malloc(MAXPATHLEN); - - if(!filename) - { - dirclose(dir); - return -2; - } - - std::vector DirList; - std::vector FileList; - - while (dirnext(dir,filename,&st) == 0) - { - if(actioncanceled) - { - free(filename); - ClearList(DirList); - ClearList(FileList); - dirclose(dir); - return -10; - } - - if(st.st_mode & S_IFDIR) - { - if(strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) - { - VectorResize(DirList); - DirList.push_back(strdup(filename)); - } - } - else - { - VectorResize(FileList); - FileList.push_back(strdup(filename)); - } - } - dirclose(dir); - free(filename); - filename = NULL; - - //! Ensure that empty directories are created - CreateSubfolder(dest); - - for(u32 i = 0; i < FileList.size(); ++i) - { - if(actioncanceled) - { - ClearList(DirList); - ClearList(FileList); - return -10; - } - - if(FileList[i]) - { - u32 strsize = strlen(src)+strlen(FileList[i])+2; - char currentname[strsize]; - char destname[strsize]; - sprintf(currentname, "%s%s", src, FileList[i]); - sprintf(destname, "%s%s", dest, FileList[i]); - - MoveFile(currentname, destname); - - free(FileList[i]); - FileList[i] = NULL; - } - } - - FileList.clear(); - ClearList(FileList); - - for(u32 i = 0; i < DirList.size(); ++i) - { - if(actioncanceled) - { - ClearList(DirList); - ClearList(FileList); - return -10; - } - - if(DirList[i]) - { - u32 strsize = strlen(src)+strlen(DirList[i])+2; - char currentname[strsize]; - char destname[strsize]; - sprintf(currentname, "%s%s/", src, DirList[i]); - sprintf(destname, "%s%s/", dest, DirList[i]); - free(DirList[i]); - DirList[i] = NULL; - - MoveDirectory(currentname, destname); - } - } - - DirList.clear(); - ClearList(DirList); - - src[strlen(src)-1] = '\0'; - - if(actioncanceled) - return -10; - - if(remove(src) != 0) - return -1; - - return 1; -} - -/**************************************************************************** - * MoveFile - * - * Move a file from srcpath to destdir - ***************************************************************************/ -extern "C" int MoveFile(const char *srcpath, char *destdir) -{ - if(CompareDevices(srcpath, destdir)) - { - if(RenameFile(srcpath, destdir)) - return 1; - else - return -1; - } - - int res = CopyFile(srcpath, destdir); - if(res < 0) - return -1; - - if(RemoveFile(srcpath)) - return 1; - - return -1; -} - -/**************************************************************************** - * RemoveDirectory - * - * Remove a directory and its content recursively - ***************************************************************************/ -extern "C" int RemoveDirectory(char * dirpath) -{ - struct stat st; - DIR_ITER *dir = NULL; - - dir = diropen(dirpath); - if(dir == NULL) - return -1; - - char * filename = (char *) malloc(MAXPATHLEN); - - if(!filename) - { - dirclose(dir); - return -2; - } - - std::vector DirList; - std::vector FileList; - - while (dirnext(dir,filename,&st) == 0) - { - if(actioncanceled) - { - free(filename); - ClearList(DirList); - ClearList(FileList); - dirclose(dir); - return -10; - } - - if(st.st_mode & S_IFDIR) - { - if(strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) - { - VectorResize(DirList); - DirList.push_back(strdup(filename)); - } - } - else - { - VectorResize(FileList); - FileList.push_back(strdup(filename)); - } - } - dirclose(dir); - free(filename); - filename = NULL; - - for(u32 i = 0; i < FileList.size(); ++i) - { - if(actioncanceled) - { - ClearList(DirList); - ClearList(FileList); - return -10; - } - - if(FileList[i]) - { - u32 strsize = strlen(dirpath)+strlen(FileList[i])+2; - char fullpath[strsize]; - sprintf(fullpath, "%s%s", dirpath, FileList[i]); - RemoveFile(fullpath); - - //!Display Throbber rotating - free(FileList[i]); - FileList[i] = NULL; - } - } - FileList.clear(); - ClearList(FileList); - - for(u32 i = 0; i < DirList.size(); ++i) - { - if(actioncanceled) - { - ClearList(DirList); - ClearList(FileList); - return -10; - } - if(DirList[i]) - { - char fullpath[strlen(dirpath)+strlen(DirList[i])+2]; - sprintf(fullpath, "%s%s/", dirpath, DirList[i]); - free(DirList[i]); - DirList[i] = NULL; - - RemoveDirectory(fullpath); - } - } - DirList.clear(); - ClearList(DirList); - - dirpath[strlen(dirpath)-1] = '\0'; - - if(actioncanceled) - return -10; - - if(remove(dirpath) != 0) - return -1; - - return 1; -} - -/**************************************************************************** - * RemoveFile - * - * Delete the file from a given filepath - ***************************************************************************/ -extern "C" bool RemoveFile(const char * filepath) -{ - return (remove(filepath) == 0); -} - -/**************************************************************************** - * RenameFile - * - * Rename the file from a given srcpath to a given destpath - ***************************************************************************/ -extern "C" bool RenameFile(const char * srcpath, const char * destpath) -{ - return (rename(srcpath, destpath) == 0); -} - -/**************************************************************************** - * GetFolderSize - * - * Get recursivly complete foldersize - ***************************************************************************/ -extern "C" void GetFolderSize(const char * folderpath, u64 * foldersize, u32 * filecount) -{ - struct stat st; - DIR_ITER *dir = diropen(folderpath); - - if(dir == NULL) - return; - - char *filename = (char *) malloc(MAXPATHLEN); - - if(!filename) - { - dirclose(dir); - return; - } - - std::vector DirList; - - while (dirnext(dir,filename,&st) == 0) - { - if(st.st_mode & S_IFDIR) - { - if(strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) - { - VectorResize(DirList); - DirList.push_back(strdup(filename)); - } - } - else - { - if(filecount) *filecount += 1; - if(foldersize) *foldersize += st.st_size; - } - } - dirclose(dir); - free(filename); - filename = NULL; - - for(u32 i = 0; i < DirList.size(); ++i) - { - if(DirList[i]) - { - char currentname[strlen(folderpath)+strlen(DirList[i])+2]; - sprintf(currentname, "%s%s/", folderpath, DirList[i]); - free(DirList[i]); - DirList[i] = NULL; - - GetFolderSize(currentname, foldersize, filecount); - } - } - DirList.clear(); - ClearList(DirList); -} diff --git a/source/FileOperations/fileops.h b/source/FileOperations/fileops.h deleted file mode 100644 index 6f16d88e..00000000 --- a/source/FileOperations/fileops.h +++ /dev/null @@ -1,57 +0,0 @@ - /*************************************************************************** - * Copyright (C) 2009 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * fileops.h - * File operations for the WiiXplorer - * Handling all the needed file operations - ***************************************************************************/ -#ifndef _FILEOPS_H_ -#define _FILEOPS_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -bool CreateSubfolder(const char * fullpath); -bool FindFile(const char * filename, const char * path); -bool SearchFile(const char * searchpath, const char * searched_filename, char * outfilepath); -bool CheckFile(const char * filepath); -u64 FileSize(const char * filepath); -int LoadFileToMem(const char * filepath, u8 **buffer, u64 *size); -int LoadFileToMemWithProgress(const char *progressText, const char *filePath, u8 **buffer, u64 *size); -int CopyFile(const char * src, const char * dest); -int CopyDirectory(const char * src, const char * dest); -int MoveDirectory(char * src, const char * dest); -int MoveFile(const char *srcpath, char *destdir); -int RemoveDirectory(char * dirpath); -bool RenameFile(const char * srcpath, const char * destpath); -bool RemoveFile(const char * filepath); -void GetFolderSize(const char * folderpath, u64 * foldersize, u32 * filenumber); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/FontSystem.cpp b/source/FontSystem.cpp deleted file mode 100644 index 74ede3a1..00000000 --- a/source/FontSystem.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include "FreeTypeGX.h" -#include "filelist.h" - -FreeTypeGX * fontSystem = NULL; -static FT_Byte * MainFont = (FT_Byte *) font_ttf; -static u32 MainFontSize = font_ttf_size; - -void ClearFontData() -{ - if (fontSystem) delete fontSystem; - fontSystem = NULL; - - if (MainFont != (FT_Byte *) font_ttf) - { - if (MainFont != NULL) delete[] MainFont; - MainFont = (FT_Byte *) font_ttf; - MainFontSize = font_ttf_size; - } -} - -bool SetupDefaultFont(const char *path) -{ - bool result = false; - FILE *pfile = NULL; - char FontPath[300]; - - ClearFontData(); - - snprintf(FontPath, sizeof(FontPath), "%sfont.ttf", path); - - pfile = fopen(FontPath, "rb"); - - if (pfile) - { - fseek(pfile, 0, SEEK_END); - MainFontSize = ftell(pfile); - rewind(pfile); - - MainFont = new (std::nothrow) FT_Byte[MainFontSize]; - if (!MainFont) - { - MainFont = (FT_Byte *) font_ttf; - MainFontSize = font_ttf_size; - } - else - { - fread(MainFont, 1, MainFontSize, pfile); - result = true; - } - fclose(pfile); - } - - fontSystem = new FreeTypeGX(MainFont, MainFontSize); - - return result; -} diff --git a/source/FontSystem.h b/source/FontSystem.h deleted file mode 100644 index e68b43a9..00000000 --- a/source/FontSystem.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef FONTSYSTEM_H_ -#define FONTSYSTEM_H_ - -bool SetupDefaultFont(const char *path); -void ClearFontData(); - -#endif diff --git a/source/FreeTypeGX.cpp b/source/FreeTypeGX.cpp deleted file mode 100644 index 6dd2a95a..00000000 --- a/source/FreeTypeGX.cpp +++ /dev/null @@ -1,596 +0,0 @@ -/* - * FreeTypeGX is a wrapper class for libFreeType which renders a compiled - * FreeType parsable font into a GX texture for Wii homebrew development. - * Copyright (C) 2008 Armin Tamzarian - * Modified by Dimok, 2010 - * - * This file is part of FreeTypeGX. - * - * FreeTypeGX is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * FreeTypeGX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with FreeTypeGX. If not, see . - */ - -#include "FreeTypeGX.h" - -using namespace std; - -/** - * Convert a short char string to a wide char string. - * - * This routine converts a supplied short character string into a wide character string. - * Note that it is the user's responsibility to clear the returned buffer once it is no longer needed. - * - * @param strChar Character string to be converted. - * @return Wide character representation of supplied character string. - */ - -wchar_t* charToWideChar(const char* strChar) -{ - if (!strChar) return NULL; - - wchar_t *strWChar = new (std::nothrow) wchar_t[strlen(strChar) + 1]; - if (!strWChar) return NULL; - - int bt = mbstowcs(strWChar, strChar, strlen(strChar)); - if (bt > 0) - { - strWChar[bt] = 0; - return strWChar; - } - - wchar_t *tempDest = strWChar; - while ((*tempDest++ = *strChar++)) - ; - - return strWChar; -} - -/** - * Default constructor for the FreeTypeGX class for WiiXplorer. - */ -FreeTypeGX::FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize) -{ - ftPointSize = 0; - - FT_Init_FreeType(&ftLibrary); - FT_New_Memory_Face(ftLibrary, (FT_Byte *) fontBuffer, bufferSize, 0, &ftFace); - - setVertexFormat(GX_VTXFMT1); - ftKerningEnabled = FT_HAS_KERNING( ftFace ); -} - -/** - * Default destructor for the FreeTypeGX class. - */ -FreeTypeGX::~FreeTypeGX() -{ - unloadFont(); - FT_Done_Face(ftFace); - FT_Done_FreeType(ftLibrary); -} - -/** - * Setup the vertex attribute formats for the glyph textures. - * - * This function sets up the vertex format for the glyph texture on the specified vertex format index. - * Note that this function should not need to be called except if the vertex formats are cleared or the specified - * vertex format index is modified. - * - * @param vertexIndex Vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. - */ -void FreeTypeGX::setVertexFormat(uint8_t vertexInd) -{ - vertexIndex = vertexInd; - GX_SetVtxAttrFmt(vertexIndex, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); - GX_SetVtxAttrFmt(vertexIndex, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); - GX_SetVtxAttrFmt(vertexIndex, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); -} - -/** - * Clears all loaded font glyph data. - * - * This routine clears all members of the font map structure and frees all allocated memory back to the system. - */ -void FreeTypeGX::unloadFont() -{ - if (this->fontData.size() == 0) return; - - map >::iterator itr; - map::iterator itr2; - - for (itr = fontData.begin(); itr != fontData.end(); itr++) - { - for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) - free(itr2->second.glyphDataTexture); - - itr->second.clear(); - } - - fontData.clear(); - ftgxAlign.clear(); -} - -/** - * Caches the given font glyph in the instance font texture buffer. - * - * This routine renders and stores the requested glyph's bitmap and relevant information into its own quickly addressible - * structure within an instance-specific map. - * - * @param charCode The requested glyph's character code. - * @return A pointer to the allocated font structure. - */ -ftgxCharData * FreeTypeGX::cacheGlyphData(wchar_t charCode, int16_t pixelSize) -{ - map >::iterator itr; - map::iterator itr2; - - itr = fontData.find(pixelSize); - if (itr != fontData.end()) - { - itr2 = itr->second.find(charCode); - - if (itr2 != itr->second.end()) - { - return &itr2->second; - } - } - - FT_UInt gIndex; - uint16_t textureWidth = 0, textureHeight = 0; - - if (ftPointSize != pixelSize) - { - ftPointSize = pixelSize; - FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize); - - //!Cache ascender and decender as well - map::iterator itrAlign = ftgxAlign.find(ftPointSize); - if (itrAlign == ftgxAlign.end()) - { - ftgxAlign[ftPointSize].ascender = (int16_t) ftFace->size->metrics.ascender >> 6; - ftgxAlign[ftPointSize].descender = (int16_t) ftFace->size->metrics.descender >> 6; - ftgxAlign[ftPointSize].max = 0; - ftgxAlign[ftPointSize].min = 0; - } - } - - gIndex = FT_Get_Char_Index(ftFace, (FT_ULong) charCode); - if (gIndex != 0 && FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT | FT_LOAD_RENDER) == 0) - { - if (ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP) - { - FT_Bitmap *glyphBitmap = &ftFace->glyph->bitmap; - - textureWidth = glyphBitmap->width + (4 - glyphBitmap->width % 4) % 4; - textureHeight = glyphBitmap->rows + (4 - glyphBitmap->rows % 4) % 4; - - fontData[pixelSize][charCode].renderOffsetX = (int16_t) ftFace->glyph->bitmap_left; - fontData[pixelSize][charCode].glyphAdvanceX = (uint16_t) (ftFace->glyph->advance.x >> 6); - fontData[pixelSize][charCode].glyphIndex = (uint32_t) gIndex; - fontData[pixelSize][charCode].textureWidth = (uint16_t) textureWidth; - fontData[pixelSize][charCode].textureHeight = (uint16_t) textureHeight; - fontData[pixelSize][charCode].renderOffsetY = (int16_t) ftFace->glyph->bitmap_top; - fontData[pixelSize][charCode].renderOffsetMax = (int16_t) ftFace->glyph->bitmap_top; - fontData[pixelSize][charCode].renderOffsetMin = (int16_t) glyphBitmap->rows - ftFace->glyph->bitmap_top; - fontData[pixelSize][charCode].glyphDataTexture = NULL; - - loadGlyphData(glyphBitmap, &fontData[pixelSize][charCode]); - - return &fontData[pixelSize][charCode]; - } - } - return NULL; -} - -/** - * Locates each character in this wrapper's configured font face and proccess them. - * - * This routine locates each character in the configured font face and renders the glyph's bitmap. - * Each bitmap and relevant information is loaded into its own quickly addressible structure within an instance-specific map. - */ -uint16_t FreeTypeGX::cacheGlyphDataComplete(int16_t pixelSize) -{ - uint32_t i = 0; - FT_UInt gIndex; - - FT_ULong charCode = FT_Get_First_Char(ftFace, &gIndex); - while (gIndex != 0) - { - if (cacheGlyphData(charCode, pixelSize) != NULL) ++i; - charCode = FT_Get_Next_Char(ftFace, charCode, &gIndex); - } - return (uint16_t) (i); -} - -/** - * Loads the rendered bitmap into the relevant structure's data buffer. - * - * This routine does a simple byte-wise copy of the glyph's rendered 8-bit grayscale bitmap into the structure's buffer. - * Each byte is converted from the bitmap's intensity value into the a uint32_t RGBA value. - * - * @param bmp A pointer to the most recently rendered glyph's bitmap. - * @param charData A pointer to an allocated ftgxCharData structure whose data represent that of the last rendered glyph. - * - * - * Optimized for RGBA8 use by Dimok. - */ -void FreeTypeGX::loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData) -{ - int length = ((((charData->textureWidth + 3) >> 2) * ((charData->textureHeight + 3) >> 2) * 32 * 2 + 31) & ~31); - - uint8_t * glyphData = (uint8_t *) memalign(32, length); - if (!glyphData) return; - - memset(glyphData, 0x00, length); - - uint8_t *src = (uint8_t *) bmp->buffer; - uint32_t offset; - - for (int imagePosY = 0; imagePosY < bmp->rows; ++imagePosY) - { - for (int imagePosX = 0; imagePosX < bmp->width; ++imagePosX) - { - offset = ((((imagePosY >> 2) * (charData->textureWidth >> 2) + (imagePosX >> 2)) << 5) + ((imagePosY & 3) - << 2) + (imagePosX & 3)) << 1; - glyphData[offset] = *src; - glyphData[offset + 1] = *src; - glyphData[offset + 32] = *src; - glyphData[offset + 33] = *src; - ++src; - } - } - DCFlushRange(glyphData, length); - - charData->glyphDataTexture = glyphData; -} - -/** - * Determines the x offset of the rendered string. - * - * This routine calculates the x offset of the rendered string based off of a supplied positional format parameter. - * - * @param width Current pixel width of the string. - * @param format Positional format of the string. - */ -int16_t FreeTypeGX::getStyleOffsetWidth(uint16_t width, uint16_t format) -{ - if (format & FTGX_JUSTIFY_LEFT) - return 0; - else if (format & FTGX_JUSTIFY_CENTER) - return -(width >> 1); - else if (format & FTGX_JUSTIFY_RIGHT) return -width; - return 0; -} - -/** - * Determines the y offset of the rendered string. - * - * This routine calculates the y offset of the rendered string based off of a supplied positional format parameter. - * - * @param offset Current pixel offset data of the string. - * @param format Positional format of the string. - */ -int16_t FreeTypeGX::getStyleOffsetHeight(int16_t format, uint16_t pixelSize) -{ - map::iterator itrAlign = ftgxAlign.find(pixelSize); - if (itrAlign == ftgxAlign.end()) return 0; - - switch (format & FTGX_ALIGN_MASK) - { - case FTGX_ALIGN_TOP: - return itrAlign->second.ascender; - - case FTGX_ALIGN_MIDDLE: - default: - return (itrAlign->second.ascender + itrAlign->second.descender + 1) >> 1; - - case FTGX_ALIGN_BOTTOM: - return itrAlign->second.descender; - - case FTGX_ALIGN_BASELINE: - return 0; - - case FTGX_ALIGN_GLYPH_TOP: - return itrAlign->second.max; - - case FTGX_ALIGN_GLYPH_MIDDLE: - return (itrAlign->second.max + itrAlign->second.min + 1) >> 1; - - case FTGX_ALIGN_GLYPH_BOTTOM: - return itrAlign->second.min; - } - return 0; -} - -/** - * Processes the supplied text string and prints the results at the specified coordinates. - * - * This routine processes each character of the supplied text string, loads the relevant preprocessed bitmap buffer, - * a texture from said buffer, and loads the resultant texture into the EFB. - * - * @param x Screen X coordinate at which to output the text. - * @param y Screen Y coordinate at which to output the text. Note that this value corresponds to the text string origin and not the top or bottom of the glyphs. - * @param text NULL terminated string to output. - * @param color Optional color to apply to the text characters. If not specified default value is ftgxWhite: (GXColor){0xff, 0xff, 0xff, 0xff} - * @param textStyle Flags which specify any styling which should be applied to the rendered string. - * @return The number of characters printed. - */ -uint16_t FreeTypeGX::drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color, - uint16_t textStyle, uint16_t textWidth, uint16_t widthLimit) -{ - if (!text) return 0; - - uint16_t fullTextWidth = textWidth > 0 ? textWidth : getWidth(text, pixelSize); - uint16_t x_pos = x, printed = 0; - uint16_t x_offset = 0, y_offset = 0; - GXTexObj glyphTexture; - FT_Vector pairDelta; - - if (textStyle & FTGX_JUSTIFY_MASK) - { - x_offset = getStyleOffsetWidth(fullTextWidth, textStyle); - } - if (textStyle & FTGX_ALIGN_MASK) - { - y_offset = getStyleOffsetHeight(textStyle, pixelSize); - } - - int i = 0; - - while (text[i]) - { - if (widthLimit > 0 && (x_pos - x) > widthLimit) break; - - ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); - - if (glyphData != NULL) - { - if (ftKerningEnabled && i > 0) - { - FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, - FT_KERNING_DEFAULT, &pairDelta); - x_pos += pairDelta.x >> 6; - } - - GX_InitTexObj(&glyphTexture, glyphData->glyphDataTexture, glyphData->textureWidth, - glyphData->textureHeight, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - copyTextureToFramebuffer(&glyphTexture, glyphData->textureWidth, glyphData->textureHeight, x_pos - + glyphData->renderOffsetX + x_offset, y - glyphData->renderOffsetY + y_offset, z, color); - - x_pos += glyphData->glyphAdvanceX; - ++printed; - } - ++i; - } - - if (textStyle & FTGX_STYLE_MASK) - { - getOffset(text, pixelSize, widthLimit); - drawTextFeature(x + x_offset, y + y_offset, z, pixelSize, fullTextWidth, &ftgxAlign[pixelSize], textStyle, - color); - } - - return printed; -} - -void FreeTypeGX::drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width, - ftgxDataOffset *offsetData, uint16_t format, GXColor color) -{ - uint16_t featureHeight = pixelSize >> 4 > 0 ? pixelSize >> 4 : 1; - - if (format & FTGX_STYLE_UNDERLINE) this->copyFeatureToFramebuffer(width, featureHeight, x, y + 1, z, color); - - if (format & FTGX_STYLE_STRIKE) this->copyFeatureToFramebuffer(width, featureHeight, x, y - - ((offsetData->max) >> 1), z, color); -} - -/** - * Processes the supplied string and return the width of the string in pixels. - * - * This routine processes each character of the supplied text string and calculates the width of the entire string. - * Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function. - * - * @param text NULL terminated string to calculate. - * @return The width of the text string in pixels. - */ -uint16_t FreeTypeGX::getWidth(const wchar_t *text, int16_t pixelSize) -{ - if (!text) return 0; - - uint16_t strWidth = 0; - FT_Vector pairDelta; - - int i = 0; - while (text[i]) - { - ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); - - if (glyphData != NULL) - { - if (ftKerningEnabled && (i > 0)) - { - FT_Get_Kerning(ftFace, fontData[pixelSize][text[i - 1]].glyphIndex, glyphData->glyphIndex, - FT_KERNING_DEFAULT, &pairDelta); - strWidth += pairDelta.x >> 6; - } - - strWidth += glyphData->glyphAdvanceX; - } - ++i; - } - return strWidth; -} - -/** - * Single char width - */ -uint16_t FreeTypeGX::getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar) -{ - uint16_t strWidth = 0; - ftgxCharData * glyphData = cacheGlyphData(wChar, pixelSize); - - if (glyphData != NULL) - { - if (ftKerningEnabled && prevChar != 0x0000) - { - FT_Vector pairDelta; - FT_Get_Kerning(ftFace, fontData[pixelSize][prevChar].glyphIndex, glyphData->glyphIndex, FT_KERNING_DEFAULT, - &pairDelta); - strWidth += pairDelta.x >> 6; - } - strWidth += glyphData->glyphAdvanceX; - } - - return strWidth; -} - -/** - * Processes the supplied string and return the height of the string in pixels. - * - * This routine processes each character of the supplied text string and calculates the height of the entire string. - * Note that if precaching of the entire font set is not enabled any uncached glyph will be cached after the call to this function. - * - * @param text NULL terminated string to calculate. - * @return The height of the text string in pixels. - */ -uint16_t FreeTypeGX::getHeight(const wchar_t *text, int16_t pixelSize) -{ - getOffset(text, pixelSize); - - return ftgxAlign[pixelSize].max - ftgxAlign[pixelSize].min; -} - -/** - * Get the maximum offset above and minimum offset below the font origin line. - * - * This function calculates the maximum pixel height above the font origin line and the minimum - * pixel height below the font origin line and returns the values in an addressible structure. - * - * @param text NULL terminated string to calculate. - * @param offset returns the max and min values above and below the font origin line - * - */ -void FreeTypeGX::getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit) -{ - if (ftgxAlign.find(pixelSize) != ftgxAlign.end()) return; - - int16_t strMax = 0, strMin = 9999; - uint16_t currWidth = 0; - - int i = 0; - - while (text[i]) - { - if (widthLimit > 0 && currWidth >= widthLimit) break; - - ftgxCharData* glyphData = cacheGlyphData(text[i], pixelSize); - - if (glyphData != NULL) - { - strMax = glyphData->renderOffsetMax > strMax ? glyphData->renderOffsetMax : strMax; - strMin = glyphData->renderOffsetMin < strMin ? glyphData->renderOffsetMin : strMin; - currWidth += glyphData->glyphAdvanceX; - } - - ++i; - } - - if (ftPointSize != pixelSize) - { - ftPointSize = pixelSize; - FT_Set_Pixel_Sizes(ftFace, 0, ftPointSize); - } - - ftgxAlign[pixelSize].ascender = ftFace->size->metrics.ascender >> 6; - ftgxAlign[pixelSize].descender = ftFace->size->metrics.descender >> 6; - ftgxAlign[pixelSize].max = strMax; - ftgxAlign[pixelSize].min = strMin; -} - -/** - * Copies the supplied texture quad to the EFB. - * - * This routine uses the in-built GX quad builder functions to define the texture bounds and location on the EFB target. - * - * @param texObj A pointer to the glyph's initialized texture object. - * @param texWidth The pixel width of the texture object. - * @param texHeight The pixel height of the texture object. - * @param screenX The screen X coordinate at which to output the rendered texture. - * @param screenY The screen Y coordinate at which to output the rendered texture. - * @param color Color to apply to the texture. - */ -void FreeTypeGX::copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, - int16_t screenY, int16_t screenZ, GXColor color) -{ - GX_LoadTexObj(texObj, GX_TEXMAP0); - GX_InvalidateTexAll(); - - GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); - GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); - - GX_Begin(GX_QUADS, this->vertexIndex, 4); - GX_Position3s16(screenX, screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - GX_TexCoord2f32(0.0f, 0.0f); - - GX_Position3s16(texWidth + screenX, screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - GX_TexCoord2f32(1.0f, 0.0f); - - GX_Position3s16(texWidth + screenX, texHeight + screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - GX_TexCoord2f32(1.0f, 1.0f); - - GX_Position3s16(screenX, texHeight + screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - GX_TexCoord2f32(0.0f, 1.0f); - GX_End(); - - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); -} - -/** - * Creates a feature quad to the EFB. - * - * This function creates a simple quad for displaying underline or strikeout text styling. - * - * @param featureWidth The pixel width of the quad. - * @param featureHeight The pixel height of the quad. - * @param screenX The screen X coordinate at which to output the quad. - * @param screenY The screen Y coordinate at which to output the quad. - * @param color Color to apply to the texture. - */ -void FreeTypeGX::copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, - int16_t screenZ, GXColor color) -{ - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); - - GX_Begin(GX_QUADS, this->vertexIndex, 4); - GX_Position3s16(screenX, screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - - GX_Position3s16(featureWidth + screenX, screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - - GX_Position3s16(featureWidth + screenX, featureHeight + screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - - GX_Position3s16(screenX, featureHeight + screenY, screenZ); - GX_Color4u8(color.r, color.g, color.b, color.a); - GX_End(); - - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); -} diff --git a/source/FreeTypeGX.h b/source/FreeTypeGX.h deleted file mode 100644 index 7b50215d..00000000 --- a/source/FreeTypeGX.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * FreeTypeGX is a wrapper class for libFreeType which renders a compiled - * FreeType parsable font into a GX texture for Wii homebrew development. - * Copyright (C) 2008 Armin Tamzarian - * Modified by Dimok, 2010 - * - * This file is part of FreeTypeGX. - * - * FreeTypeGX is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * FreeTypeGX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with FreeTypeGX. If not, see . - */ - -#ifndef FREETYPEGX_H_ -#define FREETYPEGX_H_ - -#include -#include -#include FT_FREETYPE_H -#include FT_BITMAP_H - -#include -#include -#include -#include - -/*! \struct ftgxCharData_ - * - * Font face character glyph relevant data structure. - */ -typedef struct ftgxCharData_ -{ - int16_t renderOffsetX; /**< Texture X axis bearing offset. */ - uint16_t glyphAdvanceX; /**< Character glyph X coordinate advance in pixels. */ - uint32_t glyphIndex; /**< Charachter glyph index in the font face. */ - - uint16_t textureWidth; /**< Texture width in pixels/bytes. */ - uint16_t textureHeight; /**< Texture glyph height in pixels/bytes. */ - - int16_t renderOffsetY; /**< Texture Y axis bearing offset. */ - int16_t renderOffsetMax; /**< Texture Y axis bearing maximum value. */ - int16_t renderOffsetMin; /**< Texture Y axis bearing minimum value. */ - - uint8_t* glyphDataTexture; /**< Glyph texture bitmap data buffer. */ -} ftgxCharData; - -/*! \struct ftgxDataOffset_ - * - * Offset structure which hold both a maximum and minimum value. - */ -typedef struct ftgxDataOffset_ -{ - int16_t ascender; /**< Maximum data offset. */ - int16_t descender; /**< Minimum data offset. */ - int16_t max; /**< Maximum data offset. */ - int16_t min; /**< Minimum data offset. */ -} ftgxDataOffset; - -typedef struct ftgxCharData_ ftgxCharData; -typedef struct ftgxDataOffset_ ftgxDataOffset; - -#define _TEXT(t) L ## t /**< Unicode helper macro. */ - -#define FTGX_NULL 0x0000 -#define FTGX_JUSTIFY_LEFT 0x0001 -#define FTGX_JUSTIFY_CENTER 0x0002 -#define FTGX_JUSTIFY_RIGHT 0x0004 -#define FTGX_JUSTIFY_MASK 0x000f - -#define FTGX_ALIGN_TOP 0x0010 -#define FTGX_ALIGN_MIDDLE 0x0020 -#define FTGX_ALIGN_BOTTOM 0x0040 -#define FTGX_ALIGN_BASELINE 0x0080 -#define FTGX_ALIGN_GLYPH_TOP 0x0100 -#define FTGX_ALIGN_GLYPH_MIDDLE 0x0200 -#define FTGX_ALIGN_GLYPH_BOTTOM 0x0400 -#define FTGX_ALIGN_MASK 0x0ff0 - -#define FTGX_STYLE_UNDERLINE 0x1000 -#define FTGX_STYLE_STRIKE 0x2000 -#define FTGX_STYLE_MASK 0xf000 - -const GXColor ftgxWhite = ( GXColor ) -{ 0xff, 0xff, 0xff, 0xff}; /**< Constant color value used only to sanitize Doxygen documentation. */ - -wchar_t* charToWideChar(const char* p); - -/*! \class FreeTypeGX - * \brief Wrapper class for the libFreeType library with GX rendering. - * \author Armin Tamzarian - * \version 0.2.4 - * - * FreeTypeGX acts as a wrapper class for the libFreeType library. It supports precaching of transformed glyph data into - * a specified texture format. Rendering of the data to the EFB is accomplished through the application of high performance - * GX texture functions resulting in high throughput of string rendering. - */ -class FreeTypeGX -{ - private: - FT_Library ftLibrary; /**< FreeType FT_Library instance. */ - FT_Face ftFace; /**< FreeType reusable FT_Face typographic object. */ - int16_t ftPointSize; /**< Current set size of the rendered font. */ - bool ftKerningEnabled; /**< Flag indicating the availability of font kerning data. */ - uint8_t vertexIndex; /**< Vertex format descriptor index. */ - std::map > fontData; /**< Map which holds the glyph data structures for the corresponding characters in one size. */ - std::map ftgxAlign; /**< Map which holds the ascender and decender for different sizes. */ - - int16_t getStyleOffsetWidth(uint16_t width, uint16_t format); - int16_t getStyleOffsetHeight(int16_t format, uint16_t pixelSize); - - void unloadFont(); - ftgxCharData *cacheGlyphData(wchar_t charCode, int16_t pixelSize); - uint16_t cacheGlyphDataComplete(int16_t pixelSize); - void loadGlyphData(FT_Bitmap *bmp, ftgxCharData *charData); - - void setDefaultMode(); - - void drawTextFeature(int16_t x, int16_t y, int16_t z, int16_t pixelSize, uint16_t width, - ftgxDataOffset *offsetData, uint16_t format, GXColor color); - void copyTextureToFramebuffer(GXTexObj *texObj, f32 texWidth, f32 texHeight, int16_t screenX, int16_t screenY, - int16_t screenZ, GXColor color); - void copyFeatureToFramebuffer(f32 featureWidth, f32 featureHeight, int16_t screenX, int16_t screenY, - int16_t screenZ, GXColor color); - - public: - FreeTypeGX(const uint8_t* fontBuffer, FT_Long bufferSize); - ~FreeTypeGX(); - - void setVertexFormat(uint8_t vertexIndex); - - uint16_t drawText(int16_t x, int16_t y, int16_t z, const wchar_t *text, int16_t pixelSize, GXColor color = - ftgxWhite, uint16_t textStyling = FTGX_NULL, uint16_t textWidth = 0, uint16_t widthLimit = 0); - - uint16_t getWidth(const wchar_t *text, int16_t pixelSize); - uint16_t getCharWidth(const wchar_t wChar, int16_t pixelSize, const wchar_t prevChar = 0x0000); - uint16_t getHeight(const wchar_t *text, int16_t pixelSize); - void getOffset(const wchar_t *text, int16_t pixelSize, uint16_t widthLimit = 0); -}; - -#endif /* FREETYPEGX_H_ */ diff --git a/source/GameBootProcess.cpp b/source/GameBootProcess.cpp deleted file mode 100644 index 8eb8c207..00000000 --- a/source/GameBootProcess.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include "menu/menus.h" -#include "mload/mload.h" -#include "mload/mload_modules.h" -#include "system/IosLoader.h" -#include "usbloader/disc.h" -#include "usbloader/apploader.h" -#include "usbloader/wdvd.h" -#include "usbloader/GameList.h" -#include "settings/Settings.h" -#include "settings/CGameSettings.h" -#include "usbloader/frag.h" -#include "usbloader/wbfs.h" -#include "settings/newtitles.h" -#include "patches/fst.h" -#include "patches/gamepatches.h" -#include "patches/wip.h" -#include "system/IosLoader.h" -#include "wad/nandtitle.h" -#include "menu/menus.h" -#include "memory/memory.h" -#include "fatmounter.h" -#include "FontSystem.h" -#include "sys.h" - -//appentrypoint has to be global because of asm -u32 AppEntrypoint = 0; - -struct discHdr *dvdheader = NULL; -extern int load_from_fs; -extern int mountMethod; - - -static u32 BootPartition(char * dolpath, u8 videoselected, u8 languageChoice, u8 cheat, u8 vipatch, u8 patchcountrystring, - u8 alternatedol, u32 alternatedoloffset, u32 returnTo, u8 fix002) -{ - gprintf("booting partition IOS %u v%u\n", IOS_GetVersion(), IOS_GetRevision()); - entry_point p_entry; - s32 ret; - u64 offset; - - /* Find game partition offset */ - ret = __Disc_FindPartition(&offset); - if (ret < 0) - return 0; - - /* Open specified partition */ - ret = WDVD_OpenPartition(offset); - if (ret < 0) - return 0; - - load_wip_code((u8*) Disc_ID); - - /* If a wip file is loaded for this game this does nothing - Dimok */ - PoPPatch(); - - /* Setup low memory */ - __Disc_SetLowMem(); - - /* Run apploader */ - ret = Apploader_Run(&p_entry, dolpath, cheat, videoselected, languageChoice, vipatch, patchcountrystring, - alternatedol, alternatedoloffset, returnTo, fix002); - - if (ret < 0) - return 0; - - free_wip(); - - return (u32) p_entry; -} - -int BootGame(const char * gameID) -{ - if(!gameID || strlen(gameID) < 3) - return -1; - - if (mountMethod == 2) - { - ExitApp(); - gprintf("\nLoading BC for GameCube"); - WII_Initialize(); - return WII_LaunchTitle(0x0000000100000100ULL); - } - - AppCleanUp(); - - gprintf("\tSettings.partition: %d\n", Settings.partition); - - struct discHdr gameHeader; - gameList.LoadUnfiltered(); - - if(mountMethod == 0 && !gameList.GetDiscHeader(gameID)) - { - gprintf("Game was not found: %s\n", gameID); - return -1; - } - else if(mountMethod && !dvdheader) - { - gprintf("Error: Loading empty disc header from DVD\n"); - return -1; - } - - memcpy(&gameHeader, (mountMethod ? dvdheader : gameList.GetDiscHeader(gameID)), sizeof(struct discHdr)); - - delete dvdheader; - dvdheader = NULL; - int ret = 0; - - u8 videoChoice = Settings.videomode; - u8 languageChoice = Settings.language; - u8 ocarinaChoice = Settings.ocarina; - u8 viChoice = Settings.videopatch; - u8 iosChoice = Settings.cios; - u8 fix002 = Settings.error002; - u8 countrystrings = Settings.patchcountrystrings; - u8 alternatedol = OFF; - u32 alternatedoloffset = 0; - u8 reloadblock = OFF; - u8 returnToLoaderGV = 1; - - GameCFG * game_cfg = GameSettings.GetGameCFG(gameHeader.id); - - if (game_cfg) - { - videoChoice = game_cfg->video; - languageChoice = game_cfg->language; - ocarinaChoice = game_cfg->ocarina; - viChoice = game_cfg->vipatch; - fix002 = game_cfg->errorfix002; - iosChoice = game_cfg->ios; - countrystrings = game_cfg->patchcountrystrings; - alternatedol = game_cfg->loadalternatedol; - alternatedoloffset = game_cfg->alternatedolstart; - reloadblock = game_cfg->iosreloadblock; - returnToLoaderGV = game_cfg->returnTo; - } - - if(iosChoice != IOS_GetVersion()) - { - gprintf("Reloading into game cIOS: %i...\n", iosChoice); - IosLoader::LoadGameCios(iosChoice); - if(MountGamePartition(false) < 0) - return -1; - } - - if (!mountMethod) - { - gprintf("Loading fragment list..."); - ret = get_frag_list(gameHeader.id); - gprintf("%d\n", ret); - - ret = Disc_SetUSB(gameHeader.id); - if (ret < 0) Sys_BackToLoader(); - gprintf("\tUSB set to game\n"); - } - else - { - gprintf("\tUSB not set, loading DVD\n"); - } - - gprintf("Disc_Open()..."); - ret = Disc_Open(); - gprintf("%d\n", ret); - - if (ret < 0) - Sys_BackToLoader(); - - gprintf("Loading BCA data..."); - ret = do_bca_code(gameHeader.id); - gprintf("%d\n", ret); - - if (reloadblock == ON && IosLoader::IsHermesIOS()) - { - enable_ES_ioctlv_vector(); - if (load_from_fs == PART_FS_WBFS) - mload_close(); - } - - u32 channel = 0; - if (returnToLoaderGV) - { - int idx = NandTitles.FindU32(Settings.returnTo); - if (idx >= 0) channel = TITLE_LOWER( NandTitles.At( idx ) ); - } - - //This is temporary - SetCheatFilepath(Settings.Cheatcodespath); - SetBCAFilepath(Settings.BcaCodepath); - - gprintf("\tDisc_wiiBoot\n"); - - /* Boot partition */ - AppEntrypoint = BootPartition(Settings.dolpath, videoChoice, languageChoice, ocarinaChoice, viChoice, countrystrings, - alternatedol, alternatedoloffset, channel, fix002); - - if(AppEntrypoint != 0) - { - bool enablecheat = false; - - if (ocarinaChoice) - { - // OCARINA STUFF - FISHEARS - if (ocarina_load_code((u8 *) Disc_ID) > 0) - { - ocarina_do_code(); - enablecheat = true; - } - } - - shadow_mload(); - UnmountNTFS(); - UnmountEXT(); - SDCard_deInit(); - USBDevice_deInit(); - - gprintf("Jumping to game entrypoint: 0x%08X.\n", AppEntrypoint); - - return Disc_JumpToEntrypoint(videoChoice, enablecheat); - } - - WDVD_ClosePartition(); - - return -1; -} diff --git a/source/GameBootProcess.h b/source/GameBootProcess.h deleted file mode 100644 index 5c8106d4..00000000 --- a/source/GameBootProcess.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GAMEBOOTPROCESS_H_ -#define GAMEBOOTPROCESS_H_ - -int BootGame(const char * gameID); - -#endif diff --git a/source/ImageOperations/TextureConverter.c b/source/ImageOperations/TextureConverter.c deleted file mode 100644 index 74b2b076..00000000 --- a/source/ImageOperations/TextureConverter.c +++ /dev/null @@ -1,616 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * TextureConverter.cpp - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include "TextureConverter.h" - -#define cut_bounds(x, min, max) ( (x < min) ? min : (x > max) ? max : x ) -#define ALIGN(x) (((x) + 3) & ~3) -#define ALIGN32(x) (((x) + 31) & ~31) -#define coordsRGBA8(x, y, w) (((((y >> 2) * (w >> 2) + (x >> 2)) << 5) + ((y & 3) << 2) + (x & 3)) << 1) -#define datasizeRGBA8(w, h) ALIGN32(((w+3)>>2)*((h+3)>>2)*32*2) - -#define MAXWIDTH 1024.0f -#define MAXHEIGHT 768.0f - -static u16 avg(u16 w0, u16 w1, u16 c0, u16 c1) -{ - u16 a0, a1; - u16 a, c; - - a0 = c0 >> 11; - a1 = c1 >> 11; - a = (w0*a0 + w1*a1) / (w0 + w1); - c = a << 11; - - a0 = (c0 >> 5) & 63; - a1 = (c1 >> 5) & 63; - a = (w0*a0 + w1*a1) / (w0 + w1); - c |= a << 5; - - a0 = c0 & 31; - a1 = c1 & 31; - a = (w0*a0 + w1*a1) / (w0 + w1); - c |= a; - - return c; -} - -bool I4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u32 x1, y1; - u32 iv; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(iv = 0, y1 = 0; y1 < height; y1 += 8) - { - for(x1 = 0; x1 < width; x1 += 8) - { - for(y = y1; y < (y1 + 8); y++) - { - for(x = x1; x < (x1 + 8); x += 2, iv++) - { - if((x >= width) || (y >= height)) - continue; - - u8 oldpixel = buffer[iv]; - u8 b = (oldpixel >> 4) * 255 / 15; - u8 g = (oldpixel >> 4) * 255 / 15; - u8 r = (oldpixel >> 4) * 255 / 15; - u8 a = gdAlphaOpaque; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - - r = (oldpixel & 0xF) * 255 / 15; - g = (oldpixel & 0xF) * 255 / 15; - b = (oldpixel & 0xF) * 255 / 15; - a = gdAlphaOpaque; - - gdImageSetPixel(*im, x+1, y, gdTrueColorAlpha(r, g, b, a)); - } - } - } - } - return true; -} - -bool IA4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u32 x1, y1; - u32 iv; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(iv = 0, y1 = 0; y1 < height; y1 += 4) - { - for(x1 = 0; x1 < width; x1 += 8) - { - for(y = y1; y < (y1 + 4); y++) - { - for(x = x1; x < (x1 + 8); x++) - { - u8 oldpixel = *(u8*)(buffer + (iv++)); - oldpixel = ~oldpixel; - - if((x >= width) || (y >= height)) - continue; - - u8 r = ((oldpixel & 0xF) * 255) / 15; - u8 g = ((oldpixel & 0xF) * 255) / 15; - u8 b = ((oldpixel & 0xF) * 255) / 15; - u8 a = ((oldpixel >> 4) * 255) / 15; - a = 127-127*a/255; - - gdImageSetPixel(*im, x+1, y, gdTrueColorAlpha(r, g, b, a)); - } - } - } - } - return true; -} - -bool I8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u32 x1, y1; - u32 iv; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(iv = 0, y1 = 0; y1 < height; y1 += 4) - { - for(x1 = 0; x1 < width; x1 += 8) - { - for(y = y1; y < (y1 + 4); y++) - { - for(x = x1; x < (x1 + 8); x++) - { - u8 pixel = *(u8*)(buffer + ((iv++) * 1)); - if((x >= width) || (y >= height)) - continue; - - u8 r = pixel; - u8 g = pixel; - u8 b = pixel; - u8 a = gdAlphaOpaque; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - } - } - } - } - - return true; -} - -bool IA8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u32 x1, y1; - u32 iv; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(iv = 0, y1 = 0; y1 < height; y1 += 4) - { - for(x1 = 0; x1 < width; x1 += 4) - { - for(y = y1; y < (y1 + 4); y++) - { - for(x = x1; x < (x1 + 4); x++) - { - u16 oldpixel = *(u16*)(buffer + ((iv++) * 2)); - - if((x >= width) || (y >= height)) - continue; - - u8 r = oldpixel >> 8; - u8 g = oldpixel >> 8; - u8 b = oldpixel >> 8; - u8 a = oldpixel & 0xFF; - a = 127-127*a/255; - - gdImageSetPixel(*im, x+1, y, gdTrueColorAlpha(r, g, b, a)); - } - } - } - } - return true; -} - -bool CMPToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u8 r, g, b, a; - u16 raw; - u16 c[4]; - int x0, x1, x2, y0, y1, y2, off; - int ww = (-(-(width) & -(8))); - int ix; - u32 px; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - x0 = x & 3; - x1 = (x >> 2) & 1; - x2 = x >> 3; - y0 = y & 3; - y1 = (y >> 2) & 1; - y2 = y >> 3; - off = (8 * x1) + (16 * y1) + (32 * x2) + (4 * ww * y2); - - c[0] = *(u16*)(buffer + off); - c[1] = *(u16*)(buffer + off + 2); - if (c[0] > c[1]) { - c[2] = avg(2, 1, c[0], c[1]); - c[3] = avg(1, 2, c[0], c[1]); - } else { - c[2] = avg(1, 1, c[0], c[1]); - c[3] = 0; - } - - px = *(u32*)(buffer + off + 4); - ix = x0 + (4 * y0); - raw = c[(px >> (30 - (2 * ix))) & 3]; - - r = (raw >> 8) & 0xf8; - g = (raw >> 3) & 0xf8; - b = (raw << 3) & 0xf8; - a = gdAlphaOpaque; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - } - } - - return true; -} - -bool RGB565ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u32 x1, y1; - u32 iv; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(iv = 0, y1 = 0; y1 < height; y1 += 4) - { - for(x1 = 0; x1 < width; x1 += 4) - { - for(y = y1; y < (y1 + 4); y++) - { - for(x = x1; x < (x1 + 4); x++) - { - if((x >= width) || (y >= height)) - continue; - - u16 pixel = *(u16*)(buffer + ((iv++) * 2)); - - u8 r = ((pixel >> 11) & 0x1F) << 3; - u8 g = ((pixel >> 5) & 0x3F) << 2; - u8 b = ((pixel >> 0) & 0x1F) << 3; - u8 a = gdAlphaOpaque; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - } - } - } - } - return true; -} - -bool RGB565A3ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y; - u32 x1, y1; - u32 iv; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(iv = 0, y1 = 0; y1 < height; y1 += 4) - { - for(x1 = 0; x1 < width; x1 += 4) - { - for(y = y1; y < (y1 + 4); y++) - { - for(x = x1; x < (x1 + 4); x++) - { - u16 pixel = *(u16*)(buffer + ((iv++) * 2)); - if((x >= width) || (y >= height)) - continue; - - if(pixel & (1 << 15)) - { - // RGB5 - u8 r = (((pixel >> 10) & 0x1F) * 255) / 31; - u8 g = (((pixel >> 5) & 0x1F) * 255) / 31; - u8 b = (((pixel >> 0) & 0x1F) * 255) / 31; - u8 a = gdAlphaOpaque; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - } - else - { - // RGB4A3 - u8 r = (((pixel >> 12) & 0xF) * 255) / 15; - u8 g = (((pixel >> 8) & 0xF) * 255) / 15; - u8 b = (((pixel >> 4) & 0xF) * 255) / 15; - u8 a = (((pixel >> 0) & 0x7) * 64) / 7; - a = 127-127*a/255; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - } - } - } - } - } - - return true; -} - -bool RGBA8ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y, offset; - u8 r, g, b, a; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(y = 0; y < height; y++) - { - for(x = 0; x < width; x++) - { - offset = coordsRGBA8(x, y, width); - a = *(buffer+offset); - r = *(buffer+offset+1); - g = *(buffer+offset+32); - b = *(buffer+offset+33); - - a = 127-127*a/255; - - gdImageSetPixel(*im, x, y, gdTrueColorAlpha(r, g, b, a)); - } - } - - return true; -} - -bool YCbYCrToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im) -{ - u32 x, y, x1, YCbYCr; - int r, g, b; - u8 r1, g1, b1; - - if(!buffer) - return false; - - *im = gdImageCreateTrueColor(width, height); - if(*im == 0) - return false; - - gdImageAlphaBlending(*im, 0); - gdImageSaveAlpha(*im, 1); - - for(y = 0; y < height; y++) - { - for (x = 0, x1 = 0; x < (width / 2); x++, x1++) - { - YCbYCr = ((u32 *) buffer)[y*width/2+x]; - - u8 * val = (u8 *) &YCbYCr; - - r = (int) (1.371f * (val[3] - 128)); - g = (int) (- 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128)); - b = (int) (1.732f * (val[1] - 128)); - - r1 = cut_bounds(val[0] + r, 0, 255); - g1 = cut_bounds(val[0] + g, 0, 255); - b1 = cut_bounds(val[0] + b, 0, 255); - - gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque)); - x1++; - - r1 = cut_bounds(val[2] + r, 0, 255); - g1 = cut_bounds(val[2] + g, 0, 255); - b1 = cut_bounds(val[2] + b, 0, 255); - gdImageSetPixel(*im, x1, y, gdTrueColorAlpha(r1, g1, b1, gdAlphaOpaque)); - } - } - - return true; -} - -u8 * GDImageToRGBA8(gdImagePtr * gdImg, int * w, int * h) -{ - int width = gdImageSX(*gdImg); - int height = gdImageSY(*gdImg); - float scale = 1.0f; - int retries = 100; //shouldn't need that long but to be sure - - gdImageAlphaBlending(*gdImg, 0); - gdImageSaveAlpha(*gdImg, 1); - - while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT) - { - if(width*scale > MAXWIDTH) - scale = MAXWIDTH/width; - if(height*scale > MAXHEIGHT) - scale = MAXHEIGHT/height; - - retries--; - - if(!retries) - { - while(width*scale > MAXWIDTH || height*scale > MAXHEIGHT) - scale -= 0.02; - break; - } - } - - width = ALIGN((int) (width * scale)); - height = ALIGN((int) (height * scale)); - - if(width != gdImageSX(*gdImg) || height != gdImageSY(*gdImg)) - { - gdImagePtr dst = gdImageCreateTrueColor(width, height); - gdImageAlphaBlending(dst, 0); - gdImageSaveAlpha(dst, 1); - gdImageCopyResized(dst, *gdImg, 0, 0, 0, 0, width, height, gdImageSX(*gdImg), gdImageSY(*gdImg)); - - gdImageDestroy(*gdImg); - *gdImg = dst; - - width = gdImageSX(*gdImg); - height = gdImageSY(*gdImg); - } - - int len = datasizeRGBA8(width, height); - - u8 * data = (u8 *) memalign(32, len); - if(!data) - return NULL; - - u8 a; - u32 x, y, pixel, offset; - - for(y = 0; y < height; ++y) - { - for(x = 0; x < width; ++x) - { - pixel = gdImageGetPixel(*gdImg, x, y); - - a = 254 - 2*((u8)gdImageAlpha(*gdImg, pixel)); - if(a == 254) a++; - - offset = coordsRGBA8(x, y, width); - data[offset] = a; - data[offset+1] = (u8)gdImageRed(*gdImg, pixel); - data[offset+32] = (u8)gdImageGreen(*gdImg, pixel); - data[offset+33] = (u8)gdImageBlue(*gdImg, pixel); - } - } - - DCFlushRange(data, len); - - if(w) - *w = width; - if(h) - *h = height; - - return data; -} - -u8 * FlipRGBAImage(const u8 *src, u32 width, u32 height) -{ - int x, y; - - int len = datasizeRGBA8(width, height); - - u8 * data = memalign(32, len); - if(!data) - return NULL; - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - u32 offset = coordsRGBA8(x, y, width); - u8 a = src[offset]; - u8 r = src[offset+1]; - u8 g = src[offset+32]; - u8 b = src[offset+33]; - - u32 offset2 = coordsRGBA8((width-x-1), (height-y-1), width); - data[offset2] = a; - data[offset2+1] = r; - data[offset2+32] = g; - data[offset2+33] = b; - } - } - - DCFlushRange(data, len); - - return data; -} - -u8 * RGB8ToRGBA8(const u8 *src, u32 width, u32 height) -{ - u32 x, y, offset; - - int len = datasizeRGBA8(width, height); - - u8 * dst = (u8 *) memalign(32, len); - if(!dst) - return NULL; - - for (y = 0; y < height; ++y) - { - for (x = 0; x < width; ++x) - { - offset = coordsRGBA8(x, y, width); - dst[offset] = 0xFF; - dst[offset+1] = src[(y*width+x)*3]; - dst[offset+32] = src[(y*width+x)*3+1]; - dst[offset+33] = src[(y*width+x)*3+2]; - } - } - - DCFlushRange(dst, len); - - return dst; -} diff --git a/source/ImageOperations/TextureConverter.h b/source/ImageOperations/TextureConverter.h deleted file mode 100644 index cfbac302..00000000 --- a/source/ImageOperations/TextureConverter.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * TextureConverter.h - * - * A texture to GD image converter. - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef __TEXTURE_CONVERTER_H_ -#define __TEXTURE_CONVERTER_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include - -bool I4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im); -bool IA4ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im); -bool I8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im); -bool IA8ToGD(const u8 * buffer, u32 width, u32 height, gdImagePtr * im); -bool CMPToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im); -bool RGB565ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im); -bool RGB565A3ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im); -bool RGBA8ToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im); -bool YCbYCrToGD(const u8* buffer, u32 width, u32 height, gdImagePtr * im); -u8 * GDImageToRGBA8(gdImagePtr * gdImg, int * w, int * h); -u8 * FlipRGBAImage(const u8 *src, u32 width, u32 height); -u8 * RGB8ToRGBA8(const u8 *src, u32 width, u32 height); - -#ifdef __cplusplus -} -#endif - -#endif //__TEXTURE_CONVERTER_H_ diff --git a/source/ImageOperations/TplImage.cpp b/source/ImageOperations/TplImage.cpp deleted file mode 100644 index 145dd0cd..00000000 --- a/source/ImageOperations/TplImage.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * TplImage.cpp - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include "FileOperations/fileops.h" -#include "TextureConverter.h" -#include "TplImage.h" - -TplImage::TplImage(const char * filepath) -{ - TPLBuffer = NULL; - TPLSize = 0; - - u8 * buffer = NULL; - u64 filesize = 0; - LoadFileToMem(filepath, &buffer, &filesize); - - if(buffer) - { - LoadImage(buffer, filesize); - free(buffer); - } -} - -TplImage::TplImage(const u8 * imgBuffer, u32 imgSize) -{ - TPLBuffer = NULL; - TPLSize = 0; - - if(imgBuffer) - { - LoadImage(imgBuffer, imgSize); - } -} - -TplImage::~TplImage() -{ - if(TPLBuffer) - free(TPLBuffer); - - Texture.clear(); - TextureHeader.clear(); - TplTextureBuffer.clear(); -} - -bool TplImage::LoadImage(const u8 * imgBuffer, u32 imgSize) -{ - if(TPLBuffer) - free(TPLBuffer); - - TPLBuffer = NULL; - TPLSize = 0; - - if(!imgBuffer) - return false; - - TPLBuffer = (u8 *) malloc(imgSize); - if(!TPLBuffer) - return false; - - TPLSize = imgSize; - - memcpy(TPLBuffer, imgBuffer, imgSize); - - return ParseTplFile(); -} - -bool TplImage::ParseTplFile() -{ - if(!TPLBuffer) - return false; - - TPLHeader = (const TPL_Header *) TPLBuffer; - - if(TPLHeader->magic != 0x0020AF30) - return false; - - if(TPLHeader->head_size != 12) - return false; - - const TPL_Texture * curTexture = (const TPL_Texture *) (TPLHeader+1); - - for(u32 i = 0; i < TPLHeader->num_textures; i++) - { - Texture.resize(i+1); - TextureHeader.resize(i+1); - TplTextureBuffer.resize(i+1); - - Texture[i] = curTexture; - - TextureHeader[i] = (const TPL_Texture_Header *) ((const u8 *) TPLBuffer+Texture[i]->text_header_offset); - - TplTextureBuffer[i] = TPLBuffer + TextureHeader[i]->offset; - - curTexture++; - } - - return true; - -} - -int TplImage::GetWidth(int pos) -{ - if(pos < 0 || pos >= (int) Texture.size()) - { - return 0; - } - - return TextureHeader[pos]->width; -} - -int TplImage::GetHeight(int pos) -{ - if(pos < 0 || pos >= (int) TextureHeader.size()) - { - return 0; - } - - return TextureHeader[pos]->height; -} - -u32 TplImage::GetFormat(int pos) -{ - if(pos < 0 || pos >= (int) TextureHeader.size()) - { - return 0; - } - - return TextureHeader[pos]->format; -} - -const u8 * TplImage::GetTextureBuffer(int pos) -{ - if(pos < 0 || pos >= (int) TplTextureBuffer.size()) - { - return 0; - } - - return TplTextureBuffer[pos]; -} - -int TplImage::GetTextureSize(int pos) -{ - int width = GetWidth(pos); - int height = GetHeight(pos); - int len = 0; - - switch(GetFormat(pos)) - { - case GX_TF_I4: - case GX_TF_CI4: - case GX_TF_CMPR: - len = ((width+7)>>3)*((height+7)>>3)*32; - break; - case GX_TF_I8: - case GX_TF_IA4: - case GX_TF_CI8: - len = ((width+7)>>3)*((height+7)>>2)*32; - break; - case GX_TF_IA8: - case GX_TF_CI14: - case GX_TF_RGB565: - case GX_TF_RGB5A3: - len = ((width+3)>>2)*((height+3)>>2)*32; - break; - case GX_TF_RGBA8: - len = ((width+3)>>2)*((height+3)>>2)*32*2; - break; - default: - len = ((width+3)>>2)*((height+3)>>2)*32*2; - break; - } - - return len; -} - -gdImagePtr TplImage::ConvertToGD(int pos) -{ - if(pos < 0 || pos >= (int) Texture.size()) - { - return 0; - } - - gdImagePtr gdImg = 0; - - switch(TextureHeader[pos]->format) - { - case GX_TF_RGB565: - RGB565ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_RGB5A3: - RGB565A3ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_RGBA8: - RGBA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_I4: - I4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_I8: - I8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_IA4: - IA4ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_IA8: - IA8ToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - case GX_TF_CMPR: - CMPToGD(TplTextureBuffer[pos], TextureHeader[pos]->width, TextureHeader[pos]->height, &gdImg); - break; - default: - gdImg = 0; - break; - } - - return gdImg; -} diff --git a/source/ImageOperations/TplImage.h b/source/ImageOperations/TplImage.h deleted file mode 100644 index 6f85a753..00000000 --- a/source/ImageOperations/TplImage.h +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * TplImage.h - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef TPL_IMAGE_H_ -#define TPL_IMAGE_H_ - -#include -#include -#include - -typedef struct -{ - u32 magic; - u32 num_textures; - u32 head_size; -} TPL_Header; - -typedef struct -{ - u32 text_header_offset; - u32 text_palette_offset; -} TPL_Texture; - -typedef struct -{ - u16 height; - u16 width; - u32 format; - u32 offset; - u32 wrap_s; - u32 wrap_t; - u32 min; - u32 mag; - f32 lod_bias; - u8 edge_lod; - u8 min_lod; - u8 max_lod; - u8 unpacked; -} TPL_Texture_Header; - -typedef struct -{ - u16 num_items; - u8 unpacked; - u8 pad; - u32 format; - u32 offset; -} TPL_Palette_Header; - -class TplImage -{ - public: - TplImage(const char * filepath); - TplImage(const u8 * imgBuffer, u32 imgSize); - ~TplImage(); - bool LoadImage(const u8 * imgBuffer, u32 imgSize); - int GetWidth(int Texture); - int GetHeight(int Texture); - u32 GetFormat(int Texture); - const u8 * GetTextureBuffer(int Texture); - int GetTextureSize(int Texture); - gdImagePtr ConvertToGD(int Texture); - private: - bool ParseTplFile(); - - u8 * TPLBuffer; - u32 TPLSize; - const TPL_Header * TPLHeader; - std::vector Texture; - std::vector TextureHeader; - std::vector TplTextureBuffer; -}; - -#endif diff --git a/source/SoundOperations/AifDecoder.cpp b/source/SoundOperations/AifDecoder.cpp deleted file mode 100644 index 3fa2f2b8..00000000 --- a/source/SoundOperations/AifDecoder.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include "AifDecoder.hpp" - -typedef struct -{ - u32 fccCOMM; - u32 size; - u16 channels; - u8 frames[4]; - u16 bps; - u8 freq[10]; -} SAIFFCommChunk; - -typedef struct -{ - u32 fccSSND; - u32 size; - u32 offset; - u32 blockSize; -} SAIFFSSndChunk; - -// ------ -// Copyright (C) 1988-1991 Apple Computer, Inc. -#ifndef HUGE_VAL -# define HUGE_VAL HUGE -#endif - -# define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0) - -static double ConvertFromIeeeExtended(const unsigned char* bytes) -{ - double f; - int expon; - unsigned long hiMant, loMant; - - expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF); - hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24) - | ((unsigned long)(bytes[3] & 0xFF) << 16) - | ((unsigned long)(bytes[4] & 0xFF) << 8) - | ((unsigned long)(bytes[5] & 0xFF)); - loMant = ((unsigned long)(bytes[6] & 0xFF) << 24) - | ((unsigned long)(bytes[7] & 0xFF) << 16) - | ((unsigned long)(bytes[8] & 0xFF) << 8) - | ((unsigned long)(bytes[9] & 0xFF)); - - if (expon == 0 && hiMant == 0 && loMant == 0) { - f = 0; - } - else { - if (expon == 0x7FFF) { - f = HUGE_VAL; - } - else { - expon -= 16383; - f = ldexp(UnsignedToFloat(hiMant), expon-=31); - f += ldexp(UnsignedToFloat(loMant), expon-=32); - } - } - - if (bytes[0] & 0x80) - return -f; - else - return f; -} - -AifDecoder::AifDecoder(const char * filepath) - : SoundDecoder(filepath) -{ - SoundType = SOUND_AIF; - - if(!file_fd) - return; - - OpenFile(); -} - -AifDecoder::AifDecoder(const u8 * snd, int len) - : SoundDecoder(snd, len) -{ - SoundType = SOUND_AIF; - - if(!file_fd) - return; - - OpenFile(); -} - -AifDecoder::~AifDecoder() -{ -} - -void AifDecoder::OpenFile() -{ - SWaveHdr Header; - file_fd->read((u8 *) &Header, sizeof(SWaveHdr)); - - if (Header.magicRIFF != 'FORM') - { - CloseFile(); - return; - } - else if(Header.magicWAVE != 'AIFF') - { - CloseFile(); - return; - } - - SWaveChunk WaveChunk; - do - { - int ret = file_fd->read((u8 *) &WaveChunk, sizeof(SWaveChunk)); - if(ret <= 0) - { - CloseFile(); - return; - } - } - while(WaveChunk.magicDATA != 'COMM'); - - DataOffset = file_fd->tell()+WaveChunk.size; - - SAIFFCommChunk CommHdr; - file_fd->seek(file_fd->tell()-sizeof(SWaveChunk), SEEK_SET); - file_fd->read((u8 *) &CommHdr, sizeof(SAIFFCommChunk)); - - if(CommHdr.fccCOMM != 'COMM') - { - CloseFile(); - return; - } - - file_fd->seek(DataOffset, SEEK_SET); - - SAIFFSSndChunk SSndChunk; - file_fd->read((u8 *) &SSndChunk, sizeof(SAIFFSSndChunk)); - - if(SSndChunk.fccSSND != 'SSND') - { - CloseFile(); - return; - } - - DataOffset += sizeof(SAIFFSSndChunk); - DataSize = SSndChunk.size-8; - SampleRate = (u32) ConvertFromIeeeExtended(CommHdr.freq); - Format = VOICE_STEREO_16BIT; - - if(CommHdr.channels == 1 && CommHdr.bps == 8) - Format = VOICE_MONO_8BIT; - else if (CommHdr.channels == 1 && CommHdr.bps == 16) - Format = VOICE_MONO_16BIT; - else if (CommHdr.channels == 2 && CommHdr.bps == 8) - Format = VOICE_STEREO_8BIT; - else if (CommHdr.channels == 2 && CommHdr.bps == 16) - Format = VOICE_STEREO_16BIT; - - Decode(); -} - -void AifDecoder::CloseFile() -{ - if(file_fd) - delete file_fd; - - file_fd = NULL; -} - -int AifDecoder::Read(u8 * buffer, int buffer_size, int pos) -{ - if(!file_fd) - return -1; - - if(CurPos >= (int) DataSize) - return 0; - - file_fd->seek(DataOffset+CurPos, SEEK_SET); - - if(buffer_size > (int) DataSize-CurPos) - buffer_size = DataSize-CurPos; - - int read = file_fd->read(buffer, buffer_size); - if(read > 0) - { - CurPos += read; - } - - return read; -} diff --git a/source/SoundOperations/AifDecoder.hpp b/source/SoundOperations/AifDecoder.hpp deleted file mode 100644 index f9c6fd91..00000000 --- a/source/SoundOperations/AifDecoder.hpp +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef AIFDECODER_HPP_ -#define AIFDECODER_HPP_ - -#include "SoundDecoder.hpp" -#include "WavDecoder.hpp" - -class AifDecoder : public SoundDecoder -{ - public: - AifDecoder(const char * filepath); - AifDecoder(const u8 * snd, int len); - ~AifDecoder(); - int GetFormat() { return Format; }; - int GetSampleRate() { return SampleRate; }; - int Read(u8 * buffer, int buffer_size, int pos); - protected: - void OpenFile(); - void CloseFile(); - u32 DataOffset; - u32 DataSize; - u32 SampleRate; - u8 Format; -}; - -#endif diff --git a/source/SoundOperations/BNSDecoder.cpp b/source/SoundOperations/BNSDecoder.cpp deleted file mode 100644 index e79a2442..00000000 --- a/source/SoundOperations/BNSDecoder.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include "BNSDecoder.hpp" - -BNSDecoder::BNSDecoder(const char * filepath) - : SoundDecoder(filepath) -{ - SoundType = SOUND_BNS; - memset(&SoundData, 0, sizeof(SoundBlock)); - - if(!file_fd) - return; - - OpenFile(); -} - -BNSDecoder::BNSDecoder(const u8 * snd, int len) - : SoundDecoder(snd, len) -{ - SoundType = SOUND_BNS; - memset(&SoundData, 0, sizeof(SoundBlock)); - - if(!file_fd) - return; - - OpenFile(); -} - -BNSDecoder::~BNSDecoder() -{ - ExitRequested = true; - while(Decoding) - usleep(100); - - if(SoundData.buffer != NULL) - free(SoundData.buffer); - - SoundData.buffer = NULL; -} - -void BNSDecoder::OpenFile() -{ - u8 * tempbuff = new (std::nothrow) u8[file_fd->size()]; - if(!tempbuff) - { - CloseFile(); - return; - } - - int done = 0; - - while(done < file_fd->size()) - { - int read = file_fd->read(tempbuff, file_fd->size()); - if(read > 0) - done += read; - else - { - CloseFile(); - return; - } - } - - SoundData = DecodefromBNS(tempbuff, done); - if(SoundData.buffer == NULL) - { - CloseFile(); - return; - } - - delete [] tempbuff; - tempbuff = NULL; - - Decode(); -} - -void BNSDecoder::CloseFile() -{ - if(file_fd) - delete file_fd; - - file_fd = NULL; -} - -int BNSDecoder::Read(u8 * buffer, int buffer_size, int pos) -{ - if(!SoundData.buffer) - return -1; - - if(SoundData.loopFlag) - { - int factor = SoundData.format == VOICE_STEREO_16BIT ? 4 : 2; - if(CurPos >= (int) SoundData.loopEnd*factor) - CurPos = SoundData.loopStart*factor; - - if(buffer_size > (int) SoundData.loopEnd*factor-CurPos) - buffer_size = SoundData.loopEnd*factor-CurPos; - } - else - { - if(CurPos >= (int) SoundData.size) - return 0; - - if(buffer_size > (int) SoundData.size-CurPos) - buffer_size = SoundData.size-CurPos; - } - - memcpy(buffer, SoundData.buffer+CurPos, buffer_size); - CurPos += buffer_size; - - return buffer_size; -} - -struct BNSHeader -{ - u32 fccBNS; - u32 magic; - u32 size; - u16 unk1; - u16 unk2; - u32 infoOffset; - u32 infoSize; - u32 dataOffset; - u32 dataSize; -} __attribute__((packed)); - -struct BNSInfo -{ - u32 fccINFO; - u32 size; - u8 codecNum; - u8 loopFlag; - u8 chanCount; - u8 zero; - u16 freq; - u8 pad1[2]; - u32 loopStart; - u32 loopEnd; - u32 offsetToChanStarts; - u8 pad2[4]; - u32 chan1StartOffset; - u32 chan2StartOffset; - u32 chan1Start; - u32 coeff1Offset; - u8 pad3[4]; - u32 chan2Start; - u32 coeff2Offset; - u8 pad4[4]; - s16 coefficients1[8][2]; - u16 chan1Gain; - u16 chan1PredictiveScale; - s16 chan1PrevSamples[2]; - u16 chan1LoopPredictiveScale; - s16 chan1LoopPrevSamples[2]; - u16 chan1LoopPadding; - s16 coefficients2[8][2]; - u16 chan2Gain; - u16 chan2PredictiveScale; - s16 chan2PrevSamples[2]; - u16 chan2LoopPredictiveScale; - s16 chan2LoopPrevSamples[2]; - u16 chan2LoopPadding; -} __attribute__((packed)); - -struct BNSData -{ - u32 fccDATA; - u32 size; - u8 data; -} __attribute__((packed)); - -struct ADPCMByte -{ - s8 sample1 : 4; - s8 sample2 : 4; -} __attribute__((packed)); - -struct BNSADPCMBlock -{ - u8 pad : 1; - u8 coeffIndex : 3; - u8 lshift : 4; - ADPCMByte samples[7]; -} __attribute__((packed)); - -struct BNSDecObj -{ - s16 prevSamples[2]; - s16 coeff[8][2]; -}; - -static void loadBNSInfo(BNSInfo &bnsInfo, const u8 *buffer) -{ - const u8 *ptr = buffer + 8; - bnsInfo = *(const BNSInfo *)buffer; - if (bnsInfo.offsetToChanStarts == 0x18 && bnsInfo.chan1StartOffset == 0x20 && bnsInfo.chan2StartOffset == 0x2C - && bnsInfo.coeff1Offset == 0x38 && bnsInfo.coeff2Offset == 0x68) - return; - bnsInfo.chan1StartOffset = *(const u32 *)(ptr + bnsInfo.offsetToChanStarts); - bnsInfo.chan1Start = *(const u32 *)(ptr + bnsInfo.chan1StartOffset); - bnsInfo.coeff1Offset = *(const u32 *)(ptr + bnsInfo.chan1StartOffset + 4); - if ((u8 *)bnsInfo.coefficients1 != ptr + bnsInfo.coeff1Offset) - memcpy(bnsInfo.coefficients1, ptr + bnsInfo.coeff1Offset, (u8 *)bnsInfo.coefficients2 - (u8 *)&bnsInfo.coefficients1); - if (bnsInfo.chanCount == 2) - { - bnsInfo.chan2StartOffset = *(const u32 *)(ptr + bnsInfo.offsetToChanStarts + 4); - bnsInfo.chan2Start = *(const u32 *)(ptr + bnsInfo.chan2StartOffset); - bnsInfo.coeff2Offset = *(const u32 *)(ptr + bnsInfo.chan2StartOffset + 4); - if ((u8 *)bnsInfo.coefficients2 != ptr + bnsInfo.coeff2Offset) - memcpy(bnsInfo.coefficients2, ptr + bnsInfo.coeff2Offset, (u8 *)bnsInfo.coefficients2 - (u8 *)&bnsInfo.coefficients1); - } -} - -static void decodeADPCMBlock(s16 *buffer, const BNSADPCMBlock &block, BNSDecObj &bnsDec) -{ - int h1 = bnsDec.prevSamples[0]; - int h2 = bnsDec.prevSamples[1]; - int c1 = bnsDec.coeff[block.coeffIndex][0]; - int c2 = bnsDec.coeff[block.coeffIndex][1]; - for (int i = 0; i < 14; ++i) - { - int nibSample = ((i & 1) == 0) ? block.samples[i / 2].sample1 : block.samples[i / 2].sample2; - int sampleDeltaHP = (nibSample << block.lshift) << 11; - int predictedSampleHP = c1 * h1 + c2 * h2; - int sampleHP = predictedSampleHP + sampleDeltaHP; - buffer[i] = std::min(std::max(-32768, (sampleHP + 1024) >> 11), 32767); - h2 = h1; - h1 = buffer[i]; - } - bnsDec.prevSamples[0] = h1; - bnsDec.prevSamples[1] = h2; -} - -static u8 * decodeBNS(u32 &size, const BNSInfo &bnsInfo, const BNSData &bnsData) -{ - static s16 smplBlock[14]; - BNSDecObj decObj; - int numBlocks = (bnsData.size - 8) / 8; - int numSamples = numBlocks * 14; - const BNSADPCMBlock *inputBuf = (const BNSADPCMBlock *)&bnsData.data; - u8 * buffer = (u8 *) malloc(numSamples * sizeof (s16)); - s16 *outputBuf; - - if (!buffer) - return buffer; - memcpy(decObj.coeff, bnsInfo.coefficients1, sizeof decObj.coeff); - memcpy(decObj.prevSamples, bnsInfo.chan1PrevSamples, sizeof decObj.prevSamples); - outputBuf = (s16 *)buffer; - if (bnsInfo.chanCount == 1) - for (int i = 0; i < numBlocks; ++i) - { - decodeADPCMBlock(smplBlock, inputBuf[i], decObj); - memcpy(outputBuf, smplBlock, sizeof smplBlock); - outputBuf += 14; - } - else - { - numBlocks /= 2; - for (int i = 0; i < numBlocks; ++i) - { - decodeADPCMBlock(smplBlock, inputBuf[i], decObj); - for (int j = 0; j < 14; ++j) - outputBuf[j * 2] = smplBlock[j]; - outputBuf += 2 * 14; - } - outputBuf = (s16 *)buffer + 1; - memcpy(decObj.coeff, bnsInfo.coefficients2, sizeof decObj.coeff); - memcpy(decObj.prevSamples, bnsInfo.chan2PrevSamples, sizeof decObj.prevSamples); - for (int i = 0; i < numBlocks; ++i) - { - decodeADPCMBlock(smplBlock, inputBuf[numBlocks + i], decObj); - for (int j = 0; j < 14; ++j) - outputBuf[j * 2] = smplBlock[j]; - outputBuf += 2 * 14; - } - } - size = numSamples * sizeof (s16); - return buffer; -} - -SoundBlock DecodefromBNS(const u8 *buffer, u32 size) -{ - SoundBlock OutBlock; - memset(&OutBlock, 0, sizeof(SoundBlock)); - - const BNSHeader &hdr = *(BNSHeader *)buffer; - if (size < sizeof hdr) - return OutBlock; - if (hdr.fccBNS != 'BNS ') - return OutBlock; - // Find info and data - BNSInfo infoChunk; - loadBNSInfo(infoChunk, buffer + hdr.infoOffset); - const BNSData &dataChunk = *(const BNSData *)(buffer + hdr.dataOffset); - // Check sizes - if (size < hdr.size || size < hdr.infoOffset + hdr.infoSize || size < hdr.dataOffset + hdr.dataSize - || hdr.infoSize < 0x60 || hdr.dataSize < sizeof dataChunk - || infoChunk.size != hdr.infoSize || dataChunk.size != hdr.dataSize) - return OutBlock; - // Check format - if (infoChunk.codecNum != 0) // Only codec i've found : 0 = ADPCM. Maybe there's also 1 and 2 for PCM 8 or 16 bits ? - return OutBlock; - u8 format = (u8)-1; - if (infoChunk.chanCount == 1 && infoChunk.codecNum == 0) - format = VOICE_MONO_16BIT; - else if (infoChunk.chanCount == 2 && infoChunk.codecNum == 0) - format = VOICE_STEREO_16BIT; - if (format == (u8)-1) - return OutBlock; - u32 freq = (u32) infoChunk.freq; - u32 length = 0; - // Copy data - if (infoChunk.codecNum == 0) - { - OutBlock.buffer = decodeBNS(length, infoChunk, dataChunk); - if (!OutBlock.buffer) - return OutBlock; - } - else - { - OutBlock.buffer = (u8*) malloc(dataChunk.size); - if (!OutBlock.buffer) - return OutBlock; - memcpy(OutBlock.buffer, &dataChunk.data, dataChunk.size); - length = dataChunk.size; - } - - OutBlock.frequency = freq; - OutBlock.format = format; - OutBlock.size = length; - OutBlock.loopStart = infoChunk.loopStart; - OutBlock.loopEnd = infoChunk.loopEnd; - OutBlock.loopFlag = infoChunk.loopFlag; - - return OutBlock; -} diff --git a/source/SoundOperations/BNSDecoder.hpp b/source/SoundOperations/BNSDecoder.hpp deleted file mode 100644 index 4c9d76c3..00000000 --- a/source/SoundOperations/BNSDecoder.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef BNSDECODER_HPP_ -#define BNSDECODER_HPP_ - -#include "SoundDecoder.hpp" - -typedef struct _SoundBlock -{ - u8 * buffer; - u32 size; - u8 format; - u32 frequency; - u32 loopStart; - u32 loopEnd; - u8 loopFlag; -} SoundBlock; - -class BNSDecoder : public SoundDecoder -{ - public: - BNSDecoder(const char * filepath); - BNSDecoder(const u8 * snd, int len); - ~BNSDecoder(); - int GetFormat() { return SoundData.format; }; - int GetSampleRate() { return SoundData.frequency; }; - int Read(u8 * buffer, int buffer_size, int pos); - protected: - void OpenFile(); - void CloseFile(); - SoundBlock SoundData; -}; - -SoundBlock DecodefromBNS(const u8 *buffer, u32 size); - -#endif diff --git a/source/SoundOperations/BufferCircle.cpp b/source/SoundOperations/BufferCircle.cpp deleted file mode 100644 index a8ff1e44..00000000 --- a/source/SoundOperations/BufferCircle.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include "BufferCircle.hpp" - -#define ALIGN32(x) (((x) + 31) & ~31) - -BufferCircle::BufferCircle() -{ - which = 0; - BufferBlockSize = 0; -} - -BufferCircle::~BufferCircle() -{ - FreeBuffer(); - SoundBuffer.clear(); - BufferSize.clear(); - BufferReady.clear(); -} - -void BufferCircle::SetBufferBlockSize(int size) -{ - if(size < 0) - return; - - BufferBlockSize = size; - - for(int i = 0; i < Size(); i++) - { - if(SoundBuffer[i] != NULL) - free(SoundBuffer[i]); - - SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize)); - BufferSize[i] = 0; - BufferReady[i] = false; - } -} - -void BufferCircle::Resize(int size) -{ - while(size < Size()) - RemoveBuffer(Size()-1); - - int oldSize = Size(); - - SoundBuffer.resize(size); - BufferSize.resize(size); - BufferReady.resize(size); - - for(int i = oldSize; i < Size(); i++) - { - if(BufferBlockSize > 0) - SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize)); - else - SoundBuffer[i] = NULL; - BufferSize[i] = 0; - BufferReady[i] = false; - } -} - -void BufferCircle::RemoveBuffer(int pos) -{ - if(!Valid(pos)) - return; - - if(SoundBuffer[pos] != NULL) - free(SoundBuffer[pos]); - - SoundBuffer.erase(SoundBuffer.begin()+pos); - BufferSize.erase(BufferSize.begin()+pos); - BufferReady.erase(BufferReady.begin()+pos); -} - -void BufferCircle::ClearBuffer() -{ - for(int i = 0; i < Size(); i++) - { - BufferSize[i] = 0; - BufferReady[i] = false; - } - which = 0; -} - -void BufferCircle::FreeBuffer() -{ - for(int i = 0; i < Size(); i++) - { - if(SoundBuffer[i] != NULL) - free(SoundBuffer[i]); - - SoundBuffer[i] = NULL; - BufferSize[i] = 0; - BufferReady[i] = false; - } -} - -void BufferCircle::LoadNext() -{ - int pos = (which+Size()-1) % Size(); - BufferReady[pos] = false; - BufferSize[pos] = 0; - - which = (which+1) % Size(); -} - -void BufferCircle::SetBufferReady(int pos, bool state) -{ - if(!Valid(pos)) - return; - - BufferReady[pos] = state; -} - -void BufferCircle::SetBufferSize(int pos, int size) -{ - if(!Valid(pos)) - return; - - BufferSize[pos] = size; -} diff --git a/source/SoundOperations/BufferCircle.hpp b/source/SoundOperations/BufferCircle.hpp deleted file mode 100644 index fcb9d6e4..00000000 --- a/source/SoundOperations/BufferCircle.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef BUFFER_CIRCLE_HPP_ -#define BUFFER_CIRCLE_HPP_ - -#include -#include - -class BufferCircle -{ - public: - //!> Constructor - BufferCircle(); - //!> Destructor - ~BufferCircle(); - //!> Set circle size - void Resize(int size); - //!> Get the circle size - int Size() { return SoundBuffer.size(); }; - //!> Set/resize the buffer size - void SetBufferBlockSize(int size); - //!> Remove a buffer - void RemoveBuffer(int pos); - //!> Set all buffers clear - void ClearBuffer(); - //!> Free all buffers - void FreeBuffer(); - //!> Switch to next buffer - void LoadNext(); - //!> Get the current buffer - u8 * GetBuffer() { if(!Valid(which)) return 0; return SoundBuffer[which]; }; - //!> Get a buffer at a position - u8 * GetBuffer(int pos) { if(!Valid(pos)) return NULL; else return SoundBuffer[pos]; }; - //!> Get next buffer - u8 * GetNextBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+1) % Size()]; }; - //!> Get previous buffer - u8 * GetLastBuffer() { if(Size() <= 0) return 0; else return SoundBuffer[(which+Size()-1) % Size()]; }; - //!> Get current buffer size - u32 GetBufferSize() { if(!Valid(which)) return 0; else return BufferSize[which]; }; - //!> Get buffer size at position - u32 GetBufferSize(int pos) { if(!Valid(pos)) return 0; else return BufferSize[pos]; }; - //!> Get previous buffer size - u32 GetLastBufferSize() { if(Size() <= 0) return 0; else return BufferSize[(which+Size()-1) % Size()]; }; - //!> Is current buffer ready - bool IsBufferReady() { if(!Valid(which)) return false; else return BufferReady[which]; }; - //!> Is a buffer at a position ready - bool IsBufferReady(int pos) { if(!Valid(pos)) return false; else return BufferReady[pos]; }; - //!> Is next buffer ready - bool IsNextBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+1) % Size()]; }; - //!> Is last buffer ready - bool IsLastBufferReady() { if(Size() <= 0) return false; else return BufferReady[(which+Size()-1) % Size()]; }; - //!> Set a buffer at a position to a ready state - void SetBufferReady(int pos, bool st); - //!> Set the buffersize at a position - void SetBufferSize(int pos, int size); - //!> Get the current position in the circle - u16 Which() { return which; }; - protected: - //!> Check if the position is a valid position in the vector - bool Valid(int pos) { return !(pos < 0 || pos >= Size()); }; - - u16 which; - u32 BufferBlockSize; - std::vector SoundBuffer; - std::vector BufferSize; - std::vector BufferReady; -}; - -#endif diff --git a/source/SoundOperations/Mp3Decoder.cpp b/source/SoundOperations/Mp3Decoder.cpp deleted file mode 100644 index 13dd0ae7..00000000 --- a/source/SoundOperations/Mp3Decoder.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include "Mp3Decoder.hpp" - -Mp3Decoder::Mp3Decoder(const char * filepath) - : SoundDecoder(filepath) -{ - SoundType = SOUND_MP3; - ReadBuffer = NULL; - mad_timer_reset(&Timer); - mad_stream_init(&Stream); - mad_frame_init(&Frame); - mad_synth_init(&Synth); - - if(!file_fd) - return; - - OpenFile(); -} - -Mp3Decoder::Mp3Decoder(const u8 * snd, int len) - : SoundDecoder(snd, len) -{ - SoundType = SOUND_MP3; - ReadBuffer = NULL; - mad_timer_reset(&Timer); - mad_stream_init(&Stream); - mad_frame_init(&Frame); - mad_synth_init(&Synth); - - if(!file_fd) - return; - - OpenFile(); -} - -Mp3Decoder::~Mp3Decoder() -{ - ExitRequested = true; - while(Decoding) - usleep(100); - - mad_synth_finish(&Synth); - mad_frame_finish(&Frame); - mad_stream_finish(&Stream); - - if(ReadBuffer) - free(ReadBuffer); - ReadBuffer = NULL; -} - -void Mp3Decoder::OpenFile() -{ - GuardPtr = NULL; - ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks); - if(!ReadBuffer) - { - if(file_fd) - delete file_fd; - file_fd = NULL; - return; - } - - u8 dummybuff[4096]; - int ret = Read((u8 *) &dummybuff, 4096, 0); - if(ret <= 0) - { - if(file_fd) - delete file_fd; - file_fd = NULL; - return; - } - - SampleRate = (u32) Frame.header.samplerate; - Format = ((MAD_NCHANNELS(&Frame.header) == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT); - Rewind(); - Decode(); -} - -int Mp3Decoder::Rewind() -{ - mad_synth_finish(&Synth); - mad_frame_finish(&Frame); - mad_stream_finish(&Stream); - mad_timer_reset(&Timer); - mad_stream_init(&Stream); - mad_frame_init(&Frame); - mad_synth_init(&Synth); - SynthPos = 0; - GuardPtr = NULL; - - if(!file_fd) - return -1; - - return SoundDecoder::Rewind(); -} - -static inline s16 FixedToShort(mad_fixed_t Fixed) -{ - /* Clipping */ - if(Fixed>=MAD_F_ONE) - return(SHRT_MAX); - if(Fixed<=-MAD_F_ONE) - return(-SHRT_MAX); - - Fixed=Fixed>>(MAD_F_FRACBITS-15); - return((s16)Fixed); -} - -int Mp3Decoder::Read(u8 * buffer, int buffer_size, int pos) -{ - if(!file_fd) - return -1; - - if(Format == VOICE_STEREO_16BIT) - buffer_size &= ~0x0003; - else - buffer_size &= ~0x0001; - - u8 * write_pos = buffer; - u8 * write_end = buffer+buffer_size; - - while(1) - { - while(SynthPos < Synth.pcm.length) - { - if(write_pos >= write_end) - return write_pos-buffer; - - *((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]); - write_pos += 2; - - if(MAD_NCHANNELS(&Frame.header) == 2) - { - *((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]); - write_pos += 2; - } - SynthPos++; - } - - if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN) - { - u8 * ReadStart = ReadBuffer; - int ReadSize = SoundBlockSize*SoundBlocks; - int Remaining = 0; - - if(Stream.next_frame != NULL) - { - Remaining = Stream.bufend - Stream.next_frame; - memmove(ReadBuffer, Stream.next_frame, Remaining); - ReadStart += Remaining; - ReadSize -= Remaining; - } - - ReadSize = file_fd->read(ReadStart, ReadSize); - if(ReadSize <= 0) - { - GuardPtr = ReadStart; - memset(GuardPtr, 0, MAD_BUFFER_GUARD); - ReadSize = MAD_BUFFER_GUARD; - } - - CurPos += ReadSize; - mad_stream_buffer(&Stream, ReadBuffer, Remaining+ReadSize); - } - - if(mad_frame_decode(&Frame,&Stream)) - { - if(MAD_RECOVERABLE(Stream.error)) - { - if(Stream.error != MAD_ERROR_LOSTSYNC || !GuardPtr) - continue; - } - else - { - if(Stream.error != MAD_ERROR_BUFLEN) - return -1; - else if(Stream.error == MAD_ERROR_BUFLEN && GuardPtr) - return -1; - } - } - - mad_timer_add(&Timer,Frame.header.duration); - mad_synth_frame(&Synth,&Frame); - SynthPos = 0; - } -} diff --git a/source/SoundOperations/Mp3Decoder.hpp b/source/SoundOperations/Mp3Decoder.hpp deleted file mode 100644 index a622f1f3..00000000 --- a/source/SoundOperations/Mp3Decoder.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include - -#include "SoundDecoder.hpp" - -class Mp3Decoder : public SoundDecoder -{ - public: - Mp3Decoder(const char * filepath); - Mp3Decoder(const u8 * sound, int len); - ~Mp3Decoder(); - int GetFormat() { return Format; }; - int GetSampleRate() { return SampleRate; }; - int Rewind(); - int Read(u8 * buffer, int buffer_size, int pos); - protected: - void OpenFile(); - struct mad_stream Stream; - struct mad_frame Frame; - struct mad_synth Synth; - mad_timer_t Timer; - u8 * GuardPtr; - u8 * ReadBuffer; - u8 Format; - u32 SampleRate; - u32 SynthPos; -}; diff --git a/source/SoundOperations/OggDecoder.cpp b/source/SoundOperations/OggDecoder.cpp deleted file mode 100644 index 904270ac..00000000 --- a/source/SoundOperations/OggDecoder.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include "OggDecoder.hpp" - -extern "C" int ogg_read(void * punt, int bytes, int blocks, int *f) -{ - return ((CFile *) f)->read((u8 *) punt, bytes*blocks); -} - -extern "C" int ogg_seek(int *f, ogg_int64_t offset, int mode) -{ - return ((CFile *) f)->seek((u64) offset, mode); -} - -extern "C" int ogg_close(int *f) -{ - ((CFile *) f)->close(); - return 0; -} - -extern "C" long ogg_tell(int *f) -{ - return (long) ((CFile *) f)->tell(); -} - -static ov_callbacks callbacks = { - (size_t (*)(void *, size_t, size_t, void *)) ogg_read, - (int (*)(void *, ogg_int64_t, int)) ogg_seek, - (int (*)(void *)) ogg_close, - (long (*)(void *)) ogg_tell -}; - -OggDecoder::OggDecoder(const char * filepath) - : SoundDecoder(filepath) -{ - SoundType = SOUND_OGG; - - if(!file_fd) - return; - - OpenFile(); -} - -OggDecoder::OggDecoder(const u8 * snd, int len) - : SoundDecoder(snd, len) -{ - SoundType = SOUND_OGG; - - if(!file_fd) - return; - - OpenFile(); -} - -OggDecoder::~OggDecoder() -{ - ExitRequested = true; - while(Decoding) - usleep(100); - - if(file_fd) - ov_clear(&ogg_file); -} - -void OggDecoder::OpenFile() -{ - if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0) - { - delete file_fd; - file_fd = NULL; - return; - } - - ogg_info = ov_info(&ogg_file, -1); - Decode(); -} - -int OggDecoder::GetFormat() -{ - if(!file_fd) - return VOICE_STEREO_16BIT; - - return ((ogg_info->channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT); -} - -int OggDecoder::GetSampleRate() -{ - if(!file_fd) - return 0; - - return (int) ogg_info->rate; -} - -int OggDecoder::Rewind() -{ - if(!file_fd) - return -1; - - int ret = ov_time_seek(&ogg_file, 0); - CurPos = 0; - EndOfFile = false; - - return ret; -} - -int OggDecoder::Read(u8 * buffer, int buffer_size, int pos) -{ - if(!file_fd) - return -1; - - int bitstream = 0; - - int read = ov_read(&ogg_file, (char *) buffer, buffer_size, &bitstream); - - if(read > 0) - CurPos += read; - - return read; -} diff --git a/source/SoundOperations/OggDecoder.hpp b/source/SoundOperations/OggDecoder.hpp deleted file mode 100644 index 49de225e..00000000 --- a/source/SoundOperations/OggDecoder.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include - -#include "SoundDecoder.hpp" - -class OggDecoder : public SoundDecoder -{ - public: - OggDecoder(const char * filepath); - OggDecoder(const u8 * snd, int len); - ~OggDecoder(); - int GetFormat(); - int GetSampleRate(); - int Rewind(); - int Read(u8 * buffer, int buffer_size, int pos); - protected: - void OpenFile(); - OggVorbis_File ogg_file; - vorbis_info *ogg_info; -}; diff --git a/source/SoundOperations/SoundDecoder.cpp b/source/SoundOperations/SoundDecoder.cpp deleted file mode 100644 index f4bc6ecb..00000000 --- a/source/SoundOperations/SoundDecoder.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * 3Band resampling thanks to libmad - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include "SoundDecoder.hpp" -#include "main.h" - -SoundDecoder::SoundDecoder() -{ - file_fd = NULL; - Init(); -} - -SoundDecoder::SoundDecoder(const char * filepath) -{ - file_fd = new CFile(filepath, "rb"); - Init(); -} - -SoundDecoder::SoundDecoder(const u8 * buffer, int size) -{ - file_fd = new CFile(buffer, size); - Init(); -} - -SoundDecoder::~SoundDecoder() -{ - ExitRequested = true; - while(Decoding) - usleep(100); - - if(file_fd) - delete file_fd; - file_fd = NULL; -} - -void SoundDecoder::Init() -{ - SoundType = SOUND_RAW; - SoundBlocks = 8; - SoundBlockSize = 8192; - CurPos = 0; - Loop = false; - EndOfFile = false; - Decoding = false; - ExitRequested = false; - SoundBuffer.SetBufferBlockSize(SoundBlockSize); - SoundBuffer.Resize(SoundBlocks); -} - -int SoundDecoder::Rewind() -{ - CurPos = 0; - EndOfFile = false; - file_fd->rewind(); - - return 0; -} - -int SoundDecoder::Read(u8 * buffer, int buffer_size, int pos) -{ - int ret = file_fd->read(buffer, buffer_size); - CurPos += ret; - - return ret; -} - -void SoundDecoder::Decode() -{ - if(!file_fd || ExitRequested || EndOfFile) - return; - - u16 newWhich = SoundBuffer.Which(); - u16 i = 0; - for (i = 0; i < SoundBuffer.Size()-2; i++) - { - if(!SoundBuffer.IsBufferReady(newWhich)) - break; - - newWhich = (newWhich+1) % SoundBuffer.Size(); - } - - if(i == SoundBuffer.Size()-2) - return; - - Decoding = true; - - int done = 0; - u8 * write_buf = SoundBuffer.GetBuffer(newWhich); - if(!write_buf) - { - ExitRequested = true; - Decoding = false; - return; - } - - while(done < SoundBlockSize) - { - int ret = Read(&write_buf[done], SoundBlockSize-done, Tell()); - - if(ret <= 0) - { - if(Loop) - { - Rewind(); - continue; - } - else - { - EndOfFile = true; - break; - } - } - - done += ret; - } - - if(done > 0) - { - SoundBuffer.SetBufferSize(newWhich, done); - SoundBuffer.SetBufferReady(newWhich, true); - } - - if(!SoundBuffer.IsBufferReady((newWhich+1) % SoundBuffer.Size())) - Decode(); - - Decoding = false; -} - diff --git a/source/SoundOperations/SoundDecoder.hpp b/source/SoundOperations/SoundDecoder.hpp deleted file mode 100644 index b9e71ad4..00000000 --- a/source/SoundOperations/SoundDecoder.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef SOUND_DECODER_HPP -#define SOUND_DECODER_HPP - -#include -#include -#include -#include "utils/timer.h" -#include "FileOperations/File.hpp" -#include "BufferCircle.hpp" - -enum -{ - SOUND_RAW = 0, - SOUND_MP3, - SOUND_OGG, - SOUND_WAV, - SOUND_BNS, - SOUND_AIF -}; - -class SoundDecoder -{ - public: - SoundDecoder(); - SoundDecoder(const char * filepath); - SoundDecoder(const u8 * buffer, int size); - ~SoundDecoder(); - virtual int Read(u8 * buffer, int buffer_size, int pos); - virtual int Tell() { return CurPos; }; - virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); }; - virtual int Rewind(); - virtual int GetFormat() { return VOICE_STEREO_16BIT; }; - virtual int GetSampleRate() { return 48000; }; - virtual void Decode(); - virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); }; - virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); }; - virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); }; - virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); }; - virtual void LoadNext() { SoundBuffer.LoadNext(); }; - virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); }; - virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); }; - virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); }; - virtual bool IsEOF() { return EndOfFile; }; - virtual void SetLoop(bool l) { Loop = l; }; - virtual u8 GetSoundType() { return SoundType; }; - virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); }; - virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); }; - virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); }; - protected: - void Init(); - - CFile * file_fd; - BufferCircle SoundBuffer; - u8 SoundType; - u16 SoundBlocks; - int SoundBlockSize; - int CurPos; - bool Loop; - bool EndOfFile; - bool Decoding; - bool ExitRequested; -}; - -#endif diff --git a/source/SoundOperations/SoundHandler.cpp b/source/SoundOperations/SoundHandler.cpp deleted file mode 100644 index a4548886..00000000 --- a/source/SoundOperations/SoundHandler.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include "SoundHandler.hpp" -#include "Mp3Decoder.hpp" -#include "OggDecoder.hpp" -#include "WavDecoder.hpp" -#include "AifDecoder.hpp" -#include "BNSDecoder.hpp" - -SoundHandler * SoundHandler::instance = NULL; - -SoundHandler::SoundHandler() -{ - Decoding = false; - ExitRequested = false; - for(u32 i = 0; i < MAX_DECODERS; ++i) - DecoderList[i] = NULL; - - ThreadStack = (u8 *) memalign(32, 32768); - if(!ThreadStack) - return; - - LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, 80); -} - -SoundHandler::~SoundHandler() -{ - ExitRequested = true; - ThreadSignal(); - LWP_JoinThread(SoundThread, NULL); - SoundThread = LWP_THREAD_NULL; - if(ThreadStack) - free(ThreadStack); - - ClearDecoderList(); -} - -SoundHandler * SoundHandler::Instance() -{ - if (instance == NULL) - { - instance = new SoundHandler(); - } - return instance; -} - -void SoundHandler::DestroyInstance() -{ - if(instance) - { - delete instance; - } - instance = NULL; -} - -void SoundHandler::AddDecoder(int voice, const char * filepath) -{ - if(voice < 0 || voice >= MAX_DECODERS) - return; - - if(DecoderList[voice] != NULL) - RemoveDecoder(voice); - - DecoderList[voice] = GetSoundDecoder(filepath); -} - -void SoundHandler::AddDecoder(int voice, const u8 * snd, int len) -{ - if(voice < 0 || voice >= MAX_DECODERS) - return; - - if(DecoderList[voice] != NULL) - RemoveDecoder(voice); - - DecoderList[voice] = GetSoundDecoder(snd, len); -} - -void SoundHandler::RemoveDecoder(int voice) -{ - if(voice < 0 || voice >= MAX_DECODERS) - return; - - if(DecoderList[voice] != NULL) - { - if(DecoderList[voice]->GetSoundType() == SOUND_OGG) delete ((OggDecoder *) DecoderList[voice]); - else if(DecoderList[voice]->GetSoundType() == SOUND_MP3) delete ((Mp3Decoder *) DecoderList[voice]); - else if(DecoderList[voice]->GetSoundType() == SOUND_WAV) delete ((WavDecoder *) DecoderList[voice]); - else if(DecoderList[voice]->GetSoundType() == SOUND_AIF) delete ((AifDecoder *) DecoderList[voice]); - else if(DecoderList[voice]->GetSoundType() == SOUND_BNS) delete ((BNSDecoder *) DecoderList[voice]); - else delete DecoderList[voice]; - } - - DecoderList[voice] = NULL; -} - -void SoundHandler::ClearDecoderList() -{ - for(u32 i = 0; i < MAX_DECODERS; ++i) - RemoveDecoder(i); -} - -static inline bool CheckMP3Signature(const u8 * buffer) -{ - const char MP3_Magic[][3] = - { - {'I', 'D', '3'}, //'ID3' - {0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), - {0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), - {0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), - {0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), - {0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), - {0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'), - }; - - if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] && - buffer[2] == MP3_Magic[0][2]) - { - return true; - } - - for(int i = 1; i < 13; i++) - { - if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1]) - return true; - } - - return false; -} - -SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath) -{ - u32 magic; - CFile f(filepath, "rb"); - if(f.size() == 0) - return NULL; - - do - { - f.read((u8 *) &magic, 1); - } - while(((u8 *) &magic)[0] == 0 && f.tell() < f.size()); - - if(f.tell() == f.size()) - return NULL; - - f.seek(f.tell()-1, SEEK_SET); - f.read((u8 *) &magic, 4); - f.close(); - - if(magic == 'OggS') - { - return new OggDecoder(filepath); - } - else if(magic == 'RIFF') - { - return new WavDecoder(filepath); - } - else if(magic == 'BNS ') - { - return new BNSDecoder(filepath); - } - else if(magic == 'FORM') - { - return new AifDecoder(filepath); - } - else if(CheckMP3Signature((u8 *) &magic) == true) - { - return new Mp3Decoder(filepath); - } - - return new SoundDecoder(filepath); -} - -SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length) -{ - const u8 * check = sound; - int counter = 0; - - while(check[0] == 0 && counter < length) - { - check++; - counter++; - } - - if(counter >= length) - return NULL; - - u32 * magic = (u32 *) check; - - if(magic[0] == 'OggS') - { - return new OggDecoder(sound, length); - } - else if(magic[0] == 'RIFF') - { - return new WavDecoder(sound, length); - } - else if(magic[0] == 'BNS ') - { - return new BNSDecoder(sound, length); - } - else if(magic[0] == 'FORM') - { - return new AifDecoder(sound, length); - } - else if(CheckMP3Signature(check) == true) - { - return new Mp3Decoder(sound, length); - } - - return new SoundDecoder(sound, length); -} - -void * SoundHandler::UpdateThread(void *arg) -{ - ((SoundHandler *) arg)->InternalSoundUpdates(); - return NULL; -} - -void SoundHandler::InternalSoundUpdates() -{ - u16 i = 0; - LWP_InitQueue(&ThreadQueue); - while (!ExitRequested) - { - LWP_ThreadSleep(ThreadQueue); - - for(i = 0; i < MAX_DECODERS; ++i) - { - if(DecoderList[i] == NULL) - continue; - - Decoding = true; - DecoderList[i]->Decode(); - } - Decoding = false; - } - LWP_CloseQueue(ThreadQueue); - ThreadQueue = LWP_TQUEUE_NULL; -} diff --git a/source/SoundOperations/SoundHandler.hpp b/source/SoundOperations/SoundHandler.hpp deleted file mode 100644 index b10953ec..00000000 --- a/source/SoundOperations/SoundHandler.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef SOUNDHANDLER_H_ -#define SOUNDHANDLER_H_ - -#include -#include -#include "SoundDecoder.hpp" - -#define MAX_DECODERS 16 - -class SoundHandler -{ - public: - static SoundHandler * Instance(); - static void DestroyInstance(); - - void AddDecoder(int voice, const char * filepath); - void AddDecoder(int voice, const u8 * snd, int len); - void RemoveDecoder(int voice); - void DestroyDecoder(SoundDecoder * decoder); - - SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); }; - void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); }; - bool IsDecoding() { return Decoding; }; - protected: - SoundHandler(); - ~SoundHandler(); - static void * UpdateThread(void *arg); - void InternalSoundUpdates(); - void ClearDecoderList(); - SoundDecoder * GetSoundDecoder(const char * filepath); - SoundDecoder * GetSoundDecoder(const u8 * sound, int length); - - static SoundHandler * instance; - u8 * ThreadStack; - lwp_t SoundThread; - lwpq_t ThreadQueue; - bool Decoding; - bool ExitRequested; - - SoundDecoder * DecoderList[MAX_DECODERS]; -}; - -#endif diff --git a/source/SoundOperations/WavDecoder.cpp b/source/SoundOperations/WavDecoder.cpp deleted file mode 100644 index 3f37b95b..00000000 --- a/source/SoundOperations/WavDecoder.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include "WavDecoder.hpp" -#include "utils/uncompress.h" - -WavDecoder::WavDecoder(const char * filepath) - : SoundDecoder(filepath) -{ - SoundType = SOUND_WAV; - SampleRate = 48000; - Format = VOICE_STEREO_16BIT; - - if(!file_fd) - return; - - OpenFile(); -} - -WavDecoder::WavDecoder(const u8 * snd, int len) - : SoundDecoder(snd, len) -{ - SoundType = SOUND_WAV; - SampleRate = 48000; - Format = VOICE_STEREO_16BIT; - - if(!file_fd) - return; - - OpenFile(); -} - -WavDecoder::~WavDecoder() -{ -} - -void WavDecoder::OpenFile() -{ - SWaveHdr Header; - SWaveFmtChunk FmtChunk; - memset(&Header, 0, sizeof(SWaveHdr)); - memset(&FmtChunk, 0, sizeof(SWaveFmtChunk)); - - file_fd->read((u8 *) &Header, sizeof(SWaveHdr)); - file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk)); - - if (Header.magicRIFF != 'RIFF') - { - CloseFile(); - return; - } - else if(Header.magicWAVE != 'WAVE') - { - CloseFile(); - return; - } - else if(FmtChunk.magicFMT != 'fmt ') - { - CloseFile(); - return; - } - - DataOffset = sizeof(SWaveHdr)+le32(FmtChunk.size)+8; - file_fd->seek(DataOffset, SEEK_SET); - SWaveChunk DataChunk; - file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk)); - - if(DataChunk.magicDATA == 'fact') - { - DataOffset += 8+le32(DataChunk.size); - file_fd->seek(DataOffset, SEEK_SET); - file_fd->read((u8 *) &DataChunk, sizeof(SWaveChunk)); - } - if(DataChunk.magicDATA != 'data') - { - CloseFile(); - return; - } - - DataOffset += 8; - DataSize = le32(DataChunk.size); - Is16Bit = (le16(FmtChunk.bps) == 16); - SampleRate = le32(FmtChunk.freq); - - if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1) - Format = VOICE_MONO_8BIT; - else if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 2) - Format = VOICE_MONO_16BIT; - else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 2) - Format = VOICE_STEREO_8BIT; - else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4) - Format = VOICE_STEREO_16BIT; - - Decode(); -} - -void WavDecoder::CloseFile() -{ - if(file_fd) - delete file_fd; - - file_fd = NULL; -} - -int WavDecoder::Read(u8 * buffer, int buffer_size, int pos) -{ - if(!file_fd) - return -1; - - if(CurPos >= (int) DataSize) - return 0; - - file_fd->seek(DataOffset+CurPos, SEEK_SET); - - if(buffer_size > (int) DataSize-CurPos) - buffer_size = DataSize-CurPos; - - int read = file_fd->read(buffer, buffer_size); - if(read > 0) - { - if (Is16Bit) - { - read &= ~0x0001; - - for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i) - ((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]); - } - CurPos += read; - } - - return read; -} diff --git a/source/SoundOperations/WavDecoder.hpp b/source/SoundOperations/WavDecoder.hpp deleted file mode 100644 index 4681bf2b..00000000 --- a/source/SoundOperations/WavDecoder.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef WAVDECODER_HPP_ -#define WAVDECODER_HPP_ - -#include "SoundDecoder.hpp" - -typedef struct -{ - u32 magicRIFF; - u32 size; - u32 magicWAVE; -} SWaveHdr; - -typedef struct -{ - u32 magicFMT; - u32 size; - u16 format; - u16 channels; - u32 freq; - u32 avgBps; - u16 alignment; - u16 bps; -} SWaveFmtChunk; - -typedef struct -{ - u32 magicDATA; - u32 size; -} SWaveChunk; - -class WavDecoder : public SoundDecoder -{ - public: - WavDecoder(const char * filepath); - WavDecoder(const u8 * snd, int len); - ~WavDecoder(); - int GetFormat() { return Format; }; - int GetSampleRate() { return SampleRate; }; - int Read(u8 * buffer, int buffer_size, int pos); - protected: - void OpenFile(); - void CloseFile(); - u32 DataOffset; - u32 DataSize; - u32 SampleRate; - u8 Format; - bool Is16Bit; -}; - -#endif diff --git a/source/SoundOperations/gui_bgm.cpp b/source/SoundOperations/gui_bgm.cpp deleted file mode 100644 index c56bd4fd..00000000 --- a/source/SoundOperations/gui_bgm.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** - * SettingsPrompts - * USB Loader GX 2009 - * - * Backgroundmusic - ***************************************************************************/ -#include -#include "gui_bgm.h" -#include "menu.h" - -GuiBGM::GuiBGM(const u8 *s, int l, int v) : - GuiSound(s, l, v, false, 0) -{ - loop = 0; - loopMode = ONCE; - currentPath = NULL; - currentPlaying = 0; - voice = 0; -} - -GuiBGM::~GuiBGM() -{ - if (currentPath) delete[] currentPath; - - ClearList(); -} -; - -void GuiBGM::SetLoop(u8 l) -{ - loopMode = l; - - GuiSound::SetLoop(l == LOOP); -} - -bool GuiBGM::Load(const char *path) -{ - if (!path) - { - LoadStandard(); - return false; - } - if (strcmp(path, "") == 0) - { - LoadStandard(); - return false; - } - - if (!GuiSound::Load(path)) - { - LoadStandard(); - return false; - } - - return ParsePath(path); -} - -bool GuiBGM::LoadStandard() -{ - ClearList(); - if (currentPath) - { - delete[] currentPath; - currentPath = NULL; - } - - strcpy(Settings.ogg_path, ""); - - bool ret = GuiSound::Load(bg_music_ogg, bg_music_ogg_size, false); - - if (ret) Play(); - - return ret; -} - -bool GuiBGM::ParsePath(const char * folderpath) -{ - ClearList(); - - if (currentPath) delete[] currentPath; - - currentPath = new char[strlen(folderpath) + 1]; - sprintf(currentPath, "%s", folderpath); - - char * isdirpath = strrchr(folderpath, '.'); - if (isdirpath) - { - char * pathptr = strrchr(currentPath, '/'); - if (pathptr) - { - pathptr++; - pathptr[0] = 0; - } - } - - char * LoadedFilename = strrchr(folderpath, '/') + 1; - - char filename[1024]; - struct stat st; - - DIR_ITER * dir = diropen(currentPath); - if (dir == NULL) - { - LoadStandard(); - return false; - } - u32 counter = 0; - - while (dirnext(dir, filename, &st) == 0) - { - char * fileext = strrchr(filename, '.'); - if (fileext) - { - if (strcasecmp(fileext, ".mp3") == 0 || strcasecmp(fileext, ".ogg") == 0 || strcasecmp(fileext, ".wav") - == 0) - { - AddEntrie(filename); - - if (strcmp(LoadedFilename, filename) == 0) currentPlaying = counter; - - counter++; - } - } - } - - dirclose(dir); - - snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s", folderpath); - - return true; -} - -void GuiBGM::AddEntrie(const char * filename) -{ - if (!filename) return; - - char * NewEntrie = new char[strlen(filename) + 1]; - sprintf(NewEntrie, "%s", filename); - - PlayList.push_back(NewEntrie); -} - -void GuiBGM::ClearList() -{ - for (u32 i = 0; i < PlayList.size(); i++) - { - if (PlayList.at(i) != NULL) - { - delete[] PlayList.at(i); - PlayList.at(i) = NULL; - } - } - - PlayList.clear(); -} - -bool GuiBGM::PlayNext() -{ - if (!currentPath) return false; - - currentPlaying++; - if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0; - - snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying)); - - if (!GuiSound::Load(Settings.ogg_path)) return false; - - Play(); - - return true; -} - -bool GuiBGM::PlayPrevious() -{ - if (!currentPath) return false; - - currentPlaying--; - if (currentPlaying < 0) currentPlaying = PlayList.size() - 1; - - snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying)); - - if (!GuiSound::Load(Settings.ogg_path)) return false; - - Play(); - - return true; -} - -bool GuiBGM::PlayRandom() -{ - if (!currentPath) return false; - - srand(time(NULL)); - - currentPlaying = rand() % PlayList.size(); - - //just in case - if (currentPlaying < 0) - currentPlaying = PlayList.size() - 1; - else if (currentPlaying >= (int) PlayList.size()) currentPlaying = 0; - - snprintf(Settings.ogg_path, sizeof(Settings.ogg_path), "%s%s", currentPath, PlayList.at(currentPlaying)); - - if (!GuiSound::Load(Settings.ogg_path)) return false; - - Play(); - - return true; -} - -void GuiBGM::UpdateState() -{ - if (!IsPlaying()) - { - if (loopMode == DIR_LOOP) - { - PlayNext(); - } - else if (loopMode == RANDOM_BGM) - { - PlayRandom(); - } - } -} diff --git a/source/SoundOperations/gui_bgm.h b/source/SoundOperations/gui_bgm.h deleted file mode 100644 index 741ce36a..00000000 --- a/source/SoundOperations/gui_bgm.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * SettingsPrompts - * USB Loader GX 2009 - * - * Backgroundmusic - ***************************************************************************/ - -#ifndef _BGM_H_ -#define _BGM_H_ - -#include -#include "gui_sound.h" - -enum -{ - ONCE = 0, LOOP, RANDOM_BGM, DIR_LOOP -}; - -class GuiBGM: public GuiSound -{ - public: - GuiBGM(const u8 *s, int l, int v); - ~GuiBGM(); - bool Load(const char *path); - bool LoadStandard(); - bool ParsePath(const char * folderpath); - bool PlayNext(); - bool PlayPrevious(); - bool PlayRandom(); - void SetLoop(u8 l); - void UpdateState(); - protected: - void AddEntrie(const char * filename); - void ClearList(); - - int currentPlaying; - int loopMode; - char * currentPath; - std::vector PlayList; -}; - -#endif diff --git a/source/SoundOperations/gui_sound.cpp b/source/SoundOperations/gui_sound.cpp deleted file mode 100644 index 350ecaaf..00000000 --- a/source/SoundOperations/gui_sound.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include "libwiigui/gui.h" -#include "utils/uncompress.h" -#include "FileOperations/fileops.h" -#include "SoundHandler.hpp" -#include "WavDecoder.hpp" - -#define MAX_SND_VOICES 16 - -static bool VoiceUsed[MAX_SND_VOICES] = -{ - true, false, false, false, false, false, - false, false, false, false, false, false, - false, false, false, false -}; - -static inline int GetFirstUnusedVoice() -{ - for(int i = 1; i < MAX_SND_VOICES; i++) - { - if(VoiceUsed[i] == false) - return i; - } - - return -1; -} - -extern "C" void SoundCallback(s32 voice) -{ - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return; - - if(decoder->IsBufferReady()) - { - if(ASND_AddVoice(voice, decoder->GetBuffer(), decoder->GetBufferSize()) == SND_OK) - { - decoder->LoadNext(); - SoundHandler::Instance()->ThreadSignal(); - } - } - else if(decoder->IsEOF()) - { - ASND_StopVoice(voice); - //if(voice == 0) - //MusicPlayer::Instance()->SetPlaybackFinished(true); //see if next music must be played - } - else - { - SoundHandler::Instance()->ThreadSignal(); - } -} - -GuiSound::GuiSound(const char * filepath) -{ - sound = NULL; - length = 0; - voice = GetFirstUnusedVoice(); - if(voice > 0) - VoiceUsed[voice] = true; - - volume = 255; - SoundEffectLength = 0; - loop = false; - allocated = false; - Load(filepath); -} - -GuiSound::GuiSound(const u8 * snd, s32 len, int vol, bool isallocated, int v) -{ - sound = NULL; - length = 0; - if(v < 0) - voice = GetFirstUnusedVoice(); - else - voice = v; - - if(voice > 0) - VoiceUsed[voice] = true; - - volume = vol; - SoundEffectLength = 0; - loop = false; - allocated = false; - Load(snd, len, isallocated); -} - -GuiSound::~GuiSound() -{ - FreeMemory(); - if(voice > 0) - VoiceUsed[voice] = false; -} - -void GuiSound::FreeMemory() -{ - this->Stop(); - - SoundHandler::Instance()->RemoveDecoder(voice); - - if(allocated && sound != NULL) - { - free(sound); - sound = NULL; - allocated = false; - } - - SoundEffectLength = 0; -} - -bool GuiSound::Load(const char * filepath) -{ - FreeMemory(); - - if(!filepath) - return false; - - u32 magic; - FILE * f = fopen(filepath, "rb"); - if(!f) - return false; - - fread(&magic, 1, 4, f); - fclose(f); - - if(magic == 'IMD5') - { - u8 * snd = NULL; - u64 filesize = 0; - LoadFileToMem(filepath, &snd, &filesize); - return Load(snd, filesize, true); - } - - SoundHandler::Instance()->AddDecoder(voice, filepath); - - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return false; - - if(!decoder->IsBufferReady()) - { - SoundHandler::Instance()->RemoveDecoder(voice); - return false; - } - - SetLoop(loop); - - return true; -} - -bool GuiSound::Load(const u8 * snd, s32 len, bool isallocated) -{ - FreeMemory(); - - if(!snd) - return false; - - if(!isallocated && *((u32 *) snd) == 'RIFF') - { - return LoadSoundEffect(snd, len); - } - - if(*((u32 *) snd) == 'IMD5') - { - UncompressSoundbin(snd, len, isallocated); - } - else - { - sound = (u8 *) snd; - length = len; - allocated = isallocated; - } - - SoundHandler::Instance()->AddDecoder(voice, sound, length); - - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return false; - - if(!decoder->IsBufferReady()) - { - SoundHandler::Instance()->RemoveDecoder(voice); - return false; - } - - SetLoop(loop); - - return true; -} - -bool GuiSound::LoadSoundEffect(const u8 * snd, s32 len) -{ - WavDecoder decoder(snd, len); - decoder.Rewind(); - - u32 done = 0; - sound = (u8 *) malloc(4096); - memset(sound, 0, 4096); - - while(1) - { - u8 * tmpsnd = (u8 *) realloc(sound, done+4096); - if(!tmpsnd) - { - free(sound); - sound = NULL; - return false; - } - - sound = tmpsnd; - - int read = decoder.Read(sound+done, 4096, done); - if(read <= 0) - break; - - done += read; - } - - sound = (u8 *) realloc(sound, done); - SoundEffectLength = done; - allocated = true; - - return true; -} - -void GuiSound::Play() -{ - if(SoundEffectLength > 0) - { - ASND_StopVoice(voice); - ASND_SetVoice(voice, VOICE_STEREO_16BIT, 32000, 0, sound, SoundEffectLength, volume, volume, NULL); - return; - } - - if(IsPlaying()) - return; - - if(voice < 0 || voice >= 16) - return; - - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return; - - if(decoder->IsEOF()) - { - ASND_StopVoice(voice); - decoder->ClearBuffer(); - decoder->Rewind(); - decoder->Decode(); - } - - u8 * curbuffer = decoder->GetBuffer(); - int bufsize = decoder->GetBufferSize(); - decoder->LoadNext(); - SoundHandler::Instance()->ThreadSignal(); - - ASND_SetVoice(voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, volume, volume, SoundCallback); -} - -void GuiSound::Stop() -{ - if(voice < 0 || voice >= 16) - return; - - ASND_StopVoice(voice); - - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return; - - decoder->ClearBuffer(); - Rewind(); - SoundHandler::Instance()->ThreadSignal(); -} - -void GuiSound::Pause() -{ - if(voice < 0 || voice >= 16) - return; - - ASND_StopVoice(voice); -} - -void GuiSound::Resume() -{ - Play(); -} - -bool GuiSound::IsPlaying() -{ - if(voice < 0 || voice >= 16) - return false; - - int result = ASND_StatusVoice(voice); - - if(result == SND_WORKING || result == SND_WAITING) - return true; - - return false; -} - -void GuiSound::SetVolume(int vol) -{ - if(voice < 0 || voice >= 16) - return; - - if(vol < 0) - return; - - volume = 255*(vol/100.0); - ASND_ChangeVolumeVoice(voice, volume, volume); -} - -void GuiSound::SetLoop(u8 l) -{ - loop = l; - - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return; - - decoder->SetLoop(l == 1); -} - -void GuiSound::Rewind() -{ - SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); - if(!decoder) - return; - - decoder->Rewind(); -} - -void GuiSound::UncompressSoundbin(const u8 * snd, int len, bool isallocated) -{ - const u8 * file = snd+32; - if(*((u32 *) file) == 'LZ77') - { - u32 size = 0; - sound = uncompressLZ77(file, len-32, &size); - length = size; - } - else - { - length = len-32; - sound = (u8 *) malloc(length); - memcpy(sound, file, length); - } - - if(isallocated) - free((u8 *) snd); - - allocated = true; -} diff --git a/source/SoundOperations/gui_sound.h b/source/SoundOperations/gui_sound.h deleted file mode 100644 index 1101b16b..00000000 --- a/source/SoundOperations/gui_sound.h +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef GUI_SOUND_H_ -#define GUI_SOUND_H_ - -#include - -//!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc -class GuiSound -{ - public: - //!Constructor - //!\param sound Pointer to the sound data - //!\param filesize Length of sound data - GuiSound(const char * filepath); - GuiSound(const u8 * sound, int filesize, int volume, bool allocated = false, int voice = -1); - //!Destructor - ~GuiSound(); - //!Load a file and replace the old one - bool Load(const char * filepath); - //!Load a file and replace the old one - bool Load(const u8 * sound, int filesize, bool allocated = true); - //!For quick playback of the internal soundeffects - bool LoadSoundEffect(const u8 * snd, s32 len); - //!Start sound playback - void Play(); - //!Stop sound playback - void Stop(); - //!Pause sound playback - void Pause(); - //!Resume sound playback - void Resume(); - //!Checks if the sound is currently playing - //!\return true if sound is playing, false otherwise - bool IsPlaying(); - //!Rewind the music - void Rewind(); - //!Set sound volume - //!\param v Sound volume (0-100) - void SetVolume(int v); - //!\param l Loop (true to loop) - void SetLoop(u8 l); - //!Special sound case for sound.bin - void UncompressSoundbin(const u8 * snd, int len, bool isallocated); - protected: - //!Stops sound and frees all memory/closes files - void FreeMemory(); - u8 * sound; //!< Pointer to the sound data - int length; //!< Length of sound data - s32 voice; //!< Currently assigned ASND voice channel - int volume; //!< Sound volume (0-100) - u8 loop; //!< Loop sound playback - u32 SoundEffectLength; //!< Check if it is an app soundeffect for faster playback - bool allocated; //!< Is the file allocated or not -}; - -#endif diff --git a/source/ZipFile.cpp b/source/ZipFile.cpp deleted file mode 100644 index 46764376..00000000 --- a/source/ZipFile.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2009 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * ZipFile.cpp - * - * ZipFile Class - * for Wii-FileXplorer 2009 - * - * STILL UNCOMPLETE AND UNDER CONSTRUCTION - ***************************************************************************/ -#include -#include -#include -#include -#include - -#include "prompts/ProgressWindow.h" -#include "FileOperations/fileops.h" -#include "ZipFile.h" -#include "language/gettext.h" - -ZipFile::ZipFile(const char *filepath) -{ - File = unzOpen(filepath); - if (File) this->LoadList(); -} - -ZipFile::~ZipFile() -{ - unzClose(File); -} - -bool ZipFile::LoadList() -{ - return true; -} - -bool ZipFile::ExtractAll(const char *dest) -{ - if (!File) return false; - - bool Stop = false; - - u32 blocksize = 1024 * 50; - u8 *buffer = new u8[blocksize]; - - if (!buffer) return false; - - char writepath[MAXPATHLEN]; - char filename[MAXPATHLEN]; - memset(filename, 0, sizeof(filename)); - - int ret = unzGoToFirstFile(File); - if (ret != UNZ_OK) Stop = true; - - while (!Stop) - { - if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK) Stop - = true; - - if (!Stop && filename[strlen(filename) - 1] != '/') - { - u32 uncompressed_size = cur_file_info.uncompressed_size; - - u32 done = 0; - char *pointer = NULL; - - ret = unzOpenCurrentFile(File); - - snprintf(writepath, sizeof(writepath), "%s/%s", dest, filename); - - pointer = strrchr(writepath, '/'); - int position = pointer - writepath + 2; - - char temppath[strlen(writepath)]; - snprintf(temppath, position, "%s", writepath); - - CreateSubfolder(temppath); - - if (ret == UNZ_OK) - { - FILE *pfile = fopen(writepath, "wb"); - - do - { - ShowProgress(tr( "Extracting files..." ), 0, pointer + 1, done, uncompressed_size); - - if (uncompressed_size - done < blocksize) blocksize = uncompressed_size - done; - - ret = unzReadCurrentFile(File, buffer, blocksize); - - if (ret == 0) break; - - fwrite(buffer, 1, blocksize, pfile); - - done += ret; - - } while (done < uncompressed_size); - - fclose(pfile); - unzCloseCurrentFile(File); - } - } - if (unzGoToNextFile(File) != UNZ_OK) Stop = true; - } - - delete[] buffer; - buffer = NULL; - - ProgressStop(); - - return true; -} diff --git a/source/ZipFile.h b/source/ZipFile.h deleted file mode 100644 index 7e714625..00000000 --- a/source/ZipFile.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * ZipFile.cpp - * - * for Wii-FileXplorer 2009 - ***************************************************************************/ -#ifndef _ZIPFILE_H_ -#define _ZIPFILE_H_ - -#include - -typedef struct -{ - u64 offset; // ZipFile offset - u64 length; // uncompressed file length in 64 bytes for sizes higher than 4GB - bool isdir; // 0 - file, 1 - directory - char filename[256]; // full filename -} FileStructure; - -class ZipFile -{ - public: - //!Constructor - ZipFile(const char *filepath); - //!Destructor - ~ZipFile(); - //!Extract all files from a zip file to a directory - //!\param dest Destination path to where to extract - bool ExtractAll(const char *dest); - protected: - bool LoadList(); - unzFile File; - unz_file_info cur_file_info; - FileStructure *FileList; -}; - -#endif diff --git a/source/audio.cpp b/source/audio.cpp deleted file mode 100644 index e1e3acae..00000000 --- a/source/audio.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * audio.cpp - * Audio support - ***************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * InitAudio - * - * Initializes the Wii's audio subsystem - ***************************************************************************/ -void InitAudio() -{ - AUDIO_Init(NULL); - ASND_Init(); - ASND_Pause(0); -} - -/**************************************************************************** - * ShutdownAudio - * - * Shuts down audio subsystem. Useful to avoid unpleasant sounds if a - * crash occurs during shutdown. - ***************************************************************************/ -void ShutdownAudio() -{ - ASND_Pause(1); - ASND_End(); -} diff --git a/source/audio.h b/source/audio.h deleted file mode 100644 index 6efdf6d5..00000000 --- a/source/audio.h +++ /dev/null @@ -1,15 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * audio.h - * Audio support - ***************************************************************************/ - -#ifndef _AUDIO_H_ -#define _AUDIO_H_ - -void InitAudio(); -void ShutdownAudio(); - -#endif diff --git a/source/banner/MD5.c b/source/banner/MD5.c deleted file mode 100644 index c672db10..00000000 --- a/source/banner/MD5.c +++ /dev/null @@ -1,608 +0,0 @@ -/* ========================================================================== ** - * - * MD5.c - * - * Copyright: - * Copyright (C) 2003-2005 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * - * $Id: MD5.c,v 0.6 2005/06/08 18:35:59 crh Exp $ - * - * - * Modifications and additions by dimok - * - * -------------------------------------------------------------------------- ** - * - * Description: - * Implements the MD5 hash algorithm, as described in RFC 1321. - * - * -------------------------------------------------------------------------- ** - * - * License: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * -------------------------------------------------------------------------- ** - * - * Notes: - * - * None of this will make any sense unless you're studying RFC 1321 as you - * read the code. - * - * MD5 is described in RFC 1321. - * The MD*4* algorithm is described in RFC 1320 (that's 1321 - 1). - * MD5 is very similar to MD4, but not quite similar enough to justify - * putting the two into a single module. Besides, I wanted to add a few - * extra functions to this one to expand its usability. - * - * There are three primary motivations for this particular implementation. - * 1) Programmer's pride. I wanted to be able to say I'd done it, and I - * wanted to learn from the experience. - * 2) Portability. I wanted an implementation that I knew to be portable - * to a reasonable number of platforms. In particular, the algorithm is - * designed with little-endian platforms in mind, but I wanted an - * endian-agnostic implementation. - * 3) Compactness. While not an overriding goal, I thought it worth-while - * to see if I could reduce the overall size of the result. This is in - * keeping with my hopes that this library will be suitable for use in - * some embedded environments. - * Beyond that, cleanliness and clarity are always worth pursuing. - * - * As mentioned above, the code really only makes sense if you are familiar - * with the MD5 algorithm or are using RFC 1321 as a guide. This code is - * quirky, however, so you'll want to be reading carefully. - * - * Yeah...most of the comments are cut-and-paste from my MD4 implementation. - * - * -------------------------------------------------------------------------- ** - * - * References: - * IETF RFC 1321: The MD5 Message-Digest Algorithm - * Ron Rivest. IETF, April, 1992 - * - * ========================================================================== ** - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "MD5.h" - -/* -------------------------------------------------------------------------- ** - * Static Constants: - * - * K[][] - In round one, the values of k (which are used to index - * particular four-byte sequences in the input) are simply - * sequential. In later rounds, however, they are a bit more - * varied. Rather than calculate the values of k (which may - * or may not be possible--I haven't though about it) the - * values are stored in this array. - * - * S[][] - In each round there is a left rotate operation performed as - * part of the 16 permutations. The number of bits varies in - * a repeating patter. This array keeps track of the patterns - * used in each round. - * - * T[][] - There are four rounds of 16 permutations for a total of 64. - * In each of these 64 permutation operations, a different - * constant value is added to the mix. The constants are - * based on the sine function...read RFC 1321 for more detail. - * In any case, the correct constants are stored in the T[][] - * array. They're divided up into four groups of 16. - */ - -static const uint8_t K[3][16] = { -/* Round 1: skipped (since it is simply sequential). */ -{ 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12 }, /* R2 */ -{ 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2 }, /* R3 */ -{ 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 } /* R4 */ -}; - -static const uint8_t S[4][4] = { { 7, 12, 17, 22 }, /* Round 1 */ -{ 5, 9, 14, 20 }, /* Round 2 */ -{ 4, 11, 16, 23 }, /* Round 3 */ -{ 6, 10, 15, 21 } /* Round 4 */ -}; - -static const uint32_t T[4][16] = { { 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, /* Round 1 */ -0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, - 0xa679438e, 0x49b40821 }, - -{ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, /* Round 2 */ -0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, - 0x676f02d9, 0x8d2a4c8a }, - -{ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, /* Round 3 */ -0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, - 0x1fa27cf8, 0xc4ac5665 }, - -{ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, /* Round 4 */ -0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, - 0x2ad7d2bb, 0xeb86d391 }, }; - -/* -------------------------------------------------------------------------- ** - * Macros: - * md5F(), md5G(), md5H(), and md5I() are described in RFC 1321. - * All of these operations are bitwise, and so not impacted by endian-ness. - * - * GetLongByte() - * Extract one byte from a (32-bit) longword. A value of 0 for - * indicates the lowest order byte, while 3 indicates the highest order - * byte. - * - */ - -#define md5F( X, Y, Z ) ( ((X) & (Y)) | ((~(X)) & (Z)) ) -#define md5G( X, Y, Z ) ( ((X) & (Z)) | ((Y) & (~(Z))) ) -#define md5H( X, Y, Z ) ( (X) ^ (Y) ^ (Z) ) -#define md5I( X, Y, Z ) ( (Y) ^ ((X) | (~(Z))) ) - -#define GetLongByte( L, idx ) ((unsigned char)(( L >> (((idx) & 0x03) << 3) ) & 0xFF)) - -#define STR2HEX(x) ((x >= 0x30) && (x <= 0x39)) ? x - 0x30 : toupper((int)x)-0x37 - -/* -------------------------------------------------------------------------- ** - * Static Functions: - */ - -static void Permute(uint32_t ABCD[4], const unsigned char block[64]) -/* ------------------------------------------------------------------------ ** - * Permute the ABCD "registers" using the 64-byte as a driver. - * - * Input: ABCD - Pointer to an array of four unsigned longwords. - * block - An array of bytes, 64 bytes in size. - * - * Output: none. - * - * Notes: The MD5 algorithm operates on a set of four longwords stored - * (conceptually) in four "registers". It is easy to imagine a - * simple MD4/5 chip that would operate this way. In any case, - * the mangling of the contents of those registers is driven by - * the input message. The message is chopped and finally padded - * into 64-byte chunks and each chunk is used to manipulate the - * contents of the registers. - * - * The MD5 Algorithm calls for padding the input to ensure that - * it is a multiple of 64 bytes in length. The last 16 bytes - * of the padding space are used to store the message length - * (the length of the original message, before padding, expressed - * in terms of bits). If there is not enough room for 16 bytes - * worth of bitcount (eg., if the original message was 122 bytes - * long) then the block is padded to the end with zeros and - * passed to this function. Then *another* block is filled with - * zeros except for the last 16 bytes which contain the length. - * - * Oh... and the algorithm requires that there be at least one - * padding byte. The first padding byte has a value of 0x80, - * and any others are 0x00. - * - * ------------------------------------------------------------------------ ** - */ -{ - int round; - int i, j; - uint8_t s; - uint32_t a, b, c, d; - uint32_t KeepABCD[4]; - uint32_t X[16]; - - /* Store the current ABCD values for later re-use. - */ - for (i = 0; i < 4; i++) - KeepABCD[i] = ABCD[i]; - - /* Convert the input block into an array of unsigned longs, taking care - * to read the block in Little Endian order (the algorithm assumes this). - * The uint32_t values are then handled in host order. - */ - for (i = 0, j = 0; i < 16; i++) - { - X[i] = (uint32_t) block[j++]; - X[i] |= ((uint32_t) block[j++] << 8); - X[i] |= ((uint32_t) block[j++] << 16); - X[i] |= ((uint32_t) block[j++] << 24); - } - - /* This loop performs the four rounds of permutations. - * The rounds are each very similar. The differences are in three areas: - * - The function (F, G, H, or I) used to perform bitwise permutations - * on the registers, - * - The order in which values from X[] are chosen. - * - Changes to the number of bits by which the registers are rotated. - * This implementation uses a switch statement to deal with some of the - * differences between rounds. Other differences are handled by storing - * values in arrays and using the round number to select the correct set - * of values. - * - * (My implementation appears to be a poor compromise between speed, size, - * and clarity. Ugh. [crh]) - */ - for (round = 0; round < 4; round++) - { - for (i = 0; i < 16; i++) - { - j = (4 - (i % 4)) & 0x3; /* handles the rotation of ABCD. */ - s = S[round][i % 4]; /* is the bit shift for this iteration. */ - - b = ABCD[(j + 1) & 0x3]; /* Copy the b,c,d values per ABCD rotation. */ - c = ABCD[(j + 2) & 0x3]; /* This isn't really necessary, it just looks */ - d = ABCD[(j + 3) & 0x3]; /* clean & will hopefully be optimized away. */ - - /* The actual perumation function. - * This is broken out to minimize the code within the switch(). - */ - switch (round) - { - case 0: - /* round 1 */ - a = md5F( b, c, d ) + X[i]; - break; - case 1: - /* round 2 */ - a = md5G( b, c, d ) + X[K[0][i]]; - break; - case 2: - /* round 3 */ - a = md5H( b, c, d ) + X[K[1][i]]; - break; - default: - /* round 4 */ - a = md5I( b, c, d ) + X[K[2][i]]; - break; - } - a = 0xFFFFFFFF & (ABCD[j] + a + T[round][i]); - ABCD[j] = b + (0xFFFFFFFF & ((a << s) | (a >> (32 - s)))); - } - } - - /* Use the stored original A, B, C, D values to perform - * one last convolution. - */ - for (i = 0; i < 4; i++) - ABCD[i] = 0xFFFFFFFF & (ABCD[i] + KeepABCD[i]); - -} /* Permute */ - -/* -------------------------------------------------------------------------- ** - * Functions: - */ - -auth_md5Ctx *auth_md5InitCtx(auth_md5Ctx *ctx) -/* ------------------------------------------------------------------------ ** - * Initialize an MD5 context. - * - * Input: ctx - A pointer to the MD5 context structure to be initialized. - * Contexts are typically created thusly: - * ctx = (auth_md5Ctx *)malloc( sizeof(auth_md5Ctx) ); - * - * Output: A pointer to the initialized context (same as ). - * - * Notes: The purpose of the context is to make it possible to generate - * an MD5 Message Digest in stages, rather than having to pass a - * single large block to a single MD5 function. The context - * structure keeps track of various bits of state information. - * - * Once the context is initialized, the blocks of message data - * are passed to the function. Once the - * final bit of data has been handed to the - * context can be closed out by calling , - * which also calculates the final MD5 result. - * - * Don't forget to free an allocated context structure when - * you've finished using it. - * - * See Also: , - * - * ------------------------------------------------------------------------ ** - */ -{ - ctx->len = 0; - ctx->b_used = 0; - - ctx->ABCD[0] = 0x67452301; /* The array ABCD[] contains the four 4-byte */ - ctx->ABCD[1] = 0xefcdab89; /* "registers" that are manipulated to */ - ctx->ABCD[2] = 0x98badcfe; /* produce the MD5 digest. The input acts */ - ctx->ABCD[3] = 0x10325476; /* upon the registers, not the other way */ - /* 'round. The initial values are those */ - /* given in RFC 1321 (pg. 4). Note, however, that RFC 1321 */ - /* provides these values as bytes, not as longwords, and the */ - /* bytes are arranged in little-endian order as if they were */ - /* the bytes of (little endian) 32-bit ints. That's */ - /* confusing as all getout (to me, anyway). The values given */ - /* here are provided as 32-bit values in C language format, */ - /* so they are endian-agnostic. */ - return (ctx); -} /* auth_md5InitCtx */ - -auth_md5Ctx *auth_md5SumCtx(auth_md5Ctx *ctx, const unsigned char *src, const int len) -/* ------------------------------------------------------------------------ ** - * Build an MD5 Message Digest within the given context. - * - * Input: ctx - Pointer to the context in which the MD5 sum is being - * built. - * src - A chunk of source data. This will be used to drive - * the MD5 algorithm. - * len - The number of bytes in . - * - * Output: A pointer to the updated context (same as ). - * - * See Also: , , - * - * ------------------------------------------------------------------------ ** - */ -{ - int i; - - /* Add the new block's length to the total length. - */ - ctx->len += (uint32_t) len; - - /* Copy the new block's data into the context block. - * Call the Permute() function whenever the context block is full. - */ - for (i = 0; i < len; i++) - { - ctx->block[ctx->b_used] = src[i]; - (ctx->b_used)++; - if (64 == ctx->b_used) - { - Permute(ctx->ABCD, ctx->block); - ctx->b_used = 0; - } - } - - /* Return the updated context. - */ - return (ctx); -} /* auth_md5SumCtx */ - -auth_md5Ctx *auth_md5CloseCtx(auth_md5Ctx *ctx, unsigned char *dst) -/* ------------------------------------------------------------------------ ** - * Close an MD5 Message Digest context and generate the final MD5 sum. - * - * Input: ctx - Pointer to the context in which the MD5 sum is being - * built. - * dst - A pointer to at least 16 bytes of memory, which will - * receive the finished MD5 sum. - * - * Output: A pointer to the closed context (same as ). - * You might use this to free a malloc'd context structure. :) - * - * Notes: The context () is returned in an undefined state. - * It must be re-initialized before re-use. - * - * See Also: , - * - * ------------------------------------------------------------------------ ** - */ -{ - int i; - uint32_t l; - - /* Add the required 0x80 padding initiator byte. - * The auth_md5SumCtx() function always permutes and resets the context - * block when it gets full, so we know that there must be at least one - * free byte in the context block. - */ - ctx->block[ctx->b_used] = 0x80; - (ctx->b_used)++; - - /* Zero out any remaining free bytes in the context block. - */ - for (i = ctx->b_used; i < 64; i++) - ctx->block[i] = 0; - - /* We need 8 bytes to store the length field. - * If we don't have 8, call Permute() and reset the context block. - */ - if (56 < ctx->b_used) - { - Permute(ctx->ABCD, ctx->block); - for (i = 0; i < 64; i++) - ctx->block[i] = 0; - } - - /* Add the total length and perform the final perumation. - * Note: The 60'th byte is read from the *original* len> value - * and shifted to the correct position. This neatly avoids - * any MAXINT numeric overflow issues. - */ - l = ctx->len << 3; - for (i = 0; i < 4; i++) - ctx->block[56 + i] |= GetLongByte( l, i ); - ctx->block[60] = ((GetLongByte( ctx->len, 3 ) & 0xE0) >> 5); /* See Above! */ - Permute(ctx->ABCD, ctx->block); - - /* Now copy the result into the output buffer and we're done. - */ - for (i = 0; i < 4; i++) - { - dst[0 + i] = GetLongByte( ctx->ABCD[0], i ); - dst[4 + i] = GetLongByte( ctx->ABCD[1], i ); - dst[8 + i] = GetLongByte( ctx->ABCD[2], i ); - dst[12 + i] = GetLongByte( ctx->ABCD[3], i ); - } - - /* Return the context. - * This is done for compatibility with the other auth_md5*Ctx() functions. - */ - return (ctx); -} /* auth_md5CloseCtx */ - -unsigned char * MD5(unsigned char *dst, const unsigned char *src, const int len) -/* ------------------------------------------------------------------------ ** - * Compute an MD5 message digest. - * - * Input: dst - Destination buffer into which the result will be written. - * Must be 16 bytes, minimum. - * src - Source data block to be MD5'd. - * len - The length, in bytes, of the source block. - * (Note that the length is given in bytes, not bits.) - * - * Output: A pointer to , which will contain the calculated 16-byte - * MD5 message digest. - * - * Notes: This function is a shortcut. It takes a single input block. - * For more drawn-out operations, see . - * - * This function is interface-compatible with the - * function in the MD4 module. - * - * The MD5 algorithm is designed to work on data with an - * arbitrary *bit* length. Most implementations, this one - * included, handle the input data in byte-sized chunks. - * - * The MD5 algorithm does much of its work using four-byte - * words, and so can be tuned for speed based on the endian-ness - * of the host. This implementation is intended to be - * endian-neutral, which may make it a teeny bit slower than - * others. ...maybe. - * - * See Also: - * - * ------------------------------------------------------------------------ ** - */ -{ - auth_md5Ctx ctx[1]; - - (void) auth_md5InitCtx(ctx); /* Open a context. */ - (void) auth_md5SumCtx(ctx, src, len); /* Pass only one block. */ - (void) auth_md5CloseCtx(ctx, dst); /* Close the context. */ - - return (dst); /* Makes life easy. */ -} /* auth_md5Sum */ - -unsigned char * MD5fromFile(unsigned char *dst, const char *src) -/* ------------------------------------------------------------------------ ** - * Compute an MD5 message digest. - * - * Input: dst - Destination buffer into which the result will be written. - * Must be 16 bytes, minimum. - * src - filepath of the file to be checked - * - * Output: A pointer to , which will contain the calculated 16-byte - * MD5 message digest. - * - * Notes: This function is a shortcut. It takes a single input block. - * For more drawn-out operations, see . - * - * This function is interface-compatible with the - * function in the MD4 module. - * - * The MD5 algorithm is designed to work on data with an - * arbitrary *bit* length. Most implementations, this one - * included, handle the input data in byte-sized chunks. - * - * The MD5 algorithm does much of its work using four-byte - * words, and so can be tuned for speed based on the endian-ness - * of the host. This implementation is intended to be - * endian-neutral, which may make it a teeny bit slower than - * others. ...maybe. - * - * See Also: - * - * ------------------------------------------------------------------------ ** - */ -{ - auth_md5Ctx ctx[1]; - - FILE * file; - unsigned int blksize = 0; - unsigned int read = 0; - - file = fopen(src, "rb"); - - if (file == NULL) - { - return NULL; - } - - (void) auth_md5InitCtx(ctx); /* Open a context. */ - - fseek(file, 0, SEEK_END); - unsigned long long filesize = ftell(file); - rewind(file); - - if (filesize < 1048576) //1MB cache for files bigger than 1 MB - blksize = filesize; - else blksize = 1048576; - - unsigned char * buffer = malloc(blksize); - - if (buffer == NULL) - { - //no memory - fclose(file); - return NULL; - } - - do - { - read = fread(buffer, 1, blksize, file); - (void) auth_md5SumCtx(ctx, buffer, read); /* Pass only one block. */ - - } while (read > 0); - - fclose(file); - free(buffer); - - (void) auth_md5CloseCtx(ctx, dst); /* Close the context. */ - - return (dst); /* Makes life easy. */ -} /* auth_md5Sum */ - -const char * MD5ToString(const unsigned char * hash, char * dst) -{ - char hexchar[3]; - short i = 0, n = 0; - - for (i = 0; i < 16; i++) - { - sprintf(hexchar, "%02X", hash[i]); - - dst[n++] = hexchar[0]; - dst[n++] = hexchar[1]; - } - - dst[n] = 0x00; - - return dst; -} - -unsigned char * StringToMD5(const char * hash, unsigned char * dst) -{ - char hexchar[2]; - short i = 0, n = 0; - - for (i = 0; i < 16; i++) - { - hexchar[0] = hash[n++]; - hexchar[1] = hash[n++]; - - dst[i] = STR2HEX( hexchar[0] ); - dst[i] <<= 4; - dst[i] += STR2HEX( hexchar[1] ); - } - - return dst; -} - -/* ========================================================================== */ diff --git a/source/banner/MD5.h b/source/banner/MD5.h deleted file mode 100644 index 07902c2b..00000000 --- a/source/banner/MD5.h +++ /dev/null @@ -1,241 +0,0 @@ -#ifndef MD5_H -#define MD5_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* ========================================================================== ** - * - * MD5.h - * - * Copyright: - * Copyright (C) 2003-2005 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * - * $Id: MD5.h,v 0.6 2005/06/08 18:35:59 crh Exp $ - * - * Modifications and additions by dimok - * - * -------------------------------------------------------------------------- ** - * - * Description: - * Implements the MD5 hash algorithm, as described in RFC 1321. - * - * -------------------------------------------------------------------------- ** - * - * License: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * -------------------------------------------------------------------------- ** - * - * Notes: - * - * None of this will make any sense unless you're studying RFC 1321 as you - * read the code. - * - * MD5 is described in RFC 1321. - * The MD*4* algorithm is described in RFC 1320 (that's 1321 - 1). - * MD5 is very similar to MD4, but not quite similar enough to justify - * putting the two into a single module. Besides, I wanted to add a few - * extra functions to this one to expand its usability. - * - * There are three primary motivations for this particular implementation. - * 1) Programmer's pride. I wanted to be able to say I'd done it, and I - * wanted to learn from the experience. - * 2) Portability. I wanted an implementation that I knew to be portable - * to a reasonable number of platforms. In particular, the algorithm is - * designed with little-endian platforms in mind, but I wanted an - * endian-agnostic implementation. - * 3) Compactness. While not an overriding goal, I thought it worth-while - * to see if I could reduce the overall size of the result. This is in - * keeping with my hopes that this library will be suitable for use in - * some embedded environments. - * Beyond that, cleanliness and clarity are always worth pursuing. - * - * As mentioned above, the code really only makes sense if you are familiar - * with the MD5 algorithm or are using RFC 1321 as a guide. This code is - * quirky, however, so you'll want to be reading carefully. - * - * Yeah...most of the comments are cut-and-paste from my MD4 implementation. - * - * -------------------------------------------------------------------------- ** - * - * References: - * IETF RFC 1321: The MD5 Message-Digest Algorithm - * Ron Rivest. IETF, April, 1992 - * - * ========================================================================== ** - */ - /* -------------------------------------------------------------------------- ** - * Typedefs: - */ - - typedef struct - { - unsigned int len; - unsigned int ABCD[4]; - int b_used; - unsigned char block[64]; - } auth_md5Ctx; - - /* -------------------------------------------------------------------------- ** - * Functions: - */ - - auth_md5Ctx *auth_md5InitCtx(auth_md5Ctx *ctx); - /* ------------------------------------------------------------------------ ** - * Initialize an MD5 context. - * - * Input: ctx - A pointer to the MD5 context structure to be initialized. - * Contexts are typically created thusly: - * ctx = (auth_md5Ctx *)malloc( sizeof(auth_md5Ctx) ); - * - * Output: A pointer to the initialized context (same as ). - * - * Notes: The purpose of the context is to make it possible to generate - * an MD5 Message Digest in stages, rather than having to pass a - * single large block to a single MD5 function. The context - * structure keeps track of various bits of state information. - * - * Once the context is initialized, the blocks of message data - * are passed to the function. Once the - * final bit of data has been handed to the - * context can be closed out by calling , - * which also calculates the final MD5 result. - * - * Don't forget to free an allocated context structure when - * you've finished using it. - * - * See Also: , - * - * ------------------------------------------------------------------------ ** - */ - - auth_md5Ctx *auth_md5SumCtx(auth_md5Ctx *ctx, const unsigned char *src, const int len); - /* ------------------------------------------------------------------------ ** - * Build an MD5 Message Digest within the given context. - * - * Input: ctx - Pointer to the context in which the MD5 sum is being - * built. - * src - A chunk of source data. This will be used to drive - * the MD5 algorithm. - * len - The number of bytes in . - * - * Output: A pointer to the updated context (same as ). - * - * See Also: , , - * - * ------------------------------------------------------------------------ ** - */ - - auth_md5Ctx *auth_md5CloseCtx(auth_md5Ctx *ctx, unsigned char *dst); - /* ------------------------------------------------------------------------ ** - * Close an MD5 Message Digest context and generate the final MD5 sum. - * - * Input: ctx - Pointer to the context in which the MD5 sum is being - * built. - * dst - A pointer to at least 16 bytes of memory, which will - * receive the finished MD5 sum. - * - * Output: A pointer to the closed context (same as ). - * You might use this to free a malloc'd context structure. :) - * - * Notes: The context () is returned in an undefined state. - * It must be re-initialized before re-use. - * - * See Also: , - * - * ------------------------------------------------------------------------ ** - */ - - unsigned char * MD5(unsigned char * hash, const unsigned char *src, const int len); - /* ------------------------------------------------------------------------ ** - * Compute an MD5 message digest. - * - * Input: dst - Destination buffer into which the result will be written. - * Must be 16 bytes, minimum. - * src - Source data block to be MD5'd. - * len - The length, in bytes, of the source block. - * (Note that the length is given in bytes, not bits.) - * - * Output: A pointer to , which will contain the calculated 16-byte - * MD5 message digest. - * - * Notes: This function is a shortcut. It takes a single input block. - * For more drawn-out operations, see . - * - * This function is interface-compatible with the - * function in the MD4 module. - * - * The MD5 algorithm is designed to work on data with an - * arbitrary *bit* length. Most implementations, this one - * included, handle the input data in byte-sized chunks. - * - * The MD5 algorithm does much of its work using four-byte - * words, and so can be tuned for speed based on the endian-ness - * of the host. This implementation is intended to be - * endian-neutral, which may make it a teeny bit slower than - * others. ...maybe. - * - * See Also: - * - * ------------------------------------------------------------------------ ** - */ - - unsigned char * MD5fromFile(unsigned char *dst, const char *src); - /* ------------------------------------------------------------------------ ** - * Compute an MD5 message digest. - * - * Input: dst - Destination buffer into which the result will be written. - * Must be 16 bytes, minimum. - * src - filepath to the file to be MD5'd. - * - * Output: A pointer to , which will contain the calculated 16-byte - * MD5 message digest. - * - * Notes: This function is a shortcut. It takes a single input block. - * For more drawn-out operations, see . - * - * This function is interface-compatible with the - * function in the MD4 module. - * - * The MD5 algorithm is designed to work on data with an - * arbitrary *bit* length. Most implementations, this one - * included, handle the input data in byte-sized chunks. - * - * The MD5 algorithm does much of its work using four-byte - * words, and so can be tuned for speed based on the endian-ness - * of the host. This implementation is intended to be - * endian-neutral, which may make it a teeny bit slower than - * others. ...maybe. - * - * See Also: - * - * ------------------------------------------------------------------------ ** - */ - - const char * MD5ToString(const unsigned char *hash, char *dst); - unsigned char * StringToMD5(const char * hash, unsigned char * dst); - -/* ========================================================================== */ - -#ifdef __cplusplus -} -#endif -#endif /* AUTH_MD5_H */ diff --git a/source/banner/gui_banner.cpp b/source/banner/gui_banner.cpp deleted file mode 100644 index 200d5095..00000000 --- a/source/banner/gui_banner.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** - * USB Loader GX Team - * gui_banner.cpp - * - * Shows TPL Banner images - ***************************************************************************/ -#include "gui_banner.h" - -GuiBanner::GuiBanner(const char *tplfilepath) -{ - memory = NULL; - tplfilesize = 0; - width = 0; - height = 0; - - FILE *tplfp = fopen(tplfilepath, "rb"); - - if (tplfp != NULL) - { - - unsigned short heighttemp = 0; - unsigned short widthtemp = 0; - - fseek(tplfp, 0x14, SEEK_SET); - fread((void*) &heighttemp, 1, 2, tplfp); - fread((void*) &widthtemp, 1, 2, tplfp); - fseek(tplfp, 0, SEEK_END); - tplfilesize = ftell(tplfp); - rewind(tplfp); - memory = memalign(32, tplfilesize); - if (!memory) - { - fclose(tplfp); - return; - } - fread(memory, 1, tplfilesize, tplfp); - fclose(tplfp); - - TPLFile tplfile; - int ret; - - ret = TPL_OpenTPLFromMemory(&tplfile, memory, tplfilesize); - if (ret < 0) - { - free(memory); - memory = NULL; - return; - } - ret = TPL_GetTexture(&tplfile, 0, &texObj); - if (ret < 0) - { - free(memory); - memory = NULL; - return; - } - TPL_CloseTPLFile(&tplfile); - - width = widthtemp; - height = heighttemp; - widescreen = 0; - filecheck = true; - - } - else - { - filecheck = false; - fclose(tplfp); - } -} - -GuiBanner::GuiBanner(void *mem, u32 len, int w, int h) -{ - if (!mem || !len) return; - memory = mem; - tplfilesize = len; - width = w; - height = h; - - TPLFile tplfile; - - int ret; - - ret = TPL_OpenTPLFromMemory(&tplfile, memory, tplfilesize); - if (ret < 0) - { - free(memory); - memory = NULL; - return; - } - ret = TPL_GetTexture(&tplfile, 0, &texObj); - if (ret < 0) - { - free(memory); - memory = NULL; - return; - } - TPL_CloseTPLFile(&tplfile); - - filecheck = true; -} - -GuiBanner::~GuiBanner() -{ - if (memory != NULL) - { - free(memory); - memory = NULL; - } -} - -void GuiBanner::Draw() -{ - LOCK( this ); - if (!filecheck || !this->IsVisible()) return; - - float currScale = this->GetScale(); - - Menu_DrawTPLImg(this->GetLeft(), this->GetTop(), 0, width, height, &texObj, imageangle, widescreen ? currScale - * 0.80 : currScale, currScale, this->GetAlpha(), xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4); - - this->UpdateEffects(); -} diff --git a/source/banner/gui_banner.h b/source/banner/gui_banner.h deleted file mode 100644 index 42a9cb67..00000000 --- a/source/banner/gui_banner.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * USB Loader GX Team - * gui_banner.h - * - * Shows TPL Banner images - ***************************************************************************/ - -#ifndef _GUIBANNER_H_ -#define _GUIBANNER_H_ - -#include "libwiigui/gui.h" - -class GuiBanner: public GuiImage -{ - public: - //!Constructor - //!\param tplfilepath Path of the tpl file - GuiBanner(const char *tplfilepath); - //!Constructor - //!\param mem Memory of the loaded tpl - //!\param len Filesize of the tpl - //!\param w Width of the tpl - //!\param h Height of the tpl - GuiBanner(void *mem, u32 len, int w, int h); - //!Destructor - ~GuiBanner(); - void Draw(); - protected: - void * memory; - bool filecheck; - u32 tplfilesize; - GXTexObj texObj; -}; - -#endif /* _GUIBANNER_H_ */ diff --git a/source/banner/openingbnr.c b/source/banner/openingbnr.c deleted file mode 100644 index b1ab8aca..00000000 --- a/source/banner/openingbnr.c +++ /dev/null @@ -1,562 +0,0 @@ -/**************************************************************************** - * USB Loader GX Team - * openingbnr - * - * Extract opening.bnr/banner.bin/sound.bin/icon.bin - * - * Copyright 2008 Magicus - * Licensed under the terms of the GNU GPL, version 2 - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt - * Version 1.0 Initial release - ***************************************************************************/ - -#define _GNU_SOURCE - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "MD5.h" -#include "openingbnr.h" -#include "FileOperations/fileops.h" - -u16 be16(const u8 *p) -{ - return (p[0] << 8) | p[1]; -} - -u32 be32(const u8 *p) -{ - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; -} - -u64 be64(const u8 *p) -{ - return ((u64) be32(p) << 32) | be32(p + 4); -} - -u64 be34(const u8 *p) -{ - return 4 * (u64) be32(p); -} - -void wbe16(u8 *p, u16 x) -{ - p[0] = x >> 8; - p[1] = x; -} - -void wbe32(u8 *p, u32 x) -{ - wbe16(p, x >> 16); - wbe16(p + 2, x); -} - -void wbe64(u8 *p, u64 x) -{ - wbe32(p, x >> 32); - wbe32(p + 4, x); -} - -void md5(u8 *data, u32 len, u8 *hash) -{ - MD5(hash, data, len); -} - -typedef struct -{ - u8 zeroes[0x40]; - u32 imet; // "IMET" - u8 zero_six_zero_three[8]; // fixed, unknown purpose - u32 sizes[3]; - u32 flag1; - u16 name_jp[0x2a]; // might be empty - u16 name_en[0x2a]; - u16 name_de[0x2a]; - u16 name_fr[0x2a]; - u16 name_es[0x2a]; - u16 name_it[0x2a]; - u16 name_nl[0x2a]; - u8 zeroes_2[0x348]; - u8 crypto[0x10]; -} imet_data_t; - -typedef struct -{ - u32 imd5_tag; // 0x494D4435 "IMD5"; - u32 size; // size of the rest of part B, starting from next field. - u8 zeroes[8]; - u8 md5[16]; - u32 payload_tag; // 0x4C5A3737 "LZ77" if this is lz77 - u32 payload_data; -} imd5_header_t; - -typedef struct -{ - u16 type; - u16 name_offset; - u32 data_offset; // == absolut offset frn U.8- headerns brjan - u32 size; // last included file num for directories -} U8_node; - -typedef struct -{ - u32 tag; // 0x55AA382D "U.8-" - u32 rootnode_offset; // offset to root_node, always 0x20. - u32 header_size; // size of header from root_node to end of string table. - u32 data_offset; // offset to data -- this is rootnode_offset + header_size, aligned to 0x40. - u8 zeroes[16]; -} U8_archive_header; - -static int write_file(void* data, size_t size, char* name) -{ - size_t written = 0; - FILE *out; - out = fopen(name, "wb"); - if (out) - { - written = fwrite(data, 1, size, out); - fclose(out); - } - return (written == size) ? 1 : -1; -} - -u8* decompress_lz77(u8 *data, size_t data_size, size_t* decompressed_size) -{ - u8 *data_end; - u8 *decompressed_data; - size_t unpacked_size; - u8 *in_ptr; - u8 *out_ptr; - u8 *out_end; - - in_ptr = data; - data_end = data + data_size; - - // Assume this for now and grow when needed - unpacked_size = data_size; - - decompressed_data = malloc(unpacked_size); - out_end = decompressed_data + unpacked_size; - - out_ptr = decompressed_data; - - while (in_ptr < data_end) - { - int bit; - u8 bitmask = *in_ptr; - - in_ptr++; - for (bit = 0x80; bit != 0; bit >>= 1) - { - if (bitmask & bit) - { - // Next section is compressed - u8 rep_length; - u16 rep_offset; - - rep_length = (*in_ptr >> 4) + 3; - rep_offset = *in_ptr & 0x0f; - in_ptr++; - rep_offset = *in_ptr | (rep_offset << 8); - in_ptr++; - if (out_ptr - decompressed_data < rep_offset) - { - return NULL; - } - - for (; rep_length > 0; rep_length--) - { - *out_ptr = out_ptr[-rep_offset - 1]; - out_ptr++; - if (out_ptr >= out_end) - { - // Need to grow buffer - decompressed_data = realloc(decompressed_data, unpacked_size * 2); - out_ptr = decompressed_data + unpacked_size; - unpacked_size *= 2; - out_end = decompressed_data + unpacked_size; - } - } - } - else - { - // Just copy byte - *out_ptr = *in_ptr; - out_ptr++; - if (out_ptr >= out_end) - { - // Need to grow buffer - decompressed_data = realloc(decompressed_data, unpacked_size * 2); - out_ptr = decompressed_data + unpacked_size; - unpacked_size *= 2; - out_end = decompressed_data + unpacked_size; - } - in_ptr++; - } - } - } - - *decompressed_size = (out_ptr - decompressed_data); - return decompressed_data; -} - -static int write_imd5_lz77(u8* data, size_t size, char* outname) -{ - imd5_header_t* header = (imd5_header_t*) data; - u32 tag; - u32 size_in_imd5; - u8 md5_calc[16]; - u8 *decompressed_data; - size_t decompressed_size; - - tag = be32((u8*) &header->imd5_tag); - if (tag != 0x494D4435) - { - return -4; - } - - md5(data + 32, size - 32, md5_calc); - if (memcmp(&header->md5, md5_calc, 0x10)) - { - return -5; - } - - size_in_imd5 = be32((u8*) &header->size); - if (size_in_imd5 != size - 32) - { - return -6; - } - - tag = be32((u8*) &header->payload_tag); - if (tag == 0x4C5A3737) - { - // "LZ77" - uncompress - decompressed_data = decompress_lz77(data + sizeof(imd5_header_t), size - sizeof(imd5_header_t), - &decompressed_size); - if (decompressed_data == NULL) return -7; - write_file(decompressed_data, decompressed_size, outname); - //printf(", uncompressed %d bytes, md5 ok", decompressed_size); - - free(decompressed_data); - } - else - { - write_file(&header->payload_tag, size - 32, outname); - //printf(", md5 ok"); - } - return 0; -} - -static int do_U8_archive(FILE *fp) -{ - U8_archive_header header; - U8_node root_node; - u32 tag; - u32 num_nodes; - U8_node* nodes; - u8* string_table; - size_t rest_size; - unsigned int i; - u32 data_offset; - u32 current_offset; - u16 dir_stack[16]; - int dir_index = 0; - - fread(&header, 1, sizeof header, fp); - tag = be32((u8*) &header.tag); - if (tag != 0x55AA382D) - { - return -1; - } - - fread(&root_node, 1, sizeof(root_node), fp); - num_nodes = be32((u8*) &root_node.size) - 1; - //printf("Number of files: %d\n", num_nodes); - - nodes = malloc(sizeof(U8_node) * (num_nodes)); - fread(nodes, 1, num_nodes * sizeof(U8_node), fp); - - data_offset = be32((u8*) &header.data_offset); - rest_size = data_offset - sizeof(header) - (num_nodes + 1) * sizeof(U8_node); - - string_table = malloc(rest_size); - fread(string_table, 1, rest_size, fp); - current_offset = data_offset; - - for (i = 0; i < num_nodes; i++) - { - U8_node* node = &nodes[i]; - u16 type = be16((u8*) &node->type); - u16 name_offset = be16((u8*) &node->name_offset); - u32 my_data_offset = be32((u8*) &node->data_offset); - u32 size = be32((u8*) &node->size); - char* name = (char*) &string_table[name_offset]; - u8* file_data; - - if (type == 0x0100) - { - // Directory - mkdir(name, 0777); - chdir(name); - dir_stack[++dir_index] = size; - //printf("%*s%s/\n", dir_index, "", name); - } - else - { - // Normal file - u8 padding[32]; - - if (type != 0x0000) - { - free(string_table); - return -2; - } - - if (current_offset < my_data_offset) - { - int diff = my_data_offset - current_offset; - - if (diff > 32) - { - free(string_table); - return -3; - } - fread(padding, 1, diff, fp); - current_offset += diff; - } - - file_data = malloc(size); - fread(file_data, 1, size, fp); - //printf("%*s %s (%d bytes", dir_index, "", name, size); - int result; - result = write_imd5_lz77(file_data, size, name); - if (result < 0) - { - free(string_table); - return result; - } - //printf(")\n"); - current_offset += size; - } - - while (dir_stack[dir_index] == i + 2 && dir_index > 0) - { - chdir(".."); - dir_index--; - } - } - free(string_table); - return 0; -} - -static void do_imet_header(FILE *fp) -{ - imet_data_t header; - - fread(&header, 1, sizeof header, fp); - - write_file(&header, sizeof(header), "header.imet"); -} - -void do_U8_archivebanner(FILE *fp) -{ - U8_archive_header header; - U8_node root_node; - u32 tag; - u32 num_nodes; - U8_node* nodes; - u8* string_table; - size_t rest_size; - unsigned int i; - u32 data_offset; - u16 dir_stack[16]; - int dir_index = 0; - - fread(&header, 1, sizeof header, fp); - tag = be32((u8*) &header.tag); - if (tag != 0x55AA382D) - { - //printf("No U8 tag"); - exit(0); - } - - fread(&root_node, 1, sizeof(root_node), fp); - num_nodes = be32((u8*) &root_node.size) - 1; - printf("Number of files: %d\n", num_nodes); - - nodes = malloc(sizeof(U8_node) * (num_nodes)); - fread(nodes, 1, num_nodes * sizeof(U8_node), fp); - - data_offset = be32((u8*) &header.data_offset); - rest_size = data_offset - sizeof(header) - (num_nodes + 1) * sizeof(U8_node); - - string_table = malloc(rest_size); - fread(string_table, 1, rest_size, fp); - - for (i = 0; i < num_nodes; i++) - { - U8_node* node = &nodes[i]; - u16 type = be16((u8*) &node->type); - u16 name_offset = be16((u8*) &node->name_offset); - u32 my_data_offset = be32((u8*) &node->data_offset); - u32 size = be32((u8*) &node->size); - char* name = (char*) &string_table[name_offset]; - u8* file_data; - - if (type == 0x0100) - { - // Directory - mkdir(name, 0777); - chdir(name); - dir_stack[++dir_index] = size; - //printf("%*s%s/\n", dir_index, "", name); - } - else - { - // Normal file - - if (type != 0x0000) - { - printf("Unknown type"); - exit(0); - } - - fseek(fp, my_data_offset, SEEK_SET); - file_data = malloc(size); - fread(file_data, 1, size, fp); - write_file(file_data, size, name); - free(file_data); - //printf("%*s %s (%d bytes)\n", dir_index, "", name, size); - } - - while (dir_stack[dir_index] == i + 2 && dir_index > 0) - { - chdir(".."); - dir_index--; - } - } - free(string_table); -} - -int extractbnrfile(const char * filepath, const char * destpath) -{ - int ret = -1; - FILE *fp = fopen(filepath, "rb"); - if (fp) - { - CreateSubfolder(destpath); - chdir(destpath); - - do_imet_header(fp); - ret = do_U8_archive(fp); - - fclose(fp); - } - return ret; -} - -int unpackBin(const char * filename, const char * outdir) -{ - FILE *fp = fopen(filename, "rb"); - ; - if (fp) - { - CreateSubfolder(outdir); - chdir(outdir); - - do_U8_archivebanner(fp); - fclose(fp); - return 1; - } - return 0; -} - -#if 0 - -#define TMP_PATH(s) "BANNER:/dump"s -//#define TMP_PATH(s) "SD:/dump"s - -int unpackBanner(const u8 *gameid, int what, const char *outdir) -{ - - char path[256]; - if (!ramdiskMount("BANNER", NULL)) return -1; - - CreateSubfolder(TMP_PATH( "/" )); - s32 ret = dump_banner(gameid, TMP_PATH( "/opening.bnr" )); - if (ret != 1) - { - ret = -1; - goto error2; - } - - ret = extractbnrfile(TMP_PATH( "/opening.bnr" ), TMP_PATH( "/" )); - if (ret != 0) - { - ret = -1; - goto error2; - } - - if (what & UNPACK_BANNER_BIN) - { - snprintf(path, sizeof(path), "%sbanner/", outdir); - ret = unpackBin(TMP_PATH( "/meta/banner.bin" ), path); - if (ret != 1) - { - ret = -1; - goto error2; - } - } - if (what & UNPACK_ICON_BIN) - { - snprintf(path, sizeof(path), "%sicon/", outdir); - ret = unpackBin(TMP_PATH( "/meta/icon.bin" ), path); - if (ret != 1) - { - ret = -1; - goto error2; - } - } - if (what & UNPACK_SOUND_BIN) - { - snprintf(path, sizeof(path), "%ssound.bin", outdir); - FILE *fp = fopen(TMP_PATH( "/meta/sound.bin" ), "rb"); - if (fp) - { - size_t size; - u8 *data; - fseek(fp, 0, SEEK_END); - size = ftell(fp); - if (!size) - { - ret = -1; - goto error; - } - fseek(fp, 0, SEEK_SET); - data = (u8 *) malloc(size); - if (!data) - { - ret = -1; - goto error; - } - if (fread(data, 1, size, fp) != size) - { - ret = -1; - goto error; - } - ret = write_file(data, size, path); - } - error: fclose(fp); - } - ramdiskUnmount("BANNER"); - error2: if (ret < 0) return ret; - return 1; -} -#endif diff --git a/source/banner/openingbnr.h b/source/banner/openingbnr.h deleted file mode 100644 index dd36354c..00000000 --- a/source/banner/openingbnr.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * USB Loader GX Team - * openingbnr - * - * Extract opening.bnr/banner.bin/sound.bin/icon.bin - ***************************************************************************/ - -#ifndef _OPENINGBNR_H_ -#define _OPENINGBNR_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /*********************************************************** - * Error description: - * 0 Successfully extracted - * -1 No U8 tag - * -2 Unknown type - * -3 Archive inconsistency, too much padding - * -4 No IMD5 tag - * -5 MD5 mismatch - * -6 Size mismatch - * -7 Inconsistency in LZ77 encoding - ************************************************************/ - - //! Extract opening.bnr from filepath to destpath - //! Files extracted: banner.bin icon.bin and sound.bin - int extractbnrfile(const char * filepath, const char * destpath); - int unpackBin(const char * filename, const char * outdir); -#define UNPACK_BANNER_BIN 1 /* extract banner.bin to outdir/banner/ */ -#define UNPACK_ICON_BIN 2 /* extract icon.bin to outdir/icon/ */ -#define UNPACK_SOUND_BIN 4 /* copies sound.bin to outdir/sound.bin */ -#define UNPACK_ALL (UNPACK_SOUND_BIN | UNPACK_ICON_BIN | UNPACK_BANNER_BIN) - //int unpackBanner(const u8 * gameid, int what, const char *outdir); - //! Extract the lz77 compressed banner, icon and sound .bin - u8* decompress_lz77(u8 *data, size_t data_size, size_t* decompressed_size); - - u16 be16(const u8 *p); - u32 be32(const u8 *p); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/bannersound.cpp b/source/bannersound.cpp deleted file mode 100644 index 8a6939ff..00000000 --- a/source/bannersound.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include -#include -#include -#include - -#include "usbloader/disc.h" -#include "usbloader/wbfs.h" -#include "prompts/PromptWindows.h" -#include "libs/libwbfs/libwbfs.h" -#include "language/gettext.h" -#include "bannersound.h" -#include "utils/uncompress.h" - -struct IMD5Header -{ - u32 fcc; - u32 filesize; - u8 zeroes[8]; - u8 crypto[16]; -}__attribute__( ( packed ) ); - -struct IMETHeader -{ - u8 zeroes[64]; - u32 fcc; - u8 unk[8]; - u32 iconSize; - u32 bannerSize; - u32 soundSize; - u32 flag1; - u8 names[7][84]; - u8 zeroes_2[0x348]; - u8 crypto[16]; -}__attribute__( ( packed ) ); - -struct U8Header -{ - u32 fcc; - u32 rootNodeOffset; - u32 headerSize; - u32 dataOffset; - u8 zeroes[16]; -}__attribute__( ( packed ) ); - -struct U8Entry -{ - struct - { - u32 fileType :8; - u32 nameOffset :24; - }; - u32 fileOffset; - union - { - u32 fileLength; - u32 numEntries; - }; -}__attribute__( ( packed ) ); - -struct LZ77Info -{ - u16 length :4; - u16 offset :12; -}__attribute__( ( packed ) ); - -static char *u8Filename(const U8Entry *fst, int i) -{ - return (char *) (fst + fst[0].numEntries) + fst[i].nameOffset; -} - -const u8 *LoadBannerSound(const u8 *discid, u32 *size) -{ - if (!discid) return NULL; - - wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) discid); - if (!disc) - { - // WindowPrompt(tr("Can't find disc"), 0, tr("OK")); - return NULL; - } - wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc); - if (!wdisc) - { - //WindowPrompt(tr("Could not open Disc"), 0, tr("OK")); - return NULL; - } - u8 * opening_bnr = wd_extract_file(wdisc, ALL_PARTITIONS, (char *) "opening.bnr"); - if (!opening_bnr) - { - //WindowPrompt(tr("ERROR"), tr("Failed to extract opening.bnr"), tr("OK")); - return NULL; - } - - wd_close_disc(wdisc); - WBFS_CloseDisc(disc); - - const U8Entry *fst; - - const IMETHeader *imetHdr = (IMETHeader *) opening_bnr; - if (imetHdr->fcc != 0x494D4554 /*"IMET"*/) - { - // WindowPrompt(tr("IMET Header wrong."), 0, tr("OK")); - free(opening_bnr); - return NULL; - } - const U8Header *bnrArcHdr = (U8Header *) (imetHdr + 1); - - fst = (const U8Entry *) (((const u8 *) bnrArcHdr) + bnrArcHdr->rootNodeOffset); - u32 i; - for (i = 1; i < fst[0].numEntries; ++i) - if (fst[i].fileType == 0 && strcasecmp(u8Filename(fst, i), "sound.bin") == 0) break; - if (i >= fst[0].numEntries) - { - /* Not all games have a sound.bin and this message is annoying **/ - //WindowPrompt(tr("sound.bin not found."), 0, tr("OK")); - free(opening_bnr); - return NULL; - } - const u8 *sound_bin = ((const u8 *) bnrArcHdr) + fst[i].fileOffset; - if (((IMD5Header *) sound_bin)->fcc != 0x494D4435 /*"IMD5"*/) - { - // WindowPrompt(tr("IMD5 Header not right."), 0, tr("OK")); - free(opening_bnr); - return NULL; - } - const u8 *soundChunk = sound_bin + sizeof(IMD5Header); - ; - u32 soundChunkSize = fst[i].fileLength - sizeof(IMD5Header); - - if (*((u32*) soundChunk) == 0x4C5A3737 /*"LZ77"*/) - { - u32 uncSize = 0; - u8 * uncompressed_data = uncompressLZ77(soundChunk, soundChunkSize, &uncSize); - if (!uncompressed_data) - { - // WindowPrompt(tr("Can't decompress LZ77"), 0, tr("OK")); - free(opening_bnr); - return NULL; - } - if (size) *size = uncSize; - free(opening_bnr); - return uncompressed_data; - } - u8 *out = (u8 *) malloc(soundChunkSize); - if (out) - { - memcpy(out, soundChunk, soundChunkSize); - if (size) *size = soundChunkSize; - } - free(opening_bnr); - return out; -} diff --git a/source/bannersound.h b/source/bannersound.h deleted file mode 100644 index b6da62d1..00000000 --- a/source/bannersound.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef BANNERSOUND_H -#define BANNERSOUND_H - -const u8 *LoadBannerSound(const u8 *discid, u32 *size); - -#endif /* BANNERSOUND_H */ diff --git a/source/cheats/cheatmenu.cpp b/source/cheats/cheatmenu.cpp deleted file mode 100644 index 18cbf681..00000000 --- a/source/cheats/cheatmenu.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include - -#include -#include "libwiigui/gui.h" -#include "libwiigui/gui_customoptionbrowser.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "themes/CTheme.h" -#include "fatmounter.h" -#include "FileOperations/fileops.h" -#include "menu.h" -#include "filelist.h" -#include "sys.h" -#include "gct.h" - -/*** Extern functions ***/ -extern void ResumeGui(); -extern void HaltGui(); - -/*** Extern variables ***/ -extern GuiWindow * mainWindow; - -/**************************************************************************** - * CheatMenu - ***************************************************************************/ -int CheatMenu(const char * gameID) -{ - int choice = 0; - bool exit = false; - int ret = 1; - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - GuiImage settingsbackground(&settingsbg); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage backBtnImg(&btnOutline); - GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -140, 400, &trigA, NULL, btnSoundClick2, 1); - backBtn.SetLabel(&backBtnTxt); - backBtn.SetTrigger(&trigB); - - GuiText createBtnTxt(tr( "Create" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - createBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage createBtnImg(&btnOutline); - GuiButton createBtn(&createBtnImg, &createBtnImg, 2, 3, 160, 400, &trigA, NULL, btnSoundClick2, 1); - createBtn.SetLabel(&createBtnTxt); - - char txtfilename[55]; - snprintf(txtfilename, sizeof(txtfilename), "%s%s.txt", Settings.TxtCheatcodespath, gameID); - - GCTCheats c; - int check = c.openTxtfile(txtfilename); - - int download = 0; - - switch (check) - { - case -1: - WindowPrompt(tr( "Error" ), tr( "Cheatfile is blank" ), tr( "OK" )); - break; - case 0: - download = WindowPrompt(tr( "Error" ), tr( "No Cheatfile found" ), tr( "Download Now" ), tr( "Cancel" )); - if (download == 1) - { - download = CodeDownload(gameID); - if (download < 0 || c.openTxtfile(txtfilename) != 1) break; - } - else break; - case 1: - int cntcheats = c.getCnt(); - OptionList cheatslst; - GuiCustomOptionBrowser chtBrowser(400, 280, &cheatslst, "bg_options_settings.png"); - chtBrowser.SetPosition(0, 90); - chtBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - chtBrowser.SetClickable(true); - - GuiText titleTxt(c.getGameName().c_str(), 28, ( GXColor ) {0, 0, 0, 255}); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetMaxWidth(350, SCROLL_HORIZONTAL); - titleTxt.SetPosition(12, 40); - - for (int i = 0; i <= cntcheats; i++) - { - cheatslst.SetValue(i, "%s", c.getCheatName(i).c_str()); - cheatslst.SetName(i, "OFF"); - } - - HaltGui(); - GuiWindow w(screenwidth, screenheight); - w.Append(&settingsbackground); - w.Append(&titleTxt); - w.Append(&backBtn); - w.Append(&createBtn); - w.Append(&chtBrowser); - mainWindow->SetState(STATE_DISABLED); - mainWindow->ChangeFocus(&w); - mainWindow->Append(&w); - ResumeGui(); - - while (!exit) - { - VIDEO_WaitVSync(); - - ret = chtBrowser.GetClickedOption(); - if (ret != -1) - { - const char *strCheck = cheatslst.GetName(ret); - if (strncmp(strCheck, "ON", 2) == 0) - { - cheatslst.SetName(ret, "%s", "OFF"); - } - else if (strncmp(strCheck, "OFF", 3) == 0) - { - cheatslst.SetName(ret, "%s", "ON"); - } - } - - if (createBtn.GetState() == STATE_CLICKED) - { - createBtn.ResetState(); - if (cntcheats > 0) - { - int selectednrs[30]; - int x = 0; - for (int i = 0; i <= cntcheats; i++) - { - const char *strCheck = cheatslst.GetName(i); - if (strncmp(strCheck, "ON", 2) == 0) - { - selectednrs[x] = i; - x++; - } - } - if (x == 0) - { - WindowPrompt(tr( "Error" ), tr( "No cheats were selected" ), tr( "OK" )); - } - else - { - CreateSubfolder(Settings.Cheatcodespath); - string chtpath = Settings.Cheatcodespath; - string gctfname = chtpath + c.getGameID() + ".gct"; - c.createGCT(selectednrs, x, gctfname.c_str()); - WindowPrompt(tr( "GCT File created" ), NULL, tr( "OK" )); - exit = true; - break; - } - } - else WindowPrompt(tr( "Error" ), tr( "Could not create GCT file" ), tr( "OK" )); - } - - if (backBtn.GetState() == STATE_CLICKED) - { - backBtn.ResetState(); - exit = true; - break; - } - } - HaltGui(); - mainWindow->SetState(STATE_DEFAULT); - mainWindow->Remove(&w); - ResumeGui(); - break; - } - - return choice; -} diff --git a/source/cheats/cheatmenu.h b/source/cheats/cheatmenu.h deleted file mode 100644 index d087d9c6..00000000 --- a/source/cheats/cheatmenu.h +++ /dev/null @@ -1,13 +0,0 @@ -/**************************************************************************** - * Cheat Menu - * USB Loader GX 2009 - * - * cheatmenu.h - ***************************************************************************/ - -#ifndef _CHEATMENU_H_ -#define _CHEATMENU_H_ - -int CheatMenu(const char * gameID); - -#endif diff --git a/source/cheats/gct.cpp b/source/cheats/gct.cpp deleted file mode 100644 index b2a71f20..00000000 --- a/source/cheats/gct.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* - * gct.h - * Class to handle Ocarina TXT Cheatfiles - * nIxx - */ - -#include -#include -#include -#include -#include "gct.h" - -#define ERRORRANGE "Error: CheatNr out of range" - -GCTCheats::GCTCheats(void) -{ - iCntCheats = 0; -} - -GCTCheats::~GCTCheats(void) -{ - - string sGameID = ""; - string sGameTitle = ""; - /*string sCheatName[MAXCHEATS]; - string sCheats[MAXCHEATS]; - string sCheatComment[MAXCHEATS];*/ -} - -int GCTCheats::getCnt() -{ - return iCntCheats; -} - -string GCTCheats::getGameName(void) -{ - return sGameTitle; -} - -string GCTCheats::getGameID(void) -{ - return sGameID; -} - -string GCTCheats::getCheat(int nr) -{ - if (nr <= (iCntCheats - 1)) - { - return sCheats[nr]; - } - else - { - return ERRORRANGE; - } -} - -string GCTCheats::getCheatName(int nr) -{ - if (nr <= (iCntCheats - 1)) - { - return sCheatName[nr]; - } - else - { - return ERRORRANGE; - } -} - -string GCTCheats::getCheatComment(int nr) -{ - if (nr <= (iCntCheats - 1)) - { - return sCheatComment[nr]; - } - else - { - return ERRORRANGE; - } -} - -int GCTCheats::createGCT(int nr, const char * filename) -{ - - if (nr == 0) return 0; - - ofstream filestr; - filestr.open(filename); - - if (filestr.fail()) return 0; - - //Header and Footer - char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde }; - char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - string buf = getCheat(nr); - filestr.write(header, sizeof(header)); - - int x = 0; - long int li; - int len = buf.size(); - - while (x < len) - { - string temp = buf.substr(x, 2); - li = strtol(temp.c_str(), NULL, 16); - temp = li; - filestr.write(temp.c_str(), 1); - x += 2; - } - filestr.write(footer, sizeof(footer)); - - filestr.close(); - return 1; -} - -int GCTCheats::createGCT(const char * chtbuffer, const char * filename) -{ - - ofstream filestr; - filestr.open(filename); - - if (filestr.fail()) return 0; - - //Header and Footer - char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde }; - char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - string buf = chtbuffer; - filestr.write(header, sizeof(header)); - - int x = 0; - long int li; - int len = buf.size(); - - while (x < len) - { - string temp = buf.substr(x, 2); - li = strtol(temp.c_str(), NULL, 16); - temp = li; - filestr.write(temp.c_str(), 1); - x += 2; - } - - filestr.write(footer, sizeof(footer)); - - filestr.close(); - - return 1; -} - -int GCTCheats::createGCT(int nr[], int cnt, const char * filename) -{ - - if (cnt == 0) return 0; - - ofstream filestr; - filestr.open(filename); - - if (filestr.fail()) return 0; - - //Header and Footer - char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde }; - char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - filestr.write(header, sizeof(header)); - - int c = 0; - while (c != cnt) - { - int actnr = nr[c]; - string buf = getCheat(actnr); - long int li; - int len = buf.size(); - int x = 0; - - while (x < len) - { - string temp = buf.substr(x, 2); - li = strtol(temp.c_str(), NULL, 16); - temp = li; - filestr.write(temp.c_str(), 1); - x += 2; - } - c++; - } - - filestr.write(footer, sizeof(footer)); - filestr.close(); - return 1; -} - -int GCTCheats::openTxtfile(const char * filename) -{ - ifstream filestr; - int i = 0; - string str; - filestr.open(filename); - - if (filestr.fail()) return 0; - - filestr.seekg(0, ios_base::end); - int size = filestr.tellg(); - if (size <= 0) return -1; - filestr.seekg(0, ios_base::beg); - - getline(filestr, sGameID); - if (sGameID[sGameID.length() - 1] == '\r') sGameID.erase(sGameID.length() - 1); - - getline(filestr, sGameTitle); - if (sGameTitle[sGameTitle.length() - 1] == '\r') sGameTitle.erase(sGameTitle.length() - 1); - - getline(filestr, sCheatName[i]); // skip first line if file uses CRLF - if (!sGameTitle[sGameTitle.length() - 1] == '\r') filestr.seekg(0, ios_base::beg); - - while (!filestr.eof()) - { - getline(filestr, sCheatName[i]); // '\n' delimiter by default - if (sCheatName[i][sCheatName[i].length() - 1] == '\r') sCheatName[i].erase(sCheatName[i].length() - 1); - - string cheatdata; - bool emptyline = false; - - do - { - getline(filestr, str); - if (str[str.length() - 1] == '\r') str.erase(str.length() - 1); - - if (str == "" || str[0] == '\r' || str[0] == '\n') - { - emptyline = true; - break; - } - - if (IsCode(str)) - { - // remove any garbage (comment) after code - while (str.size() > 17) - { - str.erase(str.length() - 1); - } - cheatdata.append(str); - size_t found = cheatdata.find(' '); - cheatdata.replace(found, 1, ""); - } - else - { - //printf("%i",str.size()); - sCheatComment[i] = str; - } - if (filestr.eof()) break; - - } while (!emptyline); - - sCheats[i] = cheatdata; - i++; - if (i == MAXCHEATS) break; - } - iCntCheats = i; - filestr.close(); - return 1; -} - -bool GCTCheats::IsCode(const std::string& str) -{ - if (str[8] == ' ' && str.size() >= 17) - { - // accept strings longer than 17 in case there is a comment on the same line as the code - char part1[9]; - char part2[9]; - snprintf(part1, sizeof(part1), "%c%c%c%c%c%c%c%c", str[0], str[1], str[2], str[3], str[4], str[5], str[6], - str[7]); - snprintf(part2, sizeof(part2), "%c%c%c%c%c%c%c%c", str[9], str[10], str[11], str[12], str[13], str[14], - str[15], str[16]); - if ((strtok(part1, "0123456789ABCDEFabcdef") == NULL) && (strtok(part2, "0123456789ABCDEFabcdef") == NULL)) - { - return true; - } - } - return false; -} diff --git a/source/cheats/gct.h b/source/cheats/gct.h deleted file mode 100644 index d7f0ad20..00000000 --- a/source/cheats/gct.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * gct.h - * Class to handle Ocarina TXT Cheatfiles - * - */ - -#ifndef _GCT_H -#define _GCT_H - -#include - -#define MAXCHEATS 300 - -using namespace std; - -//!Handles Ocarina TXT Cheatfiles -class GCTCheats -{ - private: - string sGameID; - string sGameTitle; - string sCheatName[MAXCHEATS]; - string sCheats[MAXCHEATS]; - string sCheatComment[MAXCHEATS]; - int iCntCheats; - - public: - //!Constructor - GCTCheats(void); - //!Destructor - ~GCTCheats(void); - //!Open txt file with cheats - //!\param filename name of TXT file - //!\return error code - int openTxtfile(const char * filename); - //!Creates GCT file for one cheat - //!\param nr selected Cheat Numbers - //!\param filename name of GCT file - //!\return error code - int createGCT(int nr, const char * filename); - //!Creates GCT file from a buffer - //!\param chtbuffer buffer that holds the cheat data - //!\param filename name of GCT file - //!\return error code - int createGCT(const char * chtbuffer, const char * filename); - //!Creates GCT file - //!\param nr[] array of selected Cheat Numbers - //!\param cnt size of array - //!\param filename name of GCT file - //!\return error code - int createGCT(int nr[], int cnt, const char * filename); - //!Gets Count cheats - //!\return Count cheats - int getCnt(); - //!Gets Game Name - //!\return Game Name - string getGameName(void); - //!Gets GameID - //!\return GameID - string getGameID(void); - //!Gets cheat data - //!\return cheat data - string getCheat(int nr); - //!Gets Cheat Name - //!\return Cheat Name - string getCheatName(int nr); - //!Gets Cheat Comment - //!\return Cheat Comment - string getCheatComment(int nr); - //!Check if string is a code - //!\return true/false - bool IsCode(const std::string& s); -}; - -#endif /* _GCT_H */ diff --git a/source/fatmounter.c b/source/fatmounter.c deleted file mode 100644 index 846c7085..00000000 --- a/source/fatmounter.c +++ /dev/null @@ -1,271 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "usbloader/usbstorage2.h" -#include "usbloader/sdhc.h" -#include "usbloader/wbfs.h" -#include "fatmounter.h" -#include "gecko.h" - -//these are the only stable and speed is good -#define CACHE 32 -#define SECTORS 64 -#define SECTORS_SD 32 - -#define MOUNT_NONE 0 -#define MOUNT_SD 1 -#define MOUNT_SDHC 2 - -#define DEBUG_FAT - -/* Disc interfaces */ -extern const DISC_INTERFACE __io_sdhc; - -extern sec_t _FAT_startSector; - -extern s32 wbfsDev; - -int fat_sd_mount = MOUNT_NONE; -sec_t fat_sd_sec = 0; // u32 - -int fat_usb_mount = 0; -sec_t fat_usb_sec = 0; - -int fat_wbfs_mount = 0; -sec_t fat_wbfs_sec = 0; - -int fs_ntfs_mount = 0; -sec_t fs_ntfs_sec = 0; - -int fs_ext_mount = 0; -sec_t fs_ext_sec = 0; - -int USBDevice_Init() -{ - //closing all open Files write back the cache and then shutdown em! - USBDevice_deInit(); - //right now mounts first FAT-partition - - bool started = false; - int retries = 10; - - // wait 0.5 sec for the USB to spin up...stupid slow ass HDD - do - { - started = (__io_usbstorage2.startup() && __io_usbstorage2.isInserted()); - usleep(50000); - --retries; - } - while(!started && retries > 0); - - if(!started) - return -1; - - if (fatMount("USB", &__io_usbstorage2, 0, CACHE, SECTORS)) - { - fat_usb_sec = _FAT_startSector; - return (fat_usb_mount = 1); - } - - return -1; -} - -int USBDevice_Init_Loop() -{ - time_t starttime = time(0); - time_t timenow = starttime; - bool StatusPrinted = false; - bool started = false; - - do - { - started = (__io_usbstorage2.startup() && __io_usbstorage2.isInserted()); - - if(!started) - { - if(timenow != time(0)) - { - timenow = time(0); - if(!StatusPrinted) - { - printf("\tWaiting for slow HDD..."); - StatusPrinted = true; - } - printf("%i ", (int) (timenow-starttime)); - } - usleep(100000); - } - } - while(!started && timenow-starttime < 30); - - if(StatusPrinted) - printf("\n"); - - return USBDevice_Init(); -} - -void USBDevice_deInit() -{ - //closing all open Files write back the cache and then shutdown em! - fatUnmount("USB:/"); - //only shutdown libogc usb and not the cios one - __io_usbstorage2.shutdown(); - - fat_usb_mount = 0; - fat_usb_sec = 0; -} - -int WBFSDevice_Init(u32 sector) -{ - //closing all open Files write back the cache and then shutdown em! - fatUnmount("WBFS:/"); - - if (!fatMount("WBFS", &__io_usbstorage2, 0, CACHE, SECTORS)) - { - return -1; - } - - fat_wbfs_mount = 1; - fat_wbfs_sec = _FAT_startSector; - - return 0; -} - -void WBFSDevice_deInit() -{ - fatUnmount("WBFS:/"); - - fat_wbfs_mount = 0; - fat_wbfs_sec = 0; -} - -int isInserted(const char *path) -{ - if (!strncmp(path, "USB:", 4)) return 1; - - return __io_sdhc.isInserted() || __io_wiisd.isInserted(); -} - -int SDCard_Init() -{ - //closing all open Files write back the cache and then shutdown em! - SDCard_deInit(); - - //right now mounts first FAT-partition - if (fatMount("SD", &__io_wiisd, 0, CACHE, SECTORS)) - { - fat_sd_mount = MOUNT_SD; - fat_sd_sec = _FAT_startSector; - return 1; - } - - __io_wiisd.shutdown(); - - if (fatMount("SD", &__io_sdhc, 0, CACHE, SECTORS)) - { - fat_sd_mount = MOUNT_SDHC; - fat_sd_sec = _FAT_startSector; - return 1; - } - - return -1; -} - -void SDCard_deInit() -{ - fatUnmount("SD:/"); - __io_wiisd.shutdown(); - __io_sdhc.shutdown(); - - fat_sd_mount = MOUNT_NONE; - fat_sd_sec = 0; -} - -s32 MountNTFS(u32 sector) -{ - s32 ret; - - if (fs_ntfs_mount) - return 0; - - if (wbfsDev == WBFS_DEVICE_USB) - { - ret = ntfsMount("NTFS", &__io_usbstorage2, sector, CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER); - if (!ret) - return -2; - } - 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); - } - else - { - ret = ntfsMount("NTFS", &__io_sdhc, 0, CACHE, SECTORS_SD, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER); - } - if (!ret) - { - return -5; - } - } - - // ntfsInit() resets locals - // which breaks unicode in console - // so we change it back to C-UTF-8 - setlocale(LC_CTYPE, "C-UTF-8"); - setlocale(LC_MESSAGES, "C-UTF-8"); - - fs_ntfs_mount = 1; - fs_ntfs_sec = sector; - - return 0; -} - -s32 UnmountNTFS(void) -{ - /* Unmount device */ - ntfsUnmount("NTFS:/", true); - - fs_ntfs_mount = 0; - fs_ntfs_sec = 0; - - return 0; -} - -s32 MountEXT(u32 sector) -{ - s32 ret; - - if (fs_ext_mount) - return 0; - - ret = ext2Mount("EXT", &__io_usbstorage2, sector, CACHE, SECTORS, EXT2_FLAG_DEFAULT); - if (!ret) - return -2; - - fs_ext_mount = 1; - fs_ext_sec = sector; - - return 0; -} - -s32 UnmountEXT(void) -{ - /* Unmount device */ - ext2Unmount("EXT:/"); - - fs_ext_mount = 0; - fs_ext_sec = 0; - - return 0; -} diff --git a/source/fatmounter.h b/source/fatmounter.h deleted file mode 100644 index 44b6a40d..00000000 --- a/source/fatmounter.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _FATMOUNTER_H_ -#define _FATMOUNTER_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include - -extern int fat_sd_mount; -extern sec_t fat_sd_sec; -extern int fat_usb_mount; -extern sec_t fat_usb_sec; -extern int fat_wbfs_mount; -extern sec_t fat_wbfs_sec; - -int USBDevice_Init(); -int USBDevice_Init_Loop(); //! Wait's for the drive before mounting it, only used on bootup -void USBDevice_deInit(); -int WBFSDevice_Init(u32 sector); -void WBFSDevice_deInit(); -int isInserted(const char *path); -int SDCard_Init(); -void SDCard_deInit(); - -s32 MountNTFS(u32 sector); -s32 UnmountNTFS(void); -s32 MountEXT(u32 sector); -s32 UnmountEXT(void); - -extern int fat_usb_mount; -extern sec_t fat_usb_sec; -extern int fat_wbfs_mount; -extern sec_t fat_wbfs_sec; -extern int fs_ntfs_mount; -extern sec_t fs_ntfs_sec; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/filelist.h b/source/filelist.h deleted file mode 100644 index 6009cb67..00000000 --- a/source/filelist.h +++ /dev/null @@ -1,553 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * imagelist.h - * Contains a list of all of the files in the images, fonts, sounds folders - ***************************************************************************/ - -#ifndef _FILELIST_H_ -#define _FILELIST_H_ - -#include - -extern const u8 font_ttf[]; -extern const u32 font_ttf_size; - -extern const u8 clock_ttf[]; -extern const u32 clock_ttf_size; - -extern const u8 closebutton_png[]; -extern const u32 closebutton_png_size; - -extern const u8 gxlogo_png[]; -extern const u32 gxlogo_png_size; - -extern const u8 sdcard_png[]; -extern const u32 sdcard_png_size; - -extern const u8 sdcard_over_png[]; -extern const u32 sdcard_over_png_size; - -extern const u8 Wifi_btn_png[]; -extern const u32 Wifi_btn_png_size; - -extern const u8 Channel_btn_png[]; -extern const u32 Channel_btn_png_size; - -extern const u8 wiimote_png[]; -extern const u32 wiimote_png_size; - -extern const u8 bg_music_ogg[]; -extern const u32 bg_music_ogg_size; - -extern const u8 credits_music_ogg[]; -extern const u32 credits_music_ogg_size; - -extern const u8 gameinfo1_png[]; -extern const u32 gameinfo1_png_size; - -extern const u8 gameinfo2_png[]; -extern const u32 gameinfo2_png_size; - -extern const u8 gameinfo1a_png[]; -extern const u32 gameinfo1a_png_size; - -extern const u8 gameinfo2a_png[]; -extern const u32 gameinfo2a_png_size; - -extern const u8 menuin_ogg[]; -extern const u32 menuin_ogg_size; - -extern const u8 menuout_ogg[]; -extern const u32 menuout_ogg_size; - -extern const u8 success_ogg[]; -extern const u32 success_ogg_size; - -extern const u8 credits_button_png[]; -extern const u32 credits_button_png_size; - -extern const u8 credits_button_over_png[]; -extern const u32 credits_button_over_png_size; - -extern const u8 button_over_wav[]; -extern const u32 button_over_wav_size; - -extern const u8 button_click_wav[]; -extern const u32 button_click_wav_size; - -extern const u8 button_click2_wav[]; -extern const u32 button_click2_wav_size; - -extern const u8 tooltip_left_png[]; -extern const u32 tooltip_left_png_size; - -extern const u8 tooltip_tile_png[]; -extern const u32 tooltip_tile_png_size; - -extern const u8 tooltip_right_png[]; -extern const u32 tooltip_right_png_size; - -extern const u8 startgame_arrow_left_png[]; -extern const u32 startgame_arrow_left_png_size; - -extern const u8 startgame_arrow_right_png[]; -extern const u32 startgame_arrow_right_png_size; - -extern const u8 credits_bg_png[]; -extern const u32 credits_bg_png_size; - -extern const u8 little_star_png[]; -extern const u32 little_star_png_size; - -extern const u8 background_png[]; -extern const u32 background_png_size; - -extern const u8 wbackground_png[]; -extern const u32 wbackground_png_size; - -extern const u8 bg_options_settings_png[]; -extern const u32 bg_options_settings_png_size; - -extern const u8 settings_background_png[]; -extern const u32 settings_background_png_size; - -extern const u8 bg_browser_png[]; -extern const u32 bg_browser_png_size; - -extern const u8 icon_folder_png[]; -extern const u32 icon_folder_png_size; - -extern const u8 bg_browser_selection_png[]; -extern const u32 bg_browser_selection_png_size; - -extern const u8 addressbar_textbox_png[]; -extern const u32 addressbar_textbox_png_size; - -extern const u8 browser_png[]; -extern const u32 browser_png_size; - -extern const u8 browser_over_png[]; -extern const u32 browser_over_png_size; - -extern const u8 nocover_png[]; -extern const u32 nocover_png_size; - -extern const u8 nocoverFlat_png[]; -extern const u32 nocoverFlat_png_size; - -extern const u8 nodisc_png[]; -extern const u32 nodisc_png_size; - -extern const u8 theme_dialogue_box_png[]; -extern const u32 theme_dialogue_box_png_size; - -extern const u8 button_install_png[]; -extern const u32 button_install_png_size; - -extern const u8 button_install_over_png[]; -extern const u32 button_install_over_png_size; - -extern const u8 dialogue_box_startgame_png[]; -extern const u32 dialogue_box_startgame_png_size; - -extern const u8 wdialogue_box_startgame_png[]; -extern const u32 wdialogue_box_startgame_png_size; - -extern const u8 button_dialogue_box_png[]; -extern const u32 button_dialogue_box_png_size; - -extern const u8 keyboard_textbox_png[]; -extern const u32 keyboard_textbox_png_size; - -extern const u8 keyboard_key_png[]; -extern const u32 keyboard_key_png_size; - -extern const u8 keyboard_key_over_png[]; -extern const u32 keyboard_key_over_png_size; - -extern const u8 keyboard_mediumkey_over_png[]; -extern const u32 keyboard_mediumkey_over_png_size; - -extern const u8 keyboard_largekey_over_png[]; -extern const u32 keyboard_largekey_over_png_size; - -extern const u8 keyboard_backspace_over_png[]; -extern const u32 keyboard_backspace_over_png_size; - -extern const u8 keyboard_clear_over_png[]; -extern const u32 keyboard_clear_over_png_size; - -extern const u8 menu_button_png[]; -extern const u32 menu_button_png_size; - -extern const u8 menu_button_over_png[]; -extern const u32 menu_button_over_png_size; - -extern const u8 settings_button_png[]; -extern const u32 settings_button_png_size; - -extern const u8 settings_button_over_png[]; -extern const u32 settings_button_over_png_size; - -extern const u8 settings_menu_button_png[]; -extern const u32 settings_menu_button_png_size; - -extern const u8 wiimote_poweroff_png[]; -extern const u32 wiimote_poweroff_png_size; - -extern const u8 dialogue_box_png[]; -extern const u32 dialogue_box_png_size; - -extern const u8 theme_box_png[]; -extern const u32 theme_box_png_size; - -extern const u8 wiimote_poweroff_over_png[]; -extern const u32 wiimote_poweroff_over_png_size; - -extern const u8 bg_options_png[]; -extern const u32 bg_options_png_size; - -extern const u8 bg_options_entry_png[]; -extern const u32 bg_options_entry_png_size; - -extern const u8 scrollbar_png[]; -extern const u32 scrollbar_png_size; - -extern const u8 scrollbar_arrowup_png[]; -extern const u32 scrollbar_arrowup_png_size; - -extern const u8 scrollbar_arrowdown_png[]; -extern const u32 scrollbar_arrowdown_png_size; - -extern const u8 scrollbar_box_png[]; -extern const u32 scrollbar_box_png_size; - -extern const u8 progressbar_png[]; -extern const u32 progressbar_png_size; - -extern const u8 progressbar_empty_png[]; -extern const u32 progressbar_empty_png_size; - -extern const u8 progressbar_outline_png[]; -extern const u32 progressbar_outline_png_size; - -extern const u8 player1_point_png[]; -extern const u32 player1_point_png_size; - -extern const u8 player2_point_png[]; -extern const u32 player2_point_png_size; - -extern const u8 player3_point_png[]; -extern const u32 player3_point_png_size; - -extern const u8 player4_point_png[]; -extern const u32 player4_point_png_size; - -extern const u8 rplayer1_point_png[]; -extern const u32 rplayer1_point_png_size; - -extern const u8 rplayer2_point_png[]; -extern const u32 rplayer2_point_png_size; - -extern const u8 rplayer3_point_png[]; -extern const u32 rplayer3_point_png_size; - -extern const u8 rplayer4_point_png[]; -extern const u32 rplayer4_point_png_size; - -extern const u8 battery_png[]; -extern const u32 battery_png_size; - -extern const u8 battery_bar_png[]; -extern const u32 battery_bar_png_size; - -extern const u8 battery_white_png[]; -extern const u32 battery_white_png_size; - -extern const u8 battery_bar_white_png[]; -extern const u32 battery_bar_white_png_size; - -extern const u8 battery_red_png[]; -extern const u32 battery_red_png_size; - -extern const u8 battery_bar_red_png[]; -extern const u32 battery_bar_red_png_size; - -extern const u8 arrow_next_png[]; -extern const u32 arrow_next_png_size; - -extern const u8 arrow_previous_png[]; -extern const u32 arrow_previous_png_size; - -extern const u8 mp3_pause_png[]; -extern const u32 mp3_pause_png_size; - -extern const u8 exit_top_png[]; -extern const u32 exit_top_png_size; - -extern const u8 exit_top_over_png[]; -extern const u32 exit_top_over_png_size; - -extern const u8 exit_bottom_png[]; -extern const u32 exit_bottom_png_size; - -extern const u8 exit_bottom_over_png[]; -extern const u32 exit_bottom_over_png_size; - -extern const u8 exit_button_png[]; -extern const u32 exit_button_png_size; - -extern const u8 mp3_stop_png[]; -extern const u32 mp3_stop_png_size; - -extern const u8 favorite_png[]; -extern const u32 favorite_png_size; - -extern const u8 not_favorite_png[]; -extern const u32 not_favorite_png_size; - -extern const u8 favIcon_png[]; -extern const u32 favIcon_png_size; - -extern const u8 favIcon_gray_png[]; -extern const u32 favIcon_gray_png_size; - -extern const u8 searchIcon_png[]; -extern const u32 searchIcon_png_size; - -extern const u8 searchIcon_gray_png[]; -extern const u32 searchIcon_gray_png_size; - -extern const u8 abcIcon_png[]; -extern const u32 abcIcon_png_size; - -extern const u8 abcIcon_gray_png[]; -extern const u32 abcIcon_gray_png_size; - -extern const u8 rankIcon_png[]; -extern const u32 rankIcon_png_size; - -extern const u8 rankIcon_gray_png[]; -extern const u32 rankIcon_gray_png_size; - -extern const u8 playCountIcon_png[]; -extern const u32 playCountIcon_png_size; - -extern const u8 playCountIcon_gray_png[]; -extern const u32 playCountIcon_gray_png_size; - -extern const u8 arrangeList_png[]; -extern const u32 arrangeList_png_size; - -extern const u8 arrangeList_gray_png[]; -extern const u32 arrangeList_gray_png_size; - -extern const u8 arrangeGrid_png[]; -extern const u32 arrangeGrid_png_size; - -extern const u8 arrangeGrid_gray_png[]; -extern const u32 arrangeGrid_gray_png_size; - -extern const u8 arrangeCarousel_png[]; -extern const u32 arrangeCarousel_png_size; - -extern const u8 arrangeCarousel_gray_png[]; -extern const u32 arrangeCarousel_gray_png_size; - -extern const u8 settings_title_png[]; -extern const u32 settings_title_png_size; - -extern const u8 settings_title_over_png[]; -extern const u32 settings_title_over_png_size; - -extern const u8 pageindicator_png[]; -extern const u32 pageindicator_png_size; - -extern const u8 Wiimote1_png[]; -extern const u32 Wiimote1_png_size; - -extern const u8 Wiimote2_png[]; -extern const u32 Wiimote2_png_size; - -extern const u8 Wiimote4_png[]; -extern const u32 Wiimote4_png_size; - -extern const u8 wifi1_png[]; -extern const u32 wifi1_png_size; - -extern const u8 wifi2_png[]; -extern const u32 wifi2_png_size; - -extern const u8 wifi3_png[]; -extern const u32 wifi3_png_size; - -extern const u8 wifi4_png[]; -extern const u32 wifi4_png_size; - -extern const u8 wifi8_png[]; -extern const u32 wifi8_png_size; - -extern const u8 wifi12_png[]; -extern const u32 wifi12_png_size; - -extern const u8 wifi16_png[]; -extern const u32 wifi16_png_size; - -extern const u8 wifi32_png[]; -extern const u32 wifi32_png_size; - -extern const u8 norating_png[]; -extern const u32 norating_png_size; - -extern const u8 guitar_png[]; -extern const u32 guitar_png_size; -extern const u8 guitarR_png[]; -extern const u32 guitarR_png_size; - -extern const u8 microphone_png[]; -extern const u32 microphone_png_size; -extern const u8 microphoneR_png[]; -extern const u32 microphoneR_png_size; - -extern const u8 gcncontroller_png[]; -extern const u32 gcncontroller_png_size; -extern const u8 gcncontrollerR_png[]; -extern const u32 gcncontrollerR_png_size; - -extern const u8 classiccontroller_png[]; -extern const u32 classiccontroller_png_size; -extern const u8 classiccontrollerR_png[]; -extern const u32 classiccontrollerR_png_size; - -extern const u8 nunchuk_png[]; -extern const u32 nunchuk_png_size; -extern const u8 nunchukR_png[]; -extern const u32 nunchukR_png_size; - -extern const u8 dancepad_png[]; -extern const u32 dancepad_png_size; -extern const u8 dancepadR_png[]; -extern const u32 dancepadR_png_size; - -extern const u8 balanceboard_png[]; -extern const u32 balanceboard_png_size; -extern const u8 balanceboardR_png[]; -extern const u32 balanceboardR_png_size; - -extern const u8 drums_png[]; -extern const u32 drums_png_size; -extern const u8 drumsR_png[]; -extern const u32 drumsR_png_size; - -extern const u8 motionplus_png[]; -extern const u32 motionplus_png_size; -extern const u8 motionplusR_png[]; -extern const u32 motionplusR_png_size; - -extern const u8 wheel_png[]; -extern const u32 wheel_png_size; -extern const u8 wheelR_png[]; -extern const u32 wheelR_png_size; - -extern const u8 zapper_png[]; -extern const u32 zapper_png_size; -extern const u8 zapperR_png[]; -extern const u32 zapperR_png_size; - -extern const u8 wiispeak_png[]; -extern const u32 wiispeak_png_size; -extern const u8 wiispeakR_png[]; -extern const u32 wiispeakR_png_size; - -extern const u8 nintendods_png[]; -extern const u32 nintendods_png_size; -extern const u8 nintendodsR_png[]; -extern const u32 nintendodsR_png_size; - -extern const u8 esrb_ec_png[]; -extern const u32 esrb_ec_png_size; - -extern const u8 esrb_e_png[]; -extern const u32 esrb_e_png_size; - -extern const u8 esrb_eten_png[]; -extern const u32 esrb_eten_png_size; - -extern const u8 esrb_t_png[]; -extern const u32 esrb_t_png_size; - -extern const u8 esrb_m_png[]; -extern const u32 esrb_m_png_size; - -extern const u8 esrb_ao_png[]; -extern const u32 esrb_ao_png_size; - -extern const u8 cero_a_png[]; -extern const u32 cero_a_png_size; - -extern const u8 cero_b_png[]; -extern const u32 cero_b_png_size; - -extern const u8 cero_c_png[]; -extern const u32 cero_c_png_size; - -extern const u8 cero_d_png[]; -extern const u32 cero_d_png_size; - -extern const u8 cero_z_png[]; -extern const u32 cero_z_png_size; - -extern const u8 pegi_3_png[]; -extern const u32 pegi_3_png_size; - -extern const u8 pegi_7_png[]; -extern const u32 pegi_7_png_size; - -extern const u8 pegi_12_png[]; -extern const u32 pegi_12_png_size; - -extern const u8 pegi_16_png[]; -extern const u32 pegi_16_png_size; - -extern const u8 pegi_18_png[]; -extern const u32 pegi_18_png_size; - -extern const u8 usbport_png[]; -extern const u32 usbport_png_size; - -extern const u8 dvd_png[]; -extern const u32 dvd_png_size; - -extern const u8 dvd_gray_png[]; -extern const u32 dvd_gray_png_size; - -extern const u8 new_png[]; -extern const u32 new_png_size; - -extern const u8 lock_png[]; -extern const u32 lock_png_size; - -extern const u8 lock_gray_png[]; -extern const u32 lock_gray_png_size; - -extern const u8 unlock_png[]; -extern const u32 unlock_png_size; - -extern const u8 unlock_gray_png[]; -extern const u32 unlock_gray_png_size; - -extern const u8 stub_bin[]; -extern const u32 stub_bin_size; - -extern const u8 fatffs_module_bin[]; -extern const u32 fatffs_module_bin_size; - -extern const u8 ehcmodule_frag_v4_bin[]; -extern const u32 ehcmodule_frag_v4_bin_size; - -extern const u8 ehcmodule_frag_v5_bin[]; -extern const u32 ehcmodule_frag_v5_bin_size; - -#endif diff --git a/source/fonts/clock.ttf b/source/fonts/clock.ttf deleted file mode 100644 index 5a252b2b..00000000 Binary files a/source/fonts/clock.ttf and /dev/null differ diff --git a/source/fonts/font.ttf b/source/fonts/font.ttf deleted file mode 100644 index 01ce5816..00000000 Binary files a/source/fonts/font.ttf and /dev/null differ diff --git a/source/gecko.c b/source/gecko.c deleted file mode 100644 index 21bbf356..00000000 --- a/source/gecko.c +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include -#include -#include - -/* init-globals */ -static bool geckoinit = false; - -#ifndef NO_DEBUG -#include - -void gprintf(const char *format, ...) -{ - if (!geckoinit) - return; - - char * tmp = NULL; - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - u32 level = IRQ_Disable(); - usb_sendbuffer(1, tmp, strlen(tmp)); - IRQ_Restore(level); - } - va_end(va); - - if(tmp) - free(tmp); -} - -bool InitGecko() -{ - u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1); - if (geckoattached) - { - usb_flush(EXI_CHANNEL_1); - CON_EnableGecko(1, false); - geckoinit = true; - return true; - } - else return false; -} - -char ascii(char s) -{ - if (s < 0x20) return '.'; - if (s > 0x7E) return '.'; - return s; -} - -void hexdump(void *d, int len) -{ - u8 *data; - int i, off; - data = (u8*) d; - - gprintf("\n 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF"); - gprintf("\n==== =============================================== ================\n"); - - for (off = 0; off < len; off += 16) - { - gprintf("%04x ", off); - for (i = 0; i < 16; i++) - if ((i + off) >= len) - gprintf(" "); - else gprintf("%02x ", data[off + i]); - - gprintf(" "); - for (i = 0; i < 16; i++) - if ((i + off) >= len) - gprintf(" "); - else gprintf("%c", ascii(data[off + i])); - gprintf("\n"); - } -} - -static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len) -{ - if(geckoinit && ptr) - { - u32 level; - level = IRQ_Disable(); - usb_sendbuffer(1, ptr, len); - IRQ_Restore(level); - } - - return len; -} - -static const devoptab_t gecko_out = { - "stdout", // device name - 0, // size of file structure - NULL, // device open - NULL, // device close - __out_write,// device write - NULL, // device read - NULL, // device seek - NULL, // device fstat - NULL, // device stat - NULL, // device link - NULL, // device unlink - NULL, // device chdir - NULL, // device rename - NULL, // device mkdir - 0, // dirStateSize - NULL, // device diropen_r - NULL, // device dirreset_r - NULL, // device dirnext_r - NULL, // device dirclose_r - NULL // device statvfs_r -}; - -void USBGeckoOutput() -{ - devoptab_list[STD_OUT] = &gecko_out; - devoptab_list[STD_ERR] = &gecko_out; -} - -#endif /* NO_DEBUG */ diff --git a/source/gecko.h b/source/gecko.h deleted file mode 100644 index 029257cb..00000000 --- a/source/gecko.h +++ /dev/null @@ -1,29 +0,0 @@ - -#ifndef _GECKO_H_ -#define _GECKO_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - char ascii(char s); - -#ifndef NO_DEBUG - //use this just like printf(); - void gprintf(const char *str, ...); - bool InitGecko(); - void hexdump(void *d, int len); - void USBGeckoOutput(); -#else -#define gprintf(...) -#define InitGecko() false -#define hexdump( x, y ) -#endif /* NO_DEBUG */ - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/source/homebrewboot/BootHomebrew.cpp b/source/homebrewboot/BootHomebrew.cpp deleted file mode 100644 index 240c4340..00000000 --- a/source/homebrewboot/BootHomebrew.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../lstub.h" -#include "../sys.h" -#include "../gecko.h" - -#include "fatmounter.h" -#include "dolloader.h" - -static u8 *homebrewbuffer = (u8 *) 0x92000000; -static u32 homebrewsize = 0; -static std::vector Arguments; - -extern const u8 app_booter_dol[]; -extern const u32 app_booter_dol_size; - -void AddBootArgument(const char * argv) -{ - std::string arg(argv); - Arguments.push_back(arg); -} - -int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len) -{ - homebrewsize += len; - memcpy((homebrewbuffer) + pos, temp, len); - - return 1; -} - -void FreeHomebrewBuffer() -{ - homebrewbuffer = (u8 *) 0x92000000; - homebrewsize = 0; - - Arguments.clear(); -} - -static int SetupARGV(struct __argv * args) -{ - if (!args) return -1; - - bzero(args, sizeof(struct __argv)); - args->argvMagic = ARGV_MAGIC; - - u32 stringlength = 1; - - /** Append Arguments **/ - for (u32 i = 0; i < Arguments.size(); i++) - { - stringlength += Arguments[i].size() + 1; - } - - args->length = stringlength; - args->commandLine = (char*) malloc(args->length); - - if (!args->commandLine) return -1; - - u32 argc = 0; - u32 position = 0; - - /** Append Arguments **/ - for (u32 i = 0; i < Arguments.size(); i++) - { - strcpy(&args->commandLine[position], Arguments[i].c_str()); - position += Arguments[i].size() + 1; - argc++; - } - - args->argc = argc; - - args->commandLine[args->length - 1] = '\0'; - args->argv = &args->commandLine; - args->endARGV = args->argv + 1; - - Arguments.clear(); - - return 0; -} - -static int RunAppbooter() -{ - if (homebrewsize == 0) return -1; - - ExitApp(); - - struct __argv args; - SetupARGV(&args); - - u32 cpu_isr; - - entrypoint entry = (entrypoint) load_dol((void*) app_booter_dol, &args); - - if (!entry) - { - FreeHomebrewBuffer(); - return -1; - } - - u64 currentStub = getStubDest(); - loadStub(); - - if (Set_Stub_Split(0x00010001, "UNEO") < 0) - { - if (Set_Stub_Split(0x00010001, "ULNR") < 0) - { - if (!currentStub) currentStub = 0x100000002ULL; - - Set_Stub(currentStub); - } - } - - SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); - _CPU_ISR_Disable( cpu_isr ); - __exception_closeall(); - entry(); - _CPU_ISR_Restore( cpu_isr ); - - return 0; -} - -int BootHomebrew(const char * filepath) -{ - void *buffer = NULL; - u32 filesize = 0; - - FILE *file = fopen(filepath, "rb"); - - if (!file) Sys_BackToLoader(); - - fseek(file, 0, SEEK_END); - filesize = ftell(file); - rewind(file); - - buffer = malloc(filesize); - - if (fread(buffer, 1, filesize, file) != filesize) - { - fclose(file); - free(buffer); - SDCard_deInit(); - USBDevice_deInit(); - Sys_BackToLoader(); - } - - fclose(file); - - CopyHomebrewMemory((u8*) buffer, 0, filesize); - - if (buffer) - { - free(buffer); - buffer = NULL; - } - - AddBootArgument(filepath); - return RunAppbooter(); -} - -int BootHomebrewFromMem() -{ - return RunAppbooter(); -} diff --git a/source/homebrewboot/BootHomebrew.h b/source/homebrewboot/BootHomebrew.h deleted file mode 100644 index f68c67f7..00000000 --- a/source/homebrewboot/BootHomebrew.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _BOOTHOMEBREW_H_ -#define _BOOTHOMEBREW_H_ - -int BootHomebrew(const char * filepath); -int BootHomebrewFromMem(); -int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len); -void AddBootArgument(const char * arg); -void FreeHomebrewBuffer(); - -#endif diff --git a/source/homebrewboot/HomebrewBrowse.cpp b/source/homebrewboot/HomebrewBrowse.cpp deleted file mode 100644 index f9bfb947..00000000 --- a/source/homebrewboot/HomebrewBrowse.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "HomebrewBrowser.hpp" - -/**************************************************************************** - * MenuHomebrewBrowse - ***************************************************************************/ -int MenuHomebrewBrowse() -{ - HomebrewBrowser * Menu = new HomebrewBrowser(); - mainWindow->Append(Menu); - - Menu->ShowMenu(); - - int returnMenu = MENU_NONE; - - while((returnMenu = Menu->MainLoop()) == MENU_NONE); - - delete Menu; - - return returnMenu; -} diff --git a/source/homebrewboot/HomebrewBrowse.h b/source/homebrewboot/HomebrewBrowse.h deleted file mode 100644 index f1605bb3..00000000 --- a/source/homebrewboot/HomebrewBrowse.h +++ /dev/null @@ -1,16 +0,0 @@ -/**************************************************************************** - * HomebrewBrowse - * USB Loader GX 2009 - * - * Homebrew launcher for USB Loader GX - * - * homebrewbrowse.h - ***************************************************************************/ - -#ifndef _HOMEBREWBROWSE_H_ -#define _HOMEBREWBROWSE_H_ - -int roundup(float number); -int MenuHomebrewBrowse(); - -#endif diff --git a/source/homebrewboot/HomebrewBrowser.cpp b/source/homebrewboot/HomebrewBrowser.cpp deleted file mode 100644 index b6bc5846..00000000 --- a/source/homebrewboot/HomebrewBrowser.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "HomebrewBrowser.hpp" -#include "themes/CTheme.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "network/networkops.h" -#include "utils/minizip/miniunz.h" -#include "usbloader/utils.h" -#include "prompts/TitleBrowser.h" -#include "homebrewboot/BootHomebrew.h" -#include "prompts/ProgressWindow.h" -#include "wstring.hpp" -#include "HomebrewXML.h" - -extern u32 infilesize; -extern u32 uncfilesize; -extern char wiiloadVersion[2]; -extern int connection; - -HomebrewBrowser::HomebrewBrowser() - : FlyingButtonsMenu(tr( "Homebrew Launcher" )) -{ - HomebrewList = new HomebrewFiles(Settings.homebrewapps_path); - - if (IsNetworkInit()) - ResumeNetworkWait(); - - wifiNotSet = true; - wifiImgData = Resources::GetImageData("Wifi_btn.png"); - wifiToolTip = new GuiTooltip(" "); - wifiImg = new GuiImage(wifiImgData); - wifiBtn = new GuiButton(wifiImgData->GetWidth(), wifiImgData->GetHeight()); - wifiBtn->SetImage(wifiImg); - wifiBtn->SetPosition(300, 400); - wifiBtn->SetSoundOver(btnSoundOver); - wifiBtn->SetSoundClick(btnSoundClick); - wifiBtn->SetEffectGrow(); - wifiBtn->SetAlpha(80); - wifiBtn->SetTrigger(trigA); - Append(wifiBtn); - - channelImgData = Resources::GetImageData("Channel_btn.png"); - channelBtnImg = new GuiImage(channelImgData); - channelBtnImg->SetWidescreen(Settings.widescreen); - channelBtn = new GuiButton(channelBtnImg->GetWidth(), channelBtnImg->GetHeight()); - channelBtn->SetPosition(240, 400); - channelBtn->SetImage(channelBtnImg); - channelBtn->SetSoundOver(btnSoundOver); - channelBtn->SetSoundClick(btnSoundClick2); - channelBtn->SetEffectGrow(); - channelBtn->SetTrigger(trigA); - Append(channelBtn); - - MainButtonDesc.resize(HomebrewList->GetFilecount()); - MainButtonDescOver.resize(HomebrewList->GetFilecount()); - - for(u32 i = 0; i < 4; ++i) - { - IconImgData[i] = NULL; - IconImg[i] = NULL; - } - - for(int i = 0; i < HomebrewList->GetFilecount(); ++i) - { - MainButtonDesc[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255}); - MainButtonDesc[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED); - MainButtonDesc[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - MainButtonDesc[i]->SetPosition(148, 15); - - MainButtonDescOver[i] = new GuiText((char *) NULL, 18, (GXColor) {0, 0, 0, 255}); - MainButtonDescOver[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, SCROLL_HORIZONTAL); - MainButtonDescOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - MainButtonDescOver[i]->SetPosition(148, 15); - } - - SetupMainButtons(); -} - -HomebrewBrowser::~HomebrewBrowser() -{ - HaltGui(); - delete HomebrewList; - - Remove(wifiBtn); - delete wifiImgData; - delete wifiImg; - delete wifiToolTip; - delete wifiBtn; - - Remove(channelBtn); - delete channelImgData; - delete channelBtnImg; - delete channelBtn; - - for(u32 i = 0; i < MainButtonDesc.size(); ++i) - { - delete MainButtonDesc[i]; - delete MainButtonDescOver[i]; - MainButton[i]->SetLabel(NULL, 1); - MainButton[i]->SetLabelOver(NULL, 1); - } - - if (IsNetworkInit()) - HaltNetworkThread(); -} - -void HomebrewBrowser::AddMainButtons() -{ - HaltGui(); - - for(u32 i = 0; i < 4; ++i) - { - if(IconImgData[i]) - delete IconImgData[i]; - if(IconImg[i]) - delete IconImg[i]; - IconImgData[i] = NULL; - IconImg[i] = NULL; - } - - for(u32 i = 0; i < MainButton.size(); ++i) - MainButton[i]->SetIcon(NULL); - - char iconpath[200]; - int FirstItem = currentPage*DISPLAY_BUTTONS; - - for(int i = FirstItem, n = 0; i < (int) MainButton.size() && i < FirstItem+DISPLAY_BUTTONS; ++i, ++n) - { - snprintf(iconpath, sizeof(iconpath), "%sicon.png", HomebrewList->GetFilepath(i)); - IconImgData[n] = new GuiImageData(iconpath); - IconImg[n] = new GuiImage(IconImgData[n]); - IconImg[n]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - IconImg[n]->SetPosition(12, 0); - IconImg[n]->SetScale(0.95); - MainButton[i]->SetIcon(IconImg[n]); - } - - FlyingButtonsMenu::AddMainButtons(); -} - -void HomebrewBrowser::SetupMainButtons() -{ - HomebrewXML MetaXML; - char metapath[200]; - - for(int i = 0; i < HomebrewList->GetFilecount(); ++i) - { - const char * HomebrewName = NULL; - snprintf(metapath, sizeof(metapath), "%smeta.xml", HomebrewList->GetFilepath(i)); - - if (MetaXML.LoadHomebrewXMLData(metapath) > 0) - { - HomebrewName = MetaXML.GetName(); - MainButtonDesc[i]->SetText(MetaXML.GetShortDescription()); - MainButtonDescOver[i]->SetText(MetaXML.GetShortDescription()); - } - else - { - const char * shortpath = strrchr(HomebrewList->GetFilename(i), '/'); - if(shortpath) - { - snprintf(metapath, sizeof(metapath), "%s/%s", shortpath, HomebrewList->GetFilename(i)); - HomebrewName = metapath; - } - else - HomebrewName = HomebrewList->GetFilename(i); - MainButtonDesc[i]->SetText(" "); - MainButtonDescOver[i]->SetText(" "); - } - - SetMainButton(i, HomebrewName, MainButtonImgData, MainButtonImgOverData); - - MainButtonTxt[i]->SetFontSize(18); - MainButtonTxt[i]->SetMaxWidth(MainButtonImgData->GetWidth() - 150, DOTTED); - MainButtonTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - MainButtonTxt[i]->SetPosition(148, -12); - MainButton[i]->SetLabel(MainButtonDesc[i], 1); - MainButton[i]->SetLabelOver(MainButtonDescOver[i], 1); - } -} - -int HomebrewBrowser::MainLoop() -{ - if (IsNetworkInit() && wifiNotSet) - { - wifiToolTip->SetText(GetNetworkIP()); - wifiBtn->SetAlpha(255); - wifiBtn->SetToolTip(wifiToolTip, 0, -50, 0, 5); - wifiNotSet = false; - } - - if(wifiBtn->GetState() == STATE_CLICKED) - { - ResumeNetworkWait(); - wifiBtn->ResetState(); - } - else if(channelBtn->GetState() == STATE_CLICKED) - { - SetState(STATE_DISABLED); - TitleBrowser(); - SetState(STATE_DEFAULT); - channelBtn->ResetState(); - } - else if (infilesize > 0) - { - int menu = ReceiveFile(); - if(menu != MENU_NONE) - return menu; - CloseConnection(); - ResumeNetworkWait(); - } - - return FlyingButtonsMenu::MainLoop(); -} - -//! Callback for MainButton clicked -void HomebrewBrowser::MainButtonClicked(int button) -{ - HomebrewXML MetaXML; - char metapath[200]; - snprintf(metapath, sizeof(metapath), "%smeta.xml", HomebrewList->GetFilepath(button)); - MetaXML.LoadHomebrewXMLData(metapath); - - u64 filesize = HomebrewList->GetFilesize(button); - - wString HomebrewName(MainButtonTxt[button]->GetText()); - - int choice = HBCWindowPrompt(HomebrewName.toUTF8().c_str(), MetaXML.GetCoder(), MetaXML.GetVersion(), - MetaXML.GetReleasedate(), MetaXML.GetLongDescription(), IconImgData[button % 4], filesize); - - if (choice == 1) - { - char homebrewpath[200]; - snprintf(homebrewpath, sizeof(homebrewpath), "%s%s", HomebrewList->GetFilepath(button), HomebrewList->GetFilename(button)); - BootHomebrew(homebrewpath); - } -} - -int HomebrewBrowser::ReceiveFile() -{ - char filesizetxt[50]; - char temp[50]; - u32 filesize = 0; - - if (infilesize < MB_SIZE) - snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fKB" ), infilesize / KB_SIZE); - else snprintf(filesizetxt, sizeof(filesizetxt), tr( "Incoming file %0.2fMB" ), infilesize / MB_SIZE); - - snprintf(temp, sizeof(temp), tr( "Load file from: %s ?" ), GetIncommingIP()); - - int choice = WindowPrompt(filesizetxt, temp, tr( "OK" ), tr( "Cancel" )); - - if (choice == 0) - return MENU_NONE; - - u32 read = 0; - int len = NETWORKBLOCKSIZE; - filesize = infilesize; - u8 * buffer = (u8 *) malloc(infilesize); - if(!buffer) - { - WindowPrompt(tr( "Not enough memory." ), 0, tr( "OK" )); - return MENU_NONE; - } - - bool error = false; - while (read < infilesize) - { - ShowProgress(tr( "Receiving file from:" ), GetIncommingIP(), NULL, read, infilesize, true); - - if (infilesize - read < (u32) len) - len = infilesize - read; - else len = NETWORKBLOCKSIZE; - - int result = network_read(connection, buffer+read, len); - - if (result < 0) - { - WindowPrompt(tr( "Error while transfering data." ), 0, tr( "OK" )); - free(buffer); - return MENU_NONE; - } - if (!result) - { - break; - } - - read += result; - } - - char filename[101]; - network_read(connection, (u8*) &filename, 100); - - // Do we need to unzip this thing? - if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) - { - // We need to unzip... - if (buffer[0] == 'P' && buffer[1] == 'K' && buffer[2] == 0x03 && buffer[3] == 0x04) - { - // It's a zip file, unzip to the apps directory - // Zip archive, ask for permission to install the zip - char zippath[255]; - sprintf((char *) &zippath, "%s%s", Settings.homebrewapps_path, filename); - - FILE *fp = fopen(zippath, "wb"); - if (!fp) - { - WindowPrompt(tr( "Error writing the data." ), 0, tr( "OK" )); - return MENU_NONE; - } - - fwrite(buffer, 1, infilesize, fp); - fclose(fp); - - free(buffer); - buffer = NULL; - - // Now unzip the zip file... - unzFile uf = unzOpen(zippath); - if (uf == NULL) - { - WindowPrompt(tr( "Error while opening the zip." ), 0, tr( "OK" )); - return MENU_NONE; - } - - extractZip(uf, 0, 1, 0, Settings.homebrewapps_path); - unzCloseCurrentFile(uf); - - remove(zippath); - - WindowPrompt(tr( "Success:" ), - tr( "Uploaded ZIP file installed to homebrew directory." ), tr( "OK" )); - - // Reload this menu here... - return MENU_HOMEBREWBROWSE; - } - else if (uncfilesize != 0) // if uncfilesize == 0, it's not compressed - { - // It's compressed, uncompress - u8 *unc = (u8 *) malloc(uncfilesize); - uLongf f = uncfilesize; - error = uncompress(unc, &f, buffer, infilesize) != Z_OK; - uncfilesize = f; - filesize = uncfilesize; - - free(buffer); - buffer = unc; - } - } - - CopyHomebrewMemory(buffer, 0, filesize); - free(buffer); - - ProgressStop(); - - if (error || read != infilesize || strcasestr(filename, ".dol") || strcasestr(filename, ".elf")) - { - WindowPrompt(tr( "Error:" ), tr( "No data could be read." ), tr( "OK" )); - FreeHomebrewBuffer(); - return MENU_NONE; - } - - CloseConnection(); - - AddBootArgument(filename); - - return BootHomebrewFromMem(); -} diff --git a/source/homebrewboot/HomebrewBrowser.hpp b/source/homebrewboot/HomebrewBrowser.hpp deleted file mode 100644 index 7f622d0b..00000000 --- a/source/homebrewboot/HomebrewBrowser.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef HOMEBREWBROWSER_HPP_ -#define HOMEBREWBROWSER_HPP_ - -#include "settings/menus/FlyingButtonsMenu.hpp" -#include "HomebrewFiles.h" - -#define DISPLAY_BUTTONS 4 - -class HomebrewBrowser : public FlyingButtonsMenu -{ - public: - HomebrewBrowser(); - ~HomebrewBrowser(); - virtual int MainLoop(); - protected: - void MainButtonClicked(int index); - int ReceiveFile(); - virtual void CreateSettingsMenu(int index) { MainButtonClicked(index); }; - virtual void DeleteSettingsMenu() { }; - virtual void SetupMainButtons(); - virtual void AddMainButtons(); - - HomebrewFiles * HomebrewList; - GuiImageData * IconImgData[DISPLAY_BUTTONS]; - GuiImage * IconImg[DISPLAY_BUTTONS]; - std::vector MainButtonDesc; - std::vector MainButtonDescOver; - - bool wifiNotSet; - GuiTooltip * wifiToolTip; - GuiImageData * wifiImgData; - GuiImage * wifiImg; - GuiButton * wifiBtn; - - GuiImageData * channelImgData; - GuiImage * channelBtnImg; - GuiButton * channelBtn; -}; - -#endif diff --git a/source/homebrewboot/HomebrewFiles.cpp b/source/homebrewboot/HomebrewFiles.cpp deleted file mode 100644 index 4b6e46c1..00000000 --- a/source/homebrewboot/HomebrewFiles.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** - * HomebrewFiles Class - * for USB Loader GX - ***************************************************************************/ -#include -#include -#include -#include - -#include "HomebrewFiles.h" - -HomebrewFiles::HomebrewFiles(const char * path) -{ - filecount = 0; - - FileInfo = (FileInfos *) malloc(sizeof(FileInfos)); - if (!FileInfo) - { - return; - } - - memset(&FileInfo[filecount], 0, sizeof(FileInfos)); - - this->LoadPath(path); - this->SortList(); -} - -HomebrewFiles::~HomebrewFiles() -{ - if (FileInfo) - { - free(FileInfo); - FileInfo = NULL; - } -} - -bool HomebrewFiles::LoadPath(const char * folderpath) -{ - struct stat st; - DIR_ITER *dir = NULL; - char filename[1024]; - - dir = diropen(folderpath); - if (dir == NULL) - { - return false; - } - - while (dirnext(dir, filename, &st) == 0) - { - if ((st.st_mode & S_IFDIR) != 0) - { - if (strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) - { - char currentname[200]; - snprintf(currentname, sizeof(currentname), "%s%s/", folderpath, filename); - this->LoadPath(currentname); - } - } - else - { - char temp[5]; - for (int i = 0; i < 5; i++) - { - temp[i] = filename[strlen(filename) - 4 + i]; - } - - if ((strncasecmp(temp, ".dol", 4) == 0 || strncasecmp(temp, ".elf", 4) == 0) && filecount < MAXHOMEBREWS - && filename[0] != '.') - { - - FileInfo = (FileInfos *) realloc(FileInfo, (filecount + 1) * sizeof(FileInfos)); - - if (!FileInfo) - { - free(FileInfo); - FileInfo = NULL; - filecount = 0; - dirclose(dir); - return false; - } - - memset(&(FileInfo[filecount]), 0, sizeof(FileInfo)); - - strlcpy(FileInfo[filecount].FilePath, folderpath, sizeof(FileInfo[filecount].FilePath)); - strlcpy(FileInfo[filecount].FileName, filename, sizeof(FileInfo[filecount].FileName)); - FileInfo[filecount].FileSize = st.st_size; - filecount++; - } - } - } - dirclose(dir); - - return true; -} - -char * HomebrewFiles::GetFilename(int ind) -{ - if (ind > filecount) - return NULL; - else return FileInfo[ind].FileName; -} - -char * HomebrewFiles::GetFilepath(int ind) -{ - if (ind > filecount) - return NULL; - else return FileInfo[ind].FilePath; -} - -unsigned int HomebrewFiles::GetFilesize(int ind) -{ - if (ind > filecount || !filecount || !FileInfo) - return 0; - else return FileInfo[ind].FileSize; -} - -static int ListCompare(const void *a, const void *b) -{ - FileInfos *ab = (FileInfos*) a; - FileInfos *bb = (FileInfos*) b; - - return stricmp((char *) ab->FilePath, (char *) bb->FilePath); -} -void HomebrewFiles::SortList() -{ - qsort(FileInfo, filecount, sizeof(FileInfos), ListCompare); -} diff --git a/source/homebrewboot/HomebrewFiles.h b/source/homebrewboot/HomebrewFiles.h deleted file mode 100644 index d2bcb259..00000000 --- a/source/homebrewboot/HomebrewFiles.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * HomebrewFiles Class - * for USB Loader GX - ***************************************************************************/ -#ifndef ___HOMEBREWFILES_H_ -#define ___HOMEBREWFILES_H_ - -#define MAXHOMEBREWS 500 - -typedef struct -{ - char FileName[100]; - char FilePath[150]; - unsigned int FileSize; -} FileInfos; - -class HomebrewFiles -{ - public: - //!Constructor - //!\param path Path where to check for homebrew files - HomebrewFiles(const char * path); - //!Destructor - ~HomebrewFiles(); - //! Load the dol/elf list of a path - //!\param path Path where to check for homebrew files - bool LoadPath(const char * path); - //! Get the a filename of the list - //!\param list index - char * GetFilename(int index); - //! Get the a filepath of the list - //!\param list index - char * GetFilepath(int index); - //! Get the a filesize of the list - //!\param list index - unsigned int GetFilesize(int index); - //! Get the filecount of the whole list - int GetFilecount() { return filecount; }; - //! Sort list by filepath - void SortList(); - protected: - int filecount; - FileInfos *FileInfo; -}; - -#endif diff --git a/source/homebrewboot/HomebrewXML.cpp b/source/homebrewboot/HomebrewXML.cpp deleted file mode 100644 index 34b19cc3..00000000 --- a/source/homebrewboot/HomebrewXML.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** - * HomebrewXML Class - * for USB Loader GX - ***************************************************************************/ -#include -#include -#include -#include -#include "FileOperations/fileops.h" -#include "xml/xml.h" - -#include "HomebrewXML.h" - -#define ENTRIE_SIZE 8192 - -/* qparam filename Filepath of the XML file */ -int HomebrewXML::LoadHomebrewXMLData(const char* filename) -{ - Name.clear(); - Coder.clear(); - Version.clear(); - ShortDescription.clear(); - LongDescription.clear(); - Releasedate.clear(); - - /* Load XML file */ - u8 * xmlbuffer = NULL; - u64 size = 0; - LoadFileToMem(filename, &xmlbuffer, &size); - - if(!xmlbuffer) - return -1; - - mxml_node_t * nodetree = mxmlLoadString(NULL, (const char *) xmlbuffer, MXML_OPAQUE_CALLBACK); - - if (!nodetree) - return -2; - - mxml_node_t * node = mxmlFindElement(nodetree, nodetree, "app", NULL, NULL, MXML_DESCEND_FIRST); - if (!node) - return -5; - - char * Entrie = new char[ENTRIE_SIZE]; - - Entrie[0] = '\0'; - GetTextFromNode(node, nodetree, (char*) "name", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); - Name = Entrie; - - Entrie[0] = '\0'; - GetTextFromNode(node, nodetree, (char*) "coder", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); - Coder = Entrie; - - Entrie[0] = '\0'; - GetTextFromNode(node, nodetree, (char*) "version", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); - Version = Entrie; - - Entrie[0] = '\0'; - GetTextFromNode(node, nodetree, (char*) "short_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); - ShortDescription = Entrie; - - Entrie[0] = '\0'; - GetTextFromNode(node, nodetree, (char*) "long_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); - LongDescription = Entrie; - - Entrie[0] = '\0'; - GetTextFromNode(node, nodetree, (char*) "release_date", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE); - - int len = (strlen(Entrie) - 6); //length of the date string without the 200000 at the end - if (len == 8) - snprintf(Entrie, ENTRIE_SIZE, "%c%c/%c%c/%c%c%c%c", Entrie[4], Entrie[5], Entrie[6], Entrie[7], Entrie[0], - Entrie[1], Entrie[2], Entrie[3]); - else if (len == 6) - snprintf(Entrie, ENTRIE_SIZE, "%c%c/%c%c%c%c", Entrie[4], Entrie[5], Entrie[0], Entrie[1], Entrie[2], Entrie[3]); - else snprintf(Entrie, ENTRIE_SIZE, "%s", Entrie); - - Releasedate = Entrie; - - delete[] Entrie; - - mxmlDelete(node); - mxmlDelete(nodetree); - free(xmlbuffer); - - return 1; -} - -/* Get name */ -const char * HomebrewXML::GetName() const -{ - return Name.c_str(); -} - -/* Set Name */ -void HomebrewXML::SetName(char * newName) -{ - Name = newName; -} - -/* Get coder */ -const char * HomebrewXML::GetCoder() const -{ - return Coder.c_str(); -} - -/* Get version */ -const char * HomebrewXML::GetVersion() const -{ - return Version.c_str(); -} - -/* Get releasedate */ -const char * HomebrewXML::GetReleasedate() const -{ - return Releasedate.c_str(); -} - -/* Get shortdescription */ -const char * HomebrewXML::GetShortDescription() const -{ - return ShortDescription.c_str(); -} - -/* Get longdescription */ -const char * HomebrewXML::GetLongDescription() const -{ - return LongDescription.c_str(); -} diff --git a/source/homebrewboot/HomebrewXML.h b/source/homebrewboot/HomebrewXML.h deleted file mode 100644 index 6032fd02..00000000 --- a/source/homebrewboot/HomebrewXML.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * HomebrewXML Class - * for USB Loader GX - ***************************************************************************/ -#ifndef ___HOMEBREWXML_H_ -#define ___HOMEBREWXML_H_ - -#include - -class HomebrewXML -{ - public: - HomebrewXML() { }; - HomebrewXML(const char* filename) { LoadHomebrewXMLData(filename); }; - - int LoadHomebrewXMLData(const char* filename); - - const char * GetName() const; - void SetName(char * newName); - const char * GetCoder() const; - const char * GetVersion() const; - const char * GetReleasedate() const; - const char * GetShortDescription() const; - const char * GetLongDescription() const; - - protected: - std::string Name; - std::string Coder; - std::string Version; - std::string Releasedate; - std::string ShortDescription; - std::string LongDescription; -}; - -#endif diff --git a/source/homebrewboot/dolloader.c b/source/homebrewboot/dolloader.c deleted file mode 100644 index d957f7e8..00000000 --- a/source/homebrewboot/dolloader.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "dolloader.h" - -typedef struct _dolheader { - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - -u32 load_dol(const void *dolstart, struct __argv *argv) -{ - u32 i; - dolheader *dolfile; - - if (dolstart) - { - dolfile = (dolheader *) dolstart; - for (i = 0; i < 7; i++) - { - if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) - continue; - - memmove((void *) dolfile->text_start[i], dolstart - + dolfile->text_pos[i], dolfile->text_size[i]); - - DCFlushRange ((void *) dolfile->text_start[i], dolfile->text_size[i]); - ICInvalidateRange((void *) dolfile->text_start[i], dolfile->text_size[i]); - } - - for (i = 0; i < 11; i++) - { - if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) - continue; - - memmove((void *) dolfile->data_start[i], dolstart - + dolfile->data_pos[i], dolfile->data_size[i]); - - DCFlushRange((void *) dolfile->data_start[i], - dolfile->data_size[i]); - } - - if (argv && argv->argvMagic == ARGV_MAGIC) - { - void *new_argv = (void *) (dolfile->entry_point + 8); - memmove(new_argv, argv, sizeof(*argv)); - DCFlushRange(new_argv, sizeof(*argv)); - } - return dolfile->entry_point; - } - return 0; -} diff --git a/source/homebrewboot/dolloader.h b/source/homebrewboot/dolloader.h deleted file mode 100644 index af644414..00000000 --- a/source/homebrewboot/dolloader.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _DOLLOADER_H_ -#define _DOLLOADER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern void __exception_closeall(); -typedef void (*entrypoint) (void); - -u32 load_dol(const void *dolstart, struct __argv *argv); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/images/Channel_btn.png b/source/images/Channel_btn.png deleted file mode 100644 index dc46e47e..00000000 Binary files a/source/images/Channel_btn.png and /dev/null differ diff --git a/source/images/Wifi_btn.png b/source/images/Wifi_btn.png deleted file mode 100644 index 24411088..00000000 Binary files a/source/images/Wifi_btn.png and /dev/null differ diff --git a/source/images/Wiimote1.png b/source/images/Wiimote1.png deleted file mode 100644 index 173ab5ee..00000000 Binary files a/source/images/Wiimote1.png and /dev/null differ diff --git a/source/images/Wiimote2.png b/source/images/Wiimote2.png deleted file mode 100644 index 3a7462ea..00000000 Binary files a/source/images/Wiimote2.png and /dev/null differ diff --git a/source/images/Wiimote3.png b/source/images/Wiimote3.png deleted file mode 100644 index bea80557..00000000 Binary files a/source/images/Wiimote3.png and /dev/null differ diff --git a/source/images/Wiimote4.png b/source/images/Wiimote4.png deleted file mode 100644 index 582cb50e..00000000 Binary files a/source/images/Wiimote4.png and /dev/null differ diff --git a/source/images/abcIcon.png b/source/images/abcIcon.png deleted file mode 100644 index 19b39e01..00000000 Binary files a/source/images/abcIcon.png and /dev/null differ diff --git a/source/images/addressbar_textbox.png b/source/images/addressbar_textbox.png deleted file mode 100644 index 77007f5b..00000000 Binary files a/source/images/addressbar_textbox.png and /dev/null differ diff --git a/source/images/arrangeCarousel.png b/source/images/arrangeCarousel.png deleted file mode 100644 index b8162cff..00000000 Binary files a/source/images/arrangeCarousel.png and /dev/null differ diff --git a/source/images/arrangeCarousel_gray.png b/source/images/arrangeCarousel_gray.png deleted file mode 100644 index c7955d54..00000000 Binary files a/source/images/arrangeCarousel_gray.png and /dev/null differ diff --git a/source/images/arrangeGrid.png b/source/images/arrangeGrid.png deleted file mode 100644 index 1b1be841..00000000 Binary files a/source/images/arrangeGrid.png and /dev/null differ diff --git a/source/images/arrangeGrid_gray.png b/source/images/arrangeGrid_gray.png deleted file mode 100644 index f8e066d3..00000000 Binary files a/source/images/arrangeGrid_gray.png and /dev/null differ diff --git a/source/images/arrangeList.png b/source/images/arrangeList.png deleted file mode 100644 index 9a116087..00000000 Binary files a/source/images/arrangeList.png and /dev/null differ diff --git a/source/images/arrangeList_gray.png b/source/images/arrangeList_gray.png deleted file mode 100644 index 59c6410b..00000000 Binary files a/source/images/arrangeList_gray.png and /dev/null differ diff --git a/source/images/arrow_next.png b/source/images/arrow_next.png deleted file mode 100644 index 3a814fde..00000000 Binary files a/source/images/arrow_next.png and /dev/null differ diff --git a/source/images/arrow_previous.png b/source/images/arrow_previous.png deleted file mode 100644 index 20eb8a55..00000000 Binary files a/source/images/arrow_previous.png and /dev/null differ diff --git a/source/images/background.png b/source/images/background.png deleted file mode 100644 index 1a482c7c..00000000 Binary files a/source/images/background.png and /dev/null differ diff --git a/source/images/balanceboard.png b/source/images/balanceboard.png deleted file mode 100644 index d713380b..00000000 Binary files a/source/images/balanceboard.png and /dev/null differ diff --git a/source/images/balanceboardR.png b/source/images/balanceboardR.png deleted file mode 100644 index ee2de742..00000000 Binary files a/source/images/balanceboardR.png and /dev/null differ diff --git a/source/images/battery.png b/source/images/battery.png deleted file mode 100644 index 9a4c9afb..00000000 Binary files a/source/images/battery.png and /dev/null differ diff --git a/source/images/battery_bar.png b/source/images/battery_bar.png deleted file mode 100644 index 3aff7411..00000000 Binary files a/source/images/battery_bar.png and /dev/null differ diff --git a/source/images/battery_bar_red.png b/source/images/battery_bar_red.png deleted file mode 100644 index bc09b4c3..00000000 Binary files a/source/images/battery_bar_red.png and /dev/null differ diff --git a/source/images/battery_bar_white.png b/source/images/battery_bar_white.png deleted file mode 100644 index 528b3405..00000000 Binary files a/source/images/battery_bar_white.png and /dev/null differ diff --git a/source/images/battery_red.png b/source/images/battery_red.png deleted file mode 100644 index 458b7364..00000000 Binary files a/source/images/battery_red.png and /dev/null differ diff --git a/source/images/battery_white.png b/source/images/battery_white.png deleted file mode 100644 index a2812c5a..00000000 Binary files a/source/images/battery_white.png and /dev/null differ diff --git a/source/images/bg_browser.png b/source/images/bg_browser.png deleted file mode 100644 index a2c03f38..00000000 Binary files a/source/images/bg_browser.png and /dev/null differ diff --git a/source/images/bg_browser_selection.png b/source/images/bg_browser_selection.png deleted file mode 100644 index 2bdc02db..00000000 Binary files a/source/images/bg_browser_selection.png and /dev/null differ diff --git a/source/images/bg_options.png b/source/images/bg_options.png deleted file mode 100644 index 389cfa1d..00000000 Binary files a/source/images/bg_options.png and /dev/null differ diff --git a/source/images/bg_options_entry.png b/source/images/bg_options_entry.png deleted file mode 100644 index db4e2472..00000000 Binary files a/source/images/bg_options_entry.png and /dev/null differ diff --git a/source/images/bg_options_settings.png b/source/images/bg_options_settings.png deleted file mode 100644 index 49ca299a..00000000 Binary files a/source/images/bg_options_settings.png and /dev/null differ diff --git a/source/images/browser.png b/source/images/browser.png deleted file mode 100644 index f6400cd5..00000000 Binary files a/source/images/browser.png and /dev/null differ diff --git a/source/images/browser_over.png b/source/images/browser_over.png deleted file mode 100644 index 59b15471..00000000 Binary files a/source/images/browser_over.png and /dev/null differ diff --git a/source/images/button_dialogue_box.png b/source/images/button_dialogue_box.png deleted file mode 100644 index 23d2b2e6..00000000 Binary files a/source/images/button_dialogue_box.png and /dev/null differ diff --git a/source/images/button_install.png b/source/images/button_install.png deleted file mode 100644 index 69737337..00000000 Binary files a/source/images/button_install.png and /dev/null differ diff --git a/source/images/button_install_over.png b/source/images/button_install_over.png deleted file mode 100644 index 9ffc0f55..00000000 Binary files a/source/images/button_install_over.png and /dev/null differ diff --git a/source/images/cero_a.png b/source/images/cero_a.png deleted file mode 100644 index 31d989fa..00000000 Binary files a/source/images/cero_a.png and /dev/null differ diff --git a/source/images/cero_b.png b/source/images/cero_b.png deleted file mode 100644 index 3358e0aa..00000000 Binary files a/source/images/cero_b.png and /dev/null differ diff --git a/source/images/cero_c.png b/source/images/cero_c.png deleted file mode 100644 index b0248697..00000000 Binary files a/source/images/cero_c.png and /dev/null differ diff --git a/source/images/cero_d.png b/source/images/cero_d.png deleted file mode 100644 index 6eb1b4b3..00000000 Binary files a/source/images/cero_d.png and /dev/null differ diff --git a/source/images/cero_z.png b/source/images/cero_z.png deleted file mode 100644 index 6b5a48cd..00000000 Binary files a/source/images/cero_z.png and /dev/null differ diff --git a/source/images/classiccontroller.png b/source/images/classiccontroller.png deleted file mode 100644 index 92f81dfe..00000000 Binary files a/source/images/classiccontroller.png and /dev/null differ diff --git a/source/images/classiccontrollerR.png b/source/images/classiccontrollerR.png deleted file mode 100644 index e3d051d0..00000000 Binary files a/source/images/classiccontrollerR.png and /dev/null differ diff --git a/source/images/closebutton.png b/source/images/closebutton.png deleted file mode 100644 index b2100d98..00000000 Binary files a/source/images/closebutton.png and /dev/null differ diff --git a/source/images/credits_bg.png b/source/images/credits_bg.png deleted file mode 100644 index 3ce92fd3..00000000 Binary files a/source/images/credits_bg.png and /dev/null differ diff --git a/source/images/credits_button.png b/source/images/credits_button.png deleted file mode 100644 index 510df769..00000000 Binary files a/source/images/credits_button.png and /dev/null differ diff --git a/source/images/credits_button_over.png b/source/images/credits_button_over.png deleted file mode 100644 index 92bb0b79..00000000 Binary files a/source/images/credits_button_over.png and /dev/null differ diff --git a/source/images/dancepad.png b/source/images/dancepad.png deleted file mode 100644 index 55191440..00000000 Binary files a/source/images/dancepad.png and /dev/null differ diff --git a/source/images/dancepadR.png b/source/images/dancepadR.png deleted file mode 100644 index 1b3ae1ce..00000000 Binary files a/source/images/dancepadR.png and /dev/null differ diff --git a/source/images/dialogue_box.png b/source/images/dialogue_box.png deleted file mode 100644 index d16b96cc..00000000 Binary files a/source/images/dialogue_box.png and /dev/null differ diff --git a/source/images/dialogue_box_install.png b/source/images/dialogue_box_install.png deleted file mode 100644 index 0bfaa26e..00000000 Binary files a/source/images/dialogue_box_install.png and /dev/null differ diff --git a/source/images/dialogue_box_startgame.png b/source/images/dialogue_box_startgame.png deleted file mode 100644 index bd684298..00000000 Binary files a/source/images/dialogue_box_startgame.png and /dev/null differ diff --git a/source/images/drums.png b/source/images/drums.png deleted file mode 100644 index ee2e000b..00000000 Binary files a/source/images/drums.png and /dev/null differ diff --git a/source/images/drumsR.png b/source/images/drumsR.png deleted file mode 100644 index 01836925..00000000 Binary files a/source/images/drumsR.png and /dev/null differ diff --git a/source/images/dvd.png b/source/images/dvd.png deleted file mode 100644 index 43d71b52..00000000 Binary files a/source/images/dvd.png and /dev/null differ diff --git a/source/images/dvd_gray.png b/source/images/dvd_gray.png deleted file mode 100644 index 84cdeb1b..00000000 Binary files a/source/images/dvd_gray.png and /dev/null differ diff --git a/source/images/esrb_ao.png b/source/images/esrb_ao.png deleted file mode 100644 index 5004a5ce..00000000 Binary files a/source/images/esrb_ao.png and /dev/null differ diff --git a/source/images/esrb_e.png b/source/images/esrb_e.png deleted file mode 100644 index a13af0ca..00000000 Binary files a/source/images/esrb_e.png and /dev/null differ diff --git a/source/images/esrb_ec.png b/source/images/esrb_ec.png deleted file mode 100644 index 3d15720b..00000000 Binary files a/source/images/esrb_ec.png and /dev/null differ diff --git a/source/images/esrb_eten.png b/source/images/esrb_eten.png deleted file mode 100644 index 4defe777..00000000 Binary files a/source/images/esrb_eten.png and /dev/null differ diff --git a/source/images/esrb_m.png b/source/images/esrb_m.png deleted file mode 100644 index a5d29daf..00000000 Binary files a/source/images/esrb_m.png and /dev/null differ diff --git a/source/images/esrb_t.png b/source/images/esrb_t.png deleted file mode 100644 index b9549ba2..00000000 Binary files a/source/images/esrb_t.png and /dev/null differ diff --git a/source/images/exit_bottom.png b/source/images/exit_bottom.png deleted file mode 100644 index 5f957415..00000000 Binary files a/source/images/exit_bottom.png and /dev/null differ diff --git a/source/images/exit_bottom_over.png b/source/images/exit_bottom_over.png deleted file mode 100644 index 38992823..00000000 Binary files a/source/images/exit_bottom_over.png and /dev/null differ diff --git a/source/images/exit_button.png b/source/images/exit_button.png deleted file mode 100644 index 1c9fb09b..00000000 Binary files a/source/images/exit_button.png and /dev/null differ diff --git a/source/images/exit_top.png b/source/images/exit_top.png deleted file mode 100644 index 759264fc..00000000 Binary files a/source/images/exit_top.png and /dev/null differ diff --git a/source/images/exit_top_over.png b/source/images/exit_top_over.png deleted file mode 100644 index 4f60dbcd..00000000 Binary files a/source/images/exit_top_over.png and /dev/null differ diff --git a/source/images/favIcon.png b/source/images/favIcon.png deleted file mode 100644 index 1b1314b9..00000000 Binary files a/source/images/favIcon.png and /dev/null differ diff --git a/source/images/favIcon_gray.png b/source/images/favIcon_gray.png deleted file mode 100644 index cf28a899..00000000 Binary files a/source/images/favIcon_gray.png and /dev/null differ diff --git a/source/images/favorite.png b/source/images/favorite.png deleted file mode 100644 index b8eeefe7..00000000 Binary files a/source/images/favorite.png and /dev/null differ diff --git a/source/images/gameinfo1.png b/source/images/gameinfo1.png deleted file mode 100644 index 7dbfea60..00000000 Binary files a/source/images/gameinfo1.png and /dev/null differ diff --git a/source/images/gameinfo1a.png b/source/images/gameinfo1a.png deleted file mode 100644 index 528824dd..00000000 Binary files a/source/images/gameinfo1a.png and /dev/null differ diff --git a/source/images/gameinfo2.png b/source/images/gameinfo2.png deleted file mode 100644 index 35ac092f..00000000 Binary files a/source/images/gameinfo2.png and /dev/null differ diff --git a/source/images/gameinfo2a.png b/source/images/gameinfo2a.png deleted file mode 100644 index 3a81238f..00000000 Binary files a/source/images/gameinfo2a.png and /dev/null differ diff --git a/source/images/gcncontroller.png b/source/images/gcncontroller.png deleted file mode 100644 index 244bb56b..00000000 Binary files a/source/images/gcncontroller.png and /dev/null differ diff --git a/source/images/gcncontrollerR.png b/source/images/gcncontrollerR.png deleted file mode 100644 index b8213715..00000000 Binary files a/source/images/gcncontrollerR.png and /dev/null differ diff --git a/source/images/guitar.png b/source/images/guitar.png deleted file mode 100644 index cbb9a836..00000000 Binary files a/source/images/guitar.png and /dev/null differ diff --git a/source/images/guitarR.png b/source/images/guitarR.png deleted file mode 100644 index 7d763b5f..00000000 Binary files a/source/images/guitarR.png and /dev/null differ diff --git a/source/images/gxlogo.png b/source/images/gxlogo.png deleted file mode 100644 index dadd5cb6..00000000 Binary files a/source/images/gxlogo.png and /dev/null differ diff --git a/source/images/icon_folder.png b/source/images/icon_folder.png deleted file mode 100644 index 269b5ca8..00000000 Binary files a/source/images/icon_folder.png and /dev/null differ diff --git a/source/images/keyboard_backspace_over.png b/source/images/keyboard_backspace_over.png deleted file mode 100644 index 419a2e6c..00000000 Binary files a/source/images/keyboard_backspace_over.png and /dev/null differ diff --git a/source/images/keyboard_clear_over.png b/source/images/keyboard_clear_over.png deleted file mode 100644 index 11fbb962..00000000 Binary files a/source/images/keyboard_clear_over.png and /dev/null differ diff --git a/source/images/keyboard_key.png b/source/images/keyboard_key.png deleted file mode 100644 index 50061ba9..00000000 Binary files a/source/images/keyboard_key.png and /dev/null differ diff --git a/source/images/keyboard_key_over.png b/source/images/keyboard_key_over.png deleted file mode 100644 index 15e352db..00000000 Binary files a/source/images/keyboard_key_over.png and /dev/null differ diff --git a/source/images/keyboard_largekey_over.png b/source/images/keyboard_largekey_over.png deleted file mode 100644 index bac10741..00000000 Binary files a/source/images/keyboard_largekey_over.png and /dev/null differ diff --git a/source/images/keyboard_mediumkey_over.png b/source/images/keyboard_mediumkey_over.png deleted file mode 100644 index f2c821cb..00000000 Binary files a/source/images/keyboard_mediumkey_over.png and /dev/null differ diff --git a/source/images/keyboard_textbox.png b/source/images/keyboard_textbox.png deleted file mode 100644 index caeef7ee..00000000 Binary files a/source/images/keyboard_textbox.png and /dev/null differ diff --git a/source/images/little_star.png b/source/images/little_star.png deleted file mode 100644 index de0da22c..00000000 Binary files a/source/images/little_star.png and /dev/null differ diff --git a/source/images/lock.png b/source/images/lock.png deleted file mode 100644 index fc613766..00000000 Binary files a/source/images/lock.png and /dev/null differ diff --git a/source/images/lock_gray.png b/source/images/lock_gray.png deleted file mode 100644 index 72db0075..00000000 Binary files a/source/images/lock_gray.png and /dev/null differ diff --git a/source/images/menu_button.png b/source/images/menu_button.png deleted file mode 100644 index 008ae4a5..00000000 Binary files a/source/images/menu_button.png and /dev/null differ diff --git a/source/images/menu_button_over.png b/source/images/menu_button_over.png deleted file mode 100644 index 4f0780e7..00000000 Binary files a/source/images/menu_button_over.png and /dev/null differ diff --git a/source/images/microphone.png b/source/images/microphone.png deleted file mode 100644 index d1e6b641..00000000 Binary files a/source/images/microphone.png and /dev/null differ diff --git a/source/images/microphoneR.png b/source/images/microphoneR.png deleted file mode 100644 index 892f8339..00000000 Binary files a/source/images/microphoneR.png and /dev/null differ diff --git a/source/images/motionplus.png b/source/images/motionplus.png deleted file mode 100644 index c3e34505..00000000 Binary files a/source/images/motionplus.png and /dev/null differ diff --git a/source/images/motionplusR.png b/source/images/motionplusR.png deleted file mode 100644 index 98576248..00000000 Binary files a/source/images/motionplusR.png and /dev/null differ diff --git a/source/images/mp3_pause.png b/source/images/mp3_pause.png deleted file mode 100644 index f0b5903a..00000000 Binary files a/source/images/mp3_pause.png and /dev/null differ diff --git a/source/images/mp3_stop.png b/source/images/mp3_stop.png deleted file mode 100644 index 2762881a..00000000 Binary files a/source/images/mp3_stop.png and /dev/null differ diff --git a/source/images/new.png b/source/images/new.png deleted file mode 100644 index 167cce95..00000000 Binary files a/source/images/new.png and /dev/null differ diff --git a/source/images/nintendods.png b/source/images/nintendods.png deleted file mode 100644 index c22cf42a..00000000 Binary files a/source/images/nintendods.png and /dev/null differ diff --git a/source/images/nintendodsR.png b/source/images/nintendodsR.png deleted file mode 100644 index 0cad10c7..00000000 Binary files a/source/images/nintendodsR.png and /dev/null differ diff --git a/source/images/nocover.png b/source/images/nocover.png deleted file mode 100644 index 4be4143a..00000000 Binary files a/source/images/nocover.png and /dev/null differ diff --git a/source/images/nocoverFlat.png b/source/images/nocoverFlat.png deleted file mode 100644 index d44936a6..00000000 Binary files a/source/images/nocoverFlat.png and /dev/null differ diff --git a/source/images/nodisc.png b/source/images/nodisc.png deleted file mode 100644 index 6bb61a7e..00000000 Binary files a/source/images/nodisc.png and /dev/null differ diff --git a/source/images/norating.png b/source/images/norating.png deleted file mode 100644 index 2b5248ee..00000000 Binary files a/source/images/norating.png and /dev/null differ diff --git a/source/images/not_favorite.png b/source/images/not_favorite.png deleted file mode 100644 index c9bd9df0..00000000 Binary files a/source/images/not_favorite.png and /dev/null differ diff --git a/source/images/nunchuk.png b/source/images/nunchuk.png deleted file mode 100644 index 1187cd65..00000000 Binary files a/source/images/nunchuk.png and /dev/null differ diff --git a/source/images/nunchukR.png b/source/images/nunchukR.png deleted file mode 100644 index 8e079079..00000000 Binary files a/source/images/nunchukR.png and /dev/null differ diff --git a/source/images/pageindicator.png b/source/images/pageindicator.png deleted file mode 100644 index 28b0f8ee..00000000 Binary files a/source/images/pageindicator.png and /dev/null differ diff --git a/source/images/pegi_12.png b/source/images/pegi_12.png deleted file mode 100644 index 5d199493..00000000 Binary files a/source/images/pegi_12.png and /dev/null differ diff --git a/source/images/pegi_16.png b/source/images/pegi_16.png deleted file mode 100644 index 039e4761..00000000 Binary files a/source/images/pegi_16.png and /dev/null differ diff --git a/source/images/pegi_18.png b/source/images/pegi_18.png deleted file mode 100644 index 102102e5..00000000 Binary files a/source/images/pegi_18.png and /dev/null differ diff --git a/source/images/pegi_3.png b/source/images/pegi_3.png deleted file mode 100644 index 34c423f4..00000000 Binary files a/source/images/pegi_3.png and /dev/null differ diff --git a/source/images/pegi_7.png b/source/images/pegi_7.png deleted file mode 100644 index b81e7514..00000000 Binary files a/source/images/pegi_7.png and /dev/null differ diff --git a/source/images/playCountIcon.png b/source/images/playCountIcon.png deleted file mode 100644 index 14609fac..00000000 Binary files a/source/images/playCountIcon.png and /dev/null differ diff --git a/source/images/player1_point.png b/source/images/player1_point.png deleted file mode 100644 index c06c08c7..00000000 Binary files a/source/images/player1_point.png and /dev/null differ diff --git a/source/images/player2_point.png b/source/images/player2_point.png deleted file mode 100644 index 6e952d24..00000000 Binary files a/source/images/player2_point.png and /dev/null differ diff --git a/source/images/player3_point.png b/source/images/player3_point.png deleted file mode 100644 index 704f84e0..00000000 Binary files a/source/images/player3_point.png and /dev/null differ diff --git a/source/images/player4_point.png b/source/images/player4_point.png deleted file mode 100644 index dd8f1ad3..00000000 Binary files a/source/images/player4_point.png and /dev/null differ diff --git a/source/images/progressbar.png b/source/images/progressbar.png deleted file mode 100644 index 747f6a4d..00000000 Binary files a/source/images/progressbar.png and /dev/null differ diff --git a/source/images/progressbar_empty.png b/source/images/progressbar_empty.png deleted file mode 100644 index e72f0c43..00000000 Binary files a/source/images/progressbar_empty.png and /dev/null differ diff --git a/source/images/progressbar_outline.png b/source/images/progressbar_outline.png deleted file mode 100644 index 6b665457..00000000 Binary files a/source/images/progressbar_outline.png and /dev/null differ diff --git a/source/images/rankIcon.png b/source/images/rankIcon.png deleted file mode 100644 index 7616dd99..00000000 Binary files a/source/images/rankIcon.png and /dev/null differ diff --git a/source/images/rplayer1_point.png b/source/images/rplayer1_point.png deleted file mode 100644 index eabd11bb..00000000 Binary files a/source/images/rplayer1_point.png and /dev/null differ diff --git a/source/images/rplayer2_point.png b/source/images/rplayer2_point.png deleted file mode 100644 index f12a5c50..00000000 Binary files a/source/images/rplayer2_point.png and /dev/null differ diff --git a/source/images/rplayer3_point.png b/source/images/rplayer3_point.png deleted file mode 100644 index d67c019c..00000000 Binary files a/source/images/rplayer3_point.png and /dev/null differ diff --git a/source/images/rplayer4_point.png b/source/images/rplayer4_point.png deleted file mode 100644 index d63ccd77..00000000 Binary files a/source/images/rplayer4_point.png and /dev/null differ diff --git a/source/images/scrollbar.png b/source/images/scrollbar.png deleted file mode 100644 index 032074db..00000000 Binary files a/source/images/scrollbar.png and /dev/null differ diff --git a/source/images/scrollbar_arrowdown.png b/source/images/scrollbar_arrowdown.png deleted file mode 100644 index ebd748c6..00000000 Binary files a/source/images/scrollbar_arrowdown.png and /dev/null differ diff --git a/source/images/scrollbar_arrowup.png b/source/images/scrollbar_arrowup.png deleted file mode 100644 index 6cef2fa0..00000000 Binary files a/source/images/scrollbar_arrowup.png and /dev/null differ diff --git a/source/images/scrollbar_box.png b/source/images/scrollbar_box.png deleted file mode 100644 index 9b568f3e..00000000 Binary files a/source/images/scrollbar_box.png and /dev/null differ diff --git a/source/images/sdcard.png b/source/images/sdcard.png deleted file mode 100644 index b3b247d9..00000000 Binary files a/source/images/sdcard.png and /dev/null differ diff --git a/source/images/sdcard_over.png b/source/images/sdcard_over.png deleted file mode 100644 index 636d3afd..00000000 Binary files a/source/images/sdcard_over.png and /dev/null differ diff --git a/source/images/searchIcon.png b/source/images/searchIcon.png deleted file mode 100644 index 2885af56..00000000 Binary files a/source/images/searchIcon.png and /dev/null differ diff --git a/source/images/searchIcon_gray.png b/source/images/searchIcon_gray.png deleted file mode 100644 index 6396ca65..00000000 Binary files a/source/images/searchIcon_gray.png and /dev/null differ diff --git a/source/images/settings_background.png b/source/images/settings_background.png deleted file mode 100644 index 02ed90db..00000000 Binary files a/source/images/settings_background.png and /dev/null differ diff --git a/source/images/settings_button.png b/source/images/settings_button.png deleted file mode 100644 index 77ce4d3f..00000000 Binary files a/source/images/settings_button.png and /dev/null differ diff --git a/source/images/settings_button_over.png b/source/images/settings_button_over.png deleted file mode 100644 index 0dba63d3..00000000 Binary files a/source/images/settings_button_over.png and /dev/null differ diff --git a/source/images/settings_menu_button.png b/source/images/settings_menu_button.png deleted file mode 100644 index 4a782e42..00000000 Binary files a/source/images/settings_menu_button.png and /dev/null differ diff --git a/source/images/settings_title.png b/source/images/settings_title.png deleted file mode 100644 index 48de5083..00000000 Binary files a/source/images/settings_title.png and /dev/null differ diff --git a/source/images/settings_title_over.png b/source/images/settings_title_over.png deleted file mode 100644 index 2111ad28..00000000 Binary files a/source/images/settings_title_over.png and /dev/null differ diff --git a/source/images/startgame_arrow_left.png b/source/images/startgame_arrow_left.png deleted file mode 100644 index 4ed6e29e..00000000 Binary files a/source/images/startgame_arrow_left.png and /dev/null differ diff --git a/source/images/startgame_arrow_right.png b/source/images/startgame_arrow_right.png deleted file mode 100644 index 0ed3d0fa..00000000 Binary files a/source/images/startgame_arrow_right.png and /dev/null differ diff --git a/source/images/theme_box.png b/source/images/theme_box.png deleted file mode 100644 index 174b7b52..00000000 Binary files a/source/images/theme_box.png and /dev/null differ diff --git a/source/images/theme_dialogue_box.png b/source/images/theme_dialogue_box.png deleted file mode 100644 index 389cfa1d..00000000 Binary files a/source/images/theme_dialogue_box.png and /dev/null differ diff --git a/source/images/tooltip_left.png b/source/images/tooltip_left.png deleted file mode 100644 index b1114ee1..00000000 Binary files a/source/images/tooltip_left.png and /dev/null differ diff --git a/source/images/tooltip_right.png b/source/images/tooltip_right.png deleted file mode 100644 index 86bd7ed5..00000000 Binary files a/source/images/tooltip_right.png and /dev/null differ diff --git a/source/images/tooltip_tile.png b/source/images/tooltip_tile.png deleted file mode 100644 index 9b68e2f7..00000000 Binary files a/source/images/tooltip_tile.png and /dev/null differ diff --git a/source/images/unlock.png b/source/images/unlock.png deleted file mode 100644 index 241f1b37..00000000 Binary files a/source/images/unlock.png and /dev/null differ diff --git a/source/images/unlock_gray.png b/source/images/unlock_gray.png deleted file mode 100644 index 8f6c90ea..00000000 Binary files a/source/images/unlock_gray.png and /dev/null differ diff --git a/source/images/usbport.png b/source/images/usbport.png deleted file mode 100644 index 78de06a8..00000000 Binary files a/source/images/usbport.png and /dev/null differ diff --git a/source/images/wbackground.png b/source/images/wbackground.png deleted file mode 100644 index 4035f47b..00000000 Binary files a/source/images/wbackground.png and /dev/null differ diff --git a/source/images/wdialogue_box_startgame.png b/source/images/wdialogue_box_startgame.png deleted file mode 100644 index 033814d8..00000000 Binary files a/source/images/wdialogue_box_startgame.png and /dev/null differ diff --git a/source/images/wheel.png b/source/images/wheel.png deleted file mode 100644 index e4e85fc8..00000000 Binary files a/source/images/wheel.png and /dev/null differ diff --git a/source/images/wheelR.png b/source/images/wheelR.png deleted file mode 100644 index b777b12d..00000000 Binary files a/source/images/wheelR.png and /dev/null differ diff --git a/source/images/wifi1.png b/source/images/wifi1.png deleted file mode 100644 index 8190f676..00000000 Binary files a/source/images/wifi1.png and /dev/null differ diff --git a/source/images/wifi12.png b/source/images/wifi12.png deleted file mode 100644 index 455f2e12..00000000 Binary files a/source/images/wifi12.png and /dev/null differ diff --git a/source/images/wifi16.png b/source/images/wifi16.png deleted file mode 100644 index 7f73c2c1..00000000 Binary files a/source/images/wifi16.png and /dev/null differ diff --git a/source/images/wifi2.png b/source/images/wifi2.png deleted file mode 100644 index 07dd889b..00000000 Binary files a/source/images/wifi2.png and /dev/null differ diff --git a/source/images/wifi3.png b/source/images/wifi3.png deleted file mode 100644 index 67204d8a..00000000 Binary files a/source/images/wifi3.png and /dev/null differ diff --git a/source/images/wifi32.png b/source/images/wifi32.png deleted file mode 100644 index 5fb2eba8..00000000 Binary files a/source/images/wifi32.png and /dev/null differ diff --git a/source/images/wifi4.png b/source/images/wifi4.png deleted file mode 100644 index 725219c6..00000000 Binary files a/source/images/wifi4.png and /dev/null differ diff --git a/source/images/wifi8.png b/source/images/wifi8.png deleted file mode 100644 index 13502a11..00000000 Binary files a/source/images/wifi8.png and /dev/null differ diff --git a/source/images/wiimote.png b/source/images/wiimote.png deleted file mode 100644 index a868c218..00000000 Binary files a/source/images/wiimote.png and /dev/null differ diff --git a/source/images/wiimote_poweroff.png b/source/images/wiimote_poweroff.png deleted file mode 100644 index 81f34462..00000000 Binary files a/source/images/wiimote_poweroff.png and /dev/null differ diff --git a/source/images/wiimote_poweroff_over.png b/source/images/wiimote_poweroff_over.png deleted file mode 100644 index 037dd7fe..00000000 Binary files a/source/images/wiimote_poweroff_over.png and /dev/null differ diff --git a/source/images/wiispeak.png b/source/images/wiispeak.png deleted file mode 100644 index 24a8e250..00000000 Binary files a/source/images/wiispeak.png and /dev/null differ diff --git a/source/images/wiispeakR.png b/source/images/wiispeakR.png deleted file mode 100644 index 272eb49a..00000000 Binary files a/source/images/wiispeakR.png and /dev/null differ diff --git a/source/images/zapper.png b/source/images/zapper.png deleted file mode 100644 index 2a6ac6e8..00000000 Binary files a/source/images/zapper.png and /dev/null differ diff --git a/source/images/zapperR.png b/source/images/zapperR.png deleted file mode 100644 index 504f802a..00000000 Binary files a/source/images/zapperR.png and /dev/null differ diff --git a/source/input.cpp b/source/input.cpp deleted file mode 100644 index 67637131..00000000 --- a/source/input.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * input.cpp - * Wii/GameCube controller management - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "menu.h" -#include "video.h" -#include "input.h" -#include "libwiigui/gui.h" - -int rumbleRequest[4] = { 0, 0, 0, 0 }; -GuiTrigger userInput[4]; -static int rumbleCount[4] = { 0, 0, 0, 0 }; - -/**************************************************************************** - * UpdatePads - * - * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad - ***************************************************************************/ -void UpdatePads() -{ - WPAD_ScanPads(); - PAD_ScanPads(); - - for (int i = 3; i >= 0; i--) - { - memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData)); - userInput[i].chan = i; - userInput[i].pad.btns_d = PAD_ButtonsDown(i); - userInput[i].pad.btns_u = PAD_ButtonsUp(i); - userInput[i].pad.btns_h = PAD_ButtonsHeld(i); - userInput[i].pad.stickX = PAD_StickX(i); - userInput[i].pad.stickY = PAD_StickY(i); - userInput[i].pad.substickX = PAD_SubStickX(i); - userInput[i].pad.substickY = PAD_SubStickY(i); - userInput[i].pad.triggerL = PAD_TriggerL(i); - userInput[i].pad.triggerR = PAD_TriggerR(i); - - if (Settings.rumble == ON) DoRumble(i); - } -} - -/**************************************************************************** - * SetupPads - * - * Sets up userInput triggers for use - ***************************************************************************/ -void SetupPads() -{ - PAD_Init(); - WPAD_Init(); - - // read wiimote accelerometer and IR data - WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - - for (int i = 0; i < 4; i++) - { - userInput[i].chan = i; - } -} - -/**************************************************************************** - * ShutoffRumble - ***************************************************************************/ - -void ShutoffRumble() -{ - for (int i = 0; i < 4; i++) - { - WPAD_Rumble(i, 0); - rumbleCount[i] = 0; - } -} - -/**************************************************************************** - * DoRumble - ***************************************************************************/ - -void DoRumble(int i) -{ - if (rumbleRequest[i] && rumbleCount[i] < 3) - { - WPAD_Rumble(i, 1); // rumble on - rumbleCount[i]++; - } - else if (rumbleRequest[i]) - { - rumbleCount[i] = 20; - rumbleRequest[i] = 0; - } - else - { - if (rumbleCount[i]) rumbleCount[i]--; - WPAD_Rumble(i, 0); // rumble off - } -} - -/**************************************************************************** - * WPAD_Stick - * - * Get X/Y value from Wii Joystick (classic, nunchuk) input - ***************************************************************************/ - -s8 WPAD_Stick(u8 chan, u8 right, int axis) -{ - float mag = 0.0; - float ang = 0.0; - WPADData *data = WPAD_Data(chan); - - switch (data->exp.type) - { - case WPAD_EXP_NUNCHUK: - case WPAD_EXP_GUITARHERO3: - if (right == 0) - { - mag = data->exp.nunchuk.js.mag; - ang = data->exp.nunchuk.js.ang; - } - break; - - case WPAD_EXP_CLASSIC: - if (right == 0) - { - mag = data->exp.classic.ljs.mag; - ang = data->exp.classic.ljs.ang; - } - else - { - mag = data->exp.classic.rjs.mag; - ang = data->exp.classic.rjs.ang; - } - break; - - default: - break; - } - - /* calculate x/y value (angle need to be converted into radian) */ - if (mag > 1.0) - mag = 1.0; - else if (mag < -1.0) mag = -1.0; - double val; - - if (axis == 0) // x-axis - val = mag * sin((PI * ang) / 180.0f); - else // y-axis - val = mag * cos((PI * ang) / 180.0f); - - return (s8) (val * 128.0f); -} diff --git a/source/input.h b/source/input.h deleted file mode 100644 index 37d417a4..00000000 --- a/source/input.h +++ /dev/null @@ -1,25 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * input.h - * Wii/GameCube controller management - ***************************************************************************/ - -#ifndef _INPUT_H_ -#define _INPUT_H_ - -#include -#include - -#define PI 3.14159265f -#define PADCAL 50 - -extern int rumbleRequest[4]; - -void SetupPads(); -void UpdatePads(); -void ShutoffRumble(); -void DoRumble(int i); - -#endif diff --git a/source/language/UpdateLanguage.cpp b/source/language/UpdateLanguage.cpp deleted file mode 100644 index 289bc563..00000000 --- a/source/language/UpdateLanguage.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** - * languagefile updater - * for USB Loader GX *giantpune* - ***************************************************************************/ -#include -#include -#include -#include - -#include "UpdateLanguage.h" -#include "gettext.h" -#include "FileOperations/fileops.h" -#include "FileOperations/DirList.h" -#include "menu.h" -#include "network/networkops.h" -#include "network/http.h" -#include "network/URL_List.h" -#include "prompts/ProgressWindow.h" -#include "utils/ShowError.h" -#include "gecko.h" - -static const char * LanguageFilesURL = "http://usbloader-gui.googlecode.com/svn/trunk/Languages/"; - -int DownloadAllLanguageFiles() -{ - if(!CreateSubfolder(Settings.languagefiles_path)) - { - ShowError(tr("Could not create path: %s"), Settings.languagefiles_path); - return -1; - } - - if(!IsNetworkInit()) - { - ShowError(tr("Network is not initiated.")); - return -2; - } - char fullURL[300]; - - URL_List LinkList(LanguageFilesURL); - int listsize = LinkList.GetURLCount(); - int files_downloaded = 0; - - ShowProgress(tr("Updating Language Files:"), 0, 0, 0, listsize, false, true); - - for (int i = 0; i < listsize; i++) - { - const char * filename = strrchr(LinkList.GetURL(i), '/'); - if(filename) filename++; - else filename = LinkList.GetURL(i); - - if(!filename) - continue; - - const char * FileExt = strrchr(filename, '.'); - if (!FileExt || strcasecmp(FileExt, ".lang") != 0) - continue; - - gprintf("%s\n", filename); - - ShowProgress(tr("Updating Language Files:"), 0, filename, i, listsize, false, true); - - snprintf(fullURL, sizeof(fullURL), "%s%s", LanguageFilesURL, filename); - - struct block file = downloadfile(fullURL); - if (file.data) - { - char filepath[300]; - snprintf(filepath, sizeof(filepath), "%s/%s", Settings.languagefiles_path, filename); - FILE * pfile = fopen(filepath, "wb"); - if(pfile) - { - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - files_downloaded++; - } - free(file.data); - } - } - - ProgressStop(); - - return files_downloaded; -} - -int UpdateLanguageFiles() -{ - if(!CreateSubfolder(Settings.languagefiles_path)) - { - ShowError(tr("Could not create path: %s"), Settings.languagefiles_path); - return -1; - } - - if(!IsNetworkInit()) - { - ShowError(tr("Network is not initiated.")); - return -2; - } - - DirList Dir(Settings.languagefiles_path, ".lang"); - - //give up now if we didn't find any - if (Dir.GetFilecount() == 0) return -2; - - char savepath[150]; - char codeurl[200]; - - //we assume that the network will already be init by another function - // ( that has gui eletents in it because this one doesn't) - int done = 0; - - //build the URL, save path, and download each file and save it - for(int i = 0; i < Dir.GetFilecount(); ++i) - { - snprintf(codeurl, sizeof(codeurl), "%s%s", LanguageFilesURL, Dir.GetFilename(i)); - snprintf(savepath, sizeof(savepath), "%s/%s", Settings.languagefiles_path, Dir.GetFilename(i)); - - struct block file = downloadfile(codeurl); - - ShowProgress(tr("Updating Language Files:"), 0, Dir.GetFilename(i), i, Dir.GetFilecount(), false, true); - - if (file.data != NULL) - { - FILE * pfile; - pfile = fopen(savepath, "wb"); - if (pfile != NULL) - { - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - done++; - } - free(file.data); - } - } - - ProgressStop(); - - // return the number of files we updated - return done; -} - diff --git a/source/language/UpdateLanguage.h b/source/language/UpdateLanguage.h deleted file mode 100644 index 6e80e34a..00000000 --- a/source/language/UpdateLanguage.h +++ /dev/null @@ -1,19 +0,0 @@ -/**************************************************************************** - * language update - * for USB Loader GX *giantpune* - ***************************************************************************/ -#ifndef ___UPDATELANGUAGE_H_ -#define ___UPDATELANGUAGE_H_ - -#define MAXLANGUAGEFILES 50 - -//! Checks the language path for files ending in .lang and updates them (up to MAXLANGUAGEFILES) -//! This function expects that the network is already init before it is called - -//! returns the number of files successfully updated -//! returns -2 if it can't find any .lang files in the path -//! return -1 if there is no network connection -int UpdateLanguageFiles(); -int DownloadAllLanguageFiles(); - -#endif diff --git a/source/language/gettext.c b/source/language/gettext.c deleted file mode 100644 index 2487a2ad..00000000 --- a/source/language/gettext.c +++ /dev/null @@ -1,241 +0,0 @@ -#include -#include -#include -#include -#include "gettext.h" - -typedef struct _MSG -{ - u32 id; - char* msgstr; - struct _MSG *next; -} MSG; -static MSG *baseMSG = 0; - -#define HASHWORDBITS 32 - -/* Defines the so called `hashpjw' function by P.J. Weinberger - [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, - 1986, 1987 Bell Telephone Laboratories, Inc.] */ -static inline u32 hash_string(const char *str_param) -{ - u32 hval, g; - const char *str = str_param; - - /* Compute the hash value for the given string. */ - hval = 0; - while (*str != '\0') - { - hval <<= 4; - hval += (u8) *str++; - g = hval & ((u32) 0xf << (HASHWORDBITS - 4)); - if (g != 0) - { - hval ^= g >> (HASHWORDBITS - 8); - hval ^= g; - } - } - return hval; -} - -/* Expand some escape sequences found in the argument string. */ -static char * -expand_escape(const char *str) -{ - char *retval, *rp; - const char *cp = str; - - retval = (char *) malloc(strlen(str) + 1); - if (retval == NULL) return NULL; - rp = retval; - - while (cp[0] != '\0' && cp[0] != '\\') - *rp++ = *cp++; - if (cp[0] == '\0') goto terminate; - do - { - - /* Here cp[0] == '\\'. */ - switch (*++cp) - { - case '\"': /* " */ - *rp++ = '\"'; - ++cp; - break; - case 'a': /* alert */ - *rp++ = '\a'; - ++cp; - break; - case 'b': /* backspace */ - *rp++ = '\b'; - ++cp; - break; - case 'f': /* form feed */ - *rp++ = '\f'; - ++cp; - break; - case 'n': /* new line */ - *rp++ = '\n'; - ++cp; - break; - case 'r': /* carriage return */ - *rp++ = '\r'; - ++cp; - break; - case 't': /* horizontal tab */ - *rp++ = '\t'; - ++cp; - break; - case 'v': /* vertical tab */ - *rp++ = '\v'; - ++cp; - break; - case '\\': - *rp = '\\'; - ++cp; - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - { - int ch = *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - - if (*cp >= '0' && *cp <= '7') - { - ch *= 8; - ch += *cp++ - '0'; - } - } - *rp = ch; - } - break; - default: - *rp = '\\'; - break; - } - - while (cp[0] != '\0' && cp[0] != '\\') - *rp++ = *cp++; - } while (cp[0] != '\0'); - - /* Terminate string. */ - terminate: *rp = '\0'; - return retval; -} - -static MSG *findMSG(u32 id) -{ - MSG *msg; - for (msg = baseMSG; msg; msg = msg->next) - { - if (msg->id == id) return msg; - } - return NULL; -} - -static MSG *setMSG(const char *msgid, const char *msgstr) -{ - u32 id = hash_string(msgid); - MSG *msg = findMSG(id); - if (!msg) - { - msg = (MSG *) malloc(sizeof(MSG)); - msg->id = id; - msg->msgstr = NULL; - msg->next = baseMSG; - baseMSG = msg; - } - if (msg) - { - if (msgstr) - { - if (msg->msgstr) free(msg->msgstr); - //msg->msgstr = strdup(msgstr); - msg->msgstr = expand_escape(msgstr); - } - return msg; - } - return NULL; -} -void gettextCleanUp(void) -{ - while (baseMSG) - { - MSG *nextMsg = baseMSG->next; - free(baseMSG->msgstr); - free(baseMSG); - baseMSG = nextMsg; - } -} - -bool gettextLoadLanguage(const char* langFile) -{ - FILE *f; - char line[512]; - char *lastID = NULL; - - gettextCleanUp(); - f = fopen(langFile, "r"); - if (!f) return false; - - while (fgets(line, sizeof(line), f)) - { - // lines starting with # are comments - if (line[0] == '#') - continue; - else if (strncmp(line, "msgid \"", 7) == 0) - { - char *msgid, *end; - if (lastID) - { - free(lastID); - lastID = NULL; - } - msgid = &line[7]; - end = strrchr(msgid, '"'); - if (end && end - msgid > 1) - { - *end = 0; - lastID = strdup(msgid); - } - } - else if (strncmp(line, "msgstr \"", 8) == 0) - { - char *msgstr, *end; - - if (lastID == NULL) continue; - - msgstr = &line[8]; - end = strrchr(msgstr, '"'); - if (end && end - msgstr > 1) - { - *end = 0; - setMSG(lastID, msgstr); - } - free(lastID); - lastID = NULL; - } - - } - - fclose(f); - return true; -} -const char *gettext(const char *msgid) -{ - if(!msgid) return NULL; - MSG *msg = findMSG(hash_string(msgid)); - if (msg && msg->msgstr) return msg->msgstr; - return msgid; -} - diff --git a/source/language/gettext.h b/source/language/gettext.h deleted file mode 100644 index 25140c7a..00000000 --- a/source/language/gettext.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _GETTEXT_H_ -#define _GETTEXT_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - bool gettextLoadLanguage(const char* langFile); - void gettextCleanUp(void); - /* - * input msg = a text in ASCII - * output = the translated msg in utf-8 - */ - const char *gettext(const char *msg); -#define tr(s) gettext(s) -#define trNOOP(s) (s) - -#ifdef __cplusplus -} -#endif - -#endif /* _GETTEXT_H_ */ diff --git a/source/libs/libext2fs/libcustomext2fs.a b/source/libs/libext2fs/libcustomext2fs.a deleted file mode 100644 index da332bc6..00000000 Binary files a/source/libs/libext2fs/libcustomext2fs.a and /dev/null differ diff --git a/source/libs/libfat/libcustomfat.a b/source/libs/libfat/libcustomfat.a deleted file mode 100644 index fd5ac19b..00000000 Binary files a/source/libs/libfat/libcustomfat.a and /dev/null differ diff --git a/source/libs/libntfs/libcustomntfs.a b/source/libs/libntfs/libcustomntfs.a deleted file mode 100644 index 5bba67a5..00000000 Binary files a/source/libs/libntfs/libcustomntfs.a and /dev/null differ diff --git a/source/libs/libwbfs/libwbfs.c b/source/libs/libwbfs/libwbfs.c deleted file mode 100644 index 57a4df82..00000000 --- a/source/libs/libwbfs/libwbfs.c +++ /dev/null @@ -1,827 +0,0 @@ -// Copyright 2009 Kwiirk -// Licensed under the terms of the GNU GPL, version 2 -// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt - -// Modified by oggzee - -#include "libwbfs.h" - -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) - -#define ERROR(x) do {wbfs_error(x);goto error;}while(0) -#define ALIGN_LBA(x) (((x)+p->hd_sec_sz-1)&(~(p->hd_sec_sz-1))) - -wbfs_t wbfs_iso_file; - -static int force_mode = 0; - -void wbfs_set_force_mode(int force) -{ - force_mode = force; -} - -static u8 size_to_shift(u32 size) -{ - u8 ret = 0; - while (size) - { - ret++; - size >>= 1; - } - return ret - 1; -} -#define read_le32_unaligned(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24)) - -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 __attribute( ( unused ) ), int reset) -{ - int i = num_hd_sector, ret; - u8 *ptr, *tmp_buffer = wbfs_ioalloc( hd_sector_size ); - u8 part_table[16 * 4]; - ret = read_hdsector(callback_data, 0, 1, tmp_buffer); - if (ret) return 0; - //find wbfs partition - wbfs_memcpy( part_table, tmp_buffer + 0x1be, 16*4 ); - ptr = part_table; - for (i = 0; i < 4; i++, ptr += 16) - { - u32 part_lba = read_le32_unaligned( ptr + 0x8 ); - wbfs_head_t *head = (wbfs_head_t *) tmp_buffer; - ret = read_hdsector(callback_data, part_lba, 1, tmp_buffer); - // verify there is the magic. - if (head->magic == wbfs_htonl( WBFS_MAGIC )) - { - wbfs_t*p = wbfs_open_partition(read_hdsector, write_hdsector, callback_data, hd_sector_size, 0, part_lba, - reset); - wbfs_iofree( tmp_buffer ); - return p; - } - } - wbfs_iofree( tmp_buffer ); - if (reset)// XXX make a empty hd partition.. - { - } - return 0; -} -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 part_lba, int reset) -{ - wbfs_t *p = wbfs_malloc( sizeof( wbfs_t ) ); - - wbfs_head_t *head = wbfs_ioalloc( hd_sector_size ? hd_sector_size : 512 ); - - //constants, but put here for consistancy - p->wii_sec_sz = 0x8000; - p->wii_sec_sz_s = size_to_shift(0x8000); - p->n_wii_sec = (num_hd_sector / 0x8000) * hd_sector_size; - p->n_wii_sec_per_disc = 143432 * 2;//support for double layers discs.. - p->head = head; - p->part_lba = part_lba; - // init the partition - if (reset) - { - u8 sz_s; - wbfs_memset( head, 0, hd_sector_size ); - head->magic = wbfs_htonl( WBFS_MAGIC ); - head->hd_sec_sz_s = size_to_shift(hd_sector_size); - head->n_hd_sec = wbfs_htonl( num_hd_sector ); - // choose minimum wblk_sz that fits this partition size - for (sz_s = 6; sz_s < 11; sz_s++) - { - // ensure that wbfs_sec_sz is big enough to address every blocks using 16 bits - if (p->n_wii_sec < ((1U << 16) * (1 << sz_s))) break; - } - head->wbfs_sec_sz_s = sz_s + p->wii_sec_sz_s; - } - else read_hdsector(callback_data, p->part_lba, 1, head); - if (head->magic != wbfs_htonl( WBFS_MAGIC )) - ERROR( "bad magic" ); - if (!force_mode && hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size)) - ERROR( "hd sector size doesn't match" ); - if (!force_mode && num_hd_sector && head->n_hd_sec != wbfs_htonl( num_hd_sector )) - ERROR( "hd num sector doesn't match" ); - p->hd_sec_sz = 1 << head->hd_sec_sz_s; - p->hd_sec_sz_s = head->hd_sec_sz_s; - p->n_hd_sec = wbfs_ntohl( head->n_hd_sec ); - - p->n_wii_sec = (p->n_hd_sec / p->wii_sec_sz) * (p->hd_sec_sz); - - p->wbfs_sec_sz_s = head->wbfs_sec_sz_s; - p->wbfs_sec_sz = 1 << p->wbfs_sec_sz_s; - p->n_wbfs_sec = p->n_wii_sec >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s); - p->n_wbfs_sec_per_disc = p->n_wii_sec_per_disc >> (p->wbfs_sec_sz_s - p->wii_sec_sz_s); - p->disc_info_sz = ALIGN_LBA( sizeof( wbfs_disc_info_t ) + p->n_wbfs_sec_per_disc * 2 ); - - //printf("hd_sector_size %X wii_sector size %X wbfs sector_size %X\n",p->hd_sec_sz,p->wii_sec_sz,p->wbfs_sec_sz); - p->read_hdsector = read_hdsector; - p->write_hdsector = write_hdsector; - p->callback_data = callback_data; - - p->freeblks_lba = (p->wbfs_sec_sz - p->n_wbfs_sec / 8) >> p->hd_sec_sz_s; - - if (!reset) - p->freeblks = 0; // will alloc and read only if needed - else - { - // init with all free blocks - p->freeblks = wbfs_ioalloc( ALIGN_LBA( p->n_wbfs_sec / 8 ) ); - wbfs_memset( p->freeblks, 0xff, p->n_wbfs_sec / 8 ); - } - p->max_disc = (p->freeblks_lba - 1) / (p->disc_info_sz >> p->hd_sec_sz_s); - if (p->max_disc > p->hd_sec_sz - sizeof(wbfs_head_t)) p->max_disc = p->hd_sec_sz - sizeof(wbfs_head_t); - - p->tmp_buffer = wbfs_ioalloc( p->hd_sec_sz ); - p->n_disc_open = 0; - return p; - error: wbfs_free( p ); - wbfs_iofree( head ); - return 0; - -} - -void wbfs_sync(wbfs_t*p) -{ - // copy back descriptors - if (p->write_hdsector) - { - p->write_hdsector(p->callback_data, p->part_lba + 0, 1, p->head); - - if (p->freeblks) p->write_hdsector(p->callback_data, p->part_lba + p->freeblks_lba, - ALIGN_LBA( p->n_wbfs_sec / 8 ) >> p->hd_sec_sz_s, p->freeblks); - } -} - -void wbfs_close(wbfs_t*p) -{ - wbfs_sync(p); - - if (p->n_disc_open) - ERROR( "trying to close wbfs while discs still open" ); - - wbfs_iofree( p->head ); - wbfs_iofree( p->tmp_buffer ); - if (p->freeblks) wbfs_iofree( p->freeblks ); - - wbfs_free( p ); - - error: return; -} - -wbfs_disc_t *wbfs_open_disc(wbfs_t* p, u8 *discid) -{ - u32 i; - int disc_info_sz_lba = p->disc_info_sz >> p->hd_sec_sz_s; - wbfs_disc_t *d = 0; - for (i = 0; i < p->max_disc; i++) - { - if (p->head->disc_table[i]) - { - p->read_hdsector(p->callback_data, p->part_lba + 1 + i * disc_info_sz_lba, 1, p->tmp_buffer); - if (wbfs_memcmp( discid, p->tmp_buffer, 6 ) == 0) - { - d = wbfs_malloc( sizeof( *d ) ); - if (!d) - ERROR( "allocating memory" ); - d->p = p; - d->i = i; - d->header = wbfs_ioalloc( p->disc_info_sz ); - if (!d->header) - ERROR( "allocating memory" ); - p->read_hdsector(p->callback_data, p->part_lba + 1 + i * disc_info_sz_lba, disc_info_sz_lba, d->header); - p->n_disc_open++; - // for(i=0;in_wbfs_sec_per_disc;i++) - // printf("%d,",wbfs_ntohs(d->header->wlba_table[i])); - return d; - } - } - } - return 0; - error: if (d) wbfs_iofree( d ); - return 0; - -} -void wbfs_close_disc(wbfs_disc_t*d) -{ - d->p->n_disc_open--; - wbfs_iofree( d->header ); - wbfs_free( d ); -} -// offset is pointing 32bit words to address the whole dvd, although len is in bytes -int wbfs_disc_read(wbfs_disc_t*d, u32 offset, u32 len, u8 *data) -{ - if (d->p == &wbfs_iso_file) - { - return wbfs_iso_file_read(d, offset, data, len); - } - - wbfs_t *p = d->p; - u16 wlba = offset >> (p->wbfs_sec_sz_s - 2); - u32 iwlba_shift = p->wbfs_sec_sz_s - p->hd_sec_sz_s; - u32 lba_mask = (p->wbfs_sec_sz - 1) >> (p->hd_sec_sz_s); - u32 lba = (offset >> (p->hd_sec_sz_s - 2)) & lba_mask; - u32 off = offset & ((p->hd_sec_sz >> 2) - 1); - u16 iwlba = wbfs_ntohs( d->header->wlba_table[wlba] ); - u32 len_copied; - int err = 0; - u8 *ptr = data; - if (unlikely( iwlba == 0 )) return 1; - if (unlikely( off )) - { - off *= 4; - err = p->read_hdsector(p->callback_data, p->part_lba + (iwlba << iwlba_shift) + lba, 1, p->tmp_buffer); - if (err) return err; - len_copied = p->hd_sec_sz - off; - if (likely( len < len_copied )) len_copied = len; - wbfs_memcpy( ptr, p->tmp_buffer + off, len_copied ); - len -= len_copied; - ptr += len_copied; - lba++; - if (unlikely( lba > lba_mask && len )) - { - lba = 0; - iwlba = wbfs_ntohs( d->header->wlba_table[++wlba] ); - if (unlikely( iwlba == 0 )) return 1; - } - } - while (likely( len >= p->hd_sec_sz )) - { - u32 nlb = len >> (p->hd_sec_sz_s); - - if (unlikely( lba + nlb > p->wbfs_sec_sz )) // dont cross wbfs sectors.. - nlb = p->wbfs_sec_sz - lba; - err = p->read_hdsector(p->callback_data, p->part_lba + (iwlba << iwlba_shift) + lba, nlb, ptr); - if (err) return err; - len -= nlb << p->hd_sec_sz_s; - ptr += nlb << p->hd_sec_sz_s; - lba += nlb; - if (unlikely( lba > lba_mask && len )) - { - lba = 0; - iwlba = wbfs_ntohs( d->header->wlba_table[++wlba] ); - if (unlikely( iwlba == 0 )) return 1; - } - } - if (unlikely( len )) - { - err = p->read_hdsector(p->callback_data, p->part_lba + (iwlba << iwlba_shift) + lba, 1, p->tmp_buffer); - if (err) return err; - wbfs_memcpy( ptr, p->tmp_buffer, len ); - } - return 0; -} - -// disc listing -u32 wbfs_count_discs(wbfs_t*p) -{ - u32 i, count = 0; - for (i = 0; i < p->max_disc; i++) - if (p->head->disc_table[i]) count++; - return count; - -} - -u32 wbfs_sector_used(wbfs_t *p, wbfs_disc_info_t *di) -{ - u32 tot_blk = 0, j; - for (j = 0; j < p->n_wbfs_sec_per_disc; j++) - if (wbfs_ntohs( di->wlba_table[j] )) tot_blk++; - return tot_blk; -} - -u32 wbfs_sector_used2(wbfs_t *p, wbfs_disc_info_t *di, u32 *last_blk) -{ - u32 tot_blk = 0, j; - for (j = 0; j < p->n_wbfs_sec_per_disc; j++) - if (wbfs_ntohs( di->wlba_table[j] )) - { - if (last_blk) *last_blk = j; - tot_blk++; - } - return tot_blk; -} - -u32 wbfs_get_disc_info(wbfs_t*p, u32 index, u8 *header, int header_size, u32 *size)//size in 32 bit -{ - u32 i, count = 0; - if (!p) return 1; - int disc_info_sz_lba = p->disc_info_sz >> p->hd_sec_sz_s; - - for (i = 0; i < p->max_disc; i++) - if (p->head->disc_table[i]) - { - if (count++ == index) - { - p->read_hdsector(p->callback_data, p->part_lba + 1 + i * disc_info_sz_lba, 1, p->tmp_buffer); - if (header_size > (int) p->hd_sec_sz) header_size = p->hd_sec_sz; - u32 magic = wbfs_ntohl( *( u32* )( p->tmp_buffer + 24 ) ); - if (magic != 0x5D1C9EA3) - { - p->head->disc_table[i] = 0; - return 1; - } - memcpy(header, p->tmp_buffer, header_size); - if (size) - { - u8 *header = wbfs_ioalloc( p->disc_info_sz ); - p->read_hdsector(p->callback_data, p->part_lba + 1 + i * disc_info_sz_lba, disc_info_sz_lba, header); - u32 sec_used = wbfs_sector_used(p, (wbfs_disc_info_t *) header); - wbfs_iofree( header ); - *size = sec_used << (p->wbfs_sec_sz_s - 2); - } - return 0; - } - } - return 1; -} - -static void load_freeblocks(wbfs_t*p) -{ - if (p->freeblks) return; - // XXX should handle malloc error.. - p->freeblks = wbfs_ioalloc( ALIGN_LBA( p->n_wbfs_sec / 8 ) ); - p->read_hdsector(p->callback_data, p->part_lba + p->freeblks_lba, ALIGN_LBA( p->n_wbfs_sec / 8 ) >> p->hd_sec_sz_s, - p->freeblks); - -} -u32 wbfs_count_usedblocks(wbfs_t*p) -{ - u32 i, j, count = 0; - load_freeblocks(p); - for (i = 0; i < p->n_wbfs_sec / (8 * 4); i++) - { - u32 v = wbfs_ntohl( p->freeblks[i] ); - if (v == ~0U) - count += 32; - else if (v != 0) for (j = 0; j < 32; j++) - if (v & (1 << j)) count++; - } - return count; -} - -// write access - - -//static -int block_used(u8 *used, u32 i, u32 wblk_sz) -{ - u32 k; - i *= wblk_sz; - for (k = 0; k < wblk_sz; k++) - if (i + k < 143432 * 2 && used[i + k]) return 1; - return 0; -} - -static u32 alloc_block(wbfs_t*p) -{ - u32 i, j; - for (i = 0; i < p->n_wbfs_sec / (8 * 4); i++) - { - u32 v = wbfs_ntohl( p->freeblks[i] ); - if (v != 0) - { - for (j = 0; j < 32; j++) - if (v & (1 << j)) - { - p->freeblks[i] = wbfs_htonl( v & ~( 1 << j ) ); - return (i * 32) + j + 1; - } - } - } - return ~0; -} -static void free_block(wbfs_t *p, int bl) -{ - int i = (bl - 1) / (32); - int j = (bl - 1) & 31; - u32 v = wbfs_ntohl( p->freeblks[i] ); - p->freeblks[i] = wbfs_htonl( v | 1 << j ); -} - -s32 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) -{ - int i, discn; - u32 tot, cur; - u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s - p->wii_sec_sz_s); - wiidisc_t *d = 0; - u8 *used = 0; - wbfs_disc_info_t *info = 0; - u8* copy_buffer = 0; - int retval = -1; - int num_wbfs_sect_to_copy; - u32 last_used; - used = wbfs_malloc( p->n_wii_sec_per_disc ); - - if (!used) - ERROR( "unable to alloc memory" ); - // copy_1_1 needs disk usage for layers detection - //if(!copy_1_1) - { - d = wd_open_disc(read_src_wii_disc, callback_data); - if (!d) - ERROR( "unable to open wii disc" ); - wd_build_disc_usage(d, sel, used); - wd_close_disc(d); - d = 0; - } - - for (i = 0; i < p->max_disc; i++)// find a free slot. - if (p->head->disc_table[i] == 0) break; - if (i == p->max_disc) - ERROR( "no space left on device (table full)" ); - p->head->disc_table[i] = 1; - discn = i; - load_freeblocks(p); - - // build disc info - info = wbfs_ioalloc( p->disc_info_sz ); - read_src_wii_disc(callback_data, 0, 0x100, info->disc_header_copy); - - copy_buffer = wbfs_ioalloc( p->wii_sec_sz ); - if (!copy_buffer) - ERROR( "alloc memory" ); - tot = 0; - cur = 0; - num_wbfs_sect_to_copy = p->n_wbfs_sec_per_disc; - // count total number of sectors to write - last_used = 0; - for (i = 0; i < num_wbfs_sect_to_copy; i++) - { - if (block_used(used, i, wii_sec_per_wbfs_sect)) - { - tot += wii_sec_per_wbfs_sect; - last_used = i; - } - } - if (copy_1_1) - { - // detect single or dual layer - if ((last_used + 1) > (p->n_wbfs_sec_per_disc / 2)) - { - // dual layer - num_wbfs_sect_to_copy = p->n_wbfs_sec_per_disc; - } - else - { - // single layer - num_wbfs_sect_to_copy = p->n_wbfs_sec_per_disc / 2; - } - tot = num_wbfs_sect_to_copy * wii_sec_per_wbfs_sect; - } - /* - // num of hd sectors to copy could be specified directly - if (copy_1_1 > 1) { - u32 hd_sec_per_wii_sec = p->wii_sec_sz / p->hd_sec_sz; - num_wbfs_sect_to_copy = copy_1_1 / hd_sec_per_wii_sec / wii_sec_per_wbfs_sect; - tot = num_wbfs_sect_to_copy * wii_sec_per_wbfs_sect; - }*/ - int ret = 0; - if (spinner) spinner(0, tot); - for (i = 0; i < num_wbfs_sect_to_copy; i++) - { - u16 bl = 0; - if (copy_1_1 || block_used(used, i, wii_sec_per_wbfs_sect)) - { - u16 j; - - bl = alloc_block(p); - if (bl == 0xffff) - ERROR( "no space left on device (disc full)" ); - for (j = 0; j < wii_sec_per_wbfs_sect; j++) - { - u32 offset = (i * (p->wbfs_sec_sz >> 2)) + (j * (p->wii_sec_sz >> 2)); - - ret = read_src_wii_disc(callback_data, offset, p->wii_sec_sz, copy_buffer); - if (ret) - { - if (copy_1_1 && i > p->n_wbfs_sec_per_disc / 2) - { - // end of dual layer data - if (j > 0) - { - info->wlba_table[i] = wbfs_htons( bl ); - } - spinner(tot, tot); - break; - } - //ERROR("read error"); - printf("\rWARNING: read (%u) error (%d)\n", offset, ret); - } - - //fix the partition table - if (offset == (0x40000 >> 2)) wd_fix_partition_table(d, sel, copy_buffer); - p->write_hdsector(p->callback_data, p->part_lba + bl * (p->wbfs_sec_sz / p->hd_sec_sz) + j - * (p->wii_sec_sz / p->hd_sec_sz), p->wii_sec_sz / p->hd_sec_sz, copy_buffer); - cur++; - if (spinner) spinner(cur, tot); - } - } - if (ret) break; - info->wlba_table[i] = wbfs_htons( bl ); - wbfs_sync(p); - } - // write disc info - int disc_info_sz_lba = p->disc_info_sz >> p->hd_sec_sz_s; - p->write_hdsector(p->callback_data, p->part_lba + 1 + discn * disc_info_sz_lba, disc_info_sz_lba, info); - wbfs_sync(p); - retval = 0; - error: if (d) wd_close_disc(d); - if (used) wbfs_free( used ); - if (info) wbfs_iofree( info ); - if (copy_buffer) wbfs_iofree( copy_buffer ); - // init with all free blocks - - return retval; -} - -u32 wbfs_rm_disc(wbfs_t*p, u8* discid) -{ - wbfs_disc_t *d = wbfs_open_disc(p, discid); - int i; - int discn = 0; - int disc_info_sz_lba = p->disc_info_sz >> p->hd_sec_sz_s; - if (!d) return 1; - load_freeblocks(p); - discn = d->i; - for (i = 0; i < p->n_wbfs_sec_per_disc; i++) - { - u32 iwlba = wbfs_ntohs( d->header->wlba_table[i] ); - if (iwlba) free_block(p, iwlba); - } - memset(d->header, 0, p->disc_info_sz); - p->write_hdsector(p->callback_data, p->part_lba + 1 + discn * disc_info_sz_lba, disc_info_sz_lba, d->header); - p->head->disc_table[discn] = 0; - wbfs_close_disc(d); - wbfs_sync(p); - return 0; -} - -u32 wbfs_ren_disc(wbfs_t*p, u8* discid, u8* newname) -{ - wbfs_disc_t *d = wbfs_open_disc(p, discid); - int disc_info_sz_lba = p->disc_info_sz >> p->hd_sec_sz_s; - - if (!d) return 1; - - memset(d->header->disc_header_copy + 0x20, 0, 0x40); - strncpy((char *) d->header->disc_header_copy + 0x20, (char *) newname, 0x39); - - p->write_hdsector(p->callback_data, p->part_lba + 1 + d->i * disc_info_sz_lba, disc_info_sz_lba, d->header); - wbfs_close_disc(d); - return 0; -} - -u32 wbfs_rID_disc(wbfs_t*p, u8* discid, u8* newID) -{ - wbfs_disc_t *d = wbfs_open_disc(p, discid); - int disc_info_sz_lba = p->disc_info_sz >> p->hd_sec_sz_s; - - if (!d) return 1; - - memset(d->header->disc_header_copy, 0, 0x10); - strncpy((char *) d->header->disc_header_copy, (char *) newID, 0x9); - - p->write_hdsector(p->callback_data, p->part_lba + 1 + d->i * disc_info_sz_lba, disc_info_sz_lba, d->header); - wbfs_close_disc(d); - return 0; -} - -// trim the file-system to its minimum size -u32 wbfs_trim(wbfs_t*p) -{ - u32 maxbl; - load_freeblocks(p); - maxbl = alloc_block(p); - p->n_hd_sec = maxbl << (p->wbfs_sec_sz_s - p->hd_sec_sz_s); - p->head->n_hd_sec = wbfs_htonl( p->n_hd_sec ); - // make all block full - memset(p->freeblks, 0, p->n_wbfs_sec / 8); - wbfs_sync(p); - // os layer will truncate the file. - return maxbl; -} - -// data extraction -u32 wbfs_extract_disc(wbfs_disc_t*d, rw_sector_callback_t write_dst_wii_sector, void *callback_data, - progress_callback_t spinner) -{ - wbfs_t *p = d->p; - u8* copy_buffer = 0; - int i; - int src_wbs_nlb = p->wbfs_sec_sz / p->hd_sec_sz; - int dst_wbs_nlb = p->wbfs_sec_sz / p->wii_sec_sz; - copy_buffer = wbfs_ioalloc( p->wbfs_sec_sz ); - if (!copy_buffer) - ERROR( "alloc memory" ); - - for (i = 0; i < p->n_wbfs_sec_per_disc; i++) - { - u32 iwlba = wbfs_ntohs( d->header->wlba_table[i] ); - if (iwlba) - { - - if (spinner) spinner(i, p->n_wbfs_sec_per_disc); - p->read_hdsector(p->callback_data, p->part_lba + iwlba * src_wbs_nlb, src_wbs_nlb, copy_buffer); - write_dst_wii_sector(callback_data, i * dst_wbs_nlb, dst_wbs_nlb, copy_buffer); - } - } - wbfs_iofree( copy_buffer ); - return 0; - error: return 1; -} - -float wbfs_estimate_disc(wbfs_t *p, read_wiidisc_callback_t read_src_wii_disc, void *callback_data, - partition_selector_t sel) -{ - u8 *b; - int i; - u32 tot; - u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s - p->wii_sec_sz_s); - wiidisc_t *d = 0; - u8 *used = 0; - wbfs_disc_info_t *info = 0; - - tot = 0; - - used = wbfs_malloc( p->n_wii_sec_per_disc ); - if (!used) - { - ERROR( "unable to alloc memory" ); - } - - d = wd_open_disc(read_src_wii_disc, callback_data); - if (!d) - { - ERROR( "unable to open wii disc" ); - } - - wd_build_disc_usage(d, sel, used); - wd_close_disc(d); - d = 0; - - info = wbfs_ioalloc( p->disc_info_sz ); - b = (u8 *) info; - read_src_wii_disc(callback_data, 0, 0x100, info->disc_header_copy); - - //fprintf(stderr, "estimating %c%c%c%c%c%c %s...\n",b[0], b[1], b[2], b[3], b[4], b[5], b + 0x20); - - for (i = 0; i < p->n_wbfs_sec_per_disc; i++) - { - if (block_used(used, i, wii_sec_per_wbfs_sect)) - { - tot++; - } - } - //memcpy(header, b,0x100); - - error: if (d) wd_close_disc(d); - - if (used) wbfs_free( used ); - - if (info) wbfs_iofree( info ); - - return tot * (((p->wbfs_sec_sz * 1.0) / p->hd_sec_sz) * 512); -} -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) -{ - int i; - u32 tot = 0, last = 0; - u32 wii_sec_per_wbfs_sect = 1 << (p->wbfs_sec_sz_s - p->wii_sec_sz_s); - wiidisc_t *d = 0; - u8 *used = 0; - used = wbfs_malloc( p->n_wii_sec_per_disc ); - if (!used) - ERROR( "unable to alloc memory" ); - d = wd_open_disc(read_src_wii_disc, callback_data); - if (!d) - ERROR( "unable to open wii disc" ); - wd_build_disc_usage(d, sel, used); - wd_close_disc(d); - d = 0; - - // count total number to write for spinner - for (i = 0; i < p->n_wbfs_sec_per_disc; i++) - { - if (block_used(used, i, wii_sec_per_wbfs_sect)) - { - tot += wii_sec_per_wbfs_sect; - last = i * wii_sec_per_wbfs_sect; - } - } - - error: if (d) wd_close_disc(d); - if (used) wbfs_free( used ); - - *comp_size = tot; - *real_size = last; - - return 0; -} - -// offset is pointing 32bit words to address the whole dvd, although len is in bytes -//int wbfs_disc_read(wbfs_disc_t*d,u32 offset, u8 *data, u32 len) - -// offset points 32bit words, count counts bytes -//int (*read_wiidisc_callback_t)(void*fp,u32 offset,u32 count,void*iobuf); - -// connect wiidisc to wbfs_disc -int read_wiidisc_wbfsdisc(void*fp, u32 offset, u32 count, void*iobuf) -{ - return wbfs_disc_read((wbfs_disc_t*) fp, offset, count, iobuf); -} - -int wbfs_extract_file(wbfs_disc_t*d, char *path, void **data) -{ - wiidisc_t *wd = 0; - int ret = 0; - - wd = wd_open_disc(read_wiidisc_wbfsdisc, d); - if (!wd) - { - ERROR( "opening wbfs disc" ); - return -1; - } - wd->extracted_size = 0; - *data = wd_extract_file(wd, ONLY_GAME_PARTITION, path); - ret = wd->extracted_size; - if (!*data) - { - //ERROR("file not found"); - ret = -1; - } - wd_close_disc(wd); - error: return ret; -} - -int wbfs_get_fragments(wbfs_disc_t *d, _frag_append_t append_fragment, void *callback_data) -{ - if (!d) return -1; - wbfs_t *p = d->p; - int src_wbs_nlb = p->wbfs_sec_sz / p->hd_sec_sz; - int i, ret, last = 0; - for (i = 0; i < p->n_wbfs_sec_per_disc; i++) - { - u32 iwlba = wbfs_ntohs( d->header->wlba_table[i] ); - if (iwlba) - { - ret = append_fragment(callback_data, i * src_wbs_nlb, // offset - p->part_lba + iwlba * src_wbs_nlb, // sector - src_wbs_nlb); // count - if (ret) return ret; // error - last = i; - } - } - if (last < p->n_wbfs_sec_per_disc / 2) - { - last = p->n_wbfs_sec_per_disc / 2; - } - u32 size = last * src_wbs_nlb; - append_fragment(callback_data, size, 0, 0); // set size - return 0; -} - -// wrapper for reading .iso files using wbfs apis - -#include -#include - -// offset is pointing 32bit words to address the whole dvd, although len is in bytes -int wbfs_iso_file_read(wbfs_disc_t*d, u32 offset, u8 *data, u32 len) -{ - if (!d || d->p != &wbfs_iso_file) return -1; - int fd = (int) d->header; - off_t off = ((u64) offset) << 2; - off_t ret_off; - int ret; - ret_off = lseek(fd, off, SEEK_SET); - if (ret_off != off) return -1; - ret = read(fd, data, len); - if (ret != len) return -2; - return 0; -} - -u32 wbfs_disc_sector_used(wbfs_disc_t *d, u32 *num_blk) -{ - if (d->p == &wbfs_iso_file) - { - int fd = (int) d->header; - struct stat st; - if (fstat(fd, &st) == -1) return 0; - if (num_blk) - { - *num_blk = (st.st_size >> 9); // in 512 units - } - return st.st_blocks; // in 512 units (can be sparse) - } - u32 last_blk = 0; - u32 ret; - ret = wbfs_sector_used2(d->p, d->header, &last_blk); - if (num_blk) - { - *num_blk = last_blk + 1; - } - return ret; -} - diff --git a/source/libs/libwbfs/libwbfs.h b/source/libs/libwbfs/libwbfs.h deleted file mode 100644 index c115e5c0..00000000 --- a/source/libs/libwbfs/libwbfs.h +++ /dev/null @@ -1,235 +0,0 @@ -// Modified by oggzee - -#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 -extern "C" -{ -#endif /* __cplusplus */ - - enum - { - WBFS_DEVICE_USB = 1, /* USB device */ - WBFS_DEVICE_SDHC - /* SDHC device */ - }; - - typedef u32 be32_t; - typedef u16 be16_t; - - typedef struct wbfs_head - { - be32_t magic; - // parameters copied in the partition for easy dumping, and bug reports - be32_t n_hd_sec; // total number of hd_sec in this partition - u8 hd_sec_sz_s; // sector size in this partition - u8 wbfs_sec_sz_s; // size of a wbfs sec - u8 padding3[2]; - u8 disc_table[0]; // size depends on hd sector size - }__attribute( ( packed ) ) wbfs_head_t; - - typedef struct wbfs_disc_info - { - u8 disc_header_copy[0x100]; - be16_t wlba_table[0]; - } wbfs_disc_info_t; - - // WBFS first wbfs_sector structure: - // - // ----------- - // | wbfs_head | (hd_sec_sz) - // ----------- - // | | - // | disc_info | - // | | - // ----------- - // | | - // | disc_info | - // | | - // ----------- - // | | - // | ... | - // | | - // ----------- - // | | - // | disc_info | - // | | - // ----------- - // | | - // |freeblk_tbl| - // | | - // ----------- - // - - // 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)(s64 status, s64 total); - - typedef struct wbfs_s - { - 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 - u32 n_hd_sec; // the number of hd sector in the wbfs partition - - /* standard wii sector (0x8000 bytes) */ - u32 wii_sec_sz; - u8 wii_sec_sz_s; - u32 n_wii_sec; - u32 n_wii_sec_per_disc; - - /* The size of a wbfs sector */ - u32 wbfs_sec_sz; - u32 wbfs_sec_sz_s; - 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 - - u32 n_disc_open; - - } wbfs_t; - - typedef struct wbfs_disc_s - { - wbfs_t *p; - wbfs_disc_info_t *header; // pointer to wii header - int i; // disc index in the wbfs header (disc_table) - } wbfs_disc_t; - -#define WBFS_MAGIC (('W'<<24)|('B'<<16)|('F'<<8)|('S')) - - /*! @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* - */ - // offset is pointing 32bit words to address the whole dvd, although len is in bytes - 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. - */ - s32 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); - - // remove some sanity checks - void wbfs_set_force_mode(int force); - - float wbfs_estimate_disc(wbfs_t *p, read_wiidisc_callback_t read_src_wii_disc, void *callback_data, - partition_selector_t sel); - // compressed and real size - 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); - - 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); - - 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); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/source/libs/libwbfs/libwbfs_os.h b/source/libs/libwbfs/libwbfs_os.h deleted file mode 100644 index f0931e5e..00000000 --- a/source/libs/libwbfs/libwbfs_os.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef LIBWBFS_GLUE_H -#define LIBWBFS_GLUE_H - -#include - -#define debug_printf(fmt, ...); - -#include -#define wbfs_fatal(x) do { printf("\nwbfs panic: %s\n\n",x); return; } while(0) -#define wbfs_error(x) do { printf("\nwbfs error: %s\n\n",x); } while(0) - -#include -#include - -#define wbfs_malloc(x) malloc(x) -#define wbfs_free(x) free(x) -#define wbfs_ioalloc(x) memalign(32, ((x) + 31) & ~31) -#define wbfs_iofree(x) free(x) -#define wbfs_be16(x) (*((u16*)(x))) -#define wbfs_be32(x) (*((u32*)(x))) -#define wbfs_ntohl(x) (x) -#define wbfs_htonl(x) (x) -#define wbfs_ntohs(x) (x) -#define wbfs_htons(x) (x) - -#include - -#define wbfs_memcmp(x,y,z) memcmp(x,y,z) -#define wbfs_memcpy(x,y,z) memcpy(x,y,z) -#define wbfs_memset(x,y,z) memset(x,y,z) - -#endif diff --git a/source/libs/libwbfs/rijndael.c b/source/libs/libwbfs/rijndael.c deleted file mode 100644 index 473023d9..00000000 --- a/source/libs/libwbfs/rijndael.c +++ /dev/null @@ -1,432 +0,0 @@ -/* Rijndael Block Cipher - rijndael.c - - Written by Mike Scott 21st April 1999 - mike@compapp.dcu.ie - - Permission for free direct or derivative use is granted subject - to compliance with any conditions that the originators of the - algorithm place on its exploitation. - - */ - -#include -#include - -#define u8 unsigned char /* 8 bits */ -#define u32 unsigned long /* 32 bits */ -#define u64 unsigned long long - -/* rotates x one bit to the left */ - -#define ROTL(x) (((x)>>7)|((x)<<1)) - -/* Rotates 32-bit word left by 1, 2 or 3 byte */ - -#define ROTL8(x) (((x)<<8)|((x)>>24)) -#define ROTL16(x) (((x)<<16)|((x)>>16)) -#define ROTL24(x) (((x)<<24)|((x)>>8)) - -/* Fixed Data */ - -static u8 InCo[4] = { 0xB, 0xD, 0x9, 0xE }; /* Inverse Coefficients */ - -static u8 fbsub[256]; -static u8 rbsub[256]; -static u8 ptab[256], ltab[256]; -static u32 ftable[256]; -static u32 rtable[256]; -static u32 rco[30]; - -/* Parameter-dependent data */ - -int Nk, Nb, Nr; -u8 fi[24], ri[24]; -u32 fkey[120]; -u32 rkey[120]; - -static u32 pack(u8 *b) -{ /* pack bytes into a 32-bit Word */ - return ((u32 ) b[3] << 24) | ((u32 ) b[2] << 16) | ((u32 ) b[1] << 8) | (u32 ) b[0]; -} - -static void unpack(u32 a, u8 *b) -{ /* unpack bytes from a word */ - b[0] = (u8 ) a; - b[1] = (u8 ) (a >> 8); - b[2] = (u8 ) (a >> 16); - b[3] = (u8 ) (a >> 24); -} - -static u8 xtime(u8 a) -{ - u8 b; - if (a & 0x80) - b = 0x1B; - else b = 0; - a <<= 1; - a ^= b; - return a; -} - -static u8 bmul(u8 x, u8 y) -{ /* x.y= AntiLog(Log(x) + Log(y)) */ - if (x && y) - return ptab[(ltab[x] + ltab[y]) % 255]; - else return 0; -} - -static u32 SubByte(u32 a) -{ - u8 b[4]; - unpack(a, b); - b[0] = fbsub[b[0]]; - b[1] = fbsub[b[1]]; - b[2] = fbsub[b[2]]; - b[3] = fbsub[b[3]]; - return pack(b); -} - -static u8 product(u32 x, u32 y) -{ /* dot product of two 4-byte arrays */ - u8 xb[4], yb[4]; - unpack(x, xb); - unpack(y, yb); - return bmul(xb[0], yb[0]) ^ bmul(xb[1], yb[1]) ^ bmul(xb[2], yb[2]) ^ bmul(xb[3], yb[3]); -} - -static u32 InvMixCol(u32 x) -{ /* matrix Multiplication */ - u32 y, m; - u8 b[4]; - - m = pack(InCo); - b[3] = product(m, x); - m = ROTL24( m ); - b[2] = product(m, x); - m = ROTL24( m ); - b[1] = product(m, x); - m = ROTL24( m ); - b[0] = product(m, x); - y = pack(b); - return y; -} - -u8 ByteSub(u8 x) -{ - u8 y = ptab[255 - ltab[x]]; /* multiplicative inverse */ - x = y; - x = ROTL( x ); - y ^= x; - x = ROTL( x ); - y ^= x; - x = ROTL( x ); - y ^= x; - x = ROTL( x ); - y ^= x; - y ^= 0x63; - return y; -} - -void gentables(void) -{ /* generate tables */ - int i; - u8 y, b[4]; - - /* use 3 as primitive root to generate power and log tables */ - - ltab[0] = 0; - ptab[0] = 1; - ltab[1] = 0; - ptab[1] = 3; - ltab[3] = 1; - for (i = 2; i < 256; i++) - { - ptab[i] = ptab[i - 1] ^ xtime(ptab[i - 1]); - ltab[ptab[i]] = i; - } - - /* affine transformation:- each bit is xored with itself shifted one bit */ - - fbsub[0] = 0x63; - rbsub[0x63] = 0; - for (i = 1; i < 256; i++) - { - y = ByteSub((u8 ) i); - fbsub[i] = y; - rbsub[y] = i; - } - - for (i = 0, y = 1; i < 30; i++) - { - rco[i] = y; - y = xtime(y); - } - - /* calculate forward and reverse tables */ - for (i = 0; i < 256; i++) - { - y = fbsub[i]; - b[3] = y ^ xtime(y); - b[2] = y; - b[1] = y; - b[0] = xtime(y); - ftable[i] = pack(b); - - y = rbsub[i]; - b[3] = bmul(InCo[0], y); - b[2] = bmul(InCo[1], y); - b[1] = bmul(InCo[2], y); - b[0] = bmul(InCo[3], y); - rtable[i] = pack(b); - } -} - -void gkey(int nb, int nk, char *key) -{ /* blocksize=32*nb bits. Key=32*nk bits */ - /* currently nb,bk = 4, 6 or 8 */ - /* key comes as 4*Nk bytes */ - /* Key Scheduler. Create expanded encryption key */ - int i, j, k, m, N; - int C1, C2, C3; - u32 CipherKey[8]; - - Nb = nb; - Nk = nk; - - /* Nr is number of rounds */ - if (Nb >= Nk) - Nr = 6 + Nb; - else Nr = 6 + Nk; - - C1 = 1; - if (Nb < 8) - { - C2 = 2; - C3 = 3; - } - else - { - C2 = 3; - C3 = 4; - } - - /* pre-calculate forward and reverse increments */ - for (m = j = 0; j < nb; j++, m += 3) - { - fi[m] = (j + C1) % nb; - fi[m + 1] = (j + C2) % nb; - fi[m + 2] = (j + C3) % nb; - ri[m] = (nb + j - C1) % nb; - ri[m + 1] = (nb + j - C2) % nb; - ri[m + 2] = (nb + j - C3) % nb; - } - - N = Nb * (Nr + 1); - - for (i = j = 0; i < Nk; i++, j += 4) - { - CipherKey[i] = pack((u8 *) &key[j]); - } - for (i = 0; i < Nk; i++) - fkey[i] = CipherKey[i]; - for (j = Nk, k = 0; j < N; j += Nk, k++) - { - fkey[j] = fkey[j - Nk] ^ SubByte(ROTL24( fkey[j-1] )) ^ rco[k]; - if (Nk <= 6) - { - for (i = 1; i < Nk && (i + j) < N; i++) - fkey[i + j] = fkey[i + j - Nk] ^ fkey[i + j - 1]; - } - else - { - for (i = 1; i < 4 && (i + j) < N; i++) - fkey[i + j] = fkey[i + j - Nk] ^ fkey[i + j - 1]; - if ((j + 4) < N) fkey[j + 4] = fkey[j + 4 - Nk] ^ SubByte(fkey[j + 3]); - for (i = 5; i < Nk && (i + j) < N; i++) - fkey[i + j] = fkey[i + j - Nk] ^ fkey[i + j - 1]; - } - - } - - /* now for the expanded decrypt key in reverse order */ - - for (j = 0; j < Nb; j++) - rkey[j + N - Nb] = fkey[j]; - for (i = Nb; i < N - Nb; i += Nb) - { - k = N - Nb - i; - for (j = 0; j < Nb; j++) - rkey[k + j] = InvMixCol(fkey[i + j]); - } - for (j = N - Nb; j < N; j++) - rkey[j - N + Nb] = fkey[j]; -} - -/* There is an obvious time/space trade-off possible here. * - * Instead of just one ftable[], I could have 4, the other * - * 3 pre-rotated to save the ROTL8, ROTL16 and ROTL24 overhead */ - -void encrypt(char *buff) -{ - int i, j, k, m; - u32 a[8], b[8], *x, *y, *t; - - for (i = j = 0; i < Nb; i++, j += 4) - { - a[i] = pack((u8 *) &buff[j]); - a[i] ^= fkey[i]; - } - k = Nb; - x = a; - y = b; - - /* State alternates between a and b */ - for (i = 1; i < Nr; i++) - { /* Nr is number of rounds. May be odd. */ - - /* if Nb is fixed - unroll this next - loop and hard-code in the values of fi[] */ - - for (m = j = 0; j < Nb; j++, m += 3) - { /* deal with each 32-bit element of the State */ - /* This is the time-critical bit */ - y[j] = fkey[k++] ^ ftable[(u8 ) x[j]] ^ ROTL8( ftable[( u8 )( x[fi[m]] >> 8 )] ) - ^ ROTL16( ftable[( u8 )( x[fi[m+1]] >> 16 )] ) ^ ROTL24( ftable[x[fi[m+2]] >> 24] ); - } - t = x; - x = y; - y = t; /* swap pointers */ - } - - /* Last Round - unroll if possible */ - for (m = j = 0; j < Nb; j++, m += 3) - { - y[j] = fkey[k++] ^ (u32 ) fbsub[(u8 ) x[j]] ^ ROTL8( ( u32 )fbsub[( u8 )( x[fi[m]] >> 8 )] ) - ^ ROTL16( ( u32 )fbsub[( u8 )( x[fi[m+1]] >> 16 )] ) ^ ROTL24( ( u32 )fbsub[x[fi[m+2]] >> 24] ); - } - for (i = j = 0; i < Nb; i++, j += 4) - { - unpack(y[i], (u8 *) &buff[j]); - x[i] = y[i] = 0; /* clean up stack */ - } - return; -} - -void decrypt(char *buff) -{ - int i, j, k, m; - u32 a[8], b[8], *x, *y, *t; - - for (i = j = 0; i < Nb; i++, j += 4) - { - a[i] = pack((u8 *) &buff[j]); - a[i] ^= rkey[i]; - } - k = Nb; - x = a; - y = b; - - /* State alternates between a and b */ - for (i = 1; i < Nr; i++) - { /* Nr is number of rounds. May be odd. */ - - /* if Nb is fixed - unroll this next - loop and hard-code in the values of ri[] */ - - for (m = j = 0; j < Nb; j++, m += 3) - { /* This is the time-critical bit */ - y[j] = rkey[k++] ^ rtable[(u8 ) x[j]] ^ ROTL8( rtable[( u8 )( x[ri[m]] >> 8 )] ) - ^ ROTL16( rtable[( u8 )( x[ri[m+1]] >> 16 )] ) ^ ROTL24( rtable[x[ri[m+2]] >> 24] ); - } - t = x; - x = y; - y = t; /* swap pointers */ - } - - /* Last Round - unroll if possible */ - for (m = j = 0; j < Nb; j++, m += 3) - { - y[j] = rkey[k++] ^ (u32 ) rbsub[(u8 ) x[j]] ^ ROTL8( ( u32 )rbsub[( u8 )( x[ri[m]] >> 8 )] ) - ^ ROTL16( ( u32 )rbsub[( u8 )( x[ri[m+1]] >> 16 )] ) ^ ROTL24( ( u32 )rbsub[x[ri[m+2]] >> 24] ); - } - for (i = j = 0; i < Nb; i++, j += 4) - { - unpack(y[i], (u8 *) &buff[j]); - x[i] = y[i] = 0; /* clean up stack */ - } - return; -} - -void aes_set_key(u8 *key) -{ - gentables(); - gkey(4, 4, (char*) key); -} - -// CBC mode decryption -void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len) -{ - u8 block[16]; - unsigned int blockno = 0, i; - - //printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len); - - for (blockno = 0; blockno <= (len / sizeof(block)); blockno++) - { - unsigned int fraction; - if (blockno == (len / sizeof(block))) // last block - { - fraction = len % sizeof(block); - if (fraction == 0) break; - memset(block, 0, sizeof(block)); - } - else fraction = 16; - - // debug_printf("block %d: fraction = %d\n", blockno, fraction); - memcpy(block, inbuf + blockno * sizeof(block), fraction); - decrypt((char*) block); - u8 *ctext_ptr; - if (blockno == 0) - ctext_ptr = iv; - else ctext_ptr = inbuf + (blockno - 1) * sizeof(block); - - for (i = 0; i < fraction; i++) - outbuf[blockno * sizeof(block) + i] = ctext_ptr[i] ^ block[i]; - // debug_printf("Block %d output: ", blockno); - // hexdump(outbuf + blockno*sizeof(block), 16); - } -} - -// CBC mode encryption -void aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len) -{ - u8 block[16]; - unsigned int blockno = 0, i; - - // debug_printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len); - - for (blockno = 0; blockno <= (len / sizeof(block)); blockno++) - { - unsigned int fraction; - if (blockno == (len / sizeof(block))) // last block - { - fraction = len % sizeof(block); - if (fraction == 0) break; - memset(block, 0, sizeof(block)); - } - else fraction = 16; - - // debug_printf("block %d: fraction = %d\n", blockno, fraction); - memcpy(block, inbuf + blockno * sizeof(block), fraction); - - for (i = 0; i < fraction; i++) - block[i] = inbuf[blockno * sizeof(block) + i] ^ iv[i]; - - encrypt((char*) block); - memcpy(iv, block, sizeof(block)); - memcpy(outbuf + blockno * sizeof(block), block, sizeof(block)); - // debug_printf("Block %d output: ", blockno); - // hexdump(outbuf + blockno*sizeof(block), 16); - } -} - diff --git a/source/libs/libwbfs/wiidisc.c b/source/libs/libwbfs/wiidisc.c deleted file mode 100644 index 3c40eae6..00000000 --- a/source/libs/libwbfs/wiidisc.c +++ /dev/null @@ -1,377 +0,0 @@ -// Copyright 2009 Kwiirk based on negentig.c: -// Copyright 2007,2008 Segher Boessenkool -// Licensed under the terms of the GNU GPL, version 2 -// http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt - -#include "wiidisc.h" - -void aes_set_key(u8 *key); -void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len); -static u8 get_fst = 0; - -static void _decrypt_title_key(u8 *tik, u8 *title_key) -{ - u8 common_key[16] = { 0xeb, 0xe4, 0x2a, 0x22, 0x5e, 0x85, 0x93, 0xe4, 0x48, 0xd9, 0xc5, 0x45, 0x73, 0x81, 0xaa, - 0xf7 }; - ; - u8 iv[16]; - - wbfs_memset( iv, 0, sizeof iv ); - wbfs_memcpy( iv, tik + 0x01dc, 8 ); - aes_set_key(common_key); - //_aes_cbc_dec(common_key, iv, tik + 0x01bf, 16, title_key); - aes_decrypt(iv, tik + 0x01bf, title_key, 16); -} -static u32 _be32(const u8 *p) -{ - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; -} - -static void disc_read(wiidisc_t *d, u32 offset, u8 *data, u32 len) -{ - if (data) - { - int ret = 0; - if (len == 0) return; - ret = d->read(d->fp, offset, len, data); - if (ret) - wbfs_fatal( "error reading disc" ); - } - if (d->sector_usage_table) - { - u32 blockno = offset >> 13; - do - { - d->sector_usage_table[blockno] = 1; - blockno += 1; - if (len > 0x8000) len -= 0x8000; - } while (len > 0x8000); - } -} - -static void partition_raw_read(wiidisc_t *d, u32 offset, u8 *data, u32 len) -{ - disc_read(d, d->partition_raw_offset + offset, data, len); -} - -static void partition_read_block(wiidisc_t *d, u32 blockno, u8 *block) -{ - u8*raw = d->tmp_buffer; - u8 iv[16]; - u32 offset; - if (d->sector_usage_table) d->sector_usage_table[d->partition_block + blockno] = 1; - offset = d->partition_data_offset + ((0x8000 >> 2) * blockno); - partition_raw_read(d, offset, raw, 0x8000); - - // decrypt data - memcpy(iv, raw + 0x3d0, 16); - aes_set_key(d->disc_key); - aes_decrypt(iv, raw + 0x400, block, 0x7c00); -} - -static void partition_read(wiidisc_t *d, u32 offset, u8 *data, u32 len, int fake) -{ - u8 *block = d->tmp_buffer2; - u32 offset_in_block; - u32 len_in_block; - if (fake && d->sector_usage_table == 0) return; - - while (len) - { - offset_in_block = offset % (0x7c00 >> 2); - len_in_block = 0x7c00 - (offset_in_block << 2); - if (len_in_block > len) len_in_block = len; - if (!fake) - { - partition_read_block(d, offset / (0x7c00 >> 2), block); - wbfs_memcpy( data, block + ( offset_in_block << 2 ), len_in_block ); - } - else d->sector_usage_table[d->partition_block + (offset / (0x7c00 >> 2))] = 1; - data += len_in_block; - offset += len_in_block >> 2; - len -= len_in_block; - } -} - -static u32 do_fst(wiidisc_t *d, u8 *fst, const char *names, u32 i) -{ - u32 offset; - u32 size; - const char *name; - u32 j; - - name = names + (_be32(fst + 12 * i) & 0x00ffffff); - size = _be32(fst + 12 * i + 8); - - if (i == 0) - { - for (j = 1; j < size && !d->extracted_buffer;) - { - j = do_fst(d, fst, names, j); - } - return size; - } - //printf("name %s\n",name); - - if (fst[12 * i]) - { - - for (j = i + 1; j < size && !d->extracted_buffer;) - j = do_fst(d, fst, names, j); - - return size; - } - else - { - offset = _be32(fst + 12 * i + 4); - if (d->extract_pathname && strcasecmp(name, d->extract_pathname) == 0) - { - d->extracted_buffer = wbfs_ioalloc( size ); - d->extracted_size = size; - partition_read(d, offset, d->extracted_buffer, size, 0); - } - else partition_read(d, offset, 0, size, 1); - return i + 1; - } -} - -static void do_files(wiidisc_t*d) -{ - u8 *b = wbfs_ioalloc( 0x480 ); // XXX: determine actual header size - u32 dol_offset; - u32 fst_offset; - u32 fst_size; - u32 apl_offset; - u32 apl_size; - u8 *apl_header = wbfs_ioalloc( 0x20 ); - u8 *fst; - u32 n_files; - partition_read(d, 0, b, 0x480, 0); - - dol_offset = _be32(b + 0x0420); - fst_offset = _be32(b + 0x0424); - fst_size = _be32(b + 0x0428) << 2; - - apl_offset = 0x2440 >> 2; - partition_read(d, apl_offset, apl_header, 0x20, 0); - apl_size = 0x20 + _be32(apl_header + 0x14) + _be32(apl_header + 0x18); - // fake read dol and partition - if (apl_size) partition_read(d, apl_offset, 0, apl_size, 1); - partition_read(d, dol_offset, 0, (fst_offset - dol_offset) << 2, 1); - - if (fst_size) - { - fst = wbfs_ioalloc( fst_size ); - if (fst == 0) - wbfs_fatal( "malloc fst" ); - partition_read(d, fst_offset, fst, fst_size, 0); - n_files = _be32(fst + 8); - - if(get_fst && !d->extracted_buffer) - { - d->extracted_buffer = malloc(fst_size); - memcpy(d->extracted_buffer, fst, fst_size); - } - - if (d->extract_pathname && *d->extract_pathname == 0) - { - // if empty pathname requested return fst - d->extracted_buffer = fst; - d->extracted_size = fst_size; - d->extract_pathname = NULL; - // skip do_fst if only fst requested - n_files = 0; - } - - if (12 * n_files <= fst_size) - { - if (n_files > 1) do_fst(d, fst, (char *) fst + 12 * n_files, 0); - } - - if (fst != d->extracted_buffer) wbfs_iofree( fst ); - } - wbfs_iofree( b ); - wbfs_iofree( apl_header ); -} - -static void do_partition(wiidisc_t*d) -{ - u8 *tik = wbfs_ioalloc( 0x2a4 ); - u8 *b = wbfs_ioalloc( 0x1c ); - u64 tmd_offset; - u32 tmd_size; - u8 *tmd; - u64 cert_offset; - u32 cert_size; - u8 *cert; - u64 h3_offset; - - // read ticket, and read some offsets and sizes - partition_raw_read(d, 0, tik, 0x2a4); - partition_raw_read(d, 0x2a4 >> 2, b, 0x1c); - - tmd_size = _be32(b); - tmd_offset = _be32(b + 4); - cert_size = _be32(b + 8); - cert_offset = _be32(b + 0x0c); - h3_offset = _be32(b + 0x10); - d->partition_data_offset = _be32(b + 0x14); - d->partition_block = (d->partition_raw_offset + d->partition_data_offset) >> 13; - tmd = wbfs_ioalloc( tmd_size ); - if (tmd == 0) - wbfs_fatal( "malloc tmd" ); - partition_raw_read(d, tmd_offset, tmd, tmd_size); - - cert = wbfs_ioalloc( cert_size ); - if (cert == 0) - wbfs_fatal( "malloc cert" ); - partition_raw_read(d, cert_offset, cert, cert_size); - - _decrypt_title_key(tik, d->disc_key); - - partition_raw_read(d, h3_offset, 0, 0x18000); - wbfs_iofree( b ); - wbfs_iofree( tik ); - wbfs_iofree( cert ); - wbfs_iofree( tmd ); - - do_files(d); - -} -static int test_parition_skip(u32 partition_type, partition_selector_t part_sel) -{ - switch (part_sel) - { - case ALL_PARTITIONS: - return 0; - case REMOVE_UPDATE_PARTITION: - return (partition_type == 1); - case ONLY_GAME_PARTITION: - return (partition_type != 0); - default: - return (partition_type != part_sel); - } -} -static void do_disc(wiidisc_t*d) -{ - u8 *b = wbfs_ioalloc( 0x100 ); - u64 partition_offset[32]; // XXX: don't know the real maximum - u64 partition_type[32]; // XXX: don't know the real maximum - u32 n_partitions; - u32 magic; - u32 i; - disc_read(d, 0, b, 0x100); - magic = _be32(b + 24); - if (magic != 0x5D1C9EA3) - { - wbfs_error( "not a wii disc" ); - return; - } - disc_read(d, 0x40000 >> 2, b, 0x100); - n_partitions = _be32(b); - disc_read(d, _be32(b + 4), b, 0x100); - for (i = 0; i < n_partitions; i++) - { - partition_offset[i] = _be32(b + 8 * i); - partition_type[i] = _be32(b + 8 * i + 4); - } - for (i = 0; i < n_partitions; i++) - { - d->partition_raw_offset = partition_offset[i]; - if (!test_parition_skip(partition_type[i], d->part_sel)) do_partition(d); - } - wbfs_iofree( b ); -} - -wiidisc_t *wd_open_disc(read_wiidisc_callback_t read, void*fp) -{ - wiidisc_t *d = wbfs_malloc( sizeof( wiidisc_t ) ); - if (!d) return 0; - wbfs_memset( d, 0, sizeof( wiidisc_t ) ); - d->read = read; - d->fp = fp; - d->part_sel = ALL_PARTITIONS; - d->tmp_buffer = wbfs_ioalloc( 0x8000 ); - d->tmp_buffer2 = wbfs_malloc( 0x8000 ); - - return d; -} -void wd_close_disc(wiidisc_t *d) -{ - wbfs_iofree( d->tmp_buffer ); - wbfs_free( d->tmp_buffer2 ); - wbfs_free( d ); -} -// returns a buffer allocated with wbfs_ioalloc() or NULL if not found of alloc error -// XXX pathname not implemented. files are extracted by their name. -// first file found with that name is returned. -u8 * wd_extract_file(wiidisc_t *d, partition_selector_t partition_type, char *pathname) -{ - u8 *retval = 0; - d->extract_pathname = pathname; - d->extracted_buffer = 0; - d->part_sel = partition_type; - do_disc(d); - d->extract_pathname = 0; - d->part_sel = ALL_PARTITIONS; - retval = d->extracted_buffer; - d->extracted_buffer = 0; - return retval; -} - -u8 * wd_get_fst(wiidisc_t *d, partition_selector_t partition_type) -{ - get_fst = 1; - u8 *retval = 0; - d->extract_pathname = 0; - d->extracted_buffer = 0; - d->part_sel = partition_type; - do_disc(d); - d->extract_pathname = 0; - d->part_sel = ALL_PARTITIONS; - retval = d->extracted_buffer; - d->extracted_buffer = 0; - get_fst = 0; - return retval; -} - -void wd_build_disc_usage(wiidisc_t *d, partition_selector_t selector, u8* usage_table) -{ - d->sector_usage_table = usage_table; - wbfs_memset( usage_table, 0, 143432*2 ); - d->part_sel = selector; - do_disc(d); - d->part_sel = ALL_PARTITIONS; - d->sector_usage_table = 0; -} - -void wd_fix_partition_table(wiidisc_t *d, partition_selector_t selector, u8* partition_table) -{ - u8 *b = partition_table; - u32 partition_offset; - u32 partition_type; - u32 n_partitions, i, j; - u32 *b32; - if (selector == ALL_PARTITIONS) return; - n_partitions = _be32(b); - if (_be32(b + 4) - (0x40000 >> 2) > 0x50) - wbfs_fatal( "cannot modify this partition table. Please report the bug." ); - - b += (_be32(b + 4) - (0x40000 >> 2)) * 4; - j = 0; - for (i = 0; i < n_partitions; i++) - { - partition_offset = _be32(b + 8 * i); - partition_type = _be32(b + 8 * i + 4); - if (!test_parition_skip(partition_type, selector)) - { - b32 = (u32*) (b + 8 * j); - b32[0] = wbfs_htonl( partition_offset ); - b32[1] = wbfs_htonl( partition_type ); - j++; - } - } - b32 = (u32*) (partition_table); - *b32 = wbfs_htonl( j ); -} - diff --git a/source/libs/libwbfs/wiidisc.h b/source/libs/libwbfs/wiidisc.h deleted file mode 100644 index c2bb0636..00000000 --- a/source/libs/libwbfs/wiidisc.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef WIIDISC_H -#define WIIDISC_H -#include -#include "libwbfs_os.h" // this file is provided by the project wanting to compile libwbfs and wiidisc -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ -#if 0 //removes extra automatic indentation by editors -} -#endif - // callback definition. Return 1 on fatal error (callback is supposed to make retries until no hopes..) - // offset points 32bit words, count counts bytes - typedef int (*read_wiidisc_callback_t)(void*fp, u32 offset, u32 count, void*iobuf); - - typedef enum - { - UPDATE_PARTITION_TYPE = 0, GAME_PARTITION_TYPE, OTHER_PARTITION_TYPE, - // value in between selects partition types of that value - ALL_PARTITIONS = 0xffffffff - 3, - REMOVE_UPDATE_PARTITION, // keeps game + channel installers - ONLY_GAME_PARTITION, - } partition_selector_t; - - typedef struct wiidisc_s - { - read_wiidisc_callback_t read; - void *fp; - u8 *sector_usage_table; - - // everything points 32bit words. - u32 disc_raw_offset; - u32 partition_raw_offset; - u32 partition_data_offset; - u32 partition_data_size; - u32 partition_block; - - u8 *tmp_buffer; - u8 *tmp_buffer2; - u8 disc_key[16]; - int dont_decrypt; - - partition_selector_t part_sel; - - char *extract_pathname; - u8 *extracted_buffer; - int extracted_size; - } wiidisc_t; - - wiidisc_t *wd_open_disc(read_wiidisc_callback_t read, void*fp); - void wd_close_disc(wiidisc_t *); - // returns a buffer allocated with wbfs_ioalloc() or NULL if not found of alloc error - u8 * wd_extract_file(wiidisc_t *d, partition_selector_t partition_type, char *pathname); - - void wd_build_disc_usage(wiidisc_t *d, partition_selector_t selector, u8* usage_table); - - // effectively remove not copied partition from the partition table. - void wd_fix_partition_table(wiidisc_t *d, partition_selector_t selector, u8* partition_table); - u8 * wd_get_fst(wiidisc_t *d, partition_selector_t partition_type); - -#if 0 -{ -#endif -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/source/libwiigui/LoadCoverImage.cpp b/source/libwiigui/LoadCoverImage.cpp deleted file mode 100644 index 0d3dde0b..00000000 --- a/source/libwiigui/LoadCoverImage.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "libwiigui/gui.h" -#include "usbloader/disc.h" -#include "FileOperations/fileops.h" -#include "settings/CSettings.h" -#include "themes/CTheme.h" - -/**************************************************************************** - * LoadCoverImage - ***************************************************************************/ -GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D, bool noCover) -{ - if (!header) return NULL; - GuiImageData *Cover = NULL; - char ID3[4]; - char IDfull[7]; - char Path[255]; - bool flag = Prefere3D; - - snprintf(ID3, sizeof(ID3), "%s", (char *) header->id); - snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id); - - for (int i = 0; i < 2; ++i) - { - char *coverPath = flag ? Settings.covers_path : Settings.covers2d_path; - flag = !flag; - //Load full id image - snprintf(Path, sizeof(Path), "%s%s.png", coverPath, IDfull); - - if(!CheckFile(Path)) - { - snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3); - if(!CheckFile(Path)) - continue; - } - - delete Cover; - Cover = new (std::nothrow) GuiImageData(Path); - //Load short id image - if (!Cover || !Cover->GetImage()) - { - snprintf(Path, sizeof(Path), "%s%s.png", coverPath, ID3); - delete Cover; - Cover = new (std::nothrow) GuiImageData(Path); - } - if (Cover && Cover->GetImage()) break; - } - //Load no image - if (noCover && (!Cover || !Cover->GetImage())) - { - flag = Prefere3D; - for (int i = 0; i < 2; ++i) - { - flag = !flag; - delete Cover; - Cover = Resources::GetImageData(flag ? "nocover.png" : "nocoverFlat.png"); - if (Cover && Cover->GetImage()) break; - } - } - if (Cover && !Cover->GetImage()) - { - delete Cover; - Cover = NULL; - } - return Cover; -} diff --git a/source/libwiigui/LoadCoverImage.h b/source/libwiigui/LoadCoverImage.h deleted file mode 100644 index dae4283c..00000000 --- a/source/libwiigui/LoadCoverImage.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef LOADCOVERIMAGE_H_ -#define LOADCOVERIMAGE_H_ - -GuiImageData *LoadCoverImage(struct discHdr *header, bool Prefere3D = true, bool noCover = true); - -#endif diff --git a/source/libwiigui/OptionList.cpp b/source/libwiigui/OptionList.cpp deleted file mode 100644 index 0afaece1..00000000 --- a/source/libwiigui/OptionList.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include "OptionList.hpp" - -OptionList::OptionList() -{ -} - -OptionList::~OptionList() -{ - ClearList(); -} - -void OptionList::SetName(int i, const char *format, ...) -{ - if(i < (int) name.size()) - name[i].clear(); - - if(!format) - return; - - char *tmp=0; - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va)>=0) && tmp) - { - if(i >= (int) name.size()) - { - Resize(i+1); - } - - name[i].assign(tmp); - - listChanged = true; - } - va_end(va); - - if(tmp) - free(tmp); -} - -void OptionList::SetValue(int i, const char *format, ...) -{ - if(i < (int) value.size()) - value[i].clear(); - - char *tmp=0; - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va)>=0) && tmp) - { - if(i >= (int) value.size()) - { - Resize(i+1); - } - - value[i].assign(tmp); - - listChanged = true; - } - va_end(va); - - if(tmp) - free(tmp); -} - -const char * OptionList::GetName(int i) -{ - if(i < 0 || i >= (int) name.size()) - return NULL; - - return name.at(i).c_str(); -} - -const char * OptionList::GetValue(int i) -{ - if(i < 0 || i >= (int) value.size()) - return NULL; - - return value.at(i).c_str(); -} - -void OptionList::Resize(int size) -{ - name.resize(size); - value.resize(size); - listChanged = true; -} - -void OptionList::RemoveOption(int i) -{ - if(i < 0 || i >= (int) name.size()) - return; - - name.erase(name.begin()+i); - value.erase(value.begin()+i); - listChanged = true; -} - -void OptionList::ClearList() -{ - name.clear(); - value.clear(); - std::vector().swap(name); - std::vector().swap(value); - listChanged = true; -} diff --git a/source/libwiigui/OptionList.hpp b/source/libwiigui/OptionList.hpp deleted file mode 100644 index 7e47fda7..00000000 --- a/source/libwiigui/OptionList.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef OPTIONLIST_HPP_ -#define OPTIONLIST_HPP_ - -#include -#include - -class OptionList -{ - public: - OptionList(); - ~OptionList(); - void SetName(int i, const char *format, ...) __attribute__((format (printf, 3, 4))); - void SetValue(int i, const char *format, ...) __attribute__((format (printf, 3, 4))); - const char * GetName(int i); - const char * GetValue(int i); - void Resize(int size); - int GetLength() { return name.size(); } - bool IsChanged() { bool ret = listChanged; listChanged = false; return ret;} - void RemoveOption(int i); - void ClearList(); - private: - std::vector name; - std::vector value; - bool listChanged; -}; - -#endif - diff --git a/source/libwiigui/Text.cpp b/source/libwiigui/Text.cpp deleted file mode 100644 index 04c9bab5..00000000 --- a/source/libwiigui/Text.cpp +++ /dev/null @@ -1,327 +0,0 @@ -#include "Text.hpp" - -Text::Text(const char * t, int s, GXColor c) : - GuiText(t, s, c) -{ - maxWidth = 400; - linestodraw = 9; - curLineStart = 0; - FirstLineOffset = 0; - wText = NULL; - - if (!text) return; - - wText = new (std::nothrow) wString(text); - if (!wText) - { - return; - } - - if (wText->size() == 0) - { - wText->push_back(L' '); - wText->push_back(0); - } - - textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize); - delete[] text; - text = NULL; - - SetMaxWidth(maxWidth); -} - -Text::Text(const wchar_t * t, int s, GXColor c) : - GuiText((wchar_t *) NULL, s, c) -{ - maxWidth = 400; - linestodraw = 9; - curLineStart = 0; - FirstLineOffset = 0; - wText = NULL; - - if (!t) return; - - wText = new (std::nothrow) wString(t); - if (!wText) - { - return; - } - - if (wText->size() == 0) - { - wText->push_back(L' '); - wText->push_back(0); - } - - textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize); - - SetMaxWidth(maxWidth); -} - -Text::~Text() -{ - if (wText) delete wText; - wText = NULL; - - TextLines.clear(); - ClearDynamicText(); -} - -void Text::SetText(const char * t) -{ - wchar_t * tmp = charToWideChar(t); - if (!tmp) return; - - if (wText) delete wText; - - wText = new (std::nothrow) wString(tmp); - if (!wText) - { - return; - } - - if (wText->size() == 0) - { - wText->push_back(L' '); - wText->push_back(0); - } - - textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize); - - delete[] tmp; - - ClearDynamicText(); - CalcLineOffsets(); -} - -void Text::SetText(const wchar_t * t) -{ - if (!t) return; - - if (wText) delete wText; - - wText = new wString(t); - textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize); - CalcLineOffsets(); -} - -void Text::SetMaxWidth(int w) -{ - maxWidth = w; - curLineStart = 0; - Refresh(); -} - -void Text::SetTextLine(int line) -{ - if (line < 0) - line = 0; - else if (line > (int) TextLines.size() - 1) line = TextLines.size() - 1; - - curLineStart = line; - - FillRows(); - - while ((int) textDyn.size() < linestodraw && curLineStart > 0) - { - PreviousLine(); - } -} - -void Text::SetTextPos(int pos) -{ - if (!wText) return; - - int diff = 10000; - - for (u32 i = 0; i < TextLines.size(); i++) - { - int curDiff = abs(TextLines[i].LineOffset - pos); - if (curDiff < diff) - { - diff = curDiff; - curLineStart = i; - } - } - - FillRows(); - - while ((int) textDyn.size() < linestodraw && curLineStart > 0) - { - PreviousLine(); - } -} - -const wchar_t * Text::GetText() -{ - return wText->c_str(); -} - -std::string Text::GetUTF8String(void) const -{ - return wText->toUTF8(); -} - -int Text::GetLineOffset(int ind) -{ - if (TextLines.size() == 0) return 0; - - if (ind < 0) return TextLines[0].LineOffset; - - if (ind >= (int) TextLines.size() - 1) return TextLines[TextLines.size() - 1].LineOffset; - - return TextLines[ind].LineOffset; -} - -const wchar_t * Text::GetTextLine(int ind) -{ - if (filling || textDyn.size() == 0) return NULL; - - if (ind < 0) return textDyn[0]; - - if (ind >= (int) textDyn.size()) return textDyn[textDyn.size() - 1]; - - return textDyn[ind]; -} - -void Text::Refresh() -{ - CalcLineOffsets(); - FillRows(); -} - -void Text::NextLine() -{ - if (!wText || (curLineStart + 1 > ((int) TextLines.size() - linestodraw))) return; - - ++curLineStart; - - FillRows(); -} - -void Text::PreviousLine() -{ - if (!wText || curLineStart - 1 < 0) return; - - --curLineStart; - - FillRows(); -} - -void Text::FillRows() -{ - if (!wText) return; - - filling = true; - - ClearDynamicText(); - - for (int i = 0; i < linestodraw && i < (int) TextLines.size(); i++) - { - if (i >= (int) textDyn.size()) - { - textDyn.resize(i + 1); - textDyn[i] = new wchar_t[maxWidth]; - } - int offset = TextLines[curLineStart + i].LineOffset; - int count = TextLines[curLineStart + i].CharCount + 1; - - for (int n = 0; n < count && offset + n < (int) wText->size(); n++) - textDyn[i][n] = wText->at(offset + n); - - textDyn[i][count] = 0; - } - - filling = false; - - return; -} - -void Text::CalcLineOffsets() -{ - if (!wText) return; - - TextLines.clear(); - - TextLine TmpLine; - TmpLine.CharCount = 0; - TmpLine.LineOffset = 0; - TmpLine.width = 0; - - const wchar_t * origTxt = wText->c_str(); - int ch = 0; - int lastSpace = -1; - int lastSpaceIndex = -1; - int currWidth = 0; - int i = 0; - - while (origTxt[ch]) - { - currWidth += fontSystem->getCharWidth(origTxt[ch], currentSize, ch > 0 ? origTxt[ch - 1] : 0x0000); - - if (currWidth >= maxWidth) - { - if (lastSpace > 0) - { - ch = lastSpace; - } - TmpLine.CharCount = ch - TmpLine.LineOffset; - TmpLine.width = currWidth; - TextLines.push_back(TmpLine); - currWidth = 0; - lastSpace = -1; - i = -1; - TmpLine.LineOffset = ch + 1; - } - else if (origTxt[ch] == '\n') - { - TmpLine.CharCount = ch - TmpLine.LineOffset; - TmpLine.width = currWidth; - TextLines.push_back(TmpLine); - currWidth = 0; - lastSpace = -1; - i = -1; - TmpLine.LineOffset = ch + 1; - } - else if (origTxt[ch] == ' ') - { - lastSpace = ch; - lastSpaceIndex = i; - } - - ch++; - i++; - } - - TmpLine.CharCount = ch - TmpLine.LineOffset; - TmpLine.width = currWidth; - - if (TmpLine.CharCount > 0) TextLines.push_back(TmpLine); -} - -void Text::Draw() -{ - if (textDyn.size() == 0) return; - - if (!this->IsVisible()) return; - - GXColor c = color; - c.a = this->GetAlpha(); - - int newSize = size * GetScale(); - - if (newSize != currentSize) - { - currentSize = newSize; - - if (wText) textWidth = (font ? font : fontSystem)->getWidth(wText->data(), currentSize); - } - - u16 lineheight = newSize + 6; - - for (u32 i = 0; i < textDyn.size(); i++) - { - if (!filling) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + i * lineheight, 0, - textDyn[i], currentSize, c, style, 0, maxWidth); - } -} diff --git a/source/libwiigui/Text.hpp b/source/libwiigui/Text.hpp deleted file mode 100644 index 6c171d82..00000000 --- a/source/libwiigui/Text.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _TEXT_HPP_ -#define _TEXT_HPP_ - -#include "libwiigui/gui.h" -#include "wstring.hpp" - -typedef struct -{ - int LineOffset; - int CharCount; - int width; -} TextLine; - -class Text: public GuiText -{ - public: - //!Constructor - //!\param t Text - //!\param s Font size - //!\param c Font color - Text(const char * t, int s, GXColor c); - Text(const wchar_t * t, int s, GXColor c); - ~Text(); - //!Sets the text of the GuiText element - //!\param t Text - void SetText(const char * t); - void SetText(const wchar_t * t); - //!Set the max texwidth - void SetMaxWidth(int width); - //!Go to next line - void NextLine(); - //!Go to previous line - void PreviousLine(); - //!Refresh the rows to draw - void Refresh(); - //!Set the text line - void SetTextLine(int line); - //!Set to the char pos in text - void SetTextPos(int pos); - //!Refresh the rows to draw - int GetCurrPos() { return curLineStart; }; - //!Get the count of loaded lines - int GetLinesCount() { return textDyn.size(); }; - //!Get the total count of lines - int GetTotalLinesCount() { return TextLines.size(); }; - //!Get the original full Text - const wchar_t * GetText(); - //!Get the original full Text as wString - wString * GetwString() { return wText; }; - //!Get the original Text as a UTF-8 text - std::string GetUTF8String() const; - //!Get a Textline - const wchar_t * GetTextLine(int ind); - //!Get the offset in the text of a drawn Line - int GetLineOffset(int ind); - //!Constantly called to draw the text - void Draw(); - protected: - void CalcLineOffsets(); - void FillRows(); - - wString * wText; - std::vector TextLines; - int curLineStart; - int FirstLineOffset; - bool filling; -}; - -#endif diff --git a/source/libwiigui/gui.h b/source/libwiigui/gui.h deleted file mode 100644 index a7ab4ec2..00000000 --- a/source/libwiigui/gui.h +++ /dev/null @@ -1,1091 +0,0 @@ -/*!\mainpage libwiigui Documentation - * - * \section Introduction - * libwiigui is a GUI library for the Wii, created to help structure the - * design of a complicated GUI interface, and to enable an author to create - * a sophisticated, feature-rich GUI. It was originally conceived and written - * after I started to design a GUI for Snes9x GX, and found libwiisprite and - * GRRLIB inadequate for the purpose. It uses GX for drawing, and makes use - * of PNGU for displaying images and FreeTypeGX for text. It was designed to - * be flexible and is easy to modify - don't be afraid to change the way it - * works or expand it to suit your GUI's purposes! If you do, and you think - * your changes might benefit others, please share them so they might be - * added to the project! - * - * \section Quickstart - * Start from the supplied template example. For more advanced uses, see the - * source code for Snes9x GX, FCE Ultra GX, and Visual Boy Advance GX. - - * \section Contact - * If you have any suggestions for the library or documentation, or want to - * contribute, please visit the libwiigui website: - - * http://code.google.com/p/libwiigui/ - * \section Credits - * This library was wholly designed and written by Tantric. Thanks to the - * authors of PNGU and FreeTypeGX, of which this library makes use. Thanks - * also to the authors of GRRLIB and libwiisprite for laying the foundations. - * - */ - -#ifndef LIBWIIGUI_H -#define LIBWIIGUI_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "gui_imagedata.h" -#include "FreeTypeGX.h" -#include "video.h" -#include "filelist.h" -#include "input.h" -#include "OptionList.hpp" -#include "SoundOperations/gui_sound.h" -#include "SoundOperations/gui_bgm.h" - -//! Frequently used variables -extern FreeTypeGX *fontSystem; -extern GuiSound *btnSoundClick; -extern GuiSound *btnSoundClick2; -extern GuiSound *btnSoundOver; -extern GuiBGM *bgMusic; - -#define SCROLL_INITIAL_DELAY 20 -#define SCROLL_LOOP_DELAY 3 -#define PAGESIZE 9 -#define FILEBROWSERSIZE 8 -#define MAX_OPTIONS 170 - -typedef void (*UpdateCallback)(void * e); - -enum -{ - ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE, ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE -}; -#define ALIGN_CENTER ALIGN_CENTRE -enum -{ - STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_HELD, STATE_DISABLED -}; - -enum -{ - IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA, IMAGE_COPY -}; - -enum -{ - TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS -}; - -enum -{ - WRAP, DOTTED, SCROLL_HORIZONTAL, SCROLL_NONE -}; - -typedef struct _paddata -{ - u16 btns_d; - u16 btns_u; - u16 btns_h; - s8 stickX; - s8 stickY; - s8 substickX; - s8 substickY; - u8 triggerL; - u8 triggerR; -} PADData; - -#define EFFECT_SLIDE_TOP 1 -#define EFFECT_SLIDE_BOTTOM 2 -#define EFFECT_SLIDE_RIGHT 4 -#define EFFECT_SLIDE_LEFT 8 -#define EFFECT_SLIDE_IN 16 -#define EFFECT_SLIDE_OUT 32 -#define EFFECT_FADE 64 -#define EFFECT_SCALE 128 -#define EFFECT_COLOR_TRANSITION 256 -#define EFFECT_PULSE 512 -#define EFFECT_ROCK_VERTICLE 1024 -#define EFFECT_GOROUND 2048 - -//!Menu input trigger management. Determine if action is neccessary based on input data by comparing controller input data to a specific trigger element. -class GuiTrigger -{ - public: - //!Constructor - GuiTrigger(); - //!Destructor - ~GuiTrigger(); - //!Sets a simple trigger. Requires: element is selected, and trigger button is pressed - //!\param ch Controller channel number - //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately - //!\param gcbtns GameCube controller trigger button(s) - void SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns); - //!Sets a held trigger. Requires: element is selected, and trigger button is pressed - //!\param ch Controller channel number - //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately - //!\param gcbtns GameCube controller trigger button(s) - void SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns); - //!Sets a button-only trigger. Requires: Trigger button is pressed - //!\param ch Controller channel number - //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately - //!\param gcbtns GameCube controller trigger button(s) - void SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns); - //!Sets a button-only trigger. Requires: trigger button is pressed and parent window of element is in focus - //!\param ch Controller channel number - //!\param wiibtns Wii controller trigger button(s) - classic controller buttons are considered separately - //!\param gcbtns GameCube controller trigger button(s) - void SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns); - //!Get X/Y value from Wii Joystick (classic, nunchuk) input - //!\param right Controller stick (left = 0, right = 1) - //!\param axis Controller stick axis (x-axis = 0, y-axis = 1) - //!\return Stick value - s8 WPAD_Stick(u8 right, int axis); - //!Move menu selection left (via pad/joystick). Allows scroll delay and button overriding - //!\return true if selection should be moved left, false otherwise - bool Left(); - //!Move menu selection right (via pad/joystick). Allows scroll delay and button overriding - //!\return true if selection should be moved right, false otherwise - bool Right(); - //!Move menu selection up (via pad/joystick). Allows scroll delay and button overriding - //!\return true if selection should be moved up, false otherwise - bool Up(); - //!Move menu selection down (via pad/joystick). Allows scroll delay and button overriding - //!\return true if selection should be moved down, false otherwise - bool Down(); - - u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS) - s32 chan; //!< Trigger controller channel (0-3, -1 for all) - WPADData wpad; //!< Wii controller trigger data - PADData pad; //!< GameCube controller trigger data -}; - -extern GuiTrigger userInput[4]; - -//!Primary GUI class. Most other classes inherit from this class. -class GuiElement -{ - public: - //!Constructor - GuiElement(); - //!Destructor - ~GuiElement(); - //!Set the element's parent - //!\param e Pointer to parent element - void SetParent(GuiElement * e); - //!Gets the element's parent - //!\return Pointer to parent element - GuiElement * GetParent(); - //!Gets the current leftmost coordinate of the element - //!Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values - //!\return left coordinate - int GetLeft(); - //!Gets the current topmost coordinate of the element - //!Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values - //!\return top coordinate - int GetTop(); - //!Sets the minimum y offset of the element - //!\param y Y offset - void SetMinY(int y); - //!Gets the minimum y offset of the element - //!\return Minimum Y offset - int GetMinY(); - //!Sets the maximum y offset of the element - //!\param y Y offset - void SetMaxY(int y); - //!Gets the maximum y offset of the element - //!\return Maximum Y offset - int GetMaxY(); - //!Sets the minimum x offset of the element - //!\param x X offset - void SetMinX(int x); - //!Gets the minimum x offset of the element - //!\return Minimum X offset - int GetMinX(); - //!Sets the maximum x offset of the element - //!\param x X offset - void SetMaxX(int x); - //!Gets the maximum x offset of the element - //!\return Maximum X offset - int GetMaxX(); - //!Gets the current width of the element. Does not currently consider the scale - //!\return width - int GetWidth(); - //!Gets the height of the element. Does not currently consider the scale - //!\return height - int GetHeight(); - //!Sets the size (width/height) of the element - //!\param w Width of element - //!\param h Height of element - void SetSize(int w, int h); - //!Checks whether or not the element is visible - //!\return true if visible, false otherwise - bool IsVisible(); - //!Checks whether or not the element is selectable - //!\return true if selectable, false otherwise - bool IsSelectable(); - //!Checks whether or not the element is clickable - //!\return true if clickable, false otherwise - bool IsClickable(); - //!Checks whether or not the element is holdable - //!\return true if holdable, false otherwise - bool IsHoldable(); - //!Sets whether or not the element is selectable - //!\param s Selectable - void SetSelectable(bool s); - //!Sets whether or not the element is clickable - //!\param c Clickable - void SetClickable(bool c); - //!Sets whether or not the element is holdable - //!\param c Holdable - void SetHoldable(bool d); - //!Gets the element's current state - //!\return state - int GetState(); - //!Gets the controller channel that last changed the element's state - //!\return Channel number (0-3, -1 = no channel) - int GetStateChan(); - //!Sets the element's alpha value - //!\param a alpha value - void SetAlpha(int a); - //!Gets the element's alpha value - //!Considers alpha, alphaDyn, and the parent element's GetAlpha() value - //!\return alpha - int GetAlpha(); - //!Gets the element's AngleDyn value - //!\return alpha - float GetAngleDyn(); - //!Sets the element's scale - //!\param s scale (1 is 100%) - void SetScale(float s); - //!Gets the element's current scale - //!Considers scale, scaleDyn, and the parent element's GetScale() value - virtual float GetScale(); - //!Set a new GuiTrigger for the element - //!\param t Pointer to GuiTrigger - void SetTrigger(GuiTrigger * t); - //!\overload - //!\param i Index of trigger array to set - //!\param t Pointer to GuiTrigger - void SetTrigger(u8 i, GuiTrigger * t); - //!Remove GuiTrigger for the element - //!\param i Index of trigger array to set - void RemoveTrigger(u8 i); - //!Checks whether rumble was requested by the element - //!\return true is rumble was requested, false otherwise - bool Rumble(); - //!Sets whether or not the element is requesting a rumble event - //!\param r true if requesting rumble, false if not - void SetRumble(bool r); - //!Set an effect for the element - //!\param e Effect to enable - //!\param a Amount of the effect (usage varies on effect) - //!\param t Target amount of the effect (usage varies on effect) - void SetEffect(int e, int a, int t = 0); - //!This SetEffect is for EFFECT_GOROUND only - //!\param e Effect to enable - //!\param speed is for Circlespeed - //!\param circles Circleamount in degree ike 180 for 1/2 circle or 720 for 2 circles - //!\param r Circle Radius in pixel - //!\param startdegree Degree where to start circling - //!\param anglespeedset Set the speed of Angle rotating make 1 for same speed as Circlespeed - //! or 0.5 for half the speed of the circlingspeed. Turn Anglecircling off by 0 to this param. - //!\param center_x x co-ordinate of the center of circle. - //!\param center_y y co-ordinate of the center of circle. - void SetEffect(int e, int speed, f32 circles, int r, f32 startdegree, f32 anglespeedset, int center_x, - int center_y); - //!Gets the frequency from the above effect - //!\return element frequency - float GetFrequency(); - //!Sets an effect to be enabled on wiimote cursor over - //!\param e Effect to enable - //!\param a Amount of the effect (usage varies on effect) - //!\param t Target amount of the effect (usage varies on effect) - void SetEffectOnOver(int e, int a, int t = 0); - //!Shortcut to SetEffectOnOver(EFFECT_SCALE, 4, 110) - void SetEffectGrow(); - //!Stops the current element effect - void StopEffect(); - //!Gets the current element effects - //!\return element effects - int GetEffect(); - //!Gets the current element on over effects - //!\return element on over effects - int GetEffectOnOver(); - //!Checks whether the specified coordinates are within the element's boundaries - //!\param x X coordinate - //!\param y Y coordinate - //!\return true if contained within, false otherwise - bool IsInside(int x, int y); - //!Sets the element's position - //!\param x X coordinate - //!\param y Y coordinate - void SetPosition(int x, int y, int z = 0); - //!Updates the element's effects (dynamic values) - //!Called by Draw(), used for animation purposes - void UpdateEffects(); - //!Sets a function to called after after Update() - //!Callback function can be used to response to changes in the state of the element, and/or update the element's attributes - void SetUpdateCallback(UpdateCallback u); - //!Checks whether the element is in focus - //!\return true if element is in focus, false otherwise - int IsFocused(); - //!Sets the element's visibility - //!\param v Visibility (true = visible) - virtual void SetVisible(bool v); - //!Sets the element's focus - //!\param f Focus (true = in focus) - virtual void SetFocus(int f); - //!Sets the element's state - //!\param s State (STATE_DEFAULT, STATE_SELECTED, STATE_CLICKED, STATE_DISABLED) - //!\param c Controller channel (0-3, -1 = none) - virtual void SetState(int s, int c = -1); - //!Resets the element's state to STATE_DEFAULT - virtual void ResetState(); - //!Gets whether or not the element is in STATE_SELECTED - //!\return true if selected, false otherwise - virtual int GetSelected(); - //!Sets the element's alignment respective to its parent element - //!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE) - //!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) - virtual void SetAlignment(int hor, int vert); - //!Called constantly to allow the element to respond to the current input data - //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD - virtual void Update(GuiTrigger * t); - //!Called constantly to redraw the element - virtual void Draw(); - virtual void DrawTooltip(); - protected: - void Lock(); - void Unlock(); - // static mutex_t mutex; - static mutex_t _lock_mutex; - lwp_t _lock_thread; - u16 _lock_count; - lwpq_t _lock_queue; - friend class SimpleLock; - - //int position2; //! B Scrollbariable - bool visible; //!< Visibility of the element. If false, Draw() is skipped - int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused) - int dontsetfocus; //! _elements; //!< Contains all elements within the GuiWindow -}; - -//!Display, manage, and manipulate images in the GUI -class GuiImage: public GuiElement -{ - public: - //!Constructor - GuiImage(); - //!\overload - //!\param img Pointer to GuiImageData element - GuiImage(GuiImageData * img); - //!\overload - //!Sets up a new image from the image data specified - //!\param img - //!\param w Image width - //!\param h Image height - GuiImage(u8 * img, int w, int h); - //!\overload - //!Creates an image filled with the specified color - //!\param w Image width - //!\param h Image height - //!\param c Image color - GuiImage(int w, int h, GXColor c); - //! Copy Constructor - GuiImage(GuiImage &srcimage); - GuiImage(GuiImage *srcimage); - //! = operator for copying images - GuiImage &operator=(GuiImage &srcimage); - //!Destructor - ~GuiImage(); - //!Sets the image rotation angle for drawing - //!\param a Angle (in degrees) - void SetAngle(float a); - //!Gets the image rotation angle for drawing - float GetAngle(); - //!Sets the number of times to draw the image horizontally - //!\param t Number of times to draw the image - void SetTile(int t); - // true set horizontal scale to 0.8 //added - void SetWidescreen(bool w); - //!Constantly called to draw the image - void Draw(); - //!Gets the image data - //!\return pointer to image data - u8 * GetImage(); - //!Sets up a new image using the GuiImageData object specified - //!\param img Pointer to GuiImageData object - void SetImage(GuiImageData * img); - //!\overload - //!\param img Pointer to image data - //!\param w Width - //!\param h Height - void SetImage(u8 * img, int w, int h); - //!Gets the pixel color at the specified coordinates of the image - //!\param x X coordinate - //!\param y Y coordinate - GXColor GetPixel(int x, int y); - //!Sets the pixel color at the specified coordinates of the image - //!\param x X coordinate - //!\param y Y coordinate - //!\param color Pixel color - void SetPixel(int x, int y, GXColor color); - //!Sets the image to grayscale - void SetGrayscale(void); - //!Set/disable the use of parentelement angle (default true) - void SetParentAngle(bool a); - //!Directly modifies the image data to create a color-striped effect - //!Alters the RGB values by the specified amount - //!\param s Amount to increment/decrement the RGB values in the image - void ColorStripe(int s); - //!Sets a stripe effect on the image, overlaying alpha blended rectangles - //!Does not alter the image data - //!\param s Alpha amount to draw over the image - void SetStripe(int s); - s32 z; - void SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4); - void SetSkew(int *skew /* int skew[8] */); - int xx1; - int yy1; - int xx2; - int yy2; - int xx3; - int yy3; - int xx4; - int yy4; - int rxx1; - int ryy1; - int rxx2; - int ryy2; - int rxx3; - int ryy3; - int rxx4; - int ryy4; - protected: - int imgType; //!< Type of image data (IMAGE_TEXTURE, IMAGE_COLOR, IMAGE_DATA) - u8 * image; //!< Poiner to image data. May be shared with GuiImageData data - f32 imageangle; //!< Angle to draw the image - int tile; //!< Number of times to draw (tile) the image horizontally - int stripe; //!< Alpha value (0-255) to apply a stripe effect to the texture - short widescreen; //added - bool parentangle; -}; -//!Display, manage, and manipulate text in the GUI -class GuiText: public GuiElement -{ - public: - //!Constructor - //!\param t Text - //!\param s Font size - //!\param c Font color - GuiText(const char * t, int s, GXColor c); - //!\overload - //!\param t Text - //!\param s Font size - //!\param c Font color - GuiText(const wchar_t * t, int s, GXColor c); - //!\overload - //!\Assumes SetPresets() has been called to setup preferred text attributes - //!\param t Text - GuiText(const char * t); - //!Destructor - ~GuiText(); - //!Sets the text of the GuiText element - //!\param t Text - virtual void SetText(const char * t); - virtual void SetText(const wchar_t * t); - virtual void SetTextf(const char *format, ...) __attribute__( ( format( printf, 2, 3 ) ) ); - //!Sets up preset values to be used by GuiText(t) - //!Useful when printing multiple text elements, all with the same attributes set - //!\param sz Font size - //!\param c Font color - //!\param w Maximum width of texture image (for text wrapping) - //!\param wrap Wrapmode when w>0 - //!\param s Font style - //!\param h Text alignment (horizontal) - //!\param v Text alignment (vertical) - static void SetPresets(int sz, GXColor c, int w, u16 s, int h, int v); - //!Sets the font size - //!\param s Font size - void SetFontSize(int s); - //!Sets the maximum width of the drawn texture image - //!If the text exceeds this, it is wrapped to the next line - //!\param w Maximum width - //!\param m WrapMode - void SetMaxWidth(int w = 0, int m = WRAP); - //!Sets the font color - //!\param c Font color - void SetColor(GXColor c); - //!Sets the FreeTypeGX style attributes - //!\param s Style attributes - //!\param m Style-Mask attributes - void SetStyle(u16 s); - //!Sets the text alignment - //!\param hor Horizontal alignment (ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE) - //!\param vert Vertical alignment (ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE) - void SetAlignment(int hor, int vert); - //!Set PassChar - void SetPassChar(wchar_t p); - //!Sets the font - //!\param f Font - void SetFont(FreeTypeGX *f); - //!Get the original text as char - virtual const wchar_t * GetText(); - //!Get the Horizontal Size of Text - int GetTextWidth(); - int GetTextWidth(int ind); - //!Get the max textwidth - int GetTextMaxWidth(); - //!Gets the total line number - virtual int GetLinesCount() - { - return 1; - } - ; - //!Get fontsize - int GetFontSize() - { - return size; - } - ; - //!Set max lines to draw - void SetLinesToDraw(int l); - void SetWidescreen(bool b) - { - widescreen = b; - } - ; - //!Get current Textline (for position calculation) - const wchar_t * GetDynText(int ind = 0); - virtual const wchar_t * GetTextLine(int ind) - { - return GetDynText(ind); - } - ; - //!Change the font - //!\param font bufferblock - //!\param font filesize - bool SetFont(const u8 *font, const u32 filesize); - //!Constantly called to draw the text - void Draw(); - protected: - //!Clear the dynamic text - void ClearDynamicText(); - //!Create a dynamic dotted text if the text is too long - void MakeDottedText(); - //!Scroll the text once - void ScrollText(); - //!Wrap the text to several lines - void WrapText(); - - wchar_t *text; - std::vector textDyn; - int wrapMode; //!< Wrapping toggle - int textScrollPos; //!< Current starting index of text string for scrolling - int textScrollInitialDelay; //!< Delay to wait before starting to scroll - int textScrollDelay; //!< Scrolling speed - int size; //!< Font size - int maxWidth; //!< Maximum width of the generated text object (for text wrapping) - u16 style; //!< FreeTypeGX style attributes - GXColor color; //!< Font color - FreeTypeGX *font; - int textWidth; - int currentSize; - int linestodraw; - wchar_t passChar; - bool widescreen; -}; - -//!Display, manage, and manipulate tooltips in the GUI. -class GuiTooltip: public GuiElement -{ - public: - //!Constructor - //!\param t Text - GuiTooltip(const char *t, int Alpha = 255); - - //!Destructor - ~ GuiTooltip(); - - //!Gets the element's current scale - //!Considers scale, scaleDyn, and the parent element's GetScale() value - float GetScale(); - //!Sets the text of the GuiTooltip element - //!\param t Text - void SetText(const char * t); - void SetWidescreen(bool w); // timely a dummy - //!Constantly called to draw the GuiButton - void Draw(); - - protected: - GuiImage leftImage; //!< Tooltip left-image - GuiImage tileImage; //!< Tooltip tile-image - GuiImage rightImage; //!< Tooltip right-image - GuiText *text; -}; - -//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) -class GuiButton: public GuiElement -{ - public: - //!Constructor - //!\param w Width - //!\param h Height - GuiButton(int w, int h); - //!\param img is the button GuiImage. it uses the height & width of this image for the button - //!\param imgOver is the button's over GuiImage - //!\param hor is horizontal alingment of the button - //!\param vert is verticle alignment of the button - //!\param x is xposition of the button - //!\param y is yposition of the button - //!\param trig is a GuiTrigger to assign to this button - //!\param sndOver is a GuiSound used for soundOnOver for this button - //!\param sndClick is a GuiSound used for clickSound of this button - //!\param grow sets effect grow for this button. 1 for yes ;0 for no - GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig, - GuiSound* sndOver, GuiSound* sndClick, u8 grow); - //!\param same as all the parameters for the above button plus the following - //!\param tt is a GuiTooltip assigned to this button - //!\param ttx and tty are the xPOS and yPOS for this tooltip in relationship to the button - //!\param h_align and v_align are horizontal and verticle alignment for the tooltip in relationship to the button - GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig, - GuiSound* sndOver, GuiSound* sndClick, u8 grow, GuiTooltip* tt, int ttx, int tty, int h_align, - int v_align); - //!Destructor - ~GuiButton(); - //!Sets the button's image - //!\param i Pointer to GuiImage object - void SetImage(GuiImage* i); - //!Sets the button's image on over - //!\param i Pointer to GuiImage object - void SetImageOver(GuiImage* i); - //!Sets the button's image on hold - //!\param i Pointer to GuiImage object - void SetAngle(float a); - void SetImageHold(GuiImage* i); - //!Sets the button's image on click - //!\param i Pointer to GuiImage object - void SetImageClick(GuiImage* i); - //!Sets the button's icon - //!\param i Pointer to GuiImage object - void SetIcon(GuiImage* i); - //!Sets the button's icon on over - //!\param i Pointer to GuiImage object - void SetIconOver(GuiImage* i); - //!Sets the button's icon on hold - //!\param i Pointer to GuiImage object - void SetIconHold(GuiImage* i); - //!Sets the button's icon on click - //!\param i Pointer to GuiImage object - void SetIconClick(GuiImage* i); - //!Sets the button's label - //!\param t Pointer to GuiText object - //!\param n Index of label to set (optional, default is 0) - void SetLabel(GuiText* t, int n = 0); - //!Sets the button's label on over (eg: different colored text) - //!\param t Pointer to GuiText object - //!\param n Index of label to set (optional, default is 0) - void SetLabelOver(GuiText* t, int n = 0); - //!Sets the button's label on hold - //!\param t Pointer to GuiText object - //!\param n Index of label to set (optional, default is 0) - void SetLabelHold(GuiText* t, int n = 0); - //!Sets the button's label on click - //!\param t Pointer to GuiText object - //!\param n Index of label to set (optional, default is 0) - void SetLabelClick(GuiText* t, int n = 0); - //!Sets the sound to play on over - //!\param s Pointer to GuiSound object - void SetSoundOver(GuiSound * s); - //!Sets the sound to play on hold - //!\param s Pointer to GuiSound object - void SetSoundHold(GuiSound * s); - //!Sets the sound to play on click - //!\param s Pointer to GuiSound object - void SetSoundClick(GuiSound * s); - //!\param reset the soundover to NULL - void RemoveSoundOver(); - //!\param reset the soundclick to NULL - void RemoveSoundClick(); - //!Constantly called to draw the GuiButtons ToolTip - //!Sets the button's Tooltip on over - //!\param tt Pointer to GuiElement object, x & y Positioning, h & v Align - void SetToolTip(GuiTooltip* tt, int x, int y, int h = ALIGN_RIGHT, int v = ALIGN_TOP); - - void RemoveToolTip(); - //!Constantly called to draw the GuiButton - void Draw(); - void DrawTooltip(); - //!Constantly called to allow the GuiButton to respond to updated input data - //!\param t Pointer to a GuiTrigger, containing the current input data from PAD/WPAD - void Update(GuiTrigger * t); - //!Deactivate/Activate pointing on Games while B scrolling - void ScrollIsOn(int f); - void SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4); - void SetSkew(int *skew /* int skew[8] */); - protected: - GuiImage * image; //!< Button image (default) - GuiImage * imageOver; //!< Button image for STATE_SELECTED - GuiImage * imageHold; //!< Button image for STATE_HELD - GuiImage * imageClick; //!< Button image for STATE_CLICKED - GuiImage * icon; //!< Button icon (drawn after button image) - GuiImage * iconOver; //!< Button icon for STATE_SELECTED - GuiImage * iconHold; //!< Button icon for STATE_HELD - GuiImage * iconClick; //!< Button icon for STATE_CLICKED - GuiTooltip *toolTip; - time_t time1, time2;//!< Tooltip timeconstants - GuiText * label[3]; //!< Label(s) to display (default) - GuiText * labelOver[3]; //!< Label(s) to display for STATE_SELECTED - GuiText * labelHold[3]; //!< Label(s) to display for STATE_HELD - GuiText * labelClick[3]; //!< Label(s) to display for STATE_CLICKED - GuiSound * soundOver; //!< Sound to play for STATE_SELECTED - GuiSound * soundHold; //!< Sound to play for STATE_HELD - GuiSound * soundClick; //!< Sound to play for STATE_CLICKED -}; - -typedef struct _keytype -{ - char ch, chShift, chalt, chalt2; -} Key; - -//!On-screen keyboard -class GuiKeyboard: public GuiWindow -{ - public: - GuiKeyboard(char * t, u32 m, int min, int lang); - ~GuiKeyboard(); - void Update(GuiTrigger * t); - char kbtextstr[256]; - protected: - u32 kbtextmaxlen; - Key keys[4][11]; - int shift; - int caps; - int alt; - int alt2; - GuiText * kbText; - GuiImage * keyTextboxImg; - GuiText * keyCapsText; - GuiImage * keyCapsImg; - GuiImage * keyCapsOverImg; - GuiButton * keyCaps; - GuiText * keyAltText; - GuiImage * keyAltImg; - GuiImage * keyAltOverImg; - GuiButton * keyAlt; - GuiText * keyAlt2Text; - GuiImage * keyAlt2Img; - GuiImage * keyAlt2OverImg; - GuiButton * keyAlt2; - GuiText * keyShiftText; - GuiImage * keyShiftImg; - GuiImage * keyShiftOverImg; - GuiButton * keyShift; - GuiText * keyBackText; - GuiImage * keyBackImg; - GuiImage * keyBackOverImg; - GuiButton * keyBack; - GuiText * keyClearText; - GuiImage * keyClearImg; - GuiImage * keyClearOverImg; - GuiButton * keyClear; - GuiImage * keySpaceImg; - GuiImage * keySpaceOverImg; - GuiButton * keySpace; - GuiButton * keyBtn[4][11]; - GuiImage * keyImg[4][11]; - GuiImage * keyImgOver[4][11]; - GuiText * keyTxt[4][11]; - GuiImageData * keyTextbox; - GuiImageData * key; - GuiImageData * keyOver; - GuiImageData * keyMedium; - GuiImageData * keyMediumOver; - GuiImageData * keyLarge; - GuiImageData * keyLargeOver; - GuiTrigger * trigA; - GuiTrigger * trigB; -}; - -//!On-screen keyboard -class GuiNumpad: public GuiWindow -{ - public: - GuiNumpad(char * t, u32 max); - ~GuiNumpad(); - void Update(GuiTrigger * t); - char kbtextstr[256]; - protected: - u32 kbtextmaxlen; - char keys[11]; - GuiText * kbText; - GuiImage * keyTextboxImg; - - GuiText * keyBackText; - GuiImage * keyBackImg; - GuiImage * keyBackOverImg; - GuiButton * keyBack; - GuiText * keyClearText; - GuiImage * keyClearImg; - GuiImage * keyClearOverImg; - GuiButton * keyClear; - GuiButton * keyBtn[11]; - GuiImage * keyImg[11]; - GuiImage * keyImgOver[11]; - GuiText * keyTxt[11]; - GuiImageData * keyTextbox; - GuiImageData * keyMedium; - GuiImageData * keyMediumOver; - GuiTrigger * trigA; - GuiTrigger * trigB; -}; - -//!Display a list of menu options -class GuiOptionBrowser: public GuiElement -{ - public: - GuiOptionBrowser(int w, int h, OptionList * l, const char *imagebg, int scrollbar); - GuiOptionBrowser(int w, int h, OptionList * l, const char *imagebg, int scrollbar, int start); - ~GuiOptionBrowser(); - void SetCol2Position(int x); - int FindMenuItem(int c, int d); - int GetClickedOption(); - int GetSelectedOption(); - void ResetState(); - void SetFocus(int f); - void Draw(); - void TriggerUpdate(); - void Update(GuiTrigger * t); - GuiText * optionVal[PAGESIZE]; - protected: - int selectedItem; - int listOffset; - bool listChanged; - OptionList * options; - int optionIndex[PAGESIZE]; - GuiButton * optionBtn[PAGESIZE]; - GuiText * optionTxt[PAGESIZE]; - GuiImage * optionBg[PAGESIZE]; - - GuiButton * arrowUpBtn; - GuiButton * arrowDownBtn; - GuiButton * scrollbarBoxBtn; - - GuiImage * bgOptionsImg; - GuiImage * bgOptionsOverImg; - GuiImage * scrollbarImg; - GuiImage * arrowDownImg; - GuiImage * arrowDownOverImg; - GuiImage * arrowUpImg; - GuiImage * arrowUpOverImg; - GuiImage * scrollbarBoxImg; - GuiImage * scrollbarBoxOverImg; - - GuiImageData * bgOptions; - GuiImageData * bgOptionsOver; - GuiImageData * bgOptionsEntry; - GuiImageData * scrollbar; - GuiImageData * arrowDown; - GuiImageData * arrowDownOver; - GuiImageData * arrowUp; - GuiImageData * arrowUpOver; - GuiImageData * scrollbarBox; - GuiImageData * scrollbarBoxOver; - - GuiTrigger * trigA; - GuiTrigger * trigB; - GuiTrigger * trigHeldA; -}; - -//!Display a list of files -class GuiFileBrowser: public GuiElement -{ - public: - GuiFileBrowser(int w, int h); - ~GuiFileBrowser(); - void DisableTriggerUpdate(bool set); - void ResetState(); - void SetFocus(int f); - void Draw(); - void TriggerUpdate(); - void Update(GuiTrigger * t); - GuiButton * fileList[PAGESIZE]; - protected: - int selectedItem; - bool listChanged; - bool triggerdisabled; - - GuiText * fileListText[PAGESIZE]; - GuiText * fileListTextOver[PAGESIZE]; - GuiImage * fileListBg[PAGESIZE]; - //GuiImage * fileListArchives[PAGESIZE]; - //GuiImage * fileListDefault[PAGESIZE]; - GuiImage * fileListFolder[PAGESIZE]; - //GuiImage * fileListGFX[PAGESIZE]; - //GuiImage * fileListPLS[PAGESIZE]; - //GuiImage * fileListSFX[PAGESIZE]; - //GuiImage * fileListTXT[PAGESIZE]; - //GuiImage * fileListXML[PAGESIZE]; - - GuiButton * arrowUpBtn; - GuiButton * arrowDownBtn; - GuiButton * scrollbarBoxBtn; - - GuiImage * bgFileSelectionImg; - GuiImage * scrollbarImg; - GuiImage * arrowDownImg; - GuiImage * arrowUpImg; - GuiImage * scrollbarBoxImg; - - GuiImageData * bgFileSelection; - GuiImageData * bgFileSelectionEntry; - //GuiImageData * fileArchives; - //GuiImageData * fileDefault; - GuiImageData * fileFolder; - //GuiImageData * fileGFX; - //GuiImageData * filePLS; - //GuiImageData * fileSFX; - //GuiImageData * fileTXT; - //GuiImageData * fileXML; - GuiImageData * scrollbar; - GuiImageData * arrowDown; - GuiImageData * arrowUp; - GuiImageData * scrollbarBox; - - GuiTrigger * trigA; - GuiTrigger * trigHeldA; -}; - -#endif diff --git a/source/libwiigui/gui_button.cpp b/source/libwiigui/gui_button.cpp deleted file mode 100644 index 2d4ade53..00000000 --- a/source/libwiigui/gui_button.cpp +++ /dev/null @@ -1,511 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_button.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" - -static int scrollison; - -/** - * Constructor for the GuiButton class. - */ - -GuiButton::GuiButton(int w, int h) -{ - width = w; - height = h; - image = NULL; - imageOver = NULL; - imageHold = NULL; - imageClick = NULL; - icon = NULL; - iconOver = NULL; - iconHold = NULL; - iconClick = NULL; - toolTip = NULL; - - for (int i = 0; i < 3; i++) - { - label[i] = NULL; - labelOver[i] = NULL; - labelHold[i] = NULL; - labelClick[i] = NULL; - } - - soundOver = NULL; - soundHold = NULL; - soundClick = NULL; - selectable = true; - holdable = false; - clickable = true; - - time1 = time2 = 0; -} - -GuiButton::GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig, - GuiSound* sndOver, GuiSound* sndClick, u8 grow) -{ - width = img ? img->GetWidth() : 0; - height = img ? img->GetHeight() : 0; - image = img; - if(image) image->SetParent(this); - imageOver = imgOver; - if (imageOver) imageOver->SetParent(this); - imageHold = NULL; - imageClick = NULL; - icon = NULL; - iconOver = NULL; - iconHold = NULL; - iconClick = NULL; - toolTip = NULL; - alignmentHor = hor; - alignmentVert = vert; - xoffset = x; - yoffset = y; - trigger[0] = trig; - - for (int i = 0; i < 3; i++) - { - label[i] = NULL; - labelOver[i] = NULL; - labelHold[i] = NULL; - labelClick[i] = NULL; - } - - soundOver = sndOver; - soundHold = NULL; - soundClick = sndClick; - selectable = true; - holdable = false; - clickable = true; - - if (grow == 1) - { - effectsOver |= EFFECT_SCALE; - effectAmountOver = 4; - effectTargetOver = 110; - } - time1 = time2 = 0; -} - -GuiButton::GuiButton(GuiImage* img, GuiImage* imgOver, int hor, int vert, int x, int y, GuiTrigger* trig, - GuiSound* sndOver, GuiSound* sndClick, u8 grow, GuiTooltip* tt, int ttx, int tty, int h_align, int v_align) -{ - width = img ? img->GetWidth() : 0; - height = img ? img->GetHeight() : 0; - image = img; - if(image) image->SetParent(this); - imageOver = imgOver; - if (imageOver) imageOver->SetParent(this); - imageHold = NULL; - imageClick = NULL; - icon = NULL; - iconOver = NULL; - iconHold = NULL; - iconClick = NULL; - toolTip = NULL; - alignmentHor = hor; - alignmentVert = vert; - xoffset = x; - yoffset = y; - trigger[0] = trig; - - for (int i = 0; i < 3; i++) - { - label[i] = NULL; - labelOver[i] = NULL; - labelHold[i] = NULL; - labelClick[i] = NULL; - } - - soundOver = sndOver; - soundHold = NULL; - soundClick = sndClick; - selectable = true; - holdable = false; - clickable = true; - - if (grow == 1) - { - effectsOver |= EFFECT_SCALE; - effectAmountOver = 4; - effectTargetOver = 110; - } - - toolTip = tt; - if(toolTip) - { - toolTip->SetParent(this); - toolTip->SetAlignment(h_align, v_align); - toolTip->SetPosition(ttx, tty); - } - - time1 = time2 = 0; -} - -/** - * Destructor for the GuiButton class. - */ -GuiButton::~GuiButton() -{ -} - -void GuiButton::SetImage(GuiImage* img) -{ - LOCK( this ); - image = img; - if (img) img->SetParent(this); -} -void GuiButton::SetImageOver(GuiImage* img) -{ - LOCK( this ); - imageOver = img; - if (img) img->SetParent(this); -} -void GuiButton::SetImageHold(GuiImage* img) -{ - LOCK( this ); - imageHold = img; - if (img) img->SetParent(this); -} -void GuiButton::SetImageClick(GuiImage* img) -{ - LOCK( this ); - imageClick = img; - if (img) img->SetParent(this); -} -void GuiButton::SetIcon(GuiImage* img) -{ - LOCK( this ); - icon = img; - if (img) img->SetParent(this); -} -void GuiButton::SetIconOver(GuiImage* img) -{ - LOCK( this ); - iconOver = img; - if (img) img->SetParent(this); -} -void GuiButton::SetIconHold(GuiImage* img) -{ - LOCK( this ); - iconHold = img; - if (img) img->SetParent(this); -} -void GuiButton::SetIconClick(GuiImage* img) -{ - LOCK( this ); - iconClick = img; - if (img) img->SetParent(this); -} -void GuiButton::SetLabel(GuiText* txt, int n) -{ - LOCK( this ); - label[n] = txt; - if (txt) txt->SetParent(this); -} -void GuiButton::SetLabelOver(GuiText* txt, int n) -{ - LOCK( this ); - labelOver[n] = txt; - if (txt) txt->SetParent(this); -} -void GuiButton::SetLabelHold(GuiText* txt, int n) -{ - LOCK( this ); - labelHold[n] = txt; - if (txt) txt->SetParent(this); -} -void GuiButton::SetLabelClick(GuiText* txt, int n) -{ - LOCK( this ); - labelClick[n] = txt; - if (txt) txt->SetParent(this); -} -void GuiButton::SetSoundOver(GuiSound * snd) -{ - LOCK( this ); - soundOver = snd; -} -void GuiButton::SetSoundHold(GuiSound * snd) -{ - LOCK( this ); - soundHold = snd; -} -void GuiButton::SetSoundClick(GuiSound * snd) -{ - LOCK( this ); - soundClick = snd; -} - -void GuiButton::SetToolTip(GuiTooltip* tt, int x, int y, int h_align, int v_align) -{ - LOCK( this ); - if (tt) - { - toolTip = tt; - toolTip->SetParent(this); - toolTip->SetAlignment(h_align, v_align); - toolTip->SetPosition(x, y); - - } -} - -void GuiButton::RemoveToolTip() -{ - LOCK( this ); - toolTip = NULL; -} - -void GuiButton::RemoveSoundOver() -{ - LOCK( this ); - soundOver = NULL; -} -void GuiButton::RemoveSoundClick() -{ - LOCK( this ); - soundClick = NULL; -} -void GuiButton::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4) -{ - if (image) - { - image->xx1 = XX1; - image->yy1 = YY1; - image->xx2 = XX2; - image->yy2 = YY2; - image->xx3 = XX3; - image->yy3 = YY3; - image->xx4 = XX4; - image->yy4 = YY4; - } -} - -void GuiButton::SetSkew(int *skew) -{ - if (image) image->SetSkew(skew); -} - -/** - * Draw the button on screen - */ -void GuiButton::Draw() -{ - LOCK( this ); - if (!this->IsVisible()) return; - - // draw image - if ((state == STATE_SELECTED || state == STATE_HELD) && imageOver) - imageOver->Draw(); - else if (image) image->Draw(); - // draw icon - if ((state == STATE_SELECTED || state == STATE_HELD) && iconOver) - iconOver->Draw(); - else if (icon) icon->Draw(); - // draw text - for (int i = 0; i < 3; i++) - { - if ((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i]) - labelOver[i]->Draw(); - else if (label[i]) label[i]->Draw(); - } - - this->UpdateEffects(); -} -void GuiButton::DrawTooltip() -{ - LOCK( this ); - if (this->IsVisible() && state == STATE_SELECTED && toolTip) - { - if (time2 == 0) - { - time(&time1); - time2 = time1; - } - if (time1 != 0) // timer luft - time(&time1); - - if (time1 == 0 || difftime(time1, time2) >= 2) - { - if (time1 != 0) // timer gerade abgelaufen - toolTip->SetEffect(EFFECT_FADE, 20); - time1 = 0; - toolTip->Draw(); - return; - } - } - else - { - if (time2 != 0 && time1 == 0) // timer abgelaufen, gerade DESELECT - if (toolTip) toolTip->SetEffect(EFFECT_FADE, -20); - time2 = 0; - } - if (toolTip && toolTip->GetEffect()) toolTip->Draw(); -} -void GuiButton::ScrollIsOn(int f) -{ - LOCK( this ); - scrollison = f; -} -void GuiButton::Update(GuiTrigger * t) -{ - LOCK( this ); - if (!this->IsVisible() || state == STATE_CLICKED || state == STATE_DISABLED || !t) - return; - else if (parentElement && parentElement->GetState() == STATE_DISABLED) return; - -#ifdef HW_RVL - // cursor - if ( t->wpad.ir.valid ) - { - if ( this->IsInside( t->wpad.ir.x, t->wpad.ir.y ) ) - { - if ( state == STATE_DEFAULT ) // we weren't on the button before! - - { - if ( scrollison == 0 ) - { - this->SetState( STATE_SELECTED, t->chan ); - } - - if ( this->Rumble() && scrollison == 0 ) - rumbleRequest[t->chan] = 1; - - if ( soundOver && scrollison == 0 ) - soundOver->Play(); - - if ( effectsOver && !effects && scrollison == 0 ) - { - // initiate effects - effects = effectsOver; - effectAmount = effectAmountOver; - effectTarget = effectTargetOver; - } - } - } - else - { - if ( state == STATE_SELECTED && ( stateChan == t->chan || stateChan == -1 ) ) - this->ResetState(); - - if ( effectTarget == effectTargetOver && effectAmount == effectAmountOver ) - { - // initiate effects (in reverse) - effects = effectsOver; - effectAmount = -effectAmountOver; - effectTarget = 100; - } - } - } -#else - - if (state == STATE_SELECTED && (stateChan == t->chan || stateChan == -1)) this->ResetState(); - - if (effectTarget == effectTargetOver && effectAmount == effectAmountOver) - { - // initiate effects (in reverse) - effects = effectsOver; - effectAmount = -effectAmountOver; - effectTarget = 100; - } - -#endif - - // button triggers - if (this->IsClickable() && scrollison == 0) - { - s32 wm_btns, wm_btns_trig, cc_btns, cc_btns_trig; - for (int i = 0; i < 6; i++) - { - if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan)) - { - // higher 16 bits only (wiimote) - wm_btns = t->wpad.btns_d << 16; - wm_btns_trig = trigger[i]->wpad.btns_d << 16; - - // lower 16 bits only (classic controller) - cc_btns = t->wpad.btns_d >> 16; - cc_btns_trig = trigger[i]->wpad.btns_d >> 16; - - if (((t->wpad.btns_d > 0 && wm_btns == wm_btns_trig) || (cc_btns == cc_btns_trig && t->wpad.exp.type - == EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0)) - { - if (t->chan == stateChan || stateChan == -1) - { - if (state == STATE_SELECTED) - { - this->SetState(STATE_CLICKED, t->chan); - - if (soundClick) soundClick->Play(); - } - else if (trigger[i]->type == TRIGGER_BUTTON_ONLY) - { - this->SetState(STATE_CLICKED, t->chan); - if (soundClick) soundClick->Play(); - } - else if (trigger[i]->type == TRIGGER_BUTTON_ONLY_IN_FOCUS && parentElement->IsFocused()) - { - this->SetState(STATE_CLICKED, t->chan); - if (soundClick) soundClick->Play(); - } - } - } - } - } - } - - if (this->IsHoldable()) - { - bool held = false; - s32 wm_btns, wm_btns_h, wm_btns_trig, cc_btns, cc_btns_h, cc_btns_trig; - - for (int i = 0; i < 6; i++) - { - if (trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan)) - { - // higher 16 bits only (wiimote) - wm_btns = t->wpad.btns_d << 16; - wm_btns_h = t->wpad.btns_h << 16; - wm_btns_trig = trigger[i]->wpad.btns_h << 16; - - // lower 16 bits only (classic controller) - cc_btns = t->wpad.btns_d >> 16; - cc_btns_h = t->wpad.btns_h >> 16; - cc_btns_trig = trigger[i]->wpad.btns_h >> 16; - - if (((t->wpad.btns_d > 0 && wm_btns == wm_btns_trig) || (cc_btns == cc_btns_trig && t->wpad.exp.type - == EXP_CLASSIC)) || (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0)) - { - if (trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED && (t->chan == stateChan - || stateChan == -1)) this->SetState(STATE_CLICKED, t->chan); - } - - if (((t->wpad.btns_h > 0 && wm_btns_h == wm_btns_trig) || (cc_btns_h == cc_btns_trig - && t->wpad.exp.type == EXP_CLASSIC)) || (t->pad.btns_h == trigger[i]->pad.btns_h - && t->pad.btns_h > 0)) - { - if (trigger[i]->type == TRIGGER_HELD) held = true; - } - - if (!held && state == STATE_HELD && stateChan == t->chan) - { - this->ResetState(); - } - else if (held && state == STATE_CLICKED && stateChan == t->chan) - { - this->SetState(STATE_HELD, t->chan); - } - } - } - } - - if (updateCB) updateCB(this); -} - diff --git a/source/libwiigui/gui_customoptionbrowser.cpp b/source/libwiigui/gui_customoptionbrowser.cpp deleted file mode 100644 index 331bca49..00000000 --- a/source/libwiigui/gui_customoptionbrowser.cpp +++ /dev/null @@ -1,529 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * gui_customoptionbrowser.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "../wpad.h" -#include "../main.h" -#include "../gecko.h" -#include "../settings/CSettings.h" -#include "gui_customoptionbrowser.h" -#include "themes/CTheme.h" -#include "menu.h" - -#include - -#define GAMESELECTSIZE 30 - -/** - * Constructor for the GuiCustomOptionBrowser class. - */ -GuiCustomOptionBrowser::GuiCustomOptionBrowser(int w, int h, OptionList * l, const char * custombg) -{ - width = w; - height = h; - options = l; - selectable = true; - selectedItem = 0; - focus = 1; // allow focus - coL2 = 50; - scrollbaron = false; - listOffset = 0; - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigHeldA = new GuiTrigger; - trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A); - - bgOptions = Resources::GetImageData(custombg); - - bgOptionsImg = new GuiImage(bgOptions); - bgOptionsImg->SetParent(this); - bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - bgOptionsEntry = Resources::GetImageData("bg_options_entry.png"); - - scrollbar = Resources::GetImageData("scrollbar.png"); - scrollbarImg = new GuiImage(scrollbar); - scrollbarImg->SetParent(this); - scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarImg->SetPosition(0, 4); - - arrowDown = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownImg = new GuiImage(arrowDown); - arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownOverImg = new GuiImage(arrowDownOver); - arrowUp = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpImg = new GuiImage(arrowUp); - arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpOverImg = new GuiImage(arrowUpOver); - scrollbarBox = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxImg = new GuiImage(scrollbarBox); - scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver); - - arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); - arrowUpBtn->SetParent(this); - arrowUpBtn->SetImage(arrowUpImg); - arrowUpBtn->SetImageOver(arrowUpOverImg); - arrowUpBtn->SetImageHold(arrowUpOverImg); - arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - arrowUpBtn->SetPosition(width / 2 - 18 + 7, -18); - arrowUpBtn->SetSelectable(false); - arrowUpBtn->SetTrigger(trigA); - arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowUpBtn->SetSoundClick(btnSoundClick); - - arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight()); - arrowDownBtn->SetParent(this); - arrowDownBtn->SetImage(arrowDownImg); - arrowDownBtn->SetImageOver(arrowDownOverImg); - arrowDownBtn->SetImageHold(arrowDownOverImg); - arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - arrowDownBtn->SetPosition(width / 2 - 18 + 7, 18); - arrowDownBtn->SetSelectable(false); - arrowDownBtn->SetTrigger(trigA); - arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowDownBtn->SetSoundClick(btnSoundClick); - - scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight()); - scrollbarBoxBtn->SetParent(this); - scrollbarBoxBtn->SetImage(scrollbarBoxImg); - scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg); - scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg); - scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - scrollbarBoxBtn->SetSelectable(false); - scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120); - scrollbarBoxBtn->SetMinY(0); - scrollbarBoxBtn->SetMaxY(height - 30); - scrollbarBoxBtn->SetHoldable(true); - scrollbarBoxBtn->SetTrigger(trigHeldA); - - for (int i = 0; i < PAGESIZE; i++) - { - optionTxt[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color")); - optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - optionTxt[i]->SetPosition(24, 0); - optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + 24), DOTTED); - - optionBg[i] = new GuiImage(bgOptionsEntry); - - optionVal[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color")); - optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - optionValOver[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color")); - optionValOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - optionBtn[i] = new GuiButton(width - 28, GAMESELECTSIZE); - optionBtn[i]->SetParent(this); - optionBtn[i]->SetLabel(optionTxt[i], 0); - optionBtn[i]->SetLabel(optionVal[i], 1); - optionBtn[i]->SetLabelOver(optionValOver[i], 1); - optionBtn[i]->SetImageOver(optionBg[i]); - optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4); - optionBtn[i]->SetRumble(false); - optionBtn[i]->SetTrigger(trigA); - optionBtn[i]->SetSoundClick(btnSoundClick); - } -} - -/** - * Destructor for the GuiCustomOptionBrowser class. - */ -GuiCustomOptionBrowser::~GuiCustomOptionBrowser() -{ - delete arrowUpBtn; - delete arrowDownBtn; - delete scrollbarBoxBtn; - delete scrollbarImg; - delete arrowDownImg; - delete arrowDownOverImg; - delete arrowUpImg; - delete arrowUpOverImg; - delete scrollbarBoxImg; - delete scrollbarBoxOverImg; - delete scrollbar; - delete arrowDown; - delete arrowDownOver; - delete arrowUp; - delete arrowUpOver; - delete scrollbarBox; - delete scrollbarBoxOver; - - delete bgOptionsImg; - delete bgOptions; - delete bgOptionsEntry; - - delete trigA; - delete trigHeldA; - - for (int i = 0; i < PAGESIZE; i++) - { - delete optionTxt[i]; - delete optionVal[i]; - delete optionValOver[i]; - delete optionBg[i]; - delete optionBtn[i]; - } -} - -void GuiCustomOptionBrowser::SetFocus(int f) -{ - focus = f; - - for (int i = 0; i < PAGESIZE; i++) - optionBtn[i]->ResetState(); - - if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED); -} - -void GuiCustomOptionBrowser::ResetState() -{ - if (state != STATE_DISABLED) - { - state = STATE_DEFAULT; - stateChan = -1; - } - - for (int i = 0; i < PAGESIZE; i++) - { - optionBtn[i]->ResetState(); - } -} - -int GuiCustomOptionBrowser::GetClickedOption() -{ - for (int i = 0; i < PAGESIZE; i++) - { - if (optionBtn[i]->GetState() == STATE_CLICKED) - { - optionBtn[i]->SetState(STATE_SELECTED); - return optionIndex[i]; - } - } - - return -1; -} - -int GuiCustomOptionBrowser::GetSelectedOption() -{ - for (int i = 0; i < PAGESIZE; i++) - { - if (optionBtn[i]->GetState() == STATE_SELECTED) - { - return optionIndex[i]; - } - } - return -1; -} - -void GuiCustomOptionBrowser::SetClickable(bool enable) -{ - for (int i = 0; i < PAGESIZE; i++) - { - optionBtn[i]->SetClickable(enable); - } -} - -void GuiCustomOptionBrowser::SetOffset(int optionnumber) -{ - listOffset = optionnumber; - selectedItem = optionnumber; -} - -/**************************************************************************** - * FindMenuItem - * - * Help function to find the next visible menu item on the list - ***************************************************************************/ - -int GuiCustomOptionBrowser::FindMenuItem(int currentItem, int direction) -{ - int nextItem = currentItem + direction; - - if (nextItem < 0 || nextItem >= options->GetLength()) return -1; - - if (strlen(options->GetName(nextItem)) > 0) - return nextItem; - - return FindMenuItem(nextItem, direction); -} - -/** - * Draw the button on screen - */ -void GuiCustomOptionBrowser::Draw() -{ - if (!this->IsVisible()) return; - - bgOptionsImg->Draw(); - - int next = listOffset; - - for (int i = 0; i < PAGESIZE; i++) - { - if (next >= 0) - { - optionBtn[i]->Draw(); - next = this->FindMenuItem(next, 1); - } - else break; - } - - if (PAGESIZE < options->GetLength()) - { - scrollbarImg->Draw(); - arrowUpBtn->Draw(); - arrowDownBtn->Draw(); - scrollbarBoxBtn->Draw(); - } - this->UpdateEffects(); -} - -void GuiCustomOptionBrowser::UpdateListEntries() -{ - LOCK(this); - scrollbaron = options->GetLength() > PAGESIZE; - if (listOffset < 0) listOffset = this->FindMenuItem(-1, 1); - int next = listOffset; - - int maxNameWidth = 0; - for (int i = 0; i < PAGESIZE; i++) - { - if (next >= 0) - { - if (optionBtn[i]->GetState() == STATE_DISABLED) - { - optionBtn[i]->SetVisible(true); - optionBtn[i]->SetState(STATE_DEFAULT); - } - - optionTxt[i]->SetText(options->GetName(next)); - if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth(); - optionVal[i]->SetText(options->GetValue(next)); - optionValOver[i]->SetText(options->GetValue(next)); - - optionIndex[i] = next; - next = this->FindMenuItem(next, 1); - } - else - { - optionBtn[i]->SetVisible(false); - optionBtn[i]->SetState(STATE_DISABLED); - } - } - - if (coL2 < (24 + maxNameWidth + 16)) - coL2 = 24 + maxNameWidth + 16; - - for (int i = 0; i < PAGESIZE; i++) - { - if (optionBtn[i]->GetState() != STATE_DISABLED) - { - optionVal[i]->SetPosition(coL2, 0); - optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + 24), DOTTED); - - optionValOver[i]->SetPosition(coL2, 0); - optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + 24), SCROLL_HORIZONTAL); - } - } -} - -void GuiCustomOptionBrowser::Update(GuiTrigger * t) -{ - if (state == STATE_DISABLED || !t) return; - - int next, prev, length = options->GetLength(); - int old_listOffset = listOffset; - - if (length < PAGESIZE) - { - // update the location of the scroll box based on the position in the option list - arrowUpBtn->Update(t); - arrowDownBtn->Update(t); - scrollbarBoxBtn->Update(t); - } - - if(options->IsChanged()) - UpdateListEntries(); - - next = listOffset; - - if (!(t->wpad.btns_h & WPAD_BUTTON_UP || t->wpad.btns_h & WPAD_BUTTON_DOWN || - t->wpad.btns_h & WPAD_CLASSIC_BUTTON_UP || t->wpad.btns_h & WPAD_CLASSIC_BUTTON_DOWN || - t->pad.btns_h & PAD_BUTTON_UP || t->pad.btns_h & PAD_BUTTON_DOWN)) - { - for (int i = 0; i < PAGESIZE; i++) - { - if (next >= 0) next = this->FindMenuItem(next, 1); - - if (focus) - { - if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED) - { - optionBtn[i]->ResetState(); - } - else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT) - { - optionBtn[selectedItem]->SetState(STATE_SELECTED); - } - } - - optionBtn[i]->Update(t); - - if (optionBtn[i]->GetState() == STATE_SELECTED) - { - selectedItem = i; - } - } - } - - // pad/joystick navigation - if (!focus) return; // skip navigation - - if (t->Down()) - { - next = this->FindMenuItem(optionIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == PAGESIZE - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - } - else if (optionBtn[selectedItem + 1]->IsVisible()) - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - } - } - else if (t->Up()) - { - prev = this->FindMenuItem(optionIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - } - else - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - } - } - - if (!scrollbaron) - return; - - if (arrowDownBtn->GetState() == STATE_CLICKED || arrowDownBtn->GetState() == STATE_HELD) - { - next = this->FindMenuItem(optionIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == PAGESIZE - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - } - else if (optionBtn[selectedItem + 1]->IsVisible()) - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - scrollbarBoxBtn->Draw(); - usleep(35000); - } - if (!(t->wpad.btns_h & WPAD_BUTTON_A || t->wpad.btns_h & WPAD_CLASSIC_BUTTON_A || - t->pad.btns_h & PAD_BUTTON_A)) - { - arrowDownBtn->ResetState(); - } - } - else if (arrowUpBtn->GetState() == STATE_CLICKED || arrowUpBtn->GetState() == STATE_HELD) - { - prev = this->FindMenuItem(optionIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - } - else - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - scrollbarBoxBtn->Draw(); - usleep(35000); - } - if (!(t->wpad.btns_h & WPAD_BUTTON_A || t->wpad.btns_h & WPAD_CLASSIC_BUTTON_A || - t->pad.btns_h & PAD_BUTTON_A)) - { - arrowUpBtn->ResetState(); - } - } - - if (scrollbarBoxBtn->GetState() == STATE_HELD && scrollbarBoxBtn->GetStateChan() == t->chan && t->wpad.ir.valid - && options->GetLength() > PAGESIZE) - { - scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, 0); - - int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop(); - - listOffset = (position * length) / 180 - selectedItem; - - if (listOffset <= 0) - { - listOffset = 0; - selectedItem = 0; - } - else if (listOffset + PAGESIZE >= length) - { - listOffset = length - PAGESIZE; - selectedItem = PAGESIZE - 1; - } - } - int positionbar = 237 * (listOffset + selectedItem) / length; - - if (positionbar > 216) positionbar = 216; - scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, positionbar + 8); - - if (t->Right()) - { - if (listOffset < length && length > PAGESIZE) - { - listOffset = listOffset + PAGESIZE; - if (listOffset + PAGESIZE >= length) listOffset = length - PAGESIZE; - } - } - else if (t->Left()) - { - if (listOffset > 0) - { - listOffset = listOffset - PAGESIZE; - if (listOffset < 0) listOffset = 0; - } - } - - if (old_listOffset != listOffset) - UpdateListEntries(); - - if (updateCB) updateCB(this); -} diff --git a/source/libwiigui/gui_customoptionbrowser.h b/source/libwiigui/gui_customoptionbrowser.h deleted file mode 100644 index 9291b2fa..00000000 --- a/source/libwiigui/gui_customoptionbrowser.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef GUI_CUSTOMBROWSER_H_ -#define GUI_CUSTOMBROWSER_H_ - -#include "gui.h" -#include - -//!Display a list of menu options -class GuiCustomOptionBrowser: public GuiElement -{ - public: - GuiCustomOptionBrowser(int w, int h, OptionList * l, const char * background); - ~GuiCustomOptionBrowser(); - int FindMenuItem(int c, int d); - int GetClickedOption(); - int GetSelectedOption(); - void SetClickable(bool enable); - void SetOffset(int optionnumber); - void ResetState(); - void SetFocus(int f); - void Draw(); - void Update(GuiTrigger * t); - protected: - void UpdateListEntries(); - int selectedItem; - int listOffset; - int coL2; - bool scrollbaron; - - OptionList * options; - int optionIndex[PAGESIZE]; - GuiButton * optionBtn[PAGESIZE]; - GuiText * optionTxt[PAGESIZE]; - GuiText * optionVal[PAGESIZE]; - GuiText * optionValOver[PAGESIZE]; - GuiImage * optionBg[PAGESIZE]; - - GuiButton * arrowUpBtn; - GuiButton * arrowDownBtn; - GuiButton * scrollbarBoxBtn; - - GuiImage * bgOptionsImg; - GuiImage * scrollbarImg; - GuiImage * arrowDownImg; - GuiImage * arrowDownOverImg; - GuiImage * arrowUpImg; - GuiImage * arrowUpOverImg; - GuiImage * scrollbarBoxImg; - GuiImage * scrollbarBoxOverImg; - - GuiImageData * bgOptions; - GuiImageData * bgOptionsEntry; - GuiImageData * scrollbar; - GuiImageData * arrowDown; - GuiImageData * arrowDownOver; - GuiImageData * arrowUp; - GuiImageData * arrowUpOver; - GuiImageData * scrollbarBox; - GuiImageData * scrollbarBoxOver; - - GuiTrigger * trigA; - GuiTrigger * trigHeldA; -}; - -#endif diff --git a/source/libwiigui/gui_diskcover.cpp b/source/libwiigui/gui_diskcover.cpp deleted file mode 100644 index bf11bd18..00000000 --- a/source/libwiigui/gui_diskcover.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "gui_diskcover.h" - -GuiDiskCover::GuiDiskCover() -{ - deg_beta = 0.0; - eff_step = 0; - // spin_angle = 0; - spin_speedup = 1.0; - spin_up = false; -} -GuiDiskCover::GuiDiskCover(GuiImageData *Disk) : - GuiImage(Disk) -{ - deg_beta = 0.0; - eff_step = 0; - // spin_angle = 0; - spin_speedup = 1.0; - spin_up = false; -} -GuiDiskCover::~GuiDiskCover() -{ -} - -void GuiDiskCover::SetBeta(f32 beta) -{ - deg_beta = beta; -} -void GuiDiskCover::SetBetaRotateEffect(f32 beta, u16 step) -{ - eff_beta = beta / (f32) step; - eff_step = step; -} -bool GuiDiskCover::GetBetaRotateEffect() -{ - return eff_step != 0; -} - -void GuiDiskCover::SetSpin(bool Up) -{ - spin_up = Up; -} - -void Menu_DrawDiskCover(f32 xpos, f32 ypos, f32 zpos, u16 width, u16 height, u16 distance, u8 data[], f32 deg_alpha, - f32 deg_beta, f32 scaleX, f32 scaleY, u8 alpha, bool shadow); -void Menu_DrawDiskCoverShadow(f32 xpos, f32 ypos, f32 zpos, u16 width, u16 height, u16 distance, u8 data[], - f32 deg_alpha, f32 deg_beta, f32 scaleX, f32 scaleY, u8 alpha, bool shadow); - -void GuiDiskCover::Draw() -{ - LOCK( this ); - if (!image || !this->IsVisible()) return; - float currScale = this->GetScale(); - // Menu_DrawDiskCoverShadow(this->GetLeft(), this->GetTop(), 190, width, height, 40, image, imageangle, deg_beta, widescreen ? currScale*0.8 : currScale, currScale, this->GetAlpha(), true); - Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), 50, width, height, 55, image, imageangle, deg_beta, - widescreen ? currScale * 0.8 : currScale, currScale, 64, true); - Menu_DrawDiskCover(this->GetLeft(), this->GetTop(), 50, width, height, 55, image, imageangle, deg_beta, - widescreen ? currScale * 0.8 : currScale, currScale, this->GetAlpha(), false); - - if (eff_step) - { - deg_beta += eff_beta; - eff_step--; - } - GuiImage::imageangle += spin_speedup; - while (GuiImage::imageangle >= 360.0) - GuiImage::imageangle -= 360.0; - - if (spin_up) - { - if (spin_speedup < 11) // speed up - spin_speedup += 0.20; - } - else - { - if (spin_speedup > 1) spin_speedup -= 0.05; //slow down - } - - this->UpdateEffects(); -} diff --git a/source/libwiigui/gui_diskcover.h b/source/libwiigui/gui_diskcover.h deleted file mode 100644 index 5f91ac03..00000000 --- a/source/libwiigui/gui_diskcover.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _GUIDISCCOVER_H_ -#define _GUIDISCCOVER_H_ - -#include "gui.h" - -class GuiDiskCover: public GuiImage -{ - public: - GuiDiskCover(); - GuiDiskCover(GuiImageData * img); - ~GuiDiskCover(); - void SetBeta(f32 beta); - void SetBetaRotateEffect(f32 beta, u16 Step); - bool GetBetaRotateEffect(); - - void SetSpin(bool Up); - void Draw(); - private: - f32 deg_beta; - f32 eff_beta; - u16 eff_step; - - // f32 spin_angle; - f32 spin_speedup; - bool spin_up; -}; - -#endif /* _GUIDISCCOVER_H_ */ diff --git a/source/libwiigui/gui_element.cpp b/source/libwiigui/gui_element.cpp deleted file mode 100644 index 8c31bc6b..00000000 --- a/source/libwiigui/gui_element.cpp +++ /dev/null @@ -1,820 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_element.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" - -/** - * Constructor for the Object class. - */ -//mutex_t GuiElement::mutex = LWP_MUTEX_NULL; -mutex_t GuiElement::_lock_mutex = LWP_MUTEX_NULL; -GuiElement::GuiElement() -{ - xoffset = 0; - yoffset = 0; - zoffset = 0; - xmin = 0; - xmax = 0; - ymin = 0; - ymax = 0; - width = 0; - height = 0; - alpha = 255; - scale = 1; - state = STATE_DEFAULT; - stateChan = -1; - trigger[0] = NULL; - trigger[1] = NULL; - trigger[2] = NULL; - trigger[3] = NULL; - trigger[4] = NULL; - trigger[5] = NULL; - parentElement = NULL; - rumble = true; - selectable = false; - clickable = false; - holdable = false; - visible = true; - focus = -1; // cannot be focused - updateCB = NULL; - yoffsetDyn = 0; - xoffsetDyn = 0; - yoffsetDynFloat = 0; - alphaDyn = -1; - scaleDyn = 1; - effects = 0; - effectAmount = 0; - effectTarget = 0; - effectsOver = 0; - effectAmountOver = 0; - effectTargetOver = 0; - frequency = 0.0f; - changervar = 0; - degree = -90.0f; - circleamount = 360.0f; - Radius = 150; - angleDyn = 0.0f; - anglespeed = 0.0f; - - // default alignment - align to top left - alignmentVert = ALIGN_TOP; - alignmentHor = ALIGN_LEFT; - // if(mutex == LWP_MUTEX_NULL) LWP_MutexInit(&mutex, true); - if (_lock_mutex == LWP_MUTEX_NULL) LWP_MutexInit(&_lock_mutex, true); - _lock_thread = LWP_THREAD_NULL; - _lock_count = 0; - _lock_queue = LWP_TQUEUE_NULL; - -} - -/** - * Destructor for the GuiElement class. - */ -GuiElement::~GuiElement() -{ - // LWP_MutexDestroy(mutex); -} - -void GuiElement::SetParent(GuiElement * e) -{ - LOCK( this ); - parentElement = e; -} - -GuiElement * GuiElement::GetParent() -{ - return parentElement; -} -/** - * Get the left position of the GuiElement. - * @see SetLeft() - * @return Left position in pixel. - */ -int GuiElement::GetLeft() -{ - int x = 0; - int pWidth = 0; - int pLeft = 0; - - if (parentElement) - { - pWidth = parentElement->GetWidth(); - pLeft = parentElement->GetLeft(); - } - - if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_GOROUND | EFFECT_ROCK_VERTICLE)) pLeft += xoffsetDyn; - - switch (alignmentHor) - { - case ALIGN_LEFT: - x = pLeft; - break; - case ALIGN_CENTRE: - x = pLeft + (pWidth / 2) - (width / 2); - break; - case ALIGN_RIGHT: - x = pLeft + pWidth - width; - break; - } - return x + xoffset; -} - -/** - * Get the top position of the GuiElement. - * @see SetTop() - * @return Top position in pixel. - */ -int GuiElement::GetTop() -{ - int y = 0; - int pHeight = 0; - int pTop = 0; - - if (parentElement) - { - pHeight = parentElement->GetHeight(); - pTop = parentElement->GetTop(); - } - - if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_GOROUND | EFFECT_ROCK_VERTICLE)) pTop += yoffsetDyn; - - switch (alignmentVert) - { - case ALIGN_TOP: - y = pTop; - break; - case ALIGN_MIDDLE: - y = pTop + (pHeight / 2) - (height / 2); - break; - case ALIGN_BOTTOM: - y = pTop + pHeight - height; - break; - } - return y + yoffset; -} - -void GuiElement::SetMinX(int x) -{ - LOCK( this ); - xmin = x; -} - -int GuiElement::GetMinX() -{ - return xmin; -} - -void GuiElement::SetMaxX(int x) -{ - LOCK( this ); - xmax = x; -} - -int GuiElement::GetMaxX() -{ - return xmax; -} - -void GuiElement::SetMinY(int y) -{ - LOCK( this ); - ymin = y; -} - -int GuiElement::GetMinY() -{ - return ymin; -} - -void GuiElement::SetMaxY(int y) -{ - LOCK( this ); - ymax = y; -} - -int GuiElement::GetMaxY() -{ - return ymax; -} - -/** - * Get the width of the GuiElement. - * @see SetWidth() - * @return Width of the GuiElement. - */ -int GuiElement::GetWidth() -{ - return width; -} - -/** - * Get the height of the GuiElement. - * @see SetHeight() - * @return Height of the GuiElement. - */ -int GuiElement::GetHeight() -{ - return height; -} - -/** - * Set the width and height of the GuiElement. - * @param[in] Width Width in pixel. - * @param[in] Height Height in pixel. - * @see SetWidth() - * @see SetHeight() - */ -void GuiElement::SetSize(int w, int h) -{ - LOCK( this ); - - width = w; - height = h; -} - -/** - * Get visible. - * @see SetVisible() - * @return true if visible, false otherwise. - */ -bool GuiElement::IsVisible() -{ - return visible; -} - -/** - * Set visible. - * @param[in] Visible Set to true to show GuiElement. - * @see IsVisible() - */ -void GuiElement::SetVisible(bool v) -{ - LOCK( this ); - visible = v; -} - -void GuiElement::SetAlpha(int a) -{ - LOCK( this ); - alpha = a; -} - -int GuiElement::GetAlpha() -{ - int a; - - if (alphaDyn >= 0) - a = alphaDyn; - else a = alpha; - - if (parentElement) a *= parentElement->GetAlpha() / 255.0; - - return a; -} - -float GuiElement::GetAngleDyn() -{ - float a = 0.0; - - if (angleDyn) a = angleDyn; - - if (parentElement && !angleDyn) a = parentElement->GetAngleDyn(); - - return a; -} - -void GuiElement::SetScale(float s) -{ - LOCK( this ); - scale = s; -} - -float GuiElement::GetScale() -{ - float s = scale * scaleDyn; - - if (parentElement) s *= parentElement->GetScale(); - - return s; -} - -int GuiElement::GetState() -{ - return state; -} - -int GuiElement::GetStateChan() -{ - return stateChan; -} - -void GuiElement::SetState(int s, int c) -{ - LOCK( this ); - state = s; - stateChan = c; -} - -void GuiElement::ResetState() -{ - LOCK( this ); - if (state != STATE_DISABLED) - { - state = STATE_DEFAULT; - stateChan = -1; - } -} - -void GuiElement::SetClickable(bool c) -{ - LOCK( this ); - clickable = c; -} - -void GuiElement::SetSelectable(bool s) -{ - LOCK( this ); - selectable = s; -} - -void GuiElement::SetHoldable(bool d) -{ - LOCK( this ); - holdable = d; -} - -bool GuiElement::IsSelectable() -{ - if (state == STATE_DISABLED || state == STATE_CLICKED) - return false; - else return selectable; -} - -bool GuiElement::IsClickable() -{ - if (state == STATE_DISABLED || state == STATE_CLICKED || state == STATE_HELD) - return false; - else return clickable; -} - -bool GuiElement::IsHoldable() -{ - if (state == STATE_DISABLED) - return false; - else return holdable; -} - -void GuiElement::SetFocus(int f) -{ - LOCK( this ); - focus = f; -} - -int GuiElement::IsFocused() -{ - return focus; -} - -void GuiElement::SetTrigger(GuiTrigger * t) -{ - LOCK( this ); - if (!trigger[0]) - trigger[0] = t; - else if (!trigger[1]) - trigger[1] = t; - else if (!trigger[2]) - trigger[2] = t; - else if (!trigger[3]) - trigger[3] = t; - else if (!trigger[4]) - trigger[4] = t; - else if (!trigger[5]) - trigger[5] = t; - else // both were assigned, so we'll just overwrite the first one - trigger[0] = t; -} - -void GuiElement::SetTrigger(u8 i, GuiTrigger * t) -{ - LOCK( this ); - trigger[i] = t; -} - -void GuiElement::RemoveTrigger(u8 i) -{ - LOCK( this ); - trigger[i] = NULL; -} - -bool GuiElement::Rumble() -{ - return rumble; -} - -void GuiElement::SetRumble(bool r) -{ - LOCK( this ); - rumble = r; -} - -int GuiElement::GetEffect() -{ - LOCK( this ); - return effects; -} - -int GuiElement::GetEffectOnOver() -{ - LOCK( this ); - return effectsOver; -} - -float GuiElement::GetFrequency() -{ - LOCK( this ); - return frequency; -} - -void GuiElement::SetEffect(int eff, int speed, f32 circles, int r, f32 startdegree, f32 anglespeedset, int center_x, - int center_y) -{ - - if (eff & EFFECT_GOROUND) - { - xoffsetDyn = 0; //!position of circle in x - yoffsetDyn = 0; //!position of circle in y - Radius = r; //!radius of the circle - degree = startdegree; //!for example -90 () to start at top of circle - circleamount = circles; //!circleamoutn in degrees for example 360 for 1 circle - angleDyn = 0.0f; //!this is used by the code to calc the angle - anglespeed = anglespeedset; //!This is anglespeed depending on circle speed 1 is same speed and 0.5 half speed - temp_xoffset = center_x; //!position of center in x - temp_yoffset = center_y; //!position of center in y - } - effects |= eff; - effectAmount = speed; //!Circlespeed -} - -void GuiElement::SetEffect(int eff, int amount, int target) -{ - LOCK( this ); - if (eff & EFFECT_SLIDE_IN) - { - // these calculations overcompensate a little - if (eff & EFFECT_SLIDE_TOP) - yoffsetDyn = -screenheight; - else if (eff & EFFECT_SLIDE_LEFT) - xoffsetDyn = -screenwidth; - else if (eff & EFFECT_SLIDE_BOTTOM) - yoffsetDyn = screenheight; - else if (eff & EFFECT_SLIDE_RIGHT) xoffsetDyn = screenwidth; - } - - if (eff & EFFECT_FADE && amount > 0) - { - alphaDyn = 0; - } - else if (eff & EFFECT_FADE && amount < 0) - { - alphaDyn = alpha; - - } - else if (eff & EFFECT_ROCK_VERTICLE) - { - changervar = 0; - yoffsetDyn = 0; - yoffsetDynFloat = 0.0; - } - - effects |= eff; - effectAmount = amount; - effectTarget = target; -} - -void GuiElement::SetEffectOnOver(int eff, int amount, int target) -{ - LOCK( this ); - effectsOver |= eff; - effectAmountOver = amount; - effectTargetOver = target; -} - -void GuiElement::SetEffectGrow() -{ - SetEffectOnOver(EFFECT_SCALE, 4, 110); -} - -void GuiElement::StopEffect() -{ - xoffsetDyn = 0; - yoffsetDyn = 0; - effects = 0; - effectsOver = 0; - effectAmount = 0; - effectAmountOver = 0; - effectTarget = 0; - effectTargetOver = 0; - scaleDyn = 1; - frequency = 0.0f; - changervar = 0; - //angleDyn = 0.0f; - anglespeed = 0.0f; -} - -void GuiElement::UpdateEffects() -{ - LOCK( this ); - - if (effects & (EFFECT_SLIDE_IN | EFFECT_SLIDE_OUT | EFFECT_GOROUND)) - { - if (effects & EFFECT_SLIDE_IN) - { - if (effects & EFFECT_SLIDE_LEFT) - { - xoffsetDyn += effectAmount; - - if (xoffsetDyn >= 0) - { - xoffsetDyn = 0; - effects = 0; - } - } - else if (effects & EFFECT_SLIDE_RIGHT) - { - xoffsetDyn -= effectAmount; - - if (xoffsetDyn <= 0) - { - xoffsetDyn = 0; - effects = 0; - } - } - else if (effects & EFFECT_SLIDE_TOP) - { - yoffsetDyn += effectAmount; - - if (yoffsetDyn >= 0) - { - yoffsetDyn = 0; - effects = 0; - } - } - else if (effects & EFFECT_SLIDE_BOTTOM) - { - yoffsetDyn -= effectAmount; - - if (yoffsetDyn <= 0) - { - yoffsetDyn = 0; - effects = 0; - } - } - } - else - { - if (effects & EFFECT_SLIDE_LEFT) - { - xoffsetDyn -= effectAmount; - - if (xoffsetDyn <= -screenwidth) effects = 0; // shut off effect - } - else if (effects & EFFECT_SLIDE_RIGHT) - { - xoffsetDyn += effectAmount; - - if (xoffsetDyn >= screenwidth) effects = 0; // shut off effect - } - else if (effects & EFFECT_SLIDE_TOP) - { - yoffsetDyn -= effectAmount; - - if (yoffsetDyn <= -screenheight) effects = 0; // shut off effect - } - else if (effects & EFFECT_SLIDE_BOTTOM) - { - yoffsetDyn += effectAmount; - - if (yoffsetDyn >= screenheight) effects = 0; // shut off effect - } - } - } - - if (effects & EFFECT_GOROUND) - { - //!< check out gui.h for info - xoffset = temp_xoffset; - yoffset = temp_yoffset; - if (fabs(frequency) < circleamount) - { - angleDyn = (frequency + degree + 90.0f) * anglespeed; - xoffsetDyn = (int) lround(((f32) Radius) * cos((frequency + degree) * PI / 180.0f)); - yoffsetDyn = (int) lround(((f32) Radius) * sin((frequency + degree) * PI / 180.0f)); - frequency += ((f32) effectAmount) * 0.01f; - } - else - { - f32 temp_frequency = ((effectAmount < 0) ? -1.0f : 1.0f) * circleamount; - angleDyn = (temp_frequency + degree + 90.0f) * anglespeed; - xoffsetDyn = (int) lround(((f32) Radius) * cos((temp_frequency + degree) * PI / 180.0f)); - yoffsetDyn = (int) lround(((f32) Radius) * sin((temp_frequency + degree) * PI / 180.0f)); - xoffset += xoffsetDyn; - yoffset += yoffsetDyn; - effects ^= EFFECT_GOROUND; - frequency = 0.0f; - } - } - - if (effects & EFFECT_ROCK_VERTICLE) - { - //move up to 10pixel above 0 - if (changervar == 0 && yoffsetDynFloat < 11.0) - { - yoffsetDynFloat += (effectAmount * 0.01); - } - else if (yoffsetDynFloat > 10.0) - { - changervar = 1; - } - //move down till 10pixel under 0 - if (changervar == 1 && yoffsetDynFloat > -11.0) - { - yoffsetDynFloat -= (effectAmount * 0.01); - } - else if (yoffsetDynFloat < -10.0) - { - changervar = 0; - } - yoffsetDyn = (int) (yoffsetDynFloat); - } - - if (effects & EFFECT_FADE) - { - alphaDyn += effectAmount; - - if (effectAmount < 0 && alphaDyn <= 0) - { - alphaDyn = 0; - effects = 0; // shut off effect - } - else if (effectAmount > 0 && alphaDyn >= alpha) - { - alphaDyn = alpha; - effects = 0; // shut off effect - } - } - if (effects & EFFECT_SCALE) - { - scaleDyn += effectAmount / 100.0; - - if ((effectAmount < 0 && scaleDyn <= effectTarget / 100.0) || (effectAmount > 0 && scaleDyn >= effectTarget - / 100.0)) - { - scaleDyn = effectTarget / 100.0; - effects = 0; // shut off effect - } - } - if (effects & EFFECT_PULSE) - { - int percent = 10; //go down from target by this - - if ((scaleDyn <= (effectTarget * 0.01)) && (!changervar)) - { - scaleDyn += (effectAmount * 0.001); - } - else if (scaleDyn > (effectTarget * 0.01)) - { - changervar = 1; - } - if ((scaleDyn >= ((effectTarget - percent) * 0.01)) && (changervar)) - { - scaleDyn -= (effectAmount * 0.001); - } - else if (scaleDyn < ((effectTarget - percent) * 0.01)) - { - changervar = 0; - } - } -} - -void GuiElement::Update(GuiTrigger * t) -{ - LOCK( this ); - if (updateCB) updateCB(this); -} - -void GuiElement::SetUpdateCallback(UpdateCallback u) -{ - LOCK( this ); - updateCB = u; -} - -void GuiElement::SetPosition(int xoff, int yoff, int zoff) -{ - LOCK( this ); - xoffset = xoff; - yoffset = yoff; - zoffset = zoff; -} - -void GuiElement::SetAlignment(int hor, int vert) -{ - LOCK( this ); - alignmentHor = hor; - alignmentVert = vert; -} - -int GuiElement::GetSelected() -{ - return -1; -} - -/** - * Draw an element on screen. - */ -void GuiElement::Draw() -{ -} - -/** - * Draw Tooltips on screen. - */ -void GuiElement::DrawTooltip() -{ -} - -/** - * Check if a position is inside the GuiElement. - * @param[in] x X position in pixel. - * @param[in] y Y position in pixel. - */ -bool GuiElement::IsInside(int x, int y) -{ - if (x > this->GetLeft() && x < (this->GetLeft() + width) && y > this->GetTop() && y < (this->GetTop() + height)) return true; - return false; -} -void GuiElement::Lock() -{ - // LWP_MutexLock(mutex); - for (;;) // loop while element is locked by self - { - LWP_MutexLock(_lock_mutex); - - if (_lock_thread == LWP_THREAD_NULL) // element is not locked - { - _lock_thread = LWP_GetSelf(); // mark as locked - _lock_count = 1; // set count of lock to 1 - LWP_MutexUnlock(_lock_mutex); - return; - } - else if (_lock_thread == LWP_GetSelf()) // thread is locked by my self - { - _lock_count++; // inc count of locks; - LWP_MutexUnlock(_lock_mutex); - return; - } - else // otherwise the element is locked by an other thread - { - if (_lock_queue == LWP_TQUEUE_NULL) // no queue - meens it is the first access to the locked element - LWP_InitQueue(&_lock_queue); // init queue - LWP_MutexUnlock(_lock_mutex); - LWP_ThreadSleep(_lock_queue); // and sleep - // try lock again; - } - } -} -void GuiElement::Unlock() -{ - // LWP_MutexUnlock(mutex); - LWP_MutexLock(_lock_mutex); - // only the thread was locked this element, can call unlock - if (_lock_thread == LWP_GetSelf()) // but we check it here safe is safe - { - if (--_lock_count == 0) // dec count of locks and check if it last lock; - { - _lock_thread = LWP_THREAD_NULL; // mark as unlocked - if (_lock_queue != LWP_TQUEUE_NULL) // has a queue - { - LWP_CloseQueue(_lock_queue); // close the queue and wake all waited threads - _lock_queue = LWP_TQUEUE_NULL; - } - } - } - LWP_MutexUnlock(_lock_mutex); -} - -SimpleLock::SimpleLock(GuiElement *e) : - element(e) -{ - element->Lock(); -} -SimpleLock::~SimpleLock() -{ - element->Unlock(); -} diff --git a/source/libwiigui/gui_filebrowser.cpp b/source/libwiigui/gui_filebrowser.cpp deleted file mode 100644 index d2a5e07c..00000000 --- a/source/libwiigui/gui_filebrowser.cpp +++ /dev/null @@ -1,456 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_filebrowser.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "prompts/filebrowser.h" -#include "settings/CSettings.h" -#include "themes/CTheme.h" - -/** - * Constructor for the GuiFileBrowser class. - */ -GuiFileBrowser::GuiFileBrowser(int w, int h) -{ - width = w; - height = h; - selectedItem = 0; - selectable = true; - listChanged = true; // trigger an initial list update - triggerdisabled = false; // trigger disable - focus = 0; // allow focus - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - trigHeldA = new GuiTrigger; - trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - bgFileSelection = new GuiImageData(Resources::GetFile("bg_browser.png"), Resources::GetFileSize("bg_browser.png")); - bgFileSelectionImg = new GuiImage(bgFileSelection); - bgFileSelectionImg->SetParent(this); - bgFileSelectionImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - bgFileSelectionEntry = Resources::GetImageData("bg_browser_selection.png"); - - fileFolder = Resources::GetImageData("icon_folder.png"); - - scrollbar = Resources::GetImageData("scrollbar.png"); - scrollbarImg = new GuiImage(scrollbar); - scrollbarImg->SetParent(this); - scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarImg->SetPosition(0, 2); - scrollbarImg->SetSkew(0, 0, 0, 0, 0, -30, 0, -30); - - arrowDown = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownImg = new GuiImage(arrowDown); - arrowUp = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpImg = new GuiImage(arrowUp); - scrollbarBox = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxImg = new GuiImage(scrollbarBox); - - arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); - arrowUpBtn->SetParent(this); - arrowUpBtn->SetImage(arrowUpImg); - arrowUpBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - arrowUpBtn->SetPosition(12, -12); - arrowUpBtn->SetSelectable(false); - arrowUpBtn->SetClickable(false); - arrowUpBtn->SetHoldable(true); - arrowUpBtn->SetTrigger(trigHeldA); - arrowUpBtn->SetSoundOver(btnSoundOver); - arrowUpBtn->SetSoundClick(btnSoundClick); - - arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight()); - arrowDownBtn->SetParent(this); - arrowDownBtn->SetImage(arrowDownImg); - arrowDownBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - arrowDownBtn->SetPosition(12, 12); - arrowDownBtn->SetSelectable(false); - arrowDownBtn->SetClickable(false); - arrowDownBtn->SetHoldable(true); - arrowDownBtn->SetTrigger(trigHeldA); - arrowDownBtn->SetSoundOver(btnSoundOver); - arrowDownBtn->SetSoundClick(btnSoundClick); - - scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight()); - scrollbarBoxBtn->SetParent(this); - scrollbarBoxBtn->SetImage(scrollbarBoxImg); - scrollbarBoxBtn->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarBoxBtn->SetPosition(-10, 0); - scrollbarBoxBtn->SetMinY(-10); - scrollbarBoxBtn->SetMaxY(156); - scrollbarBoxBtn->SetSelectable(false); - scrollbarBoxBtn->SetClickable(false); - scrollbarBoxBtn->SetHoldable(true); - scrollbarBoxBtn->SetTrigger(trigHeldA); - - for (int i = 0; i < FILEBROWSERSIZE; i++) - { - fileListText[i] = new GuiText((char *) NULL, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - fileListText[i]->SetPosition(5, 0); - fileListText[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth() + 20), DOTTED); - - fileListTextOver[i] = new GuiText((char *) NULL, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - fileListTextOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - fileListTextOver[i]->SetPosition(5, 0); - fileListTextOver[i]->SetMaxWidth(bgFileSelectionImg->GetWidth() - (arrowDownImg->GetWidth() + 20), - SCROLL_HORIZONTAL); - - fileListBg[i] = new GuiImage(bgFileSelectionEntry); - //fileListArchives[i] = new GuiImage(fileArchives); - //fileListDefault[i] = new GuiImage(fileDefault); - fileListFolder[i] = new GuiImage(fileFolder); - //fileListGFX[i] = new GuiImage(fileGFX); - //fileListPLS[i] = new GuiImage(filePLS); - //fileListSFX[i] = new GuiImage(fileSFX); - //fileListTXT[i] = new GuiImage(fileTXT); - //fileListXML[i] = new GuiImage(fileXML); - fileList[i] = new GuiButton(350, 30); - fileList[i]->SetParent(this); - fileList[i]->SetLabel(fileListText[i]); - fileList[i]->SetLabelOver(fileListTextOver[i]); - fileList[i]->SetImageOver(fileListBg[i]); - fileList[i]->SetPosition(2, 30 * i + 3); - fileList[i]->SetTrigger(trigA); - fileList[i]->SetRumble(false); - fileList[i]->SetSoundClick(btnSoundClick); - } -} - -/** - * Destructor for the GuiFileBrowser class. - */ -GuiFileBrowser::~GuiFileBrowser() -{ - delete arrowUpBtn; - delete arrowDownBtn; - delete scrollbarBoxBtn; - - delete bgFileSelectionImg; - delete scrollbarImg; - delete arrowDownImg; - delete arrowUpImg; - delete scrollbarBoxImg; - - delete bgFileSelection; - delete bgFileSelectionEntry; - //delete fileArchives; - //delete fileDefault; - delete fileFolder; - //delete fileGFX; - //delete filePLS; - //delete fileSFX; - //delete fileTXT; - //delete fileXML; - delete scrollbar; - delete arrowDown; - delete arrowUp; - delete scrollbarBox; - - delete trigHeldA; - delete trigA; - - for (int i = 0; i < FILEBROWSERSIZE; i++) - { - delete fileListText[i]; - delete fileListTextOver[i]; - delete fileList[i]; - delete fileListBg[i]; - //delete fileListArchives[i]; - //delete fileListDefault[i]; - delete fileListFolder[i]; - //delete fileListGFX[i]; - //delete fileListPLS[i]; - //delete fileListSFX[i]; - //delete fileListTXT[i]; - //delete fileListXML[i]; - } -} - -void GuiFileBrowser::SetFocus(int f) -{ - LOCK( this ); - focus = f; - - for (int i = 0; i < FILEBROWSERSIZE; i++) - fileList[i]->ResetState(); - - if (f == 1) fileList[selectedItem]->SetState(STATE_SELECTED); -} - -void GuiFileBrowser::DisableTriggerUpdate(bool set) -{ - LOCK( this ); - triggerdisabled = set; -} - -void GuiFileBrowser::ResetState() -{ - LOCK( this ); - state = STATE_DEFAULT; - stateChan = -1; - selectedItem = 0; - - for (int i = 0; i < FILEBROWSERSIZE; i++) - { - fileList[i]->ResetState(); - } -} - -void GuiFileBrowser::TriggerUpdate() -{ - LOCK( this ); - listChanged = true; -} - -/** - * Draw the button on screen - */ -void GuiFileBrowser::Draw() -{ - LOCK( this ); - if (!this->IsVisible()) return; - - bgFileSelectionImg->Draw(); - - for (int i = 0; i < FILEBROWSERSIZE; i++) - { - fileList[i]->Draw(); - } - - scrollbarImg->Draw(); - arrowUpBtn->Draw(); - arrowDownBtn->Draw(); - scrollbarBoxBtn->Draw(); - - this->UpdateEffects(); -} - -void GuiFileBrowser::Update(GuiTrigger * t) -{ - LOCK( this ); - if (state == STATE_DISABLED || !t || triggerdisabled) return; - - int position = 0; - int positionWiimote = 0; - - arrowUpBtn->Update(t); - arrowDownBtn->Update(t); - scrollbarBoxBtn->Update(t); - - // move the file listing to respond to wiimote cursor movement - if (scrollbarBoxBtn->GetState() == STATE_HELD && scrollbarBoxBtn->GetStateChan() == t->chan && t->wpad.ir.valid - && browser->browserList.size() > FILEBROWSERSIZE) - { - scrollbarBoxBtn->SetPosition(20, -10); - positionWiimote = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop(); - - if (positionWiimote < scrollbarBoxBtn->GetMinY()) - positionWiimote = scrollbarBoxBtn->GetMinY(); - else if (positionWiimote > scrollbarBoxBtn->GetMaxY()) positionWiimote = scrollbarBoxBtn->GetMaxY(); - - browser->pageIndex = (positionWiimote * browser->browserList.size()) / 136.0 - selectedItem; - - if (browser->pageIndex <= 0) - { - browser->pageIndex = 0; - } - else if (browser->pageIndex + FILEBROWSERSIZE >= (int) browser->browserList.size()) - { - browser->pageIndex = browser->browserList.size() - FILEBROWSERSIZE; - } - listChanged = true; - focus = false; - - } - - if (arrowDownBtn->GetState() == STATE_HELD && arrowDownBtn->GetStateChan() == t->chan) - { - t->wpad.btns_h |= WPAD_BUTTON_DOWN; - if (!this->IsFocused()) ((GuiWindow *) this->GetParent())->ChangeFocus(this); - - } - else if (arrowUpBtn->GetState() == STATE_HELD && arrowUpBtn->GetStateChan() == t->chan) - { - t->wpad.btns_h |= WPAD_BUTTON_UP; - if (!this->IsFocused()) ((GuiWindow *) this->GetParent())->ChangeFocus(this); - - } - - /* // pad/joystick navigation - if(!focus) - { - goto endNavigation; // skip navigation - listChanged = false; - } - */ - if (t->Right()) - { - if (browser->pageIndex < (int) browser->browserList.size() && browser->browserList.size() > FILEBROWSERSIZE) - { - browser->pageIndex += FILEBROWSERSIZE; - if (browser->pageIndex + FILEBROWSERSIZE >= (int) browser->browserList.size()) browser->pageIndex - = browser->browserList.size() - FILEBROWSERSIZE; - listChanged = true; - } - } - else if (t->Left()) - { - if (browser->pageIndex > 0) - { - browser->pageIndex -= FILEBROWSERSIZE; - if (browser->pageIndex < 0) browser->pageIndex = 0; - listChanged = true; - } - } - else if (t->Down()) - { - if (browser->pageIndex + selectedItem + 1 < (int) browser->browserList.size()) - { - if (selectedItem == FILEBROWSERSIZE - 1) - { - // move list down by 1 - browser->pageIndex++; - listChanged = true; - } - else if (fileList[selectedItem + 1]->IsVisible()) - { - fileList[selectedItem]->ResetState(); - fileList[++selectedItem]->SetState(STATE_SELECTED, t->chan); - } - } - } - else if (t->Up()) - { - if (selectedItem == 0 && browser->pageIndex + selectedItem > 0) - { - // move list up by 1 - browser->pageIndex--; - listChanged = true; - } - else if (selectedItem > 0) - { - fileList[selectedItem]->ResetState(); - fileList[--selectedItem]->SetState(STATE_SELECTED, t->chan); - } - } - - //endNavigation: - - for (int i = 0; i < FILEBROWSERSIZE; i++) - { - if (listChanged) - { - bool haveselected = false; - if (browser->pageIndex + i < (int) browser->browserList.size()) - { - if (fileList[i]->GetState() == STATE_DISABLED) fileList[i]->SetState(STATE_DEFAULT); - - if (fileList[i]->GetState() == STATE_SELECTED) haveselected = true; - - fileList[i]->SetVisible(true); - - fileListText[i]->SetText(browser->browserList[browser->pageIndex + i].displayname); - fileListTextOver[i]->SetText(browser->browserList[browser->pageIndex + i].displayname); - - if (browser->browserList[browser->pageIndex + i].isdir) // directory - { - fileList[i]->SetIcon(fileListFolder[i]); - fileListText[i]->SetPosition(30, 0); - fileListTextOver[i]->SetPosition(30, 0); - } - else - { - /* - char *fileext = strrchr(browserList[browser.pageIndex+i].displayname, '.'); - fileListText[i]->SetPosition(32,0); - fileListTextOver[i]->SetPosition(32,0); - if(fileext) - { - if(!strcasecmp(fileext, ".png") || !strcasecmp(fileext, ".jpg") || !strcasecmp(fileext, ".jpeg") || - !strcasecmp(fileext, ".gif") || !strcasecmp(fileext, ".tga") || !strcasecmp(fileext, ".tpl") || - !strcasecmp(fileext, ".bmp")) { - fileList[i]->SetIcon(fileListGFX[i]); - } else if(!strcasecmp(fileext, ".mp3") || !strcasecmp(fileext, ".ogg") || !strcasecmp(fileext, ".flac") || - !strcasecmp(fileext, ".mpc") || !strcasecmp(fileext, ".m4a") || !strcasecmp(fileext, ".wav")) { - fileList[i]->SetIcon(fileListSFX[i]); - } else if(!strcasecmp(fileext, ".pls") || !strcasecmp(fileext, ".m3u")) { - fileList[i]->SetIcon(fileListPLS[i]); - } else if(!strcasecmp(fileext, ".txt")) { - fileList[i]->SetIcon(fileListTXT[i]); - } else if(!strcasecmp(fileext, ".xml")) { - fileList[i]->SetIcon(fileListXML[i]); - } else if(!strcasecmp(fileext, ".rar") || !strcasecmp(fileext, ".zip") || - !strcasecmp(fileext, ".gz") || !strcasecmp(fileext, ".7z")) { - fileList[i]->SetIcon(fileListArchives[i]); - } else { - fileList[i]->SetIcon(fileListDefault[i]); - } - } else { - fileList[i]->SetIcon(fileListDefault[i]); - } - */ - fileList[i]->SetIcon(NULL); - fileListText[i]->SetPosition(10, 0); - fileListTextOver[i]->SetPosition(10, 0); - } - } - else - { - fileList[i]->SetVisible(false); - fileList[i]->SetState(STATE_DISABLED); - } - if (!haveselected && browser->pageIndex < (int) browser->browserList.size()) fileList[i]->SetState( - STATE_SELECTED, t->chan); - - } - - if (i != selectedItem && fileList[i]->GetState() == STATE_SELECTED) - fileList[i]->ResetState(); - else if (focus && i == selectedItem && fileList[i]->GetState() == STATE_DEFAULT) fileList[selectedItem]->SetState( - STATE_SELECTED, t->chan); - - int currChan = t->chan; - - if (t->wpad.ir.valid && !fileList[i]->IsInside(t->wpad.ir.x, t->wpad.ir.y)) t->chan = -1; - - fileList[i]->Update(t); - t->chan = currChan; - - if (fileList[i]->GetState() == STATE_SELECTED) - { - selectedItem = i; - } - } - - // update the location of the scroll box based on the position in the file list - if (positionWiimote > 0) - { - position = positionWiimote; // follow wiimote cursor - } - else - { - position = 136 * (browser->pageIndex + FILEBROWSERSIZE / 2.0) / (browser->browserList.size() * 1.0); - - if (browser->pageIndex / (FILEBROWSERSIZE / 2.0) < 1) - position = -10; - else if ((browser->pageIndex + FILEBROWSERSIZE) / (FILEBROWSERSIZE * 1.0) >= (browser->browserList.size()) - / (FILEBROWSERSIZE * 1.0)) position = 156; - } - - scrollbarBoxBtn->SetPosition(12, position + 26); - - listChanged = false; - - if (updateCB) updateCB(this); -} diff --git a/source/libwiigui/gui_gamebrowser.cpp b/source/libwiigui/gui_gamebrowser.cpp deleted file mode 100644 index 95112b71..00000000 --- a/source/libwiigui/gui_gamebrowser.cpp +++ /dev/null @@ -1,619 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * gui_gamebrowser.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "../wpad.h" - -#include -#include "gui_gamebrowser.h" -#include "../settings/CSettings.h" -#include "../main.h" -#include "settings/newtitles.h" -#include "settings/GameTitles.h" -#include "usbloader/GameList.h" -#include "themes/CTheme.h" -#include "menu.h" - -#include -#include - -#define GAMESELECTSIZE 30 -int txtscroll = 0; -/** - * Constructor for the GuiGameBrowser class. - */ -GuiGameBrowser::GuiGameBrowser(int w, int h, int selectedGame) -{ - width = w; - height = h; - pagesize = thInt("9 - game list browser page size"); - scrollbaron = (gameList.size() > pagesize) ? 1 : 0; - selectable = true; - listOffset = selectedGame - (selectedGame % pagesize); - selectedItem = selectedGame - listOffset; - focus = 1; // allow focus - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigHeldA = new GuiTrigger; - trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A); - - bgGames = Resources::GetImageData("bg_options.png"); - newGames = Resources::GetImageData("new.png"); - - bgGameImg = new GuiImage(bgGames); - bgGameImg->SetParent(this); - bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - maxTextWidth = bgGameImg->GetWidth() - 24 - 4; - - bgGamesEntry = Resources::GetImageData("bg_options_entry.png"); - - scrollbar = Resources::GetImageData("scrollbar.png"); - scrollbarImg = new GuiImage(scrollbar); - scrollbarImg->SetParent(this); - scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarImg->SetPosition(0, 4); - - maxTextWidth -= scrollbarImg->GetWidth() + 4; - - arrowDown = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownImg = new GuiImage(arrowDown); - arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownOverImg = new GuiImage(arrowDownOver); - arrowUp = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpImg = new GuiImage(arrowUp); - arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpOverImg = new GuiImage(arrowUpOver); - scrollbarBox = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxImg = new GuiImage(scrollbarBox); - scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver); - - arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); - arrowUpBtn->SetParent(this); - arrowUpBtn->SetImage(arrowUpImg); - arrowUpBtn->SetImageOver(arrowUpOverImg); - arrowUpBtn->SetImageHold(arrowUpOverImg); - arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - arrowUpBtn->SetPosition(width / 2 - 18 + 7, -18); - arrowUpBtn->SetSelectable(false); - arrowUpBtn->SetTrigger(trigA); - arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowUpBtn->SetSoundClick(btnSoundClick); - - arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight()); - arrowDownBtn->SetParent(this); - arrowDownBtn->SetImage(arrowDownImg); - arrowDownBtn->SetImageOver(arrowDownOverImg); - arrowDownBtn->SetImageHold(arrowDownOverImg); - arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - arrowDownBtn->SetPosition(width / 2 - 18 + 7, 18); - arrowDownBtn->SetSelectable(false); - arrowDownBtn->SetTrigger(trigA); - arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowDownBtn->SetSoundClick(btnSoundClick); - - scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight()); - scrollbarBoxBtn->SetParent(this); - scrollbarBoxBtn->SetImage(scrollbarBoxImg); - scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg); - scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg); - scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - scrollbarBoxBtn->SetSelectable(false); - scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120); - scrollbarBoxBtn->SetMinY(0); - scrollbarBoxBtn->SetMaxY(height - 30); - scrollbarBoxBtn->SetHoldable(true); - scrollbarBoxBtn->SetTrigger(trigHeldA); - - gameIndex = new int[pagesize]; - game = new GuiButton *[pagesize]; - gameTxt = new GuiText *[pagesize]; - gameTxtOver = new GuiText *[pagesize]; - gameBg = new GuiImage *[pagesize]; - newImg = new GuiImage *[pagesize]; - - for (int i = 0; i < pagesize; i++) - { - gameTxt[i] = new GuiText(GameTitles.GetTitle(gameList[i]), 20, thColor("r=0 g=0 b=0 a=255 - game browser list text color")); - gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - gameTxt[i]->SetPosition(24, 0); - gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED); - - gameTxtOver[i] = new GuiText(GameTitles.GetTitle(gameList[i]), 20, thColor("r=0 g=0 b=0 a=255 - game browser list text color over")); - gameTxtOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - gameTxtOver[i]->SetPosition(24, 0); - gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL); - - gameBg[i] = new GuiImage(bgGamesEntry); - - newImg[i] = new GuiImage(newGames); - newImg[i]->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); - newImg[i]->SetVisible(false); - - game[i] = new GuiButton(width - 28, GAMESELECTSIZE); - game[i]->SetParent(this); - game[i]->SetLabel(gameTxt[i]); - game[i]->SetLabelOver(gameTxtOver[i]); - game[i]->SetIcon(newImg[i]); - game[i]->SetImageOver(gameBg[i]); - game[i]->SetPosition(5, GAMESELECTSIZE * i + 4); - game[i]->SetRumble(false); - game[i]->SetTrigger(trigA); - game[i]->SetSoundClick(btnSoundClick); - - gameIndex[i] = i; - } - UpdateListEntries(); -} - -/** - * Destructor for the GuiGameBrowser class. - */ -GuiGameBrowser::~GuiGameBrowser() -{ - delete arrowUpBtn; - delete arrowDownBtn; - delete scrollbarBoxBtn; - delete scrollbarImg; - delete arrowDownImg; - delete arrowDownOverImg; - delete arrowUpImg; - delete arrowUpOverImg; - delete scrollbarBoxImg; - delete scrollbarBoxOverImg; - delete scrollbar; - delete arrowDown; - delete arrowDownOver; - delete arrowUp; - delete arrowUpOver; - delete scrollbarBox; - delete scrollbarBoxOver; - delete bgGameImg; - delete bgGames; - delete bgGamesEntry; - delete newGames; - - delete trigA; - delete trigHeldA; - - for (int i = 0; i < pagesize; i++) - { - delete gameTxt[i]; - delete gameTxtOver[i]; - delete gameBg[i]; - delete game[i]; - delete newImg[i]; - } - delete[] gameIndex; - delete[] game; - delete[] gameTxt; - delete[] gameTxtOver; - delete[] gameBg; -} - -void GuiGameBrowser::SetFocus(int f) -{ - LOCK( this ); - if (!gameList.size()) return; - - focus = f; - - for (int i = 0; i < pagesize; i++) - game[i]->ResetState(); - - if (f == 1) game[selectedItem]->SetState(STATE_SELECTED); -} - -void GuiGameBrowser::ResetState() -{ - LOCK( this ); - if (state != STATE_DISABLED) - { - state = STATE_DEFAULT; - stateChan = -1; - } - - for (int i = 0; i < pagesize; i++) - { - game[i]->ResetState(); - } -} - -int GuiGameBrowser::GetOffset() -{ - return listOffset; -} -int GuiGameBrowser::GetClickedOption() -{ - int found = -1; - for (int i = 0; i < pagesize; i++) - { - if (game[i]->GetState() == STATE_CLICKED) - { - game[i]->SetState(STATE_SELECTED); - found = gameIndex[i]; - break; - } - } - return found; -} - -int GuiGameBrowser::GetSelectedOption() -{ - int found = -1; - for (int i = 0; i < pagesize; i++) - { - if (game[i]->GetState() == STATE_SELECTED) - { - game[i]->SetState(STATE_SELECTED); - found = gameIndex[i]; - break; - } - } - return found; -} - -/**************************************************************************** - * FindMenuItem - * - * Help function to find the next visible menu item on the list - ***************************************************************************/ - -int GuiGameBrowser::FindMenuItem(int currentItem, int direction) -{ - int nextItem = currentItem + direction; - - if (nextItem < 0 || nextItem >= gameList.size()) return -1; - - if (strlen(GameTitles.GetTitle(gameList[nextItem])) > 0) - return nextItem; - - return FindMenuItem(nextItem, direction); -} - -/** - * Draw the button on screen - */ -void GuiGameBrowser::Draw() -{ - LOCK( this ); - if (!this->IsVisible() || !gameList.size()) return; - - bgGameImg->Draw(); - - int next = listOffset; - - for (int i = 0; i < pagesize; i++) - { - if (next >= 0) - { - game[i]->Draw(); - next = this->FindMenuItem(next, 1); - } - else break; - } - - if (scrollbaron == 1) - { - scrollbarImg->Draw(); - arrowUpBtn->Draw(); - arrowDownBtn->Draw(); - scrollbarBoxBtn->Draw(); - } - this->UpdateEffects(); -} - -void GuiGameBrowser::UpdateListEntries() -{ - int next = listOffset; - for (int i = 0; i < pagesize; i++) - { - if (next >= 0) - { - if (game[i]->GetState() == STATE_DISABLED) - { - game[i]->SetVisible(true); - game[i]->SetState(STATE_DEFAULT); - } - gameTxt[i]->SetText(GameTitles.GetTitle(gameList[next])); - gameTxt[i]->SetPosition(24, 0); - gameTxtOver[i]->SetText(GameTitles.GetTitle(gameList[next])); - gameTxtOver[i]->SetPosition(24, 0); - - if (Settings.marknewtitles) - { - bool isNew = NewTitles::Instance()->IsNew(gameList[next]->id); - if (isNew) - { - gameTxt[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), DOTTED); - gameTxtOver[i]->SetMaxWidth(maxTextWidth - (newGames->GetWidth() + 1), SCROLL_HORIZONTAL); - } - else - { - gameTxt[i]->SetMaxWidth(maxTextWidth, DOTTED); - gameTxtOver[i]->SetMaxWidth(maxTextWidth, SCROLL_HORIZONTAL); - } - newImg[i]->SetVisible(isNew); - } - - gameIndex[i] = next; - next = this->FindMenuItem(next, 1); - } - else - { - game[i]->SetVisible(false); - game[i]->SetState(STATE_DISABLED); - } - } -} - -void GuiGameBrowser::Update(GuiTrigger * t) -{ - LOCK( this ); - if (state == STATE_DISABLED || !t || !gameList.size()) return; - - int next, prev; - int old_listOffset = listOffset; - static int position2; - // scrolldelay affects how fast the list scrolls - // when the arrows are clicked - float scrolldelay = 3.5; - - if (scrollbaron == 1) - { - // update the location of the scroll box based on the position in the option list - arrowUpBtn->Update(t); - arrowDownBtn->Update(t); - scrollbarBoxBtn->Update(t); - } - - next = listOffset; - - u32 buttonshold = ButtonsHold(); - - if (buttonshold != WPAD_BUTTON_UP && buttonshold != WPAD_BUTTON_DOWN) - { - - for (int i = 0; i < pagesize; i++) - { - if (next >= 0) next = this->FindMenuItem(next, 1); - - if (focus) - { - if (i != selectedItem && game[i]->GetState() == STATE_SELECTED) - game[i]->ResetState(); - else if (i == selectedItem && game[i]->GetState() == STATE_DEFAULT) game[selectedItem]->SetState( - STATE_SELECTED, t->chan); - } - - game[i]->Update(t); - - if (game[i]->GetState() == STATE_SELECTED) - { - selectedItem = i; - } - } - } - - // pad and joystick navigation - if (!focus || !gameList.size()) return; // skip navigation - - if (scrollbaron == 1) - { - - if (t->Down() || arrowDownBtn->GetState() == STATE_CLICKED || arrowDownBtn->GetState() == STATE_HELD) //down - { - - next = this->FindMenuItem(gameIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == pagesize - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - } - else if (game[selectedItem + 1]->IsVisible()) - { - game[selectedItem]->ResetState(); - game[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - // scrollbarBoxBtn->Draw(); - usleep(10000 * scrolldelay); - } - if (!(ButtonsHold() & WPAD_BUTTON_A)) arrowDownBtn->ResetState(); - } - else if (t->Up() || arrowUpBtn->GetState() == STATE_CLICKED || arrowUpBtn->GetState() == STATE_HELD) //up - { - prev = this->FindMenuItem(gameIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - } - else - { - game[selectedItem]->ResetState(); - game[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - // scrollbarBoxBtn->Draw(); - usleep(10000 * scrolldelay); - } - if (!(ButtonsHold() & WPAD_BUTTON_A)) arrowUpBtn->ResetState(); - } - int position1 = t->wpad.ir.y; - - if (position2 == 0 && position1 > 0) - { - position2 = position1; - } - - if ((buttonshold & WPAD_BUTTON_B) && position1 > 0) - { - scrollbarBoxBtn->ScrollIsOn(1); - if (position2 > position1) - { - - prev = this->FindMenuItem(gameIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - } - else - { - game[selectedItem]->ResetState(); - game[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - // scrollbarBoxBtn->Draw(); - usleep(10000 * scrolldelay); - } - } - else if (position2 < position1) - { - next = this->FindMenuItem(gameIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == pagesize - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - } - else if (game[selectedItem + 1]->IsVisible()) - { - game[selectedItem]->ResetState(); - game[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - // scrollbarBoxBtn->Draw(); - usleep(10000 * scrolldelay); - } - } - - } - else if (!(buttonshold & WPAD_BUTTON_B)) - { - scrollbarBoxBtn->ScrollIsOn(0); - position2 = 0; - } - - if (scrollbarBoxBtn->GetState() == STATE_HELD && scrollbarBoxBtn->GetStateChan() == t->chan && t->wpad.ir.valid - && gameList.size() > pagesize) - { - // allow dragging of scrollbar box - scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, 0); - int position = t->wpad.ir.y - 32 - scrollbarBoxBtn->GetTop(); - - listOffset = (position * gameList.size()) / (25.2 * pagesize) - selectedItem; - - if (listOffset <= 0) - { - listOffset = 0; - selectedItem = 0; - } - else if (listOffset + pagesize >= gameList.size()) - { - listOffset = gameList.size() - pagesize; - selectedItem = pagesize - 1; - } - - } - int positionbar = (25.2 * pagesize) * (listOffset + selectedItem) / gameList.size(); - - if (positionbar > (24 * pagesize)) positionbar = (24 * pagesize); - scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, positionbar + 8); - - if (t->Right()) //skip pagesize # of games if right is pressed - { - if (listOffset < gameList.size() && gameList.size() > pagesize) - { - listOffset = listOffset + pagesize; - if (listOffset + pagesize >= gameList.size()) listOffset = gameList.size() - pagesize; - } - } - else if (t->Left()) - { - if (listOffset > 0) - { - listOffset = listOffset - pagesize; - if (listOffset < 0) listOffset = 0; - } - } - - } - else - { - if (t->Down()) //if there isn't a scrollbar and down is pressed - { - next = this->FindMenuItem(gameIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == pagesize - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - } - else if (game[selectedItem + 1]->IsVisible()) - { - game[selectedItem]->ResetState(); - game[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - } - } - else if (t->Up()) //up - { - prev = this->FindMenuItem(gameIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - } - else - { - game[selectedItem]->ResetState(); - game[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - } - } - } - - if (old_listOffset != listOffset) UpdateListEntries(); - - if (updateCB) updateCB(this); -} - -void GuiGameBrowser::Reload() -{ - LOCK( this ); - scrollbaron = (gameList.size() > pagesize) ? 1 : 0; - selectedItem = 0; - listOffset = 0; - focus = 1; - UpdateListEntries(); - - for (int i = 0; i < pagesize; i++) - game[i]->ResetState(); -} diff --git a/source/libwiigui/gui_gamebrowser.h b/source/libwiigui/gui_gamebrowser.h deleted file mode 100644 index f685033a..00000000 --- a/source/libwiigui/gui_gamebrowser.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _GUIGAMEBROWSER_H_ -#define _GUIGAMEBROWSER_H_ - -#include "gui.h" -#include "../usbloader/disc.h" - -class GuiGameBrowser: public GuiElement -{ - public: - GuiGameBrowser(int w, int h, int selectedGame = 0); - ~GuiGameBrowser(); - int FindMenuItem(int c, int d); - int GetClickedOption(); - int GetSelectedOption(); - void ResetState(); - void SetFocus(int f); - void Draw(); - void Update(GuiTrigger * t); - int GetOffset(); - void Reload(); - //GuiText * optionVal[PAGESIZE]; - protected: - void UpdateListEntries(); - int selectedItem; - int listOffset; - int scrollbaron; - int pagesize; - int maxTextWidth; - - int * gameIndex; - GuiButton ** game; - GuiText ** gameTxt; - GuiText ** gameTxtOver; - GuiImage ** gameBg; - GuiImage ** newImg; - - GuiButton * arrowUpBtn; - GuiButton * arrowDownBtn; - GuiButton * scrollbarBoxBtn; - - GuiImage * bgGameImg; - GuiImage * scrollbarImg; - GuiImage * arrowDownImg; - GuiImage * arrowDownOverImg; - GuiImage * arrowUpImg; - GuiImage * arrowUpOverImg; - GuiImage * scrollbarBoxImg; - GuiImage * scrollbarBoxOverImg; - - GuiImageData * bgGames; - GuiImageData * bgGamesEntry; - GuiImageData * newGames; - GuiImageData * scrollbar; - GuiImageData * arrowDown; - GuiImageData * arrowDownOver; - GuiImageData * arrowUp; - GuiImageData * arrowUpOver; - GuiImageData * scrollbarBox; - GuiImageData * scrollbarBoxOver; - - GuiTrigger * trigA; - GuiTrigger * trigHeldA; -}; -#endif diff --git a/source/libwiigui/gui_gamecarousel.cpp b/source/libwiigui/gui_gamecarousel.cpp deleted file mode 100644 index 1ab4f42b..00000000 --- a/source/libwiigui/gui_gamecarousel.cpp +++ /dev/null @@ -1,436 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * gui_gamecarousel.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "wpad.h" -#include "menu.h" - -#include -#include "gui_image_async.h" -#include "gui_gamecarousel.h" -#include "usbloader/GameList.h" -#include "settings/GameTitles.h" -#include "settings/CSettings.h" -#include "libwiigui/LoadCoverImage.h" -#include "themes/CTheme.h" -#include "main.h" - -#include -#include -#include - -#define SCALE 0.8f -#define DEG_OFFSET 7 -#define RADIUS 780 -#define IN_SPEED 175 -#define SHIFT_SPEED 75 -#define SPEED_STEP 4 -#define SPEED_LIMIT 250 - -static inline int OFFSETLIMIT(int Offset, int gameCnt) -{ - while (Offset < 0) - Offset += gameCnt; - return Offset % gameCnt; -} -#define GetGameIndex(pageEntry, listOffset, gameCnt) OFFSETLIMIT(listOffset+pageEntry, gameCnt) -static GuiImageData *GameCarouselLoadCoverImage(void * Arg) -{ - return LoadCoverImage((struct discHdr *) Arg, true, false); -} -/** - * Constructor for the GuiGameCarousel class. - */ -GuiGameCarousel::GuiGameCarousel(int w, int h, const char *themePath, const u8 *imagebg, int imagebgsize, int selectedGame) : - noCover(nocover_png, nocover_png_size) -{ - width = w; - height = h; - pagesize = (gameList.size() < 11) ? gameList.size() : 11; - listOffset = (selectedGame >= 0 && selectedGame < gameList.size()) ? selectedGame : 0; - selectable = true; - selectedItem = -1; - focus = 1; // allow focus - clickedItem = -1; - - speed = 0; - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigL = new GuiTrigger; - trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); - trigR = new GuiTrigger; - trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); - trigPlus = new GuiTrigger; - trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0); - trigMinus = new GuiTrigger; - trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0); - - imgLeft = Resources::GetImageData("startgame_arrow_left.png"); - imgRight = Resources::GetImageData("startgame_arrow_right.png"); - - int btnHeight = (int) lround(sqrt(RADIUS * RADIUS - 90000) - RADIUS - 50); - - btnLeftImg = new GuiImage(imgLeft); - if (Settings.wsprompt == ON) btnLeftImg->SetWidescreen(Settings.widescreen); - btnLeft = new GuiButton(imgLeft->GetWidth(), imgLeft->GetHeight()); - btnLeft->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - btnLeft->SetPosition(20, btnHeight); - btnLeft->SetParent(this); - btnLeft->SetImage(btnLeftImg); - btnLeft->SetSoundOver(btnSoundOver); - btnLeft->SetTrigger(trigA); - btnLeft->SetTrigger(trigL); - btnLeft->SetTrigger(trigMinus); - btnLeft->SetEffectGrow(); - - btnRightImg = new GuiImage(imgRight); - if (Settings.wsprompt == ON) btnRightImg->SetWidescreen(Settings.widescreen); - btnRight = new GuiButton(imgRight->GetWidth(), imgRight->GetHeight()); - btnRight->SetParent(this); - btnRight->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); - btnRight->SetPosition(-20, btnHeight); - btnRight->SetImage(btnRightImg); - btnRight->SetSoundOver(btnSoundOver); - btnRight->SetTrigger(trigA); - btnRight->SetTrigger(trigR); - btnRight->SetTrigger(trigPlus); - btnRight->SetEffectGrow(); - - gamename = new GuiText(" ", 18, thColor("r=55 g=190 b=237 a=255 - carousel game name text color")); - gamename->SetParent(this); - gamename->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - gamename->SetPosition(0, 330); - gamename->SetMaxWidth(280, DOTTED); - - gameIndex = new int[pagesize]; - game.resize(pagesize); - coverImg.resize(pagesize); - - for (int i = 0; i < pagesize; i++) - { - //------------------------ - // Index - //------------------------ - gameIndex[i] = GetGameIndex( i, listOffset, gameList.size() ); - - //------------------------ - // Image - //------------------------ - coverImg[i] = new (std::nothrow) GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[i]], - sizeof(struct discHdr), &noCover); - if (coverImg[i]) coverImg[i]->SetWidescreen(Settings.widescreen); - - //------------------------ - // GameButton - //------------------------ - - game[i] = new GuiButton(122, 244); - game[i]->SetParent(this); - game[i]->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - game[i]->SetPosition(0, 740); - game[i]->SetImage(coverImg[i]); - game[i]->SetScale(SCALE); - game[i]->SetRumble(false); - game[i]->SetTrigger(trigA); - game[i]->SetSoundClick(btnSoundClick); - game[i]->SetClickable(true); - game[i]->SetEffect(EFFECT_GOROUND, IN_SPEED, 90 - (pagesize - 2 * i - 1) * DEG_OFFSET / 2, RADIUS, 180, 1, 0, - RADIUS); - } -} - -/** - * Destructor for the GuiGameCarousel class. - */ -GuiGameCarousel::~GuiGameCarousel() -{ - delete imgRight; - delete imgLeft; - delete btnLeftImg; - delete btnRightImg; - delete btnRight; - delete btnLeft; - - delete trigA; - delete trigL; - delete trigR; - delete trigPlus; - delete trigMinus; - delete gamename; - - GuiImageAsync::ClearQueue(); - - for (u32 i = 0; i < game.size(); ++i) - delete coverImg[i]; - for (u32 i = 0; i < game.size(); ++i) - delete game[i]; - - delete[] gameIndex; - -} - -void GuiGameCarousel::SetFocus(int f) -{ - LOCK( this ); - if (!gameList.size()) return; - - focus = f; - - for (int i = 0; i < pagesize; i++) - game[i]->ResetState(); - - if (f == 1 && selectedItem >= 0) game[selectedItem]->SetState(STATE_SELECTED); -} - -void GuiGameCarousel::ResetState() -{ - LOCK( this ); - if (state != STATE_DISABLED) - { - state = STATE_DEFAULT; - stateChan = -1; - } - - for (int i = 0; i < pagesize; i++) - { - game[i]->ResetState(); - } -} - -int GuiGameCarousel::GetOffset() -{ - LOCK( this ); - return listOffset; -} - -int GuiGameCarousel::GetClickedOption() -{ - LOCK( this ); - int found = -1; - if (clickedItem >= 0) - { - game[clickedItem]->SetState(STATE_SELECTED); - found = gameIndex[clickedItem]; - clickedItem = -1; - } - return found; -} - -int GuiGameCarousel::GetSelectedOption() -{ - LOCK( this ); - int found = -1; - for (int i = 0; i < pagesize; i++) - { - if (game[i]->GetState() == STATE_SELECTED) - { - game[i]->SetState(STATE_SELECTED); - found = gameIndex[i]; - break; - } - } - return found; -} - -/** - * Draw the button on screen - */ -void GuiGameCarousel::Draw() -{ - LOCK( this ); - if (!this->IsVisible() || !gameList.size()) return; - - for (int i = 0; i < pagesize; i++) - game[i]->Draw(); - - gamename->Draw(); - - if (gameList.size() > 6) - { - btnRight->Draw(); - btnLeft->Draw(); - } - - //!Draw tooltip after the Images to have it on top - if (focus && Settings.tooltips == ON) for (int i = 0; i < pagesize; i++) - game[i]->DrawTooltip(); - - this->UpdateEffects(); -} - -void GuiGameCarousel::Update(GuiTrigger * t) -{ - LOCK( this ); - if (state == STATE_DISABLED || !t || !gameList.size()) return; - - btnRight->Update(t); - btnLeft->Update(t); - - if (game[0]->GetEffect() & EFFECT_GOROUND || game[pagesize - 1]->GetEffect() & EFFECT_GOROUND) - { - return; // skip when rotate - } - - // find selected + clicked - int selectedItem_old = selectedItem; - selectedItem = -1; - clickedItem = -1; - for (int i = pagesize - 1; i >= 0; i--) - { - game[i]->Update(t); - if (game[i]->GetState() == STATE_SELECTED) - { - selectedItem = i; - } - if (game[i]->GetState() == STATE_CLICKED) - { - clickedItem = i; - } - - } - - /// OnOver-Effect + GameText + Tooltop - if (selectedItem_old != selectedItem) - { - if (selectedItem >= 0) - { - game[selectedItem]->SetEffect(EFFECT_SCALE, 1, 130); - gamename->SetText(GameTitles.GetTitle(gameList[gameIndex[selectedItem]])); - } - else gamename->SetText((char*) NULL); - if (selectedItem_old >= 0) game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100); - } - // navigation - if (focus && gameList.size() > 6) - { - - int newspeed = 0; - // Left/Right Navigation - if (btnLeft->GetState() == STATE_CLICKED) - { - WPAD_ScanPads(); - u16 buttons = 0; - for (int i = 0; i < 4; i++) - buttons |= WPAD_ButtonsHeld(i); - if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_MINUS) || t->Left())) - { - btnLeft->ResetState(); - return; - } - - if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D) - newspeed = SHIFT_SPEED; - else newspeed = -SHIFT_SPEED; - } - else if (btnRight->GetState() == STATE_CLICKED) - { - WPAD_ScanPads(); - u16 buttons = 0; - for (int i = 0; i < 4; i++) - buttons |= WPAD_ButtonsHeld(i); - if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_PLUS) || t->Right())) - { - btnRight->ResetState(); - return; - } - if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D) - newspeed = -SHIFT_SPEED; - else newspeed = SHIFT_SPEED; - } - if (newspeed) - { - if (speed == 0) - speed = newspeed; - else if (speed > 0) - { - if ((speed += SPEED_STEP) > SPEED_LIMIT) speed = SPEED_LIMIT; - } - else - { - if ((speed -= SPEED_STEP) < -SPEED_LIMIT) speed = -SPEED_LIMIT; - } - } - else speed = 0; - - if (speed > 0) // rotate right - { - GuiButton *tmpButton; - listOffset = OFFSETLIMIT(listOffset - 1, gameList.size()); // set the new listOffset - // Save right Button + TollTip and destroy right Image + Image-Data - delete coverImg[pagesize - 1]; - coverImg[pagesize - 1] = NULL; - game[pagesize - 1]->SetImage(NULL); - tmpButton = game[pagesize - 1]; - - // Move all Page-Entries one step right - for (int i = pagesize - 1; i >= 1; i--) - { - coverImg[i] = coverImg[i - 1]; - game[i] = game[i - 1]; - gameIndex[i] = gameIndex[i - 1]; - } - // set saved Button & gameIndex to right - gameIndex[0] = listOffset; - coverImg[0] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[0]], sizeof(struct discHdr), - &noCover); - coverImg[0] ->SetWidescreen(Settings.widescreen); - - game[0] = tmpButton; - game[0] ->SetImage(coverImg[0]); - - for (int i = 0; i < pagesize; i++) - { - game[i]->StopEffect(); - game[i]->ResetState(); - game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i + 1) * DEG_OFFSET - / 2, 1, 0, RADIUS); - game[i]->UpdateEffects(); // rotate one step for liquid scrolling - } - } - else if (speed < 0) // rotate left - { - GuiButton *tmpButton; - listOffset = OFFSETLIMIT(listOffset + 1, gameList.size()); // set the new listOffset - // Save left Button + TollTip and destroy left Image + Image-Data - delete coverImg[0]; - coverImg[0] = NULL; - game[0]->SetImage(NULL); - tmpButton = game[0]; - - // Move all Page-Entries one step left - for (int i = 0; i < (pagesize - 1); i++) - { - coverImg[i] = coverImg[i + 1]; - game[i] = game[i + 1]; - gameIndex[i] = gameIndex[i + 1]; - } - // set saved Button & gameIndex to right - int ii = pagesize - 1; - gameIndex[ii] = OFFSETLIMIT(listOffset + ii, gameList.size()); - coverImg[ii] = new GuiImageAsync(GameCarouselLoadCoverImage, gameList[gameIndex[ii]], - sizeof(struct discHdr), &noCover); - coverImg[ii] ->SetWidescreen(Settings.widescreen); - - game[ii] = tmpButton; - game[ii] ->SetImage(coverImg[ii]); - - for (int i = 0; i < pagesize; i++) - { - game[i]->StopEffect(); - game[i]->ResetState(); - game[i]->SetEffect(EFFECT_GOROUND, speed, DEG_OFFSET, RADIUS, 270 - (pagesize - 2 * i - 3) * DEG_OFFSET - / 2, 1, 0, RADIUS); - game[i]->UpdateEffects(); // rotate one step for liquid scrolling - } - } - - } - if (updateCB) updateCB(this); -} - diff --git a/source/libwiigui/gui_gamecarousel.h b/source/libwiigui/gui_gamecarousel.h deleted file mode 100644 index 489a98dc..00000000 --- a/source/libwiigui/gui_gamecarousel.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _GUIGAMECAROUSEL_H_ -#define _GUIGAMECAROUSEL_H_ - -#include -#include "gui.h" -#include "usbloader/disc.h" -class GuiImageAsync; -class GuiGameCarousel: public GuiElement -{ - public: - GuiGameCarousel(int w, int h, const char *themePath, const u8 *imagebg, int imagebgsize, int selectedGame = 0); - ~GuiGameCarousel(); - int FindMenuItem(int c, int d); - int GetClickedOption(); - int GetSelectedOption(); - void ResetState(); - void SetFocus(int f); - void Draw(); - void Update(GuiTrigger * t); - int GetOffset(); - void Reload(); - //GuiText * optionVal[PAGESIZE]; - protected: - GuiImageData noCover; - int selectedItem; - int listOffset; - int scrollbaron; - int pagesize; - int speed; - int clickedItem; - - int * gameIndex; - std::vector game; - std::vector coverImg; - - GuiText * gamename; - - GuiButton * btnRight; - GuiButton * btnLeft; - - GuiImage * btnLeftImg; - GuiImage * btnRightImg; - - GuiImageData * imgLeft; - GuiImageData * imgRight; - - GuiTrigger * trigA; - GuiTrigger * trigL; - GuiTrigger * trigR; - GuiTrigger * trigPlus; - GuiTrigger * trigMinus; -}; -#endif diff --git a/source/libwiigui/gui_gamegrid.cpp b/source/libwiigui/gui_gamegrid.cpp deleted file mode 100644 index 73793830..00000000 --- a/source/libwiigui/gui_gamegrid.cpp +++ /dev/null @@ -1,837 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * gui_gameGrid.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "wpad.h" - -#include -#include "gui_gamegrid.h" -#include "gui_image_async.h" -#include "libwiigui/LoadCoverImage.h" -#include "usbloader/GameList.h" -#include "settings/GameTitles.h" -#include "settings/CSettings.h" -#include "themes/CTheme.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "menu.h" -#include "fatmounter.h" - -#include -#include -#include - -//#define SCALE 0.8f -//#define DEG_OFFSET 7 -#define RADIUS 780 -//#define IN_SPEED 175 -//#define SHIFT_SPEED 100 -//#define SPEED_STEP 4 -//#define SAFETY 320 -#define goSteps 10 -#include "../main.h" - -extern const int vol; - -static int Skew1[7][8] = { { -14, -66, 14, -34, 14, 34, -14, 66 }, { -10, -44, 10, -26, 10, 26, -10, 44 }, { -6, -22, - 6, -14, 6, 14, -6, 22 }, { 0, -11, 0, -11, 0, 11, 0, 11 }, { -6, -14, 6, -22, 6, 22, -6, 14 }, { -10, -26, 10, - -44, 10, 44, -10, 26 }, { -14, -34, 14, -66, 14, 66, -14, 34 } }; -static int Pos1[7][2][2] = { -// {{16:9 x,y},{ 4:3 x,y}} - { { -230, 74 }, { -320, 74 } }, { { -70, 74 }, { -130, 74 } }, { { 88, 74 }, { 60, 74 } }, { { 239, 74 }, { - 239, 74 } }, { { 390, 74 }, { 420, 74 } }, { { 550, 74 }, { 612, 74 } }, { { 710, 74 }, { 772, 74 } } }; -static int Skew2[18][8] = { { -5, -49, 5, -27, 5, 0, -5, 0 }, { -5, 0, 5, 0, 5, 27, -5, 49 }, - -{ -5, -49, 5, -27, 5, 0, -5, 0 }, { -5, 0, 5, 0, 5, 27, -5, 49 }, - -{ -4, -22, 4, -14, 4, 0, -4, 0 }, { -4, 0, 4, 0, 4, 14, -4, 22 }, - -{ 0, -9, 0, -5, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 5, 0, 9 }, - -{ 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, - -{ 0, -5, 0, -9, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 9, 0, 5 }, - -{ -4, -14, 4, -22, 4, 0, -4, 0 }, { -4, 0, 4, 0, 4, 22, -4, 14 }, - -{ -5, -27, 5, -49, 5, 0, -5, 0 }, { -5, 0, 5, 0, 5, 49, -5, 27 }, - -{ -5, -27, 5, -49, 5, 0, -5, 0 }, { -5, 0, 5, 0, 5, 49, -5, 27 } }; -static int Pos2[18][2][2] = { -// {{16:9 x,y},{ 4:3 x,y}} - { { -91, 50 }, { -166, 50 } }, { { -91, 193 }, { -166, 193 } }, - - { { 3, 50 }, { -54, 50 } }, { { 3, 193 }, { -54, 193 } }, - - { { 97, 50 }, { 58, 50 } }, { { 97, 193 }, { 58, 193 } }, - - { { 187, 50 }, { 166, 50 } }, { { 187, 193 }, { 166, 193 } }, - - { { 272, 50 }, { 272, 50 } }, { { 272, 193 }, { 272, 193 } }, - - { { 358, 50 }, { 378, 50 } }, { { 358, 193 }, { 378, 193 } }, - - { { 449, 50 }, { 487, 50 } }, { { 449, 193 }, { 487, 193 } }, - - { { 545, 50 }, { 599, 50 } }, { { 545, 193 }, { 599, 193 } }, - - { { 641, 50 }, { 700, 50 } }, { { 641, 193 }, { 700, 193 } } }; -static int Skew3[45][8] = { { -38, -110, 15, -42, 15, 65, -38, 32 }, { -38, -75, 15, -48, 15, 45, -38, 72 }, { -38, - -52, 15, -70, 15, 27, -38, 100 }, - -{ -38, -110, 15, -42, 15, 65, -38, 32 }, { -38, -75, 15, -48, 15, 45, -38, 72 }, - { -38, -52, 15, -70, 15, 27, -38, 100 }, - - { -38, -70, 15, -24, 15, 40, -38, 27 }, { -38, -50, 15, -35, 15, 40, -38, 50 }, { -38, -34, 15, -47, 15, 24, - -38, 58 }, - - { -27, -55, 19, -22, 19, 30, -27, 22 }, { -27, -40, 19, -30, 19, 30, -27, 40 }, { -27, -20, 19, -30, 19, 20, - -27, 50 }, - - { -19, -28, 0, -17, 0, 15, -19, 10 }, { -19, -30, 0, -20, 0, 12, -19, 30 }, - { -19, -15, 0, -20, 0, 10, -19, 24 }, - - { -10, -20, 3, -13, 3, 14, -10, 10 }, { -10, -20, 3, -18, 3, 18, -10, 20 }, - { -10, -10, 3, -10, 3, 0, -10, 10 }, - - { -10, -15, 3, -12, 3, 13, -10, 13 }, - { -10, -17, 3, -10, 3, 10, -10, 17 }, - { -10, -10, 3, -15, 3, 10, -10, 10 }, - - { -10, -10, 3, -10, 3, 14, -10, 14 }, - { -10, -10, 3, -10, 3, 10, -10, 10 },//middle - { -10, -10, 3, -10, 3, 10, -10, 10 }, - - { -14, -10, 4, -20, 3, 10, -14, 10 }, { -14, -10, 4, -17, 3, 17, -14, 10 }, - { -14, -10, 4, -10, 3, 10, -14, 10 }, - - { -10, -13, 3, -20, 3, 14, -10, 10 }, { -10, -18, 3, -20, 3, 20, -10, 18 }, - { -10, -10, 3, -10, 3, 20, -10, 5 }, - - { -19, -17, 0, -28, 0, 10, -19, 15 }, { -19, -20, 0, -30, 0, 30, -19, 12 }, - { -19, -20, 0, -15, 0, 30, -19, 10 }, - - { -27, -22, 19, -55, 19, 22, -27, 30 }, { -27, -30, 19, -40, 19, 40, -27, 30 }, { -27, -30, 19, -20, 19, 55, - -27, 20 }, - - { -38, -24, 15, -70, 15, 27, -38, 40 }, { -38, -35, 15, -50, 15, 50, -38, 40 }, { -38, -47, 15, -34, 15, 58, - -38, 24 }, - - { -38, -42, 15, -110, 15, 32, -38, 60 }, { -38, -48, 15, -75, 15, 70, -38, 45 }, { -38, -70, 15, -52, 15, 100, - -38, 27 }, - - { -38, -42, 15, -110, 15, 32, -38, 60 }, { -38, -48, 15, -75, 15, 70, -38, 45 }, { -38, -70, 15, -52, 15, 100, - -38, 27 } }; -static int Pos3[45][2][2] = { -// {{16:9 x,y},{ 4:3 x,y}} - { { -42, 49 }, { -91, 49 } }, { { -42, 153 }, { -91, 153 } }, { { -42, 261 }, { -91, 261 } }, - - { { 13, 58 }, { -29, 58 } }, { { 13, 153 }, { -29, 153 } }, { { 13, 250 }, { -29, 250 } }, - - { { 68, 67 }, { 33, 67 } }, { { 68, 153 }, { 33, 153 } }, { { 68, 239 }, { 33, 239 } }, - - { { 120, 74 }, { 92, 74 } }, { { 120, 153 }, { 92, 153 } }, { { 120, 232 }, { 92, 232 } }, - - { { 170, 78 }, { 149, 78 } }, { { 170, 153 }, { 149, 153 } }, { { 170, 228 }, { 149, 228 } }, - - { { 214, 80 }, { 200, 80 } }, { { 214, 153 }, { 200, 153 } }, { { 214, 226 }, { 200, 226 } }, - - { { 258, 81 }, { 251, 81 } }, { { 258, 153 }, { 251, 153 } }, { { 258, 224 }, { 251, 224 } }, - - { { 302, 81 }, { 302, 81 } }, { { 302, 153 }, { 302, 153 } }, { { 302, 223 }, { 302, 223 } }, - - { { 346, 81 }, { 353, 81 } }, { { 346, 153 }, { 353, 153 } }, { { 346, 223 }, { 353, 223 } }, - - { { 390, 80 }, { 404, 80 } }, { { 390, 153 }, { 404, 153 } }, { { 390, 225 }, { 404, 225 } }, - - { { 434, 77 }, { 457, 77 } }, { { 434, 153 }, { 457, 153 } }, { { 434, 227 }, { 457, 227 } }, - - { { 484, 73 }, { 512, 73 } }, { { 484, 153 }, { 512, 153 } }, { { 484, 231 }, { 512, 231 } }, - - { { 537, 67 }, { 572, 67 } }, { { 537, 153 }, { 572, 153 } }, { { 537, 239 }, { 572, 239 } }, - - { { 591, 58 }, { 633, 58 } }, { { 591, 153 }, { 633, 153 } }, { { 591, 250 }, { 633, 250 } }, - - { { 660, 58 }, { 660, 58 } }, { { 660, 153 }, { 660, 153 } }, { { 660, 250 }, { 660, 250 } } - -}; -#define VALUE4ROWS(rows, val1, val2, val3) (rows==3 ? val3 : (rows==2 ? val2 : val1)) -#define ROWS2PAGESIZE(rows) (rows==3 ? 45 : (rows==2 ? 18 : 7)) -static inline int OFFSETLIMIT(int Offset, int rows, int gameCnt) -{ - gameCnt += (rows - (gameCnt % rows)) % rows; // add count of skiped Entries at end if List - while (Offset > gameCnt) - Offset -= gameCnt; - while (Offset < 0) - Offset += gameCnt; - return Offset; -} - -// Help-Function to Calc GameIndex -static int GetGameIndex(int pageEntry, int rows, int listOffset, int gameCnt) -{ - int skip = (rows - (gameCnt % rows)) % rows; // count of skiped Entries at end if List - int pagesize = ROWS2PAGESIZE( rows ); - - if (gameCnt < (pagesize - 2 * rows)) - { - int listStart = (pagesize - gameCnt) >> 1; // align list on the center - listStart = listStart - (listStart % rows); // align listStart to the top row - if (pageEntry < listStart || pageEntry >= listStart + gameCnt) return -1; - return pageEntry - listStart; - } - else - { - listOffset = listOffset - (listOffset % rows); // align listOffset to the top row - listOffset = listOffset - 2 * rows; // align listOffset to the left full visible column - if (listOffset < 0) listOffset += gameCnt + skip; // set the correct Offset - pageEntry = (listOffset + pageEntry) % (gameCnt + skip); // get offset of pageEntry - if (pageEntry >= gameCnt) return -1; - return pageEntry; - } -} -static GuiImageData *GameGridLoadCoverImage(void * Arg) -{ - return LoadCoverImage((struct discHdr *) Arg, false, false); -} -/** - * Constructor for the GuiGamegrid class. - */ -GuiGameGrid::GuiGameGrid(int w, int h, const char *themePath, const u8 *imagebg, int selectedGame) : - noCover(nocoverFlat_png, nocoverFlat_png_size) -{ - width = w; - height = h; - theme_posX = thInt("0 - game grid layout pos x"); - theme_posY = thInt("20 - game grid layout pos y"); - - selectable = true; - focus = 1; // allow focus - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigL = new GuiTrigger; - trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); - trigR = new GuiTrigger; - trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); - trig1 = new GuiTrigger; - trig1->SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_X, PAD_BUTTON_X); - trig2 = new GuiTrigger; - trig2->SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_Y, PAD_BUTTON_Y); - trigPlus = new GuiTrigger; - trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0); - trigMinus = new GuiTrigger; - trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0); - - int btnHeight = (int) lround(sqrt(RADIUS * RADIUS - 90000) - RADIUS - 50); - - // Button Left - btnLeft = new GuiButton(0, 0); - btnLeft->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - btnLeft->SetPosition(20, btnHeight); - btnLeft->SetParent(this); - btnLeft->SetSoundOver(btnSoundOver); - btnLeft->SetTrigger(trigL); - btnLeft->SetTrigger(trigMinus); - - // Button Right - btnRight = new GuiButton(0, 0); - btnRight->SetParent(this); - btnRight->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); - btnRight->SetPosition(-20, btnHeight); - btnRight->SetSoundOver(btnSoundOver); - btnRight->SetTrigger(trigR); - btnRight->SetTrigger(trigPlus); - - // Button RowUp - btnRowUp = new GuiButton(0, 0); - btnRowUp->SetParent(this); - btnRowUp->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - btnRowUp->SetPosition(0, 0); - btnRowUp->SetTrigger(trig2); - - // Button RowDown - btnRowDown = new GuiButton(0, 0); - btnRowDown->SetParent(this); - btnRowDown->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - btnRowDown->SetPosition(0, 0); - btnRowDown->SetTrigger(trig1); - - // Page-Stuff - gameIndex = NULL; - - Reload(Settings.gridRows, 0); -} - -/** - * Destructor for the GuiGameGrid class. - */ -GuiGameGrid::~GuiGameGrid() -{ - - delete btnRight; - delete btnLeft; - delete btnRowUp; - delete btnRowDown; - - delete trigA; - delete trigL; - delete trigR; - delete trigPlus; - delete trigMinus; - delete trig1; - delete trig2; - - GuiImageAsync::ClearQueue(); - - for (u32 i = 0; i < game.size(); ++i) - delete game[i]; - - for (u32 i = 0; i < coverImg.size(); ++i) - delete coverImg[i]; - - for (u32 i = 0; i < titleTT.size(); ++i) - delete titleTT[i]; - - if(gameIndex) - delete [] gameIndex; - game.clear(); - coverImg.clear(); - titleTT.clear(); -} - -void GuiGameGrid::SetFocus(int f) -{ - LOCK( this ); - if (!gameList.size()) return; - - focus = f; - - for (int i = 0; i < pagesize; i++) - game[i]->ResetState(); - - if (f == 1 && selectedItem >= 0) game[selectedItem]->SetState(STATE_SELECTED); -} - -void GuiGameGrid::ResetState() -{ - LOCK( this ); - if (state != STATE_DISABLED) - { - state = STATE_DEFAULT; - stateChan = -1; - } - - for (int i = 0; i < pagesize; i++) - { - game[i]->ResetState(); - } -} - -int GuiGameGrid::GetOffset() -{ - LOCK( this ); - return listOffset; -} - -int GuiGameGrid::GetClickedOption() -{ - LOCK( this ); - int found = -1; - if (clickedItem >= 0) - { - game[clickedItem]->SetState(STATE_SELECTED); - found = gameIndex[clickedItem]; - clickedItem = -1; - } - return found; -} - -int GuiGameGrid::GetSelectedOption() -{ - LOCK( this ); - int found = -1; - for (int i = 0; i < pagesize; i++) - { - if (game[i]->GetState() == STATE_SELECTED) - { - game[i]->SetState(STATE_SELECTED); - found = gameIndex[i]; - break; - } - } - return found; -} - -/** - * Draw the button on screen - */ -void GuiGameGrid::Draw() -{ - LOCK( this ); - if (!this->IsVisible() || !gameList.size()) return; - - if (goLeft > 0) - { - goLeft--; - int wsi = Settings.widescreen ? 0 : 1; - float f2 = ((float) goLeft) / goSteps; - float f1 = 1.0 - f2; - int (*Pos)[2][2] = VALUE4ROWS( rows, Pos1, Pos2, Pos3 ); - int (*Skew)[8] = VALUE4ROWS( rows, Skew1, Skew2, Skew3 ); - - for (int i = 0; i < pagesize - rows; i++) - { - game[i]->SetPosition(Pos[i][wsi][0] * f1 + Pos[i + rows][wsi][0] * f2 + theme_posX, Pos[i][wsi][1] - * f1 + Pos[i + rows][wsi][1] * f2 + theme_posY); - - game[i]->SetSkew(Skew[i][0] * f1 + Skew[i + rows][0] * f2, Skew[i][1] * f1 + Skew[i + rows][1] * f2, - Skew[i][2] * f1 + Skew[i + rows][2] * f2, Skew[i][3] * f1 + Skew[i + rows][3] * f2, Skew[i][4] * f1 - + Skew[i + rows][4] * f2, Skew[i][5] * f1 + Skew[i + rows][5] * f2, Skew[i][6] * f1 - + Skew[i + rows][6] * f2, Skew[i][7] * f1 + Skew[i + rows][7] * f2); - } - } - else if (goRight > 0) - { - goRight--; - int wsi = Settings.widescreen ? 0 : 1; - float f2 = ((float) goRight) / goSteps; - float f1 = 1.0 - f2; - int (*Pos)[2][2] = VALUE4ROWS( rows, Pos1, Pos2, Pos3 ); - int (*Skew)[8] = VALUE4ROWS( rows, Skew1, Skew2, Skew3 ); - for (int i = rows; i < pagesize; i++) - { - game[i]->SetPosition(Pos[i][wsi][0] * f1 + Pos[i - rows][wsi][0] * f2 + theme_posX, Pos[i][wsi][1] - * f1 + Pos[i - rows][wsi][1] * f2 + theme_posY); - - game[i]->SetSkew(Skew[i][0] * f1 + Skew[i - rows][0] * f2, Skew[i][1] * f1 + Skew[i - rows][1] * f2, - Skew[i][2] * f1 + Skew[i - rows][2] * f2, Skew[i][3] * f1 + Skew[i - rows][3] * f2, Skew[i][4] * f1 - + Skew[i - rows][4] * f2, Skew[i][5] * f1 + Skew[i - rows][5] * f2, Skew[i][6] * f1 - + Skew[i - rows][6] * f2, Skew[i][7] * f1 + Skew[i - rows][7] * f2); - } - } - - for (int i = 0; i < pagesize; i++) - game[i]->Draw(); - if (gameList.size() > pagesize - 2 * rows) - { - btnRight->Draw(); - btnLeft->Draw(); - } - - btnRowUp->Draw(); - btnRowDown->Draw(); - - if (focus && Settings.tooltips == ON) for (int i = 0; i < pagesize; i++) - game[i]->DrawTooltip(); - - this->UpdateEffects(); -} - -/** - * Change the number of rows - */ -void GuiGameGrid::ChangeRows(int n) -{ - if (n != rows) Reload(n, -1); -} - -void GuiGameGrid::Update(GuiTrigger * t) -{ - LOCK( this ); - if (state == STATE_DISABLED || !t || !gameList.size()) return; - - if (!(game[0]->GetEffect() || game[0]->GetEffectOnOver())) - { - for (int i = 0; i < pagesize; i++) - game[i]->SetEffectGrow(); - } - - btnRight->Update(t); - btnLeft->Update(t); - btnRowUp->Update(t); - btnRowDown->Update(t); - - selectedItem = -1; - clickedItem = -1; - for (int i = 0; i < pagesize; i++) - { - game[i]->Update(t); - if (game[i]->GetState() == STATE_SELECTED) - { - selectedItem = i; - } - if (game[i]->GetState() == STATE_CLICKED) - { - clickedItem = i; - } - - } - // navigation - if (focus && gameList.size() >= (pagesize - 2 * rows) && goLeft == 0 && goRight == 0) - { - // Left/Right Navigation - - if (btnLeft->GetState() == STATE_CLICKED) - { - u32 buttons = t->wpad.btns_h; - if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_MINUS) || t->Left())) - { - btnLeft->ResetState(); - return; - } - - if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D) - goRight = goSteps; - else goLeft = goSteps; - } - else if (btnRight->GetState() == STATE_CLICKED) - { - u32 buttons = t->wpad.btns_h; - if (!((buttons & WPAD_BUTTON_A) || (buttons & WPAD_BUTTON_PLUS) || t->Right())) - { - btnRight->ResetState(); - return; - } - if (Settings.xflip == XFLIP_SYSMENU || Settings.xflip == XFLIP_YES || Settings.xflip == XFLIP_DISK3D) - goLeft = goSteps; - else goRight = goSteps; - } - - if (goLeft == goSteps) - { - GuiButton *tmpButton[rows]; - GuiTooltip *tmpTooltip[rows]; - listOffset = OFFSETLIMIT(listOffset + rows, rows, gameList.size()); // set the new listOffset - // Save left Tooltip & Button and destroy left Image + Image-Data - for (int i = 0; i < rows; i++) - { - delete coverImg[i]; - coverImg[i] = NULL; - game[i]->SetImage(NULL); - tmpTooltip[i] = titleTT[i]; - tmpButton[i] = game[i]; - } - // Move all Page-Entries one step left - for (int i = 0; i < (pagesize - rows); i++) - { - titleTT[i] = titleTT[i + rows]; - coverImg[i] = coverImg[i + rows]; - game[i] = game[i + rows]; - gameIndex[i] = gameIndex[i + rows]; - } - // set saved Tooltip, Button & gameIndex to right - int wsi = Settings.widescreen ? 0 : 1; - int (*Pos)[2][2] = VALUE4ROWS( rows, Pos1, Pos2, Pos3 ); - int (*Skew)[8] = VALUE4ROWS( rows, Skew1, Skew2, Skew3 ); - - for (int i = 0; i < rows; i++) - { - int ii = i + pagesize - rows; - gameIndex[ii] = GetGameIndex(ii, rows, listOffset, gameList.size()); - titleTT[ii] = tmpTooltip[i]; - coverImg[ii] = NULL; - if (gameIndex[ii] != -1) - { - coverImg[ii] = new GuiImageAsync(GameGridLoadCoverImage, gameList[gameIndex[ii]], - sizeof(struct discHdr), &noCover); - if (coverImg[ii]) - { - coverImg[ii] ->SetWidescreen(Settings.widescreen); - coverImg[ii] ->SetScale(VALUE4ROWS( rows, 1.0, 0.6, 0.26 )); - coverImg[ii] ->SetPosition(0, VALUE4ROWS( rows, 0, -50, -80 )); - } - titleTT[ii] ->SetText(GameTitles.GetTitle(gameList[gameIndex[ii]])); - } - else - { - titleTT[ii] ->SetText(NULL); - } - - game[ii] = tmpButton[i]; - game[ii] ->SetImage(coverImg[ii]); - game[ii] ->SetPosition(Pos[ii][wsi][0], Pos[ii][wsi][1]); - game[ii] ->SetSkew(&Skew[ii][0]); - game[ii] ->RemoveToolTip(); - if (gameIndex[ii] != -1) - { - game[ii] ->SetClickable(true); - game[ii] ->SetVisible(true); - } - else - { - game[ii] ->SetVisible(false); - game[ii] ->SetClickable(false); - game[ii] ->RemoveSoundOver(); - } - } - // Set Tooltip-Position - int ttoffset_x = Settings.widescreen ? VALUE4ROWS( rows, 70, 35, 0 ) : VALUE4ROWS( rows, 150, 55, 25 ); - int ttoffset_y = -VALUE4ROWS( rows, 224, 133, 68 ) / 4; - for (int i = 0; i < pagesize; i++) - { - switch ((i * 3) / pagesize) - { - case 0: - game[i]->SetToolTip(titleTT[i], ttoffset_x, ttoffset_y, ALIGN_LEFT, ALIGN_MIDDLE); - break; - case 1: - game[i]->SetToolTip(titleTT[i], 0, ttoffset_y, ALIGN_CENTRE, ALIGN_MIDDLE); - break; - case 2: - game[i]->SetToolTip(titleTT[i], -ttoffset_x, ttoffset_y, ALIGN_RIGHT, ALIGN_MIDDLE); - break; - default: - break; - } - } - } - else if (goRight == goSteps) - { - GuiButton *tmpButton[rows]; - GuiTooltip *tmpTooltip[rows]; - listOffset = OFFSETLIMIT(listOffset - rows, rows, gameList.size()); // set the new listOffset - // Save right Button & Tooltip and destroy right Image-Data - for (int i = 0; i < rows; i++) - { - int ii = i + pagesize - rows; - delete coverImg[ii]; - coverImg[ii] = NULL; - game[ii]->SetImage(NULL); - tmpTooltip[i] = titleTT[ii]; - tmpButton[i] = game[ii]; - } - // Move all Page-Entries one step right - for (int i = pagesize - 1; i >= rows; i--) - { - titleTT[i] = titleTT[i - rows]; - coverImg[i] = coverImg[i - rows]; - game[i] = game[i - rows]; - gameIndex[i] = gameIndex[i - rows]; - } - // set saved Image, Button & gameIndex to left - int wsi = Settings.widescreen ? 0 : 1; - int (*Pos)[2][2] = VALUE4ROWS( rows, Pos1, Pos2, Pos3 ); - int (*Skew)[8] = VALUE4ROWS( rows, Skew1, Skew2, Skew3 ); - - for (int i = 0; i < rows; i++) - { - gameIndex[i] = GetGameIndex(i, rows, listOffset, gameList.size()); - titleTT[i] = tmpTooltip[i]; - coverImg[i] = NULL; - if (gameIndex[i] != -1) - { - coverImg[i] = new GuiImageAsync(GameGridLoadCoverImage, gameList[gameIndex[i]], - sizeof(struct discHdr), &noCover); - if (coverImg[i]) - { - coverImg[i] ->SetWidescreen(Settings.widescreen); - coverImg[i] ->SetScale(VALUE4ROWS( rows, 1.0, 0.6, 0.26 )); - coverImg[i] ->SetPosition(0, VALUE4ROWS( rows, 0, -50, -80 )); - } - titleTT[i] ->SetText(GameTitles.GetTitle(gameList[gameIndex[i]])); - } - else - { - titleTT[i] ->SetText(NULL); - } - game[i] = tmpButton[i]; - game[i] ->SetImage(coverImg[i]); - game[i] ->SetPosition(Pos[i][wsi][0], Pos[i][wsi][1]); - game[i] ->SetSkew(&Skew[i][0]); - game[i] ->RemoveToolTip(); - if (gameIndex[i] != -1) - { - game[i] ->SetClickable(true); - game[i] ->SetVisible(true); - } - else - { - game[i] ->SetVisible(false); - game[i] ->SetClickable(false); - game[i] ->RemoveSoundOver(); - } - } - // Set Tooltip-Position - int ttoffset_x = Settings.widescreen ? VALUE4ROWS( rows, 70, 35, 0 ) : VALUE4ROWS( rows, 150, 55, 25 ); - int ttoffset_y = -VALUE4ROWS( rows, 224, 133, 68 ) / 4; - for (int i = 0; i < pagesize; i++) - { - switch ((i * 3) / pagesize) - { - case 0: - game[i]->SetToolTip(titleTT[i], ttoffset_x, ttoffset_y, ALIGN_LEFT, ALIGN_MIDDLE); - break; - case 1: - game[i]->SetToolTip(titleTT[i], 0, ttoffset_y, ALIGN_CENTRE, ALIGN_MIDDLE); - break; - case 2: - game[i]->SetToolTip(titleTT[i], -ttoffset_x, ttoffset_y, ALIGN_RIGHT, ALIGN_MIDDLE); - break; - default: - break; - } - } - } - } - - if ((btnRowUp->GetState() == STATE_CLICKED)) - { - if ((rows == 1) && (gameList.size() >= 18)) - this->ChangeRows(2); - else if ((rows == 2) && (gameList.size() >= 45)) this->ChangeRows(3); - btnRowUp->ResetState(); - return; - } - - if ((btnRowDown->GetState() == STATE_CLICKED)) - { - if (rows == 3) - this->ChangeRows(2); - else if (rows == 2) this->ChangeRows(1); - btnRowDown->ResetState(); - return; - } - - if (updateCB) updateCB(this); -} - -void GuiGameGrid::Reload(int Rows, int ListOffset) -{ - LOCK( this ); - - //Prevent to wait before all images are loaded before we can delete them - GuiImageAsync::ClearQueue(); - - // CleanUp - for (u32 i = 0; i < game.size(); ++i) - delete game[i]; - - for (u32 i = 0; i < coverImg.size(); ++i) - delete coverImg[i]; - - for (u32 i = 0; i < titleTT.size(); ++i) - delete titleTT[i]; - - if(gameIndex) - delete [] gameIndex; - game.clear(); - coverImg.clear(); - titleTT.clear(); - - goLeft = 0; - goRight = 0; - - rows = Rows > 3 ? 3 : (Rows < 1 ? 1 : Rows); - if ((gameList.size() < 45) && (rows == 3)) rows = 2; - if ((gameList.size() < 18) && (rows == 2)) rows = 1; - - if (ListOffset >= 0) // if ListOffset < 0 then no change - listOffset = ListOffset; - listOffset = OFFSETLIMIT(listOffset, rows, gameList.size()); - - selectedItem = -1; - clickedItem = -1; - - pagesize = ROWS2PAGESIZE( rows ); - - // Page-Stuff - gameIndex = new int[pagesize]; - titleTT.resize(pagesize); - coverImg.resize(pagesize); - game.resize(pagesize); - - int wsi = Settings.widescreen ? 0 : 1; - int (*Pos)[2][2] = VALUE4ROWS( rows, Pos1, Pos2, Pos3 ); - int (*Skew)[8] = VALUE4ROWS( rows, Skew1, Skew2, Skew3 ); - - int ttoffset_x = Settings.widescreen ? VALUE4ROWS( rows, 70, 35, 0 ) : VALUE4ROWS( rows, 150, 55, 25 ); - int ttoffset_y = -VALUE4ROWS( rows, 224, 133, 68 ) / 4; - - for (int i = 0; i < pagesize; i++) - { - //------------------------ - // Index - //------------------------ - gameIndex[i] = GetGameIndex(i, rows, listOffset, gameList.size()); - - //------------------------ - // Tooltip - //------------------------ - if (gameIndex[i] != -1) - titleTT[i] = new GuiTooltip(GameTitles.GetTitle(gameList[gameIndex[i]]), thInt("255 - tooltip alpha")); - else - titleTT[i] = new GuiTooltip(NULL, thInt("255 - tooltip alpha")); - - //------------------------ - // ImageData - //------------------------ - // if( gameIndex[i] != -1 ) - // cover[i] = LoadCoverImage(&gameList[gameIndex[i]], false /*bool Prefere3D*/); - // else - // cover[i] = new GuiImageData(NULL); - - //------------------------ - // Image - //------------------------ - coverImg[i] = NULL; - if (gameIndex[i] != -1) - { - coverImg[i] = new GuiImageAsync(GameGridLoadCoverImage, gameList[gameIndex[i]], sizeof(struct discHdr), &noCover); - if (coverImg[i]) - { - coverImg[i]->SetWidescreen(Settings.widescreen); - // if ( rows == 2 ) coverImg[i]->SetScale(.6); //these are the numbers for 2 rows - // else if ( rows == 3 ) coverImg[i]->SetScale(.26); //these are the numbers for 3 rows - coverImg[i]->SetScale(VALUE4ROWS( rows, 1.0, 0.6, 0.26 )); - coverImg[i]->SetPosition(0, VALUE4ROWS( rows, 0, -50, -80 )); - } - } - - //------------------------ - // GameButton - //------------------------ - game[i] = new GuiButton(VALUE4ROWS( rows, 160, 75, 35 ), VALUE4ROWS( rows, 224, 133, 68 )); - game[i]->SetParent(this); - game[i]->SetImage(coverImg[i]); - game[i]->SetAlignment(ALIGN_TOP, ALIGN_LEFT); - game[i]->SetPosition(Pos[i][wsi][0] + theme_posX, Pos[i][wsi][1] + theme_posY); - game[i]->SetSkew(&Skew[i][0]); - game[i]->SetTrigger(trigA); - game[i]->SetSoundOver(btnSoundOver); - game[i]->SetSoundClick(btnSoundClick); - game[i]->SetRumble(false); - switch ((i * 3) / pagesize) - { - case 0: - game[i]->SetToolTip(titleTT[i], ttoffset_x, ttoffset_y, ALIGN_LEFT, ALIGN_MIDDLE); - break; - case 1: - game[i]->SetToolTip(titleTT[i], 0, ttoffset_y, ALIGN_CENTRE, ALIGN_MIDDLE); - break; - case 2: - game[i]->SetToolTip(titleTT[i], -ttoffset_x, ttoffset_y, ALIGN_RIGHT, ALIGN_MIDDLE); - break; - default: - break; - } - if (gameIndex[i] >= 0) - { - game[i]->SetClickable(true); - game[i]->SetVisible(true); - } - else - { - game[i]->SetVisible(false); - game[i]->SetClickable(false); - // game[i]->RemoveSoundOver(); - } - } - Settings.gridRows = rows; -} - diff --git a/source/libwiigui/gui_gamegrid.h b/source/libwiigui/gui_gamegrid.h deleted file mode 100644 index 092233d8..00000000 --- a/source/libwiigui/gui_gamegrid.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _GUIGAMEGRID_H_ -#define _GUIGAMEGRID_H_ - -#include -#include "gui.h" -#include "usbloader/disc.h" - -class GuiImageAsync; -class GuiGameGrid: public GuiElement -{ - public: - GuiGameGrid(int w, int h, const char *themePath, const u8 *imagebg, int selectedGame = 0); - ~GuiGameGrid(); - int FindMenuItem(int c, int d); - int GetClickedOption(); - int GetSelectedOption(); - void ResetState(); - void SetFocus(int f); - void Draw(); - void Update(GuiTrigger * t); - int GetOffset(); - void Reload(int Rows, int ListOffset); - void ChangeRows(int n); - protected: - GuiImageData noCover; - int selectedItem; - int listOffset; - int pagesize; - int clickedItem; - int rows; - int goLeft; - int goRight; - int theme_posX; - int theme_posY; - - int * gameIndex; - std::vector game; - std::vector titleTT; - std::vector coverImg; - - GuiButton * btnRight; - GuiButton * btnLeft; - GuiButton * btnRowUp; - GuiButton * btnRowDown; - - GuiImage * btnLeftImg; - GuiImage * btnRightImg; - - GuiImageData * imgLeft; - GuiImageData * imgRight; - - GuiTrigger * trigA; - GuiTrigger * trigL; - GuiTrigger * trigR; - GuiTrigger * trigPlus; - GuiTrigger * trigMinus; - GuiTrigger * trig1; - GuiTrigger * trig2; -}; -#endif diff --git a/source/libwiigui/gui_image.cpp b/source/libwiigui/gui_image.cpp deleted file mode 100644 index e2af5545..00000000 --- a/source/libwiigui/gui_image.cpp +++ /dev/null @@ -1,453 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_image.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -/** - * Constructor for the GuiImage class. - */ -GuiImage::GuiImage() -{ - image = NULL; - width = 0; - height = 0; - imageangle = 0; - tile = -1; - stripe = 0; - widescreen = 0; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_DATA; -} - -GuiImage::GuiImage(GuiImageData * img) -{ - if (img) - { - image = img->GetImage(); - width = img->GetWidth(); - height = img->GetHeight(); - } - else - { - image = NULL; - width = 0; - height = 0; - } - imageangle = 0; - tile = -1; - stripe = 0; - widescreen = 0; - parentangle = true; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_DATA; -} - -GuiImage::GuiImage(u8 * img, int w, int h) -{ - image = img; - width = w; - height = h; - imageangle = 0; - tile = -1; - stripe = 0; - widescreen = 0; - parentangle = true; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_TEXTURE; -} - -GuiImage::GuiImage(int w, int h, GXColor c) -{ - image = (u8 *) memalign(32, w * h * 4); - width = w; - height = h; - imageangle = 0; - tile = -1; - stripe = 0; - widescreen = 0; - parentangle = true; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_COLOR; - - if (!image) return; - - int x, y; - - for (y = 0; y < h; y++) - { - for (x = 0; x < w; x++) - { - this->SetPixel(x, y, c); - } - } - int len = w * h * 4; - if (len % 32) len += (32 - len % 32); - DCFlushRange(image, len); -} - -GuiImage::GuiImage(GuiImage &srcimage) : - GuiElement() -{ - width = srcimage.GetWidth(); - height = srcimage.GetHeight(); - int len = width * height * 4; - if (len % 32) len += (32 - len % 32); - image = (u8 *) memalign(32, len); - memcpy(image, srcimage.GetImage(), len); - DCFlushRange(image, len); - imageangle = srcimage.GetAngle(); - tile = -1; - stripe = 0; - widescreen = 0; - parentangle = true; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_COPY; -} - -GuiImage::GuiImage(GuiImage *srcimage) : - GuiElement() -{ - width = srcimage->GetWidth(); - height = srcimage->GetHeight(); - int len = width * height * 4; - if (len % 32) len += (32 - len % 32); - image = (u8 *) memalign(32, len); - memcpy(image, srcimage->GetImage(), len); - DCFlushRange(image, len); - imageangle = srcimage->GetAngle(); - tile = -1; - stripe = 0; - widescreen = 0; - parentangle = true; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_COPY; -} - -GuiImage &GuiImage::operator=(GuiImage & srcimage) -{ - if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image) - { - free(image); - image = NULL; - } - - width = srcimage.GetWidth(); - height = srcimage.GetHeight(); - int len = width * height * 4; - if (len % 32) len += (32 - len % 32); - image = (u8 *) memalign(32, len); - memcpy(image, srcimage.GetImage(), len); - DCFlushRange(image, len); - imageangle = srcimage.GetAngle(); - tile = -1; - stripe = 0; - widescreen = 0; - parentangle = true; - xx1 = 0; - yy1 = 0; - xx2 = 0; - yy2 = 0; - xx3 = 0; - yy3 = 0; - xx4 = 0; - yy4 = 0; - imgType = IMAGE_COPY; - return *this; -} - -/** - * Destructor for the GuiImage class. - */ -GuiImage::~GuiImage() -{ - if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image) - { - free(image); - image = NULL; - } -} - -u8 * GuiImage::GetImage() -{ - return image; -} - -void GuiImage::SetImage(GuiImageData * img) -{ - LOCK( this ); - if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image) - { - free(image); - image = NULL; - } - - image = img->GetImage(); - width = img->GetWidth(); - height = img->GetHeight(); - imgType = IMAGE_DATA; -} - -void GuiImage::SetImage(u8 * img, int w, int h) -{ - LOCK( this ); - if ((imgType == IMAGE_COLOR || imgType == IMAGE_COPY) && image) - { - free(image); - image = NULL; - } - image = img; - width = w; - height = h; - imgType = IMAGE_TEXTURE; -} - -void GuiImage::SetAngle(float a) -{ - LOCK( this ); - imageangle = a; -} -float GuiImage::GetAngle() -{ - return imageangle; -} - -void GuiImage::SetTile(int t) -{ - LOCK( this ); - tile = t; -} - -void GuiImage::SetWidescreen(bool w) -{ - LOCK( this ); - widescreen = w; -} -void GuiImage::SetParentAngle(bool a) -{ - LOCK( this ); - parentangle = a; -} - -GXColor GuiImage::GetPixel(int x, int y) -{ - if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return ( GXColor ) - { 0, 0, 0, 0}; - - u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1); - GXColor color; - color.a = *(image + offset); - color.r = *(image + offset + 1); - color.g = *(image + offset + 32); - color.b = *(image + offset + 33); - return color; -} - -void GuiImage::SetPixel(int x, int y, GXColor color) -{ - LOCK( this ); - if (!image || this->GetWidth() <= 0 || x < 0 || y < 0) return; - - u32 offset = (((y >> 2) << 4) * this->GetWidth()) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1); - *(image + offset) = color.a; - *(image + offset + 1) = color.r; - *(image + offset + 32) = color.g; - *(image + offset + 33) = color.b; -} - -void GuiImage::SetGrayscale(void) -{ - LOCK( this ); - GXColor color; - u32 offset, gray; - - for (int x = 0; x < width; x++) - { - for (int y = 0; y < height; y++) - { - offset = (((y >> 2) << 4) * width) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1); - color.r = *(image + offset + 1); - color.g = *(image + offset + 32); - color.b = *(image + offset + 33); - - gray = (77 * color.r + 150 * color.g + 28 * color.b) / 255; - - *(image + offset + 1) = gray; - *(image + offset + 32) = gray; - *(image + offset + 33) = gray; - } - } - - int len = width * height * 4; - if (len % 32) len += (32 - len % 32); - DCFlushRange(image, len); -} - -void GuiImage::SetStripe(int s) -{ - LOCK( this ); - stripe = s; -} - -void GuiImage::SetSkew(int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4) -{ - - xx1 = XX1; - yy1 = YY1; - xx2 = XX2; - yy2 = YY2; - xx3 = XX3; - yy3 = YY3; - xx4 = XX4; - yy4 = YY4; -} -void GuiImage::SetSkew(int *skew) -{ - - xx1 = *skew++; - yy1 = *skew++; - xx2 = *skew++; - yy2 = *skew++; - xx3 = *skew++; - yy3 = *skew++; - xx4 = *skew++; - yy4 = *skew; -} - -void GuiImage::ColorStripe(int shift) -{ - LOCK( this ); - int x, y; - GXColor color; - int alt = 0; - - for (y = 0; y < this->GetHeight(); y++) - { - if (y % 3 == 0) alt ^= 1; - - for (x = 0; x < this->GetWidth(); x++) - { - color = GetPixel(x, y); - - if (alt) - { - if (color.r < 255 - shift) - color.r += shift; - else color.r = 255; - if (color.g < 255 - shift) - color.g += shift; - else color.g = 255; - if (color.b < 255 - shift) - color.b += shift; - else color.b = 255; - - color.a = 255; - } - else - { - if (color.r > shift) - color.r -= shift; - else color.r = 0; - if (color.g > shift) - color.g -= shift; - else color.g = 0; - if (color.b > shift) - color.b -= shift; - else color.b = 0; - - color.a = 255; - } - SetPixel(x, y, color); - } - } - - int len = width * height * 4; - if (len % 32) len += (32 - len % 32); - DCFlushRange(image, len); -} - -/** - * Draw the button on screen - */ - -void GuiImage::Draw() -{ - LOCK( this ); - if (!image || !this->IsVisible() || tile == 0) return; - - float currScale = this->GetScale(); - int currLeft = this->GetLeft(); - - float currAngleDyn = this->GetAngleDyn(); - - if (currAngleDyn && parentangle) imageangle = currAngleDyn; - - if (tile > 0) - { - for (int i = 0; i < tile; i++) - Menu_DrawImg(currLeft + width * i, this->GetTop(), zoffset, width, height, image, imageangle, - widescreen ? currScale * 0.80 : currScale, currScale, this->GetAlpha(), xx1, yy1, xx2, yy2, xx3, - yy3, xx4, yy4); - } - else - { - // temporary (maybe), used to correct offset for scaled images - if (scale != 1) currLeft = currLeft - width / 2 + (width * scale) / 2; - - Menu_DrawImg(currLeft, this->GetTop(), zoffset, width, height, image, imageangle, widescreen ? currScale * 0.80 - : currScale, currScale, this->GetAlpha(), xx1, yy1, xx2, yy2, xx3, yy3, xx4, yy4); - } - - if (stripe > 0) for (int y = 0; y < this->GetHeight(); y += 6) - Menu_DrawRectangle(currLeft, this->GetTop() + y, this->GetWidth(), 3, ( GXColor ) - { 0, 0, 0, stripe}, 1); - - this->UpdateEffects(); -} diff --git a/source/libwiigui/gui_image_async.cpp b/source/libwiigui/gui_image_async.cpp deleted file mode 100644 index a2ad15ad..00000000 --- a/source/libwiigui/gui_image_async.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** - * USB Loader GX - * - * gui_imagea_sync.cpp - ***************************************************************************/ -#include -#include "gui_image_async.h" - -std::vector GuiImageAsync::List; -lwp_t GuiImageAsync::Thread = LWP_THREAD_NULL; -mutex_t GuiImageAsync::ListLock = LWP_THREAD_NULL; -GuiImageAsync * GuiImageAsync::InUse = NULL; -u32 GuiImageAsync::ThreadCount = 0; -bool GuiImageAsync::ThreadSleep = true; -bool GuiImageAsync::CloseThread = false; - -static inline void * memdup(const void* src, size_t len) -{ - if(!src) return NULL; - - void *dst = malloc(len); - if (dst) memcpy(dst, src, len); - return dst; -} - -static GuiImageData * StdImageLoaderCallback(void *arg) -{ - return new GuiImageData((char *) arg); -} - -GuiImageAsync::GuiImageAsync(const char *Filename, GuiImageData * PreloadImg) : - GuiImage(PreloadImg), imgData(NULL), callback(StdImageLoaderCallback), arg(strdup(Filename)) -{ - ThreadInit(); - ThreadAddImage(this); -} - -GuiImageAsync::GuiImageAsync(ImageLoaderCallback Callback, const void * Arg, int ArgLen, GuiImageData * PreloadImg) : - GuiImage(PreloadImg), imgData(NULL), callback(Callback), arg(memdup(Arg, ArgLen)) -{ - ThreadInit(); - ThreadAddImage(this); -} - -GuiImageAsync::~GuiImageAsync() -{ - ThreadRemoveImage(this); - ThreadExit(); - while(InUse == this) usleep(100); - if (imgData) delete imgData; - if (arg) free(arg); -} - -void GuiImageAsync::ThreadAddImage(GuiImageAsync *Image) -{ - LWP_MutexLock(ListLock); - List.push_back(Image); - LWP_MutexUnlock(ListLock); - ThreadSleep = false; - LWP_ResumeThread(Thread); -} - -void GuiImageAsync::ThreadRemoveImage(GuiImageAsync *Image) -{ - for(u32 i = 0; i < List.size(); ++i) - { - if(List[i] == Image) - { - LWP_MutexLock(ListLock); - List.erase(List.begin()+i); - LWP_MutexUnlock(ListLock); - break; - } - } -} - -void GuiImageAsync::ClearQueue() -{ - LWP_MutexLock(ListLock); - List.clear(); - LWP_MutexUnlock(ListLock); -} - -void * GuiImageAsync::GuiImageAsyncThread(void *arg) -{ - while(!CloseThread) - { - if(ThreadSleep) - LWP_SuspendThread(Thread); - - while(!List.empty() && !CloseThread) - { - LWP_MutexLock(ListLock); - InUse = List.front(); - List.erase(List.begin()); - LWP_MutexUnlock(ListLock); - - if (!InUse) - continue; - - InUse->imgData = InUse->callback(InUse->arg); - - if (InUse->imgData && InUse->imgData->GetImage()) - { - InUse->width = InUse->imgData->GetWidth(); - InUse->height = InUse->imgData->GetHeight(); - InUse->image = InUse->imgData->GetImage(); - } - - InUse = NULL; - } - - ThreadSleep = true; - } - - return NULL; -} - -u32 GuiImageAsync::ThreadInit() -{ - if (Thread == LWP_THREAD_NULL) - { - LWP_MutexInit(&ListLock, false); - LWP_CreateThread(&Thread, GuiImageAsyncThread, NULL, NULL, 32768, 80); - } - return ++ThreadCount; -} - -u32 GuiImageAsync::ThreadExit() -{ - //! We don't need to always shutdown and startup the thread, especially - //! since this is a nested startup/shutdown from the gui thread. - //! It's fine with being put to suspended only. - /* - if (--ThreadCount == 0) - { - CloseThread = true; - LWP_ResumeThread(Thread); - LWP_JoinThread(Thread, NULL); - LWP_MutexUnlock(ListLock); - LWP_MutexDestroy(ListLock); - Thread = LWP_THREAD_NULL; - ListLock = LWP_MUTEX_NULL; - ListLock = LWP_MUTEX_NULL; - } - */ - return --ThreadCount; -} - diff --git a/source/libwiigui/gui_image_async.h b/source/libwiigui/gui_image_async.h deleted file mode 100644 index 3f440b4a..00000000 --- a/source/libwiigui/gui_image_async.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _GUIIMAGEASYNC_H_ -#define _GUIIMAGEASYNC_H_ - -#include -#include "libwiigui/gui.h" - -typedef GuiImageData * (*ImageLoaderCallback)(void *arg); - -class GuiImageAsync: public GuiImage -{ - public: - GuiImageAsync(const char *Filename, GuiImageData * PreloadImg); - GuiImageAsync(ImageLoaderCallback Callback, const void *Arg, int ArgLen, GuiImageData * PreloadImg); - ~GuiImageAsync(); - - static void ClearQueue(); - private: - GuiImageData *imgData; - ImageLoaderCallback callback; - void *arg; - - static void * GuiImageAsyncThread(void *arg); - static void ThreadAddImage(GuiImageAsync* Image); - static void ThreadRemoveImage(GuiImageAsync* Image); - static u32 ThreadInit(); - static u32 ThreadExit(); - - static std::vector List; - static lwp_t Thread; - static mutex_t ListLock; - static GuiImageAsync * InUse; - static u32 ThreadCount; - static bool ThreadSleep; - static bool CloseThread; -}; - -#endif /*_GUIIMAGEASYNC_H_*/ diff --git a/source/libwiigui/gui_imagedata.cpp b/source/libwiigui/gui_imagedata.cpp deleted file mode 100644 index 604bae66..00000000 --- a/source/libwiigui/gui_imagedata.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include "gui.h" -#include "ImageOperations/TextureConverter.h" -#include "ImageOperations/TplImage.h" -#include "FileOperations/fileops.h" -#include "utils/ResourceManager.h" - -#define ALIGN32(x) (((x) + 31) & ~31) - -/** - * Constructor for the GuiImageData class. - */ -GuiImageData::GuiImageData(const char * filepath) -{ - data = NULL; - width = 0; - height = 0; - format = GX_TF_RGBA8; - - u8 *buffer = NULL; - u64 size = 0; - - if(LoadFileToMem(filepath, &buffer, &size) < 0) - return; - - LoadImage(buffer, size); - - if(buffer) - free(buffer); -} - -GuiImageData::GuiImageData(const u8 * img, int imgSize) -{ - data = NULL; - width = 0; - height = 0; - format = GX_TF_RGBA8; - - ImageData * Image = ResourceManager::GetImageData(img); - if(Image != NULL && Image->data != NULL) - { - data = Image->data; - width = Image->width; - height = Image->height; - format = Image->format; - return; - } - - LoadImage(img, imgSize); - - if(data) - { - ImageData NewImage; - NewImage.data = data; - NewImage.width = width; - NewImage.height = height; - NewImage.format = format; - ResourceManager::AddImageData(img, NewImage); - } -} - -/** - * Destructor for the GuiImageData class. - */ -GuiImageData::~GuiImageData() -{ - if(data) - ResourceManager::Remove(data); -} - -void GuiImageData::LoadImage(const u8 * img, int imgSize) -{ - if(!img) - return; - - else if (imgSize < 8) - { - return; - } - else if (img[0] == 0x89 && img[1] == 'P' && img[2] == 'N' && img[3] == 'G') - { - // IMAGE_PNG - LoadPNG(img, imgSize); - } - else if (img[0] == 0xFF && img[1] == 0xD8) - { - // IMAGE_JPEG - LoadJpeg(img, imgSize); - } - else if (img[0] == 'B' && img[1] == 'M') - { - // IMAGE_BMP - LoadBMP(img, imgSize); - } - else if (img[0] == 'G' && img[1] == 'I' && img[2] == 'F') - { - // IMAGE_GIF - LoadGIF(img, imgSize); - } - else if (img[0] == 0x00 && img[1] == 0x20 && img[2] == 0xAF && img[3] == 0x30) - { - // IMAGE_TPL - LoadTPL(img, imgSize); - } -} - -void GuiImageData::LoadPNG(const u8 *img, int imgSize) -{ - gdImagePtr gdImg = gdImageCreateFromPngPtr(imgSize, (u8*) img); - if(gdImg == 0) - return; - - data = GDImageToRGBA8(&gdImg, &width, &height); - gdImageDestroy(gdImg); -} - -void GuiImageData::LoadJpeg(const u8 *img, int imgSize) -{ - gdImagePtr gdImg = gdImageCreateFromJpegPtr(imgSize, (u8*) img); - if(gdImg == 0) - return; - - data = GDImageToRGBA8(&gdImg, &width, &height); - gdImageDestroy(gdImg); -} - -void GuiImageData::LoadGIF(const u8 *img, int imgSize) -{ - gdImagePtr gdImg = gdImageCreateFromGifPtr(imgSize, (u8*) img); - if(gdImg == 0) - return; - - data = GDImageToRGBA8(&gdImg, &width, &height); - gdImageDestroy(gdImg); -} - -void GuiImageData::LoadBMP(const u8 *img, int imgSize) -{ - gdImagePtr gdImg = gdImageCreateFromBmpPtr(imgSize, (u8*) img); - if(gdImg == 0) - return; - - data = GDImageToRGBA8(&gdImg, &width, &height); - gdImageDestroy(gdImg); -} - -void GuiImageData::LoadTPL(const u8 *img, int imgSize) -{ - TplImage TplFile(img, imgSize); - - width = TplFile.GetWidth(0); - height = TplFile.GetHeight(0); - format = (u8) TplFile.GetFormat(0); - - const u8 * ImgPtr = TplFile.GetTextureBuffer(0); - - if(ImgPtr) - { - int len = ALIGN32(TplFile.GetTextureSize(0)); - - data = (u8 *) memalign(32, len); - if(!data) - return; - - memcpy(data, ImgPtr, len); - DCFlushRange(data, len); - } -} diff --git a/source/libwiigui/gui_imagedata.h b/source/libwiigui/gui_imagedata.h deleted file mode 100644 index 59542a54..00000000 --- a/source/libwiigui/gui_imagedata.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef GUI_IMAGEDATA_H_ -#define GUI_IMAGEDATA_H_ - -#include -#include - -class GuiImageData -{ - public: - //!Constructor - //!\param img Image data - //!\param imgSize The image size - GuiImageData(const u8 * img, int imgSize); - //!Overload - GuiImageData(const char * filepath); - //!Destructor - ~GuiImageData(); - //!Gets a pointer to the image data - //!\return pointer to image data - u8 * GetImage() { return data; }; - //!Gets the image width - //!\return image width - int GetWidth() { return width; }; - //!Gets the image height - //!\return image height - int GetHeight() { return height; }; - //!Gets the texture format - u8 GetTextureFormat() { return format; }; - protected: - void LoadImage(const u8 * img, int imgSize); - void LoadPNG(const u8 *img, int imgSize); - void LoadBMP(const u8 *img, int imgSize); - void LoadJpeg(const u8 *img, int imgSize); - void LoadGIF(const u8 *img, int imgSize); - void LoadTPL(const u8 *img, int imgSize); - - u8 * data; //!< Image data - int height; //!< Height of image - int width; //!< Width of image - u8 format; //!< Texture format -}; - -#endif diff --git a/source/libwiigui/gui_keyboard.cpp b/source/libwiigui/gui_keyboard.cpp deleted file mode 100644 index b4e2183c..00000000 --- a/source/libwiigui/gui_keyboard.cpp +++ /dev/null @@ -1,522 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_keyboard.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "../main.h" -#include "../settings/CSettings.h" -#include -#include -#include "menu.h" -/** - * Constructor for the GuiKeyboard class. - */ -unsigned int m; -//const Key thekeys; -GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang) -{ - width = 540; - height = 400; - shift = 0; - caps = 0; - alt = 0; - alt2 = 0; - m = min; - int mode = lang; - selectable = true; - focus = 0; // allow focus - alignmentHor = ALIGN_CENTRE; - alignmentVert = ALIGN_MIDDLE; - kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr) - // strlcpy(kbtextstr, t, kbtextmaxlen); - strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0 - kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0 - //QWERTY// - if (mode == 0) - { - Key thekeys[4][11] = { { { '1', '!' }, { '2', '@' }, { '3', '#' }, { '4', '$' }, { '5', '%' }, { '6', '^' }, { - '7', '&' }, { '8', '*' }, { '9', '(' }, { '0', ')' }, { '\0', '\0' } }, { { 'q', 'Q' }, { 'w', 'W' }, { - 'e', 'E' }, { 'r', 'R' }, { 't', 'T' }, { 'y', 'Y' }, { 'u', 'U' }, { 'i', 'I' }, { 'o', 'O' }, { 'p', - 'P' }, { '-', '_' } }, { { 'a', 'A' }, { 's', 'S' }, { 'd', 'D' }, { 'f', 'F' }, { 'g', 'G' }, { 'h', - 'H' }, { 'j', 'J' }, { 'k', 'K' }, { 'l', 'L' }, { ':', ';' }, { '\'', '"' } }, - - { { 'z', 'Z' }, { 'x', 'X' }, { 'c', 'C' }, { 'v', 'V' }, { 'b', 'B' }, { 'n', 'N' }, { 'm', 'M' }, - { ',', '<' }, { '.', '>' }, { '/', '?' }, { '\0', '\0' } } }; - - memcpy(keys, thekeys, sizeof(thekeys)); - } - //DVORAK// - if (mode == 1) - { - Key thekeys[4][11] = { { { '1', '!', '\0' }, { '2', '@', '\0' }, { '3', '#', '\0' }, { '4', '$', '\0' }, { '5', - '%', '\0' }, { '6', '^', '\0' }, { '7', '&', '\0' }, { '8', '*', '\0' }, { '9', '(', '\0' }, { '0', - ')', '\0' }, { '\0', '\0', '\0' } }, { { '\'', '"', '\0' }, { ',', '<', '\0' }, { '.', '>', '\0' }, { - 'p', 'P', '\0' }, { 'y', 'Y', '\0' }, { 'f', 'F', '\0' }, { 'g', 'G', '\0' }, { 'c', 'C', '\0' }, { - 'r', 'R', '\0' }, { 'l', 'L', '\0' }, { '/', '?', '\0' } }, { { 'a', 'A', 'm' }, { 'o', 'O', 'm' }, { - 'e', 'E', 'm' }, { 'u', 'U', 'm' }, { 'i', 'I', 'm' }, { 'd', 'D', 'm' }, { 'h', 'H', 'm' }, { 't', - 'T', 'm' }, { 'n', 'N', 'm' }, { 's', 'S', 'm' }, { '-', '_', 'm' } }, - - { { ';', ':', '\0' }, { 'q', 'Q', '\0' }, { 'j', 'J', '\0' }, { 'k', 'K', '\0' }, { 'x', 'X', '\0' }, { 'b', - 'B', '\0' }, { 'm', 'M', '\0' }, { 'w', 'W', '\0' }, { 'v', 'V', '\0' }, { 'z', 'Z', '\0' }, { '\0', - '\0', '\0' } } }; - memcpy(keys, thekeys, sizeof(thekeys)); - } - //QWETRZ// - if (mode == 2) - { - Key thekeys[4][11] = { { { '1', '!', '^', '' }, { '2', '"', '', '' }, { '3', '#', '', '' }, { '4', '$', - '', '' }, { '5', '%', '', '' }, { '6', '&', '', '' }, { '7', '/', '', '' }, { '8', '(', '[', - '' }, { '9', ')', ']', '' }, { '0', '=', '', '' }, { '', '?', '\'', '' } }, { { 'q', 'Q', '@', - '' }, { 'w', 'W', '\0', '' }, { 'e', 'E', '', '' }, { 'r', 'R', '\0', '' }, - { 't', 'T', '\0', '' }, { 'z', 'Z', '\0', '' }, { 'u', 'U', '\0', '' }, { 'i', 'I', '\0', '' }, { - 'o', 'O', '\0', '' }, { 'p', 'P', '\0', '' }, { '', '', '\0', '' } }, { { 'a', 'A', '\0', - '' }, { 's', 'S', '\0', '' }, { 'd', 'D', '\0', '' }, { 'f', 'F', '\0', '' }, - { 'g', 'G', '\0', '' }, { 'h', 'H', '\0', '' }, { 'j', 'J', '\0', '' }, { 'k', 'K', '\0', '' }, { - 'l', 'L', '\0', '' }, { '', '', '\0', '' }, { '', '', '\0', '' } }, { { '<', '>', '|', - '' }, { 'y', 'Y', '\0', '' }, { 'x', 'X', '\0', '' }, { 'c', 'C', '', '' }, - { 'v', 'V', '', '' }, { 'b', 'B', '\0', '' }, { 'n', 'N', '\0', '' }, { 'm', 'M', '', '' }, { - ',', ';', '\0', '' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } }; - memcpy(keys, thekeys, sizeof(thekeys)); - } - //AZERTY// - if (mode == 3) - { - Key thekeys[4][11] = { { { '1', '&', '', '' }, { '2', '~', '', '' }, { '3', '"', '#', '' }, { '4', '`', - '', '' }, { '5', '(', '[', '' }, { '6', '-', '|', '' }, { '7', '', '', '' }, { '8', '_', '\'', - '' }, { '9', '+', '^', '' }, { '0', '=', '@', '' }, { '', ')', ']', '' } }, { - { 'a', 'A', '', '' }, { 'z', 'Z', '', '' }, { 'e', 'E', '', '' }, { 'r', 'R', '', '' }, { 't', - 'T', '', '' }, { 'y', 'Y', '', '' }, { 'u', 'U', '', '' }, { 'i', 'I', '', '' }, { 'o', - 'O', '', '' }, { 'p', 'P', '', '' }, { '$', '', '', '' } }, { { 'q', 'Q', '', '' }, { - 's', 'S', '', '' }, { 'd', 'D', '\0', '' }, { 'f', 'F', '', '' }, { 'g', 'G', '\0', '' }, { 'h', - 'H', '\0', '' }, { 'j', 'J', '\0', '' }, { 'k', 'K', '\0', '' }, { 'l', 'L', '\0', '' }, { 'm', - 'M', '\0', '' }, { '*', '%', '', '' } }, { { '<', '>', '\0', '' }, { 'w', 'W', '\0', '' }, { 'x', - 'X', '\0', '' }, { 'c', 'C', '', '' }, { 'v', 'V', '', '' }, { 'b', 'B', '', '' }, { 'n', 'N', - '\0', '' }, { '?', ',', '?', '' }, { '.', ';', '.', '' }, { '/', ':', '/', '' }, { '', '!', '!', - '' } } }; - memcpy(keys, thekeys, sizeof(thekeys)); - } - //QWERTY 2// - if (mode == 4) - { - Key thekeys[4][11] = { { { '1', '!', '|', '' }, { '2', '"', '@', '' }, { '3', '', '#', '' }, { '4', '$', - '', '' }, { '5', '%', '~', '' }, { '6', '&', '', '' }, { '7', '/', '\'', '' }, { '8', '(', '[', - '' }, { '9', ')', ']', '' }, { '0', '=', '', '' }, { '', '?', '', '' } }, { { 'q', 'Q', '\0', - '' }, { 'w', 'W', '\0', '' }, { 'e', 'E', '', '' }, { 'r', 'R', '', '' }, { 't', 'T', '', '' }, - { 'y', 'Y', '', '' }, { 'u', 'U', '', '' }, { 'i', 'I', '', '' }, { 'o', 'O', '', '' }, { 'p', - 'P', '', '' }, { '+', '*', '\0', '' } }, { { 'a', 'A', '^', '' }, { 's', 'S', '', '' }, { - 'd', 'D', '', '' }, { 'f', 'F', '', '' }, { 'g', 'G', '', '' }, { 'h', 'H', '', '' }, { 'j', - 'J', '', '' }, { 'k', 'K', '', '' }, { 'l', 'L', '', '\0' }, { '', '', '+', '\0' }, { '', '', - '', '\0' } }, { { '<', '>', '\0', '' }, { 'z', 'Z', '\0', '' }, { 'x', 'X', '\0', '' }, { 'c', 'C', - '', '' }, { 'v', 'V', '\0', '' }, { 'b', 'B', '', '' }, { 'n', 'N', '\0', '' }, { 'm', 'M', '\0', - '' }, { ',', ';', '\0', '' }, { '.', ':', '\0', '\0' }, { '-', '_', '\0', '\0' } } }; - memcpy(keys, thekeys, sizeof(thekeys)); - } - - keyTextbox = new GuiImageData(keyboard_textbox_png, keyboard_textbox_png_size); - keyTextboxImg = new GuiImage(keyTextbox); - keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - keyTextboxImg->SetPosition(0, 40);//(0,0); - this->Append(keyTextboxImg); - - kbText = new GuiText(kbtextstr, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - kbText->SetPosition(0, 53);//(0, 13); - this->Append(kbText); - - key = new GuiImageData(keyboard_key_png, keyboard_key_png_size); - keyOver = new GuiImageData(keyboard_key_over_png, keyboard_key_over_png_size); - keyMedium = new GuiImageData(keyboard_mediumkey_over_png, keyboard_mediumkey_over_png_size); - keyMediumOver = new GuiImageData(keyboard_mediumkey_over_png, keyboard_mediumkey_over_png_size); - keyLarge = new GuiImageData(keyboard_largekey_over_png, keyboard_largekey_over_png_size); - keyLargeOver = new GuiImageData(keyboard_largekey_over_png, keyboard_largekey_over_png_size); - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigB = new GuiTrigger; - trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - int eurocheck = 0; - if (mode > 1) - { - eurocheck = -20; - } - - keyBackImg = new GuiImage(keyMedium); - keyBackOverImg = new GuiImage(keyMediumOver); - if (mode == 3) - { - keyBackText = new GuiText("Retour", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - } - else - { - keyBackText = new GuiText("Back", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - } - //keyBack = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); - keyBack = new GuiButton(keyBackImg, keyBackOverImg, 0, 3, 11 * 42 + 40 + eurocheck, 0 * 42 + 120, trigA, - btnSoundOver, btnSoundClick, 1); - //keyBack->SetImage(keyBackImg); - //keyBack->SetImageOver(keyBackOverImg); - keyBack->SetLabel(keyBackText); - //keyBack->SetSoundOver(btnSoundOver); - //keyBack->SetSoundClick(btnSoundClick); - //keyBack->SetTrigger(trigA); - keyBack->SetTrigger(trigB); - if (mode > 1) - { - keyBack->SetPosition(11 * 42 + 40 + eurocheck, 0 * 42 + 120); - } - else - { - keyBack->SetPosition(10 * 42 + 40 + eurocheck, 0 * 42 + 120); - }//(10*42+40, 0*42+80); - //keyBack->SetEffectGrow(); - this->Append(keyBack); - - keyClearImg = new GuiImage(keyMedium); - keyClearOverImg = new GuiImage(keyMediumOver); - if (mode == 3) - { - keyClearText = new GuiText("Effacer", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - } - else - { - keyClearText = new GuiText("Clear", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - } - keyClear = new GuiButton(keyClearImg, keyClearOverImg, 0, 3, (10 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA, - btnSoundOver, btnSoundClick, 1); - //keyClear = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); - //keyClear->SetImage(keyClearImg); - //keyClear->SetImageOver(keyClearOverImg); - keyClear->SetLabel(keyClearText); - //keyClear->SetSoundOver(btnSoundOver); - //keyClear->SetSoundClick(btnSoundClick); - //keyClear->SetTrigger(trigA); - //keyClear->SetPosition((10*42+40)+eurocheck, 4*42+120);//(10*42+40, 0*42+80); - //keyClear->SetEffectGrow(); - this->Append(keyClear); - - keyAltImg = new GuiImage(keyMedium); - keyAltOverImg = new GuiImage(keyMediumOver); - keyAltText = new GuiText("Alt Gr", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyAlt = new GuiButton(keyAltImg, keyAltOverImg, 0, 3, 84 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver, - btnSoundClick, 1); - //keyAlt = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); - //keyAlt->SetImage(keyAltImg); - //keyAlt->SetImageOver(keyAltOverImg); - keyAlt->SetLabel(keyAltText); - //keyAlt->SetSoundOver(btnSoundOver); - //keyAlt->SetSoundClick(btnSoundClick); - //keyAlt->SetTrigger(trigA); - //keyAlt->SetPosition(84+eurocheck, 4*42+120);//(10*42+40, 4*42+120); - //keyAlt->SetEffectGrow(); - if (mode > 1) - { - this->Append(keyAlt); - } - - keyAlt2Img = new GuiImage(keyMedium); - keyAlt2OverImg = new GuiImage(keyMediumOver); - keyAlt2Text = new GuiText("Accent", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyAlt2 = new GuiButton(keyAlt2Img, keyAlt2OverImg, 0, 3, (8 * 42 + 40) + eurocheck, 4 * 42 + 120, trigA, - btnSoundOver, btnSoundClick, 1); - //keyAlt2 = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); - //keyAlt2->SetImage(keyAlt2Img); - //keyAlt2->SetImageOver(keyAlt2OverImg); - keyAlt2->SetLabel(keyAlt2Text); - //keyAlt2->SetSoundOver(btnSoundOver); - //keyAlt2->SetSoundClick(btnSoundClick); - //keyAlt2->SetTrigger(trigA); - //keyAlt2->SetPosition((8*42+40)+eurocheck, 4*42+120);//(10*42+40, 4*42+120); - //keyAlt2->SetEffectGrow(); - if (mode > 1) - { - this->Append(keyAlt2); - } - - keyCapsImg = new GuiImage(keyMedium); - keyCapsOverImg = new GuiImage(keyMediumOver); - keyCapsText = new GuiText("Caps", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyCaps = new GuiButton(keyCapsImg, keyCapsOverImg, 0, 3, 0 + eurocheck, 2 * 42 + 120, trigA, btnSoundOver, - btnSoundClick, 1); - //keyCaps = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); - //keyCaps->SetImage(keyCapsImg); - //keyCaps->SetImageOver(keyCapsOverImg); - keyCaps->SetLabel(keyCapsText); - //keyCaps->SetSoundOver(btnSoundOver); - //keyCaps->SetSoundClick(btnSoundClick); - //keyCaps->SetTrigger(trigA); - //keyCaps->SetPosition(0+eurocheck, 2*42+120);//(0, 2*42+80); - //keyCaps->SetEffectGrow(); - this->Append(keyCaps); - - keyShiftImg = new GuiImage(keyMedium); - keyShiftOverImg = new GuiImage(keyMediumOver); - keyShiftText = new GuiText("Shift", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyShift = new GuiButton(keyShiftImg, keyShiftOverImg, 0, 3, 21 + eurocheck, 3 * 42 + 120, trigA, btnSoundOver, - btnSoundClick, 1); - //keyShift = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); - //keyShift->SetImage(keyShiftImg); - //keyShift->SetImageOver(keyShiftOverImg); - keyShift->SetLabel(keyShiftText); - //keyShift->SetSoundOver(btnSoundOver); - //keyShift->SetSoundClick(btnSoundClick); - //keyShift->SetTrigger(trigA); - //keyShift->SetPosition(21+eurocheck, 3*42+120);//(21, 3*42+80); - //keyShift->SetEffectGrow(); - this->Append(keyShift); - - keySpaceImg = new GuiImage(keyLarge); - keySpaceOverImg = new GuiImage(keyLargeOver); - keySpace = new GuiButton(keySpaceImg, keySpaceOverImg, 2, 3, 0 + eurocheck, 4 * 42 + 120, trigA, btnSoundOver, - btnSoundClick, 1); - //keySpace = new GuiButton(keyLarge->GetWidth(), keyLarge->GetHeight()); - //keySpace->SetImage(keySpaceImg); - //keySpace->SetImageOver(keySpaceOverImg); - //keySpace->SetSoundOver(btnSoundOver); - //keySpace->SetSoundClick(btnSoundClick); - //keySpace->SetTrigger(trigA); - //keySpace->SetPosition(0+eurocheck, 4*42+120);//(0, 4*42+80); - //keySpace->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - //keySpace->SetEffectGrow(); - this->Append(keySpace); - - char txt[2] = { 0, 0 }; - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 11; j++) - { - if (keys[i][j].ch != '\0') - { - keyImg[i][j] = new GuiImage(key); - keyImgOver[i][j] = new GuiImage(keyOver); - txt[0] = keys[i][j].ch; - keyTxt[i][j] = new GuiText(txt, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - keyTxt[i][j]->SetPosition(0, -10); - keyBtn[i][j] = new GuiButton(keyImg[i][j], keyImgOver[i][j], 0, 3, (j * 42 + 21 * i + 40) + eurocheck, - i * 42 + 120, trigA, btnSoundOver, btnSoundClick, 1); - //keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight()); - //keyBtn[i][j]->SetImage(keyImg[i][j]); - //keyBtn[i][j]->SetImageOver(keyImgOver[i][j]); - //keyBtn[i][j]->SetSoundOver(btnSoundOver); - //keyBtn[i][j]->SetSoundClick(btnSoundClick); - //keyBtn[i][j]->SetTrigger(trigA); - keyBtn[i][j]->SetLabel(keyTxt[i][j]); - //keyBtn[i][j]->SetPosition((j*42+21*i+40)+eurocheck, i*42+120);//SetPosition(j*42+21*i+40, i*42+80); - //keyBtn[i][j]->SetEffectGrow(); - this->Append(keyBtn[i][j]); - } - } - } -} - -/** - * Destructor for the GuiKeyboard class. - */ -GuiKeyboard::~GuiKeyboard() -{ - delete kbText; - delete keyTextbox; - delete keyTextboxImg; - delete keyCapsText; - delete keyCapsImg; - delete keyCapsOverImg; - delete keyCaps; - delete keyShiftText; - delete keyShiftImg; - delete keyShiftOverImg; - delete keyShift; - if (keyAlt) - { - delete keyAlt; - } - if (keyAlt2) - { - delete keyAlt2; - } - delete keyBackText; - delete keyBackImg; - delete keyBackOverImg; - delete keyBack; - delete keySpaceImg; - delete keySpaceOverImg; - delete keySpace; - delete key; - delete keyOver; - delete keyMedium; - delete keyMediumOver; - delete keyLarge; - delete keyLargeOver; - delete trigA; - delete trigB; - - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 11; j++) - { - if (keys[i][j].ch != '\0') - { - delete keyImg[i][j]; - delete keyImgOver[i][j]; - delete keyTxt[i][j]; - delete keyBtn[i][j]; - } - } - } -} - -void GuiKeyboard::Update(GuiTrigger * t) -{ - LOCK( this ); - if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->Update(t); - } - catch (const std::exception& e) - { - } - } - - bool changedShiftKey = false; - - if (keySpace->GetState() == STATE_CLICKED) - { - if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with terminating '\0' - { - kbtextstr[strlen(kbtextstr)] = ' '; - kbText->SetText(kbtextstr); - } - keySpace->SetState(STATE_SELECTED, t->chan); - } - else if (keyBack->GetState() == STATE_CLICKED) - { - if (strlen(kbtextstr) > (m)) - { - kbtextstr[strlen(kbtextstr) - 1] = 0; - kbText->SetText(kbtextstr); - } - keyBack->SetState(STATE_SELECTED, t->chan); - } - else if (keyClear->GetState() == STATE_CLICKED) - { - while (strlen(kbtextstr) > (m)) - { - kbtextstr[strlen(kbtextstr) - 1] = 0; - kbText->SetText(kbtextstr); - } - keyClear->SetState(STATE_SELECTED, t->chan); - } - else if (keyShift->GetState() == STATE_CLICKED) - { - changedShiftKey = true; - shift ^= 1; - if (alt) alt ^= 1; - if (alt2) alt2 ^= 1; - keyShift->SetState(STATE_SELECTED, t->chan); - } - else if (keyAlt->GetState() == STATE_CLICKED) - { - changedShiftKey = true; - alt ^= 1; - if (shift) shift ^= 1; - if (alt2) alt2 ^= 1; - keyAlt->SetState(STATE_SELECTED, t->chan); - } - else if (keyAlt2->GetState() == STATE_CLICKED) - { - changedShiftKey = true; - alt2 ^= 1; - if (shift) shift ^= 1; - if (alt) alt ^= 1; - keyAlt2->SetState(STATE_SELECTED, t->chan); - } - else if (keyCaps->GetState() == STATE_CLICKED) - { - changedShiftKey = true; - caps ^= 1; - keyCaps->SetState(STATE_SELECTED, t->chan); - } - - bool update = false; - - char txt[2] = { 0, 0 }; - - do - { - update = false; - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 11; j++) - { - if (keys[i][j].ch != '\0') - { - if (shift || caps) - txt[0] = keys[i][j].chShift; - else if (alt) - txt[0] = keys[i][j].chalt; - else if (alt2) - txt[0] = keys[i][j].chalt2; - else txt[0] = keys[i][j].ch; - - if (changedShiftKey) // change text only if needed - keyTxt[i][j]->SetText(txt); - - if (keyBtn[i][j]->GetState() == STATE_CLICKED) - { - if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0' - { - kbtextstr[strlen(kbtextstr)] = txt[0]; - kbText->SetText(kbtextstr); - } - keyBtn[i][j]->SetState(STATE_SELECTED, t->chan); - - if (shift || alt || alt2) - { - if (shift) shift ^= 1; - if (alt) alt ^= 1; - if (alt2) alt2 ^= 1; - update = true; - changedShiftKey = true; - } - } - } - } - } - } while (update); - - kbText->SetPosition(0, 53); - - this->ToggleFocus(t); - - if (focus) // only send actions to this window if it's in focus - { - // pad/joystick navigation - if (t->Right()) - this->MoveSelectionHor(1); - else if (t->Left()) - this->MoveSelectionHor(-1); - else if (t->Down()) - this->MoveSelectionVert(1); - else if (t->Up()) this->MoveSelectionVert(-1); - } -} diff --git a/source/libwiigui/gui_numpad.cpp b/source/libwiigui/gui_numpad.cpp deleted file mode 100644 index 5e770305..00000000 --- a/source/libwiigui/gui_numpad.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/**************************************************************************** - * USB Loader GX - * - * r-win 2009 - * - * gui_numpad.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "../main.h" -#include "../settings/CSettings.h" -#include -#include -/** - * Constructor for the GuiNumpad class. - */ - -#define SAFEFREE(p) if(p){free(p);p=NULL;} - -GuiNumpad::GuiNumpad(char * t, u32 max) -{ - width = 400; - height = 370; - selectable = true; - focus = 0; // allow focus - alignmentHor = ALIGN_CENTRE; - alignmentVert = ALIGN_MIDDLE; - kbtextmaxlen = max > sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr) - // strlcpy(kbtextstr, t, kbtextmaxlen); - strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0 - kbtextstr[sizeof(kbtextstr) - 1] = 0; // terminate with \0 - - char thekeys[11] = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '\0', '0' }; - memcpy(keys, thekeys, sizeof(thekeys)); - - keyTextbox = new GuiImageData(keyboard_textbox_png, keyboard_textbox_png_size); - keyTextboxImg = new GuiImage(keyTextbox); - keyTextboxImg->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - keyTextboxImg->SetPosition(0, 40);//(0,0); - this->Append(keyTextboxImg); - - kbText = new GuiText(kbtextstr, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - kbText->SetPosition(0, 53);//(0, 13); - kbText->SetPassChar('*'); - this->Append(kbText); - - keyMedium = new GuiImageData(keyboard_mediumkey_over_png, keyboard_mediumkey_over_png_size); - keyMediumOver = new GuiImageData(keyboard_mediumkey_over_png, keyboard_mediumkey_over_png_size); - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigB = new GuiTrigger; - trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - keyBackImg = new GuiImage(keyMedium); - keyBackOverImg = new GuiImage(keyMediumOver); - keyBackText = new GuiText("Back", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - - keyBack = new GuiButton(keyBackImg, keyBackOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, 90, 80, trigA, btnSoundOver, btnSoundClick, 1); - keyBack->SetLabel(keyBackText); - keyBack->SetTrigger(trigB); - this->Append(keyBack); - - keyClearImg = new GuiImage(keyMedium); - keyClearOverImg = new GuiImage(keyMediumOver); - keyClearText = new GuiText("Clear", 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyClear = new GuiButton(keyClearImg, keyClearOverImg, ALIGN_CENTRE, ALIGN_MIDDLE, -90, 80, trigA, btnSoundOver, btnSoundClick, 1); - keyClear->SetLabel(keyClearText); - this->Append(keyClear); - - char txt[2] = { 0, 0 }; - for (int i = 0; i < 11; i++) - { - if (keys[i] != '\0') - { - int col = i % 3; - int row = i / 3; - - keyImg[i] = new GuiImage(keyMedium); - keyImgOver[i] = new GuiImage(keyMediumOver); - txt[0] = keys[i]; - keyTxt[i] = new GuiText(txt, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - keyTxt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - keyTxt[i]->SetPosition(0, -10); - keyBtn[i] = new GuiButton(keyImg[i], keyImgOver[i], ALIGN_CENTRE, ALIGN_MIDDLE, -90 + 90 * col, -70 + 50 - * row, trigA, btnSoundOver, btnSoundClick, 1); - keyBtn[i]->SetLabel(keyTxt[i]); - - this->Append(keyBtn[i]); - } - } -} - -/** - * Destructor for the GuiKeyboard class. - */ -GuiNumpad::~GuiNumpad() -{ - SAFEFREE( kbText ) - SAFEFREE( keyTextbox ) - SAFEFREE( keyTextboxImg ) - SAFEFREE( keyBackText ) - SAFEFREE( keyBackImg ) - SAFEFREE( keyBackOverImg ) - SAFEFREE( keyBack ) - SAFEFREE( keyClear ) - SAFEFREE( keyClearImg ) - SAFEFREE( keyClearOverImg ) - SAFEFREE( keyClearText ) - SAFEFREE( keyMedium ) - SAFEFREE( keyMediumOver ) - SAFEFREE( trigA ) - SAFEFREE( trigB ) - - for (int i = 0; i < 11; i++) - { - if (keys[i] != '\0') - { - SAFEFREE( keyImg[i] ) - SAFEFREE( keyImgOver[i] ) - SAFEFREE( keyTxt[i] ) - SAFEFREE( keyBtn[i] ) - } - } -} - -void GuiNumpad::Update(GuiTrigger * t) -{ - LOCK( this ); - if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->Update(t); - } - catch (const std::exception& e) - { - } - } - - if (keyBack->GetState() == STATE_CLICKED) - { - if (strlen(kbtextstr) > 0) - { - kbtextstr[strlen(kbtextstr) - 1] = 0; - kbText->SetText(kbtextstr); - } - keyBack->SetState(STATE_SELECTED, t->chan); - } - else if (keyClear->GetState() == STATE_CLICKED) - { - memset(kbtextstr, 0, sizeof(kbtextstr)); - kbText->SetText(kbtextstr); - keyClear->SetState(STATE_SELECTED, t->chan); - } - - char txt[2] = { 0, 0 }; - for (int i = 0; i < 11; i++) - { - if (keys[i] != '\0') - { - if (keyBtn[i]->GetState() == STATE_CLICKED) - { - txt[0] = keys[i]; - if (strlen(kbtextstr) < kbtextmaxlen - 1) // -1 --> kbtextmaxlen means with term. '\0' - { - kbtextstr[strlen(kbtextstr)] = txt[0]; - kbText->SetText(kbtextstr); - } - keyBtn[i]->SetState(STATE_SELECTED, t->chan); - } - } - } - - kbText->SetPosition(0, 53); - - this->ToggleFocus(t); - - if (focus) // only send actions to this window if it's in focus - { - // pad/joystick navigation - if (t->Right()) - this->MoveSelectionHor(1); - else if (t->Left()) - this->MoveSelectionHor(-1); - else if (t->Down()) - this->MoveSelectionVert(1); - else if (t->Up()) this->MoveSelectionVert(-1); - } -} diff --git a/source/libwiigui/gui_optionbrowser.cpp b/source/libwiigui/gui_optionbrowser.cpp deleted file mode 100644 index 32086efb..00000000 --- a/source/libwiigui/gui_optionbrowser.cpp +++ /dev/null @@ -1,666 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_optionbrowser.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "../wpad.h" -#include "settings/CSettings.h" -#include "themes/CTheme.h" - -#include - -#define GAMESELECTSIZE 30 - -static int scrollbaron = 0, startat = 0, loaded = 0; -/** - * Constructor for the GuiOptionBrowser class. - */ -GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char *imagebg, int scrollon) -{ - width = w; - height = h; - options = l; - scrollbaron = scrollon; - selectable = true; - listOffset = this->FindMenuItem(-1, 1); - listChanged = true; // trigger an initial list update - selectedItem = 0; - focus = 1; // allow focus - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigHeldA = new GuiTrigger; - trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A); - - bgOptions = Resources::GetImageData(imagebg); - bgOptionsImg = new GuiImage(bgOptions); - bgOptionsImg->SetParent(this); - bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - bgOptionsEntry = Resources::GetImageData("bg_options_entry.png"); - if (scrollbaron == 1) - { - scrollbar = Resources::GetImageData("scrollbar.png"); - scrollbarImg = new GuiImage(scrollbar); - scrollbarImg->SetParent(this); - scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarImg->SetPosition(0, 4); - - arrowDown = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownImg = new GuiImage(arrowDown); - arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownOverImg = new GuiImage(arrowDownOver); - arrowUp = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpImg = new GuiImage(arrowUp); - arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpOverImg = new GuiImage(arrowUpOver); - scrollbarBox = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxImg = new GuiImage(scrollbarBox); - scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver); - - arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); - arrowUpBtn->SetParent(this); - arrowUpBtn->SetImage(arrowUpImg); - arrowUpBtn->SetImageOver(arrowUpOverImg); - arrowUpBtn->SetImageHold(arrowUpOverImg); - arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - arrowUpBtn->SetPosition(width / 2 - 18 + 7, -18); - arrowUpBtn->SetSelectable(false); - arrowUpBtn->SetTrigger(trigA); - arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowUpBtn->SetSoundClick(btnSoundClick); - - arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight()); - arrowDownBtn->SetParent(this); - arrowDownBtn->SetImage(arrowDownImg); - arrowDownBtn->SetImageOver(arrowDownOverImg); - arrowDownBtn->SetImageHold(arrowDownOverImg); - arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - arrowDownBtn->SetPosition(width / 2 - 18 + 7, 18); - arrowDownBtn->SetSelectable(false); - arrowDownBtn->SetTrigger(trigA); - arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowDownBtn->SetSoundClick(btnSoundClick); - - scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight()); - scrollbarBoxBtn->SetParent(this); - scrollbarBoxBtn->SetImage(scrollbarBoxImg); - scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg); - scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg); - scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - scrollbarBoxBtn->SetSelectable(false); - scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120); - scrollbarBoxBtn->SetMinY(0); - scrollbarBoxBtn->SetMaxY(height); - scrollbarBoxBtn->SetHoldable(true); - scrollbarBoxBtn->SetTrigger(trigHeldA); - } - - // optionBg = new GuiImage(bgOptionsEntry); - for (int i = 0; i < PAGESIZE; i++) - { - optionTxt[i] = new GuiText((char *) NULL, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - optionTxt[i]->SetPosition(24, 0); - - optionBg[i] = new GuiImage(bgOptionsEntry); - - optionVal[i] = new GuiText((char *) NULL, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - optionVal[i]->SetPosition(250, 0); - - optionBtn[i] = new GuiButton(width - 28, GAMESELECTSIZE); - optionBtn[i]->SetParent(this); - optionBtn[i]->SetLabel(optionTxt[i], 0); - optionBtn[i]->SetLabel(optionVal[i], 1); - optionBtn[i]->SetImageOver(optionBg[i]); - optionBtn[i]->SetPosition(5, GAMESELECTSIZE * i + 4); - optionBtn[i]->SetRumble(false); - optionBtn[i]->SetTrigger(trigA); - optionBtn[i]->SetSoundClick(btnSoundClick); - } -} - -/** - * Constructor for the GuiOptionBrowser class. - */ -GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char *imagebg, int scrollon, int start) -{ - width = w; - height = h; - options = l; - startat = start; - loaded = 0; - scrollbaron = scrollon; - selectable = true; - listOffset = this->FindMenuItem(-1, 1); - selectedItem = 0; - focus = 1; // allow focus - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigHeldA = new GuiTrigger; - trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A); - - bgOptions = Resources::GetImageData(imagebg); - - bgOptionsImg = new GuiImage(bgOptions); - bgOptionsImg->SetParent(this); - bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - - bgOptionsEntry = Resources::GetImageData("bg_options_entry.png"); - if (scrollbaron == 1) - { - scrollbar = Resources::GetImageData("scrollbar.png"); - scrollbarImg = new GuiImage(scrollbar); - scrollbarImg->SetParent(this); - scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarImg->SetPosition(0, 4); - - arrowDown = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownImg = new GuiImage(arrowDown); - arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png"); - arrowDownOverImg = new GuiImage(arrowDownOver); - arrowUp = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpImg = new GuiImage(arrowUp); - arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png"); - arrowUpOverImg = new GuiImage(arrowUpOver); - scrollbarBox = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxImg = new GuiImage(scrollbarBox); - scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png"); - scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver); - - arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight()); - arrowUpBtn->SetParent(this); - arrowUpBtn->SetImage(arrowUpImg); - arrowUpBtn->SetImageOver(arrowUpOverImg); - arrowUpBtn->SetImageHold(arrowUpOverImg); - arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - arrowUpBtn->SetPosition(width / 2 - 18 + 7, -18); - arrowUpBtn->SetSelectable(false); - arrowUpBtn->SetTrigger(trigA); - arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowUpBtn->SetSoundClick(btnSoundClick); - - arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight()); - arrowDownBtn->SetParent(this); - arrowDownBtn->SetImage(arrowDownImg); - arrowDownBtn->SetImageOver(arrowDownOverImg); - arrowDownBtn->SetImageHold(arrowDownOverImg); - arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - arrowDownBtn->SetPosition(width / 2 - 18 + 7, 18); - arrowDownBtn->SetSelectable(false); - arrowDownBtn->SetTrigger(trigA); - arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowDownBtn->SetSoundClick(btnSoundClick); - - scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight()); - scrollbarBoxBtn->SetParent(this); - scrollbarBoxBtn->SetImage(scrollbarBoxImg); - scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg); - scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg); - scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - scrollbarBoxBtn->SetSelectable(false); - scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120); - scrollbarBoxBtn->SetMinY(0); - scrollbarBoxBtn->SetMaxY(height - 30); - scrollbarBoxBtn->SetHoldable(true); - scrollbarBoxBtn->SetTrigger(trigHeldA); - } - - // optionBg = new GuiImage(bgOptionsEntry); - for (int i = 0; i < PAGESIZE; i++) - { - optionTxt[i] = new GuiText(options->GetName(i), 20, ( GXColor ) {0, 0, 0, 0xff}); - optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - optionTxt[i]->SetPosition(24, 0); - - optionBg[i] = new GuiImage(bgOptionsEntry); - - optionVal[i] = new GuiText((char *) NULL, 20, ( GXColor ) - { 0, 0, 0, 0xff}); - optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - optionVal[i]->SetPosition(250, 0); - - optionBtn[i] = new GuiButton(width - 28, GAMESELECTSIZE); - optionBtn[i]->SetParent(this); - optionBtn[i]->SetLabel(optionTxt[i], 0); - optionBtn[i]->SetLabel(optionVal[i], 1); - optionBtn[i]->SetImageOver(optionBg[i]); - optionBtn[i]->SetPosition(5, GAMESELECTSIZE * i + 4); - optionBtn[i]->SetTrigger(trigA); - optionBtn[i]->SetSoundClick(btnSoundClick); - } -} - -/** - * Destructor for the GuiOptionBrowser class. - */ -GuiOptionBrowser::~GuiOptionBrowser() -{ - if (scrollbaron == 1) - { - delete arrowUpBtn; - delete arrowDownBtn; - delete scrollbarBoxBtn; - delete scrollbarImg; - delete arrowDownImg; - delete arrowDownOverImg; - delete arrowUpImg; - delete arrowUpOverImg; - delete scrollbarBoxImg; - delete scrollbarBoxOverImg; - delete scrollbar; - delete arrowDown; - delete arrowDownOver; - delete arrowUp; - delete arrowUpOver; - delete scrollbarBox; - delete scrollbarBoxOver; - } - delete bgOptionsImg; - delete bgOptions; - delete bgOptionsEntry; - loaded = 0; - - delete trigA; - - // delete optionBg; - for (int i = 0; i < PAGESIZE; i++) - { - delete optionTxt[i]; - delete optionVal[i]; - delete optionBg[i]; - delete optionBtn[i]; - } -} - -void GuiOptionBrowser::SetCol2Position(int x) -{ - LOCK( this ); - for (int i = 0; i < PAGESIZE; i++) - optionVal[i]->SetPosition(x, 0); -} - -void GuiOptionBrowser::SetFocus(int f) -{ - LOCK( this ); - focus = f; - - for (int i = 0; i < PAGESIZE; i++) - optionBtn[i]->ResetState(); - - if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED); -} - -void GuiOptionBrowser::ResetState() -{ - LOCK( this ); - if (state != STATE_DISABLED) - { - state = STATE_DEFAULT; - stateChan = -1; - } - - for (int i = 0; i < PAGESIZE; i++) - { - optionBtn[i]->ResetState(); - } -} - -int GuiOptionBrowser::GetClickedOption() -{ - int found = -1; - for (int i = 0; i < PAGESIZE; i++) - { - if (optionBtn[i]->GetState() == STATE_CLICKED) - { - optionBtn[i]->SetState(STATE_SELECTED); - found = optionIndex[i]; - break; - } - } - return found; -} - -int GuiOptionBrowser::GetSelectedOption() -{ - int found = -1; - for (int i = 0; i < PAGESIZE; i++) - { - if (optionBtn[i]->GetState() == STATE_SELECTED) - { - optionBtn[i]->SetState(STATE_SELECTED); - found = optionIndex[i]; - break; - } - } - return found; -} - -/**************************************************************************** - * FindMenuItem - * - * Help function to find the next visible menu item on the list - ***************************************************************************/ - -int GuiOptionBrowser::FindMenuItem(int currentItem, int direction) -{ - int nextItem = currentItem + direction; - - if (nextItem < 0 || nextItem >= options->GetLength()) return -1; - - if (options->GetName(nextItem) && strlen(options->GetName(nextItem)) > 0) - return nextItem; - else - return FindMenuItem(nextItem, direction); -} - -/** - * Draw the button on screen - */ -void GuiOptionBrowser::Draw() -{ - LOCK( this ); - if (!this->IsVisible()) return; - - bgOptionsImg->Draw(); - - int next = listOffset; - - for (int i = 0; i < PAGESIZE; i++) - { - if (next >= 0) - { - optionBtn[i]->Draw(); - next = this->FindMenuItem(next, 1); - } - else break; - } - - if (scrollbaron == 1) - { - scrollbarImg->Draw(); - arrowUpBtn->Draw(); - arrowDownBtn->Draw(); - scrollbarBoxBtn->Draw(); - } - this->UpdateEffects(); -} - -void GuiOptionBrowser::TriggerUpdate() -{ - listChanged = true; -} - -void GuiOptionBrowser::Update(GuiTrigger * t) -{ - LOCK( this ); - int next, prev, lang = options->GetLength(); - - //go to the last game selected - if ((loaded == 0) && (startat > 0)) - { - - if (startat > (lang - 9)) - { - listOffset = (lang - 9); - selectedItem = startat; - optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan); - } - else if (startat < 9) - { - selectedItem = startat; - optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan); - } - else if(startat < PAGESIZE) - { - listOffset = (startat - 4); - selectedItem = startat; - optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan); - } - this->SetFocus(1); - loaded = 1; - } - - if (state == STATE_DISABLED || !t) return; - - // scrolldelay affects how fast the list scrolls - // when the arrows are clicked - float scrolldelay = 3.5; - - if (scrollbaron == 1) - { - // update the location of the scroll box based on the position in the option list - - - arrowUpBtn->Update(t); - arrowDownBtn->Update(t); - scrollbarBoxBtn->Update(t); - } - next = listOffset; - - if (listChanged) - { - for (int i = 0; i < PAGESIZE; i++) - { - if (next >= 0) - { - if (optionBtn[i]->GetState() == STATE_DISABLED) - { - optionBtn[i]->SetVisible(true); - optionBtn[i]->SetState(STATE_DEFAULT); - } - - optionTxt[i]->SetText(options->GetName(next)); - optionVal[i]->SetText(options->GetValue(next)); - optionIndex[i] = next; - next = this->FindMenuItem(next, 1); - } - else - { - optionBtn[i]->SetVisible(false); - optionBtn[i]->SetState(STATE_DISABLED); - } - } - } - for (int i = 0; i < PAGESIZE; i++) - { - if (focus) - { - if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED) - optionBtn[i]->ResetState(); - else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT) optionBtn[selectedItem]->SetState( - STATE_SELECTED, t->chan); - } - - optionBtn[i]->Update(t); - - if (optionBtn[i]->GetState() == STATE_SELECTED) - { - selectedItem = i; - } - } - - // pad/joystick navigation - if (!focus) return; // skip navigation - - if (scrollbaron == 1) - { - - if (t->Down() || arrowDownBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////down - arrowDownBtn->GetState() == STATE_HELD) - { - - next = this->FindMenuItem(optionIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == PAGESIZE - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - } - else if (optionBtn[selectedItem + 1]->IsVisible()) - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - scrollbarBoxBtn->Draw(); - usleep(10000 * scrolldelay); - - } - WPAD_ScanPads(); - u8 cnt, buttons = 0; - /* Get pressed buttons */ - for (cnt = 0; cnt < 4; cnt++) - buttons |= WPAD_ButtonsHeld(cnt); - if (buttons == WPAD_BUTTON_A) - { - - } - else - { - arrowDownBtn->ResetState(); - - } - - } - else if (t->Up() || arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up - arrowUpBtn->GetState() == STATE_HELD) - { - prev = this->FindMenuItem(optionIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - } - else - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - scrollbarBoxBtn->Draw(); - usleep(10000 * scrolldelay); - - } - WPAD_ScanPads(); - u8 cnt, buttons = 0; - /* Get pressed buttons */ - for (cnt = 0; cnt < 4; cnt++) - buttons |= WPAD_ButtonsHeld(cnt); - if (buttons == WPAD_BUTTON_A) - { - - } - else - { - arrowUpBtn->ResetState(); - - } - } - - if (scrollbarBoxBtn->GetState() == STATE_HELD && scrollbarBoxBtn->GetStateChan() == t->chan && t->wpad.ir.valid - && options->GetLength() > PAGESIZE) - { - scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, 0); - int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop(); - - listOffset = (position * lang) / 180 - selectedItem; - - if (listOffset <= 0) - { - listOffset = 0; - selectedItem = 0; - } - else if (listOffset + PAGESIZE >= lang) - { - listOffset = lang - PAGESIZE; - selectedItem = PAGESIZE - 1; - } - - } - int positionbar = 237 * (listOffset + selectedItem) / lang; - - if (positionbar > 216) positionbar = 216; - scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, positionbar + 8); - - if (t->Right()) - { - if (listOffset < lang && lang > PAGESIZE) - { - listOffset = listOffset + PAGESIZE; - if (listOffset + PAGESIZE >= lang) listOffset = lang - PAGESIZE; - } - } - else if (t->Left()) - { - if (listOffset > 0) - { - listOffset = listOffset - PAGESIZE; - if (listOffset < 0) listOffset = 0; - } - } - - } - else - { - - if (t->Down()) - { - next = this->FindMenuItem(optionIndex[selectedItem], 1); - - if (next >= 0) - { - if (selectedItem == PAGESIZE - 1) - { - // move list down by 1 - listOffset = this->FindMenuItem(listOffset, 1); - listChanged = true; - } - else if (optionBtn[selectedItem + 1]->IsVisible()) - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan); - selectedItem++; - } - } - } - else if (t->Up()) - { - prev = this->FindMenuItem(optionIndex[selectedItem], -1); - - if (prev >= 0) - { - if (selectedItem == 0) - { - // move list up by 1 - listOffset = prev; - listChanged = true; - } - else - { - optionBtn[selectedItem]->ResetState(); - optionBtn[selectedItem - 1]->SetState(STATE_SELECTED, t->chan); - selectedItem--; - } - } - } - } - - if (updateCB) updateCB(this); -} diff --git a/source/libwiigui/gui_searchbar.cpp b/source/libwiigui/gui_searchbar.cpp deleted file mode 100644 index 0f17ac26..00000000 --- a/source/libwiigui/gui_searchbar.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include "gui.h" -#include "gui_searchbar.h" - -#include "../wpad.h" -#include "../main.h" -#include "../settings/CSettings.h" -#include "../themes/CTheme.h" -#include "../usbloader/GameList.h" - -extern GuiWindow * mainWindow; - -class cSearchButton -{ - public: - cSearchButton(wchar_t *Char, GuiImageData *keyImageData, GuiImageData *keyOverImageData, int x, int y, - GuiTrigger* trig, GuiSound* sndOver, GuiSound* sndClick) : - wchar(*Char), image(keyImageData), imageOver(keyOverImageData), text((char *) NULL, 20, ( GXColor ) - { 0, 0, 0, 0xff}), button(&image, &imageOver, ALIGN_LEFT, ALIGN_TOP, x, y, trig, sndOver, sndClick, 1) - { - text.SetText(Char); - button.SetLabel(&text); - } - wchar_t wchar; - GuiImage image; - GuiImage imageOver; - GuiText text; - GuiButton button; - private: - -}; - -GuiSearchBar::GuiSearchBar(const wchar_t *SearchChars) : - inSide(0), text((char *) NULL, 22, ( GXColor ) - { 0, 0, 0, 255}), buttons(0), keyImageData(keyboard_key_png, keyboard_key_png_size), keyOverImageData(keyboard_key_over_png, keyboard_key_over_png_size) -{ - trig.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - - cnt = wcslen(SearchChars); - buttons = new cSearchButton*[cnt]; - - wchar_t charstr[2] = { 0, 0 }; - int lines = (cnt + 9) / 10; - int buttonsPerLine = (cnt + lines - 1) / lines; - width = 10 + buttonsPerLine * 42 + 10; - int x_start = 10, x = 0, y_start = 10 + 42, y = 0; - if (width < 200) - { - x_start += (200 - width) >> 1; - width = 200; - } - for (int i = 0; i < cnt; i++, x++) - { - if (x >= buttonsPerLine) x = 0; - if (x == 0) y++; - charstr[0] = SearchChars[i]; - buttons[i] = new cSearchButton(charstr, &keyImageData, &keyOverImageData, x_start + x * 42, y_start - 42 + y - * 42, &trig, btnSoundOver, btnSoundClick); - this->Append(&(buttons[i]->button)); - } - height = 10 + 42 + y * 42 + 10; - - text.SetText(gameList.GetCurrentFilter()); - text.SetPosition(10, 15); - text.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - text.SetWidescreen(Settings.widescreen); - text.SetMaxWidth(width - (10 + 2 * 42 + 10), SCROLL_HORIZONTAL); - this->Append(&text); - - imgBacspaceBtn = Resources::GetImageData("keyboard_backspace_over.png"); - BacspaceBtnImg_Over = new GuiImage(imgBacspaceBtn); - BacspaceBtnImg = new GuiImage(BacspaceBtnImg_Over); - BacspaceBtnImg->SetGrayscale(); - BacspaceBtn = new GuiButton(BacspaceBtnImg, BacspaceBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -52, 10, &trig, btnSoundOver, btnSoundClick, 1); - this->Append(BacspaceBtn); - - imgClearBtn = Resources::GetImageData("keyboard_clear_over.png"); - ClearBtnImg_Over = new GuiImage(imgClearBtn); - ClearBtnImg = new GuiImage(ClearBtnImg_Over); - ClearBtnImg->SetGrayscale(); - ClearBtn = new GuiButton(ClearBtnImg, ClearBtnImg_Over, ALIGN_RIGHT, ALIGN_TOP, -10, 10, &trig, btnSoundOver, btnSoundClick, 1); - this->Append(ClearBtn); - - // SetPosition(100,100); - -} -GuiSearchBar::~GuiSearchBar() -{ - if (buttons) - { - for (int i = 0; i < cnt; i++) - delete buttons[i]; - delete[] buttons; - } - delete ClearBtn; - delete ClearBtnImg; - delete ClearBtnImg_Over; - delete imgClearBtn; - - delete BacspaceBtn; - delete BacspaceBtnImg; - delete BacspaceBtnImg_Over; - delete imgBacspaceBtn; - if (inSide) mainWindow->SetState(STATE_DEFAULT); -} -void GuiSearchBar::Draw() -{ - Menu_DrawRectangle(this->GetLeft(), this->GetTop(), width, height, ( GXColor ) - { 0, 0, 0, 0xa0}, 1); - Menu_DrawRectangle(this->GetLeft() + 10, this->GetTop() + 15, width - (10 + 2 * 42 + 10), 22, ( GXColor ) - { 255, 255, 255, 255}, 1); - GuiWindow::Draw(); -} -void GuiSearchBar::Update(GuiTrigger * t) -{ - LOCK( this ); - if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return; - // cursor - if (t->wpad.ir.valid && state != STATE_DISABLED) - { - if (this->IsInside(t->wpad.ir.x, t->wpad.ir.y)) - { - if (inSide == 0) - { - mainWindow->SetState(STATE_DISABLED); - this->SetState(STATE_DEFAULT); - } - inSide |= 1 << t->chan; - } - else if (inSide) - { - inSide &= ~(1 << t->chan); - if (inSide == 0) mainWindow->SetState(STATE_DEFAULT); - } - } - GuiWindow::Update(t); -} -wchar_t GuiSearchBar::GetClicked() -{ - if (buttons) - { - for (int i = 0; i < cnt; i++) - { - if (buttons[i]->button.GetState() == STATE_CLICKED) - { - buttons[i]->button.ResetState(); - return buttons[i]->wchar; - } - } - } - if (BacspaceBtn->GetState() == STATE_CLICKED) return 8; - if (ClearBtn->GetState() == STATE_CLICKED) return 7; - - return 0; -} - -/* - private: - SearchButtons *buttons; - }*/ - diff --git a/source/libwiigui/gui_searchbar.h b/source/libwiigui/gui_searchbar.h deleted file mode 100644 index 32d953f8..00000000 --- a/source/libwiigui/gui_searchbar.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GUI_SEARCHBAR_H_ -#define GUI_SEARCHBAR_H_ -#include "gui.h" - -class cSearchButton; - -class GuiSearchBar: public GuiWindow -{ - public: - GuiSearchBar(const wchar_t *SearchChars); - ~GuiSearchBar(); - void Draw(); - void Update(GuiTrigger * t); - wchar_t GetClicked(); - private: - u16 inSide; - - GuiText text; - - GuiImageData* imgBacspaceBtn; - GuiImage* BacspaceBtnImg; - GuiImage* BacspaceBtnImg_Over; - GuiButton* BacspaceBtn; - - GuiImageData* imgClearBtn; - GuiImage* ClearBtnImg; - GuiImage* ClearBtnImg_Over; - GuiButton* ClearBtn; - - cSearchButton **buttons; - int cnt; - GuiImageData keyImageData; - GuiImageData keyOverImageData; - GuiTrigger trig; - -}; - -#endif \ No newline at end of file diff --git a/source/libwiigui/gui_text.cpp b/source/libwiigui/gui_text.cpp deleted file mode 100644 index b5c091e8..00000000 --- a/source/libwiigui/gui_text.cpp +++ /dev/null @@ -1,577 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_text.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" -#include "wstring.hpp" - -#define MAX_LINES_TO_DRAW 9 - -static int presetSize = 18; -static int presetMaxWidth = 0; -static int presetAlignmentHor = 0; -static int presetAlignmentVert = 0; -static u16 presetStyle = 0; -static GXColor presetColor = ( GXColor ) -{ 255, 255, 255, 255}; - -#define TEXT_SCROLL_DELAY 5 -#define TEXT_SCROLL_INITIAL_DELAY 8 - -/** - * Constructor for the GuiText class. - */ - -GuiText::GuiText(const char * t, int s, GXColor c) -{ - text = NULL; - size = s; - currentSize = size; - color = c; - alpha = c.a; - style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE; - maxWidth = 0; - wrapMode = 0; - passChar = 0; - font = NULL; - linestodraw = MAX_LINES_TO_DRAW; - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - textScrollDelay = TEXT_SCROLL_DELAY; - - alignmentHor = ALIGN_CENTRE; - alignmentVert = ALIGN_MIDDLE; - - if (t) - { - text = charToWideChar(t); - if (!text) return; - - textWidth = fontSystem->getWidth(text, currentSize); - } -} - -GuiText::GuiText(const wchar_t * t, int s, GXColor c) -{ - text = NULL; - size = s; - currentSize = size; - color = c; - alpha = c.a; - style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE; - maxWidth = 0; - wrapMode = 0; - passChar = 0; - font = NULL; - linestodraw = MAX_LINES_TO_DRAW; - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - textScrollDelay = TEXT_SCROLL_DELAY; - - alignmentHor = ALIGN_CENTRE; - alignmentVert = ALIGN_MIDDLE; - - if (t) - { - text = new (std::nothrow) wchar_t[wcslen(t) + 1]; - if (!text) return; - - wcscpy(text, t); - - textWidth = fontSystem->getWidth(text, currentSize); - } -} - -/** - * Constructor for the GuiText class, uses presets - */ -GuiText::GuiText(const char * t) -{ - text = NULL; - size = presetSize; - currentSize = size; - color = presetColor; - alpha = presetColor.a; - style = presetStyle; - maxWidth = presetMaxWidth; - wrapMode = 0; - passChar = 0; - font = NULL; - linestodraw = MAX_LINES_TO_DRAW; - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - textScrollDelay = TEXT_SCROLL_DELAY; - - alignmentHor = presetAlignmentHor; - alignmentVert = presetAlignmentVert; - - if (t) - { - text = charToWideChar(t); - if (!text) return; - - textWidth = fontSystem->getWidth(text, currentSize); - } -} - -/** - * Destructor for the GuiText class. - */ -GuiText::~GuiText() -{ - if (text) delete[] text; - text = NULL; - - if (font) - { - delete font; - font = NULL; - } - - ClearDynamicText(); -} - -void GuiText::SetText(const char * t) -{ - LOCK( this ); - - if (text) delete[] text; - text = NULL; - - ClearDynamicText(); - - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - - if (t) - { - text = charToWideChar(t); - if (!text) return; - - if (passChar != 0) - { - for (u8 i = 0; i < wcslen(text); i++) - text[i] = passChar; - } - - textWidth = fontSystem->getWidth(text, currentSize); - } -} - -void GuiText::SetTextf(const char *format, ...) -{ - if (!format) SetText((char *) NULL); - - char *tmp = 0; - va_list va; - va_start( va, format ); - if ((vasprintf(&tmp, format, va) >= 0) && tmp) - { - SetText(tmp); - } - va_end( va ); - - if (tmp) free(tmp); -} - -void GuiText::SetText(const wchar_t * t) -{ - LOCK( this ); - - if (text) delete[] text; - text = NULL; - - ClearDynamicText(); - - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - - if (t) - { - text = new (std::nothrow) wchar_t[wcslen(t) + 1]; - if (!text) return; - - wcscpy(text, t); - - if (passChar != 0) - { - for (u8 i = 0; i < wcslen(text); i++) - text[i] = passChar; - } - - textWidth = fontSystem->getWidth(text, currentSize); - } -} - -void GuiText::ClearDynamicText() -{ - for (u32 i = 0; i < textDyn.size(); i++) - { - if (textDyn[i]) delete[] textDyn[i]; - } - textDyn.clear(); -} - -void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v) -{ - presetSize = sz; - presetColor = c; - presetStyle = s; - presetMaxWidth = w; - presetAlignmentHor = h; - presetAlignmentVert = v; -} - -void GuiText::SetFontSize(int s) -{ - LOCK( this ); - - size = s; -} - -void GuiText::SetMaxWidth(int width, int w) -{ - LOCK( this ); - - maxWidth = width; - wrapMode = w; - - if (w == SCROLL_HORIZONTAL) - { - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - textScrollDelay = TEXT_SCROLL_DELAY; - } - - ClearDynamicText(); -} - -void GuiText::SetPassChar(wchar_t p) -{ - LOCK( this ); - passChar = p; -} - -void GuiText::SetColor(GXColor c) -{ - LOCK( this ); - color = c; - alpha = c.a; -} - -void GuiText::SetStyle(u16 s) -{ - LOCK( this ); - style = s; -} - -void GuiText::SetAlignment(int hor, int vert) -{ - LOCK( this ); - style = 0; - - switch (hor) - { - case ALIGN_LEFT: - style |= FTGX_JUSTIFY_LEFT; - break; - case ALIGN_RIGHT: - style |= FTGX_JUSTIFY_RIGHT; - break; - default: - style |= FTGX_JUSTIFY_CENTER; - break; - } - switch (vert) - { - case ALIGN_TOP: - style |= FTGX_ALIGN_TOP; - break; - case ALIGN_BOTTOM: - style |= FTGX_ALIGN_BOTTOM; - break; - default: - style |= FTGX_ALIGN_MIDDLE; - break; - } - - alignmentHor = hor; - alignmentVert = vert; -} - -void GuiText::SetLinesToDraw(int l) -{ - linestodraw = l; -} - -int GuiText::GetTextWidth() -{ - if (!text) return 0; - - return fontSystem->getWidth(text, currentSize); -} - -int GuiText::GetTextWidth(int ind) -{ - if (ind < 0 || ind >= (int) textDyn.size()) return this->GetTextWidth(); - - return fontSystem->getWidth(textDyn[ind], currentSize); -} - -int GuiText::GetTextMaxWidth() -{ - return maxWidth; -} - -const wchar_t * GuiText::GetDynText(int ind) -{ - if (ind < 0 || ind >= (int) textDyn.size()) return text; - - return textDyn[ind]; -} - -const wchar_t * GuiText::GetText() -{ - return text; -} - -/** - * Change font - */ -bool GuiText::SetFont(const u8 *fontbuffer, const u32 filesize) -{ - if (!fontbuffer || !filesize) return false; - LOCK( this ); - if (font) - { - delete font; - font = NULL; - } - font = new FreeTypeGX(fontbuffer, filesize); - textWidth = font->getWidth(text, currentSize); - - return true; -} - -void GuiText::MakeDottedText() -{ - int pos = textDyn.size(); - textDyn.resize(pos + 1); - - int i = 0, currentWidth = 0; - textDyn[pos] = new wchar_t[maxWidth]; - - while (text[i]) - { - currentWidth += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0x0000); - if (currentWidth >= maxWidth) - { - if (i > 3) - { - textDyn[pos][i - 3] = '.'; - textDyn[pos][i - 2] = '.'; - textDyn[pos][i - 1] = '.'; - } - break; - } - - textDyn[pos][i] = text[i]; - - i++; - } - textDyn[pos][i] = 0; -} - -void GuiText::ScrollText() -{ - if (textDyn.size() == 0) - { - int pos = textDyn.size(); - int i = 0, currentWidth = 0; - textDyn.resize(pos + 1); - - textDyn[pos] = new wchar_t[maxWidth]; - - while (text[i] && currentWidth < maxWidth-40) - { - textDyn[pos][i] = text[i]; - - currentWidth - += (font ? font : fontSystem)->getCharWidth(text[i], currentSize, i > 0 ? text[i - 1] : 0x0000); - - ++i; - } - textDyn[pos][i] = 0; - - return; - } - - if (frameCount % textScrollDelay != 0) - { - return; - } - - if (textScrollInitialDelay) - { - --textScrollInitialDelay; - return; - } - - int strlen = wcslen(text); - - ++textScrollPos; - if (textScrollPos > strlen) - { - textScrollPos = 0; - textScrollInitialDelay = TEXT_SCROLL_INITIAL_DELAY; - } - - int ch = textScrollPos; - int pos = textDyn.size() - 1; - - if (textDyn[pos]) delete[] textDyn[pos]; - - textDyn[pos] = new wchar_t[maxWidth]; - - int i = 0, currentWidth = 0; - - while (currentWidth < maxWidth-40) - { - if (ch > strlen - 1) - { - textDyn[pos][i++] = ' '; - textDyn[pos][i++] = ' '; - textDyn[pos][i++] = ' '; - ch = 0; - } - - textDyn[pos][i] = text[ch]; - ++ch; - ++i; - - currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000); - } - textDyn[pos][i] = 0; -} - -void GuiText::WrapText() -{ - if (textDyn.size() > 0) return; - - int i = 0; - int ch = 0; - int linenum = 0; - int lastSpace = -1; - int lastSpaceIndex = -1; - int currentWidth = 0; - - while (text[ch] && linenum < linestodraw) - { - if (linenum >= (int) textDyn.size()) - { - textDyn.resize(linenum + 1); - textDyn[linenum] = new wchar_t[maxWidth]; - } - - textDyn[linenum][i] = text[ch]; - textDyn[linenum][i + 1] = 0; - - currentWidth += (font ? font : fontSystem)->getCharWidth(text[ch], currentSize, ch > 0 ? text[ch - 1] : 0x0000); - - if (currentWidth >= maxWidth) - { - if (lastSpace >= 0) - { - textDyn[linenum][lastSpaceIndex] = 0; // discard space, and everything after - ch = lastSpace; // go backwards to the last space - lastSpace = -1; // we have used this space - lastSpaceIndex = -1; - } - - if (linenum + 1 == linestodraw && text[ch + 1] != 0x0000) - { - textDyn[linenum][i - 2] = '.'; - textDyn[linenum][i - 1] = '.'; - textDyn[linenum][i] = '.'; - textDyn[linenum][i + 1] = 0; - } - - currentWidth = 0; - ++linenum; - i = -1; - } - if (text[ch] == ' ' && i >= 0) - { - lastSpace = ch; - lastSpaceIndex = i; - } - ++ch; - ++i; - } -} - -/** - * Draw the text on screen - */ -void GuiText::Draw() -{ - if (!text) return; - - if (!IsVisible()) return; - - GXColor c = color; - c.a = GetAlpha(); - - int newSize = size * GetScale(); - - if (newSize != currentSize) - { - currentSize = newSize; - - if (text) textWidth = (font ? font : fontSystem)->getWidth(text, currentSize); - } - - if (maxWidth > 0 && maxWidth <= textWidth) - { - if (wrapMode == DOTTED) // text dotted - { - if (textDyn.size() == 0) MakeDottedText(); - - if (textDyn.size() > 0) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, - textDyn[textDyn.size() - 1], currentSize, c, style); - } - - else if (wrapMode == SCROLL_HORIZONTAL) - { - ScrollText(); - - if (textDyn.size() > 0) (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, - textDyn[textDyn.size() - 1], currentSize, c, style); - } - else if (wrapMode == WRAP) - { - int lineheight = currentSize + 6; - int voffset = 0; - if (alignmentVert == ALIGN_MIDDLE) voffset = -(lineheight * textDyn.size()) / 2 + lineheight / 2; - - if (textDyn.size() == 0) WrapText(); - - for (u32 i = 0; i < textDyn.size(); i++) - { - (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop() + voffset + i * lineheight, 0, - textDyn[i], currentSize, c, style); - } - } - } - else - { - (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop(), 0, text, currentSize, c, style, textWidth); - } - this->UpdateEffects(); -} diff --git a/source/libwiigui/gui_tooltip.cpp b/source/libwiigui/gui_tooltip.cpp deleted file mode 100644 index b3fa5365..00000000 --- a/source/libwiigui/gui_tooltip.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_tooltip.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" - -static GuiImageData tooltipLeft(tooltip_left_png, tooltip_left_png_size); -static GuiImageData tooltipTile(tooltip_tile_png, tooltip_left_png_size); -static GuiImageData tooltipRight(tooltip_right_png, tooltip_right_png_size); - -/** - * Constructor for the GuiTooltip class. - */ -GuiTooltip::GuiTooltip(const char *t, int Alpha/*=255*/) : - leftImage(&tooltipLeft), tileImage(&tooltipTile), rightImage(&tooltipRight) -{ - text = NULL; - height = leftImage.GetHeight(); - leftImage.SetParent(this); - tileImage.SetParent(this); - rightImage.SetParent(this); - leftImage.SetParentAngle(false); - tileImage.SetParentAngle(false); - rightImage.SetParentAngle(false); - SetText(t); - SetAlpha(Alpha); -} - -/* - * Destructor for the GuiTooltip class. - */ -GuiTooltip::~GuiTooltip() -{ - if (text) delete text; -} - -float GuiTooltip::GetScale() -{ - float s = scale * scaleDyn; - - return s; -} - -/* !Sets the text of the GuiTooltip element - * !\param t Text - */ -void GuiTooltip::SetText(const char * t) -{ - LOCK( this ); - if (text) - { - delete text; - text = NULL; - } - int tile_cnt = 0; - if (t && (text = new GuiText(t, 22, ( GXColor ) - { 0, 0, 0, 255}))) - { - text->SetParent(this); - tile_cnt = (text->GetTextWidth() - 12) / tileImage.GetWidth(); - if (tile_cnt < 0) tile_cnt = 0; - } - tileImage.SetPosition(leftImage.GetWidth(), 0); - tileImage.SetTile(tile_cnt); - rightImage.SetPosition(leftImage.GetWidth() + tile_cnt * tileImage.GetWidth(), 0); - width = leftImage.GetWidth() + tile_cnt * tileImage.GetWidth() + rightImage.GetWidth(); -} - -void GuiTooltip::SetWidescreen(bool ) -{ -} -/* - * Draw the Tooltip on screen - */ -void GuiTooltip::Draw() -{ - LOCK( this ); - if (!this->IsVisible()) return; - - leftImage.Draw(); - tileImage.Draw(); - rightImage.Draw(); - if (text) text->Draw(); - - this->UpdateEffects(); -} diff --git a/source/libwiigui/gui_trigger.cpp b/source/libwiigui/gui_trigger.cpp deleted file mode 100644 index 58e15598..00000000 --- a/source/libwiigui/gui_trigger.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_trigger.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" - -static int scrollDelay = 0; - -/** - * Constructor for the GuiTrigger class. - */ -GuiTrigger::GuiTrigger() -{ - chan = -1; - memset(&wpad, 0, sizeof(WPADData)); - memset(&pad, 0, sizeof(PADData)); -} - -/** - * Destructor for the GuiTrigger class. - */ -GuiTrigger::~GuiTrigger() -{ -} - -/** - * Sets a simple trigger. Requires: - * - Element is selected - * - Trigger button is pressed - */ -void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns) -{ - type = TRIGGER_SIMPLE; - chan = ch; - wpad.btns_d = wiibtns; - pad.btns_d = gcbtns; -} - -/** - * Sets a held trigger. Requires: - * - Element is selected - * - Trigger button is pressed and held - */ -void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns) -{ - type = TRIGGER_HELD; - chan = ch; - wpad.btns_h = wiibtns; - pad.btns_h = gcbtns; -} - -/** - * Sets a button trigger. Requires: - * - Trigger button is pressed - */ -void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns) -{ - type = TRIGGER_BUTTON_ONLY; - chan = ch; - wpad.btns_d = wiibtns; - pad.btns_d = gcbtns; -} - -/** - * Sets a button trigger. Requires: - * - Trigger button is pressed - * - Parent window is in focus - */ -void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns) -{ - type = TRIGGER_BUTTON_ONLY_IN_FOCUS; - chan = ch; - wpad.btns_d = wiibtns; - pad.btns_d = gcbtns; -} - -/**************************************************************************** - * WPAD_Stick - * - * Get X/Y value from Wii Joystick (classic, nunchuk) input - ***************************************************************************/ - -s8 GuiTrigger::WPAD_Stick(u8 right, int axis) -{ -#ifdef HW_RVL - - float mag = 0.0; - float ang = 0.0; - - switch ( wpad.exp.type ) - { - case WPAD_EXP_NUNCHUK: - case WPAD_EXP_GUITARHERO3: - if ( right == 0 ) - { - mag = wpad.exp.nunchuk.js.mag; - ang = wpad.exp.nunchuk.js.ang; - } - break; - - case WPAD_EXP_CLASSIC: - if ( right == 0 ) - { - mag = wpad.exp.classic.ljs.mag; - ang = wpad.exp.classic.ljs.ang; - } - else - { - mag = wpad.exp.classic.rjs.mag; - ang = wpad.exp.classic.rjs.ang; - } - break; - - default: - break; - } - - /* calculate x/y value (angle need to be converted into radian) */ - if ( mag > 1.0 ) mag = 1.0; - else if ( mag < -1.0 ) mag = -1.0; - double val; - - if ( axis == 0 ) // x-axis - val = mag * sin( ( PI * ang ) / 180.0f ); - else // y-axis - val = mag * cos( ( PI * ang ) / 180.0f ); - - return ( s8 )( val * 128.0f ); - -#else - return 0; -#endif -} - -bool GuiTrigger::Left() -{ - u32 wiibtn = WPAD_BUTTON_LEFT; - - if ((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT) || (pad.btns_d | pad.btns_h) - & PAD_BUTTON_LEFT || pad.stickX < -PADCAL || WPAD_Stick(0, 0) < -PADCAL) - { - if (wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT) || pad.btns_d & PAD_BUTTON_LEFT) - { - scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. - return true; - } - else if (scrollDelay == 0) - { - scrollDelay = SCROLL_LOOP_DELAY; - return true; - } - else - { - if (scrollDelay > 0) scrollDelay--; - } - } - return false; -} - -bool GuiTrigger::Right() -{ - u32 wiibtn = WPAD_BUTTON_RIGHT; - - if ((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT) || (pad.btns_d | pad.btns_h) - & PAD_BUTTON_RIGHT || pad.stickX > PADCAL || WPAD_Stick(0, 0) > PADCAL) - { - if (wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT) || pad.btns_d & PAD_BUTTON_RIGHT) - { - scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. - return true; - } - else if (scrollDelay == 0) - { - scrollDelay = SCROLL_LOOP_DELAY; - return true; - } - else - { - if (scrollDelay > 0) scrollDelay--; - } - } - return false; -} - -bool GuiTrigger::Up() -{ - u32 wiibtn = WPAD_BUTTON_UP; - - if ((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP) || (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP - || pad.stickY > PADCAL || WPAD_Stick(0, 1) > PADCAL) - { - if (wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP) || pad.btns_d & PAD_BUTTON_UP) - { - scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. - return true; - } - else if (scrollDelay == 0) - { - scrollDelay = SCROLL_LOOP_DELAY; - return true; - } - else - { - if (scrollDelay > 0) scrollDelay--; - } - } - return false; -} - -bool GuiTrigger::Down() -{ - u32 wiibtn = WPAD_BUTTON_DOWN; - - if ((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN) || (pad.btns_d | pad.btns_h) - & PAD_BUTTON_DOWN || pad.stickY < -PADCAL || WPAD_Stick(0, 1) < -PADCAL) - { - if (wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN) || pad.btns_d & PAD_BUTTON_DOWN) - { - scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. - return true; - } - else if (scrollDelay == 0) - { - scrollDelay = SCROLL_LOOP_DELAY; - return true; - } - else - { - if (scrollDelay > 0) scrollDelay--; - } - } - return false; -} diff --git a/source/libwiigui/gui_window.cpp b/source/libwiigui/gui_window.cpp deleted file mode 100644 index d536386b..00000000 --- a/source/libwiigui/gui_window.cpp +++ /dev/null @@ -1,451 +0,0 @@ -/**************************************************************************** - * libwiigui - * - * Tantric 2009 - * - * gui_window.cpp - * - * GUI class definitions - ***************************************************************************/ - -#include "gui.h" - -GuiWindow::GuiWindow() -{ - width = 0; - height = 0; - focus = 0; // allow focus -} - -GuiWindow::GuiWindow(int w, int h) -{ - width = w; - height = h; - focus = 0; // allow focus -} - -GuiWindow::~GuiWindow() -{ -} - -void GuiWindow::Append(GuiElement* e) -{ - LOCK( this ); - if (e == NULL) return; - - Remove(e); - _elements.push_back(e); - e->SetParent(this); -} - -void GuiWindow::Insert(GuiElement* e, u32 index) -{ - LOCK( this ); - if (e == NULL || index > (_elements.size() - 1)) return; - - Remove(e); - _elements.insert(_elements.begin() + index, e); - e->SetParent(this); -} - -void GuiWindow::Remove(GuiElement* e) -{ - LOCK( this ); - if (e == NULL) return; - - for (u8 i = 0; i < _elements.size(); i++) - { - if (e == _elements.at(i)) - { - _elements.erase(_elements.begin() + i); - break; - } - } -} - -void GuiWindow::RemoveAll() -{ - LOCK( this ); - _elements.clear(); -} - -GuiElement* GuiWindow::GetGuiElementAt(u32 index) const -{ - if (index >= _elements.size()) return NULL; - return _elements.at(index); -} - -u32 GuiWindow::GetSize() -{ - return _elements.size(); -} - -void GuiWindow::Draw() -{ - LOCK( this ); - if (_elements.size() == 0 || !this->IsVisible()) return; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->Draw(); - } - catch (const std::exception& e) - { - } - } - - this->UpdateEffects(); - - if (parentElement && state == STATE_DISABLED) - //Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0xbe, 0xca, 0xd5, 0x70},1); - Menu_DrawRectangle(0, 0, screenwidth, screenheight, ( GXColor ) - { 0, 0, 0, 0x70}, 1); -} -void GuiWindow::DrawTooltip() -{ - LOCK( this ); - if (_elements.size() == 0 || !this->IsVisible()) return; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->DrawTooltip(); - } - catch (const std::exception& e) - { - } - } -} -void GuiWindow::ResetState() -{ - LOCK( this ); - if (state != STATE_DISABLED) state = STATE_DEFAULT; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->ResetState(); - } - catch (const std::exception& e) - { - } - } -} - -void GuiWindow::SetState(int s) -{ - LOCK( this ); - state = s; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->SetState(s); - } - catch (const std::exception& e) - { - } - } -} - -void GuiWindow::SetVisible(bool v) -{ - LOCK( this ); - visible = v; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->SetVisible(v); - } - catch (const std::exception& e) - { - } - } -} - -void GuiWindow::SetFocus(int f) -{ - LOCK( this ); - focus = f; - - if (f == 1) - this->MoveSelectionVert(1); - else this->ResetState(); -} - -void GuiWindow::ChangeFocus(GuiElement* e) -{ - LOCK( this ); - if (parentElement) return; // this is only intended for the main window - - for (u8 i = 0; i < _elements.size(); i++) - { - if (e == _elements.at(i)) - _elements.at(i)->SetFocus(1); - else if (_elements.at(i)->IsFocused() == 1) _elements.at(i)->SetFocus(0); - } -} - -void GuiWindow::ToggleFocus(GuiTrigger * t) -{ - LOCK( this ); - if (parentElement) return; // this is only intended for the main window - - int found = -1; - int newfocus = -1; - u8 i; - - // look for currently in focus element - for (i = 0; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->IsFocused() == 1) - { - found = i; - break; - } - } - catch (const std::exception& e) - { - } - } - - // element with focus not found, try to give focus - if (found == -1) - { - for (i = 0; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set) - { - _elements.at(i)->SetFocus(1); // give this element focus - break; - } - } - catch (const std::exception& e) - { - } - } - } - // change focus - else if (t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_PLUS) || t->pad.btns_d - & PAD_BUTTON_B) - { - for (i = found; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set) - { - newfocus = i; - _elements.at(i)->SetFocus(1); // give this element focus - _elements.at(found)->SetFocus(0); // disable focus on other element - break; - } - } - catch (const std::exception& e) - { - } - } - - if (newfocus == -1) - { - for (i = 0; i < found; i++) - { - try - { - if (_elements.at(i)->IsFocused() == 0 && _elements.at(i)->GetState() != STATE_DISABLED) // focus is possible (but not set) - { - _elements.at(i)->SetFocus(1); // give this element focus - _elements.at(found)->SetFocus(0); // disable focus on other element - break; - } - } - catch (const std::exception& e) - { - } - } - } - } -} - -int GuiWindow::GetSelected() -{ - // find selected element - int found = -1; - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->GetState() == STATE_SELECTED) - { - found = i; - break; - } - } - catch (const std::exception& e) - { - } - } - return found; -} - -// set element to left/right as selected -// there's probably a more clever way to do this, but this way works -void GuiWindow::MoveSelectionHor(int dir) -{ - LOCK( this ); - int found = -1; - u16 left = 0; - u16 top = 0; - u8 i = 0; - - int selected = this->GetSelected(); - - if (selected >= 0) - { - left = _elements.at(selected)->GetLeft(); - top = _elements.at(selected)->GetTop(); - } - - // look for a button on the same row, to the left/right - for (i = 0; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->IsSelectable()) - { - if (_elements.at(i)->GetLeft() * dir > left * dir && _elements.at(i)->GetTop() == top) - { - if (found == -1) - found = i; - else if (_elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match - } - } - } - catch (const std::exception& e) - { - } - } - if (found >= 0) goto matchfound; - - // match still not found, let's try the first button in the next row - for (i = 0; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->IsSelectable()) - { - if (_elements.at(i)->GetTop() * dir > top * dir) - { - if (found == -1) - found = i; - else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir) - found = i; // this is a better match - else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir - && _elements.at(i)->GetLeft() * dir < _elements.at(found)->GetLeft() * dir) found = i; // this is a better match - } - } - } - catch (const std::exception& e) - { - } - } - - // match found - matchfound: if (found >= 0) - { - _elements.at(found)->SetState(STATE_SELECTED); - if (selected >= 0) _elements.at(selected)->ResetState(); - } -} - -void GuiWindow::MoveSelectionVert(int dir) -{ - LOCK( this ); - int found = -1; - u16 left = 0; - u16 top = 0; - u8 i = 0; - - int selected = this->GetSelected(); - - if (selected >= 0) - { - left = _elements.at(selected)->GetLeft(); - top = _elements.at(selected)->GetTop(); - } - - // look for a button above/below, with the least horizontal difference - for (i = 0; i < _elements.size(); i++) - { - try - { - if (_elements.at(i)->IsSelectable()) - { - if (_elements.at(i)->GetTop() * dir > top * dir) - { - if (found == -1) - found = i; - else if (_elements.at(i)->GetTop() * dir < _elements.at(found)->GetTop() * dir) - found = i; // this is a better match - else if (_elements.at(i)->GetTop() * dir == _elements.at(found)->GetTop() * dir && abs( - _elements.at(i)->GetLeft() - left) < abs(_elements.at(found)->GetLeft() - left)) found = i; - } - } - } - catch (const std::exception& e) - { - } - } - if (found >= 0) goto matchfound; - - // match found - matchfound: if (found >= 0) - { - _elements.at(found)->SetState(STATE_SELECTED); - if (selected >= 0) _elements.at(selected)->ResetState(); - } -} - -void GuiWindow::Update(GuiTrigger * t) -{ - LOCK( this ); - if (_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) return; - - for (u8 i = 0; i < _elements.size(); i++) - { - try - { - _elements.at(i)->Update(t); - } - catch (const std::exception& e) - { - } - } - - this->ToggleFocus(t); - - if (focus) // only send actions to this window if it's in focus - { - // pad/joystick navigation - if (t->Right()) - this->MoveSelectionHor(1); - else if (t->Left()) - this->MoveSelectionHor(-1); - else if (t->Down()) - this->MoveSelectionVert(1); - else if (t->Up()) this->MoveSelectionVert(-1); - } - - if (updateCB) updateCB(this); -} diff --git a/source/lstub.cpp b/source/lstub.cpp deleted file mode 100644 index 5047e27f..00000000 --- a/source/lstub.cpp +++ /dev/null @@ -1,100 +0,0 @@ -//functions for manipulating the HBC stub by giantpune - -#include -#include -#include -#include - -#include "lstub.h" -#include "filelist.h" -#include "gecko.h" - -#include "wad/nandtitle.h" - -static char* determineStubTIDLocation() -{ - u32 *stubID = (u32*) 0x80001818; - - //HBC stub 1.0.6 and lower, and stub.bin - if (stubID[0] == 0x480004c1 && stubID[1] == 0x480004f5) - return (char *) 0x800024C6; - - //HBC stub changed @ version 1.0.7. this file was last updated for HBC 1.0.8 - else if (stubID[0] == 0x48000859 && stubID[1] == 0x4800088d) return (char *) 0x8000286A; - - //hexdump( stubID, 0x20 ); - return NULL; - -} - -s32 Set_Stub(u64 reqID) -{ - if (NandTitles.IndexOf(reqID) < 0) return WII_EINSTALL; - - char *stub = determineStubTIDLocation(); - if (!stub) return -68; - - stub[0] = TITLE_7( reqID ); - stub[1] = TITLE_6( reqID ); - stub[8] = TITLE_5( reqID ); - stub[9] = TITLE_4( reqID ); - stub[4] = TITLE_3( reqID ); - stub[5] = TITLE_2( reqID ); - stub[12] = TITLE_1( reqID ); - stub[13] = ((u8) (reqID)); - - DCFlushRange(stub, 0x10); - - return 1; - -} - -s32 Set_Stub_Split(u32 type, const char* reqID) -{ - char tmp[4]; - u32 lower; - sprintf(tmp, "%c%c%c%c", reqID[0], reqID[1], reqID[2], reqID[3]); - memcpy(&lower, tmp, 4); - u64 reqID64 = TITLE_ID( type, lower ); - return Set_Stub(reqID64); - -} - -void loadStub() -{ - char *stubLoc = (char *) 0x80001800; - memcpy(stubLoc, stub_bin, stub_bin_size); - DCFlushRange(stubLoc, stub_bin_size); -} - -u64 getStubDest() -{ - if (!hbcStubAvailable()) return 0; - - char ret[8]; - u64 retu = 0; - - char *stub = determineStubTIDLocation(); - if (!stub) return 0; - - ret[0] = stub[0]; - ret[1] = stub[1]; - ret[2] = stub[8]; - ret[3] = stub[9]; - ret[4] = stub[4]; - ret[5] = stub[5]; - ret[6] = stub[12]; - ret[7] = stub[13]; - - memcpy(&retu, ret, 8); - - return retu; -} - -u8 hbcStubAvailable() -{ - char * sig = (char *) 0x80001804; - return (sig[0] == 'S' && sig[1] == 'T' && sig[2] == 'U' && sig[3] == 'B' && sig[4] == 'H' && sig[5] == 'A' - && sig[6] == 'X' && sig[7] == 'X') ? 1 : 0; -} - diff --git a/source/lstub.h b/source/lstub.h deleted file mode 100644 index 978d563f..00000000 --- a/source/lstub.h +++ /dev/null @@ -1,29 +0,0 @@ -//small group of functions to manipulate the HBC stub -//brought to you by giantpune - -#ifndef _LSTUB_H_ -#define _LSTUB_H_ - -//to set the "return to" stub for a certain ID -//!reqID is the Requested ID to return to -//!returns WII_EINTERNAL if it cant get the list of installed titles with ES functions -//!retuns -69 if the ID is not installed -//!1 if successful -s32 Set_Stub(u64 reqID); - -//!same as the above function, but expects a type and 4 char channel ID -s32 Set_Stub_Split(u32 type, const char* reqID); - -//load the default HBC stub into memory. as long as nothing writes to the 0x80001800 -// +0xDC7 memory block it will stay there. by default it has 0x00010001/JODI. -void loadStub(); - -//get whatever ID the stub is set to load -//!returns 0 if no stub is loaded into memory (must be the HBC stub at 0x800018000) -//!otherwise returns the ID set to return to -u64 getStubDest(); - -//returns 0 or 1 depending on wether the stub is available -u8 hbcStubAvailable(); - -#endif diff --git a/source/main.cpp b/source/main.cpp deleted file mode 100644 index 830780cf..00000000 --- a/source/main.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** - * USB Loader GX Team - * - * Main loadup of the application - * - * libwiigui - * Tantric 2009 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libwiigui/gui.h" -#include "usbloader/wbfs.h" -#include "language/gettext.h" -#include "mload/mload.h" -#include "mload/mload_modules.h" -#include "FreeTypeGX.h" -#include "FontSystem.h" -#include "video.h" -#include "audio.h" -#include "menu/menus.h" -#include "menu.h" -#include "input.h" -#include "filelist.h" -#include "FileOperations/fileops.h" -#include "settings/CGameSettings.h" -#include "settings/CGameStatistics.h" -#include "themes/CTheme.h" -#include "main.h" -#include "fatmounter.h" -#include "sys.h" -#include "gecko.h" -#include "usbloader/partition_usbloader.h" -#include "usbloader/usbstorage2.h" -#include "memory/mem2.h" -#include "lstub.h" -#include "usbloader/usbstorage2.h" -#include "wad/nandtitle.h" -#include "system/IosLoader.h" -#include "GameBootProcess.h" - -extern "C" -{ - void __exception_setreload(int t); -} - -PartList partitions; - -int main(int argc, char *argv[]) -{ - MEM2_init(48); - setlocale(LC_ALL, "en.UTF-8"); - InitVideo(); - InitGecko(); - __exception_setreload(20); - - printf("\tStarting up\n"); - NandTitles.Get(); - - // Let's try loading some cIOS - if (IosLoader::LoadAppCios() < 0) - { - printf("\n\tWARNING!\n"); - printf("\tUSB Loader GX needs unstubbed cIOS 222 v4+ or 249 v9+\n\n"); - - printf("\tWe cannot determine the versions on your system,\n\tsince you have no patched ios 36 or 236 installed.\n"); - printf("\tTherefor, if loading of USB Loader GX fails, you\n\tprobably have installed the 4.2 update,\n"); - printf("\tand you should go figure out how to get some cios action going on\n\tin your Wii.\n"); - - printf("\tERROR: No cIOS could be loaded. Exiting....\n"); - sleep(10); - Sys_BackToLoader(); - } - - //Let's use libogc sd/usb for config loading - printf("\tInitialize sd card...%s\n", SDCard_Init() < 0 ? "failed" : "done"); - printf("\tInitialize usb device...%s\n", USBDevice_Init_Loop() < 0 ? "failed" : "done"); - - //Load configurations - printf("\tLoading config...%s\n", Settings.Load() ? "done" : "failed"); - printf("\tLoading language...%s\n", Settings.LoadLanguage(Settings.language_path, CONSOLE_DEFAULT) ? "done" : "failed"); - printf("\tLoading game settings...%s\n", GameSettings.Load(Settings.ConfigPath) ? "done" : "failed"); - printf("\tLoading game statistics...%s\n", GameStatistics.Load(Settings.ConfigPath) ? "done" : "failed"); - printf("\tLoading theme...%s\n", Theme::Load(Settings.theme_path) ? "done" : "failed (using default)"); - printf("\tLoading font system...%s\n", SetupDefaultFont(Settings.theme_path) ? "done" : "failed (using default)"); - - VIDEO_SetWidescreen(Settings.widescreen); - - if(Settings.cios != IOS_GetVersion()) - { - // Unmount fat before reloading IOS. - SDCard_deInit(); - USBDevice_deInit(); - - // Loading now the cios setup in the settings - IosLoader::LoadAppCios(); - - // Remount devices after reloading IOS. - SDCard_Init(); - USBDevice_Init_Loop(); - } - printf("\tLoaded cIOS = %u (Rev %u)\n", IOS_GetVersion(), IOS_GetRevision()); - - //if a ID was passed via args copy it and try to boot it after the partition is mounted - //its not really a headless mode. more like hairless. - if (argc > 1 && argv[1]) - { - MountGamePartition(false); - return BootGame(argv[1]); - } - - //! Now we startup the GUI so no need for console prints. Output only to gecko. - USBGeckoOutput(); - - //! Init the rest of the System - Sys_Init(); - SetupPads(); - InitAudio(); - - MainMenu(MENU_DISCLIST); - return 0; -} diff --git a/source/main.h b/source/main.h deleted file mode 100644 index f545ca60..00000000 --- a/source/main.h +++ /dev/null @@ -1,16 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * demo.h - ***************************************************************************/ - -#ifndef _MAIN_H_ -#define _MAIN_H_ - -#include "FreeTypeGX.h" - -void DefaultSettings(); -extern FreeTypeGX *fontSystem; - -#endif diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp deleted file mode 100644 index 3226e19b..00000000 --- a/source/memory/mem2.cpp +++ /dev/null @@ -1,197 +0,0 @@ -#include "mem2.h" -#include "mem2alloc.hpp" - -#include -#include - -#define MEM2_PRIORITY_SIZE 2097152 //2MB -// Forbid the use of MEM2 through malloc -u32 MALLOC_MEM2 = 0; - -static CMEM2Alloc g_mem2gp; - -static bool g_bigGoesToMem2 = false; - -extern "C" -{ - - void MEM2_takeBigOnes(bool b) - { - g_bigGoesToMem2 = b; - } - - void MEM2_init(unsigned int mem2Size) - { - g_mem2gp.init(mem2Size); - } - - void MEM2_cleanup(void) - { - g_mem2gp.cleanup(); - } - - void *MEM2_alloc(unsigned int s) - { - return g_mem2gp.allocate(s); - } - - void MEM2_free(void *p) - { - g_mem2gp.release(p); - } - - void *MEM2_realloc(void *p, unsigned int s) - { - return g_mem2gp.reallocate(p, s); - } - - unsigned int MEM2_usableSize(void *p) - { - return CMEM2Alloc::usableSize(p); - } - - unsigned int MEM2_freesize() - { - return g_mem2gp.FreeSize(); - } - - extern __typeof( malloc ) __real_malloc; - extern __typeof( calloc ) __real_calloc; - extern __typeof( realloc ) __real_realloc; - extern __typeof( memalign ) __real_memalign; - extern __typeof( free ) __real_free; - extern __typeof( malloc_usable_size ) __real_malloc_usable_size; - - void *__wrap_malloc(size_t size) - { - void *p; - if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE) - { - p = MEM2_alloc(size); - if (p != 0) - { - return p; - } - return __real_malloc(size); - } - p = __real_malloc(size); - if (p != 0) - { - return p; - } - return MEM2_alloc(size); - } - - void *__wrap_calloc(size_t n, size_t size) - { - void *p; - if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE) - { - p = MEM2_alloc(n * size); - if (p != 0) - { - memset(p, 0, n * size); - return p; - } - return __real_calloc(n, size); - } - p = __real_calloc(n, size); - if (p != 0) - { - return p; - } - p = MEM2_alloc(n * size); - if (p != 0) - { - memset(p, 0, n * size); - } - return p; - } - - void *__wrap_memalign(size_t a, size_t size) - { - void *p; - if (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE) - { - if (a <= 32 && 32 % a == 0) - { - p = MEM2_alloc(size); - if (p != 0) - { - return p; - } - } - return __real_memalign(a, size); - } - p = __real_memalign(a, size); - if (p != 0 || a > 32 || 32 % a != 0) - { - return p; - } - - return MEM2_alloc(size); - } - - void __wrap_free(void *p) - { - if (!p) return; - - if (((u32) p & 0x10000000) != 0) - { - MEM2_free(p); - } - else - { - __real_free(p); - } - } - - void *__wrap_realloc(void *p, size_t size) - { - void *n; - // ptr from mem2 - if (((u32) p & 0x10000000) != 0 || (p == 0 && g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)) - { - n = MEM2_realloc(p, size); - if (n != 0) - { - return n; - } - n = __real_malloc(size); - if (n == 0) - { - return 0; - } - if (p != 0) - { - memcpy(n, p, MEM2_usableSize(p) < size ? MEM2_usableSize(p) : size); - MEM2_free(p); - } - return n; - } - // ptr from malloc - n = __real_realloc(p, size); - if (n != 0) - { - return n; - } - n = MEM2_alloc(size); - if (n == 0) - { - return 0; - } - if (p != 0) - { - memcpy(n, p, __real_malloc_usable_size(p) < size ? __real_malloc_usable_size(p) : size); - __real_free(p); - } - return n; - } - - size_t __wrap_malloc_usable_size(void *p) - { - if (((u32) p & 0x10000000) != 0) return MEM2_usableSize(p); - return __real_malloc_usable_size(p); - } - -} ///extern "C" diff --git a/source/memory/mem2alloc.cpp b/source/memory/mem2alloc.cpp deleted file mode 100644 index 73b43f9d..00000000 --- a/source/memory/mem2alloc.cpp +++ /dev/null @@ -1,226 +0,0 @@ -#include "mem2alloc.hpp" - -#include -#include -#include - -class LockMutex -{ - mutex_t &m_mutex; - public: - LockMutex(mutex_t &m) : - m_mutex(m) - { - LWP_MutexLock(m_mutex); - } - ~LockMutex(void) - { - LWP_MutexUnlock(m_mutex); - } -}; - -void CMEM2Alloc::init(unsigned int size) -{ - m_baseAddress = (SBlock *) (((u32) SYS_GetArena2Lo() + 31) & ~31); - m_endAddress = (SBlock *) ((char *) m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31)); - if (m_endAddress > (SBlock *) 0x93300000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes) - m_endAddress = (SBlock *) 0x93300000; - SYS_SetArena2Lo(m_endAddress); - LWP_MutexInit(&m_mutex, 0); -} - -void CMEM2Alloc::init(void *addr, void *end) -{ - m_baseAddress = (SBlock *) (((u32) addr + 31) & ~31); - m_endAddress = (SBlock *) ((u32) end & ~31); - LWP_MutexInit(&m_mutex, 0); -} - -void CMEM2Alloc::cleanup(void) -{ - LWP_MutexDestroy(m_mutex); - m_mutex = 0; - m_first = 0; - // Try to release the range we took through SYS functions - if (SYS_GetArena2Lo() == m_endAddress) SYS_SetArena2Lo(m_baseAddress); - m_baseAddress = 0; - m_endAddress = 0; -} - -void CMEM2Alloc::clear(void) -{ - m_first = 0; - memset(m_baseAddress, 0, (u8 *) m_endAddress - (u8 *) m_endAddress); -} - -unsigned int CMEM2Alloc::usableSize(void *p) -{ - return p == 0 ? 0 : ((SBlock *) p - 1)->s * sizeof(SBlock); -} - -void *CMEM2Alloc::allocate(unsigned int s) -{ - if (s == 0) s = 1; - // - LockMutex lock(m_mutex); - // - s = (s - 1) / sizeof(SBlock) + 1; - // First block - if (m_first == 0) - { - if (m_baseAddress + s + 1 >= m_endAddress) return 0; - m_first = m_baseAddress; - m_first->next = 0; - m_first->prev = 0; - m_first->s = s; - m_first->f = false; - return (void *) (m_first + 1); - } - // Search for a free block - SBlock *i; - SBlock *j; - for (i = m_first; i != 0; i = i->next) - { - if (i->f && i->s >= s) break; - j = i; - } - // Create a new block - if (i == 0) - { - i = j + j->s + 1; - if (i + s + 1 >= m_endAddress) return 0; - j->next = i; - i->prev = j; - i->next = 0; - i->s = s; - i->f = false; - return (void *) (i + 1); - } - // Reuse a free block - i->f = false; - // Split it - if (i->s > s + 1) - { - j = i + s + 1; - j->f = true; - j->s = i->s - s - 1; - i->s = s; - j->next = i->next; - j->prev = i; - i->next = j; - if (j->next != 0) j->next->prev = j; - } - return (void *) (i + 1); -} - -void CMEM2Alloc::release(void *p) -{ - if (p == 0) return; - - LockMutex lock(m_mutex); - SBlock *i = (SBlock *) p - 1; - i->f = true; - - // If there are no other blocks following yet, - // set the remaining size to free size. - Dimok - if (i->next == 0) i->s = m_endAddress - i - 1; - - // Merge with previous block - if (i->prev != 0 && i->prev->f) - { - i = i->prev; - i->s += i->next->s + 1; - i->next = i->next->next; - if (i->next != 0) i->next->prev = i; - } - // Merge with next block - if (i->next != 0 && i->next->f) - { - i->s += i->next->s + 1; - i->next = i->next->next; - if (i->next != 0) i->next->prev = i; - } -} - -void *CMEM2Alloc::reallocate(void *p, unsigned int s) -{ - SBlock *i; - SBlock *j; - void *n; - - if (s == 0) s = 1; - if (p == 0) return allocate(s); - - i = (SBlock *) p - 1; - s = (s - 1) / sizeof(SBlock) + 1; - { - LockMutex lock(m_mutex); - - //out of memory /* Dimok */ - if (i + s + 1 >= m_endAddress) - { - return 0; - } - - // Last block - if (i->next == 0 && i + s + 1 < m_endAddress) - { - i->s = s; - return p; - } - // Size <= current size + next block - if (i->next != 0 && i->s < s && i->next->f && i->s + i->next->s + 1 >= s) - { - // Merge - i->s += i->next->s + 1; - i->next = i->next->next; - if (i->next != 0) i->next->prev = i; - } - // Size <= current size - if (i->s >= s) - { - // Split - if (i->s > s + 1) - { - j = i + s + 1; - j->f = true; - j->s = i->s - s - 1; - i->s = s; - j->next = i->next; - j->prev = i; - i->next = j; - if (j->next != 0) j->next->prev = j; - } - return p; - } - } - // Size > current size - n = allocate(s * sizeof(SBlock)); - if (n == 0) return 0; - memcpy(n, p, i->s * sizeof(SBlock)); - release(p); - return n; -} - -unsigned int CMEM2Alloc::FreeSize() -{ - LockMutex lock(m_mutex); - - if (m_first == 0) return (const char *) m_endAddress - (const char *) m_baseAddress; - - SBlock *i; - unsigned int size = 0; - - for (i = m_first; i != 0; i = i->next) - { - if (i->f && i->next != 0) - size += i->s; - - else if (i->f && i->next == 0) - size += m_endAddress - i - 1; - - else if (!i->f && i->next == 0) size += m_endAddress - i - i->s - 1; - } - - return size * sizeof(SBlock); -} diff --git a/source/memory/mem2alloc.hpp b/source/memory/mem2alloc.hpp deleted file mode 100644 index 7ee71fae..00000000 --- a/source/memory/mem2alloc.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// MEM2 allocator -// Made as a class so i can have 2 sections, one being dedicated to the covers - -#ifndef __MEM2ALLOC_HPP -#define __MEM2ALLOC_HPP - -#include - -class CMEM2Alloc -{ - public: - void *allocate(unsigned int s); - void release(void *p); - void *reallocate(void *p, unsigned int s); - void init(unsigned int size); - void init(void *addr, void *end); - void cleanup(void); - void clear(void); - static unsigned int usableSize(void *p); - void forceEndAddress(void *newAddr) - { - m_endAddress = (SBlock *) newAddr; - } - void *getEndAddress(void) const - { - return m_endAddress; - } - void info(void *&address, unsigned int &size) const - { - address = m_baseAddress; - size = (const char *) m_endAddress - (const char *) m_baseAddress; - } - unsigned int FreeSize(); - // - CMEM2Alloc(void) : - m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0) - { - } - private: - struct SBlock - { - unsigned int s; - SBlock *next; - SBlock *prev; - bool f; - }__attribute__((aligned(32))); - SBlock *m_baseAddress; - SBlock *m_endAddress; - SBlock *m_first; - mutex_t m_mutex; - private: - CMEM2Alloc(const CMEM2Alloc &); -}; - -#endif // !defined(__MEM2ALLOC_HPP) diff --git a/source/memory/memory.h b/source/memory/memory.h deleted file mode 100644 index 84250b91..00000000 --- a/source/memory/memory.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef __MEMORY_H_ -#define __MEMORY_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define Disc_ID ((u32*) 0x80000000) -#define Disc_Region ((u32*) 0x80000003) -#define Disc_Magic ((u32*) 0x80000018) -#define Sys_Magic ((u32*) 0x80000020) -#define Version ((u32*) 0x80000024) -#define Mem_Size ((u32*) 0x80000028) -#define Board_Model ((u32*) 0x8000002C) -#define Arena_L ((u32*) 0x80000030) -#define Arena_H ((u32*) 0x80000034) -#define FST ((u32*) 0x80000038) -#define Max_FST ((u32*) 0x8000003C) -#define Assembler ((u32*) 0x80000060) -#define Video_Mode ((u32*) 0x800000CC) -#define Dev_Debugger ((u32*) 0x800000EC) -#define Simulated_Mem ((u32*) 0x800000F0) -#define BI2 ((u32*) 0x800000F4) -#define Bus_Speed ((u32*) 0x800000F8) -#define CPU_Speed ((u32*) 0x800000FC) -#define Online_Check ((u32*) 0x80003180) -#define GameID_Address ((u32*) 0x80003184) - -#define allocate_memory(size) memalign(32, (size+31)&(~31)) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/menu.cpp b/source/menu.cpp deleted file mode 100644 index ae22fe5c..00000000 --- a/source/menu.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/**************************************************************************** - * USB Loader GX Team - * - * libwiigui Template - * by Tantric 2009 - * - * menu.cpp - * Menu flow routines - handles all menu logic - ***************************************************************************/ -#include - -#include "libwiigui/gui.h" -#include "homebrewboot/BootHomebrew.h" -#include "homebrewboot/HomebrewBrowse.h" -#include "prompts/ProgressWindow.h" -#include "menu/menus.h" -#include "mload/mload.h" -#include "mload/mload_modules.h" -#include "network/networkops.h" -#include "patches/patchcode.h" -#include "settings/Settings.h" -#include "settings/CGameSettings.h" -#include "themes/CTheme.h" -#include "themes/Theme_Downloader.h" -#include "usbloader/disc.h" -#include "usbloader/GameList.h" -#include "mload/mload_modules.h" -#include "xml/xml.h" -#include "audio.h" -#include "gecko.h" -#include "menu.h" -#include "sys.h" -#include "wpad.h" -#include "settings/newtitles.h" -#include "patches/fst.h" -#include "usbloader/frag.h" -#include "usbloader/wbfs.h" -#include "wad/nandtitle.h" - -/*** Variables that are also used extern ***/ -GuiWindow * mainWindow = NULL; -GuiImageData * pointer[4]; -GuiImage * bgImg = NULL; -GuiImageData * background = NULL; -GuiBGM * bgMusic = NULL; -GuiSound *btnSoundClick = NULL; -GuiSound *btnSoundClick2 = NULL; -GuiSound *btnSoundOver = NULL; - -int currentMenu; -u8 mountMethod = 0; - -char game_partition[6]; -int load_from_fs; - -/*** Variables used only in the menus ***/ -bool altdoldefault = true; - -static lwp_t guithread = LWP_THREAD_NULL; -static bool guiHalt = true; -static bool ExitRequested = false; - -/*** Extern variables ***/ -extern u8 shutdown; -extern u8 reset; -extern s32 gameSelected, gameStart; - -/**************************************************************************** - * ResumeGui - * - * Signals the GUI thread to start, and resumes the thread. This is called - * after finishing the removal/insertion of new elements, and after initial - * GUI setup. - ***************************************************************************/ -void ResumeGui() -{ - guiHalt = false; - LWP_ResumeThread(guithread); -} - -/**************************************************************************** - * HaltGui - * - * Signals the GUI thread to stop, and waits for GUI thread to stop - * This is necessary whenever removing/inserting new elements into the GUI. - * This eliminates the possibility that the GUI is in the middle of accessing - * an element that is being changed. - ***************************************************************************/ -void HaltGui() -{ - if (guiHalt) return; - guiHalt = true; - - // wait for thread to finish - while (!LWP_ThreadIsSuspended(guithread)) - usleep(100); -} - -/**************************************************************************** - * UpdateGUI - * - * Primary thread to allow GUI to respond to state changes, and draws GUI - ***************************************************************************/ -static void * UpdateGUI(void *arg) -{ - int i; - - while (!ExitRequested) - { - if (guiHalt) - { - LWP_SuspendThread(guithread); - continue; - } - - mainWindow->Draw(); - if (Settings.tooltips == ON && Theme::ShowTooltips && mainWindow->GetState() != STATE_DISABLED) mainWindow->DrawTooltip(); - - for (i = 3; i >= 0; i--) - { - if (userInput[i].wpad.ir.valid) - { - Menu_DrawImg(userInput[i].wpad.ir.x - 48, userInput[i].wpad.ir.y - 48, 200.0, 96, 96, - pointer[i]->GetImage(), userInput[i].wpad.ir.angle, Settings.widescreen ? 0.8 : 1, 1, 255, 0, - 0, 0, 0, 0, 0, 0, 0); - } - } - - Menu_Render(); - - UpdatePads(); - - for (i = 0; i < 4; i++) - mainWindow->Update(&userInput[i]); - - if (bgMusic) bgMusic->UpdateState(); - - switch (Settings.screensaver) - { - case 1: - WPad_SetIdleTime(180); - break; - case 2: - WPad_SetIdleTime(300); - break; - case 3: - WPad_SetIdleTime(600); - break; - case 4: - WPad_SetIdleTime(1200); - break; - case 5: - WPad_SetIdleTime(1800); - break; - case 6: - WPad_SetIdleTime(3600); - break; - } - } - - for (i = 5; i < 255; i += 10) - { - mainWindow->Draw(); - Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, i}, 1); - Menu_Render(); - } - - mainWindow->RemoveAll(); - ShutoffRumble(); - - return NULL; -} - -/**************************************************************************** - * InitGUIThread - * - * Startup GUI threads - ***************************************************************************/ -void InitGUIThreads() -{ - ExitRequested = false; - - if(guithread == LWP_THREAD_NULL) - LWP_CreateThread(&guithread, UpdateGUI, NULL, NULL, 65536, LWP_PRIO_HIGHEST); -} - -void ExitGUIThreads() -{ - ExitRequested = true; - - if(guithread != LWP_THREAD_NULL) - { - ResumeGui(); - LWP_JoinThread(guithread, NULL); - guithread = LWP_THREAD_NULL; - } -} - -/**************************************************************************** - * MainMenu - ***************************************************************************/ -int MainMenu(int menu) -{ - currentMenu = menu; - - InitGUIThreads(); - - InitProgressThread(); - InitNetworkThread(); - - if (Settings.autonetwork) - ResumeNetworkThread(); - - btnSoundClick = new GuiSound(button_click_wav, button_click_wav_size, Settings.sfxvolume); - btnSoundClick2 = new GuiSound(button_click2_wav, button_click2_wav_size, Settings.sfxvolume); - btnSoundOver = new GuiSound(button_over_wav, button_over_wav_size, Settings.sfxvolume); - - pointer[0] = Resources::GetImageData("player1_point.png"); - pointer[1] = Resources::GetImageData("player2_point.png"); - pointer[2] = Resources::GetImageData("player3_point.png"); - pointer[3] = Resources::GetImageData("player4_point.png"); - - mainWindow = new GuiWindow(screenwidth, screenheight); - - background = Resources::GetImageData(Settings.widescreen ? "wbackground.png" : "background.png"); - - bgImg = new GuiImage(background); - mainWindow->Append(bgImg); - - ResumeGui(); - - bgMusic = new GuiBGM(bg_music_ogg, bg_music_ogg_size, Settings.volume); - bgMusic->SetLoop(Settings.musicloopmode); //loop music - bgMusic->Load(Settings.ogg_path); - bgMusic->Play(); - - MountGamePartition(); - - while (currentMenu != MENU_EXIT) - { - bgMusic->SetVolume(Settings.volume); - - switch (currentMenu) - { - case MENU_INSTALL: - currentMenu = MenuInstall(); - break; - case MENU_SETTINGS: - currentMenu = MenuSettings(); - break; - case MENU_THEMEDOWNLOADER: - currentMenu = Theme_Downloader(); - break; - case MENU_HOMEBREWBROWSE: - currentMenu = MenuHomebrewBrowse(); - break; - case MENU_DISCLIST: - default: // unrecognized menu - currentMenu = MenuDiscList(); - break; - } - } - - //! THIS SHOULD NEVER HAPPEN ANYMORE - ExitApp(); - - return -1; -} diff --git a/source/menu.h b/source/menu.h deleted file mode 100644 index e9cee0b0..00000000 --- a/source/menu.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * menu.h - * Menu flow routines - handles all menu logic - ***************************************************************************/ - -#ifndef _MENU_H_ -#define _MENU_H_ - -#include -#include "libwiigui/gui.h" -#include "settings/CSettings.h" -#include "main.h" - -void InitGUIThreads(void); -void ExitGUIThreads(void); - -int MainMenu(int menuitem); - -enum -{ - MENU_EXIT = -1, - MENU_NONE, - MENU_SETTINGS, - MENU_DISCLIST, - MENU_INSTALL, - MENU_GAME_SETTINGS, - MENU_HOMEBREWBROWSE, - BOOTHOMEBREW, - MENU_THEMEDOWNLOADER -}; - -void ResumeGui(); -void HaltGui(); - -extern GuiImageData *pointer[4]; -extern GuiImageData *background; -extern GuiImage *bgImg; -extern GuiWindow *mainWindow; -extern GuiText *GameRegionTxt; -extern GuiText *GameIDTxt; -extern GuiImageData *cover; -extern GuiImage *coverImg; -extern FreeTypeGX *fontSystem; - -#endif diff --git a/source/menu/GameBrowseMenu.cpp b/source/menu/GameBrowseMenu.cpp deleted file mode 100644 index 0e8de255..00000000 --- a/source/menu/GameBrowseMenu.cpp +++ /dev/null @@ -1,1375 +0,0 @@ -#include -#include "GameBrowseMenu.hpp" -#include "libwiigui/LoadCoverImage.h" -#include "prompts/PromptWindows.h" -#include "prompts/gameinfo.h" -#include "prompts/DiscBrowser.h" -#include "prompts/GameWindow.hpp" -#include "themes/CTheme.h" -#include "language/gettext.h" -#include "usbloader/wbfs.h" -#include "usbloader/wdvd.h" -#include "usbloader/GameList.h" -#include "network/networkops.h" -#include "network/update.h" -#include "network/CoverDownload.h" -#include "FileOperations/fileops.h" -#include "settings/Settings.h" -#include "settings/CSettings.h" -#include "settings/CGameStatistics.h" -#include "settings/CGameSettings.h" -#include "settings/GameTitles.h" -#include "utils/StringTools.h" -#include "GameBootProcess.h" -#include "utils/rockout.h" -#include "utils/ShowError.h" -#include "utils/tools.h" -#include "utils/PasswordCheck.h" -#include "fatmounter.h" -#include "gecko.h" -#include "menus.h" -#include "wpad.h" -#include "sys.h" - -extern int load_from_fs; -extern u8 mountMethod; -extern bool updateavailable; -extern struct discHdr *dvdheader; -extern int cntMissFiles; - -static int lastSelectedGame = 0; - -GameBrowseMenu::GameBrowseMenu() - : GuiWindow(screenwidth, screenheight) -{ - float freespace = 0.0, used = 0.0; - returnMenu = MENU_NONE; - gameSelectedOld = -1; - lastrawtime = 0; - show_searchwindow = false; - gameBrowser = NULL; - gameGrid = NULL; - gameCarousel = NULL; - searchBar = NULL; - gameCover = NULL; - gameCoverImg = NULL; - GameIDTxt = NULL; - GameRegionTxt = NULL; - ScreensaverTimer = 0; - WDVD_GetCoverStatus(&DiscDriveCoverOld); - wString oldFilter(gameList.GetCurrentFilter()); - gameList.FilterList(oldFilter.c_str()); - - if (WBFS_ShowFreeSpace()) - WBFS_DiskSpace(&used, &freespace); - - btnInstall = Resources::GetImageData("button_install.png"); - btnInstallOver = Resources::GetImageData("button_install_over.png"); - btnSettings = Resources::GetImageData("settings_button.png"); - btnSettingsOver = Resources::GetImageData("settings_button_over.png"); - btnpwroff = Resources::GetImageData("wiimote_poweroff.png"); - btnpwroffOver = Resources::GetImageData("wiimote_poweroff_over.png"); - btnhome = Resources::GetImageData("menu_button.png"); - btnhomeOver = Resources::GetImageData("menu_button_over.png"); - btnsdcardOver = Resources::GetImageData("sdcard_over.png"); - btnsdcard = Resources::GetImageData("sdcard.png"); - - imgfavIcon = Resources::GetImageData("favIcon.png"); - imgfavIcon_gray = Resources::GetImageData("favIcon_gray.png"); - imgsearchIcon = Resources::GetImageData("searchIcon.png"); - imgsearchIcon_gray = Resources::GetImageData("searchIcon_gray.png"); - imgabcIcon = Resources::GetImageData("abcIcon.png"); - imgrankIcon = Resources::GetImageData("rankIcon.png"); - imgplayCountIcon = Resources::GetImageData("playCountIcon.png"); - imgarrangeGrid = Resources::GetImageData("arrangeGrid.png"); - imgarrangeGrid_gray = Resources::GetImageData("arrangeGrid_gray.png"); - imgarrangeList = Resources::GetImageData("arrangeList.png"); - imgarrangeList_gray = Resources::GetImageData("arrangeList_gray.png"); - imgarrangeCarousel = Resources::GetImageData("arrangeCarousel.png"); - imgarrangeCarousel_gray = Resources::GetImageData("arrangeCarousel_gray.png"); - imgdvd = Resources::GetImageData("dvd.png"); - imgdvd_gray = Resources::GetImageData("dvd_gray.png"); - imgLock = Resources::GetImageData("lock.png"); - imgLock_gray = Resources::GetImageData("lock_gray.png"); - imgUnlock = Resources::GetImageData("unlock.png"); - imgUnlock_gray = Resources::GetImageData("unlock_gray.png"); - - homebrewImgData = Resources::GetImageData("browser.png"); - homebrewImgDataOver = Resources::GetImageData("browser_over.png"); - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigHome = new GuiTrigger; - trigHome->SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, PAD_BUTTON_START); - trig2 = new GuiTrigger; - trig2->SetButtonOnlyTrigger(-1, WPAD_BUTTON_2 | WPAD_CLASSIC_BUTTON_X, 0); - trig1 = new GuiTrigger; - trig1->SetButtonOnlyTrigger(-1, WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_Y, 0); - - char spaceinfo[30]; - if (load_from_fs == PART_FS_FAT) - { - memset(spaceinfo, 0, 30); - } - else - { - if (strcmp(Settings.db_language, "JA") == 0) - { - // needs to be "total...used" for Japanese - sprintf(spaceinfo, "%.2fGB %s %.2fGB %s", (freespace + used), tr( "of" ), freespace, tr( "free" )); - } - else - { - sprintf(spaceinfo, "%.2fGB %s %.2fGB %s", freespace, tr( "of" ), (freespace + used), tr( "free" )); - } - } - usedSpaceTxt = new GuiText(spaceinfo, 18, thColor("r=55 g=190 b=237 a=255 - hdd info color")); - usedSpaceTxt->SetAlignment(thAlign("center - hdd info align ver"), thAlign("top - hdd info align hor")); - usedSpaceTxt->SetPosition(thInt("0 - hdd info pos x"), thInt("400 - hdd info pos y")); - - gamecntTxt = new GuiText((char *) NULL, 18, thColor("r=55 g=190 b=237 a=255 - game count color")); - gamecntBtn = new GuiButton(100, 18); - gamecntBtn->SetAlignment(thAlign("center - game count align ver"), thAlign("top - game count align hor")); - gamecntBtn->SetPosition(thInt("0 - game count pos x"), thInt("420 - game count pos y")); - gamecntBtn->SetLabel(gamecntTxt); - gamecntBtn->SetEffectGrow(); - gamecntBtn->SetTrigger(trigA); - - installBtnTT = new GuiTooltip(tr( "Install a game" )); - if (Settings.wsprompt) installBtnTT->SetWidescreen(Settings.widescreen); - installBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - installBtnImg = new GuiImage(btnInstall); - installBtnImgOver = new GuiImage(btnInstallOver); - installBtnImg->SetWidescreen(Settings.widescreen); - installBtnImgOver->SetWidescreen(Settings.widescreen); - - installBtn = new GuiButton(installBtnImg, installBtnImgOver, ALIGN_LEFT, ALIGN_TOP, - thInt("16 - install btn pos x"), thInt("355 - install btn pos y"), - trigA, btnSoundOver, btnSoundClick2, 1, installBtnTT, 24, -30, 0, 5); - - settingsBtnTT = new GuiTooltip(tr( "Settings" )); - if (Settings.wsprompt) settingsBtnTT->SetWidescreen(Settings.widescreen); - settingsBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - settingsBtnImg = new GuiImage(btnSettings); - settingsBtnImg->SetWidescreen(Settings.widescreen); - settingsBtnImgOver = new GuiImage(btnSettingsOver); - settingsBtnImgOver->SetWidescreen(Settings.widescreen); - settingsBtn = new GuiButton(settingsBtnImg, settingsBtnImgOver, 0, 3, - thInt("64 - settings btn pos x"), thInt("371 - settings btn pos y"), - trigA, btnSoundOver, btnSoundClick2, 1, settingsBtnTT, 65, -30, 0, 5); - - homeBtnTT = new GuiTooltip(tr( "Back to HBC or Wii Menu" )); - if (Settings.wsprompt) homeBtnTT->SetWidescreen(Settings.widescreen); - settingsBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - homeBtnImg = new GuiImage(btnhome); - homeBtnImg->SetWidescreen(Settings.widescreen); - homeBtnImgOver = new GuiImage(btnhomeOver); - homeBtnImgOver->SetWidescreen(Settings.widescreen); - homeBtn = new GuiButton(homeBtnImg, homeBtnImgOver, 0, 3, - thInt("489 - home menu btn pos x"), thInt("371 - home menu btn pos x"), - trigA, btnSoundOver, btnSoundClick2, 1, homeBtnTT, 15, -30, 1, 5); - homeBtn->RemoveSoundClick(); - homeBtn->SetTrigger(trigHome); - - poweroffBtnTT = new GuiTooltip(tr( "Power off the Wii" )); - if (Settings.wsprompt) poweroffBtnTT->SetWidescreen(Settings.widescreen); - poweroffBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - poweroffBtnImg = new GuiImage(btnpwroff); - poweroffBtnImgOver = new GuiImage(btnpwroffOver); - poweroffBtnImg->SetWidescreen(Settings.widescreen); - poweroffBtnImgOver->SetWidescreen(Settings.widescreen); - poweroffBtn = new GuiButton(poweroffBtnImg, poweroffBtnImgOver, 0, 3, - thInt("576 - power off btn pos x"), thInt("355 - power off btn pos y"), - trigA, btnSoundOver, btnSoundClick2, 1, poweroffBtnTT, -10, -30, 1, 5); - - sdcardBtnTT = new GuiTooltip(tr( "Reload SD" )); - if (Settings.wsprompt) sdcardBtnTT->SetWidescreen(Settings.widescreen); - sdcardBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - sdcardImg = new GuiImage(btnsdcard); - sdcardImgOver = new GuiImage(btnsdcardOver); - sdcardImg->SetWidescreen(Settings.widescreen); - sdcardImgOver->SetWidescreen(Settings.widescreen); - sdcardBtn = new GuiButton(sdcardImg, sdcardImgOver, 0, 3, - thInt("160 - sd card btn pos x"), thInt("395 - sd card btn pos y"), - trigA, btnSoundOver, btnSoundClick2, 1, sdcardBtnTT, 15, -30, 0, 5); - - gameInfo = new GuiButton(0, 0); - gameInfo->SetTrigger(trig2); - gameInfo->SetSoundClick(btnSoundClick2); - - favoriteBtnTT = new GuiTooltip(tr( "Display favorites only" )); - if (Settings.wsprompt) favoriteBtnTT->SetWidescreen(Settings.widescreen); - favoriteBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - favoriteBtnImg = new GuiImage(imgfavIcon); - favoriteBtnImg->SetWidescreen(Settings.widescreen); - favoriteBtnImg_g = new GuiImage(imgfavIcon_gray); - favoriteBtnImg_g->SetWidescreen(Settings.widescreen); - favoriteBtn = new GuiButton(favoriteBtnImg_g, favoriteBtnImg_g, ALIGN_LEFT, ALIGN_TOP, - 0, 0, - trigA, btnSoundOver, btnSoundClick2, 1, favoriteBtnTT, -15, 52, 0, 3); - - searchBtnTT = new GuiTooltip(tr( "Set Search-Filter" )); - if (Settings.wsprompt) searchBtnTT->SetWidescreen(Settings.widescreen); - searchBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - searchBtnImg = new GuiImage(imgsearchIcon); - searchBtnImg->SetWidescreen(Settings.widescreen); - searchBtnImg_g = new GuiImage(imgsearchIcon_gray); - searchBtnImg_g->SetWidescreen(Settings.widescreen); - searchBtn = new GuiButton(searchBtnImg_g, searchBtnImg_g, ALIGN_LEFT, ALIGN_TOP, - 0, 0, - trigA, btnSoundOver, btnSoundClick2, 1, searchBtnTT, -15, 52, 0, 3); - - sortBtnTT = new GuiTooltip(" "); - if (Settings.wsprompt) sortBtnTT->SetWidescreen(Settings.widescreen); - sortBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - - sortBtnImg = new GuiImage(imgabcIcon); - sortBtnImg->SetWidescreen(Settings.widescreen); - sortBtn = new GuiButton(sortBtnImg, sortBtnImg, ALIGN_LEFT, ALIGN_TOP, 0, 0, trigA, btnSoundOver, btnSoundClick2, 1, sortBtnTT, -15, 52, 0, 3); - - listBtnTT = new GuiTooltip(tr( "Display as a list" )); - if (Settings.wsprompt) listBtnTT->SetWidescreen(Settings.widescreen); - listBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - listBtnImg = new GuiImage(imgarrangeList); - listBtnImg->SetWidescreen(Settings.widescreen); - listBtnImg_g = new GuiImage(imgarrangeList_gray); - listBtnImg_g->SetWidescreen(Settings.widescreen); - listBtn = new GuiButton(listBtnImg_g, listBtnImg_g, ALIGN_LEFT, ALIGN_TOP, 0, 0, trigA, btnSoundOver, btnSoundClick2, 1, listBtnTT, 15, 52, 1, 3); - - gridBtnTT = new GuiTooltip(tr( "Display as a grid" )); - if (Settings.wsprompt) gridBtnTT->SetWidescreen(Settings.widescreen); - gridBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - gridBtnImg = new GuiImage(imgarrangeGrid); - gridBtnImg->SetWidescreen(Settings.widescreen); - gridBtnImg_g = new GuiImage(imgarrangeGrid_gray); - gridBtnImg_g->SetWidescreen(Settings.widescreen); - gridBtn = new GuiButton(gridBtnImg_g, gridBtnImg_g, ALIGN_LEFT, ALIGN_TOP, 0, 0, trigA, btnSoundOver, btnSoundClick2, 1, gridBtnTT, 15, 52, 1, 3); - - carouselBtnTT = new GuiTooltip(tr( "Display as a carousel" )); - if (Settings.wsprompt) carouselBtnTT->SetWidescreen(Settings.widescreen); - carouselBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - carouselBtnImg = new GuiImage(imgarrangeCarousel); - carouselBtnImg->SetWidescreen(Settings.widescreen); - carouselBtnImg_g = new GuiImage(imgarrangeCarousel_gray); - carouselBtnImg_g->SetWidescreen(Settings.widescreen); - carouselBtn = new GuiButton(carouselBtnImg_g, carouselBtnImg_g, ALIGN_LEFT, ALIGN_TOP, 0, 0, trigA, btnSoundOver, btnSoundClick2, 1, carouselBtnTT, 15, 52, 1, 3); - - lockBtnTT = new GuiTooltip(NULL); - if (Settings.wsprompt) lockBtnTT->SetWidescreen(Settings.widescreen); - lockBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - lockBtnImg = new GuiImage(imgLock); - lockBtnImg->SetWidescreen(Settings.widescreen); - lockBtnImg_g = new GuiImage(imgLock_gray); - lockBtnImg_g->SetWidescreen(Settings.widescreen); - lockBtn = new GuiButton(lockBtnImg_g, lockBtnImg_g, ALIGN_LEFT, ALIGN_TOP, 0, 0, trigA, btnSoundOver, btnSoundClick2, 1, lockBtnTT, 15, 52, 1, 3); - - unlockBtnImg = new GuiImage(imgUnlock); - unlockBtnImg->SetWidescreen(Settings.widescreen); - unlockBtnImg_g = new GuiImage(imgUnlock_gray); - unlockBtnImg_g->SetWidescreen(Settings.widescreen); - - dvdBtnTT = new GuiTooltip(tr( "Mount DVD drive" )); - if (Settings.wsprompt) dvdBtnTT->SetWidescreen(Settings.widescreen); - dvdBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - dvdBtnImg = new GuiImage(imgdvd); - dvdBtnImg->SetWidescreen(Settings.widescreen); - dvdBtnImg_g = new GuiImage(imgdvd_gray); - dvdBtnImg_g->SetWidescreen(Settings.widescreen); - dvdBtn = new GuiButton(dvdBtnImg_g, dvdBtnImg_g, ALIGN_LEFT, ALIGN_TOP, 0, 0, - trigA, btnSoundOver, btnSoundClick2, 1, dvdBtnTT, 15, 52, 1, 3); - - homebrewBtnTT = new GuiTooltip(tr( "Homebrew Launcher" )); - if (Settings.wsprompt) homebrewBtnTT->SetWidescreen(Settings.widescreen); - homebrewBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - homebrewImg = new GuiImage(homebrewImgData); - homebrewImgOver = new GuiImage(homebrewImgDataOver); - homebrewImg->SetWidescreen(Settings.widescreen); - homebrewImgOver->SetWidescreen(Settings.widescreen); - homebrewBtn = new GuiButton(homebrewImg, homebrewImgOver, ALIGN_LEFT, ALIGN_TOP, thInt("410 - HBC btn pos x"), thInt("405 - HBC btn pos y"), - trigA, btnSoundOver, btnSoundClick2, 1, homebrewBtnTT, 15, -30, 1, 5); - //Downloading Covers - DownloadBtnTT = new GuiTooltip(tr( "Click to Download Covers" )); - if (Settings.wsprompt) DownloadBtnTT->SetWidescreen(Settings.widescreen); - DownloadBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - DownloadBtn = new GuiButton (0, 0); - DownloadBtn->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - DownloadBtn->SetPosition(thInt("26 - cover/download btn pos x"), thInt("58 - cover/download btn pos y")); - - IDBtnTT = new GuiTooltip(tr( "Click to change game ID" )); - if (Settings.wsprompt) IDBtnTT->SetWidescreen(Settings.widescreen); - IDBtnTT->SetAlpha(thInt("255 - tooltip alpha")); - idBtn = new GuiButton(60, 23); - idBtn->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - idBtn->SetPosition(thInt("68 - gameID btn pos x"), thInt("305 - gameID btn pos y")); - - GXColor clockColor = thColor("r=138 g=138 b=138 a=240 - clock color"); - clockTimeBack = new GuiText("88:88", 40, (GXColor) {clockColor.r, clockColor.g, clockColor.b, clockColor.a / 6}); - clockTimeBack->SetAlignment(thAlign("left - clock align ver"), thAlign("top - clock align hor")); - clockTimeBack->SetPosition(thInt("275 - clock pos x"), thInt("275 - clock pos y")); - clockTimeBack->SetFont(clock_ttf, clock_ttf_size); - - clockTime = new GuiText("", 40, clockColor); - clockTime->SetAlignment(thAlign("left - clock align ver"), thAlign("top - clock align hor")); - clockTime->SetPosition(thInt("275 - clock pos x"), thInt("275 - clock pos y")); - clockTime->SetFont(clock_ttf, clock_ttf_size); - - ToolBar.push_back(favoriteBtn); - ToolBar.push_back(searchBtn); - ToolBar.push_back(sortBtn); - ToolBar.push_back(listBtn); - ToolBar.push_back(gridBtn); - ToolBar.push_back(carouselBtn); - ToolBar.push_back(lockBtn); - ToolBar.push_back(dvdBtn); - SetUpdateCallback(UpdateCallback); - - ReloadBrowser(); -} - -GameBrowseMenu::~GameBrowseMenu() -{ - ResumeGui(); - - SetEffect(EFFECT_FADE, -20); - while(parentElement && this->GetEffect() > 0) usleep(100); - - HaltGui(); - if(parentElement) - ((GuiWindow *) parentElement)->Remove(this); - - RemoveAll(); - - delete btnInstall; - delete btnInstallOver; - delete btnSettings; - delete btnSettingsOver; - delete btnpwroff; - delete btnpwroffOver; - delete btnhome; - delete btnhomeOver; - delete btnsdcardOver; - delete btnsdcard; - delete imgfavIcon; - delete imgfavIcon_gray; - delete imgsearchIcon; - delete imgsearchIcon_gray; - delete imgabcIcon; - delete imgrankIcon; - delete imgplayCountIcon; - delete imgarrangeGrid; - delete imgarrangeGrid_gray; - delete imgarrangeCarousel; - delete imgarrangeCarousel_gray; - delete imgarrangeList; - delete imgarrangeList_gray; - delete imgdvd; - delete imgdvd_gray; - delete imgLock; - delete imgLock_gray; - delete imgUnlock; - delete imgUnlock_gray; - delete homebrewImgData; - delete homebrewImgDataOver; - delete gameCover; - - delete trigA; - delete trigHome; - delete trig1; - delete trig2; - - delete installBtnImg; - delete installBtnImgOver; - delete settingsBtnImg; - delete settingsBtnImgOver; - delete homeBtnImg; - delete homeBtnImgOver; - delete poweroffBtnImg; - delete poweroffBtnImgOver; - delete sdcardImg; - delete sdcardImgOver; - delete favoriteBtnImg; - delete favoriteBtnImg_g; - delete searchBtnImg; - delete searchBtnImg_g; - delete sortBtnImg; - delete listBtnImg; - delete listBtnImg_g; - delete gridBtnImg; - delete gridBtnImg_g; - delete carouselBtnImg; - delete carouselBtnImg_g; - delete lockBtnImg; - delete lockBtnImg_g; - delete unlockBtnImg; - delete unlockBtnImg_g; - delete dvdBtnImg; - delete dvdBtnImg_g; - delete homebrewImg; - delete homebrewImgOver; - delete gameCoverImg; - - delete GameIDTxt; - delete GameRegionTxt; - delete usedSpaceTxt; - delete gamecntTxt; - delete clockTimeBack; - delete clockTime; - - delete gamecntBtn; - delete installBtn; - delete settingsBtn; - delete homeBtn; - delete poweroffBtn; - delete sdcardBtn; - delete gameInfo; - delete favoriteBtn; - delete searchBtn; - delete sortBtn; - delete listBtn; - delete gridBtn; - delete carouselBtn; - delete lockBtn; - delete dvdBtn; - delete homebrewBtn; - delete DownloadBtn; - delete idBtn; - - delete installBtnTT; - delete settingsBtnTT; - delete homeBtnTT; - delete poweroffBtnTT; - delete sdcardBtnTT; - delete favoriteBtnTT; - delete searchBtnTT; - delete sortBtnTT; - delete listBtnTT; - delete gridBtnTT; - delete carouselBtnTT; - delete lockBtnTT; - delete dvdBtnTT; - delete homebrewBtnTT; - delete DownloadBtnTT; - delete IDBtnTT; - - lastSelectedGame = cut_bounds(GetSelectedGame(), 0, gameList.size()-1); - - delete gameBrowser; - delete gameGrid; - delete gameCarousel; - mainWindow->Remove(searchBar); - delete searchBar; - - ResumeGui(); -} - -void GameBrowseMenu::ReloadBrowser() -{ - ResumeGui(); - - SetEffect(EFFECT_FADE, -40); - while(parentElement && this->GetEffect() > 0) usleep(100); - - HaltGui(); - RemoveAll(); - mainWindow->Remove(searchBar); - - gamecntTxt->SetText(fmt("%s: %i", tr( "Games" ), gameList.size())); - - const char * sortTTText = NULL; - GuiImageData * sortImgData = NULL; - - if(Settings.GameSort & SORT_RANKING) - { - sortTTText = tr( "Sort by rank" ); - sortImgData = imgrankIcon; - } - else if(Settings.GameSort & SORT_PLAYCOUNT) - { - sortTTText = tr( "Sort order by most played"); - sortImgData = imgplayCountIcon; - } - else - { - sortTTText = tr("Sort alphabetically"); - sortImgData = imgabcIcon; - } - - sortBtnTT->SetText(sortTTText); - sortBtnImg->SetImage(sortImgData); - - if(DiscDriveCoverOld & 0x02) - dvdBtn->SetImage(dvdBtnImg); - else - dvdBtn->SetImage(dvdBtnImg_g); - - if (Settings.GameSort & SORT_FAVORITE) - { - favoriteBtn->SetImage(favoriteBtnImg); - favoriteBtn->SetImageOver(favoriteBtnImg); - } - else - { - favoriteBtn->SetImage(favoriteBtnImg_g); - favoriteBtn->SetImageOver(favoriteBtnImg_g); - } - - if (*gameList.GetCurrentFilter()) - { - if (!show_searchwindow) searchBtn->SetEffect(EFFECT_PULSE, 10, 105); - searchBtn->SetImage(searchBtnImg); - searchBtn->SetImageOver(searchBtnImg); - } - else if(!show_searchwindow) - { - searchBtn->SetImage(searchBtnImg_g); - searchBtn->SetImageOver(searchBtnImg_g); - } - - if (Settings.godmode == 1) //only make the button have trigger & tooltip if in godmode - { - DownloadBtn->SetSoundOver(btnSoundOver); - DownloadBtn->SetTrigger(0, trigA); - DownloadBtn->SetTrigger(1, trig1); - DownloadBtn->SetToolTip(DownloadBtnTT, 205, -30); - idBtn->SetSoundOver(btnSoundOver); - idBtn->SetTrigger(0, trigA); - idBtn->SetToolTip(IDBtnTT, 205, -30); - } - else - { - DownloadBtn->SetToolTip(NULL, 0, 0); - DownloadBtn->SetSoundOver(NULL); - DownloadBtn->SetTrigger(0, NULL); - DownloadBtn->SetTrigger(1, NULL); - idBtn->SetSoundOver(NULL); - idBtn->SetTrigger(0, NULL); - idBtn->SetToolTip(NULL, 0, 0); - } - - if (Settings.godmode) - { - GuiImage * unlockImage = strcmp(Settings.unlockCode, "") == 0 ? unlockBtnImg_g : unlockBtnImg; - lockBtn->SetImage(unlockImage); - lockBtn->SetImageOver(unlockImage); - lockBtnTT->SetText(tr( "Lock USB Loader GX" )); - } - else - { - lockBtn->SetImage(lockBtnImg); - lockBtn->SetImageOver(lockBtnImg); - lockBtnTT->SetText(tr( "Unlock USB Loader GX" )); - } - - if(GetSelectedGame() >= 0) - lastSelectedGame = cut_bounds(GetSelectedGame(), 0, gameList.size()-1); - else - lastSelectedGame = cut_bounds(lastSelectedGame, 0, gameList.size()-1); - - delete gameBrowser; - delete gameGrid; - delete gameCarousel; - delete searchBar; - gameBrowser = NULL; - gameGrid = NULL; - gameCarousel = NULL; - searchBar = NULL; - - if (Settings.gameDisplay == LIST_MODE) - { - DownloadBtn->SetSize(160, 224); - listBtn->SetImage(listBtnImg); - listBtn->SetImageOver(listBtnImg); - gridBtn->SetImage(gridBtnImg_g); - gridBtn->SetImageOver(gridBtnImg_g); - carouselBtn->SetImage(carouselBtnImg_g); - carouselBtn->SetImageOver(carouselBtnImg_g); - - favoriteBtn->SetPosition(Settings.widescreen ? thInt("288 - list layout favorite btn pos x widescreen") : thInt("260 - list layout favorite btn pos x"), - thInt("13 - list layout favorite btn pos y")); - searchBtn->SetPosition(Settings.widescreen ? thInt("320 - list layout search btn pos x widescreen") : thInt("300 - list layout search btn pos x"), - thInt("13 - list layout search btn pos x")); - sortBtn->SetPosition(Settings.widescreen ? thInt("352 - list layout abc/sort btn pos x widescreen") : thInt("340 - list layout abc/sort btn pos x"), - thInt("13 - list layout abc/sort btn pos y")); - listBtn->SetPosition(Settings.widescreen ? thInt("384 - list layout list btn pos x widescreen") : thInt("380 - list layout list btn pos x"), - thInt("13 - list layout list btn pos y")); - gridBtn->SetPosition(Settings.widescreen ? thInt("416 - list layout grid btn pos x widescreen") : thInt("420 - list layout grid btn pos x"), - thInt("13 - list layout grid btn pos y")); - carouselBtn->SetPosition(Settings.widescreen ? thInt("448 - list layout carousel btn pos x widescreen") : thInt("460 - list layout carousel btn pos x"), - thInt("13 - list layout carousel btn pos y")); - lockBtn->SetPosition(Settings.widescreen ? thInt("480 - list layout lock btn pos x widescreen") : thInt("500 - list layout lock btn pos x"), - thInt("13 - list layout lock btn pos y")); - dvdBtn->SetPosition(Settings.widescreen ? thInt("512 - list layout dvd btn pos x widescreen") : thInt("540 - list layout dvd btn pos x"), - thInt("13 - list layout dvd btn pos y")); - - gameBrowser = new GuiGameBrowser(thInt("396 - game list layout width"), thInt("280 - game list layout height"), lastSelectedGame); - gameBrowser->SetPosition(thInt("200 - game list layout pos x"), thInt("49 - game list layout pos y")); - gameBrowser->SetAlignment(ALIGN_LEFT, ALIGN_CENTRE); - } - else if (Settings.gameDisplay == GRID_MODE) - { - DownloadBtn->SetImage(NULL); - DownloadBtn->SetSize(0, 0); - UpdateGameInfoText(NULL); - gridBtn->SetImage(gridBtnImg); - gridBtn->SetImageOver(gridBtnImg); - listBtn->SetImage(listBtnImg_g); - listBtn->SetImageOver(listBtnImg_g); - carouselBtn->SetImage(carouselBtnImg_g); - carouselBtn->SetImageOver(carouselBtnImg_g); - - favoriteBtn->SetPosition(Settings.widescreen ? thInt("224 - grid layout favorite btn pos x widescreen") : thInt("200 - grid layout favorite btn pos x"), - thInt("13 - grid layout favorite btn pos y")); - searchBtn->SetPosition(Settings.widescreen ? thInt("256 - grid layout search btn pos x widescreen") : thInt("240 - grid layout search btn pos x"), - thInt("13 - grid layout search btn pos x")); - sortBtn->SetPosition(Settings.widescreen ? thInt("288 - grid layout abc/sort btn pos x widescreen") : thInt("280 - grid layout abc/sort btn pos x"), - thInt("13 - grid layout abc/sort btn pos y")); - listBtn->SetPosition(Settings.widescreen ? thInt("320 - grid layout list btn pos x widescreen") : thInt("320 - grid layout list btn pos x"), - thInt("13 - grid layout list btn pos y")); - gridBtn->SetPosition(Settings.widescreen ? thInt("352 - grid layout grid btn pos x widescreen") : thInt("360 - grid layout grid btn pos x"), - thInt("13 - grid layout grid btn pos y")); - carouselBtn->SetPosition(Settings.widescreen ? thInt("384 - grid layout carousel btn pos x widescreen") : thInt("400 - grid layout carousel btn pos x"), - thInt("13 - grid layout carousel btn pos y")); - lockBtn->SetPosition(Settings.widescreen ? thInt("416 - grid layout lock btn pos x widescreen") : thInt("440 - grid layout lock btn pos x"), - thInt("13 - grid layout lock btn pos y")); - dvdBtn->SetPosition(Settings.widescreen ? thInt("448 - grid layout dvd btn pos x widescreen") : thInt("480 - grid layout dvd btn pos x"), - thInt("13 - grid layout dvd btn pos y")); - - gameGrid = new GuiGameGrid(thInt("640 - game grid layout width"), thInt("400 - game grid layout height"), Settings.theme_path, bg_options_png, lastSelectedGame); - gameGrid->SetPosition(thInt("0 - game grid layout pos x"), thInt("20 - game grid layout pos y")); - gameGrid->SetAlignment(ALIGN_LEFT, ALIGN_CENTRE); - } - else if (Settings.gameDisplay == CAROUSEL_MODE) - { - DownloadBtn->SetImage(NULL); - DownloadBtn->SetSize(0, 0); - UpdateGameInfoText(NULL); - carouselBtn->SetImage(carouselBtnImg); - carouselBtn->SetImageOver(carouselBtnImg); - listBtn->SetImage(listBtnImg_g); - listBtn->SetImageOver(listBtnImg_g); - gridBtn->SetImage(gridBtnImg_g); - gridBtn->SetImageOver(gridBtnImg_g); - - favoriteBtn->SetPosition(Settings.widescreen ? thInt("224 - carousel layout favorite btn pos x widescreen") : thInt("200 - carousel layout favorite btn pos x"), - thInt("13 - carousel layout favorite btn pos y")); - searchBtn->SetPosition(Settings.widescreen ? thInt("256 - carousel layout search btn pos x widescreen") : thInt("240 - carousel layout search btn pos x"), - thInt("13 - carousel layout search btn pos x")); - sortBtn->SetPosition(Settings.widescreen ? thInt("288 - carousel layout abc/sort btn pos x widescreen") : thInt("280 - carousel layout abc/sort btn pos x"), - thInt("13 - carousel layout abc/sort btn pos y")); - listBtn->SetPosition(Settings.widescreen ? thInt("320 - carousel layout list btn pos x widescreen") : thInt("320 - carousel layout list btn pos x"), - thInt("13 - carousel layout list btn pos y")); - gridBtn->SetPosition(Settings.widescreen ? thInt("352 - carousel layout grid btn pos x widescreen") : thInt("360 - carousel layout grid btn pos x"), - thInt("13 - carousel layout grid btn pos y")); - carouselBtn->SetPosition(Settings.widescreen ? thInt("384 - carousel layout carousel btn pos x widescreen") : thInt("400 - carousel layout carousel btn pos x"), - thInt("13 - carousel layout carousel btn pos y")); - lockBtn->SetPosition(Settings.widescreen ? thInt("416 - carousel layout lock btn pos x widescreen") : thInt("440 - carousel layout lock btn pos x"), - thInt("13 - carousel layout lock btn pos y")); - dvdBtn->SetPosition(Settings.widescreen ? thInt("448 - carousel layout dvd btn pos x widescreen") : thInt("480 - carousel layout dvd btn pos x"), - thInt("13 - carousel layout dvd btn pos y")); - - gameCarousel = new GuiGameCarousel(thInt("640 - game carousel layout width"), thInt("400 - game carousel layout height"), Settings.theme_path, bg_options_png, lastSelectedGame); - gameCarousel->SetPosition(thInt("0 - game carousel layout pos x"), thInt("-20 - game carousel layout pos y")); - gameCarousel->SetAlignment(ALIGN_LEFT, ALIGN_CENTRE); - } - - - if (thInt("1 - show hdd info: 1 for on and 0 for off") == 1) //force show hdd info - Append(usedSpaceTxt); - if (thInt("1 - show game count: 1 for on and 0 for off") == 1) //force show game cnt info - Append(gamecntBtn); - Append(sdcardBtn); - Append(poweroffBtn); - Append(gameInfo); - if (Settings.godmode) Append(installBtn); - Append(homeBtn); - Append(settingsBtn); - Append(DownloadBtn); - Append(idBtn); - Append(homebrewBtn); - - Append(favoriteBtn); - Append(searchBtn); - Append(sortBtn); - Append(listBtn); - Append(gridBtn); - Append(carouselBtn); - Append(lockBtn); - Append(dvdBtn); - - if ((Settings.hddinfo == CLOCK_HR12) || (Settings.hddinfo == CLOCK_HR24)) - { - Append(clockTimeBack); - Append(clockTime); - } - - if (gameBrowser) - Append(gameBrowser); - - else if (gameGrid) - Append(gameGrid); - - else if (gameCarousel) - Append(gameCarousel); - - if (show_searchwindow) - { - searchBar = new GuiSearchBar(gameList.GetAvailableSearchChars()); - mainWindow->Append(searchBar); - } - - SetEffect(EFFECT_FADE, 40); - ResumeGui(); - - while(parentElement && this->GetEffect() > 0) usleep(100); -} - -int GameBrowseMenu::Show() -{ - int menu = MENU_NONE; - - while(menu == MENU_NONE) - { - usleep(100); - - if (shutdown) - Sys_Shutdown(); - if (reset) - Sys_Reboot(); - - menu = MainLoop(); - } - - return menu; -} - - -int GameBrowseMenu::MainLoop() -{ - UpdateClock(); - CheckDiscSlotUpdate(); - - if (updateavailable == true) - { - gprintf("\tUpdate Available\n"); - SetState(STATE_DISABLED); - UpdateApp(); - updateavailable = false; - SetState(STATE_DEFAULT); - } - - else if (poweroffBtn->GetState() == STATE_CLICKED) - { - gprintf("\tpoweroffBtn clicked\n"); - int choice = WindowPrompt(tr( "How to Shutdown?" ), 0, tr( "Full Shutdown" ), tr( "Shutdown to Idle" ), tr( "Cancel" )); - if (choice == 2) - Sys_ShutdownToIdle(); - else if (choice == 1) - Sys_ShutdownToStandby(); - - poweroffBtn->ResetState(); - } - else if (gamecntBtn->GetState() == STATE_CLICKED) - { - gprintf("\tgameCntBtn clicked\n"); - gamecntBtn->ResetState(); - - int choice = WindowPrompt(0, fmt("%s %sGameList ?", tr( "Save Game List to" ), Settings.update_path), "TXT", "CSV", tr( "Back" )); - if (choice) - { - if (save_gamelist(choice - 1)) - WindowPrompt(0, tr( "Saved" ), tr( "OK" )); - else - WindowPrompt(tr( "Error" ), tr( "Could not save." ), tr( "OK" )); - } - } - else if (homeBtn->GetState() == STATE_CLICKED) - { - gprintf("\thomeBtn clicked\n"); - bgMusic->Pause(); - int choice = WindowExitPrompt(); - bgMusic->Resume(); - - if (choice == 3) - Sys_LoadMenu(); // Back to System Menu - else if (choice == 2) - Sys_BackToLoader(); - - homeBtn->ResetState(); - } - else if (installBtn->GetState() == STATE_CLICKED) - { - int choice = WindowPrompt(tr( "Install a game" ), 0, tr( "Yes" ), tr( "No" )); - if (choice == 1) - return MENU_INSTALL; - - installBtn->ResetState(); - } - else if (sdcardBtn->GetState() == STATE_CLICKED) - { - gprintf("\tsdCardBtn Clicked\n"); - HaltGui(); - bgMusic->Pause(); - SDCard_Init(); - Settings.Load(); - bgMusic->Resume(); - ReloadBrowser(); - ResumeGui(); - sdcardBtn->ResetState(); - } - - else if (DownloadBtn->GetState() == STATE_CLICKED) - { - gprintf("\tDownloadBtn Clicked\n"); - CoverDownload(); - ReloadBrowser(); - DownloadBtn->ResetState(); - } - - else if (settingsBtn->GetState() == STATE_CLICKED) - { - return MENU_SETTINGS; - } - - else if (favoriteBtn->GetState() == STATE_CLICKED) - { - favoriteBtn->ResetState(); - gprintf("\tfavoriteBtn Clicked\n"); - - if(Settings.GameSort & SORT_FAVORITE) - Settings.GameSort &= ~SORT_FAVORITE; - else - Settings.GameSort |= SORT_FAVORITE; - - wString oldFilter(gameList.GetCurrentFilter()); - gameList.FilterList(oldFilter.c_str()); - - if(Settings.GameSort & SORT_FAVORITE && gameList.size() == 0) - { - Settings.GameSort &= ~SORT_FAVORITE; - gameList.FilterList(oldFilter.c_str()); - ShowError(tr("No favorites selected.")); - } - else - ReloadBrowser(); - } - - else if (searchBtn->GetState() == STATE_CLICKED) - { - gprintf("\tsearchBtn Clicked\n"); - show_searchwindow = !show_searchwindow; - wString oldFilter(gameList.GetCurrentFilter()); - gameList.FilterList(oldFilter.c_str()); - ReloadBrowser(); - searchBtn->ResetState(); - } - - else if (searchBar && (searchChar = searchBar->GetClicked())) - { - if (searchChar > 27) - { - int len = gameList.GetCurrentFilter() ? wcslen(gameList.GetCurrentFilter()) : 0; - wchar_t newFilter[len + 2]; - if (gameList.GetCurrentFilter()) wcscpy(newFilter, gameList.GetCurrentFilter()); - newFilter[len] = searchChar; - newFilter[len + 1] = 0; - - gameList.FilterList(newFilter); - } - else if (searchChar == 7) // Close - { - show_searchwindow = false; - searchBtn->StopEffect(); - } - else if (searchChar == 8) // Backspace - { - int len = wcslen(gameList.GetCurrentFilter()); - wchar_t newFilter[len + 1]; - if (gameList.GetCurrentFilter()) wcscpy(newFilter, gameList.GetCurrentFilter()); - newFilter[len > 0 ? len - 1 : 0] = 0; - gameList.FilterList(newFilter); - } - ReloadBrowser(); - return MENU_NONE; - } - - else if (sortBtn->GetState() == STATE_CLICKED) - { - sortBtn->ResetState(); - gprintf("\tsortBtn clicked\n"); - if(Settings.GameSort & SORT_ABC) - { - Settings.GameSort &= ~SORT_ABC; - Settings.GameSort |= SORT_RANKING; - } - else if(Settings.GameSort & SORT_RANKING) - { - Settings.GameSort &= ~SORT_RANKING; - Settings.GameSort |= SORT_PLAYCOUNT; - } - else if(Settings.GameSort & SORT_PLAYCOUNT) - { - Settings.GameSort &= ~SORT_PLAYCOUNT; - Settings.GameSort |= SORT_ABC; - } - - wString oldFilter(gameList.GetCurrentFilter()); - gameList.FilterList(oldFilter.c_str()); - ReloadBrowser(); - } - - else if (listBtn->GetState() == STATE_CLICKED) - { - gprintf("\tlistBtn Clicked\n"); - if (Settings.gameDisplay != LIST_MODE) - { - Settings.gameDisplay = LIST_MODE; - ReloadBrowser(); - } - listBtn->ResetState(); - } - - else if (gridBtn->GetState() == STATE_CLICKED) - { - gprintf("\tgridBtn Clicked\n"); - if (Settings.gameDisplay != GRID_MODE) - { - Settings.gameDisplay = GRID_MODE; - ReloadBrowser(); - } - gridBtn->ResetState(); - } - - else if (carouselBtn->GetState() == STATE_CLICKED) - { - gprintf("\tcarouselBtn Clicked\n"); - if (Settings.gameDisplay != CAROUSEL_MODE) - { - Settings.gameDisplay = CAROUSEL_MODE; - ReloadBrowser(); - } - carouselBtn->ResetState(); - } - - else if (homebrewBtn->GetState() == STATE_CLICKED) - { - gprintf("\thomebrewBtn Clicked\n"); - return MENU_HOMEBREWBROWSE; - } - - else if (gameInfo->GetState() == STATE_CLICKED) - { - gprintf("\tgameinfo Clicked\n"); - int SelectedGame = GetSelectedGame(); - gameInfo->ResetState(); - if (SelectedGame >= 0 && SelectedGame < (s32) gameList.size()) - { - rockout(SelectedGame); - struct discHdr *header = gameList[SelectedGame]; - char IDfull[7]; - snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id); - SetState(STATE_DISABLED); - int choice = showGameInfo(IDfull); - SetState(STATE_DEFAULT); - rockout(SelectedGame, 2); - if (choice == 2) - homeBtn->SetState(STATE_CLICKED); - } - } - else if (lockBtn->GetState() == STATE_CLICKED) - { - gprintf("\tlockBtn clicked\n"); - lockBtn->ResetState(); - if (Settings.godmode) - { - if(WindowPrompt(tr( "Parental Control" ), tr( "Are you sure you want to lock USB Loader GX?" ), tr( "Yes" ), tr( "No" )) == 1) - { - Settings.godmode = 0; - wString oldFilter(gameList.GetCurrentFilter()); - gameList.FilterList(oldFilter.c_str()); - ReloadBrowser(); - } - } - else - { - //password check to unlock Install,Delete and Format - SetState(STATE_DISABLED); - int result = PasswordCheck(Settings.unlockCode); - SetState(STATE_DEFAULT); - if (result > 0) - { - if(result == 1) - WindowPrompt( tr( "Correct Password" ), tr( "All the features of USB Loader GX are unlocked." ), tr( "OK" )); - Settings.godmode = 1; - wString oldFilter(gameList.GetCurrentFilter()); - gameList.FilterList(oldFilter.c_str()); - ReloadBrowser(); - } - else if(result < 0) - WindowPrompt(tr( "Wrong Password" ), tr( "USB Loader GX is protected" ), tr( "OK" )); - } - } - - else if (Settings.gameDisplay == LIST_MODE && idBtn->GetState() == STATE_CLICKED) - { - gprintf("\tidBtn Clicked\n"); - struct discHdr * header = gameList[GetSelectedGame()]; - //enter new game ID - char entered[7]; - snprintf(entered, sizeof(entered), "%s", (char *) header->id); - int result = OnScreenKeyboard(entered, sizeof(entered), 0); - if (result == 1) - { - WBFS_ReIDGame(header->id, entered); - wString oldFilter(gameList.GetCurrentFilter()); - gameList.ReadGameList(); - gameList.FilterList(oldFilter.c_str()); - ReloadBrowser(); - } - idBtn->ResetState(); - } - - else if (Settings.gameDisplay == LIST_MODE && GetSelectedGame() != gameSelectedOld) - { - gameSelectedOld = GetSelectedGame(); - int gameSelected = gameSelectedOld; - if(gameSelected >= 0 && gameSelected < (s32) gameList.size()) - { - struct discHdr *header = gameList[gameSelected]; - LoadCover(header); - UpdateGameInfoText(header->id); - } - } - - gameClicked = GetClickedGame(); - if ((gameClicked >= 0 && gameClicked < (s32) gameList.size()) || mountMethod != 0) - { - OpenClickedGame(); - } - - if (!IsWpadConnected() && Settings.screensaver != 0) - { - if(ScreensaverTimer == 0) - ScreensaverTimer = time(0); - //30s delay to not start screensaver on startup - if(time(0)-ScreensaverTimer > 30) - WindowScreensaver(); - } - else - ScreensaverTimer = 0; - - return returnMenu; -} - -void GameBrowseMenu::CheckDiscSlotUpdate() -{ - u32 DiscDriveCover; - WDVD_GetCoverStatus(&DiscDriveCover);//for detecting if i disc has been inserted - - if ((DiscDriveCover & 0x02) && (DiscDriveCover != DiscDriveCoverOld)) - { - gprintf("\tNew Disc Detected\n"); - int choice = WindowPrompt(tr( "New Disc Detected" ), 0, tr( "Install" ), tr( "Mount DVD drive" ), tr( "Cancel" )); - if (choice == 1) - returnMenu = MENU_INSTALL; - else if (choice == 2) - dvdBtn->SetState(STATE_CLICKED); - } - else if (dvdBtn->GetState() == STATE_CLICKED) - { - gprintf("\tdvdBtn Clicked\n"); - if(!dvdheader) - dvdheader = new struct discHdr; - mountMethod = DiscMount(dvdheader); - dvdBtn->ResetState(); - - rockout(GetSelectedGame()); - } - - if(DiscDriveCoverOld != DiscDriveCover) - { - if(DiscDriveCover & 0x02) - dvdBtn->SetImage(dvdBtnImg); - else - dvdBtn->SetImage(dvdBtnImg_g); - - DiscDriveCoverOld = DiscDriveCover; - } -} - -void GameBrowseMenu::UpdateClock() -{ - if(Settings.hddinfo != CLOCK_HR12 && Settings.hddinfo != CLOCK_HR24) - return; - - time_t rawtime = time(0); - if(rawtime == lastrawtime) //! Only update every 1 second - return; - - char theTime[50]; - theTime[0] = 0; - - lastrawtime = rawtime; - struct tm * timeinfo = localtime(&rawtime); - if (Settings.hddinfo == CLOCK_HR12) - { - if (rawtime & 1) - strftime(theTime, sizeof(theTime), "%I:%M", timeinfo); - else - strftime(theTime, sizeof(theTime), "%I %M", timeinfo); - } - if (Settings.hddinfo == CLOCK_HR24) - { - if (rawtime & 1) - strftime(theTime, sizeof(theTime), "%H:%M", timeinfo); - else - strftime(theTime, sizeof(theTime), "%H %M", timeinfo); - } - clockTime->SetText(theTime); -} - -int GameBrowseMenu::GetSelectedGame() -{ - if(gameBrowser) - return gameBrowser->GetSelectedOption(); - - else if(gameCarousel) - return gameCarousel->GetSelectedOption(); - - else if(gameGrid) - return gameGrid->GetSelectedOption(); - - return -1; -} - -int GameBrowseMenu::GetClickedGame() -{ - if(gameBrowser) - return gameBrowser->GetClickedOption(); - - else if(gameCarousel) - return gameCarousel->GetClickedOption(); - - else if(gameGrid) - return gameGrid->GetClickedOption(); - - return -1; -} - -void GameBrowseMenu::UpdateGameInfoText(const u8 * gameId) -{ - if(!gameId) - { - Remove(GameIDTxt); - delete GameIDTxt; - GameIDTxt = NULL; - Remove(GameRegionTxt); - delete GameRegionTxt; - GameRegionTxt = NULL; - idBtn->SetLabel(NULL); - return; - } - - char gameregion[10]; - char IDfull[7]; - memset(IDfull, 0, sizeof(IDfull)); - snprintf(IDfull, sizeof(IDfull), (char *) gameId); - - switch (IDfull[3]) - { - case 'E': - sprintf(gameregion, "NTSC U"); - break; - case 'J': - sprintf(gameregion, "NTSC J"); - break; - case 'W': - sprintf(gameregion, "NTSC T"); - break; - default: - case 'K': - sprintf(gameregion, "NTSC K"); - break; - case 'P': - case 'D': - case 'F': - case 'I': - case 'S': - case 'H': - case 'U': - case 'X': - case 'Y': - case 'Z': - sprintf(gameregion, " PAL "); - break; - } - - HaltGui(); - if ((Settings.sinfo == GAMEINFO_ID) || (Settings.sinfo == GAMEINFO_BOTH)) - { - Remove(GameIDTxt); - delete GameIDTxt; - GameIDTxt = new GuiText(IDfull, 22, thColor("r=55 g=190 b=237 a=255 - game id text color")); - GameIDTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - idBtn->SetEffect(EFFECT_FADE, 20); - idBtn->SetLabel(GameIDTxt); - Append(idBtn); - } - //don't try to show region for channels because all the custom channels wont follow the rules - if ((Settings.sinfo == GAMEINFO_REGION) || (Settings.sinfo == GAMEINFO_BOTH)) - { - Remove(GameRegionTxt); - delete GameRegionTxt; - GameRegionTxt = new GuiText(gameregion, 22, thColor("r=55 g=190 b=237 a=255 - region info text color")); - GameRegionTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - GameRegionTxt->SetPosition(thInt("68 - region info text pos x"), thInt("30 - region info text pos x")); - GameRegionTxt->SetEffect(EFFECT_FADE, 20); - Append(GameRegionTxt); - } - ResumeGui(); -} - -int GameBrowseMenu::OpenClickedGame() -{ - int gameSelected = GetSelectedGame(); - if(gameSelected < 0 || gameSelected >= gameList.size()) - return -1; - - if (searchBar) - { - HaltGui(); - mainWindow->Remove(searchBar); - ResumeGui(); - } - - rockout(gameSelected); - - struct discHdr *header = (mountMethod ? dvdheader : gameList[gameSelected]); - - char IDfull[7]; - snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id); - - u8 alternatedol = OFF; - u8 ocarinaChoice = Settings.ocarina; - - GameCFG* game_cfg = GameSettings.GetGameCFG(header->id); - if (game_cfg) - { - alternatedol = game_cfg->loadalternatedol; - ocarinaChoice = game_cfg->ocarina; - } - - bool returnHere = true;// prompt to start game - int choice = -1; - - while (returnHere) - { - returnHere = false; - - if (Settings.wiilight == ON) - wiilight(1); - - if (Settings.quickboot) //quickboot game - choice = 1; - else - { - SetState(STATE_DISABLED); - GameWindow * GamePrompt = new GameWindow(gameSelected); - mainWindow->Append(GamePrompt); - choice = GamePrompt->Show(); - gameSelected = GamePrompt->GetSelectedGame(); - delete GamePrompt; - SetState(STATE_DEFAULT); - //update header and id if it was changed - header = (mountMethod ? dvdheader : gameList[gameSelected]); - snprintf(IDfull, sizeof(IDfull), "%s", (char *) header->id); - } - - if (choice == 1) - { - if (alternatedol == 2) - CheckAlternativeDOL(IDfull); - - if (ocarinaChoice != OFF) - CheckOcarina(IDfull); - - wiilight(0); - GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1); - GameStatistics.Save(); - - //Just calling that shuts down everything and starts game - BootGame(IDfull); - } - else if (choice == 2) - { - ReloadBrowser(); - rockout(2, GetSelectedGame()); - } - } - - mountMethod = 0; - - if (searchBar) - { - HaltGui(); - mainWindow->Append(searchBar); - ResumeGui(); - } - - return 0; -} - -void GameBrowseMenu::LoadCover(struct discHdr *header) -{ - DownloadBtn->SetImage(NULL); - if(gameCover) - delete gameCover; - - gameCover = LoadCoverImage(header); - - if (gameCoverImg) - delete gameCoverImg; - - gameCoverImg = new GuiImage(gameCover); - gameCoverImg->SetWidescreen(Settings.widescreen); - - DownloadBtn->SetImage(gameCoverImg);// put the new image on the download button -} - -void GameBrowseMenu::CheckOcarina(const char * IDfull) -{ - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s%s.gct", Settings.Cheatcodespath, IDfull); - if (CheckFile(filepath) == false) - { - gprintf("\ttried to load missing gct.\n"); - sprintf(filepath, "%s %s", filepath, tr( "does not exist! Loading game without cheats." )); - WindowPrompt(tr( "Error" ), filepath, NULL, NULL, NULL, NULL, 170); - } -} - -void GameBrowseMenu::CheckAlternativeDOL(const char * IDfull) -{ - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s%s.dol", Settings.dolpath, IDfull); - if (CheckFile(filepath) == false) - { - sprintf(filepath, "%s %s", filepath, tr( "does not exist!" )); - WindowPrompt(tr( "Error" ), filepath, tr( "OK" )); - } -} - -void GameBrowseMenu::UpdateCallback(void * e) -{ - //! Draw the selected Icon allways on top - GameBrowseMenu * w = (GameBrowseMenu *) e; - - for(u32 i = 0; i < w->ToolBar.size(); ++i) - { - if(w->ToolBar[i]->GetState() == STATE_SELECTED) - { - w->Remove(w->ToolBar[i]); - w->Append(w->ToolBar[i]); - break; - } - } -} diff --git a/source/menu/GameBrowseMenu.hpp b/source/menu/GameBrowseMenu.hpp deleted file mode 100644 index c1539138..00000000 --- a/source/menu/GameBrowseMenu.hpp +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef GAMEBROWSEMENU_HPP_ -#define GAMEBROWSEMENU_HPP_ - -#include "libwiigui/gui.h" -#include "libwiigui/gui_gamebrowser.h" -#include "libwiigui/gui_gamegrid.h" -#include "libwiigui/gui_gamecarousel.h" -#include "libwiigui/gui_searchbar.h" - -class GameBrowseMenu : public GuiWindow -{ - public: - GameBrowseMenu(); - ~GameBrowseMenu(); - int Show(); - protected: - int MainLoop(); - void ReloadBrowser(); - int OpenClickedGame(); - int GetSelectedGame(); - int GetClickedGame(); - void UpdateGameInfoText(const u8 * gameId); - void LoadCover(struct discHdr *header); - void CheckAlternativeDOL(const char * IDfull); - void CheckOcarina(const char * IDfull); - void CheckDiscSlotUpdate(); - void UpdateClock(); - static void UpdateCallback(void * e); - - GuiImageData * btnInstall; - GuiImageData * btnInstallOver; - GuiImageData * btnSettings; - GuiImageData * btnSettingsOver; - GuiImageData * btnpwroff; - GuiImageData * btnpwroffOver; - GuiImageData * btnhome; - GuiImageData * btnhomeOver; - GuiImageData * btnsdcardOver; - GuiImageData * btnsdcard; - GuiImageData * imgfavIcon; - GuiImageData * imgfavIcon_gray; - GuiImageData * imgsearchIcon; - GuiImageData * imgsearchIcon_gray; - GuiImageData * imgabcIcon; - GuiImageData * imgrankIcon; - GuiImageData * imgplayCountIcon; - GuiImageData * imgarrangeGrid; - GuiImageData * imgarrangeGrid_gray; - GuiImageData * imgarrangeCarousel; - GuiImageData * imgarrangeCarousel_gray; - GuiImageData * imgarrangeList; - GuiImageData * imgarrangeList_gray; - GuiImageData * imgdvd; - GuiImageData * imgdvd_gray; - GuiImageData * imgLock; - GuiImageData * imgLock_gray; - GuiImageData * imgUnlock; - GuiImageData * imgUnlock_gray; - GuiImageData * homebrewImgData; - GuiImageData * homebrewImgDataOver; - GuiImageData * gameCover; - - GuiTrigger * trigA; - GuiTrigger * trigHome; - GuiTrigger * trig1; - GuiTrigger * trig2; - - GuiImage * installBtnImg; - GuiImage * installBtnImgOver; - GuiImage * settingsBtnImg; - GuiImage * settingsBtnImgOver; - GuiImage * homeBtnImg; - GuiImage * homeBtnImgOver; - GuiImage * poweroffBtnImg; - GuiImage * poweroffBtnImgOver; - GuiImage * sdcardImg; - GuiImage * sdcardImgOver; - GuiImage * favoriteBtnImg; - GuiImage * favoriteBtnImg_g; - GuiImage * searchBtnImg; - GuiImage * searchBtnImg_g; - GuiImage * sortBtnImg; - GuiImage * listBtnImg; - GuiImage * listBtnImg_g; - GuiImage * gridBtnImg; - GuiImage * gridBtnImg_g; - GuiImage * carouselBtnImg; - GuiImage * carouselBtnImg_g; - GuiImage * lockBtnImg; - GuiImage * lockBtnImg_g; - GuiImage * unlockBtnImg; - GuiImage * unlockBtnImg_g; - GuiImage * dvdBtnImg; - GuiImage * dvdBtnImg_g; - GuiImage * homebrewImg; - GuiImage * homebrewImgOver; - GuiImage * gameCoverImg; - - GuiText * usedSpaceTxt; - GuiText * gamecntTxt; - GuiText * clockTimeBack; - GuiText * clockTime; - GuiText * GameRegionTxt; - GuiText * GameIDTxt; - - GuiButton * gamecntBtn; - GuiButton * installBtn; - GuiButton * settingsBtn; - GuiButton * homeBtn; - GuiButton * poweroffBtn; - GuiButton * sdcardBtn; - GuiButton * gameInfo; - GuiButton * favoriteBtn; - GuiButton * searchBtn; - GuiButton * sortBtn; - GuiButton * listBtn; - GuiButton * gridBtn; - GuiButton * carouselBtn; - GuiButton * lockBtn; - GuiButton * dvdBtn; - GuiButton * homebrewBtn; - GuiButton * DownloadBtn; - GuiButton * idBtn; - - GuiTooltip * installBtnTT; - GuiTooltip * settingsBtnTT; - GuiTooltip * homeBtnTT; - GuiTooltip * poweroffBtnTT; - GuiTooltip * sdcardBtnTT; - GuiTooltip * favoriteBtnTT; - GuiTooltip * searchBtnTT; - GuiTooltip * sortBtnTT; - GuiTooltip * listBtnTT; - GuiTooltip * gridBtnTT; - GuiTooltip * carouselBtnTT; - GuiTooltip * lockBtnTT; - GuiTooltip * dvdBtnTT; - GuiTooltip * homebrewBtnTT; - GuiTooltip * DownloadBtnTT; - GuiTooltip * IDBtnTT; - - GuiGameBrowser * gameBrowser; - GuiGameGrid * gameGrid; - GuiGameCarousel * gameCarousel; - GuiSearchBar * searchBar; - u32 DiscDriveCoverOld; - int returnMenu; - int gameSelectedOld; - int gameClicked; - time_t lastrawtime; - time_t ScreensaverTimer; - bool show_searchwindow; - wchar_t searchChar; - std::vector ToolBar; -}; - -#endif diff --git a/source/menu/MountGamePartition.cpp b/source/menu/MountGamePartition.cpp deleted file mode 100644 index da890fbc..00000000 --- a/source/menu/MountGamePartition.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include - -#include "FileOperations/fileops.h" -#include "wad/nandtitle.h" -#include "system/IosLoader.h" -#include "menus.h" -#include "wpad.h" -#include "fatmounter.h" -#include "usbloader/wbfs.h" -#include "usbloader/GameList.h" -#include "settings/GameTitles.h" -#include "xml/WiiTDB.hpp" - -extern int load_from_fs; -extern char game_partition[6]; -extern PartList partitions; - -static int FindGamesPartition(PartList * partitions) -{ - if (partitions->wbfs_n != 0) - { - WBFS_Open(); - - for (int p = 0; p < partitions->num; p++) - { - if (partitions->pinfo[p].fs_type == FS_TYPE_WBFS) - { - Settings.partition = p; - load_from_fs = PART_FS_WBFS; - return 0; - } - } - } - - - if(IosLoader::IsWaninkokoIOS() && NandTitles.VersionOf(TITLE_ID(1, IOS_GetVersion())) < 18) - return -1; - - // Loop through FAT/NTFS/EXT partitions, and find the first partition with games on it (if there is one) - for (int i = 0; i < partitions->num; i++) - { - if (partitions->pinfo[i].fs_type == FS_TYPE_FAT32 || partitions->pinfo[i].fs_type == FS_TYPE_NTFS || - partitions->pinfo[i].fs_type == FS_TYPE_EXT) - { - if (!WBFS_OpenPart(partitions->pinfo[i].part_fs, partitions->pinfo[i].index, - partitions->pentry[i].sector, partitions->pentry[i].size, (char *) &game_partition)) - { - u32 count; - // Get the game count... - WBFS_GetCount(&count); - - if (count > 0) - { - load_from_fs = partitions->pinfo[i].part_fs; - Settings.partition = i; - return 0; - } - else - { - WBFS_Close(); - } - } - } - } - - return -1; -} - -static int PartitionChoice() -{ - int ret = -1; - - int choice = WindowPrompt(tr( "No WBFS or FAT/NTFS/EXT partition found" ), - tr( "You need to select or format a partition" ), tr( "Select" ), tr( "Format" ), tr( "Return" )); - - if (choice == 0) - { - Sys_LoadMenu(); - } - else if(choice == 1) - { - int part_num = SelectPartitionMenu(); - if(part_num >= 0) - { - if(IosLoader::IsWaninkokoIOS() && NandTitles.VersionOf(TITLE_ID(1, IOS_GetVersion())) < 18 - && (partitions.pinfo[part_num].part_fs == FS_TYPE_FAT32 || partitions.pinfo[part_num].part_fs == FS_TYPE_NTFS - || partitions.pinfo[part_num].part_fs == FS_TYPE_EXT)) - WindowPrompt(tr("Warning:"), tr("You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk."), tr("OK")); - - ret = WBFS_OpenPart(partitions.pinfo[part_num].part_fs, partitions.pinfo[part_num].index, partitions.pentry[part_num].sector, partitions.pentry[part_num].size, (char *) &game_partition); - - load_from_fs = partitions.pinfo[part_num].part_fs; - Settings.partition = part_num; - Settings.Save(); - } - } - else if(choice == 2) - { - while(ret < 0 || ret == -666) - { - int part_num = SelectPartitionMenu(); - if(part_num >= 0) - ret = FormatingPartition(tr( "Formatting, please wait..." ), &partitions.pentry[part_num]); - } - } - - return ret; -} - -/**************************************************************************** - * MountGamePartition - ***************************************************************************/ -int MountGamePartition(bool ShowGUI) -{ - gprintf("MountGamePartition()\n"); - - s32 wbfsinit = MountWBFS(ShowGUI); - if (wbfsinit < 0) - { - if(ShowGUI) WindowPrompt(tr( "Error !" ), tr( "USB Device not found" ), tr( "OK" )); - Sys_LoadMenu(); - } - - s32 ret = -1; - memset(game_partition, 0, 6); - load_from_fs = -1; - - gprintf("\tPartition_GetList\n"); - // Added for slow HDD - for (int retries = 10; retries > 0; retries--) - { - if (Partition_GetList(WBFS_DEVICE_USB, &partitions) == 0) - break; - - sleep(1); - } - - gprintf("\tWBFS_OpenPart: start sector %u, sector count: %u\n", partitions.pentry[Settings.partition].sector, partitions.pentry[Settings.partition].size); - if (Settings.partition != -1 && partitions.num > Settings.partition) - { - PartInfo pinfo = partitions.pinfo[Settings.partition]; - if (!WBFS_OpenPart(pinfo.part_fs, pinfo.index, partitions.pentry[Settings.partition].sector, - partitions.pentry[Settings.partition].size, (char *) &game_partition)) - { - ret = 0; - load_from_fs = pinfo.part_fs; - } - } - - if(ret < 0) - ret = FindGamesPartition(&partitions); - - if (ret < 0 && ShowGUI) - ret = PartitionChoice(); - - if(ret < 0) - Sys_LoadMenu(); - - gprintf("\tDisc_Init\n"); - ret = Disc_Init(); - if (ret < 0) - { - if(ShowGUI) - WindowPrompt(tr( "Error !" ), tr( "Could not initialize DIP module!" ), tr( "OK" )); - Sys_LoadMenu(); - } - - gprintf("\tOpenXMLDatabase\n"); - - GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); - - return ret; -} diff --git a/source/menu/menu_disclist.cpp b/source/menu/menu_disclist.cpp deleted file mode 100644 index 4060b7a6..00000000 --- a/source/menu/menu_disclist.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "GameBrowseMenu.hpp" -#include "menus.h" - -/**************************************************************************** - * MenuDiscList - ***************************************************************************/ -int MenuDiscList() -{ - int retMenu = MENU_NONE; - - GameBrowseMenu * Menu = new GameBrowseMenu(); - mainWindow->Append(Menu); - - retMenu = Menu->Show(); - - delete Menu; - - return retMenu; -} diff --git a/source/menu/menu_install.cpp b/source/menu/menu_install.cpp deleted file mode 100644 index 470447a9..00000000 --- a/source/menu/menu_install.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "menus.h" -#include "usbloader/usbstorage2.h" -#include "usbloader/wbfs.h" -#include "usbloader/disc.h" -#include "usbloader/utils.h" -#include "usbloader/GameList.h" -#include "prompts/ProgressWindow.h" -#include "themes/CTheme.h" - -float gamesize; - -/**************************************************************************** - * MenuInstall - ***************************************************************************/ - -int MenuInstall() -{ - gprintf("\nMenuInstall()"); - - static struct discHdr headerdisc ATTRIBUTE_ALIGN( 32 ); - - Disc_SetUSB(NULL); - - int ret, choice = 0; - char name[200]; - - ret = DiscWait(tr( "Insert Disk" ), tr( "Waiting..." ), tr( "Cancel" ), 0, 0); - if (ret < 0) - { - WindowPrompt(tr( "Error reading Disc" ), 0, tr( "Back" )); - return MENU_DISCLIST; - } - ret = Disc_Open(); - if (ret < 0) - { - WindowPrompt(tr( "Could not open Disc" ), 0, tr( "Back" )); - return MENU_DISCLIST; - } - - ret = Disc_IsWii(); - if (ret < 0) - { - choice = WindowPrompt(tr( "Not a Wii Disc" ), tr( "Insert a Wii Disc!" ), tr( "OK" ), tr( "Back" )); - - if (choice == 1) - return MENU_INSTALL; - else - return MENU_DISCLIST; - } - - Disc_ReadHeader(&headerdisc); - snprintf(name, sizeof(name), "%s", headerdisc.title); - - ret = WBFS_CheckGame(headerdisc.id); - if (ret) - { - WindowPrompt(tr( "Game is already installed:" ), name, tr( "Back" )); - return MENU_DISCLIST; - } - - f32 freespace, used; - - WBFS_DiskSpace(&used, &freespace); - gamesize = WBFS_EstimeGameSize() / GB_SIZE; - - char gametxt[50]; - - sprintf(gametxt, "%s : %.2fGB", name, gamesize); - - wiilight(1); - choice = WindowPrompt(tr( "Continue to install game?" ), gametxt, tr( "OK" ), tr( "Cancel" )); - - if (choice == 1) - { - sprintf(gametxt, "%s", tr( "Installing game:" )); - - if (gamesize > freespace) - { - char errortxt[50]; - sprintf(errortxt, "%s: %.2fGB, %s: %.2fGB", tr( "Game Size" ), gamesize, tr( "Free Space" ), freespace); - WindowPrompt(tr( "Not enough free space!" ), errortxt, tr( "OK" )); - return MENU_DISCLIST; - } - else - { - USBStorage2_Watchdog(0); - SetupGameInstallProgress(gametxt, name); - ret = WBFS_AddGame(); - ProgressStop(); - USBStorage2_Watchdog(1); - wiilight(0); - if (ret != 0) - { - WindowPrompt(tr( "Install Error!" ), 0, tr( "Back" )); - return MENU_DISCLIST; - } - else - { - gameList.ReadGameList(); //get the entries again - gameList.FilterList(); - GuiSound * instsuccess = NULL; - bgMusic->Pause(); - instsuccess = new GuiSound(success_ogg, success_ogg_size, Settings.sfxvolume); - instsuccess->SetVolume(Settings.sfxvolume); - instsuccess->SetLoop(0); - instsuccess->Play(); - WindowPrompt(tr( "Successfully installed:" ), name, tr( "OK" )); - instsuccess->Stop(); - delete instsuccess; - bgMusic->Resume(); - return MENU_DISCLIST; - } - } - } - else - return MENU_DISCLIST; - - //Turn off the WiiLight - wiilight(0); - - return MENU_DISCLIST; -} diff --git a/source/menu/menu_partition_selection.cpp b/source/menu/menu_partition_selection.cpp deleted file mode 100644 index f2c2ea8a..00000000 --- a/source/menu/menu_partition_selection.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include - -#include "menus.h" -#include "fatmounter.h" -#include "usbloader/usbstorage2.h" -#include "usbloader/utils.h" -#include "usbloader/wbfs.h" -#include "libwiigui/gui_customoptionbrowser.h" -#include "themes/CTheme.h" - -extern PartList partitions; - -/**************************************************************************** - * SelectPartitionMenu - ***************************************************************************/ -int SelectPartitionMenu() -{ - bool ExitSelect = false; - OptionList options; - - u32 cnt, counter = 0; - int choice = -1; - int ret = -1; - - //create the partitionlist - for (cnt = 0; cnt < (u32) partitions.num; cnt++) - { - partitionEntry *entry = &partitions.pentry[cnt]; - - /* Calculate size in gigabytes */ - f32 size = entry->size * (partitions.sector_size / GB_SIZE); - - if (size) - { - options.SetName(counter, "%s %d:", tr( "Partition" ), cnt + 1); - options.SetValue(counter, "%.2fGB", size); - } - else - { - options.SetName(counter, "%s %d:", tr( "Partition" ), cnt + 1); - options.SetValue(counter, tr( "Can't be formatted" )); - } - counter++; - } - - GuiImageData btnpwroff(Resources::GetFile("wiimote_poweroff.png"), Resources::GetFileSize("wiimote_poweroff.png")); - GuiImageData btnpwroffOver(Resources::GetFile("wiimote_poweroff_over.png"), Resources::GetFileSize("wiimote_poweroff_over.png")); - GuiImageData btnhome(Resources::GetFile("menu_button.png"), Resources::GetFileSize("menu_button.png")); - GuiImageData btnhomeOver(Resources::GetFile("menu_button_over.png"), Resources::GetFileSize("menu_button_over.png")); - GuiImageData battery(Resources::GetFile("battery.png"), Resources::GetFileSize("battery.png")); - GuiImageData batteryBar(Resources::GetFile("battery_bar.png"), Resources::GetFileSize("battery_bar.png")); - GuiImageData batteryRed(Resources::GetFile("battery_red.png"), Resources::GetFileSize("battery_red.png")); - GuiImageData batteryBarRed(Resources::GetFile("battery_bar_red.png"), Resources::GetFileSize("battery_bar_red.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - - GuiImage poweroffBtnImg(&btnpwroff); - GuiImage poweroffBtnImgOver(&btnpwroffOver); - poweroffBtnImg.SetWidescreen(Settings.widescreen); - poweroffBtnImgOver.SetWidescreen(Settings.widescreen); - GuiButton poweroffBtn(&poweroffBtnImg, &poweroffBtnImgOver, 0, 3, - thInt("576 - power off btn pos x"), thInt("355 - power off btn pos y"), - &trigA, btnSoundOver, btnSoundClick2, 1); - GuiImage exitBtnImg(&btnhome); - GuiImage exitBtnImgOver(&btnhomeOver); - exitBtnImg.SetWidescreen(Settings.widescreen); - exitBtnImgOver.SetWidescreen(Settings.widescreen); - GuiButton exitBtn(&exitBtnImg, &exitBtnImgOver, 0, 3, - thInt("489 - home menu btn pos x"), thInt("371 - home menu btn pos x"), - &trigA, btnSoundOver, btnSoundClick2, 1); - exitBtn.SetTrigger(&trigHome); - - GuiCustomOptionBrowser optionBrowser(396, 280, &options, "bg_options_settings.png"); - optionBrowser.SetPosition(0, 40); - optionBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - - HaltGui(); - GuiWindow w(screenwidth, screenheight); - w.Append(&poweroffBtn); - w.Append(&exitBtn); - - mainWindow->Append(&w); - mainWindow->Append(&optionBrowser); - - ResumeGui(); - - while (!ExitSelect) - { - VIDEO_WaitVSync(); - - if (shutdown) - Sys_Shutdown(); - if (reset) - Sys_Reboot(); - - ret = optionBrowser.GetClickedOption(); - - if (ret >= 0) - { - partitionEntry *entry = &partitions.pentry[ret]; - if (entry->size) - { - choice = ret; - ExitSelect = true; - } - } - - if (poweroffBtn.GetState() == STATE_CLICKED) - { - choice = WindowPrompt(tr( "Shutdown System" ), tr( "Are you sure?" ), tr( "Yes" ), tr( "No" )); - if (choice == 1) - Sys_Shutdown(); - - } - else if (exitBtn.GetState() == STATE_CLICKED) - { - choice = WindowPrompt(tr( "Return to Wii Menu" ), tr( "Are you sure?" ), tr( "Yes" ), tr( "No" )); - if (choice == 1) - Sys_LoadMenu(); - } - } - - HaltGui(); - - mainWindow->Remove(&optionBrowser); - mainWindow->Remove(&w); - ResumeGui(); - - return choice; -} - diff --git a/source/menu/menus.h b/source/menu/menus.h deleted file mode 100644 index 3cac187c..00000000 --- a/source/menu/menus.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _MENUS_H -#define _MENUS_H - -#include "libwiigui/gui.h" -#include "language/gettext.h" -#include "prompts/PromptWindows.h" -#include "menu.h" -#include "gecko.h" -#include "filelist.h" -#include "sys.h" - -extern u8 shutdown; -extern u8 reset; - -int MenuInstall(); -int MenuDiscList(); -int SelectPartitionMenu(); -int MountGamePartition(bool ShowGUI = true); - -#endif // _MENUS_H diff --git a/source/mload/mload.c b/source/mload/mload.c deleted file mode 100644 index 481748a5..00000000 --- a/source/mload/mload.c +++ /dev/null @@ -1,531 +0,0 @@ -/* mload.c (for PPC) (c) 2009, Hermes - - This program 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 - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "mload.h" -#include "gecko.h" - -static const char mload_fs[] ATTRIBUTE_ALIGN(32) = "/dev/mload"; - -static s32 mload_fd = -1; -static s32 hid = -1; - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to init/test if the device is running - -int mload_init() -{ - int n; - - if(hid<0) hid = iosCreateHeap(0x800); - - if(hid<0) - { - if(mload_fd>=0) - IOS_Close(mload_fd); - - mload_fd=-1; - - return hid; - } - - if(mload_fd>=0) - { - return 0; - } - - for(n=0;n<20;n++) // try 5 seconds - { - mload_fd=IOS_Open(mload_fs, 0); - - if(mload_fd>=0) break; - - usleep(250*1000); - } - - if(mload_fd<0) - { - - if(hid>=0) - { - iosDestroyHeap(hid); - hid=-1; - } - } - - return mload_fd; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to close the device (remember call it when rebooting the IOS!) - -int mload_close() -{ - int ret; - - if(hid>=0) - { - iosDestroyHeap(hid); - hid=-1; - } - - if(mload_fd<0) return -1; - - ret=IOS_Close(mload_fd); - - mload_fd=-1; - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to get the thread id of mload - -int mload_get_thread_id() -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_MLOAD_THREAD_ID, ":"); - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// get the base and the size of the memory readable/writable to load modules - -int mload_get_load_base(u32 *starlet_base, int *size) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GET_LOAD_BASE, ":ii",starlet_base, size); - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// load and run a module from starlet (it need to allocate MEM2 to send the elf file) -// the module must be a elf made with stripios - -int mload_module(void *addr, int len) -{ - int ret; - void *buf=NULL; - - - if(mload_init()<0) return -1; - - if(hid>=0) - { - iosDestroyHeap(hid); - hid=-1; - } - - hid = iosCreateHeap(len+0x800); - - if(hid<0) return hid; - - buf= iosAlloc(hid, len); - - if(!buf) {ret= -1;goto out;} - - - memcpy(buf, addr,len); - - ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_LOAD_MODULE, ":d", buf, len); - - if(ret<0) goto out; - - ret=IOS_IoctlvFormat(hid, mload_fd, MLOAD_RUN_MODULE, ":"); - - if(ret<0) {ret= -666;goto out;} - -out: - if(hid>=0) - { - iosDestroyHeap(hid); - hid=-1; - } - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// load a module from the PPC -// the module must be a elf made with stripios - -int mload_elf(void *my_elf, data_elf *data_elf) -{ - int n,m; - int p; - u8 *adr; - u32 elf=(u32) my_elf; - - if(elf & 3) return -1; // aligned to 4 please! - - elfheader *head=(void *) elf; - elfphentry *entries; - - if(head->ident0!=0x7F454C46) return -1; - if(head->ident1!=0x01020161) return -1; - if(head->ident2!=0x01000000) return -1; - - p=head->phoff; - - data_elf->start=(void *) head->entry; - - for(n=0; nphnum; n++) - { - entries=(void *) (elf+p); - p+=sizeof(elfphentry); - - if(entries->type == 4) - { - adr=(void *) (elf + entries->offset); - - if(getbe32(0)!=0) return -2; // bad info (sure) - - for(m=4; (u32)m < entries->memsz; m+=8) - { - switch(getbe32(m)) - { - case 0x9: - data_elf->start= (void *) getbe32(m+4); - break; - case 0x7D: - data_elf->prio= getbe32(m+4); - break; - case 0x7E: - data_elf->size_stack= getbe32(m+4); - break; - case 0x7F: - data_elf->stack= (void *) (getbe32(m+4)); - break; - - } - - } - - } - else - if(entries->type == 1 && entries->memsz != 0 && entries->vaddr!=0) - { - - if(mload_memset((void *) entries->vaddr, 0, entries->memsz)<0) return -1; - if(mload_seek(entries->vaddr, SEEK_SET)<0) return -1; - if(mload_write((void *) (elf + entries->offset), entries->filesz)<0) return -1; - - } - } - - return 0; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// run one thread (you can use to load modules or binary files) - -int mload_run_thread(void *starlet_addr, void *starlet_top_stack, int stack_size, int priority) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_RUN_THREAD, "iiii:", starlet_addr,starlet_top_stack, stack_size, priority); - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// stops one starlet thread - -int mload_stop_thread(int id) -{ -int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_STOP_THREAD, "i:", id); - -return ret; - -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// continue one stopped starlet thread - -int mload_continue_thread(int id) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_CONTINUE_THREAD, "i:", id); - - return ret; -} -/*--------------------------------------------------------------------------------------------------------------*/ - -// fix starlet address to read/write (uses SEEK_SET, etc as mode) - -int mload_seek(int offset, int mode) -{ - if(mload_init()<0) return -1; - - return IOS_Seek(mload_fd, offset, mode); -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// read bytes from starlet (it update the offset) - -int mload_read(void* buf, u32 size) -{ - if(mload_init()<0) return -1; - - return IOS_Read(mload_fd, buf, size); -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// write bytes from starlet (it update the offset) - -int mload_write(const void * buf, u32 size) -{ - if(mload_init()<0) return -1; - - return IOS_Write(mload_fd, buf, size); -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// fill a block (similar to memset) - -int mload_memset(void *starlet_addr, int set, int len) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_MEMSET, "iii:", starlet_addr, set, len); - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// get the ehci datas ( ehcmodule.elf uses this address) - -void * mload_get_ehci_data() -{ - int ret; - - if(mload_init()<0) return NULL; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GET_EHCI_DATA, ":"); - if(ret<0) return NULL; - - return (void *) ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// set the dev/es ioctlv in routine - -int mload_set_ES_ioctlv_vector(void *starlet_addr) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_SET_ES_IOCTLV, "i:", starlet_addr); - - return ret; -} - - - -int mload_getw(const void * addr, u32 *dat) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GETW, "i:i", addr, dat); - - return ret; -} - -int mload_geth(const void * addr, u16 *dat) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GETH, "i:h", addr, dat); - - return ret; -} - -int mload_getb(const void * addr, u8 *dat) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GETB, "i:b", addr, dat); - - return ret; -} - -int mload_setw(const void * addr, u32 dat) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_SETW, "ii:", addr, dat); - - return ret; -} - -int mload_seth(const void * addr, u16 dat) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_SETH, "ih:", addr, dat); - - return ret; -} - -int mload_setb(const void * addr, u8 dat) -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_SETB, "ib:", addr, dat); - - return ret; -} - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to get log buffer -// this function return the size of the log buffer and prepare it to read with mload_read() the datas - -int mload_get_log() -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GET_LOG, ":"); - - return ret; - -} - - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to get IOS base for dev/es to create the cIOS - -int mload_get_IOS_base() -{ - int ret; - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GET_IOS_BASE, ":"); - - return ret; - -} - - -int mload_get_version() -{ - int ret; - if(mload_init()<0) return -1; - ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_GET_MLOAD_VERSION, ":"); - return ret; -} - -/* IOS info structure */ -typedef struct { - /* Syscall base */ - u32 syscall; - - /* Module versions */ - u32 dipVersion; - u32 esVersion; - u32 ffsVersion; - u32 iopVersion; -} iosInfo; - -int wanin_mload_get_IOS_base() -{ - int ret; - iosInfo ios; - memset(&ios, 0, sizeof(ios)); - - if(mload_init()<0) return -1; - - ret= IOS_IoctlvFormat(hid, mload_fd, MLOAD_GET_IOS_BASE, ":d", &ios, sizeof(ios)); - //gprintf("get_ios_base: %d %x\n", ret, ios.dipVersion); - if (ret == 0) { - switch(ios.dipVersion) { - case 0x48776F72: /* DIP: 07/11/08 14:34:26 */ - return 37; - - case 0x4888E14C: /* DIP: 07/24/08 20:08:44 */ - return 38; - - case 0x4A262AF5: /* DIP: 06/03/09 07:49:09 */ - return 57; - - case 0x492ACA9D: /* DIP: 11/24/08 15:39:09 */ - return 60; - } - } - return ret; -} - -int mload_set_gecko_debug() -{ - int ret; - u32 log_mode = 2; // GECKO - if(mload_init()<0) return -1; - - gprintf("Setting debug mode..."); - ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_SET_LOG_MODE, ":d", &log_mode, sizeof(log_mode)); - gprintf("%d\n", ret); - return ret; -} diff --git a/source/mload/mload.h b/source/mload/mload.h deleted file mode 100644 index 43f21d4c..00000000 --- a/source/mload/mload.h +++ /dev/null @@ -1,233 +0,0 @@ -/* mload.c (for PPC) (c) 2009, Hermes - - This program 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 - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef __MLOAD_H__ -#define __MLOAD_H__ - - -#include -#include -#include -#include -#include -#include "unistd.h" - -#define MLOAD_MLOAD_THREAD_ID 0x4D4C4400 -#define MLOAD_GET_IOS_BASE 0x4D4C4401 -#define MLOAD_GET_MLOAD_VERSION 0x4D4C4402 - -#define MLOAD_LOAD_MODULE 0x4D4C4480 -#define MLOAD_RUN_MODULE 0x4D4C4481 -#define MLOAD_RUN_THREAD 0x4D4C4482 - -#define MLOAD_STOP_THREAD 0x4D4C4484 -#define MLOAD_CONTINUE_THREAD 0x4D4C4485 - -#define MLOAD_GET_LOAD_BASE 0x4D4C4490 -#define MLOAD_MEMSET 0x4D4C4491 - -#define MLOAD_GET_EHCI_DATA 0x4D4C44A0 -#define MLOAD_GET_LOG 0x4D4C44A1 - -#define MLOAD_SET_ES_IOCTLV 0x4D4C44B0 - -#define MLOAD_GETW 0x4D4C44C0 -#define MLOAD_GETH 0x4D4C44C1 -#define MLOAD_GETB 0x4D4C44C2 -#define MLOAD_SETW 0x4D4C44C3 -#define MLOAD_SETH 0x4D4C44C4 -#define MLOAD_SETB 0x4D4C44C5 - -#define MLOAD_SET_LOG_MODE 0x4D4C44D0 -#define MLOAD_GET_LOG_BUFFER 0x4D4C44D1 - -#ifdef __cplusplus -extern "C" { -#endif - -// from IOS ELF stripper of neimod - -#define getbe32(x) ((adr[x]<<24) | (adr[x+1]<<16) | (adr[x+2]<<8) | (adr[x+3])) - -typedef struct -{ - u32 ident0; - u32 ident1; - u32 ident2; - u32 ident3; - u32 machinetype; - u32 version; - u32 entry; - u32 phoff; - u32 shoff; - u32 flags; - u16 ehsize; - u16 phentsize; - u16 phnum; - u16 shentsize; - u16 shnum; - u16 shtrndx; -} elfheader; - -typedef struct -{ - u32 type; - u32 offset; - u32 vaddr; - u32 paddr; - u32 filesz; - u32 memsz; - u32 flags; - u32 align; -} elfphentry; - -typedef struct -{ - void *start; - int prio; - void *stack; - int size_stack; -} data_elf; - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to init/test if the device is running - -int mload_init(); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to close the device (remember call it when rebooting the IOS!) - -int mload_close(); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// to get the thread id of mload - -int mload_get_thread_id(); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// get the base and the size of the memory readable/writable to load modules - -int mload_get_load_base(u32 *starlet_base, int *size); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// load and run a module from starlet (it need to allocate MEM2 to send the elf file) -// the module must be a elf made with stripios - -int mload_module(void *addr, int len); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// load a module from the PPC -// the module must be a elf made with stripios - -int mload_elf(void *my_elf, data_elf *data_elf); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// run one thread (you can use to load modules or binary files) - -int mload_run_thread(void *starlet_addr, void *starlet_top_stack, int stack_size, int priority); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// stops one starlet thread - -int mload_stop_thread(int id); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// continue one stopped starlet thread - -int mload_continue_thread(int id); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// fix starlet address to read/write (uses SEEK_SET, etc as mode) - -int mload_seek(int offset, int mode); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// read bytes from starlet (it update the offset) - -int mload_read(void* buf, u32 size); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// write bytes from starlet (it update the offset) - -int mload_write(const void * buf, u32 size); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// fill a block (similar to memset) - -int mload_memset(void *starlet_addr, int set, int len); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// get the ehci datas ( ehcmodule.elf uses this address) - -void * mload_get_ehci_data(); - -/*--------------------------------------------------------------------------------------------------------------*/ - -// set the dev/es ioctlv in routine - -int mload_set_ES_ioctlv_vector(void *starlet_addr); - -/*--------------------------------------------------------------------------------------------------------------*/ - - -// to get log buffer -// this function return the size of the log buffer and prepare it to read with mload_read() the datas - -int mload_get_log(); - -/*--------------------------------------------------------------------------------------------------------------*/ - - -// to get IOS base for dev/es to create the cIOS - -int mload_get_IOS_base(); - -int mload_get_version(); - -/*--------------------------------------------------------------------------------------------------------------*/ - -int mload_getw(const void * addr, u32 *dat); -int mload_geth(const void * addr, u16 *dat); -int mload_getb(const void * addr, u8 *dat); - -int mload_setw(const void * addr, u32 dat); -int mload_seth(const void * addr, u16 dat); -int mload_setb(const void * addr, u8 dat); - -int wanin_mload_get_IOS_base(); -int mload_set_gecko_debug(); - -#ifdef __cplusplus - } -#endif - - -#endif diff --git a/source/mload/mload_modules.c b/source/mload/mload_modules.c deleted file mode 100644 index 06dcd671..00000000 --- a/source/mload/mload_modules.c +++ /dev/null @@ -1,230 +0,0 @@ -#include "mload_modules.h" - -static u32 ios_36[16] ATTRIBUTE_ALIGN(32)= -{ - 0, // DI_EmulateCmd - 0, - 0x2022DDAC, // dvd_read_controlling_data - 0x20201010+1, // handle_di_cmd_reentry (thumb) - 0x20200b9c+1, // ios_shared_alloc_aligned (thumb) - 0x20200b70+1, // ios_shared_free (thumb) - 0x20205dc0+1, // ios_memcpy (thumb) - 0x20200048+1, // ios_fatal_di_error (thumb) - 0x20202b4c+1, // ios_doReadHashEncryptedState (thumb) - 0x20203934+1, // ios_printf (thumb) -}; - -static u32 ios_38[16] ATTRIBUTE_ALIGN(32)= -{ - 0, // DI_EmulateCmd - 0, - 0x2022cdac, // dvd_read_controlling_data - 0x20200d38+1, // handle_di_cmd_reentry (thumb) - 0x202008c4+1, // ios_shared_alloc_aligned (thumb) - 0x20200898+1, // ios_shared_free (thumb) - 0x20205b80+1, // ios_memcpy (thumb) - 0x20200048+1, // ios_fatal_di_error (thumb) - 0x20202874+1, // ios_doReadHashEncryptedState (thumb) - 0x2020365c+1, // ios_printf (thumb) -}; - - -static u32 ios_37[16] ATTRIBUTE_ALIGN(32)= -{ - 0, // DI_EmulateCmd - 0, - 0x2022DD60, // dvd_read_controlling_data - 0x20200F04+1, // handle_di_cmd_reentry (thumb) - 0x2020096C+1, // ios_shared_alloc_aligned (thumb) - 0x2020093C+1, // ios_shared_free (thumb) - 0x20205E54+1, // ios_memcpy (thumb) - 0x20200048+1, // ios_fatal_di_error (thumb) - 0x20202A70+1, // ios_doReadHashEncryptedState (thumb) - 0x2020387C+1, // ios_printf (thumb) -}; - -static u32 ios_57[16] ATTRIBUTE_ALIGN(32)= -{ - 0, // DI_EmulateCmd - 0, - 0x2022cd60, // dvd_read_controlling_data - 0x20200f04+1, // handle_di_cmd_reentry (thumb) - 0x2020096c+1, // ios_shared_alloc_aligned (thumb) // no usado - 0x2020093C+1, // ios_shared_free (thumb) // no usado - 0x20205EF0+1, // ios_memcpy (thumb) - 0x20200048+1, // ios_fatal_di_error (thumb) - 0x20202944+1, // ios_doReadHashEncryptedState (thumb) - 0x20203750+1, // ios_printf (thumb) -}; - -static u32 ios_60[16] ATTRIBUTE_ALIGN(32)= -{ - 0, // DI_EmulateCmd - 0, - 0x2022cd60, // dvd_read_controlling_data - 0x20200f04+1, // handle_di_cmd_reentry (thumb) - 0x2020096c+1, // ios_shared_alloc_aligned (thumb) // no usado - 0x2020093C+1, // ios_shared_free (thumb) // no usado - 0x20205e00+1, // ios_memcpy (thumb) - 0x20200048+1, // ios_fatal_di_error (thumb) - 0x20202944+1, // ios_doReadHashEncryptedState (thumb) - 0x20203750+1, // ios_printf (thumb) -}; - - -static u32 patch_datas[8] ATTRIBUTE_ALIGN(32); -static int my_thread_id = 0; -static data_elf my_data_elf; -static u8 * dip_plugin = NULL; -static u32 dip_plugin_size = 0; - -int load_modules(const u8 * ehcmodule, int ehcmodule_size, const u8 * dip, int dip_size) -{ - if(mload_init() < 0) - return -1; - - dip_plugin = (u8 *) dip; - dip_plugin_size = dip_size; - - mload_elf((u8 *) ehcmodule, &my_data_elf); - my_thread_id= mload_run_thread(my_data_elf.start, my_data_elf.stack, my_data_elf.size_stack, my_data_elf.prio); - - if(my_thread_id < 0) - return -2; - usleep(350*1000); - - // Test for IOS - int is_ios = mload_get_IOS_base(); - u32 dip_address = 0x1377C000; - - switch(is_ios) - { - - case 36: - - memcpy(ios_36, dip_plugin, 4); // copy the entry_point - memcpy(dip_plugin, ios_36, 4*10); // copy the adresses from the array - - mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet - mload_write(dip_plugin, dip_plugin_size); - - // enables DIP plugin - mload_seek(0x20209040, SEEK_SET); - mload_write(ios_36, 4); - break; - - case 37: - - memcpy(ios_37, dip_plugin, 4); // copy the entry_point - memcpy(dip_plugin, ios_37, 4*10); // copy the adresses from the array - - mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet - mload_write(dip_plugin,dip_plugin_size); - - // enables DIP plugin - mload_seek(0x20209030, SEEK_SET); - mload_write(ios_37, 4); - break; - - case 38: - - memcpy(ios_38, dip_plugin, 4); // copy the entry_point - memcpy(dip_plugin, ios_38, 4*10); // copy the adresses from the array - - mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet - mload_write(dip_plugin,dip_plugin_size); - - // enables DIP plugin - mload_seek(0x20208030, SEEK_SET); - mload_write(ios_38, 4); - break; - - case 57: - - memcpy(ios_57, dip_plugin, 4); // copy the entry_point - memcpy(dip_plugin, ios_57, 4*10); // copy the adresses from the array - - mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet - mload_write(dip_plugin,dip_plugin_size); - - // enables DIP plugin - mload_seek(0x20208030, SEEK_SET); - mload_write(ios_57, 4); - break; - - case 60: - - memcpy(ios_60, dip_plugin, 4); // copy the entry_point - memcpy(dip_plugin, ios_60, 4*10); // copy the adresses from the array - - mload_seek(dip_address, SEEK_SET); // copy dip_plugin in the starlet - mload_write(dip_plugin,dip_plugin_size); - - // enables DIP plugin - mload_seek(0x20208030, SEEK_SET); - mload_write(ios_60, 4); - break; - - } - mload_close(); - return 0; -} - -void enable_ES_ioctlv_vector(void) -{ - mload_init(); - patch_datas[0]=*((u32 *) (dip_plugin+16*4)); - mload_set_ES_ioctlv_vector((void *) patch_datas[0]); - mload_close(); -} - -void Set_DIP_BCA_Datas(u8 *bca_data) -{ - // write in dip_plugin bca data area - mload_init(); - mload_seek(*((u32 *) (dip_plugin+15*4)), SEEK_SET); // offset 15 (bca_data area) - mload_write(bca_data, 64); - mload_close(); -} - -u8 *search_for_ehcmodule_cfg(u8 *p, int size) -{ - int n; - - for(n=0;n= 5 && mload_get_version() >= v51) - { - char fs[] ATTRIBUTE_ALIGN(32) = "/dev/mload/OFF"; - // shadow /dev/mload supported in hermes cios v5.1char fs[] ATTRIBUTE_ALIGN(32) = "/dev/usb2"; - IOS_Open(fs,0); - return true; - } - return false; -} diff --git a/source/mload/mload_modules.h b/source/mload/mload_modules.h deleted file mode 100644 index 74e4f64b..00000000 --- a/source/mload/mload_modules.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _MLOAD_MODULES_H_ -#define _MLOAD_MODULES_H_ - -#include "mload.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int load_modules(const u8 * ehcmodule, int ehcmodule_size, const u8 * dip_plugin, int dip_plugin_size); -void enable_ES_ioctlv_vector(void); -void Set_DIP_BCA_Datas(u8 *bca_data); -void disableIOSReload(void); -u8 *search_for_ehcmodule_cfg(u8 *p, int size); -bool shadow_mload(); - -#ifdef __cplusplus -} -#endif - -#endif - - diff --git a/source/mload/modules/dip_plugin_249.c b/source/mload/modules/dip_plugin_249.c deleted file mode 100644 index 4f6b211b..00000000 --- a/source/mload/modules/dip_plugin_249.c +++ /dev/null @@ -1,338 +0,0 @@ -#define size_dip_plugin_249 5340 - -unsigned char dip_plugin_249[5340] __attribute__((aligned (32)))={ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x02, 0x01, 0x61, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x13, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x34, 0x00, 0x20, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xa0, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0xa0, - 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0xd4, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x08, 0x13, 0x70, 0x00, 0x00, - 0x13, 0x70, 0x00, 0x00, 0x00, 0x00, 0x12, 0xe4, 0x00, 0x00, 0x12, 0xe4, 0x00, 0xf0, 0x00, 0x05, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x13, 0xec, 0x13, 0x70, 0x20, 0x00, - 0x13, 0x70, 0x20, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0xbd, 0xc0, 0x00, 0xf0, 0x00, 0x06, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, - 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x13, 0x70, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x7f, 0x13, 0x70, 0xdd, 0xc0, 0xe3, 0xa0, 0x00, 0x00, 0xe3, 0xa0, 0x10, 0x00, - 0xe5, 0x9f, 0x30, 0x00, 0xe1, 0x2f, 0xff, 0x13, 0x13, 0x70, 0x03, 0x8d, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xf0, 0xb0, 0x89, 0x1c, 0x0d, 0x1c, 0x06, - 0x1c, 0x17, 0x46, 0x68, 0x22, 0x20, 0x21, 0x00, 0xf0, 0x01, 0xf9, 0x0e, 0x23, 0xa8, 0x06, 0x1b, - 0x1c, 0x30, 0x1c, 0x29, 0x93, 0x00, 0x95, 0x01, 0x97, 0x02, 0xf0, 0x00, 0xed, 0x82, 0x1c, 0x31, - 0x1c, 0x2a, 0x46, 0x68, 0xf0, 0x00, 0xf9, 0x0b, 0xb0, 0x09, 0xbd, 0xf0, 0xb5, 0xf0, 0xb0, 0x8d, - 0x90, 0x01, 0x0a, 0xcb, 0x20, 0xa0, 0x27, 0xd0, 0x1c, 0x0d, 0x92, 0x03, 0x93, 0x02, 0x02, 0x00, - 0x26, 0x00, 0xac, 0x04, 0x06, 0x3f, 0xe0, 0x13, 0x22, 0x20, 0x21, 0x00, 0x1c, 0x20, 0xf0, 0x01, - 0xf8, 0xeb, 0x9b, 0x02, 0x98, 0x01, 0x60, 0xe3, 0x9b, 0x03, 0x1c, 0x29, 0x61, 0x23, 0x60, 0x27, - 0xf0, 0x00, 0xed, 0x5e, 0x1c, 0x20, 0x99, 0x01, 0x1c, 0x2a, 0xf0, 0x00, 0xf8, 0xe8, 0x36, 0x01, - 0x23, 0x0f, 0x42, 0xb3, 0xd3, 0x01, 0x28, 0x00, 0xd1, 0xe6, 0xb0, 0x0d, 0xbd, 0xf0, 0xb5, 0xf0, - 0xb0, 0x83, 0x24, 0x80, 0x93, 0x01, 0x01, 0x24, 0x18, 0x53, 0x90, 0x00, 0x1c, 0x0f, 0x1c, 0x16, - 0x42, 0xa3, 0xd8, 0x15, 0x1c, 0x20, 0x21, 0x20, 0xf0, 0x00, 0xe8, 0xa2, 0x1e, 0x05, 0xd0, 0x11, - 0x1c, 0x21, 0x1c, 0x28, 0x9a, 0x01, 0xf7, 0xff, 0xff, 0xc1, 0x1e, 0x04, 0xd1, 0x04, 0x19, 0xa9, - 0x98, 0x00, 0x1c, 0x3a, 0xf0, 0x01, 0xf8, 0x76, 0x1c, 0x28, 0xf0, 0x00, 0xe8, 0x9e, 0xe0, 0x03, - 0x24, 0x65, 0xe0, 0x00, 0x24, 0x16, 0x42, 0x64, 0xb0, 0x03, 0x1c, 0x20, 0xbd, 0xf0, 0x00, 0x00, - 0xb5, 0x10, 0x1c, 0x03, 0x1c, 0x0c, 0x48, 0x0a, 0x1c, 0x19, 0x22, 0x20, 0xf0, 0x01, 0xf8, 0x62, - 0x4b, 0x08, 0x68, 0x1b, 0x07, 0xda, 0xd4, 0x09, 0x2c, 0x00, 0xd0, 0x04, 0x1c, 0x20, 0x49, 0x04, - 0x22, 0x20, 0xf0, 0x01, 0xf8, 0x57, 0x4b, 0x04, 0x68, 0x18, 0xbd, 0x10, 0xe7, 0xfe, 0x46, 0xc0, - 0x0d, 0x00, 0x60, 0x00, 0x0d, 0x00, 0x60, 0x1c, 0x0d, 0x00, 0x60, 0x20, 0xb5, 0x00, 0x23, 0xe3, - 0xb0, 0x89, 0x06, 0x1b, 0x93, 0x00, 0x46, 0x68, 0x23, 0x00, 0x21, 0x00, 0x22, 0x00, 0x93, 0x01, - 0x93, 0x02, 0xf0, 0x00, 0xf8, 0x8c, 0xb0, 0x09, 0xbd, 0x00, 0xb5, 0xf0, 0xb0, 0x87, 0x92, 0x02, - 0x0a, 0x56, 0x23, 0xff, 0x22, 0x80, 0x01, 0x12, 0x03, 0xdb, 0x90, 0x05, 0x91, 0x04, 0x20, 0x00, - 0x27, 0x00, 0x92, 0x00, 0x93, 0x03, 0xe0, 0x30, 0x9a, 0x04, 0x02, 0x73, 0x1b, 0xd4, 0x9a, 0x02, - 0x25, 0x00, 0x42, 0x9a, 0xd9, 0x01, 0x1a, 0xd5, 0x00, 0xad, 0x9b, 0x05, 0x22, 0x80, 0x19, 0xdb, - 0x1c, 0x18, 0x1c, 0x21, 0x01, 0x12, 0x93, 0x01, 0xf0, 0x00, 0xf8, 0x7e, 0x28, 0x00, 0xd0, 0x01, - 0x2d, 0x00, 0xd0, 0x0b, 0x9a, 0x00, 0x19, 0x2b, 0x42, 0x93, 0xd9, 0x00, 0x1b, 0x54, 0x98, 0x01, - 0x1c, 0x21, 0x1c, 0x2a, 0x1c, 0x33, 0xf7, 0xff, 0xff, 0x7a, 0xe0, 0x0a, 0x9b, 0x03, 0x1c, 0x04, - 0x42, 0x98, 0xd9, 0x01, 0x24, 0xff, 0x03, 0xe4, 0x98, 0x01, 0x1c, 0x21, 0x1c, 0x32, 0xf7, 0xff, - 0xff, 0x45, 0x19, 0x65, 0x0a, 0xed, 0x19, 0x76, 0x19, 0x3f, 0x9a, 0x04, 0x42, 0x97, 0xd3, 0xcb, - 0xb0, 0x07, 0xbd, 0xf0, 0xb5, 0x08, 0xf7, 0xff, 0xff, 0x1f, 0xbd, 0x08, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x7c, - 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x13, 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, - 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x68, 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x0d, - 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x54, - 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x07, 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, - 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x40, 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x01, - 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, 0xe1, 0x2f, 0xff, 0x17, 0xb5, 0xf0, 0x46, 0x57, - 0x46, 0x46, 0xb4, 0xc0, 0x68, 0x05, 0x46, 0x8a, 0x4b, 0x09, 0x68, 0x1b, 0x47, 0x18, 0xb5, 0xf0, - 0x46, 0x5f, 0x46, 0x56, 0x46, 0x4d, 0x46, 0x44, 0xb4, 0xf0, 0x4b, 0x06, 0x68, 0x1b, 0x47, 0x18, - 0x13, 0x70, 0x21, 0x14, 0x13, 0x70, 0x21, 0x20, 0x13, 0x70, 0x21, 0x24, 0x13, 0x70, 0x21, 0x28, - 0x13, 0x70, 0x21, 0x18, 0x13, 0x70, 0x21, 0x1c, 0xb5, 0x30, 0x1c, 0x03, 0x20, 0x00, 0x06, 0xdc, - 0xd1, 0x17, 0x48, 0x0c, 0x24, 0x00, 0x42, 0x83, 0xd8, 0x02, 0x24, 0xc0, 0x04, 0x64, 0x1a, 0xe4, - 0x20, 0xf0, 0x06, 0x00, 0x18, 0x1d, 0x48, 0x08, 0x42, 0x85, 0xd8, 0x01, 0x4c, 0x07, 0x1a, 0xe4, - 0x20, 0x00, 0x42, 0x94, 0xd3, 0x03, 0x1c, 0x20, 0x42, 0x8c, 0xd9, 0x00, 0x1c, 0x08, 0x3a, 0x01, - 0x43, 0x90, 0xbd, 0x30, 0x01, 0x7f, 0xff, 0xff, 0x03, 0x61, 0x7f, 0xff, 0x13, 0x61, 0x80, 0x00, - 0xb5, 0x08, 0x21, 0x00, 0xf0, 0x00, 0xeb, 0xf4, 0x4b, 0x03, 0x60, 0x18, 0x1e, 0x43, 0x43, 0x03, - 0x17, 0xdb, 0x40, 0x18, 0xbd, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x20, 0x00, 0xb5, 0x08, 0x4b, 0x05, - 0x68, 0x18, 0x28, 0x00, 0xdb, 0x01, 0xf0, 0x00, 0xeb, 0xe8, 0x4a, 0x02, 0x23, 0x01, 0x42, 0x5b, - 0x60, 0x13, 0xbd, 0x08, 0x13, 0x70, 0x20, 0x00, 0xb5, 0x70, 0x4c, 0x0a, 0x1c, 0x05, 0x1c, 0x0e, - 0x68, 0x20, 0x00, 0x91, 0x22, 0x00, 0xf0, 0x00, 0xeb, 0xe4, 0x28, 0x00, 0xdb, 0x08, 0x68, 0x20, - 0x1c, 0x29, 0x1c, 0x32, 0xf0, 0x00, 0xeb, 0xd4, 0x1e, 0x43, 0x43, 0x03, 0x17, 0xdb, 0x40, 0x18, - 0xbd, 0x70, 0x46, 0xc0, 0x13, 0x70, 0x20, 0x00, 0xb5, 0x10, 0xf0, 0x00, 0xec, 0x32, 0xf0, 0x00, - 0xec, 0x36, 0x1c, 0x04, 0x20, 0x01, 0x42, 0x40, 0xf0, 0x00, 0xec, 0x34, 0x4b, 0x04, 0x68, 0x58, - 0xf0, 0x00, 0xf8, 0x22, 0x1c, 0x20, 0xf0, 0x00, 0xec, 0x2e, 0x20, 0x00, 0xbd, 0x10, 0x46, 0xc0, - 0x13, 0x70, 0x21, 0x00, 0xb5, 0x08, 0x48, 0x05, 0xf0, 0x00, 0xfb, 0x32, 0x48, 0x04, 0x21, 0x00, - 0x22, 0x00, 0xf0, 0x00, 0xfb, 0x23, 0x20, 0x00, 0xbd, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x21, 0x00, - 0x13, 0x70, 0x03, 0x41, 0xb5, 0x08, 0x48, 0x03, 0xf0, 0x00, 0xeb, 0xea, 0xf7, 0xff, 0xff, 0xea, - 0xbd, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x20, 0xa8, 0xb5, 0x10, 0x4b, 0x41, 0x42, 0x98, 0xd0, 0x32, - 0x42, 0x98, 0xd8, 0x03, 0x4b, 0x3f, 0x42, 0x98, 0xd1, 0x79, 0xe0, 0x06, 0x4b, 0x3e, 0x42, 0x98, - 0xd0, 0x4f, 0x4b, 0x3e, 0x42, 0x98, 0xd1, 0x72, 0xe0, 0x4b, 0x48, 0x3d, 0x4c, 0x3d, 0x21, 0x04, - 0x60, 0x04, 0xf0, 0x00, 0xeb, 0xea, 0x4b, 0x3c, 0x48, 0x3c, 0x21, 0x04, 0x60, 0x03, 0xf0, 0x00, - 0xeb, 0xe4, 0x48, 0x3b, 0x21, 0x04, 0x60, 0x04, 0xf0, 0x00, 0xeb, 0xde, 0x4b, 0x39, 0x48, 0x3a, - 0x21, 0x04, 0x60, 0x03, 0xf0, 0x00, 0xeb, 0xd8, 0x4b, 0x38, 0x4a, 0x39, 0x60, 0x1a, 0x4a, 0x39, - 0x60, 0x5a, 0x4a, 0x39, 0x60, 0x9a, 0x4a, 0x39, 0x60, 0xda, 0x3a, 0x30, 0x61, 0x1a, 0x4a, 0x38, - 0x61, 0x5a, 0x4a, 0x38, 0xe0, 0x4a, 0x48, 0x38, 0x4c, 0x2a, 0x21, 0x04, 0x60, 0x04, 0xf0, 0x00, - 0xeb, 0xc4, 0x4b, 0x29, 0x48, 0x35, 0x21, 0x04, 0x60, 0x03, 0xf0, 0x00, 0xeb, 0xbe, 0x48, 0x34, - 0x21, 0x04, 0x60, 0x04, 0xf0, 0x00, 0xeb, 0xb8, 0x4b, 0x26, 0x48, 0x32, 0x21, 0x04, 0x60, 0x03, - 0xf0, 0x00, 0xeb, 0xb2, 0x4b, 0x25, 0x4a, 0x30, 0x60, 0x1a, 0x4a, 0x30, 0x60, 0x5a, 0x4a, 0x30, - 0x60, 0x9a, 0x4a, 0x30, 0x60, 0xda, 0x3a, 0x2c, 0x61, 0x1a, 0x4a, 0x2f, 0x61, 0x5a, 0x4a, 0x2f, - 0xe0, 0x24, 0x48, 0x17, 0x4c, 0x17, 0x21, 0x04, 0x60, 0x04, 0xf0, 0x00, 0xeb, 0x9e, 0x4b, 0x16, - 0x48, 0x16, 0x21, 0x04, 0x60, 0x03, 0xf0, 0x00, 0xeb, 0x98, 0x48, 0x15, 0x21, 0x04, 0x60, 0x04, - 0xf0, 0x00, 0xeb, 0x92, 0x4b, 0x13, 0x48, 0x14, 0x21, 0x04, 0x60, 0x03, 0xf0, 0x00, 0xeb, 0x8c, - 0x4b, 0x12, 0x4a, 0x23, 0x60, 0x1a, 0x4a, 0x13, 0x60, 0x5a, 0x4a, 0x13, 0x60, 0x9a, 0x4a, 0x13, - 0x60, 0xda, 0x3a, 0x30, 0x61, 0x1a, 0x4a, 0x1f, 0x61, 0x5a, 0x4a, 0x1f, 0x61, 0x9a, 0xbd, 0x10, - 0x48, 0x88, 0xe1, 0x4c, 0x48, 0x77, 0x6f, 0x72, 0x49, 0x2a, 0xca, 0x9d, 0x4a, 0x26, 0x2a, 0xf5, - 0x20, 0x20, 0x04, 0x00, 0x4b, 0x00, 0x47, 0x18, 0x13, 0x70, 0x09, 0x45, 0x20, 0x20, 0x04, 0x04, - 0x20, 0x20, 0x0e, 0xf8, 0x13, 0x70, 0x06, 0x55, 0x20, 0x20, 0x0e, 0xfc, 0x13, 0x70, 0x21, 0x14, - 0x20, 0x20, 0x2a, 0x71, 0x20, 0x20, 0x04, 0x0d, 0x20, 0x20, 0x0f, 0x05, 0x20, 0x20, 0x09, 0x6d, - 0x20, 0x20, 0x38, 0x7d, 0x20, 0x22, 0xdd, 0x60, 0x20, 0x20, 0x03, 0xb8, 0x20, 0x20, 0x03, 0xbc, - 0x20, 0x20, 0x0d, 0x2c, 0x20, 0x20, 0x0d, 0x30, 0x20, 0x20, 0x28, 0x75, 0x20, 0x20, 0x03, 0xc5, - 0x20, 0x20, 0x0d, 0x39, 0x20, 0x20, 0x08, 0xc5, 0x20, 0x20, 0x36, 0x5d, 0x20, 0x22, 0xcd, 0xac, - 0x20, 0x20, 0x29, 0x45, 0x20, 0x20, 0x37, 0x51, 0x20, 0x22, 0xcd, 0x60, 0xb5, 0x00, 0x4b, 0x0b, - 0x68, 0x5b, 0x2b, 0x01, 0xd0, 0x02, 0x2b, 0x02, 0xd1, 0x0c, 0xe0, 0x01, 0x4a, 0x08, 0xe0, 0x00, - 0x4a, 0x08, 0x23, 0x00, 0x42, 0x90, 0xd3, 0x06, 0x4b, 0x04, 0x4a, 0x07, 0x61, 0x1a, 0x23, 0xa0, - 0x02, 0x1b, 0xe0, 0x00, 0x23, 0x00, 0x1c, 0x18, 0xbd, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x21, 0x30, - 0x46, 0x09, 0x00, 0x00, 0x7e, 0xd3, 0x80, 0x00, 0x00, 0x05, 0x21, 0x00, 0xb5, 0x70, 0x1c, 0x04, - 0x1c, 0x10, 0x1c, 0x0d, 0x1c, 0x16, 0xf7, 0xff, 0xff, 0xd9, 0x28, 0x00, 0xd1, 0x25, 0x4b, 0x13, - 0x68, 0xd9, 0x68, 0x9a, 0x68, 0x1b, 0x18, 0x8a, 0x19, 0x92, 0x06, 0xd9, 0xd5, 0x04, 0x1c, 0x20, - 0x1c, 0x29, 0xf0, 0x00, 0xfd, 0xd5, 0xe0, 0x18, 0x07, 0x19, 0xd5, 0x04, 0x1c, 0x20, 0x1c, 0x29, - 0xf7, 0xff, 0xfe, 0xba, 0xe0, 0x11, 0x07, 0x59, 0xd5, 0x04, 0x1c, 0x20, 0x1c, 0x29, 0xf0, 0x00, - 0xfb, 0x55, 0xe0, 0x0a, 0x07, 0xd9, 0xd5, 0x04, 0x1c, 0x20, 0x1c, 0x29, 0xf7, 0xff, 0xfd, 0xcd, - 0xe0, 0x03, 0x1c, 0x20, 0x1c, 0x29, 0xf7, 0xff, 0xfe, 0x0d, 0xbd, 0x70, 0x13, 0x70, 0x21, 0x30, - 0xb5, 0x10, 0x22, 0x00, 0x1c, 0x04, 0xf7, 0xff, 0xff, 0xc9, 0x28, 0x00, 0xdb, 0x0d, 0x69, 0xa2, - 0x4b, 0x06, 0x42, 0x9a, 0xd1, 0x09, 0x4b, 0x06, 0x21, 0x01, 0x68, 0x1a, 0x70, 0x11, 0x68, 0x1b, - 0x78, 0x5b, 0x2b, 0x00, 0xd1, 0x01, 0xf7, 0xff, 0xee, 0x00, 0xbd, 0x10, 0x5d, 0x1c, 0x9e, 0xa3, - 0x13, 0x70, 0x21, 0x2c, 0xb5, 0x10, 0x20, 0x80, 0x01, 0x00, 0x21, 0x20, 0xf7, 0xff, 0xee, 0x00, - 0x1e, 0x04, 0xd0, 0x0f, 0x21, 0x80, 0x22, 0xa0, 0x1c, 0x20, 0x01, 0x09, 0x05, 0xd2, 0xf7, 0xff, - 0xff, 0xa5, 0x1e, 0x43, 0x41, 0x98, 0x23, 0x02, 0x1a, 0x18, 0x4b, 0x03, 0x60, 0x58, 0x1c, 0x20, - 0xf7, 0xff, 0xed, 0xfa, 0xbd, 0x10, 0x46, 0xc0, 0x13, 0x70, 0x21, 0x30, 0x4b, 0x06, 0x21, 0x03, - 0x68, 0x1a, 0x43, 0x8a, 0x60, 0x1a, 0x22, 0x00, 0x60, 0x9a, 0x60, 0xda, 0x60, 0x5a, 0x61, 0x1a, - 0x61, 0x5a, 0x61, 0x9a, 0x47, 0x70, 0x46, 0xc0, 0x13, 0x70, 0x21, 0x30, 0xb5, 0xf0, 0xb0, 0x83, - 0x78, 0x03, 0x1c, 0x06, 0x1c, 0x0f, 0x92, 0x00, 0x2b, 0xe0, 0xd1, 0x00, 0xe0, 0xd4, 0x4c, 0xb4, - 0x22, 0x00, 0x61, 0x22, 0x2b, 0xe4, 0xd1, 0x00, 0xe0, 0xb5, 0x2b, 0xe4, 0xd8, 0x2a, 0x2b, 0xa8, - 0xd1, 0x00, 0xe0, 0x98, 0x2b, 0xa8, 0xd8, 0x10, 0x2b, 0x8a, 0xd0, 0x51, 0x2b, 0x8a, 0xd8, 0x05, - 0x2b, 0x70, 0xd0, 0x60, 0x2b, 0x71, 0xd0, 0x00, 0xe1, 0x48, 0xe0, 0x81, 0x2b, 0x8d, 0xd1, 0x00, - 0xe0, 0x89, 0x2b, 0xa4, 0xd0, 0x00, 0xe1, 0x41, 0xe0, 0xa4, 0x2b, 0xd9, 0xd1, 0x00, 0xe0, 0x8d, - 0x2b, 0xd9, 0xd8, 0x06, 0x2b, 0xab, 0xd1, 0x00, 0xe0, 0x95, 0x2b, 0xd0, 0xd0, 0x00, 0xe1, 0x35, - 0xe0, 0x79, 0x2b, 0xdb, 0xd1, 0x00, 0xe0, 0xa0, 0x2b, 0xdb, 0xd3, 0x7b, 0x2b, 0xe0, 0xd0, 0x00, - 0xe1, 0x2c, 0xe0, 0xa1, 0x2b, 0xf6, 0xd1, 0x00, 0xe1, 0x1e, 0x2b, 0xf6, 0xd8, 0x12, 0x2b, 0xf2, - 0xd1, 0x00, 0xe0, 0xaa, 0x2b, 0xf2, 0xd8, 0x06, 0x2b, 0xf0, 0xd1, 0x00, 0xe0, 0xa0, 0x2b, 0xf1, - 0xd0, 0x00, 0xe1, 0x1b, 0xe0, 0x9f, 0x2b, 0xf4, 0xd1, 0x00, 0xe0, 0xad, 0x2b, 0xf4, 0xd9, 0x00, - 0xe0, 0xbf, 0xe0, 0xa6, 0x2b, 0xf9, 0xd1, 0x00, 0xe0, 0xd7, 0x2b, 0xf9, 0xd8, 0x06, 0x2b, 0xf7, - 0xd1, 0x00, 0xe0, 0xb9, 0x2b, 0xf8, 0xd0, 0x00, 0xe1, 0x08, 0xe0, 0xca, 0x2b, 0xfb, 0xd1, 0x00, - 0xe0, 0xf3, 0x2b, 0xfb, 0xd2, 0x00, 0xe0, 0xed, 0x2b, 0xff, 0xd0, 0x00, 0xe0, 0xfe, 0xe0, 0xf6, - 0x69, 0xa3, 0x25, 0x00, 0x2b, 0x00, 0xd0, 0x00, 0xe0, 0xff, 0xf7, 0xff, 0xff, 0x7f, 0x68, 0x22, - 0x23, 0x1c, 0x42, 0x1a, 0xd1, 0x00, 0xe0, 0xf1, 0xf7, 0xff, 0xfc, 0xf8, 0x69, 0x62, 0x23, 0x04, - 0x43, 0x13, 0x61, 0x63, 0xe0, 0xf1, 0x68, 0xa3, 0x68, 0xe2, 0x25, 0x00, 0x43, 0x1a, 0x92, 0x01, - 0x68, 0x22, 0x23, 0x1c, 0x42, 0x1a, 0xd1, 0x09, 0x9a, 0x00, 0xf7, 0xff, 0xfd, 0x80, 0x1e, 0x05, - 0xd0, 0x04, 0x4b, 0x73, 0x22, 0x01, 0x68, 0x19, 0x43, 0x0a, 0x60, 0x1a, 0x4b, 0x70, 0x68, 0x1a, - 0x23, 0x1d, 0x40, 0x13, 0x9a, 0x01, 0x43, 0x1a, 0xd0, 0x04, 0x1c, 0x38, 0x99, 0x00, 0xf7, 0xff, - 0xff, 0x1f, 0x1c, 0x05, 0x2d, 0x00, 0xd0, 0x00, 0xe0, 0xcf, 0xf7, 0xff, 0xff, 0x33, 0xe0, 0xcc, - 0x68, 0x23, 0x07, 0x9a, 0xd4, 0x00, 0xe0, 0xc1, 0x68, 0x41, 0x68, 0x82, 0x1c, 0x38, 0xf7, 0xff, - 0xfe, 0xdd, 0x1c, 0x05, 0xe0, 0xc1, 0x68, 0x71, 0x68, 0xb2, 0x2b, 0xd0, 0xd1, 0xf6, 0x02, 0xc9, - 0x02, 0x52, 0xe7, 0xf3, 0x1c, 0x08, 0x22, 0x40, 0x99, 0x00, 0xe7, 0xf0, 0x68, 0x22, 0x23, 0x1d, - 0x42, 0x1a, 0xd1, 0x00, 0xe0, 0xaa, 0x68, 0x43, 0x68, 0x82, 0x07, 0x9b, 0x43, 0x13, 0x0b, 0xdb, - 0x03, 0xdb, 0x60, 0xe3, 0xe0, 0xa8, 0x68, 0x22, 0x23, 0x1d, 0x25, 0x00, 0x42, 0x1a, 0xd0, 0x00, - 0xe0, 0xa3, 0xe0, 0x9b, 0x68, 0x22, 0x23, 0x1d, 0x42, 0x1a, 0xd1, 0x00, 0xe0, 0x96, 0x4a, 0x51, - 0x4b, 0x4f, 0x25, 0xa0, 0x61, 0x1a, 0x02, 0x2d, 0xe0, 0x97, 0x68, 0x21, 0x23, 0x1c, 0x42, 0x19, - 0xd1, 0x00, 0xe0, 0x8b, 0x60, 0x3a, 0xe0, 0x8f, 0x4b, 0x49, 0x22, 0x1c, 0x68, 0x19, 0x42, 0x11, - 0xd1, 0x03, 0x69, 0x1b, 0x2b, 0x00, 0xd1, 0x00, 0xe0, 0x80, 0x4b, 0x45, 0x69, 0x1b, 0xe0, 0x6a, - 0x68, 0x43, 0x60, 0xa3, 0xe0, 0x80, 0x68, 0xa3, 0xe0, 0x65, 0x68, 0x43, 0x2b, 0x00, 0xd0, 0x03, - 0x68, 0x22, 0x23, 0x02, 0x43, 0x13, 0xe0, 0x02, 0x68, 0x23, 0x22, 0x02, 0x43, 0x93, 0x60, 0x23, - 0xe0, 0x72, 0x68, 0x23, 0x22, 0x02, 0xe0, 0x2e, 0x68, 0x47, 0xf0, 0x00, 0xf9, 0xf1, 0x68, 0x23, - 0x22, 0x04, 0x43, 0x93, 0x60, 0x23, 0x25, 0x00, 0x2f, 0x00, 0xd0, 0x66, 0x1c, 0x31, 0x1e, 0x78, - 0x31, 0x08, 0xf0, 0x00, 0xf9, 0xb9, 0x1e, 0x05, 0xd1, 0x5f, 0x4b, 0x31, 0x22, 0x04, 0x68, 0x19, - 0xe0, 0x3d, 0x68, 0x23, 0x22, 0x04, 0xe0, 0x16, 0x68, 0x46, 0xf7, 0xff, 0xfd, 0x37, 0x68, 0x23, - 0x22, 0x08, 0x43, 0x93, 0x60, 0x23, 0x25, 0x00, 0x2e, 0x00, 0xd0, 0x4e, 0x1c, 0x30, 0xf0, 0x00, - 0xe9, 0x9a, 0xf7, 0xff, 0xfd, 0x1d, 0x1e, 0x05, 0xd1, 0x47, 0x4b, 0x25, 0x22, 0x08, 0x68, 0x19, - 0xe0, 0x25, 0x68, 0x23, 0x22, 0x08, 0x40, 0x13, 0xe0, 0x25, 0x68, 0x43, 0x68, 0x82, 0x93, 0x00, - 0x92, 0x01, 0x68, 0xc6, 0xf0, 0x00, 0xfa, 0xc4, 0x68, 0x23, 0x22, 0x10, 0x43, 0x93, 0x60, 0x23, - 0x9b, 0x01, 0x2b, 0x00, 0xd0, 0x30, 0x9a, 0x00, 0x2a, 0x00, 0xd0, 0x2d, 0x25, 0x00, 0x2e, 0x00, - 0xd0, 0x2b, 0x1c, 0x18, 0xf0, 0x00, 0xe9, 0x76, 0x1c, 0x32, 0x1c, 0x01, 0x98, 0x00, 0xf0, 0x00, - 0xfa, 0xd9, 0x60, 0x38, 0x28, 0x00, 0xdd, 0x20, 0x4b, 0x11, 0x22, 0x10, 0x68, 0x19, 0x43, 0x0a, - 0x60, 0x1a, 0xe0, 0x1a, 0x68, 0x23, 0x60, 0x3b, 0xe0, 0x16, 0x4b, 0x0f, 0x60, 0x0b, 0x68, 0x23, - 0x60, 0x4b, 0x68, 0x63, 0x60, 0x8b, 0xe0, 0x0f, 0x68, 0x43, 0x61, 0xa3, 0xe0, 0x0c, 0x68, 0x40, - 0xf0, 0x00, 0xe9, 0x58, 0x1c, 0x39, 0xf7, 0xff, 0xfb, 0xeb, 0xe7, 0x42, 0x1c, 0x30, 0x1c, 0x39, - 0x9a, 0x00, 0xf7, 0xff, 0xfc, 0x9c, 0xe7, 0x3c, 0x25, 0x00, 0xb0, 0x03, 0x1c, 0x28, 0xbd, 0xf0, - 0x13, 0x70, 0x21, 0x30, 0x00, 0x05, 0x31, 0x00, 0x48, 0x45, 0x4c, 0x4f, 0xb5, 0x38, 0x1c, 0x03, - 0x68, 0x1a, 0x68, 0xc0, 0x2a, 0x86, 0xd0, 0x19, 0x2a, 0x86, 0xd8, 0x04, 0x2a, 0x79, 0xd0, 0x07, - 0x2a, 0x7a, 0xd1, 0x2d, 0xe0, 0x0b, 0x2a, 0x88, 0xd0, 0x1b, 0x2a, 0x95, 0xd1, 0x28, 0xe0, 0x20, - 0x4a, 0x15, 0x20, 0x01, 0x68, 0x14, 0x22, 0x1c, 0x42, 0x14, 0xd1, 0x24, 0xe0, 0x20, 0x4a, 0x12, - 0x24, 0x1c, 0x68, 0x15, 0x42, 0x25, 0xd0, 0x1b, 0x69, 0x53, 0xe0, 0x10, 0x4a, 0x0e, 0x20, 0x1c, - 0x68, 0x14, 0x42, 0x04, 0xd0, 0x14, 0x69, 0x53, 0x21, 0x04, 0x43, 0x8b, 0x61, 0x53, 0x20, 0x01, - 0xe0, 0x11, 0x4a, 0x09, 0x68, 0x14, 0x22, 0x1c, 0x42, 0x14, 0xd0, 0x09, 0x23, 0x02, 0x60, 0x03, - 0xe7, 0xf5, 0x4a, 0x05, 0x68, 0x14, 0x22, 0x1c, 0x42, 0x14, 0xd0, 0x01, 0x23, 0x0a, 0xe7, 0xf6, - 0x1c, 0x18, 0xf7, 0xff, 0xfc, 0x4b, 0xbd, 0x38, 0x13, 0x70, 0x21, 0x30, 0xb5, 0x38, 0x1c, 0x05, - 0x1c, 0x0c, 0x1c, 0x13, 0x1c, 0x29, 0x1c, 0x22, 0x20, 0x10, 0xf0, 0x00, 0xe8, 0xf8, 0xbd, 0x38, - 0xb5, 0x08, 0x1c, 0x01, 0x22, 0x00, 0x20, 0x12, 0x23, 0x00, 0xf0, 0x00, 0xe8, 0xf0, 0xbd, 0x08, - 0xe6, 0x00, 0x00, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0x30, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0x50, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0x70, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0x30, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0x50, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0x70, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0x30, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0x50, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0x70, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0x30, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x50, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0x70, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0x30, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0x50, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0x70, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x05, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x05, 0x30, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x05, 0x50, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x06, 0x90, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x07, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x08, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x09, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x0a, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe1, 0xa0, 0x20, 0x0e, 0xe2, 0x90, 0x10, 0x00, 0xe3, 0xb0, 0x00, 0x04, 0xef, 0x00, 0x00, 0xab, - 0xe1, 0x2f, 0xff, 0x12, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x9f, 0xc0, 0x54, 0xe5, 0x9c, 0xc0, 0x00, - 0xe1, 0xa0, 0x00, 0x00, 0xe7, 0x9c, 0xc1, 0x0b, 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0x2f, 0xff, 0x1c, - 0xe3, 0xa0, 0xb0, 0x3f, 0xea, 0xff, 0xff, 0xf7, 0xe3, 0xa0, 0xb0, 0x40, 0xea, 0xff, 0xff, 0xf5, - 0xe3, 0xa0, 0x00, 0x00, 0xee, 0x07, 0x0f, 0x15, 0xe1, 0x2f, 0xff, 0x1e, 0xee, 0x13, 0x0f, 0x10, - 0xe1, 0x2f, 0xff, 0x1e, 0xee, 0x03, 0x0f, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xef, 0x00, 0x00, 0xcc, - 0xe1, 0x2f, 0xff, 0x1e, 0xe3, 0xc0, 0x01, 0x02, 0xe1, 0x2f, 0xff, 0x1e, 0xe3, 0x80, 0x01, 0x02, - 0xe1, 0x2f, 0xff, 0x1e, 0x13, 0x70, 0x21, 0x00, 0xb5, 0x70, 0xb0, 0x82, 0x4b, 0x10, 0x00, 0x80, - 0x58, 0xc0, 0x1c, 0x0e, 0x21, 0x01, 0xf7, 0xff, 0xef, 0x6c, 0x4b, 0x0e, 0x1c, 0x05, 0x60, 0x18, - 0x28, 0x00, 0xdb, 0x11, 0x4c, 0x0c, 0x1c, 0x31, 0x1c, 0x20, 0x22, 0x06, 0xf0, 0x00, 0xfa, 0xe2, - 0x23, 0x06, 0x64, 0x63, 0x64, 0x24, 0x1c, 0x28, 0x34, 0x40, 0x49, 0x08, 0x22, 0x01, 0x23, 0x00, - 0x94, 0x00, 0xf7, 0xff, 0xef, 0x6e, 0x1c, 0x05, 0xb0, 0x02, 0x1c, 0x28, 0xbd, 0x70, 0x46, 0xc0, - 0x13, 0x70, 0x20, 0xa0, 0x13, 0x70, 0x20, 0x04, 0x13, 0x70, 0x21, 0x60, 0x57, 0x46, 0x53, 0x01, - 0xb5, 0x08, 0x4b, 0x05, 0x68, 0x18, 0x28, 0x00, 0xdb, 0x01, 0xf7, 0xff, 0xef, 0x46, 0x4a, 0x02, - 0x23, 0x01, 0x42, 0x5b, 0x60, 0x13, 0xbd, 0x08, 0x13, 0x70, 0x20, 0x04, 0xb5, 0xf0, 0xb0, 0x83, - 0x4c, 0x14, 0x23, 0x04, 0x60, 0x22, 0x1c, 0x26, 0x1c, 0x22, 0x32, 0x20, 0x36, 0x40, 0x64, 0x63, - 0x64, 0xa2, 0x64, 0xe3, 0x62, 0x21, 0x65, 0x20, 0x65, 0x61, 0x64, 0x24, 0x1c, 0x07, 0x1c, 0x0d, - 0x1c, 0x30, 0x21, 0x20, 0xf7, 0xff, 0xef, 0x68, 0x1c, 0x20, 0x21, 0x24, 0xf7, 0xff, 0xef, 0x64, - 0x4b, 0x09, 0x49, 0x0a, 0x68, 0x18, 0x22, 0x02, 0x23, 0x01, 0x96, 0x00, 0xf7, 0xff, 0xef, 0x30, - 0x1e, 0x04, 0xd1, 0x03, 0x1c, 0x38, 0x1c, 0x29, 0xf7, 0xff, 0xef, 0x52, 0xb0, 0x03, 0x1c, 0x20, - 0xbd, 0xf0, 0x46, 0xc0, 0x13, 0x70, 0x21, 0x60, 0x13, 0x70, 0x20, 0x04, 0x57, 0x46, 0x53, 0x02, - 0xb5, 0x70, 0xb0, 0x82, 0x1c, 0x03, 0x48, 0x1c, 0x68, 0x04, 0x20, 0x00, 0x2c, 0x00, 0xdb, 0x31, - 0x4e, 0x1a, 0x60, 0x33, 0x23, 0x04, 0x62, 0x73, 0x62, 0xf3, 0x6b, 0xb3, 0x60, 0x71, 0x43, 0x59, - 0x1c, 0x34, 0x1d, 0x30, 0x34, 0x20, 0x62, 0x36, 0x62, 0xb0, 0x63, 0x32, 0x63, 0x71, 0x1c, 0x25, - 0x36, 0x38, 0x68, 0x28, 0x68, 0x69, 0xf7, 0xff, 0xef, 0x30, 0x35, 0x08, 0x42, 0xb5, 0xd1, 0xf8, - 0x4d, 0x0e, 0x21, 0x18, 0x35, 0x20, 0x1c, 0x28, 0xf7, 0xff, 0xef, 0x26, 0x4b, 0x0a, 0x49, 0x0c, - 0x68, 0x18, 0x22, 0x02, 0x23, 0x01, 0x95, 0x00, 0xf7, 0xff, 0xee, 0xf2, 0x1c, 0x03, 0x20, 0x00, - 0x2b, 0x00, 0xdb, 0x07, 0x68, 0x20, 0x68, 0x61, 0xf7, 0xff, 0xef, 0x12, 0x34, 0x08, 0x42, 0xb4, - 0xd1, 0xf8, 0x20, 0x01, 0xb0, 0x02, 0xbd, 0x70, 0x13, 0x70, 0x20, 0x20, 0x13, 0x70, 0x21, 0xc0, - 0x55, 0x4d, 0x53, 0x03, 0xb5, 0x30, 0xb0, 0x83, 0x4c, 0x0e, 0x25, 0x00, 0x68, 0x23, 0x2b, 0x00, - 0xda, 0x14, 0x1c, 0x20, 0x30, 0x20, 0x21, 0x01, 0xf7, 0xff, 0xee, 0xba, 0x60, 0x20, 0x28, 0x00, - 0xdb, 0x0a, 0x22, 0x00, 0x23, 0x00, 0x49, 0x08, 0x95, 0x00, 0xf7, 0xff, 0xee, 0xca, 0x4a, 0x07, - 0x23, 0x80, 0x00, 0x9b, 0x63, 0x93, 0xe0, 0x01, 0x25, 0x0b, 0x42, 0x6d, 0xb0, 0x03, 0x1c, 0x28, - 0xbd, 0x30, 0x46, 0xc0, 0x13, 0x70, 0x20, 0x20, 0x55, 0x4d, 0x53, 0x01, 0x13, 0x70, 0x21, 0xc0, - 0xb5, 0x30, 0xb0, 0x83, 0x4c, 0x0d, 0x25, 0x00, 0x68, 0x23, 0x2b, 0x00, 0xda, 0x13, 0x1c, 0x20, - 0x30, 0x20, 0x21, 0x01, 0xf7, 0xff, 0xee, 0x94, 0x60, 0x20, 0x28, 0x00, 0xdb, 0x09, 0x23, 0x00, - 0x21, 0x01, 0x22, 0x00, 0x95, 0x00, 0xf7, 0xff, 0xee, 0xa4, 0x23, 0x80, 0x00, 0x9b, 0x63, 0x23, - 0xe0, 0x01, 0x25, 0x0b, 0x42, 0x6d, 0xb0, 0x03, 0x1c, 0x28, 0xbd, 0x30, 0x13, 0x70, 0x20, 0x60, - 0xb5, 0x70, 0xb0, 0x82, 0x4c, 0x1c, 0x1c, 0x03, 0x68, 0x25, 0x20, 0x00, 0x2d, 0x00, 0xdb, 0x31, - 0x4e, 0x1a, 0x60, 0x33, 0x23, 0x04, 0x62, 0x73, 0x62, 0xf3, 0x6b, 0x23, 0x60, 0x71, 0x43, 0x59, - 0x1c, 0x34, 0x1d, 0x30, 0x34, 0x20, 0x62, 0x36, 0x62, 0xb0, 0x63, 0x32, 0x63, 0x71, 0x1c, 0x25, - 0x36, 0x38, 0x68, 0x28, 0x68, 0x69, 0xf7, 0xff, 0xee, 0xa8, 0x35, 0x08, 0x42, 0xb5, 0xd1, 0xf8, - 0x4d, 0x0e, 0x21, 0x18, 0x35, 0x20, 0x1c, 0x28, 0xf7, 0xff, 0xee, 0x9e, 0x4b, 0x0a, 0x21, 0x02, - 0x68, 0x18, 0x22, 0x02, 0x23, 0x01, 0x95, 0x00, 0xf7, 0xff, 0xee, 0x6a, 0x1c, 0x03, 0x20, 0x00, - 0x2b, 0x00, 0xdb, 0x07, 0x68, 0x20, 0x68, 0x61, 0xf7, 0xff, 0xee, 0x8a, 0x34, 0x08, 0x42, 0xb4, - 0xd1, 0xf8, 0x20, 0x01, 0xb0, 0x02, 0xbd, 0x70, 0x13, 0x70, 0x20, 0x60, 0x13, 0x70, 0x22, 0x00, - 0x4b, 0x02, 0x22, 0x00, 0x60, 0x1a, 0x60, 0x5a, 0x60, 0x9a, 0x47, 0x70, 0x13, 0x70, 0x22, 0x40, - 0xb5, 0xf0, 0x48, 0x0f, 0x21, 0xa0, 0x68, 0x44, 0x23, 0x00, 0x30, 0x0c, 0x22, 0x00, 0x00, 0x89, - 0x03, 0xd6, 0xe0, 0x01, 0x04, 0x2b, 0x0c, 0x1b, 0x00, 0x5d, 0x18, 0xed, 0x00, 0xad, 0x19, 0x65, - 0x69, 0x6f, 0x68, 0xed, 0x19, 0x7d, 0x42, 0xae, 0xd3, 0x03, 0x68, 0x67, 0x1c, 0x5d, 0x42, 0xbd, - 0xd3, 0xf0, 0x32, 0x01, 0x80, 0x03, 0x30, 0x02, 0x42, 0x8a, 0xd1, 0xe9, 0xbd, 0xf0, 0x46, 0xc0, - 0x13, 0x70, 0x22, 0x40, 0xb5, 0xf8, 0x4b, 0x20, 0x1c, 0x06, 0x68, 0x1b, 0x1c, 0x0f, 0x1c, 0x15, - 0x2b, 0x00, 0xd0, 0x01, 0xf7, 0xff, 0xff, 0xcc, 0x1e, 0x73, 0x2b, 0x01, 0xd8, 0x2e, 0x2d, 0x00, - 0xd0, 0x2c, 0x4b, 0x1a, 0x42, 0x9d, 0xd8, 0x2b, 0x4c, 0x19, 0x2e, 0x01, 0xd1, 0x02, 0xf7, 0xff, - 0xff, 0x39, 0xe0, 0x01, 0xf7, 0xff, 0xff, 0x5c, 0x4b, 0x15, 0x60, 0xe0, 0x68, 0xd8, 0x28, 0x00, - 0xd1, 0x20, 0x4c, 0x11, 0x33, 0x10, 0x60, 0x63, 0x60, 0xa6, 0x1c, 0x38, 0x1c, 0x29, 0xf7, 0xff, - 0xee, 0x30, 0x68, 0x66, 0x21, 0x00, 0x4a, 0x0d, 0x1c, 0x30, 0xf0, 0x00, 0xf9, 0xad, 0x1c, 0x2a, - 0x1c, 0x39, 0x1c, 0x30, 0xf0, 0x00, 0xf9, 0x66, 0x1c, 0x38, 0x1c, 0x29, 0xf7, 0xff, 0xee, 0x24, - 0xf7, 0xff, 0xff, 0xa6, 0x23, 0x01, 0x60, 0x23, 0x1c, 0x28, 0xe0, 0x03, 0x20, 0x01, 0xe0, 0x00, - 0x20, 0x02, 0x42, 0x40, 0xbd, 0xf8, 0x46, 0xc0, 0x13, 0x70, 0x22, 0x40, 0x00, 0x00, 0xa4, 0x1c, - 0x13, 0x70, 0x27, 0x40, 0xb5, 0xf0, 0xb0, 0x83, 0x4d, 0x33, 0x24, 0xa0, 0x0b, 0xcf, 0x00, 0xa4, - 0x9e, 0x09, 0x62, 0xef, 0x42, 0xa7, 0xd9, 0x01, 0x4c, 0x30, 0x62, 0xec, 0x4d, 0x2e, 0x4f, 0x30, - 0x6a, 0xec, 0x46, 0x9c, 0x00, 0x64, 0x19, 0x3c, 0x89, 0xa4, 0x63, 0x2c, 0x63, 0x6c, 0x00, 0x67, - 0x68, 0x45, 0x19, 0x3f, 0x00, 0xbf, 0x95, 0x00, 0x19, 0xc7, 0x18, 0x55, 0x37, 0x0c, 0x95, 0x01, - 0xe0, 0x35, 0x68, 0x3d, 0x42, 0x8d, 0xd8, 0x18, 0x68, 0xbb, 0x18, 0xeb, 0x42, 0x8b, 0xd9, 0x2c, - 0x4f, 0x21, 0x1b, 0x4d, 0x46, 0x63, 0x63, 0x7c, 0x63, 0xbd, 0x60, 0x19, 0x00, 0x63, 0x19, 0x1c, - 0x00, 0xa4, 0x19, 0x00, 0x69, 0x03, 0x99, 0x08, 0x18, 0xeb, 0x60, 0x0b, 0x69, 0x43, 0x20, 0x00, - 0x1b, 0x5d, 0x60, 0x35, 0x42, 0x95, 0xd9, 0x2d, 0xe0, 0x15, 0x9b, 0x01, 0x42, 0x9d, 0xd2, 0x14, - 0x4f, 0x15, 0x46, 0x63, 0x1a, 0x69, 0x63, 0x7c, 0x63, 0xb9, 0x60, 0x1d, 0x00, 0x63, 0x19, 0x1c, - 0x00, 0xa4, 0x19, 0x00, 0x69, 0x03, 0x9c, 0x08, 0x1a, 0x52, 0x60, 0x23, 0x69, 0x43, 0x20, 0x00, - 0x60, 0x33, 0x42, 0x93, 0xd9, 0x16, 0x60, 0x32, 0xe0, 0x14, 0x34, 0x01, 0x37, 0x0c, 0x9d, 0x00, - 0x42, 0xac, 0xd3, 0xc6, 0x4d, 0x08, 0x18, 0x51, 0x68, 0x02, 0x46, 0x63, 0x63, 0x6c, 0x42, 0x91, - 0xd8, 0x06, 0x60, 0x19, 0x99, 0x08, 0x23, 0x00, 0x60, 0x0b, 0x20, 0x00, 0x60, 0x33, 0xe0, 0x01, - 0x20, 0x02, 0x42, 0x40, 0xb0, 0x03, 0xbd, 0xf0, 0x13, 0x70, 0xcb, 0x40, 0x00, 0x00, 0x02, 0x7f, - 0x13, 0x70, 0x22, 0x40, 0xb5, 0xf0, 0xb0, 0x85, 0x1c, 0x07, 0x1c, 0x0e, 0x92, 0x02, 0x4d, 0x28, - 0xe0, 0x43, 0x4a, 0x28, 0x4b, 0x28, 0x68, 0x50, 0x93, 0x00, 0x1c, 0x2b, 0x33, 0x44, 0x93, 0x01, - 0x1c, 0x39, 0x9a, 0x02, 0x4b, 0x25, 0xf7, 0xff, 0xff, 0x7d, 0x64, 0xa8, 0x28, 0x00, 0xd1, 0x3d, - 0x6b, 0xeb, 0x1b, 0xdb, 0x93, 0x03, 0x64, 0xeb, 0x2b, 0x00, 0xd0, 0x0b, 0x02, 0x5c, 0x1c, 0x30, - 0x1c, 0x22, 0x21, 0x00, 0xf0, 0x00, 0xf9, 0x00, 0x9a, 0x03, 0x9b, 0x02, 0x18, 0xbf, 0x1a, 0x9b, - 0x19, 0x36, 0x93, 0x02, 0x4c, 0x16, 0x6c, 0x61, 0x29, 0x00, 0xd0, 0x18, 0x4b, 0x15, 0x68, 0x9b, - 0x2b, 0x01, 0xd1, 0x04, 0x6c, 0x20, 0x1c, 0x32, 0xf7, 0xff, 0xfe, 0x22, 0xe0, 0x03, 0x6c, 0x20, - 0x1c, 0x32, 0xf7, 0xff, 0xfe, 0xa5, 0x4b, 0x0e, 0x64, 0xa0, 0x6c, 0x9a, 0x2a, 0x00, 0xd0, 0x11, - 0x6c, 0x5b, 0x02, 0x5a, 0x18, 0xb6, 0x9a, 0x02, 0x18, 0xff, 0x1a, 0xd2, 0x92, 0x02, 0x4b, 0x08, - 0x6c, 0x5a, 0x6c, 0xdb, 0x18, 0xd3, 0x2b, 0x00, 0xd0, 0x06, 0x9b, 0x02, 0x2b, 0x00, 0xd1, 0xb8, - 0x20, 0x00, 0xe0, 0x03, 0x20, 0x03, 0xe0, 0x00, 0x20, 0x04, 0x42, 0x40, 0xb0, 0x05, 0xbd, 0xf0, - 0x13, 0x70, 0xcb, 0x40, 0x13, 0x70, 0x22, 0x40, 0x13, 0x70, 0xcb, 0x80, 0x13, 0x70, 0xcb, 0x7c, - 0xb5, 0xf8, 0x24, 0x7f, 0x1c, 0x0f, 0x1c, 0x1e, 0x09, 0xc1, 0x4b, 0x17, 0x40, 0x20, 0x24, 0x80, - 0x00, 0x80, 0x00, 0xa4, 0x1a, 0x24, 0x65, 0x19, 0x65, 0x58, 0x65, 0x9c, 0x42, 0x94, 0xd9, 0x00, - 0x65, 0x9a, 0x4a, 0x11, 0x23, 0x80, 0x6d, 0x90, 0x00, 0x9b, 0x42, 0x98, 0xd1, 0x01, 0x23, 0x00, - 0x65, 0x93, 0x4c, 0x0d, 0x6d, 0xa3, 0x2b, 0x00, 0xd0, 0x10, 0x1c, 0x25, 0x35, 0x60, 0x1c, 0x08, - 0x22, 0x01, 0x1c, 0x29, 0xf7, 0xff, 0xff, 0x7e, 0x4b, 0x08, 0x66, 0x18, 0x28, 0x00, 0xd1, 0x09, - 0x6d, 0x61, 0x6d, 0xa2, 0x18, 0x69, 0x1c, 0x38, 0xf0, 0x00, 0xf8, 0x54, 0x4b, 0x02, 0x20, 0x00, - 0x6d, 0x9b, 0x60, 0x33, 0xbd, 0xf8, 0x46, 0xc0, 0x13, 0x70, 0xcb, 0x40, 0x13, 0x70, 0xcd, 0x40, - 0xb5, 0xf0, 0xb0, 0x83, 0x4c, 0x21, 0x91, 0x01, 0x1c, 0x06, 0x1c, 0x23, 0x1c, 0x10, 0x1c, 0x17, - 0x33, 0x64, 0x1c, 0x31, 0x9a, 0x01, 0xf7, 0xff, 0xff, 0xbb, 0x1c, 0x05, 0x66, 0xa0, 0x28, 0x00, - 0xd1, 0x31, 0x6e, 0x63, 0x08, 0x9a, 0x18, 0xbf, 0x9a, 0x01, 0x18, 0xf6, 0x96, 0x00, 0x1a, 0xd6, - 0x4b, 0x17, 0x42, 0x9e, 0xd9, 0x11, 0x09, 0xf8, 0x0a, 0x72, 0x66, 0xe0, 0x67, 0x22, 0x99, 0x00, - 0xf7, 0xff, 0xff, 0x48, 0x66, 0xa0, 0x28, 0x00, 0xd1, 0x19, 0x6f, 0x23, 0x01, 0xda, 0x18, 0xbf, - 0x9a, 0x00, 0x02, 0x5b, 0x18, 0xd2, 0x1a, 0xf6, 0x92, 0x00, 0x2e, 0x00, 0xd0, 0x13, 0x4c, 0x0b, - 0x1c, 0x38, 0x1c, 0x23, 0x33, 0x64, 0x99, 0x00, 0x1c, 0x32, 0xf7, 0xff, 0xff, 0x91, 0x1c, 0x05, - 0x66, 0xa0, 0x28, 0x00, 0xd1, 0x07, 0x6e, 0x63, 0x42, 0x9e, 0xd1, 0x02, 0xe0, 0x03, 0x1c, 0x05, - 0xe0, 0x01, 0x25, 0x05, 0x42, 0x6d, 0xb0, 0x03, 0x1c, 0x28, 0xbd, 0xf0, 0x13, 0x70, 0xcd, 0x40, - 0x00, 0x00, 0x01, 0xff, 0xb5, 0xf0, 0x1c, 0x05, 0x1c, 0x0e, 0x1c, 0x14, 0x2a, 0x0f, 0xd9, 0x03, - 0x1c, 0x0b, 0x43, 0x03, 0x07, 0x9f, 0xd0, 0x0a, 0x2c, 0x00, 0xd0, 0x05, 0x23, 0x00, 0x5c, 0xf2, - 0x54, 0xea, 0x33, 0x01, 0x42, 0xa3, 0xd1, 0xfa, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x1c, 0x15, - 0x1c, 0x0c, 0x1c, 0x03, 0x68, 0x26, 0x60, 0x1e, 0x68, 0x66, 0x60, 0x5e, 0x68, 0xa6, 0x60, 0x9e, - 0x68, 0xe6, 0x3d, 0x10, 0x60, 0xde, 0x34, 0x10, 0x33, 0x10, 0x2d, 0x0f, 0xd8, 0xf2, 0x3a, 0x10, - 0x09, 0x17, 0x1c, 0x7e, 0x01, 0x3f, 0x01, 0x36, 0x1b, 0xd7, 0x19, 0x85, 0x1c, 0x3c, 0x19, 0x8e, - 0x2f, 0x03, 0xd9, 0xd9, 0x1c, 0x34, 0x1c, 0x3b, 0x1c, 0x2a, 0xcc, 0x02, 0x3b, 0x04, 0xc2, 0x02, - 0x2b, 0x03, 0xd8, 0xfa, 0x3f, 0x04, 0x08, 0xbc, 0x1c, 0x63, 0x00, 0x9b, 0x00, 0xa4, 0x18, 0xed, - 0x18, 0xf6, 0x1b, 0x3c, 0xe7, 0xc8, 0x46, 0xc0, 0xb5, 0x70, 0x1c, 0x03, 0x07, 0x84, 0xd0, 0x0d, - 0x2a, 0x00, 0xd0, 0x40, 0x06, 0x0d, 0x3a, 0x01, 0x0e, 0x2d, 0x24, 0x03, 0xe0, 0x02, 0x2a, 0x00, - 0xd0, 0x39, 0x3a, 0x01, 0x70, 0x1d, 0x33, 0x01, 0x42, 0x23, 0xd1, 0xf8, 0x2a, 0x03, 0xd9, 0x29, - 0x25, 0xff, 0x40, 0x0d, 0x02, 0x2c, 0x43, 0x25, 0x04, 0x2c, 0x1c, 0x1e, 0x43, 0x25, 0x2a, 0x0f, - 0xd9, 0x12, 0x1c, 0x1c, 0x1c, 0x16, 0x3e, 0x10, 0x60, 0x25, 0x60, 0x65, 0x60, 0xa5, 0x60, 0xe5, - 0x34, 0x10, 0x2e, 0x0f, 0xd8, 0xf7, 0x3a, 0x10, 0x09, 0x16, 0x36, 0x01, 0x01, 0x36, 0x19, 0x9e, - 0x23, 0x0f, 0x40, 0x1a, 0x2a, 0x03, 0xd9, 0x0c, 0x1c, 0x34, 0x1c, 0x13, 0x3b, 0x04, 0xc4, 0x20, - 0x2b, 0x03, 0xd8, 0xfb, 0x3a, 0x04, 0x08, 0x93, 0x33, 0x01, 0x00, 0x9b, 0x18, 0xf6, 0x23, 0x03, - 0x40, 0x1a, 0x1c, 0x33, 0x2a, 0x00, 0xd0, 0x06, 0x06, 0x09, 0x0e, 0x0c, 0x21, 0x00, 0x54, 0x5c, - 0x31, 0x01, 0x42, 0x8a, 0xd1, 0xfb, 0xbc, 0x70, 0xbc, 0x02, 0x47, 0x08, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x64, 0x65, 0x76, - 0x2f, 0x75, 0x73, 0x62, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x64, 0x65, 0x76, - 0x2f, 0x73, 0x64, 0x69, 0x6f, 0x2f, 0x73, 0x64, 0x68, 0x63, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x70, 0x20, 0xd6, - 0x13, 0x70, 0x20, 0xe0, 0x24, 0x49, 0x4f, 0x53, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, - 0x20, 0x44, 0x49, 0x50, 0x50, 0x3a, 0x20, 0x53, 0x65, 0x70, 0x20, 0x20, 0x37, 0x20, 0x32, 0x30, - 0x31, 0x30, 0x20, 0x31, 0x32, 0x3a, 0x32, 0x33, 0x3a, 0x31, 0x34, 0x20, 0x36, 0x34, 0x4d, 0x24, - 0x0a, 0x00, 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x75, 0x73, 0x62, 0x32, 0x00, 0x2f, 0x64, 0x65, 0x76, - 0x2f, 0x73, 0x64, 0x69, 0x6f, 0x2f, 0x73, 0x64, 0x68, 0x63, 0x00, 0x00 -}; diff --git a/source/mload/modules/dip_plugin_249.h b/source/mload/modules/dip_plugin_249.h deleted file mode 100644 index ceaf4f96..00000000 --- a/source/mload/modules/dip_plugin_249.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef DIP_PLUGIN249_H_ -#define DIP_PLUGIN249_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern unsigned char dip_plugin_249[5340]; - -#define dip_plugin_249_size sizeof(dip_plugin_249) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/mload/modules/ehcmodule_5.c b/source/mload/modules/ehcmodule_5.c deleted file mode 100644 index 03f9c66e..00000000 --- a/source/mload/modules/ehcmodule_5.c +++ /dev/null @@ -1,1585 +0,0 @@ -#define size_ehcmodule_5 25287 - -unsigned char ehcmodule_5[25287] __attribute__((aligned (32)))={ - 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x02, 0x01, 0x61, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x13, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x34, 0x00, 0x20, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0xa0, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0xa0, - 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x34, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0xd4, 0x00, 0xf0, 0x00, 0x00, - 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x08, 0x13, 0x70, 0x00, 0x00, - 0x13, 0x70, 0x00, 0x00, 0x00, 0x00, 0x5a, 0x94, 0x00, 0x00, 0x5a, 0x94, 0x00, 0xf0, 0x00, 0x05, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x5b, 0x9c, 0x13, 0x70, 0x60, 0x00, - 0x13, 0x70, 0x60, 0x00, 0x00, 0x00, 0x07, 0x2b, 0x00, 0x02, 0x95, 0xa8, 0x00, 0xf0, 0x00, 0x06, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x06, - 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x09, 0x13, 0x70, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x30, 0x00, - 0x00, 0x00, 0x00, 0x7f, 0x13, 0x72, 0xf3, 0xa8, 0xe3, 0xa0, 0x00, 0x00, 0xe3, 0xa0, 0x10, 0x00, - 0xe5, 0x9f, 0x31, 0x00, 0xe1, 0x2f, 0xff, 0x13, 0xe5, 0x9f, 0xc0, 0xfc, 0xe5, 0x9c, 0xc0, 0x00, - 0xe1, 0xa0, 0x00, 0x00, 0xe7, 0x9c, 0xc1, 0x0b, 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0x2f, 0xff, 0x1c, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0xe3, 0xa0, 0xb0, 0x3f, 0xea, 0xff, 0xff, 0xf5, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0xe3, 0xa0, 0xb0, 0x40, 0xea, 0xff, 0xff, 0xf1, - 0xe3, 0xa0, 0x00, 0x00, 0xee, 0x07, 0x0f, 0x15, 0xe1, 0x2f, 0xff, 0x1e, 0xe1, 0xa0, 0x00, 0x00, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0xe3, 0x18, 0x00, 0x10, 0x0a, 0x00, 0x00, 0x12, - 0xe3, 0xc8, 0x80, 0x10, 0xe3, 0xa0, 0x20, 0x10, 0xe5, 0x87, 0x20, 0x00, 0xe1, 0xa0, 0x00, 0x00, - 0xe1, 0xa0, 0x20, 0x0d, 0xe1, 0xa0, 0x00, 0x00, 0xe5, 0x9f, 0xd0, 0x90, 0xe1, 0xa0, 0x00, 0x00, - 0xe9, 0x2d, 0x5f, 0xfe, 0xe1, 0xa0, 0x00, 0x00, 0xeb, 0x00, 0x00, 0x0f, 0xe8, 0xbd, 0x5f, 0xfe, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0xd0, 0x02, 0xe3, 0x10, 0x00, 0x01, 0x0a, 0x00, 0x00, 0x02, - 0xe1, 0xa0, 0x00, 0x00, 0xe3, 0xa0, 0x00, 0x04, 0xeb, 0x00, 0x00, 0x05, 0xe3, 0x18, 0x00, 0x01, - 0x0a, 0x00, 0x00, 0x01, 0xe5, 0x9f, 0xf0, 0x58, 0xe1, 0xa0, 0x00, 0x00, 0xe5, 0x9f, 0xf0, 0x54, - 0xe1, 0xa0, 0x00, 0x00, 0xe5, 0x9f, 0xf0, 0x50, 0xe1, 0xa0, 0x00, 0x00, 0xe5, 0x9f, 0x20, 0x4c, - 0xe1, 0x2f, 0xff, 0x12, 0xe1, 0xa0, 0x00, 0x00, 0xee, 0x13, 0x0f, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0xee, 0x03, 0x0f, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0x45, 0x48, 0x43, 0x5f, 0x43, 0x46, 0x47, 0x00, - 0x12, 0x34, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x13, 0x70, 0x0e, 0x2d, 0x13, 0x72, 0xc0, 0x00, - 0x13, 0x72, 0xf5, 0xa8, 0xff, 0xff, 0x1e, 0x80, 0xff, 0xff, 0x1e, 0x9c, 0xff, 0xff, 0x1d, 0x44, - 0x13, 0x70, 0x0c, 0x59, 0xe1, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x11, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xf5, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x07, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x07, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xff, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0xff, 0xff, 0xb5, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x0d, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0xff, 0xff, 0xd2, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x2d, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x29, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x2f, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xeb, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xd3, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x1f, 0x46, 0xc0, 0x47, 0x78, 0xea, 0xff, 0xff, 0xa1, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xe7, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x15, 0x1f, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xe7, 0x46, 0xc0, 0x47, 0x78, 0xea, 0xff, 0xff, 0xc5, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xef, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xd1, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xed, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xef, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0xff, 0xff, 0xb7, 0x46, 0xc0, 0x47, 0x78, 0xea, 0xff, 0xff, 0x89, - 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xd1, 0x46, 0xc0, 0x47, 0x78, 0xea, 0x00, 0x14, 0xad, - 0xb5, 0x00, 0x28, 0x02, 0xd0, 0x11, 0x28, 0x02, 0xd8, 0x04, 0x28, 0x00, 0xd0, 0x08, 0x28, 0x01, - 0xd1, 0x04, 0xe0, 0x08, 0x28, 0x10, 0xd0, 0x0d, 0x28, 0x11, 0xd0, 0x0d, 0x48, 0x08, 0xe0, 0x0c, - 0x4b, 0x08, 0x68, 0x18, 0xe0, 0x09, 0x48, 0x08, 0xe0, 0x07, 0x4a, 0x08, 0x23, 0x01, 0x60, 0x13, - 0x20, 0x00, 0xe0, 0x02, 0x48, 0x06, 0xe0, 0x00, 0x48, 0x06, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0xff, 0xff, 0xfd, 0x66, 0x13, 0x70, 0x60, 0x28, 0x13, 0x70, 0x4a, 0xd5, 0x13, 0x70, 0x67, 0x40, - 0x13, 0x70, 0x43, 0xb1, 0x13, 0x70, 0x42, 0xe5, 0xb5, 0x30, 0xb0, 0x81, 0x1c, 0x0c, 0xf7, 0xff, - 0xff, 0x8f, 0x1c, 0x05, 0x28, 0x00, 0xd1, 0x27, 0x2c, 0x00, 0xd0, 0x25, 0x68, 0x24, 0x2c, 0x00, - 0xd0, 0x22, 0x78, 0x22, 0x78, 0x63, 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x78, 0xa2, 0x02, 0x12, - 0x43, 0x1a, 0x78, 0xe3, 0x43, 0x13, 0x2b, 0x06, 0xd1, 0x16, 0x7b, 0x23, 0x7b, 0x62, 0x06, 0x1b, - 0x04, 0x12, 0x43, 0x1a, 0x7b, 0xa3, 0x02, 0x1b, 0x43, 0x13, 0x7b, 0xe2, 0x43, 0x1a, 0x2a, 0x7a, - 0xd0, 0x02, 0x2a, 0x88, 0xd1, 0x08, 0xe0, 0x02, 0x48, 0x06, 0x21, 0x15, 0xe0, 0x01, 0x48, 0x05, - 0x21, 0x14, 0x1c, 0x22, 0xf0, 0x04, 0xfc, 0x82, 0xb0, 0x01, 0x1c, 0x28, 0xbc, 0x30, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x02, 0xe1, 0xb5, 0x70, 0x1c, 0x0c, 0x1c, 0x05, 0xf7, 0xff, - 0xff, 0x87, 0x1c, 0x06, 0x20, 0x01, 0x42, 0x40, 0xf7, 0xff, 0xff, 0x6e, 0x0e, 0x2b, 0x73, 0x23, - 0x0c, 0x2b, 0x73, 0x63, 0x0a, 0x2b, 0x73, 0xa3, 0x7c, 0x62, 0x7c, 0x23, 0x04, 0x12, 0x06, 0x1b, - 0x43, 0x1a, 0x7c, 0xa3, 0x73, 0xe5, 0x02, 0x1b, 0x43, 0x13, 0x7c, 0xe2, 0x06, 0x2d, 0x43, 0x1a, - 0x1c, 0x20, 0x60, 0x15, 0x30, 0x0c, 0x21, 0x04, 0xf7, 0xff, 0xff, 0x46, 0x7c, 0x23, 0x7c, 0x62, - 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7c, 0xa3, 0x7c, 0xe0, 0x02, 0x1b, 0x43, 0x13, 0x43, 0x18, - 0x21, 0x04, 0xf7, 0xff, 0xff, 0x39, 0x1c, 0x30, 0xf7, 0xff, 0xff, 0x46, 0x20, 0x00, 0xbc, 0x70, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0xf0, 0xb0, 0x8f, 0x90, 0x08, 0x91, 0x07, 0x1c, 0x08, 0x1c, 0x11, - 0x92, 0x06, 0x92, 0x09, 0xf7, 0xff, 0xff, 0x30, 0x4c, 0x7f, 0x68, 0x23, 0x2b, 0x00, 0xd1, 0x00, - 0xe0, 0xec, 0xa8, 0x0d, 0xf0, 0x01, 0xf9, 0x0e, 0x4b, 0x7c, 0x60, 0x18, 0x28, 0x00, 0xd0, 0x04, - 0x23, 0x80, 0x9a, 0x0d, 0x01, 0x1b, 0x42, 0x9a, 0xd0, 0x04, 0x4a, 0x79, 0x23, 0x01, 0x42, 0x5b, - 0x60, 0x13, 0xe0, 0xdb, 0x4d, 0x77, 0x68, 0x2a, 0x2a, 0x00, 0xdb, 0x63, 0x4b, 0x76, 0x42, 0x9a, - 0xd0, 0x60, 0x4a, 0x73, 0x68, 0x13, 0x1c, 0x58, 0xd1, 0x5c, 0x1c, 0x2e, 0x4a, 0x6e, 0x49, 0x71, - 0x68, 0x13, 0x68, 0x08, 0x33, 0x1f, 0x21, 0x1f, 0x1c, 0x1c, 0x43, 0x8c, 0x1c, 0x07, 0x21, 0x10, - 0x1c, 0x22, 0x37, 0x10, 0xf0, 0x03, 0xff, 0xf8, 0x28, 0x00, 0xd1, 0x00, 0xe0, 0xbe, 0x78, 0x23, - 0x2b, 0x43, 0xd1, 0x0a, 0x78, 0x63, 0x2b, 0x49, 0xd1, 0x07, 0x78, 0xa3, 0x2b, 0x53, 0xd1, 0x04, - 0x78, 0xe3, 0x2b, 0x4f, 0xd1, 0x01, 0x4b, 0x64, 0xe0, 0x07, 0x68, 0x33, 0x2b, 0x00, 0xd0, 0x02, - 0x23, 0x00, 0x60, 0x33, 0xe7, 0xda, 0x23, 0x01, 0x42, 0x5b, 0x60, 0x2b, 0x79, 0x62, 0x79, 0xa3, - 0x02, 0x12, 0x04, 0x1b, 0x18, 0xd2, 0x79, 0x23, 0x4e, 0x5c, 0x18, 0xd2, 0x79, 0xe3, 0x4d, 0x5c, - 0x06, 0x1b, 0x18, 0xd2, 0x0a, 0xd2, 0x60, 0x32, 0x22, 0x80, 0x01, 0x12, 0x1c, 0x28, 0x21, 0x00, - 0xf0, 0x05, 0xfa, 0x68, 0x4b, 0x53, 0x68, 0x1a, 0x4b, 0x53, 0x42, 0x9a, 0xd1, 0x1a, 0x68, 0x36, - 0x20, 0x00, 0x46, 0xb4, 0x4e, 0x53, 0x22, 0x07, 0x40, 0x02, 0xd1, 0x02, 0x10, 0xc3, 0x00, 0x9b, - 0x51, 0x9f, 0x18, 0x23, 0x7a, 0x1b, 0x2b, 0x00, 0xd0, 0x07, 0x21, 0x01, 0x10, 0xc3, 0x40, 0x91, - 0x1c, 0x0a, 0x5c, 0xe9, 0x44, 0x67, 0x43, 0x0a, 0x54, 0xea, 0x23, 0x80, 0x30, 0x01, 0x01, 0xdb, - 0x42, 0x98, 0xd1, 0xe8, 0x4b, 0x40, 0x22, 0x1f, 0x68, 0x1b, 0x33, 0x1f, 0x43, 0x93, 0x93, 0x0b, - 0x9a, 0x07, 0x23, 0x80, 0x02, 0x1b, 0x92, 0x0a, 0x93, 0x05, 0xe0, 0x63, 0x98, 0x08, 0x4a, 0x3c, - 0x0a, 0x43, 0x1c, 0x1d, 0x21, 0x0f, 0x68, 0x13, 0x43, 0x8d, 0x42, 0x9d, 0xd0, 0x3a, 0x4b, 0x39, - 0x60, 0x15, 0x68, 0x1a, 0x4b, 0x38, 0x42, 0x9a, 0xd1, 0x1e, 0x4b, 0x38, 0x1c, 0x28, 0x68, 0x1c, - 0x27, 0x07, 0x1c, 0x21, 0xf0, 0x05, 0xf8, 0xe8, 0x4a, 0x36, 0x08, 0xc6, 0x00, 0xb3, 0x58, 0x99, - 0x4b, 0x33, 0x40, 0x07, 0x20, 0x01, 0x22, 0x00, 0x93, 0x01, 0x46, 0x84, 0xe0, 0x07, 0x98, 0x01, - 0x5d, 0x83, 0x46, 0x60, 0x41, 0x13, 0x42, 0x03, 0xd0, 0x00, 0x19, 0x09, 0x32, 0x01, 0x42, 0xba, - 0xd3, 0xf5, 0x1e, 0x63, 0x40, 0x2b, 0x18, 0xcd, 0x4b, 0x24, 0x68, 0x1b, 0x1b, 0x5c, 0x2c, 0x10, - 0xdc, 0x3a, 0x2c, 0x10, 0xd0, 0x07, 0x22, 0x80, 0x98, 0x0b, 0x21, 0x00, 0x02, 0x12, 0xf0, 0x05, - 0xfa, 0x01, 0x2c, 0x00, 0xdd, 0x06, 0x1c, 0x28, 0x1c, 0x21, 0x9a, 0x0b, 0xf0, 0x03, 0xff, 0x5c, - 0x28, 0x00, 0xd0, 0x23, 0x99, 0x08, 0x4b, 0x20, 0x9a, 0x05, 0x40, 0x0b, 0x00, 0x9b, 0x98, 0x06, - 0x1a, 0xd1, 0x42, 0x81, 0xd8, 0x01, 0x1c, 0x0c, 0xe0, 0x00, 0x9c, 0x06, 0x9a, 0x0b, 0x98, 0x0a, - 0x18, 0xd1, 0x1c, 0x22, 0xf0, 0x05, 0xf9, 0xa2, 0x98, 0x0a, 0x1c, 0x21, 0xf7, 0xff, 0xfe, 0x4c, - 0x9b, 0x0a, 0x98, 0x06, 0x19, 0x1b, 0x99, 0x08, 0x93, 0x0a, 0x10, 0xa3, 0x1b, 0x00, 0x18, 0xc9, - 0x90, 0x06, 0x91, 0x08, 0x9a, 0x06, 0x2a, 0x00, 0xd1, 0x98, 0xe0, 0x07, 0x20, 0x80, 0x02, 0x00, - 0xb0, 0x0f, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x24, 0x10, 0xe7, 0xcc, 0x98, 0x07, 0x99, 0x09, - 0xf7, 0xff, 0xfe, 0x12, 0x20, 0x00, 0xe7, 0xf3, 0x13, 0x70, 0x67, 0xd0, 0x13, 0x70, 0x67, 0x4c, - 0x13, 0x70, 0x60, 0x10, 0x13, 0x70, 0x60, 0x14, 0x7f, 0xff, 0xff, 0xff, 0x13, 0x70, 0x67, 0x50, - 0x13, 0x70, 0x78, 0x00, 0x13, 0x70, 0x80, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xb5, 0xf0, 0x4b, 0xc9, - 0xb0, 0x93, 0x68, 0x18, 0x21, 0x80, 0xf7, 0xff, 0xfe, 0x23, 0x21, 0x20, 0xf7, 0xff, 0xfe, 0x24, - 0x90, 0x0a, 0xf0, 0x00, 0xfc, 0x0d, 0xf7, 0xff, 0xfd, 0xff, 0x21, 0x78, 0xf7, 0xff, 0xfd, 0xd0, - 0x99, 0x0a, 0x48, 0xc1, 0xf7, 0xff, 0xfe, 0x20, 0x48, 0xc0, 0x9a, 0x0a, 0x23, 0x00, 0x1c, 0x01, - 0xf7, 0xff, 0xfd, 0xd2, 0x49, 0xbe, 0x90, 0x08, 0x20, 0xcd, 0xf0, 0x04, 0xfb, 0x71, 0x22, 0x00, - 0x92, 0x09, 0x92, 0x0b, 0x92, 0x0c, 0x92, 0x0d, 0x4b, 0xba, 0x4a, 0xbb, 0x26, 0x01, 0x93, 0x05, - 0x92, 0x04, 0xe0, 0x00, 0x26, 0x00, 0x98, 0x0a, 0xa9, 0x11, 0x22, 0x00, 0xf7, 0xff, 0xfd, 0xd8, - 0x90, 0x10, 0x9b, 0x10, 0x2b, 0x00, 0xd1, 0xf6, 0x2e, 0x00, 0xd0, 0x02, 0x98, 0x08, 0xf7, 0xff, - 0xfd, 0xab, 0x9a, 0x05, 0x9c, 0x11, 0x23, 0x00, 0x60, 0x13, 0x2c, 0x00, 0xd1, 0x54, 0x4b, 0xaf, - 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x05, 0x4b, 0xae, 0x68, 0x1a, 0x2a, 0x00, 0xd1, 0x01, 0x4b, 0xaa, - 0x60, 0x1a, 0x9b, 0x09, 0x2b, 0x00, 0xd0, 0xdd, 0x4b, 0xa7, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0xd9, - 0x4b, 0xa7, 0x68, 0x1b, 0x2b, 0x00, 0xd1, 0xd5, 0x4b, 0xa6, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x09, - 0xf0, 0x03, 0xfd, 0x96, 0x28, 0x00, 0xd0, 0x05, 0xf0, 0x03, 0xfd, 0x92, 0x28, 0x00, 0xd0, 0x01, - 0xf0, 0x03, 0xfd, 0x8e, 0x4b, 0x9f, 0x68, 0x1e, 0x2e, 0x00, 0xd1, 0x23, 0x4f, 0x9e, 0x4a, 0x9f, - 0x68, 0x3b, 0x3b, 0x01, 0x42, 0x93, 0xd8, 0x1d, 0x4c, 0x96, 0x4d, 0x9d, 0x23, 0x01, 0x60, 0x23, - 0x68, 0x28, 0x4a, 0x9c, 0x21, 0x01, 0xf0, 0x03, 0xfe, 0x9f, 0x60, 0x26, 0x28, 0x00, 0xd0, 0x09, - 0x23, 0x80, 0x68, 0x3a, 0x00, 0x9b, 0x42, 0x9a, 0xd1, 0x04, 0x68, 0x2b, 0x22, 0x80, 0x02, 0x12, - 0x18, 0x9b, 0x60, 0x2b, 0x49, 0x92, 0x4b, 0x94, 0x68, 0x0a, 0x68, 0x1b, 0x42, 0x9a, 0xd3, 0x01, - 0x23, 0x00, 0x60, 0x0b, 0x4b, 0x8a, 0x68, 0x1b, 0x2b, 0x00, 0xd1, 0x9b, 0x98, 0x08, 0x49, 0x83, - 0xf7, 0xff, 0xfd, 0x8e, 0x26, 0x01, 0xe7, 0x96, 0x78, 0x23, 0x78, 0x62, 0x06, 0x1b, 0x04, 0x12, - 0x43, 0x1a, 0x78, 0xa3, 0x02, 0x1b, 0x43, 0x13, 0x78, 0xe2, 0x1c, 0x16, 0x43, 0x1e, 0x2e, 0x02, - 0xd0, 0x59, 0x2e, 0x02, 0xd8, 0x02, 0x2e, 0x01, 0xd1, 0x04, 0xe0, 0x07, 0x2e, 0x06, 0xd0, 0x03, - 0x2e, 0x07, 0xd0, 0x67, 0x25, 0x01, 0xe0, 0x30, 0x25, 0x01, 0xe2, 0x4f, 0x7b, 0x23, 0x7b, 0x62, - 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7b, 0xa3, 0x49, 0x6f, 0x02, 0x1b, 0x43, 0x13, 0x7b, 0xe2, - 0x1c, 0x15, 0x43, 0x1d, 0x1c, 0x28, 0xf0, 0x05, 0xf9, 0x4d, 0x28, 0x00, 0xd1, 0x16, 0x7d, 0x23, - 0x7d, 0x62, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7d, 0xa3, 0x02, 0x1b, 0x43, 0x13, 0x7d, 0xe2, - 0x1c, 0x15, 0x43, 0x1d, 0x9b, 0x0c, 0x2b, 0x00, 0xd0, 0x00, 0xe2, 0x2d, 0x4b, 0x68, 0x68, 0x1b, - 0x2b, 0x00, 0xd0, 0x00, 0xe2, 0x28, 0xf0, 0x04, 0xf8, 0x2b, 0xe2, 0x25, 0x49, 0x6b, 0x1c, 0x28, - 0xf0, 0x05, 0xf9, 0x30, 0x28, 0x00, 0xd0, 0x02, 0x25, 0x06, 0x42, 0x6d, 0xe2, 0x1e, 0x7d, 0x23, - 0x7d, 0x62, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7d, 0xa3, 0x02, 0x1b, 0x43, 0x13, 0x7d, 0xe2, - 0x1c, 0x15, 0x43, 0x1d, 0x4b, 0x5a, 0x60, 0x1e, 0x4b, 0x57, 0x60, 0x18, 0x48, 0x60, 0xf0, 0x00, - 0xfa, 0x6d, 0x4b, 0x60, 0x68, 0x1b, 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0xf0, 0x00, 0xfd, 0xe2, - 0x23, 0x00, 0x93, 0x09, 0xe2, 0x02, 0x7a, 0x23, 0x7a, 0x62, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, - 0x7a, 0xa3, 0x02, 0x1b, 0x43, 0x13, 0x7a, 0xe2, 0x1c, 0x10, 0x9a, 0x0b, 0x43, 0x18, 0x42, 0x82, - 0xd1, 0x02, 0x23, 0x00, 0x93, 0x0b, 0xe0, 0x03, 0xf0, 0x00, 0xfd, 0xee, 0xf0, 0x00, 0xfd, 0xe2, - 0x25, 0x00, 0xe1, 0xeb, 0x7e, 0x23, 0x7e, 0x62, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7e, 0xa3, - 0x02, 0x1b, 0x43, 0x13, 0x7e, 0xe2, 0x1c, 0x16, 0x43, 0x1e, 0x7c, 0x62, 0x7c, 0x23, 0x04, 0x12, - 0x06, 0x1b, 0x43, 0x1a, 0x7c, 0xa3, 0x02, 0x1b, 0x43, 0x13, 0x7c, 0xe2, 0x43, 0x1a, 0x92, 0x06, - 0x7d, 0x23, 0x7d, 0x62, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7d, 0xa3, 0x02, 0x1b, 0x43, 0x13, - 0x7d, 0xe2, 0x1c, 0x15, 0x43, 0x1d, 0x7b, 0x23, 0x2b, 0x00, 0xd1, 0x02, 0x9a, 0x0b, 0x2a, 0x00, - 0xd0, 0x01, 0x27, 0x00, 0xe0, 0x0c, 0x7a, 0x23, 0x7a, 0x62, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, - 0x7a, 0xa3, 0x7a, 0xe0, 0x02, 0x1b, 0x43, 0x13, 0x43, 0x18, 0xf0, 0x00, 0xfd, 0xb5, 0x1c, 0x07, - 0x9b, 0x06, 0x1c, 0x30, 0x18, 0xed, 0x00, 0xe9, 0x95, 0x07, 0x1c, 0x34, 0xf7, 0xff, 0xfc, 0xac, - 0x25, 0x00, 0xe0, 0x05, 0x68, 0x20, 0x68, 0x61, 0xf7, 0xff, 0xfc, 0xa6, 0x35, 0x01, 0x34, 0x08, - 0x9a, 0x07, 0x42, 0x95, 0xdb, 0xf6, 0x4c, 0x22, 0x68, 0x20, 0x28, 0x00, 0xd0, 0x00, 0xe1, 0x87, - 0x99, 0x11, 0x7b, 0x0b, 0x7b, 0x4a, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7b, 0x8b, 0x02, 0x1b, - 0x43, 0x13, 0x7b, 0xca, 0x43, 0x1a, 0x4b, 0x24, 0x42, 0x9a, 0xd1, 0x00, 0xe0, 0xf6, 0x42, 0x9a, - 0xd8, 0x46, 0x2a, 0x06, 0xd8, 0x0b, 0x2a, 0x05, 0xd3, 0x00, 0xe0, 0xd0, 0x2a, 0x01, 0xd1, 0x00, - 0xe0, 0x92, 0x2a, 0x00, 0xd0, 0x6c, 0x2a, 0x02, 0xd0, 0x00, 0xe1, 0x01, 0xe0, 0xc7, 0x2a, 0x1b, - 0xd8, 0x06, 0x2a, 0x1a, 0xd3, 0x00, 0xe0, 0x9f, 0x2a, 0x0c, 0xd0, 0x00, 0xe0, 0xf8, 0xe0, 0x8f, - 0x4b, 0x16, 0x42, 0x9a, 0xd1, 0x00, 0xe0, 0x9a, 0x33, 0x01, 0x42, 0x9a, 0xd0, 0x00, 0xe0, 0xef, - 0xe0, 0xc7, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x28, 0x13, 0x70, 0x60, 0x50, 0x00, 0x98, 0x96, 0x80, - 0x13, 0x70, 0x02, 0x19, 0x13, 0x70, 0x67, 0xc0, 0x13, 0x70, 0x60, 0x0c, 0x13, 0x70, 0x67, 0x48, - 0x13, 0x70, 0x67, 0x40, 0x13, 0x70, 0x67, 0x6c, 0x13, 0x72, 0xc3, 0xa0, 0x00, 0x00, 0x0f, 0xfe, - 0x13, 0x70, 0x67, 0x54, 0x13, 0x70, 0x68, 0x00, 0x13, 0x72, 0xc3, 0xa4, 0x13, 0x70, 0x60, 0x5c, - 0x13, 0x70, 0x12, 0x99, 0x13, 0x70, 0x60, 0x34, 0x55, 0x4d, 0x53, 0x03, 0x55, 0x4d, 0x53, 0x01, - 0x4b, 0xac, 0x42, 0x9a, 0xd1, 0x00, 0xe0, 0x86, 0x42, 0x9a, 0xd8, 0x12, 0x3b, 0x7b, 0x42, 0x9a, - 0xd1, 0x00, 0xe0, 0xb4, 0x42, 0x9a, 0xd8, 0x04, 0x3b, 0x02, 0x42, 0x9a, 0xd0, 0x00, 0xe0, 0xb7, - 0xe0, 0xa5, 0x4b, 0xa5, 0x42, 0x9a, 0xd0, 0x72, 0x33, 0x70, 0x42, 0x9a, 0xd0, 0x00, 0xe0, 0xaf, - 0xe0, 0xaa, 0x4b, 0xa2, 0x42, 0x9a, 0xd1, 0x00, 0xe1, 0x06, 0x42, 0x9a, 0xd8, 0x07, 0x4b, 0xa0, - 0x42, 0x9a, 0xd0, 0x6e, 0x4b, 0x9f, 0x42, 0x9a, 0xd0, 0x00, 0xe0, 0xa1, 0xe0, 0xa2, 0x4b, 0x9e, - 0x42, 0x9a, 0xd1, 0x00, 0xe0, 0xed, 0x33, 0x01, 0x42, 0x9a, 0xd0, 0x00, 0xe0, 0x98, 0xe0, 0xde, - 0x2f, 0x00, 0xd1, 0x00, 0xe0, 0xfe, 0x69, 0x33, 0x88, 0x18, 0x69, 0xb3, 0x88, 0x1c, 0x6a, 0x33, - 0x88, 0x1d, 0x68, 0x33, 0x78, 0x19, 0x68, 0xb3, 0x78, 0x1a, 0x02, 0x03, 0x0a, 0x00, 0x43, 0x03, - 0x02, 0x20, 0x0a, 0x24, 0x43, 0x20, 0x04, 0x00, 0x0c, 0x00, 0x90, 0x00, 0x02, 0x28, 0x0a, 0x2d, - 0x43, 0x28, 0x04, 0x00, 0x0c, 0x00, 0x90, 0x01, 0x6b, 0x30, 0x04, 0x1b, 0x90, 0x02, 0x0c, 0x1b, - 0x1c, 0x38, 0xf0, 0x01, 0xfe, 0x95, 0xe0, 0x60, 0x2f, 0x00, 0xd1, 0x00, 0xe0, 0xda, 0x68, 0x33, - 0x1c, 0x38, 0x78, 0x19, 0x68, 0xb3, 0x88, 0x1a, 0x69, 0x33, 0xf0, 0x01, 0xfd, 0x87, 0xe0, 0x54, - 0x2f, 0x00, 0xd0, 0x00, 0xe0, 0xce, 0x68, 0x33, 0x69, 0x32, 0x78, 0x18, 0x68, 0xb3, 0x78, 0x19, - 0x69, 0xb3, 0xf0, 0x00, 0xfc, 0xed, 0xe0, 0x48, 0x25, 0x01, 0x24, 0x00, 0xe0, 0xc5, 0xf0, 0x03, - 0xfd, 0xef, 0x1c, 0x05, 0x28, 0x00, 0xda, 0x01, 0x23, 0x00, 0xe0, 0x02, 0x4a, 0x77, 0x23, 0x01, - 0x60, 0x13, 0x99, 0x11, 0x93, 0x09, 0x7a, 0x0b, 0x7a, 0x4a, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, - 0x7a, 0x8b, 0x02, 0x1b, 0x43, 0x13, 0x7a, 0xca, 0x43, 0x1a, 0x92, 0x0b, 0xe0, 0xac, 0x4b, 0x6f, - 0x22, 0x00, 0x60, 0x18, 0xe0, 0x6a, 0x68, 0x32, 0x4b, 0x6d, 0x68, 0x12, 0x60, 0x1a, 0x25, 0x00, - 0xe0, 0xa2, 0x23, 0x01, 0x60, 0x23, 0x4b, 0x69, 0x60, 0x18, 0x48, 0x6a, 0xf0, 0x00, 0xf9, 0x0e, - 0x4b, 0x69, 0x68, 0x1b, 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0xf0, 0x00, 0xfc, 0x83, 0x23, 0x00, - 0x93, 0x09, 0x4c, 0x66, 0x1c, 0x20, 0xf0, 0x00, 0xfd, 0xa5, 0x4b, 0x65, 0x1c, 0x05, 0x60, 0x18, - 0x68, 0x32, 0x2a, 0x00, 0xd1, 0x00, 0xe0, 0x87, 0x68, 0x23, 0xe0, 0x68, 0x68, 0x33, 0x69, 0x32, - 0x68, 0x18, 0x68, 0xb3, 0x68, 0x19, 0xf0, 0x03, 0xfc, 0xa7, 0x1c, 0x05, 0xe0, 0x7c, 0x68, 0x33, - 0x69, 0x32, 0x68, 0x18, 0x68, 0xb3, 0x68, 0x19, 0xf0, 0x03, 0xfc, 0x38, 0xe7, 0xf5, 0x4b, 0x59, - 0x68, 0x1a, 0x42, 0x51, 0x41, 0x4a, 0xe7, 0xc9, 0x68, 0x32, 0x4b, 0x50, 0x68, 0x12, 0x60, 0x1a, - 0x25, 0x01, 0xe0, 0x69, 0x7a, 0x0b, 0x7a, 0x4a, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7a, 0x8b, - 0x02, 0x1b, 0x43, 0x13, 0x7a, 0xca, 0x21, 0x00, 0x43, 0x1a, 0x92, 0x0b, 0x91, 0x0f, 0x68, 0x34, - 0x78, 0x23, 0x2b, 0x5f, 0xd1, 0x1c, 0x78, 0x63, 0x2b, 0x44, 0xd1, 0x19, 0x78, 0xa3, 0x2b, 0x56, - 0xd1, 0x16, 0x78, 0xe3, 0x2b, 0x44, 0xd1, 0x13, 0x4b, 0x40, 0x4c, 0x47, 0x22, 0x01, 0x60, 0x1a, - 0x60, 0x21, 0x68, 0xf3, 0x2b, 0x04, 0xd1, 0x06, 0x68, 0xb1, 0xa8, 0x0f, 0x22, 0x04, 0xf0, 0x04, - 0xfe, 0xc5, 0x9b, 0x0f, 0x60, 0x23, 0xf0, 0x04, 0xf8, 0x1f, 0x22, 0x01, 0x92, 0x09, 0xe7, 0x96, - 0x68, 0xf3, 0x2b, 0x04, 0xd1, 0x04, 0x68, 0xb1, 0xa8, 0x0f, 0x22, 0x04, 0xf0, 0x04, 0xfe, 0xb6, - 0x99, 0x0f, 0x1c, 0x20, 0xf0, 0x03, 0xff, 0x8c, 0x90, 0x0d, 0x28, 0x00, 0xd1, 0x02, 0x23, 0x01, - 0x93, 0x09, 0xe0, 0x25, 0x4a, 0x2d, 0x23, 0x01, 0x60, 0x13, 0x93, 0x09, 0xe7, 0x7f, 0xf0, 0x03, - 0xfd, 0x01, 0x1c, 0x05, 0x28, 0x00, 0xd1, 0x1f, 0x23, 0x01, 0x4a, 0x30, 0x42, 0x5b, 0x60, 0x13, - 0xe0, 0x1a, 0x4a, 0x26, 0x23, 0x01, 0x60, 0x13, 0x68, 0x33, 0x69, 0x31, 0x68, 0x18, 0x68, 0xb3, - 0x68, 0x1a, 0xf7, 0xff, 0xfc, 0x07, 0xe7, 0x90, 0x9a, 0x0d, 0x2a, 0x00, 0xd0, 0x08, 0x68, 0x33, - 0x69, 0x32, 0x68, 0x19, 0x68, 0xb3, 0x98, 0x0d, 0x68, 0x1b, 0xf0, 0x04, 0xf8, 0xb5, 0xe7, 0x5e, - 0x25, 0x01, 0xe0, 0x00, 0x25, 0x06, 0x42, 0x6d, 0x24, 0x01, 0x9a, 0x06, 0x00, 0xd3, 0x18, 0xf6, - 0x1c, 0x17, 0xe0, 0x05, 0x68, 0x30, 0x68, 0x71, 0xf7, 0xff, 0xfb, 0x26, 0x37, 0x01, 0x36, 0x08, - 0x9b, 0x07, 0x42, 0x9f, 0xdb, 0xf6, 0xe0, 0x02, 0x22, 0x01, 0x92, 0x0c, 0x24, 0x01, 0x9a, 0x04, - 0x68, 0x13, 0x2b, 0x00, 0xd1, 0x01, 0x26, 0x00, 0xe0, 0x04, 0x98, 0x08, 0x49, 0x14, 0xf7, 0xff, - 0xfb, 0x17, 0x26, 0x01, 0x2c, 0x00, 0xd1, 0x00, 0xe5, 0x1d, 0x98, 0x11, 0x1c, 0x29, 0xf7, 0xff, - 0xfa, 0xff, 0xe5, 0x18, 0x55, 0x4d, 0x53, 0x81, 0x55, 0x4d, 0x53, 0x10, 0x57, 0x46, 0x53, 0x02, - 0x55, 0x4d, 0x53, 0x82, 0x57, 0x46, 0x53, 0x01, 0x57, 0x46, 0x53, 0x03, 0x13, 0x70, 0x60, 0x0c, - 0x13, 0x70, 0x67, 0x48, 0x13, 0x70, 0x12, 0x99, 0x13, 0x70, 0x60, 0x34, 0x13, 0x72, 0xc3, 0xa0, - 0x13, 0x72, 0xc3, 0xa4, 0x13, 0x70, 0x67, 0x44, 0x13, 0x70, 0x60, 0x14, 0x13, 0x70, 0x60, 0x10, - 0x00, 0x98, 0x96, 0x80, 0xb5, 0x00, 0x4b, 0x04, 0xb0, 0x81, 0x1c, 0x01, 0x68, 0x18, 0xf7, 0xff, - 0xfa, 0xbb, 0xb0, 0x01, 0xbc, 0x01, 0x47, 0x00, 0x13, 0x70, 0x60, 0x28, 0xb5, 0x00, 0x4b, 0x0d, - 0x1c, 0x01, 0xb0, 0x81, 0x68, 0x18, 0x22, 0x20, 0xf7, 0xff, 0xfa, 0xea, 0x28, 0x00, 0xd1, 0x0d, - 0x48, 0x09, 0xf7, 0xff, 0xfa, 0xb9, 0xf0, 0x03, 0xff, 0xcd, 0x20, 0xc8, 0xf0, 0x00, 0xfa, 0x7c, - 0xf0, 0x03, 0xff, 0xbc, 0x20, 0xc8, 0xf0, 0x00, 0xfa, 0x77, 0xe7, 0xf4, 0xb0, 0x01, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x28, 0x13, 0x70, 0x60, 0x6c, 0x4b, 0x02, 0x4a, 0x03, - 0x60, 0x18, 0x23, 0x00, 0x60, 0x13, 0x47, 0x70, 0x13, 0x70, 0x67, 0x60, 0x13, 0x70, 0x67, 0x58, - 0xb5, 0xf0, 0x4f, 0x1d, 0x21, 0x10, 0x68, 0x3b, 0x4d, 0x1c, 0x43, 0x8b, 0x60, 0x3b, 0x68, 0x2b, - 0x4e, 0x1b, 0x68, 0x9a, 0x68, 0x33, 0xb0, 0x81, 0x68, 0x54, 0x2b, 0x00, 0xd0, 0x11, 0x1c, 0x20, - 0xf0, 0x00, 0xf8, 0x36, 0x28, 0x00, 0xdc, 0x13, 0x23, 0x00, 0x60, 0x33, 0x4b, 0x15, 0x60, 0x18, - 0x20, 0x04, 0xf7, 0xff, 0xfa, 0x75, 0x68, 0x2b, 0x68, 0x9a, 0x23, 0x37, 0x40, 0x23, 0x60, 0x53, - 0xe0, 0x14, 0x4b, 0x11, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x04, 0x1c, 0x20, 0xf0, 0x00, 0xf8, 0x20, - 0x68, 0x2b, 0x68, 0x9a, 0x23, 0x37, 0x40, 0x23, 0x60, 0x53, 0x68, 0x3b, 0x22, 0x10, 0x43, 0x13, - 0x4a, 0x0a, 0x60, 0x3b, 0x68, 0x13, 0x21, 0x10, 0x43, 0x0b, 0x60, 0x13, 0xb0, 0x01, 0x20, 0x00, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x0d, 0x80, 0x00, 0x3c, 0x13, 0x70, 0x60, 0x34, - 0x13, 0x70, 0x67, 0x58, 0x13, 0x70, 0x67, 0x5c, 0x13, 0x70, 0x67, 0x60, 0x0d, 0x80, 0x00, 0x38, - 0x47, 0x18, 0x46, 0xc0, 0xb5, 0x70, 0x4d, 0x15, 0x4b, 0x15, 0x26, 0x02, 0x42, 0x76, 0x1c, 0x29, - 0x68, 0x18, 0x22, 0x00, 0x60, 0x2e, 0xf7, 0xff, 0xfa, 0x4b, 0x4b, 0x12, 0x22, 0x00, 0x68, 0x1b, - 0x4c, 0x11, 0x68, 0x9b, 0x60, 0x9a, 0x4b, 0x11, 0x68, 0x20, 0x60, 0x1a, 0xf7, 0xff, 0xfa, 0x1c, - 0x68, 0x20, 0xf7, 0xff, 0xfa, 0x1d, 0x23, 0x01, 0x42, 0x5b, 0x60, 0x23, 0x68, 0x2b, 0x2b, 0x00, - 0xd1, 0x03, 0x4b, 0x0b, 0x68, 0x1b, 0x60, 0x2b, 0xe0, 0x00, 0x60, 0x2e, 0x20, 0x04, 0xf7, 0xff, - 0xfa, 0x27, 0x4b, 0x02, 0x68, 0x18, 0xbc, 0x70, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x67, 0x64, - 0x13, 0x70, 0x60, 0x18, 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x60, 0x1c, 0x13, 0x70, 0x67, 0x58, - 0x13, 0x70, 0x67, 0x5c, 0xb5, 0x10, 0x4b, 0x0f, 0x1c, 0x04, 0x68, 0x1a, 0x1c, 0x08, 0x23, 0x01, - 0x49, 0x0d, 0xf7, 0xff, 0xf9, 0xf9, 0x4b, 0x0d, 0x21, 0x10, 0x60, 0x18, 0x48, 0x0c, 0xf0, 0x03, - 0xff, 0x47, 0x21, 0x10, 0x48, 0x0b, 0xf0, 0x03, 0xff, 0x37, 0x4b, 0x0b, 0x20, 0x04, 0x60, 0x1c, - 0x4b, 0x0a, 0x68, 0x1b, 0x68, 0x9a, 0x23, 0x37, 0x60, 0x93, 0xf7, 0xff, 0xf9, 0xf9, 0xbc, 0x10, - 0xbc, 0x01, 0x47, 0x00, 0x13, 0x70, 0x60, 0x18, 0x05, 0xf5, 0xe1, 0x00, 0x13, 0x70, 0x60, 0x1c, - 0x0d, 0x80, 0x00, 0x38, 0x0d, 0x80, 0x00, 0x3c, 0x13, 0x70, 0x67, 0x58, 0x13, 0x70, 0x60, 0x34, - 0xb5, 0x30, 0x4d, 0x11, 0x4a, 0x11, 0x68, 0x2b, 0xb0, 0x81, 0x40, 0x13, 0x60, 0x2b, 0x20, 0x80, - 0xf0, 0x03, 0xfd, 0xc0, 0x21, 0x20, 0xf7, 0xff, 0xfa, 0x07, 0x4c, 0x0d, 0x60, 0x20, 0x20, 0x04, - 0xf7, 0xff, 0xf9, 0xee, 0x68, 0x21, 0x22, 0x00, 0x20, 0x04, 0xf7, 0xff, 0xfa, 0x11, 0x68, 0x2a, - 0x23, 0x80, 0x02, 0x1b, 0x43, 0x1a, 0x60, 0x2a, 0x20, 0x04, 0xf7, 0xff, 0xf9, 0xc9, 0xb0, 0x01, - 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x0d, 0x04, 0x00, 0xcc, 0xff, 0xff, 0x7f, 0xff, - 0x13, 0x70, 0x60, 0x18, 0xb5, 0x00, 0x4b, 0x06, 0x02, 0xc0, 0x68, 0x1a, 0x1c, 0x19, 0x68, 0x0b, - 0x1a, 0x9b, 0xd5, 0x00, 0x68, 0x0a, 0x42, 0x83, 0xd9, 0xf9, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, - 0x0d, 0x80, 0x00, 0x10, 0xb5, 0x00, 0x4b, 0x19, 0x4a, 0x19, 0x78, 0x1b, 0xb0, 0x81, 0x1e, 0x59, - 0x41, 0x8b, 0x60, 0x13, 0xf0, 0x03, 0xff, 0x1c, 0x1c, 0x03, 0x48, 0x16, 0x21, 0x04, 0x60, 0x03, - 0xf7, 0xff, 0xf9, 0xba, 0xf0, 0x03, 0xff, 0x08, 0x22, 0x00, 0x1c, 0x01, 0x48, 0x12, 0xf0, 0x03, - 0xfe, 0xbd, 0x21, 0xa0, 0x02, 0x49, 0x48, 0x11, 0xf7, 0xff, 0xf9, 0x6e, 0x4b, 0x10, 0x21, 0x80, - 0x60, 0x18, 0xf7, 0xff, 0xf9, 0xb5, 0x21, 0x20, 0xf7, 0xff, 0xf9, 0xb6, 0x4b, 0x0d, 0x60, 0x18, - 0xf0, 0x00, 0xfd, 0x7c, 0x28, 0x00, 0xda, 0x02, 0x20, 0x01, 0x42, 0x40, 0xe0, 0x02, 0xf7, 0xff, - 0xfb, 0x7d, 0x20, 0x00, 0xb0, 0x01, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x01, 0x0c, - 0x13, 0x70, 0x67, 0x78, 0x13, 0x72, 0xc0, 0x00, 0x13, 0x70, 0x0f, 0x21, 0x13, 0x71, 0x80, 0x00, - 0x13, 0x70, 0x60, 0x28, 0x13, 0x70, 0x60, 0x20, 0xb5, 0x70, 0x1c, 0x0c, 0x1c, 0x05, 0xf7, 0xff, - 0xf9, 0x9f, 0x1c, 0x06, 0x20, 0x01, 0x42, 0x40, 0xf7, 0xff, 0xf9, 0x86, 0x68, 0x22, 0x4b, 0x11, - 0x42, 0x9a, 0xd1, 0x18, 0x4b, 0x10, 0x49, 0x11, 0x22, 0x01, 0x43, 0x13, 0x60, 0x4b, 0x22, 0x08, - 0x1c, 0x20, 0xf0, 0x04, 0xfc, 0xc3, 0x1c, 0x20, 0x21, 0x08, 0xf7, 0xff, 0xf9, 0x65, 0x1b, 0x63, - 0x4a, 0x0b, 0x08, 0x9b, 0x3b, 0x02, 0x40, 0x13, 0x4a, 0x0a, 0x1c, 0x28, 0x43, 0x13, 0x60, 0x2b, - 0x21, 0x04, 0xf7, 0xff, 0xf9, 0x59, 0x1c, 0x30, 0xf7, 0xff, 0xf9, 0x66, 0xbc, 0x70, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xe6, 0x00, 0x01, 0x70, 0x13, 0x70, 0x02, 0x71, 0x13, 0x70, 0x60, 0x2c, - 0x00, 0xff, 0xff, 0xff, 0xea, 0x00, 0x00, 0x00, 0xb5, 0x30, 0x1c, 0x04, 0xb0, 0x81, 0xf7, 0xff, - 0xf9, 0x1f, 0x2c, 0x26, 0xd0, 0x42, 0x2c, 0x26, 0xd8, 0x05, 0x2c, 0x24, 0xd0, 0x09, 0x2c, 0x25, - 0xd0, 0x00, 0xe0, 0x97, 0xe0, 0x0e, 0x2c, 0x39, 0xd0, 0x64, 0x2c, 0x3c, 0xd0, 0x00, 0xe0, 0x91, - 0xe0, 0x62, 0x49, 0x4b, 0x4b, 0x4b, 0x48, 0x4c, 0x60, 0x4b, 0x22, 0x08, 0xf0, 0x04, 0xfc, 0x86, - 0x48, 0x49, 0xe0, 0x84, 0x49, 0x49, 0x48, 0x4a, 0xf7, 0xff, 0xff, 0xa6, 0x4c, 0x44, 0x48, 0x49, - 0x4b, 0x49, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, - 0xf9, 0x1b, 0x48, 0x46, 0x4b, 0x46, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, 0xca, 0x22, 0xc3, 0x22, - 0x21, 0x08, 0xf7, 0xff, 0xf9, 0x11, 0x48, 0x43, 0x4b, 0x43, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, - 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, 0xf9, 0x07, 0x4b, 0x36, 0x48, 0x3f, 0x60, 0x63, - 0x1c, 0x21, 0x22, 0x08, 0xf0, 0x04, 0xfc, 0x5a, 0x48, 0x3c, 0xe0, 0x58, 0x49, 0x3c, 0x48, 0x3d, - 0xf7, 0xff, 0xff, 0x7a, 0x4c, 0x2e, 0x48, 0x33, 0x4b, 0x3b, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, - 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, 0xf8, 0xef, 0x48, 0x30, 0x4b, 0x37, 0x1c, 0x22, - 0x60, 0x63, 0x1c, 0x03, 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, 0xf8, 0xe5, 0x48, 0x2d, - 0x4b, 0x33, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, - 0xf8, 0xdb, 0x4b, 0x20, 0x48, 0x2f, 0x60, 0x63, 0x1c, 0x21, 0x22, 0x08, 0xf0, 0x04, 0xfc, 0x2e, - 0x48, 0x2c, 0xe0, 0x2c, 0x48, 0x2c, 0xe0, 0x00, 0x48, 0x2c, 0x49, 0x2d, 0xf7, 0xff, 0xff, 0x4c, - 0x4c, 0x17, 0x48, 0x1c, 0x4b, 0x2b, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, 0xca, 0x22, 0xc3, 0x22, - 0x21, 0x08, 0xf7, 0xff, 0xf8, 0xc1, 0x48, 0x19, 0x4b, 0x27, 0x1c, 0x22, 0x60, 0x63, 0x1c, 0x03, - 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, 0xf8, 0xb7, 0x48, 0x16, 0x4b, 0x23, 0x1c, 0x22, - 0x60, 0x63, 0x1c, 0x03, 0xca, 0x22, 0xc3, 0x22, 0x21, 0x08, 0xf7, 0xff, 0xf8, 0xad, 0x4b, 0x09, - 0x48, 0x1f, 0x60, 0x63, 0x1c, 0x21, 0x22, 0x08, 0xf0, 0x04, 0xfc, 0x00, 0x48, 0x1c, 0x21, 0x08, - 0xf7, 0xff, 0xf8, 0xa2, 0xb0, 0x01, 0x20, 0x00, 0xbc, 0x30, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x70, 0x60, 0x2c, 0x13, 0x70, 0x00, 0x60, 0xff, 0xff, 0x1e, 0x78, 0x20, 0x20, 0x40, 0x8c, - 0x20, 0x20, 0x5d, 0xe8, 0x13, 0x70, 0x00, 0xbc, 0xff, 0xff, 0x1f, 0x70, 0x13, 0x70, 0x00, 0xc4, - 0xff, 0xff, 0x1f, 0x8c, 0x13, 0x70, 0x00, 0xcc, 0xff, 0xff, 0x1e, 0x34, 0xff, 0xff, 0x1f, 0x68, - 0x20, 0x20, 0x3e, 0x6c, 0x20, 0x20, 0x5b, 0x14, 0xff, 0xff, 0x1e, 0xb0, 0xff, 0xff, 0x1e, 0xcc, - 0xff, 0xff, 0x1d, 0x74, 0xff, 0xff, 0x1e, 0xa8, 0x20, 0x20, 0x5e, 0x84, 0x20, 0x20, 0x5d, 0x94, - 0x20, 0x20, 0x3f, 0x60, 0xff, 0xff, 0x21, 0x30, 0xff, 0xff, 0x21, 0x4c, 0xff, 0xff, 0x1f, 0xf4, - 0xff, 0xff, 0x21, 0x28, 0xb5, 0x30, 0x4d, 0x0c, 0xb0, 0x81, 0x23, 0x00, 0x68, 0x2a, 0x49, 0x0b, - 0xf7, 0xff, 0xf8, 0x3a, 0x4c, 0x0a, 0x49, 0x0b, 0x22, 0x00, 0x60, 0x20, 0x68, 0x28, 0xf7, 0xff, - 0xf8, 0x4f, 0x68, 0x20, 0xf7, 0xff, 0xf8, 0x28, 0x68, 0x20, 0xf7, 0xff, 0xf8, 0x29, 0xb0, 0x01, - 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x20, 0x00, 0x98, 0x96, 0x80, - 0x13, 0x70, 0x60, 0x24, 0x13, 0x70, 0x67, 0x68, 0xb5, 0x00, 0x1c, 0x03, 0x01, 0x40, 0x1a, 0xc0, - 0x00, 0x80, 0x18, 0xc0, 0xb0, 0x81, 0x00, 0xc0, 0xf7, 0xff, 0xff, 0xd4, 0xb0, 0x01, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xb5, 0xf0, 0xb0, 0x83, 0x93, 0x00, 0x46, 0x94, 0x06, 0x0b, 0x0e, 0x0a, - 0x26, 0xff, 0x43, 0x1a, 0x02, 0x36, 0x1c, 0x0b, 0x40, 0x33, 0x02, 0x1b, 0x25, 0xff, 0x43, 0x1a, - 0x04, 0x2d, 0x1c, 0x0b, 0x40, 0x2b, 0x0a, 0x1b, 0x43, 0x1a, 0x90, 0x01, 0x60, 0xc2, 0x9a, 0x01, - 0x23, 0x00, 0x62, 0x13, 0x4b, 0x2a, 0x1c, 0x0a, 0x40, 0x1a, 0x23, 0x80, 0x01, 0x5b, 0x1a, 0x98, - 0x45, 0x84, 0xd2, 0x01, 0x46, 0x64, 0xe0, 0x2f, 0x23, 0x80, 0x01, 0x5b, 0x18, 0xca, 0x4b, 0x25, - 0x1c, 0x11, 0x1c, 0x04, 0x1c, 0x2e, 0x40, 0x19, 0x98, 0x01, 0x27, 0x01, 0x25, 0x00, 0xe0, 0x18, - 0x06, 0x0b, 0x0e, 0x0a, 0x43, 0x1a, 0x23, 0xff, 0x02, 0x1b, 0x40, 0x0b, 0x02, 0x1b, 0x43, 0x1a, - 0x1c, 0x0b, 0x40, 0x33, 0x0a, 0x1b, 0x43, 0x1a, 0x61, 0x02, 0x22, 0x80, 0x01, 0x52, 0x18, 0xa4, - 0x62, 0x45, 0x45, 0x64, 0xd3, 0x00, 0x46, 0x64, 0x23, 0x80, 0x01, 0x5b, 0x18, 0xc9, 0x37, 0x01, - 0x30, 0x04, 0x45, 0x64, 0xd2, 0x01, 0x2f, 0x04, 0xdd, 0xe2, 0x45, 0x64, 0xd0, 0x04, 0x1c, 0x20, - 0x99, 0x08, 0xf0, 0x04, 0xfa, 0xd9, 0x1a, 0x64, 0x9b, 0x00, 0x04, 0x22, 0x43, 0x1a, 0x06, 0x13, - 0x0e, 0x11, 0x43, 0x19, 0x23, 0xff, 0x02, 0x1b, 0x40, 0x13, 0x02, 0x1b, 0x43, 0x19, 0x23, 0xff, - 0x04, 0x1b, 0x40, 0x1a, 0x0a, 0x12, 0x43, 0x11, 0x23, 0x80, 0x9a, 0x01, 0x04, 0x5b, 0xb0, 0x03, - 0x1c, 0x20, 0x60, 0x91, 0x64, 0x14, 0x60, 0x13, 0x60, 0x53, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf0, 0x00, 0xb5, 0xf0, 0x26, 0xff, 0x25, 0xff, 0x22, 0x03, - 0x02, 0x36, 0x04, 0x2d, 0x46, 0x94, 0x4f, 0x18, 0xe0, 0x1e, 0x68, 0x82, 0x06, 0x13, 0x0e, 0x11, - 0x43, 0x19, 0x1c, 0x13, 0x40, 0x33, 0x02, 0x1b, 0x43, 0x19, 0x40, 0x2a, 0x0a, 0x12, 0x1c, 0x0c, - 0x43, 0x14, 0x0a, 0x23, 0x46, 0x62, 0x40, 0x13, 0x2b, 0x02, 0xd0, 0x07, 0x6b, 0xc1, 0x6c, 0x03, - 0x69, 0x4a, 0x18, 0xd2, 0x0c, 0x23, 0x40, 0x3b, 0x1a, 0xd2, 0x61, 0x4a, 0x6c, 0x03, 0x2b, 0x00, - 0xd0, 0x01, 0x06, 0x63, 0xd4, 0x03, 0x6b, 0x80, 0x28, 0x00, 0xd1, 0xde, 0xe0, 0x04, 0x6b, 0xc2, - 0x23, 0x01, 0x42, 0x5b, 0x61, 0x53, 0x1c, 0x18, 0x4b, 0x04, 0x68, 0x1a, 0x23, 0x00, 0x64, 0x13, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x00, 0x00, 0x7f, 0xff, 0x13, 0x70, 0x60, 0x34, - 0xb5, 0x00, 0x07, 0x43, 0xd5, 0x15, 0x4b, 0x0c, 0x4a, 0x0c, 0x68, 0x1b, 0x68, 0x99, 0x6c, 0x4b, - 0x40, 0x13, 0x2b, 0x03, 0xd1, 0x02, 0x23, 0x80, 0x01, 0x9b, 0x64, 0x4b, 0x4b, 0x06, 0x4a, 0x07, - 0x68, 0x1b, 0x68, 0x99, 0x6c, 0x8b, 0x40, 0x13, 0x2b, 0x03, 0xd1, 0x02, 0x23, 0x80, 0x01, 0x9b, - 0x64, 0x8b, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x34, 0x00, 0x00, 0x20, 0x03, - 0xb5, 0xf0, 0x07, 0x43, 0xd5, 0x21, 0x24, 0x80, 0x4e, 0x11, 0x4d, 0x12, 0x4f, 0x12, 0x20, 0x00, - 0x01, 0xa4, 0x68, 0x33, 0x00, 0x82, 0x68, 0x9b, 0x33, 0x44, 0x18, 0x99, 0x68, 0x2b, 0x68, 0x0a, - 0x42, 0x98, 0xd1, 0x0a, 0x07, 0xd3, 0xd4, 0x0d, 0x4a, 0x0c, 0x23, 0x02, 0x49, 0x0c, 0x60, 0x13, - 0x68, 0x0b, 0x22, 0x20, 0x43, 0x93, 0x60, 0x0b, 0xe0, 0x04, 0x1c, 0x13, 0x40, 0x3b, 0x2b, 0x03, - 0xd1, 0x00, 0x60, 0x0c, 0x30, 0x01, 0x28, 0x04, 0xd1, 0xe3, 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x78, 0x00, 0x00, 0x20, 0x03, 0x13, 0x70, 0x67, 0x6c, - 0x0d, 0x80, 0x00, 0xc0, 0xb5, 0x00, 0x4b, 0x0a, 0x22, 0x80, 0x68, 0x1b, 0x01, 0x92, 0x68, 0x99, - 0x6c, 0x4b, 0x42, 0x13, 0xd1, 0x00, 0x64, 0x4a, 0x4b, 0x05, 0x22, 0x80, 0x68, 0x1b, 0x01, 0x92, - 0x68, 0x99, 0x6c, 0x8b, 0x42, 0x13, 0xd1, 0x00, 0x64, 0x8a, 0x20, 0x00, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x60, 0x34, 0xb5, 0x00, 0x28, 0x00, 0xd0, 0x02, 0x23, 0x01, 0x42, 0x5b, 0x62, 0x03, - 0x20, 0x00, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x4b, 0x06, 0x49, 0x07, 0x78, 0x1a, 0x68, 0x08, - 0x1e, 0x53, 0x41, 0x9a, 0x4b, 0x05, 0x60, 0x1a, 0x00, 0x93, 0x18, 0x9b, 0x00, 0xdb, 0x33, 0x58, - 0x18, 0xc0, 0x47, 0x70, 0x13, 0x70, 0x01, 0x0c, 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x78, - 0xb5, 0x10, 0x1c, 0x18, 0x4b, 0x12, 0x1c, 0x14, 0x78, 0x1a, 0x1e, 0x53, 0x41, 0x9a, 0x4b, 0x11, - 0x60, 0x1a, 0x4b, 0x11, 0x68, 0x19, 0x00, 0x93, 0x18, 0x9b, 0x00, 0xdb, 0x18, 0xc9, 0x6f, 0x0b, - 0x2b, 0x00, 0xd0, 0x10, 0x23, 0x00, 0x80, 0x03, 0x80, 0x43, 0x31, 0x60, 0x88, 0x0b, 0x04, 0x1b, - 0x0a, 0x1a, 0x0e, 0x1b, 0x43, 0x1a, 0x80, 0x82, 0x88, 0x4b, 0x04, 0x1b, 0x0a, 0x1a, 0x0e, 0x1b, - 0x43, 0x1a, 0x80, 0xc2, 0x23, 0x01, 0x20, 0x00, 0x70, 0x23, 0xbc, 0x10, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x01, 0x0c, 0x13, 0x70, 0x67, 0x78, 0x13, 0x70, 0x60, 0x34, 0xb5, 0xf0, 0xb0, 0x81, - 0x1c, 0x07, 0x28, 0x00, 0xd1, 0x04, 0x4a, 0x20, 0x23, 0x30, 0x70, 0x13, 0x70, 0x50, 0xe0, 0x36, - 0x4d, 0x1e, 0x1c, 0x06, 0x1c, 0x30, 0x21, 0x0a, 0xf0, 0x04, 0xf9, 0xb6, 0x1c, 0x30, 0x1c, 0x0c, - 0x21, 0x0a, 0xf0, 0x04, 0xf9, 0x67, 0x17, 0xe3, 0x18, 0xe4, 0x40, 0x5c, 0x34, 0x30, 0x4b, 0x18, - 0x70, 0x2c, 0x3d, 0x01, 0x1c, 0x06, 0x42, 0x9d, 0xd1, 0xec, 0x1c, 0x2a, 0x3a, 0x0f, 0x23, 0x00, - 0x76, 0x93, 0x2f, 0x00, 0xdb, 0x01, 0x20, 0x00, 0xe0, 0x02, 0x23, 0x2d, 0x70, 0x13, 0x20, 0x01, - 0x22, 0x10, 0x49, 0x0d, 0xe0, 0x00, 0x32, 0x01, 0x5c, 0x8b, 0x2b, 0x30, 0xd0, 0xfb, 0x2b, 0x00, - 0xd1, 0x00, 0x3a, 0x01, 0x4b, 0x08, 0x18, 0x99, 0x18, 0x1b, 0xe0, 0x02, 0x70, 0x1a, 0x30, 0x01, - 0x33, 0x01, 0x78, 0x0a, 0x31, 0x01, 0x2a, 0x00, 0xd1, 0xf8, 0x4b, 0x03, 0x54, 0x1a, 0xb0, 0x01, - 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x72, 0xc1, 0xe0, 0x13, 0x72, 0xc1, 0xf9, - 0x13, 0x72, 0xc1, 0xef, 0xb5, 0xf0, 0xb0, 0x81, 0x1c, 0x06, 0x28, 0x00, 0xd1, 0x04, 0x4a, 0x1a, - 0x23, 0x30, 0x70, 0x13, 0x70, 0x50, 0xe0, 0x2a, 0x4d, 0x18, 0x1c, 0x2f, 0x3f, 0x0a, 0x1c, 0x30, - 0x21, 0x0a, 0xf0, 0x04, 0xf9, 0x17, 0x1c, 0x30, 0x1c, 0x0c, 0x21, 0x0a, 0xf0, 0x04, 0xf8, 0xd4, - 0x34, 0x30, 0x70, 0x2c, 0x3d, 0x01, 0x1c, 0x06, 0x42, 0xbd, 0xd1, 0xf0, 0x1c, 0x2a, 0x23, 0x00, - 0x3a, 0x0f, 0x76, 0x93, 0x23, 0x10, 0xe0, 0x00, 0x33, 0x01, 0x5c, 0xd1, 0x29, 0x30, 0xd0, 0xfb, - 0x29, 0x00, 0xd1, 0x00, 0x3b, 0x01, 0x48, 0x08, 0x22, 0x00, 0x18, 0xc1, 0x1c, 0x04, 0xe0, 0x01, - 0x54, 0xa3, 0x32, 0x01, 0x78, 0x0b, 0x31, 0x01, 0x2b, 0x00, 0xd1, 0xf9, 0x54, 0x83, 0xb0, 0x01, - 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x72, 0xc1, 0xe0, 0x13, 0x72, 0xc1, 0xf9, - 0xb5, 0x10, 0x28, 0x00, 0xd1, 0x04, 0x4a, 0x19, 0x23, 0x30, 0x70, 0x13, 0x70, 0x50, 0xe0, 0x2a, - 0x4a, 0x17, 0x24, 0x0f, 0x1c, 0x11, 0x39, 0x08, 0x1c, 0x03, 0x40, 0x23, 0x09, 0x00, 0x2b, 0x09, - 0xdd, 0x00, 0x33, 0x07, 0x33, 0x30, 0x70, 0x13, 0x3a, 0x01, 0x42, 0x8a, 0xd1, 0xf4, 0x3a, 0x0f, - 0x23, 0x00, 0x76, 0x13, 0x23, 0x30, 0x70, 0x13, 0x23, 0x78, 0x70, 0x53, 0x23, 0x10, 0xe0, 0x00, - 0x33, 0x01, 0x5c, 0xd1, 0x29, 0x30, 0xd0, 0xfb, 0x29, 0x00, 0xd1, 0x00, 0x3b, 0x01, 0x48, 0x07, - 0x22, 0x02, 0x18, 0xc1, 0x1c, 0x04, 0xe0, 0x01, 0x54, 0xa3, 0x32, 0x01, 0x78, 0x0b, 0x31, 0x01, - 0x2b, 0x00, 0xd1, 0xf9, 0x54, 0x83, 0xbc, 0x10, 0xbc, 0x01, 0x47, 0x00, 0x13, 0x72, 0xc1, 0xe0, - 0x13, 0x72, 0xc1, 0xf7, 0xb5, 0x00, 0x28, 0x00, 0xd0, 0x01, 0x23, 0x00, 0x60, 0x03, 0x4b, 0x0c, - 0x78, 0x1b, 0x2b, 0x01, 0xd1, 0x11, 0x4b, 0x0b, 0x78, 0x1a, 0x2a, 0x10, 0xd0, 0x0d, 0x28, 0x00, - 0xd0, 0x04, 0x4b, 0x09, 0x32, 0x04, 0x00, 0x92, 0x58, 0xd3, 0x60, 0x03, 0x4b, 0x05, 0x4a, 0x06, - 0x78, 0x1b, 0x33, 0x14, 0x00, 0x9b, 0x58, 0x98, 0xe0, 0x00, 0x20, 0x00, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x67, 0x9c, 0x13, 0x70, 0x60, 0x3c, 0x13, 0x72, 0xc2, 0x00, 0xb5, 0xf0, 0x4a, 0x67, - 0xb0, 0x8b, 0x68, 0x13, 0x2b, 0x00, 0xd1, 0x06, 0x4b, 0x65, 0x68, 0x19, 0x69, 0x8b, 0x60, 0x13, - 0x6a, 0x0b, 0x4a, 0x64, 0x60, 0x13, 0x4b, 0x63, 0x4f, 0x61, 0x68, 0x1d, 0x26, 0x00, 0x1c, 0x34, - 0x68, 0x3b, 0x34, 0x08, 0x00, 0xa4, 0x50, 0xe5, 0x68, 0x3b, 0x21, 0x00, 0x58, 0xe0, 0x22, 0x60, - 0xf0, 0x04, 0xf9, 0x70, 0x68, 0x3b, 0x21, 0x60, 0x58, 0xe0, 0xf0, 0x03, 0xf9, 0xd3, 0x1c, 0x2b, - 0x33, 0x7f, 0x1c, 0x1d, 0x21, 0x1f, 0x36, 0x01, 0x43, 0x8d, 0x2e, 0x08, 0xd1, 0xe7, 0x24, 0x00, - 0x26, 0x1f, 0x1c, 0x28, 0x21, 0x00, 0x22, 0x60, 0xf0, 0x04, 0xf9, 0x5c, 0x1c, 0x28, 0x21, 0x60, - 0xf0, 0x03, 0xf9, 0xc0, 0x1c, 0x2b, 0x33, 0x7f, 0x1c, 0x1d, 0x34, 0x01, 0x43, 0xb5, 0x2c, 0x08, - 0xd1, 0xef, 0x4b, 0x4d, 0x4a, 0x4d, 0x60, 0x1d, 0x4b, 0x48, 0x92, 0x06, 0x21, 0x80, 0x22, 0xff, - 0x68, 0x1f, 0x05, 0xc9, 0x23, 0x00, 0x02, 0x12, 0x93, 0x08, 0x91, 0x02, 0x92, 0x01, 0x9b, 0x06, - 0x21, 0x00, 0x60, 0x1f, 0x22, 0x60, 0x1c, 0x38, 0xf0, 0x04, 0xf9, 0x3c, 0x1c, 0x38, 0xf0, 0x03, - 0xf9, 0x5b, 0x64, 0x78, 0x99, 0x06, 0x9b, 0x08, 0x68, 0x0a, 0x2b, 0x00, 0xd0, 0x01, 0x23, 0x80, - 0x04, 0x1b, 0x60, 0x53, 0x99, 0x06, 0x23, 0x00, 0x68, 0x0a, 0x60, 0x93, 0x68, 0x0b, 0x9a, 0x02, - 0x21, 0x1f, 0x61, 0x9a, 0x1c, 0x3b, 0x33, 0x7f, 0x9a, 0x06, 0x1c, 0x1f, 0x43, 0x8f, 0x68, 0x12, - 0x1c, 0x38, 0x92, 0x07, 0xf0, 0x03, 0xf9, 0x40, 0x1c, 0x06, 0x1c, 0x38, 0xf0, 0x03, 0xf9, 0x3c, - 0x1c, 0x04, 0x1c, 0x38, 0xf0, 0x03, 0xf9, 0x38, 0x1c, 0x05, 0x1c, 0x38, 0xf0, 0x03, 0xf9, 0x34, - 0x99, 0x01, 0x23, 0xff, 0x22, 0xff, 0x04, 0x12, 0x02, 0x1b, 0x93, 0x05, 0x40, 0x0c, 0x40, 0x15, - 0x23, 0xe0, 0x40, 0x1e, 0x21, 0x02, 0x02, 0x24, 0x0a, 0x2d, 0x0e, 0x00, 0x43, 0x0e, 0x43, 0x2c, - 0x92, 0x04, 0x43, 0x04, 0x9a, 0x07, 0x06, 0x36, 0x43, 0x34, 0x60, 0x14, 0x9b, 0x06, 0x68, 0x1a, - 0x23, 0x80, 0x04, 0x5b, 0x61, 0x13, 0x99, 0x06, 0x68, 0x0a, 0x61, 0x53, 0xc9, 0x01, 0x91, 0x06, - 0x21, 0x60, 0xf0, 0x03, 0xf9, 0x57, 0x9a, 0x08, 0x32, 0x01, 0x92, 0x08, 0x2a, 0x06, 0xd1, 0xa6, - 0x4b, 0x1a, 0x4f, 0x16, 0x93, 0x03, 0x69, 0x59, 0x68, 0x38, 0x91, 0x09, 0xf0, 0x03, 0xf9, 0x04, - 0x1c, 0x06, 0x68, 0x38, 0xf0, 0x03, 0xf9, 0x00, 0x1c, 0x04, 0x68, 0x38, 0xf0, 0x03, 0xf8, 0xfc, - 0x1c, 0x05, 0x68, 0x38, 0xf0, 0x03, 0xf8, 0xf8, 0x9a, 0x05, 0x9b, 0x04, 0x40, 0x14, 0x40, 0x1d, - 0x21, 0xe0, 0x0a, 0x2d, 0x22, 0x02, 0x40, 0x0e, 0x02, 0x24, 0x43, 0x2c, 0x43, 0x16, 0x0e, 0x00, - 0x9b, 0x09, 0x06, 0x36, 0x43, 0x04, 0x43, 0x34, 0x60, 0x1c, 0x99, 0x03, 0x69, 0x48, 0x21, 0x60, - 0xf0, 0x03, 0xf9, 0x28, 0xb0, 0x0b, 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x13, 0x70, 0x67, 0xcc, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0xc8, 0x13, 0x70, 0x67, 0xc4, 0x13, 0x72, 0xc0, 0x20, - 0xb5, 0x30, 0xb0, 0x81, 0x1c, 0x04, 0xf0, 0x03, 0xf8, 0xcf, 0x21, 0x00, 0x1c, 0x05, 0x22, 0x60, - 0x1c, 0x20, 0xf0, 0x04, 0xf8, 0xa7, 0x23, 0x40, 0x60, 0xa3, 0x23, 0x80, 0x04, 0x5b, 0xb0, 0x01, - 0x63, 0x65, 0x60, 0x23, 0x60, 0x63, 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, 0xb5, 0xf0, 0x4b, 0x1a, - 0xb0, 0x83, 0x68, 0x1d, 0x23, 0x00, 0x93, 0x01, 0x23, 0xff, 0x02, 0x1b, 0x27, 0xff, 0x26, 0x80, - 0x93, 0x00, 0x04, 0x3f, 0x04, 0x76, 0x1c, 0x28, 0xf7, 0xff, 0xff, 0xda, 0x9b, 0x01, 0x2b, 0x03, - 0xd0, 0x19, 0x1c, 0x2c, 0x23, 0x1f, 0x34, 0x7f, 0x43, 0x9c, 0x6b, 0x62, 0x1c, 0x28, 0x06, 0x13, - 0x0e, 0x11, 0x43, 0x19, 0x9b, 0x00, 0x60, 0x6e, 0x40, 0x13, 0x02, 0x1b, 0x40, 0x3a, 0x43, 0x19, - 0x0a, 0x12, 0x43, 0x11, 0x60, 0x29, 0x21, 0x60, 0xf0, 0x03, 0xf8, 0xdc, 0x9b, 0x01, 0x1c, 0x25, - 0x33, 0x01, 0x93, 0x01, 0xe7, 0xdf, 0x1c, 0x28, 0x21, 0x60, 0xf0, 0x03, 0xf8, 0xd3, 0xb0, 0x03, - 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x67, 0xc4, 0xb5, 0xf0, 0xb0, 0x83, - 0xf7, 0xff, 0xfe, 0xd4, 0xf7, 0xff, 0xff, 0xc2, 0x4d, 0x4b, 0x49, 0x4c, 0x68, 0x2a, 0x68, 0x0b, - 0x4f, 0x4b, 0x61, 0x93, 0x68, 0x2a, 0x68, 0x4b, 0x4e, 0x4a, 0x61, 0xd3, 0x68, 0x8b, 0x4a, 0x4a, - 0x60, 0x3b, 0x92, 0x01, 0x68, 0xcb, 0x60, 0x13, 0x69, 0x0b, 0x21, 0x60, 0x60, 0x33, 0x68, 0x2b, - 0x69, 0x98, 0xf0, 0x03, 0xf8, 0x97, 0x68, 0x2a, 0x69, 0x93, 0x64, 0xda, 0x68, 0x2b, 0x22, 0x00, - 0x69, 0x9b, 0x64, 0x9a, 0x68, 0x2b, 0x69, 0x9c, 0x1c, 0x20, 0xf0, 0x03, 0xf8, 0x5d, 0x64, 0x60, - 0x68, 0x33, 0x6c, 0x59, 0x68, 0x2b, 0x1c, 0x0a, 0x69, 0x98, 0x23, 0xff, 0x02, 0x1b, 0x40, 0x1a, - 0x23, 0xff, 0x04, 0x1b, 0x40, 0x0b, 0x0a, 0x1b, 0x02, 0x12, 0x43, 0x1a, 0x0e, 0x0b, 0x43, 0x1a, - 0x23, 0xe0, 0x40, 0x19, 0x23, 0x02, 0x43, 0x19, 0x06, 0x09, 0x43, 0x0a, 0x60, 0x02, 0x68, 0x2b, - 0x21, 0x60, 0x69, 0x9a, 0x23, 0x80, 0x04, 0x1b, 0x60, 0x53, 0x68, 0x2b, 0x22, 0x00, 0x69, 0x9b, - 0x60, 0x9a, 0x68, 0x2b, 0x69, 0x9a, 0x23, 0x80, 0x05, 0xdb, 0x61, 0x93, 0x68, 0x2b, 0x69, 0x9a, - 0x23, 0x80, 0x04, 0x5b, 0x61, 0x13, 0x68, 0x2a, 0x69, 0x92, 0x61, 0x53, 0x68, 0x2b, 0x69, 0x98, - 0xf0, 0x03, 0xf8, 0x70, 0x68, 0x2b, 0x21, 0x60, 0x69, 0xd8, 0xf0, 0x03, 0xf8, 0x53, 0x68, 0x2a, - 0x69, 0xd3, 0x64, 0xda, 0x68, 0x2b, 0x22, 0x00, 0x69, 0xdb, 0x64, 0x9a, 0x68, 0x2b, 0x69, 0xdc, - 0x1c, 0x20, 0xf0, 0x03, 0xf8, 0x19, 0x64, 0x60, 0x68, 0x38, 0x21, 0x60, 0xf0, 0x03, 0xf8, 0x42, - 0x68, 0x3a, 0x68, 0x2b, 0x64, 0xd3, 0x68, 0x3b, 0x22, 0x00, 0x64, 0x9a, 0x68, 0x3c, 0x1c, 0x20, - 0xf0, 0x03, 0xf8, 0x0a, 0x64, 0x60, 0x68, 0x38, 0x21, 0x60, 0xf0, 0x03, 0xf8, 0x4b, 0x9b, 0x01, - 0x21, 0x60, 0x68, 0x18, 0xf0, 0x03, 0xf8, 0x2e, 0x9b, 0x01, 0x68, 0x1a, 0x68, 0x2b, 0x64, 0xd3, - 0x9a, 0x01, 0x68, 0x13, 0x22, 0x00, 0x64, 0x9a, 0x9b, 0x01, 0x68, 0x1c, 0x1c, 0x20, 0xf0, 0x02, - 0xff, 0xf3, 0x64, 0x60, 0x9a, 0x01, 0x21, 0x60, 0x68, 0x10, 0xf0, 0x03, 0xf8, 0x33, 0xb0, 0x03, - 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x34, 0x13, 0x72, 0xc0, 0x20, - 0x13, 0x70, 0x67, 0x7c, 0x13, 0x70, 0x67, 0x84, 0x13, 0x70, 0x67, 0x80, 0xb5, 0xf0, 0x4c, 0x23, - 0x4b, 0x23, 0xb0, 0x81, 0x60, 0x23, 0xf0, 0x03, 0xf8, 0x35, 0x28, 0x00, 0xda, 0x02, 0x20, 0x01, - 0x42, 0x40, 0xe0, 0x37, 0xf0, 0x03, 0xf9, 0x80, 0x60, 0x20, 0x68, 0x82, 0x4b, 0x1d, 0x21, 0x01, - 0x60, 0x13, 0x68, 0x20, 0x68, 0x82, 0x68, 0x13, 0x42, 0x0b, 0xd1, 0xfc, 0x21, 0xfc, 0xf0, 0x03, - 0xf8, 0x09, 0x27, 0x80, 0x26, 0x80, 0x4c, 0x15, 0x25, 0x00, 0x04, 0x7f, 0x01, 0x76, 0x68, 0x23, - 0x21, 0x04, 0x6c, 0xdb, 0x51, 0x5f, 0x68, 0x23, 0x6c, 0xdb, 0x59, 0x58, 0x35, 0x04, 0xf0, 0x02, - 0xff, 0xf9, 0x42, 0xb5, 0xd1, 0xf3, 0xf7, 0xff, 0xff, 0x29, 0x68, 0x23, 0x22, 0x01, 0x33, 0x54, - 0x70, 0x1a, 0x68, 0x23, 0x20, 0x00, 0x68, 0x9a, 0x69, 0x9b, 0x6c, 0x5b, 0x61, 0x93, 0x68, 0x23, - 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0x68, 0x23, 0x68, 0x9a, 0x4b, 0x07, 0x60, 0x13, 0x68, 0x23, - 0x68, 0x9b, 0x68, 0x1b, 0xb0, 0x01, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x34, - 0x13, 0x72, 0xc2, 0xa4, 0x00, 0x01, 0x00, 0x20, 0x00, 0x01, 0x00, 0x21, 0xb5, 0x10, 0x4b, 0x0c, - 0x68, 0x18, 0x6c, 0x01, 0x29, 0x07, 0xdd, 0x01, 0x24, 0x00, 0xe0, 0x0d, 0x4b, 0x09, 0x68, 0x1b, - 0x00, 0xdb, 0x18, 0x5b, 0x00, 0x5a, 0x18, 0xd2, 0x6a, 0x03, 0x01, 0x52, 0x18, 0x9c, 0x1c, 0x4b, - 0x64, 0x03, 0x1c, 0x20, 0xf7, 0xff, 0xfe, 0xa4, 0x1c, 0x20, 0xbc, 0x10, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x70, 0xb5, 0xf0, 0xb0, 0x8d, 0x1c, 0x05, 0xf7, 0xff, - 0xff, 0xdd, 0x90, 0x08, 0x28, 0x00, 0xd1, 0x00, 0xe0, 0xad, 0x63, 0xc5, 0x23, 0x00, 0x61, 0x6b, - 0x7e, 0x6b, 0x69, 0x2a, 0x93, 0x07, 0x7e, 0x2b, 0x92, 0x0a, 0x2b, 0x00, 0xd0, 0x02, 0x9c, 0x08, - 0x26, 0x80, 0xe0, 0x26, 0x23, 0x08, 0x93, 0x00, 0x23, 0xa0, 0x68, 0x69, 0x22, 0x08, 0x00, 0x9b, - 0x98, 0x08, 0xf7, 0xff, 0xfb, 0x57, 0xf7, 0xff, 0xff, 0xc1, 0x1c, 0x04, 0x28, 0x00, 0xd1, 0x00, - 0xe0, 0x91, 0x6b, 0x42, 0x63, 0xc5, 0x06, 0x13, 0x0e, 0x11, 0x43, 0x19, 0x23, 0xff, 0x02, 0x1b, - 0x40, 0x13, 0x02, 0x1b, 0x43, 0x19, 0x23, 0xff, 0x04, 0x1b, 0x40, 0x1a, 0x0a, 0x12, 0x43, 0x11, - 0x9a, 0x08, 0x60, 0x11, 0x63, 0x90, 0x9b, 0x0a, 0x2b, 0x00, 0xd1, 0x01, 0x4e, 0x40, 0xe0, 0x00, - 0x4e, 0x40, 0x68, 0xea, 0x9b, 0x07, 0x92, 0x09, 0x2b, 0x00, 0xd0, 0x02, 0x23, 0x80, 0x00, 0x5b, - 0x43, 0x1e, 0x69, 0xea, 0x4b, 0x3c, 0x27, 0xff, 0x40, 0x13, 0x93, 0x0b, 0x3b, 0x01, 0x22, 0x80, - 0x93, 0x04, 0x23, 0xff, 0x04, 0x52, 0x02, 0x1b, 0x92, 0x05, 0x93, 0x03, 0x04, 0x3f, 0x9a, 0x0b, - 0x1c, 0x33, 0x92, 0x00, 0x1c, 0x20, 0x9a, 0x0a, 0x99, 0x09, 0xf7, 0xff, 0xfb, 0x1b, 0x9b, 0x0a, - 0x9a, 0x09, 0x1a, 0x1b, 0x93, 0x0a, 0x9b, 0x07, 0x18, 0x12, 0x92, 0x09, 0x2b, 0x00, 0xd0, 0x01, - 0x9a, 0x05, 0x60, 0x62, 0x9a, 0x04, 0x18, 0x13, 0x9a, 0x0b, 0x42, 0x13, 0xd1, 0x01, 0x4b, 0x2b, - 0x18, 0xf6, 0x9a, 0x0a, 0x2a, 0x00, 0xdd, 0x13, 0xf7, 0xff, 0xff, 0x70, 0x28, 0x00, 0xd0, 0x42, - 0x6b, 0x42, 0x63, 0xc5, 0x06, 0x13, 0x0e, 0x11, 0x43, 0x19, 0x9b, 0x03, 0x63, 0xa0, 0x40, 0x13, - 0x02, 0x1b, 0x40, 0x3a, 0x43, 0x19, 0x0a, 0x12, 0x43, 0x11, 0x60, 0x21, 0x1c, 0x04, 0xe7, 0xce, - 0x23, 0x80, 0x04, 0x5b, 0x60, 0x63, 0x69, 0x2b, 0x1c, 0x27, 0x2b, 0x00, 0xd0, 0x24, 0x7e, 0x2b, - 0x93, 0x06, 0x2b, 0x00, 0xd1, 0x20, 0xf7, 0xff, 0xff, 0x51, 0x1c, 0x04, 0x28, 0x00, 0xd0, 0x22, - 0x6b, 0x42, 0x63, 0xc5, 0x06, 0x13, 0x0e, 0x11, 0x43, 0x19, 0x23, 0xff, 0x02, 0x1b, 0x40, 0x13, - 0x02, 0x1b, 0x43, 0x19, 0x23, 0xff, 0x04, 0x1b, 0x40, 0x1a, 0x0a, 0x12, 0x23, 0x80, 0x43, 0x11, - 0x00, 0x5b, 0x4a, 0x0e, 0x60, 0x39, 0x63, 0xb8, 0x40, 0x73, 0x43, 0x13, 0x9a, 0x06, 0x21, 0x00, - 0x92, 0x00, 0x22, 0x00, 0xf7, 0xff, 0xfa, 0xc6, 0x68, 0xa3, 0x22, 0x80, 0x04, 0x12, 0x43, 0x13, - 0x60, 0xa3, 0x98, 0x08, 0xe0, 0x00, 0x20, 0x00, 0xb0, 0x0d, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x80, 0x00, 0x01, 0x80, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0x00, - 0xb5, 0xf0, 0x7c, 0x83, 0x7c, 0xc2, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7d, 0x03, 0xb0, 0x85, - 0x02, 0x1b, 0x43, 0x13, 0x7d, 0x42, 0x1c, 0x06, 0x43, 0x1a, 0xd0, 0x67, 0x22, 0x00, 0x92, 0x01, - 0xe0, 0x53, 0x06, 0x0b, 0x04, 0x12, 0x43, 0x1a, 0x02, 0x23, 0x43, 0x13, 0x9a, 0x03, 0x43, 0x03, - 0x18, 0x9d, 0x7a, 0x6b, 0x7a, 0xaa, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7a, 0xeb, 0x02, 0x1b, - 0x43, 0x13, 0x7b, 0x2a, 0x43, 0x1a, 0xd0, 0x3b, 0x23, 0x00, 0x93, 0x02, 0x27, 0x00, 0xe0, 0x26, - 0x06, 0x0b, 0x04, 0x12, 0x43, 0x1a, 0x02, 0x23, 0x43, 0x13, 0x43, 0x03, 0x19, 0xdc, 0x7b, 0xa3, - 0x7b, 0xe2, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7c, 0x23, 0x02, 0x1b, 0x43, 0x13, 0x7c, 0x62, - 0x1c, 0x10, 0x43, 0x18, 0xd0, 0x01, 0xf0, 0x02, 0xfe, 0x71, 0x7a, 0x63, 0x7a, 0xa2, 0x06, 0x1b, - 0x04, 0x12, 0x43, 0x1a, 0x7a, 0xe3, 0x02, 0x1b, 0x43, 0x13, 0x7b, 0x22, 0x1c, 0x10, 0x43, 0x18, - 0xd0, 0x01, 0xf0, 0x02, 0xfe, 0x63, 0x9a, 0x02, 0x37, 0x12, 0x32, 0x01, 0x92, 0x02, 0x79, 0x2b, - 0x7a, 0x69, 0x46, 0x9c, 0x9b, 0x02, 0x7a, 0xaa, 0x7a, 0xec, 0x7b, 0x28, 0x45, 0x63, 0xdb, 0xcf, - 0x06, 0x0b, 0x04, 0x12, 0x43, 0x1a, 0x02, 0x23, 0x43, 0x13, 0x43, 0x18, 0xf0, 0x02, 0xfe, 0x4e, - 0x9d, 0x01, 0x9a, 0x03, 0x35, 0x01, 0x95, 0x01, 0x32, 0x0d, 0x7c, 0x73, 0x9d, 0x01, 0x92, 0x03, - 0x7c, 0xb1, 0x7c, 0xf2, 0x7d, 0x34, 0x7d, 0x70, 0x42, 0x9d, 0xdb, 0xa2, 0x06, 0x0b, 0x04, 0x12, - 0x43, 0x1a, 0x02, 0x23, 0x43, 0x13, 0x43, 0x18, 0xf0, 0x02, 0xfe, 0x38, 0xb0, 0x05, 0xbc, 0xf0, - 0xbc, 0x01, 0x47, 0x00, 0xb4, 0x0f, 0xb5, 0xf0, 0xb0, 0x83, 0x46, 0x6a, 0x23, 0x80, 0xad, 0x08, - 0x32, 0x06, 0x01, 0x9b, 0xcd, 0x10, 0x80, 0x13, 0x4e, 0x1d, 0xe0, 0x30, 0x1c, 0x67, 0x2b, 0x25, - 0xd0, 0x07, 0x46, 0x6a, 0x46, 0x68, 0x71, 0x93, 0x30, 0x06, 0x1c, 0x3c, 0xf7, 0xfe, 0xfa, 0x4c, - 0xe0, 0x25, 0x78, 0x63, 0x2b, 0x73, 0xd0, 0x1c, 0x2b, 0x73, 0xd8, 0x04, 0x2b, 0x64, 0xd0, 0x07, - 0x2b, 0x69, 0xd1, 0x1b, 0xe0, 0x04, 0x2b, 0x75, 0xd0, 0x07, 0x2b, 0x78, 0xd1, 0x16, 0xe0, 0x0a, - 0x68, 0x28, 0x1d, 0x2c, 0xf7, 0xff, 0xfb, 0x72, 0xe0, 0x09, 0x68, 0x28, 0xf7, 0xff, 0xfb, 0xba, - 0x1d, 0x2c, 0x1c, 0x30, 0xe0, 0x07, 0x68, 0x28, 0x1d, 0x2c, 0xf7, 0xff, 0xfb, 0xf1, 0x48, 0x08, - 0xe0, 0x01, 0x68, 0x28, 0x1d, 0x2c, 0xf7, 0xfe, 0xfa, 0x27, 0x1c, 0x25, 0x1c, 0x7c, 0x78, 0x23, - 0x2b, 0x00, 0xd1, 0xcb, 0xb0, 0x03, 0xbc, 0xf0, 0xbc, 0x08, 0xb0, 0x04, 0x47, 0x18, 0x46, 0xc0, - 0x13, 0x72, 0xc1, 0xe0, 0xb5, 0xf0, 0x4b, 0x32, 0xb0, 0x8f, 0x68, 0x1b, 0x1c, 0x01, 0x68, 0x9a, - 0x4b, 0x30, 0x68, 0x54, 0x68, 0x1b, 0x32, 0x44, 0x00, 0x9b, 0x18, 0xd2, 0x68, 0x12, 0x48, 0x2e, - 0x92, 0x0d, 0xf7, 0xff, 0xff, 0xa7, 0x04, 0x20, 0xd4, 0x02, 0x49, 0x2c, 0x91, 0x0a, 0xe0, 0x01, - 0x4b, 0x2b, 0x93, 0x0a, 0x04, 0x60, 0xd4, 0x02, 0x49, 0x28, 0x91, 0x0b, 0xe0, 0x01, 0x4b, 0x29, - 0x93, 0x0b, 0x04, 0xa0, 0xd4, 0x02, 0x49, 0x25, 0x91, 0x0c, 0xe0, 0x01, 0x4b, 0x26, 0x93, 0x0c, - 0x04, 0xe0, 0xd4, 0x02, 0x49, 0x21, 0x46, 0x8c, 0xe0, 0x01, 0x4b, 0x24, 0x46, 0x9c, 0x06, 0xa0, - 0xd4, 0x01, 0x4f, 0x1e, 0xe0, 0x00, 0x4f, 0x22, 0x06, 0xe1, 0xd4, 0x01, 0x4e, 0x1b, 0xe0, 0x00, - 0x4e, 0x20, 0x07, 0x23, 0xd4, 0x01, 0x4d, 0x19, 0xe0, 0x00, 0x4d, 0x1f, 0x07, 0x60, 0xd4, 0x01, - 0x4a, 0x16, 0xe0, 0x00, 0x4a, 0x1d, 0x07, 0xa1, 0xd4, 0x01, 0x4b, 0x14, 0xe0, 0x00, 0x4b, 0x1c, - 0x07, 0xe0, 0xd4, 0x01, 0x49, 0x11, 0xe0, 0x00, 0x49, 0x1a, 0x48, 0x1b, 0x92, 0x05, 0x90, 0x09, - 0x98, 0x0c, 0x9a, 0x0a, 0x90, 0x00, 0x46, 0x60, 0x90, 0x01, 0x93, 0x06, 0x91, 0x07, 0x9b, 0x0b, - 0x98, 0x09, 0x1c, 0x21, 0x97, 0x02, 0x96, 0x03, 0x95, 0x04, 0xf7, 0xff, 0xff, 0x5b, 0x99, 0x0d, - 0x48, 0x12, 0xf7, 0xff, 0xff, 0x57, 0xb0, 0x0f, 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x78, 0x13, 0x70, 0x60, 0x85, 0x13, 0x70, 0x66, 0x42, - 0x13, 0x70, 0x60, 0x9b, 0x13, 0x70, 0x60, 0xa2, 0x13, 0x70, 0x60, 0xac, 0x13, 0x70, 0x60, 0xb2, - 0x13, 0x70, 0x60, 0xb8, 0x13, 0x70, 0x60, 0xbd, 0x13, 0x70, 0x60, 0xc4, 0x13, 0x70, 0x60, 0xc9, - 0x13, 0x70, 0x60, 0xce, 0x13, 0x70, 0x60, 0xd3, 0x13, 0x70, 0x60, 0xd8, 0x13, 0x70, 0x60, 0xfd, - 0xb5, 0x30, 0x4b, 0x0b, 0xb0, 0x81, 0x68, 0x1a, 0x25, 0x20, 0x68, 0x92, 0x1c, 0x1c, 0x68, 0x12, - 0x68, 0x23, 0x43, 0x2a, 0x68, 0x9b, 0x20, 0x0a, 0x60, 0x1a, 0xf7, 0xff, 0xf9, 0x2b, 0x68, 0x23, - 0x68, 0x9b, 0x68, 0x1a, 0x42, 0x2a, 0xd0, 0xf3, 0xb0, 0x01, 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, - 0x13, 0x70, 0x60, 0x34, 0xb5, 0x30, 0x4b, 0x0b, 0xb0, 0x81, 0x68, 0x1a, 0x25, 0x20, 0x68, 0x92, - 0x1c, 0x1c, 0x68, 0x12, 0x68, 0x23, 0x43, 0xaa, 0x68, 0x9b, 0x20, 0x0a, 0x60, 0x1a, 0xf7, 0xff, - 0xf9, 0x11, 0x68, 0x23, 0x68, 0x9b, 0x68, 0x1a, 0x42, 0x2a, 0xd1, 0xf3, 0xb0, 0x01, 0xbc, 0x30, - 0xbc, 0x01, 0x47, 0x00, 0x13, 0x70, 0x60, 0x34, 0xb5, 0xf0, 0xb0, 0x81, 0x1c, 0x0e, 0x28, 0x00, - 0xd1, 0x18, 0x4e, 0x18, 0x4d, 0x18, 0x4f, 0x19, 0x24, 0x00, 0x68, 0x33, 0x68, 0x9b, 0x69, 0x9a, - 0x69, 0x2b, 0x6c, 0x5b, 0x42, 0x9a, 0xd3, 0x06, 0x69, 0x6b, 0x6c, 0x5b, 0x42, 0x9a, 0xd8, 0x02, - 0xf7, 0xff, 0xff, 0xd0, 0xe0, 0x18, 0x20, 0x0a, 0x34, 0x01, 0xf7, 0xff, 0xf8, 0xeb, 0x42, 0xbc, - 0xd1, 0xeb, 0xe0, 0x11, 0x28, 0x01, 0xd1, 0x0f, 0x24, 0x00, 0x4d, 0x0a, 0x4f, 0x0b, 0xe0, 0x05, - 0x20, 0x0a, 0x34, 0x01, 0xf7, 0xff, 0xf8, 0xde, 0x42, 0xbc, 0xd0, 0x05, 0x68, 0x2b, 0x68, 0x9b, - 0x69, 0x9a, 0x6c, 0x73, 0x42, 0x9a, 0xd0, 0xf3, 0xb0, 0x01, 0x20, 0x00, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x34, 0x13, 0x72, 0xc0, 0x20, 0x00, 0x00, 0x13, 0x88, - 0xb5, 0xf0, 0xb0, 0x83, 0x1c, 0x1f, 0x4b, 0x0f, 0x92, 0x00, 0x91, 0x01, 0x9a, 0x08, 0x68, 0x1c, - 0x00, 0x55, 0x1c, 0x1e, 0x20, 0x0a, 0xf7, 0xff, 0xf8, 0xbd, 0x9a, 0x01, 0x68, 0x13, 0x9a, 0x00, - 0x40, 0x13, 0x42, 0xbb, 0xd1, 0x01, 0x20, 0x00, 0xe0, 0x07, 0x68, 0x33, 0x1b, 0x1b, 0xd5, 0x00, - 0x68, 0x34, 0x42, 0xab, 0xd3, 0xee, 0x20, 0x02, 0x42, 0x40, 0xb0, 0x03, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x0d, 0x80, 0x00, 0x10, 0xb5, 0x10, 0x4b, 0x13, 0x30, 0x10, 0x68, 0x1b, - 0x00, 0x80, 0x68, 0x9b, 0x18, 0x1c, 0x68, 0x62, 0x23, 0x80, 0x01, 0x9b, 0x42, 0x1a, 0xd1, 0x00, - 0x40, 0x5a, 0x23, 0x2e, 0x43, 0x9a, 0x60, 0x62, 0x20, 0x05, 0xf7, 0xfe, 0xff, 0x2b, 0x23, 0x80, - 0x68, 0x62, 0x01, 0x9b, 0x42, 0x1a, 0xd0, 0x00, 0x40, 0x5a, 0x23, 0x2e, 0x43, 0x9a, 0x60, 0x62, - 0x20, 0x05, 0xf7, 0xfe, 0xff, 0x1f, 0x4b, 0x05, 0x20, 0x05, 0x60, 0x63, 0xf7, 0xfe, 0xff, 0x1a, - 0xbc, 0x10, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x34, 0x00, 0x00, 0x18, 0x01, - 0xb5, 0xf0, 0x4b, 0x29, 0xb0, 0x85, 0x68, 0x1a, 0x1c, 0x03, 0x68, 0x92, 0x33, 0x10, 0x00, 0x9b, - 0x18, 0xd2, 0x92, 0x03, 0x1c, 0x15, 0x4b, 0x25, 0x68, 0x52, 0x35, 0x04, 0x40, 0x13, 0x2b, 0x01, - 0xd0, 0x06, 0x04, 0x91, 0xd5, 0x01, 0xf7, 0xff, 0xff, 0xbf, 0x24, 0x01, 0x42, 0x64, 0xe0, 0x36, - 0x26, 0x88, 0x27, 0x00, 0x01, 0x76, 0x21, 0x04, 0x1c, 0x13, 0x43, 0x8b, 0x43, 0x33, 0x60, 0x2b, - 0x20, 0x3c, 0xf7, 0xff, 0xf8, 0x79, 0x68, 0x2b, 0x4a, 0x19, 0x20, 0x32, 0x40, 0x13, 0x60, 0x2b, - 0xf7, 0xff, 0xf8, 0x72, 0x4b, 0x17, 0x22, 0x80, 0x93, 0x00, 0x1c, 0x28, 0x1c, 0x29, 0x00, 0x52, - 0x23, 0x00, 0xf7, 0xff, 0xff, 0x7d, 0x1c, 0x04, 0x28, 0x00, 0xd0, 0x03, 0x9b, 0x03, 0x4c, 0x12, - 0x68, 0x5a, 0xe0, 0x14, 0x68, 0x2a, 0x21, 0x04, 0x42, 0x0a, 0xd1, 0x02, 0x37, 0x01, 0x2f, 0x04, - 0xd1, 0xd9, 0x07, 0x53, 0xd4, 0x0b, 0x23, 0x80, 0x01, 0x9b, 0x43, 0x13, 0x99, 0x03, 0x22, 0x2a, - 0x43, 0x93, 0x60, 0x4b, 0x20, 0x0a, 0xf7, 0xff, 0xf8, 0x4f, 0x9b, 0x03, 0x68, 0x5a, 0xb0, 0x05, - 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x34, 0x00, 0x00, 0x20, 0x01, - 0xff, 0xff, 0xfe, 0xd5, 0x00, 0x00, 0x13, 0x88, 0xff, 0xff, 0xf8, 0x30, 0xb5, 0xf0, 0xb0, 0x85, - 0x90, 0x01, 0x1c, 0x0f, 0x20, 0x00, 0x21, 0x00, 0xf7, 0xff, 0xff, 0x0e, 0x7e, 0x3a, 0x2a, 0x00, - 0xd1, 0x06, 0x4b, 0xc2, 0x21, 0x08, 0x60, 0x1a, 0x68, 0x38, 0xf0, 0x02, 0xfc, 0x8b, 0x60, 0x78, - 0x69, 0x39, 0x29, 0x00, 0xd0, 0x09, 0x7e, 0x7b, 0x68, 0xb8, 0x2b, 0x00, 0xd0, 0x02, 0xf0, 0x02, - 0xfc, 0x81, 0xe0, 0x01, 0xf0, 0x02, 0xfc, 0x76, 0x60, 0xf8, 0x7e, 0x3b, 0x2b, 0x00, 0xd1, 0x03, - 0x4b, 0xb7, 0x68, 0x1b, 0x69, 0xdb, 0xe0, 0x06, 0x7e, 0x7b, 0x2b, 0x00, 0xd0, 0x01, 0x4b, 0xb5, - 0xe0, 0x00, 0x4b, 0xb5, 0x68, 0x1b, 0x93, 0x02, 0x4c, 0xb4, 0x4b, 0xb5, 0x98, 0x02, 0x99, 0x02, - 0x60, 0x18, 0x22, 0x60, 0x1c, 0x20, 0xf0, 0x02, 0xfd, 0x87, 0x21, 0x00, 0x22, 0x30, 0x98, 0x02, - 0xf0, 0x03, 0xfb, 0xe8, 0x4b, 0xaa, 0x49, 0xaf, 0x68, 0x1a, 0x23, 0x00, 0x64, 0x13, 0x68, 0x0b, - 0x22, 0x01, 0x40, 0x53, 0x60, 0x0b, 0x1c, 0x38, 0xf7, 0xff, 0xfc, 0x8e, 0x4b, 0xaa, 0x64, 0xa0, - 0x60, 0x18, 0x1c, 0x06, 0x98, 0x01, 0x22, 0x80, 0x69, 0x83, 0x7e, 0x39, 0x01, 0x92, 0x43, 0x1a, - 0x23, 0x0f, 0x40, 0x0b, 0x02, 0x1b, 0x1c, 0x10, 0x69, 0xfc, 0x43, 0x18, 0x29, 0x00, 0xd1, 0x03, - 0x4b, 0xa2, 0x1c, 0x01, 0x43, 0x19, 0xe0, 0x08, 0x4b, 0xa1, 0x1c, 0x22, 0x40, 0x1a, 0x23, 0x80, - 0x04, 0x12, 0x05, 0xdb, 0x43, 0x1a, 0x1c, 0x11, 0x43, 0x01, 0x06, 0x0b, 0x0e, 0x0a, 0x24, 0xff, - 0x02, 0x24, 0x43, 0x1a, 0x1c, 0x0b, 0x40, 0x23, 0x02, 0x1b, 0x20, 0xff, 0x04, 0x00, 0x43, 0x1a, - 0x1c, 0x0b, 0x40, 0x03, 0x4d, 0x91, 0x0a, 0x1b, 0x43, 0x1a, 0x23, 0x40, 0x60, 0xab, 0x4b, 0x95, - 0x60, 0x6a, 0x68, 0x1b, 0x6c, 0x5a, 0x1c, 0x11, 0x1c, 0x13, 0x40, 0x21, 0x40, 0x03, 0x0a, 0x1b, - 0x02, 0x09, 0x43, 0x19, 0x0e, 0x13, 0x43, 0x19, 0x23, 0xe0, 0x40, 0x1a, 0x23, 0x02, 0x43, 0x1a, - 0x06, 0x12, 0x43, 0x11, 0x60, 0x29, 0x6b, 0x72, 0x06, 0x13, 0x0e, 0x11, 0x43, 0x19, 0x1c, 0x13, - 0x40, 0x23, 0x02, 0x1b, 0x40, 0x02, 0x43, 0x19, 0x0a, 0x12, 0x23, 0x80, 0x43, 0x11, 0x04, 0x5b, - 0x61, 0x29, 0x61, 0x6b, 0x7e, 0x3a, 0x2a, 0x00, 0xd0, 0x17, 0x9b, 0x01, 0x6a, 0x58, 0x06, 0x13, - 0x2b, 0x00, 0xdb, 0x01, 0x21, 0x00, 0xe0, 0x00, 0x21, 0x10, 0x23, 0x0f, 0x40, 0x13, 0x18, 0xcb, - 0x40, 0xd8, 0x1c, 0x03, 0x49, 0x75, 0x07, 0xd8, 0xd5, 0x03, 0x69, 0x8b, 0x22, 0x80, 0x43, 0x13, - 0xe0, 0x02, 0x69, 0x8b, 0x22, 0x80, 0x43, 0x93, 0x61, 0x8b, 0x4b, 0x70, 0x49, 0x76, 0x69, 0x9a, - 0x6c, 0x9e, 0x40, 0x0a, 0x61, 0x9a, 0xe0, 0x04, 0x1c, 0x30, 0x21, 0x60, 0xf0, 0x02, 0xfb, 0xca, - 0x6b, 0xb6, 0x2e, 0x00, 0xd1, 0xf8, 0x4d, 0x69, 0x98, 0x02, 0x1c, 0x29, 0x22, 0x60, 0xf0, 0x02, - 0xfd, 0x03, 0x4a, 0x6e, 0x23, 0x01, 0x92, 0x00, 0x60, 0x13, 0x4b, 0x6d, 0x48, 0x6d, 0x68, 0x19, - 0xf7, 0xfe, 0xfd, 0x88, 0x4c, 0x5e, 0x21, 0x20, 0x68, 0x23, 0x69, 0x98, 0xf0, 0x02, 0xfb, 0x9a, - 0x68, 0x23, 0x6c, 0x69, 0x69, 0x98, 0x23, 0xff, 0x02, 0x1b, 0x1c, 0x0a, 0x40, 0x1a, 0x23, 0xff, - 0x04, 0x1b, 0x40, 0x0b, 0x0a, 0x1b, 0x02, 0x12, 0x43, 0x1a, 0x0e, 0x0b, 0x43, 0x1a, 0x23, 0xe0, - 0x40, 0x19, 0x23, 0x02, 0x43, 0x19, 0x06, 0x09, 0x43, 0x0a, 0x60, 0x02, 0x68, 0x23, 0x21, 0x20, - 0x69, 0x98, 0xf0, 0x02, 0xfb, 0x97, 0xf7, 0xff, 0xfd, 0xeb, 0xf7, 0xfe, 0xfd, 0x2b, 0x9b, 0x00, - 0x90, 0x03, 0x60, 0x1e, 0x28, 0x00, 0xd1, 0x03, 0x4b, 0x48, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x0f, - 0x4b, 0x47, 0x68, 0x1b, 0x68, 0x9a, 0x4b, 0x54, 0x32, 0x44, 0x68, 0x1b, 0x00, 0x9b, 0x18, 0xd2, - 0x68, 0x13, 0x22, 0x05, 0x40, 0x13, 0x2b, 0x05, 0xd0, 0x02, 0x4a, 0x40, 0x23, 0x01, 0x60, 0x13, - 0x98, 0x03, 0x42, 0x46, 0x41, 0x46, 0x2e, 0x00, 0xd1, 0x01, 0x30, 0x05, 0xd1, 0x4f, 0xf7, 0xff, - 0xfd, 0xe1, 0x4c, 0x3b, 0x21, 0x20, 0x68, 0x23, 0x69, 0x98, 0xf7, 0xfd, 0xff, 0x4d, 0x68, 0x23, - 0x21, 0x20, 0x69, 0x98, 0xf0, 0x02, 0xfb, 0x1e, 0x4b, 0x3e, 0x68, 0x1b, 0x6c, 0x59, 0x68, 0x23, - 0x1c, 0x0a, 0x69, 0x98, 0x23, 0xff, 0x02, 0x1b, 0x40, 0x1a, 0x23, 0xff, 0x04, 0x1b, 0x40, 0x0b, - 0x0a, 0x1b, 0x02, 0x12, 0x43, 0x1a, 0x0e, 0x0b, 0x43, 0x1a, 0x23, 0xe0, 0x40, 0x19, 0x23, 0x02, - 0x43, 0x19, 0x06, 0x09, 0x43, 0x0a, 0x60, 0x02, 0x68, 0x23, 0x21, 0x20, 0x69, 0x98, 0xf7, 0xfd, - 0xff, 0x4b, 0xf7, 0xff, 0xfd, 0x9d, 0x7e, 0x3a, 0x2a, 0x00, 0xd1, 0x00, 0xe0, 0x9f, 0x9b, 0x01, - 0x1c, 0x14, 0x6a, 0x5d, 0x23, 0x0f, 0x40, 0x1c, 0x06, 0x13, 0x2b, 0x00, 0xdb, 0x01, 0x20, 0x00, - 0xe0, 0x00, 0x20, 0x10, 0x4b, 0x2d, 0x68, 0x19, 0x06, 0x13, 0x2b, 0x00, 0xdb, 0x01, 0x22, 0x00, - 0xe0, 0x00, 0x22, 0x10, 0x09, 0xcb, 0x21, 0x01, 0x40, 0x0b, 0x19, 0x12, 0x40, 0x93, 0x19, 0x02, - 0x40, 0x91, 0x1c, 0x2a, 0x43, 0x8a, 0x98, 0x01, 0x43, 0x13, 0x62, 0x43, 0xe0, 0x7f, 0xf7, 0xff, - 0xfd, 0x91, 0x4b, 0x16, 0x6c, 0x9c, 0xe0, 0x04, 0x6b, 0x60, 0x21, 0x60, 0xf0, 0x02, 0xfb, 0x02, - 0x6b, 0xa4, 0x2c, 0x00, 0xd1, 0xf8, 0x22, 0x20, 0x48, 0x10, 0x99, 0x02, 0xf0, 0x02, 0xfc, 0x44, - 0x7e, 0x3a, 0x2a, 0x00, 0xd0, 0x41, 0x9b, 0x01, 0x1c, 0x14, 0x6a, 0x5d, 0x23, 0x0f, 0x40, 0x1c, - 0x06, 0x13, 0x2b, 0x00, 0xdb, 0x01, 0x20, 0x00, 0xe0, 0x00, 0x20, 0x10, 0x4b, 0x07, 0x69, 0x99, - 0x06, 0x13, 0x2b, 0x00, 0xdb, 0x24, 0x22, 0x00, 0xe0, 0x23, 0x46, 0xc0, 0x13, 0x70, 0x67, 0x6c, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x7c, 0x13, 0x70, 0x67, 0x80, 0x13, 0x72, 0xc1, 0x80, - 0x13, 0x70, 0x67, 0x8c, 0x13, 0x70, 0x67, 0x70, 0x13, 0x70, 0x67, 0x88, 0x40, 0x40, 0x40, 0x00, - 0x00, 0x00, 0x07, 0xff, 0x13, 0x70, 0x67, 0x84, 0x01, 0x00, 0x00, 0x80, 0x13, 0x70, 0x67, 0x74, - 0x13, 0x70, 0x60, 0x38, 0x13, 0x70, 0x48, 0x25, 0x13, 0x70, 0x67, 0x78, 0x13, 0x70, 0x67, 0x90, - 0x22, 0x10, 0x09, 0xcb, 0x21, 0x01, 0x40, 0x0b, 0x19, 0x12, 0x40, 0x93, 0x19, 0x02, 0x40, 0x91, - 0x1c, 0x2a, 0x43, 0x8a, 0x98, 0x01, 0x43, 0x13, 0x62, 0x43, 0x4c, 0x25, 0x21, 0x20, 0x68, 0x23, - 0x69, 0x98, 0xf7, 0xfd, 0xfe, 0xa9, 0x68, 0x23, 0x21, 0x20, 0x69, 0x98, 0xf0, 0x02, 0xfa, 0x7a, - 0x4b, 0x20, 0x68, 0x1b, 0x6c, 0x59, 0x68, 0x23, 0x1c, 0x0a, 0x69, 0x98, 0x23, 0xff, 0x02, 0x1b, - 0x40, 0x1a, 0x23, 0xff, 0x04, 0x1b, 0x40, 0x0b, 0x0a, 0x1b, 0x02, 0x12, 0x43, 0x1a, 0x0e, 0x0b, - 0x43, 0x1a, 0x23, 0xe0, 0x40, 0x19, 0x23, 0x02, 0x43, 0x19, 0x06, 0x09, 0x43, 0x0a, 0x60, 0x02, - 0x68, 0x23, 0x21, 0x20, 0x69, 0x98, 0xf7, 0xfd, 0xfe, 0xa7, 0xf7, 0xff, 0xfc, 0xf9, 0x49, 0x12, - 0x20, 0x01, 0xf7, 0xff, 0xfd, 0x29, 0x69, 0x39, 0x29, 0x00, 0xd0, 0x08, 0x7e, 0x7b, 0x68, 0xf8, - 0x2b, 0x00, 0xd0, 0x02, 0xf0, 0x02, 0xfa, 0x8e, 0xe0, 0x01, 0xf0, 0x02, 0xfa, 0x83, 0x7e, 0x3b, - 0x2b, 0x00, 0xd1, 0x03, 0x68, 0x78, 0x21, 0x08, 0xf0, 0x02, 0xfa, 0x84, 0x2e, 0x00, 0xd0, 0x01, - 0x69, 0x7f, 0x97, 0x03, 0x98, 0x03, 0xb0, 0x05, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x84, 0x13, 0x72, 0xc1, 0x80, 0xb5, 0x30, 0xb0, 0x89, - 0x46, 0x6d, 0x76, 0x29, 0x09, 0xc9, 0x76, 0x69, 0x21, 0x80, 0x00, 0x89, 0x91, 0x07, 0x24, 0x00, - 0x46, 0x69, 0x94, 0x00, 0x92, 0x04, 0x93, 0x02, 0xf7, 0xff, 0xfd, 0xe0, 0xb0, 0x09, 0xbc, 0x30, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0xf0, 0xb0, 0x83, 0x1c, 0x04, 0x91, 0x01, 0x92, 0x00, 0x34, 0xa0, - 0x1c, 0x07, 0x21, 0xff, 0x22, 0x0d, 0x68, 0x20, 0xf0, 0x03, 0xf9, 0xf4, 0x1c, 0x3b, 0x33, 0x90, - 0x68, 0x18, 0x7b, 0x39, 0x68, 0x23, 0x22, 0x0d, 0xf7, 0xff, 0xff, 0xd8, 0x28, 0x00, 0xdb, 0x4e, - 0x28, 0x0d, 0xd0, 0x01, 0x48, 0x28, 0xe0, 0x4a, 0x68, 0x23, 0x24, 0xff, 0x68, 0x19, 0x68, 0x5e, - 0x68, 0x9d, 0x7b, 0x1b, 0x0e, 0x0a, 0x46, 0x9c, 0x06, 0x0b, 0x43, 0x1a, 0x02, 0x24, 0x1c, 0x0b, - 0x20, 0xff, 0x40, 0x23, 0x04, 0x00, 0x02, 0x1b, 0x40, 0x01, 0x43, 0x1a, 0x0a, 0x09, 0x4b, 0x1f, - 0x43, 0x0a, 0x42, 0x9a, 0xd0, 0x01, 0x48, 0x1e, 0xe0, 0x31, 0x9a, 0x00, 0x2a, 0x00, 0xd0, 0x0c, - 0x06, 0x2b, 0x0e, 0x2a, 0x43, 0x1a, 0x1c, 0x2b, 0x40, 0x23, 0x02, 0x1b, 0x43, 0x1a, 0x1c, 0x2b, - 0x40, 0x03, 0x0a, 0x1b, 0x43, 0x1a, 0x9b, 0x00, 0x60, 0x1a, 0x9a, 0x01, 0x2a, 0x00, 0xd0, 0x01, - 0x46, 0x63, 0x70, 0x13, 0x06, 0x33, 0x0e, 0x32, 0x43, 0x1a, 0x23, 0xff, 0x02, 0x1b, 0x40, 0x33, - 0x02, 0x1b, 0x43, 0x1a, 0x23, 0xff, 0x04, 0x1b, 0x40, 0x33, 0x1c, 0x38, 0x0a, 0x1b, 0x1c, 0x11, - 0x30, 0x98, 0x43, 0x19, 0x68, 0x03, 0x42, 0x99, 0xd0, 0x01, 0x48, 0x0a, 0xe0, 0x07, 0x4a, 0x0a, - 0x1c, 0x8b, 0x40, 0x13, 0x4a, 0x09, 0x40, 0x0a, 0x43, 0x13, 0x60, 0x03, 0x20, 0x00, 0xb0, 0x03, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0xff, 0xff, 0xd8, 0xed, 0x53, 0x42, 0x53, 0x55, - 0xff, 0xff, 0xd8, 0xec, 0xff, 0xff, 0xd8, 0xeb, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, - 0xb5, 0xf0, 0xb0, 0x85, 0x93, 0x02, 0x46, 0x6b, 0x33, 0x2f, 0x78, 0x1b, 0x1c, 0x05, 0x93, 0x01, - 0x3b, 0x01, 0x06, 0x1b, 0x0e, 0x1b, 0x91, 0x03, 0x1c, 0x17, 0x2b, 0x0f, 0xd8, 0x5e, 0x1c, 0x06, - 0x36, 0xa0, 0x68, 0x30, 0x28, 0x00, 0xd0, 0x59, 0x21, 0x00, 0x22, 0x1f, 0xf0, 0x03, 0xf9, 0x72, - 0x68, 0x32, 0x4b, 0x2d, 0x24, 0xff, 0x60, 0x13, 0x1c, 0x2b, 0x33, 0x98, 0x68, 0x1a, 0x68, 0x31, - 0x06, 0x13, 0x46, 0x8c, 0x0e, 0x11, 0x43, 0x19, 0x02, 0x24, 0x1c, 0x13, 0x20, 0xff, 0x04, 0x00, - 0x40, 0x23, 0x02, 0x1b, 0x40, 0x02, 0x43, 0x19, 0x0a, 0x12, 0x43, 0x11, 0x46, 0x62, 0x60, 0x51, - 0x06, 0x3b, 0x0e, 0x3a, 0x43, 0x1a, 0x1c, 0x3b, 0x40, 0x23, 0x02, 0x1b, 0x43, 0x1a, 0x1c, 0x3b, - 0x40, 0x03, 0x68, 0x31, 0x0a, 0x1b, 0x43, 0x1a, 0x60, 0x8a, 0x22, 0x0b, 0x46, 0x69, 0x5c, 0x51, - 0x68, 0x33, 0x46, 0x6a, 0x73, 0x19, 0x21, 0x0f, 0x68, 0x33, 0x5c, 0x8a, 0x73, 0x5a, 0x1c, 0x2b, - 0x33, 0x9c, 0x78, 0x1b, 0x68, 0x31, 0x2b, 0x00, 0xd0, 0x01, 0x23, 0x0c, 0xe0, 0x05, 0x9b, 0x01, - 0x2b, 0x06, 0xd8, 0x01, 0x23, 0x06, 0xe0, 0x00, 0x23, 0x10, 0x1c, 0x2c, 0x73, 0x8b, 0x34, 0xa0, - 0x68, 0x20, 0x99, 0x0a, 0x9a, 0x01, 0x30, 0x0f, 0xf0, 0x03, 0xf8, 0xe8, 0x1c, 0x2b, 0x33, 0x90, - 0x68, 0x18, 0x7b, 0x69, 0x68, 0x23, 0x22, 0x1f, 0xf7, 0xff, 0xff, 0x10, 0x28, 0x1f, 0xd1, 0x01, - 0x20, 0x00, 0xe0, 0x05, 0x28, 0x00, 0xdb, 0x03, 0x48, 0x04, 0xe0, 0x01, 0x20, 0x03, 0x42, 0x40, - 0xb0, 0x05, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x55, 0x53, 0x42, 0x43, 0xff, 0xff, 0xd8, 0xee, - 0xb5, 0xf0, 0xb0, 0x8b, 0x90, 0x01, 0x46, 0x68, 0x30, 0x42, 0x88, 0x04, 0x30, 0x04, 0x88, 0x05, - 0x48, 0x27, 0x9f, 0x12, 0x68, 0x00, 0x04, 0x24, 0x30, 0xf8, 0x68, 0x00, 0x04, 0x2d, 0x70, 0x42, - 0x02, 0x1a, 0x0a, 0x1b, 0x43, 0x1a, 0x04, 0x12, 0x0c, 0x13, 0x70, 0xc3, 0x0a, 0x23, 0x0e, 0x24, - 0x43, 0x23, 0x0e, 0x12, 0x04, 0x1b, 0x70, 0x82, 0x0c, 0x2e, 0x0c, 0x1a, 0x0e, 0x1b, 0x71, 0x03, - 0x0e, 0x2d, 0x02, 0x33, 0x43, 0x2b, 0x04, 0x1b, 0x71, 0x42, 0x0e, 0x1a, 0x0c, 0x1b, 0x71, 0xc3, - 0xac, 0x02, 0x23, 0x00, 0x70, 0x01, 0x71, 0x82, 0x76, 0x23, 0x23, 0x40, 0x61, 0xe3, 0x4b, 0x15, - 0x09, 0xc9, 0x90, 0x02, 0x76, 0x61, 0x61, 0x26, 0x42, 0x9f, 0xd9, 0x15, 0x1c, 0x30, 0xf0, 0x02, - 0xf9, 0x09, 0x1c, 0x32, 0x1c, 0x39, 0x60, 0xa0, 0xf0, 0x03, 0xf8, 0x90, 0x1c, 0x21, 0x98, 0x01, - 0xf7, 0xff, 0xfc, 0xac, 0x68, 0xa1, 0x1c, 0x05, 0x1c, 0x32, 0x1c, 0x38, 0xf0, 0x03, 0xf8, 0x86, - 0x68, 0xa0, 0xf0, 0x02, 0xf8, 0xeb, 0xe0, 0x05, 0x60, 0xa7, 0x98, 0x01, 0x1c, 0x21, 0xf7, 0xff, - 0xfc, 0x9d, 0x1c, 0x05, 0xb0, 0x0b, 0x1c, 0x28, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x88, 0x00, 0x00, 0xb5, 0x00, 0xb0, 0x85, 0x91, 0x00, 0x23, 0x00, - 0x21, 0x02, 0x22, 0x01, 0x93, 0x01, 0x93, 0x02, 0xf7, 0xff, 0xff, 0x9a, 0xb0, 0x05, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0xb5, 0x00, 0xb0, 0x85, 0x2a, 0x00, 0xd1, 0x02, 0x20, 0x03, 0x42, 0x40, - 0xe0, 0x08, 0x1c, 0x13, 0x22, 0x00, 0x91, 0x00, 0x92, 0x01, 0x92, 0x02, 0x21, 0x01, 0x22, 0x0b, - 0xf7, 0xff, 0xff, 0x86, 0xb0, 0x05, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0xb5, 0x00, 0xb0, 0x85, - 0x22, 0x00, 0x92, 0x00, 0x92, 0x01, 0x92, 0x02, 0x1c, 0x0b, 0x22, 0x09, 0x21, 0x00, 0xf7, 0xff, - 0xff, 0x77, 0xb0, 0x05, 0xbc, 0x02, 0x47, 0x08, 0xb5, 0x70, 0xb0, 0x84, 0x1c, 0x04, 0x20, 0x01, - 0x1c, 0x0e, 0xf0, 0x02, 0xf8, 0xaf, 0x1c, 0x05, 0x28, 0x00, 0xd1, 0x02, 0x24, 0x04, 0x42, 0x64, - 0xe0, 0x12, 0x23, 0x00, 0x93, 0x00, 0x23, 0x01, 0x93, 0x01, 0x90, 0x02, 0x21, 0x80, 0x1c, 0x20, - 0x22, 0x08, 0x23, 0x00, 0xf7, 0xff, 0xff, 0x5c, 0x1c, 0x04, 0x28, 0x00, 0xdb, 0x01, 0x78, 0x2b, - 0x70, 0x33, 0x1c, 0x28, 0xf0, 0x02, 0xf8, 0x8a, 0xb0, 0x04, 0x1c, 0x20, 0xbc, 0x70, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0xb5, 0xf0, 0x4b, 0x4c, 0x4a, 0x4c, 0x78, 0x19, 0xb0, 0x87, 0x1c, 0x06, - 0x68, 0x17, 0x29, 0x00, 0xd0, 0x01, 0x4b, 0x4a, 0xe0, 0x00, 0x4b, 0x4a, 0x60, 0x13, 0x4b, 0x4a, - 0x68, 0x1b, 0x68, 0x9a, 0x1c, 0x33, 0x33, 0x90, 0x68, 0x1b, 0x32, 0x44, 0x69, 0xdb, 0x00, 0x9b, - 0x18, 0xd2, 0x68, 0x13, 0x22, 0x01, 0x42, 0x13, 0xd1, 0x06, 0x4b, 0x44, 0x24, 0x01, 0x60, 0x1a, - 0x4b, 0x3e, 0x42, 0x64, 0x60, 0x1f, 0xe0, 0x72, 0x4a, 0x3c, 0x29, 0x00, 0xd0, 0x01, 0x4b, 0x3c, - 0xe0, 0x00, 0x4b, 0x3c, 0x60, 0x13, 0x4b, 0x3e, 0x1c, 0x35, 0x78, 0x1b, 0x35, 0x90, 0x2b, 0x00, - 0xd0, 0x12, 0x88, 0xf3, 0x68, 0x28, 0x22, 0xff, 0x93, 0x00, 0x21, 0x21, 0x23, 0x00, 0x93, 0x01, - 0x93, 0x02, 0xf7, 0xff, 0xff, 0x15, 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x36, 0xf7, 0xff, 0xfa, 0x12, - 0x20, 0x3c, 0xf7, 0xfe, 0xfc, 0x39, 0xe0, 0x07, 0x21, 0x00, 0x68, 0x28, 0xf7, 0xff, 0xff, 0x64, - 0x20, 0x05, 0xf7, 0xfe, 0xfc, 0x31, 0x24, 0x00, 0x4b, 0x27, 0x4a, 0x28, 0x78, 0x1b, 0x2b, 0x00, - 0xd0, 0x01, 0x4b, 0x27, 0xe0, 0x00, 0x4b, 0x27, 0x1c, 0x35, 0x60, 0x13, 0x35, 0x90, 0x2c, 0x00, - 0xda, 0x0a, 0x20, 0x32, 0xf7, 0xfe, 0xfc, 0x20, 0x68, 0x28, 0x21, 0x00, 0xf7, 0xff, 0xff, 0x4c, - 0x20, 0x05, 0xf7, 0xfe, 0xfc, 0x19, 0xe0, 0x2d, 0x7b, 0x31, 0x68, 0x28, 0xf7, 0xff, 0xff, 0x44, - 0x1c, 0x04, 0x20, 0x05, 0xf7, 0xfe, 0xfc, 0x10, 0x48, 0x1f, 0x1c, 0x21, 0xf7, 0xff, 0xf9, 0xe2, - 0x2c, 0x00, 0xdb, 0x1f, 0x7b, 0x71, 0x68, 0x28, 0xf7, 0xff, 0xff, 0x36, 0x1c, 0x04, 0x20, 0x05, - 0xf7, 0xfe, 0xfc, 0x02, 0x48, 0x19, 0x1c, 0x21, 0xf7, 0xff, 0xf9, 0xd4, 0x2c, 0x00, 0xdb, 0x11, - 0x20, 0x0a, 0xf7, 0xfe, 0xfb, 0xf9, 0x46, 0x69, 0x31, 0x17, 0x68, 0x28, 0xf7, 0xff, 0xff, 0x54, - 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x12, 0xf7, 0xff, 0xf9, 0xc5, 0x2c, 0x00, 0xdb, 0x02, 0x4b, 0x07, - 0x60, 0x1f, 0xe0, 0x04, 0x4b, 0x05, 0x4a, 0x09, 0x60, 0x1f, 0x23, 0x01, 0x60, 0x13, 0xb0, 0x07, - 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x01, 0x0f, 0x13, 0x70, 0x60, 0x38, - 0x00, 0x0f, 0x42, 0x40, 0x00, 0x03, 0x0d, 0x40, 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x6c, - 0x13, 0x70, 0x01, 0x0d, 0x13, 0x70, 0x61, 0x12, 0x13, 0x70, 0x61, 0x33, 0x13, 0x70, 0x61, 0x5a, - 0x13, 0x70, 0x61, 0x82, 0xb5, 0x00, 0xb0, 0x81, 0x21, 0x00, 0xf7, 0xff, 0xff, 0x4b, 0xb0, 0x01, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0xf0, 0xb0, 0x8d, 0x1c, 0x1e, 0x46, 0x6b, 0x33, 0x5f, 0x92, 0x07, - 0x78, 0x1a, 0x3b, 0x10, 0x78, 0x1b, 0x06, 0x12, 0x93, 0x06, 0x46, 0x6b, 0x33, 0x53, 0x78, 0x1b, - 0x16, 0x12, 0x93, 0x05, 0x46, 0x6b, 0x92, 0x04, 0x33, 0x2f, 0x22, 0x00, 0x91, 0x08, 0x70, 0x1a, - 0x4b, 0x99, 0x92, 0x0a, 0x60, 0x1a, 0x4a, 0x99, 0x4b, 0x99, 0x24, 0x00, 0x1c, 0x05, 0x94, 0x09, - 0x92, 0x03, 0x93, 0x02, 0x1c, 0xa3, 0x2b, 0x01, 0xd8, 0x00, 0xe1, 0x08, 0x2c, 0x00, 0xd0, 0x22, - 0x1c, 0x28, 0x21, 0x00, 0xf7, 0xff, 0xff, 0x1e, 0x1c, 0x04, 0x28, 0x00, 0xdb, 0x01, 0x20, 0x05, - 0xe0, 0x00, 0x20, 0x3c, 0xf7, 0xfe, 0xfb, 0x90, 0x4b, 0x8e, 0x68, 0x1b, 0x68, 0x9a, 0x4b, 0x8e, - 0x32, 0x44, 0x68, 0x1b, 0x00, 0x9b, 0x18, 0xd2, 0x68, 0x12, 0x2c, 0x00, 0xda, 0x09, 0x9a, 0x09, - 0x32, 0x01, 0x92, 0x09, 0x2a, 0x02, 0xdd, 0x00, 0xe0, 0xeb, 0x20, 0x0a, 0xf7, 0xfe, 0xfb, 0x7c, - 0xe0, 0xdf, 0x23, 0x00, 0x93, 0x09, 0x9b, 0x04, 0x9a, 0x05, 0x3b, 0x01, 0x06, 0x1b, 0x16, 0x1b, - 0x93, 0x04, 0x2a, 0x00, 0xd0, 0x31, 0x9b, 0x03, 0x9a, 0x02, 0x68, 0x1f, 0x78, 0x13, 0x2b, 0x00, - 0xd0, 0x01, 0x4b, 0x7e, 0xe0, 0x00, 0x4b, 0x7e, 0x9a, 0x03, 0x1c, 0x28, 0x60, 0x13, 0x9b, 0x12, - 0x9a, 0x06, 0x93, 0x00, 0x92, 0x01, 0x23, 0x00, 0x99, 0x08, 0x1c, 0x32, 0xf7, 0xff, 0xfd, 0xb8, - 0x4b, 0x72, 0x1c, 0x04, 0x60, 0x1f, 0x1c, 0x83, 0x2b, 0x01, 0xd8, 0x00, 0xe0, 0xbf, 0x28, 0x00, - 0xda, 0x0d, 0xe0, 0xb8, 0x1c, 0x2b, 0x33, 0x90, 0x68, 0x18, 0x7b, 0x69, 0x9b, 0x07, 0x1c, 0x32, - 0xf7, 0xff, 0xfd, 0x1c, 0x1c, 0x83, 0x1c, 0x04, 0x2b, 0x01, 0xd8, 0x43, 0xe0, 0x02, 0x2e, 0x00, - 0xd1, 0xf0, 0xe0, 0x49, 0x28, 0x00, 0xda, 0x47, 0xe0, 0xa3, 0x9b, 0x03, 0x9a, 0x02, 0x68, 0x1f, - 0x78, 0x13, 0x2b, 0x00, 0xd0, 0x01, 0x4b, 0x65, 0xe0, 0x00, 0x4b, 0x65, 0x9a, 0x03, 0x1c, 0x28, - 0x60, 0x13, 0x9b, 0x12, 0x9a, 0x06, 0x93, 0x00, 0x92, 0x01, 0x23, 0x80, 0x99, 0x08, 0x1c, 0x32, - 0xf7, 0xff, 0xfd, 0x86, 0x4b, 0x59, 0x1c, 0x04, 0x60, 0x1f, 0x28, 0x00, 0xda, 0x06, 0x48, 0x5d, - 0x1c, 0x21, 0xf7, 0xff, 0xf8, 0xf7, 0x48, 0x5c, 0xf7, 0xff, 0xf9, 0x3c, 0x1c, 0xa3, 0x2b, 0x01, - 0xd8, 0x00, 0xe0, 0x84, 0x2c, 0x00, 0xda, 0x1a, 0xe0, 0x7d, 0x1c, 0x2b, 0x33, 0x90, 0x68, 0x18, - 0x7b, 0x29, 0x1c, 0x32, 0x9b, 0x07, 0xf7, 0xff, 0xfc, 0xe1, 0x1c, 0x04, 0x28, 0x00, 0xda, 0x06, - 0x48, 0x52, 0x1c, 0x21, 0xf7, 0xff, 0xf8, 0xde, 0x48, 0x51, 0xf7, 0xff, 0xf9, 0x23, 0x1c, 0xa3, - 0x2b, 0x01, 0xd9, 0x07, 0x2c, 0x00, 0xdb, 0x62, 0x42, 0xb4, 0xd0, 0x05, 0xe0, 0x5f, 0x2e, 0x00, - 0xd1, 0xe3, 0xe0, 0x01, 0x2c, 0x00, 0xdb, 0x5e, 0x4b, 0x41, 0x4a, 0x40, 0x78, 0x1b, 0x68, 0x17, - 0x2b, 0x00, 0xd0, 0x01, 0x4b, 0x41, 0xe0, 0x00, 0x4b, 0x41, 0x46, 0x69, 0x60, 0x13, 0x1c, 0x28, - 0x31, 0x2f, 0xaa, 0x0a, 0xf7, 0xff, 0xfc, 0xce, 0x1c, 0x04, 0x28, 0x00, 0xda, 0x28, 0x48, 0x41, - 0x1c, 0x21, 0xf7, 0xff, 0xf8, 0xb7, 0x48, 0x40, 0xf7, 0xff, 0xf8, 0xfc, 0x1c, 0x63, 0xd1, 0x02, - 0x4b, 0x32, 0x60, 0x1f, 0xe0, 0x45, 0x1c, 0x2c, 0x34, 0x90, 0x68, 0x20, 0x7b, 0x29, 0xf7, 0xff, - 0xfe, 0x03, 0x7b, 0x2a, 0x68, 0x24, 0x06, 0x13, 0x6a, 0x60, 0x2b, 0x00, 0xdb, 0x01, 0x21, 0x00, - 0xe0, 0x00, 0x21, 0x10, 0x23, 0x0f, 0x40, 0x1a, 0x18, 0x8a, 0x23, 0x01, 0x40, 0x93, 0x43, 0x98, - 0x46, 0x69, 0x62, 0x60, 0x31, 0x2f, 0x1c, 0x28, 0xaa, 0x0a, 0xf7, 0xff, 0xfc, 0xa3, 0x1c, 0x04, - 0x4b, 0x22, 0x60, 0x1f, 0x1c, 0xa3, 0x2b, 0x01, 0xd9, 0x21, 0x9b, 0x0a, 0x2b, 0x00, 0xd0, 0x07, - 0x4b, 0x2a, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x03, 0x46, 0x6b, 0x22, 0x01, 0x33, 0x2f, 0x70, 0x1a, - 0x2c, 0x00, 0xdb, 0x10, 0x4b, 0x25, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x06, 0x46, 0x6b, 0x33, 0x2f, - 0x78, 0x1b, 0x2b, 0x00, 0xd0, 0x01, 0x4c, 0x22, 0xe0, 0x05, 0x24, 0x00, 0xe0, 0x0e, 0x4c, 0x21, - 0xe0, 0x01, 0x2c, 0x00, 0xda, 0x0a, 0x9a, 0x04, 0x2a, 0x00, 0xdd, 0x00, 0xe6, 0xf2, 0x2c, 0x00, - 0xda, 0x04, 0x4a, 0x0d, 0x23, 0x01, 0x60, 0x13, 0x2c, 0x00, 0xdb, 0x02, 0x4a, 0x0a, 0x23, 0x00, - 0x60, 0x13, 0x9b, 0x15, 0x2b, 0x00, 0xd0, 0x04, 0x46, 0x6b, 0x33, 0x2f, 0x78, 0x1b, 0x9a, 0x15, - 0x70, 0x13, 0x9b, 0x16, 0x2b, 0x00, 0xd0, 0x02, 0x9b, 0x0a, 0x9a, 0x16, 0x60, 0x13, 0xb0, 0x0d, - 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x67, 0x6c, 0x13, 0x70, 0x60, 0x38, - 0x13, 0x70, 0x01, 0x0f, 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x78, 0x00, 0x0f, 0x42, 0x40, - 0x00, 0x03, 0x0d, 0x40, 0x13, 0x70, 0x61, 0xb1, 0x13, 0x70, 0x61, 0xc4, 0x13, 0x70, 0x61, 0xce, - 0x13, 0x70, 0x61, 0xe6, 0x13, 0x70, 0x61, 0xfa, 0x13, 0x70, 0x62, 0x09, 0x13, 0x70, 0x67, 0xa4, - 0xff, 0xff, 0xd8, 0xea, 0xff, 0xff, 0xd8, 0xe9, 0xb5, 0xf0, 0xb0, 0x8b, 0x1c, 0x0f, 0x21, 0x27, - 0x1c, 0x1d, 0x1c, 0x06, 0x23, 0x00, 0x44, 0x69, 0x46, 0x68, 0x30, 0x1d, 0x70, 0x0b, 0x23, 0x2a, - 0x70, 0x03, 0x21, 0x08, 0x01, 0x7b, 0x43, 0x0b, 0x70, 0x43, 0x0e, 0x13, 0x70, 0x83, 0x0c, 0x13, - 0x70, 0xc3, 0x0a, 0x13, 0x71, 0x03, 0x21, 0x00, 0x0a, 0x2b, 0x71, 0x42, 0x71, 0x81, 0x71, 0xc3, - 0x72, 0x05, 0x72, 0x41, 0x7b, 0xb3, 0x42, 0xbb, 0xd9, 0x24, 0x1d, 0x3b, 0x00, 0x9a, 0x59, 0x93, - 0x2b, 0x00, 0xd0, 0x1f, 0x4c, 0x12, 0x21, 0x01, 0x60, 0x21, 0x59, 0x93, 0x22, 0x0a, 0x92, 0x01, - 0x22, 0x27, 0x44, 0x6a, 0x91, 0x02, 0x92, 0x03, 0x21, 0x00, 0x22, 0x06, 0x90, 0x00, 0x91, 0x04, - 0x92, 0x05, 0x43, 0x6b, 0x9a, 0x10, 0x1c, 0x30, 0x1c, 0x39, 0xf7, 0xff, 0xfe, 0x5b, 0x22, 0x00, - 0x60, 0x22, 0x28, 0x00, 0xdd, 0x08, 0x21, 0x27, 0x44, 0x69, 0x78, 0x0b, 0x2b, 0x00, 0xd0, 0x03, - 0x48, 0x04, 0xe0, 0x01, 0x20, 0x03, 0x42, 0x40, 0xb0, 0x0b, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x67, 0xa4, 0xff, 0xff, 0xd8, 0xea, 0xb5, 0xf0, 0x1c, 0x1c, 0x1c, 0x1f, 0x1c, 0x0b, - 0xb0, 0x87, 0x33, 0x04, 0x90, 0x05, 0x00, 0x9b, 0x91, 0x04, 0x92, 0x03, 0x58, 0x19, 0x20, 0x80, - 0x1c, 0x0b, 0x43, 0x63, 0x02, 0x40, 0x42, 0x83, 0xd9, 0x02, 0xf0, 0x02, 0xfc, 0x9d, 0x1c, 0x07, - 0x9b, 0x04, 0x20, 0x01, 0x33, 0x04, 0x00, 0x9b, 0x42, 0x40, 0x93, 0x02, 0xe0, 0x1c, 0x1c, 0x25, - 0x42, 0xbc, 0xd9, 0x00, 0x1c, 0x3d, 0x04, 0x2b, 0x99, 0x0c, 0x0c, 0x1e, 0x91, 0x00, 0x98, 0x05, - 0x99, 0x04, 0x9a, 0x03, 0x1c, 0x33, 0xf7, 0xff, 0xff, 0x87, 0x28, 0x00, 0xdb, 0x0e, 0x9a, 0x03, - 0x1b, 0xa3, 0x19, 0x52, 0x92, 0x03, 0x99, 0x02, 0x9a, 0x05, 0x04, 0x1b, 0x0c, 0x1c, 0x58, 0x8b, - 0x99, 0x0c, 0x43, 0x6b, 0x18, 0xc9, 0x91, 0x0c, 0x2c, 0x00, 0xd1, 0xe0, 0xb0, 0x07, 0xbc, 0xf0, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0xf0, 0xb0, 0x8b, 0x1c, 0x05, 0x1c, 0x18, 0x23, 0x27, 0x27, 0x00, - 0x1c, 0x0e, 0x44, 0x6b, 0x46, 0x69, 0x31, 0x1d, 0x70, 0x1f, 0x23, 0x28, 0x70, 0x0b, 0x01, 0x73, - 0x70, 0x4b, 0x0e, 0x13, 0x70, 0x8b, 0x0c, 0x13, 0x70, 0xcb, 0x0a, 0x13, 0x71, 0x0b, 0x0a, 0x03, - 0x71, 0x4a, 0x71, 0x8f, 0x71, 0xcb, 0x72, 0x08, 0x72, 0x4f, 0x7b, 0xab, 0x42, 0xb3, 0xd9, 0x22, - 0x1d, 0x33, 0x00, 0x9a, 0x59, 0x53, 0x2b, 0x00, 0xd0, 0x1d, 0x4c, 0x12, 0x23, 0x01, 0x60, 0x23, - 0x59, 0x53, 0x22, 0x0a, 0x92, 0x01, 0x22, 0x27, 0x44, 0x6a, 0x92, 0x03, 0x22, 0x06, 0x43, 0x43, - 0x91, 0x00, 0x92, 0x05, 0x1c, 0x28, 0x1c, 0x31, 0x9a, 0x10, 0x97, 0x02, 0x97, 0x04, 0xf7, 0xff, - 0xfd, 0xd1, 0x60, 0x27, 0x28, 0x00, 0xdd, 0x08, 0x22, 0x27, 0x44, 0x6a, 0x78, 0x13, 0x2b, 0x00, - 0xd0, 0x03, 0x48, 0x05, 0xe0, 0x01, 0x20, 0x03, 0x42, 0x40, 0xb0, 0x0b, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x67, 0xa4, 0xff, 0xff, 0xd8, 0xea, 0xb5, 0xf0, 0x1c, 0x1c, - 0x1c, 0x1f, 0x1c, 0x0b, 0xb0, 0x87, 0x33, 0x04, 0x90, 0x05, 0x00, 0x9b, 0x91, 0x04, 0x92, 0x03, - 0x58, 0x19, 0x20, 0x80, 0x1c, 0x0b, 0x43, 0x63, 0x02, 0x40, 0x42, 0x83, 0xd9, 0x02, 0xf0, 0x02, - 0xfc, 0x13, 0x1c, 0x07, 0x9b, 0x04, 0x20, 0x01, 0x33, 0x04, 0x00, 0x9b, 0x42, 0x40, 0x93, 0x02, - 0xe0, 0x1c, 0x1c, 0x25, 0x42, 0xbc, 0xd9, 0x00, 0x1c, 0x3d, 0x04, 0x2b, 0x99, 0x0c, 0x0c, 0x1e, - 0x91, 0x00, 0x98, 0x05, 0x99, 0x04, 0x9a, 0x03, 0x1c, 0x33, 0xf7, 0xff, 0xff, 0x8b, 0x28, 0x00, - 0xdb, 0x0e, 0x9a, 0x03, 0x1b, 0xa3, 0x19, 0x52, 0x92, 0x03, 0x99, 0x02, 0x9a, 0x05, 0x04, 0x1b, - 0x0c, 0x1c, 0x58, 0x8b, 0x99, 0x0c, 0x43, 0x6b, 0x18, 0xc9, 0x91, 0x0c, 0x2c, 0x00, 0xd1, 0xe0, - 0xb0, 0x07, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0xb5, 0x70, 0x1c, 0x1d, 0x1c, 0x03, 0x33, 0xa0, - 0x1c, 0x16, 0x68, 0x1b, 0x22, 0x80, 0x01, 0x12, 0x18, 0x9c, 0xb0, 0x88, 0x2c, 0x00, 0xd1, 0x02, - 0x20, 0x04, 0x42, 0x40, 0xe0, 0x27, 0x46, 0x6a, 0x32, 0x1e, 0x01, 0x4b, 0x70, 0x53, 0x23, 0x25, - 0x70, 0x13, 0x23, 0x02, 0x93, 0x01, 0x23, 0x00, 0x93, 0x02, 0x93, 0x03, 0x93, 0x04, 0x23, 0x0a, - 0x92, 0x00, 0x93, 0x05, 0x1c, 0x22, 0x23, 0x08, 0xf7, 0xff, 0xfd, 0x5c, 0x28, 0x00, 0xdb, 0x12, - 0xa8, 0x06, 0x1c, 0x21, 0x22, 0x04, 0xf0, 0x02, 0xfc, 0xb9, 0x2d, 0x00, 0xd0, 0x01, 0x9b, 0x06, - 0x60, 0x2b, 0x1d, 0x21, 0xa8, 0x06, 0x22, 0x04, 0xf0, 0x02, 0xfc, 0xb0, 0x2e, 0x00, 0xd0, 0x01, - 0x9b, 0x06, 0x60, 0x33, 0x20, 0x00, 0xb0, 0x08, 0xbc, 0x70, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0xb5, 0xf0, 0xb0, 0x8b, 0x1c, 0x0f, 0x46, 0x69, 0x31, 0x22, 0x23, 0x12, 0x90, 0x07, 0x70, 0x0b, - 0x01, 0x7b, 0x22, 0x00, 0x70, 0x4b, 0x23, 0x24, 0x70, 0x8a, 0x70, 0xca, 0x71, 0x4a, 0x71, 0x0b, - 0x9b, 0x07, 0x22, 0x80, 0x33, 0xa0, 0x68, 0x1b, 0x01, 0x12, 0x18, 0x9c, 0x2c, 0x00, 0xd1, 0x02, - 0x21, 0x04, 0x42, 0x49, 0xe0, 0x2c, 0x25, 0x00, 0x21, 0x00, 0x22, 0x24, 0x1c, 0x20, 0xf0, 0x02, - 0xfc, 0xc9, 0x23, 0x22, 0x44, 0x6b, 0x93, 0x00, 0x22, 0x06, 0x23, 0x0a, 0x26, 0x00, 0x92, 0x01, - 0x93, 0x05, 0x1c, 0x39, 0x98, 0x07, 0x1c, 0x22, 0x23, 0x24, 0x96, 0x02, 0x96, 0x03, 0x96, 0x04, - 0xf7, 0xff, 0xfd, 0x10, 0x1c, 0x01, 0x28, 0x00, 0xdb, 0x08, 0x78, 0x22, 0x23, 0x1f, 0x1c, 0x10, - 0x40, 0x18, 0x28, 0x05, 0xd0, 0x06, 0x28, 0x07, 0xd1, 0x08, 0xe0, 0x03, 0x35, 0x01, 0x2d, 0x02, - 0xd0, 0x06, 0xe7, 0xd9, 0x4a, 0x05, 0x23, 0x01, 0x60, 0x13, 0xe0, 0x01, 0x4b, 0x03, 0x60, 0x1e, - 0xb0, 0x0b, 0x1c, 0x08, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x67, 0x94, - 0xb5, 0xf0, 0xb0, 0x8f, 0x1c, 0x03, 0x90, 0x07, 0x91, 0x06, 0x33, 0xa0, 0x68, 0x1b, 0x21, 0x80, - 0x46, 0x6f, 0x46, 0x6c, 0x01, 0x09, 0x37, 0x37, 0x25, 0x00, 0x34, 0x27, 0x18, 0x5e, 0x70, 0x3d, - 0x1c, 0x20, 0x21, 0x00, 0x22, 0x10, 0xf0, 0x02, 0xfc, 0x85, 0x2e, 0x00, 0xd1, 0x02, 0x25, 0x04, - 0x42, 0x6d, 0xe0, 0x5a, 0x23, 0x06, 0x70, 0x25, 0x93, 0x01, 0x23, 0x01, 0x93, 0x02, 0x23, 0x0a, - 0x93, 0x05, 0x99, 0x06, 0x22, 0x00, 0x98, 0x07, 0x23, 0x00, 0x95, 0x04, 0x94, 0x00, 0x97, 0x03, - 0xf7, 0xff, 0xfc, 0xc8, 0x1c, 0x05, 0x1c, 0x29, 0x48, 0x26, 0xf7, 0xfe, 0xfe, 0x5b, 0x1c, 0x6a, - 0xd0, 0x43, 0x78, 0x3b, 0x2b, 0x00, 0xd1, 0x01, 0x2d, 0x00, 0xda, 0x3e, 0x46, 0x6a, 0x32, 0x27, - 0x23, 0x03, 0x70, 0x13, 0x99, 0x06, 0x1c, 0x30, 0x01, 0x4b, 0x70, 0x53, 0x23, 0x12, 0x71, 0x13, - 0x23, 0x00, 0x71, 0x53, 0x21, 0x00, 0x22, 0x12, 0xf0, 0x02, 0xfc, 0x54, 0x4a, 0x1a, 0x35, 0x02, - 0xd1, 0x01, 0x4b, 0x1a, 0xe0, 0x00, 0x4b, 0x1a, 0x60, 0x13, 0x46, 0x6b, 0x33, 0x27, 0x93, 0x00, - 0x23, 0x06, 0x93, 0x01, 0x23, 0x00, 0x93, 0x02, 0x93, 0x03, 0x93, 0x04, 0x23, 0x0a, 0x93, 0x05, - 0x99, 0x06, 0x98, 0x07, 0x1c, 0x32, 0x23, 0x12, 0xf7, 0xff, 0xfc, 0x94, 0x1c, 0x05, 0x1c, 0x29, - 0x48, 0x10, 0xf7, 0xfe, 0xfe, 0x27, 0x2d, 0x00, 0xdb, 0x0f, 0x78, 0xb1, 0x23, 0x0f, 0x46, 0x6c, - 0x40, 0x19, 0x34, 0x37, 0x48, 0x0c, 0x70, 0x21, 0xf7, 0xfe, 0xfe, 0x1c, 0x78, 0x23, 0x3b, 0x02, - 0x06, 0x1b, 0x0e, 0x1b, 0x2b, 0x02, 0xd8, 0x00, 0x4d, 0x08, 0xb0, 0x0f, 0x1c, 0x28, 0xbc, 0xf0, - 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x62, 0x14, 0x13, 0x70, 0x60, 0x38, 0x00, 0x26, 0x25, 0xa0, - 0x00, 0x98, 0x96, 0x80, 0x13, 0x70, 0x62, 0x35, 0x13, 0x70, 0x62, 0x54, 0xff, 0xff, 0xd8, 0xef, - 0xb5, 0xf0, 0x7b, 0x83, 0x1c, 0x0f, 0xb0, 0x81, 0x1c, 0x06, 0x42, 0xbb, 0xd8, 0x02, 0x24, 0x03, - 0x42, 0x64, 0xe0, 0x3a, 0x4d, 0x1f, 0x4b, 0x20, 0x48, 0x20, 0x60, 0x2b, 0x21, 0x00, 0xf7, 0xfe, - 0xfd, 0xf1, 0x4b, 0x1f, 0x1c, 0x30, 0x60, 0x2b, 0x1c, 0x39, 0xf7, 0xff, 0xff, 0x61, 0x1c, 0x04, - 0x28, 0x00, 0xdb, 0x27, 0x4b, 0x18, 0x1c, 0x39, 0x60, 0x2b, 0x1c, 0x30, 0xf7, 0xff, 0xff, 0x08, - 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x17, 0xf7, 0xfe, 0xfd, 0xdd, 0x2c, 0x00, 0xdb, 0x1a, 0x1c, 0x33, - 0x33, 0xa0, 0x68, 0x1a, 0x23, 0x80, 0x01, 0x1b, 0x5c, 0xd1, 0x23, 0x1f, 0x40, 0x19, 0x48, 0x12, - 0xf7, 0xfe, 0xfd, 0xd0, 0x1c, 0x3b, 0x1d, 0x3a, 0x33, 0x14, 0x00, 0x92, 0x00, 0x9b, 0x1c, 0x39, - 0x18, 0xb2, 0x18, 0xf3, 0x1c, 0x30, 0xf7, 0xff, 0xfe, 0xaf, 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x0b, - 0xf7, 0xfe, 0xfd, 0xc0, 0x4a, 0x03, 0x4b, 0x04, 0x60, 0x13, 0xb0, 0x01, 0x1c, 0x20, 0xbc, 0xf0, - 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x38, 0x00, 0x0f, 0x42, 0x40, 0x13, 0x70, 0x62, 0x76, - 0x01, 0x31, 0x2d, 0x00, 0x13, 0x70, 0x62, 0x91, 0x13, 0x70, 0x62, 0xa5, 0x13, 0x70, 0x62, 0xba, - 0xb5, 0x10, 0xb0, 0x84, 0x1c, 0x14, 0x46, 0x6a, 0x32, 0x1b, 0x78, 0x12, 0x02, 0x24, 0x43, 0x1c, - 0x23, 0x00, 0x93, 0x00, 0x92, 0x01, 0x91, 0x02, 0x22, 0x06, 0x21, 0x80, 0x1c, 0x23, 0xf7, 0xff, - 0xfa, 0x97, 0xb0, 0x04, 0xbc, 0x10, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0xb5, 0xf0, 0xb0, 0x8f, - 0x90, 0x03, 0x20, 0x16, 0x1c, 0x0f, 0xf0, 0x01, 0xfb, 0xcd, 0x90, 0x05, 0x28, 0x00, 0xd1, 0x00, - 0xe1, 0x7e, 0x23, 0x12, 0x93, 0x00, 0x98, 0x03, 0x99, 0x05, 0x22, 0x01, 0x23, 0x00, 0xf7, 0xff, - 0xff, 0xd7, 0x1c, 0x04, 0x28, 0x00, 0xda, 0x00, 0xe1, 0x65, 0x99, 0x05, 0x22, 0x12, 0x1c, 0x38, - 0xf0, 0x02, 0xfb, 0x44, 0x98, 0x05, 0xf0, 0x01, 0xfb, 0xa9, 0x78, 0xba, 0x78, 0xfb, 0x02, 0x12, - 0x43, 0x13, 0x04, 0x1b, 0x0a, 0x1a, 0x0e, 0x1b, 0x43, 0x1a, 0x04, 0x12, 0x0c, 0x13, 0x0e, 0x12, - 0x70, 0xba, 0x7a, 0x3a, 0x70, 0xfb, 0x7a, 0x7b, 0x02, 0x12, 0x43, 0x13, 0x04, 0x1b, 0x0a, 0x1a, - 0x0e, 0x1b, 0x43, 0x1a, 0x04, 0x12, 0x0c, 0x13, 0x0e, 0x12, 0x72, 0x3a, 0x7a, 0xba, 0x72, 0x7b, - 0x7a, 0xfb, 0x02, 0x12, 0x43, 0x13, 0x04, 0x1b, 0x0a, 0x1a, 0x0e, 0x1b, 0x43, 0x1a, 0x04, 0x12, - 0x0c, 0x13, 0x0e, 0x12, 0x72, 0xba, 0x7b, 0x3a, 0x72, 0xfb, 0x7b, 0x7b, 0x02, 0x12, 0x43, 0x13, - 0x04, 0x1b, 0x0a, 0x1a, 0x0e, 0x1b, 0x43, 0x1a, 0x04, 0x12, 0x0c, 0x13, 0x73, 0x7b, 0x7c, 0x7b, - 0x0e, 0x12, 0x00, 0x58, 0x18, 0xc0, 0x00, 0x80, 0x18, 0xc0, 0x73, 0x3a, 0xf0, 0x01, 0xfb, 0x7a, - 0x0e, 0x03, 0x74, 0xbb, 0x0c, 0x03, 0x74, 0xfb, 0x0a, 0x03, 0x75, 0x3b, 0x75, 0x78, 0x28, 0x00, - 0xd1, 0x00, 0xe1, 0x28, 0x7c, 0x7b, 0x21, 0x00, 0x00, 0x5a, 0x18, 0xd2, 0x00, 0x92, 0x18, 0xd2, - 0xf0, 0x02, 0xfb, 0x38, 0x22, 0x00, 0x92, 0x08, 0x92, 0x0d, 0xe1, 0x01, 0x20, 0x09, 0xf0, 0x01, - 0xfb, 0x61, 0x1c, 0x04, 0x28, 0x00, 0xd1, 0x00, 0xe1, 0x12, 0x9a, 0x08, 0x1c, 0x21, 0x06, 0x13, - 0x0e, 0x1b, 0x93, 0x04, 0x23, 0x09, 0x93, 0x00, 0x22, 0x02, 0x9b, 0x04, 0x98, 0x03, 0xf7, 0xff, - 0xff, 0x67, 0x7c, 0xba, 0x7c, 0xfb, 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x7d, 0x3a, 0x1c, 0x21, - 0x02, 0x12, 0x43, 0x1a, 0x7d, 0x7b, 0x43, 0x13, 0x9a, 0x0d, 0x18, 0x9e, 0x1c, 0x30, 0x22, 0x09, - 0xf0, 0x02, 0xfa, 0xcc, 0x1c, 0x20, 0xf0, 0x01, 0xfb, 0x31, 0x78, 0xb2, 0x78, 0xf3, 0x02, 0x12, - 0x43, 0x13, 0x04, 0x1b, 0x0a, 0x1a, 0x0e, 0x1b, 0x43, 0x1a, 0x04, 0x12, 0x0c, 0x15, 0x0e, 0x12, - 0x70, 0xb2, 0x70, 0xf5, 0x1c, 0x28, 0xf0, 0x01, 0xfb, 0x2d, 0x90, 0x05, 0x28, 0x00, 0xd1, 0x00, - 0xe0, 0xde, 0x78, 0xf3, 0x98, 0x03, 0x93, 0x00, 0x99, 0x05, 0x22, 0x02, 0x9b, 0x04, 0xf7, 0xff, - 0xff, 0x37, 0x1c, 0x04, 0x28, 0x00, 0xda, 0x00, 0xe0, 0xc5, 0x79, 0x33, 0x78, 0x34, 0x00, 0xd8, - 0x18, 0xc0, 0x00, 0x40, 0xf0, 0x01, 0xfb, 0x16, 0x0e, 0x03, 0x72, 0x73, 0x0c, 0x03, 0x72, 0xb3, - 0x0a, 0x03, 0x72, 0xf3, 0x73, 0x30, 0x28, 0x00, 0xd1, 0x00, 0xe0, 0xc4, 0x9b, 0x05, 0x1b, 0x2d, - 0x19, 0x1b, 0x93, 0x06, 0x95, 0x07, 0x79, 0x33, 0x21, 0x00, 0x00, 0xda, 0x18, 0xd2, 0x00, 0x52, - 0xf0, 0x02, 0xfa, 0xd0, 0x22, 0x00, 0x92, 0x09, 0xe0, 0x89, 0x7a, 0x72, 0x7a, 0xb3, 0x06, 0x12, - 0x04, 0x1b, 0x43, 0x13, 0x7a, 0xf2, 0x99, 0x06, 0x02, 0x12, 0x43, 0x1a, 0x7b, 0x33, 0x43, 0x13, - 0x9a, 0x0c, 0x18, 0x9d, 0x1c, 0x28, 0x22, 0x09, 0xf0, 0x02, 0xfa, 0x78, 0x79, 0x2b, 0x78, 0x2c, - 0x00, 0xd8, 0x1a, 0xc0, 0xf0, 0x01, 0xfa, 0xe6, 0x0e, 0x03, 0x73, 0xab, 0x0c, 0x03, 0x73, 0xeb, - 0x0a, 0x03, 0x74, 0x2b, 0x74, 0x68, 0x28, 0x00, 0xd1, 0x00, 0xe0, 0x94, 0x9b, 0x06, 0x9a, 0x07, - 0x19, 0x1b, 0x1b, 0x12, 0x92, 0x07, 0x93, 0x06, 0x79, 0x2b, 0x21, 0x00, 0x00, 0xda, 0x1a, 0xd2, - 0xf0, 0x02, 0xfa, 0xa0, 0x9a, 0x07, 0x98, 0x06, 0xe0, 0x08, 0x78, 0x43, 0x3b, 0x04, 0x06, 0x1b, - 0x0e, 0x1b, 0x2b, 0x01, 0xd9, 0x04, 0x78, 0x03, 0x1a, 0xd2, 0x18, 0xc0, 0x2a, 0x00, 0xd1, 0xf4, - 0x9b, 0x06, 0x1a, 0xc4, 0x73, 0x6c, 0x2c, 0x00, 0xd0, 0x15, 0x1c, 0x20, 0xf0, 0x01, 0xfa, 0xba, - 0x0e, 0x03, 0x72, 0x6b, 0x0c, 0x03, 0x72, 0xab, 0x0a, 0x03, 0x72, 0xeb, 0x73, 0x28, 0x28, 0x00, - 0xd0, 0x69, 0x1c, 0x22, 0x99, 0x06, 0xf0, 0x02, 0xfa, 0x39, 0x9a, 0x06, 0x9b, 0x07, 0x19, 0x12, - 0x1b, 0x1b, 0x92, 0x06, 0x93, 0x07, 0x22, 0x00, 0x92, 0x0a, 0xe0, 0x26, 0x7b, 0xab, 0x7b, 0xea, - 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x7c, 0x2b, 0x7c, 0x6c, 0x02, 0x1b, 0x43, 0x13, 0x43, 0x1c, - 0x9b, 0x0b, 0x22, 0x07, 0x18, 0xe4, 0x1c, 0x20, 0x99, 0x06, 0xf0, 0x02, 0xfa, 0x1f, 0x78, 0x23, - 0x9a, 0x06, 0x18, 0xd2, 0x92, 0x06, 0x79, 0x22, 0x79, 0x63, 0x02, 0x12, 0x43, 0x13, 0x04, 0x1b, - 0x0a, 0x1a, 0x0e, 0x1b, 0x43, 0x1a, 0x04, 0x12, 0x0c, 0x13, 0x0e, 0x12, 0x71, 0x22, 0x71, 0x63, - 0x9b, 0x0a, 0x9a, 0x0b, 0x33, 0x01, 0x93, 0x0a, 0x32, 0x07, 0x92, 0x0b, 0x79, 0x2b, 0x9a, 0x0a, - 0x42, 0x9a, 0xd3, 0xd3, 0x9b, 0x09, 0x9a, 0x0c, 0x33, 0x01, 0x93, 0x09, 0x32, 0x12, 0x92, 0x0c, - 0x79, 0x33, 0x9a, 0x09, 0x42, 0x9a, 0xd2, 0x00, 0xe7, 0x6f, 0x98, 0x05, 0xf0, 0x01, 0xfa, 0x5e, - 0x9b, 0x08, 0x9a, 0x0d, 0x33, 0x01, 0x93, 0x08, 0x32, 0x0d, 0x23, 0x00, 0x92, 0x0d, 0x93, 0x05, - 0x7c, 0x7b, 0x9a, 0x08, 0x42, 0x9a, 0xd2, 0x00, 0xe6, 0xf8, 0x9b, 0x05, 0x2b, 0x00, 0xd1, 0x01, - 0x24, 0x00, 0xe0, 0x08, 0x24, 0x00, 0x98, 0x05, 0xf0, 0x01, 0xfa, 0x48, 0x2c, 0x00, 0xd0, 0x02, - 0x1c, 0x38, 0xf7, 0xfe, 0xfb, 0x95, 0xb0, 0x0f, 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x24, 0x04, 0x42, 0x64, 0xe7, 0xf4, 0x24, 0x04, 0x42, 0x64, 0xe7, 0xec, 0xb5, 0xf0, 0xb0, 0x8f, - 0x46, 0x6b, 0x1c, 0x06, 0x4a, 0xc7, 0x20, 0x00, 0x33, 0x37, 0x70, 0x18, 0x23, 0x10, 0x70, 0x13, - 0x4b, 0xc5, 0x1c, 0x32, 0x32, 0x98, 0x60, 0x13, 0x46, 0x6d, 0x1c, 0x33, 0x35, 0x21, 0x33, 0x90, - 0x60, 0x19, 0x74, 0xa8, 0x74, 0xe8, 0x75, 0x28, 0x75, 0x68, 0x1c, 0x08, 0x1c, 0x29, 0xf7, 0xff, - 0xfe, 0x55, 0x1c, 0x04, 0x1c, 0x21, 0x48, 0xbd, 0xf7, 0xfe, 0xfb, 0xe4, 0x48, 0xbc, 0xf7, 0xfe, - 0xfc, 0x29, 0x2c, 0x00, 0xda, 0x00, 0xe1, 0xf0, 0x4b, 0xba, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x32, - 0x4c, 0xb9, 0x79, 0x2b, 0x79, 0xa2, 0x42, 0x9a, 0xd1, 0x23, 0x79, 0xe2, 0x79, 0x6b, 0x42, 0x9a, - 0xd1, 0x1f, 0x7a, 0x21, 0x7a, 0x2a, 0x7a, 0x60, 0x7a, 0x6b, 0x02, 0x09, 0x02, 0x12, 0x43, 0x08, - 0x43, 0x13, 0x42, 0x98, 0xd1, 0x15, 0x7a, 0xa1, 0x7a, 0xaa, 0x7a, 0xe0, 0x7a, 0xeb, 0x02, 0x09, - 0x02, 0x12, 0x43, 0x08, 0x43, 0x13, 0x42, 0x98, 0xd1, 0x0b, 0x7b, 0x22, 0x7b, 0xab, 0x42, 0x9a, - 0xd1, 0x07, 0x7b, 0x62, 0x7b, 0xeb, 0x42, 0x9a, 0xd1, 0x03, 0x7b, 0xa2, 0x7c, 0x2b, 0x42, 0x9a, - 0xd0, 0x09, 0x46, 0x68, 0x30, 0x21, 0xf7, 0xfe, 0xfb, 0x33, 0x24, 0x01, 0x48, 0xa3, 0xf7, 0xfe, - 0xfb, 0xa9, 0x42, 0x64, 0xe1, 0xc8, 0x46, 0x68, 0x30, 0x21, 0x79, 0x03, 0x49, 0x9e, 0x71, 0x8b, - 0x79, 0x43, 0x71, 0xcb, 0x7a, 0x02, 0x7a, 0x43, 0x02, 0x12, 0x43, 0x13, 0x04, 0x1b, 0x0c, 0x1a, - 0x0e, 0x1b, 0x72, 0x0b, 0x72, 0x4a, 0x7a, 0x82, 0x7a, 0xc3, 0x02, 0x12, 0x43, 0x13, 0x04, 0x1b, - 0x0e, 0x1a, 0x0c, 0x1b, 0x72, 0x8a, 0x72, 0xcb, 0x7b, 0x83, 0x4a, 0x95, 0x73, 0x0b, 0x7b, 0xc3, - 0x73, 0x4b, 0x7c, 0x03, 0x73, 0x8b, 0x23, 0x80, 0x42, 0x5b, 0x60, 0x13, 0x4a, 0x91, 0x21, 0x00, - 0x91, 0x03, 0x91, 0x07, 0x92, 0x01, 0xe0, 0xfc, 0x23, 0x33, 0x44, 0x6b, 0xa9, 0x0d, 0x78, 0x1a, - 0x78, 0x0b, 0x21, 0x35, 0x06, 0x12, 0x44, 0x69, 0x04, 0x1b, 0x43, 0x13, 0x78, 0x0a, 0x21, 0x36, - 0x44, 0x69, 0x02, 0x12, 0x43, 0x1a, 0x78, 0x0b, 0x48, 0x87, 0x43, 0x13, 0x9a, 0x07, 0x99, 0x03, - 0x18, 0x9b, 0x93, 0x05, 0x7a, 0x1a, 0x00, 0x52, 0xf7, 0xfe, 0xfb, 0x64, 0x49, 0x83, 0x23, 0x00, - 0x93, 0x04, 0x93, 0x06, 0x91, 0x02, 0xe0, 0xd0, 0x9b, 0x05, 0x99, 0x05, 0x7a, 0x5a, 0x7a, 0x9b, - 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x7a, 0xca, 0x02, 0x12, 0x43, 0x1a, 0x7b, 0x0b, 0x43, 0x13, - 0x9a, 0x06, 0x18, 0x9c, 0x79, 0x63, 0x2b, 0x08, 0xd1, 0x7f, 0x79, 0xa3, 0x2b, 0x06, 0xd0, 0x09, - 0x2b, 0x01, 0xd0, 0x07, 0x2b, 0x02, 0xd0, 0x05, 0x2b, 0x03, 0xd0, 0x03, 0x2b, 0x04, 0xd0, 0x01, - 0x2b, 0x05, 0xd1, 0x72, 0x79, 0xe3, 0x2b, 0x50, 0xd1, 0x6f, 0x79, 0x23, 0x2b, 0x01, 0xd9, 0x6c, - 0x1c, 0x32, 0x23, 0x01, 0x32, 0x9c, 0x70, 0x13, 0x48, 0x6d, 0x79, 0xa1, 0x22, 0x01, 0xf7, 0xfe, - 0xfb, 0x31, 0x23, 0x00, 0x73, 0x73, 0x73, 0x33, 0x27, 0x00, 0x25, 0x00, 0xe0, 0x2c, 0x7b, 0xa2, - 0x7b, 0xe3, 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x7c, 0x22, 0x02, 0x12, 0x43, 0x1a, 0x7c, 0x63, - 0x43, 0x13, 0x19, 0x59, 0x78, 0xcb, 0x2b, 0x02, 0xd1, 0x1c, 0x78, 0x8a, 0x06, 0x13, 0x2b, 0x00, - 0xda, 0x0b, 0x7b, 0x33, 0x2b, 0x00, 0xd1, 0x08, 0x2a, 0x00, 0xd0, 0x06, 0x73, 0x32, 0x79, 0x0b, - 0x79, 0x49, 0x02, 0x1b, 0x43, 0x19, 0x98, 0x02, 0xe0, 0x0a, 0x7b, 0x73, 0x2b, 0x00, 0xd1, 0x09, - 0x2a, 0x00, 0xd0, 0x07, 0x73, 0x72, 0x79, 0x0b, 0x79, 0x49, 0x02, 0x1b, 0x98, 0x01, 0x43, 0x19, - 0xf7, 0xfe, 0xfb, 0x00, 0x37, 0x01, 0x35, 0x07, 0x79, 0x23, 0x42, 0x9f, 0xd3, 0xcf, 0x7b, 0x31, - 0x29, 0x00, 0xd0, 0x64, 0x7b, 0x72, 0x2a, 0x00, 0xd0, 0x61, 0x48, 0x4e, 0xf7, 0xfe, 0xfa, 0xf2, - 0x4a, 0x45, 0x7b, 0x33, 0x99, 0x05, 0x74, 0x13, 0x7b, 0x73, 0x46, 0x68, 0x74, 0x53, 0x79, 0x4b, - 0x30, 0x21, 0x70, 0x33, 0x78, 0xa3, 0x46, 0x6d, 0x60, 0x73, 0x73, 0xd3, 0x78, 0xe3, 0x35, 0x37, - 0x60, 0xb3, 0xf7, 0xfe, 0xfa, 0x65, 0x4b, 0x44, 0x4c, 0x3d, 0x48, 0x44, 0x60, 0x23, 0x78, 0x31, - 0x68, 0xb2, 0xf7, 0xfe, 0xfa, 0xd7, 0x1c, 0x33, 0x33, 0x90, 0x68, 0x18, 0x1c, 0x29, 0xf7, 0xff, - 0xf8, 0x5b, 0x28, 0x00, 0xdb, 0x00, 0xe0, 0x81, 0xe0, 0xde, 0x7b, 0xa3, 0x7b, 0xe2, 0x06, 0x1b, - 0x04, 0x12, 0x43, 0x1a, 0x7c, 0x23, 0x02, 0x1b, 0x43, 0x13, 0x7c, 0x62, 0x1c, 0x10, 0x43, 0x18, - 0xd0, 0x01, 0xf0, 0x01, 0xf8, 0xf3, 0x23, 0x00, 0x73, 0xa3, 0x73, 0xe3, 0x74, 0x23, 0x74, 0x63, - 0x7a, 0xa2, 0x7a, 0x63, 0x04, 0x12, 0x06, 0x1b, 0x43, 0x1a, 0x7a, 0xe3, 0x02, 0x1b, 0x43, 0x13, - 0x7b, 0x22, 0x1c, 0x10, 0x43, 0x18, 0xd0, 0x01, 0xf0, 0x01, 0xf8, 0xe0, 0x23, 0x00, 0x72, 0x63, - 0x72, 0xa3, 0x72, 0xe3, 0x73, 0x23, 0x79, 0x63, 0x2b, 0x09, 0xd1, 0x03, 0x4a, 0x20, 0x4b, 0x28, - 0x60, 0x13, 0xe0, 0x28, 0x2b, 0x08, 0xd1, 0x0a, 0x79, 0xe3, 0x2b, 0x50, 0xd1, 0x07, 0x79, 0x23, - 0x2b, 0x01, 0xd9, 0x04, 0x79, 0xa2, 0x4b, 0x23, 0x49, 0x19, 0x1a, 0x9b, 0x60, 0x0b, 0x9a, 0x04, - 0x9b, 0x06, 0x32, 0x01, 0x33, 0x12, 0x92, 0x04, 0x93, 0x06, 0x99, 0x05, 0x9a, 0x04, 0x79, 0x0b, - 0x42, 0x9a, 0xd2, 0x00, 0xe7, 0x28, 0x9b, 0x03, 0x99, 0x07, 0x33, 0x01, 0x31, 0x0d, 0x93, 0x03, - 0x91, 0x07, 0x22, 0x32, 0x44, 0x6a, 0x78, 0x13, 0x99, 0x03, 0x42, 0x99, 0xd2, 0x00, 0xe6, 0xfb, - 0x48, 0x15, 0xf7, 0xfe, 0xfa, 0x77, 0x46, 0x68, 0x30, 0x21, 0xf7, 0xfe, 0xf9, 0xf9, 0x4c, 0x11, - 0xe0, 0x83, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x3c, 0x2c, 0x0d, 0xe0, 0x01, 0x13, 0x70, 0x62, 0xd3, - 0x13, 0x70, 0x62, 0xfd, 0x13, 0x70, 0x67, 0x98, 0x13, 0x70, 0x67, 0xac, 0x13, 0x70, 0x63, 0x16, - 0x13, 0x70, 0x67, 0xa8, 0x13, 0x70, 0x63, 0xa8, 0x13, 0x70, 0x63, 0x3c, 0x13, 0x70, 0x63, 0x9a, - 0x13, 0x70, 0x63, 0x63, 0x13, 0x70, 0x63, 0xb7, 0xff, 0xff, 0xfb, 0x4f, 0x13, 0x70, 0x63, 0xfc, - 0xff, 0xff, 0xb1, 0xe0, 0xff, 0xff, 0xd8, 0xf0, 0x13, 0x70, 0x63, 0xcb, 0x4b, 0x39, 0x48, 0x3a, - 0x60, 0x23, 0xf7, 0xfe, 0xfa, 0x8f, 0x78, 0x29, 0x78, 0x33, 0x42, 0x8b, 0xd0, 0x02, 0x48, 0x37, - 0xf7, 0xfe, 0xfa, 0x40, 0x4b, 0x36, 0x4a, 0x37, 0x60, 0x13, 0x46, 0x6b, 0x33, 0x37, 0x78, 0x31, - 0x78, 0x1b, 0x42, 0x8b, 0xd1, 0x03, 0x4b, 0x34, 0x78, 0x1b, 0x07, 0x9a, 0xd5, 0x06, 0x1c, 0x33, - 0x33, 0x90, 0x68, 0x18, 0xf7, 0xfe, 0xff, 0xaa, 0x28, 0x00, 0xdb, 0x3d, 0x4a, 0x2f, 0x4b, 0x30, - 0x60, 0x13, 0x68, 0xb2, 0x2a, 0x00, 0xd0, 0x09, 0x1c, 0x33, 0x33, 0x90, 0x06, 0x12, 0x68, 0x18, - 0x79, 0xf1, 0x0e, 0x12, 0xf7, 0xfe, 0xff, 0x86, 0x28, 0x00, 0xdb, 0x2d, 0x4a, 0x25, 0x4b, 0x29, - 0x48, 0x29, 0x60, 0x13, 0x4a, 0x25, 0x4b, 0x29, 0x60, 0x13, 0xf7, 0xfe, 0xfa, 0x5b, 0x1c, 0x30, - 0xf7, 0xff, 0xf8, 0x70, 0x1c, 0x04, 0x48, 0x26, 0xf7, 0xfe, 0xfa, 0x54, 0x2c, 0x00, 0xdb, 0x1c, - 0x1c, 0x34, 0x23, 0x08, 0x34, 0xa0, 0x73, 0xb3, 0x68, 0x23, 0x2b, 0x00, 0xd1, 0x07, 0x20, 0x81, - 0x01, 0x40, 0xf0, 0x01, 0xf8, 0x3f, 0x23, 0x1f, 0x30, 0x1f, 0x43, 0x98, 0x60, 0x20, 0x1c, 0x33, - 0x33, 0xa0, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x01, 0x24, 0x00, 0xe0, 0x06, 0x4a, 0x13, 0x4b, 0x19, - 0x24, 0x04, 0x60, 0x13, 0x42, 0x64, 0xe0, 0x00, 0x4c, 0x17, 0x4a, 0x0e, 0x4b, 0x11, 0x60, 0x13, - 0x2c, 0x00, 0xda, 0x05, 0x4b, 0x0d, 0x48, 0x15, 0x68, 0x19, 0xf7, 0xfe, 0xf9, 0xe3, 0xe0, 0x03, - 0x48, 0x13, 0xf7, 0xfe, 0xf9, 0xdf, 0x24, 0x00, 0xb0, 0x0f, 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0xff, 0xff, 0xfb, 0x4e, 0x13, 0x70, 0x64, 0x2a, 0x13, 0x70, 0x64, 0x45, - 0x00, 0x98, 0x96, 0x80, 0x13, 0x70, 0x60, 0x38, 0x13, 0x70, 0x01, 0x0e, 0x13, 0x70, 0x67, 0xa8, - 0xff, 0xff, 0xfb, 0x4d, 0x00, 0x0f, 0x42, 0x40, 0x13, 0x70, 0x64, 0x6f, 0xff, 0xff, 0xfb, 0x4c, - 0x13, 0x70, 0x64, 0x87, 0xff, 0xff, 0xfb, 0x4b, 0xff, 0xff, 0xd8, 0xe7, 0x13, 0x70, 0x64, 0x9e, - 0x13, 0x70, 0x64, 0xc0, 0xb5, 0xf0, 0x4b, 0x78, 0xb0, 0x8b, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x4f, - 0x46, 0x6b, 0x22, 0x00, 0x33, 0x27, 0x70, 0x1a, 0xf0, 0x01, 0xf9, 0x24, 0x4a, 0x73, 0x23, 0x10, - 0x70, 0x13, 0x4b, 0x73, 0x4a, 0x73, 0x78, 0x1b, 0x2b, 0x00, 0xd0, 0x01, 0x4b, 0x72, 0xe0, 0x00, - 0x4b, 0x72, 0x4e, 0x73, 0x46, 0x6d, 0x60, 0x13, 0x35, 0x11, 0x23, 0x00, 0x1c, 0x37, 0x74, 0xab, - 0x74, 0xeb, 0x75, 0x2b, 0x75, 0x6b, 0x37, 0x90, 0x68, 0x38, 0x1c, 0x29, 0xf7, 0xff, 0xfb, 0xfe, - 0x4c, 0x6c, 0x79, 0x2b, 0x79, 0xa2, 0x42, 0x9a, 0xd1, 0x23, 0x79, 0xe2, 0x79, 0x6b, 0x42, 0x9a, - 0xd1, 0x1f, 0x7a, 0x21, 0x7a, 0x2a, 0x7a, 0x60, 0x7a, 0x6b, 0x02, 0x09, 0x02, 0x12, 0x43, 0x08, - 0x43, 0x13, 0x42, 0x98, 0xd1, 0x15, 0x7a, 0xa1, 0x7a, 0xaa, 0x7a, 0xe0, 0x7a, 0xeb, 0x02, 0x09, - 0x02, 0x12, 0x43, 0x08, 0x43, 0x13, 0x42, 0x98, 0xd1, 0x0b, 0x7b, 0x22, 0x7b, 0xab, 0x42, 0x9a, - 0xd1, 0x07, 0x7b, 0x62, 0x7b, 0xeb, 0x42, 0x9a, 0xd1, 0x03, 0x7b, 0xa2, 0x7c, 0x2b, 0x42, 0x9a, - 0xd0, 0x08, 0x46, 0x68, 0x30, 0x11, 0xf7, 0xfe, 0xf8, 0xeb, 0x48, 0x57, 0xf7, 0xfe, 0xf9, 0x62, - 0x4c, 0x56, 0xe0, 0x93, 0x46, 0x6c, 0x1c, 0x28, 0x34, 0x27, 0xf7, 0xfe, 0xf8, 0xe1, 0x68, 0x38, - 0x1c, 0x21, 0xf7, 0xfe, 0xfe, 0xe1, 0x28, 0x00, 0xda, 0x01, 0x4c, 0x51, 0xe0, 0x86, 0x4b, 0x49, - 0x4a, 0x50, 0x60, 0x1a, 0x78, 0x31, 0x78, 0x23, 0x42, 0x8b, 0xd1, 0x03, 0x4b, 0x4e, 0x78, 0x1b, - 0x07, 0x9a, 0xd5, 0x08, 0x4b, 0x46, 0x33, 0x90, 0x68, 0x18, 0xf7, 0xfe, 0xfe, 0xbf, 0x28, 0x00, - 0xda, 0x01, 0x4c, 0x4a, 0xe0, 0x72, 0x49, 0x42, 0x68, 0x8a, 0x2a, 0x00, 0xd0, 0x0b, 0x1c, 0x0b, - 0x33, 0x90, 0x06, 0x12, 0x68, 0x18, 0x79, 0xc9, 0x0e, 0x12, 0xf7, 0xfe, 0xfe, 0x9b, 0x28, 0x00, - 0xda, 0x01, 0x4c, 0x43, 0xe0, 0x62, 0x4b, 0x36, 0x4a, 0x36, 0x78, 0x1b, 0x2b, 0x00, 0xd0, 0x01, - 0x4b, 0x35, 0xe0, 0x00, 0x4b, 0x35, 0x60, 0x13, 0x48, 0x35, 0x21, 0x00, 0xf7, 0xfe, 0xfe, 0xd2, - 0x28, 0x00, 0xda, 0x01, 0x4c, 0x3b, 0xe0, 0x51, 0x4b, 0x32, 0x79, 0x5b, 0x2b, 0x00, 0xd1, 0x03, - 0x4b, 0x35, 0x78, 0x1b, 0x07, 0xda, 0xd5, 0x22, 0x4d, 0x2d, 0x23, 0x00, 0x73, 0xab, 0x4c, 0x29, - 0x4b, 0x30, 0x26, 0x01, 0x60, 0x23, 0x1c, 0x2b, 0x33, 0x90, 0x68, 0x18, 0x88, 0xeb, 0x21, 0xa1, - 0x93, 0x00, 0x1c, 0x2b, 0x33, 0x0e, 0x93, 0x02, 0x22, 0xfe, 0x23, 0x00, 0x96, 0x01, 0xf7, 0xfe, - 0xfd, 0xff, 0x4b, 0x21, 0x60, 0x23, 0x28, 0x00, 0xda, 0x06, 0x73, 0xae, 0x1c, 0x28, 0x21, 0x00, - 0xf7, 0xfe, 0xfe, 0xa8, 0x4c, 0x28, 0xe0, 0x29, 0x7b, 0xab, 0x33, 0x01, 0x73, 0xab, 0x4b, 0x27, - 0x4d, 0x18, 0x4f, 0x1b, 0x4e, 0x1b, 0x60, 0x2b, 0x79, 0x31, 0x1c, 0x38, 0xf7, 0xff, 0xfa, 0x60, - 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x22, 0xf7, 0xfe, 0xf8, 0xe5, 0x4b, 0x13, 0x60, 0x2b, 0x2c, 0x00, - 0xda, 0x01, 0x4c, 0x20, 0xe0, 0x12, 0x79, 0x31, 0x1c, 0x38, 0xf7, 0xff, 0xfa, 0x01, 0x1c, 0x04, - 0x1c, 0x21, 0x48, 0x1d, 0xf7, 0xfe, 0xf8, 0xd6, 0x2c, 0x00, 0xda, 0x01, 0x4c, 0x1b, 0xe0, 0x05, - 0x79, 0x33, 0x4a, 0x06, 0x70, 0x13, 0x4a, 0x1a, 0x23, 0x01, 0x70, 0x13, 0xb0, 0x0b, 0x1c, 0x20, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x67, 0x98, 0x13, 0x70, 0x60, 0x3c, - 0x13, 0x70, 0x01, 0x0f, 0x13, 0x70, 0x60, 0x38, 0x00, 0x0f, 0x42, 0x40, 0x00, 0x03, 0x0d, 0x40, - 0x13, 0x72, 0xc2, 0x00, 0x13, 0x70, 0x67, 0xac, 0x13, 0x70, 0x63, 0x16, 0xff, 0xff, 0xfc, 0x0f, - 0xff, 0xff, 0xfc, 0x18, 0x00, 0x98, 0x96, 0x80, 0x13, 0x70, 0x01, 0x0e, 0xff, 0xff, 0xfc, 0x17, - 0xff, 0xff, 0xfc, 0x16, 0xff, 0xff, 0xfc, 0x15, 0xff, 0xff, 0xfc, 0x14, 0x01, 0x31, 0x2d, 0x00, - 0x13, 0x70, 0x64, 0xdd, 0xff, 0xff, 0xfc, 0x13, 0x13, 0x70, 0x62, 0x91, 0xff, 0xff, 0xfc, 0x12, - 0x13, 0x70, 0x67, 0x9c, 0xb5, 0xf0, 0x4b, 0x8e, 0x22, 0x00, 0x80, 0x1a, 0x4b, 0x8d, 0x25, 0x00, - 0x80, 0x1a, 0x4b, 0x8d, 0x4a, 0x8d, 0x70, 0x1d, 0x4b, 0x8d, 0xb0, 0x8b, 0x70, 0x1d, 0x23, 0x78, - 0x42, 0x5b, 0x60, 0x13, 0x90, 0x08, 0xf0, 0x00, 0xff, 0xfd, 0x4c, 0x8a, 0x99, 0x08, 0x1c, 0x20, - 0xf7, 0xff, 0xfc, 0x7c, 0x28, 0x00, 0xda, 0x00, 0xe0, 0xfc, 0x49, 0x87, 0x20, 0x01, 0x73, 0xa0, - 0x78, 0x0b, 0x78, 0x4a, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x78, 0x8b, 0x02, 0x1b, 0x43, 0x13, - 0x78, 0xca, 0x43, 0x1a, 0xd0, 0x48, 0x79, 0x4b, 0x2b, 0x00, 0xd1, 0x03, 0x4b, 0x7f, 0x78, 0x1b, - 0x42, 0x03, 0xd0, 0x1d, 0x4d, 0x7b, 0x23, 0x00, 0x73, 0xab, 0x4c, 0x7d, 0x4b, 0x7d, 0x26, 0x01, - 0x60, 0x23, 0x1c, 0x2b, 0x33, 0x90, 0x68, 0x18, 0x88, 0xeb, 0x21, 0xa1, 0x93, 0x00, 0x1c, 0x2b, - 0x33, 0x0e, 0x93, 0x02, 0x22, 0xfe, 0x23, 0x00, 0x96, 0x01, 0xf7, 0xfe, 0xfd, 0x51, 0x4b, 0x76, - 0x60, 0x23, 0x28, 0x00, 0xda, 0x01, 0x73, 0xae, 0xe0, 0xbf, 0x7b, 0xab, 0x33, 0x01, 0x73, 0xab, - 0x4b, 0x6d, 0x48, 0x72, 0x79, 0x1d, 0x1c, 0x29, 0xf7, 0xfe, 0xf8, 0x44, 0x4e, 0x69, 0x1c, 0x29, - 0x1c, 0x30, 0xf7, 0xff, 0xfa, 0x3d, 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x6d, 0xf7, 0xfe, 0xf8, 0x3a, - 0x1c, 0xa3, 0x2b, 0x01, 0xd8, 0x01, 0x1c, 0x30, 0xe0, 0x3c, 0x2c, 0x00, 0xda, 0x00, 0xe0, 0xa4, - 0x4a, 0x5d, 0x23, 0x01, 0x70, 0x13, 0x4b, 0x5e, 0x4a, 0x61, 0x70, 0x1d, 0x4b, 0x62, 0x60, 0x13, - 0x4a, 0x5a, 0x23, 0x00, 0x60, 0x13, 0xe0, 0x94, 0x4a, 0x5c, 0x71, 0x4d, 0x27, 0x01, 0x26, 0x00, - 0x25, 0x01, 0x92, 0x05, 0x1c, 0x32, 0x1e, 0x53, 0x41, 0x9a, 0x92, 0x09, 0x9a, 0x05, 0x78, 0x13, - 0x22, 0x01, 0x42, 0x13, 0xd0, 0x04, 0x9b, 0x09, 0x2b, 0x00, 0xd1, 0x01, 0x2d, 0x00, 0xd1, 0x27, - 0x48, 0x58, 0x1c, 0x31, 0xf7, 0xfe, 0xf8, 0x0e, 0x4a, 0x4e, 0x06, 0x31, 0x0e, 0x09, 0x1c, 0x10, - 0x92, 0x07, 0xf7, 0xff, 0xfa, 0x05, 0x1c, 0x04, 0x1c, 0x21, 0x48, 0x51, 0xf7, 0xfe, 0xf8, 0x02, - 0x1c, 0xa3, 0x2b, 0x01, 0xd8, 0x10, 0x9b, 0x09, 0x2b, 0x00, 0xd0, 0x0d, 0x4a, 0x48, 0x4b, 0x4a, - 0x60, 0x13, 0x98, 0x07, 0xf7, 0xfe, 0xfe, 0x56, 0x4a, 0x40, 0x23, 0x79, 0x42, 0x5b, 0x60, 0x13, - 0x4a, 0x3d, 0x23, 0x00, 0x70, 0x13, 0xe0, 0x6d, 0x2c, 0x00, 0xda, 0x40, 0x2d, 0x00, 0xd0, 0x38, - 0x4d, 0x45, 0x4c, 0x3f, 0x4b, 0x3f, 0x95, 0x06, 0x4a, 0x3a, 0x60, 0x23, 0x4b, 0x43, 0x27, 0x00, - 0x68, 0x18, 0x88, 0xd3, 0x60, 0x2f, 0x73, 0x97, 0x93, 0x00, 0x1c, 0x13, 0x33, 0x0e, 0x25, 0x01, - 0x93, 0x02, 0x21, 0xa1, 0x23, 0x00, 0x22, 0xfe, 0x95, 0x01, 0xf7, 0xfe, 0xfc, 0xd1, 0x4b, 0x36, - 0x1c, 0x05, 0x60, 0x23, 0x28, 0x00, 0xda, 0x05, 0x4a, 0x2e, 0x23, 0x01, 0x73, 0x93, 0x9a, 0x06, - 0x60, 0x17, 0xe0, 0x06, 0x4a, 0x2b, 0x7b, 0x93, 0x33, 0x01, 0x73, 0x93, 0x4b, 0x2a, 0x22, 0x01, - 0x71, 0x5a, 0x4b, 0x28, 0x48, 0x32, 0x7b, 0x9f, 0x1c, 0x29, 0x1c, 0x3a, 0xf7, 0xfd, 0xff, 0xba, - 0x4b, 0x26, 0x22, 0x01, 0x78, 0x1b, 0x42, 0x13, 0xd0, 0x05, 0x2d, 0x00, 0xda, 0x03, 0x25, 0x01, - 0xe0, 0x02, 0x36, 0x01, 0xe0, 0x00, 0x25, 0x00, 0x42, 0xbe, 0xdb, 0x8b, 0xe0, 0x1d, 0x4b, 0x1e, - 0x20, 0x00, 0x24, 0x01, 0x70, 0x18, 0x70, 0x58, 0x70, 0x98, 0x70, 0xdc, 0x06, 0x31, 0x0e, 0x09, - 0x9d, 0x08, 0x71, 0x19, 0x89, 0x2b, 0x4a, 0x12, 0x80, 0x13, 0x89, 0x6b, 0x4a, 0x11, 0x80, 0x13, - 0x4b, 0x11, 0x4a, 0x17, 0x70, 0x1c, 0x4b, 0x12, 0x70, 0x19, 0x4b, 0x17, 0x60, 0x13, 0x4b, 0x0f, - 0x60, 0x18, 0xf0, 0x00, 0xfe, 0xfb, 0x20, 0x00, 0xe0, 0x0e, 0x4a, 0x0c, 0x23, 0x7a, 0x42, 0x5b, - 0x60, 0x13, 0x48, 0x0c, 0xf7, 0xfe, 0xfd, 0xe6, 0x4a, 0x07, 0x23, 0x00, 0x70, 0x13, 0x48, 0x15, - 0xf7, 0xfd, 0xff, 0x80, 0x20, 0x03, 0x42, 0x40, 0xb0, 0x0b, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x67, 0x9e, 0x13, 0x70, 0x67, 0xa0, 0x13, 0x70, 0x67, 0x9c, 0x13, 0x70, 0x67, 0xa8, - 0x13, 0x70, 0x60, 0x3c, 0x13, 0x72, 0xc2, 0x00, 0x13, 0x70, 0x67, 0xac, 0x13, 0x70, 0x01, 0x0e, - 0x13, 0x70, 0x60, 0x38, 0x00, 0x98, 0x96, 0x80, 0x00, 0x0f, 0x42, 0x40, 0x13, 0x70, 0x64, 0xf2, - 0x13, 0x70, 0x65, 0x10, 0x13, 0x70, 0x64, 0xf7, 0x13, 0x70, 0x67, 0x6c, 0x13, 0x72, 0xc2, 0x90, - 0x13, 0x70, 0x65, 0x2d, 0x13, 0x70, 0x65, 0x56, 0xb5, 0xf0, 0x4b, 0x51, 0xb0, 0x89, 0x68, 0x1f, - 0x00, 0x83, 0x18, 0x1b, 0x00, 0xdb, 0x1c, 0x1a, 0x32, 0x58, 0x18, 0xfb, 0x18, 0xbe, 0x22, 0x00, - 0x1c, 0x05, 0x67, 0x1a, 0x20, 0x32, 0xf7, 0xfd, 0xf9, 0x6f, 0x24, 0x00, 0x23, 0x16, 0x22, 0x00, - 0x93, 0x01, 0x23, 0x80, 0x92, 0x00, 0x1c, 0x30, 0x21, 0x80, 0x22, 0x06, 0x00, 0x5b, 0x96, 0x02, - 0xf7, 0xfe, 0xfc, 0x36, 0x28, 0x00, 0xda, 0x3d, 0x20, 0x64, 0x34, 0x01, 0xf7, 0xfd, 0xf9, 0x5c, - 0x2c, 0x03, 0xd1, 0xeb, 0x24, 0x00, 0x1c, 0x28, 0xf7, 0xfe, 0xf8, 0xba, 0x20, 0x64, 0xf7, 0xfd, - 0xf9, 0x53, 0x23, 0x16, 0x22, 0x00, 0x93, 0x01, 0x23, 0x80, 0x92, 0x00, 0x1c, 0x30, 0x21, 0x80, - 0x22, 0x06, 0x00, 0x5b, 0x96, 0x02, 0xf7, 0xfe, 0xfc, 0x1b, 0x28, 0x00, 0xda, 0x22, 0x34, 0x01, - 0x2c, 0x03, 0xd1, 0xe8, 0x24, 0x00, 0x1c, 0x28, 0xf7, 0xfe, 0xf8, 0x76, 0x20, 0x64, 0xf7, 0xfd, - 0xf9, 0x3b, 0x1c, 0x28, 0xf7, 0xfe, 0xf8, 0x9c, 0x20, 0x64, 0xf7, 0xfd, 0xf9, 0x35, 0x23, 0x16, - 0x22, 0x00, 0x93, 0x01, 0x23, 0x80, 0x92, 0x00, 0x1c, 0x30, 0x21, 0x80, 0x22, 0x06, 0x00, 0x5b, - 0x96, 0x02, 0xf7, 0xfe, 0xfb, 0xfd, 0x28, 0x00, 0xda, 0x04, 0x34, 0x01, 0x2c, 0x03, 0xd1, 0xe2, - 0x48, 0x24, 0xe0, 0x40, 0x1c, 0x6a, 0x04, 0x13, 0x0c, 0x1b, 0x93, 0x06, 0x00, 0xab, 0x19, 0x5b, - 0x00, 0xdb, 0x18, 0xff, 0x1c, 0x3b, 0x33, 0x7c, 0x24, 0x00, 0x92, 0x07, 0x93, 0x05, 0x20, 0x32, - 0xf7, 0xfd, 0xf9, 0x12, 0x23, 0x00, 0x93, 0x00, 0x93, 0x01, 0x93, 0x02, 0x1c, 0x30, 0x21, 0x00, - 0x22, 0x05, 0x9b, 0x06, 0xf7, 0xfe, 0xfb, 0xdc, 0x28, 0x00, 0xda, 0x02, 0x4b, 0x16, 0x1b, 0x18, - 0x34, 0x01, 0x9a, 0x05, 0x25, 0x00, 0x60, 0x15, 0x9b, 0x07, 0x67, 0x3b, 0x28, 0x00, 0xda, 0x1a, - 0x21, 0x00, 0x1c, 0x30, 0xf7, 0xfe, 0xfc, 0x28, 0x20, 0x32, 0xf7, 0xfd, 0xf8, 0xf5, 0x23, 0x16, - 0x93, 0x01, 0x23, 0x80, 0x1c, 0x30, 0x21, 0x80, 0x22, 0x06, 0x00, 0x5b, 0x95, 0x00, 0x96, 0x02, - 0xf7, 0xfe, 0xfb, 0xbe, 0x28, 0x00, 0xdb, 0x02, 0x20, 0x01, 0x42, 0x40, 0xe0, 0x01, 0x48, 0x07, - 0x67, 0x3d, 0x2c, 0x04, 0xdd, 0xcb, 0xb0, 0x09, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x70, 0x60, 0x34, 0xff, 0xff, 0xf7, 0x67, 0xff, 0xff, 0xe0, 0xc0, 0xff, 0xff, 0xf7, 0x3e, - 0xb5, 0x10, 0x4b, 0x0a, 0x1c, 0x04, 0x68, 0x1b, 0x68, 0x9a, 0x23, 0x01, 0x60, 0x93, 0xf7, 0xfe, - 0xf8, 0x2f, 0x28, 0x00, 0xdb, 0x02, 0x1c, 0x20, 0xf7, 0xff, 0xff, 0x46, 0x4b, 0x03, 0x68, 0x1b, - 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0xbc, 0x10, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x34, - 0xb5, 0xf0, 0x1c, 0x06, 0x48, 0x44, 0xb0, 0x8b, 0x68, 0x02, 0x1c, 0x33, 0x92, 0x06, 0x68, 0x91, - 0x33, 0x10, 0x00, 0x9b, 0x18, 0xc9, 0x00, 0xb3, 0x19, 0x9b, 0x00, 0xdb, 0x9c, 0x06, 0x1c, 0x1a, - 0x32, 0x58, 0x18, 0xa2, 0x92, 0x08, 0x18, 0xe3, 0x22, 0x00, 0x67, 0x1a, 0x68, 0x03, 0x4a, 0x3b, - 0x68, 0x9b, 0x1d, 0x0f, 0x68, 0x5b, 0x68, 0x4b, 0x40, 0x13, 0x2b, 0x01, 0xd0, 0x02, 0x24, 0x01, - 0x42, 0x64, 0xe0, 0x64, 0x1c, 0x73, 0x04, 0x1b, 0x22, 0x00, 0x0c, 0x1b, 0x92, 0x09, 0x93, 0x05, - 0x4b, 0x33, 0x20, 0x0a, 0x60, 0x3b, 0xf7, 0xfd, 0xf8, 0x8f, 0x4b, 0x32, 0x20, 0x64, 0x60, 0x3b, - 0xf7, 0xfd, 0xf8, 0x8a, 0x4b, 0x30, 0x22, 0x80, 0x60, 0x3b, 0x23, 0xfa, 0x00, 0xdb, 0x93, 0x00, - 0x00, 0x52, 0x23, 0x00, 0x1c, 0x38, 0x1c, 0x39, 0xf7, 0xfd, 0xff, 0x92, 0x68, 0x3a, 0x4b, 0x2b, - 0x1c, 0x04, 0x40, 0x13, 0x2b, 0x05, 0xd1, 0x30, 0x23, 0xc0, 0x01, 0x1b, 0x40, 0x1a, 0x23, 0x80, - 0x00, 0xdb, 0x42, 0x9a, 0xd0, 0x29, 0x28, 0x00, 0xd1, 0x29, 0x20, 0x64, 0xf7, 0xfd, 0xf8, 0x6c, - 0x4b, 0x23, 0x21, 0x80, 0x68, 0x1a, 0x25, 0x00, 0x92, 0x07, 0x4a, 0x22, 0x60, 0x1a, 0x23, 0x16, - 0x93, 0x01, 0x9b, 0x08, 0x22, 0x06, 0x93, 0x02, 0x1c, 0x18, 0x23, 0x80, 0x00, 0x5b, 0x94, 0x00, - 0xf7, 0xfe, 0xfb, 0x2e, 0x1c, 0x04, 0x28, 0x00, 0xdb, 0x09, 0x98, 0x08, 0x21, 0x00, 0x22, 0x05, - 0x9b, 0x05, 0x95, 0x00, 0x95, 0x01, 0x95, 0x02, 0xf7, 0xfe, 0xfb, 0x22, 0x1c, 0x04, 0x4b, 0x14, - 0x9a, 0x07, 0x60, 0x1a, 0x2c, 0x00, 0xdb, 0x02, 0xe0, 0x08, 0x24, 0x01, 0x42, 0x64, 0x9b, 0x09, - 0x33, 0x01, 0x93, 0x09, 0x2b, 0x04, 0xd1, 0xab, 0x2c, 0x00, 0xdb, 0x08, 0x00, 0xb3, 0x9a, 0x06, - 0x19, 0x9b, 0x00, 0xdb, 0x18, 0xd3, 0x22, 0x00, 0x67, 0xda, 0x1c, 0x72, 0x67, 0x1a, 0xb0, 0x0b, - 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x34, 0x00, 0x00, 0x20, 0x01, - 0x00, 0x00, 0x18, 0x03, 0x00, 0x00, 0x19, 0x03, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x20, 0x05, - 0x13, 0x70, 0x60, 0x38, 0x00, 0x03, 0x0d, 0x40, 0xb5, 0xf0, 0x4c, 0x1d, 0xb0, 0x81, 0x68, 0x23, - 0x1c, 0x06, 0x68, 0x9d, 0x23, 0x01, 0x60, 0xab, 0xf7, 0xff, 0xff, 0x5a, 0x1c, 0x07, 0x28, 0x00, - 0xda, 0x1b, 0x68, 0x23, 0x22, 0x37, 0x68, 0x99, 0x20, 0x0a, 0x68, 0x4b, 0x40, 0x13, 0x60, 0x4b, - 0x68, 0x23, 0x1c, 0x34, 0x68, 0x9b, 0x34, 0x10, 0x68, 0x1b, 0x00, 0xa4, 0xf7, 0xfd, 0xf8, 0x04, - 0x4b, 0x10, 0x19, 0x2c, 0x60, 0x63, 0x20, 0x32, 0xf7, 0xfc, 0xff, 0xfe, 0x4b, 0x0e, 0x20, 0x64, - 0x60, 0x63, 0xf7, 0xfc, 0xff, 0xf9, 0x4b, 0x0d, 0x60, 0x63, 0x48, 0x09, 0x22, 0x37, 0x68, 0x03, - 0xb0, 0x01, 0x68, 0x99, 0x68, 0x4b, 0x40, 0x13, 0x60, 0x4b, 0x68, 0x03, 0x68, 0x9a, 0x23, 0x04, - 0x60, 0x93, 0x68, 0x03, 0x1c, 0x38, 0x68, 0x9b, 0x68, 0x1b, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x60, 0x34, 0x00, 0x00, 0x18, 0x03, 0x00, 0x00, 0x19, 0x03, 0x00, 0x00, 0x10, 0x01, - 0xb5, 0xf0, 0x4b, 0x51, 0x4c, 0x51, 0x78, 0x1b, 0xb0, 0x83, 0x1c, 0x1a, 0x4b, 0x50, 0x1e, 0x51, - 0x41, 0x8a, 0x68, 0x1b, 0x60, 0x22, 0x2b, 0x00, 0xd0, 0x2b, 0x4b, 0x4e, 0x00, 0x92, 0x68, 0x1b, - 0x68, 0x99, 0x1c, 0x0b, 0x33, 0x44, 0x18, 0x9b, 0x68, 0x1b, 0x07, 0xda, 0xd4, 0x23, 0xf0, 0x00, - 0xfd, 0x11, 0x20, 0x64, 0xf7, 0xfc, 0xff, 0xc0, 0xf0, 0x00, 0xfd, 0x00, 0x20, 0x64, 0xf7, 0xfc, - 0xff, 0xbb, 0xf0, 0x00, 0xfd, 0x07, 0x20, 0x64, 0xf7, 0xfc, 0xff, 0xb6, 0xf0, 0x00, 0xfc, 0xf6, - 0x20, 0x64, 0xf7, 0xfc, 0xff, 0xb1, 0xf0, 0x00, 0xfc, 0xfd, 0x20, 0x64, 0xf7, 0xfc, 0xff, 0xac, - 0xf0, 0x00, 0xfc, 0xec, 0x20, 0x64, 0xf7, 0xfc, 0xff, 0xa7, 0x20, 0xfa, 0x00, 0x40, 0xf7, 0xfc, - 0xff, 0xa3, 0x24, 0x01, 0xe0, 0x62, 0x23, 0x00, 0x60, 0x8b, 0x20, 0x00, 0xf7, 0xfc, 0xfd, 0x2e, - 0x68, 0x20, 0xf7, 0xff, 0xff, 0x79, 0x1c, 0x06, 0x28, 0x00, 0xda, 0x03, 0x68, 0x20, 0xf7, 0xff, - 0xff, 0x73, 0x1c, 0x06, 0x20, 0x3c, 0xf7, 0xfc, 0xff, 0x8f, 0x4b, 0x2e, 0x48, 0x2e, 0x93, 0x01, - 0x68, 0x1b, 0x1c, 0x31, 0x68, 0x9a, 0x4b, 0x29, 0x32, 0x44, 0x68, 0x1b, 0x00, 0x9b, 0x18, 0xd2, - 0x68, 0x15, 0x1c, 0x2a, 0xf7, 0xfd, 0xfd, 0x56, 0x4c, 0x25, 0x22, 0x01, 0x60, 0x22, 0x2e, 0x00, - 0xdb, 0x38, 0x4b, 0x26, 0x1c, 0x2a, 0x40, 0x1a, 0x4b, 0x25, 0x42, 0x9a, 0xd1, 0x32, 0x4d, 0x25, - 0x27, 0x00, 0x70, 0x2f, 0x60, 0x27, 0xf7, 0xff, 0xfb, 0x8d, 0x4b, 0x23, 0x4a, 0x23, 0x60, 0x13, - 0x4b, 0x23, 0x93, 0x00, 0x28, 0x00, 0xdb, 0x11, 0x48, 0x22, 0xf7, 0xfd, 0xfd, 0x3b, 0xf0, 0x00, - 0xfc, 0xa5, 0x22, 0x01, 0x60, 0x27, 0x70, 0x2a, 0x98, 0x00, 0xf7, 0xfc, 0xfc, 0xef, 0x9a, 0x01, - 0x24, 0x00, 0x68, 0x13, 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0xe0, 0x14, 0x23, 0x01, 0x60, 0x23, - 0x1c, 0x31, 0x48, 0x19, 0xf7, 0xfd, 0xfd, 0x26, 0x70, 0x2f, 0xf0, 0x00, 0xfc, 0x8f, 0x20, 0x64, - 0xf7, 0xfc, 0xff, 0x4a, 0x98, 0x00, 0xf7, 0xfc, 0xfc, 0xd9, 0x9a, 0x01, 0x68, 0x13, 0x68, 0x9a, - 0x23, 0x04, 0x60, 0x93, 0x24, 0x01, 0x20, 0x64, 0xf7, 0xfc, 0xff, 0x3e, 0xb0, 0x03, 0x1c, 0x20, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x01, 0x0c, 0x13, 0x70, 0x67, 0x78, - 0x13, 0x70, 0x67, 0x6c, 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x65, 0x73, 0x00, 0x00, 0x31, 0x05, - 0x00, 0x00, 0x10, 0x05, 0x13, 0x70, 0x67, 0x9c, 0x00, 0x0f, 0x42, 0x40, 0x13, 0x70, 0x60, 0x38, - 0x13, 0x70, 0x12, 0xd9, 0x13, 0x70, 0x65, 0x9d, 0x13, 0x70, 0x65, 0xae, 0xb5, 0xf0, 0x4b, 0x28, - 0xb0, 0x85, 0x68, 0x1b, 0x90, 0x03, 0x92, 0x02, 0x2b, 0x00, 0xd0, 0x01, 0x20, 0x00, 0xe0, 0x43, - 0x04, 0x0b, 0x4f, 0x24, 0x25, 0x00, 0x0c, 0x1e, 0xf7, 0xff, 0xff, 0x32, 0x28, 0x00, 0xd1, 0x01, - 0x25, 0x00, 0xe0, 0x01, 0x2d, 0x00, 0xdb, 0x02, 0x78, 0x3b, 0x2b, 0x01, 0xd0, 0x04, 0x4a, 0x1e, - 0x23, 0x01, 0x25, 0x01, 0x60, 0x13, 0x42, 0x6d, 0x4b, 0x1b, 0x68, 0x19, 0x29, 0x00, 0xd1, 0xeb, - 0x4a, 0x1a, 0x4b, 0x1b, 0x60, 0x13, 0x1c, 0x6b, 0xd0, 0x17, 0x4c, 0x1a, 0x20, 0x00, 0x68, 0x23, - 0x68, 0x9b, 0x60, 0x99, 0xf7, 0xfc, 0xfc, 0x82, 0x4b, 0x17, 0x9a, 0x03, 0x78, 0x19, 0x9b, 0x02, - 0x48, 0x16, 0x93, 0x00, 0x1c, 0x33, 0xf7, 0xfe, 0xfc, 0xdf, 0x1c, 0x05, 0x48, 0x14, 0xf7, 0xfc, - 0xfc, 0x75, 0x68, 0x23, 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0x4a, 0x0c, 0x4b, 0x11, 0x60, 0x13, - 0x2d, 0x00, 0xda, 0x02, 0x4a, 0x08, 0x23, 0x01, 0x60, 0x13, 0x4b, 0x07, 0x68, 0x1b, 0x2b, 0x00, - 0xd1, 0xc2, 0x2d, 0x00, 0xdb, 0xc0, 0x20, 0x01, 0xb0, 0x05, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x67, 0x94, 0x13, 0x70, 0x67, 0x9c, 0x13, 0x70, 0x67, 0x6c, 0x13, 0x70, 0x60, 0x38, - 0x00, 0x2d, 0xc6, 0xc0, 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x60, 0x3c, 0x13, 0x72, 0xc2, 0x00, - 0x13, 0x70, 0x12, 0xd9, 0x00, 0x0f, 0x42, 0x40, 0xb5, 0xf0, 0x4b, 0x4b, 0xb0, 0x87, 0x68, 0x1b, - 0x1c, 0x07, 0x92, 0x05, 0x2b, 0x00, 0xd1, 0x07, 0x4b, 0x48, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x03, - 0x4a, 0x47, 0x4b, 0x48, 0x40, 0x02, 0x60, 0x1a, 0x4b, 0x47, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x06, - 0x4a, 0x46, 0x68, 0x13, 0x2b, 0x01, 0xdd, 0x02, 0x23, 0x01, 0x60, 0x13, 0xe0, 0x61, 0x4b, 0x3f, - 0x4a, 0x3d, 0x93, 0x03, 0x04, 0x0b, 0x0c, 0x1b, 0x25, 0x00, 0x26, 0x00, 0x92, 0x04, 0x93, 0x02, - 0x9a, 0x04, 0x68, 0x13, 0x2b, 0x00, 0xd1, 0x04, 0x9a, 0x03, 0x68, 0x13, 0x2b, 0x00, 0xd1, 0x00, - 0x26, 0x00, 0xf7, 0xff, 0xfe, 0xad, 0x28, 0x00, 0xd1, 0x00, 0x25, 0x00, 0x4b, 0x36, 0x68, 0x1b, - 0x2b, 0x00, 0xd0, 0x03, 0x4b, 0x35, 0x68, 0x1b, 0x2b, 0x03, 0xd0, 0x53, 0x2d, 0x00, 0xdb, 0x03, - 0x4b, 0x33, 0x78, 0x1b, 0x2b, 0x01, 0xd0, 0x04, 0x4a, 0x30, 0x23, 0x01, 0x25, 0x01, 0x60, 0x13, - 0x42, 0x6d, 0x4b, 0x2e, 0x68, 0x1b, 0x2b, 0x00, 0xd1, 0x41, 0x4b, 0x28, 0x4a, 0x2d, 0x68, 0x1b, - 0x2b, 0x00, 0xd0, 0x01, 0x4b, 0x2c, 0xe0, 0x00, 0x4b, 0x2c, 0x60, 0x13, 0x1c, 0x6b, 0xd0, 0x18, - 0x4c, 0x2b, 0x20, 0x00, 0x68, 0x23, 0x68, 0x9a, 0x23, 0x00, 0x60, 0x93, 0xf7, 0xfc, 0xfb, 0xee, - 0x4b, 0x28, 0x9a, 0x05, 0x78, 0x19, 0x48, 0x28, 0x9b, 0x02, 0x92, 0x00, 0x1c, 0x3a, 0xf7, 0xfe, - 0xfc, 0xd5, 0x1c, 0x05, 0x48, 0x25, 0xf7, 0xfc, 0xfb, 0xe1, 0x68, 0x23, 0x68, 0x9a, 0x23, 0x04, - 0x60, 0x93, 0x4a, 0x1c, 0x4b, 0x22, 0x60, 0x13, 0x2d, 0x00, 0xda, 0x02, 0x4a, 0x17, 0x23, 0x01, - 0x60, 0x13, 0x4b, 0x15, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x05, 0x4b, 0x14, 0x68, 0x1b, 0x2b, 0x00, - 0xd0, 0x01, 0x20, 0x00, 0xe0, 0x13, 0x4b, 0x11, 0x68, 0x1b, 0x2b, 0x00, 0xd1, 0x07, 0x4b, 0x10, - 0x78, 0x1b, 0x2b, 0x01, 0xd1, 0x03, 0x2d, 0x00, 0xdb, 0x01, 0x20, 0x01, 0xe0, 0x07, 0x36, 0x01, - 0x2e, 0x03, 0xdd, 0x95, 0x0f, 0xeb, 0x22, 0x01, 0x40, 0x53, 0x06, 0x1b, 0x0e, 0x18, 0xb0, 0x07, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x67, 0xc0, 0x13, 0x70, 0x67, 0x94, - 0x7f, 0xff, 0xff, 0xff, 0x13, 0x70, 0x67, 0x54, 0x13, 0x70, 0x67, 0x48, 0x13, 0x70, 0x67, 0x6c, - 0x13, 0x70, 0x67, 0x9c, 0x13, 0x70, 0x60, 0x38, 0x00, 0x98, 0x96, 0x80, 0x00, 0x2d, 0xc6, 0xc0, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x60, 0x3c, 0x13, 0x72, 0xc2, 0x00, 0x13, 0x70, 0x12, 0xd9, - 0x00, 0x0f, 0x42, 0x40, 0xb5, 0xf0, 0x4b, 0x1e, 0xb0, 0x81, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x31, - 0xf7, 0xff, 0xfe, 0x1e, 0x4b, 0x1b, 0x68, 0x1b, 0x2b, 0x00, 0xd1, 0x2b, 0x4b, 0x1a, 0x78, 0x1b, - 0x2b, 0x00, 0xd0, 0x27, 0x4e, 0x19, 0x4f, 0x1a, 0x4c, 0x1a, 0x4d, 0x1b, 0x60, 0x37, 0x79, 0x29, - 0x1c, 0x20, 0xf7, 0xfe, 0xfc, 0xe5, 0x28, 0x00, 0xdb, 0x1c, 0x60, 0x37, 0x79, 0x29, 0x1c, 0x22, - 0x1c, 0x23, 0x00, 0x88, 0x32, 0x10, 0x33, 0x50, 0x18, 0x12, 0x18, 0x1b, 0x1c, 0x20, 0xf7, 0xfe, - 0xfc, 0x9b, 0x28, 0x00, 0xdb, 0x0e, 0x4b, 0x11, 0x68, 0x18, 0x28, 0x00, 0xd0, 0x07, 0x79, 0x2b, - 0x22, 0x80, 0x33, 0x04, 0x00, 0x9b, 0x59, 0x1b, 0x01, 0x12, 0x42, 0x93, 0xd1, 0x02, 0x1e, 0x43, - 0x41, 0x98, 0xe0, 0x00, 0x20, 0x00, 0xb0, 0x01, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x70, 0x67, 0x98, 0x13, 0x70, 0x67, 0x6c, 0x13, 0x70, 0x67, 0x9c, 0x13, 0x70, 0x60, 0x38, - 0x00, 0x0f, 0x42, 0x40, 0x13, 0x72, 0xc2, 0x00, 0x13, 0x70, 0x67, 0xac, 0x13, 0x70, 0x67, 0x94, - 0xb5, 0xf0, 0x4b, 0x65, 0xb0, 0x83, 0x68, 0x1c, 0x2c, 0x00, 0xd0, 0x01, 0x20, 0x00, 0xe0, 0xbf, - 0x4a, 0x62, 0x20, 0x00, 0x92, 0x00, 0x68, 0x13, 0x68, 0x9b, 0x60, 0x9c, 0xf7, 0xfc, 0xfb, 0x36, - 0x4a, 0x5f, 0x23, 0x01, 0x42, 0x5b, 0x60, 0x13, 0x4a, 0x5e, 0x23, 0x01, 0x60, 0x13, 0x4b, 0x5e, - 0x48, 0x5e, 0x70, 0x1c, 0xf7, 0xfd, 0xfb, 0x6e, 0x49, 0x5d, 0x4a, 0x5e, 0x78, 0x0b, 0x1e, 0x58, - 0x41, 0x83, 0x60, 0x13, 0x1c, 0x1d, 0x00, 0x9f, 0xe0, 0x8e, 0x4b, 0x54, 0x68, 0x1b, 0x93, 0x01, - 0x00, 0xab, 0x9a, 0x01, 0x19, 0x5b, 0x00, 0xdb, 0x18, 0xd3, 0x4a, 0x56, 0x67, 0x5d, 0x60, 0x15, - 0x6f, 0x1b, 0x4a, 0x50, 0x2b, 0x00, 0xd0, 0x4d, 0x23, 0x01, 0x60, 0x13, 0x1c, 0x28, 0xf7, 0xff, - 0xfc, 0xa7, 0x1c, 0x04, 0x20, 0x14, 0xf7, 0xfc, 0xfd, 0x77, 0x4a, 0x48, 0x68, 0x13, 0x68, 0x9b, - 0x33, 0x44, 0x19, 0xdb, 0x68, 0x19, 0x2c, 0x00, 0xdb, 0x05, 0x4b, 0x4b, 0x1c, 0x0a, 0x40, 0x1a, - 0x4b, 0x4a, 0x42, 0x9a, 0xd0, 0x0c, 0x1c, 0x28, 0xf7, 0xff, 0xfd, 0x46, 0x1c, 0x04, 0x20, 0x14, - 0xf7, 0xfc, 0xfd, 0x62, 0x4b, 0x3d, 0x68, 0x1b, 0x68, 0x9b, 0x33, 0x44, 0x19, 0xdb, 0x68, 0x19, - 0x4e, 0x3c, 0x23, 0x01, 0x60, 0x33, 0x2c, 0x00, 0xdb, 0x54, 0x4b, 0x3f, 0x1c, 0x0a, 0x40, 0x1a, - 0x4b, 0x3e, 0x42, 0x9a, 0xd1, 0x4e, 0x00, 0xa8, 0x19, 0x40, 0x00, 0xc0, 0x9a, 0x01, 0x30, 0x58, - 0x18, 0x10, 0xf7, 0xff, 0xfa, 0x87, 0x28, 0x00, 0xd1, 0x44, 0x4b, 0x2f, 0x22, 0x01, 0x60, 0x1a, - 0x60, 0x30, 0x48, 0x37, 0xf7, 0xfc, 0xfa, 0xd2, 0x4b, 0x2c, 0x48, 0x36, 0x68, 0x1b, 0x68, 0x9a, - 0x23, 0x04, 0x60, 0x93, 0xf7, 0xfd, 0xfb, 0x0e, 0x4b, 0x33, 0x68, 0x1b, 0x1c, 0x18, 0x1e, 0x42, - 0x41, 0x90, 0xe0, 0x45, 0x23, 0x01, 0x60, 0x13, 0x4a, 0x24, 0x48, 0x30, 0x68, 0x13, 0x68, 0x9b, - 0x33, 0x44, 0x19, 0xdb, 0x68, 0x1c, 0x1c, 0x21, 0xf7, 0xfd, 0xfa, 0xfc, 0x23, 0x01, 0x42, 0x1c, - 0xd0, 0x19, 0x1c, 0x28, 0xf7, 0xff, 0xfd, 0x00, 0x1c, 0x04, 0x20, 0x14, 0xf7, 0xfc, 0xfd, 0x1c, - 0x4a, 0x1a, 0x68, 0x13, 0x68, 0x9b, 0x33, 0x44, 0x19, 0xdb, 0x68, 0x1a, 0x2c, 0x00, 0xdb, 0x04, - 0x4b, 0x1d, 0x40, 0x1a, 0x4b, 0x1d, 0x42, 0x9a, 0xd0, 0x02, 0x1c, 0x28, 0xf7, 0xff, 0xfc, 0x38, - 0x4a, 0x13, 0x23, 0x65, 0xe0, 0x04, 0x4a, 0x12, 0x68, 0x13, 0x33, 0x01, 0xd1, 0x02, 0x23, 0x64, - 0x42, 0x5b, 0x60, 0x13, 0x35, 0x01, 0x37, 0x04, 0x4a, 0x11, 0x78, 0x13, 0x2b, 0x00, 0xd1, 0x01, - 0x23, 0x01, 0xe0, 0x00, 0x23, 0x02, 0x42, 0x9d, 0xda, 0x00, 0xe7, 0x66, 0x48, 0x10, 0xf7, 0xfc, - 0xfa, 0x85, 0x9a, 0x00, 0x68, 0x13, 0x68, 0x9a, 0x23, 0x04, 0x60, 0x93, 0x4b, 0x04, 0x68, 0x18, - 0xb0, 0x03, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x67, 0x98, 0x13, 0x70, 0x60, 0x34, - 0x13, 0x70, 0x67, 0xa8, 0x13, 0x70, 0x67, 0x6c, 0x13, 0x70, 0x67, 0x9c, 0x13, 0x70, 0x65, 0xc6, - 0x13, 0x70, 0x01, 0x0c, 0x13, 0x70, 0x67, 0x78, 0x00, 0x00, 0x31, 0x05, 0x00, 0x00, 0x10, 0x05, - 0x13, 0x70, 0x12, 0xd9, 0x13, 0x70, 0x66, 0x43, 0x13, 0x70, 0x67, 0x94, 0x13, 0x70, 0x66, 0x59, - 0xb5, 0xf0, 0x4b, 0x21, 0x49, 0x21, 0x78, 0x1a, 0xb0, 0x81, 0x1e, 0x50, 0x41, 0x82, 0x60, 0x0a, - 0x1c, 0x15, 0x00, 0x96, 0x1c, 0x18, 0x21, 0x01, 0x4f, 0x1d, 0xe0, 0x28, 0x00, 0xab, 0x68, 0x3a, - 0x19, 0x5b, 0x00, 0xdb, 0x18, 0xd2, 0x67, 0x55, 0x68, 0x3b, 0x1d, 0x32, 0x68, 0x9b, 0x33, 0x44, - 0x19, 0x9b, 0x68, 0x1b, 0x42, 0x0b, 0xd0, 0x18, 0x1c, 0x28, 0xf7, 0xff, 0xfc, 0x8d, 0x1c, 0x04, - 0x20, 0x14, 0xf7, 0xfc, 0xfc, 0xa9, 0x68, 0x3b, 0x68, 0x9b, 0x33, 0x44, 0x19, 0x9b, 0x68, 0x1a, - 0x2c, 0x00, 0xdb, 0x04, 0x4b, 0x0f, 0x40, 0x1a, 0x4b, 0x0f, 0x42, 0x9a, 0xd0, 0x02, 0x1c, 0x28, - 0xf7, 0xff, 0xfb, 0xc6, 0x20, 0x65, 0x42, 0x40, 0xe0, 0x0a, 0x35, 0x01, 0x1c, 0x16, 0x78, 0x03, - 0x2b, 0x00, 0xd1, 0x01, 0x23, 0x01, 0xe0, 0x00, 0x23, 0x02, 0x42, 0x9d, 0xdb, 0xce, 0x20, 0x00, - 0xb0, 0x01, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x01, 0x0c, 0x13, 0x70, 0x67, 0x78, - 0x13, 0x70, 0x60, 0x34, 0x00, 0x00, 0x39, 0x05, 0x00, 0x00, 0x10, 0x05, 0xb5, 0xf0, 0xb0, 0x81, - 0x1c, 0x06, 0x07, 0xc2, 0xd4, 0x01, 0x20, 0x01, 0xe0, 0x38, 0x4b, 0x35, 0x68, 0x1c, 0x2c, 0x00, - 0xd0, 0x09, 0x6b, 0x60, 0x21, 0x60, 0xf7, 0xfb, 0xfc, 0xdf, 0x6b, 0x60, 0x21, 0x60, 0xf0, 0x00, - 0xf8, 0x71, 0x6b, 0xa4, 0xe7, 0xf3, 0x4c, 0x2f, 0x68, 0x23, 0x2b, 0x00, 0xd0, 0x1a, 0x6c, 0x58, - 0x21, 0x20, 0xf7, 0xfb, 0xfc, 0xd1, 0x68, 0x23, 0x21, 0x20, 0x6c, 0x58, 0xf0, 0x00, 0xf8, 0x62, - 0x68, 0x22, 0x23, 0x80, 0x04, 0x5b, 0x61, 0x13, 0x4b, 0x27, 0x68, 0x22, 0x68, 0x1b, 0x21, 0x20, - 0x6b, 0x5b, 0x61, 0x53, 0x68, 0x23, 0x6c, 0x58, 0xf7, 0xfb, 0xfc, 0x96, 0x68, 0x23, 0x4a, 0x23, - 0x69, 0x9b, 0x60, 0x13, 0x4b, 0x1e, 0x68, 0x18, 0xf7, 0xfc, 0xfc, 0xc6, 0x28, 0x00, 0xd0, 0x05, - 0x4b, 0x1f, 0x20, 0x05, 0x68, 0x1a, 0x23, 0x00, 0x64, 0x13, 0x42, 0x40, 0x07, 0x73, 0xd5, 0x24, - 0x4a, 0x1b, 0x25, 0x80, 0x4f, 0x1b, 0x24, 0x00, 0x46, 0x94, 0x01, 0xad, 0x46, 0x62, 0x68, 0x13, - 0x00, 0xa2, 0x68, 0x9b, 0x33, 0x44, 0x18, 0x99, 0x68, 0x3b, 0x68, 0x0a, 0x42, 0x9c, 0xd1, 0x0c, - 0x21, 0x01, 0x42, 0x0a, 0xd1, 0x0e, 0x4b, 0x14, 0x22, 0x20, 0x60, 0x19, 0x49, 0x13, 0x20, 0x01, - 0x68, 0x0b, 0x42, 0x40, 0x43, 0x93, 0x60, 0x0b, 0xe0, 0x04, 0x4b, 0x11, 0x40, 0x13, 0x2b, 0x03, - 0xd1, 0x00, 0x60, 0x0d, 0x34, 0x01, 0x2c, 0x04, 0xd1, 0xe0, 0x28, 0x00, 0xd0, 0x04, 0x23, 0x12, - 0x42, 0x1e, 0xd0, 0x01, 0x20, 0x06, 0x42, 0x40, 0xb0, 0x01, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x67, 0x88, 0x13, 0x70, 0x67, 0x8c, 0x13, 0x70, 0x67, 0xc4, 0x13, 0x70, 0x67, 0x90, - 0x13, 0x70, 0x60, 0x34, 0x13, 0x70, 0x67, 0x78, 0x13, 0x70, 0x67, 0x6c, 0x0d, 0x80, 0x00, 0xc0, - 0x00, 0x00, 0x20, 0x03, 0x47, 0x70, 0x46, 0xc0, 0x47, 0x70, 0x46, 0xc0, 0xb5, 0x00, 0x4b, 0x04, - 0xb0, 0x81, 0x1c, 0x01, 0x68, 0x18, 0xf7, 0xfb, 0xfc, 0x17, 0xb0, 0x01, 0xbc, 0x01, 0x47, 0x00, - 0x13, 0x70, 0x60, 0x40, 0xb5, 0x00, 0x4b, 0x0d, 0x1c, 0x01, 0xb0, 0x81, 0x68, 0x18, 0x22, 0x20, - 0xf7, 0xfb, 0xfc, 0x46, 0x28, 0x00, 0xd1, 0x0d, 0x48, 0x09, 0xf7, 0xfb, 0xfc, 0x15, 0xf0, 0x00, - 0xf9, 0x29, 0x20, 0xc8, 0xf7, 0xfc, 0xfb, 0xd8, 0xf0, 0x00, 0xf9, 0x18, 0x20, 0xc8, 0xf7, 0xfc, - 0xfb, 0xd3, 0xe7, 0xf4, 0xb0, 0x01, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x40, - 0x13, 0x70, 0x66, 0x76, 0xb5, 0x00, 0xb0, 0x81, 0xf7, 0xfb, 0xfb, 0xf6, 0xb0, 0x01, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xb5, 0x00, 0xb0, 0x81, 0xf7, 0xfb, 0xfb, 0xee, 0xb0, 0x01, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xb5, 0x00, 0xb0, 0x81, 0xf7, 0xfb, 0xfb, 0xe6, 0xb0, 0x01, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xb5, 0x10, 0x1c, 0x04, 0xf7, 0xfb, 0xfb, 0xfe, 0x1c, 0x20, 0xbc, 0x10, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0x10, 0x1c, 0x04, 0xf7, 0xfb, 0xfb, 0xf6, 0x1c, 0x20, 0xbc, 0x10, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0x10, 0x1c, 0x04, 0xf7, 0xfb, 0xfb, 0xee, 0x1c, 0x20, 0xbc, 0x10, - 0xbc, 0x02, 0x47, 0x08, 0xb5, 0x00, 0x21, 0xe0, 0xb0, 0x81, 0x48, 0x07, 0x02, 0x09, 0xf7, 0xfb, - 0xfb, 0xa3, 0x4b, 0x06, 0x60, 0x18, 0x28, 0x00, 0xdb, 0x01, 0x20, 0x00, 0xe0, 0x01, 0x20, 0x01, - 0x42, 0x40, 0xb0, 0x01, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0xa0, 0x00, 0x13, 0x70, 0x60, 0x40, - 0xb5, 0xf0, 0x4b, 0x27, 0x1c, 0x06, 0x68, 0x18, 0xb0, 0x87, 0x91, 0x05, 0x28, 0x00, 0xd0, 0x01, - 0xf7, 0xfc, 0xf8, 0xe0, 0x4f, 0x23, 0x4a, 0x22, 0x68, 0x3d, 0x23, 0x00, 0x60, 0x13, 0x2d, 0x00, - 0xd1, 0x17, 0xf7, 0xff, 0xfd, 0xbd, 0x4c, 0x20, 0x1c, 0x20, 0xf7, 0xfc, 0xfd, 0xa3, 0x4b, 0x1f, - 0x1c, 0x02, 0x60, 0x18, 0x28, 0x00, 0xd0, 0x2d, 0x68, 0x23, 0x92, 0x00, 0x9a, 0x05, 0x48, 0x1c, - 0x92, 0x01, 0x21, 0x00, 0x22, 0x00, 0x95, 0x02, 0xf0, 0x00, 0xfb, 0xfc, 0x60, 0x38, 0x28, 0x00, - 0xd0, 0x20, 0x4d, 0x18, 0x68, 0x2c, 0x2c, 0x00, 0xd0, 0x0b, 0x48, 0x17, 0x1c, 0x31, 0x22, 0x06, - 0xf0, 0x00, 0xfe, 0xc8, 0x28, 0x00, 0xd0, 0x16, 0x1c, 0x20, 0xf0, 0x00, 0xfa, 0x0b, 0x23, 0x00, - 0x60, 0x2b, 0x4b, 0x0c, 0x1c, 0x31, 0x68, 0x18, 0xf0, 0x00, 0xfa, 0x14, 0x4b, 0x0d, 0x60, 0x18, - 0x28, 0x00, 0xd0, 0x04, 0x48, 0x0c, 0x1c, 0x31, 0x22, 0x06, 0xf0, 0x00, 0xfe, 0xdf, 0x4b, 0x09, - 0x68, 0x1c, 0xe0, 0x00, 0x24, 0x00, 0xb0, 0x07, 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x70, 0x67, 0xd0, 0x13, 0x70, 0x67, 0xd4, 0x13, 0x72, 0xc3, 0xa0, 0x13, 0x72, 0xc3, 0xa4, - 0x13, 0x70, 0x4b, 0x61, 0x13, 0x70, 0x67, 0xd8, 0x13, 0x70, 0x60, 0x44, 0xb5, 0x30, 0x4b, 0x0f, - 0xb0, 0x81, 0x68, 0x18, 0x28, 0x00, 0xd0, 0x01, 0xf7, 0xfc, 0xf8, 0x84, 0x4c, 0x0c, 0x4b, 0x0b, - 0x68, 0x20, 0x25, 0x00, 0x60, 0x1d, 0x28, 0x00, 0xd0, 0x02, 0xf0, 0x00, 0xf9, 0xd3, 0x60, 0x25, - 0x4b, 0x08, 0x68, 0x18, 0x28, 0x00, 0xd0, 0x01, 0xf0, 0x00, 0xfa, 0x50, 0x4a, 0x05, 0x23, 0x00, - 0xb0, 0x01, 0x60, 0x13, 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x70, 0x67, 0xd0, - 0x13, 0x70, 0x67, 0xd8, 0x13, 0x70, 0x67, 0xd4, 0xb5, 0x10, 0x4c, 0x0b, 0x68, 0x20, 0x28, 0x00, - 0xd0, 0x03, 0xf0, 0x00, 0xf9, 0xb7, 0x23, 0x00, 0x60, 0x23, 0x4c, 0x08, 0x68, 0x23, 0x2b, 0x00, - 0xd1, 0x03, 0x48, 0x07, 0xf7, 0xfc, 0xf8, 0x62, 0x60, 0x20, 0x4a, 0x06, 0x23, 0x01, 0x42, 0x5b, - 0x60, 0x13, 0xbc, 0x10, 0xbc, 0x01, 0x47, 0x00, 0x13, 0x70, 0x67, 0xd8, 0x13, 0x70, 0x67, 0xd0, - 0x00, 0x00, 0x80, 0x20, 0x13, 0x70, 0x60, 0x10, 0xb5, 0xf0, 0x4f, 0x0f, 0x1c, 0x1e, 0x68, 0x3b, - 0x1c, 0x15, 0x1c, 0x0c, 0x1c, 0x30, 0x1c, 0x19, 0x43, 0x51, 0xb0, 0x81, 0xf7, 0xfb, 0xfb, 0x24, - 0x1c, 0x20, 0x1c, 0x29, 0x1c, 0x32, 0xf7, 0xff, 0xfc, 0x17, 0x28, 0x00, 0xd1, 0x01, 0x20, 0x01, - 0xe0, 0x06, 0x68, 0x3b, 0x1c, 0x30, 0x1c, 0x19, 0x43, 0x69, 0xf7, 0xfb, 0xfa, 0xf5, 0x20, 0x00, - 0xb0, 0x01, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x72, 0xc3, 0xa0, 0xb5, 0x00, 0xb0, 0x81, - 0x20, 0x81, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00, 0xf7, 0xfb, 0xfb, 0x2e, 0xb0, 0x01, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xb5, 0x00, 0xb0, 0x81, 0x20, 0x80, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00, - 0xf7, 0xfb, 0xfb, 0x22, 0xb0, 0x01, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0xb5, 0x30, 0x1c, 0x0d, - 0x1c, 0x04, 0x1c, 0x13, 0xb0, 0x81, 0x1c, 0x2a, 0x1c, 0x21, 0x20, 0x10, 0xf7, 0xfb, 0xfb, 0x14, - 0xb0, 0x01, 0xbc, 0x30, 0xbc, 0x02, 0x47, 0x08, 0xb5, 0x00, 0x1c, 0x03, 0xb0, 0x81, 0x1c, 0x0a, - 0x20, 0x06, 0x1c, 0x19, 0x23, 0x00, 0xf7, 0xfb, 0xfb, 0x07, 0xb0, 0x01, 0xbc, 0x01, 0x47, 0x00, - 0xb5, 0x00, 0x1c, 0x03, 0xb0, 0x81, 0x1c, 0x0a, 0x20, 0x05, 0x1c, 0x19, 0x23, 0x00, 0xf7, 0xfb, - 0xfa, 0xfb, 0xb0, 0x01, 0xbc, 0x01, 0x47, 0x00, 0xb5, 0x30, 0xb0, 0x81, 0x1c, 0x04, 0x1c, 0x0d, - 0x1c, 0x13, 0x2a, 0x00, 0xdd, 0x04, 0x20, 0x09, 0x1c, 0x21, 0x1c, 0x2a, 0xf7, 0xfb, 0xfa, 0xec, - 0xb0, 0x01, 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, 0xb5, 0x30, 0xb0, 0x81, 0x1c, 0x04, 0x1c, 0x0d, - 0x1c, 0x13, 0x2a, 0x00, 0xdd, 0x04, 0x20, 0x02, 0x1c, 0x21, 0x1c, 0x2a, 0xf7, 0xfb, 0xfa, 0xdc, - 0xb0, 0x01, 0xbc, 0x30, 0xbc, 0x01, 0x47, 0x00, 0xb5, 0x00, 0xb0, 0x81, 0x20, 0x12, 0x21, 0x00, - 0x22, 0x00, 0x23, 0x00, 0xf7, 0xfb, 0xfa, 0xd0, 0xb0, 0x01, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0xb5, 0x00, 0xb0, 0x81, 0x20, 0x11, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00, 0xf7, 0xfb, 0xfa, 0xc4, - 0xb0, 0x01, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0xb5, 0x00, 0xb0, 0x81, 0x20, 0x01, 0x21, 0x00, - 0x22, 0x00, 0x23, 0x00, 0xf7, 0xfb, 0xfa, 0xb8, 0xb0, 0x01, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0xb5, 0x00, 0x1c, 0x03, 0xb0, 0x81, 0x1c, 0x0a, 0x20, 0x00, 0x1c, 0x19, 0x23, 0x00, 0xf7, 0xfb, - 0xfa, 0xab, 0xb0, 0x01, 0xbc, 0x01, 0x47, 0x00, 0xb5, 0xf0, 0xb0, 0x8d, 0x90, 0x04, 0x92, 0x03, - 0x93, 0x02, 0x68, 0x05, 0x1c, 0x0a, 0x6a, 0x6e, 0x1e, 0xb3, 0x40, 0xda, 0x04, 0x13, 0x0c, 0x1b, - 0x93, 0x06, 0x9b, 0x04, 0x7a, 0x28, 0x68, 0x5a, 0x9b, 0x06, 0x6a, 0x2c, 0x33, 0x80, 0x00, 0x5b, - 0x5a, 0xd3, 0x68, 0x6f, 0x93, 0x0a, 0x2b, 0x00, 0xd1, 0x00, 0xe0, 0xc5, 0x1e, 0x63, 0x40, 0xc3, - 0x1a, 0x36, 0x93, 0x08, 0x96, 0x07, 0x1e, 0x83, 0x1c, 0x0a, 0x9e, 0x08, 0x40, 0xda, 0x08, 0xbb, - 0x40, 0x16, 0x3b, 0x01, 0x1c, 0x0a, 0x40, 0x1a, 0x92, 0x09, 0xd1, 0x02, 0x9b, 0x03, 0x93, 0x0b, - 0xe0, 0x89, 0x9b, 0x07, 0x9a, 0x0a, 0x40, 0x9a, 0x92, 0x05, 0x6a, 0xeb, 0x18, 0xf3, 0x18, 0x99, - 0x4a, 0x58, 0x92, 0x01, 0x68, 0x13, 0x6c, 0xef, 0x42, 0x8b, 0xd1, 0x05, 0x4a, 0x56, 0x4b, 0x57, - 0x68, 0x12, 0x68, 0x19, 0x1c, 0x38, 0xe0, 0x14, 0x6b, 0x2c, 0x6b, 0xa8, 0x22, 0x01, 0x1c, 0x3b, - 0xf0, 0x00, 0xf8, 0xa6, 0x1c, 0x04, 0x28, 0x00, 0xd0, 0x00, 0xe0, 0x96, 0x6a, 0xeb, 0x9a, 0x05, - 0x18, 0xf3, 0x18, 0x9b, 0x9a, 0x01, 0x60, 0x13, 0x4b, 0x4c, 0x6c, 0xe9, 0x68, 0x18, 0x4b, 0x4a, - 0x68, 0x1a, 0xf0, 0x00, 0xfd, 0x7b, 0x9b, 0x09, 0x00, 0x9a, 0x68, 0x6b, 0x1a, 0x9c, 0x9b, 0x02, - 0x42, 0x9c, 0xd9, 0x00, 0x1c, 0x1c, 0x6c, 0xe9, 0x98, 0x03, 0x18, 0x89, 0x1c, 0x22, 0xf0, 0x00, - 0xfd, 0x6d, 0x9a, 0x02, 0x9b, 0x03, 0x1b, 0x12, 0x92, 0x02, 0x9a, 0x08, 0x19, 0x1c, 0x36, 0x01, - 0x94, 0x0b, 0x42, 0x96, 0xd9, 0x47, 0x9b, 0x02, 0x2b, 0x00, 0xd0, 0x44, 0x9b, 0x06, 0x33, 0x01, - 0x04, 0x1b, 0x0c, 0x1b, 0x93, 0x06, 0x9b, 0x04, 0x68, 0x5a, 0x9b, 0x06, 0x33, 0x80, 0x00, 0x5b, - 0x5a, 0xd3, 0x93, 0x0a, 0x2b, 0x00, 0xd0, 0x5f, 0x26, 0x00, 0xe0, 0x34, 0x7a, 0x2b, 0x9f, 0x02, - 0x6a, 0x2a, 0x40, 0xdf, 0x19, 0xbb, 0x42, 0x93, 0xd9, 0x00, 0x1b, 0x97, 0x9a, 0x07, 0x6a, 0xe9, - 0x9b, 0x0a, 0x18, 0x71, 0x40, 0x93, 0x18, 0xc9, 0x6b, 0x2c, 0x6b, 0xa8, 0x1c, 0x3a, 0x9b, 0x0b, - 0xf0, 0x00, 0xf8, 0x56, 0x1c, 0x04, 0x28, 0x00, 0xd1, 0x47, 0x7a, 0x2b, 0x1c, 0x39, 0x40, 0x99, - 0x9b, 0x02, 0x9a, 0x08, 0x1a, 0x5b, 0x19, 0xf6, 0x93, 0x02, 0x42, 0x96, 0xd9, 0x10, 0x2b, 0x00, - 0xd0, 0x0e, 0x9b, 0x06, 0x33, 0x01, 0x04, 0x1b, 0x0c, 0x1b, 0x93, 0x06, 0x9b, 0x04, 0x68, 0x5a, - 0x9b, 0x06, 0x33, 0x80, 0x00, 0x5b, 0x5a, 0xd3, 0x93, 0x0a, 0x2b, 0x00, 0xd0, 0x2c, 0x26, 0x00, - 0x9a, 0x0b, 0x18, 0x52, 0x92, 0x0b, 0x68, 0x6b, 0x9a, 0x02, 0x42, 0x9a, 0xd2, 0xc6, 0x2a, 0x00, - 0xd1, 0x01, 0x24, 0x00, 0xe0, 0x21, 0x9b, 0x07, 0x9f, 0x0a, 0x6a, 0xe9, 0x40, 0x9f, 0x18, 0x71, - 0x6b, 0x2c, 0x6b, 0xa8, 0x19, 0xc9, 0x6c, 0xeb, 0x22, 0x01, 0xf0, 0x00, 0xf8, 0x21, 0x1c, 0x04, - 0x28, 0x00, 0xd1, 0x12, 0x6a, 0xeb, 0x4a, 0x0b, 0x18, 0xf3, 0x19, 0xdb, 0x60, 0x13, 0x4b, 0x0b, - 0x6c, 0xe9, 0x68, 0x18, 0x4b, 0x08, 0x68, 0x1a, 0xf0, 0x00, 0xfc, 0xf8, 0x6c, 0xe9, 0x98, 0x0b, - 0x9a, 0x02, 0xf0, 0x00, 0xfc, 0xf3, 0xe0, 0x00, 0x24, 0x01, 0xb0, 0x0d, 0x1c, 0x20, 0xbc, 0xf0, - 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x4c, 0x13, 0x70, 0x67, 0xe0, 0x13, 0x70, 0x67, 0xdc, - 0x47, 0x20, 0x46, 0xc0, 0xb5, 0x10, 0x68, 0x02, 0x1c, 0x04, 0x6d, 0x13, 0x3b, 0x01, 0x65, 0x13, - 0x68, 0x40, 0xf7, 0xfb, 0xfe, 0x9f, 0x1c, 0x20, 0xf7, 0xfb, 0xfe, 0x9c, 0xbc, 0x10, 0xbc, 0x01, - 0x47, 0x00, 0x46, 0xc0, 0xb5, 0xf0, 0x1c, 0x03, 0x33, 0x48, 0x88, 0x1a, 0x7a, 0x03, 0xb0, 0x83, - 0x41, 0x1a, 0x92, 0x01, 0x23, 0x01, 0x4a, 0x30, 0x42, 0x5b, 0x27, 0x00, 0x1c, 0x05, 0x1c, 0x0e, - 0x60, 0x13, 0x97, 0x00, 0xe0, 0x4f, 0x68, 0x2b, 0x19, 0xdb, 0x7b, 0x1b, 0x2b, 0x00, 0xd0, 0x45, - 0x6a, 0xe9, 0x9a, 0x00, 0x31, 0x01, 0x18, 0x89, 0x6b, 0xa8, 0x22, 0x01, 0x6c, 0xeb, 0x6b, 0x2c, - 0xf0, 0x00, 0xf8, 0x52, 0x6c, 0xe9, 0x1c, 0x30, 0x22, 0x06, 0xf0, 0x00, 0xfc, 0x83, 0x28, 0x00, - 0xd1, 0x34, 0x20, 0x0c, 0xf7, 0xfb, 0xfe, 0x7a, 0x1c, 0x06, 0x28, 0x00, 0xd1, 0x09, 0x48, 0x1f, - 0xf7, 0xfb, 0xf9, 0x3a, 0x48, 0x1e, 0xf7, 0xfb, 0xf9, 0x37, 0x48, 0x1e, 0xf7, 0xfb, 0xf9, 0x34, - 0xe0, 0x2d, 0x1c, 0x2b, 0x33, 0x48, 0x60, 0x05, 0x60, 0x87, 0x88, 0x18, 0xf7, 0xfb, 0xfe, 0x66, - 0x1c, 0x03, 0x60, 0x70, 0x28, 0x00, 0xd1, 0x0c, 0x48, 0x14, 0xf7, 0xfb, 0xf9, 0x25, 0x48, 0x14, - 0xf7, 0xfb, 0xf9, 0x22, 0x48, 0x13, 0xf7, 0xfb, 0xf9, 0x1f, 0x1c, 0x30, 0xf7, 0xfb, 0xfe, 0x4a, - 0xe0, 0x14, 0x6a, 0xe9, 0x9a, 0x00, 0x31, 0x01, 0x18, 0x89, 0x6b, 0xa8, 0x6b, 0x2c, 0x9a, 0x01, - 0xf0, 0x00, 0xf8, 0x1a, 0x6d, 0x2b, 0x33, 0x01, 0x65, 0x2b, 0xe0, 0x08, 0x9b, 0x00, 0x9a, 0x01, - 0x37, 0x01, 0x18, 0x9b, 0x93, 0x00, 0x8f, 0xab, 0x42, 0x9f, 0xd3, 0xac, 0x26, 0x00, 0xb0, 0x03, - 0x1c, 0x30, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x70, 0x60, 0x4c, 0x13, 0x70, 0x66, 0x95, - 0x13, 0x70, 0x66, 0xa1, 0x13, 0x70, 0x66, 0x41, 0x47, 0x20, 0x46, 0xc0, 0xb5, 0x10, 0x6d, 0x03, - 0x1c, 0x04, 0x2b, 0x00, 0xd0, 0x09, 0x48, 0x0d, 0xf7, 0xfb, 0xf8, 0xee, 0x48, 0x0c, 0xf7, 0xfb, - 0xf8, 0xeb, 0x48, 0x0c, 0xf7, 0xfb, 0xf8, 0xe8, 0xe0, 0x0d, 0x68, 0x00, 0xf7, 0xfb, 0xfe, 0x12, - 0x6c, 0xe0, 0xf7, 0xfb, 0xfe, 0x0f, 0x6c, 0x60, 0x28, 0x00, 0xd0, 0x01, 0xf7, 0xfb, 0xfe, 0x0a, - 0x1c, 0x20, 0xf7, 0xfb, 0xfe, 0x07, 0xbc, 0x10, 0xbc, 0x01, 0x47, 0x00, 0x13, 0x70, 0x66, 0x95, - 0x13, 0x70, 0x66, 0xb3, 0x13, 0x70, 0x66, 0x41, 0xb5, 0xf0, 0xb0, 0x85, 0x90, 0x03, 0x20, 0x54, - 0x91, 0x02, 0x92, 0x01, 0x1c, 0x1f, 0xf7, 0xfb, 0xfe, 0x01, 0x1c, 0x05, 0x2f, 0x00, 0xd1, 0x02, - 0x20, 0x80, 0x00, 0x80, 0xe0, 0x00, 0x1c, 0x38, 0xf7, 0xfb, 0xfd, 0xf8, 0x23, 0x80, 0x02, 0x1b, - 0x61, 0x2b, 0x1c, 0x06, 0x23, 0x00, 0x33, 0x01, 0x06, 0x1b, 0x0e, 0x1b, 0x2b, 0x10, 0xd1, 0xfa, - 0x23, 0x0f, 0x75, 0x2b, 0x4b, 0x81, 0x60, 0x2e, 0x61, 0xeb, 0x9a, 0x0b, 0x4b, 0x80, 0x62, 0xea, - 0x60, 0x1f, 0x9b, 0x0a, 0x20, 0x00, 0x0b, 0xd9, 0x17, 0xfa, 0x1c, 0x3b, 0xf0, 0x00, 0xfb, 0xae, - 0x61, 0xa9, 0x9c, 0x0c, 0x2c, 0x00, 0xd0, 0x32, 0x1c, 0x30, 0x21, 0x00, 0x1c, 0x3a, 0xf0, 0x00, - 0xfc, 0x49, 0x23, 0x57, 0x70, 0x33, 0x23, 0x42, 0x70, 0x73, 0x23, 0x46, 0x70, 0xb3, 0x23, 0x53, - 0x70, 0xf3, 0x1c, 0x3c, 0x23, 0x00, 0xe0, 0x03, 0x33, 0x01, 0x06, 0x1b, 0x0e, 0x1b, 0x08, 0x64, - 0x2c, 0x00, 0xd1, 0xf9, 0x3b, 0x01, 0x72, 0x33, 0x9a, 0x0a, 0x21, 0x80, 0x0e, 0x13, 0x71, 0x33, - 0x0c, 0x13, 0x71, 0x73, 0x0a, 0x13, 0x71, 0xf2, 0x71, 0xb3, 0x69, 0xac, 0x22, 0x06, 0x20, 0x06, - 0x02, 0x49, 0x1c, 0x0b, 0x40, 0x83, 0x42, 0x9c, 0xd3, 0x05, 0x1c, 0x53, 0x06, 0x1b, 0x0e, 0x1a, - 0x30, 0x01, 0x2a, 0x0b, 0xd1, 0xf5, 0x7d, 0x2b, 0x18, 0xd3, 0x72, 0x73, 0xe0, 0x06, 0x6a, 0xe9, - 0x98, 0x01, 0x22, 0x01, 0x1c, 0x33, 0x9c, 0x03, 0xf0, 0x00, 0xf8, 0xca, 0x78, 0x33, 0x78, 0x72, - 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x78, 0xb3, 0x02, 0x1b, 0x43, 0x13, 0x78, 0xf2, 0x43, 0x1a, - 0x4b, 0x58, 0x42, 0x9a, 0xd0, 0x04, 0x48, 0x58, 0xf7, 0xfb, 0xf8, 0x56, 0x48, 0x57, 0xe0, 0x2f, - 0x4b, 0x57, 0x68, 0x1b, 0x42, 0x59, 0x41, 0x59, 0x29, 0x00, 0xd0, 0x36, 0x2f, 0x00, 0xd0, 0x11, - 0x7a, 0x30, 0x1c, 0x3a, 0x33, 0x01, 0x06, 0x1b, 0x08, 0x52, 0x0e, 0x1b, 0x2a, 0x00, 0xd1, 0xf9, - 0x3b, 0x01, 0x06, 0x1b, 0x0e, 0x1b, 0x42, 0x98, 0xd0, 0x04, 0x48, 0x4b, 0xf7, 0xfb, 0xf8, 0x3c, - 0x48, 0x4c, 0xe0, 0x15, 0x29, 0x00, 0xd0, 0x20, 0x9a, 0x0a, 0x2a, 0x00, 0xd0, 0x1d, 0x79, 0x32, - 0x79, 0x73, 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x79, 0xb2, 0x9c, 0x0a, 0x02, 0x12, 0x43, 0x1a, - 0x79, 0xf3, 0x43, 0x13, 0x42, 0xa3, 0xd0, 0x10, 0x48, 0x3f, 0xf7, 0xfb, 0xf8, 0x25, 0x48, 0x42, - 0xf7, 0xfb, 0xf8, 0x22, 0x48, 0x41, 0xf7, 0xfb, 0xf8, 0x1f, 0x1c, 0x28, 0xf7, 0xfb, 0xfd, 0x4a, - 0x1c, 0x30, 0xf7, 0xfb, 0xfd, 0x47, 0x25, 0x00, 0xe0, 0x63, 0x7a, 0x33, 0x24, 0x01, 0x1c, 0x27, - 0x40, 0x9f, 0x60, 0x6f, 0x7a, 0x33, 0x69, 0x29, 0x72, 0x2b, 0x79, 0x33, 0x79, 0x72, 0x06, 0x1b, - 0x04, 0x12, 0x43, 0x1a, 0x79, 0xb3, 0x79, 0xf0, 0x02, 0x1b, 0x43, 0x13, 0x43, 0x18, 0x60, 0xe8, - 0xf0, 0x00, 0xfa, 0x72, 0x1c, 0x39, 0x43, 0x41, 0x61, 0xa9, 0x7a, 0x72, 0x7d, 0x2b, 0x62, 0x6a, - 0x40, 0x94, 0x1a, 0xd2, 0x69, 0xeb, 0x40, 0xd1, 0x40, 0xd3, 0x04, 0x1b, 0x0c, 0x1b, 0x04, 0x3a, - 0x85, 0x6b, 0x0c, 0x12, 0x33, 0x80, 0x85, 0x29, 0x00, 0x5b, 0x1e, 0x51, 0x18, 0xc9, 0x42, 0x52, - 0x1c, 0x2b, 0x40, 0x11, 0x33, 0x48, 0x80, 0x19, 0x62, 0x2c, 0x9a, 0x03, 0x63, 0x2a, 0x9b, 0x02, - 0x63, 0x6b, 0x9a, 0x01, 0x8d, 0x2b, 0x63, 0xaa, 0x08, 0xda, 0x7a, 0x2b, 0x1a, 0xa4, 0x40, 0xdc, - 0x64, 0x2c, 0x9b, 0x0c, 0x2b, 0x00, 0xd1, 0x01, 0x64, 0x6b, 0xe0, 0x0b, 0x1e, 0x78, 0x18, 0x80, - 0x42, 0x7b, 0x40, 0x18, 0xf7, 0xfb, 0xfd, 0x0a, 0x8d, 0x2a, 0x64, 0x68, 0x08, 0xd2, 0x21, 0xff, - 0xf0, 0x00, 0xfb, 0x78, 0x1c, 0x2b, 0x33, 0x48, 0x88, 0x19, 0x6c, 0x28, 0x7a, 0x2b, 0x38, 0x01, - 0x41, 0x19, 0xf0, 0x00, 0xfa, 0x31, 0x68, 0x6b, 0x04, 0x00, 0x0c, 0x00, 0x3b, 0x0c, 0x87, 0xa8, - 0x42, 0x98, 0xd9, 0x00, 0x87, 0xab, 0x68, 0x68, 0xf7, 0xfb, 0xfc, 0xf0, 0x23, 0x00, 0x64, 0xe8, - 0x65, 0x2b, 0xb0, 0x05, 0x1c, 0x28, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x00, 0x04, 0x60, 0x90, - 0x13, 0x70, 0x67, 0xe0, 0x57, 0x42, 0x46, 0x53, 0x13, 0x70, 0x66, 0x95, 0x13, 0x70, 0x66, 0xdf, - 0x13, 0x70, 0x67, 0xe4, 0x13, 0x70, 0x66, 0xe9, 0x13, 0x70, 0x67, 0x06, 0x13, 0x70, 0x66, 0x41, - 0x47, 0x20, 0x46, 0xc0, 0xb5, 0xf0, 0xb0, 0xa5, 0x90, 0x0c, 0x1c, 0x18, 0x92, 0x0a, 0x93, 0x09, - 0x91, 0x0b, 0xf7, 0xfb, 0xfc, 0xcb, 0x4b, 0x8c, 0x22, 0x01, 0x4c, 0x8c, 0x42, 0x52, 0x60, 0x1a, - 0x68, 0x23, 0x1c, 0x05, 0x2b, 0x00, 0xd1, 0x03, 0x98, 0x09, 0xf7, 0xfb, 0xfc, 0xbf, 0x60, 0x20, - 0x4b, 0x87, 0x99, 0x09, 0x98, 0x0a, 0x60, 0x19, 0x22, 0x01, 0x21, 0x00, 0x1c, 0x2b, 0x9c, 0x0c, - 0xf0, 0x00, 0xf9, 0x18, 0x28, 0x00, 0xd0, 0x00, 0xe0, 0xf4, 0x23, 0xff, 0x00, 0x5b, 0x5c, 0xeb, - 0x2b, 0x55, 0xd1, 0x1b, 0x4b, 0x7f, 0x5c, 0xeb, 0x2b, 0xaa, 0xd1, 0x17, 0x1c, 0xe8, 0x49, 0x7e, - 0x22, 0x04, 0xf0, 0x00, 0xfb, 0x9d, 0x28, 0x00, 0xd0, 0x10, 0x4c, 0x7c, 0x1c, 0x28, 0x30, 0x36, - 0x1c, 0x21, 0x22, 0x03, 0xf0, 0x00, 0xfb, 0x94, 0x28, 0x00, 0xd0, 0x07, 0x1c, 0x28, 0x30, 0x52, - 0x1c, 0x21, 0x22, 0x03, 0xf0, 0x00, 0xfb, 0x8c, 0x28, 0x00, 0xd1, 0x05, 0xa8, 0x14, 0x21, 0x00, - 0x22, 0x40, 0xf0, 0x00, 0xfa, 0xff, 0xe0, 0x06, 0x22, 0xdf, 0x00, 0x52, 0x18, 0xa9, 0xa8, 0x14, - 0x22, 0x40, 0xf0, 0x00, 0xfa, 0xb3, 0x23, 0x01, 0x21, 0xe4, 0x42, 0x5b, 0x24, 0x00, 0x00, 0x49, - 0xae, 0x14, 0x93, 0x11, 0x94, 0x12, 0x91, 0x07, 0x78, 0x2b, 0x78, 0x6a, 0x06, 0x1b, 0x04, 0x12, - 0x43, 0x1a, 0x78, 0xab, 0x7a, 0x37, 0x02, 0x1b, 0x43, 0x13, 0x78, 0xea, 0x7a, 0x70, 0x43, 0x1a, - 0x4b, 0x63, 0x7a, 0xb1, 0x7a, 0xf4, 0x42, 0x9a, 0xd0, 0x03, 0x79, 0x33, 0x2b, 0x00, 0xd1, 0x00, - 0xe0, 0xa3, 0x04, 0x0a, 0x02, 0x03, 0x43, 0x13, 0x43, 0x3b, 0x1c, 0x1f, 0x79, 0x33, 0x06, 0x22, - 0x43, 0x17, 0x2b, 0x0f, 0xd1, 0x69, 0x22, 0xe3, 0x21, 0x00, 0x00, 0x52, 0x91, 0x13, 0x92, 0x08, - 0x19, 0xc9, 0x91, 0x05, 0x98, 0x0a, 0x22, 0x01, 0x1c, 0x2b, 0x9c, 0x0c, 0xf0, 0x00, 0xf8, 0xb2, - 0x28, 0x00, 0xd0, 0x00, 0xe0, 0x8e, 0x49, 0x53, 0x9c, 0x07, 0x5c, 0x6a, 0x5d, 0x2b, 0x99, 0x08, - 0x04, 0x1b, 0x02, 0x12, 0x43, 0x1a, 0x4c, 0x50, 0x5c, 0x6b, 0x99, 0x05, 0x43, 0x1a, 0x5d, 0x2b, - 0x98, 0x0a, 0x06, 0x1b, 0x43, 0x1a, 0x18, 0x8a, 0x23, 0xeb, 0x92, 0x05, 0x00, 0x5b, 0x5c, 0xeb, - 0x1c, 0x11, 0x93, 0x0d, 0x4b, 0x49, 0x22, 0x01, 0x5c, 0xeb, 0x9c, 0x0c, 0x93, 0x0e, 0x23, 0xec, - 0x00, 0x5b, 0x5c, 0xeb, 0x93, 0x0f, 0x4b, 0x46, 0x5c, 0xeb, 0x93, 0x10, 0x1c, 0x2b, 0xf0, 0x00, - 0xf8, 0x89, 0x28, 0x00, 0xd1, 0x66, 0x78, 0x2b, 0x78, 0x6a, 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, - 0x78, 0xab, 0x02, 0x1b, 0x43, 0x13, 0x78, 0xea, 0x43, 0x1a, 0x4b, 0x39, 0x42, 0x9a, 0xd1, 0x12, - 0x99, 0x12, 0x9a, 0x2b, 0x42, 0x91, 0xd1, 0x05, 0x9b, 0x05, 0x9c, 0x2c, 0x90, 0x00, 0x93, 0x01, - 0x94, 0x02, 0xe0, 0x38, 0x99, 0x05, 0x9a, 0x11, 0x42, 0x91, 0xd0, 0x04, 0x9b, 0x12, 0x9c, 0x05, - 0x33, 0x01, 0x93, 0x12, 0x94, 0x11, 0x99, 0x0e, 0x9c, 0x0f, 0x02, 0x0b, 0x04, 0x22, 0x99, 0x0d, - 0x43, 0x13, 0x9c, 0x10, 0x43, 0x0b, 0x06, 0x22, 0x1c, 0x19, 0x43, 0x11, 0xd0, 0x35, 0x9a, 0x13, - 0x32, 0x01, 0x92, 0x13, 0x2a, 0x08, 0xd1, 0x9b, 0xe0, 0x2f, 0x98, 0x0a, 0x1c, 0x39, 0x22, 0x01, - 0x1c, 0x2b, 0x9c, 0x0c, 0xf0, 0x00, 0xf8, 0x4e, 0x28, 0x00, 0xd1, 0x2b, 0x78, 0x2b, 0x78, 0x6a, - 0x06, 0x1b, 0x04, 0x12, 0x43, 0x1a, 0x78, 0xab, 0x02, 0x1b, 0x43, 0x13, 0x78, 0xea, 0x43, 0x1a, - 0x4b, 0x1b, 0x42, 0x9a, 0xd1, 0x19, 0x99, 0x12, 0x9a, 0x2b, 0x42, 0x91, 0xd1, 0x0e, 0x9b, 0x2c, - 0x90, 0x00, 0x97, 0x01, 0x93, 0x02, 0x98, 0x0c, 0x99, 0x0b, 0x9a, 0x0a, 0x9b, 0x09, 0xf7, 0xff, - 0xfd, 0xc3, 0x1c, 0x04, 0x1c, 0x28, 0xf7, 0xfb, 0xfb, 0xbd, 0xe0, 0x0f, 0x9c, 0x11, 0x42, 0xa7, - 0xd0, 0x03, 0x99, 0x12, 0x97, 0x11, 0x31, 0x01, 0x91, 0x12, 0xab, 0x20, 0x42, 0x9e, 0xd0, 0x01, - 0x36, 0x10, 0xe7, 0x41, 0x1c, 0x28, 0xf7, 0xfb, 0xfb, 0xad, 0x24, 0x00, 0xb0, 0x25, 0x1c, 0x20, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x70, 0x60, 0x4c, 0x13, 0x70, 0x67, 0xdc, - 0x13, 0x70, 0x67, 0xe0, 0x00, 0x00, 0x01, 0xff, 0x13, 0x70, 0x67, 0x22, 0x13, 0x70, 0x67, 0x27, - 0x57, 0x42, 0x46, 0x53, 0x00, 0x00, 0x01, 0xc7, 0x00, 0x00, 0x01, 0xc9, 0x00, 0x00, 0x01, 0xd7, - 0x00, 0x00, 0x01, 0xd9, 0x47, 0x20, 0x46, 0xc0, 0xef, 0x00, 0x00, 0xcc, 0xe1, 0x2f, 0xff, 0x1e, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0xe6, 0x00, 0x00, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0x70, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0x90, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x00, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x00, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0x70, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0x90, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x01, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x01, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0x70, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0x90, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x02, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x02, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x70, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0x90, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0x70, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0x90, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x05, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x05, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x05, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x06, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x07, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x08, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x0a, 0x10, 0xe1, 0x2f, 0xff, 0x1e, - 0xe2, 0x90, 0x10, 0x00, 0xe3, 0xb0, 0x00, 0x04, 0xef, 0x00, 0x00, 0xab, 0xe1, 0x2f, 0xff, 0x1e, - 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0x29, 0x00, 0xd0, 0x34, 0x23, 0x01, 0x22, 0x00, - 0xb4, 0x10, 0x42, 0x88, 0xd3, 0x2c, 0x24, 0x01, 0x07, 0x24, 0x42, 0xa1, 0xd2, 0x04, 0x42, 0x81, - 0xd2, 0x02, 0x01, 0x09, 0x01, 0x1b, 0xe7, 0xf8, 0x00, 0xe4, 0x42, 0xa1, 0xd2, 0x04, 0x42, 0x81, - 0xd2, 0x02, 0x00, 0x49, 0x00, 0x5b, 0xe7, 0xf8, 0x42, 0x88, 0xd3, 0x01, 0x1a, 0x40, 0x43, 0x1a, - 0x08, 0x4c, 0x42, 0xa0, 0xd3, 0x02, 0x1b, 0x00, 0x08, 0x5c, 0x43, 0x22, 0x08, 0x8c, 0x42, 0xa0, - 0xd3, 0x02, 0x1b, 0x00, 0x08, 0x9c, 0x43, 0x22, 0x08, 0xcc, 0x42, 0xa0, 0xd3, 0x02, 0x1b, 0x00, - 0x08, 0xdc, 0x43, 0x22, 0x28, 0x00, 0xd0, 0x03, 0x09, 0x1b, 0xd0, 0x01, 0x09, 0x09, 0xe7, 0xe3, - 0x1c, 0x10, 0xbc, 0x10, 0x47, 0x70, 0xb5, 0x02, 0xf0, 0x00, 0xf8, 0x5e, 0x20, 0x00, 0xbc, 0x06, - 0x47, 0x10, 0x46, 0xc0, 0xb5, 0x03, 0xf7, 0xff, 0xff, 0xbf, 0xbc, 0x0e, 0x43, 0x42, 0x1a, 0x89, - 0x47, 0x18, 0x46, 0xc0, 0x29, 0x00, 0xd0, 0x41, 0xb4, 0x10, 0x1c, 0x04, 0x40, 0x4c, 0x46, 0xa4, - 0x23, 0x01, 0x22, 0x00, 0x29, 0x00, 0xd5, 0x00, 0x42, 0x49, 0x28, 0x00, 0xd5, 0x00, 0x42, 0x40, - 0x42, 0x88, 0xd3, 0x2c, 0x24, 0x01, 0x07, 0x24, 0x42, 0xa1, 0xd2, 0x04, 0x42, 0x81, 0xd2, 0x02, - 0x01, 0x09, 0x01, 0x1b, 0xe7, 0xf8, 0x00, 0xe4, 0x42, 0xa1, 0xd2, 0x04, 0x42, 0x81, 0xd2, 0x02, - 0x00, 0x49, 0x00, 0x5b, 0xe7, 0xf8, 0x42, 0x88, 0xd3, 0x01, 0x1a, 0x40, 0x43, 0x1a, 0x08, 0x4c, - 0x42, 0xa0, 0xd3, 0x02, 0x1b, 0x00, 0x08, 0x5c, 0x43, 0x22, 0x08, 0x8c, 0x42, 0xa0, 0xd3, 0x02, - 0x1b, 0x00, 0x08, 0x9c, 0x43, 0x22, 0x08, 0xcc, 0x42, 0xa0, 0xd3, 0x02, 0x1b, 0x00, 0x08, 0xdc, - 0x43, 0x22, 0x28, 0x00, 0xd0, 0x03, 0x09, 0x1b, 0xd0, 0x01, 0x09, 0x09, 0xe7, 0xe3, 0x1c, 0x10, - 0x46, 0x64, 0x2c, 0x00, 0xd5, 0x00, 0x42, 0x40, 0xbc, 0x10, 0x47, 0x70, 0xb5, 0x02, 0xf0, 0x00, - 0xf8, 0x0b, 0x20, 0x00, 0xbc, 0x06, 0x47, 0x10, 0xb5, 0x03, 0xf7, 0xff, 0xff, 0xb3, 0xbc, 0x0e, - 0x43, 0x42, 0x1a, 0x89, 0x47, 0x18, 0x46, 0xc0, 0x47, 0x70, 0x46, 0xc0, 0xb5, 0xf0, 0x46, 0x57, - 0x46, 0x46, 0xb4, 0xc0, 0x1c, 0x1e, 0x4b, 0x16, 0x46, 0x90, 0x1c, 0x0a, 0x40, 0x1a, 0x40, 0x33, - 0x46, 0x82, 0x1c, 0x10, 0x43, 0x58, 0x0c, 0x0c, 0x1c, 0x0f, 0x0c, 0x31, 0x46, 0x84, 0x43, 0x4a, - 0x1c, 0x20, 0x43, 0x58, 0x1c, 0x25, 0x43, 0x4d, 0x46, 0x61, 0x18, 0x82, 0x0c, 0x0b, 0x18, 0xd2, - 0x42, 0x90, 0xd9, 0x02, 0x23, 0x80, 0x02, 0x5b, 0x18, 0xed, 0x4b, 0x09, 0x46, 0x61, 0x04, 0x14, - 0x0c, 0x10, 0x40, 0x0b, 0x18, 0x2a, 0x18, 0xe1, 0x46, 0x40, 0x43, 0x78, 0x46, 0x53, 0x43, 0x73, - 0x18, 0xc0, 0x18, 0x80, 0xbc, 0x0c, 0x46, 0x90, 0x46, 0x9a, 0xbc, 0xf0, 0xbc, 0x04, 0x47, 0x10, - 0x00, 0x00, 0xff, 0xff, 0xb5, 0x70, 0x1c, 0x0e, 0x1c, 0x15, 0x1c, 0x04, 0x2a, 0x03, 0xd9, 0x20, - 0x1c, 0x33, 0x43, 0x03, 0x07, 0x9a, 0xd0, 0x12, 0x78, 0x23, 0x78, 0x08, 0x42, 0x83, 0xd1, 0x1b, - 0x1e, 0x6a, 0xe0, 0x06, 0x34, 0x01, 0x31, 0x01, 0x78, 0x23, 0x78, 0x08, 0x3a, 0x01, 0x42, 0x83, - 0xd1, 0x12, 0x2a, 0x00, 0xd1, 0xf6, 0x20, 0x00, 0xbc, 0x70, 0xbc, 0x02, 0x47, 0x08, 0x68, 0x02, - 0x68, 0x0b, 0x42, 0x9a, 0xd1, 0x04, 0x3d, 0x04, 0x30, 0x04, 0x31, 0x04, 0x2d, 0x03, 0xd8, 0xf6, - 0x1c, 0x04, 0x2d, 0x00, 0xd1, 0xe0, 0xe7, 0xee, 0x1a, 0x18, 0xe7, 0xed, 0xb5, 0xf0, 0x1c, 0x07, - 0x1c, 0x0e, 0x1c, 0x04, 0x1c, 0x15, 0x1c, 0x08, 0x1c, 0x11, 0x2a, 0x0f, 0xd9, 0x03, 0x1c, 0x33, - 0x43, 0x3b, 0x07, 0x9a, 0xd0, 0x0b, 0x29, 0x00, 0xd0, 0x05, 0x22, 0x00, 0x5c, 0x83, 0x54, 0xa3, - 0x32, 0x01, 0x42, 0x8a, 0xd1, 0xfa, 0x1c, 0x38, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x1c, 0x3a, - 0x1c, 0x31, 0x1c, 0x28, 0x68, 0x0b, 0x60, 0x13, 0x68, 0x4b, 0x60, 0x53, 0x68, 0x8b, 0x60, 0x93, - 0x68, 0xcb, 0x38, 0x10, 0x60, 0xd3, 0x31, 0x10, 0x32, 0x10, 0x28, 0x0f, 0xd8, 0xf2, 0x1c, 0x2b, - 0x3b, 0x10, 0x09, 0x1a, 0x01, 0x11, 0x32, 0x01, 0x01, 0x12, 0x1a, 0x59, 0x18, 0xb0, 0x18, 0xbc, - 0x29, 0x03, 0xd9, 0xd8, 0x22, 0x00, 0x58, 0x83, 0x50, 0xa3, 0x32, 0x04, 0x1a, 0x8b, 0x2b, 0x03, - 0xd8, 0xf9, 0x1f, 0x0b, 0x08, 0x9a, 0x00, 0x91, 0x32, 0x01, 0x00, 0x92, 0x1a, 0x59, 0x18, 0x80, - 0x18, 0xa4, 0xe7, 0xc8, 0xb5, 0xf0, 0x1c, 0x07, 0x46, 0x8c, 0x1c, 0x10, 0x1c, 0x39, 0x07, 0xba, - 0xd0, 0x0e, 0x28, 0x00, 0xd0, 0x49, 0x46, 0x62, 0x06, 0x13, 0x38, 0x01, 0x0e, 0x1b, 0x22, 0x03, - 0xe0, 0x02, 0x28, 0x00, 0xd0, 0x41, 0x38, 0x01, 0x70, 0x0b, 0x31, 0x01, 0x42, 0x11, 0xd1, 0xf8, - 0x1c, 0x05, 0x1c, 0x0a, 0x28, 0x03, 0xd9, 0x2e, 0x23, 0xff, 0x46, 0x62, 0x40, 0x1a, 0x02, 0x13, - 0x43, 0x13, 0x04, 0x1a, 0x1c, 0x14, 0x1c, 0x0e, 0x43, 0x1c, 0x28, 0x0f, 0xd9, 0x12, 0x1c, 0x02, - 0x1c, 0x0b, 0x3a, 0x10, 0x60, 0x1c, 0x60, 0x5c, 0x60, 0x9c, 0x60, 0xdc, 0x33, 0x10, 0x2a, 0x0f, - 0xd8, 0xf7, 0x1c, 0x03, 0x3b, 0x10, 0x1c, 0x1d, 0x09, 0x1b, 0x33, 0x01, 0x22, 0x0f, 0x01, 0x1b, - 0x40, 0x15, 0x18, 0xce, 0x2d, 0x03, 0xd9, 0x0d, 0x22, 0x00, 0x50, 0xb4, 0x32, 0x04, 0x1a, 0xab, - 0x2b, 0x03, 0xd8, 0xfa, 0x1f, 0x2b, 0x1c, 0x1d, 0x08, 0x9b, 0x33, 0x01, 0x22, 0x03, 0x00, 0x9b, - 0x40, 0x15, 0x18, 0xf6, 0x1c, 0x32, 0x2d, 0x00, 0xd0, 0x07, 0x46, 0x61, 0x06, 0x0b, 0x0e, 0x19, - 0x23, 0x00, 0x54, 0xd1, 0x33, 0x01, 0x42, 0x9d, 0xd1, 0xfb, 0x1c, 0x38, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0xb5, 0x30, 0x1c, 0x0b, 0x43, 0x03, 0x07, 0x9a, 0xd1, 0x1c, 0x68, 0x02, - 0x68, 0x0b, 0x42, 0x9a, 0xd1, 0x18, 0x4c, 0x10, 0x19, 0x13, 0x43, 0x93, 0x4a, 0x0f, 0x42, 0x13, - 0xd1, 0x0b, 0x1c, 0x14, 0x30, 0x04, 0x31, 0x04, 0x68, 0x02, 0x68, 0x0b, 0x42, 0x9a, 0xd1, 0x0b, - 0x4d, 0x09, 0x19, 0x53, 0x43, 0x93, 0x42, 0x23, 0xd0, 0xf4, 0x20, 0x00, 0xe0, 0x09, 0x78, 0x0a, - 0x42, 0x9a, 0xd1, 0x05, 0x30, 0x01, 0x31, 0x01, 0x78, 0x03, 0x2b, 0x00, 0xd1, 0xf7, 0x78, 0x0a, - 0x1a, 0x98, 0xbc, 0x30, 0xbc, 0x02, 0x47, 0x08, 0xfe, 0xfe, 0xfe, 0xff, 0x80, 0x80, 0x80, 0x80, - 0xb5, 0x70, 0x1c, 0x04, 0x2a, 0x00, 0xd0, 0x41, 0x1c, 0x0b, 0x43, 0x03, 0x07, 0x98, 0xd1, 0x2c, - 0x1c, 0x20, 0x1c, 0x0d, 0x2a, 0x03, 0xd9, 0x26, 0x68, 0x24, 0x68, 0x0b, 0x42, 0x9c, 0xd1, 0x22, - 0x3a, 0x04, 0x2a, 0x00, 0xd0, 0x32, 0x49, 0x1b, 0x18, 0x63, 0x49, 0x1b, 0x43, 0xa3, 0x42, 0x0b, - 0xd1, 0x2c, 0x1c, 0x0c, 0xe0, 0x0b, 0x68, 0x01, 0x68, 0x2b, 0x42, 0x99, 0xd1, 0x13, 0x3a, 0x04, - 0x2a, 0x00, 0xd0, 0x23, 0x4e, 0x13, 0x19, 0x8b, 0x43, 0x8b, 0x42, 0x23, 0xd1, 0x1e, 0x30, 0x04, - 0x35, 0x04, 0x2a, 0x03, 0xd8, 0xef, 0x1c, 0x04, 0x1c, 0x29, 0x2a, 0x00, 0xd1, 0x05, 0x78, 0x03, - 0x78, 0x28, 0x1a, 0x18, 0xe0, 0x13, 0x1c, 0x04, 0x1c, 0x29, 0x78, 0x23, 0x78, 0x08, 0x3a, 0x01, - 0x42, 0x98, 0xd0, 0x09, 0xe7, 0xf5, 0x28, 0x00, 0xd0, 0x08, 0x34, 0x01, 0x31, 0x01, 0x78, 0x23, - 0x78, 0x08, 0x42, 0x98, 0xd1, 0xed, 0x3a, 0x01, 0x2a, 0x00, 0xd1, 0xf4, 0x20, 0x00, 0xbc, 0x70, - 0xbc, 0x02, 0x47, 0x08, 0xfe, 0xfe, 0xfe, 0xff, 0x80, 0x80, 0x80, 0x80, 0x49, 0x4f, 0x53, 0x20, - 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe5, 0x1f, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x00, - 0x13, 0x72, 0xc2, 0xa4, 0x00, 0x0f, 0x42, 0x40, 0x10, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x2f, 0x64, 0x65, 0x76, - 0x2f, 0x75, 0x73, 0x62, 0x31, 0x32, 0x33, 0x00, 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x75, 0x73, 0x62, - 0x31, 0x32, 0x33, 0x2f, 0x4f, 0x46, 0x46, 0x00, 0x57, 0x42, 0x46, 0x53, 0x20, 0x6e, 0x6f, 0x74, - 0x20, 0x65, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x20, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x21, 0x0a, - 0x00, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x67, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x20, - 0x20, 0x28, 0x25, 0x73, 0x29, 0x0a, 0x00, 0x20, 0x41, 0x73, 0x79, 0x6e, 0x63, 0x00, 0x20, 0x50, - 0x65, 0x72, 0x69, 0x6f, 0x64, 0x69, 0x63, 0x00, 0x20, 0x52, 0x65, 0x63, 0x6c, 0x00, 0x20, 0x48, - 0x61, 0x6c, 0x74, 0x00, 0x20, 0x49, 0x41, 0x41, 0x00, 0x20, 0x46, 0x41, 0x54, 0x41, 0x4c, 0x00, - 0x20, 0x46, 0x4c, 0x52, 0x00, 0x20, 0x50, 0x43, 0x44, 0x00, 0x20, 0x45, 0x52, 0x52, 0x00, 0x20, - 0x49, 0x4e, 0x54, 0x00, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3a, 0x20, - 0x25, 0x78, 0x20, 0x25, 0x73, 0x25, 0x73, 0x25, 0x73, 0x25, 0x73, 0x25, 0x73, 0x25, 0x73, 0x25, - 0x73, 0x25, 0x73, 0x25, 0x73, 0x25, 0x73, 0x0a, 0x00, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x20, 0x70, 0x6f, 0x72, 0x74, 0x3a, 0x20, 0x25, 0x78, 0x0a, 0x00, 0x75, 0x73, - 0x62, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 0x72, 0x65, 0x73, 0x65, 0x74, 0x3a, 0x20, - 0x42, 0x55, 0x4c, 0x4b, 0x20, 0x52, 0x45, 0x53, 0x45, 0x54, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x75, - 0x73, 0x62, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 0x72, 0x65, 0x73, 0x65, 0x74, 0x3a, - 0x20, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x68, 0x61, 0x6c, 0x74, 0x20, 0x69, 0x6e, 0x20, 0x72, 0x65, - 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x75, 0x73, 0x62, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, - 0x20, 0x72, 0x65, 0x73, 0x65, 0x74, 0x3a, 0x20, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x68, 0x61, 0x6c, - 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x75, 0x73, - 0x62, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x20, 0x72, 0x65, 0x73, 0x65, 0x74, 0x3a, 0x20, - 0x55, 0x53, 0x42, 0x5f, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x5f, 0x5f, 0x73, - 0x65, 0x6e, 0x64, 0x5f, 0x63, 0x62, 0x77, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, - 0x5f, 0x73, 0x65, 0x6e, 0x64, 0x5f, 0x63, 0x62, 0x77, 0x00, 0x5f, 0x5f, 0x55, 0x53, 0x42, 0x5f, - 0x42, 0x6c, 0x6b, 0x4d, 0x73, 0x67, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x20, 0x25, 0x69, - 0x0a, 0x00, 0x5f, 0x5f, 0x55, 0x53, 0x42, 0x5f, 0x42, 0x6c, 0x6b, 0x4d, 0x73, 0x67, 0x54, 0x69, - 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x00, 0x5f, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x63, 0x73, 0x77, - 0x20, 0x25, 0x69, 0x0a, 0x00, 0x5f, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x63, 0x73, 0x77, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x53, 0x43, 0x53, 0x49, 0x5f, 0x54, 0x45, 0x53, 0x54, 0x5f, 0x55, 0x4e, - 0x49, 0x54, 0x5f, 0x52, 0x45, 0x41, 0x44, 0x59, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, - 0x00, 0x20, 0x20, 0x20, 0x20, 0x53, 0x43, 0x53, 0x49, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, - 0x54, 0x5f, 0x53, 0x45, 0x4e, 0x53, 0x45, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x53, 0x43, 0x53, 0x49, 0x5f, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, - 0x5f, 0x53, 0x45, 0x4e, 0x53, 0x45, 0x20, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x20, 0x25, 0x78, - 0x0a, 0x00, 0x20, 0x20, 0x20, 0x20, 0x73, 0x74, 0x61, 0x72, 0x74, 0x5f, 0x73, 0x74, 0x6f, 0x70, - 0x20, 0x63, 0x6d, 0x64, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x20, 0x20, 0x20, - 0x20, 0x49, 0x6e, 0x71, 0x75, 0x69, 0x72, 0x79, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, - 0x00, 0x20, 0x20, 0x20, 0x20, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x54, 0x79, 0x70, 0x65, - 0x3a, 0x20, 0x25, 0x78, 0x0a, 0x00, 0x20, 0x20, 0x20, 0x20, 0x52, 0x65, 0x61, 0x64, 0x43, 0x61, - 0x70, 0x61, 0x63, 0x69, 0x74, 0x79, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x55, - 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, - 0x3a, 0x20, 0x55, 0x53, 0x42, 0x5f, 0x47, 0x65, 0x74, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, - 0x74, 0x6f, 0x72, 0x73, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x55, - 0x53, 0x42, 0x5f, 0x47, 0x65, 0x74, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, - 0x73, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, - 0x6e, 0x28, 0x29, 0x3a, 0x20, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, - 0x67, 0x65, 0x64, 0x21, 0x21, 0x21, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, - 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, 0x3a, 0x20, 0x75, 0x63, 0x64, 0x20, 0x25, - 0x69, 0x20, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x20, 0x25, 0x69, 0x20, 0x6d, 0x41, 0x0a, 0x00, 0x55, - 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, - 0x3a, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x20, 0x73, 0x75, 0x62, 0x63, - 0x6c, 0x61, 0x73, 0x73, 0x20, 0x25, 0x69, 0x20, 0x61, 0x74, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x74, - 0x20, 0x25, 0x69, 0x20, 0x0a, 0x00, 0x49, 0x6e, 0x20, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x3a, 0x20, - 0x25, 0x69, 0x0a, 0x00, 0x4f, 0x75, 0x74, 0x20, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x3a, 0x20, 0x25, - 0x69, 0x0a, 0x00, 0x65, 0x70, 0x5f, 0x69, 0x6e, 0x20, 0x25, 0x78, 0x20, 0x65, 0x70, 0x5f, 0x6f, - 0x75, 0x74, 0x20, 0x25, 0x78, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, - 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, 0x3a, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f, 0x74, - 0x20, 0x66, 0x69, 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x66, - 0x61, 0x63, 0x65, 0x21, 0x21, 0x21, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, - 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, 0x3a, 0x20, 0x63, 0x6f, 0x6e, 0x66, 0x3a, - 0x20, 0x25, 0x78, 0x20, 0x61, 0x6c, 0x74, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, - 0x3a, 0x20, 0x25, 0x78, 0x0a, 0x00, 0x61, 0x66, 0x74, 0x65, 0x72, 0x20, 0x55, 0x53, 0x42, 0x5f, - 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, - 0x28, 0x29, 0x3a, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x69, 0x6e, 0x67, 0x20, 0x63, 0x6f, 0x6e, - 0x66, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x25, 0x78, 0x0a, 0x00, 0x42, 0x65, 0x66, 0x6f, 0x72, - 0x65, 0x20, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x52, 0x65, 0x73, - 0x65, 0x74, 0x00, 0x41, 0x66, 0x74, 0x65, 0x72, 0x20, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, - 0x61, 0x67, 0x65, 0x5f, 0x52, 0x65, 0x73, 0x65, 0x74, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, - 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, 0x3a, 0x20, 0x74, 0x72, 0x79, - 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, - 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4f, 0x70, 0x65, 0x6e, 0x28, 0x29, 0x3a, 0x20, 0x72, - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x0a, 0x00, 0x20, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x20, - 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x46, 0x61, - 0x73, 0x74, 0x20, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4d, 0x6f, - 0x75, 0x6e, 0x74, 0x4c, 0x55, 0x4e, 0x20, 0x25, 0x69, 0x23, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, - 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x4c, 0x55, 0x4e, 0x3a, - 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, 0x54, 0x4f, 0x52, - 0x41, 0x47, 0x45, 0x5f, 0x47, 0x45, 0x54, 0x5f, 0x4d, 0x41, 0x58, 0x5f, 0x4c, 0x55, 0x4e, 0x20, - 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x20, 0x6d, 0x61, 0x78, 0x6c, 0x75, 0x6e, 0x20, 0x25, 0x69, - 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x4d, 0x6f, 0x75, - 0x6e, 0x74, 0x4c, 0x55, 0x4e, 0x20, 0x66, 0x61, 0x69, 0x6c, 0x21, 0x21, 0x21, 0x0a, 0x00, 0x55, - 0x6e, 0x70, 0x6c, 0x75, 0x67, 0x3a, 0x20, 0x72, 0x65, 0x73, 0x65, 0x74, 0x5f, 0x70, 0x6f, 0x72, - 0x74, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, 0x20, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x73, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x20, 0x25, 0x78, 0x0a, 0x00, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x72, 0x65, - 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x4f, 0x4b, 0x0a, 0x00, 0x66, 0x61, 0x73, 0x74, 0x5f, 0x72, - 0x65, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x4b, 0x4f, 0x20, 0x72, 0x65, 0x74, 0x20, 0x25, 0x69, - 0x0a, 0x00, 0x0a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, - 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, - 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, - 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x0a, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, - 0x65, 0x5f, 0x49, 0x6e, 0x69, 0x74, 0x28, 0x29, 0x0a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, - 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, - 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, - 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x0a, 0x0a, 0x00, 0x55, - 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x49, 0x6e, 0x69, 0x74, 0x28, 0x29, - 0x20, 0x4f, 0x6b, 0x0a, 0x00, 0x55, 0x53, 0x42, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, - 0x49, 0x6e, 0x69, 0x74, 0x28, 0x29, 0x20, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x20, 0x25, 0x78, - 0x0a, 0x00, 0x55, 0x53, 0x42, 0x20, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x3a, 0x20, 0x6e, 0x6f, 0x74, - 0x20, 0x65, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x20, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x21, 0x0a, - 0x00, 0x77, 0x62, 0x66, 0x73, 0x20, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x00, 0x61, 0x6c, 0x6c, - 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x00, 0x74, - 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x74, 0x6f, 0x20, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x20, 0x77, - 0x62, 0x66, 0x73, 0x20, 0x77, 0x68, 0x69, 0x6c, 0x65, 0x20, 0x64, 0x69, 0x73, 0x63, 0x73, 0x20, - 0x73, 0x74, 0x69, 0x6c, 0x6c, 0x20, 0x6f, 0x70, 0x65, 0x6e, 0x00, 0x62, 0x61, 0x64, 0x20, 0x6d, - 0x61, 0x67, 0x69, 0x63, 0x00, 0x68, 0x64, 0x20, 0x73, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20, 0x73, - 0x69, 0x7a, 0x65, 0x20, 0x64, 0x6f, 0x65, 0x73, 0x6e, 0x27, 0x74, 0x20, 0x6d, 0x61, 0x74, 0x63, - 0x68, 0x00, 0x68, 0x64, 0x20, 0x6e, 0x75, 0x6d, 0x20, 0x73, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x20, - 0x64, 0x6f, 0x65, 0x73, 0x6e, 0x27, 0x74, 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x00, 0x4e, 0x54, - 0x46, 0x53, 0x00, 0x46, 0x41, 0x54, 0x00 -}; diff --git a/source/mload/modules/ehcmodule_5.h b/source/mload/modules/ehcmodule_5.h deleted file mode 100644 index 2d0d3a33..00000000 --- a/source/mload/modules/ehcmodule_5.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef EHC_MODULE5_H_ -#define EHC_MODULE5_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern unsigned char ehcmodule_5[3352]; - -#define ehcmodule_5_size sizeof(ehcmodule_5) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/mload/modules/odip_frag.c b/source/mload/modules/odip_frag.c deleted file mode 100644 index c044ec5b..00000000 --- a/source/mload/modules/odip_frag.c +++ /dev/null @@ -1,574 +0,0 @@ -unsigned char odip_frag[9120] __attribute__((aligned (32)))={ - 0x13, 0x77, 0xca, 0x6d, 0x12, 0x34, 0x00, 0x01, 0x20, 0x22, 0xdd, 0xac, 0x20, 0x20, 0x10, 0x11, - 0x20, 0x20, 0x0b, 0x9d, 0x20, 0x20, 0x0b, 0x71, 0x20, 0x20, 0x5d, 0xc1, 0x20, 0x20, 0x00, 0x49, - 0x20, 0x20, 0x2b, 0x4d, 0x20, 0x20, 0x39, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x77, 0xe2, 0xa0, 0x13, 0x77, 0xd8, 0xe0, - 0x13, 0x77, 0xd5, 0x2d, 0x13, 0x77, 0xe3, 0xa0, 0x00, 0x00, 0x10, 0xa0, 0xe1, 0xa0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb5, 0x00, 0x23, 0xe3, 0xb0, 0x89, 0x06, 0x1b, 0x93, 0x00, 0x46, 0x68, 0x23, 0x00, 0x21, 0x00, - 0x22, 0x00, 0x93, 0x01, 0x93, 0x02, 0xf0, 0x01, 0xfa, 0xed, 0xb0, 0x09, 0xbc, 0x02, 0x47, 0x08, - 0xb5, 0x10, 0x1c, 0x03, 0x22, 0x20, 0x1c, 0x0c, 0x48, 0x0d, 0x1c, 0x19, 0xf0, 0x01, 0xfc, 0x82, - 0x48, 0x0b, 0x21, 0x20, 0xf0, 0x01, 0xfc, 0x72, 0x4a, 0x0a, 0x23, 0x01, 0x68, 0x11, 0x42, 0x0b, - 0xd1, 0xfc, 0x22, 0x20, 0x1c, 0x20, 0x49, 0x06, 0xf0, 0x01, 0xfc, 0x74, 0x1c, 0x20, 0x21, 0x20, - 0xf0, 0x01, 0xfc, 0x64, 0x4b, 0x04, 0x68, 0x18, 0xbc, 0x10, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x0d, 0x00, 0x60, 0x00, 0x0d, 0x00, 0x60, 0x1c, 0x0d, 0x00, 0x60, 0x20, 0xb5, 0xf0, 0xb0, 0x8d, - 0x1c, 0x0e, 0x27, 0xd0, 0x0a, 0xc9, 0x90, 0x01, 0x92, 0x03, 0x91, 0x02, 0x25, 0x00, 0xac, 0x04, - 0x06, 0x3f, 0x99, 0x03, 0x9b, 0x02, 0x22, 0x00, 0x61, 0x21, 0x98, 0x01, 0x1c, 0x31, 0x60, 0xe3, - 0x60, 0x62, 0x60, 0xa2, 0x35, 0x01, 0x60, 0x27, 0xf0, 0x01, 0xfc, 0x48, 0x99, 0x01, 0x1c, 0x32, - 0x1c, 0x20, 0xf0, 0x01, 0xfa, 0xa7, 0x0f, 0xeb, 0x22, 0x00, 0x21, 0x1f, 0x42, 0xa9, 0x41, 0x53, - 0x06, 0x1b, 0x2b, 0x00, 0xd0, 0x01, 0x28, 0x00, 0xd1, 0xe3, 0xb0, 0x0d, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0xb5, 0xf0, 0xb0, 0x8b, 0x27, 0xa8, 0x90, 0x00, 0x1c, 0x0e, 0x92, 0x01, 0x25, 0x00, - 0xac, 0x02, 0x06, 0x3f, 0x99, 0x01, 0x98, 0x00, 0x60, 0xa1, 0x1c, 0x31, 0x35, 0x01, 0x60, 0x27, - 0x60, 0x66, 0xf0, 0x01, 0xfc, 0x23, 0x99, 0x00, 0x1c, 0x32, 0x1c, 0x20, 0xf0, 0x01, 0xfa, 0x82, - 0x0f, 0xeb, 0x22, 0x00, 0x21, 0x07, 0x42, 0xa9, 0x41, 0x53, 0x06, 0x1b, 0x2b, 0x00, 0xd0, 0x01, - 0x28, 0x00, 0xd1, 0xe7, 0xb0, 0x0b, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0xb5, 0xf0, 0xb0, 0x87, - 0x90, 0x05, 0x91, 0x03, 0x92, 0x04, 0x25, 0x00, 0x29, 0x00, 0xd0, 0x75, 0x0a, 0x51, 0x91, 0x01, - 0x95, 0x00, 0xe0, 0x69, 0x9a, 0x03, 0x9b, 0x00, 0x99, 0x01, 0x1a, 0xd4, 0x9a, 0x04, 0x02, 0x4b, - 0x27, 0x00, 0x42, 0x9a, 0xd9, 0x01, 0x1a, 0xd7, 0x00, 0xbf, 0x9b, 0x05, 0x21, 0x1f, 0x1c, 0x1e, - 0x9b, 0x00, 0x18, 0xf6, 0x23, 0x00, 0x42, 0x0e, 0xd1, 0x19, 0x4b, 0x32, 0x22, 0x00, 0x42, 0x9e, - 0xd8, 0x02, 0x22, 0xc0, 0x04, 0x52, 0x1b, 0x92, 0x21, 0xf0, 0x06, 0x09, 0x18, 0x73, 0x49, 0x2e, - 0x42, 0x8b, 0xd8, 0x01, 0x4a, 0x2d, 0x1b, 0x92, 0x49, 0x2d, 0x23, 0x00, 0x42, 0x8a, 0xd9, 0x03, - 0x1c, 0x13, 0x42, 0xa2, 0xd9, 0x00, 0x1c, 0x23, 0x05, 0x5a, 0x0d, 0x52, 0x1a, 0x9b, 0x2b, 0x00, - 0xd0, 0x01, 0x2f, 0x00, 0xd0, 0x22, 0x23, 0x80, 0x19, 0x3a, 0x01, 0x1b, 0x42, 0x9a, 0xd9, 0x00, - 0x1b, 0xdc, 0x20, 0x80, 0x01, 0x00, 0x21, 0x20, 0xf0, 0x01, 0xfb, 0xbc, 0x90, 0x02, 0x28, 0x00, - 0xd0, 0x30, 0x21, 0x80, 0x01, 0x09, 0x9a, 0x01, 0xf7, 0xff, 0xff, 0x60, 0x1e, 0x05, 0xd1, 0x09, - 0x9a, 0x02, 0x1c, 0x30, 0x19, 0xd1, 0x1c, 0x22, 0xf0, 0x01, 0xfb, 0xbc, 0x1c, 0x30, 0x1c, 0x21, - 0xf0, 0x01, 0xfb, 0xac, 0x98, 0x02, 0xf0, 0x01, 0xfb, 0xa1, 0xe0, 0x0b, 0x1c, 0x1c, 0x4b, 0x15, - 0x42, 0x9c, 0xd9, 0x01, 0x24, 0xff, 0x03, 0xe4, 0x1c, 0x30, 0x1c, 0x21, 0x9a, 0x01, 0xf7, 0xff, - 0xff, 0x45, 0x1c, 0x05, 0x2d, 0x00, 0xd1, 0x0f, 0x9b, 0x00, 0x99, 0x01, 0x19, 0x1b, 0x19, 0xe4, - 0x0a, 0xe4, 0x19, 0x09, 0x93, 0x00, 0x91, 0x01, 0x9a, 0x00, 0x9b, 0x03, 0x42, 0x9a, 0xd3, 0x91, - 0x25, 0x00, 0xe0, 0x01, 0x25, 0x01, 0x42, 0x6d, 0xb0, 0x07, 0x1c, 0x28, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x01, 0x7f, 0xff, 0xff, 0x03, 0x61, 0x7f, 0xff, 0x13, 0x61, 0x80, 0x00, - 0x00, 0x00, 0x07, 0xff, 0x00, 0x7f, 0x7f, 0xff, 0xb5, 0xf8, 0x4e, 0x26, 0x27, 0x01, 0x1c, 0x04, - 0x60, 0x37, 0x21, 0x20, 0xf0, 0x01, 0xfb, 0x7a, 0x7b, 0x22, 0x7b, 0x63, 0x06, 0x12, 0x04, 0x1b, - 0x43, 0x13, 0x7b, 0xa2, 0x02, 0x12, 0x43, 0x13, 0x7b, 0xe2, 0x43, 0x13, 0x2b, 0x08, 0xd1, 0x30, - 0x7e, 0x22, 0x7e, 0x63, 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x7e, 0xa2, 0x25, 0xc5, 0x02, 0x12, - 0x43, 0x13, 0x7e, 0xe2, 0x01, 0xad, 0x43, 0x13, 0x68, 0x18, 0x68, 0x59, 0xf0, 0x01, 0xfb, 0x5e, - 0x7e, 0x22, 0x7e, 0x63, 0x06, 0x12, 0x04, 0x1b, 0x43, 0x13, 0x7e, 0xa2, 0x1c, 0x28, 0x02, 0x12, - 0x43, 0x13, 0x7e, 0xe2, 0x21, 0x08, 0x43, 0x13, 0x68, 0x1b, 0x68, 0x5c, 0xf0, 0x01, 0xfb, 0x4e, - 0x04, 0x24, 0x43, 0x27, 0x4c, 0x0c, 0x60, 0x2f, 0x1c, 0x28, 0x21, 0x04, 0x60, 0x27, 0xf0, 0x01, - 0xfb, 0x3d, 0x1c, 0x20, 0x21, 0x04, 0xf0, 0x01, 0xfb, 0x39, 0x23, 0x00, 0x60, 0x33, 0x20, 0x00, - 0xe0, 0x04, 0x1c, 0x20, 0xf0, 0x01, 0xf9, 0x11, 0x23, 0x00, 0x60, 0x33, 0xbc, 0xf8, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x77, 0xe3, 0xa0, 0x00, 0x00, 0x31, 0x88, 0x4a, 0x03, 0x23, 0x00, - 0x60, 0x13, 0x4a, 0x03, 0x60, 0x13, 0x4a, 0x03, 0x60, 0x13, 0x47, 0x70, 0x13, 0x77, 0xe5, 0xe8, - 0x13, 0x77, 0xe3, 0xc0, 0x13, 0x77, 0xe3, 0xb8, 0xb5, 0xf0, 0x4b, 0x10, 0x21, 0xa0, 0x48, 0x10, - 0x68, 0x1c, 0x22, 0x00, 0x23, 0x00, 0x00, 0x89, 0x03, 0xd6, 0xe0, 0x01, 0x04, 0x2b, 0x0c, 0x1b, - 0x00, 0x5d, 0x18, 0xed, 0x00, 0xad, 0x19, 0x65, 0x69, 0x6f, 0x68, 0xed, 0x19, 0x7d, 0x42, 0xae, - 0xd3, 0x03, 0x68, 0x67, 0x1c, 0x5d, 0x42, 0xbd, 0xd3, 0xf0, 0x32, 0x01, 0x80, 0x03, 0x30, 0x02, - 0x42, 0x8a, 0xd1, 0xe9, 0xbc, 0xf0, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x77, 0xe3, 0xc0, - 0x13, 0x77, 0xe6, 0x04, 0xb5, 0xf8, 0x4b, 0x22, 0x1c, 0x06, 0x68, 0x1b, 0x1c, 0x0f, 0x1c, 0x14, - 0x2b, 0x00, 0xd0, 0x01, 0xf7, 0xff, 0xff, 0xc2, 0x1e, 0x73, 0x2b, 0x01, 0xd8, 0x30, 0x2c, 0x00, - 0xd0, 0x2e, 0x4b, 0x1c, 0x42, 0x9c, 0xd8, 0x2d, 0x4d, 0x1b, 0x2e, 0x01, 0xd1, 0x02, 0xf0, 0x00, - 0xfe, 0x29, 0xe0, 0x01, 0xf0, 0x00, 0xfd, 0x72, 0x4b, 0x17, 0x60, 0x28, 0x68, 0x18, 0x28, 0x00, - 0xd1, 0x22, 0x4b, 0x16, 0x4d, 0x16, 0x60, 0x1e, 0x4b, 0x16, 0x1c, 0x38, 0x60, 0x2b, 0x1c, 0x21, - 0xf0, 0x01, 0xfa, 0xd4, 0x68, 0x2d, 0x21, 0x00, 0x4a, 0x0e, 0x1c, 0x28, 0xf0, 0x01, 0xfa, 0x2a, - 0x1c, 0x22, 0x1c, 0x39, 0x1c, 0x28, 0xf0, 0x01, 0xf9, 0xe3, 0x1c, 0x38, 0x1c, 0x21, 0xf0, 0x01, - 0xfa, 0xbd, 0xf7, 0xff, 0xff, 0xa1, 0x4b, 0x06, 0x22, 0x01, 0x60, 0x1a, 0x1c, 0x20, 0xe0, 0x03, - 0x20, 0x01, 0xe0, 0x00, 0x20, 0x02, 0x42, 0x40, 0xbc, 0xf8, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x77, 0xe5, 0xe8, 0x00, 0x00, 0xa4, 0x1c, 0x13, 0x77, 0xe3, 0xb4, 0x13, 0x77, 0xe3, 0xb8, - 0x13, 0x77, 0xe3, 0xc0, 0x13, 0x73, 0x00, 0x00, 0xb5, 0xf0, 0xb0, 0x83, 0x24, 0xa0, 0x4d, 0x36, - 0x0b, 0xcf, 0x00, 0xa4, 0x9e, 0x09, 0x60, 0x2f, 0x42, 0xa7, 0xd9, 0x01, 0x4c, 0x33, 0x60, 0x2c, - 0x4c, 0x31, 0x4d, 0x33, 0x68, 0x24, 0x46, 0x9c, 0x00, 0x64, 0x5b, 0x2c, 0x4d, 0x31, 0x00, 0x67, - 0x60, 0x2c, 0x4d, 0x31, 0x19, 0x3f, 0x60, 0x2c, 0x68, 0x45, 0x00, 0xbf, 0x95, 0x00, 0x19, 0xc7, - 0x18, 0x55, 0x37, 0x0c, 0x95, 0x01, 0xe0, 0x37, 0x68, 0x3d, 0x42, 0x8d, 0xd8, 0x19, 0x68, 0xbb, - 0x18, 0xeb, 0x42, 0x8b, 0xd9, 0x2e, 0x4f, 0x28, 0x1b, 0x4d, 0x60, 0x3c, 0x4f, 0x27, 0x46, 0x63, - 0x60, 0x3d, 0x60, 0x19, 0x00, 0x63, 0x19, 0x1c, 0x00, 0xa4, 0x19, 0x00, 0x69, 0x03, 0x99, 0x08, - 0x18, 0xeb, 0x60, 0x0b, 0x69, 0x43, 0x20, 0x00, 0x1b, 0x5d, 0x60, 0x35, 0x42, 0x95, 0xd9, 0x2e, - 0xe0, 0x16, 0x9b, 0x01, 0x42, 0x9d, 0xd2, 0x15, 0x4f, 0x1b, 0x46, 0x63, 0x60, 0x3c, 0x4f, 0x1b, - 0x1a, 0x69, 0x60, 0x39, 0x60, 0x1d, 0x00, 0x63, 0x19, 0x1c, 0x00, 0xa4, 0x19, 0x00, 0x69, 0x03, - 0x9c, 0x08, 0x1a, 0x52, 0x60, 0x23, 0x69, 0x43, 0x20, 0x00, 0x60, 0x33, 0x42, 0x93, 0xd9, 0x16, - 0x60, 0x32, 0xe0, 0x14, 0x34, 0x01, 0x37, 0x0c, 0x9d, 0x00, 0x42, 0xac, 0xd3, 0xc4, 0x4d, 0x0e, - 0x18, 0x51, 0x68, 0x02, 0x46, 0x63, 0x60, 0x2c, 0x42, 0x91, 0xd8, 0x06, 0x60, 0x19, 0x99, 0x08, - 0x23, 0x00, 0x60, 0x0b, 0x20, 0x00, 0x60, 0x33, 0xe0, 0x01, 0x20, 0x02, 0x42, 0x40, 0xb0, 0x03, - 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x77, 0xe3, 0xa4, 0x00, 0x00, 0x02, 0x7f, - 0x13, 0x77, 0xe6, 0x04, 0x13, 0x77, 0xe5, 0xfc, 0x13, 0x77, 0xeb, 0x04, 0x13, 0x77, 0xe5, 0xec, - 0xb5, 0xf0, 0xb0, 0x85, 0x1c, 0x06, 0x1c, 0x0d, 0x1c, 0x17, 0xe0, 0x46, 0x4a, 0x29, 0x4b, 0x2a, - 0x68, 0x10, 0x4a, 0x2a, 0x93, 0x00, 0x92, 0x01, 0x4b, 0x29, 0x1c, 0x31, 0x1c, 0x3a, 0xf7, 0xff, - 0xff, 0x73, 0x4b, 0x28, 0x60, 0x18, 0x28, 0x00, 0xd1, 0x3f, 0x4a, 0x25, 0x68, 0x13, 0x1b, 0x9b, - 0x93, 0x03, 0x9a, 0x03, 0x4b, 0x24, 0x60, 0x1a, 0x2a, 0x00, 0xd0, 0x09, 0x02, 0x54, 0x1c, 0x28, - 0x21, 0x00, 0x1c, 0x22, 0xf0, 0x01, 0xf9, 0x66, 0x9b, 0x03, 0x19, 0x2d, 0x18, 0xf6, 0x1a, 0xff, - 0x4b, 0x1a, 0x68, 0x19, 0x29, 0x00, 0xd0, 0x19, 0x4b, 0x1c, 0x4c, 0x1a, 0x68, 0x1a, 0x4b, 0x16, - 0x2a, 0x01, 0xd1, 0x04, 0x68, 0x18, 0x1c, 0x2a, 0xf0, 0x00, 0xfc, 0xf4, 0xe0, 0x03, 0x68, 0x18, - 0x1c, 0x2a, 0xf0, 0x00, 0xfc, 0xa9, 0x4b, 0x13, 0x60, 0x20, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x10, - 0x4b, 0x0e, 0x68, 0x1b, 0x02, 0x5a, 0x18, 0xf6, 0x18, 0xad, 0x1a, 0xff, 0x4b, 0x0b, 0x68, 0x1a, - 0x4b, 0x0d, 0x68, 0x1b, 0x18, 0xd3, 0x2b, 0x00, 0xd0, 0x05, 0x2f, 0x00, 0xd1, 0xb6, 0x20, 0x00, - 0xe0, 0x03, 0x20, 0x03, 0xe0, 0x00, 0x20, 0x04, 0x42, 0x40, 0xb0, 0x05, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x77, 0xe3, 0xc0, 0x13, 0x77, 0xe3, 0xc8, 0x13, 0x77, 0xe5, 0xf0, - 0x13, 0x77, 0xe3, 0xac, 0x13, 0x77, 0xe6, 0x00, 0x13, 0x77, 0xe3, 0xbc, 0x13, 0x77, 0xe3, 0xb8, - 0xb5, 0xf8, 0x1c, 0x1e, 0x4b, 0x1a, 0x1c, 0x0f, 0x09, 0xc1, 0x60, 0x19, 0x23, 0x7f, 0x40, 0x18, - 0x4b, 0x18, 0x00, 0x80, 0x60, 0x18, 0x23, 0x80, 0x00, 0x9b, 0x4c, 0x17, 0x1a, 0x1b, 0x60, 0x23, - 0x42, 0x93, 0xd9, 0x00, 0x60, 0x22, 0x4a, 0x14, 0x23, 0x80, 0x68, 0x10, 0x00, 0x9b, 0x42, 0x98, - 0xd1, 0x01, 0x23, 0x00, 0x60, 0x13, 0x4c, 0x10, 0x68, 0x23, 0x2b, 0x00, 0xd0, 0x10, 0x4d, 0x0f, - 0x1c, 0x08, 0x22, 0x01, 0x1c, 0x29, 0xf7, 0xff, 0xff, 0x73, 0x4b, 0x0d, 0x60, 0x18, 0x28, 0x00, - 0xd1, 0x0a, 0x4b, 0x08, 0x68, 0x22, 0x68, 0x19, 0x1c, 0x38, 0x18, 0x69, 0xf0, 0x01, 0xf8, 0xb0, - 0x4b, 0x05, 0x20, 0x00, 0x68, 0x1b, 0x60, 0x33, 0xbc, 0xf8, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, - 0x13, 0x77, 0xe5, 0xf4, 0x13, 0x77, 0xe5, 0xf8, 0x13, 0x77, 0xe3, 0xa8, 0x13, 0x77, 0xe3, 0xe0, - 0x13, 0x77, 0xe5, 0xe0, 0xb5, 0xf0, 0xb0, 0x85, 0x4d, 0x25, 0x90, 0x01, 0x91, 0x03, 0x1c, 0x10, - 0x1c, 0x17, 0x99, 0x01, 0x9a, 0x03, 0x1c, 0x2b, 0xf7, 0xff, 0xff, 0xb2, 0x4e, 0x21, 0x1c, 0x04, - 0x60, 0x30, 0x28, 0x00, 0xd1, 0x37, 0x68, 0x2d, 0x99, 0x01, 0x08, 0xab, 0x18, 0xfb, 0x9a, 0x03, - 0x93, 0x02, 0x4b, 0x1d, 0x19, 0x49, 0x1b, 0x55, 0x91, 0x01, 0x42, 0x9d, 0xd9, 0x15, 0x9b, 0x02, - 0x4f, 0x1a, 0x09, 0xd8, 0x4b, 0x1a, 0x0a, 0x6a, 0x60, 0x18, 0x60, 0x3a, 0xf7, 0xff, 0xff, 0x30, - 0x60, 0x30, 0x28, 0x00, 0xd1, 0x1b, 0x68, 0x3b, 0x99, 0x02, 0x01, 0xda, 0x18, 0x89, 0x9a, 0x01, - 0x02, 0x5b, 0x18, 0xd2, 0x91, 0x02, 0x92, 0x01, 0x1a, 0xed, 0x2d, 0x00, 0xd0, 0x13, 0x4e, 0x0c, - 0x98, 0x02, 0x1c, 0x33, 0x99, 0x01, 0x1c, 0x2a, 0xf7, 0xff, 0xff, 0x82, 0x4b, 0x09, 0x1c, 0x04, - 0x60, 0x18, 0x28, 0x00, 0xd1, 0x07, 0x68, 0x33, 0x42, 0x9d, 0xd1, 0x02, 0xe0, 0x03, 0x1c, 0x04, - 0xe0, 0x01, 0x24, 0x05, 0x42, 0x64, 0xb0, 0x05, 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x77, 0xe3, 0xb0, 0x13, 0x77, 0xe3, 0xc4, 0x00, 0x00, 0x01, 0xff, 0x13, 0x77, 0xe5, 0xe4, - 0x13, 0x77, 0xeb, 0x08, 0xb5, 0x00, 0x4b, 0x0b, 0x68, 0x1b, 0x2b, 0x01, 0xd0, 0x02, 0x2b, 0x02, - 0xd1, 0x0c, 0xe0, 0x01, 0x4a, 0x08, 0xe0, 0x00, 0x4a, 0x08, 0x23, 0x00, 0x42, 0x90, 0xd3, 0x06, - 0x4b, 0x07, 0x4a, 0x08, 0x62, 0x1a, 0x23, 0xa0, 0x02, 0x1b, 0xe0, 0x00, 0x23, 0x00, 0x1c, 0x18, - 0xbc, 0x02, 0x47, 0x08, 0x13, 0x77, 0xeb, 0x10, 0x46, 0x09, 0x00, 0x00, 0x7e, 0xd3, 0x80, 0x00, - 0x13, 0x77, 0xeb, 0x14, 0x00, 0x05, 0x21, 0x00, 0xb5, 0x10, 0x4b, 0x0c, 0x1d, 0xdc, 0x7f, 0xe4, - 0x2c, 0x00, 0xd0, 0x02, 0xf7, 0xff, 0xff, 0x7e, 0xe0, 0x0d, 0x69, 0x1c, 0x2c, 0x00, 0xd0, 0x02, - 0xf0, 0x00, 0xfc, 0xb8, 0xe0, 0x07, 0x68, 0x5b, 0x2b, 0x00, 0xd0, 0x02, 0xf7, 0xff, 0xfc, 0xe6, - 0xe0, 0x01, 0xf7, 0xff, 0xfc, 0xbe, 0xbc, 0x10, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x77, 0xeb, 0x14, - 0xb5, 0xf0, 0xb0, 0x85, 0x90, 0x02, 0x1c, 0x10, 0x91, 0x03, 0x1c, 0x14, 0xf7, 0xff, 0xff, 0xba, - 0x28, 0x00, 0xd0, 0x00, 0xe0, 0xfe, 0x4b, 0x81, 0x68, 0xdd, 0x68, 0x9a, 0x18, 0xad, 0x19, 0x2d, - 0x95, 0x01, 0x69, 0x1b, 0x2b, 0x00, 0xd0, 0x12, 0x4b, 0x7d, 0x68, 0x1b, 0x2b, 0x00, 0xdd, 0x00, - 0xe0, 0xeb, 0x4b, 0x7c, 0x68, 0x19, 0x29, 0x00, 0xd0, 0x01, 0xf0, 0x01, 0xf8, 0xe7, 0x4b, 0x79, - 0x22, 0x00, 0x60, 0x1a, 0x23, 0x01, 0x4a, 0x78, 0x42, 0x5b, 0x60, 0x13, 0xe0, 0xdd, 0x4b, 0x76, - 0x49, 0x76, 0x68, 0x1b, 0x18, 0x5a, 0x2a, 0x00, 0xd1, 0x00, 0xe0, 0xa8, 0x2b, 0x00, 0xda, 0x00, - 0xe0, 0xa5, 0x4c, 0x70, 0x68, 0x23, 0x2b, 0x00, 0xd1, 0x06, 0x21, 0x80, 0x20, 0x00, 0x01, 0x89, - 0x22, 0x20, 0xf0, 0x01, 0xf8, 0xbb, 0x60, 0x20, 0x20, 0x80, 0x01, 0x00, 0x21, 0x20, 0xf0, 0x01, - 0xf8, 0xa1, 0x1e, 0x04, 0xd1, 0x03, 0x23, 0x01, 0x4a, 0x67, 0x42, 0x5b, 0x60, 0x13, 0x4e, 0x66, - 0x22, 0x00, 0x68, 0x33, 0x92, 0x00, 0x2b, 0x00, 0xdb, 0x26, 0x1c, 0x35, 0x27, 0x00, 0x68, 0x32, - 0x21, 0x80, 0x1c, 0x13, 0x33, 0x10, 0x02, 0x5b, 0x02, 0x52, 0x1c, 0x20, 0x01, 0x09, 0x93, 0x00, - 0xf7, 0xff, 0xff, 0x8a, 0x28, 0x00, 0xda, 0x03, 0x23, 0x01, 0x42, 0x5b, 0x60, 0x33, 0xe0, 0x13, - 0x78, 0x23, 0x2b, 0x43, 0xd1, 0x08, 0x78, 0x63, 0x2b, 0x49, 0xd1, 0x05, 0x78, 0xa3, 0x2b, 0x53, - 0xd1, 0x02, 0x78, 0xe3, 0x2b, 0x4f, 0xd0, 0x07, 0x68, 0x2b, 0x2b, 0x00, 0xd0, 0x01, 0x60, 0x2f, - 0xe7, 0xdd, 0x23, 0x01, 0x42, 0x5b, 0x60, 0x2b, 0x4e, 0x4f, 0x68, 0x33, 0x2b, 0x00, 0xdb, 0x59, - 0x4b, 0x4c, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x55, 0x79, 0x62, 0x79, 0xa3, 0x02, 0x12, 0x04, 0x1b, - 0x18, 0xd2, 0x79, 0x23, 0x48, 0x4a, 0x18, 0xd2, 0x79, 0xe3, 0x21, 0x00, 0x06, 0x1b, 0x18, 0xd2, - 0x4b, 0x48, 0x08, 0x92, 0x60, 0x1a, 0x22, 0x80, 0x01, 0x12, 0xf0, 0x00, 0xfb, 0xcb, 0x27, 0x08, - 0x25, 0x00, 0x05, 0x7b, 0x2b, 0x00, 0xd1, 0x16, 0x49, 0x43, 0x23, 0x01, 0x42, 0x8d, 0xdc, 0x00, - 0x23, 0x00, 0x06, 0x1b, 0x2b, 0x00, 0xd0, 0x0e, 0x68, 0x33, 0x12, 0xfa, 0x18, 0xd2, 0x21, 0x80, - 0x02, 0x52, 0x1c, 0x20, 0x01, 0x09, 0xf7, 0xff, 0xff, 0x3f, 0x28, 0x00, 0xda, 0x03, 0x23, 0x01, - 0x42, 0x5b, 0x60, 0x33, 0xe0, 0x20, 0x20, 0x07, 0x40, 0x28, 0xd1, 0x05, 0x4b, 0x31, 0x10, 0xea, - 0x68, 0x1b, 0x99, 0x00, 0x00, 0x92, 0x50, 0xd1, 0x05, 0x7b, 0x0d, 0x5b, 0x5c, 0xe3, 0x2b, 0x00, - 0xd0, 0x0c, 0x4a, 0x2f, 0x21, 0x01, 0x10, 0xeb, 0x40, 0x81, 0x1c, 0x08, 0x5c, 0xd1, 0x43, 0x01, - 0x54, 0xd1, 0x4b, 0x2c, 0x9a, 0x00, 0x68, 0x1b, 0x18, 0xd2, 0x92, 0x00, 0x23, 0x80, 0x35, 0x01, - 0x01, 0xdb, 0x37, 0x01, 0x42, 0x9d, 0xd1, 0xc4, 0x4b, 0x23, 0x68, 0x1a, 0x2a, 0x00, 0xdb, 0x01, - 0x4a, 0x26, 0x60, 0x1a, 0x2c, 0x00, 0xd0, 0x02, 0x1c, 0x20, 0xf0, 0x01, 0xf8, 0x07, 0x4b, 0x1e, - 0x4c, 0x1c, 0x68, 0x1a, 0x4b, 0x21, 0x42, 0x9a, 0xd1, 0x1e, 0x4b, 0x1e, 0x98, 0x01, 0x68, 0x1d, - 0x1c, 0x29, 0xf0, 0x01, 0xf8, 0x1b, 0x68, 0x23, 0x08, 0xc1, 0x24, 0x07, 0x00, 0x8a, 0x58, 0xd2, - 0x40, 0x20, 0x23, 0x00, 0x4e, 0x16, 0x24, 0x01, 0xe0, 0x05, 0x5c, 0x77, 0x41, 0x1f, 0x42, 0x3c, - 0xd0, 0x00, 0x19, 0x52, 0x33, 0x01, 0x42, 0x83, 0xd3, 0xf7, 0x9b, 0x01, 0x3d, 0x01, 0x40, 0x1d, - 0x19, 0x52, 0x98, 0x02, 0x99, 0x03, 0xe0, 0x0b, 0x68, 0x21, 0x29, 0x00, 0xd0, 0x02, 0x20, 0x00, - 0xf0, 0x01, 0xf8, 0x04, 0x4b, 0x07, 0x22, 0x00, 0x60, 0x1a, 0x98, 0x02, 0x99, 0x03, 0x9a, 0x01, - 0xf7, 0xff, 0xfe, 0xda, 0xb0, 0x05, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x77, 0xeb, 0x14, - 0x13, 0x77, 0xec, 0x24, 0x13, 0x77, 0xeb, 0x0c, 0x13, 0x77, 0xe2, 0x04, 0x80, 0x00, 0x00, 0x01, - 0x13, 0x77, 0xec, 0x40, 0x13, 0x77, 0xeb, 0x3c, 0x00, 0x00, 0x07, 0xf7, 0x7f, 0xff, 0xff, 0xff, - 0xb5, 0x10, 0x21, 0x80, 0x20, 0x00, 0x01, 0x09, 0x22, 0x20, 0xf0, 0x00, 0xff, 0xcf, 0x1e, 0x04, - 0xd0, 0x10, 0x21, 0x80, 0x22, 0x8e, 0x01, 0x09, 0x1c, 0x20, 0x05, 0xd2, 0xf7, 0xff, 0xfe, 0xd0, - 0x1e, 0x43, 0x41, 0x98, 0x23, 0x02, 0x1a, 0x18, 0x4b, 0x04, 0x1c, 0x21, 0x60, 0x18, 0x20, 0x00, - 0xf0, 0x00, 0xff, 0xcc, 0xbc, 0x10, 0xbc, 0x01, 0x47, 0x00, 0x46, 0xc0, 0x13, 0x77, 0xeb, 0x10, - 0xb5, 0x38, 0x22, 0x00, 0x21, 0x20, 0x1c, 0x04, 0xf7, 0xff, 0xfe, 0xba, 0x69, 0xa2, 0x4b, 0x09, - 0x1c, 0x05, 0x42, 0x9a, 0xd1, 0x09, 0x4b, 0x08, 0x21, 0x01, 0x68, 0x1a, 0x70, 0x11, 0x68, 0x1b, - 0x78, 0x5b, 0x2b, 0x00, 0xd1, 0x01, 0xf0, 0x00, 0xff, 0x85, 0x1c, 0x28, 0xbc, 0x38, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x5d, 0x1c, 0x9e, 0xa3, 0x13, 0x77, 0xc0, 0x08, 0xb5, 0xf0, 0xb0, 0x83, - 0x92, 0x01, 0x78, 0x02, 0x1c, 0x07, 0x92, 0x00, 0x4a, 0xba, 0x1c, 0x0d, 0x68, 0x13, 0x2b, 0x00, - 0xd0, 0x0d, 0x4c, 0xb9, 0x4e, 0xb9, 0x68, 0x20, 0x68, 0x32, 0x21, 0x00, 0xf0, 0x00, 0xfa, 0xea, - 0x68, 0x20, 0x68, 0x31, 0xf0, 0x00, 0xff, 0x72, 0x4a, 0xb2, 0x23, 0x00, 0x60, 0x13, 0x9b, 0x00, - 0x2b, 0xe0, 0xd0, 0x61, 0x4c, 0xb2, 0x26, 0x00, 0x62, 0x26, 0x2b, 0xda, 0xd1, 0x00, 0xe1, 0x51, - 0x2b, 0xda, 0xd8, 0x2f, 0x2b, 0x8a, 0xd1, 0x00, 0xe1, 0xb6, 0x2b, 0x8a, 0xd8, 0x12, 0x2b, 0x15, - 0xd1, 0x00, 0xe1, 0x1c, 0x2b, 0x15, 0xd8, 0x03, 0x2b, 0x13, 0xd2, 0x00, 0xe1, 0xd8, 0xe0, 0xf0, - 0x9a, 0x00, 0x2a, 0x71, 0xd1, 0x00, 0xe1, 0x69, 0x2a, 0x79, 0xd0, 0x60, 0x2a, 0x70, 0xd0, 0x00, - 0xe1, 0xce, 0xe1, 0x7a, 0x9b, 0x00, 0x2b, 0xa8, 0xd1, 0x00, 0xe1, 0xbe, 0x2b, 0xa8, 0xd8, 0x06, - 0x2b, 0x8d, 0xd1, 0x00, 0xe1, 0xb9, 0x2b, 0xa4, 0xd0, 0x00, 0xe1, 0xc1, 0xe1, 0x1c, 0x9a, 0x00, - 0x2a, 0xd0, 0xd1, 0x00, 0xe1, 0xb1, 0x2a, 0xd9, 0xd1, 0x00, 0xe1, 0x04, 0x2a, 0xab, 0xd0, 0x00, - 0xe1, 0xb6, 0xe0, 0x39, 0x9b, 0x00, 0x2b, 0xf4, 0xd0, 0x5e, 0x2b, 0xf4, 0xd8, 0x0f, 0x2b, 0xf0, - 0xd0, 0x50, 0x2b, 0xf0, 0xd8, 0x05, 0x2b, 0xe0, 0xd0, 0x1e, 0x2b, 0xe4, 0xd0, 0x00, 0xe1, 0xa7, - 0xe0, 0x3a, 0x9a, 0x00, 0x2a, 0xf2, 0xd0, 0x4a, 0x2a, 0xf2, 0xd8, 0x4b, 0xe0, 0x45, 0x9b, 0x00, - 0x2b, 0xf9, 0xd0, 0x61, 0x2b, 0xf9, 0xd8, 0x05, 0x2b, 0xf5, 0xd0, 0x56, 0x2b, 0xf6, 0xd0, 0x00, - 0xe1, 0x96, 0xe0, 0xaa, 0x9a, 0x00, 0x2a, 0xfb, 0xd1, 0x00, 0xe0, 0x9b, 0x2a, 0xfb, 0xd3, 0x7d, - 0x2a, 0xff, 0xd0, 0x00, 0xe1, 0x8c, 0xe0, 0xcf, 0x4b, 0x81, 0x6a, 0x1a, 0x2a, 0x00, 0xd1, 0x03, - 0x69, 0x1b, 0x2b, 0x00, 0xd1, 0x00, 0xe1, 0x83, 0x1c, 0x28, 0x21, 0x00, 0x9a, 0x01, 0xf0, 0x00, - 0xfa, 0x71, 0x4b, 0x7b, 0x6a, 0x1b, 0xe0, 0x39, 0x4b, 0x79, 0x26, 0x00, 0x68, 0x5a, 0x2a, 0x00, - 0xd0, 0x00, 0xe1, 0x7d, 0x69, 0x1b, 0x2b, 0x00, 0xd0, 0x00, 0xe1, 0x79, 0xe1, 0x70, 0x69, 0x23, - 0x2b, 0x00, 0xd1, 0x00, 0xe1, 0x6c, 0xe1, 0x72, 0x68, 0x63, 0x2b, 0x00, 0xd1, 0x04, 0x4b, 0x70, - 0x69, 0x1b, 0x2b, 0x00, 0xd1, 0x00, 0xe1, 0x63, 0x1c, 0x28, 0x21, 0x00, 0x9a, 0x01, 0xf0, 0x00, - 0xfa, 0x51, 0xe0, 0x1c, 0x68, 0x7b, 0x60, 0xa3, 0xe1, 0x61, 0x68, 0xa3, 0xe0, 0x16, 0x68, 0x7b, - 0x60, 0x23, 0xe1, 0x5c, 0x68, 0x23, 0xe0, 0x11, 0x68, 0x7b, 0x1d, 0xe2, 0x61, 0x23, 0x77, 0xd6, - 0x2b, 0x00, 0xd0, 0x06, 0x1c, 0x20, 0x1c, 0x39, 0x30, 0x18, 0x31, 0x08, 0x22, 0x06, 0xf0, 0x00, - 0xfe, 0xd1, 0x69, 0x7a, 0x4b, 0x5e, 0x61, 0x5a, 0xe1, 0x49, 0x69, 0x23, 0x60, 0x2b, 0x99, 0x01, - 0x1c, 0x28, 0xf0, 0x00, 0xfe, 0xbb, 0xe1, 0x42, 0x68, 0x7b, 0x93, 0x00, 0x68, 0xba, 0x92, 0x01, - 0x68, 0xff, 0xf7, 0xff, 0xfb, 0x8b, 0x1d, 0xe3, 0x77, 0xde, 0x9b, 0x01, 0x61, 0x26, 0x60, 0x2e, - 0x2b, 0x00, 0xd1, 0x00, 0xe1, 0x33, 0x9a, 0x00, 0x2a, 0x00, 0xd1, 0x00, 0xe1, 0x2f, 0x26, 0x00, - 0x2f, 0x00, 0xd1, 0x00, 0xe1, 0x2c, 0x1c, 0x18, 0xf0, 0x00, 0xfe, 0xa4, 0x1c, 0x3a, 0x1c, 0x01, - 0x98, 0x00, 0xf7, 0xff, 0xfb, 0xa7, 0x60, 0x28, 0x28, 0x00, 0xdc, 0x00, 0xe1, 0x20, 0x4b, 0x48, - 0x21, 0x01, 0x1d, 0xda, 0x77, 0xd1, 0x9a, 0x00, 0x61, 0x1a, 0xe1, 0x19, 0x60, 0x2e, 0x34, 0x07, - 0x7f, 0xe3, 0x2b, 0x00, 0xd0, 0x01, 0x23, 0x10, 0xe0, 0x0a, 0x4b, 0x42, 0x68, 0x1b, 0x2b, 0x00, - 0xd0, 0x01, 0x23, 0x08, 0xe0, 0x04, 0x4b, 0x3e, 0x69, 0x1a, 0x2a, 0x00, 0xd0, 0x02, 0x23, 0x04, - 0x60, 0x2b, 0xe1, 0x04, 0x68, 0x5b, 0x26, 0x00, 0x2b, 0x00, 0xd1, 0x00, 0xe1, 0x00, 0x23, 0x01, - 0x60, 0x2b, 0xe0, 0xfd, 0x1c, 0x28, 0x49, 0x38, 0x22, 0x04, 0xf0, 0x00, 0xfe, 0x7b, 0x69, 0x23, - 0x34, 0x07, 0x60, 0x6b, 0x7f, 0xe3, 0x60, 0xab, 0xe0, 0xf1, 0x79, 0x3b, 0x34, 0x05, 0x77, 0xe3, - 0xe0, 0xed, 0x26, 0x00, 0x2d, 0x00, 0xd1, 0x00, 0xe0, 0xea, 0x9b, 0x00, 0x2b, 0x13, 0xd1, 0x0d, - 0x69, 0x23, 0x2b, 0x00, 0xd0, 0x11, 0x4b, 0x2d, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x09, 0xf0, 0x00, - 0xf9, 0xf9, 0x1e, 0x43, 0x41, 0x98, 0x00, 0x40, 0x60, 0x28, 0xe7, 0x90, 0x69, 0x23, 0x2b, 0x00, - 0xd0, 0x03, 0x4b, 0x27, 0x68, 0x1b, 0x2b, 0x00, 0xda, 0x07, 0x4b, 0x26, 0x22, 0x01, 0x68, 0x1b, - 0x40, 0x13, 0x42, 0x5a, 0x41, 0x53, 0x00, 0x5b, 0xe7, 0x80, 0x23, 0x02, 0xe7, 0x7e, 0x4b, 0x21, - 0x22, 0x01, 0x68, 0x1b, 0x43, 0x93, 0xe7, 0x79, 0x68, 0x78, 0x1c, 0x29, 0x00, 0x40, 0x08, 0x40, - 0xf7, 0xff, 0xf9, 0xb6, 0xe0, 0xb9, 0x68, 0x63, 0x2b, 0x00, 0xd1, 0x04, 0x4b, 0x14, 0x69, 0x1b, - 0x2b, 0x00, 0xd1, 0x00, 0xe0, 0xac, 0x68, 0x7a, 0x68, 0xbb, 0x07, 0x92, 0x43, 0x1a, 0x0b, 0xd2, - 0x4b, 0x0f, 0x03, 0xd2, 0x60, 0xda, 0xe0, 0xaa, 0x68, 0x63, 0x2b, 0x00, 0xd1, 0x04, 0x4b, 0x0c, - 0x69, 0x1b, 0x2b, 0x00, 0xd1, 0x00, 0xe0, 0x9b, 0x4a, 0x0f, 0x4b, 0x09, 0x26, 0xa0, 0x62, 0x1a, - 0x02, 0x36, 0xe0, 0x9d, 0x4c, 0x0d, 0x21, 0x40, 0x1c, 0x20, 0xf0, 0x00, 0xfe, 0x17, 0x1c, 0x23, - 0x33, 0x40, 0xe0, 0x18, 0x13, 0x77, 0xe2, 0x00, 0x13, 0x77, 0xc0, 0x44, 0x13, 0x77, 0xc0, 0x48, - 0x13, 0x77, 0xeb, 0x14, 0x13, 0x77, 0xec, 0x24, 0x13, 0x77, 0xd8, 0xd8, 0x13, 0x77, 0xec, 0x28, - 0x13, 0x77, 0xe2, 0x84, 0x0d, 0x00, 0x60, 0x04, 0x00, 0x05, 0x31, 0x00, 0x13, 0x77, 0xd8, 0xe0, - 0x34, 0x01, 0x42, 0x9c, 0xd0, 0x74, 0x78, 0x22, 0x2a, 0x00, 0xd0, 0xf9, 0x49, 0x3f, 0x1c, 0x28, - 0x22, 0x40, 0xf0, 0x00, 0xfd, 0xf7, 0x1c, 0x28, 0x21, 0x40, 0xe7, 0x2a, 0x1d, 0xa3, 0x22, 0x01, - 0x77, 0xda, 0x68, 0x23, 0x2b, 0x00, 0xd1, 0x05, 0x1c, 0x38, 0x1c, 0x29, 0x9a, 0x01, 0xf0, 0x00, - 0xfc, 0x49, 0xe0, 0x04, 0x68, 0x79, 0x68, 0xba, 0x1c, 0x28, 0xf7, 0xff, 0xfc, 0xf1, 0x4b, 0x34, - 0x22, 0x00, 0x33, 0x06, 0x1c, 0x06, 0x77, 0xda, 0xe0, 0x5a, 0x4b, 0x31, 0x69, 0x1b, 0x2b, 0x00, - 0xd1, 0x06, 0x1c, 0x38, 0x1c, 0x29, 0x9a, 0x01, 0xf0, 0x00, 0xfc, 0x34, 0x28, 0x00, 0xd1, 0x0c, - 0x4b, 0x2b, 0x20, 0x00, 0x68, 0xd9, 0x68, 0x9a, 0x43, 0x11, 0xd1, 0x06, 0x69, 0x1a, 0x2a, 0x00, - 0xd1, 0x03, 0x69, 0xac, 0x49, 0x27, 0x42, 0x8c, 0xd0, 0x0a, 0x1e, 0x43, 0x41, 0x98, 0x4b, 0x24, - 0x99, 0x01, 0x60, 0x58, 0x1c, 0x28, 0xf7, 0xff, 0xfe, 0x0b, 0x1e, 0x06, 0xd1, 0x38, 0xe0, 0x00, - 0x60, 0x5a, 0xf7, 0xff, 0xfd, 0xe5, 0xe0, 0x32, 0x1d, 0x63, 0x7f, 0xdb, 0x26, 0x00, 0x2b, 0x00, - 0xd1, 0x2e, 0x1d, 0xa2, 0x77, 0xd3, 0x60, 0x23, 0x60, 0x63, 0x60, 0xa3, 0x60, 0xe3, 0x69, 0x23, - 0x2b, 0x00, 0xd1, 0x04, 0x69, 0x62, 0x4b, 0x18, 0x3a, 0x01, 0x60, 0x1a, 0xe0, 0x18, 0xf7, 0xff, - 0xf9, 0x07, 0x1d, 0xe3, 0x7f, 0xdb, 0x2b, 0x00, 0xd1, 0x1a, 0x69, 0x20, 0x1c, 0x21, 0x31, 0x18, - 0x69, 0x62, 0x38, 0x01, 0xf0, 0x00, 0xfa, 0x9c, 0xe0, 0x0f, 0x9b, 0x00, 0x68, 0x79, 0x68, 0xba, - 0x2b, 0xd0, 0xd1, 0x01, 0x02, 0xc9, 0x02, 0x52, 0x1c, 0x28, 0xf7, 0xff, 0xfc, 0x99, 0xe0, 0x04, - 0x1c, 0x38, 0x1c, 0x29, 0x9a, 0x01, 0xf0, 0x00, 0xfb, 0xe5, 0x1c, 0x06, 0xe0, 0x00, 0x26, 0x00, - 0xb0, 0x03, 0x1c, 0x30, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x46, 0xc0, 0x13, 0x77, 0xd8, 0xe0, - 0x13, 0x77, 0xeb, 0x14, 0x5d, 0x1c, 0x9e, 0xa3, 0x13, 0x77, 0xe2, 0x04, 0xb5, 0x30, 0xb0, 0x83, - 0x4c, 0x0e, 0x25, 0x00, 0x68, 0x23, 0x2b, 0x00, 0xda, 0x13, 0x48, 0x0d, 0x21, 0x01, 0xf0, 0x00, - 0xfd, 0x43, 0x60, 0x20, 0x28, 0x00, 0xdb, 0x0a, 0x22, 0x00, 0x23, 0x00, 0x21, 0x01, 0x95, 0x00, - 0xf0, 0x00, 0xfd, 0x44, 0x23, 0x80, 0x4a, 0x07, 0x00, 0x9b, 0x60, 0x13, 0xe0, 0x01, 0x25, 0x0b, - 0x42, 0x6d, 0xb0, 0x03, 0x1c, 0x28, 0xbc, 0x30, 0xbc, 0x02, 0x47, 0x08, 0x13, 0x77, 0xe2, 0x44, - 0x13, 0x77, 0xe2, 0x20, 0x13, 0x77, 0xe2, 0x40, 0xb5, 0x70, 0xb0, 0x82, 0x1c, 0x03, 0x48, 0x1d, - 0x68, 0x04, 0x20, 0x00, 0x2c, 0x00, 0xdb, 0x31, 0x48, 0x1b, 0x4c, 0x1c, 0x60, 0x03, 0x23, 0x04, - 0x60, 0x63, 0x60, 0xe3, 0x4b, 0x1a, 0x60, 0x41, 0x68, 0x1b, 0x60, 0x20, 0x43, 0x59, 0x30, 0x04, - 0x1c, 0x26, 0x60, 0xa0, 0x61, 0x22, 0x61, 0x61, 0x36, 0x18, 0x1c, 0x25, 0x68, 0x28, 0x68, 0x69, - 0x35, 0x08, 0xf0, 0x00, 0xfd, 0x23, 0x42, 0xb5, 0xd1, 0xf8, 0x4d, 0x10, 0x21, 0x18, 0x1c, 0x28, - 0xf0, 0x00, 0xfd, 0x1c, 0x4b, 0x0b, 0x21, 0x02, 0x68, 0x18, 0x22, 0x02, 0x23, 0x01, 0x95, 0x00, - 0xf0, 0x00, 0xfd, 0x04, 0x1c, 0x03, 0x20, 0x00, 0x2b, 0x00, 0xdb, 0x07, 0x68, 0x20, 0x68, 0x61, - 0x34, 0x08, 0xf0, 0x00, 0xfd, 0x13, 0x42, 0xb4, 0xd1, 0xf8, 0x20, 0x01, 0xb0, 0x02, 0xbc, 0x70, - 0xbc, 0x02, 0x47, 0x08, 0x13, 0x77, 0xe2, 0x44, 0x13, 0x77, 0xeb, 0x60, 0x13, 0x77, 0xeb, 0x40, - 0x13, 0x77, 0xe2, 0x40, 0xb5, 0x70, 0xb0, 0x82, 0x1c, 0x03, 0x48, 0x1d, 0x68, 0x04, 0x20, 0x00, - 0x2c, 0x00, 0xdb, 0x31, 0x48, 0x1b, 0x4c, 0x1c, 0x60, 0x03, 0x23, 0x04, 0x60, 0x63, 0x60, 0xe3, - 0x4b, 0x1a, 0x60, 0x41, 0x68, 0x1b, 0x60, 0x20, 0x43, 0x59, 0x30, 0x04, 0x1c, 0x26, 0x60, 0xa0, - 0x61, 0x22, 0x61, 0x61, 0x36, 0x18, 0x1c, 0x25, 0x68, 0x28, 0x68, 0x69, 0x35, 0x08, 0xf0, 0x00, - 0xfc, 0xdd, 0x42, 0xb5, 0xd1, 0xf8, 0x4d, 0x10, 0x21, 0x18, 0x1c, 0x28, 0xf0, 0x00, 0xfc, 0xd6, - 0x4b, 0x0b, 0x49, 0x0f, 0x68, 0x18, 0x22, 0x02, 0x23, 0x01, 0x95, 0x00, 0xf0, 0x00, 0xfc, 0xbe, - 0x1c, 0x03, 0x20, 0x00, 0x2b, 0x00, 0xdb, 0x07, 0x68, 0x20, 0x68, 0x61, 0x34, 0x08, 0xf0, 0x00, - 0xfc, 0xcd, 0x42, 0xb4, 0xd1, 0xf8, 0x20, 0x01, 0xb0, 0x02, 0xbc, 0x70, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x77, 0xe2, 0x80, 0x13, 0x77, 0xeb, 0xa0, 0x13, 0x77, 0xeb, 0x80, 0x13, 0x77, 0xeb, 0xc0, - 0x55, 0x4d, 0x53, 0x03, 0xb5, 0x30, 0xb0, 0x83, 0x4c, 0x0e, 0x25, 0x00, 0x68, 0x23, 0x2b, 0x00, - 0xda, 0x13, 0x48, 0x0d, 0x21, 0x01, 0xf0, 0x00, 0xfc, 0x8f, 0x60, 0x20, 0x28, 0x00, 0xdb, 0x0a, - 0x22, 0x00, 0x23, 0x00, 0x49, 0x09, 0x95, 0x00, 0xf0, 0x00, 0xfc, 0x90, 0x23, 0x80, 0x4a, 0x08, - 0x00, 0x9b, 0x60, 0x13, 0xe0, 0x01, 0x25, 0x0b, 0x42, 0x6d, 0xb0, 0x03, 0x1c, 0x28, 0xbc, 0x30, - 0xbc, 0x02, 0x47, 0x08, 0x13, 0x77, 0xe2, 0x80, 0x13, 0x77, 0xe2, 0x60, 0x55, 0x4d, 0x53, 0x01, - 0x13, 0x77, 0xeb, 0xc0, 0xb5, 0xf0, 0x2a, 0x00, 0xd0, 0x29, 0x23, 0x03, 0x1c, 0x1c, 0x40, 0x04, - 0x27, 0x04, 0x1b, 0x3c, 0x06, 0x0e, 0x40, 0x1c, 0x0e, 0x36, 0x1c, 0x05, 0x42, 0x94, 0xd8, 0x03, - 0x23, 0x00, 0x2c, 0x00, 0xd0, 0x08, 0xe0, 0x00, 0x1c, 0x14, 0x1c, 0x23, 0xe0, 0x01, 0x70, 0x2e, - 0x35, 0x01, 0x3b, 0x01, 0xd2, 0xfb, 0x1c, 0x23, 0x04, 0x0c, 0x06, 0x0d, 0x43, 0x25, 0x43, 0x0d, - 0x02, 0x0c, 0x1c, 0x29, 0x43, 0x21, 0x18, 0xc4, 0xe0, 0x01, 0xc4, 0x02, 0x1c, 0x2b, 0x1d, 0x1d, - 0x42, 0x95, 0xd9, 0xfa, 0xe0, 0x01, 0x33, 0x01, 0x54, 0xc6, 0x42, 0x93, 0xd3, 0xfb, 0xbc, 0xf0, - 0xbc, 0x01, 0x47, 0x00, 0xb5, 0x00, 0xb0, 0x83, 0x4b, 0x0a, 0x20, 0x01, 0x68, 0x1b, 0x2b, 0x00, - 0xd0, 0x0c, 0x4b, 0x09, 0x68, 0x1b, 0x2b, 0x00, 0xdb, 0x08, 0x4a, 0x08, 0x1c, 0x18, 0x68, 0x12, - 0x49, 0x07, 0x92, 0x00, 0x23, 0x00, 0x22, 0x00, 0xf0, 0x00, 0xfc, 0x38, 0xb0, 0x03, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x77, 0xec, 0x28, 0x13, 0x77, 0xe2, 0x84, 0x13, 0x77, 0xeb, 0xc4, - 0x57, 0x46, 0x53, 0x04, 0xb5, 0xf0, 0xb0, 0x87, 0x4b, 0x9a, 0x90, 0x03, 0x68, 0x1b, 0x91, 0x02, - 0x92, 0x04, 0x2b, 0x00, 0xd0, 0x04, 0x21, 0xff, 0x9a, 0x02, 0xf7, 0xff, 0xff, 0xa3, 0xe0, 0xee, - 0x4d, 0x95, 0x68, 0x2b, 0x2b, 0x00, 0xda, 0x00, 0xe1, 0x1c, 0x4b, 0x94, 0x68, 0x1b, 0x2b, 0x00, - 0xd1, 0x00, 0xe0, 0xf0, 0x3b, 0x01, 0x2b, 0x01, 0xd9, 0x00, 0xe0, 0xad, 0x4c, 0x90, 0x68, 0x23, - 0x2b, 0x00, 0xd1, 0x06, 0x21, 0x80, 0x20, 0x00, 0x01, 0x89, 0x22, 0x20, 0xf0, 0x00, 0xfc, 0x26, - 0x60, 0x20, 0x20, 0x80, 0x01, 0x00, 0x21, 0x20, 0xf0, 0x00, 0xfc, 0x0c, 0x1e, 0x04, 0xd1, 0x03, - 0x23, 0x01, 0x4a, 0x86, 0x42, 0x5b, 0x60, 0x13, 0x4b, 0x84, 0x25, 0x00, 0x68, 0x1b, 0x2b, 0x00, - 0xdb, 0x21, 0x4d, 0x81, 0x21, 0x00, 0x68, 0x28, 0x22, 0x00, 0xf0, 0x00, 0xfc, 0x13, 0x28, 0x00, - 0xdb, 0x13, 0x22, 0x80, 0x68, 0x28, 0x1c, 0x21, 0x01, 0x12, 0xf0, 0x00, 0xfc, 0x13, 0x28, 0x00, - 0xdb, 0x0b, 0x78, 0x23, 0x2b, 0x43, 0xd1, 0x08, 0x78, 0x63, 0x2b, 0x49, 0xd1, 0x05, 0x78, 0xa3, - 0x2b, 0x53, 0xd1, 0x02, 0x78, 0xe3, 0x2b, 0x4f, 0xd0, 0x03, 0x23, 0x01, 0x4a, 0x73, 0x42, 0x5b, - 0x60, 0x13, 0x25, 0x80, 0x01, 0xad, 0x4a, 0x71, 0x68, 0x13, 0x2b, 0x00, 0xdb, 0x67, 0x4b, 0x70, - 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x63, 0x79, 0x62, 0x79, 0xa3, 0x02, 0x12, 0x04, 0x1b, 0x18, 0xd2, - 0x79, 0x23, 0x48, 0x6c, 0x18, 0xd2, 0x79, 0xe3, 0x21, 0x00, 0x06, 0x1b, 0x18, 0xd2, 0x4b, 0x6a, - 0x08, 0x92, 0x60, 0x1a, 0x22, 0x80, 0x01, 0x12, 0xf7, 0xff, 0xff, 0x3c, 0x27, 0x08, 0x26, 0x00, - 0x05, 0x7b, 0x2b, 0x00, 0xd1, 0x26, 0x4a, 0x65, 0x23, 0x01, 0x42, 0x96, 0xdc, 0x00, 0x23, 0x00, - 0x06, 0x1b, 0x2b, 0x00, 0xd0, 0x1e, 0x4b, 0x5d, 0x68, 0x1a, 0x4b, 0x5b, 0x2a, 0x02, 0xd1, 0x03, - 0x12, 0xf9, 0x68, 0x18, 0x02, 0x49, 0xe0, 0x02, 0x0a, 0xf9, 0x68, 0x18, 0x02, 0xc9, 0x22, 0x00, - 0xf0, 0x00, 0xfb, 0xc0, 0x28, 0x00, 0xdb, 0x08, 0x4b, 0x53, 0x22, 0x80, 0x68, 0x18, 0x1c, 0x21, - 0x01, 0x12, 0xf0, 0x00, 0xfb, 0xbf, 0x28, 0x00, 0xda, 0x04, 0x23, 0x01, 0x4a, 0x4f, 0x42, 0x5b, - 0x60, 0x13, 0xe0, 0x1d, 0x20, 0x07, 0x40, 0x30, 0xd1, 0x04, 0x4b, 0x4d, 0x10, 0xf2, 0x68, 0x1b, - 0x00, 0x92, 0x50, 0xd5, 0x05, 0x7b, 0x0d, 0x5b, 0x5c, 0xe3, 0x2b, 0x00, 0xd0, 0x0a, 0x4a, 0x49, - 0x21, 0x01, 0x10, 0xf3, 0x40, 0x81, 0x1c, 0x08, 0x5c, 0xd1, 0x43, 0x01, 0x54, 0xd1, 0x4b, 0x46, - 0x68, 0x1b, 0x18, 0xed, 0x23, 0x80, 0x36, 0x01, 0x01, 0xdb, 0x37, 0x01, 0x42, 0x9e, 0xd1, 0xb7, - 0x4b, 0x3e, 0x68, 0x1a, 0x2a, 0x00, 0xdb, 0x02, 0x21, 0x04, 0x43, 0x0a, 0x60, 0x1a, 0x2c, 0x00, - 0xd0, 0x02, 0x1c, 0x20, 0xf0, 0x00, 0xfb, 0x6a, 0x4b, 0x38, 0x4c, 0x39, 0x68, 0x1b, 0x93, 0x05, - 0x2b, 0x03, 0xdd, 0x2e, 0x4b, 0x38, 0x98, 0x04, 0x68, 0x1d, 0x1c, 0x29, 0xf0, 0x00, 0xfb, 0x7e, - 0x68, 0x23, 0x08, 0xc2, 0x24, 0x07, 0x00, 0x91, 0x58, 0xc9, 0x40, 0x20, 0x23, 0x00, 0x4e, 0x31, - 0x24, 0x01, 0xe0, 0x05, 0x5c, 0xb7, 0x41, 0x1f, 0x42, 0x3c, 0xd0, 0x00, 0x19, 0x49, 0x33, 0x01, - 0x42, 0x83, 0xd3, 0xf7, 0x9a, 0x04, 0x3d, 0x01, 0x40, 0x15, 0x9a, 0x05, 0x19, 0x49, 0x4b, 0x26, - 0x07, 0x92, 0xd5, 0x01, 0x68, 0x18, 0xe0, 0x01, 0x68, 0x18, 0x00, 0x89, 0x22, 0x00, 0xf0, 0x00, - 0xfb, 0x59, 0x4b, 0x21, 0x99, 0x03, 0x68, 0x18, 0x9a, 0x02, 0xf0, 0x00, 0xfb, 0x5b, 0x24, 0x00, - 0xe0, 0x32, 0x68, 0x21, 0x29, 0x00, 0xd0, 0x02, 0x20, 0x00, 0xf0, 0x00, 0xfb, 0x57, 0x4b, 0x1c, - 0x22, 0x00, 0x60, 0x1a, 0xe0, 0x26, 0x4c, 0x1e, 0x9b, 0x04, 0x68, 0x20, 0x9a, 0x02, 0x62, 0x03, - 0x9b, 0x03, 0x63, 0xc2, 0x61, 0x03, 0x61, 0x82, 0x21, 0x40, 0xf0, 0x00, 0xfb, 0x27, 0x98, 0x03, - 0x99, 0x02, 0xf0, 0x00, 0xfb, 0x23, 0x4b, 0x17, 0x68, 0x1b, 0x2b, 0x00, 0xd0, 0x04, 0x68, 0x23, - 0x68, 0x28, 0x49, 0x15, 0x93, 0x00, 0xe0, 0x03, 0x68, 0x23, 0x49, 0x14, 0x68, 0x28, 0x93, 0x00, - 0x22, 0x02, 0x23, 0x01, 0xf0, 0x00, 0xfb, 0x02, 0x99, 0x02, 0x1c, 0x04, 0x98, 0x03, 0xf0, 0x00, - 0xfb, 0x15, 0xe0, 0x01, 0x24, 0x01, 0x42, 0x64, 0xb0, 0x07, 0x1c, 0x20, 0xbc, 0xf0, 0xbc, 0x02, - 0x47, 0x08, 0x46, 0xc0, 0x13, 0x77, 0xec, 0x20, 0x13, 0x77, 0xe2, 0x84, 0x13, 0x77, 0xec, 0x24, - 0x13, 0x77, 0xeb, 0x0c, 0x13, 0x77, 0xec, 0x40, 0x13, 0x77, 0xeb, 0x3c, 0x00, 0x00, 0x07, 0xf7, - 0x13, 0x77, 0xeb, 0xc4, 0x13, 0x77, 0xec, 0x28, 0x57, 0x46, 0x53, 0x03, 0x57, 0x46, 0x53, 0x02, - 0xb5, 0xf0, 0xb0, 0x85, 0x1c, 0x05, 0x1c, 0x0e, 0x92, 0x03, 0x28, 0x01, 0xd9, 0x00, 0xe0, 0x9e, - 0x4a, 0x53, 0x4b, 0x54, 0x68, 0x11, 0x42, 0x99, 0xd1, 0x02, 0x23, 0x01, 0x42, 0x5b, 0x60, 0x13, - 0x4b, 0x51, 0x68, 0x1a, 0x2a, 0x00, 0xd1, 0x02, 0x4a, 0x50, 0x60, 0x1a, 0xe0, 0x05, 0x4b, 0x4c, - 0x68, 0x18, 0x28, 0x00, 0xdb, 0x01, 0xf0, 0x00, 0xfa, 0xf5, 0x48, 0x49, 0x23, 0x01, 0x42, 0x5b, - 0x60, 0x03, 0x4a, 0x4b, 0x4b, 0x4b, 0x21, 0x00, 0x60, 0x11, 0x60, 0x19, 0x78, 0x31, 0x29, 0x5f, - 0xd1, 0x38, 0x78, 0x71, 0x29, 0x4e, 0xd1, 0x0c, 0x78, 0xb2, 0x2a, 0x55, 0xd1, 0x32, 0x78, 0xf2, - 0x2a, 0x4c, 0xd1, 0x2f, 0x22, 0x01, 0x60, 0x1a, 0x4b, 0x43, 0x60, 0x1a, 0x4b, 0x3d, 0x60, 0x03, - 0xe0, 0x70, 0x29, 0x44, 0xd1, 0x26, 0x78, 0xb1, 0x29, 0x45, 0xd1, 0x1c, 0x78, 0xf2, 0x2a, 0x56, - 0xd1, 0x20, 0x22, 0x01, 0x60, 0x1a, 0x79, 0x32, 0x2a, 0x57, 0xd1, 0x01, 0x22, 0x02, 0x60, 0x1a, - 0x4c, 0x3a, 0x21, 0x80, 0x1c, 0x20, 0x00, 0x49, 0xf0, 0x00, 0xfa, 0xa8, 0x1c, 0x20, 0x21, 0x00, - 0xf0, 0x00, 0xfa, 0x82, 0x4b, 0x2e, 0x1c, 0x05, 0x60, 0x18, 0x28, 0x00, 0xda, 0x52, 0x4b, 0x31, - 0x22, 0x00, 0x60, 0x1a, 0xe0, 0x4f, 0x29, 0x56, 0xd1, 0x04, 0x78, 0xf3, 0x2b, 0x44, 0xd1, 0x01, - 0x23, 0x01, 0x60, 0x13, 0x4b, 0x2e, 0x00, 0xaa, 0x58, 0xd0, 0x21, 0x01, 0xf0, 0x00, 0xfa, 0x6c, - 0x4c, 0x23, 0x60, 0x20, 0x28, 0x00, 0xda, 0x06, 0x2d, 0x00, 0xd1, 0x04, 0x48, 0x29, 0x21, 0x01, - 0xf0, 0x00, 0xfa, 0x62, 0x60, 0x20, 0x4f, 0x1e, 0x68, 0x3d, 0x2d, 0x00, 0xdb, 0x33, 0x4c, 0x1e, - 0x1c, 0x31, 0x68, 0x20, 0x22, 0x06, 0x30, 0x20, 0xf0, 0x00, 0xfa, 0x7c, 0x68, 0x20, 0xa9, 0x03, - 0x22, 0x04, 0x30, 0x3c, 0xf0, 0x00, 0xfa, 0x76, 0x68, 0x20, 0x26, 0x04, 0x1c, 0x03, 0x33, 0x20, - 0x60, 0x03, 0x23, 0x06, 0x60, 0x43, 0x1c, 0x03, 0x33, 0x3c, 0x60, 0x83, 0x60, 0xc6, 0x21, 0x40, - 0xf0, 0x00, 0xfa, 0x5c, 0x68, 0x23, 0x68, 0x38, 0x49, 0x17, 0x93, 0x00, 0x22, 0x02, 0x23, 0x00, - 0xf0, 0x00, 0xfa, 0x44, 0x1c, 0x05, 0x68, 0x20, 0x21, 0x40, 0x1c, 0x03, 0x33, 0x20, 0x60, 0x03, - 0x33, 0x1c, 0x60, 0x46, 0x60, 0x83, 0x60, 0xc6, 0xf0, 0x00, 0xfa, 0x48, 0xe0, 0x03, 0x25, 0x01, - 0x42, 0x6d, 0xe0, 0x00, 0x25, 0x00, 0xb0, 0x05, 0x1c, 0x28, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, - 0x13, 0x77, 0xe2, 0x84, 0x00, 0x66, 0x69, 0x99, 0x13, 0x77, 0xeb, 0xc4, 0x13, 0x77, 0xeb, 0xe0, - 0x13, 0x77, 0xec, 0x28, 0x13, 0x77, 0xec, 0x24, 0x13, 0x77, 0xec, 0x20, 0x13, 0x77, 0xe2, 0xa0, - 0x13, 0x77, 0xd9, 0x3c, 0x13, 0x77, 0xd9, 0x20, 0x57, 0x46, 0x53, 0x01, 0xb4, 0x7c, 0xb5, 0x00, - 0xf7, 0xfe, 0xfe, 0xaa, 0xbc, 0x02, 0xbc, 0x7c, 0x47, 0x08, 0xb5, 0x70, 0xb0, 0x88, 0x68, 0x85, - 0x1c, 0x01, 0x4b, 0x01, 0x47, 0x18, 0x00, 0x00, 0x20, 0x10, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, - 0xe6, 0x00, 0x08, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x07, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0x90, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0xb0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x03, 0xd0, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x03, 0xf0, 0xe1, 0x2f, 0xff, 0x1e, - 0xe6, 0x00, 0x04, 0x10, 0xe1, 0x2f, 0xff, 0x1e, 0xe6, 0x00, 0x04, 0x50, 0xe1, 0x2f, 0xff, 0x1e, - 0xef, 0x00, 0x00, 0xcc, 0xe1, 0x2f, 0xff, 0x1e, 0x46, 0x72, 0x1c, 0x01, 0x20, 0x04, 0xdf, 0xab, - 0x47, 0x10, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, 0x46, 0xc0, - 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0xac, 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x1f, - 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x98, - 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x19, 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, - 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x84, 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x13, - 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x70, - 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x0d, 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, - 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x5c, 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x07, - 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, 0xe9, 0x2d, 0x40, 0x80, 0xe5, 0x9f, 0x70, 0x48, - 0xe5, 0x97, 0x70, 0x00, 0xeb, 0x00, 0x00, 0x01, 0xe8, 0xbd, 0x40, 0x80, 0xe1, 0x2f, 0xff, 0x1e, - 0xe1, 0x2f, 0xff, 0x17, 0xb5, 0xf0, 0x46, 0x5f, 0x46, 0x56, 0x46, 0x4d, 0x46, 0x44, 0xb4, 0xf0, - 0x4b, 0x0b, 0x68, 0x1b, 0x47, 0x18, 0x00, 0x00, 0xe3, 0xc0, 0x01, 0x02, 0xe1, 0x2f, 0xff, 0x1e, - 0xe3, 0x80, 0x01, 0x02, 0xe1, 0x2f, 0xff, 0x1e, 0x13, 0x77, 0xc0, 0x10, 0x13, 0x77, 0xc0, 0x14, - 0x13, 0x77, 0xc0, 0x18, 0x13, 0x77, 0xc0, 0x1c, 0x13, 0x77, 0xc0, 0x20, 0x13, 0x77, 0xc0, 0x24, - 0x13, 0x77, 0xc0, 0x0c, 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, 0xe1, 0xa0, 0x00, 0x00, - 0xe2, 0x51, 0x20, 0x01, 0x01, 0x2f, 0xff, 0x1e, 0x3a, 0x00, 0x00, 0x36, 0xe1, 0x50, 0x00, 0x01, - 0x9a, 0x00, 0x00, 0x22, 0xe1, 0x11, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x23, 0xe3, 0x11, 0x02, 0x0e, - 0x01, 0xa0, 0x11, 0x81, 0x03, 0xa0, 0x30, 0x08, 0x13, 0xa0, 0x30, 0x01, 0xe3, 0x51, 0x02, 0x01, - 0x31, 0x51, 0x00, 0x00, 0x31, 0xa0, 0x12, 0x01, 0x31, 0xa0, 0x32, 0x03, 0x3a, 0xff, 0xff, 0xfa, - 0xe3, 0x51, 0x01, 0x02, 0x31, 0x51, 0x00, 0x00, 0x31, 0xa0, 0x10, 0x81, 0x31, 0xa0, 0x30, 0x83, - 0x3a, 0xff, 0xff, 0xfa, 0xe3, 0xa0, 0x20, 0x00, 0xe1, 0x50, 0x00, 0x01, 0x20, 0x40, 0x00, 0x01, - 0x21, 0x82, 0x20, 0x03, 0xe1, 0x50, 0x00, 0xa1, 0x20, 0x40, 0x00, 0xa1, 0x21, 0x82, 0x20, 0xa3, - 0xe1, 0x50, 0x01, 0x21, 0x20, 0x40, 0x01, 0x21, 0x21, 0x82, 0x21, 0x23, 0xe1, 0x50, 0x01, 0xa1, - 0x20, 0x40, 0x01, 0xa1, 0x21, 0x82, 0x21, 0xa3, 0xe3, 0x50, 0x00, 0x00, 0x11, 0xb0, 0x32, 0x23, - 0x11, 0xa0, 0x12, 0x21, 0x1a, 0xff, 0xff, 0xef, 0xe1, 0xa0, 0x00, 0x02, 0xe1, 0x2f, 0xff, 0x1e, - 0x03, 0xa0, 0x00, 0x01, 0x13, 0xa0, 0x00, 0x00, 0xe1, 0x2f, 0xff, 0x1e, 0xe3, 0x51, 0x08, 0x01, - 0x21, 0xa0, 0x18, 0x21, 0x23, 0xa0, 0x20, 0x10, 0x33, 0xa0, 0x20, 0x00, 0xe3, 0x51, 0x0c, 0x01, - 0x21, 0xa0, 0x14, 0x21, 0x22, 0x82, 0x20, 0x08, 0xe3, 0x51, 0x00, 0x10, 0x21, 0xa0, 0x12, 0x21, - 0x22, 0x82, 0x20, 0x04, 0xe3, 0x51, 0x00, 0x04, 0x82, 0x82, 0x20, 0x03, 0x90, 0x82, 0x20, 0xa1, - 0xe1, 0xa0, 0x02, 0x30, 0xe1, 0x2f, 0xff, 0x1e, 0xe1, 0x2f, 0xff, 0x1f, 0xe1, 0xa0, 0x00, 0x00, - 0xe3, 0x50, 0x00, 0x00, 0x13, 0xe0, 0x00, 0x00, 0xea, 0x00, 0x00, 0x6c, 0xe3, 0x51, 0x00, 0x00, - 0x0a, 0xff, 0xff, 0xf8, 0xe9, 0x2d, 0x40, 0x03, 0xeb, 0xff, 0xff, 0xbc, 0xe8, 0xbd, 0x40, 0x06, - 0xe0, 0x03, 0x00, 0x92, 0xe0, 0x41, 0x10, 0x03, 0xe1, 0x2f, 0xff, 0x1e, 0x47, 0x70, 0x46, 0xc0, - 0xb5, 0xf0, 0x1c, 0x05, 0x1c, 0x0e, 0x1c, 0x14, 0x2a, 0x0f, 0xd9, 0x03, 0x1c, 0x0b, 0x43, 0x03, - 0x07, 0x9f, 0xd0, 0x0a, 0x2c, 0x00, 0xd0, 0x05, 0x23, 0x00, 0x5c, 0xf2, 0x54, 0xea, 0x33, 0x01, - 0x42, 0xa3, 0xd1, 0xfa, 0xbc, 0xf0, 0xbc, 0x02, 0x47, 0x08, 0x1c, 0x15, 0x1c, 0x0c, 0x1c, 0x03, - 0x68, 0x26, 0x60, 0x1e, 0x68, 0x66, 0x60, 0x5e, 0x68, 0xa6, 0x60, 0x9e, 0x68, 0xe6, 0x3d, 0x10, - 0x60, 0xde, 0x34, 0x10, 0x33, 0x10, 0x2d, 0x0f, 0xd8, 0xf2, 0x3a, 0x10, 0x09, 0x17, 0x1c, 0x7e, - 0x01, 0x3f, 0x01, 0x36, 0x1b, 0xd7, 0x19, 0x85, 0x1c, 0x3c, 0x19, 0x8e, 0x2f, 0x03, 0xd9, 0xd9, - 0x1c, 0x34, 0x1c, 0x3b, 0x1c, 0x2a, 0xcc, 0x02, 0x3b, 0x04, 0xc2, 0x02, 0x2b, 0x03, 0xd8, 0xfa, - 0x3f, 0x04, 0x08, 0xbc, 0x1c, 0x63, 0x00, 0x9b, 0x00, 0xa4, 0x18, 0xed, 0x18, 0xf6, 0x1b, 0x3c, - 0xe7, 0xc8, 0x46, 0xc0, 0xb5, 0x70, 0x1c, 0x03, 0x07, 0x84, 0xd0, 0x0d, 0x2a, 0x00, 0xd0, 0x40, - 0x06, 0x0d, 0x3a, 0x01, 0x0e, 0x2d, 0x24, 0x03, 0xe0, 0x02, 0x2a, 0x00, 0xd0, 0x39, 0x3a, 0x01, - 0x70, 0x1d, 0x33, 0x01, 0x42, 0x23, 0xd1, 0xf8, 0x2a, 0x03, 0xd9, 0x29, 0x25, 0xff, 0x40, 0x0d, - 0x02, 0x2c, 0x43, 0x25, 0x04, 0x2c, 0x1c, 0x1e, 0x43, 0x25, 0x2a, 0x0f, 0xd9, 0x12, 0x1c, 0x1c, - 0x1c, 0x16, 0x3e, 0x10, 0x60, 0x25, 0x60, 0x65, 0x60, 0xa5, 0x60, 0xe5, 0x34, 0x10, 0x2e, 0x0f, - 0xd8, 0xf7, 0x3a, 0x10, 0x09, 0x16, 0x36, 0x01, 0x01, 0x36, 0x19, 0x9e, 0x23, 0x0f, 0x40, 0x1a, - 0x2a, 0x03, 0xd9, 0x0c, 0x1c, 0x34, 0x1c, 0x13, 0x3b, 0x04, 0xc4, 0x20, 0x2b, 0x03, 0xd8, 0xfb, - 0x3a, 0x04, 0x08, 0x93, 0x33, 0x01, 0x00, 0x9b, 0x18, 0xf6, 0x23, 0x03, 0x40, 0x1a, 0x1c, 0x33, - 0x2a, 0x00, 0xd0, 0x06, 0x06, 0x09, 0x0e, 0x0c, 0x21, 0x00, 0x54, 0x5c, 0x31, 0x01, 0x42, 0x8a, - 0xd1, 0xfb, 0xbc, 0x70, 0xbc, 0x02, 0x47, 0x08, 0x48, 0x45, 0x4c, 0x4f, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x75, 0x73, 0x62, 0x31, 0x32, 0x33, 0x00, 0x2f, 0x64, 0x65, 0x76, - 0x2f, 0x73, 0x64, 0x69, 0x6f, 0x2f, 0x73, 0x64, 0x68, 0x63, 0x00, 0x00, 0x13, 0x77, 0xd9, 0x20, - 0x13, 0x77, 0xd9, 0x2c, 0x13, 0x77, 0xd9, 0x20, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xff, 0x07, - 0xe5, 0x9f, 0xc0, 0x00, 0xe1, 0x2f, 0xff, 0x1c, 0x13, 0x77, 0xd7, 0xbd, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xff, 0x0c, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xff, 0x2c, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xff, 0x18, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xff, 0x10, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xfe, 0xf2, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xff, 0x36, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xfe, 0xf0, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xff, 0x14, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xfe, 0xee, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xfe, 0xf8, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xff, 0x3a, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xfe, 0xf0, 0x47, 0x78, 0x46, 0xc0, - 0xea, 0xff, 0xfe, 0xe8, 0x47, 0x78, 0x46, 0xc0, 0xea, 0xff, 0xfe, 0xea, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x73, 0x64, 0x69, 0x6f, 0x2f, 0x73, 0x64, 0x68, 0x63, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x2f, 0x64, 0x65, 0x76, 0x2f, 0x75, 0x73, 0x62, 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -}; -#define size_odip_frag 9120 diff --git a/source/mload/modules/odip_frag.h b/source/mload/modules/odip_frag.h deleted file mode 100644 index 43abdc30..00000000 --- a/source/mload/modules/odip_frag.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef ODIP_FRAG_H_ -#define ODIP_FRAG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern unsigned char odip_frag[9120]; - -#define odip_frag_size sizeof(odip_frag) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/network/CoverDownload.cpp b/source/network/CoverDownload.cpp deleted file mode 100644 index 9d0c0a5d..00000000 --- a/source/network/CoverDownload.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include -#include -#include "network/networkops.h" -#include "network/http.h" -#include "prompts/PromptWindows.h" -#include "prompts/ProgressWindow.h" -#include "FileOperations/fileops.h" -#include "settings/CSettings.h" -#include "language/gettext.h" -#include "usbloader/GetMissingGameFiles.hpp" -#include "utils/StringTools.h" - -#define VALID_IMAGE(x) (!(x.size == 36864 || x.size <= 1024 || x.size == 7386 || x.size <= 1174 || x.size == 4446 || x.data == NULL)) - -const char * serverURL3D = "http://wiitdb.com/wiitdb/artwork/cover3D/"; -const char * serverURL2D = "http://wiitdb.com/wiitdb/artwork/cover/"; -const char * serverURLOrigDiscs = "http://wiitdb.com/wiitdb/artwork/disc/"; -const char * serverURLCustomDiscs = "http://wiitdb.com/wiitdb/artwork/disccustom/"; - -static bool AbortRequested = false; - -static void AbortCallback(void) -{ - AbortRequested = true; -} - -static int CoverDownloadWithProgress(const char * url, const char * progressTitle, const char * writepath, std::vector & MissingFilesList) -{ - if(!url || !writepath) - return -1; - - if (!CreateSubfolder(writepath)) - { - WindowPrompt(tr( "Error !" ), fmt("%s %s", tr("Can't create directory"), writepath), tr( "OK" )); - return -1; - } - - char downloadURL[512]; - char progressMsg[255]; - int FilesSkipped = MissingFilesList.size(); - ProgressSetAbortCallback(AbortCallback); - - for(u32 i = 0; i < MissingFilesList.size(); ++i) - { - if(AbortRequested) - break; - - snprintf(progressMsg, sizeof(progressMsg), "http://wiitdb.com : %s.png", MissingFilesList[i].c_str()); - - ShowProgress(progressTitle, fmt("%i %s", MissingFilesList.size() - i, tr( "files left" )), progressMsg, i, MissingFilesList.size()); - - if(MissingFilesList[i].size() < 4) - continue; - - //Creates URL depending from which Country the game is - switch (MissingFilesList[i][3]) - { - case 'J': - sprintf(downloadURL, "%sJA/%s.png", url, MissingFilesList[i].c_str()); - break; - case 'W': - sprintf(downloadURL, "%sZH/%s.png", url, MissingFilesList[i].c_str()); - break; - case 'K': - sprintf(downloadURL, "%sKO/%s.png", url, MissingFilesList[i].c_str()); - break; - case 'P': - case 'D': - case 'F': - case 'I': - case 'S': - case 'H': - case 'U': - case 'X': - case 'Y': - case 'Z': - sprintf(downloadURL, "%s%s/%s.png", url, Settings.db_language, MissingFilesList[i].c_str()); - break; - case 'E': - sprintf(downloadURL, "%sUS/%s.png", url, MissingFilesList[i].c_str()); - break; - } - - struct block file = downloadfile(downloadURL); - if(!VALID_IMAGE(file)) - { - if(file.data) - free(file.data); - - snprintf(downloadURL, sizeof(downloadURL), "%sEN/%s.png", url, MissingFilesList[i].c_str()); - file = downloadfile(downloadURL); - if(!VALID_IMAGE(file)) - { - if(file.data) - free(file.data); - continue; - } - } - - char imgPath[200]; - snprintf(imgPath, sizeof(imgPath), "%s/%s.png", writepath, MissingFilesList[i].c_str()); - - FILE *pfile = fopen(imgPath, "wb"); - if (pfile != NULL) - { - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - FilesSkipped--; - } - free(file.data); - } - - //! Reset progress values - ProgressStop(); - ShowProgress(tr("Downloading file"), " ", 0, MissingFilesList.size(), MissingFilesList.size()); - ProgressSetAbortCallback(NULL); - - return FilesSkipped; -} - -void CoverDownload() -{ - int choice = WindowPrompt(tr( "Cover Download" ), 0, tr( "3D Covers" ), tr( "Flat Covers" ), tr( "Disc Images" ), tr( "Back" )); // ask for download choice - if (choice == 0) - return; - - const char * writepath = choice == 1 ? Settings.covers_path : choice == 2 ? Settings.covers2d_path : Settings.disc_path; - const char * downloadURL = choice == 1 ? serverURL3D : choice == 2 ? serverURL2D : NULL; - const char * progressTitle = choice != 3 ? tr("Downloading covers") : NULL; - if(choice == 3) - { - downloadURL = (Settings.discart == 0 || Settings.discart == 2) ? serverURLOrigDiscs : serverURLCustomDiscs; - progressTitle = (Settings.discart == 0 || Settings.discart == 2) ? tr("Downloading original Discarts") : tr("Downloading custom Discarts"); - } - - std::vector MissingFilesList; - GetMissingGameFiles(writepath, ".png", MissingFilesList); - - if(MissingFilesList.size() == 0) - { - WindowPrompt(tr( "No file missing!" ), 0, tr("OK")); - return; - } - - if (!IsNetworkInit() && !NetworkInitPrompt()) - return; - - const char * PromptText = choice == 3 ? tr("Download Boxart image?") : tr("Download Discart image?"); - - char tempCnt[80]; - snprintf(tempCnt, sizeof(tempCnt), "%i %s", MissingFilesList.size(), tr( "Missing files" )); - - if (WindowPrompt(PromptText, tempCnt, tr( "Yes" ), tr( "No" )) == 0) - return; - - AbortRequested = false; - - int FileSkipped = CoverDownloadWithProgress(downloadURL, progressTitle, writepath, MissingFilesList); - - if(choice == 3 && FileSkipped > 0 && Settings.discart > 1) - { - if(downloadURL == serverURLOrigDiscs) - { - progressTitle = tr("Trying custom Discarts"); - downloadURL = serverURLCustomDiscs; - } - else - { - progressTitle = tr("Trying original Discarts"); - downloadURL = serverURLOrigDiscs; - } - - GetMissingGameFiles(writepath, ".png", MissingFilesList); - FileSkipped = CoverDownloadWithProgress(downloadURL, progressTitle, writepath, MissingFilesList); - } - - if (FileSkipped == 0) - { - WindowPrompt(tr("Download finished"), tr("All images downloaded successfully."), tr( "OK" )); - } - else - { - sprintf(tempCnt, "%i %s", FileSkipped, tr( "files not found on the server!" )); - WindowPrompt(tr( "Download finished" ), tempCnt, tr( "OK" )); - } -} diff --git a/source/network/CoverDownload.h b/source/network/CoverDownload.h deleted file mode 100644 index 1c2bb7cd..00000000 --- a/source/network/CoverDownload.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef COVER_DOWNLOAD_H_ -#define COVER_DOWNLOAD_H_ - -void CoverDownload(); - -#endif diff --git a/source/network/FileDownloader.cpp b/source/network/FileDownloader.cpp deleted file mode 100644 index 5ea50f95..00000000 --- a/source/network/FileDownloader.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include "language/gettext.h" -#include "networkops.h" -#include "http.h" -#include "FileOperations/fileops.h" -#include "prompts/PromptWindows.h" -#include "prompts/ProgressWindow.h" -#include "utils/ShowError.h" - -/**************************************************************************** - * Download a file from a given url with a Progressbar - ****************************************************************************/ -int DownloadFileToMem(const char *url, u8 **inbuffer, u32 *size) -{ - if(strncasecmp(url, "http://", strlen("http://")) != 0) - { - ShowError(tr("Not a valid URL")); - return -1; - } - char *path = strchr(url + strlen("http://"), '/'); - - if(!path) - { - ShowError(tr("Not a valid URL path")); - return -2; - } - - int domainlength = path - url - strlen("http://"); - - if(domainlength == 0) - { - ShowError(tr("Not a valid domain")); - return -3; - } - - char domain[domainlength + 1]; - strncpy(domain, url + strlen("http://"), domainlength); - domain[domainlength] = '\0'; - - int connection = GetConnection(domain); - - if(connection < 0) - { - ShowError(tr("Could not connect to the server.")); - return -4; - } - - char header[1024]; - char * ptr = header; - ptr += sprintf(ptr, "GET %s HTTP/1.1\r\n", path); - ptr += sprintf(ptr, "Host: %s\r\n", domain); - ptr += sprintf(ptr, "Referer: %s\r\n", domain); - ptr += sprintf(ptr, "User-Agent: USB Loader GX\r\n"); - ptr += sprintf(ptr, "Pragma: no-cache\r\n"); - ptr += sprintf(ptr, "Cache-Control: no-cache\r\n"); - ptr += sprintf(ptr, "Connection: close\r\n\r\n"); - - char filename[255]; - memset(filename, 0, sizeof(filename)); - - u32 filesize = network_request(connection, header, (char *) &filename); - - if(!filesize) - { - net_close(connection); - ShowError(tr("Filesize is 0 Byte.")); - return -5; - } - - u32 blocksize = 10*1024; - - u8 * buffer = (u8 *) malloc(filesize); - if(!buffer) - { - net_close(connection); - ShowError(tr("Not enough memory.")); - return -6; - } - - u32 done = 0; - - while(done < filesize) - { - ShowProgress(tr("Downloading file..."), 0, filename, (f32) done, (f32) filesize, true, true); - - if(blocksize > filesize - done) - blocksize = filesize - done; - - - s32 read = network_read(connection, buffer+done, blocksize); - - if(read < 0) - { - free(buffer); - ProgressStop(); - net_close(connection); - ShowError(tr("Transfer failed")); - return -8; - } - else if(!read) - break; - - done += read; - } - - ProgressStop(); - net_close(connection); - - *inbuffer = buffer; - *size = filesize; - - return 1; -} - -/**************************************************************************** - * Download a file from a given url to a given path with a Progressbar - ****************************************************************************/ -int DownloadFileToPath(const char *orig_url, const char *dest, bool UseFilename) -{ - if(!orig_url || !dest) - { - ShowError(tr("No URL or Path specified.")); - return -2; - } - - bool addhttp = false; - - if(strncasecmp(orig_url, "http://", strlen("http://")) != 0) - { - addhttp = true; - } - - char url[strlen(orig_url) + (addhttp ? strlen("http://") : 0) + 1]; - - if(addhttp) - snprintf(url, sizeof(url), "http://%s", orig_url); - else - strcpy(url, orig_url); - - char *path = strchr(url + strlen("http://"), '/'); - - if(!path) - { - ShowError(tr("Not a valid URL path")); - return -2; - } - - int domainlength = path - url - strlen("http://"); - - if(domainlength == 0) - { - ShowError(tr("Not a valid domain")); - return -3; - } - - char domain[domainlength + 1]; - strncpy(domain, url + strlen("http://"), domainlength); - domain[domainlength] = '\0'; - - int connection = GetConnection(domain); - - if(connection < 0) - { - ShowError(tr("Could not connect to the server.")); - return -4; - } - - char header[1024]; - char * ptr = header; - ptr += sprintf(ptr, "GET %s HTTP/1.1\r\n", path); - ptr += sprintf(ptr, "Host: %s\r\n", domain); - ptr += sprintf(ptr, "Referer: %s\r\n", domain); - ptr += sprintf(ptr, "User-Agent: WiiXplorer\r\n"); - ptr += sprintf(ptr, "Pragma: no-cache\r\n"); - ptr += sprintf(ptr, "Cache-Control: no-cache\r\n"); - ptr += sprintf(ptr, "Connection: close\r\n\r\n"); - - char filename[255]; - memset(filename, 0, sizeof(filename)); - - u32 filesize = network_request(connection, header, (char *) &filename); - - if(!filesize) - { - net_close(connection); - ShowError(tr("Filesize is 0 Byte.")); - return -5; - } - - u32 blocksize = 10*1024; - - u8 *buffer = (u8 *) malloc(blocksize); - if(!buffer) - { - net_close(connection); - ShowError(tr("Not enough memory.")); - return -6; - } - - if(UseFilename) - { - if(dest[strlen(dest)-1] != '/') - strcat((char *) dest, "/"); - - CreateSubfolder(dest); - - strcat((char *) dest, filename); - } - - if(!UseFilename && strcmp(filename, "") == 0) - { - const char * ptr = strrchr(dest, '/'); - if(ptr) ptr++; - else ptr = dest; - - snprintf(filename, sizeof(filename), "%s", ptr); - } - - FILE *file = fopen(dest, "wb"); - if(!file) - { - net_close(connection); - free(buffer); - ShowError(tr("Cannot write to destination.")); - return -7; - } - - u32 done = 0; - - while(done < filesize) - { - ShowProgress(tr("Downloading file..."), 0, filename, (f32) done, (f32) filesize, true, true); - - if(blocksize > filesize - done) - blocksize = filesize - done; - - s32 read = network_read(connection, buffer, blocksize); - - if(read < 0) - { - free(buffer); - ProgressStop(); - net_close(connection); - fclose(file); - ShowError(tr("Transfer failed")); - return -8; - } - else if(!read) - break; - - fwrite(buffer, 1, read, file); - - done += read; - } - - free(buffer); - ProgressStop(); - net_close(connection); - fclose(file); - - return done; -} diff --git a/source/network/FileDownloader.h b/source/network/FileDownloader.h deleted file mode 100644 index 3fd2f24b..00000000 --- a/source/network/FileDownloader.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef FILE_DOWNLOADER_H_ -#define FILE_DOWNLOADER_H_ - -int DownloadFileToMem(const char *url, u8 **inbuffer, u32 *size); -int DownloadFileToPath(const char *url, const char *dest, bool UseFilename = true); - -#endif diff --git a/source/network/HTML_Stream.cpp b/source/network/HTML_Stream.cpp deleted file mode 100644 index ffac2d61..00000000 --- a/source/network/HTML_Stream.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * HTML_Stream Class - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include - -#include "HTML_Stream.h" -#include "networkops.h" -#include "http.h" - -#define htmlstringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos], (const char*) cmp, strlen((const char*) cmp)) - -HTML_Stream::HTML_Stream() -{ - HTML_File = NULL; - position = 0; - filesize = 0; -} - -HTML_Stream::HTML_Stream(const char * url) -{ - HTML_File = NULL; - position = 0; - filesize = 0; - - LoadLink(url); -} - -HTML_Stream::~HTML_Stream() -{ - if (HTML_File) free(HTML_File); -} - -bool HTML_Stream::LoadLink(const char * url) -{ - if (!IsNetworkInit()) return false; - - struct block file = downloadfile(url); - - if (!file.data || !file.size) return false; - - if (HTML_File) free(HTML_File); - - HTML_File = (char *) file.data; - filesize = file.size; - position = 0; - - return true; -} - -const char * HTML_Stream::FindStringStart(const char * string) -{ - if (!HTML_File) return NULL; - - while ((u32) position < filesize) - { - if (htmlstringcompare( HTML_File, string, position ) == 0) break; - - position++; - } - - return &HTML_File[position]; -} - -const char * HTML_Stream::FindStringEnd(const char * string) -{ - if (!HTML_File) return NULL; - - while ((u32) position < filesize) - { - if (htmlstringcompare( HTML_File, string, position ) == 0) break; - - position++; - } - - if ((u32) position >= filesize) - { - return NULL; - } - - position += strlen(string); - - return &HTML_File[position]; -} - -char * HTML_Stream::CopyString(const char * stopat) -{ - if (!stopat || !HTML_File) return NULL; - - u32 blocksize = 1024; - u32 counter = 0; - u32 allocatedsize = 0; - - char * outtext = (char*) malloc(blocksize); - if (!outtext) return NULL; - - allocatedsize = blocksize; - memset(outtext, 0, blocksize); - - while ((htmlstringcompare( HTML_File, stopat, position ) != 0) && (position + strlen(stopat) < filesize)) - { - if (counter > blocksize) - { - blocksize += 1024; - char * tmpblock = (char*) realloc(outtext, blocksize); - if (!tmpblock) - { - free(outtext); - outtext = NULL; - free(tmpblock); - return NULL; - } - - outtext = tmpblock; - } - - outtext[counter] = HTML_File[position]; - position++; - counter++; - } - - outtext[counter] = '\0'; - outtext = (char*) realloc(outtext, counter + 1); - - return outtext; -} - -int HTML_Stream::Seek(u32 pos, int origin) -{ - if (!HTML_File) return -1; - - switch (origin) - { - case SEEK_SET: - position = pos; - break; - case SEEK_CUR: - position += pos; - break; - case SEEK_END: - position = filesize + pos; - break; - } - - return 0; -} - -void HTML_Stream::Rewind() -{ - if (!HTML_File) return; - - position = 0; -} - -int HTML_Stream::GetPosition() -{ - return position; -} diff --git a/source/network/HTML_Stream.h b/source/network/HTML_Stream.h deleted file mode 100644 index c2b30603..00000000 --- a/source/network/HTML_Stream.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * HTML_Stream Class - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef ___HTML_STREAM_H_ -#define ___HTML_STREAM_H_ - -#include - -class HTML_Stream -{ - public: - //!Constructor - HTML_Stream(); - //!\param url from where to the HTML file - HTML_Stream(const char * url); - //!Destructor - ~HTML_Stream(); - //!Load url - bool LoadLink(const char * url); - //! Find start of a string from current position in the html - //!\param string to find - const char * FindStringStart(const char * string); - //! Find end of a string from current position in the html - //!\param string to find - const char * FindStringEnd(const char * string); - //!CopyString from current position in html till stopat string - //!\param stopat string before which to stop copying (e.g. ) - //!\param outtext variable is allocated with malloc and must be set 0 before - char * CopyString(const char * stopat); - //!Seek position in file - //!\param position seeked - //!\param seek origin (SEEK_SET, SEEK_CUR, SEEK_END) - int Seek(u32 pos, int origin); - //!Rewind to the start of the html - void Rewind(); - //!Get current position - int GetPosition(); - protected: - int position; - u32 filesize; - char * HTML_File; -}; - -#endif diff --git a/source/network/URL_List.cpp b/source/network/URL_List.cpp deleted file mode 100644 index b2b54b4d..00000000 --- a/source/network/URL_List.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** - * URL List Class - * for USB Loader GX - * by dimok - ***************************************************************************/ -#include -#include -#include -#include - -#include "URL_List.h" - -URL_List::URL_List(const char * url) -{ - Links = NULL; - urlcount = 0; - - if (!IsNetworkInit()) - { - urlcount = -1; - return; - } - - struct block file = downloadfile(url); - - if (!file.data || !file.size) - { - urlcount = -2; - return; - } - - u32 cnt = 0; - char temp[1024]; - - Links = (Link_Info *) malloc(sizeof(Link_Info)); - if (!Links) - { - free(file.data); - urlcount = -3; - return; - } - - memset(&Links[urlcount], 0, sizeof(Link_Info)); - - while (cnt < file.size) - { - - if (file.data[cnt] == '"' && file.data[cnt - 1] == '=' && file.data[cnt - 2] == 'f' && file.data[cnt - 3] - == 'e' && file.data[cnt - 4] == 'r' && file.data[cnt - 5] == 'h') - { - - u32 cnt2 = 0; - cnt++; - while (file.data[cnt] != '"' && cnt2 < 1024) - { - temp[cnt2] = file.data[cnt]; - cnt2++; - cnt++; - } - temp[cnt2] = '\0'; - - Links = (Link_Info *) realloc(Links, (urlcount + 1) * sizeof(Link_Info)); - - if (!Links) - { - for (int i = 0; i == urlcount; i++) - { - delete Links[i].URL; - Links[i].URL = NULL; - } - free(Links); - Links = NULL; - free(file.data); - urlcount = -4; - break; - } - - memset(&(Links[urlcount]), 0, sizeof(Link_Info)); - - Links[urlcount].URL = new char[cnt2 + 1]; - - if (!Links[urlcount].URL) - { - for (int i = 0; i == urlcount; i++) - { - delete Links[i].URL; - Links[i].URL = NULL; - } - free(Links); - Links = NULL; - free(file.data); - urlcount = -5; - break; - } - - snprintf(Links[urlcount].URL, cnt2 + 1, "%s", temp); - - if (strncmp(Links[urlcount].URL, "http://", strlen("http://")) != 0) - Links[urlcount].direct = false; - else Links[urlcount].direct = true; - - urlcount++; - } - cnt++; - } - - free(file.data); -} - -URL_List::~URL_List() -{ - for (int i = 0; i == urlcount; i++) - { - delete Links[i].URL; - Links[i].URL = NULL; - } - - if (Links != NULL) - { - free(Links); - Links = NULL; - } -} - -char * URL_List::GetURL(int ind) -{ - if (ind > urlcount || ind < 0 || !Links || urlcount <= 0) - return NULL; - else return Links[ind].URL; -} - -int URL_List::GetURLCount() -{ - return urlcount; -} - -static int ListCompare(const void *a, const void *b) -{ - Link_Info *ab = (Link_Info*) a; - Link_Info *bb = (Link_Info*) b; - - return stricmp((char *) ab->URL, (char *) bb->URL); -} -void URL_List::SortList() -{ - qsort(Links, urlcount, sizeof(Link_Info), ListCompare); -} diff --git a/source/network/URL_List.h b/source/network/URL_List.h deleted file mode 100644 index a78f579f..00000000 --- a/source/network/URL_List.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * URL List Class - * for USB Loader GX - * by dimok - ***************************************************************************/ -#ifndef ___URLLIST_H_ -#define ___URLLIST_H_ - -#include "network/networkops.h" -#include "network/http.h" - -typedef struct -{ - char *URL; - bool direct; -} Link_Info; - -class URL_List -{ - public: - //!Constructor - //!\param url from where to get the list of links - URL_List(const char *url); - //!Destructor - ~URL_List(); - //! Get the a filepath of the list - //!\param list index - char * GetURL(int index); - //! Is it a direct URL or just a file or path under the main url - bool IsDirectURL(int index); - //! Get the number of links counted - int GetURLCount(); - //! Sort list - void SortList(); - protected: - int urlcount; - Link_Info *Links; -}; - -#endif diff --git a/source/network/dns.c b/source/network/dns.c deleted file mode 100644 index ab189f17..00000000 --- a/source/network/dns.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "dns.h" - -/** - * Resolves a domainname to an ip address - * It makes use of net_gethostbyname from libogc, which in turn makes use of a Wii BIOS function - * Just like the net_gethostbyname function this function is NOT threadsafe! - * - * @param char* The domain name to resolve - * @return u32 The ipaddress represented by four bytes inside an u32 (in network order) - */ -u32 getipbyname(char *domain) -{ - //Care should be taken when using net_gethostbyname, - //it returns a static buffer which makes it not threadsafe - //TODO: implement some locking mechanism to make below code atomic - struct hostent *host = net_gethostbyname(domain); - - if (host == NULL) - { - return 0; - } - - u32 *ip = (u32*) host->h_addr_list[0]; - return *ip; -} - -//Defines how many DNS entries should be cached by getipbynamecached() -#define MAX_DNS_CACHE_ENTRIES 20 - -//The cache is defined as a linked list, -//The last resolved domain name will always be at the front -//This will allow heavily used domainnames to always stay cached -struct dnsentry -{ - char *domain; - u32 ip; - struct dnsentry *nextnode; -}; - -static struct dnsentry *firstdnsentry = NULL; -static int dnsentrycount = 0; - -/** - * Performs the same function as getipbyname(), - * except that it will prevent extremely expensive net_gethostbyname() calls by caching the result - */ -u32 getipbynamecached(char *domain) -{ - //Search if this domainname is already cached - struct dnsentry *node = firstdnsentry; - struct dnsentry *previousnode = NULL; - - while (node != NULL) - { - if (strcmp(node->domain, domain) == 0) - { - //DNS node found in the cache, move it to the front of the list - if (previousnode != NULL) previousnode->nextnode = node->nextnode; - - if (node != firstdnsentry) node->nextnode = firstdnsentry; - firstdnsentry = node; - - return node->ip; - } - //Go to the next element in the list - previousnode = node; - node = node->nextnode; - } - u32 ip = getipbyname(domain); - - //No cache of this domain could be found, create a cache node and add it to the front of the cache - struct dnsentry *newnode = malloc(sizeof(struct dnsentry)); - if (newnode == NULL) - { - return ip; - } - - newnode->ip = ip; - newnode->domain = malloc(strlen(domain) + 1); - if (newnode->domain == NULL) - { - free(newnode); - return ip; - } - strcpy(newnode->domain, domain); - - newnode->nextnode = firstdnsentry; - firstdnsentry = newnode; - dnsentrycount++; - - //If the cache grows too big delete the last (and probably least important) node of the list - if (dnsentrycount > MAX_DNS_CACHE_ENTRIES) - { - struct dnsentry *node = firstdnsentry; - struct dnsentry *previousnode = NULL; - - //Fetch the last two elements of the list - while (node->nextnode != NULL) - { - previousnode = node; - node = node->nextnode; - } - - if (node == NULL) - { - printf("Configuration error, MAX_DNS_ENTRIES reached while the list is empty\n"); - exit(1); - } - else if (previousnode == NULL) - { - firstdnsentry = NULL; - } - else - { - previousnode->nextnode = NULL; - } - - free(node->domain); - free(node); - dnsentrycount--; - } - - return newnode->ip; -} diff --git a/source/network/dns.h b/source/network/dns.h deleted file mode 100644 index f979550f..00000000 --- a/source/network/dns.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _DNS_H_ -#define _DNS_H_ - -#include -#include -#include -#include - -#include //usleep -#ifdef __cplusplus -extern "C" -{ -#endif - - u32 getipbyname(char *domain); - u32 getipbynamecached(char *domain); - -#ifdef __cplusplus -} -#endif - -#endif /* _DNS_H_ */ diff --git a/source/network/http.c b/source/network/http.c deleted file mode 100644 index 85dea150..00000000 --- a/source/network/http.c +++ /dev/null @@ -1,261 +0,0 @@ -#include "http.h" -#include "../svnrev.h" - -extern char incommingIP[50]; - -/** - * Emptyblock is a statically defined variable for functions to return if they are unable - * to complete a request - */ -const struct block emptyblock = { 0, NULL }; - -//The maximum amount of bytes to send per net_write() call -//#define NET_BUFFER_SIZE 1024 -#define NET_BUFFER_SIZE 3600 - -// Write our message to the server -static s32 send_message(s32 server, char *msg) -{ - s32 bytes_transferred = 0; - s32 remaining = strlen(msg); - while (remaining) - { - if ((bytes_transferred = net_write(server, msg, remaining > NET_BUFFER_SIZE ? NET_BUFFER_SIZE : remaining)) > 0) - { - remaining -= bytes_transferred; - usleep(20 * 1000); - } - else if (bytes_transferred < 0) - { - return bytes_transferred; - } - else - { - return -ENODATA; - } - } - return 0; -} - -/** - * Connect to a remote server via TCP on a specified port - * - * @param u32 ip address of the server to connect to - * @param u32 the port to connect to on the server - * @return s32 The connection to the server (negative number if connection could not be established) - */ -static s32 server_connect(u32 ipaddress, u32 socket_port) -{ - //Initialize socket - s32 connection = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); - if (connection < 0) return connection; - - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = socket_port; - connect_addr.sin_addr.s_addr = ipaddress; - - sprintf(incommingIP, "%s", inet_ntoa(connect_addr.sin_addr)); - - //Attemt to open the socket - if (net_connect(connection, (struct sockaddr*) &connect_addr, sizeof(connect_addr)) == -1) - { - net_close(connection); - return -1; - } - return connection; -} - -//The amount of memory in bytes reserved initially to store the HTTP response in -//Be careful in increasing this number, reading from a socket on the Wii -//will fail if you request more than 20k or so -#define HTTP_BUFFER_SIZE 1024 * 5 - -//The amount of memory the buffer should expanded with if the buffer is full -#define HTTP_BUFFER_GROWTH 1024 * 5 - -/** - * This function reads all the data from a connection into a buffer which it returns. - * It will return an empty buffer if something doesn't go as planned - * - * @param s32 connection The connection identifier to suck the response out of - * @return block A 'block' struct (see http.h) in which the buffer is located - */ -struct block read_message(s32 connection) -{ - //Create a block of memory to put in the response - struct block buffer; - buffer.data = malloc(HTTP_BUFFER_SIZE); - buffer.size = HTTP_BUFFER_SIZE; - - if (buffer.data == NULL) - { - return emptyblock; - } - - //The offset variable always points to the first byte of memory that is free in the buffer - u32 offset = 0; - - while (1) - { - //Fill the buffer with a new batch of bytes from the connection, - //starting from where we left of in the buffer till the end of the buffer - s32 bytes_read = net_read(connection, buffer.data + offset, buffer.size - offset); - - //Anything below 0 is an error in the connection - if (bytes_read < 0) - { - //printf("Connection error from net_read() Errorcode: %i\n", bytes_read); - return emptyblock; - } - - //No more bytes were read into the buffer, - //we assume this means the HTTP response is done - if (bytes_read == 0) - { - break; - } - - offset += bytes_read; - - //Check if we have enough buffer left over, - //if not expand it with an additional HTTP_BUFFER_GROWTH worth of bytes - if (offset >= buffer.size) - { - buffer.size += HTTP_BUFFER_GROWTH; - buffer.data = realloc(buffer.data, buffer.size); - - if (buffer.data == NULL) - { - return emptyblock; - } - } - } - - //At the end of above loop offset should be precisely the amount of bytes that were read from the connection - buffer.size = offset; - - //Shrink the size of the buffer so the data fits exactly in it - buffer.data = realloc(buffer.data, buffer.size); - - return buffer; -} - -/** - * Downloads the contents of a URL to memory - * This method is not threadsafe (because networking is not threadsafe on the Wii) - */ -struct block downloadfile(const char *url) -{ - //Check if the url starts with "http://", if not it is not considered a valid url - if (strncmp(url, "http://", strlen("http://")) != 0) - { - //printf("URL '%s' doesn't start with 'http://'\n", url); - return emptyblock; - } - - //Locate the path part of the url by searching for '/' past "http://" - char *path = strchr(url + strlen("http://"), '/'); - - //At the very least the url has to end with '/', ending with just a domain is invalid - if (path == NULL) - { - //printf("URL '%s' has no PATH part\n", url); - return emptyblock; - } - - //Extract the domain part out of the url - int domainlength = path - url - strlen("http://"); - - if (domainlength == 0) - { - //printf("No domain part in URL '%s'\n", url); - return emptyblock; - } - - char domain[domainlength + 1]; - strlcpy(domain, url + strlen("http://"), domainlength + 1); - - //Parsing of the URL is done, start making an actual connection - u32 ipaddress = getipbynamecached(domain); - - if (ipaddress == 0) - { - //printf("\ndomain %s could not be resolved", domain); - return emptyblock; - } - - s32 connection = server_connect(ipaddress, 80); - - if (connection < 0) - { - //printf("Error establishing connection"); - return emptyblock; - } - - //Form a nice request header to send to the webserver - char* headerformat = "GET %s HTTP/1.0\r\nHost: %s\r\nReferer: %s\r\nUser-Agent: USBLoaderGX r%s\r\n\r\n"; - ; - char header[strlen(headerformat) + strlen(path) + strlen(domain) + strlen(domain)]; - sprintf(header, headerformat, path, domain, domain, GetRev()); - - //Do the request and get the response - send_message(connection, header); - struct block response = read_message(connection); - net_close(connection); - - //Search for the 4-character sequence \r\n\r\n in the response which signals the start of the http payload (file) - unsigned char *filestart = NULL; - u32 filesize = 0; - int i; - for (i = 3; i < response.size; i++) - { - if (response.data[i] == '\n' && response.data[i - 1] == '\r' && response.data[i - 2] == '\n' && response.data[i - - 3] == '\r') - { - filestart = response.data + i + 1; - filesize = response.size - i - 1; - break; - } - } - - if (filestart == NULL) - { - //printf("HTTP Response was without a file\n"); - free(response.data); - return emptyblock; - } - - //Copy the file part of the response into a new memoryblock to return - struct block file; - file.data = malloc(filesize); - file.size = filesize; - - if (file.data == NULL) - { - //printf("No more memory to copy file from HTTP response\n"); - free(response.data); - return emptyblock; - } - - memcpy(file.data, filestart, filesize); - - //Dispose of the original response - free(response.data); - - return file; -} - -s32 GetConnection(char * domain) -{ - - u32 ipaddress = getipbynamecached(domain); - if (ipaddress == 0) - { - return -1; - } - s32 connection = server_connect(ipaddress, 80); - return connection; - -} diff --git a/source/network/http.h b/source/network/http.h deleted file mode 100644 index 1998b32a..00000000 --- a/source/network/http.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _HTTP_H_ -#define _HTTP_H_ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "dns.h" - - /** - * A simple structure to keep track of the size of a malloc()ated block of memory - */ - struct block - { - u32 size; - unsigned char *data; - }; - - extern const struct block emptyblock; - - struct block downloadfile(const char *url); - s32 GetConnection(char * domain); - -#ifdef __cplusplus -} -#endif - -#endif /* _HTTP_H_ */ diff --git a/source/network/networkops.cpp b/source/network/networkops.cpp deleted file mode 100644 index fe80eb08..00000000 --- a/source/network/networkops.cpp +++ /dev/null @@ -1,477 +0,0 @@ -/**************************************************************************** - * Network Operations - * for USB Loader GX - * - * HTTP operations - * Written by dhewg/bushing modified by dimok - ****************************************************************************/ - -#include -#include -#include -#include - -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "settings/CSettings.h" -#include "networkops.h" -#include "main.h" -#include "http.h" -#include "svnrev.h" -#include "buildtype.h" -#include "gecko.h" -#include "update.h" - -#define PORT 4299 - -/*** Incomming filesize ***/ -u32 infilesize = 0; -u32 uncfilesize = 0; - -bool updateavailable = false; -s32 connection; -static s32 socket; -static bool updatechecked = false; -static bool networkinitialized = false; -static bool checkincomming = false; -static bool waitforanswer = false; -static char IP[16]; -char incommingIP[50]; -char wiiloadVersion[2]; - -static lwp_t networkthread = LWP_THREAD_NULL; -static bool networkHalt = true; - -/**************************************************************************** - * Initialize_Network - ***************************************************************************/ -void Initialize_Network(void) -{ - - if (networkinitialized) return; - - s32 result; - - result = if_config(IP, NULL, NULL, true); - - if (result < 0) - { - networkinitialized = false; - return; - } - else - { - networkinitialized = true; - return; - } -} - -/**************************************************************************** - * DeinitNetwork - ***************************************************************************/ -void DeinitNetwork(void) -{ - net_wc24cleanup(); - net_deinit(); - networkinitialized = false; -} - -/**************************************************************************** - * Check if network was initialised - ***************************************************************************/ -bool IsNetworkInit(void) -{ - return networkinitialized; -} - -/**************************************************************************** - * Get network IP - ***************************************************************************/ -char * GetNetworkIP(void) -{ - return IP; -} - -/**************************************************************************** - * Get incomming IP - ***************************************************************************/ -char * GetIncommingIP(void) -{ - return incommingIP; -} - -s32 network_request(s32 connect, const char * request, char * filename) -{ - char buf[1024]; - char *ptr = NULL; - - u32 cnt, size; - s32 ret; - - /* Send request */ - ret = net_send(connect, request, strlen(request), 0); - if (ret < 0) return ret; - - /* Clear buffer */ - memset(buf, 0, sizeof(buf)); - - /* Read HTTP header */ - for (cnt = 0; !strstr(buf, "\r\n\r\n"); cnt++) - if (net_recv(connect, buf + cnt, 1, 0) <= 0) return -1; - - /* HTTP request OK? */ - if (!strstr(buf, "HTTP/1.1 200 OK")) return -1; - - if (filename) - { - /* Get filename */ - ptr = strstr(buf, "filename=\""); - - if (ptr) - { - ptr += sizeof("filename=\"") - 1; - - for (cnt = 0; ptr[cnt] != '\r' && ptr[cnt] != '\n' && ptr[cnt] != '"'; cnt++) - { - filename[cnt] = ptr[cnt]; - filename[cnt + 1] = '\0'; - } - } - } - - /* Retrieve content size */ - ptr = strstr(buf, "Content-Length:"); - if (!ptr) return -1; - - sscanf(ptr, "Content-Length: %u", &size); - return size; -} - -s32 network_read(s32 connect, u8 *buf, u32 len) -{ - u32 read = 0; - s32 ret = -1; - - /* Data to be read */ - while (read < len) - { - /* Read network data */ - ret = net_read(connect, buf + read, len - read); - if (ret < 0) return ret; - - /* Read finished */ - if (!ret) break; - - /* Increment read variable */ - read += ret; - } - - return read; -} - -/**************************************************************************** - * Download request - ***************************************************************************/ -s32 download_request(const char * url, char * filename) -{ - - //Check if the url starts with "http://", if not it is not considered a valid url - if (strncmp(url, "http://", strlen("http://")) != 0) - { - return -1; - } - - //Locate the path part of the url by searching for '/' past "http://" - char *path = strchr(url + strlen("http://"), '/'); - - //At the very least the url has to end with '/', ending with just a domain is invalid - if (path == NULL) - { - return -1; - } - - //Extract the domain part out of the url - int domainlength = path - url - strlen("http://"); - - if (domainlength == 0) - { - return -1; - } - - char domain[domainlength + 1]; - strlcpy(domain, url + strlen("http://"), domainlength + 1); - - connection = GetConnection(domain); - if (connection < 0) - { - return -1; - } - - //Form a nice request header to send to the webserver - char header[strlen(path) + strlen(domain) + strlen(url) + 100]; - sprintf(header, "GET %s HTTP/1.1\r\nHost: %s\r\nReferer: %s\r\nConnection: close\r\n\r\n", path, domain, url); - - s32 filesize = network_request(connection, header, filename); - - return filesize; -} - -/**************************************************************************** - * HTML HEAD request - ***************************************************************************/ -char * HEAD_Request(const char * url) -{ - if(strncmp(url, "http://", strlen("http://")) != 0) - { - gprintf("Not a valid URL"); - return NULL; - } - char *path = strchr(url + strlen("http://"), '/'); - - if(!path) - { - gprintf("Not a valid URL path"); - return NULL; - } - - int domainlength = path - url - strlen("http://"); - - if(domainlength == 0) - { - gprintf("Not a valid domain"); - return NULL; - } - - char domain[domainlength + 1]; - strncpy(domain, url + strlen("http://"), domainlength); - domain[domainlength] = '\0'; - - connection = GetConnection(domain); - if(connection < 0) - { - gprintf("Could not connect to the server."); - return NULL; - } - - char header[strlen(path)+strlen(domain)*2+150]; - sprintf(header, "HEAD %s HTTP/1.1\r\nHost: %s\r\nReferer: %s\r\nUser-Agent: USB Loader GX\r\nConnection: close\r\n\r\n", path, domain, domain); - - /* Send request */ - s32 ret = net_send(connection, header, strlen(header), 0); - if (ret < 0) - { - CloseConnection(); - return NULL; - } - - u32 cnt = 0; - char * buf = (char *) malloc(1024); - memset(buf, 0, 1024); - - for (cnt = 0; !strstr(buf, "\r\n\r\n") && cnt < 1024; cnt++) - { - if(net_recv(connection, buf + cnt, 1, 0) <= 0) - { - CloseConnection(); - free(buf); - return NULL; - } - } - - CloseConnection(); - - return buf; -} - -void CloseConnection() -{ - - net_close(connection); - - if (waitforanswer) - { - net_close(socket); - waitforanswer = false; - } -} - -/**************************************************************************** - * NetworkWait - ***************************************************************************/ -int NetworkWait() -{ - - if (!checkincomming) return -3; - - struct sockaddr_in sin; - struct sockaddr_in client_address; - socklen_t addrlen = sizeof(client_address); - - //Open socket - socket = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); - - if (socket == INVALID_SOCKET) - { - return socket; - } - - sin.sin_family = AF_INET; - sin.sin_port = htons( PORT ); - sin.sin_addr.s_addr = htonl( INADDR_ANY ); - - if (net_bind(socket, (struct sockaddr*) &sin, sizeof(sin)) < 0) - { - net_close(socket); - return -1; - } - - if (net_listen(socket, 3) < 0) - { - net_close(socket); - return -1; - } - - connection = net_accept(socket, (struct sockaddr*) &client_address, &addrlen); - - sprintf(incommingIP, "%s", inet_ntoa(client_address.sin_addr)); - - if (connection < 0) - { - net_close(connection); - net_close(socket); - return -4; - - } - else - { - - unsigned char haxx[9]; - //skip haxx - net_read(connection, &haxx, 8); - wiiloadVersion[0] = haxx[4]; - wiiloadVersion[1] = haxx[5]; - - net_read(connection, &infilesize, 4); - - if (haxx[4] > 0 || haxx[5] > 4) - { - net_read(connection, &uncfilesize, 4); // Compressed protocol, read another 4 bytes - } - waitforanswer = true; - checkincomming = false; - networkHalt = true; - } - - return 1; -} - -/**************************************************************************** - * Update check - ***************************************************************************/ -int CheckUpdate() -{ - if (!networkinitialized) - return -1; - - int revnumber = 0; - int currentrev = atoi(GetRev()); - -#ifdef FULLCHANNEL - struct block file = downloadfile( "http://www.techjawa.com/usbloadergx/wadrev.txt" ); -#else - struct block file = downloadfile("http://www.techjawa.com/usbloadergx/rev.txt"); -#endif - - if (file.data != NULL) - { - revnumber = atoi((char *) file.data); - free(file.data); - } - - if (revnumber > currentrev) - return revnumber; - - return -1; -} - -/**************************************************************************** - * HaltNetwork - ***************************************************************************/ -void HaltNetworkThread() -{ - networkHalt = true; - checkincomming = false; - - if (waitforanswer) CloseConnection(); - - // wait for thread to finish - while (!LWP_ThreadIsSuspended(networkthread)) - usleep(100); -} - -/**************************************************************************** - * ResumeNetworkThread - ***************************************************************************/ -void ResumeNetworkThread() -{ - networkHalt = false; - LWP_ResumeThread(networkthread); -} - -/**************************************************************************** - * Resume NetworkWait - ***************************************************************************/ -void ResumeNetworkWait() -{ - networkHalt = true; - checkincomming = true; - waitforanswer = true; - infilesize = 0; - connection = -1; - LWP_ResumeThread(networkthread); -} - -/********************************************************************************* - * Networkthread for background network initialize and update check with idle prio - *********************************************************************************/ -static void * networkinitcallback(void *arg) -{ - while (1) - { - - if (!checkincomming && networkHalt) LWP_SuspendThread(networkthread); - - Initialize_Network(); - - if (networkinitialized == true && updatechecked == false) - { - - if (CheckUpdate() > 0) updateavailable = true; - - //suspend thread - updatechecked = true; - networkHalt = true; - checkincomming = false; - } - - if (checkincomming) NetworkWait(); - } - return NULL; -} - -/**************************************************************************** - * InitNetworkThread with priority 0 (idle) - ***************************************************************************/ -void InitNetworkThread() -{ - LWP_CreateThread(&networkthread, networkinitcallback, NULL, NULL, 16384, 0); -} - -/**************************************************************************** - * ShutdownThread - ***************************************************************************/ -void ShutdownNetworkThread() -{ - LWP_JoinThread(networkthread, NULL); - networkthread = LWP_THREAD_NULL; -} diff --git a/source/network/networkops.h b/source/network/networkops.h deleted file mode 100644 index 8903584f..00000000 --- a/source/network/networkops.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * Network Operations - * for USB Loader GX - * - * HTTP operations - * Written by dhewg/bushing modified by dimok - ****************************************************************************/ -#ifndef _NETWORKOPS_H_ -#define _NETWORKOPS_H_ - -#define NETWORKBLOCKSIZE 5*1024 //5KB -void Initialize_Network(void); -void DeinitNetwork(void); -bool IsNetworkInit(void); -char * GetNetworkIP(void); -char * GetIncommingIP(void); -bool ShutdownWC24(); -s32 network_request(s32 connection, const char * request, char * filename); -s32 network_read(s32 connection, u8 *buf, u32 len); -s32 download_request(const char * url, char * filename = NULL); -void CloseConnection(); -int CheckUpdate(); -char * HEAD_Request(const char * url); -void HaltNetworkThread(); -void ResumeNetworkWait(); -void ResumeNetworkThread(); -void InitNetworkThread(); -void ShutdownNetworkThread(); - -#endif diff --git a/source/network/update.cpp b/source/network/update.cpp deleted file mode 100644 index 1f2042b6..00000000 --- a/source/network/update.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * update.cpp - * - * Update operations - * for Wii-Xplorer 2009 - ***************************************************************************/ -#include -#include -#include -#include - -#include "gecko.h" -#include "ZipFile.h" -#include "http.h" -#include "networkops.h" -#include "HTML_Stream.h" -#include "FileDownloader.h" -#include "settings/CSettings.h" -#include "settings/GameTitles.h" -#include "language/gettext.h" -#include "language/UpdateLanguage.h" -#include "homebrewboot/BootHomebrew.h" -#include "utils/StringTools.h" -#include "utils/ShowError.h" -#include "prompts/PromptWindows.h" -#include "FileOperations/fileops.h" -#include "xml/WiiTDB.hpp" - -static const char * WiiTDB_URL = "http://wiitdb.com/wiitdb.zip"; - -/**************************************************************************** - * Checking if an Update is available - ***************************************************************************/ -int CheckForBetaUpdate() -{ - int revnumber = 0; - - HTML_Stream HTML("http://code.google.com/p/usbloader-gui/downloads/list"); - - const char * HTML_Pos = NULL; - - do - { - HTML_Pos = HTML.FindStringEnd("href='"); - char * tmpLink = HTML.CopyString("'\""); - if (tmpLink) - { - char *fileext = strrchr(tmpLink, '.'); - if (fileext) - { - if (strcasecmp(fileext, ".dol") == 0) - { - char revtxt[80]; - char *filename = strrchr(tmpLink, '/') + 2; - u8 n = 0; - for (n = 0; n < strlen(filename) - 2; n++) - revtxt[n] = filename[n]; - revtxt[n] = 0; - int fileRev = atoi(revtxt); - - if (fileRev > revnumber) - { - revnumber = fileRev; - } - } - } - free(tmpLink); - } - } while (HTML_Pos != NULL); - - return revnumber; -} - -static bool CheckNewWiiTDBVersion(const char *url) -{ - u64 Version = 0; - - char * HEAD_Responde = HEAD_Request(url); - if(!HEAD_Responde) - return false; - - char * version_ptr = strstr(HEAD_Responde, "X-WiiTDB-Timestamp: "); - if(version_ptr) - { - version_ptr += strlen("X-WiiTDB-Timestamp: "); - Version = strtoull(version_ptr, NULL, 10); - } - - free(HEAD_Responde); - - std::string Title; - std::string Filepath = Settings.titlestxt_path; - if(Settings.titlestxt_path[Filepath.size()-1] != '/') - Filepath += '/'; - Filepath += "wiitdb.xml"; - - WiiTDB XML_DB; - - if(!XML_DB.OpenFile((Filepath.c_str()))) - return true; //! If no file exists we need the file - - u64 ExistingVersion = XML_DB.GetWiiTDBVersion(); - - gprintf("Existing WiiTDB Version: %llu Online WiiTDB Version: %llu\n", ExistingVersion, Version); - - return (ExistingVersion != Version); -} - -int UpdateWiiTDB() -{ - if(CheckNewWiiTDBVersion(WiiTDB_URL) == false) - { - gprintf("Not updating WiiTDB: Version is the same\n"); - return -1; - } - - gprintf("Updating WiiTDB...\n"); - - string ZipPath = Settings.titlestxt_path; - if(Settings.titlestxt_path[ZipPath.size()-1] != '/') - ZipPath += '/'; - - ZipPath += "wiitdb.zip"; - - int filesize = DownloadFileToPath(WiiTDB_URL, ZipPath.c_str(), false); - - if(filesize <= 0) - return -1; - - ZipFile zFile(ZipPath.c_str()); - - bool result = zFile.ExtractAll(Settings.titlestxt_path); - - //! The zip file is not needed anymore so we can remove it - remove(ZipPath.c_str()); - - //! Reload all titles because the file changed now. - GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); - - return (result ? filesize : -1); -} - -static void UpdateIconPng() -{ - char iconpath[200]; - struct block file = downloadfile("http://www.techjawa.com/usbloadergx/icon.png"); - if (file.data != NULL) - { - snprintf(iconpath, sizeof(iconpath), "%sicon.png", Settings.update_path); - FILE * pfile = fopen(iconpath, "wb"); - if(pfile) - { - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - } - free(file.data); - } -} - -static void UpdateMetaXml() -{ - char xmlpath[200]; - struct block file = downloadfile("http://www.techjawa.com/usbloadergx/meta.file"); - if (file.data != NULL) - { - snprintf(xmlpath, sizeof(xmlpath), "%smeta.xml", Settings.update_path); - FILE *pfile = fopen(xmlpath, "wb"); - if(pfile) - { - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - } - free(file.data); - } -} - -static int ApplicationDownload(int newrev) -{ - bool update_error = false; - char tmppath[250]; - - #ifdef FULLCHANNEL - const char * DownloadURL = "http://www.techjawa.com/usbloadergx/ULNR.wad"; - snprintf(tmppath, sizeof(tmppath), "%s/ULNR.wad", Settings.BootDevice); - #else - char realpath[250]; - snprintf(realpath, sizeof(realpath), "%sboot.dol", Settings.update_path); - const char * DownloadURL = "http://www.techjawa.com/usbloadergx/boot.dol"; - snprintf(tmppath, sizeof(tmppath), "%sboot.tmp", Settings.update_path); - #endif - - int update_choice = WindowPrompt(fmt("Rev%i %s.", newrev, tr( "available" )), tr( "How do you want to update?" ), tr( "Update DOL" ), tr( "Update All" ), tr( "Cancel" )); - if (update_choice == 0) - return 0; - - int ret = DownloadFileToPath(DownloadURL, tmppath, false); - if(ret < 1024*1024) - { - remove(tmppath); - WindowPrompt(tr("Failed updating"), tr("Error while downloding file"), tr( "OK" )); - if(update_choice == 1) - return -1; - - update_error = true; - } - else - { - #ifdef FULLCHANNEL - FILE * wadFile = fopen(realpath, "rb"); - if(!wadFile) - { - update_error = true; - WindowPrompt(tr("Failed updating"), tr("Error opening downloaded file"), tr( "OK" )); - return -1; - } - - int error = Wad_Install( wadFile ); - if(error) - { - update_error = true; - ShowError(tr( "The wad installation failed with error %i" ), error); - } - else - WindowPrompt(tr( "Success" ), tr( "The wad file was installed" ), tr( "OK" )); - - RemoveFile(realpath); - #else - gprintf("%s\n%s\n", realpath, tmppath); - RemoveFile(realpath); - if(!RenameFile(tmppath, realpath)) - update_error = true; - #endif - } - - if (update_choice == 2) - { - UpdateIconPng(); - UpdateMetaXml(); - UpdateWiiTDB(); - DownloadAllLanguageFiles(); - } - - if(update_error) - { - ShowError(tr( "Error while updating USB Loader GX." )); - return -1; - } - - if (update_choice > 0) - { - WindowPrompt(tr( "Restarting..." ), tr( "Successfully Updated thanks to www.techjawa.com" ), 0, 0, 0, 0, 150); - #ifdef FULLCHANNEL - ExitApp(); - WII_Initialize(); - WII_LaunchTitle(TITLE_ID( 0x00010001, 0x554c4e52 )); - #else - BootHomebrew(realpath); - #endif - } - - return 0; -} - -int UpdateApp() -{ - if (!IsNetworkInit() && !NetworkInitPrompt()) - { - WindowPrompt(tr("Error !"), tr("Could not initialize network!"), tr("OK")); - return -1; - } - - if (!CreateSubfolder(Settings.update_path)) - { - WindowPrompt(tr("Error !"), tr("Can't create directory"), tr("OK")); - return -1; - } - - int choice = WindowPrompt(tr( "What do you want to update?" ), 0, "USB Loader GX", tr( "WiiTDB Files" ), tr( "Language File" ), tr( "Cancel" )); - if(choice == 0) - return -1; - - if(choice == 1) - { - int newrev = CheckUpdate(); - if (newrev < 0) - { - WindowPrompt(tr( "No new updates." ), 0, tr( "OK" )); - return 0; - } - - return ApplicationDownload(newrev); - } - else if (choice == 2) - { - if(UpdateWiiTDB() < 0) - { - WindowPrompt(fmt("%s", tr( "WiiTDB is up to date." )), 0, tr("OK")); - return 1; - } - else - { - WindowPrompt(tr( "Successfully Updated" ), 0, tr( "OK" )); - return 1; - } - } - else if (choice == 3) - { - if(UpdateLanguageFiles() > 0) - WindowPrompt(tr( "Successfully Updated" ), 0, tr( "OK" )); - } - - return 1; -} diff --git a/source/network/update.h b/source/network/update.h deleted file mode 100644 index 9caec60a..00000000 --- a/source/network/update.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * update.h - * - * Update operations - * for Wii-Xplorer 2009 - ***************************************************************************/ -#ifndef _UPDATEOPS_H_ -#define _UPDATEOPS_H_ - -int CheckForBetaUpdate(); -int UpdateWiiTDB(); -int UpdateApp(); - -#endif diff --git a/source/patches/codehandler.h b/source/patches/codehandler.h deleted file mode 100644 index 7cf81098..00000000 --- a/source/patches/codehandler.h +++ /dev/null @@ -1,247 +0,0 @@ -/* - This file was autogenerated by raw2c. - Visit http://www.devkitpro.org - */ - -const unsigned char codehandler[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x27, 0x74, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x21, 0xff, 0x58, 0x90, 0x01, 0x00, - 0x08, 0x7c, 0x08, 0x02, 0xa6, 0x90, 0x01, 0x00, 0xac, 0x7c, 0x00, 0x00, 0x26, 0x90, 0x01, 0x00, 0x0c, 0x7c, - 0x09, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x10, 0x7c, 0x01, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x14, 0xbc, 0x61, 0x00, - 0x18, 0x7f, 0x20, 0x00, 0xa6, 0x63, 0x3a, 0x20, 0x00, 0x73, 0x5a, 0xf9, 0xff, 0x7f, 0x40, 0x01, 0x24, 0xd8, - 0x41, 0x00, 0x98, 0xd8, 0x61, 0x00, 0xa0, 0x3f, 0xe0, 0x80, 0x00, 0x3e, 0x80, 0xcc, 0x00, 0xa3, 0x94, 0x40, - 0x10, 0x63, 0x95, 0x00, 0xff, 0xb2, 0xb4, 0x40, 0x10, 0x48, 0x00, 0x06, 0x55, 0x3a, 0xa0, 0x00, 0x00, 0x3a, - 0xc0, 0x00, 0x19, 0x3a, 0xe0, 0x00, 0xd0, 0x3f, 0x00, 0xcd, 0x00, 0x63, 0xf2, 0x27, 0x74, 0x80, 0x01, 0x00, - 0xac, 0x90, 0x12, 0x00, 0x04, 0x92, 0xb8, 0x64, 0x3c, 0x48, 0x00, 0x04, 0x2d, 0x41, 0x82, 0x05, 0xa4, 0x2c, - 0x1d, 0x00, 0x04, 0x40, 0x80, 0x00, 0x10, 0x2c, 0x1d, 0x00, 0x01, 0x41, 0x80, 0x05, 0x94, 0x48, 0x00, 0x03, - 0x4c, 0x41, 0x82, 0x04, 0xf0, 0x2c, 0x1d, 0x00, 0x06, 0x41, 0x82, 0x00, 0x8c, 0x2c, 0x1d, 0x00, 0x07, 0x41, - 0x82, 0x03, 0x30, 0x2c, 0x1d, 0x00, 0x08, 0x41, 0x82, 0x05, 0x80, 0x2c, 0x1d, 0x00, 0x09, 0x41, 0x82, 0x00, - 0xa0, 0x2c, 0x1d, 0x00, 0x10, 0x41, 0x82, 0x00, 0x98, 0x2c, 0x1d, 0x00, 0x2f, 0x41, 0x82, 0x00, 0x70, 0x2c, - 0x1d, 0x00, 0x30, 0x41, 0x82, 0x00, 0x78, 0x2c, 0x1d, 0x00, 0x38, 0x41, 0x82, 0x05, 0x28, 0x2c, 0x1d, 0x00, - 0x40, 0x41, 0x82, 0x03, 0x40, 0x2c, 0x1d, 0x00, 0x41, 0x41, 0x82, 0x03, 0x58, 0x2c, 0x1d, 0x00, 0x44, 0x41, - 0x82, 0x00, 0x68, 0x2c, 0x1d, 0x00, 0x50, 0x41, 0x82, 0x00, 0x20, 0x2c, 0x1d, 0x00, 0x60, 0x41, 0x82, 0x00, - 0x24, 0x2c, 0x1d, 0x00, 0x89, 0x41, 0x82, 0x00, 0x50, 0x2c, 0x1d, 0x00, 0x99, 0x41, 0x82, 0x05, 0x0c, 0x48, - 0x00, 0x05, 0x10, 0x80, 0x72, 0x00, 0x00, 0x48, 0x00, 0x04, 0x29, 0x48, 0x00, 0x05, 0x04, 0x48, 0x00, 0x05, - 0x89, 0x48, 0x00, 0x04, 0xfc, 0x38, 0x80, 0x00, 0x01, 0x90, 0x92, 0x00, 0x00, 0x48, 0x00, 0x04, 0xf0, 0x48, - 0x00, 0x04, 0x09, 0x3a, 0x00, 0x00, 0xa0, 0x63, 0xec, 0x27, 0x98, 0x48, 0x00, 0x03, 0x14, 0x38, 0x60, 0x01, - 0x20, 0x63, 0xec, 0x27, 0x98, 0x48, 0x00, 0x03, 0xc9, 0x48, 0x00, 0x04, 0xd0, 0x2f, 0x1d, 0x00, 0x10, 0x2e, - 0x9d, 0x00, 0x44, 0x63, 0xe4, 0x1a, 0xb4, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x03, 0x00, 0x48, 0x00, 0x05, - 0x09, 0x38, 0x63, 0x0a, 0x00, 0x48, 0x00, 0x05, 0x01, 0x38, 0x63, 0x06, 0x00, 0x48, 0x00, 0x04, 0xf9, 0x63, - 0xec, 0x27, 0x88, 0x92, 0xac, 0x00, 0x00, 0x92, 0xac, 0x00, 0x04, 0x92, 0xac, 0x00, 0x08, 0x63, 0xe4, 0x27, - 0x98, 0x81, 0x24, 0x00, 0x18, 0x80, 0x72, 0x00, 0x00, 0x2c, 0x03, 0x00, 0x02, 0x40, 0x82, 0x00, 0x0c, 0x41, - 0x96, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x20, 0x38, 0x60, 0x00, 0x00, 0x90, 0x6c, 0x00, 0x0c, 0x40, 0x82, 0x00, - 0x14, 0x40, 0x96, 0x00, 0x10, 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x02, 0x14, 0x55, - 0x29, 0x05, 0xa8, 0x91, 0x24, 0x00, 0x18, 0x41, 0x96, 0x04, 0x54, 0x41, 0x9a, 0x00, 0x08, 0x39, 0x8c, 0x00, - 0x04, 0x38, 0x60, 0x00, 0x04, 0x48, 0x00, 0x03, 0x09, 0x40, 0x99, 0x00, 0x10, 0x39, 0x8c, 0x00, 0x04, 0x38, - 0x60, 0x00, 0x04, 0x48, 0x00, 0x02, 0xf9, 0x63, 0xe4, 0x27, 0x88, 0x80, 0x64, 0x00, 0x00, 0x80, 0x84, 0x00, - 0x04, 0x7c, 0x72, 0xfb, 0xa6, 0x7c, 0x95, 0xfb, 0xa6, 0x48, 0x00, 0x04, 0x1c, 0x7c, 0x32, 0x43, 0xa6, 0x7c, - 0x3a, 0x02, 0xa6, 0x7c, 0x73, 0x43, 0xa6, 0x7c, 0x7b, 0x02, 0xa6, 0x54, 0x63, 0x05, 0xa8, 0x90, 0x60, 0x27, - 0xb0, 0x54, 0x63, 0x06, 0x1e, 0x60, 0x63, 0x20, 0x00, 0x7c, 0x7b, 0x03, 0xa6, 0x3c, 0x60, 0x80, 0x00, 0x60, - 0x63, 0x1a, 0xe8, 0x7c, 0x7a, 0x03, 0xa6, 0x4c, 0x00, 0x00, 0x64, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x27, - 0x98, 0x90, 0x23, 0x00, 0x14, 0x7c, 0x61, 0x1b, 0x78, 0x7c, 0x73, 0x42, 0xa6, 0xbc, 0x41, 0x00, 0x24, 0x7c, - 0x24, 0x0b, 0x78, 0x7c, 0x32, 0x42, 0xa6, 0x90, 0x04, 0x00, 0x1c, 0x90, 0x24, 0x00, 0x20, 0x7c, 0x68, 0x02, - 0xa6, 0x90, 0x64, 0x00, 0x9c, 0x7c, 0x60, 0x00, 0x26, 0x90, 0x64, 0x00, 0x00, 0x7c, 0x61, 0x02, 0xa6, 0x90, - 0x64, 0x00, 0x04, 0x7c, 0x69, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x08, 0x7c, 0x72, 0x02, 0xa6, 0x90, 0x64, 0x00, - 0x0c, 0x7c, 0x73, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x10, 0x39, 0x20, 0x00, 0x00, 0x7d, 0x32, 0xfb, 0xa6, 0x7d, - 0x35, 0xfb, 0xa6, 0x3c, 0xa0, 0x80, 0x00, 0x60, 0xa5, 0x1b, 0x70, 0x3f, 0xe0, 0xd0, 0x04, 0x63, 0xff, 0x00, - 0xa0, 0x93, 0xe5, 0x00, 0x00, 0x7c, 0x00, 0x28, 0x6c, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x2f, 0xac, 0x4c, - 0x00, 0x01, 0x2c, 0xd0, 0x04, 0x00, 0xa0, 0x3b, 0xff, 0x00, 0x04, 0x3f, 0xff, 0x00, 0x20, 0x57, 0xf0, 0x01, - 0x4b, 0x41, 0x82, 0xff, 0xdc, 0x3f, 0xe0, 0x80, 0x00, 0x63, 0xe5, 0x27, 0x88, 0x82, 0x05, 0x00, 0x00, 0x82, - 0x25, 0x00, 0x04, 0x82, 0x65, 0x00, 0x0c, 0x2c, 0x13, 0x00, 0x00, 0x41, 0x82, 0x00, 0x74, 0x2c, 0x13, 0x00, - 0x02, 0x40, 0x82, 0x00, 0x18, 0x81, 0x24, 0x00, 0x14, 0x39, 0x33, 0x00, 0x03, 0x91, 0x25, 0x00, 0x00, 0x91, - 0x25, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x6c, 0x7c, 0x10, 0x98, 0x00, 0x41, 0x82, 0x00, 0x38, 0x7c, 0x11, 0x98, - 0x00, 0x41, 0x82, 0x00, 0x30, 0x7d, 0x30, 0x8a, 0x14, 0x91, 0x25, 0x00, 0x0c, 0x82, 0x05, 0x00, 0x08, 0x2c, - 0x10, 0x00, 0x00, 0x41, 0x82, 0x00, 0x48, 0x80, 0x64, 0x00, 0x10, 0x7c, 0x10, 0x18, 0x00, 0x40, 0x82, 0x00, - 0x10, 0x3a, 0x00, 0x00, 0x00, 0x92, 0x05, 0x00, 0x08, 0x48, 0x00, 0x00, 0x30, 0x3a, 0x20, 0x00, 0x00, 0x92, - 0x25, 0x00, 0x0c, 0x81, 0x24, 0x00, 0x18, 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x00, - 0x30, 0x7e, 0x12, 0xfb, 0xa6, 0x7e, 0x35, 0xfb, 0xa6, 0x39, 0x20, 0x00, 0x01, 0x91, 0x25, 0x00, 0x0c, 0x48, - 0x00, 0x00, 0x1c, 0x38, 0xa0, 0x00, 0x02, 0x63, 0xe4, 0x27, 0x74, 0x90, 0xa4, 0x00, 0x00, 0x38, 0x60, 0x00, - 0x11, 0x48, 0x00, 0x01, 0xb9, 0x4b, 0xff, 0xfc, 0x71, 0x7c, 0x20, 0x00, 0xa6, 0x54, 0x21, 0x07, 0xfa, 0x54, - 0x21, 0x04, 0x5e, 0x7c, 0x20, 0x01, 0x24, 0x63, 0xe1, 0x27, 0x98, 0x80, 0x61, 0x00, 0x00, 0x7c, 0x6f, 0xf1, - 0x20, 0x80, 0x61, 0x00, 0x14, 0x7c, 0x7a, 0x03, 0xa6, 0x80, 0x61, 0x00, 0x18, 0x7c, 0x7b, 0x03, 0xa6, 0x80, - 0x61, 0x00, 0x9c, 0x7c, 0x68, 0x03, 0xa6, 0xb8, 0x41, 0x00, 0x24, 0x80, 0x01, 0x00, 0x1c, 0x80, 0x21, 0x00, - 0x20, 0x4c, 0x00, 0x00, 0x64, 0x92, 0xb2, 0x00, 0x00, 0x48, 0x00, 0x02, 0x54, 0x2e, 0x9d, 0x00, 0x02, 0x38, - 0x60, 0x00, 0x08, 0x63, 0xec, 0x27, 0x7c, 0x48, 0x00, 0x00, 0xfd, 0x80, 0xac, 0x00, 0x00, 0x80, 0x6c, 0x00, - 0x04, 0x98, 0x65, 0x00, 0x00, 0x41, 0x94, 0x00, 0x10, 0xb0, 0x65, 0x00, 0x00, 0x41, 0x96, 0x00, 0x08, 0x90, - 0x65, 0x00, 0x00, 0x7c, 0x00, 0x28, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x2f, 0xac, 0x4c, 0x00, 0x01, - 0x2c, 0x48, 0x00, 0x02, 0x08, 0x48, 0x00, 0x01, 0x21, 0x38, 0x60, 0x00, 0x04, 0x63, 0xec, 0x27, 0x7c, 0x48, - 0x00, 0x00, 0xbd, 0x82, 0x0c, 0x00, 0x00, 0x3d, 0x80, 0x80, 0x00, 0x61, 0x8c, 0x28, 0xb8, 0x48, 0x00, 0x00, - 0x1c, 0x48, 0x00, 0x01, 0x01, 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x27, 0x7c, 0x48, 0x00, 0x00, 0x9d, 0x82, - 0x0c, 0x00, 0x04, 0x81, 0x8c, 0x00, 0x00, 0x63, 0xfb, 0x27, 0x84, 0x3a, 0x20, 0x0f, 0x80, 0x48, 0x00, 0x02, - 0x39, 0x41, 0x82, 0x00, 0x20, 0x7e, 0x23, 0x8b, 0x78, 0x48, 0x00, 0x00, 0x7d, 0x48, 0x00, 0x00, 0xd1, 0x41, - 0x82, 0xff, 0xfc, 0x7d, 0x8c, 0x72, 0x14, 0x35, 0x6b, 0xff, 0xff, 0x41, 0x81, 0xff, 0xe8, 0x80, 0x7b, 0x00, - 0x00, 0x2c, 0x03, 0x00, 0x00, 0x41, 0x82, 0x00, 0x08, 0x48, 0x00, 0x00, 0x59, 0x7c, 0x00, 0x60, 0xac, 0x7c, - 0x00, 0x04, 0xac, 0x7c, 0x00, 0x67, 0xac, 0x4c, 0x00, 0x01, 0x2c, 0x48, 0x00, 0x01, 0x80, 0x7f, 0xc8, 0x02, - 0xa6, 0x3c, 0x60, 0xa0, 0x00, 0x48, 0x00, 0x00, 0x15, 0x76, 0x03, 0x08, 0x00, 0x56, 0x1d, 0x86, 0x3e, 0x7f, - 0xc8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x92, 0xf8, 0x68, 0x14, 0x90, 0x78, 0x68, 0x24, 0x92, 0xd8, 0x68, - 0x20, 0x80, 0xb8, 0x68, 0x20, 0x70, 0xa5, 0x00, 0x01, 0x40, 0x82, 0xff, 0xf8, 0x82, 0x18, 0x68, 0x24, 0x90, - 0xb8, 0x68, 0x14, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x48, 0x02, 0xa6, 0x7c, 0x69, 0x03, 0xa6, 0x39, 0xc0, 0x00, - 0x00, 0x48, 0x00, 0x00, 0x79, 0x48, 0x00, 0x00, 0x75, 0x4b, 0xff, 0xff, 0xad, 0x41, 0x82, 0xff, 0xf4, 0x7f, - 0xae, 0x61, 0xae, 0x39, 0xce, 0x00, 0x01, 0x42, 0x00, 0xff, 0xe8, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, - 0x20, 0x7d, 0x48, 0x02, 0xa6, 0x7c, 0x69, 0x03, 0xa6, 0x39, 0xc0, 0x00, 0x00, 0x7c, 0x6c, 0x70, 0xae, 0x48, - 0x00, 0x00, 0x1d, 0x41, 0x82, 0xff, 0xf8, 0x39, 0xce, 0x00, 0x01, 0x42, 0x00, 0xff, 0xf0, 0x7d, 0x48, 0x03, - 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x38, 0x60, 0x00, 0xaa, 0x7f, 0xc8, 0x02, 0xa6, 0x54, 0x63, 0xa0, 0x16, 0x64, - 0x63, 0xb0, 0x00, 0x3a, 0xc0, 0x00, 0x19, 0x3a, 0xe0, 0x00, 0xd0, 0x3f, 0x00, 0xcd, 0x00, 0x4b, 0xff, 0xff, - 0x69, 0x56, 0x03, 0x37, 0xff, 0x7f, 0xc8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x7f, 0xc8, 0x02, 0xa6, 0x3c, - 0x60, 0xd0, 0x00, 0x4b, 0xff, 0xff, 0x51, 0x56, 0x03, 0x37, 0xff, 0x41, 0x82, 0xff, 0xf4, 0x7f, 0xc8, 0x03, - 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x4b, 0xff, 0xff, 0xb9, 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x27, 0x7c, 0x4b, - 0xff, 0xff, 0x55, 0x80, 0xac, 0x00, 0x04, 0x81, 0x8c, 0x00, 0x00, 0x63, 0xfb, 0x27, 0x84, 0x62, 0xb1, 0xf8, - 0x00, 0x7e, 0x0c, 0x28, 0x50, 0x48, 0x00, 0x00, 0xed, 0x41, 0x81, 0x00, 0x10, 0x82, 0x3b, 0x00, 0x00, 0x2c, - 0x11, 0x00, 0x00, 0x41, 0x82, 0x00, 0x68, 0x7e, 0x23, 0x8b, 0x78, 0x4b, 0xff, 0xff, 0x55, 0x4b, 0xff, 0xff, - 0xa5, 0x4b, 0xff, 0xff, 0xa1, 0x4b, 0xff, 0xfe, 0xd9, 0x41, 0x82, 0xff, 0xf4, 0x2c, 0x1d, 0x00, 0xcc, 0x41, - 0x82, 0x00, 0x48, 0x2c, 0x1d, 0x00, 0xbb, 0x41, 0x82, 0xff, 0xdc, 0x2c, 0x1d, 0x00, 0xaa, 0x40, 0x82, 0xff, - 0xdc, 0x7d, 0x8c, 0x72, 0x14, 0x35, 0x6b, 0xff, 0xff, 0x41, 0x80, 0x00, 0x2c, 0x4b, 0xff, 0xff, 0xb4, 0x7e, - 0xb5, 0xfb, 0xa6, 0x7e, 0xb2, 0xfb, 0xa6, 0x63, 0xe4, 0x27, 0x98, 0x81, 0x24, 0x00, 0x18, 0x55, 0x29, 0x05, - 0xa8, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x00, 0x0c, 0x38, 0x60, 0x00, 0x80, 0x4b, 0xff, 0xff, 0x25, 0x80, - 0x92, 0x00, 0x00, 0x2c, 0x04, 0x00, 0x00, 0x40, 0x82, 0xfa, 0x50, 0xb3, 0x94, 0x40, 0x10, 0xc8, 0x41, 0x00, - 0x98, 0xc8, 0x61, 0x00, 0xa0, 0x7f, 0x20, 0x00, 0xa6, 0x80, 0x01, 0x00, 0xac, 0x7c, 0x08, 0x03, 0xa6, 0x80, - 0x01, 0x00, 0x0c, 0x7c, 0x0f, 0xf1, 0x20, 0x80, 0x01, 0x00, 0x10, 0x7c, 0x09, 0x03, 0xa6, 0x80, 0x01, 0x00, - 0x14, 0x7c, 0x01, 0x03, 0xa6, 0xb8, 0x61, 0x00, 0x18, 0x80, 0x01, 0x00, 0x08, 0x38, 0x21, 0x00, 0xa8, 0x4c, - 0x00, 0x01, 0x2c, 0x4e, 0x80, 0x00, 0x20, 0x7e, 0x23, 0x20, 0x50, 0x3c, 0xa0, 0x48, 0x00, 0x52, 0x25, 0x01, - 0xba, 0x90, 0xa3, 0x00, 0x00, 0x7c, 0x00, 0x18, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x1f, 0xac, 0x4c, - 0x00, 0x01, 0x2c, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x70, 0x8b, 0xd7, 0x7d, 0x4b, 0x89, 0xd6, 0x7d, 0x4a, 0x80, - 0x50, 0x91, 0x5b, 0x00, 0x00, 0x4e, 0x80, 0x00, 0x20, 0x7f, 0xa8, 0x02, 0xa6, 0x3d, 0xe0, 0x80, 0x00, 0x61, - 0xef, 0x28, 0xb8, 0x63, 0xe7, 0x18, 0x08, 0x3c, 0xc0, 0x80, 0x00, 0x7c, 0xd0, 0x33, 0x78, 0x39, 0x00, 0x00, - 0x00, 0x3c, 0x60, 0x00, 0xd0, 0x60, 0x63, 0xc0, 0xde, 0x80, 0x8f, 0x00, 0x00, 0x7c, 0x03, 0x20, 0x00, 0x40, - 0x82, 0x00, 0x18, 0x80, 0x8f, 0x00, 0x04, 0x7c, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x0c, 0x39, 0xef, 0x00, - 0x08, 0x48, 0x00, 0x00, 0x0c, 0x7f, 0xa8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x80, 0x6f, 0x00, 0x00, 0x80, - 0x8f, 0x00, 0x04, 0x39, 0xef, 0x00, 0x08, 0x71, 0x09, 0x00, 0x01, 0x2f, 0x89, 0x00, 0x00, 0x39, 0x20, 0x00, - 0x00, 0x54, 0x6a, 0x1f, 0x7e, 0x54, 0x65, 0x3f, 0x7e, 0x74, 0x6b, 0x10, 0x00, 0x54, 0x63, 0x01, 0xfe, 0x40, - 0x82, 0x00, 0x0c, 0x54, 0xcc, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x08, 0x7e, 0x0c, 0x83, 0x78, 0x2e, 0x05, 0x00, - 0x00, 0x2c, 0x0a, 0x00, 0x01, 0x41, 0xa0, 0x00, 0x2c, 0x41, 0xa2, 0x00, 0xe4, 0x2c, 0x0a, 0x00, 0x03, 0x41, - 0xa0, 0x01, 0xac, 0x41, 0x82, 0x02, 0x50, 0x2c, 0x0a, 0x00, 0x05, 0x41, 0x80, 0x02, 0xd4, 0x41, 0xa2, 0x04, - 0xe0, 0x2c, 0x0a, 0x00, 0x07, 0x41, 0xa0, 0x05, 0x0c, 0x48, 0x00, 0x05, 0xf0, 0x7d, 0x8c, 0x1a, 0x14, 0x2c, - 0x05, 0x00, 0x03, 0x41, 0x82, 0x00, 0x48, 0x41, 0x81, 0x00, 0x60, 0x40, 0xbe, 0xff, 0x84, 0x2e, 0x05, 0x00, - 0x01, 0x41, 0x91, 0x00, 0x2c, 0x54, 0x8a, 0x84, 0x3e, 0x41, 0x92, 0x00, 0x10, 0x7c, 0x89, 0x61, 0xae, 0x39, - 0x29, 0x00, 0x01, 0x48, 0x00, 0x00, 0x0c, 0x7c, 0x89, 0x63, 0x2e, 0x39, 0x29, 0x00, 0x02, 0x35, 0x4a, 0xff, - 0xff, 0x40, 0xa0, 0xff, 0xe4, 0x4b, 0xff, 0xff, 0x54, 0x55, 0x8c, 0x00, 0x3a, 0x90, 0x8c, 0x00, 0x00, 0x4b, - 0xff, 0xff, 0x48, 0x7c, 0x89, 0x23, 0x78, 0x40, 0x9e, 0x04, 0xc8, 0x35, 0x29, 0xff, 0xff, 0x41, 0x80, 0x04, - 0xc0, 0x7c, 0xa9, 0x78, 0xae, 0x7c, 0xa9, 0x61, 0xae, 0x4b, 0xff, 0xff, 0xf0, 0x39, 0xef, 0x00, 0x08, 0x40, - 0xbe, 0xff, 0x24, 0x80, 0xaf, 0xff, 0xf8, 0x81, 0x6f, 0xff, 0xfc, 0x54, 0xb1, 0x04, 0x3e, 0x54, 0xaa, 0x85, - 0x3e, 0x54, 0xa5, 0x27, 0x3e, 0x2e, 0x85, 0x00, 0x01, 0x41, 0x96, 0x00, 0x10, 0x41, 0xb5, 0x00, 0x14, 0x7c, - 0x89, 0x61, 0xae, 0x48, 0x00, 0x00, 0x10, 0x7c, 0x89, 0x63, 0x2e, 0x48, 0x00, 0x00, 0x08, 0x7c, 0x89, 0x61, - 0x2e, 0x7c, 0x84, 0x5a, 0x14, 0x7d, 0x29, 0x8a, 0x14, 0x35, 0x4a, 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4, 0x4b, - 0xff, 0xfe, 0xdc, 0x54, 0x69, 0x07, 0xff, 0x41, 0x82, 0x00, 0x10, 0x55, 0x08, 0xf8, 0x7e, 0x71, 0x09, 0x00, - 0x01, 0x2f, 0x89, 0x00, 0x00, 0x2e, 0x85, 0x00, 0x04, 0x2d, 0x8a, 0x00, 0x05, 0x51, 0x08, 0x08, 0x3c, 0x40, - 0x9e, 0x00, 0x78, 0x41, 0x8d, 0x04, 0xb8, 0x7d, 0x8c, 0x1a, 0x14, 0x41, 0x8c, 0x00, 0x0c, 0x41, 0x94, 0x00, - 0x30, 0x48, 0x00, 0x00, 0x1c, 0x40, 0x94, 0x00, 0x10, 0x55, 0x8c, 0x00, 0x3a, 0x81, 0x6c, 0x00, 0x00, 0x48, - 0x00, 0x00, 0x1c, 0x55, 0x8c, 0x00, 0x3c, 0xa1, 0x6c, 0x00, 0x00, 0x7c, 0x89, 0x20, 0xf8, 0x55, 0x29, 0x84, - 0x3e, 0x7d, 0x6b, 0x48, 0x38, 0x54, 0x84, 0x04, 0x3e, 0x7f, 0x0b, 0x20, 0x40, 0x70, 0xa9, 0x00, 0x03, 0x41, - 0x82, 0x00, 0x18, 0x2c, 0x09, 0x00, 0x02, 0x41, 0x82, 0x00, 0x18, 0x41, 0x81, 0x00, 0x1c, 0x40, 0x9a, 0x00, - 0x20, 0x48, 0x00, 0x00, 0x18, 0x41, 0x9a, 0x00, 0x18, 0x48, 0x00, 0x00, 0x10, 0x41, 0x99, 0x00, 0x10, 0x48, - 0x00, 0x00, 0x08, 0x41, 0x98, 0x00, 0x08, 0x61, 0x08, 0x00, 0x01, 0x40, 0x8e, 0xfe, 0x40, 0x41, 0x94, 0xfe, - 0x3c, 0x81, 0x6f, 0xff, 0xf8, 0x40, 0x9e, 0x00, 0x20, 0x70, 0x6c, 0x00, 0x08, 0x41, 0x82, 0x00, 0x0c, 0x71, - 0x0c, 0x00, 0x01, 0x41, 0x82, 0x00, 0x10, 0x39, 0x8b, 0x00, 0x10, 0x51, 0x8b, 0x03, 0x36, 0x48, 0x00, 0x00, - 0x08, 0x55, 0x6b, 0x07, 0x16, 0x91, 0x6f, 0xff, 0xf8, 0x4b, 0xff, 0xfe, 0x0c, 0x40, 0xbe, 0xfe, 0x08, 0x54, - 0x69, 0x16, 0xba, 0x54, 0x6e, 0x87, 0xfe, 0x2d, 0x8e, 0x00, 0x00, 0x2e, 0x05, 0x00, 0x04, 0x70, 0xae, 0x00, - 0x03, 0x2e, 0x8e, 0x00, 0x02, 0x41, 0x94, 0x00, 0x14, 0x41, 0x96, 0x00, 0x50, 0x7c, 0x64, 0x07, 0x34, 0x7c, - 0x84, 0x7a, 0x14, 0x48, 0x00, 0x00, 0x68, 0x54, 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, 0x48, - 0x2e, 0x7c, 0x84, 0x4a, 0x14, 0x41, 0x8e, 0x00, 0x08, 0x7c, 0x8c, 0x22, 0x14, 0x2e, 0x8e, 0x00, 0x01, 0x41, - 0x96, 0x00, 0x08, 0x80, 0x84, 0x00, 0x00, 0x54, 0x63, 0x67, 0xff, 0x41, 0x82, 0x00, 0x3c, 0x40, 0x90, 0x00, - 0x0c, 0x7c, 0x84, 0x32, 0x14, 0x48, 0x00, 0x00, 0x30, 0x7c, 0x84, 0x82, 0x14, 0x48, 0x00, 0x00, 0x28, 0x54, - 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, 0x48, 0x2e, 0x7c, 0x84, 0x4a, 0x14, 0x40, 0x90, 0x00, - 0x0c, 0x7c, 0xcc, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x80, 0x7e, 0x0c, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x78, 0x40, - 0x90, 0x00, 0x0c, 0x7c, 0x86, 0x23, 0x78, 0x4b, 0xff, 0xfd, 0x6c, 0x7c, 0x90, 0x23, 0x78, 0x4b, 0xff, 0xfd, - 0x64, 0x54, 0x89, 0x1e, 0x78, 0x39, 0x29, 0x00, 0x40, 0x2c, 0x05, 0x00, 0x02, 0x41, 0x80, 0x00, 0x48, 0x54, - 0x6b, 0x50, 0x03, 0x41, 0x82, 0x00, 0x14, 0x41, 0x81, 0x00, 0x08, 0x48, 0x00, 0x00, 0x10, 0x41, 0xbe, 0xfd, - 0x40, 0x48, 0x00, 0x00, 0x08, 0x40, 0xbe, 0xfd, 0x38, 0x2c, 0x05, 0x00, 0x03, 0x41, 0x81, 0x00, 0x10, 0x41, - 0xa2, 0x00, 0x10, 0x7d, 0xe7, 0x48, 0x2e, 0x4b, 0xff, 0xfd, 0x24, 0x7d, 0xe7, 0x49, 0x2e, 0x7c, 0x64, 0x07, - 0x34, 0x54, 0x84, 0x1a, 0x78, 0x7d, 0xef, 0x22, 0x14, 0x4b, 0xff, 0xfd, 0x10, 0x40, 0xbe, 0xfd, 0x0c, 0x7c, - 0xa7, 0x4a, 0x14, 0x40, 0x92, 0x00, 0x14, 0x54, 0x64, 0x04, 0x3e, 0x91, 0xe5, 0x00, 0x00, 0x90, 0x85, 0x00, - 0x04, 0x4b, 0xff, 0xfc, 0xf4, 0x81, 0x25, 0x00, 0x04, 0x2c, 0x09, 0x00, 0x00, 0x41, 0xa2, 0xfc, 0xe8, 0x39, - 0x29, 0xff, 0xff, 0x91, 0x25, 0x00, 0x04, 0x81, 0xe5, 0x00, 0x00, 0x4b, 0xff, 0xfc, 0xd8, 0x40, 0xbe, 0xfc, - 0xd4, 0x54, 0x6b, 0x16, 0xba, 0x7f, 0x47, 0x5a, 0x14, 0x81, 0x3a, 0x00, 0x00, 0x54, 0x6e, 0x67, 0xbe, 0x41, - 0x92, 0x00, 0x84, 0x2e, 0x05, 0x00, 0x05, 0x40, 0x90, 0x01, 0x74, 0x2e, 0x05, 0x00, 0x03, 0x40, 0x90, 0x00, - 0x90, 0x2e, 0x05, 0x00, 0x01, 0x54, 0x65, 0x87, 0xff, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x8c, 0x22, 0x14, 0x2f, - 0x0e, 0x00, 0x01, 0x40, 0x92, 0x00, 0x24, 0x41, 0xb9, 0x00, 0x18, 0x41, 0x9a, 0x00, 0x0c, 0x88, 0x84, 0x00, - 0x00, 0x48, 0x00, 0x00, 0xf8, 0xa0, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xf0, 0x80, 0x84, 0x00, 0x00, 0x48, - 0x00, 0x00, 0xe8, 0x54, 0x73, 0xe5, 0x3e, 0x41, 0xb9, 0x00, 0x20, 0x41, 0x9a, 0x00, 0x10, 0x99, 0x24, 0x00, - 0x00, 0x38, 0x84, 0x00, 0x01, 0x48, 0x00, 0x00, 0x18, 0xb1, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x02, 0x48, - 0x00, 0x00, 0x0c, 0x91, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x04, 0x36, 0x73, 0xff, 0xff, 0x40, 0x80, 0xff, - 0xd4, 0x4b, 0xff, 0xfc, 0x40, 0x54, 0x65, 0x87, 0xff, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x84, 0x62, 0x14, 0x71, - 0xc5, 0x00, 0x01, 0x41, 0x82, 0x00, 0x9c, 0x7c, 0x84, 0x4a, 0x14, 0x48, 0x00, 0x00, 0x94, 0x54, 0x6a, 0x87, - 0xbe, 0x54, 0x8e, 0x16, 0xba, 0x7e, 0x67, 0x72, 0x14, 0x40, 0x92, 0x00, 0x08, 0x3a, 0x6f, 0xff, 0xfc, 0x80, - 0x9a, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x71, 0x4b, 0x00, 0x01, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x9a, 0x23, - 0x78, 0x71, 0x4b, 0x00, 0x02, 0x41, 0x82, 0x00, 0x10, 0x7d, 0x33, 0x4b, 0x78, 0x40, 0xb2, 0x00, 0x08, 0x7e, - 0x6c, 0x9a, 0x14, 0x54, 0x65, 0x67, 0x3f, 0x2c, 0x05, 0x00, 0x09, 0x40, 0x80, 0x00, 0x54, 0x48, 0x00, 0x00, - 0x79, 0x7c, 0x89, 0x22, 0x14, 0x48, 0x00, 0x00, 0x40, 0x7c, 0x89, 0x21, 0xd6, 0x48, 0x00, 0x00, 0x38, 0x7d, - 0x24, 0x23, 0x78, 0x48, 0x00, 0x00, 0x30, 0x7d, 0x24, 0x20, 0x38, 0x48, 0x00, 0x00, 0x28, 0x7d, 0x24, 0x22, - 0x78, 0x48, 0x00, 0x00, 0x20, 0x7d, 0x24, 0x20, 0x30, 0x48, 0x00, 0x00, 0x18, 0x7d, 0x24, 0x24, 0x30, 0x48, - 0x00, 0x00, 0x10, 0x5d, 0x24, 0x20, 0x3e, 0x48, 0x00, 0x00, 0x08, 0x7d, 0x24, 0x26, 0x30, 0x90, 0x9a, 0x00, - 0x00, 0x4b, 0xff, 0xfb, 0x8c, 0x2c, 0x05, 0x00, 0x0a, 0x41, 0x81, 0xfb, 0x84, 0xc0, 0x5a, 0x00, 0x00, 0xc0, - 0x73, 0x00, 0x00, 0x41, 0x82, 0x00, 0x0c, 0xec, 0x43, 0x10, 0x2a, 0x48, 0x00, 0x00, 0x08, 0xec, 0x43, 0x00, - 0xb2, 0xd0, 0x5a, 0x00, 0x00, 0x4b, 0xff, 0xfb, 0x64, 0x7d, 0x48, 0x02, 0xa6, 0x54, 0xa5, 0x1e, 0x78, 0x7d, - 0x4a, 0x2a, 0x14, 0x80, 0x9a, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, - 0x20, 0x40, 0xbe, 0xfb, 0x44, 0x54, 0x69, 0xc0, 0x3e, 0x7d, 0x8e, 0x63, 0x78, 0x48, 0x00, 0x00, 0x35, 0x41, - 0x92, 0x00, 0x0c, 0x7e, 0x31, 0x22, 0x14, 0x48, 0x00, 0x00, 0x08, 0x7d, 0x29, 0x22, 0x14, 0x54, 0x64, 0xc4, - 0x3f, 0x38, 0xa0, 0x00, 0x00, 0x41, 0x82, 0xfb, 0x1c, 0x7d, 0x45, 0x88, 0xae, 0x7d, 0x45, 0x49, 0xae, 0x38, - 0xa5, 0x00, 0x01, 0x7c, 0x05, 0x20, 0x00, 0x4b, 0xff, 0xff, 0xec, 0x2e, 0x8a, 0x00, 0x04, 0x55, 0x31, 0x36, - 0xba, 0x2c, 0x11, 0x00, 0x3c, 0x7e, 0x27, 0x88, 0x2e, 0x40, 0x82, 0x00, 0x08, 0x7d, 0xd1, 0x73, 0x78, 0x41, - 0x96, 0x00, 0x08, 0xa2, 0x31, 0x00, 0x00, 0x55, 0x29, 0x56, 0xba, 0x2c, 0x09, 0x00, 0x3c, 0x7d, 0x27, 0x48, - 0x2e, 0x40, 0x82, 0x00, 0x08, 0x7d, 0xc9, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, 0xa1, 0x29, 0x00, 0x00, 0x4e, - 0x80, 0x00, 0x20, 0x2c, 0x05, 0x00, 0x04, 0x40, 0x80, 0x00, 0x28, 0x7c, 0x89, 0x23, 0x78, 0x7d, 0xc3, 0x62, - 0x14, 0x55, 0xce, 0x00, 0x3c, 0x4b, 0xff, 0xff, 0xad, 0x7c, 0x84, 0x20, 0xf8, 0x54, 0x84, 0x04, 0x3e, 0x7d, - 0x2b, 0x20, 0x38, 0x7e, 0x24, 0x20, 0x38, 0x4b, 0xff, 0xfb, 0xc4, 0x54, 0x6b, 0xe4, 0x3e, 0x4b, 0xff, 0xfb, - 0xbc, 0x7c, 0x9a, 0x23, 0x78, 0x54, 0x84, 0x18, 0x38, 0x40, 0x92, 0x00, 0x20, 0x40, 0x9e, 0x00, 0x0c, 0x7d, - 0xe8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x21, 0x7d, 0xe4, 0x7a, 0x14, 0x39, 0xef, 0x00, 0x07, 0x55, 0xef, 0x00, - 0x38, 0x4b, 0xff, 0xfa, 0x6c, 0x2e, 0x05, 0x00, 0x03, 0x41, 0x91, 0x00, 0x5c, 0x3c, 0xa0, 0x48, 0x00, 0x7d, - 0x83, 0x62, 0x14, 0x55, 0x8c, 0x00, 0x3a, 0x40, 0x92, 0x00, 0x20, 0x40, 0xbe, 0xfa, 0x50, 0x57, 0x44, 0x00, - 0x3a, 0x7c, 0x8c, 0x20, 0x50, 0x50, 0x85, 0x01, 0xba, 0x50, 0x65, 0x07, 0xfe, 0x90, 0xac, 0x00, 0x00, 0x4b, - 0xff, 0xfa, 0x38, 0x40, 0xbe, 0xff, 0xbc, 0x7d, 0x2c, 0x78, 0x50, 0x51, 0x25, 0x01, 0xba, 0x90, 0xac, 0x00, - 0x00, 0x39, 0x8c, 0x00, 0x04, 0x7d, 0x6f, 0x22, 0x14, 0x39, 0x6b, 0xff, 0xfc, 0x7d, 0x2b, 0x60, 0x50, 0x51, - 0x25, 0x01, 0xba, 0x90, 0xab, 0x00, 0x00, 0x4b, 0xff, 0xff, 0x94, 0x2e, 0x05, 0x00, 0x06, 0x41, 0x92, 0x00, - 0x28, 0x4b, 0xff, 0xfb, 0x28, 0x55, 0x8c, 0x84, 0x3e, 0x57, 0x44, 0x84, 0x3e, 0x57, 0x5a, 0x04, 0x3e, 0x7c, - 0x0c, 0x20, 0x00, 0x41, 0x80, 0xfb, 0xa8, 0x7c, 0x0c, 0xd0, 0x00, 0x40, 0x80, 0xfb, 0xa0, 0x4b, 0xff, 0xf9, - 0xe0, 0x57, 0x45, 0xff, 0xfe, 0x68, 0xa5, 0x00, 0x01, 0x71, 0x03, 0x00, 0x01, 0x7c, 0x05, 0x18, 0x00, 0x41, - 0x82, 0x00, 0x1c, 0x51, 0x1a, 0x0f, 0xbc, 0x6b, 0x5a, 0x00, 0x02, 0x57, 0x45, 0xff, 0xff, 0x41, 0x82, 0x00, - 0x08, 0x6b, 0x5a, 0x00, 0x01, 0x93, 0x4f, 0xff, 0xfc, 0x53, 0x48, 0x07, 0xfe, 0x4b, 0xff, 0xf9, 0xac, 0x2c, - 0x0b, 0x00, 0x00, 0x41, 0x82, 0x01, 0x38, 0x2c, 0x05, 0x00, 0x01, 0x41, 0x82, 0x00, 0x18, 0x2c, 0x05, 0x00, - 0x02, 0x41, 0x82, 0x00, 0x14, 0x2c, 0x05, 0x00, 0x03, 0x41, 0x82, 0x00, 0x70, 0x4b, 0xff, 0xf9, 0x80, 0x54, - 0xcc, 0x00, 0x0c, 0x54, 0x97, 0x46, 0x3e, 0x54, 0x98, 0xc4, 0x3e, 0x54, 0x84, 0x06, 0x3e, 0x40, 0x9e, 0x00, - 0xfc, 0x56, 0xf9, 0x06, 0x31, 0x7d, 0x9a, 0x63, 0x78, 0x7f, 0x43, 0xd2, 0x14, 0x57, 0x5a, 0x00, 0x3a, 0x41, - 0x82, 0x00, 0x18, 0x7e, 0xf7, 0x07, 0x74, 0x7e, 0xf7, 0x00, 0xd0, 0x1f, 0x37, 0x00, 0x02, 0x3b, 0x39, 0x00, - 0x04, 0x7f, 0x59, 0xd0, 0x50, 0x2c, 0x17, 0x00, 0x00, 0x41, 0x82, 0x00, 0x1c, 0x3b, 0x20, 0x00, 0x00, 0x7e, - 0xe9, 0x03, 0xa6, 0xa3, 0x7a, 0x00, 0x04, 0x7f, 0x79, 0xca, 0x78, 0x3b, 0x5a, 0x00, 0x02, 0x42, 0x00, 0xff, - 0xf4, 0x7c, 0x18, 0xc8, 0x00, 0x40, 0x82, 0x00, 0xac, 0x4b, 0xff, 0xfe, 0x90, 0x51, 0x08, 0x08, 0x3c, 0x40, - 0x9e, 0x00, 0x9c, 0x54, 0x77, 0xb0, 0x03, 0x41, 0x81, 0x00, 0x88, 0x41, 0x80, 0x00, 0x8c, 0x54, 0x7e, 0x06, - 0x3e, 0x1f, 0xde, 0x00, 0x02, 0x54, 0x97, 0x00, 0x1e, 0x6e, 0xf8, 0x80, 0x00, 0x2c, 0x18, 0x00, 0x00, 0x40, - 0x82, 0x00, 0x08, 0x62, 0xf7, 0x30, 0x00, 0x54, 0x98, 0x80, 0x1e, 0x1f, 0x3e, 0x00, 0x04, 0x7f, 0x19, 0xc0, - 0x50, 0x3b, 0x20, 0x00, 0x00, 0x1f, 0x59, 0x00, 0x04, 0x7f, 0x6f, 0xd0, 0x2e, 0x7f, 0x57, 0xd0, 0x2e, 0x3b, - 0x39, 0x00, 0x01, 0x7c, 0x17, 0xc0, 0x40, 0x41, 0x81, 0x00, 0x34, 0x7c, 0x19, 0xf0, 0x00, 0x41, 0x81, 0x00, - 0x14, 0x7c, 0x1a, 0xd8, 0x00, 0x41, 0x82, 0xff, 0xdc, 0x3a, 0xf7, 0x00, 0x04, 0x4b, 0xff, 0xff, 0xd0, 0x80, - 0x6f, 0xff, 0xf8, 0x60, 0x63, 0x03, 0x00, 0x90, 0x6f, 0xff, 0xf8, 0x92, 0xef, 0xff, 0xfc, 0x7e, 0xf0, 0xbb, - 0x78, 0x48, 0x00, 0x00, 0x1c, 0x80, 0x6f, 0xff, 0xf8, 0x60, 0x63, 0x01, 0x00, 0x90, 0x6f, 0xff, 0xf8, 0x61, - 0x08, 0x00, 0x01, 0x48, 0x00, 0x00, 0x08, 0x7c, 0x90, 0x23, 0x78, 0x54, 0x64, 0x06, 0x3e, 0x1c, 0x84, 0x00, - 0x08, 0x7d, 0xe4, 0x7a, 0x14, 0x4b, 0xff, 0xf8, 0x70, 0x40, 0x92, 0x00, 0x0c, 0x39, 0x00, 0x00, 0x00, 0x48, - 0x00, 0x00, 0x14, 0x54, 0x69, 0x06, 0xff, 0x54, 0x65, 0x67, 0xfe, 0x7d, 0x08, 0x4c, 0x30, 0x55, 0x17, 0xff, - 0xff, 0x40, 0x82, 0x00, 0x08, 0x7d, 0x08, 0x2a, 0x78, 0x54, 0x85, 0x00, 0x1f, 0x41, 0x82, 0x00, 0x08, 0x7c, - 0xa6, 0x2b, 0x78, 0x54, 0x85, 0x80, 0x1f, 0x41, 0x82, 0x00, 0x08, 0x7c, 0xb0, 0x2b, 0x78, 0x4b, 0xff, 0xf8, - 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -}; -const int codehandler_size = sizeof(codehandler); diff --git a/source/patches/codehandleronly.h b/source/patches/codehandleronly.h deleted file mode 100644 index 62d12278..00000000 --- a/source/patches/codehandleronly.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - This file was autogenerated by raw2c. - Visit http://www.devkitpro.org - */ - -const unsigned char codehandleronly[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x21, 0x60, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x21, 0xff, 0x58, 0x90, 0x01, 0x00, - 0x08, 0x7c, 0x08, 0x02, 0xa6, 0x90, 0x01, 0x00, 0xac, 0x7c, 0x00, 0x00, 0x26, 0x90, 0x01, 0x00, 0x0c, 0x7c, - 0x09, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x10, 0x7c, 0x01, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x14, 0xbc, 0x61, 0x00, - 0x18, 0x7f, 0x20, 0x00, 0xa6, 0x63, 0x3a, 0x20, 0x00, 0x73, 0x5a, 0xf9, 0xff, 0x7f, 0x40, 0x01, 0x24, 0xd8, - 0x41, 0x00, 0x98, 0xd8, 0x61, 0x00, 0xa0, 0x3f, 0xe0, 0x80, 0x00, 0x3e, 0x80, 0xcc, 0x00, 0xa3, 0x94, 0x40, - 0x10, 0x63, 0x95, 0x00, 0xff, 0xb2, 0xb4, 0x40, 0x10, 0x7f, 0xa8, 0x02, 0xa6, 0x3d, 0xe0, 0x80, 0x00, 0x61, - 0xef, 0x22, 0xa8, 0x63, 0xe7, 0x18, 0x08, 0x3c, 0xc0, 0x80, 0x00, 0x7c, 0xd0, 0x33, 0x78, 0x39, 0x00, 0x00, - 0x00, 0x3c, 0x60, 0x00, 0xd0, 0x60, 0x63, 0xc0, 0xde, 0x80, 0x8f, 0x00, 0x00, 0x7c, 0x03, 0x20, 0x00, 0x40, - 0x82, 0x00, 0x18, 0x80, 0x8f, 0x00, 0x04, 0x7c, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x0c, 0x39, 0xef, 0x00, - 0x08, 0x48, 0x00, 0x00, 0x4c, 0x7f, 0xa8, 0x03, 0xa6, 0xb3, 0x94, 0x40, 0x10, 0xc8, 0x41, 0x00, 0x98, 0xc8, - 0x61, 0x00, 0xa0, 0x7f, 0x20, 0x00, 0xa6, 0x80, 0x01, 0x00, 0xac, 0x7c, 0x08, 0x03, 0xa6, 0x80, 0x01, 0x00, - 0x0c, 0x7c, 0x0f, 0xf1, 0x20, 0x80, 0x01, 0x00, 0x10, 0x7c, 0x09, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x14, 0x7c, - 0x01, 0x03, 0xa6, 0xb8, 0x61, 0x00, 0x18, 0x80, 0x01, 0x00, 0x08, 0x38, 0x21, 0x00, 0xa8, 0x4c, 0x00, 0x01, - 0x2c, 0x4e, 0x80, 0x00, 0x20, 0x80, 0x6f, 0x00, 0x00, 0x80, 0x8f, 0x00, 0x04, 0x39, 0xef, 0x00, 0x08, 0x71, - 0x09, 0x00, 0x01, 0x2f, 0x89, 0x00, 0x00, 0x39, 0x20, 0x00, 0x00, 0x54, 0x6a, 0x1f, 0x7e, 0x54, 0x65, 0x3f, - 0x7e, 0x74, 0x6b, 0x10, 0x00, 0x54, 0x63, 0x01, 0xfe, 0x40, 0x82, 0x00, 0x0c, 0x54, 0xcc, 0x00, 0x0c, 0x48, - 0x00, 0x00, 0x08, 0x7e, 0x0c, 0x83, 0x78, 0x2e, 0x05, 0x00, 0x00, 0x2c, 0x0a, 0x00, 0x01, 0x41, 0xa0, 0x00, - 0x2c, 0x41, 0xa2, 0x00, 0xe4, 0x2c, 0x0a, 0x00, 0x03, 0x41, 0xa0, 0x01, 0xac, 0x41, 0x82, 0x02, 0x50, 0x2c, - 0x0a, 0x00, 0x05, 0x41, 0x80, 0x02, 0xd4, 0x41, 0xa2, 0x04, 0xe0, 0x2c, 0x0a, 0x00, 0x07, 0x41, 0xa0, 0x05, - 0x0c, 0x48, 0x00, 0x05, 0xf0, 0x7d, 0x8c, 0x1a, 0x14, 0x2c, 0x05, 0x00, 0x03, 0x41, 0x82, 0x00, 0x48, 0x41, - 0x81, 0x00, 0x60, 0x40, 0xbe, 0xff, 0x84, 0x2e, 0x05, 0x00, 0x01, 0x41, 0x91, 0x00, 0x2c, 0x54, 0x8a, 0x84, - 0x3e, 0x41, 0x92, 0x00, 0x10, 0x7c, 0x89, 0x61, 0xae, 0x39, 0x29, 0x00, 0x01, 0x48, 0x00, 0x00, 0x0c, 0x7c, - 0x89, 0x63, 0x2e, 0x39, 0x29, 0x00, 0x02, 0x35, 0x4a, 0xff, 0xff, 0x40, 0xa0, 0xff, 0xe4, 0x4b, 0xff, 0xff, - 0x54, 0x55, 0x8c, 0x00, 0x3a, 0x90, 0x8c, 0x00, 0x00, 0x4b, 0xff, 0xff, 0x48, 0x7c, 0x89, 0x23, 0x78, 0x40, - 0x9e, 0x04, 0xc8, 0x35, 0x29, 0xff, 0xff, 0x41, 0x80, 0x04, 0xc0, 0x7c, 0xa9, 0x78, 0xae, 0x7c, 0xa9, 0x61, - 0xae, 0x4b, 0xff, 0xff, 0xf0, 0x39, 0xef, 0x00, 0x08, 0x40, 0xbe, 0xff, 0x24, 0x80, 0xaf, 0xff, 0xf8, 0x81, - 0x6f, 0xff, 0xfc, 0x54, 0xb1, 0x04, 0x3e, 0x54, 0xaa, 0x85, 0x3e, 0x54, 0xa5, 0x27, 0x3e, 0x2e, 0x85, 0x00, - 0x01, 0x41, 0x96, 0x00, 0x10, 0x41, 0xb5, 0x00, 0x14, 0x7c, 0x89, 0x61, 0xae, 0x48, 0x00, 0x00, 0x10, 0x7c, - 0x89, 0x63, 0x2e, 0x48, 0x00, 0x00, 0x08, 0x7c, 0x89, 0x61, 0x2e, 0x7c, 0x84, 0x5a, 0x14, 0x7d, 0x29, 0x8a, - 0x14, 0x35, 0x4a, 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4, 0x4b, 0xff, 0xfe, 0xdc, 0x54, 0x69, 0x07, 0xff, 0x41, - 0x82, 0x00, 0x10, 0x55, 0x08, 0xf8, 0x7e, 0x71, 0x09, 0x00, 0x01, 0x2f, 0x89, 0x00, 0x00, 0x2e, 0x85, 0x00, - 0x04, 0x2d, 0x8a, 0x00, 0x05, 0x51, 0x08, 0x08, 0x3c, 0x40, 0x9e, 0x00, 0x78, 0x41, 0x8d, 0x04, 0xb8, 0x7d, - 0x8c, 0x1a, 0x14, 0x41, 0x8c, 0x00, 0x0c, 0x41, 0x94, 0x00, 0x30, 0x48, 0x00, 0x00, 0x1c, 0x40, 0x94, 0x00, - 0x10, 0x55, 0x8c, 0x00, 0x3a, 0x81, 0x6c, 0x00, 0x00, 0x48, 0x00, 0x00, 0x1c, 0x55, 0x8c, 0x00, 0x3c, 0xa1, - 0x6c, 0x00, 0x00, 0x7c, 0x89, 0x20, 0xf8, 0x55, 0x29, 0x84, 0x3e, 0x7d, 0x6b, 0x48, 0x38, 0x54, 0x84, 0x04, - 0x3e, 0x7f, 0x0b, 0x20, 0x40, 0x70, 0xa9, 0x00, 0x03, 0x41, 0x82, 0x00, 0x18, 0x2c, 0x09, 0x00, 0x02, 0x41, - 0x82, 0x00, 0x18, 0x41, 0x81, 0x00, 0x1c, 0x40, 0x9a, 0x00, 0x20, 0x48, 0x00, 0x00, 0x18, 0x41, 0x9a, 0x00, - 0x18, 0x48, 0x00, 0x00, 0x10, 0x41, 0x99, 0x00, 0x10, 0x48, 0x00, 0x00, 0x08, 0x41, 0x98, 0x00, 0x08, 0x61, - 0x08, 0x00, 0x01, 0x40, 0x8e, 0xfe, 0x40, 0x41, 0x94, 0xfe, 0x3c, 0x81, 0x6f, 0xff, 0xf8, 0x40, 0x9e, 0x00, - 0x20, 0x70, 0x6c, 0x00, 0x08, 0x41, 0x82, 0x00, 0x0c, 0x71, 0x0c, 0x00, 0x01, 0x41, 0x82, 0x00, 0x10, 0x39, - 0x8b, 0x00, 0x10, 0x51, 0x8b, 0x03, 0x36, 0x48, 0x00, 0x00, 0x08, 0x55, 0x6b, 0x07, 0x16, 0x91, 0x6f, 0xff, - 0xf8, 0x4b, 0xff, 0xfe, 0x0c, 0x40, 0xbe, 0xfe, 0x08, 0x54, 0x69, 0x16, 0xba, 0x54, 0x6e, 0x87, 0xfe, 0x2d, - 0x8e, 0x00, 0x00, 0x2e, 0x05, 0x00, 0x04, 0x70, 0xae, 0x00, 0x03, 0x2e, 0x8e, 0x00, 0x02, 0x41, 0x94, 0x00, - 0x14, 0x41, 0x96, 0x00, 0x50, 0x7c, 0x64, 0x07, 0x34, 0x7c, 0x84, 0x7a, 0x14, 0x48, 0x00, 0x00, 0x68, 0x54, - 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, 0x48, 0x2e, 0x7c, 0x84, 0x4a, 0x14, 0x41, 0x8e, 0x00, - 0x08, 0x7c, 0x8c, 0x22, 0x14, 0x2e, 0x8e, 0x00, 0x01, 0x41, 0x96, 0x00, 0x08, 0x80, 0x84, 0x00, 0x00, 0x54, - 0x63, 0x67, 0xff, 0x41, 0x82, 0x00, 0x3c, 0x40, 0x90, 0x00, 0x0c, 0x7c, 0x84, 0x32, 0x14, 0x48, 0x00, 0x00, - 0x30, 0x7c, 0x84, 0x82, 0x14, 0x48, 0x00, 0x00, 0x28, 0x54, 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, - 0x27, 0x48, 0x2e, 0x7c, 0x84, 0x4a, 0x14, 0x40, 0x90, 0x00, 0x0c, 0x7c, 0xcc, 0x21, 0x2e, 0x4b, 0xff, 0xfd, - 0x80, 0x7e, 0x0c, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x78, 0x40, 0x90, 0x00, 0x0c, 0x7c, 0x86, 0x23, 0x78, 0x4b, - 0xff, 0xfd, 0x6c, 0x7c, 0x90, 0x23, 0x78, 0x4b, 0xff, 0xfd, 0x64, 0x54, 0x89, 0x1e, 0x78, 0x39, 0x29, 0x00, - 0x40, 0x2c, 0x05, 0x00, 0x02, 0x41, 0x80, 0x00, 0x48, 0x54, 0x6b, 0x50, 0x03, 0x41, 0x82, 0x00, 0x14, 0x41, - 0x81, 0x00, 0x08, 0x48, 0x00, 0x00, 0x10, 0x41, 0xbe, 0xfd, 0x40, 0x48, 0x00, 0x00, 0x08, 0x40, 0xbe, 0xfd, - 0x38, 0x2c, 0x05, 0x00, 0x03, 0x41, 0x81, 0x00, 0x10, 0x41, 0xa2, 0x00, 0x10, 0x7d, 0xe7, 0x48, 0x2e, 0x4b, - 0xff, 0xfd, 0x24, 0x7d, 0xe7, 0x49, 0x2e, 0x7c, 0x64, 0x07, 0x34, 0x54, 0x84, 0x1a, 0x78, 0x7d, 0xef, 0x22, - 0x14, 0x4b, 0xff, 0xfd, 0x10, 0x40, 0xbe, 0xfd, 0x0c, 0x7c, 0xa7, 0x4a, 0x14, 0x40, 0x92, 0x00, 0x14, 0x54, - 0x64, 0x04, 0x3e, 0x91, 0xe5, 0x00, 0x00, 0x90, 0x85, 0x00, 0x04, 0x4b, 0xff, 0xfc, 0xf4, 0x81, 0x25, 0x00, - 0x04, 0x2c, 0x09, 0x00, 0x00, 0x41, 0xa2, 0xfc, 0xe8, 0x39, 0x29, 0xff, 0xff, 0x91, 0x25, 0x00, 0x04, 0x81, - 0xe5, 0x00, 0x00, 0x4b, 0xff, 0xfc, 0xd8, 0x40, 0xbe, 0xfc, 0xd4, 0x54, 0x6b, 0x16, 0xba, 0x7f, 0x47, 0x5a, - 0x14, 0x81, 0x3a, 0x00, 0x00, 0x54, 0x6e, 0x67, 0xbe, 0x41, 0x92, 0x00, 0x84, 0x2e, 0x05, 0x00, 0x05, 0x40, - 0x90, 0x01, 0x74, 0x2e, 0x05, 0x00, 0x03, 0x40, 0x90, 0x00, 0x90, 0x2e, 0x05, 0x00, 0x01, 0x54, 0x65, 0x87, - 0xff, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x8c, 0x22, 0x14, 0x2f, 0x0e, 0x00, 0x01, 0x40, 0x92, 0x00, 0x24, 0x41, - 0xb9, 0x00, 0x18, 0x41, 0x9a, 0x00, 0x0c, 0x88, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xf8, 0xa0, 0x84, 0x00, - 0x00, 0x48, 0x00, 0x00, 0xf0, 0x80, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xe8, 0x54, 0x73, 0xe5, 0x3e, 0x41, - 0xb9, 0x00, 0x20, 0x41, 0x9a, 0x00, 0x10, 0x99, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x01, 0x48, 0x00, 0x00, - 0x18, 0xb1, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x02, 0x48, 0x00, 0x00, 0x0c, 0x91, 0x24, 0x00, 0x00, 0x38, - 0x84, 0x00, 0x04, 0x36, 0x73, 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4, 0x4b, 0xff, 0xfc, 0x40, 0x54, 0x65, 0x87, - 0xff, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x84, 0x62, 0x14, 0x71, 0xc5, 0x00, 0x01, 0x41, 0x82, 0x00, 0x9c, 0x7c, - 0x84, 0x4a, 0x14, 0x48, 0x00, 0x00, 0x94, 0x54, 0x6a, 0x87, 0xbe, 0x54, 0x8e, 0x16, 0xba, 0x7e, 0x67, 0x72, - 0x14, 0x40, 0x92, 0x00, 0x08, 0x3a, 0x6f, 0xff, 0xfc, 0x80, 0x9a, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x71, - 0x4b, 0x00, 0x01, 0x41, 0x82, 0x00, 0x08, 0x7c, 0x9a, 0x23, 0x78, 0x71, 0x4b, 0x00, 0x02, 0x41, 0x82, 0x00, - 0x10, 0x7d, 0x33, 0x4b, 0x78, 0x40, 0xb2, 0x00, 0x08, 0x7e, 0x6c, 0x9a, 0x14, 0x54, 0x65, 0x67, 0x3f, 0x2c, - 0x05, 0x00, 0x09, 0x40, 0x80, 0x00, 0x54, 0x48, 0x00, 0x00, 0x79, 0x7c, 0x89, 0x22, 0x14, 0x48, 0x00, 0x00, - 0x40, 0x7c, 0x89, 0x21, 0xd6, 0x48, 0x00, 0x00, 0x38, 0x7d, 0x24, 0x23, 0x78, 0x48, 0x00, 0x00, 0x30, 0x7d, - 0x24, 0x20, 0x38, 0x48, 0x00, 0x00, 0x28, 0x7d, 0x24, 0x22, 0x78, 0x48, 0x00, 0x00, 0x20, 0x7d, 0x24, 0x20, - 0x30, 0x48, 0x00, 0x00, 0x18, 0x7d, 0x24, 0x24, 0x30, 0x48, 0x00, 0x00, 0x10, 0x5d, 0x24, 0x20, 0x3e, 0x48, - 0x00, 0x00, 0x08, 0x7d, 0x24, 0x26, 0x30, 0x90, 0x9a, 0x00, 0x00, 0x4b, 0xff, 0xfb, 0x8c, 0x2c, 0x05, 0x00, - 0x0a, 0x41, 0x81, 0xfb, 0x84, 0xc0, 0x5a, 0x00, 0x00, 0xc0, 0x73, 0x00, 0x00, 0x41, 0x82, 0x00, 0x0c, 0xec, - 0x43, 0x10, 0x2a, 0x48, 0x00, 0x00, 0x08, 0xec, 0x43, 0x00, 0xb2, 0xd0, 0x5a, 0x00, 0x00, 0x4b, 0xff, 0xfb, - 0x64, 0x7d, 0x48, 0x02, 0xa6, 0x54, 0xa5, 0x1e, 0x78, 0x7d, 0x4a, 0x2a, 0x14, 0x80, 0x9a, 0x00, 0x00, 0x81, - 0x33, 0x00, 0x00, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x40, 0xbe, 0xfb, 0x44, 0x54, 0x69, 0xc0, - 0x3e, 0x7d, 0x8e, 0x63, 0x78, 0x48, 0x00, 0x00, 0x35, 0x41, 0x92, 0x00, 0x0c, 0x7e, 0x31, 0x22, 0x14, 0x48, - 0x00, 0x00, 0x08, 0x7d, 0x29, 0x22, 0x14, 0x54, 0x64, 0xc4, 0x3f, 0x38, 0xa0, 0x00, 0x00, 0x41, 0x82, 0xfb, - 0x1c, 0x7d, 0x45, 0x88, 0xae, 0x7d, 0x45, 0x49, 0xae, 0x38, 0xa5, 0x00, 0x01, 0x7c, 0x05, 0x20, 0x00, 0x4b, - 0xff, 0xff, 0xec, 0x2e, 0x8a, 0x00, 0x04, 0x55, 0x31, 0x36, 0xba, 0x2c, 0x11, 0x00, 0x3c, 0x7e, 0x27, 0x88, - 0x2e, 0x40, 0x82, 0x00, 0x08, 0x7d, 0xd1, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, 0xa2, 0x31, 0x00, 0x00, 0x55, - 0x29, 0x56, 0xba, 0x2c, 0x09, 0x00, 0x3c, 0x7d, 0x27, 0x48, 0x2e, 0x40, 0x82, 0x00, 0x08, 0x7d, 0xc9, 0x73, - 0x78, 0x41, 0x96, 0x00, 0x08, 0xa1, 0x29, 0x00, 0x00, 0x4e, 0x80, 0x00, 0x20, 0x2c, 0x05, 0x00, 0x04, 0x40, - 0x80, 0x00, 0x28, 0x7c, 0x89, 0x23, 0x78, 0x7d, 0xc3, 0x62, 0x14, 0x55, 0xce, 0x00, 0x3c, 0x4b, 0xff, 0xff, - 0xad, 0x7c, 0x84, 0x20, 0xf8, 0x54, 0x84, 0x04, 0x3e, 0x7d, 0x2b, 0x20, 0x38, 0x7e, 0x24, 0x20, 0x38, 0x4b, - 0xff, 0xfb, 0xc4, 0x54, 0x6b, 0xe4, 0x3e, 0x4b, 0xff, 0xfb, 0xbc, 0x7c, 0x9a, 0x23, 0x78, 0x54, 0x84, 0x18, - 0x38, 0x40, 0x92, 0x00, 0x20, 0x40, 0x9e, 0x00, 0x0c, 0x7d, 0xe8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x21, 0x7d, - 0xe4, 0x7a, 0x14, 0x39, 0xef, 0x00, 0x07, 0x55, 0xef, 0x00, 0x38, 0x4b, 0xff, 0xfa, 0x6c, 0x2e, 0x05, 0x00, - 0x03, 0x41, 0x91, 0x00, 0x5c, 0x3c, 0xa0, 0x48, 0x00, 0x7d, 0x83, 0x62, 0x14, 0x55, 0x8c, 0x00, 0x3a, 0x40, - 0x92, 0x00, 0x20, 0x40, 0xbe, 0xfa, 0x50, 0x57, 0x44, 0x00, 0x3a, 0x7c, 0x8c, 0x20, 0x50, 0x50, 0x85, 0x01, - 0xba, 0x50, 0x65, 0x07, 0xfe, 0x90, 0xac, 0x00, 0x00, 0x4b, 0xff, 0xfa, 0x38, 0x40, 0xbe, 0xff, 0xbc, 0x7d, - 0x2c, 0x78, 0x50, 0x51, 0x25, 0x01, 0xba, 0x90, 0xac, 0x00, 0x00, 0x39, 0x8c, 0x00, 0x04, 0x7d, 0x6f, 0x22, - 0x14, 0x39, 0x6b, 0xff, 0xfc, 0x7d, 0x2b, 0x60, 0x50, 0x51, 0x25, 0x01, 0xba, 0x90, 0xab, 0x00, 0x00, 0x4b, - 0xff, 0xff, 0x94, 0x2e, 0x05, 0x00, 0x06, 0x41, 0x92, 0x00, 0x28, 0x4b, 0xff, 0xfb, 0x28, 0x55, 0x8c, 0x84, - 0x3e, 0x57, 0x44, 0x84, 0x3e, 0x57, 0x5a, 0x04, 0x3e, 0x7c, 0x0c, 0x20, 0x00, 0x41, 0x80, 0xfb, 0xa8, 0x7c, - 0x0c, 0xd0, 0x00, 0x40, 0x80, 0xfb, 0xa0, 0x4b, 0xff, 0xf9, 0xe0, 0x57, 0x45, 0xff, 0xfe, 0x68, 0xa5, 0x00, - 0x01, 0x71, 0x03, 0x00, 0x01, 0x7c, 0x05, 0x18, 0x00, 0x41, 0x82, 0x00, 0x1c, 0x51, 0x1a, 0x0f, 0xbc, 0x6b, - 0x5a, 0x00, 0x02, 0x57, 0x45, 0xff, 0xff, 0x41, 0x82, 0x00, 0x08, 0x6b, 0x5a, 0x00, 0x01, 0x93, 0x4f, 0xff, - 0xfc, 0x53, 0x48, 0x07, 0xfe, 0x4b, 0xff, 0xf9, 0xac, 0x2c, 0x0b, 0x00, 0x00, 0x41, 0x82, 0x01, 0x38, 0x2c, - 0x05, 0x00, 0x01, 0x41, 0x82, 0x00, 0x18, 0x2c, 0x05, 0x00, 0x02, 0x41, 0x82, 0x00, 0x14, 0x2c, 0x05, 0x00, - 0x03, 0x41, 0x82, 0x00, 0x70, 0x4b, 0xff, 0xf9, 0x40, 0x54, 0xcc, 0x00, 0x0c, 0x54, 0x97, 0x46, 0x3e, 0x54, - 0x98, 0xc4, 0x3e, 0x54, 0x84, 0x06, 0x3e, 0x40, 0x9e, 0x00, 0xfc, 0x56, 0xf9, 0x06, 0x31, 0x7d, 0x9a, 0x63, - 0x78, 0x7f, 0x43, 0xd2, 0x14, 0x57, 0x5a, 0x00, 0x3a, 0x41, 0x82, 0x00, 0x18, 0x7e, 0xf7, 0x07, 0x74, 0x7e, - 0xf7, 0x00, 0xd0, 0x1f, 0x37, 0x00, 0x02, 0x3b, 0x39, 0x00, 0x04, 0x7f, 0x59, 0xd0, 0x50, 0x2c, 0x17, 0x00, - 0x00, 0x41, 0x82, 0x00, 0x1c, 0x3b, 0x20, 0x00, 0x00, 0x7e, 0xe9, 0x03, 0xa6, 0xa3, 0x7a, 0x00, 0x04, 0x7f, - 0x79, 0xca, 0x78, 0x3b, 0x5a, 0x00, 0x02, 0x42, 0x00, 0xff, 0xf4, 0x7c, 0x18, 0xc8, 0x00, 0x40, 0x82, 0x00, - 0xac, 0x4b, 0xff, 0xfe, 0x90, 0x51, 0x08, 0x08, 0x3c, 0x40, 0x9e, 0x00, 0x9c, 0x54, 0x77, 0xb0, 0x03, 0x41, - 0x81, 0x00, 0x88, 0x41, 0x80, 0x00, 0x8c, 0x54, 0x7e, 0x06, 0x3e, 0x1f, 0xde, 0x00, 0x02, 0x54, 0x97, 0x00, - 0x1e, 0x6e, 0xf8, 0x80, 0x00, 0x2c, 0x18, 0x00, 0x00, 0x40, 0x82, 0x00, 0x08, 0x62, 0xf7, 0x30, 0x00, 0x54, - 0x98, 0x80, 0x1e, 0x1f, 0x3e, 0x00, 0x04, 0x7f, 0x19, 0xc0, 0x50, 0x3b, 0x20, 0x00, 0x00, 0x1f, 0x59, 0x00, - 0x04, 0x7f, 0x6f, 0xd0, 0x2e, 0x7f, 0x57, 0xd0, 0x2e, 0x3b, 0x39, 0x00, 0x01, 0x7c, 0x17, 0xc0, 0x40, 0x41, - 0x81, 0x00, 0x34, 0x7c, 0x19, 0xf0, 0x00, 0x41, 0x81, 0x00, 0x14, 0x7c, 0x1a, 0xd8, 0x00, 0x41, 0x82, 0xff, - 0xdc, 0x3a, 0xf7, 0x00, 0x04, 0x4b, 0xff, 0xff, 0xd0, 0x80, 0x6f, 0xff, 0xf8, 0x60, 0x63, 0x03, 0x00, 0x90, - 0x6f, 0xff, 0xf8, 0x92, 0xef, 0xff, 0xfc, 0x7e, 0xf0, 0xbb, 0x78, 0x48, 0x00, 0x00, 0x1c, 0x80, 0x6f, 0xff, - 0xf8, 0x60, 0x63, 0x01, 0x00, 0x90, 0x6f, 0xff, 0xf8, 0x61, 0x08, 0x00, 0x01, 0x48, 0x00, 0x00, 0x08, 0x7c, - 0x90, 0x23, 0x78, 0x54, 0x64, 0x06, 0x3e, 0x1c, 0x84, 0x00, 0x08, 0x7d, 0xe4, 0x7a, 0x14, 0x4b, 0xff, 0xf8, - 0x70, 0x40, 0x92, 0x00, 0x0c, 0x39, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x14, 0x54, 0x69, 0x06, 0xff, 0x54, - 0x65, 0x67, 0xfe, 0x7d, 0x08, 0x4c, 0x30, 0x55, 0x17, 0xff, 0xff, 0x40, 0x82, 0x00, 0x08, 0x7d, 0x08, 0x2a, - 0x78, 0x54, 0x85, 0x00, 0x1f, 0x41, 0x82, 0x00, 0x08, 0x7c, 0xa6, 0x2b, 0x78, 0x54, 0x85, 0x80, 0x1f, 0x41, - 0x82, 0x00, 0x08, 0x7c, 0xb0, 0x2b, 0x78, 0x4b, 0xff, 0xf8, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00 - -}; -const int codehandleronly_size = sizeof(codehandleronly); diff --git a/source/patches/dolpatcher.c b/source/patches/dolpatcher.c deleted file mode 100644 index f5153ea8..00000000 --- a/source/patches/dolpatcher.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -bool PatchDOL(u8 * Address, int Size, const u8 * SearchPattern, int SearchSize, const u8 * PatchData, int PatchSize) -{ - u8 * Addr = Address; - u8 * Addr_end = Address + Size; - - while (Addr <= Addr_end - SearchSize) - { - if (memcmp(Addr, SearchPattern, SearchSize) == 0) - { - memcpy(Addr, PatchData, PatchSize); - return true; - } - Addr += 4; - } - return false; -} diff --git a/source/patches/dolpatcher.h b/source/patches/dolpatcher.h deleted file mode 100644 index 09eb3190..00000000 --- a/source/patches/dolpatcher.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef DOLPATCHER_C_ -#define DOLPATCHER_C_ - -#include - -bool PatchDOL(u8 * Address, int Size, const u8 * SearchPattern, int SearchSize, const u8 * PatchData, int PatchSize); - -#endif diff --git a/source/patches/dvd_broadway.c b/source/patches/dvd_broadway.c deleted file mode 100644 index 3b629991..00000000 --- a/source/patches/dvd_broadway.c +++ /dev/null @@ -1,639 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dvd_broadway.h" - -#define DI_CMDCTX_CNT 4 - -#define DVD_DISKIDSIZE 0x20 -#define DVD_DRVINFSIZE 0x20 - -#define IOCTL_DI_INQUIRY 0x12 -#define IOCTL_DI_READID 0x70 -#define IOCTL_DI_READ 0x71 -#define IOCTL_DI_WAITCVRCLOSE 0x79 -#define IOCTL_DI_COVER 0x7A -#define IOCTL_DI_RESETNOTIFY 0x7E -#define IOCTL_DI_RESET 0x8A -#define IOCTL_DI_OPENPART 0x8B -#define IOCTL_DI_CLOSEPART 0x8C -#define IOCTL_DI_UNENCREAD 0x8D -#define IOCTL_DI_ENABLE_DVD 0x8E -#define IOCTL_DI_SEEK 0xAB -#define IOCTL_DI_READ_DVDVIDEO 0xD0 -#define IOCTL_DI_STOPLASER 0xD2 -#define IOCTL_DI_OFFSET 0xD9 -#define IOCTL_DI_REQERROR 0xE0 -#define IOCTL_DI_STOPMOTOR 0xE3 -#define IOCTL_DI_SETOFFBASE 0xF0 -#define IOCTL_DI_GETOFFBASE 0xF1 -#define IOCTL_DI_SETCRYPTMODE 0xF2 -#define IOCTL_DI_GETCRYPTMODE 0xF3 -#define IOCTL_DI_SETDVDROMMODE 0xF4 -#define IOCTL_DI_GETDVDROMMODE 0xF5 - -#define _SHIFTL(v, s, w) \ - ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) -#define _SHIFTR(v, s, w) \ - ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) - -struct dicommand -{ - u32 diReg[8]; -}; - -struct dicontext -{ - lwp_node node; - dvdcallbacklow cb; - struct dicommand *cmd; -}; - -static s32 __dvd_fd = -1; -static u32 __dvd_spinupval = 1; -static lwp_queue __di_contextq; -static u32 __dvd_readlength = 0; -static u32 __dvd_cbinprogress = 0; -static u32 __dvd_reqinprogress = 0; -static u32 __dvd_lowinitcalled = 0; -static struct dicommand *__di_commands = NULL; -static struct dicontext __di_contexts[DI_CMDCTX_CNT]; -static u32 __di_regbuffer[0x08] ATTRIBUTE_ALIGN( 32 ); -static u32 __di_regvalcache[0x08] ATTRIBUTE_ALIGN( 32 ); -static u32 __di_lastticketerror[0x08] ATTRIBUTE_ALIGN( 32 ); -static ioctlv __di_iovector[0x08] ATTRIBUTE_ALIGN( 32 ); -static char __di_fs[] ATTRIBUTE_ALIGN( 32 ) = "/dev/di"; - -extern u32 __IPC_ClntInit(); - -static __inline__ lwp_node* __lwp_queue_head(lwp_queue *queue) -{ - return (lwp_node*) queue; -} - -static __inline__ lwp_node* __lwp_queue_tail(lwp_queue *queue) -{ - return (lwp_node*) &queue->perm_null; -} - -static __inline__ void __lwp_queue_init_empty(lwp_queue *queue) -{ - queue->first = __lwp_queue_tail(queue); - queue->perm_null = NULL; - queue->last = __lwp_queue_head(queue); -} - -static struct dicontext* __dvd_getcontext(dvdcallbacklow cb) -{ - struct dicontext *ctx; - - ctx = (struct dicontext*) __lwp_queue_get(&__di_contextq); - if (ctx != NULL) ctx->cb = cb; - - return ctx; -} - -static s32 __dvd_iostransactionCB(s32 result, void *usrdata) -{ - struct dicontext *ctx = (struct dicontext*) usrdata; - - __dvd_reqinprogress = 0; - - if (ctx->cb != NULL) - { - __dvd_cbinprogress = 1; - if (result != 0) __dvd_readlength = 0; - ctx->cb(result); - __dvd_cbinprogress = 0; - } - __lwp_queue_append(&__di_contextq, &ctx->node); - - return 0; -} - -static s32 __dvd_ioscoverregisterCB(s32 result, void *usrdata) -{ - struct dicontext *ctx = (struct dicontext*) usrdata; - - __dvd_reqinprogress = 0; - __di_regvalcache[1] = __di_regbuffer[0]; - - if (ctx->cb != NULL) - { - __dvd_cbinprogress = 1; - ctx->cb(result); - __dvd_cbinprogress = 0; - } - __lwp_queue_append(&__di_contextq, &ctx->node); - - return 0; -} - -static s32 __dvd_ioscovercloseCB(s32 result, void *usrdata) -{ - struct dicontext *ctx = (struct dicontext*) usrdata; - - __dvd_reqinprogress = 0; - - if (ctx->cb != NULL) - { - __dvd_cbinprogress = 1; - ctx->cb(result); - __dvd_cbinprogress = 0; - } - __lwp_queue_append(&__di_contextq, &ctx->node); - - return 0; -} - -s32 bwDVD_LowInit() -{ - s32 i, ret = 0; - u32 ipclo, ipchi; - lwp_queue inactives; - struct dicontext *ctx; - - if (__dvd_lowinitcalled == 0) - { - ret = __IPC_ClntInit(); - if (ret < 0) return ret; - - ipclo = (((u32) IPC_GetBufferLo() + 0x1f) & ~0x1f); - ipchi = (u32) IPC_GetBufferHi(); - if (ipchi >= (ipclo + (sizeof(struct dicommand) * DI_CMDCTX_CNT))) - { - __di_commands = (struct dicommand*) ipclo; - IPC_SetBufferLo((void*) (ipclo + (sizeof(struct dicommand) * DI_CMDCTX_CNT))); - - memset(__di_commands, 0, (sizeof(struct dicommand) * DI_CMDCTX_CNT)); - - i = 0; - __lwp_queue_init_empty(&__di_contextq); - __lwp_queue_initialize(&inactives, __di_contexts, DI_CMDCTX_CNT, sizeof(struct dicontext)); - while ((ctx = (struct dicontext*) __lwp_queue_get(&inactives)) != NULL) - { - ctx->cmd = &__di_commands[i]; - ctx->cb = NULL; - __lwp_queue_append(&__di_contextq, &ctx->node); - - i++; - } - } - - ret = IOS_Open(__di_fs, 0); - if (ret < 0) return ret; - - __dvd_fd = ret; - // __dvd_lowinitcalled = 1; - - // printf("DVD_LowInit(%d)\n",ret); - } - return 0; -} - -s32 bwDVD_LowInquiry(dvddrvinfo *info, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_INQUIRY << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_INQUIRY, cmd->diReg, sizeof(struct dicommand), info, DVD_DRVINFSIZE, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowReadID(dvddiskid *diskID, dvdcallbacklow cb) -{ - s32 ret = 0; - struct dicontext *ctx; - struct dicommand *cmd; - - // printf("DVD_LowReadID()\n"); - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_READID << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_READID, cmd->diReg, sizeof(struct dicommand), diskID, DVD_DISKIDSIZE, - __dvd_iostransactionCB, ctx); - - // printf("DVD_LowReadID(%d)\n",ret); - return ret; -} - -s32 bwDVD_LowRead(void *buf, u32 len, u32 offset, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - if (buf == NULL || ((u32) buf % 32) != 0) return -1; - - __dvd_reqinprogress = 1; - __dvd_readlength = len; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_READ << 24); - cmd->diReg[1] = len; - cmd->diReg[2] = offset; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_READ, cmd->diReg, sizeof(struct dicommand), buf, len, - __dvd_iostransactionCB, ctx); - - return ret; -} - -// never got this function working, probably removed from wii -s32 bwDVD_LowReadVideo(void *buf, u32 len, u32 offset, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - __dvd_readlength = len; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_READ_DVDVIDEO << 24); - cmd->diReg[1] = len; - cmd->diReg[2] = offset; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_READ_DVDVIDEO, cmd->diReg, sizeof(struct dicommand), buf, len, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowStopLaser(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_STOPLASER << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_STOPLASER, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; -} - -// never got this function working, probably removed from wii -s32 bwDVD_EnableVideo(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_ENABLE_DVD << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_ENABLE_DVD, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowSeek(u32 offset, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_SEEK << 24); - cmd->diReg[1] = offset; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_SEEK, cmd->diReg, sizeof(struct dicommand), NULL, 0, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowOffset(u64 offset, dvdcallbacklow cb) -{ - s32 ret; - //u32 *off = (u32*)(void*)(&offset); - union - { - u64 off64; - u32 off32[2]; - } off; - off.off64 = offset; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_OFFSET << 24); - cmd->diReg[1] = 0; - if (off.off32[0]) cmd->diReg[1] = 1; - cmd->diReg[2] = off.off32[1]; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_OFFSET, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowPrepareCoverRegister(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_COVER << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_COVER, cmd->diReg, sizeof(struct dicommand), __di_regbuffer, 0x20, - __dvd_ioscoverregisterCB, ctx); - - return ret; -} - -s32 bwDVD_LowOpenPartition(u32 offset, void *eticket, u32 certin_len, void *certificate_in, void *certificate_out, - dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - if (eticket != NULL && ((u32) eticket % 32) != 0) return -1; - if (certificate_in != NULL && ((u32) certificate_in % 32) != 0) return -1; - if (certificate_out != NULL && ((u32) certificate_out % 32) != 0) return -1; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_OPENPART << 24); - cmd->diReg[1] = offset; - - __di_iovector[0].data = cmd; - __di_iovector[0].len = sizeof(struct dicommand); - - __di_iovector[1].data = eticket; - if (eticket == NULL) - __di_iovector[1].len = 0; - else __di_iovector[1].len = 676; - - __di_iovector[2].data = certificate_in; - if (certificate_in == NULL) - __di_iovector[2].len = 0; - else __di_iovector[2].len = certin_len; - - __di_iovector[3].data = certificate_out; - __di_iovector[3].len = 18916; - __di_iovector[4].data = __di_lastticketerror; - __di_iovector[4].len = 0x20; - ret = IOS_IoctlvAsync(__dvd_fd, IOCTL_DI_OPENPART, 3, 2, __di_iovector, __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowClosePartition(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_CLOSEPART << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_CLOSEPART, cmd->diReg, sizeof(struct dicommand), NULL, 0, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowUnencryptedRead(void *buf, u32 len, u32 offset, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - __dvd_readlength = len; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_UNENCREAD << 24); - cmd->diReg[1] = len; - cmd->diReg[2] = offset; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_UNENCREAD, cmd->diReg, sizeof(struct dicommand), buf, len, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_LowWaitCoverClose(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_WAITCVRCLOSE << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_WAITCVRCLOSE, cmd->diReg, sizeof(struct dicommand), NULL, 0, - __dvd_ioscovercloseCB, ctx); - - return ret; -} - -s32 bwDVD_LowResetNotify() -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - if (__dvd_cbinprogress == 1) return -1; - - ctx = __dvd_getcontext(NULL); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_RESETNOTIFY << 24); - ret = IOS_Ioctl(__dvd_fd, IOCTL_DI_RESETNOTIFY, cmd->diReg, sizeof(struct dicommand), NULL, 0); - - return ret; -} - -s32 bwDVD_LowReset(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - // printf("DVD_LowReset()\n"); - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_RESET << 24); - cmd->diReg[1] = __dvd_spinupval; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_RESET, cmd->diReg, sizeof(struct dicommand), NULL, 0, - __dvd_iostransactionCB, ctx); - - // printf("DVD_LowReset(%d)\n",ret); - return ret; -} - -s32 bwDVD_LowStopMotor(u8 stop1, u8 stop2, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_STOPMOTOR << 24); - cmd->diReg[1] = (stop1 << 24); - cmd->diReg[2] = (stop2 << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_STOPMOTOR, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; - -} - -s32 bwDVD_LowRequestError(dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_REQERROR << 24); - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_REQERROR, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; -} - -s32 bwDVD_SetDecryption(s32 mode, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_SETCRYPTMODE << 24); - cmd->diReg[1] = mode; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_SETCRYPTMODE, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; - -} - -s32 bwDVD_SetOffset(u32 offset, dvdcallbacklow cb) -{ - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx == NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_SETOFFBASE << 24); - cmd->diReg[1] = offset; - ret = IOS_IoctlAsync(__dvd_fd, IOCTL_DI_SETOFFBASE, cmd->diReg, sizeof(struct dicommand), __di_regvalcache, 0x20, - __dvd_iostransactionCB, ctx); - - return ret; - -} diff --git a/source/patches/dvd_broadway.h b/source/patches/dvd_broadway.h deleted file mode 100644 index eaf41e21..00000000 --- a/source/patches/dvd_broadway.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __DVD_BROADWAY_H__ -#define __DVD_BROADWAY_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - - typedef void (*dvdcallbacklow)(s32 result); - - s32 bwDVD_LowInit(); - s32 bwDVD_LowInquiry(dvddrvinfo *info, dvdcallbacklow cb); - s32 bwDVD_LowReadID(dvddiskid *diskID, dvdcallbacklow cb); - s32 bwDVD_LowClosePartition(dvdcallbacklow cb); - s32 bwDVD_LowOpenPartition(u32 offset, void *eticket, u32 certin_len, void *certificate_in, void *certificate_out, - dvdcallbacklow cb); - s32 bwDVD_LowUnencryptedRead(void *buf, u32 len, u32 offset, dvdcallbacklow cb); - s32 bwDVD_LowReset(dvdcallbacklow cb); - s32 bwDVD_LowWaitCoverClose(dvdcallbacklow cb); - s32 bwDVD_LowRead(void *buf, u32 len, u32 offset, dvdcallbacklow cb); - s32 bwDVD_EnableVideo(dvdcallbacklow cb); - s32 bwDVD_LowReadVideo(void *buf, u32 len, u32 offset, dvdcallbacklow cb); - s32 bwDVD_SetDecryption(s32 mode, dvdcallbacklow cb); - s32 bwDVD_SetOffset(u32 offset, dvdcallbacklow cb); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/source/patches/fst.c b/source/patches/fst.c deleted file mode 100644 index a8c69417..00000000 --- a/source/patches/fst.c +++ /dev/null @@ -1,859 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "fst.h" -#include "dvd_broadway.h" -#include "fatmounter.h" -#include "mload/mload.h" -#include "mload/mload_modules.h" -#include "gecko.h" - -#include "patchcode.h" -#include "language/gettext.h" - -#include "codehandler.h" -//#include "codehandlerslota.h" -#include "codehandleronly.h" -#include "multidol.h" - -#define FSTDIRTYPE 1 -#define FSTFILETYPE 0 -#define ENTRYSIZE 0xC -//#define FILEDIR "fat0:/codes" -//#define FILEDIR "sd:/codes" -#define FILEDIR "/codes" - -#define MAX_FILENAME_LEN 128 - -const char * CheatFilepath = NULL; -static const char * BCAFilepath = NULL; - -static u8 *codelistend; -void *codelist; - -u32 gameconfsize = 0; -u32 *gameconf = NULL; - -u8 debuggerselect; - -extern const u32 viwiihooks[4]; -extern const u32 kpadhooks[4]; -extern const u32 joypadhooks[4]; -extern const u32 gxdrawhooks[4]; -extern const u32 gxflushhooks[4]; -extern const u32 ossleepthreadhooks[4]; -extern const u32 axnextframehooks[4]; -extern const u32 wpadbuttonsdownhooks[4]; -extern const u32 wpadbuttonsdown2hooks[4]; - -void SetCheatFilepath(const char * path) -{ - CheatFilepath = path; -} - -void SetBCAFilepath(const char * path) -{ - BCAFilepath = path; -} - -//static vu32 dvddone = 0; - -//--------------------------------------------------------------------------------- -void app_loadgameconfig(char *discid) -//--------------------------------------------------------------------------------- -{ - if (!CheatFilepath) return; - - gameconfsize = 0; - - if (gameconf == NULL) - { - gameconf = (u32*) malloc(65536); - if (gameconf == NULL) - { - //TODO for oggzee - //print_status("Out of memory"); - return; - } - } - - FILE* fp; - u32 ret; - u32 filesize; - s32 gameidmatch, maxgameidmatch = -1, maxgameidmatch2 = -1; - u32 i, numnonascii, parsebufpos; - u32 codeaddr, codeval, codeaddr2, codeval2, codeoffset; - u32 temp, tempoffset = 0; - char parsebuffer[18]; - - //if (config_bytes[2] == 8) - // hookset = 1; - - u8 *tempgameconf; - u32 tempgameconfsize = 0; - - //memcpy(tempgameconf, defaultgameconfig, defaultgameconfig_size); - //tempgameconf[defaultgameconfig_size] = '\n'; - //tempgameconfsize = defaultgameconfig_size + 1; - - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s/gameconfig.txt", CheatFilepath); - - fp = fopen(filepath, "rb"); - - if (!fp) - { - snprintf(filepath, sizeof(filepath), "SD:/gameconfig.txt"); - fp = fopen(filepath, "rb"); - if (!fp) - { - snprintf(filepath, sizeof(filepath), "USB:/gameconfig.txt"); - fp = fopen(filepath, "rb"); - } - } - - if (fp) - { - fseek(fp, 0, SEEK_END); - filesize = ftell(fp); - fseek(fp, 0, SEEK_SET); - - tempgameconf = (u8*) malloc(filesize); - if (tempgameconf == NULL) - { - //TODO for oggzee - //print_status("Out of memory"); - //wait(4); - return; - } - - ret = fread((void*) tempgameconf, 1, filesize, fp); - fclose(fp); - if (ret != filesize) - { - //TODO for oggzee - //print_status("Error reading gameconfig.txt"); - //wait(4); - return; - } - tempgameconfsize = filesize; - } - else - { - return; - } - - // Remove non-ASCII characters - numnonascii = 0; - for (i = 0; i < tempgameconfsize; i++) - { - if (tempgameconf[i] < 9 || tempgameconf[i] > 126) - numnonascii++; - else tempgameconf[i - numnonascii] = tempgameconf[i]; - } - tempgameconfsize -= numnonascii; - - *(tempgameconf + tempgameconfsize) = 0; - //gameconf = (tempgameconf + tempgameconfsize) + (4 - (((u32) (tempgameconf + tempgameconfsize)) % 4)); - - for (maxgameidmatch = 0; maxgameidmatch <= 6; maxgameidmatch++) - { - i = 0; - while (i < tempgameconfsize) - { - maxgameidmatch2 = -1; - while (maxgameidmatch != maxgameidmatch2) - { - while (i != tempgameconfsize && tempgameconf[i] != ':') - i++; - if (i == tempgameconfsize) break; - while ((tempgameconf[i] != 10 && tempgameconf[i] != 13) && (i != 0)) - i--; - if (i != 0) i++; - parsebufpos = 0; - gameidmatch = 0; - while (tempgameconf[i] != ':') - { - if (tempgameconf[i] == '?') - { - parsebuffer[parsebufpos] = discid[parsebufpos]; - parsebufpos++; - gameidmatch--; - i++; - } - else if (tempgameconf[i] != 0 && tempgameconf[i] != ' ') - parsebuffer[parsebufpos++] = tempgameconf[i++]; - else if (tempgameconf[i] == ' ') - break; - else i++; - if (parsebufpos == 8) break; - } - parsebuffer[parsebufpos] = 0; - if (strncasecmp("DEFAULT", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 7) - { - gameidmatch = 0; - goto idmatch; - } - if (strncmp(discid, parsebuffer, strlen(parsebuffer)) == 0) - { - gameidmatch += strlen(parsebuffer); - idmatch: if (gameidmatch > maxgameidmatch2) - { - maxgameidmatch2 = gameidmatch; - } - } - while ((i != tempgameconfsize) && (tempgameconf[i] != 10 && tempgameconf[i] != 13)) - i++; - } - while (i != tempgameconfsize && tempgameconf[i] != ':') - { - parsebufpos = 0; - while ((i != tempgameconfsize) && (tempgameconf[i] != 10 && tempgameconf[i] != 13)) - { - if (tempgameconf[i] != 0 && tempgameconf[i] != ' ' && tempgameconf[i] != '(' && tempgameconf[i] - != ':') - parsebuffer[parsebufpos++] = tempgameconf[i++]; - else if (tempgameconf[i] == ' ' || tempgameconf[i] == '(' || tempgameconf[i] == ':') - break; - else i++; - if (parsebufpos == 17) break; - } - parsebuffer[parsebufpos] = 0; - //if (!autobootcheck) - { - //if (strncasecmp("addtocodelist(", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 14) - //{ - // ret = sscanf(tempgameconf + i, "%x %x", &codeaddr, &codeval); - // if (ret == 2) - // addtocodelist(codeaddr, codeval); - //} - if (strncasecmp("codeliststart", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) - == 13) - { - sscanf((char *) (tempgameconf + i), " = %x", (unsigned int *) &codelist); - } - if (strncasecmp("codelistend", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 11) - { - sscanf((char *) (tempgameconf + i), " = %x", (unsigned int *) &codelistend); - } - /* - if (strncasecmp("hooktype", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 8) - { - if (hookset == 1) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 7) - config_bytes[2] = temp; - } - } - */ - if (strncasecmp("poke", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 4) - { - ret = sscanf((char *) tempgameconf + i, "( %x , %x", &codeaddr, &codeval); - if (ret == 2) - { - *(gameconf + (gameconfsize / 4)) = 0; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = 0; - gameconfsize += 8; - *(gameconf + (gameconfsize / 4)) = codeaddr; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeval; - gameconfsize += 4; - DCFlushRange((void *) (gameconf + (gameconfsize / 4) - 5), 20); - } - } - if (strncasecmp("pokeifequal", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 11) - { - ret = sscanf((char *) (tempgameconf + i), "( %x , %x , %x , %x", &codeaddr, &codeval, - &codeaddr2, &codeval2); - if (ret == 4) - { - *(gameconf + (gameconfsize / 4)) = 0; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeaddr; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeval; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeaddr2; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeval2; - gameconfsize += 4; - DCFlushRange((void *) (gameconf + (gameconfsize / 4) - 5), 20); - } - } - if (strncasecmp("searchandpoke", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) - == 13) - { - ret = sscanf((char *) (tempgameconf + i), "( %x%n", &codeval, &tempoffset); - if (ret == 1) - { - gameconfsize += 4; - temp = 0; - while (ret == 1) - { - *(gameconf + (gameconfsize / 4)) = codeval; - gameconfsize += 4; - temp++; - i += tempoffset; - ret = sscanf((char *) (tempgameconf + i), " %x%n", &codeval, &tempoffset); - } - *(gameconf + (gameconfsize / 4) - temp - 1) = temp; - ret = sscanf((char *) (tempgameconf + i), " , %x , %x , %x , %x", &codeaddr, &codeaddr2, - &codeoffset, &codeval2); - if (ret == 4) - { - *(gameconf + (gameconfsize / 4)) = codeaddr; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeaddr2; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeoffset; - gameconfsize += 4; - *(gameconf + (gameconfsize / 4)) = codeval2; - gameconfsize += 4; - DCFlushRange((void *) (gameconf + (gameconfsize / 4) - temp - 5), temp * 4 + 20); - } - else gameconfsize -= temp * 4 + 4; - } - - } - /* - if (strncasecmp("hook", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 4) - { - ret = sscanf(tempgameconf + i, "( %x %x %x %x %x %x %x %x", customhook, customhook + 1, customhook + 2, customhook + 3, customhook + 4, customhook + 5, customhook + 6, customhook + 7); - if (ret >= 3) - { - if (hookset != 1) - configwarn |= 4; - config_bytes[2] = 0x08; - customhooksize = ret * 4; - } - } - if (strncasecmp("002fix", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 6) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 0x1) - fakeiosversion = temp; - } - if (strncasecmp("switchios", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 9) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - willswitchios = temp; - } - if (strncasecmp("videomode", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 9) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - { - if (temp == 0) - { - if (config_bytes[1] != 0x00) - configwarn |= 1; - config_bytes[1] = 0x00; - } - else if (temp == 1) - { - if (config_bytes[1] != 0x03) - configwarn |= 1; - config_bytes[1] = 0x03; - } - else if (temp == 2) - { - if (config_bytes[1] != 0x01) - configwarn |= 1; - config_bytes[1] = 0x01; - } - else if (temp == 3) - { - if (config_bytes[1] != 0x02) - configwarn |= 1; - config_bytes[1] = 0x02; - } - } - } - if (strncasecmp("language", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 8) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - { - if (temp == 0) - { - if (config_bytes[0] != 0xCD) - configwarn |= 2; - config_bytes[0] = 0xCD; - } - else if (temp > 0 && temp <= 10) - { - if (config_bytes[0] != temp-1) - configwarn |= 2; - config_bytes[0] = temp-1; - } - } - } - if (strncasecmp("diagnostic", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 10) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - { - if (temp == 0 || temp == 1) - diagcreate = temp; - } - } - if (strncasecmp("vidtv", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 5) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - vipatchon = temp; - } - if (strncasecmp("fwritepatch", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 11) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - applyfwritepatch = temp; - } - if (strncasecmp("dumpmaindol", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 11) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - dumpmaindol = temp; - } - */ - } - /*else - { - - if (strncasecmp("autoboot", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 8) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - autoboot = temp; - } - if (strncasecmp("autobootwait", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 12) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 255) - autobootwait = temp; - } - if (strncasecmp("autoboothbc", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 11) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - autoboothbc = temp; - } - if (strncasecmp("autobootocarina", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 15) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - config_bytes[4] = temp; - } - if (strncasecmp("autobootdebugger", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 16) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - config_bytes[7] = temp; - } - if (strncasecmp("rebootermenuitem", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 16) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 1) - rebooterasmenuitem = temp; - } - if (strncasecmp("startupios", parsebuffer, strlen(parsebuffer)) == 0 && strlen(parsebuffer) == 10) - { - ret = sscanf(tempgameconf + i, " = %u", &temp); - if (ret == 1) - if (temp >= 0 && temp <= 255) - { - sdio_Shutdown(); - IOS_ReloadIOS(temp); - detectIOScapabilities(); - sd_init(); - startupiosloaded = 1; - } - } - - }*/ - if (tempgameconf[i] != ':') - { - while ((i != tempgameconfsize) && (tempgameconf[i] != 10 && tempgameconf[i] != 13)) - i++; - if (i != tempgameconfsize) i++; - } - } - if (i != tempgameconfsize) while ((tempgameconf[i] != 10 && tempgameconf[i] != 13) && (i != 0)) - i--; - } - } - - free(tempgameconf); - //tempcodelist = ((u8 *) gameconf) + gameconfsize; -} - -u8 *code_buf = NULL; -int code_size = 0; - -int ocarina_load_code(u8 *id) -{ - if (debuggerselect == 0x00) - codelist = (u8 *) 0x800022A8; - else codelist = (u8 *) 0x800028B8; - codelistend = (u8 *) 0x80003000; - - app_loadgameconfig((char *) id); - - char filepath[150]; - - gprintf("Ocarina: Searching codes..."); - gprintf("\n"); - - sprintf(filepath, "%s%s", CheatFilepath, (char *) id); - filepath[strlen(CheatFilepath) + 6] = 0x2E; - filepath[strlen(CheatFilepath) + 7] = 0x67; - filepath[strlen(CheatFilepath) + 8] = 0x63; - filepath[strlen(CheatFilepath) + 9] = 0x74; - filepath[strlen(CheatFilepath) + 10] = 0; - - FILE * fp = fopen(filepath, "rb"); - if (!fp) - { - gprintf("Ocarina: No codes found"); - printf("\n"); - return 0; - } - - fseek(fp, 0, SEEK_END); - u32 filesize = ftell(fp); - rewind(fp); - - code_buf = (u8*) malloc(filesize); - if (!code_buf) - { - gprintf("Ocarina: No codes found\n"); - fclose(fp); - return 0; - } - - code_size = fread(code_buf, 1, filesize, fp); - - fclose(fp); - - if (code_size <= 0) - { - gprintf("Ocarina: could not read file.\n"); - free(code_buf); - code_buf = NULL; - code_size = 0; - return 0; - } - - if (code_size > (s32) codelistend - (s32) codelist) - { - gprintf("Ocarina: Too many codes found\n"); - free(code_buf); - code_buf = NULL; - code_size = 0; - return 0; - } - - gprintf("Ocarina: Codes found.\n"); - - return code_size; -} - -//--------------------------------------------------------------------------------- -void app_pokevalues() -//--------------------------------------------------------------------------------- -{ - u32 i, *codeaddr, *codeaddr2, *addrfound = NULL; - - if (gameconfsize != 0) - { - for (i = 0; i < gameconfsize / 4; i++) - { - if (*(gameconf + i) == 0) - { - if (((u32 *) (*(gameconf + i + 1))) == NULL || *((u32 *) (*(gameconf + i + 1))) == *(gameconf + i + 2)) - { - *((u32 *) (*(gameconf + i + 3))) = *(gameconf + i + 4); - DCFlushRange((void *) *(gameconf + i + 3), 4); - } - i += 4; - } - else - { - codeaddr = (u32 *) *(gameconf + i + *(gameconf + i) + 1); - codeaddr2 = (u32 *) *(gameconf + i + *(gameconf + i) + 2); - if (codeaddr == 0 && addrfound != NULL) - codeaddr = addrfound; - else if (codeaddr == 0 && codeaddr2 != 0) - codeaddr = (u32 *) ((((u32) codeaddr2) >> 28) << 28); - else if (codeaddr == 0 && codeaddr2 == 0) - { - i += *(gameconf + i) + 4; - continue; - } - if (codeaddr2 == 0) codeaddr2 = codeaddr + *(gameconf + i); - addrfound = NULL; - while (codeaddr <= (codeaddr2 - *(gameconf + i))) - { - if (memcmp(codeaddr, gameconf + i + 1, (*(gameconf + i)) * 4) == 0) - { - *(codeaddr + ((*(gameconf + i + *(gameconf + i) + 3)) / 4)) = *(gameconf + i + *(gameconf + i) - + 4); - if (addrfound == NULL) addrfound = codeaddr; - } - codeaddr++; - } - i += *(gameconf + i) + 4; - } - } - } -} - -//--------------------------------------------------------------------------------- -void load_handler() -//--------------------------------------------------------------------------------- -{ - if (hooktype != 0x00) - { - if (debuggerselect == 0x01) - { - /*switch(gecko_channel) - { - case 0: // Slot A - - memset((void*)0x80001800,0,codehandlerslota_size); - memcpy((void*)0x80001800,codehandlerslota,codehandlerslota_size); - if (pausedstartoption == 0x01) - *(u32*)0x80002798 = 1; - memcpy((void*)0x80001CDE, &codelist, 2); - memcpy((void*)0x80001CE2, ((u8*) &codelist) + 2, 2); - memcpy((void*)0x80001F7E, &codelist, 2); - memcpy((void*)0x80001F82, ((u8*) &codelist) + 2, 2); - DCFlushRange((void*)0x80001800,codehandlerslota_size); - break; - - case 1: // slot B - */ - memset((void*) 0x80001800, 0, codehandler_size); - memcpy((void*) 0x80001800, codehandler, codehandler_size); - //TODO for oggzee: Consider adding an option for paused start, debugging related - //if (pausedstartoption == 0x01) - // *(u32*)0x80002798 = 1; - memcpy((void*) 0x80001CDE, &codelist, 2); - memcpy((void*) 0x80001CE2, ((u8*) &codelist) + 2, 2); - memcpy((void*) 0x80001F5A, &codelist, 2); - memcpy((void*) 0x80001F5E, ((u8*) &codelist) + 2, 2); - DCFlushRange((void*) 0x80001800, codehandler_size); - /* break; - - case 2: - memset((void*)0x80001800,0,codehandler_size); - memcpy((void*)0x80001800,codehandler,codehandler_size); - if (pausedstartoption == 0x01) - *(u32*)0x80002798 = 1; - memcpy((void*)0x80001CDE, &codelist, 2); - memcpy((void*)0x80001CE2, ((u8*) &codelist) + 2, 2); - memcpy((void*)0x80001F5A, &codelist, 2); - memcpy((void*)0x80001F5E, ((u8*) &codelist) + 2, 2); - DCFlushRange((void*)0x80001800,codehandler_size); - break; - }*/ - } - else - { - memset((void*) 0x80001800, 0, codehandleronly_size); - memcpy((void*) 0x80001800, codehandleronly, codehandleronly_size); - memcpy((void*) 0x80001906, &codelist, 2); - memcpy((void*) 0x8000190A, ((u8*) &codelist) + 2, 2); - DCFlushRange((void*) 0x80001800, codehandleronly_size); - } - // Load multidol handler - memset((void*) 0x80001000, 0, multidol_size); - memcpy((void*) 0x80001000, multidol, multidol_size); - DCFlushRange((void*) 0x80001000, multidol_size); - switch (hooktype) - { - case 0x01: - memcpy((void*) 0x8000119C, viwiihooks, 12); - memcpy((void*) 0x80001198, viwiihooks + 3, 4); - break; - case 0x02: - memcpy((void*) 0x8000119C, kpadhooks, 12); - memcpy((void*) 0x80001198, kpadhooks + 3, 4); - break; - case 0x03: - memcpy((void*) 0x8000119C, joypadhooks, 12); - memcpy((void*) 0x80001198, joypadhooks + 3, 4); - break; - case 0x04: - memcpy((void*) 0x8000119C, gxdrawhooks, 12); - memcpy((void*) 0x80001198, gxdrawhooks + 3, 4); - break; - case 0x05: - memcpy((void*) 0x8000119C, gxflushhooks, 12); - memcpy((void*) 0x80001198, gxflushhooks + 3, 4); - break; - case 0x06: - memcpy((void*) 0x8000119C, ossleepthreadhooks, 12); - memcpy((void*) 0x80001198, ossleepthreadhooks + 3, 4); - break; - case 0x07: - memcpy((void*) 0x8000119C, axnextframehooks, 12); - memcpy((void*) 0x80001198, axnextframehooks + 3, 4); - break; - case 0x08: - //if (customhooksize == 16) - //{ - // memcpy((void*)0x8000119C,customhook,12); - // memcpy((void*)0x80001198,customhook+3,4); - //} - break; - case 0x09: - //memcpy((void*)0x8000119C,wpadbuttonsdownhooks,12); - //memcpy((void*)0x80001198,wpadbuttonsdownhooks+3,4); - break; - case 0x0A: - //memcpy((void*)0x8000119C,wpadbuttonsdown2hooks,12); - //memcpy((void*)0x80001198,wpadbuttonsdown2hooks+3,4); - break; - } - DCFlushRange((void*) 0x80001198, 16); - } - memcpy((void *) 0x80001800, (void*) 0x80000000, 6); -} - -int ocarina_do_code() -{ - if (!code_buf) - { - return 0; - } - - memset((void *) 0x80001800, 0, 0x1800); - - load_handler(); - memset(codelist, 0, (u32) codelistend - (u32) codelist); - - //Copy the codes - if (code_size > 0) - { - memcpy(codelist, code_buf, code_size); - DCFlushRange(codelist, (u32) codelistend - (u32) codelist); - free(code_buf); - code_buf = NULL; - } - - // TODO What's this??? - // enable flag - //*(vu8*)0x80001807 = 0x01; - - //This needs to be done after loading the .dol into memory - app_pokevalues(); - - // hooks are patched in dogamehooks() - return 1; -} - -u32 do_bca_code(u8 *gameid) -{ - if (!BCAFilepath) return 0; - - if (IOS_GetVersion() == 222 || IOS_GetVersion() == 223) - { - FILE *fp; - u32 filesize; - char filepath[150]; - memset(filepath, 0, 150); - u8 bcaCode[64] ATTRIBUTE_ALIGN( 32 ); - - sprintf(filepath, "%s%6s", BCAFilepath, gameid); - filepath[strlen(BCAFilepath) + 6] = '.'; - filepath[strlen(BCAFilepath) + 7] = 'b'; - filepath[strlen(BCAFilepath) + 8] = 'c'; - filepath[strlen(BCAFilepath) + 9] = 'a'; - - fp = fopen(filepath, "rb"); - if (!fp) - { - memset(filepath, 0, 150); - sprintf(filepath, "%s%3s", BCAFilepath, gameid + 1); - filepath[strlen(BCAFilepath) + 3] = '.'; - filepath[strlen(BCAFilepath) + 4] = 'b'; - filepath[strlen(BCAFilepath) + 5] = 'c'; - filepath[strlen(BCAFilepath) + 6] = 'a'; - fp = fopen(filepath, "rb"); - - if (!fp) - { - // Set default bcaCode - memset(bcaCode, 0, 64); - bcaCode[0x33] = 1; - } - } - - if (fp) - { - u32 ret = 0; - - fseek(fp, 0, SEEK_END); - filesize = ftell(fp); - - if (filesize == 64) - { - fseek(fp, 0, SEEK_SET); - ret = fread(bcaCode, 1, 64, fp); - } - fclose(fp); - - if (ret != 64) - { - // Set default bcaCode - memset(bcaCode, 0, 64); - bcaCode[0x33] = 1; - } - } - - Set_DIP_BCA_Datas(bcaCode); - } - return 0; -} diff --git a/source/patches/fst.h b/source/patches/fst.h deleted file mode 100644 index 290e2af5..00000000 --- a/source/patches/fst.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __FST_H__ -#define __FST_H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - //u32 do_fst(u32 fstlocation); - //u32 do_sd_code(char *filename); - -#define MAX_GCT_SIZE 2056 - - u32 do_bca_code(u8 *gameid); - int ocarina_load_code(u8 *id); - int ocarina_do_code(); - void SetCheatFilepath(const char * path); - void SetBCAFilepath(const char * path); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/patches/fwrite_patch.h b/source/patches/fwrite_patch.h deleted file mode 100644 index 026f2796..00000000 --- a/source/patches/fwrite_patch.h +++ /dev/null @@ -1,9 +0,0 @@ -unsigned char fwrite_patch_bin[] = { 0x7c, 0x84, 0x29, 0xd6, 0x39, 0x40, 0x00, 0x00, 0x94, 0x21, 0xff, 0xf0, 0x93, - 0xe1, 0x00, 0x0c, 0x7f, 0x8a, 0x20, 0x00, 0x40, 0x9c, 0x00, 0x64, 0x3d, 0x00, 0xcd, 0x00, 0x3d, 0x60, 0xcd, - 0x00, 0x3d, 0x20, 0xcd, 0x00, 0x61, 0x08, 0x68, 0x14, 0x61, 0x6b, 0x68, 0x24, 0x61, 0x29, 0x68, 0x20, 0x39, - 0x80, 0x00, 0xd0, 0x38, 0xc0, 0x00, 0x19, 0x38, 0xe0, 0x00, 0x00, 0x91, 0x88, 0x00, 0x00, 0x7c, 0x03, 0x50, - 0xae, 0x54, 0x00, 0xa0, 0x16, 0x64, 0x00, 0xb0, 0x00, 0x90, 0x0b, 0x00, 0x00, 0x90, 0xc9, 0x00, 0x00, 0x80, - 0x09, 0x00, 0x00, 0x70, 0x1f, 0x00, 0x01, 0x40, 0x82, 0xff, 0xf8, 0x80, 0x0b, 0x00, 0x00, 0x90, 0xe8, 0x00, - 0x00, 0x54, 0x00, 0x37, 0xfe, 0x7d, 0x4a, 0x02, 0x14, 0x7f, 0x8a, 0x20, 0x00, 0x41, 0x9c, 0xff, 0xc8, 0x7c, - 0xa3, 0x2b, 0x78, 0x83, 0xe1, 0x00, 0x0c, 0x38, 0x21, 0x00, 0x10, 0x4e, 0x80, 0x00, 0x20 }; -unsigned int fwrite_patch_bin_len = 136; diff --git a/source/patches/gamepatches.c b/source/patches/gamepatches.c deleted file mode 100644 index edbbd4e9..00000000 --- a/source/patches/gamepatches.c +++ /dev/null @@ -1,405 +0,0 @@ -#include -#include -#include -#include "dolpatcher.h" -#include "wip.h" -#include "gecko.h" -#include "../settings/SettingsEnums.h" - -/** Anti 002 fix for IOS 249 rev > 12 thanks to WiiPower **/ -bool Anti_002_fix(u8 * Address, int Size) -{ - u8 SearchPattern[12] = { 0x2C, 0x00, 0x00, 0x00, 0x48, 0x00, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00 }; - u8 PatchData[12] = { 0x2C, 0x00, 0x00, 0x00, 0x40, 0x82, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00 }; - return PatchDOL(Address, Size, (const u8 *) &SearchPattern, sizeof(SearchPattern), (const u8 *) &PatchData, - sizeof(PatchData)); -} - -/** Thanks to WiiPower **/ -bool NSMBPatch(u8 * Address, int Size) -{ - if (IOS_GetVersion() == 222 || IOS_GetVersion() == 223) return false; // Don't use this when using Hermes, it'll use the BCA fix instead... - - if (memcmp("SMNE", (char *) 0x80000000, 4) == 0) - { - u8 SearchPattern[32] = { 0x94, 0x21, 0xFF, 0xD0, 0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x34, 0x39, 0x61, - 0x00, 0x30, 0x48, 0x12, 0xD7, 0x89, 0x7C, 0x7B, 0x1B, 0x78, 0x7C, 0x9C, 0x23, 0x78, 0x7C, 0xBD, 0x2B, - 0x78 }; - u8 PatchData[32] = { 0x4E, 0x80, 0x00, 0x20, 0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x34, 0x39, 0x61, 0x00, - 0x30, 0x48, 0x12, 0xD7, 0x89, 0x7C, 0x7B, 0x1B, 0x78, 0x7C, 0x9C, 0x23, 0x78, 0x7C, 0xBD, 0x2B, 0x78 }; - return PatchDOL(Address, Size, (const u8 *) &SearchPattern, sizeof(SearchPattern), (const u8 *) &PatchData, - sizeof(PatchData)); - - } - else if (memcmp("SMN", (char *) 0x80000000, 3) == 0) - { - u8 SearchPattern[4] = { 0x7A, 0x6B, 0x6F, 0x6A }; - u8 PatchData[32] = { 0x4E, 0x80, 0x00, 0x20, 0x7C, 0x08, 0x02, 0xA6, 0x90, 0x01, 0x00, 0x34, 0x39, 0x61, 0x00, - 0x30, 0x48, 0x12, 0xD9, 0x39, 0x7C, 0x7B, 0x1B, 0x78, 0x7C, 0x9C, 0x23, 0x78, 0x7C, 0xBD, 0x2B, 0x78 }; - return PatchDOL(Address, Size, (const u8 *) &SearchPattern, sizeof(SearchPattern), (const u8 *) &PatchData, - sizeof(PatchData)); - } - return false; -} - -bool PoPPatch() -{ - if (memcmp("SPX", (char *) 0x80000000, 3) == 0 || memcmp("RPW", (char *) 0x80000000, 3) == 0) - { - WIP_Code * CodeList = malloc(5 * sizeof(WIP_Code)); - CodeList[0].offset = 0x007AAC6A; - CodeList[0].srcaddress = 0x7A6B6F6A; - CodeList[0].dstaddress = 0x6F6A7A6B; - CodeList[1].offset = 0x007AAC75; - CodeList[1].srcaddress = 0x7C7A6939; - CodeList[1].dstaddress = 0x69397C7A; - CodeList[2].offset = 0x007AAC82; - CodeList[2].srcaddress = 0x7376686B; - CodeList[2].dstaddress = 0x686B7376; - CodeList[3].offset = 0x007AAC92; - CodeList[3].srcaddress = 0x80717570; - CodeList[3].dstaddress = 0x75708071; - CodeList[4].offset = 0x007AAC9D; - CodeList[4].srcaddress = 0x82806F3F; - CodeList[4].dstaddress = 0x6F3F8280; - - if (set_wip_list(CodeList, 5) == false) - { - free(CodeList); - CodeList = NULL; - } - } - return false; -} - -/** Insert the individual gamepatches above with the patterns and patch data **/ -/** Following is only the VideoPatcher **/ - -#if 0 /** Isn't used right now **/ - -static GXRModeObj* vmodes[] = -{ - &TVNtsc240Ds, - &TVNtsc240DsAa, - &TVNtsc240Int, - &TVNtsc240IntAa, - &TVNtsc480IntDf, - &TVNtsc480IntAa, - &TVNtsc480Prog, - &TVMpal480IntDf, - &TVPal264Ds, - &TVPal264DsAa, - &TVPal264Int, - &TVPal264IntAa, - &TVPal524IntAa, - &TVPal528Int, - &TVPal528IntDf, - &TVPal574IntDfScale, - &TVEurgb60Hz240Ds, - &TVEurgb60Hz240DsAa, - &TVEurgb60Hz240Int, - &TVEurgb60Hz240IntAa, - &TVEurgb60Hz480Int, - &TVEurgb60Hz480IntDf, - &TVEurgb60Hz480IntAa, - &TVEurgb60Hz480Prog, - &TVEurgb60Hz480ProgSoft, - &TVEurgb60Hz480ProgAa -}; - -#endif - -static GXRModeObj* PAL2NTSC[] = { &TVMpal480IntDf, &TVNtsc480IntDf, &TVPal264Ds, &TVNtsc240Ds, &TVPal264DsAa, - &TVNtsc240DsAa, &TVPal264Int, &TVNtsc240Int, &TVPal264IntAa, &TVNtsc240IntAa, &TVPal524IntAa, &TVNtsc480IntAa, - &TVPal528Int, &TVNtsc480IntAa, &TVPal528IntDf, &TVNtsc480IntDf, &TVPal574IntDfScale, &TVNtsc480IntDf, - &TVEurgb60Hz240Ds, &TVNtsc240Ds, &TVEurgb60Hz240DsAa, &TVNtsc240DsAa, &TVEurgb60Hz240Int, &TVNtsc240Int, - &TVEurgb60Hz240IntAa, &TVNtsc240IntAa, &TVEurgb60Hz480Int, &TVNtsc480IntAa, &TVEurgb60Hz480IntDf, - &TVNtsc480IntDf, &TVEurgb60Hz480IntAa, &TVNtsc480IntAa, &TVEurgb60Hz480Prog, &TVNtsc480Prog, - &TVEurgb60Hz480ProgSoft, &TVNtsc480Prog, &TVEurgb60Hz480ProgAa, &TVNtsc480Prog, 0, 0 }; - -static GXRModeObj* NTSC2PAL[] = { &TVNtsc240Ds, &TVPal264Ds, &TVNtsc240DsAa, &TVPal264DsAa, &TVNtsc240Int, - &TVPal264Int, &TVNtsc240IntAa, &TVPal264IntAa, &TVNtsc480IntDf, &TVPal528IntDf, &TVNtsc480IntAa, - &TVPal524IntAa, &TVNtsc480Prog, &TVPal528IntDf, 0, 0 }; - -static GXRModeObj* NTSC2PAL60[] = { &TVNtsc240Ds, &TVEurgb60Hz240Ds, &TVNtsc240DsAa, &TVEurgb60Hz240DsAa, - &TVNtsc240Int, &TVEurgb60Hz240Int, &TVNtsc240IntAa, &TVEurgb60Hz240IntAa, &TVNtsc480IntDf, - &TVEurgb60Hz480IntDf, &TVNtsc480IntAa, &TVEurgb60Hz480IntAa, &TVNtsc480Prog, &TVEurgb60Hz480Prog, 0, 0 }; - -static bool compare_videomodes(GXRModeObj* mode1, GXRModeObj* mode2) -{ - if (mode1->viTVMode != mode2->viTVMode || mode1->fbWidth != mode2->fbWidth || mode1->efbHeight != mode2->efbHeight - || mode1->xfbHeight != mode2->xfbHeight || mode1->viXOrigin != mode2->viXOrigin || mode1->viYOrigin - != mode2->viYOrigin || mode1->viWidth != mode2->viWidth || mode1->viHeight != mode2->viHeight - || mode1->xfbMode != mode2->xfbMode || mode1->field_rendering != mode2->field_rendering || mode1->aa - != mode2->aa || mode1->sample_pattern[0][0] != mode2->sample_pattern[0][0] || mode1->sample_pattern[1][0] - != mode2->sample_pattern[1][0] || mode1->sample_pattern[2][0] != mode2->sample_pattern[2][0] - || mode1->sample_pattern[3][0] != mode2->sample_pattern[3][0] || mode1->sample_pattern[4][0] - != mode2->sample_pattern[4][0] || mode1->sample_pattern[5][0] != mode2->sample_pattern[5][0] - || mode1->sample_pattern[6][0] != mode2->sample_pattern[6][0] || mode1->sample_pattern[7][0] - != mode2->sample_pattern[7][0] || mode1->sample_pattern[8][0] != mode2->sample_pattern[8][0] - || mode1->sample_pattern[9][0] != mode2->sample_pattern[9][0] || mode1->sample_pattern[10][0] - != mode2->sample_pattern[10][0] || mode1->sample_pattern[11][0] != mode2->sample_pattern[11][0] - || mode1->sample_pattern[0][1] != mode2->sample_pattern[0][1] || mode1->sample_pattern[1][1] - != mode2->sample_pattern[1][1] || mode1->sample_pattern[2][1] != mode2->sample_pattern[2][1] - || mode1->sample_pattern[3][1] != mode2->sample_pattern[3][1] || mode1->sample_pattern[4][1] - != mode2->sample_pattern[4][1] || mode1->sample_pattern[5][1] != mode2->sample_pattern[5][1] - || mode1->sample_pattern[6][1] != mode2->sample_pattern[6][1] || mode1->sample_pattern[7][1] - != mode2->sample_pattern[7][1] || mode1->sample_pattern[8][1] != mode2->sample_pattern[8][1] - || mode1->sample_pattern[9][1] != mode2->sample_pattern[9][1] || mode1->sample_pattern[10][1] - != mode2->sample_pattern[10][1] || mode1->sample_pattern[11][1] != mode2->sample_pattern[11][1] - || mode1->vfilter[0] != mode2->vfilter[0] || mode1->vfilter[1] != mode2->vfilter[1] || mode1->vfilter[2] - != mode2->vfilter[2] || mode1->vfilter[3] != mode2->vfilter[3] || mode1->vfilter[4] != mode2->vfilter[4] - || mode1->vfilter[5] != mode2->vfilter[5] || mode1->vfilter[6] != mode2->vfilter[6]) - { - return false; - } - else - { - return true; - } -} - -static void patch_videomode(GXRModeObj* mode1, GXRModeObj* mode2) -{ - mode1->viTVMode = mode2->viTVMode; - mode1->fbWidth = mode2->fbWidth; - mode1->efbHeight = mode2->efbHeight; - mode1->xfbHeight = mode2->xfbHeight; - mode1->viXOrigin = mode2->viXOrigin; - mode1->viYOrigin = mode2->viYOrigin; - mode1->viWidth = mode2->viWidth; - mode1->viHeight = mode2->viHeight; - mode1->xfbMode = mode2->xfbMode; - mode1->field_rendering = mode2->field_rendering; - mode1->aa = mode2->aa; - mode1->sample_pattern[0][0] = mode2->sample_pattern[0][0]; - mode1->sample_pattern[1][0] = mode2->sample_pattern[1][0]; - mode1->sample_pattern[2][0] = mode2->sample_pattern[2][0]; - mode1->sample_pattern[3][0] = mode2->sample_pattern[3][0]; - mode1->sample_pattern[4][0] = mode2->sample_pattern[4][0]; - mode1->sample_pattern[5][0] = mode2->sample_pattern[5][0]; - mode1->sample_pattern[6][0] = mode2->sample_pattern[6][0]; - mode1->sample_pattern[7][0] = mode2->sample_pattern[7][0]; - mode1->sample_pattern[8][0] = mode2->sample_pattern[8][0]; - mode1->sample_pattern[9][0] = mode2->sample_pattern[9][0]; - mode1->sample_pattern[10][0] = mode2->sample_pattern[10][0]; - mode1->sample_pattern[11][0] = mode2->sample_pattern[11][0]; - mode1->sample_pattern[0][1] = mode2->sample_pattern[0][1]; - mode1->sample_pattern[1][1] = mode2->sample_pattern[1][1]; - mode1->sample_pattern[2][1] = mode2->sample_pattern[2][1]; - mode1->sample_pattern[3][1] = mode2->sample_pattern[3][1]; - mode1->sample_pattern[4][1] = mode2->sample_pattern[4][1]; - mode1->sample_pattern[5][1] = mode2->sample_pattern[5][1]; - mode1->sample_pattern[6][1] = mode2->sample_pattern[6][1]; - mode1->sample_pattern[7][1] = mode2->sample_pattern[7][1]; - mode1->sample_pattern[8][1] = mode2->sample_pattern[8][1]; - mode1->sample_pattern[9][1] = mode2->sample_pattern[9][1]; - mode1->sample_pattern[10][1] = mode2->sample_pattern[10][1]; - mode1->sample_pattern[11][1] = mode2->sample_pattern[11][1]; - mode1->vfilter[0] = mode2->vfilter[0]; - mode1->vfilter[1] = mode2->vfilter[1]; - mode1->vfilter[2] = mode2->vfilter[2]; - mode1->vfilter[3] = mode2->vfilter[3]; - mode1->vfilter[4] = mode2->vfilter[4]; - mode1->vfilter[5] = mode2->vfilter[5]; - mode1->vfilter[6] = mode2->vfilter[6]; -} - -static bool Search_and_patch_Video_Modes(u8 * Address, u32 Size, GXRModeObj* Table[]) -{ - u8 *Addr = (u8 *) Address; - bool found = 0; - u32 i; - - while (Size >= sizeof(GXRModeObj)) - { - - for (i = 0; Table[i]; i += 2) - { - - if (compare_videomodes(Table[i], (GXRModeObj*) Addr)) - - { - found = 1; - patch_videomode((GXRModeObj*) Addr, Table[i + 1]); - Addr += (sizeof(GXRModeObj) - 4); - Size -= (sizeof(GXRModeObj) - 4); - break; - } - } - - Addr += 4; - Size -= 4; - } - - return found; -} - -void VideoModePatcher(u8 * dst, int len, u8 videoSelected) -{ - GXRModeObj** table = NULL; - if (videoSelected == VIDEO_MODE_PATCH) // patch enum'd in cfg.h - - { - switch (CONF_GetVideo()) - { - case CONF_VIDEO_PAL: - if (CONF_GetEuRGB60() > 0) - { - table = NTSC2PAL60; - } - else - { - table = NTSC2PAL; - } - break; - - case CONF_VIDEO_MPAL: - - table = NTSC2PAL; - break; - - default: - table = PAL2NTSC; - break; - } - Search_and_patch_Video_Modes(dst, len, table); - } -} - -//giantpune's magic super patch to return to channels - -static u32 ad[ 4 ] = { 0, 0, 0, 0 };//these variables are global on the off chance the different parts needed -static u8 found = 0; //to find in the dol are found in different sections of the dol -static u8 patched = 0; -bool PatchReturnTo( void *Address, int Size, u32 id ) -{ - if( !id || patched ) - return 0; - //gprintf("PatchReturnTo( %p, %08x, %08x )\n", Address, Size, id ); - - //new __OSLoadMenu() (SM2.0 and higher) - u8 SearchPattern[ 12 ] = { 0x38, 0x80, 0x00, 0x02, 0x38, 0x60, 0x00, 0x01, 0x38, 0xa0, 0x00, 0x00 }; //li r4,2 - //li r3,1 - //li r5,0 - //old _OSLoadMenu() (used in launch games) - u8 SearchPatternB[ 12 ] = { 0x38, 0xC0, 0x00, 0x02, 0x38, 0xA0, 0x00, 0x01, 0x38, 0xE0, 0x00, 0x00 }; //li r6,2 - //li r5,1 - //li r7,0 - //identifier for the safe place - u8 SearchPattern2[ 12 ] = { 0x4D, 0x65, 0x74, 0x72, 0x6F, 0x77, 0x65, 0x72, 0x6B, 0x73, 0x20, 0x54 }; //"Metrowerks T" - - u8 oldSDK = 0; - found = 0; - - void *Addr = Address; - void *Addr_end = Address+Size; - - while (Addr <= Addr_end - 12 ) { - //find a safe place or the patch to hang out - if ( ! ad[ 3 ] && memcmp( Addr, SearchPattern2, 12 ) == 0 ) { - ad[ 3 ] = (u32)Addr + 0x30; - } - //find __OSLaunchMenu() and remember some addresses in it - else if ( memcmp( Addr, SearchPattern, 12 )==0 ) { - ad[ found++ ] = (u32)Addr; - } - else if ( ad[ 0 ] && memcmp( Addr, SearchPattern, 8 )==0 ) //after the first match is found, only search the first 8 bytes for the other 2 - { - if( !ad[ 1 ] ) ad[ found++ ] = (u32)Addr; - else if( !ad[ 2 ] ) ad[ found++ ] = (u32)Addr; - if( found >= 3 )break; - } - Addr += 4; - } - //check for the older-ass version of the SDK - if( found < 3 && ad[ 3 ] ) - { - Addr = Address; - ad[ 0 ] = 0; ad[ 1 ] = 0; - ad[ 2 ] = 0; - found = 0; - oldSDK = 1; - - while (Addr <= Addr_end - 12 ) { - //find __OSLaunchMenu() and remember some addresses in it - if ( memcmp( Addr, SearchPatternB, 12 )==0 ) { - ad[ found++ ] = (u32)Addr; - } - else if ( ad[ 0 ] && memcmp( Addr, SearchPatternB, 8 ) == 0 ) //after the first match is found, only search the first 8 bytes for the other 2 - { - if( !ad[ 1 ] ) ad[ found++ ] = (u32)Addr; - else if( !ad[ 2 ] ) ad[ found++ ] = (u32)Addr; - if( found >= 3 )break; - } - Addr += 4; - } - } - - //if the function is found - if( found == 3 && ad[ 3 ] ) - { - //gprintf("patch __OSLaunchMenu( 0x00010001, 0x%08x )\n", id); - u32 nop = 0x60000000; - - //the magic that writes the TID to the registers - u8 jump[ 20 ] = { 0x3C, 0x60, 0x00, 0x01, //lis r3,1 - 0x60, 0x63, 0x00, 0x01, //ori r3,r3,1 - 0x3C, 0x80, (u8)( id >> 24 ), (u8)( id >> 16 ), //lis r4,(u16)(tid >> 16) - 0x60, 0x84, (u8)( id >> 8 ), (u8)id, //ori r4,r4,(u16)(tid) - 0x4E, 0x80, 0x00, 0x20 }; //blr - - if( oldSDK ) - { - jump[ 1 ] = 0xA0; //3CA00001 //lis r5,1 - jump[ 5 ] = 0xA5; //60A50001 //ori r5,r5,1 - jump[ 9 ] = 0xC0; //3CC0AF1B //lis r6,(u16)(tid >> 16) - jump[ 13 ] = 0xC6;//60C6F516 //ori r6,r6,(u16)(tid) - } - - void* addr = (u32*)ad[ 3 ]; - - //write new stuff to in a unused part of the main.dol - memcpy( addr, jump, sizeof( jump ) ); - - //ES_GetTicketViews() - u32 newval = ( ad[ 3 ] - ad[ 0 ] ); - newval &= 0x03FFFFFC; - newval |= 0x48000001; - addr = (u32*)ad[ 0 ]; - memcpy( addr, &newval, sizeof( u32 ) ); //bl ad[ 3 ] - memcpy( addr + 4, &nop, sizeof( u32 ) ); //nop - //gprintf("\t%08x -> %08x\n", addr, newval ); - - //ES_GetTicketViews() again - newval = ( ad[ 3 ] - ad[ 1 ] ); - newval &= 0x03FFFFFC; - newval |= 0x48000001; - addr = (u32*)ad[ 1 ]; - memcpy( addr, &newval, sizeof( u32 ) ); //bl ad[ 3 ] - memcpy( addr + 4, &nop, sizeof( u32 ) ); //nop - //gprintf("\t%08x -> %08x\n", addr, newval ); - - //ES_LaunchTitle() - newval = ( ad[ 3 ] - ad[ 2 ] ); - newval &= 0x03FFFFFC; - newval |= 0x48000001; - addr = (u32*)ad[ 2 ]; - memcpy( addr, &newval, sizeof( u32 ) ); //bl ad[ 3 ] - memcpy( addr + 4, &nop, sizeof( u32 ) ); //nop - //gprintf("\t%08x -> %08x\n", addr, newval ); - - patched = 1; - } - /*else - { - gprintf("not patched\n"); - gprintf("found %d addresses\n", found); - int i; - for( i = 0; i< 4; i++) - gprintf("ad[ %d ]: %08x\n", i, ad[ i ] ); - gprintf("offset : %08x\n", ad[ 2 ] - ad[ 3 ] ); - - }*/ - return patched; -} diff --git a/source/patches/gamepatches.h b/source/patches/gamepatches.h deleted file mode 100644 index cc8efb20..00000000 --- a/source/patches/gamepatches.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef GAMEPATCHES_H_ -#define GAMEPATCHES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -bool Anti_002_fix(u8 * Address, int Size); -bool NSMBPatch(u8 * Address, int Size); -bool PoPPatch(); -bool Search_and_patch_Video_Modes(u8 * Address, u32 Size, GXRModeObj* Table[]); -void VideoModePatcher(u8 * dst, int len, u8 videoSelected); -bool PatchReturnTo(void *Address, int Size, u32 id); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/patches/geckomenu.h b/source/patches/geckomenu.h deleted file mode 100644 index d86fd2c9..00000000 --- a/source/patches/geckomenu.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __GECKOMENU_H__ -#define __GECKOMENU_H__ - -#define ROOTMENU 0 -#define ABOUTMENU 1 -#define CONFIGMENU 2 -#define REBOOTMENU 3 -#define root_itemcount 7 -#define about_itemcount 4 -#define config_itemcount 9 -#define rebooter_itemcount 6 - -u32 currentmenu; // 0 ROOT -u32 rootmenu_item; -u32 menufreeze; -u32 langselect; -u32 langsaved; -u32 pal60select; -u32 pal50select; -u32 viselect; -u32 ntscselect; -u32 hookselect; -u32 ocarinaselect; -u32 recoveryselect; -u32 regionfreeselect; -u32 nocopyselect; -u32 buttonskipselect; - -u32 doprogress(u32 progstate, u32 noelements); -void drawmenu(u32 menuid); -void drawselected(u32 menuidpos); -void processwpad(); -void clearscreen(u32 *framebuffer, u16 xscreen, u16 yscreen, u16 width, u16 height, u32 color); -void drawicon(u32 *framebuffer, u16 xscreen, u16 yscreen, u16 width, u16 height, u32 gicon); -u32 CvtRGB(u8 r1, u8 g1, u8 b1, u8 r2, u8 g2, u8 b2); - -#endif // __GECKOLOAD_H__ diff --git a/source/patches/kenobiwii.h b/source/patches/kenobiwii.h deleted file mode 100644 index 7d6c4f94..00000000 --- a/source/patches/kenobiwii.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - This file was autogenerated by raw2c. - Visit http://www.devkitpro.org - */ - -const unsigned char kenobiwii[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x26, 0xa0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x21, 0xff, 0x58, 0x90, 0x01, 0x00, 0x08, - 0x7c, 0x08, 0x02, 0xa6, 0x90, 0x01, 0x00, 0xac, 0x7c, 0x00, 0x00, 0x26, 0x90, 0x01, 0x00, 0x0c, 0x7c, 0x09, - 0x02, 0xa6, 0x90, 0x01, 0x00, 0x10, 0x7c, 0x01, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x14, 0xbc, 0x61, 0x00, 0x18, - 0x7f, 0x20, 0x00, 0xa6, 0x63, 0x3a, 0x20, 0x00, 0x73, 0x5a, 0xf9, 0xff, 0x7f, 0x40, 0x01, 0x24, 0xd8, 0x41, - 0x00, 0x98, 0xd8, 0x61, 0x00, 0xa0, 0x3f, 0xe0, 0x80, 0x00, 0x3e, 0x80, 0xcc, 0x00, 0xa3, 0x94, 0x40, 0x10, - 0x63, 0x95, 0x00, 0xff, 0xb2, 0xb4, 0x40, 0x10, 0x48, 0x00, 0x06, 0xb1, 0x3a, 0xa0, 0x00, 0x00, 0x3a, 0xc0, - 0x00, 0x19, 0x3a, 0xe0, 0x00, 0xd0, 0x3f, 0x00, 0xcd, 0x00, 0x63, 0xf2, 0x26, 0xa0, 0x80, 0x01, 0x00, 0xac, - 0x90, 0x12, 0x00, 0x04, 0x92, 0xb8, 0x64, 0x3c, 0x48, 0x00, 0x04, 0x85, 0x41, 0x82, 0x05, 0xfc, 0x2c, 0x1d, - 0x00, 0x04, 0x40, 0x80, 0x00, 0x10, 0x2c, 0x1d, 0x00, 0x01, 0x41, 0x80, 0x05, 0xec, 0x48, 0x00, 0x03, 0xa8, - 0x41, 0x82, 0x05, 0x48, 0x2c, 0x1d, 0x00, 0x06, 0x41, 0x82, 0x00, 0x8c, 0x2c, 0x1d, 0x00, 0x07, 0x41, 0x82, - 0x03, 0x8c, 0x2c, 0x1d, 0x00, 0x08, 0x41, 0x82, 0x05, 0xd8, 0x2c, 0x1d, 0x00, 0x09, 0x41, 0x82, 0x00, 0xa0, - 0x2c, 0x1d, 0x00, 0x10, 0x41, 0x82, 0x00, 0x98, 0x2c, 0x1d, 0x00, 0x2f, 0x41, 0x82, 0x00, 0x70, 0x2c, 0x1d, - 0x00, 0x30, 0x41, 0x82, 0x00, 0x78, 0x2c, 0x1d, 0x00, 0x38, 0x41, 0x82, 0x05, 0x80, 0x2c, 0x1d, 0x00, 0x40, - 0x41, 0x82, 0x03, 0x9c, 0x2c, 0x1d, 0x00, 0x41, 0x41, 0x82, 0x03, 0xb0, 0x2c, 0x1d, 0x00, 0x44, 0x41, 0x82, - 0x00, 0x68, 0x2c, 0x1d, 0x00, 0x50, 0x41, 0x82, 0x00, 0x20, 0x2c, 0x1d, 0x00, 0x60, 0x41, 0x82, 0x00, 0x24, - 0x2c, 0x1d, 0x00, 0x89, 0x41, 0x82, 0x00, 0x50, 0x2c, 0x1d, 0x00, 0x99, 0x41, 0x82, 0x05, 0x64, 0x48, 0x00, - 0x05, 0x68, 0x80, 0x72, 0x00, 0x00, 0x48, 0x00, 0x04, 0x81, 0x48, 0x00, 0x05, 0x5c, 0x48, 0x00, 0x05, 0xe5, - 0x48, 0x00, 0x05, 0x54, 0x38, 0x80, 0x00, 0x01, 0x90, 0x92, 0x00, 0x00, 0x48, 0x00, 0x05, 0x48, 0x48, 0x00, - 0x04, 0x61, 0x3a, 0x00, 0x00, 0xa0, 0x63, 0xec, 0x26, 0xc4, 0x48, 0x00, 0x03, 0x6c, 0x38, 0x60, 0x01, 0x20, - 0x63, 0xec, 0x26, 0xc4, 0x48, 0x00, 0x04, 0x21, 0x48, 0x00, 0x05, 0x28, 0x2f, 0x1d, 0x00, 0x10, 0x2e, 0x9d, - 0x00, 0x44, 0x63, 0xe4, 0x1a, 0xb4, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x03, 0x00, 0x48, 0x00, 0x05, 0x65, - 0x38, 0x63, 0x0a, 0x00, 0x48, 0x00, 0x05, 0x5d, 0x38, 0x63, 0x06, 0x00, 0x48, 0x00, 0x05, 0x55, 0x63, 0xec, - 0x26, 0xb4, 0x92, 0xac, 0x00, 0x00, 0x92, 0xac, 0x00, 0x04, 0x92, 0xac, 0x00, 0x08, 0x63, 0xe4, 0x26, 0xc4, - 0x81, 0x24, 0x00, 0x18, 0x80, 0x72, 0x00, 0x00, 0x2c, 0x03, 0x00, 0x02, 0x40, 0x82, 0x00, 0x0c, 0x41, 0x96, - 0x00, 0x0c, 0x48, 0x00, 0x00, 0x20, 0x38, 0x60, 0x00, 0x00, 0x90, 0x6c, 0x00, 0x0c, 0x40, 0x82, 0x00, 0x14, - 0x40, 0x96, 0x00, 0x10, 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x02, 0x70, 0x55, 0x29, - 0x05, 0xa8, 0x91, 0x24, 0x00, 0x18, 0x41, 0x96, 0x04, 0xac, 0x41, 0x9a, 0x00, 0x08, 0x39, 0x8c, 0x00, 0x04, - 0x38, 0x60, 0x00, 0x04, 0x48, 0x00, 0x03, 0x61, 0x40, 0x99, 0x00, 0x10, 0x39, 0x8c, 0x00, 0x04, 0x38, 0x60, - 0x00, 0x04, 0x48, 0x00, 0x03, 0x51, 0x63, 0xe4, 0x26, 0xb4, 0x80, 0x64, 0x00, 0x00, 0x80, 0x84, 0x00, 0x04, - 0x7c, 0x72, 0xfb, 0xa6, 0x7c, 0x95, 0xfb, 0xa6, 0x48, 0x00, 0x04, 0x74, 0x7c, 0x32, 0x43, 0xa6, 0x7c, 0x3a, - 0x02, 0xa6, 0x7c, 0x73, 0x43, 0xa6, 0x7c, 0x7b, 0x02, 0xa6, 0x54, 0x63, 0x05, 0xa8, 0x90, 0x60, 0x26, 0xdc, - 0x54, 0x63, 0x06, 0x20, 0x60, 0x63, 0x20, 0x00, 0x54, 0x63, 0x04, 0x5e, 0x7c, 0x7b, 0x03, 0xa6, 0x3c, 0x60, - 0x80, 0x00, 0x60, 0x63, 0x1a, 0xf4, 0x7c, 0x7a, 0x03, 0xa6, 0x4c, 0x00, 0x01, 0x2c, 0x7c, 0x00, 0x04, 0xac, - 0x4c, 0x00, 0x00, 0x64, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x26, 0xc4, 0x90, 0x23, 0x00, 0x14, 0x7c, 0x61, - 0x1b, 0x78, 0x7c, 0x73, 0x42, 0xa6, 0xbc, 0x41, 0x00, 0x24, 0x7c, 0x24, 0x0b, 0x78, 0x7c, 0x32, 0x42, 0xa6, - 0x90, 0x04, 0x00, 0x1c, 0x90, 0x24, 0x00, 0x20, 0x7c, 0x68, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x9c, 0x7c, 0x60, - 0x00, 0x26, 0x90, 0x64, 0x00, 0x00, 0x7c, 0x61, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x04, 0x7c, 0x69, 0x02, 0xa6, - 0x90, 0x64, 0x00, 0x08, 0x7c, 0x72, 0x02, 0xa6, 0x90, 0x64, 0x00, 0x0c, 0x7c, 0x73, 0x02, 0xa6, 0x90, 0x64, - 0x00, 0x10, 0x39, 0x20, 0x00, 0x00, 0x7d, 0x32, 0xfb, 0xa6, 0x7d, 0x35, 0xfb, 0xa6, 0xd0, 0x04, 0x00, 0xa0, - 0xd0, 0x24, 0x00, 0xa4, 0xd0, 0x44, 0x00, 0xa8, 0xd0, 0x64, 0x00, 0xac, 0xd0, 0x84, 0x00, 0xb0, 0xd0, 0xa4, - 0x00, 0xb4, 0xd0, 0xc4, 0x00, 0xb8, 0xd0, 0xe4, 0x00, 0xbc, 0xd1, 0x04, 0x00, 0xc0, 0xd1, 0x24, 0x00, 0xc4, - 0xd1, 0x44, 0x00, 0xc8, 0xd1, 0x64, 0x00, 0xcc, 0xd1, 0x84, 0x00, 0xd0, 0xd1, 0xa4, 0x00, 0xd4, 0xd1, 0xc4, - 0x00, 0xd8, 0xd1, 0xe4, 0x00, 0xdc, 0xd2, 0x04, 0x00, 0xe0, 0xd2, 0x24, 0x00, 0xe4, 0xd2, 0x44, 0x00, 0xe8, - 0xd2, 0x64, 0x00, 0xec, 0xd2, 0x84, 0x00, 0xf0, 0xd2, 0xa4, 0x00, 0xf4, 0xd2, 0xc4, 0x00, 0xf8, 0xd2, 0xe4, - 0x00, 0xfc, 0xd3, 0x04, 0x01, 0x00, 0xd3, 0x24, 0x01, 0x04, 0xd3, 0x44, 0x01, 0x08, 0xd3, 0x64, 0x01, 0x0c, - 0xd3, 0x84, 0x01, 0x10, 0xd3, 0xa4, 0x01, 0x14, 0xd3, 0xc4, 0x01, 0x18, 0xd3, 0xe4, 0x01, 0x1c, 0x3f, 0xe0, - 0x80, 0x00, 0x63, 0xe5, 0x26, 0xb4, 0x82, 0x05, 0x00, 0x00, 0x82, 0x25, 0x00, 0x04, 0x82, 0x65, 0x00, 0x0c, - 0x2c, 0x13, 0x00, 0x00, 0x41, 0x82, 0x00, 0x74, 0x2c, 0x13, 0x00, 0x02, 0x40, 0x82, 0x00, 0x18, 0x81, 0x24, - 0x00, 0x14, 0x39, 0x33, 0x00, 0x03, 0x91, 0x25, 0x00, 0x00, 0x91, 0x25, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x6c, - 0x7c, 0x10, 0x98, 0x00, 0x41, 0x82, 0x00, 0x38, 0x7c, 0x11, 0x98, 0x00, 0x41, 0x82, 0x00, 0x30, 0x7d, 0x30, - 0x8a, 0x14, 0x91, 0x25, 0x00, 0x0c, 0x82, 0x05, 0x00, 0x08, 0x2c, 0x10, 0x00, 0x00, 0x41, 0x82, 0x00, 0x48, - 0x80, 0x64, 0x00, 0x10, 0x7c, 0x10, 0x18, 0x00, 0x40, 0x82, 0x00, 0x10, 0x3a, 0x00, 0x00, 0x00, 0x92, 0x05, - 0x00, 0x08, 0x48, 0x00, 0x00, 0x30, 0x3a, 0x20, 0x00, 0x00, 0x92, 0x25, 0x00, 0x0c, 0x81, 0x24, 0x00, 0x18, - 0x61, 0x29, 0x04, 0x00, 0x91, 0x24, 0x00, 0x18, 0x48, 0x00, 0x00, 0x30, 0x7e, 0x12, 0xfb, 0xa6, 0x7e, 0x35, - 0xfb, 0xa6, 0x39, 0x20, 0x00, 0x01, 0x91, 0x25, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x1c, 0x38, 0xa0, 0x00, 0x02, - 0x63, 0xe4, 0x26, 0xa0, 0x90, 0xa4, 0x00, 0x00, 0x38, 0x60, 0x00, 0x11, 0x48, 0x00, 0x01, 0xbd, 0x4b, 0xff, - 0xfc, 0x1d, 0x7c, 0x20, 0x00, 0xa6, 0x54, 0x21, 0x07, 0xfa, 0x54, 0x21, 0x04, 0x5e, 0x7c, 0x20, 0x01, 0x24, - 0x63, 0xe1, 0x26, 0xc4, 0x80, 0x61, 0x00, 0x00, 0x7c, 0x6f, 0xf1, 0x20, 0x80, 0x61, 0x00, 0x14, 0x7c, 0x7a, - 0x03, 0xa6, 0x80, 0x61, 0x00, 0x18, 0x7c, 0x7b, 0x03, 0xa6, 0x80, 0x61, 0x00, 0x9c, 0x7c, 0x68, 0x03, 0xa6, - 0xb8, 0x41, 0x00, 0x24, 0x80, 0x01, 0x00, 0x1c, 0x80, 0x21, 0x00, 0x20, 0x4c, 0x00, 0x01, 0x2c, 0x7c, 0x00, - 0x04, 0xac, 0x4c, 0x00, 0x00, 0x64, 0x92, 0xb2, 0x00, 0x00, 0x48, 0x00, 0x02, 0x50, 0x2e, 0x9d, 0x00, 0x02, - 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x26, 0xa8, 0x48, 0x00, 0x00, 0xf9, 0x80, 0xac, 0x00, 0x00, 0x80, 0x6c, - 0x00, 0x04, 0x98, 0x65, 0x00, 0x00, 0x41, 0x94, 0x00, 0x10, 0xb0, 0x65, 0x00, 0x00, 0x41, 0x96, 0x00, 0x08, - 0x90, 0x65, 0x00, 0x00, 0x7c, 0x00, 0x28, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x2f, 0xac, 0x4c, 0x00, - 0x01, 0x2c, 0x48, 0x00, 0x02, 0x04, 0x48, 0x00, 0x01, 0x1d, 0x38, 0x60, 0x00, 0x04, 0x63, 0xec, 0x26, 0xa8, - 0x48, 0x00, 0x00, 0xb9, 0x82, 0x0c, 0x00, 0x00, 0x63, 0xec, 0x27, 0xe8, 0x48, 0x00, 0x00, 0x1c, 0x48, 0x00, - 0x01, 0x01, 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x26, 0xa8, 0x48, 0x00, 0x00, 0x9d, 0x82, 0x0c, 0x00, 0x04, - 0x81, 0x8c, 0x00, 0x00, 0x63, 0xfb, 0x26, 0xb0, 0x3a, 0x20, 0x0f, 0x80, 0x48, 0x00, 0x02, 0x3d, 0x41, 0x82, - 0x00, 0x20, 0x7e, 0x23, 0x8b, 0x78, 0x48, 0x00, 0x00, 0x7d, 0x48, 0x00, 0x00, 0xd1, 0x41, 0x82, 0xff, 0xfc, - 0x7d, 0x8c, 0x72, 0x14, 0x35, 0x6b, 0xff, 0xff, 0x41, 0x81, 0xff, 0xe8, 0x80, 0x7b, 0x00, 0x00, 0x2c, 0x03, - 0x00, 0x00, 0x41, 0x82, 0x00, 0x08, 0x48, 0x00, 0x00, 0x59, 0x7c, 0x00, 0x60, 0xac, 0x7c, 0x00, 0x04, 0xac, - 0x7c, 0x00, 0x67, 0xac, 0x4c, 0x00, 0x01, 0x2c, 0x48, 0x00, 0x01, 0x80, 0x7f, 0xc8, 0x02, 0xa6, 0x3c, 0x60, - 0xa0, 0x00, 0x48, 0x00, 0x00, 0x15, 0x76, 0x03, 0x08, 0x00, 0x56, 0x1d, 0x86, 0x3e, 0x7f, 0xc8, 0x03, 0xa6, - 0x4e, 0x80, 0x00, 0x20, 0x92, 0xf8, 0x68, 0x14, 0x90, 0x78, 0x68, 0x24, 0x92, 0xd8, 0x68, 0x20, 0x80, 0xb8, - 0x68, 0x20, 0x70, 0xa5, 0x00, 0x01, 0x40, 0x82, 0xff, 0xf8, 0x82, 0x18, 0x68, 0x24, 0x90, 0xb8, 0x68, 0x14, - 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x48, 0x02, 0xa6, 0x7c, 0x69, 0x03, 0xa6, 0x39, 0xc0, 0x00, 0x00, 0x48, 0x00, - 0x00, 0x79, 0x48, 0x00, 0x00, 0x75, 0x4b, 0xff, 0xff, 0xad, 0x41, 0x82, 0xff, 0xf4, 0x7f, 0xae, 0x61, 0xae, - 0x39, 0xce, 0x00, 0x01, 0x42, 0x00, 0xff, 0xe8, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x48, - 0x02, 0xa6, 0x7c, 0x69, 0x03, 0xa6, 0x39, 0xc0, 0x00, 0x00, 0x7c, 0x6c, 0x70, 0xae, 0x48, 0x00, 0x00, 0x1d, - 0x41, 0x82, 0xff, 0xf8, 0x39, 0xce, 0x00, 0x01, 0x42, 0x00, 0xff, 0xf0, 0x7d, 0x48, 0x03, 0xa6, 0x4e, 0x80, - 0x00, 0x20, 0x38, 0x60, 0x00, 0xaa, 0x7f, 0xc8, 0x02, 0xa6, 0x54, 0x63, 0xa0, 0x16, 0x64, 0x63, 0xb0, 0x00, - 0x3a, 0xc0, 0x00, 0x19, 0x3a, 0xe0, 0x00, 0xd0, 0x3f, 0x00, 0xcd, 0x00, 0x4b, 0xff, 0xff, 0x69, 0x56, 0x03, - 0x37, 0xff, 0x7f, 0xc8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x7f, 0xc8, 0x02, 0xa6, 0x3c, 0x60, 0xd0, 0x00, - 0x4b, 0xff, 0xff, 0x51, 0x56, 0x03, 0x37, 0xff, 0x41, 0x82, 0xff, 0xf4, 0x7f, 0xc8, 0x03, 0xa6, 0x4e, 0x80, - 0x00, 0x20, 0x4b, 0xff, 0xff, 0xb9, 0x38, 0x60, 0x00, 0x08, 0x63, 0xec, 0x26, 0xa8, 0x4b, 0xff, 0xff, 0x55, - 0x80, 0xac, 0x00, 0x04, 0x81, 0x8c, 0x00, 0x00, 0x63, 0xfb, 0x26, 0xb0, 0x62, 0xb1, 0xf8, 0x00, 0x7e, 0x0c, - 0x28, 0x50, 0x48, 0x00, 0x00, 0xf1, 0x41, 0x81, 0x00, 0x10, 0x82, 0x3b, 0x00, 0x00, 0x2c, 0x11, 0x00, 0x00, - 0x41, 0x82, 0x00, 0x68, 0x7e, 0x23, 0x8b, 0x78, 0x4b, 0xff, 0xff, 0x55, 0x4b, 0xff, 0xff, 0xa5, 0x4b, 0xff, - 0xff, 0xa1, 0x4b, 0xff, 0xfe, 0xd9, 0x41, 0x82, 0xff, 0xf4, 0x2c, 0x1d, 0x00, 0xcc, 0x41, 0x82, 0x00, 0x48, - 0x2c, 0x1d, 0x00, 0xbb, 0x41, 0x82, 0xff, 0xdc, 0x2c, 0x1d, 0x00, 0xaa, 0x40, 0x82, 0xff, 0xdc, 0x7d, 0x8c, - 0x72, 0x14, 0x35, 0x6b, 0xff, 0xff, 0x41, 0x80, 0x00, 0x2c, 0x4b, 0xff, 0xff, 0xb4, 0x7e, 0xb5, 0xfb, 0xa6, - 0x7e, 0xb2, 0xfb, 0xa6, 0x63, 0xe4, 0x26, 0xc4, 0x81, 0x24, 0x00, 0x18, 0x55, 0x29, 0x05, 0xa8, 0x91, 0x24, - 0x00, 0x18, 0x48, 0x00, 0x00, 0x0c, 0x38, 0x60, 0x00, 0x80, 0x4b, 0xff, 0xff, 0x25, 0x80, 0x92, 0x00, 0x00, - 0x2c, 0x04, 0x00, 0x00, 0x40, 0x82, 0xf9, 0xf8, 0xb3, 0x94, 0x40, 0x10, 0xc8, 0x41, 0x00, 0x98, 0xc8, 0x61, - 0x00, 0xa0, 0x7f, 0x20, 0x00, 0xa6, 0x80, 0x01, 0x00, 0xac, 0x7c, 0x08, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x0c, - 0x7c, 0x0f, 0xf1, 0x20, 0x80, 0x01, 0x00, 0x10, 0x7c, 0x09, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x14, 0x7c, 0x01, - 0x03, 0xa6, 0xb8, 0x61, 0x00, 0x18, 0x80, 0x01, 0x00, 0x08, 0x38, 0x21, 0x00, 0xa8, 0x4c, 0x00, 0x01, 0x2c, - 0x7c, 0x00, 0x04, 0xac, 0x4e, 0x80, 0x00, 0x20, 0x7e, 0x23, 0x20, 0x50, 0x3c, 0xa0, 0x48, 0x00, 0x52, 0x25, - 0x01, 0xba, 0x90, 0xa3, 0x00, 0x00, 0x7c, 0x00, 0x18, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x1f, 0xac, - 0x4c, 0x00, 0x01, 0x2c, 0x4e, 0x80, 0x00, 0x20, 0x7d, 0x70, 0x8b, 0xd7, 0x7d, 0x4b, 0x89, 0xd6, 0x7d, 0x4a, - 0x80, 0x50, 0x91, 0x5b, 0x00, 0x00, 0x4e, 0x80, 0x00, 0x20, 0x7f, 0xa8, 0x02, 0xa6, 0x63, 0xef, 0x27, 0xe8, - 0x63, 0xe7, 0x18, 0x08, 0x3c, 0xc0, 0x80, 0x00, 0x7c, 0xd0, 0x33, 0x78, 0x39, 0x00, 0x00, 0x00, 0x3c, 0x60, - 0x00, 0xd0, 0x60, 0x63, 0xc0, 0xde, 0x80, 0x8f, 0x00, 0x00, 0x7c, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x18, - 0x80, 0x8f, 0x00, 0x04, 0x7c, 0x03, 0x20, 0x00, 0x40, 0x82, 0x00, 0x0c, 0x39, 0xef, 0x00, 0x08, 0x48, 0x00, - 0x00, 0x0c, 0x7f, 0xa8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x80, 0x6f, 0x00, 0x00, 0x80, 0x8f, 0x00, 0x04, - 0x39, 0xef, 0x00, 0x08, 0x71, 0x09, 0x00, 0x01, 0x2f, 0x89, 0x00, 0x00, 0x39, 0x20, 0x00, 0x00, 0x54, 0x6a, - 0x1f, 0x7e, 0x54, 0x65, 0x3f, 0x7e, 0x74, 0x6b, 0x10, 0x00, 0x54, 0x63, 0x01, 0xfe, 0x40, 0x82, 0x00, 0x0c, - 0x54, 0xcc, 0x00, 0x0c, 0x48, 0x00, 0x00, 0x08, 0x7e, 0x0c, 0x83, 0x78, 0x2e, 0x05, 0x00, 0x00, 0x2c, 0x0a, - 0x00, 0x01, 0x41, 0xa0, 0x00, 0x2c, 0x41, 0xa2, 0x00, 0xe4, 0x2c, 0x0a, 0x00, 0x03, 0x41, 0xa0, 0x01, 0xb0, - 0x41, 0x82, 0x02, 0x54, 0x2c, 0x0a, 0x00, 0x05, 0x41, 0x80, 0x02, 0xdc, 0x41, 0xa2, 0x04, 0xe8, 0x2c, 0x0a, - 0x00, 0x07, 0x41, 0xa0, 0x05, 0x14, 0x48, 0x00, 0x05, 0xf8, 0x7d, 0x8c, 0x1a, 0x14, 0x2c, 0x05, 0x00, 0x03, - 0x41, 0x82, 0x00, 0x48, 0x41, 0x81, 0x00, 0x60, 0x40, 0xbe, 0xff, 0x84, 0x2e, 0x05, 0x00, 0x01, 0x41, 0x91, - 0x00, 0x2c, 0x54, 0x8a, 0x84, 0x3e, 0x41, 0x92, 0x00, 0x10, 0x7c, 0x89, 0x61, 0xae, 0x39, 0x29, 0x00, 0x01, - 0x48, 0x00, 0x00, 0x0c, 0x7c, 0x89, 0x63, 0x2e, 0x39, 0x29, 0x00, 0x02, 0x35, 0x4a, 0xff, 0xff, 0x40, 0xa0, - 0xff, 0xe4, 0x4b, 0xff, 0xff, 0x54, 0x55, 0x8c, 0x00, 0x3a, 0x90, 0x8c, 0x00, 0x00, 0x4b, 0xff, 0xff, 0x48, - 0x7c, 0x89, 0x23, 0x78, 0x40, 0x9e, 0x04, 0xd0, 0x35, 0x29, 0xff, 0xff, 0x41, 0x80, 0x04, 0xc8, 0x7c, 0xa9, - 0x78, 0xae, 0x7c, 0xa9, 0x61, 0xae, 0x4b, 0xff, 0xff, 0xf0, 0x39, 0xef, 0x00, 0x08, 0x40, 0xbe, 0xff, 0x24, - 0x80, 0xaf, 0xff, 0xf8, 0x81, 0x6f, 0xff, 0xfc, 0x54, 0xb1, 0x04, 0x3e, 0x54, 0xaa, 0x85, 0x3e, 0x54, 0xa5, - 0x27, 0x3e, 0x2e, 0x85, 0x00, 0x01, 0x41, 0x96, 0x00, 0x10, 0x41, 0xb5, 0x00, 0x14, 0x7c, 0x89, 0x61, 0xae, - 0x48, 0x00, 0x00, 0x10, 0x7c, 0x89, 0x63, 0x2e, 0x48, 0x00, 0x00, 0x08, 0x7c, 0x89, 0x61, 0x2e, 0x7c, 0x84, - 0x5a, 0x14, 0x7d, 0x29, 0x8a, 0x14, 0x35, 0x4a, 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4, 0x4b, 0xff, 0xfe, 0xdc, - 0x54, 0x69, 0x07, 0xff, 0x41, 0x82, 0x00, 0x10, 0x55, 0x08, 0xf8, 0x7e, 0x71, 0x09, 0x00, 0x01, 0x2f, 0x89, - 0x00, 0x00, 0x2e, 0x85, 0x00, 0x04, 0x2d, 0x8a, 0x00, 0x05, 0x7d, 0x13, 0x43, 0x78, 0x52, 0x68, 0x08, 0x3c, - 0x40, 0x9e, 0x00, 0x78, 0x41, 0x8d, 0x04, 0xbc, 0x7d, 0x8c, 0x1a, 0x14, 0x41, 0x8c, 0x00, 0x0c, 0x41, 0x94, - 0x00, 0x30, 0x48, 0x00, 0x00, 0x1c, 0x40, 0x94, 0x00, 0x10, 0x55, 0x8c, 0x00, 0x3a, 0x81, 0x6c, 0x00, 0x00, - 0x48, 0x00, 0x00, 0x1c, 0x55, 0x8c, 0x00, 0x3c, 0xa1, 0x6c, 0x00, 0x00, 0x7c, 0x89, 0x20, 0xf8, 0x55, 0x29, - 0x84, 0x3e, 0x7d, 0x6b, 0x48, 0x38, 0x54, 0x84, 0x04, 0x3e, 0x7f, 0x0b, 0x20, 0x40, 0x70, 0xa9, 0x00, 0x03, - 0x41, 0x82, 0x00, 0x18, 0x2c, 0x09, 0x00, 0x02, 0x41, 0x82, 0x00, 0x18, 0x41, 0x81, 0x00, 0x1c, 0x40, 0x9a, - 0x00, 0x20, 0x48, 0x00, 0x00, 0x18, 0x41, 0x9a, 0x00, 0x18, 0x48, 0x00, 0x00, 0x10, 0x41, 0x99, 0x00, 0x10, - 0x48, 0x00, 0x00, 0x08, 0x41, 0x98, 0x00, 0x08, 0x61, 0x08, 0x00, 0x01, 0x40, 0x8e, 0xfe, 0x3c, 0x41, 0x94, - 0xfe, 0x38, 0x81, 0x6f, 0xff, 0xf8, 0x40, 0x9e, 0x00, 0x20, 0x70, 0x6c, 0x00, 0x08, 0x41, 0x82, 0x00, 0x0c, - 0x71, 0x0c, 0x00, 0x01, 0x41, 0x82, 0x00, 0x10, 0x39, 0x8b, 0x00, 0x10, 0x51, 0x8b, 0x03, 0x36, 0x48, 0x00, - 0x00, 0x08, 0x55, 0x6b, 0x07, 0x16, 0x91, 0x6f, 0xff, 0xf8, 0x4b, 0xff, 0xfe, 0x08, 0x40, 0xbe, 0xfe, 0x04, - 0x54, 0x69, 0x16, 0xba, 0x54, 0x6e, 0x87, 0xfe, 0x2d, 0x8e, 0x00, 0x00, 0x2e, 0x05, 0x00, 0x04, 0x70, 0xae, - 0x00, 0x03, 0x2e, 0x8e, 0x00, 0x02, 0x41, 0x94, 0x00, 0x14, 0x41, 0x96, 0x00, 0x50, 0x7c, 0x64, 0x07, 0x34, - 0x7c, 0x84, 0x7a, 0x14, 0x48, 0x00, 0x00, 0x68, 0x54, 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, - 0x48, 0x2e, 0x7c, 0x84, 0x4a, 0x14, 0x41, 0x8e, 0x00, 0x08, 0x7c, 0x8c, 0x22, 0x14, 0x2e, 0x8e, 0x00, 0x01, - 0x41, 0x96, 0x00, 0x08, 0x80, 0x84, 0x00, 0x00, 0x54, 0x63, 0x67, 0xff, 0x41, 0x82, 0x00, 0x3c, 0x40, 0x90, - 0x00, 0x0c, 0x7c, 0x84, 0x32, 0x14, 0x48, 0x00, 0x00, 0x30, 0x7c, 0x84, 0x82, 0x14, 0x48, 0x00, 0x00, 0x28, - 0x54, 0x65, 0xa7, 0xff, 0x41, 0x82, 0x00, 0x0c, 0x7d, 0x27, 0x48, 0x2e, 0x7c, 0x84, 0x4a, 0x14, 0x40, 0x90, - 0x00, 0x0c, 0x7c, 0xcc, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x7c, 0x7e, 0x0c, 0x21, 0x2e, 0x4b, 0xff, 0xfd, 0x74, - 0x40, 0x90, 0x00, 0x0c, 0x7c, 0x86, 0x23, 0x78, 0x4b, 0xff, 0xfd, 0x68, 0x7c, 0x90, 0x23, 0x78, 0x4b, 0xff, - 0xfd, 0x60, 0x54, 0x89, 0x1e, 0x78, 0x39, 0x29, 0x00, 0x40, 0x2c, 0x05, 0x00, 0x02, 0x41, 0x80, 0x00, 0x4c, - 0x54, 0x6b, 0x67, 0xbf, 0x2c, 0x0b, 0x00, 0x01, 0x41, 0x80, 0x00, 0x14, 0x41, 0x82, 0x00, 0x08, 0x48, 0x00, - 0x00, 0x10, 0x41, 0xbe, 0xfd, 0x38, 0x48, 0x00, 0x00, 0x08, 0x40, 0xbe, 0xfd, 0x30, 0x2c, 0x05, 0x00, 0x03, - 0x41, 0x81, 0x00, 0x10, 0x41, 0xa2, 0x00, 0x10, 0x7d, 0xe7, 0x48, 0x2e, 0x4b, 0xff, 0xfd, 0x1c, 0x7d, 0xe7, - 0x49, 0x2e, 0x7c, 0x64, 0x07, 0x34, 0x54, 0x84, 0x1a, 0x78, 0x7d, 0xef, 0x22, 0x14, 0x4b, 0xff, 0xfd, 0x08, - 0x40, 0xbe, 0xfd, 0x04, 0x7c, 0xa7, 0x4a, 0x14, 0x40, 0x92, 0x00, 0x14, 0x54, 0x64, 0x04, 0x3e, 0x91, 0xe5, - 0x00, 0x00, 0x90, 0x85, 0x00, 0x04, 0x4b, 0xff, 0xfc, 0xec, 0x81, 0x25, 0x00, 0x04, 0x2c, 0x09, 0x00, 0x00, - 0x41, 0xa2, 0xfc, 0xe0, 0x39, 0x29, 0xff, 0xff, 0x91, 0x25, 0x00, 0x04, 0x81, 0xe5, 0x00, 0x00, 0x4b, 0xff, - 0xfc, 0xd0, 0x40, 0xbe, 0xfc, 0xcc, 0x54, 0x6b, 0x16, 0xba, 0x7f, 0x47, 0x5a, 0x14, 0x81, 0x3a, 0x00, 0x00, - 0x54, 0x6e, 0x67, 0xbe, 0x41, 0x92, 0x00, 0x84, 0x2e, 0x05, 0x00, 0x05, 0x40, 0x90, 0x01, 0x74, 0x2e, 0x05, - 0x00, 0x03, 0x40, 0x90, 0x00, 0x90, 0x2e, 0x05, 0x00, 0x01, 0x54, 0x65, 0x87, 0xff, 0x41, 0x82, 0x00, 0x08, - 0x7c, 0x8c, 0x22, 0x14, 0x2f, 0x0e, 0x00, 0x01, 0x40, 0x92, 0x00, 0x24, 0x41, 0xb9, 0x00, 0x18, 0x41, 0x9a, - 0x00, 0x0c, 0x88, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xf8, 0xa0, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xf0, - 0x80, 0x84, 0x00, 0x00, 0x48, 0x00, 0x00, 0xe8, 0x54, 0x73, 0xe5, 0x3e, 0x41, 0xb9, 0x00, 0x20, 0x41, 0x9a, - 0x00, 0x10, 0x99, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x01, 0x48, 0x00, 0x00, 0x18, 0xb1, 0x24, 0x00, 0x00, - 0x38, 0x84, 0x00, 0x02, 0x48, 0x00, 0x00, 0x0c, 0x91, 0x24, 0x00, 0x00, 0x38, 0x84, 0x00, 0x04, 0x36, 0x73, - 0xff, 0xff, 0x40, 0x80, 0xff, 0xd4, 0x4b, 0xff, 0xfc, 0x38, 0x54, 0x65, 0x87, 0xff, 0x41, 0x82, 0x00, 0x08, - 0x7c, 0x84, 0x62, 0x14, 0x71, 0xc5, 0x00, 0x01, 0x41, 0x82, 0x00, 0x9c, 0x7c, 0x84, 0x4a, 0x14, 0x48, 0x00, - 0x00, 0x94, 0x54, 0x6a, 0x87, 0xbe, 0x54, 0x8e, 0x16, 0xba, 0x7e, 0x67, 0x72, 0x14, 0x40, 0x92, 0x00, 0x08, - 0x3a, 0x6f, 0xff, 0xfc, 0x80, 0x9a, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x71, 0x4b, 0x00, 0x01, 0x41, 0x82, - 0x00, 0x08, 0x7c, 0x9a, 0x23, 0x78, 0x71, 0x4b, 0x00, 0x02, 0x41, 0x82, 0x00, 0x10, 0x7d, 0x33, 0x4b, 0x78, - 0x40, 0xb2, 0x00, 0x08, 0x7e, 0x6c, 0x9a, 0x14, 0x54, 0x65, 0x67, 0x3f, 0x2c, 0x05, 0x00, 0x09, 0x40, 0x80, - 0x00, 0x54, 0x48, 0x00, 0x00, 0x79, 0x7c, 0x89, 0x22, 0x14, 0x48, 0x00, 0x00, 0x40, 0x7c, 0x89, 0x21, 0xd6, - 0x48, 0x00, 0x00, 0x38, 0x7d, 0x24, 0x23, 0x78, 0x48, 0x00, 0x00, 0x30, 0x7d, 0x24, 0x20, 0x38, 0x48, 0x00, - 0x00, 0x28, 0x7d, 0x24, 0x22, 0x78, 0x48, 0x00, 0x00, 0x20, 0x7d, 0x24, 0x20, 0x30, 0x48, 0x00, 0x00, 0x18, - 0x7d, 0x24, 0x24, 0x30, 0x48, 0x00, 0x00, 0x10, 0x5d, 0x24, 0x20, 0x3e, 0x48, 0x00, 0x00, 0x08, 0x7d, 0x24, - 0x26, 0x30, 0x90, 0x9a, 0x00, 0x00, 0x4b, 0xff, 0xfb, 0x84, 0x2c, 0x05, 0x00, 0x0a, 0x41, 0x81, 0xfb, 0x7c, - 0xc0, 0x5a, 0x00, 0x00, 0xc0, 0x73, 0x00, 0x00, 0x41, 0x82, 0x00, 0x0c, 0xec, 0x43, 0x10, 0x2a, 0x48, 0x00, - 0x00, 0x08, 0xec, 0x43, 0x00, 0xb2, 0xd0, 0x5a, 0x00, 0x00, 0x4b, 0xff, 0xfb, 0x5c, 0x7d, 0x48, 0x02, 0xa6, - 0x54, 0xa5, 0x1e, 0x78, 0x7d, 0x4a, 0x2a, 0x14, 0x80, 0x9a, 0x00, 0x00, 0x81, 0x33, 0x00, 0x00, 0x7d, 0x48, - 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x20, 0x40, 0xbe, 0xfb, 0x3c, 0x54, 0x69, 0xc0, 0x3e, 0x7d, 0x8e, 0x63, 0x78, - 0x48, 0x00, 0x00, 0x35, 0x41, 0x92, 0x00, 0x0c, 0x7e, 0x31, 0x22, 0x14, 0x48, 0x00, 0x00, 0x08, 0x7d, 0x29, - 0x22, 0x14, 0x54, 0x64, 0xc4, 0x3f, 0x38, 0xa0, 0x00, 0x00, 0x41, 0x82, 0xfb, 0x14, 0x7d, 0x45, 0x88, 0xae, - 0x7d, 0x45, 0x49, 0xae, 0x38, 0xa5, 0x00, 0x01, 0x7c, 0x05, 0x20, 0x00, 0x4b, 0xff, 0xff, 0xec, 0x2e, 0x8a, - 0x00, 0x04, 0x55, 0x31, 0x36, 0xba, 0x2c, 0x11, 0x00, 0x3c, 0x7e, 0x27, 0x88, 0x2e, 0x40, 0x82, 0x00, 0x08, - 0x7d, 0xd1, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, 0xa2, 0x31, 0x00, 0x00, 0x55, 0x29, 0x56, 0xba, 0x2c, 0x09, - 0x00, 0x3c, 0x7d, 0x27, 0x48, 0x2e, 0x40, 0x82, 0x00, 0x08, 0x7d, 0xc9, 0x73, 0x78, 0x41, 0x96, 0x00, 0x08, - 0xa1, 0x29, 0x00, 0x00, 0x4e, 0x80, 0x00, 0x20, 0x2c, 0x05, 0x00, 0x04, 0x40, 0x80, 0x00, 0x28, 0x7c, 0x89, - 0x23, 0x78, 0x7d, 0xc3, 0x62, 0x14, 0x55, 0xce, 0x00, 0x3c, 0x4b, 0xff, 0xff, 0xad, 0x7c, 0x84, 0x20, 0xf8, - 0x54, 0x84, 0x04, 0x3e, 0x7d, 0x2b, 0x20, 0x38, 0x7e, 0x24, 0x20, 0x38, 0x4b, 0xff, 0xfb, 0xbc, 0x54, 0x6b, - 0xe4, 0x3e, 0x4b, 0xff, 0xfb, 0xb4, 0x7c, 0x9a, 0x23, 0x78, 0x54, 0x84, 0x18, 0x38, 0x40, 0x92, 0x00, 0x20, - 0x40, 0x9e, 0x00, 0x0c, 0x7d, 0xe8, 0x03, 0xa6, 0x4e, 0x80, 0x00, 0x21, 0x7d, 0xe4, 0x7a, 0x14, 0x39, 0xef, - 0x00, 0x07, 0x55, 0xef, 0x00, 0x38, 0x4b, 0xff, 0xfa, 0x64, 0x2e, 0x05, 0x00, 0x03, 0x41, 0x91, 0x00, 0x5c, - 0x3c, 0xa0, 0x48, 0x00, 0x7d, 0x83, 0x62, 0x14, 0x55, 0x8c, 0x00, 0x3a, 0x40, 0x92, 0x00, 0x20, 0x40, 0xbe, - 0xfa, 0x48, 0x57, 0x44, 0x00, 0x3a, 0x7c, 0x8c, 0x20, 0x50, 0x50, 0x85, 0x01, 0xba, 0x50, 0x65, 0x07, 0xfe, - 0x90, 0xac, 0x00, 0x00, 0x4b, 0xff, 0xfa, 0x30, 0x40, 0xbe, 0xff, 0xbc, 0x7d, 0x2c, 0x78, 0x50, 0x51, 0x25, - 0x01, 0xba, 0x90, 0xac, 0x00, 0x00, 0x39, 0x8c, 0x00, 0x04, 0x7d, 0x6f, 0x22, 0x14, 0x39, 0x6b, 0xff, 0xfc, - 0x7d, 0x2b, 0x60, 0x50, 0x51, 0x25, 0x01, 0xba, 0x90, 0xab, 0x00, 0x00, 0x4b, 0xff, 0xff, 0x94, 0x2e, 0x05, - 0x00, 0x06, 0x41, 0x92, 0x00, 0x28, 0x4b, 0xff, 0xfb, 0x20, 0x55, 0x8c, 0x84, 0x3e, 0x57, 0x44, 0x84, 0x3e, - 0x57, 0x5a, 0x04, 0x3e, 0x7c, 0x0c, 0x20, 0x00, 0x41, 0x80, 0xfb, 0xa4, 0x7c, 0x0c, 0xd0, 0x00, 0x40, 0x80, - 0xfb, 0x9c, 0x4b, 0xff, 0xf9, 0xd8, 0x57, 0x45, 0xff, 0xfe, 0x68, 0xa5, 0x00, 0x01, 0x71, 0x03, 0x00, 0x01, - 0x7c, 0x05, 0x18, 0x00, 0x41, 0x82, 0x00, 0x1c, 0x51, 0x1a, 0x0f, 0xbc, 0x6b, 0x5a, 0x00, 0x02, 0x57, 0x45, - 0xff, 0xff, 0x41, 0x82, 0x00, 0x08, 0x6b, 0x5a, 0x00, 0x01, 0x93, 0x4f, 0xff, 0xfc, 0x53, 0x48, 0x07, 0xfe, - 0x4b, 0xff, 0xf9, 0xa4, 0x2c, 0x0b, 0x00, 0x00, 0x40, 0x82, 0xf9, 0x94, 0x40, 0x92, 0x00, 0x0c, 0x39, 0x00, - 0x00, 0x00, 0x48, 0x00, 0x00, 0x14, 0x54, 0x69, 0x06, 0xff, 0x40, 0x82, 0x00, 0x08, 0x40, 0x9e, 0x00, 0x10, - 0x54, 0x65, 0x67, 0xfe, 0x7d, 0x08, 0x4c, 0x30, 0x7d, 0x08, 0x2a, 0x78, 0x54, 0x85, 0x00, 0x1f, 0x41, 0x82, - 0x00, 0x08, 0x7c, 0xa6, 0x2b, 0x78, 0x54, 0x85, 0x80, 0x1f, 0x41, 0x82, 0x00, 0x08, 0x7c, 0xb0, 0x2b, 0x78, - 0x4b, 0xff, 0xf9, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -}; -const int kenobiwii_size = sizeof(kenobiwii); diff --git a/source/patches/multidol.c b/source/patches/multidol.c deleted file mode 100644 index 1061858b..00000000 --- a/source/patches/multidol.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file was autogenerated by raw2c. - Visit http://www.devkitpro.org - */ - -const unsigned char multidol[] = { 0x7f, 0xe8, 0x03, 0xa6, 0x7c, 0x08, 0x02, 0xa6, 0x90, 0x01, 0x00, 0xac, 0x7c, 0x00, - 0x00, 0x26, 0x90, 0x01, 0x00, 0x0c, 0x7c, 0x09, 0x02, 0xa6, 0x90, 0x01, 0x00, 0x10, 0x7c, 0x01, 0x02, 0xa6, - 0x90, 0x01, 0x00, 0x14, 0xbc, 0x61, 0x00, 0x18, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x18, 0xa8, 0x3c, 0xe0, - 0x80, 0x00, 0x60, 0xe7, 0x11, 0x98, 0x3e, 0x60, 0x80, 0x00, 0x62, 0x73, 0x11, 0x88, 0x3e, 0x40, 0x4e, 0x80, - 0x62, 0x52, 0x00, 0x20, 0x81, 0xc7, 0x00, 0x04, 0x81, 0xe7, 0x00, 0x08, 0x82, 0x07, 0x00, 0x0c, 0x82, 0x27, - 0x00, 0x00, 0x3c, 0x80, 0x80, 0x00, 0x3c, 0xa0, 0x81, 0x33, 0x38, 0x84, 0xff, 0xfc, 0x84, 0xc4, 0x00, 0x04, - 0x7c, 0x04, 0x28, 0x00, 0x40, 0x80, 0x00, 0x4c, 0x7c, 0x06, 0x70, 0x00, 0x40, 0x82, 0xff, 0xf0, 0x84, 0xc4, - 0x00, 0x04, 0x7c, 0x06, 0x78, 0x00, 0x40, 0x82, 0xff, 0xe0, 0x84, 0xc4, 0x00, 0x04, 0x7c, 0x06, 0x80, 0x00, - 0x40, 0x82, 0xff, 0xd4, 0x84, 0xc4, 0x00, 0x04, 0x7c, 0x06, 0x88, 0x00, 0x40, 0x82, 0xff, 0xc8, 0x84, 0xc4, - 0x00, 0x04, 0x7c, 0x04, 0x28, 0x00, 0x40, 0x80, 0x00, 0x14, 0x7c, 0x06, 0x90, 0x00, 0x40, 0x82, 0xff, 0xf0, - 0x48, 0x00, 0x00, 0xad, 0x4b, 0xff, 0xff, 0xb0, 0x3c, 0x60, 0x80, 0x00, 0x60, 0x63, 0x10, 0x00, 0x3e, 0x60, - 0x80, 0x00, 0x62, 0x73, 0x11, 0x90, 0x3c, 0xe0, 0x80, 0x00, 0x60, 0xe7, 0x11, 0xa8, 0x81, 0xc7, 0x00, 0x04, - 0x81, 0xe7, 0x00, 0x08, 0x82, 0x07, 0x00, 0x0c, 0x82, 0x27, 0x00, 0x00, 0x3c, 0x80, 0x80, 0x00, 0x3c, 0xa0, - 0x81, 0x40, 0x38, 0x84, 0xff, 0xfc, 0x84, 0xc4, 0x00, 0x04, 0x7c, 0x04, 0x28, 0x00, 0x40, 0x80, 0x00, 0x38, - 0x7c, 0x06, 0x70, 0x00, 0x40, 0x82, 0xff, 0xf0, 0x84, 0xc4, 0x00, 0x04, 0x7c, 0x06, 0x78, 0x00, 0x40, 0x82, - 0xff, 0xe0, 0x84, 0xc4, 0x00, 0x04, 0x7c, 0x06, 0x80, 0x00, 0x40, 0x82, 0xff, 0xd4, 0x84, 0xc4, 0x00, 0x04, - 0x7c, 0x06, 0x88, 0x00, 0x40, 0x82, 0xff, 0xc8, 0x48, 0x00, 0x00, 0x39, 0x4b, 0xff, 0xff, 0xc4, 0x80, 0x01, - 0x00, 0xac, 0x7c, 0x08, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x0c, 0x7c, 0x0f, 0xf1, 0x20, 0x80, 0x01, 0x00, 0x10, - 0x7c, 0x09, 0x03, 0xa6, 0x80, 0x01, 0x00, 0x14, 0x7c, 0x01, 0x03, 0xa6, 0xb8, 0x61, 0x00, 0x18, 0x80, 0x01, - 0x00, 0x08, 0x38, 0x21, 0x00, 0xa8, 0x48, 0x00, 0x07, 0x50, 0x7e, 0x44, 0x18, 0x50, 0x3c, 0xc0, 0x48, 0x00, - 0x52, 0x46, 0x01, 0xba, 0x90, 0xc4, 0x00, 0x00, 0x90, 0xd3, 0x00, 0x00, 0x90, 0x93, 0x00, 0x04, 0x7c, 0x00, - 0x20, 0xac, 0x7c, 0x00, 0x04, 0xac, 0x7c, 0x00, 0x27, 0xac, 0x4c, 0x00, 0x01, 0x2c, 0x4e, 0x80, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0xc7, - 0x00, 0x4c, 0x7c, 0xe3, 0x3b, 0x78, 0x38, 0x87, 0x00, 0x34, 0x38, 0xa7, 0x00, 0x38, 0x4e, 0x80, 0x04, 0x20, - 0x7c, 0x00, 0x04, 0xac, 0x4c, 0x00, 0x01, 0x2c, 0x7f, 0xe9, 0x03, 0xa6 }; -const int multidol_size = sizeof(multidol); diff --git a/source/patches/multidol.h b/source/patches/multidol.h deleted file mode 100644 index 11d1f8a4..00000000 --- a/source/patches/multidol.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - This file was autogenerated by raw2c. - Visit http://www.devkitpro.org - */ - -//--------------------------------------------------------------------------------- -#ifndef _multidol_h_ -#define _multidol_h_ -//--------------------------------------------------------------------------------- -extern const unsigned char multidol[]; -extern const int multidol_size; -//--------------------------------------------------------------------------------- -#endif //_multidol_h_ -//--------------------------------------------------------------------------------- diff --git a/source/patches/patchcode.c b/source/patches/patchcode.c deleted file mode 100644 index 9b442a80..00000000 --- a/source/patches/patchcode.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include - -#include "usbloader/apploader.h" -#include "patchcode.h" -#include "settings/SettingsEnums.h" -#include "FileOperations/fileops.h" -#include "fst.h" - -//#include "sd.h" -//#include "fwrite_patch.h" -//#include "fwrite_patch_slota.h" -//#include "main.h" - -extern const char * CheatFilepath; - -extern void patchhook(u32 address, u32 len); -extern void patchhook2(u32 address, u32 len); -extern void patchhook3(u32 address, u32 len); - -extern void multidolpatchone(u32 address, u32 len); -extern void multidolpatchtwo(u32 address, u32 len); - -extern void regionfreejap(u32 address, u32 len); -extern void regionfreeusa(u32 address, u32 len); -extern void regionfreepal(u32 address, u32 len); - -extern void removehealthcheck(u32 address, u32 len); - -extern void copyflagcheck1(u32 address, u32 len); -extern void copyflagcheck2(u32 address, u32 len); -extern void copyflagcheck3(u32 address, u32 len); -extern void copyflagcheck4(u32 address, u32 len); -extern void copyflagcheck5(u32 address, u32 len); - -extern void patchupdatecheck(u32 address, u32 len); - -extern void movedvdhooks(u32 address, u32 len); - -extern void multidolhook(u32 address); -extern void langvipatch(u32 address, u32 len, u8 langbyte); -extern void vipatch(u32 address, u32 len); - -static const u32 multidolpatch1[2] = { 0x3C03FFB4, 0x28004F43 }; - -static const u32 healthcheckhook[2] = { 0x41810010, 0x881D007D }; - -static const u32 updatecheckhook[3] = { 0x80650050, 0x80850054, 0xA0A50058 }; - -static const u32 multidolpatch2[2] = { 0x3F608000, 0x807B0018 }; - -static const u32 recoveryhooks[3] = { 0xA00100AC, 0x5400073E, 0x2C00000F }; - -static const u32 nocopyflag1[3] = { 0x540007FF, 0x4182001C, 0x80630068 }; - -static const u32 nocopyflag2[3] = { 0x540007FF, 0x41820024, 0x387E12E2 }; - -// this one is for the GH3 and VC saves -//static const u32 nocopyflag3[5] = { -// 0x2C030000, 0x40820010, 0x88010020, 0x28000002, 0x41820234 -//}; - -static const u32 nocopyflag3[5] = { 0x2C030000, 0x41820200, 0x48000058, 0x38610100 }; -// this removes the display warning for no copy VC and GH3 saves -static const u32 nocopyflag4[4] = { 0x80010008, 0x2C000000, 0x4182000C, 0x3BE00001 }; - -static const u32 nocopyflag5[3] = { 0x801D0024, 0x540007FF, 0x41820024 }; - -static const u32 movedvdpatch[3] = { 0x2C040000, 0x41820120, 0x3C608109 }; - -static const u32 regionfreehooks[5] = { 0x7C600774, 0x2C000001, 0x41820030, 0x40800010, 0x2C000000 }; - -static const u32 cIOScode[16] = { 0x7f06c378, 0x7f25cb78, 0x387e02c0, 0x4cc63182 }; - -static const u32 cIOSblock[16] = { 0x2C1800F9, 0x40820008, 0x3B000024 }; - -static const u32 fwritepatch[8] = { 0x9421FFD0, 0x7C0802A6, 0x90010034, 0xBF210014, 0x7C9B2378, 0x7CDC3378, 0x7C7A1B78, - 0x7CB92B78 // bushing fwrite - }; - -static const u32 vipatchcode[3] = { 0x4182000C, 0x4180001C, 0x48000018 }; - -const u32 viwiihooks[4] = { 0x7CE33B78, 0x38870034, 0x38A70038, 0x38C7004C }; - -const u32 kpadhooks[4] = { 0x9A3F005E, 0x38AE0080, 0x389FFFFC, 0x7E0903A6 }; - -const u32 kpadoldhooks[6] = { 0x801D0060, 0x901E0060, 0x801D0064, 0x901E0064, 0x801D0068, 0x901E0068 }; - -const u32 joypadhooks[4] = { 0x3AB50001, 0x3A73000C, 0x2C150004, 0x3B18000C }; - -const u32 gxdrawhooks[4] = { 0x3CA0CC01, 0x38000061, 0x3C804500, 0x98058000 }; - -const u32 gxflushhooks[4] = { 0x90010014, 0x800305FC, 0x2C000000, 0x41820008 }; - -const u32 ossleepthreadhooks[4] = { 0x90A402E0, 0x806502E4, 0x908502E4, 0x2C030000 }; - -const u32 axnextframehooks[4] = { 0x3800000E, 0x7FE3FB78, 0xB0050000, 0x38800080 }; - -const u32 wpadbuttonsdownhooks[4] = { 0x7D6B4A14, 0x816B0010, 0x7D635B78, 0x4E800020 }; - -const u32 wpadbuttonsdown2hooks[4] = { 0x7D6B4A14, 0x800B0010, 0x7C030378, 0x4E800020 }; - -const u32 multidolhooks[4] = { 0x7C0004AC, 0x4C00012C, 0x7FE903A6, 0x4E800420 }; - -const u32 multidolchanhooks[4] = { 0x4200FFF4, 0x48000004, 0x38800000, 0x4E800020 }; - -const u32 langpatch[3] = { 0x7C600775, 0x40820010, 0x38000000 }; - -static const u32 oldpatch002[3] = { 0x2C000000, 0x40820214, 0x3C608000 }; - -static const u32 newpatch002[3] = { 0x2C000000, 0x48000214, 0x3C608000 }; - -//--------------------------------------------------------------------------------- -bool dogamehooks(void *addr, u32 len) -//--------------------------------------------------------------------------------- -{ - if (!CheatFilepath) return false; - - //this is temporary since the screen freezes without a file loaded - char filepath[150]; - char GameId[10]; - memcpy(GameId, (u8 *) 0x80000000, 6); - GameId[6] = 0; - sprintf(filepath, "%s%s.gct", CheatFilepath, GameId); - - if (!CheckFile(filepath)) return false; - - //TODO for oggzee: when using Ocarina check if a hook as patched - - hooktype = 1; // TODO for oggzee: Create an option for hooktype - /* - 0 No Hook - 1 VBI - 2 KPAD read - 3 Joypad Hook - 4 GXDraw Hook - 5 GXFlush Hook - 6 OSSleepThread Hook - 7 AXNextFrame Hook - */ - - void *addr_start = addr; - void *addr_end = addr + len; - bool hookpatched = false; - - while (addr_start < addr_end) - { - switch (hooktype) - { - - case 0x00: - hookpatched = true; - break; - - case 0x01: - if (memcmp(addr_start, viwiihooks, sizeof(viwiihooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x02: - - if (memcmp(addr_start, kpadhooks, sizeof(kpadhooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - - if (memcmp(addr_start, kpadoldhooks, sizeof(kpadoldhooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x03: - - if (memcmp(addr_start, joypadhooks, sizeof(joypadhooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x04: - - if (memcmp(addr_start, gxdrawhooks, sizeof(gxdrawhooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x05: - - if (memcmp(addr_start, gxflushhooks, sizeof(gxflushhooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x06: - - if (memcmp(addr_start, ossleepthreadhooks, sizeof(ossleepthreadhooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x07: - - if (memcmp(addr_start, axnextframehooks, sizeof(axnextframehooks)) == 0) - { - patchhook((u32) addr_start, len); - hookpatched = true; - } - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - - case 0x08: - - //if(memcmp(addr_start, customhook, customhooksize)==0) - //{ - // patchhook((u32)addr_start, len); - // hookpatched = true; - //} - if (memcmp(addr_start, multidolhooks, sizeof(multidolhooks)) == 0) - { - multidolhook((u32) addr_start + sizeof(multidolhooks) - 4); - hookpatched = true; - } - break; - } - addr_start += 4; - } - return hookpatched; -} - -// Not used yet, for patching DOL once loaded into memory and befor execution -/* - void patchdol(void *addr, u32 len) - { - - void *addr_start = addr; - void *addr_end = addr+len; - - while(addr_start < addr_end) - { - if(memcmp(addr_start, wpadlibogc, sizeof(wpadlibogc))==0) { - // printf("\n\n\n"); - // printf("found at address %x\n", addr_start); - // sleep(10); - // patchhookdol((u32)addr_start, len); - patched = 1; - break; - } - addr_start += 4; - } - } - */ -void langpatcher(void *addr, u32 len, u8 languageChoice) -{ - u8 ocarinaLangPatchByte = 1; - switch (languageChoice) - { - case JAPANESE: - ocarinaLangPatchByte = 0x00; - break; - case ENGLISH: - ocarinaLangPatchByte = 0x01; - break; - case GERMAN: - ocarinaLangPatchByte = 0x02; - break; - case FRENCH: - ocarinaLangPatchByte = 0x03; - break; - case SPANISH: - ocarinaLangPatchByte = 0x04; - break; - case ITALIAN: - ocarinaLangPatchByte = 0x05; - break; - case DUTCH: - ocarinaLangPatchByte = 0x06; - break; - case S_CHINESE: - ocarinaLangPatchByte = 0x07; - break; - case T_CHINESE: - ocarinaLangPatchByte = 0x08; - break; - case KOREAN: - ocarinaLangPatchByte = 0x09; - break; - case CONSOLE_DEFAULT: - default: - return; - break; - } - - - - void *addr_start = addr; - void *addr_end = addr + len; - - while (addr_start < addr_end) - { - - if (memcmp(addr_start, langpatch, sizeof(langpatch)) == 0) - { - langvipatch((u32) addr_start, len, ocarinaLangPatchByte); - } - addr_start += 4; - } -} -/* - void patchdebug(void *addr, u32 len) - { - - void *addr_start = addr; - void *addr_end = addr+len; - - while(addr_start < addr_end) - { - - if(memcmp(addr_start, fwritepatch, sizeof(fwritepatch))==0) { - - memcpy(addr_start,fwrite_patch_bin,fwrite_patch_bin_len); - // apply patch - } - addr_start += 4; - } - } - */ -void vidolpatcher(void *addr, u32 len) -{ - - void *addr_start = addr; - void *addr_end = addr + len; - - while (addr_start < addr_end) - { - if (memcmp(addr_start, vipatchcode, sizeof(vipatchcode)) == 0) - { - vipatch((u32) addr_start, len); - } - addr_start += 4; - } -} - diff --git a/source/patches/patchcode.h b/source/patches/patchcode.h deleted file mode 100644 index 98e05955..00000000 --- a/source/patches/patchcode.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __PATCHCODE_H__ -#define __PATCHCODE_H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - // Globals - u32 hooktype; - int patched; - //u8 configbytes[2]; - //u32 regionfree; - - // Function prototypes - bool dogamehooks(void *addr, u32 len); - void langpatcher(void *addr, u32 len, u8 languageChoice); - void vidolpatcher(void *addr, u32 len); - void patchdebug(void *addr, u32 len); - -#ifdef __cplusplus -} -#endif - -#endif // __PATCHCODE_H__ diff --git a/source/patches/patchhook.S b/source/patches/patchhook.S deleted file mode 100644 index 865e3417..00000000 --- a/source/patches/patchhook.S +++ /dev/null @@ -1,505 +0,0 @@ -.text -.set r0,0; .set sp,1; .set r2,2; .set r3,3; .set r4,4 -.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9 -.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14 -.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19 -.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24 -.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29 -.set r30,30; .set r31,31 - - -.globl patchhook # r3 address -patchhook: - mtctr r4 - lis r6, 0x4E80 - ori r6, r6, 0x0020 # blr -findblr: - lwz r5, 0(r3) - cmpw r6, r5 - beq writebranch - addi r3, r3, 4 # next word - bdnz findblr # loop length - b exit # stop unhooked game hanging - -writebranch: - lis r4, 0x8000 # 800018A0 hook location (source) - ori r4, r4, 0x18A8 - subf r4, r3, r4 # subtract r3 from r4 and place in r4 - lis r5, 0x3FF - ori r5, r5, 0xFFFF # 0x3FFFFFF - and r4, r4, r5 - lis r5, 0x4800 # 0x48000000 - or r4, r4, r5 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exit: - blr # return - - .globl patchhook2 # r3 address -patchhook2: - mtctr r4 - lis r6, 0x4E80 - ori r6, r6, 0x0020 # blr -findblr2: - lwz r5, 0(r3) - cmpw r6, r5 - beq writebranch2 - addi r3, r3, 4 # next word - bdnz findblr2 # loop length - b exit2 # stop unhooked game hanging - -writebranch2: - lis r4, 0x8000 # 81700000 our temp patcher - ori r4, r4, 0x18a8 - subf r4, r3, r4 # subtract r3 from r4 and place in r4 - lis r5, 0x3FF - ori r5, r5, 0xFFFF # 0x3FFFFFF - and r4, r4, r5 - lis r5, 0x4800 # 0x48000000 - or r4, r4, r5 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exit2: - blr # return - -.globl patchhook3 # r3 address -patchhook3: - mtctr r4 - lis r6, 0x4BFF - ori r6, r6, 0xE955 # blr -findbne: - lwz r5, 0(r3) - cmpw r6, r5 - beq writebl - addi r3, r3, 4 # next word - bdnz findbne # loop length - b exit3 # stop unhooked game hanging - -writebl: - lis r4, 0x4BFF # 81700000 our temp patcher - ori r4, r4, 0xEA91 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exit3: - blr # return - -.globl multidolpatchone # r3 address -multidolpatchone: - mtctr r4 - lis r6, 0x3800 - ori r6, r6, 0x0001 # (li r0,1) -findmulti: - lwz r5, 0(r3) - cmpw r6, r5 - beq writemulti - subi r3, r3, 4 # go back - bdnz findmulti # loop length - b exit5 # stop unhooked game hanging - -writemulti: - lis r4, 0x8170 # 81700000 - ori r4, r4, 0x0020 - subf r18, r3, r4 # subf r18,(source),(dest) - lis r6, 0x4800 - ori r6,r6,1 - rlwimi r6,r18,0,6,29 - stw r6,0(r3) - stw r6,0(r19) - stw r3,4(r19) - dcbf r0, r3 - sync - icbi r0, r3 - isync -exit5: - blr # return - -.globl multidolpatchtwo # r3 address -multidolpatchtwo: - mtctr r4 - lis r6, 0x3F60 - ori r6, r6, 0x8000 # (lis r27,-32768) -findmulti2: - lwz r5, 0(r3) - cmpw r6, r5 - beq writemulti2 - addi r3, r3, 4 # go forward - bdnz findmulti2 # loop length - b exit6 # stop unhooked game hanging - -writemulti2: - lis r4, 0x8170 # 81700020 - ori r4, r4, 0x0000 - subf r18, r3, r4 # subf r18,(source),(dest) - lis r6, 0x4800 - ori r6,r6,1 - rlwimi r6,r18,0,6,29 - stw r6,0(r3) - stw r6,0(r19) - stw r3,4(r19) - dcbf r0, r3 - sync - icbi r0, r3 - isync -exit6: - blr # return - -.globl multidolhook # r3 address -multidolhook: - lis r4, 0x8000 # 80001000 hook location (source) - ori r4, r4, 0x1000 - subf r4, r3, r4 # subtract r3 from r4 and place in r4 - lis r5, 0x3FF - ori r5, r5, 0xFFFF # 0x3FFFFFF - and r4, r4, r5 - lis r5, 0x4800 # 0x48000000 - or r4, r4, r5 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 - blr # return - - -.globl langvipatch # r3 address, r4 len, r5 lang byte -langvipatch: - mtctr r4 - lis r6, 0x8861 - ori r6, r6, 0x0008 # lbz r3, 8(sp) -findlang: - lwz r7, 0(r3) - cmpw r6, r7 - beq patchlang - addi r3, r3, 4 # next word - bdnz findlang # loop length - b exitlang # stop unhooked game hanging - -patchlang: - - lis r4, 0x3860 # 0x38600001 li %r3, 1 # eng - add r4, r4, r5 -gofinal: - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitlang: - blr # return - -.globl vipatch # r3 address -vipatch: - mtctr r4 - lis r6, 0x5400 - ori r6, r6, 0xFFFE -findvi: - lwz r5, 0(r3) - cmpw r6, r5 - beq patchvi - addi r3, r3, 4 # next word - bdnz findvi # loop length - b exitvi # stop unhooked game hanging - -patchvi: - lis r4, 0x8000 - ori r4, r4, 0x0003 - lbz r5, 0(r4) - cmpwi r5, 0x45 # USA - beq patchusa - cmpwi r5, 0x4A - beq patchjap2 # JAP - b exitvi -patchjap2: - lis r4, 0x3800 - ori r4, r4, 0x0001 - b gofinal2 -patchusa: - lis r4, 0x3800 - ori r4, r4, 0x0000 -gofinal2: - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitvi: - blr # return - -.globl regionfreejap # r3 address -regionfreejap: - mtctr r4 - lis r6, 0x2C1B - ori r6, r6, 0x0000 # blr -findjap: - lwz r5, 0(r3) - cmpw r6, r5 - beq writenop - addi r3, r3, 4 # next word - bdnz findjap # loop length - b exitjap # stop unhooked game hanging - -writenop: - addi r3, r3, 4 # next word - lis r4, 0x6000 # nop - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitjap: - blr # return - -.globl regionfreeusa # r3 address -regionfreeusa: - mtctr r4 - lis r6, 0x281B - ori r6, r6, 0x0001 # blr -findusa: - lwz r5, 0(r3) - cmpw r6, r5 - beq writenop1 - addi r3, r3, 4 # next word - bdnz findusa # loop length - b exitusa # stop unhooked game hanging - -writenop1: - addi r3, r3, 4 # next word - lis r4, 0x6000 # nop - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitusa: - blr # return - -.globl regionfreepal # r3 address -regionfreepal: - mtctr r4 - lis r6, 0x281B - ori r6, r6, 0x0002 # blr -findpal: - lwz r5, 0(r3) - cmpw r6, r5 - beq writenop2 - addi r3, r3, 4 # next word - bdnz findpal # loop length - b exitpal # stop unhooked game hanging - -writenop2: - addi r3, r3, 4 # next word - lis r4, 0x6000 # nop - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 - - lis r6, 0x4082 - ori r6, r6, 0x001C # bne loc_81377A2C -findextra: #this is just the bne to b patch - lwz r5, 0(r3) - cmpw r6, r5 - beq writeb - addi r3, r3, 4 # next word - bdnz findextra # loop length - b exitpal # stop unhooked game hanging - -writeb: - addi r3, r3, 4 # next word - lis r4, 0x4800 - ori r4, r4, 0x001c # b loc_81377A2C - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitpal: - blr # return - -.globl removehealthcheck # r3 address -removehealthcheck: - mtctr r4 - lis r6, 0x4182 - ori r6, r6, 0x004C # blr -findhe: - lwz r5, 0(r3) - cmpw r6, r5 - beq writebhe - addi r3, r3, 4 # next word - bdnz findhe # loop length - b exithe # stop unhooked game hanging - -writebhe: - lis r4, 0x6000 - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exithe: - blr # return - - - -.globl patchupdatecheck # r3 address -patchupdatecheck: - mtctr r4 - lis r6, 0x4082 - ori r6, r6, 0x0020 # blr -finduc: - lwz r5, 0(r3) - cmpw r6, r5 - beq writenopuc - addi r3, r3, 4 # next word - bdnz finduc # loop length - b exituc # stop unhooked game hanging - -writenopuc: - lis r4, 0x6000 - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exituc: - blr # return - - - - -.globl copyflagcheck1 # r3 address -copyflagcheck1: - mtctr r4 - lis r6, 0x5400 - ori r6, r6, 0x07FF -findncf1: - lwz r5, 0(r3) - cmpw r6, r5 - beq writencf1 - subi r3, r3, 4 # next word - bdnz findncf1 # loop length - b exitncf1 # stop unhooked game hanging - -writencf1: - lis r4, 0x7C00 - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitncf1: - blr # return - -.globl copyflagcheck2 # r3 address -copyflagcheck2: - mtctr r4 - lis r6, 0x5400 - ori r6, r6, 0x07FF -findncf2: - lwz r5, 0(r3) - cmpw r6, r5 - beq writencf2 - subi r3, r3, 4 # next word - bdnz findncf2 # loop length - b exitncf2 # stop unhooked game hanging - -writencf2: - lis r4, 0x7C00 - ori r4, r4, 0x0000 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitncf2: - blr # return - - -.globl copyflagcheck3 # r3 address -copyflagcheck3: -findncf3: - addi r3, r3, 20 # go back one dword (4 bytes) - lwz r5, 0(r3) -writencf3: - lis r4, 0x3860 - ori r4, r4, 0x0001 # li r3,1 - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitncf3: - blr # return - - -.globl copyflagcheck4 # r3 address -copyflagcheck4: - mtctr r4 - lis r6, 0x3BE0 - ori r6, r6, 0x0001 # li r31,1 -findncf4: - lwz r5, 0(r3) - cmpw r6, r5 - beq writencf4 - addi r3, r3, 4 # next word - bdnz findncf4 # loop length - b exitncf4 # stop unhooked game hanging - -writencf4: - lis r4, 0x3BE0 - ori r4, r4, 0x0000 # change this to 3BE00000 (li r31,0) - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitncf4: - blr # return - -.globl copyflagcheck5 # r3 address -copyflagcheck5: - mtctr r4 - lis r6, 0x4182 - ori r6, r6, 0x0024 # beq loc_8134AA60 -findncf5: - lwz r5, 0(r3) - cmpw r6, r5 - beq writencf5 - addi r3, r3, 4 # next word - bdnz findncf5 # loop length - b exitncf5 # stop unhooked game hanging - -writencf5: - #addi r3, r3, 8 # skip 2 - - lis r4, 0x801D - ori r4, r4, 0x0024 # change to 801D0024 (lwz r0,36(r29)) - stw r4, 0(r3) - dcbf r0, r3 - icbi r0, r3 - - addi r3, r3, 4 # next word - - lis r4, 0x5400 - ori r4, r4, 0x003C # change to 5400003C (rlwinm r0,r0,0,0,30) - stw r4, 0(r3) - dcbf r0, r3 - icbi r0, r3 - - addi r3, r3, 4 # next word - - lis r4, 0x901D - ori r4, r4, 0x0024 # change to 901D0024 (stw r0,36(r29)) - stw r4, 0(r3) - dcbf r0, r3 - icbi r0, r3 - - addi r3, r3, 4 # next word - - lis r4, 0x4800 - ori r4, r4, 0x0018 # change to 48000018 (b 0x8134aa60) - stw r4, 0(r3) - dcbf r0, r3 - icbi r0, r3 -exitncf5: - blr # return - -.globl movedvdhooks # r3 address -movedvdhooks: - lis r6, 0x4182 - ori r6, r6, 0x0120 # beq loc_813A7938 -findmd1: - addi r3, r3, 4 # next word - lwz r5, 0(r3) -writemd1: - lis r4, 0x6000 - ori r4, r4, 0x0000 # nop - stw r4, 0(r3) # result in r3 - dcbf r0, r3 # data cache block flush - icbi r0, r3 -exitmd1: - blr # return diff --git a/source/patches/ppc.h b/source/patches/ppc.h deleted file mode 100644 index 000df8d3..00000000 --- a/source/patches/ppc.h +++ /dev/null @@ -1,81 +0,0 @@ - -/* Condition Register Bit Fields */ - -#define cr0 0 -#define cr1 1 -#define cr2 2 -#define cr3 3 -#define cr4 4 -#define cr5 5 -#define cr6 6 -#define cr7 7 - -/* General Purpose Registers */ - -#define r0 0 -#define r1 1 -#define r2 2 -#define r3 3 -#define r4 4 -#define r5 5 -#define r6 6 -#define r7 7 -#define r8 8 -#define r9 9 -#define r10 10 -#define r11 11 -#define r12 12 -#define r13 13 -#define r14 14 -#define r15 15 -#define r16 16 -#define r17 17 -#define r18 18 -#define r19 19 -#define r20 20 -#define r21 21 -#define r22 22 -#define r23 23 -#define r24 24 -#define r25 25 -#define r26 26 -#define r27 27 -#define r28 28 -#define r29 29 -#define r30 30 -#define r31 31 - -/* Define Floating Point Registers */ - -#define f0 0 -#define f1 1 -#define f2 2 -#define f3 3 -#define f4 4 -#define f5 5 -#define f6 6 -#define f7 7 -#define f8 8 -#define f9 9 -#define f10 10 -#define f11 11 -#define f12 12 -#define f13 13 -#define f14 14 -#define f15 15 -#define f16 16 -#define f17 17 -#define f18 18 -#define f19 19 -#define f20 20 -#define f21 21 -#define f22 22 -#define f23 23 -#define f24 24 -#define f25 25 -#define f26 26 -#define f27 27 -#define f28 28 -#define f29 29 -#define f30 30 -#define f31 31 diff --git a/source/patches/wip.c b/source/patches/wip.c deleted file mode 100644 index 6e3471a7..00000000 --- a/source/patches/wip.c +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#include -#include "gecko.h" - -#include "settings/cfg.h" -#include "wip.h" - -static WIP_Code * CodeList = NULL; -static u32 CodesCount = 0; -static u32 ProcessedLength = 0; -static u32 Counter = 0; - -void do_wip_code(u8 * dst, u32 len) -{ - if (!CodeList) return; - - if (Counter < 3) - { - Counter++; - return; - } - - int i = 0; - int n = 0; - int offset = 0; - - for (i = 0; i < CodesCount; i++) - { - for (n = 0; n < 4; n++) - { - offset = CodeList[i].offset + n - ProcessedLength; - - if (offset < 0 || offset >= len) continue; - - if (dst[offset] == ((u8 *) &CodeList[i].srcaddress)[n]) - { - dst[offset] = ((u8 *) &CodeList[i].dstaddress)[n]; - gprintf("WIP: %08X Address Patched.\n", CodeList[i].offset + n); - } - else - { - gprintf("WIP: %08X Address does not match with WIP entrie.\n", CodeList[i].offset + n); - gprintf("Destination: %02X | Should be: %02X.\n", dst[offset], ((u8 *) &CodeList[i].srcaddress)[n]); - } - } - } - ProcessedLength += len; - Counter++; -} - -//! for internal patches only -//! .wip files override internal patches -//! the codelist has to be freed if the set fails -//! if set was successful the codelist will be freed when it's done -bool set_wip_list(WIP_Code * list, int size) -{ - if (!CodeList && size > 0) - { - CodeList = list; - CodesCount = size; - return true; - } - - return false; -} - -void wip_reset_counter() -{ - ProcessedLength = 0; - //alternative dols don't need a skip. only main.dol. - Counter = 3; -} - -void free_wip() -{ - if (CodeList) free(CodeList); - CodeList = NULL; - CodesCount = 0; - Counter = 0; - ProcessedLength = 0; -} - -int load_wip_code(u8 *gameid) -{ - char filepath[150]; - char GameID[8]; - memset(GameID, 0, sizeof(GameID)); - memcpy(GameID, gameid, 6); - snprintf(filepath, sizeof(filepath), "%s%s.wip", Settings.WipCodepath, GameID); - - FILE * fp = fopen(filepath, "rb"); - if (!fp) - { - memset(GameID, 0, sizeof(GameID)); - memcpy(GameID, gameid, 4); - snprintf(filepath, sizeof(filepath), "%s%s.wip", Settings.WipCodepath, GameID); - fp = fopen(filepath, "rb"); - } - if (!fp) - { - memset(GameID, 0, sizeof(GameID)); - memcpy(GameID, gameid, 3); - snprintf(filepath, sizeof(filepath), "%s%s.wip", Settings.WipCodepath, GameID); - fp = fopen(filepath, "rb"); - } - - if (!fp) return -1; - - char line[255]; - gprintf("\nLoading WIP code from %s.\n", filepath); - - while (fgets(line, sizeof(line), fp)) - { - if (line[0] == '#') continue; - if (line[0] == ';') continue; - if (line[0] == ':') continue; - - if (strlen(line) < 26) continue; - - u32 offset = (u32) strtoul(line, NULL, 16); - u32 srcaddress = (u32) strtoul(line + 9, NULL, 16); - u32 dstaddress = (u32) strtoul(line + 18, NULL, 16); - - if (!CodeList) CodeList = malloc(sizeof(WIP_Code)); - - WIP_Code * tmp = realloc(CodeList, (CodesCount + 1) * sizeof(WIP_Code)); - if (!tmp) - { - fclose(fp); - free_wip(); - return -1; - } - - CodeList = tmp; - - CodeList[CodesCount].offset = offset; - CodeList[CodesCount].srcaddress = srcaddress; - CodeList[CodesCount].dstaddress = dstaddress; - CodesCount++; - } - fclose(fp); - gprintf("\n"); - - return 0; -} diff --git a/source/patches/wip.cpp b/source/patches/wip.cpp deleted file mode 100644 index 632e0da4..00000000 --- a/source/patches/wip.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#include -#include "gecko.h" - -#include "settings/CSettings.h" -#include "wip.h" - -static WIP_Code * CodeList = NULL; -static u32 CodesCount = 0; -static u32 ProcessedLength = 0; -static u32 Counter = 0; - -extern "C" void do_wip_code(u8 * dst, u32 len) -{ - if (!CodeList) return; - - if (Counter < 3) - { - Counter++; - return; - } - - u32 i = 0; - int n = 0; - int offset = 0; - - for (i = 0; i < CodesCount; i++) - { - for (n = 0; n < 4; n++) - { - offset = CodeList[i].offset + n - ProcessedLength; - - if (offset < 0 || offset >= (int) len) continue; - - if (dst[offset] == ((u8 *) &CodeList[i].srcaddress)[n]) - { - dst[offset] = ((u8 *) &CodeList[i].dstaddress)[n]; - gprintf("WIP: %08X Address Patched.\n", CodeList[i].offset + n); - } - else - { - gprintf("WIP: %08X Address does not match with WIP entrie.\n", CodeList[i].offset + n); - gprintf("Destination: %02X | Should be: %02X.\n", dst[offset], ((u8 *) &CodeList[i].srcaddress)[n]); - } - } - } - ProcessedLength += len; - Counter++; -} - -//! for internal patches only -//! .wip files override internal patches -//! the codelist has to be freed if the set fails -//! if set was successful the codelist will be freed when it's done -extern "C" bool set_wip_list(WIP_Code * list, int size) -{ - if (!CodeList && size > 0) - { - CodeList = list; - CodesCount = size; - return true; - } - - return false; -} - -extern "C" void wip_reset_counter() -{ - ProcessedLength = 0; - //alternative dols don't need a skip. only main.dol. - Counter = 3; -} - -extern "C" void free_wip() -{ - if (CodeList) free(CodeList); - CodeList = NULL; - CodesCount = 0; - Counter = 0; - ProcessedLength = 0; -} - -extern "C" int load_wip_code(u8 *gameid) -{ - char filepath[150]; - char GameID[8]; - memset(GameID, 0, sizeof(GameID)); - memcpy(GameID, gameid, 6); - snprintf(filepath, sizeof(filepath), "%s%s.wip", Settings.WipCodepath, GameID); - - FILE * fp = fopen(filepath, "rb"); - if (!fp) - { - memset(GameID, 0, sizeof(GameID)); - memcpy(GameID, gameid, 4); - snprintf(filepath, sizeof(filepath), "%s%s.wip", Settings.WipCodepath, GameID); - fp = fopen(filepath, "rb"); - } - if (!fp) - { - memset(GameID, 0, sizeof(GameID)); - memcpy(GameID, gameid, 3); - snprintf(filepath, sizeof(filepath), "%s%s.wip", Settings.WipCodepath, GameID); - fp = fopen(filepath, "rb"); - } - - if (!fp) return -1; - - char line[255]; - gprintf("\nLoading WIP code from %s.\n", filepath); - - while (fgets(line, sizeof(line), fp)) - { - if (line[0] == '#') continue; - if (line[0] == ';') continue; - if (line[0] == ':') continue; - - if (strlen(line) < 26) continue; - - u32 offset = (u32) strtoul(line, NULL, 16); - u32 srcaddress = (u32) strtoul(line + 9, NULL, 16); - u32 dstaddress = (u32) strtoul(line + 18, NULL, 16); - - if (!CodeList) CodeList = (WIP_Code *) malloc(sizeof(WIP_Code)); - - WIP_Code * tmp = (WIP_Code *) realloc(CodeList, (CodesCount + 1) * sizeof(WIP_Code)); - if (!tmp) - { - fclose(fp); - free_wip(); - return -1; - } - - CodeList = tmp; - - CodeList[CodesCount].offset = offset; - CodeList[CodesCount].srcaddress = srcaddress; - CodeList[CodesCount].dstaddress = dstaddress; - CodesCount++; - } - fclose(fp); - gprintf("\n"); - - return 0; -} diff --git a/source/patches/wip.h b/source/patches/wip.h deleted file mode 100644 index 45336fde..00000000 --- a/source/patches/wip.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __WIP_H__ -#define __WIP_H__ - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - - typedef struct - { - u32 offset; - u32 srcaddress; - u32 dstaddress; - } WIP_Code; - - int load_wip_code(u8 *gameid); - void do_wip_code(u8 * dst, u32 len); - bool set_wip_list(WIP_Code * list, int size); - void wip_reset_counter(); - void free_wip(); - -#ifdef __cplusplus -} -#endif - -#endif //__WIP_H__ diff --git a/source/prompts/DiscBrowser.cpp b/source/prompts/DiscBrowser.cpp deleted file mode 100644 index 3cf7f7c3..00000000 --- a/source/prompts/DiscBrowser.cpp +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** - * DiscBrowser - * USB Loader GX 2009 - * - * DiscBrowser.h - ***************************************************************************/ -#include -#include "language/gettext.h" -#include "libwiigui/gui.h" -#include "libwiigui/gui_customoptionbrowser.h" -#include "prompts/PromptWindows.h" -#include "filelist.h" -#include "menu.h" -#include "usbloader/disc.h" -#include "usbloader/fstfile.h" -#include "usbloader/wdvd.h" -#include "usbloader/wbfs.h" -#include "patches/dvd_broadway.h" -#include "libs/libwbfs/libwbfs.h" -#include "libs/libwbfs/wiidisc.h" -#include "main.h" -#include "sys.h" -#include "settings/GameTitles.h" -#include "themes/CTheme.h" -#include "memory/memory.h" -#include "gecko.h" - -/*** Extern functions ***/ -extern void ResumeGui(); -extern void HaltGui(); - -/*** Extern variables ***/ -extern GuiWindow * mainWindow; -extern u8 shutdown; -extern u8 reset; - -/******************************************************************************** - *Disk Browser - *********************************************************************************/ -int DiscBrowse(const char * GameID, char * alternatedname, int alternatedname_size) -{ - gprintf("\nDiscBrowser() started"); - bool exit = false; - int ret = -1, choice; - - HaltGui(); - - gprintf("WBFS_OpenDisc\n"); - wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) GameID); - if (!disc) - { - ResumeGui(); - WindowPrompt(tr( "ERROR:" ), tr( "Could not open Disc" ), tr( "OK" )); - return ret; - } - gprintf("wd_open_disc\n"); - wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc); - if (!wdisc) - { - ResumeGui(); - WindowPrompt(tr( "ERROR:" ), tr( "Could not open Disc" ), tr( "OK" )); - return ret; - } - - gprintf("wd_get_fst\n"); - FST_ENTRY * fstbuffer = (FST_ENTRY *) wd_get_fst(wdisc, ONLY_GAME_PARTITION); - if (!fstbuffer) - { - ResumeGui(); - WindowPrompt(tr( "ERROR:" ), tr( "Not enough free memory." ), tr( "OK" )); - return -1; - } - - gprintf("wd_close_disc\n"); - wd_close_disc(wdisc); - gprintf("WBFS_CloseDisc\n"); - WBFS_CloseDisc(disc); - - gprintf("options\n"); - OptionList options; - - for (u32 i = 0, position = 0; i < fstbuffer[0].filelen; i++) - { - //don't add files that aren't .dol to the list - const char * filename = fstfiles(fstbuffer, i); - const char * fileext = NULL; - - if(filename) - gprintf("%s\n", filename); - - if(filename) - fileext = strrchr(filename, '.'); - - if (fileext && strcasecmp(fileext, ".dol") == 0) - { - options.SetName(position, "%s %03i", tr("Offset"), i); - options.SetValue(position, filename); - position++; - } - } - - free(fstbuffer); - - gprintf("\n%i alt dols found", options.GetLength()+1); - if (options.GetLength() <= 0) - { - WindowPrompt(tr( "ERROR" ), tr( "No DOL file found on disc." ), tr( "OK" )); - return ret; - } - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText titleTxt(GameTitles.GetTitle(GameID), 28, ( GXColor ) {0, 0, 0, 255}); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(12, 40); - titleTxt.SetMaxWidth(356, SCROLL_HORIZONTAL); - - GuiImage settingsbackground(&settingsbg); - GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight()); - settingsbackgroundbtn.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - settingsbackgroundbtn.SetPosition(0, 0); - settingsbackgroundbtn.SetImage(&settingsbackground); - - GuiText cancelBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage cancelBtnImg(&btnOutline); - if (Settings.wsprompt == ON) - { - cancelBtnTxt.SetWidescreen(Settings.widescreen); - cancelBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton cancelBtn(&cancelBtnImg, &cancelBtnImg, 2, 3, 180, 400, &trigA, btnSoundOver, btnSoundClick2, 1); - cancelBtn.SetScale(0.9); - cancelBtn.SetLabel(&cancelBtnTxt); - cancelBtn.SetTrigger(&trigB); - - GuiCustomOptionBrowser optionBrowser3(396, 280, &options, "bg_options_settings.png"); - optionBrowser3.SetPosition(0, 90); - optionBrowser3.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - - HaltGui(); - GuiWindow w(screenwidth, screenheight); - w.Append(&settingsbackgroundbtn); - w.Append(&titleTxt); - w.Append(&cancelBtn); - w.Append(&optionBrowser3); - - mainWindow->Append(&w); - - ResumeGui(); - while (!exit) - { - usleep(100); - - if (shutdown) - Sys_Shutdown(); - if (reset) - Sys_Reboot(); - - ret = optionBrowser3.GetClickedOption(); - - if (ret >= 0) - { - choice = WindowPrompt(options.GetValue(ret), tr( "Load this DOL as alternate DOL?" ), tr( "OK" ), tr( "Cancel" )); - if (choice) - { - snprintf(alternatedname, alternatedname_size, options.GetValue(ret)); - const char * offset = options.GetName(ret); - if(offset) - ret = atoi(offset+strlen("Offset ")); //doloffset - else - ret = -1; // weird problem - exit = true; - } - } - - if (cancelBtn.GetState() == STATE_CLICKED) - { - exit = true; - } - } - - HaltGui(); - mainWindow->Remove(&w); - ResumeGui(); - - return ret; -} - -int autoSelectDol(const char *id, bool force) -{ - gprintf("\nautoSelectDol() started"); - - char id4[10]; - sprintf(id4, "%c%c%c%c", id[0], id[1], id[2], id[3]); - - ////// games that can be forced (always need alt dol) - - //Boogie - if (strcmp(id, "RBOP69") == 0) return 675;//previous value was 657 - if (strcmp(id, "RBOE69") == 0) return 675;//starstremr - - //Fifa 08 - if (strcmp(id, "RF8E69") == 0) return 439;//from isostar - if (strcmp(id, "RF8P69") == 0) return 463;//from isostar - if (strcmp(id, "RF8X69") == 0) return 464;//from isostar - - //Madden NFL07 - if (strcmp(id, "RMDP69") == 0) return 39;//from isostar - - //Madden NFL08 - if (strcmp(id, "RNFP69") == 0) return 1079;//from isostar - - //Medal of Honor: Heroes 2 - if (strcmp(id, "RM2X69") == 0) return 601;//dj_skual - if (strcmp(id, "RM2P69") == 0) return 517;//MZottel - if (strcmp(id, "RM2E69") == 0) return 492;//Old8oy - - //Mortal Kombat - if (strcmp(id, "RKMP5D") == 0) return 290;//from isostar - if (strcmp(id, "RKME5D") == 0) return 290;//starstremr - - //NBA 08 - if (strcmp(id, "RNBX69") == 0) return 964;//from isostar - - //Pangya! Golf with Style - if (strcmp(id, "RPYP9B") == 0) return 12490;//from isostar - - //Redsteel - if (strcmp(id, "REDP41") == 0) return 1957;//from isostar - if (strcmp(id, "REDE41") == 0) return 1957;//starstremr - - //SSX - if (strcmp(id, "RSXP69") == 0) return 377;//previous value was 337 - if (strcmp(id, "RSXE69") == 0) return 377;//previous value was 337 - - //Wii Sports Resort, needs alt dol one time only, to show the Motion Plus video - //if (strcmp(id,"RZTP01") == 0 && CheckForSave(id4)==0) return 952;//from isostar - //if (strcmp(id,"RZTE01") == 0 && CheckForSave(id4)==0) return 674;//from starstremr - //as well as Grand Slam Tennis, Tiger Woods 10, Virtual Tennis 2009 - - ///// games that can't be forced (alt dol is not always needed) - if (!force) - { - - //Grand Slam Tennis - if (strcmp(id, "R5TP69") == 0) return 1493;//from isostar - if (strcmp(id, "R5TE69") == 0) return 1493;//starstremr - - //Medal of Honor Heroes - if (strcmp(id, "RMZX69") == 0) return 492;//from isostar - if (strcmp(id, "RMZP69") == 0) return 492;//from isostar - if (strcmp(id, "RMZE69") == 0) return 492;//starstremr - - //Tiger Woods 10 - if (strcmp(id, "R9OP69") == 0) return 1991;//from isostar - if (strcmp(id, "R9OE69") == 0) return 1973;//starstremr - - //Virtual Tennis 2009 - if (strcmp(id, "RVUP8P") == 0) return 16426;//from isostar - if (strcmp(id, "RVUE8P") == 0) return 16405;//from isostar - - //Wii Sports Resort - if (strcmp(id, "RZTP01") == 0) return 952;//from isostar - if (strcmp(id, "RZTE01") == 0) return 674;//from starstremr - } - - return -1; -} - -int autoSelectDolMenu(const char *id, bool force) -{ - - /* - char id4[10]; - sprintf(id4,"%c%c%c%c",id[0],id[1],id[2],id[3]); - - switch (CheckForSave(id4)) { - case 0: - WindowPrompt(tr("NO save"),0,tr("OK")); - break; - case 1: - WindowPrompt(tr("save"),0,tr("OK")); - break; - default: - char test[10]; - sprintf(test,"%d",CheckForSave(id4)); - WindowPrompt(test,0,tr("OK")); - break; - } - return -1; - */ - - //Indiana Jones and the Staff of Kings (Fate of Atlantis) - if (strcmp(id, "RJ8E64") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Fate of Atlantis", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 8; //from starstremr - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - if (strcmp(id, "RJ8P64") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Fate of Atlantis", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 8; //from isostar - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - - //Metal Slug Anthology (Metal Slug 6) - if (strcmp(id, "RMLEH4") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Metal Slug 6", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 54; //from lustar - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - if (strcmp(id, "RMLP7U") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Metal Slug 6", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 56; //from isostar - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - - //Metroid Prime Trilogy - if (strcmp(id, "R3ME01") == 0) - { - //do not use any alt dol if there is no save game in the nand - /* - if (CheckForSave(id4)==0 && force) { - WindowPrompt(0,tr("You need to start this game one time to create a save file, then exit and start it again."),tr("OK")); - return -1; - } - */ - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Metroid Prime", "Metroid Prime 2", "Metroid Prime 3", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 780; - break; - case 2: - choice = 781; - break; - case 3: - choice = 782; - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - if (strcmp(id, "R3MP01") == 0) - { - /* - if (CheckForSave(id4)==0 && force) { - WindowPrompt(0,tr("You need to start this game one time to create a save file, then exit and start it again."),tr("OK")); - return -1; - } - */ - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Metroid Prime", "Metroid Prime 2", "Metroid Prime 3", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 782; - break; - case 2: - choice = 783; - break; - case 3: - choice = 784; - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - - //Rampage: Total Destruction (M1.dol=Rampage, jarvos.dol=Rampage World Tour) - if (strcmp(id, "RPGP5D") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "Rampage", "World Tour", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 369; //from Ramzee - break; - case 2: - choice = 368; //from Ramzee - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - - //The House Of The Dead 2 & 3 Return (only to play 2) - if (strcmp(id, "RHDE8P") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "HotD 2", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 149; //from starstremr - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - if (strcmp(id, "RHDP8P") == 0) - { - int choice = WindowPrompt(tr( "Select a DOL" ), 0, "HotD 2", tr( "Cancel" )); - switch (choice) - { - case 1: - choice = 149; //from isostar - break; - default: // no alt dol - choice = 0; - break; - } - return choice; - } - - return -1; -} - -/******************************************************************************** - * Mount a DVD, get the type and ID. - *********************************************************************************/ -u8 DiscMount(struct discHdr * header) -{ - gprintf("\nDiscMount() "); - u8 * g_diskID = (u8 *) 0x80000000; - int ret; - HaltGui(); - - u8 *tmpBuff = (u8 *) malloc(0x60); - memcpy(tmpBuff, g_diskID, 0x60); // Make a backup of the first 96 bytes at 0x80000000 - - Disc_SetUSB(NULL); - ret = WDVD_Reset(); - if(ret < 0) - return 0; - - ret = WDVD_ReadDiskId(g_diskID); - if(ret < 0) - return 0; - - ret = WDVD_UnencryptedRead(g_diskID, 0x60, 0x00); - if(ret < 0) - return 0; - - memcpy(header, g_diskID, 0x60); - memcpy(g_diskID, tmpBuff, 0x60); // Put the backup back, or games won't load - free(tmpBuff); - - ResumeGui(); - - return (header->magic == 0x5D1C9EA3) ? 1 : 2; // Don't check gamecube magic (0xC2339F3D) -} diff --git a/source/prompts/DiscBrowser.h b/source/prompts/DiscBrowser.h deleted file mode 100644 index d285ff9d..00000000 --- a/source/prompts/DiscBrowser.h +++ /dev/null @@ -1,19 +0,0 @@ -/**************************************************************************** - * DiscBrowser - * USB Loader GX 2009 - * - * DiscBrowser.h - ***************************************************************************/ - -#ifndef _DISCBROWSER_H_ -#define _DISCBROWSER_H_ - -#include -#include "usbloader/disc.h" - -int DiscBrowse(const char * GameID, char * dolname, int dolname_size); -int autoSelectDol(const char *id, bool force); -int autoSelectDolMenu(const char *id, bool force); -u8 DiscMount(struct discHdr * header); - -#endif diff --git a/source/prompts/GameWindow.cpp b/source/prompts/GameWindow.cpp deleted file mode 100644 index 6fb3e92c..00000000 --- a/source/prompts/GameWindow.cpp +++ /dev/null @@ -1,602 +0,0 @@ -#include -#include "GameWindow.hpp" -#include "usbloader/disc.h" -#include "usbloader/wbfs.h" -#include "usbloader/GameList.h" -#include "themes/CTheme.h" -#include "settings/CSettings.h" -#include "settings/CGameSettings.h" -#include "settings/CGameStatistics.h" -#include "settings/GameTitles.h" -#include "settings/Settings.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "menu/menus.h" -#include "bannersound.h" - -#define NONE 0 -#define LEFT 1 -#define RIGHT 2 -#define IN 3 -#define OUT 4 - -extern int mountMethod; -extern struct discHdr *dvdheader; - -GameWindow::GameWindow(int Selected) - : GuiWindow(472, 320) -{ - returnVal = -1; - gameSelected = Selected; - gameSound = NULL; - diskImgData = NULL; - diskImgData2 = NULL; - reducedVol = false; - SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - SetPosition(0, -10); - - dialogBox = Resources::GetImageData(Settings.widescreen ? "wdialogue_box_startgame.png" : "dialogue_box_startgame.png"); - btnOutline = Resources::GetImageData("button_dialogue_box.png"); - imgFavorite = Resources::GetImageData("favorite.png"); - imgNotFavorite = Resources::GetImageData("not_favorite.png"); - imgLeft = Resources::GetImageData("startgame_arrow_left.png"); - imgRight = Resources::GetImageData("startgame_arrow_right.png"); - - trigA = new GuiTrigger; - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigB = new GuiTrigger; - trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - trigL = new GuiTrigger; - trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); - trigR = new GuiTrigger; - trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); - trigPlus = new GuiTrigger; - trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0); - trigMinus = new GuiTrigger; - trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0); - - dialogBoxImg = new GuiImage(dialogBox); - - nameBtnTT = new GuiTooltip(tr( "Rename Game on WBFS" )); - if (Settings.wsprompt) nameBtnTT->SetWidescreen(Settings.widescreen); - nameTxt = new GuiText("", 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - if (Settings.wsprompt) nameTxt->SetWidescreen(Settings.widescreen); - nameTxt->SetMaxWidth(350, SCROLL_HORIZONTAL); - nameBtn = new GuiButton(120, 50); - nameBtn->SetLabel(nameTxt); - nameBtn->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - nameBtn->SetPosition(0, -122); - nameBtn->SetSoundOver(btnSoundOver); - nameBtn->SetSoundClick(btnSoundClick2); - if (!mountMethod) nameBtn->SetToolTip(nameBtnTT, 24, -30, ALIGN_LEFT); - - if (Settings.godmode == 1 && !mountMethod) - { - nameBtn->SetTrigger(trigA); - nameBtn->SetEffectGrow(); - } - - sizeTxt = new GuiText((char*) NULL, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - sizeTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - sizeTxt->SetPosition(-60, 70); - - diskImg = new GuiDiskCover; - diskImg->SetWidescreen(Settings.widescreen); - diskImg->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - diskImg->SetAngle(0); - diskImg2 = new GuiDiskCover; - diskImg2->SetWidescreen(Settings.widescreen); - diskImg2->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - diskImg2->SetPosition(0, -20); - diskImg2->SetAngle(0); - diskImg2->SetBeta(180); - - playcntTxt = new GuiText((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - playcntTxt->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - playcntTxt->SetPosition(-115, 45); - - gameBtn = new GuiButton(160, 160); - gameBtn->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - gameBtn->SetPosition(0, -20); - gameBtn->SetImage(diskImg); - gameBtn->SetSoundOver(btnSoundOver); - gameBtn->SetSoundClick(btnSoundClick2); - gameBtn->SetTrigger(trigA); - gameBtn->SetState(STATE_SELECTED); - - backBtnTxt = new GuiText(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnImg = new GuiImage(btnOutline); - if (Settings.wsprompt) - { - backBtnTxt->SetWidescreen(Settings.widescreen); - backBtnImg->SetWidescreen(Settings.widescreen); - } - backBtn = new GuiButton(backBtnImg, backBtnImg, 1, 5, 0, 0, trigA, btnSoundOver, btnSoundClick2, 1); - backBtn->SetLabel(backBtnTxt); - backBtn->SetTrigger(trigB); - if (Settings.godmode == 1 && mountMethod != 2) - { - backBtn->SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - backBtn->SetPosition(-50, -40); - } - else - { - backBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - backBtn->SetPosition(0, -40); - } - - settingsBtnTxt = new GuiText(tr( "Settings" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - settingsBtnImg = new GuiImage(btnOutline); - if (Settings.wsprompt) - { - settingsBtnTxt->SetWidescreen(Settings.widescreen); - settingsBtnImg->SetWidescreen(Settings.widescreen); - } - settingsBtn = new GuiButton(settingsBtnImg, settingsBtnImg, 0, 4, 50, -40, trigA, btnSoundOver, btnSoundClick2, 1); - settingsBtn->SetLabel(settingsBtnTxt); - - int xPos = -198; - for(int i = 0; i < FAVORITE_STARS; ++i) - { - FavoriteBtnImg[i] = new GuiImage; - FavoriteBtnImg[i]->SetWidescreen(Settings.widescreen); - FavoriteBtn[i] = new GuiButton(imgFavorite->GetWidth(), imgFavorite->GetHeight()); - FavoriteBtn[i]->SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - FavoriteBtn[i]->SetPosition(xPos, -60); - FavoriteBtn[i]->SetImage(FavoriteBtnImg[i]); - FavoriteBtn[i]->SetSoundOver(btnSoundOver); - FavoriteBtn[i]->SetSoundClick(btnSoundClick2); - FavoriteBtn[i]->SetTrigger(trigA); - FavoriteBtn[i]->SetEffectGrow(); - - xPos += 27; - } - - btnLeftImg = new GuiImage(imgLeft); - if (Settings.wsprompt) btnLeftImg->SetWidescreen(Settings.widescreen); - btnLeft = new GuiButton(btnLeftImg, btnLeftImg, 0, 5, 20, 0, trigA, btnSoundOver, btnSoundClick2, 1); - btnLeft->SetTrigger(trigL); - btnLeft->SetTrigger(trigMinus); - - btnRightImg = new GuiImage(imgRight); - if (Settings.wsprompt) btnRightImg->SetWidescreen(Settings.widescreen); - btnRight = new GuiButton(btnRightImg, btnRightImg, 1, 5, -20, 0, trigA, btnSoundOver, btnSoundClick2, 1); - btnRight->SetTrigger(trigR); - btnRight->SetTrigger(trigPlus); - - Append(dialogBoxImg); - Append(playcntTxt); - Append(backBtn); - if (!mountMethod)//stuff we don't show if it is a DVD mounted - { - Append(nameBtn); - Append(sizeTxt); - Append(btnLeft); - Append(btnRight); - for(int i = 0; i < FAVORITE_STARS; ++i) - Append(FavoriteBtn[i]); - } - //check if unlocked - if (Settings.godmode == 1 && mountMethod != 2) - { - Append(settingsBtn); - } - - Append(diskImg2); - Append(gameBtn); //! Appending the disc on top of all - - ChangeGame(NONE); - diskImg->SetImage(diskImgData); - - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); -} - -GameWindow::~GameWindow() -{ - StopEffect(); - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - ResumeGui(); - - while(parentElement && this->GetEffect() > 0) usleep(100); - - HaltGui(); - - if(parentElement) - ((GuiWindow * ) parentElement)->Remove(this); - - RemoveAll(); - - delete trigA; - delete trigB; - delete trigL; - delete trigR; - delete trigPlus; - delete trigMinus; - - delete diskImgData; - delete diskImgData2; - delete dialogBox; - delete btnOutline; - delete imgFavorite; - delete imgNotFavorite; - delete imgLeft; - delete imgRight; - - delete diskImg; - delete diskImg2; - - delete dialogBoxImg; - delete backBtnImg; - delete settingsBtnImg; - delete btnLeftImg; - delete btnRightImg; - - delete nameBtnTT; - - delete sizeTxt; - delete playcntTxt; - delete nameTxt; - delete backBtnTxt; - delete settingsBtnTxt; - - delete nameBtn; - delete gameBtn; - delete backBtn; - delete settingsBtn; - delete btnLeft; - delete btnRight; - - for(int i = 0; i < FAVORITE_STARS; ++i) - { - delete FavoriteBtnImg[i]; - delete FavoriteBtn[i]; - } - - if(gameSound) gameSound->Stop(); - delete gameSound; - bgMusic->SetVolume(Settings.volume); - - ResumeGui(); -} - -void GameWindow::LoadGameSound(const u8 * id) -{ - if (Settings.gamesoundvolume == 0) - return; - - if (gameSound) - { - gameSound->Stop(); - delete gameSound; - gameSound = NULL; - } - - u32 gameSoundDataLen; - const u8 *gameSoundData = LoadBannerSound(id, &gameSoundDataLen); - if (gameSoundData) - { - gameSound = new GuiSound(gameSoundData, gameSoundDataLen, Settings.gamesoundvolume, true); - bgMusic->SetVolume(0); - reducedVol = true; - if (Settings.gamesound == 2) - gameSound->SetLoop(1); - gameSound->Play(); - } -} - -void GameWindow::LoadDiscImage(const u8 * id) -{ - HaltGui(); - delete diskImgData2; - diskImgData2 = diskImgData; - diskImgData = NULL; - - char imgPath[150]; - char IDFull[7]; - char ID3[4]; - char ID4[5]; - snprintf(IDFull, sizeof(IDFull), "%s", (char*) id); - snprintf(ID3, sizeof(ID3), "%s", IDFull); - snprintf(ID4, sizeof(ID4), "%s", IDFull); - - snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.disc_path, IDFull); //changed to current full id - diskImgData = new GuiImageData(imgPath); - - if (!diskImgData->GetImage()) - { - delete diskImgData; - snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.disc_path, ID3); //changed to current id - diskImgData = new GuiImageData(imgPath); - } - if (!diskImgData->GetImage()) - { - delete diskImgData; - snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.disc_path, ID4); //changed to current id - diskImgData = new GuiImageData(imgPath); - } - if (!diskImgData->GetImage()) - { - delete diskImgData; - diskImgData = Resources::GetImageData("nodisc.png"); - } -} - -void GameWindow::SetWindowEffect(int direction, int in_out) -{ - if(direction == LEFT && Settings.xflip == XFLIP_DISK3D) - { - if(in_out == IN) - { - diskImg->SetImage(diskImgData); - diskImg->SetBeta(90); - diskImg->SetBetaRotateEffect(-90, 15); - diskImg2->SetImage(diskImgData2); - diskImg2->SetBeta(270); - diskImg2->SetBetaRotateEffect(-90, 15); - sizeTxt->SetEffect(EFFECT_FADE, 17); - nameTxt->SetEffect(EFFECT_FADE, 17); - } - else - { - diskImg->SetImage(diskImgData2); - diskImg->SetBeta(0); - diskImg->SetBetaRotateEffect(90, 15); - diskImg2->SetImage(diskImgData); - diskImg2->SetAngle(diskImg->GetAngle()); - diskImg2->SetBeta(180); - diskImg2->SetBetaRotateEffect(90, 15); - sizeTxt->SetEffect(EFFECT_FADE, -17); - nameTxt->SetEffect(EFFECT_FADE, -17); - } - } - else if(direction == RIGHT && Settings.xflip == XFLIP_DISK3D) - { - if(in_out == IN) - { - diskImg->SetImage(diskImgData); - diskImg->SetBeta(270); - diskImg->SetBetaRotateEffect(90, 15); - diskImg2->SetImage(diskImgData2); - diskImg2->SetBeta(90); - diskImg2->SetBetaRotateEffect(90, 15); - sizeTxt->SetEffect(EFFECT_FADE, 17); - nameTxt->SetEffect(EFFECT_FADE, 17); - - } - else - { - diskImg->SetImage(diskImgData2); - diskImg->SetBeta(0); - diskImg->SetBetaRotateEffect(-90, 15); - diskImg2->SetImage(diskImgData); - diskImg2->SetAngle(diskImg->GetAngle()); - diskImg2->SetBeta(180); - diskImg2->SetBetaRotateEffect(-90, 15); - sizeTxt->SetEffect(EFFECT_FADE, -17); - nameTxt->SetEffect(EFFECT_FADE, -17); - } - } - else if(direction == LEFT) - { - if(in_out == IN) - SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 50); - else - SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 50); - } - else if(direction == RIGHT) - { - if(in_out == IN) - SetEffect(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_IN, 50); - else - SetEffect(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_OUT, 50); - } - - ResumeGui(); - while(parentElement && (this->GetEffect() > 0 || - nameTxt->GetEffect() > 0 || diskImg->GetBetaRotateEffect())) - { - usleep(100); - } -} - -void GameWindow::ChangeGame(int EffectDirection) -{ - struct discHdr * header = (mountMethod ? dvdheader : gameList[gameSelected]); - LoadGameSound(header->id); - LoadDiscImage(header->id); - SetWindowEffect(EffectDirection, OUT); - - HaltGui(); - - if (!mountMethod) - { - float size = 0.0f; - WBFS_GameSize(header->id, &size); - sizeTxt->SetTextf("%.2fGB", size); //set size text; - } - - diskImg->SetImage(diskImgData); - nameTxt->SetText(GameTitles.GetTitle(header)); - playcntTxt->SetTextf("%s: %i", tr( "Play Count" ), GameStatistics.GetPlayCount(header)); - - int favoritevar = GameStatistics.GetFavoriteRank(header->id); - for(int i = 0; i < FAVORITE_STARS; ++i) - FavoriteBtnImg[i]->SetImage(favoritevar >= i+1 ? imgFavorite : imgNotFavorite); - - EffectDirection = EffectDirection == LEFT ? RIGHT : EffectDirection == RIGHT ? LEFT : NONE; - SetWindowEffect(EffectDirection, IN); -} - -int GameWindow::Show() -{ - int choice = -1; - - while(choice == -1) - { - VIDEO_WaitVSync(); - - choice = MainLoop(); - } - - return choice; -} - -int GameWindow::MainLoop() -{ - diskImg->SetSpin(gameBtn->GetState() == STATE_SELECTED); - diskImg2->SetSpin(gameBtn->GetState() == STATE_SELECTED); - - if (shutdown) //for power button - { - wiilight(0); - Sys_Shutdown(); - } - else if (reset == 1) //for reset button - { - wiilight(0); - Sys_Reboot(); - } - else if (reducedVol) - { - if (gameSound) - { - if (Settings.gamesound == 1 && !gameSound->IsPlaying()) - bgMusic->SetVolume(Settings.volume); - } - else - { - bgMusic->SetVolume(Settings.volume); - } - - reducedVol = false; - } - else if (gameBtn->GetState() == STATE_CLICKED) - { - struct discHdr * header = (mountMethod ? dvdheader : gameList[gameSelected]); - GameStatistics.SetPlayCount(header->id, GameStatistics.GetPlayCount(header->id)+1); - GameStatistics.Save(); - returnVal = 1; - } - else if (backBtn->GetState() == STATE_CLICKED) //back - { - mainWindow->SetState(STATE_DEFAULT); - wiilight(0); - returnVal = 0; - } - - else if(settingsBtn->GetState() == STATE_CLICKED) //settings - { - settingsBtn->ResetState(); - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while(parentElement && this->GetEffect() > 0) usleep(100); - HaltGui(); - if(parentElement) ((GuiWindow *) parentElement)->Remove(this); - ResumeGui(); - - wiilight(0); - int settret = MenuGameSettings(mountMethod ? dvdheader : gameList[gameSelected]); - - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - if(parentElement) - { - ((GuiWindow *) parentElement)->SetState(STATE_DISABLED); - ((GuiWindow *) parentElement)->Append(this); - } - - if (settret == MENU_DISCLIST) - returnVal = 2; - else - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - } - else if (nameBtn->GetState() == STATE_CLICKED) //rename - { - nameBtn->ResetState(); - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while(parentElement && this->GetEffect() > 0) usleep(100); - HaltGui(); - if(parentElement) ((GuiWindow *) parentElement)->Remove(this); - ResumeGui(); - wiilight(0); - //re-evaluate header now in case they changed games while on the game prompt - struct discHdr *header = gameList[gameSelected]; - - //enter new game title - char entered[60]; - snprintf(entered, sizeof(entered), "%s", GameTitles.GetTitle(header)); - int result = OnScreenKeyboard(entered, 60, 0); - if (result == 1) - { - WBFS_RenameGame(header->id, entered); - wString oldFilter(gameList.GetCurrentFilter()); - gameList.ReadGameList(); - gameList.FilterList(oldFilter.c_str()); - } - SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - if(parentElement) - { - ((GuiWindow *) parentElement)->SetState(STATE_DISABLED); - ((GuiWindow *) parentElement)->Append(this); - } - } - - else if (btnRight->GetState() == STATE_CLICKED) //next game - { - if(Settings.xflip == XFLIP_YES) - { - gameSelected = (gameSelected - 1 + gameList.size()) % gameList.size(); - ChangeGame(LEFT); - } - else if(Settings.xflip == XFLIP_SYSMENU) - { - gameSelected = (gameSelected + 1) % gameList.size(); - ChangeGame(LEFT); - } - else - { - gameSelected = (gameSelected + 1) % gameList.size(); - ChangeGame(RIGHT); - } - - btnRight->ResetState(); - } - - else if (btnLeft->GetState() == STATE_CLICKED) //previous game - { - if(Settings.xflip == XFLIP_YES) - { - gameSelected = (gameSelected + 1) % gameList.size(); - ChangeGame(RIGHT); - } - else if(Settings.xflip == XFLIP_SYSMENU) - { - gameSelected = (gameSelected - 1 + gameList.size()) % gameList.size(); - ChangeGame(RIGHT); - } - else - { - gameSelected = (gameSelected - 1 + gameList.size()) % gameList.size(); - ChangeGame(LEFT); - } - - btnLeft->ResetState(); - } - - for(int i = 0; i < FAVORITE_STARS; ++i) - { - if(FavoriteBtn[i]->GetState() == STATE_CLICKED) - { - struct discHdr * header = (mountMethod ? dvdheader : gameList[gameSelected]); - int FavoriteRank = (i+1 == GameStatistics.GetFavoriteRank(header->id)) ? 0 : i+1; // Press the current rank to reset the rank - - GameStatistics.SetFavoriteRank(header->id, FavoriteRank); - GameStatistics.Save(); - for(int j = 0; j < FAVORITE_STARS; ++j) - FavoriteBtnImg[j]->SetImage(FavoriteRank >= j+1 ? imgFavorite : imgNotFavorite); - - FavoriteBtn[i]->ResetState(); - } - } - - return returnVal; -} diff --git a/source/prompts/GameWindow.hpp b/source/prompts/GameWindow.hpp deleted file mode 100644 index a7051e6b..00000000 --- a/source/prompts/GameWindow.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef GAMEWINDOW_HPP_ -#define GAMEWINDOW_HPP_ - -#include "libwiigui/gui.h" -#include "libwiigui/gui_diskcover.h" - -#define FAVORITE_STARS 5 - -class GameWindow : public GuiWindow -{ - public: - GameWindow(int GameSelected); - ~GameWindow(); - int Show(); - int GetSelectedGame() { return gameSelected; }; - protected: - int MainLoop(); - void LoadGameSound(const u8 * id); - void LoadDiscImage(const u8 * id); - void SetWindowEffect(int direction, int in_out); - void ChangeGame(int EffectDirection); - - bool reducedVol; - int returnVal; - int gameSelected; - - GuiTrigger * trigA; - GuiTrigger * trigB; - GuiTrigger * trigL; - GuiTrigger * trigR; - GuiTrigger * trigPlus; - GuiTrigger * trigMinus; - - GuiImageData * diskImgData; - GuiImageData * diskImgData2; - GuiImageData * dialogBox; - GuiImageData * btnOutline; - GuiImageData * imgFavorite; - GuiImageData * imgNotFavorite; - GuiImageData * imgLeft; - GuiImageData * imgRight; - - GuiDiskCover * diskImg; - GuiDiskCover * diskImg2; - - GuiImage * dialogBoxImg; - GuiImage * backBtnImg; - GuiImage * settingsBtnImg; - GuiImage * btnLeftImg; - GuiImage * btnRightImg; - GuiImage * FavoriteBtnImg[FAVORITE_STARS]; - - GuiTooltip * nameBtnTT; - - GuiText * sizeTxt; - GuiText * playcntTxt; - GuiText * nameTxt; - GuiText * backBtnTxt; - GuiText * settingsBtnTxt; - - GuiButton * nameBtn; - GuiButton * gameBtn; - GuiButton * backBtn; - GuiButton * settingsBtn; - GuiButton * btnLeft; - GuiButton * btnRight; - GuiButton * FavoriteBtn[FAVORITE_STARS]; - - GuiSound * gameSound; -}; - -#endif diff --git a/source/prompts/ProgressWindow.cpp b/source/prompts/ProgressWindow.cpp deleted file mode 100644 index c7869cdb..00000000 --- a/source/prompts/ProgressWindow.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/**************************************************************************** - * ProgressWindow - * USB Loader GX 2009 - * - * ProgressWindow.cpp - ***************************************************************************/ -#include -#include -#include -#include -#include -#include - -#include "menu.h" -#include "language/gettext.h" -#include "libwiigui/gui.h" -#include "prompts/ProgressWindow.h" -#include "usbloader/wbfs.h" -#include "usbloader/utils.h" -#include "themes/CTheme.h" - -/*** Variables used only in this file ***/ -static lwp_t progressthread = LWP_THREAD_NULL; -static ProgressAbortCallback AbortCallback = NULL; -static char progressTitle[100]; -static const char * progressMsg1 = NULL; -static const char * progressMsg2 = NULL; -static char progressTime[80]; -static char progressSizeLeft[80]; -static char progressSpeed[15]; -static int showProgress = 0; -static f32 progressDone = 0.0; -static bool showTime = false; -static bool showSize = false; -static bool changed = true; -static s64 gameinstalldone = 0; -static s64 gameinstalltotal = -1; -static time_t start; - -/*** Extern variables ***/ -extern GuiWindow * mainWindow; -extern float gamesize; - -/*** Extern functions ***/ -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; - - if (gameinstalldone > gameinstalltotal) gameinstalldone = gameinstalltotal; - - static u32 expected = 300; - - u32 elapsed, h, m, s; - f32 speed = 0; - - //Elapsed time - elapsed = time(0) - start; - - //Calculate speed in MB/s - if (elapsed > 0) speed = KB_SIZE * gamesize * gameinstalldone / (gameinstalltotal * elapsed); - - if (gameinstalldone != gameinstalltotal) - { - //Expected time - if (elapsed) expected = (expected * 3 + elapsed * gameinstalltotal / gameinstalldone) / 4; - - //Remaining time - elapsed = (expected > elapsed) ? (expected - elapsed) : 0; - } - - //Calculate time values - h = elapsed / 3600; - m = (elapsed / 60) % 60; - s = elapsed % 60; - - progressDone = 100.0 * gameinstalldone / gameinstalltotal; - - snprintf(progressTime, sizeof(progressTime), "%s %d:%02d:%02d", tr( "Time left:" ), h, m, s); - snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%.2fGB/%.2fGB", - gamesize * gameinstalldone / gameinstalltotal, gamesize); - snprintf(progressSpeed, sizeof(progressSpeed), "%.1fMB/s", speed); - - changed = true; -} - -/**************************************************************************** - * SetupGameInstallProgress - ***************************************************************************/ -void SetupGameInstallProgress(char * title, char * game) -{ - - strlcpy(progressTitle, title, sizeof(progressTitle)); - progressMsg1 = game; - gameinstalltotal = 1; - showProgress = 1; - showSize = true; - showTime = true; - LWP_ResumeThread(progressthread); - start = time(0); -} - -/**************************************************************************** - * ProgressWindow - * - * Opens a window, which displays progress to the user. Can either display a - * progress bar showing % completion, or a throbber that only shows that an - * action is in progress. - ***************************************************************************/ -static void ProgressWindow(const char *title, const char *msg1, const char *msg2) -{ - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiImageData progressbarOutline(Resources::GetFile("progressbar_outline.png"), Resources::GetFileSize("progressbar_outline.png")); - - GuiImage progressbarOutlineImg(&progressbarOutline); - if (Settings.wsprompt) - { - progressbarOutlineImg.SetWidescreen(Settings.widescreen); - } - progressbarOutlineImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarOutlineImg.SetPosition(25, 40); - - GuiImageData progressbarEmpty(Resources::GetFile("progressbar_empty.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImage progressbarEmptyImg(&progressbarEmpty); - progressbarEmptyImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarEmptyImg.SetPosition(25, 40); - progressbarEmptyImg.SetTile(100); - - GuiImageData progressbar(Resources::GetFile("progressbar.png"), Resources::GetFileSize("progressbar.png")); - GuiImage progressbarImg(&progressbar); - progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarImg.SetPosition(25, 40); - - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 60); - - GuiText msg1Txt(msg1, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg1Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - if (msg2) - msg1Txt.SetPosition(0, 100); - else - msg1Txt.SetPosition(0, 120); - msg1Txt.SetMaxWidth(430, DOTTED); - - GuiText msg2Txt(msg2, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - msg2Txt.SetPosition(0, 125); - msg2Txt.SetMaxWidth(430, DOTTED); - - GuiText prsTxt("%", 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - prsTxt.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); - prsTxt.SetPosition(-188, 40); - - GuiText timeTxt((char*) NULL, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - timeTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - timeTxt.SetPosition(280, -50); - - GuiText sizeTxt((char*) NULL, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - sizeTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - sizeTxt.SetPosition(50, -50); - - GuiText speedTxt((char*) NULL, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - speedTxt.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - speedTxt.SetPosition(50, -74); - - GuiText prTxt((char*) NULL, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - prTxt.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - prTxt.SetPosition(200, 40); - - if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust for widescreen - { - progressbarOutlineImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - progressbarOutlineImg.SetPosition(0, 40); - progressbarEmptyImg.SetPosition(80, 40); - progressbarEmptyImg.SetTile(78); - progressbarImg.SetPosition(80, 40); - msg1Txt.SetMaxWidth(380, DOTTED); - msg2Txt.SetMaxWidth(380, DOTTED); - - timeTxt.SetPosition(250, -50); - timeTxt.SetFontSize(20); - speedTxt.SetPosition(90, -74); - speedTxt.SetFontSize(20); - sizeTxt.SetPosition(90, -50); - sizeTxt.SetFontSize(20); - } - - GuiText cancelTxt(tr( "Cancel" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage cancelImg(&btnOutline); - if (Settings.wsprompt) - { - cancelTxt.SetWidescreen(Settings.widescreen); - cancelImg.SetWidescreen(Settings.widescreen); - } - GuiButton cancelBtn(&cancelImg, &cancelImg, 2, 4, 0, -45, &trigA, btnSoundOver, btnSoundClick2, 1); - cancelBtn.SetLabel(&cancelTxt); - cancelBtn.SetState(STATE_SELECTED); - - usleep(400000); // wait to see if progress flag changes soon - if (!showProgress) return; - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&progressbarEmptyImg); - promptWindow.Append(&progressbarImg); - promptWindow.Append(&progressbarOutlineImg); - promptWindow.Append(&prTxt); - promptWindow.Append(&prsTxt); - if (title) promptWindow.Append(&titleTxt); - promptWindow.Append(&msg1Txt); - promptWindow.Append(&msg2Txt); - if (showTime) promptWindow.Append(&timeTxt); - if (showSize) - { - promptWindow.Append(&sizeTxt); - promptWindow.Append(&speedTxt); - } - if(AbortCallback) - promptWindow.Append(&cancelBtn); - - HaltGui(); - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - while (promptWindow.GetEffect() > 0) - usleep(100); - - int tmp; - while (showProgress) - { - usleep(100000); - - GameInstallProgress(); - - if (changed) - { - changed = false; - - tmp = static_cast (progressbarImg.GetWidth() * progressDone); - - if (Settings.widescreen && Settings.wsprompt) - progressbarImg.SetSkew(0, 0, static_cast (progressbarImg.GetWidth() * progressDone * 0.8) - - progressbarImg.GetWidth(), 0, static_cast (progressbarImg.GetWidth() * progressDone - * 0.8) - progressbarImg.GetWidth(), 0, 0, 0); - else progressbarImg.SetSkew(0, 0, static_cast (progressbarImg.GetWidth() * progressDone) - - progressbarImg.GetWidth(), 0, static_cast (progressbarImg.GetWidth() * progressDone) - - progressbarImg.GetWidth(), 0, 0, 0); - - prTxt.SetTextf("%.2f", progressDone); - - if (showSize) - { - sizeTxt.SetText(progressSizeLeft); - speedTxt.SetText(progressSpeed); - } - - if (showTime) timeTxt.SetText(progressTime); - - if (progressMsg1) msg1Txt.SetText(progressMsg1); - if (progressMsg2) msg2Txt.SetText(progressMsg2); - } - - if(cancelBtn.GetState() == STATE_CLICKED) - { - if(AbortCallback) AbortCallback(); - cancelBtn.ResetState(); - } - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); -} - -/**************************************************************************** - * ProgressThread - ***************************************************************************/ - -static void * ProgressThread(void *arg) -{ - while (1) - { - if (!showProgress) LWP_SuspendThread(progressthread); - - ProgressWindow(progressTitle, progressMsg1, progressMsg2); - usleep(100); - } - return NULL; -} - -/**************************************************************************** - * ProgressStop - ***************************************************************************/ -void ProgressStop() -{ - showProgress = 0; - strcpy(progressTitle, ""); - progressMsg1 = NULL; - progressMsg2 = NULL; - gameinstalltotal = -1; - - // wait for thread to finish - while (!LWP_ThreadIsSuspended(progressthread)) - usleep(100); -} - -/**************************************************************************** - * ShowProgress - * - * Callbackfunction for updating the progress values - * Use this function as standard callback - ***************************************************************************/ -void ShowProgress(const char *title, const char *msg1, const char *msg2, f32 done, f32 total, bool swSize, bool swTime) -{ - if (total <= 0) - return; - - else if (done > total) done = total; - - showSize = swSize; - showTime = swTime; - - if (title) strlcpy(progressTitle, title, sizeof(progressTitle)); - progressMsg1 = msg1; - progressMsg2 = msg2; - - static u32 expected; - - u32 elapsed, h, m, s, speed = 0; - - if (!done) - { - start = time(0); - expected = 300; - LWP_ResumeThread(progressthread); - } - - //Elapsed time - elapsed = time(0) - start; - - //Calculate speed in KB/s - if (elapsed > 0) speed = done / (elapsed * KB_SIZE); - - if (done != total) - { - //Expected time - if (elapsed) expected = (expected * 3 + elapsed * total / done) / 4; - - //Remaining time - elapsed = (expected > elapsed) ? (expected - elapsed) : 0; - } - - //Calculate time values - h = elapsed / 3600; - m = (elapsed / 60) % 60; - s = elapsed % 60; - - if (swTime == true) - { - snprintf(progressTime, sizeof(progressTime), "%s %d:%02d:%02d", tr( "Time left:" ), h, m, s); - } - - if (swSize == true) - { - if (total < MB_SIZE) - snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fKB/%0.2fKB", done * done / total / KB_SIZE, - total / KB_SIZE); - else if (total > MB_SIZE && total < GB_SIZE) - snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fMB/%0.2fMB", done * done / total / MB_SIZE, - total / MB_SIZE); - else snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fGB/%0.2fGB", done * done / total / GB_SIZE, - total / GB_SIZE); - - snprintf(progressSpeed, sizeof(progressSpeed), "%dKB/s", speed); - } - - showProgress = 1; - progressDone = 100.0 * done / total; - changed = true; -} - -/**************************************************************************** - * ProgressSetAbortCallback - * - * Set a callback for the cancel button - ***************************************************************************/ -void ProgressSetAbortCallback(ProgressAbortCallback callback) -{ - AbortCallback = callback; -} - -/**************************************************************************** - * InitProgressThread - * - * Startup Progressthread in idle prio - ***************************************************************************/ -void InitProgressThread() -{ - LWP_CreateThread(&progressthread, ProgressThread, NULL, NULL, 16384, 80); -} - -/**************************************************************************** - * ExitProgressThread - * - * Shutdown Progressthread - ***************************************************************************/ -void ExitProgressThread() -{ - LWP_JoinThread(progressthread, NULL); - progressthread = LWP_THREAD_NULL; -} diff --git a/source/prompts/ProgressWindow.h b/source/prompts/ProgressWindow.h deleted file mode 100644 index a9729c93..00000000 --- a/source/prompts/ProgressWindow.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * ProgressWindow - * USB Loader GX 2009 - * - * ProgressWindow.h - ***************************************************************************/ - -#ifndef _PROGRESSWINDOW_H_ -#define _PROGRESSWINDOW_H_ - -typedef void (*ProgressAbortCallback)(void); - -void InitProgressThread(); -void ExitProgressThread(); -void SetupGameInstallProgress(char * titl, char * game); -void ShowProgress(const char *title, const char *msg1, const char *msg2, f32 done, f32 total, bool swSize = false, - bool swTime = false); -void ProgressStop(); -void ProgressSetAbortCallback(ProgressAbortCallback callback); - -#ifdef __cplusplus -extern "C" -{ -#endif - - void ProgressCallback(s64 gameinstalldone, s64 gameinstalltotal); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/prompts/PromptWindows.cpp b/source/prompts/PromptWindows.cpp deleted file mode 100644 index 0bafeff4..00000000 --- a/source/prompts/PromptWindows.cpp +++ /dev/null @@ -1,1771 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "usbloader/wbfs.h" -#include "usbloader/wdvd.h" -#include "usbloader/partition_usbloader.h" -#include "usbloader/usbstorage2.h" -#include "usbloader/GameList.h" -#include "usbloader/utils.h" -#include "language/gettext.h" -#include "libwiigui/gui.h" -#include "libwiigui/gui_diskcover.h" -#include "libwiigui/Text.hpp" -#include "settings/CGameStatistics.h" -#include "settings/GameTitles.h" -#include "network/networkops.h" -#include "network/update.h" -#include "network/http.h" -#include "prompts/PromptWindows.h" -#include "prompts/gameinfo.h" -#include "themes/CTheme.h" -#include "utils/StringTools.h" -#include "mload/mload.h" -#include "fatmounter.h" -#include "FileOperations/fileops.h" -#include "menu.h" -#include "menu.h" -#include "filelist.h" -#include "sys.h" -#include "wpad.h" -#include "wad/wad.h" -#include "zlib.h" -#include "svnrev.h" -#include "audio.h" -#include "xml/xml.h" -#include "language/UpdateLanguage.h" -#include "gecko.h" -#include "lstub.h" -#include "bannersound.h" -#include "buildtype.h" - -/*** Extern variables ***/ -s32 gameStart = 0; -extern float gamesize; -extern u8 shutdown; -extern u8 reset; -extern u8 mountMethod; -extern struct discHdr *dvdheader; -extern char game_partition[6]; -extern int connection; - -/**************************************************************************** - * OnScreenNumpad - * - * Opens an on-screen numpad window, with the data entered being stored - * into the specified variable. - ***************************************************************************/ -int OnScreenNumpad(char * var, u32 maxlen) -{ - int save = -1; - - GuiNumpad numpad(var, maxlen); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetSimpleTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText okBtnTxt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage okBtnImg(&btnOutline); - if (Settings.wsprompt) - { - okBtnTxt.SetWidescreen(Settings.widescreen); - okBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton okBtn(&okBtnImg, &okBtnImg, 0, 4, 5, -15, &trigA, btnSoundOver, btnSoundClick2, 1); - okBtn.SetLabel(&okBtnTxt); - GuiText cancelBtnTxt(tr( "Cancel" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage cancelBtnImg(&btnOutline); - if (Settings.wsprompt) - { - cancelBtnTxt.SetWidescreen(Settings.widescreen); - cancelBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton cancelBtn(&cancelBtnImg, &cancelBtnImg, 1, 4, -5, -15, &trigA, btnSoundOver, btnSoundClick2, 1); - cancelBtn.SetLabel(&cancelBtnTxt); - cancelBtn.SetTrigger(&trigB); - - numpad.Append(&okBtn); - numpad.Append(&cancelBtn); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&numpad); - mainWindow->ChangeFocus(&numpad); - ResumeGui(); - - while (save == -1) - { - VIDEO_WaitVSync(); - - if (okBtn.GetState() == STATE_CLICKED) - save = 1; - else if (cancelBtn.GetState() == STATE_CLICKED) save = 0; - } - - if (save == 1) - { - snprintf(var, maxlen, "%s", numpad.kbtextstr); - } - - HaltGui(); - mainWindow->Remove(&numpad); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - gprintf("\t%s", (save == 1 ? "saved" : "discarded")); - return save; -} - -/**************************************************************************** - * OnScreenKeyboard - * - * Opens an on-screen keyboard window, with the data entered being stored - * into the specified variable. - ***************************************************************************/ -int OnScreenKeyboard(char * var, u32 maxlen, int min) -{ - - int save = -1; - - gprintf("\nOnScreenKeyboard(%s, %i, %i) \n\tkeyset = %i", var, maxlen, min, Settings.keyset); - - GuiKeyboard keyboard(var, maxlen, min, Settings.keyset); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetSimpleTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText okBtnTxt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage okBtnImg(&btnOutline); - if (Settings.wsprompt) - { - okBtnTxt.SetWidescreen(Settings.widescreen); - okBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton okBtn(&okBtnImg, &okBtnImg, 0, 4, 5, 15, &trigA, btnSoundOver, btnSoundClick2, 1); - okBtn.SetLabel(&okBtnTxt); - GuiText cancelBtnTxt(tr( "Cancel" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage cancelBtnImg(&btnOutline); - if (Settings.wsprompt) - { - cancelBtnTxt.SetWidescreen(Settings.widescreen); - cancelBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton cancelBtn(&cancelBtnImg, &cancelBtnImg, 1, 4, -5, 15, &trigA, btnSoundOver, btnSoundClick2, 1); - cancelBtn.SetLabel(&cancelBtnTxt); - cancelBtn.SetTrigger(&trigB); - - keyboard.Append(&okBtn); - keyboard.Append(&cancelBtn); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&keyboard); - mainWindow->ChangeFocus(&keyboard); - ResumeGui(); - - while (save == -1) - { - VIDEO_WaitVSync(); - - if (okBtn.GetState() == STATE_CLICKED) - save = 1; - else if (cancelBtn.GetState() == STATE_CLICKED) save = 0; - } - - if (save) - { - snprintf(var, maxlen, "%s", keyboard.kbtextstr); - } - - HaltGui(); - mainWindow->Remove(&keyboard); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - gprintf("\t%s", (save ? "saved" : "discarded")); - return save; -} - -/**************************************************************************** - * WindowCredits - * Display credits - ***************************************************************************/ -void WindowCredits() -{ - gprintf("WindowCredits()\n"); - - int angle = 0; - GuiSound * creditsMusic = NULL; - - bgMusic->Pause(); - - creditsMusic = new GuiSound(credits_music_ogg, credits_music_ogg_size, 55); - creditsMusic->SetVolume(60); - creditsMusic->SetLoop(1); - creditsMusic->Play(); - - bool exit = false; - int i = 0; - int y = 20; - - GuiWindow creditsWindow(screenwidth, screenheight); - GuiWindow creditsWindowBox(580, 448); - creditsWindowBox.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - - GuiImageData creditsBox(credits_bg_png, credits_bg_png_size); - GuiImage creditsBoxImg(&creditsBox); - creditsBoxImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - creditsWindowBox.Append(&creditsBoxImg); - - GuiImageData star(little_star_png, little_star_png_size); - GuiImage starImg(&star); - starImg.SetWidescreen(Settings.widescreen); //added - starImg.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - starImg.SetPosition(505, 350); - - int numEntries = 21; - GuiText * txt[numEntries]; - - txt[i] = new GuiText(tr( "Credits" ), 26, ( GXColor ) - { 255, 255, 255, 255}); - txt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - txt[i]->SetPosition(0, 12); - i++; - -#ifdef FULLCHANNEL - char svnTmp[4];//did this to hide the M after the rev# that is made by altering it - //to be ready to be in a full channel - snprintf( svnTmp, sizeof( svnTmp ), "%s", GetRev() ); - char SvnRev[30]; - snprintf( SvnRev, sizeof( SvnRev ), "Rev%sc IOS%u (Rev %u)", svnTmp, IOS_GetVersion(), IOS_GetRevision() ); -#else - char SvnRev[30]; - snprintf(SvnRev, sizeof(SvnRev), "Rev%s IOS%u (Rev %u)", GetRev(), IOS_GetVersion(), IOS_GetRevision()); -#endif - - txt[i] = new GuiText(SvnRev, 16, ( GXColor ) - { 255, 255, 255, 255}); - txt[i]->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - txt[i]->SetPosition(0, y); - i++; - y += 34; - - txt[i] = new GuiText("USB Loader GX", 24, ( GXColor ) - { 255, 255, 255, 255}); - txt[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - txt[i]->SetPosition(0, y); - i++; - y += 26; - - txt[i] = new GuiText(tr( "Official Site:" ), 20, ( GXColor ) - { 255, 255, 255, 255}); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(10, y); - i++; - - txt[i] = new GuiText("http://code.google.com/p/usbloader-gui/", 20, ( GXColor ) - { 255, 255, 255, 255}); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 26; - - GuiText::SetPresets(22, ( GXColor ) {255, 255, 255, 255}, 3000, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP, ALIGN_LEFT, ALIGN_TOP); - - txt[i] = new GuiText(tr( "Coding:" )); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(10, y); - i++; - - txt[i] = new GuiText("dimok / nIxx / giantpune / ardi"); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 22; - - txt[i] = new GuiText("hungyip84 / DrayX7 / lustar / r-win"); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 26; - - char text[100]; - - txt[i] = new GuiText(tr( "Design:" )); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(10, y); - i++; - - txt[i] = new GuiText("cyrex / NeoRame"); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 26; - - txt[i] = new GuiText(tr( "Big thanks to:" )); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(10, y); - i++; - - sprintf(text, "lustar %s", tr( "for WiiTDB and hosting covers / disc images" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 22; - - sprintf(text, "CorneliousJD %s", tr( "for hosting the update files" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 22; - - sprintf(text, "Kinyo %s", tr( "and translaters for language files updates" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 22; - - sprintf(text, "Deak Phreak %s", tr( "for hosting the themes" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(160, y); - i++; - y += 26; - - txt[i] = new GuiText(tr( "Special thanks to:" )); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(10, y); - i++; - y += 22; - - sprintf(text, "Waninkoko, Kwiirk & Hermes %s", tr( "for the USB Loader source" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(60, y); - i++; - y += 22; - - sprintf(text, "Tantric %s", tr( "for his awesome tool LibWiiGui" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(60, y); - i++; - y += 22; - - sprintf(text, "Fishears/Nuke %s", tr( "for Ocarina" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(60, y); - i++; - y += 22; - - sprintf(text, "WiiPower %s", tr( "for diverse patches" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(60, y); - i++; - y += 22; - - sprintf(text, "Oggzee %s", tr( "for FAT/NTFS support" )); - txt[i] = new GuiText(text); - txt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - txt[i]->SetPosition(60, y); - i++; - y += 22; - - for (i = 0; i < numEntries; i++) - creditsWindowBox.Append(txt[i]); - - creditsWindow.Append(&creditsWindowBox); - creditsWindow.Append(&starImg); - - creditsWindow.SetEffect(EFFECT_FADE, 30); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&creditsWindow); - ResumeGui(); - - while (!exit) - { - angle++; - if (angle > 360) angle = 0; - usleep(12000); - starImg.SetAngle(angle); - if (ButtonsPressed() != 0) exit = true; - - } - - creditsMusic->Stop(); - - delete creditsMusic; - - creditsWindow.SetEffect(EFFECT_FADE, -30); - while (creditsWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&creditsWindow); - mainWindow->SetState(STATE_DEFAULT); - for (i = 0; i < numEntries; i++) - { - delete txt[i]; - txt[i] = NULL; - } - ResumeGui(); - - bgMusic->Resume(); -} - -/**************************************************************************** - * WindowScreensaver - * Display screensaver - ***************************************************************************/ -int WindowScreensaver() -{ - gprintf("WindowScreenSaver()\n"); - bool exit = false; - - /* initialize random seed: */ - srand(time(NULL)); - - GuiImageData GXlogo(Resources::GetFile("gxlogo.png"), Resources::GetFileSize("gxlogo.png"));//uncomment for themable screensaver - //GuiImageData GXlogo(gxlogo_png);//comment for themable screensaver - GuiImage GXlogoImg(&GXlogo); - GXlogoImg.SetPosition(172, 152); - GXlogoImg.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - - GuiImage BackgroundImg(640, 480, ( GXColor ) {0, 0, 0, 255}); - BackgroundImg.SetPosition(0, 0); - BackgroundImg.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - - GuiWindow screensaverWindow(screenwidth, screenheight); - screensaverWindow.Append(&BackgroundImg); - screensaverWindow.Append(&GXlogoImg); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&screensaverWindow); - ResumeGui(); - - while (!exit) - { - if (IsWpadConnected()) - { - exit = true; - break; - } - /* Set random position */ - GXlogoImg.SetPosition((rand() % 345), (rand() % 305)); - - sleep(4); - } - - HaltGui(); - mainWindow->Remove(&screensaverWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - return 1; -} - -/**************************************************************************** - * WindowPrompt - * - * Displays a prompt window to user, with information, an error message, or - * presenting a user with a choice of up to 4 Buttons. - * - * Give him 1 Title, 1 Subtitle and 4 Buttons - * If title/subtitle or one of the buttons is not needed give him a 0 on that - * place. - ***************************************************************************/ -int WindowPrompt(const char *title, const char *msg, const char *btn1Label, const char *btn2Label, - const char *btn3Label, const char *btn4Label, int wait) -{ - int choice = -1; - int count = wait; - gprintf("WindowPrompt( %s, %s, %s, %s, %s, %s, %i ): ", title, msg, btn1Label, btn2Label, btn3Label, btn4Label, - wait); - - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 55); - GuiText msgTxt(msg, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - msgTxt.SetPosition(0, -40); - msgTxt.SetMaxWidth(430); - - GuiText btn1Txt(btn1Label, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - - GuiButton btn1(&btn1Img, &btn1Img, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - GuiText btn2Txt(btn2Label, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn2Img(&btnOutline); - if (Settings.wsprompt) - { - btn2Txt.SetWidescreen(Settings.widescreen); - btn2Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn2(&btn2Img, &btn2Img, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn2.SetLabel(&btn2Txt); - if (!btn3Label && !btn4Label) btn2.SetTrigger(&trigB); - - GuiText btn3Txt(btn3Label, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn3Img(&btnOutline); - if (Settings.wsprompt) - { - btn3Txt.SetWidescreen(Settings.widescreen); - btn3Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn3(&btn3Img, &btn3Img, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn3.SetLabel(&btn3Txt); - if (!btn4Label) btn3.SetTrigger(&trigB); - - GuiText btn4Txt(btn4Label, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn4Img(&btnOutline); - if (Settings.wsprompt) - { - btn4Txt.SetWidescreen(Settings.widescreen); - btn4Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn4(&btn4Img, &btn4Img, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn4.SetLabel(&btn4Txt); - if (btn4Label) btn4.SetTrigger(&trigB); - - if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust buttons for widescreen - { - msgTxt.SetMaxWidth(330); - - if (btn2Label && !btn3Label && !btn4Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(70, -80); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-70, -80); - btn3.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn3.SetPosition(-70, -55); - btn4.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn4.SetPosition(70, -55); - } - else if (btn2Label && btn3Label && !btn4Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(70, -120); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-70, -120); - btn3.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn3.SetPosition(0, -55); - btn4.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn4.SetPosition(70, -55); - } - else if (btn2Label && btn3Label && btn4Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(70, -120); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-70, -120); - btn3.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn3.SetPosition(70, -55); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-70, -55); - } - else if (!btn2Label && btn3Label && btn4Label) - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -120); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-70, -120); - btn3.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn3.SetPosition(70, -55); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-70, -55); - } - else - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -80); - btn2.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn2.SetPosition(70, -120); - btn3.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn3.SetPosition(-70, -55); - btn4.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn4.SetPosition(70, -55); - } - } - else - { - - if (btn2Label && !btn3Label && !btn4Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(40, -45); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-40, -45); - btn3.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn3.SetPosition(50, -65); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-50, -65); - } - else if (btn2Label && btn3Label && !btn4Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(50, -120); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-50, -120); - btn3.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn3.SetPosition(0, -65); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-50, -65); - } - else if (btn2Label && btn3Label && btn4Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(50, -120); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-50, -120); - btn3.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn3.SetPosition(50, -65); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-50, -65); - } - else if (!btn2Label && btn3Label && btn4Label) - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -120); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-50, -120); - btn3.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn3.SetPosition(50, -65); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-50, -65); - } - else - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -45); - btn2.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn2.SetPosition(50, -120); - btn3.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn3.SetPosition(50, -65); - btn4.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn4.SetPosition(-50, -65); - } - - } - - GuiTrigger trigZ; - trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); - - GuiButton screenShotBtn(0, 0); - screenShotBtn.SetPosition(0, 0); - screenShotBtn.SetTrigger(&trigZ); - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msgTxt); - promptWindow.Append(&screenShotBtn); - - if (btn1Label) promptWindow.Append(&btn1); - if (btn2Label) promptWindow.Append(&btn2); - if (btn3Label) promptWindow.Append(&btn3); - if (btn4Label) promptWindow.Append(&btn4); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - while (choice == -1) - { - VIDEO_WaitVSync(); - if (shutdown == 1) - { - wiilight(0); - Sys_Shutdown(); - } - if (reset == 1) Sys_Reboot(); - if (btn1.GetState() == STATE_CLICKED) - { - choice = 1; - } - else if (btn2.GetState() == STATE_CLICKED) - { - if (!btn3Label) - choice = 0; - else choice = 2; - } - else if (btn3.GetState() == STATE_CLICKED) - { - if (!btn4Label) - choice = 0; - else choice = 3; - } - else if (btn4.GetState() == STATE_CLICKED) - { - choice = 0; - } - else if (screenShotBtn.GetState() == STATE_CLICKED) - { - screenShotBtn.ResetState(); - ScreenShot(); - } - if (count > 0) count--; - if (count == 0) choice = 1; - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - gprintf(" %i\n", choice); - - return choice; -} - -/**************************************************************************** - * WindowExitPrompt - * - * Displays a prompt window to user, with information, an error message, or - * presenting a user with a choice of up to 4 Buttons. - * - * Give him 1 Titel, 1 Subtitel and 4 Buttons - * If titel/subtitle or one of the buttons is not needed give him a 0 on that - * place. - ***************************************************************************/ -int WindowExitPrompt() -{ - gprintf("WindowExitPrompt()\n"); - - GuiSound * homein = NULL; - homein = new GuiSound(menuin_ogg, menuin_ogg_size, Settings.sfxvolume); - homein->SetVolume(Settings.sfxvolume); - homein->SetLoop(0); - homein->Play(); - - GuiSound * homeout = NULL; - homeout = new GuiSound(menuout_ogg, menuout_ogg_size, Settings.sfxvolume); - homeout->SetVolume(Settings.sfxvolume); - homeout->SetLoop(0); - - int choice = -1; - - u64 oldstub = getStubDest(); - loadStub(); - if (oldstub != 0x00010001554c4e52ll && oldstub != 0x00010001554e454fll) Set_Stub(oldstub); - - GuiWindow promptWindow(640, 480); - promptWindow.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - promptWindow.SetPosition(0, 0); - GuiImageData top(exit_top_png, exit_top_png_size); - GuiImageData topOver(exit_top_over_png, exit_top_over_png_size); - GuiImageData bottom(exit_bottom_png, exit_bottom_png_size); - GuiImageData bottomOver(exit_bottom_over_png, exit_bottom_over_png_size); - GuiImageData button(exit_button_png, exit_button_png_size); - GuiImageData wiimote(wiimote_png, wiimote_png_size); - GuiImageData close(closebutton_png, closebutton_png_size); - - GuiImageData battery(Resources::GetFile("battery_white.png"), Resources::GetFileSize("battery_white.png")); - GuiImageData batteryBar(Resources::GetFile("battery_bar_white.png"), Resources::GetFileSize("battery_bar_white.png")); - GuiImageData batteryRed(Resources::GetFile("battery_red.png"), Resources::GetFileSize("battery_red.png")); - GuiImageData batteryBarRed(Resources::GetFile("battery_bar_red.png"), Resources::GetFileSize("battery_bar_red.png")); - - int i = 0, ret = 0, level; - char txt[3]; - GuiText * batteryTxt[4]; - GuiImage * batteryImg[4]; - GuiImage * batteryBarImg[4]; - GuiButton * batteryBtn[4]; - - for (i = 0; i < 4; i++) - { - sprintf(txt, "P%d", i + 1); - - batteryTxt[i] = new GuiText(txt, 22, ( GXColor ) {255, 255, 255, 255}); - batteryTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - batteryImg[i] = new GuiImage(&battery); - batteryImg[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - batteryImg[i]->SetPosition(36, 0); - batteryImg[i]->SetTile(0); - batteryBarImg[i] = new GuiImage(&batteryBar); - batteryBarImg[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - batteryBarImg[i]->SetPosition(33, 0); - - batteryBtn[i] = new GuiButton(40, 20); - batteryBtn[i]->SetLabel(batteryTxt[i]); - batteryBtn[i]->SetImage(batteryBarImg[i]); - batteryBtn[i]->SetIcon(batteryImg[i]); - batteryBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - batteryBtn[i]->SetRumble(false); - batteryBtn[i]->SetAlpha(70); - batteryBtn[i]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 50); - } - - batteryBtn[0]->SetPosition(180, 150); - batteryBtn[1]->SetPosition(284, 150); - batteryBtn[2]->SetPosition(388, 150); - batteryBtn[3]->SetPosition(494, 150); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - - GuiText titleTxt(tr( "HOME Menu" ), 36, ( GXColor ) {255, 255, 255, 255}); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(-180, 40); - titleTxt.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - GuiText closeTxt(tr( "Close" ), 28, ( GXColor ) {0, 0, 0, 255}); - closeTxt.SetPosition(10, 3); - GuiImage closeImg(&close); - if (Settings.wsprompt) - { - closeTxt.SetWidescreen(Settings.widescreen); - closeImg.SetWidescreen(Settings.widescreen); - } - GuiButton closeBtn(close.GetWidth(), close.GetHeight()); - closeBtn.SetImage(&closeImg); - closeBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - closeBtn.SetPosition(190, 30); - closeBtn.SetLabel(&closeTxt); - closeBtn.SetRumble(false); - closeBtn.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - GuiImage btn1Img(&top); - GuiImage btn1OverImg(&topOver); - GuiButton btn1(&btn1Img, &btn1OverImg, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 0); - btn1.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - GuiText btn2Txt(tr( "Back to Loader" ), 28, ( GXColor ) {0, 0, 0, 255}); - GuiImage btn2Img(&button); - if (Settings.wsprompt) - { - btn2Txt.SetWidescreen(Settings.widescreen); - btn2Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn2(&btn2Img, &btn2Img, 2, 5, -150, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn2.SetLabel(&btn2Txt); - btn2.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 50); - btn2.SetRumble(false); - btn2.SetPosition(-150, 0); - - GuiText btn3Txt(tr( "Wii Menu" ), 28, ( GXColor ) {0, 0, 0, 255}); - GuiImage btn3Img(&button); - if (Settings.wsprompt) - { - btn3Txt.SetWidescreen(Settings.widescreen); - btn3Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn3(&btn3Img, &btn3Img, 2, 5, 150, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn3.SetLabel(&btn3Txt); - btn3.SetEffect(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_IN, 50); - btn3.SetRumble(false); - btn3.SetPosition(150, 0); - - GuiImage btn4Img(&bottom); - GuiImage btn4OverImg(&bottomOver); - GuiButton btn4(&btn4Img, &btn4OverImg, 0, 4, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 0); - btn4.SetTrigger(&trigB); - btn4.SetTrigger(&trigHome); - btn4.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 50); - - GuiImage wiimoteImg(&wiimote); - if (Settings.wsprompt) - { - wiimoteImg.SetWidescreen(Settings.widescreen); - } - wiimoteImg.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiimoteImg.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_IN, 50); - wiimoteImg.SetPosition(50, 210); - - promptWindow.Append(&btn2); - promptWindow.Append(&btn3); - promptWindow.Append(&btn4); - promptWindow.Append(&btn1); - promptWindow.Append(&closeBtn); - promptWindow.Append(&titleTxt); - promptWindow.Append(&wiimoteImg); - - promptWindow.Append(batteryBtn[0]); - promptWindow.Append(batteryBtn[1]); - promptWindow.Append(batteryBtn[2]); - promptWindow.Append(batteryBtn[3]); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - while (choice == -1) - { - VIDEO_WaitVSync(); - - for (i = 0; i < 4; i++) - { - if (WPAD_Probe(i, NULL) == WPAD_ERR_NONE) // controller connected - { - level = (userInput[i].wpad.battery_level / 100.0) * 4; - if (level > 4) level = 4; - - if (level <= 1) - { - batteryBarImg[i]->SetImage(&batteryBarRed); - batteryImg[i]->SetImage(&batteryRed); - } - else - { - batteryBarImg[i]->SetImage(&batteryBar); - } - - batteryImg[i]->SetTile(level); - - batteryBtn[i]->SetAlpha(255); - } - else // controller not connected - { - batteryImg[i]->SetTile(0); - batteryImg[i]->SetImage(&battery); - batteryBtn[i]->SetAlpha(70); - } - } - - if (shutdown == 1) - { - wiilight(0); - Sys_Shutdown(); - } - if (reset == 1) Sys_Reboot(); - if (btn1.GetState() == STATE_CLICKED) - { - choice = 1; - btn1.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - closeBtn.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - btn4.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50); - btn2.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 50); - btn3.SetEffect(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_OUT, 50); - titleTxt.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - wiimoteImg.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50); - - for (int i = 0; i < 4; i++) - batteryBtn[i]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50); - - } - else if (btn4.GetState() == STATE_SELECTED) - { - wiimoteImg.SetPosition(50, 165); - } - else if (btn2.GetState() == STATE_CLICKED) - { - ret = WindowPrompt(tr( "Are you sure?" ), 0, tr( "Yes" ), tr( "No" )); - if (ret == 1) - choice = 2; - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - promptWindow.SetState(STATE_DEFAULT); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - btn2.ResetState(); - } - else if (btn3.GetState() == STATE_CLICKED) - { - ret = WindowPrompt(tr( "Are you sure?" ), 0, tr( "Yes" ), tr( "No" )); - if (ret == 1) - choice = 3; - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - promptWindow.SetState(STATE_DEFAULT); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - btn3.ResetState(); - } - else if (btn4.GetState() == STATE_CLICKED) - { - btn1.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - closeBtn.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - btn4.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50); - btn2.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 50); - btn3.SetEffect(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_OUT, 50); - titleTxt.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - wiimoteImg.SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50); - - for (int i = 0; i < 4; i++) - batteryBtn[i]->SetEffect(EFFECT_SLIDE_BOTTOM | EFFECT_SLIDE_OUT, 50); - - choice = 0; - } - else if (btn4.GetState() != STATE_SELECTED) - { - wiimoteImg.SetPosition(50, 210); - } - } - homeout->Play(); - while (btn1.GetEffect() > 0) - usleep(100); - while (promptWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - homein->Stop(); - delete homein; - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - while (homeout->IsPlaying() > 0) - usleep(100); - homeout->Stop(); - delete homeout; - - for(int i = 0; i < 4; ++i) - { - delete batteryTxt[i]; - delete batteryImg[i]; - delete batteryBarImg[i]; - delete batteryBtn[i]; - } - - ResumeGui(); - return choice; -} - -/**************************************************************************** - * DiscWait - ***************************************************************************/ -int DiscWait(const char *title, const char *msg, const char *btn1Label, const char *btn2Label, int IsDeviceWait) -{ - int ret = 0; - u32 cover = 0; - - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 60); - GuiText msgTxt(msg, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - msgTxt.SetPosition(0, -40); - msgTxt.SetMaxWidth(430); - - GuiText btn1Txt(btn1Label, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn1(&btn1Img, &btn1Img, 1, 5, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - - if (btn2Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(40, -45); - } - else - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -45); - } - - btn1.SetLabel(&btn1Txt); - btn1.SetTrigger(&trigB); - btn1.SetState(STATE_SELECTED); - - GuiText btn2Txt(btn2Label, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn2Img(&btnOutline); - if (Settings.wsprompt) - { - btn2Txt.SetWidescreen(Settings.widescreen); - btn2Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn2(&btn2Img, &btn2Img, 1, 4, -20, -25, &trigA, btnSoundOver, btnSoundClick2, 1); - btn2.SetLabel(&btn2Txt); - - if (Settings.wsprompt && Settings.widescreen) /////////////adjust buttons for widescreen - { - msgTxt.SetMaxWidth(380); - if (btn2Label) - { - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn2.SetPosition(-70, -80); - btn1.SetPosition(70, -80); - } - else - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -80); - } - } - - GuiText timerTxt((char*) NULL, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - timerTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - timerTxt.SetPosition(0, 160); - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msgTxt); - - if (btn1Label) promptWindow.Append(&btn1); - if (btn2Label) promptWindow.Append(&btn2); - if (IsDeviceWait) promptWindow.Append(&timerTxt); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - if (IsDeviceWait) - { - time_t starttime = time(0); - time_t timenow = starttime; - do - { - gprintf("%i\n", (int) (timenow-starttime)); - ret = WBFS_Init(WBFS_DEVICE_USB); - if (ret >= 0) break; - - timerTxt.SetTextf("%i %s", (int) (30-(timenow-starttime)), tr( "seconds left" )); - USBDevice_deInit(); - USBDevice_Init(); - timenow = time(0); - } - while (timenow-starttime < 30); - } - else - { - while (!(cover & 0x2)) - { - VIDEO_WaitVSync(); - if (btn1.GetState() == STATE_CLICKED) - { - btn1.ResetState(); - break; - } - ret = WDVD_GetCoverStatus(&cover); - if (ret < 0) break; - } - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - return ret; -} - -/**************************************************************************** - * FormatingPartition - ***************************************************************************/ -int FormatingPartition(const char *title, partitionEntry *entry) -{ - extern PartList partitions; - - char text[255]; - sprintf(text, "%s: %.2fGB", tr( "Partition" ), entry->size * (partitions.sector_size / GB_SIZE)); - int choice = WindowPrompt(tr( "Do you want to format:" ), text, tr( "Yes" ), tr( "No" )); - if (choice == 0) - return -666; - - int ret; - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 60); - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - VIDEO_WaitVSync(); - ret = WBFS_Format(entry->sector, entry->size); - - if (ret < 0) - { - WindowPrompt(tr( "Error !" ), tr( "Failed formating" ), tr( "Return" )); - } - else - { - sleep(1); - ret = WBFS_Open(); - sprintf(text, "%s %s", text, tr( "formatted!" )); - WindowPrompt(tr( "Success:" ), text, tr( "OK" )); - if (ret < 0) - { - WindowPrompt(tr( "ERROR" ), tr( "Failed to open partition" ), tr( "OK" )); - Sys_LoadMenu(); - } - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - return ret; -} - -/**************************************************************************** - * NetworkInitPrompt - ***************************************************************************/ -bool NetworkInitPrompt() -{ - - gprintf("\nNetworkinitPrompt()"); - if (IsNetworkInit()) return true; - - bool success = true; - - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiText titleTxt(tr( "Initializing Network" ), 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 60); - - char msg[20] = " "; - GuiText msgTxt(msg, 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - msgTxt.SetPosition(0, -40); - - GuiText btn1Txt(tr( "Cancel" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -45, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust buttons for widescreen - { - btn1.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - btn1.SetPosition(0, -80); - } - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msgTxt); - promptWindow.Append(&btn1); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - while (!IsNetworkInit()) - { - - VIDEO_WaitVSync(); - - Initialize_Network(); - - if (!IsNetworkInit()) - { - msgTxt.SetText(tr( "Could not initialize network!" )); - sleep(3); - success = false; - break; - } - - if (btn1.GetState() == STATE_CLICKED) - { - btn1.ResetState(); - success = false; - break; - } - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - return success; -} - -int CodeDownload(const char *id) -{ - int ret = 0; - - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - char title[50]; - sprintf(title, "%s", tr( "Code Download" )); - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 50); - char msg[50]; - sprintf(msg, "%s", tr( "Initializing Network" )); - GuiText msgTxt(msg, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - msgTxt.SetPosition(0, 140); - char msg2[50] = " "; - GuiText msg2Txt(msg2, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - msg2Txt.SetPosition(0, 50); - - GuiText btn1Txt(tr( "Cancel" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -40, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msgTxt); - promptWindow.Append(&msg2Txt); - promptWindow.Append(&btn1); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - struct stat st; - if (stat(Settings.TxtCheatcodespath, &st) != 0) - { - if (!CreateSubfolder(Settings.TxtCheatcodespath)) - { - WindowPrompt(tr( "Error !" ), tr( "Can't create directory" ), tr( "OK" )); - ret = -1; - goto exit; - } - } - - while (!IsNetworkInit()) - { - - VIDEO_WaitVSync(); - - Initialize_Network(); - - if (IsNetworkInit()) - { - msgTxt.SetText(GetNetworkIP()); - } - else - { - msgTxt.SetText(tr( "Could not initialize network!" )); - } - if (btn1.GetState() == STATE_CLICKED) - { - ret = -1; - btn1.ResetState(); - goto exit; - } - } - - if (IsNetworkInit() && ret >= 0) - { - - char txtpath[150]; - snprintf(txtpath, sizeof(txtpath), "%s%s.txt", Settings.TxtCheatcodespath, id); - - char codeurl[150]; - snprintf(codeurl, sizeof(codeurl), "http://geckocodes.org/codes/R/%s.txt", id); - - struct block file = downloadfile(codeurl); - - if (file.size == 333 || file.size == 216 || file.size == 284) - { - strcat(codeurl, tr( " is not on the server." )); - - WindowPrompt(tr( "Error" ), codeurl, tr( "OK" )); - ret = -1; - goto exit; - } - - if (file.data != NULL) - { - - FILE * pfile; - pfile = fopen(txtpath, "wb"); - fwrite(file.data, 1, file.size, pfile); - fclose(pfile); - free(file.data); - ret = 1; - strcat( - txtpath, - tr( " has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." )); - - WindowPrompt(0, txtpath, tr( "OK" )); - } - else - { - strcat(codeurl, tr( " could not be downloaded." )); - - WindowPrompt(tr( "Error" ), codeurl, tr( "OK" )); - ret = -1; - } - - CloseConnection(); - } - exit: promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - return ret; -} - -/**************************************************************************** - * HBCWindowPrompt - * - * Displays a prompt window to user, with information, an error message, or - * presenting a user with a choice of up to 2 Buttons. - * - ***************************************************************************/ -int HBCWindowPrompt(const char *name, const char *coder, const char *version, const char *release_date, - const char *long_description, GuiImageData * iconImgData, u64 filesize) -{ - int choice = -1; - - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, 6); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiTrigger trigU; - trigU.SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); - GuiTrigger trigD; - trigD.SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiImageData whiteBox(Resources::GetFile("bg_options.png"), Resources::GetFileSize("bg_options.png")); - - GuiImageData scrollbar(Resources::GetFile("scrollbar.png"), Resources::GetFileSize("scrollbar.png")); - GuiImage scrollbarImg(&scrollbar); - scrollbarImg.SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - scrollbarImg.SetPosition(-40, 114); - scrollbarImg.SetSkew(0, 0, 0, 0, 0, -120, 0, -120); - - GuiImageData arrowDown(Resources::GetFile("scrollbar_arrowdown.png"), Resources::GetFileSize("scrollbar_arrowdown.png")); - GuiImage arrowDownImg(&arrowDown); - arrowDownImg.SetScale(.8); - - GuiImageData arrowUp(Resources::GetFile("scrollbar_arrowup.png"), Resources::GetFileSize("scrollbar_arrowup.png")); - GuiImage arrowUpImg(&arrowUp); - arrowUpImg.SetScale(.8); - - GuiButton arrowUpBtn(arrowUpImg.GetWidth(), arrowUpImg.GetHeight()); - arrowUpBtn.SetImage(&arrowUpImg); - arrowUpBtn.SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - arrowUpBtn.SetPosition(-25, 91); - arrowUpBtn.SetTrigger(&trigA); - arrowUpBtn.SetTrigger(&trigU); - arrowUpBtn.SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowUpBtn.SetSoundClick(btnSoundClick2); - - GuiButton arrowDownBtn(arrowDownImg.GetWidth(), arrowDownImg.GetHeight()); - arrowDownBtn.SetImage(&arrowDownImg); - arrowDownBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - arrowDownBtn.SetPosition(-25, -27); - arrowDownBtn.SetTrigger(&trigA); - arrowDownBtn.SetTrigger(&trigD); - arrowDownBtn.SetEffectOnOver(EFFECT_SCALE, 50, 130); - arrowDownBtn.SetSoundClick(btnSoundClick2); - - GuiImage *iconImg = new GuiImage(iconImgData); - iconImg->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - iconImg->SetPosition(45, 10); - - GuiImage dialogBoxImg(&dialogBox); - dialogBoxImg.SetSkew(0, -80, 0, -80, 0, 50, 0, 50); - - GuiImage whiteBoxImg(&whiteBox); - whiteBoxImg.SetPosition(0, 110); - whiteBoxImg.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - whiteBoxImg.SetSkew(0, 0, 0, 0, 0, -120, 0, -120); - - GuiText nameTxt(name, 30, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - nameTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - nameTxt.SetPosition(0, -15); - nameTxt.SetMaxWidth(430, SCROLL_HORIZONTAL); - - GuiText coderTxt(fmt(tr( "Coded by: %s" ), coder), 16, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - coderTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - coderTxt.SetPosition(180, 30); - coderTxt.SetMaxWidth(280); - - GuiText versionTxt(fmt(tr( "Version: %s" ), version), 16, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - versionTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - versionTxt.SetPosition(40, 65); - versionTxt.SetMaxWidth(430); - - GuiText release_dateTxt(release_date, 16, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - release_dateTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - release_dateTxt.SetPosition(40, 85); - release_dateTxt.SetMaxWidth(430); - - int pagesize = 6; - Text long_descriptionTxt(long_description, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - long_descriptionTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - long_descriptionTxt.SetPosition(46, 117); - long_descriptionTxt.SetMaxWidth(360); - long_descriptionTxt.SetLinesToDraw(pagesize); - long_descriptionTxt.Refresh(); - - //convert filesize from u64 to char and put unit of measurement after it - char filesizeCH[15]; - if (filesize <= 1024.0) - snprintf(filesizeCH, sizeof(filesizeCH), "%lld B", filesize); - if (filesize > 1024.0) - snprintf(filesizeCH, sizeof(filesizeCH), "%0.2f KB", filesize / 1024.0); - if (filesize > 1048576.0) - snprintf(filesizeCH, sizeof(filesizeCH), "%0.2f MB", filesize / 1048576.0); - - GuiText filesizeTxt(filesizeCH, 16, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - filesizeTxt.SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - filesizeTxt.SetPosition(-40, 12); - - GuiText btn1Txt(tr( "Load" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - - GuiButton btn1(&btn1Img, &btn1Img, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - GuiText btn2Txt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn2Img(&btnOutline); - if (Settings.wsprompt) - { - btn2Txt.SetWidescreen(Settings.widescreen); - btn2Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn2(&btn2Img, &btn2Img, 0, 3, 0, 0, &trigA, btnSoundOver, btnSoundClick2, 1); - btn2.SetLabel(&btn2Txt); - btn2.SetTrigger(&trigB); - - btn1.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - btn1.SetPosition(40, 2); - btn2.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - btn2.SetPosition(-40, 2); - - GuiTrigger trigZ; - trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); - - GuiButton screenShotBtn(0, 0); - screenShotBtn.SetPosition(0, 0); - screenShotBtn.SetTrigger(&trigZ); - promptWindow.Append(&screenShotBtn); - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&whiteBoxImg); - promptWindow.Append(&scrollbarImg); - promptWindow.Append(&arrowDownBtn); - promptWindow.Append(&arrowUpBtn); - - if(strcmp(name, "") != 0) promptWindow.Append(&nameTxt); - if(strcmp(version, "") != 0) promptWindow.Append(&versionTxt); - if(strcmp(coder, "") != 0) promptWindow.Append(&coderTxt); - if(strcmp(release_date, "") != 0) promptWindow.Append(&release_dateTxt); - if(strcmp(long_description, "") != 0) promptWindow.Append(&long_descriptionTxt); - promptWindow.Append(&filesizeTxt); - promptWindow.Append(iconImg); - promptWindow.Append(&btn1); - promptWindow.Append(&btn2); - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - while (choice == -1) - { - VIDEO_WaitVSync(); - - if (shutdown == 1) - { - wiilight(0); - Sys_Shutdown(); - } - else if (reset == 1) - { - wiilight(0); - Sys_Reboot(); - } - - if (btn1.GetState() == STATE_CLICKED) - choice = 1; - else if (btn2.GetState() == STATE_CLICKED) - choice = 0; - - else if (screenShotBtn.GetState() == STATE_CLICKED) - { - gprintf("\n\tscreenShotBtn clicked"); - screenShotBtn.ResetState(); - ScreenShot(); - gprintf("...It's easy, mmmmmmKay"); - } - else if (arrowUpBtn.GetState() == STATE_CLICKED || arrowUpBtn.GetState() == STATE_HELD) - { - long_descriptionTxt.PreviousLine(); - - usleep(6000); - if (!((ButtonsHold() & WPAD_BUTTON_UP) || (ButtonsHold() & PAD_BUTTON_UP))) arrowUpBtn.ResetState(); - } - else if (arrowDownBtn.GetState() == STATE_CLICKED || arrowDownBtn.GetState() == STATE_HELD) - { - long_descriptionTxt.NextLine(); - - usleep(60000); - if (!((ButtonsHold() & WPAD_BUTTON_DOWN) || (ButtonsHold() & PAD_BUTTON_DOWN))) arrowDownBtn.ResetState(); - } - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - delete iconImg; - - return choice; -} - diff --git a/source/prompts/PromptWindows.h b/source/prompts/PromptWindows.h deleted file mode 100644 index 32d93aa6..00000000 --- a/source/prompts/PromptWindows.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * PromptWindows - * USB Loader GX 2009 - * - * PromptWindows.h - ***************************************************************************/ - -#ifndef _PROMPTWINDOWS_H_ -#define _PROMPTWINDOWS_H_ - -#include "libwiigui/gui.h" -#include "usbloader/partition_usbloader.h" - -int WindowPrompt(const char *title, const char *msg = NULL, const char * btn1Label = NULL, const char * btn2Label = - NULL, const char * btn3Label = NULL, const char * btn4Label = NULL, int wait = -1); - -void WindowCredits(); -int OnScreenKeyboard(char * var, u32 maxlen, int min); -int OnScreenNumpad(char * var, u32 maxlen); -int WindowExitPrompt(); -int DiscWait(const char *title, const char *msg, const char *btn1Label, const char *btn2Label, int IsDeviceWait); -int FormatingPartition(const char *title, partitionEntry *entry); -bool NetworkInitPrompt(); -int WindowScreensaver(); -int CodeDownload(const char *id); -int HBCWindowPrompt(const char *name, const char *coder, const char *version, const char *release_date, - const char *long_description, GuiImageData * iconImgData, u64 filesize); - -#endif diff --git a/source/prompts/TitleBrowser.cpp b/source/prompts/TitleBrowser.cpp deleted file mode 100644 index f7c8b327..00000000 --- a/source/prompts/TitleBrowser.cpp +++ /dev/null @@ -1,681 +0,0 @@ -/**************************************************************************** - * TitleBrowser - * USB Loader GX 2009 - * - * TitleBrowser.cpp *giantpune* - ***************************************************************************/ - -#include -#include - -#include "language/gettext.h" -#include "libwiigui/gui.h" -#include "libwiigui/gui_customoptionbrowser.h" -#include "prompts/PromptWindows.h" -#include "prompts/ProgressWindow.h" -#include "network/networkops.h" -#include "network/http.h" -#include "filelist.h" -#include "FileOperations/fileops.h" -#include "themes/CTheme.h" -#include "sys.h" -#include "menu.h" -#include "audio.h" -#include "wad/wad.h" -#include "xml/xml.h" -#include "wad/nandtitle.h" -#include "../usbloader/utils.h" -#include "../gecko.h" - -u32 titleCnt; -extern u32 infilesize; -extern u32 uncfilesize; -extern char wiiloadVersion[2]; - -/*** Extern functions ***/ -extern void ResumeGui(); -extern void HaltGui(); - -/*** Extern variables ***/ -extern GuiWindow * mainWindow; -extern u8 shutdown; -extern u8 reset; -extern u32 infilesize; -extern wchar_t *gameFilter; - -/******************************************************************************** - * TitleBrowser- opens a browser with a list of installed Titles - *********************************************************************************/ -bool TitleSelector(char output[]) -{ - gprintf("TitleSelector()\n"); - - s32 num_titles; - s32 r = -1; - bool ret = false; - u64 *titleList = NULL; - - ISFS_Initialize();//initialize for "titles.Exists()" - - // Get count of titles of the good titles - num_titles = NandTitles.SetType(0x10001); - u32 n = num_titles; - //gprintf("num_titles: %u\n", num_titles ); - for (u32 i = 0; i < n; i++) - { - u64 tid = NandTitles.Next(); - if (!tid) - { - break; - } - - //remove ones not actually installed on the nand - if (!NandTitles.Exists(tid)) - { - num_titles--; - } - } - //gprintf("num_titles: %u\n", num_titles ); - - //make a list of just the tids we are adding to the titlebrowser - titleList = (u64*) memalign(32, num_titles * sizeof(u64)); - if (!titleList) - { - gprintf("TitleLister(): out of memory!\n"); - return false; - } - OptionList options4; - //write the titles on the option browser - - s32 i = 0; - NandTitles.SetType(0x10001); - while (i < num_titles) - { - u64 tid = NandTitles.Next(); - if (!tid) - { - gprintf("shit happened\n"); - break; - } - - if (!NandTitles.Exists(tid)) - { - continue; - } - - char id[5]; - NandTitles.AsciiTID(tid, (char*) &id); - - const char* name = NandTitles.NameOf(tid); - //gprintf("%016llx: %s: %s\n%p\t%p\n", tid, id, name, &id, name ); - - options4.SetName(i, "%s", id); - options4.SetValue(i, "%s", name ? NandTitles.NameOf(tid) : tr( "Unknown" )); - titleList[i] = tid; - i++; - } - // gprintf("i: %u\n", i ); - //hexdump( titleList, num_titles * sizeof( u64 ) ); - - options4.SetName(i, " "); - options4.SetValue(i, "%s", tr( "Clear" )); - - ISFS_Deinitialize(); - - bool exit = false; - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - - GuiImage settingsbackground(&settingsbg); - GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight()); - settingsbackgroundbtn.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - settingsbackgroundbtn.SetPosition(0, 0); - settingsbackgroundbtn.SetImage(&settingsbackground); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText cancelBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage cancelBtnImg(&btnOutline); - if (Settings.wsprompt) - { - cancelBtnTxt.SetWidescreen(Settings.widescreen); - cancelBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton cancelBtn(&cancelBtnImg, &cancelBtnImg, 2, 3, 180, 400, &trigA, btnSoundOver, btnSoundClick2, 1); - cancelBtn.SetLabel(&cancelBtnTxt); - cancelBtn.SetTrigger(&trigB); - - GuiCustomOptionBrowser optionBrowser4(396, 280, &options4, "bg_options_settings.png"); - optionBrowser4.SetPosition(0, 90); - optionBrowser4.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - - GuiTrigger trigZ; - trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); - - GuiButton screenShotBtn(0, 0); - screenShotBtn.SetPosition(0, 0); - screenShotBtn.SetTrigger(&trigZ); - - HaltGui(); - GuiWindow w(screenwidth, screenheight); - w.Append(&settingsbackgroundbtn); - w.Append(&screenShotBtn); - w.Append(&cancelBtn); - w.Append(&optionBrowser4); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&w); - - ResumeGui(); - - while (!exit) - { - VIDEO_WaitVSync(); - - if (shutdown == 1) Sys_Shutdown(); - if (reset == 1) Sys_Reboot(); - - r = optionBrowser4.GetClickedOption(); - - if (r > -1) - { //if a click happened - if (r < num_titles) - { - u64 tid = titleList[r]; - sprintf(output, "%08x", TITLE_LOWER( tid )); - } - else output[0] = 0; - ret = true; - exit = true; - } - - else if (cancelBtn.GetState() == STATE_CLICKED) - { - //break the loop and end the function - exit = true; - } - else if (screenShotBtn.GetState() == STATE_CLICKED) - { - screenShotBtn.ResetState(); - ScreenShot(); - } - } - - HaltGui(); - mainWindow->SetState(STATE_DEFAULT); - mainWindow->Remove(&w); - free(titleList); - ResumeGui(); - - return ret; -} - -int TitleBrowser() -{ - - u32 num_titles; - u32 num_sys_titles; - s32 ret = -1; - u64 *titleList = NULL; - - ISFS_Initialize();//initialize for "titles.Exists()" - - // Get count of titles of the good titles - num_titles = NandTitles.SetType(0x10001); - u32 n = num_titles; - for (u32 i = 0; i < n; i++) - { - u64 tid = NandTitles.Next(); - if (!tid) - { - break; - } - - //remove ones not actually installed on the nand - if (!NandTitles.Exists(tid)) - { - num_titles--; - } - } - - // Get count of system titles - num_sys_titles = NandTitles.SetType(0x10002); - n = num_sys_titles; - for (u32 i = 0; i < n; i++) - { - u64 tid = NandTitles.Next(); - if (!tid) - { - break; - } - //these can't be booted anyways - if (TITLE_LOWER( tid ) == 0x48414741 || TITLE_LOWER( tid ) == 0x48414141 || TITLE_LOWER( tid ) == 0x48414641) - { - num_sys_titles--; - continue; - } - - //these aren't installed on the nand - if (!NandTitles.Exists(tid)) - { - num_sys_titles--; - } - } - - //make a list of just the tids we are adding to the titlebrowser - titleList = (u64*) memalign(32, (num_titles + num_sys_titles) * sizeof(u64)); - if (!titleList) - { - gprintf("TitleBrowser(): out of memory!\n"); - return -1; - } - OptionList options3; - //write the titles on the option browser - - u32 i = 0; - NandTitles.SetType(0x10001); - //first add the good stuff - while (i < num_titles) - { - u64 tid = NandTitles.Next(); - if (!tid) - { - gprintf("shit happened3\n"); - break; - } - gprintf("[ %u ] tid: %016llx\t%s\n", i, tid, NandTitles.NameOf(tid)); - - if (!NandTitles.Exists(tid)) - { - continue; - } - - char id[5]; - NandTitles.AsciiTID(tid, (char*) &id); - - const char* name = NandTitles.NameOf(tid); - - options3.SetName(i, "%s", id); - options3.SetValue(i, "%s", name ? NandTitles.NameOf(tid) : tr( "Unknown" )); - titleList[i] = tid; - i++; - } - - NandTitles.SetType(0x10002); - while (i < num_sys_titles + num_titles) - { - u64 tid = NandTitles.Next(); - if (!tid) - { - break; - } - if (TITLE_LOWER( tid ) == 0x48414741 || TITLE_LOWER( tid ) == 0x48414141 || TITLE_LOWER( tid ) == 0x48414641) continue; - - if (!NandTitles.Exists(tid)) - { - continue; - } - - char id[5]; - NandTitles.AsciiTID(tid, (char*) &id); - const char* name = NandTitles.NameOf(tid); - - options3.SetName(i, "%s", id); - options3.SetValue(i, "%s", name ? NandTitles.NameOf(tid) : tr( "Unknown" )); - titleList[i] = tid; - i++; - } - - ISFS_Deinitialize(); - - if (i == num_titles + num_sys_titles) - { - options3.SetName(i, " "); - options3.SetValue(i, "%s", tr( "Wii Settings" )); - } - - bool exit = false; - int total = num_titles + num_sys_titles; - - if (IsNetworkInit()) ResumeNetworkWait(); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText titleTxt(tr( "Title Launcher" ), 28, ( GXColor ) - { 0, 0, 0, 255}); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(12, 40); - titleTxt.SetMaxWidth(356, SCROLL_HORIZONTAL); - - GuiImage settingsbackground(&settingsbg); - GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight()); - settingsbackgroundbtn.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - settingsbackgroundbtn.SetPosition(0, 0); - settingsbackgroundbtn.SetImage(&settingsbackground); - - GuiText cancelBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage cancelBtnImg(&btnOutline); - if (Settings.wsprompt) - { - cancelBtnTxt.SetWidescreen(Settings.widescreen); - cancelBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton cancelBtn(&cancelBtnImg, &cancelBtnImg, 2, 3, 180, 400, &trigA, btnSoundOver, btnSoundClick2, 1); - cancelBtn.SetScale(0.9); - cancelBtn.SetLabel(&cancelBtnTxt); - cancelBtn.SetTrigger(&trigB); - - GuiCustomOptionBrowser optionBrowser3(396, 280, &options3, "bg_options_settings.png"); - optionBrowser3.SetPosition(0, 90); - optionBrowser3.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - - GuiImageData wifiImgData(Resources::GetFile("Wifi_btn.png"), Resources::GetFileSize("Wifi_btn.png")); - GuiImage wifiImg(&wifiImgData); - if (Settings.wsprompt) - { - wifiImg.SetWidescreen(Settings.widescreen); - } - GuiButton wifiBtn(wifiImg.GetWidth(), wifiImg.GetHeight()); - wifiBtn.SetImage(&wifiImg); - wifiBtn.SetPosition(100, 400); - wifiBtn.SetEffectGrow(); - wifiBtn.SetAlpha(80); - wifiBtn.SetTrigger(&trigA); - - GuiTrigger trigZ; - trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); - - GuiButton screenShotBtn(0, 0); - screenShotBtn.SetPosition(0, 0); - screenShotBtn.SetTrigger(&trigZ); - - HaltGui(); - GuiWindow w(screenwidth, screenheight); - w.Append(&screenShotBtn); - w.Append(&settingsbackgroundbtn); - w.Append(&titleTxt); - w.Append(&cancelBtn); - w.Append(&wifiBtn); - w.Append(&optionBrowser3); - mainWindow->Append(&w); - - ResumeGui(); - - while (!exit) - { - VIDEO_WaitVSync(); - - if (shutdown == 1) Sys_Shutdown(); - if (reset == 1) - Sys_Reboot(); - - else if (wifiBtn.GetState() == STATE_CLICKED) - { - ResumeNetworkWait(); - wifiBtn.ResetState(); - } - - if (IsNetworkInit()) - { - wifiBtn.SetAlpha(255); - } - - ret = optionBrowser3.GetClickedOption(); - - if (ret > -1) - { //if a click happened - - if (ret < total) - { - //set the title's name, number, ID to text - char text[0x100]; - char id[5]; - NandTitles.AsciiTID(titleList[ret], (char*) &id); - - snprintf(text, sizeof(text), "%s : %s", id, NandTitles.NameOf(titleList[ret])); - - //prompt to boot selected title - if (WindowPrompt(tr( "Boot?" ), text, tr( "OK" ), tr( "Cancel" ))) - { //if they say yes - CloseXMLDatabase(); - ExitGUIThreads(); - ShutdownAudio(); - StopGX(); - WII_Initialize(); - WII_LaunchTitle(titleList[ret]); - //this really shouldn't be needed because the title will be booted - exit = true; - break; - } - else - { - //if they said no to booting the title - ret = -1; - optionBrowser3.ResetState(); - } - - } - else if (ret == total) - { //if they clicked to go to the wii settings - CloseXMLDatabase(); - ExitGUIThreads(); - ShutdownAudio(); - StopGX(); - WII_Initialize(); - WII_ReturnToSettings(); - } - } -#if 0 - if ( infilesize > 0 ) - { - - char filesizetxt[50]; - char temp[50]; - char filepath[100]; - // u32 read = 0; - - //make sure there is a folder for this to be saved in - struct stat st; - snprintf( filepath, sizeof( filepath ), "%s/wad/", bootDevice ); - if ( stat( filepath, &st ) != 0 ) - { - if ( subfoldercreate( filepath ) != 1 ) - { - WindowPrompt( tr( "Error !" ), tr( "Can't create directory" ), tr( "OK" ) ); - } - } - snprintf( filepath, sizeof( filepath ), "%s/wad/tmp.tmp", bootDevice ); - - if ( infilesize < MB_SIZE ) - snprintf( filesizetxt, sizeof( filesizetxt ), tr( "Incoming file %0.2fKB" ), infilesize / KB_SIZE ); - else - snprintf( filesizetxt, sizeof( filesizetxt ), tr( "Incoming file %0.2fMB" ), infilesize / MB_SIZE ); - - snprintf( temp, sizeof( temp ), tr( "Load file from: %s ?" ), GetIncommingIP() ); - - int choice = WindowPrompt( filesizetxt, temp, tr( "OK" ), tr( "Cancel" ) ); - gprintf( "\nchoice:%d", choice ); - - if ( choice == 1 ) - { - - u32 read = 0; - u8 *temp = NULL; - int len = NETWORKBLOCKSIZE; - temp = ( u8 * ) malloc( infilesize ); - - bool error = false; - u8 *ptr = temp; - gprintf( "\nrecieving shit" ); - while ( read < infilesize ) - { - - ShowProgress( tr( "Receiving file from:" ), GetIncommingIP(), NULL, read, infilesize, true ); - - if ( infilesize - read < ( u32 ) len ) - len = infilesize - read; - else - len = NETWORKBLOCKSIZE; - - int result = network_read( ptr, len ); - - if ( result < 0 ) - { - WindowPrompt( tr( "Error while transfering data." ), 0, tr( "OK" ) ); - error = true; - break; - } - if ( !result ) - { - gprintf( "\n!RESULT" ); - break; - } - ptr += result; - read += result; - } - ProgressStop(); - - char filename[101]; - char tmptxt[200]; - - //bool installWad=0; - if ( !error ) - { - gprintf( "\nno error yet" ); - - network_read( ( u8* ) &filename, 100 ); - gprintf( "\nfilename: %s", filename ); - - // Do we need to unzip this thing? - if ( wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4 ) - { - gprintf( "\nusing newer wiiload version" ); - - if ( uncfilesize != 0 ) // if uncfilesize == 0, it's not compressed - - { - gprintf( "\ntrying to uncompress" ); - // It's compressed, uncompress - u8 *unc = ( u8 * ) malloc( uncfilesize ); - uLongf f = uncfilesize; - error = uncompress( unc, &f, temp, infilesize ) != Z_OK; - uncfilesize = f; - - free( temp ); - temp = unc; - } - } - - if ( !error ) - { - sprintf( tmptxt, "%s", filename ); - //if we got a wad - if ( strcasestr( tmptxt, ".wad" ) ) - { - FILE *file = fopen( filepath, "wb" ); - fwrite( temp, 1, ( uncfilesize > 0 ? uncfilesize : infilesize ), file ); - fclose( file ); - - sprintf( tmptxt, "%s/wad/%s", bootDevice, filename ); - if ( checkfile( tmptxt ) )remove( tmptxt ); - rename( filepath, tmptxt ); - - //check and make sure the wad we just saved is the correct size - u32 lSize; - file = fopen( tmptxt, "rb" ); - - // obtain file size: - fseek ( file , 0 , SEEK_END ); - lSize = ftell ( file ); - - rewind ( file ); - if ( lSize == ( uncfilesize > 0 ? uncfilesize : infilesize ) ) - { - gprintf( "\nsize is ok" ); - int pick = WindowPrompt( tr( " Wad Saved as:" ), tmptxt, tr( "Install" ), tr( "Uninstall" ), tr( "Cancel" ) ); - //install or uninstall it - if ( pick == 1 ) - { - HaltGui(); - w.Remove( &titleTxt ); - w.Remove( &cancelBtn ); - w.Remove( &wifiBtn ); - w.Remove( &optionBrowser3 ); - ResumeGui(); - - Wad_Install( file ); - - HaltGui(); - w.Append( &titleTxt ); - w.Append( &cancelBtn ); - w.Append( &wifiBtn ); - w.Append( &optionBrowser3 ); - ResumeGui(); - - } - if ( pick == 2 )Wad_Uninstall( file ); - } - else gprintf( "\nBad size" ); - //close that beast, we're done with it - fclose ( file ); - - //do we want to keep the file in the wad folder - if ( WindowPrompt( tr( "Delete ?" ), tmptxt, tr( "Delete" ), tr( "Keep" ) ) != 0 ) - remove( tmptxt ); - } - else - { - WindowPrompt( tr( "ERROR:" ), tr( "Not a WAD file." ), tr( "OK" ) ); - } - } - } - - if ( error || read != infilesize ) - { - WindowPrompt( tr( "Error:" ), tr( "No data could be read." ), tr( "OK" ) ); - - } - if ( temp )free( temp ); - } - - CloseConnection(); - ResumeNetworkWait(); - } -#endif - if (cancelBtn.GetState() == STATE_CLICKED) - { - //break the loop and end the function - exit = true; - ret = -10; - } - else if (screenShotBtn.GetState() == STATE_CLICKED) - { - screenShotBtn.ResetState(); - ScreenShot(); - } - } - - CloseConnection(); - if (IsNetworkInit()) HaltNetworkThread(); - - HaltGui(); - mainWindow->Remove(&w); - free(titleList); - ResumeGui(); - - return ret; -} - diff --git a/source/prompts/TitleBrowser.h b/source/prompts/TitleBrowser.h deleted file mode 100644 index cd15cc3c..00000000 --- a/source/prompts/TitleBrowser.h +++ /dev/null @@ -1,14 +0,0 @@ -/**************************************************************************** - * TitleBrowser - * USB Loader GX 2009 - * - * TitleBrowser.h - ***************************************************************************/ - -#ifndef _TITLEBROWSER_H_ -#define _TITLEBROWSER_H_ - -int TitleBrowser(); -bool TitleSelector(char output[]); - -#endif diff --git a/source/prompts/filebrowser.cpp b/source/prompts/filebrowser.cpp deleted file mode 100644 index f1d12c8f..00000000 --- a/source/prompts/filebrowser.cpp +++ /dev/null @@ -1,537 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * modified by dimok - * - * filebrowser.cpp - * - * Generic file routines - reading, writing, browsing - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "menu.h" - -#include "themes/CTheme.h" -#include "FileOperations/fileops.h" -#include "language/gettext.h" -#include "PromptWindows.h" -#include "libwiigui/gui.h" -#include "sys.h" -#include "filebrowser.h" - -/*** Extern variables ***/ -extern GuiWindow * mainWindow; -extern u8 shutdown; -extern u8 reset; - -/*** Extern functions ***/ -extern void ResumeGui(); -extern void HaltGui(); - -static int curDevice = -1; -static std::vector browsers; -BROWSERINFO *browser = NULL; - -/**************************************************************************** - * FileFilterCallbacks - * return: 1-visible 0-hidden - ***************************************************************************/ -int noDIRS(BROWSERENTRY *Entry, void* Args) -{ - return !Entry->isdir; -} -int noFILES(BROWSERENTRY *Entry, void* Args) -{ - return Entry->isdir; -} -int noEXT(BROWSERENTRY *Entry, void* Args) -{ - if (!Entry->isdir) - { - char *cptr = strrchr(Entry->displayname, '.'); - if (cptr && cptr != Entry->displayname) *cptr = 0; - } - return 1; -} - -void ResetBrowser(BROWSERINFO *browser); -/**************************************************************************** - * InitBrowsers() - * Clears the file browser memory, and allocates one initial entry - ***************************************************************************/ -int InitBrowsers() -{ - curDevice = -1; - browsers.clear(); - browser = NULL; - char rootdir[ROOTDIRLEN]; - for (int i = 3; i < STD_MAX; i++) - { - if (strcmp(devoptab_list[i]->name, "stdnull") && devoptab_list[i]->write_r != NULL) - { - snprintf(rootdir, sizeof(rootdir), "%s:/", devoptab_list[i]->name); - if ( DIR_ITER *dir = diropen( rootdir ) ) - { - dirclose(dir); - BROWSERINFO browser; - browser.dir[0] = '\0'; - strcpy(browser.rootdir, rootdir); - ResetBrowser(&browser); - browsers.push_back(browser); - } - } - } - if (!browsers.size()) return -1; - curDevice = 0; - browser = &browsers[curDevice]; - return 0; -} -/**************************************************************************** - * ResetBrowser() - * Clears the file browser memory, and allocates one initial entry - ***************************************************************************/ -void ResetBrowser(BROWSERINFO *browser) -{ - browser->pageIndex = 0; - browser->browserList.clear(); - /* - // Clear any existing values - if (browser->browserList != NULL) { - free(browser->browserList); - browser->browserList = NULL; - } - // set aside space for 1 entry - browser->browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY)); - if(browser->browserList) - memset(browser->browserList, 0, sizeof(BROWSERENTRY)); - */ -} - -/**************************************************************************** - * FileSortCallback - * - * sort callback to sort file entries with the following order: - * . - * .. - * - * - ***************************************************************************/ -//int FileSortCallback(const void *f1, const void *f2) { -bool operator<(const BROWSERENTRY &f1, const BROWSERENTRY &f2) -{ - /* Special case for implicit directories */ - if (f1.filename[0] == '.' || f2.filename[0] == '.') - { - if (strcmp(f1.filename, ".") == 0) - { - return true; - } - if (strcmp(f2.filename, ".") == 0) - { - return false; - } - if (strcmp(f1.filename, "..") == 0) - { - return true; - } - if (strcmp(f2.filename, "..") == 0) - { - return false; - } - } - - /* If one is a file and one is a directory the directory is first. */ - if (f1.isdir && !(f2.isdir)) return true; - if (!(f1.isdir) && f2.isdir) return false; - - return stricmp(f1.filename, f2.filename) < 0; -} - -int ParseFilter(FILTERCASCADE *Filter, BROWSERENTRY* Entry) -{ - while (Filter) - { - if (Filter->filter && Filter->filter(Entry, Filter->filter_args) == 0) return 0; - Filter = Filter->next; - } - return 1; -} -/*************************************************************************** - * Browse subdirectories - **************************************************************************/ -int ParseDirectory(const char* Path, int Flags, FILTERCASCADE *Filter) -{ - DIR_ITER *dir = NULL; - char fulldir[MAXPATHLEN]; - char filename[MAXPATHLEN]; - struct stat filestat; - unsigned int i; - - if (curDevice == -1) if (InitBrowsers()) return -1; // InitBrowser fails - - if (Path) // note in this codeblock use filename temporary - { - strlcpy(fulldir, Path, sizeof(fulldir)); - if (*fulldir && fulldir[strlen(fulldir) - 1] != '/') // a file - { - char * chrp = strrchr(fulldir, '/'); - if (chrp) chrp[1] = 0; - } - if (strchr(fulldir, ':') == NULL) // Path has no device device - { - getcwd(filename, sizeof(filename)); // save the current working dir - if (*fulldir == 0) // if path is empty - strlcpy(fulldir, filename, sizeof(fulldir)); // we use the current working dir - else - { // path is not empty - if (chdir(fulldir)) ; // sets the path to concatenate and validate - { - if (Flags & (FB_TRYROOTDIR | FB_TRYSTDDEV)) if (chdir("/") && !(Flags & FB_TRYSTDDEV)) // try to set root if is needed - return -1; - } - if (getcwd(fulldir, sizeof(fulldir))) return -1; // gets the concatenated current working dir - chdir(filename); // restore the saved cwd - } - } - for (i = 0; i < browsers.size(); i++) // searchs the browser who match the path - { - if (strnicmp(fulldir, browsers[i].rootdir, strlen(browsers[i].rootdir) - 1 /*means without trailing '/'*/) - == 0) - { - browser = &browsers[curDevice]; - break; - } - } - if (i != browsers.size()) // found browser - { - curDevice = i; - browser = &browsers[curDevice]; - strcpy(browser->dir, &fulldir[strlen(browser->rootdir)]); - } - else if (Flags & FB_TRYSTDDEV) - { - curDevice = 0; - browser = &browsers[curDevice]; // when no browser was found and - browser->dir[0] = 0; // we alowed try StdDevice and try RootDir - strlcpy(fulldir, browser->rootdir, sizeof(fulldir)); // set the first browser with root-dir - } - else return -1; - } - else snprintf(fulldir, sizeof(fulldir), "%s%s", browser->rootdir, browser->dir); - - // reset browser - ResetBrowser(browser); - - // open the directory - if ((dir = diropen(fulldir)) == NULL) - { - if (Flags & FB_TRYROOTDIR) - { - browser->dir[0] = 0; - if ((dir = diropen(browser->rootdir)) == NULL) return -1; - } - else return -1; - } - - while (dirnext(dir, filename, &filestat) == 0) - { - if (strcmp(filename, ".") != 0) - { - BROWSERENTRY newEntry; - memset(&newEntry, 0, sizeof(BROWSERENTRY)); // clear the new entry - strlcpy(newEntry.filename, filename, sizeof(newEntry.filename)); - strlcpy(newEntry.displayname, filename, sizeof(newEntry.displayname)); - newEntry.length = filestat.st_size; - newEntry.isdir = (filestat.st_mode & S_IFDIR) == 0 ? 0 : 1; // flag this as a dir - if (ParseFilter(Filter, &newEntry)) browser->browserList.push_back(newEntry); - } - } - - // close directory - dirclose(dir); - - // Sort the file list - std::sort(browser->browserList.begin(), browser->browserList.end()); - return 0; -} -int ParseDirectory(int Device, int Flags, FILTERCASCADE *Filter) -{ - if (Device >= 0 && Device < (int) browsers.size()) - { - int old_curDevice = curDevice; - curDevice = Device; - browser = &browsers[curDevice]; - if (ParseDirectory((char*) NULL, Flags, Filter) == 0) return 0; - curDevice = old_curDevice; - browser = &browsers[old_curDevice]; - } - return -1; -} - -/**************************************************************************** - * BrowseDevice - * Displays a list of files on the selected path - ***************************************************************************/ - -int BrowseDevice(char * Path, int Path_size, int Flags, FILTERCASCADE *Filter/*=NULL*/) -{ - int result = -1; - int i; - - if (InitBrowsers() || ParseDirectory(Path, Flags, Filter)) - { - WindowPrompt(tr( "Error" ), 0, tr( "OK" )); - return -1; - } - int menu = MENU_NONE; - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiImageData folderImgData(Resources::GetFile("icon_folder.png"), Resources::GetFileSize("icon_folder.png")); - GuiImage folderImg(&folderImgData); - GuiButton folderBtn(folderImg.GetWidth(), folderImg.GetHeight()); - folderBtn.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - folderBtn.SetPosition(-210, -145); - folderBtn.SetImage(&folderImg); - folderBtn.SetTrigger(&trigA); - folderBtn.SetEffectGrow(); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiText ExitBtnTxt(tr( "Cancel" ), 24, ( GXColor ) {0, 0, 0, 255}); - GuiImage ExitBtnImg(&btnOutline); - if (Settings.wsprompt) - { - ExitBtnTxt.SetWidescreen(Settings.widescreen); - ExitBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton ExitBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); - ExitBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); - ExitBtn.SetPosition(-40, -35); - ExitBtn.SetLabel(&ExitBtnTxt); - ExitBtn.SetImage(&ExitBtnImg); - ExitBtn.SetTrigger(&trigA); - ExitBtn.SetTrigger(&trigB); - ExitBtn.SetEffectGrow(); - - GuiText usbBtnTxt(browsers[(curDevice + 1) % browsers.size()].rootdir, 24, ( GXColor ) {0, 0, 0, 255}); - GuiImage usbBtnImg(&btnOutline); - if (Settings.wsprompt) - { - usbBtnTxt.SetWidescreen(Settings.widescreen); - usbBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton usbBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); - usbBtn.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); - usbBtn.SetPosition(0, -35); - usbBtn.SetLabel(&usbBtnTxt); - usbBtn.SetImage(&usbBtnImg); - usbBtn.SetTrigger(&trigA); - usbBtn.SetEffectGrow(); - - GuiText okBtnTxt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage okBtnImg(&btnOutline); - if (Settings.wsprompt) - { - okBtnTxt.SetWidescreen(Settings.widescreen); - okBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton okBtn(&okBtnImg, &okBtnImg, 0, 4, 40, -35, &trigA, btnSoundOver, btnSoundClick2, 1); - okBtn.SetLabel(&okBtnTxt); - - GuiFileBrowser fileBrowser(396, 248); - fileBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - fileBrowser.SetPosition(0, 120); - - GuiImageData Address(Resources::GetFile("addressbar_textbox.png"), Resources::GetFileSize("addressbar_textbox.png")); - GuiText AdressText((char*) NULL, 20, ( GXColor ) {0, 0, 0, 255}); - AdressText.SetTextf("%s%s", browser->rootdir, browser->dir); - AdressText.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - AdressText.SetPosition(20, 0); - AdressText.SetMaxWidth(Address.GetWidth() - 40, SCROLL_HORIZONTAL); - GuiImage AdressbarImg(&Address); - GuiButton Adressbar(Address.GetWidth(), Address.GetHeight()); - Adressbar.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - Adressbar.SetPosition(0, fileBrowser.GetTop() - 45); - Adressbar.SetImage(&AdressbarImg); - Adressbar.SetLabel(&AdressText); - - HaltGui(); - GuiWindow w(screenwidth, screenheight); - w.Append(&ExitBtn); - // w.Append(&titleTxt); - w.Append(&fileBrowser); - w.Append(&Adressbar); - w.Append(&okBtn); - if (!(Flags & FB_NOFOLDER_BTN)) w.Append(&folderBtn); - if (browsers.size() > 1 && !(Flags & FB_NODEVICE_BTN)) w.Append(&usbBtn); - mainWindow->Append(&w); - ResumeGui(); - int clickedIndex = -1; - while (menu == MENU_NONE) - { - VIDEO_WaitVSync(); - - if (shutdown == 1) Sys_Shutdown(); - - if (reset == 1) Sys_Reboot(); - - for (i = 0; i < FILEBROWSERSIZE; i++) - { - if (fileBrowser.fileList[i]->GetState() == STATE_CLICKED) - { - fileBrowser.fileList[i]->ResetState(); - - clickedIndex = browser->pageIndex + i; - bool pathCanged = false; - // check corresponding browser entry - if (browser->browserList[clickedIndex].isdir) - { - /* go up to parent directory */ - if (strcmp(browser->browserList[clickedIndex].filename, "..") == 0) - { - /* remove last subdirectory name */ - int len = strlen(browser->dir); - while (browser->dir[0] && browser->dir[len - 1] == '/') - browser->dir[--len] = '\0'; // remove all trailing '/' - char *cptr = strrchr(browser->dir, '/'); - if (cptr) - *++cptr = 0; - else browser->dir[0] = '\0'; // remove trailing dir - pathCanged = true; - } - /* Open a directory */ - /* current directory doesn't change */ - else if (strcmp(browser->browserList[clickedIndex].filename, ".")) - { - /* test new directory namelength */ - if ((strlen(browser->dir) + strlen(browser->browserList[clickedIndex].filename) + 1/*'/'*/) - < MAXPATHLEN) - { - /* update current directory name */ - sprintf(browser->dir, "%s%s/", browser->dir, browser->browserList[clickedIndex].filename); - pathCanged = true; - } - } - if (pathCanged) - { - LOCK( &fileBrowser ); - ParseDirectory((char*) NULL, Flags, Filter); - fileBrowser.ResetState(); - fileBrowser.TriggerUpdate(); - AdressText.SetTextf("%s%s", browser->rootdir, browser->dir); - } - clickedIndex = -1; - } - else /* isFile */ - { - AdressText.SetTextf("%s%s%s", browser->rootdir, browser->dir, - browser->browserList[clickedIndex].filename); - } - } - } - - if (ExitBtn.GetState() == STATE_CLICKED) - { - result = 0; - break; - } - else if (okBtn.GetState() == STATE_CLICKED) - { - if (clickedIndex >= 0) - snprintf(Path, Path_size, "%s%s%s", browser->rootdir, browser->dir, - browser->browserList[clickedIndex].filename); - else snprintf(Path, Path_size, "%s%s", browser->rootdir, browser->dir); - result = 1; - break; - } - else if (usbBtn.GetState() == STATE_CLICKED) - { - usbBtn.ResetState(); - for (u32 i = 1; i < browsers.size(); i++) - { - LOCK( &fileBrowser ); - if (ParseDirectory((curDevice + i) % browsers.size(), Flags, Filter) == 0) - { - fileBrowser.ResetState(); - fileBrowser.TriggerUpdate(); - AdressText.SetTextf("%s%s", browser->rootdir, browser->dir); - usbBtnTxt.SetText(browsers[(curDevice + 1) % browsers.size()].rootdir); - break; - } - } - } - else if (folderBtn.GetState() == STATE_CLICKED) - { - folderBtn.ResetState(); - - HaltGui(); - mainWindow->Remove(&w); - ResumeGui(); - char newfolder[100]; - char oldfolder[100]; - snprintf(newfolder, sizeof(newfolder), "%s%s", browser->rootdir, browser->dir); - strcpy(oldfolder, newfolder); - - int result = OnScreenKeyboard(newfolder, sizeof(newfolder), strlen(browser->rootdir)); - if (result == 1) - { - unsigned int len = strlen(newfolder); - if (len > 0 && len + 1 < sizeof(newfolder) && newfolder[len - 1] != '/') - { - newfolder[len] = '/'; - newfolder[len + 1] = '\0'; - } - - struct stat st; - if (stat(newfolder, &st) != 0) - { - if (WindowPrompt(tr( "Directory does not exist!" ), - tr( "The entered directory does not exist. Would you like to create it?" ), - tr( "OK" ), tr( "Cancel" )) == 1) if (CreateSubfolder(newfolder) == false) WindowPrompt( - tr( "Error !" ), tr( "Can't create directory" ), tr( "OK" )); - } - if (ParseDirectory(newfolder, Flags, Filter) == 0) - { - fileBrowser.ResetState(); - fileBrowser.TriggerUpdate(); - AdressText.SetTextf("%s%s", browser->rootdir, browser->dir); - usbBtnTxt.SetText(browsers[(curDevice + 1) % browsers.size()].rootdir); - } - } - HaltGui(); - mainWindow->Append(&w); - ResumeGui(); - } - - } - HaltGui(); - mainWindow->Remove(&w); - ResumeGui(); - - //} - - return result; -} - -int BrowseDevice(char * Path, int Path_size, int Flags, FILEFILTERCALLBACK Filter, void *FilterArgs) -{ - if (Filter) - { - FILTERCASCADE filter = { Filter, FilterArgs, NULL }; - return BrowseDevice(Path, Path_size, Flags, &filter); - } - return BrowseDevice(Path, Path_size, Flags); -} diff --git a/source/prompts/filebrowser.h b/source/prompts/filebrowser.h deleted file mode 100644 index 39c7a9ea..00000000 --- a/source/prompts/filebrowser.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * modified by dimok and ardi - * - * filebrowser.h - * - * Generic file routines - reading, writing, browsing - ****************************************************************************/ - -#ifndef _FILEBROWSER_H_ -#define _FILEBROWSER_H_ - -#include -#include - -#define MAXJOLIET 255 -#define MAXDISPLAY MAXPATHLEN -#define ROOTDIRLEN 10 - -typedef struct -{ - u64 offset; // DVD offset - u64 length; // file length in 64 bytes for sizes higher than 4GB - char isdir; // 0 - file, 1 - directory - char filename[MAXJOLIET + 1]; // full filename - char displayname[MAXDISPLAY + 1]; // name for browser display -} BROWSERENTRY; - -typedef struct -{ - char dir[MAXPATHLEN]; // directory path of browserList - char rootdir[ROOTDIRLEN];// directory path of browserList - int pageIndex; // starting index of browserList page display - std::vector browserList; -} BROWSERINFO; -extern BROWSERINFO *browser; - -#define FB_NOFOLDER_BTN 0x0001 -#define FB_NODEVICE_BTN 0x0002 -#define FB_TRYROOTDIR 0x0004 -#define FB_TRYSTDDEV 0x0008 -#define FB_DEFAULT (FB_TRYROOTDIR | FB_TRYSTDDEV) - -typedef int (*FILEFILTERCALLBACK)(BROWSERENTRY *Entry, void* Args); -int noDIRS(BROWSERENTRY *Entry, void* Args); -int noFILES(BROWSERENTRY *Entry, void* Args); -int noEXT(BROWSERENTRY *Entry, void* Args); - -typedef struct _FILTERCASCADE -{ - FILEFILTERCALLBACK filter; - void *filter_args; - _FILTERCASCADE *next; -} FILTERCASCADE; - -/**************************************************************************** - * BrowseDevice - * Displays a list of files on the selected path - * Path returns the selectet Path/File - * Path_size is the space of the Path-array - * Ret: 0 ok / -1 Error - ***************************************************************************/ -/*************************************************************************** - * Example: - * FILTERKASKADE filter2 = {noEXT, NULL, NULL}; - * FILTERKASKADE filter1 = {noDirs, NULL, &filter2}; - * char Path[MAXPATHLEN] = "SD:/"; - * BrowseDevice(Path, MAXPATHLEN, FB_DEFAULT, &filter1); - * - * - ***************************************************************************/ -int BrowseDevice(char * Path, int Path_size, int Flags/*=FB_DEFAULT*/, FILTERCASCADE *Filter = NULL); -int BrowseDevice(char * Path, int Path_size, int Flags, FILEFILTERCALLBACK Filter, void *FilterArgs = NULL); - -#endif - diff --git a/source/prompts/gameinfo.cpp b/source/prompts/gameinfo.cpp deleted file mode 100644 index 0d390f9b..00000000 --- a/source/prompts/gameinfo.cpp +++ /dev/null @@ -1,1180 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "usbloader/wbfs.h" -#include "language/gettext.h" -#include "libwiigui/gui.h" -#include "libwiigui/Text.hpp" -#include "xml/xml.h" -#include "menu.h" -#include "menu/menus.h" -#include "filelist.h" -#include "sys.h" -#include "wpad.h" -#include "fatmounter.h" -#include "FileOperations/fileops.h" -#include "prompts/PromptWindows.h" -#include "themes/CTheme.h" -#include "settings/GameTitles.h" -#include "gameinfo.h" -#include "usbloader/GameList.h" -#include "gecko.h" -#include "xml/WiiTDB.hpp" -#include "utils/ShowError.h" - -/**************************************************************************** - * gameinfo - ***************************************************************************/ -int showGameInfo(char *ID) -{ - HaltGui();//put this first to try to get rid of the code dump caused by loading this window at the same time as loading images from the SD card - mainWindow->SetState(STATE_DISABLED); - ResumeGui(); - - char xmlpath[300]; - snprintf(xmlpath, sizeof(xmlpath), "%swiitdb.xml", Settings.titlestxt_path); - - WiiTDB XML_DB; - - if(!XML_DB.OpenFile(xmlpath)) - { - ShowError(tr("Could not open wiitdb.xml.")); - return -1; - } - - XML_DB.SetLanguageCode(Settings.db_language); - - GameXMLInfo GameInfo; - - if(!XML_DB.GetGameXMLInfo(ID, &GameInfo)) - { - ShowError(tr("Could not find info for this game in the wiitdb.xml.")); - return -1; - } - - XML_DB.CloseFile(); - - bool showmeminfo = false; - - int choice = -1; - int titley = 10; - int marginY = titley + 40; - int indexy = marginY; - int wifiY = 0; - int intputX = 200, inputY = -30, txtXOffset = 90; - u8 nunchuk = 0, classiccontroller = 0, balanceboard = 0, dancepad = 0, guitar = 0, gamecube = 0, wheel = 0, - motionplus = 0, drums = 0, microphone = 0, zapper = 0, nintendods = 0, - //vitalitysensor=0, - wiispeak = 0; - int newline = 1; - u8 page = 1; - - GuiImageData * playersImgData = NULL; - GuiImage * playersImg = NULL; - - GuiImageData * wifiplayersImgData = NULL; - GuiImage * wifiplayersImg = NULL; - GuiImage * ratingImg = NULL; - - GuiImage * classiccontrollerImg = NULL; - GuiImage * nunchukImg = NULL; - GuiImage * guitarImg = NULL; - GuiImage * drumsImg = NULL; - GuiImage * dancepadImg = NULL; - GuiImage * motionplusImg = NULL; - GuiImage * wheelImg = NULL; - GuiImage * balanceboardImg = NULL; - GuiImage * microphoneImg = NULL; - GuiImage * zapperImg = NULL; - GuiImage * nintendodsImg = NULL; - GuiImage * wiispeakImg = NULL; - //GuiImage * vitalitysensorImg = NULL; - GuiImage * gcImg = NULL; - GuiImage * dialogBoxImg1 = NULL; - GuiImage * dialogBoxImg2 = NULL; - GuiImage * dialogBoxImg3 = NULL; - GuiImage * dialogBoxImg4 = NULL; - GuiImage * dialogBoxImg11 = NULL; - GuiImage * dialogBoxImg22 = NULL; - GuiImage * dialogBoxImg33 = NULL; - GuiImage * dialogBoxImg44 = NULL; - GuiImage * coverImg = NULL; - GuiImage * coverImg2 = NULL; - - GuiImageData * classiccontrollerImgData = NULL; - GuiImageData * nunchukImgData = NULL; - GuiImageData * guitarImgData = NULL; - GuiImageData * drumsImgData = NULL; - GuiImageData * motionplusImgData = NULL; - GuiImageData * wheelImgData = NULL; - GuiImageData * balanceboardImgData = NULL; - GuiImageData * dancepadImgData = NULL; - GuiImageData * microphoneImgData = NULL; - GuiImageData * zapperImgData = NULL; - GuiImageData * nintendodsImgData = NULL; - GuiImageData * wiispeakImgData = NULL; - //GuiImageData * vitalitysensorImgData = NULL; - GuiImageData * gamecubeImgData = NULL; - GuiImageData * ratingImgData = NULL; - GuiImageData * cover = NULL; - - GuiText * releasedTxt = NULL; - GuiText * publisherTxt = NULL; - GuiText * developerTxt = NULL; - GuiText * titleTxt = NULL; - Text * synopsisTxt = NULL; - GuiText * genreTitleTxt = NULL; - GuiText ** genreTxt = NULL; - GuiText ** wifiTxt = NULL; - GuiText * wiitdb1Txt = NULL; - GuiText * wiitdb2Txt = NULL; - GuiText * wiitdb3Txt = NULL; - GuiText * memTxt = NULL; - - GuiWindow gameinfoWindow(600, 308); - gameinfoWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - gameinfoWindow.SetPosition(0, -50); - - GuiWindow gameinfoWindow2(600, 308); - gameinfoWindow2.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - gameinfoWindow2.SetPosition(0, -50); - - GuiWindow txtWindow(350, 270); - txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT); - txtWindow.SetPosition(95, 55); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox1(Resources::GetFile("gameinfo1.png"), Resources::GetFileSize("gameinfo1.png")); - GuiImageData dialogBox2(Resources::GetFile("gameinfo1a.png"), Resources::GetFileSize("gameinfo1a.png")); - GuiImageData dialogBox3(Resources::GetFile("gameinfo2.png"), Resources::GetFileSize("gameinfo2.png")); - GuiImageData dialogBox4(Resources::GetFile("gameinfo2a.png"), Resources::GetFileSize("gameinfo2a.png")); - - GuiTrigger trig1; - trig1.SetButtonOnlyTrigger(-1, WPAD_BUTTON_1 | WPAD_CLASSIC_BUTTON_X, 0); - GuiTrigger trigA; - trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiTrigger trigU; - trigU.SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); - GuiTrigger trigD; - trigD.SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); - GuiTrigger trigH; - trigH.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - - //buttons for changing between synopsis and other info - GuiButton backBtn(0, 0); - backBtn.SetPosition(-20, -20); - backBtn.SetTrigger(&trigB); - gameinfoWindow.Append(&backBtn); - - GuiButton nextBtn(0, 0); - nextBtn.SetPosition(20, 20); - nextBtn.SetTrigger(&trigA); - gameinfoWindow.Append(&nextBtn); - - //buttons for scrolling the synopsis - GuiButton upBtn(0, 0); - upBtn.SetPosition(0, 0); - upBtn.SetTrigger(&trigU); - - GuiButton dnBtn(0, 0); - dnBtn.SetPosition(0, 0); - dnBtn.SetTrigger(&trigD); - - GuiButton homeBtn(0, 0); - homeBtn.SetPosition(0, 0); - homeBtn.SetTrigger(&trigH); - - // button to save the url for the zip file for poor people without wifi - GuiButton urlBtn(0, 0); - urlBtn.SetPosition(0, 0); - urlBtn.SetTrigger(&trig1); - gameinfoWindow.Append(&urlBtn); - - char linebuf2[100] = ""; - - // enable icons for required accessories - for (u32 i = 0; i < GameInfo.AccessoirList.size(); ++i) - { - if(!GameInfo.AccessoirList[i].Required) - continue; - - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "guitar") == 0) guitar = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "drums") == 0) drums = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "dancepad") == 0) dancepad = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "motionplus") == 0) motionplus = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wheel") == 0) wheel = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "microphone") == 0) microphone = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "zapper") == 0) zapper = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nintendods") == 0) nintendods = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1; - //if (strcmp(GameInfo.AccessoirList[i].Name.c_str(),"vitalitysensor")==0) - // vitalitysensor=1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "gamecube") == 0) gamecube = 1; - } - - // switch icons - if (nunchuk) - nunchukImgData = Resources::GetImageData("nunchukR.png"); - else nunchukImgData = Resources::GetImageData("nunchuk.png"); - - if (classiccontroller) - classiccontrollerImgData = Resources::GetImageData("classiccontrollerR.png"); - else classiccontrollerImgData = Resources::GetImageData("classiccontroller.png"); - - if (guitar) - guitarImgData = Resources::GetImageData("guitarR.png"); - else guitarImgData = Resources::GetImageData("guitar.png"); - - if (gamecube) - gamecubeImgData = Resources::GetImageData("gcncontrollerR.png"); - else gamecubeImgData = Resources::GetImageData("gcncontroller.png"); - - if (wheel) - wheelImgData = Resources::GetImageData("wheelR.png"); - else wheelImgData = Resources::GetImageData("wheel.png"); - - if (motionplus) - motionplusImgData = Resources::GetImageData("motionplusR.png"); - else motionplusImgData = Resources::GetImageData("motionplus.png"); - - if (drums) - drumsImgData = Resources::GetImageData("drumsR.png"); - else drumsImgData = Resources::GetImageData("drums.png"); - - if (microphone) - microphoneImgData = Resources::GetImageData("microphoneR.png"); - else microphoneImgData = Resources::GetImageData("microphone.png"); - - if (zapper) - zapperImgData = Resources::GetImageData("zapperR.png"); - else zapperImgData = Resources::GetImageData("zapper.png"); - - if (wiispeak) - wiispeakImgData = Resources::GetImageData("wiispeakR.png"); - else wiispeakImgData = Resources::GetImageData("wiispeak.png"); - - if (nintendods) - nintendodsImgData = Resources::GetImageData("nintendodsR.png"); - else nintendodsImgData = Resources::GetImageData("nintendods.png"); - - if (balanceboard) - balanceboardImgData = Resources::GetImageData("balanceboardR.png"); - else balanceboardImgData = Resources::GetImageData("balanceboard.png"); - - if (dancepad) - dancepadImgData = Resources::GetImageData("dancepadR.png"); - else dancepadImgData = Resources::GetImageData("dancepad.png"); - - // look for optional accessories - for (u32 i = 0; i < GameInfo.AccessoirList.size(); ++i) - { - if(GameInfo.AccessoirList[i].Required) - continue; - - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "guitar") == 0) guitar = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "drums") == 0) drums = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "dancepad") == 0) dancepad = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "motionplus") == 0) motionplus = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wheel") == 0) wheel = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "microphone") == 0) microphone = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "zapper") == 0) zapper = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nintendods") == 0) nintendods = 1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1; - //if (strcmp(GameInfo.AccessoirList[i].Name.c_str(),"vitalitysensor")==0) - // vitalitysensor=1; - if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "gamecube") == 0) gamecube = 1; - } - - dialogBoxImg1 = new GuiImage(&dialogBox1); - dialogBoxImg1->SetAlignment(0, 3); - dialogBoxImg1->SetPosition(-9, 0); - - dialogBoxImg2 = new GuiImage(&dialogBox2); - dialogBoxImg2->SetAlignment(0, 3); - dialogBoxImg2->SetPosition(145, 0); - - dialogBoxImg3 = new GuiImage(&dialogBox3); - dialogBoxImg3->SetAlignment(0, 3); - dialogBoxImg3->SetPosition(301, 0); - - dialogBoxImg4 = new GuiImage(&dialogBox4); - dialogBoxImg4->SetAlignment(0, 3); - dialogBoxImg4->SetPosition(457, 0); - - gameinfoWindow.Append(dialogBoxImg1); - gameinfoWindow.Append(dialogBoxImg2); - gameinfoWindow.Append(dialogBoxImg3); - gameinfoWindow.Append(dialogBoxImg4); - - char imgPath[150]; - snprintf(imgPath, sizeof(imgPath), "%s%s.png", Settings.covers_path, ID); - cover = new GuiImageData(imgPath); //load full id image - if (!cover->GetImage()) - { - delete cover; - cover = Resources::GetImageData("nocover.png"); - } - delete coverImg; - coverImg = NULL; - - coverImg = new GuiImage(cover); - coverImg->SetWidescreen(Settings.widescreen); - coverImg->SetPosition(15, 30); - gameinfoWindow.Append(coverImg); - - // # of players - if (GameInfo.Players > 0) - { - if (GameInfo.Players == 1) - playersImgData = Resources::GetImageData("wiimote1.png"); - - else if (GameInfo.Players == 2) - playersImgData = Resources::GetImageData("wiimote2.png"); - - else if (GameInfo.Players == 4) - playersImgData = Resources::GetImageData("wiimote4.png"); - - playersImg = new GuiImage(playersImgData); - playersImg->SetWidescreen(Settings.widescreen); - playersImg->SetPosition(intputX, inputY); - playersImg->SetAlignment(0, 4); - gameinfoWindow.Append(playersImg); - intputX += (Settings.widescreen ? playersImg->GetWidth() * .8 : playersImg->GetWidth()) + 5; - } - - //draw the input types for this game - if (motionplus == 1) - { - motionplusImg = new GuiImage(motionplusImgData); - motionplusImg->SetWidescreen(Settings.widescreen); - motionplusImg->SetPosition(intputX, inputY); - motionplusImg->SetAlignment(0, 4); - gameinfoWindow.Append(motionplusImg); - intputX += (Settings.widescreen ? motionplusImg->GetWidth() * .8 : motionplusImg->GetWidth()) + 5; - } - if (nunchuk == 1) - { - nunchukImg = new GuiImage(nunchukImgData); - nunchukImg->SetWidescreen(Settings.widescreen); - nunchukImg->SetPosition(intputX, inputY); - nunchukImg->SetAlignment(0, 4); - gameinfoWindow.Append(nunchukImg); - intputX += (Settings.widescreen ? nunchukImg->GetWidth() * .8 : nunchukImg->GetWidth()) + 5; - } - if (classiccontroller == 1) - { - classiccontrollerImg = new GuiImage(classiccontrollerImgData); - classiccontrollerImg->SetWidescreen(Settings.widescreen); - classiccontrollerImg->SetPosition(intputX, inputY); - classiccontrollerImg->SetAlignment(0, 4); - gameinfoWindow.Append(classiccontrollerImg); - intputX += (Settings.widescreen ? classiccontrollerImg->GetWidth() * .8 : classiccontrollerImg->GetWidth()) - + 5; - } - if (gamecube == 1) - { - gcImg = new GuiImage(gamecubeImgData); - gcImg->SetWidescreen(Settings.widescreen); - gcImg->SetPosition(intputX, inputY); - gcImg->SetAlignment(0, 4); - gameinfoWindow.Append(gcImg); - intputX += (Settings.widescreen ? gcImg->GetWidth() * .8 : gcImg->GetWidth()) + 5; - } - if (wheel == 1) - { - wheelImg = new GuiImage(wheelImgData); - wheelImg->SetWidescreen(Settings.widescreen); - wheelImg->SetPosition(intputX, inputY); - wheelImg->SetAlignment(0, 4); - gameinfoWindow.Append(wheelImg); - intputX += (Settings.widescreen ? wheelImg->GetWidth() * .8 : wheelImg->GetWidth()) + 5; - } - if (guitar == 1) - { - guitarImg = new GuiImage(guitarImgData); - guitarImg->SetWidescreen(Settings.widescreen); - guitarImg->SetPosition(intputX, inputY); - guitarImg->SetAlignment(0, 4); - gameinfoWindow.Append(guitarImg); - intputX += (Settings.widescreen ? guitarImg->GetWidth() * .8 : guitarImg->GetWidth()) + 5; - } - if (drums == 1) - { - drumsImg = new GuiImage(drumsImgData); - drumsImg->SetWidescreen(Settings.widescreen); - drumsImg->SetPosition(intputX, inputY); - drumsImg->SetAlignment(0, 4); - gameinfoWindow.Append(drumsImg); - intputX += (Settings.widescreen ? drumsImg->GetWidth() * .8 : drumsImg->GetWidth()) + 5; - } - if (microphone == 1) - { - microphoneImg = new GuiImage(microphoneImgData); - microphoneImg->SetWidescreen(Settings.widescreen); - microphoneImg->SetPosition(intputX, inputY); - microphoneImg->SetAlignment(0, 4); - gameinfoWindow.Append(microphoneImg); - intputX += (Settings.widescreen ? microphoneImg->GetWidth() * .8 : microphoneImg->GetWidth()) + 5; - } - if (zapper == 1) - { - zapperImg = new GuiImage(zapperImgData); - zapperImg->SetWidescreen(Settings.widescreen); - zapperImg->SetPosition(intputX, inputY); - zapperImg->SetAlignment(0, 4); - gameinfoWindow.Append(zapperImg); - intputX += (Settings.widescreen ? zapperImg->GetWidth() * .8 : zapperImg->GetWidth()) + 5; - } - if (wiispeak == 1) - { - wiispeakImg = new GuiImage(wiispeakImgData); - wiispeakImg->SetWidescreen(Settings.widescreen); - wiispeakImg->SetPosition(intputX, inputY); - wiispeakImg->SetAlignment(0, 4); - gameinfoWindow.Append(wiispeakImg); - intputX += (Settings.widescreen ? wiispeakImg->GetWidth() * .8 : wiispeakImg->GetWidth()) + 5; - } - if (nintendods == 1) - { - nintendodsImg = new GuiImage(nintendodsImgData); - nintendodsImg->SetWidescreen(Settings.widescreen); - nintendodsImg->SetPosition(intputX, inputY); - nintendodsImg->SetAlignment(0, 4); - gameinfoWindow.Append(nintendodsImg); - intputX += (Settings.widescreen ? nintendodsImg->GetWidth() * .8 : nintendodsImg->GetWidth()) + 5; - } - if (dancepad == 1) - { - dancepadImg = new GuiImage(dancepadImgData); - dancepadImg->SetWidescreen(Settings.widescreen); - dancepadImg->SetPosition(intputX, inputY); - dancepadImg->SetAlignment(0, 4); - gameinfoWindow.Append(dancepadImg); - intputX += (Settings.widescreen ? dancepadImg->GetWidth() * .8 : dancepadImg->GetWidth()) + 5; - } - if (balanceboard == 1) - { - balanceboardImg = new GuiImage(balanceboardImgData); - balanceboardImg->SetWidescreen(Settings.widescreen); - balanceboardImg->SetPosition(intputX, inputY); - balanceboardImg->SetAlignment(0, 4); - gameinfoWindow.Append(balanceboardImg); - intputX += (Settings.widescreen ? balanceboardImg->GetWidth() * .8 : balanceboardImg->GetWidth()) + 5; - } - - // # online players - if (GameInfo.WifiPlayers > 0) - { - if(GameInfo.WifiPlayers == 1) - wifiplayersImgData = Resources::GetImageData("wifi1.png"); - - else if(GameInfo.WifiPlayers == 2) - wifiplayersImgData = Resources::GetImageData("wifi2.png"); - - else if(GameInfo.WifiPlayers == 4) - wifiplayersImgData = Resources::GetImageData("wifi4.png"); - - else if(GameInfo.WifiPlayers == 8) - wifiplayersImgData =Resources::GetImageData("wifi8.png"); - - else if(GameInfo.WifiPlayers == 12) - wifiplayersImgData = Resources::GetImageData("wifi12.png"); - - else if(GameInfo.WifiPlayers == 16) - wifiplayersImgData = Resources::GetImageData("wifi16.png"); - - else if(GameInfo.WifiPlayers == 32) - wifiplayersImgData = Resources::GetImageData("wifi32.png"); - - wifiplayersImg = new GuiImage(wifiplayersImgData); - wifiplayersImg->SetWidescreen(Settings.widescreen); - wifiplayersImg->SetPosition(intputX, inputY); - wifiplayersImg->SetAlignment(0, 4); - gameinfoWindow.Append(wifiplayersImg); - intputX += (Settings.widescreen ? wifiplayersImg->GetWidth() * .8 : wifiplayersImg->GetWidth()) + 5; - } - - // ratings - if (GameInfo.RatingType >= 0) - { - if (GameInfo.RatingType == 1) - { - if (strcmp(GameInfo.RatingValue.c_str(), "EC") == 0) - ratingImgData = Resources::GetImageData("esrb_ec.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "E") == 0) - ratingImgData = Resources::GetImageData("esrb_e.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "E10+") == 0) - ratingImgData = Resources::GetImageData("esrb_eten.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "T") == 0) - ratingImgData = Resources::GetImageData("esrb_t.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "M") == 0) - ratingImgData = Resources::GetImageData("esrb_m.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "AO") == 0) - ratingImgData = Resources::GetImageData("esrb_ao.png"); - else - ratingImgData = Resources::GetImageData("norating.png"); - } //there are 2 values here cause some countries are stupid and - else if (GameInfo.RatingType == 2) //can't use the same as everybody else - { - if ((strcmp(GameInfo.RatingValue.c_str(), "3") == 0) || (strcmp(GameInfo.RatingValue.c_str(), "4") == 0)) - ratingImgData = Resources::GetImageData("pegi_3.png"); - else if ((strcmp(GameInfo.RatingValue.c_str(), "7") == 0) || (strcmp(GameInfo.RatingValue.c_str(), "7") == 0)) - ratingImgData = Resources::GetImageData("pegi_7.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "12") == 0) - ratingImgData = Resources::GetImageData("pegi_12.png"); - else if ((strcmp(GameInfo.RatingValue.c_str(), "16") == 0) || (strcmp(GameInfo.RatingValue.c_str(), "15") == 0)) - ratingImgData = Resources::GetImageData("pegi_16.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "18") == 0) - ratingImgData = Resources::GetImageData("pegi_18.png"); - else - { - ratingImgData = Resources::GetImageData("norating.png"); - } - } - else if (GameInfo.RatingType == 0) - { - if (strcmp(GameInfo.RatingValue.c_str(), "A") == 0) - ratingImgData = Resources::GetImageData("cero_a.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "B") == 0) - ratingImgData = Resources::GetImageData("cero_b.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "C") == 0) - ratingImgData = Resources::GetImageData("cero_c.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "D") == 0) - ratingImgData = Resources::GetImageData("cero_d.png"); - else if (strcmp(GameInfo.RatingValue.c_str(), "Z") == 0) - ratingImgData = Resources::GetImageData("cero_z.png"); - else - { - ratingImgData = Resources::GetImageData("norating.png"); - } - } - - else - { - ratingImgData = Resources::GetImageData("norating.png"); - } - ratingImg = new GuiImage(ratingImgData); - ratingImg->SetWidescreen(Settings.widescreen); - ratingImg->SetPosition(-25, inputY); - ratingImg->SetAlignment(1, 4); - gameinfoWindow.Append(ratingImg); - intputX += (Settings.widescreen ? ratingImg->GetWidth() * .8 : ratingImg->GetWidth()) + 5; - } - - // memory info - if (showmeminfo) - { - char meminfotxt[200]; - strlcpy(meminfotxt, MemInfo(), sizeof(meminfotxt)); - memTxt = new GuiText(meminfotxt, 18, ( GXColor ) {0, 0, 0, 255}); - memTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - memTxt->SetPosition(0, 0); - gameinfoWindow.Append(memTxt); - } - - // title - int titlefontsize = 25; - if (GameInfo.Title.size() > 0) - { - titleTxt = new GuiText(GameInfo.Title.c_str(), titlefontsize, ( GXColor ) {0, 0, 0, 255}); - titleTxt->SetMaxWidth(350, SCROLL_HORIZONTAL); - titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt->SetPosition(txtXOffset, 12 + titley); - gameinfoWindow.Append(titleTxt); - } - - //date - snprintf(linebuf2, sizeof(linebuf2), " "); - if (GameInfo.PublishDate != 0) - { - int year = GameInfo.PublishDate >> 16; - int day = GameInfo.PublishDate & 0xFF; - int month = (GameInfo.PublishDate >> 8) & 0xFF; - snprintf(linebuf2, sizeof(linebuf2), "%02i ", day); - - switch (month) - { - case 1: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Jan" )); - break; - case 2: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Feb" )); - break; - case 3: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Mar" )); - break; - case 4: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Apr" )); - break; - case 5: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "May" )); - break; - case 6: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "June" )); - break; - case 7: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "July" )); - break; - case 8: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Aug" )); - break; - case 9: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Sept" )); - break; - case 10: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Oct" )); - break; - case 11: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Nov" )); - break; - case 12: - snprintf(linebuf2, sizeof(linebuf2), "%s%s ", linebuf2, tr( "Dec" )); - break; - } - - char linebuf[300]; - snprintf(linebuf, sizeof(linebuf), "%s : %s%i", tr( "Released" ), linebuf2, year); - releasedTxt = new GuiText(linebuf, 16, ( GXColor ) {0, 0, 0, 255}); - if (releasedTxt->GetWidth() > 300) newline = 2; - releasedTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - releasedTxt->SetPosition(-17, 12 + indexy); - indexy += (20 * newline); - newline = 1; - gameinfoWindow.Append(releasedTxt); - } - - //publisher - if (GameInfo.Publisher.size() != 0) - { - snprintf(linebuf2, sizeof(linebuf2), "%s %s", tr( "Published by" ), GameInfo.Publisher.c_str()); - publisherTxt = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); - if (publisherTxt->GetWidth() > 250) newline = 2; - publisherTxt->SetMaxWidth(250, WRAP); - publisherTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - publisherTxt->SetPosition(-17, 12 + indexy); - indexy += (20 * newline); - newline = 1; - gameinfoWindow.Append(publisherTxt); - } - - //developer - if (GameInfo.Developer.size() != 0 && strcasecmp(GameInfo.Developer.c_str(), GameInfo.Publisher.c_str()) != 0) - { - snprintf(linebuf2, sizeof(linebuf2), "%s %s", tr( "Developed by" ), GameInfo.Developer.c_str()); - developerTxt = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); - if (developerTxt->GetWidth() > 250) newline = 2; - developerTxt->SetMaxWidth(250, WRAP); - developerTxt->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - developerTxt->SetPosition(-17, 12 + indexy); - indexy += (20 * newline); - newline = 1; - gameinfoWindow.Append(developerTxt); - } - - //genre - int genreY = marginY; - if(GameInfo.GenreList.size() > 0) - { - genreTitleTxt = new GuiText(tr("Gerne:"), 16, ( GXColor ) {0, 0, 0, 255}); - genreTitleTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - genreTitleTxt->SetPosition(205, 12 + genreY); - genreY += 20; - gameinfoWindow.Append(genreTitleTxt); - } - - genreTxt = new GuiText *[GameInfo.GenreList.size()+1]; //to not alloc a 0 vector - for (u32 i = 0; i < GameInfo.GenreList.size(); ++i) - { - genreTxt[i] = new GuiText(GameInfo.GenreList[i].c_str(), 16, ( GXColor ) {0, 0, 0, 255}); - genreTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - genreTxt[i]->SetPosition(215, 12 + genreY); - genreY += 20; - gameinfoWindow.Append(genreTxt[i]); - } - - //online - wifiTxt = new GuiText *[GameInfo.WifiFeatureList.size()+1]; //to not alloc a 0 vector - for (int i = GameInfo.WifiFeatureList.size()-1; i >= 0 && GameInfo.WifiFeatureList.size() > 0; --i) - { - if (strcmp(GameInfo.WifiFeatureList[i].c_str(), "Nintendods") == 0) - { - snprintf(linebuf2, sizeof(linebuf2), "Nintendo DS"); - } - else - { - snprintf(linebuf2, sizeof(linebuf2), "%s", GameInfo.WifiFeatureList[i].c_str()); - } - wifiTxt[i] = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); - wifiTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - wifiTxt[i]->SetPosition(215, 200 + wifiY); - wifiY -= 20; - gameinfoWindow.Append(wifiTxt[i]); - } - if (GameInfo.WifiFeatureList.size() > 0) - { - snprintf(linebuf2, sizeof(linebuf2), "%s:", tr( "WiFi Features" )); - } - else - { - strcpy(linebuf2, ""); - } - wifiTxt[0] = new GuiText(linebuf2, 16, ( GXColor ) {0, 0, 0, 255}); - wifiTxt[0]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - wifiTxt[0]->SetPosition(205, 200 + wifiY); - gameinfoWindow.Append(wifiTxt[0]); - - //synopsis - int pagesize = 12; - if (GameInfo.Synopsis.size() != 0) - { - synopsisTxt = new Text(GameInfo.Synopsis.c_str(), 16, ( GXColor ) {0, 0, 0, 255}); - synopsisTxt->SetMaxWidth(350); - synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - synopsisTxt->SetPosition(0, 0); - synopsisTxt->SetLinesToDraw(pagesize); - synopsisTxt->Refresh(); - - dialogBoxImg11 = new GuiImage(&dialogBox1); - dialogBoxImg11->SetAlignment(0, 3); - dialogBoxImg11->SetPosition(-9, 0); - - dialogBoxImg22 = new GuiImage(&dialogBox2); - dialogBoxImg22->SetAlignment(0, 3); - dialogBoxImg22->SetPosition(145, 0); - - dialogBoxImg33 = new GuiImage(&dialogBox3); - dialogBoxImg33->SetAlignment(0, 3); - dialogBoxImg33->SetPosition(301, 0); - - dialogBoxImg44 = new GuiImage(&dialogBox4); - dialogBoxImg44->SetAlignment(0, 3); - dialogBoxImg44->SetPosition(457, 0); - - gameinfoWindow2.Append(dialogBoxImg11); - gameinfoWindow2.Append(dialogBoxImg22); - gameinfoWindow2.Append(dialogBoxImg33); - gameinfoWindow2.Append(dialogBoxImg44); - - txtWindow.Append(synopsisTxt); - txtWindow.Append(&upBtn); - txtWindow.Append(&dnBtn); - coverImg2 = new GuiImage(cover); - coverImg2->SetWidescreen(Settings.widescreen); - coverImg2->SetPosition(15, 30); - gameinfoWindow2.Append(coverImg2); - gameinfoWindow2.Append(&txtWindow); - } - - wiitdb1Txt = new GuiText("http://wiitdb.com", 16, ( GXColor ) {0, 0, 0, 255}); - wiitdb1Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiitdb1Txt->SetPosition(40, -15); - gameinfoWindow.Append(wiitdb1Txt); - - wiitdb2Txt = new GuiText(tr( "If you don't have WiFi, press 1 to get an URL to get your WiiTDB.zip" ), 14, ( GXColor ) {0, 0, 0, 255}); - wiitdb2Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiitdb2Txt->SetPosition(202, -15); - gameinfoWindow.Append(wiitdb2Txt); - - wiitdb3Txt = new GuiText(" ", 14, ( GXColor ) {0, 0, 0, 255}); - wiitdb3Txt->SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); - wiitdb3Txt->SetPosition(202, -4); - gameinfoWindow.Append(wiitdb3Txt); - - gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 100); - - GuiTrigger trigZ; - trigZ.SetButtonOnlyTrigger(-1, WPAD_NUNCHUK_BUTTON_Z | WPAD_CLASSIC_BUTTON_ZL, PAD_TRIGGER_Z); - - GuiButton screenShotBtn(0, 0); - screenShotBtn.SetPosition(0, 0); - screenShotBtn.SetTrigger(&trigZ); - gameinfoWindow.Append(&screenShotBtn); - HaltGui(); - //mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&gameinfoWindow); - mainWindow->ChangeFocus(&gameinfoWindow); - ResumeGui(); - - bool savedURL = false; - - while (choice == -1) - { - - VIDEO_WaitVSync(); - if (shutdown == 1) - { - wiilight(0); - Sys_Shutdown(); - } - else if (reset == 1) - Sys_Reboot(); - - else if ((backBtn.GetState() == STATE_CLICKED) || (backBtn.GetState() == STATE_HELD)) - { - backBtn.ResetState(); - if (page == 1) - { - choice = 1; - if (synopsisTxt) delete synopsisTxt; - synopsisTxt = NULL; - break; - } - else if (page == 2) - { - HaltGui(); - gameinfoWindow2.Remove(&nextBtn); - gameinfoWindow2.Remove(&backBtn); - gameinfoWindow2.Remove(&homeBtn); - gameinfoWindow2.Remove(&screenShotBtn); - gameinfoWindow2.SetVisible(false); - gameinfoWindow.SetVisible(true); - gameinfoWindow.Append(&backBtn); - gameinfoWindow.Append(&nextBtn); - gameinfoWindow.Append(&homeBtn); - gameinfoWindow.Append(&screenShotBtn); - mainWindow->Remove(&gameinfoWindow2); - ResumeGui(); - page = 1; - } - } - else if (((nextBtn.GetState() == STATE_CLICKED) || (nextBtn.GetState() == STATE_HELD)) && GameInfo.Synopsis.size() > 0) - { - nextBtn.ResetState(); - - if (page == 1) - { - HaltGui(); - gameinfoWindow.Remove(&nextBtn); - gameinfoWindow.Remove(&backBtn); - gameinfoWindow.Remove(&homeBtn); - gameinfoWindow.Remove(&screenShotBtn); - gameinfoWindow.SetVisible(false); - gameinfoWindow2.SetVisible(true); - coverImg->SetPosition(15, 30); - gameinfoWindow2.Append(&nextBtn); - gameinfoWindow2.Append(&backBtn); - gameinfoWindow2.Append(&homeBtn); - gameinfoWindow2.Append(&screenShotBtn); - mainWindow->Append(&gameinfoWindow2); - ResumeGui(); - page = 2; - } - else - { - HaltGui(); - gameinfoWindow2.Remove(&nextBtn); - gameinfoWindow2.Remove(&backBtn); - gameinfoWindow2.Remove(&homeBtn); - gameinfoWindow2.Remove(&screenShotBtn); - gameinfoWindow2.SetVisible(false); - gameinfoWindow.SetVisible(true); - gameinfoWindow.Append(&backBtn); - gameinfoWindow.Append(&nextBtn); - gameinfoWindow.Append(&homeBtn); - gameinfoWindow.Append(&screenShotBtn); - mainWindow->Remove(&gameinfoWindow2); - ResumeGui(); - page = 1; - } - - } - else if ((upBtn.GetState() == STATE_CLICKED || upBtn.GetState() == STATE_HELD) && page == 2) - { - synopsisTxt->PreviousLine(); - - usleep(60000); - if (!((ButtonsHold() & WPAD_BUTTON_UP) || (ButtonsHold() & PAD_BUTTON_UP))) upBtn.ResetState(); - - } - else if ((dnBtn.GetState() == STATE_CLICKED || dnBtn.GetState() == STATE_HELD) && page == 2) - { - synopsisTxt->NextLine(); - - usleep(60000); - if (!((ButtonsHold() & WPAD_BUTTON_DOWN) || (ButtonsHold() & PAD_BUTTON_DOWN))) dnBtn.ResetState(); - } - else if (homeBtn.GetState() == STATE_CLICKED) - { - if (page == 1) - { - choice = 2; - if (synopsisTxt) delete synopsisTxt; - synopsisTxt = NULL; - break; - } - else if (page == 2) - { - HaltGui(); - gameinfoWindow2.SetVisible(false); - gameinfoWindow.SetVisible(true); - mainWindow->Remove(&gameinfoWindow2); - ResumeGui(); - page = 1; - } - } - else if (urlBtn.GetState() == STATE_CLICKED && !savedURL) - { - wiitdb2Txt->SetText(tr( "Please wait..." )); - gameinfoWindow.Append(wiitdb2Txt); - if (save_XML_URL()) - { - snprintf(linebuf2, sizeof(linebuf2), tr( "Your URL has been saved in %sWiiTDB_URL.txt." ), Settings.update_path); - wiitdb2Txt->SetText(linebuf2); - gameinfoWindow.Append(wiitdb2Txt); - - wiitdb3Txt->SetText(tr( "Paste it into your browser to get your WiiTDB.zip." )); - gameinfoWindow.Append(wiitdb3Txt); - savedURL = true; - } - else - { - wiitdb2Txt->SetText(tr( "Could not save." )); - gameinfoWindow.Append(wiitdb2Txt); - } - urlBtn.ResetState(); - } - else if (screenShotBtn.GetState() == STATE_CLICKED) - { - gprintf("\n\tscreenShotBtn clicked"); - screenShotBtn.ResetState(); - ScreenShot(); - gprintf("...It's easy, mmmmmmKay"); - } - } - - gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, 100); - while (gameinfoWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&gameinfoWindow); - mainWindow->SetState(STATE_DEFAULT); - - delete playersImgData; - delete playersImg; - - delete wifiplayersImgData; - delete wifiplayersImg; - delete ratingImg; - - delete classiccontrollerImg; - delete nunchukImg; - delete guitarImg; - delete drumsImg; - delete dancepadImg; - delete motionplusImg; - delete wheelImg; - delete balanceboardImg; - delete microphoneImg; - delete zapperImg; - delete wiispeakImg; - delete nintendodsImg; - delete gcImg; - delete dialogBoxImg1; - delete dialogBoxImg2; - delete dialogBoxImg3; - delete dialogBoxImg4; - delete dialogBoxImg11; - delete dialogBoxImg22; - delete dialogBoxImg33; - delete dialogBoxImg44; - delete coverImg; - delete coverImg2; - delete classiccontrollerImgData; - delete nunchukImgData; - delete guitarImgData; - delete drumsImgData; - delete motionplusImgData; - delete wheelImgData; - delete balanceboardImgData; - delete dancepadImgData; - delete microphoneImgData; - delete zapperImgData; - delete wiispeakImgData; - delete nintendodsImgData; - delete gamecubeImgData; - delete ratingImgData; - delete cover; - delete releasedTxt; - delete publisherTxt; - delete developerTxt; - delete titleTxt; - delete synopsisTxt; - delete genreTitleTxt; - delete wiitdb1Txt; - delete wiitdb2Txt; - delete wiitdb3Txt; - delete memTxt; - for (u32 i = 0; i < GameInfo.GenreList.size(); ++i) - delete genreTxt[i]; - - for (u32 i = 0; i < GameInfo.WifiFeatureList.size(); ++i) - delete wifiTxt[i]; - - delete [] genreTxt; - delete [] wifiTxt; - - ResumeGui(); - - if (savedURL) return 3; - - return choice; -} - -bool save_gamelist(int txt) // save gamelist -{ - mainWindow->SetState(STATE_DISABLED); - char tmp[200]; - sprintf(tmp, "%s", Settings.update_path); - struct stat st; - if (stat(tmp, &st) != 0) - { - mkdir(tmp, 0777); - } - FILE *f; - sprintf(tmp, "%sGameList.txt", Settings.update_path); - if (txt == 1) sprintf(tmp, "%sGameList.csv", Settings.update_path); - f = fopen(tmp, "w"); - if (!f) - { - sleep(1); - mainWindow->SetState(STATE_DEFAULT); - return false; - } - //make sure that all games are added to the gamelist - gameList.LoadUnfiltered(); - - f32 size = 0.0; - f32 freespace, used; - int i; - - WBFS_DiskSpace(&used, &freespace); - - fprintf(f, "# USB Loader Has Saved this file\n"); - fprintf(f, "# This file was created based on your list of games and language settings.\n"); - fclose(f); - /* Closing and reopening because of a write issue we are having right now */ - f = fopen(tmp, "w"); - - if (txt == 0) - { - fprintf(f, "# USB Loader Has Saved this file\n"); - fprintf(f, "# This file was created based on your list of games and language settings.\n\n"); - - fprintf(f, "%.2fGB %s %.2fGB %s\n\n", freespace, tr( "of" ), (freespace + used), tr( "free" )); - fprintf(f, "ID Size(GB) Name\n"); - - for (i = 0; i < gameList.size(); i++) - { - struct discHdr* header = gameList[i]; - WBFS_GameSize(header->id, &size); - if (i < 500) - { - fprintf(f, "%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2], header->id[3], header->id[4], - header->id[5]); - fprintf(f, " [%.2f] ", size); - fprintf(f, " %s", GameTitles.GetTitle(header)); - } - fprintf(f, "\n"); - } - } - else - { - - fprintf(f, "\"ID\",\"Size(GB)\",\"Name\"\n"); - - for (i = 0; i < gameList.size(); i++) - { - struct discHdr* header = gameList[i]; - WBFS_GameSize(header->id, &size); - if (i < 500) - { - fprintf(f, "\"%c%c%c%c%c%c\",\"%.2f\",\"%s\"\n", header->id[0], header->id[1], header->id[2], - header->id[3], header->id[4], header->id[5], size, GameTitles.GetTitle(header)); - } - } - } - fclose(f); - - gameList.FilterList(); - mainWindow->SetState(STATE_DEFAULT); - return true; -} - -bool save_XML_URL() // save xml url as as txt file for people without wifi -{ - char tmp[200]; - sprintf(tmp, "%s", Settings.update_path); - struct stat st; - if (stat(tmp, &st) != 0) - { - mkdir(tmp, 0777); - } - FILE *f; - sprintf(tmp, "%sWiiTDB_URL.txt", Settings.update_path); - f = fopen(tmp, "w"); - if (!f) - { - sleep(1); - return false; - } - - char XMLurl[3540]; - build_XML_URL(XMLurl, sizeof(XMLurl)); - - fprintf(f, "# USB Loader Has Saved this file\n"); - fprintf(f, "# This URL was created based on your list of games and language settings.\n"); - fclose(f); - // Closing and reopening because of a write issue we are having right now - f = fopen(tmp, "w"); - fprintf(f, "# USB Loader Has Saved this file\n"); - fprintf(f, "# This URL was created based on your list of games and language settings.\n"); - fprintf(f, - "# Copy and paste this URL into your web browser and you should get a zip file that will work for you.\n"); - fprintf(f, "%s\n\n\n ", XMLurl); - - fclose(f); - - return true; -} - -void MemInfoPrompt() -{ - char meminfotxt[200]; - strlcpy(meminfotxt, MemInfo(), sizeof(meminfotxt)); - WindowPrompt(0, meminfotxt, tr( "OK" )); -} - -void build_XML_URL(char *XMLurl, int XMLurlsize) -{ - gameList.LoadUnfiltered(); - // NET_BUFFER_SIZE in http.c needs to be set to size of XMLurl + headerformat - char url[3540]; - char filename[10]; - snprintf(url, sizeof(url), "http://wiitdb.com/wiitdb.zip?LANG=%s&ID=", Settings.db_language); - int i; - for (i = 0; i < gameList.size(); i++) - { - struct discHdr* header = gameList[i]; - if (i < 500) - { - snprintf(filename, sizeof(filename), "%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2], - header->id[3], header->id[4], header->id[5]); - strncat(url, filename, 6); - if ((i != gameList.size() - 1) && (i < 500)) strncat(url, ",", 1); - } - } - strlcpy(XMLurl, url, XMLurlsize); - gameList.FilterList(); -} diff --git a/source/prompts/gameinfo.h b/source/prompts/gameinfo.h deleted file mode 100644 index 4f46670b..00000000 --- a/source/prompts/gameinfo.h +++ /dev/null @@ -1,16 +0,0 @@ -/**************************************************************************** - * PromptWindows - * USB Loader GX 2009 - * - * PromptWindows.h - ***************************************************************************/ - -#ifndef _GAMEINFO_H_ -#define _GAMEINFO_H_ - -int showGameInfo(char *ID); -void build_XML_URL(char *XMLurl, int XMLurlsize); -bool save_XML_URL(); -bool save_gamelist(int txt); -void MemInfoPrompt(); -#endif diff --git a/source/settings/CGameSettings.cpp b/source/settings/CGameSettings.cpp deleted file mode 100644 index 7cae81d2..00000000 --- a/source/settings/CGameSettings.cpp +++ /dev/null @@ -1,408 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include - -#include "CGameSettings.h" -#include "FileOperations/fileops.h" - -CGameSettings GameSettings; - -const char * VideoMap[] = -{ - "system", - "game", - "patch", - "pal50", - "pal60", - "ntsc", - NULL -}; - -const char * LanguageMap[] = -{ - "console", - "japanese", - "english", - "german", - "french", - "spanish", - "italian", - "dutch", - "schinese", - "tchinese", - "korean", - NULL -}; - - -CGameSettings::CGameSettings() -{ -} - -CGameSettings::~CGameSettings() -{ -} - -GameCFG * CGameSettings::GetGameCFG(const char * id) -{ - if(!id) - return NULL; - - for(u32 i = 0; i < GameList.size(); ++i) - { - if(strncmp(id, GameList[i].id, 6) == 0) - { - return &GameList[i]; - } - } - - return NULL; -} - -bool CGameSettings::AddGame(const GameCFG & NewGame) -{ - for(u32 i = 0; i < GameList.size(); ++i) - { - if(strncmp(NewGame.id, GameList[i].id, 6) == 0) - { - memcpy(&GameList[i], &NewGame, sizeof(GameCFG)); - return true; - } - } - - GameList.push_back(NewGame); - - return true; -} - -bool CGameSettings::RemoveAll() -{ - GameList.clear(); - std::vector().swap(GameList); - - return Save(); -} - -bool CGameSettings::Remove(const char * id) -{ - if(!id) - return false; - - for(u32 i = 0; i < GameList.size(); ++i) - { - if(strncmp(id, GameList[i].id, 6) == 0) - { - GameList.erase(GameList.begin()+i); - break; - } - } - - return true; -} - -bool CGameSettings::Load(const char * path) -{ - char line[1024]; - char filepath[300]; - snprintf(filepath, sizeof(filepath), "%sGXGameSettings.cfg", path); - - ConfigPath = filepath; - - FILE *file = fopen(filepath, "r"); - if (!file) return false; - - while (fgets(line, sizeof(line), file)) - { - if (line[0] == '#') - continue; - - this->ParseLine(line); - } - fclose(file); - - return true; -} - -bool CGameSettings::Save() -{ - char filepath[300]; - strcpy(filepath, ConfigPath.c_str()); - - char * ptr = strrchr(filepath, '/'); - if(ptr) - ptr[0] = 0; - - CreateSubfolder(filepath); - - FILE * f = fopen(ConfigPath.c_str(), "w"); - if (!f) return false; - - fprintf(f, "# USB Loader settings file\n"); - fprintf(f, "# note: this file is automatically generated\n"); - fprintf(f, "# Num Games: %d\n", GameList.size()); - for (u32 i = 0; i < GameList.size(); ++i) - { - fprintf(f, "game:%s = ", GameList[i].id); - fprintf(f, "video:%s; ", VideoMap[GameList[i].video]); - fprintf(f, "language:%s; ", LanguageMap[GameList[i].language]); - fprintf(f, "ocarina:%d; ", GameList[i].ocarina); - fprintf(f, "vipatch:%d; ", GameList[i].vipatch); - fprintf(f, "ios:%d; ", GameList[i].ios); - fprintf(f, "parentalcontrol:%d; ", GameList[i].parentalcontrol); - fprintf(f, "errorfix002:%d; ", GameList[i].errorfix002); - fprintf(f, "iosreloadblock:%d; ", GameList[i].iosreloadblock); - fprintf(f, "patchcountrystrings:%d; ", GameList[i].patchcountrystrings); - fprintf(f, "loadalternatedol:%d; ", GameList[i].loadalternatedol); - fprintf(f, "alternatedolstart:%d; ", GameList[i].alternatedolstart); - fprintf(f, "alternatedolname:%s; ", GameList[i].alternatedolname); - fprintf(f, "returnTo:%d; ", GameList[i].returnTo); - fprintf(f, "Locked:%d;\n", GameList[i].Locked); - } - fprintf(f, "# END\n"); - fclose(f); - - return true; -} - -bool CGameSettings::SetSetting(GameCFG & game, char *name, char *value) -{ - int i = 0; - - if (strcmp(name, "video") == 0) - { - for(i = 0; VideoMap[i] != NULL; ++i) - { - if(strcasecmp(value, VideoMap[i]) == 0) - { - game.video = i; - break; - } - } - return true; - } - else if(strcmp(name, "language") == 0) - { - for(i = 0; LanguageMap[i] != NULL; ++i) - { - if(strcasecmp(value, LanguageMap[i]) == 0) - { - game.language = i; - break; - } - } - return true; - } - else if(strcmp(name, "ocarina") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.ocarina = i; - } - return true; - } - else if(strcmp(name, "vipatch") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.vipatch = i; - } - return true; - } - else if(strcmp(name, "ios") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.ios = i; - } - return true; - } - else if(strcmp(name, "parentalcontrol") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.parentalcontrol = i; - } - return true; - } - else if(strcmp(name, "errorfix002") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.errorfix002 = i; - } - return true; - } - else if(strcmp(name, "iosreloadblock") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.iosreloadblock = i; - } - return true; - } - else if(strcmp(name, "loadalternatedol") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.loadalternatedol = i; - } - return true; - } - else if(strcmp(name, "alternatedolstart") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.alternatedolstart = i; - } - return true; - } - else if(strcmp(name, "patchcountrystrings") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.patchcountrystrings = i; - } - return true; - } - else if(strcmp(name, "alternatedolname") == 0) - { - snprintf(game.alternatedolname, sizeof(game.alternatedolname), value); - return true; - } - else if(strcmp(name, "returnTo") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.returnTo = i; - } - return true; - } - else if(strcmp(name, "Locked") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.Locked = i; - } - return true; - } - - return false; -} - -bool CGameSettings::ReadGameID(const char * src, char * GameID, int size) -{ - if(strncasecmp(src, "game:", 5) != 0) - return false; - - char * ptr = strchr(src, ':'); - if(!ptr) - return false; - - ptr++; - - int i = 0; - - for(i = 0; i < size; i++, ptr++) - { - if(*ptr == ' ' || *ptr == '\0') - break; - - GameID[i] = *ptr; - } - - GameID[i] = 0; - - return true; -} - -void CGameSettings::ParseLine(char *line) -{ - char name[1024], value[1024]; - char GameID[8]; - - if(!ReadGameID(line, GameID, 6)) - return; - - if(strlen(GameID) != 6) - return; - - GameCFG NewCFG; - memset(&NewCFG, 0, sizeof(GameCFG)); - - strcpy(NewCFG.id, GameID); - - char * LinePtr = strchr(line, '='); - - while(LinePtr != NULL) - { - LinePtr++; - - char * eq = strchr(LinePtr, ':'); - - if (!eq) break; - - this->TrimLine(name, LinePtr, sizeof(name)); - this->TrimLine(value, eq + 1, sizeof(value)); - - SetSetting(NewCFG, name, value); - - LinePtr = strchr(LinePtr, ';'); - } - - AddGame(NewCFG); -} - -void CGameSettings::TrimLine(char *dest, const char *src, int size) -{ - while (*src == ' ') - src++; - - int i = 0; - - for(i = 0; i < size; i++, src++) - { - if(*src == ':' || *src == ';' || *src == '\n' || - *src == '\r' || *src == '\0') - break; - - dest[i] = *src; - } - - dest[i] = '\0'; -} - -int CGameSettings::GetPartenalPEGI(int parental) -{ - switch(parental) - { - case 1: return 7; - case 2: return 12; - case 3: return 16; - case 4: return 18; - default: return -1; - } -} diff --git a/source/settings/CGameSettings.h b/source/settings/CGameSettings.h deleted file mode 100644 index 815d5275..00000000 --- a/source/settings/CGameSettings.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _GAME_SETTINGS_H_ -#define _GAME_SETTINGS_H_ - -#include -#include -#include -#include -#include "usbloader/disc.h" - -typedef struct _GameCFG -{ - char id[7]; - u8 video; - u8 language; - u8 ocarina; - u8 vipatch; - u8 ios; - u8 parentalcontrol; - u8 errorfix002; - u8 iosreloadblock; - u8 loadalternatedol; - u32 alternatedolstart; - u8 patchcountrystrings; - char alternatedolname[40]; - u8 returnTo; - u8 Locked; -} GameCFG; - -class CGameSettings -{ - public: - //!Constructor - CGameSettings(); - //!Destructor - ~CGameSettings(); - //!Load - bool Load(const char * path); - //!Save - bool Save(); - //!AddGame - bool AddGame(const GameCFG & NewGame); - //!Reset - bool RemoveAll(); - //!Overload Reset for one Game - bool Remove(const char * id); - bool Remove(const u8 * id) { return Remove((const char *) id); }; - bool Remove(const struct discHdr * game) { if(!game) return false; else return Remove(game->id); }; - //!Get GameCFG - GameCFG * GetGameCFG(const char * id); - //!Overload - GameCFG * GetGameCFG(const u8 * id) { return GetGameCFG((const char *) id); }; - //!Overload - GameCFG * GetGameCFG(const struct discHdr * game) { if(!game) return NULL; else return GetGameCFG(game->id); }; - //!Quick settings to PEGI conversion - static int GetPartenalPEGI(int parentalsetting); - protected: - bool ReadGameID(const char * src, char * GameID, int size); - bool SetSetting(GameCFG & game, char *name, char *value); - //!Find the config file in the default paths - bool FindConfig(); - - void ParseLine(char *line); - void TrimLine(char *dest, const char *src, int size); - std::string ConfigPath; - std::vector GameList; -}; - -extern CGameSettings GameSettings; - -#endif diff --git a/source/settings/CGameStatistics.cpp b/source/settings/CGameStatistics.cpp deleted file mode 100644 index 5afc6697..00000000 --- a/source/settings/CGameStatistics.cpp +++ /dev/null @@ -1,297 +0,0 @@ -#include -#include -#include -#include - -#include "CGameStatistics.h" -#include "FileOperations/fileops.h" - -CGameStatistics GameStatistics; - - -CGameStatistics::CGameStatistics() -{ -} - -CGameStatistics::~CGameStatistics() -{ -} - -GameStatus * CGameStatistics::GetGameStatus(const char * id) -{ - if(!id) - return NULL; - - for(u32 i = 0; i < GameList.size(); ++i) - { - if(strncmp(id, GameList[i].id, 6) == 0) - { - return &GameList[i]; - } - } - - return NULL; -} - -bool CGameStatistics::AddGame(const GameStatus & NewGame) -{ - for(u32 i = 0; i < GameList.size(); ++i) - { - if(strncmp(NewGame.id, GameList[i].id, 6) == 0) - { - memcpy(&GameList[i], &NewGame, sizeof(GameStatus)); - return true; - } - } - - GameList.push_back(NewGame); - - return true; -} - -bool CGameStatistics::RemoveAll() -{ - GameList.clear(); - std::vector().swap(GameList); - - return Save(); -} - -bool CGameStatistics::Remove(const char * id) -{ - if(!id) - return false; - - for(u32 i = 0; i < GameList.size(); ++i) - { - if(strncmp(id, GameList[i].id, 6) == 0) - { - GameList.erase(GameList.begin()+i); - break; - } - } - - return true; -} - -bool CGameStatistics::Load(const char * path) -{ - char line[1024]; - char filepath[300]; - snprintf(filepath, sizeof(filepath), "%sGXGameStatistics.cfg", path); - - ConfigPath = filepath; - - FILE *file = fopen(filepath, "r"); - if (!file) return false; - - while (fgets(line, sizeof(line), file)) - { - if (line[0] == '#') - continue; - - this->ParseLine(line); - } - fclose(file); - - return true; -} - -bool CGameStatistics::Save() -{ - char filepath[300]; - strcpy(filepath, ConfigPath.c_str()); - - char * ptr = strrchr(filepath, '/'); - if(ptr) - ptr[0] = 0; - - if(!CreateSubfolder(filepath)) - return false; - - FILE * f = fopen(ConfigPath.c_str(), "w"); - if (!f) return false; - - fprintf(f, "# USB Loader settings file\n"); - fprintf(f, "# note: this file is automatically generated\n"); - fprintf(f, "# Num Games: %d\n", GameList.size()); - for (u32 i = 0; i < GameList.size(); i++) - { - fprintf(f, "game:%s = ", GameList[i].id); - fprintf(f, "FavoriteRank:%d; ", GameList[i].FavoriteRank); - fprintf(f, "PlayCount:%d;\n", GameList[i].PlayCount); - } - fprintf(f, "# END\n"); - fclose(f); - - return true; -} - -bool CGameStatistics::SetSetting(GameStatus & game, char *name, char *value) -{ - int i = 0; - - if(strcmp(name, "FavoriteRank") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.FavoriteRank = i; - } - return true; - } - else if(strcmp(name, "PlayCount") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - game.PlayCount = i; - } - return true; - } - - return false; -} - -bool CGameStatistics::ReadGameID(const char * src, char * GameID, int size) -{ - if(strncasecmp(src, "game:", 5) != 0) - return false; - - char * ptr = strchr(src, ':'); - if(!ptr) - return false; - - ptr++; - - int i = 0; - - for(i = 0; i < size; i++, ptr++) - { - if(*ptr == ' ' || *ptr == '\0') - break; - - GameID[i] = *ptr; - } - - GameID[i] = 0; - - return true; -} -#include "gecko.h" -void CGameStatistics::ParseLine(char *line) -{ - char name[1024], value[1024]; - char GameID[8]; - - if(!ReadGameID(line, GameID, 6)) - return; - - if(strlen(GameID) != 6) - return; - - GameStatus NewGame; - memset(&NewGame, 0, sizeof(GameStatus)); - - snprintf(NewGame.id, sizeof(NewGame.id), GameID); - - char * LinePtr = strchr(line, '='); - - while(LinePtr != NULL) - { - LinePtr++; - - char * eq = strchr(LinePtr, ':'); - - if (!eq) break; - - this->TrimLine(name, LinePtr, sizeof(name)); - this->TrimLine(value, eq + 1, sizeof(value)); - - //gprintf("ID: %s, Name = %s, Value = %s\n", GameID, name, value); - SetSetting(NewGame, name, value); - - LinePtr = strchr(LinePtr, ';'); - } - - AddGame(NewGame); -} - -void CGameStatistics::TrimLine(char *dest, const char *src, int size) -{ - while (*src == ' ') - src++; - - int i = 0; - - for(i = 0; i < size; i++, src++) - { - if(*src == ';' || *src == ':' || *src == '\n' || - *src == '\r' || *src == '\0') - break; - - dest[i] = *src; - } - - dest[i] = '\0'; -} - -void CGameStatistics::SetPlayCount(const char * id, int count) -{ - if(!id) - return; - - GameStatus NewStatus; - snprintf(NewStatus.id, sizeof(NewStatus.id), id); - NewStatus.FavoriteRank = 0; - NewStatus.PlayCount = count; - - GameStatus * game = GetGameStatus(id); - if(game) - { - NewStatus.FavoriteRank = game->FavoriteRank; - } - - AddGame(NewStatus); -} - -void CGameStatistics::SetFavoriteRank(const char * id, int rank) -{ - if(!id) - return; - - GameStatus NewStatus; - snprintf(NewStatus.id, sizeof(NewStatus.id), id); - NewStatus.FavoriteRank = rank; - NewStatus.PlayCount = 0; - - GameStatus * game = GetGameStatus(id); - if(game) - { - NewStatus.PlayCount = game->PlayCount; - } - - AddGame(NewStatus); -} - -int CGameStatistics::GetPlayCount(const char * id) -{ - if(!id) - return 0; - - GameStatus * game = GetGameStatus(id); - if(game) - return game->PlayCount; - - return 0; -} - -int CGameStatistics::GetFavoriteRank(const char * id) -{ - if(!id) - return 0; - - GameStatus * game = GetGameStatus(id); - if(game) - return game->FavoriteRank; - - return 0; -} diff --git a/source/settings/CGameStatistics.h b/source/settings/CGameStatistics.h deleted file mode 100644 index 86bd5165..00000000 --- a/source/settings/CGameStatistics.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef _GAME_STATISTICS_H_ -#define _GAME_STATISTICS_H_ - -#include -#include -#include -#include -#include "usbloader/disc.h" - -typedef struct _Stats -{ - char id[7]; - u8 FavoriteRank; - u8 PlayCount; -} GameStatus; - -class CGameStatistics -{ - public: - //!Constructor - CGameStatistics(); - //!Destructor - ~CGameStatistics(); - //!Load - bool Load(const char * path); - //!Save - bool Save(); - //!AddGame - bool AddGame(const GameStatus & NewGame); - //!Reset - bool RemoveAll(); - //!Overload for removing one game out of the list - bool Remove(const char * id); - bool Remove(const u8 * id) { return Remove((const char *) id); }; - bool Remove(const struct discHdr * game) { if(!game) return false; else return Remove(game->id); }; - //!Overloads for set playcount - void SetPlayCount(const char * id, int count); - void SetPlayCount(const u8 * id, int count) { SetPlayCount((const char *) id, count); }; - void SetPlayCount(const struct discHdr * game, int count) { if(!game) return; SetPlayCount(game->id, count); }; - //!Overloads for get playcount - int GetPlayCount(const char * id); - int GetPlayCount(const u8 * id) { return GetPlayCount((const char *) id); }; - int GetPlayCount(const struct discHdr * game) { if(!game) return 0; else return GetPlayCount(game->id); }; - //!Overloads for set FavoriteRank - void SetFavoriteRank(const char * id, int rank); - void SetFavoriteRank(const u8 * id, int rank) { SetFavoriteRank((const char *) id, rank); }; - void SetFavoriteRank(const struct discHdr * game, int rank) { if(!game) return; SetFavoriteRank(game->id, rank); }; - //!Overloads for get FavoriteRank - int GetFavoriteRank(const char * id); - int GetFavoriteRank(const u8 * id) { return GetFavoriteRank((const char *) id); }; - int GetFavoriteRank(const struct discHdr * game) { if(!game) return 0; else return GetFavoriteRank(game->id); }; - //!Get GameStatus - GameStatus * GetGameStatus(const char * id); - //!Overload - GameStatus * GetGameStatus(const u8 * id) { return GetGameStatus((const char *) id); }; - //!Overload - GameStatus * GetGameStatus(const struct discHdr * game) { if(!game) return NULL; else return GetGameStatus(game->id); }; - - protected: - bool ReadGameID(const char * src, char * GameID, int size); - bool SetSetting(GameStatus & game, char *name, char *value); - - void ParseLine(char *line); - void TrimLine(char *dest, const char *src, int size); - std::string ConfigPath; - std::vector GameList; -}; - -extern CGameStatistics GameStatistics; - -#endif diff --git a/source/settings/CSettings.cpp b/source/settings/CSettings.cpp deleted file mode 100644 index 0870de5b..00000000 --- a/source/settings/CSettings.cpp +++ /dev/null @@ -1,777 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include - -#include "CSettings.h" -#include "CGameSettings.h" -#include "CGameStatistics.h" -#include "language/gettext.h" -#include "themes/CTheme.h" -#include "FileOperations/fileops.h" -#include "utils/encrypt.h" - -CSettings Settings; - -CSettings::CSettings() -{ - CONF_Init(); - strcpy(BootDevice, "SD:"); - snprintf(ConfigPath, sizeof(ConfigPath), "%s/config/", BootDevice); - this->SetDefault(); -} - -CSettings::~CSettings() -{ -} - -void CSettings::SetDefault() -{ - snprintf(covers_path, sizeof(covers_path), "%simages/", ConfigPath); - snprintf(covers2d_path, sizeof(covers2d_path), "%simages/2D/", ConfigPath); - snprintf(disc_path, sizeof(disc_path), "%simages/disc/", ConfigPath); - snprintf(titlestxt_path, sizeof(titlestxt_path), "%s", ConfigPath); - snprintf(languagefiles_path, sizeof(languagefiles_path), "%slanguage/", ConfigPath); - snprintf(update_path, sizeof(update_path), "%s/apps/usbloader_gx/", BootDevice); - snprintf(theme_downloadpath, sizeof(theme_downloadpath), "%sthemes/", ConfigPath); - snprintf(homebrewapps_path, sizeof(homebrewapps_path), "%s/apps/", BootDevice); - snprintf(Cheatcodespath, sizeof(Cheatcodespath), "%scodes/", ConfigPath); - snprintf(TxtCheatcodespath, sizeof(TxtCheatcodespath), "%stxtcodes/", ConfigPath); - snprintf(BcaCodepath, sizeof(BcaCodepath), "%sbca/", ConfigPath); - snprintf(WipCodepath, sizeof(WipCodepath), "%swip/", ConfigPath); - snprintf(theme_path, sizeof(theme_path), "%stheme/", ConfigPath); - snprintf(dolpath, sizeof(dolpath), "%s/", BootDevice); - strcpy(language_path, ""); - strcpy(ogg_path, ""); - strcpy(unlockCode, ""); - strcpy(db_url, ""); - strcpy(db_language, ""); - strcpy(returnTo, ""); - - godmode = 1; - videomode = VIDEO_MODE_DISCDEFAULT; - videopatch = OFF; - language = CONSOLE_DEFAULT; - ocarina = OFF; - hddinfo = CLOCK_HR12; - sinfo = ON; - rumble = ON; - GameSort = SORT_ABC; - volume = 80; - sfxvolume = 80; - gamesoundvolume = 80; - tooltips = ON; - gamesound = 1; - parentalcontrol = 4; - lockedgames = 0; - cios = 249; - xflip = XFLIP_NO; - quickboot = OFF; - wiilight = 1; - autonetwork = 0; - discart = 0; - patchcountrystrings = 0; - gridRows = 3; - error002 = 2; - titlesOverride = 1; - db_JPtoEN = 0; - screensaver = 3; - musicloopmode = 1; - partition = -1; - marknewtitles = 1; - FatInstallToDir = 0; - InstallPartitions = ONLY_GAME_PARTITION; - beta_upgrades = 0; - widescreen = (CONF_GetAspectRatio() == CONF_ASPECT_16_9); - - Theme::SetDefault(); //! We need to move this later -} - -bool CSettings::Load() -{ - FindConfig(); - //! Reset default path variables to the right device - SetDefault(); - - char line[1024]; - char filepath[300]; - snprintf(filepath, sizeof(filepath), "%sGXGlobal.cfg", ConfigPath); - - file = fopen(filepath, "r"); - if (!file) return false; - - while (fgets(line, sizeof(line), file)) - { - if (line[0] == '#') continue; - - this->ParseLine(line); - } - fclose(file); - - return true; - -} - -bool CSettings::Reset() -{ - this->SetDefault(); - - if (this->Save()) return true; - - return false; -} - -bool CSettings::Save() -{ - if (!FindConfig()) return false; - - char filedest[300]; - snprintf(filedest, sizeof(filedest), "%sGXGlobal.cfg", ConfigPath); - - if(!CreateSubfolder(ConfigPath)) return false; - - file = fopen(filedest, "w"); - if (!file) return false; - - fprintf(file, "# USB Loader global settings file\n"); - fprintf(file, "# Note: This file is automatically generated\n "); - fprintf(file, "godmode = %d\n ", godmode); - fprintf(file, "videomode = %d\n ", videomode); - fprintf(file, "videopatch = %d\n ", videopatch); - fprintf(file, "language = %d\n ", language); - fprintf(file, "ocarina = %d\n ", ocarina); - fprintf(file, "hddinfo = %d\n ", hddinfo); - fprintf(file, "sinfo = %d\n ", sinfo); - fprintf(file, "rumble = %d\n ", rumble); - fprintf(file, "volume = %d\n ", volume); - fprintf(file, "sfxvolume = %d\n ", sfxvolume); - fprintf(file, "gamesoundvolume = %d\n ", gamesoundvolume); - fprintf(file, "tooltips = %d\n ", tooltips); - char EncryptedTxt[50]; - EncryptString(unlockCode, EncryptedTxt); - fprintf(file, "password = %s\n ", EncryptedTxt); - fprintf(file, "GameSort = %d\n ", GameSort); - fprintf(file, "cios = %d\n ", cios); - fprintf(file, "keyset = %d\n ", keyset); - fprintf(file, "xflip = %d\n ", xflip); - fprintf(file, "gridRows = %d\n ", gridRows); - fprintf(file, "quickboot = %d\n ", quickboot); - fprintf(file, "wsprompt = %d\n ", wsprompt); - fprintf(file, "parentalcontrol = %d\n ", parentalcontrol); - fprintf(file, "lockedgames = %d\n ", lockedgames); - fprintf(file, "covers_path = %s\n ", covers_path); - fprintf(file, "covers2d_path = %s\n ", covers2d_path); - fprintf(file, "theme_path = %s\n ", theme_path); - fprintf(file, "disc_path = %s\n ", disc_path); - fprintf(file, "language_path = %s\n ", language_path); - fprintf(file, "languagefiles_path = %s\n ", languagefiles_path); - fprintf(file, "TxtCheatcodespath = %s\n ", TxtCheatcodespath); - fprintf(file, "titlestxt_path = %s\n ", titlestxt_path); - fprintf(file, "gamesound = %d\n ", gamesound); - fprintf(file, "dolpath = %s\n ", dolpath); - fprintf(file, "ogg_path = %s\n ", ogg_path); - fprintf(file, "wiilight = %d\n ", wiilight); - fprintf(file, "gameDisplay = %d\n ", gameDisplay); - fprintf(file, "update_path = %s\n ", update_path); - fprintf(file, "theme_downloadpath = %s\n ", theme_downloadpath); - fprintf(file, "homebrewapps_path = %s\n ", homebrewapps_path); - fprintf(file, "Cheatcodespath = %s\n ", Cheatcodespath); - fprintf(file, "BcaCodepath = %s\n ", BcaCodepath); - fprintf(file, "WipCodepath = %s\n ", WipCodepath); - fprintf(file, "titlesOverride = %d\n ", titlesOverride); - fprintf(file, "patchcountrystrings = %d\n ", patchcountrystrings); - fprintf(file, "screensaver = %d\n ", screensaver); - fprintf(file, "musicloopmode = %d\n ", musicloopmode); - fprintf(file, "error002 = %d\n ", error002); - fprintf(file, "autonetwork = %d\n ", autonetwork); - fprintf(file, "discart = %d\n ", discart); - fprintf(file, "partition = %d\n ", partition); - fprintf(file, "marknewtitles = %d\n ", marknewtitles); - fprintf(file, "FatInstallToDir = %d\n ", FatInstallToDir); - fprintf(file, "InstallPartitions = %08X\n ", InstallPartitions); - fprintf(file, "beta_upgrades = %d\n ", beta_upgrades); - fprintf(file, "returnTo = %s\n ", returnTo); - fclose(file); - - return true; -} - -bool CSettings::SetSetting(char *name, char *value) -{ - int i = 0; - - if (strcmp(name, "godmode") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - godmode = i; - } - return true; - } - else if (strcmp(name, "videomode") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - videomode = i; - } - return true; - } - else if (strcmp(name, "videopatch") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - videopatch = i; - } - return true; - } - else if (strcmp(name, "language") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - language = i; - } - return true; - } - else if (strcmp(name, "ocarina") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - ocarina = i; - } - return true; - } - else if (strcmp(name, "hddinfo") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - hddinfo = i; - } - return true; - } - else if (strcmp(name, "sinfo") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - sinfo = i; - } - return true; - } - else if (strcmp(name, "rumble") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - rumble = i; - } - return true; - } - else if (strcmp(name, "volume") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - volume = i; - } - return true; - } - else if (strcmp(name, "sfxvolume") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - sfxvolume = i; - } - return true; - } - else if (strcmp(name, "gamesoundvolume") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - gamesoundvolume = i; - } - return true; - } - else if (strcmp(name, "tooltips") == 0) - { - if (sscanf(value, "%d", &i) == 1) - { - tooltips = i; - } - return true; - } - else if (strcmp(name, "password") == 0) - { - char EncryptedTxt[50]; - strcpy(EncryptedTxt, value); - DecryptString(EncryptedTxt, unlockCode); - return true; - } - else if (strcmp(name, "GameSort") == 0) - { - if (sscanf(value, "%d", &i) == 1) GameSort = i; - return true; - } - else if (strcmp(name, "cios") == 0) - { - if (sscanf(value, "%d", &i) == 1) cios = i; - return true; - } - else if (strcmp(name, "keyset") == 0) - { - if (sscanf(value, "%d", &i) == 1) keyset = i; - return true; - } - else if (strcmp(name, "xflip") == 0) - { - if (sscanf(value, "%d", &i) == 1) xflip = i; - return true; - } - else if (strcmp(name, "gridRows") == 0) - { - if (sscanf(value, "%d", &i) == 1) gridRows = i; - return true; - } - else if (strcmp(name, "quickboot") == 0) - { - if (sscanf(value, "%d", &i) == 1) quickboot = i; - return true; - } - else if (strcmp(name, "partition") == 0) - { - if (sscanf(value, "%d", &i) == 1) partition = i; - return true; - } - else if (strcmp(name, "wsprompt") == 0) - { - if (sscanf(value, "%d", &i) == 1) wsprompt = i; - return true; - } - else if (strcmp(name, "gameDisplay") == 0) - { - if (sscanf(value, "%d", &i) == 1) gameDisplay = i; - return true; - } - else if (strcmp(name, "parentalcontrol") == 0) - { - if (sscanf(value, "%d", &i) == 1) parentalcontrol = i; - return true; - } - else if (strcmp(name, "lockedgames") == 0) - { - if (sscanf(value, "%d", &i) == 1) lockedgames = i; - return true; - } - else if (strcmp(name, "screensaver") == 0) - { - if (sscanf(value, "%d", &i) == 1) screensaver = i; - return true; - } - else if (strcmp(name, "titlesOverride") == 0) - { - if (sscanf(value, "%d", &i) == 1) titlesOverride = i; - return true; - } - else if (strcmp(name, "musicloopmode") == 0) - { - if (sscanf(value, "%d", &i) == 1) musicloopmode = i; - return true; - } - else if (strcmp(name, "gamesound") == 0) - { - if (sscanf(value, "%d", &i) == 1) gamesound = i; - return true; - } - else if (strcmp(name, "wiilight") == 0) - { - if (sscanf(value, "%d", &i) == 1) wiilight = i; - return true; - } - else if (strcmp(name, "marknewtitles") == 0) - { - if (sscanf(value, "%d", &i) == 1) marknewtitles = i; - return true; - } - else if (strcmp(name, "patchcountrystrings") == 0) - { - if (sscanf(value, "%d", &i) == 1) patchcountrystrings = i; - return true; - } - else if (strcmp(name, "discart") == 0) - { - if (sscanf(value, "%d", &i) == 1) discart = i; - return true; - } - else if (strcmp(name, "error002") == 0) - { - if (sscanf(value, "%d", &i) == 1) error002 = i; - return true; - } - else if (strcmp(name, "autonetwork") == 0) - { - if (sscanf(value, "%d", &i) == 1) autonetwork = i; - return true; - } - else if (strcmp(name, "FatInstallToDir") == 0) - { - if (sscanf(value, "%d", &i) == 1) FatInstallToDir = i; - return true; - } - else if (strcmp(name, "beta_upgrades") == 0) - { - if (sscanf(value, "%d", &i) == 1) beta_upgrades = i; - return true; - } - else if (strcmp(name, "InstallPartitions") == 0) - { - InstallPartitions = strtoul(value, 0, 16); - return true; - } - else if (strcmp(name, "covers_path") == 0) - { - strcpy(covers_path, value); - return true; - } - else if (strcmp(name, "covers2d_path") == 0) - { - strcpy(covers2d_path, value); - return true; - } - else if (strcmp(name, "theme_path") == 0) - { - strcpy(theme_path, value); - return true; - } - else if (strcmp(name, "disc_path") == 0) - { - strcpy(disc_path, value); - return true; - } - else if (strcmp(name, "language_path") == 0) - { - strcpy(language_path, value); - return true; - } - else if (strcmp(name, "languagefiles_path") == 0) - { - strcpy(languagefiles_path, value); - return true; - } - else if (strcmp(name, "TxtCheatcodespath") == 0) - { - strcpy(TxtCheatcodespath, value); - return true; - } - else if (strcmp(name, "titlestxt_path") == 0) - { - strcpy(titlestxt_path, value); - return true; - } - else if (strcmp(name, "dolpath") == 0) - { - strcpy(dolpath, value); - return true; - } - else if (strcmp(name, "ogg_path") == 0) - { - strcpy(ogg_path, value); - return true; - } - else if (strcmp(name, "update_path") == 0) - { - strcpy(update_path, value); - return true; - } - else if (strcmp(name, "theme_downloadpath") == 0) - { - strcpy(theme_downloadpath, value); - return true; - } - else if (strcmp(name, "homebrewapps_path") == 0) - { - strcpy(homebrewapps_path, value); - return true; - } - else if (strcmp(name, "Cheatcodespath") == 0) - { - strcpy(Cheatcodespath, value); - return true; - } - else if (strcmp(name, "BcaCodepath") == 0) - { - strcpy(BcaCodepath, value); - return true; - } - else if (strcmp(name, "WipCodepath") == 0) - { - strcpy(WipCodepath, value); - return true; - } - else if (strcmp(name, "returnTo") == 0) - { - strcpy(returnTo, value); - return true; - } - - return false; -} - -bool CSettings::FindConfig() -{ - bool found = false; - char CheckPath[300]; - strcpy(BootDevice, "SD:"); - - for (int i = 0; i < 2; ++i) - { - if (i == 1) strcpy(BootDevice, "USB:"); - - snprintf(ConfigPath, sizeof(ConfigPath), "%s/apps/usbloader_gx/", BootDevice); - snprintf(CheckPath, sizeof(CheckPath), "%sGXGlobal.cfg", ConfigPath); - if ((found = CheckFile(CheckPath))) break; - - snprintf(ConfigPath, sizeof(ConfigPath), "%s/config/", BootDevice); - snprintf(CheckPath, sizeof(CheckPath), "%sGXGlobal.cfg", ConfigPath); - if ((found = CheckFile(CheckPath))) break; - } - - if (!found) - { - FILE * testFp = NULL; - strcpy(BootDevice, "SD:"); - //! No existing config so try to find a place where we can write it too - for (int i = 0; i < 2; ++i) - { - if (i == 1) strcpy(BootDevice, "USB:"); - if (!found) - { - snprintf(ConfigPath, sizeof(ConfigPath), "%s/apps/usbloader_gx/", BootDevice); - snprintf(CheckPath, sizeof(CheckPath), "%sGXGlobal.cfg", ConfigPath); - testFp = fopen(CheckPath, "wb"); - found = (testFp != NULL); - fclose(testFp); - } - if (!found) - { - snprintf(ConfigPath, sizeof(ConfigPath), "%s/config/", BootDevice); - CreateSubfolder(ConfigPath); - snprintf(CheckPath, sizeof(CheckPath), "%sGXGlobal.cfg", ConfigPath); - testFp = fopen(CheckPath, "wb"); - found = (testFp != NULL); - fclose(testFp); - } - } - } - - return found; -} - -void CSettings::ParseLine(char *line) -{ - char temp[1024], name[1024], value[1024]; - - strncpy(temp, line, sizeof(temp)); - - char * eq = strchr(temp, '='); - - if (!eq) return; - - *eq = 0; - - this->TrimLine(name, temp, sizeof(name)); - this->TrimLine(value, eq + 1, sizeof(value)); - - this->SetSetting(name, value); -} - -void CSettings::TrimLine(char *dest, char *src, int size) -{ - int len; - while (*src == ' ') - src++; - len = strlen(src); - while (len > 0 && strchr(" \r\n", src[len - 1])) - len--; - if (len >= size) len = size - 1; - strncpy(dest, src, len); - dest[len] = 0; -} - -//! Get the language code from CONF -static inline const char * GetLangCode(int langid) -{ - switch (langid) - { - case CONF_LANG_JAPANESE: - return "JA"; - case CONF_LANG_ENGLISH: - return "EN"; - case CONF_LANG_GERMAN: - return "DE"; - case CONF_LANG_FRENCH: - return "FR"; - case CONF_LANG_SPANISH: - return "ES"; - case CONF_LANG_ITALIAN: - return "IT"; - case CONF_LANG_DUTCH: - return "NL"; - case CONF_LANG_SIMP_CHINESE: - return "ZHCN"; - case CONF_LANG_TRAD_CHINESE: - return "ZHTW"; - case CONF_LANG_KOREAN: - return "KO"; - default: - return "EN"; - } -} - -//! Get language code from the selected language file -//! eg. german.lang = DE and default to EN -static inline const char * GetLangCode(const char * langpath) -{ - if(strcasestr(langpath, "japanese")) - return "JA"; - - else if(strcasestr(langpath, "german")) - return "DE"; - - else if(strcasestr(langpath, "french")) - return "FR"; - - else if(strcasestr(langpath, "spanish")) - return "ES"; - - else if(strcasestr(langpath, "italian")) - return "IT"; - - else if(strcasestr(langpath, "dutch")) - return "NL"; - - else if(strcasestr(langpath, "schinese")) - return "ZHCN"; - - else if(strcasestr(langpath, "tchinese")) - return "ZHTW"; - - else if(strcasestr(langpath, "korean")) - return "KO"; - - return "EN"; -} - -bool CSettings::LoadLanguage(const char *path, int language) -{ - bool ret = false; - - if (language >= 0 || !path || strlen(path) == 0) - { - if (language < 0) return false; - - char filepath[150]; - char langpath[150]; - snprintf(langpath, sizeof(langpath), "%s", language_path); - if (langpath[strlen(langpath) - 1] != '/') - { - char * ptr = strrchr(langpath, '/'); - if (ptr) - { - ptr++; - ptr[0] = '\0'; - } - } - - if (language == APP_DEFAULT) - { - strcpy(language_path, ""); - gettextCleanUp(); - return true; - } - else if (language == CONSOLE_DEFAULT) - { - return LoadLanguage(NULL, CONF_GetLanguage() + 2); - } - else if (language == JAPANESE) - { - snprintf(filepath, sizeof(filepath), "%s/japanese.lang", langpath); - } - else if (language == ENGLISH) - { - snprintf(filepath, sizeof(filepath), "%s/english.lang", langpath); - } - else if (language == GERMAN) - { - snprintf(filepath, sizeof(filepath), "%s/german.lang", langpath); - } - else if (language == FRENCH) - { - snprintf(filepath, sizeof(filepath), "%s/french.lang", langpath); - } - else if (language == SPANISH) - { - snprintf(filepath, sizeof(filepath), "%s/spanish.lang", langpath); - } - else if (language == ITALIAN) - { - snprintf(filepath, sizeof(filepath), "%s/italian.lang", langpath); - } - else if (language == DUTCH) - { - snprintf(filepath, sizeof(filepath), "%s/dutch.lang", langpath); - } - else if (language == S_CHINESE) - { - snprintf(filepath, sizeof(filepath), "%s/schinese.lang", langpath); - } - else if (language == T_CHINESE) - { - snprintf(filepath, sizeof(filepath), "%s/tchinese.lang", langpath); - } - else if (language == KOREAN) - { - snprintf(filepath, sizeof(filepath), "%s%s/korean.lang", BootDevice, langpath); - } - - ret = gettextLoadLanguage(filepath); - if (ret) - { - strncpy(language_path, filepath, sizeof(language_path)); - strcpy(db_language, GetLangCode(language_path)); - } - } - else if (strlen(path) < 3) - { - return LoadLanguage(NULL, CONF_GetLanguage() + 2); - } - else - { - ret = gettextLoadLanguage(path); - if (ret) - { - strncpy(language_path, path, sizeof(language_path)); - strcpy(db_language, GetLangCode(language_path)); - } - } - - return ret; -} diff --git a/source/settings/CSettings.h b/source/settings/CSettings.h deleted file mode 100644 index 2031ebf4..00000000 --- a/source/settings/CSettings.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef _CSETTINGS_H_ -#define _CSETTINGS_H_ - -#include -#include -#include -#include "SettingsEnums.h" - -class CSettings -{ - public: - //!Constructor - CSettings(); - //!Destructor - ~CSettings(); - //!Set Default Settings - void SetDefault(); - //!Load Settings - bool Load(); - //!Save Settings - bool Save(); - //!Reset Settings - bool Reset(); - //!Load a languagefile - //!\param language - bool LoadLanguage(const char *path, int language = -1); - - /** Variables **/ - char BootDevice[10]; - char ConfigPath[80]; - short videomode; - short language; - short ocarina; - short videopatch; - short sinfo; - short hddinfo; - short rumble; - short xflip; - int volume; - int sfxvolume; - int gamesoundvolume; - short tooltips; - char unlockCode[20]; - short parentalcontrol; - short lockedgames; - short cios; - short quickboot; - short wsprompt; - short keyset; - short GameSort; - short wiilight; - short gameDisplay; - short patchcountrystrings; - short screensaver; - short partition; - short musicloopmode; - short widescreen; - short godmode; - char covers_path[100]; - char covers2d_path[100]; - char theme_path[100]; - char theme_downloadpath[100]; - char disc_path[100]; - char titlestxt_path[100]; - char language_path[100]; - char languagefiles_path[100]; - char ogg_path[250]; - char dolpath[150]; - char update_path[150]; - char homebrewapps_path[150]; - char Cheatcodespath[100]; - char TxtCheatcodespath[100]; - char BcaCodepath[100]; - char WipCodepath[100]; - short error002; - short titlesOverride; // db_titles - char db_url[200]; - char db_language[20]; - short db_JPtoEN; - short gridRows; - short autonetwork; - short discart; - short gamesound; - short marknewtitles; - short FatInstallToDir; - u32 InstallPartitions; - short beta_upgrades; - char returnTo[20]; - protected: - bool SetSetting(char *name, char *value); - //!Find the config file in the default paths - bool FindConfig(); - - void ParseLine(char *line); - void TrimLine(char *dest, char *src, int size); - FILE * file; -}; - -extern CSettings Settings; - -#endif diff --git a/source/settings/GameTitles.cpp b/source/settings/GameTitles.cpp deleted file mode 100644 index 1396ab5b..00000000 --- a/source/settings/GameTitles.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include "GameTitles.h" -#include "CSettings.h" -#include "usbloader/GameList.h" -#include "xml/xml.h" -#include "xml/WiiTDB.hpp" - -CGameTitles GameTitles; - -void CGameTitles::SetGameTitle(const char * id, const char * title) -{ - if(!id || !title) - return; - - for(u32 i = 0; i < TitleList.size(); ++i) - { - if(strncasecmp(id, TitleList[i].GameID, 6) == 0) - { - TitleList[i].Title = title; - return; - } - } - - GameTitle newTitle; - newTitle.Title = title; - - //! Just in case a 0 termination is missing - int n; - for(n = 0; n < 6; ++n) - newTitle.GameID[n] = id[n]; - - newTitle.GameID[n] = '\0'; - - TitleList.push_back(newTitle); -} - -const char * CGameTitles::GetTitle(const char * id) -{ - if(!id) - return NULL; - - for(u32 i = 0; i < TitleList.size(); ++i) - { - if(strncasecmp(id, TitleList[i].GameID, 6) == 0) - return TitleList[i].Title.c_str(); - } - - return NULL; -} - -const char * CGameTitles::GetTitle(const struct discHdr *header) -{ - if(!header) - return NULL; - - for(u32 i = 0; i < TitleList.size(); ++i) - { - if(strncasecmp((const char *) header->id, TitleList[i].GameID, 6) == 0) - return TitleList[i].Title.c_str(); - } - - return header->title; -} - -int CGameTitles::GetParentalRating(const char * id) -{ - if(!id) - return -1; - - for(u32 i = 0; i < TitleList.size(); ++i) - { - if(strncasecmp(id, TitleList[i].GameID, 6) == 0) - return TitleList[i].ParentalRating; - } - - return -1; -} - -void CGameTitles::SetDefault() -{ - TitleList.clear(); - //! Free vector memory - std::vector().swap(TitleList); -} - -void CGameTitles::LoadTitlesFromWiiTDB(const char * path) -{ - this->SetDefault(); - - if(!path || !Settings.titlesOverride) - return; - - gameList.LoadUnfiltered(); - - std::string Title; - std::string Filepath = path; - if(path[strlen(path)-1] != '/') - Filepath += '/'; - Filepath += "wiitdb.xml"; - - WiiTDB XML_DB(Filepath.c_str()); - XML_DB.SetLanguageCode(Settings.db_language); - int Rating; - std::string RatValTxt; - - for(int i = 0; i < gameList.GameCount(); ++i) - { - if(!XML_DB.GetTitle((const char *) gameList[i]->id, Title)) - continue; - - this->SetGameTitle(gameList[i]->id, Title.c_str()); - - TitleList[TitleList.size()-1].ParentalRating = -1; - - Rating = XML_DB.GetRating((const char *) gameList[i]->id); - if(Rating < 0) - continue; - - if(!XML_DB.GetRatingValue((const char *) gameList[i]->id, RatValTxt)) - continue; - - TitleList[TitleList.size()-1].ParentalRating = ConvertRating(RatValTxt.c_str(), WiiTDB::RatingToString(Rating), "PEGI"); - } -} diff --git a/source/settings/GameTitles.h b/source/settings/GameTitles.h deleted file mode 100644 index ef8f9def..00000000 --- a/source/settings/GameTitles.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef WIITDB_TITLES_H_ -#define WIITDB_TITLES_H_ - -#include -#include -#include -#include "usbloader/disc.h" - -typedef struct _GameTitle -{ - char GameID[7]; - std::string Title; - int ParentalRating; - -} GameTitle; - -class CGameTitles -{ - public: - //! Set a game title from wiitdb - void SetGameTitle(const char * id, const char * title); - //! Overload - void SetGameTitle(const u8 * id, const char * title) { SetGameTitle((const char *) id, title); }; - - //! Get a game title - const char * GetTitle(const char * id); - //! Overload - const char * GetTitle(const u8 * id) { return GetTitle((const char *) id); }; - //! Overload - const char * GetTitle(const struct discHdr *header); - - //! Get game parental rating - int GetParentalRating(const char * id); - - //! Load Game Titles from WiiTDB - void LoadTitlesFromWiiTDB(const char * path); - //! Set default game titles - void SetDefault(); - protected: - std::vector TitleList; -}; - -extern CGameTitles GameTitles; - -#endif diff --git a/source/settings/Settings.cpp b/source/settings/Settings.cpp deleted file mode 100644 index c7ac0a43..00000000 --- a/source/settings/Settings.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include "settings/menus/GlobalSettings.hpp" -#include "settings/menus/GameSettingsMenu.hpp" - -/**************************************************************************** - * MenuSettings - ***************************************************************************/ -int MenuSettings() -{ - GlobalSettings * Menu = new GlobalSettings(); - mainWindow->Append(Menu); - - Menu->ShowMenu(); - - int returnMenu = MENU_NONE; - - while((returnMenu = Menu->MainLoop()) == MENU_NONE); - - delete Menu; - - return returnMenu; -} - -/******************************************************************************** - *Game specific settings - *********************************************************************************/ -int MenuGameSettings(struct discHdr * header) -{ - GameSettingsMenu * Menu = new GameSettingsMenu(header); - mainWindow->Append(Menu); - - Menu->ShowMenu(); - - int returnMenu = MENU_NONE; - - while((returnMenu = Menu->MainLoop()) == MENU_NONE); - - delete Menu; - - return returnMenu; -} diff --git a/source/settings/Settings.h b/source/settings/Settings.h deleted file mode 100644 index 9eb367ec..00000000 --- a/source/settings/Settings.h +++ /dev/null @@ -1,14 +0,0 @@ -/**************************************************************************** - * Settings - * USB Loader GX 2009 - * - * settings.h - ***************************************************************************/ - -#ifndef _SETTINGS_H_ -#define _SETTINGS_H_ - -int MenuSettings(); -int MenuGameSettings(struct discHdr * header); - -#endif diff --git a/source/settings/SettingsEnums.h b/source/settings/SettingsEnums.h deleted file mode 100644 index 0691f17a..00000000 --- a/source/settings/SettingsEnums.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef SETTINGS_ENUMS_H_ -#define SETTINGS_ENUMS_H_ - -#include "libs/libwbfs/wiidisc.h" - -enum -{ - APP_DEFAULT = 0, - CONSOLE_DEFAULT, - JAPANESE, - ENGLISH, - GERMAN, - FRENCH, - SPANISH, - ITALIAN, - DUTCH, - S_CHINESE, - T_CHINESE, - KOREAN, - MAX_LANGUAGE -}; - -enum -{ - VIDEO_MODE_SYSDEFAULT = 0, - VIDEO_MODE_DISCDEFAULT, - VIDEO_MODE_PATCH, - VIDEO_MODE_PAL50, - VIDEO_MODE_PAL60, - VIDEO_MODE_NTSC, - VIDEO_MODE_MAX -}; - -enum -{ - OFF = 0, - ON, - MAX_ON_OFF -}; - -enum -{ - CLOCK_HR12 = 1, // use OFF for clock off - CLOCK_HR24, - CLOCK_MAX -}; - - -enum -{ - WIILIGHT_OFF = 0, - WIILIGHT_ON, - WIILIGHT_INSTALL, - WIILIGHT_MAX - -}; - -enum -{ - GAMEINFO_ID, - GAMEINFO_REGION, - GAMEINFO_BOTH, - GAMEINFO_NONE, - GAMEINFO_MAX -}; - -enum -{ - SCREENSAVER_3_MIN = 1, - SCREENSAVER_5_MIN, - SCREENSAVER_10_MIN, - SCREENSAVER_20_MIN, - SCREENSAVER_30_MIN, - SCREENSAVER_60_MIN, - SCREENSAVER_MAX -}; - -enum -{ - XFLIP_NO = 0, - XFLIP_YES, - XFLIP_SYSMENU, - XFLIP_WTF, - XFLIP_DISK3D, - XFLIP_MAX -}; - -enum -{ - //! Sorting should be used as AND to allow favorite ABC/RANK - SORT_ABC = 0x01, - SORT_PLAYCOUNT = 0x02, - SORT_RANKING = 0x04, - SORT_FAVORITE = 0x08, -}; -enum -{ - KEYBOARD_QWERTY = 0, - KEYBOARD_DVORAK, - KEYBOARD_QWERTZ, - KEYBOARD_AZERTY, - KEYBOARD_QWERTY2, - KEYBOARD_MAX -}; - -enum -{ - INSTALL_TO_NO_DIR, - INSTALL_TO_GAMEID_NAME, - INSTALL_TO_NAME_GAMEID, - INSTALL_TO_MAX -}; - -enum -{ - LIST_MODE, - GRID_MODE, - CAROUSEL_MODE -}; - -#endif diff --git a/source/settings/SettingsPrompts.cpp b/source/settings/SettingsPrompts.cpp deleted file mode 100644 index 51f3cec8..00000000 --- a/source/settings/SettingsPrompts.cpp +++ /dev/null @@ -1,545 +0,0 @@ -#include -#include -#include - -#include "language/gettext.h" -#include "language/UpdateLanguage.h" -#include "prompts/PromptWindows.h" -#include "prompts/ProgressWindow.h" -#include "libwiigui/gui.h" -#include "libwiigui/gui_customoptionbrowser.h" -#include "settings/CSettings.h" -#include "themes/CTheme.h" -#include "network/URL_List.h" -#include "FileOperations/fileops.h" -#include "FileOperations/DirList.h" -#include "main.h" -#include "fatmounter.h" -#include "filelist.h" -#include "prompts/filebrowser.h" -#include "sys.h" -#include "menu/menus.h" - -/*** Extern variables ***/ -extern u8 shutdown; -extern u8 reset; - - -/**************************************************************************** - * MenuOGG - ***************************************************************************/ -bool MenuBackgroundMusic() -{ - bool ret = false; - char entered[1024]; - int result = -1; - snprintf( entered, sizeof( entered ), "%s", Settings.ogg_path ); - - if ( strcmp( entered, "" ) == 0 ) - { - sprintf( entered, "%s", Settings.BootDevice ); - } - else - { - char * pathptr = strrchr( entered, '/' ); - if ( pathptr ) - { - pathptr++; - int choice = WindowPrompt( tr( "Playing Music:" ), pathptr, tr( "Play Previous" ), tr( "Play Next" ), tr( "Change Play Path" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - return bgMusic->PlayPrevious(); - } - else if ( choice == 2 ) - { - return bgMusic->PlayNext(); - } - else if ( choice == 3 ) - { - pathptr[0] = 0; - } - else - return true; - } - else - sprintf( entered, "%s", Settings.BootDevice ); - } - - result = BrowseDevice( entered, sizeof( entered ), FB_DEFAULT ); - - if ( result ) - { - if ( !bgMusic->Load( entered ) ) - { - WindowPrompt( tr( "Not supported format!" ), tr( "Loading standard music." ), tr( "OK" ) ); - } - else - ret = true; - bgMusic->Play(); - bgMusic->SetVolume( Settings.volume ); - } - - return ret; -} - -/**************************************************************************** - * MenuLanguageSelect - ***************************************************************************/ -int MenuLanguageSelect() -{ - int cnt = 0; - int ret = 0, choice = 0; - int returnhere = 0; - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger( -1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A ); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger( -1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B ); - - char fullpath[100]; - DirList Dir(Settings.languagefiles_path, ".lang"); - - if ( !strcmp( "", Settings.language_path ) ) - { - sprintf( fullpath, "%s", tr( "Default" ) ); - } - else - { - sprintf( fullpath, "%s", Settings.languagefiles_path ); - } - - GuiText titleTxt( fullpath, 24, ( GXColor ) {0, 0, 0, 255} ); - titleTxt.SetAlignment( ALIGN_CENTRE, ALIGN_MIDDLE ); - titleTxt.SetPosition( 0, 0 ); - GuiButton pathBtn( 300, 50 ); - pathBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - pathBtn.SetPosition( 0, 28 ); - pathBtn.SetLabel( &titleTxt ); - pathBtn.SetSoundOver( btnSoundOver ); - pathBtn.SetSoundClick( btnSoundClick2 ); - pathBtn.SetTrigger( &trigA ); - pathBtn.SetEffectGrow(); - - GuiImage oggmenubackground( &settingsbg ); - oggmenubackground.SetAlignment( ALIGN_LEFT, ALIGN_TOP ); - oggmenubackground.SetPosition( 0, 0 ); - - GuiText backBtnTxt( tr( "Back" ) , 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnTxt.SetMaxWidth( btnOutline.GetWidth() - 30 ); - GuiImage backBtnImg( &btnOutline ); - if ( Settings.wsprompt == ON ) - { - backBtnTxt.SetWidescreen( Settings.widescreen ); - backBtnImg.SetWidescreen( Settings.widescreen ); - } - GuiButton backBtn( btnOutline.GetWidth(), btnOutline.GetHeight() ); - backBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - backBtn.SetPosition( -190, 400 ); - backBtn.SetLabel( &backBtnTxt ); - backBtn.SetImage( &backBtnImg ); - backBtn.SetSoundOver( btnSoundOver ); - backBtn.SetSoundClick( btnSoundClick2 ); - backBtn.SetTrigger( &trigA ); - backBtn.SetTrigger( &trigB ); - backBtn.SetEffectGrow(); - - GuiText defaultBtnTxt( tr( "Default" ) , 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - defaultBtnTxt.SetMaxWidth( btnOutline.GetWidth() - 30 ); - GuiImage defaultBtnImg( &btnOutline ); - if ( Settings.wsprompt == ON ) - { - defaultBtnTxt.SetWidescreen( Settings.widescreen ); - defaultBtnImg.SetWidescreen( Settings.widescreen ); - } - GuiButton defaultBtn( btnOutline.GetWidth(), btnOutline.GetHeight() ); - defaultBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - defaultBtn.SetPosition( 190, 400 ); - defaultBtn.SetLabel( &defaultBtnTxt ); - defaultBtn.SetImage( &defaultBtnImg ); - defaultBtn.SetSoundOver( btnSoundOver ); - defaultBtn.SetSoundClick( btnSoundClick2 ); - defaultBtn.SetTrigger( &trigA ); - defaultBtn.SetEffectGrow(); - - GuiText updateBtnTxt( tr( "Update Files" ) , 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - updateBtnTxt.SetMaxWidth( btnOutline.GetWidth() - 30 ); - GuiImage updateBtnImg( &btnOutline ); - if ( Settings.wsprompt == ON ) - { - updateBtnTxt.SetWidescreen( Settings.widescreen ); - updateBtnImg.SetWidescreen( Settings.widescreen ); - } - GuiButton updateBtn( btnOutline.GetWidth(), btnOutline.GetHeight() ); - updateBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - updateBtn.SetPosition( 0, 400 ); - updateBtn.SetLabel( &updateBtnTxt ); - updateBtn.SetImage( &updateBtnImg ); - updateBtn.SetSoundOver( btnSoundOver ); - updateBtn.SetSoundClick( btnSoundClick2 ); - updateBtn.SetTrigger( &trigA ); - updateBtn.SetEffectGrow(); - - OptionList options2; - - for ( cnt = 0; cnt < Dir.GetFilecount(); cnt++ ) - { - char filename[64]; - strlcpy( filename, Dir.GetFilename( cnt ), sizeof( filename ) ); - char *dot = strchr( filename, '.' ); - if ( dot ) *dot = '\0'; - options2.SetName( cnt, "%s", filename ); - options2.SetValue( cnt, NULL ); - - } - - GuiCustomOptionBrowser optionBrowser4( 396, 280, &options2, "bg_options_settings.png"); - optionBrowser4.SetPosition( 0, 90 ); - optionBrowser4.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - - HaltGui(); - GuiWindow w( screenwidth, screenheight ); - w.Append( &oggmenubackground ); - w.Append( &pathBtn ); - w.Append( &backBtn ); - w.Append( &defaultBtn ); - w.Append( &updateBtn ); - w.Append( &optionBrowser4 ); - mainWindow->Append( &w ); - - w.SetEffect( EFFECT_FADE, 20 ); - ResumeGui(); - - while ( w.GetEffect() > 0 ) usleep( 50 ); - - while ( !returnhere ) - { - usleep(100); - - if ( shutdown == 1 ) - Sys_Shutdown(); - else if ( reset == 1 ) - Sys_Reboot(); - - else if ( backBtn.GetState() == STATE_CLICKED ) - { - backBtn.ResetState(); - break; - } - - else if ( defaultBtn.GetState() == STATE_CLICKED ) - { - choice = WindowPrompt( tr( "Loading standard language." ), 0, tr( "OK" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - Settings.LoadLanguage(NULL, APP_DEFAULT); - Settings.Save(); - returnhere = 2; - } - defaultBtn.ResetState(); - //optionBrowser4.SetFocus(1); // commented out to prevent crash - } - - else if ( updateBtn.GetState() == STATE_CLICKED ) - { - choice = WindowPrompt( tr( "Update all Language Files" ), tr( "Do you wish to update/download all language files?" ), tr( "OK" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - if (IsNetworkInit() || NetworkInitPrompt()) - { - if(DownloadAllLanguageFiles() > 0) - WindowPrompt(tr("Update successfull"), 0, tr("OK")); - returnhere = 1; - break; - } - } - updateBtn.ResetState(); - //optionBrowser4.SetFocus(1); // commented out to prevent crash - } - - else if ( pathBtn.GetState() == STATE_CLICKED ) - { - w.Remove( &optionBrowser4 ); - w.Remove( &backBtn ); - w.Remove( &pathBtn ); - w.Remove( &defaultBtn ); - char entered[43] = ""; - strlcpy( entered, Settings.languagefiles_path, sizeof( entered ) ); - int result = OnScreenKeyboard( entered, 43, 0 ); - w.Append( &optionBrowser4 ); - w.Append( &pathBtn ); - w.Append( &backBtn ); - w.Append( &defaultBtn ); - if ( result == 1 ) - { - int len = ( strlen( entered ) - 1 ); - if ( entered[len] != '/' ) - strncat ( entered, "/", 1 ); - strlcpy( Settings.languagefiles_path, entered, sizeof( Settings.languagefiles_path ) ); - WindowPrompt( tr( "Languagepath changed." ), 0, tr( "OK" ) ); - if ( isInserted( Settings.BootDevice ) ) - { - Settings.Save(); - returnhere = 1; - break; - } - else - { - WindowPrompt( tr( "No SD-Card inserted!" ), tr( "Insert an SD-Card to save." ), tr( "OK" ) ); - } - } - if ( Dir.GetFilecount() > 0 ) - { - optionBrowser4.SetFocus( 1 ); - } - pathBtn.ResetState(); - } - - ret = optionBrowser4.GetClickedOption(); - - if ( ret >= 0 ) - { - choice = WindowPrompt( tr( "Do you want to change language?" ), 0, tr( "Yes" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - char newLangPath[150]; - snprintf( Settings.languagefiles_path, sizeof( Settings.languagefiles_path ), "%s", Dir.GetFilepath(ret)); - char * ptr = strrchr(Settings.languagefiles_path, '/'); - if(ptr) ptr[1] = 0; - snprintf( newLangPath, sizeof( newLangPath ), "%s", Dir.GetFilepath(ret)); - if ( !CheckFile( newLangPath ) ) - { - WindowPrompt( tr( "File not found." ), tr( "Loading standard language." ), tr( "OK" ) ); - Settings.LoadLanguage(NULL, APP_DEFAULT); - } - else - { - Settings.LoadLanguage(newLangPath); - } - Settings.Save(); - returnhere = 2; - break; - } - optionBrowser4.SetFocus( 1 ); - } - - } - - w.SetEffect( EFFECT_FADE, -20 ); - while ( w.GetEffect() > 0 ) usleep( 50 ); - - HaltGui(); - mainWindow->Remove( &w ); - ResumeGui(); - - return returnhere; -} - - -/**************************************************************************** - * MenuThemeSelect - ***************************************************************************/ -int MenuThemeSelect() -{ - char themepath[250]; - int cnt = 0; - int ret = 0, choice = 0; - int returnVal = 0; - - snprintf(themepath, sizeof(themepath), Settings.theme_path); - - char * ptr = strrchr(themepath, '/'); - if(ptr && *ptr != '\0') ptr[1] = '\0'; - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - - GuiTrigger trigA; - trigA.SetSimpleTrigger( -1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A ); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger( -1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B ); - - GuiText titleTxt(themepath, 24, ( GXColor ) {0, 0, 0, 255} ); - titleTxt.SetAlignment( ALIGN_CENTRE, ALIGN_MIDDLE ); - titleTxt.SetPosition( 0, 0 ); - GuiButton pathBtn( 300, 50 ); - pathBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - pathBtn.SetPosition( 0, 28 ); - pathBtn.SetLabel( &titleTxt ); - pathBtn.SetSoundOver( btnSoundOver ); - pathBtn.SetSoundClick( btnSoundClick2 ); - pathBtn.SetTrigger( &trigA ); - pathBtn.SetEffectGrow(); - - GuiImage backgroundImg( &settingsbg ); - backgroundImg.SetAlignment( ALIGN_LEFT, ALIGN_TOP ); - backgroundImg.SetPosition( 0, 0 ); - - GuiText backBtnTxt( tr( "Back" ) , 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnTxt.SetMaxWidth( btnOutline.GetWidth() - 30 ); - GuiImage backBtnImg( &btnOutline ); - if ( Settings.wsprompt == ON ) - { - backBtnTxt.SetWidescreen( Settings.widescreen ); - backBtnImg.SetWidescreen( Settings.widescreen ); - } - GuiButton backBtn( btnOutline.GetWidth(), btnOutline.GetHeight() ); - backBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - backBtn.SetPosition( -190, 400 ); - backBtn.SetLabel( &backBtnTxt ); - backBtn.SetImage( &backBtnImg ); - backBtn.SetSoundOver( btnSoundOver ); - backBtn.SetSoundClick( btnSoundClick2 ); - backBtn.SetTrigger( &trigA ); - backBtn.SetTrigger( &trigB ); - backBtn.SetEffectGrow(); - - GuiText defaultBtnTxt( tr( "Default" ) , 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - defaultBtnTxt.SetMaxWidth( btnOutline.GetWidth() - 30 ); - GuiImage defaultBtnImg( &btnOutline ); - if ( Settings.wsprompt == ON ) - { - defaultBtnTxt.SetWidescreen( Settings.widescreen ); - defaultBtnImg.SetWidescreen( Settings.widescreen ); - } - GuiButton defaultBtn( btnOutline.GetWidth(), btnOutline.GetHeight() ); - defaultBtn.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - defaultBtn.SetPosition( 190, 400 ); - defaultBtn.SetLabel( &defaultBtnTxt ); - defaultBtn.SetImage( &defaultBtnImg ); - defaultBtn.SetSoundOver( btnSoundOver ); - defaultBtn.SetSoundClick( btnSoundClick2 ); - defaultBtn.SetTrigger( &trigA ); - defaultBtn.SetEffectGrow(); - - DirList * Dir = new DirList(themepath, ".them"); - OptionList options2; - - for ( cnt = 0; cnt < Dir->GetFilecount(); cnt++ ) - { - char filename[64]; - strlcpy( filename, Dir->GetFilename( cnt ), sizeof( filename ) ); - char *dot = strchr( filename, '.' ); - if ( dot ) *dot = '\0'; - options2.SetName( cnt, "%s", filename ); - options2.SetValue( cnt, NULL ); - - } - - GuiCustomOptionBrowser optionBrowser4( 396, 280, &options2, "bg_options_settings.png"); - optionBrowser4.SetPosition( 0, 90 ); - optionBrowser4.SetAlignment( ALIGN_CENTRE, ALIGN_TOP ); - - HaltGui(); - GuiWindow w( screenwidth, screenheight ); - w.Append( &backgroundImg ); - w.Append( &pathBtn ); - w.Append( &backBtn ); - w.Append( &optionBrowser4 ); - mainWindow->Append( &w ); - - w.SetEffect( EFFECT_FADE, 20 ); - ResumeGui(); - - while ( w.GetEffect() > 0 ) usleep(100); - - while (returnVal == 0) - { - usleep(100); - - if (shutdown) - Sys_Shutdown(); - else if (reset) - Sys_Reboot(); - - else if ( backBtn.GetState() == STATE_CLICKED ) - break; - - else if ( defaultBtn.GetState() == STATE_CLICKED ) - { - choice = WindowPrompt( tr( "Loading default theme." ), 0, tr( "OK" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - snprintf(Settings.theme_path, sizeof(Settings.theme_path), "%stheme/", Settings.ConfigPath); - Theme::SetDefault(); - Settings.Save(); - returnVal = 1; - } - defaultBtn.ResetState(); - } - - else if ( pathBtn.GetState() == STATE_CLICKED ) - { - w.Remove( &optionBrowser4 ); - w.Remove( &backBtn ); - w.Remove( &pathBtn ); - w.Remove( &defaultBtn ); - int result = OnScreenKeyboard( themepath, sizeof(themepath), 0 ); - w.Append( &optionBrowser4 ); - w.Append( &pathBtn ); - w.Append( &backBtn ); - w.Append( &defaultBtn ); - if (result == 1) - { - if (themepath[strlen(themepath)-1] != '/') - strcat(themepath, "/"); - - HaltGui(); - delete Dir; - Dir = new DirList(themepath, ".them"); - options2.ClearList(); - for ( cnt = 0; cnt < Dir->GetFilecount(); cnt++ ) - { - char filename[64]; - strlcpy( filename, Dir->GetFilename( cnt ), sizeof( filename ) ); - char *dot = strchr( filename, '.' ); - if ( dot ) *dot = '\0'; - options2.SetName( cnt, "%s", filename ); - options2.SetValue( cnt, NULL ); - } - titleTxt.SetText(themepath); - ResumeGui(); - WindowPrompt( tr( "Theme path is changed." ), 0, tr( "OK" ) ); - } - pathBtn.ResetState(); - } - - ret = optionBrowser4.GetClickedOption(); - - if (ret >= 0 && ret < Dir->GetFilecount()) - { - choice = WindowPrompt( tr( "Do you want to load this theme?" ), Dir->GetFilename(ret), tr( "Yes" ), tr( "Cancel" ) ); - if ( choice == 1 ) - { - snprintf(Settings.theme_path, sizeof( Settings.theme_path ), "%s", Dir->GetFilepath(ret)); - if ( !CheckFile( Settings.theme_path ) ) - { - WindowPrompt( tr( "File not found." ), tr( "Loading default theme." ), tr( "OK" ) ); - Theme::SetDefault(); - } - else - { - Theme::Load(Settings.theme_path); - } - Settings.Save(); - returnVal = 1; - break; - } - optionBrowser4.SetFocus( 1 ); - } - } - - w.SetEffect( EFFECT_FADE, -20 ); - while ( w.GetEffect() > 0 ) usleep(100); - - HaltGui(); - mainWindow->Remove( &w ); - ResumeGui(); - - delete Dir; - - return returnVal; -} - diff --git a/source/settings/SettingsPrompts.h b/source/settings/SettingsPrompts.h deleted file mode 100644 index d1c13e49..00000000 --- a/source/settings/SettingsPrompts.h +++ /dev/null @@ -1,15 +0,0 @@ -/**************************************************************************** - * SettingsPrompts - * USB Loader GX 2009 - * - * SettingsPrompts.h - ***************************************************************************/ - -#ifndef _SETTINGSPROMPTS_H_ -#define _SETTINGSPROMPTS_H_ - -bool MenuBackgroundMusic(); -int MenuLanguageSelect(); -int MenuThemeSelect(); - -#endif diff --git a/source/settings/menus/CustomPathsSM.cpp b/source/settings/menus/CustomPathsSM.cpp deleted file mode 100644 index 2e57ecbe..00000000 --- a/source/settings/menus/CustomPathsSM.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "CustomPathsSM.hpp" -#include "settings/SettingsPrompts.h" -#include "settings/CSettings.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "prompts/filebrowser.h" -#include "themes/CTheme.h" - -CustomPathsSM::CustomPathsSM() - : SettingsMenu(tr("Custom Paths"), &GuiOptions, MENU_NONE) -{ - int Idx = 0; - Options->SetName(Idx++, tr("3D Cover Path")); - Options->SetName(Idx++, tr("2D Cover Path")); - Options->SetName(Idx++, tr("Disc Artwork Path")); - Options->SetName(Idx++, tr("Theme Path")); - Options->SetName(Idx++, tr("WiiTDB Path")); - Options->SetName(Idx++, tr("Update Path")); - Options->SetName(Idx++, tr("GCT Cheatcodes Path")); - Options->SetName(Idx++, tr("TXT Cheatcodes Path")); - Options->SetName(Idx++, tr("DOL Path")); - Options->SetName(Idx++, tr("Homebrew Apps Path")); - Options->SetName(Idx++, tr("Theme Download Path")); - Options->SetName(Idx++, tr("BCA Codes Path")); - Options->SetName(Idx++, tr("WIP Patches Path")); - Options->SetName(Idx++, tr("Languagefiles Path")); - - SetOptionValues(); -} - -void CustomPathsSM::SetOptionValues() -{ - int Idx = 0; - - //! Settings: 3D Cover Path - Options->SetValue(Idx++, Settings.covers_path); - - //! Settings: 2D Cover Path - Options->SetValue(Idx++, Settings.covers2d_path); - - //! Settings: Disc Artwork Path - Options->SetValue(Idx++, Settings.disc_path); - - //! Settings: Theme Path - Options->SetValue(Idx++, Settings.theme_path); - - //! Settings: WiiTDB Path - Options->SetValue(Idx++, Settings.titlestxt_path); - - //! Settings: Update Path - Options->SetValue(Idx++, Settings.update_path); - - //! Settings: GCT Cheatcodes Path - Options->SetValue(Idx++, Settings.Cheatcodespath); - - //! Settings: TXT Cheatcodes Path - Options->SetValue(Idx++, Settings.TxtCheatcodespath); - - //! Settings: DOL Path - Options->SetValue(Idx++, Settings.dolpath); - - //! Settings: Homebrew Apps Path - Options->SetValue(Idx++, Settings.homebrewapps_path); - - //! Settings: Theme Download Path - Options->SetValue(Idx++, Settings.theme_downloadpath); - - //! Settings: BCA Codes Path - Options->SetValue(Idx++, Settings.BcaCodepath); - - //! Settings: WIP Patches Path - Options->SetValue(Idx++, Settings.WipCodepath); - - //! Settings: Languagefiles Path - Options->SetValue(Idx++, Settings.languagefiles_path); -} - -int CustomPathsSM::GetMenuInternal() -{ - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: 3D Cover Path - if (ret == ++Idx) - { - titleTxt->SetText(tr( "3D Cover Path" )); - ChangePath(Settings.covers_path, sizeof(Settings.covers_path)); - } - - //! Settings: 2D Cover Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "2D Cover Path" )); - ChangePath(Settings.covers2d_path, sizeof(Settings.covers2d_path)); - } - - //! Settings: Disc Artwork Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "Disc Artwork Path" )); - ChangePath(Settings.disc_path, sizeof(Settings.disc_path)); - } - - //! Settings: Theme Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "Theme Path" )); - HaltGui(); - GuiWindow * parent = (GuiWindow *) parentElement; - if(parent) parent->SetState(STATE_DISABLED); - this->SetState(STATE_DEFAULT); - this->Remove(optionBrowser); - ResumeGui(); - int res = MenuThemeSelect(); - if(parent) parent->SetState(STATE_DEFAULT); - this->Append(optionBrowser); - if (res == 1) - { - HaltGui(); - mainWindow->Remove(bgImg); - if(pointer[0]) delete pointer[0]; - if(pointer[1]) delete pointer[1]; - if(pointer[2]) delete pointer[2]; - if(pointer[3]) delete pointer[3]; - pointer[0] = Resources::GetImageData("player1_point.png"); - pointer[1] = Resources::GetImageData("player2_point.png"); - pointer[2] = Resources::GetImageData("player3_point.png"); - pointer[3] = Resources::GetImageData("player4_point.png"); - if(background) delete background; - background = Resources::GetImageData(Settings.widescreen ? "wbackground.png" : "background.png"); - if(bgImg) delete bgImg; - bgImg = new GuiImage(background); - mainWindow->Append(bgImg); - ResumeGui(); - return MENU_SETTINGS; - } - } - - //! Settings: WiiTDB Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "WiiTDB Path" )); - ChangePath(Settings.titlestxt_path, sizeof(Settings.titlestxt_path)); - } - - //! Settings: Update Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "Update Path" )); - ChangePath(Settings.update_path, sizeof(Settings.update_path)); - } - - //! Settings: GCT Cheatcodes Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "GCT Cheatcodes Path" )); - ChangePath(Settings.Cheatcodespath, sizeof(Settings.Cheatcodespath)); - } - - //! Settings: TXT Cheatcodes Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "TXT Cheatcodes Path" )); - ChangePath(Settings.TxtCheatcodespath, sizeof(Settings.TxtCheatcodespath)); - } - - //! Settings: DOL Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "DOL Path" )); - ChangePath(Settings.dolpath, sizeof(Settings.dolpath)); - } - - //! Settings: Homebrew Apps Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "Homebrew Apps Path" )); - ChangePath(Settings.homebrewapps_path, sizeof(Settings.homebrewapps_path)); - } - - //! Settings: Theme Download Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "Theme Download Path" )); - ChangePath(Settings.theme_downloadpath, sizeof(Settings.theme_downloadpath)); - } - - //! Settings: BCA Codes Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "BCA Codes Path" )); - ChangePath(Settings.BcaCodepath, sizeof(Settings.BcaCodepath)); - } - - //! Settings: WIP Patches Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "WIP Patches Path" )); - ChangePath(Settings.WipCodepath, sizeof(Settings.WipCodepath)); - } - - //! Settings: Languagefiles Path - else if (ret == ++Idx) - { - titleTxt->SetText(tr( "Languagefiles Path" )); - ChangePath(Settings.languagefiles_path, sizeof(Settings.languagefiles_path)); - } - - //! Global set back of the titleTxt after a change - titleTxt->SetText(tr( "Custom Paths" )); - SetOptionValues(); - - return MENU_NONE; -} - -int CustomPathsSM::ChangePath(char * SettingsPath, int SizeOfPath) -{ - char entered[300]; - snprintf(entered, sizeof(entered), SettingsPath); - - HaltGui(); - GuiWindow * parent = (GuiWindow *) parentElement; - if(parent) parent->SetState(STATE_DISABLED); - this->SetState(STATE_DEFAULT); - this->Remove(optionBrowser); - ResumeGui(); - - int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES); - - if(parent) parent->SetState(STATE_DEFAULT); - this->Append(optionBrowser); - - if (result == 1) - { - if (entered[strlen(entered)-1] != '/') - strcat(entered, "/"); - - snprintf(SettingsPath, SizeOfPath, entered); - WindowPrompt(tr( "Path Changed" ), 0, tr( "OK" )); - } - - return result; -} diff --git a/source/settings/menus/CustomPathsSM.hpp b/source/settings/menus/CustomPathsSM.hpp deleted file mode 100644 index 344e7fb7..00000000 --- a/source/settings/menus/CustomPathsSM.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef CUSTOMPATHS_MENU_HPP_ -#define CUSTOMPATHS_MENU_HPP_ - -#include "SettingsMenu.hpp" - -class CustomPathsSM : public SettingsMenu -{ - public: - CustomPathsSM(); - virtual int GetType() { return CCustomPathsSM; }; - protected: - void SetOptionValues(); - int GetMenuInternal(); - int ChangePath(char * SettingsPath, int SizeOfPath); - - OptionList GuiOptions; -}; - - -#endif diff --git a/source/settings/menus/FlyingButtonsMenu.cpp b/source/settings/menus/FlyingButtonsMenu.cpp deleted file mode 100644 index 9e5573e4..00000000 --- a/source/settings/menus/FlyingButtonsMenu.cpp +++ /dev/null @@ -1,466 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include - -#include "FlyingButtonsMenu.hpp" -#include "utils/StringTools.h" -#include "language/gettext.h" -#include "themes/CTheme.h" -#include "menu/menus.h" -#include "sys.h" - -#define FADE_SPEED 20 -#define SLIDE_SPEED 35 -#define DISPLAY_BUTTONS 4 - -FlyingButtonsMenu::FlyingButtonsMenu(const char * menu_title) - : GuiWindow(screenwidth, screenheight) - -{ - currentPage = 0; - returnMenu = MENU_NONE; - ParentMenu = MENU_DISCLIST; - CurrentMenu = NULL; - titleTxt = NULL; - GoLeftImg = NULL; - GoLeftBtn = NULL; - GoRightImg = NULL; - GoRightBtn = NULL; - MenuTitle = menu_title ? menu_title : " "; - - trigA = new GuiTrigger(); - trigHome = new GuiTrigger(); - trigB = new GuiTrigger(); - trigL = new GuiTrigger(); - trigR = new GuiTrigger(); - trigMinus = new GuiTrigger(); - trigPlus = new GuiTrigger(); - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - trigHome->SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - trigL->SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); - trigR->SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); - trigMinus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0); - trigPlus->SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0); - - btnOutline = Resources::GetImageData("button_dialogue_box.png"); - settingsbg = Resources::GetImageData("settings_background.png"); - MainButtonImgData = Resources::GetImageData("settings_title.png"); - MainButtonImgOverData = Resources::GetImageData("settings_title_over.png"); - PageindicatorImgData = Resources::GetImageData("pageindicator.png"); - arrow_left = Resources::GetImageData("startgame_arrow_left.png"); - arrow_right = Resources::GetImageData("startgame_arrow_right.png"); - - settingsbackground = new GuiImage(settingsbg); - Append(settingsbackground); - - homeBtn = new GuiButton(1, 1); - homeBtn->SetTrigger(trigHome); - Append(homeBtn); - - backBtnTxt = new GuiText(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnTxt->SetMaxWidth(btnOutline->GetWidth() - 30); - backBtnImg = new GuiImage(btnOutline); - if (Settings.wsprompt == ON) - { - backBtnTxt->SetWidescreen(Settings.widescreen); - backBtnImg->SetWidescreen(Settings.widescreen); - } - backBtn = new GuiButton(backBtnImg, backBtnImg, 2, 3, -195, 400, trigA, btnSoundOver, btnSoundClick2, 1); - backBtn->SetLabel(backBtnTxt); - backBtn->SetTrigger(trigB); - Append(backBtn); - - SetEffect(EFFECT_FADE, FADE_SPEED); -} - -FlyingButtonsMenu::~FlyingButtonsMenu() -{ - ResumeGui(); - - SetEffect(EFFECT_FADE, -FADE_SPEED); - while(parentElement && this->GetEffect() > 0) usleep(100); - - HaltGui(); - if(parentElement) - ((GuiWindow *) parentElement)->Remove(this); - - RemoveAll(); - HideMenu(); - - delete trigA; - delete trigHome; - delete trigB; - delete trigL; - delete trigR; - delete trigMinus; - delete trigPlus; - delete settingsbackground; - delete homeBtn; - delete btnOutline; - delete settingsbg; - delete MainButtonImgData; - delete MainButtonImgOverData; - delete PageindicatorImgData; - delete arrow_left; - delete arrow_right; - delete backBtnTxt; - delete backBtnImg; - delete backBtn; - - ResumeGui(); -} - -void FlyingButtonsMenu::SetPageIndicators() -{ - HaltGui(); - - for(u32 i = 0; i < PageIndicatorBtn.size(); ++i) - { - Remove(PageIndicatorBtn[i]); - delete PageindicatorImg[i]; - delete PageindicatorTxt[i]; - delete PageIndicatorBtn[i]; - } - PageindicatorImg.clear(); - PageindicatorTxt.clear(); - PageIndicatorBtn.clear(); - - int IndicatorCount = ceil(MainButton.size()/(1.0f*DISPLAY_BUTTONS)); - - for(int i = 0; i < IndicatorCount; ++i) - { - PageindicatorImg.push_back(new GuiImage(PageindicatorImgData)); - PageindicatorTxt.push_back(new GuiText(fmt("%i", i+1), 22, ( GXColor ) {0, 0, 0, 255})); - PageIndicatorBtn.push_back(new GuiButton(PageindicatorImgData->GetWidth(), PageindicatorImgData->GetHeight())); - PageIndicatorBtn[i]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - PageIndicatorBtn[i]->SetPosition(270-IndicatorCount*35+35*i, 400); - PageIndicatorBtn[i]->SetImage(PageindicatorImg[i]); - PageIndicatorBtn[i]->SetLabel(PageindicatorTxt[i]); - PageIndicatorBtn[i]->SetSoundOver(btnSoundOver); - PageIndicatorBtn[i]->SetSoundClick(btnSoundClick); - PageIndicatorBtn[i]->SetTrigger(trigA); - PageIndicatorBtn[i]->SetEffectGrow(); - PageIndicatorBtn[i]->SetAlpha(i == currentPage ? 255 : 50); - Append(PageIndicatorBtn[i]); - } -} - -void FlyingButtonsMenu::SetMainButton(int position, const char * ButtonText, GuiImageData * imageData, GuiImageData * imageOver) -{ - //! Don't allow operating gui mode while adding/setting the buttons - HaltGui(); - - if(position < (int) MainButton.size()) - { - delete MainButtonImg[position]; - delete MainButtonImgOver[position]; - delete MainButtonTxt[position]; - delete MainButton[position]; - } - else - { - MainButtonImg.resize(position+1); - MainButtonImgOver.resize(position+1); - MainButtonTxt.resize(position+1); - MainButton.resize(position+1); - } - - MainButtonImg[position] = new GuiImage(imageData); - MainButtonImgOver[position] = new GuiImage(imageOver); - - MainButtonTxt[position] = new GuiText(ButtonText, 22, ( GXColor ) {0, 0, 0, 255}); - MainButtonTxt[position]->SetMaxWidth(MainButtonImg[position]->GetWidth()); - - MainButton[position] = new GuiButton(imageData->GetWidth(), imageData->GetHeight()); - MainButton[position]->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - MainButton[position]->SetPosition(0, 90+(position % DISPLAY_BUTTONS)*70); - MainButton[position]->SetImage(MainButtonImg[position]); - MainButton[position]->SetImageOver(MainButtonImgOver[position]); - MainButton[position]->SetLabel(MainButtonTxt[position]); - MainButton[position]->SetSoundOver(btnSoundOver); - MainButton[position]->SetSoundClick(btnSoundClick); - MainButton[position]->SetEffectGrow(); - MainButton[position]->SetTrigger(trigA); -} - -void FlyingButtonsMenu::HideMenu() -{ - HaltGui(); - - if(titleTxt) - Remove(titleTxt); - if(GoLeftBtn) - Remove(GoLeftBtn); - if(GoRightBtn) - Remove(GoRightBtn); - - if(titleTxt) - delete titleTxt; - if(GoLeftImg) - delete GoLeftImg; - if(GoLeftBtn) - delete GoLeftBtn; - if(GoRightImg) - delete GoRightImg; - if(GoRightBtn) - delete GoRightBtn; - titleTxt = NULL; - GoLeftImg = NULL; - GoLeftBtn = NULL; - GoRightImg = NULL; - GoRightBtn = NULL; - - for(u32 i = 0; i < MainButton.size(); ++i) - { - Remove(MainButton[i]); - delete MainButtonImg[i]; - delete MainButtonImgOver[i]; - delete MainButtonTxt[i]; - delete MainButton[i]; - } - for(u32 i = 0; i < PageIndicatorBtn.size(); ++i) - { - Remove(PageIndicatorBtn[i]); - delete PageindicatorImg[i]; - delete PageindicatorTxt[i]; - delete PageIndicatorBtn[i]; - } - - PageindicatorImg.clear(); - PageindicatorTxt.clear(); - PageIndicatorBtn.clear(); - MainButtonImg.clear(); - MainButtonImgOver.clear(); - MainButtonTxt.clear(); - MainButton.clear(); -} - -void FlyingButtonsMenu::ShowMenu() -{ - //! Free memory if not done yet because new is allocated - HideMenu(); - - titleTxt = new GuiText(MenuTitle.c_str(), 28, ( GXColor ) {0, 0, 0, 255}); - titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt->SetPosition(0, 40); - titleTxt->SetMaxWidth(310, SCROLL_HORIZONTAL); - Append(titleTxt); - - GoLeftImg = new GuiImage(arrow_left); - GoLeftBtn = new GuiButton(GoLeftImg->GetWidth(), GoLeftImg->GetHeight()); - GoLeftBtn->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - GoLeftBtn->SetPosition(25, -25); - GoLeftBtn->SetImage(GoLeftImg); - GoLeftBtn->SetSoundOver(btnSoundOver); - GoLeftBtn->SetSoundClick(btnSoundClick2); - GoLeftBtn->SetEffectGrow(); - GoLeftBtn->SetTrigger(trigA); - GoLeftBtn->SetTrigger(trigL); - GoLeftBtn->SetTrigger(trigMinus); - Append(GoLeftBtn); - - GoRightImg = new GuiImage(arrow_right); - GoRightBtn = new GuiButton(GoRightImg->GetWidth(), GoRightImg->GetHeight()); - GoRightBtn->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); - GoRightBtn->SetPosition(-25, -25); - GoRightBtn->SetImage(GoRightImg); - GoRightBtn->SetSoundOver(btnSoundOver); - GoRightBtn->SetSoundClick(btnSoundClick2); - GoRightBtn->SetEffectGrow(); - GoRightBtn->SetTrigger(trigA); - GoRightBtn->SetTrigger(trigR); - GoRightBtn->SetTrigger(trigPlus); - Append(GoRightBtn); - - SetupMainButtons(); - AddMainButtons(); - - ShowButtonsEffects(EFFECT_FADE, FADE_SPEED); -} - -void FlyingButtonsMenu::AddMainButtons() -{ - HaltGui(); - - for(u32 i = 0; i < MainButton.size(); ++i) - Remove(MainButton[i]); - - int FirstItem = currentPage*DISPLAY_BUTTONS; - - for(int i = FirstItem; i < (int) MainButton.size() && i < FirstItem+DISPLAY_BUTTONS; ++i) - { - Append(MainButton[i]); - } - - SetPageIndicators(); -} - -void FlyingButtonsMenu::ShowButtonsEffects(int effect, int effect_speed) -{ - int FirstItem = currentPage*DISPLAY_BUTTONS; - if(FirstItem < 0) - FirstItem = 0; - - HaltGui(); - - for(int i = FirstItem; i < (int) MainButton.size() && i < FirstItem+DISPLAY_BUTTONS; ++i) - { - MainButton[i]->StopEffect(); - MainButton[i]->SetEffect(effect, effect_speed); - } - - ResumeGui(); - - if(FirstItem < 0 || FirstItem >= (int) MainButton.size()) - return; - - //! Don't lock on fade in for initiation purpose - if(effect & EFFECT_FADE && effect_speed > 0) - return; - - while (parentElement && MainButton[FirstItem]->GetEffect() > 0) - usleep(100); -} - -void FlyingButtonsMenu::SlideButtons(int direction) -{ - int SlideEffectIN = 0; - - if(direction == SLIDE_LEFT) - { - ShowButtonsEffects(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_OUT, SLIDE_SPEED); - SlideEffectIN = EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN; - - currentPage--; - - if(currentPage < 0) - currentPage = MainButton.size() > 0 ? ceil(MainButton.size()/4.0f)-1 : 0; - } - else - { - ShowButtonsEffects(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, SLIDE_SPEED); - SlideEffectIN = EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_IN; - - currentPage++; - - if(currentPage >= ceil(MainButton.size()/4.0f)) - currentPage = 0; - } - - AddMainButtons(); - - ShowButtonsEffects(SlideEffectIN, SLIDE_SPEED); -} - -int FlyingButtonsMenu::MainLoop() -{ - usleep(100); - - if(shutdown) - Sys_Shutdown(); - else if(reset) - Sys_Reboot(); - - if(backBtn->GetState() == STATE_CLICKED) - { - if(CurrentMenu) - { - DeleteSettingsMenu(); - ShowMenu(); - } - else - { - return ParentMenu; - } - backBtn->ResetState(); - } - else if(GoRightBtn && GoRightBtn->GetState() == STATE_CLICKED) - { - SlideButtons(SLIDE_RIGHT); - GoRightBtn->ResetState(); - } - else if(GoLeftBtn && GoLeftBtn->GetState() == STATE_CLICKED) - { - SlideButtons(SLIDE_LEFT); - GoLeftBtn->ResetState(); - } - else if(homeBtn->GetState() == STATE_CLICKED) - { - Settings.Save(); - if(CurrentMenu) CurrentMenu->SetState(STATE_DISABLED); - bgMusic->Pause(); - int choice = WindowExitPrompt(); - bgMusic->Resume(); - if (choice == 3) - Sys_LoadMenu(); // Back to System Menu - else if (choice == 2) - Sys_BackToLoader(); - homeBtn->ResetState(); - if(CurrentMenu) CurrentMenu->SetState(STATE_DEFAULT); - } - else if(CurrentMenu) - { - int newMenu = CurrentMenu->GetMenu(); - if(newMenu != MENU_NONE) - return newMenu; - } - - for(u32 i = 0; i < PageIndicatorBtn.size(); ++i) - { - if(PageIndicatorBtn[i]->GetState() != STATE_CLICKED) - continue; - - if(i < (u32) currentPage) - { - ShowButtonsEffects(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_OUT, SLIDE_SPEED); - currentPage = i; - AddMainButtons(); - ShowButtonsEffects(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, SLIDE_SPEED); - } - else if(i > (u32) currentPage) - { - ShowButtonsEffects(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_OUT, SLIDE_SPEED); - currentPage = i; - AddMainButtons(); - ShowButtonsEffects(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_IN, SLIDE_SPEED); - } - - PageIndicatorBtn[i]->ResetState(); - } - - for(u32 i = 0; i < MainButton.size(); ++i) - { - if(MainButton[i]->GetState() != STATE_CLICKED) - continue; - - MainButton[i]->ResetState(); - - CreateSettingsMenu(i); - break; - } - - return returnMenu; -} diff --git a/source/settings/menus/FlyingButtonsMenu.hpp b/source/settings/menus/FlyingButtonsMenu.hpp deleted file mode 100644 index 49644660..00000000 --- a/source/settings/menus/FlyingButtonsMenu.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef FLYINGBUTTONSMENU_HPP_ -#define FLYINGBUTTONSMENU_HPP_ - -#include -#include -#include "libwiigui/gui.h" -#include "SettingsMenu.hpp" -#include "menu.h" - -class FlyingButtonsMenu : public GuiWindow -{ - public: - FlyingButtonsMenu(const char * menu_title); - ~FlyingButtonsMenu(); - virtual int MainLoop(); - virtual void HideMenu(); - virtual void ShowMenu(); - protected: - virtual void CreateSettingsMenu(int index) { }; - virtual void DeleteSettingsMenu() { }; - virtual void SetupMainButtons() { }; - virtual void AddMainButtons(); - virtual void ShowButtonsEffects(int effect, int effect_speed); - virtual void SlideButtons(int slide_direction); - virtual void SetPageIndicators(); - virtual void SetMainButton(int position, const char * ButtonText, GuiImageData * imageData, GuiImageData * imageOver); - - int currentPage; - int returnMenu; - int ParentMenu; - std::string MenuTitle; - enum - { - SLIDE_LEFT, SLIDE_RIGHT - }; - - //!The main settings gui with browser - SettingsMenu * CurrentMenu; - - GuiImageData * btnOutline; - GuiImageData * settingsbg; - GuiImageData * MainButtonImgData; - GuiImageData * MainButtonImgOverData; - GuiImageData * PageindicatorImgData; - GuiImageData * arrow_left; - GuiImageData * arrow_right; - - GuiImage * settingsbackground; - GuiImage * backBtnImg; - GuiImage * PageindicatorImg2; - GuiImage * GoLeftImg; - GuiImage * GoRightImg; - - GuiTrigger * trigA; - GuiTrigger * trigHome; - GuiTrigger * trigB; - GuiTrigger * trigL; - GuiTrigger * trigR; - GuiTrigger * trigMinus; - GuiTrigger * trigPlus; - - GuiText * titleTxt; - GuiText * backBtnTxt; - GuiText * PageindicatorTxt1; - - GuiButton * backBtn; - GuiButton * homeBtn; - GuiButton * GoLeftBtn; - GuiButton * GoRightBtn; - - std::vectorPageindicatorImg; - std::vectorPageindicatorTxt; - std::vectorPageIndicatorBtn; - - std::vector MainButtonImg; - std::vector MainButtonImgOver; - std::vector MainButtonTxt; - std::vector MainButton; -}; - -#endif diff --git a/source/settings/menus/GUISettingsMenu.cpp b/source/settings/menus/GUISettingsMenu.cpp deleted file mode 100644 index fabc063d..00000000 --- a/source/settings/menus/GUISettingsMenu.cpp +++ /dev/null @@ -1,332 +0,0 @@ - /**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "GUISettingsMenu.hpp" -#include "settings/CSettings.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "settings/SettingsPrompts.h" -#include "settings/GameTitles.h" -#include "xml/xml.h" -#include "fatmounter.h" - -static const char * OnOffText[MAX_ON_OFF] = -{ - trNOOP( "OFF" ), - trNOOP( "ON" ) -}; - -static const char * WiilightText[WIILIGHT_MAX] = -{ - trNOOP( "OFF" ), - trNOOP( "ON" ), - trNOOP( "Only for Install" ) -}; - -static const char * GameInfoText[GAMEINFO_MAX] = -{ - trNOOP( "Game ID" ), - trNOOP( "Game Region" ), - trNOOP( "Both" ), - trNOOP( "Neither" ) -}; - -static const char * FlipXText[XFLIP_MAX][3] = -{ - { trNOOP( "Right" ), "/", trNOOP( "Next" ) }, - { trNOOP( "Left" ), "/", trNOOP( "Prev" ) }, - { trNOOP( "Like SysMenu" ), "", "" }, - { trNOOP( "Right" ), "/", trNOOP( "Prev" ) }, - { trNOOP( "DiskFlip" ), "", "" } -}; - -static const char * PromptButtonsText[MAX_ON_OFF] = -{ - trNOOP( "Normal" ), - trNOOP( "Widescreen Fix" ), -}; - -static const char * KeyboardText[KEYBOARD_MAX] = -{ - "QWERTY", - "DVORAK", - "QWERTZ", - "AZERTY", - "QWERTY 2" -}; - -static const char * DiscArtDownloadText[4] = -{ - trNOOP( "Only Original" ), - trNOOP( "Only Customs" ), - trNOOP( "Original/Customs" ), - trNOOP( "Customs/Original" ) -}; - -static const char *ScreensaverText[SCREENSAVER_MAX] = -{ - trNOOP( "OFF" ), - trNOOP( "3 min" ), - trNOOP( "5 min" ), - trNOOP( "10 min" ), - trNOOP( "20 min" ), - trNOOP( "30 min" ), - trNOOP( "1 hour" ) -}; - -GuiSettingsMenu::GuiSettingsMenu() - : SettingsMenu(tr("GUI Settings"), &GuiOptions, MENU_NONE) -{ - int Idx = 0; - Options->SetName(Idx++, "%s", tr( "App Language" )); - Options->SetName(Idx++, "%s", tr( "Display" )); - Options->SetName(Idx++, "%s", tr( "Clock" )); - Options->SetName(Idx++, "%s", tr( "Tooltips" )); - Options->SetName(Idx++, "%s", tr( "Flip-X" )); - Options->SetName(Idx++, "%s", tr( "Prompts Buttons" )); - Options->SetName(Idx++, "%s", tr( "Keyboard" )); - Options->SetName(Idx++, "%s", tr( "Disc Artwork Download" )); - Options->SetName(Idx++, "%s", tr( "Wiilight" )); - Options->SetName(Idx++, "%s", tr( "Rumble" )); - Options->SetName(Idx++, "%s", tr( "AutoInit Network" )); - Options->SetName(Idx++, "%s", tr( "BETA revisions" )); - Options->SetName(Idx++, "%s", tr( "Titles from WiiTDB" )); - Options->SetName(Idx++, "%s", tr( "Screensaver" )); - Options->SetName(Idx++, "%s", tr( "Mark new games" )); - - SetOptionValues(); - - OldTitlesOverride = Settings.titlesOverride; -} - -GuiSettingsMenu::~GuiSettingsMenu() -{ - if (Settings.titlesOverride != OldTitlesOverride) - GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); -} - -void GuiSettingsMenu::SetOptionValues() -{ - int Idx = 0; - - //! Settings: App Language - const char * language = strrchr(Settings.language_path, '/'); - if(language) - language += 1; - if (!language || strcmp(Settings.language_path, "") == 0) - Options->SetValue(Idx++, "%s", tr( "Default" )); - else - Options->SetValue(Idx++, "%s", language); - - //! Settings: Display - Options->SetValue(Idx++, "%s", tr( GameInfoText[Settings.sinfo] )); - - //! Settings: Clock - if (Settings.hddinfo == CLOCK_HR12) - Options->SetValue(Idx++, "12 %s", tr( "Hour" )); - else if (Settings.hddinfo == CLOCK_HR24) - Options->SetValue(Idx++, "24 %s", tr( "Hour" )); - else if (Settings.hddinfo == OFF) - Options->SetValue(Idx++, "%s", tr( "OFF" )); - - //! Settings: Tooltips - Options->SetValue(Idx++, "%s", tr(OnOffText[Settings.tooltips])); - - //! Settings: Flip-X - Options->SetValue(Idx++, "%s%s%s", tr(FlipXText[Settings.xflip][0]), - FlipXText[Settings.xflip][1], tr( FlipXText[Settings.xflip][2] )); - - //! Settings: Prompts Buttons - Options->SetValue(Idx++, "%s", tr( PromptButtonsText[Settings.wsprompt] )); - - //! Settings: Keyboard - Options->SetValue(Idx++, "%s", KeyboardText[Settings.keyset]); - - //! Settings: Disc Artwork Download - Options->SetValue(Idx++, "%s", tr( DiscArtDownloadText[Settings.discart] )); - - //! Settings: Wiilight - Options->SetValue(Idx++, "%s", tr( WiilightText[Settings.wiilight] )); - - //! Settings: Rumble - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.rumble] )); - - //! Settings: AutoInit Network - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.autonetwork] )); - - //! Settings: BETA revisions - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.beta_upgrades] )); - - //! Settings: Titles from WiiTDB - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.titlesOverride] )); - - //! Settings: Screensaver - Options->SetValue(Idx++, "%s", tr( ScreensaverText[Settings.screensaver] )); - - //! Settings: Mark new games - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.marknewtitles] )); -} - -int GuiSettingsMenu::GetMenuInternal() -{ - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: App Language - if (ret == ++Idx) - { - if (!isInserted(Settings.BootDevice)) - { - WindowPrompt(tr( "No SD-Card inserted!" ), tr( "Insert an SD-Card to use this option." ), tr( "OK" )); - return MENU_NONE; - } - if (!Settings.godmode) - { - WindowPrompt(tr( "Language change:" ), tr( "Console should be unlocked to modify it." ), tr( "OK" )); - return MENU_NONE; - } - SetEffect(EFFECT_FADE, -20); - while (GetEffect() > 0) usleep(100); - HaltGui(); - if(parentElement) - { - ((GuiWindow *) parentElement)->Remove(this); - ((GuiWindow *) parentElement)->SetState(STATE_DISABLED); - } - ResumeGui(); - - int returnhere = 1; - while (returnhere == 1) - returnhere = MenuLanguageSelect(); - - if (returnhere == 2) - { - //! Language changed. Reload game titles with new lang code. - GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); - return MENU_SETTINGS; - } - - HaltGui(); - if(parentElement) - { - ((GuiWindow *) parentElement)->Append(this); - ((GuiWindow *) parentElement)->SetState(STATE_DEFAULT); - } - SetEffect(EFFECT_FADE, 20); - ResumeGui(); - while (GetEffect() > 0) usleep(100); - } - - //! Settings: Display - else if (ret == ++Idx) - { - if (++Settings.sinfo >= GAMEINFO_MAX) Settings.sinfo = 0; - } - - //! Settings: Clock - else if (ret == ++Idx) - { - if (++Settings.hddinfo >= CLOCK_MAX) Settings.hddinfo = 0; //CLOCK - } - - //! Settings: Tooltips - else if (ret == ++Idx) - { - if (++Settings.tooltips >= MAX_ON_OFF) Settings.tooltips = 0; - } - - //! Settings: Flip-X - else if (ret == ++Idx) - { - if (++Settings.xflip >= XFLIP_MAX) Settings.xflip = 0; - } - - //! Settings: Prompts Buttons - else if (ret == ++Idx) - { - if (++Settings.wsprompt >= MAX_ON_OFF) Settings.wsprompt = 0; - } - - //! Settings: Keyboard - else if (ret == ++Idx) - { - if (++Settings.keyset >= KEYBOARD_MAX) Settings.keyset = 0; - } - - //! Settings: Disc Artwork Download - else if (ret == ++Idx) - { - if (++Settings.discart >= 4) Settings.discart = 0; - } - - //! Settings: Wiilight - else if (ret == ++Idx) - { - if (++Settings.wiilight >= WIILIGHT_MAX) Settings.wiilight = 0; - } - - //! Settings: Rumble - else if (ret == ++Idx) - { - if (++Settings.rumble >= MAX_ON_OFF) Settings.rumble = 0; //RUMBLE - } - - //! Settings: AutoInit Network - else if (ret == ++Idx) - { - if (++Settings.autonetwork >= MAX_ON_OFF) Settings.autonetwork = 0; - } - - //! Settings: BETA revisions - else if (ret == ++Idx) - { - if (++Settings.beta_upgrades >= MAX_ON_OFF) Settings.beta_upgrades = 0; - } - - //! Settings: Titles from WiiTDB - else if (ret == ++Idx) - { - if (++Settings.titlesOverride >= MAX_ON_OFF) Settings.titlesOverride = 0; - } - - //! Settings: Screensaver - else if (ret == ++Idx) - { - if (++Settings.screensaver >= SCREENSAVER_MAX) Settings.screensaver = 0; - } - - //! Settings: Mark new games - else if (ret == ++Idx) - { - if (++Settings.marknewtitles >= MAX_ON_OFF) Settings.marknewtitles = 0; - } - - SetOptionValues(); - - return MENU_NONE; -} diff --git a/source/settings/menus/GUISettingsMenu.hpp b/source/settings/menus/GUISettingsMenu.hpp deleted file mode 100644 index 97680648..00000000 --- a/source/settings/menus/GUISettingsMenu.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef GUISETTINGS_MENU_HPP_ -#define GUISETTINGS_MENU_HPP_ - -#include "SettingsMenu.hpp" - -class GuiSettingsMenu : public SettingsMenu -{ - public: - GuiSettingsMenu(); - ~GuiSettingsMenu(); - virtual int GetType() { return CGUISettingsMenu; }; - protected: - void SetOptionValues(); - int GetMenuInternal(); - - int OldTitlesOverride; - - OptionList GuiOptions; -}; - - -#endif diff --git a/source/settings/menus/GameLoadSM.cpp b/source/settings/menus/GameLoadSM.cpp deleted file mode 100644 index cd39c4f7..00000000 --- a/source/settings/menus/GameLoadSM.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "GameLoadSM.hpp" -#include "settings/CSettings.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "wad/nandtitle.h" -#include "prompts/TitleBrowser.h" -#include "usbloader/GameList.h" -#include "usbloader/wbfs.h" -#include "usbloader/utils.h" -#include "system/IosLoader.h" -#include "settings/GameTitles.h" -#include "xml/xml.h" -#include "menu.h" - -extern PartList partitions; -extern char game_partition[6]; -extern u8 load_from_fs; - -static const char * OnOffText[MAX_ON_OFF] = -{ - trNOOP( "OFF" ), - trNOOP( "ON" ) -}; - -static const char * VideoModeText[VIDEO_MODE_MAX] = -{ - trNOOP( "Disc Default" ), - trNOOP( "System Default" ), - trNOOP( "AutoPatch" ), - trNOOP( "Force PAL50" ), - trNOOP( "Force PAL60" ), - trNOOP( "Force NTSC" ) -}; - -static const char * LanguageText[MAX_LANGUAGE] = -{ - trNOOP( "Disc Default" ), - trNOOP( "Console Default" ), - trNOOP( "Japanese" ), - trNOOP( "English" ), - trNOOP( "German" ), - trNOOP( "French" ), - trNOOP( "Spanish" ), - trNOOP( "Italian" ), - trNOOP( "Dutch" ), - trNOOP( "SChinese" ), - trNOOP( "TChinese" ), - trNOOP( "Korean" ) -}; - -static const char * InstallToText[INSTALL_TO_MAX] = -{ - trNOOP( "None" ), - trNOOP( "GAMEID_Gamename" ), - trNOOP( "Gamename [GAMEID]" ) -}; - -static const char * Error002Text[3] = -{ - trNOOP( "No" ), - trNOOP( "Yes" ), - trNOOP( "Anti" ) -}; - -static inline bool IsValidPartition(int fs_type, int cios) -{ - if (IosLoader::IsWaninkokoIOS() && NandTitles.VersionOf(TITLE_ID(1, cios)) < 18) - { - return fs_type == FS_TYPE_WBFS; - } - else - { - return fs_type == FS_TYPE_WBFS || fs_type == FS_TYPE_FAT32 || fs_type == FS_TYPE_NTFS || fs_type == FS_TYPE_EXT; - } -} - -GameLoadSM::GameLoadSM() - : SettingsMenu(tr("Game Load"), &GuiOptions, MENU_NONE) -{ - int Idx = 0; - - Options->SetName(Idx++, "%s", tr( "Video Mode" )); - Options->SetName(Idx++, "%s", tr( "VIDTV Patch" )); - Options->SetName(Idx++, "%s", tr( "Game Language" )); - Options->SetName(Idx++, "%s", tr( "Patch Country Strings" )); - Options->SetName(Idx++, "%s", tr( "Ocarina" )); - Options->SetName(Idx++, "%s", tr( "Boot/Standard" )); - Options->SetName(Idx++, "%s", tr( "Partition" )); - Options->SetName(Idx++, "%s", tr( "FAT: Use directories" )); - Options->SetName(Idx++, "%s", tr( "Quick Boot" )); - Options->SetName(Idx++, "%s", tr( "Error 002 fix" )); - Options->SetName(Idx++, "%s", tr( "Install partitions" )); - Options->SetName(Idx++, "%s", tr( "Return To" )); - - SetOptionValues(); - - OldSettingsPartition = Settings.partition; -} - -GameLoadSM::~GameLoadSM() -{ - //! if partition has changed, Reinitialize it - if (Settings.partition != OldSettingsPartition) - { - PartInfo pinfo = partitions.pinfo[Settings.partition]; - partitionEntry pentry = partitions.pentry[Settings.partition]; - WBFS_OpenPart(pinfo.part_fs, pinfo.index, pentry.sector, pentry.size, (char *) &game_partition); - load_from_fs = pinfo.part_fs; - - //! Reload the new game titles - gameList.ReadGameList(); - GameTitles.LoadTitlesFromWiiTDB(Settings.titlestxt_path); - } -} - -void GameLoadSM::SetOptionValues() -{ - int Idx = 0; - - //! Settings: Video Mode - Options->SetValue(Idx++, "%s", tr(VideoModeText[Settings.videomode])); - - //! Settings: VIDTV Patch - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.videopatch] )); - - //! Settings: Game Language - Options->SetValue(Idx++, "%s", tr( LanguageText[Settings.language] )); - - //! Settings: Patch Country Strings - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.patchcountrystrings] )); - - //! Settings: Ocarina - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.ocarina] )); - - //! Settings: Boot/Standard - if (Settings.godmode) - Options->SetValue(Idx++, "IOS %i", Settings.cios); - else - Options->SetValue(Idx++, "********"); - - //! Settings: Partition - PartInfo pInfo = partitions.pinfo[Settings.partition]; - f32 partition_size = partitions.pentry[Settings.partition].size - * (partitions.sector_size / GB_SIZE); - - // Get the partition name and it's size in GB's - Options->SetValue(Idx++, "%s%d (%.2fGB)", pInfo.fs_type == FS_TYPE_FAT32 ? "FAT" - : pInfo.fs_type == FS_TYPE_NTFS ? "NTFS" : pInfo.fs_type == FS_TYPE_EXT ? "LINUX" : "WBFS", pInfo.index, partition_size); - - //! Settings: FAT: Use directories - Options->SetValue(Idx++, "%s", tr( InstallToText[Settings.FatInstallToDir] )); - - //! Settings: Quick Boot - Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.quickboot] )); - - //! Settings: Error 002 fix - Options->SetValue(Idx++, "%s", tr( Error002Text[Settings.error002] )); - - //! Settings: Install partitions - if(Settings.InstallPartitions == ONLY_GAME_PARTITION) - Options->SetValue(Idx++, "%s", tr("Game partition")); - else if(Settings.InstallPartitions == ALL_PARTITIONS) - Options->SetValue(Idx++, "%s", tr("All partitions")); - else if(Settings.InstallPartitions == REMOVE_UPDATE_PARTITION) - Options->SetValue(Idx++, "%s", tr("Remove update")); - - //! Settings: Return To - const char* TitleName = NULL; - int haveTitle = NandTitles.FindU32(Settings.returnTo); - if (haveTitle >= 0) - TitleName = NandTitles.NameFromIndex(haveTitle); - TitleName = TitleName ? TitleName : strlen(Settings.returnTo) > 0 ? Settings.returnTo : tr(OnOffText[0]); - Options->SetValue(Idx++, "%s", TitleName); -} - -int GameLoadSM::GetMenuInternal() -{ - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: Video Mode - if (ret == ++Idx) - { - if (++Settings.videomode >= VIDEO_MODE_MAX) Settings.videomode = 0; - } - - //! Settings: VIDTV Patch - else if (ret == ++Idx) - { - if (++Settings.videopatch >= MAX_ON_OFF) Settings.videopatch = 0; - } - - //! Settings: Game Language - else if (ret == ++Idx) - { - if (++Settings.language >= MAX_LANGUAGE) Settings.language = 0; - } - - //! Settings: Patch Country Strings - else if (ret == ++Idx) - { - if (++Settings.patchcountrystrings >= MAX_ON_OFF) Settings.patchcountrystrings = 0; - } - - //! Settings: Ocarina - else if (ret == ++Idx) - { - if (++Settings.ocarina >= MAX_ON_OFF) Settings.ocarina = 0; - } - - //! Settings: Boot/Standard - else if (ret == ++Idx) - { - if(!Settings.godmode) - return MENU_NONE; - - char entered[4]; - snprintf(entered, sizeof(entered), "%i", Settings.cios); - if(OnScreenKeyboard(entered, sizeof(entered), 0)) - { - Settings.cios = atoi(entered); - if(Settings.cios < 200) Settings.cios = 200; - else if(Settings.cios > 255) Settings.cios = 255; - - if(NandTitles.IndexOf(TITLE_ID(1, Settings.cios)) < 0) - { - WindowPrompt(tr("Warning:"), tr("This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning."), tr("OK")); - } - else if(Settings.cios == 254) - { - WindowPrompt(tr("Warning:"), tr("This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning."), tr("OK")); - } - } - } - - //! Settings: Partition - else if (ret == ++Idx) - { - // Select the next valid partition, even if that's the same one - int fs_type = partitions.pinfo[Settings.partition].fs_type; - int ios = IOS_GetVersion(); - do - { - Settings.partition = (Settings.partition + 1) % partitions.num; - fs_type = partitions.pinfo[Settings.partition].fs_type; - } - while (!IsValidPartition(fs_type, ios)); - } - - //! Settings: FAT: Use directories - else if (ret == ++Idx) - { - if (++Settings.FatInstallToDir >= INSTALL_TO_MAX) Settings.FatInstallToDir = 0; - } - - //! Settings: Quick Boot - else if (ret == ++Idx) - { - if (++Settings.quickboot >= MAX_ON_OFF) Settings.quickboot = 0; - } - - //! Settings: Error 002 fix - else if (ret == ++Idx ) - { - if (++Settings.error002 >= 3) Settings.error002 = 0; - } - - //! Settings: Install partitions - else if (ret == ++Idx) - { - switch(Settings.InstallPartitions) - { - case ONLY_GAME_PARTITION: - Settings.InstallPartitions = ALL_PARTITIONS; - break; - case ALL_PARTITIONS: - Settings.InstallPartitions = REMOVE_UPDATE_PARTITION; - break; - default: - case REMOVE_UPDATE_PARTITION: - Settings.InstallPartitions = ONLY_GAME_PARTITION; - break; - } - } - - //! Settings: Return To - else if (ret == ++Idx) - { - char tidChar[10]; - bool getChannel = TitleSelector(tidChar); - if (getChannel) - snprintf(Settings.returnTo, sizeof(Settings.returnTo), "%s", tidChar); - } - - SetOptionValues(); - - return MENU_NONE; -} - diff --git a/source/settings/menus/GameLoadSM.hpp b/source/settings/menus/GameLoadSM.hpp deleted file mode 100644 index 27fd7e7b..00000000 --- a/source/settings/menus/GameLoadSM.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef GAMELOADSM_HPP_ -#define GAMELOADSM_HPP_ - -#include "SettingsMenu.hpp" - -class GameLoadSM : public SettingsMenu -{ - public: - GameLoadSM(); - ~GameLoadSM(); - virtual int GetType() { return CGameLoadSM; }; - protected: - void SetOptionValues(); - int GetMenuInternal(); - - int OldSettingsPartition; - - OptionList GuiOptions; -}; - - -#endif diff --git a/source/settings/menus/GameSettingsMenu.cpp b/source/settings/menus/GameSettingsMenu.cpp deleted file mode 100644 index 1f187aa2..00000000 --- a/source/settings/menus/GameSettingsMenu.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "GameSettingsMenu.hpp" -#include "themes/CTheme.h" -#include "prompts/PromptWindows.h" -#include "settings/GameTitles.h" -#include "language/gettext.h" -#include "wad/nandtitle.h" -#include "cheats/cheatmenu.h" -#include "IndGameLoadSM.hpp" -#include "UninstallSM.hpp" - -GameSettingsMenu::GameSettingsMenu(struct discHdr * header) - : FlyingButtonsMenu(GameTitles.GetTitle(header)) -{ - DiscHeader = header; - //! Don't switch menu's by default but return to disc window. - ParentMenu = -2; -} - -GameSettingsMenu::~GameSettingsMenu() -{ -} - -void GameSettingsMenu::SetupMainButtons() -{ - int pos = 0; - - SetMainButton(pos++, tr( "Game Load" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Ocarina" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Uninstall Menu" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Default Gamesettings" ), MainButtonImgData, MainButtonImgOverData); -} - -void GameSettingsMenu::CreateSettingsMenu(int menuNr) -{ - if(CurrentMenu) - return; - - int Idx = 0; - - //! Game Load - if(menuNr == Idx++) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new IndGameLoadSM((const char *) DiscHeader->id); - Append(CurrentMenu); - } - - //! Ocarina - else if(menuNr == Idx++) - { - char ID[7]; - snprintf(ID, sizeof(ID), "%s", (char *) DiscHeader->id); - CheatMenu(ID); - } - - //! Uninstall Menu - else if(menuNr == Idx++) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new UninstallSM(DiscHeader); - Append(CurrentMenu); - } - - //! Default Gamesettings - else if(menuNr == Idx++) - { - int choice = WindowPrompt(tr( "Are you sure?" ), 0, tr( "Yes" ), tr( "Cancel" )); - if (choice == 1) - { - GameSettings.Remove(DiscHeader->id); - GameSettings.Save(); - } - } -} - -void GameSettingsMenu::DeleteSettingsMenu() -{ - if(!CurrentMenu) - return; - - int type = CurrentMenu->GetType(); - - switch(type) - { - case CIndGameLoadSM: - delete ((IndGameLoadSM *) CurrentMenu); - break; - case CUninstallSM: - delete ((UninstallSM *) CurrentMenu); - break; - case CSettingsMenu: - default: - delete CurrentMenu; - break; - } - - CurrentMenu = NULL; -} diff --git a/source/settings/menus/GameSettingsMenu.hpp b/source/settings/menus/GameSettingsMenu.hpp deleted file mode 100644 index 91cb6b58..00000000 --- a/source/settings/menus/GameSettingsMenu.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef GAMESETTINGSMENU_HPP_ -#define GAMESETTINGSMENU_HPP_ - -#include "FlyingButtonsMenu.hpp" -#include "settings/CGameSettings.h" -#include "usbloader/disc.h" - -class GameSettingsMenu : public FlyingButtonsMenu -{ - public: - GameSettingsMenu(struct discHdr * header); - ~GameSettingsMenu(); - protected: - virtual void CreateSettingsMenu(int index); - virtual void DeleteSettingsMenu(); - virtual void SetupMainButtons(); - - struct discHdr * DiscHeader; -}; - -#endif diff --git a/source/settings/menus/GlobalSettings.cpp b/source/settings/menus/GlobalSettings.cpp deleted file mode 100644 index e2810450..00000000 --- a/source/settings/menus/GlobalSettings.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "GlobalSettings.hpp" -#include "themes/CTheme.h" -#include "prompts/PromptWindows.h" -#include "network/update.h" -#include "language/gettext.h" -#include "GUISettingsMenu.hpp" -#include "GameLoadSM.hpp" -#include "ParentalControlSM.hpp" -#include "SoundSettingsMenu.hpp" -#include "CustomPathsSM.hpp" - -GlobalSettings::GlobalSettings() - : FlyingButtonsMenu(tr("Global Settings")) -{ - creditsImgData = Resources::GetImageData("credits_button.png"); - creditsImgOverData = Resources::GetImageData("credits_button_over.png"); -} - -GlobalSettings::~GlobalSettings() -{ - Settings.Save(); - - delete creditsImgData; - delete creditsImgOverData; -} - -void GlobalSettings::SetupMainButtons() -{ - int pos = 0; - - SetMainButton(pos++, tr( "GUI Settings" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Game Load" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Parental Control" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Sound" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Custom Paths" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Update" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Default Settings" ), MainButtonImgData, MainButtonImgOverData); - SetMainButton(pos++, tr( "Credits" ), creditsImgData, creditsImgOverData); - SetMainButton(pos++, tr( "Theme Downloader" ), MainButtonImgData, MainButtonImgOverData); -} - -void GlobalSettings::CreateSettingsMenu(int menuNr) -{ - if(CurrentMenu) - return; - - int Idx = 0; - - //! GUI Settings - if(menuNr == Idx++) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new GuiSettingsMenu(); - Append(CurrentMenu); - } - //! Game Load - else if(menuNr == Idx++) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new GameLoadSM(); - Append(CurrentMenu); - } - //! Parental Control - else if(menuNr == Idx++) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new ParentalControlSM(); - Append(CurrentMenu); - } - //! Sound - else if(menuNr == Idx++) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new SoundSettingsMenu(); - Append(CurrentMenu); - } - //! Custom Paths - else if(menuNr == Idx++) - { - if(Settings.godmode) - { - HideMenu(); - ResumeGui(); - CurrentMenu = new CustomPathsSM(); - Append(CurrentMenu); - } - else - WindowPrompt(tr( "Console Locked" ), tr( "Unlock console to use this option." ), tr( "OK" )); - - } - //! Update - else if(menuNr == Idx++) - { - if (Settings.godmode) - { - HideMenu(); - Remove(backBtn); - ResumeGui(); - int ret = UpdateApp(); - if (ret < 0) - WindowPrompt(tr( "Update failed" ), 0, tr( "OK" )); - Append(backBtn); - ShowMenu(); - } - else - WindowPrompt(tr( "Console Locked" ), tr( "Unlock console to use this option." ), tr( "OK" )); - } - //! Default Settings - else if(menuNr == Idx++) - { - if (Settings.godmode) - { - int choice = WindowPrompt(tr( "Are you sure you want to reset?" ), 0, tr( "Yes" ), tr( "Cancel" )); - if (choice == 1) - { - HaltGui(); - gettextCleanUp(); - Settings.Reset(); - returnMenu = MENU_SETTINGS; - ResumeGui(); - } - } - else - WindowPrompt(tr( "Console Locked" ), tr( "Unlock console to use this option." ), tr( "OK" )); - } - //! Credits - else if(menuNr == Idx++) - { - HideMenu(); - Remove(backBtn); - ResumeGui(); - WindowCredits(); - Append(backBtn); - ShowMenu(); - } - //! Theme Downloader - else if(menuNr == Idx++) - { - returnMenu = MENU_THEMEDOWNLOADER; - } -} - -void GlobalSettings::DeleteSettingsMenu() -{ - if(!CurrentMenu) - return; - - int type = CurrentMenu->GetType(); - - switch(type) - { - case CGUISettingsMenu: - delete ((GuiSettingsMenu *) CurrentMenu); - break; - case CGameLoadSM: - delete ((GameLoadSM *) CurrentMenu); - break; - case CParentalControlSM: - delete ((ParentalControlSM *) CurrentMenu); - break; - case CSoundSettingsMenu: - delete ((SoundSettingsMenu *) CurrentMenu); - break; - case CCustomPathsSM: - delete ((CustomPathsSM *) CurrentMenu); - break; - case CSettingsMenu: - default: - delete CurrentMenu; - break; - } - - CurrentMenu = NULL; -} diff --git a/source/settings/menus/GlobalSettings.hpp b/source/settings/menus/GlobalSettings.hpp deleted file mode 100644 index 97b9400c..00000000 --- a/source/settings/menus/GlobalSettings.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef GLOBAL_SETTINGS_HPP_ -#define GLOBAL_SETTINGS_HPP_ - -#include "FlyingButtonsMenu.hpp" - -class GlobalSettings : public FlyingButtonsMenu -{ - public: - GlobalSettings(); - ~GlobalSettings(); - protected: - virtual void CreateSettingsMenu(int index); - virtual void DeleteSettingsMenu(); - virtual void SetupMainButtons(); - - GuiImageData * creditsImgData; - GuiImageData * creditsImgOverData; -}; - -#endif diff --git a/source/settings/menus/IndGameLoadSM.cpp b/source/settings/menus/IndGameLoadSM.cpp deleted file mode 100644 index 9a6848ca..00000000 --- a/source/settings/menus/IndGameLoadSM.cpp +++ /dev/null @@ -1,408 +0,0 @@ - /**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include "settings/CSettings.h" -#include "themes/CTheme.h" -#include "prompts/PromptWindows.h" -#include "prompts/DiscBrowser.h" -#include "language/gettext.h" -#include "wad/nandtitle.h" -#include "IndGameLoadSM.hpp" - -static const char * OnOffText[MAX_ON_OFF] = -{ - trNOOP( "OFF" ), - trNOOP( "ON" ) -}; - -static const char * VideoModeText[VIDEO_MODE_MAX] = -{ - trNOOP( "Disc Default" ), - trNOOP( "System Default" ), - trNOOP( "AutoPatch" ), - trNOOP( "Force PAL50" ), - trNOOP( "Force PAL60" ), - trNOOP( "Force NTSC" ) -}; - -static const char * LanguageText[MAX_LANGUAGE] = -{ - trNOOP( "Disc Default" ), - trNOOP( "Console Default" ), - trNOOP( "Japanese" ), - trNOOP( "English" ), - trNOOP( "German" ), - trNOOP( "French" ), - trNOOP( "Spanish" ), - trNOOP( "Italian" ), - trNOOP( "Dutch" ), - trNOOP( "SChinese" ), - trNOOP( "TChinese" ), - trNOOP( "Korean" ) -}; - -static const char * Error002Text[3] = -{ - trNOOP( "No" ), - trNOOP( "Yes" ), - trNOOP( "Anti" ) -}; - -static const char * ParentalText[5] = -{ - trNOOP( "0 (Everyone)" ), - trNOOP( "1 (Child 7+)" ), - trNOOP( "2 (Teen 12+)" ), - trNOOP( "3 (Mature 16+)" ), - trNOOP( "4 (Adults Only 18+)" ) -}; - -static const char * AlternateDOLText[] = -{ - trNOOP( "OFF" ), - trNOOP( "Select a DOL from Game" ), - trNOOP( "Load From SD/USB" ), -}; - -IndGameLoadSM::IndGameLoadSM(const char * GameID) - : SettingsMenu(tr("Game Load"), &GuiOptions, MENU_NONE) -{ - //! Setup default settings from global settings - snprintf(GameConfig.id, sizeof(GameConfig.id), "%s", (char *) GameID); - SetDefaultConfig(); - - GameCFG * existCFG = GameSettings.GetGameCFG(GameID); - - //! Overwrite with existing if available - if (existCFG) - memcpy(&GameConfig, existCFG, sizeof(GameCFG)); - - if(!btnOutline) - btnOutline = Resources::GetImageData("button_dialogue_box.png"); - if(!trigA) - trigA = new GuiTrigger(); - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - saveBtnTxt = new GuiText(tr( "Save" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - saveBtnTxt->SetMaxWidth(btnOutline->GetWidth() - 30); - saveBtnImg = new GuiImage (btnOutline); - if (Settings.wsprompt == ON) - { - saveBtnTxt->SetWidescreen(Settings.widescreen); - saveBtnImg->SetWidescreen(Settings.widescreen); - } - saveBtn = new GuiButton(saveBtnImg, saveBtnImg, 2, 3, 180, 400, trigA, btnSoundOver, btnSoundClick2, 1); - saveBtn->SetLabel(saveBtnTxt); - Append(saveBtn); - - SetOptionNames(); - SetOptionValues(); -} - -IndGameLoadSM::~IndGameLoadSM() -{ - HaltGui(); - //! The rest is destroyed in SettingsMenu.cpp - Remove(saveBtn); - delete saveBtnTxt; - delete saveBtnImg; - delete saveBtn; - ResumeGui(); -} - -void IndGameLoadSM::SetDefaultConfig() -{ - GameConfig.video = Settings.videomode; - GameConfig.language = Settings.language; - GameConfig.ocarina = Settings.ocarina; - GameConfig.vipatch = Settings.videopatch; - GameConfig.ios = Settings.cios; - GameConfig.parentalcontrol = 0; - GameConfig.errorfix002 = Settings.error002; - GameConfig.patchcountrystrings = Settings.patchcountrystrings; - GameConfig.loadalternatedol = OFF; - GameConfig.alternatedolstart = 0; - GameConfig.iosreloadblock = OFF; - strcpy(GameConfig.alternatedolname, ""); - GameConfig.returnTo = 1; - GameConfig.Locked = 0; -} - -void IndGameLoadSM::SetOptionNames() -{ - int Idx = 0; - - Options->SetName(Idx++, "%s", tr( "Video Mode" )); - Options->SetName(Idx++, "%s", tr( "VIDTV Patch" )); - Options->SetName(Idx++, "%s", tr( "Game Language" )); - Options->SetName(Idx++, "%s", tr( "Patch Country Strings" )); - Options->SetName(Idx++, "%s", tr( "Ocarina" )); - Options->SetName(Idx++, "%s", tr( "Game IOS" )); - Options->SetName(Idx++, "%s", tr( "Parental Control" )); - Options->SetName(Idx++, "%s", tr( "Error 002 fix" )); - Options->SetName(Idx++, "%s", tr( "Return To" )); - Options->SetName(Idx++, "%s", tr( "Alternate DOL" )); - Options->SetName(Idx++, "%s", tr( "Select DOL Offset" )); - Options->SetName(Idx++, "%s", tr( "Block IOS Reload" )); - Options->SetName(Idx++, "%s", tr( "Game Lock" )); -} - -void IndGameLoadSM::SetOptionValues() -{ - int Idx = 0; - - //! Settings: Video Mode - Options->SetValue(Idx++, "%s", tr(VideoModeText[GameConfig.video])); - - //! Settings: VIDTV Patch - Options->SetValue(Idx++, "%s", tr(OnOffText[GameConfig.vipatch])); - - //! Settings: Game Language - Options->SetValue(Idx++, "%s", tr(LanguageText[GameConfig.language])); - - //! Settings: Patch Country Strings - Options->SetValue(Idx++, "%s", tr(OnOffText[GameConfig.patchcountrystrings])); - - //! Settings: Ocarina - Options->SetValue(Idx++, "%s", tr(OnOffText[GameConfig.ocarina])); - - //! Settings: Game IOS - Options->SetValue(Idx++, "%i", GameConfig.ios); - - //! Settings: Parental Control - Options->SetValue(Idx++, "%s", tr(ParentalText[GameConfig.parentalcontrol])); - - //! Settings: Error 002 fix - Options->SetValue(Idx++, "%s", tr(Error002Text[GameConfig.errorfix002])); - - //! Settings: Return To - if(GameConfig.returnTo) - { - const char* TitleName = NULL; - int haveTitle = NandTitles.FindU32(Settings.returnTo); - if (haveTitle >= 0) - TitleName = NandTitles.NameFromIndex(haveTitle); - Options->SetValue(Idx++, "%s", TitleName ? TitleName : strlen(Settings.returnTo) > 0 ? - Settings.returnTo : tr( OnOffText[0] )); - } - else - { - Options->SetValue(Idx++, "%s", tr( OnOffText[0] )); - } - - //! Settings: Alternate DOL - Options->SetValue(Idx++, "%s", tr( AlternateDOLText[GameConfig.loadalternatedol] )); - - //! Settings: Select DOL Offset - if(GameConfig.loadalternatedol != 1) - Options->SetValue(Idx++, tr("Not required")); - else - { - if(strcmp(GameConfig.alternatedolname, "") != 0) - Options->SetValue(Idx++, "%i <%s>", GameConfig.alternatedolstart, GameConfig.alternatedolname); - else - Options->SetValue(Idx++, "%i", GameConfig.alternatedolstart); - } - - //! Settings: Block IOS Reload - Options->SetValue(Idx++, "%s", tr( OnOffText[GameConfig.iosreloadblock] )); - - //! Settings: Game Lock - Options->SetValue(Idx++, "%s", tr( OnOffText[GameConfig.Locked] )); -} - -int IndGameLoadSM::GetMenuInternal() -{ - if (saveBtn->GetState() == STATE_CLICKED) - { - if (GameSettings.AddGame(GameConfig) && GameSettings.Save()) - { - WindowPrompt(tr( "Successfully Saved" ), 0, tr( "OK" )); - } - else - WindowPrompt(tr( "Save Failed. No device inserted?" ), 0, tr( "OK" )); - - saveBtn->ResetState(); - } - - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: Video Mode - if (ret == ++Idx) - { - if (++GameConfig.video >= VIDEO_MODE_MAX) GameConfig.video = 0; - } - - //! Settings: VIDTV Patch - else if (ret == ++Idx) - { - if (++GameConfig.vipatch >= MAX_ON_OFF) GameConfig.vipatch = 0; - } - - //! Settings: Game Language - else if (ret == ++Idx) - { - if (++GameConfig.language >= MAX_LANGUAGE) GameConfig.language = 0; - } - - //! Settings: Patch Country Strings - else if (ret == ++Idx) - { - if (++GameConfig.patchcountrystrings >= MAX_ON_OFF) GameConfig.patchcountrystrings = 0; - } - - //! Settings: Ocarina - else if (ret == ++Idx) - { - if (++GameConfig.ocarina >= MAX_ON_OFF) GameConfig.ocarina = 0; - } - - //! Settings: Game IOS - else if (ret == ++Idx) - { - char entered[4]; - snprintf(entered, sizeof(entered), "%i", GameConfig.ios); - if(OnScreenKeyboard(entered, sizeof(entered), 0)) - { - GameConfig.ios = atoi(entered); - if(GameConfig.ios < 200) GameConfig.ios = 200; - else if(GameConfig.ios > 255) GameConfig.ios = 255; - - if(NandTitles.IndexOf(TITLE_ID(1, GameConfig.ios)) < 0) - { - WindowPrompt(tr("Warning:"), tr("This IOS was not found on the titles list. If you are sure you have it installed than ignore this warning."), tr("OK")); - } - else if(GameConfig.ios == 254) - { - WindowPrompt(tr("Warning:"), tr("This IOS is the BootMii ios. If you are sure it is not BootMii and you have something else installed there than ignore this warning."), tr("OK")); - } - } - } - - //! Settings: Parental Control - else if (ret == ++Idx) - { - if (++GameConfig.parentalcontrol >= 5) GameConfig.parentalcontrol = 0; - } - - //! Settings: Error 002 fix - else if (ret == ++Idx) - { - if (++GameConfig.errorfix002 >= 3) GameConfig.errorfix002 = 0; - } - - //! Settings: Return To - else if (ret == ++Idx) - { - if (++GameConfig.returnTo >= MAX_ON_OFF) GameConfig.returnTo = 0; - } - - //! Settings: Alternate DOL - else if (ret == ++Idx) - { - if (++GameConfig.loadalternatedol > 2) - GameConfig.loadalternatedol = 0; - } - - //! Settings: Select DOL Offset from Game - else if (ret == ++Idx && GameConfig.loadalternatedol == 1) - { - char filename[10]; - snprintf(filename, 7, "%s", GameConfig.id); - - //alt dol menu for games that require more than a single alt dol - int autodol = autoSelectDolMenu(filename, false); - - if (autodol > 0) - { - GameConfig.alternatedolstart = autodol; - snprintf(GameConfig.alternatedolname, sizeof(GameConfig.alternatedolname), "%s <%i>", tr( "AUTO" ), autodol); - SetOptionValues(); - return MENU_NONE; - } - else if (autodol == 0) - { - GameConfig.loadalternatedol = 0; - SetOptionValues(); - return MENU_NONE; - } - - //check to see if we already know the offset of the correct dol - autodol = autoSelectDol(filename, false); - //if we do know that offset ask if they want to use it - if (autodol > 0) - { - int dolchoice = WindowPrompt(0, tr( "Do you want to use the alternate DOL that is known to be correct?" ), - tr( "Yes" ), tr( "Pick from a list" ), tr( "Cancel" )); - if (dolchoice == 1) - { - GameConfig.alternatedolstart = autodol; - snprintf(GameConfig.alternatedolname, sizeof(GameConfig.alternatedolname), "%s <%i>", tr( "AUTO" ), autodol); - } - else if (dolchoice == 2) //they want to search for the correct dol themselves - { - int res = DiscBrowse(GameConfig.id, GameConfig.alternatedolname, sizeof(GameConfig.alternatedolname)); - if (res >= 0) - GameConfig.alternatedolstart = res; - } - } - else - { - int res = DiscBrowse(GameConfig.id, GameConfig.alternatedolname, sizeof(GameConfig.alternatedolname)); - if (res >= 0) - { - GameConfig.alternatedolstart = res; - char tmp[170]; - snprintf(tmp, sizeof(tmp), "%s %s - %i", tr( "It seems that you have some information that will be helpful to us. Please pass this information along to the DEV team." ), filename, GameConfig.alternatedolstart); - WindowPrompt(0, tmp, tr( "OK" )); - } - } - - if(GameConfig.alternatedolstart == 0) - GameConfig.loadalternatedol = 0; - } - - //! Settings: Block IOS Reload - else if (ret == ++Idx) - { - if (++GameConfig.iosreloadblock >= MAX_ON_OFF) GameConfig.iosreloadblock = 0; - } - - //! Settings: Game Lock - else if (ret == ++Idx) - { - if (++GameConfig.Locked >= MAX_ON_OFF) GameConfig.Locked = 0; - } - - SetOptionValues(); - - return MENU_NONE; -} - diff --git a/source/settings/menus/IndGameLoadSM.hpp b/source/settings/menus/IndGameLoadSM.hpp deleted file mode 100644 index 9b7aaf6c..00000000 --- a/source/settings/menus/IndGameLoadSM.hpp +++ /dev/null @@ -1,51 +0,0 @@ - /**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef INDIVIDUAL_GAMELOAD_SM_HPP -#define INDIVIDUAL_GAMELOAD_SM_HPP - -#include "SettingsMenu.hpp" -#include "settings/CGameSettings.h" - -class IndGameLoadSM : public SettingsMenu -{ - public: - IndGameLoadSM(const char * GameID); - ~IndGameLoadSM(); - virtual int GetType() { return CIndGameLoadSM; }; - protected: - void SetDefaultConfig(); - void SetOptionNames(); - void SetOptionValues(); - int GetMenuInternal(); - - GameCFG GameConfig; - OptionList GuiOptions; - - GuiText * saveBtnTxt; - GuiImage * saveBtnImg; - GuiButton * saveBtn; -}; - - -#endif diff --git a/source/settings/menus/ParentalControlSM.cpp b/source/settings/menus/ParentalControlSM.cpp deleted file mode 100644 index 6b4dd9a1..00000000 --- a/source/settings/menus/ParentalControlSM.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "ParentalControlSM.hpp" -#include "settings/CSettings.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "utils/PasswordCheck.h" - -static const char * LockModeText[] = -{ - trNOOP( "Locked" ), - trNOOP( "Unlocked" ) -}; - -static const char * ParentalText[5] = -{ - trNOOP( "0 (Everyone)" ), - trNOOP( "1 (Child 7+)" ), - trNOOP( "2 (Teen 12+)" ), - trNOOP( "3 (Mature 16+)" ), - trNOOP( "4 (Adults Only 18+)" ) -}; - -static const char * LockedGamesText[2] = -{ - trNOOP( "0 (Locked and Unlocked Games)" ), - trNOOP( "1 (Unlocked Games Only)" ) -}; - -ParentalControlSM::ParentalControlSM() - : SettingsMenu(tr("Parental Control"), &GuiOptions, MENU_NONE) -{ - int Idx = 0; - Options->SetName(Idx++, "%s", tr( "Console" )); - Options->SetName(Idx++, "%s", tr( "Password" )); - Options->SetName(Idx++, "%s", tr( "Controllevel" )); - Options->SetName(Idx++, "%s", tr( "GamesLevel" )); - - SetOptionValues(); -} - -void ParentalControlSM::SetOptionValues() -{ - int Idx = 0; - - //! Settings: Console - Options->SetValue(Idx++, "%s", tr( LockModeText[Settings.godmode] )); - - //! Settings: Password - if (!Settings.godmode) - Options->SetValue(Idx++, "********"); - else if (strcmp(Settings.unlockCode, "") == 0) - Options->SetValue(Idx++, "%s", tr( "not set" )); - else - Options->SetValue(Idx++, Settings.unlockCode); - - //! Settings: Controllevel - if (Settings.godmode) - Options->SetValue(Idx++, "%s", tr( ParentalText[Settings.parentalcontrol] )); - else - Options->SetValue(Idx++, "********"); - - - //! Settings: GamesLevel - if (Settings.godmode) - Options->SetValue(Idx++, "%s", tr( LockedGamesText[Settings.lockedgames] )); - else - Options->SetValue(Idx++, "********"); -} - -int ParentalControlSM::GetMenuInternal() -{ - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: Console - if (ret == ++Idx) - { - if (!Settings.godmode) - { - //password check to unlock Install,Delete and Format - SetState(STATE_DISABLED); - int result = PasswordCheck(Settings.unlockCode); - SetState(STATE_DEFAULT); - if (result > 0) - { - if(result == 1) - WindowPrompt( tr( "Correct Password" ), tr( "All the features of USB Loader GX are unlocked." ), tr( "OK" )); - Settings.godmode = 1; - } - else if(result < 0) - WindowPrompt(tr( "Wrong Password" ), tr( "USB Loader GX is protected" ), tr( "OK" )); - } - else - { - int choice = WindowPrompt(tr( "Lock Console" ), tr( "Are you sure?" ), tr( "Yes" ), tr( "No" )); - if (choice == 1) - { - WindowPrompt(tr( "Console Locked" ), tr( "USB Loader GX is protected" ), tr( "OK" )); - Settings.godmode = 0; - } - } - } - - //! Settings: Password - else if (ret == ++Idx) - { - if (Settings.godmode) - { - char entered[20]; - SetState(STATE_DISABLED); - snprintf(entered, sizeof(entered), Settings.unlockCode); - int result = OnScreenKeyboard(entered, 20, 0); - SetState(STATE_DEFAULT); - if (result == 1) - { - snprintf(Settings.unlockCode, sizeof(Settings.unlockCode), entered); - WindowPrompt(tr( "Password Changed" ), tr( "Password has been changed" ), tr( "OK" )); - } - } - else - { - WindowPrompt(tr( "Password Changed" ), tr( "Console should be unlocked to modify it." ), tr( "OK" )); - } - } - - //! Settings: Controllevel - else if (ret == ++Idx) - { - if (Settings.godmode && ++Settings.parentalcontrol >= 5) Settings.parentalcontrol = 0; - } - - //! Settings: GamesLevel - else if (ret == ++Idx) - { - if (Settings.godmode && ++Settings.lockedgames >= 2) Settings.lockedgames = 0; - } - - SetOptionValues(); - - return MENU_NONE; -} diff --git a/source/settings/menus/ParentalControlSM.hpp b/source/settings/menus/ParentalControlSM.hpp deleted file mode 100644 index 7a6b2487..00000000 --- a/source/settings/menus/ParentalControlSM.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef PARENTALCONTROL_MENU_HPP_ -#define PARENTALCONTROL_MENU_HPP_ - -#include "SettingsMenu.hpp" - -class ParentalControlSM : public SettingsMenu -{ - public: - ParentalControlSM(); - virtual int GetType() { return CParentalControlSM; }; - protected: - void SetOptionValues(); - int GetMenuInternal(); - - OptionList GuiOptions; -}; - - -#endif diff --git a/source/settings/menus/SettingsMenu.cpp b/source/settings/menus/SettingsMenu.cpp deleted file mode 100644 index fa7b40dc..00000000 --- a/source/settings/menus/SettingsMenu.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "SettingsMenu.hpp" -#include "themes/CTheme.h" -#include "language/gettext.h" - -SettingsMenu::SettingsMenu(const char * title, OptionList * opts, int returnTo) - : GuiWindow(screenwidth, screenheight) -{ - Options = opts; - returnToMenu = returnTo; - trigA = NULL; - trigB = NULL; - backBtnTxt = NULL; - backBtnImg = NULL; - backBtn = NULL; - btnOutline = NULL; - - //! Skipping back button if there is no menu defined to go back to - if(returnToMenu != MENU_NONE) - { - btnOutline = Resources::GetImageData("button_dialogue_box.png"); - - trigA = new GuiTrigger(); - trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - trigB = new GuiTrigger(); - trigB->SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - backBtnTxt = new GuiText(tr("Back"), 22, (GXColor){0, 0, 0, 255}); - backBtnImg = new GuiImage(btnOutline); - backBtn = new GuiButton(backBtnImg, backBtnImg, 2, 3, -180, 400, trigA, btnSoundOver, btnSoundClick2, 1); - backBtn->SetLabel(backBtnTxt); - backBtn->SetTrigger(trigB); - Append(backBtn); - } - - optionBrowser = new GuiCustomOptionBrowser(396, 280, Options, "bg_options_settings.png"); - optionBrowser->SetPosition(0, 90); - optionBrowser->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - - titleTxt = new GuiText(title, 28, (GXColor) {0, 0, 0, 255}); - titleTxt->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt->SetPosition(0, 40); - titleTxt->SetMaxWidth(310, SCROLL_HORIZONTAL); - - Append(optionBrowser); - Append(titleTxt); - - SetEffect(EFFECT_FADE, 50); -} - -SettingsMenu::~SettingsMenu() -{ - ResumeGui(); - - SetEffect(EFFECT_FADE, -50); - while(this->GetEffect() > 0) - usleep(100); - - HaltGui(); - if(parentElement) - ((GuiWindow *) parentElement)->Remove(this); - - RemoveAll(); - - if(btnOutline) - delete btnOutline; - - if(backBtnTxt) - delete backBtnTxt; - if(backBtnImg) - delete backBtnImg; - if(backBtn) - delete backBtn; - - if(trigA) - delete trigA; - if(trigB) - delete trigB; - - delete titleTxt; - - delete optionBrowser; - - ResumeGui(); -} - -int SettingsMenu::GetClickedOption() -{ - if(!optionBrowser) - return -1; - - return optionBrowser->GetClickedOption(); -} - -int SettingsMenu::GetMenu() -{ - if(backBtn && backBtn->GetState() == STATE_CLICKED) - return returnToMenu; - - return GetMenuInternal(); -} diff --git a/source/settings/menus/SettingsMenu.hpp b/source/settings/menus/SettingsMenu.hpp deleted file mode 100644 index 4724d93c..00000000 --- a/source/settings/menus/SettingsMenu.hpp +++ /dev/null @@ -1,72 +0,0 @@ - /**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef SETTINGS_MENU_HPP_ -#define SETTINGS_MENU_HPP_ - -#include "libwiigui/gui.h" -#include "libwiigui/gui_customoptionbrowser.h" -#include "menu.h" - -enum -{ - CSettingsMenu = 0, - CGUISettingsMenu, - CGameLoadSM, - CParentalControlSM, - CSoundSettingsMenu, - CCustomPathsSM, - CIndGameLoadSM, - CUninstallSM, -}; - -class SettingsMenu : public GuiWindow -{ - public: - SettingsMenu(const char * title, OptionList * option, int returnTo); - ~SettingsMenu(); - int GetClickedOption(); - int GetMenu(); - virtual int GetType() { return CSettingsMenu; } - protected: - virtual int GetMenuInternal() { return MENU_NONE; }; - int returnToMenu; - - GuiImageData * btnOutline; - - GuiTrigger * trigA; - GuiTrigger * trigB; - - OptionList * Options; - - GuiText * titleTxt; - GuiText * backBtnTxt; - GuiImage * backBtnImg; - GuiButton * backBtn; - - GuiCustomOptionBrowser * optionBrowser; - -}; - - -#endif diff --git a/source/settings/menus/SoundSettingsMenu.cpp b/source/settings/menus/SoundSettingsMenu.cpp deleted file mode 100644 index a6b0a76e..00000000 --- a/source/settings/menus/SoundSettingsMenu.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "SoundSettingsMenu.hpp" -#include "settings/CSettings.h" -#include "settings/SettingsPrompts.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" - -static const char * GameSoundText[] = -{ - trNOOP( "Sound+Quiet" ), - trNOOP( "Sound+BGM" ), - trNOOP( "Loop Sound" ), -}; - -static const char * MusicLoopText[] = -{ - trNOOP( "Play Once" ), - trNOOP( "Loop Music" ), - trNOOP( "Random Directory Music" ), - trNOOP( "Loop Directory" ), -}; - -SoundSettingsMenu::SoundSettingsMenu() - : SettingsMenu(tr("Sound Settings"), &GuiOptions, MENU_NONE) -{ - int Idx = 0; - Options->SetName(Idx++, "%s", tr( "Backgroundmusic" )); - Options->SetName(Idx++, "%s", tr( "Music Volume" )); - Options->SetName(Idx++, "%s", tr( "SFX Volume" )); - Options->SetName(Idx++, "%s", tr( "Game Sound Mode" )); - Options->SetName(Idx++, "%s", tr( "Game Sound Volume" )); - Options->SetName(Idx++, "%s", tr( "Music Loop Mode" )); - Options->SetName(Idx++, "%s", tr( "Reset BG Music" )); - - SetOptionValues(); -} - -void SoundSettingsMenu::SetOptionValues() -{ - int Idx = 0; - - //! Settings: Backgroundmusic - const char * filename = strrchr(Settings.ogg_path, '/'); - if (filename) - Options->SetValue(Idx++, filename+1); - else - Options->SetValue(Idx++, tr( "Default" )); - - //! Settings: Music Volume - if (Settings.volume > 0) - Options->SetValue(Idx++, "%i", Settings.volume); - else - Options->SetValue(Idx++, tr( "OFF" )); - - //! Settings: SFX Volume - if (Settings.sfxvolume > 0) - Options->SetValue(Idx++, "%i", Settings.sfxvolume); - else - Options->SetValue(Idx++, tr( "OFF" )); - - //! Settings: Game Sound Mode - Options->SetValue(Idx++, "%s", tr( GameSoundText[Settings.gamesound] )); - - //! Settings: Game Sound Volume - if (Settings.gamesoundvolume > 0) - Options->SetValue(Idx++, "%i", Settings.gamesoundvolume); - else - Options->SetValue(Idx++, tr( "OFF" )); - - //! Settings: Music Loop Mode - Options->SetValue(Idx++, tr( MusicLoopText[Settings.musicloopmode] )); - - //! Settings: Reset BG Music - Options->SetValue(Idx++, " "); -} - -int SoundSettingsMenu::GetMenuInternal() -{ - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: Backgroundmusic - if (ret == ++Idx) - { - SetEffect(EFFECT_FADE, -20); - while (GetEffect() > 0) usleep(100); - HaltGui(); - GuiWindow * parent = (GuiWindow *) parentElement; - if(parent) parent->SetState(STATE_DISABLED); - ResumeGui(); - - MenuBackgroundMusic(); - - HaltGui(); - SetEffect(EFFECT_FADE, 20); - if(parent) parent->SetState(STATE_DEFAULT); - ResumeGui(); - while (GetEffect() > 0) usleep(100); - } - - //! Settings: Music Volume - else if (ret == ++Idx) - { - Settings.volume += 10; - if (Settings.volume > 100) Settings.volume = 0; - bgMusic->SetVolume(Settings.volume); - } - - //! Settings: SFX Volume - else if (ret == ++Idx) - { - Settings.sfxvolume += 10; - if (Settings.sfxvolume > 100) Settings.sfxvolume = 0; - btnSoundOver->SetVolume(Settings.sfxvolume); - btnSoundClick->SetVolume(Settings.sfxvolume); - btnSoundClick2->SetVolume(Settings.sfxvolume); - } - - //! Settings: Game Sound Mode - else if (ret == ++Idx) - { - if (++Settings.gamesound > 2) Settings.gamesound = 0; - } - - //! Settings: Game Sound Volume - else if (ret == ++Idx) - { - Settings.gamesoundvolume += 10; - if (Settings.gamesoundvolume > 100) Settings.gamesoundvolume = 0; - } - - //! Settings: Music Loop Mode - else if (ret == ++Idx) - { - if (++Settings.musicloopmode > 3) Settings.musicloopmode = 0; - bgMusic->SetLoop(Settings.musicloopmode); - } - - //! Settings: Reset BG Music - else if (ret == ++Idx) - { - int result = WindowPrompt(tr( "Reset to default BGM?" ), 0, tr( "Yes" ), tr( "No" )); - if (result) - { - bgMusic->LoadStandard(); - bgMusic->Play(); - } - } - - SetOptionValues(); - - return MENU_NONE; -} diff --git a/source/settings/menus/SoundSettingsMenu.hpp b/source/settings/menus/SoundSettingsMenu.hpp deleted file mode 100644 index 5f6bbb05..00000000 --- a/source/settings/menus/SoundSettingsMenu.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef SOUNDSETTINGS_MENU_HPP_ -#define SOUNDSETTINGS_MENU_HPP_ - -#include "SettingsMenu.hpp" - -class SoundSettingsMenu : public SettingsMenu -{ - public: - SoundSettingsMenu(); - virtual int GetType() { return CSoundSettingsMenu; }; - protected: - void SetOptionValues(); - int GetMenuInternal(); - - OptionList GuiOptions; -}; - - -#endif diff --git a/source/settings/menus/UninstallSM.cpp b/source/settings/menus/UninstallSM.cpp deleted file mode 100644 index 73b7c809..00000000 --- a/source/settings/menus/UninstallSM.cpp +++ /dev/null @@ -1,185 +0,0 @@ - /**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include "UninstallSM.hpp" -#include "FileOperations/fileops.h" -#include "settings/CSettings.h" -#include "settings/CGameSettings.h" -#include "settings/CGameStatistics.h" -#include "settings/GameTitles.h" -#include "prompts/PromptWindows.h" -#include "language/gettext.h" -#include "usbloader/wbfs.h" -#include "usbloader/GameList.h" -#include "wstring.hpp" - -extern int mountMethod; - -UninstallSM::UninstallSM(struct discHdr * header) - : SettingsMenu(tr("Uninstall Menu"), &GuiOptions, MENU_NONE) -{ - DiscHeader = header; - - int Idx = 0; - - Options->SetName(Idx++, "%s", tr( "Uninstall Game" )); - Options->SetName(Idx++, "%s", tr( "Reset Playcounter" )); - Options->SetName(Idx++, "%s", tr( "Delete Cover Artwork" )); - Options->SetName(Idx++, "%s", tr( "Delete Disc Artwork" )); - Options->SetName(Idx++, "%s", tr( "Delete Cheat TXT" )); - Options->SetName(Idx++, "%s", tr( "Delete Cheat GCT" )); - - SetOptionValues(); -} - -void UninstallSM::SetOptionValues() -{ - int Idx = 0; - - //! Settings: Uninstall Game - Options->SetValue(Idx++, " "); - - //! Settings: Reset Playcounter - Options->SetValue(Idx++, " "); - - //! Settings: Delete Cover Artwork - Options->SetValue(Idx++, " "); - - //! Settings: Delete Disc Artwork - Options->SetValue(Idx++, " "); - - //! Settings: Delete Cheat TXT - Options->SetValue(Idx++, " "); - - //! Settings: Delete Cheat GCT - Options->SetValue(Idx++, " "); -} - -int UninstallSM::GetMenuInternal() -{ - int ret = optionBrowser->GetClickedOption(); - - if (ret < 0) - return MENU_NONE; - - int Idx = -1; - - //! Settings: Uninstall Game - if (ret == ++Idx) - { - int choice = WindowPrompt(tr( "Do you really want to delete:" ), GameTitles.GetTitle(DiscHeader), tr( "Yes" ), tr( "Cancel" )); - if (choice == 1) - { - std::string Title = GameTitles.GetTitle(DiscHeader); - GameSettings.Remove(DiscHeader->id); - GameSettings.Save(); - GameStatistics.Remove(DiscHeader->id); - GameStatistics.Save(); - int ret = 0; - if(!mountMethod) - ret = WBFS_RemoveGame(DiscHeader->id); - - if(ret >= 0) - { - wString oldFilter(gameList.GetCurrentFilter()); - gameList.ReadGameList(); - gameList.FilterList(oldFilter.c_str()); - } - - if (ret < 0) - WindowPrompt(tr( "Can't delete:" ), Title.c_str(), tr( "OK" )); - else - WindowPrompt(tr( "Successfully deleted:" ), Title.c_str(), tr( "OK" )); - - return MENU_DISCLIST; - } - } - - //! Settings: Reset Playcounter - else if (ret == ++Idx) - { - int result = WindowPrompt(tr( "Are you sure?" ), 0, tr( "Yes" ), tr( "Cancel" )); - if (result == 1) - { - GameStatistics.SetPlayCount(DiscHeader->id, 0); - GameStatistics.Save(); - } - } - - //! Settings: Delete Cover Artwork - else if (ret == ++Idx) - { - char GameID[7]; - snprintf(GameID, sizeof(GameID), "%s", (char *) DiscHeader->id); - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s%s.png", Settings.covers_path, GameID); - - int choice = WindowPrompt(tr( "Delete" ), filepath, tr( "Yes" ), tr( "No" )); - if (choice == 1) - if (CheckFile(filepath)) remove(filepath); - } - - //! Settings: Delete Disc Artwork - else if (ret == ++Idx) - { - char GameID[7]; - snprintf(GameID, sizeof(GameID), "%s", (char *) DiscHeader->id); - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s%s.png", Settings.disc_path, GameID); - - int choice = WindowPrompt(tr( "Delete" ), filepath, tr( "Yes" ), tr( "No" )); - if (choice == 1) - if (CheckFile(filepath)) remove(filepath); - } - - //! Settings: Delete Cheat TXT - else if (ret == ++Idx) - { - char GameID[7]; - snprintf(GameID, sizeof(GameID), "%s", (char *) DiscHeader->id); - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s%s.txt", Settings.TxtCheatcodespath, GameID); - - int choice = WindowPrompt(tr( "Delete" ), filepath, tr( "Yes" ), tr( "No" )); - if (choice == 1) - if (CheckFile(filepath)) remove(filepath); - } - - //! Settings: Delete Cheat GCT - else if (ret == ++Idx) - { - char GameID[7]; - snprintf(GameID, sizeof(GameID), "%s", (char *) DiscHeader->id); - char filepath[200]; - snprintf(filepath, sizeof(filepath), "%s%s.gct", Settings.Cheatcodespath, GameID); - - int choice = WindowPrompt(tr( "Delete" ), filepath, tr( "Yes" ), tr( "No" )); - if (choice == 1) - if (CheckFile(filepath)) remove(filepath); - } - - SetOptionValues(); - - return MENU_NONE; -} diff --git a/source/settings/menus/UninstallSM.hpp b/source/settings/menus/UninstallSM.hpp deleted file mode 100644 index e639f589..00000000 --- a/source/settings/menus/UninstallSM.hpp +++ /dev/null @@ -1,44 +0,0 @@ - /**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef UNINSTALL_MENU_HPP_ -#define UNINSTALL_MENU_HPP_ - -#include "SettingsMenu.hpp" - -class UninstallSM : public SettingsMenu -{ - public: - UninstallSM(struct discHdr * header); - virtual int GetType() { return CUninstallSM; }; - protected: - void SetOptionValues(); - int GetMenuInternal(); - - struct discHdr * DiscHeader; - - OptionList GuiOptions; -}; - - -#endif diff --git a/source/settings/newtitles.cpp b/source/settings/newtitles.cpp deleted file mode 100644 index 2d2c5667..00000000 --- a/source/settings/newtitles.cpp +++ /dev/null @@ -1,209 +0,0 @@ -#include -#include - -#include "CSettings.h" -#include "settings/CGameStatistics.h" -#include "newtitles.h" - -#define NEW_SECONDS 24 * 60 * 60 -#define GAMETITLES "gametitles.txt" - -NewTitles *NewTitles::instance = NULL; - -NewTitles* NewTitles::Instance() -{ - if (instance == NULL) - { - instance = new NewTitles(); - } - return instance; -} - -void NewTitles::DestroyInstance() -{ - if (instance != NULL) - { - delete instance; - instance = NULL; - } -} - -NewTitles::NewTitles() -{ - firstTitle = lastTitle = NULL; - isDirty = isNewFile = false; - - // Read the text file - char path[255]; - strcpy(path, Settings.titlestxt_path); - path[strlen(Settings.titlestxt_path) - 1] = '/'; - strcat(path, GAMETITLES); - - char line[20]; - FILE *fp = fopen(path, "r"); - if (fp != NULL) - { - while (fgets(line, sizeof(line), fp)) - { - // This is one line - if (line[0] != '#' || line[0] != ';') - { - Title *title = new Title(); - if (sscanf(line, "%6c:%ld", (u8 *) &title->titleId, &title->timestamp) == 2) - { - if (firstTitle == NULL) - { - firstTitle = title; - lastTitle = title; - } - else - { - lastTitle->next = title; - lastTitle = title; - } - } - else - { - delete title; // Invalid title entry, ignore - } - } - } - - fclose(fp); - } - else - { - isNewFile = true; - } -} - -NewTitles::~NewTitles() -{ - Save(); - - Title *t = firstTitle; - while (t != NULL) - { - Title *temp = (Title *) t->next; - delete t; - t = temp; - } - firstTitle = lastTitle = NULL; -} - -void NewTitles::CheckGame(u8 *titleid) -{ - if (titleid == NULL || strlen((char *) titleid) == 0) - { - return; - } - - Title *t = firstTitle; - while (t != NULL) - { - // Loop all titles, search for the correct titleid - if (strcmp((const char *) titleid, (const char *) t->titleId) == 0) - { - return; // Game found, which is excellent - } - t = (Title *) t->next; - } - - // Not found, add it - t = new Title(); - strncpy((char *) t->titleId, (char *) titleid, 6); - t->timestamp = time(NULL); - if (isNewFile) - { - t->timestamp -= (NEW_SECONDS + 1); // Mark all games as not new if this is a new file - } - - if (firstTitle == NULL) - { - firstTitle = t; - lastTitle = t; - } - else - { - lastTitle -> next = t; - lastTitle = t; - } - isDirty = true; -} - -bool NewTitles::IsNew(u8 *titleid) -{ - if (titleid == NULL || strlen((char *) titleid) == 0) return false; - - Title *t = firstTitle; - - while (t != NULL) - { - // Loop all titles, search for the correct titleid - if (strcmp((const char *) titleid, (const char *) t->titleId) == 0) - { - // This title is less than 24 hours old - if ((time(NULL) - t->timestamp) < NEW_SECONDS) - { - // Only count the game as new when it's never been played through GX - GameStatus *gnum = GameStatistics.GetGameStatus(titleid); - return gnum == NULL || gnum->PlayCount == 0; - } - return false; - } - t = (Title *) t->next; - } - // We should never get here, since all files should be added by now! - CheckGame(titleid); - - return !isNewFile; // If this is a new file, return false -} - -void NewTitles::Remove(u8 *titleid) -{ - if (titleid == NULL || strlen((char *) titleid) == 0) return; - - Title *t = firstTitle, *prev = NULL; - while (t != NULL) - { - if (strcmp((const char *) titleid, (const char *) t->titleId) == 0) - { - if (prev == NULL) - { - firstTitle = (Title *) t->next; - } - else - { - prev->next = t->next; - } - delete t; - isDirty = true; - - return; - } - prev = t; - t = (Title *) t->next; - } -} - -void NewTitles::Save() -{ - if (!isDirty) return; - - char path[255]; - strcpy(path, Settings.titlestxt_path); - path[strlen(Settings.titlestxt_path) - 1] = '/'; - strcat(path, GAMETITLES); - - FILE *fp = fopen(path, "w"); - if (fp != NULL) - { - Title *t = firstTitle; - while (t != NULL && strlen((char *) t->titleId) > 0) - { - fprintf(fp, "%s:%ld\n", t->titleId, t->timestamp); - t = (Title *) t->next; - } - fclose(fp); - } -} diff --git a/source/settings/newtitles.h b/source/settings/newtitles.h deleted file mode 100644 index af30b2c7..00000000 --- a/source/settings/newtitles.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _NEWTITLES_H -#define _NEWTITLES_H - -#include - -class NewTitles -{ - public: - static NewTitles *Instance(); - static void DestroyInstance(); - - void Save(); - void CheckGame(u8 *titleid); - bool IsNew(u8 *titleid); - void Remove(u8 *titleid); - private: - NewTitles(); - ~NewTitles(); - - static NewTitles *instance; - - class Title - { - public: - u8 titleId[6]; - time_t timestamp; - void *next; - }; - - Title *firstTitle; - Title *lastTitle; - bool isDirty; - bool isNewFile; -}; - -#endif //_NEWTITLES_H diff --git a/source/sounds/bg_music.ogg b/source/sounds/bg_music.ogg deleted file mode 100644 index a22a73ae..00000000 Binary files a/source/sounds/bg_music.ogg and /dev/null differ diff --git a/source/sounds/button_click.wav b/source/sounds/button_click.wav deleted file mode 100644 index b0578c50..00000000 Binary files a/source/sounds/button_click.wav and /dev/null differ diff --git a/source/sounds/button_click2.wav b/source/sounds/button_click2.wav deleted file mode 100644 index 011c0ada..00000000 Binary files a/source/sounds/button_click2.wav and /dev/null differ diff --git a/source/sounds/button_over.wav b/source/sounds/button_over.wav deleted file mode 100644 index 8a06f4b0..00000000 Binary files a/source/sounds/button_over.wav and /dev/null differ diff --git a/source/sounds/credits_music.ogg b/source/sounds/credits_music.ogg deleted file mode 100644 index 4010c41c..00000000 Binary files a/source/sounds/credits_music.ogg and /dev/null differ diff --git a/source/sounds/menuin.ogg b/source/sounds/menuin.ogg deleted file mode 100644 index 65ea7d73..00000000 Binary files a/source/sounds/menuin.ogg and /dev/null differ diff --git a/source/sounds/menuout.ogg b/source/sounds/menuout.ogg deleted file mode 100644 index 3d840b0e..00000000 Binary files a/source/sounds/menuout.ogg and /dev/null differ diff --git a/source/sounds/success.ogg b/source/sounds/success.ogg deleted file mode 100644 index bb3821e5..00000000 Binary files a/source/sounds/success.ogg and /dev/null differ diff --git a/source/svnrev.h b/source/svnrev.h deleted file mode 100644 index 6f1943e2..00000000 --- a/source/svnrev.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SVNREV_H -#define SVNREV_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - const char *GetRev(); - -#ifdef __cplusplus -} -#endif - -#endif /* SVNREV_H */ diff --git a/source/sys.cpp b/source/sys.cpp deleted file mode 100644 index 98a13ca5..00000000 --- a/source/sys.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include -#include -#include - -#include "mload/mload.h" -#include "settings/CSettings.h" -#include "settings/newtitles.h" -#include "language/gettext.h" -#include "network/networkops.h" -#include "utils/ResourceManager.h" -#include "FontSystem.h" -#include "audio.h" -#include "fatmounter.h" -#include "lstub.h" -#include "menu.h" -#include "video.h" -#include "gecko.h" -#include "xml/xml.h" - -extern char game_partition[6]; -extern u8 load_from_fs; - -//Wiilight stuff -static vu32 *_wiilight_reg = (u32*) 0xCD0000C0; -void wiilight(int enable) // Toggle wiilight (thanks Bool for wiilight source) -{ - u32 val = (*_wiilight_reg & ~0x20); - if (enable && Settings.wiilight) val |= 0x20; - *_wiilight_reg = val; -} - -/* Variables */ -u8 shutdown = 0; -u8 reset = 0; - -void __Sys_ResetCallback(void) -{ - /* Reboot console */ - reset = 1; -} - -void __Sys_PowerCallback(void) -{ - /* Poweroff console */ - shutdown = 1; -} - -void Sys_Init(void) -{ - /* Initialize video subsytem */ - //VIDEO_Init(); - - /* Set RESET/POWER button callback */ - SYS_SetResetCallback(__Sys_ResetCallback); - SYS_SetPowerCallback(__Sys_PowerCallback); -} - -void AppCleanUp(void) -{ - extern u8 mountMethod; - gprintf("Exiting main GUI. mountMethod = %d\n", mountMethod); - - Settings.Save(); - - ExitGUIThreads(); - - delete bgMusic; - delete btnSoundClick; - delete btnSoundOver; - delete btnSoundClick2; - delete background; - delete bgImg; - delete mainWindow; - for (int i = 0; i < 4; i++) - delete pointer[i]; - - gettextCleanUp(); - CloseXMLDatabase(); - ClearFontData(); - NewTitles::DestroyInstance(); - DeinitNetwork(); - - StopGX(); - ShutdownAudio(); - - ResourceManager::DestroyInstance(); - - WPAD_Flush(0); - WPAD_Disconnect(0); - WPAD_Shutdown(); -} - -void ExitApp(void) -{ - AppCleanUp(); - UnmountNTFS(); - UnmountEXT(); - SDCard_deInit(); - USBDevice_deInit(); -} - -void Sys_Reboot(void) -{ - /* Restart console */ - ExitApp(); - STM_RebootSystem(); -} - -#define ShutdownToDefault 0 -#define ShutdownToIdle 1 -#define ShutdownToStandby 2 - -static void _Sys_Shutdown(int SHUTDOWN_MODE) -{ - ExitApp(); - - /* Poweroff console */ - if ((CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE && SHUTDOWN_MODE != ShutdownToStandby) || SHUTDOWN_MODE - == ShutdownToIdle) - { - s32 ret; - - /* Set LED mode */ - ret = CONF_GetIdleLedMode(); - if (ret >= 0 && ret <= 2) STM_SetLedMode(ret); - - /* Shutdown to idle */ - STM_ShutdownToIdle(); - } - else - { - /* Shutdown to standby */ - STM_ShutdownToStandby(); - } -} - -void Sys_Shutdown(void) -{ - _Sys_Shutdown(ShutdownToDefault); -} - -void Sys_ShutdownToIdle(void) -{ - _Sys_Shutdown(ShutdownToIdle); -} -void Sys_ShutdownToStandby(void) -{ - _Sys_Shutdown(ShutdownToStandby); -} - -void Sys_LoadMenu(void) -{ - ExitApp(); - /* Return to the Wii system menu */ - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); -} - -void Sys_BackToLoader(void) -{ - ExitApp(); - - if (hbcStubAvailable()) - exit(0); - // Channel Version - Sys_LoadMenu(); -} - -void ScreenShot() -{ - time_t rawtime; - struct tm * timeinfo; - char buffer[150]; - char buffer2[300]; - - time(&rawtime); - timeinfo = localtime(&rawtime); - //USBLoader_GX_ScreenShot-Month_Day_Hour_Minute_Second_Year.png - strftime(buffer, 80, "USBLoader_GX_ScreenShot-%b%d%H%M%S%y.png", timeinfo); - sprintf(buffer2, "%s%s", Settings.ConfigPath, buffer); - - TakeScreenshot(buffer2); -} diff --git a/source/sys.h b/source/sys.h deleted file mode 100644 index 572c22ae..00000000 --- a/source/sys.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _SYS_H_ -#define _SYS_H_ - -void wiilight(int enable); - -/* Prototypes */ -void AppCleanUp(void); //! Deletes all allocated space for everything -void ExitApp(void); //! Like AppCleanUp() and additional device unmount -void Sys_Init(void); -void Sys_Reboot(void); -void Sys_Shutdown(void); -void Sys_ShutdownToIdle(void); -void Sys_ShutdownToStandby(void); -void Sys_LoadMenu(void); -void Sys_BackToLoader(void); -void ScreenShot(); - -#endif diff --git a/source/system/IosLoader.cpp b/source/system/IosLoader.cpp deleted file mode 100644 index 6d886ee1..00000000 --- a/source/system/IosLoader.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include - -#include "IosLoader.h" -#include "../fatmounter.h" -#include "../usbloader/usbstorage2.h" -#include "../usbloader/disc.h" -#include "../usbloader/wbfs.h" -#include "../usbloader/wdvd.h" -#include "../wad/nandtitle.h" -#include "../mload/mload_modules.h" -#include "../settings/CSettings.h" -#include "wad/nandtitle.h" -#include "mload/mload.h" -#include "mload/modules/ehcmodule_5.h" -#include "mload/modules/dip_plugin_249.h" -#include "mload/modules/odip_frag.h" -#include "gecko.h" - - -/****************************************************************************** - * Public Methods: - ******************************************************************************/ -/* - * Check if the ios passed is a Hermes ios. - */ -bool IosLoader::IsHermesIOS(s32 ios) -{ - return (ios == 222 || ios == 223 || ios == 224 || ios == 202); -} - -/* - * Check if the ios passed is a Waninkoko ios. - */ -bool IosLoader::IsWaninkokoIOS(s32 ios) -{ - if(ios < 200 || ios > 255) - return false; - - return !IsHermesIOS(ios); -} - -/* - * Loads CIOS (If possible the one from the settings file). - * @return 0 if a cios has been successfully loaded. Else a value below 0 is returned. - */ -s32 IosLoader::LoadAppCios() -{ - u32 activeCios = IOS_GetVersion(); - s32 ret = -1; - - // We have what we need - if((int) activeCios == Settings.cios) - return 0; - - // Unmount fat before reloading IOS. - SDCard_deInit(); - USBDevice_deInit(); - - u32 ciosLoadPriority[] = { 250, 249, 222, Settings.cios }; // Descending. - - - for (u8 i = (sizeof(ciosLoadPriority)/sizeof(ciosLoadPriority[0]))-1; i >= 0; i--) - { - u32 cios = ciosLoadPriority[i]; - - if (activeCios == cios) - { - ret = 0; - break; - } - - if ((ret = ReloadIosSafe(cios)) > -1) - { - // Remember working cios. - Settings.cios = cios; - break; - } - } - - return ret; -} - - -/* - * Loads a CIOS before a game start. - * @return 0 if a cios has been successfully loaded. Else a value below 0 is returned. - */ -s32 IosLoader::LoadGameCios(s32 ios) -{ - if(ios == IOS_GetVersion()) - return 0; - - s32 ret = -1; - - // Unmount fat before reloading IOS. - WBFS_Close(); - WDVD_Close(); - SDCard_deInit(); - USBDevice_deInit(); - - ret = ReloadIosSafe(ios); - - // Remount devices after reloading IOS. - SDCard_Init(); - USBDevice_Init_Loop(); - Disc_Init(); - - return ret; -} - -/* - * Reloads a certain IOS under the condition, that an appropriate version of the IOS is installed. - * @return a negative value if a safe reload of the ios was not possible. - */ -s32 IosLoader::ReloadIosSafe(s32 ios) -{ - if(IsHermesIOS(ios)) - { - s32 iosRev = NandTitles.VersionOf(TITLE_ID(1, ios)); - if((iosRev < 4 || iosRev > 6) && iosRev != 65535) - return -11; - } - else if(IsWaninkokoIOS(ios)) - { - s32 iosRev = NandTitles.VersionOf(TITLE_ID(1, ios)); - if((iosRev < 9 || iosRev > 30) && iosRev != 65535) //let's see if Waninkoko actually gets to 30 - return -22; - } - else - { - return -33; - } - - s32 r = IOS_ReloadIOS(ios); - if (r >= 0) WII_Initialize(); - - IosLoader::LoadIOSModules(IOS_GetVersion(), IOS_GetRevision()); - - return r; -} - -/****************************************************************************** - * Private/Protected Methods: - ******************************************************************************/ -void IosLoader::LoadIOSModules(s32 ios, s32 ios_rev) -{ - //! Hermes IOS - if(IsHermesIOS(ios)) - { - const u8 * ech_module = NULL; - int ehc_module_size = 0; - const u8 * dip_plugin = NULL; - int dip_plugin_size = 0; - - ech_module = ehcmodule_5; - ehc_module_size = ehcmodule_5_size; - dip_plugin = odip_frag; - dip_plugin_size = odip_frag_size; - gprintf("Loading ehc v5 and opendip module\n"); - - u8 *ehc_cfg = search_for_ehcmodule_cfg((u8 *) ech_module, ehc_module_size); - if (ehc_cfg) - { - ehc_cfg += 12; - ehc_cfg[0] = 0; // USB Port 0 - gprintf("Patched ehc module to use usb port 0.\n"); - } - - load_modules(ech_module, ehc_module_size, dip_plugin, dip_plugin_size); - } - //! Waninkoko IOS - else if(IsWaninkokoIOS(ios)) - { - if(ios_rev >= 18) - { - if(mload_init() < 0) - return; - - gprintf("Loading dip module for Waninkoko's cios\n"); - mload_module((u8 *) dip_plugin_249, dip_plugin_249_size); - mload_close(); - } - } -} diff --git a/source/system/IosLoader.h b/source/system/IosLoader.h deleted file mode 100644 index b00b04ef..00000000 --- a/source/system/IosLoader.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _IOSLOADER_H_ -#define _IOSLOADER_H_ - -#include - -class IosLoader -{ - public: - static s32 LoadAppCios(); - static s32 LoadGameCios(s32 ios); - static s32 ReloadIosSafe(s32 ios); - static bool IsHermesIOS(s32 ios = IOS_GetVersion()); - static bool IsWaninkokoIOS(s32 ios = IOS_GetVersion()); - private: - static void LoadIOSModules(s32 ios, s32 ios_rev); -}; - -#endif diff --git a/source/themes/CTheme.cpp b/source/themes/CTheme.cpp deleted file mode 100644 index 1914c343..00000000 --- a/source/themes/CTheme.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include - -#include "CTheme.h" -#include "libwiigui/gui.h" - -bool Theme::ShowTooltips = true; - -void Theme::SetDefault() -{ - Theme::ShowTooltips = true; - ThemeCleanUp(); - Resources::Clear(); -} - -bool Theme::Load(const char * theme_file_path) -{ - bool result = LoadTheme(theme_file_path); - if(!result) - return result; - - Theme::ShowTooltips = (thInt("1 - Enable tooltips: 0 for off and 1 for on") != 0); - - char theme_path[300]; - snprintf(theme_path, sizeof(theme_path), theme_file_path); - - char * ptr = strrchr(theme_path, '/'); - if(ptr) *ptr = '\0'; - - FILE * file = fopen(theme_file_path, "rb"); - if(!file) - return false; - - char line[300]; - char * Foldername = NULL; - - while (fgets(line, sizeof(line), file)) - { - char * ptr = strcasestr(line, "Image-Folder:"); - if(!ptr) - continue; - - ptr += strlen("Image-Folder:"); - - while(*ptr != '\0' && *ptr == ' ') ptr++; - - Foldername = ptr; - - while(*ptr != '\\' && *ptr != '"' && *ptr != '\0') ptr++; - - *ptr = '\0'; - break; - } - - fclose(file); - - if(!Foldername) - return result; - - snprintf(theme_path, sizeof(theme_path), "%s/%s", theme_path, Foldername); - Resources::LoadFiles(theme_path); - - return result; -} diff --git a/source/themes/CTheme.h b/source/themes/CTheme.h deleted file mode 100644 index 86a3c48b..00000000 --- a/source/themes/CTheme.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _THEME_H_ -#define _THEME_H_ - -#include -#include -#include -#include "Resources.h" -#include "gettheme.h" - -class Theme -{ - public: - //!Set Default - static void SetDefault(); - //!Load - static bool Load(const char * path); - //!Enable tooltips: special case treaded because it is called every frame - static bool ShowTooltips; -}; - -#endif diff --git a/source/themes/Resources.cpp b/source/themes/Resources.cpp deleted file mode 100644 index 3a39af68..00000000 --- a/source/themes/Resources.cpp +++ /dev/null @@ -1,258 +0,0 @@ -#include -#include -#include "FileOperations/fileops.h" -#include "filelist.h" -#include "Resources.h" - -RecourceFile Resources::RecourceFiles[] = -{ - {"closebutton.png", closebutton_png, closebutton_png_size, NULL, 0}, - {"gxlogo.png", gxlogo_png, gxlogo_png_size, NULL, 0}, - {"sdcard.png", sdcard_png, sdcard_png_size, NULL, 0}, - {"sdcard_over.png", sdcard_over_png, sdcard_over_png_size, NULL, 0}, - {"Wifi_btn.png", Wifi_btn_png, Wifi_btn_png_size, NULL, 0}, - {"wiimote.png", wiimote_png, wiimote_png_size, NULL, 0}, - {"gameinfo1.png", gameinfo1_png, gameinfo1_png_size, NULL, 0}, - {"gameinfo2.png", gameinfo2_png, gameinfo2_png_size, NULL, 0}, - {"gameinfo1a.png", gameinfo1a_png, gameinfo1a_png_size, NULL, 0}, - {"gameinfo2a.png", gameinfo2a_png, gameinfo2a_png_size, NULL, 0}, - {"credits_button.png", credits_button_png, credits_button_png_size, NULL, 0}, - {"credits_button_over.png", credits_button_over_png, credits_button_over_png_size, NULL, 0}, - {"tooltip_left.png", tooltip_left_png, tooltip_left_png_size, NULL, 0}, - {"tooltip_tile.png", tooltip_tile_png, tooltip_tile_png_size, NULL, 0}, - {"tooltip_right.png", tooltip_right_png, tooltip_right_png_size, NULL, 0}, - {"startgame_arrow_left.png", startgame_arrow_left_png, startgame_arrow_left_png_size, NULL, 0}, - {"startgame_arrow_right.png", startgame_arrow_right_png, startgame_arrow_right_png_size, NULL, 0}, - {"credits_bg.png", credits_bg_png, credits_bg_png_size, NULL, 0}, - {"little_star.png", little_star_png, little_star_png_size, NULL, 0}, - {"background.png", background_png, background_png_size, NULL, 0}, - {"wbackground.png", wbackground_png, wbackground_png_size, NULL, 0}, - {"bg_options_settings.png", bg_options_settings_png, bg_options_settings_png_size, NULL, 0}, - {"settings_background.png", settings_background_png, settings_background_png_size, NULL, 0}, - {"bg_browser.png", bg_browser_png, bg_browser_png_size, NULL, 0}, - {"icon_folder.png", icon_folder_png, icon_folder_png_size, NULL, 0}, - {"bg_browser_selection.png", bg_browser_selection_png, bg_browser_selection_png_size, NULL, 0}, - {"addressbar_textbox.png", addressbar_textbox_png, addressbar_textbox_png_size, NULL, 0}, - {"browser.png", browser_png, browser_png_size, NULL, 0}, - {"browser_over.png", browser_over_png, browser_over_png_size, NULL, 0}, - {"nocover.png", nocover_png, nocover_png_size, NULL, 0}, - {"nocoverFlat.png", nocoverFlat_png, nocoverFlat_png_size, NULL, 0}, - {"nodisc.png", nodisc_png, nodisc_png_size, NULL, 0}, - {"theme_dialogue_box.png", theme_dialogue_box_png, theme_dialogue_box_png_size, NULL, 0}, - {"button_install.png", button_install_png, button_install_png_size, NULL, 0}, - {"button_install_over.png", button_install_over_png, button_install_over_png_size, NULL, 0}, - {"dialogue_box_startgame.png", dialogue_box_startgame_png, dialogue_box_startgame_png_size, NULL, 0}, - {"wdialogue_box_startgame.png", wdialogue_box_startgame_png, wdialogue_box_startgame_png_size, NULL, 0}, - {"button_dialogue_box.png", button_dialogue_box_png, button_dialogue_box_png_size, NULL, 0}, - {"keyboard_textbox.png", keyboard_textbox_png, keyboard_textbox_png_size, NULL, 0}, - {"keyboard_key.png", keyboard_key_png, keyboard_key_png_size, NULL, 0}, - {"keyboard_key_over.png", keyboard_key_over_png, keyboard_key_over_png_size, NULL, 0}, - {"keyboard_mediumkey_over.png", keyboard_mediumkey_over_png, keyboard_mediumkey_over_png_size, NULL, 0}, - {"keyboard_largekey_over.png", keyboard_largekey_over_png, keyboard_largekey_over_png_size, NULL, 0}, - {"keyboard_backspace_over.png", keyboard_backspace_over_png, keyboard_backspace_over_png_size, NULL, 0}, - {"keyboard_clear_over.png", keyboard_clear_over_png, keyboard_clear_over_png_size, NULL, 0}, - {"menu_button.png", menu_button_png, menu_button_png_size, NULL, 0}, - {"menu_button_over.png", menu_button_over_png, menu_button_over_png_size, NULL, 0}, - {"settings_button.png", settings_button_png, settings_button_png_size, NULL, 0}, - {"settings_button_over.png", settings_button_over_png, settings_button_over_png_size, NULL, 0}, - {"settings_menu_button.png", settings_menu_button_png, settings_menu_button_png_size, NULL, 0}, - {"wiimote_poweroff.png", wiimote_poweroff_png, wiimote_poweroff_png_size, NULL, 0}, - {"dialogue_box.png", dialogue_box_png, dialogue_box_png_size, NULL, 0}, - {"theme_box.png", theme_box_png, theme_box_png_size, NULL, 0}, - {"wiimote_poweroff_over.png", wiimote_poweroff_over_png, wiimote_poweroff_over_png_size, NULL, 0}, - {"bg_options.png", bg_options_png, bg_options_png_size, NULL, 0}, - {"bg_options_entry.png", bg_options_entry_png, bg_options_entry_png_size, NULL, 0}, - {"scrollbar.png", scrollbar_png, scrollbar_png_size, NULL, 0}, - {"scrollbar_arrowup.png", scrollbar_arrowup_png, scrollbar_arrowup_png_size, NULL, 0}, - {"scrollbar_arrowdown.png", scrollbar_arrowdown_png, scrollbar_arrowdown_png_size, NULL, 0}, - {"scrollbar_box.png", scrollbar_box_png, scrollbar_box_png_size, NULL, 0}, - {"progressbar.png", progressbar_png, progressbar_png_size, NULL, 0}, - {"progressbar_empty.png", progressbar_empty_png, progressbar_empty_png_size, NULL, 0}, - {"progressbar_outline.png", progressbar_outline_png, progressbar_outline_png_size, NULL, 0}, - {"player1_point.png", player1_point_png, player1_point_png_size, NULL, 0}, - {"player2_point.png", player2_point_png, player2_point_png_size, NULL, 0}, - {"player3_point.png", player3_point_png, player3_point_png_size, NULL, 0}, - {"player4_point.png", player4_point_png, player4_point_png_size, NULL, 0}, - {"rplayer1_point.png", rplayer1_point_png, rplayer1_point_png_size, NULL, 0}, - {"rplayer2_point.png", rplayer2_point_png, rplayer2_point_png_size, NULL, 0}, - {"rplayer3_point.png", rplayer3_point_png, rplayer3_point_png_size, NULL, 0}, - {"rplayer4_point.png", rplayer4_point_png, rplayer4_point_png_size, NULL, 0}, - {"battery.png", battery_png, battery_png_size, NULL, 0}, - {"battery_bar.png", battery_bar_png, battery_bar_png_size, NULL, 0}, - {"battery_white.png", battery_white_png, battery_white_png_size, NULL, 0}, - {"battery_red.png", battery_red_png, battery_red_png_size, NULL, 0}, - {"battery_bar_white.png", battery_bar_white_png, battery_bar_white_png_size, NULL, 0}, - {"battery_bar_red.png", battery_bar_red_png, battery_bar_red_png_size, NULL, 0}, - {"arrow_next.png", arrow_next_png, arrow_next_png_size, NULL, 0}, - {"arrow_previous.png", arrow_previous_png, arrow_previous_png_size, NULL, 0}, - {"mp3_pause.png", mp3_pause_png, mp3_pause_png_size, NULL, 0}, - {"mp3_stop.png", mp3_stop_png, mp3_stop_png_size, NULL, 0}, - {"exit_top.png", exit_top_png, exit_top_png_size, NULL, 0}, - {"exit_top_over.png", exit_top_over_png, exit_top_over_png_size, NULL, 0}, - {"exit_bottom.png", exit_bottom_png, exit_bottom_png_size, NULL, 0}, - {"exit_bottom_over.png", exit_bottom_over_png, exit_bottom_over_png_size, NULL, 0}, - {"exit_button.png", exit_button_png, exit_button_png_size, NULL, 0}, - {"favorite.png", favorite_png, favorite_png_size, NULL, 0}, - {"not_favorite.png", not_favorite_png, not_favorite_png_size, NULL, 0}, - {"favIcon.png", favIcon_png, favIcon_png_size, NULL, 0}, - {"favIcon_gray.png", favIcon_gray_png, favIcon_gray_png_size, NULL, 0}, - {"searchIcon.png", searchIcon_png, searchIcon_png_size, NULL, 0}, - {"searchIcon_gray.png", searchIcon_gray_png, searchIcon_gray_png_size, NULL, 0}, - {"abcIcon.png", abcIcon_png, abcIcon_png_size, NULL, 0}, - {"rankIcon.png", rankIcon_png, rankIcon_png_size, NULL, 0}, - {"playCountIcon.png", playCountIcon_png, playCountIcon_png_size, NULL, 0}, - {"arrangeList.png", arrangeList_png, arrangeList_png_size, NULL, 0}, - {"arrangeList_gray.png", arrangeList_gray_png, arrangeList_gray_png_size, NULL, 0}, - {"arrangeGrid.png", arrangeGrid_png, arrangeGrid_png_size, NULL, 0}, - {"arrangeGrid_gray.png", arrangeGrid_gray_png, arrangeGrid_gray_png_size, NULL, 0}, - {"arrangeCarousel.png", arrangeCarousel_png, arrangeCarousel_png_size, NULL, 0}, - {"arrangeCarousel_gray.png", arrangeCarousel_gray_png, arrangeCarousel_gray_png_size, NULL, 0}, - {"settings_title.png", settings_title_png, settings_title_png_size, NULL, 0}, - {"settings_title_over.png", settings_title_over_png, settings_title_over_png_size, NULL, 0}, - {"pageindicator.png", pageindicator_png, pageindicator_png_size, NULL, 0}, - {"Wiimote1.png", Wiimote1_png, Wiimote1_png_size, NULL, 0}, - {"Wiimote2.png", Wiimote2_png, Wiimote1_png_size, NULL, 0}, - {"Wiimote4.png", Wiimote4_png, Wiimote4_png_size, NULL, 0}, - {"wifi1.png", wifi1_png, wifi1_png_size, NULL, 0}, - {"wifi2.png", wifi2_png, wifi2_png_size, NULL, 0}, - {"wifi3.png", wifi3_png, wifi3_png_size, NULL, 0}, - {"wifi4.png", wifi4_png, wifi4_png_size, NULL, 0}, - {"wifi8.png", wifi8_png, wifi8_png_size, NULL, 0}, - {"wifi12.png", wifi12_png, wifi12_png_size, NULL, 0}, - {"wifi16.png", wifi16_png, wifi16_png_size, NULL, 0}, - {"wifi32.png", wifi32_png, wifi32_png_size, NULL, 0}, - {"norating.png", norating_png, norating_png_size, NULL, 0}, - {"guitar.png", guitar_png, guitar_png_size, NULL, 0}, - {"guitarR.png", guitarR_png, guitarR_png_size, NULL, 0}, - {"microphone.png", microphone_png, microphone_png_size, NULL, 0}, - {"microphoneR.png", microphoneR_png, microphoneR_png_size, NULL, 0}, - {"gcncontroller.png", gcncontroller_png, gcncontroller_png_size, NULL, 0}, - {"gcncontrollerR.png", gcncontrollerR_png, gcncontrollerR_png_size, NULL, 0}, - {"classiccontroller.png", classiccontroller_png, classiccontroller_png_size, NULL, 0}, - {"classiccontrollerR.png", classiccontrollerR_png, classiccontrollerR_png_size, NULL, 0}, - {"nunchuk.png", nunchuk_png, nunchuk_png_size, NULL, 0}, - {"nunchukR.png", nunchukR_png, nunchukR_png_size, NULL, 0}, - {"dancepad.png", dancepad_png, dancepad_png_size, NULL, 0}, - {"dancepadR.png", dancepadR_png, dancepadR_png_size, NULL, 0}, - {"balanceboard.png", balanceboard_png, balanceboard_png_size, NULL, 0}, - {"balanceboardR.png", balanceboardR_png, balanceboardR_png_size, NULL, 0}, - {"drums.png", drums_png, drums_png_size, NULL, 0}, - {"drumsR.png", drumsR_png, drumsR_png_size, NULL, 0}, - {"motionplus.png", motionplus_png, motionplus_png_size, NULL, 0}, - {"motionplusR.png", motionplusR_png, motionplusR_png_size, NULL, 0}, - {"wheel.png", wheel_png, wheel_png_size, NULL, 0}, - {"wheelR.png", wheelR_png, wheelR_png_size, NULL, 0}, - {"zapper.png", zapper_png, zapper_png_size, NULL, 0}, - {"zapperR.png", zapperR_png, zapperR_png_size, NULL, 0}, - {"wiispeak.png", wiispeak_png, wiispeak_png_size, NULL, 0}, - {"wiispeakR.png", wiispeakR_png, wiispeakR_png_size, NULL, 0}, - {"nintendods.png", nintendods_png, nintendods_png_size, NULL, 0}, - {"nintendodsR.png", nintendodsR_png, nintendodsR_png_size, NULL, 0}, - {"esrb_ec.png", esrb_ec_png, esrb_ec_png_size, NULL, 0}, - {"esrb_e.png", esrb_e_png, esrb_e_png_size, NULL, 0}, - {"esrb_eten.png", esrb_eten_png, esrb_eten_png_size, NULL, 0}, - {"esrb_t.png", esrb_t_png, esrb_t_png_size, NULL, 0}, - {"esrb_m.png", esrb_m_png, esrb_m_png_size, NULL, 0}, - {"esrb_ao.png", esrb_ao_png, esrb_ao_png_size, NULL, 0}, - {"cero_a.png", cero_a_png, cero_a_png_size, NULL, 0}, - {"cero_b.png", cero_b_png, cero_b_png_size, NULL, 0}, - {"cero_c.png", cero_c_png, cero_c_png_size, NULL, 0}, - {"cero_d.png", cero_d_png, cero_d_png_size, NULL, 0}, - {"cero_z.png", cero_z_png, cero_z_png_size, NULL, 0}, - {"pegi_3.png", pegi_3_png, pegi_3_png_size, NULL, 0}, - {"pegi_7.png", pegi_7_png, pegi_7_png_size, NULL, 0}, - {"pegi_12.png", pegi_12_png, pegi_12_png_size, NULL, 0}, - {"pegi_16.png", pegi_16_png, pegi_16_png_size, NULL, 0}, - {"pegi_18.png", pegi_18_png, pegi_18_png_size, NULL, 0}, - {"dvd.png", dvd_png, dvd_png_size, NULL, 0}, - {"dvd_gray.png", dvd_gray_png, dvd_gray_png_size, NULL, 0}, - {"new.png", new_png, new_png_size, NULL, 0}, - {"lock.png", lock_png, lock_png_size, NULL, 0}, - {"lock_gray.png", lock_gray_png, lock_gray_png_size, NULL, 0}, - {"unlock.png", unlock_png, unlock_png_size, NULL, 0}, - {"unlock_gray.png", unlock_gray_png, unlock_gray_png_size, NULL, 0}, - {"Channel_btn.png", Channel_btn_png, Channel_btn_png_size, NULL, 0}, - {NULL, NULL, 0, NULL, 0} -}; - -void Resources::Clear() -{ - for(int i = 0; RecourceFiles[i].filename != NULL; ++i) - { - if(RecourceFiles[i].CustomFile) - { - free(RecourceFiles[i].CustomFile); - RecourceFiles[i].CustomFile = NULL; - } - - if(RecourceFiles[i].CustomFileSize != 0) - RecourceFiles[i].CustomFileSize = 0; - } -} - -void Resources::LoadFiles(const char * path) -{ - if(!path) - return; - - Clear(); - - char fullpath[1024]; - - for(int i = 0; RecourceFiles[i].filename != NULL; ++i) - { - snprintf(fullpath, sizeof(fullpath), "%s/%s", path, RecourceFiles[i].filename); - - if(CheckFile(fullpath)) - { - u8 * buffer = NULL; - u64 filesize = 0; - - LoadFileToMem(fullpath, &buffer, &filesize); - - RecourceFiles[i].CustomFile = buffer; - RecourceFiles[i].CustomFileSize = (u32) filesize; - } - } -} - -const u8 * Resources::GetFile(const char * filename) -{ - for(int i = 0; RecourceFiles[i].filename != NULL; ++i) - { - if(strcasecmp(filename, RecourceFiles[i].filename) == 0) - { - return (RecourceFiles[i].CustomFile ? RecourceFiles[i].CustomFile : RecourceFiles[i].DefaultFile); - } - } - - return NULL; -} - -const u32 Resources::GetFileSize(const char * filename) -{ - for(int i = 0; RecourceFiles[i].filename != NULL; ++i) - { - if(strcasecmp(filename, RecourceFiles[i].filename) == 0) - { - return (RecourceFiles[i].CustomFile ? RecourceFiles[i].CustomFileSize : RecourceFiles[i].DefaultFileSize); - } - } - - return 0; -} - -GuiImageData * Resources::GetImageData(const char * filename) -{ - for(int i = 0; RecourceFiles[i].filename != NULL; ++i) - { - if(strcasecmp(filename, RecourceFiles[i].filename) == 0) - { - const u8 * buff = RecourceFiles[i].CustomFile ? RecourceFiles[i].CustomFile : RecourceFiles[i].DefaultFile; - const u32 size = RecourceFiles[i].CustomFile ? RecourceFiles[i].CustomFileSize : RecourceFiles[i].DefaultFileSize; - return (new GuiImageData(buff, size)); - } - } - - return NULL; -} diff --git a/source/themes/Resources.h b/source/themes/Resources.h deleted file mode 100644 index 49cf8ee4..00000000 --- a/source/themes/Resources.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef RECOURCES_H_ -#define RECOURCES_H_ - -#include "libwiigui/gui_imagedata.h" -#include "filelist.h" - -typedef struct _RecourceFile -{ - const char *filename; - const u8 *DefaultFile; - const u32 DefaultFileSize; - u8 *CustomFile; - u32 CustomFileSize; -} RecourceFile; - -class Resources -{ - public: - static void Clear(); - static void LoadFiles(const char * path); - static const u8 * GetFile(const char * filename); - static const u32 GetFileSize(const char * filename); - static GuiImageData * GetImageData(const char * filename); - - private: - static RecourceFile RecourceFiles[]; -}; - -#endif diff --git a/source/themes/Theme_Downloader.cpp b/source/themes/Theme_Downloader.cpp deleted file mode 100644 index 20a3e0cd..00000000 --- a/source/themes/Theme_Downloader.cpp +++ /dev/null @@ -1,627 +0,0 @@ -/**************************************************************************** - * Theme_Downloader - * USB Loader GX 2009 - * - * Theme downloader for USB Loader GX - * - * Theme_Downloader.cpp - ***************************************************************************/ -#include -#include - -#include "language/gettext.h" -#include "libwiigui/gui.h" -#include "prompts/PromptWindows.h" -#include "prompts/ProgressWindow.h" -#include "homebrewboot/HomebrewBrowse.h" -#include "network/networkops.h" -#include "themes/Theme_List.h" -#include "themes/CTheme.h" -#include "menu.h" -#include "filelist.h" -#include "FileOperations/fileops.h" -#include "sys.h" -#include "network/http.h" -#include "ZipFile.h" -#include "gecko.h" - -/*** Extern variables ***/ -extern u8 shutdown; -extern u8 reset; -extern int connection; - -int DownloadTheme(const char *url, const char *title) -{ - if (!url) return 0; - - char filename[255]; - memset(filename, 0, sizeof(filename)); - - int filesize = download_request(url, (char *) &filename); - - if (filesize <= 0) - { - WindowPrompt(tr( "Download request failed." ), 0, tr( "OK" )); - return 0; - } - - char path[300]; - char filepath[300]; - - snprintf(path, sizeof(path), "%s%s", Settings.theme_downloadpath, title); - - CreateSubfolder(path); - - snprintf(filepath, sizeof(filepath), "%s/%s", path, filename); - - FILE *file = fopen(filepath, "wb"); - if (!file) - { - WindowPrompt(tr( "Download failed." ), tr( "Can't create file" ), tr( "OK" )); - return 0; - } - - u32 done = 0; - - int blocksize = 1024 * 5; - - u8 *buffer = new u8[blocksize]; - - while (done < (u32) filesize) - { - if ((u32) blocksize > filesize - done) blocksize = filesize - done; - - ShowProgress(tr( "Downloading file" ), 0, (char*) filename, done, filesize, true); - - int ret = network_read(connection, buffer, blocksize); - if (ret < 0) - { - free(buffer); - fclose(file); - remove(path); - ProgressStop(); - WindowPrompt(tr( "Download failed." ), tr( "Transfer failed." ), tr( "OK" )); - return 0; - } - else if (ret == 0) break; - - fwrite(buffer, 1, blocksize, file); - - done += ret; - } - - delete[] buffer; - fclose(file); - - ProgressStop(); - - if (done != (u32) filesize) - { - remove(filepath); - WindowPrompt(tr( "Download failed." ), tr( "Connection lost..." ), tr( "OK" )); - return 0; - } - - ZipFile zipfile(filepath); - - int result = zipfile.ExtractAll(path); - if (result) - { - remove(filepath); - int choice = WindowPrompt(tr( "Successfully extracted theme." ), tr( "Do you want to apply it now?" ), - tr( "Yes" ), tr( "No" )); - if (choice) - { - char real_themepath[1024]; - sprintf(real_themepath, "%s", Settings.theme_path); - if (SearchFile(path, "GXtheme.cfg", real_themepath) == true) - { - char *ptr = strrchr(real_themepath, '/'); - if (ptr) - { - ptr++; - ptr[0] = '\0'; - } - snprintf(Settings.theme_path, sizeof(Settings.theme_path), "%s", real_themepath); - Settings.Save(); - Settings.Load(); - result = 2; - } - else WindowPrompt(tr( "ERROR: Can't set up theme." ), tr( "GXtheme.cfg not found in any subfolder." ), - tr( "OK" )); - } - } - else WindowPrompt(tr( "Failed to extract." ), tr( "Unsupported format, try to extract manually." ), tr( "OK" )); - - return result; -} - -static int Theme_Prompt(const char *title, const char *author, GuiImageData *thumbimageData, const char *downloadlink) -{ - gprintf("\nTheme_Prompt(%s ,%s, , %s)", title, author, downloadlink); - bool leave = false; - int result = 0; - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("theme_dialogue_box.png"), Resources::GetFileSize("theme_dialogue_box.png")); - - GuiImage dialogBoxImg(&dialogBox); - - GuiWindow promptWindow(dialogBox.GetWidth(), dialogBox.GetHeight()); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - - GuiText titleTxt(tr( "Theme Title:" ), 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - titleTxt.SetPosition(230, 30); - - GuiText titleTxt2(title, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt2.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - titleTxt2.SetPosition(230, 50); - titleTxt2.SetMaxWidth(dialogBox.GetWidth() - 220, WRAP); - - GuiText authorTxt(tr( "Author:" ), 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - authorTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - authorTxt.SetPosition(230, 100); - - GuiText authorTxt2(author, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - authorTxt2.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - authorTxt2.SetPosition(230, 120); - authorTxt2.SetMaxWidth(dialogBox.GetWidth() - 220, DOTTED); - - GuiText downloadBtnTxt(tr( "Download" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - downloadBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage downloadBtnImg(&btnOutline); - if (Settings.wsprompt) - { - downloadBtnTxt.SetWidescreen(Settings.widescreen); - downloadBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton downloadBtn(&downloadBtnImg, &downloadBtnImg, ALIGN_RIGHT, ALIGN_TOP, -5, 170, &trigA, btnSoundOver, - btnSoundClick2, 1); - downloadBtn.SetLabel(&downloadBtnTxt); - downloadBtn.SetScale(0.9); - - GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage backBtnImg(&btnOutline); - if (Settings.wsprompt) - { - backBtnTxt.SetWidescreen(Settings.widescreen); - backBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton backBtn(&backBtnImg, &backBtnImg, ALIGN_RIGHT, ALIGN_TOP, -5, 220, &trigA, btnSoundOver, btnSoundClick2, 1); - backBtn.SetLabel(&backBtnTxt); - backBtn.SetTrigger(&trigB); - backBtn.SetScale(0.9); - - GuiImage ThemeImage(thumbimageData); - ThemeImage.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - ThemeImage.SetPosition(20, 10); - ThemeImage.SetScale(0.8); - - ThemeImage.SetScale(0.8); - - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&ThemeImage); - promptWindow.Append(&titleTxt); - promptWindow.Append(&titleTxt2); - promptWindow.Append(&authorTxt); - promptWindow.Append(&authorTxt2); - promptWindow.Append(&downloadBtn); - promptWindow.Append(&backBtn); - - HaltGui(); - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - - while (!leave) - { - VIDEO_WaitVSync(); - - if (shutdown == 1) - Sys_Shutdown(); - else if (reset == 1) Sys_Reboot(); - - if (downloadBtn.GetState() == STATE_CLICKED) - { - int choice = WindowPrompt(tr( "Do you want to download this theme?" ), title, tr( "Yes" ), tr( "Cancel" )); - if (choice) - { - result = DownloadTheme(downloadlink, title); - if (result == 2) leave = true; - } - mainWindow->SetState(STATE_DISABLED); - promptWindow.SetState(STATE_DEFAULT); - mainWindow->ChangeFocus(&promptWindow); - downloadBtn.ResetState(); - } - - else if (backBtn.GetState() == STATE_CLICKED) - { - leave = true; - backBtn.ResetState(); - } - } - - promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); - while (promptWindow.GetEffect() > 0) - usleep(100); - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - return result; -} - -int Theme_Downloader() -{ - int pagesize = 4; - int menu = MENU_NONE; - bool listchanged = false; - - char THEME_LINK[70]; - sprintf(THEME_LINK, "http://wii.spiffy360.com/themes.php?xml=1&category=1&adult=%d", Settings.godmode); - - /*** Image Variables ***/ - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - - GuiImageData theme_box_Data(Resources::GetFile("theme_box.png"), Resources::GetFileSize("theme_box.png")); - - GuiImageData bgData(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png")); - - GuiImageData arrow_left(Resources::GetFile("startgame_arrow_left.png"), Resources::GetFileSize("startgame_arrow_left.png")); - - GuiImageData arrow_right(Resources::GetFile("startgame_arrow_right.png"), Resources::GetFileSize("startgame_arrow_right.png")); - - GuiImageData wifiImgData(Resources::GetFile("Wifi_btn.png"), Resources::GetFileSize("Wifi_btn.png")); - - GuiImageData PageindicatorImgData(Resources::GetFile("pageindicator.png"), Resources::GetFileSize("pageindicator.png")); - - GuiImage background(&bgData); - - /*** Trigger Variables ***/ - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - GuiTrigger trigHome; - trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - GuiTrigger trigB; - trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiTrigger trigL; - trigL.SetButtonOnlyTrigger(-1, WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT, PAD_BUTTON_LEFT); - GuiTrigger trigR; - trigR.SetButtonOnlyTrigger(-1, WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT, PAD_BUTTON_RIGHT); - GuiTrigger trigMinus; - trigMinus.SetButtonOnlyTrigger(-1, WPAD_BUTTON_MINUS | WPAD_CLASSIC_BUTTON_MINUS, 0); - GuiTrigger trigPlus; - trigPlus.SetButtonOnlyTrigger(-1, WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS, 0); - - GuiText titleTxt(tr( "Theme Downloader" ), 28, ( GXColor ) - { 0, 0, 0, 255}); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 40); - - GuiImageData *ImageData[pagesize]; - GuiImage *Image[pagesize]; - GuiImage *theme_box_img[pagesize]; - GuiButton *MainButton[pagesize]; - GuiText *MainButtonTxt[pagesize]; - Theme_List *ThemeList = NULL; - - /*** Buttons ***/ - - for (int i = 0; i < pagesize; i++) - { - ImageData[i] = NULL; - Image[i] = NULL; - MainButtonTxt[i] = NULL; - theme_box_img[i] = new GuiImage(&theme_box_Data); - - MainButton[i] = new GuiButton(theme_box_Data.GetWidth(), theme_box_Data.GetHeight()); - MainButton[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); - MainButton[i]->SetSoundOver(btnSoundOver); - MainButton[i]->SetSoundClick(btnSoundClick); - MainButton[i]->SetImage(theme_box_img[i]); - MainButton[i]->SetEffectGrow(); - MainButton[i]->SetTrigger(&trigA); - } - - /*** Positions ***/ - MainButton[0]->SetPosition(90, 75); - MainButton[1]->SetPosition(340, 75); - MainButton[2]->SetPosition(90, 230); - MainButton[3]->SetPosition(340, 230); - - GuiText backBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - backBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30); - GuiImage backBtnImg(&btnOutline); - if (Settings.wsprompt) - { - backBtnTxt.SetWidescreen(Settings.widescreen); - backBtnImg.SetWidescreen(Settings.widescreen); - } - GuiButton backBtn(&backBtnImg, &backBtnImg, 2, 3, -180, 400, &trigA, btnSoundOver, btnSoundClick2, 1); - backBtn.SetLabel(&backBtnTxt); - backBtn.SetTrigger(&trigB); - - GuiButton HomeBtn(1, 1); - HomeBtn.SetTrigger(&trigHome); - - GuiImage GoLeftImg(&arrow_left); - GuiButton GoLeftBtn(GoLeftImg.GetWidth(), GoLeftImg.GetHeight()); - GoLeftBtn.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - GoLeftBtn.SetPosition(25, -25); - GoLeftBtn.SetImage(&GoLeftImg); - GoLeftBtn.SetSoundOver(btnSoundOver); - GoLeftBtn.SetSoundClick(btnSoundClick2); - GoLeftBtn.SetEffectGrow(); - GoLeftBtn.SetTrigger(&trigA); - GoLeftBtn.SetTrigger(&trigL); - GoLeftBtn.SetTrigger(&trigMinus); - - GuiImage GoRightImg(&arrow_right); - GuiButton GoRightBtn(GoRightImg.GetWidth(), GoRightImg.GetHeight()); - GoRightBtn.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); - GoRightBtn.SetPosition(-25, -25); - GoRightBtn.SetImage(&GoRightImg); - GoRightBtn.SetSoundOver(btnSoundOver); - GoRightBtn.SetSoundClick(btnSoundClick2); - GoRightBtn.SetEffectGrow(); - GoRightBtn.SetTrigger(&trigA); - GoRightBtn.SetTrigger(&trigR); - GoRightBtn.SetTrigger(&trigPlus); - - GuiImage PageindicatorImg(&PageindicatorImgData); - GuiText PageindicatorTxt((char *) NULL, 22, ( GXColor ) - { 0, 0, 0, 255}); - GuiButton PageIndicatorBtn(PageindicatorImg.GetWidth(), PageindicatorImg.GetHeight()); - PageIndicatorBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - PageIndicatorBtn.SetPosition(110, 400); - PageIndicatorBtn.SetImage(&PageindicatorImg); - PageIndicatorBtn.SetLabel(&PageindicatorTxt); - PageIndicatorBtn.SetSoundOver(btnSoundOver); - PageIndicatorBtn.SetSoundClick(btnSoundClick); - PageIndicatorBtn.SetTrigger(&trigA); - PageIndicatorBtn.SetEffectGrow(); - - GuiImage wifiImg(&wifiImgData); - if (Settings.wsprompt) - { - wifiImg.SetWidescreen(Settings.widescreen); - } - GuiButton wifiBtn(wifiImg.GetWidth(), wifiImg.GetHeight()); - wifiBtn.SetImage(&wifiImg); - wifiBtn.SetPosition(500, 400); - wifiBtn.SetSoundOver(btnSoundOver); - wifiBtn.SetSoundClick(btnSoundClick); - wifiBtn.SetEffectGrow(); - wifiBtn.SetTrigger(&trigA); - - GuiWindow w(screenwidth, screenheight); - - HaltGui(); - w.Append(&background); - mainWindow->Append(&w); - ResumeGui(); - - if (!IsNetworkInit()) NetworkInitPrompt(); - - char url[300]; - int currentpage = 1; - int currenttheme = 0; - - HaltGui(); - w.RemoveAll(); - w.Append(&background); - w.Append(&titleTxt); - w.Append(&backBtn); - w.Append(&GoLeftBtn); - w.Append(&GoRightBtn); - w.Append(&PageIndicatorBtn); - w.Append(&wifiBtn); - w.Append(&HomeBtn); - ResumeGui(); - - ShowProgress(tr( "Downloading Page List:" ), "", (char *) tr( "Please wait..." ), 0, pagesize); - - ThemeList = new Theme_List(THEME_LINK); - - int ThemesOnPage = ThemeList->GetThemeCount(); - - if (!ThemesOnPage) - { - WindowPrompt(tr( "No themes found on the site." ), 0, "OK"); - menu = MENU_SETTINGS; - } - - while (menu == MENU_NONE) - { - HaltGui(); - w.RemoveAll(); - w.Append(&background); - w.Append(&titleTxt); - w.Append(&backBtn); - w.Append(&GoLeftBtn); - w.Append(&GoRightBtn); - w.Append(&PageIndicatorBtn); - w.Append(&wifiBtn); - w.Append(&HomeBtn); - ResumeGui(); - - sprintf(url, "%i", currentpage); - PageindicatorTxt.SetText(url); - - int n = 0; - - for (int i = currenttheme; (i < (currenttheme + pagesize)); i++) - { - ShowProgress(tr( "Downloading image:" ), 0, (char *) ThemeList->GetThemeTitle(i), n, pagesize); - - if (MainButtonTxt[n]) delete MainButtonTxt[n]; - if (ImageData[n]) delete ImageData[n]; - if (Image[n]) delete Image[n]; - - MainButtonTxt[n] = NULL; - ImageData[n] = NULL; - Image[n] = NULL; - - if (i < ThemesOnPage) - { - MainButtonTxt[n] = new GuiText(ThemeList->GetThemeTitle(i), 18, ( GXColor ) - { 0, 0, 0, 255}); - MainButtonTxt[n]->SetAlignment(ALIGN_CENTER, ALIGN_TOP); - MainButtonTxt[n]->SetPosition(0, 10); - MainButtonTxt[n]->SetMaxWidth(theme_box_Data.GetWidth() - 10, DOTTED); - - sprintf(url, "%s", ThemeList->GetImageLink(i)); - - char filepath[300]; - snprintf(filepath, sizeof(filepath), "%s/tmp/%s.jpg", Settings.theme_downloadpath, - ThemeList->GetThemeTitle(i)); - - FILE * storefile = fopen(filepath, "rb"); - - if (!storefile) - { - struct block file = downloadfile(url); - char storepath[300]; - snprintf(storepath, sizeof(storepath), "%s/tmp/", Settings.theme_downloadpath); - CreateSubfolder(storepath); - if (file.data) - { - storefile = fopen(filepath, "wb"); - fwrite(file.data, 1, file.size, storefile); - fclose(storefile); - } - ImageData[n] = new GuiImageData(file.data, file.size); - free(file.data); - } - else - { - fseek(storefile, 0, SEEK_END); - u32 filesize = ftell(storefile); - u8 *buffer = (u8*) malloc(filesize); - rewind(storefile); - fread(buffer, 1, filesize, storefile); - fclose(storefile); - ImageData[n] = new GuiImageData(buffer, filesize); - free(buffer); - buffer = NULL; - } - Image[n] = new GuiImage(ImageData[n]); - Image[n]->SetScale(0.4); - Image[n]->SetPosition(50, -45); - MainButton[n]->SetIcon(Image[n]); - MainButton[n]->SetLabel(MainButtonTxt[n]); - } - n++; - } - - ProgressStop(); - - HaltGui(); - for (int i = 0; i < pagesize; i++) - { - if (MainButtonTxt[i]) w.Append(MainButton[i]); - } - ResumeGui(); - - listchanged = false; - - while (!listchanged) - { - VIDEO_WaitVSync(); - - if (shutdown == 1) - Sys_Shutdown(); - else if (reset == 1) - Sys_Reboot(); - - else if (wifiBtn.GetState() == STATE_CLICKED) - { - Initialize_Network(); - wifiBtn.ResetState(); - } - else if (backBtn.GetState() == STATE_CLICKED) - { - listchanged = true; - menu = MENU_SETTINGS; - backBtn.ResetState(); - break; - } - else if (GoRightBtn.GetState() == STATE_CLICKED) - { - listchanged = true; - currenttheme += pagesize; - currentpage++; - if (currenttheme >= ThemesOnPage) - { - currentpage = 1; - currenttheme = 0; - } - GoRightBtn.ResetState(); - } - else if (GoLeftBtn.GetState() == STATE_CLICKED) - { - listchanged = true; - currenttheme -= pagesize; - currentpage--; - if (currenttheme < 0) - { - currentpage = ceil((ThemesOnPage + 1.0f) / pagesize); - currenttheme = currentpage * pagesize - pagesize; - } - GoLeftBtn.ResetState(); - } - - for (int i = 0; i < pagesize; i++) - { - if (MainButton[i]->GetState() == STATE_CLICKED) - { - snprintf(url, sizeof(url), "%s", ThemeList->GetDownloadLink(currenttheme + i)); - int ret = Theme_Prompt(ThemeList->GetThemeTitle(currenttheme + i), ThemeList->GetThemeAuthor(currenttheme - + i), ImageData[i], url); - MainButton[i]->ResetState(); - if (ret == 2) - { - listchanged = true; - menu = MENU_THEMEDOWNLOADER; - } - } - } - } - } - - w.SetEffect(EFFECT_FADE, -20); - - while (w.GetEffect() > 0) - usleep(100); - - HaltGui(); - mainWindow->Remove(&w); - - for (int i = 0; i < pagesize; i++) - { - if (MainButton[i]) delete MainButton[i]; - if (theme_box_img[i]) delete theme_box_img[i]; - if (ImageData[i]) delete ImageData[i]; - if (Image[i]) delete Image[i]; - if (MainButtonTxt[i]) delete MainButtonTxt[i]; - } - - if (ThemeList) delete ThemeList; - ThemeList = NULL; - - ResumeGui(); - - return menu; -} diff --git a/source/themes/Theme_Downloader.h b/source/themes/Theme_Downloader.h deleted file mode 100644 index 99d867d7..00000000 --- a/source/themes/Theme_Downloader.h +++ /dev/null @@ -1,15 +0,0 @@ -/**************************************************************************** - * Theme_Downloader - * USB Loader GX 2009 - * - * Theme downloader for USB Loader GX - * - * Theme_Downloader.h - ***************************************************************************/ - -#ifndef _THEME_DOWNLOADER_H_ -#define _THEME_DOWNLOADER_H_ - -int Theme_Downloader(); - -#endif diff --git a/source/themes/Theme_List.cpp b/source/themes/Theme_List.cpp deleted file mode 100644 index d306f6e3..00000000 --- a/source/themes/Theme_List.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 - * by USB Loader GX Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * Theme_List Class - * for the USB Loader GX - ***************************************************************************/ -#include -#include -#include -#include - -#include "Theme_List.h" -#include "xml/xml.h" -#include "prompts/PromptWindows.h" - -#define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp)) - -static void copyhtmlsting(const char *from, char *outtext, const char *stopat, u32 &cnt) -{ - u32 cnt2 = 0; - - u32 stringlength = strlen(from); - - while ((stringcompare( from, stopat, cnt + strlen( stopat ) ) != 0) && (cnt2 < 1024) && (cnt < stringlength)) - { - outtext[cnt2] = from[cnt]; - cnt2++; - cnt++; - } - outtext[cnt2] = '\0'; -} - -Theme_List::Theme_List(const char * url) -{ - Theme = NULL; - themescount = 0; - - if (!IsNetworkInit()) - { - themescount = -1; - return; - } - - struct block file = downloadfile(url); - - if (!file.data || !file.size) - { - themescount = -2; - return; - } - - themescount = CountThemes(file.data); - if (themescount <= 0) - { - free(file.data); - return; - } - - ParseXML(file.data); - - free(file.data); -} - -Theme_List::~Theme_List() -{ - for (int i = 0; i < themescount; i++) - { - if (Theme[i].themetitle) delete[] Theme[i].themetitle; - if (Theme[i].author) delete[] Theme[i].author; - if (Theme[i].imagelink) delete[] Theme[i].imagelink; - if (Theme[i].downloadlink) delete[] Theme[i].downloadlink; - Theme[i].themetitle = NULL; - Theme[i].author = NULL; - Theme[i].imagelink = NULL; - Theme[i].downloadlink = NULL; - } - - if (Theme) delete[] Theme; - Theme = NULL; -} - -int Theme_List::CountThemes(const u8 * xmlfile) -{ - char tmp[200]; - u32 cnt = 0; - u32 stringlength = strlen((const char *) xmlfile); - memset(tmp, 0, sizeof(tmp)); - - while (cnt < stringlength) - { - if (stringcompare( xmlfile, "", cnt ) == 0) - { - copyhtmlsting((const char *) xmlfile, tmp, ">", cnt); - break; - } - cnt++; - } - tmp[cnt + 1] = 0; - - return atoi(tmp); -} - -bool Theme_List::ParseXML(const u8 * xmlfile) -{ - char element_text[1024]; - memset(element_text, 0, sizeof(element_text)); - mxml_node_t *nodetree = NULL; - mxml_node_t *nodedata = NULL; - mxml_node_t *nodeid = NULL; - mxml_index_t *nodeindex = NULL; - - nodetree = mxmlLoadString(NULL, (const char *) xmlfile, MXML_OPAQUE_CALLBACK); - - if (nodetree == NULL) - { - return false; - } - - nodedata = mxmlFindElement(nodetree, nodetree, "themes", NULL, NULL, MXML_DESCEND); - if (nodedata == NULL) - { - return false; - } - - nodeindex = mxmlIndexNew(nodedata, "name", NULL); - nodeid = mxmlIndexReset(nodeindex); - - Theme = new Theme_Info[themescount]; - memset(Theme, 0, sizeof(Theme)); - - for (int i = 0; i < themescount; i++) - { - nodeid = mxmlIndexFind(nodeindex, "name", NULL); - if (nodeid != NULL) - { - get_nodetext(nodeid, element_text, sizeof(element_text)); - Theme[i].themetitle = new char[strlen(element_text) + 2]; - snprintf(Theme[i].themetitle, strlen(element_text) + 1, "%s", element_text); - - GetTextFromNode(nodeid, nodedata, (char *) "creator", NULL, NULL, MXML_NO_DESCEND, element_text, - sizeof(element_text)); - Theme[i].author = new char[strlen(element_text) + 2]; - snprintf(Theme[i].author, strlen(element_text) + 1, "%s", element_text); - - GetTextFromNode(nodeid, nodedata, (char *) "thumbpath", NULL, NULL, MXML_NO_DESCEND, element_text, - sizeof(element_text)); - Theme[i].imagelink = new char[strlen(element_text) + 2]; - snprintf(Theme[i].imagelink, strlen(element_text) + 1, "%s", element_text); - - GetTextFromNode(nodeid, nodedata, (char *) "downloadpath", NULL, NULL, MXML_NO_DESCEND, element_text, - sizeof(element_text)); - Theme[i].downloadlink = new char[strlen(element_text) + 2]; - snprintf(Theme[i].downloadlink, strlen(element_text) + 1, "%s", element_text); - - GetTextFromNode(nodeid, nodedata, (char *) "averagerating", NULL, NULL, MXML_NO_DESCEND, element_text, - sizeof(element_text)); - Theme[i].rating = atoi(element_text); - } - } - - mxmlIndexDelete(nodeindex); - free(nodetree); - free(nodedata); - free(nodeid); - nodetree = NULL; - nodedata = NULL; - nodeid = NULL; - nodeindex = NULL; - - return true; -} - -const char * Theme_List::GetThemeTitle(int ind) -{ - if (ind > themescount || ind < 0 || !Theme || themescount <= 0) - return NULL; - else return Theme[ind].themetitle; -} - -const char * Theme_List::GetThemeAuthor(int ind) -{ - if (ind > themescount || ind < 0 || !Theme || themescount <= 0) - return NULL; - else return Theme[ind].author; -} - -const char * Theme_List::GetImageLink(int ind) -{ - if (ind > themescount || ind < 0 || !Theme || themescount <= 0) - return NULL; - else return Theme[ind].imagelink; -} - -const char * Theme_List::GetDownloadLink(int ind) -{ - if (ind > themescount || ind < 0 || !Theme || themescount <= 0) - return NULL; - else return Theme[ind].downloadlink; -} - -int Theme_List::GetThemeCount() -{ - return themescount; -} - -static int ListCompare(const void *a, const void *b) -{ - Theme_Info *ab = (Theme_Info*) a; - Theme_Info *bb = (Theme_Info*) b; - - return stricmp((char *) ab->themetitle, (char *) bb->themetitle); -} -void Theme_List::SortList() -{ - qsort(Theme, themescount, sizeof(Theme_Info), ListCompare); -} diff --git a/source/themes/Theme_List.h b/source/themes/Theme_List.h deleted file mode 100644 index 84ebe62b..00000000 --- a/source/themes/Theme_List.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * Theme_List Class - * for USB Loader GX - * by dimok - ***************************************************************************/ -#ifndef ___THEMELIST_H_ -#define ___THEMELIST_H_ - -#include "network/networkops.h" -#include "network/http.h" - -typedef struct _theme_info -{ - char *themetitle; - char *author; - char *imagelink; - char *downloadlink; - u8 rating; -} Theme_Info; - -class Theme_List -{ - public: - //!Constructor - //!\param url from where to get the list of links - Theme_List(const char *url); - //!Destructor - ~Theme_List(); - //!Get Themes into a struct from the XML file amount - bool ParseXML(const u8 * xmlfile); - //!Get Theme amount - int CountThemes(const u8 * xmlfile); - //! Get the a theme title - //!\param list index - const char * GetThemeTitle(int index); - //! Get the author of the theme - //!\param list index - const char * GetThemeAuthor(int index); - //! Get the author of the theme - //!\param list index - const char * GetImageLink(int index); - //! Get the download link of the theme - //!\param list index - const char * GetDownloadLink(int index); - //! Get the number of links counted - int GetThemeCount(); - //! Sort list - void SortList(); - protected: - int themescount; - Theme_Info *Theme; -}; - -#endif diff --git a/source/themes/gettheme.c b/source/themes/gettheme.c deleted file mode 100644 index 2fe870a6..00000000 --- a/source/themes/gettheme.c +++ /dev/null @@ -1,273 +0,0 @@ -#include -#include -#include -#include -#include - -enum -{ - ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTRE, ALIGN_TOP, ALIGN_BOTTOM, ALIGN_MIDDLE -}; - -typedef struct _MSG -{ - u32 id; - char* msgstr; - struct _MSG *next; -} MSG; -static MSG *baseMSG=0; - - -#define HASHWORDBITS 32 - -/* Defines the so called `hashpjw' function by P.J. Weinberger - [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, - 1986, 1987 Bell Telephone Laboratories, Inc.] */ -static inline u32 hash_string (const char *str_param) -{ - u32 hval, g; - const char *str = str_param; - - /* Compute the hash value for the given string. */ - hval = 0; - while (*str != '\0') - { - hval <<= 4; - hval += (u8) *str++; - g = hval & ((u32) 0xf << (HASHWORDBITS - 4)); - if (g != 0) - { - hval ^= g >> (HASHWORDBITS - 8); - hval ^= g; - } - } - return hval; -} - - -static MSG *findMSG(u32 id) -{ - MSG *msg; - for(msg=baseMSG; msg; msg=msg->next) - { - if(msg->id == id) - return msg; - } - return NULL; -} - -static MSG *setMSG(const char *msgid, const char *msgstr) -{ - u32 id = hash_string(msgid); - MSG *msg = findMSG(id); - if(!msg) - { - msg = (MSG *)malloc(sizeof(MSG)); - msg->id = id; - msg->msgstr = NULL; - msg->next = baseMSG; - baseMSG = msg; - } - if(msg) - { - if(msgstr) - { - if(msg->msgstr) free(msg->msgstr); - msg->msgstr = strdup(msgstr); - } - return msg; - } - return NULL; -} - -static inline void ClearPrefixes(char * msg) -{ - if(!msg) - return; - - const char * ptr = msg; - - int i = 0; - - while(ptr[0] != '\0') - { - if(ptr[0] == '\\' && (ptr[1] == '\\' || ptr[1] == '"')) - { - ++ptr; - } - - msg[i] = ptr[0]; - - ++i; - ++ptr; - } - - msg[i] = '\0'; -} - -void ThemeCleanUp(void) -{ - while(baseMSG) - { - MSG *nextMsg =baseMSG->next; - free(baseMSG->msgstr); - free(baseMSG); - baseMSG = nextMsg; - } -} - -bool LoadTheme(const char* themeFile) -{ - FILE *f; - char line[200]; - char *lastID=NULL; - - ThemeCleanUp(); - f = fopen(themeFile, "r"); - if(!f) - return false; - - while (fgets(line, sizeof(line), f)) - { - // lines starting with # are comments - if (line[0] == '#') - continue; - else if (strncmp(line, "msgid \"", 7) == 0) - { - char *msgid, *end; - if(lastID) { free(lastID); lastID=NULL;} - msgid = &line[7]; - end = strrchr(msgid, '"'); - if(end && end-msgid>1) - { - *end = 0; - ClearPrefixes(msgid); - lastID = strdup(msgid); - } - } - else if (strncmp(line, "msgstr \"", 8) == 0) - { - char *msgstr, *end; - - if(lastID == NULL) - continue; - - msgstr = &line[8]; - end = strrchr(msgstr, '"'); - if(end && end-msgstr>1) - { - *end = 0; - ClearPrefixes(msgstr); - setMSG(lastID, msgstr); - } - free(lastID); - lastID=NULL; - } - } - - fclose(f); - return true; -} - -int getThemeInt(const char *msgid) -{ - MSG *msg = findMSG(hash_string(msgid)); - if(msg) return atoi(msg->msgstr); - return atoi(msgid); -} - -int getThemeAlignment(const char *msgid) -{ - MSG *msg = findMSG(hash_string(msgid)); - - const char * string = msgid; - if(msg) - string = msg->msgstr; - - while(*string == ' ') string++; - - if(strncasecmp(string, "left", strlen("left")) == 0) - return ALIGN_LEFT; - - else if(strncasecmp(string, "right", strlen("right")) == 0) - return ALIGN_RIGHT; - - else if(strncasecmp(string, "center", strlen("center")) == 0) - return ALIGN_CENTRE; - - else if(strncasecmp(string, "top", strlen("top")) == 0) - return ALIGN_TOP; - - else if(strncasecmp(string, "bottom", strlen("bottom")) == 0) - return ALIGN_BOTTOM; - - else if(strncasecmp(string, "middle", strlen("middle")) == 0) - return ALIGN_MIDDLE; - - return -1; -} - -GXColor getThemeColor(const char *msgid) -{ - MSG *msg = findMSG(hash_string(msgid)); - - const char * string = msgid; - if(msg) - string = msg->msgstr; - - GXColor color = (GXColor) {0, 0, 0, 0}; - - while(*string == ' ') string++; - - while(*string != '\0') - { - if(*string == 'r') - { - string++; - while(*string == ' ' || *string == '=' || *string == ',') string++; - - if(*string == '\0') - break; - - color.r = atoi(string) & 0xFF; - } - else if(*string == 'g') - { - string++; - while(*string == ' ' || *string == '=' || *string == ',') string++; - - if(*string == '\0') - break; - - color.g = atoi(string) & 0xFF; - } - else if(*string == 'b') - { - string++; - while(*string == ' ' || *string == '=' || *string == ',') string++; - - if(*string == '\0') - break; - - color.b = atoi(string) & 0xFF; - } - else if(*string == 'a') - { - string++; - while(*string == ' ' || *string == '=' || *string == ',') string++; - - if(*string == '\0') - break; - - color.a = atoi(string) & 0xFF; - } - else if(*string == '-') - { - break; - } - - ++string; - } - - return color; -} diff --git a/source/themes/gettheme.h b/source/themes/gettheme.h deleted file mode 100644 index ada1154b..00000000 --- a/source/themes/gettheme.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef GETTHEME_H_ -#define GETTHEME_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -int getThemeInt(const char *msgid); -int getThemeAlignment(const char *msgid); -GXColor getThemeColor(const char *msgid); -bool LoadTheme(const char* themeFile); -void ThemeCleanUp(void); - -#define thInt(s) getThemeInt(s) -#define thAlign(s) getThemeAlignment(s) -#define thColor(s) getThemeColor(s) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/GameList.cpp b/source/usbloader/GameList.cpp deleted file mode 100644 index ef654b49..00000000 --- a/source/usbloader/GameList.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include "usbloader/wbfs.h" -#include "settings/newtitles.h" -#include "settings/CSettings.h" -#include "settings/CGameSettings.h" -#include "settings/CGameStatistics.h" -#include "settings/GameTitles.h" -#include "xml/xml.h" -#include "FreeTypeGX.h" -#include "GameList.h" -#include "memory/memory.h" - -GameList gameList; - -GameList::GameList() -{ - -} - -void GameList::clear() -{ - GameFilter.clear(); - AvailableSearchChars.clear(); - FullGameList.clear(); - FilteredList.clear(); - //! Clear memory of the vector completely - std::vector().swap(FilteredList); - std::vector().swap(FullGameList); -} - -struct discHdr * GameList::at(int i) -{ - if (i < 0 || i >= (int) FilteredList.size()) return NULL; - - return FilteredList[i]; -} - -struct discHdr * GameList::GetDiscHeader(const char * gameID) -{ - for (u32 i = 0; i < FilteredList.size(); ++i) - { - if(strncasecmp(gameID, (const char *) FilteredList[i]->id, 6) == 0) - return FilteredList[i]; - } - - return NULL; -} - -int GameList::ReadGameList() -{ - // Clear list - clear(); - - // Retrieve all stuff from WBFS - u32 cnt; - - int ret = WBFS_GetCount(&cnt); - if (ret < 0) return -1; - - // We are done here if no games are there - if(cnt == 0) - return 0; - - /* Buffer length */ - u32 len = sizeof(struct discHdr) * cnt; - - /* Allocate memory */ - struct discHdr *buffer = (struct discHdr *) allocate_memory( len ); - if (!buffer) return -1; - - /* Clear buffer */ - memset(buffer, 0, len); - - /* Get header list */ - ret = WBFS_GetHeaders(buffer, cnt, sizeof(struct discHdr)); - if (ret < 0) - { - if (buffer) free(buffer); - return -1; - } - - FullGameList.resize(cnt); - memcpy(&FullGameList[0], buffer, len); - - free(buffer); - - return LoadUnfiltered(); -} - -static bool WCharSortCallback(const wchar_t char1, const wchar_t char2) -{ - if (char2 == 0) return true; - if (char1 == 0) return false; - - return char2 > char1; -} - -int GameList::FilterList(const wchar_t * gameFilter) -{ - if (FullGameList.size() == 0) ReadGameList(); - if (gameFilter) GameFilter.assign(gameFilter); - - FilteredList.clear(); - AvailableSearchChars.clear(); - - for (u32 i = 0; i < FullGameList.size(); ++i) - { - struct discHdr *header = &FullGameList[i]; - - /* Register game */ - NewTitles::Instance()->CheckGame(header->id); - - /* Filters */ - if (Settings.GameSort & SORT_FAVORITE) - { - GameStatus * GameStats = GameStatistics.GetGameStatus(header->id); - if (!GameStats || GameStats->FavoriteRank == 0) continue; - } - - //ignore uLoader cfg "iso". i was told it is "__CFG_" but not confirmed - if (strncasecmp((char*) header->id, "__CFG_", 6) == 0) - continue; - - GameCFG * GameConfig = GameSettings.GetGameCFG(header); - - if (Settings.parentalcontrol && !Settings.godmode) - { - if (GameConfig && GameConfig->parentalcontrol >= Settings.parentalcontrol) - continue; - } - - /* Rating based parental control method */ - if (Settings.parentalcontrol != 4 && Settings.godmode == 0) - { - // Check game rating in WiiTDB, since the default Wii parental control setting is enabled - int rating = GameTitles.GetParentalRating((char *) header->id); - if (rating > Settings.parentalcontrol) - continue; - } - - //! Per game lock method - if(!Settings.godmode && Settings.lockedgames && GameConfig && GameConfig->Locked) - continue; - - wchar_t *gameName = charToWideChar(GameTitles.GetTitle(header)); - - if (gameName && *GameFilter.c_str()) - { - if (wcsnicmp(gameName, GameFilter.c_str(), GameFilter.size()) != 0) - { - delete[] gameName; - continue; - } - } - - if (gameName) - { - if (wcslen(gameName) > GameFilter.size() && AvailableSearchChars.find(gameName[GameFilter.size()]) - == std::string::npos) AvailableSearchChars.push_back(gameName[GameFilter.size()]); - delete[] gameName; - } - - FilteredList.push_back(header); - } - - NewTitles::Instance()->Save(); - - AvailableSearchChars.push_back(L'\0'); - - if (FilteredList.size() < 2) AvailableSearchChars.clear(); - - SortList(); - - return FilteredList.size(); -} - -int GameList::LoadUnfiltered() -{ - if (FullGameList.size() == 0) ReadGameList(); - - GameFilter.clear(); - AvailableSearchChars.clear(); - FilteredList.clear(); - - for (u32 i = 0; i < FullGameList.size(); ++i) - { - struct discHdr *header = &FullGameList[i]; - - /* Register game */ - NewTitles::Instance()->CheckGame(header->id); - - wchar_t *gameName = charToWideChar(GameTitles.GetTitle(header)); - if (gameName) - { - if (wcslen(gameName) > GameFilter.size() && AvailableSearchChars.find(gameName[GameFilter.size()]) - == std::string::npos) AvailableSearchChars.push_back(gameName[GameFilter.size()]); - delete[] gameName; - } - - FilteredList.push_back(header); - } - - NewTitles::Instance()->Save(); - - AvailableSearchChars.push_back(L'\0'); - - if (FilteredList.size() < 2) AvailableSearchChars.clear(); - - SortList(); - - return FilteredList.size(); -} - -void GameList::SortList() -{ - if (FilteredList.size() < 2) return; - - if (Settings.GameSort & SORT_PLAYCOUNT) - { - std::sort(FilteredList.begin(), FilteredList.end(), PlaycountSortCallback); - } - else if(Settings.GameSort & SORT_RANKING) - { - std::sort(FilteredList.begin(), FilteredList.end(), RankingSortCallback); - } - else - { - std::sort(FilteredList.begin(), FilteredList.end(), NameSortCallback); - } - - if (AvailableSearchChars.size() > 1) std::sort(AvailableSearchChars.begin(), AvailableSearchChars.end(), - WCharSortCallback); - -} - -bool GameList::NameSortCallback(const struct discHdr *a, const struct discHdr *b) -{ - return (strcasecmp(GameTitles.GetTitle((struct discHdr *) a), GameTitles.GetTitle((struct discHdr *) b)) < 0); -} - -bool GameList::PlaycountSortCallback(const struct discHdr *a, const struct discHdr *b) -{ - int count1 = GameStatistics.GetPlayCount(a->id); - int count2 = GameStatistics.GetPlayCount(b->id); - - if (count1 == count2) return NameSortCallback(a, b); - - return (count1 > count2); -} - -bool GameList::RankingSortCallback(const struct discHdr *a, const struct discHdr *b) -{ - int fav1 = GameStatistics.GetFavoriteRank(a->id); - int fav2 = GameStatistics.GetFavoriteRank(b->id); - - if (fav1 == fav2) return NameSortCallback(a, b); - - return (fav1 > fav2); -} diff --git a/source/usbloader/GameList.h b/source/usbloader/GameList.h deleted file mode 100644 index 179cdc01..00000000 --- a/source/usbloader/GameList.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef GAME_LIST_H_ -#define GAME_LIST_H_ - -#include -#include "wstring.hpp" -#include "usbloader/disc.h" - -class GameList -{ - public: - GameList(); - int ReadGameList(); - int size() { return FilteredList.size(); }; - int GameCount() { return FullGameList.size(); }; - int FilterList(const wchar_t * gameFilter = NULL); - int LoadUnfiltered(); - struct discHdr * at(int i); - struct discHdr * operator[](int i) { return at(i); }; - struct discHdr * GetDiscHeader(const char * gameID); - const wchar_t * GetCurrentFilter() { return GameFilter.c_str(); }; - const wchar_t * GetAvailableSearchChars() { return AvailableSearchChars.c_str(); }; - void SortList(); - void clear(); - protected: - static bool NameSortCallback(const struct discHdr *a, const struct discHdr *b); - static bool PlaycountSortCallback(const struct discHdr *a, const struct discHdr *b); - static bool RankingSortCallback(const struct discHdr *a, const struct discHdr *b); - - wString AvailableSearchChars; - wString GameFilter; - std::vector FilteredList; - std::vector FullGameList; -}; - -extern GameList gameList; - -#endif diff --git a/source/usbloader/GetMissingGameFiles.cpp b/source/usbloader/GetMissingGameFiles.cpp deleted file mode 100644 index 3d148356..00000000 --- a/source/usbloader/GetMissingGameFiles.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#include "FileOperations/fileops.h" -#include "usbloader/GameList.h" -#include "wstring.hpp" -#include "gecko.h" - -/************************************************************************************** - * FindMissingFiles - * Inputs: - * path - Path to search in with. example "SD:/covers/" - * fileext - the file extension. example ".png" - * MissingFilesList - string vector where the IDs of missing game files will be put in. - **************************************************************************************/ -int GetMissingGameFiles(const char * path, const char * fileext, std::vector & MissingFilesList) -{ - char gameID[7]; - char filepath[512]; - MissingFilesList.clear(); - wString oldFilter(gameList.GetCurrentFilter()); - - //! make sure that all games are added to the gamelist - gameList.LoadUnfiltered(); - - for (int i = 0; i < gameList.size(); ++i) - { - struct discHdr* header = gameList[i]; - snprintf(gameID, sizeof(gameID), "%s", (char *) header->id); - snprintf(filepath, sizeof(filepath), "%s/%s%s", path, gameID, fileext); - - if (CheckFile(filepath)) - continue; - - //! Not found. Try 4 ID path. - gameID[4] = '\0'; - snprintf(filepath, sizeof(filepath), "%s/%s%s", path, gameID, fileext); - - if (CheckFile(filepath)) - continue; - - //! Not found. Try 3 ID path. - gameID[3] = '\0'; - snprintf(filepath, sizeof(filepath), "%s/%s%s", path, gameID, fileext); - - if (CheckFile(filepath)) - continue; - - //! Not found add to missing list - snprintf(gameID, sizeof(gameID), "%s", (char *) header->id); - MissingFilesList.push_back(std::string(gameID)); - } - - //! Bring game list to the old state - gameList.FilterList(oldFilter.c_str()); - - gprintf(" = %i", MissingFilesList.size()); - - return MissingFilesList.size(); -} diff --git a/source/usbloader/GetMissingGameFiles.hpp b/source/usbloader/GetMissingGameFiles.hpp deleted file mode 100644 index 1b08a7f6..00000000 --- a/source/usbloader/GetMissingGameFiles.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GETMISSINGGAMEFILES_HPP_ -#define GETMISSINGGAMEFILES_HPP_ - -/************************************************************************************** - * FindMissingFiles - * This function can be used for any files that are game related: .png, .wip, .gct, ... - * Inputs: - * path - Path to search in with. example "SD:/covers/" - * fileext - the file extension. example ".png" - * List - string vector where the IDs of missing game files will be put in. - **************************************************************************************/ -int GetMissingGameFiles(const char * path, const char * fileext, std::vector & List); - -#endif diff --git a/source/usbloader/alternatedol.c b/source/usbloader/alternatedol.c deleted file mode 100644 index 63c0b8e3..00000000 --- a/source/usbloader/alternatedol.c +++ /dev/null @@ -1,280 +0,0 @@ -#include -#include -#include -#include -#include - -#include "fatmounter.h" -#include "apploader.h" -#include "wdvd.h" -#include "fstfile.h" -#include "../patches/dvd_broadway.h" - -extern u8 mountMethod; - -/** Alternate dolloader made by WiiPower modified by dimok **/ -bool Load_Dol(void **buffer, int* dollen, char * filepath) -{ - int ret; - FILE* file; - void* dol_buffer; - - char fullpath[200]; - char gameidbuffer6[7]; - memset(gameidbuffer6, 0, 7); - memcpy(gameidbuffer6, (char*) 0x80000000, 6); - snprintf(fullpath, 200, "%s%s.dol", filepath, gameidbuffer6); - - // SDCard_Init(); - // USBDevice_Init(); - - file = fopen(fullpath, "rb"); - - if (file == NULL) - { - fclose(file); - // SDCard_deInit(); - // USBDevice_deInit(); - return false; - } - - int filesize; - fseek(file, 0, SEEK_END); - filesize = ftell(file); - fseek(file, 0, SEEK_SET); - - dol_buffer = malloc(filesize); - if (dol_buffer == NULL) - { - fclose(file); - // SDCard_deInit(); - // USBDevice_deInit(); - return false; - } - ret = fread(dol_buffer, 1, filesize, file); - if (ret != filesize) - { - free(dol_buffer); - fclose(file); - // SDCard_deInit(); - // USBDevice_deInit(); - return false; - } - fclose(file); - - // SDCard_deInit(); - // USBDevice_deInit(); - *buffer = dol_buffer; - *dollen = filesize; - return true; -} - -bool Remove_001_Protection(void *Address, int Size) -{ - u8 SearchPattern[16] = { 0x40, 0x82, 0x00, 0x0C, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, - 0x18 }; - u8 PatchData[16] = - { 0x40, 0x82, 0x00, 0x04, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18 }; - - void *Addr = Address; - void *Addr_end = Address + Size; - - while (Addr <= Addr_end - sizeof(SearchPattern)) - { - if (memcmp(Addr, SearchPattern, sizeof(SearchPattern)) == 0) - { - memcpy(Addr, PatchData, sizeof(PatchData)); - return true; - } - Addr += 4; - } - return false; -} - -typedef struct _dolheader -{ - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - -static dolheader *dolfile; - -u32 load_dol_image(void *dolstart, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, u8 cheat, u32 returnTo, u8 fix002) -{ - - u32 i; - - if (dolstart) - { - dolfile = (dolheader *) dolstart; - for (i = 0; i < 7; i++) - { - if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue; - - ICInvalidateRange((void *) dolfile->text_start[i], dolfile->text_size[i]); - memmove((void *) dolfile->text_start[i], dolstart + dolfile->text_pos[i], dolfile->text_size[i]); - gamepatches((void *) dolfile->text_start[i], dolfile->text_size[i], videoSelected, languageChoice, patchcountrystring, - vipatch, cheat, returnTo, fix002); - Remove_001_Protection((void *) dolfile->data_start[i], dolfile->data_size[i]); - } - - for (i = 0; i < 11; i++) - { - if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue; - - memmove((void *) dolfile->data_start[i], dolstart + dolfile->data_pos[i], dolfile->data_size[i]); - gamepatches((void *) dolfile->data_start[i], dolfile->data_size[i], videoSelected, languageChoice, patchcountrystring, - vipatch, cheat, returnTo, fix002); - Remove_001_Protection((void *) dolfile->data_start[i], dolfile->data_size[i]); - DCFlushRangeNoSync((void *) dolfile->data_start[i], dolfile->data_size[i]); - } - /* - memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - */ - return dolfile->entry_point; - } - return 0; -} - -static int i; -static int phase; - -u32 load_dol_start(void *dolstart) -{ - if (dolstart) - { - dolfile = (dolheader *) dolstart; - return dolfile->entry_point; - } - else - { - return 0; - } - - memset((void *) dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - - phase = 0; - i = 0; -} - -bool load_dol_image_modified(void **offset, u32 *pos, u32 *len) -{ - if (phase == 0) - { - if (i == 7) - { - phase = 1; - i = 0; - } - else - { - if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) - { - *offset = 0; - *pos = 0; - *len = 0; - } - else - { - *offset = (void *) dolfile->text_start[i]; - *pos = dolfile->text_pos[i]; - *len = dolfile->text_size[i]; - } - i++; - return true; - } - } - - if (phase == 1) - { - if (i == 11) - { - phase = 2; - return false; - } - - if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) - { - *offset = 0; - *pos = 0; - *len = 0; - } - else - { - *offset = (void *) dolfile->data_start[i]; - *pos = dolfile->data_pos[i]; - *len = dolfile->data_size[i]; - } - i++; - return true; - } - return false; -} -static vu32 dvddone = 0; -void __dvd_readidcb(s32 result) -{ - dvddone = result; -} -u32 Load_Dol_from_disc(u32 doloffset, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, u8 cheat, u32 returnTo, u8 fix002) -{ - int ret; - void *dol_header; - u32 entrypoint; - - dol_header = memalign(32, sizeof(dolheader)); - if (dol_header == NULL) - { - return -1; - } - - if (!mountMethod) - ret = WDVD_Read(dol_header, sizeof(dolheader), (doloffset << 2)); - - else - { - dvddone = 0; - ret = bwDVD_LowRead(dol_header, sizeof(dolheader), doloffset, __dvd_readidcb); - while (ret >= 0 && dvddone == 0) - ; - } - - entrypoint = load_dol_start(dol_header); - - if (entrypoint == 0) - { - free(dol_header); - return -1; - } - - void *offset; - u32 pos; - u32 len; - - while (load_dol_image_modified(&offset, &pos, &len)) - { - if (len != 0) - { - ret = WDVD_Read(offset, len, (doloffset << 2) + pos); - - gamepatches(offset, len, videoSelected, languageChoice, patchcountrystring, vipatch, cheat, returnTo, fix002); - - Remove_001_Protection(offset, len); - - DCFlushRange(offset, len); - } - } - - free(dol_header); - - return entrypoint; - -} diff --git a/source/usbloader/alternatedol.h b/source/usbloader/alternatedol.h deleted file mode 100644 index 006fd783..00000000 --- a/source/usbloader/alternatedol.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _ALTERNATEDOL_H_ -#define _ALTERNATEDOL_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* not the full path is needed here, the path where the dol is */ - - bool Load_Dol(void **buffer, int* dollen, char * path, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, - u8 cheat, u32 returnTo); - bool Remove_001_Protection(void *Address, int Size); - u32 load_dol_image(void * dolstart); - u32 Load_Dol_from_disc(u32 doloffset, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, u8 cheat, u32 returnTo); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/apploader.c b/source/usbloader/apploader.c deleted file mode 100644 index 40a19ca2..00000000 --- a/source/usbloader/apploader.c +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include -#include -#include - -#include "patches/patchcode.h" -#include "apploader.h" -#include "wdvd.h" -#include "wpad.h" -#include "disc.h" -#include "alternatedol.h" -#include "fstfile.h" -#include "gecko.h" -#include "patches/wip.h" -#include "patches/dolpatcher.h" -#include "patches/gamepatches.h" - -extern bool geckoinit; - -/* Apploader function pointers */ -typedef int (*app_main)(void **dst, int *size, int *offset); -typedef void (*app_init)(void(*report)(const char *fmt, ...)); -typedef void *(*app_final)(); -typedef void (*app_entry)(void(**init)(void(*report)(const char *fmt, ...)), int(**main)(), void *(**final)()); - -/* Apploader pointers */ -static u8 *appldr = (u8 *) 0x81200000; - -/* Constants */ -#define APPLDR_OFFSET 0x2440 - -/* Variables */ -static u32 buffer[0x20] ATTRIBUTE_ALIGN( 32 ); - -void gamepatches( u8 * dst, int len, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, u8 cheat, u32 returnTo, u8 fix002 ) -{ - VideoModePatcher( dst, len, videoSelected ); - - if ( cheat ) - dogamehooks( dst, len ); - - if ( vipatch ) - vidolpatcher( dst, len ); - - /*LANGUAGE PATCH - FISHEARS*/ - langpatcher( dst, len, languageChoice ); - - /*Thanks to WiiPower*/ - if ( patchcountrystring == 1 ) - PatchCountryStrings( dst, len ); - - NSMBPatch( dst, len ); - - do_wip_code( ( u8 * ) dst, len ); - - if ( fix002 == 2 ) - Anti_002_fix( dst, len ); - - PatchReturnTo( dst, len, returnTo ); -} - -s32 Apploader_Run(entry_point *entry, char * dolpath, u8 cheat, u8 videoSelected, u8 languageChoice, u8 vipatch, u8 patchcountrystring, - u8 alternatedol, u32 alternatedoloffset, u32 returnTo, u8 fix002) -{ - app_entry appldr_entry; - app_init appldr_init; - app_main appldr_main; - app_final appldr_final; - - u32 appldr_len; - s32 ret; - gprintf("\nApploader_Run() started\n"); - - /* Read apploader header */ - ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET); - if (ret < 0) return ret; - - /* Calculate apploader length */ - appldr_len = buffer[5] + buffer[6]; - - /* Read apploader code */ - ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20); - if (ret < 0) return ret; - - /* Set apploader entry function */ - appldr_entry = (app_entry) buffer[4]; - - /* Call apploader entry */ - appldr_entry(&appldr_init, &appldr_main, &appldr_final); - - /* Initialize apploader */ - appldr_init(gprintf); - - if (fix002 != 0) - { - /* ERROR 002 fix (thanks to WiiPower for sharing this)*/ - *(u32 *) 0x80003188 = *(u32 *) 0x80003140; - } - - for (;;) - { - void *dst = NULL; - int len = 0, offset = 0; - - /* Run apploader main function */ - ret = appldr_main(&dst, &len, &offset); - if (!ret) break; - - /* Read data from DVD */ - WDVD_Read(dst, len, (u64) (offset << 2)); - - if( !alternatedol ) - gamepatches(dst, len, videoSelected, languageChoice, patchcountrystring, vipatch, cheat, returnTo, fix002 ); - - DCFlushRange(dst, len); - } - - *entry = appldr_final(); - - /** Load alternate dol if set **/ - if (alternatedol == 2) - { - wip_reset_counter(); - void *dolbuffer = NULL; - int dollen = 0; - - bool dolloaded = Load_Dol(&dolbuffer, &dollen, dolpath, videoSelected, languageChoice, patchcountrystring, vipatch, cheat, returnTo); - if (dolloaded) - { - *entry = (entry_point) load_dol_image(dolbuffer); - } - - if (dolbuffer) free(dolbuffer); - } - else if (alternatedol == 1) - { - wip_reset_counter(); - FST_ENTRY *fst = (FST_ENTRY *) *(u32 *) 0x80000038; - - *entry = (entry_point) Load_Dol_from_disc(fst[alternatedoloffset].fileoffset, videoSelected, languageChoice, - patchcountrystring, vipatch, cheat, returnTo); - } - - return 0; -} diff --git a/source/usbloader/apploader.h b/source/usbloader/apploader.h deleted file mode 100644 index 477a4884..00000000 --- a/source/usbloader/apploader.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _APPLOADER_H_ -#define _APPLOADER_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Entry point */ - typedef void (*entry_point)(void); - - /* Prototypes */ - s32 Apploader_Run(entry_point *entry, char * dolpath, u8 cheat, u8 videoSelected, u8 languageChoice, u8 vipatch, - u8 patchcountrystring, u8 alternatedol, u32 alternatedoloffset, u32 returnTo, u8 fix002); - void gamepatches( u8 * dst, int len, u8 videoSelected, u8 languageChoice, u8 patchcountrystring, u8 vipatch, u8 cheat, u32 returnTo, u8 fix002 ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/disc.c b/source/usbloader/disc.c deleted file mode 100644 index 4e930914..00000000 --- a/source/usbloader/disc.c +++ /dev/null @@ -1,406 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "patches/fst.h" -#include "patches/gamepatches.h" -#include "patches/wip.h" -#include "apploader.h" -#include "disc.h" -#include "video.h" -#include "wdvd.h" -#include "frag.h" -#include "alternatedol.h" -#include "memory/memory.h" -#include "wbfs.h" -#include "../settings/SettingsEnums.h" -#include "../gecko.h" -#include "../fatmounter.h" - -/* Constants */ -#define PTABLE_OFFSET 0x40000 -#define WII_MAGIC 0x5D1C9EA3 - -/* Disc pointers */ -static u32 *buffer = (u32 *) 0x93000000; -static u8 *diskid = (u8 *) Disc_ID; - -void __Disc_SetLowMem(void) -{ - - *Sys_Magic = 0x0D15EA5E; // Standard Boot Code - *Version = 0x00000001; // Version - *Arena_L = 0x00000000; // Arena Low - *BI2 = 0x817E5480; // BI2 - *Bus_Speed = 0x0E7BE2C0; // Console Bus Speed - *CPU_Speed = 0x2B73A840; // Console CPU Speed - - /* Setup low memory */ - *Assembler = 0x38A00040; // Assembler - *(u32 *) 0x800000E4 = 0x80431A80; - *Dev_Debugger = 0x81800000; // Dev Debugger Monitor Address - *Simulated_Mem = 0x01800000; // Simulated Memory Size - *(vu32 *) 0xCD00643C = 0x00000000; // 32Mhz on Bus - - //If the game is sam & max: season 1 put this shit in - if ((strncmp((char*) Disc_ID, "R3XE6U", 6) == 0) || (strncmp((char*) Disc_ID, "R3XP6V", 6) == 0)) - { - *GameID_Address = 0x80000000; // Game ID Address - } - - /* Copy disc ID */ - memcpy((void *) Online_Check, (void *) Disc_ID, 4); - - /* Flush cache */ - DCFlushRange((void *) Disc_ID, 0x3F00); -} - -void __Disc_SetVMode(u8 videoselected) -{ - GXRModeObj *vmode = NULL; - - u32 progressive, tvmode, vmode_reg = 0; - - /* Get video mode configuration */ - progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable(); - tvmode = CONF_GetVideo(); - - /* Select video mode register */ - switch (tvmode) - { - case CONF_VIDEO_PAL: - vmode_reg = (CONF_GetEuRGB60() > 0) ? 5 : 1; - break; - - case CONF_VIDEO_MPAL: - vmode_reg = 4; - break; - - case CONF_VIDEO_NTSC: - vmode_reg = 0; - break; - } - - switch (videoselected) - { - case VIDEO_MODE_PAL50: - vmode = &TVPal528IntDf; - vmode_reg = (vmode->viTVMode) >> 2; - break; - case VIDEO_MODE_PAL60: - vmode = (progressive) ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; - vmode_reg = (vmode->viTVMode) >> 2; - break; - case VIDEO_MODE_NTSC: - vmode = (progressive) ? &TVNtsc480Prog : &TVNtsc480IntDf; - vmode_reg = (vmode->viTVMode) >> 2; - break; - case VIDEO_MODE_SYSDEFAULT: - // vmode = VIDEO_GetPreferredMode(NULL); - break; - case VIDEO_MODE_DISCDEFAULT: - default: - /* Select video mode */ - switch (diskid[3]) - { - /* PAL */ - case 'P': - case 'D': - case 'F': - case 'I': - case 'S': - case 'H': - case 'X': - case 'Y': - case 'Z': - if (tvmode != CONF_VIDEO_PAL) - { - vmode_reg = 5; - vmode = (progressive) ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; - } - - break; - - /* NTSC or unknown */ - case 'E': - case 'J': - case 'K': - case 'W': - if (tvmode != CONF_VIDEO_NTSC) - { - vmode_reg = 0; - vmode = (progressive) ? &TVNtsc480Prog : &TVNtsc480IntDf; - } - - break; - } - break; - } - - /* Set video mode register */ - *Video_Mode = vmode_reg; - - /* Set video mode */ - if (vmode) - { - - VIDEO_Configure(vmode); - - /* Setup video */ - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - - if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); - } - gprintf("Video mode - %s\n", ((progressive) ? "progressive" : "interlaced")); - -} - -void __Disc_SetTime(void) -{ - /* Extern */ - extern void settime(u64); - - /* Set proper time */ - settime(secs_to_ticks( time( NULL ) - 946684800 )); -} - -s32 __Disc_FindPartition(u64 *outbuf) -{ - u64 offset = 0, table_offset = 0; - - u32 cnt, nb_partitions; - s32 ret; - - /* Read partition info */ - ret = WDVD_UnencryptedRead(buffer, 0x20, PTABLE_OFFSET); - if (ret < 0) return ret; - - /* Get data */ - nb_partitions = buffer[0]; - table_offset = buffer[1] << 2; - - /* Read partition table */ - ret = WDVD_UnencryptedRead(buffer, 0x20, table_offset); - if (ret < 0) return ret; - - /* Find game partition */ - for (cnt = 0; cnt < nb_partitions; cnt++) - { - u32 type = buffer[cnt * 2 + 1]; - - /* Game partition */ - if (!type) offset = buffer[cnt * 2] << 2; - } - - /* No game partition found */ - if (!offset) return -1; - - /* Set output buffer */ - *outbuf = offset; - - return 0; -} - -s32 Disc_Init(void) -{ - /* Init DVD subsystem */ - return WDVD_Init(); -} - -s32 Disc_Open(void) -{ - s32 ret; - - /* Reset drive */ - ret = WDVD_Reset(); - if (ret < 0) return ret; - - /* Read disc ID */ - return WDVD_ReadDiskId(diskid); -} - -s32 Disc_Wait(void) -{ - u32 cover = 0; - s32 ret; - - /* Wait for disc */ - while (!(cover & 0x2)) - { - /* Get cover status */ - ret = WDVD_GetCoverStatus(&cover); - if (ret < 0) return ret; - } - - return 0; -} - -s32 Disc_SetUSB(const u8 *id) -{ - if (wbfs_part_fs) - return set_frag_list((u8 *) id); - - u32 part = wbfs_part_idx ? wbfs_part_idx - 1 : 0; - - /* Set USB mode */ - return WDVD_SetUSBMode((u8 *) id, part); -} - -s32 Disc_ReadHeader(void *outbuf) -{ - /* Read disc header */ - return WDVD_UnencryptedRead(outbuf, sizeof(struct discHdr), 0); -} - -s32 Disc_IsWii(void) -{ - struct discHdr *header = (struct discHdr *) buffer; - - s32 ret; - - /* Read disc header */ - ret = Disc_ReadHeader(header); - if (ret < 0) return ret; - - /* Check magic word */ - if (header->magic != WII_MAGIC) return -1; - - return 0; -} - -s32 Disc_JumpToEntrypoint(u8 videoselected, bool enablecheat) -{ - /* Set an appropiate video mode */ - __Disc_SetVMode(videoselected); - - /* Set time */ - __Disc_SetTime(); - - // Anti-green screen fix - VIDEO_SetBlack(TRUE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - VIDEO_WaitVSync(); - gprintf("USB Loader GX is done.\n"); - - /* Shutdown IOS subsystems */ - extern void __exception_closeall(); - u32 level = IRQ_Disable(); - __IOS_ShutdownSubsystems(); - __exception_closeall(); - - if (enablecheat) - { - __asm__( - "lis %r3, AppEntrypoint@h\n" - "ori %r3, %r3, AppEntrypoint@l\n" - "lwz %r3, 0(%r3)\n" - "mtlr %r3\n" - "lis %r3, 0x8000\n" - "ori %r3, %r3, 0x18A8\n" - "mtctr %r3\n" - "bctr\n" - ); - } - else - { - __asm__( - "lis %r3, AppEntrypoint@h\n" - "ori %r3, %r3, AppEntrypoint@l\n" - "lwz %r3, 0(%r3)\n" - "mtlr %r3\n" - "blr\n" - ); - } - - IRQ_Restore(level); - - return 0; -} - -void PatchCountryStrings(void *Address, int Size) -{ - u8 SearchPattern[4] = { 0x00, 0x00, 0x00, 0x00 }; - u8 PatchData[4] = { 0x00, 0x00, 0x00, 0x00 }; - u8 *Addr = (u8*) Address; - - int wiiregion = CONF_GetRegion(); - - switch (wiiregion) - { - case CONF_REGION_JP: - SearchPattern[0] = 0x00; - SearchPattern[1] = 0x4A; // J - SearchPattern[2] = 0x50; // P - break; - case CONF_REGION_EU: - SearchPattern[0] = 0x02; - SearchPattern[1] = 0x45; // E - SearchPattern[2] = 0x55; // U - break; - case CONF_REGION_KR: - SearchPattern[0] = 0x04; - SearchPattern[1] = 0x4B; // K - SearchPattern[2] = 0x52; // R - break; - case CONF_REGION_CN: - SearchPattern[0] = 0x05; - SearchPattern[1] = 0x43; // C - SearchPattern[2] = 0x4E; // N - break; - case CONF_REGION_US: - default: - SearchPattern[0] = 0x01; - SearchPattern[1] = 0x55; // U - SearchPattern[2] = 0x53; // S - } - - switch (diskid[3]) - { - case 'J': - PatchData[1] = 0x4A; // J - PatchData[2] = 0x50; // P - break; - - case 'D': - case 'F': - case 'P': - case 'X': - case 'Y': - PatchData[1] = 0x45; // E - PatchData[2] = 0x55; // U - break; - - case 'E': - default: - PatchData[1] = 0x55; // U - PatchData[2] = 0x53; // S - } - - while (Size >= 4) - { - if (Addr[0] == SearchPattern[0] && Addr[1] == SearchPattern[1] && Addr[2] == SearchPattern[2] && Addr[3] - == SearchPattern[3]) - { - //*Addr = PatchData[0]; - Addr += 1; - *Addr = PatchData[1]; - Addr += 1; - *Addr = PatchData[2]; - Addr += 1; - //*Addr = PatchData[3]; - Addr += 1; - Size -= 4; - } - else - { - Addr += 4; - Size -= 4; - } - } -} diff --git a/source/usbloader/disc.h b/source/usbloader/disc.h deleted file mode 100644 index 3cbc4025..00000000 --- a/source/usbloader/disc.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _DISC_H_ -#define _DISC_H_ - -#include /* for define ATTRIBUTE_PACKED */ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Disc header structure */ - struct discHdr - { - /* Game ID */ - u8 id[6]; - - /* Game version */ - u16 version; - - /* Audio streaming */ - u8 streaming; - u8 bufsize; - - /* Padding */ - u8 is_ciso; - u8 unused1[13]; - - /* Magic word */ - u32 magic; - - /* Padding */ - u8 unused2[4]; - - /* Game title */ - char title[64]; - - /* Encryption/Hashing */ - u8 encryption; - u8 h3_verify; - - /* Padding */ - u8 unused3[30]; - } ATTRIBUTE_PACKED; - - /* Prototypes */ - s32 Disc_Init(void); - s32 Disc_Open(void); - s32 Disc_Wait(void); - void __Disc_SetLowMem(void); - s32 Disc_SetUSB(const u8 *); - s32 Disc_ReadHeader(void *); - s32 Disc_IsWii(void); - s32 __Disc_FindPartition(u64 *outbuf); - void PatchCountryStrings(void *Address, int Size); - s32 __Disc_FindPartition(u64 *outbuf); - s32 Disc_JumpToEntrypoint(u8 videoselected, bool enablecheat); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/frag.c b/source/usbloader/frag.c deleted file mode 100644 index 988467d8..00000000 --- a/source/usbloader/frag.c +++ /dev/null @@ -1,292 +0,0 @@ -#include -#include -#include -#include -#include - -#include "libs/libwbfs/libwbfs.h" -#include "libs/libfat/fatfile_frag.h" -#include "libs/libntfs/ntfsfile_frag.h" -#include "libs/libext2fs/ext2_frag.h" - -#include "usbloader/wbfs.h" -#include "usbloader/wdvd.h" -#include "usbloader/usbstorage2.h" -#include "frag.h" -#include "sys.h" -#include "gecko.h" - -#define SAFE_FREE(x) if(x) { free(x); x = NULL; } - -extern sec_t fs_ntfs_sec; -extern sec_t fs_ext_sec; - -static FragList *frag_list = NULL; - -void frag_init(FragList *ff, int maxnum) -{ - memset(ff, 0, sizeof(Fragment) * (maxnum+1)); - ff->maxnum = maxnum; -} - -void frag_dump(FragList *ff) -{ - int i; - gprintf("frag list: %d %d 0x%x\n", ff->num, ff->size, ff->size); - for (i=0; inum; i++) { - if (i>10) { - gprintf("...\n"); - break; - } - gprintf(" %d : %8x %8x %8x\n", i, - ff->frag[i].offset, - ff->frag[i].count, - ff->frag[i].sector); - } -} - -int frag_append(FragList *ff, u32 offset, u32 sector, u32 count) -{ - int n; - if (count) { - n = ff->num - 1; - if (ff->num > 0 - && ff->frag[n].offset + ff->frag[n].count == offset - && ff->frag[n].sector + ff->frag[n].count == sector) - { - // merge - ff->frag[n].count += count; - } - else - { - // add - if (ff->num >= ff->maxnum) { - // too many fragments - return -500; - } - n = ff->num; - ff->frag[n].offset = offset; - ff->frag[n].sector = sector; - ff->frag[n].count = count; - ff->num++; - } - } - ff->size = offset + count; - return 0; -} - -int _frag_append(void *ff, u32 offset, u32 sector, u32 count) -{ - return frag_append(ff, offset, sector, count); -} - -int frag_concat(FragList *ff, FragList *src) -{ - int i, ret; - u32 size = ff->size; - //printf("concat: %d %d <- %d %d\n", ff->num, ff->size, src->num, src->size); - for (i=0; inum; i++) { - ret = frag_append(ff, size + src->frag[i].offset, - src->frag[i].sector, src->frag[i].count); - if (ret) return ret; - } - ff->size = size + src->size; - //printf("concat: -> %d %d\n", ff->num, ff->size); - return 0; -} - -// in case a sparse block is requested, -// the returned poffset might not be equal to requested offset -// the difference should be filled with 0 -int frag_get(FragList *ff, u32 offset, u32 count, - u32 *poffset, u32 *psector, u32 *pcount) -{ - int i; - u32 delta; - //printf("frag_get(%u %u)\n", offset, count); - for (i=0; inum; i++) { - if (ff->frag[i].offset <= offset - && ff->frag[i].offset + ff->frag[i].count > offset) - { - delta = offset - ff->frag[i].offset; - *poffset = offset; - *psector = ff->frag[i].sector + delta; - *pcount = ff->frag[i].count - delta; - if (*pcount > count) *pcount = count; - goto out; - } - if (ff->frag[i].offset > offset - && ff->frag[i].offset < offset + count) - { - delta = ff->frag[i].offset - offset; - *poffset = ff->frag[i].offset; - *psector = ff->frag[i].sector; - *pcount = ff->frag[i].count; - count -= delta; - if (*pcount > count) *pcount = count; - goto out; - } - } - // not found - if (offset + count > ff->size) { - // error: out of range! - return -1; - } - // if inside range, then it must be just sparse, zero filled - // return empty block at the end of requested - *poffset = offset + count; - *psector = 0; - *pcount = 0; - out: - //printf("=>(%u %u %u)\n", *poffset, *psector, *pcount); - return 0; -} - -int frag_remap(FragList *ff, FragList *log, FragList *phy) -{ - int i; - int ret; - u32 offset; - u32 sector; - u32 count; - u32 delta; - for (i=0; inum; i++) { - delta = 0; - count = 0; - do { - ret = frag_get(phy, - log->frag[i].sector + delta + count, - log->frag[i].count - delta - count, - &offset, §or, &count); - if (ret) return ret; // error - delta = offset - log->frag[i].sector; - ret = frag_append(ff, log->frag[i].offset + delta, sector, count); - if (ret) return ret; // error - } while (count + delta < log->frag[i].count); - } - return 0; -} - -int get_frag_list_for_file(char *fname, u8 *id) -{ - char fname1[1024]; - struct stat st; - FragList *fs = NULL; - FragList *fa = NULL; - FragList *fw = NULL; - int ret; - int i, j; - int is_wbfs = 0; - int ret_val = -1; - - if (strcasecmp(strrchr(fname,'.'), ".wbfs") == 0) { - is_wbfs = 1; - } - - fs = malloc(sizeof(FragList)); - fa = malloc(sizeof(FragList)); - fw = malloc(sizeof(FragList)); - - frag_init(fa, MAX_FRAG); - - for (i=0; i<10; i++) { - frag_init(fs, MAX_FRAG); - if (i > 0) { - fname[strlen(fname)-1] = '0' + i; - if (stat(fname, &st) == -1) break; - } - strcpy(fname1, fname); - if (wbfs_part_fs == PART_FS_FAT) { - ret = _FAT_get_fragments(fname, &_frag_append, fs); - if (ret) { - // don't return failure, let it fallback to old method - //ret_val = ret; - ret_val = 0; - goto out; - } - } else if (wbfs_part_fs == PART_FS_NTFS) { - ret = _NTFS_get_fragments(fname, &_frag_append, fs); - if (ret) { - ret_val = ret; - goto out; - } - // offset to start of partition - for (j=0; jnum; j++) { - fs->frag[j].sector += fs_ntfs_sec; - } - } else if (wbfs_part_fs == PART_FS_EXT) { - ret = _EXT2_get_fragments(fname, &_frag_append, fs); - if (ret) { - ret_val = ret; - goto out; - } - // offset to start of partition - for (j=0; jnum; j++) { - fs->frag[j].sector += fs_ext_sec; - } - } - frag_concat(fa, fs); - } - - frag_list = malloc(sizeof(FragList)); - frag_init(frag_list, MAX_FRAG); - if (is_wbfs) { - // if wbfs file format, remap. - wbfs_disc_t *d = WBFS_OpenDisc(id); - if (!d) { ret_val = -4; goto out; } - frag_init(fw, MAX_FRAG); - ret = wbfs_get_fragments(d, &_frag_append, fw); - if (ret) { ret_val = -5; goto out; } - WBFS_CloseDisc(d); - // DEBUG: frag_list->num = MAX_FRAG-10; // stress test - ret = frag_remap(frag_list, fw, fa); - if (ret) { ret_val = -6; goto out; } - } else { - // .iso does not need remap just copy - memcpy(frag_list, fa, sizeof(FragList)); - } - - ret_val = 0; - -out: - if (ret_val) { - // error - SAFE_FREE(frag_list); - } - SAFE_FREE(fs); - SAFE_FREE(fa); - SAFE_FREE(fw); - - return ret_val; -} - -int get_frag_list(u8 *id) -{ - return WBFS_GetFragList(id); -} - -int set_frag_list(u8 *id) -{ - if (wbfs_part_fs == PART_FS_WBFS) return 1; - if (frag_list == NULL) { - return -2; - } - - // (+1 for header which is same size as fragment) - int size = sizeof(Fragment) * (frag_list->num + 1); - int ret; - DCFlushRange(frag_list, size); - - gprintf("Calling WDVD_SetFragList, frag list size %d\n", size); - ret = WDVD_SetFragList(wbfsDev, frag_list, size); - if (ret) { - return ret; - } - - // verify id matches - char discid[8]; - memset(discid, 0, sizeof(discid)); - ret = WDVD_UnencryptedRead(discid, 8, 0); - gprintf("Reading ID after setting fraglist: %s (expected: %s)\n", discid, id); - return (strncasecmp((char *) id, discid, 6) != 0) ? -3 : 0; -} diff --git a/source/usbloader/frag.h b/source/usbloader/frag.h deleted file mode 100644 index d3c48bd2..00000000 --- a/source/usbloader/frag.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _FRAG_H_ -#define _FRAG_H_ -// worst case wbfs fragmentation scenario: -// 9GB (dual layer) / 2mb (wbfs sector size) = 4608 -#define MAX_FRAG 20000 -// max that ehcmodule_frag will allow at the moment is about: -// 40000/4/3-1 = 21844 - -#ifdef __cplusplus -extern "C" { -#endif - -#include "gctypes.h" - -typedef struct -{ - u32 offset; // file offset, in sectors unit - u32 sector; - u32 count; -} Fragment; - -typedef struct -{ - u32 size; // num sectors - u32 num; // num fragments - u32 maxnum; - Fragment frag[MAX_FRAG]; -} FragList; - -void frag_init(FragList *ff, int maxnum); -void frag_dump(FragList *ff); -int frag_append(FragList *ff, u32 offset, u32 sector, u32 count); -int _frag_append(void *ff, u32 offset, u32 sector, u32 count); -int frag_concat(FragList *ff, FragList *src); - -// in case a sparse block is requested, -// the returned poffset might not be equal to requested offset -// the difference should be filled with 0 -int frag_get(FragList *ff, u32 offset, u32 count, u32 *poffset, u32 *psector, u32 *pcount); - -int frag_remap(FragList *ff, FragList *log, FragList *phy); - -int get_frag_list_for_file(char *fname, u8 *id); -int get_frag_list(u8 *id); -int set_frag_list(u8 *id); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/fstfile.c b/source/usbloader/fstfile.c deleted file mode 100644 index 116f1b34..00000000 --- a/source/usbloader/fstfile.c +++ /dev/null @@ -1,48 +0,0 @@ -#include - -#include "fstfile.h" - -char *fstfiles(FST_ENTRY *fst, u32 index) -{ - u32 count = fst[0].filelen; - u32 stringoffset; - if (index < count) - { - stringoffset = *(u32 *) &(fst[index]) % (256 * 256 * 256); - return (char *) ((u32) fst + count * 12 + stringoffset); - } - else - { - return NULL; - } -} - -char *fstfilename(u32 index) -{ - FST_ENTRY *fst = (FST_ENTRY *) *(u32 *) 0x80000038; - u32 count = fst[0].filelen; - u32 stringoffset; - if (index < count) - { - stringoffset = *(u32 *) &(fst[index]) % (256 * 256 * 256); - return (char *) (*(u32 *) 0x80000038 + count * 12 + stringoffset); - } - else - { - return NULL; - } -} - -u32 fstfileoffset(u32 index) -{ - FST_ENTRY *fst = (FST_ENTRY *) *(u32 *) 0x80000038; - u32 count = fst[0].filelen; - if (index < count) - { - return fst[index].fileoffset; - } - else - { - return 0; - } -} diff --git a/source/usbloader/fstfile.h b/source/usbloader/fstfile.h deleted file mode 100644 index dc72b14b..00000000 --- a/source/usbloader/fstfile.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _FSTFILE_H_ -#define _FSTFILE_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - typedef struct - { - u8 filetype; - char name_offset[3]; - u32 fileoffset; - u32 filelen; - }__attribute__( ( packed ) ) FST_ENTRY; - - char *fstfiles(FST_ENTRY *fst, u32 index); - char *fstfilename(u32 index); - u32 fstfileoffset(u32 index); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/partition_usbloader.c b/source/usbloader/partition_usbloader.c deleted file mode 100644 index 52974067..00000000 --- a/source/usbloader/partition_usbloader.c +++ /dev/null @@ -1,428 +0,0 @@ -// Modified by oggzee - -#include -#include -#include -#include - -#include "partition_usbloader.h" -#include "sdhc.h" -#include "usbstorage2.h" -#include "utils.h" -#include "wbfs.h" -#include "libs/libwbfs/libwbfs.h" - -/* 'partition table' structure */ -typedef struct -{ - /* Zero bytes */ - u8 padding[446]; - - /* Partition table entries */ - partitionEntry entries[MAX_PARTITIONS]; -}ATTRIBUTE_PACKED partitionTable; - -s32 Partition_GetEntries(u32 device, partitionEntry *outbuf, u32 *outval) -{ - static partitionTable table ATTRIBUTE_ALIGN( 32 ); - - u32 cnt, sector_size; - s32 ret; - - /* Read from specified device */ - switch (device) - { - case WBFS_DEVICE_USB: - { - /* Get sector size */ - ret = USBStorage2_GetCapacity(§or_size); - if (ret == 0) return -1; - - /* Read partition table */ - ret = USBStorage2_ReadSectors(0, 1, &table); - if (ret < 0) return ret; - - break; - } - - case WBFS_DEVICE_SDHC: - { - /* SDHC sector size */ - sector_size = SDHC_SECTOR_SIZE; - - /* Read partition table */ - ret = SDHC_ReadSectors(0, 1, &table); - if (!ret) return -1; - - break; - } - - default: - return -1; - } - - /* Swap endianess */ - for (cnt = 0; cnt < 4; cnt++) - { - partitionEntry *entry = &table.entries[cnt]; - - entry->sector = swap32(entry->sector); - entry->size = swap32(entry->size); - } - - /* Set partition entries */ - memcpy(outbuf, table.entries, sizeof(table.entries)); - - /* Set sector size */ - *outval = sector_size; - - return 0; -} - -bool Device_ReadSectors(u32 device, u32 sector, u32 count, void *buffer) -{ - s32 ret; - - /* Read from specified device */ - switch (device) - { - case WBFS_DEVICE_USB: - ret = USBStorage2_ReadSectors(sector, count, buffer); - if (ret < 0) return false; - return true; - - case WBFS_DEVICE_SDHC: - return SDHC_ReadSectors(sector, count, buffer); - } - - return false; -} - -bool Device_WriteSectors(u32 device, u32 sector, u32 count, void *buffer) -{ - s32 ret; - - /* Read from specified device */ - switch (device) - { - case WBFS_DEVICE_USB: - ret = USBStorage2_WriteSectors(sector, count, buffer); - if (ret < 0) return false; - return true; - - case WBFS_DEVICE_SDHC: - return SDHC_WriteSectors(sector, count, buffer); - } - - return false; -} - -s32 Partition_GetEntriesEx(u32 device, partitionEntry *outbuf, u32 *psect_size, u8 *num) -{ - static u8 Buffer[sizeof(partitionTable)] ATTRIBUTE_ALIGN( 32 ); - partitionTable *table = (partitionTable *) Buffer; - partitionEntry *entry; - - u32 i, sector_size; - s32 ret; - int maxpart = *num; - - // Get sector size - switch (device) - { - case WBFS_DEVICE_USB: - ret = USBStorage2_GetCapacity(§or_size); - if (ret == 0) return -1; - break; - case WBFS_DEVICE_SDHC: - sector_size = SDHC_SECTOR_SIZE; - break; - default: - return -1; - } - /* Set sector size */ - *psect_size = sector_size; - - u32 ext = 0; - u32 next = 0; - - // Read partition table - ret = Device_ReadSectors(device, 0, 1, table); - if (!ret) return -1; - // Check if it's a RAW WBFS disc, without partition table - if (get_fs_type((u8 *) table) == FS_TYPE_WBFS) - { - memset(outbuf, 0, sizeof(table->entries)); - wbfs_head_t * head = (wbfs_head_t *) Buffer; - outbuf->size = wbfs_ntohl( head->n_hd_sec ); - *num = 1; - return 0; - } - /* Swap endianess */ - for (i = 0; i < 4; i++) - { - entry = &table->entries[i]; - entry->sector = swap32(entry->sector); - entry->size = swap32(entry->size); - if (!ext && part_is_extended(entry->type)) - { - ext = entry->sector; - } - } - /* Set partition entries */ - memcpy(outbuf, table->entries, sizeof(table->entries)); - // num primary - *num = 4; - - if (!ext) return 0; - - next = ext; - // scan extended partition for logical - for (i = 0; i < maxpart - 4; i++) - { - ret = Device_ReadSectors(device, next, 1, table); - if (!ret) break; - if (i == 0) - { - // handle the invalid scenario where wbfs is on an EXTENDED - // partition instead of on the Logical inside Extended. - if (get_fs_type((u8 *) table) == FS_TYPE_WBFS) break; - } - entry = &table->entries[0]; - entry->sector = swap32(entry->sector); - entry->size = swap32(entry->size); - if (entry->type && entry->size && entry->sector) - { - // rebase to abolute address - entry->sector += next; - // add logical - memcpy(&outbuf[*num], entry, sizeof(*entry)); - (*num)++; - // get next - entry++; - if (entry->type && entry->size && entry->sector) - { - next = ext + swap32(entry->sector); - } - else - { - break; - } - } - } - - return 0; -} - -bool part_is_extended(int type) -{ - if (type == 0x05) return true; - if (type == 0x0f) return true; - return false; -} - -bool part_is_data(int type) -{ - if (type && !part_is_extended(type)) return true; - return false; -} - -bool part_valid_data(partitionEntry *entry) -{ - if (entry->size && entry->type && entry->sector) - { - return part_is_data(entry->type); - } - return false; -} - -char* part_type_data(int type) -{ - switch (type) - { - case 0x01: - return "FAT12"; - case 0x04: - return "FAT16"; - case 0x06: - return "FAT16"; //+ - case 0x07: - return "NTFS"; - case 0x0b: - return "FAT32"; - case 0x0c: - return "FAT32"; - case 0x0e: - return "FAT16"; - case 0x82: - return "LxSWP"; - case 0x83: - return "LINUX"; - case 0x8e: - return "LxLVM"; - case 0xa8: - return "OSX"; - case 0xab: - return "OSXBT"; - case 0xaf: - return "OSXHF"; - case 0xe8: - return "LUKS"; - } - return NULL; -} - -char *part_type_name(int type) -{ - static char unk[8]; - if (type == 0) return "UNUSED"; - if (part_is_extended(type)) return "EXTEND"; - char *p = part_type_data(type); - if (p) return p; - sprintf(unk, "UNK-%02x", type); - return unk; -} - -int get_fs_type(u8 *buff) -{ - // WBFS - wbfs_head_t *head = (wbfs_head_t *) buff; - if (head->magic == wbfs_htonl( WBFS_MAGIC )) return FS_TYPE_WBFS; - // 55AA - if(*((u16 *) (buff + 0x1FE)) == 0x55AA) - { - // FAT - if (memcmp(buff + 0x36, "FAT", 3) == 0) return FS_TYPE_FAT16; - if (memcmp(buff + 0x52, "FAT", 3) == 0) return FS_TYPE_FAT32; - // NTFS - if (memcmp(buff + 0x03, "NTFS", 4) == 0) return FS_TYPE_NTFS; - } - - return FS_TYPE_UNK; -} - -int get_part_fs(int fs_type) -{ - switch (fs_type) - { - case FS_TYPE_FAT32: - return PART_FS_FAT; - case FS_TYPE_NTFS: - return PART_FS_NTFS; - case FS_TYPE_WBFS: - return PART_FS_WBFS; - case FS_TYPE_EXT: - return PART_FS_EXT; - default: - return -1; - } -} - -bool is_type_fat(int type) -{ - return (type == FS_TYPE_FAT16 || type == FS_TYPE_FAT32); -} - -char *get_fs_name(int i) -{ - switch (i) - { - case FS_TYPE_FAT16: - return "FAT16"; - case FS_TYPE_FAT32: - return "FAT32"; - case FS_TYPE_NTFS: - return "NTFS"; - case FS_TYPE_EXT: - return "EXT"; - case FS_TYPE_WBFS: - return "WBFS"; - } - return ""; -} - -s32 Partition_GetList(u32 device, PartList *plist) -{ - partitionEntry *entry = NULL; - PartInfo *pinfo = NULL; - int i, ret; - - memset(plist, 0, sizeof(PartList)); - - // Get partition entries - plist->num = MAX_PARTITIONS_EX; - ret = Partition_GetEntriesEx(device, plist->pentry, &plist->sector_size, &plist->num); - if (ret < 0) - { - return -1; - } - // check for RAW WBFS disc - if (plist->num == 1) - { - pinfo = &plist->pinfo[0]; - entry = &plist->pentry[0]; - plist->wbfs_n = 1; - pinfo->wbfs_i = pinfo->index = 1; - return 0; - } - - char buf[plist->sector_size]; - - // scan partitions for filesystem type - for (i = 0; i < plist->num; i++) - { - pinfo = &plist->pinfo[i]; - entry = &plist->pentry[i]; - if (!entry->size) continue; - if (!entry->type) continue; - if (!entry->sector) continue; - // even though wrong, it's possible WBFS is on an extended part. - //if (!part_is_data(entry->type)) continue; - if (!Device_ReadSectors(device, entry->sector, 1, buf)) continue; - pinfo->fs_type = get_fs_type((u8 *) buf); - if(entry->type == 0x83 && pinfo->fs_type == FS_TYPE_UNK) pinfo->fs_type = FS_TYPE_EXT; - if (pinfo->fs_type == FS_TYPE_WBFS) - { - // multiple wbfs on sdhc not supported - if (device == WBFS_DEVICE_SDHC && (plist->wbfs_n > 1 || i > 4)) continue; - plist->wbfs_n++; - pinfo->wbfs_i = pinfo->index = plist->wbfs_n; - } - else if (is_type_fat(pinfo->fs_type)) - { - plist->fat_n++; - pinfo->fat_i = pinfo->index = plist->fat_n; - } - else if (pinfo->fs_type == FS_TYPE_NTFS) - { - plist->ntfs_n++; - pinfo->ntfs_i = pinfo->index = plist->ntfs_n; - } - else if (pinfo->fs_type == FS_TYPE_EXT) - { - plist->ext_n++; - pinfo->ext_i = pinfo->index = plist->ext_n; - } - pinfo->part_fs = get_part_fs(pinfo->fs_type); - } - return 0; -} - -int Partition_FixEXT(u32 device, u8 part) -{ - static partitionTable table ATTRIBUTE_ALIGN( 32 ); - int ret; - - if (part > 3) return -1; - // Read partition table - ret = Device_ReadSectors(device, 0, 1, &table); - if (!ret) return -1; - if (part_is_extended(table.entries[part].type)) - { - table.entries[part].type = 0x0b; // FAT32 - ret = Device_WriteSectors(device, 0, 1, &table); - if (!ret) return -1; - return 0; - } - return -1; -} diff --git a/source/usbloader/partition_usbloader.h b/source/usbloader/partition_usbloader.h deleted file mode 100644 index 703b3433..00000000 --- a/source/usbloader/partition_usbloader.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _PARTITION_H_ -#define _PARTITION_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* 'partition entry' structure */ - typedef struct - { - /* Boot indicator */ - u8 boot; - - /* Starting CHS */ - u8 start[3]; - - /* Partition type */ - u8 type; - - /* Ending CHS */ - u8 end[3]; - - /* Partition sector */ - u32 sector; - - /* Partition size */ - u32 size; - }ATTRIBUTE_PACKED partitionEntry; - - /* Constants */ -#define MAX_PARTITIONS 4 -#define MAX_PARTITIONS_EX 10 - -#define FS_TYPE_UNK 0 -#define FS_TYPE_FAT16 1 -#define FS_TYPE_FAT32 2 -#define FS_TYPE_NTFS 3 -#define FS_TYPE_WBFS 4 -#define FS_TYPE_EXT 5 - - typedef struct - { - u8 fs_type; - u8 part_fs; - u8 wbfs_i; // seq wbfs part index - u8 fat_i; // seq fat part index - u8 ntfs_i; // seq ntfs part index - u8 ext_i; // seq ntfs part index - u8 index; - } PartInfo; - - typedef struct - { - u8 num; - u32 sector_size; - partitionEntry pentry[MAX_PARTITIONS_EX]; - u8 wbfs_n; - u8 fat_n; - u8 ntfs_n; - u8 ext_n; - PartInfo pinfo[MAX_PARTITIONS_EX]; - } PartList; - - /* Prototypes */ - s32 Partition_GetEntries(u32 device, partitionEntry *outbuf, u32 *outval); - s32 Partition_GetEntriesEx(u32 device, partitionEntry *outbuf, u32 *outval, u8 *num); - bool Device_ReadSectors(u32 device, u32 sector, u32 count, void *buffer); - bool Device_WriteSectors(u32 device, u32 sector, u32 count, void *buffer); - s32 Partition_GetList(u32 device, PartList *plist); - int Partition_FixEXT(u32 device, u8 part); - - bool part_is_extended(int type); - bool part_is_data(int type); - char* part_type_data(int type); - char* part_type_name(int type); - bool part_valid_data(partitionEntry *entry); - int get_fs_type(u8 *buf); - bool is_type_fat(int type); - char* get_fs_name(int i); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/sdhc.c b/source/usbloader/sdhc.c deleted file mode 100644 index 249fe790..00000000 --- a/source/usbloader/sdhc.c +++ /dev/null @@ -1,215 +0,0 @@ -#include -#include -#include -#include - -#include "sdhc.h" - -/* IOCTL comamnds */ -#define IOCTL_SDHC_INIT 0x01 -#define IOCTL_SDHC_READ 0x02 -#define IOCTL_SDHC_WRITE 0x03 -#define IOCTL_SDHC_ISINSERTED 0x04 - -#define SDHC_HEAPSIZE 0x8000 -#define SDHC_MEM2_SIZE 0x10000 - -int sdhc_mode_sd = 0; - -/* Variables */ -static char fs[] ATTRIBUTE_ALIGN( 32 ) = "/dev/sdio/sdhc"; - -static s32 hid = -1, fd = -1; -static u32 sector_size = SDHC_SECTOR_SIZE; -static void *sdhc_buf2; - -extern void* SYS_AllocArena2MemLo(u32 size, u32 align); - -bool SDHC_Init(void) -{ - s32 ret; - - if (sdhc_mode_sd) - { - return __io_wiisd.startup(); - } - - /* Already open */ - if (fd >= 0) return true; - - /* Create heap */ - if (hid < 0) - { - hid = iosCreateHeap(SDHC_HEAPSIZE); - if (hid < 0) goto err; - } - - // allocate buf2 - if (sdhc_buf2 == NULL) - { - sdhc_buf2 = SYS_AllocArena2MemLo(SDHC_MEM2_SIZE, 32); - } - - /* Open SDHC device */ - fd = IOS_Open(fs, 0); - if (fd < 0) goto err; - - /* Initialize SDHC */ - ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_INIT, ":"); - if (ret) goto err; - - return true; - - err: - /* Close SDHC device */ - if (fd >= 0) - { - IOS_Close(fd); - fd = -1; - } - - return false; -} - -bool SDHC_Close(void) -{ - if (sdhc_mode_sd) - { - return __io_wiisd.shutdown(); - } - - /* Close SDHC device */ - if (fd >= 0) - { - IOS_Close(fd); - fd = -1; - } - - /*if (hid > 0) { - iosDestroyHeap(hid); - hid = -1; - }*/ - - return true; -} - -bool SDHC_IsInserted(void) -{ - s32 ret; - if (sdhc_mode_sd) - { - return __io_wiisd.isInserted(); - } - - /* Check if SD card is inserted */ - ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_ISINSERTED, ":"); - - return (!ret) ? true : false; -} - -bool SDHC_ReadSectors(u32 sector, u32 count, void *buffer) -{ - //printf("SD-R(%u %u)\n", sector, count); - if (sdhc_mode_sd) - { - return __io_wiisd.readSectors(sector, count, buffer); - } - - void *buf = (void *) buffer; - u32 len = (sector_size * count); - - s32 ret; - - /* Device not opened */ - if (fd < 0) return false; - - /* Buffer not aligned */ - if ((u32) buffer & 0x1F) - { - /* Allocate memory */ - //buf = iosAlloc(hid, len); - buf = sdhc_buf2; - if (!buf) return false; - } - - /* Read data */ - ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_READ, "ii:d", sector, count, buf, len); - - /* Copy data */ - if (buf != buffer) - { - memcpy(buffer, buf, len); - //iosFree(hid, buf); - } - - return (!ret) ? true : false; -} - -bool SDHC_WriteSectors(u32 sector, u32 count, void *buffer) -{ - if (sdhc_mode_sd) - { - return __io_wiisd.writeSectors(sector, count, buffer); - } - - void *buf = (void *) buffer; - u32 len = (sector_size * count); - - s32 ret; - - /* Device not opened */ - if (fd < 0) return false; - - /* Buffer not aligned */ - if ((u32) buffer & 0x1F) - { - /* Allocate memory */ - //buf = iosAlloc(hid, len); - buf = sdhc_buf2; - if (!buf) return false; - - /* Copy data */ - memcpy(buf, buffer, len); - } - - /* Read data */ - ret = IOS_IoctlvFormat(hid, fd, IOCTL_SDHC_WRITE, "ii:d", sector, count, buf, len); - - /* Free memory */ - //if (buf != buffer) - // iosFree(hid, buf); - - return (!ret) ? true : false; -} - -bool SDHC_ClearStatus(void) -{ - return true; -} - -bool __io_SDHC_Close(void) -{ - // do nothing. - return true; -} - -bool __io_SDHC_NOP(void) -{ - // do nothing. - return true; -} - -const DISC_INTERFACE __io_sdhc = { DEVICE_TYPE_WII_SD, FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE - | FEATURE_WII_SD, (FN_MEDIUM_STARTUP) &SDHC_Init, (FN_MEDIUM_ISINSERTED) &SDHC_IsInserted, - (FN_MEDIUM_READSECTORS) &SDHC_ReadSectors, (FN_MEDIUM_WRITESECTORS) &SDHC_WriteSectors, - (FN_MEDIUM_CLEARSTATUS) &SDHC_ClearStatus, - //(FN_MEDIUM_SHUTDOWN)&SDHC_Close - (FN_MEDIUM_SHUTDOWN) &__io_SDHC_Close }; - -const DISC_INTERFACE __io_sdhc_ro = { DEVICE_TYPE_WII_SD, FEATURE_MEDIUM_CANREAD | FEATURE_WII_SD, - (FN_MEDIUM_STARTUP) &SDHC_Init, (FN_MEDIUM_ISINSERTED) &SDHC_IsInserted, - (FN_MEDIUM_READSECTORS) &SDHC_ReadSectors, (FN_MEDIUM_WRITESECTORS) &__io_SDHC_NOP, // &SDHC_WriteSectors, - (FN_MEDIUM_CLEARSTATUS) &SDHC_ClearStatus, - //(FN_MEDIUM_SHUTDOWN)&SDHC_Close - (FN_MEDIUM_SHUTDOWN) &__io_SDHC_Close }; - diff --git a/source/usbloader/sdhc.h b/source/usbloader/sdhc.h deleted file mode 100644 index 7c405fed..00000000 --- a/source/usbloader/sdhc.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _SDHC_H_ -#define _SDHC_H_ - -/* Constants */ -#define SDHC_SECTOR_SIZE 0x200 - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Prototypes */ - bool SDHC_Init(void); - bool SDHC_Close(void); - bool SDHC_ReadSectors(u32, u32, void *); - bool SDHC_WriteSectors(u32, u32, void *); - extern int sdhc_mode_sd; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/splits.c b/source/usbloader/splits.c deleted file mode 100644 index d75a80bf..00000000 --- a/source/usbloader/splits.c +++ /dev/null @@ -1,348 +0,0 @@ -// by oggzee - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "splits.h" - -#define off64_t off_t -#define FMT_llu "%llu" -#define FMT_lld "%lld" - -#define split_error(x) do { printf("\nsplit error: %s\n\n",x); } while(0) - -// 1 cluster less than 4gb -u64 OPT_split_size = (u64) 4LL * 1024 * 1024 * 1024 - 32 * 1024; -// 1 cluster less than 2gb -//u64 OPT_split_size = (u64)2LL * 1024 * 1024 * 1024 - 32 * 1024; - -//split_info_t split; - -void split_get_fname(split_info_t *s, int idx, char *fname) -{ - strcpy(fname, s->fname); - if (idx == 0 && s->create_mode) - { - strcat(fname, ".tmp"); - } - else if (idx > 0) - { - char *c = fname + strlen(fname) - 1; - *c = '0' + idx; - } -} - -int split_open_file(split_info_t *s, int idx) -{ - int fd = s->fd[idx]; - if (fd >= 0) return fd; - char fname[1024]; - split_get_fname(s, idx, fname); - //char *mode = s->create_mode ? "wb+" : "rb+"; - int mode = s->create_mode ? (O_CREAT | O_RDWR) : O_RDWR; - //printf("SPLIT OPEN %s %s %d\n", fname, mode, idx); //Wpad_WaitButtons(); - //f = fopen(fname, mode); - fd = open(fname, mode); - if (fd < 0) return -1; - if (idx > 0 && s->create_mode) - { - printf("%s Split: %d %s \n", s->create_mode ? "Create" : "Read", idx, fname); - } - s->fd[idx] = fd; - return fd; -} - -// faster as it uses larger chunks than ftruncate internally -int write_zero(int fd, off_t size) -{ - int buf[0x4000]; //64kb - int chunk; - int ret; - memset(buf, 0, sizeof(buf)); - while (size) - { - chunk = size; - if (chunk > sizeof(buf)) chunk = sizeof(buf); - ret = write(fd, buf, chunk); - //printf("WZ %d %d / %lld \n", ret, chunk, size); - size -= chunk; - if (ret < 0) return ret; - } - return 0; -} - -int split_fill(split_info_t *s, int idx, u64 size) -{ - int fd = split_open_file(s, idx); - off64_t fsize = lseek(fd, 0, SEEK_END); - if (fsize < size) - { - //printf("TRUNC %d "FMT_lld"\n", idx, size); Wpad_WaitButtons(); - //ftruncate(fd, size); - write_zero(fd, size - fsize); - return 1; - } - return 0; -} - -int split_get_file(split_info_t *s, u32 lba, u32 *sec_count, int fill) -{ - int fd; - if (lba >= s->total_sec) - { - fprintf(stderr, "SPLIT: invalid sector %u / %u\n", lba, (u32) s->total_sec); - return -1; - } - int idx; - idx = lba / s->split_sec; - if (idx >= s->max_split) - { - fprintf(stderr, "SPLIT: invalid split %d / %d\n", idx, s->max_split - 1); - return -1; - } - fd = s->fd[idx]; - if (fd < 0) - { - // opening new, make sure all previous are full - int i; - for (i = 0; i < idx; i++) - { - if (split_fill(s, i, s->split_size)) - { - printf("FILL %d\n", i); - } - } - fd = split_open_file(s, idx); - } - if (fd < 0) - { - fprintf(stderr, "SPLIT %d: no file\n", idx); - return -1; - } - u32 sec = lba % s->split_sec; // inside file - off64_t off = (off64_t ) sec * 512; - // num sectors till end of file - u32 to_end = s->split_sec - sec; - if (*sec_count > to_end) *sec_count = to_end; - if (s->create_mode) - { - if (fill) - { - // extend, so that read will be succesfull - split_fill(s, idx, off + 512 * (*sec_count)); - } - else - { - // fill up so that write continues from end of file - // shouldn't be necessary, but libfat looks buggy - // and this is faster - split_fill(s, idx, off); - } - } - lseek(fd, off, SEEK_SET); - return fd; -} - -int split_read_sector(void *_fp, u32 lba, u32 count, void*buf) -{ - split_info_t *s = _fp; - int fd; - u64 off = lba; - off *= 512ULL; - int i; - u32 chunk; - size_t ret; - //fprintf(stderr,"READ %d %d\n", lba, count); - for (i = 0; i < (int) count; i += chunk) - { - chunk = count - i; - fd = split_get_file(s, lba + i, &chunk, 1); - if (fd < 0) - { - fprintf(stderr, "\n\n"FMT_lld" %d %p\n", off, count, _fp); - split_error( "error seeking in disc partition" ); - return 1; - } - void *ptr = ((u8 *) buf) + (i * 512); - ret = read(fd, ptr, chunk * 512); - if (ret != chunk * 512) - { - fprintf(stderr, "error reading %u %u [%u] %u = %u\n", lba, count, i, chunk, ret); - split_error( "error reading disc" ); - return 1; - } - } - return 0; -} - -int split_write_sector(void *_fp, u32 lba, u32 count, void*buf) -{ - split_info_t *s = _fp; - int fd; - u64 off = lba; - off *= 512ULL; - int i; - u32 chunk; - size_t ret; - //printf("WRITE %d %d %p \n", lba, count, buf); - for (i = 0; i < (int) count; i += chunk) - { - chunk = count - i; - fd = split_get_file(s, lba + i, &chunk, 0); - //if (chunk != count) - // fprintf(stderr, "WRITE CHUNK %d %d/%d\n", lba+i, chunk, count); - if (fd < 0 || !chunk) - { - fprintf(stderr, "\n\n"FMT_lld" %d %p\n", off, count, _fp); - split_error( "error seeking in disc partition" ); - return 1; - } - //if (fwrite(buf+i*512, 512ULL, chunk, f) != chunk) { - //printf("write %d %p %d \n", fd, buf+i*512, chunk * 512); - void *ptr = ((u8 *) buf) + (i * 512); - ret = write(fd, ptr, chunk * 512); - //printf("write ret = %d \n", ret); - if (ret != chunk * 512) - { - split_error( "error writing disc" ); - return 1; - } - } - return 0; -} - -void split_init(split_info_t *s, char *fname) -{ - int i; - char *p; - //fprintf(stderr, "SPLIT_INIT %s\n", fname); - memset(s, 0, sizeof(*s)); - for (i = 0; i < MAX_SPLIT; i++) - { - s->fd[i] = -1; - } - strcpy(s->fname, fname); - s->max_split = 1; - p = strrchr(fname, '.'); - if (p && (strcasecmp(p, ".wbfs") == 0)) - { - s->max_split = MAX_SPLIT; - } -} - -void split_set_size(split_info_t *s, u64 split_size, u64 total_size) -{ - s->total_size = total_size; - s->split_size = split_size; - s->total_sec = total_size / 512; - s->split_sec = split_size / 512; -} - -void split_close(split_info_t *s) -{ - int i; - char fname[1024]; - char tmpname[1024]; - for (i = 0; i < s->max_split; i++) - { - if (s->fd[i] >= 0) - { - close(s->fd[i]); - } - } - if (s->create_mode) - { - split_get_fname(s, -1, fname); - split_get_fname(s, 0, tmpname); - rename(tmpname, fname); - } - memset(s, 0, sizeof(*s)); -} - -int split_create(split_info_t *s, char *fname, u64 split_size, u64 total_size, bool overwrite) -{ - int i; - int fd; - char sname[1024]; - int error = 0; - split_init(s, fname); - s->create_mode = 1; - // check if any file already exists - for (i = -1; i < s->max_split; i++) - { - split_get_fname(s, i, sname); - if (overwrite) - { - remove(sname); - } - else - { - fd = open(sname, O_RDONLY); - if (fd >= 0) - { - fprintf(stderr, "Error: file already exists: %s\n", sname); - close(fd); - error = 1; - } - } - } - if (error) - { - split_init(s, ""); - return -1; - } - split_set_size(s, split_size, total_size); - return 0; -} - -int split_open(split_info_t *s, char *fname) -{ - int i; - u64 size = 0; - u64 total_size = 0; - u64 split_size = 0; - int fd; - split_init(s, fname); - for (i = 0; i < s->max_split; i++) - { - fd = split_open_file(s, i); - if (fd < 0) - { - if (i == 0) goto err; - break; - } - // check previous size - all splits except last must be same size - if (i > 0 && size != split_size) - { - fprintf(stderr, "split %d: invalid size "FMT_lld"", i, size); - goto err; - } - // get size - //fseeko(f, 0, SEEK_END); - //size = ftello(f); - size = lseek(fd, 0, SEEK_END); - // check sector alignment - if (size % 512) - { - fprintf(stderr, "split %d: size ("FMT_lld") not sector (512) aligned!", i, size); - } - // first sets split size - if (i == 0) - { - split_size = size; - } - total_size += size; - } - split_set_size(s, split_size, total_size); - return 0; - err: split_close(s); - return -1; -} - diff --git a/source/usbloader/splits.h b/source/usbloader/splits.h deleted file mode 100644 index 7969cf4e..00000000 --- a/source/usbloader/splits.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _SPLITS_H -#define _SPLITS_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define MAX_SPLIT 10 - - typedef struct split_info - { - char fname[1024]; - //FILE *f[MAX_SPLIT]; - int fd[MAX_SPLIT]; - //u64 fsize[MAX_SPLIT]; - u32 split_sec; - u32 total_sec; - u64 split_size; - u64 total_size; - int create_mode; - int max_split; - } split_info_t; - - // 1 sector less than 4gb - extern u64 OPT_split_size; - - void split_get_fname(split_info_t *s, int idx, char *fname); - //FILE *split_open_file(split_info_t *s, int idx); - //FILE *split_get_file(split_info_t *s, u32 lba, u32 *sec_count, int fill); - int split_open_file(split_info_t *s, int idx); - int split_get_file(split_info_t *s, u32 lba, u32 *sec_count, int fill); - int split_fill(split_info_t *s, int idx, u64 size); - int split_read_sector(void *_fp, u32 lba, u32 count, void*buf); - int split_write_sector(void *_fp, u32 lba, u32 count, void*buf); - void split_init(split_info_t *s, char *fname); - void split_set_size(split_info_t *s, u64 split_size, u64 total_size); - void split_close(split_info_t *s); - int split_open(split_info_t *s, char *fname); - int split_create(split_info_t *s, char *fname, u64 split_size, u64 total_size, bool overwrite); - -#ifdef __cplusplus -} -#endif - -#endif //_SPLITS_H diff --git a/source/usbloader/usbstorage2.c b/source/usbloader/usbstorage2.c deleted file mode 100644 index 19027a7a..00000000 --- a/source/usbloader/usbstorage2.c +++ /dev/null @@ -1,344 +0,0 @@ -/*------------------------------------------------------------- - - 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 - 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 - damages arising from the use of this software. - - Permission is granted to anyone to use this software for any - purpose, including commercial applications, and to alter it and - redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you - must not claim that you wrote the original software. If you use - this software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and - must not be misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. - - -------------------------------------------------------------*/ - -#include -#include -#include -#include -#include "usbstorage2.h" -#include "memory/mem2.h" - - -/* IOCTL commands */ -#define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) -#define USB_IOCTL_UMS_INIT (UMS_BASE+0x1) -#define USB_IOCTL_UMS_GET_CAPACITY (UMS_BASE+0x2) -#define USB_IOCTL_UMS_READ_SECTORS (UMS_BASE+0x3) -#define USB_IOCTL_UMS_WRITE_SECTORS (UMS_BASE+0x4) -#define USB_IOCTL_UMS_READ_STRESS (UMS_BASE+0x5) -#define USB_IOCTL_UMS_SET_VERBOSE (UMS_BASE+0x6) -#define USB_IOCTL_UMS_UMOUNT (UMS_BASE+0x10) -#define USB_IOCTL_UMS_WATCHDOG (UMS_BASE+0x80) - -#define USB_IOCTL_UMS_TESTMODE (UMS_BASE+0x81) - -#define WBFS_BASE (('W'<<24)|('F'<<16)|('S'<<8)) -#define USB_IOCTL_WBFS_OPEN_DISC (WBFS_BASE+0x1) -#define USB_IOCTL_WBFS_READ_DISC (WBFS_BASE+0x2) -#define USB_IOCTL_WBFS_SET_DEVICE (WBFS_BASE+0x50) -#define USB_IOCTL_WBFS_SET_FRAGLIST (WBFS_BASE+0x51) - -#define isMEM2Buffer(p) (((u32) p & 0x10000000) != 0) - -#define MAX_BUFFER_SECTORS 256 -#define UMS_HEAPSIZE 0x1000 - -/* Variables */ -static char fs[] ATTRIBUTE_ALIGN(32) = "/dev/usb2"; -static char fs2[] ATTRIBUTE_ALIGN(32) = "/dev/usb123"; -static char fs3[] ATTRIBUTE_ALIGN(32) = "/dev/usb/ehc"; - -static u8 * mem2_ptr = NULL; -static s32 hid = -1, fd = -1; -static u32 sector_size = 0; - -s32 USBStorage2_Init(void) -{ - s32 ret; - - /* Already open */ - if (fd >= 0) return 0; - - /* Create heap */ - if (hid < 0) - { - hid = iosCreateHeap(UMS_HEAPSIZE); - if (hid < 0) return IPC_ENOMEM; - } - - /* Open USB device */ - fd = IOS_Open(fs, 0); - if (fd < 0) fd = IOS_Open(fs2, 0); - if (fd < 0) fd = IOS_Open(fs3, 0); - - if (fd < 0) return fd; - - /* Initialize USB storage */ - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_INIT, ":"); - if (ret < 0) goto err; - - /* Get device capacity */ - if (USBStorage2_GetCapacity(§or_size) == 0 || sector_size != 512) - { - ret = IPC_ENOENT; - goto err; - } - - return ret; // 0->HDD, 1->DVD - - err: - /* Close USB device */ - if (fd >= 0) - { - IOS_Close(fd); - fd = -1; - } - - return ret; -} - -void USBStorage2_Deinit(void) -{ - /* Close USB device */ - if (fd >= 0) - { - IOS_Close(fd); - fd = -1; - } -} - - -s32 USBStorage2_Watchdog(u32 on_off) -{ - if (fd >= 0) - { - s32 ret; - - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_WATCHDOG, "i:", on_off); - - return ret; - } - - return IPC_ENOENT; -} - -s32 USBStorage2_GetCapacity(u32 *_sector_size) -{ - if (fd >= 0) - { - s32 ret; - - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", §or_size); - - if (ret && _sector_size) *_sector_size = sector_size; - - return ret; - } - - return IPC_ENOENT; -} - -s32 USBStorage2_ReadSectors(u32 sector, u32 numSectors, void *buffer) -{ - u8 *buf = (u8 *) buffer; - s32 ret = -1; - - /* Device not opened */ - if (fd < 0) return fd; - - if (!mem2_ptr) - mem2_ptr = (u8 *) MEM2_alloc(sector_size * MAX_BUFFER_SECTORS); - - s32 read_secs, read_size; - - while(numSectors > 0) - { - read_secs = numSectors > MAX_BUFFER_SECTORS ? MAX_BUFFER_SECTORS : numSectors; - read_size = read_secs*sector_size; - - // Do not read more than MAX_BUFFER_SECTORS sectors at once and create a mem overflow! - if (!isMEM2Buffer(buffer)) - { - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_READ_SECTORS, "ii:d", sector, read_secs, mem2_ptr, read_size); - if(ret < 0) - return ret; - - memcpy(buf, mem2_ptr, read_size); - } - else - { - /* Read data */ - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_READ_SECTORS, "ii:d", sector, read_secs, buf, read_size); - if(ret < 0) - return ret; - } - - sector += read_secs; - numSectors -= read_secs; - buf += read_size; - } - - return ret; -} - -s32 USBStorage2_WriteSectors(u32 sector, u32 numSectors, const void *buffer) -{ - u8 *buf = (u8 *) buffer; - s32 ret = -1; - - /* Device not opened */ - if (fd < 0) return fd; - - /* Device not opened */ - if (!mem2_ptr) - mem2_ptr = (u8 *) MEM2_alloc(sector_size * MAX_BUFFER_SECTORS); - - s32 write_size, write_secs; - - while(numSectors > 0) - { - write_secs = numSectors > MAX_BUFFER_SECTORS ? MAX_BUFFER_SECTORS : numSectors; - write_size = write_secs*sector_size; - - /* MEM1 buffer */ - if (!isMEM2Buffer(buffer)) - { - // Do not read more than MAX_BUFFER_SECTORS sectors at once and create a mem overflow! - memcpy(mem2_ptr, buf, write_size); - - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_WRITE_SECTORS, "ii:d", sector, write_secs, mem2_ptr, write_size); - if(ret < 0) - return ret; - } - else - { - /* Write data */ - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_WRITE_SECTORS, "ii:d", sector, write_secs, buf, write_size); - if(ret < 0) - return ret; - } - - sector += write_secs; - numSectors -= write_secs; - buf += write_size; - } - - return ret; -} - -static bool __usbstorage_Startup(void) -{ - return USBStorage2_Init() == 0; -} - -static bool __usbstorage_IsInserted(void) -{ - return (USBStorage2_GetCapacity(NULL) != 0); -} - -static bool __usbstorage_ReadSectors(u32 sector, u32 numSectors, void *buffer) -{ - return (USBStorage2_ReadSectors(sector, numSectors, buffer) >= 0); -} - -static bool __usbstorage_WriteSectors(u32 sector, u32 numSectors, const void *buffer) -{ - return (USBStorage2_WriteSectors(sector, numSectors, buffer) >= 0); -} - -static bool __usbstorage_ClearStatus(void) -{ - return true; -} - -static bool __usbstorage_Shutdown(void) -{ - USBStorage2_Deinit(); - return true; -} - -const DISC_INTERFACE __io_usbstorage2 = { - DEVICE_TYPE_WII_UMS, FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_USB, - (FN_MEDIUM_STARTUP) &__usbstorage_Startup, - (FN_MEDIUM_ISINSERTED) &__usbstorage_IsInserted, - (FN_MEDIUM_READSECTORS) &__usbstorage_ReadSectors, - (FN_MEDIUM_WRITESECTORS) &__usbstorage_WriteSectors, - (FN_MEDIUM_CLEARSTATUS) &__usbstorage_ClearStatus, - (FN_MEDIUM_SHUTDOWN) &__usbstorage_Shutdown -}; - -// woffset is in 32bit words, len is in bytes -s32 USBStorage_WBFS_Read(u32 woffset, u32 len, void *buffer) -{ - s32 ret; - - USBStorage2_Init(); - /* Device not opened */ - if (fd < 0) return fd; - - /* Read data */ - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_WBFS_READ_DISC, "ii:d", woffset, len, buffer, len); - - return ret; -} - -s32 USBStorage_WBFS_SetFragList(void *p, int size) -{ - s32 ret; - USBStorage2_Init(); - // Device not opened - if (fd < 0) return fd; - // ioctl - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_WBFS_SET_FRAGLIST, "d:", p, size); - return ret; -} - -// Not used currently -#if 0 - -s32 USBStorage_WBFS_Open(char *buffer) -{ - u32 len = 8; - - s32 ret; - - /* Device not opened */ - if (fd < 0) return fd; - - extern u32 wbfs_part_lba; - u32 part = wbfs_part_lba; - - /* Read data */ - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_WBFS_OPEN_DISC, "dd:", buffer, len, &part, 4); - - return ret; -} - -s32 USBStorage_WBFS_SetDevice(int dev) -{ - s32 ret, retval = 0; - USBStorage2_Init(); - // Device not opened - if (fd < 0) return fd; - // ioctl - ret = IOS_IoctlvFormat(hid, fd, USB_IOCTL_WBFS_SET_DEVICE, "i:i", dev, &retval); - if (retval) return retval; - return ret; -} - -#endif diff --git a/source/usbloader/usbstorage2.h b/source/usbloader/usbstorage2.h deleted file mode 100644 index f3732c04..00000000 --- a/source/usbloader/usbstorage2.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _USBSTORAGE2_H_ -#define _USBSTORAGE2_H_ - -#include "ogc/disc_io.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Prototypes */ - s32 USBStorage2_Init(void); - void USBStorage2_Deinit(void); - s32 USBStorage2_Umount(void); - s32 USBStorage2_GetCapacity(u32 *); - - s32 USBStorage2_ReadSectors(u32, u32, void *); - s32 USBStorage2_WriteSectors(u32, u32, const void *); - - s32 USBStorage2_Watchdog(u32 on_off); - - s32 USBStorage_WBFS_Read(u32 woffset, u32 len, void *buffer); - s32 USBStorage_WBFS_SetDevice(int dev); - s32 USBStorage_WBFS_SetFragList(void *p, int size); - -#define DEVICE_TYPE_WII_UMS (('W'<<24)|('U'<<16)|('M'<<8)|'S') - - extern const DISC_INTERFACE __io_usbstorage2; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/utils.c b/source/usbloader/utils.c deleted file mode 100644 index d7e46448..00000000 --- a/source/usbloader/utils.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -u32 swap32(u32 x) -{ - return (x >> 24) | ((x << 8) & 0x00FF0000UL) | ((x >> 8) & 0x0000FF00UL) | (x << 24); -} diff --git a/source/usbloader/utils.h b/source/usbloader/utils.h deleted file mode 100644 index fd1e7ef1..00000000 --- a/source/usbloader/utils.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _UTILS_H_ -#define _UTILS_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Constants */ -#define KB_SIZE 1024.0 -#define MB_SIZE 1048576.0 -#define GB_SIZE 1073741824.0 - - /* Macros */ -#define round_up(x,n) (-(-(x) & -(n))) - -#define SAFE_FREE(P) if(P){free(P);P=NULL;} - - /* Prototypes */ - u32 swap32(u32); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/wbfs.cpp b/source/usbloader/wbfs.cpp deleted file mode 100644 index 4b0131a2..00000000 --- a/source/usbloader/wbfs.cpp +++ /dev/null @@ -1,342 +0,0 @@ -#include -#include -#include - -#include "usbloader/usbstorage2.h" -#include "fatmounter.h" -#include "wbfs.h" -#include "usbloader/wbfs/wbfs_base.h" -#include "usbloader/wbfs/wbfs_wbfs.h" -#include "usbloader/wbfs/wbfs_fat.h" -#include "usbloader/wbfs/wbfs_ntfs.h" -#include "usbloader/wbfs/wbfs_ext.h" - -#include "usbloader/partition_usbloader.h" -#include "usbloader/GameList.h" -#include "menu/menus.h" -#include "gecko.h" - -Wbfs *current = NULL; -//#define DEBUG_WBFS - -/* WBFS device */ -s32 wbfsDev = WBFS_MIN_DEVICE; - -// partition -char wbfs_fs_drive[16]; -int wbfs_part_fs = PART_FS_WBFS; -u32 wbfs_part_idx = 0; -u32 wbfs_part_lba = 0; - -wbfs_disc_t* WBFS_OpenDisc(u8 *discid) -{ - return current->OpenDisc(discid); -} - -void WBFS_CloseDisc(wbfs_disc_t *disc) -{ - current->CloseDisc(disc); -} - -wbfs_t *GetHddInfo(void) -{ - return current->GetHddInfo(); -} - -s32 WBFS_Init(u32 device) -{ - return Wbfs::Init(device); -} - -s32 WBFS_Open(void) -{ - WBFS_Close(); - - current = new Wbfs_Wbfs(WBFS_DEVICE_USB, 0, 0); // Fix me! - - wbfs_part_fs = wbfs_part_idx = wbfs_part_lba = 0; - wbfs_part_idx = 1; - - return current->Open(); -} - -s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition) -{ - // close - WBFS_Close(); - - if (part_fs == PART_FS_FAT) - { - current = new Wbfs_Fat(wbfsDev, part_lba, part_size); - strcpy(wbfs_fs_drive, "USB:"); - } - else if (part_fs == PART_FS_NTFS) - { - current = new Wbfs_Ntfs(wbfsDev, part_lba, part_size); - strcpy(wbfs_fs_drive, "NTFS:"); - } - else if (part_fs == PART_FS_EXT) - { - current = new Wbfs_Ext(wbfsDev, part_lba, part_size); - strcpy(wbfs_fs_drive, "EXT:"); - } - else - { - current = new Wbfs_Wbfs(wbfsDev, part_lba, part_size); - } - if (current->Open()) - { - delete current; - current = NULL; - return -1; - } - - // success - wbfs_part_fs = part_fs; - wbfs_part_idx = part_idx; - wbfs_part_lba = part_lba; - - const char *fs = "WBFS"; - if (wbfs_part_fs == PART_FS_FAT) fs = "FAT"; - if (wbfs_part_fs == PART_FS_NTFS) fs = "NTFS"; - if (wbfs_part_fs == PART_FS_EXT) fs = "EXT"; - sprintf(partition, "%s%d", fs, wbfs_part_idx); - return 0; -} - -s32 WBFS_OpenNamed(char *partition) -{ - u32 i; - u32 part_fs = PART_FS_WBFS; - u32 part_idx = 0; - u32 part_lba = 0; - s32 ret = 0; - PartList plist; - - // close - WBFS_Close(); - - // parse partition option - if (strncasecmp(partition, "WBFS", 4) == 0) - { - i = atoi(partition + 4); - if (i < 1 || i > 4) goto err; - part_fs = PART_FS_WBFS; - part_idx = i; - } - else if (strncasecmp(partition, "FAT", 3) == 0) - { - if (wbfsDev != WBFS_DEVICE_USB) goto err; - i = atoi(partition + 3); - if (i < 1 || i > 9) goto err; - part_fs = PART_FS_FAT; - part_idx = i; - } - else if (strncasecmp(partition, "NTFS", 4) == 0) - { - i = atoi(partition + 4); - if (i < 1 || i > 9) goto err; - part_fs = PART_FS_NTFS; - part_idx = i; - } - else if (strncasecmp(partition, "EXT", 3) == 0) - { - i = atoi(partition + 3); - if (i < 1 || i > 9) goto err; - part_fs = PART_FS_EXT; - part_idx = i; - } - else - { - goto err; - } - - // Get partition entries - ret = Partition_GetList(wbfsDev, &plist); - if (ret || plist.num == 0) return -1; - - if (part_fs == PART_FS_WBFS) - { - if (part_idx > plist.wbfs_n) goto err; - for (i = 0; i < plist.num; i++) - { - if (plist.pinfo[i].wbfs_i == part_idx) break; - } - } - else if (part_fs == PART_FS_FAT) - { - if (part_idx > plist.fat_n) goto err; - for (i = 0; i < plist.num; i++) - { - if (plist.pinfo[i].fat_i == part_idx) break; - } - } - else if (part_fs == PART_FS_NTFS) - { - if (part_idx > plist.ntfs_n) goto err; - for (i = 0; i < plist.num; i++) - { - if (plist.pinfo[i].ntfs_i == part_idx) break; - } - } - else if (part_fs == PART_FS_EXT) - { - if (part_idx > plist.ext_n) goto err; - for (i = 0; i < plist.num; i++) - { - if (plist.pinfo[i].ext_i == part_idx) break; - } - } - if (i >= plist.num) goto err; - // set partition lba sector - part_lba = plist.pentry[i].sector; - - if (WBFS_OpenPart(part_fs, part_idx, part_lba, plist.pentry[i].size, partition)) - { - goto err; - } - // success - return 0; - err: return -1; -} - -s32 WBFS_OpenLBA(u32 lba, u32 size) -{ - Wbfs *part = new Wbfs_Wbfs(wbfsDev, lba, size); - if (part->Open() != 0) - { - delete part; - return -1; - } - - WBFS_Close(); - current = part; - return 0; -} - -bool WBFS_Close(void) -{ - if (current != NULL) - { - current->Close(); - delete current; - current = NULL; - } - - wbfs_part_fs = 0; - wbfs_part_idx = 0; - wbfs_part_lba = 0; - wbfs_fs_drive[0] = '\0'; - - gameList.clear(); - - return 0; -} - -bool WBFS_Mounted() -{ - return (current != NULL && current->Mounted()); -} - -s32 WBFS_Format(u32 lba, u32 size) -{ - return current->Format(); -} - -s32 WBFS_GetCount(u32 *count) -{ - return current->GetCount(count); -} - -s32 WBFS_GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len) -{ - return current->GetHeaders(outbuf, cnt, len); -} - -s32 WBFS_CheckGame(u8 *discid) -{ - return current->CheckGame(discid); -} - -s32 WBFS_AddGame(void) -{ - s32 retval = current->AddGame(); - if (retval == 0) gameList.clear(); - - return retval; -} - -s32 WBFS_RemoveGame(u8 *discid) -{ - s32 retval = current->RemoveGame(discid); - if (retval == 0) gameList.clear(); - - return retval; -} - -s32 WBFS_GameSize(u8 *discid, f32 *size) -{ - return current->GameSize(discid, size); -} - -s32 WBFS_DiskSpace(f32 *used, f32 *free) -{ - return current->DiskSpace(used, free); -} - -s32 WBFS_RenameGame(u8 *discid, const void *newname) -{ - s32 retval = current->RenameGame(discid, newname); - if (retval == 0) gameList.clear(); - - return retval; -} - -s32 WBFS_ReIDGame(u8 *discid, const void *newID) -{ - s32 retval = current->ReIDGame(discid, newID); - if (retval == 0) gameList.clear(); - - return retval; -} - -f32 WBFS_EstimeGameSize(void) -{ - return current->EstimateGameSize(); -} - -int WBFS_GetFragList(u8 *id) -{ - return current->GetFragList(id); -} - -bool WBFS_ShowFreeSpace(void) -{ - return current->ShowFreeSpace(); -} - -int MountWBFS(bool ShowGUI) -{ - if(ShowGUI) - return DiscWait(tr( "Waiting for USB Device" ), 0, 0, 0, 1); - - int ret = -1; - time_t currTime = time(0); - - while (time(0) - currTime < 30) - { - - USBDevice_deInit(); - USBStorage2_Deinit(); - USBDevice_Init(); - ret = WBFS_Init(WBFS_DEVICE_USB); - printf("%i...", int(time(0) - currTime)); - if (ret < 0) - sleep(1); - else break; - } - - printf("\n"); - - return ret; -} diff --git a/source/usbloader/wbfs.h b/source/usbloader/wbfs.h deleted file mode 100644 index eda23a37..00000000 --- a/source/usbloader/wbfs.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef _WBFS_H_ -#define _WBFS_H_ - -#include "libs/libwbfs/libwbfs.h" -#include "usbloader/disc.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define PART_FS_WBFS 0 -#define PART_FS_FAT 1 -#define PART_FS_NTFS 2 -#define PART_FS_EXT 3 - - /* Macros */ -#define WBFS_MIN_DEVICE 1 -#define WBFS_MAX_DEVICE 2 - - extern s32 wbfsDev; - extern int wbfs_part_fs; - extern u32 wbfs_part_idx; - extern u32 wbfs_part_lba; - extern char wbfs_fs_drive[16]; - - /* Prototypes */ - s32 WBFS_Init(u32); - s32 WBFS_Open(void); - s32 WBFS_Format(u32, u32); - s32 WBFS_GetCount(u32 *); - s32 WBFS_GetHeaders(struct discHdr *, u32, u32); - // s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf); - wbfs_t *GetHddInfo(void); - s32 WBFS_CheckGame(u8 *); - s32 WBFS_AddGame(void); - s32 WBFS_RemoveGame(u8 *); - s32 WBFS_GameSize(u8 *, f32 *); - bool WBFS_ShowFreeSpace(void); - s32 WBFS_DiskSpace(f32 *, f32 *); - s32 WBFS_RenameGame(u8 *, const void *); - s32 WBFS_ReIDGame(u8 *discid, const void *newID); - f32 WBFS_EstimeGameSize(void); - - int WBFS_GetFragList(u8 *id); - /* - s32 __WBFS_ReadUSB(void *fp, u32 lba, u32 count, void *iobuf); - s32 __WBFS_WriteUSB(void *fp, u32 lba, u32 count, void *iobuf); - */ - - s32 WBFS_OpenPart(u32 part_fat, u32 part_idx, u32 part_lba, u32 part_size, char *partition); - s32 WBFS_OpenNamed(char *partition); - s32 WBFS_OpenLBA(u32 lba, u32 size); - wbfs_disc_t* WBFS_OpenDisc(u8 *discid); - void WBFS_CloseDisc(wbfs_disc_t *disc); - bool WBFS_Close(); - bool WBFS_Mounted(); - bool WBFS_Selected(); - int MountWBFS(bool ShowGUI); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/usbloader/wbfs/wbfs_base.cpp b/source/usbloader/wbfs/wbfs_base.cpp deleted file mode 100644 index af78fa90..00000000 --- a/source/usbloader/wbfs/wbfs_base.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include -#include -#include -#include - -#include "usbloader/sdhc.h" -#include "usbloader/usbstorage2.h" -#include "fatmounter.h" -#include "wbfs_rw.h" - -#include "wbfs_base.h" - -s32 Wbfs::done = -1; -s32 Wbfs::total = -1; -u32 Wbfs::nb_sectors; - -Wbfs::Wbfs(u32 device, u32 lba, u32 size) : - hdd(NULL) -{ - this->device = device; - this->lba = lba; - this->size = size; -} - -void Wbfs::GetProgressValue(s32 * d, s32 * m) -{ - *d = done; - *m = total; -} - -s32 Wbfs::Init(u32 device) -{ - s32 ret; - - switch (device) - { - case WBFS_DEVICE_USB: - /* Initialize USB storage */ - ret = USBStorage2_Init(); - if (ret >= 0) - { - /* Setup callbacks */ - readCallback = __ReadUSB; - writeCallback = __WriteUSB; - /* Device info */ - /* Get USB capacity */ - nb_sectors = USBStorage2_GetCapacity(§or_size); - if (!nb_sectors) return -1; - } - else return ret; - break; - case WBFS_DEVICE_SDHC: - /* Initialize SDHC */ - ret = SDHC_Init(); - - if (ret) - { - /* Setup callbacks */ - readCallback = __ReadSDHC; - writeCallback = __WriteSDHC; - - /* Device info */ - nb_sectors = 0; - sector_size = SDHC_SECTOR_SIZE; - } - else return -1; - break; - } - - return 0; -} - -void Wbfs::Close() -{ - if (hdd) - { - wbfs_close(hdd); - hdd = NULL; - } - - WBFSDevice_deInit(); -} - -// Default behavior: can't format -s32 Wbfs::Format() -{ - return -1; -} - -s32 Wbfs::CheckGame(u8 *discid) -{ - wbfs_disc_t *disc = NULL; - - /* Try to open game disc */ - disc = OpenDisc(discid); - if (disc) - { - /* Close disc */ - CloseDisc(disc); - - return 1; - } - - return 0; -} - -s32 Wbfs::GameSize(u8 *discid, f32 *size) -{ - wbfs_disc_t *disc = NULL; - - u32 sectors; - - /* Open disc */ - disc = OpenDisc(discid); - if (!disc) return -2; - - /* Get game size in sectors */ - sectors = wbfs_sector_used(disc->p, disc->header); - - /* Copy value */ - *size = (disc->p->wbfs_sec_sz / GB_SIZE) * sectors; - - /* Close disc */ - CloseDisc(disc); - - return 0; -} - -wbfs_t *Wbfs::GetHddInfo() -{ - return hdd; -} - -bool Wbfs::Mounted() -{ - return hdd == NULL; -} - - -bool Wbfs::ShowFreeSpace(void) -{ - return true; -} diff --git a/source/usbloader/wbfs/wbfs_base.h b/source/usbloader/wbfs/wbfs_base.h deleted file mode 100644 index 670bfd46..00000000 --- a/source/usbloader/wbfs/wbfs_base.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _H -#define _H - -#include "libs/libwbfs/libwbfs.h" -#include "usbloader/utils.h" -#include "usbloader/frag.h" - -class Wbfs -{ - public: - Wbfs(u32, u32, u32); - - void GetProgressValue(s32 * d, s32 * m); - static s32 Init(u32); - void Close(); - s32 CheckGame(u8 *); - s32 GameSize(u8 *, f32 *); - wbfs_t *GetHddInfo(void); - bool Mounted(); - virtual int GetFragList(u8 *id) { return 0; }; - virtual bool ShowFreeSpace(void); - - virtual s32 Open() = 0; - virtual wbfs_disc_t* OpenDisc(u8 *discid) = 0; - virtual void CloseDisc(wbfs_disc_t *disc) = 0; - virtual s32 Format(); - virtual s32 GetCount(u32 *) = 0; - virtual s32 GetHeaders(struct discHdr *, u32, u32) = 0; - virtual s32 AddGame(void) = 0; - virtual s32 RemoveGame(u8 *) = 0; - virtual s32 DiskSpace(f32 *, f32 *) = 0; - virtual s32 RenameGame(u8 *, const void *) = 0; - virtual s32 ReIDGame(u8 *discid, const void *newID) = 0; - virtual f32 EstimateGameSize(void) = 0; - - /* - static s32 OpenPart(u32 part_fat, u32 part_idx, u32 part_lba, u32 part_size, char *partition); - static s32 OpenNamed(char *partition); - static s32 OpenLBA(u32 lba, u32 size); - */ - protected: - static u32 nb_sectors; - - /* WBFS HDD */ - wbfs_t *hdd; - - u32 device, lba, size; - private: - - static s32 total, done; -}; - -#endif //_H diff --git a/source/usbloader/wbfs/wbfs_ext.h b/source/usbloader/wbfs/wbfs_ext.h deleted file mode 100644 index 6bf2c730..00000000 --- a/source/usbloader/wbfs/wbfs_ext.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _WBFS_EXT_H -#define _WBFS_EXT_H - -#include -#include "wbfs_fat.h" -#include "fatmounter.h" - -class Wbfs_Ext: public Wbfs_Fat -{ - public: - Wbfs_Ext(u32 device, u32 lba, u32 size) : - Wbfs_Fat(device, lba, size) - { - } - - virtual s32 Open() - { - strcpy(wbfs_fs_drive, "EXT:"); - return MountEXT(lba); - }; - - bool ShowFreeSpace(void) { return true; }; -}; - -#endif //_WBFS_NTFS_H diff --git a/source/usbloader/wbfs/wbfs_fat.cpp b/source/usbloader/wbfs/wbfs_fat.cpp deleted file mode 100644 index 9686b8fb..00000000 --- a/source/usbloader/wbfs/wbfs_fat.cpp +++ /dev/null @@ -1,817 +0,0 @@ -// WBFS FAT by oggzee - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "settings/CSettings.h" -#include "settings/GameTitles.h" -#include "usbloader/disc.h" -#include "fatmounter.h" -#include "wbfs_fat.h" -#include "prompts/ProgressWindow.h" -#include "wbfs_rw.h" - -#include "gecko.h" - -#define MAX_FAT_PATH 1024 -#define TITLE_LEN 64 - -using namespace std; - -char Wbfs_Fat::wbfs_fs_drive[16]; -char Wbfs_Fat::wbfs_fat_dir[16] = "/wbfs"; -char Wbfs_Fat::invalid_path[] = "/\\:|<>?*\"'"; -struct discHdr *Wbfs_Fat::fat_hdr_list = NULL; -u32 Wbfs_Fat::fat_hdr_count = 0; - -extern "C" -{ - int _FAT_get_fragments(const char *path, _frag_append_t append_fragment, void *callback_data); - extern FragList *frag_list; -} - -u32 Wbfs_Fat::fat_sector_size = 512; - -Wbfs_Fat::Wbfs_Fat(u32 device, u32 lba, u32 size) : - Wbfs(device, lba, size) -{ -} - -s32 Wbfs_Fat::Open() -{ - if (device == WBFS_DEVICE_USB && lba == fat_usb_sec) - { - strcpy(wbfs_fs_drive, "USB:"); - } - else if (device == WBFS_DEVICE_SDHC && lba == fat_sd_sec) - { - strcpy(wbfs_fs_drive, "SD:"); - } - else - { - if (WBFSDevice_Init(lba)) return -1; - strcpy(wbfs_fs_drive, "WBFS:"); - } - - return 0; -} - -wbfs_disc_t* Wbfs_Fat::OpenDisc(u8 *discid) -{ - char fname[MAX_FAT_PATH]; - - // wbfs 'partition' file - if (!FindFilename(discid, fname, sizeof(fname))) return NULL; - - if (strcasecmp(strrchr(fname, '.'), ".iso") == 0) - { - // .iso file - // create a fake wbfs_disc - int fd; - fd = open(fname, O_RDONLY); - if (fd == -1) return NULL; - wbfs_disc_t *iso_file = (wbfs_disc_t *) calloc(sizeof(wbfs_disc_t), 1); - if (iso_file == NULL) return NULL; - // mark with a special wbfs_part - wbfs_iso_file.wbfs_sec_sz = 512; - iso_file->p = &wbfs_iso_file; - iso_file->header = (wbfs_disc_info_t*) fd; - return iso_file; - } - - wbfs_t *part = OpenPart(fname); - if (!part) return NULL; - return wbfs_open_disc(part, discid); -} - -void Wbfs_Fat::CloseDisc(wbfs_disc_t* disc) -{ - if (!disc) return; - wbfs_t *part = disc->p; - - // is this really a .iso file? - if (part == &wbfs_iso_file) - { - close((int) disc->header); - free(disc); - return; - } - - wbfs_close_disc(disc); - ClosePart(part); - return; -} - -s32 Wbfs_Fat::GetCount(u32 *count) -{ - *count = 0; - GetHeadersCount(); - if (fat_hdr_count && fat_hdr_list) - { - // for compacter mem - move up as it will be freed later - int size = fat_hdr_count * sizeof(struct discHdr); - struct discHdr *buf = (struct discHdr *) malloc(size); - if (buf) - { - memcpy(buf, fat_hdr_list, size); - SAFE_FREE( fat_hdr_list ); - fat_hdr_list = buf; - } - } - *count = fat_hdr_count; - return 0; -} - -s32 Wbfs_Fat::GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len) -{ - u32 i; - if (len > sizeof(struct discHdr)) - { - len = sizeof(struct discHdr); - } -#ifdef DEBUG_WBFS - gprintf( "\n\tGetHeaders" ); -#endif - for (i = 0; i < cnt && i < fat_hdr_count; i++) - { - memcpy(&outbuf[i], &fat_hdr_list[i], len); - } - SAFE_FREE( fat_hdr_list ); - fat_hdr_count = 0; -#ifdef DEBUG_WBFS - gprintf( "...ok" ); -#endif - return 0; -} - -s32 Wbfs_Fat::AddGame(void) -{ - static struct discHdr header ATTRIBUTE_ALIGN( 32 ); - char path[MAX_FAT_PATH]; - wbfs_t *part = NULL; - s32 ret; - - // read ID from DVD - Disc_ReadHeader(&header); - // path - GetDir(&header, path); - // create wbfs 'partition' file - part = CreatePart(header.id, path); - if (!part) return -1; - /* Add game to device */ - partition_selector_t part_sel = (partition_selector_t) Settings.InstallPartitions; - - wbfs_t *old_hdd = hdd; - hdd = part; // used by spinner - ret = wbfs_add_disc(hdd, __ReadDVD, NULL, ProgressCallback, part_sel, 0); - hdd = old_hdd; - wbfs_trim(part); - ClosePart(part); - - if (ret < 0) return ret; - mk_title_txt(&header, path); - - return 0; -} - -s32 Wbfs_Fat::RemoveGame(u8 *discid) -{ - char fname[MAX_FAT_PATH]; - int loc; - // wbfs 'partition' file - loc = FindFilename(discid, fname, sizeof(fname)); - if (!loc) return -1; - split_create(&split, fname, 0, 0, true); - split_close(&split); - if (loc == 1) return 0; - - // game is in subdir - // remove optional .txt file - DIR_ITER *dir_iter; - struct stat st; - char path[MAX_FAT_PATH]; - char name[MAX_FAT_PATH]; - strncpy(path, fname, sizeof(path)); - char *p = strrchr(path, '/'); - if (p) *p = 0; - dir_iter = diropen(path); - if (!dir_iter) return 0; - while (dirnext(dir_iter, name, &st) == 0) - { - if (name[0] == '.') continue; - if (name[6] != '_') continue; - if (strncmp(name, (char*) discid, 6) != 0) continue; - p = strrchr(name, '.'); - if (!p) continue; - if (strcasecmp(p, ".txt") != 0) continue; - snprintf(fname, sizeof(fname), "%s/%s", path, name); - remove(fname); - break; - } - dirclose(dir_iter); - // remove game subdir - unlink(path); - - return 0; -} - -s32 Wbfs_Fat::DiskSpace(f32 *used, f32 *free) -{ - f32 size; - int ret; - struct statvfs wbfs_fat_vfs; - - *used = 0; - *free = 0; - ret = statvfs(wbfs_fs_drive, &wbfs_fat_vfs); - if (ret) return -1; - - /* FS size in GB */ - size = (f32) wbfs_fat_vfs.f_frsize * (f32) wbfs_fat_vfs.f_blocks / GB_SIZE; - *free = (f32) wbfs_fat_vfs.f_frsize * (f32) wbfs_fat_vfs.f_bfree / GB_SIZE; - *used = size - *free; - - return 0; -} - -s32 Wbfs_Fat::RenameGame(u8 *discid, const void *newname) -{ - wbfs_t *part = OpenPart((char *) discid); - if (!part) return -1; - - s32 ret = wbfs_ren_disc(part, discid, (u8*) newname); - - ClosePart(part); - - return ret; -} - -s32 Wbfs_Fat::ReIDGame(u8 *discid, const void *newID) -{ - wbfs_t *part = OpenPart((char *) discid); - if (!part) return -1; - - s32 ret = wbfs_rID_disc(part, discid, (u8*) newID); - - ClosePart(part); - - if (ret == 0) - { - char fname[100]; - char fnamenew[100]; - s32 cnt = 0x31; - - Filename(discid, fname, sizeof(fname), NULL); - Filename((u8*) newID, fnamenew, sizeof(fnamenew), NULL); - - int stringlength = strlen(fname); - - while (rename(fname, fnamenew) == 0) - { - fname[stringlength] = cnt; - fname[stringlength + 1] = 0; - fnamenew[stringlength] = cnt; - fnamenew[stringlength + 1] = 0; - cnt++; - } - } - - return ret; -} - -f32 Wbfs_Fat::EstimateGameSize() -{ - wbfs_t *part = NULL; - u64 size = (u64) 143432 * 2 * 0x8000ULL; - u32 n_sector = size / fat_sector_size; - u32 wii_sec_sz; - - // init a temporary dummy part - // as a placeholder for wbfs_size_disc - part = wbfs_open_partition(nop_rw_sector, nop_rw_sector, NULL, fat_sector_size, n_sector, 0, 1); - if (!part) return -1; - wii_sec_sz = part->wii_sec_sz; - - partition_selector_t part_sel = (partition_selector_t) Settings.InstallPartitions; - return wbfs_estimate_disc(part, __ReadDVD, NULL, part_sel); -} - -// TITLE [GAMEID] -bool Wbfs_Fat::CheckLayoutB(char *fname, int len, u8* id, char *fname_title) -{ - if (len <= 8) return false; - if (fname[len - 8] != '[' || fname[len - 1] != ']') return false; - if (!is_gameid(&fname[len - 7])) return false; - strncpy(fname_title, fname, TITLE_LEN); - // cut at '[' - fname_title[len - 8] = 0; - int n = strlen(fname_title); - if (n == 0) return false; - // cut trailing _ or ' ' - if (fname_title[n - 1] == ' ' || fname_title[n - 1] == '_') - { - fname_title[n - 1] = 0; - } - if (strlen(fname_title) == 0) return false; - if (id) - { - memcpy(id, &fname[len - 7], 6); - id[6] = 0; - } - return true; -} - -s32 Wbfs_Fat::GetHeadersCount() -{ - char path[MAX_FAT_PATH]; - char fname[MAX_FAT_PATH]; - char fpath[MAX_FAT_PATH]; - struct discHdr tmpHdr; - struct stat st; - wbfs_t *part = NULL; - u8 id[8]; - int ret; - char *p; - u32 size; - int is_dir; - int len; - char dir_title[65]; - char fname_title[TITLE_LEN]; - const char *title; - DIR_ITER *dir_iter; - - //dbg_time1(); - - SAFE_FREE( fat_hdr_list ); - fat_hdr_count = 0; - - strcpy(path, wbfs_fs_drive); - strcat(path, wbfs_fat_dir); - - dir_iter = diropen(path); - if (!dir_iter) return 0; - - dir_iter = diropen(path); - if (!dir_iter) return 0; - - while (dirnext(dir_iter, fname, &st) == 0) - { - //printf("found: %s\n", fname); Wpad_WaitButtonsCommon(); - if ((char) fname[0] == '.') continue; - len = strlen(fname); - if (len < 8) continue; // "GAMEID_x" - - memcpy(id, fname, 6); - id[6] = 0; - *fname_title = 0; - - is_dir = S_ISDIR( st.st_mode ); - //printf("mode: %d %d %x\n", is_dir, st.st_mode, st.st_mode); - if (is_dir) - { - int lay_a = 0; - int lay_b = 0; - if (fname[6] == '_' && is_gameid((char*) id)) - { - // usb:/wbfs/GAMEID_TITLE/GAMEID.wbfs - lay_a = 1; - } - if (CheckLayoutB(fname, len, NULL, fname_title)) - { - // usb:/wbfs/TITLE[GAMEID]/GAMEID.wbfs - lay_b = 1; - } - if (!lay_a && !lay_b) continue; - if (lay_a) - { - strncpy(dir_title, &fname[7], sizeof(dir_title)); - } - else - { - try_lay_b: if (!CheckLayoutB(fname, len, id, fname_title)) continue; - } - snprintf(fpath, sizeof(fpath), "%s/%s/%s.wbfs", path, fname, id); - //printf("path2: %s\n", fpath); - // if more than 50 games, skip second stat to improve speed - // but if ambiguous layout check anyway - if (fat_hdr_count < 50 || (lay_a && lay_b)) - { - if (stat(fpath, &st) == -1) - { - //printf("missing: %s\n", fpath); - // try .iso - strcpy(strrchr(fpath, '.'), ".iso"); // replace .wbfs with .iso - if (stat(fpath, &st) == -1) - { - //printf("missing: %s\n", fpath); - // try .ciso - strcpy(strrchr(fpath, '.'), ".ciso"); // replace .iso with .ciso - if (stat(fpath, &st) == -1) - { - if (lay_a && lay_b == 1) - { - // mark lay_b so that the stat check is still done, - // but lay_b is not re-tried again - lay_b = 2; - // retry with layout b - goto try_lay_b; - } - continue; - } - } - } - } - else - { - st.st_size = 1024 * 1024; - } - } - else - { - // usb:/wbfs/GAMEID.wbfs - // or usb:/wbfs/GAMEID.iso - // or usb:/wbfs/GAMEID.ciso - p = strrchr(fname, '.'); - if (!p) continue; - if ((strcasecmp(p, ".wbfs") != 0) && (strcasecmp(p, ".iso") != 0) && (strcasecmp(p, ".ciso") != 0)) continue; - int n = p - fname; // length withouth .wbfs - if (n != 6) - { - // TITLE [GAMEID].wbfs - if (!CheckLayoutB(fname, n, id, fname_title)) continue; - } - snprintf(fpath, sizeof(fpath), "%s/%s", path, fname); - } - - //printf("found: %s %d MB\n", fpath, (int)(st.st_size/1024/1024)); - // size must be at least 1MB to be considered a valid wbfs file - if (st.st_size < 1024 * 1024) continue; - // if we have titles.txt entry use that - title = GameTitles.GetTitle(id); - // if no titles.txt get title from dir or file name - if (!title && *fname_title) - { - title = fname_title; - } - if (title) - { - memset(&tmpHdr, 0, sizeof(tmpHdr)); - memcpy(tmpHdr.id, id, 6); - strncpy(tmpHdr.title, title, sizeof(tmpHdr.title) - 1); - tmpHdr.magic = 0x5D1C9EA3; - goto add_hdr; - } - - // else read it from file directly - if (strcasecmp(strrchr(fpath, '.'), ".wbfs") == 0) - { - // wbfs file directly - FILE *fp = fopen(fpath, "rb"); - if (fp != NULL) - { - fseek(fp, 512, SEEK_SET); - fread(&tmpHdr, sizeof(struct discHdr), 1, fp); - fclose(fp); - tmpHdr.is_ciso = 0; - if ((tmpHdr.magic == 0x5D1C9EA3) && (memcmp(tmpHdr.id, id, 6) == 0)) - { - goto add_hdr; - } - } - // no title found, read it from wbfs file - // but this is a little bit slower - // open 'partition' file - part = OpenPart(fpath); - if (!part) - { - continue; - } - // Get header - ret = wbfs_get_disc_info(part, 0, (u8*) &tmpHdr, sizeof(struct discHdr), &size); - ClosePart(part); - if (ret == 0) - { - goto add_hdr; - } - } - else if (strcasecmp(strrchr(fpath, '.'), ".iso") == 0) - { - // iso file - FILE *fp = fopen(fpath, "rb"); - if (fp != NULL) - { - fseek(fp, 0, SEEK_SET); - fread(&tmpHdr, sizeof(struct discHdr), 1, fp); - fclose(fp); - tmpHdr.is_ciso = 0; - if ((tmpHdr.magic == 0x5D1C9EA3) && (memcmp(tmpHdr.id, id, 6) == 0)) - { - goto add_hdr; - } - } - } - else if (strcasecmp(strrchr(fpath, '.'), ".ciso") == 0) - { - // ciso file - FILE *fp = fopen(fpath, "rb"); - if (fp != NULL) - { - fseek(fp, 0x8000, SEEK_SET); - fread(&tmpHdr, sizeof(struct discHdr), 1, fp); - fclose(fp); - tmpHdr.is_ciso = 1; - if ((tmpHdr.magic == 0x5D1C9EA3) && (memcmp(tmpHdr.id, id, 6) == 0)) - { - goto add_hdr; - } - } - } - // fail: - continue; - - // succes: add tmpHdr to list: - add_hdr: memset(&st, 0, sizeof(st)); - //printf("added: %.6s %.20s\n", tmpHdr.id, tmpHdr.title); Wpad_WaitButtons(); - fat_hdr_count++; - fat_hdr_list = (struct discHdr *) realloc(fat_hdr_list, fat_hdr_count * sizeof(struct discHdr)); - memcpy(&fat_hdr_list[fat_hdr_count - 1], &tmpHdr, sizeof(struct discHdr)); - } - dirclose(dir_iter); - //dbg_time2("\nFAT_GetCount"); Wpad_WaitButtonsCommon(); - - return 0; -} - -int Wbfs_Fat::FindFilename(u8 *id, char *fname, int len) -{ - struct stat st; - // look for direct .wbfs file - Filename(id, fname, len, NULL); - if (stat(fname, &st) == 0) return 1; - // look for direct .iso file - strcpy(strrchr(fname, '.'), ".iso"); // replace .wbfs with .iso - if (stat(fname, &st) == 0) return 1; - // look for direct .ciso file - strcpy(strrchr(fname, '.'), ".ciso"); // replace .iso with .ciso - if (stat(fname, &st) == 0) return 1; - // direct file not found, check subdirs - *fname = 0; - DIR_ITER *dir_iter; - char path[MAX_FAT_PATH]; - char name[MAX_FAT_PATH]; - strcpy(path, wbfs_fs_drive); - strcat(path, wbfs_fat_dir); - dir_iter = diropen(path); - //printf("dir: %s %p\n", path, dir); Wpad_WaitButtons(); - if (!dir_iter) - { - return 0; - } - while (dirnext(dir_iter, name, &st) == 0) - { - //dbg_printf("name:%s\n", name); - if (name[0] == '.') continue; - int n = strlen(name); - if (n < 8) continue; - if (S_ISDIR( st.st_mode )) - { - if (name[6] == '_') - { - // GAMEID_TITLE - if (strncmp(name, (char*) id, 6) != 0) goto try_alter; - } - else - { - try_alter: - // TITLE [GAMEID] - if (name[n - 8] != '[' || name[n - 1] != ']') continue; - if (strncmp(&name[n - 7], (char*) id, 6) != 0) continue; - } - // look for .wbfs file - snprintf(fname, len, "%s/%s/%.6s.wbfs", path, name, id); - if (stat(fname, &st) == 0) break; - // look for .iso file - snprintf(fname, len, "%s/%s/%.6s.iso", path, name, id); - if (stat(fname, &st) == 0) break; - // look for .ciso file - snprintf(fname, len, "%s/%s/%.6s.ciso", path, name, id); - } - else - { - // TITLE [GAMEID].wbfs - char fn_title[TITLE_LEN]; - u8 fn_id[8]; - char *p = strrchr(name, '.'); - if (!p) continue; - if ((strcasecmp(p, ".wbfs") != 0) && (strcasecmp(p, ".iso") != 0) && (strcasecmp(p, ".ciso") != 0)) continue; - int n = p - name; // length withouth .wbfs - if (!CheckLayoutB(name, n, fn_id, fn_title)) continue; - if (strncmp((char*) fn_id, (char*) id, 6) != 0) continue; - snprintf(fname, len, "%s/%s", path, name); - } - if (stat(fname, &st) == 0) break; - *fname = 0; - } - dirclose(dir_iter); - if (*fname) - { - // found - //printf("found:%s\n", fname); - return 2; - } - // not found - return 0; -} - -wbfs_t* Wbfs_Fat::OpenPart(char *fname) -{ - wbfs_t *part = NULL; - int ret; - - // wbfs 'partition' file - ret = split_open(&split, fname); - if (ret) return NULL; - part = wbfs_open_partition(split_read_sector, nop_rw_sector, //readonly //split_write_sector, - &split, fat_sector_size, split.total_sec, 0, 0); - if (!part) - { - split_close(&split); - } - return part; -} - -void Wbfs_Fat::ClosePart(wbfs_t* part) -{ - if (!part) return; - split_info_t *s = (split_info_t*) part->callback_data; - wbfs_close(part); - if (s) split_close(s); -} - -void Wbfs_Fat::Filename(u8 *id, char *fname, int len, char *path) -{ - if (path == NULL) - { - snprintf(fname, len, "%s%s/%.6s.wbfs", wbfs_fs_drive, wbfs_fat_dir, id); - } - else - { - snprintf(fname, len, "%s/%.6s.wbfs", path, id); - } -} - -void Wbfs_Fat::GetDir(struct discHdr *header, char *path) -{ - strcpy(path, wbfs_fs_drive); - strcat(path, wbfs_fat_dir); - if (Settings.FatInstallToDir) - { - strcat(path, "/"); - int layout = 0; - if (Settings.FatInstallToDir == 2) layout = 1; - mk_gameid_title(header, path + strlen(path), 0, layout); - } -} - -wbfs_t* Wbfs_Fat::CreatePart(u8 *id, char *path) -{ - char fname[MAX_FAT_PATH]; - wbfs_t *part = NULL; - u64 size = (u64) 143432 * 2 * 0x8000ULL; - u32 n_sector = size / 512; - int ret; - - //printf("CREATE PART %s %lld %d\n", id, size, n_sector); - snprintf(fname, sizeof(fname), "%s%s", wbfs_fs_drive, wbfs_fat_dir); - mkdir(fname, 0777); // base usb:/wbfs - mkdir(path, 0777); // game subdir - Filename(id, fname, sizeof(fname), path); - printf("Writing to %s\n", fname); - ret = split_create(&split, fname, OPT_split_size, size, true); - if (ret) return NULL; - - // force create first file - u32 scnt = 0; - int fd = split_get_file(&split, 0, &scnt, 0); - if (fd < 0) - { - printf("ERROR creating file\n"); - sleep(2); - split_close(&split); - return NULL; - } - - part = wbfs_open_partition(split_read_sector, split_write_sector, &split, fat_sector_size, n_sector, 0, 1); - if (!part) - { - split_close(&split); - } - return part; -} - -void Wbfs_Fat::mk_title_txt(struct discHdr *header, char *path) -{ - char fname[MAX_FAT_PATH]; - FILE *f; - - strcpy(fname, path); - strcat(fname, "/"); - mk_gameid_title(header, fname + strlen(fname), 1, 0); - strcat(fname, ".txt"); - - f = fopen(fname, "wb"); - if (!f) return; - fprintf(f, "%.6s = %.64s\n", header->id, GameTitles.GetTitle(header)); - fclose(f); - printf("Info file: %s\n", fname); -} - -void Wbfs_Fat::mk_gameid_title(struct discHdr *header, char *name, int re_space, int layout) -{ - int i, len; - char title[65]; - char id[8]; - - memcpy(name, header->id, 6); - name[6] = 0; - strncpy(title, GameTitles.GetTitle(header), sizeof(title)); - title_filename(title); - - if (layout == 0) - { - sprintf(name, "%s_%s", id, title); - } - else - { - sprintf(name, "%s [%s]", title, id); - } - - // replace space with '_' - if (re_space) - { - len = strlen(name); - for (i = 0; i < len; i++) - { - if (name[i] == ' ') name[i] = '_'; - } - } -} - -void Wbfs_Fat::title_filename(char *title) -{ - int i, len; - // trim leading space - len = strlen(title); - while (*title == ' ') - { - memmove(title, title + 1, len); - len--; - } - // trim trailing space - not allowed on windows directories - while (len && title[len - 1] == ' ') - { - title[len - 1] = 0; - len--; - } - // replace silly chars with '_' - for (i = 0; i < len; i++) - { - if (strchr(invalid_path, title[i]) || iscntrl((int) title[i])) - { - title[i] = '_'; - } - } -} - -bool Wbfs_Fat::is_gameid(char *id) -{ - int i; - for (i = 0; i < 6; i++) - { - if (!isalnum((u32) id[i])) return false; - } - return true; -} - -int Wbfs_Fat::GetFragList(u8 *id) -{ - char fname[1024]; - - int ret = FindFilename(id, fname, sizeof(fname)); - if (!ret) return -1; - - return get_frag_list_for_file(fname, id); -} - -bool Wbfs_Fat::ShowFreeSpace(void) -{ - return false; -} diff --git a/source/usbloader/wbfs/wbfs_fat.h b/source/usbloader/wbfs/wbfs_fat.h deleted file mode 100644 index 6e2783be..00000000 --- a/source/usbloader/wbfs/wbfs_fat.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _WBFS_FAT_H -#define _WBFS_FAT_H - -#include - -#include "usbloader/splits.h" -#include "wbfs_base.h" - -class Wbfs_Fat: public Wbfs -{ - public: - Wbfs_Fat(u32 device, u32 lba, u32 size); - ~Wbfs_Fat(); - - virtual s32 Open(); - wbfs_disc_t* OpenDisc(u8 *); - void CloseDisc(wbfs_disc_t *); - - s32 GetCount(u32 *); - s32 GetHeaders(struct discHdr *, u32, u32); - - s32 AddGame(); - s32 RemoveGame(u8 *); - - s32 DiskSpace(f32 *, f32 *); - - s32 RenameGame(u8 *, const void *); - s32 ReIDGame(u8 *, const void *); - - f32 EstimateGameSize(); - - int GetFragList(u8 *); - virtual bool ShowFreeSpace(void); - - protected: - static char wbfs_fs_drive[16]; - private: - split_info_t split; - - static u32 fat_sector_size; - static char wbfs_fat_dir[16]; - static char invalid_path[]; - static struct discHdr *fat_hdr_list; - static u32 fat_hdr_count; - - wbfs_t* OpenPart(char *fname); - void ClosePart(wbfs_t* part); - wbfs_t* CreatePart(u8 *id, char *path); - int FindFilename(u8 *id, char *fname, int len); - void Filename(u8 *id, char *fname, int len, char *path); - bool CheckLayoutB(char *fname, int len, u8* id, char *fname_title); - s32 GetHeadersCount(); - void GetDir(struct discHdr *header, char *path); - - void mk_title_txt(struct discHdr *header, char *path); - void mk_gameid_title(struct discHdr *header, char *name, int re_space, int layout); - void title_filename(char *title); - bool is_gameid(char *id); - - static int nop_rw_sector(void *_fp, u32 lba, u32 count, void* buf) - { - return 0; - } -}; - -#endif //_WBFS_FAT_H diff --git a/source/usbloader/wbfs/wbfs_ntfs.cpp b/source/usbloader/wbfs/wbfs_ntfs.cpp deleted file mode 100644 index 456a7f09..00000000 --- a/source/usbloader/wbfs/wbfs_ntfs.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "wbfs_ntfs.h" -#include "fatmounter.h" -#include "libs/libntfs/ntfsfile_frag.h" - -s32 Wbfs_Ntfs::Open() -{ - strcpy(wbfs_fs_drive, "NTFS:"); - return MountNTFS(lba); -} - -bool Wbfs_Ntfs::ShowFreeSpace(void) -{ - return true; -} diff --git a/source/usbloader/wbfs/wbfs_ntfs.h b/source/usbloader/wbfs/wbfs_ntfs.h deleted file mode 100644 index 2551c7a9..00000000 --- a/source/usbloader/wbfs/wbfs_ntfs.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _WBFS_NTFS_H -#define _WBFS_NTFS_H - -#include "wbfs_fat.h" - -class Wbfs_Ntfs: public Wbfs_Fat -{ - public: - Wbfs_Ntfs(u32 device, u32 lba, u32 size) : - Wbfs_Fat(device, lba, size) - { - } - - virtual s32 Open(); - - bool ShowFreeSpace(void); -}; - -#endif //_WBFS_NTFS_H diff --git a/source/usbloader/wbfs/wbfs_rw.c b/source/usbloader/wbfs/wbfs_rw.c deleted file mode 100644 index 28610c60..00000000 --- a/source/usbloader/wbfs/wbfs_rw.c +++ /dev/null @@ -1,168 +0,0 @@ -#include -#include -#include - -#include "usbloader/sdhc.h" -#include "usbloader/usbstorage2.h" -#include "usbloader/wdvd.h" -#include "wbfs_rw.h" - -/* Constants */ -#define MAX_NB_SECTORS 32 - -u32 sector_size = 512; -rw_sector_callback_t readCallback = NULL; -rw_sector_callback_t writeCallback = NULL; - -void SetSectorSize(u32 size) -{ - sector_size = size; -} - -s32 __ReadDVD(void *fp, u32 lba, u32 len, void *iobuf) -{ - void *buffer = NULL; - - u64 offset; - u32 mod, size; - s32 ret; - - /* Calculate offset */ - offset = ((u64) lba) << 2; - - /* Calcualte sizes */ - mod = len % 32; - size = len - mod; - - /* Read aligned data */ - if (size) - { - ret = WDVD_UnencryptedRead(iobuf, size, offset); - if (ret < 0) goto out; - } - - /* Read non-aligned data */ - if (mod) - { - /* Allocate memory */ - buffer = memalign(32, 0x20); - if (!buffer) return -1; - - /* Read data */ - ret = WDVD_UnencryptedRead(buffer, 0x20, offset + size); - if (ret < 0) goto out; - - /* Copy data */ - void *ptr = ((u8 *) iobuf) + size; - memcpy(ptr, buffer, mod); - } - - /* Success */ - ret = 0; - - out: - /* Free memory */ - if (buffer) free(buffer); - - return ret; -} - -s32 __ReadUSB(void *fp, u32 lba, u32 count, void *iobuf) -{ - u32 cnt = 0; - s32 ret; - - /* Do reads */ - while (cnt < count) - { - void *ptr = ((u8 *) iobuf) + (cnt * sector_size); - u32 sectors = (count - cnt); - - /* Read sectors is too big */ - if (sectors > MAX_NB_SECTORS) sectors = MAX_NB_SECTORS; - - /* USB read */ - ret = USBStorage2_ReadSectors(lba + cnt, sectors, ptr); - if (ret < 0) return ret; - - /* Increment counter */ - cnt += sectors; - } - - return 0; -} - -s32 __WriteUSB(void *fp, u32 lba, u32 count, void *iobuf) -{ - u32 cnt = 0; - s32 ret; - - /* Do writes */ - while (cnt < count) - { - void *ptr = ((u8 *) iobuf) + (cnt * sector_size); - u32 sectors = (count - cnt); - - /* Write sectors is too big */ - if (sectors > MAX_NB_SECTORS) sectors = MAX_NB_SECTORS; - - /* USB write */ - ret = USBStorage2_WriteSectors(lba + cnt, sectors, ptr); - if (ret < 0) return ret; - - /* Increment counter */ - cnt += sectors; - } - - return 0; -} - -s32 __ReadSDHC(void *fp, u32 lba, u32 count, void *iobuf) -{ - u32 cnt = 0; - s32 ret; - - /* Do reads */ - while (cnt < count) - { - void *ptr = ((u8 *) iobuf) + (cnt * sector_size); - u32 sectors = (count - cnt); - - /* Read sectors is too big */ - if (sectors > MAX_NB_SECTORS) sectors = MAX_NB_SECTORS; - - /* SDHC read */ - ret = SDHC_ReadSectors(lba + cnt, sectors, ptr); - if (!ret) return -1; - - /* Increment counter */ - cnt += sectors; - } - - return 0; -} - -s32 __WriteSDHC(void *fp, u32 lba, u32 count, void *iobuf) -{ - u32 cnt = 0; - s32 ret; - - /* Do writes */ - while (cnt < count) - { - void *ptr = ((u8 *) iobuf) + (cnt * sector_size); - u32 sectors = (count - cnt); - - /* Write sectors is too big */ - if (sectors > MAX_NB_SECTORS) sectors = MAX_NB_SECTORS; - - /* SDHC write */ - ret = SDHC_WriteSectors(lba + cnt, sectors, ptr); - if (!ret) return -1; - - /* Increment counter */ - cnt += sectors; - } - - return 0; -} diff --git a/source/usbloader/wbfs/wbfs_rw.h b/source/usbloader/wbfs/wbfs_rw.h deleted file mode 100644 index 528765b0..00000000 --- a/source/usbloader/wbfs/wbfs_rw.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _WBFS_RW_H -#define _WBFS_RW_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "libs/libwbfs/libwbfs.h" - - extern u32 sector_size; - extern rw_sector_callback_t readCallback; - extern rw_sector_callback_t writeCallback; - - s32 __ReadDVD(void *fp, u32 lba, u32 len, void *iobuf); - s32 __ReadUSB(void *fp, u32 lba, u32 count, void *iobuf); - s32 __WriteUSB(void *fp, u32 lba, u32 count, void *iobuf); - s32 __ReadSDHC(void *fp, u32 lba, u32 count, void *iobuf); - s32 __WriteSDHC(void *fp, u32 lba, u32 count, void *iobuf); - -#ifdef __cplusplus -} -#endif - -#endif //_WBFS_RW_H diff --git a/source/usbloader/wbfs/wbfs_wbfs.cpp b/source/usbloader/wbfs/wbfs_wbfs.cpp deleted file mode 100644 index 27c98aec..00000000 --- a/source/usbloader/wbfs/wbfs_wbfs.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include "wbfs_wbfs.h" -#include "prompts/ProgressWindow.h" -#include "settings/CSettings.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; - - partition_selector_t part_sel = (partition_selector_t) Settings.InstallPartitions; - - /* Add game to device */ - ret = wbfs_add_disc(hdd, __ReadDVD, NULL, ProgressCallback, part_sel, 0); - 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 = (partition_selector_t) Settings.InstallPartitions; - return wbfs_estimate_disc(hdd, __ReadDVD, NULL, part_sel); -} diff --git a/source/usbloader/wbfs/wbfs_wbfs.h b/source/usbloader/wbfs/wbfs_wbfs.h deleted file mode 100644 index 7cbee6eb..00000000 --- a/source/usbloader/wbfs/wbfs_wbfs.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _WBFS_WBFS_H -#define _WBFS_WBFS_H - -#include "wbfs_base.h" -#include "libs/libwbfs/libwbfs.h" - -class Wbfs_Wbfs: public Wbfs -{ - public: - Wbfs_Wbfs(u32 device, u32 lba, u32 size) : - Wbfs(device, lba, size) - { - } - - s32 Open(); - wbfs_disc_t* OpenDisc(u8 *); - void CloseDisc(wbfs_disc_t *); - - s32 Format(); - s32 GetCount(u32 *); - s32 GetHeaders(struct discHdr *, u32, u32); - - s32 AddGame(); - s32 RemoveGame(u8 *); - - s32 DiskSpace(f32 *, f32 *); - - s32 RenameGame(u8 *, const void *); - s32 ReIDGame(u8 *, const void *); - - f32 EstimateGameSize(); -}; - -#endif //_WBFS_WBFS_H diff --git a/source/usbloader/wdvd.c b/source/usbloader/wdvd.c deleted file mode 100644 index 32938d7c..00000000 --- a/source/usbloader/wdvd.c +++ /dev/null @@ -1,437 +0,0 @@ -#include -#include -#include -#include -#include "gecko.h" -#include "wbfs.h" - -/* Constants */ -#define IOCTL_DI_READID 0x70 -#define IOCTL_DI_READ 0x71 -#define IOCTL_DI_WAITCVRCLOSE 0x79 -#define IOCTL_DI_GETCOVER 0x88 -#define IOCTL_DI_RESET 0x8A -#define IOCTL_DI_OPENPART 0x8B -#define IOCTL_DI_CLOSEPART 0x8C -#define IOCTL_DI_UNENCREAD 0x8D -#define IOCTL_DI_SEEK 0xAB -#define IOCTL_DI_STOPLASER 0xD2 -#define IOCTL_DI_OFFSET 0xD9 -#define IOCTL_DI_DISC_BCA 0xDA -#define IOCTL_DI_STOPMOTOR 0xE3 -#define IOCTL_DI_SETWBFSMODE 0xF4 -#define IOCTL_DI_GETWBFSMODE 0xF5 // odip -#define IOCTL_DI_DISABLERESET 0xF6 // odip - -/** Hermes IOS222 **/ -#define DI_SETWBFSMODE 0xfe - -#define IOCTL_DI_SETFRAG 0xF9 -#define IOCTL_DI_GETMODE 0xFA - -/* Variables */ -static u32 inbuf[8] ATTRIBUTE_ALIGN(32); -static u32 outbuf[8] ATTRIBUTE_ALIGN(32); - -static const char di_fs[] ATTRIBUTE_ALIGN(32) = "/dev/di"; -static s32 di_fd = -1; - - -s32 WDVD_Init(void) -{ - /* Open "/dev/di" */ - if (di_fd < 0) { - di_fd = IOS_Open(di_fs, 0); - if (di_fd < 0) - return di_fd; - } - - return 0; -} - -s32 WDVD_Close(void) -{ - /* Close "/dev/di" */ - if (di_fd >= 0) { - IOS_Close(di_fd); - di_fd = -1; - } - - return 0; -} - -s32 WDVD_GetHandle(void) -{ - /* Return di handle */ - return di_fd; -} - -s32 WDVD_Reset(void) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Reset drive */ - inbuf[0] = IOCTL_DI_RESET << 24; - inbuf[1] = 1; - - - ret = IOS_Ioctl(di_fd, IOCTL_DI_RESET, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_ReadDiskId(void *id) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Read disc ID */ - inbuf[0] = IOCTL_DI_READID << 24; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_READID, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - if (ret == 1) { - memcpy(id, outbuf, sizeof(dvddiskid)); - return 0; - } - - return -ret; -} - -s32 WDVD_Seek(u64 offset) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Drive seek */ - inbuf[0] = IOCTL_DI_SEEK << 24; - inbuf[1] = (u32)(offset >> 2); - - ret = IOS_Ioctl(di_fd, IOCTL_DI_SEEK, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; - -} - -s32 WDVD_Offset(u64 offset) -{ - if (di_fd < 0) - return di_fd; - - //u32 *off = (u32 *)((void *)&offset); - union { u64 off64; u32 off32[2]; } off;off.off64 = offset; - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Set offset */ - inbuf[0] = IOCTL_DI_OFFSET << 24; - inbuf[1] = (off.off32[0]) ? 1: 0; - inbuf[2] = (off.off32[1] >> 2); - - ret = IOS_Ioctl(di_fd, IOCTL_DI_OFFSET, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_StopLaser(void) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Stop laser */ - inbuf[0] = IOCTL_DI_STOPLASER << 24; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_STOPLASER, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_StopMotor(void) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Stop motor */ - inbuf[0] = IOCTL_DI_STOPMOTOR << 24; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_STOPMOTOR, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_OpenPartition(u64 offset) -{ - if (di_fd < 0) - return di_fd; - - static u8 Tmd_Buffer[0x4A00] ATTRIBUTE_ALIGN(32); - static ioctlv Vectors[5] ATTRIBUTE_ALIGN(32); - s32 ret; - - memset(inbuf, 0, sizeof inbuf); - memset(outbuf, 0, sizeof outbuf); - - inbuf[0] = IOCTL_DI_OPENPART << 24; - inbuf[1] = offset >> 2; - - Vectors[0].data = inbuf; - Vectors[0].len = 0x20; - Vectors[1].data = 0; - Vectors[1].len = 0; - Vectors[2].data = 0; - Vectors[2].len = 0; - Vectors[3].data = Tmd_Buffer; - Vectors[3].len = 0x49e4; - Vectors[4].data = outbuf; - Vectors[4].len = 0x20; - - ret = IOS_Ioctlv(di_fd, IOCTL_DI_OPENPART, 3, 2, (ioctlv *)Vectors); - - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_ClosePartition(void) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Close partition */ - inbuf[0] = IOCTL_DI_CLOSEPART << 24; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_CLOSEPART, inbuf, sizeof(inbuf), NULL, 0); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_UnencryptedRead(void *buf, u32 len, u64 offset) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Unencrypted read */ - inbuf[0] = IOCTL_DI_UNENCREAD << 24; - inbuf[1] = len; - inbuf[2] = (u32)(offset >> 2); - - ret = IOS_Ioctl(di_fd, IOCTL_DI_UNENCREAD, inbuf, sizeof(inbuf), buf, len); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_Read(void *buf, u32 len, u64 offset) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Disc read */ - inbuf[0] = IOCTL_DI_READ << 24; - inbuf[1] = len; - inbuf[2] = (u32)(offset >> 2); - - ret = IOS_Ioctl(di_fd, IOCTL_DI_READ, inbuf, sizeof(inbuf), buf, len); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_WaitForDisc(void) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Wait for disc */ - inbuf[0] = IOCTL_DI_WAITCVRCLOSE << 24; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_WAITCVRCLOSE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_GetCoverStatus(u32 *status) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Get cover status */ - inbuf[0] = IOCTL_DI_GETCOVER << 24; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_GETCOVER, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - if (ret == 1) { - /* Copy cover status */ - memcpy(status, outbuf, sizeof(u32)); - - return 0; - } - - return -ret; -} - -s32 WDVD_SetUSBMode(const u8 *id, s32 partition) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Set USB mode */ - inbuf[0] = IOCTL_DI_SETWBFSMODE << 24; - inbuf[1] = (id) ? WBFS_DEVICE_USB : 0; - - /* Copy ID */ - if (id) { - memcpy(&inbuf[2], id, 6); - if(partition >= 0) { - inbuf[5] = partition; - } - } - - ret = IOS_Ioctl(di_fd, IOCTL_DI_SETWBFSMODE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret!=1) { - // Try old cIOS 222 - /* Set USB mode */ - inbuf[0] = DI_SETWBFSMODE << 24; - ret = IOS_Ioctl(di_fd, DI_SETWBFSMODE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - } - - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_Read_Disc_BCA(void *buf) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Disc read */ - inbuf[0] = IOCTL_DI_DISC_BCA << 24; - //inbuf[1] = 64; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_DISC_BCA, inbuf, sizeof(inbuf), buf, 64); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -// frag - -s32 WDVD_SetFragList(int device, void *fraglist, int size) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - memset(outbuf, 0, sizeof(outbuf)); - - /* Set FRAG mode */ - inbuf[0] = IOCTL_DI_SETFRAG << 24; - inbuf[1] = device; - inbuf[2] = (u32)fraglist; - inbuf[3] = size; - - DCFlushRange(fraglist, size); - ret = IOS_Ioctl(di_fd, IOCTL_DI_SETFRAG, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} - -s32 WDVD_Eject(void) -{ - if (di_fd < 0) - return di_fd; - - s32 ret; - - memset(inbuf, 0, sizeof(inbuf)); - - /* Stop motor */ - inbuf[0] = IOCTL_DI_STOPMOTOR << 24; - /* Eject DVD */ - inbuf[1] = 1; - - ret = IOS_Ioctl(di_fd, IOCTL_DI_STOPMOTOR, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); - if (ret < 0) - return ret; - - return (ret == 1) ? 0 : -ret; -} diff --git a/source/usbloader/wdvd.h b/source/usbloader/wdvd.h deleted file mode 100644 index 295a9975..00000000 --- a/source/usbloader/wdvd.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _WDVD_H_ -#define _WDVD_H_ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* Prototypes */ -s32 WDVD_Init(void); -s32 WDVD_Close(void); -s32 WDVD_GetHandle(void); -s32 WDVD_Reset(void); -s32 WDVD_ReadDiskId(void *); -s32 WDVD_Seek(u64); -s32 WDVD_Offset(u64); -s32 WDVD_StopLaser(void); -s32 WDVD_StopMotor(void); -s32 WDVD_OpenPartition(u64 offset); -s32 WDVD_ClosePartition(void); -s32 WDVD_UnencryptedRead(void *, u32, u64); -s32 WDVD_Read(void *, u32, u64); -s32 WDVD_WaitForDisc(void); -s32 WDVD_GetCoverStatus(u32 *); -s32 WDVD_SetUSBMode(const u8 *, s32); -s32 WDVD_Eject(void); -s32 WDVD_Read_Disc_BCA(void *); -s32 WDVD_SetFragList(int device, void *fraglist, int size); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif - diff --git a/source/utils/PasswordCheck.cpp b/source/utils/PasswordCheck.cpp deleted file mode 100644 index a0ceb595..00000000 --- a/source/utils/PasswordCheck.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "prompts/PromptWindows.h" - -int PasswordCheck(const char * password) -{ - if(!password || strcmp(password, "") == 0 || strcmp(password, "not set") == 0) - return 2; - - char entered[100]; - memset(entered, 0, sizeof(entered)); - - int result = OnScreenKeyboard(entered, 20, 0); - if (result == 1) - { - if (strcmp(entered, password) == 0) //if password correct - return 1; - else - return -1; - } - - return 0; -} diff --git a/source/utils/PasswordCheck.h b/source/utils/PasswordCheck.h deleted file mode 100644 index 9df6cc22..00000000 --- a/source/utils/PasswordCheck.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PASSWORD_CHECK_H_ -#define PASSWORD_CHECK_H_ - -int PasswordCheck(const char * password); - -#endif diff --git a/source/utils/ResourceManager.cpp b/source/utils/ResourceManager.cpp deleted file mode 100644 index a18881f7..00000000 --- a/source/utils/ResourceManager.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include "ResourceManager.h" - -ResourceManager * ResourceManager::instance = NULL; - -ResourceManager * ResourceManager::Instance() -{ - if (instance == NULL) - { - instance = new ResourceManager(); - } - return instance; -} - -void ResourceManager::DestroyInstance() -{ - if (instance != NULL) - { - delete instance; - instance = NULL; - } -} - -ResourceManager::~ResourceManager() -{ - // Delete all images... - std::map::iterator imgitr; - for (imgitr = images.begin(); imgitr != images.end(); imgitr++) - { - if(imgitr->second.data) - free(imgitr->second.data); - } - images.clear(); - imageCount.clear(); -} - -void ResourceManager::AddImageData(const u8 *img, ImageData & Data) -{ - ResourceManager::Instance()->InternalAddImageData(img, Data); -} - -ImageData * ResourceManager::GetImageData(const u8 *img) -{ - return ResourceManager::Instance()->InternalGetImageData(img); -} - -void ResourceManager::Remove(u8 * img) -{ - ResourceManager::Instance()->InternalRemoveImageData(img); -} - -void ResourceManager::InternalAddImageData(const u8 * img, ImageData & Data) -{ - std::map::iterator itr = images.find(img); - if (itr != images.end()) - return; - - images[img] = Data; - imageCount[Data.data] = 1; -} - -ImageData * ResourceManager::InternalGetImageData(const u8 *img) -{ - std::map::iterator itr = images.find(img); - if (itr == images.end()) - return NULL; - - imageCount[itr->second.data]++; - - return &itr->second; -} - -void ResourceManager::InternalRemoveImageData(u8 * img) -{ - std::map::iterator itr = imageCount.find(img); - if (itr != imageCount.end()) - { - itr->second--; - - if (itr->second == 0) // Remove the resource - { - imageCount.erase(itr); - - std::map::iterator iitr; - for (iitr = images.begin(); iitr != images.end(); iitr++) - { - if (iitr->second.data == img) - { - if(iitr->second.data) - free(iitr->second.data); - images.erase(iitr); - break; - } - } - } - } - else if(img) - { - //! This case should actually never accur - free(img); - } -} diff --git a/source/utils/ResourceManager.h b/source/utils/ResourceManager.h deleted file mode 100644 index 320ca910..00000000 --- a/source/utils/ResourceManager.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef _RESOURCE_MANAGER_H -#define _RESOURCE_MANAGER_H - -#include - -#include "libwiigui/gui.h" -#include "filelist.h" - -#include - -typedef struct _ImageData -{ - u8 * data; - int width; - int height; - u8 format; -} ImageData; - -class ResourceManager -{ - public: - static ResourceManager *Instance(); - static void DestroyInstance(); - - static void AddImageData(const u8 *img, ImageData & data); - static ImageData * GetImageData(const u8 *img); - static void Remove(u8 * img); - private: - void InternalAddImageData(const u8 * img, ImageData & Data); - ImageData *InternalGetImageData(const u8 *img); - void InternalRemoveImageData(u8 * img); - - ~ResourceManager(); - - static ResourceManager *instance; - - std::map images; - std::map imageCount; -}; - -#endif //_ResourceManager_H diff --git a/source/utils/ShowError.cpp b/source/utils/ShowError.cpp deleted file mode 100644 index ad9c8e09..00000000 --- a/source/utils/ShowError.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -#include "language/gettext.h" -#include "prompts/PromptWindows.h" - -extern "C" void ShowError(const char * format, ...) -{ - char *tmp=0; - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va)>=0) && tmp) - { - WindowPrompt(tr("Error:"), tmp, tr("OK")); - } - va_end(va); - - if(tmp) - free(tmp); -} diff --git a/source/utils/ShowError.h b/source/utils/ShowError.h deleted file mode 100644 index 20f64aed..00000000 --- a/source/utils/ShowError.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef SHOWERROR_H_ -#define SHOWERROR_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void ShowError(const char * format, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/utils/StringTools.c b/source/utils/StringTools.c deleted file mode 100644 index 1f19dcd9..00000000 --- a/source/utils/StringTools.c +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include - -const char * fmt(const char * format, ...) -{ - static char strChar[512]; - strChar[0] = 0; - char * tmp = NULL; - - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - snprintf(strChar, sizeof(strChar), tmp); - free(tmp); - va_end(va); - return (const char *) strChar; - } - va_end(va); - - if(tmp) - free(tmp); - - return NULL; -} - -const wchar_t * wfmt(const char * format, ...) -{ - static wchar_t strWChar[512]; - strWChar[0] = 0; - - if(!format) - return (const wchar_t *) strWChar; - - if(strcmp(format, "") == 0) - return (const wchar_t *) strWChar; - - char * tmp = NULL; - - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - int bt; - int strlength = strlen(tmp); - bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512 ); - free(tmp); - tmp = 0; - - if(bt > 0) - { - strWChar[bt] = 0; - return (const wchar_t *) strWChar; - } - } - va_end(va); - - if(tmp) - free(tmp); - - return NULL; -} - -bool char2wchar_t(const char * strChar, wchar_t * dest) -{ - if(!strChar || !dest) - return false; - - int bt; - bt = mbstowcs(dest, strChar, strlen(strChar)); - if (bt > 0) { - dest[bt] = 0; - return true; - } - - return false; -} - -int strtokcmp(const char * string, const char * compare, const char * separator) -{ - if(!string || !compare) - return -1; - - char TokCopy[512]; - strcpy(TokCopy, compare); - - char * strTok = strtok(TokCopy, separator); - - while (strTok != NULL) - { - if (strcasecmp(string, strTok) == 0) - { - return 0; - } - strTok = strtok(NULL,separator); - } - - return -1; -} - -inline const char * FullpathToFilename(const char *path) -{ - if(!path) return path; - - const char * ptr = path; - const char * Filename = ptr; - - while(*ptr != '\0') - { - if(*ptr == '/' && ptr[1] != '\0') - Filename = ptr+1; - - ++ptr; - } - - return Filename; -} diff --git a/source/utils/StringTools.h b/source/utils/StringTools.h deleted file mode 100644 index d9c0a856..00000000 --- a/source/utils/StringTools.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef __STRING_TOOLS_H -#define __STRING_TOOLS_H - -#ifdef __cplusplus -extern "C" { -#endif - -//! fmt and wfmt can only be used once at a session and the strings needs -//! to be copied afterwards. A second use overwrites the first string. -const char * fmt(const char * format, ...); -const wchar_t * wfmt(const char * format, ...); -bool char2wchar_t(const char * src, wchar_t * dest); -int strtokcmp(const char * string, const char * compare, const char * separator); -const char * FullpathToFilename(const char *path); - -#ifdef __cplusplus -} -#endif //__cplusplus - -#endif /* __STRING_TOOLS_H */ - diff --git a/source/utils/encrypt.c b/source/utils/encrypt.c deleted file mode 100644 index 53cadbe1..00000000 --- a/source/utils/encrypt.c +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by dude, Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include - -//! No need for high security crap. It's a simple encrypter/decrypter -//! with a constant sid. -const char * sid = "USBLoaderGX"; - -void EncryptString(const char *src, char *dst) -{ - unsigned int i; - char tmp[3]; - dst[0] = 0; - - for (i = 0; i < strlen(src); i++) - { - sprintf(tmp, "%02x", src[i] ^ sid[i%10]); - strcat(dst, tmp); - } -} - -void DecryptString(const char *src, char *dst) -{ - unsigned int i; - for (i = 0; i < strlen(src); i += 2) - { - char c = (src[i] >= 'a' ? (src[i] - 'a') + 10 : (src[i] - '0')) << 4; - c += (src[i+1] >= 'a' ? (src[i+1] - 'a') + 10 : (src[i+1] - '0')); - dst[i>>1] = c ^ sid[(i>>1)%10]; - } - dst[strlen(src)>>1] = 0; -} - diff --git a/source/utils/encrypt.h b/source/utils/encrypt.h deleted file mode 100644 index 6c8139de..00000000 --- a/source/utils/encrypt.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by dude - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef __ENCRYPT_H -#define __ENCRYPT_H - -#ifdef __cplusplus -extern "C" { -#endif - -void EncryptString(const char *src, char *dst); -void DecryptString(const char *src, char *dst); - -#ifdef __cplusplus -} -#endif //__cplusplus - -#endif /* __ENCRYPT_H */ - diff --git a/source/utils/minizip/miniunz.c b/source/utils/minizip/miniunz.c deleted file mode 100644 index c54725c7..00000000 --- a/source/utils/minizip/miniunz.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - miniunz.c - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - */ - -#include -#include -#include -#include -#include -#include -# include -# include - -#include "miniunz.h" - -#define CASESENSITIVITY (0) -#define WRITEBUFFERSIZE (8192) -#define MAXFILENAME (256) - -static int mymkdir(const char* dirname) -{ - int ret = 0; - ret = mkdir(dirname, 0775); - return ret; -} - -int makedir(char *newdir) -{ - char *buffer; - char *p; - int len = (int) strlen(newdir); - - if (len <= 0) return 0; - - buffer = (char*) malloc(len + 1); - strcpy(buffer, newdir); - - if (buffer[len - 1] == '/') - { - buffer[len - 1] = '\0'; - } - if (mymkdir(buffer) == 0) - { - free(buffer); - return 1; - } - - p = buffer + 1; - while (1) - { - char hold; - - while (*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mymkdir(buffer) == -1) && (errno == ENOENT)) - { - // printf("couldn't create directory %s\n",buffer); - free(buffer); - return 0; - } - if (hold == 0) break; - *p++ = hold; - } - free(buffer); - return 1; -} - -static char *fullfilename(const char *basedir, char *filename) -{ - char *file = (char *) malloc(strlen(basedir) + strlen(filename) + 1); - if (basedir == NULL) - { - strcpy(file, filename); - } - else - { - if (basedir[strlen(basedir) - 1] == '/') - { - sprintf(file, "%s%s", basedir, filename); - } - else - { - sprintf(file, "%s/%s", basedir, filename); - } - } - return file; -} - -static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, - const char* password, const char *basedir) -{ - char filename_inzip[256]; - char* filename_withoutpath; - char* filename_withpath; - char* p; - int err = UNZ_OK; - FILE *fout = NULL; - void* buf; - uInt size_buf; - - unz_file_info file_info; - err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); - - if (err != UNZ_OK) - { - // printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); - return err; - } - - size_buf = WRITEBUFFERSIZE; - buf = (void*) malloc(size_buf); - if (buf == NULL) - { - // printf("Error allocating memory\n"); - return UNZ_INTERNALERROR; - } - - p = filename_withoutpath = filename_inzip; - filename_withpath = fullfilename(basedir, filename_inzip); - while ((*p) != '\0') - { - if (((*p) == '/') || ((*p) == '\\')) filename_withoutpath = p + 1; - p++; - } - - if ((*filename_withoutpath) == '\0') - { - if ((*popt_extract_without_path) == 0) - { - - // Fix the path, this will fail if the directoryname is the same as the first filename in the zip - char *path = (char *) malloc(strlen(filename_withpath)); - strcpy(path, filename_withpath); - char *ptr = strstr(path, filename_withoutpath); - *ptr = '\0'; - - // printf("creating directory: %s\n",path); - mymkdir(path); - - free(path); - } - } - else - { - char* write_filename; - int skip = 0; - - if ((*popt_extract_without_path) == 0) - write_filename = filename_withpath; - else write_filename = filename_withoutpath; - - err = unzOpenCurrentFilePassword(uf, password); - if (err != UNZ_OK) - { - // printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); - } - - if (((*popt_overwrite) == 0) && (err == UNZ_OK)) - { - char rep = 0; - FILE* ftestexist; - ftestexist = fopen(write_filename, "rb"); - if (ftestexist != NULL) - { - fclose(ftestexist); - do - { - char answer[128]; - int ret; - - // printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); - ret = scanf("%1s", answer); - if (ret != 1) - { - exit(EXIT_FAILURE); - } - rep = answer[0]; - if ((rep >= 'a') && (rep <= 'z')) rep -= 0x20; - } while ((rep != 'Y') && (rep != 'N') && (rep != 'A')); - } - - if (rep == 'N') skip = 1; - - if (rep == 'A') *popt_overwrite = 1; - } - - if ((skip == 0) && (err == UNZ_OK)) - { - fout = fopen(write_filename, "wb"); - - /* some zipfile don't contain directory alone before file */ - if ((fout == NULL) && ((*popt_extract_without_path) == 0) && (filename_withoutpath - != (char*) filename_inzip)) - { - char c = *(filename_withoutpath - 1); - *(filename_withoutpath - 1) = '\0'; - - // Fix the path, this will fail if the directoryname is the same as the first filename in the zip - char *path = (char *) malloc(strlen(write_filename)); - strcpy(path, write_filename); - char *ptr = strstr(path, filename_withoutpath); - *ptr = '\0'; - makedir(path); - free(path); - - *(filename_withoutpath - 1) = c; - fout = fopen(write_filename, "wb"); - } - - if (fout == NULL) - { - // printf("error opening %s\n",write_filename); - } - } - - if (fout != NULL) - { - // printf(" extracting: %s\n",write_filename); - - do - { - err = unzReadCurrentFile(uf, buf, size_buf); - if (err < 0) - { - // printf("error %d with zipfile in unzReadCurrentFile\n",err); - break; - } - if (err > 0) if (fwrite(buf, err, 1, fout) != 1) - { - // printf("error in writing extracted file\n"); - err = UNZ_ERRNO; - break; - } - } while (err > 0); - if (fout) fclose(fout); - - } - - if (err == UNZ_OK) - { - err = unzCloseCurrentFile(uf); - if (err != UNZ_OK) - { - // printf("error %d with zipfile in unzCloseCurrentFile\n",err); - } - } - else unzCloseCurrentFile(uf); /* don't lose the error */ - } - free(filename_withpath); - free(buf); - return err; -} - -int extractZip(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password, const char *basedir) -{ - uLong i; - unz_global_info gi; - int err; - - err = unzGetGlobalInfo(uf, &gi); - if (err != UNZ_OK) - // printf("error %d with zipfile in unzGetGlobalInfo \n",err); - - for (i = 0; i < gi.number_entry; i++) - { - if (do_extract_currentfile(uf, &opt_extract_without_path, &opt_overwrite, password, basedir) != UNZ_OK) break; - - if ((i + 1) < gi.number_entry) - { - err = unzGoToNextFile(uf); - if (err != UNZ_OK) - { - // printf("error %d with zipfile in unzGoToNextFile\n",err); - break; - } - } - } - - return 0; -} - -int extractZipOnefile(unzFile uf, const char* filename, int opt_extract_without_path, int opt_overwrite, - const char* password) -{ - if (unzLocateFile(uf, filename, CASESENSITIVITY) != UNZ_OK) - { - // printf("file %s not found in the zipfile\n",filename); - return 2; - } - - if (do_extract_currentfile(uf, &opt_extract_without_path, &opt_overwrite, password, NULL) == UNZ_OK) - return 0; - else return 1; -} diff --git a/source/utils/minizip/miniunz.h b/source/utils/minizip/miniunz.h deleted file mode 100644 index 216d31bd..00000000 --- a/source/utils/minizip/miniunz.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _miniunz_H -#define _miniunz_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include - - int extractZip(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char* password, - const char *basedir); - int extractZipOnefile(unzFile uf, const char* filename, int opt_extract_without_path, int opt_overwrite, - const char* password); - int makedir(char *newdir); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/utils/rockout.cpp b/source/utils/rockout.cpp deleted file mode 100644 index 1f69025c..00000000 --- a/source/utils/rockout.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "libwiigui/gui.h" -#include "themes/CTheme.h" -#include "usbloader/GameList.h" -#include "settings/GameTitles.h" -#include "menu/menus.h" - -extern GuiImageData * pointer[4]; - -void rockout(int gameSelected, int f) -{ - HaltGui(); - - if (gameSelected >= 0 && gameSelected < gameList.size() && (strcasestr(GameTitles.GetTitle(gameList[gameSelected]), "guitar") - || strcasestr(GameTitles.GetTitle(gameList[gameSelected]), "band") || strcasestr(GameTitles.GetTitle(gameList[gameSelected]), - "rock"))) - { - for (int i = 0; i < 4; i++) - delete pointer[i]; - pointer[0] = Resources::GetImageData("rplayer1_point.png"); - pointer[1] = Resources::GetImageData("rplayer2_point.png"); - pointer[2] = Resources::GetImageData("rplayer3_point.png"); - pointer[3] = Resources::GetImageData("rplayer4_point.png"); - } - else - { - - for (int i = 0; i < 4; i++) - delete pointer[i]; - pointer[0] = Resources::GetImageData("player1_point.png"); - pointer[1] = Resources::GetImageData("player2_point.png"); - pointer[2] = Resources::GetImageData("player3_point.png"); - pointer[3] = Resources::GetImageData("player4_point.png"); - } - ResumeGui(); -} diff --git a/source/utils/rockout.h b/source/utils/rockout.h deleted file mode 100644 index 3d4904da..00000000 --- a/source/utils/rockout.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef ROCKOUT_H_ -#define ROCKOUT_H_ - -void rockout(int gameSelected, int f = 0); - -#endif diff --git a/source/utils/timer.c b/source/utils/timer.c deleted file mode 100644 index c8b82021..00000000 --- a/source/utils/timer.c +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include "timer.h" - -bool TimePassed(int limit) -{ - static time_t starttime = 0; - time_t timer = time(NULL); - - if (starttime == 0) - starttime = timer; - - if(difftime(timer, starttime) >= limit) - { - starttime = 0; - return true; - } - - return false; -} - -#define PERIOD_4 (4 * 365 + 1) -#define PERIOD_100 (PERIOD_4 * 25 - 1) -#define PERIOD_400 (PERIOD_100 * 4 + 1) -void ConvertNTFSDate(u64 ulNTFSDate, TimeStruct * ptm) -{ - unsigned year, mon, day, hour, min, sec; - u64 v64 = ulNTFSDate; - u8 ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - unsigned temp; - u32 v; - v64 /= 10000000; - sec = (unsigned)(v64 % 60); - v64 /= 60; - min = (unsigned)(v64 % 60); - v64 /= 60; - hour = (unsigned)(v64 % 24)+1; - v64 /= 24; - - v = (u32)v64; - - year = (unsigned)(1601 + v / PERIOD_400 * 400); - v %= PERIOD_400; - - temp = (unsigned)(v / PERIOD_100); - if (temp == 4) - temp = 3; - year += temp * 100; - v -= temp * PERIOD_100; - - temp = v / PERIOD_4; - if (temp == 25) - temp = 24; - year += temp * 4; - v -= temp * PERIOD_4; - - temp = v / 365; - if (temp == 4) - temp = 3; - year += temp; - v -= temp * 365; - - if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) - ms[1] = 29; - for (mon = 1; mon <= 12; mon++) - { - unsigned s = ms[mon - 1]; - if (v < s) - break; - v -= s; - } - day = (unsigned)v + 1; - - ptm->tm_mday = (u32)day; - ptm->tm_mon = (u32)mon; - ptm->tm_year = (u32)year; - - ptm->tm_hour = (u32)hour; - ptm->tm_min = (u32)min; - ptm->tm_sec = (u32)sec; -} - -void ConvertDosDate(u64 ulDosDate, TimeStruct * ptm) -{ - u32 uDate; - uDate = (u32)(ulDosDate>>16); - ptm->tm_mday = (u32)(uDate&0x1f) ; - ptm->tm_mon = (u32)((((uDate)&0x1E0)/0x20)) ; - ptm->tm_year = (u32)(((uDate&0x0FE00)/0x0200)+1980) ; - - ptm->tm_hour = (u32) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (u32) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (u32) (2*(ulDosDate&0x1f)) ; -} diff --git a/source/utils/timer.h b/source/utils/timer.h deleted file mode 100644 index 9180a331..00000000 --- a/source/utils/timer.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef __TIMER_H -#define __TIMER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -typedef struct _TimeStruct -{ - u32 tm_sec; /* seconds after the minute - [0,59] */ - u32 tm_min; /* minutes after the hour - [0,59] */ - u32 tm_hour; /* hours since midnight - [0,23] */ - u32 tm_mday; /* day of the month - [1,31] */ - u32 tm_mon; /* months since January - [0,11] */ - u32 tm_year; /* years - [1980..2044] */ -} TimeStruct; - -bool TimePassed(int limit); -void ConvertDosDate(u64 ulDosDate, TimeStruct * ptm); -void ConvertNTFSDate(u64 ulNTFSDate, TimeStruct * ptm); - - -#ifdef __cplusplus -} - -class Timer -{ - public: - Timer() { starttick = gettime(); }; - ~Timer() { }; - float elapsed() { return (float) (gettime()-starttick)/(1000.0f*TB_TIMER_CLOCK); }; - float elapsed_millisecs() { return 1000.0f*elapsed(); }; - void reset() { starttick = gettime(); }; - protected: - u64 starttick; -}; - -#endif //__cplusplus - -#endif //__TIMER_H diff --git a/source/utils/tools.h b/source/utils/tools.h deleted file mode 100644 index 91c7cb37..00000000 --- a/source/utils/tools.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TOOLS_H_ -#define TOOLS_H_ - -#define cut_bounds(x, min, max) ( ((x) < (min)) ? (min) : ((x) > (max)) ? (max) : (x) ) - -#endif diff --git a/source/utils/uncompress.c b/source/utils/uncompress.c deleted file mode 100644 index 049b0386..00000000 --- a/source/utils/uncompress.c +++ /dev/null @@ -1,185 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include - -#include "uncompress.h" - -struct _LZ77Info -{ - u16 length : 4; - u16 offset : 12; -} __attribute__((packed)); - -typedef struct _LZ77Info LZ77Info; - -u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * size) -{ - u8 *buffer = NULL; - if (inLength <= 0x8 || *((const u32 *)inBuf) != 0x4C5A3737 /*"LZ77"*/ || inBuf[4] != 0x10) - return NULL; - - u32 uncSize = le32(((const u32 *)inBuf)[1] << 8); - - const u8 *inBufEnd = inBuf + inLength; - inBuf += 8; - - buffer = (u8 *) malloc(uncSize); - - if (!buffer) - return buffer; - - u8 *bufCur = buffer; - u8 *bufEnd = buffer + uncSize; - - while (bufCur < bufEnd && inBuf < inBufEnd) - { - u8 flags = *inBuf; - ++inBuf; - int i = 0; - for (i = 0; i < 8 && bufCur < bufEnd && inBuf < inBufEnd; ++i) - { - if ((flags & 0x80) != 0) - { - const LZ77Info * info = (const LZ77Info *)inBuf; - inBuf += sizeof (LZ77Info); - int length = info->length + 3; - if (bufCur - info->offset - 1 < buffer || bufCur + length > bufEnd) - return buffer; - memcpy(bufCur, bufCur - info->offset - 1, length); - bufCur += length; - } - else - { - *bufCur = *inBuf; - ++inBuf; - ++bufCur; - } - flags <<= 1; - } - } - - *size = uncSize; - - return buffer; -} - -//Thanks to _demo_ for this function -//src points to the yaz0 source data (to the "real" source data, not at the header!) -//dst points to a buffer uncompressedSize bytes large (you get uncompressedSize from -//the second 4 bytes in the Yaz0 header). -void uncompressYaz0(const u8* srcBuf, u8* dst, int uncompressedSize) -{ - const u8 * src = srcBuf; - - if(memcmp(src, "Yaz0", 4) == 0) - { - src += sizeof(Yaz0_Header); - } - - int srcPlace = 0, dstPlace = 0; //current read/write positions - - u32 validBitCount = 0; //number of valid bits left in "code" byte - u8 currCodeByte = 0; - - while(dstPlace < uncompressedSize) - { - //read new "code" byte if the current one is used up - if(validBitCount == 0) - { - currCodeByte = src[srcPlace]; - ++srcPlace; - validBitCount = 8; - } - - if((currCodeByte & 0x80) != 0) - { - //straight copy - dst[dstPlace] = src[srcPlace]; - dstPlace++; - srcPlace++; - } - else - { - //RLE part - u8 byte1 = src[srcPlace]; - u8 byte2 = src[srcPlace + 1]; - srcPlace += 2; - - u32 dist = ((byte1 & 0xF) << 8) | byte2; - u32 copySource = dstPlace - (dist + 1); - - u32 numBytes = byte1 >> 4; - if(numBytes == 0) - { - numBytes = src[srcPlace] + 0x12; - srcPlace++; - } - else - numBytes += 2; - - //copy run - u32 i = 0; - for(i = 0; i < numBytes; ++i) - { - dst[dstPlace] = dst[copySource]; - copySource++; - dstPlace++; - } - } - - //use next bit from "code" byte - currCodeByte <<= 1; - validBitCount-=1; - } -} - - -u32 CheckIMD5Type(const u8 * buffer, int length) -{ - if(*((u32 *) buffer) != 'IMD5') - { - return *((u32 *) buffer); - } - - const u8 * file = buffer+32; - - if(*((u32 *) file) != 'LZ77') - { - return *((u32 *) file); - } - - u32 uncSize = 0; - u8 * uncompressed_data = uncompressLZ77(file, length-32, &uncSize); - if(!uncompressed_data) - return 0; - - u32 * magic = (u32 *) uncompressed_data; - u32 Type = magic[0]; - free(uncompressed_data); - - return Type; -} diff --git a/source/utils/uncompress.h b/source/utils/uncompress.h deleted file mode 100644 index 2ebb3858..00000000 --- a/source/utils/uncompress.h +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef __UNCOMPRESS_H -#define __UNCOMPRESS_H - -#include - -#define le16(i) (((((u16) i) & 0xFF) << 8) | ((((u16) i) & 0xFF00) >> 8)) -#define le32(i) (((((u32) i) & 0xFF) << 24) | ((((u32) i) & 0xFF00) << 8) | \ - ((((u32) i) & 0xFF0000) >> 8) | ((((u32) i) & 0xFF000000) >> 24)) - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - u32 magic; //Yaz0 - u32 decompressed_size; - u8 zeros[8]; -} Yaz0_Header; - -u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * uncSize); -void uncompressYaz0(const u8* srcBuf, u8* dst, int uncompressedSize); -u32 CheckIMD5Type(const u8 * buffer, int length); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/utils/wifi_gecko.c b/source/utils/wifi_gecko.c deleted file mode 100644 index a5dc92dd..00000000 --- a/source/utils/wifi_gecko.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include - -#define DESTINATION_IP "192.168.178.3" -#define DESTINATION_PORT 4405 - -static int connection = -1; - -void WifiGecko_Close() -{ - if(connection >= 0) - net_close(connection); - - connection = -1; -} - -int WifiGecko_Connect() -{ - if(!(connection < 0)) - return connection; - - connection = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); - if (connection < 0) - return connection; - - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); - connect_addr.sin_family = AF_INET; - connect_addr.sin_port = htons(DESTINATION_PORT); - inet_aton(DESTINATION_IP, &connect_addr.sin_addr); - - if(net_connect(connection, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) - { - WifiGecko_Close(); - return -1; - } - - return connection; -} - -int WifiGecko_Send(const char * data, int datasize) -{ - if(!WifiGecko_Connect()) - return connection; - - int ret = 0, done = 0, blocksize = 1024; - - while (done < datasize) - { - if(blocksize > datasize-done) - blocksize = datasize-done; - - ret = net_send(connection, data+done, blocksize, 0); - if (ret < 0) - { - WifiGecko_Close(); - return ret; - } - else if(ret == 0) - { - break; - } - - done += ret; - usleep (1000); - } - - return ret; -} - -void wifi_printf(const char * format, ...) -{ - char * tmp = NULL; - va_list va; - va_start(va, format); - if((vasprintf(&tmp, format, va) >= 0) && tmp) - { - WifiGecko_Send(tmp, strlen(tmp)); - } - va_end(va); - - if(tmp) - free(tmp); -} diff --git a/source/utils/wifi_gecko.h b/source/utils/wifi_gecko.h deleted file mode 100644 index ef97e470..00000000 --- a/source/utils/wifi_gecko.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#ifndef WIFI_GECKO_H_ -#define WIFI_GECKO_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -int WifiGecko_Connect(); -void WifiGecko_Close(); -int WifiGecko_Send(const char * data, int datasize); -void wifi_printf(const char * format, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/video.cpp b/source/video.cpp deleted file mode 100644 index cac33301..00000000 --- a/source/video.cpp +++ /dev/null @@ -1,463 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * video.cpp - * Video routines - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "input.h" -#include "gecko.h" -#include "libwiigui/gui.h" - -#define DEFAULT_FIFO_SIZE 256 * 1024 -static unsigned int *xfb[2] = { NULL, NULL }; // Double buffered -static int whichfb = 0; // Switch -static GXRModeObj *vmode; // Menu video mode -static unsigned char gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN ( 32 ); -static Mtx GXmodelView2D; -int screenheight; -int screenwidth; -u32 frameCount = 0; - -u8 * gameScreenTex = NULL; // a GX texture screen capture of the game -u8 * gameScreenTex2 = NULL; // a GX texture screen capture of the game (copy) - -/**************************************************************************** - * StartGX - * - * Initialises GX and sets it up for use - ***************************************************************************/ -static void StartGX() -{ - GXColor background = { 0, 0, 0, 0xff }; - - /*** Clear out FIFO area ***/ - memset(&gp_fifo, 0, DEFAULT_FIFO_SIZE); - - /*** Initialise GX ***/ - GX_Init(&gp_fifo, DEFAULT_FIFO_SIZE); - GX_SetCopyClear(background, 0x00ffffff); - - GX_SetDispCopyGamma(GX_GM_1_0); - GX_SetCullMode(GX_CULL_NONE); -} - -/**************************************************************************** - * ResetVideo_Menu - * - * Reset the video/rendering mode for the menu - ****************************************************************************/ -void ResetVideo_Menu() -{ - Mtx44 p; - f32 yscale; - u32 xfbHeight; - - VIDEO_Configure(vmode); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if (vmode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); - else while (VIDEO_GetNextField()) - VIDEO_WaitVSync(); - - // clears the bg to color and clears the z buffer - GXColor background = { 0, 0, 0, 255 }; - GX_SetCopyClear(background, 0x00ffffff); - - yscale = GX_GetYScaleFactor(vmode->efbHeight, vmode->xfbHeight); - xfbHeight = GX_SetDispCopyYScale(yscale); - GX_SetScissor(0, 0, vmode->fbWidth, vmode->efbHeight); - GX_SetDispCopySrc(0, 0, vmode->fbWidth, vmode->efbHeight); - GX_SetDispCopyDst(vmode->fbWidth, xfbHeight); - GX_SetCopyFilter(vmode->aa, vmode->sample_pattern, GX_TRUE, vmode->vfilter); - GX_SetFieldMode(vmode->field_rendering, ((vmode->viHeight == 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); - - if (vmode->aa) - GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); - else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); - - // setup the vertex descriptor - // tells the flipper to expect direct data - GX_ClearVtxDesc(); - GX_InvVtxCache(); - GX_InvalidateTexAll(); - - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); - GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); - GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); - - GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); - GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); - GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); - GX_SetZMode(GX_FALSE, GX_LEQUAL, GX_TRUE); - - GX_SetNumChans(1); - GX_SetNumTexGens(1); - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); - GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); - - guMtxIdentity(GXmodelView2D); - guMtxTransApply(GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -200.0F); - GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0); - - guOrtho(p, 0, 479, 0, 639, 0, 300); - GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC); - - GX_SetViewport(0, 0, vmode->fbWidth, vmode->efbHeight, 0, 1); - GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); - GX_SetAlphaUpdate(GX_TRUE); -} - -/**************************************************************************** - * InitVideo - * - * This function MUST be called at startup. - * - also sets up menu video mode - ***************************************************************************/ - -void InitVideo() -{ - VIDEO_Init(); - vmode = VIDEO_GetPreferredMode(NULL); // get default video mode - - VIDEO_Configure(vmode); - - screenheight = 480; - screenwidth = vmode->fbWidth; - - // Allocate the video buffers - xfb[0] = (u32 *) MEM_K0_TO_K1 ( SYS_AllocateFramebuffer ( vmode ) ); - xfb[1] = (u32 *) MEM_K0_TO_K1 ( SYS_AllocateFramebuffer ( vmode ) ); - - // Clear framebuffers etc. - VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); - VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); - VIDEO_SetNextFramebuffer(xfb[0]); - - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); - - StartGX(); - ResetVideo_Menu(); - // Finally, the video is up and ready for use :) - - // A console is always useful while debugging - console_init(xfb[0], 80, 100, 500, 350, vmode->fbWidth * 2); -} - -void VIDEO_SetWidescreen(bool widescreen) -{ - if (widescreen) - { - // widescreen fix - vmode->viWidth = VI_MAX_WIDTH_PAL - 12; - vmode->viXOrigin = ((VI_MAX_WIDTH_PAL - vmode->viWidth) / 2) + 2; - } - else - { - VIDEO_GetPreferredMode(NULL); - } - - VIDEO_Configure(vmode); -} -/**************************************************************************** - * StopGX - * - * Stops GX (when exiting) - ***************************************************************************/ -void StopGX() -{ - GX_AbortFrame(); - GX_Flush(); - - VIDEO_SetBlack(TRUE); - VIDEO_Flush(); -} - -/**************************************************************************** - * Menu_Render - * - * Renders everything current sent to GX, and flushes video - ***************************************************************************/ -void Menu_Render() -{ - whichfb ^= 1; // flip framebuffer - GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); - GX_SetColorUpdate(GX_TRUE); - GX_CopyDisp(xfb[whichfb], GX_TRUE); - GX_DrawDone(); - VIDEO_SetNextFramebuffer(xfb[whichfb]); - VIDEO_Flush(); - VIDEO_WaitVSync(); - frameCount++; -} - -/**************************************************************************** - * Menu_DrawImg - * - * Draws the specified image on screen using GX - ***************************************************************************/ -void Menu_DrawImg(f32 xpos, f32 ypos, f32 zpos, f32 width, f32 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, - u8 alpha, int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4) -{ - if (data == NULL) return; - - GXTexObj texObj; - - GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GX_LoadTexObj(&texObj, GX_TEXMAP0); - GX_InvalidateTexAll(); - - GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); - GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); - - Mtx m, m1, m2, mv; - width *= .5; - height *= .5; - guMtxIdentity(m1); - guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0); - guVector axis = ( guVector ) - { - 0 , 0, 1 - }; - guMtxRotAxisDeg ( m2, &axis, degrees ); - // guMtxConcat(m2,m1,m); - guMtxConcat(m1, m2, m); - - guMtxTransApply(m, m, xpos + width + 0.5, ypos + height + 0.5, zpos); - guMtxConcat(GXmodelView2D, m, mv); - GX_LoadPosMtxImm(mv, GX_PNMTX0); - // - - GX_Begin(GX_QUADS, GX_VTXFMT0, 4); - GX_Position3f32(-width + XX1, -height + YY1, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(0, 0); - - GX_Position3f32(width + XX2, -height + YY2, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(1, 0); - - GX_Position3f32(width + XX3, height + YY3, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(1, 1); - - GX_Position3f32(-width + XX4, height + YY4, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(0, 1); - - // - - GX_End(); - GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0); - - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); -} - -/**************************************************************************** - * Menu_DrawRectangle - * - * Draws a rectangle at the specified coordinates using GX - ***************************************************************************/ -void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled) -{ - u8 fmt; - long n; - int i; - f32 x2 = x + width; - f32 y2 = y + height; - guVector v[] = { { x, y, 0.0f }, { x2, y, 0.0f }, { x2, y2, 0.0f }, { x, y2, 0.0f }, { x, y, 0.0f } }; - - if (!filled) - { - fmt = GX_LINESTRIP; - n = 5; - } - else - { - fmt = GX_TRIANGLEFAN; - n = 4; - } - - GX_Begin(fmt, GX_VTXFMT0, n); - for (i = 0; i < n; i++) - { - GX_Position3f32(v[i].x, v[i].y, v[i].z); - GX_Color4u8(color.r, color.g, color.b, color.a); - } - GX_End(); -} - -void Menu_DrawDiskCover(f32 xpos, f32 ypos, f32 zpos, u16 width, u16 height, u16 distance, u8 data[], f32 deg_alpha, - f32 deg_beta, f32 scaleX, f32 scaleY, u8 alpha, bool shadow) -{ - if (data == NULL) return; - - GXTexObj texObj; - - GX_InitTexObj(&texObj, data, width, height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GX_LoadTexObj(&texObj, GX_TEXMAP0); - GX_InvalidateTexAll(); - - GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); - GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); - - f32 cos_beta = cos(DegToRad( deg_beta )); - f32 s_offset_y = (zpos + (cos_beta * distance)) * tan(DegToRad( 5 )); - f32 s_offset_x = (cos_beta < 0 ? -cos_beta : cos_beta) * s_offset_y; - f32 s_offset_z = (s_offset_y < 0 ? 0 : s_offset_y) * 2; - - Mtx m, m1, m2, m3, m4, mv; - width *= .5; - height *= .5; - guMtxIdentity(m4); - guMtxTransApply(m4, m4, 0, 0, distance); - - guMtxIdentity(m1); - guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0); - guVector axis2 = ( guVector ) - { - 0 , 1, 0 - }; - guMtxRotAxisDeg ( m2, &axis2, deg_beta ); - guVector axis = ( guVector ) - { - 0 , 0, 1 - }; - guMtxRotAxisDeg ( m3, &axis, deg_alpha ); - // guMtxConcat(m2,m1,m); - guMtxConcat(m3, m4, m3); // move distance then rotate z-axis - guMtxConcat(m2, m3, m2); // rotate y-axis - guMtxConcat(m1, m2, m); // scale - - if (shadow) - guMtxTransApply(m, m, xpos + width + 0.5 + s_offset_x, ypos + height + 0.5 + s_offset_y, zpos - s_offset_z); - else - guMtxTransApply(m, m, xpos + width + 0.5, ypos + height + 0.5, zpos); - - guMtxConcat(GXmodelView2D, m, mv); - GX_LoadPosMtxImm(mv, GX_PNMTX0); - - if (shadow) - { - GX_Begin(GX_QUADS, GX_VTXFMT0, 4); - GX_Position3f32(-width, -height, 0); - GX_Color4u8(0, 0, 0, alpha); - GX_TexCoord2f32(0, 0); - - GX_Position3f32(width, -height, 0); - GX_Color4u8(0, 0, 0, alpha); - GX_TexCoord2f32(1, 0); - - GX_Position3f32(width, height, 0); - GX_Color4u8(0, 0, 0, alpha); - GX_TexCoord2f32(1, 1); - - GX_Position3f32(-width, height, 0); - GX_Color4u8(0, 0, 0, alpha); - GX_TexCoord2f32(0, 1); - } - else - { - GX_Begin(GX_QUADS, GX_VTXFMT0, 4); - GX_Position3f32(-width, -height, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(0, 0); - - GX_Position3f32(width, -height, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(1, 0); - - GX_Position3f32(width, height, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(1, 1); - - GX_Position3f32(-width, height, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(0, 1); - } - - GX_End(); - GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0); - - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); -} - -void Menu_DrawTPLImg(f32 xpos, f32 ypos, f32 zpos, f32 width, f32 height, GXTexObj *texObj, f32 degrees, f32 scaleX, - f32 scaleY, u8 alpha, int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4) -{ - GX_LoadTexObj(texObj, GX_TEXMAP0); - GX_InvalidateTexAll(); - - GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE); - GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); - - Mtx m, m1, m2, mv; - width *= .5; - height *= .5; - guMtxIdentity(m1); - guMtxScaleApply(m1, m1, scaleX, scaleY, 1.0); - guVector axis = ( guVector ) - { - 0 , 0, 1 - }; - guMtxRotAxisDeg ( m2, &axis, degrees ); - guMtxConcat(m1, m2, m); - - guMtxTransApply(m, m, xpos + width + 0.5, ypos + height + 0.5, zpos); - guMtxConcat(GXmodelView2D, m, mv); - GX_LoadPosMtxImm(mv, GX_PNMTX0); - - GX_Begin(GX_QUADS, GX_VTXFMT0, 4); - GX_Position3f32(-width + XX1, -height + YY1, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(0, 0); - - GX_Position3f32(width + XX2, -height + YY2, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(1, 0); - - GX_Position3f32(width + XX3, height + YY3, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(1, 1); - - GX_Position3f32(-width + XX4, height + YY4, 0); - GX_Color4u8(0xFF, 0xFF, 0xFF, alpha); - GX_TexCoord2f32(0, 1); - - GX_End(); - GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0); - - GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR); - GX_SetVtxDesc(GX_VA_TEX0, GX_NONE); -} -/**************************************************************************** - * TakeScreenshot - * - * Copies the current screen into a file "path" - ***************************************************************************/ -s32 TakeScreenshot(const char *path) -{ - gprintf("\nTakeScreenshot(%s)", path); - IMGCTX ctx = PNGU_SelectImageFromDevice(path); - s32 ret = PNGU_EncodeFromYCbYCr(ctx, vmode->fbWidth, vmode->efbHeight, xfb[whichfb], 0); - PNGU_ReleaseImageContext(ctx); - gprintf(":%d", ret); - return 1; -} diff --git a/source/video.h b/source/video.h deleted file mode 100644 index 902dd4fc..00000000 --- a/source/video.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * video.h - * Video routines - ***************************************************************************/ - -#ifndef _VIDEO_H_ -#define _VIDEO_H_ - -#include - -void InitVideo(); -void InitVideodebug(); -void StopGX(); -void ResetVideo_Menu(); -void Menu_Render(); -void Menu_DrawImg(f32 xpos, f32 ypos, f32 zpos, f32 width, f32 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, - u8 alphaF, int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4); -void Menu_DrawTPLImg(f32 xpos, f32 ypos, f32 zpos, f32 width, f32 height, GXTexObj *texObj, f32 degrees, f32 scaleX, - f32 scaleY, u8 alpha, int XX1, int YY1, int XX2, int YY2, int XX3, int YY3, int XX4, int YY4); -void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled); -s32 TakeScreenshot(const char *path); -void VIDEO_SetWidescreen(bool widescreen); - -extern int screenheight; -extern int screenwidth; -extern u32 frameCount; - -#endif diff --git a/source/wad/nandtitle.cpp b/source/wad/nandtitle.cpp deleted file mode 100644 index 9963fbfd..00000000 --- a/source/wad/nandtitle.cpp +++ /dev/null @@ -1,439 +0,0 @@ -#include "nandtitle.h" -#include "gecko.h" - -NandTitle NandTitles; - -extern "C" -{ - extern s32 MagicPatches(s32); -} - -static u8 tmd_buf[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN( 32 ); - -//based on one from comex's nand formatter -static u64 atoi_hex(const char *s) -{ - u64 ret = 0; - u32 n = strlen(s); - - for (u32 i = 0; i < n; i++) - { - if (s[i] > 0x39) - { - ret += (s[i] & ~0x20) - 0x37; - } - else - { - ret += (s[i] - 0x30); - } - if (i != (n - 1)) ret *= 16; - } - - return ret; -} - -NandTitle::NandTitle() -{ - currentIndex = 0; - currentType = 0; -} - -NandTitle::~NandTitle() -{ - titleIds.clear(); - NameList.clear(); -} - -s32 NandTitle::Get() -{ - s32 ret; - u64 *list = NULL; - u32 numTitles = 0; - - titleIds.clear(); - NameList.clear(); - - ret = ES_GetNumTitles(&numTitles); - if (ret < 0) return WII_EINTERNAL; - - list = (u64*) memalign(32, numTitles * sizeof(u64)); - if (!list) - { - return -1; - } - - ret = ES_GetTitles(list, numTitles); - if (ret < 0) - { - free(list); - return WII_EINTERNAL; - } - - for (u32 i = 0; i < numTitles; i++) - { - titleIds.push_back(list[i]); - } - - free(list); - - MagicPatches(1); - int language = CONF_GetLanguage(); - ISFS_Initialize(); - - wchar_t name[IMET_MAX_NAME_LEN]; - - for (u32 i = 0; i < titleIds.size(); i++) - { - bool r = GetName(titleIds.at(i), language, name); - if (r) - { - wString wsname(name); - NameList[titleIds.at(i)] = wsname.toUTF8(); - } - } - - ISFS_Deinitialize(); - MagicPatches(0); - return 1; -} - -tmd* NandTitle::GetTMD(u64 tid) -{ - //gprintf("GetTMD( %016llx ): ", tid ); - signed_blob *s_tmd = (signed_blob *) tmd_buf; - u32 tmd_size; - - if (ES_GetStoredTMDSize(tid, &tmd_size) < 0) - { - //gprintf("!size\n"); - return NULL; - } - - s32 ret = ES_GetStoredTMD(tid, s_tmd, tmd_size); - if (ret < 0) - { - //gprintf("!tmd - %04x\n", ret ); - return NULL; - } - - tmd *t = (tmd*) SIGNATURE_PAYLOAD(s_tmd); - //gprintf("ok\n"); - - return t; -} - -bool NandTitle::GetName(u64 tid, int language, wchar_t* name) -{ - if (TITLE_UPPER( tid ) != 0x10001 && TITLE_UPPER( tid ) != 0x10002 && TITLE_UPPER( tid ) != 0x10004) return false; - //gprintf("GetName( %016llx ): ", tid ); - char app[ISFS_MAXPATH]; - IMET *imet = (IMET*) memalign(32, sizeof(IMET)); - - tmd* titleTmd = GetTMD(tid); - if (!titleTmd) - { - //gprintf("no TMD\n"); - free(imet); - return false; - } - - u16 i; - bool ok = false; - for (i = 0; i < titleTmd->num_contents; i++) - { - if (!titleTmd->contents[i].index) - { - ok = true; - break; - } - } - if (!ok) - { - free(imet); - return false; - } - - snprintf(app, sizeof(app), "/title/%08x/%08x/content/%08x.app", TITLE_UPPER( tid ), TITLE_LOWER( tid ), - titleTmd->contents[i].cid); - //gprintf("%s\n", app ); - - if (language > CONF_LANG_KOREAN) language = CONF_LANG_ENGLISH; - - s32 fd = ISFS_Open(app, ISFS_OPEN_READ); - if (fd < 0) - { - //gprintf("fd: %d\n", fd ); - free(imet); - return false; - } - - if (ISFS_Seek(fd, IMET_OFFSET, SEEK_SET) != IMET_OFFSET) - { - ISFS_Close(fd); - free(imet); - return false; - } - - if (ISFS_Read(fd, imet, sizeof(IMET)) != sizeof(IMET)) - { - ISFS_Close(fd); - free(imet); - return false; - } - - ISFS_Close(fd); - - if (imet->sig != IMET_SIGNATURE) - { - free(imet); - return false; - } - - if (imet->name_japanese[language * IMET_MAX_NAME_LEN] == 0) - { - // channel name is not available in system language - if (imet->name_english[0] != 0) - { - language = CONF_LANG_ENGLISH; - } - else - { - // channel name is also not available on english, get ascii name - for (int i = 0; i < 4; i++) - { - name[i] = (TITLE_LOWER( tid ) >> (24 - i * 8)) & 0xFF; - } - name[4] = 0; - free(imet); - return true; - } - } - - // retrieve channel name in system language or on english - for (int i = 0; i < IMET_MAX_NAME_LEN; i++) - { - name[i] = imet->name_japanese[i + (language * IMET_MAX_NAME_LEN)]; - } - - free(imet); - - return true; -} - -bool NandTitle::Exists(u64 tid) -{ - char app[ISFS_MAXPATH]; - tmd* titleTmd = GetTMD(tid); - if (!titleTmd) return false; - - u16 i; - bool ok = false; - for (i = 0; i < titleTmd->num_contents; i++) - { - if (!titleTmd->contents[i].index) - { - ok = true; - break; - } - } - if (!ok) return false; - - snprintf(app, sizeof(app), "/title/%08x/%08x/content/%08x.app", TITLE_UPPER( tid ), TITLE_LOWER( tid ), - titleTmd->contents[i].cid); - s32 fd = ISFS_Open(app, ISFS_OPEN_READ); - if (fd >= 0) ISFS_Close(fd); - - //gprintf(" fd: %d\n", fd ); - return fd >= 0 || fd == -102; //102 means it exists, but we dont have permission to open it - -} - -bool NandTitle::ExistsFromIndex(u32 i) -{ - if (i > titleIds.size() || i < 0) return false; - - return Exists(titleIds.at(i)); -} - -u64 NandTitle::At(u32 i) -{ - if (i > titleIds.size() || i < 0) return 0; - - return titleIds.at(i); -} - -int NandTitle::IndexOf(u64 tid) -{ - for (u32 i = 0; i < titleIds.size(); i++) - { - if (titleIds.at(i) == tid) return i; - } - - return WII_EINSTALL; -} - -const char* NandTitle::NameOf(u64 tid) -{ - map::iterator itr = NameList.find(tid); - if (itr != NameList.end()) return itr->second.c_str(); - - return NULL; -} - -const char* NandTitle::NameFromIndex(u32 i) -{ - if (i > titleIds.size() || i < 0) return NULL; - - map::iterator itr = NameList.find(titleIds.at(i)); - if (itr != NameList.end()) return itr->second.c_str(); - - return NULL; -} - -u16 NandTitle::VersionOf(u64 tid) -{ - for (u32 i = 0; i < titleIds.size(); i++) - { - if (titleIds.at(i) == tid) - { - tmd* Tmd = GetTMD(tid); - if (!Tmd) break; - - return Tmd->title_version; - } - } - return 0; - -} - -u16 NandTitle::VersionFromIndex(u32 i) -{ - if (i > titleIds.size() || i < 0) return 0; - - tmd* Tmd = GetTMD(titleIds.at(i)); - if (!Tmd) return 0; - - return Tmd->title_version; -} - -u32 NandTitle::CountType(u32 type) -{ - u32 ret = 0; - for (u32 i = 0; i < titleIds.size(); i++) - { - if (TITLE_UPPER( titleIds.at( i ) ) == type) - { - ret++; - } - } - return ret; -} - -u32 NandTitle::SetType(u32 upper) -{ - currentType = upper; - currentIndex = 0; - - return CountType(upper); -} - -u64 NandTitle::Next() -{ - u64 ret = 0; - //gprintf("Next( %08x, %u )\n", currentType, currentIndex ); - u32 i; - for (i = currentIndex; i < titleIds.size(); i++) - { - if (currentType) - { - if (currentType == TITLE_UPPER( titleIds.at( i ) )) - { - ret = titleIds.at(i); - break; - } - } - else - { - ret = titleIds.at(i); - break; - } - } - currentIndex = i + 1; - - return ret; -} - -void NandTitle::ResetCounter() -{ - currentIndex = 0; -} - -void NandTitle::AsciiTID(u64 tid, char* out) -{ - //gprintf("AsciiTID( %016llx ): "); - out[0] = ascii(TITLE_3( tid )); - out[1] = ascii(TITLE_2( tid )); - out[2] = ascii(TITLE_1( tid )); - out[3] = ascii((u8) (tid)); - out[4] = 0; - //gprintf("%s\n", out ); -} - -void NandTitle::AsciiFromIndex(u32 i, char* out) -{ - if (i > titleIds.size() || i < 0) - { - out[0] = 0; - return; - } - - AsciiTID(titleIds.at(i), out); -} - -s32 NandTitle::GetTicketViews(u64 tid, tikview **outbuf, u32 *outlen) -{ - tikview *views = NULL; - - u32 nb_views; - s32 ret; - - /* Get number of ticket views */ - ret = ES_GetNumTicketViews(tid, &nb_views); - if (ret < 0) return ret; - - /* Allocate memory */ - views = (tikview *) memalign(32, sizeof(tikview) * nb_views); - if (!views) return -1; - - /* Get ticket views */ - ret = ES_GetTicketViews(tid, views, nb_views); - if (ret < 0) goto err; - - /* Set values */ - *outbuf = views; - *outlen = nb_views; - - return 0; - - err: - /* Free memory */ - if (views) free(views); - - return ret; -} - -int NandTitle::FindU64(const char *s) -{ - u64 tid = atoi_hex(s); - return IndexOf(tid); -} - -int NandTitle::FindU32(const char *s) -{ - u64 tid = atoi_hex(s); - for (u32 i = 0; i < titleIds.size(); i++) - { - if (TITLE_LOWER( titleIds.at( i ) ) == TITLE_LOWER( tid )) return i; - } - return WII_EINSTALL; -} diff --git a/source/wad/nandtitle.h b/source/wad/nandtitle.h deleted file mode 100644 index 27584314..00000000 --- a/source/wad/nandtitle.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef NANDTITLE_H -#define NANDTITLE_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wstring.hpp" -using namespace std; - -#define TITLE_ID(x,y) (((u64)(x) << 32) | (y)) -#define TITLE_UPPER(x) ((u32)((x) >> 32)) -#define TITLE_LOWER(x) ((u32)(x)) - -#define TITLE_1(x) ((u8)((x) >> 8)) -#define TITLE_2(x) ((u8)((x) >> 16)) -#define TITLE_3(x) ((u8)((x) >> 24)) -#define TITLE_4(x) ((u8)((x) >> 32)) -#define TITLE_5(x) ((u8)((x) >> 40)) -#define TITLE_6(x) ((u8)((x) >> 48)) -#define TITLE_7(x) ((u8)((x) >> 56)) - -#define IMET_MAX_NAME_LEN 0x2a - -#define IMET_OFFSET 0x40 -#define IMET_SIGNATURE 0x494d4554 -#define DOWNLOADED_CHANNELS 0x00010001 -#define SYSTEM_CHANNELS 0x00010002 -#define RF_NEWS_CHANNEL 0x48414741 -#define RF_FORECAST_CHANNEL 0x48414641 - -typedef struct -{ - u8 zeroes1[0x40]; - u32 sig; // "IMET" - u32 unk1; - u32 unk2; - u32 filesizes[3]; - u32 unk3; - u16 name_japanese[IMET_MAX_NAME_LEN]; - u16 name_english[IMET_MAX_NAME_LEN]; - u16 name_german[IMET_MAX_NAME_LEN]; - u16 name_french[IMET_MAX_NAME_LEN]; - u16 name_spanish[IMET_MAX_NAME_LEN]; - u16 name_italian[IMET_MAX_NAME_LEN]; - u16 name_dutch[IMET_MAX_NAME_LEN]; - u16 name_simp_chinese[IMET_MAX_NAME_LEN]; - u16 name_trad_chinese[IMET_MAX_NAME_LEN]; - u16 name_korean[IMET_MAX_NAME_LEN]; - u8 zeroes2[0x24c]; - u8 md5[0x10]; -} IMET; - -class NandTitle -{ - public: - NandTitle(); - ~NandTitle(); - - s32 Get(); - u64 At(u32 i); - int IndexOf(u64 tid); - u32 Count() - { - return titleIds.size(); - } - - const char* NameOf(u64 tid); - const char* NameFromIndex(u32 i); - - u16 VersionOf(u64 tid); - u16 VersionFromIndex(u32 i); - - u32 CountType(u32 type); - - u32 SetType(u32 upper); - u64 Next(); - void ResetCounter(); - - void AsciiTID(u64 tid, char* out); - void AsciiFromIndex(u32 i, char* out); - - bool Exists(u64 tid); - bool ExistsFromIndex(u32 i); - - int FindU64(const char *s); - int FindU32(const char *s); - - s32 GetTicketViews(u64 tid, tikview **outbuf, u32 *outlen); - - u64 operator[](u32 i) - { - return At(i); - } - - private: - std::vector titleIds; - std::map NameList; - bool GetName(u64 tid, int language, wchar_t* name); - tmd* GetTMD(u64 tid); - - u32 currentIndex; - u32 currentType; -}; - -extern NandTitle NandTitles; - -#endif // NANDTITLE_H diff --git a/source/wad/utils.h b/source/wad/utils.h deleted file mode 100644 index 29584b23..00000000 --- a/source/wad/utils.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _UTILS_H_ -#define _UTILS_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - /* Constants */ -#define KB_SIZE 1024.0 -#define MB_SIZE 1048576.0 -#define GB_SIZE 1073741824.0 - - /* Macros */ -#define round_up(x,n) (-(-(x) & -(n))) - - /* Prototypes */ - u32 swap32(u32); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/wad/wad.cpp b/source/wad/wad.cpp deleted file mode 100644 index c0389df1..00000000 --- a/source/wad/wad.cpp +++ /dev/null @@ -1,630 +0,0 @@ -#include -#include -#include -#include -#include - -#include "utils.h" -#include "video.h" -#include "wad.h" - -#include "nandtitle.h" - -#include "prompts/PromptWindows.h" -#include "libwiigui/gui.h" -#include "language/gettext.h" -#include "menu.h" -#include "filelist.h" -#include "themes/CTheme.h" - -/*** Extern functions ***/ -extern void ResumeGui(); -extern void HaltGui(); -/*** Extern variables ***/ -extern GuiWindow * mainWindow; - -/* 'WAD Header' structure */ -typedef struct -{ - /* Header length */ - u32 header_len; - - /* WAD type */ - u16 type; - - u16 padding; - - /* Data length */ - u32 certs_len; - u32 crl_len; - u32 tik_len; - u32 tmd_len; - u32 data_len; - u32 footer_len; -}ATTRIBUTE_PACKED wadHeader; - -/* Variables */ -static u8 wadBuffer[BLOCK_SIZE] ATTRIBUTE_ALIGN( 32 ); - -s32 __Wad_ReadFile(FILE *fp, void *outbuf, u32 offset, u32 len) -{ - s32 ret; - - /* Seek to offset */ - fseek(fp, offset, SEEK_SET); - - /* Read data */ - ret = fread(outbuf, len, 1, fp); - if (ret < 0) return ret; - - return 0; -} - -s32 __Wad_ReadAlloc(FILE *fp, void **outbuf, u32 offset, u32 len) -{ - void *buffer = NULL; - s32 ret; - - /* Allocate memory */ - buffer = memalign(32, len); - if (!buffer) return -1; - - /* Read file */ - ret = __Wad_ReadFile(fp, buffer, offset, len); - if (ret < 0) - { - free(buffer); - return ret; - } - - /* Set pointer */ - *outbuf = buffer; - return 0; -} - -s32 __Wad_GetTitleID(FILE *fp, wadHeader *header, u64 *tid) -{ - //signed_blob *p_tik = NULL; - void *p_tik = NULL; - tik *tik_data = NULL; - - u32 offset = 0; - s32 ret; - - /* Ticket offset */ - offset += round_up( header->header_len, 64 ); - offset += round_up( header->certs_len, 64 ); - offset += round_up( header->crl_len, 64 ); - - /* Read ticket */ - ret = __Wad_ReadAlloc(fp, &p_tik, offset, header->tik_len); - if (ret < 0) goto out; - - /* Ticket data */ - tik_data = (tik *) SIGNATURE_PAYLOAD((signed_blob *) p_tik); - - /* Copy title ID */ - *tid = tik_data->titleid; - - out: - /* Free memory */ - if (p_tik) free(p_tik); - - return ret; -} - -s32 Wad_Install(FILE *fp) -{ - //////start the gui shit - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiText btn1Txt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -35, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - GuiImageData progressbarOutline(Resources::GetFile("progressbar_outline.png"), Resources::GetFileSize("progressbar_outline.png")); - GuiImage progressbarOutlineImg(&progressbarOutline); - if (Settings.wsprompt) - { - progressbarOutlineImg.SetWidescreen(Settings.widescreen); - } - progressbarOutlineImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarOutlineImg.SetPosition(25, 50); - - GuiImageData progressbarEmpty(Resources::GetFile("progressbar_empty.png"), Resources::GetFileSize("progressbar_empty.png")); - GuiImage progressbarEmptyImg(&progressbarEmpty); - progressbarEmptyImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarEmptyImg.SetPosition(25, 50); - progressbarEmptyImg.SetTile(100); - - GuiImageData progressbar(Resources::GetFile("progressbar.png"), Resources::GetFileSize("progressbar.png")); - GuiImage progressbarImg(&progressbar); - progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); - progressbarImg.SetPosition(25, 50); - - char title[50]; - sprintf(title, "%s", tr( "Installing wad" )); - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 40); - char msg[50]; - sprintf(msg, " "); - // sprintf(msg, "%s", tr("Initializing Network")); - GuiText msg1Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg1Txt.SetPosition(50, 75); - // char msg2[50] = " "; - GuiText msg2Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg2Txt.SetPosition(50, 98); - - GuiText msg3Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg3Txt.SetPosition(50, 121); - - GuiText msg4Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg4Txt.SetPosition(50, 144); - - GuiText msg5Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg5Txt.SetPosition(50, 167); - - GuiText prTxt((char*) NULL, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - prTxt.SetPosition(0, 50); - - if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust for widescreen - { - progressbarOutlineImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - progressbarOutlineImg.SetPosition(0, 50); - progressbarEmptyImg.SetPosition(80, 50); - progressbarEmptyImg.SetTile(78); - progressbarImg.SetPosition(80, 50); - - msg1Txt.SetPosition(90, 75); - msg2Txt.SetPosition(90, 98); - msg3Txt.SetPosition(90, 121); - msg4Txt.SetPosition(90, 144); - msg5Txt.SetPosition(90, 167); - - } - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msg5Txt); - promptWindow.Append(&msg4Txt); - promptWindow.Append(&msg3Txt); - promptWindow.Append(&msg1Txt); - promptWindow.Append(&msg2Txt); - - //promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - //sleep(1); - - - ///start the wad shit - bool fail = false; - wadHeader *header = NULL; - void *pvoid; - signed_blob *p_certs = NULL, *p_crl = NULL, *p_tik = NULL, *p_tmd = NULL; - - tmd *tmd_data = NULL; - - u32 cnt, offset = 0; - s32 ret = 666; - - ResumeGui(); - msg1Txt.SetText(tr( ">> Reading WAD data..." )); - HaltGui(); -#define SetPointer(a, p) a=(typeof(a))p - // WAD header - //ret = __Wad_ReadAlloc(fp, (void *)header, offset, sizeof(wadHeader)); - ret = __Wad_ReadAlloc(fp, &pvoid, offset, sizeof(wadHeader)); - - if (ret < 0) goto err; - SetPointer( header, pvoid ); - offset += round_up( header->header_len, 64 ); - - // WAD certificates - //ret = __Wad_ReadAlloc(fp, (void *)&p_certs, offset, header->certs_len); - ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->certs_len); - if (ret < 0) goto err; - SetPointer( p_certs, pvoid ); - offset += round_up( header->certs_len, 64 ); - - // WAD crl - - if (header->crl_len) - { - //ret = __Wad_ReadAlloc(fp, (void *)&p_crl, offset, header->crl_len); - ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->crl_len); - if (ret < 0) goto err; - SetPointer( p_crl, pvoid ); - offset += round_up( header->crl_len, 64 ); - } - - // WAD ticket - //ret = __Wad_ReadAlloc(fp, (void *)&p_tik, offset, header->tik_len); - ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->tik_len); - if (ret < 0) goto err; - SetPointer( p_tik, pvoid ); - offset += round_up( header->tik_len, 64 ); - - // WAD TMD - //ret = __Wad_ReadAlloc(fp, (void *)&p_tmd, offset, header->tmd_len); - ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->tmd_len); - if (ret < 0) goto err; - SetPointer( p_tmd, pvoid ); - offset += round_up( header->tmd_len, 64 ); - - ResumeGui(); - msg1Txt.SetText(tr( "Reading WAD data... Ok!" )); - msg2Txt.SetText(tr( ">> Installing ticket..." )); - HaltGui(); - // Install ticket - ret = ES_AddTicket(p_tik, header->tik_len, p_certs, header->certs_len, p_crl, header->crl_len); - if (ret < 0) goto err; - - ResumeGui(); - msg2Txt.SetText(tr( "Installing ticket... Ok!" )); - msg3Txt.SetText(tr( ">> Installing title..." )); - //WindowPrompt(">> Installing title...",0,0,0,0,0,200); - HaltGui(); - // Install title - ret = ES_AddTitleStart(p_tmd, header->tmd_len, p_certs, header->certs_len, p_crl, header->crl_len); - if (ret < 0) goto err; - - // Get TMD info - tmd_data = (tmd *) SIGNATURE_PAYLOAD(p_tmd); - - char imgPath[150]; - - // Install contents - //ResumeGui(); - //HaltGui(); - promptWindow.Append(&progressbarEmptyImg); - promptWindow.Append(&progressbarImg); - promptWindow.Append(&progressbarOutlineImg); - promptWindow.Append(&prTxt); - ResumeGui(); - msg3Txt.SetText(tr( "Installing title... Ok!" )); - for (cnt = 0; cnt < tmd_data->num_contents; cnt++) - { - - tmd_content *content = &tmd_data->contents[cnt]; - - u32 idx = 0, len; - s32 cfd; - ResumeGui(); - - //printf("\r\t\t>> Installing content #%02d...", content->cid); - // Encrypted content size - len = round_up( content->size, 64 ); - - // Install content - cfd = ES_AddContentStart(tmd_data->title_id, content->cid); - if (cfd < 0) - { - ret = cfd; - goto err; - } - snprintf(imgPath, sizeof(imgPath), "%s%d...", tr( ">> Installing content #" ), content->cid); - msg4Txt.SetText(imgPath); - // Install content data - while (idx < len) - { - - //VIDEO_WaitVSync (); - - u32 size; - - // Data length - size = (len - idx); - if (size > BLOCK_SIZE) size = BLOCK_SIZE; - - // Read data - ret = __Wad_ReadFile(fp, &wadBuffer, offset, size); - if (ret < 0) goto err; - - // Install data - ret = ES_AddContentData(cfd, wadBuffer, size); - if (ret < 0) goto err; - - // Increase variables - idx += size; - offset += size; - - //snprintf(imgPath, sizeof(imgPath), "%s%d (%d)...",tr(">> Installing content #"),content->cid,idx); - - //msg4Txt.SetText(imgPath); - - prTxt.SetTextf("%i%%", 100 * (cnt * len + idx) / (tmd_data->num_contents * len)); - if ((Settings.wsprompt) && (Settings.widescreen)) - { - progressbarImg.SetTile(78 * (cnt * len + idx) / (tmd_data->num_contents * len)); - } - else - { - progressbarImg.SetTile(100 * (cnt * len + idx) / (tmd_data->num_contents * len)); - } - - } - - // Finish content installation - ret = ES_AddContentFinish(cfd); - if (ret < 0) goto err; - } - - msg4Txt.SetText(tr( "Installing content... Ok!" )); - msg5Txt.SetText(tr( ">> Finishing installation..." )); - - // Finish title install - ret = ES_AddTitleFinish(); - if (ret >= 0) - { - // printf(" OK!\n"); - goto out; - } - - err: - //char titties[100]; - ResumeGui(); - prTxt.SetTextf("%s%d", tr( "Error..." ), ret); - promptWindow.Append(&prTxt); - fail = true; - //snprintf(titties, sizeof(titties), "%d", ret); - //printf(" ERROR! (ret = %d)\n", ret); - //WindowPrompt("ERROR!",titties,"Back",0,0); - // Cancel install - ES_AddTitleCancel(); - goto exit; - //return ret; - - out: - // Free memory - if (header) free(header); - if (p_certs) free(p_certs); - if (p_crl) free(p_crl); - if (p_tik) free(p_tik); - if (p_tmd) free(p_tmd); - goto exit; - - exit: if (!fail) msg5Txt.SetText(tr( "Finishing installation... Ok!" )); - promptWindow.Append(&btn1); - while (btn1.GetState() != STATE_CLICKED) - { - } - - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - return ret; -} - -s32 Wad_Uninstall(FILE *fp) -{ - //////start the gui shit - GuiWindow promptWindow(472, 320); - promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); - promptWindow.SetPosition(0, -10); - - GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png")); - GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png")); - GuiTrigger trigA; - trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); - - GuiImage dialogBoxImg(&dialogBox); - if (Settings.wsprompt) - { - dialogBoxImg.SetWidescreen(Settings.widescreen); - } - - GuiText btn1Txt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - GuiImage btn1Img(&btnOutline); - if (Settings.wsprompt) - { - btn1Txt.SetWidescreen(Settings.widescreen); - btn1Img.SetWidescreen(Settings.widescreen); - } - GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -55, &trigA, btnSoundOver, btnSoundClick2, 1); - btn1.SetLabel(&btn1Txt); - btn1.SetState(STATE_SELECTED); - - char title[50]; - sprintf(title, "%s", tr( "Uninstalling wad" )); - GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(0, 40); - - GuiText msg1Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg1Txt.SetPosition(50, 75); - - GuiText msg2Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg2Txt.SetPosition(50, 98); - - GuiText msg3Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg3Txt.SetPosition(50, 121); - - GuiText msg4Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg4Txt.SetPosition(50, 144); - - GuiText msg5Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color")); - msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - msg5Txt.SetPosition(50, 167); - - if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust for widescreen - { - - msg1Txt.SetPosition(70, 95); - msg2Txt.SetPosition(70, 118); - msg3Txt.SetPosition(70, 141); - msg4Txt.SetPosition(70, 164); - msg5Txt.SetPosition(70, 187); - - } - promptWindow.Append(&dialogBoxImg); - promptWindow.Append(&titleTxt); - promptWindow.Append(&msg5Txt); - promptWindow.Append(&msg4Txt); - promptWindow.Append(&msg3Txt); - promptWindow.Append(&msg1Txt); - promptWindow.Append(&msg2Txt); - - HaltGui(); - mainWindow->SetState(STATE_DISABLED); - mainWindow->Append(&promptWindow); - mainWindow->ChangeFocus(&promptWindow); - ResumeGui(); - //sleep(3); - - ///start the wad shit - wadHeader *header = NULL; - void *pvoid = NULL; - tikview *viewData = NULL; - - u64 tid; - u32 viewCnt; - s32 ret; - - msg1Txt.SetText(tr( ">> Reading WAD data..." )); - - // WAD header - ret = __Wad_ReadAlloc(fp, &pvoid, 0, sizeof(wadHeader)); - if (ret < 0) - { - char errTxt[50]; - sprintf(errTxt, "%sret = %d", tr( ">> Reading WAD data...ERROR! " ), ret); - msg1Txt.SetText(errTxt); - //printf(" ERROR! (ret = %d)\n", ret); - goto out; - } - SetPointer( header, pvoid ); - - // Get title ID - ret = __Wad_GetTitleID(fp, header, &tid); - if (ret < 0) - { - //printf(" ERROR! (ret = %d)\n", ret); - char errTxt[50]; - sprintf(errTxt, "%sret = %d", tr( ">> Reading WAD data...ERROR! " ), ret); - msg1Txt.SetText(errTxt); - goto out; - } - - msg1Txt.SetText(tr( ">> Reading WAD data...Ok!" )); - msg2Txt.SetText(tr( ">> Deleting tickets..." )); - - // Get ticket views - ret = NandTitles.GetTicketViews(tid, &viewData, &viewCnt); - if (ret < 0) - { - char errTxt[50]; - sprintf(errTxt, "%sret = %d", tr( ">> Deleting tickets...ERROR! " ), ret); - msg2Txt.SetText(errTxt); - //printf(" ERROR! (ret = %d)\n", ret); - } - // Delete tickets - if (ret >= 0) - { - u32 cnt; - - // Delete all tickets - for (cnt = 0; cnt < viewCnt; cnt++) - { - ret = ES_DeleteTicket(&viewData[cnt]); - if (ret < 0) break; - } - - if (ret < 0) - { - char errTxt[50]; - sprintf(errTxt, "%sret = %d", tr( ">> Deleting tickets...ERROR! " ), ret); - msg2Txt.SetText(errTxt); - } - //printf(" ERROR! (ret = %d\n", ret); - else - //printf(" OK!\n"); - msg2Txt.SetText(tr( ">> Deleting tickets...Ok! " )); - - } - - msg3Txt.SetText(tr( ">> Deleting title contents..." )); - //WindowPrompt(">> Deleting title contents...",0,"Back",0,0); - - // Delete title contents - ret = ES_DeleteTitleContent(tid); - if (ret < 0) - { - char errTxt[50]; - sprintf(errTxt, "%sret = %d", tr( ">> Deleting title contents...ERROR! " ), ret); - msg3Txt.SetText(errTxt); - } - //printf(" ERROR! (ret = %d)\n", ret); - else - //printf(" OK!\n"); - msg3Txt.SetText(tr( ">> Deleting title contents...Ok!" )); - - msg4Txt.SetText(tr( ">> Deleting title..." )); - // Delete title - ret = ES_DeleteTitle(tid); - if (ret < 0) - { - char errTxt[50]; - sprintf(errTxt, "%sret = %d", tr( ">> Deleting title ...ERROR! " ), ret); - msg4Txt.SetText(errTxt); - } - //printf(" ERROR! (ret = %d)\n", ret); - else - //printf(" OK!\n"); - msg4Txt.SetText(tr( ">> Deleting title ...Ok!" )); - - out: - // Free memory - if (header) free(header); - - goto exit; - - exit: msg5Txt.SetText(tr( "Done!" )); - promptWindow.Append(&btn1); - while (btn1.GetState() != STATE_CLICKED) - { - } - - HaltGui(); - mainWindow->Remove(&promptWindow); - mainWindow->SetState(STATE_DEFAULT); - ResumeGui(); - - return ret; -} - diff --git a/source/wad/wad.h b/source/wad/wad.h deleted file mode 100644 index 89dd7358..00000000 --- a/source/wad/wad.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _WAD_H_ -#define _WAD_H_ - -/* Prototypes */ - -#define BLOCK_SIZE 1024 - -s32 Wad_Install(FILE *); -s32 Wad_Uninstall(FILE *); - -#endif diff --git a/source/wpad.c b/source/wpad.c deleted file mode 100644 index f4a0a4a3..00000000 --- a/source/wpad.c +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include -#include - -#include "sys.h" -#include "wpad.h" - -/* Constants */ -#define MAX_WIIMOTES 4 - -extern u8 shutdown; - -void __Wpad_PowerCallback(s32 chan) -{ - /* Poweroff console */ - shutdown = 1; -} - -void WPad_SetIdleTime(u32 seconds) -{ - /*Set idle time for wiimote*/ - WPAD_SetIdleTimeout(seconds); -} - -s32 Wpad_Init(void) -{ - s32 ret; - - /* Initialize Wiimote subsystem */ - ret = WPAD_Init(); - if (ret < 0) return ret; - - /* Set POWER button callback */ - WPAD_SetPowerButtonCallback(__Wpad_PowerCallback); - - return ret; -} - -void Wpad_Disconnect(void) -{ - u32 cnt; - - /* Disconnect Wiimotes */ - for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) - WPAD_Disconnect(cnt); - - /* Shutdown Wiimote subsystem */ - WPAD_Shutdown(); -} - -bool IsWpadConnected() -{ - int i = 0; - u32 test = 0; - int notconnected = 0; - for (i = 0; i < 4; i++) - { - if (WPAD_Probe(i, &test) == WPAD_ERR_NO_CONTROLLER) - { - notconnected++; - } - } - if (notconnected < 4) - return true; - else return false; -} - -u32 ButtonsHold(void) -{ - - int i; - u32 buttons = 0; - - WPAD_ScanPads(); - PAD_ScanPads(); - - for (i = 3; i >= 0; i--) - { - buttons |= PAD_ButtonsHeld(i); - buttons |= WPAD_ButtonsHeld(i); - } - return buttons; -} - -u32 ButtonsPressed(void) -{ - - int i; - u32 buttons = 0; - - WPAD_ScanPads(); - PAD_ScanPads(); - - for (i = 3; i >= 0; i--) - { - buttons |= PAD_ButtonsDown(i); - buttons |= WPAD_ButtonsDown(i); - } - return buttons; - - /* Don't remove this commented out code it might be useful for checking which buttons were pressed/hold - - if(buttons & (PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_DOWN | PAD_BUTTON_UP - | PAD_BUTTON_A | PAD_BUTTON_B | PAD_BUTTON_X | PAD_BUTTON_Y | PAD_BUTTON_MENU - | PAD_BUTTON_START | WPAD_BUTTON_2 | WPAD_BUTTON_1 - | WPAD_BUTTON_B | WPAD_BUTTON_A | WPAD_BUTTON_MINUS - | WPAD_BUTTON_HOME | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT - | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_PLUS - | WPAD_NUNCHUK_BUTTON_Z | WPAD_NUNCHUK_BUTTON_C - | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_LEFT - | WPAD_CLASSIC_BUTTON_ZR | WPAD_CLASSIC_BUTTON_X - | WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_Y - | WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_ZL - | WPAD_CLASSIC_BUTTON_FULL_R | WPAD_CLASSIC_BUTTON_PLUS - | WPAD_CLASSIC_BUTTON_HOME | WPAD_CLASSIC_BUTTON_MINUS - | WPAD_CLASSIC_BUTTON_FULL_L | WPAD_CLASSIC_BUTTON_DOWN - | WPAD_CLASSIC_BUTTON_RIGHT | WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP - | WPAD_GUITAR_HERO_3_BUTTON_YELLOW | WPAD_GUITAR_HERO_3_BUTTON_GREEN - | WPAD_GUITAR_HERO_3_BUTTON_BLUE | WPAD_GUITAR_HERO_3_BUTTON_RED - | WPAD_GUITAR_HERO_3_BUTTON_ORANGE | WPAD_GUITAR_HERO_3_BUTTON_PLUS - | WPAD_GUITAR_HERO_3_BUTTON_MINUS | WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN) - ) - */ - -} diff --git a/source/wpad.h b/source/wpad.h deleted file mode 100644 index 85fc2acd..00000000 --- a/source/wpad.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _WPAD_H_ -#define _WPAD_H_ - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Prototypes */ - s32 Wpad_Init(void); - void Wpad_Disconnect(void); - u32 ButtonsPressed(void); - u32 ButtonsHold(void); - bool IsWpadConnected(); - void WPad_SetIdleTime(u32 seconds); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/wstring.cpp b/source/wstring.cpp deleted file mode 100644 index 06fc8082..00000000 --- a/source/wstring.cpp +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include "wstring.hpp" - -using namespace std; - -wString::wString(const wchar_t *s) : - std::basic_string, std::allocator >(s) -{ -} - -wString::wString(const basic_string , allocator > &ws) : - basic_string , allocator > (ws) -{ -} - -wString::wString(const string &s) -{ - std::string::size_type size; - - size = s.size(); - resize(size); - for (std::string::size_type i = 0; i < size; ++i) - (*this)[i] = (unsigned char) s[i]; -} - -wString &wString::operator=(const string & s) -{ - std::string::size_type size; - - size = s.size(); - this->resize(size); - for (std::string::size_type i = 0; i < size; ++i) - (*this)[i] = (unsigned char) s[i]; - return *this; -} - -void wString::fromUTF8(const char *s) -{ - size_t len = utf8Len(s); - - clear(); - if (len == 0) return; - reserve(len); - for (int i = 0; s[i] != 0;) - { - if ((s[i] & 0xF8) == 0xF0) - { - push_back(((wchar_t) (s[i] & 0x07) << 18) | ((wchar_t) (s[i + 1] & 0x3F) << 12) | ((wchar_t) (s[i + 2] - & 0x3F) << 6) | (wchar_t) (s[i + 3] & 0x3F)); - i += 4; - } - else if ((s[i] & 0xF0) == 0xE0) - { - push_back(((wchar_t) (s[i] & 0x0F) << 12) | ((wchar_t) (s[i + 1] & 0x3F) << 6) - | (wchar_t) (s[i + 2] & 0x3F)); - i += 3; - } - else if ((s[i] & 0xE0) == 0xC0) - { - push_back(((wchar_t) (s[i] & 0x1F) << 6) | (wchar_t) (s[i + 1] & 0x3F)); - i += 2; - } - else - { - push_back((wchar_t) s[i]); - ++i; - } - } -} - -string wString::toUTF8(void) const -{ - string s; - size_t len = 0; - wchar_t wc; - - for (size_t i = 0; i < size(); ++i) - { - wc = operator[](i); - if (wc < 0x80) - ++len; - else if (wc < 0x800) - len += 2; - else if (wc < 0x10000) - len += 3; - else len += 4; - } - s.reserve(len); - for (size_t i = 0; i < size(); ++i) - { - wc = operator[](i); - if (wc < 0x80) - s.push_back((char) wc); - else if (wc < 0x800) - { - s.push_back((char) ((wc >> 6) | 0xC0)); - s.push_back((char) ((wc & 0x3F) | 0x80)); - } - else if (wc < 0x10000) - { - s.push_back((char) ((wc >> 12) | 0xE0)); - s.push_back((char) (((wc >> 6) & 0x3F) | 0x80)); - s.push_back((char) ((wc & 0x3F) | 0x80)); - } - else - { - s.push_back((char) (((wc >> 18) & 0x07) | 0xF0)); - s.push_back((char) (((wc >> 12) & 0x3F) | 0x80)); - s.push_back((char) (((wc >> 6) & 0x3F) | 0x80)); - s.push_back((char) ((wc & 0x3F) | 0x80)); - } - } - return s; -} - -size_t utf8Len(const char *s) -{ - size_t len = 0; - - for (int i = 0; s[i] != 0;) - { - if ((s[i] & 0xF8) == 0xF0) - { - if (((s[i + 1] & 0xC0) != 0x80) || ((s[i + 2] & 0xC0) != 0x80) || ((s[i + 3] & 0xC0) != 0x80)) return 0; - ++len; - i += 4; - } - else if ((s[i] & 0xF0) == 0xE0) - { - if (((s[i + 1] & 0xC0) != 0x80) || ((s[i + 2] & 0xC0) != 0x80)) return 0; - ++len; - i += 3; - } - else if ((s[i] & 0xE0) == 0xC0) - { - if (((s[i + 1] & 0xC0) != 0x80)) return 0; - ++len; - i += 2; - } - else if ((s[i] & 0x80) == 0x00) - { - ++len; - ++i; - } - else return 0; - } - return len; -} - -int wcsnicmp(const wchar_t *s1, const wchar_t *s2, int len) -{ - if (len <= 0) return (0); - - do - { - int r = towupper(*s1) - towupper(*s2++); - if (r) return r; - if (*s1++ == 0) break; - } while (--len != 0); - - return (0); -} diff --git a/source/wstring.hpp b/source/wstring.hpp deleted file mode 100644 index e2d79b86..00000000 --- a/source/wstring.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/**************************************************************************** - * wstring Class - * by Hibernatus - ***************************************************************************/ -#ifndef __WSTRING_HPP -#define __WSTRING_HPP - -#include - -class wString: public std::basic_string, std::allocator > -{ - public: - wString(void) - { - } - wString(const wchar_t *s); - wString(const std::basic_string, std::allocator > &ws); - wString(const std::string &s); - wString &operator=(const std::string &s); - void fromUTF8(const char *s); - std::string toUTF8(void) const; -}; - -size_t utf8Len(const char *s); -int wcsnicmp(const wchar_t *s1, const wchar_t *s2, int len); - -#endif // !defined(__WSTRING_HPP) diff --git a/source/xml/WiiTDB.cpp b/source/xml/WiiTDB.cpp deleted file mode 100644 index aa806835..00000000 --- a/source/xml/WiiTDB.cpp +++ /dev/null @@ -1,998 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#include -#include -#include -#include -#include "WiiTDB.hpp" - -#define NAME_OFFSET_DB "wiitdb_offsets.bin" -#define MAXREADSIZE 1024*1024 // Cache size only for parsing the offsets: 1MB - -typedef struct _ReplaceStruct -{ - const char * orig; - char replace; - short size; -} ReplaceStruct; - -//! More replacements can be added if needed -static const ReplaceStruct Replacements[] = -{ - { ">", '>', 4 }, - { "<", '<', 4 }, - { """, '\"', 6 }, - { "'", '\'', 6 }, - { "&", '&', 5 }, - { NULL, '\0', 0 } -}; - -WiiTDB::WiiTDB() - : file(0), LangCode("EN"), GameNodeCache(0) -{ -} - -WiiTDB::WiiTDB(const char * filepath) - : file(0), LangCode("EN"), GameNodeCache(0) -{ - OpenFile(filepath); -} - -WiiTDB::~WiiTDB() -{ - CloseFile(); -} - -bool WiiTDB::OpenFile(const char * filepath) -{ - if(!filepath) - return false; - - file = fopen(filepath, "rb"); - if(file) - { - int pos; - string OffsetsPath = filepath; - if((pos = OffsetsPath.find_last_of('/')) != (int) string::npos) - OffsetsPath[pos] = '\0'; - else - OffsetsPath.clear(); //! Relative path - - LoadGameOffsets(OffsetsPath.c_str()); - } - - return (file != NULL); -} - -void WiiTDB::CloseFile() -{ - OffsetMap.clear(); - vector().swap(OffsetMap); - - if(GameNodeCache) - delete [] GameNodeCache; - GameNodeCache = NULL; - - if(file) - fclose(file); - file = NULL; -} - -bool WiiTDB::LoadGameOffsets(const char * path) -{ - if(!path) - return false; - - string OffsetDBPath = path; - if(strlen(path) > 0 && path[strlen(path)-1] != '/') - OffsetDBPath += '/'; - OffsetDBPath += NAME_OFFSET_DB; - - FILE * fp = fopen(OffsetDBPath.c_str(), "rb"); - if(!fp) - { - bool result = ParseFile(); - if(result) - SaveGameOffsets(OffsetDBPath.c_str()); - - return result; - } - - unsigned long long ExistingVersion = GetWiiTDBVersion(); - unsigned long long Version = 0; - unsigned int NodeCount = 0; - - fread(&Version, 1, sizeof(Version), fp); - - if(ExistingVersion != Version) - { - fclose(fp); - bool result = ParseFile(); - if(result) - SaveGameOffsets(OffsetDBPath.c_str()); - - return result; - } - - fread(&NodeCount, 1, sizeof(NodeCount), fp); - - if(NodeCount == 0) - { - fclose(fp); - bool result = ParseFile(); - if(result) - SaveGameOffsets(OffsetDBPath.c_str()); - - return result; - } - - OffsetMap.resize(NodeCount); - - if(fread(&OffsetMap[0], 1, NodeCount*sizeof(GameOffsets), fp) != NodeCount*sizeof(GameOffsets)) - { - fclose(fp); - bool result = ParseFile(); - if(result) - SaveGameOffsets(OffsetDBPath.c_str()); - - return result; - } - - fclose(fp); - - return true; -} - -bool WiiTDB::SaveGameOffsets(const char * path) -{ - if(OffsetMap.size() == 0 || !path) - return false; - - FILE * fp = fopen(path, "wb"); - if(!fp) - return false; - - unsigned long long ExistingVersion = GetWiiTDBVersion(); - unsigned int NodeCount = OffsetMap.size(); - - if(fwrite(&ExistingVersion, 1, sizeof(ExistingVersion), fp) < 0) - { - fclose(fp); - return false; - } - - if(fwrite(&NodeCount, 1, sizeof(NodeCount), fp) < 0) - { - fclose(fp); - return false; - } - - if(fwrite(&OffsetMap[0], 1, NodeCount*sizeof(GameOffsets), fp) < 0) - { - fclose(fp); - return false; - } - - fclose(fp); - - return true; -} - -unsigned long long WiiTDB::GetWiiTDBVersion() -{ - if(!file) - return 0; - - char TmpText[1024]; - - if(GetData(TmpText, 0, sizeof(TmpText)) < 0) - return 0; - - char * VersionText = GetNodeText(TmpText, ""); - if(!VersionText) - return 0; - - return strtoull(VersionText, NULL, 10); -} - -size_t WiiTDB::GetData(char * data, int offset, int size) -{ - if(!file || !data) - return -1; - - fseek(file, offset, SEEK_SET); - - return fread(data, 1, size, file); -} - -char * WiiTDB::LoadGameNode(const char * id) -{ - unsigned int read = 0; - - GameOffsets * offset = this->GetGameOffset(id); - if(!offset) - return NULL; - - char * data = new (std::nothrow) char[offset->nodesize+1]; - if(!data) - return NULL; - - if((read = GetData(data, offset->gamenode, offset->nodesize)) != offset->nodesize) - { - delete [] data; - return NULL; - } - - data[read] = '\0'; - - return data; -} - -char * WiiTDB::GetGameNode(const char * id) -{ - char * data = NULL; - - if(GameNodeCache != 0 && strncmp(id, GameIDCache, strlen(GameIDCache)) == 0) - { - data = new (std::nothrow) char[strlen(GameNodeCache)+1]; - if(data) - strcpy(data, GameNodeCache); - } - else - { - if(GameNodeCache) - delete [] GameNodeCache; - - GameNodeCache = LoadGameNode(id); - - if(GameNodeCache) - { - snprintf(GameIDCache, sizeof(GameIDCache), id); - data = new (std::nothrow) char[strlen(GameNodeCache)+1]; - if(data) - strcpy(data, GameNodeCache); - } - } - - return data; -} - -GameOffsets * WiiTDB::GetGameOffset(const char * gameID) -{ - for(unsigned int i = 0; i < OffsetMap.size(); ++i) - { - if(strncmp(gameID, OffsetMap[i].gameID, strlen(OffsetMap[i].gameID)) == 0) - return &OffsetMap[i]; - } - - return 0; -} - -static inline char * CleanText(char * in_text) -{ - if(!in_text) - return NULL; - - const char * ptr = in_text; - char * text = in_text; - - while(*ptr != '\0') - { - for(int i = 0; Replacements[i].orig != 0; ++i) - { - if(strncmp(ptr, Replacements[i].orig, Replacements[i].size) == 0) - { - ptr += Replacements[i].size; - *text = Replacements[i].replace; - ++text; - i = 0; - continue; - } - } - - if(*ptr == '\r') - { - ++ptr; - continue; - } - - *text = *ptr; - ++ptr; - ++text; - } - - *text = '\0'; - - return in_text; -} - -char * WiiTDB::GetNodeText(char * data, const char * nodestart, const char * nodeend) -{ - if(!data || !nodestart || !nodeend) - return NULL; - - char * position = strstr(data, nodestart); - if(!position) - return NULL; - - position += strlen(nodestart); - - char * end = strstr(position, nodeend); - if(!end) - return NULL; - - *end = '\0'; - - return CleanText(position); -} - -char * WiiTDB::SeekLang(char * text, const char * langcode) -{ - if(!text || !langcode) return NULL; - - char * ptr = text; - while((ptr = strstr(ptr, ""); - if(!end) - return NULL; - - end += strlen(""); - *end = '\0'; - - return ptr; - } - } - - return NULL; -} - -bool WiiTDB::ParseFile() -{ - OffsetMap.clear(); - - if(!file) - return false; - - char * Line = new (std::nothrow) char[MAXREADSIZE+1]; - if(!Line) - return false; - - bool readnew = false; - int i, currentPos = 0; - int read = 0; - const char * gameNode = NULL; - const char * idNode = NULL; - const char * gameEndNode = NULL; - - while((read = GetData(Line, currentPos, MAXREADSIZE)) > 0) - { - gameNode = Line; - readnew = false; - - //! Ensure the null termination at the end - Line[read] = '\0'; - - while((gameNode = strstr(gameNode, ""); - gameEndNode = strstr(gameNode, ""); - if(!idNode || !gameEndNode) - { - //! We are in the middle of the game node, reread complete node and more - currentPos += (gameNode-Line); - fseek(file, currentPos, SEEK_SET); - readnew = true; - break; - } - - idNode += strlen(""); - gameEndNode += strlen(""); - - int size = OffsetMap.size(); - OffsetMap.resize(size+1); - - for(i = 0; i < 7 && *idNode != '<'; ++i, ++idNode) - OffsetMap[size].gameID[i] = *idNode; - OffsetMap[size].gameID[i] = '\0'; - OffsetMap[size].gamenode = currentPos+(gameNode-Line); - OffsetMap[size].nodesize = (gameEndNode-gameNode); - gameNode = gameEndNode; - } - - if(readnew) - continue; - - currentPos += read; - } - - delete [] Line; - - return true; -} - -bool WiiTDB::GetTitle(const char * id, string & title) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * language = SeekLang(data, LangCode.c_str()); - if(!language) - { - language = SeekLang(data, "EN"); - if(!language) - { - delete [] data; - return false; - } - } - - char * the_title = GetNodeText(language, "", ""); - if(!the_title) - { - delete [] data; - return false; - } - - title = the_title; - - delete [] data; - - return true; -} - -bool WiiTDB::GetSynopsis(const char * id, string & synopsis) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * language = SeekLang(data, LangCode.c_str()); - if(!language) - { - language = SeekLang(data, "EN"); - if(!language) - { - delete [] data; - return false; - } - } - - char * the_synopsis = GetNodeText(language, "", ""); - if(!the_synopsis) - { - delete [] data; - return false; - } - - synopsis = the_synopsis; - - delete [] data; - - return true; -} - -bool WiiTDB::GetRegion(const char * id, string & region) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * the_region = GetNodeText(data, "", ""); - if(!the_region) - { - delete [] data; - return false; - } - - region = the_region; - - delete [] data; - - return true; -} - -bool WiiTDB::GetDeveloper(const char * id, string & dev) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * the_dev = GetNodeText(data, "", ""); - if(!the_dev) - { - delete [] data; - return false; - } - - dev = the_dev; - - delete [] data; - - return true; -} - -bool WiiTDB::GetPublisher(const char * id, string & pub) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * the_pub = GetNodeText(data, "", ""); - if(!the_pub) - { - delete [] data; - return false; - } - - pub = the_pub; - - delete [] data; - - return true; -} - -unsigned int WiiTDB::GetPublishDate(const char * id) -{ - if(!id) - return 0; - - char * data = GetGameNode(id); - if(!data) - return 0; - - char * year_string = GetNodeText(data, ""); - if(!year_string) - { - delete [] data; - return 0; - } - - unsigned int year, day, month; - - year = atoi(year_string); - - char * month_string = strstr(year_string, "month=\""); - if(!month_string) - { - delete [] data; - return 0; - } - - month_string += strlen("month=\""); - - month = atoi(month_string); - - char * day_string = strstr(month_string, "day=\""); - if(!day_string) - { - delete [] data; - return 0; - } - - day_string += strlen("day=\""); - - day = atoi(day_string); - - delete [] data; - - return ((year & 0xFFFF) << 16 | (month & 0xFF) << 8 | (day & 0xFF)); -} - -bool WiiTDB::GetGenreList(const char * id, vector & genre) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * the_genre = GetNodeText(data, "", ""); - if(!the_genre) - { - delete [] data; - return false; - } - - unsigned int genre_num = 0; - const char * ptr = the_genre; - - while(*ptr != '\0') - { - if(genre_num >= genre.size()) - genre.resize(genre_num+1); - - if(*ptr == ',' || *ptr == '/' || *ptr == ';') - { - ptr++; - while(*ptr == ' ') ptr++; - genre[genre_num].push_back('\0'); - genre_num++; - continue; - } - - if(genre[genre_num].size() == 0) - genre[genre_num].push_back(toupper((int)*ptr)); - else - genre[genre_num].push_back(*ptr); - - ++ptr; - } - genre[genre_num].push_back('\0'); - - delete [] data; - - return true; -} - -const char * WiiTDB::RatingToString(int rating) -{ - switch(rating) - { - case 0: - return "CERO"; - case 1: - return "ESRB"; - case 2: - return "PEGI"; - default: - break; - } - - return NULL; -} - -int WiiTDB::GetRating(const char * id) -{ - int rating = -1; - - if(!id) - return rating; - - char * data = GetGameNode(id); - if(!data) - return rating; - - char * rating_text = GetNodeText(data, ""); - if(!rating_text) - { - delete [] data; - return rating; - } - - if(strncmp(rating_text, "CERO", 4) == 0) - rating = 0; - - else if(strncmp(rating_text, "ESRB", 4) == 0) - rating = 1; - - else if(strncmp(rating_text, "PEGI", 4) == 0) - rating = 2; - - delete [] data; - - return rating; -} - -bool WiiTDB::GetRatingValue(const char * id, string & rating_value) -{ - if(!id) - return false; - - char * data = GetGameNode(id); - if(!data) - return false; - - char * rating_text = GetNodeText(data, ""); - if(!rating_text) - { - delete [] data; - return false; - } - - char * value_text = GetNodeText(rating_text, "value=\"", "\""); - if(!value_text) - { - delete [] data; - return false; - } - - rating_value = value_text; - - delete [] data; - - return true; -} - -int WiiTDB::GetRatingDescriptorList(const char * id, vector & desc_list) -{ - if(!id) - return -1; - - char * data = GetGameNode(id); - if(!data) - return -1; - - char * descriptor_text = GetNodeText(data, "", ""); - if(!descriptor_text) - { - delete [] data; - return -1; - } - - unsigned int list_num = 0; - desc_list.clear(); - - while(*descriptor_text != '\0') - { - if(strncmp(descriptor_text, "", strlen("")) == 0) - { - desc_list[list_num].push_back('\0'); - descriptor_text = strstr(descriptor_text, ""); - if(!descriptor_text) - break; - - descriptor_text += strlen(""); - list_num++; - } - - if(list_num >= desc_list.size()) - desc_list.resize(list_num+1); - - desc_list[list_num].push_back(*descriptor_text); - ++descriptor_text; - } - - delete [] data; - - return desc_list.size(); -} - -int WiiTDB::GetWifiPlayers(const char * id) -{ - int players = -1; - - if(!id) - return players; - - char * data = GetGameNode(id); - if(!data) - return players; - - char * PlayersNode = GetNodeText(data, ""); - if(!PlayersNode) - { - delete [] data; - return players; - } - - players = atoi(PlayersNode); - - return players; -} - -int WiiTDB::GetWifiFeatureList(const char * id, vector & feat_list) -{ - if(!id) - return -1; - - char * data = GetGameNode(id); - if(!data) - return -1; - - char * feature_text = GetNodeText(data, "", ""); - if(!feature_text) - { - delete [] data; - return -1; - } - - unsigned int list_num = 0; - feat_list.clear(); - - while(*feature_text != '\0') - { - if(strncmp(feature_text, "", strlen("")) == 0) - { - feat_list[list_num].push_back('\0'); - feature_text = strstr(feature_text, ""); - if(!feature_text) - break; - - feature_text += strlen(""); - list_num++; - } - - if(list_num >= feat_list.size()) - feat_list.resize(list_num+1); - - - if(feat_list[list_num].size() == 0) - feat_list[list_num].push_back(toupper((int)*feature_text)); - else - feat_list[list_num].push_back(*feature_text); - - ++feature_text; - } - - delete [] data; - - return feat_list.size(); -} - -int WiiTDB::GetPlayers(const char * id) -{ - int players = -1; - - if(!id) - return players; - - char * data = GetGameNode(id); - if(!data) - return players; - - char * PlayersNode = GetNodeText(data, ""); - if(!PlayersNode) - { - delete [] data; - return players; - } - - players = atoi(PlayersNode); - - return players; -} - -int WiiTDB::GetAccessoirList(const char * id, vector & acc_list) -{ - if(!id) - return -1; - - char * data = GetGameNode(id); - if(!data) - return -1; - - char * ControlsNode = GetNodeText(data, ""); - if(!ControlsNode) - { - delete [] data; - return -1; - } - - unsigned int list_num = 0; - acc_list.clear(); - - while(ControlsNode && *ControlsNode != '\0') - { - if(list_num >= acc_list.size()) - acc_list.resize(list_num+1); - - for(const char * ptr = ControlsNode; *ptr != '"' && *ptr != '\0'; ptr++) - { - acc_list[list_num].Name.push_back(*ptr); - } - acc_list[list_num].Name.push_back('\0'); - - char * requiredField = strstr(ControlsNode, "required=\""); - if(!requiredField) - { - delete [] data; - return -1; - } - - requiredField += strlen("required=\""); - - if(strncmp(requiredField, "true", 4) == 0) - { - acc_list[list_num].Required = true; - } - else - { - acc_list[list_num].Required = false; - } - - ControlsNode = strstr(requiredField, ""); - if(!ColorNode) - { - delete [] data; - return color; - } - - color = strtoul(ColorNode, NULL, 16); - - return color; -} - -bool WiiTDB::GetGameXMLInfo(const char * id, GameXMLInfo * gameInfo) -{ - if(!id || !gameInfo) - return false; - - for(int i = 0; i < 6 && id[i] != 0; ++i) - gameInfo->GameID.push_back(id[i]); - gameInfo->GameID.push_back('\0'); - - GetTitle(id, gameInfo->Title); - GetSynopsis(id, gameInfo->Synopsis); - GetRegion(id, gameInfo->Region); - GetDeveloper(id, gameInfo->Developer); - GetPublisher(id, gameInfo->Publisher); - gameInfo->PublishDate = GetPublishDate(id); - GetGenreList(id, gameInfo->GenreList); - gameInfo->RatingType = GetRating(id); - GetRatingValue(id, gameInfo->RatingValue); - GetRatingDescriptorList(id, gameInfo->RatingDescriptorList); - gameInfo->WifiPlayers = GetWifiPlayers(id); - GetWifiFeatureList(id, gameInfo->WifiFeatureList); - gameInfo->Players = GetPlayers(id); - GetAccessoirList(id, gameInfo->AccessoirList); - gameInfo->CaseColor = GetCaseColor(id); - - return true; -} diff --git a/source/xml/WiiTDB.hpp b/source/xml/WiiTDB.hpp deleted file mode 100644 index 7b2a0f74..00000000 --- a/source/xml/WiiTDB.hpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - ***************************************************************************/ -#ifndef WIITDB_HPP_ -#define WIITDB_HPP_ - -#include -#include - -using namespace std; - -typedef struct _Accessoir -{ - string Name; - bool Required; -} Accessoir; - -typedef struct _GameXMLInfo -{ - string GameID; - string Region; - string Title; - string Synopsis; - string Developer; - string Publisher; - unsigned int PublishDate; - vector GenreList; - int RatingType; - string RatingValue; - vector RatingDescriptorList; - int WifiPlayers; - vector WifiFeatureList; - int Players; - vector AccessoirList; - long CaseColor; - -} GameXMLInfo; - -typedef struct _GameOffsets -{ - char gameID[7]; - unsigned int gamenode; - unsigned int nodesize; -} __attribute__((__packed__)) GameOffsets; - -class WiiTDB -{ - public: - //! Constructor - WiiTDB(); - //! Constructor - //! If filepath is passed the xml file is opened and the node offsets are loaded - WiiTDB(const char * filepath); - //! Destructor - ~WiiTDB(); - //! If filepath is passed the xml file is opened and the node offsets are loaded - bool OpenFile(const char * filepath); - //! Closes the WiiTDB xml file - void CloseFile(); - //! Set the language code which should be use to find the appropriate language - //! If the language code is not found, the language code defaults to EN - void SetLanguageCode(const char * code) { if(code) LangCode = code; }; - //! Get the current set language code - const char * GetLanguageCode() { return LangCode.c_str(); }; - //! Get the title of a specific game id in the language defined in LangCode - bool GetTitle(const char * id, string & title); - //! Get the synopsis of a specific game id in the language defined in LangCode - bool GetSynopsis(const char * id, string & synopsis); - //! Get the region of a game for a specific game id - bool GetRegion(const char * id, string & region); - //! Get the developer of a game for a specific game id - bool GetDeveloper(const char * id, string & dev); - //! Get the publisher of a game for a specific game id - bool GetPublisher(const char * id, string & pub); - //! Get the publish date of a game for a specific game id - //! First 1 byte is the day, than 1 byte month and last 2 bytes is the year - //! year = (return >> 16), month = (return >> 8) & 0xFF, day = return & 0xFF - unsigned int GetPublishDate(const char * id); - //! Get the genre list of a game for a specific game id - bool GetGenreList(const char * id, vector & genre); - //! Get the rating type for a specific game id - //! The rating type can be converted to a string with WiiTDB::RatingToString(rating) - int GetRating(const char * id); - //! Get the rating value for a specific game id - bool GetRatingValue(const char * id, string & rating_value); - //! Get the rating descriptor list inside a vector for a specific game id - //! Returns the amount of descriptors found or -1 if failed - int GetRatingDescriptorList(const char * id, vector & desc_list); - //! Get the wifi player count for a specific game id - //! Returns the amount of wifi players or -1 if failed - int GetWifiPlayers(const char * id); - //! Get the wifi feature list inside a vector for a specific game id - //! Returns the amount of wifi features found or -1 if failed - int GetWifiFeatureList(const char * id, vector & feat_list); - //! Get the player count for a specific game id - //! Returns the amount of players or -1 if failed - int GetPlayers(const char * id); - //! Returns the amount of accessoirs found or -1 if failed - //! Get the accessoir (inputs) list inside a vector for a specific game id - int GetAccessoirList(const char * id, vector & acc_list); - //! Get the box (case) color for a specific game id - //! Returns the color in RGB (first 3 bytes) - int GetCaseColor(const char * id); - //! Get the complete game info in the GameXMLInfo struct - bool GetGameXMLInfo(const char * id, GameXMLInfo * gameInfo); - //! Convert a specific game rating to a string - static const char * RatingToString(int rating); - //! Get the version of the wiitdb xml database - unsigned long long GetWiiTDBVersion(); - //! Get the entry count in the xml database - inline size_t GetEntryCount() { return OffsetMap.size(); }; - private: - bool ParseFile(); - bool LoadGameOffsets(const char * path); - bool SaveGameOffsets(const char * path); - inline size_t GetData(char * data, int offset, int size); - inline char * LoadGameNode(const char * id); - inline char * GetGameNode(const char * id); - inline GameOffsets * GetGameOffset(const char * id); - inline char * SeekLang(char * text, const char * langcode); - inline char * GetNodeText(char * data, const char * nodestart, const char * nodeend); - - vector OffsetMap; - FILE * file; - string LangCode; - char * GameNodeCache; - char GameIDCache[7]; -}; - -#endif diff --git a/source/xml/xml.cpp b/source/xml/xml.cpp deleted file mode 100644 index 2d62def1..00000000 --- a/source/xml/xml.cpp +++ /dev/null @@ -1,451 +0,0 @@ -/* - Load game information from XML - Lustar - - Mini-XML by Michael Sweet - - MiniZip adapted by Tantric - */ - -#include -#include -#include "settings/CSettings.h" -#include "settings/CGameSettings.h" -#include "settings/GameTitles.h" -#include "xml/xml.h" - -extern char game_partition[6]; - -/* config */ -static char xmlcfg_filename[100] = "wiitdb"; -static int xmlmaxsize = 1572864; - -static char langlist[11][22] = { { "Console Default" }, { "Japanese" }, { "English" }, { "German" }, { "French" }, { - "Spanish" }, { "Italian" }, { "Dutch" }, { "S. Chinese" }, { "T. Chinese" }, { "Korean" } }; - -static char langcodes[11][5] = { { "" }, { "JA" }, { "EN" }, { "DE" }, { "FR" }, { "ES" }, { "IT" }, { "NL" }, - { "ZHCN" }, // People's Republic of China - { "ZHTW" }, // Taiwan - { "KO" } }; - -static char element_text[5000]; -static mxml_node_t *nodetree = NULL; -static mxml_node_t *nodedata = NULL; -static mxml_node_t *nodeid = NULL; -static mxml_node_t *nodeidtmp = NULL; -static mxml_node_t *nodefound = NULL; -static mxml_index_t *nodeindex = NULL; -static mxml_index_t *nodeindextmp = NULL; -int xmlloadtime = 0; -char * get_nodetext(mxml_node_t *node, char *buffer, int buflen); -bool xml_loaded = false; - -/* load renamed titles from proper names and game info XML, needs to be after cfg_load_games */ -bool OpenXMLDatabase(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool openfile, bool loadtitles, bool keepopen) -{ - if (!xml_loaded) - { - bool opensuccess = false; - char pathname[200]; - snprintf(pathname, sizeof(pathname), "%s", xmlfilepath); - if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/", pathname); - snprintf(pathname, sizeof(pathname), "%s%s_%s.zip", pathname, xmlcfg_filename, game_partition); - if (openfile) opensuccess = OpenXMLFile(pathname); - if (!opensuccess) - { - snprintf(pathname, sizeof(pathname), "%s", xmlfilepath); - if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/", pathname); - snprintf(pathname, sizeof(pathname), "%swiitdb.zip", pathname); - if (openfile) opensuccess = OpenXMLFile(pathname); - } - if (!opensuccess && openfile) - { - CloseXMLDatabase(); - return false; - } - if (loadtitles) LoadTitlesFromXML(argdblang, argJPtoEN); - if (!keepopen) CloseXMLDatabase(); - } - else - { - if (loadtitles) LoadTitlesFromXML(argdblang, argJPtoEN); - if (!keepopen) CloseXMLDatabase(); - } - return true; -} - -void CloseXMLDatabase() -{ - /* free memory */ - if (xml_loaded) - { - mxmlDelete(nodedata); - mxmlDelete(nodetree); - xml_loaded = false; - } -} - -void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, const char *nodename, const char *attributename, - char *value, int descend, char *dest, int destsize) -{ - *element_text = 0; - nodefound = mxmlFindElement(currentnode, topnode, nodename, attributename, value, descend); - if (nodefound != NULL) - { - if (attributename != NULL) - { - strlcpy(dest, mxmlElementGetAttr(nodefound, attributename), destsize); - } - else - { - get_nodetext(nodefound, element_text, sizeof(element_text)); - strlcpy(dest, element_text, destsize); - } - } - else - { - strcpy(dest, ""); - } -} - -bool OpenXMLFile(char *filename) -{ - //if (xmldebug) dbg_time1(); - - if (xml_loaded) return false; - - nodedata = NULL; - nodetree = NULL; - nodeid = NULL; - nodeidtmp = NULL; - nodefound = NULL; - - char* strresult = strstr(filename, ".zip"); - if (strresult == NULL) - { - /* Load XML file */ - FILE *filexml; - filexml = fopen(filename, "rb"); - if (!filexml) return false; - - nodetree = mxmlLoadFile(NULL, filexml, MXML_OPAQUE_CALLBACK); - fclose(filexml); - - } - else - { - /* load zipped XML file */ - unzFile unzfile = unzOpen(filename); - if (unzfile == NULL) return false; - unzOpenCurrentFile(unzfile); - - unz_file_info zipfileinfo; - unzGetCurrentFileInfo(unzfile, &zipfileinfo, NULL, 0, NULL, 0, NULL, 0); - int zipfilebuffersize = zipfileinfo.uncompressed_size; - if (zipfilebuffersize >= xmlmaxsize) - { - unzCloseCurrentFile(unzfile); - unzClose(unzfile); - return false; - } - - char * zipfilebuffer = (char *) malloc(zipfilebuffersize); - memset(zipfilebuffer, 0, zipfilebuffersize); - if (zipfilebuffer == NULL) - { - unzCloseCurrentFile(unzfile); - unzClose(unzfile); - return false; - } - - unzReadCurrentFile(unzfile, zipfilebuffer, zipfilebuffersize); - unzCloseCurrentFile(unzfile); - unzClose(unzfile); - - nodetree = mxmlLoadString(NULL, zipfilebuffer, MXML_OPAQUE_CALLBACK); - free(zipfilebuffer); - } - - if (nodetree == NULL) return false; - - nodedata = mxmlFindElement(nodetree, nodetree, "datafile", NULL, NULL, MXML_DESCEND); - if (nodedata == NULL) - { - return false; - } - else - { - //if (xmldebug) xmlloadtime = dbg_time2(NULL); - xml_loaded = true; - return true; - } -} - -char *GetLangSettingFromGame(char *gameid) -{ - int langcode; - GameCFG *game_cfg = GameSettings.GetGameCFG((u8*) gameid); - if (game_cfg) - { - langcode = game_cfg->language; - } - else - { - //langcode = CFG.language; // for Configurable Loader - langcode = Settings.language; // for Loader GX - } - char *langtxt = langlist[langcode]; - return langtxt; -} - -/* convert language text into ISO 639 two-letter language code (+ZHTW/ZHCN) */ -const char *ConvertLangTextToCode(char *languagetxt) -{ - // do not convert if languagetext seems to be a language code (can be 2 or 4 letters) - if (strlen(languagetxt) <= 4) return languagetxt; - int i; - for (i = 0; i <= 10; i++) - { - if (!strcasecmp(languagetxt, langlist[i])) // case insensitive comparison - return langcodes[i]; - } - return ""; -} - -char ConvertRatingToIndex(char *ratingtext) -{ - int type = -1; - if (!strcmp(ratingtext, "CERO")) - { - type = 0; - } - if (!strcmp(ratingtext, "ESRB")) - { - type = 1; - } - if (!strcmp(ratingtext, "PEGI")) - { - type = 2; - } - return type; -} - -int ConvertRating(const char *ratingvalue, const char *fromrating, const char *torating) -{ - if (!strcmp(fromrating, torating)) - { - int ret = atoi(ratingvalue); - if(ret < 7) - return 0; - else if(ret < 12) - return 1; - else if(ret < 16) - return 2; - else if(ret < 18) - return 3; - else - return 4; - } - - int type = -1; - int desttype = -1; - - type = ConvertRatingToIndex((char *) fromrating); - desttype = ConvertRatingToIndex((char *) torating); - if (type == -1 || desttype == -1) return -1; - - /* rating conversion table */ - /* the list is ordered to pick the most likely value first: */ - /* EC and AO are less likely to be used so they are moved down to only be picked up when converting ESRB to PEGI or CERO */ - /* the conversion can never be perfect because ratings can differ between regions for the same game */ - char ratingtable[12][3][5] = - { - { { "A" }, { "E" }, { "3" } }, - { { "A" }, { "E" }, { "4" } }, - { { "A" }, { "E" }, { "6" } }, - { { "A" }, { "E" }, { "7" } }, - { { "A" }, { "EC" }, { "3" } }, - { { "A" }, { "E10+" }, { "7" } }, - { { "B" }, { "T" }, { "12" } }, - { { "D" }, { "M" }, { "18" } }, - { { "D" }, { "M" }, { "16" } }, - { { "C" }, { "T" }, { "16" } }, - { { "C" }, { "T" }, { "15" } }, - { { "Z" }, { "AO" }, { "18" } }, - }; - - int i; - for (i = 0; i <= 11; i++) - { - if (!strcmp(ratingtable[i][type], ratingvalue)) - { - int ret = atoi(ratingtable[i][desttype]); - if(ret < 7) - return 0; - else if(ret < 12) - return 1; - else if(ret < 16) - return 2; - else if(ret < 18) - return 3; - else - return 4; - } - } - - return -1; -} - -void LoadTitlesFromXML(char *langtxt, bool forcejptoen) -/* langtxt: set to "English","French","German", to force language for all titles, or "" to load title depending on each game's setting */ -/* forcejptoen: set to true to load English title instead of Japanese title when game is set to Japanese */ -{ - if (nodedata == NULL) return; - - bool forcelang = false; - if (strcmp(langtxt, "")) forcelang = true; - - char langcode[10] = ""; - if (forcelang) strcpy(langcode, ConvertLangTextToCode(langtxt)); /* convert language text into ISO 639 two-letter language code */ - - /* create index of elements */ - nodeindex = mxmlIndexNew(nodedata, "id", NULL); - nodeid = mxmlIndexReset(nodeindex); - *element_text = 0; - char id_text[10]; - char title_text[200] = ""; - char title_text_EN[200] = ""; - - /* search index of id elements, load all id/titles text */ - while (nodeid != NULL) - { - nodeid = mxmlIndexFind(nodeindex, "id", NULL); - if (nodeid != NULL) - { - strcpy(title_text, ""); - strcpy(title_text_EN, ""); - - get_nodetext(nodeid, element_text, sizeof(element_text)); - snprintf(id_text, 7, "%s", element_text); - - // if language is not forced, use game language setting from config - if (!forcelang) - { - langtxt = GetLangSettingFromGame(id_text); - strcpy(langcode, ConvertLangTextToCode(langtxt)); - } - - /* if enabled, force English title for all games set to Japanese */ - if (forcejptoen && (strcmp(langcode, "JA")) == 0) strcpy(langcode, "EN"); - - /* load title from nodes */ - nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", "EN", MXML_NO_DESCEND); - if (nodefound != NULL) - { - GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, title_text_EN, - sizeof(title_text_EN)); - } - nodefound = mxmlFindElement(nodeid, nodedata, "locale", "lang", langcode, MXML_NO_DESCEND); - if (nodefound != NULL) - { - GetTextFromNode(nodefound, nodedata, "title", NULL, NULL, MXML_DESCEND, title_text, sizeof(title_text)); - } - - /* fall back to English title if prefered language was not found */ - if (!strcmp(title_text, "")) - { - strcpy(title_text, title_text_EN); - } - - snprintf(id_text, 7, "%s", id_text); - GameTitles.SetGameTitle(id_text, title_text); - } - } - - // free memory - mxmlIndexDelete(nodeindex); - - //if (xmldebug) xmlloadtime = dbg_time2(NULL); -} - -void GetPublisherFromGameid(char *idtxt, char *dest, int destsize) -{ - /* guess publisher from company list using last two characters from game id */ - nodeindextmp = mxmlIndexNew(nodedata, "company", NULL); - nodeidtmp = mxmlIndexReset(nodeindextmp); - - *element_text = 0; - char publishercode[3]; - sprintf(publishercode, "%c%c", idtxt[4], idtxt[5]); - - while (strcmp(element_text, publishercode) != 0) - { - nodeidtmp = mxmlIndexFind(nodeindextmp, "company", NULL); - if (nodeidtmp != NULL) - { - strlcpy(element_text, mxmlElementGetAttr(nodeidtmp, "code"), sizeof(element_text)); - } - else - { - break; - } - } - if (!strcmp(element_text, publishercode)) - { - strlcpy(dest, mxmlElementGetAttr(nodeidtmp, "name"), destsize); - } - else - { - strcpy(dest, ""); - } - - // free memory - mxmlIndexDelete(nodeindextmp); -} - -char *MemInfo() -{ - char linebuf[300] = ""; - char memtotal[20]; - char memused[20]; - char memnotinuse[20]; - char memcanbefreed[20]; - struct mallinfo mymallinfo = mallinfo(); - sprintf(memtotal, "%d", mymallinfo.arena / 1024); - sprintf(memused, "%d", mymallinfo.uordblks / 1024); - sprintf(memnotinuse, "%d", mymallinfo.fordblks / 1024); - sprintf(memcanbefreed, "%d", mymallinfo.keepcost / 1024); - snprintf(linebuf, sizeof(linebuf), "all:%sKB used:%sKB notused:%sKB canfree:%sKB", memtotal, memused, memnotinuse, - memcanbefreed); - char *minfo[300]; - *minfo = linebuf; - return *minfo; -} - -/*-------------------------------------------------------------------------------------*/ -/* get_nodetext() - Get the text for a node, taken from mini-mxml example mxmldoc.c */ -char * get_nodetext(mxml_node_t *node, char *buffer, int buflen) /* O - Text in node, I - Node to get, I - Buffer, I - Size of buffer */ -{ - char *ptr, *end; /* Pointer into buffer, End of buffer */ - int len; /* Length of node */ - mxml_node_t *current; /* Current node */ - ptr = buffer; - end = buffer + buflen - 1; - for (current = node->child; current && ptr < end; current = current->next) - { - if (current->type == MXML_TEXT) - { - if (current->value.text.whitespace) *ptr++ = ' '; - len = (int) strlen(current->value.text.string); - if (len > (int) (end - ptr)) len = (int) (end - ptr); - memcpy(ptr, current->value.text.string, len); - ptr += len; - } - else if (current->type == MXML_OPAQUE) - { - len = (int) strlen(current->value.opaque); - if (len > (int) (end - ptr)) len = (int) (end - ptr); - memcpy(ptr, current->value.opaque, len); - ptr += len; - } - } - *ptr = '\0'; - return (buffer); -} diff --git a/source/xml/xml.h b/source/xml/xml.h deleted file mode 100644 index cd40b089..00000000 --- a/source/xml/xml.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _XML_H_ -#define _XML_H_ - -#include - -// open database, close database, load info for a game -bool OpenXMLDatabase(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool openfile, bool loadtitles, bool keepopen); -void CloseXMLDatabase(); - -#define XML_ELEMMAX 15 - -bool OpenXMLFile(char* filename); -void LoadTitlesFromXML(char *langcode, bool forcejptoen); -void GetPublisherFromGameid(char *idtxt, char *dest, int destsize); -const char *ConvertLangTextToCode(char *langtext); -int ConvertRating(const char *ratingvalue, const char *fromrating, const char *torating); -char *MemInfo(); -void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, const char *nodename, const char *attributename, - char *value, int descend, char *dest, int destsize); -char * get_nodetext(mxml_node_t *node, char *buffer, int buflen); - -#endif - diff --git a/svnrev.sh b/svnrev.sh deleted file mode 100644 index 96b7eec8..00000000 --- a/svnrev.sh +++ /dev/null @@ -1,89 +0,0 @@ -#! /bin/bash -# -rev_new_raw=$(svnversion -n . 2>/dev/null | tr '\n' ' ' | tr -d '\r') -[ -n "$rev_new_raw" ] || rev_new_raw=$(SubWCRev . 2>/dev/null | tr '\n' ' ' | tr -d '\r') - - -rev_new_raw=$(echo $rev_new_raw | sed 's/[^0-9]*\([0-9]*\)\(.*\)/\1 \2/') -rev_new=0 -a=$(echo $rev_new_raw | sed 's/\([0-9]*\).*/\1/') -let "a+=0" -#find max rev -while [ "$a" ]; do - [ "$a" -gt "$rev_new" ] && rev_new=$a - rev_new_raw=$(echo -n $rev_new_raw | sed 's/[0-9]*[^0-9]*\([0-9]*\)\(.*\)/\1 \2/') - a=$(echo $rev_new_raw | sed 's/\([0-9]*\).*/\1/') -done - -rev_old=$(cat ./source/svnrev.c 2>/dev/null | tr -d '\n' | sed 's/[^0-9]*\([0-9]*\).*/\1/') - -if [ "$rev_new" != "$rev_old" ] || [ ! -f ./source/svnrev.c ]; then - - cat < ./source/svnrev.c -#define SVN_REV "$rev_new" - -const char *GetRev() -{ - return SVN_REV; -} -EOF - - if [ -n "$rev_new" ]; then - echo "Changed Rev $rev_old to $rev_new" >&2 - else - echo "svnrev.c created" >&2 - fi - echo >&2 - - rev_new=`expr $rev_new + 1` - rev_date=`date +%Y%m%d%H%M -u` - - cat < ./HBC/META.XML - - - USB Loader GX - USB Loader GX Team - 1.0 r$rev_new - $rev_date - Loads games from USB-devices - 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. -Features are automatic widescreen detection, coverdownload, parental control, theme support and many more. - -Credits: -Coding: Dimok, nIxx, giantpune, ardi, Hungyip84, DrayX7, Lustar, r-win, WiiShizzza -Artworks: cyrex, NeoRame -WiiTDB / Hosting covers: Lustar -Hosting updates files: CorneliousJD -USBLoader sources: Waninkoko, Kwiirk, Hermes -Languages files updates: Kinyo and translaters -Hosting themes: Deak Phreak - -Libwiigui: Tantric -Libogc/Devkit: Shagkur and Wintermute -FreeTypeGX: Armin Tamzarian. - -Links: -USB Loader GX Project Page and Support Site: -http://code.google.com/p/usbloader-gui/ -Help Website: -http://usbloadergx.koureio.net/ -WiiTDB Site: -http://wiitdb.com -Themes Site: -http://wii.spiffy360.com -Languages Translaters Page: -http://gbatemp.net/index.php?showtopic=155252 - -Libwiigui Website: -http://wiibrew.org/wiki/Libwiigui/ -FreeTypeGX Project Page: -http://code.google.com/p/freetypegx/ -Gettext Official Page: -http://www.gnu.org/software/gettext/gettext.html - - -EOF - -fi -echo $a