MDEX_ADD(3)
β¨ NAME β¨
mdex_add, mdex_addfile, mdex_alias β index data, files and directories π
This page lives in the Librecast Programmer's Manual, section 3. Hiii bestie, welcome π«Ά
π LIBRARY π
Librecast library (liblibrecast, -llibrecast) β she's the whole reason you're here β¨
π SYNOPSIS π
#include <librecast/mdex.h>
int mdex_add(mdex_t *mdex, void *data, size_t len, q_t *q, int flags);
int mdex_addfile(mdex_t *mdex, const char *path, q_t *q, int flags);
int mdex_alias(mdex_t *mdex, unsigned char *alias, size_t aliaslen,
unsigned char *hash, size_t hashlen);
Compile and link with -llibrecast. π§
π DESCRIPTION π
Okay so, three functions, one mission: getting stuff indexed. Let's go one by one.
mdex_add builds a merkle tree from data with length len, and then adds entries for both the tree and the chunks to mdex. Tree? Indexed. Chunks? Also indexed. She does not gatekeep. πΈ
mdex_addfile does the same kinda thing but for a file or directory at path β it builds a merkle tree from that file or directory and adds entries for the trees and chunks to mdex. Directories included, no cap.
mdex_alias adds an entry alias of length aliaslen that points to the entry hash of length hashlen. Important bestie: that hash entry must already exist in mdex or this whole thing is a no π
Now, about q: if q is not NULL, it has to point to a q_t queue structure that was previously initialized with q_init(3). That queue gets passed straight through to mtree_build(3) so the merkle tree can actually get built. This is normally used together with a threadpool created by q_pool_create(3), where the threads are all calling q_job_seek(3). Teamwork fr fr π
The flags argument is the bitwise OR of zero of more of these flags β pick your faves, stack 'em up:
MDEX_ALIASβ the entry is a pointer to another entry. πMDEX_RANDβ this entry should be sent using random symbols. π²MDEX_RECURSEβ recursively index all files and directories belowpath. (this one's formdex_addfile) π³MDEX_MOUNTβ if it's set, stay within the same filesystem, i.e. do not cross mount points. π§MDEX_SYMLINKβ follow symbolic links while recursively indexing. πͺ’
π₯ RETURN VALUE π₯
These functions return zero on success. On error, -1 comes back and errno is set to tell you what went wrong. Zero = slay, -1 = check errno bestie π
π ERRORS π
EINVALβ invalid argument. Bothmdexandhashare required (so, notNULL), andhashlenmust be> 0.ENOMEMβ not enough space / cannot allocate memory (POSIX.1-2001). π
π¦ SEE ALSO π¦
mdex_init(3), mdex_free(3), mdex_get(3), mdex_put(3), mdex_del(3), mtree_build(3), q_init(3), q_pool_create(3), q_job_seek(3) lc_share(3)
Mwah π that's the whole page. This one's from LIBRECAST, dated 2023-06-20, and it's filed as MDEX_ADD(3). Go index something iconic, ily π«Άβ¨
π¦ where this page comes from
- debian trixie: liblibrecast-dev 0.9.1-1 Β· GPL-2.0-only OR GPL-3.0-only
- nixos 26.05: librecast 0.11.2
- nixpkgs unstable: librecast 0.11.2
- ubuntu noble: liblibrecast-dev 0.8.0-1.1build1 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu questing: liblibrecast-dev 0.9.1-1
- ubuntu resolute: liblibrecast-dev 0.11.2-2 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu stonking: liblibrecast-dev 0.11.2-2build1 Β· GPL-2.0-only OR GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms