diff --git a/src/bin/package/DataReader.cpp b/src/bin/package/DataReader.cpp index 05aa82af87..735103d4fc 100644 --- a/src/bin/package/DataReader.cpp +++ b/src/bin/package/DataReader.cpp @@ -10,6 +10,8 @@ #include #include +#include + // #pragma mark - DataReader @@ -39,6 +41,30 @@ FDDataReader::ReadData(off_t offset, void* buffer, size_t size) } +// #pragma mark - AttributeDataReader + + +AttributeDataReader::AttributeDataReader(int fd, const char* attribute, + uint32 type) + : + fFD(fd), + fType(type), + fAttribute(attribute) +{ +} + + +status_t +AttributeDataReader::ReadData(off_t offset, void* buffer, size_t size) +{ + ssize_t bytesRead = fs_read_attr(fFD, fAttribute, fType, offset, buffer, + size); + if (bytesRead < 0) + return errno; + return (size_t)bytesRead == size ? B_OK : B_ERROR; +} + + // #pragma mark - BufferDataReader diff --git a/src/bin/package/DataReader.h b/src/bin/package/DataReader.h index 6ac47f9a64..be6a897be0 100644 --- a/src/bin/package/DataReader.h +++ b/src/bin/package/DataReader.h @@ -30,6 +30,21 @@ private: }; +class AttributeDataReader : public DataReader { +public: + AttributeDataReader(int fd, + const char* attribute, uint32 type); + + virtual status_t ReadData(off_t offset, void* buffer, + size_t size); + +private: + int fFD; + uint32 fType; + const char* fAttribute; +}; + + class BufferDataReader : public DataReader { public: BufferDataReader(const void* data, size_t size);