[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / filesystem / UDFBlockInput.cpp
blobb4eb26563decd9bcad9ab518ec77f06251241607
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 "UDFBlockInput.h"
11 #include "filesystem/File.h"
13 #include <mutex>
15 #include <udfread/udfread.h>
17 int CUDFBlockInput::Close(udfread_block_input* bi)
19 auto m_bi = reinterpret_cast<UDF_BI*>(bi);
21 m_bi->fp->Close();
23 return 0;
26 uint32_t CUDFBlockInput::Size(udfread_block_input* bi)
28 auto m_bi = reinterpret_cast<UDF_BI*>(bi);
30 return static_cast<uint32_t>(m_bi->fp->GetLength() / UDF_BLOCK_SIZE);
33 int CUDFBlockInput::Read(
34 udfread_block_input* bi, uint32_t lba, void* buf, uint32_t blocks, int flags)
36 auto m_bi = reinterpret_cast<UDF_BI*>(bi);
37 std::unique_lock<CCriticalSection> lock(m_bi->lock);
39 int64_t pos = static_cast<int64_t>(lba) * UDF_BLOCK_SIZE;
41 if (m_bi->fp->Seek(pos, SEEK_SET) != pos)
42 return -1;
44 ssize_t size = blocks * UDF_BLOCK_SIZE;
45 ssize_t read = m_bi->fp->Read(buf, size);
46 if (read > 0)
47 return static_cast<int>(read / UDF_BLOCK_SIZE);
49 return static_cast<int>(read);
52 udfread_block_input* CUDFBlockInput::GetBlockInput(const std::string& file)
54 auto fp = std::make_shared<XFILE::CFile>();
56 if (fp->Open(file))
58 m_bi = std::make_unique<UDF_BI>();
59 if (m_bi)
61 m_bi->fp = fp;
62 m_bi->bi.close = CUDFBlockInput::Close;
63 m_bi->bi.read = CUDFBlockInput::Read;
64 m_bi->bi.size = CUDFBlockInput::Size;
66 return &m_bi->bi;
69 fp->Close();
72 return nullptr;