From 5bdf9f4f7dbba29c13588a71af42fbb3db9b85ee Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Thu, 18 Dec 2003 09:31:10 +0000 Subject: [PATCH] Initial checkin. SimulatedStream implementation that takes a list of Udf::extent_address structs. Will be used for standard data streams. Mostly complete, completely untested. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5699 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/makeudfimage/ExtentStream.cpp | 77 ++++++++++++++++++++++ src/apps/bin/makeudfimage/ExtentStream.h | 36 ++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/apps/bin/makeudfimage/ExtentStream.cpp create mode 100644 src/apps/bin/makeudfimage/ExtentStream.h diff --git a/src/apps/bin/makeudfimage/ExtentStream.cpp b/src/apps/bin/makeudfimage/ExtentStream.cpp new file mode 100644 index 0000000000..a3e43bcfd8 --- /dev/null +++ b/src/apps/bin/makeudfimage/ExtentStream.cpp @@ -0,0 +1,77 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//---------------------------------------------------------------------- + +/*! \file ExtentStream.cpp +*/ + +#include "ExtentStream.h" + +#include +#include + +ExtentStream::ExtentStream(DataStream &stream, + const std::list &extentList, + uint32 blockSize) + : SimulatedStream(stream) + , fExtentList(extentList) + , fBlockSize(blockSize) + , fSize(0) +{ + for (std::list::const_iterator i = fExtentList.begin(); + i != fExtentList.end(); + i++) + { + fSize += i->length(); + } +} + +/*! \brief Returns the largest extent in the underlying data stream + corresponding to the extent starting at byte position \a pos of + byte length \a size in the output parameter \a extent. + + NOTE: If the position is at or beyond the end of the stream, the + function will return B_OK, but the value of extent.size will be 0. +*/ +status_t +ExtentStream::_GetExtent(off_t pos, size_t size, data_extent &extent) +{ + status_t error = pos >= 0 ? B_OK : B_BAD_VALUE; + if (!error) { + off_t finalOffset = 0; + off_t streamPos = 0; + for (std::list::const_iterator i = fExtentList.begin(); + i != fExtentList.end(); + i++) + { + off_t offset = i->location() * fBlockSize; + finalOffset = offset + i->length(); + if (streamPos <= pos && pos < streamPos+i->length()) { + // Found it + off_t difference = pos - streamPos; + extent.offset = offset + difference; + extent.size = i->length() - difference; + if (extent.size > size) + extent.size = size; + return B_OK; + } else { + streamPos += i->length(); + } + } + // Didn't find it, so pos is past the end of the stream + extent.offset = finalOffset; + extent.size = 0; + } + return error; +} + +/*! \brief Returns the current size of the stream. +*/ +off_t +ExtentStream::_Size() +{ + return fSize; +} diff --git a/src/apps/bin/makeudfimage/ExtentStream.h b/src/apps/bin/makeudfimage/ExtentStream.h new file mode 100644 index 0000000000..b7707bb4da --- /dev/null +++ b/src/apps/bin/makeudfimage/ExtentStream.h @@ -0,0 +1,36 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//---------------------------------------------------------------------- + +/*! \file ExtentStream.h +*/ + +#ifndef _EXTENT_STREAM_H +#define _EXTENT_STREAM_H + +#include + +#include "SimulatedStream.h" +#include "UdfStructures.h" + +/*! \brief AbstractExtentStream implementation that takes a list of + block-aligned data extents. +*/ +class ExtentStream : public SimulatedStream { +public: + ExtentStream(DataStream &stream, const std::list &extentList, uint32 blockSize); + +protected: + virtual status_t _GetExtent(off_t pos, size_t size, data_extent &extent); + virtual off_t _Size(); + +private: + const std::list &fExtentList; + const uint32 fBlockSize; + off_t fSize; +}; + +#endif // _EXTENT_STREAM_H