1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //----------------------------------------------------------------------
8 /*! \file ExtentStream.cpp
11 #include "ExtentStream.h"
16 ExtentStream::ExtentStream(DataStream
&stream
,
17 const std::list
<Udf::extent_address
> &extentList
,
19 : SimulatedStream(stream
)
20 , fExtentList(extentList
)
21 , fBlockSize(blockSize
)
24 for (std::list
<Udf::extent_address
>::const_iterator i
= fExtentList
.begin();
25 i
!= fExtentList
.end();
32 /*! \brief Returns the largest extent in the underlying data stream
33 corresponding to the extent starting at byte position \a pos of
34 byte length \a size in the output parameter \a extent.
36 NOTE: If the position is at or beyond the end of the stream, the
37 function will return B_OK, but the value of extent.size will be 0.
40 ExtentStream::_GetExtent(off_t pos
, size_t size
, data_extent
&extent
)
42 status_t error
= pos
>= 0 ? B_OK
: B_BAD_VALUE
;
44 off_t finalOffset
= 0;
46 for (std::list
<Udf::extent_address
>::const_iterator i
= fExtentList
.begin();
47 i
!= fExtentList
.end();
50 off_t offset
= i
->location() * fBlockSize
;
51 finalOffset
= offset
+ i
->length();
52 if (streamPos
<= pos
&& pos
< streamPos
+i
->length()) {
54 off_t difference
= pos
- streamPos
;
55 extent
.offset
= offset
+ difference
;
56 extent
.size
= i
->length() - difference
;
57 if (extent
.size
> size
)
61 streamPos
+= i
->length();
64 // Didn't find it, so pos is past the end of the stream
65 extent
.offset
= finalOffset
;
71 /*! \brief Returns the current size of the stream.