Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv27831/ntfstools
Modified Files:
mkntfs.c upcase.c
Log Message:
mkntfs alpha 3
==============
- Several bugfixes (root dir link count wasn't incremented, mftmirror usns
weren't correct [off by one too high], etc).
- Implement new $UpCase generation using flatcap (Richard Russon)'s algorithm
for generating it. This dropped the stripped mkntfs executable from 204kb down
to 78kb in size. A whopping 62% size decrease! Yey! And the source code dropped
ny over 600kb in size as well. And compilation got quicker, too.
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -U2 -r1.19 -r1.20
--- mkntfs.c 2001/06/09 18:32:57 1.19
+++ mkntfs.c 2001/06/10 02:25:38 1.20
@@ -58,12 +58,10 @@
#include "disk_io.h"
#include "attrib.h"
-//#include "mft.h"
-//#include "volume.h"
extern const unsigned char attrdef_ntfs12_array[2400];
-extern const unsigned char upcase_array[131072];
extern const unsigned char boot_array[3429];
extern void init_system_file_sd(int sys_file_no, char **sd_val,
int *sd_val_len);
+extern void init_upcase_table(uchar_t *uc, __u32 uc_len);
#define BLKGETSIZE _IO(0x12,96)
@@ -125,5 +123,5 @@
int attr_defs_len; /* in bytes */
uchar_t *upcase; /* -u filename, upcase table. */
- int upcase_len; /* Determined automatically. */
+ __u32 upcase_len; /* Determined automatically. */
char quiet; /* -q, quiet execution. */
char verbose; /* -v, verbose execution, -vv really
@@ -1593,7 +1591,20 @@
const FILE_NAME_TYPE_FLAGS file_name_type)
{
+ attr_search_context ctx;
+ STANDARD_INFORMATION *si;
FILE_NAME_ATTR *fn;
int i, fn_size;
+ /* Check if the attribute is already there. */
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.mrec = m;
+ if (!find_first_attr($STANDARD_INFORMATION, NULL, 0, 0, NULL, 0,
+ NULL, 0, &ctx)) {
+ Eprintf("BUG: Standard information attribute not present in "
+ "file record\n");
+ return -EINVAL;
+ }
+ si = (STANDARD_INFORMATION*)((char*)ctx.attr +
+ le16_to_cpu(ctx.attr->value_offset));
i = (strlen(file_name) + 1) * sizeof(uchar_t);
fn_size = sizeof(FILE_NAME_ATTR) + i;
@@ -1602,10 +1613,8 @@
return -errno;
fn->parent_directory = parent_dir;
- // FIXME: Is this correct? Or do we have to copy the creation_time
- // from the std info?
- fn->creation_time = time2ntfs(time(NULL));
- fn->last_data_change_time = fn->creation_time;
- fn->last_mft_change_time = fn->creation_time;
- fn->last_access_time = fn->creation_time;
+ fn->creation_time = si->creation_time;
+ fn->last_data_change_time = si->last_data_change_time;
+ fn->last_mft_change_time = si->last_mft_change_time;
+ fn->last_access_time = si->last_access_time;
fn->allocated_size = cpu_to_le64(allocated_size);
fn->data_size = cpu_to_le64(data_size);
@@ -2314,9 +2323,11 @@
opt.attr_defs_len = sizeof(attrdef_ntfs12_array);
Dprintf("Attr_defs table length = %u\n", opt.attr_defs_len);
- opt.upcase = (uchar_t*)&upcase_array;
/* Length is in characters. */
- opt.upcase_len = sizeof(upcase_array) >> 1;
+ opt.upcase_len = 65536;
+ opt.upcase = (uchar_t*)malloc(opt.upcase_len * sizeof(uchar_t));
+ if (!opt.upcase)
+ err_exit("Could not allocate memory for internal buffer.\n");
+ init_upcase_table(opt.upcase, opt.upcase_len * sizeof(uchar_t));
opt.volume_label = NULL;
- Dprintf("UpCase table length = %u\n", opt.upcase_len);
}
@@ -2355,4 +2366,6 @@
if (opt.attr_defs != (ATTR_DEF*)attrdef_ntfs12_array)
free(opt.attr_defs);
+ if (opt.upcase)
+ free(opt.upcase);
if (opt.volume_label)
free(opt.volume_label);
@@ -2802,4 +2815,5 @@
m = (MFT_RECORD*)(buf + 5 * opt.mft_record_size);
m->flags |= MFT_RECORD_IS_DIRECTORY;
+ m->link_count = cpu_to_le16(le16_to_cpu(m->link_count) + 1);
err = add_attr_file_name(m, root_ref, 0LL, 0LL,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM |
@@ -3218,14 +3232,17 @@
lw = opt.mft_record_size;
for (i = 0; i < 4; i++) {
- __u16 usn;
+ __u16 usn, *usnp;
m = (MFT_RECORD*)(buf + i * opt.mft_record_size);
/*
- * Decrement the usn by one so it becomes the same as the one in
- * $MFT once it is mst protected.
+ * Decrement the usn by one, so it becomes the same as the one
+ * in $MFT once it is mst protected. - This is as we need the
+ * $MFTMirr to have the exact same byte by byte content as
+ * $MFT, rather than just equivalent meaning content.
*/
- usn = le16_to_cpu(*(__u16*)((char*)m +
- le16_to_cpu(m->usa_ofs)));
+ usnp = (__u16*)((char*)m + le16_to_cpu(m->usa_ofs));
+ usn = le16_to_cpup(usnp);
if (usn-- <= 1)
usn = 0xfffe;
+ *usnp = cpu_to_le16(usn);
if (!opt.no_action)
lw = mst_pwrite(f, buf + i * opt.mft_record_size,
Index: upcase.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/upcase.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -U2 -r1.1 -r1.2
--- upcase.c 2001/06/01 02:07:26 1.1
+++ upcase.c 2001/06/10 02:25:38 1.2
@@ -1,8195 +1,80 @@
-const unsigned char upcase_array[131072] = {
- 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0,
- 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0,
- 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
- 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0,
- 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0,
- 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0,
- 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0,
- 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0,
- 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0, 71, 0,
- 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, 79, 0,
[...8243 lines suppressed...]
+ {0x0199, 0x0198}, {0x01CC, 0x01CA}, {0x0263, 0x0194}, {0x0292, 0x01B7},
+ {0x01A8, 0x01A7}, {0x01DD, 0x018E}, {0x0268, 0x0197},
+ {0}
+ };
+ int i, r;
+
+ memset((char*)uc, 0, uc_len);
+ uc_len >>= 1;
+ for (i = 0; i < uc_len; i++)
+ uc[i] = i;
+ for (r = 0; uc_run_table[r][0]; r++)
+ for (i = uc_run_table[r][0]; i < uc_run_table[r][1]; i++)
+ uc[i] += uc_run_table[r][2];
+ for (r = 0; uc_dup_table[r][0]; r++)
+ for (i = uc_dup_table[r][0]; i < uc_dup_table[r][1]; i += 2)
+ uc[i + 1]--;
+ for (r = 0; uc_byte_table[r][0]; r++)
+ uc[uc_byte_table[r][0]] = uc_byte_table[r][1];
+}
|