提交 9e76d919 编写于 作者: P PMheart

OcAppleKernelLib: Disable trim using new method

closes https://github.com/acidanthera/bugtracker/issues/1950
上级 b80c8ec3
...@@ -3,6 +3,8 @@ OpenCore Changelog ...@@ -3,6 +3,8 @@ OpenCore Changelog
#### v0.7.9 #### v0.7.9
- Added auto-detect `macOS Installer` volume name for use when `.disk_label` file cannot be displayed - Added auto-detect `macOS Installer` volume name for use when `.disk_label` file cannot be displayed
- Added `--restore-nosnoop` flag to AudioDxe, making v0.7.7 fix for Windows sound opt-in - Added `--restore-nosnoop` flag to AudioDxe, making v0.7.7 fix for Windows sound opt-in
- Added new method to disable trim when `SetApfsTrimTimeout` is set to zero
- Fixed `SetApfsTrimTimeout` on macOS 12 (only works when set to zero)
#### v0.7.8 #### v0.7.8
- Updated ocvalidate to warn about insecure `DmgLoading` with secure `SecureBootModel` (already disallowed in runtime) - Updated ocvalidate to warn about insecure `DmgLoading` with secure `SecureBootModel` (already disallowed in runtime)
......
8fe92652e6b6bf444b97fb743cae2a52 63ebe375542ad0f079cc7071555dd405
...@@ -2748,6 +2748,9 @@ blocking. ...@@ -2748,6 +2748,9 @@ blocking.
\href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article} \href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article}
for details. for details.
As of macOS 12.0, it is no longer possible to set trim timeout for APFS filesystems.
However, trim can be disabled when the timeout value is set to \texttt{0}.
\item \item
\texttt{ThirdPartyDrives}\\ \texttt{ThirdPartyDrives}\\
\textbf{Type}: \texttt{plist\ boolean}\\ \textbf{Type}: \texttt{plist\ boolean}\\
......
\documentclass[]{article} \documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE %DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Wed Feb 9 09:37:10 2022 %DIF DEL PreviousConfiguration.tex Thu Feb 10 15:29:05 2022
%DIF ADD ../Configuration.tex Wed Feb 9 23:42:58 2022 %DIF ADD ../Configuration.tex Thu Feb 10 19:56:56 2022
\usepackage{lmodern} \usepackage{lmodern}
\usepackage{amssymb,amsmath} \usepackage{amssymb,amsmath}
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
%DIF HYPERREF PREAMBLE %DIF PREAMBLE %DIF HYPERREF PREAMBLE %DIF PREAMBLE
\providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} %DIF PREAMBLE \providecommand{\DIFadd}[1]{\texorpdfstring{\DIFaddtex{#1}}{#1}} %DIF PREAMBLE
\providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE \providecommand{\DIFdel}[1]{\texorpdfstring{\DIFdeltex{#1}}{}} %DIF PREAMBLE
%DIF LISTINGS PREAMBLE %DIF PREAMBLE %DIF COLORLISTINGS PREAMBLE %DIF PREAMBLE
\RequirePackage{listings} %DIF PREAMBLE \RequirePackage{listings} %DIF PREAMBLE
\RequirePackage{color} %DIF PREAMBLE \RequirePackage{color} %DIF PREAMBLE
\lstdefinelanguage{DIFcode}{ %DIF PREAMBLE \lstdefinelanguage{DIFcode}{ %DIF PREAMBLE
...@@ -2808,7 +2808,11 @@ blocking. ...@@ -2808,7 +2808,11 @@ blocking.
\href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article} \href{https://interface31.ru/tech_it/2015/04/mozhno-li-effektivno-ispolzovat-ssd-bez-podderzhki-trim.html}{article}
for details. for details.
\item \DIFaddbegin \DIFadd{As of macOS 12.0, it is no longer possible to set trim timeout for APFS filesystems.
However, trim can be disabled when the timeout value is set to }\texttt{\DIFadd{0}}\DIFadd{.
}
\DIFaddend \item
\texttt{ThirdPartyDrives}\\ \texttt{ThirdPartyDrives}\\
\textbf{Type}: \texttt{plist\ boolean}\\ \textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\ \textbf{Failsafe}: \texttt{false}\\
......
...@@ -1979,45 +1979,38 @@ mApfsTimeoutPatch = { ...@@ -1979,45 +1979,38 @@ mApfsTimeoutPatch = {
.Limit = 0 .Limit = 0
}; };
STATIC VOID
UINT8 PatchSetApfsTimeout (
mApfsTimeoutV2Find[] = { IN UINT32 Timeout
0x40, 0x42, 0x0F, 0x00 )
}; {
// FIXME: This is really ugly, make quirks take a context param.
DEBUG ((DEBUG_INFO, "OCAK: Registering %u APFS timeout\n", Timeout));
CopyMem (&mApfsTimeoutReplace[2], &Timeout, sizeof (Timeout));
}
STATIC STATIC
UINT8 UINT8
mApfsTimeoutV2Replace[] = { mApfsDisableTrimReplace[] = {
0x00, 0x02, 0x00, 0x00 0x31, 0xC0, ///< xor eax, eax
0xC3 ///< ret
}; };
STATIC STATIC
PATCHER_GENERIC_PATCH PATCHER_GENERIC_PATCH
mApfsTimeoutV2Patch = { mApfsDisableTrimPatch = {
.Comment = DEBUG_POINTER ("ApfsTimeout V2"), .Comment = DEBUG_POINTER ("ApfsTimeout disable trim"),
.Base = "_spaceman_scan_free_blocks", .Base = "_spaceman_iterate_free_extents_internal",
.Find = mApfsTimeoutV2Find, .Find = NULL,
.Mask = NULL, .Mask = NULL,
.Replace = mApfsTimeoutV2Replace, .Replace = mApfsDisableTrimReplace,
.ReplaceMask = NULL, .ReplaceMask = NULL,
.Size = sizeof (mApfsTimeoutV2Find), .Size = sizeof (mApfsDisableTrimReplace),
.Count = 2, .Count = 1,
.Skip = 0, .Skip = 0,
.Limit = 4096 .Limit = 0
}; };
VOID
PatchSetApfsTimeout (
IN UINT32 Timeout
)
{
// FIXME: This is really ugly, make quirks take a context param.
DEBUG ((DEBUG_INFO, "OCAK: Registering %u APFS timeout\n", Timeout));
CopyMem (&mApfsTimeoutReplace[2], &Timeout, sizeof (Timeout));
CopyMem (&mApfsTimeoutV2Replace[0], &Timeout, sizeof (Timeout));
}
STATIC STATIC
EFI_STATUS EFI_STATUS
PatchSetApfsTrimTimeout ( PatchSetApfsTrimTimeout (
...@@ -2036,23 +2029,33 @@ PatchSetApfsTrimTimeout ( ...@@ -2036,23 +2029,33 @@ PatchSetApfsTrimTimeout (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (KernelVersion >= KERNEL_VERSION_MONTEREY_MIN) { //
Status = PatcherApplyGenericPatch (Patcher, &mApfsTimeoutV2Patch); // Disable trim using another patch when timeout is 0.
//
if (mApfsTimeoutReplace[2] == 0) {
Status = PatcherApplyGenericPatch (Patcher, &mApfsDisableTrimPatch);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch SetApfsTrimTimeoutV2 - %r\n", Status)); DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch ApfsDisableTrim - %r\n", Status));
} else { } else {
DEBUG ((DEBUG_INFO, "OCAK: Patch success SetApfsTrimTimeoutV2\n")); DEBUG ((DEBUG_INFO, "OCAK: Patch success ApfsDisableTrim\n"));
} }
} else {
return Status;
}
if (KernelVersion < KERNEL_VERSION_MONTEREY_MIN) {
Status = PatcherApplyGenericPatch (Patcher, &mApfsTimeoutPatch); Status = PatcherApplyGenericPatch (Patcher, &mApfsTimeoutPatch);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch SetApfsTrimTimeout - %r\n", Status)); DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch SetApfsTrimTimeout - %r\n", Status));
} else { } else {
DEBUG ((DEBUG_INFO, "OCAK: Patch success SetApfsTrimTimeout\n")); DEBUG ((DEBUG_INFO, "OCAK: Patch success SetApfsTrimTimeout\n"));
} }
return Status;
} }
return Status; DEBUG ((DEBUG_INFO, "OCAK: Skipping patch SetApfsTrimTimeout on macOS 12.0+\n"));
return EFI_SUCCESS;
} }
// //
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册