NTFS的几个patch

来源:互联网 发布:淘宝钱夫人雪梨微博 编辑:程序博客网 时间:2024/05/21 16:49

NTFS-3G移植后在项目测试过程中发现的一些bug, 摘录了一些放在blog上.


a.读目录返回EIO, 是index allocation里面的文件名的index entry的长度正好快到这个allocation结束的时候, 判断有问题.
=== (+5,-2) src/kware/ufs/ntfs-3g/libntfs-3g/dir.c ===
@@ -1372,8 +1372,11 @@
         dirent = (char*)dirent + ie->key.file_name.file_name_length + 1;//do not forget the ending \0
         info++;
 
-        do
+        do{
             ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length));
+            if (ie->ie_flags & INDEX_ENTRY_END)
+                break;
+            }
         while(last_index == ie->indexed_file || ie->key.file_name.file_name_type == FILE_NAME_DOS);
         last_index = ie->indexed_file;
     }
其实这样还有bug,应该是:
        do{
            ie = (INDEX_ENTRY*)((u8*)ie + le16_to_cpu(ie->length));
            if (ie->ie_flags & INDEX_ENTRY_END){
                if((u8*)ie + le16_to_cpu(ie->key_length) > index_end)
                    goto EOD;
                else
                    break;
                }
                
            }
        while(last_index == ie->indexed_file || ie->key.file_name.file_name_type == FILE_NAME_DOS);


b.文件名长度正好是某个特殊长度的话,创建新文件会失败
attrib.c
@@ -5242,11 +5242,19 @@
     if (new_size != attr_size) {
         
         u32 new_muse = old_size - attr_size + new_size;
+
+                /* Not enough space in this mft record. */
+        if (a->type == AT_INDEX_ROOT && new_muse > alloc_size) {
+            errno = ENOSPC;
+            ntfs_log_perror("Not enough space in the MFT record "
+                       "(%u > %u)\n", new_muse, alloc_size);
+            return STATUS_RESIDENT_ATTRIBUTE_FILLED_MFT;
+        }


        if(attr_size > new_size)
            memset((u8*)m + new_size + old_size - attr_size, 0, attr_size - new_size);

c. 创建一个文件, 一直写,一直提示分区满, 在申请新的空间的时候, 会破坏DBR还是MFT来着不记得了.
=== (+7,-1) src/kware/ufs/ntfs-3g/libntfs-3g/attrib.c ===
@@ -2339,6 +2339,12 @@
         /* It is a real lcn, write it to the volume. */
         to_write = min(count, (rl->length << vol->cluster_size_bits) - ofs);
 retry:
+        
+        if(rl->lcn < vol->mft_lcn)
+            to_write = min(to_write, (vol->mft_lcn - rl->lcn) * vol->cluster_size);
+        else if((rl->lcn == vol->mft_lcn) && (to_write != vol->mft_record_size))
+            to_write = 0;
+
         ntfs_log_trace("Writing %ld bytes to vcn %ld, lcn %ld, ofs "
                    "%ld.\n", (long)to_write, (unsigned long)rl->vcn,
                    (unsigned long)rl->lcn, (long)ofs);


d.memory leak
=== (+2,-2) src/kware/ufs/ntfs-3g/libntfs-3g/volume.c ===
@@ -1158,7 +1158,7 @@
          * format.
          */
         vol->vol_name = NULL;
-        if (ntfs_ucstombs(vname, u, (tchar_t**)(&vol->vol_name), 0) == -1) {
+        if (u && ntfs_ucstombs(vname, u, (tchar_t**)(&vol->vol_name), 0) == -1) {
             ntfs_log_perror("Volume name could not be converted "
                     "to current locale");
             ntfs_log_debug("Forcing name into ASCII by replacing "


e.硬盘很大(1T),连续几百G内都没有剩余空间,搜索bitmap很慢
=== (+11,-4) src/kware/ufs/ntfs-3g/libntfs-3g/lcnalloc.c ===
@@ -271,7 +271,10 @@
         goto out;
     }
 
-    buf = ntfs_malloc(NTFS_LCNALLOC_BSIZE);
+    if(vol->nr_clusters > 262144000)//vol size over 1T
+        buf = ntfs_malloc(8192);
+    else
+        buf = ntfs_malloc(NTFS_LCNALLOC_BSIZE);
     if (!buf)
         goto out;
     /*
@@ -316,7 +319,11 @@
         if (search_zone & vol->full_zones)
             goto zone_pass_done;
         last_read_pos = bmp_pos >> 3;
-        br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos,
+        if(vol->nr_clusters > 262144000)//vol is larger than 1T
+            br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos,
+                     8192, buf);
+        else
+            br = ntfs_attr_pread(vol->lcnbmp_na, last_read_pos,
                      NTFS_LCNALLOC_BSIZE, buf);
         if (br <= 0) {
             if (!br)

0 0