Sample Code
windows driver samples/ cdfs file system driver/ C++/ strucsup.c/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 | /*++ Copyright (c) 1989-2000 Microsoft Corporation Module Name: StrucSup.c Abstract: This module implements the Cdfs in-memory data structure manipulation routines --*/ #include "CdProcs.h" // // The Bug check file id for this module // #define BugCheckFileId (CDFS_BUG_CHECK_STRUCSUP) // // Local macros // // // PFCB // CdAllocateFcbData ( // _In_ PIRP_CONTEXT IrpContext // ); // // VOID // CdDeallocateFcbData ( // _In_ PIRP_CONTEXT IrpContext, // _Inout_ PFCB Fcb // ); // // PFCB // CdAllocateFcbIndex ( // _In_ PIRP_CONTEXT IrpContext // ); // // VOID // CdDeallocateFcbIndex ( // _In_ PIRP_CONTEXT IrpContext, // _Inout_ PFCB Fcb // ); // // PFCB_NONPAGED // CdAllocateFcbNonpaged ( // _In_ PIRP_CONTEXT IrpContext // ); // // VOID // CdDeallocateFcbNonpaged ( // _In_ PIRP_CONTEXT IrpContext, // _Inout_ PFCB_NONPAGED FcbNonpaged // ); // // PCCB // CdAllocateCcb ( // _In_ PIRP_CONTEXT IrpContext // ); // // VOID // CdDeallocateCcb ( // _In_ PIRP_CONTEXT IrpContext, // _Inout_ PCCB Ccb // ); // #define CdAllocateFcbData(IC) \ FsRtlAllocatePoolWithTag( CdPagedPool, SIZEOF_FCB_DATA, TAG_FCB_DATA ) #define CdDeallocateFcbData(IC,F) \ CdFreePool( &(F) ) #define CdAllocateFcbIndex(IC) \ FsRtlAllocatePoolWithTag( CdPagedPool, SIZEOF_FCB_INDEX, TAG_FCB_INDEX ) #define CdDeallocateFcbIndex(IC,F) \ CdFreePool( &(F) ) #define CdAllocateFcbNonpaged(IC) \ ExAllocatePoolWithTag( CdNonPagedPool, sizeof ( FCB_NONPAGED ), TAG_FCB_NONPAGED ) #define CdDeallocateFcbNonpaged(IC,FNP) \ CdFreePool( &(FNP) ) #define CdAllocateCcb(IC) \ FsRtlAllocatePoolWithTag( CdPagedPool, sizeof ( CCB ), TAG_CCB ) #define CdDeallocateCcb(IC,C) \ CdFreePool( &(C) ) // // Local structures // typedef struct _FCB_TABLE_ELEMENT { FILE_ID FileId; PFCB Fcb; } FCB_TABLE_ELEMENT, *PFCB_TABLE_ELEMENT; // // Local macros // // // VOID // CdInsertFcbTable ( // _In_ PIRP_CONTEXT IrpContext, // _In_ PFCB Fcb // ); // // VOID // CdDeleteFcbTable ( // _In_ PIRP_CONTEXT IrpContext, // _In_ PFCB Fcb // ); // #define CdInsertFcbTable(IC,F) { \ FCB_TABLE_ELEMENT _Key; \ _Key.Fcb = (F); \ _Key.FileId = (F)->FileId; \ RtlInsertElementGenericTable( &(F)->Vcb->FcbTable, \ &_Key, \ sizeof ( FCB_TABLE_ELEMENT ), \ NULL ); \ } #define CdDeleteFcbTable(IC,F) { \ FCB_TABLE_ELEMENT _Key; \ _Key.FileId = (F)->FileId; \ RtlDeleteElementGenericTable( &(F)->Vcb->FcbTable, &_Key ); \ } // // Local support routines // VOID CdDeleteFcb ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb ); PFCB_NONPAGED CdCreateFcbNonpaged ( _In_ PIRP_CONTEXT IrpContext ); VOID CdDeleteFcbNonpaged ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB_NONPAGED FcbNonpaged ); // Inform prefast that this is a compare routine. RTL_GENERIC_COMPARE_ROUTINE CdFcbTableCompare; RTL_GENERIC_COMPARE_RESULTS CdFcbTableCompare ( _In_ PRTL_GENERIC_TABLE FcbTable, _In_ PVOID Fid1, _In_ PVOID Fid2 ); // Inform prefast that this is an alloc reoutine. RTL_GENERIC_ALLOCATE_ROUTINE CdAllocateFcbTable; PVOID CdAllocateFcbTable ( _In_ PRTL_GENERIC_TABLE FcbTable, _In_ CLONG ByteSize ); // Inform prefast that this is a free reoutine. RTL_GENERIC_FREE_ROUTINE CdDeallocateFcbTable; VOID CdDeallocateFcbTable ( _In_ PRTL_GENERIC_TABLE FcbTable, _In_ __drv_freesMem(Mem) _Post_invalid_ PVOID Buffer ); ULONG CdTocSerial ( _In_ PIRP_CONTEXT IrpContext, _In_ PCDROM_TOC_LARGE CdromToc ); #ifdef ALLOC_PRAGMA #pragma alloc_text(PAGE, CdAllocateFcbTable) #pragma alloc_text(PAGE, CdCleanupIrpContext) #pragma alloc_text(PAGE, CdCreateCcb) #pragma alloc_text(PAGE, CdCreateFcb) #pragma alloc_text(PAGE, CdCreateFcbNonpaged) #pragma alloc_text(PAGE, CdCreateFileLock) #pragma alloc_text(PAGE, CdCreateIrpContext) #pragma alloc_text(PAGE, CdDeallocateFcbTable) #pragma alloc_text(PAGE, CdDeleteCcb) #pragma alloc_text(PAGE, CdDeleteFcb) #pragma alloc_text(PAGE, CdDeleteFcbNonpaged) #pragma alloc_text(PAGE, CdDeleteFileLock) #pragma alloc_text(PAGE, CdDeleteVcb) #pragma alloc_text(PAGE, CdFcbTableCompare) #pragma alloc_text(PAGE, CdGetNextFcb) #pragma alloc_text(PAGE, CdInitializeFcbFromFileContext) #pragma alloc_text(PAGE, CdInitializeFcbFromPathEntry) #pragma alloc_text(PAGE, CdInitializeStackIrpContext) #pragma alloc_text(PAGE, CdInitializeVcb) #pragma alloc_text(PAGE, CdLookupFcbTable) #pragma alloc_text(PAGE, CdProcessToc) #pragma alloc_text(PAGE, CdTeardownStructures) #pragma alloc_text(PAGE, CdTocSerial) #pragma alloc_text(PAGE, CdUpdateVcbFromVolDescriptor) #endif // // Some static names for volume streams // UNICODE_STRING CdInternalStreamNames[] = { { 24, 24, L "$PATH_TABLE$" }, { 2, 2, L "\\" } };
VOID CdInitializeVcb ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_ __drv_aliasesMem PDEVICE_OBJECT TargetDeviceObject, _In_ __drv_aliasesMem PVPB Vpb, _In_ __drv_aliasesMem PCDROM_TOC_LARGE CdromToc, _In_ ULONG TocLength, _In_ ULONG TocTrackCount, _In_ ULONG TocDiskFlags, _In_ ULONG BlockFactor, _In_ ULONG MediaChangeCount ) /*++ Routine Description: This routine initializes and inserts a new Vcb record into the in-memory data structure. The Vcb record "hangs" off the end of the Volume device object and must be allocated by our caller. Arguments: Vcb - Supplies the address of the Vcb record being initialized. TargetDeviceObject - Supplies the address of the target device object to associate with the Vcb record. Vpb - Supplies the address of the Vpb to associate with the Vcb record. CdromToc - Buffer to hold table of contents. NULL if TOC command not supported. TocLength - Byte count length of TOC. We use this as the TOC length to return on a user query. TocTrackCount - Count of tracks in TOC. Used to create pseudo files for audio disks. TocDiskFlags - Flag field to indicate the type of tracks on the disk. BlockFactor - Used to decode any multi-session information. MediaChangeCount - Initial media change count of the target device Return Value: None. --*/ { PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); // // We start by first zeroing out all of the VCB, this will guarantee // that any stale data is wiped clean. // RtlZeroMemory( Vcb, sizeof ( VCB )); // // Set the proper node type code and node byte size. // Vcb->NodeTypeCode = CDFS_NTC_VCB; Vcb->NodeByteSize = sizeof ( VCB ); // // Initialize the DirNotify structs. FsRtlNotifyInitializeSync can raise. // InitializeListHead( &Vcb->DirNotifyList ); FsRtlNotifyInitializeSync( &Vcb->NotifySync ); // // Pick up a VPB right now so we know we can pull this filesystem stack // off of the storage stack on demand. This can raise - if it does, // uninitialize the notify structures before returning. // try { Vcb->SwapVpb = FsRtlAllocatePoolWithTag( CdNonPagedPool, sizeof ( VPB ), TAG_VPB ); } finally { if (AbnormalTermination()) { FsRtlNotifyUninitializeSync( &Vcb->NotifySync ); } } // // Nothing beyond this point should raise. // RtlZeroMemory( Vcb->SwapVpb, sizeof ( VPB ) ); // // Initialize the resource variable for the Vcb and files. // ExInitializeResourceLite( &Vcb->VcbResource ); ExInitializeResourceLite( &Vcb->FileResource ); ExInitializeFastMutex( &Vcb->VcbMutex ); // // Insert this Vcb record on the CdData.VcbQueue. // InsertHeadList( &CdData.VcbQueue, &Vcb->VcbLinks ); // // Set the Target Device Object and Vpb fields, referencing the // Target device for the mount. // ObReferenceObject( TargetDeviceObject ); Vcb->TargetDeviceObject = TargetDeviceObject; Vcb->Vpb = Vpb; // // Set the removable media flag based on the real device's // characteristics // if (FlagOn( Vpb->RealDevice->Characteristics, FILE_REMOVABLE_MEDIA )) { SetFlag( Vcb->VcbState, VCB_STATE_REMOVABLE_MEDIA ); } // // Initialize the generic Fcb Table. // RtlInitializeGenericTable( &Vcb->FcbTable, (PRTL_GENERIC_COMPARE_ROUTINE) CdFcbTableCompare, (PRTL_GENERIC_ALLOCATE_ROUTINE) CdAllocateFcbTable, (PRTL_GENERIC_FREE_ROUTINE) CdDeallocateFcbTable, NULL ); // // Show that we have a mount in progress. // CdUpdateVcbCondition( Vcb, VcbMountInProgress); // // Refererence the Vcb for two reasons. The first is a reference // that prevents the Vcb from going away on the last close unless // dismount has already occurred. The second is to make sure // we don't go into the dismount path on any error during mount // until we get to the Mount cleanup. // Vcb->VcbReference = 1 + CDFS_RESIDUAL_REFERENCE; // // Update the TOC information in the Vcb. // Vcb->CdromToc = CdromToc; Vcb->TocLength = TocLength; Vcb->TrackCount = TocTrackCount; Vcb->DiskFlags = TocDiskFlags; // // If this disk contains audio tracks only then set the audio flag. // if (TocDiskFlags == CDROM_DISK_AUDIO_TRACK) { SetFlag( Vcb->VcbState, VCB_STATE_AUDIO_DISK | VCB_STATE_CDXA ); } // // Set the block factor. // Vcb->BlockFactor = BlockFactor; // // Set the media change count on the device // CdUpdateMediaChangeCount( Vcb, MediaChangeCount); }
VOID CdUpdateVcbFromVolDescriptor ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_reads_bytes_opt_(SECTOR_SIZE) PCHAR RawIsoVd ) /*++ Routine Description: This routine is called to perform the final initialization of a Vcb from the volume descriptor on the disk. Arguments: Vcb - Vcb for the volume being mounted. We have already set the flags for the type of descriptor. RawIsoVd - If specified this is the volume descriptor to use to mount the volume. Not specified for a raw disk. Return Value: None --*/ { ULONG StartingBlock; ULONG ByteCount; LONGLONG FileId = 0; PRAW_DIRENT RawDirent; PATH_ENTRY PathEntry; PCD_MCB_ENTRY McbEntry; BOOLEAN UnlockVcb = FALSE; PAGED_CODE(); // // Use a try-finally to facilitate cleanup. // try { // // Copy the block size and compute the various block masks. // Block size must not be larger than the sector size. We will // use a default of the CD physical sector size if we are not // on a data-full disc. // // This must always be set. // Vcb->BlockSize = ( ARGUMENT_PRESENT( RawIsoVd ) ? CdRvdBlkSz( RawIsoVd, Vcb->VcbState ) : SECTOR_SIZE ); // // We no longer accept media where blocksize != sector size. // if (Vcb->BlockSize != SECTOR_SIZE) { CdRaiseStatus( IrpContext, STATUS_DISK_CORRUPT_ERROR ); } Vcb->BlocksPerSector = SECTOR_SIZE / Vcb->BlockSize; Vcb->BlockMask = Vcb->BlockSize - 1; Vcb->BlockInverseMask = ~Vcb->BlockMask; Vcb->BlockToSectorShift = 0; Vcb->BlockToByteShift = SECTOR_SHIFT; // // If there is a volume descriptor then do the internal Fcb's and // other Vcb fields. // if (ARGUMENT_PRESENT( RawIsoVd )) { // // Create the path table Fcb and refererence it and the Vcb. // CdLockVcb( IrpContext, Vcb ); UnlockVcb = TRUE; Vcb->PathTableFcb = CdCreateFcb( IrpContext, *((PFILE_ID) &FileId), CDFS_NTC_FCB_PATH_TABLE, NULL ); CdIncrementReferenceCounts( IrpContext, Vcb->PathTableFcb, 1, 1 ); CdUnlockVcb( IrpContext, Vcb ); UnlockVcb = FALSE; // // Compute the stream offset and size of this path table. // StartingBlock = CdRvdPtLoc( RawIsoVd, Vcb->VcbState ); ByteCount = CdRvdPtSz( RawIsoVd, Vcb->VcbState ); Vcb->PathTableFcb->StreamOffset = BytesFromBlocks( Vcb, SectorBlockOffset( Vcb, StartingBlock )); Vcb->PathTableFcb->FileSize.QuadPart = ( LONGLONG ) (Vcb->PathTableFcb->StreamOffset + ByteCount); Vcb->PathTableFcb->ValidDataLength.QuadPart = Vcb->PathTableFcb->FileSize.QuadPart; Vcb->PathTableFcb->AllocationSize.QuadPart = LlSectorAlign( Vcb->PathTableFcb->FileSize.QuadPart ); // // Now add the mapping information. // CdLockFcb( IrpContext, Vcb->PathTableFcb ); CdAddInitialAllocation( IrpContext, Vcb->PathTableFcb, StartingBlock, Vcb->PathTableFcb->AllocationSize.QuadPart ); CdUnlockFcb( IrpContext, Vcb->PathTableFcb ); // // Point to the file resource. // Vcb->PathTableFcb->Resource = &Vcb->FileResource; // // Mark the Fcb as initialized and create the stream file for this. // SetFlag( Vcb->PathTableFcb->FcbState, FCB_STATE_INITIALIZED ); CdCreateInternalStream( IrpContext, Vcb, Vcb->PathTableFcb, &CdInternalStreamNames[0]); // // Create the root index and reference it in the Vcb. // CdLockVcb( IrpContext, Vcb ); UnlockVcb = TRUE; Vcb->RootIndexFcb = CdCreateFcb( IrpContext, *((PFILE_ID) &FileId), CDFS_NTC_FCB_INDEX, NULL ); CdIncrementReferenceCounts( IrpContext, Vcb->RootIndexFcb, 1, 1 ); CdUnlockVcb( IrpContext, Vcb ); UnlockVcb = FALSE; // // Create the File id by hand for this Fcb. // CdSetFidPathTableOffset( Vcb->RootIndexFcb->FileId, Vcb->PathTableFcb->StreamOffset ); CdFidSetDirectory( Vcb->RootIndexFcb->FileId ); // // Create a pseudo path table entry so we can call the initialization // routine for the directory. // RawDirent = (PRAW_DIRENT) CdRvdDirent( RawIsoVd, Vcb->VcbState ); CopyUchar4( &PathEntry.DiskOffset, RawDirent->FileLoc ); PathEntry.DiskOffset += RawDirent->XarLen; PathEntry.Ordinal = 1; PathEntry.PathTableOffset = Vcb->PathTableFcb->StreamOffset; CdInitializeFcbFromPathEntry( IrpContext, Vcb->RootIndexFcb, NULL, &PathEntry ); // // Create the stream file for the root directory. // CdCreateInternalStream( IrpContext, Vcb, Vcb->RootIndexFcb, &CdInternalStreamNames[1] ); // // Now do the volume dasd Fcb. Create this and reference it in the // Vcb. // CdLockVcb( IrpContext, Vcb ); UnlockVcb = TRUE; Vcb->VolumeDasdFcb = CdCreateFcb( IrpContext, *((PFILE_ID) &FileId), CDFS_NTC_FCB_DATA, NULL ); CdIncrementReferenceCounts( IrpContext, Vcb->VolumeDasdFcb, 1, 1 ); CdUnlockVcb( IrpContext, Vcb ); UnlockVcb = FALSE; // // The file size is the full disk. // StartingBlock = CdRvdVolSz( RawIsoVd, Vcb->VcbState ); Vcb->VolumeDasdFcb->FileSize.QuadPart = LlBytesFromBlocks( Vcb, StartingBlock ); Vcb->VolumeDasdFcb->AllocationSize.QuadPart = Vcb->VolumeDasdFcb->ValidDataLength.QuadPart = Vcb->VolumeDasdFcb->FileSize.QuadPart; // // Now add the extent representing the volume 'by hand'. // CdLockFcb( IrpContext, Vcb->VolumeDasdFcb ); McbEntry = Vcb->VolumeDasdFcb->Mcb.McbArray; McbEntry->FileOffset = McbEntry->DiskOffset = 0; McbEntry->ByteCount = Vcb->VolumeDasdFcb->AllocationSize.QuadPart; McbEntry->DataBlockByteCount = McbEntry->TotalBlockByteCount = McbEntry->ByteCount; Vcb->VolumeDasdFcb->Mcb.CurrentEntryCount = 1; CdUnlockFcb( IrpContext, Vcb->VolumeDasdFcb ); // // Point to the file resource. // Vcb->VolumeDasdFcb->Resource = &Vcb->FileResource; Vcb->VolumeDasdFcb->FileAttributes = FILE_ATTRIBUTE_READONLY; // // Mark the Fcb as initialized. // SetFlag( Vcb->VolumeDasdFcb->FcbState, FCB_STATE_INITIALIZED ); // // Check and see if this is an XA disk. // if (FlagOn( Vcb->VcbState, VCB_STATE_ISO | VCB_STATE_JOLIET) && RtlEqualMemory( CdXaId, Add2Ptr( RawIsoVd, 0x400, PCHAR ), 8 )) { SetFlag( Vcb->VcbState, VCB_STATE_CDXA ); } // // If this is a music disk then we want to mock this disk to make it // look like ISO disk. We will create a pseudo root directory in // that case. // } else if (FlagOn( Vcb->VcbState, VCB_STATE_AUDIO_DISK )) { ULONG RootDirectorySize; // // Create the path table Fcb and refererence it and the Vcb. // CdLockVcb( IrpContext, Vcb ); UnlockVcb = TRUE; Vcb->PathTableFcb = CdCreateFcb( IrpContext, *((PFILE_ID) &FileId), CDFS_NTC_FCB_PATH_TABLE, NULL ); CdIncrementReferenceCounts( IrpContext, Vcb->PathTableFcb, 1, 1 ); CdUnlockVcb( IrpContext, Vcb ); UnlockVcb = FALSE; // // We only create a pseudo entry for the root. // Vcb->PathTableFcb->FileSize.QuadPart = ( LONGLONG ) (FIELD_OFFSET( RAW_PATH_ISO, DirId ) + 2); Vcb->PathTableFcb->ValidDataLength.QuadPart = Vcb->PathTableFcb->FileSize.QuadPart; Vcb->PathTableFcb->AllocationSize.QuadPart = LlSectorAlign( Vcb->PathTableFcb->FileSize.QuadPart ); // // Point to the file resource. // Vcb->PathTableFcb->Resource = &Vcb->FileResource; // // Mark the Fcb as initialized and create the stream file for this. // SetFlag( Vcb->PathTableFcb->FcbState, FCB_STATE_INITIALIZED ); CdCreateInternalStream( IrpContext, Vcb, Vcb->PathTableFcb, &CdInternalStreamNames[0]); // // Create the root index and reference it in the Vcb. // CdLockVcb( IrpContext, Vcb ); UnlockVcb = TRUE; Vcb->RootIndexFcb = CdCreateFcb( IrpContext, *((PFILE_ID) &FileId), CDFS_NTC_FCB_INDEX, NULL ); CdIncrementReferenceCounts( IrpContext, Vcb->RootIndexFcb, 1, 1 ); CdUnlockVcb( IrpContext, Vcb ); UnlockVcb = FALSE; // // Create the File id by hand for this Fcb. // CdSetFidPathTableOffset( Vcb->RootIndexFcb->FileId, Vcb->PathTableFcb->StreamOffset ); CdFidSetDirectory( Vcb->RootIndexFcb->FileId ); // // Create a pseudo path table entry so we can call the initialization // routine for the directory. // RtlZeroMemory( &PathEntry, sizeof ( PATH_ENTRY )); PathEntry.Ordinal = 1; PathEntry.PathTableOffset = Vcb->PathTableFcb->StreamOffset; CdInitializeFcbFromPathEntry( IrpContext, Vcb->RootIndexFcb, NULL, &PathEntry ); // // Set the sizes by hand for this Fcb. It should have an entry for each track plus an // entry for the root and parent. // RootDirectorySize = (Vcb->TrackCount + 2) * CdAudioDirentSize; RootDirectorySize = SectorAlign( RootDirectorySize ); Vcb->RootIndexFcb->AllocationSize.QuadPart = Vcb->RootIndexFcb->ValidDataLength.QuadPart = Vcb->RootIndexFcb->FileSize.QuadPart = RootDirectorySize; SetFlag( Vcb->RootIndexFcb->FcbState, FCB_STATE_INITIALIZED ); // // Create the stream file for the root directory. // CdCreateInternalStream( IrpContext, Vcb, Vcb->RootIndexFcb, &CdInternalStreamNames[1] ); // // Now do the volume dasd Fcb. Create this and reference it in the // Vcb. // CdLockVcb( IrpContext, Vcb ); UnlockVcb = TRUE; Vcb->VolumeDasdFcb = CdCreateFcb( IrpContext, *((PFILE_ID) &FileId), CDFS_NTC_FCB_DATA, NULL ); CdIncrementReferenceCounts( IrpContext, Vcb->VolumeDasdFcb, 1, 1 ); CdUnlockVcb( IrpContext, Vcb ); UnlockVcb = FALSE; // // We won't allow raw reads on this Fcb so leave the size at // zero. // // // Point to the file resource. // Vcb->VolumeDasdFcb->Resource = &Vcb->FileResource; Vcb->VolumeDasdFcb->FileAttributes = FILE_ATTRIBUTE_READONLY; // // Mark the Fcb as initialized. // SetFlag( Vcb->VolumeDasdFcb->FcbState, FCB_STATE_INITIALIZED ); // // We will store a hard-coded name in the Vpb and use the toc as // the serial number. // Vcb->Vpb->VolumeLabelLength = CdAudioLabelLength; RtlCopyMemory( Vcb->Vpb->VolumeLabel, CdAudioLabel, CdAudioLabelLength ); // // Find the serial number for the audio disk. // Vcb->Vpb->SerialNumber = CdTocSerial( IrpContext, Vcb->CdromToc ); // // Set the ISO bit so we know how to treat the names. // SetFlag( Vcb->VcbState, VCB_STATE_ISO ); } } finally { if (UnlockVcb) { CdUnlockVcb( IrpContext, Vcb ); } } }
VOID CdDeleteVcb ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb ) /*++ Routine Description: This routine is called to delete a Vcb which failed mount or has been dismounted. The dismount code should have already removed all of the open Fcb's. We do nothing here but clean up other auxilary structures. Arguments: Vcb - Vcb to delete. Return Value: None --*/ { PAGED_CODE(); ASSERT_EXCLUSIVE_CDDATA; ASSERT_EXCLUSIVE_VCB( Vcb ); UNREFERENCED_PARAMETER( IrpContext ); // // Chuck the backpocket Vpb we kept just in case. // CdFreePool( &Vcb->SwapVpb ); // // If there is a Vpb then we must delete it ourselves. // CdFreePool( &Vcb->Vpb ); // // Dereference our target if we haven't already done so. // if (Vcb->TargetDeviceObject != NULL) { ObDereferenceObject( Vcb->TargetDeviceObject ); } // // Delete the XA Sector and sector cache buffer if allocated. // CdFreePool( &Vcb->XASector ); CdFreePool( &Vcb->SectorCacheBuffer); if (Vcb->SectorCacheIrp != NULL) { IoFreeIrp( Vcb->SectorCacheIrp); Vcb->SectorCacheIrp = NULL; ExDeleteResourceLite( &Vcb->SectorCacheResource); } // // Remove this entry from the global queue. // RemoveEntryList( &Vcb->VcbLinks ); // // Delete the Vcb and File resources. // ExDeleteResourceLite( &Vcb->VcbResource ); ExDeleteResourceLite( &Vcb->FileResource ); // // Delete the TOC if present. // CdFreePool( &Vcb->CdromToc ); // // Uninitialize the notify structures. // if (Vcb->NotifySync != NULL) { FsRtlNotifyUninitializeSync( &Vcb->NotifySync ); } // // Now delete the volume device object. // #pragma prefast( suppress: __WARNING_BUFFER_UNDERFLOW, "This is ok, the Vcb is embedded in our volume device object, and that is what we are really deleting." ) IoDeleteDevice( (PDEVICE_OBJECT) CONTAINING_RECORD( Vcb, VOLUME_DEVICE_OBJECT, Vcb )); return ; }
PFCB CdCreateFcb ( _In_ PIRP_CONTEXT IrpContext, _In_ FILE_ID FileId, _In_ NODE_TYPE_CODE NodeTypeCode, _Out_opt_ PBOOLEAN FcbExisted ) /*++ Routine Description: This routine is called to find the Fcb for the given FileId. We will look this up first in the Fcb table and if not found we will create an Fcb. We don't initialize it or insert it into the FcbTable in this routine. This routine is called while the Vcb is locked. Arguments: FileId - This is the Id for the target Fcb. NodeTypeCode - Node type for this Fcb if we need to create. FcbExisted - If specified, we store whether the Fcb existed. Return Value: PFCB - The Fcb found in the table or created if needed. --*/ { PFCB NewFcb; BOOLEAN LocalFcbExisted; PAGED_CODE(); // // Use the local boolean if one was not passed in. // if (!ARGUMENT_PRESENT( FcbExisted )) { FcbExisted = &LocalFcbExisted; } // // Maybe this is already in the table. // NewFcb = CdLookupFcbTable( IrpContext, IrpContext->Vcb, FileId ); // // If not then create the Fcb is requested by our caller. // if (NewFcb == NULL) { // // Allocate and initialize the structure depending on the // type code. // switch (NodeTypeCode) { case CDFS_NTC_FCB_PATH_TABLE: case CDFS_NTC_FCB_INDEX: NewFcb = CdAllocateFcbIndex( IrpContext ); RtlZeroMemory( NewFcb, SIZEOF_FCB_INDEX ); NewFcb->NodeByteSize = SIZEOF_FCB_INDEX; InitializeListHead( &NewFcb->FcbQueue ); break ; case CDFS_NTC_FCB_DATA : NewFcb = CdAllocateFcbData( IrpContext ); RtlZeroMemory( NewFcb, SIZEOF_FCB_DATA ); NewFcb->NodeByteSize = SIZEOF_FCB_DATA; break ; default : #pragma prefast( suppress: __WARNING_USE_OTHER_FUNCTION, "This is a bug." ) CdBugCheck( 0, 0, 0 ); } // // Now do the common initialization. // NewFcb->NodeTypeCode = NodeTypeCode; NewFcb->Vcb = IrpContext->Vcb; NewFcb->FileId = FileId; CdInitializeMcb( IrpContext, NewFcb ); // // Now create the non-paged section object. // NewFcb->FcbNonpaged = CdCreateFcbNonpaged( IrpContext ); // // Deallocate the Fcb and raise if the allocation failed. // if (NewFcb->FcbNonpaged == NULL) { CdFreePool( &NewFcb ); CdRaiseStatus( IrpContext, STATUS_INSUFFICIENT_RESOURCES ); } *FcbExisted = FALSE; // // Initialize Advanced FCB Header fields // ExInitializeFastMutex( &NewFcb->FcbNonpaged->AdvancedFcbHeaderMutex ); FsRtlSetupAdvancedHeader( &NewFcb->Header, &NewFcb->FcbNonpaged->AdvancedFcbHeaderMutex ); if (NodeTypeCode == CDFS_NTC_FCB_DATA) { FsRtlInitializeOplock( CdGetFcbOplock(NewFcb) ); } } else { *FcbExisted = TRUE; } return NewFcb; }
VOID CdInitializeFcbFromPathEntry ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_opt_ PFCB ParentFcb, _In_ PPATH_ENTRY PathEntry ) /*++ Routine Description: This routine is called to initialize an Fcb for a directory from the path entry. Since we only have a starting point for the directory, not the length, we can only speculate on the sizes. The general initialization is performed in CdCreateFcb. Arguments: Fcb - Newly created Fcb for this stream. ParentFcb - Parent Fcb for this stream. It may not be present. PathEntry - PathEntry for this Fcb in the Path Table. Return Value: None --*/ { PAGED_CODE(); // // Fill in the Index specific fields of the Fcb. // Fcb->StreamOffset = BytesFromBlocks( Fcb->Vcb, SectorBlockOffset( Fcb->Vcb, PathEntry->DiskOffset )); Fcb->Ordinal = PathEntry->Ordinal; // // Initialize the common header in the Fcb. The node type is already // present. // Fcb->Resource = &Fcb->Vcb->FileResource; // // Always set the sizes to one sector until we read the self-entry. // Fcb->AllocationSize.QuadPart = Fcb->FileSize.QuadPart = Fcb->ValidDataLength.QuadPart = SECTOR_SIZE; CdAddInitialAllocation( IrpContext, Fcb, PathEntry->DiskOffset, SECTOR_SIZE ); // // State flags for this Fcb. // SetFlag( Fcb->FileAttributes, FILE_ATTRIBUTE_DIRECTORY ); // // Link into the other in-memory structures and into the Fcb table. // if (ParentFcb != NULL) { Fcb->ParentFcb = ParentFcb; InsertTailList( &ParentFcb->FcbQueue, &Fcb->FcbLinks ); CdIncrementReferenceCounts( IrpContext, ParentFcb, 1, 1 ); } CdInsertFcbTable( IrpContext, Fcb ); SetFlag( Fcb->FcbState, FCB_STATE_IN_FCB_TABLE ); return ; }
VOID CdInitializeFcbFromFileContext ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ PFCB ParentFcb, _In_ PFILE_ENUM_CONTEXT FileContext ) /*++ Routine Description: This routine is called to initialize an Fcb for a file from the file context. We have looked up all of the dirents for this stream and have the full file size. We will load the all of the allocation for the file into the Mcb now. The general initialization is performed in CdCreateFcb. Arguments: Fcb - Newly created Fcb for this stream. ParentFcb - Parent Fcb for this stream. FileContext - FileContext for the file. Return Value: None --*/ { PDIRENT ThisDirent = &FileContext->InitialDirent->Dirent; PCOMPOUND_DIRENT CurrentCompoundDirent; LONGLONG CurrentFileOffset; ULONG CurrentMcbEntryOffset; PAGED_CODE(); // // Use a try-finally to facilitate cleanup. // CdLockFcb( IrpContext, Fcb ); try { // // Initialize the common header in the Fcb. The node type is already // present. // Fcb->Resource = &IrpContext->Vcb->FileResource; // // Allocation occurs in block-sized units. // Fcb->FileSize.QuadPart = Fcb->ValidDataLength.QuadPart = FileContext->FileSize; Fcb->AllocationSize.QuadPart = LlBlockAlign( Fcb->Vcb, FileContext->FileSize ); // // Set the flags from the dirent. We always start with the read-only bit. // SetFlag( Fcb->FileAttributes, FILE_ATTRIBUTE_READONLY ); if (FlagOn( ThisDirent->DirentFlags, CD_ATTRIBUTE_HIDDEN )) { SetFlag( Fcb->FileAttributes, FILE_ATTRIBUTE_HIDDEN ); } // // Convert the time to NT time. // CdConvertCdTimeToNtTime( IrpContext, ThisDirent->CdTime, (PLARGE_INTEGER) &Fcb->CreationTime ); // // Set the flag indicating the type of extent. // if (ThisDirent->ExtentType != Form1Data) { if (ThisDirent->ExtentType == Mode2Form2Data) { SetFlag( Fcb->FcbState, FCB_STATE_MODE2FORM2_FILE ); } else { SetFlag( Fcb->FcbState, FCB_STATE_DA_FILE ); } Fcb->XAAttributes = ThisDirent->XAAttributes; Fcb->XAFileNumber = ThisDirent->XAFileNumber; } // // Read through all of the dirents for the file until we find the last // and add the allocation into the Mcb. // CurrentCompoundDirent = FileContext->InitialDirent; CurrentFileOffset = 0; CurrentMcbEntryOffset = 0; while (TRUE) { CdAddAllocationFromDirent( IrpContext, Fcb, CurrentMcbEntryOffset, CurrentFileOffset, &CurrentCompoundDirent->Dirent ); // // Break out if we are at the last dirent. // if (!FlagOn( CurrentCompoundDirent->Dirent.DirentFlags, CD_ATTRIBUTE_MULTI )) { break ; } CurrentFileOffset += CurrentCompoundDirent->Dirent.DataLength; CurrentMcbEntryOffset += 1; // // We better be able to find the next dirent. // if (!CdLookupNextDirent( IrpContext, ParentFcb, &CurrentCompoundDirent->DirContext, &FileContext->CurrentDirent->DirContext )) { CdRaiseStatus( IrpContext, STATUS_FILE_CORRUPT_ERROR ); } CurrentCompoundDirent = FileContext->CurrentDirent; CdUpdateDirentFromRawDirent( IrpContext, ParentFcb, &CurrentCompoundDirent->DirContext, &CurrentCompoundDirent->Dirent ); } // // Show that the Fcb is initialized. // SetFlag( Fcb->FcbState, FCB_STATE_INITIALIZED ); // // Link into the other in-memory structures and into the Fcb table. // Fcb->ParentFcb = ParentFcb; InsertTailList( &ParentFcb->FcbQueue, &Fcb->FcbLinks ); CdIncrementReferenceCounts( IrpContext, ParentFcb, 1, 1 ); CdInsertFcbTable( IrpContext, Fcb ); SetFlag( Fcb->FcbState, FCB_STATE_IN_FCB_TABLE ); } finally { CdUnlockFcb( IrpContext, Fcb ); } return ; }
PCCB CdCreateCcb ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ ULONG Flags ) /*++ Routine Description: This routine is called to allocate and initialize the Ccb structure. Arguments: Fcb - This is the Fcb for the file being opened. Flags - User flags to set in this Ccb. Return Value: PCCB - Pointer to the created Ccb. --*/ { PCCB NewCcb; PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); // // Allocate and initialize the structure. // NewCcb = CdAllocateCcb( IrpContext ); RtlZeroMemory( NewCcb, sizeof ( CCB )); // // Set the proper node type code and node byte size // NewCcb->NodeTypeCode = CDFS_NTC_CCB; NewCcb->NodeByteSize = sizeof ( CCB ); // // Set the initial value for the flags and Fcb // NewCcb->Flags = Flags; NewCcb->Fcb = Fcb; return NewCcb; }
VOID CdDeleteCcb ( _In_ PIRP_CONTEXT IrpContext, _In_ __drv_freesMem( Pool ) PCCB Ccb ) /*++ Routine Description: This routine is called to cleanup and deallocate a Ccb structure. Arguments: Ccb - This is the Ccb to delete. Return Value: None --*/ { PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); if (Ccb->SearchExpression.FileName.Buffer != NULL) { CdFreePool( &Ccb->SearchExpression.FileName.Buffer ); } CdDeallocateCcb( IrpContext, Ccb ); return ; }
_When_(RaiseOnError || return , _At_(Fcb->FileLock, _Post_notnull_)) _When_(RaiseOnError, _At_(IrpContext, _Pre_notnull_)) BOOLEAN CdCreateFileLock ( _In_opt_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ BOOLEAN RaiseOnError ) /*++ Routine Description: This routine is called when we want to attach a file lock structure to the given Fcb. It is possible the file lock is already attached. This routine is sometimes called from the fast path and sometimes in the Irp-based path. We don't want to raise in the fast path, just return FALSE. Arguments: Fcb - This is the Fcb to create the file lock for. RaiseOnError - If TRUE, we will raise on an allocation failure. Otherwise we return FALSE on an allocation failure. Return Value: BOOLEAN - TRUE if the Fcb has a filelock, FALSE otherwise. --*/ { BOOLEAN Result = TRUE; PFILE_LOCK FileLock; PAGED_CODE(); // // Lock the Fcb and check if there is really any work to do. // CdLockFcb( IrpContext, Fcb ); if (Fcb->FileLock != NULL) { CdUnlockFcb( IrpContext, Fcb ); return TRUE; } Fcb->FileLock = FileLock = FsRtlAllocateFileLock( NULL, NULL ); CdUnlockFcb( IrpContext, Fcb ); // // Return or raise as appropriate. // if (FileLock == NULL) { if (RaiseOnError) { NT_ASSERT( ARGUMENT_PRESENT( IrpContext )); CdRaiseStatus( IrpContext, STATUS_INSUFFICIENT_RESOURCES ); } Result = FALSE; } return Result; }
_Ret_valid_ PIRP_CONTEXT CdCreateIrpContext ( _In_ PIRP Irp, _In_ BOOLEAN Wait ) /*++ Routine Description: This routine is called to initialize an IrpContext for the current CDFS request. We allocate the structure and then initialize it from the given Irp. Arguments: Irp - Irp for this request. Wait - TRUE if this request is synchronous, FALSE otherwise. Return Value: PIRP_CONTEXT - Allocated IrpContext. --*/ { PIRP_CONTEXT NewIrpContext = NULL; PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp ); PAGED_CODE(); // // The only operations a filesystem device object should ever receive // are create/teardown of fsdo handles and operations which do not // occur in the context of fileobjects (i.e., mount). // if (IrpSp->DeviceObject == CdData.FileSystemDeviceObject) { if (IrpSp->FileObject != NULL && IrpSp->MajorFunction != IRP_MJ_CREATE && IrpSp->MajorFunction != IRP_MJ_CLEANUP && IrpSp->MajorFunction != IRP_MJ_CLOSE) { ExRaiseStatus( STATUS_INVALID_DEVICE_REQUEST ); } NT_ASSERT( IrpSp->FileObject != NULL || (IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL && IrpSp->MinorFunction == IRP_MN_USER_FS_REQUEST && IrpSp->Parameters.FileSystemControl.FsControlCode == FSCTL_INVALIDATE_VOLUMES) || (IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL && IrpSp->MinorFunction == IRP_MN_MOUNT_VOLUME ) || IrpSp->MajorFunction == IRP_MJ_SHUTDOWN ); } // // Look in our lookaside list for an IrpContext. // if (CdData.IrpContextDepth) { CdLockCdData(); NewIrpContext = (PIRP_CONTEXT) PopEntryList( &CdData.IrpContextList ); if (NewIrpContext != NULL) { CdData.IrpContextDepth--; } CdUnlockCdData(); } if (NewIrpContext == NULL) { // // We didn't get it from our private list so allocate it from pool. // NewIrpContext = FsRtlAllocatePoolWithTag( CdNonPagedPool, sizeof ( IRP_CONTEXT ), TAG_IRP_CONTEXT ); } RtlZeroMemory( NewIrpContext, sizeof ( IRP_CONTEXT )); // // Set the proper node type code and node byte size // NewIrpContext->NodeTypeCode = CDFS_NTC_IRP_CONTEXT; NewIrpContext->NodeByteSize = sizeof ( IRP_CONTEXT ); // // Set the originating Irp field // NewIrpContext->Irp = Irp; // // Copy RealDevice for workque algorithms. We will update this in the Mount or // Verify since they have no file objects to use here. // if (IrpSp->FileObject != NULL) { NewIrpContext->RealDevice = IrpSp->FileObject->DeviceObject; } // // Locate the volume device object and Vcb that we are trying to access. // This may be our filesystem device object. In that case don't initialize // the Vcb field. // if (IrpSp->DeviceObject != CdData.FileSystemDeviceObject) { NewIrpContext->Vcb = &((PVOLUME_DEVICE_OBJECT) IrpSp->DeviceObject)->Vcb; } // // Major/Minor Function codes // NewIrpContext->MajorFunction = IrpSp->MajorFunction; NewIrpContext->MinorFunction = IrpSp->MinorFunction; // // Set the wait parameter // if (Wait) { SetFlag( NewIrpContext->Flags, IRP_CONTEXT_FLAG_WAIT ); } else { SetFlag( NewIrpContext->Flags, IRP_CONTEXT_FLAG_FORCE_POST ); } // // return and tell the caller // return NewIrpContext; }
VOID CdCleanupIrpContext ( _In_ PIRP_CONTEXT IrpContext, _In_ BOOLEAN Post ) /*++ Routine Description: This routine is called to cleanup and possibly deallocate the Irp Context. If the request is being posted or this Irp Context is possibly on the stack then we only cleanup any auxilary structures. Arguments: Post - TRUE if we are posting this request, FALSE if we are deleting or retrying this in the current thread. Return Value: None. --*/ { PAGED_CODE(); // // If we aren't doing more processing then deallocate this as appropriate. // if (!FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING)) { // // If this context is the top level CDFS context then we need to // restore the top level thread context. // if (IrpContext->ThreadContext != NULL) { CdRestoreThreadContext( IrpContext ); } // // Deallocate the Io context if allocated. // if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_ALLOC_IO )) { CdFreeIoContext( IrpContext->IoContext ); } // // Deallocate the IrpContext if not from the stack. // if (!FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_ON_STACK )) { if (CdData.IrpContextDepth < CdData.IrpContextMaxDepth) { CdLockCdData(); PushEntryList( &CdData.IrpContextList, (PSINGLE_LIST_ENTRY) IrpContext ); CdData.IrpContextDepth++; CdUnlockCdData(); } else { // // We couldn't add this to our lookaside list so free it to // pool. // CdFreePool( &IrpContext ); } } // // Clear the appropriate flags. // } else if (Post) { // // If this context is the top level CDFS context then we need to // restore the top level thread context. // if (IrpContext->ThreadContext != NULL) { CdRestoreThreadContext( IrpContext ); } ClearFlag( IrpContext->Flags, IRP_CONTEXT_FLAGS_CLEAR_ON_POST ); } else { ClearFlag( IrpContext->Flags, IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY ); } return ; }
VOID CdInitializeStackIrpContext ( _Out_ PIRP_CONTEXT IrpContext, _In_ PIRP_CONTEXT_LITE IrpContextLite ) /*++ Routine Description: This routine is called to initialize an IrpContext for the current CDFS request. The IrpContext is on the stack and we need to initialize it for the current request. The request is a close operation. Arguments: IrpContext - IrpContext to initialize. IrpContextLite - Structure containing the details of this request. Return Value: None --*/ { PAGED_CODE(); // // Zero and then initialize the structure. // RtlZeroMemory( IrpContext, sizeof ( IRP_CONTEXT )); // // Set the proper node type code and node byte size // IrpContext->NodeTypeCode = CDFS_NTC_IRP_CONTEXT; IrpContext->NodeByteSize = sizeof ( IRP_CONTEXT ); // // Note that this is from the stack. // SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_ON_STACK ); // // Copy RealDevice for workque algorithms. // IrpContext->RealDevice = IrpContextLite->RealDevice; // // The Vcb is found in the Fcb. // IrpContext->Vcb = IrpContextLite->Fcb->Vcb; // // Major/Minor Function codes // IrpContext->MajorFunction = IRP_MJ_CLOSE; // // Set the wait parameter // SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT ); return ; }
_Requires_lock_held_(_Global_critical_region_) VOID CdTeardownStructures ( _In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB StartingFcb, _Out_ PBOOLEAN RemovedStartingFcb ) /*++ Routine Description: This routine is used to walk from some starting point in the Fcb tree towards the root. It will remove the Fcb and continue walking up the tree until it finds a point where we can't remove an Fcb. We look at the following fields in the Fcb to determine whether we can remove this. 1 - Handle count must be zero. 2 - If directory then only the only reference can be for a stream file. 3 - Reference count must either be zero or go to zero here. We return immediately if we are recursively entering this routine. Arguments: StartingFcb - This is the Fcb node in the tree to begin with. This Fcb must currently be acquired exclusively. RemovedStartingFcb - Address to store whether we removed the starting Fcb. Return Value: None --*/ { PVCB Vcb = StartingFcb->Vcb; PFCB CurrentFcb = StartingFcb; BOOLEAN AcquiredCurrentFcb = FALSE; PFCB ParentFcb; PAGED_CODE(); *RemovedStartingFcb = FALSE; // // If this is a recursive call to TearDownStructures we return immediately // doing no operation. // if (FlagOn( IrpContext->TopLevel->Flags, IRP_CONTEXT_FLAG_IN_TEARDOWN )) { return ; } SetFlag( IrpContext->TopLevel->Flags, IRP_CONTEXT_FLAG_IN_TEARDOWN ); // // Use a try-finally to safely clear the top-level field. // try { // // Loop until we find an Fcb we can't remove. // do { // // See if there is an internal stream we should delete. // Only do this if it is the last reference on the Fcb. // if ((SafeNodeType( CurrentFcb ) != CDFS_NTC_FCB_DATA) && (CurrentFcb->FcbUserReference == 0) && (CurrentFcb->FileObject != NULL)) { // // Go ahead and delete the stream file object. // CdDeleteInternalStream( IrpContext, CurrentFcb ); } // // If the reference count is non-zero then break. // if (CurrentFcb->FcbReference != 0) { break ; } // // It looks like we have a candidate for removal here. We // will need to acquire the parent, if present, in order to // remove this from the parent prefix table. // ParentFcb = CurrentFcb->ParentFcb; if (ParentFcb != NULL) { CdAcquireFcbExclusive( IrpContext, ParentFcb, FALSE ); } // // Now lock the vcb. // CdLockVcb( IrpContext, Vcb ); // // Final check to see if the reference count is still zero. // if (CurrentFcb->FcbReference != 0) { CdUnlockVcb( IrpContext, Vcb ); if (ParentFcb != NULL) { CdReleaseFcb( IrpContext, ParentFcb ); } break ; } // // If there is a parent then do the necessary cleanup for the parent. // if (ParentFcb != NULL) { CdRemovePrefix( IrpContext, CurrentFcb ); RemoveEntryList( &CurrentFcb->FcbLinks ); CdDecrementReferenceCounts( IrpContext, ParentFcb, 1, 1 ); } if (FlagOn( CurrentFcb->FcbState, FCB_STATE_IN_FCB_TABLE )) { CdDeleteFcbTable( IrpContext, CurrentFcb ); ClearFlag( CurrentFcb->FcbState, FCB_STATE_IN_FCB_TABLE ); } // // Unlock the Vcb but hold the parent in order to walk up // the tree. // CdUnlockVcb( IrpContext, Vcb ); CdDeleteFcb( IrpContext, CurrentFcb ); // // Move to the parent Fcb. // CurrentFcb = ParentFcb; AcquiredCurrentFcb = TRUE; } while (CurrentFcb != NULL); } finally { // // Release the current Fcb if we have acquired it. // if (AcquiredCurrentFcb && (CurrentFcb != NULL)) { CdReleaseFcb( IrpContext, CurrentFcb ); } // // Clear the teardown flag. // ClearFlag( IrpContext->TopLevel->Flags, IRP_CONTEXT_FLAG_IN_TEARDOWN ); } *RemovedStartingFcb = (CurrentFcb != StartingFcb); return ; }
PFCB CdLookupFcbTable ( _In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ FILE_ID FileId ) /*++ Routine Description: This routine will look through the Fcb table looking for a matching entry. Arguments: Vcb - Vcb for this volume. FileId - This is the key value to use for the search. Return Value: PFCB - A pointer to the matching entry or NULL otherwise. --*/ { FCB_TABLE_ELEMENT Key; PFCB_TABLE_ELEMENT Hit; PFCB ReturnFcb = NULL; PAGED_CODE(); Key.FileId = FileId; Hit = (PFCB_TABLE_ELEMENT) RtlLookupElementGenericTable( &Vcb->FcbTable, &Key ); if (Hit != NULL) { ReturnFcb = Hit->Fcb; } return ReturnFcb; UNREFERENCED_PARAMETER( IrpContext ); }
PFCB CdGetNextFcb ( _In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ PVOID *RestartKey ) /*++ Routine Description: This routine will enumerate through all of the Fcb's in the Fcb table. Arguments: Vcb - Vcb for this volume. RestartKey - This value is used by the table package to maintain its position in the enumeration. It is initialized to NULL for the first search. Return Value: PFCB - A pointer to the next fcb or NULL if the enumeration is completed --*/ { PFCB Fcb; PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); Fcb = (PFCB) RtlEnumerateGenericTableWithoutSplaying( &Vcb->FcbTable, RestartKey ); if (Fcb != NULL) { Fcb = ((PFCB_TABLE_ELEMENT)(Fcb))->Fcb; } return Fcb; }
NTSTATUS CdProcessToc ( _In_ PIRP_CONTEXT IrpContext, _In_ PDEVICE_OBJECT TargetDeviceObject, _In_ PCDROM_TOC_LARGE CdromToc, _Inout_ PULONG Length, _Out_ PULONG TrackCount, _Inout_ PULONG DiskFlags ) /*++ Routine Description: This routine is called to verify and process the TOC for this disk. We hide a data track for a CD+ volume. Arguments: TargetDeviceObject - Device object to send TOC request to. CdromToc - Pointer to TOC structure. Length - On input this is the length of the TOC. On return is the TOC length we will show to the user. TrackCount - This is the count of tracks for the TOC. We use this when creating a pseudo directory for a music disk. DiskFlags - We return flags indicating what we know about this disk. Return Value: NTSTATUS - The result of trying to read the TOC. --*/ { NTSTATUS Status; IO_STATUS_BLOCK Iosb; CDROM_READ_TOC_EX Command; ULONG CurrentTrack; ULONG LocalTrackCount; ULONG LocalTocLength; ULONG Address = 0; BOOLEAN UseReadToc = FALSE; union { UCHAR BigEndian[2]; USHORT Length; } BiasedTocLength; PTRACK_DATA Track; PAGED_CODE(); // // Zero the command block. This conveniently corresponds to an // LBA mode READ_TOC request. // RtlZeroMemory( &Command, sizeof ( Command)); RetryReadToc: // // Go ahead and read the table of contents // Status = CdPerformDevIoCtrlEx( IrpContext, UseReadToc ? IOCTL_CDROM_READ_TOC : IOCTL_CDROM_READ_TOC_EX, TargetDeviceObject, &Command, sizeof ( Command ), CdromToc, sizeof ( CDROM_TOC_LARGE ), FALSE, TRUE, &Iosb ); // // Nothing to process if this request fails. // if (!NT_SUCCESS( Status )) { // // If the underlying device does not support READ_TOC_EX, try the old method. // if (!UseReadToc && ((Status == STATUS_INVALID_DEVICE_REQUEST) || (Status == STATUS_INVALID_PARAMETER))) { UseReadToc = TRUE; goto RetryReadToc; } return Status; } // // Get the number of tracks and stated size of this structure. // CurrentTrack = 0; LocalTrackCount = CdromToc->LastTrack - CdromToc->FirstTrack + 1; LocalTocLength = PtrOffset( CdromToc, &CdromToc->TrackData[LocalTrackCount + 1] ); // // Get out if there is an immediate problem with the TOC. // if ((LocalTocLength > Iosb.Information) || (CdromToc->FirstTrack > CdromToc->LastTrack)) { Status = STATUS_DISK_CORRUPT_ERROR; return Status; } // // Walk through the individual tracks. Stop at the first data track after // any lead-in audio tracks. // do { // // Get the next track. // Track = &CdromToc->TrackData[CurrentTrack]; // // If this is a data track then check if we have only seen audio tracks // to this point. // if (FlagOn( Track->Control, TOC_DATA_TRACK )) { // // If we have only seen audio tracks then assume this is a // CD+ disk. Hide the current data track and only return // the previous audio tracks. Set the disk type to be mixed // data/audio. // if (FlagOn( *DiskFlags, CDROM_DISK_AUDIO_TRACK ) && !FlagOn( *DiskFlags, CDROM_DISK_DATA_TRACK )) { // // Remove one track from the TOC. // CdromToc->LastTrack -= 1; // // Knock 2.5 minutes off the current track to hide the final leadin. // 2.5 min = 150 sec = (x 75) 11250 frames (sectors). // SwapCopyUchar4( &Address, &Track->Address); Address -= 11250; SwapCopyUchar4( &Track->Address, &Address); Track->TrackNumber = TOC_LAST_TRACK; // // Set the disk type to mixed data/audio. // SetFlag( *DiskFlags, CDROM_DISK_DATA_TRACK ); break ; } // // Set the flag to indicate data tracks present. // SetFlag( *DiskFlags, CDROM_DISK_DATA_TRACK ); // // If this is a audio track then set the flag indicating audio // tracks. // } else { SetFlag( *DiskFlags, CDROM_DISK_AUDIO_TRACK ); } // // Set our index for the next track. // CurrentTrack += 1; } while (CurrentTrack < LocalTrackCount); // // Set the length to point just past the last track we looked at. // *TrackCount = CurrentTrack; *Length = PtrOffset( CdromToc, &CdromToc->TrackData[CurrentTrack + 1] ); BiasedTocLength.Length = ( USHORT ) *Length - 2; CdromToc->Length[0] = BiasedTocLength.BigEndian[1]; CdromToc->Length[1] = BiasedTocLength.BigEndian[0]; return Status; }
// // Local support routine // VOID CdDeleteFcb ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb ) /*++ Routine Description: This routine is called to cleanup and deallocate an Fcb. We know there are no references remaining. We cleanup any auxilary structures and deallocate this Fcb. Arguments: Fcb - This is the Fcb to deallcoate. Return Value: None --*/ { PVCB Vcb = NULL; PAGED_CODE(); // // Sanity check the counts. // NT_ASSERT( Fcb->FcbCleanup == 0 ); NT_ASSERT( Fcb->FcbReference == 0 ); // // Release any Filter Context structures associated with this FCB // FsRtlTeardownPerStreamContexts( &Fcb->Header ); // // Start with the common structures. // CdUninitializeMcb( IrpContext, Fcb ); CdDeleteFcbNonpaged( IrpContext, Fcb->FcbNonpaged ); // // Check if we need to deallocate the prefix name buffer. // if ((Fcb->FileNamePrefix.ExactCaseName.FileName.Buffer != ( PWCHAR ) Fcb->FileNamePrefix.FileNameBuffer) && (Fcb->FileNamePrefix.ExactCaseName.FileName.Buffer != NULL)) { CdFreePool( &Fcb->FileNamePrefix.ExactCaseName.FileName.Buffer ); } // // Now look at the short name prefix. // if (Fcb->ShortNamePrefix != NULL) { CdFreePool( &Fcb->ShortNamePrefix ); } // // Now do the type specific structures. // switch (Fcb->NodeTypeCode) { case CDFS_NTC_FCB_PATH_TABLE: case CDFS_NTC_FCB_INDEX: NT_ASSERT( Fcb->FileObject == NULL ); NT_ASSERT( IsListEmpty( &Fcb->FcbQueue )); if (Fcb == Fcb->Vcb->RootIndexFcb) { Vcb = Fcb->Vcb; Vcb->RootIndexFcb = NULL; } else if (Fcb == Fcb->Vcb->PathTableFcb) { Vcb = Fcb->Vcb; Vcb->PathTableFcb = NULL; } CdDeallocateFcbIndex( IrpContext, Fcb ); break ; case CDFS_NTC_FCB_DATA : if (Fcb->FileLock != NULL) { FsRtlFreeFileLock( Fcb->FileLock ); } FsRtlUninitializeOplock( CdGetFcbOplock(Fcb) ); if (Fcb == Fcb->Vcb->VolumeDasdFcb) { Vcb = Fcb->Vcb; Vcb->VolumeDasdFcb = NULL; } CdDeallocateFcbData( IrpContext, Fcb ); } // // Decrement the Vcb reference count if this is a system // Fcb. // if (Vcb != NULL) { InterlockedDecrement( ( LONG *)&Vcb->VcbReference ); InterlockedDecrement( ( LONG *)&Vcb->VcbUserReference ); } return ; }
// // Local support routine // PFCB_NONPAGED CdCreateFcbNonpaged ( _In_ PIRP_CONTEXT IrpContext ) /*++ Routine Description: This routine is called to create and initialize the non-paged portion of an Fcb. Arguments: Return Value: PFCB_NONPAGED - Pointer to the created nonpaged Fcb. NULL if not created. --*/ { PFCB_NONPAGED FcbNonpaged; PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); // // Allocate the non-paged pool and initialize the various // synchronization objects. // FcbNonpaged = CdAllocateFcbNonpaged( IrpContext ); if (FcbNonpaged != NULL) { RtlZeroMemory( FcbNonpaged, sizeof ( FCB_NONPAGED )); FcbNonpaged->NodeTypeCode = CDFS_NTC_FCB_NONPAGED; FcbNonpaged->NodeByteSize = sizeof ( FCB_NONPAGED ); ExInitializeResourceLite( &FcbNonpaged->FcbResource ); ExInitializeFastMutex( &FcbNonpaged->FcbMutex ); } return FcbNonpaged; }
// // Local support routine // VOID CdDeleteFcbNonpaged ( _In_ PIRP_CONTEXT IrpContext, _In_ PFCB_NONPAGED FcbNonpaged ) /*++ Routine Description: This routine is called to cleanup the non-paged portion of an Fcb. Arguments: FcbNonpaged - Structure to clean up. Return Value: None --*/ { PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); ExDeleteResourceLite( &FcbNonpaged->FcbResource ); CdDeallocateFcbNonpaged( IrpContext, FcbNonpaged ); return ; }
// // Local support routine // RTL_GENERIC_COMPARE_RESULTS CdFcbTableCompare ( _In_ PRTL_GENERIC_TABLE FcbTable, _In_ PVOID Fid1, _In_ PVOID Fid2 ) /*++ Routine Description: This routine is the Cdfs compare routine called by the generic table package. If will compare the two File Id values and return a comparison result. Arguments: FcbTable - This is the table being searched. Fid1 - First key value. Fid2 - Second key value. Return Value: RTL_GENERIC_COMPARE_RESULTS - The results of comparing the two input structures --*/ { FILE_ID Id1, Id2; PAGED_CODE(); Id1 = *((FILE_ID UNALIGNED *) Fid1); Id2 = *((FILE_ID UNALIGNED *) Fid2); if (Id1.QuadPart < Id2.QuadPart) { return GenericLessThan; } else if (Id1.QuadPart > Id2.QuadPart) { return GenericGreaterThan; } else { return GenericEqual; } UNREFERENCED_PARAMETER( FcbTable ); }
// // Local support routine // PVOID CdAllocateFcbTable ( _In_ PRTL_GENERIC_TABLE FcbTable, _In_ CLONG ByteSize ) /*++ Routine Description: This is a generic table support routine to allocate memory Arguments: FcbTable - Supplies the generic table being used ByteSize - Supplies the number of bytes to allocate Return Value: PVOID - Returns a pointer to the allocated data --*/ { PAGED_CODE(); UNREFERENCED_PARAMETER( FcbTable ); return ( FsRtlAllocatePoolWithTag( CdPagedPool, ByteSize, TAG_FCB_TABLE )); }
// // Local support routine // VOID CdDeallocateFcbTable ( _In_ PRTL_GENERIC_TABLE FcbTable, _In_ __drv_freesMem(Mem) _Post_invalid_ PVOID Buffer ) /*++ Routine Description: This is a generic table support routine that deallocates memory Arguments: FcbTable - Supplies the generic table being used Buffer - Supplies the buffer being deallocated Return Value: None. --*/ { PAGED_CODE(); CdFreePool( &Buffer ); UNREFERENCED_PARAMETER( FcbTable ); }
// // Local support routine // ULONG CdTocSerial ( _In_ PIRP_CONTEXT IrpContext, _In_ PCDROM_TOC_LARGE CdromToc ) /*++ Routine Description: This routine is called to generate a serial number for an audio disk. The number is based on the starting positions of the tracks. The following algorithm is used. If the number of tracks is <= 2 then initialize the serial number to the leadout block number. Then add the starting address of each track (use 0x00mmssff format). Arguments: CdromToc - Valid table of contents to use for track information. Return Value: ULONG - 32 bit serial number based on TOC. --*/ { ULONG SerialNumber = 0; PTRACK_DATA ThisTrack; PTRACK_DATA LastTrack; ULONG Address; ULONG MsfAddress = 0; // satisfy PREFIX PAGED_CODE(); UNREFERENCED_PARAMETER( IrpContext ); // // Check if there are two tracks or fewer. // LastTrack = &CdromToc->TrackData[ CdromToc->LastTrack - CdromToc->FirstTrack + 1]; ThisTrack = &CdromToc->TrackData[0]; if (CdromToc->LastTrack - CdromToc->FirstTrack <= 1) { SwapCopyUchar4( &Address, LastTrack->Address); CdLbnToMmSsFf( Address, ( PUCHAR )&SerialNumber); } else { // // Add the starting offset of each track and add to the serial number. // while (ThisTrack != LastTrack) { SwapCopyUchar4( &Address, ThisTrack->Address); CdLbnToMmSsFf( Address, ( PUCHAR )&MsfAddress); SerialNumber += MsfAddress; ThisTrack += 1; } } return SerialNumber; } |
Our Services
-
What our customers say about us?
Read our customer testimonials to find out why our clients keep returning for their projects.
View Testimonials