2017-09-08 08:02:43 +00:00
|
|
|
/* Copyright (c) Mark Harmstone 2016-17
|
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* This file is part of WinBtrfs.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* WinBtrfs is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public Licence as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the Licence, or
|
|
|
|
* (at your option) any later version.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* WinBtrfs 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 Lesser General Public Licence for more details.
|
2017-09-08 08:02:43 +00:00
|
|
|
*
|
2016-03-23 20:35:05 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public Licence
|
|
|
|
* along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
#pragma once
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
#undef NTDDI_VERSION
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define _WIN32_WINNT 0x0601
|
|
|
|
#define NTDDI_VERSION 0x06020000 // Win 8
|
2016-03-23 20:35:05 +00:00
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
2017-09-08 08:02:43 +00:00
|
|
|
#define _NO_CRT_STDIO_INLINE
|
2016-03-23 20:35:05 +00:00
|
|
|
#endif /* __REACTOS__ */
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4163)
|
|
|
|
#pragma warning(disable:4311)
|
|
|
|
#pragma warning(disable:4312)
|
|
|
|
#else
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
|
|
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#include <ntifs.h>
|
|
|
|
#include <ntddk.h>
|
|
|
|
#ifdef __REACTOS__
|
|
|
|
#include <ntdddisk.h>
|
|
|
|
#endif /* __REACTOS__ */
|
|
|
|
#include <mountmgr.h>
|
|
|
|
#ifdef __REACTOS__
|
|
|
|
#include <rtlfuncs.h>
|
|
|
|
#include <iotypes.h>
|
2016-05-05 17:26:47 +00:00
|
|
|
#include <pseh/pseh2.h>
|
2016-03-23 20:35:05 +00:00
|
|
|
#endif /* __REACTOS__ */
|
|
|
|
#include <windef.h>
|
|
|
|
#include <wdm.h>
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#else
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2019-09-01 12:53:20 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2016-03-23 20:35:05 +00:00
|
|
|
#include "btrfs.h"
|
2017-01-01 17:12:12 +00:00
|
|
|
#include "btrfsioctl.h"
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2019-09-06 06:56:26 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
C_ASSERT(sizeof(bool) == 1);
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
// #define DEBUG_FCB_REFCOUNTS
|
|
|
|
// #define DEBUG_LONG_MESSAGES
|
2016-10-29 17:05:10 +00:00
|
|
|
// #define DEBUG_FLUSH_TIMES
|
2018-12-16 11:03:16 +00:00
|
|
|
// #define DEBUG_CHUNK_LOCKS
|
2019-09-01 12:53:20 +00:00
|
|
|
// #define DEBUG_TRIM_EMULATION
|
2016-03-23 20:35:05 +00:00
|
|
|
#define DEBUG_PARANOID
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define UNUSED(x) (void)(x)
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#define BTRFS_NODE_TYPE_CCB 0x2295
|
|
|
|
#define BTRFS_NODE_TYPE_FCB 0x2296
|
|
|
|
|
|
|
|
#define ALLOC_TAG 0x7442484D //'MHBt'
|
2016-09-04 15:27:46 +00:00
|
|
|
#define ALLOC_TAG_ZLIB 0x7A42484D //'MHBz'
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
#define UID_NOBODY 65534
|
|
|
|
#define GID_NOBODY 65534
|
|
|
|
|
|
|
|
#define EA_NTACL "security.NTACL"
|
|
|
|
#define EA_NTACL_HASH 0x45922146
|
|
|
|
|
|
|
|
#define EA_DOSATTRIB "user.DOSATTRIB"
|
|
|
|
#define EA_DOSATTRIB_HASH 0x914f9939
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define EA_REPARSE "user.reparse"
|
|
|
|
#define EA_REPARSE_HASH 0xfabad1fe
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
#define EA_EA "user.EA"
|
|
|
|
#define EA_EA_HASH 0x8270dd43
|
|
|
|
|
2019-06-11 10:35:19 +00:00
|
|
|
#define EA_CASE_SENSITIVE "user.casesensitive"
|
|
|
|
#define EA_CASE_SENSITIVE_HASH 0x1a9d97d4
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define EA_PROP_COMPRESSION "btrfs.compression"
|
|
|
|
#define EA_PROP_COMPRESSION_HASH 0x20ccdf69
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
#define MAX_EXTENT_SIZE 0x8000000 // 128 MB
|
2016-09-04 15:27:46 +00:00
|
|
|
#define COMPRESSED_EXTENT_SIZE 0x20000 // 128 KB
|
|
|
|
|
|
|
|
#define READ_AHEAD_GRANULARITY COMPRESSED_EXTENT_SIZE // really ought to be a multiple of COMPRESSED_EXTENT_SIZE
|
2016-07-27 19:24:26 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#ifndef IO_REPARSE_TAG_LX_SYMLINK
|
2016-10-29 17:05:10 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#define IO_REPARSE_TAG_LX_SYMLINK 0xa000001d
|
|
|
|
|
|
|
|
#define IO_REPARSE_TAG_AF_UNIX 0x80000023
|
|
|
|
#define IO_REPARSE_TAG_LX_FIFO 0x80000024
|
|
|
|
#define IO_REPARSE_TAG_LX_CHR 0x80000025
|
|
|
|
#define IO_REPARSE_TAG_LX_BLK 0x80000026
|
|
|
|
|
|
|
|
#endif
|
2018-12-16 11:03:16 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define BTRFS_VOLUME_PREFIX L"\\Device\\Btrfs{"
|
|
|
|
|
2022-04-28 19:35:40 +00:00
|
|
|
#if defined(_MSC_VER) || defined(__clang__)
|
2016-03-23 20:35:05 +00:00
|
|
|
#define try __try
|
|
|
|
#define except __except
|
|
|
|
#define finally __finally
|
2022-04-28 19:33:48 +00:00
|
|
|
#define leave __leave
|
2016-03-23 20:35:05 +00:00
|
|
|
#else
|
|
|
|
#define try if (1)
|
|
|
|
#define except(x) if (0 && (x))
|
|
|
|
#define finally if (1)
|
2022-04-28 19:33:48 +00:00
|
|
|
#define leave
|
2016-03-23 20:35:05 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
#ifndef __REACTOS__
|
2022-04-28 19:33:48 +00:00
|
|
|
#ifndef InterlockedIncrement64
|
2019-11-12 18:32:46 +00:00
|
|
|
#define InterlockedIncrement64(a) __sync_add_and_fetch(a, 1)
|
|
|
|
#endif
|
2020-04-23 02:38:57 +00:00
|
|
|
#endif // __REACTOS__
|
2019-11-12 18:32:46 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifndef FILE_SUPPORTS_BLOCK_REFCOUNTING
|
|
|
|
#define FILE_SUPPORTS_BLOCK_REFCOUNTING 0x08000000
|
|
|
|
#endif
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2019-06-11 10:35:19 +00:00
|
|
|
#ifndef FILE_SUPPORTS_POSIX_UNLINK_RENAME
|
|
|
|
#define FILE_SUPPORTS_POSIX_UNLINK_RENAME 0x00000400
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifndef FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
|
|
|
|
#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000
|
|
|
|
#endif
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
#ifndef _MSC_VER
|
2019-06-11 10:35:19 +00:00
|
|
|
typedef struct _FILE_ID_128 {
|
|
|
|
UCHAR Identifier[16];
|
|
|
|
} FILE_ID_128, *PFILE_ID_128;
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#define FILE_CS_FLAG_CASE_SENSITIVE_DIR 1
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
typedef struct _FILE_ID_128 {
|
|
|
|
UCHAR Identifier[16];
|
|
|
|
} FILE_ID_128, *PFILE_ID_128;
|
|
|
|
|
|
|
|
#define FILE_CS_FLAG_CASE_SENSITIVE_DIR 1
|
|
|
|
#endif // __REACTOS__
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
typedef struct _DUPLICATE_EXTENTS_DATA {
|
|
|
|
HANDLE FileHandle;
|
|
|
|
LARGE_INTEGER SourceFileOffset;
|
|
|
|
LARGE_INTEGER TargetFileOffset;
|
|
|
|
LARGE_INTEGER ByteCount;
|
|
|
|
} DUPLICATE_EXTENTS_DATA, *PDUPLICATE_EXTENTS_DATA;
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 209, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
|
|
|
|
|
|
|
typedef struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER {
|
|
|
|
WORD ChecksumAlgorithm;
|
|
|
|
WORD Reserved;
|
|
|
|
DWORD Flags;
|
|
|
|
DWORD ChecksumChunkSizeInBytes;
|
|
|
|
DWORD ClusterSizeInBytes;
|
|
|
|
} FSCTL_GET_INTEGRITY_INFORMATION_BUFFER, *PFSCTL_GET_INTEGRITY_INFORMATION_BUFFER;
|
|
|
|
|
|
|
|
typedef struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER {
|
|
|
|
WORD ChecksumAlgorithm;
|
|
|
|
WORD Reserved;
|
|
|
|
DWORD Flags;
|
|
|
|
} FSCTL_SET_INTEGRITY_INFORMATION_BUFFER, *PFSCTL_SET_INTEGRITY_INFORMATION_BUFFER;
|
|
|
|
|
|
|
|
#define FSCTL_GET_INTEGRITY_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 159, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
|
|
#define FSCTL_SET_INTEGRITY_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 160, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
#define __drv_aliasesMem
|
|
|
|
#define _Dispatch_type_(a)
|
|
|
|
#define _Lock_level_order_(a,b)
|
|
|
|
#endif
|
2020-04-23 02:38:57 +00:00
|
|
|
#endif // __REACTOS__
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Create_lock_level_(tree_lock)
|
|
|
|
_Create_lock_level_(fcb_lock)
|
|
|
|
_Lock_level_order_(tree_lock, fcb_lock)
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#define MAX_HASH_SIZE 32
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
struct _device_extension;
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct _fcb_nonpaged {
|
|
|
|
FAST_MUTEX HeaderMutex;
|
|
|
|
SECTION_OBJECT_POINTERS segment_object;
|
|
|
|
ERESOURCE resource;
|
|
|
|
ERESOURCE paging_resource;
|
2017-01-01 17:12:12 +00:00
|
|
|
ERESOURCE dir_children_lock;
|
2016-03-23 20:35:05 +00:00
|
|
|
} fcb_nonpaged;
|
|
|
|
|
|
|
|
struct _root;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t offset;
|
|
|
|
uint16_t datalen;
|
|
|
|
bool unique;
|
|
|
|
bool ignore;
|
|
|
|
bool inserted;
|
2020-04-23 02:38:57 +00:00
|
|
|
void* csum;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
EXTENT_DATA extent_data;
|
2016-07-27 19:24:26 +00:00
|
|
|
} extent;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t parent;
|
|
|
|
uint64_t index;
|
2016-07-27 19:24:26 +00:00
|
|
|
UNICODE_STRING name;
|
|
|
|
ANSI_STRING utf8;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} hardlink;
|
|
|
|
|
|
|
|
struct _file_ref;
|
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
typedef struct {
|
|
|
|
KEY key;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t index;
|
|
|
|
uint8_t type;
|
2017-01-01 17:12:12 +00:00
|
|
|
ANSI_STRING utf8;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t hash;
|
2017-01-01 17:12:12 +00:00
|
|
|
UNICODE_STRING name;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t hash_uc;
|
2017-01-01 17:12:12 +00:00
|
|
|
UNICODE_STRING name_uc;
|
2017-09-08 08:02:43 +00:00
|
|
|
ULONG size;
|
2017-01-01 17:12:12 +00:00
|
|
|
struct _file_ref* fileref;
|
2019-11-12 18:32:46 +00:00
|
|
|
bool root_dir;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY list_entry_index;
|
|
|
|
LIST_ENTRY list_entry_hash;
|
|
|
|
LIST_ENTRY list_entry_hash_uc;
|
|
|
|
} dir_child;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
enum prop_compression_type {
|
|
|
|
PropCompression_None,
|
|
|
|
PropCompression_Zlib,
|
2018-12-16 11:03:16 +00:00
|
|
|
PropCompression_LZO,
|
|
|
|
PropCompression_ZSTD
|
2017-09-08 08:02:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
USHORT namelen;
|
|
|
|
USHORT valuelen;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool dirty;
|
2017-09-08 08:02:43 +00:00
|
|
|
char data[1];
|
|
|
|
} xattr;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct _fcb {
|
|
|
|
FSRTL_ADVANCED_FCB_HEADER Header;
|
|
|
|
struct _fcb_nonpaged* nonpaged;
|
|
|
|
LONG refcount;
|
2017-09-08 08:02:43 +00:00
|
|
|
POOL_TYPE pool_type;
|
2016-03-23 20:35:05 +00:00
|
|
|
struct _device_extension* Vcb;
|
|
|
|
struct _root* subvol;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t inode;
|
|
|
|
uint32_t hash;
|
|
|
|
uint8_t type;
|
2016-03-23 20:35:05 +00:00
|
|
|
INODE_ITEM inode_item;
|
|
|
|
SECURITY_DESCRIPTOR* sd;
|
|
|
|
FILE_LOCK lock;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool deleted;
|
2016-03-23 20:35:05 +00:00
|
|
|
PKTHREAD lazy_writer_thread;
|
|
|
|
ULONG atts;
|
|
|
|
SHARE_ACCESS share_access;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool csum_loaded;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY extents;
|
|
|
|
ANSI_STRING reparse_xattr;
|
2016-10-29 17:05:10 +00:00
|
|
|
ANSI_STRING ea_xattr;
|
|
|
|
ULONG ealen;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY hardlinks;
|
|
|
|
struct _file_ref* fileref;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool inode_item_changed;
|
2017-09-08 08:02:43 +00:00
|
|
|
enum prop_compression_type prop_compression;
|
|
|
|
LIST_ENTRY xattrs;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool marked_as_orphan;
|
|
|
|
bool case_sensitive;
|
|
|
|
bool case_sensitive_set;
|
2019-11-12 18:32:46 +00:00
|
|
|
OPLOCK oplock;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY dir_children_index;
|
|
|
|
LIST_ENTRY dir_children_hash;
|
|
|
|
LIST_ENTRY dir_children_hash_uc;
|
|
|
|
LIST_ENTRY** hash_ptrs;
|
|
|
|
LIST_ENTRY** hash_ptrs_uc;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
bool dirty;
|
|
|
|
bool sd_dirty, sd_deleted;
|
|
|
|
bool atts_changed, atts_deleted;
|
|
|
|
bool extents_changed;
|
|
|
|
bool reparse_xattr_changed;
|
|
|
|
bool ea_changed;
|
|
|
|
bool prop_compression_changed;
|
|
|
|
bool xattrs_changed;
|
|
|
|
bool created;
|
|
|
|
|
|
|
|
bool ads;
|
|
|
|
uint32_t adshash;
|
2016-09-04 15:27:46 +00:00
|
|
|
ULONG adsmaxlen;
|
2016-03-23 20:35:05 +00:00
|
|
|
ANSI_STRING adsxattr;
|
2016-07-27 19:24:26 +00:00
|
|
|
ANSI_STRING adsdata;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY list_entry_all;
|
2017-09-08 08:02:43 +00:00
|
|
|
LIST_ENTRY list_entry_dirty;
|
2016-03-23 20:35:05 +00:00
|
|
|
} fcb;
|
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
typedef struct _file_ref {
|
|
|
|
fcb* fcb;
|
2016-07-27 19:24:26 +00:00
|
|
|
ANSI_STRING oldutf8;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t oldindex;
|
|
|
|
bool delete_on_close;
|
|
|
|
bool posix_delete;
|
|
|
|
bool deleted;
|
|
|
|
bool created;
|
2016-05-05 17:26:47 +00:00
|
|
|
LIST_ENTRY children;
|
|
|
|
LONG refcount;
|
2016-10-29 17:05:10 +00:00
|
|
|
LONG open_count;
|
2016-05-05 17:26:47 +00:00
|
|
|
struct _file_ref* parent;
|
2017-01-01 17:12:12 +00:00
|
|
|
dir_child* dc;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
bool dirty;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2017-09-08 08:02:43 +00:00
|
|
|
LIST_ENTRY list_entry_dirty;
|
2016-05-05 17:26:47 +00:00
|
|
|
} file_ref;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
typedef struct {
|
2017-09-08 08:02:43 +00:00
|
|
|
HANDLE thread;
|
|
|
|
struct _ccb* ccb;
|
|
|
|
void* context;
|
|
|
|
KEVENT cleared_event;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool cancelling;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2017-09-08 08:02:43 +00:00
|
|
|
} send_info;
|
2016-07-27 19:24:26 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct _ccb {
|
|
|
|
USHORT NodeType;
|
|
|
|
CSHORT NodeSize;
|
|
|
|
ULONG disposition;
|
|
|
|
ULONG options;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t query_dir_offset;
|
2016-03-23 20:35:05 +00:00
|
|
|
UNICODE_STRING query_string;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool has_wildcard;
|
|
|
|
bool specific_file;
|
|
|
|
bool manage_volume_privilege;
|
|
|
|
bool allow_extended_dasd_io;
|
|
|
|
bool reserving;
|
2016-05-05 17:26:47 +00:00
|
|
|
ACCESS_MASK access;
|
|
|
|
file_ref* fileref;
|
2016-07-27 19:24:26 +00:00
|
|
|
UNICODE_STRING filename;
|
2016-10-29 17:05:10 +00:00
|
|
|
ULONG ea_index;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool case_sensitive;
|
|
|
|
bool user_set_creation_time;
|
|
|
|
bool user_set_access_time;
|
|
|
|
bool user_set_write_time;
|
|
|
|
bool user_set_change_time;
|
|
|
|
bool lxss;
|
2017-09-08 08:02:43 +00:00
|
|
|
send_info* send;
|
|
|
|
NTSTATUS send_status;
|
2016-03-23 20:35:05 +00:00
|
|
|
} ccb;
|
|
|
|
|
|
|
|
struct _device_extension;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
|
|
|
uint64_t generation;
|
2016-03-23 20:35:05 +00:00
|
|
|
struct _tree* tree;
|
|
|
|
} tree_holder;
|
|
|
|
|
|
|
|
typedef struct _tree_data {
|
|
|
|
KEY key;
|
|
|
|
LIST_ENTRY list_entry;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool ignore;
|
|
|
|
bool inserted;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
union {
|
|
|
|
tree_holder treeholder;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint16_t size;
|
|
|
|
uint8_t* data;
|
2016-03-23 20:35:05 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
} tree_data;
|
|
|
|
|
2019-05-11 09:20:02 +00:00
|
|
|
typedef struct {
|
|
|
|
FAST_MUTEX mutex;
|
|
|
|
} tree_nonpaged;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct _tree {
|
2019-05-11 09:20:02 +00:00
|
|
|
tree_nonpaged* nonpaged;
|
2016-03-23 20:35:05 +00:00
|
|
|
tree_header header;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t hash;
|
|
|
|
bool has_address;
|
|
|
|
uint32_t size;
|
2016-03-23 20:35:05 +00:00
|
|
|
struct _device_extension* Vcb;
|
|
|
|
struct _tree* parent;
|
|
|
|
tree_data* paritem;
|
|
|
|
struct _root* root;
|
|
|
|
LIST_ENTRY itemlist;
|
|
|
|
LIST_ENTRY list_entry;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY list_entry_hash;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t new_address;
|
|
|
|
bool has_new_address;
|
|
|
|
bool updated_extents;
|
|
|
|
bool write;
|
|
|
|
bool is_unique;
|
|
|
|
bool uniqueness_determined;
|
|
|
|
uint8_t* buf;
|
2016-03-23 20:35:05 +00:00
|
|
|
} tree;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ERESOURCE load_tree_lock;
|
|
|
|
} root_nonpaged;
|
|
|
|
|
|
|
|
typedef struct _root {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t id;
|
2016-10-29 17:05:10 +00:00
|
|
|
LONGLONG lastinode; // signed so we can use InterlockedIncrement64
|
2016-03-23 20:35:05 +00:00
|
|
|
tree_holder treeholder;
|
|
|
|
root_nonpaged* nonpaged;
|
|
|
|
ROOT_ITEM root_item;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool dirty;
|
|
|
|
bool received;
|
2017-09-08 08:02:43 +00:00
|
|
|
PEPROCESS reserved;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t parent;
|
2017-09-08 08:02:43 +00:00
|
|
|
LONG send_ops;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t fcbs_version;
|
|
|
|
bool checked_for_orphans;
|
2020-04-23 02:38:57 +00:00
|
|
|
bool dropped;
|
2016-05-05 17:26:47 +00:00
|
|
|
LIST_ENTRY fcbs;
|
2019-05-11 09:20:02 +00:00
|
|
|
LIST_ENTRY* fcbs_ptrs[256];
|
2016-05-05 17:26:47 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2017-09-08 08:02:43 +00:00
|
|
|
LIST_ENTRY list_entry_dirty;
|
2016-03-23 20:35:05 +00:00
|
|
|
} root;
|
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
enum batch_operation {
|
2017-01-01 17:12:12 +00:00
|
|
|
Batch_Delete,
|
|
|
|
Batch_DeleteInode,
|
|
|
|
Batch_DeleteDirItem,
|
|
|
|
Batch_DeleteInodeRef,
|
|
|
|
Batch_DeleteInodeExtRef,
|
2017-09-08 08:02:43 +00:00
|
|
|
Batch_DeleteXattr,
|
|
|
|
Batch_DeleteExtentData,
|
|
|
|
Batch_DeleteFreeSpace,
|
2018-05-26 08:44:36 +00:00
|
|
|
Batch_Insert,
|
|
|
|
Batch_SetXattr,
|
|
|
|
Batch_DirItem,
|
|
|
|
Batch_InodeRef,
|
|
|
|
Batch_InodeExtRef,
|
2016-10-29 17:05:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
KEY key;
|
|
|
|
void* data;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint16_t datalen;
|
2016-10-29 17:05:10 +00:00
|
|
|
enum batch_operation operation;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} batch_item;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-09-28 16:08:10 +00:00
|
|
|
KEY key;
|
2016-10-29 17:05:10 +00:00
|
|
|
LIST_ENTRY items;
|
2022-09-28 16:08:10 +00:00
|
|
|
unsigned int num_items;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} batch_item_ind;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
root* r;
|
|
|
|
LIST_ENTRY items_ind;
|
2016-10-29 17:05:10 +00:00
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} batch_root;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct {
|
|
|
|
tree* tree;
|
|
|
|
tree_data* item;
|
|
|
|
} traverse_ptr;
|
|
|
|
|
|
|
|
typedef struct _root_cache {
|
|
|
|
root* root;
|
|
|
|
struct _root_cache* next;
|
|
|
|
} root_cache;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
|
|
|
uint64_t size;
|
2016-03-23 20:35:05 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY list_entry_size;
|
2016-03-23 20:35:05 +00:00
|
|
|
} space;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PDEVICE_OBJECT devobj;
|
2019-09-01 12:53:20 +00:00
|
|
|
PFILE_OBJECT fileobj;
|
2016-03-23 20:35:05 +00:00
|
|
|
DEV_ITEM devitem;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool removable;
|
|
|
|
bool seeding;
|
|
|
|
bool readonly;
|
|
|
|
bool reloc;
|
|
|
|
bool trim;
|
|
|
|
bool can_flush;
|
2016-05-05 17:26:47 +00:00
|
|
|
ULONG change_count;
|
2017-01-01 17:12:12 +00:00
|
|
|
ULONG disk_num;
|
|
|
|
ULONG part_num;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t stats[5];
|
|
|
|
bool stats_changed;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY space;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2017-09-08 08:02:43 +00:00
|
|
|
ULONG num_trim_entries;
|
|
|
|
LIST_ENTRY trim_list;
|
2016-03-23 20:35:05 +00:00
|
|
|
} device;
|
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t start;
|
|
|
|
uint64_t length;
|
2016-10-29 17:05:10 +00:00
|
|
|
PETHREAD thread;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} range_lock;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
2017-09-08 08:02:43 +00:00
|
|
|
ULONG* bmparr;
|
2019-09-01 12:53:20 +00:00
|
|
|
ULONG bmplen;
|
2017-09-08 08:02:43 +00:00
|
|
|
RTL_BITMAP bmp;
|
|
|
|
LIST_ENTRY list_entry;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint8_t data[1];
|
2017-09-08 08:02:43 +00:00
|
|
|
} partial_stripe;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct {
|
|
|
|
CHUNK_ITEM* chunk_item;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint16_t size;
|
|
|
|
uint64_t offset;
|
|
|
|
uint64_t used;
|
|
|
|
uint64_t oldused;
|
2016-03-23 20:35:05 +00:00
|
|
|
device** devices;
|
2016-07-27 19:24:26 +00:00
|
|
|
fcb* cache;
|
2017-09-08 08:02:43 +00:00
|
|
|
fcb* old_cache;
|
2016-03-23 20:35:05 +00:00
|
|
|
LIST_ENTRY space;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY space_size;
|
|
|
|
LIST_ENTRY deleting;
|
|
|
|
LIST_ENTRY changed_extents;
|
2016-10-29 17:05:10 +00:00
|
|
|
LIST_ENTRY range_locks;
|
2017-09-08 08:02:43 +00:00
|
|
|
ERESOURCE range_locks_lock;
|
2016-10-29 17:05:10 +00:00
|
|
|
KEVENT range_locks_event;
|
2016-09-04 15:27:46 +00:00
|
|
|
ERESOURCE lock;
|
|
|
|
ERESOURCE changed_extents_lock;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool created;
|
|
|
|
bool readonly;
|
|
|
|
bool reloc;
|
|
|
|
bool last_alloc_set;
|
|
|
|
bool cache_loaded;
|
|
|
|
bool changed;
|
|
|
|
bool space_changed;
|
|
|
|
uint64_t last_alloc;
|
|
|
|
uint16_t last_stripe;
|
2017-09-08 08:02:43 +00:00
|
|
|
LIST_ENTRY partial_stripes;
|
|
|
|
ERESOURCE partial_stripes_lock;
|
|
|
|
ULONG balance_num;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY list_entry_balance;
|
2016-03-23 20:35:05 +00:00
|
|
|
} chunk;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
|
|
|
uint64_t size;
|
|
|
|
uint64_t old_size;
|
|
|
|
uint64_t count;
|
|
|
|
uint64_t old_count;
|
|
|
|
bool no_csum;
|
|
|
|
bool superseded;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY refs;
|
|
|
|
LIST_ENTRY old_refs;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} changed_extent;
|
|
|
|
|
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint8_t type;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
union {
|
|
|
|
EXTENT_DATA_REF edr;
|
|
|
|
SHARED_DATA_REF sdr;
|
|
|
|
};
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} changed_extent_ref;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct {
|
|
|
|
KEY key;
|
|
|
|
void* data;
|
|
|
|
USHORT size;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} sys_chunk;
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
enum calc_thread_type {
|
|
|
|
calc_thread_crc32c,
|
|
|
|
calc_thread_xxhash,
|
|
|
|
calc_thread_sha256,
|
|
|
|
calc_thread_blake2,
|
|
|
|
calc_thread_decomp_zlib,
|
|
|
|
calc_thread_decomp_lzo,
|
|
|
|
calc_thread_decomp_zstd,
|
|
|
|
calc_thread_comp_zlib,
|
|
|
|
calc_thread_comp_lzo,
|
|
|
|
calc_thread_comp_zstd,
|
|
|
|
};
|
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
typedef struct {
|
|
|
|
LIST_ENTRY list_entry;
|
2020-04-23 02:38:57 +00:00
|
|
|
void* in;
|
|
|
|
void* out;
|
|
|
|
unsigned int inlen, outlen, off, space_left;
|
|
|
|
LONG left, not_started;
|
|
|
|
KEVENT event;
|
|
|
|
enum calc_thread_type type;
|
|
|
|
NTSTATUS Status;
|
2017-01-01 17:12:12 +00:00
|
|
|
} calc_job;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
HANDLE handle;
|
|
|
|
KEVENT finished;
|
2020-04-23 02:38:57 +00:00
|
|
|
unsigned int number;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool quit;
|
2017-01-01 17:12:12 +00:00
|
|
|
} drv_calc_thread;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ULONG num_threads;
|
|
|
|
LIST_ENTRY job_list;
|
2020-04-23 02:38:57 +00:00
|
|
|
KSPIN_LOCK spinlock;
|
2017-01-01 17:12:12 +00:00
|
|
|
drv_calc_thread* threads;
|
|
|
|
KEVENT event;
|
|
|
|
} drv_calc_threads;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
bool ignore;
|
|
|
|
bool compress;
|
|
|
|
bool compress_force;
|
|
|
|
uint8_t compress_type;
|
|
|
|
bool readonly;
|
|
|
|
uint32_t zlib_level;
|
|
|
|
uint32_t zstd_level;
|
|
|
|
uint32_t flush_interval;
|
|
|
|
uint32_t max_inline;
|
|
|
|
uint64_t subvol_id;
|
|
|
|
bool skip_balance;
|
|
|
|
bool no_barrier;
|
|
|
|
bool no_trim;
|
|
|
|
bool clear_cache;
|
|
|
|
bool allow_degraded;
|
2019-11-12 18:32:46 +00:00
|
|
|
bool no_root_dir;
|
2022-09-28 16:08:10 +00:00
|
|
|
bool nodatacow;
|
2016-07-27 19:24:26 +00:00
|
|
|
} mount_options;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define VCB_TYPE_FS 1
|
|
|
|
#define VCB_TYPE_CONTROL 2
|
|
|
|
#define VCB_TYPE_VOLUME 3
|
|
|
|
#define VCB_TYPE_PDO 4
|
2019-09-01 12:53:20 +00:00
|
|
|
#define VCB_TYPE_BUS 5
|
2016-10-29 17:05:10 +00:00
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
#define BALANCE_OPTS_DATA 0
|
|
|
|
#define BALANCE_OPTS_METADATA 1
|
|
|
|
#define BALANCE_OPTS_SYSTEM 2
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
HANDLE thread;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t total_chunks;
|
|
|
|
uint64_t chunks_left;
|
2017-01-01 17:12:12 +00:00
|
|
|
btrfs_balance_opts opts[3];
|
2019-09-01 12:53:20 +00:00
|
|
|
bool paused;
|
|
|
|
bool stopping;
|
|
|
|
bool removing;
|
|
|
|
bool shrinking;
|
|
|
|
bool dev_readonly;
|
2017-09-08 08:02:43 +00:00
|
|
|
ULONG balance_num;
|
2017-01-01 17:12:12 +00:00
|
|
|
NTSTATUS status;
|
|
|
|
KEVENT event;
|
|
|
|
KEVENT finished;
|
|
|
|
} balance_info;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
|
|
|
uint64_t device;
|
|
|
|
bool recovered;
|
|
|
|
bool is_metadata;
|
|
|
|
bool parity;
|
2017-09-08 08:02:43 +00:00
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t subvol;
|
|
|
|
uint64_t offset;
|
|
|
|
uint16_t filename_length;
|
2017-09-08 08:02:43 +00:00
|
|
|
WCHAR filename[1];
|
|
|
|
} data;
|
|
|
|
|
|
|
|
struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t root;
|
|
|
|
uint8_t level;
|
2017-09-08 08:02:43 +00:00
|
|
|
KEY firstitem;
|
|
|
|
} metadata;
|
|
|
|
};
|
|
|
|
} scrub_error;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
HANDLE thread;
|
|
|
|
ERESOURCE stats_lock;
|
|
|
|
KEVENT event;
|
|
|
|
KEVENT finished;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool stopping;
|
|
|
|
bool paused;
|
2017-09-08 08:02:43 +00:00
|
|
|
LARGE_INTEGER start_time;
|
|
|
|
LARGE_INTEGER finish_time;
|
|
|
|
LARGE_INTEGER resume_time;
|
|
|
|
LARGE_INTEGER duration;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t total_chunks;
|
|
|
|
uint64_t chunks_left;
|
|
|
|
uint64_t data_scrubbed;
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS error;
|
|
|
|
ULONG num_errors;
|
|
|
|
LIST_ENTRY errors;
|
|
|
|
} scrub_info;
|
|
|
|
|
|
|
|
struct _volume_device_extension;
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct _device_extension {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t type;
|
2016-07-27 19:24:26 +00:00
|
|
|
mount_options options;
|
|
|
|
PVPB Vpb;
|
2019-11-12 18:32:46 +00:00
|
|
|
PDEVICE_OBJECT devobj;
|
2017-09-08 08:02:43 +00:00
|
|
|
struct _volume_device_extension* vde;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY devices;
|
2018-12-16 11:03:16 +00:00
|
|
|
#ifdef DEBUG_CHUNK_LOCKS
|
|
|
|
LONG chunk_locks_held;
|
2016-10-29 17:05:10 +00:00
|
|
|
#endif
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t devices_loaded;
|
2016-03-23 20:35:05 +00:00
|
|
|
superblock superblock;
|
2022-04-28 19:31:44 +00:00
|
|
|
unsigned int sector_shift;
|
2020-04-23 02:38:57 +00:00
|
|
|
unsigned int csum_size;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool readonly;
|
|
|
|
bool removing;
|
|
|
|
bool locked;
|
|
|
|
bool lock_paused_balance;
|
|
|
|
bool disallow_dismount;
|
|
|
|
LONG page_file_count;
|
|
|
|
bool trim;
|
2016-07-27 19:24:26 +00:00
|
|
|
PFILE_OBJECT locked_fileobj;
|
2016-03-23 20:35:05 +00:00
|
|
|
fcb* volume_fcb;
|
2017-09-08 08:02:43 +00:00
|
|
|
fcb* dummy_fcb;
|
2016-05-05 17:26:47 +00:00
|
|
|
file_ref* root_fileref;
|
2016-10-29 17:05:10 +00:00
|
|
|
LONG open_files;
|
2017-09-08 08:02:43 +00:00
|
|
|
_Has_lock_level_(fcb_lock) ERESOURCE fcb_lock;
|
2019-05-11 09:20:02 +00:00
|
|
|
ERESOURCE fileref_lock;
|
2016-03-23 20:35:05 +00:00
|
|
|
ERESOURCE load_lock;
|
2017-09-08 08:02:43 +00:00
|
|
|
_Has_lock_level_(tree_lock) ERESOURCE tree_lock;
|
2016-03-23 20:35:05 +00:00
|
|
|
PNOTIFY_SYNC NotifySync;
|
|
|
|
LIST_ENTRY DirNotifyList;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool need_write;
|
|
|
|
bool stats_changed;
|
|
|
|
uint64_t data_flags;
|
|
|
|
uint64_t metadata_flags;
|
|
|
|
uint64_t system_flags;
|
2016-05-05 17:26:47 +00:00
|
|
|
LIST_ENTRY roots;
|
|
|
|
LIST_ENTRY drop_roots;
|
2016-03-23 20:35:05 +00:00
|
|
|
root* chunk_root;
|
|
|
|
root* root_root;
|
|
|
|
root* extent_root;
|
|
|
|
root* checksum_root;
|
|
|
|
root* dev_root;
|
2016-05-05 17:26:47 +00:00
|
|
|
root* uuid_root;
|
2016-10-29 17:05:10 +00:00
|
|
|
root* data_reloc_root;
|
2017-09-08 08:02:43 +00:00
|
|
|
root* space_root;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool log_to_phys_loaded;
|
|
|
|
bool chunk_usage_found;
|
2016-03-23 20:35:05 +00:00
|
|
|
LIST_ENTRY sys_chunks;
|
|
|
|
LIST_ENTRY chunks;
|
|
|
|
LIST_ENTRY trees;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY trees_hash;
|
|
|
|
LIST_ENTRY* trees_ptrs[256];
|
2019-05-11 09:20:02 +00:00
|
|
|
FAST_MUTEX trees_list_mutex;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY all_fcbs;
|
|
|
|
LIST_ENTRY dirty_fcbs;
|
2017-09-08 08:02:43 +00:00
|
|
|
ERESOURCE dirty_fcbs_lock;
|
2016-07-27 19:24:26 +00:00
|
|
|
LIST_ENTRY dirty_filerefs;
|
2017-09-08 08:02:43 +00:00
|
|
|
ERESOURCE dirty_filerefs_lock;
|
|
|
|
LIST_ENTRY dirty_subvols;
|
|
|
|
ERESOURCE dirty_subvols_lock;
|
2016-07-27 19:24:26 +00:00
|
|
|
ERESOURCE chunk_lock;
|
2016-03-23 20:35:05 +00:00
|
|
|
HANDLE flush_thread_handle;
|
2016-07-27 19:24:26 +00:00
|
|
|
KTIMER flush_thread_timer;
|
|
|
|
KEVENT flush_thread_finished;
|
2017-01-01 17:12:12 +00:00
|
|
|
drv_calc_threads calcthreads;
|
|
|
|
balance_info balance;
|
2017-09-08 08:02:43 +00:00
|
|
|
scrub_info scrub;
|
|
|
|
ERESOURCE send_load_lock;
|
|
|
|
LONG running_sends;
|
|
|
|
LIST_ENTRY send_ops;
|
2016-07-27 19:24:26 +00:00
|
|
|
PFILE_OBJECT root_file;
|
2016-10-29 17:05:10 +00:00
|
|
|
PAGED_LOOKASIDE_LIST tree_data_lookaside;
|
|
|
|
PAGED_LOOKASIDE_LIST traverse_ptr_lookaside;
|
|
|
|
PAGED_LOOKASIDE_LIST batch_item_lookaside;
|
2017-09-08 08:02:43 +00:00
|
|
|
PAGED_LOOKASIDE_LIST fileref_lookaside;
|
|
|
|
PAGED_LOOKASIDE_LIST fcb_lookaside;
|
|
|
|
PAGED_LOOKASIDE_LIST name_bit_lookaside;
|
2016-10-29 17:05:10 +00:00
|
|
|
NPAGED_LOOKASIDE_LIST range_lock_lookaside;
|
2017-09-08 08:02:43 +00:00
|
|
|
NPAGED_LOOKASIDE_LIST fcb_np_lookaside;
|
2016-03-23 20:35:05 +00:00
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} device_extension;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t type;
|
|
|
|
} control_device_extension;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t type;
|
2017-09-08 08:02:43 +00:00
|
|
|
PDEVICE_OBJECT buspdo;
|
|
|
|
PDEVICE_OBJECT attached_device;
|
|
|
|
UNICODE_STRING bus_name;
|
2019-09-01 12:53:20 +00:00
|
|
|
} bus_device_extension;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2016-07-27 19:24:26 +00:00
|
|
|
BTRFS_UUID uuid;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t devid;
|
|
|
|
uint64_t generation;
|
2017-09-08 08:02:43 +00:00
|
|
|
PDEVICE_OBJECT devobj;
|
|
|
|
PFILE_OBJECT fileobj;
|
|
|
|
UNICODE_STRING pnp_name;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t size;
|
|
|
|
bool seeding;
|
|
|
|
bool had_drive_letter;
|
2017-09-08 08:02:43 +00:00
|
|
|
void* notification_entry;
|
|
|
|
ULONG disk_num;
|
|
|
|
ULONG part_num;
|
2020-04-23 02:38:57 +00:00
|
|
|
bool boot_volume;
|
2017-09-08 08:02:43 +00:00
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} volume_child;
|
|
|
|
|
|
|
|
struct pdo_device_extension;
|
|
|
|
|
|
|
|
typedef struct _volume_device_extension {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t type;
|
2016-07-27 19:24:26 +00:00
|
|
|
UNICODE_STRING name;
|
2017-09-08 08:02:43 +00:00
|
|
|
PDEVICE_OBJECT device;
|
|
|
|
PDEVICE_OBJECT mounted_device;
|
|
|
|
PDEVICE_OBJECT pdo;
|
|
|
|
struct pdo_device_extension* pdode;
|
|
|
|
UNICODE_STRING bus_name;
|
|
|
|
PDEVICE_OBJECT attached_device;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool removing;
|
2019-11-12 18:32:46 +00:00
|
|
|
bool dead;
|
2017-09-08 08:02:43 +00:00
|
|
|
LONG open_count;
|
|
|
|
} volume_device_extension;
|
2016-07-27 19:24:26 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
typedef struct pdo_device_extension {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t type;
|
2017-09-08 08:02:43 +00:00
|
|
|
BTRFS_UUID uuid;
|
|
|
|
volume_device_extension* vde;
|
|
|
|
PDEVICE_OBJECT pdo;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool removable;
|
2019-11-12 18:32:46 +00:00
|
|
|
bool dont_report;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t num_children;
|
|
|
|
uint64_t children_loaded;
|
2017-09-08 08:02:43 +00:00
|
|
|
ERESOURCE child_lock;
|
|
|
|
LIST_ENTRY children;
|
|
|
|
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} pdo_device_extension;
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
typedef struct {
|
|
|
|
LIST_ENTRY listentry;
|
|
|
|
PSID sid;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t uid;
|
2016-03-23 20:35:05 +00:00
|
|
|
} uid_map;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
typedef struct {
|
|
|
|
LIST_ENTRY listentry;
|
|
|
|
PSID sid;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint32_t gid;
|
2017-09-08 08:02:43 +00:00
|
|
|
} gid_map;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
enum write_data_status {
|
|
|
|
WriteDataStatus_Pending,
|
|
|
|
WriteDataStatus_Success,
|
|
|
|
WriteDataStatus_Error,
|
|
|
|
WriteDataStatus_Cancelling,
|
|
|
|
WriteDataStatus_Cancelled,
|
|
|
|
WriteDataStatus_Ignore
|
2016-05-05 17:26:47 +00:00
|
|
|
};
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
struct _write_data_context;
|
2016-05-05 17:26:47 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2016-09-04 15:27:46 +00:00
|
|
|
struct _write_data_context* context;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint8_t* buf;
|
2017-09-08 08:02:43 +00:00
|
|
|
PMDL mdl;
|
2016-05-05 17:26:47 +00:00
|
|
|
device* device;
|
|
|
|
PIRP Irp;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
2016-07-27 19:24:26 +00:00
|
|
|
enum write_data_status status;
|
2016-05-05 17:26:47 +00:00
|
|
|
LIST_ENTRY list_entry;
|
2016-07-27 19:24:26 +00:00
|
|
|
} write_data_stripe;
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
typedef struct _write_data_context {
|
2016-05-05 17:26:47 +00:00
|
|
|
KEVENT Event;
|
|
|
|
LIST_ENTRY stripes;
|
2016-07-27 19:24:26 +00:00
|
|
|
LONG stripes_left;
|
2019-09-01 12:53:20 +00:00
|
|
|
bool need_wait;
|
|
|
|
uint8_t *parity1, *parity2, *scratch;
|
2017-09-08 08:02:43 +00:00
|
|
|
PMDL mdl, parity1_mdl, parity2_mdl;
|
2016-07-27 19:24:26 +00:00
|
|
|
} write_data_context;
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
typedef struct {
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
|
|
|
uint32_t length;
|
|
|
|
uint8_t* data;
|
2017-09-08 08:02:43 +00:00
|
|
|
chunk* c;
|
2019-11-12 18:32:46 +00:00
|
|
|
bool allocated;
|
2017-01-01 17:12:12 +00:00
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} tree_write;
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
typedef struct {
|
|
|
|
UNICODE_STRING us;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} name_bit;
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2017-10-16 18:05:33 +00:00
|
|
|
_Requires_lock_not_held_(Vcb->fcb_lock)
|
|
|
|
_Acquires_shared_lock_(Vcb->fcb_lock)
|
|
|
|
static __inline void acquire_fcb_lock_shared(device_extension* Vcb) {
|
2019-09-01 12:53:20 +00:00
|
|
|
ExAcquireResourceSharedLite(&Vcb->fcb_lock, true);
|
2017-10-16 18:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Requires_lock_not_held_(Vcb->fcb_lock)
|
|
|
|
_Acquires_exclusive_lock_(Vcb->fcb_lock)
|
|
|
|
static __inline void acquire_fcb_lock_exclusive(device_extension* Vcb) {
|
2019-09-01 12:53:20 +00:00
|
|
|
ExAcquireResourceExclusiveLite(&Vcb->fcb_lock, true);
|
2017-10-16 18:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Requires_lock_held_(Vcb->fcb_lock)
|
|
|
|
_Releases_lock_(Vcb->fcb_lock)
|
|
|
|
static __inline void release_fcb_lock(device_extension* Vcb) {
|
|
|
|
ExReleaseResourceLite(&Vcb->fcb_lock);
|
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
static __inline void* map_user_buffer(PIRP Irp, ULONG priority) {
|
2016-03-23 20:35:05 +00:00
|
|
|
if (!Irp->MdlAddress) {
|
|
|
|
return Irp->UserBuffer;
|
|
|
|
} else {
|
2017-09-08 08:02:43 +00:00
|
|
|
return MmGetSystemAddressForMdlSafe(Irp->MdlAddress, priority);
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
static __inline uint64_t unix_time_to_win(BTRFS_TIME* t) {
|
2016-03-23 20:35:05 +00:00
|
|
|
return (t->seconds * 10000000) + (t->nanoseconds / 100) + 116444736000000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME* out) {
|
2018-12-16 11:03:16 +00:00
|
|
|
ULONGLONG l = (ULONGLONG)t.QuadPart - 116444736000000000;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
out->seconds = l / 10000000;
|
2019-09-01 12:53:20 +00:00
|
|
|
out->nanoseconds = (uint32_t)((l % 10000000) * 100);
|
2016-03-23 20:35:05 +00:00
|
|
|
}
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Post_satisfies_(*stripe>=0&&*stripe<num_stripes)
|
2019-09-01 12:53:20 +00:00
|
|
|
static __inline void get_raid0_offset(_In_ uint64_t off, _In_ uint64_t stripe_length, _In_ uint16_t num_stripes, _Out_ uint64_t* stripeoff, _Out_ uint16_t* stripe) {
|
|
|
|
uint64_t initoff, startoff;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
startoff = off % (num_stripes * stripe_length);
|
|
|
|
initoff = (off / (num_stripes * stripe_length)) * stripe_length;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
*stripe = (uint16_t)(startoff / stripe_length);
|
2016-07-27 19:24:26 +00:00
|
|
|
*stripeoff = initoff + startoff - (*stripe * stripe_length);
|
|
|
|
}
|
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
/* We only have 64 bits for a file ID, which isn't technically enough to be
|
|
|
|
* unique on Btrfs. We fudge it by having three bytes for the subvol and
|
|
|
|
* five for the inode, which should be good enough.
|
|
|
|
* Inodes are also 64 bits on Linux, but the Linux driver seems to get round
|
|
|
|
* this by tricking it into thinking subvols are separate volumes. */
|
2019-09-01 12:53:20 +00:00
|
|
|
static __inline uint64_t make_file_id(root* r, uint64_t inode) {
|
2016-10-29 17:05:10 +00:00
|
|
|
return (r->id << 40) | (inode & 0xffffffffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define keycmp(key1, key2)\
|
|
|
|
((key1.obj_id < key2.obj_id) ? -1 :\
|
|
|
|
((key1.obj_id > key2.obj_id) ? 1 :\
|
|
|
|
((key1.obj_type < key2.obj_type) ? -1 :\
|
|
|
|
((key1.obj_type > key2.obj_type) ? 1 :\
|
|
|
|
((key1.offset < key2.offset) ? -1 :\
|
|
|
|
((key1.offset > key2.offset) ? 1 :\
|
|
|
|
0))))))
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Post_satisfies_(return>=n)
|
2019-09-01 12:53:20 +00:00
|
|
|
__inline static uint64_t sector_align(_In_ uint64_t n, _In_ uint64_t a) {
|
2017-09-08 08:02:43 +00:00
|
|
|
if (n & (a - 1))
|
|
|
|
n = (n + a) & ~(a - 1);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
__inline static bool is_subvol_readonly(root* r, PIRP Irp) {
|
2017-09-08 08:02:43 +00:00
|
|
|
if (!(r->root_item.flags & BTRFS_SUBVOL_READONLY))
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
if (!r->reserved)
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
return (!Irp || Irp->RequestorMode == UserMode) && PsGetCurrentProcess() != r->reserved ? true : false;
|
2017-09-08 08:02:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
__inline static uint16_t get_extent_data_len(uint8_t type) {
|
2017-09-08 08:02:43 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_TREE_BLOCK_REF:
|
|
|
|
return sizeof(TREE_BLOCK_REF);
|
|
|
|
|
|
|
|
case TYPE_EXTENT_DATA_REF:
|
|
|
|
return sizeof(EXTENT_DATA_REF);
|
|
|
|
|
|
|
|
case TYPE_EXTENT_REF_V0:
|
|
|
|
return sizeof(EXTENT_REF_V0);
|
|
|
|
|
|
|
|
case TYPE_SHARED_BLOCK_REF:
|
|
|
|
return sizeof(SHARED_BLOCK_REF);
|
|
|
|
|
|
|
|
case TYPE_SHARED_DATA_REF:
|
|
|
|
return sizeof(SHARED_DATA_REF);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
__inline static uint32_t get_extent_data_refcount(uint8_t type, void* data) {
|
2017-09-08 08:02:43 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_TREE_BLOCK_REF:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case TYPE_EXTENT_DATA_REF:
|
|
|
|
{
|
|
|
|
EXTENT_DATA_REF* edr = (EXTENT_DATA_REF*)data;
|
|
|
|
return edr->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_EXTENT_REF_V0:
|
|
|
|
{
|
|
|
|
EXTENT_REF_V0* erv0 = (EXTENT_REF_V0*)data;
|
|
|
|
return erv0->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TYPE_SHARED_BLOCK_REF:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case TYPE_SHARED_DATA_REF:
|
|
|
|
{
|
|
|
|
SHARED_DATA_REF* sdr = (SHARED_DATA_REF*)data;
|
|
|
|
return sdr->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-28 19:33:48 +00:00
|
|
|
// in xor-gas.S
|
|
|
|
#if defined(_X86_) || defined(_AMD64_)
|
|
|
|
void __stdcall do_xor_sse2(uint8_t* buf1, uint8_t* buf2, uint32_t len);
|
|
|
|
void __stdcall do_xor_avx2(uint8_t* buf1, uint8_t* buf2, uint32_t len);
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
// in btrfs.c
|
2017-09-08 08:02:43 +00:00
|
|
|
_Ret_maybenull_
|
|
|
|
device* find_device_from_uuid(_In_ device_extension* Vcb, _In_ BTRFS_UUID* uuid);
|
|
|
|
|
|
|
|
_Success_(return)
|
2019-09-01 12:53:20 +00:00
|
|
|
bool get_file_attributes_from_xattr(_In_reads_bytes_(len) char* val, _In_ uint16_t len, _Out_ ULONG* atts);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
ULONG get_file_attributes(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_ root* r, _In_ uint64_t inode,
|
|
|
|
_In_ uint8_t type, _In_ bool dotfile, _In_ bool ignore_xa, _In_opt_ PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Success_(return)
|
2019-09-01 12:53:20 +00:00
|
|
|
bool get_xattr(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_ root* subvol, _In_ uint64_t inode, _In_z_ char* name, _In_ uint32_t crc32,
|
|
|
|
_Out_ uint8_t** data, _Out_ uint16_t* datalen, _In_opt_ PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
#ifndef DEBUG_FCB_REFCOUNTS
|
2019-05-11 09:20:02 +00:00
|
|
|
void free_fcb(_Inout_ fcb* fcb);
|
2017-09-08 08:02:43 +00:00
|
|
|
#endif
|
2019-05-11 09:20:02 +00:00
|
|
|
void free_fileref(_Inout_ file_ref* fr);
|
2017-09-08 08:02:43 +00:00
|
|
|
void protect_superblocks(_Inout_ chunk* c);
|
2019-09-01 12:53:20 +00:00
|
|
|
bool is_top_level(_In_ PIRP Irp);
|
|
|
|
NTSTATUS create_root(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_ uint64_t id,
|
|
|
|
_Out_ root** rootptr, _In_ bool no_tree, _In_ uint64_t offset, _In_opt_ PIRP Irp);
|
2018-12-16 11:03:16 +00:00
|
|
|
void uninit(_In_ device_extension* Vcb);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS dev_ioctl(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize,
|
2019-09-01 12:53:20 +00:00
|
|
|
_Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _In_ bool Override, _Out_opt_ IO_STATUS_BLOCK* iosb);
|
2022-04-28 19:34:48 +00:00
|
|
|
NTSTATUS check_file_name_valid(_In_ PUNICODE_STRING us, _In_ bool posix, _In_ bool stream);
|
2017-09-08 08:02:43 +00:00
|
|
|
void send_notification_fileref(_In_ file_ref* fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream);
|
2019-11-12 18:32:46 +00:00
|
|
|
void queue_notification_fcb(_In_ file_ref* fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2022-04-28 19:33:48 +00:00
|
|
|
typedef void (__stdcall *xor_func)(uint8_t* buf1, uint8_t* buf2, uint32_t len);
|
|
|
|
|
|
|
|
extern xor_func do_xor;
|
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
#ifdef DEBUG_CHUNK_LOCKS
|
2019-09-01 12:53:20 +00:00
|
|
|
#define acquire_chunk_lock(c, Vcb) { ExAcquireResourceExclusiveLite(&c->lock, true); InterlockedIncrement(&Vcb->chunk_locks_held); }
|
2018-12-16 11:03:16 +00:00
|
|
|
#define release_chunk_lock(c, Vcb) { InterlockedDecrement(&Vcb->chunk_locks_held); ExReleaseResourceLite(&c->lock); }
|
|
|
|
#else
|
2019-09-01 12:53:20 +00:00
|
|
|
#define acquire_chunk_lock(c, Vcb) ExAcquireResourceExclusiveLite(&(c)->lock, true)
|
2018-12-16 11:03:16 +00:00
|
|
|
#define release_chunk_lock(c, Vcb) ExReleaseResourceLite(&(c)->lock)
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
void mark_fcb_dirty(_In_ fcb* fcb);
|
|
|
|
void mark_fileref_dirty(_In_ file_ref* fileref);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_ PFILE_OBJECT FileObject, _In_ bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY* rollback);
|
|
|
|
void chunk_lock_range(_In_ device_extension* Vcb, _In_ chunk* c, _In_ uint64_t start, _In_ uint64_t length);
|
|
|
|
void chunk_unlock_range(_In_ device_extension* Vcb, _In_ chunk* c, _In_ uint64_t start, _In_ uint64_t length);
|
|
|
|
void init_device(_In_ device_extension* Vcb, _Inout_ device* dev, _In_ bool get_nums);
|
2017-09-08 08:02:43 +00:00
|
|
|
void init_file_cache(_In_ PFILE_OBJECT FileObject, _In_ CC_FILE_SIZES* ccfs);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_ PFILE_OBJECT FileObject, _In_ uint64_t StartingOffset, _In_ ULONG Length,
|
|
|
|
_Out_writes_bytes_(Length) PUCHAR Buffer, _In_ bool override);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS get_device_pnp_name(_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _Out_ const GUID** guid);
|
|
|
|
void log_device_error(_In_ device_extension* Vcb, _Inout_ device* dev, _In_ int error);
|
|
|
|
NTSTATUS find_chunk_usage(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_opt_ PIRP Irp);
|
2019-09-01 12:53:20 +00:00
|
|
|
|
|
|
|
_Function_class_(DRIVER_ADD_DEVICE)
|
|
|
|
NTSTATUS __stdcall AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject);
|
|
|
|
|
2019-05-11 09:20:02 +00:00
|
|
|
void reap_fcb(fcb* fcb);
|
|
|
|
void reap_fcbs(device_extension* Vcb);
|
|
|
|
void reap_fileref(device_extension* Vcb, file_ref* fr);
|
|
|
|
void reap_filerefs(device_extension* Vcb, file_ref* fr);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS utf8_to_utf16(WCHAR* dest, ULONG dest_max, ULONG* dest_len, char* src, ULONG src_len);
|
|
|
|
NTSTATUS utf16_to_utf8(char* dest, ULONG dest_max, ULONG* dest_len, WCHAR* src, ULONG src_len);
|
|
|
|
uint32_t get_num_of_processors();
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
_Ret_maybenull_
|
|
|
|
root* find_default_subvol(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_opt_ PIRP Irp);
|
|
|
|
|
|
|
|
void do_shutdown(PIRP Irp);
|
2020-04-23 02:38:57 +00:00
|
|
|
bool check_superblock_checksum(superblock* sb);
|
2019-11-12 18:32:46 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define funcname __FUNCTION__
|
|
|
|
#else
|
|
|
|
#define funcname __func__
|
|
|
|
#endif
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
extern uint32_t mount_compress;
|
|
|
|
extern uint32_t mount_compress_force;
|
|
|
|
extern uint32_t mount_compress_type;
|
|
|
|
extern uint32_t mount_zlib_level;
|
|
|
|
extern uint32_t mount_zstd_level;
|
|
|
|
extern uint32_t mount_flush_interval;
|
|
|
|
extern uint32_t mount_max_inline;
|
|
|
|
extern uint32_t mount_skip_balance;
|
|
|
|
extern uint32_t mount_no_barrier;
|
|
|
|
extern uint32_t mount_no_trim;
|
|
|
|
extern uint32_t mount_clear_cache;
|
|
|
|
extern uint32_t mount_allow_degraded;
|
|
|
|
extern uint32_t mount_readonly;
|
2019-11-12 18:32:46 +00:00
|
|
|
extern uint32_t mount_no_root_dir;
|
2022-09-28 16:08:10 +00:00
|
|
|
extern uint32_t mount_nodatacow;
|
2019-09-01 12:53:20 +00:00
|
|
|
extern uint32_t no_pnp;
|
2016-09-04 15:27:46 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#ifndef __GNUC__
|
|
|
|
#define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
extern bool log_started;
|
|
|
|
extern uint32_t debug_log_level;
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifdef DEBUG_LONG_MESSAGES
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#define MSG(fn, file, line, s, level, ...) (!log_started || level <= debug_log_level) ? _debug_message(fn, file, line, s, ##__VA_ARGS__) : (void)0
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
#define TRACE(s, ...) MSG(funcname, __FILE__, __LINE__, s, 3, ##__VA_ARGS__)
|
|
|
|
#define WARN(s, ...) MSG(funcname, __FILE__, __LINE__, s, 2, ##__VA_ARGS__)
|
|
|
|
#define FIXME(s, ...) MSG(funcname, __FILE__, __LINE__, s, 1, ##__VA_ARGS__)
|
|
|
|
#define ERR(s, ...) MSG(funcname, __FILE__, __LINE__, s, 1, ##__VA_ARGS__)
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
void _debug_message(_In_ const char* func, _In_ const char* file, _In_ unsigned int line, _In_ char* s, ...) __attribute__((format(printf, 4, 5)));
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
#define MSG(fn, s, level, ...) (!log_started || level <= debug_log_level) ? _debug_message(fn, s, ##__VA_ARGS__) : (void)0
|
2016-05-05 17:26:47 +00:00
|
|
|
|
|
|
|
#define TRACE(s, ...) MSG(funcname, s, 3, ##__VA_ARGS__)
|
|
|
|
#define WARN(s, ...) MSG(funcname, s, 2, ##__VA_ARGS__)
|
|
|
|
#define FIXME(s, ...) MSG(funcname, s, 1, ##__VA_ARGS__)
|
|
|
|
#define ERR(s, ...) MSG(funcname, s, 1, ##__VA_ARGS__)
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
void _debug_message(_In_ const char* func, _In_ char* s, ...) __attribute__((format(printf, 2, 3)));
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2022-04-28 19:33:48 +00:00
|
|
|
#define TRACE(s, ...) do { } while(0)
|
|
|
|
#define WARN(s, ...) do { } while(0)
|
2016-03-23 20:35:05 +00:00
|
|
|
#define FIXME(s, ...) DbgPrint("Btrfs FIXME : %s : " s, funcname, ##__VA_ARGS__)
|
|
|
|
#define ERR(s, ...) DbgPrint("Btrfs ERR : %s : " s, funcname, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifdef DEBUG_FCB_REFCOUNTS
|
2019-05-11 09:20:02 +00:00
|
|
|
void _free_fcb(_Inout_ fcb* fcb, _In_ const char* func);
|
|
|
|
#define free_fcb(fcb) _free_fcb(fcb, funcname)
|
2017-09-08 08:02:43 +00:00
|
|
|
#endif
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
// in fastio.c
|
2017-09-08 08:02:43 +00:00
|
|
|
void init_fast_io_dispatch(FAST_IO_DISPATCH** fiod);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
// in sha256.c
|
|
|
|
void calc_sha256(uint8_t* hash, const void* input, size_t len);
|
|
|
|
#define SHA256_HASH_SIZE 32
|
|
|
|
|
|
|
|
// in blake2b-ref.c
|
|
|
|
void blake2b(void *out, size_t outlen, const void* in, size_t inlen);
|
|
|
|
#define BLAKE2_HASH_SIZE 32
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
typedef struct {
|
|
|
|
LIST_ENTRY* list;
|
|
|
|
LIST_ENTRY* list_size;
|
2019-09-01 12:53:20 +00:00
|
|
|
uint64_t address;
|
|
|
|
uint64_t length;
|
2016-09-04 15:27:46 +00:00
|
|
|
chunk* chunk;
|
|
|
|
} rollback_space;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
fcb* fcb;
|
|
|
|
extent* ext;
|
|
|
|
} rollback_extent;
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
enum rollback_type {
|
|
|
|
ROLLBACK_INSERT_EXTENT,
|
2016-09-04 15:27:46 +00:00
|
|
|
ROLLBACK_DELETE_EXTENT,
|
|
|
|
ROLLBACK_ADD_SPACE,
|
|
|
|
ROLLBACK_SUBTRACT_SPACE
|
2016-07-27 19:24:26 +00:00
|
|
|
};
|
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
typedef struct {
|
|
|
|
enum rollback_type type;
|
|
|
|
void* ptr;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} rollback_item;
|
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
typedef struct {
|
|
|
|
ANSI_STRING name;
|
|
|
|
ANSI_STRING value;
|
|
|
|
UCHAR flags;
|
|
|
|
LIST_ENTRY list_entry;
|
|
|
|
} ea_item;
|
|
|
|
|
|
|
|
static const char lxuid[] = "$LXUID";
|
|
|
|
static const char lxgid[] = "$LXGID";
|
|
|
|
static const char lxmod[] = "$LXMOD";
|
|
|
|
static const char lxdev[] = "$LXDEV";
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
// in treefuncs.c
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS find_item(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_ root* r, _Out_ traverse_ptr* tp,
|
2022-04-28 19:31:44 +00:00
|
|
|
_In_ const KEY* searchkey, _In_ bool ignore, _In_opt_ PIRP Irp) __attribute__((nonnull(1,2,3,4)));
|
|
|
|
NTSTATUS find_item_to_level(device_extension* Vcb, root* r, traverse_ptr* tp, const KEY* searchkey, bool ignore,
|
|
|
|
uint8_t level, PIRP Irp) __attribute__((nonnull(1,2,3,4)));
|
|
|
|
bool find_next_item(_Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, const traverse_ptr* tp,
|
|
|
|
traverse_ptr* next_tp, bool ignore, PIRP Irp) __attribute__((nonnull(1,2,3)));
|
|
|
|
bool find_prev_item(_Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, const traverse_ptr* tp,
|
|
|
|
traverse_ptr* prev_tp, PIRP Irp) __attribute__((nonnull(1,2,3)));
|
|
|
|
void free_trees(device_extension* Vcb) __attribute__((nonnull(1)));
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS insert_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension* Vcb, _In_ root* r, _In_ uint64_t obj_id,
|
|
|
|
_In_ uint8_t obj_type, _In_ uint64_t offset, _In_reads_bytes_opt_(size) _When_(return >= 0, __drv_aliasesMem) void* data,
|
2022-04-28 19:31:44 +00:00
|
|
|
_In_ uint16_t size, _Out_opt_ traverse_ptr* ptp, _In_opt_ PIRP Irp) __attribute__((nonnull(1,2)));
|
|
|
|
NTSTATUS delete_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension* Vcb,
|
|
|
|
_Inout_ traverse_ptr* tp) __attribute__((nonnull(1,2)));
|
|
|
|
void free_tree(tree* t) __attribute__((nonnull(1)));
|
|
|
|
NTSTATUS load_tree(device_extension* Vcb, uint64_t addr, uint8_t* buf, root* r, tree** pt) __attribute__((nonnull(1,3,4,5)));
|
|
|
|
NTSTATUS do_load_tree(device_extension* Vcb, tree_holder* th, root* r, tree* t, tree_data* td, PIRP Irp) __attribute__((nonnull(1,2,3)));
|
|
|
|
void clear_rollback(LIST_ENTRY* rollback) __attribute__((nonnull(1)));
|
|
|
|
void do_rollback(device_extension* Vcb, LIST_ENTRY* rollback) __attribute__((nonnull(1,2)));
|
|
|
|
void free_trees_root(device_extension* Vcb, root* r) __attribute__((nonnull(1,2)));
|
|
|
|
void add_rollback(_In_ LIST_ENTRY* rollback, _In_ enum rollback_type type, _In_ __drv_aliasesMem void* ptr) __attribute__((nonnull(1,3)));
|
|
|
|
NTSTATUS commit_batch_list(_Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension* Vcb,
|
|
|
|
LIST_ENTRY* batchlist, PIRP Irp) __attribute__((nonnull(1,2)));
|
|
|
|
void clear_batch_list(device_extension* Vcb, LIST_ENTRY* batchlist) __attribute__((nonnull(1,2)));
|
|
|
|
NTSTATUS skip_to_difference(device_extension* Vcb, traverse_ptr* tp, traverse_ptr* tp2, bool* ended1, bool* ended2) __attribute__((nonnull(1,2,3,4,5)));
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in search.c
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS remove_drive_letter(PDEVICE_OBJECT mountmgr, PUNICODE_STRING devpath);
|
|
|
|
|
|
|
|
_Function_class_(KSTART_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
void __stdcall mountmgr_thread(_In_ void* context);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Function_class_(DRIVER_NOTIFICATION_CALLBACK_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall pnp_notification(PVOID NotificationStructure, PVOID Context);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2022-04-28 19:35:58 +00:00
|
|
|
void disk_arrival(PUNICODE_STRING devpath);
|
|
|
|
bool volume_arrival(PUNICODE_STRING devpath, bool fve_callback);
|
|
|
|
void volume_removal(PUNICODE_STRING devpath);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Function_class_(DRIVER_NOTIFICATION_CALLBACK_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall volume_notification(PVOID NotificationStructure, PVOID Context);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
void remove_volume_child(_Inout_ _Requires_exclusive_lock_held_(_Curr_->child_lock) _Releases_exclusive_lock_(_Curr_->child_lock) _In_ volume_device_extension* vde,
|
2019-09-01 12:53:20 +00:00
|
|
|
_In_ volume_child* vc, _In_ bool skip_dev);
|
2022-04-28 19:35:58 +00:00
|
|
|
extern KSPIN_LOCK fve_data_lock;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
// in cache.c
|
2019-11-12 18:32:46 +00:00
|
|
|
void init_cache();
|
|
|
|
extern CACHE_MANAGER_CALLBACKS cache_callbacks;
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in write.c
|
2022-04-28 19:31:44 +00:00
|
|
|
NTSTATUS write_file(device_extension* Vcb, PIRP Irp, bool wait, bool deferred_write) __attribute__((nonnull(1,2)));
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS write_file2(device_extension* Vcb, PIRP Irp, LARGE_INTEGER offset, void* buf, ULONG* length, bool paging_io, bool no_cache,
|
2022-04-28 19:31:44 +00:00
|
|
|
bool wait, bool deferred_write, bool write_irp, LIST_ENTRY* rollback) __attribute__((nonnull(1,2,4,5,11)));
|
|
|
|
NTSTATUS truncate_file(fcb* fcb, uint64_t end, PIRP Irp, LIST_ENTRY* rollback) __attribute__((nonnull(1,4)));
|
|
|
|
NTSTATUS extend_file(fcb* fcb, file_ref* fileref, uint64_t end, bool prealloc, PIRP Irp, LIST_ENTRY* rollback) __attribute__((nonnull(1,6)));
|
|
|
|
NTSTATUS excise_extents(device_extension* Vcb, fcb* fcb, uint64_t start_data, uint64_t end_data, PIRP Irp, LIST_ENTRY* rollback) __attribute__((nonnull(1,2,6)));
|
|
|
|
chunk* get_chunk_from_address(device_extension* Vcb, uint64_t address) __attribute__((nonnull(1)));
|
|
|
|
NTSTATUS alloc_chunk(device_extension* Vcb, uint64_t flags, chunk** pc, bool full_size) __attribute__((nonnull(1,3)));
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS write_data(_In_ device_extension* Vcb, _In_ uint64_t address, _In_reads_bytes_(length) void* data, _In_ uint32_t length, _In_ write_data_context* wtc,
|
2022-04-28 19:31:44 +00:00
|
|
|
_In_opt_ PIRP Irp, _In_opt_ chunk* c, _In_ bool file_write, _In_ uint64_t irp_offset, _In_ ULONG priority) __attribute__((nonnull(1,3,5)));
|
|
|
|
NTSTATUS write_data_complete(device_extension* Vcb, uint64_t address, void* data, uint32_t length, PIRP Irp, chunk* c, bool file_write,
|
|
|
|
uint64_t irp_offset, ULONG priority) __attribute__((nonnull(1,3)));
|
|
|
|
void free_write_data_stripes(write_data_context* wtc) __attribute__((nonnull(1)));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_WRITE)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2022-04-28 19:31:44 +00:00
|
|
|
NTSTATUS __stdcall drv_write(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) __attribute__((nonnull(1,2)));
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Requires_lock_held_(c->lock)
|
|
|
|
_When_(return != 0, _Releases_lock_(c->lock))
|
2022-04-28 19:31:44 +00:00
|
|
|
bool insert_extent_chunk(_In_ device_extension* Vcb, _In_ fcb* fcb, _In_ chunk* c, _In_ uint64_t start_data, _In_ uint64_t length, _In_ bool prealloc,
|
|
|
|
_In_opt_ void* data, _In_opt_ PIRP Irp, _In_ LIST_ENTRY* rollback, _In_ uint8_t compression, _In_ uint64_t decoded_size,
|
|
|
|
_In_ bool file_write, _In_ uint64_t irp_offset) __attribute__((nonnull(1,2,3,9)));
|
2019-09-01 12:53:20 +00:00
|
|
|
|
2022-04-28 19:31:44 +00:00
|
|
|
NTSTATUS do_write_file(fcb* fcb, uint64_t start_data, uint64_t end_data, void* data, PIRP Irp, bool file_write, uint32_t irp_offset, LIST_ENTRY* rollback) __attribute__((nonnull(1, 4)));
|
|
|
|
bool find_data_address_in_chunk(device_extension* Vcb, chunk* c, uint64_t length, uint64_t* address) __attribute__((nonnull(1, 2, 4)));
|
|
|
|
void get_raid56_lock_range(chunk* c, uint64_t address, uint64_t length, uint64_t* lockaddr, uint64_t* locklen) __attribute__((nonnull(1,4,5)));
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS add_extent_to_fcb(_In_ fcb* fcb, _In_ uint64_t offset, _In_reads_bytes_(edsize) EXTENT_DATA* ed, _In_ uint16_t edsize,
|
2022-04-28 19:31:44 +00:00
|
|
|
_In_ bool unique, _In_opt_ _When_(return >= 0, __drv_aliasesMem) void* csum, _In_ LIST_ENTRY* rollback) __attribute__((nonnull(1,3,7)));
|
|
|
|
void add_extent(_In_ fcb* fcb, _In_ LIST_ENTRY* prevextle, _In_ __drv_aliasesMem extent* newext) __attribute__((nonnull(1,2,3)));
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in dirctrl.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_DIRECTORY_CONTROL)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_directory_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
ULONG get_reparse_tag(device_extension* Vcb, root* subvol, uint64_t inode, uint8_t type, ULONG atts, bool lxss, PIRP Irp);
|
2018-12-16 11:03:16 +00:00
|
|
|
ULONG get_reparse_tag_fcb(fcb* fcb);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in security.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_QUERY_SECURITY)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_query_security(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_SET_SECURITY)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_set_security(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
void fcb_get_sd(fcb* fcb, struct _fcb* parent, bool look_for_xattr, PIRP Irp);
|
|
|
|
void add_user_mapping(WCHAR* sidstring, ULONG sidstringlength, uint32_t uid);
|
|
|
|
void add_group_mapping(WCHAR* sidstring, ULONG sidstringlength, uint32_t gid);
|
|
|
|
uint32_t sid_to_uid(PSID sid);
|
|
|
|
NTSTATUS uid_to_sid(uint32_t uid, PSID* sid);
|
2016-07-27 19:24:26 +00:00
|
|
|
NTSTATUS fcb_get_new_sd(fcb* fcb, file_ref* parfileref, ACCESS_STATE* as);
|
2017-09-08 08:02:43 +00:00
|
|
|
void find_gid(struct _fcb* fcb, struct _fcb* parfcb, PSECURITY_SUBJECT_CONTEXT subjcont);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in fileinfo.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_SET_INFORMATION)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_set_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_QUERY_INFORMATION)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_query_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_QUERY_EA)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_query_ea(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_SET_EA)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_set_ea(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
bool has_open_children(file_ref* fileref);
|
|
|
|
NTSTATUS stream_set_end_of_file_information(device_extension* Vcb, uint16_t end, fcb* fcb, file_ref* fileref, bool advance_only);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS fileref_get_filename(file_ref* fileref, PUNICODE_STRING fn, USHORT* name_offset, ULONG* preqlen);
|
2017-01-01 17:12:12 +00:00
|
|
|
void insert_dir_child_into_hash_lists(fcb* fcb, dir_child* dc);
|
|
|
|
void remove_dir_child_from_hash_lists(fcb* fcb, dir_child* dc);
|
2022-04-28 19:34:48 +00:00
|
|
|
void add_fcb_to_subvol(_In_ _Requires_exclusive_lock_held_(_Curr_->Vcb->fcb_lock) fcb* fcb);
|
|
|
|
void remove_fcb_from_subvol(_In_ _Requires_exclusive_lock_held_(_Curr_->Vcb->fcb_lock) fcb* fcb);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in reparse.c
|
2022-04-28 19:33:48 +00:00
|
|
|
NTSTATUS get_reparse_point(PFILE_OBJECT FileObject, void* buffer, DWORD buflen, ULONG_PTR* retlen);
|
2018-12-16 11:03:16 +00:00
|
|
|
NTSTATUS set_reparse_point2(fcb* fcb, REPARSE_DATA_BUFFER* rdb, ULONG buflen, ccb* ccb, file_ref* fileref, PIRP Irp, LIST_ENTRY* rollback);
|
2022-04-28 19:33:48 +00:00
|
|
|
NTSTATUS set_reparse_point(PIRP Irp);
|
|
|
|
NTSTATUS delete_reparse_point(PIRP Irp);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in create.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_CREATE)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
NTSTATUS open_fileref(_Requires_lock_held_(_Curr_->tree_lock) _Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension* Vcb, _Out_ file_ref** pfr,
|
2019-09-01 12:53:20 +00:00
|
|
|
_In_ PUNICODE_STRING fnus, _In_opt_ file_ref* related, _In_ bool parent, _Out_opt_ USHORT* parsed, _Out_opt_ ULONG* fn_offset, _In_ POOL_TYPE pooltype,
|
|
|
|
_In_ bool case_sensitive, _In_opt_ PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS open_fcb(_Requires_lock_held_(_Curr_->tree_lock) _Requires_exclusive_lock_held_(_Curr_->fcb_lock) device_extension* Vcb,
|
2019-09-01 12:53:20 +00:00
|
|
|
root* subvol, uint64_t inode, uint8_t type, PANSI_STRING utf8, bool always_add_hl, fcb* parent, fcb** pfcb, POOL_TYPE pooltype, PIRP Irp);
|
2020-04-23 02:38:57 +00:00
|
|
|
NTSTATUS load_csum(_Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, void* csum, uint64_t start, uint64_t length, PIRP Irp);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS load_dir_children(_Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb, fcb* fcb, bool ignore_size, PIRP Irp);
|
|
|
|
NTSTATUS add_dir_child(fcb* fcb, uint64_t inode, bool subvol, PANSI_STRING utf8, PUNICODE_STRING name, uint8_t type, dir_child** pdc);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS open_fileref_child(_Requires_lock_held_(_Curr_->tree_lock) _Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension* Vcb,
|
2019-09-01 12:53:20 +00:00
|
|
|
_In_ file_ref* sf, _In_ PUNICODE_STRING name, _In_ bool case_sensitive, _In_ bool lastpart, _In_ bool streampart,
|
2017-09-08 08:02:43 +00:00
|
|
|
_In_ POOL_TYPE pooltype, _Out_ file_ref** psf2, _In_opt_ PIRP Irp);
|
|
|
|
fcb* create_fcb(device_extension* Vcb, POOL_TYPE pool_type);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS find_file_in_dir(PUNICODE_STRING filename, fcb* fcb, root** subvol, uint64_t* inode, dir_child** pdc, bool case_sensitive);
|
|
|
|
uint32_t inherit_mode(fcb* parfcb, bool is_dir);
|
2017-09-08 08:02:43 +00:00
|
|
|
file_ref* create_fileref(device_extension* Vcb);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS open_fileref_by_inode(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) device_extension* Vcb, root* subvol, uint64_t inode, file_ref** pfr, PIRP Irp);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in fsctl.c
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP* Pirp, uint32_t type);
|
2016-07-27 19:24:26 +00:00
|
|
|
void do_unlock_volume(device_extension* Vcb);
|
2017-09-08 08:02:43 +00:00
|
|
|
void trim_whole_device(device* dev);
|
|
|
|
void flush_subvol_fcbs(root* subvol);
|
2019-09-01 12:53:20 +00:00
|
|
|
bool fcb_is_inline(fcb* fcb);
|
2019-11-12 18:32:46 +00:00
|
|
|
NTSTATUS dismount_volume(device_extension* Vcb, bool shutdown, PIRP Irp);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in flushthread.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Function_class_(KSTART_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
void __stdcall flush_thread(void* context);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
NTSTATUS do_write(device_extension* Vcb, PIRP Irp);
|
2016-10-29 17:05:10 +00:00
|
|
|
NTSTATUS get_tree_new_address(device_extension* Vcb, tree* t, PIRP Irp, LIST_ENTRY* rollback);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS flush_fcb(fcb* fcb, bool cache, LIST_ENTRY* batchlist, PIRP Irp);
|
|
|
|
NTSTATUS write_data_phys(_In_ PDEVICE_OBJECT device, _In_ PFILE_OBJECT fileobj, _In_ uint64_t address,
|
|
|
|
_In_reads_bytes_(length) void* data, _In_ uint32_t length);
|
|
|
|
bool is_tree_unique(device_extension* Vcb, tree* t, PIRP Irp);
|
|
|
|
NTSTATUS do_tree_writes(device_extension* Vcb, LIST_ENTRY* tree_writes, bool no_free);
|
2020-04-23 02:38:57 +00:00
|
|
|
void add_checksum_entry(device_extension* Vcb, uint64_t address, ULONG length, void* csum, PIRP Irp);
|
2019-09-01 12:53:20 +00:00
|
|
|
bool find_metadata_address_in_chunk(device_extension* Vcb, chunk* c, uint64_t* address);
|
|
|
|
void add_trim_entry_avoid_sb(device_extension* Vcb, device* dev, uint64_t address, uint64_t size);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS flush_partial_stripe(device_extension* Vcb, chunk* c, partial_stripe* ps);
|
|
|
|
NTSTATUS update_dev_item(device_extension* Vcb, device* device, PIRP Irp);
|
2020-04-23 02:38:57 +00:00
|
|
|
void calc_tree_checksum(device_extension* Vcb, tree_header* th);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// in read.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_READ)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_read(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
NTSTATUS read_data(_In_ device_extension* Vcb, _In_ uint64_t addr, _In_ uint32_t length, _In_reads_bytes_opt_(length*sizeof(uint32_t)/Vcb->superblock.sector_size) void* csum,
|
2019-09-01 12:53:20 +00:00
|
|
|
_In_ bool is_tree, _Out_writes_bytes_(length) uint8_t* buf, _In_opt_ chunk* c, _Out_opt_ chunk** pc, _In_opt_ PIRP Irp, _In_ uint64_t generation, _In_ bool file_read,
|
2017-09-08 08:02:43 +00:00
|
|
|
_In_ ULONG priority);
|
2022-04-28 19:31:44 +00:00
|
|
|
NTSTATUS read_file(fcb* fcb, uint8_t* data, uint64_t start, uint64_t length, ULONG* pbr, PIRP Irp) __attribute__((nonnull(1, 2)));
|
|
|
|
NTSTATUS read_stream(fcb* fcb, uint8_t* data, uint64_t start, ULONG length, ULONG* pbr) __attribute__((nonnull(1, 2)));
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS do_read(PIRP Irp, bool wait, ULONG* bytes_read);
|
2020-04-23 02:38:57 +00:00
|
|
|
NTSTATUS check_csum(device_extension* Vcb, uint8_t* data, uint32_t sectors, void* csum);
|
2019-09-01 12:53:20 +00:00
|
|
|
void raid6_recover2(uint8_t* sectors, uint16_t num_stripes, ULONG sector_size, uint16_t missing1, uint16_t missing2, uint8_t* out);
|
2020-04-23 02:38:57 +00:00
|
|
|
void get_tree_checksum(device_extension* Vcb, tree_header* th, void* csum);
|
|
|
|
bool check_tree_checksum(device_extension* Vcb, tree_header* th);
|
|
|
|
void get_sector_csum(device_extension* Vcb, void* buf, void* csum);
|
|
|
|
bool check_sector_csum(device_extension* Vcb, void* buf, void* csum);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
// in pnp.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_PNP)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
NTSTATUS pnp_surprise_removal(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
|
|
|
NTSTATUS pnp_query_remove_device(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
2016-05-05 17:26:47 +00:00
|
|
|
|
|
|
|
// in free-space.c
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS load_cache_chunk(device_extension* Vcb, chunk* c, PIRP Irp);
|
2016-10-29 17:05:10 +00:00
|
|
|
NTSTATUS clear_free_space_cache(device_extension* Vcb, LIST_ENTRY* batchlist, PIRP Irp);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS allocate_cache(device_extension* Vcb, bool* changed, PIRP Irp, LIST_ENTRY* rollback);
|
2016-09-04 15:27:46 +00:00
|
|
|
NTSTATUS update_chunk_caches(device_extension* Vcb, PIRP Irp, LIST_ENTRY* rollback);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS update_chunk_caches_tree(device_extension* Vcb, PIRP Irp);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS add_space_entry(LIST_ENTRY* list, LIST_ENTRY* list_size, uint64_t offset, uint64_t size);
|
|
|
|
void space_list_add(chunk* c, uint64_t address, uint64_t length, LIST_ENTRY* rollback);
|
|
|
|
void space_list_add2(LIST_ENTRY* list, LIST_ENTRY* list_size, uint64_t address, uint64_t length, chunk* c, LIST_ENTRY* rollback);
|
2022-04-28 19:31:44 +00:00
|
|
|
void space_list_subtract(chunk* c, uint64_t address, uint64_t length, LIST_ENTRY* rollback);
|
2019-09-01 12:53:20 +00:00
|
|
|
void space_list_subtract2(LIST_ENTRY* list, LIST_ENTRY* list_size, uint64_t address, uint64_t length, chunk* c, LIST_ENTRY* rollback);
|
2022-04-28 19:31:44 +00:00
|
|
|
void space_list_merge(LIST_ENTRY* spacelist, LIST_ENTRY* spacelist_size, LIST_ENTRY* deleting);
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS load_stored_free_space_cache(device_extension* Vcb, chunk* c, bool load_only, PIRP Irp);
|
2016-05-05 17:26:47 +00:00
|
|
|
|
|
|
|
// in extent-tree.c
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS increase_extent_refcount_data(device_extension* Vcb, uint64_t address, uint64_t size, uint64_t root, uint64_t inode, uint64_t offset, uint32_t refcount, PIRP Irp);
|
|
|
|
NTSTATUS decrease_extent_refcount_data(device_extension* Vcb, uint64_t address, uint64_t size, uint64_t root, uint64_t inode, uint64_t offset,
|
|
|
|
uint32_t refcount, bool superseded, PIRP Irp);
|
|
|
|
NTSTATUS decrease_extent_refcount_tree(device_extension* Vcb, uint64_t address, uint64_t size, uint64_t root, uint8_t level, PIRP Irp);
|
|
|
|
uint64_t get_extent_refcount(device_extension* Vcb, uint64_t address, uint64_t size, PIRP Irp);
|
|
|
|
bool is_extent_unique(device_extension* Vcb, uint64_t address, uint64_t size, PIRP Irp);
|
|
|
|
NTSTATUS increase_extent_refcount(device_extension* Vcb, uint64_t address, uint64_t size, uint8_t type, void* data, KEY* firstitem, uint8_t level, PIRP Irp);
|
|
|
|
uint64_t get_extent_flags(device_extension* Vcb, uint64_t address, PIRP Irp);
|
|
|
|
void update_extent_flags(device_extension* Vcb, uint64_t address, uint64_t flags, PIRP Irp);
|
|
|
|
NTSTATUS update_changed_extent_ref(device_extension* Vcb, chunk* c, uint64_t address, uint64_t size, uint64_t root, uint64_t objid, uint64_t offset,
|
|
|
|
int32_t count, bool no_csum, bool superseded, PIRP Irp);
|
|
|
|
void add_changed_extent_ref(chunk* c, uint64_t address, uint64_t size, uint64_t root, uint64_t objid, uint64_t offset, uint32_t count, bool no_csum);
|
|
|
|
uint64_t find_extent_shared_tree_refcount(device_extension* Vcb, uint64_t address, uint64_t parent, PIRP Irp);
|
|
|
|
uint32_t find_extent_shared_data_refcount(device_extension* Vcb, uint64_t address, uint64_t parent, PIRP Irp);
|
|
|
|
NTSTATUS decrease_extent_refcount(device_extension* Vcb, uint64_t address, uint64_t size, uint8_t type, void* data, KEY* firstitem,
|
|
|
|
uint8_t level, uint64_t parent, bool superseded, PIRP Irp);
|
|
|
|
uint64_t get_extent_data_ref_hash2(uint64_t root, uint64_t objid, uint64_t offset);
|
2016-07-27 19:24:26 +00:00
|
|
|
|
|
|
|
// in worker-thread.c
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS do_read_job(PIRP Irp);
|
|
|
|
NTSTATUS do_write_job(device_extension* Vcb, PIRP Irp);
|
|
|
|
bool add_thread_job(device_extension* Vcb, PIRP Irp);
|
2016-07-27 19:24:26 +00:00
|
|
|
|
|
|
|
// in registry.c
|
2019-09-01 12:53:20 +00:00
|
|
|
void read_registry(PUNICODE_STRING regpath, bool refresh);
|
2016-07-27 19:24:26 +00:00
|
|
|
NTSTATUS registry_mark_volume_mounted(BTRFS_UUID* uuid);
|
|
|
|
NTSTATUS registry_mark_volume_unmounted(BTRFS_UUID* uuid);
|
2016-09-04 15:27:46 +00:00
|
|
|
NTSTATUS registry_load_volume_options(device_extension* Vcb);
|
2017-09-08 08:02:43 +00:00
|
|
|
void watch_registry(HANDLE regh);
|
2016-09-04 15:27:46 +00:00
|
|
|
|
|
|
|
// in compress.c
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS zlib_decompress(uint8_t* inbuf, uint32_t inlen, uint8_t* outbuf, uint32_t outlen);
|
|
|
|
NTSTATUS lzo_decompress(uint8_t* inbuf, uint32_t inlen, uint8_t* outbuf, uint32_t outlen, uint32_t inpageoff);
|
|
|
|
NTSTATUS zstd_decompress(uint8_t* inbuf, uint32_t inlen, uint8_t* outbuf, uint32_t outlen);
|
2020-04-23 02:38:57 +00:00
|
|
|
NTSTATUS write_compressed(fcb* fcb, uint64_t start_data, uint64_t end_data, void* data, PIRP Irp, LIST_ENTRY* rollback);
|
|
|
|
NTSTATUS zlib_compress(uint8_t* inbuf, uint32_t inlen, uint8_t* outbuf, uint32_t outlen, unsigned int level, unsigned int* space_left);
|
|
|
|
NTSTATUS lzo_compress(uint8_t* inbuf, uint32_t inlen, uint8_t* outbuf, uint32_t outlen, unsigned int* space_left);
|
|
|
|
NTSTATUS zstd_compress(uint8_t* inbuf, uint32_t inlen, uint8_t* outbuf, uint32_t outlen, uint32_t level, unsigned int* space_left);
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2016-10-29 17:05:10 +00:00
|
|
|
// in galois.c
|
2019-09-01 12:53:20 +00:00
|
|
|
void galois_double(uint8_t* data, uint32_t len);
|
|
|
|
void galois_divpower(uint8_t* data, uint8_t div, uint32_t readlen);
|
|
|
|
uint8_t gpow2(uint8_t e);
|
|
|
|
uint8_t gmul(uint8_t a, uint8_t b);
|
|
|
|
uint8_t gdiv(uint8_t a, uint8_t b);
|
2016-10-29 17:05:10 +00:00
|
|
|
|
|
|
|
// in devctrl.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Dispatch_type_(IRP_MJ_DEVICE_CONTROL)
|
|
|
|
_Function_class_(DRIVER_DISPATCH)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall drv_device_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2016-10-29 17:05:10 +00:00
|
|
|
|
2017-01-01 17:12:12 +00:00
|
|
|
// in calcthread.c
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
_Function_class_(KSTART_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
void __stdcall calc_thread(void* context);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2020-04-23 02:38:57 +00:00
|
|
|
void do_calc_job(device_extension* Vcb, uint8_t* data, uint32_t sectors, void* csum);
|
|
|
|
NTSTATUS add_calc_job_decomp(device_extension* Vcb, uint8_t compression, void* in, unsigned int inlen,
|
|
|
|
void* out, unsigned int outlen, unsigned int off, calc_job** pcj);
|
|
|
|
NTSTATUS add_calc_job_comp(device_extension* Vcb, uint8_t compression, void* in, unsigned int inlen,
|
|
|
|
void* out, unsigned int outlen, calc_job** pcj);
|
|
|
|
void calc_thread_main(device_extension* Vcb, calc_job* cj);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
|
|
|
// in balance.c
|
|
|
|
NTSTATUS start_balance(device_extension* Vcb, void* data, ULONG length, KPROCESSOR_MODE processor_mode);
|
|
|
|
NTSTATUS query_balance(device_extension* Vcb, void* data, ULONG length);
|
|
|
|
NTSTATUS pause_balance(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
|
|
|
NTSTATUS resume_balance(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
|
|
|
NTSTATUS stop_balance(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS look_for_balance_item(_Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb);
|
2017-01-01 17:12:12 +00:00
|
|
|
NTSTATUS remove_device(device_extension* Vcb, void* data, ULONG length, KPROCESSOR_MODE processor_mode);
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
_Function_class_(KSTART_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
void __stdcall balance_thread(void* context);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
// in volume.c
|
|
|
|
NTSTATUS vol_create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
|
|
|
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
|
|
|
NTSTATUS vol_read(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
|
|
|
NTSTATUS vol_write(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
|
|
|
NTSTATUS vol_device_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
|
2019-09-01 12:53:20 +00:00
|
|
|
void add_volume_device(superblock* sb, PUNICODE_STRING devpath, uint64_t length, ULONG disk_num, ULONG part_num);
|
2017-09-08 08:02:43 +00:00
|
|
|
NTSTATUS mountmgr_add_drive_letter(PDEVICE_OBJECT mountmgr, PUNICODE_STRING devpath);
|
|
|
|
|
|
|
|
_Function_class_(DRIVER_NOTIFICATION_CALLBACK_ROUTINE)
|
2019-09-01 12:53:20 +00:00
|
|
|
NTSTATUS __stdcall pnp_removal(PVOID NotificationStructure, PVOID Context);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
void free_vol(volume_device_extension* vde);
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
// in scrub.c
|
|
|
|
NTSTATUS start_scrub(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
|
|
|
NTSTATUS query_scrub(device_extension* Vcb, KPROCESSOR_MODE processor_mode, void* data, ULONG length);
|
|
|
|
NTSTATUS pause_scrub(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
|
|
|
NTSTATUS resume_scrub(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
|
|
|
NTSTATUS stop_scrub(device_extension* Vcb, KPROCESSOR_MODE processor_mode);
|
|
|
|
|
|
|
|
// in send.c
|
|
|
|
NTSTATUS send_subvol(device_extension* Vcb, void* data, ULONG datalen, PFILE_OBJECT FileObject, PIRP Irp);
|
|
|
|
NTSTATUS read_send_buffer(device_extension* Vcb, PFILE_OBJECT FileObject, void* data, ULONG datalen, ULONG_PTR* retlen, KPROCESSOR_MODE processor_mode);
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
// in fsrtl.c
|
2019-11-12 18:32:46 +00:00
|
|
|
NTSTATUS __stdcall compat_FsRtlValidateReparsePointBuffer(IN ULONG BufferLength, IN PREPARSE_DATA_BUFFER ReparseBuffer);
|
2019-09-01 12:53:20 +00:00
|
|
|
|
|
|
|
// in boot.c
|
2022-04-28 19:34:48 +00:00
|
|
|
void check_system_root();
|
2020-04-23 02:38:57 +00:00
|
|
|
void boot_add_device(DEVICE_OBJECT* pdo);
|
|
|
|
extern BTRFS_UUID boot_uuid;
|
2019-09-01 12:53:20 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
// based on function in sys/sysmacros.h
|
2019-09-01 12:53:20 +00:00
|
|
|
#define makedev(major, minor) (((minor) & 0xFF) | (((major) & 0xFFF) << 8) | (((uint64_t)((minor) & ~0xFF)) << 12) | (((uint64_t)((major) & ~0xFFF)) << 32))
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-11-12 23:03:22 +00:00
|
|
|
#ifndef __REACTOS__
|
2019-11-12 18:32:46 +00:00
|
|
|
// not in mingw yet
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
typedef struct {
|
2022-04-28 19:35:40 +00:00
|
|
|
FSRTL_COMMON_FCB_HEADER Header;
|
2019-11-12 18:32:46 +00:00
|
|
|
PFAST_MUTEX FastMutex;
|
|
|
|
LIST_ENTRY FilterContexts;
|
|
|
|
EX_PUSH_LOCK PushLock;
|
|
|
|
PVOID* FileContextSupportPointer;
|
|
|
|
union {
|
|
|
|
OPLOCK Oplock;
|
|
|
|
PVOID ReservedForRemote;
|
|
|
|
};
|
|
|
|
PVOID ReservedContext;
|
|
|
|
} FSRTL_ADVANCED_FCB_HEADER_NEW;
|
|
|
|
|
|
|
|
#define FSRTL_FCB_HEADER_V2 2
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define FSRTL_ADVANCED_FCB_HEADER_NEW FSRTL_ADVANCED_FCB_HEADER
|
|
|
|
#endif
|
2019-11-12 23:03:22 +00:00
|
|
|
#else
|
|
|
|
typedef struct {
|
2022-04-28 19:35:40 +00:00
|
|
|
FSRTL_COMMON_FCB_HEADER Header;
|
2019-11-12 23:03:22 +00:00
|
|
|
PFAST_MUTEX FastMutex;
|
|
|
|
LIST_ENTRY FilterContexts;
|
|
|
|
EX_PUSH_LOCK PushLock;
|
|
|
|
PVOID* FileContextSupportPointer;
|
|
|
|
union {
|
|
|
|
OPLOCK Oplock;
|
|
|
|
PVOID ReservedForRemote;
|
|
|
|
};
|
|
|
|
PVOID ReservedContext;
|
|
|
|
} FSRTL_ADVANCED_FCB_HEADER_NEW;
|
|
|
|
|
|
|
|
#define FSRTL_FCB_HEADER_V2 2
|
2020-04-23 02:38:57 +00:00
|
|
|
#endif // __REACTOS__
|
2019-11-12 18:32:46 +00:00
|
|
|
|
|
|
|
static __inline POPLOCK fcb_oplock(fcb* fcb) {
|
|
|
|
if (fcb->Header.Version >= FSRTL_FCB_HEADER_V2)
|
|
|
|
return &((FSRTL_ADVANCED_FCB_HEADER_NEW*)&fcb->Header)->Oplock;
|
|
|
|
else
|
|
|
|
return &fcb->oplock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline FAST_IO_POSSIBLE fast_io_possible(fcb* fcb) {
|
|
|
|
if (!FsRtlOplockIsFastIoPossible(fcb_oplock(fcb)))
|
|
|
|
return FastIoIsNotPossible;
|
|
|
|
|
|
|
|
if (!FsRtlAreThereCurrentFileLocks(&fcb->lock) && !fcb->Vcb->readonly)
|
|
|
|
return FastIoIsPossible;
|
|
|
|
|
|
|
|
return FastIoIsQuestionable;
|
|
|
|
}
|
2016-05-05 17:26:47 +00:00
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
static __inline void print_open_trees(device_extension* Vcb) {
|
|
|
|
LIST_ENTRY* le = Vcb->trees.Flink;
|
|
|
|
while (le != &Vcb->trees) {
|
|
|
|
tree* t = CONTAINING_RECORD(le, tree, list_entry);
|
|
|
|
tree_data* td = CONTAINING_RECORD(t->itemlist.Flink, tree_data, list_entry);
|
2019-09-01 12:53:20 +00:00
|
|
|
ERR("tree %p: root %I64x, level %u, first key (%I64x,%x,%I64x)\n",
|
2016-05-05 17:26:47 +00:00
|
|
|
t, t->root->id, t->header.level, td->key.obj_id, td->key.obj_type, td->key.offset);
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
le = le->Flink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
static __inline bool write_fcb_compressed(fcb* fcb) {
|
2022-09-28 16:08:10 +00:00
|
|
|
if (fcb->inode_item.flags & BTRFS_INODE_NODATACOW)
|
|
|
|
return false;
|
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
// make sure we don't accidentally write the cache inodes or pagefile compressed
|
|
|
|
if (fcb->subvol->id == BTRFS_ROOT_ROOT || fcb->Header.Flags2 & FSRTL_FLAG2_IS_PAGING_FILE)
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (fcb->Vcb->options.compress_force)
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (fcb->inode_item.flags & BTRFS_INODE_NOCOMPRESS)
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2016-09-04 15:27:46 +00:00
|
|
|
if (fcb->inode_item.flags & BTRFS_INODE_COMPRESS || fcb->Vcb->options.compress)
|
2019-09-01 12:53:20 +00:00
|
|
|
return true;
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
return false;
|
2016-09-04 15:27:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:24:26 +00:00
|
|
|
#ifdef DEBUG_FCB_REFCOUNTS
|
|
|
|
#ifdef DEBUG_LONG_MESSAGES
|
|
|
|
#define increase_fileref_refcount(fileref) {\
|
|
|
|
LONG rc = InterlockedIncrement(&fileref->refcount);\
|
|
|
|
MSG(funcname, __FILE__, __LINE__, "fileref %p: refcount now %i\n", 1, fileref, rc);\
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define increase_fileref_refcount(fileref) {\
|
|
|
|
LONG rc = InterlockedIncrement(&fileref->refcount);\
|
|
|
|
MSG(funcname, "fileref %p: refcount now %i\n", 1, fileref, rc);\
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define increase_fileref_refcount(fileref) InterlockedIncrement(&fileref->refcount)
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define int3 __debugbreak()
|
|
|
|
#else
|
|
|
|
#define int3 asm("int3;")
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#define hex_digit(c) ((c) <= 9) ? ((c) + '0') : ((c) - 10 + 'a')
|
2016-03-23 20:35:05 +00:00
|
|
|
|
|
|
|
// FIXME - find a way to catch unfreed trees again
|
|
|
|
|
|
|
|
// from sys/stat.h
|
|
|
|
#define __S_IFMT 0170000 /* These bits determine file type. */
|
|
|
|
#define __S_IFDIR 0040000 /* Directory. */
|
|
|
|
#define __S_IFCHR 0020000 /* Character device. */
|
|
|
|
#define __S_IFBLK 0060000 /* Block device. */
|
|
|
|
#define __S_IFREG 0100000 /* Regular file. */
|
|
|
|
#define __S_IFIFO 0010000 /* FIFO. */
|
|
|
|
#define __S_IFLNK 0120000 /* Symbolic link. */
|
|
|
|
#define __S_IFSOCK 0140000 /* Socket. */
|
|
|
|
#define __S_ISTYPE(mode, mask) (((mode) & __S_IFMT) == (mask))
|
|
|
|
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
#ifndef S_IRUSR
|
|
|
|
#define S_IRUSR 0000400
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_IWUSR
|
|
|
|
#define S_IWUSR 0000200
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifndef S_IXUSR
|
|
|
|
#define S_IXUSR 0000100
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __REACTOS__
|
|
|
|
#define S_IFDIR __S_IFDIR
|
|
|
|
#define S_IFREG __S_IFREG
|
|
|
|
#endif /* __REACTOS__ */
|
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
#ifndef S_IRGRP
|
|
|
|
#define S_IRGRP (S_IRUSR >> 3)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_IWGRP
|
|
|
|
#define S_IWGRP (S_IWUSR >> 3)
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifndef S_IXGRP
|
|
|
|
#define S_IXGRP (S_IXUSR >> 3)
|
|
|
|
#endif
|
|
|
|
|
2016-05-05 17:26:47 +00:00
|
|
|
#ifndef S_IROTH
|
|
|
|
#define S_IROTH (S_IRGRP >> 3)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_IWOTH
|
|
|
|
#define S_IWOTH (S_IWGRP >> 3)
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 20:35:05 +00:00
|
|
|
#ifndef S_IXOTH
|
|
|
|
#define S_IXOTH (S_IXGRP >> 3)
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifndef S_ISUID
|
|
|
|
#define S_ISUID 0004000
|
2016-10-29 17:05:10 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifndef S_ISGID
|
|
|
|
#define S_ISGID 0002000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISVTX
|
|
|
|
#define S_ISVTX 0001000
|
|
|
|
#endif
|
|
|
|
|
2018-12-16 11:03:16 +00:00
|
|
|
// based on functions in sys/sysmacros.h
|
2019-09-01 12:53:20 +00:00
|
|
|
#define major(rdev) ((((rdev) >> 8) & 0xFFF) | ((uint32_t)((rdev) >> 32) & ~0xFFF))
|
|
|
|
#define minor(rdev) (((rdev) & 0xFF) | ((uint32_t)((rdev) >> 12) & ~0xFF))
|
2018-12-16 11:03:16 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
static __inline uint64_t fcb_alloc_size(fcb* fcb) {
|
2017-09-08 08:02:43 +00:00
|
|
|
if (S_ISDIR(fcb->inode_item.st_mode))
|
|
|
|
return 0;
|
|
|
|
else if (fcb->atts & FILE_ATTRIBUTE_SPARSE_FILE)
|
|
|
|
return fcb->inode_item.st_blocks;
|
|
|
|
else
|
|
|
|
return sector_align(fcb->inode_item.st_size, fcb->Vcb->superblock.sector_size);
|
|
|
|
}
|
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef BOOLEAN (__stdcall *tPsIsDiskCountersEnabled)();
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef VOID (__stdcall *tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten,
|
|
|
|
ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef BOOLEAN (__stdcall *tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait,
|
|
|
|
PVOID Buffer, PETHREAD IoIssuerThread);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef BOOLEAN (__stdcall *tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait,
|
|
|
|
PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2017-09-08 08:02:43 +00:00
|
|
|
#ifndef CC_ENABLE_DISK_IO_ACCOUNTING
|
2017-01-01 17:12:12 +00:00
|
|
|
#define CC_ENABLE_DISK_IO_ACCOUNTING 0x00000010
|
2017-09-08 08:02:43 +00:00
|
|
|
#endif
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-09-01 12:53:20 +00:00
|
|
|
#if defined(__REACTOS__) && (NTDDI_VERSION < NTDDI_VISTA)
|
|
|
|
typedef struct _ECP_LIST ECP_LIST;
|
|
|
|
typedef struct _ECP_LIST *PECP_LIST;
|
|
|
|
#endif
|
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef VOID (__stdcall *tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags);
|
|
|
|
|
|
|
|
typedef VOID (__stdcall *tFsRtlUpdateDiskCounters)(ULONG64 BytesRead, ULONG64 BytesWritten);
|
|
|
|
|
|
|
|
typedef NTSTATUS (__stdcall *tIoUnregisterPlugPlayNotificationEx)(PVOID NotificationEntry);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef NTSTATUS (__stdcall *tFsRtlGetEcpListFromIrp)(PIRP Irp, PECP_LIST* EcpList);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef NTSTATUS (__stdcall *tFsRtlGetNextExtraCreateParameter)(PECP_LIST EcpList, PVOID CurrentEcpContext, LPGUID NextEcpType,
|
|
|
|
PVOID* NextEcpContext, ULONG* NextEcpContextSize);
|
2017-09-08 08:02:43 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef NTSTATUS (__stdcall *tFsRtlValidateReparsePointBuffer)(ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef BOOLEAN (__stdcall *tFsRtlCheckLockForOplockRequest)(PFILE_LOCK FileLock, PLARGE_INTEGER AllocationSize);
|
2017-01-01 17:12:12 +00:00
|
|
|
|
2019-11-12 18:32:46 +00:00
|
|
|
typedef BOOLEAN (__stdcall *tFsRtlAreThereCurrentOrInProgressFileLocks)(PFILE_LOCK FileLock);
|
2019-09-01 12:53:20 +00:00
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
#ifndef _MSC_VER
|
2019-11-12 18:32:46 +00:00
|
|
|
PEPROCESS __stdcall PsGetThreadProcess(_In_ PETHREAD Thread); // not in mingw
|
2017-09-08 08:02:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// not in DDK headers - taken from winternl.h
|
|
|
|
typedef struct _LDR_DATA_TABLE_ENTRY {
|
|
|
|
PVOID Reserved1[2];
|
|
|
|
LIST_ENTRY InMemoryOrderLinks;
|
|
|
|
PVOID Reserved2[2];
|
|
|
|
PVOID DllBase;
|
|
|
|
PVOID Reserved3[2];
|
|
|
|
UNICODE_STRING FullDllName;
|
|
|
|
BYTE Reserved4[8];
|
|
|
|
PVOID Reserved5[3];
|
|
|
|
union {
|
|
|
|
ULONG CheckSum;
|
|
|
|
PVOID Reserved6;
|
|
|
|
};
|
|
|
|
ULONG TimeDateStamp;
|
|
|
|
} LDR_DATA_TABLE_ENTRY,*PLDR_DATA_TABLE_ENTRY;
|
|
|
|
|
|
|
|
typedef struct _PEB_LDR_DATA {
|
|
|
|
BYTE Reserved1[8];
|
|
|
|
PVOID Reserved2[3];
|
|
|
|
LIST_ENTRY InMemoryOrderModuleList;
|
|
|
|
} PEB_LDR_DATA,*PPEB_LDR_DATA;
|
|
|
|
|
|
|
|
typedef struct _RTL_USER_PROCESS_PARAMETERS {
|
|
|
|
BYTE Reserved1[16];
|
|
|
|
PVOID Reserved2[10];
|
|
|
|
UNICODE_STRING ImagePathName;
|
|
|
|
UNICODE_STRING CommandLine;
|
|
|
|
} RTL_USER_PROCESS_PARAMETERS,*PRTL_USER_PROCESS_PARAMETERS;
|
|
|
|
|
|
|
|
typedef VOID (NTAPI *PPS_POST_PROCESS_INIT_ROUTINE)(VOID);
|
|
|
|
|
|
|
|
typedef struct _PEB {
|
|
|
|
BYTE Reserved1[2];
|
|
|
|
BYTE BeingDebugged;
|
|
|
|
BYTE Reserved2[1];
|
|
|
|
PVOID Reserved3[2];
|
|
|
|
PPEB_LDR_DATA Ldr;
|
|
|
|
PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
|
|
|
|
BYTE Reserved4[104];
|
|
|
|
PVOID Reserved5[52];
|
|
|
|
PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine;
|
|
|
|
BYTE Reserved6[128];
|
|
|
|
PVOID Reserved7[1];
|
|
|
|
ULONG SessionId;
|
|
|
|
} PEB,*PPEB;
|
2020-04-23 02:38:57 +00:00
|
|
|
#endif /* __REACTOS__ */
|
2017-09-08 08:02:43 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
__kernel_entry
|
|
|
|
NTSTATUS NTAPI ZwQueryInformationProcess(
|
|
|
|
IN HANDLE ProcessHandle,
|
|
|
|
IN PROCESSINFOCLASS ProcessInformationClass,
|
|
|
|
OUT PVOID ProcessInformation,
|
|
|
|
IN ULONG ProcessInformationLength,
|
|
|
|
OUT PULONG ReturnLength OPTIONAL
|
|
|
|
);
|
|
|
|
#endif
|