ReactOS  0.4.14-dev-1296-g56aa513
btrfslib.c File Reference
#include <stdlib.h>
#include <stddef.h>
#include <time.h>
#include <ntstatus.h>
#include <windef.h>
#include <winbase.h>
#include <winternl.h>
#include <devioctl.h>
#include <ntdddisk.h>
#include <ntddscsi.h>
#include <ntddstor.h>
#include <ata.h>
#include <mountmgr.h>
#include <stringapiset.h>
#include "../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)
 
FORCEINLINE VOID InitializeListHead (PLIST_ENTRY ListHead)
 
FORCEINLINE VOID InsertTailList (PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
 
static uint32_t calc_crc32c (uint32_t seed, uint8_t *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_t id)
 
static void free_roots (LIST_ENTRY *roots)
 
static void free_chunks (LIST_ENTRY *chunks)
 
static void add_item (btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
 
static uint64_t find_chunk_offset (uint64_t size, uint64_t offset, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid)
 
static btrfs_chunkadd_chunk (LIST_ENTRY *chunks, uint64_t flags, btrfs_root *chunk_root, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid, uint32_t sector_size)
 
static BOOL superblock_collision (btrfs_chunk *c, uint64_t address)
 
static uint64_t get_next_address (btrfs_chunk *c)
 
static void assign_addresses (LIST_ENTRY *roots, btrfs_chunk *sys_chunk, btrfs_chunk *metadata_chunk, uint32_t node_size, btrfs_root *root_root, btrfs_root *extent_root, BOOL skinny)
 
static NTSTATUS write_data (HANDLE h, uint64_t address, btrfs_chunk *c, void *data, ULONG size)
 
static NTSTATUS write_roots (HANDLE h, LIST_ENTRY *roots, uint32_t node_size, BTRFS_UUID *fsuuid, BTRFS_UUID *chunkuuid)
 
static void get_uuid (BTRFS_UUID *uuid)
 
static void init_device (btrfs_dev *dev, uint64_t id, uint64_t size, BTRFS_UUID *fsuuid, uint32_t sector_size)
 
static NTSTATUS write_superblocks (HANDLE h, btrfs_dev *dev, btrfs_root *chunk_root, btrfs_root *root_root, btrfs_root *extent_root, btrfs_chunk *sys_chunk, uint32_t node_size, BTRFS_UUID *fsuuid, uint32_t sector_size, PUNICODE_STRING label, uint64_t incompat_flags)
 
static __inline void win_time_to_unix (LARGE_INTEGER t, BTRFS_TIME *out)
 
static void add_inode_ref (btrfs_root *r, uint64_t inode, uint64_t parent, uint64_t index, const char *name)
 
static void init_fs_tree (btrfs_root *r, uint32_t node_size)
 
static void add_block_group_items (LIST_ENTRY *chunks, btrfs_root *extent_root)
 
static NTSTATUS clear_first_megabyte (HANDLE h)
 
static BOOL is_ssd (HANDLE h)
 
static void add_dir_item (btrfs_root *root, uint64_t inode, uint32_t hash, uint64_t key_objid, uint8_t key_type, uint64_t key_offset, uint64_t transid, uint8_t type, const char *name)
 
static void set_default_subvol (btrfs_root *root_root, uint32_t node_size)
 
static NTSTATUS write_btrfs (HANDLE h, uint64_t size, PUNICODE_STRING label, uint32_t sector_size, uint32_t node_size, uint64_t incompat_flags)
 
static BOOL look_for_device (btrfs_filesystem *bfs, BTRFS_UUID *devuuid)
 
static BOOL is_mounted_multi_device (HANDLE h, uint32_t sector_size)
 
static void do_full_trim (HANDLE h)
 
static BOOL is_power_of_two (ULONG i)
 
static NTSTATUS NTAPI FormatEx2 (PUNICODE_STRING DriveRoot, FMIFS_MEDIA_FLAG MediaFlag, PUNICODE_STRING Label, BOOLEAN QuickFormat, ULONG ClusterSize, PFMIFSCALLBACK Callback)
 
BOOL __stdcall FormatEx (DSTRING *root, STREAM_MESSAGE *message, options *opts, uint32_t unk1)
 
void __stdcall SetSizes (ULONG sector, ULONG node)
 
void __stdcall SetIncompatFlags (uint64_t incompat_flags)
 
BOOL __stdcall GetFilesystemInformation (uint32_t unk1, uint32_t unk2, void *unk3)
 
BOOL APIENTRY DllMain (HANDLE hModule, DWORD dwReason, void *lpReserved)
 

Variables

HMODULE module
 
ULONG def_sector_size = 0
 
ULONG def_node_size = 0
 
uint64_t def_incompat_flags = BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
 
static const uint32_t crctable []
 

Macro Definition Documentation

◆ DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED

#define DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED   0x80000000

Definition at line 54 of file btrfslib.c.

◆ FORMAT_FLAG_DISMOUNT_FIRST

#define FORMAT_FLAG_DISMOUNT_FIRST   0x00000004

Definition at line 85 of file btrfslib.c.

◆ FORMAT_FLAG_INTEGRITY_DISABLE

#define FORMAT_FLAG_INTEGRITY_DISABLE   0x00000100

Definition at line 88 of file btrfslib.c.

◆ FORMAT_FLAG_LARGE_RECORDS

#define FORMAT_FLAG_LARGE_RECORDS   0x00000100

Definition at line 87 of file btrfslib.c.

◆ FORMAT_FLAG_QUICK_FORMAT

#define FORMAT_FLAG_QUICK_FORMAT   0x00000001

Definition at line 83 of file btrfslib.c.

◆ FORMAT_FLAG_UNKNOWN1

#define FORMAT_FLAG_UNKNOWN1   0x00000002

Definition at line 84 of file btrfslib.c.

◆ FORMAT_FLAG_UNKNOWN2

#define FORMAT_FLAG_UNKNOWN2   0x00000040

Definition at line 86 of file btrfslib.c.

◆ FSCTL_DISMOUNT_VOLUME

Definition at line 51 of file btrfslib.c.

◆ FSCTL_LOCK_VOLUME

Definition at line 49 of file btrfslib.c.

◆ FSCTL_UNLOCK_VOLUME

Definition at line 50 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 145 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 212 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 192 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 165 of file btrfslib.c.

165  {
174  FMIFS_FLOPPY,
FMIFS_MEDIA_FLAG
Definition: btrfslib.c:165

Function Documentation

◆ add_block_group_items()

static void add_block_group_items ( LIST_ENTRY chunks,
btrfs_root extent_root 
)
static

Definition at line 977 of file btrfslib.c.

977  {
978  LIST_ENTRY* le;
979 
980  le = chunks->Flink;
981  while (le != chunks) {
983  BLOCK_GROUP_ITEM bgi;
984 
985  bgi.used = c->used;
986  bgi.chunk_tree = 0x100;
987  bgi.flags = c->chunk_item->type;
988  add_item(extent_root, c->offset, TYPE_BLOCK_GROUP_ITEM, c->chunk_item->size, &bgi, sizeof(BLOCK_GROUP_ITEM));
989 
990  le = le->Flink;
991  }
992 }
uint64_t flags
Definition: btrfs.h:404
uint64_t used
Definition: btrfs.h:402
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
const GLubyte * c
Definition: glext.h:8905
#define TYPE_BLOCK_GROUP_ITEM
Definition: btrfs.h:38
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
Definition: typedefs.h:118
uint64_t chunk_tree
Definition: btrfs.h:403
Definition: list.h:27

Referenced by write_btrfs().

◆ add_chunk()

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

Definition at line 419 of file btrfslib.c.

419  {
420  uint64_t off, size;
421  uint16_t stripes, i;
422  btrfs_chunk* c;
423  LIST_ENTRY* le;
424  CHUNK_ITEM_STRIPE* cis;
425 
426  off = 0xc00000;
427  le = chunks->Flink;
428  while (le != chunks) {
430 
431  if (c->offset + c->chunk_item->size > off)
432  off = c->offset + c->chunk_item->size;
433 
434  le = le->Flink;
435  }
436 
437  if (flags & BLOCK_FLAG_METADATA) {
438  if (dev->dev_item.num_bytes > 0xC80000000) // 50 GB
439  size = 0x40000000; // 1 GB
440  else
441  size = 0x10000000; // 256 MB
442  } else if (flags & BLOCK_FLAG_SYSTEM)
443  size = 0x800000;
444 
445  size = min(size, dev->dev_item.num_bytes / 10); // cap at 10%
446  size &= ~(sector_size - 1);
447 
448  stripes = flags & BLOCK_FLAG_DUPLICATE ? 2 : 1;
449 
450  if (dev->dev_item.num_bytes - dev->dev_item.bytes_used < stripes * size) // not enough space
451  return NULL;
452 
453 #ifndef __REACTOS__
454  c = malloc(sizeof(btrfs_chunk));
455 #else
456  c = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(btrfs_chunk));
457 #endif
458  c->offset = off;
459  c->lastoff = off;
460  c->used = 0;
461 
462 #ifndef __REACTOS__
463  c->chunk_item = malloc(sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
464 #else
465  c->chunk_item = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
466 #endif
467 
468  c->chunk_item->size = size;
469  c->chunk_item->root_id = BTRFS_ROOT_EXTENT;
470  c->chunk_item->stripe_length = max(sector_size, 0x10000);
471  c->chunk_item->type = flags;
472  c->chunk_item->opt_io_alignment = max(sector_size, 0x10000);
473  c->chunk_item->opt_io_width = max(sector_size, 0x10000);
474  c->chunk_item->sector_size = sector_size;
475  c->chunk_item->num_stripes = stripes;
476  c->chunk_item->sub_stripes = 0;
477 
478  cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
479 
480  for (i = 0; i < stripes; i++) {
481  cis[i].dev_id = dev->dev_item.dev_id;
482  cis[i].offset = find_chunk_offset(size, c->offset, dev, dev_root, chunkuuid);
483  cis[i].dev_uuid = dev->dev_item.device_uuid;
484  }
485 
486  add_item(chunk_root, 0x100, TYPE_CHUNK_ITEM, c->offset, c->chunk_item, sizeof(CHUNK_ITEM) + (stripes * sizeof(CHUNK_ITEM_STRIPE)));
487 
488  InsertTailList(chunks, &c->list_entry);
489 
490  return c;
491 }
#define max(a, b)
Definition: svc.c:63
static uint64_t find_chunk_offset(uint64_t size, uint64_t offset, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid)
Definition: btrfslib.c:399
uint64_t dev_id
Definition: btrfs.h:330
#define TYPE_CHUNK_ITEM
Definition: btrfs.h:44
unsigned short int uint16_t
Definition: acefiex.h:54
uint64_t offset
Definition: btrfs.h:331
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:102
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:76
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
#define for
Definition: utility.h:88
BTRFS_UUID dev_uuid
Definition: btrfs.h:332
GLbitfield flags
Definition: glext.h:7161
#define BLOCK_FLAG_METADATA
Definition: shellext.h:77
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
Definition: typedefs.h:118
__u8 sector_size[2]
Definition: mkdosfs.c:361
UINT64 uint64_t
Definition: types.h:77
#define min(a, b)
Definition: monoChain.cc:55
Definition: list.h:27
uint64_t dev_id
#define c
Definition: ke_i.h:80
#define malloc
Definition: debug_ros.c:4
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:80
#define BTRFS_ROOT_EXTENT
Definition: btrfs.h:51
off
Definition: i386-dis.c:3909

Referenced by write_btrfs().

◆ add_dir_item()

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

Definition at line 1067 of file btrfslib.c.

1068  {
1069  uint16_t name_len = (uint16_t)strlen(name);
1070 #ifndef __REACTOS__
1071  DIR_ITEM* di = malloc(offsetof(DIR_ITEM, name[0]) + name_len);
1072 #else
1073  DIR_ITEM* di = RtlAllocateHeap(RtlGetProcessHeap(), 0, offsetof(DIR_ITEM, name[0]) + name_len);
1074 #endif
1075 
1076  di->key.obj_id = key_objid;
1077  di->key.obj_type = key_type;
1078  di->key.offset = key_offset;
1079  di->transid = transid;
1080  di->m = 0;
1081  di->n = name_len;
1082  di->type = type;
1083  memcpy(di->name, name, name_len);
1084 
1085  add_item(root, inode, TYPE_DIR_ITEM, hash, di, (uint16_t)(offsetof(DIR_ITEM, name[0]) + di->m + di->n));
1086 
1087 #ifndef __REACTOS__
1088  free(di);
1089 #else
1090  RtlFreeHeap(RtlGetProcessHeap(), 0, di);
1091 #endif
1092 }
uint64_t obj_id
Definition: btrfs.h:128
uint8_t obj_type
Definition: btrfs.h:129
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
unsigned short int uint16_t
Definition: acefiex.h:54
#define uint16_t
Definition: nsiface.idl:60
uint64_t offset
Definition: btrfs.h:130
Definition: fs.h:78
uint16_t m
Definition: btrfs.h:258
KEY key
Definition: btrfs.h:256
char name[1]
Definition: btrfs.h:261
#define offsetof(TYPE, MEMBER)
uint8_t type
Definition: btrfs.h:260
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
#define TYPE_DIR_ITEM
Definition: btrfs.h:24
Definition: name.c:38
#define malloc
Definition: debug_ros.c:4
uint64_t transid
Definition: btrfs.h:257
uint16_t n
Definition: btrfs.h:259
Definition: _hash_fun.h:40

Referenced by set_default_subvol().

◆ add_inode_ref()

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

Definition at line 932 of file btrfslib.c.

932  {
933  uint16_t name_len = (uint16_t)strlen(name);
934 #ifndef __REACTOS__
935  INODE_REF* ir = malloc(offsetof(INODE_REF, name[0]) + name_len);
936 #else
937  INODE_REF* ir = RtlAllocateHeap(RtlGetProcessHeap(), 0, offsetof(INODE_REF, name[0]) + name_len);
938 #endif
939 
940  ir->index = 0;
941  ir->n = name_len;
942  memcpy(ir->name, name, name_len);
943 
945 
946 #ifndef __REACTOS__
947  free(ir);
948 #else
949  RtlFreeHeap(RtlGetProcessHeap(), 0, ir);
950 #endif
951 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
unsigned short int uint16_t
Definition: acefiex.h:54
#define uint16_t
Definition: nsiface.idl:60
Definition: fs.h:78
char name[1]
Definition: btrfs.h:355
#define offsetof(TYPE, MEMBER)
#define TYPE_INODE_REF
Definition: btrfs.h:20
uint16_t n
Definition: btrfs.h:354
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
r parent
Definition: btrfs.c:2869
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
uint64_t index
Definition: btrfs.h:353
Definition: name.c:38
#define malloc
Definition: debug_ros.c:4

Referenced by init_fs_tree(), and set_default_subvol().

◆ add_item()

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

Definition at line 358 of file btrfslib.c.

358  {
359  LIST_ENTRY* le;
360  btrfs_item* item;
361 
362 #ifndef __REACTOS__
363  item = malloc(sizeof(btrfs_item));
364 #else
365  item = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(btrfs_item));
366 #endif
367 
368  item->key.obj_id = obj_id;
369  item->key.obj_type = obj_type;
370  item->key.offset = offset;
371  item->size = size;
372 
373  if (size == 0)
374  item->data = NULL;
375  else {
376 #ifndef __REACTOS__
377  item->data = malloc(size);
378 #else
379  item->data = RtlAllocateHeap(RtlGetProcessHeap(), 0, size);
380 #endif
381  memcpy(item->data, data, size);
382  }
383 
384  le = r->items.Flink;
385  while (le != &r->items) {
387 
388  if (keycmp(item->key, i2->key) != 1) {
389  InsertTailList(le, &item->list_entry);
390  return;
391  }
392 
393  le = le->Flink;
394  }
395 
396  InsertTailList(&r->items, &item->list_entry);
397 }
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:102
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:145
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
GLsizeiptr size
Definition: glext.h:5919
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: typedefs.h:118
static ATOM item
Definition: dde.c:856
Definition: list.h:27
#define malloc
Definition: debug_ros.c:4

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

◆ add_root()

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

Definition at line 282 of file btrfslib.c.

282  {
283  btrfs_root* root;
284 
285 #ifdef __REACTOS__
286  root = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(btrfs_root));
287 #else
288  root = malloc(sizeof(btrfs_root));
289 #endif
290 
291  root->id = id;
292 #ifndef __REACTOS__
293  RtlZeroMemory(&root->header, sizeof(tree_header));
294 #endif
295  InitializeListHead(&root->items);
296  InsertTailList(roots, &root->list_entry);
297 
298  return root;
299 }
LIST_ENTRY list_entry
Definition: btrfs_drv.h:466
struct _root root
uint64_t id
Definition: btrfs_drv.h:452
FORCEINLINE VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
Definition: btrfslib.c:102
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead)
Definition: btrfslib.c:98
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
GLenum GLuint id
Definition: glext.h:5579
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define malloc
Definition: debug_ros.c:4

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

◆ assign_addresses()

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

Definition at line 542 of file btrfslib.c.

543  {
544  LIST_ENTRY* le;
545 
546  le = roots->Flink;
547  while (le != roots) {
549  btrfs_chunk* c = r->id == BTRFS_ROOT_CHUNK ? sys_chunk : metadata_chunk;
550 
551  r->header.address = get_next_address(c);
552  r->c = c;
553  c->lastoff = r->header.address + node_size;
554  c->used += node_size;
555 
556  if (skinny) {
558 
559  eim.ei.refcount = 1;
560  eim.ei.generation = 1;
563  eim.tbr.offset = r->id;
564 
565  add_item(extent_root, r->header.address, TYPE_METADATA_ITEM, 0, &eim, sizeof(EXTENT_ITEM_METADATA));
566  } else {
568  KEY firstitem;
569 
570  if (r->items.Flink == &r->items) {
571  firstitem.obj_id = 0;
572  firstitem.obj_type = 0;
573  firstitem.offset = 0;
574  } else {
575  btrfs_item* bi = CONTAINING_RECORD(r->items.Flink, btrfs_item, list_entry);
576 
577  firstitem = bi->key;
578  }
579 
580  eim2.ei.refcount = 1;
581  eim2.ei.generation = 1;
583  eim2.ei2.firstitem = firstitem;
584  eim2.ei2.level = 0;
585  eim2.type = TYPE_TREE_BLOCK_REF;
586  eim2.tbr.offset = r->id;
587 
588  add_item(extent_root, r->header.address, TYPE_EXTENT_ITEM, node_size, &eim2, sizeof(EXTENT_ITEM_METADATA2));
589  }
590 
591  if (r->id != BTRFS_ROOT_ROOT && r->id != BTRFS_ROOT_CHUNK) {
592  ROOT_ITEM ri;
593 
594  memset(&ri, 0, sizeof(ROOT_ITEM));
595 
596  ri.inode.generation = 1;
597  ri.inode.st_size = 3;
598  ri.inode.st_blocks = node_size;
599  ri.inode.st_nlink = 1;
600  ri.inode.st_mode = 040755;
601  ri.generation = 1;
602  ri.objid = r->id == 5 || r->id >= 0x100 ? SUBVOL_ROOT_INODE : 0;
603  ri.block_number = r->header.address;
604  ri.bytes_used = node_size;
605  ri.num_references = 1;
606  ri.generation2 = ri.generation;
607 
608  add_item(root_root, r->id, TYPE_ROOT_ITEM, 0, &ri, sizeof(ROOT_ITEM));
609  }
610 
611  le = le->Flink;
612  }
613 }
uint64_t obj_id
Definition: btrfs.h:128
uint8_t obj_type
Definition: btrfs.h:129
EXTENT_ITEM2 ei2
Definition: btrfslib.c:537
uint64_t bytes_used
Definition: btrfs.h:295
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define SUBVOL_ROOT_INODE
Definition: propsheet.cpp:42
#define TYPE_TREE_BLOCK_REF
Definition: btrfs.h:33
uint64_t block_number
Definition: btrfs.h:293
EXTENT_ITEM ei
Definition: btrfslib.c:536
TREE_BLOCK_REF tbr
Definition: btrfslib.c:539
#define TYPE_METADATA_ITEM
Definition: btrfs.h:32
uint64_t offset
Definition: btrfs.h:130
uint64_t generation2
Definition: btrfs.h:302
uint64_t refcount
Definition: btrfs.h:370
uint64_t generation
Definition: btrfs.h:291
uint32_t st_nlink
Definition: btrfs.h:275
uint32_t num_references
Definition: btrfs.h:298
#define TYPE_EXTENT_ITEM
Definition: btrfs.h:31
struct btrfs_disk_key key
Definition: btrfs.h:110
uint64_t offset
Definition: btrfs.h:391
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static uint64_t get_next_address(btrfs_chunk *c)
Definition: btrfslib.c:514
#define BTRFS_ROOT_ROOT
Definition: btrfs.h:50
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
uint64_t st_size
Definition: btrfs.h:272
uint64_t objid
Definition: btrfs.h:292
const GLubyte * c
Definition: glext.h:8905
KEY firstitem
Definition: btrfs.h:376
TREE_BLOCK_REF tbr
Definition: btrfslib.c:532
EXTENT_ITEM ei
Definition: btrfslib.c:530
uint8_t level
Definition: btrfs.h:377
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
Definition: typedefs.h:118
uint64_t generation
Definition: btrfs.h:270
uint64_t st_blocks
Definition: btrfs.h:273
uint64_t generation
Definition: btrfs.h:371
Definition: btrfs.h:127
INODE_ITEM inode
Definition: btrfs.h:290
#define EXTENT_ITEM_TREE_BLOCK
Definition: btrfs.h:366
#define TYPE_ROOT_ITEM
Definition: btrfs.h:28
Definition: list.h:27
#define c
Definition: ke_i.h:80
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:52
uint64_t flags
Definition: btrfs.h:372
#define memset(x, y, z)
Definition: compat.h:39
uint32_t st_mode
Definition: btrfs.h:278

Referenced by write_btrfs().

◆ calc_crc32c()

static uint32_t calc_crc32c ( uint32_t  seed,
uint8_t msg,
ULONG  msglen 
)
static

Definition at line 249 of file btrfslib.c.

249  {
250  uint32_t rem;
251  ULONG i;
252 
253  rem = seed;
254 
255  for (i = 0; i < msglen; i++) {
256  rem = crctable[(rem ^ msg[i]) & 0xff] ^ (rem >> 8);
257  }
258 
259  return rem;
260 }
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
static const uint32_t crctable[]
Definition: btrfslib.c:214
UINT32 uint32_t
Definition: types.h:75
#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 263 of file btrfslib.c.

267  {
268  // STUB
269 
270  if (Callback) {
272 
273  TextOut.Lines = 1;
274  TextOut.Output = "stub, not implemented";
275 
276  Callback(OUTPUT, 0, &TextOut);
277  }
278 
279  return STATUS_SUCCESS;
280 }
#define TextOut
Definition: wingdi.h:4482
return STATUS_SUCCESS
Definition: btrfs.c:2938
LPFNPSPCALLBACK Callback
Definition: desk.c:112

◆ clear_first_megabyte()

static NTSTATUS clear_first_megabyte ( HANDLE  h)
static

Definition at line 994 of file btrfslib.c.

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

Referenced by write_btrfs().

◆ DllMain()

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

Definition at line 1600 of file btrfslib.c.

1600  {
1602  module = (HMODULE)hModule;
1603 
1604  return TRUE;
1605 }
#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:76
HMODULE hModule
Definition: animate.c:44

◆ do_full_trim()

static void do_full_trim ( HANDLE  h)
static

Definition at line 1362 of file btrfslib.c.

1362  {
1365 
1367 
1368  dmdsa.Size = sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES);
1369  dmdsa.Action = DeviceDsmAction_Trim;
1371  dmdsa.ParameterBlockOffset = 0;
1372  dmdsa.ParameterBlockLength = 0;
1373  dmdsa.DataSetRangesOffset = 0;
1374  dmdsa.DataSetRangesLength = 0;
1375 
1377 }
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:54
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DEVICE_DATA_MANAGEMENT_SET_ACTION Action
Definition: ntddstor.h:578
#define DeviceDsmAction_Trim
Definition: ntddstor.h:211
smooth NULL
Definition: ftsmooth.c:416
#define IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES
Definition: ntddstor.h:170
#define DEVICE_DSM_FLAG_ENTIRE_DATA_SET_RANGE
Definition: ntddstor.h:214
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by FormatEx2().

◆ find_chunk_offset()

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

Definition at line 399 of file btrfslib.c.

399  {
400  uint64_t off;
401  DEV_EXTENT de;
402 
403  off = dev->last_alloc;
404  dev->last_alloc += size;
405 
406  dev->dev_item.bytes_used += size;
407 
409  de.objid = 0x100;
410  de.address = offset;
411  de.length = size;
412  de.chunktree_uuid = *chunkuuid;
413 
414  add_item(dev_root, dev->dev_item.dev_id, TYPE_DEV_EXTENT, off, &de, sizeof(DEV_EXTENT));
415 
416  return off;
417 }
GLintptr offset
Definition: glext.h:5920
uint64_t length
Definition: btrfs.h:450
#define TYPE_DEV_EXTENT
Definition: btrfs.h:42
GLsizeiptr size
Definition: glext.h:5919
uint64_t objid
Definition: btrfs.h:448
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
UINT64 uint64_t
Definition: types.h:77
uint64_t dev_id
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:52
uint64_t chunktree
Definition: btrfs.h:447
BTRFS_UUID chunktree_uuid
Definition: btrfs.h:451
uint64_t address
Definition: btrfs.h:449
off
Definition: i386-dis.c:3909

Referenced by add_chunk().

◆ FormatEx()

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

Definition at line 1554 of file btrfslib.c.

1554  {
1555  UNICODE_STRING DriveRoot, Label;
1556  NTSTATUS Status;
1557 
1558  if (!root || !root->string)
1559  return FALSE;
1560 
1561  DriveRoot.Length = DriveRoot.MaximumLength = (USHORT)(wcslen(root->string) * sizeof(WCHAR));
1562  DriveRoot.Buffer = root->string;
1563 
1564  if (opts && opts->label && opts->label->string) {
1565  Label.Length = Label.MaximumLength = (USHORT)(wcslen(opts->label->string) * sizeof(WCHAR));
1566  Label.Buffer = opts->label->string;
1567  } else {
1568  Label.Length = Label.MaximumLength = 0;
1569  Label.Buffer = NULL;
1570  }
1571 
1572 #ifndef __REACTOS__
1573  Status = FormatEx2(&DriveRoot, FMIFS_HARDDISK, &Label, opts && opts->flags & FORMAT_FLAG_QUICK_FORMAT, 0, NULL);
1574 #else
1575  Status = BtrfsFormatEx(&DriveRoot, FMIFS_HARDDISK, &Label, opts && opts->flags & FORMAT_FLAG_QUICK_FORMAT, 0, NULL);
1576 #endif
1577 
1578  return NT_SUCCESS(Status);
1579 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
#define FORMAT_FLAG_QUICK_FORMAT
Definition: btrfslib.c:83
DSTRING * label
Definition: btrfslib.c:94
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:1384
WCHAR * string
Definition: btrfslib.c:76
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
uint32_t flags
Definition: btrfslib.c:93
unsigned short USHORT
Definition: pedump.c:61
PWCHAR Label
Definition: format.c:70
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ FormatEx2()

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

Definition at line 1384 of file btrfslib.c.

1389 {
1390  NTSTATUS Status;
1391  HANDLE h, btrfsh;
1395  DISK_GEOMETRY dg;
1396  uint32_t sector_size, node_size;
1397  UNICODE_STRING btrfsus;
1398 #ifndef __REACTOS__
1399  HANDLE token;
1401  LUID luid;
1402 #endif
1403  uint64_t incompat_flags;
1404  UNICODE_STRING empty_label;
1405 
1406  static WCHAR btrfs[] = L"\\Btrfs";
1407 
1408 #ifndef __REACTOS__
1411 
1412  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
1413  CloseHandle(token);
1415  }
1416 
1417  tp.PrivilegeCount = 1;
1418  tp.Privileges[0].Luid = luid;
1419  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1420 
1422  CloseHandle(token);
1424  }
1425 
1426  CloseHandle(token);
1427 #endif
1428 
1430 
1433 
1434  if (!NT_SUCCESS(Status))
1435  return Status;
1436 
1438  if (!NT_SUCCESS(Status)) {
1439  NtClose(h);
1440  return Status;
1441  }
1442 
1443  // MSDN tells us to use IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, but there are
1444  // some instances where it fails and IOCTL_DISK_GET_DRIVE_GEOMETRY succeeds -
1445  // such as with spanned volumes.
1447  if (!NT_SUCCESS(Status)) {
1448  NtClose(h);
1449  return Status;
1450  }
1451 
1452  if (def_sector_size == 0) {
1454 
1455  if (sector_size == 0x200 || sector_size == 0)
1456  sector_size = 0x1000;
1457  } else {
1459  NtClose(h);
1460  return STATUS_INVALID_PARAMETER;
1461  }
1462 
1464  }
1465 
1466  if (def_node_size == 0)
1467  node_size = 0x4000;
1468  else {
1470  NtClose(h);
1471  return STATUS_INVALID_PARAMETER;
1472  }
1473 
1474  node_size = def_node_size;
1475  }
1476 
1477  if (Callback) {
1478  ULONG pc = 0;
1479  Callback(PROGRESS, 0, (PVOID)&pc);
1480  }
1481 
1483 
1486  goto end;
1487  }
1488 
1489  do_full_trim(h);
1490 
1491  incompat_flags = def_incompat_flags;
1493 
1494  if (!Label) {
1495  empty_label.Buffer = NULL;
1496  empty_label.Length = empty_label.MaximumLength = 0;
1497  Label = &empty_label;
1498  }
1499 
1500  Status = write_btrfs(h, gli.Length.QuadPart, Label, sector_size, node_size, incompat_flags);
1501 
1503 
1504 end:
1506 
1507  NtClose(h);
1508 
1509  if (NT_SUCCESS(Status)) {
1510  btrfsus.Buffer = btrfs;
1511  btrfsus.Length = btrfsus.MaximumLength = (USHORT)(wcslen(btrfs) * sizeof(WCHAR));
1512 
1513  InitializeObjectAttributes(&attr, &btrfsus, 0, NULL, NULL);
1514 
1517 
1518  if (NT_SUCCESS(Status)) {
1519  MOUNTDEV_NAME* mdn;
1520  ULONG mdnsize;
1521 
1522  mdnsize = offsetof(MOUNTDEV_NAME, Name[0]) + DriveRoot->Length;
1523 #ifndef __REACTOS__
1524  mdn = malloc(mdnsize);
1525 #else
1526  mdn = RtlAllocateHeap(RtlGetProcessHeap(), 0, mdnsize);
1527 #endif
1528 
1529  mdn->NameLength = DriveRoot->Length;
1530  memcpy(mdn->Name, DriveRoot->Buffer, DriveRoot->Length);
1531 
1532  NtDeviceIoControlFile(btrfsh, NULL, NULL, NULL, &iosb, IOCTL_BTRFS_PROBE_VOLUME, mdn, mdnsize, NULL, 0);
1533 
1534 #ifndef __REACTOS__
1535  free(mdn);
1536 #else
1537  RtlFreeHeap(RtlGetProcessHeap(), 0, mdn);
1538 #endif
1539 
1540  NtClose(btrfsh);
1541  }
1542 
1544  }
1545 
1546  if (Callback) {
1548  Callback(DONE, 0, (PVOID)&success);
1549  }
1550 
1551  return Status;
1552 }
#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:406
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
static BOOL is_power_of_two(ULONG i)
Definition: btrfslib.c:1379
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define free
Definition: debug_ros.c:5
static NTSTATUS write_btrfs(HANDLE h, uint64_t size, PUNICODE_STRING label, uint32_t sector_size, uint32_t node_size, uint64_t incompat_flags)
Definition: btrfslib.c:1126
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ULONG BytesPerSector
Definition: ntdddisk.h:381
GLuint GLuint end
Definition: gl.h:1545
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:50
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
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
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2855
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:106
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
#define TOKEN_QUERY
Definition: setypes.h:874
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR Name[1]
Definition: imports.h:144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
static BOOL is_mounted_multi_device(HANDLE h, uint32_t sector_size)
Definition: btrfslib.c:1230
static void do_full_trim(HANDLE h)
Definition: btrfslib.c:1362
#define success(from, fromstr, to, tostr)
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
Definition: cookie.c:201
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ULONG def_node_size
Definition: btrfslib.c:155
#define IOCTL_BTRFS_PROBE_VOLUME
Definition: btrfsioctl.h:28
__u8 attr
Definition: mkdosfs.c:359
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:111
Definition: btrfslib.c:204
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG def_sector_size
Definition: btrfslib.c:155
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:51
UINT64 uint64_t
Definition: types.h:77
unsigned short USHORT
Definition: pedump.c:61
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
USHORT NameLength
Definition: imports.h:143
UINT32 uint32_t
Definition: types.h:75
uint64_t def_incompat_flags
Definition: btrfslib.c:156
#define FSCTL_LOCK_VOLUME
Definition: btrfslib.c:49
unsigned int ULONG
Definition: retypes.h:1
PWCHAR Label
Definition: format.c:70
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define malloc
Definition: debug_ros.c:4
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
LPFNPSPCALLBACK Callback
Definition: desk.c:112
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
LONGLONG QuadPart
Definition: typedefs.h:113

Referenced by FormatEx().

◆ free_chunks()

static void free_chunks ( LIST_ENTRY chunks)
static

Definition at line 338 of file btrfslib.c.

338  {
339  LIST_ENTRY* le;
340 
341  le = chunks->Flink;
342  while (le != chunks) {
343  LIST_ENTRY *le2 = le->Flink;
345 
346 #ifndef __REACTOS__
347  free(c->chunk_item);
348  free(c);
349 #else
350  RtlFreeHeap(RtlGetProcessHeap(), 0, c->chunk_item);
351  RtlFreeHeap(RtlGetProcessHeap(), 0, c);
352 #endif
353 
354  le = le2;
355  }
356 }
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
const GLubyte * c
Definition: glext.h:8905
Definition: typedefs.h:118
Definition: list.h:27

Referenced by write_btrfs().

◆ free_roots()

static void free_roots ( LIST_ENTRY roots)
static

Definition at line 301 of file btrfslib.c.

301  {
302  LIST_ENTRY* le;
303 
304  le = roots->Flink;
305  while (le != roots) {
306  LIST_ENTRY *le2 = le->Flink, *le3;
308 
309  le3 = r->items.Flink;
310  while (le3 != &r->items) {
311  LIST_ENTRY* le4 = le3->Flink;
313 
314  if (item->data)
315 #ifdef __REACTOS__
316  RtlFreeHeap(RtlGetProcessHeap(), 0, item->data);
317 
318  RtlFreeHeap(RtlGetProcessHeap(), 0, item);
319 #else
320  free(item->data);
321 
322  free(item);
323 #endif
324 
325  le3 = le4;
326  }
327 
328 #ifdef __REACTOS__
329  RtlFreeHeap(RtlGetProcessHeap(), 0, r);
330 #else
331  free(r);
332 #endif
333 
334  le = le2;
335  }
336 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
static ATOM item
Definition: dde.c:856
Definition: list.h:27

Referenced by write_btrfs().

◆ get_next_address()

static uint64_t get_next_address ( btrfs_chunk c)
static

Definition at line 514 of file btrfslib.c.

514  {
515  uint64_t addr;
516 
517  addr = c->lastoff;
518 
519  while (superblock_collision(c, addr)) {
520  addr = addr - ((addr - c->offset) % c->chunk_item->stripe_length) + c->chunk_item->stripe_length;
521 
522  if (addr >= c->offset + c->chunk_item->size) // chunk has been exhausted
523  return 0;
524  }
525 
526  return addr;
527 }
const GLubyte * c
Definition: glext.h:8905
GLenum const GLvoid * addr
Definition: glext.h:9621
UINT64 uint64_t
Definition: types.h:77
static BOOL superblock_collision(btrfs_chunk *c, uint64_t address)
Definition: btrfslib.c:493

Referenced by assign_addresses().

◆ get_uuid()

static void get_uuid ( BTRFS_UUID uuid)
static

Definition at line 716 of file btrfslib.c.

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

Referenced by init_device(), and write_btrfs().

◆ GetFilesystemInformation()

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

Definition at line 1593 of file btrfslib.c.

1593  {
1594  // STUB - undocumented
1595 
1596  return TRUE;
1597 }
#define TRUE
Definition: types.h:120

◆ init_device()

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

Definition at line 735 of file btrfslib.c.

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

Referenced by write_btrfs().

◆ init_fs_tree()

static void init_fs_tree ( btrfs_root r,
uint32_t  node_size 
)
static

Definition at line 953 of file btrfslib.c.

953  {
954  INODE_ITEM ii;
957 
958  memset(&ii, 0, sizeof(INODE_ITEM));
959 
960  ii.generation = 1;
961  ii.st_blocks = node_size;
962  ii.st_nlink = 1;
963  ii.st_mode = 040755;
964 
966  time.LowPart = filetime.dwLowDateTime;
967  time.HighPart = filetime.dwHighDateTime;
968 
970  ii.st_ctime = ii.st_mtime = ii.st_atime;
971 
973 
975 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define SUBVOL_ROOT_INODE
Definition: propsheet.cpp:42
static void add_inode_ref(btrfs_root *r, uint64_t inode, uint64_t parent, uint64_t index, const char *name)
Definition: btrfslib.c:932
__u16 time
Definition: mkdosfs.c:366
BTRFS_TIME st_ctime
Definition: btrfs.h:284
uint32_t st_nlink
Definition: btrfs.h:275
BTRFS_TIME st_mtime
Definition: btrfs.h:285
BTRFS_TIME st_atime
Definition: btrfs.h:283
#define TYPE_INODE_ITEM
Definition: btrfs.h:19
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
uint64_t generation
Definition: btrfs.h:270
uint64_t st_blocks
Definition: btrfs.h:273
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME *out)
Definition: btrfslib.c:906
#define memset(x, y, z)
Definition: compat.h:39
uint32_t st_mode
Definition: btrfs.h:278

Referenced by write_btrfs().

◆ InitializeListHead()

FORCEINLINE VOID InitializeListHead ( PLIST_ENTRY  ListHead)

Definition at line 98 of file btrfslib.c.

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

Referenced by add_root(), and write_btrfs().

◆ InsertTailList()

FORCEINLINE VOID InsertTailList ( PLIST_ENTRY  ListHead,
PLIST_ENTRY  Entry 
)

Definition at line 102 of file btrfslib.c.

102  {
103  PLIST_ENTRY Blink;
104 
105  Blink = ListHead->Blink;
106  Entry->Flink = ListHead;
107  Entry->Blink = Blink;
108  Blink->Flink = Entry;
109  ListHead->Blink = Entry;
110 }
struct _Entry Entry
Definition: kefuncs.h:627
struct _LIST_ENTRY * Blink
Definition: typedefs.h:121
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
base of all file and directory entries
Definition: entries.h:82

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

◆ is_mounted_multi_device()

static BOOL is_mounted_multi_device ( HANDLE  h,
uint32_t  sector_size 
)
static

Definition at line 1230 of file btrfslib.c.

1230  {
1231  NTSTATUS Status;
1232  superblock* sb;
1233  ULONG sblen;
1236  BTRFS_UUID fsuuid, devuuid;
1237  uint32_t crc32;
1240  HANDLE h2;
1241  btrfs_filesystem *bfs = NULL, *bfs2;
1242  ULONG bfssize;
1243  BOOL ret = FALSE;
1244 
1245  static WCHAR btrfs[] = L"\\Btrfs";
1246 
1247  sblen = sizeof(*sb);
1248  if (sblen & (sector_size - 1))
1249  sblen = (sblen & sector_size) + sector_size;
1250 
1251 #ifndef __REACTOS__
1252  sb = malloc(sblen);
1253 #else
1254  sb = RtlAllocateHeap(RtlGetProcessHeap(), 0, sblen);
1255 #endif
1256 
1257  off.QuadPart = superblock_addrs[0];
1258 
1259  Status = NtReadFile(h, NULL, NULL, NULL, &iosb, sb, sblen, &off, NULL);
1260  if (!NT_SUCCESS(Status)) {
1261 #ifndef __REACTOS__
1262  free(sb);
1263 #else
1264  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1265 #endif
1266  return FALSE;
1267  }
1268 
1269  if (sb->magic != BTRFS_MAGIC) {
1270 #ifndef __REACTOS__
1271  free(sb);
1272 #else
1273  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1274 #endif
1275  return FALSE;
1276  }
1277 
1278  crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
1279  if (crc32 != *((uint32_t*)sb)) {
1280 #ifndef __REACTOS__
1281  free(sb);
1282 #else
1283  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1284 #endif
1285  return FALSE;
1286  }
1287 
1288  fsuuid = sb->uuid;
1289  devuuid = sb->dev_item.device_uuid;
1290 
1291 #ifndef __REACTOS__
1292  free(sb);
1293 #else
1294  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
1295 #endif
1296 
1297  us.Length = us.MaximumLength = (USHORT)(wcslen(btrfs) * sizeof(WCHAR));
1298  us.Buffer = btrfs;
1299 
1301 
1304  if (!NT_SUCCESS(Status)) // not a problem, it usually just means the driver isn't loaded
1305  return FALSE;
1306 
1307  bfssize = 0;
1308 
1309  do {
1310  bfssize += 1024;
1311 
1312 #ifndef __REACTOS__
1313  if (bfs) free(bfs);
1314  bfs = malloc(bfssize);
1315 #else
1316  if (bfs) RtlFreeHeap(RtlGetProcessHeap(), 0, bfs);
1317  bfs = RtlAllocateHeap(RtlGetProcessHeap(), 0, bfssize);
1318 #endif
1319 
1322  NtClose(h2);
1323  return FALSE;
1324  }
1325  } while (Status == STATUS_BUFFER_OVERFLOW);
1326 
1327  if (!NT_SUCCESS(Status))
1328  goto end;
1329 
1330  if (bfs->num_devices != 0) {
1331  bfs2 = bfs;
1332  while (TRUE) {
1333  if (RtlCompareMemory(&bfs2->uuid, &fsuuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
1334  if (bfs2->num_devices == 1)
1335  ret = FALSE;
1336  else
1337  ret = look_for_device(bfs2, &devuuid);
1338 
1339  goto end;
1340  }
1341 
1342  if (bfs2->next_entry == 0)
1343  break;
1344  else
1345  bfs2 = (btrfs_filesystem*)((uint8_t*)bfs2 + bfs2->next_entry);
1346  }
1347  }
1348 
1349 end:
1350  NtClose(h2);
1351 
1352  if (bfs)
1353 #ifndef __REACTOS__
1354  free(bfs);
1355 #else
1356  RtlFreeHeap(RtlGetProcessHeap(), 0, bfs);
1357 #endif
1358 
1359  return ret;
1360 }
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:1213
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)
uint64_t magic
Definition: btrfs.h:212
superblock * sb
Definition: btrfs.c:4137
static const BYTE us[]
Definition: encode.c:689
#define IOCTL_BTRFS_QUERY_FILESYSTEMS
Definition: btrfsioctl.h:21
#define free
Definition: debug_ros.c:5
static uint32_t calc_crc32c(uint32_t seed, uint8_t *msg, ULONG msglen)
Definition: btrfslib.c:249
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
uint32_t crc32
Definition: btrfs.c:4138
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
uint8_t checksum[32]
Definition: btrfs.h:208
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
uint32_t num_devices
Definition: btrfsioctl.h:190
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
DEV_ITEM dev_item
Definition: btrfs.h:235
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BTRFS_UUID device_uuid
Definition: btrfs.h:174
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define SYNCHRONIZE
Definition: nt_native.h:61
BYTE uint8_t
Definition: msvideo1.c:66
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
unsigned short USHORT
Definition: pedump.c:61
BTRFS_UUID uuid
Definition: btrfs.h:209
UINT32 uint32_t
Definition: types.h:75
static const uint64_t superblock_addrs[]
Definition: btrfs.h:13
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define malloc
Definition: debug_ros.c:4
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
_In_ uint16_t _Out_ ULONG * atts
Definition: btrfs_drv.h:1076
#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 1379 of file btrfslib.c.

1379  {
1380  return ((i != 0) && !(i & (i - 1)));
1381 }
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 1020 of file btrfslib.c.

1020  {
1021  ULONG aptelen;
1022  ATA_PASS_THROUGH_EX* apte;
1024  NTSTATUS Status;
1025  IDENTIFY_DEVICE_DATA* idd;
1026 
1027  aptelen = sizeof(ATA_PASS_THROUGH_EX) + 512;
1028 #ifndef __REACTOS__
1029  apte = malloc(aptelen);
1030 
1031  RtlZeroMemory(apte, aptelen);
1032 #else
1033  apte = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, aptelen);
1034 #endif
1035 
1036  apte->Length = sizeof(ATA_PASS_THROUGH_EX);
1037  apte->AtaFlags = ATA_FLAGS_DATA_IN;
1038  apte->DataTransferLength = aptelen - sizeof(ATA_PASS_THROUGH_EX);
1039  apte->TimeOutValue = 3;
1040  apte->DataBufferOffset = apte->Length;
1042 
1043  Status = NtDeviceIoControlFile(h, NULL, NULL, NULL, &iosb, IOCTL_ATA_PASS_THROUGH, apte, aptelen, apte, aptelen);
1044 
1045  if (NT_SUCCESS(Status)) {
1046  idd = (IDENTIFY_DEVICE_DATA*)((uint8_t*)apte + sizeof(ATA_PASS_THROUGH_EX));
1047 
1048  if (idd->NominalMediaRotationRate == 1) {
1049 #ifndef __REACTOS__
1050  free(apte);
1051 #else
1052  RtlFreeHeap(RtlGetProcessHeap(), 0, apte);
1053 #endif
1054  return TRUE;
1055  }
1056  }
1057 
1058 #ifndef __REACTOS__
1059  free(apte);
1060 #else
1061  RtlFreeHeap(RtlGetProcessHeap(), 0, apte);
1062 #endif
1063 
1064  return FALSE;
1065 }
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:606
ULONG_PTR DataBufferOffset
Definition: ntddscsi.h:139
#define ATA_FLAGS_DATA_IN
Definition: uata_ctl.h:222
#define IDE_COMMAND_IDENTIFY
Definition: atapi.h:118
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
USHORT NominalMediaRotationRate
Definition: ata.h:243
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG DataTransferLength
Definition: ntddscsi.h:136
BYTE uint8_t
Definition: msvideo1.c:66
struct _ATA_PASS_THROUGH_EX ATA_PASS_THROUGH_EX
Status
Definition: gdiplustypes.h:24
UCHAR CurrentTaskFile[8]
Definition: ntddscsi.h:141
#define IOCTL_ATA_PASS_THROUGH
Definition: ntddscsi.h:40
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define malloc
Definition: debug_ros.c:4

Referenced by write_btrfs().

◆ look_for_device()

static BOOL look_for_device ( btrfs_filesystem bfs,
BTRFS_UUID devuuid 
)
static

Definition at line 1213 of file btrfslib.c.

1213  {
1214  uint32_t i;
1216 
1217  for (i = 0; i < bfs->num_devices; i++) {
1218  if (i == 0)
1219  dev = &bfs->device;
1220  else
1222 
1223  if (RtlCompareMemory(&dev->uuid, devuuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID))
1224  return TRUE;
1225  }
1226 
1227  return FALSE;
1228 }
#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
uint32_t num_devices
Definition: btrfsioctl.h:190
#define offsetof(TYPE, MEMBER)
BYTE uint8_t
Definition: msvideo1.c:66
UINT32 uint32_t
Definition: types.h:75
Definition: name.c:38
btrfs_filesystem_device device
Definition: btrfsioctl.h:191
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by is_mounted_multi_device().

◆ NtFsControlFile()

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

Referenced by FormatEx2().

◆ NtReadFile()

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

Referenced by is_mounted_multi_device().

◆ NtWriteFile()

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

◆ set_default_subvol()

static void set_default_subvol ( btrfs_root root_root,
uint32_t  node_size 
)
static

Definition at line 1094 of file btrfslib.c.

1094  {
1095  INODE_ITEM ii;
1098 
1099  static const char default_subvol[] = "default";
1100  static const uint32_t default_hash = 0x8dbfc2d2;
1101 
1102  add_inode_ref(root_root, BTRFS_ROOT_FSTREE, BTRFS_ROOT_TREEDIR, 0, default_subvol);
1103 
1104  memset(&ii, 0, sizeof(INODE_ITEM));
1105 
1106  ii.generation = 1;
1107  ii.st_blocks = node_size;
1108  ii.st_nlink = 1;
1109  ii.st_mode = 040755;
1110 
1112  time.LowPart = filetime.dwLowDateTime;
1113  time.HighPart = filetime.dwHighDateTime;
1114 
1116  ii.st_ctime = ii.st_mtime = ii.otime = ii.st_atime;
1117 
1118  add_item(root_root, BTRFS_ROOT_TREEDIR, TYPE_INODE_ITEM, 0, &ii, sizeof(INODE_ITEM));
1119 
1120  add_inode_ref(root_root, BTRFS_ROOT_TREEDIR, BTRFS_ROOT_TREEDIR, 0, "..");
1121 
1123  0xffffffffffffffff, 0, BTRFS_TYPE_DIRECTORY, default_subvol);
1124 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
BTRFS_TIME otime
Definition: btrfs.h:286
static void add_inode_ref(btrfs_root *r, uint64_t inode, uint64_t parent, uint64_t index, const char *name)
Definition: btrfslib.c:932
__u16 time
Definition: mkdosfs.c:366
BTRFS_TIME st_ctime
Definition: btrfs.h:284
uint32_t st_nlink
Definition: btrfs.h:275
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
BTRFS_TIME st_mtime
Definition: btrfs.h:285
#define BTRFS_ROOT_TREEDIR
Definition: btrfs.h:55
BTRFS_TIME st_atime
Definition: btrfs.h:283
#define BTRFS_ROOT_FSTREE
Definition: btrfs.h:54
#define TYPE_INODE_ITEM
Definition: btrfs.h:19
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
uint64_t generation
Definition: btrfs.h:270
uint64_t st_blocks
Definition: btrfs.h:273
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME *out)
Definition: btrfslib.c:906
static void add_dir_item(btrfs_root *root, uint64_t inode, uint32_t hash, uint64_t key_objid, uint8_t key_type, uint64_t key_offset, uint64_t transid, uint8_t type, const char *name)
Definition: btrfslib.c:1067
#define TYPE_ROOT_ITEM
Definition: btrfs.h:28
UINT32 uint32_t
Definition: types.h:75
#define memset(x, y, z)
Definition: compat.h:39
uint32_t st_mode
Definition: btrfs.h:278

Referenced by write_btrfs().

◆ SetIncompatFlags()

void __stdcall SetIncompatFlags ( uint64_t  incompat_flags)

Definition at line 1589 of file btrfslib.c.

1589  {
1590  def_incompat_flags = incompat_flags;
1591 }
uint64_t def_incompat_flags
Definition: btrfslib.c:156

◆ SetSizes()

void __stdcall SetSizes ( ULONG  sector,
ULONG  node 
)

Definition at line 1581 of file btrfslib.c.

1581  {
1582  if (sector != 0)
1584 
1585  if (node != 0)
1586  def_node_size = node;
1587 }
uint32_t sector
Definition: isohybrid.c:61
struct node node
ULONG def_node_size
Definition: btrfslib.c:155
ULONG def_sector_size
Definition: btrfslib.c:155
Definition: dlist.c:348

◆ superblock_collision()

static BOOL superblock_collision ( btrfs_chunk c,
uint64_t  address 
)
static

Definition at line 493 of file btrfslib.c.

493  {
494  CHUNK_ITEM_STRIPE* cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
495  uint64_t stripe = (address - c->offset) / c->chunk_item->stripe_length;
496  uint16_t i, j;
497 
498  for (i = 0; i < c->chunk_item->num_stripes; i++) {
499  j = 0;
500  while (superblock_addrs[j] != 0) {
501  if (superblock_addrs[j] >= cis[i].offset) {
502  uint64_t stripe2 = (superblock_addrs[j] - cis[i].offset) / c->chunk_item->stripe_length;
503 
504  if (stripe2 == stripe)
505  return TRUE;
506  }
507  j++;
508  }
509  }
510 
511  return FALSE;
512 }
#define TRUE
Definition: types.h:120
GLintptr offset
Definition: glext.h:5920
Definition: write.c:111
unsigned short int uint16_t
Definition: acefiex.h:54
uint64_t offset
Definition: btrfs.h:331
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
if(!(yy_init))
Definition: macro.lex.yy.c:714
const GLubyte * c
Definition: glext.h:8905
GLuint address
Definition: glext.h:9393
UINT64 uint64_t
Definition: types.h:77
static const uint64_t superblock_addrs[]
Definition: btrfs.h:13

Referenced by get_next_address().

◆ win_time_to_unix()

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

Definition at line 906 of file btrfslib.c.

906  {
907  ULONGLONG l = t.QuadPart - 116444736000000000;
908 
909  out->seconds = l / 10000000;
910  out->nanoseconds = (l % 10000000) * 100;
911 }
GLdouble GLdouble t
Definition: gl.h:2047
r l[0]
Definition: byte_order.h:167
uint64_t ULONGLONG
Definition: typedefs.h:66
static FILE * out
Definition: regtests2xml.c:44

Referenced by init_fs_tree(), and set_default_subvol().

◆ write_btrfs()

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

Definition at line 1126 of file btrfslib.c.

1126  {
1127  NTSTATUS Status;
1128  LIST_ENTRY roots, chunks;
1129  btrfs_root *root_root, *chunk_root, *extent_root, *dev_root, *fs_root, *reloc_root;
1130  btrfs_chunk *sys_chunk, *metadata_chunk;
1131  btrfs_dev dev;
1132  BTRFS_UUID fsuuid, chunkuuid;
1133  BOOL ssd;
1134  uint64_t metadata_flags;
1135 #ifdef __REACTOS__
1136  ULONG seed;
1137 #endif
1138 
1139 #ifndef __REACTOS__
1140  srand((unsigned int)time(0));
1141  get_uuid(&fsuuid);
1142  get_uuid(&chunkuuid);
1143 #else
1144  seed = NtGetTickCount();
1145  get_uuid(&fsuuid, &seed);
1146  get_uuid(&chunkuuid, &seed);
1147 #endif
1148 
1149  InitializeListHead(&roots);
1150  InitializeListHead(&chunks);
1151 
1152  root_root = add_root(&roots, BTRFS_ROOT_ROOT);
1153  chunk_root = add_root(&roots, BTRFS_ROOT_CHUNK);
1154  extent_root = add_root(&roots, BTRFS_ROOT_EXTENT);
1155  dev_root = add_root(&roots, BTRFS_ROOT_DEVTREE);
1156  add_root(&roots, BTRFS_ROOT_CHECKSUM);
1157  fs_root = add_root(&roots, BTRFS_ROOT_FSTREE);
1159 
1160 #ifndef __REACTOS__
1161  init_device(&dev, 1, size, &fsuuid, sector_size);
1162 #else
1163  init_device(&dev, 1, size, &fsuuid, sector_size, &seed);
1164 #endif
1165 
1166  ssd = is_ssd(h);
1167 
1168  sys_chunk = add_chunk(&chunks, BLOCK_FLAG_SYSTEM | (ssd ? 0 : BLOCK_FLAG_DUPLICATE), chunk_root, &dev, dev_root, &chunkuuid, sector_size);
1169  if (!sys_chunk)
1170  return STATUS_INTERNAL_ERROR;
1171 
1172  metadata_flags = BLOCK_FLAG_METADATA;
1173 
1174  if (!ssd && !(incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS))
1175  metadata_flags |= BLOCK_FLAG_DUPLICATE;
1176 
1177  if (incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS)
1178  metadata_flags |= BLOCK_FLAG_DATA;
1179 
1180  metadata_chunk = add_chunk(&chunks, metadata_flags, chunk_root, &dev, dev_root, &chunkuuid, sector_size);
1181  if (!metadata_chunk)
1182  return STATUS_INTERNAL_ERROR;
1183 
1184  add_item(chunk_root, 1, TYPE_DEV_ITEM, dev.dev_item.dev_id, &dev.dev_item, sizeof(DEV_ITEM));
1185 
1186  set_default_subvol(root_root, node_size);
1187 
1188  init_fs_tree(fs_root, node_size);
1189  init_fs_tree(reloc_root, node_size);
1190 
1191  assign_addresses(&roots, sys_chunk, metadata_chunk, node_size, root_root, extent_root, incompat_flags & BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA);
1192 
1193  add_block_group_items(&chunks, extent_root);
1194 
1195  Status = write_roots(h, &roots, node_size, &fsuuid, &chunkuuid);
1196  if (!NT_SUCCESS(Status))
1197  return Status;
1198 
1200  if (!NT_SUCCESS(Status))
1201  return Status;
1202 
1203  Status = write_superblocks(h, &dev, chunk_root, root_root, extent_root, sys_chunk, node_size, &fsuuid, sector_size, label, incompat_flags);
1204  if (!NT_SUCCESS(Status))
1205  return Status;
1206 
1207  free_roots(&roots);
1208  free_chunks(&chunks);
1209 
1210  return STATUS_SUCCESS;
1211 }
#define TYPE_DEV_ITEM
Definition: btrfs.h:43
static NTSTATUS write_superblocks(HANDLE h, btrfs_dev *dev, btrfs_root *chunk_root, btrfs_root *root_root, btrfs_root *extent_root, btrfs_chunk *sys_chunk, uint32_t node_size, BTRFS_UUID *fsuuid, uint32_t sector_size, PUNICODE_STRING label, uint64_t incompat_flags)
Definition: btrfslib.c:761
static NTSTATUS write_roots(HANDLE h, LIST_ENTRY *roots, uint32_t node_size, BTRFS_UUID *fsuuid, BTRFS_UUID *chunkuuid)
Definition: btrfslib.c:635
static void set_default_subvol(btrfs_root *root_root, uint32_t node_size)
Definition: btrfslib.c:1094
char * reloc_root
Definition: mkisofs.c:177
static BOOL is_ssd(HANDLE h)
Definition: btrfslib.c:1020
LONG NTSTATUS
Definition: precomp.h:26
void __cdecl srand(_In_ unsigned int _Seed)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:114
__u16 time
Definition: mkdosfs.c:366
static void add_block_group_items(LIST_ENTRY *chunks, btrfs_root *extent_root)
Definition: btrfslib.c:977
#define NtGetTickCount
Definition: rtlp.h:146
#define BTRFS_ROOT_DATA_RELOC
Definition: btrfs.h:59
static int dev
Definition: mkdosfs.c:536
static btrfs_root * add_root(LIST_ENTRY *roots, uint64_t id)
Definition: btrfslib.c:282
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#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:108
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:76
#define BTRFS_ROOT_ROOT
Definition: btrfs.h:50
static void init_device(btrfs_dev *dev, uint64_t id, uint64_t size, BTRFS_UUID *fsuuid, uint32_t sector_size)
Definition: btrfslib.c:735
GLsizeiptr size
Definition: glext.h:5919
FORCEINLINE VOID InitializeListHead(PLIST_ENTRY ListHead)
Definition: btrfslib.c:98
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void assign_addresses(LIST_ENTRY *roots, btrfs_chunk *sys_chunk, btrfs_chunk *metadata_chunk, uint32_t node_size, btrfs_root *root_root, btrfs_root *extent_root, BOOL skinny)
Definition: btrfslib.c:542
#define BLOCK_FLAG_METADATA
Definition: shellext.h:77
#define BTRFS_ROOT_FSTREE
Definition: btrfs.h:54
static void add_item(btrfs_root *r, uint64_t obj_id, uint8_t obj_type, uint64_t offset, void *data, uint16_t size)
Definition: btrfslib.c:358
Definition: typedefs.h:118
static void init_fs_tree(btrfs_root *r, uint32_t node_size)
Definition: btrfslib.c:953
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:301
UINT64 uint64_t
Definition: types.h:77
#define BTRFS_ROOT_CHECKSUM
Definition: btrfs.h:56
static btrfs_chunk * add_chunk(LIST_ENTRY *chunks, uint64_t flags, btrfs_root *chunk_root, btrfs_dev *dev, btrfs_root *dev_root, BTRFS_UUID *chunkuuid, uint32_t sector_size)
Definition: btrfslib.c:419
uint64_t dev_id
#define BLOCK_FLAG_DATA
Definition: shellext.h:75
#define BTRFS_ROOT_DEVTREE
Definition: btrfs.h:53
static NTSTATUS clear_first_megabyte(HANDLE h)
Definition: btrfslib.c:994
unsigned int ULONG
Definition: retypes.h:1
static void free_chunks(LIST_ENTRY *chunks)
Definition: btrfslib.c:338
#define BTRFS_ROOT_CHUNK
Definition: btrfs.h:52
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:80
#define BTRFS_ROOT_EXTENT
Definition: btrfs.h:51
static void get_uuid(BTRFS_UUID *uuid)
Definition: btrfslib.c:716
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by FormatEx2().

◆ write_data()

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

Definition at line 615 of file btrfslib.c.

615  {
617  uint16_t i;
620  CHUNK_ITEM_STRIPE* cis;
621 
622  cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
623 
624  for (i = 0; i < c->chunk_item->num_stripes; i++) {
625  off.QuadPart = cis[i].offset + address - c->offset;
626 
628  if (!NT_SUCCESS(Status))
629  return Status;
630  }
631 
632  return STATUS_SUCCESS;
633 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtWriteFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
unsigned short int uint16_t
Definition: acefiex.h:54
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
uint64_t offset
Definition: btrfs.h:331
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
const GLubyte * c
Definition: glext.h:8905
#define for
Definition: utility.h:88
GLuint address
Definition: glext.h:9393
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938
off
Definition: i386-dis.c:3909

Referenced by write_roots().

◆ write_roots()

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

Definition at line 635 of file btrfslib.c.

635  {
636  LIST_ENTRY *le, *le2;
638  uint8_t* tree;
639 
640 #ifndef __REACTOS__
641  tree = malloc(node_size);
642 #else
643  tree = RtlAllocateHeap(RtlGetProcessHeap(), 0, node_size);
644 #endif
645 
646  le = roots->Flink;
647  while (le != roots) {
649  uint8_t* dp;
650  leaf_node* ln;
651  uint32_t crc32;
652 
653  memset(tree, 0, node_size);
654 
655  r->header.num_items = 0;
656  r->header.fs_uuid = *fsuuid;
658  r->header.chunk_tree_uuid = *chunkuuid;
659  r->header.generation = 1;
660  r->header.tree_id = r->id;
661 
662  ln = (leaf_node*)(tree + sizeof(tree_header));
663 
664  dp = tree + node_size;
665 
666  le2 = r->items.Flink;
667  while (le2 != &r->items) {
669 
670  ln->key = item->key;
671  ln->size = item->size;
672 
673  if (item->size > 0) {
674  dp -= item->size;
675  memcpy(dp, item->data, item->size);
676 
677  ln->offset = dp - tree - sizeof(tree_header);
678  } else
679  ln->offset = 0;
680 
681  ln = &ln[1];
682 
683  r->header.num_items++;
684 
685  le2 = le2->Flink;
686  }
687 
688  memcpy(tree, &r->header, sizeof(tree_header));
689 
690  crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&((tree_header*)tree)->fs_uuid, node_size - sizeof(((tree_header*)tree)->csum));
691  memcpy(tree, &crc32, sizeof(uint32_t));
692 
693  Status = write_data(h, r->header.address, r->c, tree, node_size);
694  if (!NT_SUCCESS(Status)) {
695 #ifndef __REACTOS__
696  free(tree);
697 #else
698  RtlFreeHeap(RtlGetProcessHeap(), 0, tree);
699 #endif
700  return Status;
701  }
702 
703  le = le->Flink;
704  }
705 
706 #ifndef __REACTOS__
707  free(tree);
708 #else
709  RtlFreeHeap(RtlGetProcessHeap(), 0, tree);
710 #endif
711 
712  return STATUS_SUCCESS;
713 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
struct _tree tree
#define free
Definition: debug_ros.c:5
static uint32_t calc_crc32c(uint32_t seed, uint8_t *msg, ULONG msglen)
Definition: btrfslib.c:249
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
uint32_t crc32
Definition: btrfs.c:4138
#define HEADER_FLAG_MIXED_BACKREF
Definition: btrfs.h:135
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
uint32_t offset
Definition: btrfs.h:151
uint32_t size
Definition: btrfs.h:152
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
tree_header header
Definition: btrfs_drv.h:427
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: typedefs.h:118
BYTE uint8_t
Definition: msvideo1.c:66
Status
Definition: gdiplustypes.h:24
static ATOM item
Definition: dde.c:856
KEY key
Definition: btrfs.h:150
Definition: list.h:27
static NTSTATUS write_data(HANDLE h, uint64_t address, btrfs_chunk *c, void *data, ULONG size)
Definition: btrfslib.c:615
UINT32 uint32_t
Definition: types.h:75
Definition: fs.h:216
#define HEADER_FLAG_WRITTEN
Definition: btrfs.h:133
#define malloc
Definition: debug_ros.c:4
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39

Referenced by write_btrfs().

◆ write_superblocks()

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

Definition at line 761 of file btrfslib.c.

762  {
765  ULONG sblen;
766  int i;
767  uint32_t crc32;
768  superblock* sb;
769  KEY* key;
770  uint64_t bytes_used;
771  LIST_ENTRY* le;
772 
773  sblen = sizeof(*sb);
774  if (sblen & (sector_size - 1))
775  sblen = (sblen & sector_size) + sector_size;
776 
777  bytes_used = 0;
778 
779  le = extent_root->items.Flink;
780  while (le != &extent_root->items) {
782 
783  if (item->key.obj_type == TYPE_EXTENT_ITEM)
784  bytes_used += item->key.offset;
785  else if (item->key.obj_type == TYPE_METADATA_ITEM)
786  bytes_used += node_size;
787 
788  le = le->Flink;
789  }
790 
791 #ifndef __REACTOS__
792  sb = malloc(sblen);
793  memset(sb, 0, sblen);
794 #else
795  sb = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sblen);
796 #endif
797 
798  sb->uuid = *fsuuid;
799  sb->flags = 1;
800  sb->magic = BTRFS_MAGIC;
801  sb->generation = 1;
802  sb->root_tree_addr = root_root->header.address;
803  sb->chunk_tree_addr = chunk_root->header.address;
804  sb->total_bytes = dev->dev_item.num_bytes;
805  sb->bytes_used = bytes_used;
807  sb->num_devices = 1;
809  sb->node_size = node_size;
810  sb->leaf_size = node_size;
812  sb->n = sizeof(KEY) + sizeof(CHUNK_ITEM) + (sys_chunk->chunk_item->num_stripes * sizeof(CHUNK_ITEM_STRIPE));
814  sb->incompat_flags = incompat_flags;
815  memcpy(&sb->dev_item, &dev->dev_item, sizeof(DEV_ITEM));
816 
817  if (label->Length > 0) {
818 #ifdef __REACTOS__
819  ANSI_STRING as;
820  unsigned int i;
821 
822  for (i = 0; i < label->Length / sizeof(WCHAR); i++) {
823 #else
824  ULONG utf8len;
825 
826  for (unsigned int i = 0; i < label->Length / sizeof(WCHAR); i++) {
827 #endif
828  if (label->Buffer[i] == '/' || label->Buffer[i] == '\\') {
829 #ifndef __REACTOS__
830  free(sb);
831 #else
832  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
833 #endif
835  }
836  }
837 
838 #ifndef __REACTOS__
839  utf8len = WideCharToMultiByte(CP_UTF8, 0, label->Buffer, label->Length / sizeof(WCHAR), NULL, 0, NULL, NULL);
840 
841  if (utf8len == 0 || utf8len > MAX_LABEL_SIZE) {
842  free(sb);
844  }
845 
846  if (WideCharToMultiByte(CP_UTF8, 0, label->Buffer, label->Length / sizeof(WCHAR), sb->label, utf8len, NULL, NULL) == 0) {
847  free(sb);
849  }
850 #else
851  as.Buffer = sb->label;
852  as.Length = 0;
854 
856  {
857  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
859  }
860 #endif
861  }
862  sb->cache_generation = 0xffffffffffffffff;
863 
864  key = (KEY*)sb->sys_chunk_array;
865  key->obj_id = 0x100;
866  key->obj_type = TYPE_CHUNK_ITEM;
867  key->offset = sys_chunk->offset;
868  memcpy(&key[1], sys_chunk->chunk_item, sizeof(CHUNK_ITEM) + (sys_chunk->chunk_item->num_stripes * sizeof(CHUNK_ITEM_STRIPE)));
869 
870  i = 0;
871  while (superblock_addrs[i] != 0) {
873 
874  if (superblock_addrs[i] > dev->dev_item.num_bytes)
875  break;
876 
878 
879  crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
880  memcpy(&sb->checksum, &crc32, sizeof(uint32_t));
881 
882  off.QuadPart = superblock_addrs[i];
883 
884  Status = NtWriteFile(h, NULL, NULL, NULL, &iosb, sb, sblen, &off, NULL);
885  if (!NT_SUCCESS(Status)) {
886 #ifndef __REACTOS__
887  free(sb);
888 #else
889  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
890 #endif
891  return Status;
892  }
893 
894  i++;
895  }
896 
897 #ifndef __REACTOS__
898  free(sb);
899 #else
900  RtlFreeHeap(RtlGetProcessHeap(), 0, sb);
901 #endif
902 
903  return STATUS_SUCCESS;
904 }
uint8_t sys_chunk_array[SYS_CHUNK_ARRAY_SIZE]
Definition: btrfs.h:240
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
uint64_t bytes_used
Definition: btrfs.h:219
#define WideCharToMultiByte
Definition: compat.h:101
uint64_t root_tree_addr
Definition: btrfs.h:214
uint64_t magic
Definition: btrfs.h:212
char label[MAX_LABEL_SIZE]
Definition: btrfs.h:236
superblock * sb
Definition: btrfs.c:4137
#define free
Definition: debug_ros.c:5
static uint32_t calc_crc32c(uint32_t seed, uint8_t *msg, ULONG msglen)
Definition: btrfslib.c:249
#define TYPE_CHUNK_ITEM
Definition: btrfs.h:44
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSTATUS NTAPI NtWriteFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
uint32_t crc32
Definition: btrfs.c:4138
#define STATUS_INVALID_VOLUME_LABEL
Definition: udferr_usr.h:156
#define TYPE_METADATA_ITEM
Definition: btrfs.h:32
uint64_t chunk_tree_addr
Definition: btrfs.h:215
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
uint8_t checksum[32]
Definition: btrfs.h:208
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint64_t address
Definition: btrfs.h:140
uint32_t stripe_size
Definition: btrfs.h:225
#define CP_UTF8
Definition: nls.h:20
uint64_t num_devices
Definition: btrfs.h:221
smooth NULL
Definition: ftsmooth.c:416
#define TYPE_EXTENT_ITEM
Definition: btrfs.h:31
DEV_ITEM dev_item
Definition: btrfs.h:235
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
tree_header header
Definition: btrfslib.c:134
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
uint64_t sb_phys_addr
Definition: btrfs.h:210
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
uint64_t flags
Definition: btrfs.h:211
USHORT MaximumLength
Definition: env_spec_w32.h:377
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define BTRFS_ROOT_TREEDIR
Definition: btrfs.h:55
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t root_dir_objectid
Definition: btrfs.h:220
uint64_t generation
Definition: btrfs.h:213
HKEY key
Definition: reg.c:42
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint64_t cache_generation
Definition: btrfs.h:237
Definition: typedefs.h:118
uint32_t n
Definition: btrfs.h:226
BYTE uint8_t
Definition: msvideo1.c:66
uint8_t label[11]
Definition: fsck.fat.h:65
__u8 sector_size[2]
Definition: mkdosfs.c:361
Status
Definition: gdiplustypes.h:24
Definition: btrfs.h:127
#define MAX_LABEL_SIZE
Definition: btrfs.h:16
UINT64 uint64_t
Definition: types.h:77
static ATOM item
Definition: dde.c:856
#define KEY
Definition: profile.c:30
uint64_t total_bytes
Definition: btrfs.h:218
BTRFS_UUID uuid
Definition: btrfs.h:209
uint32_t node_size
Definition: btrfs.h:223
Definition: list.h:27
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
UINT32 uint32_t
Definition: types.h:75
LIST_ENTRY items
Definition: btrfslib.c:136
static const uint64_t superblock_addrs[]
Definition: btrfs.h:13
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
uint32_t sector_size
Definition: btrfs.h:222
uint32_t leaf_size
Definition: btrfs.h:224
uint64_t chunk_root_generation
Definition: btrfs.h:227
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define memset(x, y, z)
Definition: compat.h:39
Definition: path.c:41
#define BTRFS_MAGIC
Definition: btrfs.h:42
off
Definition: i386-dis.c:3909
uint64_t incompat_flags
Definition: btrfs.h:230

Referenced by write_btrfs().

Variable Documentation

◆ crctable

const uint32_t crctable[]
static

Definition at line 214 of file btrfslib.c.

Referenced by calc_crc32c().

◆ def_incompat_flags

◆ def_node_size

ULONG def_node_size = 0

Definition at line 155 of file btrfslib.c.

Referenced by FormatEx2(), and SetSizes().

◆ def_sector_size

ULONG def_sector_size = 0

Definition at line 155 of file btrfslib.c.

Referenced by FormatEx2(), and SetSizes().

◆ module

Definition at line 154 of file btrfslib.c.