mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-12-18 16:01:58 +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
@ -880,7 +880,7 @@ BOOL ntfs_valid_posix(const struct POSIX_SECURITY *pxdesc)
|
||||
}
|
||||
}
|
||||
if ((pxdesc->acccnt > 0)
|
||||
&& ((checks[0].owners != 1) || (checks[0].groups != 1)
|
||||
&& ((checks[0].owners != 1) || (checks[0].groups != 1)
|
||||
|| (checks[0].others != 1)))
|
||||
ok = FALSE;
|
||||
/* do not check owner, group or other are present in */
|
||||
@ -1082,7 +1082,7 @@ struct POSIX_SECURITY *ntfs_replace_acl(const struct POSIX_SECURITY *oldpxdesc,
|
||||
else
|
||||
newsize = sizeof(struct POSIX_SECURITY)
|
||||
+ (oldpxdesc->defcnt + count)*sizeof(struct POSIX_ACE);
|
||||
newpxdesc = (struct POSIX_SECURITY*)malloc(newsize);
|
||||
newpxdesc = (struct POSIX_SECURITY*)ntfs_malloc(newsize);
|
||||
if (newpxdesc) {
|
||||
if (deflt) {
|
||||
offset = oldpxdesc->acccnt;
|
||||
@ -1147,7 +1147,7 @@ struct POSIX_SECURITY *ntfs_build_inherited_posix(
|
||||
count = pxdesc->defcnt + 3;
|
||||
} else
|
||||
count = 3;
|
||||
pydesc = (struct POSIX_SECURITY*)malloc(
|
||||
pydesc = (struct POSIX_SECURITY*)ntfs_malloc(
|
||||
sizeof(struct POSIX_SECURITY) + count*sizeof(struct POSIX_ACE));
|
||||
if (pydesc) {
|
||||
/*
|
||||
@ -1330,7 +1330,7 @@ struct POSIX_SECURITY *ntfs_merge_descr_posix(const struct POSIX_SECURITY *first
|
||||
size = sizeof(struct POSIX_SECURITY)
|
||||
+ (first->acccnt + first->defcnt
|
||||
+ second->acccnt + second->defcnt)*sizeof(struct POSIX_ACE);
|
||||
pxdesc = (struct POSIX_SECURITY*)malloc(size);
|
||||
pxdesc = (struct POSIX_SECURITY*)ntfs_malloc(size);
|
||||
if (pxdesc) {
|
||||
/*
|
||||
* merge access ACEs
|
||||
@ -1806,7 +1806,7 @@ static BOOL build_group_denials_grant(ACL *pacl,
|
||||
* - grants to owner (always present - first grant)
|
||||
* + grants to designated user
|
||||
* + mask denial to group (unless mask allows all)
|
||||
* - denials to group (preventing grants to world to apply)
|
||||
* - denials to group (preventing grants to world to apply)
|
||||
* - grants to group (unless group has no more than world rights)
|
||||
* + mask denials to designated group (unless mask allows all)
|
||||
* + grants to designated group
|
||||
@ -3490,7 +3490,7 @@ struct POSIX_SECURITY *ntfs_build_permissions_posix(
|
||||
* and 2 more for other
|
||||
*/
|
||||
alloccnt = acecnt + 6;
|
||||
pxdesc = (struct POSIX_SECURITY*)malloc(
|
||||
pxdesc = (struct POSIX_SECURITY*)ntfs_malloc(
|
||||
sizeof(struct POSIX_SECURITY)
|
||||
+ alloccnt*sizeof(struct POSIX_ACE));
|
||||
k = 0;
|
||||
|
@ -280,7 +280,7 @@ struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
|
||||
cache->oldest_entry = current->previous;
|
||||
if (item->varsize) {
|
||||
if (current->varsize)
|
||||
current->variable = realloc(
|
||||
current->variable = MEM2_realloc(
|
||||
current->variable,
|
||||
item->varsize);
|
||||
else
|
||||
|
@ -28,7 +28,7 @@
|
||||
* this was put into public domain in 1988 by Haruhiko OKUMURA).
|
||||
*
|
||||
* LZHUF.C English version 1.0
|
||||
* Based on Japanese version 29-NOV-1988
|
||||
* Based on Japanese version 29-NOV-1988
|
||||
* LZSS coded by Haruhiko OKUMURA
|
||||
* Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI
|
||||
* Edited and translated to English by Kenji RIKITAKE
|
||||
@ -164,7 +164,7 @@ static void ntfs_new_node (struct COMPRESS_CONTEXT *pctx,
|
||||
}
|
||||
if (i >= THRESHOLD) {
|
||||
if (i > pctx->match_length) {
|
||||
pctx->match_position =
|
||||
pctx->match_position =
|
||||
r - pp + 2*NTFS_SB_SIZE - 1;
|
||||
if ((pctx->match_length = i) > mxl) {
|
||||
i = pctx->rson[pp];
|
||||
@ -267,7 +267,7 @@ static unsigned int ntfs_compress_block(const char *inbuf,
|
||||
unsigned int xout;
|
||||
unsigned int ntag;
|
||||
|
||||
pctx = (struct COMPRESS_CONTEXT*)malloc(sizeof(struct COMPRESS_CONTEXT));
|
||||
pctx = (struct COMPRESS_CONTEXT*)ntfs_malloc(sizeof(struct COMPRESS_CONTEXT));
|
||||
if (pctx) {
|
||||
pctx->inbuf = (const unsigned char*)inbuf;
|
||||
ntfs_init_compress_tree(pctx);
|
||||
@ -543,7 +543,7 @@ return_overflow:
|
||||
* code. Might be a bit confusing to debug but there really should never be
|
||||
* errors coming from here.
|
||||
*/
|
||||
static BOOL ntfs_is_cb_compressed(ntfs_attr *na, runlist_element *rl,
|
||||
static BOOL ntfs_is_cb_compressed(ntfs_attr *na, runlist_element *rl,
|
||||
VCN cb_start_vcn, int cb_clusters)
|
||||
{
|
||||
/*
|
||||
@ -663,12 +663,12 @@ s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b)
|
||||
cb_size = na->compression_block_size;
|
||||
cb_size_mask = cb_size - 1UL;
|
||||
cb_clusters = na->compression_block_clusters;
|
||||
|
||||
|
||||
/* Need a temporary buffer for each loaded compression block. */
|
||||
cb = (u8*)ntfs_malloc(cb_size);
|
||||
if (!cb)
|
||||
return -1;
|
||||
|
||||
|
||||
/* Need a temporary buffer for each uncompressed block. */
|
||||
dest = (u8*)ntfs_malloc(cb_size);
|
||||
if (!dest) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -124,7 +124,7 @@ ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol)
|
||||
static void __ntfs_inode_release(ntfs_inode *ni)
|
||||
{
|
||||
if (NInoDirty(ni))
|
||||
ntfs_log_error("Releasing dirty inode %lld!\n",
|
||||
ntfs_log_error("Releasing dirty inode %lld!\n",
|
||||
(long long)ni->mft_no);
|
||||
if (NInoAttrList(ni) && ni->attr_list)
|
||||
free(ni->attr_list);
|
||||
@ -243,7 +243,7 @@ static ntfs_inode *ntfs_inode_real_open(ntfs_volume *vol, const MFT_REF mref)
|
||||
if (l != ni->attr_list_size) {
|
||||
errno = EIO;
|
||||
ntfs_log_perror("Unexpected attrlist size (%lld <> %u), inode "
|
||||
"%lld", (long long)l, ni->attr_list_size,
|
||||
"%lld", (long long)l, ni->attr_list_size,
|
||||
(long long)MREF(mref));
|
||||
goto put_err_out;
|
||||
}
|
||||
@ -273,7 +273,7 @@ get_size:
|
||||
set_nino_flag(ni,KnownSize);
|
||||
}
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
out:
|
||||
out:
|
||||
ntfs_log_leave("\n");
|
||||
return ni;
|
||||
|
||||
@ -313,7 +313,7 @@ err_out:
|
||||
int ntfs_inode_real_close(ntfs_inode *ni)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
|
||||
if (!ni)
|
||||
return 0;
|
||||
|
||||
@ -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)
|
||||
@ -378,8 +378,8 @@ int ntfs_inode_real_close(ntfs_inode *ni)
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* We could successfully sync, so only log this error
|
||||
* and try to sync other inode extents too.
|
||||
*/
|
||||
@ -387,7 +387,7 @@ int ntfs_inode_real_close(ntfs_inode *ni)
|
||||
ntfs_log_error("Extent inode %lld was not found\n",
|
||||
(long long)ni->mft_no);
|
||||
}
|
||||
|
||||
|
||||
__ntfs_inode_release(ni);
|
||||
ret = 0;
|
||||
err:
|
||||
@ -580,11 +580,11 @@ ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref)
|
||||
ntfs_log_perror("%s", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
ntfs_log_enter("Opening extent inode %lld (base mft record %lld).\n",
|
||||
(unsigned long long)mft_no,
|
||||
(unsigned long long)base_ni->mft_no);
|
||||
|
||||
|
||||
/* Is the extent inode already open and attached to the base inode? */
|
||||
if (base_ni->nr_extents > 0) {
|
||||
extent_nis = base_ni->extent_nis;
|
||||
@ -797,7 +797,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni)
|
||||
if (dir_ni)
|
||||
index_ni = dir_ni;
|
||||
else
|
||||
index_ni = ntfs_inode_open(ni->vol,
|
||||
index_ni = ntfs_inode_open(ni->vol,
|
||||
le64_to_cpu(fn->parent_directory));
|
||||
if (!index_ni) {
|
||||
if (!err)
|
||||
@ -954,8 +954,8 @@ static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni)
|
||||
}
|
||||
NInoAttrListSetDirty(ni);
|
||||
goto sync_inode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (na->data_size == ni->attr_list_size) {
|
||||
if (ntfs_attr_pwrite(na, 0, ni->attr_list_size,
|
||||
ni->attr_list) != ni->attr_list_size) {
|
||||
@ -977,7 +977,7 @@ static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni)
|
||||
}
|
||||
ntfs_attr_close(na);
|
||||
}
|
||||
|
||||
|
||||
sync_inode:
|
||||
/* Write this inode out to the $MFT (and $MFTMirr if applicable). */
|
||||
if (NInoTestAndClearDirty(ni)) {
|
||||
@ -1003,8 +1003,8 @@ sync_inode:
|
||||
eni = ni->extent_nis[i];
|
||||
if (!NInoTestAndClearDirty(eni))
|
||||
continue;
|
||||
|
||||
if (ntfs_mft_record_write(eni->vol, eni->mft_no,
|
||||
|
||||
if (ntfs_mft_record_write(eni->vol, eni->mft_no,
|
||||
eni->mrec)) {
|
||||
if (!err || errno == EIO) {
|
||||
err = errno;
|
||||
@ -1024,7 +1024,7 @@ sync_inode:
|
||||
errno = err;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
|
||||
ntfs_log_leave("\n");
|
||||
return ret;
|
||||
}
|
||||
@ -1093,20 +1093,20 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni)
|
||||
}
|
||||
/* Walk through all attributes. */
|
||||
while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, 0, 0, NULL, 0, ctx)) {
|
||||
|
||||
|
||||
int ale_size;
|
||||
|
||||
|
||||
if (ctx->attr->type == AT_ATTRIBUTE_LIST) {
|
||||
err = EIO;
|
||||
ntfs_log_perror("Attribute list already present");
|
||||
goto put_err_out;
|
||||
}
|
||||
|
||||
|
||||
ale_size = (sizeof(ATTR_LIST_ENTRY) + sizeof(ntfschar) *
|
||||
ctx->attr->name_length + 7) & ~7;
|
||||
al_len += ale_size;
|
||||
|
||||
aln = realloc(al, al_len);
|
||||
|
||||
aln = MEM2_realloc(al, al_len);
|
||||
if (!aln) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Failed to realloc %d bytes", al_len);
|
||||
@ -1114,9 +1114,9 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni)
|
||||
}
|
||||
ale = (ATTR_LIST_ENTRY *)(aln + ((u8 *)ale - al));
|
||||
al = aln;
|
||||
|
||||
|
||||
memset(ale, 0, ale_size);
|
||||
|
||||
|
||||
/* Add attribute to attribute list. */
|
||||
ale->type = ctx->attr->type;
|
||||
ale->length = cpu_to_le16((sizeof(ATTR_LIST_ENTRY) +
|
||||
@ -1183,7 +1183,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni)
|
||||
ntfs_attr_close(na);
|
||||
goto remove_attrlist_record;;
|
||||
}
|
||||
|
||||
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
ntfs_attr_close(na);
|
||||
return 0;
|
||||
@ -1284,12 +1284,12 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size)
|
||||
* find next, because we don't need such.
|
||||
*/
|
||||
while (ctx->ntfs_ino->mft_no != ni->mft_no) {
|
||||
retry:
|
||||
retry:
|
||||
if (ntfs_attr_position(AT_UNUSED, ctx))
|
||||
goto put_err_out;
|
||||
}
|
||||
|
||||
if (ntfs_inode_base(ctx->ntfs_ino)->mft_no == FILE_MFT &&
|
||||
if (ntfs_inode_base(ctx->ntfs_ino)->mft_no == FILE_MFT &&
|
||||
ctx->attr->type == AT_DATA)
|
||||
goto retry;
|
||||
|
||||
@ -1310,10 +1310,10 @@ retry:
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Reposition to first attribute after $STANDARD_INFORMATION
|
||||
* and $ATTRIBUTE_LIST instead of simply skipping this attribute
|
||||
* because in the case when we have got only in-memory attribute
|
||||
* list then ntfs_attr_lookup will fail when it tries to find
|
||||
* Reposition to first attribute after $STANDARD_INFORMATION
|
||||
* and $ATTRIBUTE_LIST instead of simply skipping this attribute
|
||||
* because in the case when we have got only in-memory attribute
|
||||
* list then ntfs_attr_lookup will fail when it tries to find
|
||||
* $ATTRIBUTE_LIST.
|
||||
*/
|
||||
ntfs_attr_reinit_search_ctx(ctx);
|
||||
@ -1355,7 +1355,7 @@ void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
|
||||
ni->last_data_change_time = now;
|
||||
if (mask & NTFS_UPDATE_CTIME)
|
||||
ni->last_mft_change_time = now;
|
||||
|
||||
|
||||
NInoFileNameSetDirty(ni);
|
||||
NInoSetDirty(ni);
|
||||
}
|
||||
@ -1368,7 +1368,7 @@ void ntfs_inode_update_times(ntfs_inode *ni, ntfs_time_update_flags mask)
|
||||
* Check if the mft record given by @mft_no and @attr contains the bad sector
|
||||
* list. Please note that mft record numbers describing $Badclus extent inodes
|
||||
* will not match the current $Badclus:$Bad check.
|
||||
*
|
||||
*
|
||||
* On success return 1 if the file is $Badclus:$Bad, otherwise return 0.
|
||||
* On error return -1 with errno set to the error code.
|
||||
*/
|
||||
@ -1382,7 +1382,7 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (mft_no != FILE_BadClus)
|
||||
return 0;
|
||||
|
||||
@ -1456,7 +1456,7 @@ int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size)
|
||||
ret = -ERANGE;
|
||||
}
|
||||
ntfs_attr_put_search_ctx(ctx);
|
||||
}
|
||||
}
|
||||
return (ret ? ret : -errno);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
||||
|
||||
/*
|
||||
* Plenty possibilities for big optimizations all over in the cluster
|
||||
* allocation, however at the moment the dominant bottleneck (~ 90%) is
|
||||
* allocation, however at the moment the dominant bottleneck (~ 90%) is
|
||||
* the update of the mapping pairs which converges to the cubic Faulhaber's
|
||||
* formula as the function of the number of extents (fragments, runs).
|
||||
*/
|
||||
@ -74,7 +74,7 @@ static void ntfs_cluster_set_zone_pos(LCN start, LCN end, LCN *pos, LCN tc)
|
||||
static void ntfs_cluster_update_zone_pos(ntfs_volume *vol, u8 zone, LCN tc)
|
||||
{
|
||||
ntfs_log_trace("tc = %lld, zone = %d\n", (long long)tc, zone);
|
||||
|
||||
|
||||
if (zone == ZONE_MFT)
|
||||
ntfs_cluster_set_zone_pos(vol->mft_lcn, vol->mft_zone_end,
|
||||
&vol->mft_zone_pos, tc);
|
||||
@ -82,7 +82,7 @@ static void ntfs_cluster_update_zone_pos(ntfs_volume *vol, u8 zone, LCN tc)
|
||||
ntfs_cluster_set_zone_pos(vol->mft_zone_end, vol->nr_clusters,
|
||||
&vol->data1_zone_pos, tc);
|
||||
else /* zone == ZONE_DATA2 */
|
||||
ntfs_cluster_set_zone_pos(0, vol->mft_zone_start,
|
||||
ntfs_cluster_set_zone_pos(0, vol->mft_zone_start,
|
||||
&vol->data2_zone_pos, tc);
|
||||
}
|
||||
|
||||
@ -112,15 +112,15 @@ static void update_full_status(ntfs_volume *vol, LCN lcn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static s64 max_empty_bit_range(unsigned char *buf, int size)
|
||||
{
|
||||
int i, j, run = 0;
|
||||
int max_range = 0;
|
||||
s64 start_pos = -1;
|
||||
|
||||
|
||||
ntfs_log_trace("Entering\n");
|
||||
|
||||
|
||||
i = 0;
|
||||
while (i < size) {
|
||||
switch (*buf) {
|
||||
@ -144,42 +144,42 @@ static s64 max_empty_bit_range(unsigned char *buf, int size)
|
||||
break;
|
||||
default :
|
||||
for (j = 0; j < 8; j++) {
|
||||
|
||||
|
||||
int bit = *buf & (1 << j);
|
||||
|
||||
|
||||
if (bit) {
|
||||
if (run > max_range) {
|
||||
max_range = run;
|
||||
start_pos = (s64)i * 8 + (j - run);
|
||||
}
|
||||
run = 0;
|
||||
} else
|
||||
} else
|
||||
run++;
|
||||
}
|
||||
i++;
|
||||
buf++;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (run > max_range)
|
||||
start_pos = (s64)i * 8 - run;
|
||||
|
||||
|
||||
return start_pos;
|
||||
}
|
||||
|
||||
static int bitmap_writeback(ntfs_volume *vol, s64 pos, s64 size, void *b,
|
||||
static int bitmap_writeback(ntfs_volume *vol, s64 pos, s64 size, void *b,
|
||||
u8 *writeback)
|
||||
{
|
||||
s64 written;
|
||||
|
||||
|
||||
ntfs_log_trace("Entering\n");
|
||||
|
||||
|
||||
if (!*writeback)
|
||||
return 0;
|
||||
|
||||
|
||||
*writeback = 0;
|
||||
|
||||
|
||||
written = ntfs_attr_pwrite(vol->lcnbmp_na, pos, size, b);
|
||||
if (written != size) {
|
||||
if (!written)
|
||||
@ -220,16 +220,16 @@ static int bitmap_writeback(ntfs_volume *vol, s64 pos, s64 size, void *b,
|
||||
* expanded to cover the start of the volume in order to reserve space for the
|
||||
* mft bitmap attribute.
|
||||
*
|
||||
* The complexity stems from the need of implementing the mft vs data zoned
|
||||
* approach and from the fact that we have access to the lcn bitmap via up to
|
||||
* NTFS_LCNALLOC_BSIZE bytes at a time, so we need to cope with crossing over
|
||||
* boundaries of two buffers. Further, the fact that the allocator allows for
|
||||
* caller supplied hints as to the location of where allocation should begin
|
||||
* and the fact that the allocator keeps track of where in the data zones the
|
||||
* next natural allocation should occur, contribute to the complexity of the
|
||||
* function. But it should all be worthwhile, because this allocator:
|
||||
* The complexity stems from the need of implementing the mft vs data zoned
|
||||
* approach and from the fact that we have access to the lcn bitmap via up to
|
||||
* NTFS_LCNALLOC_BSIZE bytes at a time, so we need to cope with crossing over
|
||||
* boundaries of two buffers. Further, the fact that the allocator allows for
|
||||
* caller supplied hints as to the location of where allocation should begin
|
||||
* and the fact that the allocator keeps track of where in the data zones the
|
||||
* next natural allocation should occur, contribute to the complexity of the
|
||||
* function. But it should all be worthwhile, because this allocator:
|
||||
* 1) implements MFT zone reservation
|
||||
* 2) causes reduction in fragmentation.
|
||||
* 2) causes reduction in fragmentation.
|
||||
* The code is not optimized for speed.
|
||||
*/
|
||||
runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
@ -251,12 +251,12 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
ntfs_log_enter("Entering with count = 0x%llx, start_lcn = 0x%llx, "
|
||||
"zone = %s_ZONE.\n", (long long)count, (long long)
|
||||
start_lcn, zone == MFT_ZONE ? "MFT" : "DATA");
|
||||
|
||||
|
||||
if (!vol || count < 0 || start_lcn < -1 || !vol->lcnbmp_na ||
|
||||
(s8)zone < FIRST_ZONE || zone > LAST_ZONE) {
|
||||
errno = EINVAL;
|
||||
ntfs_log_perror("%s: vcn: %lld, count: %lld, lcn: %lld",
|
||||
__FUNCTION__, (long long)start_vcn,
|
||||
ntfs_log_perror("%s: vcn: %lld, count: %lld, lcn: %lld",
|
||||
__FUNCTION__, (long long)start_vcn,
|
||||
(long long)count, (long long)start_lcn);
|
||||
goto out;
|
||||
}
|
||||
@ -281,7 +281,7 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
*/
|
||||
has_guess = 1;
|
||||
zone_start = start_lcn;
|
||||
|
||||
|
||||
if (zone_start < 0) {
|
||||
if (zone == DATA_ZONE)
|
||||
zone_start = vol->data1_zone_pos;
|
||||
@ -289,13 +289,13 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
zone_start = vol->mft_zone_pos;
|
||||
has_guess = 0;
|
||||
}
|
||||
|
||||
|
||||
used_zone_pos = has_guess ? 0 : 1;
|
||||
|
||||
|
||||
if (!zone_start || zone_start == vol->mft_zone_start ||
|
||||
zone_start == vol->mft_zone_end)
|
||||
pass = 2;
|
||||
|
||||
|
||||
if (zone_start < vol->mft_zone_start) {
|
||||
zone_end = vol->mft_zone_start;
|
||||
search_zone = ZONE_DATA2;
|
||||
@ -306,7 +306,7 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
zone_end = vol->nr_clusters;
|
||||
search_zone = ZONE_DATA1;
|
||||
}
|
||||
|
||||
|
||||
bmp_pos = zone_start;
|
||||
|
||||
/* Loop until all clusters are allocated. */
|
||||
@ -317,7 +317,7 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
if (search_zone & vol->full_zones)
|
||||
goto zone_pass_done;
|
||||
last_read_pos = bmp_pos >> 3;
|
||||
br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos,
|
||||
br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos,
|
||||
NTFS_LCNALLOC_BSIZE, buf);
|
||||
if (br <= 0) {
|
||||
if (!br)
|
||||
@ -334,7 +334,7 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
lcn = bmp_pos & 7;
|
||||
bmp_pos &= ~7;
|
||||
writeback = 0;
|
||||
|
||||
|
||||
while (lcn < buf_size) {
|
||||
byte = buf + (lcn >> 3);
|
||||
bit = 1 << (lcn & 7);
|
||||
@ -352,11 +352,11 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
}
|
||||
|
||||
/* First free bit is at lcn + bmp_pos. */
|
||||
|
||||
|
||||
/* Reallocate memory if necessary. */
|
||||
if ((rlpos + 2) * (int)sizeof(runlist) >= rlsize) {
|
||||
rlsize += 4096;
|
||||
trl = realloc(rl, rlsize);
|
||||
trl = MEM2_realloc(rl, rlsize);
|
||||
if (!trl) {
|
||||
err = ENOMEM;
|
||||
ntfs_log_perror("realloc() failed");
|
||||
@ -364,17 +364,17 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
}
|
||||
rl = trl;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate the bitmap bit. */
|
||||
*byte |= bit;
|
||||
writeback = 1;
|
||||
if (vol->free_clusters <= 0)
|
||||
if (vol->free_clusters <= 0)
|
||||
ntfs_log_error("Non-positive free clusters "
|
||||
"(%lld)!\n",
|
||||
(long long)vol->free_clusters);
|
||||
else
|
||||
vol->free_clusters--;
|
||||
|
||||
else
|
||||
vol->free_clusters--;
|
||||
|
||||
/*
|
||||
* Coalesce with previous run if adjacent LCNs.
|
||||
* Otherwise, append a new run.
|
||||
@ -382,9 +382,9 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
if (prev_lcn == lcn + bmp_pos - prev_run_len && rlpos) {
|
||||
ntfs_log_debug("Cluster coalesce: prev_lcn: "
|
||||
"%lld lcn: %lld bmp_pos: %lld "
|
||||
"prev_run_len: %lld\n",
|
||||
(long long)prev_lcn,
|
||||
(long long)lcn, (long long)bmp_pos,
|
||||
"prev_run_len: %lld\n",
|
||||
(long long)prev_lcn,
|
||||
(long long)lcn, (long long)bmp_pos,
|
||||
(long long)prev_run_len);
|
||||
rl[rlpos - 1].length = ++prev_run_len;
|
||||
} else {
|
||||
@ -393,54 +393,54 @@ runlist *ntfs_cluster_alloc(ntfs_volume *vol, VCN start_vcn, s64 count,
|
||||
prev_run_len;
|
||||
else {
|
||||
rl[rlpos].vcn = start_vcn;
|
||||
ntfs_log_debug("Start_vcn: %lld\n",
|
||||
ntfs_log_debug("Start_vcn: %lld\n",
|
||||
(long long)start_vcn);
|
||||
}
|
||||
|
||||
|
||||
rl[rlpos].lcn = prev_lcn = lcn + bmp_pos;
|
||||
rl[rlpos].length = prev_run_len = 1;
|
||||
rlpos++;
|
||||
}
|
||||
|
||||
ntfs_log_debug("RUN: %-16lld %-16lld %-16lld\n",
|
||||
(long long)rl[rlpos - 1].vcn,
|
||||
(long long)rl[rlpos - 1].lcn,
|
||||
|
||||
ntfs_log_debug("RUN: %-16lld %-16lld %-16lld\n",
|
||||
(long long)rl[rlpos - 1].vcn,
|
||||
(long long)rl[rlpos - 1].lcn,
|
||||
(long long)rl[rlpos - 1].length);
|
||||
/* Done? */
|
||||
if (!--clusters) {
|
||||
if (used_zone_pos)
|
||||
ntfs_cluster_update_zone_pos(vol,
|
||||
ntfs_cluster_update_zone_pos(vol,
|
||||
search_zone, lcn + bmp_pos + 1 +
|
||||
NTFS_LCNALLOC_SKIP);
|
||||
goto done_ret;
|
||||
}
|
||||
|
||||
|
||||
lcn++;
|
||||
}
|
||||
|
||||
|
||||
if (bitmap_writeback(vol, last_read_pos, br, buf, &writeback)) {
|
||||
err = errno;
|
||||
goto err_ret;
|
||||
}
|
||||
|
||||
|
||||
if (!used_zone_pos) {
|
||||
|
||||
|
||||
used_zone_pos = 1;
|
||||
|
||||
|
||||
if (search_zone == ZONE_MFT)
|
||||
zone_start = vol->mft_zone_pos;
|
||||
else if (search_zone == ZONE_DATA1)
|
||||
zone_start = vol->data1_zone_pos;
|
||||
else
|
||||
zone_start = vol->data2_zone_pos;
|
||||
|
||||
|
||||
if (!zone_start || zone_start == vol->mft_zone_start ||
|
||||
zone_start == vol->mft_zone_end)
|
||||
pass = 2;
|
||||
bmp_pos = zone_start;
|
||||
} else
|
||||
bmp_pos += buf_size;
|
||||
|
||||
|
||||
if (bmp_pos < zone_end)
|
||||
continue;
|
||||
|
||||
@ -449,22 +449,22 @@ zone_pass_done:
|
||||
if (pass == 1) {
|
||||
pass = 2;
|
||||
zone_end = zone_start;
|
||||
|
||||
|
||||
if (search_zone == ZONE_MFT)
|
||||
zone_start = vol->mft_zone_start;
|
||||
else if (search_zone == ZONE_DATA1)
|
||||
zone_start = vol->mft_zone_end;
|
||||
else
|
||||
zone_start = 0;
|
||||
|
||||
|
||||
/* Sanity check. */
|
||||
if (zone_end < zone_start)
|
||||
zone_end = zone_start;
|
||||
|
||||
|
||||
bmp_pos = zone_start;
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* pass == 2 */
|
||||
done_zones_check:
|
||||
done_zones |= search_zone;
|
||||
@ -473,14 +473,14 @@ done_zones_check:
|
||||
ntfs_log_trace("Switching zone.\n");
|
||||
pass = 1;
|
||||
if (rlpos) {
|
||||
LCN tc = rl[rlpos - 1].lcn +
|
||||
LCN tc = rl[rlpos - 1].lcn +
|
||||
rl[rlpos - 1].length + NTFS_LCNALLOC_SKIP;
|
||||
|
||||
|
||||
if (used_zone_pos)
|
||||
ntfs_cluster_update_zone_pos(vol,
|
||||
ntfs_cluster_update_zone_pos(vol,
|
||||
search_zone, tc);
|
||||
}
|
||||
|
||||
|
||||
switch (search_zone) {
|
||||
case ZONE_MFT:
|
||||
ntfs_log_trace("Zone switch: mft -> data1\n");
|
||||
@ -511,17 +511,17 @@ switch_to_data1_zone: search_zone = ZONE_DATA1;
|
||||
pass = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
bmp_pos = zone_start;
|
||||
|
||||
|
||||
if (zone_start == zone_end) {
|
||||
ntfs_log_trace("Empty zone, skipped.\n");
|
||||
goto done_zones_check;
|
||||
}
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
ntfs_log_trace("All zones are finished, no space on device.\n");
|
||||
err = ENOSPC;
|
||||
goto err_ret;
|
||||
@ -543,7 +543,7 @@ done_err_ret:
|
||||
ntfs_log_perror("Failed to allocate clusters");
|
||||
rl = NULL;
|
||||
}
|
||||
out:
|
||||
out:
|
||||
ntfs_log_leave("\n");
|
||||
return rl;
|
||||
|
||||
@ -585,26 +585,26 @@ int ntfs_cluster_free_from_rl(ntfs_volume *vol, runlist *rl)
|
||||
ntfs_log_trace("Dealloc lcn 0x%llx, len 0x%llx.\n",
|
||||
(long long)rl->lcn, (long long)rl->length);
|
||||
|
||||
if (rl->lcn >= 0) {
|
||||
if (rl->lcn >= 0) {
|
||||
update_full_status(vol,rl->lcn);
|
||||
if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn,
|
||||
if (ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn,
|
||||
rl->length)) {
|
||||
ntfs_log_perror("Cluster deallocation failed "
|
||||
"(%lld, %lld)",
|
||||
(long long)rl->lcn,
|
||||
(long long)rl->lcn,
|
||||
(long long)rl->length);
|
||||
goto out;
|
||||
}
|
||||
nr_freed += rl->length ;
|
||||
nr_freed += rl->length ;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
vol->free_clusters += nr_freed;
|
||||
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->free_clusters,
|
||||
(long long)vol->nr_clusters);
|
||||
return ret;
|
||||
}
|
||||
@ -623,24 +623,24 @@ int ntfs_cluster_free_basic(ntfs_volume *vol, s64 lcn, s64 count)
|
||||
ntfs_log_trace("Dealloc lcn 0x%llx, len 0x%llx.\n",
|
||||
(long long)lcn, (long long)count);
|
||||
|
||||
if (lcn >= 0) {
|
||||
if (lcn >= 0) {
|
||||
update_full_status(vol,lcn);
|
||||
if (ntfs_bitmap_clear_run(vol->lcnbmp_na, lcn,
|
||||
if (ntfs_bitmap_clear_run(vol->lcnbmp_na, lcn,
|
||||
count)) {
|
||||
ntfs_log_perror("Cluster deallocation failed "
|
||||
"(%lld, %lld)",
|
||||
(long long)lcn,
|
||||
(long long)lcn,
|
||||
(long long)count);
|
||||
goto out;
|
||||
}
|
||||
nr_freed += count;
|
||||
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->free_clusters,
|
||||
(long long)vol->nr_clusters);
|
||||
return ret;
|
||||
}
|
||||
@ -673,7 +673,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x, count 0x%llx, "
|
||||
"vcn 0x%llx.\n", (unsigned long long)na->ni->mft_no,
|
||||
na->type, (long long)count, (long long)start_vcn);
|
||||
@ -687,7 +687,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count)
|
||||
|
||||
if (rl->lcn < 0 && rl->lcn != LCN_HOLE) {
|
||||
errno = EIO;
|
||||
ntfs_log_perror("%s: Unexpected lcn (%lld)", __FUNCTION__,
|
||||
ntfs_log_perror("%s: Unexpected lcn (%lld)", __FUNCTION__,
|
||||
(long long)rl->lcn);
|
||||
goto leave;
|
||||
}
|
||||
@ -707,7 +707,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count)
|
||||
to_free))
|
||||
goto leave;
|
||||
nr_freed = to_free;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go to the next run and adjust the number of clusters left to free. */
|
||||
++rl;
|
||||
@ -724,7 +724,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count)
|
||||
if (rl->lcn < 0 && rl->lcn != LCN_HOLE) {
|
||||
// FIXME: Eeek! We need rollback! (AIA)
|
||||
errno = EIO;
|
||||
ntfs_log_perror("%s: Invalid lcn (%lli)",
|
||||
ntfs_log_perror("%s: Invalid lcn (%lli)",
|
||||
__FUNCTION__, (long long)rl->lcn);
|
||||
goto out;
|
||||
}
|
||||
@ -760,12 +760,12 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count)
|
||||
|
||||
ret = nr_freed;
|
||||
out:
|
||||
vol->free_clusters += nr_freed ;
|
||||
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->free_clusters,
|
||||
(long long)vol->nr_clusters);
|
||||
leave:
|
||||
leave:
|
||||
ntfs_log_leave("\n");
|
||||
return ret;
|
||||
}
|
||||
|
@ -34,17 +34,21 @@
|
||||
#include "types.h"
|
||||
#include "misc.h"
|
||||
#include "logging.h"
|
||||
#include "mem2.h"
|
||||
|
||||
/**
|
||||
* ntfs_calloc
|
||||
*
|
||||
*
|
||||
* Return a pointer to the allocated memory or NULL if the request fails.
|
||||
*/
|
||||
void *ntfs_calloc(size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = calloc(1, size);
|
||||
|
||||
p = MEM2_alloc(size);
|
||||
if(p)
|
||||
memset(p, 0, size);
|
||||
|
||||
if (!p)
|
||||
ntfs_log_perror("Failed to calloc %lld bytes", (long long)size);
|
||||
return p;
|
||||
@ -53,8 +57,8 @@ void *ntfs_calloc(size_t size)
|
||||
void *ntfs_malloc(size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = malloc(size);
|
||||
|
||||
p = MEM2_alloc(size);
|
||||
if (!p)
|
||||
ntfs_log_perror("Failed to malloc %lld bytes", (long long)size);
|
||||
return p;
|
||||
|
@ -101,14 +101,15 @@ static void ntfs_rl_mc(runlist_element *dstbase, int dst,
|
||||
* On success, return a pointer to the newly allocated, or recycled, memory.
|
||||
* On error, return NULL with errno set to the error code.
|
||||
*/
|
||||
static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size,
|
||||
#include "mem2.h"
|
||||
static runlist_element *ntfs_rl_realloc(runlist_element *rl, int old_size,
|
||||
int new_size)
|
||||
{
|
||||
old_size = (old_size * sizeof(runlist_element) + 0xfff) & ~0xfff;
|
||||
new_size = (new_size * sizeof(runlist_element) + 0xfff) & ~0xfff;
|
||||
if (old_size == new_size)
|
||||
return rl;
|
||||
return realloc(rl, new_size);
|
||||
return MEM2_realloc(rl, new_size);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -381,7 +382,7 @@ static runlist_element *ntfs_rl_insert(runlist_element *dst, int dsize,
|
||||
* left unmodified.
|
||||
*/
|
||||
static runlist_element *ntfs_rl_replace(runlist_element *dst, int dsize,
|
||||
runlist_element *src, int ssize,
|
||||
runlist_element *src, int ssize,
|
||||
int loc)
|
||||
{
|
||||
signed delta;
|
||||
@ -502,7 +503,7 @@ static runlist_element *ntfs_rl_split(runlist_element *dst, int dsize,
|
||||
/**
|
||||
* ntfs_runlists_merge_i - see ntfs_runlists_merge
|
||||
*/
|
||||
static runlist_element *ntfs_runlists_merge_i(runlist_element *drl,
|
||||
static runlist_element *ntfs_runlists_merge_i(runlist_element *drl,
|
||||
runlist_element *srl)
|
||||
{
|
||||
int di, si; /* Current index into @[ds]rl. */
|
||||
@ -744,8 +745,8 @@ critical_error:
|
||||
runlist_element *ntfs_runlists_merge(runlist_element *drl,
|
||||
runlist_element *srl)
|
||||
{
|
||||
runlist_element *rl;
|
||||
|
||||
runlist_element *rl;
|
||||
|
||||
ntfs_log_enter("Entering\n");
|
||||
rl = ntfs_runlists_merge_i(drl, srl);
|
||||
ntfs_log_leave("\n");
|
||||
@ -835,7 +836,7 @@ static runlist_element *ntfs_mapping_pairs_decompress_i(const ntfs_volume *vol,
|
||||
runlist_element *rl2;
|
||||
|
||||
rlsize += 0x1000;
|
||||
rl2 = realloc(rl, rlsize);
|
||||
rl2 = MEM2_realloc(rl, rlsize);
|
||||
if (!rl2) {
|
||||
int eo = errno;
|
||||
free(rl);
|
||||
@ -1006,8 +1007,8 @@ err_out:
|
||||
runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol,
|
||||
const ATTR_RECORD *attr, runlist_element *old_rl)
|
||||
{
|
||||
runlist_element *rle;
|
||||
|
||||
runlist_element *rle;
|
||||
|
||||
ntfs_log_enter("Entering\n");
|
||||
rle = ntfs_mapping_pairs_decompress_i(vol, attr, old_rl);
|
||||
ntfs_log_leave("\n");
|
||||
@ -1211,10 +1212,10 @@ s64 ntfs_rl_pwrite(const ntfs_volume *vol, const runlist_element *rl,
|
||||
|
||||
if (rl->lcn != (LCN)LCN_HOLE)
|
||||
goto rl_err_out;
|
||||
|
||||
|
||||
to_write = min(count, (rl->length <<
|
||||
vol->cluster_size_bits) - ofs);
|
||||
|
||||
|
||||
total += to_write;
|
||||
count -= to_write;
|
||||
b = (u8*)b + to_write;
|
||||
@ -1384,14 +1385,14 @@ int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol,
|
||||
prev_lcn = rl->lcn;
|
||||
}
|
||||
}
|
||||
out:
|
||||
out:
|
||||
return rls;
|
||||
err_out:
|
||||
if (rl->lcn == LCN_RL_NOT_MAPPED)
|
||||
errno = EINVAL;
|
||||
else
|
||||
errno = EIO;
|
||||
errno_set:
|
||||
errno_set:
|
||||
rls = -1;
|
||||
goto out;
|
||||
}
|
||||
@ -1590,7 +1591,7 @@ int ntfs_mapping_pairs_build(const ntfs_volume *vol, u8 *dst,
|
||||
/* Set stop vcn. */
|
||||
if (stop_rl)
|
||||
*stop_rl = rl;
|
||||
ok:
|
||||
ok:
|
||||
/* Add terminator byte. */
|
||||
*dst = 0;
|
||||
out:
|
||||
@ -1644,31 +1645,31 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn)
|
||||
" arl: %p *arl: %p", arl, *arl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
rl = *arl;
|
||||
|
||||
|
||||
if (start_vcn < rl->vcn) {
|
||||
errno = EINVAL;
|
||||
ntfs_log_perror("Start_vcn lies outside front of runlist");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Find the starting vcn in the run list. */
|
||||
while (rl->length) {
|
||||
if (start_vcn < rl[1].vcn)
|
||||
break;
|
||||
rl++;
|
||||
}
|
||||
|
||||
|
||||
if (!rl->length) {
|
||||
errno = EIO;
|
||||
ntfs_log_trace("Truncating already truncated runlist?\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Truncate the run. */
|
||||
rl->length = start_vcn - rl->vcn;
|
||||
|
||||
|
||||
/*
|
||||
* If a run was partially truncated, make the following runlist
|
||||
* element a terminator instead of the truncated runlist
|
||||
@ -1684,10 +1685,10 @@ int ntfs_rl_truncate(runlist **arl, const VCN start_vcn)
|
||||
rl->lcn = (LCN)LCN_ENOENT;
|
||||
/**
|
||||
* Reallocate memory if necessary.
|
||||
* FIXME: Below code is broken, because runlist allocations must be
|
||||
* FIXME: Below code is broken, because runlist allocations must be
|
||||
* a multiply of 4096. The code caused crashes and corruptions.
|
||||
*/
|
||||
/*
|
||||
/*
|
||||
if (!is_end) {
|
||||
size_t new_size = (rl - *arl + 1) * sizeof(runlist_element);
|
||||
rl = realloc(*arl, new_size);
|
||||
@ -1900,7 +1901,7 @@ static runlist_element * test_rl_pure_src(BOOL contig, BOOL multi, int vcn, int
|
||||
result = ntfs_malloc(4096);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
|
||||
if (multi) {
|
||||
MKRL(result+0, vcn + (0*len/4), fudge + vcn + 1000 + (0*len/4), len / 4)
|
||||
MKRL(result+1, vcn + (1*len/4), fudge + vcn + 1000 + (1*len/4), len / 4)
|
||||
|
@ -127,8 +127,8 @@ struct SDH { /* this is an image of an $SDH index entry */
|
||||
|
||||
static ntfschar sii_stream[] = { const_cpu_to_le16('$'),
|
||||
const_cpu_to_le16('S'),
|
||||
const_cpu_to_le16('I'),
|
||||
const_cpu_to_le16('I'),
|
||||
const_cpu_to_le16('I'),
|
||||
const_cpu_to_le16('I'),
|
||||
const_cpu_to_le16(0) };
|
||||
static ntfschar sdh_stream[] = { const_cpu_to_le16('$'),
|
||||
const_cpu_to_le16('S'),
|
||||
@ -769,7 +769,7 @@ static le32 entersecurityattr(ntfs_volume *vol,
|
||||
retries = 0;
|
||||
while (entry) {
|
||||
next = ntfs_index_next(entry,xsii);
|
||||
if (next) {
|
||||
if (next) {
|
||||
psii = (struct SII*)next;
|
||||
/* save last key and */
|
||||
/* available position */
|
||||
@ -1109,7 +1109,7 @@ static int update_secur_descr(ntfs_volume *vol,
|
||||
* This is intended to allow graceful upgrades for files which
|
||||
* were created in previous versions, with a security attributes
|
||||
* and no security id.
|
||||
*
|
||||
*
|
||||
* It will allocate a security id and replace the individual
|
||||
* security attribute by a reference to the global one
|
||||
*
|
||||
@ -1458,7 +1458,7 @@ static int leg_compare(const struct CACHED_PERMISSIONS_LEGACY *cached,
|
||||
/*
|
||||
* Resize permission cache table
|
||||
* do not call unless resizing is needed
|
||||
*
|
||||
*
|
||||
* If allocation fails, the cache size is not updated
|
||||
* Lack of memory is not considered as an error, the cache is left
|
||||
* consistent and errno is not set.
|
||||
@ -1554,7 +1554,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;
|
||||
@ -1585,7 +1585,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++)
|
||||
@ -1598,7 +1598,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;
|
||||
@ -2088,7 +2088,7 @@ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
const SECURITY_DESCRIPTOR_RELATIVE *phead;
|
||||
struct POSIX_SECURITY *pxdesc;
|
||||
@ -2429,7 +2429,7 @@ int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx,
|
||||
stbuf->st_uid = ntfs_find_user(scx->mapping[MAPUSERS],usid);
|
||||
#else
|
||||
if (!perm && ntfs_same_sid(usid, adminsid)) {
|
||||
stbuf->st_uid =
|
||||
stbuf->st_uid =
|
||||
find_tenant(scx,
|
||||
securattr);
|
||||
if (stbuf->st_uid)
|
||||
@ -2541,7 +2541,7 @@ static struct POSIX_SECURITY *inherit_posix(struct SECURITY_CONTEXT *scx,
|
||||
|
||||
/*
|
||||
* Allocate a security_id for a file being created
|
||||
*
|
||||
*
|
||||
* Returns zero if not possible (NTFS v3.x required)
|
||||
*/
|
||||
|
||||
@ -2763,7 +2763,7 @@ le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
|
||||
/*
|
||||
* Update ownership and mode of a file, reusing an existing
|
||||
* security descriptor when possible
|
||||
*
|
||||
*
|
||||
* Returns zero if successful
|
||||
*/
|
||||
|
||||
@ -3177,7 +3177,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))
|
||||
@ -3265,7 +3265,7 @@ int ntfs_sd_add_everyone(ntfs_inode *ni)
|
||||
ACCESS_ALLOWED_ACE *ace;
|
||||
SID *sid;
|
||||
int ret, sd_len;
|
||||
|
||||
|
||||
/* Create SECURITY_DESCRIPTOR attribute (everyone has full access). */
|
||||
/*
|
||||
* Calculate security descriptor length. We have 2 sub-authorities in
|
||||
@ -3273,14 +3273,14 @@ int ntfs_sd_add_everyone(ntfs_inode *ni)
|
||||
* 4 bytes to every SID.
|
||||
*/
|
||||
sd_len = sizeof(SECURITY_DESCRIPTOR_ATTR) + 2 * (sizeof(SID) + 4) +
|
||||
sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
|
||||
sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE);
|
||||
sd = (SECURITY_DESCRIPTOR_RELATIVE*)ntfs_calloc(sd_len);
|
||||
if (!sd)
|
||||
return -1;
|
||||
|
||||
|
||||
sd->revision = SECURITY_DESCRIPTOR_REVISION;
|
||||
sd->control = SE_DACL_PRESENT | SE_SELF_RELATIVE;
|
||||
|
||||
|
||||
sid = (SID*)((u8*)sd + sizeof(SECURITY_DESCRIPTOR_ATTR));
|
||||
sid->revision = SID_REVISION;
|
||||
sid->sub_authority_count = 2;
|
||||
@ -3288,21 +3288,21 @@ int ntfs_sd_add_everyone(ntfs_inode *ni)
|
||||
sid->sub_authority[1] = const_cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS);
|
||||
sid->identifier_authority.value[5] = 5;
|
||||
sd->owner = cpu_to_le32((u8*)sid - (u8*)sd);
|
||||
|
||||
sid = (SID*)((u8*)sid + sizeof(SID) + 4);
|
||||
|
||||
sid = (SID*)((u8*)sid + sizeof(SID) + 4);
|
||||
sid->revision = SID_REVISION;
|
||||
sid->sub_authority_count = 2;
|
||||
sid->sub_authority[0] = const_cpu_to_le32(SECURITY_BUILTIN_DOMAIN_RID);
|
||||
sid->sub_authority[1] = const_cpu_to_le32(DOMAIN_ALIAS_RID_ADMINS);
|
||||
sid->identifier_authority.value[5] = 5;
|
||||
sd->group = cpu_to_le32((u8*)sid - (u8*)sd);
|
||||
|
||||
|
||||
acl = (ACL*)((u8*)sid + sizeof(SID) + 4);
|
||||
acl->revision = ACL_REVISION;
|
||||
acl->size = const_cpu_to_le16(sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE));
|
||||
acl->ace_count = const_cpu_to_le16(1);
|
||||
sd->dacl = cpu_to_le32((u8*)acl - (u8*)sd);
|
||||
|
||||
|
||||
ace = (ACCESS_ALLOWED_ACE*)((u8*)acl + sizeof(ACL));
|
||||
ace->type = ACCESS_ALLOWED_ACE_TYPE;
|
||||
ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE;
|
||||
@ -3317,7 +3317,7 @@ int ntfs_sd_add_everyone(ntfs_inode *ni)
|
||||
sd_len);
|
||||
if (ret)
|
||||
ntfs_log_perror("Failed to add initial SECURITY_DESCRIPTOR");
|
||||
|
||||
|
||||
free(sd);
|
||||
return ret;
|
||||
}
|
||||
@ -3416,7 +3416,7 @@ int ntfs_allowed_access(struct SECURITY_CONTEXT *scx,
|
||||
*
|
||||
* Returns true if access is allowed, including user is root and
|
||||
* no user mapping defined
|
||||
*
|
||||
*
|
||||
* Sets errno if there is a problem or if not allowed
|
||||
*
|
||||
* This is used for Posix ACL and checking creation of DOS file names
|
||||
@ -3564,7 +3564,7 @@ int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
if (uid && (fileuid != uid))
|
||||
mode &= 01777;
|
||||
#if POSIXACLS
|
||||
res = ntfs_set_owner_mode(scx, ni, uid, gid,
|
||||
res = ntfs_set_owner_mode(scx, ni, uid, gid,
|
||||
mode, pxdesc);
|
||||
#else
|
||||
res = ntfs_set_owner_mode(scx, ni, uid, gid, mode);
|
||||
@ -3626,7 +3626,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))
|
||||
@ -3680,7 +3680,7 @@ int ntfs_set_ownmod(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
|
||||
if ((int)gid < 0)
|
||||
gid = filegid;
|
||||
#if POSIXACLS
|
||||
res = ntfs_set_owner_mode(scx, ni, uid, gid,
|
||||
res = ntfs_set_owner_mode(scx, ni, uid, gid,
|
||||
mode, newpxdesc);
|
||||
#else
|
||||
res = ntfs_set_owner_mode(scx, ni, uid, gid, mode);
|
||||
@ -3891,7 +3891,7 @@ le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
|
||||
*
|
||||
* Returns 0 if OK, -1 (and errno set) if error
|
||||
*/
|
||||
|
||||
#include "mem2.h"
|
||||
static int link_single_group(struct MAPPING *usermapping, struct passwd *user,
|
||||
gid_t gid)
|
||||
{
|
||||
@ -3911,9 +3911,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;
|
||||
@ -4323,7 +4323,7 @@ void ntfs_close_secure(struct SECURITY_CONTEXT *scx)
|
||||
ntfs_index_ctx_put(vol->secure_xsii);
|
||||
ntfs_index_ctx_put(vol->secure_xsdh);
|
||||
ntfs_inode_close(vol->secure_ni);
|
||||
|
||||
|
||||
}
|
||||
ntfs_free_mapping(scx->mapping);
|
||||
free_caches(scx);
|
||||
|
@ -434,18 +434,18 @@ void ntfs_file_value_upcase(FILE_NAME_ATTR *file_name_attr,
|
||||
so this patch fixes the resulting issues for systems which use
|
||||
UTF-8 and for others, specifying the locale in fstab brings them
|
||||
the encoding which they want.
|
||||
|
||||
|
||||
If no locale is defined or there was a problem with setting one
|
||||
up and whenever nl_langinfo(CODESET) returns a sting starting with
|
||||
"ANSI", use an internal UCS-2LE <-> UTF-8 codeset converter to fix
|
||||
the bug where NTFS-3G does not show any path names which include
|
||||
international characters!!! (and also fails on creating them) as result.
|
||||
|
||||
|
||||
Author: Bernhard Kaindl <bk@suse.de>
|
||||
Jean-Pierre Andre made it compliant with RFC3629/RFC2781.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Return the amount of 8-bit elements in UTF-8 needed (without the terminating
|
||||
* null) to store a given UTF-16LE string.
|
||||
*
|
||||
@ -464,7 +464,7 @@ static int utf16_to_utf8_size(const ntfschar *ins, const int ins_len, int outs_l
|
||||
if ((c >= 0xdc00) && (c < 0xe000)) {
|
||||
surrog = FALSE;
|
||||
count += 4;
|
||||
} else
|
||||
} else
|
||||
goto fail;
|
||||
} else
|
||||
if (c < 0x80)
|
||||
@ -481,14 +481,14 @@ static int utf16_to_utf8_size(const ntfschar *ins, const int ins_len, int outs_l
|
||||
else if (c >= 0xe000)
|
||||
#endif
|
||||
count += 3;
|
||||
else
|
||||
else
|
||||
goto fail;
|
||||
if (count > outs_len) {
|
||||
errno = ENAMETOOLONG;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
if (surrog)
|
||||
if (surrog)
|
||||
goto fail;
|
||||
|
||||
ret = count;
|
||||
@ -550,7 +550,7 @@ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len,
|
||||
*t++ = 0x80 + ((c >> 6) & 15) + ((halfpair & 3) << 4);
|
||||
*t++ = 0x80 + (c & 63);
|
||||
halfpair = 0;
|
||||
} else
|
||||
} else
|
||||
goto fail;
|
||||
} else if (c < 0x80) {
|
||||
*t++ = c;
|
||||
@ -568,12 +568,12 @@ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len,
|
||||
*t++ = 0xe0 | (c >> 12);
|
||||
*t++ = 0x80 | ((c >> 6) & 0x3f);
|
||||
*t++ = 0x80 | (c & 0x3f);
|
||||
} else
|
||||
} else
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
*t = '\0';
|
||||
|
||||
|
||||
#if defined(__APPLE__) || defined(__DARWIN__)
|
||||
#ifdef ENABLE_NFCONV
|
||||
if(nfconvert_utf8 && (t - *outs) > 0) {
|
||||
@ -602,7 +602,7 @@ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len,
|
||||
}
|
||||
#endif /* ENABLE_NFCONV */
|
||||
#endif /* defined(__APPLE__) || defined(__DARWIN__) */
|
||||
|
||||
|
||||
ret = t - *outs;
|
||||
out:
|
||||
return ret;
|
||||
@ -611,8 +611,8 @@ fail:
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the amount of 16-bit elements in UTF-16LE needed
|
||||
/*
|
||||
* Return the amount of 16-bit elements in UTF-16LE needed
|
||||
* (without the terminating null) to store given UTF-8 string.
|
||||
*
|
||||
* Return -1 with errno set if it's longer than PATH_MAX or string is invalid.
|
||||
@ -627,22 +627,22 @@ static int utf8_to_utf16_size(const char *s)
|
||||
size_t count = 0;
|
||||
|
||||
while ((byte = *((const unsigned char *)s++))) {
|
||||
if (++count >= PATH_MAX)
|
||||
if (++count >= PATH_MAX)
|
||||
goto fail;
|
||||
if (byte >= 0xc0) {
|
||||
if (byte >= 0xF5) {
|
||||
errno = EILSEQ;
|
||||
goto out;
|
||||
}
|
||||
if (!*s)
|
||||
if (!*s)
|
||||
break;
|
||||
if (byte >= 0xC0)
|
||||
if (byte >= 0xC0)
|
||||
s++;
|
||||
if (!*s)
|
||||
if (!*s)
|
||||
break;
|
||||
if (byte >= 0xE0)
|
||||
if (byte >= 0xE0)
|
||||
s++;
|
||||
if (!*s)
|
||||
if (!*s)
|
||||
break;
|
||||
if (byte >= 0xF0) {
|
||||
s++;
|
||||
@ -658,11 +658,11 @@ fail:
|
||||
errno = ENAMETOOLONG;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
/*
|
||||
* This converts one UTF-8 sequence to cpu-endian Unicode value
|
||||
* within range U+0 .. U+10ffff and excluding U+D800 .. U+DFFF
|
||||
*
|
||||
* Return the number of used utf8 bytes or -1 with errno set
|
||||
* Return the number of used utf8 bytes or -1 with errno set
|
||||
* if sequence is invalid.
|
||||
*/
|
||||
static int utf8_to_unicode(u32 *wc, const char *s)
|
||||
@ -728,7 +728,7 @@ fail:
|
||||
* @ins: input multibyte string buffer
|
||||
* @outs: on return contains the (allocated) output utf16 string
|
||||
* @outs_len: length of output buffer in utf16 characters
|
||||
*
|
||||
*
|
||||
* Return -1 with errno set.
|
||||
*/
|
||||
static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs)
|
||||
@ -789,7 +789,7 @@ static int ntfs_utf8_to_utf16(const char *ins, ntfschar **outs)
|
||||
}
|
||||
t += m;
|
||||
}
|
||||
|
||||
|
||||
ret = --outpos - *outs;
|
||||
fail:
|
||||
#if defined(__APPLE__) || defined(__DARWIN__)
|
||||
@ -932,7 +932,7 @@ err_out:
|
||||
* Convert the input multibyte string @ins, from the current locale into the
|
||||
* corresponding little endian, 2-byte Unicode string.
|
||||
*
|
||||
* The function allocates the string and the caller is responsible for calling
|
||||
* The function allocates the string and the caller is responsible for calling
|
||||
* free(*@outs); when finished with it.
|
||||
*
|
||||
* On success the function returns the number of Unicode characters written to
|
||||
@ -963,7 +963,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs)
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (use_utf8)
|
||||
return ntfs_utf8_to_utf16(ins, outs);
|
||||
|
||||
@ -1013,7 +1013,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs)
|
||||
if (o >= ucs_len) {
|
||||
ntfschar *tc;
|
||||
ucs_len = (ucs_len * sizeof(ntfschar) + 64) & ~63;
|
||||
tc = realloc(ucs, ucs_len);
|
||||
tc = MEM2_realloc(ucs, ucs_len);
|
||||
if (!tc)
|
||||
goto err_out;
|
||||
ucs = tc;
|
||||
@ -1227,12 +1227,12 @@ ntfschar *ntfs_locase_table_build(const ntfschar *uc, u32 uc_cnt)
|
||||
* @len: length of output buffer in Unicode characters
|
||||
*
|
||||
* Convert the input @s string into the corresponding little endian,
|
||||
* 2-byte Unicode string. The length of the converted string is less
|
||||
* 2-byte Unicode string. The length of the converted string is less
|
||||
* or equal to the maximum length allowed by the NTFS format (255).
|
||||
*
|
||||
* If @s is NULL then return AT_UNNAMED.
|
||||
*
|
||||
* On success the function returns the Unicode string in an allocated
|
||||
* On success the function returns the Unicode string in an allocated
|
||||
* buffer and the caller is responsible to free it when it's not needed
|
||||
* anymore.
|
||||
*
|
||||
@ -1371,7 +1371,7 @@ int ntfs_macosx_normalize_filenames(int normalize) {
|
||||
#else
|
||||
return -1;
|
||||
#endif /* ENABLE_NFCONV */
|
||||
}
|
||||
}
|
||||
|
||||
int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target,
|
||||
int composed) {
|
||||
@ -1383,14 +1383,14 @@ int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target,
|
||||
CFIndex requiredBufferLength;
|
||||
char *result = NULL;
|
||||
int resultLength = -1;
|
||||
|
||||
|
||||
/* Convert the UTF-8 string to a CFString. */
|
||||
cfSourceString = CFStringCreateWithCString(kCFAllocatorDefault, utf8_string, kCFStringEncodingUTF8);
|
||||
if(cfSourceString == NULL) {
|
||||
ntfs_log_error("CFStringCreateWithCString failed!\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
/* Create a mutable string from cfSourceString that we are free to modify. */
|
||||
cfMutableString = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, cfSourceString);
|
||||
CFRelease(cfSourceString); /* End-of-life. */
|
||||
@ -1398,16 +1398,16 @@ int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target,
|
||||
ntfs_log_error("CFStringCreateMutableCopy failed!\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
|
||||
/* Normalize the mutable string to the desired normalization form. */
|
||||
CFStringNormalize(cfMutableString, (composed != 0 ? kCFStringNormalizationFormC : kCFStringNormalizationFormD));
|
||||
|
||||
|
||||
/* Store the resulting string in a '\0'-terminated UTF-8 encoded char* buffer. */
|
||||
rangeToProcess = CFRangeMake(0, CFStringGetLength(cfMutableString));
|
||||
if(CFStringGetBytes(cfMutableString, rangeToProcess, kCFStringEncodingUTF8, 0, false, NULL, 0, &requiredBufferLength) > 0) {
|
||||
resultLength = sizeof(char)*(requiredBufferLength + 1);
|
||||
result = ntfs_calloc(resultLength);
|
||||
|
||||
|
||||
if(result != NULL) {
|
||||
if(CFStringGetBytes(cfMutableString, rangeToProcess, kCFStringEncodingUTF8,
|
||||
0, false, (UInt8*)result, resultLength-1, &requiredBufferLength) <= 0) {
|
||||
@ -1422,9 +1422,9 @@ int ntfs_macosx_normalize_utf8(const char *utf8_string, char **target,
|
||||
else
|
||||
ntfs_log_error("Could not perform check for required length of UTF-8 conversion of normalized CFMutableString.\n");
|
||||
|
||||
|
||||
|
||||
CFRelease(cfMutableString);
|
||||
|
||||
|
||||
if(result != NULL) {
|
||||
*target = result;
|
||||
return resultLength - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user