16#define TAG_BTRFS_INFO 'IftB'
17#define TAG_BTRFS_CHUNK_MAP 'CftB'
18#define TAG_BTRFS_NODE 'NftB'
19#define TAG_BTRFS_FILE 'FftB'
20#define TAG_BTRFS_LINK 'LftB'
22#define INVALID_INODE _UI64_MAX
23#define INVALID_ADDRESS _UI64_MAX
24#define READ_ERROR _UI64_MAX
53 mid = (low + high) / 2;
112 TRACE(
"too many chunk items\n");
117 chunk_map->
map[
i] = chunk_map->
map[
i - 1];
138 TRACE(
"inserting chunk log: %llx len: %llx devid: %llx phys: %llx\n",
147 TRACE(
"insert finished. Printing chunk map:\n------------------------------\n");
151 itm = &chunk_map->
map[
i];
152 TRACE(
"%llx..%llx -> %llx..%llx, devid: %llu\n",
181 return &
path->tree_buf->leaf.items[
path->slots[0]];
248 TRACE(
"Address translation: 0x%llx -> 0x%llx\n",
logical,
267 ERR(
"ArcSeek returned status %lu\n",
Status);
274 ERR(
"ArcRead returned status %lu\n",
Status);
287 u64 physical, logical = loffset;
289 TRACE(
"BtrFsSearchTree called: offset: 0x%llx, level: %u (%llu %u %llu)\n",
294 ERR(
"Path struct is not allocated\n");
298 for (lvl =
level; lvl >= 0; lvl--)
305 ERR(
"Error when reading tree node, loffset: 0x%llx, poffset: 0x%llx, level: %u\n",
306 logical, physical, lvl);
312 ERR(
"Error when searching in tree: expected lvl=%u but got %u\n",
317 TRACE(
"BtrFsSearchTree loop, level %u, loffset: 0x%llx\n", lvl, logical);
343 path->offsets[lvl] = logical;
351 TRACE(
"BtrFsSearchTree found item (%llu %u %llu) offset: %lu, size: %lu, returning %lu\n",
390 if (!
path->itemsnr[0])
449 TRACE(
"reading chunk array\n-----------------------------\n");
451 while (cur < sb->sys_chunk_array_size)
454 TRACE(
"chunk key objectid: %llx, offset: %llx, type: %u\n",
460 TRACE(
"chunk stripe_len: %llx\n",
chunk->stripe_len);
462 TRACE(
"chunk io_align: %u\n",
chunk->io_align);
463 TRACE(
"chunk io_width: %u\n",
chunk->io_width);
464 TRACE(
"chunk sector_size: %u\n",
chunk->sector_size);
465 TRACE(
"chunk num_stripes: %u\n",
chunk->num_stripes);
466 TRACE(
"chunk sub_stripes: %u\n",
chunk->sub_stripes);
469 TRACE(
"read_sys_chunk_array() cur=%d\n",
cur);
488 TRACE(
"warning: only support single device btrfs\n");
537 ERR(
"Invalid dir item name len: %u\n",
item->name_len);
550 const char *name_ptr;
554 this_len =
sizeof(*item) +
item->name_len +
item->data_len;
555 name_ptr = (
const char *)
item +
sizeof(*
item);
610 key.objectid = dir_haystack;
632 name_buf = (
char *)
item +
sizeof(*
item);
662 cbuf = (
const char *)
extent + data_off;
669 ERR(
"Tried to read offset (%llu) beyond extent length (%lu)\n",
offset, dlen);
678 TRACE(
"read_extent_inline %lu, \n", data_off);
683 ERR(
"No compression supported right now\n");
698 ERR(
"Tried to read offset (%llu) beyond extent length (%lu)\n",
offset, dlen);
706 if (
extent->disk_bytenr == 0 &&
extent->disk_num_bytes == 0)
715 ERR(
"Unable to convert logical address to physical: %llu\n",
extent->disk_bytenr);
766 ERR(
"No compression supported right now\n");
781 TRACE(
"btrfs_file_read inr=%llu offset=%llu size=%llu\n", inr,
offset,
size);
805 TRACE(
"Current extent: (%llu %u %llu) \n",
812 offset_in_extent = seek_pointer;
828 ERR(
"Error while reading extent\n");
836 TRACE(
"file_read size=%llu rd=%llu seek_pointer=%llu\n",
size,
rd, seek_pointer);
908 *new_root = tmp_root;
934 ERR(
"Extent for symlink %llu not of INLINE type\n", inr);
940 ERR(
"Symlink %llu extent data compressed!\n", inr);
943 else if (
extent->encryption != 0)
945 ERR(
"Symlink %llu extent data encrypted!\n", inr);
950 ERR(
"Symlink %llu extent data too long (%llu)!\n", inr,
extent->ram_bytes);
960 ERR(
"Cannot allocate %llu bytes\n",
extent->ram_bytes + 1);
965 (*target)[
extent->ram_bytes] =
'\0';
1042 if (
cur[0] ==
'/' ||
cur[0] ==
'\\')
1044 else if (
cur[0] ==
'.' && (
cur[1] ==
'/' ||
cur[1] ==
'\\'))
1061 int len, have_inode = 0;
1063 const char *last_elem;
1066 if (*
cur ==
'/' || *
cur ==
'\\')
1069 inr =
root->root_dirid;
1085 last_elem_len =
len;
1087 if (
len == 1 &&
cur[0] ==
'.')
1090 if (
len == 2 &&
cur[0] ==
'.' &&
cur[1] ==
'.')
1106 TRACE(
"Try to find case-insensitive, path=%s inr=%llu s=%.*s\n",
path, inr,
len,
cur);
1118 char *link_target =
NULL;
1122 TRACE(
"%s: Too much symlinks!\n");
1131 &
type, &inode_item, symlink_limit - 1,
1144 inr =
item.location.objectid;
1166 *inode_item_p = inode_item;
1169 if (filename_buffer)
1172 *filename_length =
min(*filename_length, last_elem_len);
1173 RtlCopyMemory(filename_buffer, last_elem, *filename_length);
1183 TRACE(
"BtrFsClose %lu\n", FileId);
1205 TRACE(
"BtrFsGetFileInformation(%lu) -> FileSize = %llu, FilePointer = 0x%llx\n",
1237 BtrFsInfo->
FsRoot.root_dirid,
1247 TRACE(
"Not a regular file: %s\n",
Path);
1269 TRACE(
"found inode inr=%llu size=%llu\n", inr, temp_file_info.
inode.size);
1271 temp_file_info.
inr = inr;
1279 phandle->
Volume = BtrFsInfo;
1290 TRACE(
"BtrFsRead %lu, size=%lu \n", FileId,
Size);
1302 TRACE(
"An error occured while reading file %lu\n", FileId);
1349 return Volume->SuperBlock.total_bytes;
1369 TRACE(
"Enter BtrFsMount(%lu)\n", DeviceId);
1392 TRACE(
"BtrFsMount(%lu) superblock magic ok\n", DeviceId);
1418 TRACE(
"BtrFsMount(%lu) success\n", DeviceId);
#define ALIGN_DOWN_BY(size, align)
PRTL_UNICODE_STRING_BUFFER Path
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
#define DBG_DEFAULT_CHANNEL(ch)
#define BTRFS_SUPER_FLAG_METADUMP
#define btrfs_crc32c(name, len)
#define BTRFS_FIRST_CHUNK_TREE_OBJECTID
#define BTRFS_DEV_ITEMS_OBJECTID
#define BTRFS_FIRST_FREE_OBJECTID
#define BTRFS_DIR_INDEX_KEY
#define BTRFS_INODE_REF_KEY
#define BTRFS_DEV_ITEM_KEY
#define BTRFS_DIR_ITEM_KEY
#define BTRFS_COMPRESS_NONE
#define BTRFS_MAX_CHUNK_ENTRIES
#define BTRFS_FS_TREE_OBJECTID
#define BTRFS_ROOT_ITEM_KEY
#define BTRFS_SUPER_INFO_OFFSET
#define BTRFS_INODE_ITEM_KEY
#define BTRFS_FT_REG_FILE
#define BTRFS_CHUNK_ITEM_KEY
#define BTRFS_EXTENT_DATA_KEY
#define BTRFS_FILE_EXTENT_INLINE
static void btrfs_init_crc32c(void)
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
PVOID FsGetDeviceSpecific(ULONG FileId)
VOID FsSetDeviceSpecific(ULONG FileId, PVOID Specific)
ULONG FsGetDeviceId(ULONG FileId)
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
static u64 btrfs_file_read(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 inr, u64 offset, u64 size, char *buf)
static u64 btrfs_lookup_path(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 inr, const char *path, u8 *type_p, struct btrfs_inode_item *inode_item_p, int symlink_limit, _Out_opt_ PCHAR filename_buffer, _Inout_ PULONG filename_length)
ARC_STATUS BtrFsClose(ULONG FileId)
static u64 get_parent_inode(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 inr, struct btrfs_inode_item *inode_item)
static u64 btrfs_lookup_inode_ref(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 inr, struct btrfs_inode_ref *refp, char *name)
ARC_STATUS BtrFsOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
ULONGLONG BtrFsGetVolumeSize(_In_ ULONG DeviceId)
Returns the size of the BTRFS volume laid on the storage media device opened via DeviceId.
ARC_STATUS BtrFsSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
struct _BTRFS_INFO BTRFS_INFO
static const struct btrfs_disk_key * path_current_disk_key(struct btrfs_path *path)
const DEVVTBL * BtrFsMount(ULONG DeviceId)
static struct btrfs_item * path_current_item(struct btrfs_path *path)
static u64 logical_physical(struct btrfs_chunk_map *chunk_map, u64 logical)
static u64 btrfs_read_extent_reg(PBTRFS_INFO BtrFsInfo, struct btrfs_path *path, struct btrfs_file_extent_item *extent, u64 offset, u64 size, char *out)
ARC_STATUS BtrFsRead(ULONG FileId, VOID *Buffer, ULONG Size, ULONG *BytesRead)
static void free_path(struct btrfs_path *path)
#define TAG_BTRFS_CHUNK_MAP
static BOOLEAN BtrFsSearchTree(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, struct btrfs_disk_key *key, struct btrfs_path *path)
static BOOLEAN _BtrFsSearchTree(PBTRFS_INFO BtrFsInfo, u64 loffset, u8 level, struct btrfs_disk_key *key, struct btrfs_path *path)
static BOOLEAN BtrFsLookupDirItemI(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 dir_haystack, const char *name, int name_len, struct btrfs_dir_item *ret_item)
static int next_slot(PBTRFS_INFO BtrFsInfo, struct btrfs_disk_key *key, struct btrfs_path *path)
static void insert_map(struct btrfs_chunk_map *chunk_map, const struct btrfs_disk_key *key, struct btrfs_chunk *chunk)
static int btrfs_lookup_inode(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, struct btrfs_disk_key *location, struct btrfs_inode_item *item, struct btrfs_root_item *new_root)
static int next_length(const char *path)
static BOOLEAN BtrFsLookupDirItem(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 dir, const char *name, int name_len, struct btrfs_dir_item *item)
ARC_STATUS BtrFsGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
static int btrfs_comp_keys(const struct btrfs_disk_key *k1, const struct btrfs_disk_key *k2)
static BOOLEAN btrfs_readlink(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 inr, char **target)
static int btrfs_comp_chunk_map(struct btrfs_chunk_map_item *m1, struct btrfs_chunk_map_item *m2)
static void init_path(const struct btrfs_super_block *sb, struct btrfs_path *path)
static void btrfs_read_chunk_tree(PBTRFS_INFO BtrFsInfo)
static int bin_search(void *ptr, int item_size, void *cmp_item, cmp_func func, int min, int max, int *slot)
static void insert_chunk_item(struct btrfs_chunk_map *chunk_map, struct btrfs_chunk_map_item *item)
PBTRFS_INFO BtrFsVolumes[MAX_FDS]
static void btrfs_read_sys_chunk_array(PBTRFS_INFO BtrFsInfo)
static u64 btrfs_read_extent_inline(struct btrfs_path *path, struct btrfs_file_extent_item *extent, u64 offset, u64 size, char *out)
static BOOLEAN disk_read(ULONG DeviceId, u64 physical, void *dest, u32 count)
static UCHAR * path_current_data(struct btrfs_path *path)
static int btrfs_comp_keys_type(const struct btrfs_disk_key *k1, const struct btrfs_disk_key *k2)
static struct btrfs_dir_item * BtrFsMatchDirItemName(struct btrfs_path *path, const char *name, int name_len)
static int prev_slot(struct btrfs_disk_key *key, struct btrfs_path *path)
static const char * skip_current_directories(const char *cur)
static BOOLEAN BtrFsSearchTreeType(PBTRFS_INFO BtrFsInfo, const struct btrfs_root_item *root, u64 objectid, u8 type, struct btrfs_path *path)
const DEVVTBL BtrFsFuncTable
static unsigned long btrfs_chunk_item_size(int num_stripes)
static BOOLEAN verify_dir_item(struct btrfs_dir_item *item, u32 start, u32 total)
int(* cmp_func)(const void *ptr1, const void *ptr2)
#define _strnicmp(_String1, _String2, _MaxCount)
static void cleanup(void)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ HANDLE _In_ ULONG FileNameLength
GLuint GLuint GLsizei count
GLuint GLuint GLsizei GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define memcpy(s1, s2, n)
#define offsetof(TYPE, MEMBER)
struct btrfs_super_block SuperBlock
struct btrfs_root_item FsRoot
struct btrfs_root_item ExtentRoot
struct btrfs_chunk_map ChunkMap
struct btrfs_chunk_map_item * map
struct btrfs_inode_item inode
CHAR FileName[RTL_FIELD_SIZE(FILEINFORMATION, FileName)]
uint8_t sys_chunk_array[SYS_CHUNK_ARRAY_SIZE]
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
struct btrfs_header header
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList