* Clean up continues

* Removing _IMPEXP_KERNEL macro along with the COMPILE_FOR_R5 macro
* Also removing Udf namespace


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26884 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Salvatore Benedetto
2008-08-09 08:32:48 +00:00
parent 90b73f5f3f
commit 70081c0dfc
2 changed files with 106 additions and 144 deletions
+94 -105
View File
@@ -1,54 +1,83 @@
//---------------------------------------------------------------------- /*
// This software is part of the Haiku distribution and is covered * Copyright 2003, Tyler Dauwalder, [email protected].
// by the MIT license. * Distributed under the terms of the MIT License.
// */
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
//---------------------------------------------------------------------
/*! \file Utils.cpp /*! \file Utils.cpp - Miscellaneous Udf utility functions. */
Miscellaneous Udf utility functions.
*/
#include "Utils.h" #include "Utils.h"
extern "C" { extern "C" {
#ifndef _IMPEXP_KERNEL
# define _IMPEXP_KERNEL
#endif
extern int32 timezone_offset; extern int32 timezone_offset;
} }
/*! \brief Returns "true" if \a value is true, "false" otherwise. */
namespace Udf { const char*
bool_to_string(bool value)
long_address
to_long_address(ino_t id, uint32 length)
{ {
DEBUG_INIT_ETC(NULL, ("ino_t: %Ld (0x%Lx), length: %ld", id, id, length)); return value ? "true" : "false";
long_address result;
result.set_block((id >> 16) & 0xffffffff);
result.set_partition(id & 0xffff);
result.set_length(length);
DUMP(result);
return result;
} }
ino_t
to_vnode_id(long_address address) /*! \brief Calculates the UDF crc checksum for the given byte stream.
Based on crc code from UDF-2.50 6.5, as permitted.
\param data Pointer to the byte stream.
\param length Length of the byte stream in bytes.
\return The crc checksum, or 0 if an error occurred.
*/
uint16
calculate_crc(uint8 *data, uint16 length)
{ {
DEBUG_INIT(NULL); uint16 crc = 0;
ino_t result = address.block(); if (data) {
result <<= 16; for ( ; length > 0; length--, data++)
result |= address.partition(); crc = kCrcTable[(crc >> 8 ^ *data) & 0xff] ^ (crc << 8);
PRINT(("block: %ld, 0x%lx\n", address.block(), address.block())); }
PRINT(("partition: %d, 0x%x\n", address.partition(), address.partition())); return crc;
PRINT(("length: %ld, 0x%lx\n", address.length(), address.length()));
PRINT(("ino_t: %Ld, 0x%Lx\n", result, result));
return result;
} }
/*! \brief Takes an overloaded ssize_t return value like those returned
by BFile::Read() and friends, as well as an expected number of bytes,
and returns B_OK if the byte counts match, or the appropriate error
code otherwise.
*/
status_t
check_size_error(ssize_t bytesReturned, ssize_t bytesExpected)
{
return bytesReturned == bytesExpected
? B_OK : (bytesReturned >= 0 ? B_IO_ERROR : status_t(bytesReturned));
}
/*! \brief Calculates the block shift amount for the given
block size, which must be a positive power of 2.
*/
status_t
get_block_shift(uint32 blockSize, uint32 &blockShift)
{
if (blockSize == 0)
return B_BAD_VALUE;
uint32 bitCount = 0;
uint32 result = 0;
for (int i = 0; i < 32; i++) {
// Zero out all bits except bit i
uint32 block = blockSize & (uint32(1) << i);
if (block) {
if (++bitCount > 1)
return B_BAD_VALUE;
else
result = i;
}
}
blockShift = result;
return B_OK;
}
time_t time_t
make_time(timestamp &timestamp) make_time(timestamp &timestamp)
{ {
@@ -59,9 +88,10 @@ make_time(timestamp &timestamp)
timestamp.month(), timestamp.day(), timestamp.hour(), timestamp.minute(), timestamp.second())); timestamp.month(), timestamp.day(), timestamp.hour(), timestamp.minute(), timestamp.second()));
time_t result = 0; time_t result = 0;
if (timestamp.year() >= 1970) { if (timestamp.year() >= 1970) {
const int monthLengths[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const int monthLengths[12]
= { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int year = timestamp.year(); int year = timestamp.year();
int month = timestamp.month(); int month = timestamp.month();
@@ -78,12 +108,12 @@ make_time(timestamp &timestamp)
if (-1440 > timezone_offset || timezone_offset > 1440) if (-1440 > timezone_offset || timezone_offset > 1440)
timezone_offset = 0; timezone_offset = 0;
timezone_offset -= timezone_offset % 60; timezone_offset -= timezone_offset % 60;
int previousLeapYears = (year - 1968) / 4; int previousLeapYears = (year - 1968) / 4;
bool isLeapYear = (year - 1968) % 4 == 0; bool isLeapYear = (year - 1968) % 4 == 0;
if (isLeapYear) if (isLeapYear)
--previousLeapYears; --previousLeapYears;
// Years to days // Years to days
result = (year - 1970) * 365 + previousLeapYears; result = (year - 1970) * 365 + previousLeapYears;
// Months to days // Months to days
@@ -97,77 +127,36 @@ make_time(timestamp &timestamp)
// Hours to minutes // Hours to minutes
result = (result + hour) * 60 + timezone_offset; result = (result + hour) * 60 + timezone_offset;
// Minutes to seconds // Minutes to seconds
result = (result + minute) * 60 + second; result = (result + minute) * 60 + second;
} }
return result; return result;
} }
/*! \brief Calculates the block shift amount for the given
block size, which must be a positive power of 2.
*/
status_t
Udf::get_block_shift(uint32 blockSize, uint32 &blockShift)
{
if (blockSize == 0)
return B_BAD_VALUE;
uint32 bitCount = 0;
uint32 result = 0;
for (int i = 0; i < 32; i++) {
// Zero out all bits except bit i
uint32 block = blockSize & (uint32(1) << i);
if (block) {
if (++bitCount > 1) {
return B_BAD_VALUE;
} else {
result = i;
}
}
}
blockShift = result;
return B_OK;
}
/*! \brief Returns "true" if \a value is true, "false" otherwise. long_address
*/ to_long_address(ino_t id, uint32 length)
const char*
Udf::bool_to_string(bool value)
{ {
return value ? "true" : "false"; DEBUG_INIT_ETC(NULL, ("ino_t: %Ld (0x%Lx), length: %ld", id, id, length));
long_address result;
result.set_block((id >> 16) & 0xffffffff);
result.set_partition(id & 0xffff);
result.set_length(length);
DUMP(result);
return result;
} }
/*! \brief Takes an overloaded ssize_t return value like those returned
by BFile::Read() and friends, as well as an expected number of bytes, ino_t
and returns B_OK if the byte counts match, or the appropriate error to_vnode_id(long_address address)
code otherwise.
*/
status_t
Udf::check_size_error(ssize_t bytesReturned, ssize_t bytesExpected)
{ {
return bytesReturned == bytesExpected DEBUG_INIT(NULL);
? B_OK ino_t result = address.block();
: (bytesReturned >= 0 ? B_IO_ERROR : status_t(bytesReturned)); result <<= 16;
result |= address.partition();
PRINT(("block: %ld, 0x%lx\n", address.block(), address.block()));
PRINT(("partition: %d, 0x%x\n", address.partition(), address.partition()));
PRINT(("length: %ld, 0x%lx\n", address.length(), address.length()));
PRINT(("ino_t: %Ld, 0x%Lx\n", result, result));
return result;
} }
/*! \brief Calculates the UDF crc checksum for the given byte stream.
Based on crc code from UDF-2.50 6.5, as permitted.
\param data Pointer to the byte stream.
\param length Length of the byte stream in bytes.
\return The crc checksum, or 0 if an error occurred.
*/
uint16
Udf::calculate_crc(uint8 *data, uint16 length)
{
uint16 crc = 0;
if (data) {
for ( ; length > 0; length--, data++)
crc = Udf::kCrcTable[(crc >> 8 ^ *data) & 0xff] ^ (crc << 8);
}
return crc;
}
} // namespace Udf
+12 -39
View File
@@ -1,47 +1,20 @@
//---------------------------------------------------------------------- /*
// This software is part of the Haiku distribution and is covered * Copyright 2003, Tyler Dauwalder, [email protected].
// by the MIT license. * Distributed under the terms of the MIT License.
// */
// Copyright (c) 2003 Tyler Dauwalder, [email protected]
//---------------------------------------------------------------------
#ifndef _UDF_UTILS_H #ifndef _UDF_UTILS_H
#define _UDF_UTILS_H #define _UDF_UTILS_H
/*! \file Utils.h /*! \file Utils.h - Miscellaneous Udf utility functions. */
Miscellaneous Udf utility functions.
*/
#ifndef _IMPEXP_KERNEL
# define _IMPEXP_KERNEL
#endif
#ifdef COMPILE_FOR_R5
extern "C" {
#endif
#include "fsproto.h"
#ifdef COMPILE_FOR_R5
}
#endif
#include "UdfStructures.h" #include "UdfStructures.h"
namespace Udf { const char *bool_to_string(bool value);
uint16 calculate_crc(uint8 *data, uint16 length);
long_address to_long_address(ino_t id, uint32 length = 0); status_t check_size_error(ssize_t bytesReturned, ssize_t bytesExpected);
status_t get_block_shift(uint32 blockSize, uint32 &blockShift);
ino_t to_vnode_id(long_address address); time_t make_time(timestamp &timestamp);
long_address to_long_address(ino_t id, uint32 length = 0);
time_t make_time(timestamp &timestamp); ino_t to_vnode_id(long_address address);
status_t get_block_shift(uint32 blockSize, uint32 &blockShift);
const char* bool_to_string(bool value);
status_t check_size_error(ssize_t bytesReturned, ssize_t bytesExpected);
uint16 calculate_crc(uint8 *data, uint16 length);
} // namespace Udf
#endif // _UDF_UTILS_H #endif // _UDF_UTILS_H