File 0001-fsck_hfs-Disable-BlocksRuntime.patch of Package hfsplus-tools
From 4492450a3f48efc70f82c2a040f873c5da0fb2ab Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Tue, 20 Jun 2023 16:56:32 +0200
Subject: [PATCH 1/7] fsck_hfs: Disable BlocksRuntime
---
fsck_hfs/dfalib/SControl.c | 55 +++++++++++++++++++---------------
fsck_hfs/dfalib/fsck_journal.c | 4 +--
fsck_hfs/dfalib/fsck_journal.h | 4 ++-
fsck_hfs/fsck_messages.c | 21 ++-----------
fsck_hfs/fsck_messages.h | 2 +-
5 files changed, 38 insertions(+), 48 deletions(-)
diff --git a/fsck_hfs/dfalib/SControl.c b/fsck_hfs/dfalib/SControl.c
index 43b2eda..ea497ac 100644
--- a/fsck_hfs/dfalib/SControl.c
+++ b/fsck_hfs/dfalib/SControl.c
@@ -204,6 +204,22 @@ isMinorError(int msg, int *counts)
}
}
+static int *msgCounts = NULL;
+static jmp_buf envBuf;
+
+static fsck_block_status_t
+fsckAfterCallback(fsck_ctx_t c, int msgNum, va_list args)
+{
+ if (abs(msgNum) > E_FirstError && abs(msgNum) < E_LastError) {
+ if (isMinorError(abs(msgNum), msgCounts) == 1)
+ return fsckBlockContinue;
+ longjmp(envBuf, 1);
+ return fsckBlockAbort;
+ } else {
+ return fsckBlockContinue;
+ }
+}
+
/*------------------------------------------------------------------------------
External
@@ -211,7 +227,6 @@ External
------------------------------------------------------------------------------*/
-static jmp_buf envBuf;
int
CheckHFS( const char *rdevnode, int fsReadRef, int fsWriteRef, int checkLevel,
int repairLevel, fsck_ctx_t fsckContext, int lostAndFoundMode,
@@ -226,7 +241,6 @@ CheckHFS( const char *rdevnode, int fsReadRef, int fsWriteRef, int checkLevel,
int isJournaled = 0;
Boolean autoRepair;
Boolean exitEarly = 0;
- __block int *msgCounts = NULL;
Boolean majorErrors = 0;
if (checkLevel == kMajorCheck) {
@@ -288,16 +302,7 @@ CheckHFS( const char *rdevnode, int fsReadRef, int fsWriteRef, int checkLevel,
* the message in question corresponds to a major or a minor error. If it's
* major, we longjmp just above, which causes us to exit out early.
*/
- fsckSetBlock(fsckContext, fsckPhaseAfterMessage, (fsckBlock_t) ^(fsck_ctx_t c, int msgNum, va_list args) {
- if (abs(msgNum) > E_FirstError && abs(msgNum) < E_LastError) {
- if (isMinorError(abs(msgNum), msgCounts) == 1)
- return fsckBlockContinue;
- longjmp(envBuf, 1);
- return fsckBlockAbort;
- } else {
- return fsckBlockContinue;
- }
- });
+ fsckSetBlock(fsckContext, fsckPhaseAfterMessage, fsckAfterCallback);
}
}
DoAgain:
@@ -542,6 +547,19 @@ termScav:
return( err );
}
+static int ScavCtrlJournalCallback (off_t start, void *data, size_t len)
+{
+ Buf_t *buf;
+ int rv;
+ rv = CacheRead(&fscache, start, (int)len, &buf);
+ if (rv != 0)
+ abort();
+ memcpy(buf->Buffer, data, len);
+ rv = CacheWrite(&fscache, buf, 0, kLockWrite);
+ if (rv != 0)
+ abort();
+ return 0;
+}
/*------------------------------------------------------------------------------
@@ -681,18 +699,7 @@ void ScavCtrl( SGlobPtr GPtr, UInt32 ScavOp, short *ScavRes )
blockSize,
0,
jnlInfo.name,
- ^(off_t start, void *data, size_t len) {
- Buf_t *buf;
- int rv;
- rv = CacheRead(&fscache, start, (int)len, &buf);
- if (rv != 0)
- abort();
- memcpy(buf->Buffer, data, len);
- rv = CacheWrite(&fscache, buf, 0, kLockWrite);
- if (rv != 0)
- abort();
- return 0;}
- ) == -1) {
+ ScavCtrlJournalCallback) == -1) {
fsckPrint(GPtr->context, E_DirtyJournal);
GPtr->JStat |= S_DirtyJournal;
} else if (debug) {
diff --git a/fsck_hfs/dfalib/fsck_journal.c b/fsck_hfs/dfalib/fsck_journal.c
index 8c76d5f..1a37e28 100644
--- a/fsck_hfs/dfalib/fsck_journal.c
+++ b/fsck_hfs/dfalib/fsck_journal.c
@@ -74,8 +74,6 @@ static swapper_t swappedEndian = {
^(uint64_t x) { return OSSwapInt64(x); }
};
-typedef int (^journal_write_block_t)(off_t, void *, size_t);
-
//
// this isn't a great checksum routine but it will do for now.
// we use it to checksum the journal header and the block list
@@ -379,7 +377,7 @@ journal_open(int jfd,
size_t min_fs_blksize, // Blocksize of the data filesystem, journal blocksize must be at least this size
uint32_t flags __unused, // Not used in this implementation
const char *jdev_name, // The name of the journal device, for logging
- int (^do_write_b)(off_t, void*, size_t))
+ journal_write_block_t do_write_b)
{
journal_header jhdr = { 0 };
swapper_t *jnlSwap; // Used to swap fields of the journal
diff --git a/fsck_hfs/dfalib/fsck_journal.h b/fsck_hfs/dfalib/fsck_journal.h
index 8b3ecbf..e81c40a 100644
--- a/fsck_hfs/dfalib/fsck_journal.h
+++ b/fsck_hfs/dfalib/fsck_journal.h
@@ -97,12 +97,14 @@ typedef struct journal_header {
* bytes.
*/
+typedef int (*journal_write_block_t)(off_t, void *, size_t);
+
int journal_open(int jdev,
off_t offset,
off_t journal_size,
size_t min_fs_block_size,
uint32_t flags,
const char *jdev_name,
- int (^do_write_b)(off_t, void *, size_t));
+ journal_write_block_t do_write_b);
#endif /* !_FSCK_JOURNAL_H */
diff --git a/fsck_hfs/fsck_messages.c b/fsck_hfs/fsck_messages.c
index 9dcf3d8..b4bbb2c 100644
--- a/fsck_hfs/fsck_messages.c
+++ b/fsck_hfs/fsck_messages.c
@@ -28,7 +28,6 @@
#include <stdarg.h>
#include <string.h>
#include <assert.h>
-#include <Block.h>
#include <sys/param.h>
#include "fsck_messages.h"
@@ -300,20 +299,10 @@ fsckSetBlock(fsck_ctx_t c, fsck_block_phase_t phase, fsckBlock_t bp)
if (c != NULL) {
switch (phase) {
case fsckPhaseBeforeMessage:
- if (ctx->preMessage) {
- Block_release(ctx->preMessage);
- ctx->preMessage = NULL;
- }
- if (bp)
- ctx->preMessage = (fsckBlock_t)Block_copy(bp);
+ ctx->preMessage = bp;
break;
case fsckPhaseAfterMessage:
- if (ctx->postMessage) {
- Block_release(ctx->postMessage);
- ctx->postMessage = NULL;
- }
- if (bp)
- ctx->postMessage = (fsckBlock_t)Block_copy(bp);
+ ctx->postMessage = bp;
break;
case fsckPhaseNone:
/* Just here for compiler warnings */
@@ -608,12 +597,6 @@ fsckDestroy(fsck_ctx_t c)
if (ctx->flags & cfFromFD) {
fclose(ctx->fp);
}
- if (ctx->preMessage) {
- Block_release(ctx->preMessage);
- }
- if (ctx->postMessage) {
- Block_release(ctx->postMessage);
- }
free(ctx);
return;
diff --git a/fsck_hfs/fsck_messages.h b/fsck_hfs/fsck_messages.h
index d42e36e..d05ca48 100644
--- a/fsck_hfs/fsck_messages.h
+++ b/fsck_hfs/fsck_messages.h
@@ -141,7 +141,7 @@ typedef enum fsck_block_phase_type fsck_block_phase_t;
* the third is a va_list of the arguments for the message.
*/
-typedef fsck_block_status_t (^fsckBlock_t)(fsck_ctx_t, int, va_list);
+typedef fsck_block_status_t (*fsckBlock_t)(fsck_ctx_t, int, va_list);
extern fsckBlock_t fsckGetBlock(fsck_ctx_t, fsck_block_phase_t);
extern void fsckSetBlock(fsck_ctx_t, fsck_block_phase_t, fsckBlock_t);
--
2.41.0