Changes by: szaka
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv11567/ntfstools
Modified Files:
ntfsfix.c ntfsresize.c
Log Message:
Rewrote $LogFile reset using new inode API and moved it from ntfsfix to
libntfs as ntfs_reset_logfile(). ntfsresize also resets log file.
Index: ntfsfix.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsfix.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -U2 -r1.39 -r1.40
--- ntfsfix.c 12 Jul 2002 07:10:44 -0000 1.39
+++ ntfsfix.c 12 Jul 2002 12:38:54 -0000 1.40
@@ -69,7 +69,4 @@
unsigned char *m = NULL, *m2 = NULL;
ntfs_volume *vol;
- ntfs_attr_search_ctx *ctx;
- ATTR_RECORD *a;
- unsigned char *lfd;
unsigned long mnt_flags;
int i;
@@ -298,96 +295,13 @@
puts(OK);
printf("\n");
- /*
- * Fill the value of the $LogFile data attribute, i.e. the contents of
- * the file, with 0xff's, thus marking the journal as empty.
- * FIXME(?): We might need to zero the LSN field of every single mft
- * record as well. (But, first try without doing that and see what
- * happens, since chkdsk might pickup the pieces and do it for us...)
- */
- if (ntfs_read_file_record(vol, FILE_LogFile, (MFT_RECORD**)&m, NULL)) {
- perror("Failed to read $LogFile");
- goto error_exit;
- }
- if (!(((MFT_RECORD*)m)->flags & MFT_RECORD_IN_USE)) {
- fprintf(stderr, "Error: $LogFile has been deleted. Cannot "
- "handle this yet. Run chkdsk to fix this.\n");
- goto error_exit;
- }
printf("Going to empty the journal ($LogFile)... ");
- /* Find the $DATA attribute. */
- ctx = ntfs_get_attr_search_ctx(NULL, (MFT_RECORD*)m);
- if (!ctx) {
- puts(FAILED);
- perror("Failed to allocate attribute search context");
- goto log_file_error;
- }
- if (ntfs_lookup_attr(AT_DATA, AT_NONAME, 0, 0, 0, NULL, 0, ctx)) {
+ if (ntfs_reset_logfile(vol)) {
puts(FAILED);
- fprintf(stderr, "Error: Attribute $DATA was not found in" \
- "$LogFile!\n");
- goto log_file_error;
- }
- a = ctx->attr;
- /* The $DATA attribute of the $LogFile has to be non-resident. */
- if (!a->non_resident) {
- puts(FAILED);
- fprintf(stderr, "$LogFile $DATA attribute is resident!?!\n");
- goto log_file_error;
- }
- /* Get length of $LogFile contents. */
- l = get_attribute_value_length((ATTR_RECORD*)a);
- if (!l) {
- puts(OK);
- puts("$LogFile has zero length, no need to write to disk.");
- goto log_file_error;
- }
- /* Allocate a buffer to hold all of the $LogFile contents. */
- lfd = (unsigned char*)malloc(l);
- if (!lfd) {
- puts(FAILED);
- puts("Not enough memory to load $LogFile.");
- goto log_file_error;
+ perror("Failed to reset $LogFile");
+ goto error_exit;
}
- /* Read in the $LogFile into the buffer. We do this more as a check
- for correct length than anything else. We thus make sure we are
- decompressing the mapping pairs array correctly and hence writing
- below if safe as well. */
- if (l != get_attribute_value(vol, (MFT_RECORD*)m, a, lfd)) {
- puts(FAILED);
- puts("Amount of data read does not correspond to expected "
- "length!");
- free(lfd);
- goto log_file_error;
- }
- /* Fill the buffer with 0xff's. */
- memset(lfd, -1, l);
- /* Set the $DATA attribute. */
- /* FIXME: set_attribute_value needs to either:
- * - know the MFT_RECORD so it can adjust it accordingly with
- * changes in length of the resident part of the attribute.
- * or
- * - return a copy of the attribute so the MFT_RECORD can be
- * adjusted accordingly with changes in the length of the resident
- * part of the attribute by the caller.
- * For now, just assume that attribute length remains constant, since
- * this is the case for the $LogFile zeroing out. */
- if (!set_attribute_value(vol, (ATTR_RECORD*)a, lfd, l)) {
- puts(FAILED);
- puts("Failed to set the $LogFile attribute value.");
- free(lfd);
- goto log_file_error;
- }
- /* No need to sync the $LogFile mft record to disk as we haven't
- touched it at all. */
- /* Release the allocated buffer and finish $LogFile processing. */
- free(lfd);
puts(OK);
-
-log_file_error:
printf("\n");
-
- if (ctx)
- ntfs_put_attr_search_ctx(ctx);
if (vol->major_ver >= 3) {
Index: ntfsresize.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfsresize.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -U2 -r1.10 -r1.11
--- ntfsresize.c 12 Jul 2002 07:10:44 -0000 1.10
+++ ntfsresize.c 12 Jul 2002 12:38:54 -0000 1.11
@@ -651,4 +651,8 @@
/* FIXME: first do all checks before any write attempt */
+ if (!opt.ro_flag)
+ if (ntfs_reset_logfile(vol))
+ perr_exit("Failed to reset $LogFile");
+
truncate_badclust_file(opt.size);
truncate_bitmap_file(opt.size);
|