mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-22 11:19:17 +01:00
*Mem2 fix
*updated libntfs (write fix) *updated libfat *lots of changes in the startup code, removed almost everything. This might cause problems for some drives at loading the gamelist and needs to be adjusted later but better this time. more cleanup is needed in main.cpp and will come. *using libogc sd/usb for config loading and reload to cIOS afterwards *added missing boothomebrew stuff pune forgot NOTE: From now on we will be doing a lot of revs which we won't be compiling and releasing. This revs are officially not available for public so don't making issues regarding those revs. Those will be closed right away. We need first to cleanup a lot of crap and update loader to new standards before releasing stuff again.
This commit is contained in:
parent
ac26935769
commit
64f8406b07
@ -2,8 +2,8 @@
|
|||||||
<app version="1">
|
<app version="1">
|
||||||
<name> USB Loader GX</name>
|
<name> USB Loader GX</name>
|
||||||
<coder>USB Loader GX Team</coder>
|
<coder>USB Loader GX Team</coder>
|
||||||
<version>1.0 r943</version>
|
<version>1.0 r944</version>
|
||||||
<release_date>201009161155</release_date>
|
<release_date>201009161846</release_date>
|
||||||
<short_description>Loads games from USB-devices</short_description>
|
<short_description>Loads games from USB-devices</short_description>
|
||||||
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
|
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
|
||||||
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.
|
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.
|
||||||
|
BIN
data/app_booter.dol
Normal file
BIN
data/app_booter.dol
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
File diff suppressed because one or more lines are too long
@ -1,151 +0,0 @@
|
|||||||
#include <gccore.h>
|
|
||||||
#include <ogcsys.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ogc/machine/processor.h>
|
|
||||||
#include <wiiuse/wpad.h>
|
|
||||||
#include "../lstub.h"
|
|
||||||
|
|
||||||
#include "fatmounter.h"
|
|
||||||
#include "dolloader.h"
|
|
||||||
#include "elfloader.h"
|
|
||||||
|
|
||||||
void *innetbuffer = NULL;
|
|
||||||
|
|
||||||
int AllocHomebrewMemory(u32 filesize) {
|
|
||||||
|
|
||||||
innetbuffer = malloc(filesize);
|
|
||||||
|
|
||||||
if (!innetbuffer)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void FreeHomebrewBuffer() {
|
|
||||||
free(innetbuffer);
|
|
||||||
innetbuffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CopyHomebrewMemory(u32 read, u8 *temp, u32 len) {
|
|
||||||
|
|
||||||
memcpy(((u8 *) innetbuffer)+read, temp, len);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int BootHomebrew(char * path) {
|
|
||||||
loadStub();
|
|
||||||
if (Set_Stub_Split(0x00010001,"UNEO")<0)
|
|
||||||
Set_Stub_Split(0x00010001,"ULNR");
|
|
||||||
void *buffer = NULL;
|
|
||||||
u32 filesize = 0;
|
|
||||||
entrypoint entry;
|
|
||||||
u32 cpu_isr;
|
|
||||||
|
|
||||||
FILE * file = fopen(path, "rb");
|
|
||||||
if (!file) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
|
|
||||||
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_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
|
||||||
fclose (file);
|
|
||||||
|
|
||||||
struct __argv args;
|
|
||||||
bzero(&args, sizeof(args));
|
|
||||||
args.argvMagic = ARGV_MAGIC;
|
|
||||||
args.length = strlen(path) + 2;
|
|
||||||
args.commandLine = (char*)malloc(args.length);
|
|
||||||
if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
strcpy(args.commandLine, path);
|
|
||||||
args.commandLine[args.length - 1] = '\0';
|
|
||||||
args.argc = 1;
|
|
||||||
args.argv = &args.commandLine;
|
|
||||||
args.endARGV = args.argv + 1;
|
|
||||||
|
|
||||||
int ret = valid_elf_image(buffer);
|
|
||||||
if (ret == 1)
|
|
||||||
entry = (entrypoint) load_elf_image(buffer);
|
|
||||||
else
|
|
||||||
entry = (entrypoint) load_dol(buffer, &args);
|
|
||||||
|
|
||||||
free(buffer);
|
|
||||||
|
|
||||||
if (!entry) {
|
|
||||||
SDCard_deInit();
|
|
||||||
USBDevice_deInit();
|
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDCard_deInit();
|
|
||||||
USBDevice_deInit();
|
|
||||||
|
|
||||||
WPAD_Flush(0);
|
|
||||||
WPAD_Disconnect(0);
|
|
||||||
WPAD_Shutdown();
|
|
||||||
|
|
||||||
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
|
||||||
_CPU_ISR_Disable (cpu_isr);
|
|
||||||
__exception_closeall();
|
|
||||||
entry();
|
|
||||||
_CPU_ISR_Restore (cpu_isr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int BootHomebrewFromMem() {
|
|
||||||
loadStub();
|
|
||||||
if (Set_Stub_Split(0x00010001,"UNEO")<0)
|
|
||||||
Set_Stub_Split(0x00010001,"ULNR");
|
|
||||||
entrypoint entry;
|
|
||||||
u32 cpu_isr;
|
|
||||||
|
|
||||||
if (!innetbuffer) {
|
|
||||||
SDCard_deInit();
|
|
||||||
USBDevice_deInit();
|
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct __argv args;
|
|
||||||
|
|
||||||
int ret = valid_elf_image(innetbuffer);
|
|
||||||
if (ret == 1)
|
|
||||||
entry = (entrypoint) load_elf_image(innetbuffer);
|
|
||||||
else
|
|
||||||
entry = (entrypoint) load_dol(innetbuffer, &args);
|
|
||||||
|
|
||||||
free(innetbuffer);
|
|
||||||
|
|
||||||
if (!entry) {
|
|
||||||
SDCard_deInit();
|
|
||||||
USBDevice_deInit();
|
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDCard_deInit();
|
|
||||||
USBDevice_deInit();
|
|
||||||
|
|
||||||
WPAD_Flush(0);
|
|
||||||
WPAD_Disconnect(0);
|
|
||||||
WPAD_Shutdown();
|
|
||||||
|
|
||||||
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
|
||||||
_CPU_ISR_Disable (cpu_isr);
|
|
||||||
__exception_closeall();
|
|
||||||
entry();
|
|
||||||
_CPU_ISR_Restore (cpu_isr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
131
source/homebrewboot/BootHomebrew.cpp
Normal file
131
source/homebrewboot/BootHomebrew.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#include <gccore.h>
|
||||||
|
#include <ogcsys.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ogc/machine/processor.h>
|
||||||
|
#include <wiiuse/wpad.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "usbloader/usbstorage2.h"
|
||||||
|
#include "dolloader.h"
|
||||||
|
#include "fatmounter.h"
|
||||||
|
#include "sys.h"
|
||||||
|
|
||||||
|
extern const u8 app_booter_dol[];
|
||||||
|
extern const u32 app_booter_dol_size;
|
||||||
|
|
||||||
|
static u8 *homebrewbuffer = (u8 *) 0x92000000;
|
||||||
|
static int homebrewsize = 0;
|
||||||
|
static std::vector<std::string> Arguments;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BootHomebrew()
|
||||||
|
{
|
||||||
|
if(homebrewsize <= 0)
|
||||||
|
Sys_BackToLoader();
|
||||||
|
|
||||||
|
SDCard_deInit();
|
||||||
|
USBDevice_deInit();
|
||||||
|
USBStorage2_Deinit();
|
||||||
|
|
||||||
|
struct __argv args;
|
||||||
|
SetupARGV(&args);
|
||||||
|
|
||||||
|
u32 cpu_isr;
|
||||||
|
|
||||||
|
entrypoint entry = (entrypoint) load_dol(app_booter_dol, &args);
|
||||||
|
|
||||||
|
if (!entry)
|
||||||
|
Sys_BackToLoader();
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
FILE * file = fopen(filepath, "rb");
|
||||||
|
if(!file)
|
||||||
|
Sys_BackToLoader();
|
||||||
|
|
||||||
|
fseek(file, 0, SEEK_END);
|
||||||
|
|
||||||
|
int size = ftell(file);
|
||||||
|
rewind(file);
|
||||||
|
|
||||||
|
homebrewsize = fread(homebrewbuffer, 1, size, file);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
AddBootArgument(filepath);
|
||||||
|
|
||||||
|
return BootHomebrew();
|
||||||
|
}
|
@ -1,13 +1,11 @@
|
|||||||
#ifndef _BOOTHOMEBREW_H_
|
#ifndef _BOOTHOMEBREW_H_
|
||||||
#define _BOOTHOMEBREW_H_
|
#define _BOOTHOMEBREW_H_
|
||||||
|
|
||||||
|
int BootHomebrew();
|
||||||
int BootHomebrew(char * path);
|
int BootHomebrew(const char * filepath);
|
||||||
int BootHomebrewFromMem();
|
int CopyHomebrewMemory(u8 *temp, u32 pos, u32 len);
|
||||||
void CopyHomebrewMemory(u32 read, u8 *temp, u32 len);
|
void AddBootArgument(const char * arg);
|
||||||
int AllocHomebrewMemory(u32 filesize);
|
|
||||||
void FreeHomebrewBuffer();
|
void FreeHomebrewBuffer();
|
||||||
void AddBootArgument(const char * argv);
|
int LoadHomebrew(const char * filepath);
|
||||||
extern u32 homebrewsize;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,7 +41,6 @@ extern char wiiloadVersion[2];
|
|||||||
extern u8 shutdown;
|
extern u8 shutdown;
|
||||||
extern u8 reset;
|
extern u8 reset;
|
||||||
extern struct SSettings Settings;
|
extern struct SSettings Settings;
|
||||||
extern void *innetbuffer;
|
|
||||||
|
|
||||||
/*** Variables used elsewhere ***/
|
/*** Variables used elsewhere ***/
|
||||||
u8 boothomebrew = 0;
|
u8 boothomebrew = 0;
|
||||||
@ -794,124 +793,118 @@ int MenuHomebrewBrowse() {
|
|||||||
|
|
||||||
int choice = WindowPrompt(filesizetxt, temp, tr("OK"), tr("Cancel"));
|
int choice = WindowPrompt(filesizetxt, temp, tr("OK"), tr("Cancel"));
|
||||||
|
|
||||||
if (choice == 1) {
|
if (choice == 1)
|
||||||
|
{
|
||||||
|
u32 read = 0;
|
||||||
|
u8 *temp = NULL;
|
||||||
|
int len = NETWORKBLOCKSIZE;
|
||||||
|
temp = (u8 *) malloc(infilesize);
|
||||||
|
|
||||||
int res = AllocHomebrewMemory(infilesize);
|
bool error = false;
|
||||||
|
u8 *ptr = temp;
|
||||||
|
while (read < infilesize) {
|
||||||
|
|
||||||
if (res < 0) {
|
ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true);
|
||||||
CloseConnection();
|
|
||||||
WindowPrompt(tr("Not enough free memory."), 0, tr("OK"));
|
|
||||||
} else {
|
|
||||||
u32 read = 0;
|
|
||||||
u8 *temp = NULL;
|
|
||||||
int len = NETWORKBLOCKSIZE;
|
|
||||||
temp = (u8 *) malloc(infilesize);
|
|
||||||
|
|
||||||
bool error = false;
|
if (infilesize - read < (u32) len)
|
||||||
u8 *ptr = temp;
|
len = infilesize-read;
|
||||||
while (read < infilesize) {
|
else
|
||||||
|
len = NETWORKBLOCKSIZE;
|
||||||
|
|
||||||
ShowProgress(tr("Receiving file from:"), GetIncommingIP(), NULL, read, infilesize, true);
|
int result = network_read(ptr, len);
|
||||||
|
|
||||||
if (infilesize - read < (u32) len)
|
if (result < 0) {
|
||||||
len = infilesize-read;
|
WindowPrompt(tr("Error while transfering data."), 0, tr("OK"));
|
||||||
else
|
error = true;
|
||||||
len = NETWORKBLOCKSIZE;
|
break;
|
||||||
|
}
|
||||||
int result = network_read(ptr, len);
|
if (!result) {
|
||||||
|
break;
|
||||||
if (result < 0) {
|
|
||||||
WindowPrompt(tr("Error while transfering data."), 0, tr("OK"));
|
|
||||||
error = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!result) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr += result;
|
|
||||||
|
|
||||||
read += result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char filename[101];
|
ptr += result;
|
||||||
if (!error) {
|
|
||||||
|
|
||||||
network_read((u8*) &filename, 100);
|
read += result;
|
||||||
|
}
|
||||||
|
|
||||||
// Do we need to unzip this thing?
|
char filename[101];
|
||||||
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) {
|
if (!error) {
|
||||||
|
|
||||||
// We need to unzip...
|
network_read((u8*) &filename, 100);
|
||||||
if (temp[0] == 'P' && temp[1] == 'K' && temp[2] == 0x03 && temp[3] == 0x04) {
|
|
||||||
// It's a zip file, unzip to the apps directory
|
|
||||||
|
|
||||||
// Zip archive, ask for permission to install the zip
|
// Do we need to unzip this thing?
|
||||||
char zippath[255];
|
if (wiiloadVersion[0] > 0 || wiiloadVersion[1] > 4) {
|
||||||
sprintf((char *) &zippath, "%s%s", Settings.homebrewapps_path, filename);
|
|
||||||
|
|
||||||
FILE *fp = fopen(zippath, "wb");
|
// We need to unzip...
|
||||||
if (fp != NULL)
|
if (temp[0] == 'P' && temp[1] == 'K' && temp[2] == 0x03 && temp[3] == 0x04) {
|
||||||
{
|
// It's a zip file, unzip to the apps directory
|
||||||
fwrite(temp, 1, infilesize, fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
// Now unzip the zip file...
|
// Zip archive, ask for permission to install the zip
|
||||||
unzFile uf = unzOpen(zippath);
|
char zippath[255];
|
||||||
if (uf==NULL) {
|
sprintf((char *) &zippath, "%s%s", Settings.homebrewapps_path, filename);
|
||||||
error = true;
|
|
||||||
} else {
|
|
||||||
extractZip(uf,0,1,0, Settings.homebrewapps_path);
|
|
||||||
unzCloseCurrentFile(uf);
|
|
||||||
|
|
||||||
remove(zippath);
|
FILE *fp = fopen(zippath, "wb");
|
||||||
|
if (fp != NULL)
|
||||||
|
{
|
||||||
|
fwrite(temp, 1, infilesize, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
// Reload this menu here...
|
// Now unzip the zip file...
|
||||||
menu = MENU_HOMEBREWBROWSE;
|
unzFile uf = unzOpen(zippath);
|
||||||
break;
|
if (uf==NULL) {
|
||||||
}
|
error = true;
|
||||||
} else {
|
} else {
|
||||||
error = true;
|
extractZip(uf,0,1,0, Settings.homebrewapps_path);
|
||||||
}
|
unzCloseCurrentFile(uf);
|
||||||
} 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, temp, infilesize) != Z_OK;
|
|
||||||
uncfilesize = f;
|
|
||||||
homebrewsize = uncfilesize;
|
|
||||||
|
|
||||||
free(temp);
|
remove(zippath);
|
||||||
temp = unc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!error && strstr(filename,".zip") == NULL) {
|
// Reload this menu here...
|
||||||
innetbuffer = temp;
|
menu = MENU_HOMEBREWBROWSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} 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, temp, infilesize) != Z_OK;
|
||||||
|
uncfilesize = f;
|
||||||
|
infilesize = f;
|
||||||
|
|
||||||
}
|
free(temp);
|
||||||
}
|
temp = unc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProgressStop();
|
if (!error && strstr(filename,".zip") == NULL) {
|
||||||
|
CopyHomebrewMemory(temp, 0, infilesize);
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (error || read != infilesize) {
|
ProgressStop();
|
||||||
WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK"));
|
|
||||||
FreeHomebrewBuffer();
|
if (error || read != infilesize) {
|
||||||
|
WindowPrompt(tr("Error:"), tr("No data could be read."), tr("OK"));
|
||||||
|
FreeHomebrewBuffer();
|
||||||
|
} else {
|
||||||
|
if (strstr(filename,".dol") || strstr(filename,".DOL")
|
||||||
|
|| strstr(filename,".elf") || strstr(filename,".ELF"))
|
||||||
|
{
|
||||||
|
boothomebrew = 2;
|
||||||
|
AddBootArgument( filename );
|
||||||
|
menu = MENU_EXIT;
|
||||||
|
CloseConnection();
|
||||||
|
break;
|
||||||
|
} else if (strstr(filename,".zip")) {
|
||||||
|
WindowPrompt(tr("Success:"), tr("Uploaded ZIP file installed to homebrew directory."), tr("OK"));
|
||||||
|
CloseConnection();
|
||||||
} else {
|
} else {
|
||||||
if (strstr(filename,".dol") || strstr(filename,".DOL")
|
FreeHomebrewBuffer();
|
||||||
|| strstr(filename,".elf") || strstr(filename,".ELF")) {
|
WindowPrompt(tr("ERROR:"), tr("Not a DOL/ELF file."), tr("OK"));
|
||||||
boothomebrew = 2;
|
|
||||||
AddBootArgument( filename );
|
|
||||||
menu = MENU_EXIT;
|
|
||||||
CloseConnection();
|
|
||||||
break;
|
|
||||||
} else if (strstr(filename,".zip")) {
|
|
||||||
WindowPrompt(tr("Success:"), tr("Uploaded ZIP file installed to homebrew directory."), tr("OK"));
|
|
||||||
CloseConnection();
|
|
||||||
} else {
|
|
||||||
FreeHomebrewBuffer();
|
|
||||||
WindowPrompt(tr("ERROR:"), tr("Not a DOL/ELF file."), tr("OK"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ typedef struct _dolheader {
|
|||||||
u32 entry_point;
|
u32 entry_point;
|
||||||
} dolheader;
|
} dolheader;
|
||||||
|
|
||||||
u32 load_dol(void *dolstart, struct __argv *argv) {
|
u32 load_dol(const void *dolstart, struct __argv *argv) {
|
||||||
u32 i;
|
u32 i;
|
||||||
dolheader *dolfile;
|
dolheader *dolfile;
|
||||||
|
|
||||||
@ -28,15 +28,13 @@ u32 load_dol(void *dolstart, struct __argv *argv) {
|
|||||||
dolfile = (dolheader *) dolstart;
|
dolfile = (dolheader *) dolstart;
|
||||||
for (i = 0; i < 7; i++) {
|
for (i = 0; i < 7; i++) {
|
||||||
if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue;
|
if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue;
|
||||||
VIDEO_WaitVSync();
|
|
||||||
ICInvalidateRange ((void *) dolfile->text_start[i],dolfile->text_size[i]);
|
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]);
|
memcpy((void *) dolfile->text_start[i],dolstart+dolfile->text_pos[i],dolfile->text_size[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 11; i++) {
|
for (i = 0; i < 11; i++) {
|
||||||
if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue;
|
if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue;
|
||||||
VIDEO_WaitVSync();
|
memcpy((void *) dolfile->data_start[i],dolstart+dolfile->data_pos[i],dolfile->data_size[i]);
|
||||||
memmove ((void *) dolfile->data_start[i],dolstart+dolfile->data_pos[i],dolfile->data_size[i]);
|
|
||||||
DCFlushRangeNoSync ((void *) dolfile->data_start[i],dolfile->data_size[i]);
|
DCFlushRangeNoSync ((void *) dolfile->data_start[i],dolfile->data_size[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ u32 load_dol(void *dolstart, struct __argv *argv) {
|
|||||||
|
|
||||||
if (argv && argv->argvMagic == ARGV_MAGIC) {
|
if (argv && argv->argvMagic == ARGV_MAGIC) {
|
||||||
void *new_argv = (void *)(dolfile->entry_point + 8);
|
void *new_argv = (void *)(dolfile->entry_point + 8);
|
||||||
memmove(new_argv, argv, sizeof(*argv));
|
memcpy(new_argv, argv, sizeof(*argv));
|
||||||
DCFlushRange(new_argv, sizeof(*argv));
|
DCFlushRange(new_argv, sizeof(*argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void __exception_closeall();
|
extern void __exception_closeall();
|
||||||
typedef void (*entrypoint) (void);
|
typedef void (*entrypoint) (void);
|
||||||
|
|
||||||
u32 load_dol(void *dolstart, struct __argv *argv);
|
u32 load_dol(const void *dolstart, struct __argv *argv);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1,590 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 1995, 1996, 2001, 2002
|
|
||||||
* Erik Theisen. 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. 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This is the ELF ABI header file
|
|
||||||
* formerly known as "elf_abi.h".
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ELF_ABI_H
|
|
||||||
#define _ELF_ABI_H
|
|
||||||
|
|
||||||
#include <gctypes.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This version doesn't work for 64-bit ABIs - Erik.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* These typedefs need to be handled better.
|
|
||||||
*/
|
|
||||||
typedef u32 Elf32_Addr; /* Unsigned program address */
|
|
||||||
typedef u32 Elf32_Off; /* Unsigned file offset */
|
|
||||||
typedef s32 Elf32_Sword; /* Signed large integer */
|
|
||||||
typedef u32 Elf32_Word; /* Unsigned large integer */
|
|
||||||
typedef u16 Elf32_Half; /* Unsigned medium integer */
|
|
||||||
|
|
||||||
/* e_ident[] identification indexes */
|
|
||||||
#define EI_MAG0 0 /* file ID */
|
|
||||||
#define EI_MAG1 1 /* file ID */
|
|
||||||
#define EI_MAG2 2 /* file ID */
|
|
||||||
#define EI_MAG3 3 /* file ID */
|
|
||||||
#define EI_CLASS 4 /* file class */
|
|
||||||
#define EI_DATA 5 /* data encoding */
|
|
||||||
#define EI_VERSION 6 /* ELF header version */
|
|
||||||
#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
|
|
||||||
#define EI_ABIVERSION 8 /* ABI target version */
|
|
||||||
#define EI_PAD 9 /* start of pad bytes */
|
|
||||||
#define EI_NIDENT 16 /* Size of e_ident[] */
|
|
||||||
|
|
||||||
/* e_ident[] magic number */
|
|
||||||
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
|
||||||
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
|
||||||
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
|
||||||
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
|
||||||
#define ELFMAG "\177ELF" /* magic */
|
|
||||||
#define SELFMAG 4 /* size of magic */
|
|
||||||
|
|
||||||
/* e_ident[] file class */
|
|
||||||
#define ELFCLASSNONE 0 /* invalid */
|
|
||||||
#define ELFCLASS32 1 /* 32-bit objs */
|
|
||||||
#define ELFCLASS64 2 /* 64-bit objs */
|
|
||||||
#define ELFCLASSNUM 3 /* number of classes */
|
|
||||||
|
|
||||||
/* e_ident[] data encoding */
|
|
||||||
#define ELFDATANONE 0 /* invalid */
|
|
||||||
#define ELFDATA2LSB 1 /* Little-Endian */
|
|
||||||
#define ELFDATA2MSB 2 /* Big-Endian */
|
|
||||||
#define ELFDATANUM 3 /* number of data encode defines */
|
|
||||||
|
|
||||||
/* e_ident[] OS/ABI specific ELF extensions */
|
|
||||||
#define ELFOSABI_NONE 0 /* No extension specified */
|
|
||||||
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
|
|
||||||
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
|
||||||
#define ELFOSABI_LINUX 3 /* Linux */
|
|
||||||
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
|
|
||||||
#define ELFOSABI_AIX 7 /* AIX */
|
|
||||||
#define ELFOSABI_IRIX 8 /* IRIX */
|
|
||||||
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
|
||||||
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
|
|
||||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
|
||||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
|
||||||
/* 64-255 Architecture-specific value range */
|
|
||||||
|
|
||||||
/* e_ident[] ABI Version */
|
|
||||||
#define ELFABIVERSION 0
|
|
||||||
|
|
||||||
/* e_ident */
|
|
||||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
|
||||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
|
||||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
|
||||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
|
||||||
|
|
||||||
/* ELF Header */
|
|
||||||
typedef struct elfhdr {
|
|
||||||
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
|
||||||
Elf32_Half e_type; /* object file type */
|
|
||||||
Elf32_Half e_machine; /* machine */
|
|
||||||
Elf32_Word e_version; /* object file version */
|
|
||||||
Elf32_Addr e_entry; /* virtual entry point */
|
|
||||||
Elf32_Off e_phoff; /* program header table offset */
|
|
||||||
Elf32_Off e_shoff; /* section header table offset */
|
|
||||||
Elf32_Word e_flags; /* processor-specific flags */
|
|
||||||
Elf32_Half e_ehsize; /* ELF header size */
|
|
||||||
Elf32_Half e_phentsize; /* program header entry size */
|
|
||||||
Elf32_Half e_phnum; /* number of program header entries */
|
|
||||||
Elf32_Half e_shentsize; /* section header entry size */
|
|
||||||
Elf32_Half e_shnum; /* number of section header entries */
|
|
||||||
Elf32_Half e_shstrndx; /* section header table's "section
|
|
||||||
header string table" entry offset */
|
|
||||||
} Elf32_Ehdr;
|
|
||||||
|
|
||||||
/* e_type */
|
|
||||||
#define ET_NONE 0 /* No file type */
|
|
||||||
#define ET_REL 1 /* relocatable file */
|
|
||||||
#define ET_EXEC 2 /* executable file */
|
|
||||||
#define ET_DYN 3 /* shared object file */
|
|
||||||
#define ET_CORE 4 /* core file */
|
|
||||||
#define ET_NUM 5 /* number of types */
|
|
||||||
#define ET_LOOS 0xfe00 /* reserved range for operating */
|
|
||||||
#define ET_HIOS 0xfeff /* system specific e_type */
|
|
||||||
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
|
||||||
#define ET_HIPROC 0xffff /* specific e_type */
|
|
||||||
|
|
||||||
/* e_machine */
|
|
||||||
#define EM_NONE 0 /* No Machine */
|
|
||||||
#define EM_M32 1 /* AT&T WE 32100 */
|
|
||||||
#define EM_SPARC 2 /* SPARC */
|
|
||||||
#define EM_386 3 /* Intel 80386 */
|
|
||||||
#define EM_68K 4 /* Motorola 68000 */
|
|
||||||
#define EM_88K 5 /* Motorola 88000 */
|
|
||||||
#if 0
|
|
||||||
#define EM_486 6 /* RESERVED - was Intel 80486 */
|
|
||||||
#endif
|
|
||||||
#define EM_860 7 /* Intel 80860 */
|
|
||||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
|
||||||
#define EM_S370 9 /* IBM System/370 Processor */
|
|
||||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
|
||||||
#if 0
|
|
||||||
#define EM_SPARC64 11 /* RESERVED - was SPARC v9
|
|
||||||
64-bit unoffical */
|
|
||||||
#endif
|
|
||||||
/* RESERVED 11-14 for future use */
|
|
||||||
#define EM_PARISC 15 /* HPPA */
|
|
||||||
/* RESERVED 16 for future use */
|
|
||||||
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
|
||||||
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
|
||||||
#define EM_960 19 /* Intel 80960 */
|
|
||||||
#define EM_PPC 20 /* PowerPC */
|
|
||||||
#define EM_PPC64 21 /* 64-bit PowerPC */
|
|
||||||
#define EM_S390 22 /* IBM System/390 Processor */
|
|
||||||
/* RESERVED 23-35 for future use */
|
|
||||||
#define EM_V800 36 /* NEC V800 */
|
|
||||||
#define EM_FR20 37 /* Fujitsu FR20 */
|
|
||||||
#define EM_RH32 38 /* TRW RH-32 */
|
|
||||||
#define EM_RCE 39 /* Motorola RCE */
|
|
||||||
#define EM_ARM 40 /* Advanced Risc Machines ARM */
|
|
||||||
#define EM_ALPHA 41 /* Digital Alpha */
|
|
||||||
#define EM_SH 42 /* Hitachi SH */
|
|
||||||
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
|
||||||
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
|
|
||||||
#define EM_ARC 45 /* Argonaut RISC Core */
|
|
||||||
#define EM_H8_300 46 /* Hitachi H8/300 */
|
|
||||||
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
|
||||||
#define EM_H8S 48 /* Hitachi H8S */
|
|
||||||
#define EM_H8_500 49 /* Hitachi H8/500 */
|
|
||||||
#define EM_IA_64 50 /* Intel Merced */
|
|
||||||
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
|
||||||
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
|
||||||
#define EM_68HC12 53 /* Motorola M68HC12 */
|
|
||||||
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
|
|
||||||
#define EM_PCP 55 /* Siemens PCP */
|
|
||||||
#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
|
|
||||||
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
|
|
||||||
#define EM_STARCORE 58 /* Motorola Start*Core processor */
|
|
||||||
#define EM_ME16 59 /* Toyota ME16 processor */
|
|
||||||
#define EM_ST100 60 /* STMicroelectronic ST100 processor */
|
|
||||||
#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
|
|
||||||
#define EM_X86_64 62 /* AMD x86-64 */
|
|
||||||
#define EM_PDSP 63 /* Sony DSP Processor */
|
|
||||||
/* RESERVED 64,65 for future use */
|
|
||||||
#define EM_FX66 66 /* Siemens FX66 microcontroller */
|
|
||||||
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
|
|
||||||
#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
|
|
||||||
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
|
|
||||||
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
|
|
||||||
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
|
|
||||||
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
|
|
||||||
#define EM_SVX 73 /* Silicon Graphics SVx */
|
|
||||||
#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
|
|
||||||
#define EM_VAX 75 /* Digital VAX */
|
|
||||||
#define EM_CHRIS 76 /* Axis Communications embedded proc. */
|
|
||||||
#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
|
|
||||||
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
|
|
||||||
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
|
|
||||||
#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
|
|
||||||
#define EM_HUANY 81 /* Harvard University mach-indep objs */
|
|
||||||
#define EM_PRISM 82 /* SiTera Prism */
|
|
||||||
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
|
|
||||||
#define EM_FR30 84 /* Fujitsu FR30 */
|
|
||||||
#define EM_D10V 85 /* Mitsubishi DV10V */
|
|
||||||
#define EM_D30V 86 /* Mitsubishi DV30V */
|
|
||||||
#define EM_V850 87 /* NEC v850 */
|
|
||||||
#define EM_M32R 88 /* Mitsubishi M32R */
|
|
||||||
#define EM_MN10300 89 /* Matsushita MN10200 */
|
|
||||||
#define EM_MN10200 90 /* Matsushita MN10200 */
|
|
||||||
#define EM_PJ 91 /* picoJava */
|
|
||||||
#define EM_NUM 92 /* number of machine types */
|
|
||||||
|
|
||||||
/* Version */
|
|
||||||
#define EV_NONE 0 /* Invalid */
|
|
||||||
#define EV_CURRENT 1 /* Current */
|
|
||||||
#define EV_NUM 2 /* number of versions */
|
|
||||||
|
|
||||||
/* Section Header */
|
|
||||||
typedef struct {
|
|
||||||
Elf32_Word sh_name; /* name - index into section header
|
|
||||||
string table section */
|
|
||||||
Elf32_Word sh_type; /* type */
|
|
||||||
Elf32_Word sh_flags; /* flags */
|
|
||||||
Elf32_Addr sh_addr; /* address */
|
|
||||||
Elf32_Off sh_offset; /* file offset */
|
|
||||||
Elf32_Word sh_size; /* section size */
|
|
||||||
Elf32_Word sh_link; /* section header table index link */
|
|
||||||
Elf32_Word sh_info; /* extra information */
|
|
||||||
Elf32_Word sh_addralign; /* address alignment */
|
|
||||||
Elf32_Word sh_entsize; /* section entry size */
|
|
||||||
} Elf32_Shdr;
|
|
||||||
|
|
||||||
/* Special Section Indexes */
|
|
||||||
#define SHN_UNDEF 0 /* undefined */
|
|
||||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
|
||||||
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
|
||||||
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
|
||||||
#define SHN_LOOS 0xff20 /* reserved range for operating */
|
|
||||||
#define SHN_HIOS 0xff3f /* specific semantics */
|
|
||||||
#define SHN_ABS 0xfff1 /* absolute value */
|
|
||||||
#define SHN_COMMON 0xfff2 /* common symbol */
|
|
||||||
#define SHN_XINDEX 0xffff /* Index is an extra table */
|
|
||||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
|
||||||
|
|
||||||
/* sh_type */
|
|
||||||
#define SHT_NULL 0 /* inactive */
|
|
||||||
#define SHT_PROGBITS 1 /* program defined information */
|
|
||||||
#define SHT_SYMTAB 2 /* symbol table section */
|
|
||||||
#define SHT_STRTAB 3 /* string table section */
|
|
||||||
#define SHT_RELA 4 /* relocation section with addends*/
|
|
||||||
#define SHT_HASH 5 /* symbol hash table section */
|
|
||||||
#define SHT_DYNAMIC 6 /* dynamic section */
|
|
||||||
#define SHT_NOTE 7 /* note section */
|
|
||||||
#define SHT_NOBITS 8 /* no space section */
|
|
||||||
#define SHT_REL 9 /* relation section without addends */
|
|
||||||
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
|
||||||
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
|
||||||
#define SHT_INIT_ARRAY 14 /* Array of constructors */
|
|
||||||
#define SHT_FINI_ARRAY 15 /* Array of destructors */
|
|
||||||
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
|
|
||||||
#define SHT_GROUP 17 /* Section group */
|
|
||||||
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
|
|
||||||
#define SHT_NUM 19 /* number of section types */
|
|
||||||
#define SHT_LOOS 0x60000000 /* Start OS-specific */
|
|
||||||
#define SHT_HIOS 0x6fffffff /* End OS-specific */
|
|
||||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
|
||||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
|
||||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
|
||||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
|
||||||
|
|
||||||
/* Section names */
|
|
||||||
#define ELF_BSS ".bss" /* uninitialized data */
|
|
||||||
#define ELF_COMMENT ".comment" /* version control information */
|
|
||||||
#define ELF_DATA ".data" /* initialized data */
|
|
||||||
#define ELF_DATA1 ".data1" /* initialized data */
|
|
||||||
#define ELF_DEBUG ".debug" /* debug */
|
|
||||||
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
|
||||||
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
|
||||||
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
|
||||||
#define ELF_FINI ".fini" /* termination code */
|
|
||||||
#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
|
|
||||||
#define ELF_GOT ".got" /* global offset table */
|
|
||||||
#define ELF_HASH ".hash" /* symbol hash table */
|
|
||||||
#define ELF_INIT ".init" /* initialization code */
|
|
||||||
#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
|
|
||||||
#define ELF_INTERP ".interp" /* Pathname of program interpreter */
|
|
||||||
#define ELF_LINE ".line" /* Symbolic line numnber information */
|
|
||||||
#define ELF_NOTE ".note" /* Contains note section */
|
|
||||||
#define ELF_PLT ".plt" /* Procedure linkage table */
|
|
||||||
#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
|
|
||||||
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
|
||||||
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
|
||||||
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
|
||||||
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
|
||||||
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
|
||||||
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
|
||||||
#define ELF_RODATA ".rodata" /* read-only data */
|
|
||||||
#define ELF_RODATA1 ".rodata1" /* read-only data */
|
|
||||||
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
|
||||||
#define ELF_STRTAB ".strtab" /* string table */
|
|
||||||
#define ELF_SYMTAB ".symtab" /* symbol table */
|
|
||||||
#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
|
|
||||||
#define ELF_TBSS ".tbss" /* thread local uninit data */
|
|
||||||
#define ELF_TDATA ".tdata" /* thread local init data */
|
|
||||||
#define ELF_TDATA1 ".tdata1" /* thread local init data */
|
|
||||||
#define ELF_TEXT ".text" /* code */
|
|
||||||
|
|
||||||
/* Section Attribute Flags - sh_flags */
|
|
||||||
#define SHF_WRITE 0x1 /* Writable */
|
|
||||||
#define SHF_ALLOC 0x2 /* occupies memory */
|
|
||||||
#define SHF_EXECINSTR 0x4 /* executable */
|
|
||||||
#define SHF_MERGE 0x10 /* Might be merged */
|
|
||||||
#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
|
|
||||||
#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
|
|
||||||
#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
|
|
||||||
#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
|
|
||||||
#define SHF_GROUP 0x200 /* Member of section group */
|
|
||||||
#define SHF_TLS 0x400 /* Thread local storage */
|
|
||||||
#define SHF_MASKOS 0x0ff00000 /* OS specific */
|
|
||||||
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
|
||||||
/* specific section attributes */
|
|
||||||
|
|
||||||
/* Section Group Flags */
|
|
||||||
#define GRP_COMDAT 0x1 /* COMDAT group */
|
|
||||||
#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
|
|
||||||
#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
|
|
||||||
|
|
||||||
/* Symbol Table Entry */
|
|
||||||
typedef struct elf32_sym {
|
|
||||||
Elf32_Word st_name; /* name - index into string table */
|
|
||||||
Elf32_Addr st_value; /* symbol value */
|
|
||||||
Elf32_Word st_size; /* symbol size */
|
|
||||||
unsigned char st_info; /* type and binding */
|
|
||||||
unsigned char st_other; /* 0 - no defined meaning */
|
|
||||||
Elf32_Half st_shndx; /* section header index */
|
|
||||||
} Elf32_Sym;
|
|
||||||
|
|
||||||
/* Symbol table index */
|
|
||||||
#define STN_UNDEF 0 /* undefined */
|
|
||||||
|
|
||||||
/* Extract symbol info - st_info */
|
|
||||||
#define ELF32_ST_BIND(x) ((x) >> 4)
|
|
||||||
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
|
||||||
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
|
||||||
#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
|
|
||||||
|
|
||||||
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
|
||||||
#define STB_LOCAL 0 /* Local symbol */
|
|
||||||
#define STB_GLOBAL 1 /* Global symbol */
|
|
||||||
#define STB_WEAK 2 /* like global - lower precedence */
|
|
||||||
#define STB_NUM 3 /* number of symbol bindings */
|
|
||||||
#define STB_LOOS 10 /* reserved range for operating */
|
|
||||||
#define STB_HIOS 12 /* system specific symbol bindings */
|
|
||||||
#define STB_LOPROC 13 /* reserved range for processor */
|
|
||||||
#define STB_HIPROC 15 /* specific symbol bindings */
|
|
||||||
|
|
||||||
/* Symbol type - ELF32_ST_TYPE - st_info */
|
|
||||||
#define STT_NOTYPE 0 /* not specified */
|
|
||||||
#define STT_OBJECT 1 /* data object */
|
|
||||||
#define STT_FUNC 2 /* function */
|
|
||||||
#define STT_SECTION 3 /* section */
|
|
||||||
#define STT_FILE 4 /* file */
|
|
||||||
#define STT_NUM 5 /* number of symbol types */
|
|
||||||
#define STT_TLS 6 /* Thread local storage symbol */
|
|
||||||
#define STT_LOOS 10 /* reserved range for operating */
|
|
||||||
#define STT_HIOS 12 /* system specific symbol types */
|
|
||||||
#define STT_LOPROC 13 /* reserved range for processor */
|
|
||||||
#define STT_HIPROC 15 /* specific symbol types */
|
|
||||||
|
|
||||||
/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
|
|
||||||
#define STV_DEFAULT 0 /* Normal visibility rules */
|
|
||||||
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
|
||||||
#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
|
|
||||||
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
|
||||||
|
|
||||||
|
|
||||||
/* Relocation entry with implicit addend */
|
|
||||||
typedef struct {
|
|
||||||
Elf32_Addr r_offset; /* offset of relocation */
|
|
||||||
Elf32_Word r_info; /* symbol table index and type */
|
|
||||||
} Elf32_Rel;
|
|
||||||
|
|
||||||
/* Relocation entry with explicit addend */
|
|
||||||
typedef struct {
|
|
||||||
Elf32_Addr r_offset; /* offset of relocation */
|
|
||||||
Elf32_Word r_info; /* symbol table index and type */
|
|
||||||
Elf32_Sword r_addend;
|
|
||||||
} Elf32_Rela;
|
|
||||||
|
|
||||||
/* Extract relocation info - r_info */
|
|
||||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
|
||||||
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
|
||||||
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
|
||||||
|
|
||||||
/* Program Header */
|
|
||||||
typedef struct {
|
|
||||||
Elf32_Word p_type; /* segment type */
|
|
||||||
Elf32_Off p_offset; /* segment offset */
|
|
||||||
Elf32_Addr p_vaddr; /* virtual address of segment */
|
|
||||||
Elf32_Addr p_paddr; /* physical address - ignored? */
|
|
||||||
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
|
||||||
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
|
||||||
Elf32_Word p_flags; /* flags */
|
|
||||||
Elf32_Word p_align; /* memory alignment */
|
|
||||||
} Elf32_Phdr;
|
|
||||||
|
|
||||||
/* Segment types - p_type */
|
|
||||||
#define PT_NULL 0 /* unused */
|
|
||||||
#define PT_LOAD 1 /* loadable segment */
|
|
||||||
#define PT_DYNAMIC 2 /* dynamic linking section */
|
|
||||||
#define PT_INTERP 3 /* the RTLD */
|
|
||||||
#define PT_NOTE 4 /* auxiliary information */
|
|
||||||
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
|
||||||
#define PT_PHDR 6 /* program header */
|
|
||||||
#define PT_TLS 7 /* Thread local storage template */
|
|
||||||
#define PT_NUM 8 /* Number of segment types */
|
|
||||||
#define PT_LOOS 0x60000000 /* reserved range for operating */
|
|
||||||
#define PT_HIOS 0x6fffffff /* system specific segment types */
|
|
||||||
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
|
||||||
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
|
||||||
|
|
||||||
/* Segment flags - p_flags */
|
|
||||||
#define PF_X 0x1 /* Executable */
|
|
||||||
#define PF_W 0x2 /* Writable */
|
|
||||||
#define PF_R 0x4 /* Readable */
|
|
||||||
#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
|
|
||||||
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
|
||||||
/* specific segment flags */
|
|
||||||
/* Dynamic structure */
|
|
||||||
typedef struct {
|
|
||||||
Elf32_Sword d_tag; /* controls meaning of d_val */
|
|
||||||
union {
|
|
||||||
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
|
||||||
Elf32_Addr d_ptr; /* program virtual address */
|
|
||||||
} d_un;
|
|
||||||
} Elf32_Dyn;
|
|
||||||
|
|
||||||
extern Elf32_Dyn _DYNAMIC[];
|
|
||||||
|
|
||||||
/* Dynamic Array Tags - d_tag */
|
|
||||||
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
|
||||||
#define DT_NEEDED 1 /* string table offset of needed lib */
|
|
||||||
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
|
||||||
#define DT_PLTGOT 3 /* address PLT/GOT */
|
|
||||||
#define DT_HASH 4 /* address of symbol hash table */
|
|
||||||
#define DT_STRTAB 5 /* address of string table */
|
|
||||||
#define DT_SYMTAB 6 /* address of symbol table */
|
|
||||||
#define DT_RELA 7 /* address of relocation table */
|
|
||||||
#define DT_RELASZ 8 /* size of relocation table */
|
|
||||||
#define DT_RELAENT 9 /* size of relocation entry */
|
|
||||||
#define DT_STRSZ 10 /* size of string table */
|
|
||||||
#define DT_SYMENT 11 /* size of symbol table entry */
|
|
||||||
#define DT_INIT 12 /* address of initialization func. */
|
|
||||||
#define DT_FINI 13 /* address of termination function */
|
|
||||||
#define DT_SONAME 14 /* string table offset of shared obj */
|
|
||||||
#define DT_RPATH 15 /* string table offset of library
|
|
||||||
search path */
|
|
||||||
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
|
||||||
#define DT_REL 17 /* address of rel. tbl. w addends */
|
|
||||||
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
|
||||||
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
|
||||||
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
|
||||||
#define DT_DEBUG 21 /* bugger */
|
|
||||||
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
|
||||||
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
|
||||||
#define DT_BIND_NOW 24 /* Process relocations of object */
|
|
||||||
#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
|
|
||||||
#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
|
|
||||||
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
|
|
||||||
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
|
|
||||||
#define DT_RUNPATH 29 /* Library search path */
|
|
||||||
#define DT_FLAGS 30 /* Flags for the object being loaded */
|
|
||||||
#define DT_ENCODING 32 /* Start of encoded range */
|
|
||||||
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
|
|
||||||
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
|
|
||||||
#define DT_NUM 34 /* Number used. */
|
|
||||||
#define DT_LOOS 0x60000000 /* reserved range for OS */
|
|
||||||
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
|
|
||||||
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
|
||||||
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
|
||||||
|
|
||||||
/* Dynamic Tag Flags - d_un.d_val */
|
|
||||||
#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
|
|
||||||
#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
|
|
||||||
#define DF_TEXTREL 0x04 /* Object contains text relocations */
|
|
||||||
#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
|
|
||||||
#define DF_STATIC_TLS 0x10 /* Static thread local storage */
|
|
||||||
|
|
||||||
/* Standard ELF hashing function */
|
|
||||||
unsigned long elf_hash(const unsigned char *name);
|
|
||||||
|
|
||||||
#define ELF_TARG_VER 1 /* The ver for which this code is intended */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* XXX - PowerPC defines really don't belong in here,
|
|
||||||
* but we'll put them in for simplicity.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Values for Elf32/64_Ehdr.e_flags. */
|
|
||||||
#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
|
|
||||||
|
|
||||||
/* Cygnus local bits below */
|
|
||||||
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
|
|
||||||
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
|
|
||||||
flag */
|
|
||||||
|
|
||||||
/* PowerPC relocations defined by the ABIs */
|
|
||||||
#define R_PPC_NONE 0
|
|
||||||
#define R_PPC_ADDR32 1 /* 32bit absolute address */
|
|
||||||
#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
|
|
||||||
#define R_PPC_ADDR16 3 /* 16bit absolute address */
|
|
||||||
#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
|
|
||||||
#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
|
|
||||||
#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
|
|
||||||
#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
|
|
||||||
#define R_PPC_ADDR14_BRTAKEN 8
|
|
||||||
#define R_PPC_ADDR14_BRNTAKEN 9
|
|
||||||
#define R_PPC_REL24 10 /* PC relative 26 bit */
|
|
||||||
#define R_PPC_REL14 11 /* PC relative 16 bit */
|
|
||||||
#define R_PPC_REL14_BRTAKEN 12
|
|
||||||
#define R_PPC_REL14_BRNTAKEN 13
|
|
||||||
#define R_PPC_GOT16 14
|
|
||||||
#define R_PPC_GOT16_LO 15
|
|
||||||
#define R_PPC_GOT16_HI 16
|
|
||||||
#define R_PPC_GOT16_HA 17
|
|
||||||
#define R_PPC_PLTREL24 18
|
|
||||||
#define R_PPC_COPY 19
|
|
||||||
#define R_PPC_GLOB_DAT 20
|
|
||||||
#define R_PPC_JMP_SLOT 21
|
|
||||||
#define R_PPC_RELATIVE 22
|
|
||||||
#define R_PPC_LOCAL24PC 23
|
|
||||||
#define R_PPC_UADDR32 24
|
|
||||||
#define R_PPC_UADDR16 25
|
|
||||||
#define R_PPC_REL32 26
|
|
||||||
#define R_PPC_PLT32 27
|
|
||||||
#define R_PPC_PLTREL32 28
|
|
||||||
#define R_PPC_PLT16_LO 29
|
|
||||||
#define R_PPC_PLT16_HI 30
|
|
||||||
#define R_PPC_PLT16_HA 31
|
|
||||||
#define R_PPC_SDAREL16 32
|
|
||||||
#define R_PPC_SECTOFF 33
|
|
||||||
#define R_PPC_SECTOFF_LO 34
|
|
||||||
#define R_PPC_SECTOFF_HI 35
|
|
||||||
#define R_PPC_SECTOFF_HA 36
|
|
||||||
/* Keep this the last entry. */
|
|
||||||
#define R_PPC_NUM 37
|
|
||||||
|
|
||||||
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
|
||||||
in the SVR4 ELF ABI. */
|
|
||||||
#define R_PPC_EMB_NADDR32 101
|
|
||||||
#define R_PPC_EMB_NADDR16 102
|
|
||||||
#define R_PPC_EMB_NADDR16_LO 103
|
|
||||||
#define R_PPC_EMB_NADDR16_HI 104
|
|
||||||
#define R_PPC_EMB_NADDR16_HA 105
|
|
||||||
#define R_PPC_EMB_SDAI16 106
|
|
||||||
#define R_PPC_EMB_SDA2I16 107
|
|
||||||
#define R_PPC_EMB_SDA2REL 108
|
|
||||||
#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
|
|
||||||
#define R_PPC_EMB_MRKREF 110
|
|
||||||
#define R_PPC_EMB_RELSEC16 111
|
|
||||||
#define R_PPC_EMB_RELST_LO 112
|
|
||||||
#define R_PPC_EMB_RELST_HI 113
|
|
||||||
#define R_PPC_EMB_RELST_HA 114
|
|
||||||
#define R_PPC_EMB_BIT_FLD 115
|
|
||||||
#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
|
|
||||||
|
|
||||||
/* Diab tool relocations. */
|
|
||||||
#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
|
|
||||||
#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
|
|
||||||
#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
|
|
||||||
#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
|
|
||||||
#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
|
|
||||||
#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
|
|
||||||
|
|
||||||
/* This is a phony reloc to handle any old fashioned TOC16 references
|
|
||||||
that may still be in object files. */
|
|
||||||
#define R_PPC_TOC16 255
|
|
||||||
|
|
||||||
#endif /* _ELF_H */
|
|
||||||
|
|
@ -1,101 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001 William L. Pitts
|
|
||||||
* Modifications (c) 2004 Felix Domke
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms are freely
|
|
||||||
* permitted provided that the above copyright notice and this
|
|
||||||
* paragraph and the following disclaimer are duplicated in all
|
|
||||||
* such forms.
|
|
||||||
*
|
|
||||||
* This software is provided "AS IS" and without any express or
|
|
||||||
* implied warranties, including, without limitation, the implied
|
|
||||||
* warranties of merchantability and fitness for a particular
|
|
||||||
* purpose.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <gccore.h>
|
|
||||||
|
|
||||||
#include "elf_abi.h"
|
|
||||||
|
|
||||||
/* ======================================================================
|
|
||||||
* Determine if a valid ELF image exists at the given memory location.
|
|
||||||
* First looks at the ELF header magic field, the makes sure that it is
|
|
||||||
* executable and makes sure that it is for a PowerPC.
|
|
||||||
* ====================================================================== */
|
|
||||||
s32 valid_elf_image (void *addr) {
|
|
||||||
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
|
|
||||||
|
|
||||||
ehdr = (Elf32_Ehdr *) addr;
|
|
||||||
|
|
||||||
if (!IS_ELF (*ehdr))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (ehdr->e_type != ET_EXEC)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (ehdr->e_machine != EM_PPC)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ======================================================================
|
|
||||||
* A very simple elf loader, assumes the image is valid, returns the
|
|
||||||
* entry point address.
|
|
||||||
* ====================================================================== */
|
|
||||||
u32 load_elf_image (void *addr) {
|
|
||||||
Elf32_Ehdr *ehdr;
|
|
||||||
Elf32_Shdr *shdr;
|
|
||||||
u8 *strtab = 0;
|
|
||||||
u8 *image;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
ehdr = (Elf32_Ehdr *) addr;
|
|
||||||
/* Find the section header string table for output info */
|
|
||||||
shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff +
|
|
||||||
(ehdr->e_shstrndx * sizeof (Elf32_Shdr)));
|
|
||||||
|
|
||||||
if (shdr->sh_type == SHT_STRTAB)
|
|
||||||
strtab = (u8 *) (addr + shdr->sh_offset);
|
|
||||||
|
|
||||||
/* Load each appropriate section */
|
|
||||||
for (i = 0; i < ehdr->e_shnum; ++i) {
|
|
||||||
shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff +
|
|
||||||
(i * sizeof (Elf32_Shdr)));
|
|
||||||
|
|
||||||
if (!(shdr->sh_flags & SHF_ALLOC)
|
|
||||||
|| shdr->sh_addr == 0 || shdr->sh_size == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
shdr->sh_addr &= 0x3FFFFFFF;
|
|
||||||
shdr->sh_addr |= 0x80000000;
|
|
||||||
|
|
||||||
if (strtab) {
|
|
||||||
/*printf ("%sing section %s @ 0x%08x (0x%08x bytes)\n",
|
|
||||||
(shdr->sh_type == SHT_NOBITS) ?
|
|
||||||
"clear" : "load",
|
|
||||||
&strtab[shdr->sh_name],
|
|
||||||
(u32) shdr->sh_addr,
|
|
||||||
(u32) shdr->sh_size);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shdr->sh_type == SHT_NOBITS) {
|
|
||||||
memset ((void *) shdr->sh_addr, 0, shdr->sh_size);
|
|
||||||
} else {
|
|
||||||
image = (u8 *) addr + shdr->sh_offset;
|
|
||||||
memcpy ((void *) shdr->sh_addr,
|
|
||||||
(const void *) image,
|
|
||||||
shdr->sh_size);
|
|
||||||
}
|
|
||||||
DCFlushRangeNoSync ((void *) shdr->sh_addr, shdr->sh_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ehdr->e_entry & 0x3FFFFFFF) | 0x80000000;
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
#ifndef _ELFLOADER_H_
|
|
||||||
#define _ELFLOADER_H_
|
|
||||||
|
|
||||||
#include <wiiuse/wpad.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
s32 valid_elf_image (void *addr);
|
|
||||||
u32 load_elf_image (void *addr);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -26,8 +26,8 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BIT_OPS_H
|
#ifndef _BIT_OPS_H
|
||||||
#define __BIT_OPS_H
|
#define _BIT_OPS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
130
source/libfat/cache.h
Normal file
130
source/libfat/cache.h
Normal file
@ -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
|
||||||
|
|
@ -26,23 +26,54 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __COMMON_H
|
#ifndef _COMMON_H
|
||||||
#define __COMMON_H
|
#define _COMMON_H
|
||||||
|
|
||||||
#define BYTES_PER_READ 512
|
#define BYTES_PER_READ 512
|
||||||
#include "fat.h"
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "libfat/fat.h"
|
||||||
|
|
||||||
|
// When compiling for NDS, make sure NDS is defined
|
||||||
|
#ifndef NDS
|
||||||
|
#if defined ARM9 || defined ARM7
|
||||||
|
#define NDS
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Platform specific includes
|
// Platform specific includes
|
||||||
#include <gctypes.h>
|
#if defined(__gamecube__) || defined (__wii__)
|
||||||
#include <ogc/disc_io.h>
|
#include <gctypes.h>
|
||||||
#include <gccore.h>
|
#include <ogc/disc_io.h>
|
||||||
|
#include <gccore.h>
|
||||||
|
#elif defined(NDS)
|
||||||
|
#include <nds/ndstypes.h>
|
||||||
|
#include <nds/system.h>
|
||||||
|
#include <nds/disc_io.h>
|
||||||
|
#elif defined(GBA)
|
||||||
|
#include <gba_types.h>
|
||||||
|
#include <disc_io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Platform specific options
|
// Platform specific options
|
||||||
#define DEFAULT_CACHE_PAGES 4
|
#if defined (__wii__)
|
||||||
#define DEFAULT_SECTORS_PAGE 64
|
#define DEFAULT_CACHE_PAGES 4
|
||||||
#define USE_LWP_LOCK
|
#define DEFAULT_SECTORS_PAGE 64
|
||||||
#define USE_RTC_TIME
|
#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
|
#endif // _COMMON_H
|
||||||
|
@ -329,7 +329,8 @@ bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry) {
|
|||||||
}
|
}
|
||||||
lfn[lfnPos] = '\0'; // Set end of lfn to null character
|
lfn[lfnPos] = '\0'; // Set end of lfn to null character
|
||||||
lfnChkSum = entryData[LFN_offset_checkSum];
|
lfnChkSum = entryData[LFN_offset_checkSum];
|
||||||
} if (lfnChkSum != entryData[LFN_offset_checkSum]) {
|
}
|
||||||
|
if (lfnChkSum != entryData[LFN_offset_checkSum]) {
|
||||||
lfnExists = false;
|
lfnExists = false;
|
||||||
}
|
}
|
||||||
if (lfnExists) {
|
if (lfnExists) {
|
||||||
@ -417,6 +418,49 @@ bool _FAT_directory_getRootEntry (PARTITION* partition, DIR_ENTRY* entry) {
|
|||||||
return true;
|
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_directory_incrementDirEntryPosition (partition, &entryEnd, false) == false) {
|
||||||
|
end = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry) {
|
bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry) {
|
||||||
DIR_ENTRY_POSITION entryStart = entry->dataStart;
|
DIR_ENTRY_POSITION entryStart = entry->dataStart;
|
||||||
DIR_ENTRY_POSITION entryEnd = entry->dataEnd;
|
DIR_ENTRY_POSITION entryEnd = entry->dataEnd;
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __DIRECTORY_H
|
#ifndef _DIRECTORY_H
|
||||||
#define __DIRECTORY_H
|
#define _DIRECTORY_H
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@ -170,4 +170,9 @@ Fill in a stat struct based on a file entry
|
|||||||
*/
|
*/
|
||||||
void _FAT_directory_entryStat (PARTITION* partition, DIR_ENTRY* entry, struct stat *st);
|
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
|
#endif // _DIRECTORY_H
|
||||||
|
110
source/libfat/disc.h
Normal file
110
source/libfat/disc.h
Normal file
@ -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
|
@ -2,7 +2,9 @@
|
|||||||
fat.h
|
fat.h
|
||||||
Simple functionality for startup, mounting and unmounting of FAT-based devices.
|
Simple functionality for startup, mounting and unmounting of FAT-based devices.
|
||||||
|
|
||||||
Copyright (c) 2006 Michael "Chishm" Chisholm
|
Copyright (c) 2006 - 2009
|
||||||
|
Michael "Chishm" Chisholm
|
||||||
|
Dave "WinterMute" Murphy
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
@ -34,8 +36,24 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// When compiling for NDS, make sure NDS is defined
|
||||||
|
#ifndef NDS
|
||||||
|
#if defined ARM9 || defined ARM7
|
||||||
|
#define NDS
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <ogc/disc_io.h>
|
|
||||||
|
#if defined(__gamecube__) || defined (__wii__)
|
||||||
|
# include <ogc/disc_io.h>
|
||||||
|
#else
|
||||||
|
# ifdef NDS
|
||||||
|
# include "nds/disc_io.h"
|
||||||
|
# else
|
||||||
|
# include "disc_io.h"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Initialise any inserted block-devices.
|
Initialise any inserted block-devices.
|
||||||
@ -67,12 +85,18 @@ 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.
|
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);
|
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.
|
Unmount the partition specified by name.
|
||||||
If there are open files, it will attempt to synchronise them to disc.
|
If there are open files, it will attempt to synchronise them to disc.
|
||||||
*/
|
*/
|
||||||
extern void fatUnmount (const char* name);
|
extern void fatUnmount (const char* name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Get Volume Label
|
||||||
|
*/
|
||||||
|
extern void fatGetVolumeLabel (const char* name, char *label);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,8 +37,8 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fat_cache.h"
|
#include "cache.h"
|
||||||
#include "disc_fat.h"
|
#include "disc.h"
|
||||||
|
|
||||||
#include "mem_allocate.h"
|
#include "mem_allocate.h"
|
||||||
#include "bit_ops.h"
|
#include "bit_ops.h"
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "disc_fat.h"
|
#include "disc.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The list of interfaces consists of a series of name/interface pairs.
|
The list of interfaces consists of a series of name/interface pairs.
|
||||||
@ -39,15 +39,16 @@ The list is terminated by a NULL/NULL entry.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* ====================== Wii ====================== */
|
/* ====================== Wii ====================== */
|
||||||
|
#if defined (__wii__)
|
||||||
#include <sdcard/wiisd_io.h>
|
#include <sdcard/wiisd_io.h>
|
||||||
#include "usbloader/usbstorage2.h"
|
#include <ogc/usbstorage.h>
|
||||||
#include <sdcard/gcsd.h>
|
#include <sdcard/gcsd.h>
|
||||||
|
|
||||||
static const DISC_INTERFACE* get_io_wiisd (void) {
|
static const DISC_INTERFACE* get_io_wiisd (void) {
|
||||||
return &__io_wiisd;
|
return &__io_wiisd;
|
||||||
}
|
}
|
||||||
static const DISC_INTERFACE* get_io_usbstorage (void) {
|
static const DISC_INTERFACE* get_io_usbstorage (void) {
|
||||||
return &__io_usbstorage2;
|
return &__io_usbstorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const DISC_INTERFACE* get_io_gcsda (void) {
|
static const DISC_INTERFACE* get_io_gcsda (void) {
|
||||||
@ -65,3 +66,40 @@ const INTERFACE_ID _FAT_disc_interfaces[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* ==================== Gamecube ==================== */
|
||||||
|
#elif defined (__gamecube__)
|
||||||
|
#include <sdcard/gcsd.h>
|
||||||
|
|
||||||
|
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 <nds/arm9/dldi.h>
|
||||||
|
|
||||||
|
const INTERFACE_ID _FAT_disc_interfaces[] = {
|
||||||
|
{"fat", dldiGetInternal},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* ====================== GBA ====================== */
|
||||||
|
#elif defined (GBA)
|
||||||
|
#include <disc.h>
|
||||||
|
|
||||||
|
const INTERFACE_ID _FAT_disc_interfaces[] = {
|
||||||
|
{"fat", discGetInterface},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
#include "fatdir.h"
|
#include "fatdir.h"
|
||||||
|
|
||||||
#include "fat_cache.h"
|
#include "cache.h"
|
||||||
#include "file_allocation_table.h"
|
#include "file_allocation_table.h"
|
||||||
#include "partition.h"
|
#include "partition.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __FATDIR_H
|
#ifndef _FATDIR_H
|
||||||
#define __FATDIR_H
|
#define _FATDIR_H
|
||||||
|
|
||||||
#include <sys/reent.h>
|
#include <sys/reent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "fat_cache.h"
|
#include "cache.h"
|
||||||
#include "file_allocation_table.h"
|
#include "file_allocation_table.h"
|
||||||
#include "bit_ops.h"
|
#include "bit_ops.h"
|
||||||
#include "filetime.h"
|
#include "filetime.h"
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __FAT_H
|
#ifndef _FAT_H
|
||||||
#define __FAT_H
|
#define _FAT_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "partition.h"
|
#include "partition.h"
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __FILETIME_H
|
#ifndef _FILETIME_H
|
||||||
#define __FILETIME_H
|
#define _FILETIME_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#include "fatdir.h"
|
#include "fatdir.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "mem_allocate.h"
|
#include "mem_allocate.h"
|
||||||
#include "disc_fat.h"
|
#include "disc.h"
|
||||||
|
|
||||||
static const devoptab_t dotab_fat = {
|
static const devoptab_t dotab_fat = {
|
||||||
"fat",
|
"fat",
|
||||||
@ -69,17 +69,17 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec
|
|||||||
devoptab_t* devops;
|
devoptab_t* devops;
|
||||||
char* nameCopy;
|
char* nameCopy;
|
||||||
|
|
||||||
|
if(!name || !interface)
|
||||||
|
return false;
|
||||||
|
|
||||||
if(!interface->startup())
|
if(!interface->startup())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!interface->isInserted()) {
|
if(!interface->isInserted())
|
||||||
interface->shutdown();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1);
|
devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1);
|
||||||
if (!devops) {
|
if (!devops) {
|
||||||
interface->shutdown();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Use the space allocated at the end of the devoptab struct for storing the name
|
// Use the space allocated at the end of the devoptab struct for storing the name
|
||||||
@ -89,7 +89,6 @@ bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSec
|
|||||||
partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector);
|
partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector);
|
||||||
if (!partition) {
|
if (!partition) {
|
||||||
_FAT_mem_free (devops);
|
_FAT_mem_free (devops);
|
||||||
interface->shutdown();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +110,9 @@ bool fatMountSimple (const char* name, const DISC_INTERFACE* interface) {
|
|||||||
void fatUnmount (const char* name) {
|
void fatUnmount (const char* name) {
|
||||||
devoptab_t *devops;
|
devoptab_t *devops;
|
||||||
PARTITION* partition;
|
PARTITION* partition;
|
||||||
const DISC_INTERFACE *disc;
|
|
||||||
|
if(!name)
|
||||||
|
return;
|
||||||
|
|
||||||
devops = (devoptab_t*)GetDeviceOpTab (name);
|
devops = (devoptab_t*)GetDeviceOpTab (name);
|
||||||
if (!devops) {
|
if (!devops) {
|
||||||
@ -128,10 +129,8 @@ void fatUnmount (const char* name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
partition = (PARTITION*)devops->deviceData;
|
partition = (PARTITION*)devops->deviceData;
|
||||||
disc = partition->disc;
|
|
||||||
_FAT_partition_destructor (partition);
|
_FAT_partition_destructor (partition);
|
||||||
_FAT_mem_free (devops);
|
_FAT_mem_free (devops);
|
||||||
disc->shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) {
|
bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) {
|
||||||
@ -194,4 +193,49 @@ bool fatInitDefault (void) {
|
|||||||
return fatInit (DEFAULT_CACHE_PAGES, true);
|
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)) {
|
||||||
|
free(buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
10
source/libfat/libfatversion.h
Normal file
10
source/libfat/libfatversion.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __LIBFATVERSION_H__
|
||||||
|
#define __LIBFATVERSION_H__
|
||||||
|
|
||||||
|
#define _LIBFAT_MAJOR_ 1
|
||||||
|
#define _LIBFAT_MINOR_ 0
|
||||||
|
#define _LIBFAT_PATCH_ 7
|
||||||
|
|
||||||
|
#define _LIBFAT_STRING "libFAT Release 1.0.7"
|
||||||
|
|
||||||
|
#endif // __LIBFATVERSION_H__
|
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LOCK_H
|
#ifndef _LOCK_H
|
||||||
#define __LOCK_H
|
#define _LOCK_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MEM_ALLOCATE_H_
|
#ifndef _MEM_ALLOCATE_H
|
||||||
#define __MEM_ALLOCATE_H_
|
#define _MEM_ALLOCATE_H
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
@ -38,7 +38,6 @@ static inline void* _FAT_mem_allocate (size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void* _FAT_mem_align (size_t size) {
|
static inline void* _FAT_mem_align (size_t size) {
|
||||||
|
|
||||||
return memalign (32, size);
|
return memalign (32, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,11 +205,17 @@ PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cach
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_FAT_startSector = startSector;
|
|
||||||
|
|
||||||
// Init the partition lock
|
// Init the partition lock
|
||||||
_FAT_lock_init(&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
|
// Set partition's disc interface
|
||||||
partition->disc = disc;
|
partition->disc = disc;
|
||||||
|
|
||||||
|
@ -27,11 +27,11 @@
|
|||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PARTITION_H
|
#ifndef _PARTITION_H
|
||||||
#define __PARTITION_H
|
#define _PARTITION_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fat_cache.h"
|
#include "cache.h"
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
|
|
||||||
// Device name
|
// Device name
|
||||||
@ -67,6 +67,7 @@ typedef struct {
|
|||||||
struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files
|
struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files
|
||||||
mutex_t lock; // A lock for partition operations
|
mutex_t lock; // A lock for partition operations
|
||||||
bool readOnly; // If this is set, then do not try writing to the disc
|
bool readOnly; // If this is set, then do not try writing to the disc
|
||||||
|
char label[12]; // Volume label
|
||||||
} PARTITION;
|
} PARTITION;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -563,7 +563,8 @@ static BOOL valid_acl(const ACL *pacl, unsigned int end)
|
|||||||
&((const char*)pacl)[offace];
|
&((const char*)pacl)[offace];
|
||||||
acesz = le16_to_cpu(pace->size);
|
acesz = le16_to_cpu(pace->size);
|
||||||
if (((offace + acesz) > end)
|
if (((offace + acesz) > end)
|
||||||
|| !ntfs_valid_sid(&pace->sid))
|
|| !ntfs_valid_sid(&pace->sid)
|
||||||
|
|| ((ntfs_sid_size(&pace->sid) + 8) != (int)acesz))
|
||||||
ok = FALSE;
|
ok = FALSE;
|
||||||
offace += acesz;
|
offace += acesz;
|
||||||
}
|
}
|
||||||
@ -614,7 +615,6 @@ BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz)
|
|||||||
* old revision and no DACL though SE_DACL_PRESENT is set
|
* old revision and no DACL though SE_DACL_PRESENT is set
|
||||||
*/
|
*/
|
||||||
if ((attrsz >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
if ((attrsz >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
||||||
&& (ntfs_attr_size(securattr) <= attrsz)
|
|
||||||
&& (phead->revision == SECURITY_DESCRIPTOR_REVISION)
|
&& (phead->revision == SECURITY_DESCRIPTOR_REVISION)
|
||||||
&& (offowner >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
&& (offowner >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
||||||
&& ((offowner + 2) < attrsz)
|
&& ((offowner + 2) < attrsz)
|
||||||
@ -622,14 +622,15 @@ BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz)
|
|||||||
&& ((offgroup + 2) < attrsz)
|
&& ((offgroup + 2) < attrsz)
|
||||||
&& (!offdacl
|
&& (!offdacl
|
||||||
|| ((offdacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
|| ((offdacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
||||||
&& (offdacl < attrsz)))
|
&& (offdacl+sizeof(ACL) < attrsz)))
|
||||||
&& (!offsacl
|
&& (!offsacl
|
||||||
|| ((offsacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
|| ((offsacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
|
||||||
&& (offsacl < attrsz)))
|
&& (offsacl+sizeof(ACL) < attrsz)))
|
||||||
&& !(phead->owner & const_cpu_to_le32(3))
|
&& !(phead->owner & const_cpu_to_le32(3))
|
||||||
&& !(phead->group & const_cpu_to_le32(3))
|
&& !(phead->group & const_cpu_to_le32(3))
|
||||||
&& !(phead->dacl & const_cpu_to_le32(3))
|
&& !(phead->dacl & const_cpu_to_le32(3))
|
||||||
&& !(phead->sacl & 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[offowner])
|
||||||
&& ntfs_valid_sid((const SID*)&securattr[offgroup])
|
&& ntfs_valid_sid((const SID*)&securattr[offgroup])
|
||||||
/*
|
/*
|
||||||
@ -707,10 +708,12 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl,
|
|||||||
if (ntfs_same_sid(&pnewace->sid, ownersid)) {
|
if (ntfs_same_sid(&pnewace->sid, ownersid)) {
|
||||||
memcpy(&pnewace->sid, usid, usidsz);
|
memcpy(&pnewace->sid, usid, usidsz);
|
||||||
acesz = usidsz + 8;
|
acesz = usidsz + 8;
|
||||||
|
pnewace->size = cpu_to_le16(acesz);
|
||||||
}
|
}
|
||||||
if (ntfs_same_sid(&pnewace->sid, groupsid)) {
|
if (ntfs_same_sid(&pnewace->sid, groupsid)) {
|
||||||
memcpy(&pnewace->sid, gsid, gsidsz);
|
memcpy(&pnewace->sid, gsid, gsidsz);
|
||||||
acesz = gsidsz + 8;
|
acesz = gsidsz + 8;
|
||||||
|
pnewace->size = cpu_to_le16(acesz);
|
||||||
}
|
}
|
||||||
if (pnewace->mask & GENERIC_ALL) {
|
if (pnewace->mask & GENERIC_ALL) {
|
||||||
pnewace->mask &= ~GENERIC_ALL;
|
pnewace->mask &= ~GENERIC_ALL;
|
||||||
@ -2985,8 +2988,10 @@ static int build_std_permissions(const char *securattr,
|
|||||||
if (offdacl) {
|
if (offdacl) {
|
||||||
acecnt = le16_to_cpu(pacl->ace_count);
|
acecnt = le16_to_cpu(pacl->ace_count);
|
||||||
offace = offdacl + sizeof(ACL);
|
offace = offdacl + sizeof(ACL);
|
||||||
} else
|
} else {
|
||||||
acecnt = 0;
|
acecnt = 0;
|
||||||
|
offace = 0;
|
||||||
|
}
|
||||||
for (nace = 0; nace < acecnt; nace++) {
|
for (nace = 0; nace < acecnt; nace++) {
|
||||||
pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace];
|
pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace];
|
||||||
if (!(pace->flags & INHERIT_ONLY_ACE)) {
|
if (!(pace->flags & INHERIT_ONLY_ACE)) {
|
||||||
@ -3255,8 +3260,10 @@ static int build_ownadmin_permissions(const char *securattr,
|
|||||||
if (offdacl) {
|
if (offdacl) {
|
||||||
acecnt = le16_to_cpu(pacl->ace_count);
|
acecnt = le16_to_cpu(pacl->ace_count);
|
||||||
offace = offdacl + sizeof(ACL);
|
offace = offdacl + sizeof(ACL);
|
||||||
} else
|
} else {
|
||||||
acecnt = 0;
|
acecnt = 0;
|
||||||
|
offace = 0;
|
||||||
|
}
|
||||||
firstapply = TRUE;
|
firstapply = TRUE;
|
||||||
isforeign = 3;
|
isforeign = 3;
|
||||||
for (nace = 0; nace < acecnt; nace++) {
|
for (nace = 0; nace < acecnt; nace++) {
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
* should be moved to some config file
|
* should be moved to some config file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FORCE_FORMAT_v1x 0 /* Insert security data as in NTFS v1.x */
|
|
||||||
#define OWNERFROMACL 1 /* Get the owner from ACL (not Windows owner) */
|
|
||||||
#define BUFSZ 1024 /* buffer size to read mapping file */
|
#define BUFSZ 1024 /* buffer size to read mapping file */
|
||||||
#define MAPPINGFILE ".NTFS-3G/UserMapping" /* default mapping file */
|
#define MAPPINGFILE ".NTFS-3G/UserMapping" /* default mapping file */
|
||||||
#define LINESZ 120 /* maximum useful size of a mapping line */
|
#define LINESZ 120 /* maximum useful size of a mapping line */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -189,6 +189,7 @@ struct _ntfs_attr {
|
|||||||
u32 compression_block_size;
|
u32 compression_block_size;
|
||||||
u8 compression_block_size_bits;
|
u8 compression_block_size_bits;
|
||||||
u8 compression_block_clusters;
|
u8 compression_block_clusters;
|
||||||
|
s8 unused_runs; /* pre-reserved entries available */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,6 +199,9 @@ struct _ntfs_attr {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
NA_Initialized, /* 1: structure is initialized. */
|
NA_Initialized, /* 1: structure is initialized. */
|
||||||
NA_NonResident, /* 1: Attribute is not resident. */
|
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;
|
} ntfs_attr_state_bits;
|
||||||
|
|
||||||
#define test_nattr_flag(na, flag) test_bit(NA_##flag, (na)->state)
|
#define test_nattr_flag(na, flag) test_bit(NA_##flag, (na)->state)
|
||||||
@ -212,6 +216,18 @@ typedef enum {
|
|||||||
#define NAttrSetNonResident(na) set_nattr_flag(na, NonResident)
|
#define NAttrSetNonResident(na) set_nattr_flag(na, NonResident)
|
||||||
#define NAttrClearNonResident(na) clear_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) \
|
#define GenNAttrIno(func_name, flag) \
|
||||||
extern int NAttr##func_name(ntfs_attr *na); \
|
extern int NAttr##func_name(ntfs_attr *na); \
|
||||||
extern void NAttrSet##func_name(ntfs_attr *na); \
|
extern void NAttrSet##func_name(ntfs_attr *na); \
|
||||||
@ -288,6 +304,7 @@ extern int ntfs_attr_can_be_resident(const ntfs_volume *vol,
|
|||||||
const ATTR_TYPES type);
|
const ATTR_TYPES type);
|
||||||
int ntfs_attr_make_non_resident(ntfs_attr *na,
|
int ntfs_attr_make_non_resident(ntfs_attr *na,
|
||||||
ntfs_attr_search_ctx *ctx);
|
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_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size);
|
||||||
|
|
||||||
extern int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
|
extern int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
|
||||||
|
@ -818,7 +818,7 @@ static s64 ntfs_attr_getfragments_i(ntfs_attr *na, const s64 pos, s64 count, u64
|
|||||||
s64 br, to_read, ofs, total, total2, max_read, max_init;
|
s64 br, to_read, ofs, total, total2, max_read, max_init;
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
runlist_element *rl;
|
runlist_element *rl;
|
||||||
// u16 efs_padding_length;
|
//u16 efs_padding_length;
|
||||||
|
|
||||||
/* Sanity checking arguments is done in ntfs_attr_pread(). */
|
/* Sanity checking arguments is done in ntfs_attr_pread(). */
|
||||||
|
|
||||||
|
@ -1,378 +1,609 @@
|
|||||||
/*
|
/**
|
||||||
cache.c
|
* cache.c : deal with LRU caches
|
||||||
The cache is not visible to the user. It should be flushed
|
*
|
||||||
when any file is closed or changes are made to the filesystem.
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
This cache implements a least-used-page replacement policy. This will
|
#ifdef HAVE_CONFIG_H
|
||||||
distribute sectors evenly over the pages, so if less than the maximum
|
#include "config.h"
|
||||||
pages are used at once, they should all eventually remain in the cache.
|
#endif
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#endif
|
||||||
|
|
||||||
//#include "common.h"
|
#include "types.h"
|
||||||
|
#include "security.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "bit_ops.h"
|
#include "misc.h"
|
||||||
//#include "disc.h"
|
#include "logging.h"
|
||||||
|
|
||||||
#include "mem_allocate.h"
|
/*
|
||||||
#include <ogc/lwp_watchdog.h>
|
* General functions to deal with LRU caches
|
||||||
//#include "bit_ops.h"
|
*
|
||||||
//#include "file_allocation_table.h"
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
#define CACHE_FREE UINT_MAX
|
/*
|
||||||
|
* 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)
|
||||||
|
*/
|
||||||
|
|
||||||
NTFS_CACHE* _NTFS_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition) {
|
static void inserthashindex(struct CACHE_HEADER *cache,
|
||||||
NTFS_CACHE* cache;
|
struct CACHED_GENERIC *current)
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
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 * BYTES_PER_READ );
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
int h;
|
||||||
NTFS_CACHE_ENTRY* cacheEntries = cache->cacheEntries;
|
struct HASH_ENTRY *link;
|
||||||
unsigned int numberOfPages = cache->numberOfPages;
|
struct HASH_ENTRY *first;
|
||||||
unsigned int sectorsPerPage = cache->sectorsPerPage;
|
|
||||||
|
|
||||||
bool foundFree = false;
|
if (cache->dohash) {
|
||||||
unsigned int oldUsed = 0;
|
h = cache->dohash(current);
|
||||||
unsigned int oldAccess = UINT_MAX;
|
if ((h >= 0) && (h < cache->max_hash)) {
|
||||||
|
/* get a free link and insert at top of hash list */
|
||||||
for(i=0;i<numberOfPages;i++) {
|
link = cache->free_hash;
|
||||||
if(sector>=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) {
|
if (link) {
|
||||||
cacheEntries[i].last_access = accessTime();
|
cache->free_hash = link->next;
|
||||||
return &(cacheEntries[i]);
|
first = cache->first_hash[h];
|
||||||
}
|
if (first)
|
||||||
|
link->next = first;
|
||||||
if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_access<oldAccess)) {
|
else
|
||||||
if(cacheEntries[i].sector==CACHE_FREE) foundFree = true;
|
link->next = NULL;
|
||||||
oldUsed = i;
|
link->entry = current;
|
||||||
oldAccess = cacheEntries[i].last_access;
|
cache->first_hash[h] = link;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(foundFree==false && cacheEntries[oldUsed].dirty==true) {
|
|
||||||
if(!cache->disc->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<numberOfPages;i++) {
|
|
||||||
if (cacheEntries[i].sector != CACHE_FREE) {
|
|
||||||
bool intersect;
|
|
||||||
if (sector > cacheEntries[i].sector) {
|
|
||||||
intersect = sector - cacheEntries[i].sector < cacheEntries[i].count;
|
|
||||||
} else {
|
} else {
|
||||||
intersect = cacheEntries[i].sector - sector < count;
|
ntfs_log_error("No more hash entries,"
|
||||||
|
" cache %s hashing dropped\n",
|
||||||
|
cache->name);
|
||||||
|
cache->dohash = (cache_hash)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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*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 _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 > BYTES_PER_READ) return false;
|
|
||||||
|
|
||||||
entry = _NTFS_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 _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 > BYTES_PER_READ) return false;
|
|
||||||
|
|
||||||
entry = _NTFS_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 _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 > BYTES_PER_READ) return false;
|
|
||||||
|
|
||||||
entry = _NTFS_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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*BYTES_PER_READ);
|
|
||||||
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*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;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cache->disc->writeSectors(sector,numSectors,src);
|
ntfs_log_error("Illegal hash value,"
|
||||||
numSectors=0;
|
" cache %s hashing dropped\n",
|
||||||
|
cache->name);
|
||||||
|
cache->dohash = (cache_hash)NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Flushes all dirty pages to disc, clearing the dirty flag.
|
* Drop a hash index when a record is about to be deleted
|
||||||
*/
|
*/
|
||||||
bool _NTFS_cache_flush (NTFS_CACHE* cache) {
|
|
||||||
unsigned int i;
|
|
||||||
if(cache==NULL) return true;
|
|
||||||
|
|
||||||
for (i = 0; i < cache->numberOfPages; i++) {
|
static void drophashindex(struct CACHE_HEADER *cache,
|
||||||
if (cache->cacheEntries[i].dirty) {
|
const struct CACHED_GENERIC *current, int hash)
|
||||||
if (!cache->disc->writeSectors (cache->cacheEntries[i].sector, cache->cacheEntries[i].count, cache->cacheEntries[i].cache)) {
|
{
|
||||||
return false;
|
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->cacheEntries[i].dirty = false;
|
cache->reads++;
|
||||||
}
|
}
|
||||||
|
return (current);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _NTFS_cache_invalidate (NTFS_CACHE* cache) {
|
/*
|
||||||
unsigned int i;
|
* Enter an inode number into cache
|
||||||
if(cache==NULL)
|
* returns the cache entry or NULL if not possible
|
||||||
return;
|
*/
|
||||||
|
|
||||||
_NTFS_cache_flush(cache);
|
struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
|
||||||
for (i = 0; i < cache->numberOfPages; i++) {
|
const struct CACHED_GENERIC *item,
|
||||||
cache->cacheEntries[i].sector = CACHE_FREE;
|
cache_compare compare)
|
||||||
cache->cacheEntries[i].last_access = 0;
|
{
|
||||||
cache->cacheEntries[i].count = 0;
|
struct CACHED_GENERIC *current;
|
||||||
cache->cacheEntries[i].dirty = false;
|
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; i<max_hash; i++)
|
||||||
|
px[i] = (struct HASH_ENTRY*)NULL;
|
||||||
|
} else {
|
||||||
|
cache->free_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
|
||||||
|
}
|
||||||
|
@ -1,136 +1,119 @@
|
|||||||
/*
|
/*
|
||||||
NTFS_CACHE.h
|
* cache.h : deal with indexed LRU caches
|
||||||
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.
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
This NTFS_CACHE implements a least-used-page replacement policy. This will
|
#ifndef _NTFS_CACHE_H_
|
||||||
distribute sectors evenly over the pages, so if less than the maximum
|
#define _NTFS_CACHE_H_
|
||||||
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
|
#include "volume.h"
|
||||||
Copyright (c) 2009 shareese, rodries
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
struct CACHED_GENERIC {
|
||||||
are permitted provided that the following conditions are met:
|
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];
|
||||||
|
} ;
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
struct CACHED_INODE {
|
||||||
this list of conditions and the following disclaimer.
|
struct CACHED_INODE *next;
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
struct CACHED_INODE *previous;
|
||||||
this list of conditions and the following disclaimer in the documentation and/or
|
const char *pathname;
|
||||||
other materials provided with the distribution.
|
size_t varsize;
|
||||||
3. The name of the author may not be used to endorse or promote products derived
|
/* above fields must match "struct CACHED_GENERIC" */
|
||||||
from this software without specific prior written permission.
|
u64 inum;
|
||||||
|
} ;
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
struct CACHED_NIDATA {
|
||||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
struct CACHED_NIDATA *next;
|
||||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
|
struct CACHED_NIDATA *previous;
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
const char *pathname; /* not used */
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
size_t varsize; /* not used */
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
/* above fields must match "struct CACHED_GENERIC" */
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
u64 inum;
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
ntfs_inode *ni;
|
||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
} ;
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _CACHE_H
|
struct CACHED_LOOKUP {
|
||||||
#define _CACHE_H
|
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;
|
||||||
|
} ;
|
||||||
|
|
||||||
//#include "common.h"
|
enum {
|
||||||
//#include "disc.h"
|
CACHE_FREE = 1,
|
||||||
|
CACHE_NOHASH = 2
|
||||||
|
} ;
|
||||||
|
|
||||||
#include <stddef.h>
|
typedef int (*cache_compare)(const struct CACHED_GENERIC *cached,
|
||||||
#include <stdint.h>
|
const struct CACHED_GENERIC *item);
|
||||||
#include <gctypes.h>
|
typedef void (*cache_free)(const struct CACHED_GENERIC *cached);
|
||||||
#include <ogc/disc_io.h>
|
typedef int (*cache_hash)(const struct CACHED_GENERIC *cached);
|
||||||
#include <gccore.h>
|
|
||||||
|
|
||||||
#define BYTES_PER_READ 512
|
struct HASH_ENTRY {
|
||||||
|
struct HASH_ENTRY *next;
|
||||||
|
struct CACHED_GENERIC *entry;
|
||||||
|
} ;
|
||||||
|
|
||||||
typedef struct {
|
struct CACHE_HEADER {
|
||||||
sec_t sector;
|
const char *name;
|
||||||
unsigned int count;
|
struct CACHED_GENERIC *most_recent_entry;
|
||||||
u64 last_access;
|
struct CACHED_GENERIC *oldest_entry;
|
||||||
bool dirty;
|
struct CACHED_GENERIC *free_entry;
|
||||||
u8* cache;
|
struct HASH_ENTRY *free_hash;
|
||||||
} NTFS_CACHE_ENTRY;
|
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];
|
||||||
|
} ;
|
||||||
|
|
||||||
typedef struct {
|
/* cast to generic, avoiding gcc warnings */
|
||||||
const DISC_INTERFACE* disc;
|
#define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr))
|
||||||
sec_t endOfPartition;
|
|
||||||
unsigned int numberOfPages;
|
|
||||||
unsigned int sectorsPerPage;
|
|
||||||
NTFS_CACHE_ENTRY* cacheEntries;
|
|
||||||
} NTFS_CACHE;
|
|
||||||
|
|
||||||
/*
|
struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache,
|
||||||
Read data from a sector in the NTFS_CACHE
|
const struct CACHED_GENERIC *wanted,
|
||||||
If the sector is not in the NTFS_CACHE, it will be swapped in
|
cache_compare compare);
|
||||||
offset is the position to start reading from
|
struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
|
||||||
size is the amount of data to read
|
const struct CACHED_GENERIC *item,
|
||||||
Precondition: offset + size <= BYTES_PER_READ
|
cache_compare compare);
|
||||||
*/
|
int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
|
||||||
//bool _NTFS_cache_readPartialSector (NTFS_CACHE* NTFS_CACHE, void* buffer, sec_t sector, unsigned int offset, size_t size);
|
const struct CACHED_GENERIC *item,
|
||||||
|
cache_compare compare, int flags);
|
||||||
|
int ntfs_remove_cache(struct CACHE_HEADER *cache,
|
||||||
|
struct CACHED_GENERIC *item, int flags);
|
||||||
|
|
||||||
//bool _NTFS_cache_readLittleEndianValue (NTFS_CACHE* NTFS_CACHE, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes);
|
void ntfs_create_lru_caches(ntfs_volume *vol);
|
||||||
|
void ntfs_free_lru_caches(ntfs_volume *vol);
|
||||||
|
|
||||||
/*
|
#endif /* _NTFS_CACHE_H_ */
|
||||||
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);
|
|
||||||
|
|
||||||
void _NTFS_cache_destructor (NTFS_CACHE* NTFS_CACHE);
|
|
||||||
|
|
||||||
#endif // _CACHE_H
|
|
||||||
|
|
||||||
|
374
source/libntfs/cache2.c
Normal file
374
source/libntfs/cache2.c
Normal file
@ -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 <ogc/lwp_watchdog.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#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<numberOfPages;i++) {
|
||||||
|
if(sector>=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_access<oldAccess)) {
|
||||||
|
if(cacheEntries[i].sector==CACHE_FREE) foundFree = true;
|
||||||
|
oldUsed = i;
|
||||||
|
oldAccess = cacheEntries[i].last_access;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(foundFree==false && cacheEntries[oldUsed].dirty==true) {
|
||||||
|
if(!cache->disc->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<numberOfPages;i++) {
|
||||||
|
if (cacheEntries[i].sector != CACHE_FREE) {
|
||||||
|
bool intersect;
|
||||||
|
if (sector > 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;
|
||||||
|
}
|
||||||
|
}
|
135
source/libntfs/cache2.h
Normal file
135
source/libntfs/cache2.h
Normal file
@ -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 <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <gctypes.h>
|
||||||
|
#include <ogc/disc_io.h>
|
||||||
|
#include <gccore.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -23,32 +23,23 @@
|
|||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_STRING_H
|
#ifdef HAVE_STRING_H
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_ERRNO_H
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "attrib.h"
|
||||||
|
#include "index.h"
|
||||||
#include "collate.h"
|
#include "collate.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "unistr.h"
|
#include "unistr.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
BOOL ntfs_is_collation_rule_supported(COLLATION_RULES cr)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* FIXME: At the moment we only support COLLATION_BINARY,
|
|
||||||
* COLLATION_NTOFS_ULONG and COLLATION_FILE_NAME so we return false
|
|
||||||
* for everything else.
|
|
||||||
* JPA added COLLATION_NTOFS_SECURITY_HASH
|
|
||||||
*/
|
|
||||||
if (cr != COLLATION_BINARY && cr != COLLATION_NTOFS_ULONG
|
|
||||||
&& cr != COLLATION_FILE_NAME
|
|
||||||
&& cr != COLLATION_NTOFS_SECURITY_HASH
|
|
||||||
&& cr != COLLATION_NTOFS_ULONGS)
|
|
||||||
return FALSE;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ntfs_collate_binary - Which of two binary objects should be listed first
|
* ntfs_collate_binary - Which of two binary objects should be listed first
|
||||||
* @vol: unused
|
* @vol: unused
|
||||||
@ -177,15 +168,15 @@ static int ntfs_collate_ntofs_security_hash(ntfs_volume *vol __attribute__((unus
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
u32 d1, d2;
|
u32 d1, d2;
|
||||||
const u32 *p1, *p2;
|
const le32 *p1, *p2;
|
||||||
|
|
||||||
ntfs_log_trace("Entering.\n");
|
ntfs_log_trace("Entering.\n");
|
||||||
if (data1_len != data2_len || data1_len != 8) {
|
if (data1_len != data2_len || data1_len != 8) {
|
||||||
ntfs_log_error("data1_len or/and data2_len not equal to 8.\n");
|
ntfs_log_error("data1_len or/and data2_len not equal to 8.\n");
|
||||||
return NTFS_COLLATION_ERROR;
|
return NTFS_COLLATION_ERROR;
|
||||||
}
|
}
|
||||||
p1 = (const u32*)data1;
|
p1 = (const le32*)data1;
|
||||||
p2 = (const u32*)data2;
|
p2 = (const le32*)data2;
|
||||||
d1 = le32_to_cpup(p1);
|
d1 = le32_to_cpup(p1);
|
||||||
d2 = le32_to_cpup(p2);
|
d2 = le32_to_cpup(p2);
|
||||||
if (d1 < d2)
|
if (d1 < d2)
|
||||||
@ -228,89 +219,53 @@ static int ntfs_collate_file_name(ntfs_volume *vol,
|
|||||||
const void *data1, const int data1_len __attribute__((unused)),
|
const void *data1, const int data1_len __attribute__((unused)),
|
||||||
const void *data2, const int data2_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;
|
int rc;
|
||||||
|
|
||||||
ntfs_log_trace("Entering.\n");
|
ntfs_log_trace("Entering.\n");
|
||||||
rc = ntfs_file_values_compare(data1, data2, NTFS_COLLATION_ERROR,
|
file_name_attr1 = (const FILE_NAME_ATTR*)data1;
|
||||||
IGNORE_CASE, vol->upcase, vol->upcase_len);
|
file_name_attr2 = (const FILE_NAME_ATTR*)data2;
|
||||||
if (!rc)
|
rc = ntfs_names_full_collate(
|
||||||
rc = ntfs_file_values_compare(data1, data2,
|
(ntfschar*)&file_name_attr1->file_name,
|
||||||
NTFS_COLLATION_ERROR, CASE_SENSITIVE,
|
file_name_attr1->file_name_length,
|
||||||
vol->upcase, vol->upcase_len);
|
(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);
|
ntfs_log_trace("Done, returning %i.\n", rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*ntfs_collate_func_t)(ntfs_volume *, const void *, const int,
|
/*
|
||||||
const void *, const int);
|
* Get a pointer to appropriate collation function.
|
||||||
|
|
||||||
static ntfs_collate_func_t ntfs_do_collate0x0[3] = {
|
|
||||||
ntfs_collate_binary,
|
|
||||||
ntfs_collate_file_name,
|
|
||||||
NULL/*ntfs_collate_unicode_string*/,
|
|
||||||
};
|
|
||||||
|
|
||||||
static ntfs_collate_func_t ntfs_do_collate0x1[4] = {
|
|
||||||
ntfs_collate_ntofs_ulong,
|
|
||||||
NULL/*ntfs_collate_ntofs_sid*/,
|
|
||||||
ntfs_collate_ntofs_security_hash,
|
|
||||||
ntfs_collate_ntofs_ulongs
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ntfs_collate - collate two data items using a specified collation rule
|
|
||||||
* @vol: ntfs volume to which the data items belong
|
|
||||||
* @cr: collation rule to use when comparing the items
|
|
||||||
* @data1: first data item to collate
|
|
||||||
* @data1_len: length in bytes of @data1
|
|
||||||
* @data2: second data item to collate
|
|
||||||
* @data2_len: length in bytes of @data2
|
|
||||||
*
|
*
|
||||||
* Collate the two data items @data1 and @data2 using the collation rule @cr
|
* Returns NULL if the needed function is not implemented
|
||||||
* and return -1, 0, or 1 if @data1 is found, respectively, to collate before,
|
|
||||||
* to match, or to collate after @data2.
|
|
||||||
*
|
|
||||||
* For speed we use the collation rule @cr as an index into two tables of
|
|
||||||
* function pointers to call the appropriate collation function.
|
|
||||||
*
|
|
||||||
* Return NTFS_COLLATION_ERROR if error occurred.
|
|
||||||
*/
|
*/
|
||||||
int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr,
|
|
||||||
const void *data1, const int data1_len,
|
|
||||||
const void *data2, const int data2_len)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
ntfs_log_trace("Entering.\n");
|
COLLATE ntfs_get_collate_function(COLLATION_RULES cr)
|
||||||
if (!vol || !data1 || !data2 || data1_len < 0 || data2_len < 0) {
|
{
|
||||||
ntfs_log_error("Invalid arguments passed.\n");
|
COLLATE collate;
|
||||||
return NTFS_COLLATION_ERROR;
|
|
||||||
|
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);
|
||||||
* FIXME: At the moment we only support COLLATION_BINARY,
|
|
||||||
* COLLATION_NTOFS_ULONG and COLLATION_FILE_NAME so we return error
|
|
||||||
* for everything else.
|
|
||||||
* JPA added COLLATION_NTOFS_SECURITY_HASH
|
|
||||||
* JPA added COLLATION_NTOFS_ULONGS
|
|
||||||
*/
|
|
||||||
if (cr != COLLATION_BINARY && cr != COLLATION_NTOFS_ULONG
|
|
||||||
&& cr != COLLATION_FILE_NAME
|
|
||||||
&& cr != COLLATION_NTOFS_SECURITY_HASH
|
|
||||||
&& cr != COLLATION_NTOFS_ULONGS)
|
|
||||||
goto err;
|
|
||||||
i = le32_to_cpu(cr);
|
|
||||||
if (i < 0)
|
|
||||||
goto err;
|
|
||||||
if (i <= 0x02)
|
|
||||||
return ntfs_do_collate0x0[i](vol, data1, data1_len,
|
|
||||||
data2, data2_len);
|
|
||||||
if (i < 0x10)
|
|
||||||
goto err;
|
|
||||||
i -= 0x10;
|
|
||||||
if (i <= 3)
|
|
||||||
return ntfs_do_collate0x1[i](vol, data1, data1_len,
|
|
||||||
data2, data2_len);
|
|
||||||
err:
|
|
||||||
ntfs_log_debug("Unknown collation rule.\n");
|
|
||||||
return NTFS_COLLATION_ERROR;
|
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,6 @@
|
|||||||
|
|
||||||
#define NTFS_COLLATION_ERROR -2
|
#define NTFS_COLLATION_ERROR -2
|
||||||
|
|
||||||
extern BOOL ntfs_is_collation_rule_supported(COLLATION_RULES cr);
|
extern COLLATE ntfs_get_collate_function(COLLATION_RULES);
|
||||||
extern int ntfs_collate(ntfs_volume *vol, COLLATION_RULES cr,
|
|
||||||
const void *data1, const int data1_len,
|
|
||||||
const void *data2, const int data2_len);
|
|
||||||
|
|
||||||
#endif /* _NTFS_COLLATE_H */
|
#endif /* _NTFS_COLLATE_H */
|
||||||
|
@ -77,7 +77,7 @@ int ffs(int x)
|
|||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static const char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93";
|
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.7 2009/03/27 09:09:59 jpandre Exp $";
|
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 */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -164,7 +164,7 @@ int daemon(int nochdir, int noclose) {
|
|||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static const char sccsid[] = "strsep.c 8.1 (Berkeley) 6/4/93";
|
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.7 2009/03/27 09:09:59 jpandre Exp $";
|
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 */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Copyright (c) 2004-2005 Anton Altaparmakov
|
* Copyright (c) 2004-2005 Anton Altaparmakov
|
||||||
* Copyright (c) 2004-2006 Szabolcs Szakacsits
|
* Copyright (c) 2004-2006 Szabolcs Szakacsits
|
||||||
* Copyright (c) 2005 Yura Pakhuchiy
|
* Copyright (c) 2005 Yura Pakhuchiy
|
||||||
* Copyright (c) 2009 Jean-Pierre Andre
|
* Copyright (c) 2009-2010 Jean-Pierre Andre
|
||||||
*
|
*
|
||||||
* This program/include file is free software; you can redistribute it and/or
|
* This program/include file is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as published
|
* modify it under the terms of the GNU General Public License as published
|
||||||
@ -118,7 +118,7 @@ static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx,
|
|||||||
BOOL done;
|
BOOL done;
|
||||||
const unsigned char *key;
|
const unsigned char *key;
|
||||||
int c;
|
int c;
|
||||||
unsigned int mxi;
|
unsigned long mxi;
|
||||||
unsigned int mxl;
|
unsigned int mxl;
|
||||||
|
|
||||||
mxl = (1 << (16 - pctx->nbt)) + 2;
|
mxl = (1 << (16 - pctx->nbt)) + 2;
|
||||||
@ -147,16 +147,21 @@ static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!done) {
|
if (!done) {
|
||||||
register unsigned int i;
|
register unsigned long i;
|
||||||
register const unsigned char *p1,*p2;
|
register const unsigned char *p1,*p2;
|
||||||
|
|
||||||
i = 1;
|
i = 1;
|
||||||
p1 = key;
|
|
||||||
p2 = &pctx->inbuf[pp];
|
|
||||||
mxi = NTFS_SB_SIZE - r;
|
mxi = NTFS_SB_SIZE - r;
|
||||||
do {
|
if (mxi < 2)
|
||||||
} while ((p1[i] == p2[i]) && (++i < mxi));
|
less = FALSE;
|
||||||
less = (i < mxi) && (p1[i] < p2[i]);
|
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 >= THRESHOLD) {
|
||||||
if (i > pctx->match_length) {
|
if (i > pctx->match_length) {
|
||||||
pctx->match_position =
|
pctx->match_position =
|
||||||
@ -174,7 +179,8 @@ static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx,
|
|||||||
pctx->rson[i] = r;
|
pctx->rson[i] = r;
|
||||||
else
|
else
|
||||||
pctx->lson[i] = r;
|
pctx->lson[i] = r;
|
||||||
pctx->dad[pp] = NIL; /* remove pp */
|
/* remove pp */
|
||||||
|
pctx->dad[pp] = NIL;
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
pctx->match_length = mxl;
|
pctx->match_length = mxl;
|
||||||
}
|
}
|
||||||
@ -196,7 +202,8 @@ static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx,
|
|||||||
* or zero if there was a bug
|
* or zero if there was a bug
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static unsigned int ntfs_nextmatch(struct COMPRESS_CONTEXT *pctx, unsigned int rr, int dd)
|
static unsigned int ntfs_nextmatch(struct COMPRESS_CONTEXT *pctx,
|
||||||
|
unsigned int rr, int dd)
|
||||||
{
|
{
|
||||||
unsigned int bestlen = 0;
|
unsigned int bestlen = 0;
|
||||||
|
|
||||||
@ -214,7 +221,8 @@ static unsigned int ntfs_nextmatch(struct COMPRESS_CONTEXT *pctx, unsigned int r
|
|||||||
goto bug;
|
goto bug;
|
||||||
}
|
}
|
||||||
if (((rr + bestlen) < NTFS_SB_SIZE)) {
|
if (((rr + bestlen) < NTFS_SB_SIZE)) {
|
||||||
while ((unsigned int)(1 << pctx->nbt) <= (rr - 1))
|
while ((unsigned int)(1 << pctx->nbt)
|
||||||
|
<= (rr - 1))
|
||||||
pctx->nbt++;
|
pctx->nbt++;
|
||||||
ntfs_new_node(pctx,rr);
|
ntfs_new_node(pctx,rr);
|
||||||
if (pctx->match_length > bestlen)
|
if (pctx->match_length > bestlen)
|
||||||
@ -247,7 +255,8 @@ bug :
|
|||||||
* or zero if there was an error
|
* or zero if there was an error
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static unsigned int ntfs_compress_block(const char *inbuf, unsigned int size, char *outbuf)
|
static unsigned int ntfs_compress_block(const char *inbuf,
|
||||||
|
unsigned int size, char *outbuf)
|
||||||
{
|
{
|
||||||
struct COMPRESS_CONTEXT *pctx;
|
struct COMPRESS_CONTEXT *pctx;
|
||||||
char *ptag;
|
char *ptag;
|
||||||
@ -284,7 +293,8 @@ static unsigned int ntfs_compress_block(const char *inbuf, unsigned int size, ch
|
|||||||
outbuf[xout++] = inbuf[rr];
|
outbuf[xout++] = inbuf[rr];
|
||||||
ntag++;
|
ntag++;
|
||||||
} else {
|
} else {
|
||||||
while ((unsigned int)(1 << pctx->nbt) <= (rr - 1))
|
while ((unsigned int)(1 << pctx->nbt)
|
||||||
|
<= (rr - 1))
|
||||||
pctx->nbt++;
|
pctx->nbt++;
|
||||||
q = (pctx->match_position << (16 - pctx->nbt))
|
q = (pctx->match_position << (16 - pctx->nbt))
|
||||||
+ pctx->match_length - THRESHOLD;
|
+ pctx->match_length - THRESHOLD;
|
||||||
@ -732,7 +742,15 @@ do_next_cb:
|
|||||||
na->data_size = na->initialized_size = na->allocated_size;
|
na->data_size = na->initialized_size = na->allocated_size;
|
||||||
do {
|
do {
|
||||||
br = ntfs_attr_pread(na, ofs, to_read, b);
|
br = ntfs_attr_pread(na, ofs, to_read, b);
|
||||||
if (br < 0) {
|
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;
|
err = errno;
|
||||||
na->data_size = tdata_size;
|
na->data_size = tdata_size;
|
||||||
na->initialized_size = tinitialized_size;
|
na->initialized_size = tinitialized_size;
|
||||||
@ -783,7 +801,15 @@ do_next_cb:
|
|||||||
br = ntfs_attr_pread(na,
|
br = ntfs_attr_pread(na,
|
||||||
(vcn << vol->cluster_size_bits) +
|
(vcn << vol->cluster_size_bits) +
|
||||||
(cb_pos - cb), to_read, cb_pos);
|
(cb_pos - cb), to_read, cb_pos);
|
||||||
if (br < 0) {
|
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;
|
err = errno;
|
||||||
na->data_size = tdata_size;
|
na->data_size = tdata_size;
|
||||||
na->initialized_size = tinitialized_size;
|
na->initialized_size = tinitialized_size;
|
||||||
@ -881,11 +907,11 @@ static u32 read_clusters(ntfs_volume *vol, const runlist_element *rl,
|
|||||||
* Returns the amount of data written
|
* Returns the amount of data written
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int write_clusters(ntfs_volume *vol, const runlist_element *rl,
|
static s32 write_clusters(ntfs_volume *vol, const runlist_element *rl,
|
||||||
s64 offs, int to_write, const char *outbuf)
|
s64 offs, s32 to_write, const char *outbuf)
|
||||||
{
|
{
|
||||||
int count;
|
s32 count;
|
||||||
int put, xput;
|
s32 put, xput;
|
||||||
s64 xpos;
|
s64 xpos;
|
||||||
BOOL first;
|
BOOL first;
|
||||||
const char *xoutbuf;
|
const char *xoutbuf;
|
||||||
@ -926,17 +952,17 @@ static int write_clusters(ntfs_volume *vol, const runlist_element *rl,
|
|||||||
* or -2 if there were an irrecoverable error (errno set)
|
* or -2 if there were an irrecoverable error (errno set)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int ntfs_comp_set(ntfs_attr *na, runlist_element *rl,
|
static s32 ntfs_comp_set(ntfs_attr *na, runlist_element *rl,
|
||||||
s64 offs, unsigned int insz, const char *inbuf)
|
s64 offs, u32 insz, const char *inbuf)
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
char *outbuf;
|
char *outbuf;
|
||||||
char *pbuf;
|
char *pbuf;
|
||||||
unsigned int compsz;
|
u32 compsz;
|
||||||
int written;
|
s32 written;
|
||||||
int rounded;
|
s32 rounded;
|
||||||
unsigned int clsz;
|
unsigned int clsz;
|
||||||
unsigned int p;
|
u32 p;
|
||||||
unsigned int sz;
|
unsigned int sz;
|
||||||
unsigned int bsz;
|
unsigned int bsz;
|
||||||
BOOL fail;
|
BOOL fail;
|
||||||
@ -1002,7 +1028,10 @@ static int ntfs_comp_set(ntfs_attr *na, runlist_element *rl,
|
|||||||
rounded = ((compsz - 1) | (clsz - 1)) + 1;
|
rounded = ((compsz - 1) | (clsz - 1)) + 1;
|
||||||
written = write_clusters(vol, rl, offs, rounded, outbuf);
|
written = write_clusters(vol, rl, offs, rounded, outbuf);
|
||||||
if (written != rounded) {
|
if (written != rounded) {
|
||||||
// previously written text has been spoilt, should return a specific error
|
/*
|
||||||
|
* TODO : previously written text has been
|
||||||
|
* spoilt, should return a specific error
|
||||||
|
*/
|
||||||
ntfs_log_error("error writing compressed data\n");
|
ntfs_log_error("error writing compressed data\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
written = -2;
|
written = -2;
|
||||||
@ -1016,25 +1045,297 @@ static int ntfs_comp_set(ntfs_attr *na, runlist_element *rl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free unneeded clusters after compression
|
* 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 an empty slot at the end of runlist,
|
* This generally requires one or two empty slots at the end of runlist,
|
||||||
* but we do not want to reallocate the runlist here because
|
* but we do not want to reallocate the runlist here because
|
||||||
* there are many pointers to it.
|
* there are many pointers to it.
|
||||||
* So the empty slot has to be reserved beforehand
|
* 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)
|
* Returns zero unless some error occurred (described by errno)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl,
|
static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl,
|
||||||
s64 used, s64 reserved)
|
s64 used, s64 reserved, BOOL appending,
|
||||||
|
VCN *update_from)
|
||||||
{
|
{
|
||||||
int freecnt;
|
s32 freecnt;
|
||||||
int usedcnt;
|
s32 usedcnt;
|
||||||
int res;
|
int res;
|
||||||
s64 freelcn;
|
s64 freelcn;
|
||||||
s64 freevcn;
|
s64 freevcn;
|
||||||
int freelength;
|
s32 freelength;
|
||||||
BOOL mergeholes;
|
BOOL mergeholes;
|
||||||
BOOL beginhole;
|
BOOL beginhole;
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
@ -1044,9 +1345,11 @@ static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl,
|
|||||||
vol = na->ni->vol;
|
vol = na->ni->vol;
|
||||||
freecnt = (reserved - used) >> vol->cluster_size_bits;
|
freecnt = (reserved - used) >> vol->cluster_size_bits;
|
||||||
usedcnt = (reserved >> vol->cluster_size_bits) - freecnt;
|
usedcnt = (reserved >> vol->cluster_size_bits) - freecnt;
|
||||||
|
if (rl->vcn < *update_from)
|
||||||
|
*update_from = rl->vcn;
|
||||||
/* skip entries fully used, if any */
|
/* skip entries fully used, if any */
|
||||||
while (rl->length && (rl->length < usedcnt)) {
|
while (rl->length && (rl->length < usedcnt)) {
|
||||||
usedcnt -= rl->length;
|
usedcnt -= rl->length; /* must be > 0 */
|
||||||
rl++;
|
rl++;
|
||||||
}
|
}
|
||||||
if (rl->length) {
|
if (rl->length) {
|
||||||
@ -1056,62 +1359,93 @@ static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl,
|
|||||||
* The required entry has been prereserved when
|
* The required entry has been prereserved when
|
||||||
* mapping the runlist.
|
* mapping the runlist.
|
||||||
*/
|
*/
|
||||||
|
/* get the free part in initial run */
|
||||||
freelcn = rl->lcn + usedcnt;
|
freelcn = rl->lcn + usedcnt;
|
||||||
freevcn = rl->vcn + usedcnt;
|
freevcn = rl->vcn + usedcnt;
|
||||||
freelength = rl->length - usedcnt;
|
|
||||||
/* new count of allocated clusters */
|
/* new count of allocated clusters */
|
||||||
rl->length = usedcnt; /* warning : can be zero */
|
|
||||||
if (!((freevcn + freecnt)
|
if (!((freevcn + freecnt)
|
||||||
& (na->compression_block_clusters - 1))) {
|
& (na->compression_block_clusters - 1))) {
|
||||||
beginhole = !usedcnt && !rl->vcn;
|
if (!appending)
|
||||||
mergeholes = !usedcnt
|
res = ntfs_compress_overwr_free(na,rl,
|
||||||
&& rl[0].vcn
|
usedcnt,freecnt,update_from);
|
||||||
&& (rl[-1].lcn == LCN_HOLE);
|
else {
|
||||||
if (mergeholes) {
|
freelength = rl->length - usedcnt;
|
||||||
freerl = rl;
|
beginhole = !usedcnt && !rl->vcn;
|
||||||
freerl->length = freecnt;
|
mergeholes = !usedcnt
|
||||||
} else
|
&& rl[0].vcn
|
||||||
freerl = ++rl;
|
&& (rl[-1].lcn == LCN_HOLE);
|
||||||
if ((freelength > 0)
|
if (mergeholes) {
|
||||||
&& !mergeholes
|
s32 carry;
|
||||||
&& (usedcnt || beginhole)) {
|
|
||||||
|
/* 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,
|
* move the unused part to the end. Doing so,
|
||||||
* the vcn will be out of order. This does
|
* the vcn will be out of order. This does
|
||||||
* not harm, the vcn are meaningless now, and
|
* not harm, the vcn are meaningless now, and
|
||||||
* only the lcn are meaningful for freeing.
|
* only the lcn are meaningful for freeing.
|
||||||
*/
|
*/
|
||||||
/* locate current end */
|
/* locate current end */
|
||||||
while (rl->length)
|
while (rl->length)
|
||||||
rl++;
|
rl++;
|
||||||
/* new terminator relocated */
|
/* new terminator relocated */
|
||||||
rl[1].vcn = rl->vcn;
|
rl[1].vcn = rl->vcn;
|
||||||
rl[1].lcn = LCN_ENOENT;
|
rl[1].lcn = LCN_ENOENT;
|
||||||
rl[1].length = 0;
|
rl[1].length = 0;
|
||||||
/* hole, currently allocated */
|
/* hole, currently allocated */
|
||||||
rl->vcn = freevcn;
|
rl->vcn = freevcn;
|
||||||
rl->lcn = freelcn;
|
rl->lcn = freelcn;
|
||||||
rl->length = freelength;
|
rl->length = freelength;
|
||||||
}
|
|
||||||
/* free the hole */
|
|
||||||
res = ntfs_cluster_free_from_rl(vol,freerl);
|
|
||||||
if (!res) {
|
|
||||||
if (mergeholes) {
|
|
||||||
/* merge with adjacent hole */
|
|
||||||
freerl--;
|
|
||||||
freerl->length += freecnt;
|
|
||||||
} else {
|
} else {
|
||||||
if (beginhole)
|
/* why is this different from the begin hole case ? */
|
||||||
|
if ((freelength > 0)
|
||||||
|
&& !mergeholes
|
||||||
|
&& !usedcnt) {
|
||||||
freerl--;
|
freerl--;
|
||||||
/* mark hole as free */
|
freerl->length = freelength;
|
||||||
freerl->lcn = LCN_HOLE;
|
if (freerl->vcn < *update_from)
|
||||||
freerl->vcn = freevcn;
|
*update_from
|
||||||
freerl->length = freecnt;
|
= 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;
|
||||||
}
|
}
|
||||||
/* and set up the new end */
|
|
||||||
freerl[1].lcn = LCN_ENOENT;
|
|
||||||
freerl[1].vcn = freevcn + freecnt;
|
|
||||||
freerl[1].length = 0;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ntfs_log_error("Bad end of a compression block set\n");
|
ntfs_log_error("Bad end of a compression block set\n");
|
||||||
@ -1130,7 +1464,7 @@ static int ntfs_compress_free(ntfs_attr *na, runlist_element *rl,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl,
|
static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl,
|
||||||
s64 offs, u32 compsz, int pos,
|
s64 offs, u32 compsz, s32 pos, BOOL appending,
|
||||||
char *outbuf, s64 to_write, const void *b)
|
char *outbuf, s64 to_write, const void *b)
|
||||||
{
|
{
|
||||||
int fail = 1;
|
int fail = 1;
|
||||||
@ -1147,7 +1481,10 @@ static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl,
|
|||||||
compbuf = (char*)ntfs_malloc(compsz);
|
compbuf = (char*)ntfs_malloc(compsz);
|
||||||
if (compbuf) {
|
if (compbuf) {
|
||||||
/* must align to full block for decompression */
|
/* must align to full block for decompression */
|
||||||
decompsz = ((pos - 1) | (NTFS_SB_SIZE - 1)) + 1;
|
if (appending)
|
||||||
|
decompsz = ((pos - 1) | (NTFS_SB_SIZE - 1)) + 1;
|
||||||
|
else
|
||||||
|
decompsz = na->compression_block_size;
|
||||||
got = read_clusters(na->ni->vol, rl, offs,
|
got = read_clusters(na->ni->vol, rl, offs,
|
||||||
compsz, compbuf);
|
compsz, compbuf);
|
||||||
if ((got == compsz)
|
if ((got == compsz)
|
||||||
@ -1171,7 +1508,8 @@ static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int ntfs_flush(ntfs_attr *na, runlist_element *rl, s64 offs,
|
static int ntfs_flush(ntfs_attr *na, runlist_element *rl, s64 offs,
|
||||||
const char *outbuf, int count, BOOL compress)
|
const char *outbuf, s32 count, BOOL compress,
|
||||||
|
BOOL appending, VCN *update_from)
|
||||||
{
|
{
|
||||||
int rounded;
|
int rounded;
|
||||||
int written;
|
int written;
|
||||||
@ -1183,9 +1521,11 @@ static int ntfs_flush(ntfs_attr *na, runlist_element *rl, s64 offs,
|
|||||||
compress = FALSE;
|
compress = FALSE;
|
||||||
if ((written >= 0)
|
if ((written >= 0)
|
||||||
&& ntfs_compress_free(na,rl,offs + written,
|
&& ntfs_compress_free(na,rl,offs + written,
|
||||||
offs + na->compression_block_size))
|
offs + na->compression_block_size, appending,
|
||||||
|
update_from))
|
||||||
written = -1;
|
written = -1;
|
||||||
}
|
} else
|
||||||
|
written = 0;
|
||||||
if (!compress) {
|
if (!compress) {
|
||||||
clsz = 1 << na->ni->vol->cluster_size_bits;
|
clsz = 1 << na->ni->vol->cluster_size_bits;
|
||||||
rounded = ((count - 1) | (clsz - 1)) + 1;
|
rounded = ((count - 1) | (clsz - 1)) + 1;
|
||||||
@ -1204,32 +1544,55 @@ static int ntfs_flush(ntfs_attr *na, runlist_element *rl, s64 offs,
|
|||||||
* it has to be reserved beforehand.
|
* it has to be reserved beforehand.
|
||||||
*
|
*
|
||||||
* Returns the size of uncompressed data written,
|
* Returns the size of uncompressed data written,
|
||||||
* or zero if an error occurred.
|
* or negative if an error occurred.
|
||||||
* When the returned size is less than requested, new clusters have
|
* When the returned size is less than requested, new clusters have
|
||||||
* to be allocated before the function is called again.
|
* to be allocated before the function is called again.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
||||||
s64 offs, s64 to_write, s64 rounded,
|
s64 offs, s64 to_write, s64 rounded,
|
||||||
const void *b, int compressed_part)
|
const void *b, int compressed_part,
|
||||||
|
VCN *update_from)
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
runlist_element *brl; /* entry containing the beginning of block */
|
runlist_element *brl; /* entry containing the beginning of block */
|
||||||
int compression_length;
|
int compression_length;
|
||||||
s64 written;
|
s64 written;
|
||||||
s64 to_read;
|
s64 to_read;
|
||||||
|
s64 to_flush;
|
||||||
s64 roffs;
|
s64 roffs;
|
||||||
s64 got;
|
s64 got;
|
||||||
s64 start_vcn;
|
s64 start_vcn;
|
||||||
s64 nextblock;
|
s64 nextblock;
|
||||||
|
s64 endwrite;
|
||||||
u32 compsz;
|
u32 compsz;
|
||||||
char *inbuf;
|
char *inbuf;
|
||||||
char *outbuf;
|
char *outbuf;
|
||||||
BOOL fail;
|
BOOL fail;
|
||||||
BOOL done;
|
BOOL done;
|
||||||
BOOL compress;
|
BOOL compress;
|
||||||
|
BOOL appending;
|
||||||
|
|
||||||
written = 0; /* default return */
|
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;
|
vol = na->ni->vol;
|
||||||
compression_length = na->compression_block_clusters;
|
compression_length = na->compression_block_clusters;
|
||||||
compress = FALSE;
|
compress = FALSE;
|
||||||
@ -1243,8 +1606,10 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
|||||||
*/
|
*/
|
||||||
nextblock = ((offs + (wrl->vcn << vol->cluster_size_bits))
|
nextblock = ((offs + (wrl->vcn << vol->cluster_size_bits))
|
||||||
| (na->compression_block_size - 1)) + 1;
|
| (na->compression_block_size - 1)) + 1;
|
||||||
if ((offs + to_write + (wrl->vcn << vol->cluster_size_bits))
|
/* determine whether we are appending to file */
|
||||||
>= nextblock) {
|
endwrite = offs + to_write + (wrl->vcn << vol->cluster_size_bits);
|
||||||
|
appending = endwrite >= na->initialized_size;
|
||||||
|
if (endwrite >= nextblock) {
|
||||||
/* it is time to compress */
|
/* it is time to compress */
|
||||||
compress = TRUE;
|
compress = TRUE;
|
||||||
/* only process what we can */
|
/* only process what we can */
|
||||||
@ -1265,6 +1630,8 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
|||||||
/* find the beginning of block */
|
/* find the beginning of block */
|
||||||
start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits))
|
start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits))
|
||||||
& -compression_length;
|
& -compression_length;
|
||||||
|
if (start_vcn < *update_from)
|
||||||
|
*update_from = start_vcn;
|
||||||
while (brl->vcn && (brl->vcn > start_vcn)) {
|
while (brl->vcn && (brl->vcn > start_vcn)) {
|
||||||
/* jumping back a hole means big trouble */
|
/* jumping back a hole means big trouble */
|
||||||
if (brl->lcn == (LCN)LCN_HOLE) {
|
if (brl->lcn == (LCN)LCN_HOLE) {
|
||||||
@ -1284,14 +1651,24 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
|||||||
* Decompress the data and append
|
* Decompress the data and append
|
||||||
*/
|
*/
|
||||||
compsz = compressed_part << vol->cluster_size_bits;
|
compsz = compressed_part << vol->cluster_size_bits;
|
||||||
// improve the needed size
|
|
||||||
outbuf = (char*)ntfs_malloc(na->compression_block_size);
|
outbuf = (char*)ntfs_malloc(na->compression_block_size);
|
||||||
if (outbuf) {
|
if (outbuf) {
|
||||||
to_read = offs - roffs;
|
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,
|
if (!ntfs_read_append(na, brl, roffs, compsz,
|
||||||
to_read, outbuf, to_write, b)) {
|
(s32)(offs - roffs), appending,
|
||||||
|
outbuf, to_write, b)) {
|
||||||
written = ntfs_flush(na, brl, roffs,
|
written = ntfs_flush(na, brl, roffs,
|
||||||
outbuf, to_read + to_write, compress);
|
outbuf, to_flush, compress, appending,
|
||||||
|
update_from);
|
||||||
if (written >= 0) {
|
if (written >= 0) {
|
||||||
written = to_write;
|
written = to_write;
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
@ -1302,9 +1679,9 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
|||||||
} else {
|
} else {
|
||||||
if (compress && !fail) {
|
if (compress && !fail) {
|
||||||
/*
|
/*
|
||||||
* we are filling up a block, read the full set of blocks
|
* we are filling up a block, read the full set
|
||||||
* and compress it
|
* of blocks and compress it
|
||||||
*/
|
*/
|
||||||
inbuf = (char*)ntfs_malloc(na->compression_block_size);
|
inbuf = (char*)ntfs_malloc(na->compression_block_size);
|
||||||
if (inbuf) {
|
if (inbuf) {
|
||||||
to_read = offs - roffs;
|
to_read = offs - roffs;
|
||||||
@ -1326,7 +1703,8 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
|||||||
&& !ntfs_compress_free(na,brl,
|
&& !ntfs_compress_free(na,brl,
|
||||||
written + roffs,
|
written + roffs,
|
||||||
na->compression_block_size
|
na->compression_block_size
|
||||||
+ roffs)) {
|
+ roffs,
|
||||||
|
appending, update_from)) {
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
written = to_write;
|
written = to_write;
|
||||||
}
|
}
|
||||||
@ -1354,18 +1732,22 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((written >= 0)
|
||||||
|
&& !valid_compressed_run(na,wrl,TRUE,"end compressed write"))
|
||||||
|
written = -1;
|
||||||
return (written);
|
return (written);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Close a file written compressed.
|
* Close a file written compressed.
|
||||||
* This compresses the last partial compression block of the file.
|
* This compresses the last partial compression block of the file.
|
||||||
* An empty runlist slot has to be reserved beforehand.
|
* Two empty runlist slots have to be reserved beforehand.
|
||||||
*
|
*
|
||||||
* Returns zero if closing is successful.
|
* Returns zero if closing is successful.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs)
|
int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs,
|
||||||
|
VCN *update_from)
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
runlist_element *brl; /* entry containing the beginning of block */
|
runlist_element *brl; /* entry containing the beginning of block */
|
||||||
@ -1379,6 +1761,18 @@ int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs)
|
|||||||
BOOL fail;
|
BOOL fail;
|
||||||
BOOL done;
|
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;
|
vol = na->ni->vol;
|
||||||
compression_length = na->compression_block_clusters;
|
compression_length = na->compression_block_clusters;
|
||||||
done = FALSE;
|
done = FALSE;
|
||||||
@ -1390,7 +1784,10 @@ int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs)
|
|||||||
if (inbuf) {
|
if (inbuf) {
|
||||||
start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits))
|
start_vcn = (wrl->vcn + (offs >> vol->cluster_size_bits))
|
||||||
& -compression_length;
|
& -compression_length;
|
||||||
to_read = offs + ((wrl->vcn - start_vcn) << vol->cluster_size_bits);
|
if (start_vcn < *update_from)
|
||||||
|
*update_from = start_vcn;
|
||||||
|
to_read = offs + ((wrl->vcn - start_vcn)
|
||||||
|
<< vol->cluster_size_bits);
|
||||||
brl = wrl;
|
brl = wrl;
|
||||||
fail = FALSE;
|
fail = FALSE;
|
||||||
while (brl->vcn && (brl->vcn > start_vcn)) {
|
while (brl->vcn && (brl->vcn > start_vcn)) {
|
||||||
@ -1403,7 +1800,8 @@ int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs)
|
|||||||
}
|
}
|
||||||
if (!fail) {
|
if (!fail) {
|
||||||
/* roffs can be an offset from another uncomp block */
|
/* roffs can be an offset from another uncomp block */
|
||||||
roffs = (start_vcn - brl->vcn) << vol->cluster_size_bits;
|
roffs = (start_vcn - brl->vcn)
|
||||||
|
<< vol->cluster_size_bits;
|
||||||
if (to_read) {
|
if (to_read) {
|
||||||
got = read_clusters(vol, brl, roffs, to_read,
|
got = read_clusters(vol, brl, roffs, to_read,
|
||||||
inbuf);
|
inbuf);
|
||||||
@ -1414,7 +1812,8 @@ int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs)
|
|||||||
/* free the unused clusters */
|
/* free the unused clusters */
|
||||||
&& !ntfs_compress_free(na,brl,
|
&& !ntfs_compress_free(na,brl,
|
||||||
written + roffs,
|
written + roffs,
|
||||||
na->compression_block_size + roffs)) {
|
na->compression_block_size + roffs,
|
||||||
|
TRUE, update_from)) {
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
} else
|
} else
|
||||||
/* if compression failed, leave uncompressed */
|
/* if compression failed, leave uncompressed */
|
||||||
@ -1426,5 +1825,7 @@ int ntfs_compressed_close(ntfs_attr *na, runlist_element *wrl, s64 offs)
|
|||||||
free(inbuf);
|
free(inbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (done && !valid_compressed_run(na,wrl,TRUE,"end compressed close"))
|
||||||
|
done = FALSE;
|
||||||
return (!done);
|
return (!done);
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,11 @@ extern s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count,
|
|||||||
|
|
||||||
extern s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *brl, s64 wpos,
|
extern s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *brl, s64 wpos,
|
||||||
s64 offs, s64 to_write, s64 rounded,
|
s64 offs, s64 to_write, s64 rounded,
|
||||||
const void *b, int compressed_part);
|
const void *b, int compressed_part,
|
||||||
|
VCN *update_from);
|
||||||
|
|
||||||
extern int ntfs_compressed_close(ntfs_attr *na, runlist_element *brl, s64 offs);
|
extern int ntfs_compressed_close(ntfs_attr *na, runlist_element *brl,
|
||||||
|
s64 offs, VCN *update_from);
|
||||||
|
|
||||||
#endif /* defined _NTFS_COMPRESS_H */
|
#endif /* defined _NTFS_COMPRESS_H */
|
||||||
|
|
||||||
|
@ -1,45 +1,43 @@
|
|||||||
/* config.h. Generated from config.h.in by configure. */
|
|
||||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||||
|
|
||||||
/* Define if building universal (internal helper macro) */
|
|
||||||
/* #undef AC_APPLE_UNIVERSAL_BUILD */
|
|
||||||
|
|
||||||
//#define DEBUG
|
|
||||||
/* Define to 1 if debug should be enabled */
|
/* Define to 1 if debug should be enabled */
|
||||||
#ifdef DEBUG
|
#undef ENABLE_DEBUG
|
||||||
#define ENABLE_DEBUG
|
|
||||||
#define NTFS_ENABLE_LOG
|
/* Define to 1 if the nfconv patch should be enabled */
|
||||||
#endif
|
#undef ENABLE_NFCONV
|
||||||
|
|
||||||
/* Define to 1 if using internal fuse */
|
/* Define to 1 if using internal fuse */
|
||||||
/* #undef FUSE_INTERNAL */
|
#undef FUSE_INTERNAL
|
||||||
|
|
||||||
/* Define to 1 if you have the `atexit' function. */
|
/* Define to 1 if you have the `atexit' function. */
|
||||||
#define HAVE_ATEXIT 1
|
#define HAVE_ATEXIT 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `basename' function. */
|
/* Define to 1 if you have the `basename' function. */
|
||||||
/* #undef HAVE_BASENAME */
|
#undef HAVE_BASENAME
|
||||||
|
|
||||||
/* Define to 1 if you have the <byteswap.h> header file. */
|
/* Define to 1 if you have the <byteswap.h> header file. */
|
||||||
/* #undef HAVE_BYTESWAP_H */
|
#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 <ctype.h> header file. */
|
/* Define to 1 if you have the <ctype.h> header file. */
|
||||||
#define HAVE_CTYPE_H 1
|
#define HAVE_CTYPE_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `daemon' function. */
|
/* Define to 1 if you have the `daemon' function. */
|
||||||
/* #undef HAVE_DAEMON */
|
#undef HAVE_DAEMON
|
||||||
|
|
||||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||||
/* #undef HAVE_DLFCN_H */
|
#undef HAVE_DLFCN_H
|
||||||
|
|
||||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||||
/* #undef HAVE_DOPRNT */
|
#undef HAVE_DOPRNT
|
||||||
|
|
||||||
/* Define to 1 if you have the `dup2' function. */
|
/* Define to 1 if you have the `dup2' function. */
|
||||||
/* #undef HAVE_DUP2 */
|
#undef HAVE_DUP2
|
||||||
|
|
||||||
/* Define to 1 if you have the <endian.h> header file. */
|
/* Define to 1 if you have the <endian.h> header file. */
|
||||||
/* #undef HAVE_ENDIAN_H */
|
#undef HAVE_ENDIAN_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <errno.h> header file. */
|
/* Define to 1 if you have the <errno.h> header file. */
|
||||||
#define HAVE_ERRNO_H 1
|
#define HAVE_ERRNO_H 1
|
||||||
@ -48,10 +46,10 @@
|
|||||||
#define HAVE_FCNTL_H 1
|
#define HAVE_FCNTL_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `fdatasync' function. */
|
/* Define to 1 if you have the `fdatasync' function. */
|
||||||
/* #undef HAVE_FDATASYNC */
|
#undef HAVE_FDATASYNC
|
||||||
|
|
||||||
/* Define to 1 if you have the <features.h> header file. */
|
/* Define to 1 if you have the <features.h> header file. */
|
||||||
/* #undef HAVE_FEATURES_H */
|
#undef HAVE_FEATURES_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `ffs' function. */
|
/* Define to 1 if you have the `ffs' function. */
|
||||||
#define HAVE_FFS 1
|
#define HAVE_FFS 1
|
||||||
@ -60,7 +58,7 @@
|
|||||||
#define HAVE_FORK 1
|
#define HAVE_FORK 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `getmntent' function. */
|
/* Define to 1 if you have the `getmntent' function. */
|
||||||
/* #undef HAVE_GETMNTENT */
|
#undef HAVE_GETMNTENT
|
||||||
|
|
||||||
/* Define to 1 if you have the <getopt.h> header file. */
|
/* Define to 1 if you have the <getopt.h> header file. */
|
||||||
#define HAVE_GETOPT_H 1
|
#define HAVE_GETOPT_H 1
|
||||||
@ -68,8 +66,11 @@
|
|||||||
/* Define to 1 if you have the `getopt_long' function. */
|
/* Define to 1 if you have the `getopt_long' function. */
|
||||||
#define HAVE_GETOPT_LONG 1
|
#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. */
|
/* Define to 1 if you have the `hasmntopt' function. */
|
||||||
/* #undef HAVE_HASMNTOPT */
|
#undef HAVE_HASMNTOPT
|
||||||
|
|
||||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||||
#define HAVE_INTTYPES_H 1
|
#define HAVE_INTTYPES_H 1
|
||||||
@ -78,19 +79,19 @@
|
|||||||
#define HAVE_LIBGEN_H 1
|
#define HAVE_LIBGEN_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <libintl.h> header file. */
|
/* Define to 1 if you have the <libintl.h> header file. */
|
||||||
/* #undef HAVE_LIBINTL_H */
|
#undef HAVE_LIBINTL_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <limits.h> header file. */
|
/* Define to 1 if you have the <limits.h> header file. */
|
||||||
#define HAVE_LIMITS_H 1
|
#define HAVE_LIMITS_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <linux/fd.h> header file. */
|
/* Define to 1 if you have the <linux/fd.h> header file. */
|
||||||
/* #undef HAVE_LINUX_FD_H */
|
#undef HAVE_LINUX_FD_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <linux/hdreg.h> header file. */
|
/* Define to 1 if you have the <linux/hdreg.h> header file. */
|
||||||
/* #undef HAVE_LINUX_HDREG_H */
|
#undef HAVE_LINUX_HDREG_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <linux/major.h> header file. */
|
/* Define to 1 if you have the <linux/major.h> header file. */
|
||||||
/* #undef HAVE_LINUX_MAJOR_H */
|
#undef HAVE_LINUX_MAJOR_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <locale.h> header file. */
|
/* Define to 1 if you have the <locale.h> header file. */
|
||||||
#define HAVE_LOCALE_H 1
|
#define HAVE_LOCALE_H 1
|
||||||
@ -111,25 +112,25 @@
|
|||||||
#define HAVE_MEMMOVE 1
|
#define HAVE_MEMMOVE 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <memory.h> header file. */
|
/* Define to 1 if you have the <memory.h> header file. */
|
||||||
/* #undef HAVE_MEMORY_H */
|
#undef HAVE_MEMORY_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `memset' function. */
|
/* Define to 1 if you have the `memset' function. */
|
||||||
#define HAVE_MEMSET 1
|
#define HAVE_MEMSET 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <mntent.h> header file. */
|
/* Define to 1 if you have the <mntent.h> header file. */
|
||||||
/* #undef HAVE_MNTENT_H */
|
#undef HAVE_MNTENT_H
|
||||||
|
|
||||||
/* Define to 1 if you have the `realpath' function. */
|
/* Define to 1 if you have the `realpath' function. */
|
||||||
/* #undef HAVE_REALPATH */
|
#undef HAVE_REALPATH
|
||||||
|
|
||||||
/* Define to 1 if you have the `regcomp' function. */
|
/* Define to 1 if you have the `regcomp' function. */
|
||||||
/* #undef HAVE_REGCOMP */
|
#undef HAVE_REGCOMP
|
||||||
|
|
||||||
/* Define to 1 if you have the `setlocale' function. */
|
/* Define to 1 if you have the `setlocale' function. */
|
||||||
#define HAVE_SETLOCALE 1
|
#define HAVE_SETLOCALE 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `setxattr' function. */
|
/* Define to 1 if you have the `setxattr' function. */
|
||||||
/* #undef HAVE_SETXATTR */
|
#undef HAVE_SETXATTR
|
||||||
|
|
||||||
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
||||||
zero-length file name argument. */
|
zero-length file name argument. */
|
||||||
@ -169,7 +170,7 @@
|
|||||||
#define HAVE_STRFTIME 1
|
#define HAVE_STRFTIME 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <strings.h> header file. */
|
/* Define to 1 if you have the <strings.h> header file. */
|
||||||
/* #undef HAVE_STRINGS_H */
|
#undef HAVE_STRINGS_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <string.h> header file. */
|
/* Define to 1 if you have the <string.h> header file. */
|
||||||
#define HAVE_STRING_H 1
|
#define HAVE_STRING_H 1
|
||||||
@ -187,42 +188,44 @@
|
|||||||
#define HAVE_STRTOUL 1
|
#define HAVE_STRTOUL 1
|
||||||
|
|
||||||
/* Define to 1 if `st_atim' is member of `struct stat'. */
|
/* Define to 1 if `st_atim' is member of `struct stat'. */
|
||||||
/* #undef HAVE_STRUCT_STAT_ST_ATIM */
|
#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'. */
|
/* Define to 1 if `st_atimespec' is member of `struct stat'. */
|
||||||
/* #undef HAVE_STRUCT_STAT_ST_ATIMESPEC */
|
#undef HAVE_STRUCT_STAT_ST_ATIMESPEC
|
||||||
|
|
||||||
/* Define to 1 if `st_blocks' is member of `struct stat'. */
|
/* Define to 1 if `st_blocks' is member of `struct stat'. */
|
||||||
#define HAVE_STRUCT_STAT_ST_BLOCKS 1
|
#undef HAVE_STRUCT_STAT_ST_BLOCKS
|
||||||
|
|
||||||
/* Define to 1 if `st_rdev' is member of `struct stat'. */
|
/* Define to 1 if `st_rdev' is member of `struct stat'. */
|
||||||
#define HAVE_STRUCT_STAT_ST_RDEV 1
|
#undef HAVE_STRUCT_STAT_ST_RDEV
|
||||||
|
|
||||||
/* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use
|
/* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use
|
||||||
`HAVE_STRUCT_STAT_ST_BLOCKS' instead. */
|
`HAVE_STRUCT_STAT_ST_BLOCKS' instead. */
|
||||||
#define HAVE_ST_BLOCKS 1
|
#undef HAVE_ST_BLOCKS
|
||||||
#define HAVE_STRUCT_STAT_ST_BLOCKS 1
|
|
||||||
|
|
||||||
/* Define to 1 if you have the `sysconf' function. */
|
/* Define to 1 if you have the `sysconf' function. */
|
||||||
/* #undef HAVE_SYSCONF */
|
#define HAVE_SYSCONF 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <syslog.h> header file. */
|
/* Define to 1 if you have the <syslog.h> header file. */
|
||||||
/* #undef HAVE_SYSLOG_H */
|
#undef HAVE_SYSLOG_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/byteorder.h> header file. */
|
/* Define to 1 if you have the <sys/byteorder.h> header file. */
|
||||||
/* #undef HAVE_SYS_BYTEORDER_H */
|
#undef HAVE_SYS_BYTEORDER_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||||
/* #undef HAVE_SYS_ENDIAN_H */
|
#undef HAVE_SYS_ENDIAN_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||||
/* #undef HAVE_SYS_IOCTL_H */
|
#undef HAVE_SYS_IOCTL_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/mkdev.h> header file. */
|
/* Define to 1 if you have the <sys/mkdev.h> header file. */
|
||||||
/* #undef HAVE_SYS_MKDEV_H */
|
#undef HAVE_SYS_MKDEV_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/mount.h> header file. */
|
/* Define to 1 if you have the <sys/mount.h> header file. */
|
||||||
/* #undef HAVE_SYS_MOUNT_H */
|
#undef HAVE_SYS_MOUNT_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||||
#define HAVE_SYS_PARAM_H 1
|
#define HAVE_SYS_PARAM_H 1
|
||||||
@ -234,13 +237,13 @@
|
|||||||
#define HAVE_SYS_STAT_H 1
|
#define HAVE_SYS_STAT_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/sysmacros.h> header file. */
|
/* Define to 1 if you have the <sys/sysmacros.h> header file. */
|
||||||
/* #undef HAVE_SYS_SYSMACROS_H */
|
#undef HAVE_SYS_SYSMACROS_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||||
#define HAVE_SYS_TYPES_H 1
|
#define HAVE_SYS_TYPES_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/vfs.h> header file. */
|
/* Define to 1 if you have the <sys/vfs.h> header file. */
|
||||||
/* #undef HAVE_SYS_VFS_H */
|
#undef HAVE_SYS_VFS_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <time.h> header file. */
|
/* Define to 1 if you have the <time.h> header file. */
|
||||||
#define HAVE_TIME_H 1
|
#define HAVE_TIME_H 1
|
||||||
@ -249,13 +252,16 @@
|
|||||||
#define HAVE_UNISTD_H 1
|
#define HAVE_UNISTD_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the `utime' function. */
|
/* Define to 1 if you have the `utime' function. */
|
||||||
/* #undef HAVE_UTIME */
|
#undef HAVE_UTIME
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `utimensat' function. */
|
||||||
|
#undef HAVE_UTIMENSAT
|
||||||
|
|
||||||
/* Define to 1 if you have the <utime.h> header file. */
|
/* Define to 1 if you have the <utime.h> header file. */
|
||||||
#define HAVE_UTIME_H 1
|
#define HAVE_UTIME_H 1
|
||||||
|
|
||||||
/* Define to 1 if `utime(file, NULL)' sets file's timestamp to the present. */
|
/* Define to 1 if `utime(file, NULL)' sets file's timestamp to the present. */
|
||||||
/* #undef HAVE_UTIME_NULL */
|
#undef HAVE_UTIME_NULL
|
||||||
|
|
||||||
/* Define to 1 if you have the `vprintf' function. */
|
/* Define to 1 if you have the `vprintf' function. */
|
||||||
#define HAVE_VPRINTF 1
|
#define HAVE_VPRINTF 1
|
||||||
@ -264,27 +270,23 @@
|
|||||||
#define HAVE_WCHAR_H 1
|
#define HAVE_WCHAR_H 1
|
||||||
|
|
||||||
/* Define to 1 if you have the <windows.h> header file. */
|
/* Define to 1 if you have the <windows.h> header file. */
|
||||||
/* #undef HAVE_WINDOWS_H */
|
#undef HAVE_WINDOWS_H
|
||||||
|
|
||||||
/* Define to 1 if the system has the type `_Bool'. */
|
/* Define to 1 if the system has the type `_Bool'. */
|
||||||
#define HAVE__BOOL 1
|
#undef HAVE__BOOL
|
||||||
|
|
||||||
/* Don't update /etc/mtab */
|
/* Don't update /etc/mtab */
|
||||||
/* #undef IGNORE_MTAB */
|
#undef IGNORE_MTAB
|
||||||
|
|
||||||
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
||||||
slash. */
|
slash. */
|
||||||
/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
|
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
|
||||||
|
|
||||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
|
||||||
*/
|
|
||||||
#define LT_OBJDIR ".libs/"
|
|
||||||
|
|
||||||
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||||
/* #undef NO_MINUS_C_MINUS_O */
|
#undef NO_MINUS_C_MINUS_O
|
||||||
|
|
||||||
/* Don't use default IO ops */
|
/* Don't use default IO ops */
|
||||||
/* #undef NO_NTFS_DEVICE_DEFAULT_IO_OPS */
|
#undef NO_NTFS_DEVICE_DEFAULT_IO_OPS
|
||||||
|
|
||||||
/* Name of package */
|
/* Name of package */
|
||||||
#define PACKAGE "ntfs-3g"
|
#define PACKAGE "ntfs-3g"
|
||||||
@ -296,16 +298,16 @@
|
|||||||
#define PACKAGE_NAME "ntfs-3g"
|
#define PACKAGE_NAME "ntfs-3g"
|
||||||
|
|
||||||
/* Define to the full name and version of this package. */
|
/* Define to the full name and version of this package. */
|
||||||
#define PACKAGE_STRING "ntfs-3g 2009.4.4AR.16"
|
#define PACKAGE_STRING "ntfs-3g 2010.8.8"
|
||||||
|
|
||||||
/* Define to the one symbol short name of this package. */
|
/* Define to the one symbol short name of this package. */
|
||||||
#define PACKAGE_TARNAME "ntfs-3g"
|
#define PACKAGE_TARNAME "ntfs-3g"
|
||||||
|
|
||||||
/* Define to the version of this package. */
|
/* Define to the version of this package. */
|
||||||
#define PACKAGE_VERSION "2009.4.4AR.16"
|
#define PACKAGE_VERSION "2010.8.8"
|
||||||
|
|
||||||
/* POSIX ACL support */
|
/* POSIX ACL support */
|
||||||
/* #undef POSIXACLS */
|
#undef POSIXACLS
|
||||||
|
|
||||||
/* Define to 1 if you have the ANSI C header files. */
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
#define STDC_HEADERS 1
|
#define STDC_HEADERS 1
|
||||||
@ -331,59 +333,42 @@
|
|||||||
# define __EXTENSIONS__ 1
|
# define __EXTENSIONS__ 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Version number of package */
|
/* Version number of package */
|
||||||
#define VERSION "2009.4.4AR.16"
|
#define VERSION "2010.8.8"
|
||||||
|
|
||||||
/* Define to 1 if this is a Windows OS */
|
/* Define to 1 if this is a Windows OS */
|
||||||
/* #undef WINDOWS */
|
#undef WINDOWS
|
||||||
|
|
||||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
/* Define to 1 if your processor stores words with the most significant byte
|
||||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
#define WORDS_BIGENDIAN 1
|
||||||
# if defined __BIG_ENDIAN__
|
|
||||||
# define WORDS_BIGENDIAN 1
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
# ifndef WORDS_BIGENDIAN
|
|
||||||
# define WORDS_BIGENDIAN 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define to 1 if your processor stores words with the least significant byte
|
/* Define to 1 if your processor stores words with the least significant byte
|
||||||
first (like Intel and VAX, unlike Motorola and SPARC). */
|
first (like Intel and VAX, unlike Motorola and SPARC). */
|
||||||
/* #undef WORDS_LITTLEENDIAN */
|
#undef WORDS_LITTLEENDIAN
|
||||||
|
|
||||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||||
/* #undef _FILE_OFFSET_BITS */
|
#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 for large files, on AIX-style hosts. */
|
||||||
/* #undef _LARGE_FILES */
|
#define _LARGE_FILES 1
|
||||||
|
|
||||||
/* Define to 1 if on MINIX. */
|
|
||||||
/* #undef _MINIX */
|
|
||||||
|
|
||||||
/* Define to 2 if the system does not provide POSIX.1 features except with
|
|
||||||
this defined. */
|
|
||||||
/* #undef _POSIX_1_SOURCE */
|
|
||||||
|
|
||||||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
|
||||||
/* #undef _POSIX_SOURCE */
|
|
||||||
|
|
||||||
/* Required define if using POSIX threads */
|
/* Required define if using POSIX threads */
|
||||||
/* #undef _REENTRANT */
|
#undef _REENTRANT
|
||||||
|
|
||||||
/* Define to empty if `const' does not conform to ANSI C. */
|
|
||||||
/* #undef const */
|
|
||||||
|
|
||||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
/* 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. */
|
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
/* #undef inline */
|
#define inline __inline__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Define to `long int' if <sys/types.h> does not define. */
|
/* Define to `long int' if <sys/types.h> does not define. */
|
||||||
/* #undef off_t */
|
#undef off_t
|
||||||
|
|
||||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||||
/* #undef size_t */
|
#undef size_t
|
||||||
|
@ -28,6 +28,18 @@
|
|||||||
|
|
||||||
#ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS
|
#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
|
#ifndef HDIO_GETGEO
|
||||||
# define HDIO_GETGEO 0x301
|
# define HDIO_GETGEO 0x301
|
||||||
/**
|
/**
|
||||||
@ -53,8 +65,10 @@ struct hd_geometry {
|
|||||||
# define BLKBSZSET 0x40041271
|
# define BLKBSZSET 0x40041271
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* On Nintendo GameCube/Wii; use Gekko low level device operations. */
|
/* On Cygwin; use Win32 low level device operations. */
|
||||||
#define ntfs_device_default_io_ops ntfs_device_gekko_io_ops
|
#define ntfs_device_default_io_ops ntfs_device_win32_io_ops
|
||||||
|
|
||||||
|
#endif /* __CYGWIN32__ */
|
||||||
|
|
||||||
|
|
||||||
/* Forward declaration. */
|
/* Forward declaration. */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -61,6 +61,9 @@ extern ntfschar NTFS_INDEX_R[3];
|
|||||||
|
|
||||||
extern u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
|
extern u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
|
||||||
const ntfschar *uname, const int uname_len);
|
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,
|
extern ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent,
|
||||||
const char *pathname);
|
const char *pathname);
|
||||||
@ -104,12 +107,22 @@ typedef int (*ntfs_filldir_t)(void *dirent, const ntfschar *name,
|
|||||||
extern int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
|
extern int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
|
||||||
void *dirent, ntfs_filldir_t filldir);
|
void *dirent, ntfs_filldir_t filldir);
|
||||||
|
|
||||||
int ntfs_get_ntfs_dos_name(const char *path,
|
ntfs_inode *ntfs_dir_parent_inode(ntfs_inode *ni);
|
||||||
char *value, size_t size, ntfs_inode *ni);
|
|
||||||
int ntfs_set_ntfs_dos_name(const char *path,
|
int ntfs_get_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni,
|
||||||
const char *value, size_t size, int flags,
|
char *value, size_t size);
|
||||||
ntfs_inode *ni);
|
int ntfs_set_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni,
|
||||||
int ntfs_remove_ntfs_dos_name(const char *path, ntfs_inode *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 */
|
#endif /* defined _NTFS_DIR_H */
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* This module is part of ntfs-3g library
|
* This module is part of ntfs-3g library
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009 Martin Bene
|
* Copyright (c) 2009 Martin Bene
|
||||||
* Copyright (c) 2009 Jean-Pierre Andre
|
* Copyright (c) 2009-2010 Jean-Pierre Andre
|
||||||
*
|
*
|
||||||
* This program/include file is free software; you can redistribute it and/or
|
* This program/include file is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as published
|
* modify it under the terms of the GNU General Public License as published
|
||||||
@ -73,8 +73,7 @@ static ntfschar logged_utility_stream_name[] = {
|
|||||||
* Get the ntfs EFS info into an extended attribute
|
* Get the ntfs EFS info into an extended attribute
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_get_efs_info(const char *path,
|
int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size)
|
||||||
char *value, size_t size, ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
EFS_ATTR_HEADER *efs_info;
|
EFS_ATTR_HEADER *efs_info;
|
||||||
s64 attr_size = 0;
|
s64 attr_size = 0;
|
||||||
@ -102,43 +101,133 @@ int ntfs_get_efs_info(const char *path,
|
|||||||
} else {
|
} else {
|
||||||
if (efs_info) {
|
if (efs_info) {
|
||||||
free(efs_info);
|
free(efs_info);
|
||||||
ntfs_log_info("Bad efs_info for file %s\n",path);
|
ntfs_log_error("Bad efs_info for inode %lld\n",
|
||||||
|
(long long)ni->mft_no);
|
||||||
} else {
|
} else {
|
||||||
ntfs_log_info("Could not get efsinfo"
|
ntfs_log_error("Could not get efsinfo"
|
||||||
" for file %s\n", path);
|
" for inode %lld\n",
|
||||||
|
(long long)ni->mft_no);
|
||||||
}
|
}
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
attr_size = 0;
|
attr_size = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errno = ENODATA;
|
errno = ENODATA;
|
||||||
ntfs_log_info("File %s is not encrypted",path);
|
ntfs_log_trace("Inode %lld is not encrypted\n",
|
||||||
|
(long long)ni->mft_no);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (attr_size ? (int)attr_size : -errno);
|
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
|
* Set the efs data from an extended attribute
|
||||||
* Warning : the new data is not checked
|
* Warning : the new data is not checked
|
||||||
* Returns 0, or -1 if there is a problem
|
* Returns 0, or -1 if there is a problem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_set_efs_info(const char *path __attribute__((unused)),
|
int ntfs_set_efs_info(ntfs_inode *ni, const char *value, size_t size,
|
||||||
const char *value, size_t size, int flags,
|
int flags)
|
||||||
ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
int written;
|
int written;
|
||||||
ntfs_attr *na;
|
ntfs_attr *na;
|
||||||
const EFS_ATTR_HEADER *info_header;
|
const EFS_ATTR_HEADER *info_header;
|
||||||
ntfs_attr_search_ctx *ctx;
|
|
||||||
|
|
||||||
res = 0;
|
res = 0;
|
||||||
if (ni && value && size) {
|
if (ni && value && size) {
|
||||||
if (ni->flags & (FILE_ATTR_ENCRYPTED | FILE_ATTR_COMPRESSED)) {
|
if (ni->flags & (FILE_ATTR_ENCRYPTED | FILE_ATTR_COMPRESSED)) {
|
||||||
if (ni->flags & FILE_ATTR_ENCRYPTED) {
|
if (ni->flags & FILE_ATTR_ENCRYPTED) {
|
||||||
ntfs_log_info("File %s already encrypted",path);
|
ntfs_log_trace("Inode %lld already encrypted\n",
|
||||||
|
(long long)ni->mft_no);
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
@ -147,8 +236,8 @@ int ntfs_set_efs_info(const char *path __attribute__((unused)),
|
|||||||
* restored as compressed.
|
* restored as compressed.
|
||||||
* TODO : decompress first.
|
* TODO : decompress first.
|
||||||
*/
|
*/
|
||||||
ntfs_log_error("File %s cannot be encrypted and compressed\n",
|
ntfs_log_error("Inode %lld cannot be encrypted and compressed\n",
|
||||||
path);
|
(long long)ni->mft_no);
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@ -207,20 +296,8 @@ int ntfs_set_efs_info(const char *path __attribute__((unused)),
|
|||||||
/* iterate over AT_DATA attributes */
|
/* iterate over AT_DATA attributes */
|
||||||
/* set encrypted flag, truncate attribute to match padding bytes */
|
/* set encrypted flag, truncate attribute to match padding bytes */
|
||||||
|
|
||||||
ctx = ntfs_attr_get_search_ctx(ni, NULL);
|
if (fixup_loop(ni))
|
||||||
if (!ctx) {
|
return -1;
|
||||||
ntfs_log_error("Failed to get ctx for efs\n");
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
while (!ntfs_attr_lookup(AT_DATA, NULL, 0,
|
|
||||||
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
|
|
||||||
if (ntfs_efs_fixup_attribute(ctx, NULL)) {
|
|
||||||
ntfs_log_error("Error in efs fixup of AT_DATA Attribute");
|
|
||||||
ntfs_attr_put_search_ctx(ctx);
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ntfs_attr_put_search_ctx(ctx);
|
|
||||||
}
|
}
|
||||||
ni->flags |= FILE_ATTR_ENCRYPTED;
|
ni->flags |= FILE_ATTR_ENCRYPTED;
|
||||||
NInoSetDirty(ni);
|
NInoSetDirty(ni);
|
||||||
@ -247,15 +324,14 @@ int ntfs_set_efs_info(const char *path __attribute__((unused)),
|
|||||||
int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na)
|
int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na)
|
||||||
{
|
{
|
||||||
u64 newsize;
|
u64 newsize;
|
||||||
|
u64 oldsize;
|
||||||
le16 appended_bytes;
|
le16 appended_bytes;
|
||||||
u16 padding_length;
|
u16 padding_length;
|
||||||
ATTR_RECORD *a;
|
|
||||||
ntfs_inode *ni;
|
ntfs_inode *ni;
|
||||||
BOOL close_na = FALSE;
|
|
||||||
BOOL close_ctx = FALSE;
|
BOOL close_ctx = FALSE;
|
||||||
|
|
||||||
if (!ctx && !na) {
|
if (!na) {
|
||||||
ntfs_log_error("neither ctx nor na specified for efs_fixup_attribute\n");
|
ntfs_log_error("no na specified for efs_fixup_attribute\n");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
@ -264,55 +340,79 @@ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na)
|
|||||||
ntfs_log_error("Failed to get ctx for efs\n");
|
ntfs_log_error("Failed to get ctx for efs\n");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
close_ctx=TRUE;
|
close_ctx = TRUE;
|
||||||
if (ntfs_attr_lookup(AT_DATA, na->name, na->name_len,
|
if (ntfs_attr_lookup(AT_DATA, na->name, na->name_len,
|
||||||
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
|
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
|
||||||
ntfs_log_error("attr lookup for AT_DATA attribute failed in efs fixup\n");
|
ntfs_log_error("attr lookup for AT_DATA attribute failed in efs fixup\n");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
if (!NAttrNonResident(na)) {
|
||||||
a = ctx->attr;
|
ntfs_log_error("Cannot make non resident"
|
||||||
if (!na) {
|
" when a context has been allocated\n");
|
||||||
na = ntfs_attr_open(ctx->ntfs_ino, AT_DATA,
|
goto err_out;
|
||||||
(ntfschar*)((u8*)a + le16_to_cpu(a->name_offset)),
|
|
||||||
a->name_length);
|
|
||||||
if (!na) {
|
|
||||||
ntfs_log_error("can't open DATA Attribute\n");
|
|
||||||
return (-1);
|
|
||||||
}
|
}
|
||||||
close_na = TRUE;
|
|
||||||
}
|
|
||||||
/* make sure size is valid for a raw encrypted stream */
|
|
||||||
if ((na->data_size & 511) != 2) {
|
|
||||||
ntfs_log_error("Bad raw encrypted stream");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
/* read padding length from last two bytes of attribute */
|
|
||||||
if (ntfs_attr_pread(na, na->data_size-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)na->data_size);
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
newsize = na->data_size - padding_length - 2;
|
|
||||||
/* truncate attribute to possibly free clusters allocated
|
|
||||||
for the last two bytes */
|
|
||||||
if (ntfs_attr_truncate(na, na->data_size-2)) {
|
|
||||||
ntfs_log_error("Error truncating attribute\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encrypted AT_DATA Attributes MUST be non-resident */
|
/* 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)
|
if (!NAttrNonResident(na)
|
||||||
&& ntfs_attr_make_non_resident(na, ctx)) {
|
&& ntfs_attr_make_non_resident(na, ctx)) {
|
||||||
ntfs_log_error("Error making DATA attribute non-resident\n");
|
if (!close_ctx
|
||||||
goto err_out;
|
|| 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;
|
ni = na->ni;
|
||||||
if (!na->name_len) {
|
if (!na->name_len) {
|
||||||
@ -321,8 +421,6 @@ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na)
|
|||||||
}
|
}
|
||||||
NInoSetDirty(ni);
|
NInoSetDirty(ni);
|
||||||
NInoFileNameSetDirty(ni);
|
NInoFileNameSetDirty(ni);
|
||||||
if (close_na)
|
|
||||||
ntfs_attr_close(na);
|
|
||||||
|
|
||||||
ctx->attr->data_size = cpu_to_le64(newsize);
|
ctx->attr->data_size = cpu_to_le64(newsize);
|
||||||
if (le64_to_cpu(ctx->attr->initialized_size) > newsize)
|
if (le64_to_cpu(ctx->attr->initialized_size) > newsize)
|
||||||
@ -333,8 +431,6 @@ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na)
|
|||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
err_out:
|
err_out:
|
||||||
if (close_na && na)
|
|
||||||
ntfs_attr_close(na);
|
|
||||||
if (close_ctx && ctx)
|
if (close_ctx && ctx)
|
||||||
ntfs_attr_put_search_ctx(ctx);
|
ntfs_attr_put_search_ctx(ctx);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -21,11 +21,10 @@
|
|||||||
#ifndef EFS_H
|
#ifndef EFS_H
|
||||||
#define EFS_H
|
#define EFS_H
|
||||||
|
|
||||||
int ntfs_get_efs_info(const char *path,
|
int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size);
|
||||||
char *value, size_t size, ntfs_inode *ni);
|
|
||||||
int ntfs_set_efs_info(const char *path,
|
int ntfs_set_efs_info(ntfs_inode *ni,
|
||||||
const char *value, size_t size, int flags,
|
const char *value, size_t size, int flags);
|
||||||
ntfs_inode *ni);
|
|
||||||
int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na);
|
int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na);
|
||||||
|
|
||||||
#endif /* EFS_H */
|
#endif /* EFS_H */
|
||||||
|
@ -132,22 +132,13 @@ static int ntfs_device_gekko_io_open(struct ntfs_device *dev, int flags)
|
|||||||
fd->len = (fd->sectorCount * fd->sectorSize);
|
fd->len = (fd->sectorCount * fd->sectorSize);
|
||||||
fd->ino = le64_to_cpu(boot.volume_serial_number);
|
fd->ino = le64_to_cpu(boot.volume_serial_number);
|
||||||
|
|
||||||
// If the device sector size is not 512 bytes then we cannot continue,
|
|
||||||
// gekko disc I/O works on the assumption that sectors are always 512 bytes long.
|
|
||||||
// TODO: Implement support for non-512 byte sector sizes through some fancy maths!?
|
|
||||||
if (fd->sectorSize != BYTES_PER_SECTOR) {
|
|
||||||
ntfs_log_error("Boot sector claims there is %i bytes per sector; expected %i\n", fd->sectorSize, BYTES_PER_SECTOR);
|
|
||||||
errno = EIO;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark the device as read-only (if required)
|
// Mark the device as read-only (if required)
|
||||||
if (flags & O_RDONLY) {
|
if (flags & O_RDONLY) {
|
||||||
NDevSetReadOnly(dev);
|
NDevSetReadOnly(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the cache
|
// Create the cache
|
||||||
fd->cache = _NTFS_cache_constructor(fd->cachePageCount, fd->cachePageSize, interface, fd->startSector + fd->sectorCount);
|
fd->cache = _NTFS_cache_constructor(fd->cachePageCount, fd->cachePageSize, interface, fd->startSector + fd->sectorCount, fd->sectorSize);
|
||||||
|
|
||||||
// Mark the device as open
|
// Mark the device as open
|
||||||
NDevSetBlock(dev);
|
NDevSetBlock(dev);
|
||||||
@ -288,29 +279,31 @@ static s64 ntfs_device_gekko_io_readbytes(struct ntfs_device *dev, s64 offset, s
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(offset < 0)
|
||||||
|
{
|
||||||
|
errno = EROFS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if(!count)
|
if(!count)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sec_t sec_start = (sec_t) fd->startSector;
|
sec_t sec_start = (sec_t) fd->startSector;
|
||||||
sec_t sec_count = 1;
|
sec_t sec_count = 1;
|
||||||
u32 buffer_offset = 0;
|
u32 buffer_offset = (u32) (offset % fd->sectorSize);
|
||||||
u8 *buffer = NULL;
|
u8 *buffer = NULL;
|
||||||
|
|
||||||
// Determine the range of sectors required for this read
|
// Determine the range of sectors required for this read
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
sec_start += (sec_t) floor((f64) offset/fd->sectorSize);
|
sec_start += (sec_t) floor((f64) offset / (f64) fd->sectorSize);
|
||||||
buffer_offset = (u32) (offset % fd->sectorSize);
|
|
||||||
}
|
}
|
||||||
if (count > fd->sectorSize) {
|
if (buffer_offset+count > fd->sectorSize) {
|
||||||
sec_count = (sec_t) ceil((f64) count/fd->sectorSize);
|
sec_count = (sec_t) ceil((f64) (buffer_offset+count) / (f64) fd->sectorSize);
|
||||||
|
|
||||||
if(buffer_offset > 0)
|
|
||||||
sec_count += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this read happens to be on the sector boundaries then do the read straight into the destination buffer
|
// If this read happens to be on the sector boundaries then do the read straight into the destination buffer
|
||||||
|
|
||||||
if((offset % fd->sectorSize == 0) && (count % fd->sectorSize == 0)) {
|
if((buffer_offset == 0) && (count % fd->sectorSize == 0)) {
|
||||||
|
|
||||||
// Read from the device
|
// Read from the device
|
||||||
ntfs_log_trace("direct read from sector %d (%d sector(s) long)\n", sec_start, sec_count);
|
ntfs_log_trace("direct read from sector %d (%d sector(s) long)\n", sec_start, sec_count);
|
||||||
@ -378,29 +371,30 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!count)
|
if(count < 0 || offset < 0) {
|
||||||
|
errno = EROFS;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sec_t sec_start = (sec_t) fd->startSector;
|
sec_t sec_start = (sec_t) fd->startSector;
|
||||||
sec_t sec_count = 1;
|
sec_t sec_count = 1;
|
||||||
u32 buffer_offset = 0;
|
u32 buffer_offset = (u32) (offset % fd->sectorSize);
|
||||||
u8 *buffer = NULL;
|
u8 *buffer = NULL;
|
||||||
|
|
||||||
// Determine the range of sectors required for this write
|
// Determine the range of sectors required for this write
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
sec_start += (sec_t) floor((f64) offset/fd->sectorSize);
|
sec_start += (sec_t) floor((f64) offset / (f64) fd->sectorSize);
|
||||||
buffer_offset = (u32) (offset % fd->sectorSize);
|
|
||||||
}
|
}
|
||||||
if (count > fd->sectorSize) {
|
if ((buffer_offset+count) > fd->sectorSize) {
|
||||||
sec_count = (sec_t) ceil((f64) count/fd->sectorSize);
|
sec_count = (sec_t) ceil((f64) (buffer_offset+count) / (f64) fd->sectorSize);
|
||||||
|
|
||||||
if(buffer_offset > 0)
|
|
||||||
sec_count += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this write happens to be on the sector boundaries then do the write straight to disc
|
// If this write happens to be on the sector boundaries then do the write straight to disc
|
||||||
if((offset % fd->sectorSize == 0) && (count % fd->sectorSize == 0)) {
|
if((buffer_offset == 0) && (count % fd->sectorSize == 0))
|
||||||
|
{
|
||||||
// Write to the device
|
// Write to the device
|
||||||
ntfs_log_trace("direct write to sector %d (%d sector(s) long)\n", sec_start, sec_count);
|
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)) {
|
if (!ntfs_device_gekko_io_writesectors(dev, sec_start, sec_count, buf)) {
|
||||||
@ -408,10 +402,10 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
|
|||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else write from a buffer aligned to the sector boundaries
|
// Else write from a buffer aligned to the sector boundaries
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Allocate a buffer to hold the write data
|
// Allocate a buffer to hold the write data
|
||||||
buffer = (u8 *) ntfs_alloc(sec_count * fd->sectorSize);
|
buffer = (u8 *) ntfs_alloc(sec_count * fd->sectorSize);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
@ -421,11 +415,23 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
|
|||||||
// Read the first and last sectors of the buffer from disc (if required)
|
// 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,
|
// 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
|
// we just read in the buffer edges where the data overlaps with the rest of the disc
|
||||||
if (!ntfs_device_gekko_io_readsectors(dev, sec_start, sec_count, buffer)) {
|
if(buffer_offset != 0)
|
||||||
ntfs_log_perror("read failure @ sector %d\n", sec_start);
|
{
|
||||||
ntfs_free(buffer);
|
if (!ntfs_device_gekko_io_readsectors(dev, sec_start, 1, buffer)) {
|
||||||
errno = EIO;
|
ntfs_log_perror("read failure @ sector %d\n", sec_start);
|
||||||
return -1;
|
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
|
// Copy the data into the write buffer
|
||||||
@ -445,8 +451,7 @@ static s64 ntfs_device_gekko_io_writebytes(struct ntfs_device *dev, s64 offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mark the device as dirty (if we actually wrote anything)
|
// Mark the device as dirty (if we actually wrote anything)
|
||||||
if (count > 0)
|
NDevSetDirty(dev);
|
||||||
NDevSetDirty(dev);
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -608,11 +613,6 @@ static int ntfs_device_gekko_io_ioctl(struct ntfs_device *dev, int request, void
|
|||||||
#if defined(BLKBSZSET)
|
#if defined(BLKBSZSET)
|
||||||
case BLKBSZSET: {
|
case BLKBSZSET: {
|
||||||
int sectorSize = *(int*)argp;
|
int sectorSize = *(int*)argp;
|
||||||
if (sectorSize != BYTES_PER_SECTOR) {
|
|
||||||
ntfs_log_perror("Attempt to set sector size to an unsupported value (%i), ignored\n", sectorSize);
|
|
||||||
errno = EOPNOTSUPP;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
fd->sectorSize = sectorSize;
|
fd->sectorSize = sectorSize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "cache.h"
|
#include "cache2.h"
|
||||||
#include <gccore.h>
|
#include <gccore.h>
|
||||||
#include <ogc/disc_io.h>
|
#include <ogc/disc_io.h>
|
||||||
|
|
||||||
#define BYTES_PER_SECTOR 512 /* Forced by gekko disc i/o */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gekko_fd - Gekko device driver descriptor
|
* gekko_fd - Gekko device driver descriptor
|
||||||
*/
|
*/
|
||||||
|
@ -38,9 +38,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "attrib.h"
|
#include "attrib.h"
|
||||||
#include "collate.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "index.h"
|
#include "index.h"
|
||||||
|
#include "collate.h"
|
||||||
#include "mst.h"
|
#include "mst.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
@ -517,8 +517,13 @@ static int ntfs_ie_lookup(const void *key, const int key_len,
|
|||||||
* Not a perfect match, need to do full blown collation so we
|
* Not a perfect match, need to do full blown collation so we
|
||||||
* know which way in the B+tree we have to go.
|
* know which way in the B+tree we have to go.
|
||||||
*/
|
*/
|
||||||
rc = ntfs_collate(icx->ni->vol, icx->cr, key, key_len, &ie->key,
|
if (!icx->collate) {
|
||||||
le16_to_cpu(ie->key_length));
|
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) {
|
if (rc == NTFS_COLLATION_ERROR) {
|
||||||
ntfs_log_error("Collation error. Perhaps a filename "
|
ntfs_log_error("Collation error. Perhaps a filename "
|
||||||
"contains invalid characters?\n");
|
"contains invalid characters?\n");
|
||||||
@ -697,12 +702,12 @@ int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *ic
|
|||||||
icx->vcn_size_bits = ni->vol->cluster_size_bits;
|
icx->vcn_size_bits = ni->vol->cluster_size_bits;
|
||||||
else
|
else
|
||||||
icx->vcn_size_bits = ni->vol->sector_size_bits;
|
icx->vcn_size_bits = ni->vol->sector_size_bits;
|
||||||
|
/* get the appropriate collation function */
|
||||||
icx->cr = ir->collation_rule;
|
icx->collate = ntfs_get_collate_function(ir->collation_rule);
|
||||||
if (!ntfs_is_collation_rule_supported(icx->cr)) {
|
if (!icx->collate) {
|
||||||
err = errno = EOPNOTSUPP;
|
err = errno = EOPNOTSUPP;
|
||||||
ntfs_log_perror("Unknown collation rule 0x%x",
|
ntfs_log_perror("Unknown collation rule 0x%x",
|
||||||
(unsigned)le32_to_cpu(icx->cr));
|
(unsigned)le32_to_cpu(ir->collation_rule));
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,9 @@
|
|||||||
|
|
||||||
#define MAX_PARENT_VCN 32
|
#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 -
|
* struct ntfs_index_context -
|
||||||
* @ni: inode containing the @entry described by this context
|
* @ni: inode containing the @entry described by this context
|
||||||
@ -116,7 +119,7 @@ typedef struct {
|
|||||||
INDEX_ENTRY *entry;
|
INDEX_ENTRY *entry;
|
||||||
void *data;
|
void *data;
|
||||||
u16 data_len;
|
u16 data_len;
|
||||||
COLLATION_RULES cr;
|
COLLATE collate;
|
||||||
BOOL is_in_root;
|
BOOL is_in_root;
|
||||||
INDEX_ROOT *ir;
|
INDEX_ROOT *ir;
|
||||||
ntfs_attr_search_ctx *actx;
|
ntfs_attr_search_ctx *actx;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
* Copyright (c) 2002-2008 Szabolcs Szakacsits
|
* Copyright (c) 2002-2008 Szabolcs Szakacsits
|
||||||
* Copyright (c) 2004-2007 Yura Pakhuchiy
|
* Copyright (c) 2004-2007 Yura Pakhuchiy
|
||||||
* Copyright (c) 2004-2005 Richard Russon
|
* 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
|
* This program/include file is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as published
|
* modify it under the terms of the GNU General Public License as published
|
||||||
@ -39,10 +40,13 @@
|
|||||||
#include <sys/xattr.h>
|
#include <sys/xattr.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "attrib.h"
|
#include "volume.h"
|
||||||
|
#include "cache.h"
|
||||||
#include "inode.h"
|
#include "inode.h"
|
||||||
|
#include "attrib.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "mft.h"
|
#include "mft.h"
|
||||||
#include "attrlist.h"
|
#include "attrlist.h"
|
||||||
@ -152,7 +156,7 @@ static void __ntfs_inode_release(ntfs_inode *ni)
|
|||||||
* Return a pointer to the ntfs_inode structure on success or NULL on error,
|
* Return a pointer to the ntfs_inode structure on success or NULL on error,
|
||||||
* with errno set to the error code.
|
* with errno set to the error code.
|
||||||
*/
|
*/
|
||||||
ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref)
|
static ntfs_inode *ntfs_inode_real_open(ntfs_volume *vol, const MFT_REF mref)
|
||||||
{
|
{
|
||||||
s64 l;
|
s64 l;
|
||||||
ntfs_inode *ni = NULL;
|
ntfs_inode *ni = NULL;
|
||||||
@ -190,10 +194,10 @@ ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref)
|
|||||||
std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr +
|
std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr +
|
||||||
le16_to_cpu(ctx->attr->value_offset));
|
le16_to_cpu(ctx->attr->value_offset));
|
||||||
ni->flags = std_info->file_attributes;
|
ni->flags = std_info->file_attributes;
|
||||||
ni->creation_time = ntfs2utc(std_info->creation_time);
|
ni->creation_time = std_info->creation_time;
|
||||||
ni->last_data_change_time = ntfs2utc(std_info->last_data_change_time);
|
ni->last_data_change_time = std_info->last_data_change_time;
|
||||||
ni->last_mft_change_time = ntfs2utc(std_info->last_mft_change_time);
|
ni->last_mft_change_time = std_info->last_mft_change_time;
|
||||||
ni->last_access_time = ntfs2utc(std_info->last_access_time);
|
ni->last_access_time = std_info->last_access_time;
|
||||||
/* JPA insert v3 extensions if present */
|
/* JPA insert v3 extensions if present */
|
||||||
/* length may be seen as 72 (v1.x) or 96 (v3.x) */
|
/* length may be seen as 72 (v1.x) or 96 (v3.x) */
|
||||||
lthle = ctx->attr->length;
|
lthle = ctx->attr->length;
|
||||||
@ -205,13 +209,13 @@ ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref)
|
|||||||
ni->usn = std_info->usn;
|
ni->usn = std_info->usn;
|
||||||
} else {
|
} else {
|
||||||
clear_nino_flag(ni, v3_Extensions);
|
clear_nino_flag(ni, v3_Extensions);
|
||||||
ni->owner_id = 0;
|
ni->owner_id = const_cpu_to_le32(0);
|
||||||
ni->security_id = 0;
|
ni->security_id = const_cpu_to_le32(0);
|
||||||
}
|
}
|
||||||
/* Set attribute list information. */
|
/* Set attribute list information. */
|
||||||
olderrno = errno;
|
olderrno = errno;
|
||||||
if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0, 0, 0, NULL, 0,
|
if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, AT_UNNAMED, 0,
|
||||||
ctx)) {
|
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
goto put_err_out;
|
goto put_err_out;
|
||||||
/* Attribute list attribute does not present. */
|
/* Attribute list attribute does not present. */
|
||||||
@ -266,6 +270,7 @@ get_size:
|
|||||||
ni->data_size = le32_to_cpu(ctx->attr->value_length);
|
ni->data_size = le32_to_cpu(ctx->attr->value_length);
|
||||||
ni->allocated_size = (ni->data_size + 7) & ~7;
|
ni->allocated_size = (ni->data_size + 7) & ~7;
|
||||||
}
|
}
|
||||||
|
set_nino_flag(ni,KnownSize);
|
||||||
}
|
}
|
||||||
ntfs_attr_put_search_ctx(ctx);
|
ntfs_attr_put_search_ctx(ctx);
|
||||||
out:
|
out:
|
||||||
@ -304,7 +309,8 @@ err_out:
|
|||||||
* EINVAL @ni is invalid (probably it is an extent inode).
|
* EINVAL @ni is invalid (probably it is an extent inode).
|
||||||
* EIO I/O error while trying to write inode to disk.
|
* EIO I/O error while trying to write inode to disk.
|
||||||
*/
|
*/
|
||||||
int ntfs_inode_close(ntfs_inode *ni)
|
|
||||||
|
int ntfs_inode_real_close(ntfs_inode *ni)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -324,7 +330,7 @@ int ntfs_inode_close(ntfs_inode *ni)
|
|||||||
/* Is this a base inode with mapped extent inodes? */
|
/* Is this a base inode with mapped extent inodes? */
|
||||||
if (ni->nr_extents > 0) {
|
if (ni->nr_extents > 0) {
|
||||||
while (ni->nr_extents > 0) {
|
while (ni->nr_extents > 0) {
|
||||||
if (ntfs_inode_close(ni->extent_nis[0])) {
|
if (ntfs_inode_real_close(ni->extent_nis[0])) {
|
||||||
if (errno != EIO)
|
if (errno != EIO)
|
||||||
errno = EBUSY;
|
errno = EBUSY;
|
||||||
goto err;
|
goto err;
|
||||||
@ -364,8 +370,10 @@ int ntfs_inode_close(ntfs_inode *ni)
|
|||||||
/* Ignore errors, they don't really matter. */
|
/* Ignore errors, they don't really matter. */
|
||||||
if (tmp_nis)
|
if (tmp_nis)
|
||||||
base_ni->extent_nis = tmp_nis;
|
base_ni->extent_nis = tmp_nis;
|
||||||
} else if (tmp_nis)
|
} else if (tmp_nis) {
|
||||||
free(tmp_nis);
|
free(tmp_nis);
|
||||||
|
base_ni->extent_nis = (ntfs_inode**)NULL;
|
||||||
|
}
|
||||||
/* Allow for error checking. */
|
/* Allow for error checking. */
|
||||||
i = -1;
|
i = -1;
|
||||||
break;
|
break;
|
||||||
@ -387,6 +395,154 @@ err:
|
|||||||
return ret;
|
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
|
* ntfs_extent_inode_open - load an extent inode and attach it to its base
|
||||||
* @base_ni: base ntfs inode
|
* @base_ni: base ntfs inode
|
||||||
@ -561,11 +717,11 @@ static int ntfs_inode_sync_standard_information(ntfs_inode *ni)
|
|||||||
std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr +
|
std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr +
|
||||||
le16_to_cpu(ctx->attr->value_offset));
|
le16_to_cpu(ctx->attr->value_offset));
|
||||||
std_info->file_attributes = ni->flags;
|
std_info->file_attributes = ni->flags;
|
||||||
if (test_nino_flag(ni, TimesDirty)) {
|
if (!test_nino_flag(ni, TimesSet)) {
|
||||||
std_info->creation_time = utc2ntfs(ni->creation_time);
|
std_info->creation_time = ni->creation_time;
|
||||||
std_info->last_data_change_time = utc2ntfs(ni->last_data_change_time);
|
std_info->last_data_change_time = ni->last_data_change_time;
|
||||||
std_info->last_mft_change_time = utc2ntfs(ni->last_mft_change_time);
|
std_info->last_mft_change_time = ni->last_mft_change_time;
|
||||||
std_info->last_access_time = utc2ntfs(ni->last_access_time);
|
std_info->last_access_time = ni->last_access_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* JPA update v3.x extensions, ensuring consistency */
|
/* JPA update v3.x extensions, ensuring consistency */
|
||||||
@ -595,12 +751,15 @@ static int ntfs_inode_sync_standard_information(ntfs_inode *ni)
|
|||||||
*
|
*
|
||||||
* Return 0 on success or -1 on error with errno set to the error code.
|
* 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)
|
static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni)
|
||||||
{
|
{
|
||||||
ntfs_attr_search_ctx *ctx = NULL;
|
ntfs_attr_search_ctx *ctx = NULL;
|
||||||
ntfs_index_context *ictx;
|
ntfs_index_context *ictx;
|
||||||
ntfs_inode *index_ni;
|
ntfs_inode *index_ni;
|
||||||
FILE_NAME_ATTR *fn;
|
FILE_NAME_ATTR *fn;
|
||||||
|
FILE_NAME_ATTR *fnx;
|
||||||
|
REPARSE_POINT *rpp;
|
||||||
|
le32 reparse_tag;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
ntfs_log_trace("Entering for inode %lld\n", (long long)ni->mft_no);
|
ntfs_log_trace("Entering for inode %lld\n", (long long)ni->mft_no);
|
||||||
@ -610,6 +769,17 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni)
|
|||||||
err = errno;
|
err = errno;
|
||||||
goto err_out;
|
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. */
|
/* Walk through all FILE_NAME attributes and update them. */
|
||||||
while (!ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) {
|
while (!ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) {
|
||||||
fn = (FILE_NAME_ATTR *)((u8 *)ctx->attr +
|
fn = (FILE_NAME_ATTR *)((u8 *)ctx->attr +
|
||||||
@ -624,7 +794,10 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni)
|
|||||||
*/
|
*/
|
||||||
index_ni = ni;
|
index_ni = ni;
|
||||||
} else
|
} else
|
||||||
index_ni = ntfs_inode_open(ni->vol,
|
if (dir_ni)
|
||||||
|
index_ni = dir_ni;
|
||||||
|
else
|
||||||
|
index_ni = ntfs_inode_open(ni->vol,
|
||||||
le64_to_cpu(fn->parent_directory));
|
le64_to_cpu(fn->parent_directory));
|
||||||
if (!index_ni) {
|
if (!index_ni) {
|
||||||
if (!err)
|
if (!err)
|
||||||
@ -639,7 +812,8 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni)
|
|||||||
err = errno;
|
err = errno;
|
||||||
ntfs_log_perror("Failed to get index ctx, inode %lld",
|
ntfs_log_perror("Failed to get index ctx, inode %lld",
|
||||||
(long long)index_ni->mft_no);
|
(long long)index_ni->mft_no);
|
||||||
if (ni != index_ni && ntfs_inode_close(index_ni) && !err)
|
if ((ni != index_ni) && !dir_ni
|
||||||
|
&& ntfs_inode_close(index_ni) && !err)
|
||||||
err = errno;
|
err = errno;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -658,21 +832,34 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Update flags and file size. */
|
/* Update flags and file size. */
|
||||||
fn = (FILE_NAME_ATTR *)ictx->data;
|
fnx = (FILE_NAME_ATTR *)ictx->data;
|
||||||
fn->file_attributes =
|
fnx->file_attributes =
|
||||||
(fn->file_attributes & ~FILE_ATTR_VALID_FLAGS) |
|
(fnx->file_attributes & ~FILE_ATTR_VALID_FLAGS) |
|
||||||
(ni->flags & FILE_ATTR_VALID_FLAGS);
|
(ni->flags & FILE_ATTR_VALID_FLAGS);
|
||||||
fn->allocated_size = cpu_to_sle64(ni->allocated_size);
|
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|
||||||
fn->data_size = cpu_to_sle64(ni->data_size);
|
fnx->data_size = fnx->allocated_size
|
||||||
if (test_nino_flag(ni, TimesDirty)) {
|
= const_cpu_to_le64(0);
|
||||||
fn->creation_time = utc2ntfs(ni->creation_time);
|
else {
|
||||||
fn->last_data_change_time = utc2ntfs(ni->last_data_change_time);
|
fnx->allocated_size = cpu_to_sle64(ni->allocated_size);
|
||||||
fn->last_mft_change_time = utc2ntfs(ni->last_mft_change_time);
|
fnx->data_size = cpu_to_sle64(ni->data_size);
|
||||||
fn->last_access_time = utc2ntfs(ni->last_access_time);
|
}
|
||||||
|
/* 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_entry_mark_dirty(ictx);
|
||||||
ntfs_index_ctx_put(ictx);
|
ntfs_index_ctx_put(ictx);
|
||||||
if ((ni != index_ni) && ntfs_inode_close(index_ni) && !err)
|
if ((ni != index_ni) && !dir_ni
|
||||||
|
&& ntfs_inode_close(index_ni) && !err)
|
||||||
err = errno;
|
err = errno;
|
||||||
}
|
}
|
||||||
/* Check for real error occurred. */
|
/* Check for real error occurred. */
|
||||||
@ -714,11 +901,10 @@ err_out:
|
|||||||
* EBUSY - Inode and/or one of its extents is busy, try again later.
|
* 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).
|
* EIO - I/O error while writing the inode (or one of its extents).
|
||||||
*/
|
*/
|
||||||
int ntfs_inode_sync(ntfs_inode *ni)
|
static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
if (!ni) {
|
if (!ni) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
ntfs_log_error("Failed to sync NULL inode\n");
|
ntfs_log_error("Failed to sync NULL inode\n");
|
||||||
@ -740,7 +926,7 @@ int ntfs_inode_sync(ntfs_inode *ni)
|
|||||||
/* Update FILE_NAME's in the index. */
|
/* Update FILE_NAME's in the index. */
|
||||||
if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 &&
|
if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 &&
|
||||||
NInoFileNameTestAndClearDirty(ni) &&
|
NInoFileNameTestAndClearDirty(ni) &&
|
||||||
ntfs_inode_sync_file_name(ni)) {
|
ntfs_inode_sync_file_name(ni, dir_ni)) {
|
||||||
if (!err || errno == EIO) {
|
if (!err || errno == EIO) {
|
||||||
err = errno;
|
err = errno;
|
||||||
if (err != EIO)
|
if (err != EIO)
|
||||||
@ -843,6 +1029,28 @@ sync_inode:
|
|||||||
return ret;
|
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
|
* ntfs_inode_add_attrlist - add attribute list to inode and fill it
|
||||||
* @ni: opened ntfs inode to which add attribute list
|
* @ni: opened ntfs inode to which add attribute list
|
||||||
@ -1129,7 +1337,7 @@ put_err_out:
|
|||||||
*/
|
*/
|
||||||
void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
|
void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
|
||||||
{
|
{
|
||||||
time_t now;
|
ntfs_time now;
|
||||||
|
|
||||||
if (!ni) {
|
if (!ni) {
|
||||||
ntfs_log_error("%s(): Invalid arguments.\n", __FUNCTION__);
|
ntfs_log_error("%s(): Invalid arguments.\n", __FUNCTION__);
|
||||||
@ -1140,7 +1348,7 @@ void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
|
|||||||
NVolReadOnly(ni->vol) || !mask)
|
NVolReadOnly(ni->vol) || !mask)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
now = time(NULL);
|
now = ntfs_current_time();
|
||||||
if (mask & NTFS_UPDATE_ATIME)
|
if (mask & NTFS_UPDATE_ATIME)
|
||||||
ni->last_access_time = now;
|
ni->last_access_time = now;
|
||||||
if (mask & NTFS_UPDATE_MTIME)
|
if (mask & NTFS_UPDATE_MTIME)
|
||||||
@ -1148,7 +1356,6 @@ void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
|
|||||||
if (mask & NTFS_UPDATE_CTIME)
|
if (mask & NTFS_UPDATE_CTIME)
|
||||||
ni->last_mft_change_time = now;
|
ni->last_mft_change_time = now;
|
||||||
|
|
||||||
set_nino_flag(ni, TimesDirty);
|
|
||||||
NInoFileNameSetDirty(ni);
|
NInoFileNameSetDirty(ni);
|
||||||
NInoSetDirty(ni);
|
NInoSetDirty(ni);
|
||||||
}
|
}
|
||||||
@ -1209,8 +1416,7 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr)
|
|||||||
* -errno if failed
|
* -errno if failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_inode_get_times(const char *path __attribute__((unused)),
|
int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size)
|
||||||
char *value, size_t size, ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
ntfs_attr_search_ctx *ctx;
|
ntfs_attr_search_ctx *ctx;
|
||||||
STANDARD_INFORMATION *std_info;
|
STANDARD_INFORMATION *std_info;
|
||||||
@ -1268,22 +1474,21 @@ int ntfs_inode_get_times(const char *path __attribute__((unused)),
|
|||||||
* -1 if there were an error (described by errno)
|
* -1 if there were an error (described by errno)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_inode_set_times(const char *path __attribute__((unused)),
|
int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size,
|
||||||
const char *value, size_t size,
|
int flags)
|
||||||
int flags, ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
ntfs_attr_search_ctx *ctx;
|
ntfs_attr_search_ctx *ctx;
|
||||||
STANDARD_INFORMATION *std_info;
|
STANDARD_INFORMATION *std_info;
|
||||||
FILE_NAME_ATTR *fn;
|
FILE_NAME_ATTR *fn;
|
||||||
const u64 *times;
|
const u64 *times;
|
||||||
le64 now;
|
ntfs_time now;
|
||||||
int cnt;
|
int cnt;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
if ((size >= 8) && !(flags & XATTR_CREATE)) {
|
if ((size >= 8) && !(flags & XATTR_CREATE)) {
|
||||||
times = (const u64*)value;
|
times = (const u64*)value;
|
||||||
now = utc2ntfs(time((time_t*)NULL));
|
now = ntfs_current_time();
|
||||||
/* update the standard information attribute */
|
/* update the standard information attribute */
|
||||||
ctx = ntfs_attr_get_search_ctx(ni, NULL);
|
ctx = ntfs_attr_get_search_ctx(ni, NULL);
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
@ -1296,16 +1501,31 @@ int ntfs_inode_set_times(const char *path __attribute__((unused)),
|
|||||||
std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr +
|
std_info = (STANDARD_INFORMATION *)((u8 *)ctx->attr +
|
||||||
le16_to_cpu(ctx->attr->value_offset));
|
le16_to_cpu(ctx->attr->value_offset));
|
||||||
/*
|
/*
|
||||||
* Do not mark times dirty to avoid
|
* Mark times set to avoid overwriting
|
||||||
* overwriting them when the inode is closed.
|
* 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]);
|
std_info->creation_time = cpu_to_le64(times[0]);
|
||||||
if (size >= 16)
|
ni->creation_time
|
||||||
|
= std_info->creation_time;
|
||||||
|
if (size >= 16) {
|
||||||
std_info->last_data_change_time = cpu_to_le64(times[1]);
|
std_info->last_data_change_time = cpu_to_le64(times[1]);
|
||||||
if (size >= 24)
|
ni->last_data_change_time
|
||||||
|
= std_info->last_data_change_time;
|
||||||
|
}
|
||||||
|
if (size >= 24) {
|
||||||
std_info->last_access_time = cpu_to_le64(times[2]);
|
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;
|
std_info->last_mft_change_time = now;
|
||||||
|
ni->last_mft_change_time = now;
|
||||||
ntfs_inode_mark_dirty(ctx->ntfs_ino);
|
ntfs_inode_mark_dirty(ctx->ntfs_ino);
|
||||||
|
NInoFileNameSetDirty(ni);
|
||||||
|
|
||||||
/* update the file names attributes */
|
/* update the file names attributes */
|
||||||
ntfs_attr_reinit_search_ctx(ctx);
|
ntfs_attr_reinit_search_ctx(ctx);
|
||||||
@ -1315,10 +1535,6 @@ int ntfs_inode_set_times(const char *path __attribute__((unused)),
|
|||||||
0, NULL, 0, ctx)) {
|
0, NULL, 0, ctx)) {
|
||||||
fn = (FILE_NAME_ATTR*)((u8 *)ctx->attr +
|
fn = (FILE_NAME_ATTR*)((u8 *)ctx->attr +
|
||||||
le16_to_cpu(ctx->attr->value_offset));
|
le16_to_cpu(ctx->attr->value_offset));
|
||||||
/*
|
|
||||||
* Do not mark times dirty to avoid
|
|
||||||
* overwriting them when the inode is closed.
|
|
||||||
*/
|
|
||||||
fn->creation_time
|
fn->creation_time
|
||||||
= cpu_to_le64(times[0]);
|
= cpu_to_le64(times[0]);
|
||||||
if (size >= 16)
|
if (size >= 16)
|
||||||
|
@ -32,6 +32,7 @@ typedef struct _ntfs_inode ntfs_inode;
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
#include "volume.h"
|
#include "volume.h"
|
||||||
|
#include "ntfstime.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enum ntfs_inode_state_bits -
|
* enum ntfs_inode_state_bits -
|
||||||
@ -49,7 +50,8 @@ typedef enum {
|
|||||||
NI_FileNameDirty, /* 1: FILE_NAME attributes need to be updated
|
NI_FileNameDirty, /* 1: FILE_NAME attributes need to be updated
|
||||||
in the index. */
|
in the index. */
|
||||||
NI_v3_Extensions, /* 1: JPA v3.x extensions present. */
|
NI_v3_Extensions, /* 1: JPA v3.x extensions present. */
|
||||||
NI_TimesDirty, /* 1: Times need to be updated */
|
NI_TimesSet, /* 1: Use times which were set */
|
||||||
|
NI_KnownSize, /* 1: Set if sizes are meaningful */
|
||||||
} ntfs_inode_state_bits;
|
} ntfs_inode_state_bits;
|
||||||
|
|
||||||
#define test_nino_flag(ni, flag) test_bit(NI_##flag, (ni)->state)
|
#define test_nino_flag(ni, flag) test_bit(NI_##flag, (ni)->state)
|
||||||
@ -135,8 +137,11 @@ struct _ntfs_inode {
|
|||||||
* These two fields are used to sync filename index and guaranteed to be
|
* These two fields are used to sync filename index and guaranteed to be
|
||||||
* correct, however value in index itself maybe wrong (windows itself
|
* correct, however value in index itself maybe wrong (windows itself
|
||||||
* do not update them properly).
|
* 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. */
|
s64 data_size; /* Data size of unnamed DATA attribute
|
||||||
|
(or INDEX_ROOT for directories) */
|
||||||
s64 allocated_size; /* Allocated size stored in the filename
|
s64 allocated_size; /* Allocated size stored in the filename
|
||||||
index. (NOTE: Equal to allocated size of
|
index. (NOTE: Equal to allocated size of
|
||||||
the unnamed data attribute for normal or
|
the unnamed data attribute for normal or
|
||||||
@ -149,10 +154,10 @@ struct _ntfs_inode {
|
|||||||
* STANDARD_INFORMATION attribute and used to sync it and FILE_NAME
|
* STANDARD_INFORMATION attribute and used to sync it and FILE_NAME
|
||||||
* attribute in the index.
|
* attribute in the index.
|
||||||
*/
|
*/
|
||||||
time_t creation_time;
|
ntfs_time creation_time;
|
||||||
time_t last_data_change_time;
|
ntfs_time last_data_change_time;
|
||||||
time_t last_mft_change_time;
|
ntfs_time last_mft_change_time;
|
||||||
time_t last_access_time;
|
ntfs_time last_access_time;
|
||||||
/* NTFS 3.x extensions added by JPA */
|
/* NTFS 3.x extensions added by JPA */
|
||||||
/* only if NI_v3_Extensions is set in state */
|
/* only if NI_v3_Extensions is set in state */
|
||||||
le32 owner_id;
|
le32 owner_id;
|
||||||
@ -177,6 +182,19 @@ extern ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol);
|
|||||||
extern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref);
|
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(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,
|
extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni,
|
||||||
const MFT_REF mref);
|
const MFT_REF mref);
|
||||||
@ -195,9 +213,13 @@ 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_badclus_bad(u64 mft_no, ATTR_RECORD *a);
|
||||||
|
|
||||||
extern int ntfs_inode_get_times(const char *path, char *value,
|
extern int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size);
|
||||||
size_t size, ntfs_inode *ni);
|
|
||||||
extern int ntfs_inode_set_times(const char *path, const char *value,
|
extern int ntfs_inode_set_times(ntfs_inode *ni, const char *value,
|
||||||
size_t size, int flags, ntfs_inode *ni);
|
size_t size, int flags);
|
||||||
|
|
||||||
|
/* debugging */
|
||||||
|
#define debug_double_inode(num, type)
|
||||||
|
#define debug_cached_inode(ni)
|
||||||
|
|
||||||
#endif /* defined _NTFS_INODE_H */
|
#endif /* defined _NTFS_INODE_H */
|
||||||
|
@ -473,7 +473,7 @@ done_zones_check:
|
|||||||
ntfs_log_trace("Switching zone.\n");
|
ntfs_log_trace("Switching zone.\n");
|
||||||
pass = 1;
|
pass = 1;
|
||||||
if (rlpos) {
|
if (rlpos) {
|
||||||
LCN tc = tc = rl[rlpos - 1].lcn +
|
LCN tc = rl[rlpos - 1].lcn +
|
||||||
rl[rlpos - 1].length + NTFS_LCNALLOC_SKIP;
|
rl[rlpos - 1].length + NTFS_LCNALLOC_SKIP;
|
||||||
|
|
||||||
if (used_zone_pos)
|
if (used_zone_pos)
|
||||||
@ -609,6 +609,42 @@ out:
|
|||||||
return ret;
|
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
|
* ntfs_cluster_free - free clusters on an ntfs volume
|
||||||
* @vol: mounted ntfs volume on which to free the clusters
|
* @vol: mounted ntfs volume on which to free the clusters
|
||||||
|
@ -42,6 +42,7 @@ extern runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
|||||||
LCN start_lcn, const NTFS_CLUSTER_ALLOCATION_ZONES zone);
|
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_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,
|
extern int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn,
|
||||||
s64 count);
|
s64 count);
|
||||||
|
@ -699,8 +699,8 @@ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp)
|
|||||||
*/
|
*/
|
||||||
int ntfs_empty_logfile(ntfs_attr *na)
|
int ntfs_empty_logfile(ntfs_attr *na)
|
||||||
{
|
{
|
||||||
/*s64 pos, count;
|
s64 pos, count;
|
||||||
char buf[NTFS_BUF_SIZE];*/
|
char buf[NTFS_BUF_SIZE];
|
||||||
|
|
||||||
ntfs_log_trace("Entering.\n");
|
ntfs_log_trace("Entering.\n");
|
||||||
|
|
||||||
@ -713,7 +713,7 @@ int ntfs_empty_logfile(ntfs_attr *na)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*memset(buf, -1, NTFS_BUF_SIZE);
|
memset(buf, -1, NTFS_BUF_SIZE);
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
while ((count = na->data_size - pos) > 0) {
|
while ((count = na->data_size - pos) > 0) {
|
||||||
@ -729,7 +729,7 @@ int ntfs_empty_logfile(ntfs_attr *na)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pos += count;
|
pos += count;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
NVolSetLogFileEmpty(na->ni->vol);
|
NVolSetLogFileEmpty(na->ni->vol);
|
||||||
|
|
||||||
|
@ -1478,8 +1478,7 @@ found_free_rec:
|
|||||||
ni->flags = 0;
|
ni->flags = 0;
|
||||||
ni->creation_time = ni->last_data_change_time =
|
ni->creation_time = ni->last_data_change_time =
|
||||||
ni->last_mft_change_time =
|
ni->last_mft_change_time =
|
||||||
ni->last_access_time = time(NULL);
|
ni->last_access_time = ntfs_current_time();
|
||||||
set_nino_flag(ni, TimesDirty);
|
|
||||||
/* Update the default mft allocation position if it was used. */
|
/* Update the default mft allocation position if it was used. */
|
||||||
if (!base_ni)
|
if (!base_ni)
|
||||||
vol->mft_data_pos = bit + 1;
|
vol->mft_data_pos = bit + 1;
|
||||||
@ -1781,8 +1780,7 @@ found_free_rec:
|
|||||||
ni->flags = 0;
|
ni->flags = 0;
|
||||||
ni->creation_time = ni->last_data_change_time =
|
ni->creation_time = ni->last_data_change_time =
|
||||||
ni->last_mft_change_time =
|
ni->last_mft_change_time =
|
||||||
ni->last_access_time = time(NULL);
|
ni->last_access_time = ntfs_current_time();
|
||||||
set_nino_flag(ni, TimesDirty);
|
|
||||||
/* Update the default mft allocation position if it was used. */
|
/* Update the default mft allocation position if it was used. */
|
||||||
if (!base_ni)
|
if (!base_ni)
|
||||||
vol->mft_data_pos = bit + 1;
|
vol->mft_data_pos = bit + 1;
|
||||||
@ -1862,7 +1860,11 @@ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Throw away the now freed inode. */
|
/* Throw away the now freed inode. */
|
||||||
|
#if CACHE_NIDATA_SIZE
|
||||||
|
if (!ntfs_inode_real_close(ni)) {
|
||||||
|
#else
|
||||||
if (!ntfs_inode_close(ni)) {
|
if (!ntfs_inode_close(ni)) {
|
||||||
|
#endif
|
||||||
vol->free_mft_records++;
|
vol->free_mft_records++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* misc.c : miscellaneous :
|
* misc.c : miscellaneous :
|
||||||
* - dealing with errors in memory allocation
|
* - dealing with errors in memory allocation
|
||||||
* - data caching
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008 Jean-Pierre Andre
|
* Copyright (c) 2008 Jean-Pierre Andre
|
||||||
*
|
*
|
||||||
@ -33,7 +32,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "security.h"
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
@ -61,304 +59,3 @@ void *ntfs_malloc(size_t size)
|
|||||||
ntfs_log_perror("Failed to malloc %lld bytes", (long long)size);
|
ntfs_log_perror("Failed to malloc %lld bytes", (long long)size);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Fetch an entry from cache
|
|
||||||
*
|
|
||||||
* returns the cache entry, or NULL if not available
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
current = (struct CACHED_GENERIC*)NULL;
|
|
||||||
if (cache) {
|
|
||||||
/*
|
|
||||||
* Search sequentially in LRU list
|
|
||||||
*/
|
|
||||||
current = cache->most_recent_entry;
|
|
||||||
previous = (struct CACHED_GENERIC*)NULL;
|
|
||||||
while (current
|
|
||||||
&& compare(current, wanted)) {
|
|
||||||
previous = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
if (current)
|
|
||||||
cache->hits++;
|
|
||||||
if (current && previous) {
|
|
||||||
/*
|
|
||||||
* found and not at head of list, unlink from current
|
|
||||||
* position and relink as head of list
|
|
||||||
*/
|
|
||||||
previous->next = current->next;
|
|
||||||
current->next = cache->most_recent_entry;
|
|
||||||
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 *previous;
|
|
||||||
struct CACHED_GENERIC *before;
|
|
||||||
|
|
||||||
current = (struct CACHED_GENERIC*)NULL;
|
|
||||||
if (cache) {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
previous = (struct CACHED_GENERIC*)NULL;
|
|
||||||
before = (struct CACHED_GENERIC*)NULL;
|
|
||||||
while (current
|
|
||||||
&& compare(current, item)) {
|
|
||||||
before = previous;
|
|
||||||
previous = current;
|
|
||||||
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;
|
|
||||||
} else {
|
|
||||||
before->next = (struct CACHED_GENERIC*)NULL;
|
|
||||||
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;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cache->writes++;
|
|
||||||
}
|
|
||||||
return (current);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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)
|
|
||||||
{
|
|
||||||
struct CACHED_GENERIC *current;
|
|
||||||
struct CACHED_GENERIC *previous;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
current = (struct CACHED_GENERIC*)NULL;
|
|
||||||
count = 0;
|
|
||||||
if (cache) {
|
|
||||||
/*
|
|
||||||
* Search sequentially in LRU list
|
|
||||||
*/
|
|
||||||
current = cache->most_recent_entry;
|
|
||||||
previous = (struct CACHED_GENERIC*)NULL;
|
|
||||||
while (current) {
|
|
||||||
if (!compare(current, item)) {
|
|
||||||
/*
|
|
||||||
* Relink into free list
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
if (previous)
|
|
||||||
current = previous->next;
|
|
||||||
else
|
|
||||||
current = cache->most_recent_entry;
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
previous = current;
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 (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,
|
|
||||||
int full_item_size, int item_count)
|
|
||||||
{
|
|
||||||
struct CACHE_HEADER *cache;
|
|
||||||
struct CACHED_GENERIC *p;
|
|
||||||
struct CACHED_GENERIC *q;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
cache = (struct CACHE_HEADER*)
|
|
||||||
ntfs_malloc(sizeof(struct CACHE_HEADER)
|
|
||||||
+ item_count*full_item_size);
|
|
||||||
if (cache) {
|
|
||||||
cache->name = name;
|
|
||||||
cache->fixed_size = full_item_size - sizeof(struct CACHED_GENERIC);
|
|
||||||
cache->reads = 0;
|
|
||||||
cache->writes = 0;
|
|
||||||
cache->hits = 0;
|
|
||||||
/* chain the entries, and mark an invalid entry */
|
|
||||||
cache->most_recent_entry = (struct CACHED_GENERIC*)NULL;
|
|
||||||
cache->free_entry = &cache->entry[0];
|
|
||||||
p = &cache->entry[0];
|
|
||||||
for (i=0; i<(item_count - 1); i++) {
|
|
||||||
q = (struct CACHED_GENERIC*)((char*)p + full_item_size);
|
|
||||||
p->next = q;
|
|
||||||
p->variable = (void*)NULL;
|
|
||||||
p->varsize = 0;
|
|
||||||
p = q;
|
|
||||||
}
|
|
||||||
/* special for the last entry */
|
|
||||||
p->next = (struct CACHED_GENERIC*)NULL;
|
|
||||||
p->variable = (void*)NULL;
|
|
||||||
p->varsize = 0;
|
|
||||||
}
|
|
||||||
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",
|
|
||||||
sizeof(struct CACHED_INODE), CACHE_INODE_SIZE);
|
|
||||||
#endif
|
|
||||||
vol->securid_cache = ntfs_create_cache("securid",
|
|
||||||
sizeof(struct CACHED_SECURID), CACHE_SECURID_SIZE);
|
|
||||||
#if CACHE_LEGACY_SIZE
|
|
||||||
vol->legacy_cache = ntfs_create_cache("legacy",
|
|
||||||
sizeof(struct CACHED_PERMISSIONS_LEGACY), CACHE_LEGACY_SIZE);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Free all LRU caches
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ntfs_free_lru_caches(ntfs_volume *vol)
|
|
||||||
{
|
|
||||||
#if CACHE_INODE_SIZE
|
|
||||||
ntfs_free_cache(vol->xinode_cache);
|
|
||||||
#endif
|
|
||||||
ntfs_free_cache(vol->securid_cache);
|
|
||||||
#if CACHE_LEGACY_SIZE
|
|
||||||
ntfs_free_cache(vol->legacy_cache);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* misc.h : miscellaneous exports
|
* misc.h : miscellaneous exports
|
||||||
* - memory allocation
|
* - memory allocation
|
||||||
* - LRU caches
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008 Jean-Pierre Andre
|
* Copyright (c) 2008 Jean-Pierre Andre
|
||||||
*
|
*
|
||||||
@ -24,49 +23,6 @@
|
|||||||
#ifndef _NTFS_MISC_H_
|
#ifndef _NTFS_MISC_H_
|
||||||
#define _NTFS_MISC_H_
|
#define _NTFS_MISC_H_
|
||||||
|
|
||||||
#include "volume.h"
|
|
||||||
|
|
||||||
struct CACHED_GENERIC {
|
|
||||||
struct CACHED_GENERIC *next;
|
|
||||||
void *variable;
|
|
||||||
size_t varsize;
|
|
||||||
void *fixed[0];
|
|
||||||
} ;
|
|
||||||
|
|
||||||
struct CACHED_INODE {
|
|
||||||
struct CACHED_INODE *next;
|
|
||||||
const char *pathname;
|
|
||||||
size_t varsize;
|
|
||||||
/* above fields must match "struct CACHED_GENERIC" */
|
|
||||||
u64 inum;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
typedef int (*cache_compare)(const struct CACHED_GENERIC *cached,
|
|
||||||
const struct CACHED_GENERIC *item);
|
|
||||||
|
|
||||||
struct CACHE_HEADER {
|
|
||||||
const char *name;
|
|
||||||
struct CACHED_GENERIC *most_recent_entry;
|
|
||||||
struct CACHED_GENERIC *free_entry;
|
|
||||||
unsigned long reads;
|
|
||||||
unsigned long writes;
|
|
||||||
unsigned long hits;
|
|
||||||
int fixed_size;
|
|
||||||
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);
|
|
||||||
void ntfs_create_lru_caches(ntfs_volume *vol);
|
|
||||||
void ntfs_free_lru_caches(ntfs_volume *vol);
|
|
||||||
|
|
||||||
void *ntfs_calloc(size_t size);
|
void *ntfs_calloc(size_t size);
|
||||||
void *ntfs_malloc(size_t size);
|
void *ntfs_malloc(size_t size);
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ int ntfsFindPartitions (const DISC_INTERFACE *interface, sec_t **partitions)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
u8 buffer[BYTES_PER_SECTOR];
|
u8 buffer[512];
|
||||||
MASTER_BOOT_RECORD mbr;
|
MASTER_BOOT_RECORD mbr;
|
||||||
EXTENDED_BOOT_RECORD ebr;
|
EXTENDED_BOOT_RECORD ebr;
|
||||||
NTFS_BOOT_SECTOR boot;
|
NTFS_BOOT_SECTOR boot;
|
||||||
@ -419,7 +419,7 @@ bool ntfsMount (const char *name, const DISC_INTERFACE *interface, sec_t startSe
|
|||||||
// Sanity check
|
// Sanity check
|
||||||
if (!name || !interface) {
|
if (!name || !interface) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise ntfs-3g
|
// Initialise ntfs-3g
|
||||||
|
@ -139,18 +139,6 @@ extern const char *ntfsGetVolumeName (const char *name);
|
|||||||
*/
|
*/
|
||||||
extern bool ntfsSetVolumeName (const char *name, const char *volumeName);
|
extern bool ntfsSetVolumeName (const char *name, const char *volumeName);
|
||||||
|
|
||||||
/*
|
|
||||||
typedef struct _FileInfo FileInfo;
|
|
||||||
|
|
||||||
struct _FileInfo
|
|
||||||
{
|
|
||||||
u64 offset[64];
|
|
||||||
s64 sector[64];
|
|
||||||
u64 count[64];
|
|
||||||
u32 num;
|
|
||||||
u64 filesize;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
typedef int (*_ntfs_frag_append_t)(void *ff, u32 offset, u32 sector, u32 count);
|
typedef int (*_ntfs_frag_append_t)(void *ff, u32 offset, u32 sector, u32 count);
|
||||||
int _NTFS_get_fragments (const char *path, _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);
|
||||||
|
|
||||||
|
@ -402,19 +402,22 @@ int ntfs_readdir_filler (DIR_ITER *dirState, const ntfschar *name, const int nam
|
|||||||
|
|
||||||
// Convert the entry name to our current local
|
// Convert the entry name to our current local
|
||||||
if (ntfsUnicodeToLocal(name, name_len, &entry_name, 0) < 0) {
|
if (ntfsUnicodeToLocal(name, name_len, &entry_name, 0) < 0) {
|
||||||
ntfs_free(entry);
|
|
||||||
return -1;
|
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 this is not the parent or self directory reference
|
||||||
if ((strcmp(entry_name, ".") != 0) && (strcmp(entry_name, "..") != 0)) {
|
if ((strcmp(entry_name, ".") != 0) && (strcmp(entry_name, "..") != 0)) {
|
||||||
|
|
||||||
// Open the entry
|
// Open the entry
|
||||||
ntfs_inode *ni = ntfs_pathname_to_inode(dir->vd->vol, dir->ni, entry_name);
|
ntfs_inode *ni = ntfs_pathname_to_inode(dir->vd->vol, dir->ni, entry_name);
|
||||||
if (!ni) {
|
if (!ni)
|
||||||
ntfs_free(entry);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
// Double check that this entry can be emuerated (as described by the volume descriptor)
|
// Double check that this entry can be emuerated (as described by the volume descriptor)
|
||||||
if (((ni->flags & FILE_ATTR_HIDDEN) && !dir->vd->showHiddenFiles) ||
|
if (((ni->flags & FILE_ATTR_HIDDEN) && !dir->vd->showHiddenFiles) ||
|
||||||
@ -429,13 +432,14 @@ int ntfs_readdir_filler (DIR_ITER *dirState, const ntfschar *name, const int nam
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a new directory entry
|
// Allocate a new directory entry
|
||||||
entry = ntfs_alloc(sizeof(ntfs_dir_entry));
|
entry = (ntfs_dir_entry *) ntfs_alloc(sizeof(ntfs_dir_entry));
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Setup the entry
|
// Setup the entry
|
||||||
entry->name = entry_name;
|
entry->name = entry_name;
|
||||||
entry->next = NULL;
|
entry->next = NULL;
|
||||||
|
entry->mref = MREF(mref);
|
||||||
|
|
||||||
// Link the entry to the directory
|
// Link the entry to the directory
|
||||||
if (!dir->first) {
|
if (!dir->first) {
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
typedef struct _ntfs_dir_entry {
|
typedef struct _ntfs_dir_entry {
|
||||||
char *name;
|
char *name;
|
||||||
|
u64 mref;
|
||||||
struct _ntfs_dir_entry *next;
|
struct _ntfs_dir_entry *next;
|
||||||
} ntfs_dir_entry;
|
} ntfs_dir_entry;
|
||||||
|
|
||||||
|
@ -65,8 +65,8 @@ void ntfsCloseFile (ntfs_file_state *file)
|
|||||||
// Sync the file (and its attributes) to disc
|
// Sync the file (and its attributes) to disc
|
||||||
if(file->write)
|
if(file->write)
|
||||||
{
|
{
|
||||||
ntfsSync(file->vd, file->ni);
|
|
||||||
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME | NTFS_UPDATE_CTIME);
|
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME | NTFS_UPDATE_CTIME);
|
||||||
|
ntfsSync(file->vd, file->ni);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file->read)
|
if (file->read)
|
||||||
|
@ -43,7 +43,7 @@ typedef struct _ntfs_file_state {
|
|||||||
bool compressed; /* True if file data is compressed */
|
bool compressed; /* True if file data is compressed */
|
||||||
bool encrypted; /* True if file data is encryted */
|
bool encrypted; /* True if file data is encryted */
|
||||||
off_t pos; /* Current position within the file (in bytes) */
|
off_t pos; /* Current position within the file (in bytes) */
|
||||||
size_t len; /* Total length of 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 *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 */
|
struct _ntfs_file_state *nextOpenFile; /* The next entry in a double-linked FILO list of open files */
|
||||||
} ntfs_file_state;
|
} ntfs_file_state;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* ntfsfile.c - devoptab file routines for NTFS-based devices.
|
* ntfsfile.c - devoptab file routines for NTFS-based devices.
|
||||||
*
|
* Copyright (c) 2010 Miigotu
|
||||||
* Copyright (c) 2009 Rhys "Shareese" Koedijk
|
* Copyright (c) 2009 Rhys "Shareese" Koedijk
|
||||||
* Copyright (c) 2006 Michael "Chishm" Chisholm
|
* Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||||
*
|
*
|
||||||
@ -59,16 +59,23 @@ void ntfsCloseFile (ntfs_file_state *file)
|
|||||||
// Special case fix ups for compressed and/or encrypted files
|
// Special case fix ups for compressed and/or encrypted files
|
||||||
if (file->compressed)
|
if (file->compressed)
|
||||||
ntfs_attr_pclose(file->data_na);
|
ntfs_attr_pclose(file->data_na);
|
||||||
|
#ifdef HAVE_SETXATTR
|
||||||
if (file->encrypted)
|
if (file->encrypted)
|
||||||
ntfs_efs_fixup_attribute(NULL, file->data_na);
|
ntfs_efs_fixup_attribute(NULL, file->data_na);
|
||||||
|
#endif
|
||||||
// Close the file data attribute (if open)
|
// Close the file data attribute (if open)
|
||||||
if (file->data_na)
|
if (file->data_na)
|
||||||
ntfs_attr_close(file->data_na);
|
ntfs_attr_close(file->data_na);
|
||||||
|
|
||||||
// Sync the file (and its attributes) to disc
|
// Sync the file (and its attributes) to disc
|
||||||
if(file->write)
|
if(file->write)
|
||||||
|
{
|
||||||
|
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME | NTFS_UPDATE_CTIME);
|
||||||
ntfsSync(file->vd, file->ni);
|
ntfsSync(file->vd, file->ni);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file->read)
|
||||||
|
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
|
||||||
|
|
||||||
// Close the file (if open)
|
// Close the file (if open)
|
||||||
if (file->ni)
|
if (file->ni)
|
||||||
@ -204,6 +211,8 @@ int ntfs_open_r (struct _reent *r, void *fileStruct, const char *path, int flags
|
|||||||
file->pos = 0;
|
file->pos = 0;
|
||||||
file->len = file->data_na->data_size;
|
file->len = file->data_na->data_size;
|
||||||
|
|
||||||
|
ntfs_log_trace("file->len %d\n", file->len);
|
||||||
|
|
||||||
// Update file times
|
// Update file times
|
||||||
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
|
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
|
||||||
|
|
||||||
@ -314,10 +323,6 @@ ssize_t ntfs_write_r (struct _reent *r, int fd, const char *ptr, size_t len)
|
|||||||
if (written)
|
if (written)
|
||||||
file->ni->flags |= FILE_ATTR_ARCHIVE;
|
file->ni->flags |= FILE_ATTR_ARCHIVE;
|
||||||
|
|
||||||
// Update file times (if we actually wrote something)
|
|
||||||
if (written)
|
|
||||||
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_MCTIME);
|
|
||||||
|
|
||||||
// Update the files data length
|
// Update the files data length
|
||||||
file->len = file->data_na->data_size;
|
file->len = file->data_na->data_size;
|
||||||
|
|
||||||
@ -346,6 +351,9 @@ int _NTFS_get_fragments (const char *path,
|
|||||||
if (fd != (int)file) return -12;
|
if (fd != (int)file) return -12;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (!file || !file->vd || !file->ni || !file->data_na) {
|
if (!file || !file->vd || !file->ni || !file->data_na) {
|
||||||
//r->_errno = EINVAL;
|
//r->_errno = EINVAL;
|
||||||
@ -373,6 +381,7 @@ int _NTFS_get_fragments (const char *path,
|
|||||||
if (file->pos + len > file->len) {
|
if (file->pos + len > file->len) {
|
||||||
r->_errno = EOVERFLOW;
|
r->_errno = EOVERFLOW;
|
||||||
len = file->len - file->pos;
|
len = file->len - file->pos;
|
||||||
|
ntfs_log_trace("EOVERFLOW");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -384,6 +393,7 @@ int _NTFS_get_fragments (const char *path,
|
|||||||
s64 ret = ntfs_attr_getfragments(file->data_na, file->pos,
|
s64 ret = ntfs_attr_getfragments(file->data_na, file->pos,
|
||||||
len, offset, append_fragment, callback_data);
|
len, offset, append_fragment, callback_data);
|
||||||
if (ret <= 0 || ret > len) {
|
if (ret <= 0 || ret > len) {
|
||||||
|
ntfsUnlock(file->vd);
|
||||||
//r->_errno = errno;
|
//r->_errno = errno;
|
||||||
ret_val = -14;
|
ret_val = -14;
|
||||||
if (ret < 0) ret_val = ret;
|
if (ret < 0) ret_val = ret;
|
||||||
@ -401,6 +411,7 @@ int _NTFS_get_fragments (const char *path,
|
|||||||
ret_val = 0;
|
ret_val = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
//ntfs_log_trace("file->pos: %d \n", (u32)file->pos);
|
||||||
// Update file times (if we actually read something)
|
// Update file times (if we actually read something)
|
||||||
if (read)
|
if (read)
|
||||||
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
|
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_ATIME);
|
||||||
@ -523,7 +534,7 @@ int ntfs_ftruncate_r (struct _reent *r, int fd, off_t len)
|
|||||||
|
|
||||||
// Update file times (if we actually changed something)
|
// Update file times (if we actually changed something)
|
||||||
if (file->len != file->data_na->data_size)
|
if (file->len != file->data_na->data_size)
|
||||||
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_MCTIME);
|
ntfsUpdateTimes(file->vd, file->ni, NTFS_UPDATE_AMCTIME);
|
||||||
|
|
||||||
// Update the files data length
|
// Update the files data length
|
||||||
file->len = file->data_na->data_size;
|
file->len = file->data_na->data_size;
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "usbloader/usbstorage2.h"
|
|
||||||
#include "ntfsinternal.h"
|
#include "ntfsinternal.h"
|
||||||
#include "ntfsdir.h"
|
#include "ntfsdir.h"
|
||||||
#include "ntfsfile.h"
|
#include "ntfsfile.h"
|
||||||
@ -42,11 +41,11 @@
|
|||||||
#if defined(__wii__)
|
#if defined(__wii__)
|
||||||
#include <sdcard/wiisd_io.h>
|
#include <sdcard/wiisd_io.h>
|
||||||
#include <sdcard/gcsd.h>
|
#include <sdcard/gcsd.h>
|
||||||
|
#include <ogc/usbstorage.h>
|
||||||
|
|
||||||
const INTERFACE_ID ntfs_disc_interfaces[] = {
|
const INTERFACE_ID ntfs_disc_interfaces[] = {
|
||||||
{ "sd", &__io_wiisd },
|
{ "sd", &__io_wiisd },
|
||||||
{ "usb", &__io_usbstorage2 },
|
{ "usb", &__io_usbstorage },
|
||||||
{ "carda", &__io_gcsda },
|
{ "carda", &__io_gcsda },
|
||||||
{ "cardb", &__io_gcsdb },
|
{ "cardb", &__io_gcsdb },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
@ -77,7 +76,7 @@ int ntfsAddDevice (const char *name, void *deviceData)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a devoptab for this device
|
// Allocate a devoptab for this device
|
||||||
dev = ntfs_alloc(sizeof(devoptab_t) + strlen(name) + 1);
|
dev = (devoptab_t *) ntfs_alloc(sizeof(devoptab_t) + strlen(name) + 1);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return false;
|
return false;
|
||||||
@ -304,7 +303,7 @@ ntfs_inode *ntfsParseEntry (ntfs_vd *vd, const char *path, int reparseLevel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the target path of this entry
|
// Get the target path of this entry
|
||||||
target = ntfs_make_symlink(path, ni, &attr_size);
|
target = ntfs_make_symlink(ni, path, &attr_size);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
ntfsCloseEntry(vd, ni);
|
ntfsCloseEntry(vd, ni);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -549,7 +548,6 @@ int ntfsLink (ntfs_vd *vd, const char *old_path, const char *new_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update entry times
|
// Update entry times
|
||||||
ntfsUpdateTimes(vd, ni, NTFS_UPDATE_CTIME);
|
|
||||||
ntfsUpdateTimes(vd, dir_ni, NTFS_UPDATE_MCTIME);
|
ntfsUpdateTimes(vd, dir_ni, NTFS_UPDATE_MCTIME);
|
||||||
|
|
||||||
// Sync the entry to disc
|
// Sync the entry to disc
|
||||||
@ -816,7 +814,7 @@ int ntfsUnicodeToLocal (const ntfschar *ins, const int ins_len, char **outs, int
|
|||||||
// do it manually by replacing non-ASCII characters with underscores
|
// do it manually by replacing non-ASCII characters with underscores
|
||||||
if (!*outs || outs_len >= ins_len) {
|
if (!*outs || outs_len >= ins_len) {
|
||||||
if (!*outs) {
|
if (!*outs) {
|
||||||
*outs = ntfs_alloc(ins_len + 1);
|
*outs = (char *) ntfs_alloc(ins_len + 1);
|
||||||
if (!*outs) {
|
if (!*outs) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2005 Anton Altaparmakov
|
* Copyright (c) 2005 Anton Altaparmakov
|
||||||
* Copyright (c) 2005 Yura Pakhuchiy
|
* Copyright (c) 2005 Yura Pakhuchiy
|
||||||
|
* Copyright (c) 2010 Jean-Pierre Andre
|
||||||
*
|
*
|
||||||
* This program/include file is free software; you can redistribute it and/or
|
* This program/include file is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as published
|
* modify it under the terms of the GNU General Public License as published
|
||||||
@ -26,44 +27,95 @@
|
|||||||
#ifdef HAVE_TIME_H
|
#ifdef HAVE_TIME_H
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_SYS_STAT_H
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_GETTIMEOFDAY
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#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)
|
#define NTFS_TIME_OFFSET ((s64)(369 * 365 + 89) * 24 * 3600 * 10000000)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ntfs2utc - Convert an NTFS time to Unix time
|
* ntfs2timespec - Convert an NTFS time to Unix time
|
||||||
* @ntfs_time: An NTFS time in 100ns units since 1601
|
* @ntfs_time: An NTFS time in 100ns units since 1601
|
||||||
*
|
*
|
||||||
* NTFS stores times as the number of 100ns intervals since January 1st 1601 at
|
* 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.
|
* 00:00 UTC. This system will not suffer from Y2K problems until ~57000AD.
|
||||||
*
|
*
|
||||||
* Return: n A Unix time (number of seconds since 1970)
|
* Return: A Unix time (number of seconds since 1970, and nanoseconds)
|
||||||
*/
|
*/
|
||||||
static __inline__ time_t ntfs2utc(s64 ntfs_time)
|
static __inline__ struct timespec ntfs2timespec(ntfs_time ntfstime)
|
||||||
{
|
{
|
||||||
return (sle64_to_cpu(ntfs_time) - (NTFS_TIME_OFFSET)) / 10000000;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* utc2ntfs - Convert Linux time to NTFS time
|
* timespec2ntfs - Convert Linux time to NTFS time
|
||||||
* @utc_time: Linux time to convert to NTFS
|
* @utc_time: Linux time to convert to NTFS
|
||||||
*
|
*
|
||||||
* Convert the Linux time @utc_time to its corresponding NTFS time.
|
* 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
|
* 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.
|
* 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 s64 and is
|
* 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,
|
* measured as the number of 100 nano-second intervals since 1st January 1601,
|
||||||
* 00:00:00 UTC.
|
* 00:00:00 UTC.
|
||||||
*
|
*
|
||||||
* Return: n An NTFS time (100ns units since Jan 1601)
|
* Return: An NTFS time (100ns units since Jan 1601)
|
||||||
*/
|
*/
|
||||||
static __inline__ s64 utc2ntfs(time_t utc_time)
|
static __inline__ ntfs_time timespec2ntfs(struct timespec spec)
|
||||||
{
|
{
|
||||||
/* Convert to 100ns intervals and then add the NTFS time offset. */
|
s64 units;
|
||||||
return cpu_to_sle64((s64)utc_time * 10000000 + NTFS_TIME_OFFSET);
|
|
||||||
|
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 */
|
#endif /* _NTFS_NTFSTIME_H */
|
||||||
|
637
source/libntfs/object_id.c
Normal file
637
source/libntfs/object_id.c
Normal file
@ -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 <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_ERRNO_H
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_SYS_STAT_H
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SETXATTR
|
||||||
|
#include <sys/xattr.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_SYSMACROS_H
|
||||||
|
#include <sys/sysmacros.h>
|
||||||
|
#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 */
|
35
source/libntfs/object_id.h
Normal file
35
source/libntfs/object_id.h
Normal file
@ -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 */
|
82
source/libntfs/param.h
Normal file
82
source/libntfs/param.h
Normal file
@ -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 */
|
@ -1,8 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* reparse.c - Processing of reparse points
|
* reparse.c - Processing of reparse points
|
||||||
*
|
*
|
||||||
* This module is part of ntfs-3g library, but may also be
|
* This module is part of ntfs-3g library
|
||||||
* integrated in tools running over Linux or Windows
|
|
||||||
*
|
*
|
||||||
* Copyright (c) 2008-2009 Jean-Pierre Andre
|
* Copyright (c) 2008-2009 Jean-Pierre Andre
|
||||||
*
|
*
|
||||||
@ -89,12 +88,6 @@ struct SYMLINK_REPARSE_DATA { /* reparse data for symlinks */
|
|||||||
char path_buffer[0]; /* above data assume this is char array */
|
char path_buffer[0]; /* above data assume this is char array */
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
struct INODE_STACK {
|
|
||||||
struct INODE_STACK *previous;
|
|
||||||
struct INODE_STACK *next;
|
|
||||||
ntfs_inode *ni;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
struct REPARSE_INDEX { /* index entry in $Extend/$Reparse */
|
struct REPARSE_INDEX { /* index entry in $Extend/$Reparse */
|
||||||
INDEX_ENTRY_HEADER header;
|
INDEX_ENTRY_HEADER header;
|
||||||
REPARSE_INDEX_KEY key;
|
REPARSE_INDEX_KEY key;
|
||||||
@ -123,7 +116,7 @@ static const ntfschar vol_junction_head[] = {
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
static ntfschar reparse_index_name[] = { const_cpu_to_le16('$'),
|
static ntfschar reparse_index_name[] = { const_cpu_to_le16('$'),
|
||||||
const_cpu_to_le16('R') };
|
const_cpu_to_le16('R') };
|
||||||
|
|
||||||
static const char mappingdir[] = ".NTFS-3G/";
|
static const char mappingdir[] = ".NTFS-3G/";
|
||||||
|
|
||||||
@ -194,10 +187,10 @@ static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname,
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
found = &entry->key.file_name;
|
found = &entry->key.file_name;
|
||||||
if (lkup
|
if (lkup
|
||||||
&& !ntfs_names_collate(find.attr.file_name,
|
&& ntfs_names_are_equal(find.attr.file_name,
|
||||||
find.attr.file_name_length,
|
find.attr.file_name_length,
|
||||||
found->file_name, found->file_name_length,
|
found->file_name, found->file_name_length,
|
||||||
1, IGNORE_CASE,
|
IGNORE_CASE,
|
||||||
vol->upcase, vol->upcase_len))
|
vol->upcase, vol->upcase_len))
|
||||||
lkup = 0;
|
lkup = 0;
|
||||||
if (!lkup) {
|
if (!lkup) {
|
||||||
@ -205,9 +198,7 @@ static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname,
|
|||||||
* name found :
|
* name found :
|
||||||
* fix original name and return inode
|
* fix original name and return inode
|
||||||
*/
|
*/
|
||||||
lemref = *(le64*)((char*)found->file_name
|
lemref = entry->indexed_file;
|
||||||
- sizeof(INDEX_ENTRY_HEADER)
|
|
||||||
- sizeof(FILE_NAME_ATTR));
|
|
||||||
mref = le64_to_cpu(lemref);
|
mref = le64_to_cpu(lemref);
|
||||||
for (i=0; i<found->file_name_length; i++)
|
for (i=0; i<found->file_name_length; i++)
|
||||||
uname[i] = found->file_name[i];
|
uname[i] = found->file_name[i];
|
||||||
@ -271,181 +262,90 @@ static char *search_absolute(ntfs_volume *vol, ntfschar *path,
|
|||||||
return (target);
|
return (target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Stack the next inode in the path
|
|
||||||
*
|
|
||||||
* Returns the new top of stack
|
|
||||||
* or NULL (with stack unchanged) if there is a problem
|
|
||||||
*/
|
|
||||||
|
|
||||||
static struct INODE_STACK *stack_inode(struct INODE_STACK *topni,
|
|
||||||
ntfschar *name, int len, BOOL fix)
|
|
||||||
{
|
|
||||||
struct INODE_STACK *curni;
|
|
||||||
u64 inum;
|
|
||||||
|
|
||||||
if (fix)
|
|
||||||
inum = ntfs_fix_file_name(topni->ni, name, len);
|
|
||||||
else
|
|
||||||
inum = ntfs_inode_lookup_by_name(topni->ni, name, len);
|
|
||||||
if (inum != (u64)-1) {
|
|
||||||
inum = MREF(inum);
|
|
||||||
curni = (struct INODE_STACK*)malloc(sizeof(struct INODE_STACK));
|
|
||||||
if (curni) {
|
|
||||||
curni->ni = ntfs_inode_open(topni->ni->vol, inum);
|
|
||||||
topni->next = curni;
|
|
||||||
curni->previous = topni;
|
|
||||||
curni->next = (struct INODE_STACK*)NULL;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
curni = (struct INODE_STACK*)NULL;
|
|
||||||
return (curni);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Destack and close the current inode in the path
|
|
||||||
*
|
|
||||||
* Returns the new top of stack
|
|
||||||
* or NULL (with stack unchanged) if there is a problem
|
|
||||||
*/
|
|
||||||
|
|
||||||
static struct INODE_STACK *pop_inode(struct INODE_STACK *topni)
|
|
||||||
{
|
|
||||||
struct INODE_STACK *curni;
|
|
||||||
|
|
||||||
curni = (struct INODE_STACK*)NULL;
|
|
||||||
if (topni->previous) {
|
|
||||||
if (!ntfs_inode_close(topni->ni)) {
|
|
||||||
curni = topni->previous;
|
|
||||||
free(topni);
|
|
||||||
curni->next = (struct INODE_STACK*)NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* ".." reached the root of fs */
|
|
||||||
errno = ENOENT;
|
|
||||||
}
|
|
||||||
return (curni);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search for a symbolic link along the target path,
|
* Search for a symbolic link along the target path,
|
||||||
* with the target defined as a relative 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
|
* Returns the path translated to a Linux path
|
||||||
* or NULL if the path is not valid
|
* or NULL if the path is not valid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *search_relative(ntfs_volume *vol, ntfschar *path, int count,
|
static char *search_relative(ntfs_inode *ni, ntfschar *path, int count)
|
||||||
const char *base, BOOL isdir)
|
|
||||||
{
|
{
|
||||||
struct INODE_STACK *topni;
|
char *target = (char*)NULL;
|
||||||
struct INODE_STACK *curni;
|
ntfs_inode *curni;
|
||||||
char *target;
|
ntfs_inode *newni;
|
||||||
ntfschar *unicode;
|
u64 inum;
|
||||||
int unisz;
|
int pos;
|
||||||
int start;
|
int lth;
|
||||||
int len;
|
BOOL ok;
|
||||||
|
int max = 32; /* safety */
|
||||||
|
|
||||||
target = (char*)NULL; /* default return */
|
pos = 0;
|
||||||
topni = (struct INODE_STACK*)malloc(sizeof(struct INODE_STACK));
|
ok = TRUE;
|
||||||
if (topni) {
|
curni = ntfs_dir_parent_inode(ni);
|
||||||
topni->ni = ntfs_inode_open(vol, FILE_root);
|
while (curni && ok && (pos < (count - 1)) && --max) {
|
||||||
topni->previous = (struct INODE_STACK*)NULL;
|
if ((count >= (pos + 2))
|
||||||
topni->next = (struct INODE_STACK*)NULL;
|
&& (path[pos] == const_cpu_to_le16('.'))
|
||||||
}
|
&& (path[pos+1] == const_cpu_to_le16('\\'))) {
|
||||||
if (topni && topni->ni) {
|
path[1] = const_cpu_to_le16('/');
|
||||||
/*
|
pos += 2;
|
||||||
* Process the base path
|
} else {
|
||||||
*/
|
if ((count >= (pos + 3))
|
||||||
unicode = (ntfschar*)NULL;
|
&& (path[pos] == const_cpu_to_le16('.'))
|
||||||
unisz = ntfs_mbstoucs(base, &unicode);
|
&&(path[pos+1] == const_cpu_to_le16('.'))
|
||||||
if ((unisz > 0) && unicode) {
|
&& (path[pos+2] == const_cpu_to_le16('\\'))) {
|
||||||
start = 1;
|
path[2] = const_cpu_to_le16('/');
|
||||||
do {
|
pos += 3;
|
||||||
len = 0;
|
newni = ntfs_dir_parent_inode(curni);
|
||||||
while (((start + len) < unisz)
|
if (curni != ni)
|
||||||
&& (unicode[start + len]
|
ntfs_inode_close(curni);
|
||||||
!= const_cpu_to_le16('/')))
|
curni = newni;
|
||||||
len++;
|
if (!curni)
|
||||||
curni = (struct INODE_STACK*)NULL;
|
ok = FALSE;
|
||||||
if ((start + len) < unisz) {
|
} else {
|
||||||
curni = stack_inode(topni,
|
lth = 0;
|
||||||
&unicode[start], len, FALSE);
|
while (((pos + lth) < count)
|
||||||
if (curni)
|
&& (path[pos + lth] != const_cpu_to_le16('\\')))
|
||||||
topni = curni;
|
lth++;
|
||||||
} else
|
if (lth > 0)
|
||||||
curni = topni;
|
inum = ntfs_fix_file_name(curni,&path[pos],lth);
|
||||||
start += len + 1;
|
else
|
||||||
} while (curni
|
inum = (u64)-1;
|
||||||
&& topni->ni
|
if (!lth
|
||||||
&& (topni->ni->mrec->flags
|
|| ((curni != ni)
|
||||||
& MFT_RECORD_IS_DIRECTORY)
|
&& ntfs_inode_close(curni))
|
||||||
&& (start < unisz));
|
|| (inum == (u64)-1))
|
||||||
free(unicode);
|
ok = FALSE;
|
||||||
if (curni
|
else {
|
||||||
&& topni->ni
|
curni = ntfs_inode_open(ni->vol, MREF(inum));
|
||||||
&& (topni->ni->mrec->flags
|
if (!curni)
|
||||||
& MFT_RECORD_IS_DIRECTORY)) {
|
ok = FALSE;
|
||||||
start = 0;
|
else {
|
||||||
do {
|
if (ok && ((pos + lth) < count)) {
|
||||||
len = 0;
|
path[pos + lth] = const_cpu_to_le16('/');
|
||||||
while (((start + len) < count)
|
pos += lth + 1;
|
||||||
&& (path[start + len]
|
} else {
|
||||||
!= const_cpu_to_le16('\\')))
|
pos += lth;
|
||||||
len++;
|
if ((ni->mrec->flags ^ curni->mrec->flags)
|
||||||
curni = (struct INODE_STACK*)NULL;
|
& MFT_RECORD_IS_DIRECTORY)
|
||||||
if ((path[start]
|
ok = FALSE;
|
||||||
== const_cpu_to_le16('.'))
|
if (ntfs_inode_close(curni))
|
||||||
&& ((len == 1)
|
ok = FALSE;
|
||||||
|| ((len == 2)
|
|
||||||
&& (path[start+1]
|
|
||||||
== const_cpu_to_le16('.'))))) {
|
|
||||||
/* leave the .. or . in the path */
|
|
||||||
curni = topni;
|
|
||||||
if (len == 2) {
|
|
||||||
curni = pop_inode(topni);
|
|
||||||
if (curni)
|
|
||||||
topni = curni;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
curni = stack_inode(topni,
|
|
||||||
&path[start], len, TRUE);
|
|
||||||
if (curni)
|
|
||||||
topni = curni;
|
|
||||||
}
|
|
||||||
if (topni->ni) {
|
|
||||||
start += len;
|
|
||||||
if (start < count)
|
|
||||||
path[start++]
|
|
||||||
= const_cpu_to_le16('/');
|
|
||||||
}
|
|
||||||
} while (curni
|
|
||||||
&& topni->ni
|
|
||||||
&& (topni->ni->mrec->flags
|
|
||||||
& MFT_RECORD_IS_DIRECTORY)
|
|
||||||
&& (start < count));
|
|
||||||
if (curni
|
|
||||||
&& topni->ni
|
|
||||||
&& (topni->ni->mrec->flags
|
|
||||||
& MFT_RECORD_IS_DIRECTORY
|
|
||||||
? isdir : !isdir)) {
|
|
||||||
if (ntfs_ucstombs(path, count,
|
|
||||||
&target, 0) < 0) {
|
|
||||||
if (target) {
|
|
||||||
free(target);
|
|
||||||
target = (char*)NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
do {
|
}
|
||||||
if (topni->ni)
|
|
||||||
ntfs_inode_close(topni->ni);
|
if (ok && (ntfs_ucstombs(path, count, &target, 0) < 0)) {
|
||||||
curni = topni;
|
free(target); // needed ?
|
||||||
topni = topni->previous;
|
target = (char*)NULL;
|
||||||
free(curni);
|
|
||||||
} while (topni);
|
|
||||||
}
|
}
|
||||||
return (target);
|
return (target);
|
||||||
}
|
}
|
||||||
@ -492,6 +392,62 @@ static int ntfs_drive_letter(ntfs_volume *vol, ntfschar letter)
|
|||||||
return (ret);
|
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
|
* Check and translate the target of a junction point or
|
||||||
* a full absolute symbolic link.
|
* a full absolute symbolic link.
|
||||||
@ -507,16 +463,12 @@ static int ntfs_drive_letter(ntfs_volume *vol, ntfschar letter)
|
|||||||
* or NULL if there were some problem, as described by errno
|
* or NULL if there were some problem, as described by errno
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
|
static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
|
||||||
int count, const char *path, BOOL isdir)
|
int count, const char *mnt_point, BOOL isdir)
|
||||||
{
|
{
|
||||||
char *target;
|
char *target;
|
||||||
char *fulltarget;
|
char *fulltarget;
|
||||||
int i;
|
|
||||||
int sz;
|
int sz;
|
||||||
int level;
|
|
||||||
const char *p;
|
|
||||||
char *q;
|
char *q;
|
||||||
enum { DIR_JUNCTION, VOL_JUNCTION, NO_JUNCTION } kind;
|
enum { DIR_JUNCTION, VOL_JUNCTION, NO_JUNCTION } kind;
|
||||||
|
|
||||||
@ -554,19 +506,11 @@ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
&& !ntfs_drive_letter(vol, junction[4])) {
|
&& !ntfs_drive_letter(vol, junction[4])) {
|
||||||
target = search_absolute(vol,&junction[7],count - 7, isdir);
|
target = search_absolute(vol,&junction[7],count - 7, isdir);
|
||||||
if (target) {
|
if (target) {
|
||||||
level = 0;
|
fulltarget = (char*)ntfs_malloc(strlen(mnt_point)
|
||||||
for (p=path; *p; p++)
|
+ strlen(target) + 2);
|
||||||
if (*p == '/')
|
|
||||||
level++;
|
|
||||||
fulltarget = (char*)ntfs_malloc(3*level
|
|
||||||
+ strlen(target) + 1);
|
|
||||||
if (fulltarget) {
|
if (fulltarget) {
|
||||||
fulltarget[0] = 0;
|
strcpy(fulltarget,mnt_point);
|
||||||
if (level > 1) {
|
strcat(fulltarget,"/");
|
||||||
for (i=1; i<level; i++)
|
|
||||||
strcat(fulltarget,"../");
|
|
||||||
} else
|
|
||||||
strcpy(fulltarget,"./");
|
|
||||||
strcat(fulltarget,target);
|
strcat(fulltarget,target);
|
||||||
}
|
}
|
||||||
free(target);
|
free(target);
|
||||||
@ -593,19 +537,11 @@ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
&& (target[0] >= 'a')
|
&& (target[0] >= 'a')
|
||||||
&& (target[0] <= 'z'))
|
&& (target[0] <= 'z'))
|
||||||
target[0] += 'A' - 'a';
|
target[0] += 'A' - 'a';
|
||||||
level = 0;
|
fulltarget = (char*)ntfs_malloc(strlen(mnt_point)
|
||||||
for (p=path; *p; p++)
|
+ sizeof(mappingdir) + strlen(target) + 1);
|
||||||
if (*p == '/')
|
|
||||||
level++;
|
|
||||||
fulltarget = (char*)ntfs_malloc(3*level
|
|
||||||
+ sizeof(mappingdir) + strlen(target) - 3);
|
|
||||||
if (fulltarget) {
|
if (fulltarget) {
|
||||||
fulltarget[0] = 0;
|
strcpy(fulltarget,mnt_point);
|
||||||
if (level > 1) {
|
strcat(fulltarget,"/");
|
||||||
for (i=1; i<level; i++)
|
|
||||||
strcat(fulltarget,"../");
|
|
||||||
} else
|
|
||||||
strcpy(fulltarget,"./");
|
|
||||||
strcat(fulltarget,mappingdir);
|
strcat(fulltarget,mappingdir);
|
||||||
strcat(fulltarget,target);
|
strcat(fulltarget,target);
|
||||||
}
|
}
|
||||||
@ -631,14 +567,11 @@ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction,
|
static char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction,
|
||||||
int count, const char *path, BOOL isdir)
|
int count, const char *mnt_point, BOOL isdir)
|
||||||
{
|
{
|
||||||
char *target;
|
char *target;
|
||||||
char *fulltarget;
|
char *fulltarget;
|
||||||
int i;
|
|
||||||
int sz;
|
int sz;
|
||||||
int level;
|
|
||||||
const char *p;
|
|
||||||
char *q;
|
char *q;
|
||||||
enum { FULL_PATH, ABS_PATH, REJECTED_PATH } kind;
|
enum { FULL_PATH, ABS_PATH, REJECTED_PATH } kind;
|
||||||
|
|
||||||
@ -680,19 +613,11 @@ static char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
target = search_absolute(vol, &junction[3],
|
target = search_absolute(vol, &junction[3],
|
||||||
count - 3, isdir);
|
count - 3, isdir);
|
||||||
if (target) {
|
if (target) {
|
||||||
level = 0;
|
fulltarget = (char*)ntfs_malloc(strlen(mnt_point)
|
||||||
for (p=path; *p; p++)
|
+ strlen(target) + 2);
|
||||||
if (*p == '/')
|
|
||||||
level++;
|
|
||||||
fulltarget = (char*)ntfs_malloc(3*level
|
|
||||||
+ strlen(target) + 1);
|
|
||||||
if (fulltarget) {
|
if (fulltarget) {
|
||||||
fulltarget[0] = 0;
|
strcpy(fulltarget,mnt_point);
|
||||||
if (level > 1) {
|
strcat(fulltarget,"/");
|
||||||
for (i=1; i<level; i++)
|
|
||||||
strcat(fulltarget,"../");
|
|
||||||
} else
|
|
||||||
strcpy(fulltarget,"./");
|
|
||||||
strcat(fulltarget,target);
|
strcat(fulltarget,target);
|
||||||
}
|
}
|
||||||
free(target);
|
free(target);
|
||||||
@ -716,19 +641,11 @@ static char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
&& (target[0] >= 'a')
|
&& (target[0] >= 'a')
|
||||||
&& (target[0] <= 'z'))
|
&& (target[0] <= 'z'))
|
||||||
target[0] += 'A' - 'a';
|
target[0] += 'A' - 'a';
|
||||||
level = 0;
|
fulltarget = (char*)ntfs_malloc(strlen(mnt_point)
|
||||||
for (p=path; *p; p++)
|
+ sizeof(mappingdir) + strlen(target) + 1);
|
||||||
if (*p == '/')
|
|
||||||
level++;
|
|
||||||
fulltarget = (char*)ntfs_malloc(3*level
|
|
||||||
+ sizeof(mappingdir) + strlen(target) - 3);
|
|
||||||
if (fulltarget) {
|
if (fulltarget) {
|
||||||
fulltarget[0] = 0;
|
strcpy(fulltarget,mnt_point);
|
||||||
if (level > 1) {
|
strcat(fulltarget,"/");
|
||||||
for (i=1; i<level; i++)
|
|
||||||
strcat(fulltarget,"../");
|
|
||||||
} else
|
|
||||||
strcpy(fulltarget,"./");
|
|
||||||
strcat(fulltarget,mappingdir);
|
strcat(fulltarget,mappingdir);
|
||||||
strcat(fulltarget,target);
|
strcat(fulltarget,target);
|
||||||
}
|
}
|
||||||
@ -751,12 +668,11 @@ static char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
* or NULL if there were some problem, as described by errno
|
* or NULL if there were some problem, as described by errno
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *ntfs_get_rellink(ntfs_volume *vol, ntfschar *junction,
|
static char *ntfs_get_rellink(ntfs_inode *ni, ntfschar *junction, int count)
|
||||||
int count, const char *path, BOOL isdir)
|
|
||||||
{
|
{
|
||||||
char *target;
|
char *target;
|
||||||
|
|
||||||
target = search_relative(vol,junction,count,path,isdir);
|
target = search_relative(ni,junction,count);
|
||||||
return (target);
|
return (target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -770,8 +686,8 @@ static char *ntfs_get_rellink(ntfs_volume *vol, ntfschar *junction,
|
|||||||
* symbolic link or directory junction
|
* symbolic link or directory junction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *ntfs_make_symlink(const char *org_path,
|
char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point,
|
||||||
ntfs_inode *ni, int *pattr_size)
|
int *pattr_size)
|
||||||
{
|
{
|
||||||
s64 attr_size = 0;
|
s64 attr_size = 0;
|
||||||
char *target;
|
char *target;
|
||||||
@ -793,26 +709,20 @@ char *ntfs_make_symlink(const char *org_path,
|
|||||||
vol = ni->vol;
|
vol = ni->vol;
|
||||||
reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni,
|
reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni,
|
||||||
AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size);
|
AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size);
|
||||||
if (reparse_attr && attr_size) {
|
if (reparse_attr && attr_size
|
||||||
|
&& valid_reparse_data(ni, reparse_attr, attr_size)) {
|
||||||
switch (reparse_attr->reparse_tag) {
|
switch (reparse_attr->reparse_tag) {
|
||||||
case IO_REPARSE_TAG_MOUNT_POINT :
|
case IO_REPARSE_TAG_MOUNT_POINT :
|
||||||
mount_point_data = (struct MOUNT_POINT_REPARSE_DATA*)
|
mount_point_data = (struct MOUNT_POINT_REPARSE_DATA*)
|
||||||
reparse_attr->reparse_data;
|
reparse_attr->reparse_data;
|
||||||
offs = le16_to_cpu(mount_point_data->subst_name_offset);
|
offs = le16_to_cpu(mount_point_data->subst_name_offset);
|
||||||
lth = le16_to_cpu(mount_point_data->subst_name_length);
|
lth = le16_to_cpu(mount_point_data->subst_name_length);
|
||||||
/* consistency checks */
|
/* reparse data consistency has been checked */
|
||||||
if (isdir
|
target = ntfs_get_fulllink(vol,
|
||||||
&& ((le16_to_cpu(reparse_attr->reparse_data_length)
|
(ntfschar*)&mount_point_data->path_buffer[offs],
|
||||||
+ 8) == attr_size)
|
lth/2, mnt_point, isdir);
|
||||||
&& ((int)((sizeof(REPARSE_POINT)
|
if (target)
|
||||||
+ sizeof(struct MOUNT_POINT_REPARSE_DATA)
|
bad = FALSE;
|
||||||
+ offs + lth)) <= attr_size)) {
|
|
||||||
target = ntfs_get_fulllink(vol,
|
|
||||||
(ntfschar*)&mount_point_data->path_buffer[offs],
|
|
||||||
lth/2, org_path, isdir);
|
|
||||||
if (target)
|
|
||||||
bad = FALSE;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case IO_REPARSE_TAG_SYMLINK :
|
case IO_REPARSE_TAG_SYMLINK :
|
||||||
symlink_data = (struct SYMLINK_REPARSE_DATA*)
|
symlink_data = (struct SYMLINK_REPARSE_DATA*)
|
||||||
@ -836,44 +746,37 @@ char *ntfs_make_symlink(const char *org_path,
|
|||||||
else
|
else
|
||||||
kind = REL_TARGET;
|
kind = REL_TARGET;
|
||||||
p--;
|
p--;
|
||||||
/* consistency checks */
|
/* reparse data consistency has been checked */
|
||||||
if (((le16_to_cpu(reparse_attr->reparse_data_length)
|
switch (kind) {
|
||||||
+ 8) == attr_size)
|
case FULL_TARGET :
|
||||||
&& ((int)((sizeof(REPARSE_POINT)
|
if (!(symlink_data->flags
|
||||||
+ sizeof(struct SYMLINK_REPARSE_DATA)
|
& const_cpu_to_le32(1))) {
|
||||||
+ offs + lth)) <= attr_size)) {
|
target = ntfs_get_fulllink(vol,
|
||||||
switch (kind) {
|
p, lth/2,
|
||||||
case FULL_TARGET :
|
mnt_point, isdir);
|
||||||
if (!(symlink_data->flags
|
if (target)
|
||||||
& const_cpu_to_le32(1))) {
|
bad = FALSE;
|
||||||
target = ntfs_get_fulllink(vol,
|
|
||||||
p, lth/2,
|
|
||||||
org_path, 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,
|
|
||||||
org_path, isdir);
|
|
||||||
if (target)
|
|
||||||
bad = FALSE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case REL_TARGET :
|
|
||||||
if (symlink_data->flags
|
|
||||||
& const_cpu_to_le32(1)) {
|
|
||||||
target = ntfs_get_rellink(vol,
|
|
||||||
p, lth/2,
|
|
||||||
org_path, isdir);
|
|
||||||
if (target)
|
|
||||||
bad = FALSE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@ -984,8 +887,9 @@ static int remove_reparse_index(ntfs_attr *na, ntfs_index_context *xr,
|
|||||||
key.reparse_tag = *preparse_tag;
|
key.reparse_tag = *preparse_tag;
|
||||||
/* danger on processors which require proper alignment ! */
|
/* danger on processors which require proper alignment ! */
|
||||||
memcpy(&key.file_id, &file_id, 8);
|
memcpy(&key.file_id, &file_id, 8);
|
||||||
if (!ntfs_index_lookup(&key, sizeof(REPARSE_INDEX_KEY), xr))
|
if (!ntfs_index_lookup(&key, sizeof(REPARSE_INDEX_KEY), xr)
|
||||||
ret = ntfs_index_rm(xr);
|
&& ntfs_index_rm(xr))
|
||||||
|
ret = -1;
|
||||||
} else {
|
} else {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
errno = ENODATA;
|
errno = ENODATA;
|
||||||
@ -1005,10 +909,20 @@ static int remove_reparse_index(ntfs_attr *na, ntfs_index_context *xr,
|
|||||||
|
|
||||||
static ntfs_index_context *open_reparse_index(ntfs_volume *vol)
|
static ntfs_index_context *open_reparse_index(ntfs_volume *vol)
|
||||||
{
|
{
|
||||||
|
u64 inum;
|
||||||
ntfs_inode *ni;
|
ntfs_inode *ni;
|
||||||
|
ntfs_inode *dir_ni;
|
||||||
ntfs_index_context *xr;
|
ntfs_index_context *xr;
|
||||||
|
|
||||||
ni = ntfs_pathname_to_inode(vol, NULL, "$Extend/$Reparse");
|
/* 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) {
|
if (ni) {
|
||||||
xr = ntfs_index_ctx_get(ni, reparse_index_name, 2);
|
xr = ntfs_index_ctx_get(ni, reparse_index_name, 2);
|
||||||
if (!xr) {
|
if (!xr) {
|
||||||
@ -1133,8 +1047,7 @@ int ntfs_delete_reparse_index(ntfs_inode *ni)
|
|||||||
* and the buffer is updated if it is long enough
|
* and the buffer is updated if it is long enough
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_get_ntfs_reparse_data(const char *path __attribute__((unused)),
|
int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size)
|
||||||
char *value, size_t size, ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
REPARSE_POINT *reparse_attr;
|
REPARSE_POINT *reparse_attr;
|
||||||
s64 attr_size;
|
s64 attr_size;
|
||||||
@ -1168,9 +1081,8 @@ int ntfs_get_ntfs_reparse_data(const char *path __attribute__((unused)),
|
|||||||
* Returns 0, or -1 if there is a problem
|
* Returns 0, or -1 if there is a problem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_set_ntfs_reparse_data(const char *path __attribute__((unused)),
|
int ntfs_set_ntfs_reparse_data(ntfs_inode *ni,
|
||||||
const char *value, size_t size, int flags,
|
const char *value, size_t size, int flags)
|
||||||
ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
u8 dummy;
|
u8 dummy;
|
||||||
@ -1178,7 +1090,7 @@ int ntfs_set_ntfs_reparse_data(const char *path __attribute__((unused)),
|
|||||||
ntfs_index_context *xr;
|
ntfs_index_context *xr;
|
||||||
|
|
||||||
res = 0;
|
res = 0;
|
||||||
if (ni && value && (size >= 4)) {
|
if (ni && valid_reparse_data(ni, (const REPARSE_POINT*)value, size)) {
|
||||||
xr = open_reparse_index(ni->vol);
|
xr = open_reparse_index(ni->vol);
|
||||||
if (xr) {
|
if (xr) {
|
||||||
if (!ntfs_attr_exist(ni,AT_REPARSE_POINT,
|
if (!ntfs_attr_exist(ni,AT_REPARSE_POINT,
|
||||||
@ -1194,9 +1106,11 @@ int ntfs_set_ntfs_reparse_data(const char *path __attribute__((unused)),
|
|||||||
AT_REPARSE_POINT,
|
AT_REPARSE_POINT,
|
||||||
AT_UNNAMED,0,&dummy,
|
AT_UNNAMED,0,&dummy,
|
||||||
(s64)0);
|
(s64)0);
|
||||||
if (!res)
|
if (!res) {
|
||||||
ni->flags |=
|
ni->flags |=
|
||||||
FILE_ATTR_REPARSE_POINT;
|
FILE_ATTR_REPARSE_POINT;
|
||||||
|
NInoFileNameSetDirty(ni);
|
||||||
|
}
|
||||||
NInoSetDirty(ni);
|
NInoSetDirty(ni);
|
||||||
} else {
|
} else {
|
||||||
errno = EOPNOTSUPP;
|
errno = EOPNOTSUPP;
|
||||||
@ -1237,8 +1151,7 @@ int ntfs_set_ntfs_reparse_data(const char *path __attribute__((unused)),
|
|||||||
* Returns 0, or -1 if there is a problem
|
* Returns 0, or -1 if there is a problem
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int ntfs_remove_ntfs_reparse_data(const char *path __attribute__((unused)),
|
int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni)
|
||||||
ntfs_inode *ni)
|
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
int olderrno;
|
int olderrno;
|
||||||
@ -1267,6 +1180,7 @@ int ntfs_remove_ntfs_reparse_data(const char *path __attribute__((unused)),
|
|||||||
if (!res) {
|
if (!res) {
|
||||||
ni->flags &=
|
ni->flags &=
|
||||||
~FILE_ATTR_REPARSE_POINT;
|
~FILE_ATTR_REPARSE_POINT;
|
||||||
|
NInoFileNameSetDirty(ni);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* If we could not remove the
|
* If we could not remove the
|
||||||
|
@ -24,15 +24,15 @@
|
|||||||
#ifndef REPARSE_H
|
#ifndef REPARSE_H
|
||||||
#define REPARSE_H
|
#define REPARSE_H
|
||||||
|
|
||||||
char *ntfs_make_symlink(const char *org_path,
|
char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point,
|
||||||
ntfs_inode *ni, int *pattr_size);
|
int *pattr_size);
|
||||||
BOOL ntfs_possible_symlink(ntfs_inode *ni);
|
BOOL ntfs_possible_symlink(ntfs_inode *ni);
|
||||||
|
|
||||||
int ntfs_get_ntfs_reparse_data(const char *path,
|
int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size);
|
||||||
char *value, size_t size, ntfs_inode *ni);
|
|
||||||
int ntfs_set_ntfs_reparse_data(const char *path, const char *value,
|
int ntfs_set_ntfs_reparse_data(ntfs_inode *ni, const char *value,
|
||||||
size_t size, int flags, ntfs_inode *ni);
|
size_t size, int flags);
|
||||||
int ntfs_remove_ntfs_reparse_data(const char *path, ntfs_inode *ni);
|
int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni);
|
||||||
|
|
||||||
int ntfs_delete_reparse_index(ntfs_inode *ni);
|
int ntfs_delete_reparse_index(ntfs_inode *ni);
|
||||||
|
|
||||||
|
@ -117,18 +117,33 @@ static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size,
|
|||||||
*
|
*
|
||||||
* Returns the reallocated runlist
|
* Returns the reallocated runlist
|
||||||
* or NULL if reallocation was not possible (with errno set)
|
* or NULL if reallocation was not possible (with errno set)
|
||||||
|
* the runlist is left unchanged if the reallocation fails
|
||||||
*/
|
*/
|
||||||
|
|
||||||
runlist_element *ntfs_rl_extend(runlist_element *rl, int more_entries)
|
runlist_element *ntfs_rl_extend(ntfs_attr *na, runlist_element *rl,
|
||||||
|
int more_entries)
|
||||||
{
|
{
|
||||||
|
runlist_element *newrl;
|
||||||
int last;
|
int last;
|
||||||
|
int irl;
|
||||||
|
|
||||||
last = 0;
|
if (na->rl && rl) {
|
||||||
while (rl[last].length)
|
irl = (int)(rl - na->rl);
|
||||||
last++;
|
last = irl;
|
||||||
rl = ntfs_rl_realloc(rl,last+1,last+more_entries+1);
|
while (na->rl[last].length)
|
||||||
if (!rl)
|
last++;
|
||||||
errno = ENOMEM;
|
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);
|
return (rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -764,7 +779,7 @@ runlist_element *ntfs_runlists_merge(runlist_element *drl,
|
|||||||
* two into one, if that is possible (we check for overlap and discard the new
|
* 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).
|
* runlist if overlap present before returning NULL, with errno = ERANGE).
|
||||||
*/
|
*/
|
||||||
runlist_element *ntfs_mapping_pairs_decompress_i(const ntfs_volume *vol,
|
static runlist_element *ntfs_mapping_pairs_decompress_i(const ntfs_volume *vol,
|
||||||
const ATTR_RECORD *attr, runlist_element *old_rl)
|
const ATTR_RECORD *attr, runlist_element *old_rl)
|
||||||
{
|
{
|
||||||
VCN vcn; /* Current vcn. */
|
VCN vcn; /* Current vcn. */
|
||||||
@ -1622,7 +1637,11 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn)
|
|||||||
|
|
||||||
if (!arl || !*arl) {
|
if (!arl || !*arl) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
ntfs_log_perror("rl_truncate error: arl: %p *arl: %p", arl, *arl);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ struct _runlist_element {/* In memory vcn to lcn mapping structure element. */
|
|||||||
s64 length; /* Run length in clusters. */
|
s64 length; /* Run length in clusters. */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern runlist_element *ntfs_rl_extend(runlist_element *rl, int more_entries);
|
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 LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn);
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,9 @@
|
|||||||
#define POSIXACLS 0
|
#define POSIXACLS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef u16 be16;
|
||||||
|
typedef u32 be32;
|
||||||
|
|
||||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
#define const_cpu_to_be16(x) ((((x) & 255L) << 8) + (((x) >> 8) & 255L))
|
#define const_cpu_to_be16(x) ((((x) & 255L) << 8) + (((x) >> 8) & 255L))
|
||||||
#define const_cpu_to_be32(x) ((((x) & 255L) << 24) + (((x) & 0xff00L) << 8) \
|
#define const_cpu_to_be32(x) ((((x) & 255L) << 24) + (((x) & 0xff00L) << 8) \
|
||||||
@ -79,6 +82,7 @@ struct CACHED_PERMISSIONS {
|
|||||||
|
|
||||||
struct CACHED_PERMISSIONS_LEGACY {
|
struct CACHED_PERMISSIONS_LEGACY {
|
||||||
struct CACHED_PERMISSIONS_LEGACY *next;
|
struct CACHED_PERMISSIONS_LEGACY *next;
|
||||||
|
struct CACHED_PERMISSIONS_LEGACY *previous;
|
||||||
void *variable;
|
void *variable;
|
||||||
size_t varsize;
|
size_t varsize;
|
||||||
/* above fields must match "struct CACHED_GENERIC" */
|
/* above fields must match "struct CACHED_GENERIC" */
|
||||||
@ -92,6 +96,7 @@ struct CACHED_PERMISSIONS_LEGACY {
|
|||||||
|
|
||||||
struct CACHED_SECURID {
|
struct CACHED_SECURID {
|
||||||
struct CACHED_SECURID *next;
|
struct CACHED_SECURID *next;
|
||||||
|
struct CACHED_SECURID *previous;
|
||||||
void *variable;
|
void *variable;
|
||||||
size_t varsize;
|
size_t varsize;
|
||||||
/* above fields must match "struct CACHED_GENERIC" */
|
/* above fields must match "struct CACHED_GENERIC" */
|
||||||
@ -238,28 +243,29 @@ extern int ntfs_sd_add_everyone(ntfs_inode *ni);
|
|||||||
extern le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd,
|
extern le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd,
|
||||||
const u32 len);
|
const u32 len);
|
||||||
|
|
||||||
int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path);
|
int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path,
|
||||||
|
BOOL allowdef);
|
||||||
int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx,
|
int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx,
|
||||||
const char *path, ntfs_inode *ni, struct stat*);
|
ntfs_inode *ni, struct stat*);
|
||||||
int ntfs_set_mode(struct SECURITY_CONTEXT *scx,
|
int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode);
|
||||||
const char *path, ntfs_inode *ni, mode_t mode);
|
BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni);
|
||||||
BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx,
|
int ntfs_allowed_access(struct SECURITY_CONTEXT *scx,
|
||||||
const char *path, ntfs_inode *ni);
|
|
||||||
int ntfs_allowed_access(struct SECURITY_CONTEXT *scx, const char *path,
|
|
||||||
ntfs_inode *ni, int accesstype);
|
ntfs_inode *ni, int accesstype);
|
||||||
BOOL ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx,
|
BOOL old_ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx,
|
||||||
const char *path, int accesstype);
|
const char *path, int accesstype);
|
||||||
|
|
||||||
#if POSIXACLS
|
#if POSIXACLS
|
||||||
le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
|
le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
|
||||||
uid_t uid, gid_t gid, const char *dir_path,
|
uid_t uid, gid_t gid, ntfs_inode *dir_ni,
|
||||||
ntfs_inode *dir_ni, mode_t mode, BOOL isdir);
|
mode_t mode, BOOL isdir);
|
||||||
#else
|
#else
|
||||||
le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
|
le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
|
||||||
uid_t uid, gid_t gid, mode_t mode, BOOL isdir);
|
uid_t uid, gid_t gid, mode_t mode, BOOL isdir);
|
||||||
#endif
|
#endif
|
||||||
int ntfs_set_owner(struct SECURITY_CONTEXT *scx,
|
int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||||
const char *path, ntfs_inode *ni, uid_t uid, gid_t gid);
|
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
|
#if POSIXACLS
|
||||||
int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx,
|
int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx,
|
||||||
ntfs_inode *ni, uid_t uid, gid_t gid,
|
ntfs_inode *ni, uid_t uid, gid_t gid,
|
||||||
@ -269,7 +275,7 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx,
|
|||||||
ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode);
|
ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode);
|
||||||
#endif
|
#endif
|
||||||
le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
|
le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
|
||||||
const char *dir_path, ntfs_inode *dir_ni, BOOL fordir);
|
ntfs_inode *dir_ni, BOOL fordir);
|
||||||
int ntfs_open_secure(ntfs_volume *vol);
|
int ntfs_open_secure(ntfs_volume *vol);
|
||||||
void ntfs_close_secure(struct SECURITY_CONTEXT *scx);
|
void ntfs_close_secure(struct SECURITY_CONTEXT *scx);
|
||||||
|
|
||||||
@ -277,28 +283,25 @@ void ntfs_close_secure(struct SECURITY_CONTEXT *scx);
|
|||||||
|
|
||||||
int ntfs_set_inherited_posix(struct SECURITY_CONTEXT *scx,
|
int ntfs_set_inherited_posix(struct SECURITY_CONTEXT *scx,
|
||||||
ntfs_inode *ni, uid_t uid, gid_t gid,
|
ntfs_inode *ni, uid_t uid, gid_t gid,
|
||||||
const char *dir_path, ntfs_inode *dir_ni, mode_t mode);
|
ntfs_inode *dir_ni, mode_t mode);
|
||||||
int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||||
const char *name, char *value, size_t size,
|
const char *name, char *value, size_t size);
|
||||||
ntfs_inode *ni);
|
int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||||
int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
|
||||||
const char *name, const char *value, size_t size,
|
const char *name, const char *value, size_t size,
|
||||||
int flags, ntfs_inode *ni);
|
int flags);
|
||||||
int ntfs_remove_posix_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
int ntfs_remove_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||||
const char *name, ntfs_inode *ni);
|
const char *name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
int ntfs_get_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||||
const char *name, char *value, size_t size,
|
char *value, size_t size);
|
||||||
ntfs_inode *ni);
|
int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||||
int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, const char *path,
|
const char *value, size_t size, int flags);
|
||||||
const char *name, const char *value, size_t size,
|
|
||||||
int flags, ntfs_inode *ni);
|
int ntfs_get_ntfs_attrib(ntfs_inode *ni, char *value, size_t size);
|
||||||
int ntfs_get_ntfs_attrib(const char *path,
|
int ntfs_set_ntfs_attrib(ntfs_inode *ni,
|
||||||
char *value, size_t size, ntfs_inode *ni);
|
const char *value, size_t size, int flags);
|
||||||
int ntfs_set_ntfs_attrib(const char *path,
|
|
||||||
const char *value, size_t size, int flags,
|
|
||||||
ntfs_inode *ni);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Security API for direct access to security descriptors
|
* Security API for direct access to security descriptors
|
||||||
|
@ -87,8 +87,8 @@ typedef sle64 leLSN;
|
|||||||
* Cygwin has a collision between our BOOL and <windef.h>'s
|
* Cygwin has a collision between our BOOL and <windef.h>'s
|
||||||
* As long as this file will be included after <windows.h> were fine.
|
* As long as this file will be included after <windows.h> were fine.
|
||||||
*/
|
*/
|
||||||
#ifndef _WINDEF_H
|
|
||||||
#ifndef GEKKO
|
#ifndef GEKKO
|
||||||
|
#ifndef _WINDEF_H
|
||||||
/**
|
/**
|
||||||
* enum BOOL - These are just to make the code more readable...
|
* enum BOOL - These are just to make the code more readable...
|
||||||
*/
|
*/
|
||||||
@ -112,8 +112,8 @@ typedef enum {
|
|||||||
ONE = 1,
|
ONE = 1,
|
||||||
#endif
|
#endif
|
||||||
} BOOL;
|
} BOOL;
|
||||||
#endif /* GEKKO */
|
|
||||||
#endif /* defined _WINDEF_H */
|
#endif /* defined _WINDEF_H */
|
||||||
|
#endif /* defined GECKO */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enum IGNORE_CASE_BOOL -
|
* enum IGNORE_CASE_BOOL -
|
||||||
|
@ -132,37 +132,30 @@ BOOL ntfs_names_are_equal(const ntfschar *s1, size_t s1_len,
|
|||||||
TRUE;
|
TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* ntfs_names_collate - collate two Unicode names
|
* ntfs_names_full_collate() fully collate two Unicode names
|
||||||
|
*
|
||||||
* @name1: first Unicode name to compare
|
* @name1: first Unicode name to compare
|
||||||
* @name1_len: length of first Unicode name to compare
|
* @name1_len: length of first Unicode name to compare
|
||||||
* @name2: second Unicode name to compare
|
* @name2: second Unicode name to compare
|
||||||
* @name2_len: length of second Unicode name to compare
|
* @name2_len: length of second Unicode name to compare
|
||||||
* @err_val: if @name1 contains an invalid character return this value
|
|
||||||
* @ic: either CASE_SENSITIVE or IGNORE_CASE
|
* @ic: either CASE_SENSITIVE or IGNORE_CASE
|
||||||
* @upcase: upcase table (ignored if @ic is CASE_SENSITIVE)
|
* @upcase: upcase table (ignored if @ic is CASE_SENSITIVE)
|
||||||
* @upcase_len: upcase table size (ignored if @ic is CASE_SENSITIVE)
|
* @upcase_len: upcase table size (ignored if @ic is CASE_SENSITIVE)
|
||||||
*
|
*
|
||||||
* ntfs_names_collate() collates two Unicode names and returns:
|
|
||||||
*
|
|
||||||
* -1 if the first name collates before the second one,
|
* -1 if the first name collates before the second one,
|
||||||
* 0 if the names match,
|
* 0 if the names match,
|
||||||
* 1 if the second name collates before the first one, or
|
* 1 if the second name collates before the first one, or
|
||||||
* @err_val if an invalid character is found in @name1 during the comparison.
|
|
||||||
*
|
*
|
||||||
* The following characters are considered invalid: '"', '*', '<', '>' and '?'.
|
|
||||||
*
|
|
||||||
* A few optimizations made by JPA
|
|
||||||
*/
|
*/
|
||||||
|
int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len,
|
||||||
int ntfs_names_collate(const ntfschar *name1, const u32 name1_len,
|
|
||||||
const ntfschar *name2, const u32 name2_len,
|
const ntfschar *name2, const u32 name2_len,
|
||||||
const int err_val __attribute__((unused)),
|
|
||||||
const IGNORE_CASE_BOOL ic, const ntfschar *upcase,
|
const IGNORE_CASE_BOOL ic, const ntfschar *upcase,
|
||||||
const u32 upcase_len)
|
const u32 upcase_len)
|
||||||
{
|
{
|
||||||
u32 cnt;
|
u32 cnt;
|
||||||
ntfschar c1, c2;
|
u16 c1, c2;
|
||||||
|
u16 u1, u2;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) {
|
if (!name1 || !name2 || (ic && (!upcase || !upcase_len))) {
|
||||||
@ -171,38 +164,70 @@ int ntfs_names_collate(const ntfschar *name1, const u32 name1_len,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
cnt = min(name1_len, name2_len);
|
cnt = min(name1_len, name2_len);
|
||||||
/* JPA average loop count is 8 */
|
|
||||||
if (cnt > 0) {
|
if (cnt > 0) {
|
||||||
if (ic)
|
if (ic == CASE_SENSITIVE) {
|
||||||
/* JPA this loop in 76% cases */
|
|
||||||
do {
|
do {
|
||||||
c1 = le16_to_cpu(*name1);
|
c1 = le16_to_cpu(*name1);
|
||||||
name1++;
|
name1++;
|
||||||
c2 = le16_to_cpu(*name2);
|
c2 = le16_to_cpu(*name2);
|
||||||
name2++;
|
name2++;
|
||||||
if (c1 < upcase_len)
|
} while (--cnt && (c1 == c2));
|
||||||
c1 = le16_to_cpu(upcase[c1]);
|
u1 = c1;
|
||||||
if (c2 < upcase_len)
|
u2 = c2;
|
||||||
c2 = le16_to_cpu(upcase[c2]);
|
if (u1 < upcase_len)
|
||||||
} while ((c1 == c2) && --cnt);
|
u1 = le16_to_cpu(upcase[u1]);
|
||||||
else
|
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 {
|
do {
|
||||||
/* JPA this loop in 24% cases */
|
u1 = c1 = le16_to_cpu(*name1);
|
||||||
c1 = le16_to_cpu(*name1);
|
|
||||||
name1++;
|
name1++;
|
||||||
c2 = le16_to_cpu(*name2);
|
u2 = c2 = le16_to_cpu(*name2);
|
||||||
name2++;
|
name2++;
|
||||||
} while ((c1 == c2) && --cnt);
|
if (u1 < upcase_len)
|
||||||
if (c1 < c2)
|
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;
|
return -1;
|
||||||
if (c1 > c2)
|
if (name1_len > name2_len)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (name1_len < name2_len)
|
return 0;
|
||||||
return -1;
|
|
||||||
if (name1_len == name2_len)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -264,7 +289,7 @@ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n)
|
|||||||
int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
|
int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
|
||||||
const ntfschar *upcase, const u32 upcase_size)
|
const ntfschar *upcase, const u32 upcase_size)
|
||||||
{
|
{
|
||||||
ntfschar c1, c2;
|
u16 c1, c2;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -357,13 +382,28 @@ void ntfs_name_upcase(ntfschar *name, u32 name_len, const ntfschar *upcase,
|
|||||||
const u32 upcase_len)
|
const u32 upcase_len)
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 i;
|
||||||
ntfschar u;
|
u16 u;
|
||||||
|
|
||||||
for (i = 0; i < name_len; i++)
|
for (i = 0; i < name_len; i++)
|
||||||
if ((u = le16_to_cpu(name[i])) < upcase_len)
|
if ((u = le16_to_cpu(name[i])) < upcase_len)
|
||||||
name[i] = upcase[u];
|
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
|
* ntfs_file_value_upcase - Convert a filename to upper case
|
||||||
* @file_name_attr:
|
* @file_name_attr:
|
||||||
@ -381,31 +421,6 @@ void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr,
|
|||||||
file_name_attr->file_name_length, upcase, upcase_len);
|
file_name_attr->file_name_length, upcase, upcase_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ntfs_file_values_compare - Which of two filenames should be listed first
|
|
||||||
* @file_name_attr1:
|
|
||||||
* @file_name_attr2:
|
|
||||||
* @err_val:
|
|
||||||
* @ic:
|
|
||||||
* @upcase:
|
|
||||||
* @upcase_len:
|
|
||||||
*
|
|
||||||
* Description...
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
*/
|
|
||||||
int ntfs_file_values_compare(const FILE_NAME_ATTR *file_name_attr1,
|
|
||||||
const FILE_NAME_ATTR *file_name_attr2,
|
|
||||||
const int err_val, const IGNORE_CASE_BOOL ic,
|
|
||||||
const ntfschar *upcase, const u32 upcase_len)
|
|
||||||
{
|
|
||||||
return ntfs_names_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,
|
|
||||||
err_val, ic, upcase, upcase_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NTFS uses Unicode (UTF-16LE [NTFS-3G uses UCS-2LE, which is enough
|
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
|
for now]) for path names, but the Unicode code points need to be
|
||||||
@ -505,7 +520,7 @@ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len,
|
|||||||
|
|
||||||
char *t;
|
char *t;
|
||||||
int i, size, ret = -1;
|
int i, size, ret = -1;
|
||||||
ntfschar halfpair;
|
int halfpair;
|
||||||
|
|
||||||
halfpair = 0;
|
halfpair = 0;
|
||||||
if (!*outs)
|
if (!*outs)
|
||||||
@ -614,24 +629,26 @@ static int utf8_to_utf16_size(const char *s)
|
|||||||
while ((byte = *((const unsigned char *)s++))) {
|
while ((byte = *((const unsigned char *)s++))) {
|
||||||
if (++count >= PATH_MAX)
|
if (++count >= PATH_MAX)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (byte >= 0xF5) {
|
if (byte >= 0xc0) {
|
||||||
errno = EILSEQ;
|
if (byte >= 0xF5) {
|
||||||
goto out;
|
errno = EILSEQ;
|
||||||
}
|
goto out;
|
||||||
if (!*s)
|
}
|
||||||
break;
|
if (!*s)
|
||||||
if (byte >= 0xC0)
|
break;
|
||||||
s++;
|
if (byte >= 0xC0)
|
||||||
if (!*s)
|
s++;
|
||||||
break;
|
if (!*s)
|
||||||
if (byte >= 0xE0)
|
break;
|
||||||
s++;
|
if (byte >= 0xE0)
|
||||||
if (!*s)
|
s++;
|
||||||
break;
|
if (!*s)
|
||||||
if (byte >= 0xF0) {
|
break;
|
||||||
s++;
|
if (byte >= 0xF0) {
|
||||||
if (++count >= PATH_MAX)
|
s++;
|
||||||
goto fail;
|
if (++count >= PATH_MAX)
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = count;
|
ret = count;
|
||||||
@ -663,8 +680,6 @@ static int utf8_to_unicode(u32 *wc, const char *s)
|
|||||||
} else if (byte < 0xc2) {
|
} else if (byte < 0xc2) {
|
||||||
goto fail;
|
goto fail;
|
||||||
} else if (byte < 0xE0) {
|
} else if (byte < 0xE0) {
|
||||||
if (strlen(s) < 2)
|
|
||||||
goto fail;
|
|
||||||
if ((s[1] & 0xC0) == 0x80) {
|
if ((s[1] & 0xC0) == 0x80) {
|
||||||
*wc = ((u32)(byte & 0x1F) << 6)
|
*wc = ((u32)(byte & 0x1F) << 6)
|
||||||
| ((u32)(s[1] & 0x3F));
|
| ((u32)(s[1] & 0x3F));
|
||||||
@ -673,8 +688,6 @@ static int utf8_to_unicode(u32 *wc, const char *s)
|
|||||||
goto fail;
|
goto fail;
|
||||||
/* three-byte */
|
/* three-byte */
|
||||||
} else if (byte < 0xF0) {
|
} else if (byte < 0xF0) {
|
||||||
if (strlen(s) < 3)
|
|
||||||
goto fail;
|
|
||||||
if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80)) {
|
if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80)) {
|
||||||
*wc = ((u32)(byte & 0x0F) << 12)
|
*wc = ((u32)(byte & 0x0F) << 12)
|
||||||
| ((u32)(s[1] & 0x3F) << 6)
|
| ((u32)(s[1] & 0x3F) << 6)
|
||||||
@ -693,8 +706,6 @@ static int utf8_to_unicode(u32 *wc, const char *s)
|
|||||||
goto fail;
|
goto fail;
|
||||||
/* four-byte */
|
/* four-byte */
|
||||||
} else if (byte < 0xF5) {
|
} else if (byte < 0xF5) {
|
||||||
if (strlen(s) < 4)
|
|
||||||
goto fail;
|
|
||||||
if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80)
|
if (((s[1] & 0xC0) == 0x80) && ((s[2] & 0xC0) == 0x80)
|
||||||
&& ((s[3] & 0xC0) == 0x80)) {
|
&& ((s[3] & 0xC0) == 0x80)) {
|
||||||
*wc = ((u32)(byte & 0x07) << 18)
|
*wc = ((u32)(byte & 0x07) << 18)
|
||||||
@ -737,6 +748,7 @@ static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs)
|
|||||||
#endif /* defined(__APPLE__) || defined(__DARWIN__) */
|
#endif /* defined(__APPLE__) || defined(__DARWIN__) */
|
||||||
const char *t = ins;
|
const char *t = ins;
|
||||||
u32 wc;
|
u32 wc;
|
||||||
|
BOOL allocated;
|
||||||
ntfschar *outpos;
|
ntfschar *outpos;
|
||||||
int shorts, ret = -1;
|
int shorts, ret = -1;
|
||||||
|
|
||||||
@ -744,18 +756,30 @@ static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs)
|
|||||||
if (shorts < 0)
|
if (shorts < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
allocated = FALSE;
|
||||||
if (!*outs) {
|
if (!*outs) {
|
||||||
*outs = ntfs_malloc((shorts + 1) * sizeof(ntfschar));
|
*outs = ntfs_malloc((shorts + 1) * sizeof(ntfschar));
|
||||||
if (!*outs)
|
if (!*outs)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
allocated = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
outpos = *outs;
|
outpos = *outs;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
int m = utf8_to_unicode(&wc, t);
|
int m = utf8_to_unicode(&wc, t);
|
||||||
if (m < 0)
|
if (m <= 0) {
|
||||||
goto fail;
|
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)
|
if (wc < 0x10000)
|
||||||
*outpos++ = cpu_to_le16(wc);
|
*outpos++ = cpu_to_le16(wc);
|
||||||
else {
|
else {
|
||||||
@ -763,8 +787,6 @@ static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs)
|
|||||||
*outpos++ = cpu_to_le16((wc >> 10) + 0xd800);
|
*outpos++ = cpu_to_le16((wc >> 10) + 0xd800);
|
||||||
*outpos++ = cpu_to_le16((wc & 0x3ff) + 0xdc00);
|
*outpos++ = cpu_to_le16((wc & 0x3ff) + 0xdc00);
|
||||||
}
|
}
|
||||||
if (m == 0)
|
|
||||||
break;
|
|
||||||
t += m;
|
t += m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,6 +1050,61 @@ err_out:
|
|||||||
return -1;
|
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
|
* ntfs_upcase_table_build - build the default upcase table for NTFS
|
||||||
* @uc: destination buffer where to store the built table
|
* @uc: destination buffer where to store the built table
|
||||||
@ -1099,6 +1176,38 @@ void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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<uc_cnt; i++)
|
||||||
|
lc[i] = cpu_to_le16(i);
|
||||||
|
for (i=0; i<uc_cnt; i++) {
|
||||||
|
upp = le16_to_cpu(uc[i]);
|
||||||
|
if ((upp != i) && (upp < uc_cnt))
|
||||||
|
lc[upp] = cpu_to_le16(i);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
ntfs_log_error("Could not build the locase table\n");
|
||||||
|
return (lc);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ntfs_str2ucs - convert a string to a valid NTFS file name
|
* ntfs_str2ucs - convert a string to a valid NTFS file name
|
||||||
* @s: input string
|
* @s: input string
|
||||||
@ -1170,7 +1279,9 @@ BOOL ntfs_forbidden_chars(const ntfschar *name, int len)
|
|||||||
| (1L << ('>' - 0x20))
|
| (1L << ('>' - 0x20))
|
||||||
| (1L << ('?' - 0x20));
|
| (1L << ('?' - 0x20));
|
||||||
|
|
||||||
forbidden = (len == 0) || (le16_to_cpu(name[len-1]) == ' ');
|
forbidden = (len == 0)
|
||||||
|
|| (le16_to_cpu(name[len-1]) == ' ')
|
||||||
|
|| (le16_to_cpu(name[len-1]) == '.');
|
||||||
for (i=0; i<len; i++) {
|
for (i=0; i<len; i++) {
|
||||||
ch = le16_to_cpu(name[i]);
|
ch = le16_to_cpu(name[i]);
|
||||||
if ((ch < 0x20)
|
if ((ch < 0x20)
|
||||||
|
@ -30,9 +30,9 @@ 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 *s2, size_t s2_len, const IGNORE_CASE_BOOL ic,
|
||||||
const ntfschar *upcase, const u32 upcase_size);
|
const ntfschar *upcase, const u32 upcase_size);
|
||||||
|
|
||||||
extern int ntfs_names_collate(const ntfschar *name1, const u32 name1_len,
|
extern int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len,
|
||||||
const ntfschar *name2, const u32 name2_len,
|
const ntfschar *name2, const u32 name2_len,
|
||||||
const int err_val, const IGNORE_CASE_BOOL ic,
|
const IGNORE_CASE_BOOL ic,
|
||||||
const ntfschar *upcase, const u32 upcase_len);
|
const ntfschar *upcase, const u32 upcase_len);
|
||||||
|
|
||||||
extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
|
extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
|
||||||
@ -47,19 +47,21 @@ extern ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen);
|
|||||||
extern void ntfs_name_upcase(ntfschar *name, u32 name_len,
|
extern void ntfs_name_upcase(ntfschar *name, u32 name_len,
|
||||||
const ntfschar *upcase, const u32 upcase_len);
|
const ntfschar *upcase, const u32 upcase_len);
|
||||||
|
|
||||||
extern void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr,
|
extern void ntfs_name_locase(ntfschar *name, u32 name_len,
|
||||||
const ntfschar *upcase, const u32 upcase_len);
|
const ntfschar *locase, const u32 locase_len);
|
||||||
|
|
||||||
extern int ntfs_file_values_compare(const FILE_NAME_ATTR *file_name_attr1,
|
extern void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr,
|
||||||
const FILE_NAME_ATTR *file_name_attr2,
|
|
||||||
const int err_val, const IGNORE_CASE_BOOL ic,
|
|
||||||
const ntfschar *upcase, const u32 upcase_len);
|
const ntfschar *upcase, const u32 upcase_len);
|
||||||
|
|
||||||
extern int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs,
|
extern int ntfs_ucstombs(const ntfschar *ins, const int ins_len, char **outs,
|
||||||
int outs_len);
|
int outs_len);
|
||||||
extern int ntfs_mbstoucs(const char *ins, ntfschar **outs);
|
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 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 ntfschar *ntfs_str2ucs(const char *s, int *len);
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Copyright (c) 2000-2006 Anton Altaparmakov
|
* Copyright (c) 2000-2006 Anton Altaparmakov
|
||||||
* Copyright (c) 2002-2009 Szabolcs Szakacsits
|
* Copyright (c) 2002-2009 Szabolcs Szakacsits
|
||||||
* Copyright (c) 2004-2005 Richard Russon
|
* 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
|
* This program/include file is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License as published
|
* modify it under the terms of the GNU General Public License as published
|
||||||
@ -65,6 +66,7 @@
|
|||||||
#include "logfile.h"
|
#include "logfile.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
#include "cache.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
const char *ntfs_home =
|
const char *ntfs_home =
|
||||||
@ -200,6 +202,7 @@ static int __ntfs_volume_release(ntfs_volume *v)
|
|||||||
ntfs_free_lru_caches(v);
|
ntfs_free_lru_caches(v);
|
||||||
free(v->vol_name);
|
free(v->vol_name);
|
||||||
free(v->upcase);
|
free(v->upcase);
|
||||||
|
if (v->locase) free(v->locase);
|
||||||
free(v->attrdef);
|
free(v->attrdef);
|
||||||
free(v);
|
free(v);
|
||||||
|
|
||||||
@ -486,7 +489,14 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags)
|
|||||||
|
|
||||||
ntfs_upcase_table_build(vol->upcase,
|
ntfs_upcase_table_build(vol->upcase,
|
||||||
vol->upcase_len * sizeof(ntfschar));
|
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)
|
if (flags & MS_RDONLY)
|
||||||
NVolSetReadOnly(vol);
|
NVolSetReadOnly(vol);
|
||||||
|
|
||||||
@ -760,6 +770,70 @@ out:
|
|||||||
return errno ? -1 : 0;
|
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
|
* ntfs_device_mount - open ntfs volume
|
||||||
* @dev: device to open
|
* @dev: device to open
|
||||||
@ -1045,9 +1119,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags)
|
|||||||
goto error_exit;
|
goto error_exit;
|
||||||
|
|
||||||
for (j = 0; j < (s32)u; j++) {
|
for (j = 0; j < (s32)u; j++) {
|
||||||
ntfschar uc = le16_to_cpu(vname[j]);
|
u16 uc = le16_to_cpu(vname[j]);
|
||||||
if (uc > 0xff)
|
if (uc > 0xff)
|
||||||
uc = (ntfschar)'_';
|
uc = (u16)'_';
|
||||||
vol->vol_name[j] = (char)uc;
|
vol->vol_name[j] = (char)uc;
|
||||||
}
|
}
|
||||||
vol->vol_name[u] = '\0';
|
vol->vol_name[u] = '\0';
|
||||||
@ -1111,6 +1185,9 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, unsigned long flags)
|
|||||||
goto error_exit;
|
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;
|
return vol;
|
||||||
io_error_exit:
|
io_error_exit:
|
||||||
@ -1126,6 +1203,58 @@ error_exit:
|
|||||||
return NULL;
|
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
|
* ntfs_mount - open ntfs volume
|
||||||
* @name: name of device/file to open
|
* @name: name of device/file to open
|
||||||
@ -1432,7 +1561,7 @@ error_exit:
|
|||||||
*
|
*
|
||||||
* Return 0 if successful and -1 if not with errno set to the error code.
|
* Return 0 if successful and -1 if not with errno set to the error code.
|
||||||
*/
|
*/
|
||||||
int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags)
|
int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags)
|
||||||
{
|
{
|
||||||
ATTR_RECORD *a;
|
ATTR_RECORD *a;
|
||||||
VOLUME_INFORMATION *c;
|
VOLUME_INFORMATION *c;
|
||||||
|
@ -42,10 +42,6 @@
|
|||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CACHE_INODE_SIZE 32 /* inode 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 */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY,
|
* Under Cygwin, DJGPP and FreeBSD we do not have MS_RDONLY,
|
||||||
* so we define them ourselves.
|
* so we define them ourselves.
|
||||||
@ -65,6 +61,7 @@
|
|||||||
/* Forward declaration */
|
/* Forward declaration */
|
||||||
typedef struct _ntfs_volume ntfs_volume;
|
typedef struct _ntfs_volume ntfs_volume;
|
||||||
|
|
||||||
|
#include "param.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
@ -110,6 +107,10 @@ typedef enum {
|
|||||||
NV_ReadOnly, /* 1: Volume is read-only. */
|
NV_ReadOnly, /* 1: Volume is read-only. */
|
||||||
NV_CaseSensitive, /* 1: Volume is mounted case-sensitive. */
|
NV_CaseSensitive, /* 1: Volume is mounted case-sensitive. */
|
||||||
NV_LogFileEmpty, /* 1: $logFile journal is empty. */
|
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;
|
} ntfs_volume_state_bits;
|
||||||
|
|
||||||
#define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state)
|
#define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state)
|
||||||
@ -128,6 +129,22 @@ typedef enum {
|
|||||||
#define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty)
|
#define NVolSetLogFileEmpty(nv) set_nvol_flag(nv, LogFileEmpty)
|
||||||
#define NVolClearLogFileEmpty(nv) clear_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 1.1 and 1.2 are used by Windows NT4.
|
||||||
* NTFS version 2.x is used by Windows 2000 Beta
|
* NTFS version 2.x is used by Windows 2000 Beta
|
||||||
@ -159,7 +176,7 @@ struct _ntfs_volume {
|
|||||||
ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */
|
ntfs_inode *vol_ni; /* ntfs_inode structure for FILE_Volume. */
|
||||||
u8 major_ver; /* Ntfs major version of volume. */
|
u8 major_ver; /* Ntfs major version of volume. */
|
||||||
u8 minor_ver; /* Ntfs minor version of volume. */
|
u8 minor_ver; /* Ntfs minor version of volume. */
|
||||||
u16 flags; /* Bit array of VOLUME_* flags. */
|
le16 flags; /* Bit array of VOLUME_* flags. */
|
||||||
|
|
||||||
u16 sector_size; /* Byte size of a sector. */
|
u16 sector_size; /* Byte size of a sector. */
|
||||||
u8 sector_size_bits; /* Log(2) of the byte size of a sector. */
|
u8 sector_size_bits; /* Log(2) of the byte size of a sector. */
|
||||||
@ -220,6 +237,9 @@ struct _ntfs_volume {
|
|||||||
FILE_UpCase. */
|
FILE_UpCase. */
|
||||||
u32 upcase_len; /* Length in Unicode characters of the upcase
|
u32 upcase_len; /* Length in Unicode characters of the upcase
|
||||||
table. */
|
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
|
ATTR_DEF *attrdef; /* Attribute definitions. Obtained from
|
||||||
FILE_AttrDef. */
|
FILE_AttrDef. */
|
||||||
@ -235,6 +255,12 @@ struct _ntfs_volume {
|
|||||||
#if CACHE_INODE_SIZE
|
#if CACHE_INODE_SIZE
|
||||||
struct CACHE_HEADER *xinode_cache;
|
struct CACHE_HEADER *xinode_cache;
|
||||||
#endif
|
#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
|
#if CACHE_SECURID_SIZE
|
||||||
struct CACHE_HEADER *securid_cache;
|
struct CACHE_HEADER *securid_cache;
|
||||||
#endif
|
#endif
|
||||||
@ -261,14 +287,17 @@ extern int ntfs_version_is_supported(ntfs_volume *vol);
|
|||||||
extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose);
|
extern int ntfs_volume_check_hiberfile(ntfs_volume *vol, int verbose);
|
||||||
extern int ntfs_logfile_reset(ntfs_volume *vol);
|
extern int ntfs_logfile_reset(ntfs_volume *vol);
|
||||||
|
|
||||||
extern int ntfs_volume_write_flags(ntfs_volume *vol, const u16 flags);
|
extern int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags);
|
||||||
|
|
||||||
extern int ntfs_volume_error(int err);
|
extern int ntfs_volume_error(int err);
|
||||||
extern void ntfs_mount_error(const char *vol, const char *mntpoint, 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_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_locale(void);
|
||||||
|
extern int ntfs_set_ignore_case(ntfs_volume *vol);
|
||||||
|
|
||||||
#endif /* defined _NTFS_VOLUME_H */
|
#endif /* defined _NTFS_VOLUME_H */
|
||||||
|
|
||||||
|
392
source/main.cpp
392
source/main.cpp
@ -51,6 +51,7 @@ extern "C"
|
|||||||
#include "usbloader/usbstorage2.h"
|
#include "usbloader/usbstorage2.h"
|
||||||
#include "memory/mem2.h"
|
#include "memory/mem2.h"
|
||||||
#include "lstub.h"
|
#include "lstub.h"
|
||||||
|
#include "usbloader/usbstorage2.h"
|
||||||
|
|
||||||
extern bool geckoinit;
|
extern bool geckoinit;
|
||||||
extern bool textVideoInit;
|
extern bool textVideoInit;
|
||||||
@ -65,172 +66,19 @@ extern char headlessID[8];
|
|||||||
FreeTypeGX *fontSystem=0;
|
FreeTypeGX *fontSystem=0;
|
||||||
FreeTypeGX *fontClock=0;
|
FreeTypeGX *fontClock=0;
|
||||||
PartList partitions;
|
PartList partitions;
|
||||||
|
|
||||||
u8 dbvideo =0;
|
u8 dbvideo =0;
|
||||||
|
|
||||||
static void BootUpProblems()
|
int main(int argc, char *argv[])
|
||||||
{
|
|
||||||
s32 ret2;
|
|
||||||
|
|
||||||
// load main font from file, or default to built-in font
|
|
||||||
fontSystem = new FreeTypeGX();
|
|
||||||
fontSystem->loadFont(NULL, font_ttf, font_ttf_size, 0);
|
|
||||||
fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
|
||||||
|
|
||||||
GuiImageData bootimageData(gxlogo_png);
|
|
||||||
GuiImage bootimage(&bootimageData);
|
|
||||||
GuiText boottext(NULL, 20, (GXColor) {255, 255, 255, 255}
|
|
||||||
);
|
|
||||||
boottext.SetPosition(200, 240-1.2*bootimage.GetHeight()/2+250);
|
|
||||||
bootimage.SetPosition(320-1.2*bootimage.GetWidth()/2, 240-1.2*bootimage.GetHeight()/2);
|
|
||||||
bootimage.SetScale(1.2);
|
|
||||||
|
|
||||||
GuiImageData usbimageData(usbport_png);
|
|
||||||
GuiImage usbimage(&usbimageData);
|
|
||||||
usbimage.SetPosition(400,300);
|
|
||||||
usbimage.SetScale(.7);
|
|
||||||
usbimage.SetAlpha(200);
|
|
||||||
|
|
||||||
time_t curtime;
|
|
||||||
time_t endtime = time(0) + 30;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
/*ret2 = IOS_ReloadIOSsafe(249);
|
|
||||||
if (ret2 < 0) {
|
|
||||||
ret2 = IOS_ReloadIOSsafe(222);
|
|
||||||
SDCard_Init();
|
|
||||||
load_ehc_module();
|
|
||||||
SDCard_deInit();
|
|
||||||
if(ret2 <0) {
|
|
||||||
boottext.SetText("ERROR: cIOS could not be loaded!");
|
|
||||||
bootimage.Draw();
|
|
||||||
boottext.Draw();
|
|
||||||
Menu_Render();
|
|
||||||
sleep(5);
|
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
USBDevice_deInit();
|
|
||||||
USBDevice_Init();
|
|
||||||
ret2 = WBFS_Init(WBFS_DEVICE_USB);
|
|
||||||
if (ret2 >= 0)
|
|
||||||
{
|
|
||||||
boottext.SetText("Loading...");
|
|
||||||
bootimage.Draw();
|
|
||||||
boottext.Draw();
|
|
||||||
Menu_Render();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
curtime = time(0);
|
|
||||||
boottext.SetTextf("Waiting for your slow USB Device: %i secs...", int(endtime-curtime));
|
|
||||||
while(curtime == time(0))
|
|
||||||
{
|
|
||||||
boottext.Draw();
|
|
||||||
bootimage.Draw();
|
|
||||||
if (endtime-curtime<15)usbimage.Draw();
|
|
||||||
Menu_Render();
|
|
||||||
}
|
|
||||||
} while((endtime-time(0)) > 0);
|
|
||||||
|
|
||||||
/*if(ret2 < 0) {
|
|
||||||
boottext.SetText("ERROR: USB device could not be loaded!");
|
|
||||||
usbimage.Draw();
|
|
||||||
bootimage.Draw();
|
|
||||||
boottext.Draw();
|
|
||||||
Menu_Render();
|
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
///delete font to load up custom if set
|
|
||||||
if(fontSystem)
|
|
||||||
{
|
|
||||||
delete fontSystem;
|
|
||||||
fontSystem = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int *xfb = NULL;
|
|
||||||
|
|
||||||
void InitTextVideo ()
|
|
||||||
{
|
|
||||||
gprintf("\nInitTextVideo ()");
|
|
||||||
if (textVideoInit)
|
|
||||||
{
|
|
||||||
gprintf("...0");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dbvideo=1;
|
|
||||||
VIDEO_Init();
|
|
||||||
// get default video mode
|
|
||||||
GXRModeObj *vmode = VIDEO_GetPreferredMode(NULL);
|
|
||||||
|
|
||||||
// widescreen fix
|
|
||||||
VIDEO_Configure (vmode);
|
|
||||||
|
|
||||||
// Allocate the video buffers
|
|
||||||
xfb = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
|
|
||||||
|
|
||||||
// A console is always useful while debugging
|
|
||||||
console_init (xfb, 20, 64, vmode->fbWidth, vmode->xfbHeight, vmode->fbWidth * 2);
|
|
||||||
|
|
||||||
// Clear framebuffers etc.
|
|
||||||
VIDEO_ClearFrameBuffer (vmode, xfb, COLOR_BLACK);
|
|
||||||
VIDEO_SetNextFramebuffer (xfb);
|
|
||||||
|
|
||||||
VIDEO_SetBlack (FALSE);
|
|
||||||
VIDEO_Flush ();
|
|
||||||
VIDEO_WaitVSync ();
|
|
||||||
if (vmode->viTVMode & VI_NON_INTERLACE)
|
|
||||||
VIDEO_WaitVSync ();
|
|
||||||
|
|
||||||
//send console output to the gecko
|
|
||||||
if (geckoinit)CON_EnableGecko(1, true);
|
|
||||||
textVideoInit = true;
|
|
||||||
gprintf("...1");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
|
MEM2_init(48);
|
||||||
|
PAD_Init();
|
||||||
|
InitVideo();
|
||||||
setlocale(LC_ALL, "en.UTF-8");
|
setlocale(LC_ALL, "en.UTF-8");
|
||||||
geckoinit = InitGecko();
|
geckoinit = InitGecko();
|
||||||
|
__exception_setreload(5);
|
||||||
if (hbcStubAvailable() || geckoinit)
|
|
||||||
{
|
|
||||||
InitTextVideo();
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEBUG_Init(GDBSTUB_DEVICE_USB, 1);
|
|
||||||
//_break();
|
|
||||||
|
|
||||||
__exception_setreload(5); //auto reset code dump nobody gives us codedump info anyways.
|
|
||||||
|
|
||||||
gprintf("\n\n------------------");
|
|
||||||
gprintf("\nUSB Loader GX rev%s",GetRev());
|
|
||||||
gprintf("\nmain(%d", argc);
|
|
||||||
for (int i=0;i<argc;i++)
|
|
||||||
gprintf(", %s",argv[i]?argv[i]:"<NULL>");
|
|
||||||
gprintf(")");
|
|
||||||
|
|
||||||
// This part is added, because we need a identify patched ios
|
|
||||||
// printf("\n\tReloading into ios 236");
|
|
||||||
if (IOS_ReloadIOSsafe(236) < 0)
|
|
||||||
{
|
|
||||||
// printf("\n\tIOS 236 not found, reloading into 36");
|
|
||||||
IOS_ReloadIOSsafe(36);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n\tStarting up");
|
printf("\n\tStarting up");
|
||||||
|
|
||||||
MEM2_init(36); // Initialize 36 MB
|
|
||||||
MEM2_takeBigOnes(true);
|
|
||||||
|
|
||||||
s32 ret;
|
|
||||||
bool startupproblem = false;
|
|
||||||
|
|
||||||
bool bootDevice_found=false;
|
bool bootDevice_found=false;
|
||||||
if (argc >= 1)
|
if (argc >= 1)
|
||||||
{
|
{
|
||||||
@ -242,144 +90,15 @@ main(int argc, char *argv[])
|
|||||||
bootDevice_found = true;
|
bootDevice_found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n\tInitializing controllers");
|
//Let's use libogc sd/usb for config loading
|
||||||
|
|
||||||
/** PAD_Init has to be before InitVideo don't move that **/
|
|
||||||
PAD_Init(); // initialize PAD/WPAD
|
|
||||||
|
|
||||||
printf("\n\tInitialize USB (wake up)");
|
|
||||||
|
|
||||||
USBDevice_Init(); // seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5")
|
|
||||||
|
|
||||||
gprintf("\n\tChecking for stub IOS");
|
|
||||||
ios222rev = getIOSrev(0x00000001000000dell);
|
|
||||||
ios249rev = getIOSrev(0x00000001000000f9ll);
|
|
||||||
|
|
||||||
//if we don't like either of the cIOS then scram
|
|
||||||
if (!(ios222rev==4 || ios222rev==5 || (ios249rev>=9 && ios249rev<65280)))
|
|
||||||
{
|
|
||||||
InitTextVideo();
|
|
||||||
printf("\x1b[2J");
|
|
||||||
if ((ios222rev < 0 && ios222rev != WII_EINSTALL) && (ios249rev < 0 && ios249rev != WII_EINSTALL))
|
|
||||||
{
|
|
||||||
printf("\n\n\n\tWARNING!");
|
|
||||||
printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+");
|
|
||||||
printf("\n\n\tWe cannot determine the versions on your system,\n\tsince you have no patched ios 36 or 236 installed.");
|
|
||||||
printf("\n\tTherefor, if loading of USB Loader GX fails, you\n\tprobably have installed the 4.2 update,");
|
|
||||||
printf("\n\tand you should go figure out how to get some cios action going on\n\tin your Wii.");
|
|
||||||
printf("\n\n\tThis message will show every time.");
|
|
||||||
sleep(5);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("\n\n\n\tERROR!");
|
|
||||||
printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+");
|
|
||||||
printf("\n\n\tI found \n\t\t222 = %d%s",ios222rev,ios222rev==65280?" (Stubbed by 4.2 update)":"");
|
|
||||||
printf("\n\t\t249 = %d%s",ios249rev,ios249rev==65280?" (Stubbed by 4.2 update)":"");
|
|
||||||
printf("\n\n\tGo figure out how to get some cIOS action going on\n\tin your Wii and come back and see me.");
|
|
||||||
|
|
||||||
sleep(15);
|
|
||||||
printf("\n\n\tBye");
|
|
||||||
|
|
||||||
USBDevice_deInit();
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n\tReloading ios 249...");
|
|
||||||
ret = IOS_ReloadIOSsafe(249);
|
|
||||||
|
|
||||||
printf("%d", ret);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("\n\tIOS 249 failed, reloading ios 222...");
|
|
||||||
ret = IOS_ReloadIOSsafe(222);
|
|
||||||
printf("%d", ret);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("\n\tIOS 222 failed, reloading ios 250...");
|
|
||||||
ret = IOS_ReloadIOSsafe(250);
|
|
||||||
printf("%d", ret);
|
|
||||||
|
|
||||||
if(ret < 0)
|
|
||||||
{
|
|
||||||
printf("\n\tIOS 250 failed, reloading ios 223...");
|
|
||||||
ret = IOS_ReloadIOSsafe(223);
|
|
||||||
printf("%d", ret);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("\n\tERROR: cIOS could not be loaded!\n");
|
|
||||||
sleep(5);
|
|
||||||
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("\n\tInitialize sd card");
|
|
||||||
SDCard_Init();
|
|
||||||
printf("\n\tLoad ehc module");
|
|
||||||
load_ehc_module();
|
|
||||||
printf("\n\tdeinit sd card");
|
|
||||||
SDCard_deInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n\tInit wbfs...");
|
|
||||||
ret = WBFS_Init(WBFS_DEVICE_USB);
|
|
||||||
printf("%d", ret);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("\n\tYou have issues with a slow disc, or a difficult disc\n\tReloading 222...");
|
|
||||||
ret = IOS_ReloadIOSsafe(222);
|
|
||||||
printf("%d", ret);
|
|
||||||
/*if(ret < 0) {
|
|
||||||
// printf("\n\tSleeping for 4 seconds");
|
|
||||||
// sleep(4);
|
|
||||||
|
|
||||||
InitVideo(); // Initialise video
|
|
||||||
Menu_Render();
|
|
||||||
BootUpProblems();
|
|
||||||
startupproblem = true;
|
|
||||||
ret = 1;
|
|
||||||
}*/
|
|
||||||
printf("\n\tInitialize sd card");
|
|
||||||
SDCard_Init();
|
|
||||||
printf("\n\tLoad ehc module");
|
|
||||||
load_ehc_module();
|
|
||||||
printf("\n\tdeinit sd card");
|
|
||||||
SDCard_deInit();
|
|
||||||
|
|
||||||
printf("\n\tInitialize wbfs...");
|
|
||||||
USBDevice_deInit();
|
|
||||||
USBDevice_Init();
|
|
||||||
ret = WBFS_Init(WBFS_DEVICE_USB);
|
|
||||||
printf("%d", ret);
|
|
||||||
|
|
||||||
if(ret < 0)
|
|
||||||
{
|
|
||||||
// printf("\n\tSleeping for 4 seconds");
|
|
||||||
// sleep(4);
|
|
||||||
InitVideo(); // Initialise video
|
|
||||||
Menu_Render();
|
|
||||||
BootUpProblems();
|
|
||||||
startupproblem = true;
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\n\tInitialize sd card");
|
printf("\n\tInitialize sd card");
|
||||||
SDCard_Init(); // mount SD for loading cfg's
|
SDCard_Init();
|
||||||
|
|
||||||
//this should have already been done by now in order to WBFS_Init().
|
|
||||||
printf("\n\tInitialize usb device");
|
printf("\n\tInitialize usb device");
|
||||||
USBDevice_Init(); // and mount USB:/
|
USBDevice_Init();
|
||||||
|
|
||||||
if (!bootDevice_found)
|
if (!bootDevice_found)
|
||||||
{
|
{
|
||||||
printf("\n\tSearch for configuration file");
|
printf("\n\tSearch for configuration file");
|
||||||
|
|
||||||
//try USB
|
//try USB
|
||||||
//left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config
|
//left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config
|
||||||
if (checkfile((char*) "USB:/config/GXglobal.cfg") || (checkfile((char*) "USB:/apps/usbloader_gx/boot.elf"))
|
if (checkfile((char*) "USB:/config/GXglobal.cfg") || (checkfile((char*) "USB:/apps/usbloader_gx/boot.elf"))
|
||||||
@ -390,82 +109,39 @@ main(int argc, char *argv[])
|
|||||||
printf("\n\tConfiguration file is on %s", bootDevice);
|
printf("\n\tConfiguration file is on %s", bootDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try opening and closing the configuration file here
|
|
||||||
// to prevent a crash dump later on - giantpune
|
|
||||||
char GXGlobal_cfg[26];
|
|
||||||
sprintf(GXGlobal_cfg, "%s/config/GXGlobal.cfg", bootDevice);
|
|
||||||
FILE *fp = fopen(GXGlobal_cfg, "r");
|
|
||||||
if (fp)
|
|
||||||
{
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
gettextCleanUp();
|
gettextCleanUp();
|
||||||
printf("\n\tLoading configuration...");
|
printf("\n\tLoading configuration...");
|
||||||
CFG_Load();
|
CFG_Load();
|
||||||
printf("done");
|
printf("done");
|
||||||
// gprintf("\n\tbootDevice = %s",bootDevice);
|
|
||||||
|
|
||||||
/* Load Custom IOS */
|
SDCard_deInit();// unmount SD for reloading IOS
|
||||||
if ((Settings.cios == ios222 && IOS_GetVersion() != 222) ||
|
USBDevice_deInit();// unmount USB for reloading IOS
|
||||||
(Settings.cios == ios223 && IOS_GetVersion() != 223))
|
USBStorage2_Deinit();
|
||||||
|
|
||||||
|
// This part is added, because we need a identify patched ios
|
||||||
|
//! pune please replace this with your magic patch functions - Dimok
|
||||||
|
if (IOS_ReloadIOSsafe(236) < 0)
|
||||||
|
IOS_ReloadIOSsafe(36);
|
||||||
|
|
||||||
|
printf("\n\tCheck for an existing cIOS");
|
||||||
|
CheckForCIOS();
|
||||||
|
|
||||||
|
// Let's load the cIOS now
|
||||||
|
if(LoadAppCIOS() < 0)
|
||||||
{
|
{
|
||||||
printf("\n\tReloading IOS to config setting (%d)...", Settings.cios == ios222 ? 222 : 223);
|
printf("\n\tERROR: No cIOS could be loaded. Exiting....");
|
||||||
SDCard_deInit(); // unmount SD for reloading IOS
|
|
||||||
USBDevice_deInit(); // unmount USB for reloading IOS
|
|
||||||
USBStorage2_Deinit();
|
|
||||||
ret = IOS_ReloadIOSsafe(Settings.cios == ios222 ? 222 : 223);
|
|
||||||
printf("%d", ret);
|
|
||||||
SDCard_Init();
|
|
||||||
load_ehc_module();
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
SDCard_deInit();
|
|
||||||
Settings.cios = ios249;
|
|
||||||
ret = IOS_ReloadIOSsafe(249);
|
|
||||||
// now mount SD:/ //no need to keep mindlessly mounting and unmounting SD card
|
|
||||||
SDCard_Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
USBDevice_Init(); // and mount USB:/
|
|
||||||
WBFS_Init(WBFS_DEVICE_USB);
|
|
||||||
} else if ((Settings.cios == ios249 && IOS_GetVersion() != 249) ||
|
|
||||||
(Settings.cios == ios250 && IOS_GetVersion() != 250))
|
|
||||||
{
|
|
||||||
|
|
||||||
printf("\n\tReloading IOS to config setting (%d)...", ios249 ? 249 : 250);
|
|
||||||
SDCard_deInit(); // unmount SD for reloading IOS
|
|
||||||
USBDevice_deInit(); // unmount USB for reloading IOS
|
|
||||||
USBStorage2_Deinit();
|
|
||||||
ret = IOS_ReloadIOSsafe(ios249 ? 249 : 250);
|
|
||||||
printf("%d", ret);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
Settings.cios = ios222;
|
|
||||||
ret = IOS_ReloadIOSsafe(222);
|
|
||||||
SDCard_Init();
|
|
||||||
load_ehc_module();
|
|
||||||
}
|
|
||||||
|
|
||||||
else SDCard_Init(); // now mount SD:/ //no need to keep mindlessly mounting and unmounting SD card
|
|
||||||
USBDevice_Init(); // and mount USB:/
|
|
||||||
WBFS_Init(WBFS_DEVICE_USB);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Partition_GetList(&partitions);
|
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
printf("\nERROR: cIOS could not be loaded!");
|
|
||||||
sleep(5);
|
sleep(5);
|
||||||
exit(0);
|
Sys_BackToLoader();
|
||||||
//SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
||||||
}
|
}
|
||||||
//gprintf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());//don't need gprintf if sending console shit to gecko, too
|
|
||||||
printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());
|
printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());
|
||||||
|
|
||||||
// printf("Sleeping for 5 seconds\n");
|
// Init WBFS
|
||||||
// sleep(5);
|
int ret = WBFS_Init(WBFS_DEVICE_USB);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("\nERROR: No WBFS drive mounted.");
|
||||||
|
}
|
||||||
|
|
||||||
//if a ID was passed via args copy it and try to boot it after the partition is mounted
|
//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.
|
//its not really a headless mode. more like hairless.
|
||||||
@ -478,9 +154,7 @@ main(int argc, char *argv[])
|
|||||||
//! Init the rest of the System
|
//! Init the rest of the System
|
||||||
Sys_Init();
|
Sys_Init();
|
||||||
Wpad_Init();
|
Wpad_Init();
|
||||||
if(!startupproblem)
|
InitAudio();
|
||||||
InitVideo();
|
|
||||||
InitAudio(); // Initialize audio
|
|
||||||
|
|
||||||
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
||||||
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
|
|
||||||
#include "mem2.h"
|
#include "mem2.h"
|
||||||
#include "mem2alloc.h"
|
#include "mem2alloc.hpp"
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define MEM2_PRIORITY_SIZE 0x40
|
#define MEM2_PRIORITY_SIZE 2097152 //2MB
|
||||||
|
|
||||||
// Forbid the use of MEM2 through malloc
|
// Forbid the use of MEM2 through malloc
|
||||||
u32 MALLOC_MEM2 = 0;
|
u32 MALLOC_MEM2 = 0;
|
||||||
|
|
||||||
static CMEM2Alloc g_mem2gp;
|
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)
|
void MEM2_init(unsigned int mem2Size)
|
||||||
{
|
{
|
||||||
g_mem2gp.init(mem2Size);
|
g_mem2gp.init(mem2Size);
|
||||||
@ -22,41 +32,31 @@ void MEM2_cleanup(void)
|
|||||||
g_mem2gp.cleanup();
|
g_mem2gp.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void *MEM2_alloc(unsigned int s)
|
void *MEM2_alloc(unsigned int s)
|
||||||
{
|
{
|
||||||
return g_mem2gp.allocate(s);
|
return g_mem2gp.allocate(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void MEM2_free(void *p)
|
void MEM2_free(void *p)
|
||||||
{
|
{
|
||||||
g_mem2gp.release(p);
|
g_mem2gp.release(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void *MEM2_realloc(void *p, unsigned int s)
|
void *MEM2_realloc(void *p, unsigned int s)
|
||||||
{
|
{
|
||||||
return g_mem2gp.reallocate(p, s);
|
return g_mem2gp.reallocate(p, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" unsigned int MEM2_usableSize(void *p)
|
unsigned int MEM2_usableSize(void *p)
|
||||||
{
|
{
|
||||||
return CMEM2Alloc::usableSize(p);
|
return CMEM2Alloc::usableSize(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give priority to MEM2 for big allocations
|
unsigned int MEM2_freesize()
|
||||||
// Used for saving some space in malloc, which is required for 2 reasons :
|
|
||||||
// - decent speed on small and frequent allocations
|
|
||||||
// - newlib uses its malloc internally (for *printf for example) so it should always have some memory left
|
|
||||||
bool g_bigGoesToMem2 = false;
|
|
||||||
|
|
||||||
void MEM2_takeBigOnes(bool b)
|
|
||||||
{
|
{
|
||||||
g_bigGoesToMem2 = b;
|
return g_mem2gp.FreeSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
|
|
||||||
extern __typeof(malloc) __real_malloc;
|
extern __typeof(malloc) __real_malloc;
|
||||||
extern __typeof(calloc) __real_calloc;
|
extern __typeof(calloc) __real_calloc;
|
||||||
extern __typeof(realloc) __real_realloc;
|
extern __typeof(realloc) __real_realloc;
|
||||||
@ -133,9 +133,12 @@ void __wrap_free(void *p)
|
|||||||
if(!p)
|
if(!p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (((u32)p & 0x10000000) != 0) {
|
if (((u32)p & 0x10000000) != 0)
|
||||||
|
{
|
||||||
MEM2_free(p);
|
MEM2_free(p);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
__real_free(p);
|
__real_free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,4 +188,4 @@ size_t __wrap_malloc_usable_size(void *p)
|
|||||||
return __real_malloc_usable_size(p);
|
return __real_malloc_usable_size(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} ///extern "C"
|
||||||
|
@ -1,26 +1,24 @@
|
|||||||
// 2 MEM2 allocators, one for general purpose, one for covers
|
// 2 MEM2 allocators, one for general purpose, one for covers
|
||||||
// Aligned and padded to 32 bytes, as required by many functions
|
// Aligned and padded to 32 bytes, as required by many functions
|
||||||
|
|
||||||
#ifndef __MEM2_HPP
|
#ifndef __MEM2_H_
|
||||||
#define __MEM2_HPP
|
#define __MEM2_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
|
|
||||||
void MEM2_init(unsigned int mem2Size);
|
void MEM2_init(unsigned int mem2Size);
|
||||||
void MEM2_cleanup(void);
|
void MEM2_cleanup(void);
|
||||||
void MEM2_takeBigOnes(bool b);
|
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
|
||||||
|
|
||||||
#endif // !defined(__MEM2_HPP)
|
#endif // !defined(__MEM2_H_)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "mem2alloc.h"
|
#include "mem2alloc.hpp"
|
||||||
|
|
||||||
#include <ogc/system.h>
|
#include <ogc/system.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -16,10 +16,10 @@ public:
|
|||||||
|
|
||||||
void CMEM2Alloc::init(unsigned int size)
|
void CMEM2Alloc::init(unsigned int size)
|
||||||
{
|
{
|
||||||
m_baseAddress = (SBlock *)(((u32)SYS_GetArena2Lo() + 31) & ~31);
|
m_baseAddress = (SBlock *) (((u32)SYS_GetArena2Lo() + 31) & ~31);
|
||||||
m_endAddress = (SBlock *)((char *)m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
|
m_endAddress = (SBlock *) ((char *)m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
|
||||||
if (m_endAddress > (SBlock *)0x93000000) // See loader/disc.c
|
if (m_endAddress > (SBlock *) 0x93300000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes)
|
||||||
m_endAddress = (SBlock *)0x93000000;
|
m_endAddress = (SBlock *) 0x93300000;
|
||||||
SYS_SetArena2Lo(m_endAddress);
|
SYS_SetArena2Lo(m_endAddress);
|
||||||
LWP_MutexInit(&m_mutex, 0);
|
LWP_MutexInit(&m_mutex, 0);
|
||||||
}
|
}
|
||||||
@ -36,9 +36,9 @@ void CMEM2Alloc::cleanup(void)
|
|||||||
LWP_MutexDestroy(m_mutex);
|
LWP_MutexDestroy(m_mutex);
|
||||||
m_mutex = 0;
|
m_mutex = 0;
|
||||||
m_first = 0;
|
m_first = 0;
|
||||||
// // Try to release the range we took through SYS functions
|
// Try to release the range we took through SYS functions
|
||||||
// if (SYS_GetArena2Lo() == m_endAdress)
|
if (SYS_GetArena2Lo() == m_endAddress)
|
||||||
// SYS_SetArena2Lo(m_baseAddress);
|
SYS_SetArena2Lo(m_baseAddress);
|
||||||
m_baseAddress = 0;
|
m_baseAddress = 0;
|
||||||
m_endAddress = 0;
|
m_endAddress = 0;
|
||||||
}
|
}
|
||||||
@ -118,9 +118,16 @@ void CMEM2Alloc::release(void *p)
|
|||||||
{
|
{
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LockMutex lock(m_mutex);
|
LockMutex lock(m_mutex);
|
||||||
SBlock *i = (SBlock *)p - 1;
|
SBlock *i = (SBlock *)p - 1;
|
||||||
i->f = true;
|
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
|
// Merge with previous block
|
||||||
if (i->prev != 0 && i->prev->f)
|
if (i->prev != 0 && i->prev->f)
|
||||||
{
|
{
|
||||||
@ -150,12 +157,17 @@ void *CMEM2Alloc::reallocate(void *p, unsigned int s)
|
|||||||
s = 1;
|
s = 1;
|
||||||
if (p == 0)
|
if (p == 0)
|
||||||
return allocate(s);
|
return allocate(s);
|
||||||
|
|
||||||
i = (SBlock *)p - 1;
|
i = (SBlock *)p - 1;
|
||||||
s = (s - 1) / sizeof (SBlock) + 1;
|
s = (s - 1) / sizeof (SBlock) + 1;
|
||||||
{
|
{
|
||||||
LockMutex lock(m_mutex);
|
LockMutex lock(m_mutex);
|
||||||
|
|
||||||
|
//out of memory /* Dimok */
|
||||||
if (i + s + 1 >= m_endAddress)
|
if (i + s + 1 >= m_endAddress)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Last block
|
// Last block
|
||||||
if (i->next == 0 && i + s + 1 < m_endAddress)
|
if (i->next == 0 && i + s + 1 < m_endAddress)
|
||||||
@ -164,7 +176,7 @@ void *CMEM2Alloc::reallocate(void *p, unsigned int s)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
// Size <= current size + next block
|
// Size <= current size + next block
|
||||||
if (i->s < s && i->next->f && i->s + i->next->s + 1 >= s)
|
if (i->next != 0 && i->s < s && i->next->f && i->s + i->next->s + 1 >= s)
|
||||||
{
|
{
|
||||||
// Merge
|
// Merge
|
||||||
i->s += i->next->s + 1;
|
i->s += i->next->s + 1;
|
||||||
@ -199,3 +211,28 @@ void *CMEM2Alloc::reallocate(void *p, unsigned int s)
|
|||||||
release(p);
|
release(p);
|
||||||
return n;
|
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);
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ public:
|
|||||||
void forceEndAddress(void *newAddr) { m_endAddress = (SBlock *)newAddr; }
|
void forceEndAddress(void *newAddr) { m_endAddress = (SBlock *)newAddr; }
|
||||||
void *getEndAddress(void) const { return m_endAddress; }
|
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; }
|
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) { }
|
CMEM2Alloc(void) : m_baseAddress(0), m_endAddress(0), m_first(0), m_mutex(0) { }
|
||||||
private:
|
private:
|
@ -350,10 +350,8 @@ int MainMenu(int menu) {
|
|||||||
gettextCleanUp();
|
gettextCleanUp();
|
||||||
|
|
||||||
if(dbvideo)
|
if(dbvideo)
|
||||||
{
|
InitVideodebug ();
|
||||||
InitVideodebug ();
|
|
||||||
//printf("\n\n\n\n\n");
|
|
||||||
}
|
|
||||||
if (mountMethod==3)
|
if (mountMethod==3)
|
||||||
{
|
{
|
||||||
struct discHdr *header = &gameList[gameSelected];
|
struct discHdr *header = &gameList[gameSelected];
|
||||||
@ -372,13 +370,13 @@ int MainMenu(int menu) {
|
|||||||
WII_LaunchTitle(0x0000000100000100ULL);
|
WII_LaunchTitle(0x0000000100000100ULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (boothomebrew == 1) {
|
if (boothomebrew == 1) {
|
||||||
gprintf("\nBootHomebrew");
|
gprintf("\nBootHomebrew");
|
||||||
BootHomebrew(Settings.selected_homebrew);
|
BootHomebrew(Settings.selected_homebrew);
|
||||||
}
|
}
|
||||||
else if (boothomebrew == 2) {
|
else if (boothomebrew == 2) {
|
||||||
gprintf("\nBootHomebrewFromMenu");
|
gprintf("\nBootHomebrew from Menu");
|
||||||
BootHomebrewFromMem();
|
BootHomebrew();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gprintf("\n\tSettings.partition:%d",Settings.partition);
|
gprintf("\n\tSettings.partition:%d",Settings.partition);
|
||||||
|
@ -577,7 +577,7 @@ int MenuDiscList() {
|
|||||||
w.Append(&sdcardBtn);
|
w.Append(&sdcardBtn);
|
||||||
w.Append(&poweroffBtn);
|
w.Append(&poweroffBtn);
|
||||||
w.Append(&gameInfo);
|
w.Append(&gameInfo);
|
||||||
if (Settings.godmode && load_from_fs != PART_FS_NTFS)
|
if (Settings.godmode)
|
||||||
w.Append(&installBtn);
|
w.Append(&installBtn);
|
||||||
w.Append(&homeBtn);
|
w.Append(&homeBtn);
|
||||||
w.Append(&settingsBtn);
|
w.Append(&settingsBtn);
|
||||||
@ -800,18 +800,10 @@ int MenuDiscList() {
|
|||||||
gameCarousel->SetFocus(1);
|
gameCarousel->SetFocus(1);
|
||||||
}
|
}
|
||||||
} else if (installBtn.GetState() == STATE_CLICKED) {
|
} else if (installBtn.GetState() == STATE_CLICKED) {
|
||||||
gprintf("\n\tinstallBtn clicked");
|
choice = WindowPrompt(tr("Install a game"),0,tr("Yes"),tr("No"));
|
||||||
if (load_from_fs == PART_FS_NTFS)
|
|
||||||
{
|
|
||||||
choice = 0;
|
|
||||||
WindowPrompt(tr("Install not possible"), tr("You are using NTFS filesystem. Due to possible write errors to a NTFS partition, installing a game is not possible."), tr("OK"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
choice = WindowPrompt(tr("Install a game"),0,tr("Yes"),tr("No"));
|
|
||||||
if (choice == 1)
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
if (load_from_fs == PART_FS_NTFS)
|
menu = MENU_INSTALL;
|
||||||
menu = MENU_INSTALL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -825,7 +817,7 @@ int MenuDiscList() {
|
|||||||
gameCarousel->SetFocus(1);
|
gameCarousel->SetFocus(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((covert & 0x2)&&(covert!=covertOld) && load_from_fs != PART_FS_NTFS) {
|
} else if ((covert & 0x2)&&(covert!=covertOld)) {
|
||||||
gprintf("\n\tNew Disc Detected");
|
gprintf("\n\tNew Disc Detected");
|
||||||
choice = WindowPrompt(tr("New Disc Detected"),0,tr("Install"),tr("Mount DVD drive"),tr("Cancel"));
|
choice = WindowPrompt(tr("New Disc Detected"),0,tr("Install"),tr("Mount DVD drive"),tr("Cancel"));
|
||||||
if (choice == 1) {
|
if (choice == 1) {
|
||||||
|
@ -12,8 +12,10 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "fatmounter.h"
|
#include "fatmounter.h"
|
||||||
|
#include "gecko.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "wpad.h"
|
#include "wpad.h"
|
||||||
|
#include "lstub.h"
|
||||||
|
|
||||||
extern char game_partition[6];
|
extern char game_partition[6];
|
||||||
extern u8 load_from_fs;
|
extern u8 load_from_fs;
|
||||||
@ -197,7 +199,8 @@ void Sys_LoadMenu(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Sys_BackToLoader(void) {
|
void Sys_BackToLoader(void) {
|
||||||
if (*((u32*) 0x80001800)) {
|
|
||||||
|
if (hbcStubAvailable()) {
|
||||||
_ExitApp();
|
_ExitApp();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -264,6 +267,85 @@ s32 IOS_ReloadIOSsafe(int ios)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s32 CheckForCIOS()
|
||||||
|
{
|
||||||
|
gprintf("\n\tChecking for stub IOS");
|
||||||
|
s32 ret = 1;
|
||||||
|
ios222rev = getIOSrev(0x00000001000000dell);
|
||||||
|
ios249rev = getIOSrev(0x00000001000000f9ll);
|
||||||
|
|
||||||
|
//if we don't like either of the cIOS then scram
|
||||||
|
if (!((ios222rev >= 4 && ios222rev < 65280) || (ios249rev >=9 && ios249rev < 65280)))
|
||||||
|
{
|
||||||
|
printf("\x1b[2J");
|
||||||
|
if ((ios222rev < 0 && ios222rev != WII_EINSTALL) && (ios249rev < 0 && ios249rev != WII_EINSTALL)) {
|
||||||
|
printf("\n\n\n\tWARNING!");
|
||||||
|
printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+");
|
||||||
|
printf("\n\n\tWe cannot determine the versions on your system,\n\tsince you have no patched ios 36 or 236 installed.");
|
||||||
|
printf("\n\tTherefor, if loading of USB Loader GX fails, you\n\tprobably have installed the 4.2 update,");
|
||||||
|
printf("\n\tand you should go figure out how to get some cios action going on\n\tin your Wii.");
|
||||||
|
printf("\n\n\tThis message will show every time.");
|
||||||
|
sleep(5);
|
||||||
|
} else {
|
||||||
|
printf("\n\n\n\tERROR!");
|
||||||
|
printf("\n\tUSB Loader GX needs unstubbed cIOS 222 v4 or 249 v9+");
|
||||||
|
printf("\n\n\tI found \n\t\t222 = %d%s",ios222rev,ios222rev==65280?" (Stubbed by 4.2 update)":"");
|
||||||
|
printf("\n\t\t249 = %d%s",ios249rev,ios249rev==65280?" (Stubbed by 4.2 update)":"");
|
||||||
|
printf("\n\n\tGo figure out how to get some cIOS action going on\n\tin your Wii and come back and see me.");
|
||||||
|
|
||||||
|
sleep(15);
|
||||||
|
printf("\n\n\tBye");
|
||||||
|
|
||||||
|
USBDevice_deInit();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LoadAppCIOS()
|
||||||
|
{
|
||||||
|
s32 ret = 1;
|
||||||
|
/* Load Custom IOS */
|
||||||
|
SDCard_deInit();// unmount SD for reloading IOS
|
||||||
|
USBDevice_deInit();// unmount USB for reloading IOS
|
||||||
|
USBStorage2_Deinit();
|
||||||
|
|
||||||
|
if (Settings.cios == ios222 && IOS_GetVersion() != 222)
|
||||||
|
{
|
||||||
|
printf("\n\tReloading IOS to config setting (222)...");
|
||||||
|
ret = IOS_ReloadIOSsafe(222);
|
||||||
|
printf("%d", ret);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
Settings.cios = ios249;
|
||||||
|
IOS_ReloadIOSsafe(249);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Settings.cios == ios249 && IOS_GetVersion() != 249)
|
||||||
|
|| (Settings.cios == ios250 && IOS_GetVersion() != 250))
|
||||||
|
{
|
||||||
|
printf("\n\tReloading IOS to config setting (%d)...", (Settings.cios == ios249) ? 249 : 250);
|
||||||
|
ret = IOS_ReloadIOSsafe((Settings.cios == ios249) ? 249 : 250);
|
||||||
|
printf("%d", ret);
|
||||||
|
if (ret < 0) {
|
||||||
|
Settings.cios = ios222;
|
||||||
|
ret = IOS_ReloadIOSsafe(222);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDCard_Init();
|
||||||
|
if(IOS_GetVersion() == 222)
|
||||||
|
load_ehc_module();
|
||||||
|
|
||||||
|
USBDevice_Init();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
void ScreenShot()
|
void ScreenShot()
|
||||||
|
@ -16,7 +16,8 @@ int Sys_IosReload(int IOS);
|
|||||||
bool Sys_IsHermes();
|
bool Sys_IsHermes();
|
||||||
s32 IOS_ReloadIOSsafe(int ios);
|
s32 IOS_ReloadIOSsafe(int ios);
|
||||||
void ScreenShot();
|
void ScreenShot();
|
||||||
|
s32 CheckForCIOS();
|
||||||
|
int LoadAppCIOS();
|
||||||
void ShowMemInfo();
|
void ShowMemInfo();
|
||||||
extern s32 ios222rev;
|
extern s32 ios222rev;
|
||||||
extern s32 ios223rev;
|
extern s32 ios223rev;
|
||||||
|
@ -177,9 +177,6 @@ InitVideo () {
|
|||||||
xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
|
xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
|
||||||
xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
|
xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
|
||||||
|
|
||||||
// A console is always useful while debugging
|
|
||||||
console_init (xfb[0], 20, 64, vmode->fbWidth, vmode->xfbHeight, vmode->fbWidth * 2);
|
|
||||||
|
|
||||||
// Clear framebuffers etc.
|
// Clear framebuffers etc.
|
||||||
VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK);
|
VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK);
|
||||||
VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK);
|
VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK);
|
||||||
@ -197,6 +194,9 @@ InitVideo () {
|
|||||||
StartGX();
|
StartGX();
|
||||||
ResetVideo_Menu();
|
ResetVideo_Menu();
|
||||||
// Finally, the video is up and ready for use :)
|
// 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);
|
||||||
}
|
}
|
||||||
static unsigned int *xfbDB = NULL;
|
static unsigned int *xfbDB = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user