upgrade to use new logging

change stderror messages to ntfs_log_perror
edge.strict_endians
flatcap 2005-10-29 00:08:43 +00:00
parent 9d92722737
commit 4e6dd9b97b
4 changed files with 144 additions and 101 deletions

View File

@ -35,6 +35,7 @@
#include "cluster.h"
#include "utils.h"
#include "logging.h"
/**
* cluster_find
@ -63,9 +64,9 @@ 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");
ntfs_log_verbose("cluster isn't in use\n");
else
Vprintf("clusters aren't in use\n");
ntfs_log_verbose("clusters aren't in use\n");
return 0;
}
@ -73,13 +74,13 @@ int cluster_find(ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void
m_ctx->flags_search = FEMR_IN_USE | FEMR_BASE_RECORD;
while (mft_next_record(m_ctx) == 0) {
Qprintf("Inode: %llu\n", (unsigned long long)
ntfs_log_quiet("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)
ntfs_log_verbose("Inode: %llu\n", (unsigned long long)
m_ctx->inode->mft_no);
a_ctx = ntfs_attr_get_search_ctx(m_ctx->inode, NULL);
@ -87,19 +88,19 @@ int cluster_find(ntfs_volume *vol, LCN c_begin, LCN c_end, cluster_cb *cb, void
while ((rec = find_attribute(AT_UNUSED, a_ctx))) {
if (!rec->non_resident) {
Vprintf("0x%02x skipped - attr is resident\n", a_ctx->attr->type);
ntfs_log_verbose("0x%02x skipped - attr is resident\n", a_ctx->attr->type);
continue;
}
runs = ntfs_mapping_pairs_decompress(vol, a_ctx->attr, NULL);
if (!runs) {
Eprintf("Couldn't read the data runs.\n");
ntfs_log_error("Couldn't read the data runs.\n");
goto done;
}
Vprintf("\t[0x%02X]\n", a_ctx->attr->type);
ntfs_log_verbose("\t[0x%02X]\n", a_ctx->attr->type);
Vprintf("\t\tVCN\tLCN\tLength\n");
ntfs_log_verbose("\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;
@ -107,7 +108,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",
ntfs_log_verbose("\t\t%lld\t%lld-%lld (%lld)\n",
(long long)runs[j].vcn,
(long long)runs[j].lcn,
(long long)(runs[j].lcn +

View File

@ -49,14 +49,11 @@
#include "dir.h"
#include "cluster.h"
#include "version.h"
#include "logging.h"
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)
/**
* version - Print version information about the program
*
@ -66,11 +63,11 @@ GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
*/
static void version(void)
{
printf("\n%s v%s (libntfs %s) - Find the owner of any given sector or "
ntfs_log_info("\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);
ntfs_log_info("Copyright (c) 2002-2003 Richard Russon\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -82,7 +79,7 @@ static void version(void)
*/
static void usage(void)
{
printf("\nUsage: %s [options] device\n"
ntfs_log_info("\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 +94,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);
ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
/**
@ -131,6 +128,7 @@ static int parse_options(int argc, char **argv)
int err = 0;
int ver = 0;
int help = 0;
int levels = 0;
char *end = NULL;
opterr = 0; /* We'll handle the errors, thank you. */
@ -170,6 +168,11 @@ static int parse_options(int argc, char **argv)
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'I':
@ -196,6 +199,7 @@ static int parse_options(int argc, char **argv)
break;
case 'q':
opts.quiet++;
ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET);
break;
case 's':
if ((opts.action == act_none) &&
@ -206,20 +210,28 @@ static int parse_options(int argc, char **argv)
break;
case 'v':
opts.verbose++;
ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);
break;
case 'V':
ver++;
break;
default:
if ((optopt == 'c') || (optopt == 's'))
Eprintf("Option '%s' requires an argument.\n", argv[optind-1]);
ntfs_log_error("Option '%s' requires an argument.\n", argv[optind-1]);
else
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
}
/* Make sure we're in sync with the log levels */
levels = ntfs_log_get_levels();
if (levels & NTFS_LOG_LEVEL_VERBOSE)
opts.verbose++;
if (!(levels & NTFS_LOG_LEVEL_QUIET))
opts.quiet++;
if (help || ver) {
opts.quiet = 0;
} else {
@ -230,20 +242,20 @@ static int parse_options(int argc, char **argv)
if (opts.device == NULL) {
if (argc > 1)
Eprintf("You must specify exactly one device.\n");
ntfs_log_error("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");
ntfs_log_error("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");
ntfs_log_error("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");
ntfs_log_error("The range must be in ascending order.\n");
err++;
}
}
@ -340,27 +352,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);
ntfs_log_info("bytes per sector : %llu\n", (unsigned long long)a);
ntfs_log_info("bytes per cluster : %llu\n", (unsigned long long)b);
ntfs_log_info("sectors per cluster : %llu\n", (unsigned long long)c);
ntfs_log_info("bytes per volume : %llu\n", (unsigned long long)d);
ntfs_log_info("sectors per volume : %llu\n", (unsigned long long)e);
ntfs_log_info("clusters per volume : %llu\n", (unsigned long long)f);
ntfs_log_info("initialized mft records : %llu\n", (unsigned long long)g);
ntfs_log_info("mft records in use : %llu\n", (unsigned long long)h);
ntfs_log_info("mft records percentage : %llu\n", (unsigned long long)i);
ntfs_log_info("bytes of free space : %llu\n", (unsigned long long)j);
ntfs_log_info("sectors of free space : %llu\n", (unsigned long long)k);
ntfs_log_info("clusters of free space : %llu\n", (unsigned long long)l);
ntfs_log_info("percentage free space : %llu\n", (unsigned long long)m);
ntfs_log_info("bytes of user data : %llu\n", (unsigned long long)n);
ntfs_log_info("sectors of user data : %llu\n", (unsigned long long)o);
ntfs_log_info("clusters of user data : %llu\n", (unsigned long long)p);
ntfs_log_info("percentage user data : %llu\n", (unsigned long long)q);
ntfs_log_info("bytes of metadata : %llu\n", (unsigned long long)r);
ntfs_log_info("sectors of metadata : %llu\n", (unsigned long long)s);
ntfs_log_info("clusters of metadata : %llu\n", (unsigned long long)t);
ntfs_log_info("percentage metadata : %llu\n", (unsigned long long)u);
return 0;
}
@ -378,19 +390,19 @@ static int dump_file(ntfs_volume *vol, ntfs_inode *ino)
utils_inode_get_name(ino, buffer, sizeof(buffer));
printf("Dump: %s\n", buffer);
ntfs_log_info("Dump: %s\n", buffer);
ctx = ntfs_attr_get_search_ctx(ino, NULL);
while ((rec = find_attribute(AT_UNUSED, ctx))) {
printf(" 0x%02x - ", rec->type);
ntfs_log_info(" 0x%02x - ", rec->type);
if (rec->non_resident) {
printf("non-resident\n");
ntfs_log_info("non-resident\n");
runs = ntfs_mapping_pairs_decompress(vol, rec, NULL);
if (runs) {
printf(" VCN LCN Length\n");
ntfs_log_info(" VCN LCN Length\n");
for (i = 0; runs[i].length > 0; i++) {
printf(" %8lld %8lld %8lld\n",
ntfs_log_info(" %8lld %8lld %8lld\n",
(long long)runs[i].vcn,
(long long)runs[i].lcn,
(long long)
@ -399,7 +411,7 @@ static int dump_file(ntfs_volume *vol, ntfs_inode *ino)
free(runs);
}
} else {
printf("resident\n");
ntfs_log_info("resident\n");
}
}
@ -420,15 +432,15 @@ static int print_match(ntfs_inode *ino, ATTR_RECORD *attr,
buffer = malloc(MAX_PATH);
if (!buffer) {
Eprintf("!buffer\n");
ntfs_log_error("!buffer\n");
return 1;
}
utils_inode_get_name(ino, buffer, MAX_PATH);
printf("Inode %llu %s", (unsigned long long)ino->mft_no, buffer);
ntfs_log_info("Inode %llu %s", (unsigned long long)ino->mft_no, buffer);
utils_attr_get_name(ino->vol, attr, buffer, MAX_PATH);
printf("/%s\n", buffer);
ntfs_log_info("/%s\n", buffer);
free(buffer);
return 0;
@ -470,6 +482,8 @@ int main(int argc, char *argv[])
struct match m;
int result = 1;
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv))
return 1;
@ -482,10 +496,10 @@ int main(int argc, char *argv[])
switch (opts.action) {
case act_sector:
if (opts.range_begin == opts.range_end)
Qprintf("Searching for sector %llu\n",
ntfs_log_quiet("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);
ntfs_log_quiet("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);
@ -493,10 +507,10 @@ int main(int argc, char *argv[])
break;
case act_cluster:
if (opts.range_begin == opts.range_end)
Qprintf("Searching for cluster %llu\n",
ntfs_log_quiet("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);
ntfs_log_quiet("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:
@ -510,7 +524,7 @@ int main(int argc, char *argv[])
result = dump_file(vol, ino);
ntfs_inode_close(ino);
} else {
Eprintf("Cannot open inode %llu\n",
ntfs_log_error("Cannot open inode %llu\n",
(unsigned long long)opts.inode);
}
break;
@ -524,7 +538,7 @@ int main(int argc, char *argv[])
result = dump_file(vol, ino);
ntfs_inode_close(ino);
} else {
Eprintf("Cannot open inode %llu\n",
ntfs_log_error("Cannot open inode %llu\n",
(unsigned long long)
opts.inode);
}

View File

@ -48,6 +48,7 @@
#include "mft.h"
#include "utils.h"
#include "version.h"
#include "logging.h"
static const char *EXEC_NAME = "ntfslabel";
@ -60,10 +61,6 @@ 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)
/**
* version - Print version information about the program
*
@ -73,14 +70,14 @@ GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
*/
static void version(void)
{
printf("\n%s v%s (libntfs %s) - Display, or set, the label for an "
ntfs_log_info("\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);
ntfs_log_info("Copyright (c)\n");
ntfs_log_info(" 2002 Matthew J. Fanto\n");
ntfs_log_info(" 2002-2005 Anton Altaparmakov\n");
ntfs_log_info(" 2002-2003 Richard Russon\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
/**
@ -92,7 +89,7 @@ static void version(void)
*/
static void usage(void)
{
printf("\nUsage: %s [options] device [label]\n"
ntfs_log_info("\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 +97,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);
ntfs_log_info("%s%s\n", ntfs_bugs, ntfs_home);
}
/**
@ -129,6 +126,7 @@ static int parse_options(int argc, char *argv[])
int err = 0;
int ver = 0;
int help = 0;
int levels = 0;
opterr = 0; /* We'll handle the errors, thank you. */
@ -147,6 +145,11 @@ static int parse_options(int argc, char *argv[])
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'n':
@ -154,31 +157,40 @@ static int parse_options(int argc, char *argv[])
break;
case 'q':
opts.quiet++;
ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET);
break;
case 'v':
opts.verbose++;
ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);
break;
case 'V':
ver++;
break;
default:
Eprintf("Unknown option '%s'.\n", argv[optind-1]);
ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
}
}
/* Make sure we're in sync with the log levels */
levels = ntfs_log_get_levels();
if (levels & NTFS_LOG_LEVEL_VERBOSE)
opts.verbose++;
if (!(levels & NTFS_LOG_LEVEL_QUIET))
opts.quiet++;
if (help || ver) {
opts.quiet = 0;
} else {
if (opts.device == NULL) {
if (argc > 1)
Eprintf("You must specify a device.\n");
ntfs_log_error("You must specify a device.\n");
err++;
}
if (opts.quiet && opts.verbose) {
Eprintf("You may not use --quiet and --verbose at "
ntfs_log_error("You may not use --quiet and --verbose at "
"the same time.\n");
err++;
}
@ -199,7 +211,7 @@ static int parse_options(int argc, char *argv[])
* @mnt_flags: mount flags of the device or 0 if not mounted
* @mnt_point: mount point of the device or NULL
*
* Print the label of the device @dev to stdout.
* Print the label of the device @dev.
*/
static int print_label(ntfs_volume *vol, unsigned long mnt_flags)
{
@ -207,12 +219,12 @@ static int print_label(ntfs_volume *vol, unsigned long mnt_flags)
//XXX significant?
if ((mnt_flags & (NTFS_MF_MOUNTED | NTFS_MF_READONLY)) ==
NTFS_MF_MOUNTED) {
Eprintf("%s is mounted read-write, results may be "
ntfs_log_error("%s is mounted read-write, results may be "
"unreliable.\n", opts.device);
result = 1;
}
printf("%s\n", vol->vol_name);
ntfs_log_info("%s\n", vol->vol_name);
return result;
}
@ -274,7 +286,7 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
if (!(mnt_flags & NTFS_MF_ISROOT) ||
!(mnt_flags & NTFS_MF_READONLY)) {
if (!force) {
fprintf(stderr, "Refusing to change label on "
ntfs_log_error("Refusing to change label on "
"read-%s mounted device %s.\n",
mnt_flags & NTFS_MF_READONLY ?
"only" : "write", opts.device);
@ -284,13 +296,13 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
}
ctx = ntfs_attr_get_search_ctx(vol->vol_ni, NULL);
if (!ctx) {
perror("Failed to get attribute search context");
ntfs_log_perror("Failed to get attribute search context");
goto err_out;
}
if (ntfs_attr_lookup(AT_VOLUME_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0,
ctx)) {
if (errno != ENOENT) {
perror("Lookup of $VOLUME_NAME attribute failed");
ntfs_log_perror("Lookup of $VOLUME_NAME attribute failed");
goto err_out;
}
/* The volume name attribute does not exist. Need to add it. */
@ -298,19 +310,19 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
} else {
a = ctx->attr;
if (a->non_resident) {
fprintf(stderr, "Error: Attribute $VOLUME_NAME must be "
ntfs_log_error("Error: Attribute $VOLUME_NAME must be "
"resident.\n");
goto err_out;
}
}
label_len = ntfs_mbstoucs(label, &new_label, 0);
if (label_len == -1) {
perror("Unable to convert label string to Unicode");
ntfs_log_perror("Unable to convert label string to Unicode");
goto err_out;
}
label_len *= sizeof(ntfschar);
if (label_len > 0x100) {
fprintf(stderr, "New label is too long. Maximum %u characters "
ntfs_log_error("New label is too long. Maximum %u characters "
"allowed. Truncating excess characters.\n",
(unsigned)(0x100 / sizeof(ntfschar)));
label_len = 0x100;
@ -318,7 +330,7 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
}
if (a) {
if (resize_resident_attribute_value(ctx->mrec, a, label_len)) {
perror("Error resizing resident attribute");
ntfs_log_perror("Error resizing resident attribute");
goto err_out;
}
} else {
@ -327,7 +339,7 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
u32 biu = le32_to_cpu(ctx->mrec->bytes_in_use);
if (biu + asize > le32_to_cpu(ctx->mrec->bytes_allocated)) {
errno = ENOSPC;
perror("Error adding resident attribute");
ntfs_log_perror("Error adding resident attribute");
goto err_out;
}
a = ctx->attr;
@ -349,7 +361,7 @@ static int change_label(ntfs_volume *vol, unsigned long mnt_flags, char *label,
}
memcpy((u8*)a + le16_to_cpu(a->value_offset), new_label, label_len);
if (!opts.noaction && ntfs_inode_sync(vol->vol_ni)) {
perror("Error writing MFT Record to disk");
ntfs_log_perror("Error writing MFT Record to disk");
goto err_out;
}
result = 0;
@ -372,6 +384,8 @@ int main(int argc, char **argv)
int result = 0;
ntfs_volume *vol;
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv))
return 1;

View File

@ -52,6 +52,7 @@
#include "list.h"
#include "ntfstime.h"
#include "version.h"
#include "logging.h"
static const char *EXEC_NAME = "ntfsls";
@ -123,9 +124,10 @@ typedef struct {
ntfs_volume *vol;
} ntfsls_dirent;
GEN_PRINTF(Eprintf, stderr, NULL, FALSE)
GEN_PRINTF(Vprintf, stdout, &opts.verbose, TRUE)
GEN_PRINTF(Qprintf, stdout, &opts.quiet, FALSE)
static int list_dir_entry(ntfsls_dirent * dirent, const ntfschar * name,
const int name_len, const int name_type,
const s64 pos, const MFT_REF mref,
const unsigned dt_type);
/**
* version - Print version information about the program
@ -212,6 +214,7 @@ static int parse_options(int argc, char *argv[])
int err = 0;
int ver = 0;
int help = 0;
int levels = 0;
opterr = 0; /* We'll handle the errors, thank you. */
@ -235,13 +238,20 @@ static int parse_options(int argc, char *argv[])
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'q':
opts.quiet++;
ntfs_log_clear_levels(NTFS_LOG_LEVEL_QUIET);
break;
case 'v':
opts.verbose++;
ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);
break;
case 'V':
ver++;
@ -268,12 +278,19 @@ static int parse_options(int argc, char *argv[])
opts.recursive++;
break;
default:
Eprintf("Unknown option '%s'.\n", argv[optind - 1]);
ntfs_log_error("Unknown option '%s'.\n", argv[optind - 1]);
err++;
break;
}
}
/* Make sure we're in sync with the log levels */
levels = ntfs_log_get_levels();
if (levels & NTFS_LOG_LEVEL_VERBOSE)
opts.verbose++;
if (!(levels & NTFS_LOG_LEVEL_QUIET))
opts.quiet++;
/* defaults to -a if -s is not specified */
if (!opts.system)
opts.all++;
@ -283,13 +300,13 @@ static int parse_options(int argc, char *argv[])
else {
if (opts.device == NULL) {
if (argc > 1)
Eprintf("You must specify exactly one "
ntfs_log_error("You must specify exactly one "
"device.\n");
err++;
}
if (opts.quiet && opts.verbose) {
Eprintf("You may not use --quiet and --verbose at the "
ntfs_log_error("You may not use --quiet and --verbose at the "
"same time.\n");
err++;
}
@ -303,11 +320,6 @@ static int parse_options(int argc, char *argv[])
return (!err && !help && !ver);
}
static int list_dir_entry(ntfsls_dirent * dirent, const ntfschar * name,
const int name_len, const int name_type,
const s64 pos, const MFT_REF mref,
const unsigned dt_type);
/**
* free_dir - free one dir
* @tofree: the dir to free
@ -422,7 +434,7 @@ static int readdir_recursive(ntfs_inode * ni, s64 * pos, ntfsls_dirent * dirent)
subdir->name);
if (!subdir->ni) {
Eprintf
ntfs_log_error
("ntfsls::readdir_recursive(): cannot get inode from pathname.\n");
result = -1;
break;
@ -491,7 +503,7 @@ static int list_dir_entry(ntfsls_dirent * dirent, const ntfschar * name,
return -1;
if (ntfs_ucstombs(name, name_len, &filename, MAX_PATH) < 0) {
Eprintf("Cannot represent filename in current locale.\n");
ntfs_log_error("Cannot represent filename in current locale.\n");
goto free;
}
@ -516,7 +528,7 @@ static int list_dir_entry(ntfsls_dirent * dirent, const ntfschar * name,
dir = (struct dir *)calloc(1, sizeof(struct dir));
if (!dir) {
Eprintf("Failed to allocate for subdir.\n");
ntfs_log_error("Failed to allocate for subdir.\n");
result = -1;
goto free;
}
@ -630,6 +642,8 @@ int main(int argc, char **argv)
ntfs_inode *ni;
ntfsls_dirent dirent;
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv)) {
// FIXME: Print error... (AIA)
return 1;