2003-01-19 19:48:06 +08:00
|
|
|
|
/**
|
2002-11-29 20:16:35 +08:00
|
|
|
|
* ntfsinfo - Part of the Linux-NTFS project.
|
|
|
|
|
*
|
2004-01-09 20:38:56 +08:00
|
|
|
|
* Copyright (c) 2002-2004 Matthew J. Fanto
|
|
|
|
|
* Copyright (c) 2002-2004 Anton Altaparmakov
|
2003-01-19 19:48:06 +08:00
|
|
|
|
* Copyright (c) 2002-2003 Richard Russon
|
2002-11-29 20:16:35 +08:00
|
|
|
|
*
|
|
|
|
|
* This utility will dump a file's attributes.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2004-01-09 20:38:56 +08:00
|
|
|
|
/* TODO LIST:
|
|
|
|
|
* 1. Better error checking. In fact, my error checking sucks.
|
|
|
|
|
* 2. Fix output issues.
|
|
|
|
|
* 3. Check on the 72/48 issue
|
|
|
|
|
* 4. Comment things better
|
|
|
|
|
*
|
|
|
|
|
* Still not dumping certain attributes. Need to find the best
|
|
|
|
|
* way to output some of these attributes.
|
|
|
|
|
*
|
|
|
|
|
* Still need to do:
|
|
|
|
|
* $OBJECT_ID - dump correctly
|
|
|
|
|
* $SECURITY_DESCRIPTOR
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-11-29 20:16:35 +08:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2004-01-09 20:38:56 +08:00
|
|
|
|
#include <string.h>
|
2002-12-23 12:42:18 +08:00
|
|
|
|
#include <time.h>
|
2003-01-19 19:48:06 +08:00
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-12-02 09:57:17 +08:00
|
|
|
|
#include "types.h"
|
2002-11-29 20:16:35 +08:00
|
|
|
|
#include "mft.h"
|
|
|
|
|
#include "attrib.h"
|
|
|
|
|
#include "layout.h"
|
|
|
|
|
#include "inode.h"
|
2003-01-19 19:48:06 +08:00
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
|
|
static const char *EXEC_NAME = "ntfsinfo";
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
static struct options {
|
|
|
|
|
char *device; /* Device/File to work with */
|
|
|
|
|
s64 inode; /* Info for this inode */
|
|
|
|
|
int quiet; /* Less output */
|
|
|
|
|
int verbose; /* Extra output */
|
|
|
|
|
int force; /* Override common sense */
|
2003-07-23 05:08:22 +08:00
|
|
|
|
int epochtime; /* Report all timestamps as "Thu Jan 1 00:00:00 1970" */
|
|
|
|
|
int notime; /* Don't report timestamps at all */
|
2004-01-09 20:38:56 +08:00
|
|
|
|
int mft; /* Dump information about the volume as well */
|
2003-01-19 19:48:06 +08:00
|
|
|
|
} opts;
|
|
|
|
|
|
|
|
|
|
GEN_PRINTF (Eprintf, stderr, NULL, FALSE)
|
|
|
|
|
GEN_PRINTF (Vprintf, stdout, &opts.verbose, TRUE)
|
|
|
|
|
GEN_PRINTF (Qprintf, stdout, &opts.quiet, FALSE)
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
/**
|
2003-01-19 19:48:06 +08:00
|
|
|
|
* version - Print version information about the program
|
2002-12-23 12:42:18 +08:00
|
|
|
|
*
|
2003-01-19 19:48:06 +08:00
|
|
|
|
* Print a copyright statement and a brief description of the program.
|
2002-12-23 12:42:18 +08:00
|
|
|
|
*
|
2003-01-19 19:48:06 +08:00
|
|
|
|
* Return: none
|
2002-12-23 12:42:18 +08:00
|
|
|
|
*/
|
2003-01-19 19:48:06 +08:00
|
|
|
|
void version (void)
|
2002-12-23 12:42:18 +08:00
|
|
|
|
{
|
2003-01-20 06:01:18 +08:00
|
|
|
|
printf ("\n%s v%s - Display information about an NTFS Volume.\n\n",
|
|
|
|
|
EXEC_NAME, VERSION);
|
|
|
|
|
printf ("Copyright (c)\n");
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf (" 2002-2004 Matthew J. Fanto\n");
|
2003-01-20 06:01:18 +08:00
|
|
|
|
printf (" 2002 Anton Altaparmakov\n");
|
|
|
|
|
printf (" 2002-2003 Richard Russon\n");
|
2003-07-23 17:45:39 +08:00
|
|
|
|
printf (" 2003 Leonard Norrg<72>rd\n");
|
2003-01-20 06:01:18 +08:00
|
|
|
|
printf ("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
|
2002-12-23 12:42:18 +08:00
|
|
|
|
}
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* usage - Print a list of the parameters to the program
|
|
|
|
|
*
|
|
|
|
|
* Print a list of the parameters and options for the program.
|
|
|
|
|
*
|
|
|
|
|
* Return: none
|
|
|
|
|
*/
|
|
|
|
|
void usage (void)
|
2002-11-29 20:16:35 +08:00
|
|
|
|
{
|
2003-10-06 19:38:25 +08:00
|
|
|
|
printf ("\nUsage: %s [options] -d dev\n"
|
|
|
|
|
" -d dev --device dev The ntfs volume to display information about\n"
|
2003-01-19 19:48:06 +08:00
|
|
|
|
" -i num --inode num Display information about this inode\n"
|
2004-01-09 20:38:56 +08:00
|
|
|
|
" -m --mft Dump information about the volume\n"
|
2003-10-11 23:36:14 +08:00
|
|
|
|
" -t --epochtime Report all timestamps as \"Thu Jan 1 00:00:00 1970\"\n"
|
|
|
|
|
" -T --notime Don't report timestamps at all\n"
|
2003-01-19 19:48:06 +08:00
|
|
|
|
"\n"
|
2003-01-20 07:45:17 +08:00
|
|
|
|
" -f --force Use less caution\n"
|
|
|
|
|
" -q --quiet Less output\n"
|
|
|
|
|
" -v --verbose More output\n"
|
|
|
|
|
" -V --version Display version information\n"
|
2003-10-11 23:36:14 +08:00
|
|
|
|
" -h --help Display this help\n\n",
|
2003-01-19 19:48:06 +08:00
|
|
|
|
EXEC_NAME);
|
2003-01-20 06:01:18 +08:00
|
|
|
|
printf ("%s%s\n", ntfs_bugs, ntfs_home);
|
2002-11-29 20:16:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
int parse_options (int argc, char *argv[])
|
2002-11-29 20:16:35 +08:00
|
|
|
|
{
|
2003-10-06 19:38:25 +08:00
|
|
|
|
static const char *sopt = "-fh?i:qtTvVd:";
|
2003-01-19 19:48:06 +08:00
|
|
|
|
static const struct option lopt[] = {
|
2003-10-06 19:38:25 +08:00
|
|
|
|
{ "device", required_argument, NULL, 'd' },
|
2003-01-19 19:48:06 +08:00
|
|
|
|
{ "force", no_argument, NULL, 'f' },
|
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
|
{ "inode", required_argument, NULL, 'i' },
|
|
|
|
|
{ "quiet", no_argument, NULL, 'q' },
|
|
|
|
|
{ "verbose", no_argument, NULL, 'v' },
|
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2003-07-23 05:08:22 +08:00
|
|
|
|
{ "epochtime", no_argument, NULL, 't' },
|
|
|
|
|
{ "notime", no_argument, NULL, 'T' },
|
2004-01-09 20:38:56 +08:00
|
|
|
|
{ "mft", no_argument, NULL, 'm' },
|
2003-01-19 19:48:06 +08:00
|
|
|
|
{ NULL, 0, NULL, 0 },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
char c = -1;
|
|
|
|
|
int err = 0;
|
|
|
|
|
int ver = 0;
|
|
|
|
|
int help = 0;
|
|
|
|
|
|
|
|
|
|
opterr = 0; /* We'll handle the errors, thank you. */
|
|
|
|
|
|
|
|
|
|
opts.inode = -1;
|
|
|
|
|
|
|
|
|
|
while ((c = getopt_long (argc, argv, sopt, lopt, NULL)) != -1) {
|
|
|
|
|
switch (c) {
|
2003-10-06 19:38:25 +08:00
|
|
|
|
case 'd': /* A non-option argument */
|
2003-01-19 19:48:06 +08:00
|
|
|
|
if (!opts.device) {
|
|
|
|
|
opts.device = argv[optind-1];
|
|
|
|
|
} else {
|
|
|
|
|
opts.device = NULL;
|
|
|
|
|
err++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'i':
|
|
|
|
|
if ((opts.inode != -1) ||
|
|
|
|
|
(!utils_parse_size (argv[optind-1], &opts.inode, FALSE))) {
|
|
|
|
|
err++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
opts.force++;
|
|
|
|
|
break;
|
|
|
|
|
case 'h':
|
2003-01-20 06:01:18 +08:00
|
|
|
|
case '?':
|
2003-01-19 19:48:06 +08:00
|
|
|
|
help++;
|
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
opts.quiet++;
|
|
|
|
|
break;
|
2003-07-23 05:08:22 +08:00
|
|
|
|
case 't':
|
|
|
|
|
opts.epochtime++;
|
|
|
|
|
break;
|
|
|
|
|
case 'T':
|
|
|
|
|
opts.notime++;
|
|
|
|
|
break;
|
2003-01-19 19:48:06 +08:00
|
|
|
|
case 'v':
|
|
|
|
|
opts.verbose++;
|
|
|
|
|
break;
|
|
|
|
|
case 'V':
|
|
|
|
|
ver++;
|
|
|
|
|
break;
|
2004-01-09 20:38:56 +08:00
|
|
|
|
case 'm':
|
|
|
|
|
opts.mft++;
|
|
|
|
|
break;
|
2003-01-19 19:48:06 +08:00
|
|
|
|
default:
|
|
|
|
|
if ((optopt == 'i') && (!optarg)) {
|
|
|
|
|
Eprintf ("Option '%s' requires an argument.\n", argv[optind-1]);
|
|
|
|
|
} else {
|
|
|
|
|
Eprintf ("Unknown option '%s'.\n", argv[optind-1]);
|
|
|
|
|
}
|
|
|
|
|
err++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-12-23 12:42:18 +08:00
|
|
|
|
}
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
if (help || ver) {
|
|
|
|
|
opts.quiet = 0;
|
|
|
|
|
} else {
|
|
|
|
|
if (opts.device == NULL) {
|
2003-01-20 06:01:18 +08:00
|
|
|
|
if (argc > 1)
|
|
|
|
|
Eprintf ("You must specify exactly one device.\n");
|
2003-01-19 19:48:06 +08:00
|
|
|
|
err++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opts.inode == -1) {
|
2003-01-20 06:01:18 +08:00
|
|
|
|
if (argc > 1)
|
|
|
|
|
Eprintf ("You much specify an inode to learn about.\n");
|
2003-01-19 19:48:06 +08:00
|
|
|
|
err++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opts.quiet && opts.verbose) {
|
|
|
|
|
Eprintf ("You may not use --quiet and --verbose at the same time.\n");
|
|
|
|
|
err++;
|
|
|
|
|
}
|
2003-07-23 05:08:22 +08:00
|
|
|
|
|
|
|
|
|
if (opts.epochtime && opts.notime) {
|
|
|
|
|
Eprintf ("You may not use --notime and --epochtime at the same time.\n");
|
|
|
|
|
err++;
|
|
|
|
|
}
|
2002-11-29 20:16:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
if (ver)
|
|
|
|
|
version();
|
|
|
|
|
if (help || err)
|
|
|
|
|
usage();
|
|
|
|
|
|
|
|
|
|
return (!err && !help && !ver);
|
2002-12-23 12:42:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
/**
|
|
|
|
|
* ntfs_dump_volume - dump information about the volume
|
|
|
|
|
*/
|
|
|
|
|
void ntfs_dump_volume(ntfs_volume *vol)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("Volume Information \n");
|
|
|
|
|
printf("\tName of device: %s\n", vol->dev->d_name);
|
|
|
|
|
printf("\tDevice state: %lu\n", vol->dev->d_state);
|
|
|
|
|
printf("\tVolume Name: %s\n", vol->vol_name);
|
|
|
|
|
printf("\tVolume State: %lu\n", vol->state);
|
|
|
|
|
printf("\tVolume Version: %u.%u\n", vol->major_ver, vol->minor_ver);
|
|
|
|
|
printf("\tSector Size: %hu\n", vol->sector_size);
|
|
|
|
|
printf("\tCluster Size: %u\n", vol->cluster_size);
|
|
|
|
|
printf("\tVolume Size in Clusters: %lld\n", vol->nr_clusters);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("MFT Information \n");
|
|
|
|
|
printf("\tMFT Record Size: %u\n", vol->mft_record_size);
|
|
|
|
|
printf("\tMFT Zone Multiplier: %u\n", vol->mft_zone_multiplier);
|
|
|
|
|
printf("\tMFT Data Position: %lld\n", vol->mft_data_pos);
|
|
|
|
|
printf("\tMFT Zone Start: %lld\n", vol->mft_zone_start);
|
|
|
|
|
printf("\tMFT Zone End: %lld\n", vol->mft_zone_end);
|
|
|
|
|
printf("\tMFT Zone Position: %lld\n", vol->mft_zone_pos);
|
|
|
|
|
printf("\tCurrent Position in First Data Zone: %lld\n", vol->data1_zone_pos);
|
|
|
|
|
printf("\tCurrent Position in Second Data Zone: %lld\n", vol->data2_zone_pos);
|
|
|
|
|
printf("\tNumber of Records in MFT: %lld\n", vol->nr_mft_records);
|
|
|
|
|
printf("\tLCN of Data Attribute for FILE_MFT: %lld\n", vol->mft_lcn);
|
|
|
|
|
printf("\tFILE_MFTMirr Size: %d\n", vol->mftmirr_size);
|
|
|
|
|
printf("\tLCN of Data Attribute for File_MFTMirr: %lld\n", vol->mftmirr_lcn);
|
|
|
|
|
printf("\tSize of Attribute Definition Table: %d\n", vol->attrdef_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("FILE_Bitmap Information \n");
|
|
|
|
|
printf("\tFILE_Bitmap MFT Record Number: %lld\n", vol->lcnbmp_ni->mft_no);
|
|
|
|
|
printf("\tState of FILE_Bitmap Inode: %lu\n", vol->lcnbmp_ni->state);
|
|
|
|
|
printf("\tLength of Attribute List: %u\n", vol->lcnbmp_ni->attr_list_size);
|
|
|
|
|
printf("\tAttribute List: %s\n", vol->lcnbmp_ni->attr_list);
|
|
|
|
|
printf("\tNumber of Attached Extent Inodes: %d\n", vol->lcnbmp_ni->nr_extents);
|
|
|
|
|
//FIXME: need to add code for the union if nr_extens != 0, but
|
|
|
|
|
//i dont know if it will ever != 0 with FILE_Bitmap
|
|
|
|
|
|
|
|
|
|
printf("FILE_Bitmap Data Attribute Information\n");
|
|
|
|
|
printf("\tDecompressed Runlist: not done yet\n");
|
|
|
|
|
printf("\tBase Inode: %lld\n", vol->lcnbmp_na->ni->mft_no);
|
|
|
|
|
printf("\tAttribute Types: not done yet\n");
|
|
|
|
|
//printf("\tAttribute Name: %s\n", vol->lcnbmp_na->name);
|
|
|
|
|
printf("\tAttribute Name Length: %u\n", vol->lcnbmp_na->name_len);
|
|
|
|
|
printf("\tAttribute State: %lu\n", vol->lcnbmp_na->state);
|
|
|
|
|
printf("\tAttribute Allocated Size: %lld\n", vol->lcnbmp_na->allocated_size);
|
|
|
|
|
printf("\tAttribute Data Size: %lld\n", vol->lcnbmp_na->data_size);
|
|
|
|
|
printf("\tAttribute Initialized Size: %lld\n", vol->lcnbmp_na->initialized_size);
|
|
|
|
|
printf("\tAttribute Compressed Size: %lld\n", vol->lcnbmp_na->compressed_size);
|
|
|
|
|
printf("\tCompression Block Size: %u\n", vol->lcnbmp_na->compression_block_size);
|
|
|
|
|
printf("\tCompression Block Size Bits: %u\n", vol->lcnbmp_na->compression_block_size_bits);
|
|
|
|
|
printf("\tCompression Block Clusters: %u\n", vol->lcnbmp_na->compression_block_clusters);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Still need to add a few more attributes
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ntfs_dump_standard_information
|
|
|
|
|
*/
|
|
|
|
|
void ntfs_dump_standard_information_attr(ntfs_inode *inode)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
STANDARD_INFORMATION *standard_attr = NULL;
|
|
|
|
|
ATTR_RECORD *attr = NULL;
|
|
|
|
|
ntfs_attr_search_ctx *ctx = NULL;
|
|
|
|
|
|
|
|
|
|
ctx = ntfs_attr_get_search_ctx(inode, NULL);
|
|
|
|
|
|
|
|
|
|
if(ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) {
|
|
|
|
|
fprintf(stderr, "ntfsinfo error: cannot look up attribute AT_STANDARD_INFORMATION!\n");
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx); //free ctx
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attr = ctx->attr;
|
|
|
|
|
|
|
|
|
|
standard_attr = (STANDARD_INFORMATION*)((char *)attr + le16_to_cpu(attr->value_offset));
|
|
|
|
|
|
|
|
|
|
printf("Dumping $STANDARD_INFORMATION (0x10)\n");
|
|
|
|
|
|
|
|
|
|
//check with flatcap/anton and make sure this is correct
|
|
|
|
|
if (sizeof(STANDARD_INFORMATION) == 48) {
|
|
|
|
|
printf("\t$STANDARD_INFORMATION fields maximum_versions, version_number, \
|
|
|
|
|
class_id, owner_id, security_id missing. This volume has \
|
|
|
|
|
not been upgraded\n");
|
|
|
|
|
}
|
|
|
|
|
if (sizeof(STANDARD_INFORMATION) == 72) {
|
|
|
|
|
printf("\tMaximum Number of Versions: \t %d \n", le32_to_cpu (standard_attr->maximum_versions));
|
|
|
|
|
printf("\tVersion Number: \t\t %d \n", le32_to_cpu (standard_attr->version_number));
|
|
|
|
|
printf("\tClass ID: \t\t\t %d \n", le32_to_cpu (standard_attr->class_id));
|
|
|
|
|
printf("\tUser ID: \t\t\t %d \n", le32_to_cpu (standard_attr->owner_id));
|
|
|
|
|
printf("\tSecurity ID: \t\t\t %d \n", le32_to_cpu (standard_attr->security_id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
printf("\tSize of STANDARD_INFORMATION is %d. It should be either 72 or 48, \
|
|
|
|
|
something is wrong...\n",sizeof(STANDARD_INFORMATION));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx); //free ctx
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* ntfs_dump_file_name_attribute
|
|
|
|
|
*/
|
2004-01-09 20:38:56 +08:00
|
|
|
|
void ntfs_dump_file_name_attr(ntfs_inode *inode)
|
2002-12-23 12:42:18 +08:00
|
|
|
|
{
|
|
|
|
|
FILE_NAME_ATTR *file_name_attr = NULL;
|
|
|
|
|
ATTR_RECORD *attr = NULL;
|
|
|
|
|
ntfs_attr_search_ctx *ctx = NULL;
|
2003-02-10 06:55:20 +08:00
|
|
|
|
char *file_name = NULL;
|
2002-12-23 12:42:18 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
ctx = ntfs_attr_get_search_ctx(inode, NULL);
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
if(ntfs_attr_lookup(AT_FILE_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) {
|
|
|
|
|
fprintf(stderr, "ntfsinfo error: cannot lookup attribute AT_FILE_NAME!\n");
|
2004-01-09 20:38:56 +08:00
|
|
|
|
ntfs_attr_put_search_ctx(ctx); //free ctx
|
2002-12-23 12:42:18 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attr = ctx->attr;
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
file_name_attr = (FILE_NAME_ATTR*)((char *)attr + le16_to_cpu(attr->value_offset));
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
//need to convert the little endian unicode string to a multibyte string
|
|
|
|
|
ntfs_ucstombs(file_name_attr->file_name, file_name_attr->file_name_length,
|
|
|
|
|
&file_name, file_name_attr->file_name_length);
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
printf("Dumping $FILE_NAME (0x30)\n");
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
//basic stuff about the file
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("\tFile Name: \t\t %s\n",file_name);
|
|
|
|
|
printf("\tFile Name Length: \t %d\n",file_name_attr->file_name_length);
|
|
|
|
|
printf("\tAllocated File Size: \t %lld\n", sle64_to_cpu(file_name_attr->allocated_size));
|
|
|
|
|
printf("\tReal File Size: \t %lld\n", sle64_to_cpu(file_name_attr->data_size));
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
//time conversion stuff
|
2003-07-23 05:08:22 +08:00
|
|
|
|
if (!opts.notime) {
|
|
|
|
|
time_t ntfs_time = { 0 };
|
2004-01-09 20:38:56 +08:00
|
|
|
|
|
2003-07-23 05:08:22 +08:00
|
|
|
|
if (!opts.epochtime) {
|
|
|
|
|
ntfs_time = ntfs2utc (sle64_to_cpu (file_name_attr->creation_time));
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("\tFile Creation Time: \t %s",ctime(&ntfs_time));
|
2003-07-23 05:08:22 +08:00
|
|
|
|
|
|
|
|
|
ntfs_time = ntfs2utc (sle64_to_cpu (file_name_attr->last_data_change_time));
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("\tFile Altered Time: \t %s",ctime(&ntfs_time));
|
2003-07-23 05:08:22 +08:00
|
|
|
|
|
|
|
|
|
ntfs_time = ntfs2utc (sle64_to_cpu (file_name_attr->last_mft_change_time));
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("\tMFT Changed Time: \t %s",ctime(&ntfs_time));
|
2003-07-23 05:08:22 +08:00
|
|
|
|
|
|
|
|
|
ntfs_time = ntfs2utc (sle64_to_cpu (file_name_attr->last_access_time));
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("\tLast Accessed Time: \t %s",ctime(&ntfs_time));
|
2003-07-23 05:08:22 +08:00
|
|
|
|
} else {
|
|
|
|
|
char *t = asctime(gmtime(&ntfs_time));
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("\tFile Creation Time: \t %s",t);
|
|
|
|
|
printf("\tFile Altered Time: \t %s",t);
|
|
|
|
|
printf("\tMFT Changed Time: \t %s",t);
|
|
|
|
|
printf("\tLast Accessed Time: \t %s",t);
|
2003-07-23 05:08:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-09 20:38:56 +08:00
|
|
|
|
|
2002-12-23 12:42:18 +08:00
|
|
|
|
free(file_name);
|
2004-01-09 20:38:56 +08:00
|
|
|
|
ntfs_attr_put_search_ctx(ctx); //free ctx
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ntfs_dump_object_id
|
|
|
|
|
*
|
|
|
|
|
* dump the $OBJECT_ID attribute - not present on all systems
|
|
|
|
|
*
|
2003-01-19 19:48:06 +08:00
|
|
|
|
*/
|
2004-01-09 20:38:56 +08:00
|
|
|
|
void ntfs_dump_object_id_attr(ntfs_inode *inode)
|
2002-11-29 20:16:35 +08:00
|
|
|
|
{
|
2004-01-09 20:38:56 +08:00
|
|
|
|
|
|
|
|
|
OBJECT_ID_ATTR *obj_id_attr = NULL;
|
|
|
|
|
ATTR_RECORD *attr = NULL;
|
|
|
|
|
ntfs_attr_search_ctx *ctx = NULL;
|
2002-12-23 12:42:18 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
ctx = ntfs_attr_get_search_ctx(inode, NULL);
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
if(ntfs_attr_lookup(AT_OBJECT_ID, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) {
|
|
|
|
|
fprintf(stderr, "ntfsinfo error: cannot look up attribute AT_OBJECT_ID: %s\n",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-12-23 12:42:18 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
attr = ctx->attr;
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
obj_id_attr = (OBJECT_ID_ATTR*)((char *)attr + le16_to_cpu(attr->value_offset)); //the attribute plus the offset
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
printf("Dumping $OBJECT_ID (0x40)\n");
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
//I believe these attributes are only present on volume versions > 3.0. It was introduced
|
|
|
|
|
//in Win2k, which is 3.0
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
//FIXME: Need to do a check to make sure these attributes are actually present
|
|
|
|
|
//even if it is > 3.0.
|
|
|
|
|
if (inode->vol->major_ver >= 3.0) {
|
|
|
|
|
printf("\tVolume Version > 3.0... Dumping Attributes\n");
|
|
|
|
|
|
|
|
|
|
//printf("\tObject ID: \t\t\t %d\n", obj_id_attr->object_id);
|
|
|
|
|
//printf("\tBirth Volume ID: \t\t\t %d\n", obj_id_attr->birth_volume_id);
|
|
|
|
|
//printf("\tBirth Object ID: \t\t\t %d\n", obj_id_attr->birth_object_id);
|
|
|
|
|
}
|
2002-11-29 20:16:35 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
else
|
|
|
|
|
printf("\t$OBJECT_ID not present. Only NTFS versions > 3.0 have $OBJECT_ID. \
|
|
|
|
|
Your version of NTFS is %d\n", inode->vol->major_ver);
|
|
|
|
|
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx);
|
2002-11-29 20:16:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ntfs_dump_volume_name()
|
|
|
|
|
*
|
|
|
|
|
* dump the name of the volume the inode belongs to
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void ntfs_dump_volume_name_attr(ntfs_inode *inode)
|
|
|
|
|
{
|
|
|
|
|
VOLUME_NAME *vol_name = NULL;
|
|
|
|
|
ATTR_RECORD *attr = NULL;
|
|
|
|
|
ntfs_attr_search_ctx *ctx = NULL;
|
|
|
|
|
|
|
|
|
|
ctx = ntfs_attr_get_search_ctx(inode, NULL);
|
|
|
|
|
|
|
|
|
|
if(ntfs_attr_lookup(AT_VOLUME_NAME, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) {
|
|
|
|
|
fprintf(stderr, "ntfsinfo error: cannot look up attribute AT_VOLUME_NAME: %s\n",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attr = ctx->attr;
|
|
|
|
|
|
|
|
|
|
vol_name = (VOLUME_NAME*)((char *)attr + le16_to_cpu(attr->value_offset));
|
|
|
|
|
|
|
|
|
|
printf("Dumping $VOLUME_NAME (0x60)\n");
|
|
|
|
|
|
|
|
|
|
//printf("\tVolume Name: \t\t\t %s\n", vol_name->name);
|
|
|
|
|
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ntfs_dump_volume_information()
|
|
|
|
|
*
|
|
|
|
|
* dump the information for the volume the inode belongs to
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void ntfs_dump_volume_information_attr(ntfs_inode *inode)
|
|
|
|
|
{
|
|
|
|
|
VOLUME_INFORMATION *vol_information = NULL;
|
|
|
|
|
ATTR_RECORD *attr = NULL;
|
|
|
|
|
ntfs_attr_search_ctx *ctx = NULL;
|
|
|
|
|
|
|
|
|
|
ctx = ntfs_attr_get_search_ctx(inode, NULL);
|
|
|
|
|
|
|
|
|
|
if(ntfs_attr_lookup(AT_VOLUME_INFORMATION, AT_UNNAMED, 0, 0, 0, NULL, 0, ctx)) {
|
|
|
|
|
fprintf(stderr, "ntfsinfo error: cannot look up attribute AT_VOLUME_INFORMATION: %s\n",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attr = ctx->attr;
|
|
|
|
|
|
|
|
|
|
vol_information = (VOLUME_INFORMATION*)((char *)attr + le16_to_cpu(attr->value_offset));
|
|
|
|
|
|
|
|
|
|
printf("Dumping $VOLUME_INFORMATION (0x70)\n");
|
|
|
|
|
|
|
|
|
|
printf("\tVolume Major Version: \t\t\t %d\n", vol_information->major_ver);
|
|
|
|
|
printf("\tVolume Minor Version: \t\t\t %d\n", vol_information->minor_ver);
|
|
|
|
|
printf("\tFlags: \t\t\t Not Finished Yet! \n");
|
|
|
|
|
|
|
|
|
|
ntfs_attr_put_search_ctx(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
/**
|
|
|
|
|
* ntfs_get_file_attributes
|
|
|
|
|
*/
|
2004-01-09 20:38:56 +08:00
|
|
|
|
void ntfs_get_file_attributes(ntfs_volume *vol, s64 mft_no, int dump_volume)
|
2003-01-19 19:48:06 +08:00
|
|
|
|
{
|
|
|
|
|
ntfs_inode *inode = NULL;
|
|
|
|
|
//int error;
|
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
inode = ntfs_inode_open(vol, MK_MREF(mft_no, 0));
|
|
|
|
|
|
|
|
|
|
/* if opts.mft is not 0, then we will print out information about
|
|
|
|
|
* the volume, such as the sector size and whatnot.
|
|
|
|
|
*/
|
|
|
|
|
// if (dump_volume)
|
|
|
|
|
ntfs_dump_volume(vol);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//see flatcap.org/ntfs/info for what formatting should look likei
|
|
|
|
|
//FIXME: both $FILE_NAME_ATTR and $STANDARD_INFORMATION has times, when do
|
|
|
|
|
//we want to output it?
|
|
|
|
|
ntfs_dump_standard_information_attr(inode);
|
|
|
|
|
ntfs_dump_file_name_attr(inode);
|
|
|
|
|
ntfs_dump_object_id_attr(inode);
|
|
|
|
|
ntfs_dump_volume_name_attr(inode);
|
|
|
|
|
ntfs_dump_volume_information_attr(inode);
|
|
|
|
|
|
|
|
|
|
ntfs_inode_close(inode);
|
2003-01-19 19:48:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* main - Begin here
|
|
|
|
|
*
|
|
|
|
|
* Start from here.
|
|
|
|
|
*
|
|
|
|
|
* Return: 0 Success, the program worked
|
|
|
|
|
* 1 Error, something went wrong
|
|
|
|
|
*/
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
ntfs_volume *vol;
|
|
|
|
|
|
|
|
|
|
if (!parse_options (argc, argv))
|
|
|
|
|
return 1;
|
|
|
|
|
|
2003-01-20 06:01:18 +08:00
|
|
|
|
utils_set_locale();
|
|
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
|
vol = utils_mount_volume (opts.device, MS_RDONLY, opts.force);
|
|
|
|
|
if (!vol)
|
|
|
|
|
return 1;
|
2003-01-20 06:01:18 +08:00
|
|
|
|
|
2004-01-09 20:38:56 +08:00
|
|
|
|
ntfs_get_file_attributes (vol, opts.inode, opts.mft);
|
2003-01-19 19:48:06 +08:00
|
|
|
|
|
|
|
|
|
ntfs_umount (vol, FALSE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|