fsck: fix fsck apply

- Throw an error if the handler tries to apply in readonly mode
- Do not expose BOOKMARKFS_FSCK_RESULT_END to the handler
This commit is contained in:
CismonX 2025-01-18 08:52:43 +08:00
parent 7aaa8753cc
commit 712861e8f8
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
4 changed files with 11 additions and 9 deletions

View file

@ -1486,7 +1486,6 @@ The first element of the list is an integer indicating the reason for
this handler call:
@table @code
@item $::bookmarkfs::fsck::result::end
@item $::bookmarkfs::fsck::result::nameDuplicate
@item $::bookmarkfs::fsck::result::nameBadChar
@item $::bookmarkfs::fsck::result::nameBadLen
@ -1494,8 +1493,7 @@ this handler call:
@item $::bookmarkfs::fsck::result::nameInvalid
@xref{Filesystem-check Result Code} for the meaning of each value.
Except for @code{$::bookmarkfs::fsck::result::end}, the second element
is a list of information about the current entry:
The second element is a list of information about the current entry:
@enumerate 0
@item The bookmark ID
@ -1569,7 +1567,7 @@ coroutine whatever apply @{@{@} @{
set args [yield [info coroutine]]
while 1 @{
lassign $args why data
if @{$why > $::bookmarkfs::fsck::result::end@} @{
if @{$why > -1@} @{
lassign $data id extra name parent
puts "id: $id, extra: $extra, name: $name, parent: $parent"
@}

View file

@ -165,6 +165,9 @@ do_fsck (
if (result < 0) {
return -1;
}
if (result == BOOKMARKFS_FSCK_RESULT_END) {
result = -1;
}
goto run_handler;
}
#ifdef BOOKMARKFS_INTERACTIVE_FSCK

View file

@ -279,10 +279,8 @@ handle_entry (
int control = BOOKMARKFS_FSCK_NEXT;
if (!(ctx->flags & BOOKMARKFS_BACKEND_READONLY)) {
if (why != BOOKMARKFS_FSCK_RESULT_END) {
fix_entry(ctx, why, entry_data);
control = BOOKMARKFS_FSCK_APPLY;
}
fix_entry(ctx, why, entry_data);
control = BOOKMARKFS_FSCK_APPLY;
}
#ifdef BOOKMARKFS_INTERACTIVE_FSCK
if (ctx->flags & BOOKMARKFS_FSCK_HANDLER_INTERACTIVE) {

View file

@ -159,7 +159,6 @@ init_interp (
DO_SET_VAR(interp, "handler::reset", BOOKMARKFS_FSCK_RESET);
#define DO_SET_RESULT_VAR(interp, name, val) \
DO_SET_VAR(interp, "result::" name, BOOKMARKFS_FSCK_RESULT_##val)
DO_SET_RESULT_VAR(interp, "end", END);
DO_SET_RESULT_VAR(interp, "nameDuplicate", NAME_DUPLICATE);
DO_SET_RESULT_VAR(interp, "nameBadChar", NAME_BADCHAR);
DO_SET_RESULT_VAR(interp, "nameBadLen", NAME_BADLEN);
@ -365,6 +364,10 @@ fsck_handler_run (
break;
case BOOKMARKFS_FSCK_APPLY:
if (ctx->flags & BOOKMARKFS_BACKEND_READONLY) {
log_puts("cannot apply, fsck is running in readonly mode");
return -1;
}
if (TCL_OK != Tcl_ListObjIndex(interp, result_obj, 1, &data_obj)) {
log_puts("bad return value, no new name given");
return -1;