Changes by: szaka
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv15070/libntfs
Modified Files:
volume.c
Log Message:
ntfs_reset_logfile(): free resources in error, handle partial I/O
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -U2 -r1.53 -r1.54
--- volume.c 12 Jul 2002 12:38:54 -0000 1.53
+++ volume.c 14 Jul 2002 12:34:44 -0000 1.54
@@ -938,5 +938,11 @@
s64 len, pos, count;
char buf[NTFS_BUF_SIZE];
+ int eo;
+ if (!vol) {
+ errno = EINVAL;
+ return -1;
+ }
+
if ((ni = ntfs_open_inode(vol, FILE_LogFile)) == NULL) {
Dperror("Failed to open inode FILE_LogFile.\n");
@@ -946,5 +952,5 @@
if ((na = ntfs_attr_open(ni, AT_DATA, AT_NONAME, 0)) == NULL) {
Dperror("Failed to open $FILE_LogFile/$DATA\n");
- return -1;
+ goto error_exit;
}
@@ -953,5 +959,5 @@
Dprintf("$LogFile $DATA attribute is resident!?!\n");
errno = EIO;
- return -1;
+ goto io_error_exit;
}
@@ -967,20 +973,13 @@
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;
-
+ while ((count = ntfs_attr_pread(na, pos, NTFS_BUF_SIZE, buf)) > 0)
pos += count;
- if (count != NTFS_BUF_SIZE || !count)
- break;
- }
- if (count == -1 || pos != len) {
+ if (count == -1 || (pos + count) != len) {
Dprintf("Amount of $LogFile data read does not "
"correspond to expected length!");
if (count != -1)
errno = EIO;
- return -1;
+ goto io_error_exit;
}
@@ -994,9 +993,9 @@
count = NTFS_BUF_SIZE;
- if (count != ntfs_attr_pwrite(na, pos, count, buf)) {
+ if ((count = ntfs_attr_pwrite(na, pos, count, buf)) <= 0) {
Dprintf("Failed to set the $LogFile attribute value.");
if (count != -1)
errno = EIO;
- return -1;
+ goto io_error_exit;
}
pos += count;
@@ -1004,6 +1003,15 @@
ntfs_attr_close(na);
-
return ntfs_close_inode(ni);
+
+io_error_exit:
+ eo = errno;
+ ntfs_attr_close(na);
+ errno = eo;
+error_exit:
+ eo = errno;
+ ntfs_close_inode(ni);
+ errno = eo;
+ return -1;
}
|