Finally added crc checking for descriptor_tags.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5570 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "CS0String.h"
|
#include "CS0String.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
using namespace Udf;
|
using namespace Udf;
|
||||||
|
|
||||||
@@ -290,15 +291,41 @@ descriptor_tag ::dump() const
|
|||||||
/*! \brief Calculates the tag's CRC, verifies the tag's checksum, and
|
/*! \brief Calculates the tag's CRC, verifies the tag's checksum, and
|
||||||
verifies the tag's location on the medium.
|
verifies the tag's location on the medium.
|
||||||
|
|
||||||
|
Note that this function makes the assumption that the descriptor_tag
|
||||||
|
is the first data member in a larger descriptor structure, the remainder
|
||||||
|
of which immediately follows the descriptor_tag itself in memory. This
|
||||||
|
is generally a safe assumption, as long as the entire descriptor (and
|
||||||
|
not the its tag) is read in before init_check() is called. If this is
|
||||||
|
not the case, it's best to call this function with a \a calculateCrc
|
||||||
|
value of false, to keep from trying to calculate a crc value on invalid
|
||||||
|
and possibly unowned memory.
|
||||||
|
|
||||||
|
\param block The block location of this descriptor as taken from the
|
||||||
|
corresponding allocation descriptor. If the address specifies
|
||||||
|
a block in a partition, the partition block is the desired
|
||||||
|
location, not the mapped physical disk block.
|
||||||
|
\param calculateCrc Whether or not to perform the crc calculation
|
||||||
|
on the descriptor data following the tag.
|
||||||
|
|
||||||
\todo Calc the CRC.
|
\todo Calc the CRC.
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
descriptor_tag ::init_check(uint32 diskBlock)
|
descriptor_tag::init_check(uint32 block, bool calculateCrc)
|
||||||
{
|
{
|
||||||
DEBUG_INIT("descriptor_tag");
|
DEBUG_INIT_ETC("descriptor_tag", ("location: %ld, calculateCrc: %s",
|
||||||
PRINT(("location (paramater) == %ld\n", diskBlock));
|
block, bool_to_string(calculateCrc)));
|
||||||
|
PRINT(("location (paramater) == %ld\n", block));
|
||||||
PRINT(("location (in structure) == %ld\n", location()));
|
PRINT(("location (in structure) == %ld\n", location()));
|
||||||
status_t error = (diskBlock == location()) ? B_OK : B_NO_INIT;
|
if (calculateCrc) {
|
||||||
|
PRINT(("crc (calculated) == %d\n",
|
||||||
|
Udf::calculate_crc(reinterpret_cast<uint8*>(this)+sizeof(descriptor_tag),
|
||||||
|
crc_length())))
|
||||||
|
} else {
|
||||||
|
PRINT(("crc (calculated) == (not calculated)\n"));
|
||||||
|
}
|
||||||
|
PRINT(("crc (in structure) == %d\n", crc()));
|
||||||
|
PRINT(("crc_length (in structure) == %d\n", crc_length()));
|
||||||
|
status_t error = (block == location()) ? B_OK : B_NO_INIT;
|
||||||
// checksum
|
// checksum
|
||||||
if (!error) {
|
if (!error) {
|
||||||
uint32 sum = 0;
|
uint32 sum = 0;
|
||||||
@@ -308,7 +335,12 @@ descriptor_tag ::init_check(uint32 diskBlock)
|
|||||||
sum += ((uint8*)this)[i];
|
sum += ((uint8*)this)[i];
|
||||||
error = sum % 256 == checksum() ? B_OK : B_NO_INIT;
|
error = sum % 256 == checksum() ? B_OK : B_NO_INIT;
|
||||||
}
|
}
|
||||||
|
// crc
|
||||||
|
if (!error && calculateCrc) {
|
||||||
|
uint16 _crc = Udf::calculate_crc(reinterpret_cast<uint8*>(this)
|
||||||
|
+ sizeof(descriptor_tag), crc_length());
|
||||||
|
error = _crc == crc() ? B_OK : B_NO_INIT;
|
||||||
|
}
|
||||||
RETURN(error);
|
RETURN(error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ struct descriptor_tag {
|
|||||||
public:
|
public:
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
status_t init_check(uint32 diskBlock);
|
status_t init_check(uint32 block, bool calculateCrc = true);
|
||||||
|
|
||||||
uint16 id() const { return B_LENDIAN_TO_HOST_INT16(_id); }
|
uint16 id() const { return B_LENDIAN_TO_HOST_INT16(_id); }
|
||||||
uint16 version() const { return B_LENDIAN_TO_HOST_INT16(_version); }
|
uint16 version() const { return B_LENDIAN_TO_HOST_INT16(_version); }
|
||||||
|
|||||||
Reference in New Issue
Block a user