whitespace fixes - no code changes

edge.strict_endians
flatcap 2005-10-26 22:54:57 +00:00
parent c59d76aed2
commit 8a584700c5
27 changed files with 1268 additions and 1266 deletions

View File

@ -248,8 +248,8 @@ typedef enum {
typedef enum {
MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001),
MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002),
MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004),
MFT_RECORD_IS_8 = const_cpu_to_le16(0x0008),
MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004),
MFT_RECORD_IS_8 = const_cpu_to_le16(0x0008),
MFT_REC_SPACE_FILLER = 0xffff /* Just to make flags 16-bit. */
} __attribute__((__packed__)) MFT_RECORD_FLAGS;
@ -1833,18 +1833,18 @@ typedef struct {
u64 offset_in_sds; /* Offset 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" */
} __attribute__ ((__packed__)) SDH_INDEX_DATA;
} __attribute__((__packed__)) SDH_INDEX_DATA;
typedef struct {
u32 hash; /* Hash of the security descriptor. */
u32 security_id; /* The security_id assigned to the descriptor. */
u64 offset_in_sds; /* Offset 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 {
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
@ -2461,7 +2461,7 @@ typedef struct {
2 = Unexpected type.
3 = Certificate thumbprint.
other = Unknown type. */
union {
union {
/* CryptoAPI container. */
struct {
/* 12*/ u32 container_name_offset; /* Offset in bytes to

View File

@ -1842,7 +1842,7 @@ find_attr_list_attr:
/* Got it. Done. */
if (!rc)
return 0;
return 0;
/* Error! If other than not found return it. */
if (errno != ENOENT)

View File

@ -52,18 +52,18 @@
* and "$Q" as global constants.
*/
ntfschar NTFS_INDEX_I30[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('I'),
const_cpu_to_le16('3'), const_cpu_to_le16('0'),
const_cpu_to_le16('\0') };
const_cpu_to_le16('3'), const_cpu_to_le16('0'),
const_cpu_to_le16('\0') };
ntfschar NTFS_INDEX_SII[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'),
const_cpu_to_le16('I'), const_cpu_to_le16('I'),
const_cpu_to_le16('\0') };
const_cpu_to_le16('I'), const_cpu_to_le16('I'),
const_cpu_to_le16('\0') };
ntfschar NTFS_INDEX_SDH[5] = { const_cpu_to_le16('$'), const_cpu_to_le16('S'),
const_cpu_to_le16('D'), const_cpu_to_le16('H'),
const_cpu_to_le16('\0') };
const_cpu_to_le16('D'), const_cpu_to_le16('H'),
const_cpu_to_le16('\0') };
ntfschar NTFS_INDEX_O[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('O'),
const_cpu_to_le16('\0') };
const_cpu_to_le16('\0') };
ntfschar NTFS_INDEX_Q[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('Q'),
const_cpu_to_le16('\0') };
const_cpu_to_le16('\0') };
/**
* ntfs_inode_lookup_by_name - find an inode in a directory given its name

View File

@ -413,7 +413,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na,
"detected in $LogFile restart page.");
err = EINVAL;
goto err_out;
}
}
}
/*
* If the restart page is modified by chkdsk or there are no active

View File

@ -98,7 +98,7 @@ char *ntfs_guid_to_mbs(const GUID *guid, char *guid_str)
guid->data4[2], guid->data4[3], guid->data4[4],
guid->data4[5], guid->data4[6], guid->data4[7]);
if (res == 36)
return _guid_str;
return _guid_str;
if (!guid_str)
free(_guid_str);
errno = EINVAL;

View File

@ -2046,7 +2046,7 @@ ascend:
//ntfs_log_debug("\tnode has %d children\n", suc->child_count);
// initialise new node
// XXX ntfs_dt_initialise (new, vcn);
// XXX ntfs_dt_initialise(new, vcn);
goto done;

View File

@ -46,7 +46,7 @@
/**
* 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;
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
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;
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 (c_begin == c_end)
Vprintf ("cluster isn't in use\n");
Vprintf("cluster isn't in use\n");
else
Vprintf ("clusters aren't in use\n");
Vprintf("clusters aren't in use\n");
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;
while (mft_next_record (m_ctx) == 0) {
//Qprintf (RED "Inode: %llu\n" NORM, (unsigned long long)
Qprintf ("Inode: %llu\n", (unsigned long long)
while (mft_next_record(m_ctx) == 0) {
//Qprintf(RED "Inode: %llu\n" NORM, (unsigned long long)
Qprintf("Inode: %llu\n", (unsigned long long)
m_ctx->inode->mft_no);
if (!(m_ctx->flags_match & FEMR_BASE_RECORD))
continue;
Vprintf ("Inode: %llu\n", (unsigned long long)
Vprintf("Inode: %llu\n", (unsigned long long)
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) {
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;
}
runs = ntfs_mapping_pairs_decompress (vol, a_ctx->attr, NULL);
runs = ntfs_mapping_pairs_decompress(vol, a_ctx->attr, NULL);
if (!runs) {
Eprintf ("Couldn't read the data runs.\n");
Eprintf("Couldn't read the data runs.\n");
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++) {
LCN a_begin = runs[j].lcn;
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)
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].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;
}
result = 0;
done:
ntfs_attr_put_search_ctx (a_ctx);
mft_put_search_ctx (m_ctx);
ntfs_attr_put_search_ctx(a_ctx);
mft_put_search_ctx(m_ctx);
return result;
}

View File

@ -31,9 +31,9 @@ typedef struct {
int x;
} 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_ */

View File

@ -305,7 +305,7 @@ static void license(void)
/**
* usage - print a list of the parameters to the program
*/
__attribute__ ((noreturn))
__attribute__((noreturn))
static void usage(void)
{
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,
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)
{
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,
o_size, m,
NTFS_INDEX_O, 2, AT_UNUSED);
if (idx_entry_o) free (idx_entry_o);
if (idx_entry_o) free(idx_entry_o);
return err;
}

View File

@ -50,10 +50,10 @@
static const char *EXEC_NAME = "ntfscat";
static struct options opts;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stderr, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stderr, &opts.quiet, FALSE)
static GEN_PRINTF (Printf, stderr, NULL, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stderr, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stderr, &opts.quiet, FALSE)
static GEN_PRINTF(Printf, stderr, NULL, FALSE)
/**
* version - Print version information about the program
@ -62,7 +62,7 @@ static GEN_PRINTF (Printf, stderr, NULL, FALSE)
*
* Return: none
*/
static void version (void)
static void version(void)
{
Printf("\n%s v%s (libntfs %s) - Concatenate files and print on the "
"standard output.\n\n", EXEC_NAME, VERSION,
@ -78,17 +78,17 @@ static void version (void)
*
* Return: none
*/
static void usage (void)
static void usage(void)
{
Printf ("\nUsage: %s [options] device [file]\n\n"
" -a, --attribute type Display this attribute type\n"
" -n, --attribute-name name Display this attribute name\n"
" -i, --inode num Display this inode\n\n"
" -f --force Use less caution\n"
" -h --help Print this help\n"
" -q --quiet Less output\n"
" -V --version Version information\n"
" -v --verbose More output\n\n",
" -a, --attribute type Display this attribute type\n"
" -n, --attribute-name name Display this attribute name\n"
" -i, --inode num Display this inode\n\n"
" -f --force Use less caution\n"
" -h --help Print this help\n"
" -q --quiet Less output\n"
" -V --version Version information\n"
" -v --verbose More output\n\n",
//" -r --raw Display the compressed or encrypted file",
EXEC_NAME);
Printf ("%s%s\n", ntfs_bugs, ntfs_home);
@ -106,7 +106,7 @@ static void usage (void)
* Return: 1 Success, a valid 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[] = {
"$STANDARD_INFORMATION",
@ -132,14 +132,14 @@ static int parse_attribute (const char *value, ATTR_TYPES *attr)
long num;
for (i = 0; attr_name[i]; i++) {
if ((strcmp (value, attr_name[i]) == 0) ||
(strcmp (value, attr_name[i]+1) == 0)) {
if ((strcmp(value, attr_name[i]) == 0) ||
(strcmp(value, attr_name[i]+1) == 0)) {
*attr = (ATTR_TYPES) ((i+1)*16);
return 1;
}
}
num = strtol (value, NULL, 0);
num = strtol(value, NULL, 0);
if ((num > 0) && (num < 257)) {
*attr = (ATTR_TYPES) num;
return 1;
@ -157,7 +157,7 @@ static int parse_attribute (const char *value, ATTR_TYPES *attr)
* Return: 1 Success
* 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 struct option lopt[] = {
@ -185,7 +185,7 @@ static int parse_options (int argc, char **argv)
opts.attr_name = NULL;
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) {
case 1: /* A non-option argument */
if (!opts.device) {
@ -200,7 +200,7 @@ static int parse_options (int argc, char **argv)
case 'a':
if (opts.attr != (ATTR_TYPES)-1) {
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;
break;
} else {
@ -226,7 +226,7 @@ static int parse_options (int argc, char **argv)
break;
case 'n':
opts.attr_name_len = ntfs_mbstoucs(optarg,
opts.attr_name_len = ntfs_mbstoucs(optarg,
&opts.attr_name, 0);
if (opts.attr_name_len < 0) {
Eprintf("Invalid attribute name '%s': %s\n",
@ -244,7 +244,7 @@ static int parse_options (int argc, char **argv)
opts.verbose++;
break;
default:
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
@ -254,16 +254,16 @@ static int parse_options (int argc, char **argv)
opts.quiet = 0;
} else {
if (opts.device == NULL) {
Eprintf ("You must specify a device.\n");
Eprintf("You must specify a device.\n");
err++;
} 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");
err++;
} 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++;
}
@ -291,12 +291,12 @@ static int parse_options (int argc, char **argv)
* Return: n Success, the INDX blocks are n bytes in size
* 0 Error, not a directory
*/
static int index_get_size (ntfs_inode *inode)
static int index_get_size(ntfs_inode *inode)
{
ATTR_RECORD *attr90;
INDEX_ROOT *iroot;
attr90 = find_first_attribute (AT_INDEX_ROOT, inode->mrec);
attr90 = find_first_attribute(AT_INDEX_ROOT, inode->mrec);
if (!attr90)
return 0; // not a directory
@ -308,7 +308,7 @@ static int index_get_size (ntfs_inode *inode)
/**
* 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)
{
const int bufsize = 4096;
@ -318,21 +318,21 @@ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
s64 offset;
u32 block_size;
buffer = malloc (bufsize);
buffer = malloc(bufsize);
if (!buffer)
return 1;
attr = ntfs_attr_open (inode, type, name, namelen);
attr = ntfs_attr_open(inode, type, name, namelen);
if (!attr) {
Eprintf ("Cannot find attribute type 0x%lx.\n", (long) type);
free (buffer);
Eprintf("Cannot find attribute type 0x%lx.\n", (long) type);
free(buffer);
return 1;
}
if ((inode->mft_no < 2) && (attr->type == AT_DATA))
block_size = vol->mft_record_size;
else if (attr->type == AT_INDEX_ALLOCATION)
block_size = index_get_size (inode);
block_size = index_get_size(inode);
else
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 *= block_size;
} 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) {
perror ("ERROR: Couldn't read file");
perror("ERROR: Couldn't read file");
break;
}
if (!bytes_read)
break;
written = fwrite (buffer, 1, bytes_read, stdout);
written = fwrite(buffer, 1, bytes_read, stdout);
if (written != bytes_read) {
perror ("ERROR: Couldn't output all data!");
perror("ERROR: Couldn't output all data!");
break;
}
offset += bytes_read;
}
ntfs_attr_close (attr);
free (buffer);
ntfs_attr_close(attr);
free(buffer);
return 0;
}
@ -374,28 +374,28 @@ static int cat (ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
* Return: 0 Success, the program worked
* 1 Error, something went wrong
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
ntfs_volume *vol;
ntfs_inode *inode;
ATTR_TYPES attr;
int result = 1;
if (!parse_options (argc, argv))
if (!parse_options(argc, argv))
return 1;
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) {
perror("ERROR: couldn't mount volume");
return 1;
}
if (opts.inode != -1)
inode = ntfs_inode_open (vol, opts.inode);
inode = ntfs_inode_open(vol, opts.inode);
else
inode = ntfs_pathname_to_inode (vol, NULL, opts.file);
inode = ntfs_pathname_to_inode(vol, NULL, opts.file);
if (!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);
ntfs_inode_close (inode);
ntfs_umount (vol, FALSE);
ntfs_inode_close(inode);
ntfs_umount(vol, FALSE);
return result;
}

View File

@ -154,7 +154,7 @@ struct {
s64 device_size;
s64 nr_clusters;
s64 inuse;
} __attribute__ ((__packed__)) image_hdr;
} __attribute__((__packed__)) image_hdr;
#define NTFS_MBYTE (1000 * 1000)
@ -499,7 +499,7 @@ static void rescue_sector(void *fd, off_t pos, void *buff)
if (read_all(fd, buff, NTFS_SECTOR_SIZE) == -1) {
Printf("WARNING: Can't read sector at %llu, lost data.\n",
(unsigned long long)pos);
(unsigned long long)pos);
memset(buff, '?', NTFS_SECTOR_SIZE);
memmove(buff, badsector_magic, sizeof(badsector_magic));
}
@ -991,9 +991,9 @@ static int walk_clusters(ntfs_volume *volume, struct ntfs_walk_cluster *walk)
continue;
}
deleted_inode = !(ni->mrec->flags & MFT_RECORD_IN_USE);
deleted_inode = !(ni->mrec->flags & MFT_RECORD_IN_USE);
if (deleted_inode) {
if (deleted_inode) {
ni->mft_no = MREF(mref);
if (wipe) {
@ -1007,7 +1007,7 @@ static int walk_clusters(ntfs_volume *volume, struct ntfs_walk_cluster *walk)
free(ni->mrec);
free(ni);
if (deleted_inode)
if (deleted_inode)
continue;
if ((ni = ntfs_inode_open(volume, mref)) == NULL) {
@ -1468,10 +1468,10 @@ int main(int argc, char **argv)
ntfs_size += 512; /* add backup boot sector */
if (opt.std_out) {
if ((fd_out = fileno(stdout)) == -1)
perr_exit("fileno for stdout failed");
if ((fd_out = fileno(stdout)) == -1)
perr_exit("fileno for stdout failed");
} else {
/* device_size_get() might need to read() */
/* device_size_get() might need to read() */
int flags = O_RDWR;
if (!opt.blkdev_out) {

View File

@ -53,9 +53,9 @@
static const char *EXEC_NAME = "ntfscluster";
static struct options opts;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
/**
* version - Print version information about the program
@ -64,13 +64,13 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
*
* 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 "
"cluster.\n\n", EXEC_NAME, VERSION,
ntfs_libntfs_version());
printf ("Copyright (c) 2002-2003 Richard Russon\n");
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
printf("Copyright (c) 2002-2003 Richard Russon\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -80,9 +80,9 @@ static void version (void)
*
* 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"
"\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"
" -h --help Print this help\n\n",
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
* 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 struct option lopt[] = {
@ -139,7 +139,7 @@ static int parse_options (int argc, char **argv)
opts.range_begin = -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) {
case 1: /* A non-option argument */
if (!opts.device) {
@ -152,7 +152,7 @@ static int parse_options (int argc, char **argv)
case 'c':
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;
else
opts.action = act_error;
@ -175,7 +175,7 @@ static int parse_options (int argc, char **argv)
case 'I':
if (opts.action == act_none) {
opts.action = act_inode;
opts.inode = strtol (optarg, &end, 0);
opts.inode = strtol(optarg, &end, 0);
if (end && *end)
err++;
} else {
@ -199,7 +199,7 @@ static int parse_options (int argc, char **argv)
break;
case 's':
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;
else
opts.action = act_error;
@ -212,9 +212,9 @@ static int parse_options (int argc, char **argv)
break;
default:
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
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
@ -230,20 +230,20 @@ static int parse_options (int argc, char **argv)
if (opts.device == NULL) {
if (argc > 1)
Eprintf ("You must specify exactly one device.\n");
Eprintf("You must specify exactly one device.\n");
err++;
}
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++;
}
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++;
} 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++;
}
}
@ -260,7 +260,7 @@ static int parse_options (int argc, char **argv)
/**
* 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;
int cb, sb, cps;
@ -273,23 +273,23 @@ static int info (ntfs_volume *vol)
int z;
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;
while (mft_next_record (m_ctx) == 0) {
while (mft_next_record(m_ctx) == 0) {
if (!(m_ctx->flags_match & FEMR_IN_USE))
continue;
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)
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++)
{
@ -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;
sb = vol->sector_size_bits;
@ -340,27 +340,27 @@ static int info (ntfs_volume *vol)
t = mc >> cb;
u = mc * 100 / b / e;
printf ("bytes per sector : %llu\n", (unsigned long long)a);
printf ("bytes per cluster : %llu\n", (unsigned long long)b);
printf ("sectors per cluster : %llu\n", (unsigned long long)c);
printf ("bytes per volume : %llu\n", (unsigned long long)d);
printf ("sectors per volume : %llu\n", (unsigned long long)e);
printf ("clusters per volume : %llu\n", (unsigned long long)f);
printf ("initialized mft records : %llu\n", (unsigned long long)g);
printf ("mft records in use : %llu\n", (unsigned long long)h);
printf ("mft records percentage : %llu\n", (unsigned long long)i);
printf ("bytes of free space : %llu\n", (unsigned long long)j);
printf ("sectors of free space : %llu\n", (unsigned long long)k);
printf ("clusters of free space : %llu\n", (unsigned long long)l);
printf ("percentage free space : %llu\n", (unsigned long long)m);
printf ("bytes of user data : %llu\n", (unsigned long long)n);
printf ("sectors of user data : %llu\n", (unsigned long long)o);
printf ("clusters of user data : %llu\n", (unsigned long long)p);
printf ("percentage user data : %llu\n", (unsigned long long)q);
printf ("bytes of metadata : %llu\n", (unsigned long long)r);
printf ("sectors of metadata : %llu\n", (unsigned long long)s);
printf ("clusters of metadata : %llu\n", (unsigned long long)t);
printf ("percentage metadata : %llu\n", (unsigned long long)u);
printf("bytes per sector : %llu\n", (unsigned long long)a);
printf("bytes per cluster : %llu\n", (unsigned long long)b);
printf("sectors per cluster : %llu\n", (unsigned long long)c);
printf("bytes per volume : %llu\n", (unsigned long long)d);
printf("sectors per volume : %llu\n", (unsigned long long)e);
printf("clusters per volume : %llu\n", (unsigned long long)f);
printf("initialized mft records : %llu\n", (unsigned long long)g);
printf("mft records in use : %llu\n", (unsigned long long)h);
printf("mft records percentage : %llu\n", (unsigned long long)i);
printf("bytes of free space : %llu\n", (unsigned long long)j);
printf("sectors of free space : %llu\n", (unsigned long long)k);
printf("clusters of free space : %llu\n", (unsigned long long)l);
printf("percentage free space : %llu\n", (unsigned long long)m);
printf("bytes of user data : %llu\n", (unsigned long long)n);
printf("sectors of user data : %llu\n", (unsigned long long)o);
printf("clusters of user data : %llu\n", (unsigned long long)p);
printf("percentage user data : %llu\n", (unsigned long long)q);
printf("bytes of metadata : %llu\n", (unsigned long long)r);
printf("sectors of metadata : %llu\n", (unsigned long long)s);
printf("clusters of metadata : %llu\n", (unsigned long long)t);
printf("percentage metadata : %llu\n", (unsigned long long)u);
return 0;
}
@ -368,7 +368,7 @@ static int info (ntfs_volume *vol)
/**
* 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];
ntfs_attr_search_ctx *ctx;
@ -376,41 +376,41 @@ static int dump_file (ntfs_volume *vol, ntfs_inode *ino)
int i;
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))) {
printf (" 0x%02x - ", rec->type);
while ((rec = find_attribute(AT_UNUSED, ctx))) {
printf(" 0x%02x - ", rec->type);
if (rec->non_resident) {
printf ("non-resident\n");
runs = ntfs_mapping_pairs_decompress (vol, rec, NULL);
printf("non-resident\n");
runs = ntfs_mapping_pairs_decompress(vol, rec, NULL);
if (runs) {
printf (" VCN LCN Length\n");
printf(" VCN LCN Length\n");
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].lcn,
(long long)
runs[i].length);
}
free (runs);
free(runs);
}
} else {
printf ("resident\n");
printf("resident\n");
}
}
ntfs_attr_put_search_ctx (ctx);
ntfs_attr_put_search_ctx(ctx);
return 0;
}
/**
* 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)))
{
char *buffer;
@ -418,26 +418,26 @@ static int print_match (ntfs_inode *ino, ATTR_RECORD *attr,
if (!ino || !attr || !run)
return 1;
buffer = malloc (MAX_PATH);
buffer = malloc(MAX_PATH);
if (!buffer) {
Eprintf ("!buffer\n");
Eprintf("!buffer\n");
return 1;
}
utils_inode_get_name (ino, buffer, MAX_PATH);
printf ("Inode %llu %s", (unsigned long long)ino->mft_no, buffer);
utils_inode_get_name(ino, buffer, MAX_PATH);
printf("Inode %llu %s", (unsigned long long)ino->mft_no, buffer);
utils_attr_get_name (ino->vol, attr, buffer, MAX_PATH);
printf ("/%s\n", buffer);
utils_attr_get_name(ino->vol, attr, buffer, MAX_PATH);
printf("/%s\n", buffer);
free (buffer);
free(buffer);
return 0;
}
/**
* 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)
{
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
* 1 Error, something went wrong
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
ntfs_volume *vol;
ntfs_inode *ino = NULL;
struct match m;
int result = 1;
if (!parse_options (argc, argv))
if (!parse_options(argc, argv))
return 1;
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)
return 1;
switch (opts.action) {
case act_sector:
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);
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 */
opts.range_begin >>= (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;
case act_cluster:
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);
else
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);
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);
break;
case act_file:
ino = ntfs_pathname_to_inode(vol, NULL, opts.filename);
if (ino)
result = dump_file (vol, ino);
result = dump_file(vol, ino);
break;
case act_inode:
ino = ntfs_inode_open (vol, opts.inode);
ino = ntfs_inode_open(vol, opts.inode);
if (ino) {
result = dump_file (vol, ino);
ntfs_inode_close (ino);
result = dump_file(vol, ino);
ntfs_inode_close(ino);
} else {
Eprintf ("Cannot open inode %llu\n",
Eprintf("Cannot open inode %llu\n",
(unsigned long long)opts.inode);
}
break;
case act_last:
memset (&m, 0, sizeof (m));
memset(&m, 0, sizeof(m));
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) {
ino = ntfs_inode_open (vol, m.inum);
ino = ntfs_inode_open(vol, m.inum);
if (ino) {
result = dump_file (vol, ino);
ntfs_inode_close (ino);
result = dump_file(vol, ino);
ntfs_inode_close(ino);
} else {
Eprintf ("Cannot open inode %llu\n",
Eprintf("Cannot open inode %llu\n",
(unsigned long long)
opts.inode);
}
@ -535,11 +535,11 @@ int main (int argc, char *argv[])
break;
case act_info:
default:
result = info (vol);
result = info(vol);
break;
}
ntfs_umount (vol, FALSE);
ntfs_umount(vol, FALSE);
return result;
}

View File

@ -153,7 +153,7 @@ __attribute__((noreturn))
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"
"\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"
#endif
"\n", EXEC_NAME);
printf ("%s%s", ntfs_bugs, ntfs_home);
printf("%s%s", ntfs_bugs, ntfs_home);
exit(1);
}
@ -186,7 +186,7 @@ static void parse_options(int argc, char **argv)
memset(&opt, 0, sizeof(opt));
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) {
case 1: /* A non-option argument */
if (!opt.vol1) {

View File

@ -69,10 +69,10 @@ static const char *EXEC_NAME = "ntfscp";
static struct options opts;
volatile sig_atomic_t caught_terminate = 0;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stderr, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stderr, &opts.quiet, FALSE)
static GEN_PRINTF (Printf, stderr, NULL, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stderr, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stderr, &opts.quiet, FALSE)
static GEN_PRINTF(Printf, stderr, NULL, FALSE)
/**
* version - Print version information about the program
@ -81,12 +81,12 @@ static GEN_PRINTF (Printf, stderr, NULL, FALSE)
*
* Return: none
*/
static void version (void)
static void version(void)
{
Printf("\n%s v%s (libntfs %s) - Overwrite files on NTFS volume.\n\n",
EXEC_NAME, VERSION, ntfs_libntfs_version());
Printf ("Copyright (c) 2004-2005 Yura Pakhuchiy\n");
Printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
Printf("Copyright (c) 2004-2005 Yura Pakhuchiy\n");
Printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -96,9 +96,9 @@ static void version (void)
*
* 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"
" -i --inode Treat dest_file as inode number\n"
" -f --force Use less caution\n"
@ -109,7 +109,7 @@ static void usage (void)
" -V --version Version information\n"
" -v --verbose More output\n\n",
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
* 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 struct option lopt[] = {
@ -263,7 +263,7 @@ static void signal_handler(int arg __attribute__((unused)))
* Return: 0 Success, the program worked
* 1 Error, something went wrong
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
FILE *in;
ntfs_volume *vol;
@ -308,7 +308,7 @@ int main (int argc, char *argv[])
{
struct stat fst;
if (stat (opts.src_file, &fst) == -1) {
if (stat(opts.src_file, &fst) == -1) {
perror("ERROR: Couldn't stat source file");
goto umount;
}

View File

@ -87,7 +87,7 @@ typedef struct {
};
} logfile_file;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
/**
* 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.
* if you don't have some parameter to pass, just pass NULL.
*/
__attribute__ ((noreturn))
__attribute__ ((format(printf, 4, 5)))
__attribute__((noreturn))
__attribute__((format(printf, 4, 5)))
static void device_err_exit(ntfs_volume *vol, ntfs_inode *ni,
ntfs_attr *na, const char *fmt, ...)
{
@ -147,7 +147,7 @@ static void device_err_exit(ntfs_volume *vol, ntfs_inode *ni,
/**
* log_err_exit -
*/
__attribute__ ((noreturn))
__attribute__((noreturn))
__attribute__((format(printf, 2, 3)))
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 -
*/
__attribute__ ((noreturn))
__attribute__((noreturn))
static void usage(const char *exec_name)
{
Eprintf("%s v%s (libntfs %s) - Interpret and display information "

View File

@ -136,7 +136,7 @@ static void parse_options(int argc, char **argv)
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) {
case 1: /* A non-option argument */
if (!opt.volume)
@ -307,7 +307,7 @@ static int fix_mftmirr(ntfs_volume *vol)
unsigned char *m, *m2;
int i, ret = -1; /* failure */
BOOL done;
puts("\nProcessing $MFT and $MFTMirr... ");
/* Load data from $MFT and $MFTMirr and compare the contents. */
@ -426,7 +426,7 @@ static int fix_mount(void)
int ret = -1; /* failure */
ntfs_volume *vol;
struct ntfs_device *dev;
printf("Attempting to correct errors... ");
dev = ntfs_device_alloc(opt.volume, 0, &ntfs_device_default_io_ops, NULL);

View File

@ -92,9 +92,9 @@ static struct options {
u8 padding[4]; /* Unused: padding to 64 bit. */
} opts;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
/**
* version - Print version information about the program
@ -103,18 +103,18 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
*
* 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,
ntfs_libntfs_version());
printf ("Copyright (c)\n");
printf (" 2002-2004 Matthew J. Fanto\n");
printf (" 2002-2005 Anton Altaparmakov\n");
printf (" 2002-2003 Richard Russon\n");
printf (" 2003 Leonard Norrgård\n");
printf (" 2004-2005 Yura Pakhuchiy\n");
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
printf("Copyright (c)\n");
printf(" 2002-2004 Matthew J. Fanto\n");
printf(" 2002-2005 Anton Altaparmakov\n");
printf(" 2002-2003 Richard Russon\n");
printf(" 2003 Leonard Norrgård\n");
printf(" 2004-2005 Yura Pakhuchiy\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -124,9 +124,9 @@ static void version (void)
*
* 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"
" -i num --inode num Display information about this inode\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"
" -h --help Display this help\n\n",
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
* 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 struct option lopt[] = {
@ -178,7 +178,7 @@ static int parse_options (int argc, char *argv[])
opts.inode = -1;
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,
optarg);
switch (c) {
@ -190,7 +190,7 @@ static int parse_options (int argc, char *argv[])
break;
case 'i':
if ((opts.inode != -1) ||
(!utils_parse_size (optarg, &opts.inode, FALSE))) {
(!utils_parse_size(optarg, &opts.inode, FALSE))) {
err++;
}
break;
@ -217,7 +217,7 @@ static int parse_options (int argc, char *argv[])
break;
case 'T':
/* '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++;
break;
case 'v':
@ -257,24 +257,24 @@ static int parse_options (int argc, char *argv[])
} else {
if (opts.device == NULL) {
if (argc > 1)
Eprintf ("You must specify exactly one device.\n");
Eprintf("You must specify exactly one device.\n");
err++;
}
if ((opts.inode == -1) && (opts.filename == NULL) && !opts.mft) {
if (argc > 1)
Eprintf ("You must specify an inode to learn about.\n");
Eprintf("You must specify an inode to learn about.\n");
err++;
}
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++;
}
if ((opts.inode != -1) && (opts.filename != NULL)) {
if (argc > 1)
Eprintf ("You may not specify --inode and --file together.\n");
Eprintf("You may not specify --inode and --file together.\n");
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);
if (rl) {
runlist *rlc = rl;
printf ("\tRunlist:\tVCN\t\tLCN\t\tLength\n");
printf("\tRunlist:\tVCN\t\tLCN\t\tLength\n");
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++;
}
free (rl);
free(rl);
} else {
Eprintf("ntfsinfo error: could not decompress runlist\n");
return;
@ -1872,12 +1872,12 @@ int main(int argc, char **argv)
{
ntfs_volume *vol;
if (!parse_options (argc, argv))
if (!parse_options(argc, argv))
return 1;
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)
return 1;
@ -1913,7 +1913,7 @@ int main(int argc, char **argv)
}
}
ntfs_umount (vol, FALSE);
ntfs_umount(vol, FALSE);
return 0;
}

View File

@ -60,9 +60,9 @@ static struct options {
int noaction; /* Do not write to disk */
} opts;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
/**
* version - Print version information about the program
@ -71,16 +71,16 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
*
* 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_libntfs_version());
printf ("Copyright (c)\n");
printf (" 2002 Matthew J. Fanto\n");
printf (" 2002-2005 Anton Altaparmakov\n");
printf (" 2002-2003 Richard Russon\n");
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
printf("Copyright (c)\n");
printf(" 2002 Matthew J. Fanto\n");
printf(" 2002-2005 Anton Altaparmakov\n");
printf(" 2002-2003 Richard Russon\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -90,9 +90,9 @@ static void version (void)
*
* 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"
" -f --force Use less caution\n"
" -q --quiet Less output\n"
@ -100,7 +100,7 @@ static void usage (void)
" -V --version Display version information\n"
" -h --help Display this help\n\n",
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
* 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 struct option lopt[] = {
@ -132,7 +132,7 @@ static int parse_options (int argc, char *argv[])
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) {
case 1: /* A non-option argument */
if (!err && !opts.device)
@ -162,7 +162,7 @@ static int parse_options (int argc, char *argv[])
ver++;
break;
default:
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
@ -173,12 +173,12 @@ static int parse_options (int argc, char *argv[])
} else {
if (opts.device == NULL) {
if (argc > 1)
Eprintf ("You must specify a device.\n");
Eprintf("You must specify a device.\n");
err++;
}
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");
err++;
}
@ -201,13 +201,13 @@ static int parse_options (int argc, char *argv[])
*
* 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;
//XXX significant?
if ((mnt_flags & (NTFS_MF_MOUNTED | NTFS_MF_READONLY)) ==
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);
result = 1;
}
@ -372,7 +372,7 @@ int main(int argc, char **argv)
int result = 0;
ntfs_volume *vol;
if (!parse_options (argc, argv))
if (!parse_options(argc, argv))
return 1;
utils_set_locale();
@ -380,17 +380,17 @@ int main(int argc, char **argv)
if (!opts.label)
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);
if (!vol)
return 1;
if (opts.label)
result = change_label (vol, mnt_flags, opts.label, opts.force);
result = change_label(vol, mnt_flags, opts.label, opts.force);
else
result = print_label (vol, mnt_flags);
result = print_label(vol, mnt_flags);
ntfs_umount (vol, FALSE);
ntfs_umount(vol, FALSE);
return result;
}

View File

@ -275,7 +275,7 @@ static int parse_options(int argc, char *argv[])
/* defaults to -a if -s is not specified */
if (!opts.system)
opts.all++;
opts.all++;
if (help || ver)
opts.quiet = 0;
@ -484,12 +484,12 @@ static int list_dir_entry(ntfsls_dirent * dirent, const ntfschar * name,
struct dir *dir = NULL;
filename = calloc (1, MAX_PATH);
filename = calloc(1, MAX_PATH);
if (!filename)
return -1;
if (ntfs_ucstombs (name, name_len, &filename, MAX_PATH) < 0) {
Eprintf ("Cannot represent filename in current locale.\n");
if (ntfs_ucstombs(name, name_len, &filename, MAX_PATH) < 0) {
Eprintf("Cannot represent filename in current locale.\n");
goto free;
}
@ -606,7 +606,7 @@ release:
}
free:
free (filename);
free(filename);
return result;
}
@ -641,7 +641,7 @@ int main(int argc, char **argv)
return 2;
}
ni = ntfs_pathname_to_inode (vol, NULL, opts.path);
ni = ntfs_pathname_to_inode(vol, NULL, opts.path);
if (!ni) {
// FIXME: Print error... (AIA)
ntfs_umount(vol, FALSE);
@ -674,9 +674,9 @@ int main(int argc, char **argv)
if (!ctx)
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. */
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) {
name = attr->file_name;

View File

@ -166,8 +166,8 @@ static void license(void)
/**
* usage - print a list of the parameters to the program
*/
__attribute__ ((noreturn))
static void usage (void)
__attribute__((noreturn))
static void usage(void)
{
copyright();
fprintf(stderr, "Usage: %s [options] device [base-mft-record]\n"

View File

@ -80,7 +80,7 @@ typedef enum {
NF_STREAMS_INTERFACE_NONE, /* No access to named data streams. */
#if 0
NF_STREAMS_INTERFACE_XATTR, /* Map named data streams to xattrs. */
#endif
#endif
NF_STREAMS_INTERFACE_WINDOWS, /* "file:stream" interface. */
} ntfs_fuse_streams_interface;
@ -670,7 +670,7 @@ static int ntfs_fuse_link(const char *old_path, const char *new_path)
if (strchr(old_path, ':') && /* n/a for named data streams. */
ctx->streams == NF_STREAMS_INTERFACE_WINDOWS)
return -EINVAL;
return -EINVAL;
if (strchr(new_path, ':') && /* n/a for named data streams. */
ctx->streams == NF_STREAMS_INTERFACE_WINDOWS)
return -EINVAL;

View File

@ -50,9 +50,9 @@
static const char *EXEC_NAME = "ntfsmove";
static struct options opts;
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
#if 0
#define RED "\e[31m"
@ -68,13 +68,13 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
*
* 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_libntfs_version());
printf ("Copyright (c) 2003 Richard Russon\n");
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
printf("Copyright (c) 2003 Richard Russon\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -84,9 +84,9 @@ static void version (void)
*
* 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"
" -S --start Move to the start of 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 --verbose More output\n\n",
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
* 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 struct option lopt[] = {
@ -139,7 +139,7 @@ static int parse_options (int argc, char **argv)
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) {
case 1: /* A non-option argument */
if (!opts.device) {
@ -160,7 +160,7 @@ static int parse_options (int argc, char **argv)
break;
case 'C':
if (opts.location == 0) {
opts.location = strtoll (optarg, &end, 0);
opts.location = strtoll(optarg, &end, 0);
if (end && *end)
err++;
} else {
@ -202,7 +202,7 @@ static int parse_options (int argc, char **argv)
opts.verbose++;
break;
default:
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
@ -214,7 +214,7 @@ static int parse_options (int argc, char **argv)
if ((opts.device == NULL) ||
(opts.file == NULL)) {
if (argc > 1)
Eprintf ("You must specify one device and one file.\n");
Eprintf("You must specify one device and one file.\n");
err++;
}
@ -225,7 +225,7 @@ static int parse_options (int argc, char **argv)
}
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");
err++;
} else if (opts.location == 0) {
@ -246,7 +246,7 @@ static int parse_options (int argc, char **argv)
/**
* 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 len = 0;
@ -274,7 +274,7 @@ static int ntfs_debug_runlist_dump2 (const runlist *rl, int abbr, char *prefix)
if (abbr)
if (len > 20) {
if ((i == abbr) && (len > (abbr*2)))
printf ("%s ... ... ...\n", prefix);
printf("%s ... ... ...\n", prefix);
if ((i > (abbr-1)) && (i < (len - (abbr-1))))
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,
rl->vcn, rl->lcn, rl->length);
}
printf ("%s --------\n", prefix);
printf ("%s %8lld\n", prefix, total);
printf ("\n");
printf("%s --------\n", prefix);
printf("%s %8lld\n", prefix, total);
printf("\n");
return res;
}
@ -306,7 +306,7 @@ static int ntfs_debug_runlist_dump2 (const runlist *rl, int abbr, char *prefix)
/**
* 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 next_attr;
@ -323,15 +323,15 @@ static int resize_nonres_attr (MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size
ptr = (u8*) m;
/*
printf ("old_size = %d\n", old_size);
printf ("new_size = %d\n", new_size);
printf ("file_size = %d\n", file_size);
printf ("this_attr = %d\n", this_attr);
printf ("next_attr = %d\n", next_attr);
printf ("tail_size = %d\n", tail_size);
printf("old_size = %d\n", old_size);
printf("new_size = %d\n", new_size);
printf("file_size = %d\n", file_size);
printf("this_attr = %d\n", this_attr);
printf("next_attr = %d\n", next_attr);
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;
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
*/
static int calc_attr_length (ATTR_RECORD *rec, int runlength)
static int calc_attr_length(ATTR_RECORD *rec, int runlength)
{
int size;
@ -361,15 +361,15 @@ static int calc_attr_length (ATTR_RECORD *rec, int runlength)
/**
* dump_runs
*/
static void dump_runs (u8 *buffer, int len)
static void dump_runs(u8 *buffer, int len)
{
int i;
printf ("RUN: \e[01;31m");
printf("RUN: \e[01;31m");
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 */
@ -377,7 +377,7 @@ static void dump_runs (u8 *buffer, int len)
/**
* 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)))
{
const int bufsize = 8192;
@ -390,34 +390,34 @@ static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
int bit = 0;
runlist *res = NULL;
//printf ("find_unused\n");
buffer = malloc (bufsize);
//printf("find_unused\n");
buffer = malloc(bufsize);
if (!buffer) {
printf ("!buffer\n");
printf("!buffer\n");
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;
//printf ("clus = %d\n", clus);
//printf("clus = %d\n", clus);
for (i = 0; i < clus; i++) {
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);
if (bytes_read != bufsize) {
printf ("!read\n");
printf("!read\n");
return NULL;
}
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) {
count++;
if ((!bit) && (count >= size)) {
//res = calloc (2, sizeof (*res));
res = calloc (1, 4096);
//res = calloc(2, sizeof(*res));
res = calloc(1, 4096);
if (res) {
res[0].vcn = 0;
res[0].lcn = start;
@ -427,7 +427,7 @@ static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
goto done;
}
} else {
//printf ("%d * %d\n", curr, count);
//printf("%d * %d\n", curr, count);
curr = bit;
count = 1;
start = i*bufsize*8 + j;
@ -435,18 +435,18 @@ static runlist * find_unused (ntfs_volume *vol, s64 size, u64 loc
}
}
done:
//printf ("%d * %d\n", curr, count);
//printf("%d * %d\n", curr, count);
free (buffer);
free(buffer);
if (res) {
for (i = 0; i < size; i++) {
if (utils_cluster_in_use (vol, res->lcn + i)) {
printf ("ERROR cluster %lld in use\n", res->lcn + i);
if (utils_cluster_in_use(vol, res->lcn + i)) {
printf("ERROR cluster %lld in use\n", res->lcn + i);
}
}
} else {
printf ("failed\n");
printf("failed\n");
}
return res;
@ -460,7 +460,7 @@ done:
* Any fragmented MFT records
* The boot file 'ntldr'
*/
static int dont_move (ntfs_inode *ino)
static int dont_move(ntfs_inode *ino)
{
static const ntfschar ntldr[6] = {
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;
FILE_NAME_ATTR *name;
if (utils_is_metadata (ino)) {
Eprintf ("metadata\n");
if (utils_is_metadata(ino)) {
Eprintf("metadata\n");
return 1;
}
rec = find_first_attribute (AT_ATTRIBUTE_LIST, ino->mrec);
rec = find_first_attribute(AT_ATTRIBUTE_LIST, ino->mrec);
if (rec) {
Eprintf ("attribute list\n");
Eprintf("attribute list\n");
return 1;
}
rec = find_first_attribute (AT_FILE_NAME, ino->mrec);
rec = find_first_attribute(AT_FILE_NAME, ino->mrec);
if (!rec) {
Eprintf ("extend inode\n");
Eprintf("extend inode\n");
return 1;
}
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)) {
Eprintf ("ntldr\n");
Eprintf("ntldr\n");
return 1;
}
@ -501,16 +501,16 @@ static int dont_move (ntfs_inode *ino)
/**
* bitmap_alloc
*/
static int bitmap_alloc (ntfs_volume *vol, runlist_element *rl)
static int bitmap_alloc(ntfs_volume *vol, runlist_element *rl)
{
int res;
if (!rl)
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) {
Eprintf ("bitmap alloc returns %d\n", res);
Eprintf("bitmap alloc returns %d\n", res);
}
return res;
@ -519,16 +519,16 @@ static int bitmap_alloc (ntfs_volume *vol, runlist_element *rl)
/**
* bitmap_free
*/
static int bitmap_free (ntfs_volume *vol, runlist_element *rl)
static int bitmap_free(ntfs_volume *vol, runlist_element *rl)
{
int res;
if (!rl)
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) {
Eprintf ("bitmap free returns %d\n", res);
Eprintf("bitmap free returns %d\n", res);
}
return res;
@ -537,7 +537,7 @@ static int bitmap_free (ntfs_volume *vol, runlist_element *rl)
/**
* 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;
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))
return -1;
//printf ("data_copy: from 0x%llx to 0x%llx\n", from->lcn, to->lcn);
buffer = malloc (vol->cluster_size);
//printf("data_copy: from 0x%llx to 0x%llx\n", from->lcn, to->lcn);
buffer = malloc(vol->cluster_size);
if (!buffer) {
printf ("!buffer\n");
printf("!buffer\n");
return -1;
}
for (i = 0; i < from->length; 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);
//printf("read cluster at %8lld\n", from->lcn+i);
res = ntfs_pread(vol->dev, (from->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
if (res != vol->cluster_size) {
Eprintf ("!read\n");
Eprintf("!read\n");
res = -1;
break;
}
//printf ("write cluster to %8lld\n", to->lcn+i);
res = ntfs_pwrite (vol->dev, (to->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
//printf("write cluster to %8lld\n", to->lcn+i);
res = ntfs_pwrite(vol->dev, (to->lcn+i) * vol->cluster_size, vol->cluster_size, buffer);
if (res != vol->cluster_size) {
Eprintf ("!write %lld\n", res);
Eprintf("!write %lld\n", res);
res = -1;
break;
}
}
free (buffer);
free(buffer);
return res;
}
@ -588,7 +588,7 @@ static int data_copy (ntfs_volume *vol, runlist_element *from, runlist_element *
* copy data
* 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)
{
int i;
@ -596,41 +596,41 @@ static s64 move_runlist (ntfs_volume *vol, runlist_element *from,
if (!vol || !from || !to)
return -1;
if (from->length != to->length) {
Eprintf ("diffsizes\n");
Eprintf("diffsizes\n");
return -1;
}
if ((from->lcn < 0) || (to->lcn < 0)) {
Eprintf ("invalid runs\n");
Eprintf("invalid runs\n");
return -1;
}
for (i = 0; i < from->length; i++) {
if (!utils_cluster_in_use (vol, from->lcn+i)) {
Eprintf ("from not in use\n");
if (!utils_cluster_in_use(vol, from->lcn+i)) {
Eprintf("from not in use\n");
return -1;
}
}
for (i = 0; i < to->length; i++) {
if (utils_cluster_in_use (vol, to->lcn+i)) {
Eprintf ("to is in use\n");
if (utils_cluster_in_use(vol, to->lcn+i)) {
Eprintf("to is in use\n");
return -1;
}
}
if (bitmap_alloc (vol, to) < 0) {
Eprintf ("cannot bitmap_alloc\n");
if (bitmap_alloc(vol, to) < 0) {
Eprintf("cannot bitmap_alloc\n");
return -1;
}
if (data_copy (vol, from, to) < 0) {
Eprintf ("cannot data_copy\n");
if (data_copy(vol, from, to) < 0) {
Eprintf("cannot data_copy\n");
return -1;
}
if (bitmap_free (vol, from) < 0) {
Eprintf ("cannot bitmap_free\n");
if (bitmap_free(vol, from) < 0) {
Eprintf("cannot bitmap_free\n");
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)
// check size of new runlist before allocating / moving
// 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 *from;
@ -665,27 +665,27 @@ static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
s64 res = -1;
// find empty space
to = find_unused (vol, run->length, loc, flags);
to = find_unused(vol, run->length, loc, flags);
if (!to) {
Eprintf ("!to\n");
Eprintf("!to\n");
return -1;
}
to->vcn = run->vcn;
// copy original runlist
from = ntfs_mapping_pairs_decompress (vol, rec, NULL);
from = ntfs_mapping_pairs_decompress(vol, rec, NULL);
if (!from) {
printf ("!from\n");
printf("!from\n");
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);
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++) {
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);
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_to = calc_attr_length (rec, need_to);
need_from = calc_attr_length(rec, need_from);
need_to = calc_attr_length(rec, 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(RED "Before %d, after %d\n" NORM, need_from, need_to);
printf("Before %d, after %d\n", need_from, need_to);
if (need_from != need_to) {
if (resize_nonres_attr (ino->mrec, rec, need_to) < 0) {
printf ("!resize\n");
if (resize_nonres_attr(ino->mrec, rec, need_to) < 0) {
printf("!resize\n");
return -1;
}
}
res = move_runlist (vol, run, to);
res = move_runlist(vol, run, to);
if (res < 0) {
Eprintf ("!move_runlist\n");
Eprintf("!move_runlist\n");
return -1;
}
// 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
ntfs_mapping_pairs_build(vol, ((u8*)rec) + rec->mapping_pairs_offset,
need_to, from, 0, NULL);
// commit
ntfs_inode_mark_dirty (ino);
ntfs_inode_mark_dirty(ino);
if (ntfs_inode_sync (ino) < 0) {
printf ("!sync\n");
if (ntfs_inode_sync(ino) < 0) {
printf("!sync\n");
return -1;
}
free (from);
free (to);
free(from);
free(to);
return res;
}
@ -744,7 +744,7 @@ static s64 move_datarun (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
* = 0 Nothing to do
* < 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)
{
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.
// 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) {
Eprintf ("!runs\n");
Eprintf("!runs\n");
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++) {
if (runs[i].lcn == LCN_RL_NOT_MAPPED) {
continue;
}
res = move_datarun (vol, ino, rec, runs+i, loc, flags);
//printf (" %8lld %8lld %8lld\n", runs[i].vcn, runs[i].lcn, runs[i].length);
res = move_datarun(vol, ino, rec, runs+i, loc, flags);
//printf(" %8lld %8lld %8lld\n", runs[i].vcn, runs[i].lcn, runs[i].length);
if (res < 0) {
Eprintf ("!move_datarun\n");
Eprintf("!move_datarun\n");
count = res;
break;
}
@ -789,7 +789,7 @@ static s64 move_attribute (ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec,
* = 0 Nothing to do
* < 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;
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 count = 0;
buffer = malloc (MAX_PATH);
buffer = malloc(MAX_PATH);
if (!buffer) {
Eprintf ("Out of memory\n");
Eprintf("Out of memory\n");
return -1;
}
utils_inode_get_name (ino, buffer, MAX_PATH);
utils_inode_get_name(ino, buffer, MAX_PATH);
if (dont_move (ino)) {
Eprintf ("can't move\n");
if (dont_move(ino)) {
Eprintf("can't move\n");
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,
// find that space and pass the location to our children.
// 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))) {
utils_attr_get_name (vol, rec, buffer, MAX_PATH);
printf ("\tAttribute 0x%02x %s is ", rec->type, buffer);
while ((rec = find_attribute(AT_UNUSED, ctx))) {
utils_attr_get_name(vol, rec, buffer, MAX_PATH);
printf("\tAttribute 0x%02x %s is ", rec->type, buffer);
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) {
count = res;
break;
}
count += res;
} else {
printf ("resident.\n\t\tSkipping it.\n");
printf("resident.\n\t\tSkipping it.\n");
}
}
ntfs_attr_put_search_ctx (ctx);
free (buffer);
ntfs_attr_put_search_ctx(ctx);
free(buffer);
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
* 1 Error, something went wrong
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
ntfs_volume *vol;
ntfs_inode *inode;
@ -858,7 +858,7 @@ int main (int argc, char *argv[])
int result = 1;
s64 count;
if (!parse_options (argc, argv))
if (!parse_options(argc, argv))
return 1;
utils_set_locale();
@ -866,35 +866,35 @@ int main (int argc, char *argv[])
if (opts.noaction)
flags |= MS_RDONLY;
vol = utils_mount_volume (opts.device, flags, opts.force);
vol = utils_mount_volume(opts.device, flags, opts.force);
if (!vol) {
printf ("!vol\n");
printf("!vol\n");
return 1;
}
inode = ntfs_pathname_to_inode(vol, NULL, opts.file);
if (!inode) {
printf ("!inode\n");
printf("!inode\n");
return 1;
}
count = move_file (vol, inode, opts.location, 0);
count = move_file(vol, inode, opts.location, 0);
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) {
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)
result = 0;
if (result)
printf ("failed\n");
printf("failed\n");
else
printf ("success\n");
printf("success\n");
ntfs_inode_close (inode);
ntfs_umount (vol, FALSE);
ntfs_inode_close(inode);
ntfs_umount(vol, FALSE);
return result;
}

View File

@ -301,7 +301,7 @@ __attribute__((noreturn))
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"
"\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"
" omitted then the NTFS volume will be enlarged to the DEVICE size.\n"
"\n", EXEC_NAME);
printf ("%s%s", ntfs_bugs, ntfs_home);
printf ("Ntfsresize FAQ: http://linux-ntfs.sourceforge.net/info/ntfsresize.html\n");
printf("%s%s", ntfs_bugs, ntfs_home);
printf("Ntfsresize FAQ: http://linux-ntfs.sourceforge.net/info/ntfsresize.html\n");
exit(1);
}
@ -356,13 +356,13 @@ static void proceed_question(void)
*
* Return: none
*/
static void version (void)
static void version(void)
{
printf ("\nResize an NTFS Volume, without data loss.\n\n");
printf ("Copyright (c) 2002-2005 Szabolcs Szakacsits\n");
printf ("Copyright (c) 2002-2004 Anton Altaparmakov\n");
printf ("Copyright (c) 2002-2003 Richard Russon\n");
printf ("\n%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
printf("\nResize an NTFS Volume, without data loss.\n\n");
printf("Copyright (c) 2002-2005 Szabolcs Szakacsits\n");
printf("Copyright (c) 2002-2004 Anton Altaparmakov\n");
printf("Copyright (c) 2002-2003 Richard Russon\n");
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));
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) {
case 1: /* A non-option argument */
if (!err && !opt.volume)

View File

@ -56,9 +56,9 @@ static const char *EXEC_NAME = "ntfsrm";
static struct options opts;
static const char *space_line = " ";
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
#define RM_WRITE 0
@ -69,12 +69,12 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
*
* 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",
EXEC_NAME, VERSION, ntfs_libntfs_version());
printf ("Copyright (c) 2004 Richard Russon\n");
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
printf("Copyright (c) 2004 Richard Russon\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -84,9 +84,9 @@ static void version (void)
*
* 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"
" -r --recursive Delete files in subdirectories\n"
" -i --interactive Ask before deleting files\n"
@ -101,7 +101,7 @@ static void usage (void)
" -V --version Version information\n"
" -v --verbose More output\n\n",
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
* 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 struct option lopt[] = {
@ -138,7 +138,7 @@ static int parse_options (int argc, char **argv)
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) {
case 1: /* A non-option argument */
if (!opts.device) {
@ -181,7 +181,7 @@ static int parse_options (int argc, char **argv)
opts.verbose++;
break;
default:
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
@ -193,7 +193,7 @@ static int parse_options (int argc, char **argv)
if ((opts.device == NULL) ||
(opts.file == NULL)) {
if (argc > 1)
Eprintf ("You must specify one device and one file.\n");
Eprintf("You must specify one device and one file.\n");
err++;
}
@ -216,18 +216,18 @@ static int parse_options (int argc, char **argv)
/**
* 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;
if (!dir)
return;
printf ("%.*s%p ", indent, space_line, dir);
ntfs_name_print (dir->name, dir->name_len);
printf ("\n");
printf("%.*s%p ", indent, space_line, dir);
ntfs_name_print(dir->name, dir->name_len);
printf("\n");
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
*/
static void ntfs_dt_print (struct ntfs_dt *dt, int indent)
static void ntfs_dt_print(struct ntfs_dt *dt, int indent)
{
int i;
if (!dt)
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++) {
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
*/
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 *dst;
int len;
@ -268,11 +268,11 @@ static int utils_array_insert (void *ptr, int asize, int before, int count)
len = (asize - before) * esize;
// XXX what about realloc?
memmove (dst, src, len);
memmove(dst, src, len);
len = count * esize;
memset (src, 0, len);
memset(src, 0, len);
return 0;
}
@ -280,9 +280,9 @@ static int utils_array_insert (void *ptr, int asize, int before, int count)
/**
* 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 *dst;
int len;
@ -294,12 +294,12 @@ static int utils_array_remove (void *ptr, int asize, int first, int count)
src = dst + (count * esize);
len = (asize - first) * esize;
memmove (dst, src, len);
memmove(dst, src, len);
src = (u8*) ptr + ((asize - count) * esize);
len = count * esize;
memset (src, 0, len);
memset(src, 0, len);
// XXX don't want to memset, want to realloc
return 0;
@ -309,7 +309,7 @@ static int utils_array_remove (void *ptr, int asize, int first, int count)
/**
* 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;
char *p, *q;
@ -326,22 +326,22 @@ static BOOL utils_pathname_to_inode2 (ntfs_volume *vol, struct ntfs_dir *parent,
return FALSE;
}
memset (found, 0, sizeof (*found));
memset(found, 0, sizeof(*found));
if (parent) {
dir = parent;
} else {
dir = (struct ntfs_dir *) vol->private_data;
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;
}
}
unicode = malloc (MAX_PATH * sizeof (ntfschar));
ascii = strdup (pathname); // Work with a r/w copy
unicode = malloc(MAX_PATH * sizeof(ntfschar));
ascii = strdup(pathname); // Work with a r/w copy
if (!unicode || !ascii) {
Eprintf ("Out of memory.\n");
Eprintf("Out of memory.\n");
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
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) {
*q = '\0';
q++;
}
len = ntfs_mbstoucs (p, &unicode, MAX_PATH);
len = ntfs_mbstoucs(p, &unicode, MAX_PATH);
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;
}
//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("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);
//if (dir->parent)
if (q) {
child = ntfs_dir_find2 (dir, unicode, len);
child = ntfs_dir_find2(dir, unicode, len);
if (!child) {
printf ("can't find %s in %s\n", p, pathname);
printf("can't find %s in %s\n", p, pathname);
goto close;
}
} 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) {
printf ("can't find %s in %s (2)\n", p, pathname);
printf("can't find %s in %s (2)\n", p, pathname);
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) {
//printf ("DIR\n");
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("DIR\n");
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));
if (child) {
child->index = ntfs_dt_create (child, NULL, -1);
ntfs_dir_add (dir, child);
child->index = ntfs_dt_create(child, NULL, -1);
ntfs_dir_add(dir, child);
}
}
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]) {
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;
}
dt->inodes[dt_num]->ref_count = 2;
dt->inodes[dt_num]->private_data = dt;
}
//printf ("dt = %p,%d\n", dt, dt_num);
//printf("dt = %p,%d\n", dt, dt_num);
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->mref = found->inode->mft_no;
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:
free (ascii); // from strdup
free (unicode);
free(ascii); // from strdup
free(unicode);
return result;
}
@ -429,7 +429,7 @@ close:
/**
* 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;
u64 recs;
@ -438,9 +438,9 @@ static s64 ntfs_mft_find_free_entry (ntfs_volume *vol)
return -1;
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++) {
if (utils_mftrec_in_use (vol, i) == 0)
if (utils_mftrec_in_use(vol, i) == 0)
return i;
}
return -1;
@ -449,14 +449,14 @@ static s64 ntfs_mft_find_free_entry (ntfs_volume *vol)
/**
* 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;
if (!inode)
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;
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);
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;
}
@ -480,7 +480,7 @@ static int ntfs_mft_set_inuse6 (ntfs_inode *inode, struct ntfs_bmp *bmp, BOOL in
/**
* 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_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;
top = del->dir->index;
//ntfs_dt_find_all (top);
//ntfs_dt_print (top, 0);
//ntfs_dt_find_all(top);
//ntfs_dt_print(top, 0);
del_ie = del->children[del_num];
//utils_dump_mem (del_ie, 0, del_ie->length, DM_DEFAULTS);
//printf ("\n");
//utils_dump_mem(del_ie, 0, del_ie->length, DM_DEFAULTS);
//printf("\n");
/*
* 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++) {
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");
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
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));
}
*/
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);
//printf ("vcn = %lld\n", vcn);
vcn = ntfs_ie_get_vcn(del_ie);
//printf("vcn = %lld\n", vcn);
suc = ntfs_dt_find4 (find_dir->index, uname, name_len, &suc_num);
//printf ("succ = %p, index = %d\n", suc, suc_num);
//printf ("\n");
suc = ntfs_dt_find4(find_dir->index, uname, name_len, &suc_num);
//printf("succ = %p, index = %d\n", suc, suc_num);
//printf("\n");
suc_ie = ntfs_ie_copy (suc->children[suc_num]);
//utils_dump_mem (suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
//printf ("\n");
suc_ie = ntfs_ie_copy(suc->children[suc_num]);
//utils_dump_mem(suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
//printf("\n");
suc_ie = ntfs_ie_set_vcn (suc_ie, vcn);
//utils_dump_mem (suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
//printf ("\n");
suc_ie = ntfs_ie_set_vcn(suc_ie, vcn);
//utils_dump_mem(suc_ie, 0, suc_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
//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 = &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");
//utils_dump_mem (del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
if (ntfs_dt_isroot (del))
res = ntfs_dt_root_replace (del, del_num, del_ie, suc_ie);
//utils_dump_mem(del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
if (ntfs_dt_isroot(del))
res = ntfs_dt_root_replace(del, del_num, del_ie, suc_ie);
else
res = ntfs_dt_alloc_replace (del, del_num, del_ie, suc_ie);
//printf ("\n");
//utils_dump_mem (del->data, 0, del->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
res = ntfs_dt_alloc_replace(del, del_num, del_ie, suc_ie);
//printf("\n");
//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)
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];
}
//ntfs_dt_print (top, 0);
//ntfs_dt_print(top, 0);
/*
* Now we have the simpler case of deleting from a leaf node.
* If this step creates an empty node, we have more to do.
*/
printf ("\n");
printf (BOLD YELLOW "Delete key:\n" END);
printf("\n");
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
// no, if we combine with another node, we'll have to remember
if (ntfs_dt_isroot (del))
ntfs_dt_root_remove (del, del_num);
if (ntfs_dt_isroot(del))
ntfs_dt_root_remove(del, del_num);
else
ntfs_dt_alloc_remove (del, del_num);
//printf ("\n");
//utils_dump_mem (del->data, 0, del->header->index_length+24, DM_BLUE|DM_GREEN|DM_INDENT);
ntfs_dt_alloc_remove(del, del_num);
//printf("\n");
//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)
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
printf ("\n");
printf (BOLD YELLOW "Find childless parent:\n" END);
printf("\n");
printf(BOLD YELLOW "Find childless parent:\n" END);
#if 0
for (par = del->parent, old = par; par; old = par, par = par->parent) {
if (par->child_count > 1)
break;
par_num = ntfs_dt_find_parent (par);
par_num = ntfs_dt_find_parent(par);
}
#endif
printf ("del = %p, parent = %p\n", del, del->parent);
printf("del = %p, parent = %p\n", del, 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
if (par) {
file = &par->children[par_num]->key.file_name;
printf ("\tpar name: ");
ntfs_name_print (file->file_name, file->file_name_length);
printf ("\n");
printf("\tpar name: ");
ntfs_name_print(file->file_name, file->file_name_length);
printf("\n");
}
if (par == NULL) {
@ -634,123 +634,123 @@ static int ntfs_file_remove (ntfs_volume *vol, struct ntfs_dt *del, int del_num)
goto freedts;
}
//ntfs_dt_print (top, 0);
printf ("\n");
//ntfs_dt_print(top, 0);
printf("\n");
//utils_dump_mem (par->data, 0, par->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
//printf ("\n");
//utils_dump_mem(par->data, 0, par->data_len, DM_BLUE|DM_GREEN|DM_INDENT);
//printf("\n");
/*
for (i = 0; i < top->child_count; 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");
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
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));
}
*/
// find if parent has left siblings
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];
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);
//utils_dump_mem (par_ie, 0, par_ie->length, DM_DEFAULTS);
//printf ("\n");
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);
//utils_dump_mem(par_ie, 0, par_ie->length, DM_DEFAULTS);
//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);
//utils_dump_mem (par_ie, 0, par_ie->length, DM_DEFAULTS);
//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);
//utils_dump_mem(par_ie, 0, par_ie->length, DM_DEFAULTS);
//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] ->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");
old = par->sub_nodes[par_num];
par->sub_nodes[par_num] = par->sub_nodes[par_num-1];
par->sub_nodes[par_num-1] = old;
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];
ntfs_ie_set_vcn (par_ie, vcn);
ntfs_ie_set_vcn(par_ie, vcn);
par_num--;
if (ntfs_dt_isroot (par))
printf (GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, par->dir->inode->mft_no);
if (ntfs_dt_isroot(par))
printf(GREEN "Modified: inode %lld, $INDEX_ROOT\n" END, par->dir->inode->mft_no);
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");
//utils_dump_mem (par->data, 0, par->data_len, DM_DEFAULTS);
//printf("\n");
//utils_dump_mem(par->data, 0, par->data_len, DM_DEFAULTS);
// unhook and hold onto the ded dt's
printf ("\n");
printf (BOLD YELLOW "Remove parent\n" END);
printf("\n");
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_remove_vcn (add_ie);
add_ie = ntfs_ie_copy(par->children[par_num]);
add_ie = ntfs_ie_remove_vcn(add_ie);
if (!add_ie)
goto done;
//printf ("\n");
//utils_dump_mem (add_ie, 0, add_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
//printf("\n");
//utils_dump_mem(add_ie, 0, add_ie->length, DM_BLUE|DM_GREEN|DM_INDENT);
ded = par->sub_nodes[par_num];
par->sub_nodes[par_num] = NULL;
//ntfs_dt_print (ded, 8);
//ntfs_dt_print(ded, 8);
#if 0
for (i = 0; i < par->child_count; 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");
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
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));
}
#endif
#if 1
//printf ("PAR: %p,%d\n", par, par_num);
if (ntfs_dt_isroot (par))
ntfs_dt_root_remove (par, par_num);
//printf("PAR: %p,%d\n", par, par_num);
if (ntfs_dt_isroot(par))
ntfs_dt_root_remove(par, par_num);
else
ntfs_dt_alloc_remove (par, par_num);
ntfs_dt_alloc_remove(par, par_num);
#endif
//printf ("count = %d\n", par->child_count);
//utils_dump_mem (par->data, 0, par->data_len, DM_DEFAULTS);
//printf ("0x%x\n", (u8*)par->children[0] - par->data);
//printf("count = %d\n", par->child_count);
//utils_dump_mem(par->data, 0, par->data_len, DM_DEFAULTS);
//printf("0x%x\n", (u8*)par->children[0] - par->data);
#if 0
for (i = 0; i < par->child_count; 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");
printf ("\tvcn = %lld\n", ntfs_ie_get_vcn (par_ie));
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));
}
#endif
//ntfs_dt_print (top, 0);
printf ("\n");
printf (BOLD YELLOW "Add childless parent\n" END);
//ntfs_dt_print(top, 0);
printf("\n");
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_num = -1;
suc = ntfs_dt_find4 (top, file->file_name, file->file_name_length, &suc_num);
//printf ("SUC: %p, %d\n", suc, suc_num);
suc = ntfs_dt_find4(top, file->file_name, file->file_name_length, &suc_num);
//printf("SUC: %p, %d\n", suc, suc_num);
if (!suc)
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
// 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;
// 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 if ded, don't write it back, just update bitmap
printf ("empty\n");
printf("empty\n");
goto done;
freedts:
printf ("\twhole dir is empty\n");
printf("\twhole dir is empty\n");
commit:
//printf ("commit\n");
//printf("commit\n");
done:
return 0;
@ -778,7 +778,7 @@ done:
/**
* 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;
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_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 vol = %lld\n", ntfs_bmp_find_last_set (bmp_vol));
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));
return 0;
}
@ -817,7 +817,7 @@ static int ntfs_file_remove2 (ntfs_volume *vol, struct ntfs_dt *dt, int dt_num)
/**
* 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;
char *ptr = NULL;
@ -838,20 +838,20 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
struct ntfs_dt *suc = NULL;
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)
return 1;
if (rindex (filename, PATH_SEP)) {
ptr = rindex (filename, PATH_SEP);
if (rindex(filename, PATH_SEP)) {
ptr = rindex(filename, PATH_SEP);
*ptr = 0;
dirname = filename;
filename = ptr + 1;
}
printf ("looking for %s\n", dirname);
if (utils_pathname_to_inode2 (vol, NULL, dirname, &find) == FALSE) {
printf ("!inode\n");
printf("looking for %s\n", dirname);
if (utils_pathname_to_inode2(vol, NULL, dirname, &find) == FALSE) {
printf("!inode\n");
return 0;
}
@ -862,18 +862,18 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
if (uname_len < 0)
goto close;
printf ("new inode %lld\n", new_num);
ino = ntfs_inode_open3 (vol, new_num);
printf("new inode %lld\n", new_num);
ino = ntfs_inode_open3(vol, new_num);
if (!ino) {
printf ("!ino\n");
printf("!ino\n");
goto close;
}
tmp = (u8*) ino->mrec;
now = utc2ntfs (time(NULL));
now = utc2ntfs(time(NULL));
// 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
*(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->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)
goto close;
// Standard information
memset (buffer, 0, 128);
memset(buffer, 0, 128);
*(u64*)(buffer + 0x00) = now; // Time
*(u64*)(buffer + 0x08) = now; // Time
*(u64*)(buffer + 0x10) = now; // Time
*(u64*)(buffer + 0x18) = now; // Time
ino->creation_time = time (NULL);
ino->last_data_change_time = time (NULL);
ino->last_mft_change_time = time (NULL);
ino->last_access_time = time (NULL);
attr = ntfs_mft_add_attr (ino, AT_STANDARD_INFORMATION, buffer, 0x48);
ino->creation_time = time(NULL);
ino->last_data_change_time = time(NULL);
ino->last_mft_change_time = time(NULL);
ino->last_access_time = time(NULL);
attr = ntfs_mft_add_attr(ino, AT_STANDARD_INFORMATION, buffer, 0x48);
// Data
memset (buffer, 0, 128);
data_len = sprintf ((char*)buffer, "Contents of file: %s\n", filename);
attr = ntfs_mft_add_attr (ino, AT_DATA, buffer, data_len);
memset(buffer, 0, 128);
data_len = sprintf((char*)buffer, "Contents of file: %s\n", filename);
attr = ntfs_mft_add_attr(ino, AT_DATA, buffer, data_len);
// File name
memset (buffer, 0, 128);
*(u64*)(buffer + 0x00) = MK_MREF (find.mref, 2); // MFT Ref of parent dir
memset(buffer, 0, 128);
*(u64*)(buffer + 0x00) = MK_MREF(find.mref, 2); // MFT Ref of parent dir
*(u64*)(buffer + 0x08) = now; // Time
*(u64*)(buffer + 0x10) = now; // Time
*(u64*)(buffer + 0x18) = 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
*(u32*)(buffer + 0x38) = 0; // Flags
*(u32*)(buffer + 0x3C) = 0; // Not relevant
*(u8* )(buffer + 0x40) = uname_len; // Filename length
*(u8* )(buffer + 0x41) = FILE_NAME_POSIX; // Filename namespace
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))));
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->resident_flags = RESIDENT_ATTR_IS_INDEXED;
attr->name_offset = 0x18;
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) {
printf ("!ie\n");
printf("!ie\n");
goto close;
}
// 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->indexed_file = MK_MREF (new_num, ino->mrec->sequence_number);
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->key.file_name.creation_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_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;
dir = dt->dir->children[0];
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) {
dt->inodes[dt_index] = ino;
ino->ref_count++;
@ -961,11 +961,11 @@ static int ntfs_file_add2 (ntfs_volume *vol, char *filename)
*/
close:
free (buffer);
ntfs_inode_close2 (ino);
ntfs_ie_free (ie);
free (uname);
ntfs_inode_close2 (find.inode);
free(buffer);
ntfs_inode_close2(ino);
ntfs_ie_free(ie);
free(uname);
ntfs_inode_close2(find.inode);
return 0;
}
@ -977,7 +977,7 @@ close:
* Return: 0 Success, the program worked
* 1 Error, something went wrong
*/
int main (int argc, char *argv[])
int main(int argc, char *argv[])
{
ntfs_volume *vol = NULL;
ntfs_inode *inode = NULL;
@ -985,52 +985,52 @@ int main (int argc, char *argv[])
int result = 1;
struct ntfs_find find;
if (!parse_options (argc, argv))
if (!parse_options(argc, argv))
goto done;
utils_set_locale();
#if 0
printf ("sizeof (ntfs_bmp) = %d\n", sizeof (struct ntfs_bmp));
printf ("sizeof (ntfs_dt) = %d\n", sizeof (struct ntfs_dt));
printf ("sizeof (ntfs_dir) = %d\n", sizeof (struct ntfs_dir));
printf ("\n");
printf("sizeof(ntfs_bmp) = %d\n", sizeof(struct ntfs_bmp));
printf("sizeof(ntfs_dt) = %d\n", sizeof(struct ntfs_dt));
printf("sizeof(ntfs_dir) = %d\n", sizeof(struct ntfs_dir));
printf("\n");
#endif
if (opts.noaction)
flags |= MS_RDONLY;
vol = ntfs_volume_mount2 (opts.device, flags, opts.force);
vol = ntfs_volume_mount2(opts.device, flags, opts.force);
if (!vol) {
printf ("!vol\n");
printf("!vol\n");
goto done;
}
#if 0
if (utils_pathname_to_inode2 (vol, NULL, opts.file, &find) == FALSE) {
printf ("!inode\n");
if (utils_pathname_to_inode2(vol, NULL, opts.file, &find) == FALSE) {
printf("!inode\n");
goto done;
}
inode = find.inode;
#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 (1) result = ntfs_file_add2 (vol, opts.file);
if (0) result = ntfs_file_remove2(vol, find.dt, find.dt_index);
if (1) result = ntfs_file_add2(vol, opts.file);
done:
if (1) ntfs_volume_commit (vol);
if (0) ntfs_volume_rollback (vol);
if (0) ntfs_inode_close2 (inode);
if (1) ntfs_volume_umount2 (vol, FALSE);
if (1) ntfs_volume_commit(vol);
if (0) ntfs_volume_rollback(vol);
if (0) ntfs_inode_close2(inode);
if (1) ntfs_volume_umount2(vol, FALSE);
if (0) utils_pathname_to_inode2 (NULL, NULL, NULL, NULL);
if (0) ntfs_ie_remove_name (NULL);
if (0) ntfs_dt_transfer2 (NULL, NULL, 0, 0);
if (0) utils_array_remove (NULL, 0, 0, 0);
if (0) utils_array_insert (NULL, 0, 0, 0);
if (0) utils_pathname_to_inode2(NULL, NULL, NULL, NULL);
if (0) ntfs_ie_remove_name(NULL);
if (0) ntfs_dt_transfer2(NULL, NULL, 0, 0);
if (0) utils_array_remove(NULL, 0, 0, 0);
if (0) utils_array_insert(NULL, 0, 0, 0);
return result;
}

View File

@ -171,8 +171,8 @@ static void license(void)
/**
* usage - print a list of the parameters to the program
*/
__attribute__ ((noreturn))
static void usage (void)
__attribute__((noreturn))
static void usage(void)
{
copyright();
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