ntfscat.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/**
* ntfscat - Part of the Linux-NTFS project.
*
* Copyright (c) 2003-2005 Richard Russon
* Copyright (c) 2003-2005 Anton Altaparmakov
* Copyright (c) 2003-2005 Szabolcs Szakacsits
* Copyright (c) 2007 Yura Pakhuchiy
*
* This utility will concatenate files and print on the standard output.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "types.h"
#include "attrib.h"
#include "utils.h"
#include "volume.h"
#include "debug.h"
#include "dir.h"
#include "ntfscat.h"
#include "version.h"
static const char *EXEC_NAME = "ntfscat";
/**
* version - Print version information about the program
*
* Print a copyright statement and a brief description of the program.
*
* Return: none
*/
static void version(void)
{
ntfs_log_info("\n%s v%s (libntfs %s) - Concatenate files and print "
ntfs_log_info("Copyright (c) 2003-2005 Richard Russon\n");
ntfs_log_info("Copyright (c) 2003-2005 Anton Altaparmakov\n");
ntfs_log_info("Copyright (c) 2003-2005 Szabolcs Szakacsits\n");
ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n");
}
/**
* usage - Print a list of the parameters to the program
*
* Print a list of the parameters and options for the program.
*
* Return: none
*/
static void usage(void)
{
ntfs_log_info("\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",
// Does not work for compressed files at present so leave undocumented...
// " -r --raw Display the raw data (e.g. for compressed or encrypted file)",
}
/**
* parse_attribute - Read an attribute name, or number
* @value: String to be parsed
* @attr: Resulting attribute id (on success)
*
* Read a string representing an attribute. It may be a decimal, octal or
* hexadecimal number, or the attribute name in full. The leading $ sign is
* optional.
*
* Return: 1 Success, a valid attribute name or number
* 0 Error, not an attribute name or number
*/
{
static const char *attr_name[] = {
"$STANDARD_INFORMATION",
"$ATTRIBUTE_LIST",
"$FILE_NAME",
"$OBJECT_ID",
"$SECURITY_DESCRIPTOR",
"$VOLUME_NAME",
"$VOLUME_INFORMATION",
"$DATA",
"$INDEX_ROOT",
"$INDEX_ALLOCATION",
"$BITMAP",
"$REPARSE_POINT",
"$EA_INFORMATION",
"$EA",
"$PROPERTY_SET",
"$LOGGED_UTILITY_STREAM",
};
int i;
long num;
for (i = 0; attr_name[i]; i++) {
return 1;
}
}
return 1;
}
return 0;
}
/**
* parse_options - Read and validate the programs command line
*
* Read the command line, verify the syntax and parse the options.
* This function is very long, but quite simple.
*
* Return: 1 Success
* 0 Error, one or more problems
*/
{
static const char *sopt = "-a:fh?i:n:qVvr";
};
int c = -1;
int err = 0;
int ver = 0;
int help = 0;
int levels = 0;
opterr = 0; /* We'll handle the errors, thank you. */
opts.attr_name_len = 0;
switch (c) {
case 1: /* A non-option argument */
} else {
ntfs_log_error("You must specify exactly one "
"file.\n");
err++;
}
break;
case 'a':
ntfs_log_error("You must specify exactly one "
"attribute.\n");
break;
} else {
ntfs_log_error("Couldn't parse attribute.\n");
}
err++;
break;
case 'f':
break;
case 'h':
case '?':
err++;
break;
}
help++;
break;
case 'i':
ntfs_log_error("You must specify exactly one inode.\n");
break;
else
ntfs_log_error("Couldn't parse inode number.\n");
err++;
break;
case 'n':
if (opts.attr_name_len < 0) {
ntfs_log_perror("Invalid attribute name '%s'",
optarg);
usage();
}
case 'q':
break;
case 'V':
ver++;
break;
case 'v':
break;
case 'r':
break;
default:
err++;
break;
}
}
/* Make sure we're in sync with the log levels */
if (levels & NTFS_LOG_LEVEL_VERBOSE)
if (!(levels & NTFS_LOG_LEVEL_QUIET))
} else {
ntfs_log_error("You must specify a device.\n");
err++;
ntfs_log_error("You must specify a file or inode "
"with the -i option.\n");
err++;
ntfs_log_error("You can't specify both a file and inode.\n");
err++;
}
ntfs_log_error("You may not use --quiet and --verbose at the "
"same time.\n");
err++;
}
}
if (ver)
version();
usage();
}
/**
* index_get_size - Find the INDX block size from the index root
* @inode: Inode of the directory to be checked
*
* Find the size of a directory's INDX block from the INDEX_ROOT attribute.
*
* Return: n Success, the INDX blocks are n bytes in size
* 0 Error, not a directory
*/
{
if (!attr90)
return 0; // not a directory
}
/**
* cat
*/
{
const int bufsize = 4096;
char *buffer;
if (!buffer)
return 1;
if (!attr) {
ntfs_log_error("Cannot find attribute type 0x%x.\n",
le32_to_cpu(type));
return 1;
}
else
block_size = 0;
offset = 0;
for (;;) {
// These types have fixup
if (bytes_read > 0)
bytes_read *= block_size;
} else {
}
//ntfs_log_info("read %lld bytes\n", bytes_read);
if (bytes_read == -1) {
ntfs_log_perror("ERROR: Couldn't read file");
break;
}
if (!bytes_read)
break;
if (written != bytes_read) {
ntfs_log_perror("ERROR: Couldn't output all data!");
break;
}
offset += bytes_read;
}
return 0;
}
/**
* main - Begin here
*
* Start from here.
*
* Return: 0 Success, the program worked
* 1 Error, something went wrong
*/
{
int result = 1;
return 1;
if (!vol) {
ntfs_log_perror("ERROR: couldn't mount volume");
return 1;
}
else
if (!inode) {
ntfs_log_perror("ERROR: Couldn't open inode");
return 1;
}
return result;
}