2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "ISO9660File.h"
15 using namespace XFILE
;
17 CISO9660File::CISO9660File() : m_iso(new ISO9660::IFS())
21 bool CISO9660File::Open(const CURL
& url
)
26 if (!m_iso
->open(url
.GetHostName().c_str()))
29 m_stat
.reset(m_iso
->stat(url
.GetFileName().c_str()));
37 m_start
= m_stat
->p_stat
->lsn
;
43 int CISO9660File::Stat(const CURL
& url
, struct __stat64
* buffer
)
58 buffer
->st_size
= m_stat
->p_stat
->size
;
60 switch (m_stat
->p_stat
->type
)
63 buffer
->st_mode
= S_IFDIR
;
67 buffer
->st_mode
= S_IFREG
;
74 ssize_t
CISO9660File::Read(void* buffer
, size_t size
)
76 const int maxSize
= std::min(size
, static_cast<size_t>(GetLength()));
77 const int blocks
= std::ceil(maxSize
/ ISO_BLOCKSIZE
);
79 if (m_current
> std::ceil(GetLength() / ISO_BLOCKSIZE
))
82 auto read
= m_iso
->seek_read(buffer
, m_start
+ m_current
, blocks
);
89 int64_t CISO9660File::Seek(int64_t filePosition
, int whence
)
91 int block
= std::floor(filePosition
/ ISO_BLOCKSIZE
);
102 m_current
= std::ceil(GetLength() / ISO_BLOCKSIZE
) + block
;
106 return m_current
* ISO_BLOCKSIZE
;
109 int64_t CISO9660File::GetLength()
111 return m_stat
->p_stat
->size
;
114 int64_t CISO9660File::GetPosition()
116 return m_current
* ISO_BLOCKSIZE
;
119 bool CISO9660File::Exists(const CURL
& url
)
124 int CISO9660File::GetChunkSize()
126 return ISO_BLOCKSIZE
;