- DiskStructures.{h,cpp} -> UdfStructures.{h,cpp}

- Added Udf::get_block_shift()


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5529 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2003-12-02 10:50:23 +00:00
parent 9c6a058880
commit f79d99c80d
2 changed files with 28 additions and 1 deletions
@@ -103,4 +103,29 @@ make_time(timestamp &timestamp)
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;
}
} // namespace Udf
+3 -1
View File
@@ -20,7 +20,7 @@ extern "C" {
#include <fsproto.h>
}
#include "DiskStructures.h"
#include "UdfStructures.h"
namespace Udf {
@@ -30,6 +30,8 @@ vnode_id to_vnode_id(long_address address);
time_t make_time(timestamp &timestamp);
status_t get_block_shift(uint32 blockSize, uint32 &blockShift);
} // namespace Udf
#endif // _UDF_UTILS_H