Commit graph

118 commits

Author SHA1 Message Date
CismonX
8cbd5846d9
chore: tidy up 2025-03-01 23:40:34 +08:00
CismonX
f3f522ae63
test: fix
- Address sanitizer may call sigaltstack().
  Add it to the syscall whitelist (debug only).
- Fix args count checking for `check-bookmarkfs-util watcher`.
2025-03-01 12:14:53 +08:00
CismonX
0b7b46be9c
watcher: refactor
- Use negated errno as return value.
- Do not consider deletion of the watched file as a fatal error,
  and use a separate error code to distinguish between them.
- Lazy-init worker: Starts watching upon the first call to
  watcher_poll().
2025-03-01 10:02:05 +08:00
CismonX
03da5fea5c
xstd: add convenience function xstrerror_save() 2025-03-01 07:40:13 +08:00
CismonX
6f11f51171
backend_firefox: rename msecs -> usecs
For microseconds, "usecs" is the correct abbreviation,
while "msecs" should be used for milliseconds.
2025-03-01 00:52:18 +08:00
CismonX
f952a35ddc
backend: misc refactor
- Following commit d01554400c, rename `attr_key_*` to `xattr_name_*`.
- Other misc changes.
2025-02-28 10:05:25 +08:00
CismonX
cd648f9ef0
backend_firefox: separator-aware
There's a special kind of bookmark in Firefox known as "separator",
which appears as vertical or horizontal bars in the browser.

BookmarkFS currently does not support managing separators, but
the backend should be aware of their existence, and must not break
when one appears.

A separator always has a NULL `title` and `fk` in `moz_bookmarks`,
so it doesn't break `bookmark_list()` and `bookmark_lookup()`,
but breaks `bookmark_check()` since it could be mistaken for a
bookmark or bookmark folder with NULL title.

Fix by checking the bookmark type in `bookmark_check_cb()`.
2025-02-28 00:07:24 +08:00
CismonX
348f13df02
backend_firefox: improve length(url) performace
The SQLite builtin function `length()` calculates the number of
Unicode code points of the given argument, while `octet_length()`
calculates the number of bytes.

The two functions should produce the same result for a URL since it's
always ASCII-only, however, with `octet_length()` the length can be
directly fetched from metadata without actually reading the URL text,
thereby improving performance.
2025-02-27 14:26:24 +08:00
CismonX
f737aa9868
chore: remove bad copy-pasted comment lines 2025-02-26 14:58:42 +08:00
CismonX
b33f2ced0b
fsck: limit history list length
Add a hard limit to prevent the history command list from growing
unnecessarily large, especially when interactive fsck is automated
with scripting.
2025-02-26 14:46:29 +08:00
CismonX
0fd2cbbc9d
backend_firefox: no db_check() in sandbox mode
Following commit 35d4a93a41, now only perform `PRAGMA quick_check`
in non-sandbox mode before querying data on the database.

Although in practice SQLite does well in terms of memory safety,
most likely way better than BookmarkFS itself, we consider
sandboxing a stronger security guarantee than `PRAGMA quick_check`.
2025-02-26 14:06:18 +08:00
CismonX
d01554400c
backend: rename ATTR_KEY_* -> BM_XATTR_* 2025-02-26 13:56:18 +08:00
CismonX
55c0726c7f
all: minor refactor 2025-02-26 00:23:27 +08:00
CismonX
7816e955b7
fsck: remove unnecessary isatty() checks
There are legitimate use cases for interactive fsck.bookmarkfs
without a terminal, and Readline works fine without one.
2025-02-25 08:35:15 +08:00
CismonX
3e5c800de8
backend_chromium: improve sandboxing
- Always lazy-init watcher when possible.
- Add a check in `backend_create()` that fails when the bookmark
  storage does not exist, so that function behavior is more
  consistent on different platforms with and without sandboxing.
- Only check Landlock flags on Linux.
2025-02-24 17:45:52 +08:00
CismonX
bd90602d4a
xattr: misc refactor
- Check for XATTR_CREATE in setxattr.
- Rename bookmark_attrs -> xattr_names.
- Other misc changes.
2025-02-19 11:34:03 +08:00
CismonX
d7724e9a8f
db: disable SQL printing in debug mode by default 2025-02-18 10:31:55 +08:00
CismonX
fef7b4d3a8
backend: remove BOOKMARKFS_BOOKMARK_DELETE_DIR
It's up to the backend to check whether it's deleting a directory.
2025-02-17 17:52:50 +08:00
CismonX
c90c5f6fc7
all: fix build with musl libc
- Should not assume whether O_xxx macros are defined by checking
  feature test macros.
- Workaround conflicting getdents() declaration.
2025-02-16 00:19:51 +08:00
CismonX
1db61bc878
all: debug_puts() should accept arbitrary string 2025-02-15 19:38:15 +08:00
CismonX
bf9e0e7f92
sandbox: workaround legacy landlock
So that they can build with kernel headers older than 6.2,
and still work as expected on newer kernels.
2025-02-15 19:08:08 +08:00
CismonX
9afdfc45d7
backend: rename bookmark_check args
- Rename `id` -> `parent_id`, since the function works on
  the parent directory.
2025-02-13 17:48:07 +08:00
CismonX
52b3707d2b
backend: rename bookmark_fsck -> bookmark_check
Some relevant names are also renamed.
2025-02-12 20:47:10 +08:00
CismonX
3375674973
backend: ignore val_len when updating timestamps 2025-02-12 12:36:30 +08:00
CismonX
e199a1203a
backend: fix includes
Fix a regression in commit d1dac54b72 where sys/stat.h is no longer
included in backend_firefox.c and backend_chromium.c.

It has to be explicitly included for the UTIME_xxx macros.
2025-02-10 19:55:43 +08:00
CismonX
916102484f
all: only log line numbers in debug mode 2025-02-10 18:43:15 +08:00
CismonX
cd3d6a6232
backend_firefox: improve mkfs
Switch to schema version 74, so that it is compatible with
browsers (e.g., GNU IceCat) which are still based on
Firefox 115 ESR (now end-of-life), as well as saving us
a bit more space since there are fewer tables to be created.
2025-02-10 18:40:00 +08:00
CismonX
4f8b15fd80
backend_firefox: improve bookmark storage init
- Check schema version when initializing database.
- Minor refactor for db_check().
2025-02-09 23:49:21 +08:00
CismonX
df29392008
all: fix conditional build
There were bad code changes that cause the compiler to complain or
panic, but went unnoticed since they are only built if toggled with
`--enable-xxx` or `--disable-xxx` during build configuration.

Fix them altogether.
2025-02-08 19:47:20 +08:00
CismonX
d1dac54b72
chore: tidy up includes 2025-02-08 18:56:45 +08:00
CismonX
b195e7821a
hash: add hash_digestcb() function
May be useful for calculating hash of a stream of input data.
2025-02-06 16:09:58 +08:00
CismonX
767e25e867
xstd: update xabort_() output format 2025-02-05 18:28:22 +08:00
CismonX
d99ef6d681
chore: update links
- Specify the full homepage URL.
- Follow GNU's naming convention for mailing lists.
2025-02-05 18:11:37 +08:00
CismonX
fbed71ce3e
all: add line number to log output 2025-02-04 20:55:49 +08:00
CismonX
852caab209
doc: misc update 2025-02-04 20:55:29 +08:00
CismonX
d0aa74b212
backend: rename object_free -> cookie_free 2025-02-03 18:15:52 +08:00
CismonX
1d1ff58aa4
ioctl: move type definitions to common.h 2025-02-02 21:35:12 +08:00
CismonX
031691fae5
build: move BUILDING_BOOKMARKFS to config.h 2025-02-02 18:51:48 +08:00
CismonX
d08848c097
db: minor refactor 2025-02-02 17:55:14 +08:00
CismonX
54c81c43bb
all: fix __FILE_NAME__ workaround
Do not apply offset for __FILE__ in non-VPATH build,
since the path is not prefixed with `${srcdir}/` in that case.
2025-02-02 17:48:42 +08:00
CismonX
c17d6ebadf
all: better workaround for __FILE_NAME__
There's only a few legacy releases of gcc and clang that
support -fmacro-prefix-map but not __FILE_NAME__.
Thus the originial workaround is not very beneficial.

Switching to a more portable `__FILE__ + offset` workaround
that works for any standard-compliant compiler, even TinyCC.

However, this workaround may produce binaries that leak
information about the build environment, especially when using
an exotic build path.
2025-02-01 23:25:19 +08:00
CismonX
88e38bd38e
backend: update cookie even on callback failure
No need to check status and always update cookie after
invoking callback for bookmark_list() and bookmark_fsck().
2025-02-01 00:21:02 +08:00
CismonX
78b80be2e5
backend: rename struct bookmarkfs_bookmark_entry
Rename field `next` -> `off`.
2025-01-31 20:31:52 +08:00
CismonX
341b7b3d5a
doc: misc update
- Add manual section for the utility library.
- Add comments for utility library functions.
- Fix installation path for backends and fsck handlers.
2025-01-28 20:56:06 +08:00
CismonX
50f05d2bd3
all: relax compiler requirements
- Do not check __STDC_HOSTED__.
- Do not use atomic builtins.
- Do not use thread-local storage for PRNG state.
2025-01-28 20:20:20 +08:00
CismonX
56fa90397d
fs_ops: limit xattr value length 2025-01-27 23:48:37 +08:00
CismonX
3ed11f53e5
backend: fix xattr bookmark title check
Do not check if the bookmark title is a valid filename,
as we said in the user manual.

However, we should ensure that the string does not contain
NUL characters, since we assume that a valid bookmark storage
should not contain bookmarks with such names.
2025-01-26 19:35:03 +08:00
CismonX
996ca0e042
backend_firefox: fix and refactor mkfs
- Make sure all tables and indices are created for the database,
  even the ones that are not used by BookmarkFS.
- Maintain the schema version in `PRAGMA user_version`.
- Always use `INT` for integer type, and `TEXT` for text type,
  so that we could save a little space.  This does not affect the
  actual datatype (more precisely, type affinity) of the columns.
2025-01-26 00:19:54 +08:00
CismonX
3b45900157
db: allow non-integer argument for safeincr 2025-01-25 21:25:37 +08:00
CismonX
35d4a93a41
backend_firefox: fix sandbox
- Allow fdatasync(), since it is used by SQLite when commiting.
- Move `PRAGMA quick_check` to backend_create(), since it sometimes
  calls stat() and cannot be sandboxed.
2025-01-25 21:15:57 +08:00