mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-16 00:15:08 +01:00
*Moved every allocation of libntfs now to MEM2 (in mem1 it gets overwritten and so the games didn't work in last rev)
Forwarder change: *Ignore MBR partition type and read partition type from boot record sector (Channel will follow later)
This commit is contained in:
parent
9bcb476262
commit
85eb0a7ed2
@ -1082,7 +1082,7 @@ struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc,
|
|||||||
else
|
else
|
||||||
newsize = sizeof(struct POSIX_SECURITY)
|
newsize = sizeof(struct POSIX_SECURITY)
|
||||||
+ (oldpxdesc->defcnt + count)*sizeof(struct POSIX_ACE);
|
+ (oldpxdesc->defcnt + count)*sizeof(struct POSIX_ACE);
|
||||||
newpxdesc = (struct POSIX_SECURITY*)malloc(newsize);
|
newpxdesc = (struct POSIX_SECURITY*)ntfs_malloc(newsize);
|
||||||
if (newpxdesc) {
|
if (newpxdesc) {
|
||||||
if (deflt) {
|
if (deflt) {
|
||||||
offset = oldpxdesc->acccnt;
|
offset = oldpxdesc->acccnt;
|
||||||
@ -1147,7 +1147,7 @@ struct POSIX_SECURITY *ntfs_build_inherited_posix(
|
|||||||
count = pxdesc->defcnt + 3;
|
count = pxdesc->defcnt + 3;
|
||||||
} else
|
} else
|
||||||
count = 3;
|
count = 3;
|
||||||
pydesc = (struct POSIX_SECURITY*)malloc(
|
pydesc = (struct POSIX_SECURITY*)ntfs_malloc(
|
||||||
sizeof(struct POSIX_SECURITY) + count*sizeof(struct POSIX_ACE));
|
sizeof(struct POSIX_SECURITY) + count*sizeof(struct POSIX_ACE));
|
||||||
if (pydesc) {
|
if (pydesc) {
|
||||||
/*
|
/*
|
||||||
@ -1330,7 +1330,7 @@ struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first
|
|||||||
size = sizeof(struct POSIX_SECURITY)
|
size = sizeof(struct POSIX_SECURITY)
|
||||||
+ (first->acccnt + first->defcnt
|
+ (first->acccnt + first->defcnt
|
||||||
+ second->acccnt + second->defcnt)*sizeof(struct POSIX_ACE);
|
+ second->acccnt + second->defcnt)*sizeof(struct POSIX_ACE);
|
||||||
pxdesc = (struct POSIX_SECURITY*)malloc(size);
|
pxdesc = (struct POSIX_SECURITY*)ntfs_malloc(size);
|
||||||
if (pxdesc) {
|
if (pxdesc) {
|
||||||
/*
|
/*
|
||||||
* merge access ACEs
|
* merge access ACEs
|
||||||
@ -3490,7 +3490,7 @@ struct POSIX_SECURITY *ntfs_build_permissions_posix(
|
|||||||
* and 2 more for other
|
* and 2 more for other
|
||||||
*/
|
*/
|
||||||
alloccnt = acecnt + 6;
|
alloccnt = acecnt + 6;
|
||||||
pxdesc = (struct POSIX_SECURITY*)malloc(
|
pxdesc = (struct POSIX_SECURITY*)ntfs_malloc(
|
||||||
sizeof(struct POSIX_SECURITY)
|
sizeof(struct POSIX_SECURITY)
|
||||||
+ alloccnt*sizeof(struct POSIX_ACE));
|
+ alloccnt*sizeof(struct POSIX_ACE));
|
||||||
k = 0;
|
k = 0;
|
||||||
|
@ -280,7 +280,7 @@ struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
|
|||||||
cache->oldest_entry = current->previous;
|
cache->oldest_entry = current->previous;
|
||||||
if (item->varsize) {
|
if (item->varsize) {
|
||||||
if (current->varsize)
|
if (current->varsize)
|
||||||
current->variable = realloc(
|
current->variable = MEM2_realloc(
|
||||||
current->variable,
|
current->variable,
|
||||||
item->varsize);
|
item->varsize);
|
||||||
else
|
else
|
||||||
|
@ -267,7 +267,7 @@ static unsigned int ntfs_compress_block(const char *inbuf,
|
|||||||
unsigned int xout;
|
unsigned int xout;
|
||||||
unsigned int ntag;
|
unsigned int ntag;
|
||||||
|
|
||||||
pctx = (struct COMPRESS_CONTEXT*)malloc(sizeof(struct COMPRESS_CONTEXT));
|
pctx = (struct COMPRESS_CONTEXT*)ntfs_malloc(sizeof(struct COMPRESS_CONTEXT));
|
||||||
if (pctx) {
|
if (pctx) {
|
||||||
pctx->inbuf = (const unsigned char*)inbuf;
|
pctx->inbuf = (const unsigned char*)inbuf;
|
||||||
ntfs_init_compress_tree(pctx);
|
ntfs_init_compress_tree(pctx);
|
||||||
|
@ -1257,7 +1257,7 @@ static int ntfs_ie_add_vcn(INDEX_ENTRY **ie)
|
|||||||
INDEX_ENTRY *p, *old = *ie;
|
INDEX_ENTRY *p, *old = *ie;
|
||||||
|
|
||||||
old->length = cpu_to_le16(le16_to_cpu(old->length) + sizeof(VCN));
|
old->length = cpu_to_le16(le16_to_cpu(old->length) + sizeof(VCN));
|
||||||
p = realloc(old, le16_to_cpu(old->length));
|
p = MEM2_realloc(old, le16_to_cpu(old->length));
|
||||||
if (!p)
|
if (!p)
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ int ntfs_inode_real_close(ntfs_inode *ni)
|
|||||||
*/
|
*/
|
||||||
if (base_ni->nr_extents) {
|
if (base_ni->nr_extents) {
|
||||||
/* Resize the memory buffer. */
|
/* 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 *));
|
sizeof(ntfs_inode *));
|
||||||
/* Ignore errors, they don't really matter. */
|
/* Ignore errors, they don't really matter. */
|
||||||
if (tmp_nis)
|
if (tmp_nis)
|
||||||
@ -1106,7 +1106,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni)
|
|||||||
ctx->attr->name_length + 7) & ~7;
|
ctx->attr->name_length + 7) & ~7;
|
||||||
al_len += ale_size;
|
al_len += ale_size;
|
||||||
|
|
||||||
aln = realloc(al, al_len);
|
aln = MEM2_realloc(al, al_len);
|
||||||
if (!aln) {
|
if (!aln) {
|
||||||
err = errno;
|
err = errno;
|
||||||
ntfs_log_perror("Failed to realloc %d bytes", al_len);
|
ntfs_log_perror("Failed to realloc %d bytes", al_len);
|
||||||
|
@ -356,7 +356,7 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
|||||||
/* Reallocate memory if necessary. */
|
/* Reallocate memory if necessary. */
|
||||||
if ((rlpos + 2) * (int)sizeof(runlist) >= rlsize) {
|
if ((rlpos + 2) * (int)sizeof(runlist) >= rlsize) {
|
||||||
rlsize += 4096;
|
rlsize += 4096;
|
||||||
trl = realloc(rl, rlsize);
|
trl = MEM2_realloc(rl, rlsize);
|
||||||
if (!trl) {
|
if (!trl) {
|
||||||
err = ENOMEM;
|
err = ENOMEM;
|
||||||
ntfs_log_perror("realloc() failed");
|
ntfs_log_perror("realloc() failed");
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
#include "mem2.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ntfs_calloc
|
* ntfs_calloc
|
||||||
@ -44,7 +45,10 @@ void *ntfs_calloc(size_t size)
|
|||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
p = calloc(1, size);
|
p = MEM2_alloc(size);
|
||||||
|
if(p)
|
||||||
|
memset(p, 0, size);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
ntfs_log_perror("Failed to calloc %lld bytes", (long long)size);
|
ntfs_log_perror("Failed to calloc %lld bytes", (long long)size);
|
||||||
return p;
|
return p;
|
||||||
@ -54,7 +58,7 @@ void *ntfs_malloc(size_t size)
|
|||||||
{
|
{
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
p = malloc(size);
|
p = MEM2_alloc(size);
|
||||||
if (!p)
|
if (!p)
|
||||||
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;
|
||||||
|
@ -101,6 +101,7 @@ static void ntfs_rl_mc(runlist_element *dstbase, int dst,
|
|||||||
* On success, return a pointer to the newly allocated, or recycled, memory.
|
* On success, return a pointer to the newly allocated, or recycled, memory.
|
||||||
* On error, return NULL with errno set to the error code.
|
* On error, return NULL with errno set to the error code.
|
||||||
*/
|
*/
|
||||||
|
#include "mem2.h"
|
||||||
static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size,
|
static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size,
|
||||||
int new_size)
|
int new_size)
|
||||||
{
|
{
|
||||||
@ -108,7 +109,7 @@ static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size,
|
|||||||
new_size = (new_size * sizeof(runlist_element) + 0xfff) & ~0xfff;
|
new_size = (new_size * sizeof(runlist_element) + 0xfff) & ~0xfff;
|
||||||
if (old_size == new_size)
|
if (old_size == new_size)
|
||||||
return rl;
|
return rl;
|
||||||
return realloc(rl, new_size);
|
return MEM2_realloc(rl, new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -835,7 +836,7 @@ static runlist_element *ntfs_mapping_pairs_decompress_i(const ntfs_volume *vol,
|
|||||||
runlist_element *rl2;
|
runlist_element *rl2;
|
||||||
|
|
||||||
rlsize += 0x1000;
|
rlsize += 0x1000;
|
||||||
rl2 = realloc(rl, rlsize);
|
rl2 = MEM2_realloc(rl, rlsize);
|
||||||
if (!rl2) {
|
if (!rl2) {
|
||||||
int eo = errno;
|
int eo = errno;
|
||||||
free(rl);
|
free(rl);
|
||||||
|
@ -1554,7 +1554,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
|
|||||||
if (pxdesc) {
|
if (pxdesc) {
|
||||||
pxsize = sizeof(struct POSIX_SECURITY)
|
pxsize = sizeof(struct POSIX_SECURITY)
|
||||||
+ (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
+ (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||||
pxcached = (struct POSIX_SECURITY*)malloc(pxsize);
|
pxcached = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||||
if (pxcached) {
|
if (pxcached) {
|
||||||
memcpy(pxcached, pxdesc, pxsize);
|
memcpy(pxcached, pxdesc, pxsize);
|
||||||
cacheentry->pxdesc = pxcached;
|
cacheentry->pxdesc = pxcached;
|
||||||
@ -1585,7 +1585,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
|
|||||||
/* allocate block, if cache table was allocated */
|
/* allocate block, if cache table was allocated */
|
||||||
if (pcache && (index1 <= pcache->head.last)) {
|
if (pcache && (index1 <= pcache->head.last)) {
|
||||||
cacheblock = (struct CACHED_PERMISSIONS*)
|
cacheblock = (struct CACHED_PERMISSIONS*)
|
||||||
malloc(sizeof(struct CACHED_PERMISSIONS)
|
ntfs_malloc(sizeof(struct CACHED_PERMISSIONS)
|
||||||
<< CACHE_PERMISSIONS_BITS);
|
<< CACHE_PERMISSIONS_BITS);
|
||||||
pcache->cachetable[index1] = cacheblock;
|
pcache->cachetable[index1] = cacheblock;
|
||||||
for (i=0; i<(1 << CACHE_PERMISSIONS_BITS); i++)
|
for (i=0; i<(1 << CACHE_PERMISSIONS_BITS); i++)
|
||||||
@ -1598,7 +1598,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
|
|||||||
if (pxdesc) {
|
if (pxdesc) {
|
||||||
pxsize = sizeof(struct POSIX_SECURITY)
|
pxsize = sizeof(struct POSIX_SECURITY)
|
||||||
+ (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
+ (pxdesc->acccnt + pxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||||
pxcached = (struct POSIX_SECURITY*)malloc(pxsize);
|
pxcached = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||||
if (pxcached) {
|
if (pxcached) {
|
||||||
memcpy(pxcached, pxdesc, pxsize);
|
memcpy(pxcached, pxdesc, pxsize);
|
||||||
cacheentry->pxdesc = pxcached;
|
cacheentry->pxdesc = pxcached;
|
||||||
@ -3177,7 +3177,7 @@ int ntfs_set_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, mode_t mode)
|
|||||||
/* must copy before merging */
|
/* must copy before merging */
|
||||||
pxsize = sizeof(struct POSIX_SECURITY)
|
pxsize = sizeof(struct POSIX_SECURITY)
|
||||||
+ (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
+ (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||||
newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize);
|
newpxdesc = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||||
if (newpxdesc) {
|
if (newpxdesc) {
|
||||||
memcpy(newpxdesc, oldpxdesc, pxsize);
|
memcpy(newpxdesc, oldpxdesc, pxsize);
|
||||||
if (ntfs_merge_mode_posix(newpxdesc, mode))
|
if (ntfs_merge_mode_posix(newpxdesc, mode))
|
||||||
@ -3626,7 +3626,7 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
|||||||
/* must copy before merging */
|
/* must copy before merging */
|
||||||
pxsize = sizeof(struct POSIX_SECURITY)
|
pxsize = sizeof(struct POSIX_SECURITY)
|
||||||
+ (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
+ (oldpxdesc->acccnt + oldpxdesc->defcnt)*sizeof(struct POSIX_ACE);
|
||||||
newpxdesc = (struct POSIX_SECURITY*)malloc(pxsize);
|
newpxdesc = (struct POSIX_SECURITY*)ntfs_malloc(pxsize);
|
||||||
if (newpxdesc) {
|
if (newpxdesc) {
|
||||||
memcpy(newpxdesc, oldpxdesc, pxsize);
|
memcpy(newpxdesc, oldpxdesc, pxsize);
|
||||||
if (ntfs_merge_mode_posix(newpxdesc, mode))
|
if (ntfs_merge_mode_posix(newpxdesc, mode))
|
||||||
@ -3891,7 +3891,7 @@ le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
|
|||||||
*
|
*
|
||||||
* Returns 0 if OK, -1 (and errno set) if error
|
* Returns 0 if OK, -1 (and errno set) if error
|
||||||
*/
|
*/
|
||||||
|
#include "mem2.h"
|
||||||
static int link_single_group(struct MAPPING *usermapping, struct passwd *user,
|
static int link_single_group(struct MAPPING *usermapping, struct passwd *user,
|
||||||
gid_t gid)
|
gid_t gid)
|
||||||
{
|
{
|
||||||
@ -3911,9 +3911,9 @@ static int link_single_group(struct MAPPING *usermapping, struct passwd *user,
|
|||||||
grmem++;
|
grmem++;
|
||||||
if (*grmem) {
|
if (*grmem) {
|
||||||
if (!grcnt)
|
if (!grcnt)
|
||||||
groups = (gid_t*)malloc(sizeof(gid_t));
|
groups = (gid_t*)ntfs_malloc(sizeof(gid_t));
|
||||||
else
|
else
|
||||||
groups = (gid_t*)realloc(groups,
|
groups = (gid_t*)MEM2_realloc(groups,
|
||||||
(grcnt+1)*sizeof(gid_t));
|
(grcnt+1)*sizeof(gid_t));
|
||||||
if (groups)
|
if (groups)
|
||||||
groups[grcnt++] = gid;
|
groups[grcnt++] = gid;
|
||||||
|
@ -1013,7 +1013,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs)
|
|||||||
if (o >= ucs_len) {
|
if (o >= ucs_len) {
|
||||||
ntfschar *tc;
|
ntfschar *tc;
|
||||||
ucs_len = (ucs_len * sizeof(ntfschar) + 64) & ~63;
|
ucs_len = (ucs_len * sizeof(ntfschar) + 64) & ~63;
|
||||||
tc = realloc(ucs, ucs_len);
|
tc = MEM2_realloc(ucs, ucs_len);
|
||||||
if (!tc)
|
if (!tc)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
ucs = tc;
|
ucs = tc;
|
||||||
|
Loading…
Reference in New Issue
Block a user