mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2024-11-30 15:14:18 +01:00
-back to a cache of 8, libntfs 2011.4.12 and the old
ntfs mount settings (new libntfs makes problems)
This commit is contained in:
parent
d714ded900
commit
70e3df6d5d
@ -1,7 +1,6 @@
|
||||
/**
|
||||
* ntfs.h - Simple functionality for startup, mounting and unmounting of NTFS-based devices.
|
||||
*
|
||||
* Copyright (c) 2010 Dimok
|
||||
* Copyright (c) 2009 Rhys "Shareese" Koedijk
|
||||
* Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
*
|
||||
|
Binary file not shown.
@ -1,31 +1,33 @@
|
||||
# Quick'n'dirty makefile [BC] v2
|
||||
|
||||
default: cube-release wii-release
|
||||
ifeq ($(strip $(DEVKITPPC)),)
|
||||
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
|
||||
endif
|
||||
|
||||
all: debug release
|
||||
include $(DEVKITPPC)/wii_rules
|
||||
|
||||
debug: cube-debug wii-debug
|
||||
LIBOGC_INC := $(DEVKITPRO)/libogc/include
|
||||
LIBOGC_LIB := $(DEVKITPRO)/libogc/lib/wii
|
||||
|
||||
release: cube-release wii-release
|
||||
CFLAGS := -O3 $(MACHDEP) -I$(LIBOGC_INC) -DHAVE_CONFIG_H
|
||||
|
||||
cube-debug:
|
||||
$(MAKE) -C source PLATFORM=cube BUILD=cube_debug
|
||||
SOURCES := source
|
||||
LIB := ntfs
|
||||
CFILES := $(wildcard $(SOURCES)/*.c)
|
||||
OFILES := $(CFILES:.c=.o)
|
||||
ARC := lib$(LIB).a
|
||||
HDR := ntfs.h
|
||||
|
||||
wii-debug:
|
||||
$(MAKE) -C source PLATFORM=wii BUILD=wii_debug
|
||||
all : $(OFILES)
|
||||
$(AR) -r $(ARC) $(OFILES)
|
||||
|
||||
cube-release:
|
||||
$(MAKE) -C source PLATFORM=cube BUILD=cube_release
|
||||
clean :
|
||||
rm -f $(OFILES) $(ARC)
|
||||
|
||||
wii-release:
|
||||
$(MAKE) -C source PLATFORM=wii BUILD=wii_release
|
||||
|
||||
clean:
|
||||
$(MAKE) -C source clean
|
||||
|
||||
install: cube-release wii-release
|
||||
$(MAKE) -C source install
|
||||
|
||||
run: install
|
||||
$(MAKE) -C example
|
||||
$(MAKE) -C example run
|
||||
install :
|
||||
cp -f $(ARC) ../../lib
|
||||
cp -f $(HDR) ../../include
|
||||
cp -f ntfsfile_frag.h ../../include
|
||||
|
||||
%.o : %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
@ -1,7 +1,6 @@
|
||||
/**
|
||||
* ntfs.h - Simple functionality for startup, mounting and unmounting of NTFS-based devices.
|
||||
*
|
||||
* Copyright (c) 2010 Dimok
|
||||
* Copyright (c) 2009 Rhys "Shareese" Koedijk
|
||||
* Copyright (c) 2006 Michael "Chishm" Chisholm
|
||||
*
|
||||
|
@ -522,7 +522,9 @@ gid_t ntfs_find_group(const struct MAPPING* groupmapping, const SID * gsid)
|
||||
{
|
||||
gid_t gid;
|
||||
const struct MAPPING *p;
|
||||
int gsidsz;
|
||||
|
||||
gsidsz = ntfs_sid_size(gsid);
|
||||
p = groupmapping;
|
||||
while (p && p->xid && !ntfs_same_sid(gsid, p->sid))
|
||||
p = p->next;
|
||||
@ -1899,6 +1901,7 @@ static int buildacls_posix(struct MAPPING* const mapping[],
|
||||
const SID *sid;
|
||||
int acecnt;
|
||||
int usidsz;
|
||||
int gsidsz;
|
||||
int wsidsz;
|
||||
int asidsz;
|
||||
int ssidsz;
|
||||
@ -1906,6 +1909,7 @@ static int buildacls_posix(struct MAPPING* const mapping[],
|
||||
le32 grants;
|
||||
|
||||
usidsz = ntfs_sid_size(usid);
|
||||
gsidsz = ntfs_sid_size(gsid);
|
||||
wsidsz = ntfs_sid_size(worldsid);
|
||||
asidsz = ntfs_sid_size(adminsid);
|
||||
ssidsz = ntfs_sid_size(systemsid);
|
||||
@ -3128,6 +3132,7 @@ static int norm_ownadmin_permissions_posix(struct POSIX_SECURITY *posix_desc,
|
||||
u16 tag;
|
||||
u16 tagsset;
|
||||
struct POSIX_ACE *pxace;
|
||||
int acccnt;
|
||||
mode_t denywrld;
|
||||
mode_t allow;
|
||||
mode_t deny;
|
||||
@ -3136,6 +3141,7 @@ static int norm_ownadmin_permissions_posix(struct POSIX_SECURITY *posix_desc,
|
||||
|
||||
mode = 0;
|
||||
pxace = posix_desc->acl.ace;
|
||||
acccnt = posix_desc->acccnt;
|
||||
tagsset = 0;
|
||||
denywrld = 0;
|
||||
/*
|
||||
@ -3875,10 +3881,12 @@ struct POSIX_SECURITY *ntfs_build_permissions_posix(
|
||||
int ntfs_build_permissions(const char *securattr,
|
||||
const SID *usid, const SID *gsid, BOOL isdir)
|
||||
{
|
||||
const SECURITY_DESCRIPTOR_RELATIVE *phead;
|
||||
int perm;
|
||||
BOOL adminowns;
|
||||
BOOL groupowns;
|
||||
|
||||
phead = (const SECURITY_DESCRIPTOR_RELATIVE*)securattr;
|
||||
adminowns = ntfs_same_sid(usid,adminsid)
|
||||
|| ntfs_same_sid(gsid,adminsid);
|
||||
groupowns = !adminowns && ntfs_same_sid(gsid,usid);
|
||||
@ -3961,6 +3969,7 @@ static struct MAPLIST *getmappingitem(FILEREADER reader, void *fileid,
|
||||
{
|
||||
int src;
|
||||
int dst;
|
||||
char *p;
|
||||
char *q;
|
||||
char *pu;
|
||||
char *pg;
|
||||
@ -3994,6 +4003,7 @@ static struct MAPLIST *getmappingitem(FILEREADER reader, void *fileid,
|
||||
if (gotend) {
|
||||
pu = pg = (char*)NULL;
|
||||
/* decompose into uid, gid and sid */
|
||||
p = item->maptext;
|
||||
item->uidstr = item->maptext;
|
||||
item->gidstr = strchr(item->uidstr, ':');
|
||||
if (item->gidstr) {
|
||||
|
@ -476,9 +476,8 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type,
|
||||
|
||||
cs = a->flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE);
|
||||
|
||||
/* a file may be sparse though its unnamed data is not (cf $UsnJrnl) */
|
||||
if (na->type == AT_DATA && na->name == AT_UNNAMED &&
|
||||
(((a->flags & ATTR_IS_SPARSE) && !NAttrSparse(na)) ||
|
||||
((!(a->flags & ATTR_IS_SPARSE) != !NAttrSparse(na)) ||
|
||||
(!(a->flags & ATTR_IS_ENCRYPTED) != !NAttrEncrypted(na)))) {
|
||||
errno = EIO;
|
||||
ntfs_log_perror("Inode %lld has corrupt attribute flags "
|
||||
@ -1775,6 +1774,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b)
|
||||
} need_to = { 0, 0 };
|
||||
BOOL wasnonresident = FALSE;
|
||||
BOOL compressed;
|
||||
BOOL sparse;
|
||||
BOOL updatemap;
|
||||
|
||||
ntfs_log_enter("Entering for inode %lld, attr 0x%x, pos 0x%llx, count "
|
||||
@ -1850,7 +1850,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b)
|
||||
goto errno_set;
|
||||
}
|
||||
#else
|
||||
if (ntfs_attr_truncate_i(na, pos + count, HOLES_OK)) {
|
||||
if (ntfs_attr_truncate(na, pos + count)) {
|
||||
ntfs_log_perror("Failed to enlarge attribute");
|
||||
goto errno_set;
|
||||
}
|
||||
@ -1860,6 +1860,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b)
|
||||
!= const_cpu_to_le16(0);
|
||||
need_to.undo_data_size = 1;
|
||||
}
|
||||
sparse = (na->data_flags & ATTR_IS_SPARSE) != const_cpu_to_le16(0);
|
||||
/*
|
||||
* For compressed data, a single full block was allocated
|
||||
* to deal with compression, possibly in a previous call.
|
||||
@ -2220,7 +2221,7 @@ done:
|
||||
updatemap = (compressed
|
||||
? NAttrFullyMapped(na) != 0 : update_from != -1);
|
||||
#endif
|
||||
if (updatemap) {
|
||||
if (updatemap)
|
||||
if (ntfs_attr_update_mapping_pairs(na,
|
||||
(update_from < 0 ? 0 : update_from))) {
|
||||
/*
|
||||
@ -2230,10 +2231,6 @@ done:
|
||||
total = -1;
|
||||
goto out;
|
||||
}
|
||||
if (!wasnonresident)
|
||||
NAttrClearBeingNonResident(na);
|
||||
NAttrClearDataAppending(na);
|
||||
}
|
||||
out:
|
||||
ntfs_log_leave("\n");
|
||||
return total;
|
||||
@ -2295,8 +2292,7 @@ err_out:
|
||||
if (updatemap)
|
||||
ntfs_attr_update_mapping_pairs(na, 0);
|
||||
/* Restore original data_size if needed. */
|
||||
if (need_to.undo_data_size
|
||||
&& ntfs_attr_truncate_i(na, old_data_size, HOLES_OK))
|
||||
if (need_to.undo_data_size && ntfs_attr_truncate(na, old_data_size))
|
||||
ntfs_log_perror("Failed to restore data_size");
|
||||
errno = eo;
|
||||
errno_set:
|
||||
@ -2314,6 +2310,7 @@ int ntfs_attr_pclose(ntfs_attr *na)
|
||||
ntfs_attr_search_ctx *ctx = NULL;
|
||||
runlist_element *rl;
|
||||
int eo;
|
||||
s64 hole;
|
||||
int compressed_part;
|
||||
BOOL compressed;
|
||||
|
||||
@ -2425,6 +2422,7 @@ int ntfs_attr_pclose(ntfs_attr *na)
|
||||
goto rl_err_out;
|
||||
}
|
||||
if (rl->lcn < (LCN)0) {
|
||||
hole = rl->vcn + rl->length;
|
||||
if (rl->lcn != (LCN)LCN_HOLE) {
|
||||
errno = EIO;
|
||||
ntfs_log_perror("%s: Unexpected LCN (%lld)",
|
||||
@ -2477,7 +2475,6 @@ retry:
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
NAttrClearComprClosing(na);
|
||||
ntfs_log_leave("\n");
|
||||
return (!ok);
|
||||
rl_err_out:
|
||||
@ -2534,7 +2531,6 @@ s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt,
|
||||
{
|
||||
s64 br;
|
||||
u8 *end;
|
||||
BOOL warn;
|
||||
|
||||
ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n",
|
||||
(unsigned long long)na->ni->mft_no, na->type,
|
||||
@ -2548,11 +2544,9 @@ s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt,
|
||||
if (br <= 0)
|
||||
return br;
|
||||
br /= bk_size;
|
||||
/* log errors unless silenced */
|
||||
warn = !na->ni || !na->ni->vol || !NVolNoFixupWarn(na->ni->vol);
|
||||
for (end = (u8*)dst + br * bk_size; (u8*)dst < end; dst = (u8*)dst +
|
||||
bk_size)
|
||||
ntfs_mst_post_read_fixup_warn((NTFS_RECORD*)dst, bk_size, warn);
|
||||
ntfs_mst_post_read_fixup((NTFS_RECORD*)dst, bk_size);
|
||||
/* Finally, return the number of blocks read. */
|
||||
return br;
|
||||
}
|
||||
@ -3551,14 +3545,6 @@ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type,
|
||||
min_size = sle64_to_cpu(ad->min_size);
|
||||
max_size = sle64_to_cpu(ad->max_size);
|
||||
|
||||
/* The $AttrDef generated by Windows specifies 2 as min_size for the
|
||||
* volume name attribute, but in reality Windows sets it to 0 when
|
||||
* clearing the volume name. If we want to be able to clear the volume
|
||||
* name we must also accept 0 as min_size, despite the $AttrDef
|
||||
* definition. */
|
||||
if(type == AT_VOLUME_NAME)
|
||||
min_size = 0;
|
||||
|
||||
if ((min_size && (size < min_size)) ||
|
||||
((max_size > 0) && (size > max_size))) {
|
||||
errno = ERANGE;
|
||||
@ -4310,7 +4296,7 @@ add_non_resident:
|
||||
goto rm_attr_err_out;
|
||||
}
|
||||
/* Resize and set attribute value. */
|
||||
if (ntfs_attr_truncate_i(na, size, HOLES_OK) ||
|
||||
if (ntfs_attr_truncate(na, size) ||
|
||||
(val && (ntfs_attr_pwrite(na, 0, size, val) != size))) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Failed to initialize just added attribute");
|
||||
@ -4891,7 +4877,6 @@ cluster_free_err_out:
|
||||
ntfs_log_trace("Eeek! Failed to release allocated clusters in error "
|
||||
"code path. Leaving inconsistent metadata...\n");
|
||||
NAttrClearNonResident(na);
|
||||
NAttrClearFullyMapped(na);
|
||||
na->allocated_size = na->data_size;
|
||||
na->rl = NULL;
|
||||
free(rl);
|
||||
@ -5015,7 +5000,7 @@ static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize,
|
||||
return (ret);
|
||||
}
|
||||
/* Resize non-resident attribute */
|
||||
return ntfs_attr_truncate_i(na, newsize, HOLES_OK);
|
||||
return ntfs_attr_truncate(na, newsize);
|
||||
} else if (errno != ENOSPC && errno != EPERM) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Failed to make attribute non-resident");
|
||||
@ -5363,6 +5348,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx)
|
||||
* record is in a transiently corrupted state at this moment in time.
|
||||
*/
|
||||
if (ntfs_cluster_free(vol, na, 0, -1) < 0) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Eeek! Failed to release allocated clusters");
|
||||
ntfs_log_trace("Ignoring error and leaving behind wasted "
|
||||
"clusters.\n");
|
||||
@ -5374,7 +5360,6 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx)
|
||||
|
||||
/* Update in-memory struct ntfs_attr. */
|
||||
NAttrClearNonResident(na);
|
||||
NAttrClearFullyMapped(na);
|
||||
NAttrClearSparse(na);
|
||||
NAttrClearEncrypted(na);
|
||||
na->initialized_size = na->data_size;
|
||||
@ -5468,7 +5453,6 @@ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m,
|
||||
|
||||
NAttrClearSparse(na);
|
||||
a->flags &= ~ATTR_IS_SPARSE;
|
||||
na->data_flags = a->flags;
|
||||
a->compression_unit = 0;
|
||||
|
||||
memmove((u8*)a + le16_to_cpu(a->name_offset) - 8,
|
||||
@ -6438,12 +6422,7 @@ out:
|
||||
|
||||
int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = ntfs_attr_truncate_i(na, newsize, HOLES_OK);
|
||||
NAttrClearDataAppending(na);
|
||||
NAttrClearBeingNonResident(na);
|
||||
return (r);
|
||||
return (ntfs_attr_truncate_i(na, newsize, HOLES_OK));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -376,6 +376,7 @@ int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
|
||||
int flags)
|
||||
{
|
||||
struct CACHED_GENERIC *current;
|
||||
struct CACHED_GENERIC *previous;
|
||||
struct CACHED_GENERIC *next;
|
||||
struct HASH_ENTRY *link;
|
||||
int count;
|
||||
@ -411,6 +412,7 @@ int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
|
||||
* Search sequentially in LRU list
|
||||
*/
|
||||
current = cache->most_recent_entry;
|
||||
previous = (struct CACHED_GENERIC*)NULL;
|
||||
while (current) {
|
||||
if (!compare(current, item)) {
|
||||
next = current->next;
|
||||
@ -421,6 +423,7 @@ int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
|
||||
current = next;
|
||||
count++;
|
||||
} else {
|
||||
previous = current;
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
|
@ -81,215 +81,259 @@ typedef enum {
|
||||
NTFS_SB_IS_COMPRESSED = 0x8000,
|
||||
} ntfs_compression_constants;
|
||||
|
||||
#define THRESHOLD 3 /* minimal match length for compression */
|
||||
#define NIL NTFS_SB_SIZE /* End of tree's node */
|
||||
|
||||
struct COMPRESS_CONTEXT {
|
||||
const unsigned char *inbuf;
|
||||
int bufsize;
|
||||
int size;
|
||||
int rel;
|
||||
int mxsz;
|
||||
s16 head[256];
|
||||
s16 lson[NTFS_SB_SIZE];
|
||||
s16 rson[NTFS_SB_SIZE];
|
||||
unsigned int len;
|
||||
unsigned int nbt;
|
||||
int match_position;
|
||||
unsigned int match_length;
|
||||
u16 lson[NTFS_SB_SIZE + 1];
|
||||
u16 rson[NTFS_SB_SIZE + 257];
|
||||
u16 dad[NTFS_SB_SIZE + 1];
|
||||
} ;
|
||||
|
||||
/*
|
||||
* Search for the longest sequence matching current position
|
||||
*
|
||||
* A binary tree is maintained to locate all previously met sequences,
|
||||
* and this function has to be called for all of them.
|
||||
*
|
||||
* This function is heavily used, it has to be optimized carefully
|
||||
*
|
||||
* Returns the size of the longest match,
|
||||
* zero if no match is found.
|
||||
* Initialize the match tree
|
||||
*/
|
||||
|
||||
static int ntfs_best_match(struct COMPRESS_CONTEXT *pctx, int i)
|
||||
static void ntfs_init_compress_tree(struct COMPRESS_CONTEXT *pctx)
|
||||
{
|
||||
s16 *prev;
|
||||
int node;
|
||||
register long j;
|
||||
long maxpos;
|
||||
long startj;
|
||||
long bestj;
|
||||
int bufsize;
|
||||
int bestnode;
|
||||
register const unsigned char *p1,*p2;
|
||||
int i;
|
||||
|
||||
p1 = pctx->inbuf;
|
||||
node = pctx->head[p1[i] & 255];
|
||||
if (node >= 0) {
|
||||
/* search the best match at current position */
|
||||
bestnode = node;
|
||||
bufsize = pctx->bufsize;
|
||||
/* restrict matches to the longest allowed sequence */
|
||||
maxpos = bufsize;
|
||||
if ((i + pctx->mxsz) < maxpos)
|
||||
maxpos = i + pctx->mxsz;
|
||||
startj = i + 1 - maxpos;
|
||||
bestj = startj;
|
||||
/* make indexes relative to end of allowed position */
|
||||
p1 = &p1[maxpos];
|
||||
if (startj < 0) {
|
||||
do {
|
||||
/* indexes are negative */
|
||||
p2 = &p1[node - i];
|
||||
/* no need to compare the first byte */
|
||||
j = startj;
|
||||
/* the second byte cannot lead to useful compression */
|
||||
if (p1[j] == p2[j]) {
|
||||
j++;
|
||||
if (j < 0) {
|
||||
do {
|
||||
} while ((p1[j] == p2[j])
|
||||
&& (++j < 0));
|
||||
}
|
||||
/* remember the match, if better */
|
||||
if (j > bestj) {
|
||||
bestj = j;
|
||||
bestnode = node;
|
||||
}
|
||||
}
|
||||
/* walk in the tree in the right direction */
|
||||
if ((j < 0) && (p1[j] < p2[j]))
|
||||
prev = &pctx->lson[node];
|
||||
else
|
||||
prev = &pctx->rson[node];
|
||||
node = *prev;
|
||||
/* stop if reaching a leaf or maximum length */
|
||||
} while ((node >= 0) && (j < 0));
|
||||
/* put the node into the tree if we reached a leaf */
|
||||
if (node < 0)
|
||||
*prev = i;
|
||||
}
|
||||
/* done, return the best match */
|
||||
pctx->size = bestj + maxpos - i;
|
||||
pctx->rel = bestnode - i;
|
||||
} else {
|
||||
pctx->head[p1[i] & 255] = i;
|
||||
pctx->size = 0;
|
||||
pctx->rel = 0;
|
||||
}
|
||||
return (pctx->size);
|
||||
for (i = NTFS_SB_SIZE + 1; i <= NTFS_SB_SIZE + 256; i++)
|
||||
pctx->rson[i] = NIL; /* root */
|
||||
for (i = 0; i < NTFS_SB_SIZE; i++)
|
||||
pctx->dad[i] = NIL; /* node */
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress a 4096-byte block
|
||||
*
|
||||
* Returns a header of two bytes followed by the compressed data.
|
||||
* If compression is not effective, the header and an uncompressed
|
||||
* block is returned.
|
||||
*
|
||||
* Note : two bytes may be output before output buffer overflow
|
||||
* is detected, so a 4100-bytes output buffer must be reserved.
|
||||
*
|
||||
* Returns the size of the compressed block, including the
|
||||
* header (minimal size is 2, maximum size is 4098)
|
||||
* 0 if an error has been met.
|
||||
* Insert a new node into match tree for quickly locating
|
||||
* further similar strings
|
||||
*/
|
||||
|
||||
static unsigned int ntfs_compress_block(const char *inbuf, int bufsize,
|
||||
char *outbuf)
|
||||
static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx,
|
||||
unsigned int r)
|
||||
{
|
||||
unsigned int pp;
|
||||
BOOL less;
|
||||
BOOL done;
|
||||
const unsigned char *key;
|
||||
int c;
|
||||
unsigned long mxi;
|
||||
unsigned int mxl;
|
||||
|
||||
mxl = (1 << (16 - pctx->nbt)) + 2;
|
||||
less = FALSE;
|
||||
done = FALSE;
|
||||
key = &pctx->inbuf[r];
|
||||
pp = NTFS_SB_SIZE + 1 + key[0];
|
||||
pctx->rson[r] = pctx->lson[r] = NIL;
|
||||
pctx->match_length = 0;
|
||||
do {
|
||||
if (!less) {
|
||||
if (pctx->rson[pp] != NIL)
|
||||
pp = pctx->rson[pp];
|
||||
else {
|
||||
pctx->rson[pp] = r;
|
||||
pctx->dad[r] = pp;
|
||||
done = TRUE;
|
||||
}
|
||||
} else {
|
||||
if (pctx->lson[pp] != NIL)
|
||||
pp = pctx->lson[pp];
|
||||
else {
|
||||
pctx->lson[pp] = r;
|
||||
pctx->dad[r] = pp;
|
||||
done = TRUE;
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
register unsigned long i;
|
||||
register const unsigned char *p1,*p2;
|
||||
|
||||
i = 1;
|
||||
mxi = NTFS_SB_SIZE - r;
|
||||
if (mxi < 2)
|
||||
less = FALSE;
|
||||
else {
|
||||
p1 = key;
|
||||
p2 = &pctx->inbuf[pp];
|
||||
/* this loop has a significant impact on performances */
|
||||
do {
|
||||
} while ((p1[i] == p2[i]) && (++i < mxi));
|
||||
less = (i < mxi) && (p1[i] < p2[i]);
|
||||
}
|
||||
if (i >= THRESHOLD) {
|
||||
if (i > pctx->match_length) {
|
||||
pctx->match_position =
|
||||
r - pp + 2*NTFS_SB_SIZE - 1;
|
||||
if ((pctx->match_length = i) > mxl) {
|
||||
i = pctx->rson[pp];
|
||||
pctx->rson[r] = i;
|
||||
pctx->dad[i] = r;
|
||||
i = pctx->lson[pp];
|
||||
pctx->lson[r] = i;
|
||||
pctx->dad[i] = r;
|
||||
i = pctx->dad[pp];
|
||||
pctx->dad[r] = i;
|
||||
if (pctx->rson[i] == pp)
|
||||
pctx->rson[i] = r;
|
||||
else
|
||||
pctx->lson[i] = r;
|
||||
/* remove pp */
|
||||
pctx->dad[pp] = NIL;
|
||||
done = TRUE;
|
||||
pctx->match_length = mxl;
|
||||
}
|
||||
} else
|
||||
if ((i == pctx->match_length)
|
||||
&& ((c = (r - pp + 2*NTFS_SB_SIZE - 1))
|
||||
< pctx->match_position))
|
||||
pctx->match_position = c;
|
||||
}
|
||||
}
|
||||
} while (!done);
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for the longest previous string matching the
|
||||
* current one
|
||||
*
|
||||
* Returns the end of the longest current string which matched
|
||||
* or zero if there was a bug
|
||||
*/
|
||||
|
||||
static unsigned int ntfs_nextmatch(struct COMPRESS_CONTEXT *pctx,
|
||||
unsigned int rr, int dd)
|
||||
{
|
||||
unsigned int bestlen = 0;
|
||||
|
||||
do {
|
||||
rr++;
|
||||
if (pctx->match_length > 0)
|
||||
pctx->match_length--;
|
||||
if (!pctx->len) {
|
||||
ntfs_log_error("compress bug : void run\n");
|
||||
goto bug;
|
||||
}
|
||||
if (--pctx->len) {
|
||||
if (rr >= NTFS_SB_SIZE) {
|
||||
ntfs_log_error("compress bug : buffer overflow\n");
|
||||
goto bug;
|
||||
}
|
||||
if (((rr + bestlen) < NTFS_SB_SIZE)) {
|
||||
while ((unsigned int)(1 << pctx->nbt)
|
||||
<= (rr - 1))
|
||||
pctx->nbt++;
|
||||
ntfs_new_node(pctx,rr);
|
||||
if (pctx->match_length > bestlen)
|
||||
bestlen = pctx->match_length;
|
||||
} else
|
||||
if (dd > 0) {
|
||||
rr += dd;
|
||||
if ((int)pctx->match_length > dd)
|
||||
pctx->match_length -= dd;
|
||||
else
|
||||
pctx->match_length = 0;
|
||||
if ((int)pctx->len < dd) {
|
||||
ntfs_log_error("compress bug : run overflows\n");
|
||||
goto bug;
|
||||
}
|
||||
pctx->len -= dd;
|
||||
dd = 0;
|
||||
}
|
||||
}
|
||||
} while (dd-- > 0);
|
||||
return (rr);
|
||||
bug :
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress an input block
|
||||
*
|
||||
* Returns the size of the compressed block (including header)
|
||||
* or zero if there was an error
|
||||
*/
|
||||
|
||||
static unsigned int ntfs_compress_block(const char *inbuf,
|
||||
unsigned int size, char *outbuf)
|
||||
{
|
||||
struct COMPRESS_CONTEXT *pctx;
|
||||
int i; /* current position */
|
||||
int j; /* end of best match from current position */
|
||||
int k; /* end of best match from next position */
|
||||
int offs; /* offset to best match */
|
||||
int n;
|
||||
int bp; /* bits to store offset */
|
||||
int mxoff; /* max match offset : 1 << bp */
|
||||
int mxsz2;
|
||||
char *ptag;
|
||||
int dd;
|
||||
unsigned int rr;
|
||||
unsigned int last_match_length;
|
||||
unsigned int q;
|
||||
unsigned int xout;
|
||||
unsigned int q; /* aggregated offset and size */
|
||||
int done;
|
||||
char *ptag; /* location reserved for a tag */
|
||||
int tag; /* current value of tag */
|
||||
int ntag; /* count of bits still undefined in tag */
|
||||
unsigned int ntag;
|
||||
|
||||
pctx = (struct COMPRESS_CONTEXT*)ntfs_malloc(sizeof(struct COMPRESS_CONTEXT));
|
||||
if (pctx) {
|
||||
for (n=0; n<NTFS_SB_SIZE; n++)
|
||||
pctx->lson[n] = pctx->rson[n] = -1;
|
||||
for (n=0; n<256; n++)
|
||||
pctx->head[n] = -1;
|
||||
pctx->inbuf = (const unsigned char*)inbuf;
|
||||
pctx->bufsize = bufsize;
|
||||
ntfs_init_compress_tree(pctx);
|
||||
xout = 2;
|
||||
n = 0;
|
||||
i = 0;
|
||||
bp = 4;
|
||||
mxoff = 1 << bp;
|
||||
pctx->mxsz = (1 << (16 - bp)) + 2;
|
||||
tag = 0;
|
||||
done = -1;
|
||||
ntag = 8;
|
||||
ntag = 0;
|
||||
ptag = &outbuf[xout++];
|
||||
while ((i < bufsize) && (xout < (NTFS_SB_SIZE + 2))) {
|
||||
/* adjust the longest match we can output */
|
||||
while (mxoff < i) {
|
||||
bp++;
|
||||
mxoff <<= 1;
|
||||
pctx->mxsz = (pctx->mxsz + 2) >> 1;
|
||||
}
|
||||
/* search the best match at current position */
|
||||
if (done < i)
|
||||
do {
|
||||
ntfs_best_match(pctx,++done);
|
||||
} while (done < i);
|
||||
j = i + pctx->size;
|
||||
if ((j - i) > pctx->mxsz)
|
||||
j = i + pctx->mxsz;
|
||||
|
||||
if ((j - i) > 2) {
|
||||
offs = pctx->rel;
|
||||
/* check whether there is a better run at i+1 */
|
||||
ntfs_best_match(pctx,i+1);
|
||||
done = i+1;
|
||||
k = i + 1 + pctx->size;
|
||||
mxsz2 = pctx->mxsz;
|
||||
if (mxoff <= i)
|
||||
mxsz2 = (pctx->mxsz + 2) >> 1;
|
||||
if ((k - i) > mxsz2)
|
||||
k = i + mxsz2;
|
||||
if (k > (j + 1)) {
|
||||
/* issue a single byte */
|
||||
outbuf[xout++] = inbuf[i];
|
||||
i++;
|
||||
} else {
|
||||
q = (~offs << (16 - bp))
|
||||
+ (j - i - 3);
|
||||
outbuf[xout++] = q & 255;
|
||||
outbuf[xout++] = (q >> 8) & 255;
|
||||
tag |= (1 << (8 - ntag));
|
||||
i = j;
|
||||
*ptag = 0;
|
||||
rr = 0;
|
||||
pctx->nbt = 4;
|
||||
pctx->len = size;
|
||||
pctx->match_length = 0;
|
||||
ntfs_new_node(pctx,0);
|
||||
do {
|
||||
if (pctx->match_length > pctx->len)
|
||||
pctx->match_length = pctx->len;
|
||||
if (pctx->match_length < THRESHOLD) {
|
||||
pctx->match_length = 1;
|
||||
if (ntag >= 8) {
|
||||
ntag = 0;
|
||||
ptag = &outbuf[xout++];
|
||||
*ptag = 0;
|
||||
}
|
||||
outbuf[xout++] = inbuf[rr];
|
||||
ntag++;
|
||||
} else {
|
||||
outbuf[xout++] = inbuf[i];
|
||||
i++;
|
||||
while ((unsigned int)(1 << pctx->nbt)
|
||||
<= (rr - 1))
|
||||
pctx->nbt++;
|
||||
q = (pctx->match_position << (16 - pctx->nbt))
|
||||
+ pctx->match_length - THRESHOLD;
|
||||
if (ntag >= 8) {
|
||||
ntag = 0;
|
||||
ptag = &outbuf[xout++];
|
||||
*ptag = 0;
|
||||
}
|
||||
*ptag |= 1 << ntag++;
|
||||
outbuf[xout++] = q & 255;
|
||||
outbuf[xout++] = (q >> 8) & 255;
|
||||
}
|
||||
/* store the tag if fully used */
|
||||
if (!--ntag) {
|
||||
*ptag = tag;
|
||||
ntag = 8;
|
||||
ptag = &outbuf[xout++];
|
||||
tag = 0;
|
||||
last_match_length = pctx->match_length;
|
||||
dd = last_match_length;
|
||||
if (dd-- > 0) {
|
||||
rr = ntfs_nextmatch(pctx,rr,dd);
|
||||
if (!rr)
|
||||
goto bug;
|
||||
}
|
||||
}
|
||||
/* store the last tag, if partially used */
|
||||
if (ntag == 8)
|
||||
xout--;
|
||||
else
|
||||
*ptag = tag;
|
||||
/* uncompressed must be full size, accept if better */
|
||||
if ((i >= bufsize) && (xout < (NTFS_SB_SIZE + 2))) {
|
||||
/*
|
||||
* stop if input is exhausted or output has exceeded
|
||||
* the maximum size. Two extra bytes have to be
|
||||
* reserved in output buffer, as 3 bytes may be
|
||||
* output in a loop.
|
||||
*/
|
||||
} while ((pctx->len > 0)
|
||||
&& (rr < size) && (xout < (NTFS_SB_SIZE + 2)));
|
||||
/* uncompressed must be full size, so accept if better */
|
||||
if (xout < (NTFS_SB_SIZE + 2)) {
|
||||
outbuf[0] = (xout - 3) & 255;
|
||||
outbuf[1] = 0xb0 + (((xout - 3) >> 8) & 15);
|
||||
} else {
|
||||
memcpy(&outbuf[2],inbuf,bufsize);
|
||||
if (bufsize < NTFS_SB_SIZE)
|
||||
memset(&outbuf[bufsize+2], 0,
|
||||
NTFS_SB_SIZE - bufsize);
|
||||
memcpy(&outbuf[2],inbuf,size);
|
||||
if (size < NTFS_SB_SIZE)
|
||||
memset(&outbuf[size+2],0,NTFS_SB_SIZE - size);
|
||||
outbuf[0] = 0xff;
|
||||
outbuf[1] = 0x3f;
|
||||
xout = NTFS_SB_SIZE + 2;
|
||||
@ -299,7 +343,9 @@ static unsigned int ntfs_compress_block(const char *inbuf, int bufsize,
|
||||
xout = 0;
|
||||
errno = ENOMEM;
|
||||
}
|
||||
return (xout);
|
||||
return (xout); /* 0 for an error, > size if cannot compress */
|
||||
bug :
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1466,12 +1512,12 @@ static int ntfs_read_append(ntfs_attr *na, const runlist_element *rl,
|
||||
* or -1 if there were an irrecoverable error (errno set)
|
||||
*/
|
||||
|
||||
static s32 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, s32 count, BOOL compress,
|
||||
BOOL appending, VCN *update_from)
|
||||
{
|
||||
s32 rounded;
|
||||
s32 written;
|
||||
int rounded;
|
||||
int written;
|
||||
int clsz;
|
||||
|
||||
if (compress) {
|
||||
@ -1609,7 +1655,7 @@ s64 ntfs_compressed_pwrite(ntfs_attr *na, runlist_element *wrl, s64 wpos,
|
||||
* (we are reopening an existing file to append to it)
|
||||
* Decompress the data and append
|
||||
*/
|
||||
compsz = (s32)compressed_part << vol->cluster_size_bits;
|
||||
compsz = compressed_part << vol->cluster_size_bits;
|
||||
outbuf = (char*)ntfs_malloc(na->compression_block_size);
|
||||
if (outbuf) {
|
||||
if (appending) {
|
||||
|
@ -226,9 +226,6 @@
|
||||
/* Define to 1 if you have the <sys/byteorder.h> header file. */
|
||||
#undef HAVE_SYS_BYTEORDER_H
|
||||
|
||||
/* Define to 1 if you have the <sys/disk.h> header file. */
|
||||
#undef HAVE_SYS_DISK_H
|
||||
|
||||
/* Define to 1 if you have the <sys/endian.h> header file. */
|
||||
#undef HAVE_SYS_ENDIAN_H
|
||||
|
||||
@ -312,13 +309,13 @@
|
||||
#define PACKAGE_NAME "ntfs-3g"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "ntfs-3g 2012.1.15"
|
||||
#define PACKAGE_STRING "ntfs-3g 2011.4.12"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "ntfs-3g"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "2012.1.15"
|
||||
#define PACKAGE_VERSION "2011.4.12"
|
||||
|
||||
/* POSIX ACL support */
|
||||
#undef POSIXACLS
|
||||
@ -348,7 +345,7 @@
|
||||
#endif
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "2012.1.15"
|
||||
#define VERSION "2011.4.12"
|
||||
|
||||
/* Define to 1 if this is a Windows OS */
|
||||
#undef WINDOWS
|
||||
@ -378,9 +375,6 @@
|
||||
/* Required define if using POSIX threads */
|
||||
#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
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
|
@ -38,10 +38,10 @@ static __inline__ void ntfs_debug_runlist_dump(const struct _runlist_element *rl
|
||||
|
||||
#define NTFS_BUG(msg) \
|
||||
{ \
|
||||
int ___i = 1; \
|
||||
int ___i; \
|
||||
ntfs_log_critical("Bug in %s(): %s\n", __FUNCTION__, msg); \
|
||||
ntfs_log_debug("Forcing segmentation fault!"); \
|
||||
___i = ((int*)NULL)[___i]; \
|
||||
___i = ((int*)NULL)[1]; \
|
||||
}
|
||||
|
||||
#endif /* defined _NTFS_DEBUG_H */
|
||||
|
@ -58,9 +58,6 @@
|
||||
#ifdef HAVE_SYS_MOUNT_H
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_DISK_H
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
#ifdef HAVE_LINUX_FD_H
|
||||
#include <linux/fd.h>
|
||||
#endif
|
||||
@ -559,36 +556,6 @@ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size)
|
||||
return (s64)this_floppy.size * 512 / block_size;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef DIOCGMEDIASIZE
|
||||
{
|
||||
/* FreeBSD */
|
||||
off_t size;
|
||||
|
||||
if (dev->d_ops->ioctl(dev, DIOCGMEDIASIZE, &size) >= 0) {
|
||||
ntfs_log_debug("DIOCGMEDIASIZE nr bytes = %llu (0x%llx)\n",
|
||||
(unsigned long long)size,
|
||||
(unsigned long long)size);
|
||||
return (s64)size / block_size;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef DKIOCGETBLOCKCOUNT
|
||||
{
|
||||
/* Mac OS X */
|
||||
uint64_t blocks;
|
||||
int sector_size;
|
||||
|
||||
sector_size = ntfs_device_sector_size_get(dev);
|
||||
if (sector_size >= 0 && dev->d_ops->ioctl(dev,
|
||||
DKIOCGETBLOCKCOUNT, &blocks) >= 0)
|
||||
{
|
||||
ntfs_log_debug("DKIOCGETBLOCKCOUNT nr blocks = %llu (0x%llx)\n",
|
||||
(unsigned long long) blocks,
|
||||
(unsigned long long) blocks);
|
||||
return blocks * sector_size / block_size;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* We couldn't figure it out by using a specialized ioctl,
|
||||
@ -738,28 +705,6 @@ int ntfs_device_sector_size_get(struct ntfs_device *dev)
|
||||
return sect_size;
|
||||
}
|
||||
}
|
||||
#elif defined(DIOCGSECTORSIZE)
|
||||
{
|
||||
/* FreeBSD */
|
||||
size_t sect_size = 0;
|
||||
|
||||
if (!dev->d_ops->ioctl(dev, DIOCGSECTORSIZE, §_size)) {
|
||||
ntfs_log_debug("DIOCGSECTORSIZE sector size = %d bytes\n",
|
||||
(int) sect_size);
|
||||
return sect_size;
|
||||
}
|
||||
}
|
||||
#elif defined(DKIOCGETBLOCKSIZE)
|
||||
{
|
||||
/* Mac OS X */
|
||||
uint32_t sect_size = 0;
|
||||
|
||||
if (!dev->d_ops->ioctl(dev, DKIOCGETBLOCKSIZE, §_size)) {
|
||||
ntfs_log_debug("DKIOCGETBLOCKSIZE sector size = %d bytes\n",
|
||||
(int) sect_size);
|
||||
return sect_size;
|
||||
}
|
||||
}
|
||||
#else
|
||||
errno = EOPNOTSUPP;
|
||||
#endif
|
||||
|
@ -257,7 +257,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
|
||||
u8 *index_end;
|
||||
ntfs_attr *ia_na;
|
||||
int eo, rc;
|
||||
u32 index_block_size;
|
||||
u32 index_block_size, index_vcn_size;
|
||||
u8 index_vcn_size_bits;
|
||||
|
||||
ntfs_log_trace("Entering\n");
|
||||
@ -378,9 +378,11 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
|
||||
|
||||
/* Determine the size of a vcn in the directory index. */
|
||||
if (vol->cluster_size <= index_block_size) {
|
||||
index_vcn_size = vol->cluster_size;
|
||||
index_vcn_size_bits = vol->cluster_size_bits;
|
||||
} else {
|
||||
index_vcn_size_bits = NTFS_BLOCK_SIZE_BITS;
|
||||
index_vcn_size = vol->sector_size;
|
||||
index_vcn_size_bits = vol->sector_size_bits;
|
||||
}
|
||||
|
||||
/* Get the starting vcn of the index_block holding the child node. */
|
||||
@ -1037,7 +1039,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
|
||||
INDEX_ENTRY *ie;
|
||||
INDEX_ALLOCATION *ia = NULL;
|
||||
int rc, ir_pos, bmp_buf_size, bmp_buf_pos, eo;
|
||||
u32 index_block_size;
|
||||
u32 index_block_size, index_vcn_size;
|
||||
u8 index_block_size_bits, index_vcn_size_bits;
|
||||
|
||||
ntfs_log_trace("Entering.\n");
|
||||
@ -1129,9 +1131,11 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
|
||||
}
|
||||
index_block_size_bits = ffs(index_block_size) - 1;
|
||||
if (vol->cluster_size <= index_block_size) {
|
||||
index_vcn_size = vol->cluster_size;
|
||||
index_vcn_size_bits = vol->cluster_size_bits;
|
||||
} else {
|
||||
index_vcn_size_bits = NTFS_BLOCK_SIZE_BITS;
|
||||
index_vcn_size = vol->sector_size;
|
||||
index_vcn_size_bits = vol->sector_size_bits;
|
||||
}
|
||||
|
||||
/* Are we jumping straight into the index allocation attribute? */
|
||||
@ -1513,7 +1517,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid,
|
||||
else
|
||||
ir->clusters_per_index_block =
|
||||
ni->vol->indx_record_size >>
|
||||
NTFS_BLOCK_SIZE_BITS;
|
||||
ni->vol->sector_size_bits;
|
||||
ir->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER));
|
||||
ir->index.index_length = cpu_to_le32(index_len);
|
||||
ir->index.allocated_size = cpu_to_le32(index_len);
|
||||
@ -2504,24 +2508,24 @@ int ntfs_set_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni,
|
||||
int res = 0;
|
||||
int longlen = 0;
|
||||
int shortlen = 0;
|
||||
char newname[3*MAX_DOS_NAME_LENGTH + 1];
|
||||
char newname[MAX_DOS_NAME_LENGTH + 1];
|
||||
ntfschar oldname[MAX_DOS_NAME_LENGTH];
|
||||
int oldlen;
|
||||
ntfs_volume *vol;
|
||||
u64 fnum;
|
||||
u64 dnum;
|
||||
BOOL closed = FALSE;
|
||||
ntfschar *shortname = NULL;
|
||||
ntfschar longname[NTFS_MAX_NAME_LEN];
|
||||
|
||||
/* copy the string to insert a null char, and truncate */
|
||||
if (size > 3*MAX_DOS_NAME_LENGTH)
|
||||
size = 3*MAX_DOS_NAME_LENGTH;
|
||||
vol = ni->vol;
|
||||
fnum = ni->mft_no;
|
||||
/* convert the string to the NTFS wide chars */
|
||||
if (size > MAX_DOS_NAME_LENGTH)
|
||||
size = MAX_DOS_NAME_LENGTH;
|
||||
strncpy(newname, value, size);
|
||||
/* a long name may be truncated badly and be untranslatable */
|
||||
newname[size] = 0;
|
||||
/* convert the string to the NTFS wide chars, and truncate */
|
||||
shortlen = ntfs_mbstoucs(newname, &shortname);
|
||||
if (shortlen > MAX_DOS_NAME_LENGTH)
|
||||
shortlen = MAX_DOS_NAME_LENGTH;
|
||||
/* make sure the short name has valid chars */
|
||||
if ((shortlen < 0) || ntfs_forbidden_chars(shortname,shortlen)) {
|
||||
ntfs_inode_close_in_dir(ni,dir_ni);
|
||||
|
@ -139,6 +139,7 @@ static int fixup_loop(ntfs_inode *ni)
|
||||
ntfs_attr *na;
|
||||
ATTR_RECORD *a;
|
||||
BOOL restart;
|
||||
BOOL first;
|
||||
int cnt;
|
||||
int maxcnt;
|
||||
int res = 0;
|
||||
@ -199,6 +200,7 @@ static int fixup_loop(ntfs_inode *ni)
|
||||
if (na)
|
||||
ntfs_attr_close(na);
|
||||
}
|
||||
first = FALSE;
|
||||
} while (restart && !res);
|
||||
if (ctx)
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
|
@ -701,7 +701,7 @@ int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *ic
|
||||
if (ni->vol->cluster_size <= icx->block_size)
|
||||
icx->vcn_size_bits = ni->vol->cluster_size_bits;
|
||||
else
|
||||
icx->vcn_size_bits = NTFS_BLOCK_SIZE_BITS;
|
||||
icx->vcn_size_bits = ni->vol->sector_size_bits;
|
||||
/* get the appropriate collation function */
|
||||
icx->collate = ntfs_get_collate_function(ir->collation_rule);
|
||||
if (!icx->collate) {
|
||||
|
@ -365,7 +365,7 @@ int ntfs_inode_real_close(ntfs_inode *ni)
|
||||
*/
|
||||
if (base_ni->nr_extents) {
|
||||
/* Resize the memory buffer. */
|
||||
tmp_nis = realloc(tmp_nis, base_ni->nr_extents *
|
||||
tmp_nis = MEM2_realloc(tmp_nis, base_ni->nr_extents *
|
||||
sizeof(ntfs_inode *));
|
||||
/* Ignore errors, they don't really matter. */
|
||||
if (tmp_nis)
|
||||
@ -437,12 +437,13 @@ static int idata_cache_compare(const struct CACHED_GENERIC *cached,
|
||||
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;
|
||||
ntfs_invalidate_cache(vol->nidata_cache,
|
||||
count = ntfs_invalidate_cache(vol->nidata_cache,
|
||||
GENERIC(&item),idata_cache_compare,CACHE_FREE);
|
||||
}
|
||||
|
||||
@ -573,9 +574,6 @@ int ntfs_inode_close(ntfs_inode *ni)
|
||||
ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref)
|
||||
{
|
||||
u64 mft_no = MREF_LE(mref);
|
||||
VCN extent_vcn;
|
||||
runlist_element *rl;
|
||||
ntfs_volume *vol;
|
||||
ntfs_inode *ni = NULL;
|
||||
ntfs_inode **extent_nis;
|
||||
int i;
|
||||
@ -590,37 +588,6 @@ ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref)
|
||||
(unsigned long long)mft_no,
|
||||
(unsigned long long)base_ni->mft_no);
|
||||
|
||||
if (!base_ni->mft_no) {
|
||||
/*
|
||||
* When getting extents of MFT, we must be sure
|
||||
* they are in the MFT part which has already
|
||||
* been mapped, otherwise we fall into an endless
|
||||
* recursion.
|
||||
* Situations have been met where extents locations
|
||||
* are described in themselves.
|
||||
* This is a severe error which chkdsk cannot fix.
|
||||
*/
|
||||
vol = base_ni->vol;
|
||||
extent_vcn = mft_no << vol->mft_record_size_bits
|
||||
>> vol->cluster_size_bits;
|
||||
rl = vol->mft_na->rl;
|
||||
if (rl) {
|
||||
while (rl->length
|
||||
&& ((rl->vcn + rl->length) <= extent_vcn))
|
||||
rl++;
|
||||
}
|
||||
if (!rl || (rl->lcn < 0)) {
|
||||
ntfs_log_error("MFT is corrupt, cannot read"
|
||||
" its unmapped extent record %lld\n",
|
||||
(long long)mft_no);
|
||||
ntfs_log_error("Note : chkdsk cannot fix this,"
|
||||
" try ntfsfix\n");
|
||||
errno = EIO;
|
||||
ni = (ntfs_inode*)NULL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Is the extent inode already open and attached to the base inode? */
|
||||
if (base_ni->nr_extents > 0) {
|
||||
extent_nis = base_ni->extent_nis;
|
||||
@ -1148,7 +1115,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni)
|
||||
ctx->attr->name_length + 7) & ~7;
|
||||
al_len += ale_size;
|
||||
|
||||
aln = realloc(al, al_len);
|
||||
aln = MEM2_realloc(al, al_len);
|
||||
if (!aln) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Failed to realloc %d bytes", al_len);
|
||||
|
@ -2223,11 +2223,11 @@ typedef struct {
|
||||
/* The below field is NOT present for the quota defaults entry. */
|
||||
SID sid; /* The SID of the user/object associated with
|
||||
this quota entry. If this field is missing
|
||||
then the INDEX_ENTRY is padded to a multiple
|
||||
of 8 with zeros which are not counted in
|
||||
then the INDEX_ENTRY is padded with zeros
|
||||
to multiply of 8 which are not counted in
|
||||
the data_length field. If the sid is present
|
||||
then this structure is padded with zeros to
|
||||
a multiple of 8 and the padding is counted in
|
||||
multiply of 8 and the padding is counted in
|
||||
the INDEX_ENTRY's data_length. */
|
||||
} __attribute__((__packed__)) QUOTA_CONTROL_ENTRY;
|
||||
|
||||
|
@ -468,7 +468,7 @@ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp)
|
||||
u8 *kaddr = NULL;
|
||||
RESTART_PAGE_HEADER *rstr1_ph = NULL;
|
||||
RESTART_PAGE_HEADER *rstr2_ph = NULL;
|
||||
int log_page_size, err;
|
||||
int log_page_size, log_page_mask, err;
|
||||
BOOL logfile_is_empty = TRUE;
|
||||
u8 log_page_bits;
|
||||
|
||||
@ -481,6 +481,7 @@ BOOL ntfs_check_logfile(ntfs_attr *log_na, RESTART_PAGE_HEADER **rp)
|
||||
if (size > (s64)MaxLogFileSize)
|
||||
size = MaxLogFileSize;
|
||||
log_page_size = DefaultLogPageSize;
|
||||
log_page_mask = log_page_size - 1;
|
||||
/*
|
||||
* Use generic_ffs() instead of ffs() to enable the compiler to
|
||||
* optimize log_page_size and log_page_bits into constants.
|
||||
|
@ -216,10 +216,8 @@ int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref,
|
||||
int ret = -1;
|
||||
|
||||
if (!ntfs_is_file_record(m->magic)) {
|
||||
if (!NVolNoFixupWarn(vol))
|
||||
ntfs_log_error("Record %llu has no FILE magic (0x%x)\n",
|
||||
(unsigned long long)MREF(mref),
|
||||
(int)le32_to_cpu(*(le32*)m));
|
||||
ntfs_log_error("Record %llu has no FILE magic (0x%x)\n",
|
||||
(unsigned long long)MREF(mref), *(le32 *)m);
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@ -1192,7 +1190,7 @@ undo_alloc:
|
||||
static int ntfs_mft_record_init(ntfs_volume *vol, s64 size)
|
||||
{
|
||||
int ret = -1;
|
||||
ntfs_attr *mft_na;
|
||||
ntfs_attr *mft_na, *mftbmp_na;
|
||||
s64 old_data_initialized, old_data_size;
|
||||
ntfs_attr_search_ctx *ctx;
|
||||
|
||||
@ -1201,6 +1199,7 @@ static int ntfs_mft_record_init(ntfs_volume *vol, s64 size)
|
||||
/* NOTE: Caller must sanity check vol, vol->mft_na and vol->mftbmp_na */
|
||||
|
||||
mft_na = vol->mft_na;
|
||||
mftbmp_na = vol->mftbmp_na;
|
||||
|
||||
/*
|
||||
* The mft record is outside the initialized data. Extend the mft data
|
||||
@ -1296,13 +1295,14 @@ undo_data_init:
|
||||
static int ntfs_mft_rec_init(ntfs_volume *vol, s64 size)
|
||||
{
|
||||
int ret = -1;
|
||||
ntfs_attr *mft_na;
|
||||
ntfs_attr *mft_na, *mftbmp_na;
|
||||
s64 old_data_initialized, old_data_size;
|
||||
ntfs_attr_search_ctx *ctx;
|
||||
|
||||
ntfs_log_enter("Entering\n");
|
||||
|
||||
mft_na = vol->mft_na;
|
||||
mftbmp_na = vol->mftbmp_na;
|
||||
|
||||
if (size > mft_na->allocated_size || size > mft_na->initialized_size) {
|
||||
errno = EIO;
|
||||
|
@ -47,8 +47,7 @@
|
||||
* EIO Multi sector transfer error was detected. Magic of the NTFS
|
||||
* record in @b will have been set to "BAAD".
|
||||
*/
|
||||
int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size,
|
||||
BOOL warn)
|
||||
int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size)
|
||||
{
|
||||
u16 usa_ofs, usa_count, usn;
|
||||
u16 *usa_pos, *data_pos;
|
||||
@ -64,14 +63,9 @@ int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size,
|
||||
(u32)(usa_ofs + (usa_count * 2)) > size ||
|
||||
(size >> NTFS_BLOCK_SIZE_BITS) != usa_count) {
|
||||
errno = EINVAL;
|
||||
if (warn) {
|
||||
ntfs_log_perror("%s: magic: 0x%08lx size: %ld "
|
||||
" usa_ofs: %d usa_count: %u",
|
||||
__FUNCTION__,
|
||||
(long)le32_to_cpu(*(le32 *)b),
|
||||
(long)size, (int)usa_ofs,
|
||||
(unsigned int)usa_count);
|
||||
}
|
||||
ntfs_log_perror("%s: magic: 0x%08x size: %d usa_ofs: %d "
|
||||
"usa_count: %d", __FUNCTION__, *(le32 *)b,
|
||||
size, usa_ofs, usa_count);
|
||||
return -1;
|
||||
}
|
||||
/* Position of usn in update sequence array. */
|
||||
@ -124,16 +118,6 @@ int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deprotect multi sector transfer protected data
|
||||
* with a warning if an error is found.
|
||||
*/
|
||||
|
||||
int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size)
|
||||
{
|
||||
return (ntfs_mst_post_read_fixup_warn(b,size,TRUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_mst_pre_write_fixup - apply multi sector transfer protection
|
||||
* @b: pointer to the data to protect
|
||||
|
@ -25,11 +25,8 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "layout.h"
|
||||
#include "volume.h"
|
||||
|
||||
extern int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size);
|
||||
extern int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size,
|
||||
BOOL warn);
|
||||
extern int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size);
|
||||
extern void ntfs_mst_post_write_fixup(NTFS_RECORD *b);
|
||||
|
||||
|
@ -36,18 +36,6 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifndef GEKKO
|
||||
/*
|
||||
* assume "struct timespec" is not defined if st_mtime is not defined
|
||||
*/
|
||||
#if !defined(st_mtime) & !defined(__timespec_defined)
|
||||
struct timespec {
|
||||
time_t tv_sec;
|
||||
long tv_nsec;
|
||||
} ;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* There are four times more conversions of internal representation
|
||||
* to ntfs representation than any other conversion, so the most
|
||||
|
@ -287,6 +287,7 @@ static int remove_object_id_index(ntfs_attr *na, ntfs_index_context *xo,
|
||||
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;
|
||||
@ -299,6 +300,7 @@ static int remove_object_id_index(ntfs_attr *na, ntfs_index_context *xo,
|
||||
memcpy(&old_attr->domain_id,
|
||||
&entry->data.domain_id,
|
||||
sizeof(GUID));
|
||||
size = sizeof(OBJECT_ID_ATTR);
|
||||
if (ntfs_index_rm(xo))
|
||||
ret = -1;
|
||||
}
|
||||
|
@ -50,19 +50,6 @@ enum {
|
||||
/* maximum cluster size for allowing compression for new files */
|
||||
#define MAX_COMPRESSION_CLUSTER_SIZE 4096
|
||||
|
||||
/*
|
||||
* Use of big write buffers
|
||||
*
|
||||
* With small volumes, the cluster allocator may fail to allocate
|
||||
* enough clusters when the volume is nearly full. At most a run
|
||||
* can be allocated per bitmap chunk. So, there is a danger when the
|
||||
* number of chunks (capacity/(32768*clsiz)) is less than the number
|
||||
* of clusters in the biggest write buffer (131072/clsiz). Hence
|
||||
* a safe minimal capacity is 4GB
|
||||
*/
|
||||
|
||||
#define SAFE_CAPACITY_FOR_BIG_WRITES 0x100000000LL
|
||||
|
||||
/*
|
||||
* Parameters for runlists
|
||||
*/
|
||||
@ -76,11 +63,6 @@ enum {
|
||||
|
||||
#define XATTRMAPPINGFILE ".NTFS-3G/XattrMapping" /* default mapping file */
|
||||
|
||||
/*
|
||||
* Parameters for path canonicalization
|
||||
*/
|
||||
|
||||
#define MAPPERNAMELTH 256
|
||||
|
||||
/*
|
||||
* Permission checking modes for high level and low level
|
||||
|
@ -136,10 +136,9 @@ runlist_element *ntfs_rl_extend(ntfs_attr *na, runlist_element *rl,
|
||||
if (!newrl) {
|
||||
errno = ENOMEM;
|
||||
rl = (runlist_element*)NULL;
|
||||
} else {
|
||||
} else
|
||||
na->rl = newrl;
|
||||
rl = &newrl[irl];
|
||||
}
|
||||
} else {
|
||||
ntfs_log_error("Cannot extend unmapped runlist");
|
||||
errno = EIO;
|
||||
@ -1624,7 +1623,7 @@ errno_set:
|
||||
int ntfs_rl_truncate(runlist **arl, const VCN start_vcn)
|
||||
{
|
||||
runlist *rl;
|
||||
/* BOOL is_end = FALSE; */
|
||||
BOOL is_end = FALSE;
|
||||
|
||||
if (!arl || !*arl) {
|
||||
errno = EINVAL;
|
||||
@ -1667,10 +1666,8 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn)
|
||||
*/
|
||||
if (rl->length) {
|
||||
++rl;
|
||||
/*
|
||||
if (!rl->length)
|
||||
is_end = TRUE;
|
||||
*/
|
||||
rl->vcn = start_vcn;
|
||||
rl->length = 0;
|
||||
}
|
||||
@ -1678,7 +1675,7 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn)
|
||||
/**
|
||||
* Reallocate memory if necessary.
|
||||
* FIXME: Below code is broken, because runlist allocations must be
|
||||
* a multiple of 4096. The code caused crashes and corruptions.
|
||||
* a multiply of 4096. The code caused crashes and corruptions.
|
||||
*/
|
||||
/*
|
||||
if (!is_end) {
|
||||
|
@ -1064,6 +1064,7 @@ static int upgrade_secur_desc(ntfs_volume *vol,
|
||||
na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION,
|
||||
AT_UNNAMED, 0);
|
||||
if (na) {
|
||||
res = 0;
|
||||
/* expand standard information attribute to v3.x */
|
||||
res = ntfs_attr_truncate(na,
|
||||
(s64)sizeof(STANDARD_INFORMATION));
|
||||
@ -1468,7 +1469,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
|
||||
if (pxdesc) {
|
||||
pxsize = sizeof(struct POSIX_SECURITY)
|
||||
+ (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||
pxcached = (struct POSIX_SECURITY*)malloc(pxsize);
|
||||
pxcached = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||
if (pxcached) {
|
||||
memcpy(pxcached, pxdesc, pxsize);
|
||||
cacheentry->pxdesc = pxcached;
|
||||
@ -1499,7 +1500,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
|
||||
/* allocate block, if cache table was allocated */
|
||||
if (pcache && (index1 <= pcache->head.last)) {
|
||||
cacheblock = (struct CACHED_PERMISSIONS*)
|
||||
malloc(sizeof(struct CACHED_PERMISSIONS)
|
||||
ntfs_malloc(sizeof(struct CACHED_PERMISSIONS)
|
||||
<< CACHE_PERMISSIONS_BITS);
|
||||
pcache->cachetable[index1] = cacheblock;
|
||||
for (i=0; i<(1 << CACHE_PERMISSIONS_BITS); i++)
|
||||
@ -1512,7 +1513,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
|
||||
if (pxdesc) {
|
||||
pxsize = sizeof(struct POSIX_SECURITY)
|
||||
+ (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||
pxcached = (struct POSIX_SECURITY*)malloc(pxsize);
|
||||
pxcached = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||
if (pxcached) {
|
||||
memcpy(pxcached, pxdesc, pxsize);
|
||||
cacheentry->pxdesc = pxcached;
|
||||
@ -2012,6 +2013,7 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
const SID *gsid; /* group of file/directory */
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
int perm;
|
||||
BOOL isdir;
|
||||
size_t outsize;
|
||||
|
||||
@ -2046,6 +2048,7 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
* fetch owner and group for cacheing
|
||||
*/
|
||||
if (pxdesc) {
|
||||
perm = pxdesc->mode & 07777;
|
||||
/*
|
||||
* Create a security id if there were none
|
||||
* and upgrade option is selected
|
||||
@ -2059,10 +2062,11 @@ int ntfs_get_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
#if OWNERFROMACL
|
||||
uid = ntfs_find_user(scx->mapping[MAPUSERS],usid);
|
||||
#else
|
||||
if (!(pxdesc->mode & 07777)
|
||||
&& ntfs_same_sid(usid, adminsid)) {
|
||||
if (!perm && ntfs_same_sid(usid, adminsid)) {
|
||||
uid = find_tenant(scx,
|
||||
securattr);
|
||||
if (uid)
|
||||
perm = 0700;
|
||||
} else
|
||||
uid = ntfs_find_user(scx->mapping[MAPUSERS],usid);
|
||||
#endif
|
||||
@ -2889,6 +2893,7 @@ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
uid_t uid;
|
||||
uid_t gid;
|
||||
int res;
|
||||
mode_t mode;
|
||||
BOOL isdir;
|
||||
BOOL deflt;
|
||||
BOOL exist;
|
||||
@ -2914,6 +2919,7 @@ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
gid = cached->gid;
|
||||
oldpxdesc = cached->pxdesc;
|
||||
if (oldpxdesc) {
|
||||
mode = oldpxdesc->mode;
|
||||
newpxdesc = ntfs_replace_acl(oldpxdesc,
|
||||
(const struct POSIX_ACL*)value,count,deflt);
|
||||
}
|
||||
@ -2940,6 +2946,7 @@ int ntfs_set_posix_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
|| (!exist && (flags & XATTR_REPLACE))) {
|
||||
errno = (exist ? EEXIST : ENODATA);
|
||||
} else {
|
||||
mode = oldpxdesc->mode;
|
||||
newpxdesc = ntfs_replace_acl(oldpxdesc,
|
||||
(const struct POSIX_ACL*)value,count,deflt);
|
||||
}
|
||||
@ -3085,7 +3092,7 @@ int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode)
|
||||
/* must copy before merging */
|
||||
pxsize = sizeof(struct POSIX_SECURITY)
|
||||
+ (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||
newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize);
|
||||
newpxdesc = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||
if (newpxdesc) {
|
||||
memcpy(newpxdesc, oldpxdesc, pxsize);
|
||||
if (ntfs_merge_mode_posix(newpxdesc, mode))
|
||||
@ -3506,16 +3513,16 @@ int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
uid_t uid, gid_t gid, const mode_t mode)
|
||||
{
|
||||
const SECURITY_DESCRIPTOR_RELATIVE *phead;
|
||||
const struct CACHED_PERMISSIONS *cached;
|
||||
char *oldattr;
|
||||
uid_t fileuid;
|
||||
uid_t filegid;
|
||||
int res;
|
||||
#if POSIXACLS
|
||||
const SECURITY_DESCRIPTOR_RELATIVE *phead;
|
||||
const SID *usid;
|
||||
const SID *gsid;
|
||||
uid_t fileuid;
|
||||
uid_t filegid;
|
||||
BOOL isdir;
|
||||
int res;
|
||||
#if POSIXACLS
|
||||
const struct POSIX_SECURITY *oldpxdesc;
|
||||
struct POSIX_SECURITY *newpxdesc = (struct POSIX_SECURITY*)NULL;
|
||||
int pxsize;
|
||||
@ -3534,7 +3541,7 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
/* must copy before merging */
|
||||
pxsize = sizeof(struct POSIX_SECURITY)
|
||||
+ (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||
newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize);
|
||||
newpxdesc = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||
if (newpxdesc) {
|
||||
memcpy(newpxdesc, oldpxdesc, pxsize);
|
||||
if (ntfs_merge_mode_posix(newpxdesc, mode))
|
||||
@ -3548,7 +3555,6 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
filegid = 0;
|
||||
oldattr = getsecurityattr(scx->vol, ni);
|
||||
if (oldattr) {
|
||||
#if POSIXACLS
|
||||
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|
||||
!= const_cpu_to_le16(0);
|
||||
phead = (const SECURITY_DESCRIPTOR_RELATIVE*)
|
||||
@ -3561,6 +3567,7 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
usid = (const SID*)
|
||||
&oldattr[le32_to_cpu(phead->owner)];
|
||||
#endif
|
||||
#if POSIXACLS
|
||||
newpxdesc = ntfs_build_permissions_posix(scx->mapping, oldattr,
|
||||
usid, gsid, isdir);
|
||||
if (!newpxdesc || ntfs_merge_mode_posix(newpxdesc, mode))
|
||||
@ -3819,9 +3826,9 @@ static int link_single_group(struct MAPPING *usermapping, struct passwd *user,
|
||||
grmem++;
|
||||
if (*grmem) {
|
||||
if (!grcnt)
|
||||
groups = (gid_t*)malloc(sizeof(gid_t));
|
||||
groups = (gid_t*)ntfs_malloc(sizeof(gid_t));
|
||||
else
|
||||
groups = (gid_t*)realloc(groups,
|
||||
groups = (gid_t*)MEM2_realloc(groups,
|
||||
(grcnt+1)*sizeof(gid_t));
|
||||
if (groups)
|
||||
groups[grcnt++] = gid;
|
||||
@ -4777,7 +4784,6 @@ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi,
|
||||
ni->flags = (ni->flags & ~settable)
|
||||
| (cpu_to_le32(attrib) & settable);
|
||||
NInoSetDirty(ni);
|
||||
NInoFileNameSetDirty(ni);
|
||||
}
|
||||
if (!ntfs_inode_close(ni))
|
||||
res = -1;
|
||||
|
@ -1262,7 +1262,7 @@ void ntfs_upcase_table_build(ntfschar *uc, u32 uc_len)
|
||||
|
||||
u32 ntfs_upcase_build_default(ntfschar **upcase)
|
||||
{
|
||||
u32 upcase_len = 0;
|
||||
u32 upcase_len;
|
||||
|
||||
*upcase = (ntfschar*)ntfs_malloc(UPCASE_LEN*2);
|
||||
if (*upcase) {
|
||||
@ -1406,18 +1406,16 @@ BOOL ntfs_collapsible_chars(ntfs_volume *vol,
|
||||
{
|
||||
BOOL collapsible;
|
||||
unsigned int ch;
|
||||
unsigned int cs;
|
||||
int i;
|
||||
|
||||
collapsible = shortlen == longlen;
|
||||
for (i=0; collapsible && (i<shortlen); i++) {
|
||||
ch = le16_to_cpu(longname[i]);
|
||||
cs = le16_to_cpu(shortname[i]);
|
||||
if ((cs != ch)
|
||||
&& ((ch >= vol->upcase_len)
|
||||
|| (cs >= vol->upcase_len)
|
||||
|| (vol->upcase[cs] != vol->upcase[ch])))
|
||||
collapsible = FALSE;
|
||||
if (collapsible)
|
||||
for (i=0; i<shortlen; i++) {
|
||||
ch = le16_to_cpu(longname[i]);
|
||||
if ((ch >= vol->upcase_len)
|
||||
|| ((shortname[i] != longname[i])
|
||||
&& (shortname[i] != vol->upcase[ch])))
|
||||
collapsible = FALSE;
|
||||
}
|
||||
return (collapsible);
|
||||
}
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#include "param.h"
|
||||
#include "compat.h"
|
||||
#include "volume.h"
|
||||
#include "attrib.h"
|
||||
@ -68,7 +67,6 @@
|
||||
#include "dir.h"
|
||||
#include "logging.h"
|
||||
#include "cache.h"
|
||||
#include "realpath.h"
|
||||
#include "misc.h"
|
||||
|
||||
const char *ntfs_home =
|
||||
@ -375,12 +373,6 @@ mft_has_no_attr_list:
|
||||
/* Done with the $Mft mft record. */
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
ctx = NULL;
|
||||
|
||||
/* Update the size fields in the inode. */
|
||||
vol->mft_ni->data_size = vol->mft_na->data_size;
|
||||
vol->mft_ni->allocated_size = vol->mft_na->allocated_size;
|
||||
set_nino_flag(vol->mft_ni, KnownSize);
|
||||
|
||||
/*
|
||||
* The volume is now setup so we can use all read access functions.
|
||||
*/
|
||||
@ -502,12 +494,6 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags)
|
||||
NVolSetShowSysFiles(vol);
|
||||
NVolSetShowHidFiles(vol);
|
||||
NVolClearHideDotFiles(vol);
|
||||
/* set default compression */
|
||||
#if DEFAULT_COMPRESSION
|
||||
NVolSetCompression(vol);
|
||||
#else
|
||||
NVolClearCompression(vol);
|
||||
#endif
|
||||
if (flags & MS_RDONLY)
|
||||
NVolSetReadOnly(vol);
|
||||
|
||||
@ -1373,6 +1359,18 @@ int ntfs_umount(ntfs_volume *vol, const BOOL force __attribute__((unused)))
|
||||
|
||||
#ifdef HAVE_MNTENT_H
|
||||
|
||||
#ifndef HAVE_REALPATH
|
||||
/**
|
||||
* realpath - If there is no realpath on the system
|
||||
*/
|
||||
static char *realpath(const char *path, char *resolved_path)
|
||||
{
|
||||
strncpy(resolved_path, path, PATH_MAX);
|
||||
resolved_path[PATH_MAX] = '\0';
|
||||
return resolved_path;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ntfs_mntent_check - desc
|
||||
*
|
||||
@ -1396,7 +1394,7 @@ static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags)
|
||||
err = errno;
|
||||
goto exit;
|
||||
}
|
||||
if (!ntfs_realpath_canonicalize(file, real_file)) {
|
||||
if (!realpath(file, real_file)) {
|
||||
err = errno;
|
||||
goto exit;
|
||||
}
|
||||
@ -1405,7 +1403,7 @@ static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags)
|
||||
goto exit;
|
||||
}
|
||||
while ((mnt = getmntent(f))) {
|
||||
if (!ntfs_realpath_canonicalize(mnt->mnt_fsname, real_fsname))
|
||||
if (!realpath(mnt->mnt_fsname, real_fsname))
|
||||
continue;
|
||||
if (!strcmp(real_file, real_fsname))
|
||||
break;
|
||||
@ -1732,113 +1730,3 @@ int ntfs_volume_get_free_space(ntfs_volume *vol)
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_volume_rename - change the current label on a volume
|
||||
* @vol: volume to change the label on
|
||||
* @label: the new label
|
||||
* @label_len: the length of @label in ntfschars including the terminating NULL
|
||||
* character, which is mandatory (the value can not exceed 128)
|
||||
*
|
||||
* Change the label on the volume @vol to @label.
|
||||
*/
|
||||
int ntfs_volume_rename(ntfs_volume *vol, ntfschar *label, int label_len)
|
||||
{
|
||||
ntfs_attr *na;
|
||||
char *old_vol_name;
|
||||
char *new_vol_name = NULL;
|
||||
int new_vol_name_len;
|
||||
int err;
|
||||
|
||||
if (NVolReadOnly(vol)) {
|
||||
ntfs_log_error("Refusing to change label on read-only mounted "
|
||||
"volume.\n");
|
||||
errno = EROFS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
label_len *= sizeof(ntfschar);
|
||||
if (label_len > 0x100) {
|
||||
ntfs_log_error("New label is too long. Maximum %u characters "
|
||||
"allowed.\n",
|
||||
(unsigned)(0x100 / sizeof(ntfschar)));
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
na = ntfs_attr_open(vol->vol_ni, AT_VOLUME_NAME, AT_UNNAMED, 0);
|
||||
if (!na) {
|
||||
if (errno != ENOENT) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Lookup of $VOLUME_NAME attribute "
|
||||
"failed");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
/* The volume name attribute does not exist. Need to add it. */
|
||||
if (ntfs_attr_add(vol->vol_ni, AT_VOLUME_NAME, AT_UNNAMED, 0,
|
||||
(u8*) label, label_len))
|
||||
{
|
||||
err = errno;
|
||||
ntfs_log_perror("Encountered error while adding "
|
||||
"$VOLUME_NAME attribute");
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
else {
|
||||
s64 written;
|
||||
|
||||
if (NAttrNonResident(na)) {
|
||||
err = errno;
|
||||
ntfs_log_error("Error: Attribute $VOLUME_NAME must be "
|
||||
"resident.\n");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (na->data_size != label_len) {
|
||||
if (ntfs_attr_truncate(na, label_len)) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Error resizing resident "
|
||||
"attribute");
|
||||
goto err_out;
|
||||
}
|
||||
}
|
||||
|
||||
if (label_len) {
|
||||
written = ntfs_attr_pwrite(na, 0, label_len, label);
|
||||
if (written == -1) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Error when writing "
|
||||
"$VOLUME_NAME data");
|
||||
goto err_out;
|
||||
}
|
||||
else if (written != label_len) {
|
||||
err = EIO;
|
||||
ntfs_log_error("Partial write when writing "
|
||||
"$VOLUME_NAME data.");
|
||||
goto err_out;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_vol_name_len =
|
||||
ntfs_ucstombs(label, label_len, &new_vol_name, 0);
|
||||
if (new_vol_name_len == -1) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Error while decoding new volume name");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
old_vol_name = vol->vol_name;
|
||||
vol->vol_name = new_vol_name;
|
||||
free(old_vol_name);
|
||||
|
||||
err = 0;
|
||||
err_out:
|
||||
if (na)
|
||||
ntfs_attr_close(na);
|
||||
if (err)
|
||||
errno = err;
|
||||
return err ? -1 : 0;
|
||||
}
|
||||
|
@ -113,7 +113,6 @@ typedef enum {
|
||||
NV_ShowHidFiles, /* 1: Show files marked hidden. */
|
||||
NV_HideDotFiles, /* 1: Set hidden flag on dot files */
|
||||
NV_Compression, /* 1: allow compression */
|
||||
NV_NoFixupWarn, /* 1: Do not log fixup errors */
|
||||
} ntfs_volume_state_bits;
|
||||
|
||||
#define test_nvol_flag(nv, flag) test_bit(NV_##flag, (nv)->state)
|
||||
@ -148,10 +147,6 @@ typedef enum {
|
||||
#define NVolSetCompression(nv) set_nvol_flag(nv, Compression)
|
||||
#define NVolClearCompression(nv) clear_nvol_flag(nv, Compression)
|
||||
|
||||
#define NVolNoFixupWarn(nv) test_nvol_flag(nv, NoFixupWarn)
|
||||
#define NVolSetNoFixupWarn(nv) set_nvol_flag(nv, NoFixupWarn)
|
||||
#define NVolClearNoFixupWarn(nv) clear_nvol_flag(nv, NoFixupWarn)
|
||||
|
||||
/*
|
||||
* NTFS version 1.1 and 1.2 are used by Windows NT4.
|
||||
* NTFS version 2.x is used by Windows 2000 Beta
|
||||
@ -302,7 +297,6 @@ extern int ntfs_volume_error(int err);
|
||||
extern void ntfs_mount_error(const char *vol, const char *mntpoint, int err);
|
||||
|
||||
extern int ntfs_volume_get_free_space(ntfs_volume *vol);
|
||||
extern int ntfs_volume_rename(ntfs_volume *vol, ntfschar *label, int label_len);
|
||||
|
||||
extern int ntfs_set_shown_files(ntfs_volume *vol,
|
||||
BOOL show_sys_files, BOOL show_hid_files, BOOL hide_dot_files);
|
||||
|
@ -42,7 +42,7 @@
|
||||
#define PARTITION_TYPE_WIN95_EXTENDED 0x0F /* Windows 95 extended partition */
|
||||
#define PARTITION_TYPE_GPT_TABLE 0xEE /* New Standard */
|
||||
|
||||
#define CACHE 32
|
||||
#define CACHE 8
|
||||
#define SECTORS 64
|
||||
|
||||
extern const DISC_INTERFACE __io_sdhc;
|
||||
@ -128,7 +128,7 @@ bool PartitionHandle::Mount(int pos, const char * name)
|
||||
}
|
||||
else if(strncmp(GetFSName(pos), "NTFS", 4) == 0)
|
||||
{
|
||||
if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SHOW_HIDDEN_FILES | NTFS_RECOVER))
|
||||
if(ntfsMount(MountNameList[pos].c_str(), interface, GetLBAStart(pos), CACHE, SECTORS, NTFS_SU | NTFS_RECOVER | NTFS_IGNORE_CASE))
|
||||
return true;
|
||||
}
|
||||
else if(strncmp(GetFSName(pos), "LINUX", 5) == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user