ReactOS  0.4.15-dev-439-g292f67a
btrfslib.c File Reference
#include <stdlib.h>
#include <stddef.h>
#include <time.h>
#include <ntstatus.h>
#include <windef.h>
#include <winbase.h>
#include <winternl.h>
#include <devioctl.h>
#include <ntdddisk.h>
#include <ntddscsi.h>
#include <ntddstor.h>
#include <ata.h>
#include <mountmgr.h>
#include <stringapiset.h>
#include <stdbool.h>
#include "../btrfs.h"
#include "../btrfsioctl.h"
#include "../crc32c.h"
#include "../xxhash.h"
Include dependency graph for btrfslib.c:

Go to the source code of this file.

Classes

struct  DSTRING
 
struct  STREAM_MESSAGE
 
struct  options
 
struct  btrfs_item
 
struct  btrfs_chunk
 
struct  btrfs_root
 
struct  btrfs_dev
 
struct  TEXTOUTPUT
 
struct  EXTENT_ITEM_METADATA
 
struct  EXTENT_ITEM_METADATA2
 

Macros

#define WIN32_NO_STATUS
 
#define SHA256_HASH_SIZE   32
 
#define BLAKE2_HASH_SIZE   32
 
#define FSCTL_LOCK_VOLUME   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 6, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define FSCTL_UNLOCK_VOLUME   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 7, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define FSCTL_DISMOUNT_VOLUME   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 8, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED   0x80000000
 
#define FORMAT_FLAG_QUICK_FORMAT   0x00000001
 
#define FORMAT_FLAG_UNKNOWN1   0x00000002
 
#define FORMAT_FLAG_DISMOUNT_FIRST   0x00000004
 
#define FORMAT_FLAG_UNKNOWN2   0x00000040
 
#define FORMAT_FLAG_LARGE_RECORDS   0x00000100
 
#define FORMAT_FLAG_INTEGRITY_DISABLE   0x00000100
 
#define keycmp(key1, key2)
 

Typedefs

typedef struct TEXTOUTPUTPTEXTOUTPUT
 
typedef BOOLEAN(NTAPIPFMIFSCALLBACK) (CALLBACKCOMMAND Command, ULONG SubAction, PVOID ActionInfo)
 

Enumerations

enum  FMIFS_MEDIA_FLAG {
  FMIFS_UNKNOWN0, FMIFS_UNKNOWN1, FMIFS_UNKNOWN2, FMIFS_UNKNOWN3,
  FMIFS_UNKNOWN4, FMIFS_UNKNOWN5, FMIFS_UNKNOWN6, FMIFS_UNKNOWN7,
  FMIFS_FLOPPY, FMIFS_UNKNOWN9, FMIFS_UNKNOWN10, FMIFS_REMOVABLE,
  FMIFS_HARDDISK, FMIFS_UNKNOWN13, FMIFS_UNKNOWN14, FMIFS_UNKNOWN15,
  FMIFS_UNKNOWN16, FMIFS_UNKNOWN17, FMIFS_UNKNOWN18, FMIFS_UNKNOWN19,
  FMIFS_UNKNOWN20, FMIFS_UNKNOWN21, FMIFS_UNKNOWN22, FMIFS_UNKNOWN23,
  FMIFS_UNKNOWN0, FMIFS_UNKNOWN1, FMIFS_UNKNOWN2, FMIFS_UNKNOWN3,
  FMIFS_UNKNOWN4, FMIFS_UNKNOWN5, FMIFS_UNKNOWN6, FMIFS_UNKNOWN7,
  FMIFS_FLOPPY, FMIFS_UNKNOWN9, FMIFS_UNKNOWN10, FMIFS_REMOVABLE,
  FMIFS_HARDDISK, FMIFS_UNKNOWN13, FMIFS_UNKNOWN14, FMIFS_UNKNOWN15,
  FMIFS_UNKNOWN16, FMIFS_UNKNOWN17, FMIFS_UNKNOWN18, FMIFS_UNKNOWN19,
  FMIFS_UNKNOWN20, FMIFS_UNKNOWN21, FMIFS_UNKNOWN22, FMIFS_UNKNOWN23
}
 
enum  CALLBACKCOMMAND {
  PROGRESS, DONEWITHSTRUCTURE, UNKNOWN2, UNKNOWN3,
  UNKNOWN4, UNKNOWN5, INSUFFICIENTRIGHTS, FSNOTSUPPORTED,
  VOLUMEINUSE, UNKNOWN9, UNKNOWNA, DONE,
  UNKNOWNC, UNKNOWND, OUTPUT, STRUCTUREPROGRESS,
  CLUSTERSIZETOOSMALL, PROGRESS, DONEWITHSTRUCTURE, UNKNOWN2,
  UNKNOWN3, UNKNOWN4, UNKNOWN5, INSUFFICIENTRIGHTS,
  FSNOTSUPPORTED, VOLUMEINUSE, UNKNOWN9, UNKNOWNA,
  DONE, UNKNOWNC, UNKNOWND, OUTPUT,
  STRUCTUREPROGRESS, CLUSTERSIZETOOSMALL
}
 

Functions

void calc_sha256 (uint8_t *hash, const void *input, size_t len)
 
void blake2b (void *out, size_t outlen, const void *in, size_t inlen)
 
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile (HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
 
NTSTATUS NTAPI NtWriteFile (HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
 
NTSTATUS NTAPI NtReadFile (HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
 
FORCEINLINE VOID InitializeListHead (PLIST_ENTRY ListHead)
 
FORCEINLINE VOID InsertTailList (PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
 
NTSTATUS WINAPI ChkdskEx (PUNICODE_STRING DriveRoot, BOOLEAN FixErrors, BOOLEAN Verbose, BOOLEAN CheckOnlyIfDirty, BOOLEAN ScanDrive, PFMIFSCALLBACK Callback)
 
static btrfs_rootadd_root (LIST_ENTRY *roots, uint64_t id)
 
static void free_roots (LIST_ENTRY *roots)
 
static void free_chunks (LIST_ENTRY *chunks)
 
static void add_item (btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
 
static uint64_t find_chunk_offset (uint64_t size, uint64_t offset, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid)
 
static btrfs_chunkadd_chunk (LIST_ENTRY *chunks, uint64_t flags, btrfs_root *chunk_root, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid, uint32_t sector_size)
 
static bool superblock_collision (btrfs_chunk *c, uint64_t address)
 
static uint64_t get_next_address (btrfs_chunk *c)
 
static void assign_addresses (LIST_ENTRY *roots, btrfs_chunk *sys_chunk, btrfs_chunk *metadata_chunk, uint32_t node_size, btrfs_root *root_root, btrfs_root *extent_root, bool skinny)
 
static NTSTATUS write_data (HANDLE h, uint64_t address, btrfs_chunk *c, void *data, ULONG size)
 
static void calc_tree_checksum (tree_header *th, uint32_t node_size)
 
static NTSTATUS write_roots (HANDLE h, LIST_ENTRY *roots, uint32_t node_size, BTRFS_UUID *fsuuid, BTRFS_UUID *chunkuuid)
 
static void get_uuid (BTRFS_UUID *uuid)
 
static void init_device (btrfs_dev *dev, uint64_t id, uint64_t size, BTRFS_UUID *fsuuid, uint32_t sector_size)
 
static void calc_superblock_checksum (superblock *sb)
 
static NTSTATUS write_superblocks (HANDLE h, btrfs_dev *dev, btrfs_root *chunk_root, btrfs_root *root_root, btrfs_root *extent_root, btrfs_chunk *sys_chunk, uint32_t node_size, BTRFS_UUID *fsuuid, uint32_t sector_size, PUNICODE_STRING label, uint64_t incompat_flags)
 
static __inline void win_time_to_unix (LARGE_INTEGER t, BTRFS_TIME *out)
 
static void add_inode_ref (btrfs_root *r, uint64_t inode, uint64_t parent, uint64_t index, const char *name)
 
static void init_fs_tree (btrfs_root *r, uint32_t node_size)
 
static void add_block_group_items (LIST_ENTRY *chunks, btrfs_root *extent_root)
 
static NTSTATUS clear_first_megabyte (HANDLE h)
 
static bool is_ssd (HANDLE h)
 
static void add_dir_item (btrfs_root *root, uint64_t inode, uint32_t hash, uint64_t key_objid, uint8_t key_type, uint64_t key_offset, uint64_t transid, uint8_t type, const char *name)
 
static void set_default_subvol (btrfs_root *root_root, uint32_t node_size)
 
static NTSTATUS write_btrfs (HANDLE h, uint64_t size, PUNICODE_STRING label, uint32_t sector_size, uint32_t node_size, uint64_t incompat_flags)
 
static bool look_for_device (btrfs_filesystem *bfs, BTRFS_UUID *devuuid)
 
static bool check_superblock_checksum (superblock *sb)
 
static bool is_mounted_multi_device (HANDLE h, uint32_t sector_size)
 
static void do_full_trim (HANDLE h)
 
static bool is_power_of_two (ULONG i)
 
static NTSTATUS NTAPI FormatEx2 (PUNICODE_STRING DriveRoot, FMIFS_MEDIA_FLAG MediaFlag, PUNICODE_STRING Label, BOOLEAN QuickFormat, ULONG ClusterSize, PFMIFSCALLBACK Callback)
 
BOOL __stdcall FormatEx (DSTRING *root, STREAM_MESSAGE *message, options *opts, uint32_t unk1)
 
void __stdcall SetSizes (ULONG sector, ULONG node)
 
void __stdcall SetIncompatFlags (uint64_t incompat_flags)
 
void __stdcall SetCsumType (uint16_t csum_type)
 
BOOL __stdcall GetFilesystemInformation (uint32_t unk1, uint32_t unk2, void *unk3)
 
BOOL APIENTRY DllMain (HANDLE hModule, DWORD dwReason, void *lpReserved)
 

Variables

HMODULE module
 
ULONG def_sector_size = 0
 
ULONG def_node_size = 0
 
uint64_t def_incompat_flags = BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
 
uint16_t def_csum_type = CSUM_TYPE_CRC32C
 

Macro Definition Documentation

◆ BLAKE2_HASH_SIZE

#define BLAKE2_HASH_SIZE   32

Definition at line 65 of file btrfslib.c.

◆ DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED

#define DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED   0x80000000

Definition at line 74 of file btrfslib.c.

◆ FORMAT_FLAG_DISMOUNT_FIRST

#define FORMAT_FLAG_DISMOUNT_FIRST   0x00000004

Definition at line 105 of file btrfslib.c.

◆ FORMAT_FLAG_INTEGRITY_DISABLE

#define FORMAT_FLAG_INTEGRITY_DISABLE   0x00000100

Definition at line 108 of file btrfslib.c.

◆ FORMAT_FLAG_LARGE_RECORDS

#define FORMAT_FLAG_LARGE_RECORDS   0x00000100

Definition at line 107 of file btrfslib.c.

◆ FORMAT_FLAG_QUICK_FORMAT

#define FORMAT_FLAG_QUICK_FORMAT   0x00000001

Definition at line 103 of file btrfslib.c.

◆ FORMAT_FLAG_UNKNOWN1

#define FORMAT_FLAG_UNKNOWN1   0x00000002

Definition at line 104 of file btrfslib.c.

◆ FORMAT_FLAG_UNKNOWN2

#define FORMAT_FLAG_UNKNOWN2   0x00000040

Definition at line 106 of file btrfslib.c.

◆ FSCTL_DISMOUNT_VOLUME

Definition at line 71 of file btrfslib.c.

◆ FSCTL_LOCK_VOLUME

Definition at line 69 of file btrfslib.c.

◆ FSCTL_UNLOCK_VOLUME

Definition at line 70 of file btrfslib.c.

◆ keycmp

#define keycmp (   key1,
  key2 
)
Value:
((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))))))
GLuint64EXT GLuint GLuint GLenum GLenum GLuint GLuint GLenum GLuint GLuint key1
Definition: glext.h:10608

Definition at line 165 of file btrfslib.c.

◆ SHA256_HASH_SIZE

#define SHA256_HASH_SIZE   32

Definition at line 62 of file btrfslib.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 22 of file btrfslib.c.

Typedef Documentation

◆ PFMIFSCALLBACK

typedef BOOLEAN(NTAPI* PFMIFSCALLBACK) (CALLBACKCOMMAND Command, ULONG SubAction, PVOID ActionInfo)

Definition at line 233 of file btrfslib.c.

◆ PTEXTOUTPUT

Enumeration Type Documentation

◆ CALLBACKCOMMAND

Enumerator
PROGRESS 
DONEWITHSTRUCTURE 
UNKNOWN2 
UNKNOWN3 
UNKNOWN4 
UNKNOWN5 
INSUFFICIENTRIGHTS 
FSNOTSUPPORTED 
VOLUMEINUSE 
UNKNOWN9 
UNKNOWNA 
DONE 
UNKNOWNC 
UNKNOWND 
OUTPUT 
STRUCTUREPROGRESS 
CLUSTERSIZETOOSMALL 
PROGRESS 
DONEWITHSTRUCTURE 
UNKNOWN2 
UNKNOWN3 
UNKNOWN4 
UNKNOWN5 
INSUFFICIENTRIGHTS 
FSNOTSUPPORTED 
VOLUMEINUSE 
UNKNOWN9 
UNKNOWNA 
DONE 
UNKNOWNC 
UNKNOWND 
OUTPUT 
STRUCTUREPROGRESS 
CLUSTERSIZETOOSMALL 

Definition at line 213 of file btrfslib.c.

◆ FMIFS_MEDIA_FLAG

Enumerator
FMIFS_UNKNOWN0 
FMIFS_UNKNOWN1 
FMIFS_UNKNOWN2 
FMIFS_UNKNOWN3 
FMIFS_UNKNOWN4 
FMIFS_UNKNOWN5 
FMIFS_UNKNOWN6 
FMIFS_UNKNOWN7 
FMIFS_FLOPPY 
FMIFS_UNKNOWN9 
FMIFS_UNKNOWN10 
FMIFS_REMOVABLE 
FMIFS_HARDDISK 
FMIFS_UNKNOWN13 
FMIFS_UNKNOWN14 
FMIFS_UNKNOWN15 
FMIFS_UNKNOWN16 
FMIFS_UNKNOWN17 
FMIFS_UNKNOWN18 
FMIFS_UNKNOWN19 
FMIFS_UNKNOWN20 
FMIFS_UNKNOWN21 
FMIFS_UNKNOWN22 
FMIFS_UNKNOWN23 
FMIFS_UNKNOWN0 
FMIFS_UNKNOWN1 
FMIFS_UNKNOWN2 
FMIFS_UNKNOWN3 
FMIFS_UNKNOWN4 
FMIFS_UNKNOWN5 
FMIFS_UNKNOWN6 
FMIFS_UNKNOWN7 
FMIFS_FLOPPY 
FMIFS_UNKNOWN9 
FMIFS_UNKNOWN10 
FMIFS_REMOVABLE 
FMIFS_HARDDISK 
FMIFS_UNKNOWN13 
FMIFS_UNKNOWN14 
FMIFS_UNKNOWN15 
FMIFS_UNKNOWN16 
FMIFS_UNKNOWN17 
FMIFS_UNKNOWN18 
FMIFS_UNKNOWN19 
FMIFS_UNKNOWN20 
FMIFS_UNKNOWN21 
FMIFS_UNKNOWN22 
FMIFS_UNKNOWN23 

Definition at line 186 of file btrfslib.c.

186  {
195  FMIFS_FLOPPY,
FMIFS_MEDIA_FLAG
Definition: btrfslib.c:186

Function Documentation

◆ add_block_group_items()

static void add_block_group_items ( LIST_ENTRY chunks,
btrfs_root extent_root 
)
static

Definition at line 987 of file btrfslib.c.

987  {
988  LIST_ENTRY* le;
989 
990  le = chunks->Flink;
991  while (le != chunks) {
993  BLOCK_GROUP_ITEM bgi;
994 
995  bgi.used = c->used;
996  bgi.chunk_tree = 0x100;
997  bgi.flags = c->chunk_item->type;
998  add_item(extent_root, c->offset, TYPE_BLOCK_GROUP_ITEM, c->chunk_item->size, &bgi, sizeof(BLOCK_GROUP_ITEM));
999 
1000  le = le->Flink;
1001  }
1002 }
uint64_t flags
Definition: btrfs.h:414
uint64_t used
Definition: btrfs.h:412
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
const GLubyte * c
Definition: glext.h:8905
#define TYPE_BLOCK_GROUP_ITEM
Definition: btrfs.h:38
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
Definition: typedefs.h:118
uint64_t chunk_tree
Definition: btrfs.h:413
Definition: list.h:27

Referenced by write_btrfs().

◆ add_chunk()

static btrfs_chunk* add_chunk ( LIST_ENTRY chunks,
uint64_t  flags,
btrfs_root chunk_root,
btrfs_dev dev,
btrfs_root dev_root,
BTRFS_UUID chunkuuid,
uint32_t  sector_size 
)
static

Definition at line 392 of file btrfslib.c.

392  {
393  uint64_t off, size;
394  uint16_t stripes, i;
395  btrfs_chunk* c;
396  LIST_ENTRY* le;
397  CHUNK_ITEM_STRIPE* cis;
398 
399  off = 0xc00000;
400  le = chunks->Flink;
401  while (le != chunks) {
403 
404  if (c->offset + c->chunk_item->size > off)
405  off = c->offset + c->chunk_item->size;
406 
407  le = le->Flink;
408  }
409 
410  if (flags & BLOCK_FLAG_METADATA) {
411  if (dev->dev_item.num_bytes > 0xC80000000) // 50 GB
412  size = 0x40000000; // 1 GB
413  else
414  size = 0x10000000; // 256 MB
415  } else if (flags & BLOCK_FLAG_SYSTEM)
416  size = 0x800000;
417 
418  size = min(size, dev->dev_item.num_bytes / 10); // cap at 10%
419  size &= ~(sector_size - 1);
420 
421  stripes = flags & BLOCK_FLAG_DUPLICATE ? 2 : 1;
422 
423  if (dev->dev_item.num_bytes - dev->dev_item.bytes_used < stripes * size) // not enough space
424  return NULL;
425 
426 #ifndef __REACTOS__
427  c = malloc(sizeof(btrfs_chunk));
428 #else
429  c = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(btrfs_chunk));
430 #endif
431  c->offset = off;
432  c->lastoff = off;
433  c->used = 0;
434 
435 #ifndef __REACTOS__
436  c->chunk_item = malloc(sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
437 #else
438  c->chunk_item = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
439 #endif
440 
441  c->chunk_item->size = size;
442  c->chunk_item->root_id = BTRFS_ROOT_EXTENT;
443  c->chunk_item->stripe_length = max(sector_size, 0x10000);
444  c->chunk_item->type = flags;
445  c->chunk_item->opt_io_alignment = max(sector_size, 0x10000);
446  c->chunk_item->opt_io_width = max(sector_size, 0x10000);
447  c->chunk_item->sector_size = sector_size;
448  c->chunk_item->num_stripes = stripes;
449  c->chunk_item->sub_stripes = 0;
450 
451  cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
452 
453  for (i = 0; i < stripes; i++) {
454  cis[i].dev_id = dev->dev_item.dev_id;
455  cis[i].offset = find_chunk_offset(size, c->offset, dev, dev_root, chunkuuid);
456  cis[i].dev_uuid = dev->dev_item.device_uuid;
457  }
458 
459  add_item(chunk_root, 0x100, TYPE_CHUNK_ITEM, c->offset, c->chunk_item, sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
460 
461  InsertTailList(chunks, &c->list_entry);
462 
463  return c;
464 }
#define max(a, b)
Definition: svc.c:63
static uint64_t find_chunk_offset(uint64_t size, uint64_t offset, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid)
Definition: btrfslib.c:372
uint64_t dev_id
Definition: btrfs.h:340
#define TYPE_CHUNK_ITEM
Definition: btrfs.h:44
unsigned short int uint16_t
Definition: acefiex.h:54
uint64_t offset
Definition: btrfs.h:341
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
FORCEINLINE VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
Definition: btrfslib.c:122
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:76
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
#define for
Definition: utility.h:88
BTRFS_UUID dev_uuid
Definition: btrfs.h:342
GLbitfield flags
Definition: glext.h:7161
#define BLOCK_FLAG_METADATA
Definition: shellext.h:77
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
Definition: typedefs.h:118
__u8 sector_size[2]
Definition: mkdosfs.c:361
UINT64 uint64_t
Definition: types.h:77
#define min(a, b)
Definition: monoChain.cc:55
Definition: list.h:27
uint64_t dev_id
#define c
Definition: ke_i.h:80
#define malloc
Definition: debug_ros.c:4
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:80
#define BTRFS_ROOT_EXTENT
Definition: btrfs.h:51
off
Definition: i386-dis.c:3909

Referenced by write_btrfs().

◆ add_dir_item()

static void add_dir_item ( btrfs_root root,
uint64_t  inode,
uint32_t  hash,
uint64_t  key_objid,
uint8_t  key_type,
uint64_t  key_offset,
uint64_t  transid,
uint8_t  type,
const char name 
)
static

Definition at line 1077 of file btrfslib.c.

1078  {
1079  uint16_t name_len = (uint16_t)strlen(name);
1080 #ifndef __REACTOS__
1081  DIR_ITEM* di = malloc(offsetof(DIR_ITEM, name[0]) + name_len);
1082 #else
1083  DIR_ITEM* di = RtlAllocateHeap(RtlGetProcessHeap(), 0, offsetof(DIR_ITEM, name[0]) + name_len);
1084 #endif
1085 
1086  di->key.obj_id = key_objid;
1087  di->key.obj_type = key_type;
1088  di->key.offset = key_offset;
1089  di->transid = transid;
1090  di->m = 0;
1091  di->n = name_len;
1092  di->type = type;
1093  memcpy(di->name, name, name_len);
1094 
1095  add_item(root, inode, TYPE_DIR_ITEM, hash, di, (uint16_t)(offsetof(DIR_ITEM, name[0]) + di->m + di->n));
1096 
1097 #ifndef __REACTOS__
1098  free(di);
1099 #else
1100  RtlFreeHeap(RtlGetProcessHeap(), 0, di);
1101 #endif
1102 }
uint64_t obj_id
Definition: btrfs.h:137
uint8_t obj_type
Definition: btrfs.h:138
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
unsigned short int uint16_t
Definition: acefiex.h:54
#define uint16_t
Definition: nsiface.idl:60
uint64_t offset
Definition: btrfs.h:139
Definition: fs.h:78
uint16_t m
Definition: btrfs.h:268
KEY key
Definition: btrfs.h:266
char name[1]
Definition: btrfs.h:271
#define offsetof(TYPE, MEMBER)
uint8_t type
Definition: btrfs.h:270
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
#define TYPE_DIR_ITEM
Definition: btrfs.h:24
Definition: name.c:38
#define malloc
Definition: debug_ros.c:4
uint64_t transid
Definition: btrfs.h:267
uint16_t n
Definition: btrfs.h:269
Definition: _hash_fun.h:40

Referenced by set_default_subvol().

◆ add_inode_ref()

static void add_inode_ref ( btrfs_root r,
uint64_t  inode,
uint64_t  parent,
uint64_t  index,
const char name 
)
static

Definition at line 942 of file btrfslib.c.

942  {
943  uint16_t name_len = (uint16_t)strlen(name);
944 #ifndef __REACTOS__
945  INODE_REF* ir = malloc(offsetof(INODE_REF, name[0]) + name_len);
946 #else
947  INODE_REF* ir = RtlAllocateHeap(RtlGetProcessHeap(), 0, offsetof(INODE_REF, name[0]) + name_len);
948 #endif
949 
950  ir->index = 0;
951  ir->n = name_len;
952  memcpy(ir->name, name, name_len);
953 
955 
956 #ifndef __REACTOS__
957  free(ir);
958 #else
959  RtlFreeHeap(RtlGetProcessHeap(), 0, ir);
960 #endif
961 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
unsigned short int uint16_t
Definition: acefiex.h:54
#define uint16_t
Definition: nsiface.idl:60
Definition: fs.h:78
char name[1]
Definition: btrfs.h:365
#define offsetof(TYPE, MEMBER)
#define TYPE_INODE_REF
Definition: btrfs.h:20
uint16_t n
Definition: btrfs.h:364
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
r parent
Definition: btrfs.c:2944
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
uint64_t index
Definition: btrfs.h:363
Definition: name.c:38
#define malloc
Definition: debug_ros.c:4

Referenced by init_fs_tree(), and set_default_subvol().

◆ add_item()

static void add_item ( btrfs_root r,
uint64_t  obj_id,
uint8_t  obj_type,
uint64_t  offset,
void data,
uint16_t  size 
)
static

Definition at line 331 of file btrfslib.c.

331  {
332  LIST_ENTRY* le;
333  btrfs_item* item;
334 
335 #ifndef __REACTOS__
336  item = malloc(sizeof(btrfs_item));
337 #else
338  item = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(btrfs_item));
339 #endif
340 
341  item->key.obj_id = obj_id;
342  item->key.obj_type = obj_type;
343  item->key.offset = offset;
344  item->size = size;
345 
346  if (size == 0)
347  item->data = NULL;
348  else {
349 #ifndef __REACTOS__
350  item->data = malloc(size);
351 #else
352  item->data = RtlAllocateHeap(RtlGetProcessHeap(), 0, size);
353 #endif
354  memcpy(item->data, data, size);
355  }
356 
357  le = r->items.Flink;
358  while (le != &r->items) {
360 
361  if (keycmp(item->key, i2->key) != 1) {
362  InsertTailList(le, &item->list_entry);
363  return;
364  }
365 
366  le = le->Flink;
367  }
368 
369  InsertTailList(&r->items, &item->list_entry);
370 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLintptr offset
Definition: glext.h:5920
FORCEINLINE VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
Definition: btrfslib.c:122
smooth NULL
Definition: ftsmooth.c:416
struct btrfs_disk_key key
Definition: btrfs.h:110
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define keycmp(key1, key2)
Definition: btrfslib.c:165
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
GLsizeiptr size
Definition: glext.h:5919
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: typedefs.h:118
static ATOM item
Definition: dde.c:856
Definition: list.h:27
#define malloc
Definition: debug_ros.c:4

Referenced by add_block_group_items(), add_chunk(), add_dir_item(), add_inode_ref(), assign_addresses(), find_chunk_offset(), init_fs_tree(), set_default_subvol(), and write_btrfs().

◆ add_root()

static btrfs_root* add_root ( LIST_ENTRY roots,
uint64_t  id 
)
static

Definition at line 255 of file btrfslib.c.

255  {
256  btrfs_root* root;
257 
258 #ifdef __REACTOS__
259  root = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(btrfs_root));
260 #else
261  root = malloc(sizeof(btrfs_root));
262 #endif
263 
264  root->id = id;
265 #ifndef __REACTOS__
266  RtlZeroMemory(&root->header, sizeof(tree_header));
267 #endif
268  InitializeListHead(&root->items);
269  InsertTailList(roots, &root->list_entry);
270 
271  return root;
272 }
LIST_ENTRY list_entry
Definition: btrfs_drv.h:482
struct _root root
uint64_t id
Definition: btrfs_drv.h:467
FORCEINLINE VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
Definition: btrfslib.c:122
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead)
Definition: btrfslib.c:118
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
GLenum GLuint id
Definition: glext.h:5579
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define malloc
Definition: debug_ros.c:4

Referenced by look_for_roots(), mount_vol(), and write_btrfs().

◆ assign_addresses()

static void assign_addresses ( LIST_ENTRY roots,
btrfs_chunk sys_chunk,
btrfs_chunk metadata_chunk,
uint32_t  node_size,
btrfs_root root_root,
btrfs_root extent_root,
bool  skinny 
)
static

Definition at line 515 of file btrfslib.c.

516  {
517  LIST_ENTRY* le;
518 
519  le = roots->Flink;
520  while (le != roots) {
522  btrfs_chunk* c = r->id == BTRFS_ROOT_CHUNK ? sys_chunk : metadata_chunk;
523 
524  r->header.address = get_next_address(c);
525  r->c = c;
526  c->lastoff = r->header.address + node_size;
527  c->used += node_size;
528 
529  if (skinny) {
531 
532  eim.ei.refcount = 1;
533  eim.ei.generation = 1;
536  eim.tbr.offset = r->id;
537 
538  add_item(extent_root, r->header.address, TYPE_METADATA_ITEM, 0, &eim, sizeof(EXTENT_ITEM_METADATA));
539  } else {
541  KEY firstitem;
542 
543  if (r->items.Flink == &r->items) {
544  firstitem.obj_id = 0;
545  firstitem.obj_type = 0;
546  firstitem.offset = 0;
547  } else {
548  btrfs_item* bi = CONTAINING_RECORD(r->items.Flink, btrfs_item, list_entry);
549 
550  firstitem = bi->key;
551  }
552 
553  eim2.ei.refcount = 1;
554  eim2.ei.generation = 1;
556  eim2.ei2.firstitem = firstitem;
557  eim2.ei2.level = 0;
558  eim2.type = TYPE_TREE_BLOCK_REF;
559  eim2.tbr.offset = r->id;
560 
561  add_item(extent_root, r->header.address, TYPE_EXTENT_ITEM, node_size, &eim2, sizeof(EXTENT_ITEM_METADATA2));
562  }
563 
564  if (r->id != BTRFS_ROOT_ROOT && r->id != BTRFS_ROOT_CHUNK) {
565  ROOT_ITEM ri;
566 
567  memset(&ri, 0, sizeof(ROOT_ITEM));
568 
569  ri.inode.generation = 1;
570  ri.inode.st_size = 3;
571  ri.inode.st_blocks = node_size;
572  ri.inode.st_nlink = 1;
573  ri.inode.st_mode = 040755;
574  ri.generation = 1;
575  ri.objid = r->id == 5 || r->id >= 0x100 ? SUBVOL_ROOT_INODE : 0;
576  ri.block_number = r->header.address;
577  ri.bytes_used = node_size;
578  ri.num_references = 1;
579  ri.generation2 = ri.generation;
580 
581  add_item(root_root, r->id, TYPE_ROOT_ITEM, 0, &ri, sizeof(ROOT_ITEM));
582  }
583 
584  le = le->Flink;
585  }
586 }
uint64_t obj_id
Definition: btrfs.h:137
uint8_t obj_type
Definition: btrfs.h:138
EXTENT_ITEM2 ei2
Definition: btrfslib.c:510
uint64_t bytes_used
Definition: btrfs.h:305
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define SUBVOL_ROOT_INODE
Definition: propsheet.cpp:42
#define TYPE_TREE_BLOCK_REF
Definition: btrfs.h:33
uint64_t block_number
Definition: btrfs.h:303
EXTENT_ITEM ei
Definition: btrfslib.c:509
TREE_BLOCK_REF tbr
Definition: btrfslib.c:512
#define TYPE_METADATA_ITEM
Definition: btrfs.h:32
uint64_t offset
Definition: btrfs.h:139
uint64_t generation2
Definition: btrfs.h:312
uint64_t refcount
Definition: btrfs.h:380
uint64_t generation
Definition: btrfs.h:301
uint32_t st_nlink
Definition: btrfs.h:285
uint32_t num_references
Definition: btrfs.h:308
#define TYPE_EXTENT_ITEM
Definition: btrfs.h:31
struct btrfs_disk_key key
Definition: btrfs.h:110
uint64_t offset
Definition: btrfs.h:401
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static uint64_t get_next_address(btrfs_chunk *c)
Definition: btrfslib.c:487
#define BTRFS_ROOT_ROOT
Definition: btrfs.h:50
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
uint64_t st_size
Definition: btrfs.h:282
uint64_t objid
Definition: btrfs.h:302
const GLubyte * c
Definition: glext.h:8905
KEY firstitem
Definition: btrfs.h:386
TREE_BLOCK_REF tbr
Definition: btrfslib.c:505
EXTENT_ITEM ei
Definition: btrfslib.c:503
uint8_t level
Definition: btrfs.h:387
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
Definition: typedefs.h:118
uint64_t generation
Definition: btrfs.h:280
uint64_t st_blocks
Definition: btrfs.h:283
uint64_t generation
Definition: btrfs.h:381
Definition: btrfs.h:136
INODE_ITEM inode
Definition: btrfs.h:300
#define EXTENT_ITEM_TREE_BLOCK
Definition: btrfs.h:376
#define TYPE_ROOT_ITEM
Definition: btrfs.h:28
Definition: list.h:27
#define c
Definition: ke_i.h:80
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:52
uint64_t flags
Definition: btrfs.h:382
#define memset(x, y, z)
Definition: compat.h:39
uint32_t st_mode
Definition: btrfs.h:288

Referenced by write_btrfs().

◆ blake2b()

void blake2b ( void out,
size_t  outlen,
const void in,
size_t  inlen 
)

Definition at line 237 of file blake2b-ref.c.

238 {
239  blake2b_state S[1];
240 
241  blake2b_init( S, outlen );
242 
243  blake2b_update( S, ( const uint8_t * )in, inlen );
244  blake2b_final( S, out, outlen );
245 }
Definition: movable.cpp:7
static FILE * out
Definition: regtests2xml.c:44
static void blake2b_init(blake2b_state *S, size_t outlen)
Definition: blake2b-ref.c:97
BYTE uint8_t
Definition: msvideo1.c:66
static int blake2b_update(blake2b_state *S, const void *in, size_t inlen)
Definition: blake2b-ref.c:185
GLuint in
Definition: glext.h:9616
static int blake2b_final(blake2b_state *S, void *out, size_t outlen)
Definition: blake2b-ref.c:212

Referenced by calc_superblock_checksum(), calc_thread_main(), calc_tree_checksum(), check_sector_csum(), check_superblock_checksum(), check_tree_checksum(), get_sector_csum(), and get_tree_checksum().

◆ calc_sha256()

void calc_sha256 ( uint8_t hash,
const void input,
size_t  len 
)

Definition at line 126 of file sha256.c.

127 {
128  /*
129  * Note 1: All integers (expect indexes) are 32-bit unsigned integers and addition is calculated modulo 2^32.
130  * Note 2: For each round, there is one round constant k[i] and one entry in the message schedule array w[i], 0 = i = 63
131  * Note 3: The compression function uses 8 working variables, a through h
132  * Note 4: Big-endian convention is used when expressing the constants in this pseudocode,
133  * and when parsing message block data from bytes to words, for example,
134  * the first word of the input message "abc" after padding is 0x61626380
135  */
136 
137  /*
138  * Initialize hash values:
139  * (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
140  */
141  uint32_t h[] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
142  unsigned i, j;
143 
144  /* 512-bit chunks is what we will operate on. */
145  uint8_t chunk[64];
146 
147  struct buffer_state state;
148 
150 
151  while (calc_chunk(chunk, &state)) {
152  uint32_t ah[8];
153 
154  const uint8_t *p = chunk;
155 
156  /* Initialize working variables to current hash value: */
157  for (i = 0; i < 8; i++)
158  ah[i] = h[i];
159 
160  /* Compression function main loop: */
161  for (i = 0; i < 4; i++) {
162  /*
163  * The w-array is really w[64], but since we only need
164  * 16 of them at a time, we save stack by calculating
165  * 16 at a time.
166  *
167  * This optimization was not there initially and the
168  * rest of the comments about w[64] are kept in their
169  * initial state.
170  */
171 
172  /*
173  * create a 64-entry message schedule array w[0..63] of 32-bit words
174  * (The initial values in w[0..63] don't matter, so many implementations zero them here)
175  * copy chunk into first 16 words w[0..15] of the message schedule array
176  */
177  uint32_t w[16];
178 
179  for (j = 0; j < 16; j++) {
180  if (i == 0) {
181  w[j] = (uint32_t) p[0] << 24 | (uint32_t) p[1] << 16 |
182  (uint32_t) p[2] << 8 | (uint32_t) p[3];
183  p += 4;
184  } else {
185  /* Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array: */
186  const uint32_t s0 = right_rot(w[(j + 1) & 0xf], 7) ^ right_rot(w[(j + 1) & 0xf], 18) ^ (w[(j + 1) & 0xf] >> 3);
187  const uint32_t s1 = right_rot(w[(j + 14) & 0xf], 17) ^ right_rot(w[(j + 14) & 0xf], 19) ^ (w[(j + 14) & 0xf] >> 10);
188  w[j] = w[j] + s0 + w[(j + 9) & 0xf] + s1;
189  }
190  {
191  const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25);
192  const uint32_t ch = (ah[4] & ah[5]) ^ (~ah[4] & ah[6]);
193  const uint32_t temp1 = ah[7] + s1 + ch + k[i << 4 | j] + w[j];
194  const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22);
195  const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]);
196  const uint32_t temp2 = s0 + maj;
197 
198  ah[7] = ah[6];
199  ah[6] = ah[5];
200  ah[5] = ah[4];
201  ah[4] = ah[3] + temp1;
202  ah[3] = ah[2];
203  ah[2] = ah[1];
204  ah[1] = ah[0];
205  ah[0] = temp1 + temp2;
206  }
207  }
208  }
209 
210  /* Add the compressed chunk to the current hash value: */
211  for (i = 0; i < 8; i++)
212  h[i] += ah[i];
213  }
214 
215  /* Produce the final hash value (big-endian): */
216  for (i = 0, j = 0; i < 8; i++)
217  {
218  hash[j++] = (uint8_t) (h[i] >> 24);
219  hash[j++] = (uint8_t) (h[i] >> 16);
220  hash[j++] = (uint8_t) (h[i] >> 8);
221  hash[j++] = (uint8_t) h[i];
222  }
223 }
static void init_buf_state(struct buffer_state *state, const void *input, size_t len)
Definition: sha256.c:52
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
static uint32_t right_rot(uint32_t value, unsigned int count)
Definition: sha256.c:43
static int calc_chunk(uint8_t chunk[CHUNK_SIZE], struct buffer_state *state)
Definition: sha256.c:62
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
struct S1 s1
static int state
Definition: maze.c:121
GLenum GLsizei len
Definition: glext.h:6722
BYTE uint8_t
Definition: msvideo1.c:66
static const uint32_t k[]
Definition: sha256.c:24
GLenum GLenum GLenum input
Definition: glext.h:9031
#define uint8_t
Definition: nsiface.idl:59
UINT32 uint32_t
Definition: types.h:75
GLfloat GLfloat p
Definition: glext.h:8902
#define uint32_t
Definition: nsiface.idl:61
Definition: _hash_fun.h:40

Referenced by calc_superblock_checksum(), calc_tree_checksum(), and check_superblock_checksum().

◆ calc_superblock_checksum()

static void calc_superblock_checksum ( superblock sb)
static

Definition at line 752 of file btrfslib.c.

752  {
753  switch (def_csum_type) {
754  case CSUM_TYPE_CRC32C:
755  *(uint32_t*)sb = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
756  break;
757 
758  case CSUM_TYPE_XXHASH:
759  *(uint64_t*)sb = XXH64(&sb->uuid, sizeof(superblock) - sizeof(sb->checksum), 0);
760  break;
761 
762  case CSUM_TYPE_SHA256:
763  calc_sha256((uint8_t*)sb, &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
764  break;
765 
766  case CSUM_TYPE_BLAKE2:
767  blake2b((uint8_t*)sb, BLAKE2_HASH_SIZE, &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
768  break;
769  }
770 }
superblock * sb
Definition: btrfs.c:4220
#define CSUM_TYPE_BLAKE2
Definition: btrfs.h:128
#define CSUM_TYPE_CRC32C
Definition: btrfs.h:125
uint8_t checksum[32]
Definition: btrfs.h:217
uint16_t def_csum_type
Definition: btrfslib.c:177
void blake2b(void *out, size_t outlen, const void *in, size_t inlen)
Definition: blake2b-ref.c:237
void calc_sha256(uint8_t *hash, const void *input, size_t len)
Definition: sha256.c:126
#define CSUM_TYPE_XXHASH
Definition: btrfs.h:126
crc_func calc_crc32c
Definition: crc32c.c:23
#define BLAKE2_HASH_SIZE
Definition: btrfslib.c:65
BYTE uint8_t
Definition: msvideo1.c:66
XXH_PUBLIC_API unsigned long long XXH64(const void *input, size_t len, unsigned long long seed)
Definition: xxhash.c:555
#define CSUM_TYPE_SHA256
Definition: btrfs.h:127
UINT64 uint64_t
Definition: types.h:77
BTRFS_UUID uuid
Definition: btrfs.h:218
UINT32 uint32_t
Definition: types.h:75
unsigned int ULONG
Definition: retypes.h:1

Referenced by write_superblocks().

◆ calc_tree_checksum()

static void calc_tree_checksum ( tree_header th,
uint32_t  node_size 
)
static

Definition at line 608 of file btrfslib.c.

608  {
609  switch (def_csum_type) {
610  case CSUM_TYPE_CRC32C:
611  *(uint32_t*)th = ~calc_crc32c(0xffffffff, (uint8_t*)&th->fs_uuid, node_size - sizeof(th->csum));
612  break;
613 
614  case CSUM_TYPE_XXHASH:
615  *(uint64_t*)th = XXH64((uint8_t*)&th->fs_uuid, node_size - sizeof(th->csum), 0);
616  break;
617 
618  case CSUM_TYPE_SHA256:
619  calc_sha256((uint8_t*)th, &th->fs_uuid, node_size - sizeof(th->csum));
620  break;
621 
622  case CSUM_TYPE_BLAKE2:
623  blake2b((uint8_t*)th, BLAKE2_HASH_SIZE, &th->fs_uuid, node_size - sizeof(th->csum));
624  break;
625  }
626 }
#define CSUM_TYPE_BLAKE2
Definition: btrfs.h:128
uint8_t csum[32]
Definition: btrfs.h:147
#define CSUM_TYPE_CRC32C
Definition: btrfs.h:125
uint16_t def_csum_type
Definition: btrfslib.c:177
void blake2b(void *out, size_t outlen, const void *in, size_t inlen)
Definition: blake2b-ref.c:237
void calc_sha256(uint8_t *hash, const void *input, size_t len)
Definition: sha256.c:126
#define CSUM_TYPE_XXHASH
Definition: btrfs.h:126
crc_func calc_crc32c
Definition: crc32c.c:23
#define BLAKE2_HASH_SIZE
Definition: btrfslib.c:65
BYTE uint8_t
Definition: msvideo1.c:66
XXH_PUBLIC_API unsigned long long XXH64(const void *input, size_t len, unsigned long long seed)
Definition: xxhash.c:555
#define CSUM_TYPE_SHA256
Definition: btrfs.h:127
UINT64 uint64_t
Definition: types.h:77
BTRFS_UUID fs_uuid
Definition: btrfs.h:148
UINT32 uint32_t
Definition: types.h:75

Referenced by write_roots().

◆ check_superblock_checksum()

static bool check_superblock_checksum ( superblock sb)
static

Definition at line 1240 of file btrfslib.c.

1240  {
1241  switch (sb->csum_type) {
1242  case CSUM_TYPE_CRC32C: {
1243  uint32_t crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
1244 
1245  return crc32 == *(uint32_t*)sb;
1246  }
1247 
1248  case CSUM_TYPE_XXHASH: {
1249  uint64_t hash = XXH64(&sb->uuid, sizeof(superblock) - sizeof(sb->checksum), 0);
1250 
1251  return hash == *(uint64_t*)sb;
1252  }
1253 
1254  case CSUM_TYPE_SHA256: {
1256 
1257  calc_sha256(hash, &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
1258 
1259  return !memcmp(hash, sb, SHA256_HASH_SIZE);
1260  }
1261 
1262  case CSUM_TYPE_BLAKE2: {
1264 
1265  blake2b(hash, sizeof(hash), &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
1266 
1267  return !memcmp(hash, sb, BLAKE2_HASH_SIZE);
1268  }
1269 
1270  default:
1271  return false;
1272  }
1273 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
uint32 __fastcall crc32(IN uint8 *s, IN uint32 len)
Definition: udf_info.cpp:4290
superblock * sb
Definition: btrfs.c:4220
#define CSUM_TYPE_BLAKE2
Definition: btrfs.h:128
#define CSUM_TYPE_CRC32C
Definition: btrfs.h:125
uint16_t csum_type
Definition: btrfs.h:240
uint8_t checksum[32]
Definition: btrfs.h:217
void blake2b(void *out, size_t outlen, const void *in, size_t inlen)
Definition: blake2b-ref.c:237
void calc_sha256(uint8_t *hash, const void *input, size_t len)
Definition: sha256.c:126
#define CSUM_TYPE_XXHASH
Definition: btrfs.h:126
crc_func calc_crc32c
Definition: crc32c.c:23
#define BLAKE2_HASH_SIZE
Definition: btrfslib.c:65
BYTE uint8_t
Definition: msvideo1.c:66
XXH_PUBLIC_API unsigned long long XXH64(const void *input, size_t len, unsigned long long seed)
Definition: xxhash.c:555
#define CSUM_TYPE_SHA256
Definition: btrfs.h:127
UINT64 uint64_t
Definition: types.h:77
BTRFS_UUID uuid
Definition: btrfs.h:218
UINT32 uint32_t
Definition: types.h:75
unsigned int ULONG
Definition: retypes.h:1
Definition: _hash_fun.h:40
#define SHA256_HASH_SIZE
Definition: btrfslib.c:62

Referenced by is_mounted_multi_device().

◆ ChkdskEx()

NTSTATUS WINAPI ChkdskEx ( PUNICODE_STRING  DriveRoot,
BOOLEAN  FixErrors,
BOOLEAN  Verbose,
BOOLEAN  CheckOnlyIfDirty,
BOOLEAN  ScanDrive,
PFMIFSCALLBACK  Callback 
)

Definition at line 236 of file btrfslib.c.

240  {
241  // STUB
242 
243  if (Callback) {
245 
246  TextOut.Lines = 1;
247  TextOut.Output = "stub, not implemented";
248 
249  Callback(OUTPUT, 0, &TextOut);
250  }
251 
252  return STATUS_SUCCESS;
253 }
#define TextOut
Definition: wingdi.h:4482
return STATUS_SUCCESS
Definition: btrfs.c:3014
LPFNPSPCALLBACK Callback
Definition: desk.c:112

◆ clear_first_megabyte()

static NTSTATUS clear_first_megabyte ( HANDLE  h)
static

Definition at line 1004 of file btrfslib.c.

1004  {
1005  NTSTATUS Status;
1008  uint8_t* mb;
1009 
1010 #ifndef __REACTOS__
1011  mb = malloc(0x100000);
1012  memset(mb, 0, 0x100000);
1013 #else
1014  mb = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, 0x100000);
1015 #endif
1016 
1017  zero.QuadPart = 0;
1018 
1019  Status = NtWriteFile(h, NULL, NULL, NULL, &iosb, mb, 0x100000, &zero, NULL);
1020 
1021 #ifndef __REACTOS__
1022  free(mb);
1023 #else
1024  RtlFreeHeap(RtlGetProcessHeap(), 0, mb);
1025 #endif
1026 
1027  return Status;
1028 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS NTAPI NtWriteFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
static double zero
Definition: j0_y0.c:96
BYTE uint8_t
Definition: msvideo1.c:66
Status
Definition: gdiplustypes.h:24
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define malloc
Definition: debug_ros.c:4
#define memset(x, y, z)
Definition: compat.h:39

Referenced by write_btrfs().

◆ DllMain()

BOOL APIENTRY DllMain ( HANDLE  hModule,
DWORD  dwReason,
void lpReserved 
)

Definition at line 1673 of file btrfslib.c.

1673  {
1675  module = (HMODULE)hModule;
1676 
1677  return true;
1678 }
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
DWORD dwReason
Definition: misc.cpp:154
HANDLE HMODULE
Definition: typedefs.h:76
HMODULE hModule
Definition: animate.c:44

◆ do_full_trim()

static void do_full_trim ( HANDLE  h)
static

Definition at line 1405 of file btrfslib.c.

1405  {
1408 
1410 
1411  dmdsa.Size = sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES);
1412  dmdsa.Action = DeviceDsmAction_Trim;
1414  dmdsa.ParameterBlockOffset = 0;
1415  dmdsa.ParameterBlockLength = 0;
1416  dmdsa.DataSetRangesOffset = 0;
1417  dmdsa.DataSetRangesLength = 0;
1418 
1420 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
struct _DEVICE_MANAGE_DATA_SET_ATTRIBUTES DEVICE_MANAGE_DATA_SET_ATTRIBUTES
#define DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED
Definition: btrfslib.c:74
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DEVICE_DATA_MANAGEMENT_SET_ACTION Action
Definition: ntddstor.h:578
#define DeviceDsmAction_Trim
Definition: ntddstor.h:211
smooth NULL
Definition: ftsmooth.c:416
#define IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES
Definition: ntddstor.h:170
#define DEVICE_DSM_FLAG_ENTIRE_DATA_SET_RANGE
Definition: ntddstor.h:214
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by FormatEx2().

◆ find_chunk_offset()

static uint64_t find_chunk_offset ( uint64_t  size,
uint64_t  offset,
btrfs_dev dev,
btrfs_root dev_root,
BTRFS_UUID chunkuuid 
)
static

Definition at line 372 of file btrfslib.c.

372  {
373  uint64_t off;
374  DEV_EXTENT de;
375 
376  off = dev->last_alloc;
377  dev->last_alloc += size;
378 
379  dev->dev_item.bytes_used += size;
380 
382  de.objid = 0x100;
383  de.address = offset;
384  de.length = size;
385  de.chunktree_uuid = *chunkuuid;
386 
387  add_item(dev_root, dev->dev_item.dev_id, TYPE_DEV_EXTENT, off, &de, sizeof(DEV_EXTENT));
388 
389  return off;
390 }
GLintptr offset
Definition: glext.h:5920
uint64_t length
Definition: btrfs.h:460
#define TYPE_DEV_EXTENT
Definition: btrfs.h:42
GLsizeiptr size
Definition: glext.h:5919
uint64_t objid
Definition: btrfs.h:458
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
UINT64 uint64_t
Definition: types.h:77
uint64_t dev_id
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:52
uint64_t chunktree
Definition: btrfs.h:457
BTRFS_UUID chunktree_uuid
Definition: btrfs.h:461
uint64_t address
Definition: btrfs.h:459
off
Definition: i386-dis.c:3909

Referenced by add_chunk().

◆ FormatEx()

BOOL __stdcall FormatEx ( DSTRING root,
STREAM_MESSAGE message,
options opts,
uint32_t  unk1 
)

Definition at line 1623 of file btrfslib.c.

1623  {
1624  UNICODE_STRING DriveRoot, Label;
1625  NTSTATUS Status;
1626 
1627  if (!root || !root->string)
1628  return false;
1629 
1630  DriveRoot.Length = DriveRoot.MaximumLength = (USHORT)(wcslen(root->string) * sizeof(WCHAR));
1631  DriveRoot.Buffer = root->string;
1632 
1633  if (opts && opts->label && opts->label->string) {
1634  Label.Length = Label.MaximumLength = (USHORT)(wcslen(opts->label->string) * sizeof(WCHAR));
1635  Label.Buffer = opts->label->string;
1636  } else {
1637  Label.Length = Label.MaximumLength = 0;
1638  Label.Buffer = NULL;
1639  }
1640 
1641 #ifndef __REACTOS__
1642  Status = FormatEx2(&DriveRoot, FMIFS_HARDDISK, &Label, opts && opts->flags & FORMAT_FLAG_QUICK_FORMAT, 0, NULL);
1643 #else
1644  Status = BtrfsFormatEx(&DriveRoot, FMIFS_HARDDISK, &Label, opts && opts->flags & FORMAT_FLAG_QUICK_FORMAT, 0, NULL);
1645 #endif
1646 
1647  return NT_SUCCESS(Status);
1648 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
#define FORMAT_FLAG_QUICK_FORMAT
Definition: btrfslib.c:103
DSTRING * label
Definition: btrfslib.c:114
NTSTATUS NTAPI BtrfsFormatEx(IN PUNICODE_STRING DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
static NTSTATUS NTAPI FormatEx2(PUNICODE_STRING DriveRoot, FMIFS_MEDIA_FLAG MediaFlag, PUNICODE_STRING Label, BOOLEAN QuickFormat, ULONG ClusterSize, PFMIFSCALLBACK Callback)
Definition: btrfslib.c:1445
WCHAR * string
Definition: btrfslib.c:96
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
uint32_t flags
Definition: btrfslib.c:113
unsigned short USHORT
Definition: pedump.c:61
PWCHAR Label
Definition: format.c:70
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ FormatEx2()

static NTSTATUS NTAPI FormatEx2 ( PUNICODE_STRING  DriveRoot,
FMIFS_MEDIA_FLAG  MediaFlag,
PUNICODE_STRING  Label,
BOOLEAN  QuickFormat,
ULONG  ClusterSize,
PFMIFSCALLBACK  Callback 
)
static

Definition at line 1445 of file btrfslib.c.

1450 {
1451  NTSTATUS Status;
1452  HANDLE h, btrfsh;
1456  DISK_GEOMETRY dg;
1457  uint32_t sector_size, node_size;
1458  UNICODE_STRING btrfsus;
1459 #ifndef __REACTOS__
1460  HANDLE token;
1462  LUID luid;
1463 #endif
1464  uint64_t incompat_flags;
1465  UNICODE_STRING empty_label;
1466 
1467  static WCHAR btrfs[] = L"\\Btrfs";
1468 
1469 #ifndef __REACTOS__
1472 
1473  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
1474  CloseHandle(token);
1476  }
1477 
1478  tp.PrivilegeCount = 1;
1479  tp.Privileges[0].Luid = luid;
1480  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1481 
1482  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
1483  CloseHandle(token);
1485  }
1486 
1487  CloseHandle(token);
1488 
1489 #if defined(_X86_) || defined(_AMD64_)
1490  check_cpu();
1491 #endif
1492 #endif
1493 
1496  return STATUS_INVALID_PARAMETER;
1497 
1499 
1502 
1503  if (!NT_SUCCESS(Status))
1504  return Status;
1505 
1507  if (!NT_SUCCESS(Status)) {
1508  NtClose(h);
1509  return Status;
1510  }
1511 
1512  // MSDN tells us to use IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, but there are
1513  // some instances where it fails and IOCTL_DISK_GET_DRIVE_GEOMETRY succeeds -
1514  // such as with spanned volumes.
1516  if (!NT_SUCCESS(Status)) {
1517  NtClose(h);
1518  return Status;
1519  }
1520 
1521  if (def_sector_size == 0) {
1523 
1524  if (sector_size == 0x200 || sector_size == 0)
1525  sector_size = 0x1000;
1526  } else {
1528  NtClose(h);
1529  return STATUS_INVALID_PARAMETER;
1530  }
1531 
1533  }
1534 
1535  if (def_node_size == 0)
1536  node_size = 0x4000;
1537  else {
1539  NtClose(h);
1540  return STATUS_INVALID_PARAMETER;
1541  }
1542 
1543  node_size = def_node_size;
1544  }
1545 
1546  if (Callback) {
1547  ULONG pc = 0;
1548  Callback(PROGRESS, 0, (PVOID)&pc);
1549  }
1550 
1552 
1555  goto end;
1556  }
1557 
1558  do_full_trim(h);
1559 
1560  incompat_flags = def_incompat_flags;
1562 
1563  if (!Label) {
1564  empty_label.Buffer = NULL;
1565  empty_label.Length = empty_label.MaximumLength = 0;
1566  Label = &empty_label;
1567  }
1568 
1569  Status = write_btrfs(h, gli.Length.QuadPart, Label, sector_size, node_size, incompat_flags);
1570 
1572 
1573 end:
1575 
1576  NtClose(h);
1577 
1578  if (NT_SUCCESS(Status)) {
1579  btrfsus.Buffer = btrfs;
1580  btrfsus.Length = btrfsus.MaximumLength = (USHORT)(wcslen(btrfs) * sizeof(WCHAR));
1581 
1582  InitializeObjectAttributes(&attr, &btrfsus, 0, NULL, NULL);
1583 
1586 
1587  if (NT_SUCCESS(Status)) {
1588  MOUNTDEV_NAME* mdn;
1589  ULONG mdnsize;
1590 
1591  mdnsize = (ULONG)(offsetof(MOUNTDEV_NAME, Name[0]) + DriveRoot->Length);
1592 #ifndef __REACTOS__
1593  mdn = malloc(mdnsize);
1594 #else
1595  mdn = RtlAllocateHeap(RtlGetProcessHeap(), 0, mdnsize);
1596 #endif
1597 
1598  mdn->NameLength = DriveRoot->Length;
1599  memcpy(mdn->Name, DriveRoot->Buffer, DriveRoot->Length);
1600 
1601  NtDeviceIoControlFile(btrfsh, NULL, NULL, NULL, &iosb, IOCTL_BTRFS_PROBE_VOLUME, mdn, mdnsize, NULL, 0);
1602 
1603 #ifndef __REACTOS__
1604  free(mdn);
1605 #else
1606  RtlFreeHeap(RtlGetProcessHeap(), 0, mdn);
1607 #endif
1608 
1609  NtClose(btrfsh);
1610  }
1611 
1613  }
1614 
1615  if (Callback) {
1616  bool success = NT_SUCCESS(Status);
1617  Callback(DONE, 0, (PVOID)&success);
1618  }
1619 
1620  return Status;
1621 }
#define FILE_GENERIC_READ
Definition: nt_native.h:653
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define CloseHandle
Definition: compat.h:407
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
static bool is_power_of_two(ULONG i)
Definition: btrfslib.c:1422
static bool is_mounted_multi_device(HANDLE h, uint32_t sector_size)
Definition: btrfslib.c:1275
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define CSUM_TYPE_BLAKE2
Definition: btrfs.h:128
#define free
Definition: debug_ros.c:5
static NTSTATUS write_btrfs(HANDLE h, uint64_t size, PUNICODE_STRING label, uint32_t sector_size, uint32_t node_size, uint64_t incompat_flags)
Definition: btrfslib.c:1136
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ULONG BytesPerSector
Definition: ntdddisk.h:381
GLuint GLuint end
Definition: gl.h:1545
#define CSUM_TYPE_CRC32C
Definition: btrfs.h:125
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define FSCTL_UNLOCK_VOLUME
Definition: btrfslib.c:70
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
uint16_t def_csum_type
Definition: btrfslib.c:177
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2930
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:108
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
#define TOKEN_QUERY
Definition: setypes.h:874
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR Name[1]
Definition: imports.h:144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
static void do_full_trim(HANDLE h)
Definition: btrfslib.c:1405
#define success(from, fromstr, to, tostr)
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
Definition: cookie.c:201
#define CSUM_TYPE_XXHASH
Definition: btrfs.h:126
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ULONG def_node_size
Definition: btrfslib.c:175
#define IOCTL_BTRFS_PROBE_VOLUME
Definition: btrfsioctl.h:28
__u8 attr
Definition: mkdosfs.c:359
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:113
Definition: btrfslib.c:225
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG def_sector_size
Definition: btrfslib.c:175
LARGE_INTEGER Length
Definition: winioctl.h:423
__u8 sector_size[2]
Definition: mkdosfs.c:361
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
Status
Definition: gdiplustypes.h:24
#define CSUM_TYPE_SHA256
Definition: btrfs.h:127
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define FSCTL_DISMOUNT_VOLUME
Definition: btrfslib.c:71
UINT64 uint64_t
Definition: types.h:77
unsigned short USHORT
Definition: pedump.c:61
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
USHORT NameLength
Definition: imports.h:143
UINT32 uint32_t
Definition: types.h:75
uint64_t def_incompat_flags
Definition: btrfslib.c:176
#define FSCTL_LOCK_VOLUME
Definition: btrfslib.c:69
unsigned int ULONG
Definition: retypes.h:1
PWCHAR Label
Definition: format.c:70
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define malloc
Definition: debug_ros.c:4
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
LPFNPSPCALLBACK Callback
Definition: desk.c:112
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
LONGLONG QuadPart
Definition: typedefs.h:113

Referenced by FormatEx().

◆ free_chunks()

static void free_chunks ( LIST_ENTRY chunks)
static

Definition at line 311 of file btrfslib.c.

311  {
312  LIST_ENTRY* le;
313 
314  le = chunks->Flink;
315  while (le != chunks) {
316  LIST_ENTRY *le2 = le->Flink;
318 
319 #ifndef __REACTOS__
320  free(c->chunk_item);
321  free(c);
322 #else
323  RtlFreeHeap(RtlGetProcessHeap(), 0, c->chunk_item);
324  RtlFreeHeap(RtlGetProcessHeap(), 0, c);
325 #endif
326 
327  le = le2;
328  }
329 }
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
const GLubyte * c
Definition: glext.h:8905
Definition: typedefs.h:118
Definition: list.h:27

Referenced by write_btrfs().

◆ free_roots()

static void free_roots ( LIST_ENTRY roots)
static

Definition at line 274 of file btrfslib.c.

274  {
275  LIST_ENTRY* le;
276 
277  le = roots->Flink;
278  while (le != roots) {
279  LIST_ENTRY *le2 = le->Flink, *le3;
281 
282  le3 = r->items.Flink;
283  while (le3 != &r->items) {
284  LIST_ENTRY* le4 = le3->Flink;
286 
287  if (item->data)
288 #ifdef __REACTOS__
289  RtlFreeHeap(RtlGetProcessHeap(), 0, item->data);
290 
291  RtlFreeHeap(RtlGetProcessHeap(), 0, item);
292 #else
293  free(item->data);
294 
295  free(item);
296 #endif
297 
298  le3 = le4;
299  }
300 
301 #ifdef __REACTOS__
302  RtlFreeHeap(RtlGetProcessHeap(), 0, r);
303 #else
304  free(r);
305 #endif
306 
307  le = le2;
308  }
309 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
static ATOM item
Definition: dde.c:856
Definition: list.h:27

Referenced by write_btrfs().

◆ get_next_address()

static uint64_t get_next_address ( btrfs_chunk c)
static

Definition at line 487 of file btrfslib.c.

487  {
488  uint64_t addr;
489 
490  addr = c->lastoff;
491 
492  while (superblock_collision(c, addr)) {
493  addr = addr - ((addr - c->offset) % c->chunk_item->stripe_length) + c->chunk_item->stripe_length;
494 
495  if (addr >= c->offset + c->chunk_item->size) // chunk has been exhausted
496  return 0;
497  }
498 
499  return addr;
500 }
const GLubyte * c
Definition: glext.h:8905
GLenum const GLvoid * addr
Definition: glext.h:9621
static bool superblock_collision(btrfs_chunk *c, uint64_t address)
Definition: btrfslib.c:466
UINT64 uint64_t
Definition: types.h:77

Referenced by assign_addresses().

◆ get_uuid()

static void get_uuid ( BTRFS_UUID uuid)
static

Definition at line 707 of file btrfslib.c.

707  {
708 #else
709 static void get_uuid(BTRFS_UUID* uuid, ULONG* seed) {
710 #endif
711  uint8_t i;
712 
713  for (i = 0; i < 16; i+=2) {
714 #ifndef __REACTOS__
715  ULONG r = rand();
716 #else
717  ULONG r = RtlRandom(seed);
718 #endif
719 
720  uuid->uuid[i] = (r & 0xff00) >> 8;
721  uuid->uuid[i+1] = r & 0xff;
722  }
723 }
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
BYTE uint8_t
Definition: msvideo1.c:66
Definition: msctf.idl:510
unsigned int ULONG
Definition: retypes.h:1
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:707

Referenced by init_device(), and write_btrfs().

◆ GetFilesystemInformation()

BOOL __stdcall GetFilesystemInformation ( uint32_t  unk1,
uint32_t  unk2,
void unk3 
)

Definition at line 1666 of file btrfslib.c.

1666  {
1667  // STUB - undocumented
1668 
1669  return true;
1670 }

◆ init_device()

static void init_device ( btrfs_dev dev,
uint64_t  id,
uint64_t  size,
BTRFS_UUID fsuuid,
uint32_t  sector_size 
)
static

Definition at line 726 of file btrfslib.c.

726  {
727 #else
728 static void init_device(btrfs_dev* dev, uint64_t id, uint64_t size, BTRFS_UUID* fsuuid, uint32_t sector_size, ULONG* seed) {
729 #endif
730  dev->dev_item.dev_id = id;
731  dev->dev_item.num_bytes = size;
732  dev->dev_item.bytes_used = 0;
733  dev->dev_item.optimal_io_align = sector_size;
734  dev->dev_item.optimal_io_width = sector_size;
735  dev->dev_item.minimal_io_size = sector_size;
736  dev->dev_item.type = 0;
737  dev->dev_item.generation = 0;
738  dev->dev_item.start_offset = 0;
739  dev->dev_item.dev_group = 0;
740  dev->dev_item.seek_speed = 0;
741  dev->dev_item.bandwidth = 0;
742 #ifndef __REACTOS__
743  get_uuid(&dev->dev_item.device_uuid);
744 #else
745  get_uuid(&dev->dev_item.device_uuid, seed);
746 #endif
747  dev->dev_item.fs_uuid = *fsuuid;
748 
749  dev->last_alloc = 0x100000; // skip first megabyte
750 }
static void init_device(btrfs_dev *dev, uint64_t id, uint64_t size, BTRFS_UUID *fsuuid, uint32_t sector_size)
Definition: btrfslib.c:726
GLsizeiptr size
Definition: glext.h:5919
__u8 sector_size[2]
Definition: mkdosfs.c:361
UINT64 uint64_t
Definition: types.h:77
uint64_t dev_id
UINT32 uint32_t
Definition: types.h:75
unsigned int ULONG
Definition: retypes.h:1
GLenum GLuint id
Definition: glext.h:5579
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:707

Referenced by write_btrfs().

◆ init_fs_tree()

static void init_fs_tree ( btrfs_root r,
uint32_t  node_size 
)
static

Definition at line 963 of file btrfslib.c.

963  {
964  INODE_ITEM ii;
967 
968  memset(&ii, 0, sizeof(INODE_ITEM));
969 
970  ii.generation = 1;
971  ii.st_blocks = node_size;
972  ii.st_nlink = 1;
973  ii.st_mode = 040755;
974 
976  time.LowPart = filetime.dwLowDateTime;
977  time.HighPart = filetime.dwHighDateTime;
978 
980  ii.st_ctime = ii.st_mtime = ii.st_atime;
981 
983 
985 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define SUBVOL_ROOT_INODE
Definition: propsheet.cpp:42
static void add_inode_ref(btrfs_root *r, uint64_t inode, uint64_t parent, uint64_t index, const char *name)
Definition: btrfslib.c:942
__u16 time
Definition: mkdosfs.c:366
BTRFS_TIME st_ctime
Definition: btrfs.h:294
uint32_t st_nlink
Definition: btrfs.h:285
BTRFS_TIME st_mtime
Definition: btrfs.h:295
BTRFS_TIME st_atime
Definition: btrfs.h:293
#define TYPE_INODE_ITEM
Definition: btrfs.h:19
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
uint64_t generation
Definition: btrfs.h:280
uint64_t st_blocks
Definition: btrfs.h:283
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME *out)
Definition: btrfslib.c:916
#define memset(x, y, z)
Definition: compat.h:39
uint32_t st_mode
Definition: btrfs.h:288

Referenced by write_btrfs().

◆ InitializeListHead()

FORCEINLINE VOID InitializeListHead ( PLIST_ENTRY  ListHead)

Definition at line 118 of file btrfslib.c.

118  {
119  ListHead->Flink = ListHead->Blink = ListHead;
120 }
struct _LIST_ENTRY * Blink
Definition: typedefs.h:121
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120

Referenced by add_root(), and write_btrfs().

◆ InsertTailList()

FORCEINLINE VOID InsertTailList ( PLIST_ENTRY  ListHead,
PLIST_ENTRY  Entry 
)

Definition at line 122 of file btrfslib.c.

122  {
123  PLIST_ENTRY Blink;
124 
125  Blink = ListHead->Blink;
126  Entry->Flink = ListHead;
127  Entry->Blink = Blink;
128  Blink->Flink = Entry;
129  ListHead->Blink = Entry;
130 }
struct _Entry Entry
Definition: kefuncs.h:627
struct _LIST_ENTRY * Blink
Definition: typedefs.h:121
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
base of all file and directory entries
Definition: entries.h:82

Referenced by add_chunk(), add_item(), and add_root().

◆ is_mounted_multi_device()

static bool is_mounted_multi_device ( HANDLE  h,
uint32_t  sector_size 
)
static

Definition at line 1275 of file btrfslib.c.

1275  {
1276  NTSTATUS Status;
1277  superblock* sb;
1278  ULONG sblen;
1281  BTRFS_UUID fsuuid, devuuid;
1284  HANDLE h2;
1285  btrfs_filesystem *bfs = NULL, *bfs2;
1286  ULONG bfssize;
1287  bool ret = false;
1288 
1289  static WCHAR btrfs[] = L"\\Btrfs";
1290 
1291  sblen = sizeof(*sb);
1292  if (sblen & (sector_size - 1))
1293  sblen = (sblen & sector_size) + sector_size;
1294 
1295 #ifndef __REACTOS__
1296  sb = malloc(sblen);
1297 #else
1298  sb = RtlAllocateHeap(RtlGetProcessHeap(), 0, sblen);
1299 #endif
1300 
1301  off.QuadPart = superblock_addrs[0];
1302 
1303  Status = NtReadFile(h, NULL, NULL, NULL, &iosb, sb, sblen, &off, NULL);
1304  if (!NT_SUCCESS(Status)) {
1305 #ifndef __REACTOS__
1306  free(sb);
1307 #else
1308  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1309 #endif
1310  return false;
1311  }
1312 
1313  if (sb->magic != BTRFS_MAGIC) {
1314 #ifndef __REACTOS__
1315  free(sb);
1316 #else
1317  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1318 #endif
1319  return false;
1320  }
1321 
1322  if (!check_superblock_checksum(sb)) {
1323 #ifndef __REACTOS__
1324  free(sb);
1325 #else
1326  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1327 #endif
1328  return false;
1329  }
1330 
1331  fsuuid = sb->uuid;
1332  devuuid = sb->dev_item.device_uuid;
1333 
1334 #ifndef __REACTOS__
1335  free(sb);
1336 #else
1337  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1338 #endif
1339 
1340  us.Length = us.MaximumLength = (USHORT)(wcslen(btrfs) * sizeof(WCHAR));
1341  us.Buffer = btrfs;
1342 
1344 
1347  if (!NT_SUCCESS(Status)) // not a problem, it usually just means the driver isn't loaded
1348  return false;
1349 
1350  bfssize = 0;
1351 
1352  do {
1353  bfssize += 1024;
1354 
1355 #ifndef __REACTOS__
1356  if (bfs) free(bfs);
1357  bfs = malloc(bfssize);
1358 #else
1359  if (bfs) RtlFreeHeap(RtlGetProcessHeap(), 0, bfs);
1360  bfs = RtlAllocateHeap(RtlGetProcessHeap(), 0, bfssize);
1361 #endif
1362 
1365  NtClose(h2);
1366  return false;
1367  }
1368  } while (Status == STATUS_BUFFER_OVERFLOW);
1369 
1370  if (!NT_SUCCESS(Status))
1371  goto end;
1372 
1373  if (bfs->num_devices != 0) {
1374  bfs2 = bfs;
1375  while (true) {
1376  if (RtlCompareMemory(&bfs2->uuid, &fsuuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
1377  if (bfs2->num_devices == 1)
1378  ret = false;
1379  else
1380  ret = look_for_device(bfs2, &devuuid);
1381 
1382  goto end;
1383  }
1384 
1385  if (bfs2->next_entry == 0)
1386  break;
1387  else
1388  bfs2 = (btrfs_filesystem*)((uint8_t*)bfs2 + bfs2->next_entry);
1389  }
1390  }
1391 
1392 end:
1393  NtClose(h2);
1394 
1395  if (bfs)
1396 #ifndef __REACTOS__
1397  free(bfs);
1398 #else
1399  RtlFreeHeap(RtlGetProcessHeap(), 0, bfs);
1400 #endif
1401 
1402  return ret;
1403 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
static bool look_for_device(btrfs_filesystem *bfs, BTRFS_UUID *devuuid)
Definition: btrfslib.c:1223
uint64_t magic
Definition: btrfs.h:221
superblock * sb
Definition: btrfs.c:4220
static const BYTE us[]
Definition: encode.c:689
#define IOCTL_BTRFS_QUERY_FILESYSTEMS
Definition: btrfsioctl.h:21
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
GLuint GLuint end
Definition: gl.h:1545
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
static bool check_superblock_checksum(superblock *sb)
Definition: btrfslib.c:1240
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
uint32_t num_devices
Definition: btrfsioctl.h:190
smooth NULL
Definition: ftsmooth.c:416
DEV_ITEM dev_item
Definition: btrfs.h:244
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BTRFS_UUID device_uuid
Definition: btrfs.h:183
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define SYNCHRONIZE
Definition: nt_native.h:61
BYTE uint8_t
Definition: msvideo1.c:66
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
BTRFS_UUID uuid
Definition: btrfs.h:218
static const uint64_t superblock_addrs[]
Definition: btrfs.h:13
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define malloc
Definition: debug_ros.c:4
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
_In_ uint16_t _Out_ ULONG * atts
Definition: btrfs_drv.h:1109
#define BTRFS_MAGIC
Definition: btrfs.h:42
off
Definition: i386-dis.c:3909

Referenced by FormatEx2().

◆ is_power_of_two()

static bool is_power_of_two ( ULONG  i)
static

Definition at line 1422 of file btrfslib.c.

1422  {
1423  return ((i != 0) && !(i & (i - 1)));
1424 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by FormatEx2().

◆ is_ssd()

static bool is_ssd ( HANDLE  h)
static

Definition at line 1030 of file btrfslib.c.

1030  {
1031  ULONG aptelen;
1032  ATA_PASS_THROUGH_EX* apte;
1034  NTSTATUS Status;
1035  IDENTIFY_DEVICE_DATA* idd;
1036 
1037  aptelen = sizeof(ATA_PASS_THROUGH_EX) + 512;
1038 #ifndef __REACTOS__
1039  apte = malloc(aptelen);
1040 
1041  RtlZeroMemory(apte, aptelen);
1042 #else
1043  apte = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, aptelen);
1044 #endif
1045 
1046  apte->Length = sizeof(ATA_PASS_THROUGH_EX);
1047  apte->AtaFlags = ATA_FLAGS_DATA_IN;
1048  apte->DataTransferLength = aptelen - sizeof(ATA_PASS_THROUGH_EX);
1049  apte->TimeOutValue = 3;
1050  apte->DataBufferOffset = apte->Length;
1052 
1053  Status = NtDeviceIoControlFile(h, NULL, NULL, NULL, &iosb, IOCTL_ATA_PASS_THROUGH, apte, aptelen, apte, aptelen);
1054 
1055  if (NT_SUCCESS(Status)) {
1056  idd = (IDENTIFY_DEVICE_DATA*)((uint8_t*)apte + sizeof(ATA_PASS_THROUGH_EX));
1057 
1058  if (idd->NominalMediaRotationRate == 1) {
1059 #ifndef __REACTOS__
1060  free(apte);
1061 #else
1062  RtlFreeHeap(RtlGetProcessHeap(), 0, apte);
1063 #endif
1064  return true;
1065  }
1066  }
1067 
1068 #ifndef __REACTOS__
1069  free(apte);
1070 #else
1071  RtlFreeHeap(RtlGetProcessHeap(), 0, apte);
1072 #endif
1073 
1074  return false;
1075 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ULONG_PTR DataBufferOffset
Definition: ntddscsi.h:139
#define ATA_FLAGS_DATA_IN
Definition: uata_ctl.h:222
#define IDE_COMMAND_IDENTIFY
Definition: atapi.h:118
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
USHORT NominalMediaRotationRate
Definition: ata.h:243
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG DataTransferLength
Definition: ntddscsi.h:136
BYTE uint8_t
Definition: msvideo1.c:66
struct _ATA_PASS_THROUGH_EX ATA_PASS_THROUGH_EX
Status
Definition: gdiplustypes.h:24
UCHAR CurrentTaskFile[8]
Definition: ntddscsi.h:141
#define IOCTL_ATA_PASS_THROUGH
Definition: ntddscsi.h:40
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define malloc
Definition: debug_ros.c:4

Referenced by write_btrfs().

◆ look_for_device()

static bool look_for_device ( btrfs_filesystem bfs,
BTRFS_UUID devuuid 
)
static

Definition at line 1223 of file btrfslib.c.

1223  {
1224  uint32_t i;
1226 
1227  for (i = 0; i < bfs->num_devices; i++) {
1228  if (i == 0)
1229  dev = &bfs->device;
1230  else
1232 
1233  if (RtlCompareMemory(&dev->uuid, devuuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID))
1234  return true;
1235  }
1236 
1237  return false;
1238 }
static int dev
Definition: mkdosfs.c:536
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t num_devices
Definition: btrfsioctl.h:190
#define offsetof(TYPE, MEMBER)
BYTE uint8_t
Definition: msvideo1.c:66
UINT32 uint32_t
Definition: types.h:75
Definition: name.c:38
btrfs_filesystem_device device
Definition: btrfsioctl.h:191
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by is_mounted_multi_device().

◆ NtFsControlFile()

NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile ( HANDLE  FileHandle,
HANDLE  Event,
PIO_APC_ROUTINE  ApcRoutine,
PVOID  ApcContext,
PIO_STATUS_BLOCK  IoStatusBlock,
ULONG  FsControlCode,
PVOID  InputBuffer,
ULONG  InputBufferLength,
PVOID  OutputBuffer,
ULONG  OutputBufferLength 
)

Referenced by FormatEx2().

◆ NtReadFile()

NTSTATUS NTAPI NtReadFile ( HANDLE  FileHandle,
HANDLE  Event,
PIO_APC_ROUTINE  ApcRoutine,
PVOID  ApcContext,
PIO_STATUS_BLOCK  IoStatusBlock,
PVOID  Buffer,
ULONG  Length,
PLARGE_INTEGER  ByteOffset,
PULONG  Key 
)

Referenced by is_mounted_multi_device().

◆ NtWriteFile()

NTSTATUS NTAPI NtWriteFile ( HANDLE  FileHandle,
HANDLE  Event,
PIO_APC_ROUTINE  ApcRoutine,
PVOID  ApcContext,
PIO_STATUS_BLOCK  IoStatusBlock,
PVOID  Buffer,
ULONG  Length,
PLARGE_INTEGER  ByteOffset,
PULONG  Key 
)

◆ set_default_subvol()

static void set_default_subvol ( btrfs_root root_root,
uint32_t  node_size 
)
static

Definition at line 1104 of file btrfslib.c.

1104  {
1105  INODE_ITEM ii;
1108 
1109  static const char default_subvol[] = "default";
1110  static const uint32_t default_hash = 0x8dbfc2d2;
1111 
1112  add_inode_ref(root_root, BTRFS_ROOT_FSTREE, BTRFS_ROOT_TREEDIR, 0, default_subvol);
1113 
1114  memset(&ii, 0, sizeof(INODE_ITEM));
1115 
1116  ii.generation = 1;
1117  ii.st_blocks = node_size;
1118  ii.st_nlink = 1;
1119  ii.st_mode = 040755;
1120 
1122  time.LowPart = filetime.dwLowDateTime;
1123  time.HighPart = filetime.dwHighDateTime;
1124 
1126  ii.st_ctime = ii.st_mtime = ii.otime = ii.st_atime;
1127 
1128  add_item(root_root, BTRFS_ROOT_TREEDIR, TYPE_INODE_ITEM, 0, &ii, sizeof(INODE_ITEM));
1129 
1130  add_inode_ref(root_root, BTRFS_ROOT_TREEDIR, BTRFS_ROOT_TREEDIR, 0, "..");
1131 
1133  0xffffffffffffffff, 0, BTRFS_TYPE_DIRECTORY, default_subvol);
1134 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
BTRFS_TIME otime
Definition: btrfs.h:296
static void add_inode_ref(btrfs_root *r, uint64_t inode, uint64_t parent, uint64_t index, const char *name)
Definition: btrfslib.c:942
__u16 time
Definition: mkdosfs.c:366
BTRFS_TIME st_ctime
Definition: btrfs.h:294
uint32_t st_nlink
Definition: btrfs.h:285
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
BTRFS_TIME st_mtime
Definition: btrfs.h:295
#define BTRFS_ROOT_TREEDIR
Definition: btrfs.h:55
BTRFS_TIME st_atime
Definition: btrfs.h:293
#define BTRFS_ROOT_FSTREE
Definition: btrfs.h:54
#define TYPE_INODE_ITEM
Definition: btrfs.h:19
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
uint64_t generation
Definition: btrfs.h:280
uint64_t st_blocks
Definition: btrfs.h:283
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME *out)
Definition: btrfslib.c:916
static void add_dir_item(btrfs_root *root, uint64_t inode, uint32_t hash, uint64_t key_objid, uint8_t key_type, uint64_t key_offset, uint64_t transid, uint8_t type, const char *name)
Definition: btrfslib.c:1077
#define TYPE_ROOT_ITEM
Definition: btrfs.h:28
UINT32 uint32_t
Definition: types.h:75
#define memset(x, y, z)
Definition: compat.h:39
uint32_t st_mode
Definition: btrfs.h:288

Referenced by write_btrfs().

◆ SetCsumType()

void __stdcall SetCsumType ( uint16_t  csum_type)

Definition at line 1662 of file btrfslib.c.

1662  {
1663  def_csum_type = csum_type;
1664 }
uint16_t def_csum_type
Definition: btrfslib.c:177

◆ SetIncompatFlags()

void __stdcall SetIncompatFlags ( uint64_t  incompat_flags)

Definition at line 1658 of file btrfslib.c.

1658  {
1659  def_incompat_flags = incompat_flags;
1660 }
uint64_t def_incompat_flags
Definition: btrfslib.c:176

◆ SetSizes()

void __stdcall SetSizes ( ULONG  sector,
ULONG  node 
)

Definition at line 1650 of file btrfslib.c.

1650  {
1651  if (sector != 0)
1653 
1654  if (node != 0)
1655  def_node_size = node;
1656 }
uint32_t sector
Definition: isohybrid.c:61
struct node node
ULONG def_node_size
Definition: btrfslib.c:175
ULONG def_sector_size
Definition: btrfslib.c:175
Definition: dlist.c:348

◆ superblock_collision()

static bool superblock_collision ( btrfs_chunk c,
uint64_t  address 
)
static

Definition at line 466 of file btrfslib.c.

466  {
467  CHUNK_ITEM_STRIPE* cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
468  uint64_t stripe = (address - c->offset) / c->chunk_item->stripe_length;
469  uint16_t i, j;
470 
471  for (i = 0; i < c->chunk_item->num_stripes; i++) {
472  j = 0;
473  while (superblock_addrs[j] != 0) {
474  if (superblock_addrs[j] >= cis[i].offset) {
475  uint64_t stripe2 = (superblock_addrs[j] - cis[i].offset) / c->chunk_item->stripe_length;
476 
477  if (stripe2 == stripe)
478  return true;
479  }
480  j++;
481  }
482  }
483 
484  return false;
485 }
GLintptr offset
Definition: glext.h:5920
Definition: write.c:111
unsigned short int uint16_t
Definition: acefiex.h:54
uint64_t offset
Definition: btrfs.h:341
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
if(!(yy_init))
Definition: macro.lex.yy.c:714
const GLubyte * c
Definition: glext.h:8905
GLuint address
Definition: glext.h:9393
UINT64 uint64_t
Definition: types.h:77
static const uint64_t superblock_addrs[]
Definition: btrfs.h:13

Referenced by get_next_address().

◆ win_time_to_unix()

static __inline void win_time_to_unix ( LARGE_INTEGER  t,
BTRFS_TIME out 
)
static

Definition at line 916 of file btrfslib.c.

916  {
917  ULONGLONG l = t.QuadPart - 116444736000000000;
918 
919  out->seconds = l / 10000000;
920  out->nanoseconds = (l % 10000000) * 100;
921 }
GLdouble GLdouble t
Definition: gl.h:2047
r l[0]
Definition: byte_order.h:167
uint64_t ULONGLONG
Definition: typedefs.h:66
static FILE * out
Definition: regtests2xml.c:44

Referenced by init_fs_tree(), and set_default_subvol().

◆ write_btrfs()

static NTSTATUS write_btrfs ( HANDLE  h,
uint64_t  size,
PUNICODE_STRING  label,
uint32_t  sector_size,
uint32_t  node_size,
uint64_t  incompat_flags 
)
static

Definition at line 1136 of file btrfslib.c.

1136  {
1137  NTSTATUS Status;
1138  LIST_ENTRY roots, chunks;
1139  btrfs_root *root_root, *chunk_root, *extent_root, *dev_root, *fs_root, *reloc_root;
1140  btrfs_chunk *sys_chunk, *metadata_chunk;
1141  btrfs_dev dev;
1142  BTRFS_UUID fsuuid, chunkuuid;
1143  bool ssd;
1144  uint64_t metadata_flags;
1145 #ifdef __REACTOS__
1146  ULONG seed;
1147 #endif
1148 
1149 #ifndef __REACTOS__
1150  srand((unsigned int)time(0));
1151  get_uuid(&fsuuid);
1152  get_uuid(&chunkuuid);
1153 #else
1154  seed = NtGetTickCount();
1155  get_uuid(&fsuuid, &seed);
1156  get_uuid(&chunkuuid, &seed);
1157 #endif
1158 
1159  InitializeListHead(&roots);
1160  InitializeListHead(&chunks);
1161 
1162  root_root = add_root(&roots, BTRFS_ROOT_ROOT);
1163  chunk_root = add_root(&roots, BTRFS_ROOT_CHUNK);
1164  extent_root = add_root(&roots, BTRFS_ROOT_EXTENT);
1165  dev_root = add_root(&roots, BTRFS_ROOT_DEVTREE);
1166  add_root(&roots, BTRFS_ROOT_CHECKSUM);
1167  fs_root = add_root(&roots, BTRFS_ROOT_FSTREE);
1169 
1170 #ifndef __REACTOS__
1171  init_device(&dev, 1, size, &fsuuid, sector_size);
1172 #else
1173  init_device(&dev, 1, size, &fsuuid, sector_size, &seed);
1174 #endif
1175 
1176  ssd = is_ssd(h);
1177 
1178  sys_chunk = add_chunk(&chunks, BLOCK_FLAG_SYSTEM | (ssd ? 0 : BLOCK_FLAG_DUPLICATE), chunk_root, &dev, dev_root, &chunkuuid, sector_size);
1179  if (!sys_chunk)
1180  return STATUS_INTERNAL_ERROR;
1181 
1182  metadata_flags = BLOCK_FLAG_METADATA;
1183 
1184  if (!ssd && !(incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS))
1185  metadata_flags |= BLOCK_FLAG_DUPLICATE;
1186 
1187  if (incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS)
1188  metadata_flags |= BLOCK_FLAG_DATA;
1189 
1190  metadata_chunk = add_chunk(&chunks, metadata_flags, chunk_root, &dev, dev_root, &chunkuuid, sector_size);
1191  if (!metadata_chunk)
1192  return STATUS_INTERNAL_ERROR;
1193 
1194  add_item(chunk_root, 1, TYPE_DEV_ITEM, dev.dev_item.dev_id, &dev.dev_item, sizeof(DEV_ITEM));
1195 
1196  set_default_subvol(root_root, node_size);
1197 
1198  init_fs_tree(fs_root, node_size);
1199  init_fs_tree(reloc_root, node_size);
1200 
1201  assign_addresses(&roots, sys_chunk, metadata_chunk, node_size, root_root, extent_root, incompat_flags & BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA);
1202 
1203  add_block_group_items(&chunks, extent_root);
1204 
1205  Status = write_roots(h, &roots, node_size, &fsuuid, &chunkuuid);
1206  if (!NT_SUCCESS(Status))
1207  return Status;
1208 
1210  if (!NT_SUCCESS(Status))
1211  return Status;
1212 
1213  Status = write_superblocks(h, &dev, chunk_root, root_root, extent_root, sys_chunk, node_size, &fsuuid, sector_size, label, incompat_flags);
1214  if (!NT_SUCCESS(Status))
1215  return Status;
1216 
1217  free_roots(&roots);
1218  free_chunks(&chunks);
1219 
1220  return STATUS_SUCCESS;
1221 }
#define TYPE_DEV_ITEM
Definition: btrfs.h:43
static NTSTATUS write_superblocks(HANDLE h, btrfs_dev *dev, btrfs_root *chunk_root, btrfs_root *root_root, btrfs_root *extent_root, btrfs_chunk *sys_chunk, uint32_t node_size, BTRFS_UUID *fsuuid, uint32_t sector_size, PUNICODE_STRING label, uint64_t incompat_flags)
Definition: btrfslib.c:772
static NTSTATUS write_roots(HANDLE h, LIST_ENTRY *roots, uint32_t node_size, BTRFS_UUID *fsuuid, BTRFS_UUID *chunkuuid)
Definition: btrfslib.c:628
static void set_default_subvol(btrfs_root *root_root, uint32_t node_size)
Definition: btrfslib.c:1104
char * reloc_root
Definition: mkisofs.c:177
LONG NTSTATUS
Definition: precomp.h:26
void __cdecl srand(_In_ unsigned int _Seed)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:116
__u16 time
Definition: mkdosfs.c:366
static void add_block_group_items(LIST_ENTRY *chunks, btrfs_root *extent_root)
Definition: btrfslib.c:987
#define NtGetTickCount
Definition: rtlp.h:146
#define BTRFS_ROOT_DATA_RELOC
Definition: btrfs.h:59
static int dev
Definition: mkdosfs.c:536
static btrfs_root * add_root(LIST_ENTRY *roots, uint64_t id)
Definition: btrfslib.c:255
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:110
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:76
#define BTRFS_ROOT_ROOT
Definition: btrfs.h:50
static void init_device(btrfs_dev *dev, uint64_t id, uint64_t size, BTRFS_UUID *fsuuid, uint32_t sector_size)
Definition: btrfslib.c:726
GLsizeiptr size
Definition: glext.h:5919
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead)
Definition: btrfslib.c:118
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static bool is_ssd(HANDLE h)
Definition: btrfslib.c:1030
#define BLOCK_FLAG_METADATA
Definition: shellext.h:77
#define BTRFS_ROOT_FSTREE
Definition: btrfs.h:54
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:331
Definition: typedefs.h:118
static void init_fs_tree(btrfs_root *r, uint32_t node_size)
Definition: btrfslib.c:963
uint8_t label[11]
Definition: fsck.fat.h:65
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
static void free_roots(LIST_ENTRY *roots)
Definition: btrfslib.c:274
UINT64 uint64_t
Definition: types.h:77
#define BTRFS_ROOT_CHECKSUM
Definition: btrfs.h:56
static btrfs_chunk * add_chunk(LIST_ENTRY *chunks, uint64_t flags, btrfs_root *chunk_root, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid, uint32_t sector_size)
Definition: btrfslib.c:392
uint64_t dev_id
#define BLOCK_FLAG_DATA
Definition: shellext.h:75
#define BTRFS_ROOT_DEVTREE
Definition: btrfs.h:53
static NTSTATUS clear_first_megabyte(HANDLE h)
Definition: btrfslib.c:1004
unsigned int ULONG
Definition: retypes.h:1
static void free_chunks(LIST_ENTRY *chunks)
Definition: btrfslib.c:311
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:52
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:80
#define BTRFS_ROOT_EXTENT
Definition: btrfs.h:51
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:707
return STATUS_SUCCESS
Definition: btrfs.c:3014
static void assign_addresses(LIST_ENTRY *roots, btrfs_chunk *sys_chunk, btrfs_chunk *metadata_chunk, uint32_t node_size, btrfs_root *root_root, btrfs_root *extent_root, bool skinny)
Definition: btrfslib.c:515

Referenced by FormatEx2().

◆ write_data()

static NTSTATUS write_data ( HANDLE  h,
uint64_t  address,
btrfs_chunk c,
void data,
ULONG  size 
)
static

Definition at line 588 of file btrfslib.c.

588  {
590  uint16_t i;
593  CHUNK_ITEM_STRIPE* cis;
594 
595  cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
596 
597  for (i = 0; i < c->chunk_item->num_stripes; i++) {
598  off.QuadPart = cis[i].offset + address - c->offset;
599 
601  if (!NT_SUCCESS(Status))
602  return Status;
603  }
604 
605  return STATUS_SUCCESS;
606 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtWriteFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
unsigned short int uint16_t
Definition: acefiex.h:54
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
uint64_t offset
Definition: btrfs.h:341
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const GLubyte * c
Definition: glext.h:8905
#define for
Definition: utility.h:88
GLuint address
Definition: glext.h:9393
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:3014
off
Definition: i386-dis.c:3909

Referenced by write_roots().

◆ write_roots()

static NTSTATUS write_roots ( HANDLE  h,
LIST_ENTRY roots,
uint32_t  node_size,
BTRFS_UUID fsuuid,
BTRFS_UUID chunkuuid 
)
static

Definition at line 628 of file btrfslib.c.

628  {
629  LIST_ENTRY *le, *le2;
631  uint8_t* tree;
632 
633 #ifndef __REACTOS__
634  tree = malloc(node_size);
635 #else
636  tree = RtlAllocateHeap(RtlGetProcessHeap(), 0, node_size);
637 #endif
638 
639  le = roots->Flink;
640  while (le != roots) {
642  uint8_t* dp;
643  leaf_node* ln;
644 
645  memset(tree, 0, node_size);
646 
647  r->header.num_items = 0;
648  r->header.fs_uuid = *fsuuid;
650  r->header.chunk_tree_uuid = *chunkuuid;
651  r->header.generation = 1;
652  r->header.tree_id = r->id;
653 
654  ln = (leaf_node*)(tree + sizeof(tree_header));
655 
656  dp = tree + node_size;
657 
658  le2 = r->items.Flink;
659  while (le2 != &r->items) {
661 
662  ln->key = item->key;
663  ln->size = item->size;
664 
665  if (item->size > 0) {
666  dp -= item->size;
667  memcpy(dp, item->data, item->size);
668 
669  ln->offset = (uint32_t)(dp - tree - sizeof(tree_header));
670  } else
671  ln->offset = 0;
672 
673  ln = &ln[1];
674 
675  r->header.num_items++;
676 
677  le2 = le2->Flink;
678  }
679 
680  memcpy(tree, &r->header, sizeof(tree_header));
681 
682  calc_tree_checksum((tree_header*)tree, node_size);
683 
684  Status = write_data(h, r->header.address, r->c, tree, node_size);
685  if (!NT_SUCCESS(Status)) {
686 #ifndef __REACTOS__
687  free(tree);
688 #else
689  RtlFreeHeap(RtlGetProcessHeap(), 0, tree);
690 #endif
691  return Status;
692  }
693 
694  le = le->Flink;
695  }
696 
697 #ifndef __REACTOS__
698  free(tree);
699 #else
700  RtlFreeHeap(RtlGetProcessHeap(), 0, tree);
701 #endif
702 
703  return STATUS_SUCCESS;
704 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
struct _tree tree
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define HEADER_FLAG_MIXED_BACKREF
Definition: btrfs.h:144
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
uint32_t offset
Definition: btrfs.h:160
uint32_t size
Definition: btrfs.h:161
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
tree_header header
Definition: btrfs_drv.h:442
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: typedefs.h:118
BYTE uint8_t
Definition: msvideo1.c:66
static void calc_tree_checksum(tree_header *th, uint32_t node_size)
Definition: btrfslib.c:608
Status
Definition: gdiplustypes.h:24
static ATOM item
Definition: dde.c:856
KEY key
Definition: btrfs.h:159
Definition: list.h:27
static NTSTATUS write_data(HANDLE h, uint64_t address, btrfs_chunk *c, void *data, ULONG size)
Definition: btrfslib.c:588
#define HEADER_FLAG_WRITTEN
Definition: btrfs.h:142
#define malloc
Definition: debug_ros.c:4
#define uint32_t
Definition: nsiface.idl:61
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define memset(x, y, z)
Definition: compat.h:39

Referenced by write_btrfs().

◆ write_superblocks()

static NTSTATUS write_superblocks ( HANDLE  h,
btrfs_dev dev,
btrfs_root chunk_root,
btrfs_root root_root,
btrfs_root extent_root,
btrfs_chunk sys_chunk,
uint32_t  node_size,
BTRFS_UUID fsuuid,
uint32_t  sector_size,
PUNICODE_STRING  label,
uint64_t  incompat_flags 
)
static

Definition at line 772 of file btrfslib.c.

773  {
776  ULONG sblen;
777  int i;
778  superblock* sb;
779  KEY* key;
780  uint64_t bytes_used;
781  LIST_ENTRY* le;
782 
783  sblen = sizeof(*sb);
784  if (sblen & (sector_size - 1))
785  sblen = (sblen & sector_size) + sector_size;
786 
787  bytes_used = 0;
788 
789  le = extent_root->items.Flink;
790  while (le != &extent_root->items) {
792 
793  if (item->key.obj_type == TYPE_EXTENT_ITEM)
794  bytes_used += item->key.offset;
795  else if (item->key.obj_type == TYPE_METADATA_ITEM)
796  bytes_used += node_size;
797 
798  le = le->Flink;
799  }
800 
801 #ifndef __REACTOS__
802  sb = malloc(sblen);
803  memset(sb, 0, sblen);
804 #else
805  sb = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sblen);
806 #endif
807 
808  sb->uuid = *fsuuid;
809  sb->flags = 1;
810  sb->magic = BTRFS_MAGIC;
811  sb->generation = 1;
812  sb->root_tree_addr = root_root->header.address;
813  sb->chunk_tree_addr = chunk_root->header.address;
814  sb->total_bytes = dev->dev_item.num_bytes;
815  sb->bytes_used = bytes_used;
817  sb->num_devices = 1;
819  sb->node_size = node_size;
820  sb->leaf_size = node_size;
822  sb->n = sizeof(KEY) + sizeof(CHUNK_ITEM) + (sys_chunk->chunk_item->num_stripes * sizeof(CHUNK_ITEM_STRIPE));
824  sb->incompat_flags = incompat_flags;
826  memcpy(&sb->dev_item, &dev->dev_item, sizeof(DEV_ITEM));
827 
828  if (label->Length > 0) {
829 #ifdef __REACTOS__
830  ANSI_STRING as;
831  unsigned int i;
832 
833  for (i = 0; i < label->Length / sizeof(WCHAR); i++) {
834 #else
835  ULONG utf8len;
836 
837  for (unsigned int i = 0; i < label->Length / sizeof(WCHAR); i++) {
838 #endif
839  if (label->Buffer[i] == '/' || label->Buffer[i] == '\\') {
840 #ifndef __REACTOS__
841  free(sb);
842 #else
843  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
844 #endif
846  }
847  }
848 
849 #ifndef __REACTOS__
850  utf8len = WideCharToMultiByte(CP_UTF8, 0, label->Buffer, label->Length / sizeof(WCHAR), NULL, 0, NULL, NULL);
851 
852  if (utf8len == 0 || utf8len > MAX_LABEL_SIZE) {
853  free(sb);
855  }
856 
857  if (WideCharToMultiByte(CP_UTF8, 0, label->Buffer, label->Length / sizeof(WCHAR), sb->label, utf8len, NULL, NULL) == 0) {
858  free(sb);
860  }
861 #else
862  as.Buffer = sb->label;
863  as.Length = 0;
865 
867  {
868  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
870  }
871 #endif
872  }
873  sb->cache_generation = 0xffffffffffffffff;
874 
875  key = (KEY*)sb->sys_chunk_array;
876  key->obj_id = 0x100;
877  key->obj_type = TYPE_CHUNK_ITEM;
878  key->offset = sys_chunk->offset;
879  memcpy(&key[1], sys_chunk->chunk_item, sizeof(CHUNK_ITEM) + (sys_chunk->chunk_item->num_stripes * sizeof(CHUNK_ITEM_STRIPE)));
880 
881  i = 0;
882  while (superblock_addrs[i] != 0) {
884 
885  if (superblock_addrs[i] > dev->dev_item.num_bytes)
886  break;
887 
889 
891 
892  off.QuadPart = superblock_addrs[i];
893 
894  Status = NtWriteFile(h, NULL, NULL, NULL, &iosb, sb, sblen, &off, NULL);
895  if (!NT_SUCCESS(Status)) {
896 #ifndef __REACTOS__
897  free(sb);
898 #else
899  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
900 #endif
901  return Status;
902  }
903 
904  i++;
905  }
906 
907 #ifndef __REACTOS__
908  free(sb);
909 #else
910  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
911 #endif
912 
913  return STATUS_SUCCESS;
914 }
uint8_t sys_chunk_array[SYS_CHUNK_ARRAY_SIZE]
Definition: btrfs.h:250
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
uint64_t bytes_used
Definition: btrfs.h:228
#define WideCharToMultiByte
Definition: compat.h:101
uint64_t root_tree_addr
Definition: btrfs.h:223
uint64_t magic
Definition: btrfs.h:221
char label[MAX_LABEL_SIZE]
Definition: btrfs.h:245
superblock * sb
Definition: btrfs.c:4220
#define free
Definition: debug_ros.c:5
#define TYPE_CHUNK_ITEM
Definition: btrfs.h:44
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS NTAPI NtWriteFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
#define STATUS_INVALID_VOLUME_LABEL
Definition: udferr_usr.h:156
#define TYPE_METADATA_ITEM
Definition: btrfs.h:32
uint16_t csum_type
Definition: btrfs.h:240
uint64_t chunk_tree_addr
Definition: btrfs.h:224
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint64_t address
Definition: btrfs.h:149
uint32_t stripe_size
Definition: btrfs.h:234
#define CP_UTF8
Definition: nls.h:20
uint16_t def_csum_type
Definition: btrfslib.c:177
uint64_t num_devices
Definition: btrfs.h:230
smooth NULL
Definition: ftsmooth.c:416
#define TYPE_EXTENT_ITEM
Definition: btrfs.h:31
DEV_ITEM dev_item
Definition: btrfs.h:244
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
tree_header header
Definition: btrfslib.c:154
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
uint64_t sb_phys_addr
Definition: btrfs.h:219
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
uint64_t flags
Definition: btrfs.h:220
USHORT MaximumLength
Definition: env_spec_w32.h:377
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
static void calc_superblock_checksum(superblock *sb)
Definition: btrfslib.c:752
#define BTRFS_ROOT_TREEDIR
Definition: btrfs.h:55
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t root_dir_objectid
Definition: btrfs.h:229
uint64_t generation
Definition: btrfs.h:222
HKEY key
Definition: reg.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint64_t cache_generation
Definition: btrfs.h:246
Definition: typedefs.h:118
uint32_t n
Definition: btrfs.h:235
uint8_t label[11]
Definition: fsck.fat.h:65
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
Definition: btrfs.h:136
#define MAX_LABEL_SIZE
Definition: btrfs.h:16
UINT64 uint64_t
Definition: types.h:77
static ATOM item
Definition: dde.c:856
#define KEY
Definition: profile.c:30
uint64_t total_bytes
Definition: btrfs.h:227
BTRFS_UUID uuid
Definition: btrfs.h:218
uint32_t node_size
Definition: btrfs.h:232
Definition: list.h:27
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LIST_ENTRY items
Definition: btrfslib.c:156
static const uint64_t superblock_addrs[]
Definition: btrfs.h:13
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
uint32_t sector_size
Definition: btrfs.h:231
uint32_t leaf_size
Definition: btrfs.h:233
uint64_t chunk_root_generation
Definition: btrfs.h:236
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define memset(x, y, z)
Definition: compat.h:39
Definition: path.c:41
#define BTRFS_MAGIC
Definition: btrfs.h:42
off
Definition: i386-dis.c:3909
uint64_t incompat_flags
Definition: btrfs.h:239

Referenced by write_btrfs().

Variable Documentation

◆ def_csum_type

◆ def_incompat_flags

◆ def_node_size

ULONG def_node_size = 0

Definition at line 175 of file btrfslib.c.

Referenced by FormatEx2(), and SetSizes().

◆ def_sector_size

ULONG def_sector_size = 0

Definition at line 175 of file btrfslib.c.

Referenced by FormatEx2(), and SetSizes().

◆ module

Definition at line 174 of file btrfslib.c.