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 "UDFBlockInput.h"
11 #include "filesystem/File.h"
15 #include <udfread/udfread.h>
17 int CUDFBlockInput::Close(udfread_block_input
* bi
)
19 auto m_bi
= reinterpret_cast<UDF_BI
*>(bi
);
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
)
44 ssize_t size
= blocks
* UDF_BLOCK_SIZE
;
45 ssize_t read
= m_bi
->fp
->Read(buf
, size
);
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
>();
58 m_bi
= std::make_unique
<UDF_BI
>();
62 m_bi
->bi
.close
= CUDFBlockInput::Close
;
63 m_bi
->bi
.read
= CUDFBlockInput::Read
;
64 m_bi
->bi
.size
= CUDFBlockInput::Size
;