ReactOS  0.4.13-dev-99-g7e18b6d
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 "../btrfs.h"
#include "../btrfsioctl.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 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

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)
 
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToUTF8N (PCHAR UTF8StringDestination, ULONG UTF8StringMaxByteCount, PULONG UTF8StringActualByteCount, PCWCH UnicodeStringSource, ULONG UnicodeStringByteCount)
 
FORCEINLINE VOID InitializeListHead (PLIST_ENTRY ListHead)
 
FORCEINLINE VOID InsertTailList (PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
 
static UINT32 calc_crc32c (UINT32 seed, UINT8 *msg, ULONG msglen)
 
NTSTATUS WINAPI ChkdskEx (PUNICODE_STRING DriveRoot, BOOLEAN FixErrors, BOOLEAN Verbose, BOOLEAN CheckOnlyIfDirty, BOOLEAN ScanDrive, PFMIFSCALLBACK Callback)
 
static btrfs_rootadd_root (LIST_ENTRY *roots, UINT64 id)
 
static void free_roots (LIST_ENTRY *roots)
 
static void free_chunks (LIST_ENTRY *chunks)
 
static void add_item (btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
 
static UINT64 find_chunk_offset (UINT64 size, UINT64 offset, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid)
 
static btrfs_chunkadd_chunk (LIST_ENTRY *chunks, UINT64 flags, btrfs_root *chunk_root, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid, UINT32 sector_size)
 
static BOOL superblock_collision (btrfs_chunk *c, UINT64 address)
 
static UINT64 get_next_address (btrfs_chunk *c)
 
static void assign_addresses (LIST_ENTRY *roots, btrfs_chunk *sys_chunk, btrfs_chunk *metadata_chunk, UINT32 node_size, btrfs_root *root_root, btrfs_root *extent_root, BOOL skinny)
 
static NTSTATUS write_data (HANDLE h, UINT64 address, btrfs_chunk *c, void *data, ULONG size)
 
static NTSTATUS write_roots (HANDLE h, LIST_ENTRY *roots, UINT32 node_size, BTRFS_UUID *fsuuid, BTRFS_UUID *chunkuuid)
 
static void get_uuid (BTRFS_UUID *uuid)
 
static void init_device (btrfs_dev *dev, UINT64 id, UINT64 size, BTRFS_UUID *fsuuid, UINT32 sector_size)
 
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 node_size, BTRFS_UUID *fsuuid, UINT32 sector_size, PUNICODE_STRING label, UINT64 incompat_flags)
 
static __inline void win_time_to_unix (LARGE_INTEGER t, BTRFS_TIME *out)
 
static void init_fs_tree (btrfs_root *r, UINT32 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 NTSTATUS write_btrfs (HANDLE h, UINT64 size, PUNICODE_STRING label, UINT32 sector_size, UINT32 node_size, UINT64 incompat_flags)
 
static BOOL look_for_device (btrfs_filesystem *bfs, BTRFS_UUID *devuuid)
 
static BOOL is_mounted_multi_device (HANDLE h, UINT32 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 unk1)
 
void __stdcall SetSizes (ULONG sector, ULONG node)
 
void __stdcall SetIncompatFlags (UINT64 incompat_flags)
 
BOOL __stdcall GetFilesystemInformation (UINT32 unk1, UINT32 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 def_incompat_flags = BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
 
static const UINT32 crctable []
 

Macro Definition Documentation

◆ DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED

#define DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED   0x80000000

Definition at line 52 of file btrfslib.c.

◆ FORMAT_FLAG_DISMOUNT_FIRST

#define FORMAT_FLAG_DISMOUNT_FIRST   0x00000004

Definition at line 86 of file btrfslib.c.

◆ FORMAT_FLAG_INTEGRITY_DISABLE

#define FORMAT_FLAG_INTEGRITY_DISABLE   0x00000100

Definition at line 89 of file btrfslib.c.

◆ FORMAT_FLAG_LARGE_RECORDS

#define FORMAT_FLAG_LARGE_RECORDS   0x00000100

Definition at line 88 of file btrfslib.c.

◆ FORMAT_FLAG_QUICK_FORMAT

#define FORMAT_FLAG_QUICK_FORMAT   0x00000001

Definition at line 84 of file btrfslib.c.

◆ FORMAT_FLAG_UNKNOWN1

#define FORMAT_FLAG_UNKNOWN1   0x00000002

Definition at line 85 of file btrfslib.c.

◆ FORMAT_FLAG_UNKNOWN2

#define FORMAT_FLAG_UNKNOWN2   0x00000040

Definition at line 87 of file btrfslib.c.

◆ FSCTL_DISMOUNT_VOLUME

Definition at line 49 of file btrfslib.c.

◆ FSCTL_LOCK_VOLUME

Definition at line 47 of file btrfslib.c.

◆ FSCTL_UNLOCK_VOLUME

Definition at line 48 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 152 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 219 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 199 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 172 of file btrfslib.c.

172  {
181  FMIFS_FLOPPY,
FMIFS_MEDIA_FLAG
Definition: btrfslib.c:172

Function Documentation

◆ add_block_group_items()

static void add_block_group_items ( LIST_ENTRY chunks,
btrfs_root extent_root 
)
static

Definition at line 1090 of file btrfslib.c.

1090  {
1091  LIST_ENTRY* le;
1092 
1093  le = chunks->Flink;
1094  while (le != chunks) {
1096  BLOCK_GROUP_ITEM bgi;
1097 
1098  bgi.used = c->used;
1099  bgi.chunk_tree = 0x100;
1100  bgi.flags = c->chunk_item->type;
1101  add_item(extent_root, c->offset, TYPE_BLOCK_GROUP_ITEM, c->chunk_item->size, &bgi, sizeof(BLOCK_GROUP_ITEM));
1102 
1103  le = le->Flink;
1104  }
1105 }
static void add_item(btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
Definition: btrfslib.c:365
UINT64 flags
Definition: btrfs.h:399
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:119
const GLubyte * c
Definition: glext.h:8905
#define TYPE_BLOCK_GROUP_ITEM
Definition: btrfs.h:36
Definition: typedefs.h:117
UINT64 chunk_tree
Definition: btrfs.h:398
Definition: list.h:27
UINT64 used
Definition: btrfs.h:397

Referenced by write_btrfs().

◆ add_chunk()

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

Definition at line 426 of file btrfslib.c.

426  {
427  UINT64 off, size;
428  UINT16 stripes, i;
429  btrfs_chunk* c;
430  LIST_ENTRY* le;
431  CHUNK_ITEM_STRIPE* cis;
432 
433  off = 0xc00000;
434  le = chunks->Flink;
435  while (le != chunks) {
437 
438  if (c->offset + c->chunk_item->size > off)
439  off = c->offset + c->chunk_item->size;
440 
441  le = le->Flink;
442  }
443 
444  if (flags & BLOCK_FLAG_METADATA) {
445  if (dev->dev_item.num_bytes > 0xC80000000) // 50 GB
446  size = 0x40000000; // 1 GB
447  else
448  size = 0x10000000; // 256 MB
449  } else if (flags & BLOCK_FLAG_SYSTEM)
450  size = 0x800000;
451 
452  size = min(size, dev->dev_item.num_bytes / 10); // cap at 10%
453  size &= ~(sector_size - 1);
454 
455  stripes = flags & BLOCK_FLAG_DUPLICATE ? 2 : 1;
456 
457  if (dev->dev_item.num_bytes - dev->dev_item.bytes_used < stripes * size) // not enough space
458  return NULL;
459 
460 #ifndef __REACTOS__
461  c = malloc(sizeof(btrfs_chunk));
462 #else
463  c = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(btrfs_chunk));
464 #endif
465  c->offset = off;
466  c->lastoff = off;
467  c->used = 0;
468 
469 #ifndef __REACTOS__
470  c->chunk_item = malloc(sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
471 #else
472  c->chunk_item = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
473 #endif
474 
475  c->chunk_item->size = size;
476  c->chunk_item->root_id = BTRFS_ROOT_EXTENT;
477  c->chunk_item->stripe_length = max(sector_size, 0x10000);
478  c->chunk_item->type = flags;
479  c->chunk_item->opt_io_alignment = max(sector_size, 0x10000);
480  c->chunk_item->opt_io_width = max(sector_size, 0x10000);
481  c->chunk_item->sector_size = sector_size;
482  c->chunk_item->num_stripes = stripes;
483  c->chunk_item->sub_stripes = 0;
484 
485  cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
486 
487  for (i = 0; i < stripes; i++) {
488  cis[i].dev_id = dev->dev_item.dev_id;
489  cis[i].offset = find_chunk_offset(size, c->offset, dev, dev_root, chunkuuid);
490  cis[i].dev_uuid = dev->dev_item.device_uuid;
491  }
492 
493  add_item(chunk_root, 0x100, TYPE_CHUNK_ITEM, c->offset, c->chunk_item, sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
494 
495  InsertTailList(chunks, &c->list_entry);
496 
497  return c;
498 }
static void add_item(btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
Definition: btrfslib.c:365
#define max(a, b)
Definition: svc.c:63
#define TYPE_CHUNK_ITEM
Definition: btrfs.h:42
UINT64 offset
Definition: btrfs.h:326
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:103
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:71
UINT64 dev_id
Definition: btrfs.h:325
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:585
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
static UINT64 find_chunk_offset(UINT64 size, UINT64 offset, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid)
Definition: btrfslib.c:406
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:327
GLbitfield flags
Definition: glext.h:7161
#define BLOCK_FLAG_METADATA
Definition: shellext.h:72
Definition: typedefs.h:117
__u8 sector_size[2]
Definition: mkdosfs.c:361
unsigned short UINT16
#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:75
#define BTRFS_ROOT_EXTENT
Definition: btrfs.h:49
unsigned long long UINT64
off
Definition: i386-dis.c:3909

Referenced by write_btrfs().

◆ add_item()

static void add_item ( btrfs_root r,
UINT64  obj_id,
UINT8  obj_type,
UINT64  offset,
void data,
UINT16  size 
)
static

Definition at line 365 of file btrfslib.c.

365  {
366  LIST_ENTRY* le;
367  btrfs_item* item;
368 
369 #ifndef __REACTOS__
370  item = malloc(sizeof(btrfs_item));
371 #else
372  item = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(btrfs_item));
373 #endif
374 
375  item->key.obj_id = obj_id;
376  item->key.obj_type = obj_type;
377  item->key.offset = offset;
378  item->size = size;
379 
380  if (size == 0)
381  item->data = NULL;
382  else {
383 #ifndef __REACTOS__
384  item->data = malloc(size);
385 #else
386  item->data = RtlAllocateHeap(RtlGetProcessHeap(), 0, size);
387 #endif
388  memcpy(item->data, data, size);
389  }
390 
391  le = r->items.Flink;
392  while (le != &r->items) {
394 
395  if (keycmp(item->key, i2->key) != 1) {
396  InsertTailList(le, &item->list_entry);
397  return;
398  }
399 
400  le = le->Flink;
401  }
402 
403  InsertTailList(&r->items, &item->list_entry);
404 }
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:103
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:152
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
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:117
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(), assign_addresses(), find_chunk_offset(), init_fs_tree(), and write_btrfs().

◆ add_root()

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

Definition at line 289 of file btrfslib.c.

289  {
290  btrfs_root* root;
291 
292 #ifdef __REACTOS__
293  root = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(btrfs_root));
294 #else
295  root = malloc(sizeof(btrfs_root));
296 #endif
297 
298  root->id = id;
299 #ifndef __REACTOS__
300  RtlZeroMemory(&root->header, sizeof(tree_header));
301 #endif
302  InitializeListHead(&root->items);
303  InsertTailList(roots, &root->list_entry);
304 
305  return root;
306 }
UINT64 id
Definition: btrfs_drv.h:421
LIST_ENTRY list_entry
Definition: btrfs_drv.h:432
struct _root root
FORCEINLINE VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
Definition: btrfslib.c:103
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead)
Definition: btrfslib.c:99
#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  node_size,
btrfs_root root_root,
btrfs_root extent_root,
BOOL  skinny 
)
static

Definition at line 549 of file btrfslib.c.

550  {
551  LIST_ENTRY* le;
552 
553  le = roots->Flink;
554  while (le != roots) {
556  btrfs_chunk* c = r->id == BTRFS_ROOT_CHUNK ? sys_chunk : metadata_chunk;
557 
558  r->header.address = get_next_address(c);
559  r->c = c;
560  c->lastoff = r->header.address + node_size;
561  c->used += node_size;
562 
563  if (skinny) {
565 
566  eim.ei.refcount = 1;
567  eim.ei.generation = 1;
570  eim.tbr.offset = r->id;
571 
572  add_item(extent_root, r->header.address, TYPE_METADATA_ITEM, 0, &eim, sizeof(EXTENT_ITEM_METADATA));
573  } else {
575  KEY firstitem;
576 
577  if (r->items.Flink == &r->items) {
578  firstitem.obj_id = 0;
579  firstitem.obj_type = 0;
580  firstitem.offset = 0;
581  } else {
582  btrfs_item* bi = CONTAINING_RECORD(r->items.Flink, btrfs_item, list_entry);
583 
584  firstitem = bi->key;
585  }
586 
587  eim2.ei.refcount = 1;
588  eim2.ei.generation = 1;
590  eim2.ei2.firstitem = firstitem;
591  eim2.ei2.level = 0;
592  eim2.type = TYPE_TREE_BLOCK_REF;
593  eim2.tbr.offset = r->id;
594 
595  add_item(extent_root, r->header.address, TYPE_EXTENT_ITEM, node_size, &eim2, sizeof(EXTENT_ITEM_METADATA2));
596  }
597 
598  if (r->id != BTRFS_ROOT_ROOT && r->id != BTRFS_ROOT_CHUNK) {
599  ROOT_ITEM ri;
600 
601  memset(&ri, 0, sizeof(ROOT_ITEM));
602 
603  ri.inode.generation = 1;
604  ri.inode.st_size = 3;
605  ri.inode.st_blocks = node_size;
606  ri.inode.st_nlink = 1;
607  ri.inode.st_mode = 040755;
608  ri.generation = 1;
609  ri.objid = r->id == 5 || r->id >= 0x100 ? SUBVOL_ROOT_INODE : 0;
610  ri.block_number = r->header.address;
611  ri.bytes_used = node_size;
612  ri.num_references = 1;
613  ri.generation2 = ri.generation;
614 
615  add_item(root_root, r->id, TYPE_ROOT_ITEM, 0, &ri, sizeof(ROOT_ITEM));
616  }
617 
618  le = le->Flink;
619  }
620 }
static void add_item(btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
Definition: btrfslib.c:365
UINT64 objid
Definition: btrfs.h:287
UINT64 offset
Definition: btrfs.h:125
EXTENT_ITEM2 ei2
Definition: btrfslib.c:544
static UINT64 get_next_address(btrfs_chunk *c)
Definition: btrfslib.c:521
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define SUBVOL_ROOT_INODE
Definition: propsheet.cpp:42
UINT64 generation
Definition: btrfs.h:366
#define TYPE_TREE_BLOCK_REF
Definition: btrfs.h:31
UINT64 obj_id
Definition: btrfs.h:123
EXTENT_ITEM ei
Definition: btrfslib.c:543
TREE_BLOCK_REF tbr
Definition: btrfslib.c:546
#define TYPE_METADATA_ITEM
Definition: btrfs.h:30
UINT64 bytes_used
Definition: btrfs.h:290
UINT32 st_mode
Definition: btrfs.h:273
UINT8 obj_type
Definition: btrfs.h:124
UINT64 generation
Definition: btrfs.h:265
#define TYPE_EXTENT_ITEM
Definition: btrfs.h:29
struct btrfs_disk_key key
Definition: btrfs.h:110
UINT64 generation
Definition: btrfs.h:286
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 BTRFS_ROOT_ROOT
Definition: btrfs.h:48
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
UINT64 generation2
Definition: btrfs.h:297
UINT64 block_number
Definition: btrfs.h:288
const GLubyte * c
Definition: glext.h:8905
KEY firstitem
Definition: btrfs.h:371
TREE_BLOCK_REF tbr
Definition: btrfslib.c:539
UINT64 st_blocks
Definition: btrfs.h:268
EXTENT_ITEM ei
Definition: btrfslib.c:537
Definition: typedefs.h:117
Definition: btrfs.h:122
UINT64 flags
Definition: btrfs.h:367
INODE_ITEM inode
Definition: btrfs.h:285
UINT64 st_size
Definition: btrfs.h:267
UINT64 refcount
Definition: btrfs.h:365
#define EXTENT_ITEM_TREE_BLOCK
Definition: btrfs.h:361
#define TYPE_ROOT_ITEM
Definition: btrfs.h:26
Definition: list.h:27
UINT8 level
Definition: btrfs.h:372
#define c
Definition: ke_i.h:80
UINT32 st_nlink
Definition: btrfs.h:270
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:50
UINT32 num_references
Definition: btrfs.h:293
#define memset(x, y, z)
Definition: compat.h:39
UINT64 offset
Definition: btrfs.h:386

Referenced by write_btrfs().

◆ calc_crc32c()

static UINT32 calc_crc32c ( UINT32  seed,
UINT8 msg,
ULONG  msglen 
)
static

Definition at line 256 of file btrfslib.c.

256  {
257  UINT32 rem;
258  ULONG i;
259 
260  rem = seed;
261 
262  for (i = 0; i < msglen; i++) {
263  rem = crctable[(rem ^ msg[i]) & 0xff] ^ (rem >> 8);
264  }
265 
266  return rem;
267 }
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
unsigned int UINT32
static const UINT32 crctable[]
Definition: btrfslib.c:221
#define msg(x)
Definition: auth_time.c:54
unsigned int ULONG
Definition: retypes.h:1

Referenced by is_mounted_multi_device(), write_roots(), and write_superblocks().

◆ ChkdskEx()

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

Definition at line 270 of file btrfslib.c.

274  {
275  // STUB
276 
277  if (Callback) {
279 
280  TextOut.Lines = 1;
281  TextOut.Output = "stub, not implemented";
282 
283  Callback(OUTPUT, 0, &TextOut);
284  }
285 
286  return STATUS_SUCCESS;
287 }
#define TextOut
Definition: wingdi.h:4461
return STATUS_SUCCESS
Definition: btrfs.c:2725
LPFNPSPCALLBACK Callback
Definition: desk.c:111

◆ clear_first_megabyte()

static NTSTATUS clear_first_megabyte ( HANDLE  h)
static

Definition at line 1107 of file btrfslib.c.

1107  {
1108  NTSTATUS Status;
1111  UINT8* mb;
1112 
1113 
1114 #ifndef __REACTOS__
1115  mb = malloc(0x100000);
1116  memset(mb, 0, 0x100000);
1117 #else
1118  mb = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, 0x100000);
1119 #endif
1120 
1121  zero.QuadPart = 0;
1122 
1123  Status = NtWriteFile(h, NULL, NULL, NULL, &iosb, mb, 0x100000, &zero, NULL);
1124 
1125 #ifndef __REACTOS__
1126  free(mb);
1127 #else
1128  RtlFreeHeap(RtlGetProcessHeap(), 0, mb);
1129 #endif
1130 
1131  return Status;
1132 }
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:603
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:585
static double zero
Definition: j0_y0.c:96
Status
Definition: gdiplustypes.h:24
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define malloc
Definition: debug_ros.c:4
unsigned char UINT8
#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 1653 of file btrfslib.c.

1653  {
1655  module = (HMODULE)hModule;
1656 
1657  return TRUE;
1658 }
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
DWORD dwReason
Definition: misc.cpp:154
HANDLE HMODULE
Definition: typedefs.h:75
HMODULE hModule
Definition: animate.c:44

◆ do_full_trim()

static void do_full_trim ( HANDLE  h)
static

Definition at line 1415 of file btrfslib.c.

1415  {
1418 
1420 
1421  dmdsa.Size = sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES);
1422  dmdsa.Action = DeviceDsmAction_Trim;
1424  dmdsa.ParameterBlockOffset = 0;
1425  dmdsa.ParameterBlockLength = 0;
1426  dmdsa.DataSetRangesOffset = 0;
1427  dmdsa.DataSetRangesLength = 0;
1428 
1430 }
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:52
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 find_chunk_offset ( UINT64  size,
UINT64  offset,
btrfs_dev dev,
btrfs_root dev_root,
BTRFS_UUID chunkuuid 
)
static

Definition at line 406 of file btrfslib.c.

406  {
407  UINT64 off;
408  DEV_EXTENT de;
409 
410  off = dev->last_alloc;
411  dev->last_alloc += size;
412 
413  dev->dev_item.bytes_used += size;
414 
416  de.objid = 0x100;
417  de.address = offset;
418  de.length = size;
419  de.chunktree_uuid = *chunkuuid;
420 
421  add_item(dev_root, dev->dev_item.dev_id, TYPE_DEV_EXTENT, off, &de, sizeof(DEV_EXTENT));
422 
423  return off;
424 }
static void add_item(btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
Definition: btrfslib.c:365
GLintptr offset
Definition: glext.h:5920
UINT64 length
Definition: btrfs.h:445
#define TYPE_DEV_EXTENT
Definition: btrfs.h:40
UINT64 objid
Definition: btrfs.h:443
GLsizeiptr size
Definition: glext.h:5919
UINT64 address
Definition: btrfs.h:444
UINT64 chunktree
Definition: btrfs.h:442
uint64_t dev_id
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:50
unsigned long long UINT64
BTRFS_UUID chunktree_uuid
Definition: btrfs.h:446
off
Definition: i386-dis.c:3909

Referenced by add_chunk().

◆ FormatEx()

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

Definition at line 1607 of file btrfslib.c.

1607  {
1608  UNICODE_STRING DriveRoot, Label;
1609  NTSTATUS Status;
1610 
1611  if (!root || !root->string)
1612  return FALSE;
1613 
1614  DriveRoot.Length = DriveRoot.MaximumLength = wcslen(root->string) * sizeof(WCHAR);
1615  DriveRoot.Buffer = root->string;
1616 
1617  if (opts && opts->label && opts->label->string) {
1618  Label.Length = Label.MaximumLength = wcslen(opts->label->string) * sizeof(WCHAR);
1619  Label.Buffer = opts->label->string;
1620  } else {
1621  Label.Length = Label.MaximumLength = 0;
1622  Label.Buffer = NULL;
1623  }
1624 
1625 #ifndef __REACTOS__
1626  Status = FormatEx2(&DriveRoot, FMIFS_HARDDISK, &Label, opts && opts->flags & FORMAT_FLAG_QUICK_FORMAT, 0, NULL);
1627 #else
1628  Status = BtrfsFormatEx(&DriveRoot, FMIFS_HARDDISK, &Label, opts && opts->flags & FORMAT_FLAG_QUICK_FORMAT, 0, NULL);
1629 #endif
1630 
1631  return NT_SUCCESS(Status);
1632 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
#define FORMAT_FLAG_QUICK_FORMAT
Definition: btrfslib.c:84
DSTRING * label
Definition: btrfslib.c:95
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:1437
WCHAR * string
Definition: btrfslib.c:77
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UINT32 flags
Definition: btrfslib.c:94
Status
Definition: gdiplustypes.h:24
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 1437 of file btrfslib.c.

1442 {
1443  NTSTATUS Status;
1444  HANDLE h, btrfsh;
1448  DISK_GEOMETRY dg;
1449  UINT32 sector_size, node_size;
1450  UNICODE_STRING btrfsus;
1451 #ifndef __REACTOS__
1452  HANDLE token;
1454  LUID luid;
1455 #endif
1456  UINT64 incompat_flags;
1457  UNICODE_STRING empty_label;
1458 
1459  static WCHAR btrfs[] = L"\\Btrfs";
1460 
1461 #ifndef __REACTOS__
1464 
1465  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
1466  CloseHandle(token);
1468  }
1469 
1470  tp.PrivilegeCount = 1;
1471  tp.Privileges[0].Luid = luid;
1472  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1473 
1475  CloseHandle(token);
1477  }
1478 
1479  CloseHandle(token);
1480 #endif
1481 
1483 
1486 
1487  if (!NT_SUCCESS(Status))
1488  return Status;
1489 
1491  if (!NT_SUCCESS(Status)) {
1492  NtClose(h);
1493  return Status;
1494  }
1495 
1496  // MSDN tells us to use IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, but there are
1497  // some instances where it fails and IOCTL_DISK_GET_DRIVE_GEOMETRY succeeds -
1498  // such as with spanned volumes.
1500  if (!NT_SUCCESS(Status)) {
1501  NtClose(h);
1502  return Status;
1503  }
1504 
1505  if (def_sector_size == 0) {
1507 
1508  if (sector_size == 0x200 || sector_size == 0)
1509  sector_size = 0x1000;
1510  } else {
1512  NtClose(h);
1513  return STATUS_INVALID_PARAMETER;
1514  }
1515 
1517  }
1518 
1519  if (def_node_size == 0)
1520  node_size = 0x4000;
1521  else {
1523  NtClose(h);
1524  return STATUS_INVALID_PARAMETER;
1525  }
1526 
1527  node_size = def_node_size;
1528  }
1529 
1530  if (Callback) {
1531  ULONG pc = 0;
1532  Callback(PROGRESS, 0, (PVOID)&pc);
1533  }
1534 
1536 
1539  goto end;
1540  }
1541 
1542  do_full_trim(h);
1543 
1544  incompat_flags = def_incompat_flags;
1546 
1547  if (!Label) {
1548  empty_label.Buffer = NULL;
1549  empty_label.Length = empty_label.MaximumLength = 0;
1550  Label = &empty_label;
1551  }
1552 
1553  Status = write_btrfs(h, gli.Length.QuadPart, Label, sector_size, node_size, incompat_flags);
1554 
1556 
1557 end:
1559 
1560  NtClose(h);
1561 
1562  if (NT_SUCCESS(Status)) {
1563  btrfsus.Buffer = btrfs;
1564  btrfsus.Length = btrfsus.MaximumLength = wcslen(btrfs) * sizeof(WCHAR);
1565 
1566  InitializeObjectAttributes(&attr, &btrfsus, 0, NULL, NULL);
1567 
1570 
1571  if (NT_SUCCESS(Status)) {
1572  MOUNTDEV_NAME* mdn;
1573  ULONG mdnsize;
1574 
1575  mdnsize = offsetof(MOUNTDEV_NAME, Name[0]) + DriveRoot->Length;
1576 #ifndef __REACTOS__
1577  mdn = malloc(mdnsize);
1578 #else
1579  mdn = RtlAllocateHeap(RtlGetProcessHeap(), 0, mdnsize);
1580 #endif
1581 
1582  mdn->NameLength = DriveRoot->Length;
1583  memcpy(mdn->Name, DriveRoot->Buffer, DriveRoot->Length);
1584 
1585  NtDeviceIoControlFile(btrfsh, NULL, NULL, NULL, &iosb, IOCTL_BTRFS_PROBE_VOLUME, mdn, mdnsize, NULL, 0);
1586 
1587 #ifndef __REACTOS__
1588  free(mdn);
1589 #else
1590  RtlFreeHeap(RtlGetProcessHeap(), 0, mdn);
1591 #endif
1592 
1593  NtClose(btrfsh);
1594  }
1595 
1597  }
1598 
1599  if (Callback) {
1601  Callback(DONE, 0, (PVOID)&success);
1602  }
1603 
1604  return Status;
1605 }
#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:398
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
static BOOL is_power_of_two(ULONG i)
Definition: btrfslib.c:1432
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#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:603
static NTSTATUS write_btrfs(HANDLE h, UINT64 size, PUNICODE_STRING label, UINT32 sector_size, UINT32 node_size, UINT64 incompat_flags)
Definition: btrfslib.c:1181
ULONG BytesPerSector
Definition: ntdddisk.h:376
GLuint GLuint end
Definition: gl.h:1545
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2645
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:48
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
unsigned int UINT32
unsigned int BOOL
Definition: ntddk_ex.h:94
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
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:103
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:1168
static void do_full_trim(HANDLE h)
Definition: btrfslib.c:1415
#define success(from, fromstr, to, tostr)
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
Definition: cookie.c:170
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ULONG def_node_size
Definition: btrfslib.c:162
#define IOCTL_BTRFS_PROBE_VOLUME
Definition: btrfsioctl.h:29
__u8 attr
Definition: mkdosfs.c:359
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:108
Definition: btrfslib.c:211
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG def_sector_size
Definition: btrfslib.c:162
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 FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define FSCTL_DISMOUNT_VOLUME
Definition: btrfslib.c:49
static BOOL is_mounted_multi_device(HANDLE h, UINT32 sector_size)
Definition: btrfslib.c:1283
UINT64 def_incompat_flags
Definition: btrfslib.c:163
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
#define FSCTL_LOCK_VOLUME
Definition: btrfslib.c:47
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
unsigned long long UINT64
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
LPFNPSPCALLBACK Callback
Definition: desk.c:111
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:112

Referenced by FormatEx().

◆ free_chunks()

static void free_chunks ( LIST_ENTRY chunks)
static

Definition at line 345 of file btrfslib.c.

345  {
346  LIST_ENTRY* le;
347 
348  le = chunks->Flink;
349  while (le != chunks) {
350  LIST_ENTRY *le2 = le->Flink;
352 
353 #ifndef __REACTOS__
354  free(c->chunk_item);
355  free(c);
356 #else
357  RtlFreeHeap(RtlGetProcessHeap(), 0, c->chunk_item);
358  RtlFreeHeap(RtlGetProcessHeap(), 0, c);
359 #endif
360 
361  le = le2;
362  }
363 }
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
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:119
const GLubyte * c
Definition: glext.h:8905
Definition: typedefs.h:117
Definition: list.h:27

Referenced by write_btrfs().

◆ free_roots()

static void free_roots ( LIST_ENTRY roots)
static

Definition at line 308 of file btrfslib.c.

308  {
309  LIST_ENTRY* le;
310 
311  le = roots->Flink;
312  while (le != roots) {
313  LIST_ENTRY *le2 = le->Flink, *le3;
315 
316  le3 = r->items.Flink;
317  while (le3 != &r->items) {
318  LIST_ENTRY* le4 = le3->Flink;
320 
321  if (item->data)
322 #ifdef __REACTOS__
323  RtlFreeHeap(RtlGetProcessHeap(), 0, item->data);
324 
325  RtlFreeHeap(RtlGetProcessHeap(), 0, item);
326 #else
327  free(item->data);
328 
329  free(item);
330 #endif
331 
332  le3 = le4;
333  }
334 
335 #ifdef __REACTOS__
336  RtlFreeHeap(RtlGetProcessHeap(), 0, r);
337 #else
338  free(r);
339 #endif
340 
341  le = le2;
342  }
343 }
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:603
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:119
Definition: typedefs.h:117
static ATOM item
Definition: dde.c:856
Definition: list.h:27

Referenced by write_btrfs().

◆ get_next_address()

static UINT64 get_next_address ( btrfs_chunk c)
static

Definition at line 521 of file btrfslib.c.

521  {
522  UINT64 addr;
523 
524  addr = c->lastoff;
525 
526  while (superblock_collision(c, addr)) {
527  addr = addr - ((addr - c->offset) % c->chunk_item->stripe_length) + c->chunk_item->stripe_length;
528 
529  if (addr >= c->offset + c->chunk_item->size) // chunk has been exhausted
530  return 0;
531  }
532 
533  return addr;
534 }
const GLubyte * c
Definition: glext.h:8905
GLenum const GLvoid * addr
Definition: glext.h:9621
static BOOL superblock_collision(btrfs_chunk *c, UINT64 address)
Definition: btrfslib.c:500
unsigned long long UINT64

Referenced by assign_addresses().

◆ get_uuid()

static void get_uuid ( BTRFS_UUID uuid)
static

Definition at line 723 of file btrfslib.c.

723  {
724 #else
725 static void get_uuid(BTRFS_UUID* uuid, ULONG* seed) {
726 #endif
727  UINT8 i;
728 
729  for (i = 0; i < 16; i+=2) {
730 #ifndef __REACTOS__
731  ULONG r = rand();
732 #else
733  ULONG r = RtlRandom(seed);
734 #endif
735 
736  uuid->uuid[i] = (r & 0xff00) >> 8;
737  uuid->uuid[i+1] = r & 0xff;
738  }
739 }
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
Definition: msctf.idl:510
unsigned int ULONG
Definition: retypes.h:1
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:723
unsigned char UINT8

Referenced by init_device(), and write_btrfs().

◆ GetFilesystemInformation()

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

Definition at line 1646 of file btrfslib.c.

1646  {
1647  // STUB - undocumented
1648 
1649  return TRUE;
1650 }
#define TRUE
Definition: types.h:120

◆ init_device()

static void init_device ( btrfs_dev dev,
UINT64  id,
UINT64  size,
BTRFS_UUID fsuuid,
UINT32  sector_size 
)
static

Definition at line 742 of file btrfslib.c.

742  {
743 #else
744 static void init_device(btrfs_dev* dev, UINT64 id, UINT64 size, BTRFS_UUID* fsuuid, UINT32 sector_size, ULONG* seed) {
745 #endif
746  dev->dev_item.dev_id = id;
747  dev->dev_item.num_bytes = size;
748  dev->dev_item.bytes_used = 0;
749  dev->dev_item.optimal_io_align = sector_size;
750  dev->dev_item.optimal_io_width = sector_size;
751  dev->dev_item.minimal_io_size = sector_size;
752  dev->dev_item.type = 0;
753  dev->dev_item.generation = 0;
754  dev->dev_item.start_offset = 0;
755  dev->dev_item.dev_group = 0;
756  dev->dev_item.seek_speed = 0;
757  dev->dev_item.bandwidth = 0;
758 #ifndef __REACTOS__
759  get_uuid(&dev->dev_item.device_uuid);
760 #else
761  get_uuid(&dev->dev_item.device_uuid, seed);
762 #endif
763  dev->dev_item.fs_uuid = *fsuuid;
764 
765  dev->last_alloc = 0x100000; // skip first megabyte
766 }
static void init_device(btrfs_dev *dev, UINT64 id, UINT64 size, BTRFS_UUID *fsuuid, UINT32 sector_size)
Definition: btrfslib.c:742
unsigned int UINT32
GLsizeiptr size
Definition: glext.h:5919
__u8 sector_size[2]
Definition: mkdosfs.c:361
uint64_t dev_id
unsigned int ULONG
Definition: retypes.h:1
GLenum GLuint id
Definition: glext.h:5579
unsigned long long UINT64
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:723

Referenced by write_btrfs().

◆ init_fs_tree()

static void init_fs_tree ( btrfs_root r,
UINT32  node_size 
)
static

Definition at line 1048 of file btrfslib.c.

1048  {
1049  INODE_ITEM ii;
1050  INODE_REF* ir;
1053 
1054  memset(&ii, 0, sizeof(INODE_ITEM));
1055 
1056  ii.generation = 1;
1057  ii.st_blocks = node_size;
1058  ii.st_nlink = 1;
1059  ii.st_mode = 040755;
1060 
1062  time.LowPart = filetime.dwLowDateTime;
1063  time.HighPart = filetime.dwHighDateTime;
1064 
1066  ii.st_ctime = ii.st_mtime = ii.st_atime;
1067 
1069 
1070 #ifndef __REACTOS__
1071  ir = malloc(sizeof(INODE_REF) - 1 + 2);
1072 #else
1073  ir = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(INODE_REF) - 1 + 2);
1074 #endif
1075 
1076  ir->index = 0;
1077  ir->n = 2;
1078  ir->name[0] = '.';
1079  ir->name[1] = '.';
1080 
1082 
1083 #ifndef __REACTOS__
1084  free(ir);
1085 #else
1086  RtlFreeHeap(RtlGetProcessHeap(), 0, ir);
1087 #endif
1088 }
static void add_item(btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
Definition: btrfslib.c:365
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
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
__u16 time
Definition: mkdosfs.c:366
BTRFS_TIME st_ctime
Definition: btrfs.h:279
UINT32 st_mode
Definition: btrfs.h:273
UINT64 generation
Definition: btrfs.h:265
char name[1]
Definition: btrfs.h:350
UINT64 index
Definition: btrfs.h:348
#define TYPE_INODE_REF
Definition: btrfs.h:19
BTRFS_TIME st_mtime
Definition: btrfs.h:280
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
BTRFS_TIME st_atime
Definition: btrfs.h:278
UINT64 st_blocks
Definition: btrfs.h:268
#define TYPE_INODE_ITEM
Definition: btrfs.h:18
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME *out)
Definition: btrfslib.c:1022
UINT32 st_nlink
Definition: btrfs.h:270
UINT16 n
Definition: btrfs.h:349
#define malloc
Definition: debug_ros.c:4
#define memset(x, y, z)
Definition: compat.h:39

Referenced by write_btrfs().

◆ InitializeListHead()

FORCEINLINE VOID InitializeListHead ( PLIST_ENTRY  ListHead)

Definition at line 99 of file btrfslib.c.

99  {
100  ListHead->Flink = ListHead->Blink = ListHead;
101 }
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119

Referenced by add_root(), and write_btrfs().

◆ InsertTailList()

FORCEINLINE VOID InsertTailList ( PLIST_ENTRY  ListHead,
PLIST_ENTRY  Entry 
)

Definition at line 103 of file btrfslib.c.

103  {
104  PLIST_ENTRY Blink;
105 
106  Blink = ListHead->Blink;
107  Entry->Flink = ListHead;
108  Entry->Blink = Blink;
109  Blink->Flink = Entry;
110  ListHead->Blink = Entry;
111 }
struct _Entry Entry
Definition: kefuncs.h:640
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
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  sector_size 
)
static

Definition at line 1283 of file btrfslib.c.

1283  {
1284  NTSTATUS Status;
1285  superblock* sb;
1286  ULONG sblen;
1289  BTRFS_UUID fsuuid, devuuid;
1290  UINT32 crc32;
1293  HANDLE h2;
1294  btrfs_filesystem *bfs = NULL, *bfs2;
1295  ULONG bfssize;
1296  BOOL ret = FALSE;
1297 
1298  static WCHAR btrfs[] = L"\\Btrfs";
1299 
1300  sblen = sizeof(sb);
1301  if (sblen & (sector_size - 1))
1302  sblen = (sblen & sector_size) + sector_size;
1303 
1304 #ifndef __REACTOS__
1305  sb = malloc(sblen);
1306 #else
1307  sb = RtlAllocateHeap(RtlGetProcessHeap(), 0, sblen);
1308 #endif
1309 
1310  off.QuadPart = superblock_addrs[0];
1311 
1312  Status = NtReadFile(h, NULL, NULL, NULL, &iosb, sb, sblen, &off, NULL);
1313  if (!NT_SUCCESS(Status)) {
1314 #ifndef __REACTOS__
1315  free(sb);
1316 #else
1317  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1318 #endif
1319  return FALSE;
1320  }
1321 
1322  if (sb->magic != BTRFS_MAGIC) {
1323 #ifndef __REACTOS__
1324  free(sb);
1325 #else
1326  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1327 #endif
1328  return FALSE;
1329  }
1330 
1331  crc32 = ~calc_crc32c(0xffffffff, (UINT8*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
1332  if (crc32 != *((UINT32*)sb)) {
1333 #ifndef __REACTOS__
1334  free(sb);
1335 #else
1336  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1337 #endif
1338  return FALSE;
1339  }
1340 
1341  fsuuid = sb->uuid;
1342  devuuid = sb->dev_item.device_uuid;
1343 
1344 #ifndef __REACTOS__
1345  free(sb);
1346 #else
1347  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1348 #endif
1349 
1350  us.Length = us.MaximumLength = wcslen(btrfs) * sizeof(WCHAR);
1351  us.Buffer = btrfs;
1352 
1354 
1357  if (!NT_SUCCESS(Status)) // not a problem, it usually just means the driver isn't loaded
1358  return FALSE;
1359 
1360  bfssize = 0;
1361 
1362  do {
1363  bfssize += 1024;
1364 
1365 #ifndef __REACTOS__
1366  if (bfs) free(bfs);
1367  bfs = malloc(bfssize);
1368 #else
1369  if (bfs) RtlFreeHeap(RtlGetProcessHeap(), 0, bfs);
1370  bfs = RtlAllocateHeap(RtlGetProcessHeap(), 0, bfssize);
1371 #endif
1372 
1375  NtClose(h2);
1376  return FALSE;
1377  }
1378  } while (Status == STATUS_BUFFER_OVERFLOW);
1379 
1380  if (!NT_SUCCESS(Status))
1381  goto end;
1382 
1383  if (bfs->num_devices != 0) {
1384  bfs2 = bfs;
1385  while (TRUE) {
1386  if (RtlCompareMemory(&bfs2->uuid, &fsuuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
1387  if (bfs2->num_devices == 1)
1388  ret = FALSE;
1389  else
1390  ret = look_for_device(bfs2, &devuuid);
1391 
1392  goto end;
1393  }
1394 
1395  if (bfs2->next_entry == 0)
1396  break;
1397  else
1398  bfs2 = (btrfs_filesystem*)((UINT8*)bfs2 + bfs2->next_entry);
1399  }
1400  }
1401 
1402 end:
1403  NtClose(h2);
1404 
1405  if (bfs)
1406 #ifndef __REACTOS__
1407  free(bfs);
1408 #else
1409  RtlFreeHeap(RtlGetProcessHeap(), 0, bfs);
1410 #endif
1411 
1412  return ret;
1413 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define TRUE
Definition: types.h:120
static BOOL look_for_device(btrfs_filesystem *bfs, BTRFS_UUID *devuuid)
Definition: btrfslib.c:1266
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)
superblock * sb
Definition: btrfs.c:3876
static const BYTE us[]
Definition: encode.c:689
#define IOCTL_BTRFS_QUERY_FILESYSTEMS
Definition: btrfsioctl.h:22
#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:603
static UINT32 calc_crc32c(UINT32 seed, UINT8 *msg, ULONG msglen)
Definition: btrfslib.c:256
UINT32 crc32
Definition: btrfs.c:3877
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
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
unsigned int UINT32
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
DEV_ITEM dev_item
Definition: btrfs.h:230
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
BTRFS_UUID device_uuid
Definition: btrfs.h:169
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
static const UINT64 superblock_addrs[]
Definition: btrfs.h:12
#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
UINT8 checksum[32]
Definition: btrfs.h:203
UINT32 num_devices
Definition: btrfsioctl.h:204
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
BTRFS_UUID uuid
Definition: btrfs.h:204
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
UINT64 magic
Definition: btrfs.h:207
unsigned char UINT8
_In_ UINT16 _Out_ ULONG * atts
Definition: btrfs_drv.h:1080
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#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 1432 of file btrfslib.c.

1432  {
1433  return ((i != 0) && !(i & (i - 1)));
1434 }
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 1134 of file btrfslib.c.

1134  {
1135  ULONG aptelen;
1136  ATA_PASS_THROUGH_EX* apte;
1138  NTSTATUS Status;
1139  IDENTIFY_DEVICE_DATA* idd;
1140 
1141  aptelen = sizeof(ATA_PASS_THROUGH_EX) + 512;
1142 #ifndef __REACTOS__
1143  apte = malloc(aptelen);
1144 
1145  RtlZeroMemory(apte, aptelen);
1146 #else
1147  apte = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, aptelen);
1148 #endif
1149 
1150  apte->Length = sizeof(ATA_PASS_THROUGH_EX);
1151  apte->AtaFlags = ATA_FLAGS_DATA_IN;
1152  apte->DataTransferLength = aptelen - sizeof(ATA_PASS_THROUGH_EX);
1153  apte->TimeOutValue = 3;
1154  apte->DataBufferOffset = apte->Length;
1156 
1157  Status = NtDeviceIoControlFile(h, NULL, NULL, NULL, &iosb, IOCTL_ATA_PASS_THROUGH, apte, aptelen, apte, aptelen);
1158 
1159  if (NT_SUCCESS(Status)) {
1160  idd = (IDENTIFY_DEVICE_DATA*)((UINT8*)apte + sizeof(ATA_PASS_THROUGH_EX));
1161 
1162  if (idd->NominalMediaRotationRate == 1) {
1163 #ifndef __REACTOS__
1164  free(apte);
1165 #else
1166  RtlFreeHeap(RtlGetProcessHeap(), 0, apte);
1167 #endif
1168  return TRUE;
1169  }
1170  }
1171 
1172 #ifndef __REACTOS__
1173  free(apte);
1174 #else
1175  RtlFreeHeap(RtlGetProcessHeap(), 0, apte);
1176 #endif
1177 
1178  return FALSE;
1179 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define TRUE
Definition: types.h:120
#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:603
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:585
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG DataTransferLength
Definition: ntddscsi.h:136
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
unsigned char UINT8

Referenced by write_btrfs().

◆ look_for_device()

static BOOL look_for_device ( btrfs_filesystem bfs,
BTRFS_UUID devuuid 
)
static

Definition at line 1266 of file btrfslib.c.

1266  {
1267  UINT32 i;
1269 
1270  for (i = 0; i < bfs->num_devices; i++) {
1271  if (i == 0)
1272  dev = &bfs->device;
1273  else
1275 
1276  if (RtlCompareMemory(&dev->uuid, devuuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID))
1277  return TRUE;
1278  }
1279 
1280  return FALSE;
1281 }
#define TRUE
Definition: types.h:120
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
unsigned int UINT32
#define offsetof(TYPE, MEMBER)
UINT32 num_devices
Definition: btrfsioctl.h:204
Definition: name.c:36
unsigned char UINT8
btrfs_filesystem_device device
Definition: btrfsioctl.h:205
#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 
)

◆ RtlUnicodeToUTF8N()

NTSYSAPI NTSTATUS NTAPI RtlUnicodeToUTF8N ( PCHAR  UTF8StringDestination,
ULONG  UTF8StringMaxByteCount,
PULONG  UTF8StringActualByteCount,
PCWCH  UnicodeStringSource,
ULONG  UnicodeStringByteCount 
)

Referenced by init_device(), and write_superblocks().

◆ SetIncompatFlags()

void __stdcall SetIncompatFlags ( UINT64  incompat_flags)

Definition at line 1642 of file btrfslib.c.

1642  {
1643  def_incompat_flags = incompat_flags;
1644 }
UINT64 def_incompat_flags
Definition: btrfslib.c:163

◆ SetSizes()

void __stdcall SetSizes ( ULONG  sector,
ULONG  node 
)

Definition at line 1634 of file btrfslib.c.

1634  {
1635  if (sector != 0)
1637 
1638  if (node != 0)
1639  def_node_size = node;
1640 }
uint8_t sector
Definition: isohybrid.c:61
struct node node
ULONG def_node_size
Definition: btrfslib.c:162
ULONG def_sector_size
Definition: btrfslib.c:162
Definition: dlist.c:348

◆ superblock_collision()

static BOOL superblock_collision ( btrfs_chunk c,
UINT64  address 
)
static

Definition at line 500 of file btrfslib.c.

500  {
501  CHUNK_ITEM_STRIPE* cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
502  UINT64 stripe = (address - c->offset) / c->chunk_item->stripe_length;
503  UINT16 i, j;
504 
505  for (i = 0; i < c->chunk_item->num_stripes; i++) {
506  j = 0;
507  while (superblock_addrs[j] != 0) {
508  if (superblock_addrs[j] >= cis[i].offset) {
509  UINT64 stripe2 = (superblock_addrs[j] - cis[i].offset) / c->chunk_item->stripe_length;
510 
511  if (stripe2 == stripe)
512  return TRUE;
513  }
514  j++;
515  }
516  }
517 
518  return FALSE;
519 }
#define TRUE
Definition: types.h:120
GLintptr offset
Definition: glext.h:5920
Definition: write.c:115
UINT64 offset
Definition: btrfs.h:326
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
static const UINT64 superblock_addrs[]
Definition: btrfs.h:12
const GLubyte * c
Definition: glext.h:8905
GLuint address
Definition: glext.h:9393
unsigned short UINT16
unsigned long long UINT64

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 1022 of file btrfslib.c.

1022  {
1023  ULONGLONG l = t.QuadPart - 116444736000000000;
1024 
1025  out->seconds = l / 10000000;
1026  out->nanoseconds = (l % 10000000) * 100;
1027 }
GLdouble GLdouble t
Definition: gl.h:2047
r l[0]
Definition: byte_order.h:167
uint64_t ULONGLONG
Definition: typedefs.h:65
static FILE * out
Definition: regtests2xml.c:44

Referenced by init_fs_tree().

◆ write_btrfs()

static NTSTATUS write_btrfs ( HANDLE  h,
UINT64  size,
PUNICODE_STRING  label,
UINT32  sector_size,
UINT32  node_size,
UINT64  incompat_flags 
)
static

Definition at line 1181 of file btrfslib.c.

1181  {
1182  NTSTATUS Status;
1183  LIST_ENTRY roots, chunks;
1184  btrfs_root *root_root, *chunk_root, *extent_root, *dev_root, *fs_root, *reloc_root;
1185  btrfs_chunk *sys_chunk, *metadata_chunk;
1186  btrfs_dev dev;
1187  BTRFS_UUID fsuuid, chunkuuid;
1188  BOOL ssd;
1189  UINT64 metadata_flags;
1190 #ifdef __REACTOS__
1191  ULONG seed;
1192 #endif
1193 
1194 #ifndef __REACTOS__
1195  srand(time(0));
1196  get_uuid(&fsuuid);
1197  get_uuid(&chunkuuid);
1198 #else
1199  seed = NtGetTickCount();
1200  get_uuid(&fsuuid, &seed);
1201  get_uuid(&chunkuuid, &seed);
1202 #endif
1203 
1204  InitializeListHead(&roots);
1205  InitializeListHead(&chunks);
1206 
1207  root_root = add_root(&roots, BTRFS_ROOT_ROOT);
1208  chunk_root = add_root(&roots, BTRFS_ROOT_CHUNK);
1209  extent_root = add_root(&roots, BTRFS_ROOT_EXTENT);
1210  dev_root = add_root(&roots, BTRFS_ROOT_DEVTREE);
1211  add_root(&roots, BTRFS_ROOT_CHECKSUM);
1212  fs_root = add_root(&roots, BTRFS_ROOT_FSTREE);
1214 
1215 #ifndef __REACTOS__
1216  init_device(&dev, 1, size, &fsuuid, sector_size);
1217 #else
1218  init_device(&dev, 1, size, &fsuuid, sector_size, &seed);
1219 #endif
1220 
1221  ssd = is_ssd(h);
1222 
1223  sys_chunk = add_chunk(&chunks, BLOCK_FLAG_SYSTEM | (ssd ? 0 : BLOCK_FLAG_DUPLICATE), chunk_root, &dev, dev_root, &chunkuuid, sector_size);
1224  if (!sys_chunk)
1225  return STATUS_INTERNAL_ERROR;
1226 
1227  metadata_flags = BLOCK_FLAG_METADATA;
1228 
1229  if (!ssd && !(incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS))
1230  metadata_flags |= BLOCK_FLAG_DUPLICATE;
1231 
1232  if (incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS)
1233  metadata_flags |= BLOCK_FLAG_DATA;
1234 
1235  metadata_chunk = add_chunk(&chunks, metadata_flags, chunk_root, &dev, dev_root, &chunkuuid, sector_size);
1236  if (!metadata_chunk)
1237  return STATUS_INTERNAL_ERROR;
1238 
1239  add_item(chunk_root, 1, TYPE_DEV_ITEM, dev.dev_item.dev_id, &dev.dev_item, sizeof(DEV_ITEM));
1240 
1241  init_fs_tree(fs_root, node_size);
1242  init_fs_tree(reloc_root, node_size);
1243 
1244  assign_addresses(&roots, sys_chunk, metadata_chunk, node_size, root_root, extent_root, incompat_flags & BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA);
1245 
1246  add_block_group_items(&chunks, extent_root);
1247 
1248  Status = write_roots(h, &roots, node_size, &fsuuid, &chunkuuid);
1249  if (!NT_SUCCESS(Status))
1250  return Status;
1251 
1253  if (!NT_SUCCESS(Status))
1254  return Status;
1255 
1256  Status = write_superblocks(h, &dev, chunk_root, root_root, extent_root, sys_chunk, node_size, &fsuuid, sector_size, label, incompat_flags);
1257  if (!NT_SUCCESS(Status))
1258  return Status;
1259 
1260  free_roots(&roots);
1261  free_chunks(&chunks);
1262 
1263  return STATUS_SUCCESS;
1264 }
static void add_item(btrfs_root *r, UINT64 obj_id, UINT8 obj_type, UINT64 offset, void *data, UINT16 size)
Definition: btrfslib.c:365
#define TYPE_DEV_ITEM
Definition: btrfs.h:41
static void init_device(btrfs_dev *dev, UINT64 id, UINT64 size, BTRFS_UUID *fsuuid, UINT32 sector_size)
Definition: btrfslib.c:742
char * reloc_root
Definition: mkisofs.c:177
static BOOL is_ssd(HANDLE h)
Definition: btrfslib.c:1134
LONG NTSTATUS
Definition: precomp.h:26
static void init_fs_tree(btrfs_root *r, UINT32 node_size)
Definition: btrfslib.c:1048
void __cdecl srand(_In_ unsigned int _Seed)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:111
__u16 time
Definition: mkdosfs.c:366
static void add_block_group_items(LIST_ENTRY *chunks, btrfs_root *extent_root)
Definition: btrfslib.c:1090
#define NtGetTickCount
Definition: rtlp.h:146
#define BTRFS_ROOT_DATA_RELOC
Definition: btrfs.h:56
static int dev
Definition: mkdosfs.c:536
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
static btrfs_chunk * add_chunk(LIST_ENTRY *chunks, UINT64 flags, btrfs_root *chunk_root, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid, UINT32 sector_size)
Definition: btrfslib.c:426
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
unsigned int BOOL
Definition: ntddk_ex.h:94
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:105
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:71
static void assign_addresses(LIST_ENTRY *roots, btrfs_chunk *sys_chunk, btrfs_chunk *metadata_chunk, UINT32 node_size, btrfs_root *root_root, btrfs_root *extent_root, BOOL skinny)
Definition: btrfslib.c:549
#define BTRFS_ROOT_ROOT
Definition: btrfs.h:48
GLsizeiptr size
Definition: glext.h:5919
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead)
Definition: btrfslib.c:99
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BLOCK_FLAG_METADATA
Definition: shellext.h:72
#define BTRFS_ROOT_FSTREE
Definition: btrfs.h:52
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 node_size, BTRFS_UUID *fsuuid, UINT32 sector_size, PUNICODE_STRING label, UINT64 incompat_flags)
Definition: btrfslib.c:878
Definition: typedefs.h:117
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:308
#define BTRFS_ROOT_CHECKSUM
Definition: btrfs.h:53
uint64_t dev_id
#define BLOCK_FLAG_DATA
Definition: shellext.h:70
static NTSTATUS write_roots(HANDLE h, LIST_ENTRY *roots, UINT32 node_size, BTRFS_UUID *fsuuid, BTRFS_UUID *chunkuuid)
Definition: btrfslib.c:642
#define BTRFS_ROOT_DEVTREE
Definition: btrfs.h:51
static NTSTATUS clear_first_megabyte(HANDLE h)
Definition: btrfslib.c:1107
unsigned int ULONG
Definition: retypes.h:1
static void free_chunks(LIST_ENTRY *chunks)
Definition: btrfslib.c:345
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:50
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:75
static btrfs_root * add_root(LIST_ENTRY *roots, UINT64 id)
Definition: btrfslib.c:289
#define BTRFS_ROOT_EXTENT
Definition: btrfs.h:49
unsigned long long UINT64
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:723
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by FormatEx2().

◆ write_data()

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

Definition at line 622 of file btrfslib.c.

622  {
624  UINT16 i;
627  CHUNK_ITEM_STRIPE* cis;
628 
629  cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
630 
631  for (i = 0; i < c->chunk_item->num_stripes; i++) {
632  off.QuadPart = cis[i].offset + address - c->offset;
633 
635  if (!NT_SUCCESS(Status))
636  return Status;
637  }
638 
639  return STATUS_SUCCESS;
640 }
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)
UINT64 offset
Definition: btrfs.h:326
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
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
unsigned short UINT16
return STATUS_SUCCESS
Definition: btrfs.c:2725
off
Definition: i386-dis.c:3909

Referenced by write_roots().

◆ write_roots()

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

Definition at line 642 of file btrfslib.c.

642  {
643  LIST_ENTRY *le, *le2;
645  UINT8* tree;
646 
647 #ifndef __REACTOS__
648  tree = malloc(node_size);
649 #else
650  tree = RtlAllocateHeap(RtlGetProcessHeap(), 0, node_size);
651 #endif
652 
653  le = roots->Flink;
654  while (le != roots) {
656  UINT8* dp;
657  leaf_node* ln;
658  UINT32 crc32;
659 
660  memset(tree, 0, node_size);
661 
662  r->header.num_items = 0;
663  r->header.fs_uuid = *fsuuid;
665  r->header.chunk_tree_uuid = *chunkuuid;
666  r->header.generation = 1;
667  r->header.tree_id = r->id;
668 
669  ln = (leaf_node*)(tree + sizeof(tree_header));
670 
671  dp = tree + node_size;
672 
673  le2 = r->items.Flink;
674  while (le2 != &r->items) {
676 
677  ln->key = item->key;
678  ln->size = item->size;
679 
680  if (item->size > 0) {
681  dp -= item->size;
682  memcpy(dp, item->data, item->size);
683 
684  ln->offset = dp - tree - sizeof(tree_header);
685  } else
686  ln->offset = 0;
687 
688  ln = &ln[1];
689 
690  r->header.num_items++;
691 
692  le2 = le2->Flink;
693  }
694 
695  memcpy(tree, &r->header, sizeof(tree_header));
696 
697  crc32 = ~calc_crc32c(0xffffffff, (UINT8*)&((tree_header*)tree)->fs_uuid, node_size - sizeof(((tree_header*)tree)->csum));
698  memcpy(tree, &crc32, sizeof(UINT32));
699 
700  Status = write_data(h, r->header.address, r->c, tree, node_size);
701  if (!NT_SUCCESS(Status)) {
702 #ifndef __REACTOS__
703  free(tree);
704 #else
705  RtlFreeHeap(RtlGetProcessHeap(), 0, tree);
706 #endif
707  return Status;
708  }
709 
710  le = le->Flink;
711  }
712 
713 #ifndef __REACTOS__
714  free(tree);
715 #else
716  RtlFreeHeap(RtlGetProcessHeap(), 0, tree);
717 #endif
718 
719  return STATUS_SUCCESS;
720 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
struct _tree tree
static NTSTATUS write_data(HANDLE h, UINT64 address, btrfs_chunk *c, void *data, ULONG size)
Definition: btrfslib.c:622
#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:603
static UINT32 calc_crc32c(UINT32 seed, UINT8 *msg, ULONG msglen)
Definition: btrfslib.c:256
UINT32 crc32
Definition: btrfs.c:3877
UINT32 offset
Definition: btrfs.h:146
#define HEADER_FLAG_MIXED_BACKREF
Definition: btrfs.h:130
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
unsigned int UINT32
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:585
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
tree_header header
Definition: btrfs_drv.h:396
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
static ATOM item
Definition: dde.c:856
KEY key
Definition: btrfs.h:145
Definition: list.h:27
Definition: fs.h:216
#define HEADER_FLAG_WRITTEN
Definition: btrfs.h:128
#define malloc
Definition: debug_ros.c:4
return STATUS_SUCCESS
Definition: btrfs.c:2725
UINT32 size
Definition: btrfs.h:147
unsigned char UINT8
#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  node_size,
BTRFS_UUID fsuuid,
UINT32  sector_size,
PUNICODE_STRING  label,
UINT64  incompat_flags 
)
static

Definition at line 878 of file btrfslib.c.

879  {
882  ULONG sblen;
883  int i;
884  UINT32 crc32;
885  superblock* sb;
886  KEY* key;
887  UINT64 bytes_used;
888  LIST_ENTRY* le;
889 
890  sblen = sizeof(sb);
891  if (sblen & (sector_size - 1))
892  sblen = (sblen & sector_size) + sector_size;
893 
894  bytes_used = 0;
895 
896  le = extent_root->items.Flink;
897  while (le != &extent_root->items) {
899 
900  if (item->key.obj_type == TYPE_EXTENT_ITEM)
901  bytes_used += item->key.offset;
902  else if (item->key.obj_type == TYPE_METADATA_ITEM)
903  bytes_used += node_size;
904 
905  le = le->Flink;
906  }
907 
908 #ifndef __REACTOS__
909  sb = malloc(sblen);
910  memset(sb, 0, sblen);
911 #else
912  sb = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sblen);
913 #endif
914 
915  sb->uuid = *fsuuid;
916  sb->flags = 1;
917  sb->magic = BTRFS_MAGIC;
918  sb->generation = 1;
919  sb->root_tree_addr = root_root->header.address;
920  sb->chunk_tree_addr = chunk_root->header.address;
921  sb->total_bytes = dev->dev_item.num_bytes;
922  sb->bytes_used = bytes_used;
923  sb->root_dir_objectid = 6;
924  sb->num_devices = 1;
926  sb->node_size = node_size;
927  sb->leaf_size = node_size;
929  sb->n = sizeof(KEY) + sizeof(CHUNK_ITEM) + (sys_chunk->chunk_item->num_stripes * sizeof(CHUNK_ITEM_STRIPE));
931  sb->incompat_flags = incompat_flags;
932  memcpy(&sb->dev_item, &dev->dev_item, sizeof(DEV_ITEM));
933 
934  if (label->Length > 0) {
935  int i;
936  ULONG utf8len;
937 
938  for (i = 0; i < label->Length / sizeof(WCHAR); i++) {
939  if (label->Buffer[i] == '/' || label->Buffer[i] == '\\') {
940 #ifndef __REACTOS__
941  free(sb);
942 #else
943  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
944 #endif
946  }
947  }
948 
949  Status = RtlUnicodeToUTF8N(NULL, 0, &utf8len, label->Buffer, label->Length);
950  if (!NT_SUCCESS(Status)) {
951 #ifndef __REACTOS__
952  free(sb);
953 #else
954  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
955 #endif
956  return Status;
957  }
958 
959  if (utf8len > MAX_LABEL_SIZE) {
960 #ifndef __REACTOS__
961  free(sb);
962 #else
963  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
964 #endif
966  }
967 
968  Status = RtlUnicodeToUTF8N((PCHAR)&sb->label, MAX_LABEL_SIZE, &utf8len, label->Buffer, label->Length);
969  if (!NT_SUCCESS(Status)) {
970 #ifndef __REACTOS__
971  free(sb);
972 #else
973  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
974 #endif
975  return Status;
976  }
977  }
978  sb->cache_generation = 0xffffffffffffffff;
979 
980  key = (KEY*)sb->sys_chunk_array;
981  key->obj_id = 0x100;
982  key->obj_type = TYPE_CHUNK_ITEM;
983  key->offset = sys_chunk->offset;
984  memcpy(&key[1], sys_chunk->chunk_item, sizeof(CHUNK_ITEM) + (sys_chunk->chunk_item->num_stripes * sizeof(CHUNK_ITEM_STRIPE)));
985 
986  i = 0;
987  while (superblock_addrs[i] != 0) {
989 
990  if (superblock_addrs[i] > dev->dev_item.num_bytes)
991  break;
992 
994 
995  crc32 = ~calc_crc32c(0xffffffff, (UINT8*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
996  memcpy(&sb->checksum, &crc32, sizeof(UINT32));
997 
998  off.QuadPart = superblock_addrs[i];
999 
1000  Status = NtWriteFile(h, NULL, NULL, NULL, &iosb, sb, sblen, &off, NULL);
1001  if (!NT_SUCCESS(Status)) {
1002 #ifndef __REACTOS__
1003  free(sb);
1004 #else
1005  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1006 #endif
1007  return Status;
1008  }
1009 
1010  i++;
1011  }
1012 
1013 #ifndef __REACTOS__
1014  free(sb);
1015 #else
1016  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1017 #endif
1018 
1019  return STATUS_SUCCESS;
1020 }
signed char * PCHAR
Definition: retypes.h:7
UINT64 total_bytes
Definition: btrfs.h:213
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToUTF8N(PCHAR UTF8StringDestination, ULONG UTF8StringMaxByteCount, PULONG UTF8StringActualByteCount, PCWCH UnicodeStringSource, ULONG UnicodeStringByteCount)
UINT64 chunk_tree_addr
Definition: btrfs.h:210
UINT32 n
Definition: btrfs.h:221
char label[MAX_LABEL_SIZE]
Definition: btrfs.h:231
superblock * sb
Definition: btrfs.c:3876
UINT64 num_devices
Definition: btrfs.h:216
#define free
Definition: debug_ros.c:5
#define TYPE_CHUNK_ITEM
Definition: btrfs.h:42
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
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)
static UINT32 calc_crc32c(UINT32 seed, UINT8 *msg, ULONG msglen)
Definition: btrfslib.c:256
UINT32 crc32
Definition: btrfs.c:3877
#define STATUS_INVALID_VOLUME_LABEL
Definition: udferr_usr.h:156
#define TYPE_METADATA_ITEM
Definition: btrfs.h:30
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
unsigned int UINT32
UINT64 bytes_used
Definition: btrfs.h:214
smooth NULL
Definition: ftsmooth.c:416
#define TYPE_EXTENT_ITEM
Definition: btrfs.h:29
UINT32 sector_size
Definition: btrfs.h:217
UINT64 address
Definition: btrfs.h:135
DEV_ITEM dev_item
Definition: btrfs.h:230
UINT64 cache_generation
Definition: btrfs.h:232
tree_header header
Definition: btrfslib.c:141
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:585
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UINT64 superblock_addrs[]
Definition: btrfs.h:12
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UINT64 incompat_flags
Definition: btrfs.h:225
UINT8 sys_chunk_array[SYS_CHUNK_ARRAY_SIZE]
Definition: btrfs.h:235
UINT64 chunk_root_generation
Definition: btrfs.h:222
HKEY key
Definition: reg.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
UINT32 node_size
Definition: btrfs.h:218
Definition: typedefs.h:117
UINT8 checksum[32]
Definition: btrfs.h:203
UINT32 stripe_size
Definition: btrfs.h:220
uint8_t label[11]
Definition: fsck.fat.h:65
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
UINT64 root_tree_addr
Definition: btrfs.h:209
Definition: btrfs.h:122
#define MAX_LABEL_SIZE
Definition: btrfs.h:15
static ATOM item
Definition: dde.c:856
#define KEY
Definition: profile.c:30
BTRFS_UUID uuid
Definition: btrfs.h:204
UINT64 generation
Definition: btrfs.h:208
Definition: list.h:27
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LIST_ENTRY items
Definition: btrfslib.c:143
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
unsigned long long UINT64
UINT64 flags
Definition: btrfs.h:206
return STATUS_SUCCESS
Definition: btrfs.c:2725
UINT64 magic
Definition: btrfs.h:207
unsigned char UINT8
#define memset(x, y, z)
Definition: compat.h:39
UINT64 root_dir_objectid
Definition: btrfs.h:215
UINT64 sb_phys_addr
Definition: btrfs.h:205
UINT32 leaf_size
Definition: btrfs.h:219
Definition: path.c:42
#define BTRFS_MAGIC
Definition: btrfs.h:42
off
Definition: i386-dis.c:3909

Referenced by write_btrfs().

Variable Documentation

◆ crctable

const UINT32 crctable[]
static

Definition at line 221 of file btrfslib.c.

Referenced by calc_crc32c().

◆ def_incompat_flags

Definition at line 163 of file btrfslib.c.

Referenced by FormatEx2(), and SetIncompatFlags().

◆ def_node_size

ULONG def_node_size = 0

Definition at line 162 of file btrfslib.c.

Referenced by FormatEx2(), and SetSizes().

◆ def_sector_size

ULONG def_sector_size = 0

Definition at line 162 of file btrfslib.c.

Referenced by FormatEx2(), and SetSizes().

◆ module

Definition at line 161 of file btrfslib.c.