Changes by: mattjf
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv16979/ntfstools
Modified Files:
ntfsinfo.c
Log Message:
ntfsinfo update
Index: ntfsinfo.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsinfo.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -U2 -r1.8 -r1.9
--- ntfsinfo.c 30 Jun 2002 21:22:52 -0000 1.8
+++ ntfsinfo.c 1 Jul 2002 23:18:37 -0000 1.9
@@ -1,7 +1,7 @@
-/*
+/*z
* $Id$
*
* ntfsinfo - Part of the Linux-NTFS project.
- *
+ *
* Copyright (c) 2002 Matthew J. Fanto
* Copyright (c) 2002 Anton Altaparmakov
@@ -32,5 +32,5 @@
#include <errno.h>
#include <locale.h>
-
+#include <asm/types.h>
#include "mft.h"
#include "attrib.h"
@@ -39,8 +39,10 @@
void get_file_attribute_value(const char *dev, long int i);
+void print_standard_information_attr(ntfs_attr_search_ctx * ctx);
+void print_file_name_attr(ntfs_attr_search_ctx * ctx);
+
+
+#define NTFS_TIME_OFFSET ((__u64)(369*365 + 89) * 24 * 3600 * 10000000)
-/**
- * main
- */
int main(int argc, char **argv)
{
@@ -48,5 +50,5 @@
const char *EXEC_NAME = "ntfsinfo";
const char *locale;
- int i;
+ long i;
locale = setlocale(LC_ALL, "");
@@ -59,10 +61,12 @@
printf("Using locale %s.\n", locale);
- if(argc < 3 || argc > 4) {
+ if (argc < 3 || argc > 4) {
fprintf(stderr, "%s v%s - %s\n", EXEC_NAME, VERSION, AUTHOR);
fprintf(stderr, "Usage: ntfsinfo device inode\n");
exit(1);
- } else {
- i = atol(argv[2]);
+ }
+
+ else {
+ i = atoll(argv[2]);
get_file_attribute_value(argv[1], i);
}
@@ -71,32 +75,56 @@
}
-/**
- * get_file_attribute_value
- */
void get_file_attribute_value(const char *dev, long int i)
{
+
MFT_REF mref;
+ MFT_RECORD *mrec = NULL;
ATTR_RECORD *attr = NULL;
FILE_NAME_ATTR *file_name_attr = NULL;
+ STANDARD_INFORMATION *standard_information = NULL;
+ SECURITY_DESCRIPTOR_RELATIVE *security_descriptor = NULL;
ntfs_attr_search_ctx *ctx = NULL;
ntfs_volume *vol = NULL;
- char *file_name = NULL;
+ char *file_name;
ntfs_inode *inode = NULL;
- vol = ntfs_mount(dev,0);
+ vol = ntfs_mount(dev, 0);
- mref = (MFT_REF)i;
- inode = ntfs_open_inode(vol,mref);
- if (!inode) {
- perror("Error opening file!\n");
+ mref = (MFT_REF) i;
+ inode = ntfs_open_inode(vol, mref);
+
+ if (ntfs_read_file_record(vol, mref, &mrec, NULL)) {
+ perror("Error reading file record!\n");
exit(1);
}
- ctx = ntfs_get_attr_search_ctx(inode,NULL);
+ ctx = ntfs_get_attr_search_ctx(inode, mrec);
+
+// print_file_name_attr(ctx);
+
+// ctx = ntfs_get_attr_search_ctx(inode, mrec); //need to fix this
+
+ print_standard_information_attr(ctx);
+}
- //Here is where we need to start searching for each attribute
+
+__s64 ntfs2time(__s64 time)
+{
+ printf("Original Time: %Li\n",time);
+ __s64 t = time - NTFS_TIME_OFFSET;
+ t = t / 10000000;
+ return t;
+
- if(ntfs_lookup_attr(AT_FILE_NAME,NULL,0,0,0,NULL,0,ctx)) {
- perror("Error looking up attribute!\n");
+}
+
+void print_standard_information_attr(ntfs_attr_search_ctx *ctx)
+{
+ ATTR_RECORD *attr = NULL;
+ STANDARD_INFORMATION *standard_information_attr = NULL;
+
+ if (ntfs_lookup_attr
+ (AT_STANDARD_INFORMATION, NULL, 0, 0, 0, NULL, 0, ctx)) {
+ perror("Error looking up $STANDARD_INFORMATION!\n");
exit(1);
}
@@ -104,13 +132,63 @@
attr = ctx->attr;
- file_name_attr = (FILE_NAME_ATTR*)((char*)attr + le16_to_cpu(attr->value_offset));
+ standard_information_attr =
+ (STANDARD_INFORMATION *) ((char *) attr +
+ le16_to_cpu(attr->value_offset));
+
+ printf("Creation time: %Li\n",
+ ntfs2time(standard_information_attr->creation_time));
+/* printf("Last Data Change Time: %Li\n",
+ ntfs2time(standard_information_attr->last_data_change_time));
+ printf("Last MFT Change Time: %Li\n",
+ ntfs2time(standard_information_attr->last_mft_change_time));
+ printf("Last Access Time: %Li\n",
+ ntfs2time(standard_information_attr->last_access_time));
+ printf("Maxium Versions: %d\n",
+ standard_information_attr->maximum_versions);
+ printf("Version Number: %d\n",
+ standard_information_attr->version_number);
+ printf("Class ID: %d\n",
+ standard_information_attr->class_id);
+ printf("Owner ID: %d\n",
+ standard_information_attr->owner_id);
+ printf("Security ID: %d\n",
+ standard_information_attr->security_id);
+
+*/
+}
+
+void print_file_name_attr(ntfs_attr_search_ctx *ctx)
+{
+ ATTR_RECORD *attr = NULL;
+ ntfs_attr_search_ctx *c = ctx;
+ FILE_NAME_ATTR *file_name_attr = NULL;
+ char *file_name;
+
+ if (ntfs_lookup_attr(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) {
+ perror("Error looking up $FILE_NAME_ATTR!\n");
+ exit(1);
+ }
- ntfs_ucstombs(file_name_attr->file_name,file_name_attr->file_name_length,
- &file_name,file_name_attr->file_name_length);
- printf("%s\n",file_name);
-
- free (file_name);
- ntfs_put_attr_search_ctx (ctx);
- ntfs_close_inode (inode);
- ntfs_umount (vol, FALSE);
+ attr = ctx->attr;
+ ctx = c;
+
+ file_name_attr =
+ (FILE_NAME_ATTR *) ((char *) attr +
+ le16_to_cpu(attr->value_offset));
+
+ file_name = malloc(file_name_attr->file_name_length * sizeof (char));
+
+ ntfs_ucstombs(file_name_attr->file_name,
+ file_name_attr->file_name_length, &file_name,
+ file_name_attr->file_name_length);
+
+ printf("File Name: %s\n", file_name);
+ printf("File Name Length: %ld\n", file_name_attr->file_name_length);
+ printf("Allocated Size: %Li\n",sle64_to_cpu(file_name_attr->allocated_size));
+ printf("Data Size: %Li\n",sle64_to_cpu(file_name_attr->data_size));
}
+
+/*void print_security_descriptor_attr(SECURITY_DESCRIPTOR_RELATIVE *security_descriptor)
+{
+
+}*/
|