NTFS: Code cleanup
This commit is contained in:
@@ -57,7 +57,7 @@ status_t set_mime(vnode *node, const char *filename)
|
|||||||
if (!strcasecmp(filename + namelen - ext_len, p->extension))
|
if (!strcasecmp(filename + namelen - ext_len, p->extension))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(p->mime==NULL)
|
if(p->mime == NULL)
|
||||||
node->mime = kFailBackMime;
|
node->mime = kFailBackMime;
|
||||||
else
|
else
|
||||||
node->mime = p->mime;
|
node->mime = p->mime;
|
||||||
|
|||||||
@@ -75,8 +75,10 @@ UNLOCK((vol)->vlock); \
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NF_FreeClustersOutdate = (1 << 0), // Information about amount of free clusters is outdated.
|
// Information about amount of free clusters is outdated.
|
||||||
NF_FreeMFTOutdate = (1 << 1), // Information about amount of free MFT records is outdated.
|
NF_FreeClustersOutdate = (1 << 0),
|
||||||
|
// Information about amount of free MFT records is outdated.
|
||||||
|
NF_FreeMFTOutdate = (1 << 1),
|
||||||
} ntfs_state_bits;
|
} ntfs_state_bits;
|
||||||
|
|
||||||
|
|
||||||
@@ -104,8 +106,8 @@ typedef struct attrdircookie {
|
|||||||
ntfs_attr_search_ctx *ctx;
|
ntfs_attr_search_ctx *ctx;
|
||||||
} attrdircookie;
|
} attrdircookie;
|
||||||
|
|
||||||
#define ntfs_mark_free_space_outdated(ns) (ns->state |= (NF_FreeClustersOutdate | NF_FreeMFTOutdate));
|
#define ntfs_mark_free_space_outdated(ns) \
|
||||||
|
(ns->state |= (NF_FreeClustersOutdate | NF_FreeMFTOutdate));
|
||||||
|
|
||||||
|
|
||||||
typedef struct nspace {
|
typedef struct nspace {
|
||||||
|
|||||||
@@ -38,27 +38,25 @@
|
|||||||
#include "ntfs.h"
|
#include "ntfs.h"
|
||||||
#include "volume_util.h"
|
#include "volume_util.h"
|
||||||
|
|
||||||
static unsigned char ntfs_bits_table[] = { 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0 };
|
static unsigned char ntfs_bits_table[] = { 4, 3, 3, 2, 3, 2, 2, 1,
|
||||||
|
3, 2, 2, 1, 2, 1, 1, 0 };
|
||||||
|
|
||||||
static uint8 ntfs_count_bits(unsigned char byte, unsigned char shift)
|
static uint8 ntfs_count_bits(unsigned char byte, unsigned char shift)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned char counter = 0;
|
unsigned char counter = 0;
|
||||||
|
|
||||||
if(shift < 8)
|
if(shift < 8) {
|
||||||
{
|
for(i=0; i<shift; i++) {
|
||||||
for(i=0; i<shift; i++)
|
if(!(byte & 0x80))
|
||||||
{
|
counter++;
|
||||||
if(!(byte & 0x80))counter++;
|
byte = byte << 1;
|
||||||
byte = byte << 1;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
counter += ntfs_bits_table[byte & 0x0F];
|
counter += ntfs_bits_table[byte & 0x0F];
|
||||||
counter += ntfs_bits_table[(byte & 0xF0) >> 4];
|
counter += ntfs_bits_table[(byte & 0xF0) >> 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,34 +71,35 @@ int ntfs_calc_free_space(nspace *_ns)
|
|||||||
size_t readed;
|
size_t readed;
|
||||||
unsigned char *buf = NULL;
|
unsigned char *buf = NULL;
|
||||||
|
|
||||||
if(ns== NULL || vol==NULL || data==NULL)
|
if (ns == NULL || vol == NULL || data == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(vol->lcnbmp_na==NULL)
|
if (vol->lcnbmp_na == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(ns->state & NF_FreeClustersOutdate))
|
if (!(ns->state & NF_FreeClustersOutdate))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
buf = (unsigned char*)ntfs_malloc(vol->cluster_size);
|
buf = (unsigned char*)ntfs_malloc(vol->cluster_size);
|
||||||
if(!buf)goto exit;
|
if(!buf)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
while( pos < data->data_size)
|
while( pos < data->data_size) {
|
||||||
{
|
if( pos % vol->cluster_size == 0) {
|
||||||
if( pos % vol->cluster_size == 0)
|
readed = ntfs_attr_pread(vol->lcnbmp_na, pos,
|
||||||
{
|
min(data->data_size - pos, vol->cluster_size), buf);
|
||||||
readed = ntfs_attr_pread(vol->lcnbmp_na, pos, min(data->data_size - pos, vol->cluster_size), buf);
|
if(readed < B_NO_ERROR)
|
||||||
if(readed < B_NO_ERROR) goto error;
|
goto error;
|
||||||
if(readed != min(data->data_size - pos, vol->cluster_size))
|
if(readed != min(data->data_size - pos, vol->cluster_size))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_clusters += ntfs_count_bits( buf[pos%vol->cluster_size], min( (vol->nr_clusters) - (pos * 8), 8));
|
free_clusters += ntfs_count_bits( buf[pos%vol->cluster_size],
|
||||||
|
min( (vol->nr_clusters) - (pos * 8), 8));
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
error:
|
error:
|
||||||
if(buf)
|
free(buf);
|
||||||
free(buf);
|
|
||||||
exit:
|
exit:
|
||||||
ns->free_clusters = free_clusters;
|
ns->free_clusters = free_clusters;
|
||||||
ns->state &= ~(NF_FreeClustersOutdate);
|
ns->state &= ~(NF_FreeClustersOutdate);
|
||||||
|
|||||||
Reference in New Issue
Block a user