Commit graph

118 commits

Author SHA1 Message Date
CismonX
14b5a79147
build: fix builds with existing utility library
Regression in commit 81db7a786c.
2025-06-11 17:11:19 +08:00
CismonX
6f2a00dd6f
fs_ops: refactor setattr
- Only perform one operation per call.
- Always fail with EPERM if given unsupported flags.
2025-06-09 19:51:25 +08:00
CismonX
fdfd6fe069
backend_firefox: fix directory attr update 2025-06-08 07:24:39 +08:00
CismonX
5082e7c67c
fs_ops: fix mtime update of regular files
Explicit mtime update (e.g., via futimens(2)) should override
file handle mtime.
2025-06-07 19:55:27 +08:00
CismonX
72b9e200d9
fs_ops: misc refactor
- Use nodeid for fh_map keys as well as bm_*() and intfs_*() args.
- bm_readdir(), fs_op_rename(): check subsys type more gracefully.
- ...
2025-06-07 08:57:48 +08:00
CismonX
29338ca02b
backend_firefox: purge dangling refs on delete
When a bookmark is deleted, if there are no other bookmarks
referencing the corresponding `moz_place` entry, tag and keyword
references to that entry are considered "dangling" references,
and shall be automatically removed.

Also reverts commit b5fa6960ef,
since the NULL title check is no longer necessary.
2025-06-06 22:46:44 +08:00
CismonX
eb426f9fc4
bookmarkctl: xattr-get: rename -m option to -a 2025-06-06 19:41:09 +08:00
CismonX
b5fa6960ef
backend_firefox: hide dangling keywords
When a bookmark associated with a keyword is deleted,
there may still be dangling references (e.g., tags) to the
corresponding `moz_places` entry.

By filtering out NULL titles, `bookmark_lookup()` and
`bookmark_list()` now only give keywords associated with
valid bookmarks.
2025-06-05 08:27:59 +08:00
CismonX
6fb9438d3c
fs_ops: fix opendir for keyword directory 2025-06-05 07:39:53 +08:00
CismonX
495f8592e6
fs_ops: fix deletion of tag directories 2025-06-02 08:41:33 +08:00
CismonX
e6809b7e84
xstd: add xgetdents() 2025-05-28 18:27:55 +08:00
CismonX
5a28b069c4
fs_ops: fix file size opened with O_CREAT|O_TRUNC
Also make sure that new regular files always have a size of zero.
2025-04-29 14:48:39 +08:00
CismonX
83f201435f
backend_firefox: add keyword xattr
This allows users to quickly discover which keyword is
associated with a given bookmark.

Updating keywords via xattr is not implemented,
since it can be done trivially using existing API.
2025-04-29 12:46:29 +08:00
CismonX
0e20604c73
backend_firefox: fix stmt id for keyword delete 2025-04-28 20:04:40 +08:00
CismonX
565063ee9b
chore: bump version to 0.1.1 2025-04-07 12:23:50 +08:00
CismonX
763bba9444
backend_firefox: fix bookmark_check()
Regression in commit 85b02f6c2b.
2025-04-03 10:23:54 +08:00
CismonX
5ad23ac8f6
hashmap: allow rehash failure
There is a chance that rehash may fail,
even with a decent hash function, and no collision attack.

Allow the hashmap to be rehashed for a second time during insert,
and ignore rehash failures during delete.
2025-04-03 09:51:09 +08:00
CismonX
159c2c7625
fsck_util: improve fsck output format
Now the built-in fsck handler and `bookmarkctl fsck` produces
output that is both parsable and human-readable.

Also document the output format in the user manual.
2025-03-30 14:10:31 +08:00
CismonX
63d8b8e213
backend_firefox: fix sqlite version compatibility
In commit 348f13df02, we replaced
`length(url)` with `octet_length(url)`.
However, `octet_length` was added in SQLite 3.43, while we claim to
support SQLite 3.35 and later.

Stable GNU/Linux distros like Debian may still be using pre-3.43
releases of SQLite, so don't bump that version too soon.
Instead, use `length(CAST(url AS BLOB))`, which is a bit less
efficient than `octet_length(url)`, but O(1) nonetheless.
2025-03-29 16:14:10 +08:00
CismonX
c9ccc4f6df
backend_chromium: fix use-after-free
It's a regression in commit bdfa812d79.
2025-03-29 13:22:52 +08:00
CismonX
bdfa812d79
backend: respect the BOOKMARK_DELETE_DIR flag
Following commit 2e3685f217,
make sure all backends check this flag and return correct error codes.

Normally this is not mandatory, since the kernel looks up
the directory entry to be removed, and fails if the system call
is inappropriate (e.g., calling rmdir() on a regular file).
This happens before FUSE_UNLINK or FUSE_RMDIR is sent to the server.

However, when not in exclusive mode, there is a short window that
TOCTOU problem may occur, which may lead to undesired behavior
(e.g., deletion of a non-empty directory) or even the corruption of
bookmark storage if not properly checked.

Also explain this flag in the user manual.
2025-03-27 12:36:27 +08:00
CismonX
2e3685f217
backend_firefox: fix directory deletion
Also reverts commit fef7b4d3a8.

The DELETE_DIR flag is in fact useful, but bookmark_delete()
incorrectly checked CREATE_DIR instead.
2025-03-26 19:03:00 +08:00
CismonX
bd80cbf2c1
frontend: silently ignore empty subopts 2025-03-25 12:19:11 +08:00
CismonX
3422d68193
backend: allow bad system time in readonly mode
In readonly mode, we're not using the current time as timestamp,
thus a bad system time won't hurt.

Also in Chromium backend, use zero timestamp for the bookmark root
dir, to accomodate this change (no one cares about it anyway).
2025-03-23 14:56:16 +08:00
CismonX
2024008373
frontend_util: fix usage of xasprintf()
Expressions with side effects should not be passed as arguments,
since they may be used multiple times.
2025-03-22 10:53:04 +08:00
CismonX
750c16077c
backend: prevent timestamp overflow
When updating timestamps, make sure that the corresponding
microsecond value fits in a single signed 64-bit integer,
so that it won't result in an integer overflow, which is UB.

Also forbid timestamps before the Unix epoch, since working with
negative time_t is problematic.

This check does not apply to current timestamp, however,
add a check on backend startup to ensure sane system time.

There's no need to validate `tv_nsec`, since the kernel already
does that for us.
2025-03-20 12:46:11 +08:00
CismonX
09e186b348
fs_ops: fix setattr 2025-03-20 12:21:47 +08:00
CismonX
e0d2aa2058
backend: refactor bookmark_set() for timestamps
Do not expose UTIME_OMIT to backends, but instead specify
which timestamps to update with flags.

This allows us to further refactor backend code, especially
the Chromium backend.
2025-03-20 12:14:59 +08:00
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