1N/A * ntfsinfo - Part of the Linux-NTFS project. 1N/A * Copyright (c) 2002-2004 Matthew J. Fanto 1N/A * Copyright (c) 2002-2006 Anton Altaparmakov 1N/A * Copyright (c) 2002-2005 Richard Russon 1N/A * Copyright (c) 2003-2006 Szabolcs Szakacsits 1N/A * Copyright (c) 2004-2005 Yuval Fledel 1N/A * Copyright (c) 2004-2007 Yura Pakhuchiy 1N/A * Copyright (c) 2005 Cristian Klein 1N/A * This utility will dump a file's attributes. 1N/A * This program is free software; you can redistribute it and/or modify 1N/A * it under the terms of the GNU General Public License as published by 1N/A * the Free Software Foundation; either version 2 of the License, or 1N/A * (at your option) any later version. 1N/A * This program is distributed in the hope that it will be useful, 1N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A * GNU General Public License for more details. 1N/A * You should have received a copy of the GNU General Public License 1N/A * along with this program (in the main directory of the Linux-NTFS 1N/A * distribution in the file COPYING); if not, write to the Free Software 1N/A * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1N/A * - Better error checking. (focus on ntfs_dump_volume) 1N/A * - Comment things better. 1N/A * - More things at verbose mode. 1N/A * - Dump ACLs when security_id exists (NTFS 3+ only). 1N/A * - Internationalization. 1N/A * - Add more Indexed Attr Types. 1N/A * Still not dumping certain attributes. Need to find the best 1N/A * way to output some of these attributes. 1N/A * $REPARSE_POINT/$SYMBOLIC_LINK 1N/A * $LOGGED_UTILITY_STREAM 1N/A const char *
filename;
/* Resolve this filename to mft number */ 1N/A int notime;
/* Don't report timestamps at all */ 1N/A int mft;
/* Dump information about the volume as well */ 1N/A * version - Print version information about the program 1N/A * Print a copyright statement and a brief description of the program. 1N/A printf(
"\n%s v%s (libntfs %s) - Display information about an NTFS " 1N/A * usage - Print a list of the parameters to the program 1N/A * Print a list of the parameters and options for the program. 1N/A " -i, --inode NUM Display information about this inode\n" 1N/A " -F, --file FILE Display information about this file (absolute path)\n" 1N/A " -m, --mft Dump information about the volume\n" 1N/A " -t, --notime Don't report timestamps\n" 1N/A " -f, --force Use less caution\n" 1N/A " -q, --quiet Less output\n" 1N/A " -v, --verbose More output\n" 1N/A " -V, --version Display version information\n" 1N/A " -h, --help Display this help\n" 1N/A " -d, --debug Show debug information\n" 1N/A * parse_options - Read and validate the programs command line 1N/A * Read the command line, verify the syntax and parse the options. 1N/A * This function is very long, but quite simple. 1N/A * 0 Error, one or more problems 1N/A static const char *
sopt =
"-:dfhi:F:mqtTvV";
1N/A opterr = 0;
/* We'll handle the errors, thank you. */ 1N/A /* The inode can not be resolved here, 1N/A store the filename */ 1N/A /* "-F" can't appear more than once */ 1N/A /* 'T' is deprecated, notify */ 1N/A "replaced by 't'.\n");
1N/A /* Make sure we're in sync with the log levels */ 1N/A "at the same time.\n");
1N/A "and --file together.\n");
1N/A/* *************** utility functions ******************** */ 1N/A * ntfsinfo_time_to_str() - 1N/A * @sle_ntfs_clock: on disk time format in 100ns units since 1st jan 1601 1N/A * in little-endian format 1N/A * Return char* in a format 'Thu Jan 1 00:00:00 1970'. 1N/A * No need to free the returned memory. 1N/A * char *time_str = ntfsinfo_time_to_str( 1N/A * sle64_to_cpu(standard_attr->creation_time)); 1N/A * printf("\tFile Creation Time:\t %s", time_str); 1N/A * ntfs_attr_get_name() 1N/A * @attr: a valid attribute record 1N/A * return multi-byte string containing the attribute name if exist. the user 1N/A * is then responsible of freeing that memory. 1N/A * null if no name exists (attr->name_length==0). no memory allocated. 1N/A * null if cannot convert to multi-byte string. errno would contain the 1N/A * error id. no memory allocated in that case 1N/A /* Get name in unicode. */ 1N/A /* Convert unicode to printable format. */ 1N/A/* *************** functions for dumping global info ******************** */ 1N/A * ntfs_dump_volume - dump information about the volume 1N/A printf(
"\tCurrent Position in First Data Zone: %lld\n",
1N/A printf(
"\tCurrent Position in Second Data Zone: %lld\n",
1N/A printf(
"\tLCN of Data Attribute for FILE_MFT: %lld\n",
1N/A printf(
"\tLCN of Data Attribute for File_MFTMirr: %lld\n",
1N/A printf(
"\tSize of Attribute Definition Table: %d\n",
1N/A printf(
"\tFILE_Bitmap MFT Record Number: %llu\n",
1N/A printf(
"\tNumber of Attached Extent Inodes: %d\n",
1N/A /* FIXME: need to add code for the union if nr_extens != 0, but 1N/A i dont know if it will ever != 0 with FILE_Bitmap */ 1N/A printf(
"FILE_Bitmap Data Attribute Information\n");
1N/A printf(
"\tDecompressed Runlist: not done yet\n");
1N/A //printf("\tAttribute Name: %s\n", vol->lcnbmp_na->name); 1N/A printf(
"\tAttribute Initialized Size: %lld\n",
1N/A printf(
"\tAttribute Compressed Size: %lld\n",
1N/A printf(
"\tCompression Block Size Bits: %u\n",
1N/A //TODO: Still need to add a few more attributes 1N/A * ntfs_dump_flags - Dump flags for STANDARD_INFORMATION and FILE_NAME. 1N/A * @type: dump flags for this attribute type 1N/A * @flags: flags for dumping 1N/A /* We know that FILE_ATTR_I30_INDEX_PRESENT only exists on $FILE_NAME, 1N/A and in case we are wrong, let it appear as UNKNOWN */ 1N/A /* Print all the flags in hex. */ 1N/A * ntfs_dump_namespace 1N/A/* *************** functions for dumping attributes ******************** */ 1N/A * ntfs_dump_standard_information 1N/A /* time conversion stuff */ 1N/A /* Only 12 reserved bytes here */ 1N/A printf(
"\tMaximum versions:\t %u \n", (
unsigned int)
1N/A printf(
"\tVersion number:\t\t %u \n", (
unsigned int)
1N/A printf(
"\tQuota charged:\t\t %llu (0x%llx)\n",
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A printf(
"\tUpdate Sequence Number:\t %llu (0x%llx)\n",
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A printf(
"\tSize of STANDARD_INFORMATION is %u (0x%x). It " 1N/A "should be either 72 or 48, something is " 1N/A * ntfs_dump_attr_list() 1N/A (
unsigned long long)
1N/A printf(
"\t\tMFT reference:\t%lld (0x%llx)\n",
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A printf(
"\tEnd of attribute list reached.\n");
1N/A * ntfs_dump_filename() 1N/A /* other basic stuff about the file */ 1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A /* but first we need to convert the little endian unicode string 1N/A into a printable format */ 1N/A /* an error occurred, errno holds the reason - notify the user */ 1N/A * ntfs_dump_attr_file_name() 1N/A * ntfs_dump_object_id 1N/A * dump the $OBJECT_ID attribute - not present on all systems 1N/A /* Object ID is mandatory. */ 1N/A /* Dump Birth Volume ID. */ 1N/A /* Dumping Birth Object ID */ 1N/A /* Dumping Domain_id - reserved for now */ 1N/A printf(
"\t$OBJECT_ID not present. Only NTFS versions > 3.0\n" 1N/A "\thave $OBJECT_ID. Your version of NTFS is %d.\n",
1N/A * given an acl, print it in a beautiful & lovely way. 1N/A * Do not recalculate le16_to_cpu every iteration (minor speedup on 1N/A * big-endian machines. 1N/A /* initialize 'ace' to the first ace (if any) */ 1N/A /* iterate through ACE's */ 1N/A /* get a SID string */ 1N/A /* proceed to next ACE */ 1N/A /* TODO: parse the flags */ 1N/A * ntfs_dump_security_descriptor() 1N/A * dump the security information about the file 1N/A /* FIXME: We don't handle fragmented mapping pairs case. */ 1N/A "read security descriptor\n");
1N/A "decompress runlist\n");
1N/A * ntfs_dump_volume_name() 1N/A * dump the name of the volume the inode belongs to 1N/A /* calculate volume name position */ 1N/A /* convert the name to current locale multibyte sequence */ 1N/A /* output the converted name. */ 1N/A * ntfs_dump_volume_information() 1N/A * dump the information for the volume the inode belongs to 1N/A * FIXME: The right way is based on the indexes, so we couldn't 1N/A * miss real entries. For now, dump until it makes sense. 1N/A return "<RL_NOT_MAPPED>";
1N/A return "<ENOENT>\t";
1N/A return "<EINVAL>\t";
1N/A printf(
"Dumping attribute %s (0x%x) from mft record %lld (0x%llx)\n",
1N/A /* Dump the attribute (stream) name */ 1N/A /* TODO: parse the flags */ 1N/A printf(
"\tAttribute instance:\t %u (0x%x)\n",
1N/A /* Resident attribute */ 1N/A /* TODO: parse the flags */ 1N/A /* Non-resident attribute */ 1N/A /* TODO: dump the 5 reserved bytes here in verbose mode */ 1N/A printf(
"\tAllocated size:\t\t %llu (0x%llx)\n",
1N/A (
unsigned long long)
1N/A printf(
"\tInitialized size:\t %llu (0x%llx)\n",
1N/A (
unsigned long long)
1N/A printf(
"\tCompressed size:\t %llu (0x%llx)\n",
1N/A // TODO: Switch this to properly aligned hex... 1N/A printf(
"\tRunlist:\tVCN\t\tLCN\t\tLength\n");
1N/A * ntfs_dump_data_attr() 1N/A * dump some info about the data attribute if it's metadata 1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A * ntfs_dump_index_entries() 1N/A * dump sequence of index_entries and return number of entries dumped. 1N/A "(0x%llx)\n", (
unsigned long long)
1N/A (
unsigned long long)
1N/A "skipping the remainder of this index " 1N/A /* weird, this should be illegal */ 1N/A /* FIXME: there are 3 reserved bytes here */ 1N/A * ntfs_dump_attr_index_root() 1N/A * dump the index_root attribute 1N/A /* attr_type dumping */ 1N/A /* collation rule dumping */ 1N/A/* COLLATION_BINARY, COLLATION_FILE_NAME, COLLATION_UNICODE_STRING, 1N/A COLLATION_NTOFS_ULONG, COLLATION_NTOFS_SID, 1N/A COLLATION_NTOFS_SECURITY_HASH, COLLATION_NTOFS_ULONGS */ 1N/A printf(
"\tClusters Per Block:\t %u (0x%x)\n",
1N/A * ntfs_dump_attr_index_allocation() 1N/A * dump context of the index_allocation attribute 1N/A * ntfs_dump_attr_bitmap() 1N/A * dump the bitmap attribute 1N/A * ntfs_dump_attr_reparse_point() 1N/A * of ntfs 3.x dumps the reparse_point attribute 1N/A * ntfs_dump_attr_ea_information() 1N/A * dump the ea_information attribute 1N/A printf(
"\tUnpacked EA length:\t %u (0x%x)\n",
1N/A * ntfs_dump_attr_ea() 1N/A * dump the ea attribute 1N/A /* FIXME: We don't handle fragmented mapping pairs case. */ 1N/A * ntfs_dump_attr_property_set() 1N/A * dump the property_set attribute 1N/A * ntfs_dump_attr_logged_utility_stream() 1N/A * dump the property_set attribute 1N/A unsigned char c = *((
char *)
buf + j);
1N/A unsigned char c = *((
char *)
buf + j);
1N/A /* display unprintable chars as '.' */ 1N/A if ((c<
32) || (c>
126)) {
1N/A * ntfs_dump_attr_unknown 1N/A printf(
"===== Please report this unknown attribute type to %s =====\n",
1N/A printf(
"\tDumping some of the attribute data:\n");
1N/A * ntfs_dump_inode_general_info 1N/A printf(
"MFT Record Seq. Numb.:\t %u (0x%x)\n",
1N/A printf(
"Number of Hard Links:\t %u (0x%x)\n",
1N/A /* The meaning of IS_4 is illusive but not its existence. */ 1N/A printf(
"Bytes Allocated:\t %u (0x%x) bytes\n",
1N/A (
unsigned long long)
1N/A (
unsigned long long)
1N/A printf(
"Next Attribute Instance: %u (0x%x)\n",
1N/A * ntfs_get_file_attributes 1N/A /* then start enumerating attributes 1N/A see ntfs_attr_lookup documentation for detailed explanation */ 1N/A printf(
"Weird: %s attribute type was found, please " 1N/A /* if we exited the loop before we're done - notify the user */ 1N/A "enumerating attributes");
1N/A /* close all data-structures we used */ 1N/A * main() - Begin here 1N/A * Return: 0 Success, the program worked 1N/A * 1 Error, something went wrong 1N/A printf(
"Failed to parse command line options\n");
1N/A * if opts.mft is not 0, then we will print out information about 1N/A * the volume, such as the sector size and whatnot. 1N/A /* obtain the inode */ 1N/A /* dump the inode information */ 1N/A /* general info about the inode's mft record */ 1N/A /* dump attributes */ 1N/A /* can't open inode */ 1N/A * note: when the specified inode does not exist, either 1N/A * EIO or or ESPIPE is returned, we should notify better