/*
 * The internal definitions
 *
 * Copyright (C) 2009-2022, Joachim Metz <joachim.metz@gmail.com>
 *
 * Refer to AUTHORS for acknowledgements.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#if !defined( _LIBFSHFS_INTERNAL_DEFINITIONS_H )
#define _LIBFSHFS_INTERNAL_DEFINITIONS_H

#include <common.h>
#include <byte_stream.h>

#define LIBFSHFS_ENDIAN_BIG					_BYTE_STREAM_ENDIAN_BIG
#define LIBFSHFS_ENDIAN_LITTLE					_BYTE_STREAM_ENDIAN_LITTLE

/* Define HAVE_LOCAL_LIBFSHFS for local use of libfshfs
 */
#if !defined( HAVE_LOCAL_LIBFSHFS )
#include <libfshfs/definitions.h>

/* The definitions in <libfshfs/definitions.h> are copied here
 * for local use of libfshfs
 */
#else
#define LIBFSHFS_VERSION					20220114

/* The version string
 */
#define LIBFSHFS_VERSION_STRING					"20220114"

/* The file access
 * bit 1        set to 1 for read access
 * bit 2        set to 1 for write access
 * bit 3-8      not used
 */
enum LIBFSHFS_ACCESS_FLAGS
{
	LIBFSHFS_ACCESS_FLAG_READ				= 0x01,
/* Reserved: not supported yet */
	LIBFSHFS_ACCESS_FLAG_WRITE				= 0x02
};

/* The file access macros
 */
#define LIBFSHFS_OPEN_READ					( LIBFSHFS_ACCESS_FLAG_READ )
/* Reserved: not supported yet */
#define LIBFSHFS_OPEN_WRITE					( LIBFSHFS_ACCESS_FLAG_WRITE )
/* Reserved: not supported yet */
#define LIBFSHFS_OPEN_READ_WRITE				( LIBFSHFS_ACCESS_FLAG_READ | LIBFSHFS_ACCESS_FLAG_WRITE )

/* The path segment separator
 */
#define LIBFSHFS_SEPARATOR					'/'

/* The file system types
 */
enum LIBFSHFS_FILE_SYSTEM_TYPES
{
        LIBFSHFS_FILE_SYSTEM_TYPE_UNDEFINED,
        LIBFSHFS_FILE_SYSTEM_TYPE_HFS,
        LIBFSHFS_FILE_SYSTEM_TYPE_HFS_PLUS,
        LIBFSHFS_FILE_SYSTEM_TYPE_HFSX
};

/* The file types
 */
enum LIBFSHFS_FILE_TYPES
{
	LIBFSHFS_FILE_TYPE_FIFO					= 0x1000,
	LIBFSHFS_FILE_TYPE_CHARACTER_DEVICE			= 0x2000,
	LIBFSHFS_FILE_TYPE_DIRECTORY				= 0x4000,
	LIBFSHFS_FILE_TYPE_BLOCK_DEVICE				= 0x6000,
	LIBFSHFS_FILE_TYPE_REGULAR_FILE				= 0x8000,
	LIBFSHFS_FILE_TYPE_SYMBOLIC_LINK			= 0xa000,
	LIBFSHFS_FILE_TYPE_SOCKET				= 0xc000
};

#endif /* !defined( HAVE_LOCAL_LIBFSHFS ) */

/* The B-tree node types
 */
enum LIBFSHFS_BTREE_NODE_TYPES
{
        LIBFSHFS_BTREE_NODE_TYPE_INDEX_NODE			= 0x00,
        LIBFSHFS_BTREE_NODE_TYPE_HEADER_NODE			= 0x01,
        LIBFSHFS_BTREE_NODE_TYPE_MAP_NODE			= 0x02,

        LIBFSHFS_BTREE_NODE_TYPE_LEAF_NODE			= 0xff
};

/* The record types
 */
enum LIBFSHFS_RECORD_TYPES
{
        LIBFSHFS_RECORD_TYPE_HFSPLUS_DIRECTORY_RECORD		= 0x0001,
        LIBFSHFS_RECORD_TYPE_HFSPLUS_FILE_RECORD		= 0x0002,
        LIBFSHFS_RECORD_TYPE_HFSPLUS_DIRECTORY_THREAD_RECORD	= 0x0003,
        LIBFSHFS_RECORD_TYPE_HFSPLUS_FILE_THREAD_RECORD		= 0x0004,

        LIBFSHFS_RECORD_TYPE_HFS_DIRECTORY_RECORD		= 0x0100,
        LIBFSHFS_RECORD_TYPE_HFS_FILE_RECORD			= 0x0200,
        LIBFSHFS_RECORD_TYPE_HFS_DIRECTORY_THREAD_RECORD	= 0x0300,
        LIBFSHFS_RECORD_TYPE_HFS_FILE_THREAD_RECORD		= 0x0400
};

/* The fork types
 */
enum LIBFSHFS_FORK_TYPES
{
        LIBFSHFS_FORK_TYPE_DATA					= 0x00,
        LIBFSHFS_FORK_TYPE_RESOURCE				= 0xff
};

/* The attribute record types
 */
enum LIBFSHFS_ATTRIBUTE_RECORD_TYPES
{
        LIBFSHFS_ATTRIBUTE_RECORD_TYPE_INLINE_DATA		= 0x00000010UL,
        LIBFSHFS_ATTRIBUTE_RECORD_TYPE_FORK_DATA		= 0x00000020UL,
        LIBFSHFS_ATTRIBUTE_RECORD_TYPE_EXTENTS			= 0x00000030UL
};

/* The compression methods
 */
enum LIBFSHFS_COMPRESSION_METHODS
{
	LIBFSHFS_COMPRESSION_METHOD_NONE			= 0,
	LIBFSHFS_COMPRESSION_METHOD_DEFLATE			= 1,
	LIBFSHFS_COMPRESSION_METHOD_LZVN			= 2,

	LIBFSHFS_COMPRESSION_METHOD_UNKNOWN5			= 5
};

#define LIBFSHFS_ROOT_DIRECTORY_IDENTIFIER			2
#define LIBFSHFS_EXTENTS_FILE_IDENTIFIER			3
#define LIBFSHFS_CATALOG_FILE_IDENTIFIER			4
#define LIBFSHFS_ATTRIBUTES_FILE_IDENTIFIER			8

#define LIBFSHFS_MAXIMUM_BTREE_NODE_RECURSION_DEPTH		256

/* The maximum number of cache entries definitions
 */
#define LIBFSHFS_MAXIMUM_CACHE_ENTRIES_BTREE_FILE_BLOCKS	LIBFSHFS_MAXIMUM_BTREE_NODE_RECURSION_DEPTH + 1

#endif /* !defined( _LIBFSHFS_INTERNAL_DEFINITIONS_H ) */

