/* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc * Copyright (C) 2009, 2011-2012 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef _RAZOR_INTERNAL_H_ #define _RAZOR_INTERNAL_H_ #ifdef MSWIN_API #include #endif #include #include #include #include #include "razor.h" #include "types/types.h" /* GCC extensions */ #if defined(__GNUC__) && __GNUC__ >= 4 #define RAZOR_EXPORT __attribute__ ((visibility("default"))) #else #define RAZOR_EXPORT #endif #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define PADDING(value, base) (-(value) & (base - 1)) #define ALIGN(value, base) ((value) + PADDING(value, base)) void *zalloc(size_t size); struct razor_set_section { uint32_t name; uint32_t offset; uint32_t size; }; struct razor_set_header { uint32_t magic; uint32_t version; uint32_t num_sections; }; #define RAZOR_MAGIC 0x525a4442 #define RAZOR_STRING_POOL "string_pool" #define RAZOR_PACKAGES "packages" #define RAZOR_PROPERTIES "properties" #define RAZOR_PACKAGE_POOL "package_pool" #define RAZOR_PROPERTY_POOL "property_pool" #define RAZOR_PREFIX_POOL "prefix_pool" #define RAZOR_DETAILS_STRING_POOL "details_string_pool" #define RAZOR_FILES "files" #define RAZOR_FILE_POOL "file_pool" #define RAZOR_FILE_STRING_POOL "file_string_pool" struct razor_script { uint32_t program; uint32_t body; }; struct razor_package { unsigned int name : 24; unsigned int flags : 8; uint32_t version; uint32_t arch; uint32_t summary; uint32_t description; uint32_t url; uint32_t license; struct list_head properties; struct list_head files; struct list_head install_prefixes; struct razor_script preun; struct razor_script postun; }; struct razor_property { uint32_t name; uint32_t flags; uint32_t version; struct list_head packages; }; struct razor_entry { uint32_t name : 24; uint32_t flags : 8; uint32_t start; struct list_head packages; }; #define RAZOR_ENTRY_LAST 0x80 struct razor_set { uint32_t header_version; struct array string_pool; struct array packages; struct array properties; struct array files; struct array package_pool; struct array property_pool; struct array file_pool; struct array prefix_pool; struct array file_string_pool; struct array details_string_pool; struct razor_mapped_file *mapped_files; int lock_fd, ref_count; enum razor_set_flags flags; }; struct import_entry { uint32_t package; char *name; }; struct import_directory { uint32_t name, count; struct array files; struct array packages; struct import_directory *last; }; struct razor_importer { struct razor_set *set; struct hashtable table; struct hashtable file_table; struct hashtable details_table; struct razor_package *package; struct array properties; struct array files; struct array file_requires; struct array install_prefixes; }; struct razor_package_iterator { struct razor_set *set; struct razor_package *package, *end; struct list *index; int free_index; }; void razor_package_iterator_init_for_property(struct razor_package_iterator *pi, struct razor_set *set, struct razor_property *property); struct razor_property_iterator { struct razor_set *set; struct razor_property *property, *end; struct list *index; }; struct razor_file_iterator { struct razor_set *set; struct array path; struct list *index; int post_order; }; int razor_set_aquire_lock(struct razor_set *set, const char *path, int exclusive); struct razor_entry * razor_set_find_entry(struct razor_set *set, struct razor_entry *dir, const char *pattern); struct razor_merger * razor_merger_create(struct razor_set *set1, struct razor_set *set2); void razor_merger_add_package(struct razor_merger *merger, struct razor_package *package); struct razor_set * razor_merger_commit(struct razor_merger *merger); void razor_merger_package_add_script(struct razor_merger *merger, struct razor_package *package, enum razor_property_flags script, const char *program, const char *body); void razor_merger_destroy(struct razor_merger *merger); int run_lua_script(const char *root, const char *name, const char *body, ssize_t len, int arg1); int razor_run_script(const char *root, enum razor_property_flags script, const char *program, const char *body, int arg1); /* Utility functions */ void razor_package_get_details_varg(struct razor_set *set, struct razor_package *package, va_list args); void razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args); int razor_create_dir(const char *root, const char *path); int razor_remove(const char *path); int razor_write(int fd, const void *data, size_t size); void * razor_file_get_contents(const char *filename, size_t *length, int private, struct razor_error **error); int razor_file_free_contents(void *addr, size_t length); typedef int (*razor_compare_with_data_func_t)(const void *p1, const void *p, void *data); uint32_t * razor_qsort_with_data(void *base, size_t nelem, size_t size, razor_compare_with_data_func_t compare, void *data); struct environment { int is_set; struct array vars, string_pool; }; void environment_init(struct environment *env); void environment_add_variable(struct environment *env, const char *variable, const char *value); void environment_set(struct environment *env); void environment_unset(struct environment *env); void environment_release(struct environment *env); #ifdef MSWIN_API char *razor_utf16_to_utf8(const wchar_t *utf16, int len); wchar_t *razor_utf8_to_utf16(const char *utf8, int len); #endif /* Error functions */ struct razor_error { char *path; char *str; char *path_str; char *summary; char *msg; }; #ifdef MSWIN_API struct razor_error *razor_error_new_mswin(const wchar_t *path, DWORD error); struct razor_error *razor_error_new_str2(const wchar_t *path, const char *str); #define razor_set_error_mswin(error, path, err) \ if (error) \ *(error) = razor_error_new_mswin(path, err); \ else #define razor_set_error2(error, path, str) \ if (error) \ *(error) = razor_error_new_str2(path, str); \ else #endif /* MSWIN_API */ /* Atomic functions */ #if HAVE_WINDOWS_KTM struct razor_atomic { HANDLE transaction; int n_files; struct razor_atomic_file { wchar_t *path; HANDLE h; } *files; int in_undo; struct razor_error *error; }; #elif ENABLE_ATOMIC struct atomic_action { struct atomic_action *next; enum atomic_action_type { /* Complex actions */ ACTION_MAKE_DIRS, ACTION_REMOVE, /* Primitive actions */ ACTION_CREATE_DIR, #if HAVE_SYMLINK ACTION_CREATE_SYMLINK, #endif ACTION_MOVE, } type; struct { char *path; union atomic_action_args { struct { char *root; } make_dirs; struct { mode_t mode; } create_dir; #if HAVE_SYMLINK struct { char *target; } create_symlink; #endif struct { char *dest; } move; } u; } args; }; struct razor_atomic { struct atomic_action *actions; char *description; char *toplevel; unsigned next_file_tag; int in_undo; struct razor_error *error; }; char *atomic_action_attic_tmpnam(struct razor_atomic *atomic); struct atomic_action * atomic_action_list_prepend(struct atomic_action *list, struct atomic_action *action); struct atomic_action *atomic_action_new(enum atomic_action_type type); void atomic_action_free(struct atomic_action *action); struct atomic_action *atomic_action_list_reverse(struct atomic_action *list); struct atomic_action * atomic_action_do(struct razor_atomic *atomic, struct atomic_action *action); void atomic_action_undo(struct razor_atomic *atomic, struct atomic_action *action); #else /* !HAVE_WINDOWS_KTM && !ENABLE_ATOMIC */ struct razor_atomic { int in_undo; struct razor_error *error; }; #endif int razor_allow_all_root_names(void); int razor_valid_root_name(const char *name); #define RAZOR_ASCII_ISALPHA(c) \ ((c) >= 'A' && (c) <= 'Z' || (c) >= 'a' && (c) <= 'z') #ifdef MSWIN_API #define SKIP_DRIVE_LETTER(path) \ ((RAZOR_ASCII_ISALPHA(path[0]) && (path)[1] == ':') ? \ (path) + 2 : (path)) #else #define SKIP_DRIVE_LETTER(path) (path) #endif /* MSWIN_API */ #endif /* _RAZOR_INTERNAL_H_ */