aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive/Iso9660ArchivePlugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive/Iso9660ArchivePlugin.cxx')
-rw-r--r--src/archive/Iso9660ArchivePlugin.cxx81
1 files changed, 48 insertions, 33 deletions
diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx
index ad21d4a3d..c83e38b0d 100644
--- a/src/archive/Iso9660ArchivePlugin.cxx
+++ b/src/archive/Iso9660ArchivePlugin.cxx
@@ -32,7 +32,6 @@
#include "util/Error.hxx"
#include "util/Domain.hxx"
-#include <cdio/cdio.h>
#include <cdio/iso9660.h>
#include <stdlib.h>
@@ -41,11 +40,11 @@
#define CEILING(x, y) ((x+(y-1))/y)
class Iso9660ArchiveFile final : public ArchiveFile {
-public:
RefCount ref;
iso9660_t *iso;
+public:
Iso9660ArchiveFile(iso9660_t *_iso)
:ArchiveFile(iso9660_archive_plugin), iso(_iso) {}
@@ -53,11 +52,19 @@ public:
iso9660_close(iso);
}
+ void Ref() {
+ ref.Increment();
+ }
+
void Unref() {
if (ref.Decrement())
delete this;
}
+ long SeekRead(void *ptr, lsn_t start, long int i_size) const {
+ return iso9660_iso_seek_read(iso, ptr, start, i_size);
+ }
+
void Visit(const char *path, ArchiveVisitor &visitor);
virtual void Close() override {
@@ -131,31 +138,35 @@ Iso9660ArchiveFile::Visit(ArchiveVisitor &visitor)
/* single archive handling */
-struct Iso9660InputStream {
+class Iso9660InputStream {
InputStream base;
- Iso9660ArchiveFile *archive;
+ Iso9660ArchiveFile &archive;
iso9660_stat_t *statbuf;
- size_t max_blocks;
+public:
Iso9660InputStream(Iso9660ArchiveFile &_archive, const char *uri,
Mutex &mutex, Cond &cond,
iso9660_stat_t *_statbuf)
:base(iso9660_input_plugin, uri, mutex, cond),
- archive(&_archive), statbuf(_statbuf),
- max_blocks(CEILING(statbuf->size, ISO_BLOCKSIZE)) {
-
+ archive(_archive), statbuf(_statbuf) {
base.ready = true;
base.size = statbuf->size;
- archive->ref.Increment();
+ archive.Ref();
}
~Iso9660InputStream() {
free(statbuf);
- archive->Unref();
+ archive.Unref();
}
+
+ InputStream *Get() {
+ return &base;
+ }
+
+ size_t Read(void *ptr, size_t size, Error &error);
};
InputStream *
@@ -173,7 +184,7 @@ Iso9660ArchiveFile::OpenStream(const char *pathname,
Iso9660InputStream *iis =
new Iso9660InputStream(*this, pathname, mutex, cond,
statbuf);
- return &iis->base;
+ return iis->Get();
}
static void
@@ -184,45 +195,49 @@ iso9660_input_close(InputStream *is)
delete iis;
}
-
-static size_t
-iso9660_input_read(InputStream *is, void *ptr, size_t size,
- Error &error)
+inline size_t
+Iso9660InputStream::Read(void *ptr, size_t size, Error &error)
{
- Iso9660InputStream *iis = (Iso9660InputStream *)is;
int readed = 0;
int no_blocks, cur_block;
- size_t left_bytes = iis->statbuf->size - is->offset;
-
- size = (size * ISO_BLOCKSIZE) / ISO_BLOCKSIZE;
+ size_t left_bytes = statbuf->size - base.offset;
if (left_bytes < size) {
no_blocks = CEILING(left_bytes,ISO_BLOCKSIZE);
} else {
no_blocks = size / ISO_BLOCKSIZE;
}
- if (no_blocks > 0) {
- cur_block = is->offset / ISO_BLOCKSIZE;
+ if (no_blocks == 0)
+ return 0;
- readed = iso9660_iso_seek_read (iis->archive->iso, ptr,
- iis->statbuf->lsn + cur_block, no_blocks);
+ cur_block = base.offset / ISO_BLOCKSIZE;
- if (readed != no_blocks * ISO_BLOCKSIZE) {
- error.Format(iso9660_domain,
- "error reading ISO file at lsn %lu",
- (unsigned long)cur_block);
- return 0;
- }
- if (left_bytes < size) {
- readed = left_bytes;
- }
+ readed = archive.SeekRead(ptr, statbuf->lsn + cur_block,
+ no_blocks);
- is->offset += readed;
+ if (readed != no_blocks * ISO_BLOCKSIZE) {
+ error.Format(iso9660_domain,
+ "error reading ISO file at lsn %lu",
+ (unsigned long)cur_block);
+ return 0;
+ }
+ if (left_bytes < size) {
+ readed = left_bytes;
}
+
+ base.offset += readed;
return readed;
}
+static size_t
+iso9660_input_read(InputStream *is, void *ptr, size_t size,
+ Error &error)
+{
+ Iso9660InputStream *iis = (Iso9660InputStream *)is;
+ return iis->Read(ptr, size, error);
+}
+
static bool
iso9660_input_eof(InputStream *is)
{