Cleaned code


			
			
				N2009_11_14_FIXES
			
			
		
jpandre 2007-10-09 08:01:37 +00:00
parent 88772c9912
commit 0fcd72cf55
1 changed files with 42 additions and 26 deletions

View File

@ -59,6 +59,11 @@
#include "misc.h"
ntfschar AT_UNNAMED[] = { const_cpu_to_le16('\0') };
const ntfschar STREAM_SDS[] = { const_cpu_to_le16('$'),
const_cpu_to_le16('S'),
const_cpu_to_le16('D'),
const_cpu_to_le16('S'),
const_cpu_to_le16('\0') };
/**
* ntfs_get_attribute_value_length - Find the length of an attribute
@ -265,11 +270,13 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol,
* Initialize the ntfs attribute @na with @ni, @type, @name, and @name_len.
*/
static void __ntfs_attr_init(ntfs_attr *na, ntfs_inode *ni,
const ATTR_TYPES type, ntfschar *name, const u32 name_len)
const ATTR_TYPES type, const ntfschar *name, const u32 name_len)
{
na->rl = NULL;
na->ni = ni;
na->type = type;
/* JPA should warn against feeing the name */
/* before closing the struct */
na->name = name;
if (name)
na->name_len = name_len;
@ -340,7 +347,7 @@ void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident,
* both those cases @name_len is not used at all.
*/
ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type,
ntfschar *name, u32 name_len)
const ntfschar *name, u32 name_len)
{
ntfs_attr_search_ctx *ctx;
ntfs_attr *na;
@ -439,8 +446,9 @@ void ntfs_attr_close(ntfs_attr *na)
if (NAttrNonResident(na) && na->rl)
free(na->rl);
/* Don't release if using an internal constant. */
if (na->name != AT_UNNAMED && na->name != NTFS_INDEX_I30)
free(na->name);
if (na->name != AT_UNNAMED && na->name != NTFS_INDEX_I30
&& na->name != STREAM_SDS)
ntfs_free(na->name);
free(na);
}
@ -754,7 +762,8 @@ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b)
if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) {
errno = EINVAL;
ntfs_log_perror("%s: na=%p b=%p pos=%lld count=%lld",
__FUNCTION__, na, b, pos, count);
__FUNCTION__, na, b, (long long)pos,
(long long)count);
return -1;
}
@ -868,7 +877,8 @@ res_err_out:
if (rl->lcn < (LCN)0) {
if (rl->lcn != (LCN)LCN_HOLE) {
ntfs_log_perror("%s: Bad run (%lld)",
__FUNCTION__, rl->lcn);
__FUNCTION__,
(long long)rl->lcn);
goto rl_err_out;
}
/* It is a hole, just zero the matching @b range. */
@ -1271,7 +1281,8 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b)
if (rl->lcn != (LCN)LCN_HOLE) {
errno = EIO;
ntfs_log_perror("%s: Unexpected LCN (%lld)",
__FUNCTION__, rl->lcn);
__FUNCTION__,
(long long)rl->lcn);
goto rl_err_out;
}
@ -1286,9 +1297,9 @@ retry:
if (!NVolReadOnly(vol)) {
s64 wpos = (rl->lcn << vol->cluster_size_bits) + ofs;
s64 wend = (rl->vcn << vol->cluster_size_bits) + ofs + to_write;
u32 bsize = vol->cluster_size;
s64 rounded = ((wend + bsize - 1) & ~(s64)(bsize - 1)) - wend;
s64 wend = (rl->vcn << vol->cluster_size_bits) + ofs + to_write;
s64 rounded = ((wend + bsize - 1) & ~(s64)(bsize - 1)) - wend;
/*
* Zero fill to cluster boundary if we're writing to an
@ -1530,7 +1541,8 @@ s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt,
/* Write the prepared data. */
written = ntfs_attr_pwrite(na, pos, bk_cnt * bk_size, src);
if (written <= 0) {
ntfs_log_perror("%s: written=%lld", __FUNCTION__, written);
ntfs_log_perror("%s: written=%lld", __FUNCTION__,
(long long)written);
}
/* Quickly deprotect the data again. */
for (i = 0; i < bk_cnt; ++i)
@ -2430,7 +2442,8 @@ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type,
if (size < 0) {
errno = EINVAL;
ntfs_log_perror("%s: size=%lld", __FUNCTION__, size);
ntfs_log_perror("%s: size=%lld", __FUNCTION__,
(long long)size);
return -1;
}
@ -2440,7 +2453,7 @@ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type,
*/
if (type == AT_ATTRIBUTE_LIST && size > 0x40000) {
errno = ERANGE;
ntfs_log_perror("Too large attrlist (%lld)", size);
ntfs_log_perror("Too large attrlist (%lld)", (long long)size);
return -1;
}
@ -2455,7 +2468,8 @@ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type,
((max_size > 0) && (size > max_size))) {
errno = ERANGE;
ntfs_log_perror("Attr type %d size check failed (min,size,max="
"%lld,%lld,%lld)", type, min_size, size, max_size);
"%lld,%lld,%lld)", type, (long long)min_size,
(long long)size, (long long)max_size);
return -1;
}
return 0;
@ -2600,8 +2614,8 @@ int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size)
* EIO - I/O error occurred or damaged filesystem.
*/
int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
ntfschar *name, u8 name_len, u8 *val, u32 size,
ATTR_FLAGS flags)
const ntfschar *name, u8 name_len, const u8 *val,
u32 size, ATTR_FLAGS flags)
{
ntfs_attr_search_ctx *ctx;
u32 length;
@ -2723,8 +2737,8 @@ put_err_out:
* EIO - I/O error occurred or damaged filesystem.
*/
int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size,
ATTR_FLAGS flags)
const ntfschar *name, u8 name_len, VCN lowest_vcn,
int dataruns_size, ATTR_FLAGS flags)
{
ntfs_attr_search_ctx *ctx;
u32 length;
@ -3006,7 +3020,7 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx)
* On success return 0. On error return -1 with errno set to the error code.
*/
int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type,
ntfschar *name, u8 name_len, u8 *val, s64 size)
const ntfschar *name, u8 name_len, const u8 *val, s64 size)
{
u32 attr_rec_size;
int err, i, offset;
@ -3016,7 +3030,8 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type,
if (!ni || size < 0 || type == AT_ATTRIBUTE_LIST) {
errno = EINVAL;
ntfs_log_perror("%s: ni=%p size=%lld", __FUNCTION__, ni, size);
ntfs_log_perror("%s: ni=%p size=%lld", __FUNCTION__, ni,
(long long)size);
return -1;
}
@ -4728,8 +4743,9 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize)
DATA_ZONE);
if (!rl) {
ntfs_log_perror("Cluster allocation failed "
"(%lld)", first_free_vcn -
(na->allocated_size >>
"(%lld)",
(long long)first_free_vcn -
((long long)na->allocated_size >>
vol->cluster_size_bits));
return -1;
}
@ -4920,7 +4936,7 @@ int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize)
* On error NULL is returned with errno set to the error code.
*/
void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type,
ntfschar *name, u32 name_len, s64 *data_size)
const ntfschar *name, u32 name_len, s64 *data_size)
{
ntfs_attr *na;
void *data, *ret = NULL;
@ -4953,8 +4969,8 @@ out:
int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name,
u32 name_len)
int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type,
const ntfschar *name, u32 name_len)
{
ntfs_attr_search_ctx *ctx;
int ret;
@ -4973,8 +4989,8 @@ int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name,
return !ret;
}
int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name,
u32 name_len)
int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type,
const ntfschar *name, u32 name_len)
{
ntfs_attr *na;
int ret;