whitespace fixes - no code changes
parent
c59d76aed2
commit
8a584700c5
|
|
@ -1833,18 +1833,18 @@ typedef struct {
|
||||||
u64 offset_in_sds; /* Offset of the descriptor in SDS data stream */
|
u64 offset_in_sds; /* Offset of the descriptor in SDS data stream */
|
||||||
u32 size_in_sds; /* Size of the descriptor in SDS data stream */
|
u32 size_in_sds; /* Size of the descriptor in SDS data stream */
|
||||||
u64 reserved_II; /* Padding - always unicode "II" */
|
u64 reserved_II; /* Padding - always unicode "II" */
|
||||||
} __attribute__ ((__packed__)) SDH_INDEX_DATA;
|
} __attribute__((__packed__)) SDH_INDEX_DATA;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 hash; /* Hash of the security descriptor. */
|
u32 hash; /* Hash of the security descriptor. */
|
||||||
u32 security_id; /* The security_id assigned to the descriptor. */
|
u32 security_id; /* The security_id assigned to the descriptor. */
|
||||||
u64 offset_in_sds; /* Offset of the descriptor in SDS data stream */
|
u64 offset_in_sds; /* Offset of the descriptor in SDS data stream */
|
||||||
u32 size_in_sds; /* Size of the descriptor in SDS data stream */
|
u32 size_in_sds; /* Size of the descriptor in SDS data stream */
|
||||||
} __attribute__ ((__packed__)) SII_INDEX_DATA;
|
} __attribute__((__packed__)) SII_INDEX_DATA;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 owner_id;
|
u64 owner_id;
|
||||||
} __attribute__ ((__packed__)) QUOTA_O_INDEX_DATA;
|
} __attribute__((__packed__)) QUOTA_O_INDEX_DATA;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The $SDS data stream contains the security descriptors, aligned on 16-byte
|
* The $SDS data stream contains the security descriptors, aligned on 16-byte
|
||||||
|
|
|
||||||
|
|
@ -2046,7 +2046,7 @@ ascend:
|
||||||
//ntfs_log_debug("\tnode has %d children\n", suc->child_count);
|
//ntfs_log_debug("\tnode has %d children\n", suc->child_count);
|
||||||
|
|
||||||
// initialise new node
|
// initialise new node
|
||||||
// XXX ntfs_dt_initialise (new, vcn);
|
// XXX ntfs_dt_initialise(new, vcn);
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
/**
|
/**
|
||||||
* cluster_find
|
* cluster_find
|
||||||
*/
|
*/
|
||||||
int cluster_find (ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void *data)
|
int cluster_find(ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void *data)
|
||||||
{
|
{
|
||||||
u64 i;
|
u64 i;
|
||||||
int j;
|
int j;
|
||||||
|
|
@ -62,7 +62,7 @@ int cluster_find (ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void
|
||||||
|
|
||||||
// Quick check that at least one cluster is in use
|
// Quick check that at least one cluster is in use
|
||||||
for (i = c_begin; (LCN)i < c_end; i++) {
|
for (i = c_begin; (LCN)i < c_end; i++) {
|
||||||
if (utils_cluster_in_use (vol, i) == 1) {
|
if (utils_cluster_in_use(vol, i) == 1) {
|
||||||
in_use = 1;
|
in_use = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -70,44 +70,44 @@ int cluster_find (ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void
|
||||||
|
|
||||||
if (!in_use) {
|
if (!in_use) {
|
||||||
if (c_begin == c_end)
|
if (c_begin == c_end)
|
||||||
Vprintf ("cluster isn't in use\n");
|
Vprintf("cluster isn't in use\n");
|
||||||
else
|
else
|
||||||
Vprintf ("clusters aren't in use\n");
|
Vprintf("clusters aren't in use\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ctx = mft_get_search_ctx (vol);
|
m_ctx = mft_get_search_ctx(vol);
|
||||||
m_ctx->flags_search = FEMR_IN_USE | FEMR_BASE_RECORD;
|
m_ctx->flags_search = FEMR_IN_USE | FEMR_BASE_RECORD;
|
||||||
|
|
||||||
while (mft_next_record (m_ctx) == 0) {
|
while (mft_next_record(m_ctx) == 0) {
|
||||||
//Qprintf (RED "Inode: %llu\n" NORM, (unsigned long long)
|
//Qprintf(RED "Inode: %llu\n" NORM, (unsigned long long)
|
||||||
Qprintf ("Inode: %llu\n", (unsigned long long)
|
Qprintf("Inode: %llu\n", (unsigned long long)
|
||||||
m_ctx->inode->mft_no);
|
m_ctx->inode->mft_no);
|
||||||
|
|
||||||
if (!(m_ctx->flags_match & FEMR_BASE_RECORD))
|
if (!(m_ctx->flags_match & FEMR_BASE_RECORD))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Vprintf ("Inode: %llu\n", (unsigned long long)
|
Vprintf("Inode: %llu\n", (unsigned long long)
|
||||||
m_ctx->inode->mft_no);
|
m_ctx->inode->mft_no);
|
||||||
|
|
||||||
a_ctx = ntfs_attr_get_search_ctx (m_ctx->inode, NULL);
|
a_ctx = ntfs_attr_get_search_ctx(m_ctx->inode, NULL);
|
||||||
|
|
||||||
while ((rec = find_attribute (AT_UNUSED, a_ctx))) {
|
while ((rec = find_attribute(AT_UNUSED, a_ctx))) {
|
||||||
|
|
||||||
if (!rec->non_resident) {
|
if (!rec->non_resident) {
|
||||||
Vprintf ("0x%02x skipped - attr is resident\n", a_ctx->attr->type);
|
Vprintf("0x%02x skipped - attr is resident\n", a_ctx->attr->type);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
runs = ntfs_mapping_pairs_decompress (vol, a_ctx->attr, NULL);
|
runs = ntfs_mapping_pairs_decompress(vol, a_ctx->attr, NULL);
|
||||||
if (!runs) {
|
if (!runs) {
|
||||||
Eprintf ("Couldn't read the data runs.\n");
|
Eprintf("Couldn't read the data runs.\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vprintf ("\t[0x%02X]\n", a_ctx->attr->type);
|
Vprintf("\t[0x%02X]\n", a_ctx->attr->type);
|
||||||
|
|
||||||
Vprintf ("\t\tVCN\tLCN\tLength\n");
|
Vprintf("\t\tVCN\tLCN\tLength\n");
|
||||||
for (j = 0; runs[j].length > 0; j++) {
|
for (j = 0; runs[j].length > 0; j++) {
|
||||||
LCN a_begin = runs[j].lcn;
|
LCN a_begin = runs[j].lcn;
|
||||||
LCN a_end = a_begin + runs[j].length - 1;
|
LCN a_end = a_begin + runs[j].length - 1;
|
||||||
|
|
@ -115,7 +115,7 @@ int cluster_find (ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void
|
||||||
if (a_begin < 0)
|
if (a_begin < 0)
|
||||||
continue; // sparse, discontiguous, etc
|
continue; // sparse, discontiguous, etc
|
||||||
|
|
||||||
Vprintf ("\t\t%lld\t%lld-%lld (%lld)\n",
|
Vprintf("\t\t%lld\t%lld-%lld (%lld)\n",
|
||||||
(long long)runs[j].vcn,
|
(long long)runs[j].vcn,
|
||||||
(long long)runs[j].lcn,
|
(long long)runs[j].lcn,
|
||||||
(long long)(runs[j].lcn +
|
(long long)(runs[j].lcn +
|
||||||
|
|
@ -131,14 +131,14 @@ int cluster_find (ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_attr_put_search_ctx (a_ctx);
|
ntfs_attr_put_search_ctx(a_ctx);
|
||||||
a_ctx = NULL;
|
a_ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
done:
|
done:
|
||||||
ntfs_attr_put_search_ctx (a_ctx);
|
ntfs_attr_put_search_ctx(a_ctx);
|
||||||
mft_put_search_ctx (m_ctx);
|
mft_put_search_ctx(m_ctx);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ typedef struct {
|
||||||
int x;
|
int x;
|
||||||
} ntfs_cluster;
|
} ntfs_cluster;
|
||||||
|
|
||||||
typedef int (cluster_cb) (ntfs_inode *ino, ATTR_RECORD *attr, runlist_element *run, void *data);
|
typedef int (cluster_cb)(ntfs_inode *ino, ATTR_RECORD *attr, runlist_element *run, void *data);
|
||||||
|
|
||||||
int cluster_find (ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void *data);
|
int cluster_find(ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void *data);
|
||||||
|
|
||||||
#endif /* _CLUSTER_H_ */
|
#endif /* _CLUSTER_H_ */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ static void license(void)
|
||||||
/**
|
/**
|
||||||
* usage - print a list of the parameters to the program
|
* usage - print a list of the parameters to the program
|
||||||
*/
|
*/
|
||||||
__attribute__ ((noreturn))
|
__attribute__((noreturn))
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
copyright();
|
copyright();
|
||||||
|
|
@ -1486,7 +1486,7 @@ static int mkntfs_attr_find(const ATTR_TYPES type, const ntfschar *name,
|
||||||
*/
|
*/
|
||||||
static int mkntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
|
static int mkntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
|
||||||
const u32 name_len, const IGNORE_CASE_BOOL ic,
|
const u32 name_len, const IGNORE_CASE_BOOL ic,
|
||||||
const VCN lowest_vcn __attribute__ ((unused)), const u8 *val,
|
const VCN lowest_vcn __attribute__((unused)), const u8 *val,
|
||||||
const u32 val_len, ntfs_attr_search_ctx *ctx)
|
const u32 val_len, ntfs_attr_search_ctx *ctx)
|
||||||
{
|
{
|
||||||
ntfs_inode *base_ni;
|
ntfs_inode *base_ni;
|
||||||
|
|
@ -3064,7 +3064,7 @@ static int initialize_objid(MFT_RECORD *m, GUID guid, const MFT_REF mref) {
|
||||||
err = insert_index_entry_in_res_dir_index(idx_entry_o,
|
err = insert_index_entry_in_res_dir_index(idx_entry_o,
|
||||||
o_size, m,
|
o_size, m,
|
||||||
NTFS_INDEX_O, 2, AT_UNUSED);
|
NTFS_INDEX_O, 2, AT_UNUSED);
|
||||||
if (idx_entry_o) free (idx_entry_o);
|
if (idx_entry_o) free(idx_entry_o);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,10 @@
|
||||||
static const char *EXEC_NAME = "ntfscat";
|
static const char *EXEC_NAME = "ntfscat";
|
||||||
static struct options opts;
|
static struct options opts;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stderr, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stderr, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stderr, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stderr, &opts.quiet, FALSE)
|
||||||
static GEN_PRINTF (Printf, stderr, NULL, FALSE)
|
static GEN_PRINTF(Printf, stderr, NULL, FALSE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* version - Print version information about the program
|
* version - Print version information about the program
|
||||||
|
|
@ -62,7 +62,7 @@ static GEN_PRINTF (Printf, stderr, NULL, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
Printf("\n%s v%s (libntfs %s) - Concatenate files and print on the "
|
Printf("\n%s v%s (libntfs %s) - Concatenate files and print on the "
|
||||||
"standard output.\n\n", EXEC_NAME, VERSION,
|
"standard output.\n\n", EXEC_NAME, VERSION,
|
||||||
|
|
@ -78,7 +78,7 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
Printf ("\nUsage: %s [options] device [file]\n\n"
|
Printf ("\nUsage: %s [options] device [file]\n\n"
|
||||||
" -a, --attribute type Display this attribute type\n"
|
" -a, --attribute type Display this attribute type\n"
|
||||||
|
|
@ -106,7 +106,7 @@ static void usage (void)
|
||||||
* Return: 1 Success, a valid attribute name or number
|
* Return: 1 Success, a valid attribute name or number
|
||||||
* 0 Error, not an attribute name or number
|
* 0 Error, not an attribute name or number
|
||||||
*/
|
*/
|
||||||
static int parse_attribute (const char *value, ATTR_TYPES *attr)
|
static int parse_attribute(const char *value, ATTR_TYPES *attr)
|
||||||
{
|
{
|
||||||
static const char *attr_name[] = {
|
static const char *attr_name[] = {
|
||||||
"$STANDARD_INFORMATION",
|
"$STANDARD_INFORMATION",
|
||||||
|
|
@ -132,14 +132,14 @@ static int parse_attribute (const char *value, ATTR_TYPES *attr)
|
||||||
long num;
|
long num;
|
||||||
|
|
||||||
for (i = 0; attr_name[i]; i++) {
|
for (i = 0; attr_name[i]; i++) {
|
||||||
if ((strcmp (value, attr_name[i]) == 0) ||
|
if ((strcmp(value, attr_name[i]) == 0) ||
|
||||||
(strcmp (value, attr_name[i]+1) == 0)) {
|
(strcmp(value, attr_name[i]+1) == 0)) {
|
||||||
*attr = (ATTR_TYPES) ((i+1)*16);
|
*attr = (ATTR_TYPES) ((i+1)*16);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
num = strtol (value, NULL, 0);
|
num = strtol(value, NULL, 0);
|
||||||
if ((num > 0) && (num < 257)) {
|
if ((num > 0) && (num < 257)) {
|
||||||
*attr = (ATTR_TYPES) num;
|
*attr = (ATTR_TYPES) num;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -157,7 +157,7 @@ static int parse_attribute (const char *value, ATTR_TYPES *attr)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char **argv)
|
static int parse_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const char *sopt = "-a:fh?i:n:qVv";
|
static const char *sopt = "-a:fh?i:n:qVv";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -185,7 +185,7 @@ static int parse_options (int argc, char **argv)
|
||||||
opts.attr_name = NULL;
|
opts.attr_name = NULL;
|
||||||
opts.attr_name_len = 0;
|
opts.attr_name_len = 0;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!opts.device) {
|
if (!opts.device) {
|
||||||
|
|
@ -200,7 +200,7 @@ static int parse_options (int argc, char **argv)
|
||||||
case 'a':
|
case 'a':
|
||||||
if (opts.attr != (ATTR_TYPES)-1) {
|
if (opts.attr != (ATTR_TYPES)-1) {
|
||||||
Eprintf("You must specify exactly one attribute.\n");
|
Eprintf("You must specify exactly one attribute.\n");
|
||||||
} else if (parse_attribute (optarg, &attr) > 0) {
|
} else if (parse_attribute(optarg, &attr) > 0) {
|
||||||
opts.attr = attr;
|
opts.attr = attr;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -244,7 +244,7 @@ static int parse_options (int argc, char **argv)
|
||||||
opts.verbose++;
|
opts.verbose++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
|
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
|
||||||
err++;
|
err++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -254,16 +254,16 @@ static int parse_options (int argc, char **argv)
|
||||||
opts.quiet = 0;
|
opts.quiet = 0;
|
||||||
} else {
|
} else {
|
||||||
if (opts.device == NULL) {
|
if (opts.device == NULL) {
|
||||||
Eprintf ("You must specify a device.\n");
|
Eprintf("You must specify a device.\n");
|
||||||
err++;
|
err++;
|
||||||
|
|
||||||
} else if (opts.file == NULL && opts.inode == -1) {
|
} else if (opts.file == NULL && opts.inode == -1) {
|
||||||
Eprintf ("You must specify a file or inode "
|
Eprintf("You must specify a file or inode "
|
||||||
"with the -i option.\n");
|
"with the -i option.\n");
|
||||||
err++;
|
err++;
|
||||||
|
|
||||||
} else if (opts.file != NULL && opts.inode != -1) {
|
} else if (opts.file != NULL && opts.inode != -1) {
|
||||||
Eprintf ("You can't specify both a file and inode.\n");
|
Eprintf("You can't specify both a file and inode.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -291,12 +291,12 @@ static int parse_options (int argc, char **argv)
|
||||||
* Return: n Success, the INDX blocks are n bytes in size
|
* Return: n Success, the INDX blocks are n bytes in size
|
||||||
* 0 Error, not a directory
|
* 0 Error, not a directory
|
||||||
*/
|
*/
|
||||||
static int index_get_size (ntfs_inode *inode)
|
static int index_get_size(ntfs_inode *inode)
|
||||||
{
|
{
|
||||||
ATTR_RECORD *attr90;
|
ATTR_RECORD *attr90;
|
||||||
INDEX_ROOT *iroot;
|
INDEX_ROOT *iroot;
|
||||||
|
|
||||||
attr90 = find_first_attribute (AT_INDEX_ROOT, inode->mrec);
|
attr90 = find_first_attribute(AT_INDEX_ROOT, inode->mrec);
|
||||||
if (!attr90)
|
if (!attr90)
|
||||||
return 0; // not a directory
|
return 0; // not a directory
|
||||||
|
|
||||||
|
|
@ -308,7 +308,7 @@ static int index_get_size (ntfs_inode *inode)
|
||||||
/**
|
/**
|
||||||
* cat
|
* cat
|
||||||
*/
|
*/
|
||||||
static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
|
static int cat(ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
|
||||||
ntfschar *name, int namelen)
|
ntfschar *name, int namelen)
|
||||||
{
|
{
|
||||||
const int bufsize = 4096;
|
const int bufsize = 4096;
|
||||||
|
|
@ -318,21 +318,21 @@ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
|
||||||
s64 offset;
|
s64 offset;
|
||||||
u32 block_size;
|
u32 block_size;
|
||||||
|
|
||||||
buffer = malloc (bufsize);
|
buffer = malloc(bufsize);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
attr = ntfs_attr_open (inode, type, name, namelen);
|
attr = ntfs_attr_open(inode, type, name, namelen);
|
||||||
if (!attr) {
|
if (!attr) {
|
||||||
Eprintf ("Cannot find attribute type 0x%lx.\n", (long) type);
|
Eprintf("Cannot find attribute type 0x%lx.\n", (long) type);
|
||||||
free (buffer);
|
free(buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((inode->mft_no < 2) && (attr->type == AT_DATA))
|
if ((inode->mft_no < 2) && (attr->type == AT_DATA))
|
||||||
block_size = vol->mft_record_size;
|
block_size = vol->mft_record_size;
|
||||||
else if (attr->type == AT_INDEX_ALLOCATION)
|
else if (attr->type == AT_INDEX_ALLOCATION)
|
||||||
block_size = index_get_size (inode);
|
block_size = index_get_size(inode);
|
||||||
else
|
else
|
||||||
block_size = 0;
|
block_size = 0;
|
||||||
|
|
||||||
|
|
@ -343,26 +343,26 @@ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
|
||||||
bytes_read = ntfs_attr_mst_pread(attr, offset, 1, block_size, buffer);
|
bytes_read = ntfs_attr_mst_pread(attr, offset, 1, block_size, buffer);
|
||||||
bytes_read *= block_size;
|
bytes_read *= block_size;
|
||||||
} else {
|
} else {
|
||||||
bytes_read = ntfs_attr_pread (attr, offset, bufsize, buffer);
|
bytes_read = ntfs_attr_pread(attr, offset, bufsize, buffer);
|
||||||
}
|
}
|
||||||
//fprintf (stderr, "read %lld bytes\n", bytes_read);
|
//fprintf(stderr, "read %lld bytes\n", bytes_read);
|
||||||
if (bytes_read == -1) {
|
if (bytes_read == -1) {
|
||||||
perror ("ERROR: Couldn't read file");
|
perror("ERROR: Couldn't read file");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!bytes_read)
|
if (!bytes_read)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
written = fwrite (buffer, 1, bytes_read, stdout);
|
written = fwrite(buffer, 1, bytes_read, stdout);
|
||||||
if (written != bytes_read) {
|
if (written != bytes_read) {
|
||||||
perror ("ERROR: Couldn't output all data!");
|
perror("ERROR: Couldn't output all data!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
offset += bytes_read;
|
offset += bytes_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_attr_close (attr);
|
ntfs_attr_close(attr);
|
||||||
free (buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -374,28 +374,28 @@ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
|
||||||
* Return: 0 Success, the program worked
|
* Return: 0 Success, the program worked
|
||||||
* 1 Error, something went wrong
|
* 1 Error, something went wrong
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
ntfs_inode *inode;
|
ntfs_inode *inode;
|
||||||
ATTR_TYPES attr;
|
ATTR_TYPES attr;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
if (!parse_options (argc, argv))
|
if (!parse_options(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
utils_set_locale();
|
utils_set_locale();
|
||||||
|
|
||||||
vol = utils_mount_volume (opts.device, MS_RDONLY, opts.force);
|
vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
|
||||||
if (!vol) {
|
if (!vol) {
|
||||||
perror("ERROR: couldn't mount volume");
|
perror("ERROR: couldn't mount volume");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.inode != -1)
|
if (opts.inode != -1)
|
||||||
inode = ntfs_inode_open (vol, opts.inode);
|
inode = ntfs_inode_open(vol, opts.inode);
|
||||||
else
|
else
|
||||||
inode = ntfs_pathname_to_inode (vol, NULL, opts.file);
|
inode = ntfs_pathname_to_inode(vol, NULL, opts.file);
|
||||||
|
|
||||||
if (!inode) {
|
if (!inode) {
|
||||||
perror("ERROR: Couldn't open inode");
|
perror("ERROR: Couldn't open inode");
|
||||||
|
|
@ -408,8 +408,8 @@ int main (int argc, char *argv[])
|
||||||
|
|
||||||
result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len);
|
result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len);
|
||||||
|
|
||||||
ntfs_inode_close (inode);
|
ntfs_inode_close(inode);
|
||||||
ntfs_umount (vol, FALSE);
|
ntfs_umount(vol, FALSE);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ struct {
|
||||||
s64 device_size;
|
s64 device_size;
|
||||||
s64 nr_clusters;
|
s64 nr_clusters;
|
||||||
s64 inuse;
|
s64 inuse;
|
||||||
} __attribute__ ((__packed__)) image_hdr;
|
} __attribute__((__packed__)) image_hdr;
|
||||||
|
|
||||||
#define NTFS_MBYTE (1000 * 1000)
|
#define NTFS_MBYTE (1000 * 1000)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,9 @@
|
||||||
static const char *EXEC_NAME = "ntfscluster";
|
static const char *EXEC_NAME = "ntfscluster";
|
||||||
static struct options opts;
|
static struct options opts;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* version - Print version information about the program
|
* version - Print version information about the program
|
||||||
|
|
@ -64,13 +64,13 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
printf("\n%s v%s (libntfs %s) - Find the owner of any given sector or "
|
printf("\n%s v%s (libntfs %s) - Find the owner of any given sector or "
|
||||||
"cluster.\n\n", EXEC_NAME, VERSION,
|
"cluster.\n\n", EXEC_NAME, VERSION,
|
||||||
ntfs_libntfs_version());
|
ntfs_libntfs_version());
|
||||||
printf ("Copyright (c) 2002-2003 Richard Russon\n");
|
printf("Copyright (c) 2002-2003 Richard Russon\n");
|
||||||
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -80,9 +80,9 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf ("\nUsage: %s [options] device\n"
|
printf("\nUsage: %s [options] device\n"
|
||||||
" -i --info Print information about the volume (default)\n"
|
" -i --info Print information about the volume (default)\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -c range --cluster range Look for objects in this range of clusters\n"
|
" -c range --cluster range Look for objects in this range of clusters\n"
|
||||||
|
|
@ -97,7 +97,7 @@ static void usage (void)
|
||||||
" -V --version Version information\n"
|
" -V --version Version information\n"
|
||||||
" -h --help Print this help\n\n",
|
" -h --help Print this help\n\n",
|
||||||
EXEC_NAME);
|
EXEC_NAME);
|
||||||
printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
printf("%s%s\n", ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -109,7 +109,7 @@ static void usage (void)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char **argv)
|
static int parse_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const char *sopt = "-c:F:fh?I:ilqs:vV";
|
static const char *sopt = "-c:F:fh?I:ilqs:vV";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -139,7 +139,7 @@ static int parse_options (int argc, char **argv)
|
||||||
opts.range_begin = -1;
|
opts.range_begin = -1;
|
||||||
opts.range_end = -1;
|
opts.range_end = -1;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!opts.device) {
|
if (!opts.device) {
|
||||||
|
|
@ -152,7 +152,7 @@ static int parse_options (int argc, char **argv)
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
if ((opts.action == act_none) &&
|
if ((opts.action == act_none) &&
|
||||||
(utils_parse_range (optarg, &opts.range_begin, &opts.range_end, FALSE)))
|
(utils_parse_range(optarg, &opts.range_begin, &opts.range_end, FALSE)))
|
||||||
opts.action = act_cluster;
|
opts.action = act_cluster;
|
||||||
else
|
else
|
||||||
opts.action = act_error;
|
opts.action = act_error;
|
||||||
|
|
@ -175,7 +175,7 @@ static int parse_options (int argc, char **argv)
|
||||||
case 'I':
|
case 'I':
|
||||||
if (opts.action == act_none) {
|
if (opts.action == act_none) {
|
||||||
opts.action = act_inode;
|
opts.action = act_inode;
|
||||||
opts.inode = strtol (optarg, &end, 0);
|
opts.inode = strtol(optarg, &end, 0);
|
||||||
if (end && *end)
|
if (end && *end)
|
||||||
err++;
|
err++;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -199,7 +199,7 @@ static int parse_options (int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if ((opts.action == act_none) &&
|
if ((opts.action == act_none) &&
|
||||||
(utils_parse_range (optarg, &opts.range_begin, &opts.range_end, FALSE)))
|
(utils_parse_range(optarg, &opts.range_begin, &opts.range_end, FALSE)))
|
||||||
opts.action = act_sector;
|
opts.action = act_sector;
|
||||||
else
|
else
|
||||||
opts.action = act_error;
|
opts.action = act_error;
|
||||||
|
|
@ -212,9 +212,9 @@ static int parse_options (int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ((optopt == 'c') || (optopt == 's'))
|
if ((optopt == 'c') || (optopt == 's'))
|
||||||
Eprintf ("Option '%s' requires an argument.\n", argv[optind-1]);
|
Eprintf("Option '%s' requires an argument.\n", argv[optind-1]);
|
||||||
else
|
else
|
||||||
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
|
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
|
||||||
err++;
|
err++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -230,20 +230,20 @@ static int parse_options (int argc, char **argv)
|
||||||
|
|
||||||
if (opts.device == NULL) {
|
if (opts.device == NULL) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You must specify exactly one device.\n");
|
Eprintf("You must specify exactly one device.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.quiet && opts.verbose) {
|
if (opts.quiet && opts.verbose) {
|
||||||
Eprintf ("You may not use --quiet and --verbose at the same time.\n");
|
Eprintf("You may not use --quiet and --verbose at the same time.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.action == act_error) {
|
if (opts.action == act_error) {
|
||||||
Eprintf ("You may only specify one action: --info, --cluster, --sector or --last.\n");
|
Eprintf("You may only specify one action: --info, --cluster, --sector or --last.\n");
|
||||||
err++;
|
err++;
|
||||||
} else if (opts.range_begin > opts.range_end) {
|
} else if (opts.range_begin > opts.range_end) {
|
||||||
Eprintf ("The range must be in ascending order.\n");
|
Eprintf("The range must be in ascending order.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +260,7 @@ static int parse_options (int argc, char **argv)
|
||||||
/**
|
/**
|
||||||
* info
|
* info
|
||||||
*/
|
*/
|
||||||
static int info (ntfs_volume *vol)
|
static int info(ntfs_volume *vol)
|
||||||
{
|
{
|
||||||
u64 a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u;
|
u64 a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u;
|
||||||
int cb, sb, cps;
|
int cb, sb, cps;
|
||||||
|
|
@ -273,23 +273,23 @@ static int info (ntfs_volume *vol)
|
||||||
int z;
|
int z;
|
||||||
int inuse = 0;
|
int inuse = 0;
|
||||||
|
|
||||||
m_ctx = mft_get_search_ctx (vol);
|
m_ctx = mft_get_search_ctx(vol);
|
||||||
m_ctx->flags_search = FEMR_IN_USE | FEMR_METADATA | FEMR_BASE_RECORD | FEMR_NOT_BASE_RECORD;
|
m_ctx->flags_search = FEMR_IN_USE | FEMR_METADATA | FEMR_BASE_RECORD | FEMR_NOT_BASE_RECORD;
|
||||||
while (mft_next_record (m_ctx) == 0) {
|
while (mft_next_record(m_ctx) == 0) {
|
||||||
|
|
||||||
if (!(m_ctx->flags_match & FEMR_IN_USE))
|
if (!(m_ctx->flags_match & FEMR_IN_USE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
inuse++;
|
inuse++;
|
||||||
|
|
||||||
a_ctx = ntfs_attr_get_search_ctx (m_ctx->inode, NULL);
|
a_ctx = ntfs_attr_get_search_ctx(m_ctx->inode, NULL);
|
||||||
|
|
||||||
while ((rec = find_attribute (AT_UNUSED, a_ctx))) {
|
while ((rec = find_attribute(AT_UNUSED, a_ctx))) {
|
||||||
|
|
||||||
if (!rec->non_resident)
|
if (!rec->non_resident)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
rl = ntfs_mapping_pairs_decompress (vol, rec, NULL);
|
rl = ntfs_mapping_pairs_decompress(vol, rec, NULL);
|
||||||
|
|
||||||
for (z = 0; rl[z].length > 0; z++)
|
for (z = 0; rl[z].length > 0; z++)
|
||||||
{
|
{
|
||||||
|
|
@ -302,12 +302,12 @@ static int info (ntfs_volume *vol)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free (rl);
|
free(rl);
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_attr_put_search_ctx (a_ctx);
|
ntfs_attr_put_search_ctx(a_ctx);
|
||||||
}
|
}
|
||||||
mft_put_search_ctx (m_ctx);
|
mft_put_search_ctx(m_ctx);
|
||||||
|
|
||||||
cb = vol->cluster_size_bits;
|
cb = vol->cluster_size_bits;
|
||||||
sb = vol->sector_size_bits;
|
sb = vol->sector_size_bits;
|
||||||
|
|
@ -340,27 +340,27 @@ static int info (ntfs_volume *vol)
|
||||||
t = mc >> cb;
|
t = mc >> cb;
|
||||||
u = mc * 100 / b / e;
|
u = mc * 100 / b / e;
|
||||||
|
|
||||||
printf ("bytes per sector : %llu\n", (unsigned long long)a);
|
printf("bytes per sector : %llu\n", (unsigned long long)a);
|
||||||
printf ("bytes per cluster : %llu\n", (unsigned long long)b);
|
printf("bytes per cluster : %llu\n", (unsigned long long)b);
|
||||||
printf ("sectors per cluster : %llu\n", (unsigned long long)c);
|
printf("sectors per cluster : %llu\n", (unsigned long long)c);
|
||||||
printf ("bytes per volume : %llu\n", (unsigned long long)d);
|
printf("bytes per volume : %llu\n", (unsigned long long)d);
|
||||||
printf ("sectors per volume : %llu\n", (unsigned long long)e);
|
printf("sectors per volume : %llu\n", (unsigned long long)e);
|
||||||
printf ("clusters per volume : %llu\n", (unsigned long long)f);
|
printf("clusters per volume : %llu\n", (unsigned long long)f);
|
||||||
printf ("initialized mft records : %llu\n", (unsigned long long)g);
|
printf("initialized mft records : %llu\n", (unsigned long long)g);
|
||||||
printf ("mft records in use : %llu\n", (unsigned long long)h);
|
printf("mft records in use : %llu\n", (unsigned long long)h);
|
||||||
printf ("mft records percentage : %llu\n", (unsigned long long)i);
|
printf("mft records percentage : %llu\n", (unsigned long long)i);
|
||||||
printf ("bytes of free space : %llu\n", (unsigned long long)j);
|
printf("bytes of free space : %llu\n", (unsigned long long)j);
|
||||||
printf ("sectors of free space : %llu\n", (unsigned long long)k);
|
printf("sectors of free space : %llu\n", (unsigned long long)k);
|
||||||
printf ("clusters of free space : %llu\n", (unsigned long long)l);
|
printf("clusters of free space : %llu\n", (unsigned long long)l);
|
||||||
printf ("percentage free space : %llu\n", (unsigned long long)m);
|
printf("percentage free space : %llu\n", (unsigned long long)m);
|
||||||
printf ("bytes of user data : %llu\n", (unsigned long long)n);
|
printf("bytes of user data : %llu\n", (unsigned long long)n);
|
||||||
printf ("sectors of user data : %llu\n", (unsigned long long)o);
|
printf("sectors of user data : %llu\n", (unsigned long long)o);
|
||||||
printf ("clusters of user data : %llu\n", (unsigned long long)p);
|
printf("clusters of user data : %llu\n", (unsigned long long)p);
|
||||||
printf ("percentage user data : %llu\n", (unsigned long long)q);
|
printf("percentage user data : %llu\n", (unsigned long long)q);
|
||||||
printf ("bytes of metadata : %llu\n", (unsigned long long)r);
|
printf("bytes of metadata : %llu\n", (unsigned long long)r);
|
||||||
printf ("sectors of metadata : %llu\n", (unsigned long long)s);
|
printf("sectors of metadata : %llu\n", (unsigned long long)s);
|
||||||
printf ("clusters of metadata : %llu\n", (unsigned long long)t);
|
printf("clusters of metadata : %llu\n", (unsigned long long)t);
|
||||||
printf ("percentage metadata : %llu\n", (unsigned long long)u);
|
printf("percentage metadata : %llu\n", (unsigned long long)u);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -368,7 +368,7 @@ static int info (ntfs_volume *vol)
|
||||||
/**
|
/**
|
||||||
* dump_file
|
* dump_file
|
||||||
*/
|
*/
|
||||||
static int dump_file (ntfs_volume *vol, ntfs_inode *ino)
|
static int dump_file(ntfs_volume *vol, ntfs_inode *ino)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
ntfs_attr_search_ctx *ctx;
|
ntfs_attr_search_ctx *ctx;
|
||||||
|
|
@ -376,41 +376,41 @@ static int dump_file (ntfs_volume *vol, ntfs_inode *ino)
|
||||||
int i;
|
int i;
|
||||||
runlist *runs;
|
runlist *runs;
|
||||||
|
|
||||||
utils_inode_get_name (ino, buffer, sizeof (buffer));
|
utils_inode_get_name(ino, buffer, sizeof(buffer));
|
||||||
|
|
||||||
printf ("Dump: %s\n", buffer);
|
printf("Dump: %s\n", buffer);
|
||||||
|
|
||||||
ctx = ntfs_attr_get_search_ctx (ino, NULL);
|
ctx = ntfs_attr_get_search_ctx(ino, NULL);
|
||||||
|
|
||||||
while ((rec = find_attribute (AT_UNUSED, ctx))) {
|
while ((rec = find_attribute(AT_UNUSED, ctx))) {
|
||||||
printf (" 0x%02x - ", rec->type);
|
printf(" 0x%02x - ", rec->type);
|
||||||
if (rec->non_resident) {
|
if (rec->non_resident) {
|
||||||
printf ("non-resident\n");
|
printf("non-resident\n");
|
||||||
runs = ntfs_mapping_pairs_decompress (vol, rec, NULL);
|
runs = ntfs_mapping_pairs_decompress(vol, rec, NULL);
|
||||||
if (runs) {
|
if (runs) {
|
||||||
printf (" VCN LCN Length\n");
|
printf(" VCN LCN Length\n");
|
||||||
for (i = 0; runs[i].length > 0; i++) {
|
for (i = 0; runs[i].length > 0; i++) {
|
||||||
printf (" %8lld %8lld %8lld\n",
|
printf(" %8lld %8lld %8lld\n",
|
||||||
(long long)runs[i].vcn,
|
(long long)runs[i].vcn,
|
||||||
(long long)runs[i].lcn,
|
(long long)runs[i].lcn,
|
||||||
(long long)
|
(long long)
|
||||||
runs[i].length);
|
runs[i].length);
|
||||||
}
|
}
|
||||||
free (runs);
|
free(runs);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf ("resident\n");
|
printf("resident\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_attr_put_search_ctx (ctx);
|
ntfs_attr_put_search_ctx(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print_match
|
* print_match
|
||||||
*/
|
*/
|
||||||
static int print_match (ntfs_inode *ino, ATTR_RECORD *attr,
|
static int print_match(ntfs_inode *ino, ATTR_RECORD *attr,
|
||||||
runlist_element *run, void *data __attribute__((unused)))
|
runlist_element *run, void *data __attribute__((unused)))
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
|
@ -418,26 +418,26 @@ static int print_match (ntfs_inode *ino, ATTR_RECORD *attr,
|
||||||
if (!ino || !attr || !run)
|
if (!ino || !attr || !run)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
buffer = malloc (MAX_PATH);
|
buffer = malloc(MAX_PATH);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
Eprintf ("!buffer\n");
|
Eprintf("!buffer\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
utils_inode_get_name (ino, buffer, MAX_PATH);
|
utils_inode_get_name(ino, buffer, MAX_PATH);
|
||||||
printf ("Inode %llu %s", (unsigned long long)ino->mft_no, buffer);
|
printf("Inode %llu %s", (unsigned long long)ino->mft_no, buffer);
|
||||||
|
|
||||||
utils_attr_get_name (ino->vol, attr, buffer, MAX_PATH);
|
utils_attr_get_name(ino->vol, attr, buffer, MAX_PATH);
|
||||||
printf ("/%s\n", buffer);
|
printf("/%s\n", buffer);
|
||||||
|
|
||||||
free (buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* find_last
|
* find_last
|
||||||
*/
|
*/
|
||||||
static int find_last (ntfs_inode *ino, ATTR_RECORD *attr, runlist_element *run,
|
static int find_last(ntfs_inode *ino, ATTR_RECORD *attr, runlist_element *run,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
struct match *m;
|
struct match *m;
|
||||||
|
|
@ -463,68 +463,68 @@ static int find_last (ntfs_inode *ino, ATTR_RECORD *attr, runlist_element *run,
|
||||||
* Return: 0 Success, the program worked
|
* Return: 0 Success, the program worked
|
||||||
* 1 Error, something went wrong
|
* 1 Error, something went wrong
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
ntfs_inode *ino = NULL;
|
ntfs_inode *ino = NULL;
|
||||||
struct match m;
|
struct match m;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
if (!parse_options (argc, argv))
|
if (!parse_options(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
utils_set_locale();
|
utils_set_locale();
|
||||||
|
|
||||||
vol = utils_mount_volume (opts.device, MS_RDONLY, opts.force);
|
vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
|
||||||
if (!vol)
|
if (!vol)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
switch (opts.action) {
|
switch (opts.action) {
|
||||||
case act_sector:
|
case act_sector:
|
||||||
if (opts.range_begin == opts.range_end)
|
if (opts.range_begin == opts.range_end)
|
||||||
Qprintf ("Searching for sector %llu\n",
|
Qprintf("Searching for sector %llu\n",
|
||||||
(unsigned long long)opts.range_begin);
|
(unsigned long long)opts.range_begin);
|
||||||
else
|
else
|
||||||
Qprintf ("Searching for sector range %llu-%llu\n", (unsigned long long)opts.range_begin, (unsigned long long)opts.range_end);
|
Qprintf("Searching for sector range %llu-%llu\n", (unsigned long long)opts.range_begin, (unsigned long long)opts.range_end);
|
||||||
/* Convert to clusters */
|
/* Convert to clusters */
|
||||||
opts.range_begin >>= (vol->cluster_size_bits - vol->sector_size_bits);
|
opts.range_begin >>= (vol->cluster_size_bits - vol->sector_size_bits);
|
||||||
opts.range_end >>= (vol->cluster_size_bits - vol->sector_size_bits);
|
opts.range_end >>= (vol->cluster_size_bits - vol->sector_size_bits);
|
||||||
result = cluster_find (vol, opts.range_begin, opts.range_end, (cluster_cb*)&print_match, NULL);
|
result = cluster_find(vol, opts.range_begin, opts.range_end, (cluster_cb*)&print_match, NULL);
|
||||||
break;
|
break;
|
||||||
case act_cluster:
|
case act_cluster:
|
||||||
if (opts.range_begin == opts.range_end)
|
if (opts.range_begin == opts.range_end)
|
||||||
Qprintf ("Searching for cluster %llu\n",
|
Qprintf("Searching for cluster %llu\n",
|
||||||
(unsigned long long)opts.range_begin);
|
(unsigned long long)opts.range_begin);
|
||||||
else
|
else
|
||||||
Qprintf ("Searching for cluster range %llu-%llu\n", (unsigned long long)opts.range_begin, (unsigned long long)opts.range_end);
|
Qprintf("Searching for cluster range %llu-%llu\n", (unsigned long long)opts.range_begin, (unsigned long long)opts.range_end);
|
||||||
result = cluster_find (vol, opts.range_begin, opts.range_end, (cluster_cb*)&print_match, NULL);
|
result = cluster_find(vol, opts.range_begin, opts.range_end, (cluster_cb*)&print_match, NULL);
|
||||||
break;
|
break;
|
||||||
case act_file:
|
case act_file:
|
||||||
ino = ntfs_pathname_to_inode(vol, NULL, opts.filename);
|
ino = ntfs_pathname_to_inode(vol, NULL, opts.filename);
|
||||||
if (ino)
|
if (ino)
|
||||||
result = dump_file (vol, ino);
|
result = dump_file(vol, ino);
|
||||||
break;
|
break;
|
||||||
case act_inode:
|
case act_inode:
|
||||||
ino = ntfs_inode_open (vol, opts.inode);
|
ino = ntfs_inode_open(vol, opts.inode);
|
||||||
if (ino) {
|
if (ino) {
|
||||||
result = dump_file (vol, ino);
|
result = dump_file(vol, ino);
|
||||||
ntfs_inode_close (ino);
|
ntfs_inode_close(ino);
|
||||||
} else {
|
} else {
|
||||||
Eprintf ("Cannot open inode %llu\n",
|
Eprintf("Cannot open inode %llu\n",
|
||||||
(unsigned long long)opts.inode);
|
(unsigned long long)opts.inode);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case act_last:
|
case act_last:
|
||||||
memset (&m, 0, sizeof (m));
|
memset(&m, 0, sizeof(m));
|
||||||
m.lcn = -1;
|
m.lcn = -1;
|
||||||
result = cluster_find (vol, 0, LONG_MAX, (cluster_cb*)&find_last, &m);
|
result = cluster_find(vol, 0, LONG_MAX, (cluster_cb*)&find_last, &m);
|
||||||
if (m.lcn >= 0) {
|
if (m.lcn >= 0) {
|
||||||
ino = ntfs_inode_open (vol, m.inum);
|
ino = ntfs_inode_open(vol, m.inum);
|
||||||
if (ino) {
|
if (ino) {
|
||||||
result = dump_file (vol, ino);
|
result = dump_file(vol, ino);
|
||||||
ntfs_inode_close (ino);
|
ntfs_inode_close(ino);
|
||||||
} else {
|
} else {
|
||||||
Eprintf ("Cannot open inode %llu\n",
|
Eprintf("Cannot open inode %llu\n",
|
||||||
(unsigned long long)
|
(unsigned long long)
|
||||||
opts.inode);
|
opts.inode);
|
||||||
}
|
}
|
||||||
|
|
@ -535,11 +535,11 @@ int main (int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case act_info:
|
case act_info:
|
||||||
default:
|
default:
|
||||||
result = info (vol);
|
result = info(vol);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_umount (vol, FALSE);
|
ntfs_umount(vol, FALSE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ __attribute__((noreturn))
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
printf ("\nUsage: %s [OPTIONS] DEVICE1 DEVICE2\n"
|
printf("\nUsage: %s [OPTIONS] DEVICE1 DEVICE2\n"
|
||||||
" Compare two NTFS volumes and tell the differences.\n"
|
" Compare two NTFS volumes and tell the differences.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -P, --no-progress-bar Don't show progress bar\n"
|
" -P, --no-progress-bar Don't show progress bar\n"
|
||||||
|
|
@ -163,7 +163,7 @@ static void usage(void)
|
||||||
" -d, --debug Show debug information\n"
|
" -d, --debug Show debug information\n"
|
||||||
#endif
|
#endif
|
||||||
"\n", EXEC_NAME);
|
"\n", EXEC_NAME);
|
||||||
printf ("%s%s", ntfs_bugs, ntfs_home);
|
printf("%s%s", ntfs_bugs, ntfs_home);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,7 +186,7 @@ static void parse_options(int argc, char **argv)
|
||||||
memset(&opt, 0, sizeof(opt));
|
memset(&opt, 0, sizeof(opt));
|
||||||
opt.show_progress = 1;
|
opt.show_progress = 1;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!opt.vol1) {
|
if (!opt.vol1) {
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,10 @@ static const char *EXEC_NAME = "ntfscp";
|
||||||
static struct options opts;
|
static struct options opts;
|
||||||
volatile sig_atomic_t caught_terminate = 0;
|
volatile sig_atomic_t caught_terminate = 0;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stderr, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stderr, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stderr, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stderr, &opts.quiet, FALSE)
|
||||||
static GEN_PRINTF (Printf, stderr, NULL, FALSE)
|
static GEN_PRINTF(Printf, stderr, NULL, FALSE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* version - Print version information about the program
|
* version - Print version information about the program
|
||||||
|
|
@ -81,12 +81,12 @@ static GEN_PRINTF (Printf, stderr, NULL, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
Printf("\n%s v%s (libntfs %s) - Overwrite files on NTFS volume.\n\n",
|
Printf("\n%s v%s (libntfs %s) - Overwrite files on NTFS volume.\n\n",
|
||||||
EXEC_NAME, VERSION, ntfs_libntfs_version());
|
EXEC_NAME, VERSION, ntfs_libntfs_version());
|
||||||
Printf ("Copyright (c) 2004-2005 Yura Pakhuchiy\n");
|
Printf("Copyright (c) 2004-2005 Yura Pakhuchiy\n");
|
||||||
Printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
Printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,9 +96,9 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
Printf ("\nUsage: %s [options] device src_file dest_file\n\n"
|
Printf("\nUsage: %s [options] device src_file dest_file\n\n"
|
||||||
" -a --attribute num Write to this attribute\n"
|
" -a --attribute num Write to this attribute\n"
|
||||||
" -i --inode Treat dest_file as inode number\n"
|
" -i --inode Treat dest_file as inode number\n"
|
||||||
" -f --force Use less caution\n"
|
" -f --force Use less caution\n"
|
||||||
|
|
@ -109,7 +109,7 @@ static void usage (void)
|
||||||
" -V --version Version information\n"
|
" -V --version Version information\n"
|
||||||
" -v --verbose More output\n\n",
|
" -v --verbose More output\n\n",
|
||||||
EXEC_NAME);
|
EXEC_NAME);
|
||||||
Printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
Printf("%s%s\n", ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -121,7 +121,7 @@ static void usage (void)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char **argv)
|
static int parse_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const char *sopt = "-a:ifh?N:nqVv";
|
static const char *sopt = "-a:ifh?N:nqVv";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -263,7 +263,7 @@ static void signal_handler(int arg __attribute__((unused)))
|
||||||
* Return: 0 Success, the program worked
|
* Return: 0 Success, the program worked
|
||||||
* 1 Error, something went wrong
|
* 1 Error, something went wrong
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *in;
|
FILE *in;
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
|
|
@ -308,7 +308,7 @@ int main (int argc, char *argv[])
|
||||||
|
|
||||||
{
|
{
|
||||||
struct stat fst;
|
struct stat fst;
|
||||||
if (stat (opts.src_file, &fst) == -1) {
|
if (stat(opts.src_file, &fst) == -1) {
|
||||||
perror("ERROR: Couldn't stat source file");
|
perror("ERROR: Couldn't stat source file");
|
||||||
goto umount;
|
goto umount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ typedef struct {
|
||||||
};
|
};
|
||||||
} logfile_file;
|
} logfile_file;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* logfile_close
|
* logfile_close
|
||||||
|
|
@ -120,8 +120,8 @@ static int logfile_close(logfile_file *logfile)
|
||||||
* Use when you wish to exit and collate all the cleanups together.
|
* Use when you wish to exit and collate all the cleanups together.
|
||||||
* if you don't have some parameter to pass, just pass NULL.
|
* if you don't have some parameter to pass, just pass NULL.
|
||||||
*/
|
*/
|
||||||
__attribute__ ((noreturn))
|
__attribute__((noreturn))
|
||||||
__attribute__ ((format(printf, 4, 5)))
|
__attribute__((format(printf, 4, 5)))
|
||||||
static void device_err_exit(ntfs_volume *vol, ntfs_inode *ni,
|
static void device_err_exit(ntfs_volume *vol, ntfs_inode *ni,
|
||||||
ntfs_attr *na, const char *fmt, ...)
|
ntfs_attr *na, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +147,7 @@ static void device_err_exit(ntfs_volume *vol, ntfs_inode *ni,
|
||||||
/**
|
/**
|
||||||
* log_err_exit -
|
* log_err_exit -
|
||||||
*/
|
*/
|
||||||
__attribute__ ((noreturn))
|
__attribute__((noreturn))
|
||||||
__attribute__((format(printf, 2, 3)))
|
__attribute__((format(printf, 2, 3)))
|
||||||
static void log_err_exit(u8 *buf, const char *fmt, ...)
|
static void log_err_exit(u8 *buf, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +167,7 @@ static void log_err_exit(u8 *buf, const char *fmt, ...)
|
||||||
/**
|
/**
|
||||||
* usage -
|
* usage -
|
||||||
*/
|
*/
|
||||||
__attribute__ ((noreturn))
|
__attribute__((noreturn))
|
||||||
static void usage(const char *exec_name)
|
static void usage(const char *exec_name)
|
||||||
{
|
{
|
||||||
Eprintf("%s v%s (libntfs %s) - Interpret and display information "
|
Eprintf("%s v%s (libntfs %s) - Interpret and display information "
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ static void parse_options(int argc, char **argv)
|
||||||
|
|
||||||
memset(&opt, 0, sizeof(opt));
|
memset(&opt, 0, sizeof(opt));
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!opt.volume)
|
if (!opt.volume)
|
||||||
|
|
|
||||||
|
|
@ -92,9 +92,9 @@ static struct options {
|
||||||
u8 padding[4]; /* Unused: padding to 64 bit. */
|
u8 padding[4]; /* Unused: padding to 64 bit. */
|
||||||
} opts;
|
} opts;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* version - Print version information about the program
|
* version - Print version information about the program
|
||||||
|
|
@ -103,18 +103,18 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
printf ("\n%s v%s (libntfs %s) - Display information about an NTFS "
|
printf("\n%s v%s (libntfs %s) - Display information about an NTFS "
|
||||||
"Volume.\n\n", EXEC_NAME, VERSION,
|
"Volume.\n\n", EXEC_NAME, VERSION,
|
||||||
ntfs_libntfs_version());
|
ntfs_libntfs_version());
|
||||||
printf ("Copyright (c)\n");
|
printf("Copyright (c)\n");
|
||||||
printf (" 2002-2004 Matthew J. Fanto\n");
|
printf(" 2002-2004 Matthew J. Fanto\n");
|
||||||
printf (" 2002-2005 Anton Altaparmakov\n");
|
printf(" 2002-2005 Anton Altaparmakov\n");
|
||||||
printf (" 2002-2003 Richard Russon\n");
|
printf(" 2002-2003 Richard Russon\n");
|
||||||
printf (" 2003 Leonard Norrgård\n");
|
printf(" 2003 Leonard Norrgård\n");
|
||||||
printf (" 2004-2005 Yura Pakhuchiy\n");
|
printf(" 2004-2005 Yura Pakhuchiy\n");
|
||||||
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -124,9 +124,9 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf ("\nUsage: %s [options] -d dev\n"
|
printf("\nUsage: %s [options] -d dev\n"
|
||||||
" -d dev --device dev The ntfs volume to display information about\n"
|
" -d dev --device dev The ntfs volume to display information about\n"
|
||||||
" -i num --inode num Display information about this inode\n"
|
" -i num --inode num Display information about this inode\n"
|
||||||
" -F file --file file Display information about this file (absolute path)\n"
|
" -F file --file file Display information about this file (absolute path)\n"
|
||||||
|
|
@ -139,7 +139,7 @@ static void usage (void)
|
||||||
" -V --version Display version information\n"
|
" -V --version Display version information\n"
|
||||||
" -h --help Display this help\n\n",
|
" -h --help Display this help\n\n",
|
||||||
EXEC_NAME);
|
EXEC_NAME);
|
||||||
printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
printf("%s%s\n", ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -151,7 +151,7 @@ static void usage (void)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char *argv[])
|
static int parse_options(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static const char *sopt = "-:fhi:F:mqtTvVd:";
|
static const char *sopt = "-:fhi:F:mqtTvVd:";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -178,7 +178,7 @@ static int parse_options (int argc, char *argv[])
|
||||||
opts.inode = -1;
|
opts.inode = -1;
|
||||||
opts.filename = NULL;
|
opts.filename = NULL;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
||||||
ntfs_log_trace("optind=%d; c='%c' optarg=\"%s\".\n", optind, c,
|
ntfs_log_trace("optind=%d; c='%c' optarg=\"%s\".\n", optind, c,
|
||||||
optarg);
|
optarg);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
@ -190,7 +190,7 @@ static int parse_options (int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
if ((opts.inode != -1) ||
|
if ((opts.inode != -1) ||
|
||||||
(!utils_parse_size (optarg, &opts.inode, FALSE))) {
|
(!utils_parse_size(optarg, &opts.inode, FALSE))) {
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -217,7 +217,7 @@ static int parse_options (int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
/* 'T' is deprecated, notify */
|
/* 'T' is deprecated, notify */
|
||||||
Eprintf ("Option 'T' is deprecated, it was replaced by 't'.\n");
|
Eprintf("Option 'T' is deprecated, it was replaced by 't'.\n");
|
||||||
err++;
|
err++;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
|
|
@ -257,24 +257,24 @@ static int parse_options (int argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
if (opts.device == NULL) {
|
if (opts.device == NULL) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You must specify exactly one device.\n");
|
Eprintf("You must specify exactly one device.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((opts.inode == -1) && (opts.filename == NULL) && !opts.mft) {
|
if ((opts.inode == -1) && (opts.filename == NULL) && !opts.mft) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You must specify an inode to learn about.\n");
|
Eprintf("You must specify an inode to learn about.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.quiet && opts.verbose) {
|
if (opts.quiet && opts.verbose) {
|
||||||
Eprintf ("You may not use --quiet and --verbose at the same time.\n");
|
Eprintf("You may not use --quiet and --verbose at the same time.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((opts.inode != -1) && (opts.filename != NULL)) {
|
if ((opts.inode != -1) && (opts.filename != NULL)) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You may not specify --inode and --file together.\n");
|
Eprintf("You may not specify --inode and --file together.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1078,13 +1078,13 @@ static void ntfs_dump_attr_data(ATTR_RECORD *attr, ntfs_volume *vol)
|
||||||
runlist *rl = ntfs_mapping_pairs_decompress(vol, attr, 0);
|
runlist *rl = ntfs_mapping_pairs_decompress(vol, attr, 0);
|
||||||
if (rl) {
|
if (rl) {
|
||||||
runlist *rlc = rl;
|
runlist *rlc = rl;
|
||||||
printf ("\tRunlist:\tVCN\t\tLCN\t\tLength\n");
|
printf("\tRunlist:\tVCN\t\tLCN\t\tLength\n");
|
||||||
while (rlc->length) {
|
while (rlc->length) {
|
||||||
printf ("\t\t\t%lld\t\t%lld\t\t%lld\n",
|
printf("\t\t\t%lld\t\t%lld\t\t%lld\n",
|
||||||
rlc->vcn, rlc->lcn, rlc->length);
|
rlc->vcn, rlc->lcn, rlc->length);
|
||||||
rlc++;
|
rlc++;
|
||||||
}
|
}
|
||||||
free (rl);
|
free(rl);
|
||||||
} else {
|
} else {
|
||||||
Eprintf("ntfsinfo error: could not decompress runlist\n");
|
Eprintf("ntfsinfo error: could not decompress runlist\n");
|
||||||
return;
|
return;
|
||||||
|
|
@ -1872,12 +1872,12 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
|
|
||||||
if (!parse_options (argc, argv))
|
if (!parse_options(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
utils_set_locale();
|
utils_set_locale();
|
||||||
|
|
||||||
vol = utils_mount_volume (opts.device, MS_RDONLY, opts.force);
|
vol = utils_mount_volume(opts.device, MS_RDONLY, opts.force);
|
||||||
if (!vol)
|
if (!vol)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
@ -1913,7 +1913,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_umount (vol, FALSE);
|
ntfs_umount(vol, FALSE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,9 @@ static struct options {
|
||||||
int noaction; /* Do not write to disk */
|
int noaction; /* Do not write to disk */
|
||||||
} opts;
|
} opts;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* version - Print version information about the program
|
* version - Print version information about the program
|
||||||
|
|
@ -71,16 +71,16 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
printf ("\n%s v%s (libntfs %s) - Display, or set, the label for an "
|
printf("\n%s v%s (libntfs %s) - Display, or set, the label for an "
|
||||||
"NTFS Volume.\n\n", EXEC_NAME, VERSION,
|
"NTFS Volume.\n\n", EXEC_NAME, VERSION,
|
||||||
ntfs_libntfs_version());
|
ntfs_libntfs_version());
|
||||||
printf ("Copyright (c)\n");
|
printf("Copyright (c)\n");
|
||||||
printf (" 2002 Matthew J. Fanto\n");
|
printf(" 2002 Matthew J. Fanto\n");
|
||||||
printf (" 2002-2005 Anton Altaparmakov\n");
|
printf(" 2002-2005 Anton Altaparmakov\n");
|
||||||
printf (" 2002-2003 Richard Russon\n");
|
printf(" 2002-2003 Richard Russon\n");
|
||||||
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -90,9 +90,9 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf ("\nUsage: %s [options] device [label]\n"
|
printf("\nUsage: %s [options] device [label]\n"
|
||||||
" -n --no-action Do not write to disk\n"
|
" -n --no-action Do not write to disk\n"
|
||||||
" -f --force Use less caution\n"
|
" -f --force Use less caution\n"
|
||||||
" -q --quiet Less output\n"
|
" -q --quiet Less output\n"
|
||||||
|
|
@ -100,7 +100,7 @@ static void usage (void)
|
||||||
" -V --version Display version information\n"
|
" -V --version Display version information\n"
|
||||||
" -h --help Display this help\n\n",
|
" -h --help Display this help\n\n",
|
||||||
EXEC_NAME);
|
EXEC_NAME);
|
||||||
printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
printf("%s%s\n", ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -112,7 +112,7 @@ static void usage (void)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char *argv[])
|
static int parse_options(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
static const char *sopt = "-fh?nqvV";
|
static const char *sopt = "-fh?nqvV";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -132,7 +132,7 @@ static int parse_options (int argc, char *argv[])
|
||||||
|
|
||||||
opterr = 0; /* We'll handle the errors, thank you. */
|
opterr = 0; /* We'll handle the errors, thank you. */
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!err && !opts.device)
|
if (!err && !opts.device)
|
||||||
|
|
@ -162,7 +162,7 @@ static int parse_options (int argc, char *argv[])
|
||||||
ver++;
|
ver++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
|
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
|
||||||
err++;
|
err++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -173,12 +173,12 @@ static int parse_options (int argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
if (opts.device == NULL) {
|
if (opts.device == NULL) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You must specify a device.\n");
|
Eprintf("You must specify a device.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.quiet && opts.verbose) {
|
if (opts.quiet && opts.verbose) {
|
||||||
Eprintf ("You may not use --quiet and --verbose at "
|
Eprintf("You may not use --quiet and --verbose at "
|
||||||
"the same time.\n");
|
"the same time.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
@ -201,13 +201,13 @@ static int parse_options (int argc, char *argv[])
|
||||||
*
|
*
|
||||||
* Print the label of the device @dev to stdout.
|
* Print the label of the device @dev to stdout.
|
||||||
*/
|
*/
|
||||||
static int print_label (ntfs_volume *vol, unsigned long mnt_flags)
|
static int print_label(ntfs_volume *vol, unsigned long mnt_flags)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
//XXX significant?
|
//XXX significant?
|
||||||
if ((mnt_flags & (NTFS_MF_MOUNTED | NTFS_MF_READONLY)) ==
|
if ((mnt_flags & (NTFS_MF_MOUNTED | NTFS_MF_READONLY)) ==
|
||||||
NTFS_MF_MOUNTED) {
|
NTFS_MF_MOUNTED) {
|
||||||
Eprintf ("%s is mounted read-write, results may be "
|
Eprintf("%s is mounted read-write, results may be "
|
||||||
"unreliable.\n", opts.device);
|
"unreliable.\n", opts.device);
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -372,7 +372,7 @@ int main(int argc, char **argv)
|
||||||
int result = 0;
|
int result = 0;
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
|
|
||||||
if (!parse_options (argc, argv))
|
if (!parse_options(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
utils_set_locale();
|
utils_set_locale();
|
||||||
|
|
@ -380,17 +380,17 @@ int main(int argc, char **argv)
|
||||||
if (!opts.label)
|
if (!opts.label)
|
||||||
opts.noaction++;
|
opts.noaction++;
|
||||||
|
|
||||||
vol = utils_mount_volume (opts.device, opts.noaction ? MS_RDONLY : 0,
|
vol = utils_mount_volume(opts.device, opts.noaction ? MS_RDONLY : 0,
|
||||||
opts.force);
|
opts.force);
|
||||||
if (!vol)
|
if (!vol)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (opts.label)
|
if (opts.label)
|
||||||
result = change_label (vol, mnt_flags, opts.label, opts.force);
|
result = change_label(vol, mnt_flags, opts.label, opts.force);
|
||||||
else
|
else
|
||||||
result = print_label (vol, mnt_flags);
|
result = print_label(vol, mnt_flags);
|
||||||
|
|
||||||
ntfs_umount (vol, FALSE);
|
ntfs_umount(vol, FALSE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -484,12 +484,12 @@ static int list_dir_entry(ntfsls_dirent * dirent, const ntfschar * name,
|
||||||
|
|
||||||
struct dir *dir = NULL;
|
struct dir *dir = NULL;
|
||||||
|
|
||||||
filename = calloc (1, MAX_PATH);
|
filename = calloc(1, MAX_PATH);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (ntfs_ucstombs (name, name_len, &filename, MAX_PATH) < 0) {
|
if (ntfs_ucstombs(name, name_len, &filename, MAX_PATH) < 0) {
|
||||||
Eprintf ("Cannot represent filename in current locale.\n");
|
Eprintf("Cannot represent filename in current locale.\n");
|
||||||
goto free;
|
goto free;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -606,7 +606,7 @@ release:
|
||||||
}
|
}
|
||||||
|
|
||||||
free:
|
free:
|
||||||
free (filename);
|
free(filename);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -641,7 +641,7 @@ int main(int argc, char **argv)
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ni = ntfs_pathname_to_inode (vol, NULL, opts.path);
|
ni = ntfs_pathname_to_inode(vol, NULL, opts.path);
|
||||||
if (!ni) {
|
if (!ni) {
|
||||||
// FIXME: Print error... (AIA)
|
// FIXME: Print error... (AIA)
|
||||||
ntfs_umount(vol, FALSE);
|
ntfs_umount(vol, FALSE);
|
||||||
|
|
@ -674,9 +674,9 @@ int main(int argc, char **argv)
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while ((rec = find_attribute (AT_FILE_NAME, ctx))) {
|
while ((rec = find_attribute(AT_FILE_NAME, ctx))) {
|
||||||
/* We know this will always be resident. */
|
/* We know this will always be resident. */
|
||||||
attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu (rec->value_offset));
|
attr = (FILE_NAME_ATTR *) ((char *) rec + le16_to_cpu(rec->value_offset));
|
||||||
|
|
||||||
if (attr->file_name_type < space) {
|
if (attr->file_name_type < space) {
|
||||||
name = attr->file_name;
|
name = attr->file_name;
|
||||||
|
|
|
||||||
|
|
@ -166,8 +166,8 @@ static void license(void)
|
||||||
/**
|
/**
|
||||||
* usage - print a list of the parameters to the program
|
* usage - print a list of the parameters to the program
|
||||||
*/
|
*/
|
||||||
__attribute__ ((noreturn))
|
__attribute__((noreturn))
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
copyright();
|
copyright();
|
||||||
fprintf(stderr, "Usage: %s [options] device [base-mft-record]\n"
|
fprintf(stderr, "Usage: %s [options] device [base-mft-record]\n"
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,9 @@
|
||||||
static const char *EXEC_NAME = "ntfsmove";
|
static const char *EXEC_NAME = "ntfsmove";
|
||||||
static struct options opts;
|
static struct options opts;
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#define RED "\e[31m"
|
#define RED "\e[31m"
|
||||||
|
|
@ -68,13 +68,13 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
printf ("\n%s v%s (libntfs %s) - Move files and directories on an "
|
printf("\n%s v%s (libntfs %s) - Move files and directories on an "
|
||||||
"NTFS volume.\n\n", EXEC_NAME, VERSION,
|
"NTFS volume.\n\n", EXEC_NAME, VERSION,
|
||||||
ntfs_libntfs_version());
|
ntfs_libntfs_version());
|
||||||
printf ("Copyright (c) 2003 Richard Russon\n");
|
printf("Copyright (c) 2003 Richard Russon\n");
|
||||||
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -84,9 +84,9 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf ("\nUsage: %s [options] device file\n"
|
printf("\nUsage: %s [options] device file\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -S --start Move to the start of the volume\n"
|
" -S --start Move to the start of the volume\n"
|
||||||
" -B --best Move to the best place on the volume\n"
|
" -B --best Move to the best place on the volume\n"
|
||||||
|
|
@ -101,7 +101,7 @@ static void usage (void)
|
||||||
" -V --version Version information\n"
|
" -V --version Version information\n"
|
||||||
" -v --verbose More output\n\n",
|
" -v --verbose More output\n\n",
|
||||||
EXEC_NAME);
|
EXEC_NAME);
|
||||||
printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
printf("%s%s\n", ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,7 +113,7 @@ static void usage (void)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char **argv)
|
static int parse_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const char *sopt = "-BC:DEfh?nqSVv";
|
static const char *sopt = "-BC:DEfh?nqSVv";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -139,7 +139,7 @@ static int parse_options (int argc, char **argv)
|
||||||
|
|
||||||
opterr = 0; /* We'll handle the errors, thank you. */
|
opterr = 0; /* We'll handle the errors, thank you. */
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!opts.device) {
|
if (!opts.device) {
|
||||||
|
|
@ -160,7 +160,7 @@ static int parse_options (int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
if (opts.location == 0) {
|
if (opts.location == 0) {
|
||||||
opts.location = strtoll (optarg, &end, 0);
|
opts.location = strtoll(optarg, &end, 0);
|
||||||
if (end && *end)
|
if (end && *end)
|
||||||
err++;
|
err++;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -202,7 +202,7 @@ static int parse_options (int argc, char **argv)
|
||||||
opts.verbose++;
|
opts.verbose++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
|
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
|
||||||
err++;
|
err++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -214,7 +214,7 @@ static int parse_options (int argc, char **argv)
|
||||||
if ((opts.device == NULL) ||
|
if ((opts.device == NULL) ||
|
||||||
(opts.file == NULL)) {
|
(opts.file == NULL)) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You must specify one device and one file.\n");
|
Eprintf("You must specify one device and one file.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,7 +225,7 @@ static int parse_options (int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.location == -1) {
|
if (opts.location == -1) {
|
||||||
Eprintf ("You may only specify one location option: "
|
Eprintf("You may only specify one location option: "
|
||||||
"--start, --best, --end or --cluster\n");
|
"--start, --best, --end or --cluster\n");
|
||||||
err++;
|
err++;
|
||||||
} else if (opts.location == 0) {
|
} else if (opts.location == 0) {
|
||||||
|
|
@ -246,7 +246,7 @@ static int parse_options (int argc, char **argv)
|
||||||
/**
|
/**
|
||||||
* ntfs_debug_runlist_dump2 - Dump a runlist.
|
* ntfs_debug_runlist_dump2 - Dump a runlist.
|
||||||
*/
|
*/
|
||||||
static int ntfs_debug_runlist_dump2 (const runlist *rl, int abbr, char *prefix)
|
static int ntfs_debug_runlist_dump2(const runlist *rl, int abbr, char *prefix)
|
||||||
{
|
{
|
||||||
//int abbr = 3; /* abbreviate long lists */
|
//int abbr = 3; /* abbreviate long lists */
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
@ -274,7 +274,7 @@ static int ntfs_debug_runlist_dump2 (const runlist *rl, int abbr, char *prefix)
|
||||||
if (abbr)
|
if (abbr)
|
||||||
if (len > 20) {
|
if (len > 20) {
|
||||||
if ((i == abbr) && (len > (abbr*2)))
|
if ((i == abbr) && (len > (abbr*2)))
|
||||||
printf ("%s ... ... ...\n", prefix);
|
printf("%s ... ... ...\n", prefix);
|
||||||
if ((i > (abbr-1)) && (i < (len - (abbr-1))))
|
if ((i > (abbr-1)) && (i < (len - (abbr-1))))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -295,9 +295,9 @@ static int ntfs_debug_runlist_dump2 (const runlist *rl, int abbr, char *prefix)
|
||||||
printf("%s%8lld %8lld %8lld\n", prefix,
|
printf("%s%8lld %8lld %8lld\n", prefix,
|
||||||
rl->vcn, rl->lcn, rl->length);
|
rl->vcn, rl->lcn, rl->length);
|
||||||
}
|
}
|
||||||
printf ("%s --------\n", prefix);
|
printf("%s --------\n", prefix);
|
||||||
printf ("%s %8lld\n", prefix, total);
|
printf("%s %8lld\n", prefix, total);
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -306,7 +306,7 @@ static int ntfs_debug_runlist_dump2 (const runlist *rl, int abbr, char *prefix)
|
||||||
/**
|
/**
|
||||||
* resize_nonres_attr
|
* resize_nonres_attr
|
||||||
*/
|
*/
|
||||||
static int resize_nonres_attr (MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size)
|
static int resize_nonres_attr(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size)
|
||||||
{
|
{
|
||||||
int this_attr;
|
int this_attr;
|
||||||
int next_attr;
|
int next_attr;
|
||||||
|
|
@ -323,15 +323,15 @@ static int resize_nonres_attr (MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size
|
||||||
ptr = (u8*) m;
|
ptr = (u8*) m;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
printf ("old_size = %d\n", old_size);
|
printf("old_size = %d\n", old_size);
|
||||||
printf ("new_size = %d\n", new_size);
|
printf("new_size = %d\n", new_size);
|
||||||
printf ("file_size = %d\n", file_size);
|
printf("file_size = %d\n", file_size);
|
||||||
printf ("this_attr = %d\n", this_attr);
|
printf("this_attr = %d\n", this_attr);
|
||||||
printf ("next_attr = %d\n", next_attr);
|
printf("next_attr = %d\n", next_attr);
|
||||||
printf ("tail_size = %d\n", tail_size);
|
printf("tail_size = %d\n", tail_size);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
memmove (ptr + this_attr + new_size, ptr + next_attr, tail_size);
|
memmove(ptr + this_attr + new_size, ptr + next_attr, tail_size);
|
||||||
|
|
||||||
a->length = new_size;
|
a->length = new_size;
|
||||||
m->bytes_in_use += new_size - old_size;
|
m->bytes_in_use += new_size - old_size;
|
||||||
|
|
@ -342,7 +342,7 @@ static int resize_nonres_attr (MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size
|
||||||
/**
|
/**
|
||||||
* calc_attr_length
|
* calc_attr_length
|
||||||
*/
|
*/
|
||||||
static int calc_attr_length (ATTR_RECORD *rec, int runlength)
|
static int calc_attr_length(ATTR_RECORD *rec, int runlength)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
|
|
@ -361,15 +361,15 @@ static int calc_attr_length (ATTR_RECORD *rec, int runlength)
|
||||||
/**
|
/**
|
||||||
* dump_runs
|
* dump_runs
|
||||||
*/
|
*/
|
||||||
static void dump_runs (u8 *buffer, int len)
|
static void dump_runs(u8 *buffer, int len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
printf ("RUN: \e[01;31m");
|
printf("RUN: \e[01;31m");
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
printf (" %02x", buffer[i]);
|
printf(" %02x", buffer[i]);
|
||||||
}
|
}
|
||||||
printf ("\e[0m\n");
|
printf("\e[0m\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* if 0 */
|
#endif /* if 0 */
|
||||||
|
|
@ -377,7 +377,7 @@ static void dump_runs (u8 *buffer, int len)
|
||||||
/**
|
/**
|
||||||
* find_unused
|
* find_unused
|
||||||
*/
|
*/
|
||||||
static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
|
static runlist * find_unused(ntfs_volume *vol, s64 size, u64 loc
|
||||||
__attribute__((unused)), int flags __attribute__((unused)))
|
__attribute__((unused)), int flags __attribute__((unused)))
|
||||||
{
|
{
|
||||||
const int bufsize = 8192;
|
const int bufsize = 8192;
|
||||||
|
|
@ -390,34 +390,34 @@ static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
|
||||||
int bit = 0;
|
int bit = 0;
|
||||||
runlist *res = NULL;
|
runlist *res = NULL;
|
||||||
|
|
||||||
//printf ("find_unused\n");
|
//printf("find_unused\n");
|
||||||
buffer = malloc (bufsize);
|
buffer = malloc(bufsize);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
printf ("!buffer\n");
|
printf("!buffer\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf ("looking for space for %lld clusters\n", size);
|
//printf("looking for space for %lld clusters\n", size);
|
||||||
|
|
||||||
clus = vol->lcnbmp_na->allocated_size / bufsize;
|
clus = vol->lcnbmp_na->allocated_size / bufsize;
|
||||||
//printf ("clus = %d\n", clus);
|
//printf("clus = %d\n", clus);
|
||||||
|
|
||||||
for (i = 0; i < clus; i++) {
|
for (i = 0; i < clus; i++) {
|
||||||
int bytes_read, j;
|
int bytes_read, j;
|
||||||
|
|
||||||
bytes_read = ntfs_attr_pread (vol->lcnbmp_na, i*bufsize,
|
bytes_read = ntfs_attr_pread(vol->lcnbmp_na, i*bufsize,
|
||||||
bufsize, buffer);
|
bufsize, buffer);
|
||||||
if (bytes_read != bufsize) {
|
if (bytes_read != bufsize) {
|
||||||
printf ("!read\n");
|
printf("!read\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (j = 0; j < bufsize*8; j++) {
|
for (j = 0; j < bufsize*8; j++) {
|
||||||
bit = !!test_bit (j & 7, buffer[j>>3]);
|
bit = !!test_bit(j & 7, buffer[j>>3]);
|
||||||
if (curr == bit) {
|
if (curr == bit) {
|
||||||
count++;
|
count++;
|
||||||
if ((!bit) && (count >= size)) {
|
if ((!bit) && (count >= size)) {
|
||||||
//res = calloc (2, sizeof (*res));
|
//res = calloc(2, sizeof(*res));
|
||||||
res = calloc (1, 4096);
|
res = calloc(1, 4096);
|
||||||
if (res) {
|
if (res) {
|
||||||
res[0].vcn = 0;
|
res[0].vcn = 0;
|
||||||
res[0].lcn = start;
|
res[0].lcn = start;
|
||||||
|
|
@ -427,7 +427,7 @@ static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//printf ("%d * %d\n", curr, count);
|
//printf("%d * %d\n", curr, count);
|
||||||
curr = bit;
|
curr = bit;
|
||||||
count = 1;
|
count = 1;
|
||||||
start = i*bufsize*8 + j;
|
start = i*bufsize*8 + j;
|
||||||
|
|
@ -435,18 +435,18 @@ static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
//printf ("%d * %d\n", curr, count);
|
//printf("%d * %d\n", curr, count);
|
||||||
|
|
||||||
free (buffer);
|
free(buffer);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
if (utils_cluster_in_use (vol, res->lcn + i)) {
|
if (utils_cluster_in_use(vol, res->lcn + i)) {
|
||||||
printf ("ERROR cluster %lld in use\n", res->lcn + i);
|
printf("ERROR cluster %lld in use\n", res->lcn + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf ("failed\n");
|
printf("failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -460,7 +460,7 @@ done:
|
||||||
* Any fragmented MFT records
|
* Any fragmented MFT records
|
||||||
* The boot file 'ntldr'
|
* The boot file 'ntldr'
|
||||||
*/
|
*/
|
||||||
static int dont_move (ntfs_inode *ino)
|
static int dont_move(ntfs_inode *ino)
|
||||||
{
|
{
|
||||||
static const ntfschar ntldr[6] = {
|
static const ntfschar ntldr[6] = {
|
||||||
const_cpu_to_le16('n'), const_cpu_to_le16('t'), const_cpu_to_le16('l'),
|
const_cpu_to_le16('n'), const_cpu_to_le16('t'), const_cpu_to_le16('l'),
|
||||||
|
|
@ -470,27 +470,27 @@ static int dont_move (ntfs_inode *ino)
|
||||||
ATTR_RECORD *rec;
|
ATTR_RECORD *rec;
|
||||||
FILE_NAME_ATTR *name;
|
FILE_NAME_ATTR *name;
|
||||||
|
|
||||||
if (utils_is_metadata (ino)) {
|
if (utils_is_metadata(ino)) {
|
||||||
Eprintf ("metadata\n");
|
Eprintf("metadata\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rec = find_first_attribute (AT_ATTRIBUTE_LIST, ino->mrec);
|
rec = find_first_attribute(AT_ATTRIBUTE_LIST, ino->mrec);
|
||||||
if (rec) {
|
if (rec) {
|
||||||
Eprintf ("attribute list\n");
|
Eprintf("attribute list\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rec = find_first_attribute (AT_FILE_NAME, ino->mrec);
|
rec = find_first_attribute(AT_FILE_NAME, ino->mrec);
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
Eprintf ("extend inode\n");
|
Eprintf("extend inode\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = (FILE_NAME_ATTR*) ((u8*)rec + rec->value_offset);
|
name = (FILE_NAME_ATTR*) ((u8*)rec + rec->value_offset);
|
||||||
if (ntfs_names_are_equal (ntldr, 5, name->file_name, name->file_name_length,
|
if (ntfs_names_are_equal(ntldr, 5, name->file_name, name->file_name_length,
|
||||||
IGNORE_CASE, ino->vol->upcase, ino->vol->upcase_len)) {
|
IGNORE_CASE, ino->vol->upcase, ino->vol->upcase_len)) {
|
||||||
Eprintf ("ntldr\n");
|
Eprintf("ntldr\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -501,16 +501,16 @@ static int dont_move (ntfs_inode *ino)
|
||||||
/**
|
/**
|
||||||
* bitmap_alloc
|
* bitmap_alloc
|
||||||
*/
|
*/
|
||||||
static int bitmap_alloc (ntfs_volume *vol, runlist_element *rl)
|
static int bitmap_alloc(ntfs_volume *vol, runlist_element *rl)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (!rl)
|
if (!rl)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
res = ntfs_bitmap_set_run (vol->lcnbmp_na, rl->lcn, rl->length);
|
res = ntfs_bitmap_set_run(vol->lcnbmp_na, rl->lcn, rl->length);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
Eprintf ("bitmap alloc returns %d\n", res);
|
Eprintf("bitmap alloc returns %d\n", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -519,16 +519,16 @@ static int bitmap_alloc (ntfs_volume *vol, runlist_element *rl)
|
||||||
/**
|
/**
|
||||||
* bitmap_free
|
* bitmap_free
|
||||||
*/
|
*/
|
||||||
static int bitmap_free (ntfs_volume *vol, runlist_element *rl)
|
static int bitmap_free(ntfs_volume *vol, runlist_element *rl)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (!rl)
|
if (!rl)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
res = ntfs_bitmap_clear_run (vol->lcnbmp_na, rl->lcn, rl->length);
|
res = ntfs_bitmap_clear_run(vol->lcnbmp_na, rl->lcn, rl->length);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
Eprintf ("bitmap free returns %d\n", res);
|
Eprintf("bitmap free returns %d\n", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -537,7 +537,7 @@ static int bitmap_free (ntfs_volume *vol, runlist_element *rl)
|
||||||
/**
|
/**
|
||||||
* data_copy
|
* data_copy
|
||||||
*/
|
*/
|
||||||
static int data_copy (ntfs_volume *vol, runlist_element *from, runlist_element *to)
|
static int data_copy(ntfs_volume *vol, runlist_element *from, runlist_element *to)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u8 *buffer;
|
u8 *buffer;
|
||||||
|
|
@ -548,32 +548,32 @@ static int data_copy (ntfs_volume *vol, runlist_element *from, runlist_element *
|
||||||
if ((from->length != to->length) || (from->lcn < 0) || (to->lcn < 0))
|
if ((from->length != to->length) || (from->lcn < 0) || (to->lcn < 0))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
//printf ("data_copy: from 0x%llx to 0x%llx\n", from->lcn, to->lcn);
|
//printf("data_copy: from 0x%llx to 0x%llx\n", from->lcn, to->lcn);
|
||||||
buffer = malloc (vol->cluster_size);
|
buffer = malloc(vol->cluster_size);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
printf ("!buffer\n");
|
printf("!buffer\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < from->length; i++) {
|
for (i = 0; i < from->length; i++) {
|
||||||
//printf ("read cluster at %8lld\n", from->lcn+i);
|
//printf("read cluster at %8lld\n", from->lcn+i);
|
||||||
res = ntfs_pread (vol->dev, (from->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
|
res = ntfs_pread(vol->dev, (from->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
|
||||||
if (res != vol->cluster_size) {
|
if (res != vol->cluster_size) {
|
||||||
Eprintf ("!read\n");
|
Eprintf("!read\n");
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf ("write cluster to %8lld\n", to->lcn+i);
|
//printf("write cluster to %8lld\n", to->lcn+i);
|
||||||
res = ntfs_pwrite (vol->dev, (to->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
|
res = ntfs_pwrite(vol->dev, (to->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
|
||||||
if (res != vol->cluster_size) {
|
if (res != vol->cluster_size) {
|
||||||
Eprintf ("!write %lld\n", res);
|
Eprintf("!write %lld\n", res);
|
||||||
res = -1;
|
res = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free (buffer);
|
free(buffer);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -588,7 +588,7 @@ static int data_copy (ntfs_volume *vol, runlist_element *from, runlist_element *
|
||||||
* copy data
|
* copy data
|
||||||
* deallocate old space
|
* deallocate old space
|
||||||
*/
|
*/
|
||||||
static s64 move_runlist (ntfs_volume *vol, runlist_element *from,
|
static s64 move_runlist(ntfs_volume *vol, runlist_element *from,
|
||||||
runlist_element *to)
|
runlist_element *to)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -596,41 +596,41 @@ static s64 move_runlist (ntfs_volume *vol, runlist_element *from,
|
||||||
if (!vol || !from || !to)
|
if (!vol || !from || !to)
|
||||||
return -1;
|
return -1;
|
||||||
if (from->length != to->length) {
|
if (from->length != to->length) {
|
||||||
Eprintf ("diffsizes\n");
|
Eprintf("diffsizes\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((from->lcn < 0) || (to->lcn < 0)) {
|
if ((from->lcn < 0) || (to->lcn < 0)) {
|
||||||
Eprintf ("invalid runs\n");
|
Eprintf("invalid runs\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < from->length; i++) {
|
for (i = 0; i < from->length; i++) {
|
||||||
if (!utils_cluster_in_use (vol, from->lcn+i)) {
|
if (!utils_cluster_in_use(vol, from->lcn+i)) {
|
||||||
Eprintf ("from not in use\n");
|
Eprintf("from not in use\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < to->length; i++) {
|
for (i = 0; i < to->length; i++) {
|
||||||
if (utils_cluster_in_use (vol, to->lcn+i)) {
|
if (utils_cluster_in_use(vol, to->lcn+i)) {
|
||||||
Eprintf ("to is in use\n");
|
Eprintf("to is in use\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitmap_alloc (vol, to) < 0) {
|
if (bitmap_alloc(vol, to) < 0) {
|
||||||
Eprintf ("cannot bitmap_alloc\n");
|
Eprintf("cannot bitmap_alloc\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_copy (vol, from, to) < 0) {
|
if (data_copy(vol, from, to) < 0) {
|
||||||
Eprintf ("cannot data_copy\n");
|
Eprintf("cannot data_copy\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitmap_free (vol, from) < 0) {
|
if (bitmap_free(vol, from) < 0) {
|
||||||
Eprintf ("cannot bitmap_free\n");
|
Eprintf("cannot bitmap_free\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -654,7 +654,7 @@ static s64 move_runlist (ntfs_volume *vol, runlist_element *from,
|
||||||
// requires a mrec arg, not an ino (ino->mrec will do for now)
|
// requires a mrec arg, not an ino (ino->mrec will do for now)
|
||||||
// check size of new runlist before allocating / moving
|
// check size of new runlist before allocating / moving
|
||||||
// replace one datarun with another (by hand)
|
// replace one datarun with another (by hand)
|
||||||
static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
static s64 move_datarun(ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
runlist_element *run, u64 loc, int flags)
|
runlist_element *run, u64 loc, int flags)
|
||||||
{
|
{
|
||||||
runlist *from;
|
runlist *from;
|
||||||
|
|
@ -665,27 +665,27 @@ static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
s64 res = -1;
|
s64 res = -1;
|
||||||
|
|
||||||
// find empty space
|
// find empty space
|
||||||
to = find_unused (vol, run->length, loc, flags);
|
to = find_unused(vol, run->length, loc, flags);
|
||||||
if (!to) {
|
if (!to) {
|
||||||
Eprintf ("!to\n");
|
Eprintf("!to\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
to->vcn = run->vcn;
|
to->vcn = run->vcn;
|
||||||
|
|
||||||
// copy original runlist
|
// copy original runlist
|
||||||
from = ntfs_mapping_pairs_decompress (vol, rec, NULL);
|
from = ntfs_mapping_pairs_decompress(vol, rec, NULL);
|
||||||
if (!from) {
|
if (!from) {
|
||||||
printf ("!from\n");
|
printf("!from\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("move %lld,%lld,%lld to %lld,%lld,%lld\n", run->vcn, run->lcn, run->length, to->vcn, to->lcn, to->length);
|
printf("move %lld,%lld,%lld to %lld,%lld,%lld\n", run->vcn, run->lcn, run->length, to->vcn, to->lcn, to->length);
|
||||||
|
|
||||||
need_from = ntfs_get_size_for_mapping_pairs(vol, from, 0);
|
need_from = ntfs_get_size_for_mapping_pairs(vol, from, 0);
|
||||||
printf ("orig data run = %d bytes\n", need_from);
|
printf("orig data run = %d bytes\n", need_from);
|
||||||
|
|
||||||
//ntfs_debug_runlist_dump2 (from, 5, "\t");
|
//ntfs_debug_runlist_dump2(from, 5, "\t");
|
||||||
|
|
||||||
for (i = 0; to[i].length > 0; i++) {
|
for (i = 0; to[i].length > 0; i++) {
|
||||||
if (from[i].vcn == run->vcn) {
|
if (from[i].vcn == run->vcn) {
|
||||||
|
|
@ -694,47 +694,47 @@ static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ntfs_debug_runlist_dump2 (from, 5, "\t");
|
//ntfs_debug_runlist_dump2(from, 5, "\t");
|
||||||
|
|
||||||
need_to = ntfs_get_size_for_mapping_pairs(vol, from, 0);
|
need_to = ntfs_get_size_for_mapping_pairs(vol, from, 0);
|
||||||
printf ("new data run = %d bytes\n", need_to);
|
printf("new data run = %d bytes\n", need_to);
|
||||||
|
|
||||||
need_from = calc_attr_length (rec, need_from);
|
need_from = calc_attr_length(rec, need_from);
|
||||||
need_to = calc_attr_length (rec, need_to);
|
need_to = calc_attr_length(rec, need_to);
|
||||||
|
|
||||||
//printf (RED "Before %d, after %d\n" NORM, need_from, need_to);
|
//printf(RED "Before %d, after %d\n" NORM, need_from, need_to);
|
||||||
printf ("Before %d, after %d\n", need_from, need_to);
|
printf("Before %d, after %d\n", need_from, need_to);
|
||||||
|
|
||||||
if (need_from != need_to) {
|
if (need_from != need_to) {
|
||||||
if (resize_nonres_attr (ino->mrec, rec, need_to) < 0) {
|
if (resize_nonres_attr(ino->mrec, rec, need_to) < 0) {
|
||||||
printf ("!resize\n");
|
printf("!resize\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = move_runlist (vol, run, to);
|
res = move_runlist(vol, run, to);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
Eprintf ("!move_runlist\n");
|
Eprintf("!move_runlist\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// wipe orig runs
|
// wipe orig runs
|
||||||
memset (((u8*)rec) +rec->mapping_pairs_offset, 0, need_to - rec->mapping_pairs_offset);
|
memset(((u8*)rec) +rec->mapping_pairs_offset, 0, need_to - rec->mapping_pairs_offset);
|
||||||
|
|
||||||
// update data runs
|
// update data runs
|
||||||
ntfs_mapping_pairs_build(vol, ((u8*)rec) + rec->mapping_pairs_offset,
|
ntfs_mapping_pairs_build(vol, ((u8*)rec) + rec->mapping_pairs_offset,
|
||||||
need_to, from, 0, NULL);
|
need_to, from, 0, NULL);
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
ntfs_inode_mark_dirty (ino);
|
ntfs_inode_mark_dirty(ino);
|
||||||
|
|
||||||
if (ntfs_inode_sync (ino) < 0) {
|
if (ntfs_inode_sync(ino) < 0) {
|
||||||
printf ("!sync\n");
|
printf("!sync\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (from);
|
free(from);
|
||||||
free (to);
|
free(to);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -744,7 +744,7 @@ static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
* = 0 Nothing to do
|
* = 0 Nothing to do
|
||||||
* < 0 Error
|
* < 0 Error
|
||||||
*/
|
*/
|
||||||
static s64 move_attribute (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
static s64 move_attribute(ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
u64 loc, int flags)
|
u64 loc, int flags)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -756,24 +756,24 @@ static s64 move_attribute (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
// find that space and pass the location to our children.
|
// find that space and pass the location to our children.
|
||||||
// Anything else we pass directly to move_datarun.
|
// Anything else we pass directly to move_datarun.
|
||||||
|
|
||||||
runs = ntfs_mapping_pairs_decompress (vol, rec, NULL);
|
runs = ntfs_mapping_pairs_decompress(vol, rec, NULL);
|
||||||
if (!runs) {
|
if (!runs) {
|
||||||
Eprintf ("!runs\n");
|
Eprintf("!runs\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ntfs_debug_runlist_dump2 (runs, 5, "\t");
|
//ntfs_debug_runlist_dump2(runs, 5, "\t");
|
||||||
|
|
||||||
//printf (" VCN LCN Length\n");
|
//printf(" VCN LCN Length\n");
|
||||||
for (i = 0; runs[i].length > 0; i++) {
|
for (i = 0; runs[i].length > 0; i++) {
|
||||||
if (runs[i].lcn == LCN_RL_NOT_MAPPED) {
|
if (runs[i].lcn == LCN_RL_NOT_MAPPED) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = move_datarun (vol, ino, rec, runs+i, loc, flags);
|
res = move_datarun(vol, ino, rec, runs+i, loc, flags);
|
||||||
//printf (" %8lld %8lld %8lld\n", runs[i].vcn, runs[i].lcn, runs[i].length);
|
//printf(" %8lld %8lld %8lld\n", runs[i].vcn, runs[i].lcn, runs[i].length);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
Eprintf ("!move_datarun\n");
|
Eprintf("!move_datarun\n");
|
||||||
count = res;
|
count = res;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -789,7 +789,7 @@ static s64 move_attribute (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
|
||||||
* = 0 Nothing to do
|
* = 0 Nothing to do
|
||||||
* < 0 Error
|
* < 0 Error
|
||||||
*/
|
*/
|
||||||
static s64 move_file (ntfs_volume *vol, ntfs_inode *ino, u64 loc, int flags)
|
static s64 move_file(ntfs_volume *vol, ntfs_inode *ino, u64 loc, int flags)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
ntfs_attr_search_ctx *ctx;
|
ntfs_attr_search_ctx *ctx;
|
||||||
|
|
@ -797,47 +797,47 @@ static s64 move_file (ntfs_volume *vol, ntfs_inode *ino, u64 loc, int flags)
|
||||||
s64 res;
|
s64 res;
|
||||||
s64 count = 0;
|
s64 count = 0;
|
||||||
|
|
||||||
buffer = malloc (MAX_PATH);
|
buffer = malloc(MAX_PATH);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
Eprintf ("Out of memory\n");
|
Eprintf("Out of memory\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
utils_inode_get_name (ino, buffer, MAX_PATH);
|
utils_inode_get_name(ino, buffer, MAX_PATH);
|
||||||
|
|
||||||
if (dont_move (ino)) {
|
if (dont_move(ino)) {
|
||||||
Eprintf ("can't move\n");
|
Eprintf("can't move\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("Moving %s\n", buffer);
|
printf("Moving %s\n", buffer);
|
||||||
|
|
||||||
// NTFS_MOVE_LOC_BEST : assess how much space all the attributes will need,
|
// NTFS_MOVE_LOC_BEST : assess how much space all the attributes will need,
|
||||||
// find that space and pass the location to our children.
|
// find that space and pass the location to our children.
|
||||||
// Anything else we pass directly to move_attribute.
|
// Anything else we pass directly to move_attribute.
|
||||||
|
|
||||||
ctx = ntfs_attr_get_search_ctx (ino, NULL);
|
ctx = ntfs_attr_get_search_ctx(ino, NULL);
|
||||||
|
|
||||||
while ((rec = find_attribute (AT_UNUSED, ctx))) {
|
while ((rec = find_attribute(AT_UNUSED, ctx))) {
|
||||||
utils_attr_get_name (vol, rec, buffer, MAX_PATH);
|
utils_attr_get_name(vol, rec, buffer, MAX_PATH);
|
||||||
printf ("\tAttribute 0x%02x %s is ", rec->type, buffer);
|
printf("\tAttribute 0x%02x %s is ", rec->type, buffer);
|
||||||
|
|
||||||
if (rec->non_resident) {
|
if (rec->non_resident) {
|
||||||
printf ("non-resident. Moving it.\n");
|
printf("non-resident. Moving it.\n");
|
||||||
|
|
||||||
res = move_attribute (vol, ino, rec, loc, flags);
|
res = move_attribute(vol, ino, rec, loc, flags);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
count = res;
|
count = res;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
count += res;
|
count += res;
|
||||||
} else {
|
} else {
|
||||||
printf ("resident.\n\t\tSkipping it.\n");
|
printf("resident.\n\t\tSkipping it.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ntfs_attr_put_search_ctx (ctx);
|
ntfs_attr_put_search_ctx(ctx);
|
||||||
free (buffer);
|
free(buffer);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -850,7 +850,7 @@ static s64 move_file (ntfs_volume *vol, ntfs_inode *ino, u64 loc, int flags)
|
||||||
* Return: 0 Success, the program worked
|
* Return: 0 Success, the program worked
|
||||||
* 1 Error, something went wrong
|
* 1 Error, something went wrong
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ntfs_volume *vol;
|
ntfs_volume *vol;
|
||||||
ntfs_inode *inode;
|
ntfs_inode *inode;
|
||||||
|
|
@ -858,7 +858,7 @@ int main (int argc, char *argv[])
|
||||||
int result = 1;
|
int result = 1;
|
||||||
s64 count;
|
s64 count;
|
||||||
|
|
||||||
if (!parse_options (argc, argv))
|
if (!parse_options(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
utils_set_locale();
|
utils_set_locale();
|
||||||
|
|
@ -866,35 +866,35 @@ int main (int argc, char *argv[])
|
||||||
if (opts.noaction)
|
if (opts.noaction)
|
||||||
flags |= MS_RDONLY;
|
flags |= MS_RDONLY;
|
||||||
|
|
||||||
vol = utils_mount_volume (opts.device, flags, opts.force);
|
vol = utils_mount_volume(opts.device, flags, opts.force);
|
||||||
if (!vol) {
|
if (!vol) {
|
||||||
printf ("!vol\n");
|
printf("!vol\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = ntfs_pathname_to_inode(vol, NULL, opts.file);
|
inode = ntfs_pathname_to_inode(vol, NULL, opts.file);
|
||||||
if (!inode) {
|
if (!inode) {
|
||||||
printf ("!inode\n");
|
printf("!inode\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = move_file (vol, inode, opts.location, 0);
|
count = move_file(vol, inode, opts.location, 0);
|
||||||
if ((count > 0) && (!opts.nodirty)) {
|
if ((count > 0) && (!opts.nodirty)) {
|
||||||
if (ntfs_volume_write_flags (vol, vol->flags | VOLUME_IS_DIRTY) <
|
if (ntfs_volume_write_flags(vol, vol->flags | VOLUME_IS_DIRTY) <
|
||||||
0) {
|
0) {
|
||||||
Eprintf ("Couldn't mark volume dirty\n");
|
Eprintf("Couldn't mark volume dirty\n");
|
||||||
}
|
}
|
||||||
printf ("Relocated %lld bytes\n", count);
|
printf("Relocated %lld bytes\n", count);
|
||||||
}
|
}
|
||||||
if (count >= 0)
|
if (count >= 0)
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
printf ("failed\n");
|
printf("failed\n");
|
||||||
else
|
else
|
||||||
printf ("success\n");
|
printf("success\n");
|
||||||
|
|
||||||
ntfs_inode_close (inode);
|
ntfs_inode_close(inode);
|
||||||
ntfs_umount (vol, FALSE);
|
ntfs_umount(vol, FALSE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ __attribute__((noreturn))
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
printf ("\nUsage: %s [OPTIONS] DEVICE\n"
|
printf("\nUsage: %s [OPTIONS] DEVICE\n"
|
||||||
" Resize an NTFS volume non-destructively, safely move any data if needed.\n"
|
" Resize an NTFS volume non-destructively, safely move any data if needed.\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -i, --info Estimate the smallest shrunken size possible\n"
|
" -i, --info Estimate the smallest shrunken size possible\n"
|
||||||
|
|
@ -321,8 +321,8 @@ static void usage(void)
|
||||||
" The options -i and -s are mutually exclusive. If both options are\n"
|
" The options -i and -s are mutually exclusive. If both options are\n"
|
||||||
" omitted then the NTFS volume will be enlarged to the DEVICE size.\n"
|
" omitted then the NTFS volume will be enlarged to the DEVICE size.\n"
|
||||||
"\n", EXEC_NAME);
|
"\n", EXEC_NAME);
|
||||||
printf ("%s%s", ntfs_bugs, ntfs_home);
|
printf("%s%s", ntfs_bugs, ntfs_home);
|
||||||
printf ("Ntfsresize FAQ: http://linux-ntfs.sourceforge.net/info/ntfsresize.html\n");
|
printf("Ntfsresize FAQ: http://linux-ntfs.sourceforge.net/info/ntfsresize.html\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -356,13 +356,13 @@ static void proceed_question(void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
printf ("\nResize an NTFS Volume, without data loss.\n\n");
|
printf("\nResize an NTFS Volume, without data loss.\n\n");
|
||||||
printf ("Copyright (c) 2002-2005 Szabolcs Szakacsits\n");
|
printf("Copyright (c) 2002-2005 Szabolcs Szakacsits\n");
|
||||||
printf ("Copyright (c) 2002-2004 Anton Altaparmakov\n");
|
printf("Copyright (c) 2002-2004 Anton Altaparmakov\n");
|
||||||
printf ("Copyright (c) 2002-2003 Richard Russon\n");
|
printf("Copyright (c) 2002-2003 Richard Russon\n");
|
||||||
printf ("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
|
printf("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -454,7 +454,7 @@ static int parse_options(int argc, char **argv)
|
||||||
memset(&opt, 0, sizeof(opt));
|
memset(&opt, 0, sizeof(opt));
|
||||||
opt.show_progress = 1;
|
opt.show_progress = 1;
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != (char)-1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!err && !opt.volume)
|
if (!err && !opt.volume)
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,9 @@ static const char *EXEC_NAME = "ntfsrm";
|
||||||
static struct options opts;
|
static struct options opts;
|
||||||
static const char *space_line = " ";
|
static const char *space_line = " ";
|
||||||
|
|
||||||
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
|
||||||
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
|
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
|
||||||
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
|
|
||||||
#define RM_WRITE 0
|
#define RM_WRITE 0
|
||||||
|
|
||||||
|
|
@ -69,12 +69,12 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void version (void)
|
static void version(void)
|
||||||
{
|
{
|
||||||
printf("\n%s v%s (libntfs %s) - Delete files from an NTFS volume.\n\n",
|
printf("\n%s v%s (libntfs %s) - Delete files from an NTFS volume.\n\n",
|
||||||
EXEC_NAME, VERSION, ntfs_libntfs_version());
|
EXEC_NAME, VERSION, ntfs_libntfs_version());
|
||||||
printf ("Copyright (c) 2004 Richard Russon\n");
|
printf("Copyright (c) 2004 Richard Russon\n");
|
||||||
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -84,9 +84,9 @@ static void version (void)
|
||||||
*
|
*
|
||||||
* Return: none
|
* Return: none
|
||||||
*/
|
*/
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf ("\nUsage: %s [options] device file\n"
|
printf("\nUsage: %s [options] device file\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -r --recursive Delete files in subdirectories\n"
|
" -r --recursive Delete files in subdirectories\n"
|
||||||
" -i --interactive Ask before deleting files\n"
|
" -i --interactive Ask before deleting files\n"
|
||||||
|
|
@ -101,7 +101,7 @@ static void usage (void)
|
||||||
" -V --version Version information\n"
|
" -V --version Version information\n"
|
||||||
" -v --verbose More output\n\n",
|
" -v --verbose More output\n\n",
|
||||||
EXEC_NAME);
|
EXEC_NAME);
|
||||||
printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
printf("%s%s\n", ntfs_bugs, ntfs_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,7 +113,7 @@ static void usage (void)
|
||||||
* Return: 1 Success
|
* Return: 1 Success
|
||||||
* 0 Error, one or more problems
|
* 0 Error, one or more problems
|
||||||
*/
|
*/
|
||||||
static int parse_options (int argc, char **argv)
|
static int parse_options(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static const char *sopt = "-Dfh?inqRrVv"; //"-Dfh?I:inqRrUVv";
|
static const char *sopt = "-Dfh?inqRrVv"; //"-Dfh?I:inqRrUVv";
|
||||||
static const struct option lopt[] = {
|
static const struct option lopt[] = {
|
||||||
|
|
@ -138,7 +138,7 @@ static int parse_options (int argc, char **argv)
|
||||||
|
|
||||||
opterr = 0; /* We'll handle the errors, thank you. */
|
opterr = 0; /* We'll handle the errors, thank you. */
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != -1) {
|
while ((c = getopt_long(argc, argv, sopt, lopt, NULL)) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* A non-option argument */
|
case 1: /* A non-option argument */
|
||||||
if (!opts.device) {
|
if (!opts.device) {
|
||||||
|
|
@ -181,7 +181,7 @@ static int parse_options (int argc, char **argv)
|
||||||
opts.verbose++;
|
opts.verbose++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
|
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
|
||||||
err++;
|
err++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ static int parse_options (int argc, char **argv)
|
||||||
if ((opts.device == NULL) ||
|
if ((opts.device == NULL) ||
|
||||||
(opts.file == NULL)) {
|
(opts.file == NULL)) {
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
Eprintf ("You must specify one device and one file.\n");
|
Eprintf("You must specify one device and one file.\n");
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -216,18 +216,18 @@ static int parse_options (int argc, char **argv)
|
||||||
/**
|
/**
|
||||||
* ntfs_dir_print
|
* ntfs_dir_print
|
||||||
*/
|
*/
|
||||||
static void ntfs_dir_print (struct ntfs_dir *dir, int indent)
|
static void ntfs_dir_print(struct ntfs_dir *dir, int indent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf ("%.*s%p ", indent, space_line, dir);
|
printf("%.*s%p ", indent, space_line, dir);
|
||||||
ntfs_name_print (dir->name, dir->name_len);
|
ntfs_name_print(dir->name, dir->name_len);
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
|
|
||||||
for (i = 0; i < dir->child_count; i++) {
|
for (i = 0; i < dir->child_count; i++) {
|
||||||
ntfs_dir_print (dir->children[i], indent + 4);
|
ntfs_dir_print(dir->children[i], indent + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -235,17 +235,17 @@ static void ntfs_dir_print (struct ntfs_dir *dir, int indent)
|
||||||
/**
|
/**
|
||||||
* ntfs_dt_print
|
* ntfs_dt_print
|
||||||
*/
|
*/
|
||||||
static void ntfs_dt_print (struct ntfs_dt *dt, int indent)
|
static void ntfs_dt_print(struct ntfs_dt *dt, int indent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!dt)
|
if (!dt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf ("%.*s%p (%d)\n", indent, space_line, dt, dt->child_count);
|
printf("%.*s%p (%d)\n", indent, space_line, dt, dt->child_count);
|
||||||
|
|
||||||
for (i = 0; i < dt->child_count; i++) {
|
for (i = 0; i < dt->child_count; i++) {
|
||||||
ntfs_dt_print (dt->sub_nodes[i], indent + 4);
|
ntfs_dt_print(dt->sub_nodes[i], indent + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,9 +253,9 @@ static void ntfs_dt_print (struct ntfs_dt *dt, int indent)
|
||||||
/**
|
/**
|
||||||
* utils_array_insert
|
* utils_array_insert
|
||||||
*/
|
*/
|
||||||
static int utils_array_insert (void *ptr, int asize, int before, int count)
|
static int utils_array_insert(void *ptr, int asize, int before, int count)
|
||||||
{
|
{
|
||||||
static int esize = sizeof (u8*);
|
static int esize = sizeof(u8*);
|
||||||
u8 *src;
|
u8 *src;
|
||||||
u8 *dst;
|
u8 *dst;
|
||||||
int len;
|
int len;
|
||||||
|
|
@ -268,11 +268,11 @@ static int utils_array_insert (void *ptr, int asize, int before, int count)
|
||||||
len = (asize - before) * esize;
|
len = (asize - before) * esize;
|
||||||
|
|
||||||
// XXX what about realloc?
|
// XXX what about realloc?
|
||||||
memmove (dst, src, len);
|
memmove(dst, src, len);
|
||||||
|
|
||||||
len = count * esize;
|
len = count * esize;
|
||||||
|
|
||||||
memset (src, 0, len);
|
memset(src, 0, len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -280,9 +280,9 @@ static int utils_array_insert (void *ptr, int asize, int before, int count)
|
||||||
/**
|
/**
|
||||||
* utils_array_remove
|
* utils_array_remove
|
||||||
*/
|
*/
|
||||||
static int utils_array_remove (void *ptr, int asize, int first, int count)
|
static int utils_array_remove(void *ptr, int asize, int first, int count)
|
||||||
{
|
{
|
||||||
static int esize = sizeof (u8*);
|
static int esize = sizeof(u8*);
|
||||||
u8 *src;
|
u8 *src;
|
||||||
u8 *dst;
|
u8 *dst;
|
||||||
int len;
|
int len;
|
||||||
|
|
@ -294,12 +294,12 @@ static int utils_array_remove (void *ptr, int asize, int first, int count)
|
||||||
src = dst + (count * esize);
|
src = dst + (count * esize);
|
||||||
len = (asize - first) * esize;
|
len = (asize - first) * esize;
|
||||||
|
|
||||||
memmove (dst, src, len);
|
memmove(dst, src, len);
|
||||||
|
|
||||||
src = (u8*) ptr + ((asize - count) * esize);
|
src = (u8*) ptr + ((asize - count) * esize);
|
||||||
len = count * esize;
|
len = count * esize;
|
||||||
|
|
||||||
memset (src, 0, len);
|
memset(src, 0, len);
|
||||||
// XXX don't want to memset, want to realloc
|
// XXX don't want to memset, want to realloc
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -309,7 +309,7 @@ static int utils_array_remove (void *ptr, int asize, int first, int count)
|
||||||
/**
|
/**
|
||||||
* utils_pathname_to_inode2
|
* utils_pathname_to_inode2
|
||||||
*/
|
*/
|
||||||
static BOOL utils_pathname_to_inode2 (ntfs_volume *vol, struct ntfs_dir *parent, const char *pathname, struct ntfs_find *found)
|
static BOOL utils_pathname_to_inode2(ntfs_volume *vol, struct ntfs_dir *parent, const char *pathname, struct ntfs_find *found)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
|
@ -326,22 +326,22 @@ static BOOL utils_pathname_to_inode2 (ntfs_volume *vol, struct ntfs_dir *parent,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset (found, 0, sizeof (*found));
|
memset(found, 0, sizeof(*found));
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
dir = parent;
|
dir = parent;
|
||||||
} else {
|
} else {
|
||||||
dir = (struct ntfs_dir *) vol->private_data;
|
dir = (struct ntfs_dir *) vol->private_data;
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
Eprintf ("Couldn't open the inode of the root directory.\n");
|
Eprintf("Couldn't open the inode of the root directory.\n");
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unicode = malloc (MAX_PATH * sizeof (ntfschar));
|
unicode = malloc(MAX_PATH * sizeof(ntfschar));
|
||||||
ascii = strdup (pathname); // Work with a r/w copy
|
ascii = strdup(pathname); // Work with a r/w copy
|
||||||
if (!unicode || !ascii) {
|
if (!unicode || !ascii) {
|
||||||
Eprintf ("Out of memory.\n");
|
Eprintf("Out of memory.\n");
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,59 +349,59 @@ static BOOL utils_pathname_to_inode2 (ntfs_volume *vol, struct ntfs_dir *parent,
|
||||||
while (p && *p && *p == PATH_SEP) // Remove leading /'s
|
while (p && *p && *p == PATH_SEP) // Remove leading /'s
|
||||||
p++;
|
p++;
|
||||||
while (p && *p) {
|
while (p && *p) {
|
||||||
q = strchr (p, PATH_SEP); // Find the end of the first token
|
q = strchr(p, PATH_SEP); // Find the end of the first token
|
||||||
if (q != NULL) {
|
if (q != NULL) {
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = ntfs_mbstoucs (p, &unicode, MAX_PATH);
|
len = ntfs_mbstoucs(p, &unicode, MAX_PATH);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
Eprintf ("Couldn't convert name to Unicode: %s.\n", p);
|
Eprintf("Couldn't convert name to Unicode: %s.\n", p);
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf ("looking for %s in dir %lld\n", p, MREF (dir->mft_num));
|
//printf("looking for %s in dir %lld\n", p, MREF(dir->mft_num));
|
||||||
//printf ("dir: index = %p, children = %p, inode = %p, iroot = %p, ialloc = %p, count = %d\n", dir->index, dir->children, dir->inode, dir->iroot, dir->ialloc, dir->child_count);
|
//printf("dir: index = %p, children = %p, inode = %p, iroot = %p, ialloc = %p, count = %d\n", dir->index, dir->children, dir->inode, dir->iroot, dir->ialloc, dir->child_count);
|
||||||
//if (dir->parent)
|
//if (dir->parent)
|
||||||
if (q) {
|
if (q) {
|
||||||
child = ntfs_dir_find2 (dir, unicode, len);
|
child = ntfs_dir_find2(dir, unicode, len);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
printf ("can't find %s in %s\n", p, pathname);
|
printf("can't find %s in %s\n", p, pathname);
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//printf ("file: %s\n", p);
|
//printf("file: %s\n", p);
|
||||||
|
|
||||||
dt = ntfs_dt_find2 (dir->index, unicode, len, &dt_num);
|
dt = ntfs_dt_find2(dir->index, unicode, len, &dt_num);
|
||||||
if (!dt) {
|
if (!dt) {
|
||||||
printf ("can't find %s in %s (2)\n", p, pathname);
|
printf("can't find %s in %s (2)\n", p, pathname);
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf ("dt's flags = 0x%08x\n", dt->children[dt_num]->key.file_name.file_attributes);
|
//printf("dt's flags = 0x%08x\n", dt->children[dt_num]->key.file_name.file_attributes);
|
||||||
if (dt->children[dt_num]->key.file_name.file_attributes == FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT) {
|
if (dt->children[dt_num]->key.file_name.file_attributes == FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT) {
|
||||||
//printf ("DIR\n");
|
//printf("DIR\n");
|
||||||
child = ntfs_dir_create (dir->vol, dt->children[dt_num]->indexed_file);
|
child = ntfs_dir_create(dir->vol, dt->children[dt_num]->indexed_file);
|
||||||
//printf ("child = %p (%lld)\n", child, MREF (dt->children[dt_num]->indexed_file));
|
//printf("child = %p (%lld)\n", child, MREF(dt->children[dt_num]->indexed_file));
|
||||||
if (child) {
|
if (child) {
|
||||||
child->index = ntfs_dt_create (child, NULL, -1);
|
child->index = ntfs_dt_create(child, NULL, -1);
|
||||||
ntfs_dir_add (dir, child);
|
ntfs_dir_add(dir, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dt->inodes[dt_num] == NULL) {
|
if (dt->inodes[dt_num] == NULL) {
|
||||||
dt->inodes[dt_num] = ntfs_inode_open (dir->vol, dt->children[dt_num]->indexed_file);
|
dt->inodes[dt_num] = ntfs_inode_open(dir->vol, dt->children[dt_num]->indexed_file);
|
||||||
if (!dt->inodes[dt_num]) {
|
if (!dt->inodes[dt_num]) {
|
||||||
printf ("Can't open inode %lld\n", MREF (dt->children[dt_num]->indexed_file));
|
printf("Can't open inode %lld\n", MREF(dt->children[dt_num]->indexed_file));
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
dt->inodes[dt_num]->ref_count = 2;
|
dt->inodes[dt_num]->ref_count = 2;
|
||||||
dt->inodes[dt_num]->private_data = dt;
|
dt->inodes[dt_num]->private_data = dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf ("dt = %p,%d\n", dt, dt_num);
|
//printf("dt = %p,%d\n", dt, dt_num);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -418,10 +418,10 @@ static BOOL utils_pathname_to_inode2 (ntfs_volume *vol, struct ntfs_dir *parent,
|
||||||
found->inode = dt->inodes[dt_num];
|
found->inode = dt->inodes[dt_num];
|
||||||
found->mref = found->inode->mft_no;
|
found->mref = found->inode->mft_no;
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
//printf ("dir %p, dt %p, num %d, ino %p, %lld\n", dir, dt, dt_num, dt->inodes[dt_num], MREF (found->inode->mft_no));
|
//printf("dir %p, dt %p, num %d, ino %p, %lld\n", dir, dt, dt_num, dt->inodes[dt_num], MREF(found->inode->mft_no));
|
||||||
close:
|
close:
|
||||||
free (ascii); // from strdup
|
free(ascii); // from strdup
|
||||||
free (unicode);
|
free(unicode);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -429,7 +429,7 @@ close:
|
||||||
/**
|
/**
|
||||||
* ntfs_mft_find_free_entry
|
* ntfs_mft_find_free_entry
|
||||||
*/
|
*/
|
||||||
static s64 ntfs_mft_find_free_entry (ntfs_volume *vol)
|
static s64 ntfs_mft_find_free_entry(ntfs_volume *vol)
|
||||||
{
|
{
|
||||||
MFT_REF i;
|
MFT_REF i;
|
||||||
u64 recs;
|
u64 recs;
|
||||||
|
|
@ -438,9 +438,9 @@ static s64 ntfs_mft_find_free_entry (ntfs_volume *vol)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
recs = vol->mft_na->initialized_size >> vol->mft_record_size_bits;
|
recs = vol->mft_na->initialized_size >> vol->mft_record_size_bits;
|
||||||
//printf ("mft contains %lld records\n", recs);
|
//printf("mft contains %lld records\n", recs);
|
||||||
for (i = 24; i < recs; i++) {
|
for (i = 24; i < recs; i++) {
|
||||||
if (utils_mftrec_in_use (vol, i) == 0)
|
if (utils_mftrec_in_use(vol, i) == 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -449,14 +449,14 @@ static s64 ntfs_mft_find_free_entry (ntfs_volume *vol)
|
||||||
/**
|
/**
|
||||||
* ntfs_mft_set_inuse6
|
* ntfs_mft_set_inuse6
|
||||||
*/
|
*/
|
||||||
static int ntfs_mft_set_inuse6 (ntfs_inode *inode, struct ntfs_bmp *bmp, BOOL inuse)
|
static int ntfs_mft_set_inuse6(ntfs_inode *inode, struct ntfs_bmp *bmp, BOOL inuse)
|
||||||
{
|
{
|
||||||
MFT_RECORD *rec;
|
MFT_RECORD *rec;
|
||||||
|
|
||||||
if (!inode)
|
if (!inode)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (ntfs_bmp_set_range (bmp, (VCN) MREF (inode->mft_no), 1, inuse) < 0)
|
if (ntfs_bmp_set_range(bmp, (VCN) MREF(inode->mft_no), 1, inuse) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
rec = (MFT_RECORD*) inode->mrec;
|
rec = (MFT_RECORD*) inode->mrec;
|
||||||
|
|
@ -472,7 +472,7 @@ static int ntfs_mft_set_inuse6 (ntfs_inode *inode, struct ntfs_bmp *bmp, BOOL in
|
||||||
|
|
||||||
NInoSetDirty(inode);
|
NInoSetDirty(inode);
|
||||||
|
|
||||||
printf (GREEN "Modified: inode %lld MFT_RECORD header\n" END, inode->mft_no);
|
printf(GREEN "Modified: inode %lld MFT_RECORD header\n" END, inode->mft_no);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -480,7 +480,7 @@ static int ntfs_mft_set_inuse6 (ntfs_inode *inode, struct ntfs_bmp *bmp, BOOL in
|
||||||
/**
|
/**
|
||||||
* ntfs_file_remove
|
* ntfs_file_remove
|
||||||
*/
|
*/
|
||||||
static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
static int ntfs_file_remove(ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
{
|
{
|
||||||
struct ntfs_dir *find_dir = NULL;
|
struct ntfs_dir *find_dir = NULL;
|
||||||
struct ntfs_dt *top = NULL;
|
struct ntfs_dt *top = NULL;
|
||||||
|
|
@ -511,12 +511,12 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
name_len = del->children[del_num]->key.file_name.file_name_length;
|
name_len = del->children[del_num]->key.file_name.file_name_length;
|
||||||
|
|
||||||
top = del->dir->index;
|
top = del->dir->index;
|
||||||
//ntfs_dt_find_all (top);
|
//ntfs_dt_find_all(top);
|
||||||
//ntfs_dt_print (top, 0);
|
//ntfs_dt_print(top, 0);
|
||||||
|
|
||||||
del_ie = del->children[del_num];
|
del_ie = del->children[del_num];
|
||||||
//utils_dump_mem (del_ie, 0, del_ie->length, DM_DEFAULTS);
|
//utils_dump_mem(del_ie, 0, del_ie->length, DM_DEFAULTS);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the key is not in a leaf node, then replace it with its successor.
|
* If the key is not in a leaf node, then replace it with its successor.
|
||||||
|
|
@ -526,41 +526,41 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
/*
|
/*
|
||||||
for (i = 0; i < top->child_count; i++) {
|
for (i = 0; i < top->child_count; i++) {
|
||||||
par_ie = top->children[i];
|
par_ie = top->children[i];
|
||||||
file = &par_ie->key.file_name; printf ("\ttop node, key %d: ", i); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par_ie->key.file_name; printf("\ttop node, key %d: ", i); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
|
printf("\tvcn = %lld\n", ntfs_ie_get_vcn(par_ie));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (del->header->flags & INDEX_NODE) {
|
if (del->header->flags & INDEX_NODE) {
|
||||||
printf (BOLD YELLOW "Replace key with its successor:\n" END);
|
printf(BOLD YELLOW "Replace key with its successor:\n" END);
|
||||||
|
|
||||||
vcn = ntfs_ie_get_vcn (del_ie);
|
vcn = ntfs_ie_get_vcn(del_ie);
|
||||||
//printf ("vcn = %lld\n", vcn);
|
//printf("vcn = %lld\n", vcn);
|
||||||
|
|
||||||
suc = ntfs_dt_find4 (find_dir->index, uname, name_len, &suc_num);
|
suc = ntfs_dt_find4(find_dir->index, uname, name_len, &suc_num);
|
||||||
//printf ("succ = %p, index = %d\n", suc, suc_num);
|
//printf("succ = %p, index = %d\n", suc, suc_num);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
suc_ie = ntfs_ie_copy (suc->children[suc_num]);
|
suc_ie = ntfs_ie_copy(suc->children[suc_num]);
|
||||||
//utils_dump_mem (suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
suc_ie = ntfs_ie_set_vcn (suc_ie, vcn);
|
suc_ie = ntfs_ie_set_vcn(suc_ie, vcn);
|
||||||
//utils_dump_mem (suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
file = &del_ie->key.file_name; printf ("\trep name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &del_ie->key.file_name; printf("\trep name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
file = &suc_ie->key.file_name; printf ("\tsuc name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &suc_ie->key.file_name; printf("\tsuc name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
|
|
||||||
//utils_dump_mem (del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
if (ntfs_dt_isroot (del))
|
if (ntfs_dt_isroot(del))
|
||||||
res = ntfs_dt_root_replace (del, del_num, del_ie, suc_ie);
|
res = ntfs_dt_root_replace(del, del_num, del_ie, suc_ie);
|
||||||
else
|
else
|
||||||
res = ntfs_dt_alloc_replace (del, del_num, del_ie, suc_ie);
|
res = ntfs_dt_alloc_replace(del, del_num, del_ie, suc_ie);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
//utils_dump_mem (del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
|
|
||||||
ntfs_ie_free (suc_ie);
|
ntfs_ie_free(suc_ie);
|
||||||
|
|
||||||
if (res == FALSE)
|
if (res == FALSE)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -570,27 +570,27 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
del_ie = suc->children[suc_num];
|
del_ie = suc->children[suc_num];
|
||||||
}
|
}
|
||||||
|
|
||||||
//ntfs_dt_print (top, 0);
|
//ntfs_dt_print(top, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we have the simpler case of deleting from a leaf node.
|
* Now we have the simpler case of deleting from a leaf node.
|
||||||
* If this step creates an empty node, we have more to do.
|
* If this step creates an empty node, we have more to do.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
printf (BOLD YELLOW "Delete key:\n" END);
|
printf(BOLD YELLOW "Delete key:\n" END);
|
||||||
|
|
||||||
file = &del->children[del_num]->key.file_name; printf ("\tdel name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &del->children[del_num]->key.file_name; printf("\tdel name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
|
|
||||||
//utils_dump_mem (del->data, 0, del->header->index_length+24, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(del->data, 0, del->header->index_length+24, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
// XXX if del->child_count == 2, we could skip this step
|
// XXX if del->child_count == 2, we could skip this step
|
||||||
// no, if we combine with another node, we'll have to remember
|
// no, if we combine with another node, we'll have to remember
|
||||||
if (ntfs_dt_isroot (del))
|
if (ntfs_dt_isroot(del))
|
||||||
ntfs_dt_root_remove (del, del_num);
|
ntfs_dt_root_remove(del, del_num);
|
||||||
else
|
else
|
||||||
ntfs_dt_alloc_remove (del, del_num);
|
ntfs_dt_alloc_remove(del, del_num);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
//utils_dump_mem (del->data, 0, del->header->index_length+24, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(del->data, 0, del->header->index_length+24, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
|
|
||||||
if (del->child_count > 1) // XXX ntfs_dt_empty (dt), ntfs_dt_full (dt, new)
|
if (del->child_count > 1) // XXX ntfs_dt_empty (dt), ntfs_dt_full (dt, new)
|
||||||
goto commit;
|
goto commit;
|
||||||
|
|
@ -603,30 +603,30 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// find the key nearest the root which has no descendants
|
// find the key nearest the root which has no descendants
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
printf (BOLD YELLOW "Find childless parent:\n" END);
|
printf(BOLD YELLOW "Find childless parent:\n" END);
|
||||||
#if 0
|
#if 0
|
||||||
for (par = del->parent, old = par; par; old = par, par = par->parent) {
|
for (par = del->parent, old = par; par; old = par, par = par->parent) {
|
||||||
if (par->child_count > 1)
|
if (par->child_count > 1)
|
||||||
break;
|
break;
|
||||||
par_num = ntfs_dt_find_parent (par);
|
par_num = ntfs_dt_find_parent(par);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf ("del = %p, parent = %p\n", del, del->parent);
|
printf("del = %p, parent = %p\n", del, del->parent);
|
||||||
par = del->parent;
|
par = del->parent;
|
||||||
par_num = ntfs_dt_find_parent (del);
|
par_num = ntfs_dt_find_parent(del);
|
||||||
|
|
||||||
//utils_dump_mem (par->data, 0, par->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(par->data, 0, par->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
|
|
||||||
printf ("par = %p, par->parent = %p, num = %d\n", par, par->parent, par_num);
|
printf("par = %p, par->parent = %p, num = %d\n", par, par->parent, par_num);
|
||||||
par_num = 0; // TEMP
|
par_num = 0; // TEMP
|
||||||
|
|
||||||
if (par) {
|
if (par) {
|
||||||
file = &par->children[par_num]->key.file_name;
|
file = &par->children[par_num]->key.file_name;
|
||||||
printf ("\tpar name: ");
|
printf("\tpar name: ");
|
||||||
ntfs_name_print (file->file_name, file->file_name_length);
|
ntfs_name_print(file->file_name, file->file_name_length);
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (par == NULL) {
|
if (par == NULL) {
|
||||||
|
|
@ -634,123 +634,123 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
goto freedts;
|
goto freedts;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ntfs_dt_print (top, 0);
|
//ntfs_dt_print(top, 0);
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
|
|
||||||
//utils_dump_mem (par->data, 0, par->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(par->data, 0, par->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (i = 0; i < top->child_count; i++) {
|
for (i = 0; i < top->child_count; i++) {
|
||||||
par_ie = top->children[i];
|
par_ie = top->children[i];
|
||||||
file = &par_ie->key.file_name; printf ("\ttop node, key %d: ", i); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par_ie->key.file_name; printf("\ttop node, key %d: ", i); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
|
printf("\tvcn = %lld\n", ntfs_ie_get_vcn(par_ie));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// find if parent has left siblings
|
// find if parent has left siblings
|
||||||
if (par->children[par_num]->flags & INDEX_ENTRY_END) {
|
if (par->children[par_num]->flags & INDEX_ENTRY_END) {
|
||||||
printf (BOLD YELLOW "Swap the children of the parent and its left sibling\n" END);
|
printf(BOLD YELLOW "Swap the children of the parent and its left sibling\n" END);
|
||||||
|
|
||||||
par_ie = par->children[par_num];
|
par_ie = par->children[par_num];
|
||||||
vcn = ntfs_ie_get_vcn (par_ie);
|
vcn = ntfs_ie_get_vcn(par_ie);
|
||||||
//printf ("\toffset = %d\n", (u8*)par_ie - par->data); printf ("\tflags = %d\n", par_ie->flags); printf ("\tvcn = %lld\n", vcn); printf ("\tlength = %d\n", par_ie->length);
|
//printf("\toffset = %d\n", (u8*)par_ie - par->data); printf("\tflags = %d\n", par_ie->flags); printf("\tvcn = %lld\n", vcn); printf("\tlength = %d\n", par_ie->length);
|
||||||
//utils_dump_mem (par_ie, 0, par_ie->length, DM_DEFAULTS);
|
//utils_dump_mem(par_ie, 0, par_ie->length, DM_DEFAULTS);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
//printf ("\toffset = %d\n", (u8*)par_ie - par->data); printf ("\tflags = %d\n", par_ie->flags); printf ("\tvcn = %lld\n", vcn); printf ("\tlength = %d\n", par_ie->length);
|
//printf("\toffset = %d\n", (u8*)par_ie - par->data); printf("\tflags = %d\n", par_ie->flags); printf("\tvcn = %lld\n", vcn); printf("\tlength = %d\n", par_ie->length);
|
||||||
//utils_dump_mem (par_ie, 0, par_ie->length, DM_DEFAULTS);
|
//utils_dump_mem(par_ie, 0, par_ie->length, DM_DEFAULTS);
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
|
|
||||||
file = &par->children[par_num] ->key.file_name; printf ("\tpar name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par->children[par_num] ->key.file_name; printf("\tpar name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
file = &par->children[par_num-1]->key.file_name; printf ("\tsib name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par->children[par_num-1]->key.file_name; printf("\tsib name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
|
|
||||||
old = par->sub_nodes[par_num];
|
old = par->sub_nodes[par_num];
|
||||||
par->sub_nodes[par_num] = par->sub_nodes[par_num-1];
|
par->sub_nodes[par_num] = par->sub_nodes[par_num-1];
|
||||||
par->sub_nodes[par_num-1] = old;
|
par->sub_nodes[par_num-1] = old;
|
||||||
|
|
||||||
par_ie = par->children[par_num-1];
|
par_ie = par->children[par_num-1];
|
||||||
vcn = ntfs_ie_get_vcn (par_ie);
|
vcn = ntfs_ie_get_vcn(par_ie);
|
||||||
|
|
||||||
par_ie = par->children[par_num];
|
par_ie = par->children[par_num];
|
||||||
ntfs_ie_set_vcn (par_ie, vcn);
|
ntfs_ie_set_vcn(par_ie, vcn);
|
||||||
|
|
||||||
par_num--;
|
par_num--;
|
||||||
|
|
||||||
if (ntfs_dt_isroot (par))
|
if (ntfs_dt_isroot(par))
|
||||||
printf (GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, par->dir->inode->mft_no);
|
printf(GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, par->dir->inode->mft_no);
|
||||||
else
|
else
|
||||||
printf (GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, par->dir->inode->mft_no, par->vcn, par->vcn + (par->dir->index_size>>9) - 1);
|
printf(GREEN "Modified: inode %lld, $INDEX_ALLOCATION vcn %lld-%lld\n" END, par->dir->inode->mft_no, par->vcn, par->vcn + (par->dir->index_size>>9) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ntfs_dt_print (top, 0);
|
//ntfs_dt_print(top, 0);
|
||||||
|
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
//utils_dump_mem (par->data, 0, par->data_len, DM_DEFAULTS);
|
//utils_dump_mem(par->data, 0, par->data_len, DM_DEFAULTS);
|
||||||
|
|
||||||
// unhook and hold onto the ded dt's
|
// unhook and hold onto the ded dt's
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
printf (BOLD YELLOW "Remove parent\n" END);
|
printf(BOLD YELLOW "Remove parent\n" END);
|
||||||
|
|
||||||
file = &par->children[par_num]->key.file_name; printf ("\tpar name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par->children[par_num]->key.file_name; printf("\tpar name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
|
|
||||||
add_ie = ntfs_ie_copy (par->children[par_num]);
|
add_ie = ntfs_ie_copy(par->children[par_num]);
|
||||||
add_ie = ntfs_ie_remove_vcn (add_ie);
|
add_ie = ntfs_ie_remove_vcn(add_ie);
|
||||||
if (!add_ie)
|
if (!add_ie)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
//printf ("\n");
|
//printf("\n");
|
||||||
//utils_dump_mem (add_ie, 0, add_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
|
//utils_dump_mem(add_ie, 0, add_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
|
||||||
|
|
||||||
ded = par->sub_nodes[par_num];
|
ded = par->sub_nodes[par_num];
|
||||||
par->sub_nodes[par_num] = NULL;
|
par->sub_nodes[par_num] = NULL;
|
||||||
//ntfs_dt_print (ded, 8);
|
//ntfs_dt_print(ded, 8);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
for (i = 0; i < par->child_count; i++) {
|
for (i = 0; i < par->child_count; i++) {
|
||||||
par_ie = par->children[i];
|
par_ie = par->children[i];
|
||||||
file = &par_ie->key.file_name; printf ("\tdel node, key %d: ", i); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par_ie->key.file_name; printf("\tdel node, key %d: ", i); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
|
printf("\tvcn = %lld\n", ntfs_ie_get_vcn(par_ie));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
//printf ("PAR: %p,%d\n", par, par_num);
|
//printf("PAR: %p,%d\n", par, par_num);
|
||||||
if (ntfs_dt_isroot (par))
|
if (ntfs_dt_isroot(par))
|
||||||
ntfs_dt_root_remove (par, par_num);
|
ntfs_dt_root_remove(par, par_num);
|
||||||
else
|
else
|
||||||
ntfs_dt_alloc_remove (par, par_num);
|
ntfs_dt_alloc_remove(par, par_num);
|
||||||
#endif
|
#endif
|
||||||
//printf ("count = %d\n", par->child_count);
|
//printf("count = %d\n", par->child_count);
|
||||||
//utils_dump_mem (par->data, 0, par->data_len, DM_DEFAULTS);
|
//utils_dump_mem(par->data, 0, par->data_len, DM_DEFAULTS);
|
||||||
//printf ("0x%x\n", (u8*)par->children[0] - par->data);
|
//printf("0x%x\n", (u8*)par->children[0] - par->data);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
for (i = 0; i < par->child_count; i++) {
|
for (i = 0; i < par->child_count; i++) {
|
||||||
par_ie = par->children[i];
|
par_ie = par->children[i];
|
||||||
file = &par_ie->key.file_name; printf ("\tadd node, key %d: ", i); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &par_ie->key.file_name; printf("\tadd node, key %d: ", i); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
|
printf("\tvcn = %lld\n", ntfs_ie_get_vcn(par_ie));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//ntfs_dt_print (top, 0);
|
//ntfs_dt_print(top, 0);
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
printf (BOLD YELLOW "Add childless parent\n" END);
|
printf(BOLD YELLOW "Add childless parent\n" END);
|
||||||
|
|
||||||
file = &add_ie->key.file_name; printf ("\tadd name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &add_ie->key.file_name; printf("\tadd name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
suc = NULL;
|
suc = NULL;
|
||||||
suc_num = -1;
|
suc_num = -1;
|
||||||
suc = ntfs_dt_find4 (top, file->file_name, file->file_name_length, &suc_num);
|
suc = ntfs_dt_find4(top, file->file_name, file->file_name_length, &suc_num);
|
||||||
//printf ("SUC: %p, %d\n", suc, suc_num);
|
//printf("SUC: %p, %d\n", suc, suc_num);
|
||||||
|
|
||||||
if (!suc)
|
if (!suc)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
file = &suc->children[suc_num]->key.file_name; printf ("\tsuc name: "); ntfs_name_print (file->file_name, file->file_name_length); printf ("\n");
|
file = &suc->children[suc_num]->key.file_name; printf("\tsuc name: "); ntfs_name_print(file->file_name, file->file_name_length); printf("\n");
|
||||||
|
|
||||||
// insert key into successor
|
// insert key into successor
|
||||||
// if any new nodes are needed, reuse the preserved nodes
|
// if any new nodes are needed, reuse the preserved nodes
|
||||||
if (!ntfs_dt_add2 (add_ie, suc, suc_num, ded))
|
if (!ntfs_dt_add2(add_ie, suc, suc_num, ded))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
// remove any unused nodes
|
// remove any unused nodes
|
||||||
|
|
@ -762,14 +762,14 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
|
||||||
// XXX reduce size of alloc
|
// XXX reduce size of alloc
|
||||||
// XXX if ded, don't write it back, just update bitmap
|
// XXX if ded, don't write it back, just update bitmap
|
||||||
|
|
||||||
printf ("empty\n");
|
printf("empty\n");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
freedts:
|
freedts:
|
||||||
printf ("\twhole dir is empty\n");
|
printf("\twhole dir is empty\n");
|
||||||
|
|
||||||
commit:
|
commit:
|
||||||
//printf ("commit\n");
|
//printf("commit\n");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -778,7 +778,7 @@ done:
|
||||||
/**
|
/**
|
||||||
* ntfs_file_remove2
|
* ntfs_file_remove2
|
||||||
*/
|
*/
|
||||||
static int ntfs_file_remove2 (ntfs_volume *vol, struct ntfs_dt *dt, int dt_num)
|
static int ntfs_file_remove2(ntfs_volume *vol, struct ntfs_dt *dt, int dt_num)
|
||||||
{
|
{
|
||||||
INDEX_ENTRY *ie;
|
INDEX_ENTRY *ie;
|
||||||
ntfs_inode *ino;
|
ntfs_inode *ino;
|
||||||
|
|
@ -796,20 +796,20 @@ static int ntfs_file_remove2 (ntfs_volume *vol, struct ntfs_dt *dt, int dt_num)
|
||||||
bmp_mft = vol->private_bmp1;
|
bmp_mft = vol->private_bmp1;
|
||||||
bmp_vol = vol->private_bmp2;
|
bmp_vol = vol->private_bmp2;
|
||||||
|
|
||||||
if (1) ntfs_mft_set_inuse6 (ino, bmp_mft, FALSE);
|
if (1) ntfs_mft_set_inuse6(ino, bmp_mft, FALSE);
|
||||||
|
|
||||||
if (1) utils_free_non_residents2 (ino, bmp_vol);
|
if (1) utils_free_non_residents2(ino, bmp_vol);
|
||||||
|
|
||||||
if (1) ntfs_file_remove (vol, dt, dt_num); // remove name from index
|
if (1) ntfs_file_remove(vol, dt, dt_num); // remove name from index
|
||||||
|
|
||||||
if (1) ntfs_dir_truncate (vol, dt->dir);
|
if (1) ntfs_dir_truncate(vol, dt->dir);
|
||||||
|
|
||||||
if (1) ntfs_volume_commit (vol);
|
if (1) ntfs_volume_commit(vol);
|
||||||
|
|
||||||
if (0) ntfs_volume_rollback (vol);
|
if (0) ntfs_volume_rollback(vol);
|
||||||
|
|
||||||
if (0) printf ("last mft = %lld\n", ntfs_bmp_find_last_set (bmp_mft));
|
if (0) printf("last mft = %lld\n", ntfs_bmp_find_last_set(bmp_mft));
|
||||||
if (0) printf ("last vol = %lld\n", ntfs_bmp_find_last_set (bmp_vol));
|
if (0) printf("last vol = %lld\n", ntfs_bmp_find_last_set(bmp_vol));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -817,7 +817,7 @@ static int ntfs_file_remove2 (ntfs_volume *vol, struct ntfs_dt *dt, int dt_num)
|
||||||
/**
|
/**
|
||||||
* ntfs_file_add2
|
* ntfs_file_add2
|
||||||
*/
|
*/
|
||||||
static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
|
static int ntfs_file_add2(ntfs_volume *vol, char *filename)
|
||||||
{
|
{
|
||||||
MFT_REF new_num;
|
MFT_REF new_num;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
|
|
@ -838,20 +838,20 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
|
||||||
struct ntfs_dt *suc = NULL;
|
struct ntfs_dt *suc = NULL;
|
||||||
int suc_num = 0;
|
int suc_num = 0;
|
||||||
|
|
||||||
new_num = ntfs_mft_find_free_entry (vol);
|
new_num = ntfs_mft_find_free_entry(vol);
|
||||||
if (new_num == (MFT_REF) -1)
|
if (new_num == (MFT_REF) -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (rindex (filename, PATH_SEP)) {
|
if (rindex(filename, PATH_SEP)) {
|
||||||
ptr = rindex (filename, PATH_SEP);
|
ptr = rindex(filename, PATH_SEP);
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
dirname = filename;
|
dirname = filename;
|
||||||
filename = ptr + 1;
|
filename = ptr + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf ("looking for %s\n", dirname);
|
printf("looking for %s\n", dirname);
|
||||||
if (utils_pathname_to_inode2 (vol, NULL, dirname, &find) == FALSE) {
|
if (utils_pathname_to_inode2(vol, NULL, dirname, &find) == FALSE) {
|
||||||
printf ("!inode\n");
|
printf("!inode\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -862,18 +862,18 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
|
||||||
if (uname_len < 0)
|
if (uname_len < 0)
|
||||||
goto close;
|
goto close;
|
||||||
|
|
||||||
printf ("new inode %lld\n", new_num);
|
printf("new inode %lld\n", new_num);
|
||||||
ino = ntfs_inode_open3 (vol, new_num);
|
ino = ntfs_inode_open3(vol, new_num);
|
||||||
if (!ino) {
|
if (!ino) {
|
||||||
printf ("!ino\n");
|
printf("!ino\n");
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = (u8*) ino->mrec;
|
tmp = (u8*) ino->mrec;
|
||||||
now = utc2ntfs (time(NULL));
|
now = utc2ntfs(time(NULL));
|
||||||
|
|
||||||
// Wipe all the attributes
|
// Wipe all the attributes
|
||||||
memset (tmp + ino->mrec->attrs_offset, 0, vol->mft_record_size - ino->mrec->attrs_offset);
|
memset(tmp + ino->mrec->attrs_offset, 0, vol->mft_record_size - ino->mrec->attrs_offset);
|
||||||
|
|
||||||
// Add new end marker
|
// Add new end marker
|
||||||
*(u32*) (tmp + ino->mrec->attrs_offset) = 0xFFFFFFFF;
|
*(u32*) (tmp + ino->mrec->attrs_offset) = 0xFFFFFFFF;
|
||||||
|
|
@ -886,74 +886,74 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
|
||||||
ino->mrec->next_attr_instance = 0;
|
ino->mrec->next_attr_instance = 0;
|
||||||
ino->mrec->flags = MFT_RECORD_IN_USE;
|
ino->mrec->flags = MFT_RECORD_IN_USE;
|
||||||
|
|
||||||
ntfs_mft_set_inuse6 (ino, vol->private_bmp1, TRUE);
|
ntfs_mft_set_inuse6(ino, vol->private_bmp1, TRUE);
|
||||||
|
|
||||||
buffer = malloc (128);
|
buffer = malloc(128);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
goto close;
|
goto close;
|
||||||
|
|
||||||
// Standard information
|
// Standard information
|
||||||
memset (buffer, 0, 128);
|
memset(buffer, 0, 128);
|
||||||
*(u64*)(buffer + 0x00) = now; // Time
|
*(u64*)(buffer + 0x00) = now; // Time
|
||||||
*(u64*)(buffer + 0x08) = now; // Time
|
*(u64*)(buffer + 0x08) = now; // Time
|
||||||
*(u64*)(buffer + 0x10) = now; // Time
|
*(u64*)(buffer + 0x10) = now; // Time
|
||||||
*(u64*)(buffer + 0x18) = now; // Time
|
*(u64*)(buffer + 0x18) = now; // Time
|
||||||
ino->creation_time = time (NULL);
|
ino->creation_time = time(NULL);
|
||||||
ino->last_data_change_time = time (NULL);
|
ino->last_data_change_time = time(NULL);
|
||||||
ino->last_mft_change_time = time (NULL);
|
ino->last_mft_change_time = time(NULL);
|
||||||
ino->last_access_time = time (NULL);
|
ino->last_access_time = time(NULL);
|
||||||
attr = ntfs_mft_add_attr (ino, AT_STANDARD_INFORMATION, buffer, 0x48);
|
attr = ntfs_mft_add_attr(ino, AT_STANDARD_INFORMATION, buffer, 0x48);
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
memset (buffer, 0, 128);
|
memset(buffer, 0, 128);
|
||||||
data_len = sprintf ((char*)buffer, "Contents of file: %s\n", filename);
|
data_len = sprintf((char*)buffer, "Contents of file: %s\n", filename);
|
||||||
attr = ntfs_mft_add_attr (ino, AT_DATA, buffer, data_len);
|
attr = ntfs_mft_add_attr(ino, AT_DATA, buffer, data_len);
|
||||||
|
|
||||||
// File name
|
// File name
|
||||||
memset (buffer, 0, 128);
|
memset(buffer, 0, 128);
|
||||||
*(u64*)(buffer + 0x00) = MK_MREF (find.mref, 2); // MFT Ref of parent dir
|
*(u64*)(buffer + 0x00) = MK_MREF(find.mref, 2); // MFT Ref of parent dir
|
||||||
*(u64*)(buffer + 0x08) = now; // Time
|
*(u64*)(buffer + 0x08) = now; // Time
|
||||||
*(u64*)(buffer + 0x10) = now; // Time
|
*(u64*)(buffer + 0x10) = now; // Time
|
||||||
*(u64*)(buffer + 0x18) = now; // Time
|
*(u64*)(buffer + 0x18) = now; // Time
|
||||||
*(u64*)(buffer + 0x20) = now; // Time
|
*(u64*)(buffer + 0x20) = now; // Time
|
||||||
*(u64*)(buffer + 0x28) = ATTR_SIZE (data_len); // Allocated size
|
*(u64*)(buffer + 0x28) = ATTR_SIZE(data_len); // Allocated size
|
||||||
*(u64*)(buffer + 0x30) = data_len; // Initialised size
|
*(u64*)(buffer + 0x30) = data_len; // Initialised size
|
||||||
*(u32*)(buffer + 0x38) = 0; // Flags
|
*(u32*)(buffer + 0x38) = 0; // Flags
|
||||||
*(u32*)(buffer + 0x3C) = 0; // Not relevant
|
*(u32*)(buffer + 0x3C) = 0; // Not relevant
|
||||||
*(u8* )(buffer + 0x40) = uname_len; // Filename length
|
*(u8* )(buffer + 0x40) = uname_len; // Filename length
|
||||||
*(u8* )(buffer + 0x41) = FILE_NAME_POSIX; // Filename namespace
|
*(u8* )(buffer + 0x41) = FILE_NAME_POSIX; // Filename namespace
|
||||||
memcpy (buffer + 0x42, uname, uname_len * sizeof (ntfschar));
|
memcpy(buffer + 0x42, uname, uname_len * sizeof(ntfschar));
|
||||||
attr = ntfs_mft_add_attr (ino, AT_FILE_NAME, buffer, ATTR_SIZE (0x42 + (uname_len * sizeof (ntfschar))));
|
attr = ntfs_mft_add_attr(ino, AT_FILE_NAME, buffer, ATTR_SIZE(0x42 + (uname_len * sizeof(ntfschar))));
|
||||||
attr->resident_flags = RESIDENT_ATTR_IS_INDEXED;
|
attr->resident_flags = RESIDENT_ATTR_IS_INDEXED;
|
||||||
attr->name_offset = 0x18;
|
attr->name_offset = 0x18;
|
||||||
|
|
||||||
ie = ntfs_ie_create();
|
ie = ntfs_ie_create();
|
||||||
ie = ntfs_ie_set_name (ie, uname, uname_len, FILE_NAME_POSIX);
|
ie = ntfs_ie_set_name(ie, uname, uname_len, FILE_NAME_POSIX);
|
||||||
if (!ie) {
|
if (!ie) {
|
||||||
printf ("!ie\n");
|
printf("!ie\n");
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These two NEED the sequence number in the top 8 bits
|
// These two NEED the sequence number in the top 8 bits
|
||||||
ie->key.file_name.parent_directory = MK_MREF (find.mref, 2);// MFT Ref: parent dir
|
ie->key.file_name.parent_directory = MK_MREF(find.mref, 2);// MFT Ref: parent dir
|
||||||
ie->indexed_file = MK_MREF (new_num, ino->mrec->sequence_number);
|
ie->indexed_file = MK_MREF(new_num, ino->mrec->sequence_number);
|
||||||
|
|
||||||
ie->key.file_name.creation_time = now;
|
ie->key.file_name.creation_time = now;
|
||||||
ie->key.file_name.last_data_change_time = now;
|
ie->key.file_name.last_data_change_time = now;
|
||||||
ie->key.file_name.last_mft_change_time = now;
|
ie->key.file_name.last_mft_change_time = now;
|
||||||
ie->key.file_name.last_access_time = now;
|
ie->key.file_name.last_access_time = now;
|
||||||
ie->key.file_name.allocated_size = ATTR_SIZE (data_len);
|
ie->key.file_name.allocated_size = ATTR_SIZE(data_len);
|
||||||
ie->key.file_name.data_size = data_len;
|
ie->key.file_name.data_size = data_len;
|
||||||
|
|
||||||
dir = dt->dir->children[0];
|
dir = dt->dir->children[0];
|
||||||
dt = dir->index;
|
dt = dir->index;
|
||||||
|
|
||||||
suc = ntfs_dt_find3 (dt, uname, uname_len, &suc_num);
|
suc = ntfs_dt_find3(dt, uname, uname_len, &suc_num);
|
||||||
|
|
||||||
ntfs_dt_add2 (ie, suc, suc_num, NULL);
|
ntfs_dt_add2(ie, suc, suc_num, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
dt_index = ntfs_dt_root_add (dt, ie);
|
dt_index = ntfs_dt_root_add(dt, ie);
|
||||||
if (dt_index >= 0) {
|
if (dt_index >= 0) {
|
||||||
dt->inodes[dt_index] = ino;
|
dt->inodes[dt_index] = ino;
|
||||||
ino->ref_count++;
|
ino->ref_count++;
|
||||||
|
|
@ -961,11 +961,11 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
close:
|
close:
|
||||||
free (buffer);
|
free(buffer);
|
||||||
ntfs_inode_close2 (ino);
|
ntfs_inode_close2(ino);
|
||||||
ntfs_ie_free (ie);
|
ntfs_ie_free(ie);
|
||||||
free (uname);
|
free(uname);
|
||||||
ntfs_inode_close2 (find.inode);
|
ntfs_inode_close2(find.inode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -977,7 +977,7 @@ close:
|
||||||
* Return: 0 Success, the program worked
|
* Return: 0 Success, the program worked
|
||||||
* 1 Error, something went wrong
|
* 1 Error, something went wrong
|
||||||
*/
|
*/
|
||||||
int main (int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
ntfs_volume *vol = NULL;
|
ntfs_volume *vol = NULL;
|
||||||
ntfs_inode *inode = NULL;
|
ntfs_inode *inode = NULL;
|
||||||
|
|
@ -985,52 +985,52 @@ int main (int argc, char *argv[])
|
||||||
int result = 1;
|
int result = 1;
|
||||||
struct ntfs_find find;
|
struct ntfs_find find;
|
||||||
|
|
||||||
if (!parse_options (argc, argv))
|
if (!parse_options(argc, argv))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
utils_set_locale();
|
utils_set_locale();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
printf ("sizeof (ntfs_bmp) = %d\n", sizeof (struct ntfs_bmp));
|
printf("sizeof(ntfs_bmp) = %d\n", sizeof(struct ntfs_bmp));
|
||||||
printf ("sizeof (ntfs_dt) = %d\n", sizeof (struct ntfs_dt));
|
printf("sizeof(ntfs_dt) = %d\n", sizeof(struct ntfs_dt));
|
||||||
printf ("sizeof (ntfs_dir) = %d\n", sizeof (struct ntfs_dir));
|
printf("sizeof(ntfs_dir) = %d\n", sizeof(struct ntfs_dir));
|
||||||
printf ("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (opts.noaction)
|
if (opts.noaction)
|
||||||
flags |= MS_RDONLY;
|
flags |= MS_RDONLY;
|
||||||
|
|
||||||
vol = ntfs_volume_mount2 (opts.device, flags, opts.force);
|
vol = ntfs_volume_mount2(opts.device, flags, opts.force);
|
||||||
if (!vol) {
|
if (!vol) {
|
||||||
printf ("!vol\n");
|
printf("!vol\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (utils_pathname_to_inode2 (vol, NULL, opts.file, &find) == FALSE) {
|
if (utils_pathname_to_inode2(vol, NULL, opts.file, &find) == FALSE) {
|
||||||
printf ("!inode\n");
|
printf("!inode\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
inode = find.inode;
|
inode = find.inode;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//printf ("inode = %lld\n", inode->mft_no);
|
//printf("inode = %lld\n", inode->mft_no);
|
||||||
|
|
||||||
if (0) result = ntfs_file_remove2 (vol, find.dt, find.dt_index);
|
if (0) result = ntfs_file_remove2(vol, find.dt, find.dt_index);
|
||||||
if (1) result = ntfs_file_add2 (vol, opts.file);
|
if (1) result = ntfs_file_add2(vol, opts.file);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (1) ntfs_volume_commit (vol);
|
if (1) ntfs_volume_commit(vol);
|
||||||
if (0) ntfs_volume_rollback (vol);
|
if (0) ntfs_volume_rollback(vol);
|
||||||
if (0) ntfs_inode_close2 (inode);
|
if (0) ntfs_inode_close2(inode);
|
||||||
if (1) ntfs_volume_umount2 (vol, FALSE);
|
if (1) ntfs_volume_umount2(vol, FALSE);
|
||||||
|
|
||||||
if (0) utils_pathname_to_inode2 (NULL, NULL, NULL, NULL);
|
if (0) utils_pathname_to_inode2(NULL, NULL, NULL, NULL);
|
||||||
if (0) ntfs_ie_remove_name (NULL);
|
if (0) ntfs_ie_remove_name(NULL);
|
||||||
if (0) ntfs_dt_transfer2 (NULL, NULL, 0, 0);
|
if (0) ntfs_dt_transfer2(NULL, NULL, 0, 0);
|
||||||
if (0) utils_array_remove (NULL, 0, 0, 0);
|
if (0) utils_array_remove(NULL, 0, 0, 0);
|
||||||
if (0) utils_array_insert (NULL, 0, 0, 0);
|
if (0) utils_array_insert(NULL, 0, 0, 0);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,8 +171,8 @@ static void license(void)
|
||||||
/**
|
/**
|
||||||
* usage - print a list of the parameters to the program
|
* usage - print a list of the parameters to the program
|
||||||
*/
|
*/
|
||||||
__attribute__ ((noreturn))
|
__attribute__((noreturn))
|
||||||
static void usage (void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
copyright();
|
copyright();
|
||||||
fprintf(stderr, "Usage: %s [options] device inode [attr-type "
|
fprintf(stderr, "Usage: %s [options] device inode [attr-type "
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue