[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / filesystem / ISO9660File.cpp
blob83de0cc800f5bfe44ec4fc20daef1eec8d8b8d46
1 /*
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.
7 */
9 #include "ISO9660File.h"
11 #include "URL.h"
13 #include <cmath>
15 using namespace XFILE;
17 CISO9660File::CISO9660File() : m_iso(new ISO9660::IFS())
21 bool CISO9660File::Open(const CURL& url)
23 if (m_iso && m_stat)
24 return true;
26 if (!m_iso->open(url.GetHostName().c_str()))
27 return false;
29 m_stat.reset(m_iso->stat(url.GetFileName().c_str()));
31 if (!m_stat)
32 return false;
34 if (!m_stat->p_stat)
35 return false;
37 m_start = m_stat->p_stat->lsn;
38 m_current = 0;
40 return true;
43 int CISO9660File::Stat(const CURL& url, struct __stat64* buffer)
45 if (!m_iso)
46 return -1;
48 if (!m_stat)
49 return -1;
51 if (!m_stat->p_stat)
52 return -1;
54 if (!buffer)
55 return -1;
57 *buffer = {};
58 buffer->st_size = m_stat->p_stat->size;
60 switch (m_stat->p_stat->type)
62 case 2:
63 buffer->st_mode = S_IFDIR;
64 break;
65 case 1:
66 default:
67 buffer->st_mode = S_IFREG;
68 break;
71 return 0;
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))
80 return -1;
82 auto read = m_iso->seek_read(buffer, m_start + m_current, blocks);
84 m_current += blocks;
86 return read;
89 int64_t CISO9660File::Seek(int64_t filePosition, int whence)
91 int block = std::floor(filePosition / ISO_BLOCKSIZE);
93 switch (whence)
95 case SEEK_SET:
96 m_current = block;
97 break;
98 case SEEK_CUR:
99 m_current += block;
100 break;
101 case SEEK_END:
102 m_current = std::ceil(GetLength() / ISO_BLOCKSIZE) + block;
103 break;
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)
121 return Open(url);
124 int CISO9660File::GetChunkSize()
126 return ISO_BLOCKSIZE;