diff --git a/include/ntfs/layout.h b/include/ntfs/layout.h index 9b465b44..41aa1ecd 100644 --- a/include/ntfs/layout.h +++ b/include/ntfs/layout.h @@ -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 diff --git a/libntfs/attrib.c b/libntfs/attrib.c index e1ecf730..6f80783f 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -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) diff --git a/libntfs/dir.c b/libntfs/dir.c index 410028cf..27be8804 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -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 diff --git a/libntfs/logfile.c b/libntfs/logfile.c index 7ed40304..d699c39c 100644 --- a/libntfs/logfile.c +++ b/libntfs/logfile.c @@ -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 diff --git a/libntfs/security.c b/libntfs/security.c index e30e6662..2c0598f2 100644 --- a/libntfs/security.c +++ b/libntfs/security.c @@ -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; diff --git a/libntfs/tree.c b/libntfs/tree.c index 0945d0b8..e111407a 100644 --- a/libntfs/tree.c +++ b/libntfs/tree.c @@ -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; diff --git a/ntfsprogs/cluster.c b/ntfsprogs/cluster.c index 3f77ea27..5abdd12e 100644 --- a/ntfsprogs/cluster.c +++ b/ntfsprogs/cluster.c @@ -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; } diff --git a/ntfsprogs/cluster.h b/ntfsprogs/cluster.h index f3fdebe7..4bc18276 100644 --- a/ntfsprogs/cluster.h +++ b/ntfsprogs/cluster.h @@ -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_ */ diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 7880c208..0eee3594 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -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; } diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index 2a939279..152959cb 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -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; } diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index 697a3417..3584106e 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -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) { diff --git a/ntfsprogs/ntfscluster.c b/ntfsprogs/ntfscluster.c index 2f0a0bbe..95301172 100644 --- a/ntfsprogs/ntfscluster.c +++ b/ntfsprogs/ntfscluster.c @@ -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; } diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 687e25c3..f123ddd7 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -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) { diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index 988e2777..740f034a 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -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; } diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 0ace7ef1..c91edf5c 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -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 " diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index ccc832f7..1a63bf5f 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -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); diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 9a1d2b37..b406fa48 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -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; } diff --git a/ntfsprogs/ntfslabel.c b/ntfsprogs/ntfslabel.c index 2de0c033..8067605d 100644 --- a/ntfsprogs/ntfslabel.c +++ b/ntfsprogs/ntfslabel.c @@ -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; } diff --git a/ntfsprogs/ntfsls.c b/ntfsprogs/ntfsls.c index 97752159..17beedd6 100644 --- a/ntfsprogs/ntfsls.c +++ b/ntfsprogs/ntfsls.c @@ -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; diff --git a/ntfsprogs/ntfsmftalloc.c b/ntfsprogs/ntfsmftalloc.c index 5237d520..155d8706 100644 --- a/ntfsprogs/ntfsmftalloc.c +++ b/ntfsprogs/ntfsmftalloc.c @@ -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" diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index 0accd102..cdb35de4 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -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; diff --git a/ntfsprogs/ntfsmove.c b/ntfsprogs/ntfsmove.c index 11ac72e9..7d1054f5 100644 --- a/ntfsprogs/ntfsmove.c +++ b/ntfsprogs/ntfsmove.c @@ -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; } diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index 3b074fdf..0b31d4b0 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -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) diff --git a/ntfsprogs/ntfsrm.c b/ntfsprogs/ntfsrm.c index 0a4cf481..30b02bea 100644 --- a/ntfsprogs/ntfsrm.c +++ b/ntfsprogs/ntfsrm.c @@ -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; } diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index c82ad43d..04530913 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -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 " diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index cd089662..47f3f85d 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -99,9 +99,9 @@ static short avoid_duplicate_printing; /* Flag No duplicate printing of file in static range *ranges; /* Array containing all Inode-Rages for undelete */ static long nr_entries; /* Number of range entries */ -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) /** * parse_inode_arg - parses the inode expression @@ -110,7 +110,7 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE) * * Return: Number of correct inode specifications or -1 for error */ -static int parse_inode_arg (void) +static int parse_inode_arg(void) { int p; u32 imax; @@ -129,28 +129,28 @@ static int parse_inode_arg (void) return (0); /* bailout if no optarg */ /* init variables */ - p = strlen (optarg); + p = strlen(optarg); imax = p; opt_arg_ptr = optarg; opt_arg_end1 = optarg; opt_arg_end2 = &(optarg[p]); /* alloc mem for range table */ - ranges = (range *) malloc ((p + 1) * sizeof (range)); + ranges = (range *) malloc((p + 1) * sizeof(range)); if (ranges == NULL) { - printf ("ERROR: Couldn't alloc mem for parsing inodes!\n"); + printf("ERROR: Couldn't alloc mem for parsing inodes!\n"); return (-1); } /* loop */ while ((opt_arg_end1 != opt_arg_end2) && (p > 0)) { /* Try to get inode */ - inode = strtoul (opt_arg_ptr, &opt_arg_end1, 0); + inode = strtoul(opt_arg_ptr, &opt_arg_end1, 0); p--; /* invalid char at begin */ if ((opt_arg_ptr == opt_arg_end1) || (opt_arg_ptr == opt_arg_end2)) { - printf ("ERROR: Invalid Number: %s\n", opt_arg_ptr); + printf("ERROR: Invalid Number: %s\n", opt_arg_ptr); return (-1); } @@ -160,15 +160,15 @@ static int parse_inode_arg (void) opt_arg_temp = opt_arg_end1; opt_arg_end1 = & (opt_arg_temp[1]); if (opt_arg_temp >= opt_arg_end2) { - printf ("ERROR: Missing range end!\n"); + printf("ERROR: Missing range end!\n"); return (-1); } range_begin = inode; /* get count */ - range_end = strtoul (opt_arg_end1, &opt_arg_temp, 0); + range_end = strtoul(opt_arg_end1, &opt_arg_temp, 0); if (opt_arg_temp == opt_arg_end1) { - printf ("ERROR: Invalid Number: %s\n", opt_arg_temp); + printf("ERROR: Invalid Number: %s\n", opt_arg_temp); return (-1); } @@ -198,7 +198,7 @@ static int parse_inode_arg (void) /* Next inode */ opt_arg_ptr = & (opt_arg_end1[1]); if (opt_arg_ptr >= opt_arg_end2) { - printf ("ERROR: Missing new value at end of input!\n"); + printf("ERROR: Missing new value at end of input!\n"); return (-1); } continue; @@ -218,14 +218,14 @@ static int parse_inode_arg (void) * * Return: none */ -static void version (void) +static void version(void) { printf("\n%s v%s (libntfs %s) - Recover deleted files from an NTFS " "Volume.\n\n", EXEC_NAME, VERSION, ntfs_libntfs_version()); - printf ("Copyright (c) 2002-2005 Richard Russon\n" + printf("Copyright (c) 2002-2005 Richard Russon\n" "Copyright (c) 2004-2005 Holger Ohmacht\n"); - printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); + printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); } /** @@ -235,9 +235,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" " -s --scan Scan for files (default)\n" " -p num --percentage num Minimum percentage recoverable\n" " -m pattern --match pattern Only work on files with matching names\n" @@ -262,7 +262,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); } /** @@ -286,7 +286,7 @@ static void usage (void) * Return: 1, Success, the string was transformed * 0, An error occurred */ -static int transform (const char *pattern, char **regex) +static int transform(const char *pattern, char **regex) { char *result; int length, i, j; @@ -294,9 +294,9 @@ static int transform (const char *pattern, char **regex) if (!pattern || !regex) return 0; - length = strlen (pattern); + length = strlen(pattern); if (length < 1) { - Eprintf ("Pattern to transform is empty\n"); + Eprintf("Pattern to transform is empty\n"); return 0; } @@ -305,9 +305,9 @@ static int transform (const char *pattern, char **regex) length++; } - result = malloc (length + 3); + result = malloc(length + 3); if (!result) { - Eprintf ("Couldn't allocate memory in transform()\n"); + Eprintf("Couldn't allocate memory in transform()\n"); return 0; } @@ -362,7 +362,7 @@ static int transform (const char *pattern, char **regex) * Return: 1 Success * 0 Error, the string was malformed */ -static int parse_time (const char *value, time_t *since) +static int parse_time(const char *value, time_t *since) { long long result; time_t now; @@ -373,19 +373,19 @@ static int parse_time (const char *value, time_t *since) ntfs_log_trace("Parsing time '%s' ago.\n", value); - result = strtoll (value, &suffix, 10); + result = strtoll(value, &suffix, 10); if (result < 0 || errno == ERANGE) { - Eprintf ("Invalid time '%s'.\n", value); + Eprintf("Invalid time '%s'.\n", value); return 0; } if (!suffix) { - Eprintf ("Internal error, strtoll didn't return a suffix.\n"); + Eprintf("Internal error, strtoll didn't return a suffix.\n"); return 0; } - if (strlen (suffix) > 1) { - Eprintf ("Invalid time suffix '%s'. Use Y, M, W, D or H.\n", suffix); + if (strlen(suffix) > 1) { + Eprintf("Invalid time suffix '%s'. Use Y, M, W, D or H.\n", suffix); return 0; } @@ -399,11 +399,11 @@ static int parse_time (const char *value, time_t *since) break; default: - Eprintf ("Invalid time suffix '%s'. Use Y, M, W, D or H.\n", suffix); + Eprintf("Invalid time suffix '%s'. Use Y, M, W, D or H.\n", suffix); return 0; } - now = time (NULL); + now = time(NULL); ntfs_log_debug("Time now = %lld, Time then = %lld.\n", (long long) now, (long long) result); @@ -420,7 +420,7 @@ static int parse_time (const char *value, time_t *since) * 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 = "-b:Cc:d:fhi?m:o:OPp:sS:t:Tu::qvV"; static const struct option lopt[] = { @@ -433,7 +433,7 @@ static int parse_options (int argc, char *argv[]) { "help", no_argument, NULL, 'h' }, { "match", required_argument, NULL, 'm' }, { "output", required_argument, NULL, 'o' }, - { "optimistic", no_argument, NULL, 'O' }, + { "optimistic", no_argument, NULL, 'O' }, { "percentage", required_argument, NULL, 'p' }, { "scan", no_argument, NULL, 's' }, { "size", required_argument, NULL, 'S' }, @@ -459,7 +459,7 @@ static int parse_options (int argc, char *argv[]) opts.uinode = -1; opts.percent = -1; opts.fillbyte = -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) { @@ -472,7 +472,7 @@ static int parse_options (int argc, char *argv[]) case 'b': if (opts.fillbyte == (char)-1) { end = NULL; - opts.fillbyte = strtol (optarg, &end, 0); + opts.fillbyte = strtol(optarg, &end, 0); if (end && *end) err++; } else { @@ -484,7 +484,7 @@ static int parse_options (int argc, char *argv[]) break; case 'c': if (opts.mode == MODE_NONE) { - if (!utils_parse_range (optarg, + if (!utils_parse_range(optarg, &opts.mft_begin, &opts.mft_end, TRUE)) err++; opts.mode = MODE_COPY; @@ -507,7 +507,7 @@ static int parse_options (int argc, char *argv[]) break; case 'm': if (!opts.match) { - if (!transform (optarg, &opts.match)) { + if (!transform(optarg, &opts.match)) { err++; } else { /* set regex-flag on true ;) */ @@ -525,10 +525,10 @@ static int parse_options (int argc, char *argv[]) } break; case 'O': - if (!opts.optimistic) { + if (!opts.optimistic) { opts.optimistic++; } else { - err++; + err++; } break; case 'P': @@ -541,7 +541,7 @@ static int parse_options (int argc, char *argv[]) case 'p': if (opts.percent == -1) { end = NULL; - opts.percent = strtol (optarg, &end, 0); + opts.percent = strtol(optarg, &end, 0); if (end && ((*end != '%') && (*end != 0))) err++; } else { @@ -559,14 +559,14 @@ static int parse_options (int argc, char *argv[]) break; case 'S': if ((opts.size_begin > 0) || (opts.size_end > 0) || - !utils_parse_range (optarg, &opts.size_begin, + !utils_parse_range(optarg, &opts.size_begin, &opts.size_end, TRUE)) { err++; } break; case 't': if (opts.since == 0) { - if (!parse_time (optarg, &opts.since)) + if (!parse_time(optarg, &opts.since)) err++; } else { err++; @@ -600,9 +600,9 @@ static int parse_options (int argc, char *argv[]) (optopt == 'o') || (optopt == 'p') || (optopt == 'S') || (optopt == 't') || (optopt == 'u')) && (!optarg)) { - 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; @@ -614,7 +614,7 @@ 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++; } @@ -626,19 +626,19 @@ static int parse_options (int argc, char *argv[]) case MODE_SCAN: if (opts.output || opts.dest || opts.truncate || (opts.fillbyte != (char)-1)) { - Eprintf ("Scan can only be used with --percent, " + Eprintf("Scan can only be used with --percent, " "--match, --ignore-case, --size and --time.\n"); err++; } if (opts.match_case && !opts.match) { - Eprintf ("The --case option doesn't make sense without the --match option\n"); + Eprintf("The --case option doesn't make sense without the --match option\n"); err++; } break; case MODE_UNDELETE: /*if ((opts.percent != -1) || (opts.size_begin > 0) || (opts.size_end > 0)) { - Eprintf ("Undelete can only be used with " + Eprintf("Undelete can only be used with " "--output, --destination, --byte and --truncate.\n"); err++; }*/ @@ -649,32 +649,32 @@ static int parse_options (int argc, char *argv[]) opts.match || opts.match_case || (opts.size_begin > 0) || (opts.size_end > 0)) { - Eprintf ("Copy can only be used with --output and --destination.\n"); + Eprintf("Copy can only be used with --output and --destination.\n"); err++; } break; default: - Eprintf ("You can only select one of Scan, Undelete or Copy.\n"); + Eprintf("You can only select one of Scan, Undelete or Copy.\n"); err++; } if ((opts.percent < -1) || (opts.percent > 100)) { - Eprintf ("Percentage value must be in the range 0 - 100.\n"); + Eprintf("Percentage value must be in the range 0 - 100.\n"); err++; } if (opts.quiet) { if (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++; } else if (opts.mode == MODE_SCAN) { - Eprintf ("You may not use --quiet when scanning a volume.\n"); + Eprintf("You may not use --quiet when scanning a volume.\n"); err++; } } if (opts.parent && !opts.verbose) { - Eprintf ("To use --parent, you must also use --verbose.\n"); + Eprintf("To use --parent, you must also use --verbose.\n"); err++; } } @@ -700,41 +700,41 @@ static int parse_options (int argc, char *argv[]) * * Return: none */ -static void free_file (struct ufile *file) +static void free_file(struct ufile *file) { struct list_head *item, *tmp; if (!file) return; - list_for_each_safe (item, tmp, &file->name) { /* List of filenames */ - struct filename *f = list_entry (item, struct filename, list); + list_for_each_safe(item, tmp, &file->name) { /* List of filenames */ + struct filename *f = list_entry(item, struct filename, list); ntfs_log_debug("freeing filename '%s'", f->name ? f->name : NONE); if (f->name) - free (f->name); + free(f->name); if (f->parent_name) { ntfs_log_debug(" and parent filename '%s'", f->parent_name); - free (f->parent_name); + free(f->parent_name); } ntfs_log_debug(".\n"); - free (f); + free(f); } - list_for_each_safe (item, tmp, &file->data) { /* List of data streams */ - struct data *d = list_entry (item, struct data, list); + list_for_each_safe(item, tmp, &file->data) { /* List of data streams */ + struct data *d = list_entry(item, struct data, list); ntfs_log_debug("Freeing data stream '%s'.\n", d->name ? d->name : UNNAMED); if (d->name) - free (d->name); + free(d->name); if (d->runlist) - free (d->runlist); - free (d); + free(d->runlist); + free(d); } - free (file->mft); - free (file); + free(file->mft); + free(file); } /** @@ -765,7 +765,7 @@ static FILE_NAME_ATTR* verify_parent(struct filename* name, MFT_RECORD* rec) ctx = ntfs_attr_get_search_ctx(NULL, rec); if (!ctx) { - Eprintf ("ERROR: Couldn't create a search context.\n"); + Eprintf("ERROR: Couldn't create a search context.\n"); return NULL; } @@ -806,7 +806,7 @@ static FILE_NAME_ATTR* verify_parent(struct filename* name, MFT_RECORD* rec) * get_parent_name - Find the name of a file's parent. * @name: the filename whose parent's name to find */ -static void get_parent_name (struct filename* name, ntfs_volume* vol) +static void get_parent_name(struct filename* name, ntfs_volume* vol) { ntfs_attr* mft_data; MFT_RECORD* rec; @@ -818,18 +818,18 @@ static void get_parent_name (struct filename* name, ntfs_volume* vol) rec = calloc(1, vol->mft_record_size); if (!rec) { - Eprintf ("ERROR: Couldn't allocate memory in get_parent_name()\n"); + Eprintf("ERROR: Couldn't allocate memory in get_parent_name()\n"); return; } mft_data = ntfs_attr_open(vol->mft_ni, AT_DATA, AT_UNNAMED, 0); if (!mft_data) { - Eprintf ("ERROR: Couldn't open $MFT/$DATA: %s\n", strerror (errno)); + Eprintf("ERROR: Couldn't open $MFT/$DATA: %s\n", strerror(errno)); } else { inode_num = MREF(name->parent_mref); if (ntfs_attr_pread(mft_data, vol->mft_record_size * inode_num, vol->mft_record_size, rec) < 1) { - Eprintf ("ERROR: Couldn't read MFT Record %lld.\n", inode_num); + Eprintf("ERROR: Couldn't read MFT Record %lld.\n", inode_num); } else if ((filename_attr = verify_parent(name, rec))) { if (ntfs_ucstombs(filename_attr->file_name, filename_attr->file_name_length, @@ -872,7 +872,7 @@ static void get_parent_name (struct filename* name, ntfs_volume* vol) * Return: n The number of $FILENAME attributes found * -1 Error */ -static int get_filenames (struct ufile *file, ntfs_volume* vol) +static int get_filenames(struct ufile *file, ntfs_volume* vol) { ATTR_RECORD *rec; FILE_NAME_ATTR *attr; @@ -884,17 +884,17 @@ static int get_filenames (struct ufile *file, ntfs_volume* vol) if (!file) return -1; - ctx = ntfs_attr_get_search_ctx (NULL, file->mft); + ctx = ntfs_attr_get_search_ctx(NULL, file->mft); 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)); - name = calloc (1, sizeof (*name)); + name = calloc(1, sizeof(*name)); if (!name) { - Eprintf ("ERROR: Couldn't allocate memory in get_filenames().\n"); + Eprintf("ERROR: Couldn't allocate memory in get_filenames().\n"); count = -1; break; } @@ -902,16 +902,16 @@ static int get_filenames (struct ufile *file, ntfs_volume* vol) name->uname = attr->file_name; name->uname_len = attr->file_name_length; name->name_space = attr->file_name_type; - name->size_alloc = sle64_to_cpu (attr->allocated_size); - name->size_data = sle64_to_cpu (attr->data_size); + name->size_alloc = sle64_to_cpu(attr->allocated_size); + name->size_data = sle64_to_cpu(attr->data_size); name->flags = attr->file_attributes; - name->date_c = ntfs2utc (attr->creation_time); - name->date_a = ntfs2utc (attr->last_data_change_time); - name->date_m = ntfs2utc (attr->last_mft_change_time); - name->date_r = ntfs2utc (attr->last_access_time); + name->date_c = ntfs2utc(attr->creation_time); + name->date_a = ntfs2utc(attr->last_data_change_time); + name->date_m = ntfs2utc(attr->last_mft_change_time); + name->date_r = ntfs2utc(attr->last_access_time); - if (ntfs_ucstombs (name->uname, name->uname_len, &name->name, + if (ntfs_ucstombs(name->uname, name->uname_len, &name->name, 0) < 0) { ntfs_log_debug("ERROR: Couldn't translate filename to " "current locale.\n"); @@ -930,10 +930,10 @@ static int get_filenames (struct ufile *file, ntfs_volume* vol) space = name->name_space; } - file->max_size = max (file->max_size, name->size_alloc); - file->max_size = max (file->max_size, name->size_data); + file->max_size = max(file->max_size, name->size_alloc); + file->max_size = max(file->max_size, name->size_data); - list_add_tail (&name->list, &file->name); + list_add_tail(&name->list, &file->name); count++; } @@ -957,7 +957,7 @@ static int get_filenames (struct ufile *file, ntfs_volume* vol) * Return: n The number of $FILENAME attributes found * -1 Error */ -static int get_data (struct ufile *file, ntfs_volume *vol) +static int get_data(struct ufile *file, ntfs_volume *vol) { ATTR_RECORD *rec; ntfs_attr_search_ctx *ctx; @@ -967,14 +967,14 @@ static int get_data (struct ufile *file, ntfs_volume *vol) if (!file) return -1; - ctx = ntfs_attr_get_search_ctx (NULL, file->mft); + ctx = ntfs_attr_get_search_ctx(NULL, file->mft); if (!ctx) return -1; - while ((rec = find_attribute (AT_DATA, ctx))) { - data = calloc (1, sizeof (*data)); + while ((rec = find_attribute(AT_DATA, ctx))) { + data = calloc(1, sizeof(*data)); if (!data) { - Eprintf ("ERROR: Couldn't allocate memory in get_data().\n"); + Eprintf("ERROR: Couldn't allocate memory in get_data().\n"); count = -1; break; } @@ -984,23 +984,23 @@ static int get_data (struct ufile *file, ntfs_volume *vol) data->encrypted = rec->flags & ATTR_IS_ENCRYPTED; if (rec->name_length) { - data->uname = (ntfschar *) ((char *) rec + le16_to_cpu (rec->name_offset)); + data->uname = (ntfschar *) ((char *) rec + le16_to_cpu(rec->name_offset)); data->uname_len = rec->name_length; - if (ntfs_ucstombs (data->uname, data->uname_len, &data->name, + if (ntfs_ucstombs(data->uname, data->uname_len, &data->name, 0) < 0) { - Eprintf ("ERROR: Cannot translate name into current locale.\n"); + Eprintf("ERROR: Cannot translate name into current locale.\n"); } } if (data->resident) { - data->size_data = le32_to_cpu (rec->value_length); - data->data = ((char*) (rec)) + le16_to_cpu (rec->value_offset); + data->size_data = le32_to_cpu(rec->value_length); + data->data = ((char*) (rec)) + le16_to_cpu(rec->value_offset); } else { - data->size_alloc = sle64_to_cpu (rec->allocated_size); - data->size_data = sle64_to_cpu (rec->data_size); - data->size_init = sle64_to_cpu (rec->initialized_size); - data->size_vcn = sle64_to_cpu (rec->highest_vcn) + 1; + data->size_alloc = sle64_to_cpu(rec->allocated_size); + data->size_data = sle64_to_cpu(rec->data_size); + data->size_init = sle64_to_cpu(rec->initialized_size); + data->size_vcn = sle64_to_cpu(rec->highest_vcn) + 1; } data->runlist = ntfs_mapping_pairs_decompress(vol, rec, NULL); @@ -1008,10 +1008,10 @@ static int get_data (struct ufile *file, ntfs_volume *vol) ntfs_log_debug("Couldn't decompress the data runs.\n"); } - file->max_size = max (file->max_size, data->size_data); - file->max_size = max (file->max_size, data->size_init); + file->max_size = max(file->max_size, data->size_data); + file->max_size = max(file->max_size, data->size_init); - list_add_tail (&data->list, &file->data); + list_add_tail(&data->list, &file->data); count++; } @@ -1031,7 +1031,7 @@ static int get_data (struct ufile *file, ntfs_volume *vol) * Return: Pointer A ufile object containing the results * NULL Error */ -static struct ufile * read_record (ntfs_volume *vol, long long record) +static struct ufile * read_record(ntfs_volume *vol, long long record) { ATTR_RECORD *attr10, *attr20, *attr90; struct ufile *file; @@ -1040,51 +1040,51 @@ static struct ufile * read_record (ntfs_volume *vol, long long record) if (!vol) return NULL; - file = calloc (1, sizeof (*file)); + file = calloc(1, sizeof(*file)); if (!file) { - Eprintf ("ERROR: Couldn't allocate memory in read_record()\n"); + Eprintf("ERROR: Couldn't allocate memory in read_record()\n"); return NULL; } - INIT_LIST_HEAD (&file->name); - INIT_LIST_HEAD (&file->data); + INIT_LIST_HEAD(&file->name); + INIT_LIST_HEAD(&file->data); file->inode = record; - file->mft = malloc (vol->mft_record_size); + file->mft = malloc(vol->mft_record_size); if (!file->mft) { - Eprintf ("ERROR: Couldn't allocate memory in read_record()\n"); - free_file (file); + Eprintf("ERROR: Couldn't allocate memory in read_record()\n"); + free_file(file); return NULL; } - mft = ntfs_attr_open (vol->mft_ni, AT_DATA, AT_UNNAMED, 0); + mft = ntfs_attr_open(vol->mft_ni, AT_DATA, AT_UNNAMED, 0); if (!mft) { - Eprintf ("ERROR: Couldn't open $MFT/$DATA: %s\n", strerror (errno)); - free_file (file); + Eprintf("ERROR: Couldn't open $MFT/$DATA: %s\n", strerror(errno)); + free_file(file); return NULL; } - if (ntfs_attr_mst_pread (mft, vol->mft_record_size * record, 1, vol->mft_record_size, file->mft) < 1) { - Eprintf ("ERROR: Couldn't read MFT Record %lld.\n", record); - ntfs_attr_close (mft); - free_file (file); + if (ntfs_attr_mst_pread(mft, vol->mft_record_size * record, 1, vol->mft_record_size, file->mft) < 1) { + Eprintf("ERROR: Couldn't read MFT Record %lld.\n", record); + ntfs_attr_close(mft); + free_file(file); return NULL; } - ntfs_attr_close (mft); + ntfs_attr_close(mft); mft = NULL; - attr10 = find_first_attribute (AT_STANDARD_INFORMATION, file->mft); - attr20 = find_first_attribute (AT_ATTRIBUTE_LIST, file->mft); - attr90 = find_first_attribute (AT_INDEX_ROOT, file->mft); + attr10 = find_first_attribute(AT_STANDARD_INFORMATION, file->mft); + attr20 = find_first_attribute(AT_ATTRIBUTE_LIST, file->mft); + attr90 = find_first_attribute(AT_INDEX_ROOT, file->mft); ntfs_log_debug("Attributes present: %s %s %s.\n", attr10?"0x10":"", attr20?"0x20":"", attr90?"0x90":""); if (attr10) { STANDARD_INFORMATION *si; - si = (STANDARD_INFORMATION *) ((char *) attr10 + le16_to_cpu (attr10->value_offset)); - file->date = ntfs2utc (si->last_data_change_time); + si = (STANDARD_INFORMATION *) ((char *) attr10 + le16_to_cpu(attr10->value_offset)); + file->date = ntfs2utc(si->last_data_change_time); } if (attr20 || !attr10) @@ -1092,11 +1092,11 @@ static struct ufile * read_record (ntfs_volume *vol, long long record) if (attr90) file->directory = 1; - if (get_filenames (file, vol) < 0) { - Eprintf ("ERROR: Couldn't get filenames.\n"); + if (get_filenames(file, vol) < 0) { + Eprintf("ERROR: Couldn't get filenames.\n"); } - if (get_data (file, vol) < 0) { - Eprintf ("ERROR: Couldn't get data streams.\n"); + if (get_data(file, vol) < 0) { + Eprintf("ERROR: Couldn't get data streams.\n"); } return file; @@ -1125,7 +1125,7 @@ static struct ufile * read_record (ntfs_volume *vol, long long record) * Return: n The percentage of the file that _could_ be recovered * -1 Error */ -static int calc_percentage (struct ufile *file, ntfs_volume *vol) +static int calc_percentage(struct ufile *file, ntfs_volume *vol) { runlist_element *rl = NULL; struct list_head *pos; @@ -1143,28 +1143,28 @@ static int calc_percentage (struct ufile *file, ntfs_volume *vol) return 0; } - if (list_empty (&file->data)) { - Vprintf ("File has no data streams.\n"); + if (list_empty(&file->data)) { + Vprintf("File has no data streams.\n"); return 0; } - list_for_each (pos, &file->data) { - data = list_entry (pos, struct data, list); + list_for_each(pos, &file->data) { + data = list_entry(pos, struct data, list); clusters_inuse = 0; clusters_free = 0; if (data->encrypted) { - Vprintf ("File is encrypted, recovery is impossible.\n"); + Vprintf("File is encrypted, recovery is impossible.\n"); continue; } if (data->compressed) { - Vprintf ("File is compressed, recovery not yet implemented.\n"); + Vprintf("File is compressed, recovery not yet implemented.\n"); continue; } if (data->resident) { - Vprintf ("File is resident, therefore recoverable.\n"); + Vprintf("File is resident, therefore recoverable.\n"); percent = 100; data->percent = 100; continue; @@ -1172,17 +1172,17 @@ static int calc_percentage (struct ufile *file, ntfs_volume *vol) rl = data->runlist; if (!rl) { - Vprintf ("File has no runlist, hence no data.\n"); + Vprintf("File has no runlist, hence no data.\n"); continue; } if (rl[0].length <= 0) { - Vprintf ("File has an empty runlist, hence no data.\n"); + Vprintf("File has an empty runlist, hence no data.\n"); continue; } if (rl[0].lcn == LCN_RL_NOT_MAPPED) { /* extended mft record */ - Vprintf ("Missing segment at beginning, %lld " + Vprintf("Missing segment at beginning, %lld " "clusters\n", (long long)rl[0].length); clusters_inuse += rl[0].length; rl++; @@ -1190,7 +1190,7 @@ static int calc_percentage (struct ufile *file, ntfs_volume *vol) for (i = 0; rl[i].length > 0; i++) { if (rl[i].lcn == LCN_RL_NOT_MAPPED) { - Vprintf ("Missing segment at end, %lld " + Vprintf("Missing segment at end, %lld " "clusters\n", (long long)rl[i].length); clusters_inuse += rl[i].length; @@ -1206,7 +1206,7 @@ static int calc_percentage (struct ufile *file, ntfs_volume *vol) end = rl[i].lcn + rl[i].length; for (j = start; j < end; j++) { - if (utils_cluster_in_use (vol, j)) + if (utils_cluster_in_use(vol, j)) clusters_inuse++; else clusters_free++; @@ -1214,17 +1214,17 @@ static int calc_percentage (struct ufile *file, ntfs_volume *vol) } if ((clusters_inuse + clusters_free) == 0) { - Eprintf ("ERROR: Unexpected error whilst calculating percentage for inode %lld\n", file->inode); + Eprintf("ERROR: Unexpected error whilst calculating percentage for inode %lld\n", file->inode); continue; } data->percent = (clusters_free * 100) / (clusters_inuse + clusters_free); - percent = max (percent, data->percent); + percent = max(percent, data->percent); } - Vprintf ("File is %d%% recoverable\n", percent); + Vprintf("File is %d%% recoverable\n", percent); return percent; } @@ -1243,7 +1243,7 @@ static int calc_percentage (struct ufile *file, ntfs_volume *vol) * * Return: none */ -static void dump_record (struct ufile *file) +static void dump_record(struct ufile *file) { char buffer[20]; const char *name; @@ -1253,88 +1253,88 @@ static void dump_record (struct ufile *file) if (!file) return; - Qprintf ("MFT Record %lld\n", file->inode); - Qprintf ("Type: %s\n", (file->directory) ? "Directory" : "File"); - strftime (buffer, sizeof (buffer), "%F %R", localtime (&file->date)); - Qprintf ("Date: %s\n", buffer); + Qprintf("MFT Record %lld\n", file->inode); + Qprintf("Type: %s\n", (file->directory) ? "Directory" : "File"); + strftime(buffer, sizeof(buffer), "%F %R", localtime(&file->date)); + Qprintf("Date: %s\n", buffer); if (file->attr_list) - Qprintf ("Metadata may span more than one MFT record\n"); + Qprintf("Metadata may span more than one MFT record\n"); - list_for_each (item, &file->name) { - struct filename *f = list_entry (item, struct filename, list); + list_for_each(item, &file->name) { + struct filename *f = list_entry(item, struct filename, list); if (f->name) name = f->name; else name = NONE; - Qprintf ("Filename: (%d) %s\n", f->name_space, f->name); - Qprintf ("File Flags: "); - if (f->flags & FILE_ATTR_SYSTEM) Qprintf ("System "); - if (f->flags & FILE_ATTR_DIRECTORY) Qprintf ("Directory "); - if (f->flags & FILE_ATTR_SPARSE_FILE) Qprintf ("Sparse "); - if (f->flags & FILE_ATTR_REPARSE_POINT) Qprintf ("Reparse "); - if (f->flags & FILE_ATTR_COMPRESSED) Qprintf ("Compressed "); - if (f->flags & FILE_ATTR_ENCRYPTED) Qprintf ("Encrypted "); + Qprintf("Filename: (%d) %s\n", f->name_space, f->name); + Qprintf("File Flags: "); + if (f->flags & FILE_ATTR_SYSTEM) Qprintf("System "); + if (f->flags & FILE_ATTR_DIRECTORY) Qprintf("Directory "); + if (f->flags & FILE_ATTR_SPARSE_FILE) Qprintf("Sparse "); + if (f->flags & FILE_ATTR_REPARSE_POINT) Qprintf("Reparse "); + if (f->flags & FILE_ATTR_COMPRESSED) Qprintf("Compressed "); + if (f->flags & FILE_ATTR_ENCRYPTED) Qprintf("Encrypted "); if (!(f->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_DIRECTORY | FILE_ATTR_SPARSE_FILE | FILE_ATTR_REPARSE_POINT | FILE_ATTR_COMPRESSED | FILE_ATTR_ENCRYPTED))) { - Qprintf ("%s", NONE); + Qprintf("%s", NONE); } - Qprintf ("\n"); + Qprintf("\n"); if (opts.parent) { - Qprintf ("Parent: %s\n", f->parent_name ? f->parent_name : ""); + Qprintf("Parent: %s\n", f->parent_name ? f->parent_name : ""); } - Qprintf ("Size alloc: %lld\n", f->size_alloc); - Qprintf ("Size data: %lld\n", f->size_data); + Qprintf("Size alloc: %lld\n", f->size_alloc); + Qprintf("Size data: %lld\n", f->size_data); - strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_c)); - Qprintf ("Date C: %s\n", buffer); - strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_a)); - Qprintf ("Date A: %s\n", buffer); - strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_m)); - Qprintf ("Date M: %s\n", buffer); - strftime (buffer, sizeof (buffer), "%F %R", localtime (&f->date_r)); - Qprintf ("Date R: %s\n", buffer); + strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_c)); + Qprintf("Date C: %s\n", buffer); + strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_a)); + Qprintf("Date A: %s\n", buffer); + strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_m)); + Qprintf("Date M: %s\n", buffer); + strftime(buffer, sizeof(buffer), "%F %R", localtime(&f->date_r)); + Qprintf("Date R: %s\n", buffer); } - Qprintf ("Data Streams:\n"); - list_for_each (item, &file->data) { - struct data *d = list_entry (item, struct data, list); - Qprintf ("Name: %s\n", (d->name) ? d->name : UNNAMED); - Qprintf ("Flags: "); - if (d->resident) Qprintf ("Resident\n"); - if (d->compressed) Qprintf ("Compressed\n"); - if (d->encrypted) Qprintf ("Encrypted\n"); + Qprintf("Data Streams:\n"); + list_for_each(item, &file->data) { + struct data *d = list_entry(item, struct data, list); + Qprintf("Name: %s\n", (d->name) ? d->name : UNNAMED); + Qprintf("Flags: "); + if (d->resident) Qprintf("Resident\n"); + if (d->compressed) Qprintf("Compressed\n"); + if (d->encrypted) Qprintf("Encrypted\n"); if (!d->resident && !d->compressed && !d->encrypted) - Qprintf ("None\n"); + Qprintf("None\n"); else - Qprintf ("\n"); + Qprintf("\n"); - Qprintf ("Size alloc: %lld\n", d->size_alloc); - Qprintf ("Size data: %lld\n", d->size_data); - Qprintf ("Size init: %lld\n", d->size_init); - Qprintf ("Size vcn: %lld\n", d->size_vcn); + Qprintf("Size alloc: %lld\n", d->size_alloc); + Qprintf("Size data: %lld\n", d->size_data); + Qprintf("Size init: %lld\n", d->size_init); + Qprintf("Size vcn: %lld\n", d->size_vcn); - Qprintf ("Data runs:\n"); + Qprintf("Data runs:\n"); if ((!d->runlist) || (d->runlist[0].length <= 0)) { - Qprintf (" None\n"); + Qprintf(" None\n"); } else { for (i = 0; d->runlist[i].length > 0; i++) { - Qprintf (" %lld @ %lld\n", + Qprintf(" %lld @ %lld\n", (long long)d->runlist[i].length, (long long)d->runlist[i].lcn); } } - Qprintf ("Amount potentially recoverable %d%%\n", d->percent); + Qprintf("Amount potentially recoverable %d%%\n", d->percent); } - Qprintf ("________________________________________\n\n"); + Qprintf("________________________________________\n\n"); } /** @@ -1360,7 +1360,7 @@ static void dump_record (struct ufile *file) * * Return: none */ -static void list_record (struct ufile *file) +static void list_record(struct ufile *file) { char buffer[20]; struct list_head *item; @@ -1370,7 +1370,7 @@ static void list_record (struct ufile *file) char flagd = '.', flagr = '.', flagc = '.', flagx = '.'; - strftime (buffer, sizeof (buffer), "%F", localtime (&file->date)); + strftime(buffer, sizeof(buffer), "%F", localtime(&file->date)); if (file->attr_list) flagx = '!'; @@ -1380,8 +1380,8 @@ static void list_record (struct ufile *file) else flagd = 'F'; - list_for_each (item, &file->data) { - struct data *d = list_entry (item, struct data, list); + list_for_each(item, &file->data) { + struct data *d = list_entry(item, struct data, list); if (!d->name) { if (d->resident) flagr = 'R'; @@ -1389,11 +1389,11 @@ static void list_record (struct ufile *file) if (d->compressed) flagc = 'C'; /* These two are mutually exclusive */ if (d->encrypted) flagc = 'E'; - percent = max (percent, d->percent); + percent = max(percent, d->percent); } - size = max (size, d->size_data); - size = max (size, d->size_init); + size = max(size, d->size_data); + size = max(size, d->size_init); } if (file->pref_name) @@ -1401,7 +1401,7 @@ static void list_record (struct ufile *file) else name = NONE; - Qprintf ("%-8lld %c%c%c%c %3d%% %s %9lld %s\n", + Qprintf("%-8lld %c%c%c%c %3d%% %s %9lld %s\n", file->inode, flagd, flagr, flagc, flagx, percent, buffer, size, name); @@ -1418,7 +1418,7 @@ static void list_record (struct ufile *file) * Return: 1 There is a matching filename. * 0 There is no match. */ -static int name_match (regex_t *re, struct ufile *file) +static int name_match(regex_t *re, struct ufile *file) { struct list_head *item; int result; @@ -1426,14 +1426,14 @@ static int name_match (regex_t *re, struct ufile *file) if (!re || !file) return 0; - list_for_each (item, &file->name) { - struct filename *f = list_entry (item, struct filename, list); + list_for_each(item, &file->name) { + struct filename *f = list_entry(item, struct filename, list); if (!f->name) continue; - result = regexec (re, f->name, 0, NULL, 0); + result = regexec(re, f->name, 0, NULL, 0); if (result < 0) { - Eprintf ("Couldn't compare filename with regex: %s\n", strerror (errno)); + Eprintf("Couldn't compare filename with regex: %s\n", strerror(errno)); return 0; } else if (result == REG_NOERROR) { ntfs_log_debug("Found a matching filename.\n"); @@ -1456,7 +1456,7 @@ static int name_match (regex_t *re, struct ufile *file) * Return: -1 Error, something went wrong * 0 Success, all the data was written */ -static unsigned int write_data (int fd, const char *buffer, +static unsigned int write_data(int fd, const char *buffer, unsigned int bufsize) { ssize_t result1, result2; @@ -1466,7 +1466,7 @@ static unsigned int write_data (int fd, const char *buffer, return -1; } - result1 = write (fd, buffer, bufsize); + result1 = write(fd, buffer, bufsize); if ((result1 == (ssize_t) bufsize) || (result1 < 0)) return result1; @@ -1474,7 +1474,7 @@ static unsigned int write_data (int fd, const char *buffer, buffer += result1; bufsize -= result1; - result2 = write (fd, buffer, bufsize); + result2 = write(fd, buffer, bufsize); if (result2 < 0) return result1; @@ -1504,7 +1504,7 @@ static unsigned int write_data (int fd, const char *buffer, * * Return: n Length of the allocated name */ -static int create_pathname (const char *dir, const char *name, +static int create_pathname(const char *dir, const char *name, const char *stream, char *buffer, int bufsize) { if (!name) @@ -1512,16 +1512,16 @@ static int create_pathname (const char *dir, const char *name, if (dir) if (stream) - snprintf (buffer, bufsize, "%s/%s:%s", dir, name, stream); + snprintf(buffer, bufsize, "%s/%s:%s", dir, name, stream); else - snprintf (buffer, bufsize, "%s/%s", dir, name); + snprintf(buffer, bufsize, "%s/%s", dir, name); else if (stream) - snprintf (buffer, bufsize, "%s:%s", name, stream); + snprintf(buffer, bufsize, "%s:%s", name, stream); else - snprintf (buffer, bufsize, "%s", name); + snprintf(buffer, bufsize, "%s", name); - return strlen (buffer); + return strlen(buffer); } /** @@ -1535,18 +1535,18 @@ static int create_pathname (const char *dir, const char *name, * Return: -1 Error, failed to create the file * n Success, this is the file descriptor */ -static int open_file (const char *pathname) +static int open_file(const char *pathname) { int flags; - Vprintf ("Creating file: %s\n", pathname); + Vprintf("Creating file: %s\n", pathname); if (opts.force) flags = O_RDWR | O_CREAT | O_TRUNC; else flags = O_RDWR | O_CREAT | O_EXCL; - return open (pathname, flags, S_IRUSR | S_IWUSR); + return open(pathname, flags, S_IRUSR | S_IWUSR); } /** @@ -1559,7 +1559,7 @@ static int open_file (const char *pathname) * Return: 1 Success, set the file's date and time * 0 Error, failed to change the file's date and time */ -static int set_date (const char *pathname, time_t date) +static int set_date(const char *pathname, time_t date) { struct utimbuf ut; @@ -1568,8 +1568,8 @@ static int set_date (const char *pathname, time_t date) ut.actime = date; ut.modtime = date; - if (utime (pathname, &ut)) { - Eprintf ("ERROR: Couldn't set the file's date and time\n"); + if (utime(pathname, &ut)) { + Eprintf("ERROR: Couldn't set the file's date and time\n"); return 0; } return 1; @@ -1597,7 +1597,7 @@ static int set_date (const char *pathname, time_t date) * Return: 0 Error, something went wrong * 1 Success, the data was recovered */ -static int undelete_file (ntfs_volume *vol, long long inode) +static int undelete_file(ntfs_volume *vol, long long inode) { char pathname[256]; char *buffer = NULL; @@ -1617,101 +1617,101 @@ static int undelete_file (ntfs_volume *vol, long long inode) return 0; /* try to get record */ - file = read_record (vol, inode); + file = read_record(vol, inode); if (!file || !file->mft) { - Eprintf ("Can't read info from mft record %lld.\n", inode); + Eprintf("Can't read info from mft record %lld.\n", inode); return 0; } /* if flag was not set, print file informations */ if (avoid_duplicate_printing == 0) { if (opts.verbose) { - dump_record (file); + dump_record(file); } else { - list_record (file); - //Qprintf ("\n"); + list_record(file); + //Qprintf("\n"); } } bufsize = vol->cluster_size; - buffer = malloc (bufsize); + buffer = malloc(bufsize); if (!buffer) goto free; if (file->mft->flags & MFT_RECORD_IN_USE) { /* These two statement blocks were */ - Eprintf ("Record is in use by the mft\n"); /* relocated from below because */ + Eprintf("Record is in use by the mft\n"); /* relocated from below because */ if (!opts.force) { /* calc_percentage() must be called */ free(buffer); - free_file (file); /* before dump_record() or list_record(). */ + free_file(file); /* before dump_record() or list_record(). */ return 0; /* Otherwise, when undeleting, a file */ } /* will always be listed as 0% recoverable */ - Vprintf ("Forced to continue.\n"); /* even if successfully undeleted. +mabs */ + Vprintf("Forced to continue.\n"); /* even if successfully undeleted. +mabs */ } - if (calc_percentage (file, vol) == 0) { - Qprintf ("File has no recoverable data.\n"); + if (calc_percentage(file, vol) == 0) { + Qprintf("File has no recoverable data.\n"); goto free; } - if (list_empty (&file->data)) { - Qprintf ("File has no data. There is nothing to recover.\n"); + if (list_empty(&file->data)) { + Qprintf("File has no data. There is nothing to recover.\n"); goto free; } - list_for_each (item, &file->data) { - struct data *d = list_entry (item, struct data, list); + list_for_each(item, &file->data) { + struct data *d = list_entry(item, struct data, list); if (opts.output) name = opts.output; else name = file->pref_name; - create_pathname (opts.dest, name, d->name, pathname, sizeof (pathname)); + create_pathname(opts.dest, name, d->name, pathname, sizeof(pathname)); if (d->resident) { - fd = open_file (pathname); + fd = open_file(pathname); if (fd < 0) { - Eprintf ("Couldn't create file: %s\n", strerror (errno)); + Eprintf("Couldn't create file: %s\n", strerror(errno)); goto free; } - Vprintf ("File has resident data.\n"); - if (write_data (fd, d->data, d->size_data) < d->size_data) { - Eprintf ("Write failed: %s\n", strerror (errno)); - close (fd); + Vprintf("File has resident data.\n"); + if (write_data(fd, d->data, d->size_data) < d->size_data) { + Eprintf("Write failed: %s\n", strerror(errno)); + close(fd); goto free; } - if (close (fd) < 0) { - Eprintf ("Close failed: %s\n", strerror (errno)); + if (close(fd) < 0) { + Eprintf("Close failed: %s\n", strerror(errno)); } fd = -1; } else { rl = d->runlist; if (!rl) { - Vprintf ("File has no runlist, hence no data.\n"); + Vprintf("File has no runlist, hence no data.\n"); continue; } if (rl[0].length <= 0) { - Vprintf ("File has an empty runlist, hence no data.\n"); + Vprintf("File has an empty runlist, hence no data.\n"); continue; } - fd = open_file (pathname); + fd = open_file(pathname); if (fd < 0) { - Eprintf ("Couldn't create output file: %s\n", strerror (errno)); + Eprintf("Couldn't create output file: %s\n", strerror(errno)); goto free; } if (rl[0].lcn == LCN_RL_NOT_MAPPED) { /* extended mft record */ - Vprintf ("Missing segment at beginning, %lld " + Vprintf("Missing segment at beginning, %lld " "clusters.\n", (long long)rl[0].length); - memset (buffer, opts.fillbyte, bufsize); + memset(buffer, opts.fillbyte, bufsize); for (k = 0; k < rl[0].length * vol->cluster_size; k += bufsize) { - if (write_data (fd, buffer, bufsize) < bufsize) { - Eprintf ("Write failed: %s\n", strerror (errno)); - close (fd); + if (write_data(fd, buffer, bufsize) < bufsize) { + Eprintf("Write failed: %s\n", strerror(errno)); + close(fd); goto free; } } @@ -1721,14 +1721,14 @@ static int undelete_file (ntfs_volume *vol, long long inode) for (i = 0; rl[i].length > 0; i++) { if (rl[i].lcn == LCN_RL_NOT_MAPPED) { - Vprintf ("Missing segment at end, " + Vprintf("Missing segment at end, " "%lld clusters.\n", (long long)rl[i].length); - memset (buffer, opts.fillbyte, bufsize); + memset(buffer, opts.fillbyte, bufsize); for (k = 0; k < rl[k].length * vol->cluster_size; k += bufsize) { - if (write_data (fd, buffer, bufsize) < bufsize) { - Eprintf ("Write failed: %s\n", strerror (errno)); - close (fd); + if (write_data(fd, buffer, bufsize) < bufsize) { + Eprintf("Write failed: %s\n", strerror(errno)); + close(fd); goto free; } cluster_count++; @@ -1737,12 +1737,12 @@ static int undelete_file (ntfs_volume *vol, long long inode) } if (rl[i].lcn == LCN_HOLE) { - Vprintf ("File has a sparse section.\n"); - memset (buffer, 0, bufsize); + Vprintf("File has a sparse section.\n"); + memset(buffer, 0, bufsize); for (k = 0; k < rl[k].length * vol->cluster_size; k += bufsize) { - if (write_data (fd, buffer, bufsize) < bufsize) { - Eprintf ("Write failed: %s\n", strerror (errno)); - close (fd); + if (write_data(fd, buffer, bufsize) < bufsize) { + Eprintf("Write failed: %s\n", strerror(errno)); + close(fd); goto free; } } @@ -1753,42 +1753,44 @@ static int undelete_file (ntfs_volume *vol, long long inode) end = rl[i].lcn + rl[i].length; for (j = start; j < end; j++) { - if (utils_cluster_in_use (vol, j) && !opts.optimistic) { - memset (buffer, opts.fillbyte, bufsize); - if (write_data (fd, buffer, bufsize) < bufsize) { - Eprintf ("Write failed: %s\n", strerror (errno)); - close (fd); + if (utils_cluster_in_use(vol, j) && !opts.optimistic) { + memset(buffer, opts.fillbyte, bufsize); + if (write_data(fd, buffer, bufsize) < bufsize) { + Eprintf("Write failed: %s\n", strerror(errno)); + close(fd); goto free; } } else { if (ntfs_cluster_read(vol, j, 1, buffer) < 1) { - Eprintf ("Read failed: %s\n", strerror (errno)); - close (fd); + Eprintf("Read failed: %s\n", strerror(errno)); + close(fd); goto free; } - if (write_data (fd, buffer, bufsize) < bufsize) { - Eprintf ("Write failed: %s\n", strerror (errno)); - close (fd); + if (write_data(fd, buffer, bufsize) < bufsize) { + Eprintf("Write failed: %s\n", strerror(errno)); + close(fd); goto free; } cluster_count++; } } } - Qprintf ("\n"); + Qprintf("\n"); - /* The following block of code implements the --truncate option. */ - /* Its semantics are as follows: */ - /* IF opts.truncate is set AND data stream currently being recovered is */ - /* non-resident AND data stream has no holes (100% recoverability) AND */ - /* 0 <= (data->size_alloc - data->size_data) <= vol->cluster_size AND */ - /* cluster_count * vol->cluster_size == data->size_alloc THEN file */ - /* currently being written is truncated to data->size_data bytes before */ - /* it's closed. */ - /* This multiple checks try to ensure that only files with consistent */ - /* values of size/occupied clusters are eligible for truncation. Note */ - /* that resident streams need not be truncated, since the original code */ - /* already recovers their exact length. +mabs */ + /* + * The following block of code implements the --truncate option. + * Its semantics are as follows: + * IF opts.truncate is set AND data stream currently being recovered is + * non-resident AND data stream has no holes (100% recoverability) AND + * 0 <= (data->size_alloc - data->size_data) <= vol->cluster_size AND + * cluster_count * vol->cluster_size == data->size_alloc THEN file + * currently being written is truncated to data->size_data bytes before + * it's closed. + * This multiple checks try to ensure that only files with consistent + * values of size/occupied clusters are eligible for truncation. Note + * that resident streams need not be truncated, since the original code + * already recovers their exact length. +mabs + */ if (opts.truncate) { if (d->percent == 100 && d->size_alloc >= d->size_data && @@ -1800,23 +1802,23 @@ static int undelete_file (ntfs_volume *vol, long long inode) "inconsistent $MFT record.\n"); } - if (close (fd) < 0) { - Eprintf ("Close failed: %s\n", strerror (errno)); + if (close(fd) < 0) { + Eprintf("Close failed: %s\n", strerror(errno)); } fd = -1; } - set_date (pathname, file->date); + set_date(pathname, file->date); if (d->name) - Qprintf ("Undeleted '%s:%s' successfully.\n", file->pref_name, d->name); + Qprintf("Undeleted '%s:%s' successfully.\n", file->pref_name, d->name); else - Qprintf ("Undeleted '%s' successfully.\n", file->pref_name); + Qprintf("Undeleted '%s' successfully.\n", file->pref_name); } result = 1; free: if (buffer) - free (buffer); - free_file (file); + free(buffer); + free_file(file); return result; } @@ -1832,7 +1834,7 @@ free: * Return: -1 Error, something went wrong * n Success, the number of recoverable files */ -static int scan_disk (ntfs_volume *vol) +static int scan_disk(ntfs_volume *vol) { s64 nr_mft_records; const int BUFSIZE = 8192; @@ -1849,16 +1851,16 @@ static int scan_disk (ntfs_volume *vol) if (!vol) return -1; - attr = ntfs_attr_open (vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); + attr = ntfs_attr_open(vol->mft_ni, AT_BITMAP, AT_UNNAMED, 0); if (!attr) { - Eprintf ("ERROR: Couldn't open $MFT/$BITMAP: %s\n", strerror (errno)); + Eprintf("ERROR: Couldn't open $MFT/$BITMAP: %s\n", strerror(errno)); return -1; } bmpsize = attr->initialized_size; - buffer = malloc (BUFSIZE); + buffer = malloc(BUFSIZE); if (!buffer) { - Eprintf ("ERROR: Couldn't allocate memory in scan_disk()\n"); + Eprintf("ERROR: Couldn't allocate memory in scan_disk()\n"); results = -1; goto out; } @@ -1868,8 +1870,8 @@ static int scan_disk (ntfs_volume *vol) if (!opts.match_case) flags |= REG_ICASE; - if (regcomp (&re, opts.match, flags)) { - Eprintf ("ERROR: Couldn't create a regex.\n"); + if (regcomp(&re, opts.match, flags)) { + Eprintf("ERROR: Couldn't create a regex.\n"); goto out; } } @@ -1877,11 +1879,11 @@ static int scan_disk (ntfs_volume *vol) nr_mft_records = vol->mft_na->initialized_size >> vol->mft_record_size_bits; - Qprintf ("Inode Flags %%age Date Size Filename\n"); - Qprintf ("---------------------------------------------------------------\n"); + Qprintf("Inode Flags %%age Date Size Filename\n"); + Qprintf("---------------------------------------------------------------\n"); for (i = 0; i < bmpsize; i += BUFSIZE) { - long long read_count = min ((bmpsize - i), BUFSIZE); - size = ntfs_attr_pread (attr, i, read_count, buffer); + long long read_count = min((bmpsize - i), BUFSIZE); + size = ntfs_attr_pread(attr, i, read_count, buffer); if (size < 0) break; @@ -1892,36 +1894,36 @@ static int scan_disk (ntfs_volume *vol) goto done; if (b & 1) continue; - file = read_record (vol, (i+j)*8+k); + file = read_record(vol, (i+j)*8+k); if (!file) { - Eprintf ("Couldn't read MFT Record %d.\n", (i+j)*8+k); + Eprintf("Couldn't read MFT Record %d.\n", (i+j)*8+k); continue; } if ((opts.since > 0) && (file->date <= opts.since)) goto skip; - if (opts.match && !name_match (&re, file)) + if (opts.match && !name_match(&re, file)) goto skip; if (opts.size_begin && (opts.size_begin > file->max_size)) goto skip; if (opts.size_end && (opts.size_end < file->max_size)) goto skip; - percent = calc_percentage (file, vol); + percent = calc_percentage(file, vol); if ((opts.percent == -1) || (percent >= opts.percent)) { if (opts.verbose) - dump_record (file); + dump_record(file); else - list_record (file); + list_record(file); /* Was -u specified with no inode so undelete file by regex */ if (opts.mode == MODE_UNDELETE) { - if (!undelete_file (vol, file->inode)) - Vprintf ("ERROR: Failed to undelete " - "inode %lli\n!", - file->inode); - printf ("\n"); + if (!undelete_file(vol, file->inode)) + Vprintf("ERROR: Failed to undelete " + "inode %lli\n!", + file->inode); + printf("\n"); } } if (((opts.percent == -1) && (percent > 0)) || @@ -1929,18 +1931,18 @@ static int scan_disk (ntfs_volume *vol) results++; } skip: - free_file (file); + free_file(file); } } } done: - Qprintf ("\nFiles with potentially recoverable content: %d\n", results); + Qprintf("\nFiles with potentially recoverable content: %d\n", results); out: if (opts.match) - regfree (&re); - free (buffer); + regfree(&re); + free(buffer); if (attr) - ntfs_attr_close (attr); + ntfs_attr_close(attr); return results; } @@ -1955,7 +1957,7 @@ out: * Return: 0 Success, all the records were written * 1 Error, something went wrong */ -static int copy_mft (ntfs_volume *vol, long long mft_begin, long long mft_end) +static int copy_mft(ntfs_volume *vol, long long mft_begin, long long mft_end) { s64 nr_mft_records; char pathname[256]; @@ -1970,19 +1972,19 @@ static int copy_mft (ntfs_volume *vol, long long mft_begin, long long mft_end) return 1; if (mft_end < mft_begin) { - Eprintf ("Range to copy is backwards.\n"); + Eprintf("Range to copy is backwards.\n"); return 1; } - buffer = malloc (vol->mft_record_size); + buffer = malloc(vol->mft_record_size); if (!buffer) { - Eprintf ("Couldn't allocate memory in copy_mft()\n"); + Eprintf("Couldn't allocate memory in copy_mft()\n"); return 1; } - mft = ntfs_attr_open (vol->mft_ni, AT_DATA, AT_UNNAMED, 0); + mft = ntfs_attr_open(vol->mft_ni, AT_DATA, AT_UNNAMED, 0); if (!mft) { - Eprintf ("Couldn't open $MFT/$DATA: %s\n", strerror (errno)); + Eprintf("Couldn't open $MFT/$DATA: %s\n", strerror(errno)); goto free; } @@ -1993,17 +1995,17 @@ static int copy_mft (ntfs_volume *vol, long long mft_begin, long long mft_end) name); } - create_pathname (opts.dest, name, NULL, pathname, sizeof (pathname)); - fd = open_file (pathname); + create_pathname(opts.dest, name, NULL, pathname, sizeof(pathname)); + fd = open_file(pathname); if (fd < 0) { - Eprintf ("Couldn't open output file '%s': %s\n", name, strerror (errno)); + Eprintf("Couldn't open output file '%s': %s\n", name, strerror(errno)); goto attr; } nr_mft_records = vol->mft_na->initialized_size >> vol->mft_record_size_bits; - mft_end = min (mft_end, nr_mft_records - 1); + mft_end = min(mft_end, nr_mft_records - 1); ntfs_log_debug("MFT records:\n"); ntfs_log_debug("\tTotal: %8lld\n", nr_mft_records); @@ -2011,25 +2013,25 @@ static int copy_mft (ntfs_volume *vol, long long mft_begin, long long mft_end) ntfs_log_debug("\tEnd: %8lld\n", mft_end); for (i = mft_begin; i <= mft_end; i++) { - if (ntfs_attr_pread (mft, vol->mft_record_size * i, vol->mft_record_size, buffer) < vol->mft_record_size) { - Eprintf ("Couldn't read MFT Record %lld: %s.\n", i, strerror (errno)); + if (ntfs_attr_pread(mft, vol->mft_record_size * i, vol->mft_record_size, buffer) < vol->mft_record_size) { + Eprintf("Couldn't read MFT Record %lld: %s.\n", i, strerror(errno)); goto close; } - if (write_data (fd, buffer, vol->mft_record_size) < vol->mft_record_size) { - Eprintf ("Write failed: %s\n", strerror (errno)); + if (write_data(fd, buffer, vol->mft_record_size) < vol->mft_record_size) { + Eprintf("Write failed: %s\n", strerror(errno)); goto close; } } - Vprintf ("Read %lld MFT Records\n", mft_end - mft_begin + 1); + Vprintf("Read %lld MFT Records\n", mft_end - mft_begin + 1); result = 0; close: - close (fd); + close(fd); attr: - ntfs_attr_close (mft); + ntfs_attr_close(mft); free: - free (buffer); + free(buffer); return result; } @@ -2037,7 +2039,7 @@ free: * handle_undelete * Handles the undelete */ -static int handle_undelete (ntfs_volume *vol) +static int handle_undelete(ntfs_volume *vol) { int result = 1; int i; @@ -2046,25 +2048,25 @@ static int handle_undelete (ntfs_volume *vol) /* Check whether (an) inode(s) was specified or at least a regex! */ if (nr_entries == 0) { if (with_regex == 0) { - printf ("ERROR: NO inode(s) AND NO match-regex specified!\n"); + printf("ERROR: NO inode(s) AND NO match-regex specified!\n"); } else { avoid_duplicate_printing= 1; - result = !scan_disk (vol); + result = !scan_disk(vol); if (result) - Vprintf ("ERROR: Failed to scan device '%s'.\n", opts.device); + Vprintf("ERROR: Failed to scan device '%s'.\n", opts.device); } } else { /* Normal undelete by specifying inode(s) */ - Qprintf ("Inode Flags %%age Date Size Filename\n"); - Qprintf ("---------------------------------------------------------------\n"); + Qprintf("Inode Flags %%age Date Size Filename\n"); + Qprintf("---------------------------------------------------------------\n"); /* loop all given inodes */ for (i = 0; i < nr_entries; i++) { for (inode = ranges[i].begin; inode <= ranges[i].end; inode ++) { /* Now undelete file */ - result = !undelete_file (vol, inode); + result = !undelete_file(vol, inode); if (result) - Vprintf ("ERROR: Failed to undelete " + Vprintf("ERROR: Failed to undelete " "inode %lli\n!", inode); } @@ -2081,7 +2083,7 @@ static int handle_undelete (ntfs_volume *vol) * 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; int result = 1; @@ -2089,12 +2091,12 @@ int main (int argc, char *argv[]) with_regex = 0; avoid_duplicate_printing = 0; - if (!parse_options (argc, argv)) + if (!parse_options(argc, argv)) goto free; 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; @@ -2102,21 +2104,21 @@ int main (int argc, char *argv[]) switch (opts.mode) { /* Scanning */ case MODE_SCAN: - result = !scan_disk (vol); + result = !scan_disk(vol); if (result) - Vprintf ("ERROR: Failed to scan device '%s'.\n", opts.device); + Vprintf("ERROR: Failed to scan device '%s'.\n", opts.device); break; /* Undelete-handling */ case MODE_UNDELETE: - result= handle_undelete (vol); + result= handle_undelete(vol); break; /* Handling of copy mft */ case MODE_COPY: - result = !copy_mft (vol, opts.mft_begin, opts.mft_end); + result = !copy_mft(vol, opts.mft_begin, opts.mft_end); if (result) - Vprintf ("ERROR: Failed to read MFT blocks %lld-%lld.\n", + Vprintf("ERROR: Failed to read MFT blocks %lld-%lld.\n", opts.mft_begin, min((vol->mft_na->initialized_size >> vol->mft_record_size_bits) , opts.mft_end)); @@ -2125,10 +2127,10 @@ int main (int argc, char *argv[]) ; /* Cannot happen */ } - ntfs_umount (vol, FALSE); + ntfs_umount(vol, FALSE); free: if (opts.match) - free (opts.match); + free(opts.match); return result; } diff --git a/ntfsprogs/ntfswipe.c b/ntfsprogs/ntfswipe.c index 30a352c7..6f54af07 100644 --- a/ntfsprogs/ntfswipe.c +++ b/ntfsprogs/ntfswipe.c @@ -59,9 +59,9 @@ static const char *EXEC_NAME = "ntfswipe"; 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 @@ -70,14 +70,14 @@ GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE) * * Return: none */ -static void version (void) +static void version(void) { printf("\n%s v%s (libntfs %s) - Overwrite the unused space on an NTFS " "Volume.\n\n", EXEC_NAME, VERSION, ntfs_libntfs_version()); - printf ("Copyright (c) 2002-2003 Richard Russon\n"); - printf ("Copyright (c) 2004 Yura Pakhuchiy\n"); - printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); + printf("Copyright (c) 2002-2003 Richard Russon\n"); + printf("Copyright (c) 2004 Yura Pakhuchiy\n"); + printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home); } /** @@ -87,9 +87,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 Show volume information (default)\n" "\n" " -d --directory Wipe directory indexes\n" @@ -101,8 +101,8 @@ static void usage (void) "\n" " -a --all Wipe all unused space\n" "\n" - " -c num --count num Number of times to write (default = 1)\n" - " -b list --bytes list List of values to write (default = 0)\n" + " -c num --count num Number of times to write(default = 1)\n" + " -b list --bytes list List of values to write(default = 0)\n" "\n" " -n --no-action Do not write to disk\n" " -f --force Use less caution\n" @@ -111,7 +111,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); } /** @@ -128,7 +128,7 @@ static void usage (void) * Return: 0 Error, invalid string * n Success, the count of numbers parsed */ -static int parse_list (char *list, int **result) +static int parse_list(char *list, int **result) { char *ptr; char *end; @@ -139,31 +139,31 @@ static int parse_list (char *list, int **result) if (!list || !result) return 0; - for (count = 0, ptr = list; ptr; ptr = strchr (ptr+1, ',')) + for (count = 0, ptr = list; ptr; ptr = strchr(ptr+1, ',')) count++; - mem = malloc ((count+1) * sizeof (int)); + mem = malloc((count+1) * sizeof(int)); if (!mem) { - Eprintf ("Couldn't allocate memory in parse_list().\n"); + Eprintf("Couldn't allocate memory in parse_list().\n"); return 0; } - memset (mem, 0xFF, (count+1) * sizeof (int)); + memset(mem, 0xFF, (count+1) * sizeof(int)); for (ptr = list, i = 0; i < count; i++) { end = NULL; - mem[i] = strtol (ptr, &end, 0); + mem[i] = strtol(ptr, &end, 0); if (!end || (end == ptr) || ((*end != ',') && (*end != 0))) { - Eprintf ("Invalid list '%s'\n", list); - free (mem); + Eprintf("Invalid list '%s'\n", list); + free(mem); return 0; } if ((mem[i] < 0) || (mem[i] > 255)) { - Eprintf ("Bytes must be in range 0-255.\n"); - free (mem); + Eprintf("Bytes must be in range 0-255.\n"); + free(mem); return 0; } @@ -188,7 +188,7 @@ static int parse_list (char *list, int **result) * 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 = "-ab:c:dfh?ilmnpqtuvV"; static struct option lopt[] = { @@ -222,7 +222,7 @@ static int parse_options (int argc, char *argv[]) opts.count = 1; - 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) { @@ -245,7 +245,7 @@ static int parse_options (int argc, char *argv[]) break; case 'b': if (!opts.bytes) { - if (!parse_list (optarg, &opts.bytes)) + if (!parse_list(optarg, &opts.bytes)) err++; } else { err++; @@ -254,7 +254,7 @@ static int parse_options (int argc, char *argv[]) case 'c': if (opts.count == 1) { end = NULL; - opts.count = strtol (optarg, &end, 0); + opts.count = strtol(optarg, &end, 0); if (end && *end) err++; } else { @@ -300,9 +300,9 @@ static int parse_options (int argc, char *argv[]) break; default: if ((optopt == 'b') || (optopt == 'c')) { - 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; @@ -314,35 +314,35 @@ 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.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.info && (opts.unused || opts.tails || opts.mft || opts.directory)) { - Eprintf ("You may not use any other options with --info.\n"); + Eprintf("You may not use any other options with --info.\n"); err++; } */ if ((opts.count < 1) || (opts.count > 100)) { - Eprintf ("The iteration count must be between 1 and 100.\n"); + Eprintf("The iteration count must be between 1 and 100.\n"); err++; } /* Create a default list */ if (!opts.bytes) { - opts.bytes = malloc (2 * sizeof (int)); + opts.bytes = malloc(2 * sizeof(int)); if (opts.bytes) { opts.bytes[0] = 0; opts.bytes[1] = -1; } else { - Eprintf ("Couldn't allocate memory for byte list.\n"); + Eprintf("Couldn't allocate memory for byte list.\n"); err++; } } @@ -373,7 +373,7 @@ static int parse_options (int argc, char *argv[]) * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_unused (ntfs_volume *vol, int byte, enum action act) +static s64 wipe_unused(ntfs_volume *vol, int byte, enum action act) { s64 i; s64 total = 0; @@ -384,25 +384,25 @@ static s64 wipe_unused (ntfs_volume *vol, int byte, enum action act) return -1; if (act != act_info) { - buffer = malloc (vol->cluster_size); + buffer = malloc(vol->cluster_size); if (!buffer) { - Eprintf ("malloc failed\n"); + Eprintf("malloc failed\n"); return -1; } - memset (buffer, byte, vol->cluster_size); + memset(buffer, byte, vol->cluster_size); } for (i = 0; i < vol->nr_clusters; i++) { - if (utils_cluster_in_use (vol, i)) { - //Vprintf ("cluster %lld is in use\n", i); + if (utils_cluster_in_use(vol, i)) { + //Vprintf("cluster %lld is in use\n", i); continue; } if (act == act_wipe) { - //Vprintf ("cluster %lld is not in use\n", i); - result = ntfs_pwrite (vol->dev, vol->cluster_size * i, vol->cluster_size, buffer); + //Vprintf("cluster %lld is not in use\n", i); + result = ntfs_pwrite(vol->dev, vol->cluster_size * i, vol->cluster_size, buffer); if (result != vol->cluster_size) { - Eprintf ("write failed\n"); + Eprintf("write failed\n"); goto free; } } @@ -410,9 +410,9 @@ static s64 wipe_unused (ntfs_volume *vol, int byte, enum action act) total += vol->cluster_size; } - Qprintf ("wipe_unused 0x%02x, %lld bytes\n", byte, (long long)total); + Qprintf("wipe_unused 0x%02x, %lld bytes\n", byte, (long long)total); free: - free (buffer); + free(buffer); return total; } @@ -427,7 +427,7 @@ free: * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_compressed_attribute (ntfs_volume *vol, int byte, +static s64 wipe_compressed_attribute(ntfs_volume *vol, int byte, enum action act, ntfs_attr *na) { unsigned char *buf; @@ -458,12 +458,12 @@ static s64 wipe_compressed_attribute (ntfs_volume *vol, int byte, rlt = rlc; while ((rlt - 1)->lcn == LCN_HOLE) rlt--; while (1) { - ret = ntfs_rl_pread (vol, na->rl, + ret = ntfs_rl_pread(vol, na->rl, offset, 2, &block_size); - block_size = le16_to_cpu (block_size); + block_size = le16_to_cpu(block_size); if (ret != 2) { - Vprintf ("Internal error\n"); - Eprintf ("ntfs_rl_pread failed"); + Vprintf("Internal error\n"); + Eprintf("ntfs_rl_pread failed"); return -1; } if (block_size == 0) { @@ -484,8 +484,8 @@ static s64 wipe_compressed_attribute (ntfs_volume *vol, int byte, } if (size < 0) { - Vprintf ("Internal error\n"); - Eprintf ("bug or damaged fs: we want " + Vprintf("Internal error\n"); + Eprintf("bug or damaged fs: we want " "allocate buffer size %lld bytes", size); return -1; } @@ -496,20 +496,20 @@ static s64 wipe_compressed_attribute (ntfs_volume *vol, int byte, continue; } - buf = malloc (size); + buf = malloc(size); if (!buf) { - Vprintf ("Not enough memory\n"); - Eprintf ("Not enough memory to allocate " + Vprintf("Not enough memory\n"); + Eprintf("Not enough memory to allocate " "%lld bytes", size); return -1; } - memset (buf, byte, size); + memset(buf, byte, size); - ret = ntfs_rl_pwrite (vol, na->rl, offset, size, buf); - free (buf); + ret = ntfs_rl_pwrite(vol, na->rl, offset, size, buf); + free(buf); if (ret != size) { - Vprintf ("Internal error\n"); - Eprintf ("ntfs_rl_pwrite failed, offset %llu, " + Vprintf("Internal error\n"); + Eprintf("ntfs_rl_pwrite failed, offset %llu, " "size %lld, vcn %lld", offset, size, rlc->vcn); return -1; } @@ -532,7 +532,7 @@ next: * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_attribute (ntfs_volume *vol, int byte, enum action act, +static s64 wipe_attribute(ntfs_volume *vol, int byte, enum action act, ntfs_attr *na) { unsigned char *buf; @@ -549,21 +549,21 @@ static s64 wipe_attribute (ntfs_volume *vol, int byte, enum action act, if (act == act_info) return size; - buf = malloc (size); + buf = malloc(size); if (!buf) { - Vprintf ("Not enough memory\n"); - Eprintf ("Not enough memory to allocate %lld bytes", size); + Vprintf("Not enough memory\n"); + Eprintf("Not enough memory to allocate %lld bytes", size); return -1; } - memset (buf, byte, size); + memset(buf, byte, size); - wiped = ntfs_rl_pwrite (vol, na->rl, offset, size, buf); + wiped = ntfs_rl_pwrite(vol, na->rl, offset, size, buf); if (wiped == -1) { - Vprintf ("Internal error\n"); - Eprintf ("Couldn't wipe tail"); + Vprintf("Internal error\n"); + Eprintf("Couldn't wipe tail"); } - free (buf); + free(buf); return wiped; } @@ -580,7 +580,7 @@ static s64 wipe_attribute (ntfs_volume *vol, int byte, enum action act, * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_tails (ntfs_volume *vol, int byte, enum action act) +static s64 wipe_tails(ntfs_volume *vol, int byte, enum action act) { s64 total = 0; s64 nr_mft_records, inode_num; @@ -596,56 +596,56 @@ static s64 wipe_tails (ntfs_volume *vol, int byte, enum action act) for (inode_num = 16; inode_num < nr_mft_records; inode_num++) { s64 wiped; - Vprintf ("Inode %lld - ", inode_num); - ni = ntfs_inode_open (vol, inode_num); + Vprintf("Inode %lld - ", inode_num); + ni = ntfs_inode_open(vol, inode_num); if (!ni) { - Vprintf ("Could not open inode\n"); + Vprintf("Could not open inode\n"); continue; } if (ni->mrec->base_mft_record) { - Vprintf ("Not base mft record. Skipping\n"); + Vprintf("Not base mft record. Skipping\n"); goto close_inode; } - na = ntfs_attr_open (ni, AT_DATA, AT_UNNAMED, 0); + na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { - Vprintf ("Couldn't open $DATA attribute\n"); + Vprintf("Couldn't open $DATA attribute\n"); goto close_inode; } if (!NAttrNonResident(na)) { - Vprintf ("Resident $DATA attribute. Skipping.\n"); + Vprintf("Resident $DATA attribute. Skipping.\n"); goto close_attr; } if (ntfs_attr_map_whole_runlist(na)) { - Vprintf ("Internal error\n"); - Eprintf ("Can't map runlist (inode %lld)\n", inode_num); + Vprintf("Internal error\n"); + Eprintf("Can't map runlist (inode %lld)\n", inode_num); goto close_attr; } if (NAttrCompressed(na)) - wiped = wipe_compressed_attribute (vol, byte, act, na); + wiped = wipe_compressed_attribute(vol, byte, act, na); else - wiped = wipe_attribute (vol, byte, act, na); + wiped = wipe_attribute(vol, byte, act, na); if (wiped == -1) { - Eprintf (" (inode %lld)\n", inode_num); + Eprintf(" (inode %lld)\n", inode_num); goto close_attr; } if (wiped) { - Vprintf ("Wiped %llu bytes\n", wiped); + Vprintf("Wiped %llu bytes\n", wiped); total += wiped; } else - Vprintf ("Nothing to wipe\n"); + Vprintf("Nothing to wipe\n"); close_attr: - ntfs_attr_close (na); + ntfs_attr_close(na); close_inode: - ntfs_inode_close (ni); + ntfs_inode_close(ni); } - Qprintf ("wipe_tails 0x%02x, %lld bytes\n", byte, total); + Qprintf("wipe_tails 0x%02x, %lld bytes\n", byte, total); return total; } @@ -662,7 +662,7 @@ close_inode: * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) +static s64 wipe_mft(ntfs_volume *vol, int byte, enum action act) { // by considering the individual attributes we might be able to // wipe a few more bytes at the attr's tail. @@ -675,9 +675,9 @@ static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) if (!vol || (byte < 0)) return -1; - buffer = malloc (vol->mft_record_size); + buffer = malloc(vol->mft_record_size); if (!buffer) { - Eprintf ("malloc failed\n"); + Eprintf("malloc failed\n"); return -1; } @@ -685,11 +685,11 @@ static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) vol->mft_record_size_bits; for (i = 0; i < nr_mft_records; i++) { - if (utils_mftrec_in_use (vol, i)) { - result = ntfs_attr_mst_pread (vol->mft_na, vol->mft_record_size * i, + if (utils_mftrec_in_use(vol, i)) { + result = ntfs_attr_mst_pread(vol->mft_na, vol->mft_record_size * i, 1, vol->mft_record_size, buffer); if (result != 1) { - Eprintf ("error attr mst read %lld\n", + Eprintf("error attr mst read %lld\n", (long long)i); total = -1; // XXX just negate result? goto free; @@ -699,17 +699,17 @@ static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) size = *((u32*) (buffer + 0x18)) - 4; if (act == act_info) { - //printf ("mft %d\n", size); + //printf("mft %d\n", size); total += size; continue; } - memset (buffer + size, byte, vol->mft_record_size - size); + memset(buffer + size, byte, vol->mft_record_size - size); - result = ntfs_attr_mst_pwrite (vol->mft_na, vol->mft_record_size * i, + result = ntfs_attr_mst_pwrite(vol->mft_na, vol->mft_record_size * i, 1, vol->mft_record_size, buffer); if (result != 1) { - Eprintf ("error attr mst write %lld\n", + Eprintf("error attr mst write %lld\n", (long long)i); total = -1; goto free; @@ -720,14 +720,14 @@ static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) // We have to reduce the update sequence number, or else... u16 offset; u16 usa; - offset = le16_to_cpu (*(buffer + 0x04)); - usa = le16_to_cpu (*(buffer + offset)); - *((u16*) (buffer + offset)) = cpu_to_le16 (usa - 1); + offset = le16_to_cpu(*(buffer + 0x04)); + usa = le16_to_cpu(*(buffer + offset)); + *((u16*) (buffer + offset)) = cpu_to_le16(usa - 1); - result = ntfs_attr_mst_pwrite (vol->mftmirr_na, vol->mft_record_size * i, + result = ntfs_attr_mst_pwrite(vol->mftmirr_na, vol->mft_record_size * i, 1, vol->mft_record_size, buffer); if (result != 1) { - Eprintf ("error attr mst write %lld\n", + Eprintf("error attr mst write %lld\n", (long long)i); total = -1; goto free; @@ -742,33 +742,33 @@ static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) } // Build the record from scratch - memset (buffer, 0, vol->mft_record_size); + memset(buffer, 0, vol->mft_record_size); // Common values *((u32*) (buffer + 0x00)) = magic_FILE; // Magic - *((u16*) (buffer + 0x06)) = cpu_to_le16 (0x0003); // USA size - *((u16*) (buffer + 0x10)) = cpu_to_le16 (0x0001); // Seq num - *((u32*) (buffer + 0x1C)) = cpu_to_le32 (vol->mft_record_size); // FILE size - *((u16*) (buffer + 0x28)) = cpu_to_le16 (0x0001); // Attr ID + *((u16*) (buffer + 0x06)) = cpu_to_le16(0x0003); // USA size + *((u16*) (buffer + 0x10)) = cpu_to_le16(0x0001); // Seq num + *((u32*) (buffer + 0x1C)) = cpu_to_le32(vol->mft_record_size); // FILE size + *((u16*) (buffer + 0x28)) = cpu_to_le16(0x0001); // Attr ID if (vol->major_ver == 3) { // Only XP and 2K3 - *((u16*) (buffer + 0x04)) = cpu_to_le16 (0x0030); // USA offset - *((u16*) (buffer + 0x14)) = cpu_to_le16 (0x0038); // Attr offset - *((u32*) (buffer + 0x18)) = cpu_to_le32 (0x00000040); // FILE usage - *((u32*) (buffer + 0x38)) = cpu_to_le32 (0xFFFFFFFF); // End marker + *((u16*) (buffer + 0x04)) = cpu_to_le16(0x0030); // USA offset + *((u16*) (buffer + 0x14)) = cpu_to_le16(0x0038); // Attr offset + *((u32*) (buffer + 0x18)) = cpu_to_le32(0x00000040); // FILE usage + *((u32*) (buffer + 0x38)) = cpu_to_le32(0xFFFFFFFF); // End marker } else { // Only NT and 2K - *((u16*) (buffer + 0x04)) = cpu_to_le16 (0x002A); // USA offset - *((u16*) (buffer + 0x14)) = cpu_to_le16 (0x0030); // Attr offset - *((u32*) (buffer + 0x18)) = cpu_to_le32 (0x00000038); // FILE usage - *((u32*) (buffer + 0x30)) = cpu_to_le32 (0xFFFFFFFF); // End marker + *((u16*) (buffer + 0x04)) = cpu_to_le16(0x002A); // USA offset + *((u16*) (buffer + 0x14)) = cpu_to_le16(0x0030); // Attr offset + *((u32*) (buffer + 0x18)) = cpu_to_le32(0x00000038); // FILE usage + *((u32*) (buffer + 0x30)) = cpu_to_le32(0xFFFFFFFF); // End marker } - result = ntfs_attr_mst_pwrite (vol->mft_na, vol->mft_record_size * i, + result = ntfs_attr_mst_pwrite(vol->mft_na, vol->mft_record_size * i, 1, vol->mft_record_size, buffer); if (result != 1) { - Eprintf ("error attr mst write %lld\n", + Eprintf("error attr mst write %lld\n", (long long)i); total = -1; goto free; @@ -778,9 +778,9 @@ static s64 wipe_mft (ntfs_volume *vol, int byte, enum action act) } } - Qprintf ("wipe_mft 0x%02x, %lld bytes\n", byte, (long long)total); + Qprintf("wipe_mft 0x%02x, %lld bytes\n", byte, (long long)total); free: - free (buffer); + free(buffer); return total; } @@ -797,7 +797,7 @@ free: * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_index_allocation (ntfs_volume *vol, int byte, enum action act +static s64 wipe_index_allocation(ntfs_volume *vol, int byte, enum action act __attribute__((unused)), ntfs_attr *naa, ntfs_attr *nab, u32 indx_record_size) { @@ -812,25 +812,25 @@ static s64 wipe_index_allocation (ntfs_volume *vol, int byte, enum action act u8 *bitmap; u8 *buf; - bitmap = malloc (nab->data_size); + bitmap = malloc(nab->data_size); if (!bitmap) { - Vprintf ("malloc failed\n"); - Eprintf ("Couldn't allocate %lld bytes", nab->data_size); + Vprintf("malloc failed\n"); + Eprintf("Couldn't allocate %lld bytes", nab->data_size); return -1; } - if (ntfs_attr_pread (nab, 0, nab->data_size, bitmap) + if (ntfs_attr_pread(nab, 0, nab->data_size, bitmap) != nab->data_size) { - Vprintf ("Internal error\n"); - Eprintf ("Couldn't read $BITMAP"); + Vprintf("Internal error\n"); + Eprintf("Couldn't read $BITMAP"); total = -1; goto free_bitmap; } - buf = malloc (indx_record_size); + buf = malloc(indx_record_size); if (!buf) { - Vprintf ("malloc failed\n"); - Eprintf ("Couldn't allocate %u bytes", + Vprintf("malloc failed\n"); + Eprintf("Couldn't allocate %u bytes", (unsigned int)indx_record_size); total = -1; goto free_bitmap; @@ -841,24 +841,24 @@ static s64 wipe_index_allocation (ntfs_volume *vol, int byte, enum action act if (bitmap[obyte] & mask) { INDEX_ALLOCATION *indx; - s64 ret = ntfs_rl_pread (vol, naa->rl, + s64 ret = ntfs_rl_pread(vol, naa->rl, offset, indx_record_size, buf); if (ret != indx_record_size) { - Vprintf ("ntfs_rl_pread failed\n"); - Eprintf ("Couldn't read INDX record"); + Vprintf("ntfs_rl_pread failed\n"); + Eprintf("Couldn't read INDX record"); total = -1; goto free_buf; } indx = (INDEX_ALLOCATION *) buf; - if (ntfs_mst_post_read_fixup ((NTFS_RECORD *)buf, + if (ntfs_mst_post_read_fixup((NTFS_RECORD *)buf, indx_record_size)) - Eprintf ("damaged fs: mst_post_read_fixup failed"); + Eprintf("damaged fs: mst_post_read_fixup failed"); if ((le32_to_cpu(indx->index.allocated_size) + 0x18) != indx_record_size) { - Vprintf ("Internal error\n"); - Eprintf ("INDX record should be %u bytes", + Vprintf("Internal error\n"); + Eprintf("INDX record should be %u bytes", (unsigned int)indx_record_size); total = -1; goto free_buf; @@ -866,23 +866,23 @@ static s64 wipe_index_allocation (ntfs_volume *vol, int byte, enum action act wipe_offset = le32_to_cpu(indx->index.index_length) + 0x18; wipe_size = indx_record_size - wipe_offset; - memset (buf + wipe_offset, byte, wipe_size); - if (ntfs_mst_pre_write_fixup ((NTFS_RECORD *)indx, + memset(buf + wipe_offset, byte, wipe_size); + if (ntfs_mst_pre_write_fixup((NTFS_RECORD *)indx, indx_record_size)) - Eprintf ("damaged fs: mst_pre_write_protect failed"); + Eprintf("damaged fs: mst_pre_write_protect failed"); if (opts.verbose > 1) - Vprintf ("+"); + Vprintf("+"); } else { wipe_size = indx_record_size; - memset (buf, byte, wipe_size); + memset(buf, byte, wipe_size); if (opts.verbose > 1) - Vprintf ("x"); + Vprintf("x"); } - wiped = ntfs_rl_pwrite (vol, naa->rl, offset, indx_record_size, buf); + wiped = ntfs_rl_pwrite(vol, naa->rl, offset, indx_record_size, buf); if (wiped != indx_record_size) { - Vprintf ("ntfs_rl_pwrite failed\n"); - Eprintf ("Couldn't wipe tail of INDX record"); + Vprintf("ntfs_rl_pwrite failed\n"); + Eprintf("Couldn't wipe tail of INDX record"); total = -1; goto free_buf; } @@ -896,11 +896,11 @@ static s64 wipe_index_allocation (ntfs_volume *vol, int byte, enum action act } } if ((opts.verbose > 1) && (wiped != -1)) - Vprintf ("\n\t"); + Vprintf("\n\t"); free_buf: - free (buf); + free(buf); free_bitmap: - free (bitmap); + free(bitmap); return total; } @@ -911,20 +911,20 @@ free_bitmap: * Return: >0 Success, return INDX record size * 0 Error, something went wrong */ -static u32 get_indx_record_size (ntfs_attr *nar) +static u32 get_indx_record_size(ntfs_attr *nar) { u32 indx_record_size; - if (ntfs_attr_pread (nar, 8, 4, &indx_record_size) != 4) { - Vprintf ("Couldn't determine size of INDX record\n"); - Eprintf ("ntfs_attr_pread failed"); + if (ntfs_attr_pread(nar, 8, 4, &indx_record_size) != 4) { + Vprintf("Couldn't determine size of INDX record\n"); + Eprintf("ntfs_attr_pread failed"); return 0; } - indx_record_size = le32_to_cpu (indx_record_size); + indx_record_size = le32_to_cpu(indx_record_size); if (!indx_record_size) { - Vprintf ("Internal error\n"); - Eprintf ("INDX record should be 0"); + Vprintf("Internal error\n"); + Eprintf("INDX record should be 0"); } return indx_record_size; } @@ -942,7 +942,7 @@ static u32 get_indx_record_size (ntfs_attr *nar) * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_directory (ntfs_volume *vol, int byte, enum action act) +static s64 wipe_directory(ntfs_volume *vol, int byte, enum action act) { s64 total = 0; s64 nr_mft_records, inode_num; @@ -961,101 +961,101 @@ static s64 wipe_directory (ntfs_volume *vol, int byte, enum action act) u32 indx_record_size; s64 wiped; - Vprintf ("Inode %lld - ", inode_num); - ni = ntfs_inode_open (vol, inode_num); + Vprintf("Inode %lld - ", inode_num); + ni = ntfs_inode_open(vol, inode_num); if (!ni) { if (opts.verbose > 2) - Vprintf ("Could not open inode\n"); + Vprintf("Could not open inode\n"); else - Vprintf ("\r"); + Vprintf("\r"); continue; } if (ni->mrec->base_mft_record) { if (opts.verbose > 2) - Vprintf ("Not base mft record. Skipping\n"); + Vprintf("Not base mft record. Skipping\n"); else - Vprintf ("\r"); + Vprintf("\r"); goto close_inode; } - naa = ntfs_attr_open (ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); + naa = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); if (!naa) { if (opts.verbose > 2) - Vprintf ("Couldn't open $INDEX_ALLOCATION\n"); + Vprintf("Couldn't open $INDEX_ALLOCATION\n"); else - Vprintf ("\r"); + Vprintf("\r"); goto close_inode; } if (!NAttrNonResident(naa)) { - Vprintf ("Resident $INDEX_ALLOCATION\n"); - Eprintf ("damaged fs: Resident $INDEX_ALLOCATION " + Vprintf("Resident $INDEX_ALLOCATION\n"); + Eprintf("damaged fs: Resident $INDEX_ALLOCATION " "(inode %lld)\n", inode_num); goto close_attr_allocation; } if (ntfs_attr_map_whole_runlist(naa)) { - Vprintf ("Internal error\n"); - Eprintf ("Can't map runlist for $INDEX_ALLOCATION " + Vprintf("Internal error\n"); + Eprintf("Can't map runlist for $INDEX_ALLOCATION " "(inode %lld)\n", inode_num); goto close_attr_allocation; } - nab = ntfs_attr_open (ni, AT_BITMAP, NTFS_INDEX_I30, 4); + nab = ntfs_attr_open(ni, AT_BITMAP, NTFS_INDEX_I30, 4); if (!nab) { - Vprintf ("Couldn't open $BITMAP\n"); - Eprintf ("damaged fs: $INDEX_ALLOCATION is present, " + Vprintf("Couldn't open $BITMAP\n"); + Eprintf("damaged fs: $INDEX_ALLOCATION is present, " "but we can't open $BITMAP with same " "name (inode %lld)\n", inode_num); goto close_attr_allocation; } - nar = ntfs_attr_open (ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4); + nar = ntfs_attr_open(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4); if (!nar) { - Vprintf ("Couldn't open $INDEX_ROOT\n"); - Eprintf ("damaged fs: $INDEX_ALLOCATION is present, but " + Vprintf("Couldn't open $INDEX_ROOT\n"); + Eprintf("damaged fs: $INDEX_ALLOCATION is present, but " "we can't open $INDEX_ROOT with same name" " (inode %lld)\n", inode_num); goto close_attr_bitmap; } if (NAttrNonResident(nar)) { - Vprintf ("Not resident $INDEX_ROOT\n"); - Eprintf ("damaged fs: Not resident $INDEX_ROOT " + Vprintf("Not resident $INDEX_ROOT\n"); + Eprintf("damaged fs: Not resident $INDEX_ROOT " "(inode %lld)\n", inode_num); goto close_attr_root; } - indx_record_size = get_indx_record_size (nar); + indx_record_size = get_indx_record_size(nar); if (!indx_record_size) { - Eprintf (" (inode %lld)\n", inode_num); + Eprintf(" (inode %lld)\n", inode_num); goto close_attr_root; } - wiped = wipe_index_allocation (vol, byte, act, + wiped = wipe_index_allocation(vol, byte, act, naa, nab, indx_record_size); if (wiped == -1) { - Eprintf (" (inode %lld)\n", inode_num); + Eprintf(" (inode %lld)\n", inode_num); goto close_attr_root; } if (wiped) { - Vprintf ("Wiped %llu bytes\n", wiped); + Vprintf("Wiped %llu bytes\n", wiped); total += wiped; } else - Vprintf ("Nothing to wipe\n"); + Vprintf("Nothing to wipe\n"); close_attr_root: - ntfs_attr_close (nar); + ntfs_attr_close(nar); close_attr_bitmap: - ntfs_attr_close (nab); + ntfs_attr_close(nab); close_attr_allocation: - ntfs_attr_close (naa); + ntfs_attr_close(naa); close_inode: - ntfs_inode_close (ni); + ntfs_inode_close(ni); } - Qprintf ("wipe_directory 0x%02x, %lld bytes\n", byte, total); + Qprintf("wipe_directory 0x%02x, %lld bytes\n", byte, total); return total; } @@ -1072,7 +1072,7 @@ close_inode: * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_logfile (ntfs_volume *vol, int byte, enum action act +static s64 wipe_logfile(ntfs_volume *vol, int byte, enum action act __attribute__((unused))) { const int NTFS_BUF_SIZE2 = 8192; @@ -1091,7 +1091,7 @@ static s64 wipe_logfile (ntfs_volume *vol, int byte, enum action act if (!vol || (byte < 0)) return -1; - //Qprintf ("wipe_logfile (not implemented) 0x%02x\n", byte); + //Qprintf("wipe_logfile(not implemented) 0x%02x\n", byte); if ((ni = ntfs_inode_open(vol, FILE_LogFile)) == NULL) { ntfs_log_debug("Failed to open inode FILE_LogFile.\n"); @@ -1155,7 +1155,7 @@ static s64 wipe_logfile (ntfs_volume *vol, int byte, enum action act ntfs_attr_close(na); ntfs_inode_close(ni); - Qprintf ("wipe_logfile 0x%02x, %lld bytes\n", byte, pos); + Qprintf("wipe_logfile 0x%02x, %lld bytes\n", byte, pos); return pos; io_error_exit: @@ -1182,7 +1182,7 @@ error_exit: * 0 Nothing to wipe * -1 Error, something went wrong */ -static s64 wipe_pagefile (ntfs_volume *vol, int byte, enum action act +static s64 wipe_pagefile(ntfs_volume *vol, int byte, enum action act __attribute__((unused))) { // wipe completely, chkdsk doesn't do anything, booting writes header @@ -1196,7 +1196,7 @@ static s64 wipe_pagefile (ntfs_volume *vol, int byte, enum action act if (!vol || (byte < 0)) return -1; - //Qprintf ("wipe_pagefile (not implemented) 0x%02x\n", byte); + //Qprintf("wipe_pagefile(not implemented) 0x%02x\n", byte); ni = ntfs_pathname_to_inode(vol, NULL, "pagefile.sys"); if (!ni) { @@ -1245,7 +1245,7 @@ static s64 wipe_pagefile (ntfs_volume *vol, int byte, enum action act ntfs_attr_close(na); ntfs_inode_close(ni); - Qprintf ("wipe_pagefile 0x%02x, %lld bytes\n", byte, pos); + Qprintf("wipe_pagefile 0x%02x, %lld bytes\n", byte, pos); return pos; io_error_exit: @@ -1267,38 +1267,38 @@ error_exit: * * Return: none */ -static void print_summary (void) +static void print_summary(void) { int i; if (opts.noaction) - Qprintf ("%s is in 'no-action' mode, it will NOT write to disk." + Qprintf("%s is in 'no-action' mode, it will NOT write to disk." "\n\n", EXEC_NAME); - Qprintf ("%s is about to wipe:\n", EXEC_NAME); + Qprintf("%s is about to wipe:\n", EXEC_NAME); if (opts.unused) - Qprintf ("\tunused disk space\n"); + Qprintf("\tunused disk space\n"); if (opts.tails) - Qprintf ("\tfile tails\n"); + Qprintf("\tfile tails\n"); if (opts.mft) - Qprintf ("\tunused mft areas\n"); + Qprintf("\tunused mft areas\n"); if (opts.directory) - Qprintf ("\tunused directory index space\n"); + Qprintf("\tunused directory index space\n"); if (opts.logfile) - Qprintf ("\tthe logfile (journal)\n"); + Qprintf("\tthe logfile (journal)\n"); if (opts.pagefile) - Qprintf ("\tthe pagefile (swap space)\n"); + Qprintf("\tthe pagefile (swap space)\n"); - Qprintf ("\n%s will overwrite these areas with: ", EXEC_NAME); + Qprintf("\n%s will overwrite these areas with: ", EXEC_NAME); if (opts.bytes) { for (i = 0; opts.bytes[i] >= 0; i++) - Qprintf ("0x%02x ", opts.bytes[i]); + Qprintf("0x%02x ", opts.bytes[i]); } - Qprintf ("\n"); + Qprintf("\n"); if (opts.count > 1) - Qprintf ("%s will repeat these operations %d times.\n", EXEC_NAME, opts.count); - Qprintf ("\n"); + Qprintf("%s will repeat these operations %d times.\n", EXEC_NAME, opts.count); + Qprintf("\n"); } /** @@ -1309,7 +1309,7 @@ static void print_summary (void) * 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; int result = 1; @@ -1317,7 +1317,7 @@ int main (int argc, char *argv[]) int i, j; enum action act = act_info; - if (!parse_options (argc, argv)) + if (!parse_options(argc, argv)) return 1; utils_set_locale(); @@ -1328,7 +1328,7 @@ int main (int argc, char *argv[]) if (opts.info || 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) goto free; @@ -1346,11 +1346,11 @@ int main (int argc, char *argv[]) /* Even if the output it quieted, you still get 5 seconds to abort. */ if ((act == act_wipe) && !opts.force) { - Qprintf ("\n%s will begin in 5 seconds, press CTRL-C to abort.\n", EXEC_NAME); - sleep (5); + Qprintf("\n%s will begin in 5 seconds, press CTRL-C to abort.\n", EXEC_NAME); + sleep(5); } - printf ("\n"); + printf("\n"); for (i = 0; i < opts.count; i++) { int byte; s64 total = 0; @@ -1359,7 +1359,7 @@ int main (int argc, char *argv[]) for (j = 0; byte = opts.bytes[j], byte >= 0; j++) { if (opts.directory) { - wiped = wipe_directory (vol, byte, act); + wiped = wipe_directory(vol, byte, act); if (wiped < 0) goto umount; else @@ -1367,7 +1367,7 @@ int main (int argc, char *argv[]) } if (opts.tails) { - wiped = wipe_tails (vol, byte, act); + wiped = wipe_tails(vol, byte, act); if (wiped < 0) goto umount; else @@ -1375,7 +1375,7 @@ int main (int argc, char *argv[]) } if (opts.logfile) { - wiped = wipe_logfile (vol, byte, act); + wiped = wipe_logfile(vol, byte, act); if (wiped < 0) goto umount; else @@ -1383,7 +1383,7 @@ int main (int argc, char *argv[]) } if (opts.mft) { - wiped = wipe_mft (vol, byte, act); + wiped = wipe_mft(vol, byte, act); if (wiped < 0) goto umount; else @@ -1391,7 +1391,7 @@ int main (int argc, char *argv[]) } if (opts.pagefile) { - wiped = wipe_pagefile (vol, byte, act); + wiped = wipe_pagefile(vol, byte, act); if (wiped < 0) goto umount; else @@ -1399,7 +1399,7 @@ int main (int argc, char *argv[]) } if (opts.unused) { - wiped = wipe_unused (vol, byte, act); + wiped = wipe_unused(vol, byte, act); if (wiped < 0) goto umount; else @@ -1410,13 +1410,13 @@ int main (int argc, char *argv[]) break; } - printf ("%lld bytes were wiped\n", (long long)total); + printf("%lld bytes were wiped\n", (long long)total); } result = 0; umount: - ntfs_umount (vol, FALSE); + ntfs_umount(vol, FALSE); free: if (opts.bytes) - free (opts.bytes); + free(opts.bytes); return result; }