[BTRFS] Upgrade to 1.4
[reactos.git] / drivers / filesystems / btrfs / dirctrl.c
index d088de3..2e324e4 100644 (file)
@@ -18,7 +18,7 @@
 #include "btrfs_drv.h"
 
 // not currently in mingw
-//#ifndef _MSC_VER
+#ifndef _MSC_VER
 #define FileIdExtdDirectoryInformation (enum _FILE_INFORMATION_CLASS)60
 #define FileIdExtdBothDirectoryInformation (enum _FILE_INFORMATION_CLASS)63
 
@@ -58,7 +58,7 @@ typedef struct _FILE_ID_EXTD_BOTH_DIR_INFORMATION {
     WCHAR FileName[1];
 } FILE_ID_EXTD_BOTH_DIR_INFORMATION, *PFILE_ID_EXTD_BOTH_DIR_INFORMATION;
 
-//#endif
+#endif
 
 enum DirEntryType {
     DirEntryType_File,
@@ -69,7 +69,7 @@ enum DirEntryType {
 typedef struct {
     KEY key;
     UNICODE_STRING name;
-    UINT8 type;
+    uint8_t type;
     enum DirEntryType dir_entry_type;
     dir_child* dc;
 } dir_entry;
@@ -88,7 +88,7 @@ ULONG get_reparse_tag_fcb(fcb* fcb) {
         NTSTATUS Status;
         ULONG br;
 
-        Status = read_file(fcb, (UINT8*)&tag, 0, sizeof(ULONG), &br, NULL);
+        Status = read_file(fcb, (uint8_t*)&tag, 0, sizeof(ULONG), &br, NULL);
         if (!NT_SUCCESS(Status)) {
             ERR("read_file returned %08x\n", Status);
             return 0;
@@ -98,7 +98,7 @@ ULONG get_reparse_tag_fcb(fcb* fcb) {
     return tag;
 }
 
-ULONG get_reparse_tag(device_extension* Vcb, root* subvol, UINT64 inode, UINT8 type, ULONG atts, BOOL lxss, PIRP Irp) {
+ULONG get_reparse_tag(device_extension* Vcb, root* subvol, uint64_t inode, uint8_t type, ULONG atts, bool lxss, PIRP Irp) {
     fcb* fcb;
     ULONG tag = 0;
     NTSTATUS Status;
@@ -122,13 +122,13 @@ ULONG get_reparse_tag(device_extension* Vcb, root* subvol, UINT64 inode, UINT8 t
     if (!(atts & FILE_ATTRIBUTE_REPARSE_POINT))
         return 0;
 
-    Status = open_fcb(Vcb, subvol, inode, type, NULL, FALSE, NULL, &fcb, PagedPool, Irp);
+    Status = open_fcb(Vcb, subvol, inode, type, NULL, false, NULL, &fcb, PagedPool, Irp);
     if (!NT_SUCCESS(Status)) {
         ERR("open_fcb returned %08x\n", Status);
         return 0;
     }
 
-    ExAcquireResourceSharedLite(fcb->Header.Resource, TRUE);
+    ExAcquireResourceSharedLite(fcb->Header.Resource, true);
 
     tag = get_reparse_tag_fcb(fcb);
 
@@ -139,9 +139,9 @@ ULONG get_reparse_tag(device_extension* Vcb, root* subvol, UINT64 inode, UINT8 t
     return tag;
 }
 
-static ULONG get_ea_len(device_extension* Vcb, root* subvol, UINT64 inode, PIRP Irp) {
-    UINT8* eadata;
-    UINT16 len;
+static ULONG get_ea_len(device_extension* Vcb, root* subvol, uint64_t inode, PIRP Irp) {
+    uint8_t* eadata;
+    uint16_t len;
 
     if (get_xattr(Vcb, subvol, inode, EA_EA, EA_EA_HASH, &eadata, &len, Irp)) {
         ULONG offset;
@@ -165,8 +165,8 @@ static ULONG get_ea_len(device_extension* Vcb, root* subvol, UINT64 inode, PIRP
                 if (eainfo->NextEntryOffset == 0)
                     break;
 
-                eainfo = (FILE_FULL_EA_INFORMATION*)(((UINT8*)eainfo) + eainfo->NextEntryOffset);
-            } while (TRUE);
+                eainfo = (FILE_FULL_EA_INFORMATION*)(((uint8_t*)eainfo) + eainfo->NextEntryOffset);
+            } while (true);
 
             ExFreePool(eadata);
 
@@ -179,7 +179,7 @@ static ULONG get_ea_len(device_extension* Vcb, root* subvol, UINT64 inode, PIRP
 static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Irp, dir_entry* de, root* r) {
     PIO_STACK_LOCATION IrpSp;
     LONG needed;
-    UINT64 inode;
+    uint64_t inode;
     INODE_ITEM ii;
     NTSTATUS Status;
     ULONG atts = 0, ealen = 0;
@@ -227,13 +227,13 @@ static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Ir
                     win_time_to_unix(time, &ii.otime);
                     ii.st_atime = ii.st_mtime = ii.st_ctime = ii.otime;
                 } else {
-                    BOOL found = FALSE;
+                    bool found = false;
 
                     if (de->dc && de->dc->fileref && de->dc->fileref->fcb) {
                         ii = de->dc->fileref->fcb->inode_item;
                         atts = de->dc->fileref->fcb->atts;
                         ealen = de->dc->fileref->fcb->ealen;
-                        found = TRUE;
+                        found = true;
                     }
 
                     if (!found) {
@@ -244,14 +244,14 @@ static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Ir
                         searchkey.obj_type = TYPE_INODE_ITEM;
                         searchkey.offset = 0xffffffffffffffff;
 
-                        Status = find_item(fcb->Vcb, r, &tp, &searchkey, FALSE, Irp);
+                        Status = find_item(fcb->Vcb, r, &tp, &searchkey, false, Irp);
                         if (!NT_SUCCESS(Status)) {
                             ERR("error - find_item returned %08x\n", Status);
                             return Status;
                         }
 
                         if (tp.item->key.obj_id != searchkey.obj_id || tp.item->key.obj_type != searchkey.obj_type) {
-                            ERR("could not find inode item for inode %llx in root %llx\n", inode, r->id);
+                            ERR("could not find inode item for inode %I64x in root %I64x\n", inode, r->id);
                             return STATUS_INTERNAL_ERROR;
                         }
 
@@ -268,9 +268,9 @@ static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Ir
                             IrpSp->Parameters.QueryDirectory.FileInformationClass == FileIdExtdDirectoryInformation ||
                             IrpSp->Parameters.QueryDirectory.FileInformationClass == FileIdExtdBothDirectoryInformation) {
 
-                            BOOL dotfile = de->name.Length > sizeof(WCHAR) && de->name.Buffer[0] == '.';
+                            bool dotfile = de->name.Length > sizeof(WCHAR) && de->name.Buffer[0] == '.';
 
-                            atts = get_file_attributes(fcb->Vcb, r, inode, de->type, dotfile, FALSE, Irp);
+                            atts = get_file_attributes(fcb->Vcb, r, inode, de->type, dotfile, false, Irp);
                         }
 
                         if (IrpSp->Parameters.QueryDirectory.FileInformationClass == FileBothDirectoryInformation ||
@@ -549,8 +549,8 @@ static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Ir
             fiedi->EaSize = ealen;
             fiedi->ReparsePointTag = get_reparse_tag(fcb->Vcb, r, inode, de->type, atts, ccb->lxss, Irp);
 
-            RtlCopyMemory(&fiedi->FileId.Identifier[0], &fcb->inode, sizeof(UINT64));
-            RtlCopyMemory(&fiedi->FileId.Identifier[sizeof(UINT64)], &fcb->subvol->id, sizeof(UINT64));
+            RtlCopyMemory(&fiedi->FileId.Identifier[0], &fcb->inode, sizeof(uint64_t));
+            RtlCopyMemory(&fiedi->FileId.Identifier[sizeof(uint64_t)], &fcb->subvol->id, sizeof(uint64_t));
 
             RtlCopyMemory(fiedi->FileName, de->name.Buffer, de->name.Length);
 
@@ -592,8 +592,8 @@ static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Ir
             fiebdi->EaSize = ealen;
             fiebdi->ReparsePointTag = get_reparse_tag(fcb->Vcb, r, inode, de->type, atts, ccb->lxss, Irp);
 
-            RtlCopyMemory(&fiebdi->FileId.Identifier[0], &fcb->inode, sizeof(UINT64));
-            RtlCopyMemory(&fiebdi->FileId.Identifier[sizeof(UINT64)], &fcb->subvol->id, sizeof(UINT64));
+            RtlCopyMemory(&fiebdi->FileId.Identifier[0], &fcb->inode, sizeof(uint64_t));
+            RtlCopyMemory(&fiebdi->FileId.Identifier[sizeof(uint64_t)], &fcb->subvol->id, sizeof(uint64_t));
 
             fiebdi->ShortNameLength = 0;
 
@@ -652,7 +652,7 @@ static NTSTATUS query_dir_item(fcb* fcb, ccb* ccb, void* buf, LONG* len, PIRP Ir
     return STATUS_NO_MORE_FILES;
 }
 
-static NTSTATUS next_dir_entry(file_ref* fileref, UINT64* offset, dir_entry* de, dir_child** pdc) {
+static NTSTATUS next_dir_entry(file_ref* fileref, uint64_t* offset, dir_entry* de, dir_child** pdc) {
     LIST_ENTRY* le;
     dir_child* dc;
 
@@ -739,12 +739,12 @@ static NTSTATUS query_directory(PIRP Irp) {
     file_ref* fileref;
     device_extension* Vcb;
     void* buf;
-    UINT8 *curitem, *lastitem;
+    uint8_t *curitem, *lastitem;
     LONG length;
     ULONG count;
-    BOOL has_wildcard = FALSE, specific_file = FALSE, initial;
+    bool has_wildcard = false, specific_file = false, initial;
     dir_entry de;
-    UINT64 newoffset;
+    uint64_t newoffset;
     dir_child* dc = NULL;
 
     TRACE("query directory\n");
@@ -816,8 +816,8 @@ static NTSTATUS query_directory(PIRP Irp) {
             ccb->query_string.Buffer = NULL;
         }
 
-        ccb->has_wildcard = FALSE;
-        ccb->specific_file = FALSE;
+        ccb->has_wildcard = false;
+        ccb->specific_file = false;
     }
 
     initial = !ccb->query_string.Buffer;
@@ -826,11 +826,11 @@ static NTSTATUS query_directory(PIRP Irp) {
         TRACE("QD filename: %.*S\n", IrpSp->Parameters.QueryDirectory.FileName->Length / sizeof(WCHAR), IrpSp->Parameters.QueryDirectory.FileName->Buffer);
 
         if (IrpSp->Parameters.QueryDirectory.FileName->Length > sizeof(WCHAR) || IrpSp->Parameters.QueryDirectory.FileName->Buffer[0] != L'*') {
-            specific_file = TRUE;
+            specific_file = true;
 
             if (FsRtlDoesNameContainWildCards(IrpSp->Parameters.QueryDirectory.FileName)) {
-                has_wildcard = TRUE;
-                specific_file = FALSE;
+                has_wildcard = true;
+                specific_file = false;
             }
         }
 
@@ -838,7 +838,7 @@ static NTSTATUS query_directory(PIRP Irp) {
             RtlFreeUnicodeString(&ccb->query_string);
 
         if (has_wildcard)
-            RtlUpcaseUnicodeString(&ccb->query_string, IrpSp->Parameters.QueryDirectory.FileName, TRUE);
+            RtlUpcaseUnicodeString(&ccb->query_string, IrpSp->Parameters.QueryDirectory.FileName, true);
         else {
             ccb->query_string.Buffer = ExAllocatePoolWithTag(PagedPool, IrpSp->Parameters.QueryDirectory.FileName->Length, ALLOC_TAG);
             if (!ccb->query_string.Buffer) {
@@ -857,7 +857,7 @@ static NTSTATUS query_directory(PIRP Irp) {
         specific_file = ccb->specific_file;
 
         if (!(IrpSp->Flags & SL_RESTART_SCAN)) {
-            initial = FALSE;
+            initial = false;
 
             if (specific_file)
                 return STATUS_NO_MORE_FILES;
@@ -870,9 +870,9 @@ static NTSTATUS query_directory(PIRP Irp) {
 
     newoffset = ccb->query_dir_offset;
 
-    ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
+    ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
 
-    ExAcquireResourceSharedLite(&fileref->fcb->nonpaged->dir_children_lock, TRUE);
+    ExAcquireResourceSharedLite(&fileref->fcb->nonpaged->dir_children_lock, true);
 
     Status = next_dir_entry(fileref, &newoffset, &de, &dc);
 
@@ -895,24 +895,24 @@ static NTSTATUS query_directory(PIRP Irp) {
     length = IrpSp->Parameters.QueryDirectory.Length;
 
     if (specific_file) {
-        BOOL found = FALSE;
+        bool found = false;
         UNICODE_STRING us;
         LIST_ENTRY* le;
-        UINT32 hash;
-        UINT8 c;
+        uint32_t hash;
+        uint8_t c;
 
         us.Buffer = NULL;
 
         if (!ccb->case_sensitive) {
-            Status = RtlUpcaseUnicodeString(&us, &ccb->query_string, TRUE);
+            Status = RtlUpcaseUnicodeString(&us, &ccb->query_string, true);
             if (!NT_SUCCESS(Status)) {
                 ERR("RtlUpcaseUnicodeString returned %08x\n", Status);
                 goto end;
             }
 
-            hash = calc_crc32c(0xffffffff, (UINT8*)us.Buffer, us.Length);
+            hash = calc_crc32c(0xffffffff, (uint8_t*)us.Buffer, us.Length);
         } else
-            hash = calc_crc32c(0xffffffff, (UINT8*)ccb->query_string.Buffer, ccb->query_string.Length);
+            hash = calc_crc32c(0xffffffff, (uint8_t*)ccb->query_string.Buffer, ccb->query_string.Length);
 
         c = hash >> 24;
 
@@ -924,7 +924,7 @@ static NTSTATUS query_directory(PIRP Irp) {
 
                     if (dc2->hash == hash) {
                         if (dc2->name.Length == ccb->query_string.Length && RtlCompareMemory(dc2->name.Buffer, ccb->query_string.Buffer, ccb->query_string.Length) == ccb->query_string.Length) {
-                            found = TRUE;
+                            found = true;
 
                             de.key = dc2->key;
                             de.name = dc2->name;
@@ -948,7 +948,7 @@ static NTSTATUS query_directory(PIRP Irp) {
 
                     if (dc2->hash_uc == hash) {
                         if (dc2->name_uc.Length == us.Length && RtlCompareMemory(dc2->name_uc.Buffer, us.Buffer, us.Length) == us.Length) {
-                            found = TRUE;
+                            found = true;
 
                             de.key = dc2->key;
                             de.name = dc2->name;
@@ -996,7 +996,7 @@ static NTSTATUS query_directory(PIRP Irp) {
 
     count = 0;
     if (NT_SUCCESS(Status) && !(IrpSp->Flags & SL_RETURN_SINGLE_ENTRY) && !specific_file) {
-        lastitem = (UINT8*)buf;
+        lastitem = (uint8_t*)buf;
 
         while (length > 0) {
             switch (IrpSp->Parameters.QueryDirectory.FileInformationClass) {
@@ -1031,10 +1031,10 @@ static NTSTATUS query_directory(PIRP Irp) {
                 Status = next_dir_entry(fileref, &newoffset, &de, &dc);
                 if (NT_SUCCESS(Status)) {
                     if (!has_wildcard || FsRtlIsNameInExpression(&ccb->query_string, &de.name, !ccb->case_sensitive, NULL)) {
-                        curitem = (UINT8*)buf + IrpSp->Parameters.QueryDirectory.Length - length;
+                        curitem = (uint8_t*)buf + IrpSp->Parameters.QueryDirectory.Length - length;
                         count++;
 
-                        TRACE("file(%u) %u = %.*S\n", count, curitem - (UINT8*)buf, de.name.Length / sizeof(WCHAR), de.name.Buffer);
+                        TRACE("file(%u) %u = %.*S\n", count, curitem - (uint8_t*)buf, de.name.Length / sizeof(WCHAR), de.name.Buffer);
                         TRACE("offset = %u\n", ccb->query_dir_offset - 1);
 
                         status2 = query_dir_item(fcb, ccb, curitem, &length, Irp, &de, fcb->subvol);
@@ -1098,8 +1098,8 @@ static NTSTATUS notify_change_directory(device_extension* Vcb, PIRP Irp) {
         return STATUS_ACCESS_DENIED;
     }
 
-    ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
-    ExAcquireResourceExclusiveLite(fcb->Header.Resource, TRUE);
+    ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
+    ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
 
     if (fcb->type != BTRFS_TYPE_DIRECTORY) {
         Status = STATUS_INVALID_PARAMETER;
@@ -1124,7 +1124,7 @@ static NTSTATUS notify_change_directory(device_extension* Vcb, PIRP Irp) {
                 goto end;
             }
 
-            ccb->filename.MaximumLength = (UINT16)reqlen;
+            ccb->filename.MaximumLength = (uint16_t)reqlen;
 
             Status = fileref_get_filename(fileref, &ccb->filename, NULL, &reqlen);
             if (!NT_SUCCESS(Status)) {
@@ -1138,7 +1138,7 @@ static NTSTATUS notify_change_directory(device_extension* Vcb, PIRP Irp) {
     }
 
     FsRtlNotifyFilterChangeDirectory(Vcb->NotifySync, &Vcb->DirNotifyList, FileObject->FsContext2, (PSTRING)&ccb->filename,
-                                     IrpSp->Flags & SL_WATCH_TREE, FALSE, IrpSp->Parameters.NotifyDirectory.CompletionFilter, Irp,
+                                     IrpSp->Flags & SL_WATCH_TREE, false, IrpSp->Parameters.NotifyDirectory.CompletionFilter, Irp,
                                      NULL, NULL, NULL);
 
     Status = STATUS_PENDING;
@@ -1152,11 +1152,11 @@ end:
 
 _Dispatch_type_(IRP_MJ_DIRECTORY_CONTROL)
 _Function_class_(DRIVER_DISPATCH)
-NTSTATUS NTAPI drv_directory_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) {
+NTSTATUS __stdcall drv_directory_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) {
     PIO_STACK_LOCATION IrpSp;
     NTSTATUS Status;
     ULONG func;
-    BOOL top_level;
+    bool top_level;
     device_extension* Vcb = DeviceObject->DeviceExtension;
 
     FsRtlEnterFileSystem();