15#define RAT_MACHINE_ARCH "x86_64"
17#define RAT_MACHINE_ARCH "i686"
21#define RAT_ENTRIES_MAX 65536
24#define RAT_TEXT_MAX 512
27#define RAT_KEYS_DIR "etc/rat/keys"
30#define RAT_RATINFO_MAX 65536
33#define RAT_STAGE_NAME_MAX 66
93char *
rat_read_file(const
char *path,
size_t max,
size_t *size_out);
258#define RAT_NEW_SUFFIX ".ratnew"
void rat_stage_name(const char *path, char out[RAT_STAGE_NAME_MAX])
the name of a path in the stage folder: 'f' and the SHA-256 of the path
Definition archive.c:608
int rat_package_unpack(const char *path, const char *arch, const char *stage, rat_package_t *package, rat_error_t *err)
read and check a package file, as rat_package_read.
Definition archive.c:519
settings files: sections of "key = value" lines.
struct conf conf_t
Definition conf.h:37
char * rat_files_record_text(const rat_entry_t *entries, int count)
the text of a files record.
Definition db.c:142
int rat_owners_load(rat_t *rat, rat_owners_t *owners, rat_error_t *err)
read base.files and the files records of every installed package.
Definition db.c:291
void rat_owners_free(rat_owners_t *owners)
release the owners
Definition db.c:328
bool rat_owned_by_other(const rat_owners_t *owners, const char *path, const char *name)
true if the base image, or a package other than name, owns path
Definition db.c:364
int rat_read_files_record(const char *path, rat_entry_t **entries_out, int *count_out, rat_error_t *err)
read the record of the files of a package (installed/<name>/files).
Definition db.c:94
const rat_owned_t * rat_owners_find(const rat_owners_t *owners, const char *path, int *count_out)
the owners of a path.
Definition db.c:339
int rat_download(const char *url, const char *path, uint64_t max_size, rat_progress_t progress, void *context, rat_error_t *err)
download a URL into a file.
Definition download.c:69
int rat_index_parse(const char *text, const char *arch, rat_index_t *index, rat_error_t *err)
read the text of index.conf and check every field.
Definition index.c:136
void rat_remote_clear(rat_remote_t *remote)
release the strings of one package of an index
Definition index.c:205
int rat_parse_number(const char *text, uint64_t max, uint64_t *out)
a whole number of decimal digits only, at most max.
Definition info.c:70
bool rat_text_ok(const char *text)
a text field: at most RAT_TEXT_MAX bytes, and no control characters
Definition info.c:53
bool rat_version_ok(const char *version)
a version: 1 to RAT_VERSION_MAX characters of 0-9 a-z A-Z .
Definition info.c:34
int rat_parse_info(const char *text, rat_info_t *info, rat_error_t *err)
fill info from the text of .RATINFO and check its fields.
Definition info.c:168
int rat_info_from_conf(const conf_t *conf, const char *section, const char *where, rat_info_t *info, rat_error_t *err)
fill info from one section of a parsed file and check its fields.
Definition info.c:121
bool rat_txn_pending(const rat_t *rat)
true if the list of an interrupted change is there
Definition txn.c:414
int rat_compare_entries(const void *a, const void *b)
compare two entries by path, for qsort and bsearch
Definition util.c:482
void rat_sort_entries(rat_entry_t *entries, int count)
sort entries by path
Definition util.c:487
rat_disk_t rat_disk_state(const rat_t *rat, const rat_entry_t *entry)
compare a file or link of a record with the disk
Definition remove.c:21
void rat_txn_free(rat_txn_t *txn)
Definition txn.c:43
int rat_mkdirs(const char *path, uint32_t mode)
make a folder and the folders above it that are not there.
Definition util.c:385
void rat_hex(const uint8_t sha[32], char out[65])
the SHA-256 as 64 hexadecimal digits and a '\0'
Definition util.c:184
int rat_test_stop_after
for the host tests only: when 0 or more, a transaction stops after this number of operations,...
Definition txn.c:36
int rat_write_file(const char *path, const void *data, size_t size, uint32_t mode)
write a file so that a crash leaves the old file or the new one: to <path>.new, fsync,...
Definition util.c:342
char * rat_strdup(const char *s)
a copy of a string, or NULL when there is no memory
Definition util.c:46
int void rat_say(rat_note_t note, void *context, const char *format,...) __attribute__((format(printf
give a note to the caller (printf format); nothing when note is NULL
int rat_unhex(const char *text, uint8_t sha[32])
read 64 hexadecimal digits.
Definition util.c:209
bool rat_is_settings(const rat_entry_t *entry)
true if a path of a package is a settings file: a file under etc/.
Definition util.c:495
const char * rat_check_path(const char *path, char out[RAT_PATH_MAX+1])
check a path of a package and make it the normal form: a "./" at the start and a '/' at the end are r...
Definition util.c:74
int rat_sha256_file(const char *path, uint8_t sha[32], uint64_t *size_out)
the SHA-256 and size of a file.
Definition util.c:224
const char * rat_check_link(const char *path, const char *target)
check the target of a symbolic link at path: relative, and inside the package root when it is resolve...
Definition util.c:130
int rat_remove_tree(const char *path)
remove a file, a link, or a folder with everything in it.
Definition util.c:418
int rat_signature_check(const rat_t *rat, const void *data, size_t size, const void *signature, size_t signature_size, rat_error_t *err)
check a detached signature: ECDSA P-256 over the SHA-256 of the data, in DER.
Definition signature.c:63
int rat_recover(rat_t *rat, rat_error_t *err)
finish the transaction of an earlier rat that stopped, or remove its stage folder.
Definition txn.c:357
void rat_entry_clear(rat_entry_t *entry)
release the members of an entry
Definition util.c:465
void rat_txn_init(rat_txn_t *txn)
Definition txn.c:38
rat_disk_t
what is on the disk at the path of a file or link of an installed package
Definition internal.h:265
@ RAT_DISK_SAME
Definition internal.h:267
@ RAT_DISK_CHANGED
Definition internal.h:268
@ RAT_DISK_GONE
Definition internal.h:266
@ RAT_DISK_FOLDER
Definition internal.h:269
int int rat_txn_commit(rat_t *rat, rat_txn_t *txn, const char *note, rat_error_t *err)
write the list and do it, then remove the list and the stage folder.
Definition txn.c:317
int rat_fail(rat_error_t *err, const char *format,...) __attribute__((format(printf
set the message of err (printf format).
char * rat_read_file(const char *path, size_t max, size_t *size_out)
read a whole file into memory, with a '\0' after it.
Definition util.c:261
int rat_txn_add(rat_txn_t *txn, const char *format,...) __attribute__((format(printf
add one operation (printf format, without the ' ').
int void char * rat_path(const rat_t *rat, const char *rel)
a path on the root: <root>/<rel>.
Definition util.c:57
#define RAT_STAGE_NAME_MAX
the size of a name in the stage folder: 'f', 64 hex digits, '\0'
Definition internal.h:33
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
buffered streams and formatted input/output.
int printf(const char *fmt,...) __attribute__((format(printf
formatted output.
librat: the package manager of ginnOS.
#define RAT_ERROR_MAX
Definition rat.h:32
#define RAT_PATH_MAX
Definition rat.h:31
void(*) rat_progress_t(void *context, const char *file, uint64_t done, uint64_t total)
a function that gets the progress of a download.
Definition rat.h:130
void(*) rat_note_t(void *context, const char *text)
a function that gets the notes of a change (one line, without ' ')
Definition rat.h:123
struct rat rat_t
an open root folder
Definition rat.h:120
ELF32 file header.
Definition elf.h:51
a folder, file or symbolic link of a package
Definition rat.h:53
a message about a failure
Definition rat.h:39
the index of the repository, after its signature was checked
Definition rat.h:95
the fields of .RATINFO
Definition rat.h:64
the owners of all paths: the base image and the installed packages
Definition internal.h:221
const char * owner
Definition internal.h:223
char type
Definition internal.h:224
const char * path
Definition internal.h:222
Definition internal.h:228
rat_owned_t * items
Definition internal.h:229
char ** strings
Definition internal.h:231
int count
Definition internal.h:230
int string_count
Definition internal.h:232
a package file that was read and checked
Definition rat.h:77
a package of the index of the repository
Definition rat.h:86
a list of operations that is being made
Definition internal.h:167
char * text
Definition internal.h:168
size_t capacity
Definition internal.h:170
size_t used
Definition internal.h:169
char * root
Definition internal.h:37
int lock_fd
Definition internal.h:38
bool writable
Definition internal.h:39
bool pending
Definition internal.h:40
char recovered[RAT_ERROR_MAX]
Definition internal.h:41