Changes by: szaka
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv11567/libntfs
Modified Files:
volume.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: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -U2 -r1.52 -r1.53
--- volume.c 12 Jul 2002 08:18:15 -0000 1.52
+++ volume.c 12 Jul 2002 12:38:54 -0000 1.53
@@ -917,2 +917,93 @@
return -1;
}
+
+/**
+ * ntfs_reset_logfile - "empty" $LogFile data attribute value
+ * @vol: ntfs volume whose $LogFile we intend to reset.
+ *
+ * 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...)
+ *
+ * On success return 0.
+ *
+ * On error, return -1 with errno set to the error code.
+ */
+int ntfs_reset_logfile(ntfs_volume *vol)
+{
+ ntfs_inode *ni;
+ ntfs_attr *na;
+ s64 len, pos, count;
+ char buf[NTFS_BUF_SIZE];
+
+ if ((ni = ntfs_open_inode(vol, FILE_LogFile)) == NULL) {
+ Dperror("Failed to open inode FILE_LogFile.\n");
+ return -1;
+ }
+
+ if ((na = ntfs_attr_open(ni, AT_DATA, AT_NONAME, 0)) == NULL) {
+ Dperror("Failed to open $FILE_LogFile/$DATA\n");
+ return -1;
+ }
+
+ /* The $DATA attribute of the $LogFile has to be non-resident. */
+ if (!NAttrNonResident(na)) {
+ Dprintf("$LogFile $DATA attribute is resident!?!\n");
+ errno = EIO;
+ return -1;
+ }
+
+ /* Get length of $LogFile contents. */
+ len = na->data_size;
+ if (!len) {
+ Dprintf("$LogFile has zero length, no disk write needed.\n");
+ return 0;
+ }
+
+ /* Read $LogFile until its end. We do this as a check for correct
+ length thus making sure we are decompressing the mapping pairs
+ array correctly and hence writing below is safe as well. */
+ pos = 0;
+ while (1) {
+ count = ntfs_attr_pread(na, pos, NTFS_BUF_SIZE, buf);
+ if (count == -1)
+ break;
+
+ pos += count;
+ if (count != NTFS_BUF_SIZE || !count)
+ break;
+ }
+
+ if (count == -1 || pos != len) {
+ Dprintf("Amount of $LogFile data read does not "
+ "correspond to expected length!");
+ if (count != -1)
+ errno = EIO;
+ return -1;
+ }
+
+ /* Fill the buffer with 0xff's. */
+ memset(buf, -1, NTFS_BUF_SIZE);
+
+ /* Set the $DATA attribute. */
+ pos = 0;
+ while ((count = len - pos) > 0) {
+ if (count > NTFS_BUF_SIZE)
+ count = NTFS_BUF_SIZE;
+
+ if (count != ntfs_attr_pwrite(na, pos, count, buf)) {
+ Dprintf("Failed to set the $LogFile attribute value.");
+ if (count != -1)
+ errno = EIO;
+ return -1;
+ }
+ pos += count;
+ }
+
+ ntfs_attr_close(na);
+
+ return ntfs_close_inode(ni);
+}
+
|