Magisk/jni/utils/utils.h

105 lines
3.8 KiB
C
Raw Normal View History

2017-04-07 00:21:20 +02:00
/* util.h - Header for all utility functions
*/
2017-04-04 21:44:13 +02:00
#ifndef _UTILS_H_
#define _UTILS_H_
#include <stdio.h>
2017-04-07 00:21:20 +02:00
#include <dirent.h>
#include <pthread.h>
2017-04-08 01:37:43 +02:00
#include <sys/types.h>
#include <sys/socket.h>
2017-04-14 21:23:09 +02:00
#include <sys/stat.h>
2017-04-04 21:44:13 +02:00
2017-04-08 01:37:43 +02:00
#include "vector.h"
2017-04-04 21:44:13 +02:00
2017-04-14 21:23:09 +02:00
#define UID_SHELL (get_shell_uid())
#define UID_ROOT 0
#define UID_SYSTEM (get_system_uid())
#define UID_RADIO (get_radio_uid())
2017-04-17 10:36:49 +02:00
extern int quit_signals[];
2017-04-04 21:44:13 +02:00
// xwrap.c
FILE *xfopen(const char *pathname, const char *mode);
2017-05-07 21:11:14 +02:00
FILE *xfdopen(int fd, const char *mode);
2017-04-28 15:48:38 +02:00
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define xopen(...) GET_MACRO(__VA_ARGS__, xopen3, xopen2)(__VA_ARGS__)
int xopen2(const char *pathname, int flags);
int xopen3(const char *pathname, int flags, mode_t mode);
2017-04-06 00:12:29 +02:00
ssize_t xwrite(int fd, const void *buf, size_t count);
ssize_t xread(int fd, void *buf, size_t count);
ssize_t xxread(int fd, void *buf, size_t count);
2017-07-10 16:29:53 +02:00
int xpipe2(int pipefd[2], int flags);
2017-04-06 00:12:29 +02:00
int xsetns(int fd, int nstype);
2017-04-07 00:21:20 +02:00
DIR *xopendir(const char *name);
struct dirent *xreaddir(DIR *dirp);
2017-04-08 01:37:43 +02:00
pid_t xsetsid();
int xsocket(int domain, int type, int protocol);
int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int xlisten(int sockfd, int backlog);
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
2017-04-08 01:37:43 +02:00
void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *ptr, size_t size);
ssize_t xsendmsg(int sockfd, const struct msghdr *msg, int flags);
ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags);
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
2017-04-17 10:36:49 +02:00
void *(*start_routine) (void *), void *arg);
int xsocketpair(int domain, int type, int protocol, int sv[2]);
2017-04-14 21:23:09 +02:00
int xstat(const char *pathname, struct stat *buf);
2017-05-03 19:13:04 +02:00
int xlstat(const char *pathname, struct stat *buf);
2017-04-14 21:23:09 +02:00
int xdup2(int oldfd, int newfd);
2017-04-15 12:10:54 +02:00
ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz);
int xsymlink(const char *target, const char *linkpath);
2017-04-17 10:36:49 +02:00
int xmount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
2017-05-03 19:13:04 +02:00
int xumount(const char *target);
int xumount2(const char *target, int flags);
2017-04-17 10:36:49 +02:00
int xchmod(const char *pathname, mode_t mode);
int xrename(const char *oldpath, const char *newpath);
int xmkdir(const char *pathname, mode_t mode);
2017-04-28 15:48:38 +02:00
void *xmmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset);
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count);
2017-04-30 19:58:52 +02:00
int xmkdir_p(const char *pathname, mode_t mode);
2017-04-04 21:44:13 +02:00
2017-04-06 00:12:29 +02:00
// misc.c
2017-04-14 21:23:09 +02:00
unsigned get_shell_uid();
unsigned get_system_uid();
unsigned get_radio_uid();
2017-04-06 00:12:29 +02:00
int check_data();
2017-04-20 16:45:56 +02:00
int file_to_vector(const char* filename, struct vector *v);
int vector_to_file(const char* filename, struct vector *v);
2017-04-07 00:21:20 +02:00
int isNum(const char *s);
2017-04-18 13:32:50 +02:00
ssize_t fdgets(char *buf, size_t size, int fd);
2017-04-07 00:21:20 +02:00
void ps(void (*func)(int));
void ps_filter_proc_name(const char *filter, void (*func)(int));
2017-04-15 12:10:54 +02:00
int create_links(const char *bin, const char *path);
2017-04-15 12:33:16 +02:00
void unlock_blocks();
2017-04-17 10:36:49 +02:00
void setup_sighandlers(void (*handler)(int));
2017-06-07 21:20:49 +02:00
int run_command(int err, int *fd, const char *path, char *const argv[]);
2017-04-30 19:58:52 +02:00
int mkdir_p(const char *pathname, mode_t mode);
int bind_mount(const char *from, const char *to);
int open_new(const char *filename);
2017-05-03 19:13:04 +02:00
int cp_afc(const char *source, const char *target);
int clone_dir(const char *source, const char *target);
int rm_rf(const char *target);
2017-07-01 08:05:54 +02:00
void fclone_attr(const int sourcefd, const int targetfd);
2017-05-04 22:16:00 +02:00
void clone_attr(const char *source, const char *target);
2017-05-05 10:13:26 +02:00
void get_client_cred(int fd, struct ucred *cred);
2017-06-24 16:37:45 +02:00
int switch_mnt_ns(int pid);
// img.c
2017-06-02 21:58:26 +02:00
int create_img(const char *img, int size);
int get_img_size(const char *img, int *used, int *total);
int resize_img(const char *img, int size);
2017-06-24 16:37:45 +02:00
char *mount_image(const char *img, const char *target);
void umount_image(const char *target, const char *device);
2017-04-06 00:12:29 +02:00
#endif