[haiku-commits] r37638 - haiku/trunk/src/tests/system/kernel/file_corruption/driver

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 21 Jul 2010 01:16:46 +0200 (CEST)

Author: bonefish
Date: 2010-07-21 01:16:46 +0200 (Wed, 21 Jul 2010)
New Revision: 37638
Changeset: http://dev.haiku-os.org/changeset/37638

Modified:
   
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp
   haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.h
Log:
* Added CHECKSUM_DEVICE_IOCTL_GET_CHECK_SUM ioctl.
* Added some debug output.
* CheckSumCache::_GetBlock(): Fixed incorrect check. The method could return
  an arbitrary block.


Modified: 
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp
===================================================================
--- 
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp  
    2010-07-20 23:14:48 UTC (rev 37637)
+++ 
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.cpp  
    2010-07-20 23:16:46 UTC (rev 37638)
@@ -32,6 +32,14 @@
 #include "CheckSum.h"
 
 
+//#define TRACE_CHECK_SUM_DEVICE
+#ifdef TRACE_CHECK_SUM_DEVICE
+#      define TRACE(x...)      dprintf(x)
+#else
+#      define TRACE(x) do {} while (false)
+#endif
+
+
 // parameters for the DMA resource
 static const uint32 kDMAResourceBufferCount                    = 16;
 static const uint32 kDMAResourceBounceBufferCount      = 16;
@@ -138,6 +146,14 @@
                block->checkSums[blockIndex % kCheckSumsPerBlock] = checkSum;
                block->dirty = true;
 
+#ifdef TRACE_CHECK_SUM_DEVICE
+               TRACE("checksum_device: setting check sum of block %" B_PRIu64 
" to: ",
+                       blockIndex);
+               for (size_t i = 0; i < kCheckSumLength; i++)
+                       TRACE("%02x", checkSum.Data()[i]);
+               TRACE("\n");
+#endif
+
                return B_OK;
        }
 
@@ -150,7 +166,7 @@
                // check whether we have already cached the block
                for (BlockList::Iterator it = fBlocks.GetIterator();
                        CheckSumBlock* block = it.Next();) {
-                       if (block->used && block->blockIndex) {
+                       if (block->used && blockIndex == block->blockIndex) {
                                // we know it -- requeue and return
                                it.Remove();
                                fBlocks.Add(block);
@@ -434,6 +450,11 @@
                        kRawDeviceModuleName);
        }
 
+       status_t GetBlockCheckSum(uint64 blockIndex, CheckSum& checkSum)
+       {
+               return fCheckSumCache->GetCheckSum(blockIndex, checkSum);
+       }
+
        status_t SetBlockCheckSum(uint64 blockIndex, const CheckSum& checkSum)
        {
                return fCheckSumCache->SetCheckSum(blockIndex, checkSum);
@@ -552,7 +573,9 @@
                fSHA256.Update(fTransferBuffer, B_PAGE_SIZE);
 
                if (expectedCheckSum != fSHA256.Digest())
-                       panic("Check sum mismatch for block %" B_PRIu64, 
blockIndex);
+                       panic("Check sum mismatch for block %" B_PRIu64 " 
(exptected at %p"
+                               ", actual at %p)", blockIndex, 
&expectedCheckSum,
+                               fSHA256.Digest());
        }
 
 private:
@@ -1085,10 +1108,33 @@
                case B_FLUSH_DRIVE_CACHE:
                        return B_OK;
 
+               case CHECKSUM_DEVICE_IOCTL_GET_CHECK_SUM:
+               {
+                       if (IS_USER_ADDRESS(buffer)) {
+                               checksum_device_ioctl_check_sum getCheckSum;
+                               if (user_memcpy(&getCheckSum, buffer, 
sizeof(getCheckSum))
+                                               != B_OK) {
+                                       return B_BAD_ADDRESS;
+                               }
+
+                               status_t error = device->GetBlockCheckSum(
+                                       getCheckSum.blockIndex, 
getCheckSum.checkSum);
+                               if (error != B_OK)
+                                       return error;
+
+                               return user_memcpy(buffer, &getCheckSum, 
sizeof(getCheckSum));
+                       }
+
+                       checksum_device_ioctl_check_sum* getCheckSum
+                               = (checksum_device_ioctl_check_sum*)buffer;
+                       return device->GetBlockCheckSum(getCheckSum->blockIndex,
+                               getCheckSum->checkSum);
+               }
+
                case CHECKSUM_DEVICE_IOCTL_SET_CHECK_SUM:
                {
                        if (IS_USER_ADDRESS(buffer)) {
-                               checksum_device_ioctl_set_check_sum setCheckSum;
+                               checksum_device_ioctl_check_sum setCheckSum;
                                if (user_memcpy(&setCheckSum, buffer, 
sizeof(setCheckSum))
                                                != B_OK) {
                                        return B_BAD_ADDRESS;
@@ -1098,8 +1144,8 @@
                                        setCheckSum.checkSum);
                        }
 
-                       checksum_device_ioctl_set_check_sum* setCheckSum
-                               = (checksum_device_ioctl_set_check_sum*)buffer;
+                       checksum_device_ioctl_check_sum* setCheckSum
+                               = (checksum_device_ioctl_check_sum*)buffer;
                        return device->SetBlockCheckSum(setCheckSum->blockIndex,
                                setCheckSum->checkSum);
                }

Modified: 
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.h
===================================================================
--- 
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.h    
    2010-07-20 23:14:48 UTC (rev 37637)
+++ 
haiku/trunk/src/tests/system/kernel/file_corruption/driver/checksum_device.h    
    2010-07-20 23:16:46 UTC (rev 37638)
@@ -12,11 +12,12 @@
 
 
 enum {
-       CHECKSUM_DEVICE_IOCTL_SET_CHECK_SUM     = B_DEVICE_OP_CODES_END + 0x666
+       CHECKSUM_DEVICE_IOCTL_GET_CHECK_SUM     = B_DEVICE_OP_CODES_END + 0x666,
+       CHECKSUM_DEVICE_IOCTL_SET_CHECK_SUM
 };
 
 
-struct checksum_device_ioctl_set_check_sum {
+struct checksum_device_ioctl_check_sum {
        uint64          blockIndex;
        CheckSum        checkSum;
 };


Other related posts:

  • » [haiku-commits] r37638 - haiku/trunk/src/tests/system/kernel/file_corruption/driver - ingo_weinhold