1480 {
1487 uint16_t i, startoffstripe, allowed_missing, missing_devices = 0;
1490 bool need_to_wait;
1492
1493 if (
Vcb->log_to_phys_loaded) {
1496
1498 ERR(
"get_chunk_from_address failed\n");
1500 }
1501 }
1502
1506
1507 if (pc)
1509 } else {
1511
1513
1515 while (le != &
Vcb->sys_chunks) {
1517
1520
1522 ci = chunk_item;
1525
1528 ERR(
"out of memory\n");
1530 }
1531
1534 }
1535
1536 break;
1537 }
1538 }
1539
1541 }
1542
1543 if (!ci) {
1544 ERR(
"could not find chunk for %I64x in bootstrap\n",
addr);
1546 }
1547
1548 if (pc)
1550 }
1551
1557 allowed_missing = 0;
1560 allowed_missing = 1;
1563 allowed_missing = 1;
1566 allowed_missing = 1;
1569 allowed_missing = 2;
1572 allowed_missing = 2;
1575 allowed_missing = 3;
1576 } else {
1578 allowed_missing = 0;
1579 }
1580
1582
1585
1588 ERR(
"out of memory\n");
1590 }
1591
1595 }
1596
1598
1602 context.sector_size =
Vcb->superblock.sector_size;
1606
1613
1614
1615
1616
1617
1618
1619
1620
1623
1624 if (file_read) {
1625
1626
1627
1628
1630
1632 ERR(
"out of memory\n");
1635 }
1636 } else
1638
1640 if (!master_mdl) {
1641 ERR(
"out of memory\n");
1644 }
1645
1647
1653
1655 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
1658 }
1659
1661
1663 if (startoffstripe >
i)
1665 else if (startoffstripe ==
i)
1666 context.stripes[
i].stripestart = startoff;
1667 else
1669
1670 if (endoffstripe >
i)
1672 else if (endoffstripe ==
i)
1673 context.stripes[
i].stripeend = endoff + 1;
1674 else
1676
1679
1681 ERR(
"IoAllocateMdl failed\n");
1686 }
1687 }
1688 }
1689
1691 if (!stripeoff) {
1692 ERR(
"out of memory\n");
1697 }
1698
1700
1705
1708
1710
1711 stripeoff[
stripe] += readlen;
1713 }
else if (
length - pos < ci->stripe_length) {
1715
1717 } else {
1719
1722 }
1723
1725 }
1726
1729
1739
1741 orig_ls =
c->last_stripe;
1742 else
1743 orig_ls = 0;
1744
1747
1752 }
1753
1754 if (file_read) {
1756
1758 ERR(
"out of memory\n");
1761 }
1762 } else
1764
1766 context.startoffstripe = startoffstripe;
1768
1771
1774
1776 if (!master_mdl) {
1777 ERR(
"out of memory\n");
1780 }
1781
1783
1789
1791 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
1794 }
1795
1797
1799 if (!stripes) {
1800 ERR(
"out of memory\n");
1805 }
1806
1808
1811 bool stripeset = false;
1812
1813 if (startoffstripe >
i)
1815 else if (startoffstripe ==
i)
1816 sstart = startoff;
1817 else
1819
1820 if (endoffstripe >
i)
1822 else if (endoffstripe ==
i)
1824 else
1826
1829 context.stripes[
i+
j].stripestart = sstart;
1832
1833 if (sstart !=
send) {
1835
1837 ERR(
"IoAllocateMdl failed\n");
1842 }
1843 }
1844
1845 stripeset = true;
1846 } else
1848 }
1849
1850 if (!stripeset) {
1853 context.stripes[
i+
j].stripestart = sstart;
1857
1858 if (sstart !=
send) {
1860
1862 ERR(
"IoAllocateMdl failed\n");
1867 }
1868 }
1869
1870 stripeset = true;
1871 break;
1872 }
1873 }
1874
1875 if (!stripeset) {
1876 ERR(
"could not find stripe to read\n");
1879 }
1880 }
1881 }
1882
1884 if (!stripeoff) {
1885 ERR(
"out of memory\n");
1890 }
1891
1893
1898
1902
1904
1905 stripeoff[
stripe] += readlen;
1907 }
else if (
length - pos < ci->stripe_length) {
1909
1911 } else {
1913
1916 }
1917
1919 }
1920
1923
1928
1930 orig_ls =
i =
c->last_stripe;
1931 else
1933
1936
1938 ERR(
"no devices available to service request\n");
1941 }
1942 }
1943
1946
1949
1952
1954 ERR(
"out of memory\n");
1957 }
1958
1961 ERR(
"IoAllocateMdl failed\n");
1964 }
1965
1967 } else {
1969
1971 ERR(
"IoAllocateMdl failed\n");
1974 }
1975
1977
1983
1985 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
1987 }
1988 }
1995 bool need_dummy = false;
1996
1999
2000 if (file_read) {
2002
2004 ERR(
"out of memory\n");
2007 }
2008 } else
2010
2012 if (!master_mdl) {
2013 ERR(
"out of memory\n");
2016 }
2017
2019
2025
2027 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
2030 }
2031
2033
2037
2041
2044 if (
i == startoffstripe) {
2046
2049
2051
2053 break;
2054 } else {
2056
2059
2061
2063 break;
2064 }
2065
2068 }
2069
2071 break;
2072
2073 for (
i = 0;
i < startoffstripe;
i++) {
2075
2077 }
2078
2080
2083
2086 }
2087
2089 need_dummy = true;
2090 }
2094 }
2095
2097 need_dummy = true;
2098 } else {
2100
2103 if (endoffstripe ==
i) {
2105 break;
2106 }
else if (endoffstripe >
i)
2108
2111 }
2112
2113 break;
2114 }
2115 }
2116
2120 false,
false,
NULL);
2121
2123 ERR(
"IoAllocateMdl failed\n");
2128 }
2129 }
2130 }
2131
2132 if (need_dummy) {
2134 if (!dummypage) {
2135 ERR(
"out of memory\n");
2140 }
2141
2143 if (!dummy_mdl) {
2144 ERR(
"IoAllocateMdl failed\n");
2149 }
2150
2152
2154 }
2155
2157 if (!stripeoff) {
2158 ERR(
"out of memory\n");
2163 }
2164
2166
2168
2171
2173
2178
2180
2182
2183 stripeoff[
stripe] = readlen;
2185
2187
2191
2192 if (readlen == 0)
2193 break;
2194
2196
2197 stripeoff[
stripe] = readlen;
2199
2201 }
2205
2208
2210
2213
2215 }
2216
2218
2222 }
2223 } else {
2226
2230
2231 if (readlen == 0)
2232 break;
2233
2235
2236 stripeoff[
stripe] += readlen;
2238
2240 }
2241 }
2242 }
2243
2246
2254 bool need_dummy = false;
2255
2258
2259 if (file_read) {
2261
2263 ERR(
"out of memory\n");
2266 }
2267 } else
2269
2271 if (!master_mdl) {
2272 ERR(
"out of memory\n");
2275 }
2276
2278
2284
2286 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
2289 }
2290
2292
2296
2300
2303 if (
i == startoffstripe) {
2305
2308
2310
2312 break;
2313 } else {
2315
2318
2320
2322 break;
2323 }
2324
2327 }
2328
2330 break;
2331
2332 for (
i = 0;
i < startoffstripe;
i++) {
2334
2336 }
2337
2339
2342
2345
2348 }
2349
2351 need_dummy = true;
2352 }
2356 }
2357
2359 need_dummy = true;
2360 } else {
2362
2365 if (endoffstripe ==
i) {
2367 break;
2368 }
else if (endoffstripe >
i)
2370
2373 }
2374
2375 break;
2376 }
2377 }
2378
2382
2384 ERR(
"IoAllocateMdl failed\n");
2389 }
2390 }
2391 }
2392
2393 if (need_dummy) {
2395 if (!dummypage) {
2396 ERR(
"out of memory\n");
2401 }
2402
2404 if (!dummy_mdl) {
2405 ERR(
"IoAllocateMdl failed\n");
2410 }
2411
2413
2415 }
2416
2418 if (!stripeoff) {
2419 ERR(
"out of memory\n");
2424 }
2425
2427
2429
2432
2434
2439
2441
2443
2444 stripeoff[
stripe] = readlen;
2446
2448
2452
2453 if (readlen == 0)
2454 break;
2455
2457
2458 stripeoff[
stripe] = readlen;
2460
2462 }
2467
2468 while (
stripe != parity1) {
2470
2472
2475
2477 }
2478
2480
2484 }
2485
2487
2491 }
2492 } else {
2495
2499
2500 if (readlen == 0)
2501 break;
2502
2504
2505 stripeoff[
stripe] += readlen;
2507
2509 }
2510 }
2511 }
2512
2515
2517 }
2518
2520
2525
2527 missing_devices++;
2528 }
2529 }
2530
2531 if (missing_devices > allowed_missing) {
2532 ERR(
"not enough devices to service request (%u missing)\n", missing_devices);
2535 }
2536
2539
2542
2545 }
2546
2549
2551 ERR(
"IoAllocateIrp failed\n");
2554 }
2555 } else {
2557
2559 ERR(
"IoMakeAssociatedIrp failed\n");
2562 }
2563 }
2564
2569
2572 if (!
context.stripes[
i].Irp->AssociatedIrp.SystemBuffer) {
2573 ERR(
"out of memory\n");
2576 }
2577
2579
2583 else
2585
2588
2590
2592
2594
2596 }
2597 }
2598
2599 need_to_wait = false;
2603 need_to_wait = true;
2604 }
2605 }
2606
2607 if (need_to_wait)
2609
2612
2613
2614
2619 }
2620 }
2621
2625 ERR(
"read_data_raid0 returned %08lx\n",
Status);
2626
2627 if (file_read)
2629
2631 }
2632
2633 if (file_read) {
2636 }
2639
2641 ERR(
"read_data_raid10 returned %08lx\n",
Status);
2642
2643 if (file_read)
2645
2647 }
2648
2649 if (file_read) {
2652 }
2656 ERR(
"read_data_dup returned %08lx\n",
Status);
2657
2658 if (file_read)
2660
2662 }
2663
2664 if (file_read) {
2667 }
2669 Status =
read_data_raid5(
Vcb, file_read ?
context.va :
buf,
addr,
length, &
context, ci,
devices,
offset,
generation,
c, missing_devices > 0 ?
true :
false);
2671 ERR(
"read_data_raid5 returned %08lx\n",
Status);
2672
2673 if (file_read)
2675
2677 }
2678
2679 if (file_read) {
2682 }
2684 Status =
read_data_raid6(
Vcb, file_read ?
context.va :
buf,
addr,
length, &
context, ci,
devices,
offset,
generation,
c, missing_devices > 0 ?
true :
false);
2686 ERR(
"read_data_raid6 returned %08lx\n",
Status);
2687
2688 if (file_read)
2690
2692 }
2693
2694 if (file_read) {
2697 }
2698 }
2699
2703
2704 if (dummy_mdl)
2706
2707 if (dummypage)
2709
2714
2716 }
2717
2720 }
2721
2723
2724 if (!
Vcb->log_to_phys_loaded)
2726
2728}
_Post_satisfies_ static stripe __inline void get_raid0_offset(_In_ uint64_t off, _In_ uint64_t stripe_length, _In_ uint16_t num_stripes, _Out_ uint64_t *stripeoff, _Out_ uint16_t *stripe)
NTSTATUS NTSTATUS NTSTATUS NTSTATUS NTSTATUS chunk * get_chunk_from_address(device_extension *Vcb, uint64_t address) __attribute__((nonnull(1)))
NTSTATUS bool void get_raid56_lock_range(chunk *c, uint64_t address, uint64_t length, uint64_t *lockaddr, uint64_t *locklen) __attribute__((nonnull(1
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
void chunk_lock_range(_In_ device_extension *Vcb, _In_ chunk *c, _In_ uint64_t start, _In_ uint64_t length)
void chunk_unlock_range(_In_ device_extension *Vcb, _In_ chunk *c, _In_ uint64_t start, _In_ uint64_t length)
_In_ uint64_t _In_ uint64_t _In_ uint64_t generation
_Ret_maybenull_ device * find_device_from_uuid(_In_ device_extension *Vcb, _In_ BTRFS_UUID *uuid)
#define BLOCK_FLAG_RAID1C4
#define BLOCK_FLAG_RAID1C3
static struct all_devices * devices
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
#define KeInitializeEvent(pEvt, foo, foo2)
static NTSTATUS read_data_raid6(device_extension *Vcb, uint8_t *buf, uint64_t addr, uint32_t length, read_data_context *context, CHUNK_ITEM *ci, device **devices, uint64_t offset, uint64_t generation, chunk *c, bool degraded)
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
static NTSTATUS read_data_raid0(device_extension *Vcb, uint8_t *buf, uint64_t addr, uint32_t length, read_data_context *context, CHUNK_ITEM *ci, device **devices, uint64_t generation, uint64_t offset)
static NTSTATUS read_data_raid5(device_extension *Vcb, uint8_t *buf, uint64_t addr, uint32_t length, read_data_context *context, CHUNK_ITEM *ci, device **devices, uint64_t offset, uint64_t generation, chunk *c, bool degraded)
static NTSTATUS read_data_dup(device_extension *Vcb, uint8_t *buf, uint64_t addr, read_data_context *context, CHUNK_ITEM *ci, device **devices, uint64_t generation)
static NTSTATUS read_data_raid10(device_extension *Vcb, uint8_t *buf, uint64_t addr, uint32_t length, read_data_context *context, CHUNK_ITEM *ci, device **devices, uint64_t generation, uint64_t offset)
GLuint GLuint GLsizei GLenum type
GLenum const GLvoid * addr
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
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
VOID NTAPI IoFreeIrp(IN PIRP Irp)
PIRP NTAPI IoMakeAssociatedIrp(IN PIRP Irp, IN CCHAR StackSize)
#define STATUS_UNEXPECTED_IO_ERROR
#define STATUS_DEVICE_NOT_READY
#define BLOCK_FLAG_DUPLICATE
#define BLOCK_FLAG_RAID10
struct _LIST_ENTRY * Flink
#define CONTAINING_RECORD(address, type, field)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
#define IoIsErrorUserInduced(Status)
#define IRP_DEALLOCATE_BUFFER
#define IRP_INPUT_OPERATION
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)