Commit graph

90 commits

Author SHA1 Message Date
CismonX
d36c070ef2
backend_chromium: refactor parse_ts()
We only need to parse a single integer.
There's no chance that a 64-bit integer cannot hold a valid timestamp.
2025-03-20 10:11:35 +08:00
CismonX
00f40beec7
xstd: add helper function for getting current time
Also, don't bother with failed clock_gettime() calls.
2025-03-19 21:26:27 +08:00
CismonX
d7c7ec0174
bookmarkctl: xattr: misc refactor 2025-03-19 12:25:30 +08:00
CismonX
db0ca276b1
bookmarkctl: xattr-get: replace -N option with -qq
The `-N` option does not make sense without `-q`,
so we replace it with a second `-q`.
2025-03-18 06:08:30 +08:00
CismonX
4be158c988
fsck_util: rename: escape -> translit
In the `escape_control_chars()` function, we're not actually
"escaping" the characters, just replacing them.
2025-03-17 12:45:40 +08:00
CismonX
7ae2b283c3
bookmarkctl: add sub-commands for xattr
Provides platform-agnostic command-line interface for managing
extended attributes on a BookmarkFS filesystem.
2025-03-15 17:25:26 +08:00
CismonX
2ce0be8a18
bookmarkctl: better handling of command-line args 2025-03-13 14:45:10 +08:00
CismonX
68aafe3d8d
frontend: add helper macros for getopt() 2025-03-13 07:55:35 +08:00
CismonX
bd343ddf4b
backend_firefox: fix integer parsing 2025-03-12 17:22:54 +08:00
CismonX
0a4ff8770e
backend_firefox: misc refactor
- Follow the "best practice" in the SQLite manual, where calls to
  sqlite3_column_bytes() should come after sqlite3_column_text().
  This change does not affect the values returned.
- Other misc updates.
2025-03-11 16:22:29 +08:00
CismonX
48b1d8c98d
backend_firefox: tombstone for deleted bookmarks
If a bookmark is assigned SYNC_STATUS_NORMAL (value 2),
a "tombstone" has to be inserted upon deletion,
so that the browser could purge it from remote.
2025-03-10 14:40:26 +08:00
CismonX
217e185496
backend_firefox: temp ts buffer for usecs_now() 2025-03-09 16:27:09 +08:00
CismonX
85b02f6c2b
backend_firefox, fs_ops: store hashcode in entry
Trade a bit of memory for hashmap rehash/remove efficiency.
2025-03-09 15:44:29 +08:00
CismonX
3e6bcb8b4f
backend_firefox: set bookmark initial sync status
New bookmarks should be assigned SYNC_STATUS_NEW (value 1).
2025-03-09 14:21:13 +08:00
CismonX
1ed607de69
hashmap: tidy up log messages 2025-03-08 13:44:38 +08:00
CismonX
9fab17734c
chore: misc cleanup 2025-03-07 14:35:45 +08:00
CismonX
cadde0b61e
doc: update docs for the utility library
Move documentation for the hash table from source code comments
to the user manual.
2025-03-06 10:33:15 +08:00
CismonX
c2a91d6420
hashmap: refactor interface
- `hashmap_insert()` no longer takes key as argument, and
  takes the pointer to be associated with the entry as argument.
- Rename `hashmap_entry_delete` -> `hashmap_delete`.
- Make `user_data` the first argument for `hashmap_walk_func`.
- Other misc renames.
2025-03-06 06:40:28 +08:00
CismonX
b585a05c91
chore: remove null pointer representation check
That part of code in configure.ac look stupid, remove it.

If we _do_ try to run BookmarkFS on such an exotic platform with
non-zero null pointers, the breakage should be detected by the tests
(if it can run or even build at all).
2025-03-05 16:43:00 +08:00
CismonX
182967497d
sandbox: various fix and improvements
- Workaround a glibc issue for filtering negative syscall arguments.
- Allow unlinkat() syscall.
- Add extra filter for openat() in read-only mode when Landlock
  is not available.
2025-03-04 11:29:04 +08:00
CismonX
b8d03f008c
doc: add chapter for the utility library
Move the documentation of the following library components
from source code comments to the user manual:

- hash
- prng
- sandbox
- watcher
2025-03-02 11:18:34 +08:00
CismonX
b1100445b7
watcher: misc fix
- The initial `impl_rearm()` should always be performed by the
  worker thread, so that we won't get spurious zero returns from
  `watcher_poll()`.
- Sandboxing should not be implicitly disabled if not implemented.
- Shift internal watcher flags, to save space for public ones
  if we wish to add any in the future.
2025-03-02 06:54:06 +08:00
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