diff --git a/cmd/vu_insmod.c b/cmd/vu_insmod.c index ba51c6b..15366a2 100644 --- a/cmd/vu_insmod.c +++ b/cmd/vu_insmod.c @@ -28,14 +28,14 @@ static char *progname; void usage() { - fprintf(stderr, + fprintf(stderr, "Usage:\n" " %s OPTIONS vu_module [vu_module] ...\n" " OPTIONS:\n" " -p --permanent: rmmod forbidden\n\n" " -h --help: print this help message\n\n", progname); - exit(2); + exit(2); } static const char *short_options = "p"; @@ -47,38 +47,38 @@ static const struct option long_options[] = { int main(int argc, char *argv[]) { - int c; - int permanent=0; + int c; + int permanent=0; progname = basename(argv[0]); - if (vu_check() < 0) { - fprintf(stderr,"This is a VUOS command." + if (vu_check() < 0) { + fprintf(stderr,"This is a VUOS command." "It works only inside a vuos virtual namespace\n"); - usage(); - } - while (1) { - c=getopt_long(argc, argv, + usage(); + } + while (1) { + c=getopt_long(argc, argv, short_options, long_options, NULL); - if (c == -1) break; - switch (c) { - case 'p': permanent=1; - break; - case 'h': usage(); - break; - } - } - if (argc - optind < 1) - usage(); - else { - int rv=0; - int i; - for (i = optind; i < argc; i++) { - if (vu_insmod(argv[i], permanent) < 0) { - perror(argv[i]); - rv=1; - } - } - return rv; - } - return 0; + if (c == -1) break; + switch (c) { + case 'p': permanent=1; + break; + case 'h': usage(); + break; + } + } + if (argc - optind < 1) + usage(); + else { + int rv=0; + int i; + for (i = optind; i < argc; i++) { + if (vu_insmod(argv[i], permanent) < 0) { + perror(argv[i]); + rv=1; + } + } + return rv; + } + return 0; } diff --git a/cmd/vu_lsmod.c b/cmd/vu_lsmod.c index cf679e0..9167aaf 100644 --- a/cmd/vu_lsmod.c +++ b/cmd/vu_lsmod.c @@ -28,12 +28,12 @@ static char *progname; void usage() { - fprintf(stderr, + fprintf(stderr, "Usage:\n" " %s OPTIONS\n" " OPTIONS:\n" " -h --help: print this help message\n\n", progname); - exit(2); + exit(2); } static const char *short_options = "p"; @@ -44,25 +44,25 @@ static const struct option long_options[] = { int main(int argc, char *argv[]) { - int c; + int c; progname = basename(argv[0]); size_t bufsize; - if (vu_check() < 0) { - fprintf(stderr,"This is a VUOS command." + if (vu_check() < 0) { + fprintf(stderr,"This is a VUOS command." "It works only inside a vuos virtual namespace\n"); - usage(); - } - while (1) { - c=getopt_long(argc, argv, + usage(); + } + while (1) { + c=getopt_long(argc, argv, short_options, long_options, NULL); - if (c == -1) break; - switch (c) { - case 'h': usage(); - break; - } - } - if (argc - optind > 0) - usage(); + if (c == -1) break; + switch (c) { + case 'h': usage(); + break; + } + } + if (argc - optind > 0) + usage(); if ((bufsize = vu_lsmod(NULL, 0)) > 0) { char buf[bufsize]; if (vu_lsmod(buf, bufsize) < 0) @@ -70,5 +70,5 @@ int main(int argc, char *argv[]) else printf("%s", buf); } - return 0; + return 0; } diff --git a/cmd/vu_rmmod.c b/cmd/vu_rmmod.c index 5dd7a93..e635022 100644 --- a/cmd/vu_rmmod.c +++ b/cmd/vu_rmmod.c @@ -28,12 +28,12 @@ static char *progname; void usage() { - fprintf(stderr, + fprintf(stderr, "Usage:\n" " %s OPTIONS vu_module [vu_module] ...\n" " OPTIONS:\n" " -h --help: print this help message\n\n", progname); - exit(2); + exit(2); } static const char *short_options = "p"; @@ -44,34 +44,34 @@ static const struct option long_options[] = { int main(int argc, char *argv[]) { - int c; + int c; progname = basename(argv[0]); - if (vu_check() < 0) { - fprintf(stderr,"This is a VUOS command." + if (vu_check() < 0) { + fprintf(stderr,"This is a VUOS command." "It works only inside a vuos virtual namespace\n"); - usage(); - } - while (1) { - c=getopt_long(argc, argv, + usage(); + } + while (1) { + c=getopt_long(argc, argv, short_options, long_options, NULL); - if (c == -1) break; - switch (c) { - case 'h': usage(); - break; - } - } - if (argc - optind < 1) - usage(); - else { - int rv=0; - int i; - for (i = optind; i < argc; i++) { - if (vu_rmmod(argv[i]) < 0) { - perror(argv[i]); - rv=1; - } - } - return rv; - } - return 0; + if (c == -1) break; + switch (c) { + case 'h': usage(); + break; + } + } + if (argc - optind < 1) + usage(); + else { + int rv=0; + int i; + for (i = optind; i < argc; i++) { + if (vu_rmmod(argv[i]) < 0) { + perror(argv[i]); + rv=1; + } + } + return rv; + } + return 0; } diff --git a/cmd/vudebug.c b/cmd/vudebug.c index e10a827..dccc00b 100644 --- a/cmd/vudebug.c +++ b/cmd/vudebug.c @@ -30,7 +30,7 @@ static char *progname; void usage() { - fprintf(stderr, + fprintf(stderr, "Usage: %s [ARG] [ARG] ... [ -- cmd args ]\n" " ARG = --help | DEBUGSPEC\n" " DEBUGSPEC = [+|-]TAG[TAG]...[:COLORSPEC]\n" @@ -42,7 +42,7 @@ void usage() " +:,bright, -: dim, _: underlined, *: blinking, #: reverse\n\n", progname); - exit(2); + exit(2); } static inline void unique(int c) { @@ -64,7 +64,7 @@ static void vu_ls_debugtags(char *lstags) { char tagname[32]; vu_get_debugtagname(c, tagname, 32); if (((lstags != NULL && strchr(lstags, c)) || - (lstags == NULL && (tagselected || *tagname != '\0')))) + (lstags == NULL && (tagselected || *tagname != '\0')))) printf("%c %c%s%s\n", c, tagselected ? '+' : '-', ltagselected ? "(+)" : " ", @@ -76,16 +76,16 @@ static char functions[] = "+-?"; int main(int argc, char *argv[]) { progname = basename(argv[0]); - if (vu_check() < 0) { - fprintf(stderr,"This is a VUOS command." + if (vu_check() < 0) { + fprintf(stderr,"This is a VUOS command." "It works only inside a vuos virtual namespace\n"); - usage(); - } + usage(); + } if (argc == 1) { char tags[DEBUG_NTAGS+1]; char ltags[DEBUG_NTAGS+1]; - vu_get_debugtags(tags, DEBUG_NTAGS+1, 0); - vu_get_debugtags(ltags, DEBUG_NTAGS+1, 1); + vu_get_debugtags(tags, DEBUG_NTAGS+1, 0); + vu_get_debugtags(ltags, DEBUG_NTAGS+1, 1); if (*tags) printf("%s\n",tags); if (*ltags) @@ -120,12 +120,12 @@ int main(int argc, char *argv[]) case '?': vu_ls_debugtags(*tags ? tags : NULL); break; default: if (color == NULL) - usage(); + usage(); break; } char *colorstring; if (asprintf(&colorstring, "%s:%s", *tags ? tags : ALLTAGS, - (color) ? color : "") >= 0) { + (color) ? color : "") >= 0) { vu_set_debugcolor(colorstring); free(colorstring); } diff --git a/cmd/vumount.c b/cmd/vumount.c index 6be95c8..86959d3 100644 --- a/cmd/vumount.c +++ b/cmd/vumount.c @@ -122,7 +122,7 @@ char *parse_options(char *options, unsigned long *mountflags) { tags[i] = STROPTX_DELETED_TAG; } return stropt2str(tags, args, ',', '='); - } else + } else return options; } diff --git a/cmd/vustack.c b/cmd/vustack.c index e3ac490..26661e2 100644 --- a/cmd/vustack.c +++ b/cmd/vustack.c @@ -36,57 +36,57 @@ static char *progname; /* This is the command that creates the list of proocol family names echo "#include" | gcc -E -dD - | egrep '^#define *PF_.*[0-9]$' | \ - awk 'BEGIN {printf "static char *pf_names[] = {\n"} {printf " [%s] = \"%s\",\n", $3, substr(tolower($2),4)} END {printf "};\n"}' -*/ + awk 'BEGIN {printf "static char *pf_names[] = {\n"} {printf "\t[%s] = \"%s\",\n", $3, substr(tolower($2),4)} END {printf "};\n"}' + */ static char *pf_names[] = { - [0] = "unspec", - [1] = "local", - [2] = "inet", - [3] = "ax25", - [4] = "ipx", - [5] = "appletalk", - [6] = "netrom", - [7] = "bridge", - [8] = "atmpvc", - [9] = "x25", - [10] = "inet6", - [11] = "rose", - [12] = "decnet", - [13] = "netbeui", - [14] = "security", - [15] = "key", - [16] = "netlink", - [17] = "packet", - [18] = "ash", - [19] = "econet", - [20] = "atmsvc", - [21] = "rds", - [22] = "sna", - [23] = "irda", - [24] = "pppox", - [25] = "wanpipe", - [26] = "llc", - [27] = "ib", - [28] = "mpls", - [29] = "can", - [30] = "tipc", - [31] = "bluetooth", - [32] = "iucv", - [33] = "rxrpc", - [34] = "isdn", - [35] = "phonet", - [36] = "ieee802154", - [37] = "caif", - [38] = "alg", - [39] = "nfc", - [40] = "vsock", - [41] = "kcm", - [42] = "qipcrtr", - [43] = "smc", - [44] = "xdp", - [45] = "mctp", - [46] = "max", + [0] = "unspec", + [1] = "local", + [2] = "inet", + [3] = "ax25", + [4] = "ipx", + [5] = "appletalk", + [6] = "netrom", + [7] = "bridge", + [8] = "atmpvc", + [9] = "x25", + [10] = "inet6", + [11] = "rose", + [12] = "decnet", + [13] = "netbeui", + [14] = "security", + [15] = "key", + [16] = "netlink", + [17] = "packet", + [18] = "ash", + [19] = "econet", + [20] = "atmsvc", + [21] = "rds", + [22] = "sna", + [23] = "irda", + [24] = "pppox", + [25] = "wanpipe", + [26] = "llc", + [27] = "ib", + [28] = "mpls", + [29] = "can", + [30] = "tipc", + [31] = "bluetooth", + [32] = "iucv", + [33] = "rxrpc", + [34] = "isdn", + [35] = "phonet", + [36] = "ieee802154", + [37] = "caif", + [38] = "alg", + [39] = "nfc", + [40] = "vsock", + [41] = "kcm", + [42] = "qipcrtr", + [43] = "smc", + [44] = "xdp", + [45] = "mctp", + [46] = "max", }; #define PF_NAMES_SIZE ((int)(sizeof(pf_names) / sizeof(*pf_names))) @@ -126,7 +126,7 @@ static void add_supported_families(char *stack) { for (family = 1; family < PF_EXTRA_SIZE; family++) { int fd = msocket(stack, family, -1, 0); if (fd >= 0 || errno == EINVAL) - vustack_proto[family] = 1; + vustack_proto[family] = 1; if (fd >= 0) close(fd); } @@ -134,12 +134,12 @@ static void add_supported_families(char *stack) { static void process_families(const char *input) { int tagc = stropt(input, NULL, NULL, 0); - if(tagc > 0) { - char buf[strlen(input)+1]; - char *tags[tagc]; - stropt(input, tags, NULL, buf); + if(tagc > 0) { + char buf[strlen(input)+1]; + char *tags[tagc]; + stropt(input, tags, NULL, buf); vustack_proto[PF_UNSPEC] = 0; - for (int i=0; i < tagc - 1; i++) { + for (int i=0; i < tagc - 1; i++) { switch(strcase_tolower(tags[i])) { case STRCASE(i,p): vustack_proto[PF_INET] = 1; @@ -181,7 +181,7 @@ static void process_families(const char *input) { } } } - } + } } static char *short_options = "hvsf:"; @@ -196,9 +196,9 @@ static struct option long_options[] = { void usage(char *progname, int verbose) { - fprintf(stderr, + fprintf(stderr, "%s: set the default networking stack\n\n" - "Usage: %s [options] stack cmd [args]\n\n" + "Usage: %s [options] stack cmd [args]\n\n" " -h --help print this short usage message\n" " -f list\n" " -family list\n" @@ -227,12 +227,12 @@ int main(int argc, char *argv[]) int verbose = 0; int supported = 0; progname = basename(argv[0]); - + if (vu_getinfo(NULL) < 0) { fprintf(stderr, "%s is a vuos command\n", progname); return 1; } - + while (1) { int option_index = 0; c = getopt_long(argc, argv, short_options, @@ -260,7 +260,7 @@ int main(int argc, char *argv[]) char *stack = argv[optind]; char *cmd = argv[optind + 1]; char **newargv = argv + (optind + 1); - + if (is_a_stack(stack) < 0) { perror(stack); exit(1); diff --git a/cmd/vusu.c b/cmd/vusu.c index cf2c4e5..3d85c2b 100644 --- a/cmd/vusu.c +++ b/cmd/vusu.c @@ -83,26 +83,26 @@ void usage(char *argv0) } char *getlogindefs(char *tag) { - char *line = NULL; - size_t linelen = 0; - FILE *f=fopen("/etc/login.defs","r"); - char *retvalue = NULL; - if (f) { - while (retvalue == NULL && getline(&line, &linelen, f) > 0) { - char *s = line; - while (*s==' ' || *s=='\t') s++; - if (*s=='#') continue; - if (strncmp(tag,s,strlen(tag))!=0) continue; - s+=strlen(tag); - if (*s != ' ' && *s != '\t') continue; - while (*s==' ' || *s=='\t') s++; - s[strlen(s)-1]=0; - retvalue = strdup(s); - } - fclose(f); - if (line) free(line); - } - return retvalue; + char *line = NULL; + size_t linelen = 0; + FILE *f=fopen("/etc/login.defs","r"); + char *retvalue = NULL; + if (f) { + while (retvalue == NULL && getline(&line, &linelen, f) > 0) { + char *s = line; + while (*s==' ' || *s=='\t') s++; + if (*s=='#') continue; + if (strncmp(tag,s,strlen(tag))!=0) continue; + s+=strlen(tag); + if (*s != ' ' && *s != '\t') continue; + while (*s==' ' || *s=='\t') s++; + s[strlen(s)-1]=0; + retvalue = strdup(s); + } + fclose(f); + if (line) free(line); + } + return retvalue; } void setpath(void) @@ -139,15 +139,15 @@ void loginenv(void) { } } } - + int main(int argc, char *argv[]) { int c; struct passwd *pwd; - + if (vu_getinfo(NULL) < 0) execvp("su",argv); - + while (1) { int option_index = 0; c = getopt_long(argc, argv, short_options, @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) break; default: usage(argv[0]); - break; + break; } } diff --git a/include/libvumod.h b/include/libvumod.h index 5e7697f..1e65a6e 100644 --- a/include/libvumod.h +++ b/include/libvumod.h @@ -16,13 +16,13 @@ #define PSEUDOFILE_LOAD_DIRENTS 3 /* upcall: this is the prototype upcall function registered by pseudofile_open, -tag == PSEUDOFILE_LOAD_CONTENTS: upload the contents f-writing the file f -(this happens at first read/write/lseek) -tag == PSEUDOFILE_STORE_CLOSE: store/use the contents (and free any dynamic memory -allocated for pseudoprivate). f can be NULL if the file has been never read or written. -tag == PSEUDOFILE_LOAD_DIRENTS: populate the dir for getdents using pseudofile_filldir. -(this appens at first getdents64) -*/ + tag == PSEUDOFILE_LOAD_CONTENTS: upload the contents f-writing the file f + (this happens at first read/write/lseek) + tag == PSEUDOFILE_STORE_CLOSE: store/use the contents (and free any dynamic memory + allocated for pseudoprivate). f can be NULL if the file has been never read or written. + tag == PSEUDOFILE_LOAD_DIRENTS: populate the dir for getdents using pseudofile_filldir. + (this appens at first getdents64) + */ typedef int (* pseudo_upcall)(int tag, FILE *f, int openflags, void *pseudoprivate); /* helper function: convert struct stat's st_mode to struct dirent's d_type */ @@ -36,15 +36,15 @@ ssize_t pseudofile_readlink_fill(char *path, char *buf, size_t bufsiz); int pseudofile_filldir(FILE *f, char *name, ino_t ino, char type); /* open a pseudofile: pseudoprivate is an opaque arg forwarded to the upcall. - *private value must be stored and passed to all the other function here below. - (e.g. using the private arg of the module's open syscall implementation */ + *private value must be stored and passed to all the other function here below. + (e.g. using the private arg of the module's open syscall implementation */ int pseudofile_open(pseudo_upcall upcall, void *pseudoprivate, int flags, void **private); /* syscall implementation for pseudofiles. The signature of these function has been designed to be a drop in replacement for your module's functions. e.g. in yourmodule_init: struct vu_service_t *s = vu_mod_getservice(); vu_syscall_handler(s, close) = pseudofile_close; - */ + */ int pseudofile_close(int fd, void *private); int pseudofile_read(int fd, void *buf, size_t count, void *private); diff --git a/include/vulib.h b/include/vulib.h index 5e5db6d..345fda4 100644 --- a/include/vulib.h +++ b/include/vulib.h @@ -53,9 +53,9 @@ /* struct for vuctl VUCTL_GETINFO */ struct vu_info { - struct utsname uname; - char vu_serverid[_UTSNAME_LENGTH]; - char vu_name[_UTSNAME_LENGTH]; + struct utsname uname; + char vu_serverid[_UTSNAME_LENGTH]; + char vu_name[_UTSNAME_LENGTH]; }; #ifndef _VU_HYPERVISOR diff --git a/include/vumisc.h b/include/vumisc.h index 5a4a3ca..47b9a56 100644 --- a/include/vumisc.h +++ b/include/vumisc.h @@ -4,9 +4,9 @@ #include struct vumisc_info { - char *path; - struct vu_stat stat; - void *upcall_private; + char *path; + struct vu_stat stat; + void *upcall_private; }; /* get the private data (return value of "init") */ diff --git a/include/vumodule.h b/include/vumodule.h index 3382d37..a882a7e 100644 --- a/include/vumodule.h +++ b/include/vumodule.h @@ -34,10 +34,10 @@ struct vu_service_t; struct vuht_entry_t; struct vu_module_t { - char *name; - char *description; - uint64_t flags; - uint64_t filler; + char *name; + char *description; + uint64_t flags; + uint64_t filler; }; /* flags: @@ -152,7 +152,7 @@ int VU_SYSNAME(name, clock_settime) (clockid_t clk_id, const struct timespec *tp int VU_SYSNAME(name, clock_getres) (clockid_t clk_id, struct timespec *res); \ \ void VU_SYSNAME(name, cleanup) (uint8_t type, void *arg, int arglen, \ - struct vuht_entry_t *ht); \ + struct vuht_entry_t *ht); \ /* HASH TABLE management functions */ @@ -189,10 +189,10 @@ struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source, #define BINFMT_CREDENTIALS 0x4 struct binfmt_req_t { - char *path; - char filehead[BINFMTBUFLEN + 2]; - int fileheadlen; - int flags; + char *path; + char filehead[BINFMTBUFLEN + 2]; + int fileheadlen; + int flags; }; /* mainly for modules' threads */ @@ -259,12 +259,12 @@ struct mod_inheritance_exec_arg { typedef void *(*mod_inheritance_upcall_t) (mod_inheritance_state_t state, void *ioarg, void *arg); -void mod_inheritance_upcall_register(mod_inheritance_upcall_t upcall); -void mod_inheritance_upcall_deregister(mod_inheritance_upcall_t upcall); + void mod_inheritance_upcall_register(mod_inheritance_upcall_t upcall); + void mod_inheritance_upcall_deregister(mod_inheritance_upcall_t upcall); -/* stat must be implemented using 64bit data structures - even if VUOS is running on a 32bit architecture. - always use vu_stat/vu_lstat when writing module code */ + /* stat must be implemented using 64bit data structures + even if VUOS is running on a 32bit architecture. + always use vu_stat/vu_lstat when writing module code */ #if __WORDSIZE == 32 #define __VU_vu_lstat __VU_lstat64 #define vu_stat stat64 @@ -274,7 +274,7 @@ void mod_inheritance_upcall_deregister(mod_inheritance_upcall_t upcall); #define vu_lstat lstat #endif -/* log/debug facilities */ + /* log/debug facilities */ #define KERN_SOH "\001" /* ASCII Start Of Header */ #define KERN_EMERG KERN_SOH "0" /* system is unusable */ #define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */ @@ -285,24 +285,24 @@ void mod_inheritance_upcall_deregister(mod_inheritance_upcall_t upcall); #define KERN_INFO KERN_SOH "6" /* informational */ #define KERN_DEBUG KERN_SOH "7" /*debug-level messages */ -void _debug_set_name(int index, const char *s); -void debug_get_name(char tag, char *buf, size_t bufsize); + void _debug_set_name(int index, const char *s); + void debug_get_name(char tag, char *buf, size_t bufsize); #define debug_set_name(tag, s) \ - _debug_set_name(DEBUG_TAG2INDEX_##tag, "" s) + _debug_set_name(DEBUG_TAG2INDEX_##tag, "" s) -int vprintk(const char *fmt, va_list ap); -int printk(const char *fmt, ...); + int vprintk(const char *fmt, va_list ap); + int printk(const char *fmt, ...); -extern uint64_t debugmask; -extern __thread uint64_t tdebugmask; -extern __thread pid_t debugtid; + extern uint64_t debugmask; + extern __thread uint64_t tdebugmask; + extern __thread pid_t debugtid; -int _printkdebug(int index, const char *fmt, ...); + int _printkdebug(int index, const char *fmt, ...); #define printkdebug(tag, fmt, ...) \ - if (__builtin_expect((debugmask | tdebugmask) & (1ULL << DEBUG_TAG2INDEX_##tag), 0)) \ -_printkdebug(DEBUG_TAG2INDEX_##tag, "%d:%d\040%s:%d " fmt "\n", \ - debugtid, gettid(), basename(__FILE__), __LINE__, ##__VA_ARGS__) + if (__builtin_expect((debugmask | tdebugmask) & (1ULL << DEBUG_TAG2INDEX_##tag), 0)) \ + _printkdebug(DEBUG_TAG2INDEX_##tag, "%d:%d\040%s:%d " fmt "\n", \ + debugtid, gettid(), basename(__FILE__), __LINE__, ##__VA_ARGS__) #define DEBUG_TAG2INDEX_A 1 #define DEBUG_TAG2INDEX_B 2 diff --git a/include/vunet.h b/include/vunet.h index a6f1c52..5f2a60d 100644 --- a/include/vunet.h +++ b/include/vunet.h @@ -11,10 +11,10 @@ /* A vunet submodule must define a global non-static variable: - struct vunet_operations_t vunet_ops = { - .... - } -*/ + struct vunet_operations_t vunet_ops = { + .... + } + */ #ifndef S_IFSTACK #define S_IFSTACK 0160000 diff --git a/libvumod/vu_mod_pseudofile.c b/libvumod/vu_mod_pseudofile.c index ed9cfad..4aa8255 100644 --- a/libvumod/vu_mod_pseudofile.c +++ b/libvumod/vu_mod_pseudofile.c @@ -61,7 +61,7 @@ int pseudofile_mode2type(mode_t mode) { ssize_t pseudofile_readlink_fill(char *path, char *buf, size_t bufsiz) { if (path == NULL) { errno = EINVAL; - return -1; + return -1; } else { size_t len = strlen(path); if (len > bufsiz) len = bufsiz; @@ -146,7 +146,7 @@ int pseudofile_read(int fd, void *buf, size_t count, void *private) { } int pseudofile_write(int fd, const void *buf, size_t count, void *private) { - struct pseudofile *pseudofile = private; + struct pseudofile *pseudofile = private; if (pseudofile == NULL) { errno = EINVAL; return -1; @@ -161,18 +161,18 @@ int pseudofile_write(int fd, const void *buf, size_t count, void *private) { } int pseudofile_lseek(int fd, off_t offset, int whence, void *private) { - struct pseudofile *pseudofile = private; + struct pseudofile *pseudofile = private; if (pseudofile == NULL) { errno = EINVAL; return -1; } - if (pseudofile->f == NULL) + if (pseudofile->f == NULL) pseudofile_load_contents(pseudofile); - return fseeko(pseudofile->f, offset, whence); + return fseeko(pseudofile->f, offset, whence); } int pseudofile_getdents64(int fd, struct dirent64 *dirp, - unsigned int count, void *private) { + unsigned int count, void *private) { struct pseudofile *pseudofile = private; size_t freadout; if (pseudofile == NULL) { diff --git a/test_modules/mountreal.c b/test_modules/mountreal.c index 05a3500..1c4ea30 100644 --- a/test_modules/mountreal.c +++ b/test_modules/mountreal.c @@ -138,7 +138,7 @@ int vu_mountreal_truncate(const char *path, off_t length, int fd, void *fdprivat int vu_mountreal_statfs(const char *path, struct statfs *buf, int fd, void *fdprivate) { char pathbuf[PATH_MAX]; - return statfs(unwrap(path, pathbuf, PATH_MAX), buf); + return statfs(unwrap(path, pathbuf, PATH_MAX), buf); } ssize_t vu_mountreal_lgetxattr(const char *path, const char *name, @@ -188,7 +188,7 @@ int vu_mountreal_umount2(const char *target, int flags) { } void vu_mountreal_cleanup(uint8_t type, void *arg, int arglen, - struct vuht_entry_t *ht) { + struct vuht_entry_t *ht) { if (type == CHECKPATH) { struct mountreal_entry *entry = vuht_get_private_data(ht); if (entry->source) diff --git a/test_modules/netlinkdump.c b/test_modules/netlinkdump.c index 81e65d3..6719213 100644 --- a/test_modules/netlinkdump.c +++ b/test_modules/netlinkdump.c @@ -45,7 +45,7 @@ static void dump(const char *title, const uint8_t *data, size_t bufsize, ssize_t /* out format: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 01234567890123456789012345678901234567890123456789012345678901234 - */ + */ char hexbuf[48]; char charbuf[17]; printk("%s size %zd len %zd:\n", title, bufsize, len); diff --git a/test_modules/unreal.c b/test_modules/unreal.c index c595c92..a4795ff 100644 --- a/test_modules/unreal.c +++ b/test_modules/unreal.c @@ -40,7 +40,7 @@ /unreal/unreal/X -> VUOS forwards the requests to VUOS and then to the kernel (this latter case uses process self-virtualization) - */ + */ #include #include @@ -74,7 +74,7 @@ int vu_unreal_access(char *path, int mode, int flags) { static struct vuht_entry_t *ht1,*ht2; void vu_unreal_cleanup(uint8_t type, void *arg, int arglen, - struct vuht_entry_t *ht) { + struct vuht_entry_t *ht) { if (type == CHECKPATH) { //printk("%*.*s\n", arglen, arglen, arg); } diff --git a/test_modules/unrealprw.c b/test_modules/unrealprw.c index 36bc054..0003fe2 100644 --- a/test_modules/unrealprw.c +++ b/test_modules/unrealprw.c @@ -40,7 +40,7 @@ /unreal/unreal/X -> VUOS forwards the requests to VUOS and then to the kernel (this latter case uses process self-virtualization) - */ + */ #include #include @@ -75,7 +75,7 @@ int vu_unrealprw_access(char *path, int mode, int flags) { static struct vuht_entry_t *ht1,*ht2; void vu_unrealprw_cleanup(uint8_t type, void *arg, int arglen, - struct vuht_entry_t *ht) { + struct vuht_entry_t *ht) { if (type == CHECKPATH) { //printk("%*.*s\n", arglen, arglen, arg); } diff --git a/test_modules/unrealuidgid.c b/test_modules/unrealuidgid.c index 40aadfe..bbc7f18 100644 --- a/test_modules/unrealuidgid.c +++ b/test_modules/unrealuidgid.c @@ -38,31 +38,31 @@ VU_PROTOTYPES(unrealuidgid) }; struct vu_uid_gid_t { - pthread_rwlock_t lock; - uid_t ruid, euid, suid, fsuid; - gid_t rgid, egid, sgid, fsgid; + pthread_rwlock_t lock; + uid_t ruid, euid, suid, fsuid; + gid_t rgid, egid, sgid, fsgid; int ngroups; gid_t *groups; - size_t count; + size_t count; }; static __thread struct vu_uid_gid_t *vu_uid_gid = NULL; static void vu_uid_gid_create(void) { - struct vu_uid_gid_t *new; + struct vu_uid_gid_t *new; - new = malloc(sizeof(struct vu_uid_gid_t)); - getresuid(&new->ruid, &new->euid, &new->suid); - getresgid(&new->rgid, &new->egid, &new->sgid); - new->fsuid = setfsuid(-1); - new->fsgid = setfsgid(-1); - new->count = 1; + new = malloc(sizeof(struct vu_uid_gid_t)); + getresuid(&new->ruid, &new->euid, &new->suid); + getresgid(&new->rgid, &new->egid, &new->sgid); + new->fsuid = setfsuid(-1); + new->fsgid = setfsgid(-1); + new->count = 1; new->ngroups = getgroups(0, NULL); new->groups = malloc(new->ngroups * sizeof(gid_t)); if (getgroups(new->ngroups, new->groups) < 0) new->ngroups = 0; - pthread_rwlock_init(&new->lock, NULL); - vu_uid_gid = new; + pthread_rwlock_init(&new->lock, NULL); + vu_uid_gid = new; } static void vu_uid_gid_modify_lock(void) { @@ -124,38 +124,38 @@ int vu_unrealuidgid_getresfuid(uid_t *ruid, uid_t *euid, uid_t *suid, } int vu_unrealuidgid_setresfgid(gid_t rgid, gid_t egid, gid_t sgid, gid_t fsgid, void *private) { - if (vu_uid_gid == NULL) - vu_uid_gid_create(); + if (vu_uid_gid == NULL) + vu_uid_gid_create(); vu_uid_gid_modify_lock(); - if (rgid != (gid_t) -1) vu_uid_gid->rgid = rgid; - if (egid != (gid_t) -1) vu_uid_gid->egid = egid; - if (sgid != (gid_t) -1) vu_uid_gid->sgid = sgid; - if (fsgid != (gid_t) -1) vu_uid_gid->fsgid = fsgid; - pthread_rwlock_unlock(&vu_uid_gid->lock); - return 0; + if (rgid != (gid_t) -1) vu_uid_gid->rgid = rgid; + if (egid != (gid_t) -1) vu_uid_gid->egid = egid; + if (sgid != (gid_t) -1) vu_uid_gid->sgid = sgid; + if (fsgid != (gid_t) -1) vu_uid_gid->fsgid = fsgid; + pthread_rwlock_unlock(&vu_uid_gid->lock); + return 0; } int vu_unrealuidgid_getresfgid(gid_t *rgid, gid_t *egid, gid_t *sgid, - gid_t *fsgid, void *private) { - if (vu_uid_gid != NULL) { - pthread_rwlock_rdlock(&vu_uid_gid->lock); - if (rgid != NULL) *rgid = vu_uid_gid->rgid; - if (egid != NULL) *egid = vu_uid_gid->egid; - if (sgid != NULL) *sgid = vu_uid_gid->sgid; - if (fsgid != NULL) *fsgid = vu_uid_gid->fsgid; - pthread_rwlock_unlock(&vu_uid_gid->lock); - } else { - if (fsgid != NULL) - *fsgid = setfsgid(-1); - getresgid(rgid, egid, sgid); - } - return 0; + gid_t *fsgid, void *private) { + if (vu_uid_gid != NULL) { + pthread_rwlock_rdlock(&vu_uid_gid->lock); + if (rgid != NULL) *rgid = vu_uid_gid->rgid; + if (egid != NULL) *egid = vu_uid_gid->egid; + if (sgid != NULL) *sgid = vu_uid_gid->sgid; + if (fsgid != NULL) *fsgid = vu_uid_gid->fsgid; + pthread_rwlock_unlock(&vu_uid_gid->lock); + } else { + if (fsgid != NULL) + *fsgid = setfsgid(-1); + getresgid(rgid, egid, sgid); + } + return 0; } int vu_unrealuidgid_getgroups(int size, gid_t list[], void *private) { int ret_value; if (vu_uid_gid != NULL) { - pthread_rwlock_rdlock(&vu_uid_gid->lock); + pthread_rwlock_rdlock(&vu_uid_gid->lock); ret_value = vu_uid_gid->ngroups; if (size != 0) { if (size < vu_uid_gid->ngroups) { @@ -177,7 +177,7 @@ int vu_unrealuidgid_setgroups(int size, const gid_t list[], void *private) { } if (vu_uid_gid == NULL) vu_uid_gid_create(); - vu_uid_gid_modify_lock(); + vu_uid_gid_modify_lock(); vu_uid_gid->ngroups = size; vu_uid_gid->groups = realloc(vu_uid_gid->groups, vu_uid_gid->ngroups * sizeof(gid_t)); memcpy(vu_uid_gid->groups, list, vu_uid_gid->ngroups * sizeof(gid_t)); @@ -195,17 +195,17 @@ static void *vu_uid_gid_clone(void *arg) { } static void vu_uid_gid_exec(void *arg) { - struct mod_inheritance_exec_arg *mod_exec = arg; - if (mod_exec->exec_uid != (uid_t) -1) { - uid_t setuid = mod_exec->exec_uid; - vu_unrealuidgid_setresfuid(-1, setuid, setuid, setuid, NULL); - mod_exec->exec_uid = (uid_t) -1; - } - if (mod_exec->exec_gid != (gid_t) -1) { - gid_t setgid = mod_exec->exec_gid; - vu_unrealuidgid_setresfgid(-1, setgid, setgid, setgid, NULL); - mod_exec->exec_gid = (gid_t) -1; - } + struct mod_inheritance_exec_arg *mod_exec = arg; + if (mod_exec->exec_uid != (uid_t) -1) { + uid_t setuid = mod_exec->exec_uid; + vu_unrealuidgid_setresfuid(-1, setuid, setuid, setuid, NULL); + mod_exec->exec_uid = (uid_t) -1; + } + if (mod_exec->exec_gid != (gid_t) -1) { + gid_t setgid = mod_exec->exec_gid; + vu_unrealuidgid_setresfgid(-1, setgid, setgid, setgid, NULL); + mod_exec->exec_gid = (gid_t) -1; + } } static void vu_uid_gid_terminate(void) { @@ -224,50 +224,50 @@ static void vu_uid_gid_terminate(void) { } static void *vu_uid_gid_tracer_upcall(mod_inheritance_state_t state, void *ioarg, void *arg) { - void *ret_value = NULL; - switch (state) { - case MOD_INH_CLONE: - ret_value = vu_uid_gid_clone(arg); - break; - case MOD_INH_START: - vu_uid_gid = ioarg; - break; - case MOD_INH_EXEC: - vu_uid_gid_exec(arg); - break; - case MOD_INH_TERMINATE: - vu_uid_gid_terminate(); - break; - } - return ret_value; + void *ret_value = NULL; + switch (state) { + case MOD_INH_CLONE: + ret_value = vu_uid_gid_clone(arg); + break; + case MOD_INH_START: + vu_uid_gid = ioarg; + break; + case MOD_INH_EXEC: + vu_uid_gid_exec(arg); + break; + case MOD_INH_TERMINATE: + vu_uid_gid_terminate(); + break; + } + return ret_value; } static short vusc[]={ - __NR_getresuid, __NR_getresgid, - __NR_setresuid, __NR_setresgid, - __NR_setgroups, - __NR_getgroups + __NR_getresuid, __NR_getresgid, + __NR_setresuid, __NR_setresgid, + __NR_setgroups, + __NR_getgroups }; #define VUSCLEN (sizeof(vusc) / sizeof(*vusc)) static struct vuht_entry_t *ht[VUSCLEN]; void *vu_unrealuidgid_init(void) { - struct vu_service_t *s = vu_mod_getservice(); - unsigned int i; - for (i = 0; i < VUSCLEN; i++) { - int vu_syscall = vu_arch_table[vusc[i]]; - ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, NULL, NULL, 0); - } + struct vu_service_t *s = vu_mod_getservice(); + unsigned int i; + for (i = 0; i < VUSCLEN; i++) { + int vu_syscall = vu_arch_table[vusc[i]]; + ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, NULL, NULL, 0); + } mod_inheritance_upcall_register(vu_uid_gid_tracer_upcall); - return NULL; + return NULL; } int vu_unrealuidgid_fini(void *private) { - unsigned int i; - for (i = 0; i < VUSCLEN; i++) { - if (ht[i] && vuht_del(ht[i], MNT_FORCE) == 0) - ht[i] = NULL; - } + unsigned int i; + for (i = 0; i < VUSCLEN; i++) { + if (ht[i] && vuht_del(ht[i], MNT_FORCE) == 0) + ht[i] = NULL; + } mod_inheritance_upcall_deregister(vu_uid_gid_tracer_upcall); return 0; } diff --git a/umvu/include/linux_32_64.h b/umvu/include/linux_32_64.h index 7f87c29..6639d3f 100644 --- a/umvu/include/linux_32_64.h +++ b/umvu/include/linux_32_64.h @@ -55,7 +55,7 @@ struct linux_dirent { /* char pad; // Zero padding byte char d_type; // File type (only since Linux - // 2.6.4); offset is (d_reclen - 1) + // 2.6.4); offset is (d_reclen - 1) */ }; diff --git a/umvu/include/ptrace_defs.h b/umvu/include/ptrace_defs.h index 1815d18..3b5781d 100644 --- a/umvu/include/ptrace_defs.h +++ b/umvu/include/ptrace_defs.h @@ -9,60 +9,60 @@ #include /* helpers for ptrace: - P_* produce an error messsage if ptrace fails, and terminates the thread - P_*_NODIE produce an error messsage if ptrace fails (and continue) */ + P_* produce an error messsage if ptrace fails, and terminates the thread + P_*_NODIE produce an error messsage if ptrace fails (and continue) */ #define PTRACE(action, tracee_tid, addr, data) \ - if (r_ptrace(action, tracee_tid, addr, data) == -1) { \ - char errmsg[80]; \ - snprintf(errmsg, 80, "%s line %d, ptrace", __FILE__, __LINE__); \ - perror(errmsg); \ - pthread_exit(NULL); \ - } + if (r_ptrace(action, tracee_tid, addr, data) == -1) { \ + char errmsg[80]; \ + snprintf(errmsg, 80, "%s line %d, ptrace", __FILE__, __LINE__); \ + perror(errmsg); \ + pthread_exit(NULL); \ + } #define PTRACE_NODIE(action, tracee_tid, addr, data) \ - if (r_ptrace(action, tracee_tid, addr, data) == -1) { \ - char errmsg[80]; \ - snprintf(errmsg, 80, "%s line %d, ptrace", __FILE__, __LINE__); \ - perror(errmsg); \ - } + if (r_ptrace(action, tracee_tid, addr, data) == -1) { \ + char errmsg[80]; \ + snprintf(errmsg, 80, "%s line %d, ptrace", __FILE__, __LINE__); \ + perror(errmsg); \ + } #define P_GETREGS(tracee_tid, regs) \ - PTRACE(PTRACE_GETREGSET, tracee_tid, NT_PRSTATUS, &((struct iovec) {regs, sizeof(arch_regs_struct)})) + PTRACE(PTRACE_GETREGSET, tracee_tid, NT_PRSTATUS, &((struct iovec) {regs, sizeof(arch_regs_struct)})) #define P_SETREGS(tracee_tid, regs) \ - PTRACE(PTRACE_SETREGSET, tracee_tid, NT_PRSTATUS, &((struct iovec) {regs, sizeof(arch_regs_struct)})) + PTRACE(PTRACE_SETREGSET, tracee_tid, NT_PRSTATUS, &((struct iovec) {regs, sizeof(arch_regs_struct)})) #define P_SYSCALL(tracee_tid, signal) PTRACE(PTRACE_SYSCALL, tracee_tid, 0L, signal) #define P_CONT(tracee_tid, signal) PTRACE(PTRACE_CONT, tracee_tid, 0L, signal) #define P_LISTEN(tracee_tid, signal) PTRACE(PTRACE_LISTEN, tracee_tid, 0L, signal) #define P_INTERRUPT(tracee_tid, signal) \ - PTRACE(PTRACE_INTERRUPT, tracee_tid, 0L, signal) + PTRACE(PTRACE_INTERRUPT, tracee_tid, 0L, signal) #define P_ATTACH(tracee_tid, signal) PTRACE(PTRACE_ATTACH, tracee_tid, 0L, signal) #define P_SEIZE(tracee_tid, signal) PTRACE(PTRACE_SEIZE, tracee_tid, 0L, signal) #define P_DETACH(tracee_tid, signal) PTRACE(PTRACE_DETACH, tracee_tid, 0L, signal) #define P_SETOPT(tracee_tid, opt) PTRACE(PTRACE_SETOPTIONS, tracee_tid, 0L, opt) #define P_GETEVENTMSG(tracee_tid, event) \ - PTRACE(PTRACE_GETEVENTMSG, tracee_tid, 0L, event) + PTRACE(PTRACE_GETEVENTMSG, tracee_tid, 0L, event) #define P_GETREGS_NODIE(tracee_tid, regs) \ - PTRACE_NODIE(PTRACE_GETREGSET, tracee_tid, NT_PRSTATUS, \ - &((struct iovec) {regs, sizeof(arch_regs_struct)})) + PTRACE_NODIE(PTRACE_GETREGSET, tracee_tid, NT_PRSTATUS, \ + &((struct iovec) {regs, sizeof(arch_regs_struct)})) #define P_SETREGS_NODIE(tracee_tid, regs) \ - PTRACE_NODIE(PTRACE_SETREGSET, tracee_tid, NT_PRSTATUS, \ - &((struct iovec) {regs, sizeof(arch_regs_struct)})) + PTRACE_NODIE(PTRACE_SETREGSET, tracee_tid, NT_PRSTATUS, \ + &((struct iovec) {regs, sizeof(arch_regs_struct)})) #define P_SYSCALL_NODIE(tracee_tid, signal) \ - PTRACE_NODIE(PTRACE_SYSCALL, tracee_tid, 0L, signal) + PTRACE_NODIE(PTRACE_SYSCALL, tracee_tid, 0L, signal) #define P_CONT_NODIE(tracee_tid, signal) \ - PTRACE_NODIE(PTRACE_CONT, tracee_tid, 0L, signal) + PTRACE_NODIE(PTRACE_CONT, tracee_tid, 0L, signal) #define P_DETACH_NODIE(tracee_tid, signal) \ - PTRACE_NODIE(PTRACE_DETACH, tracee_tid, 0L, signal) + PTRACE_NODIE(PTRACE_DETACH, tracee_tid, 0L, signal) #define P_SEIZE_NODIE(tracee_tid, signal) \ - PTRACE_NODIE(PTRACE_SEIZE, tracee_tid, 0L, signal) + PTRACE_NODIE(PTRACE_SEIZE, tracee_tid, 0L, signal) #define PTRACE_STD_OPTS \ - PTRACE_O_TRACESYSGOOD | PTRACE_O_EXITKILL | PTRACE_O_TRACEEXEC | \ - PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | \ - PTRACE_O_TRACEEXIT | PTRACE_O_TRACESECCOMP + PTRACE_O_TRACESYSGOOD | PTRACE_O_EXITKILL | PTRACE_O_TRACEEXEC | \ + PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | \ + PTRACE_O_TRACEEXIT | PTRACE_O_TRACESECCOMP #ifndef PTRACE_EVENT_STOP #define PTRACE_EVENT_STOP 128 diff --git a/umvu/include/service.h b/umvu/include/service.h index 97c44d2..1951abf 100644 --- a/umvu/include/service.h +++ b/umvu/include/service.h @@ -30,7 +30,7 @@ struct vu_service_t { struct vuht_entry_t *vu_mod_getht(void); /* A static thread variable records the module hash table element chosen by the hypervisor, - so that the module can access it */ + so that the module can access it */ void vu_mod_setht(struct vuht_entry_t *ht); /* hash table and epoch wrapper: @@ -64,10 +64,10 @@ __attribute__((always_inline)) } /* inline function: it is here for performance. - it returns the flags of the module */ + it returns the flags of the module */ __attribute__((always_inline)) - static inline uint64_t service_getflags(struct vuht_entry_t *ht) { - return ht ? vuht_get_service(ht)->mod->flags : 0; - } + static inline uint64_t service_getflags(struct vuht_entry_t *ht) { + return ht ? vuht_get_service(ht)->mod->flags : 0; + } #endif diff --git a/umvu/include/syscall_table.h b/umvu/include/syscall_table.h index 7dc3f4b..d4be909 100644 --- a/umvu/include/syscall_table.h +++ b/umvu/include/syscall_table.h @@ -1,8 +1,8 @@ #ifndef _SYSCALL_TABLE_H_ #define _SYSCALL_TABLE_H_ /* header file for the file syscall_table.c which is automatically generated - during the building/compilation process. The source file to generate - arch_table.c is vu_syscall.conf */ + during the building/compilation process. The source file to generate + arch_table.c is vu_syscall.conf */ struct syscall_descriptor_t; struct vuht_entry_t; @@ -17,11 +17,11 @@ typedef void wrapf_t(struct vuht_entry_t *, struct syscall_descriptor_t *); /* vu_syscall_table defines for each _VU_ system call: the choice function, the system call pre-processing wrapper - it is evaluated before the kernel gets the system call. + it is evaluated before the kernel gets the system call. the system call co-processing wrapper - it is evaluated while the kernel is processing the request + it is evaluated while the kernel is processing the request the system call post-processing wrapper - it runs when the kernel has completed the system call request + it runs when the kernel has completed the system call request */ struct syscall_tab_entry{ diff --git a/umvu/include/vu_access_emu.h b/umvu/include/vu_access_emu.h index cf81f7f..5cfe8e8 100644 --- a/umvu/include/vu_access_emu.h +++ b/umvu/include/vu_access_emu.h @@ -6,8 +6,8 @@ /* this emulates 'access' given a stat buffer. use getuid (or geteuid if AT_EACCESS), getgid (or getegid if AT_EACCESS) and getgroups. - return 0 or -errno + return 0 or -errno AT_SYMLINK_NOFOLLOW is handled by canonicalize/path-utils -*/ + */ int vu_access_emu(struct vu_stat *statbuf, int mode, int flags); #endif diff --git a/umvu/include/vu_inheritance.h b/umvu/include/vu_inheritance.h index c67b9b6..3e6f8ac 100644 --- a/umvu/include/vu_inheritance.h +++ b/umvu/include/vu_inheritance.h @@ -10,7 +10,7 @@ /* Warning: vu_inheritance_upcall_register is *NOT* thread safe. It has been designed for __attribute__((constructor)) functions (so the call happens before going multi-threading. A thread safe implementation for modules as - an upper layer is provided by vu_mod_inheritance.c */ + an upper layer is provided by vu_mod_inheritance.c */ /* CLONE/START is the pair of events to manage a new process/thread: CLONE is an event of the parent process/creating thread @@ -47,7 +47,7 @@ void vu_inheritance_upcall_register(inheritance_upcall_t upcall); >>> the return value of each handler updates its element in inoutarg. >>> inoutargs must point to a memory area vu_inheritance_inout_size() bytes wide >>> (START / CLONE events use this) -*/ + */ void vu_inheritance_call(inheritance_state_t state, void **inout, void *arg); size_t vu_inheritance_inout_size(void); diff --git a/umvu/include/vu_log.h b/umvu/include/vu_log.h index 1f79fde..544fa6b 100644 --- a/umvu/include/vu_log.h +++ b/umvu/include/vu_log.h @@ -108,7 +108,7 @@ extern __thread pid_t debugtid; int _printkdebug(int index, const char *fmt, ...); #define printkdebug(tag, fmt, ...) \ if (__builtin_expect((debugmask | tdebugmask) & (1ULL << DEBUG_TAG2INDEX_##tag), 0)) \ - _printkdebug(DEBUG_TAG2INDEX_##tag, "%d:%d\040%s:%d " fmt "\n", \ +_printkdebug(DEBUG_TAG2INDEX_##tag, "%d:%d\040%s:%d " fmt "\n", \ debugtid, gettid(), basename(__FILE__), __LINE__, ##__VA_ARGS__) #define DEBUG_ALLTAGS " ABCDEFGHIJKLMNOPQRSTUVWXYZ_01234abcdefghijklmnopqrstuvwxyz56789" diff --git a/umvu/include/vu_thread_sd.h b/umvu/include/vu_thread_sd.h index 8268ced..6259b53 100644 --- a/umvu/include/vu_thread_sd.h +++ b/umvu/include/vu_thread_sd.h @@ -5,7 +5,7 @@ mainly for modules */ /* set the new value of thread_sd and return the previous, - so that it can be used later to restore the old value */ + so that it can be used later to restore the old value */ struct syscall_descriptor_t *set_thread_sd(struct syscall_descriptor_t *sd); /* get the current thread_sd */ struct syscall_descriptor_t *get_thread_sd(void); diff --git a/umvu/include/vu_wrapper_utils.h b/umvu/include/vu_wrapper_utils.h index bf5be6d..24daa02 100644 --- a/umvu/include/vu_wrapper_utils.h +++ b/umvu/include/vu_wrapper_utils.h @@ -120,9 +120,9 @@ __attribute__((always_inline)) __attribute__((always_inline)) static inline void vu_poke_iov_arg(uintptr_t iovaddr, - struct iovec *iov, int iovcnt, void *buf, size_t len, int nested) { + struct iovec *iov, int iovcnt, void *buf, size_t len, int nested) { int i; - char *cbuf = (char *) buf; + char *cbuf = (char *) buf; for (i = 0; i < iovcnt && len > 0; i++) { size_t iov_len = iov[i].iov_len; if (len < iov_len) iov_len = len; @@ -148,8 +148,8 @@ __attribute__((always_inline)) #define vu_free_iov_arg(iov, buf, nested) \ do {\ vu_free_arg(iov, nested); \ - xfree(buf); \ - } while(0) + xfree(buf); \ + } while(0) #define default_nosys(sd) \ do {\ diff --git a/umvu/src/canonicalize.c b/umvu/src/canonicalize.c index c5c88e5..140b49f 100644 --- a/umvu/src/canonicalize.c +++ b/umvu/src/canonicalize.c @@ -34,21 +34,21 @@ /* canonstruct: this struct contains the values that must be shared during the whole recursive scan: .ebuf: source for the relative to absolute path translation. - it is allocated on the stack. - if the path to translate begins by '/': - it contains the root dir followed by the path to translate, - otherwise - it contains the current working dir followed by the path to translate + it is allocated on the stack. + if the path to translate begins by '/': + it contains the root dir followed by the path to translate, + otherwise + it contains the current working dir followed by the path to translate .start, .end: pointers on ebuf, the boundaries of the current component .resolved: the user provided buffer where the result must be stored .rootlen: the len of the root component (it is not possible to generate - shorter pathnames to force the root cage. rootlen includes the '/') + shorter pathnames to force the root cage. rootlen includes the '/') .num_links: counter of symlink to avoid infinite loops (ELOOP) .mode: lstat's st_mode of the last component (of the file at the end) - 0 means non-existent -1 invalid (lstat must be called again). + 0 means non-existent -1 invalid (lstat must be called again). .flags: flags (see canonicalize.h), follow link (final component) - this flag is for l-system calls like lstat, lchmod, lchown etc... - permit nonexistent leaves, etc. + this flag is for l-system calls like lstat, lchmod, lchown etc... + permit nonexistent leaves, etc. .private: opaque arg for user provided access functions (lmode, readlink, getcwd, getroot). */ @@ -253,8 +253,8 @@ static int rec_realpath(struct canonstruct *cdata, char *dest) /* absolute path: copy prefix in cdata->ebuf -return the length of the prefix -(not including trailing '/' as the path has a leading '/' already) */ + return the length of the prefix + (not including trailing '/' as the path has a leading '/' already) */ static ssize_t abs_prefix(struct canonstruct *cdata) { char *root = cdata->ebuf; size_t prefixlen; @@ -268,8 +268,8 @@ static ssize_t abs_prefix(struct canonstruct *cdata) { } /* relative path: copy cwd in cdata->ebuf as a prefix -return the length of the prefix -(including a trailing '/' to catenate the path as it is)*/ + return the length of the prefix + (including a trailing '/' to catenate the path as it is)*/ static ssize_t rel_prefix(struct canonstruct *cdata) { char root[PATH_MAX]; size_t rootlen; @@ -315,7 +315,7 @@ char *canon_realpath(const char *path, char *resolved_path, int flags, void *pri } if (__builtin_expect(*path == 0, 0)) { if (flags & PERMIT_EMPTY_PATH && - operations.getcwd(resolved_path, PATH_MAX, private) >= 0) + operations.getcwd(resolved_path, PATH_MAX, private) >= 0) return resolved_path; else { errno = ENOENT; diff --git a/umvu/src/carrot.c b/umvu/src/carrot.c index 4d7ed1c..b3127ca 100644 --- a/umvu/src/carrot.c +++ b/umvu/src/carrot.c @@ -91,7 +91,7 @@ void carrot_free(struct carrot_t *old) { * otherwise: then new carrot has only one element (eventual existing carrot is deleted */ struct carrot_t *carrot_insert(struct carrot_t *head, struct vuht_entry_t *elem, epoch_t time, - int (*has_exception)(struct vuht_entry_t *)) { + int (*has_exception)(struct vuht_entry_t *)) { if (head == NULL || /* empty carrot */ time > head->time) { /* this is newer */ if (head == NULL || has_exception(elem)) { diff --git a/umvu/src/hashtable.c b/umvu/src/hashtable.c index 244936e..73cb42d 100644 --- a/umvu/src/hashtable.c +++ b/umvu/src/hashtable.c @@ -67,7 +67,7 @@ struct vuht_entry_t { int objlen; long hashsum; _Atomic int count; - + /* confirmfun_t */ confirmfun_t confirmfun; struct vuht_entry_t *prev, *next, **pprevhash, *nexthash; @@ -140,8 +140,8 @@ static inline long hashsum(uint8_t type, const char *c, int len) static inline int trailnum(char *s) { /* "at least one" the first element needs a special case. - performance: >'9' is the most frequent case, <'0' are quite rare - in pathnames, the end of string is more common */ +performance: >'9' is the most frequent case, <'0' are quite rare +in pathnames, the end of string is more common */ int nonzero = 0; if (*s > '9' || *s == 0 || *s < '0') @@ -194,7 +194,7 @@ static int vuht_scan_stop(uint8_t type, char *objc, int len, int exact) return 1; /* CHECKFSTYPE char by char */ default: return 0; - } + } } /* terminate the scan */ @@ -332,7 +332,7 @@ static inline int stringobj(uint8_t type) { type == CHECKFSALIAS; } -static struct vuht_entry_t * + static struct vuht_entry_t * internal_vuht_add(uint8_t type, const void *obj, int objlen, unsigned long mountflags, char *mtabline, struct vu_service_t *service, uint8_t trailingnumbers, @@ -423,10 +423,10 @@ struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source, char opts[optslen]; mountflags2opts(mountflags & VUHT_MTABLINE, opts, optslen); if (asprintf(&mtabline, "%s%s %s %s %s 0 %" PRIu64, - (confirmfun == NEGATIVE_MOUNT) ? "-" : "", source, path, - fstype, - *opts == 0 ? "rw" : opts, - get_epoch()) <= 0) { + (confirmfun == NEGATIVE_MOUNT) ? "-" : "", source, path, + fstype, + *opts == 0 ? "rw" : opts, + get_epoch()) <= 0) { errno = ENOMEM; fatal(NULL); } @@ -540,7 +540,7 @@ struct vuht_entry_t *vuht_pick(uint8_t type, void *arg, struct vu_stat *st, int break; case CHECKIOCTL: hte = vuht_search(type, arg, sizeof(unsigned long), 0); - break; + break; case CHECKFSALIAS: case CHECKMODULE: hte = vuht_search(type, arg, 0, 1); @@ -638,7 +638,7 @@ void vuht_set_private_data(struct vuht_entry_t *hte, void *private_data) { void vuht_set_service_cleanupfun(struct vuht_entry_t *hte, confirmfun_t cleanup_fun) { if (hte != NULL && hte->type == CHECKMODULE) { - hte->confirmfun = cleanup_fun; + hte->confirmfun = cleanup_fun; } } @@ -665,7 +665,7 @@ int vuht_get_count(struct vuht_entry_t *hte) { } int vuht_get_objlen(struct vuht_entry_t *hte) { - return hte->objlen; + return hte->objlen; } void vuht_terminate(void) { diff --git a/umvu/src/linux_32_64.c b/umvu/src/linux_32_64.c index 7aad70b..2fecadf 100644 --- a/umvu/src/linux_32_64.c +++ b/umvu/src/linux_32_64.c @@ -27,27 +27,27 @@ VUOS modules handle 64bit dirents, this conversion is needed to support 32bit dirent (on 32bit architectures) */ void dirent64_to_dirent(void* buf, int count){ - struct linux_dirent *dirp=buf; - struct dirent64 *dirp64=buf; - int counter=0; - unsigned short int buf_len; + struct linux_dirent *dirp=buf; + struct dirent64 *dirp64=buf; + int counter=0; + unsigned short int buf_len; /* Actually the conversion is a bit tricky. * dirent is always shorter then dirent64. * copy the corresponding fields * keep the record length (there will be some unused bytes) */ - for( counter=0; counterd_ino = (unsigned long) dirp64->d_ino; - dirp->d_off = (unsigned long) dirp64->d_off; - buf_len = dirp->d_reclen = dirp64->d_reclen; - tmptype = dirp64->d_type; - memmove(dirp->d_name,dirp64->d_name,strlen(dirp64->d_name)+1); - *((char *) dirp + buf_len - 1)=tmptype; - counter= counter + dirp->d_reclen; //bad... - dirp = (struct linux_dirent *) ((char*)dirp + buf_len); - dirp64 = (struct dirent64 *) ((char*)dirp64 + buf_len); - } + for( counter=0; counterd_ino = (unsigned long) dirp64->d_ino; + dirp->d_off = (unsigned long) dirp64->d_off; + buf_len = dirp->d_reclen = dirp64->d_reclen; + tmptype = dirp64->d_type; + memmove(dirp->d_name,dirp64->d_name,strlen(dirp64->d_name)+1); + *((char *) dirp + buf_len - 1)=tmptype; + counter= counter + dirp->d_reclen; //bad... + dirp = (struct linux_dirent *) ((char*)dirp + buf_len); + dirp64 = (struct dirent64 *) ((char*)dirp64 + buf_len); + } } diff --git a/umvu/src/path_utils.c b/umvu/src/path_utils.c index 0c535db..b1101c0 100644 --- a/umvu/src/path_utils.c +++ b/umvu/src/path_utils.c @@ -106,18 +106,18 @@ int path_check_exceptions(int syscall_number, syscall_arg_t *args) { If the path is empty these system calls operate on the dirfd file */ static inline int is_at_empty_path(int syscall_number, syscall_arg_t *args) { int nargs = vu_arch_table_nargs(syscall_number); - switch (syscall_number) { - case __NR_openat: - case __NR_open: - case __NR_umount2: - case __NR_unlinkat: - case __NR_readlinkat: - return 0; - case __NR_statx: - return (args[3] & AT_EMPTY_PATH); - default: - return (args[nargs-1] & AT_EMPTY_PATH); - } + switch (syscall_number) { + case __NR_openat: + case __NR_open: + case __NR_umount2: + case __NR_unlinkat: + case __NR_readlinkat: + return 0; + case __NR_statx: + return (args[3] & AT_EMPTY_PATH); + default: + return (args[nargs-1] & AT_EMPTY_PATH); + } } /* get the pathname argument of a system call, canonicalize it. The return value is @@ -193,17 +193,17 @@ char *get_vsyspath(struct syscall_descriptor_t *sd, struct vu_stat *buf, uint8_t /* rewrite the pathname argument of a system call. newpath must be an absolute pathname */ void rewrite_syspath(struct syscall_descriptor_t *sd, char *newpath) { - int syscall_number = sd->syscall_number; - int patharg = vu_arch_table_patharg(syscall_number); + int syscall_number = sd->syscall_number; + int patharg = vu_arch_table_patharg(syscall_number); - if (patharg >= 0) { - int type = vu_arch_table_type(syscall_number); + if (patharg >= 0) { + int type = vu_arch_table_type(syscall_number); if (type == 3) type = path_check_exceptions(syscall_number, sd->syscall_args); - if (type & ARCH_TYPE_IS_AT) - patharg++; - sd->syscall_args[patharg] = vu_push(sd, newpath, strlen(newpath) + 1); - } + if (type & ARCH_TYPE_IS_AT) + patharg++; + sd->syscall_args[patharg] = vu_push(sd, newpath, strlen(newpath) + 1); + } } /* canonicalize's helper functions */ diff --git a/umvu/src/service.c b/umvu/src/service.c index 6b10737..aa1359f 100644 --- a/umvu/src/service.c +++ b/umvu/src/service.c @@ -60,19 +60,19 @@ void vu_mod_setht(struct vuht_entry_t *ht) { /* modules are not aware of direct or nested calls */ int vu_mod_getsyscall_number(void) { struct syscall_descriptor_t *sd = get_thread_sd(); - fatal(sd); + fatal(sd); return sd->syscall_number; } syscall_arg_t vu_mod_getsyscall_arg(unsigned int narg) { struct syscall_descriptor_t *sd = get_thread_sd(); - fatal(sd); + fatal(sd); if (narg < 6) return sd->syscall_args[narg]; else return 0; } - + void vu_mod_peek_str(void *addr, void *buf, size_t datalen) { struct syscall_descriptor_t *sd = get_thread_sd(); fatal(sd); diff --git a/umvu/src/umvu_main.c b/umvu/src/umvu_main.c index 72e768a..31c59ed 100644 --- a/umvu/src/umvu_main.c +++ b/umvu/src/umvu_main.c @@ -117,19 +117,19 @@ static void early_args(int argc, char *argv[]) { static void runrc(const char *path) { - if (faccessat(AT_FDCWD, path, X_OK, AT_EACCESS)==0) { - int pid; - int status; - - switch (pid=fork()) { - case -1: exit(2); - case 0: execl(path,path,(char *)0); - exit(2); + if (faccessat(AT_FDCWD, path, X_OK, AT_EACCESS)==0) { + int pid; + int status; + + switch (pid=fork()) { + case -1: exit(2); + case 0: execl(path,path,(char *)0); + exit(2); default: r_wait4(pid, &status, 0, NULL); - if (!WIFEXITED(status)) - exit(2); - } - } + if (!WIFEXITED(status)) + exit(2); + } + } } int main(int argc, char *argv[]) @@ -175,13 +175,13 @@ int main(int argc, char *argv[]) case 'S': seccomp = 0; break; case SECCOMP_ARG: seccomp = 1; - break; + break; } } argc -= optind; argv += optind; - + if (vu_name) set_vu_name(vu_name); diff --git a/umvu/src/umvu_tracer.c b/umvu/src/umvu_tracer.c index c1f895e..aa9743d 100644 --- a/umvu/src/umvu_tracer.c +++ b/umvu/src/umvu_tracer.c @@ -63,34 +63,34 @@ static void default_syscall_handler(syscall_state_t state, struct syscall_descri static syscall_handler_t syscall_handler = default_syscall_handler; /* This BPF filter: - returns SECCOMP_RET_ALLOW if the syscall is restart_syscall or poll(1, _, _). - it returns SECCOMP_RET_TRACE otherwise. */ + returns SECCOMP_RET_ALLOW if the syscall is restart_syscall or poll(1, _, _). + it returns SECCOMP_RET_TRACE otherwise. */ /* All syscalls are forwarded via ptrace to the hypervisor (but - restart_syscall or the special case of poll to manage the - hand-off between guardian angels) */ + restart_syscall or the special case of poll to manage the + hand-off between guardian angels) */ /* The hypervisor: - * changes the syscall number to -1 to skip the syscall - * returns PTRACE_CONT if the syscall is real (the kernel must process it) - * returns PTRACE_SYSCALL if the kernel must process it but post processing is needed + * changes the syscall number to -1 to skip the syscall + * returns PTRACE_CONT if the syscall is real (the kernel must process it) + * returns PTRACE_SYSCALL if the kernel must process it but post processing is needed */ static struct sock_filter seccomp_filter[] = { - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), + BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, nr)), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_restart_syscall, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_restart_syscall, 0, 1), + BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_ppoll, 0, 3), - BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, args[0])), - BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 1, 0, 1), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_ppoll, 0, 3), + BPF_STMT(BPF_LD+BPF_W+BPF_ABS, offsetof(struct seccomp_data, args[0])), + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 1, 0, 1), + BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_TRACE), + BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_TRACE), }; static struct sock_fprog seccomp_prog = { - .filter = seccomp_filter, - .len = (unsigned short) (sizeof(seccomp_filter)/sizeof(seccomp_filter[0])), + .filter = seccomp_filter, + .len = (unsigned short) (sizeof(seccomp_filter)/sizeof(seccomp_filter[0])), }; #ifdef DISABLE_VDSO @@ -369,9 +369,9 @@ static int umvu_trace_legacy(pid_t tracee_tid) if (syscall_desc.action & UMVU_CB_AFTER) syscall_handler(syscall_state, &syscall_desc); if (syscall_desc.action & UMVU_DO_IT_AGAIN) { - syscall_desc.prog_counter -= SYSCALL_INSTRUCTION_LEN; - umvu_poke_syscall(®s, &syscall_desc, POKE_ARGS); - P_SETREGS(sig_tid, ®s); + syscall_desc.prog_counter -= SYSCALL_INSTRUCTION_LEN; + umvu_poke_syscall(®s, &syscall_desc, POKE_ARGS); + P_SETREGS(sig_tid, ®s); } else { syscall_desc.inout = NULL; @@ -582,35 +582,35 @@ int umvu_tracer_fork(int seccomp) { /* check if seccomp/BPF is supported */ int umvu_tracer_test_seccomp(void) { - pid_t childpid; - int status; - struct sock_filter filter[] = { - BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), - }; - struct sock_fprog prog = { - .filter = filter, - .len = (unsigned short) (sizeof(filter)/sizeof(filter[0])), - }; - - childpid = r_fork(); - switch (childpid) { - case 0: - /*child*/ - if (r_prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) - exit(errno); - if (r_seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog) == -1) - exit(errno); - exit(0); - default: - r_wait4(childpid, &status, 0, NULL); - if (WEXITSTATUS(status) != 0) { - errno = WEXITSTATUS(status); - return -1; - } else - return 0; - case -1: - return -1; - } + pid_t childpid; + int status; + struct sock_filter filter[] = { + BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), + }; + struct sock_fprog prog = { + .filter = filter, + .len = (unsigned short) (sizeof(filter)/sizeof(filter[0])), + }; + + childpid = r_fork(); + switch (childpid) { + case 0: + /*child*/ + if (r_prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1) + exit(errno); + if (r_seccomp(SECCOMP_SET_MODE_FILTER, 0, &prog) == -1) + exit(errno); + exit(0); + default: + r_wait4(childpid, &status, 0, NULL); + if (WEXITSTATUS(status) != 0) { + errno = WEXITSTATUS(status); + return -1; + } else + return 0; + case -1: + return -1; + } } __attribute__((constructor)) diff --git a/umvu/src/vu_access_emu.c b/umvu/src/vu_access_emu.c index fc20ac1..d18488d 100644 --- a/umvu/src/vu_access_emu.c +++ b/umvu/src/vu_access_emu.c @@ -25,15 +25,15 @@ #include static int _is_group_member(gid_t gid) { - int len = getgroups(0, NULL); - gid_t list[len]; - int i; - len = getgroups(len, list); - for (i = 0; i < len; i++) { - if (gid == list[i]) - return 1; - } - return 0; + int len = getgroups(0, NULL); + gid_t list[len]; + int i; + len = getgroups(len, list); + for (i = 0; i < len; i++) { + if (gid == list[i]) + return 1; + } + return 0; } int vu_access_emu(struct vu_stat *statbuf, int mode, int flags) { @@ -48,31 +48,31 @@ int vu_access_emu(struct vu_stat *statbuf, int mode, int flags) { uid_t uid = (flags & AT_EACCESS) ? geteuid() : getuid(); - if (uid == 0) { // it is root - if ((mode & X_OK) == 0) // RW are always allowed - return 0; - // X OK is X is okay for someone - if (statbuf->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) - return 0; - } + if (uid == 0) { // it is root + if ((mode & X_OK) == 0) // RW are always allowed + return 0; + // X OK is X is okay for someone + if (statbuf->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) + return 0; + } - int granted; + int granted; - if (uid == statbuf->st_uid) - // user permissions - granted = (int) ((statbuf->st_mode >> 6) & mode); - else { - gid_t gid = (flags & AT_EACCESS) ? getegid() : getgid(); - if (statbuf->st_gid == gid || _is_group_member(statbuf->st_gid)) - // group permissions - granted = (int) ((statbuf->st_mode >> 3) & mode); - else - // other permissions - granted = statbuf->st_mode & mode; - } + if (uid == statbuf->st_uid) + // user permissions + granted = (int) ((statbuf->st_mode >> 6) & mode); + else { + gid_t gid = (flags & AT_EACCESS) ? getegid() : getgid(); + if (statbuf->st_gid == gid || _is_group_member(statbuf->st_gid)) + // group permissions + granted = (int) ((statbuf->st_mode >> 3) & mode); + else + // other permissions + granted = statbuf->st_mode & mode; + } - if (granted == mode) - return 0; + if (granted == mode) + return 0; - return -EACCES; + return -EACCES; } diff --git a/umvu/src/vu_choice.c b/umvu/src/vu_choice.c index ffe34ce..8fbf07e 100644 --- a/umvu/src/vu_choice.c +++ b/umvu/src/vu_choice.c @@ -83,23 +83,23 @@ struct vuht_entry_t *choice_fd(struct syscall_descriptor_t *sd) { * can use a file descriptor * can use the request number as a parameter */ struct vuht_entry_t *choice_ioctl(struct syscall_descriptor_t *sd) { - struct syscall_extra_t *extra = sd->extra; - int fd = sd->syscall_args[0]; + struct syscall_extra_t *extra = sd->extra; + int fd = sd->syscall_args[0]; unsigned long request = sd->syscall_args[1]; - int nested = extra->nested; - struct vuht_entry_t *ht = vu_fd_get_ht(fd, nested); - char path[PATH_MAX]; - vu_fd_get_path(fd, nested, path, PATH_MAX); - extra->path = strdup(path); - extra->statbuf.st_mode = vu_fd_get_mode(fd, nested); - if (ht) { - set_vepoch(vuht_get_vepoch(ht)); - vuht_pick_again(ht); - } else + int nested = extra->nested; + struct vuht_entry_t *ht = vu_fd_get_ht(fd, nested); + char path[PATH_MAX]; + vu_fd_get_path(fd, nested, path, PATH_MAX); + extra->path = strdup(path); + extra->statbuf.st_mode = vu_fd_get_mode(fd, nested); + if (ht) { + set_vepoch(vuht_get_vepoch(ht)); + vuht_pick_again(ht); + } else ht = vuht_pick(CHECKIOCTL, &request, NULL, SET_EPOCH); - printkdebug(c, "ioctl %d %s: %c ht %p", fd, extra->path, - nested ? 'N' : '-', ht); - return ht; + printkdebug(c, "ioctl %d %s: %c ht %p", fd, extra->path, + nested ? 'N' : '-', ht); + return ht; } /* standard choice function: if there is a path it uses the path @@ -141,7 +141,7 @@ struct vuht_entry_t *choice_utimensat(struct syscall_descriptor_t *sd) { /* mount uses filesystem type */ struct vuht_entry_t *choice_mount(struct syscall_descriptor_t *sd) { - int nested = sd->extra->nested; + int nested = sd->extra->nested; if (nested) /* nested calls cannot be further virtualized */ return NULL; @@ -153,13 +153,13 @@ struct vuht_entry_t *choice_mount(struct syscall_descriptor_t *sd) { umvu_peek_str(filesystemtype_addr, filesystemtype, PATH_MAX); ht = vuht_pick(CHECKFSTYPE, filesystemtype, NULL, 0); printkdebug(c, "mount %s on %s: - ht %p", filesystemtype, extra->path, ht); - return ht; + return ht; } } /* mount pathname must match exactly the mountpoint */ struct vuht_entry_t *choice_umount2(struct syscall_descriptor_t *sd) { - int nested = sd->extra->nested; + int nested = sd->extra->nested; if (nested) /* nested calls cannot be further virtualized */ return NULL; @@ -177,8 +177,8 @@ struct vuht_entry_t *choice_umount2(struct syscall_descriptor_t *sd) { ht = vuht_pick(CHECKPATHEXACT, no_root_path, &extra->statbuf, SET_EPOCH); } printkdebug(c, "umount2 %s: - ht %p err = %d %s", extra->path, ht, - (sd->action == SKIPIT) ? -sd->ret_value : 0, - (sd->action == SKIPIT) ? "SKIPIT" : ""); + (sd->action == SKIPIT) ? -sd->ret_value : 0, + (sd->action == SKIPIT) ? "SKIPIT" : ""); return ht; } } @@ -186,49 +186,49 @@ struct vuht_entry_t *choice_umount2(struct syscall_descriptor_t *sd) { /* mmap uses fd (fifth argument) */ struct vuht_entry_t *choice_mmap(struct syscall_descriptor_t *sd) { struct syscall_extra_t *extra = sd->extra; - int fd = sd->syscall_args[4]; - int nested = extra->nested; - struct vuht_entry_t *ht = vu_fd_get_ht(fd, nested); - char path[PATH_MAX]; - vu_fd_get_path(fd, nested, path, PATH_MAX); - extra->path = strdup(path); - extra->statbuf.st_mode = vu_fd_get_mode(fd, nested); - printkdebug(c, "mmap2 %d %s: %c ht %p", fd, extra->path, - nested ? 'N' : '-', ht); - if (ht) { + int fd = sd->syscall_args[4]; + int nested = extra->nested; + struct vuht_entry_t *ht = vu_fd_get_ht(fd, nested); + char path[PATH_MAX]; + vu_fd_get_path(fd, nested, path, PATH_MAX); + extra->path = strdup(path); + extra->statbuf.st_mode = vu_fd_get_mode(fd, nested); + printkdebug(c, "mmap2 %d %s: %c ht %p", fd, extra->path, + nested ? 'N' : '-', ht); + if (ht) { extra->mpath = vuht_path2mpath(ht, extra->path); - set_vepoch(vuht_get_vepoch(ht)); - vuht_pick_again(ht); - } - return ht; + set_vepoch(vuht_get_vepoch(ht)); + vuht_pick_again(ht); + } + return ht; } /* some system calls need to use the file descriptor passed as second argument (e.g. epoll_ctl) */ struct vuht_entry_t *choice_fd2(struct syscall_descriptor_t *sd) { - struct syscall_extra_t *extra = sd->extra; - int fd = sd->syscall_args[2]; - int nested = extra->nested; - struct vuht_entry_t *ht = vu_fd_get_ht(fd, nested); - char path[PATH_MAX]; - vu_fd_get_path(fd, nested, path, PATH_MAX); - extra->path = strdup(path); - extra->statbuf.st_mode = vu_fd_get_mode(fd, nested); - printkdebug(c, "fd2 %d %s: %c ht %p", fd, extra->path, - nested ? 'N' : '-', ht); - if (ht) { + struct syscall_extra_t *extra = sd->extra; + int fd = sd->syscall_args[2]; + int nested = extra->nested; + struct vuht_entry_t *ht = vu_fd_get_ht(fd, nested); + char path[PATH_MAX]; + vu_fd_get_path(fd, nested, path, PATH_MAX); + extra->path = strdup(path); + extra->statbuf.st_mode = vu_fd_get_mode(fd, nested); + printkdebug(c, "fd2 %d %s: %c ht %p", fd, extra->path, + nested ? 'N' : '-', ht); + if (ht) { extra->mpath = vuht_path2mpath(ht, extra->path); - set_vepoch(vuht_get_vepoch(ht)); - vuht_pick_again(ht); - } - return ht; + set_vepoch(vuht_get_vepoch(ht)); + vuht_pick_again(ht); + } + return ht; } /* socket uses the protocol family */ struct vuht_entry_t *choice_socket(struct syscall_descriptor_t *sd) { struct syscall_extra_t *extra = sd->extra; int domain = sd->syscall_args[0]; - int nested = extra->nested; + int nested = extra->nested; struct vuht_entry_t *ht = vuht_pick(CHECKSOCKET, &domain, NULL, SET_EPOCH); printkdebug(c, "socket: fam:%d %c ht %p", domain, nested ? 'N' : '-', ht); return ht; @@ -239,7 +239,7 @@ struct vuht_entry_t *choice_msocket(struct syscall_descriptor_t *sd) { struct syscall_extra_t *extra = sd->extra; uintptr_t path = sd->syscall_args[0]; int domain = sd->syscall_args[1]; - int nested = extra->nested; + int nested = extra->nested; if (path == 0) { /* msocket path == NULL ===> socket) */ struct vuht_entry_t *ht = vuht_pick(CHECKSOCKET, &domain, NULL, SET_EPOCH); diff --git a/umvu/src/vu_fd_table.c b/umvu/src/vu_fd_table.c index 7939f89..3f7789e 100644 --- a/umvu/src/vu_fd_table.c +++ b/umvu/src/vu_fd_table.c @@ -69,23 +69,23 @@ static __thread struct vu_fd_table_t *vu_fd = NULL; } while(0) #define pthread_rwlock_wrlock(X) do { \ - if (X == &vu_n_fd->lock) { \ - printk("pthread_rwlock_wrlock %d\n", __LINE__); \ - pthread_rwlock_wrlock(X); \ - printk("pthread_rwlock_wrlock done %d\n", __LINE__); \ - } \ - else \ - pthread_rwlock_wrlock(X); \ + if (X == &vu_n_fd->lock) { \ + printk("pthread_rwlock_wrlock %d\n", __LINE__); \ + pthread_rwlock_wrlock(X); \ + printk("pthread_rwlock_wrlock done %d\n", __LINE__); \ + } \ + else \ + pthread_rwlock_wrlock(X); \ } while(0) #define pthread_rwlock_unlock(X) do { \ - if (X == &vu_n_fd->lock) { \ - printk("pthread_rwlock_unlock %d\n", __LINE__); \ - pthread_rwlock_unlock(X); \ - printk("pthread_rwlock_unlock done %d\n", __LINE__); \ - } \ - else \ - pthread_rwlock_unlock(X); \ + if (X == &vu_n_fd->lock) { \ + printk("pthread_rwlock_unlock %d\n", __LINE__); \ + pthread_rwlock_unlock(X); \ + printk("pthread_rwlock_unlock done %d\n", __LINE__); \ + } \ + else \ + pthread_rwlock_unlock(X); \ } while(0) #endif @@ -179,18 +179,18 @@ static void vu_fd_close_on_exec(void) { static void vu_fd_table_resize(struct vu_fd_table_t *fd_table, int fd) { if (fd >= fd_table->table_size) { - int i; - int new_size = (fd + (FD_TABLE_CHUNK)) & ~(FD_TABLE_CHUNK - 1); - fd_table->fnode = realloc(fd_table->fnode, new_size * sizeof(fd_table->fnode[0])); - fatal(fd_table->fnode); - fd_table->flags = realloc(fd_table->flags, new_size * sizeof(fd_table->flags[0])); - fatal(fd_table->flags); - for (i = fd_table->table_size; i < new_size; i++) { - fd_table->fnode[i] = NULL; - fd_table->flags[i] = 0; - } - fd_table->table_size = new_size; - } + int i; + int new_size = (fd + (FD_TABLE_CHUNK)) & ~(FD_TABLE_CHUNK - 1); + fd_table->fnode = realloc(fd_table->fnode, new_size * sizeof(fd_table->fnode[0])); + fatal(fd_table->fnode); + fd_table->flags = realloc(fd_table->flags, new_size * sizeof(fd_table->flags[0])); + fatal(fd_table->flags); + for (i = fd_table->table_size; i < new_size; i++) { + fd_table->fnode[i] = NULL; + fd_table->flags[i] = 0; + } + fd_table->table_size = new_size; + } } /* "connect" a fd to its fnode. @@ -202,7 +202,7 @@ static void vu_fd_table_resize(struct vu_fd_table_t *fd_table, int fd) { this is *4 */ void vu_fd_set_fnode(int fd, int nested, struct vu_fnode_t *fnode, int fdflags) { struct vu_fd_table_t *fd_table = VU_FD_TABLE(nested); - fatal(fd_table); + fatal(fd_table); pthread_rwlock_wrlock(&fd_table->lock); vu_fd_table_resize(fd_table, fd); fd_table->fnode[fd] = fnode; @@ -239,7 +239,7 @@ int vu_fd_close(int fd, int nested) { void vu_fd_dup(int fd, int nested, int oldfd, int fdflags) { struct vu_fd_table_t *fd_table = VU_FD_TABLE(nested); - fatal(fd_table); + fatal(fd_table); if (fd >= 0) { pthread_rwlock_wrlock(&fd_table->lock); printkdebug(d, "dup %p fd=%d->%d", vu_fd, oldfd, fd); @@ -276,11 +276,11 @@ static uint8_t *get_flags_addr_nolock(struct vu_fd_table_t *fd_table, int fd) { struct vu_fnode_t *vu_fd_get_fnode(int fd, int nested) { struct vu_fd_table_t *fd_table = VU_FD_TABLE(nested); - struct vu_fnode_t *fnode; + struct vu_fnode_t *fnode; pthread_rwlock_rdlock(&fd_table->lock); - fnode = get_fnode_nolock(fd_table, fd); - pthread_rwlock_unlock(&fd_table->lock); - return fnode; + fnode = get_fnode_nolock(fd_table, fd); + pthread_rwlock_unlock(&fd_table->lock); + return fnode; } struct vuht_entry_t *vu_fd_get_ht(int fd, int nested) { @@ -377,22 +377,22 @@ int vu_fd_get_sfd(int fd, void **pprivate, int nested) { void vu_fd_get_possize_lock(int fd, int nested, off_t *pos, off_t *size) { struct vu_fd_table_t *fd_table = VU_FD_TABLE(nested); - struct vu_fnode_t *fnode; - pthread_rwlock_rdlock(&fd_table->lock); - fnode = get_fnode_nolock(fd_table, fd); + struct vu_fnode_t *fnode; + pthread_rwlock_rdlock(&fd_table->lock); + fnode = get_fnode_nolock(fd_table, fd); if (fnode) vu_fnode_get_possize_lock(fnode, pos, size); - pthread_rwlock_unlock(&fd_table->lock); + pthread_rwlock_unlock(&fd_table->lock); } void vu_fd_set_possize_unlock(int fd, int nested, off_t pos, off_t size) { struct vu_fd_table_t *fd_table = VU_FD_TABLE(nested); - struct vu_fnode_t *fnode; - pthread_rwlock_rdlock(&fd_table->lock); - fnode = get_fnode_nolock(fd_table, fd); + struct vu_fnode_t *fnode; + pthread_rwlock_rdlock(&fd_table->lock); + fnode = get_fnode_nolock(fd_table, fd); if (fnode) vu_fnode_set_possize_unlock(fnode, pos, size); - pthread_rwlock_unlock(&fd_table->lock); + pthread_rwlock_unlock(&fd_table->lock); } static void *vu_fd_tracer_upcall(inheritance_state_t state, void *ioarg, void *arg) { diff --git a/umvu/src/vu_file_table.c b/umvu/src/vu_file_table.c index 9a9289a..be46df2 100644 --- a/umvu/src/vu_file_table.c +++ b/umvu/src/vu_file_table.c @@ -130,11 +130,11 @@ void vu_fnode_dup(struct vu_fnode_t *fnode) { } struct vuht_entry_t *vu_fnode_get_ht(struct vu_fnode_t *v) { - struct vuht_entry_t *ret_value; - pthread_rwlock_rdlock(&v->lock); - ret_value = v->ht; - pthread_rwlock_unlock(&v->lock); - return ret_value; + struct vuht_entry_t *ret_value; + pthread_rwlock_rdlock(&v->lock); + ret_value = v->ht; + pthread_rwlock_unlock(&v->lock); + return ret_value; } void vu_fnode_get_path(struct vu_fnode_t *v, char *dest, size_t n) { @@ -187,7 +187,7 @@ int vu_fnode_get_sfd(struct vu_fnode_t *v, void **pprivate) { } int vu_fnode_copyinout (struct vu_fnode_t *v, copyfun cp) { - int ret_value; + int ret_value; pthread_rwlock_rdlock(&v->lock); ret_value = vu_vnode_copyinout(v->vnode, v->path, cp); pthread_rwlock_unlock(&v->lock); @@ -215,6 +215,6 @@ off_t vu_fnode_getset_size(struct vuht_entry_t *ht, struct vu_stat *stat, off_t __attribute__((constructor)) static void init(void) { - debug_set_name(f, "FILETABLE"); - } + debug_set_name(f, "FILETABLE"); + } diff --git a/umvu/src/vu_fnode_copy.c b/umvu/src/vu_fnode_copy.c index f42b219..cc5eddd 100644 --- a/umvu/src/vu_fnode_copy.c +++ b/umvu/src/vu_fnode_copy.c @@ -37,16 +37,16 @@ /* some system calls need the file to be real (execve, mmap). this function creates a copy of a virtual file in tmp_path (usually in /tmp/.vu_....) */ static int copyfile_in(struct vuht_entry_t *ht, char *path, char *tmp_path) { - int fdin, fdout; + int fdin, fdout; ssize_t n; size_t filesize = 0; - char *buf[BUFSIZ]; - void *private; + char *buf[BUFSIZ]; + void *private; struct vu_stat fdoutstat; //printk("COPY %s to %s\n",path,tmp_path); - fdout = r_open(tmp_path, O_WRONLY | O_CREAT | O_CLOEXEC, 0700); - if (fdout < 0) - return -1; + fdout = r_open(tmp_path, O_WRONLY | O_CREAT | O_CLOEXEC, 0700); + if (fdout < 0) + return -1; if (r_fstat(fdout, &fdoutstat) < 0) { r_close(fdout); return -1; diff --git a/umvu/src/vu_initfini.c b/umvu/src/vu_initfini.c index 1dabda5..200e20f 100644 --- a/umvu/src/vu_initfini.c +++ b/umvu/src/vu_initfini.c @@ -26,8 +26,8 @@ #include struct voidfun_elem_t { - voidfun_t upcall; - struct voidfun_elem_t *next; + voidfun_t upcall; + struct voidfun_elem_t *next; }; /* constructor and destructor list head/tail pointers */ @@ -59,30 +59,30 @@ void vu_destructor_register(voidfun_t upcall) { destructor_list_h = new; else destructor_list_t->next = new; - destructor_list_t = new; + destructor_list_t = new; } static void umvu_voidfun_list_run(struct voidfun_elem_t *list) { - struct voidfun_elem_t *scan; - for (scan = list; scan != NULL; scan = scan->next) - scan->upcall(); + struct voidfun_elem_t *scan; + for (scan = list; scan != NULL; scan = scan->next) + scan->upcall(); } static void sig_handler(int sig) { signal(sig, SIG_DFL); vu_fini(); if (sig == SIGTERM) - r_exit(0); - else - r_kill(-getpgrp(), sig); + r_exit(0); + else + r_kill(-getpgrp(), sig); } static void setsighandlers(void) { struct sigaction sa = { - .sa_handler = sig_handler, - .sa_flags = 0, - .sa_restorer = NULL}; - sigfillset(&sa.sa_mask); + .sa_handler = sig_handler, + .sa_flags = 0, + .sa_restorer = NULL}; + sigfillset(&sa.sa_mask); sigaction(SIGHUP, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); diff --git a/umvu/src/vu_modutils.c b/umvu/src/vu_modutils.c index 84e7d58..2da2c16 100644 --- a/umvu/src/vu_modutils.c +++ b/umvu/src/vu_modutils.c @@ -70,12 +70,12 @@ static inline char *gethomedir(void) { static void *module_dlopen(const char *modname, int flags) { #define TRY_DLOPEN(...) \ -{ \ - snprintf(testpath, tplen, __VA_ARGS__); \ - if ((handle = dlopen(testpath, flags))) { \ - return handle; \ - } \ -} + { \ + snprintf(testpath, tplen, __VA_ARGS__); \ + if ((handle = dlopen(testpath, flags))) { \ + return handle; \ + } \ + } void *handle; char *homedir = gethomedir(); int tplen = strlen(modname) + strlen(MODULES_EXT) + @@ -160,7 +160,7 @@ syscall_t *vu_syscall_handler_pointer(struct vu_service_t *service, char *name) if (strcmp(name, vu_syscall_names[i]) == 0) return &service->module_syscall[i]; } - useless = NULL; + useless = NULL; return &useless; } @@ -195,12 +195,12 @@ void module_run_init(struct vu_service_t *service) { } int module_run_fini(struct vu_service_t *service) { - int (*fini)(void *); + int (*fini)(void *); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" - fini = module_getsym(service, "fini"); + fini = module_getsym(service, "fini"); #pragma GCC diagnostic pop - if (fini) { + if (fini) { printkdebug(m, "%s running vu_%s_fini", service->mod->name, service->mod->name); return fini(service->private); } else @@ -208,8 +208,8 @@ int module_run_fini(struct vu_service_t *service) { } __attribute__((constructor)) - static void init(void) { - debug_set_name(m, "MODULE"); - } + static void init(void) { + debug_set_name(m, "MODULE"); + } diff --git a/umvu/src/vu_pthreads.c b/umvu/src/vu_pthreads.c index 67786a7..1241137 100644 --- a/umvu/src/vu_pthreads.c +++ b/umvu/src/vu_pthreads.c @@ -27,8 +27,8 @@ static int (*libc_pthread_create)(); struct _pthread_arg { - void *(*start_routine) (void *); - void *start_arg; + void *(*start_routine) (void *); + void *start_arg; void *inherited_args[]; }; @@ -38,33 +38,33 @@ void cleanup(void *arg) { } void *_pthread_wrapper(void *arg) { - struct _pthread_arg *ptarg = arg; + struct _pthread_arg *ptarg = arg; - void *(*start_routine) (void *) = ptarg->start_routine; - void *start_arg = ptarg->start_arg; + void *(*start_routine) (void *) = ptarg->start_routine; + void *start_arg = ptarg->start_arg; vu_inheritance_call(INH_PTHREAD_START, ptarg->inherited_args, NULL); free(ptarg); - pthread_cleanup_push(cleanup, NULL); + pthread_cleanup_push(cleanup, NULL); //printk("start_routine \n"); - start_arg = start_routine(start_arg); + start_arg = start_routine(start_arg); //printk("start_routine DONE\n"); - pthread_cleanup_pop(1); + pthread_cleanup_pop(1); - return start_arg; + return start_arg; } int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine) (void *), void *arg) { + void *(*start_routine) (void *), void *arg) { //printk("pthread_create\n"); struct _pthread_arg *ptarg = malloc(sizeof(struct _pthread_arg) + vu_inheritance_inout_size()); fatal(ptarg); ptarg->start_routine = start_routine; - ptarg->start_arg = arg; + ptarg->start_arg = arg; vu_inheritance_call(INH_PTHREAD_CLONE, ptarg->inherited_args, (void *) -1); - return libc_pthread_create(thread, attr, _pthread_wrapper, ptarg); + return libc_pthread_create(thread, attr, _pthread_wrapper, ptarg); } __attribute__((constructor)) diff --git a/umvu/src/vu_slow_calls.c b/umvu/src/vu_slow_calls.c index cd85e0a..e1b0c7f 100644 --- a/umvu/src/vu_slow_calls.c +++ b/umvu/src/vu_slow_calls.c @@ -82,7 +82,7 @@ pid_t vu_slowcall_during(struct slowcall *sc) { //printk(">>>>>>>>>%lu\n", pthread_self()); return libc_clone(slow_thread, sc->stack + STACKSIZE, CLONE_FILES | CLONE_VM | CLONE_CHILD_CLEARTID | CLONE_CHILD_SETTID | SIGCHLD, - sc); + sc); } void vu_slowcall_out(struct slowcall *sc, struct vuht_entry_t *ht, int fd, uint32_t events, int nested) { diff --git a/umvu/src/vu_vnode.c b/umvu/src/vu_vnode.c index e1cd177..59d64bf 100644 --- a/umvu/src/vu_vnode.c +++ b/umvu/src/vu_vnode.c @@ -63,8 +63,8 @@ static pthread_mutex_t vnode_mutex = PTHREAD_MUTEX_INITIALIZER; static struct vu_vnode_t *vnode_hash[VU_VNODE_HASH_SIZE]; -__attribute__((always_inline)) - static inline int vnode_hashfun(struct vuht_entry_t *ht, dev_t dev, ino_t inode) + __attribute__((always_inline)) +static inline int vnode_hashfun(struct vuht_entry_t *ht, dev_t dev, ino_t inode) { uintptr_t htint = (uintptr_t) ht; return (major(dev) + minor(dev) + inode + ((13 * htint) ^ (htint >> 13))) & VU_VNODE_HASH_MASK; @@ -95,8 +95,8 @@ struct vu_vnode_t *vu_vnode_open(struct vuht_entry_t *ht, ino_t dev, ino_t inode new_vnode->inode = inode; new_vnode->size = size; if (asprintf(&new_vnode->vpath, "%s/%p_%lx_%lx", - vu_tmpdirpath(), (void *) ht, - (unsigned long) dev, (unsigned long) inode) <= 0) { + vu_tmpdirpath(), (void *) ht, + (unsigned long) dev, (unsigned long) inode) <= 0) { errno = ENOMEM; fatal(NULL); } @@ -143,7 +143,7 @@ int vu_vnode_copyinout (struct vu_vnode_t *vnode, char *path, copyfun cp) { int ret_value; pthread_mutex_lock(&vnode->mutex); ret_value = cp(vnode->ht, path, vnode->vpath); - pthread_mutex_unlock(&vnode->mutex); + pthread_mutex_unlock(&vnode->mutex); return ret_value; } diff --git a/umvu/src/vu_vwrap_vumgmt.c b/umvu/src/vu_vwrap_vumgmt.c index bbfa605..4d9b90a 100644 --- a/umvu/src/vu_vwrap_vumgmt.c +++ b/umvu/src/vu_vwrap_vumgmt.c @@ -177,9 +177,9 @@ void vuctl_setname(struct syscall_descriptor_t *sd) { char vu_name[_UTSNAME_LENGTH+1]; syscall_arg_t name_addr = sd->syscall_args[1]; if (umvu_peek_str(name_addr, vu_name, _UTSNAME_LENGTH+1) < 0) { - sd->ret_value = -EINVAL; - return; - } + sd->ret_value = -EINVAL; + return; + } set_vu_name(vu_name); sd->ret_value = 0; } @@ -203,9 +203,9 @@ void vuctl_add_debugtags(struct syscall_descriptor_t *sd) { syscall_arg_t tags_addr = sd->syscall_args[1]; int local = sd->syscall_args[2]; if (umvu_peek_str(tags_addr, tags, DEBUG_NTAGS+1) < 0) { - sd->ret_value = -EINVAL; - return; - } + sd->ret_value = -EINVAL; + return; + } debug_add_tags(tags, local); sd->ret_value = 0; } diff --git a/umvu/src/vu_wrap_cap.c b/umvu/src/vu_wrap_cap.c index e310bc1..f82cfd5 100644 --- a/umvu/src/vu_wrap_cap.c +++ b/umvu/src/vu_wrap_cap.c @@ -55,8 +55,8 @@ void wi_capget(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } if (datap == 0) { sd->ret_value = 0; - return; - } + return; + } vu_alloc_local_arg(datap, data, sizeof(*data) * _LINUX_CAPABILITY_U32S_3, nested); if (ht) { diff --git a/umvu/src/vu_wrap_execve.c b/umvu/src/vu_wrap_execve.c index f2bd59d..3a7d13f 100644 --- a/umvu/src/vu_wrap_execve.c +++ b/umvu/src/vu_wrap_execve.c @@ -93,7 +93,7 @@ static int read_exec_header(struct vuht_entry_t *ht, struct binfmt_req_t *req) { } /* the confirm function re-assigns the filehead field of the struct binfmt_req to - "!%" + path of the interpreter */ + "!%" + path of the interpreter */ static void check_binfmt_misc(struct binfmt_req_t *req) { struct vuht_entry_t *binfmt_ht; if ((binfmt_ht = vuht_pick(CHECKBINFMT, req, NULL, 0)) != NULL) @@ -115,23 +115,23 @@ int interpreter_fill_args(struct binfmt_req_t *req, char *argv[2]) { char *interpreter = req->filehead + 2; char *extra_arg; char *scan; - char *term; + char *term; if ((scan = memchr(req->filehead, '\n', req->fileheadlen)) != NULL) - *scan = 0; + *scan = 0; if ((scan = memchr(req->filehead, '\0', req->fileheadlen)) == NULL || req->filehead[0] != '#' || req->filehead[1] != '!') { errno = EINVAL; - return -1; + return -1; } - interpreter += strspn(interpreter, " \t"); - scan = interpreter; - scan += strcspn(scan, " \t\n"); - term = scan; - scan += strspn(scan, " \t"); - extra_arg = scan; - scan += strcspn(scan, "\n"); - *scan = 0; - *term = 0; + interpreter += strspn(interpreter, " \t"); + scan = interpreter; + scan += strcspn(scan, " \t\n"); + term = scan; + scan += strspn(scan, " \t"); + extra_arg = scan; + scan += strcspn(scan, "\n"); + *scan = 0; + *term = 0; argv[0] = interpreter; argv[1] = extra_arg; return *extra_arg == '\0' ? 1 : 2; @@ -209,7 +209,7 @@ static void copy_argv(uintptr_t *newargv, struct argv_list *argv) { static void push_argv(struct syscall_descriptor_t *sd, struct argv_list *argv) { struct argv_item *scan; - for (scan = argv->argv_head; scan != NULL; scan = scan->next) { + for (scan = argv->argv_head; scan != NULL; scan = scan->next) { if (scan->arg == 0) scan->arg = vu_push(sd, scan->larg, strlen(scan->larg) + 1); } @@ -269,9 +269,9 @@ static void recursive_interpreter(struct binfmt_req_t *req, struct syscall_descr if (depth > EXECVE_MAX_DEPTH) { sd->ret_value = -ELOOP; - sd->action = SKIPIT; - return; - } + sd->action = SKIPIT; + return; + } epoch_t e = set_vepoch(sd->extra->epoch); if ((extra_argc = interpreter_fill_args(req, extra_argv)) < 0) { diff --git a/umvu/src/vu_wrap_fs.c b/umvu/src/vu_wrap_fs.c index 9a1f18c..f16a848 100644 --- a/umvu/src/vu_wrap_fs.c +++ b/umvu/src/vu_wrap_fs.c @@ -90,9 +90,9 @@ void wi_lstat(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } /* update st_size of currently open files */ if (S_ISREG(statbuf->st_mode) && (service_getflags(ht) & VU_USE_PRW)) { - off_t opensize = vu_fnode_getset_size(ht, statbuf, -1); - if (opensize >= 0) - statbuf->st_size = opensize; + off_t opensize = vu_fnode_getset_size(ht, statbuf, -1); + if (opensize >= 0) + statbuf->st_size = opensize; } /* store results */ vu_poke_arg(bufaddr, statbuf, sizeof(*statbuf), nested); @@ -102,7 +102,7 @@ void wi_lstat(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { /* statx */ void wi_statx(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { - if (ht) { + if (ht) { /* standard args */ int nested = sd->extra->nested; int syscall_number = sd->syscall_number; @@ -118,13 +118,13 @@ void wi_statx(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { /* call */ /* emulation mode. XXX - future module support? */ - sd->action = SKIPIT; + sd->action = SKIPIT; struct vu_stat statbuf; - ret_value = service_syscall(ht, __VU_lstat)(sd->extra->mpath, &statbuf, flags, -1, NULL); - if (ret_value < 0) { - sd->ret_value = -errno; - return; - } + ret_value = service_syscall(ht, __VU_lstat)(sd->extra->mpath, &statbuf, flags, -1, NULL); + if (ret_value < 0) { + sd->ret_value = -errno; + return; + } (void) mask; // unused in emulation mode statxbuf->stx_mask = STATX_BASIC_STATS; @@ -162,7 +162,7 @@ void wi_statx(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { void wi_readlink(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { if (ht) { /* standard args */ - int nested = sd->extra->nested; + int nested = sd->extra->nested; int syscall_number = sd->syscall_number; ssize_t ret_value; /* args */ @@ -351,37 +351,37 @@ void wi_mkdir(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { /* mknod */ void wi_mknod(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { - if (ht) { - /* standard args */ - int syscall_number = sd->syscall_number; - int ret_value; - /* args */ - int mode; - dev_t dev; - /* local bufs */ - /* fetch args */ - switch (syscall_number) { - case __NR_mknod: - mode = sd->syscall_args[1]; - dev = sd->syscall_args[2]; - break; - case __NR_mknodat: - mode = sd->syscall_args[2]; - dev = sd->syscall_args[3]; - break; + if (ht) { + /* standard args */ + int syscall_number = sd->syscall_number; + int ret_value; + /* args */ + int mode; + dev_t dev; + /* local bufs */ + /* fetch args */ + switch (syscall_number) { + case __NR_mknod: + mode = sd->syscall_args[1]; + dev = sd->syscall_args[2]; + break; + case __NR_mknodat: + mode = sd->syscall_args[2]; + dev = sd->syscall_args[3]; + break; default: default_nosys(sd); - } + } mode = mode & ~vu_fs_get_umask(); - /* call */ - sd->action = SKIPIT; - ret_value = service_syscall(ht, __VU_mknod)(sd->extra->mpath, mode, dev); - if (ret_value < 0) { - sd->ret_value = -errno; - return; - } - /* store results */ - sd->ret_value = ret_value; - } + /* call */ + sd->action = SKIPIT; + ret_value = service_syscall(ht, __VU_mknod)(sd->extra->mpath, mode, dev); + if (ret_value < 0) { + sd->ret_value = -errno; + return; + } + /* store results */ + sd->ret_value = ret_value; + } } /* rmdir */ @@ -488,33 +488,33 @@ void wi_chmod(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } static void utime2utimen(struct utimbuf *in_times, struct timespec *out_times) { - out_times[0].tv_sec = in_times->actime; - out_times[1].tv_sec = in_times->modtime; - out_times[0].tv_nsec = out_times[1].tv_nsec = 0; + out_times[0].tv_sec = in_times->actime; + out_times[1].tv_sec = in_times->modtime; + out_times[0].tv_nsec = out_times[1].tv_nsec = 0; } static void utimes2utimen(struct timeval *in_times, struct timespec *out_times) { - out_times[0].tv_sec = in_times[0].tv_sec; - out_times[1].tv_sec = in_times[1].tv_sec; - out_times[0].tv_nsec = in_times[0].tv_usec * 1000; - out_times[1].tv_nsec = in_times[1].tv_usec * 1000; + out_times[0].tv_sec = in_times[0].tv_sec; + out_times[1].tv_sec = in_times[1].tv_sec; + out_times[0].tv_nsec = in_times[0].tv_usec * 1000; + out_times[1].tv_nsec = in_times[1].tv_usec * 1000; } /* utimensat, utime, utimes, futimesat */ void wi_utimensat(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { - if (ht) { - /* standard args */ - int nested = sd->extra->nested; - int syscall_number = sd->syscall_number; - int ret_value; - /* args */ + if (ht) { + /* standard args */ + int nested = sd->extra->nested; + int syscall_number = sd->syscall_number; + int ret_value; + /* args */ int inarg = 1; struct timespec times[2]; int flags = 0; int sfd = -1; - void *private = NULL; - /* fetch args */ - switch (syscall_number) { + void *private = NULL; + /* fetch args */ + switch (syscall_number) { case __NR_utime: case __NR_utimes: break; @@ -535,7 +535,7 @@ void wi_utimensat(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { if (sd->syscall_args[inarg] == (uintptr_t) NULL) { clock_gettime(CLOCK_REALTIME, ×[0]); times[1] = times[0]; - } else { + } else { if (nested) { switch (syscall_number) { case __NR_utime: { @@ -613,8 +613,8 @@ void wi_link(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { sd->action = SKIPIT; if (sd->extra->statbuf.st_mode != 0) { sd->ret_value = -EEXIST; - return; - } + return; + } e = set_vepoch(sd->extra->epoch); /* old/src path must be canonicalized */ oldpath = get_path(dirfd, oldaddr, NULL, 0, NULL, nested); @@ -682,11 +682,11 @@ void wi_rename(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { epoch_t e; switch (syscall_number) { case __NR_rename: dirfd = AT_FDCWD; - oldaddr = sd->syscall_args[0]; - break; - case __NR_renameat: dirfd = sd->syscall_args[0]; - oldaddr = sd->syscall_args[1]; + oldaddr = sd->syscall_args[0]; break; + case __NR_renameat: dirfd = sd->syscall_args[0]; + oldaddr = sd->syscall_args[1]; + break; case __NR_renameat2: dirfd = sd->syscall_args[0]; oldaddr = sd->syscall_args[1]; flags = sd->syscall_args[4]; @@ -733,33 +733,33 @@ void wi_statfs(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { if (ht) { /* standard args */ int nested = sd->extra->nested; - int syscall_number = sd->syscall_number; - int ret_value; + int syscall_number = sd->syscall_number; + int ret_value; /* args */ - syscall_arg_t bufaddr = sd->syscall_args[1]; + syscall_arg_t bufaddr = sd->syscall_args[1]; /* local bufs */ struct statfs *buf; int sfd = -1; - void *private = NULL; + void *private = NULL; /* fetch args */ - switch (syscall_number) { + switch (syscall_number) { case __NR_statfs: break; case __NR_fstatfs: sfd = sd->syscall_args[0]; sfd = (vu_fd_get_sfd(sfd, &private, nested)); - break; + break; } vu_alloc_local_arg(bufaddr, buf, sizeof(*buf), nested); - /* call */ - sd->action = SKIPIT; - ret_value = service_syscall(ht, __VU_statfs)(sd->extra->mpath, buf, sfd, private); - if (ret_value < 0) { + /* call */ + sd->action = SKIPIT; + ret_value = service_syscall(ht, __VU_statfs)(sd->extra->mpath, buf, sfd, private); + if (ret_value < 0) { sd->ret_value = -errno; - return; - } - /* store results */ - vu_poke_arg(bufaddr, buf, sizeof(*buf), nested); - sd->ret_value = ret_value; - } + return; + } + /* store results */ + vu_poke_arg(bufaddr, buf, sizeof(*buf), nested); + sd->ret_value = ret_value; + } } diff --git a/umvu/src/vu_wrap_ioctl.c b/umvu/src/vu_wrap_ioctl.c index 5bc0c79..dc6bcc9 100644 --- a/umvu/src/vu_wrap_ioctl.c +++ b/umvu/src/vu_wrap_ioctl.c @@ -67,7 +67,7 @@ void wi_ioctl(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } sfd = vu_fd_get_sfd(fd, &private, nested); /* module's ioctl returns the encoding of size and direction of the parameter i - if fd == -1 */ + if fd == -1 */ /* modern ioctls have already size and direction encoded in their request argument, so if the modules' call fails, reqargs gets the value of request */ reqargs = service_syscall(ht, __VU_ioctl)(-1, request, NULL, addr, private); diff --git a/umvu/src/vu_wrap_poll.c b/umvu/src/vu_wrap_poll.c index 0a5a68e..1477c18 100644 --- a/umvu/src/vu_wrap_poll.c +++ b/umvu/src/vu_wrap_poll.c @@ -61,11 +61,11 @@ struct epoll_tab_elem { int fd; int wepfd; - struct vuht_entry_t *ht; - int sfd; - void *private; - struct epoll_event event; - struct epoll_tab_elem *next; + struct vuht_entry_t *ht; + int sfd; + void *private; + struct epoll_event event; + struct epoll_tab_elem *next; }; struct epoll_tab { @@ -88,12 +88,12 @@ static struct epoll_tab epoll_tab_init(void) { } static struct epoll_tab_elem *epoll_tab_search(struct epoll_tab tab, int fd) { - struct epoll_tab_elem *scan; - for (scan = tab.head; scan != NULL; scan = scan->next) { - if (scan->fd == fd) - return scan; - } - return NULL; + struct epoll_tab_elem *scan; + for (scan = tab.head; scan != NULL; scan = scan->next) { + if (scan->fd == fd) + return scan; + } + return NULL; } static inline struct epoll_tab_elem *epoll_tab_head(struct epoll_tab tab) { @@ -101,26 +101,26 @@ static inline struct epoll_tab_elem *epoll_tab_head(struct epoll_tab tab) { } static void epoll_tab_del(struct epoll_tab *tab, int fd) { - struct epoll_tab_elem **scan; - for (scan = &tab->head; *scan != NULL; scan = &((*scan)->next)) { - struct epoll_tab_elem *this = *scan; - if (this->fd == fd) { - *scan = this->next; - free(this); - return; - } - } + struct epoll_tab_elem **scan; + for (scan = &tab->head; *scan != NULL; scan = &((*scan)->next)) { + struct epoll_tab_elem *this = *scan; + if (this->fd == fd) { + *scan = this->next; + free(this); + return; + } + } } static inline struct epoll_tab_elem *epoll_tab_alloc(void) { - struct epoll_tab_elem *new = malloc(sizeof(struct epoll_tab_elem)); - fatal(new); + struct epoll_tab_elem *new = malloc(sizeof(struct epoll_tab_elem)); + fatal(new); return new; } static void epoll_tab_add(struct epoll_tab *tab, struct epoll_tab_elem *new) { - new->next = tab->head; - tab->head = new; + new->next = tab->head; + tab->head = new; } static void epoll_tab_destroy(struct epoll_tab *tab) { @@ -136,17 +136,17 @@ static struct epoll_info *epoll_info_create(int nested) { struct epoll_info *info = malloc(sizeof(struct epoll_info)); fatal(info); pthread_mutex_init(&info->mutex, NULL); - info->nested = nested; - info->tab = epoll_tab_init(); - return info; + info->nested = nested; + info->tab = epoll_tab_init(); + return info; } static void epoll_info_lock(struct epoll_info *info) { - pthread_mutex_lock(&info->mutex); + pthread_mutex_lock(&info->mutex); } static void epoll_info_unlock(struct epoll_info *info) { - pthread_mutex_unlock(&info->mutex); + pthread_mutex_unlock(&info->mutex); } static void epoll_info_destroy(struct epoll_info *info) { @@ -160,14 +160,14 @@ static void epoll_info_destroy(struct epoll_info *info) { /* common wait code */ static void vu_poll_wait_thread(struct syscall_descriptor_t *sd, int epfd) { - if ((sd->waiting_pid = r_fork()) == 0) { - struct pollfd pfd = {epfd, POLLIN, 0}; - //printk("epoll_thread... %d\n", epfd); - //int ret_value = - r_poll(&pfd, 1, -1); - //printk("epoll_thread %d %d\n", ret_value, errno); - r_exit(1); - } + if ((sd->waiting_pid = r_fork()) == 0) { + struct pollfd pfd = {epfd, POLLIN, 0}; + //printk("epoll_thread... %d\n", epfd); + //int ret_value = + r_poll(&pfd, 1, -1); + //printk("epoll_thread %d %d\n", ret_value, errno); + r_exit(1); + } } /* EPOLL: @@ -200,35 +200,35 @@ void wi_epoll_create1(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) * to its internal epoll fd. */ void wo_epoll_create1(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { int nested = sd->extra->nested; - int fd = sd->orig_ret_value; - if (fd >= 0) { + int fd = sd->orig_ret_value; + if (fd >= 0) { /* standard args */ int syscall_number = sd->syscall_number; - /* args */ - int flags; - int epfd; - struct vu_fnode_t *fnode; - struct epoll_info *info = epoll_info_create(nested); + /* args */ + int flags; + int epfd; + struct vu_fnode_t *fnode; + struct epoll_info *info = epoll_info_create(nested); /* fetch args */ - switch (syscall_number) { + switch (syscall_number) { default: - case __NR_epoll_create: - flags = 0; - break; - case __NR_epoll_create1: - flags = sd->syscall_args[0]; - break; - } - epfd = r_epoll_create1(EPOLL_CLOEXEC); - sd->extra->statbuf.st_mode = (sd->extra->statbuf.st_mode & ~S_IFMT) | S_IFEPOLL; - sd->extra->statbuf.st_dev = 0; - sd->extra->statbuf.st_ino = epfd; + case __NR_epoll_create: + flags = 0; + break; + case __NR_epoll_create1: + flags = sd->syscall_args[0]; + break; + } + epfd = r_epoll_create1(EPOLL_CLOEXEC); + sd->extra->statbuf.st_mode = (sd->extra->statbuf.st_mode & ~S_IFMT) | S_IFEPOLL; + sd->extra->statbuf.st_dev = 0; + sd->extra->statbuf.st_ino = epfd; //printk("wo_epoll_create1 %d %d %p\n", fd, epfd, info); - /* use the file table to map the user level fd to the (real) epollfd for modules */ - fnode = vu_fnode_create(NULL, NULL, &sd->extra->statbuf, 0, epfd, info); - vu_fd_set_fnode(fd, nested, fnode, (flags & EPOLL_CLOEXEC) ? FD_CLOEXEC : 0); - } - sd->ret_value = sd->orig_ret_value; + /* use the file table to map the user level fd to the (real) epollfd for modules */ + fnode = vu_fnode_create(NULL, NULL, &sd->extra->statbuf, 0, epfd, info); + vu_fd_set_fnode(fd, nested, fnode, (flags & EPOLL_CLOEXEC) ? FD_CLOEXEC : 0); + } + sd->ret_value = sd->orig_ret_value; } /* epoll_ctl_add/del/mod code is in three specific functions*/ @@ -314,8 +314,8 @@ static int epoll_ctl_del(struct vuht_entry_t *ht, struct syscall_descriptor_t *s void wi_epoll_ctl(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { if (ht) { int nested = sd->extra->nested; - int proc_epfd = sd->syscall_args[0]; - int op = sd->syscall_args[1]; + int proc_epfd = sd->syscall_args[0]; + int op = sd->syscall_args[1]; int fd = sd->syscall_args[2]; int mode = vu_fd_get_mode(proc_epfd, nested); //printk("wi_epoll_ctl %d %p epfd %d, fd %d\n", sd->extra->nested, ht, proc_epfd, fd); @@ -339,7 +339,7 @@ void wi_epoll_ctl(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { struct epoll_info *info; int epfd = vu_fd_get_sfd(proc_epfd, (void **) &info, nested); void *private = NULL; - int sfd = vu_fd_get_sfd(fd, &private, nested); + int sfd = vu_fd_get_sfd(fd, &private, nested); epoll_info_lock(info); switch (op) { case EPOLL_CTL_ADD: @@ -360,8 +360,8 @@ void wi_epoll_ctl(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } static int epoll_close_upcall(struct vuht_entry_t *ht, int epfd, void *private) { - struct epoll_info *info = private; - epoll_info_lock(info); + struct epoll_info *info = private; + epoll_info_lock(info); struct epoll_tab_elem *head; //printk("epoll_close_upcall %d %p\n", epfd, info); @@ -372,17 +372,17 @@ static int epoll_close_upcall(struct vuht_entry_t *ht, int epfd, void *private) r_close(head->wepfd); epoll_tab_del(&info->tab, head->fd); } - epoll_info_unlock(info); - epoll_info_destroy(info); - r_close(epfd); - return 0; + epoll_info_unlock(info); + epoll_info_destroy(info); + r_close(epfd); + return 0; } void wi_epoll_wait(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { int nested = sd->extra->nested; int pepfd = sd->syscall_args[0]; struct epoll_info *info; - __attribute__((unused)) int epfd = vu_fd_get_sfd(pepfd, (void **) &info, nested); + __attribute__((unused)) int epfd = vu_fd_get_sfd(pepfd, (void **) &info, nested); //printk("wi_epoll_wait n%d %d %p %p\n", nested, epfd, info, epoll_tab_head(info->tab)); /* if there are already pending events do not stop and skip to the wo */ if (epoll_tab_head(info->tab) != NULL) @@ -394,22 +394,22 @@ void wi_epoll_wait(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { * the epoll file descriptor (the sfd corresponding to the user's fd) */ void wd_epoll_wait(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { int pepfd = sd->syscall_args[0]; - struct epoll_info *info; - int epfd = vu_fd_get_sfd(pepfd, (void **) &info, VU_NOT_NESTED); + struct epoll_info *info; + int epfd = vu_fd_get_sfd(pepfd, (void **) &info, VU_NOT_NESTED); vu_poll_wait_thread(sd, epfd); } void wo_epoll_wait(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { int nested = sd->extra->nested; int pepfd = sd->syscall_args[0]; - struct epoll_info *info; - int epfd = vu_fd_get_sfd(pepfd, (void **) &info, nested); + struct epoll_info *info; + int epfd = vu_fd_get_sfd(pepfd, (void **) &info, nested); int orig_ret_value = sd->orig_ret_value; - /* args */ - uintptr_t eventaddr = sd->syscall_args[1]; - struct epoll_event *events; - int maxevents = sd->syscall_args[2]; - //printk("wo_epoll_wait %d %d\n", maxevents, orig_ret_value); + /* args */ + uintptr_t eventaddr = sd->syscall_args[1]; + struct epoll_event *events; + int maxevents = sd->syscall_args[2]; + //printk("wo_epoll_wait %d %d\n", maxevents, orig_ret_value); /* there are user events or the watchdog terminated and then the process got a PTRACE_INTERRUPT */ if(orig_ret_value >= 0 || orig_ret_value == -EINTR) { int ret_value = orig_ret_value; @@ -438,13 +438,13 @@ void wo_epoll_wait(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } epoll_info_unlock(info); if (epoll_ret_value > 0) { - ret_value += epoll_ret_value; + ret_value += epoll_ret_value; /* update the struct epoll_event (array) argument */ - vu_poke_arg(eventaddr, events, ret_value * sizeof(struct epoll_event), nested); - sd->ret_value = ret_value; - } else - sd->ret_value = orig_ret_value; - vu_free_arg(events, nested); + vu_poke_arg(eventaddr, events, ret_value * sizeof(struct epoll_event), nested); + sd->ret_value = ret_value; + } else + sd->ret_value = orig_ret_value; + vu_free_arg(events, nested); } } else sd->ret_value = orig_ret_value; @@ -452,9 +452,9 @@ void wo_epoll_wait(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { /* management of poll/ppoll */ struct poll_inout { - int epfd; - int nvirt; - struct epoll_tab tab; + int epfd; + int nvirt; + struct epoll_tab tab; int orig_fd[]; }; @@ -468,7 +468,7 @@ void wi_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { sd->action = SKIPIT; return; } - if (!nested) { + if (!nested) { struct pollfd *fds; struct epoll_tab tab = epoll_tab_init(); int i; @@ -482,30 +482,30 @@ void wi_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { /* merge all the pollfd args referring to the same virtual file descriptor */ if ((elem = epoll_tab_search(tab, fd)) == NULL) { void *private = NULL; - int sfd = vu_fd_get_sfd(fd, &private, nested); - elem = epoll_tab_alloc(); - elem->fd = fd; - elem->wepfd = -1; - elem->ht = fd_ht; - elem->sfd = sfd; - elem->private = private; - elem->event.events = 0; - elem->event.data.ptr = elem; - epoll_tab_add(&tab, elem); - } + int sfd = vu_fd_get_sfd(fd, &private, nested); + elem = epoll_tab_alloc(); + elem->fd = fd; + elem->wepfd = -1; + elem->ht = fd_ht; + elem->sfd = sfd; + elem->private = private; + elem->event.events = 0; + elem->event.data.ptr = elem; + epoll_tab_add(&tab, elem); + } elem->event.events |= fds[i].events; } } /* if there are virtual file descriptors */ if (epoll_tab_head(tab) != NULL) { - struct poll_inout *pollio = malloc(sizeof(struct poll_inout) + + struct poll_inout *pollio = malloc(sizeof(struct poll_inout) + nfds * sizeof(int)); struct epoll_tab_elem *scan; fatal(pollio); /* create an epoll fd */ - pollio->epfd = r_epoll_create1(EPOLL_CLOEXEC); - pollio->nvirt = 0; - pollio->tab = tab; + pollio->epfd = r_epoll_create1(EPOLL_CLOEXEC); + pollio->nvirt = 0; + pollio->tab = tab; /* save the original file descriptors */ for (i = 0; i < nfds; i++) { int fd = fds[i].fd; @@ -523,20 +523,20 @@ void wi_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { VU_HTWRAP(scan->ht, service_syscall(scan->ht, __VU_epoll_ctl) (pollio->epfd, EPOLL_CTL_ADD, scan->sfd, &scan->event, scan->private)); // XXX error mgmt? - } + } sd->inout = pollio; - sd->action = DOIT_CB_AFTER; + sd->action = DOIT_CB_AFTER; /* store the modified struct pollfd array */ - vu_poke_arg(fdsaddr, fds, nfds * sizeof(struct pollfd), nested); - } - vu_free_arg(fds, nested); - } + vu_poke_arg(fdsaddr, fds, nfds * sizeof(struct pollfd), nested); + } + vu_free_arg(fds, nested); + } } /* Blocking syscall: start a "waiting process" as explained for wd_epoll_wait here above */ void wd_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { - struct poll_inout *pollio = sd->inout; - vu_poll_wait_thread(sd, pollio->epfd); + struct poll_inout *pollio = sd->inout; + vu_poll_wait_thread(sd, pollio->epfd); } static inline int poll_add_events(int nfds, struct pollfd *fds, int fd, uint32_t events) { @@ -555,12 +555,12 @@ static inline int poll_add_events(int nfds, struct pollfd *fds, int fd, uint32_t void wo_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { struct poll_inout *pollio = sd->inout; - uintptr_t fdsaddr = sd->syscall_args[0]; - int nfds = sd->syscall_args[1]; - struct pollfd *fds; - int orig_ret_value = sd->orig_ret_value; - struct epoll_tab_elem *scan; - vu_alloc_peek_arg(fdsaddr, fds, nfds * sizeof(struct pollfd), VU_NOT_NESTED); + uintptr_t fdsaddr = sd->syscall_args[0]; + int nfds = sd->syscall_args[1]; + struct pollfd *fds; + int orig_ret_value = sd->orig_ret_value; + struct epoll_tab_elem *scan; + vu_alloc_peek_arg(fdsaddr, fds, nfds * sizeof(struct pollfd), VU_NOT_NESTED); int i; /* restore file descriptors */ for (i = 0; i < nfds; i++) { @@ -571,7 +571,7 @@ void wo_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } /* the user level poll terminated first: events on real fds only */ if (sd->waiting_pid != 0) - sd->ret_value = orig_ret_value; + sd->ret_value = orig_ret_value; else { /* EINTR/ERESTARTNOHAND are not error for us, just the watchdog terminated */ if (orig_ret_value == -EINTR || orig_ret_value == -ERESTARTNOHAND || @@ -588,9 +588,9 @@ void wo_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { scan = eventv[i].data.ptr; orig_ret_value += poll_add_events(nfds, fds, scan->fd, eventv[i].events); } - } + } sd->ret_value = orig_ret_value; - } + } /* de-register the epoll requests for modules */ for (scan = epoll_tab_head(pollio->tab); scan != NULL; scan = scan->next) { VU_HTWRAP(scan->ht, @@ -598,10 +598,10 @@ void wo_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { (pollio->epfd, EPOLL_CTL_DEL, scan->sfd, NULL, scan->private)); // XXX error mgmt? } epoll_tab_destroy(&pollio->tab); - r_close(pollio->epfd); + r_close(pollio->epfd); vu_poke_arg(fdsaddr, fds, nfds * sizeof(struct pollfd), VU_NOT_NESTED); vu_free_arg(fds, VU_NOT_NESTED); - xfree(pollio); + xfree(pollio); } /* management of select pselect */ @@ -614,7 +614,7 @@ void wo_poll(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { #define EPOLL_SELECT_SET (EPOLLIN | EPOLLOUT | EPOLLPRI) struct select_inout { - int epfd; + int epfd; int nvirt; struct epoll_tab tab; }; @@ -665,8 +665,8 @@ void wi_select(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { sd->action = SKIPIT; return; } - if (!nested) { - struct epoll_tab tab = epoll_tab_init(); + if (!nested) { + struct epoll_tab tab = epoll_tab_init(); int fd; fd_set readfds, writefds, exceptfds; peek_fd_set(readfdsaddr, &readfds, nfds, nested); @@ -696,24 +696,24 @@ void wi_select(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { } /* if select involves virtual file descriptors */ if (epoll_tab_head(tab) != NULL) { - struct select_inout *selectio = malloc(sizeof(struct select_inout)); - struct epoll_tab_elem *scan; - fatal(selectio); + struct select_inout *selectio = malloc(sizeof(struct select_inout)); + struct epoll_tab_elem *scan; + fatal(selectio); selectio->epfd = r_epoll_create1(EPOLL_CLOEXEC); - selectio->nvirt = 0; - selectio->tab = tab; + selectio->nvirt = 0; + selectio->tab = tab; for (scan = epoll_tab_head(tab); scan != NULL; scan = scan->next) { - selectio->nvirt++; + selectio->nvirt++; //printk("EPOLL_CTL_ADD %d %d %p\n", selectio->epfd, scan->sfd, scan->private); VU_HTWRAP(scan->ht, service_syscall(scan->ht, __VU_epoll_ctl) (selectio->epfd, EPOLL_CTL_ADD, scan->sfd, &scan->event, scan->private)); // XXX error mgmt? - } + } poke_fd_set(readfdsaddr, &readfds, nfds, nested); poke_fd_set(writefdsaddr, &writefds, nfds, nested); poke_fd_set(exceptfdsaddr, &exceptfds, nfds, nested); sd->inout = selectio; - sd->action = DOIT_CB_AFTER; + sd->action = DOIT_CB_AFTER; } } } @@ -721,15 +721,15 @@ void wi_select(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { /* Blocking syscall: start a "waiting process" as explained for wd_epoll_wait here above */ void wd_select(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { struct select_inout *selectio = sd->inout; - vu_poll_wait_thread(sd, selectio->epfd); + vu_poll_wait_thread(sd, selectio->epfd); } void wo_select(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { int nested = VU_NOT_NESTED; int orig_ret_value = sd->orig_ret_value; - struct select_inout *selectio = sd->inout; - struct epoll_tab_elem *scan; - //printk("wo_select\n"); + struct select_inout *selectio = sd->inout; + struct epoll_tab_elem *scan; + //printk("wo_select\n"); if (sd->waiting_pid != 0) // userland select terminated first, no virtual events sd->ret_value = orig_ret_value; else { @@ -757,7 +757,7 @@ void wo_select(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { for (scan = epoll_tab_head(selectio->tab); scan != NULL; scan = scan->next) events2fd_set(scan->fd, scan->event.events, EPOLL_SELECT_SET, &readfds, &writefds, &exceptfds); sd->ret_value = orig_ret_value; - } else { + } else { struct epoll_event events[selectio->nvirt]; int epollnfds, i; int ret_value = 0; diff --git a/umvu/src/vu_wrap_rw_multiplex.c b/umvu/src/vu_wrap_rw_multiplex.c index c85e1bf..749b1c2 100644 --- a/umvu/src/vu_wrap_rw_multiplex.c +++ b/umvu/src/vu_wrap_rw_multiplex.c @@ -47,7 +47,7 @@ static void wi_einval(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) } void multiplex_read_wrappers(mode_t mode, - wrapf_t wrapin, wrapf_t wrapduring, wrapf_t wrapout) { + wrapf_t wrapin, wrapf_t wrapduring, wrapf_t wrapout) { int modeindex = S_MODE2TYPE(mode); if (wrapin == NULL) @@ -67,7 +67,7 @@ void multiplex_read_wrappers(mode_t mode, } void multiplex_write_wrappers(mode_t mode, - wrapf_t wrapin, wrapf_t wrapduring, wrapf_t wrapout) { + wrapf_t wrapin, wrapf_t wrapduring, wrapf_t wrapout) { int modeindex = S_MODE2TYPE(mode); if (wrapin == NULL) diff --git a/umvu/src/vu_wrap_socket.c b/umvu/src/vu_wrap_socket.c index 408dbcf..c81bb94 100644 --- a/umvu/src/vu_wrap_socket.c +++ b/umvu/src/vu_wrap_socket.c @@ -232,7 +232,7 @@ void wi_accept4(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { if (!nested) { int fd = sd->syscall_args[0]; struct slowcall *sc = vu_slowcall_in(ht, fd, EPOLLIN, nested); - if (sc != NULL) { + if (sc != NULL) { sd->inout = sc; if (vu_slowcall_test(sc) <= 0) { /* BLOCKIT implies UMVU_CB_AFTER, the "during" wrapper waits for a connection request */ @@ -500,9 +500,9 @@ void _wo_sendmsg(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { void _wo_sendmmsg(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { #ifdef EXP_SEMDMMSG /* standard args */ - int nested = sd->extra->nested; - /* args */ - int fd = sd->syscall_args[0]; + int nested = sd->extra->nested; + /* args */ + int fd = sd->syscall_args[0]; uintptr_t msgvecaddr = sd->syscall_args[1]; int len = sd->syscall_args[2] & 1023; int flags = sd->syscall_args[3]; diff --git a/umvu/src/vu_wrap_time.c b/umvu/src/vu_wrap_time.c index 1e95aef..cdb4e9a 100644 --- a/umvu/src/vu_wrap_time.c +++ b/umvu/src/vu_wrap_time.c @@ -64,8 +64,8 @@ void wi_clock_gettime(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) /* timezone is obsolete. ignored here */ uintptr_t tvaddr = sd->syscall_args[0]; if (tvaddr == 0) - ret_value = -EFAULT; - else { + ret_value = -EFAULT; + else { struct timespec tp; struct timeval *tv; vu_alloc_local_arg(tvaddr, tv, sizeof(*tv), nested); @@ -73,7 +73,7 @@ void wi_clock_gettime(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) tv->tv_sec = tp.tv_sec; tv->tv_usec = tp.tv_nsec / 1000; if (ret_value == 0) - vu_poke_arg(tvaddr, tv, sizeof(*tv), nested); + vu_poke_arg(tvaddr, tv, sizeof(*tv), nested); else ret_value = -errno; } @@ -90,7 +90,7 @@ void wi_clock_gettime(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) time_t *now; vu_alloc_local_arg(timeaddr, now, sizeof(*now), nested); *now = tp.tv_sec; - vu_poke_arg(timeaddr, now, sizeof(*now), nested); + vu_poke_arg(timeaddr, now, sizeof(*now), nested); } } else ret_value = -errno; @@ -128,13 +128,13 @@ void wi_clock_settime(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) case __NR_settimeofday: { /* timezone is obsolete. ignored here */ - uintptr_t tvaddr = sd->syscall_args[0]; - if (tvaddr == 0) - ret_value = -EFAULT; - else { - struct timespec tp; - struct timeval *tv; - vu_alloc_peek_local_arg(tvaddr, tv, sizeof(*tv), nested); + uintptr_t tvaddr = sd->syscall_args[0]; + if (tvaddr == 0) + ret_value = -EFAULT; + else { + struct timespec tp; + struct timeval *tv; + vu_alloc_peek_local_arg(tvaddr, tv, sizeof(*tv), nested); tp.tv_sec = tv->tv_sec; tp.tv_nsec = tv->tv_usec * 1000; ret_value = service_syscall(ht, __VU_clock_settime)(CLOCK_REALTIME, &tp); @@ -153,8 +153,8 @@ void wi_clock_settime(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) } void wi_clock_getres(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { - int nested = sd->extra->nested; - if (ht) { + int nested = sd->extra->nested; + if (ht) { long ret_value; uintptr_t tpaddr = sd->syscall_args[1]; if (tpaddr == 0) diff --git a/umvu/src/vu_wrap_uid_gid.c b/umvu/src/vu_wrap_uid_gid.c index 2435609..f3f3d0d 100644 --- a/umvu/src/vu_wrap_uid_gid.c +++ b/umvu/src/vu_wrap_uid_gid.c @@ -346,61 +346,61 @@ void wo_setresfuid(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { euid = ruid = suid = fsuid = sd->syscall_args[0]; else euid = sd->syscall_args[0]; - break; - case __NR_setreuid: - ruid = sd->syscall_args[0]; - euid = sd->syscall_args[1]; - break; - case __NR_setresuid: - ruid = sd->syscall_args[0]; - euid = sd->syscall_args[1]; - suid = sd->syscall_args[2]; - break; - case __NR_setfsuid: - newfsuid = sd->syscall_args[0]; - if (euid == 0 || newfsuid == ruid || newfsuid == euid - || newfsuid == suid || newfsuid == fsuid) - fsuid = newfsuid; - break; + break; + case __NR_setreuid: + ruid = sd->syscall_args[0]; + euid = sd->syscall_args[1]; + break; + case __NR_setresuid: + ruid = sd->syscall_args[0]; + euid = sd->syscall_args[1]; + suid = sd->syscall_args[2]; + break; + case __NR_setfsuid: + newfsuid = sd->syscall_args[0]; + if (euid == 0 || newfsuid == ruid || newfsuid == euid + || newfsuid == suid || newfsuid == fsuid) + fsuid = newfsuid; + break; } vu_uidgid_setresfuid(ruid, euid, suid, fsuid); } } void wo_setresfgid(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { - sd->ret_value = sd->orig_ret_value; - if (sd->ret_value == 0) { + sd->ret_value = sd->orig_ret_value; + if (sd->ret_value == 0) { /* if the real system call succeeded, update vu_uidgid */ int syscall_number = sd->syscall_number; uid_t euid; gid_t rgid, egid, sgid, fsgid, newfsgid; vu_uidgid_getresfuid(NULL, &euid, NULL, NULL); vu_uidgid_getresfgid(&rgid, &egid, &sgid, &fsgid); - switch (syscall_number) { - case __NR_setgid: - if (euid == 0) - egid = rgid = sgid = fsgid = sd->syscall_args[0]; - else - egid = sd->syscall_args[0]; - break; - case __NR_setregid: - rgid = sd->syscall_args[0]; - egid = sd->syscall_args[1]; - break; - case __NR_setresgid: - rgid = sd->syscall_args[0]; - egid = sd->syscall_args[1]; - sgid = sd->syscall_args[2]; - break; - case __NR_setfsgid: - newfsgid = sd->syscall_args[0]; - if (egid == 0 || newfsgid == rgid || newfsgid == egid - || newfsgid == sgid || newfsgid == fsgid) - fsgid = newfsgid; - break; - } - vu_uidgid_setresfgid(rgid, egid, sgid, fsgid); - } + switch (syscall_number) { + case __NR_setgid: + if (euid == 0) + egid = rgid = sgid = fsgid = sd->syscall_args[0]; + else + egid = sd->syscall_args[0]; + break; + case __NR_setregid: + rgid = sd->syscall_args[0]; + egid = sd->syscall_args[1]; + break; + case __NR_setresgid: + rgid = sd->syscall_args[0]; + egid = sd->syscall_args[1]; + sgid = sd->syscall_args[2]; + break; + case __NR_setfsgid: + newfsgid = sd->syscall_args[0]; + if (egid == 0 || newfsgid == rgid || newfsgid == egid + || newfsgid == sgid || newfsgid == fsgid) + fsgid = newfsgid; + break; + } + vu_uidgid_setresfgid(rgid, egid, sgid, fsgid); + } } void wi_setgroups(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { @@ -431,9 +431,9 @@ void wo_setgroups(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { if (sd->ret_value == 0) { /* if the real system call succeeded, update vu_uidgid */ int size = sd->syscall_args[0]; - uintptr_t listaddr = sd->syscall_args[1]; - gid_t *list; - vu_alloc_peek_arg(listaddr, list, size * sizeof(gid_t), VU_NOT_NESTED); + uintptr_t listaddr = sd->syscall_args[1]; + gid_t *list; + vu_alloc_peek_arg(listaddr, list, size * sizeof(gid_t), VU_NOT_NESTED); vu_uidgid_setgroups(size, list); vu_free_arg(list, VU_NOT_NESTED); } diff --git a/vudev/vudev.c b/vudev/vudev.c index 47ad590..209fcc6 100644 --- a/vudev/vudev.c +++ b/vudev/vudev.c @@ -123,33 +123,33 @@ int vu_vudev_close(int fd, void *fdprivate) { #if (VUDEV_VUMODULE_FLAGS & VU_USE_PRW) ssize_t vu_vudev_read(int fd, void *buf, size_t count, void *fdprivate) { - struct vudevfd_t *vudevfd = fdprivate; - struct vudev_t *vudev = vudevfd->vudev; - ssize_t retval; - printkdebug(D,"READ %d %p", fd, vudevfd); - if((vudevfd->flags & O_WRONLY) != 0) { - errno = EBADF; - return -1; - } - pthread_mutex_lock(&(vudev->mutex)); + struct vudevfd_t *vudevfd = fdprivate; + struct vudev_t *vudev = vudevfd->vudev; + ssize_t retval; + printkdebug(D,"READ %d %p", fd, vudevfd); + if((vudevfd->flags & O_WRONLY) != 0) { + errno = EBADF; + return -1; + } + pthread_mutex_lock(&(vudev->mutex)); retval = vudev->devops->read(fd, buf, count, vudevfd); - pthread_mutex_unlock(&(vudev->mutex)); - return retval; + pthread_mutex_unlock(&(vudev->mutex)); + return retval; } ssize_t vu_vudev_write(int fd, const void *buf, size_t count, void *fdprivate) { - struct vudevfd_t *vudevfd = fdprivate; - struct vudev_t *vudev = vudevfd->vudev; - ssize_t retval; - printkdebug(D,"WRITE %d %p", fd, vudevfd); - if((vudevfd->flags & O_RDONLY) != 0) { - errno = EBADF; - return -1; - } - pthread_mutex_lock(&(vudev->mutex)); + struct vudevfd_t *vudevfd = fdprivate; + struct vudev_t *vudev = vudevfd->vudev; + ssize_t retval; + printkdebug(D,"WRITE %d %p", fd, vudevfd); + if((vudevfd->flags & O_RDONLY) != 0) { + errno = EBADF; + return -1; + } + pthread_mutex_lock(&(vudev->mutex)); retval = vudev->devops->write(fd, buf, count, vudevfd); - pthread_mutex_unlock(&(vudev->mutex)); - return retval; + pthread_mutex_unlock(&(vudev->mutex)); + return retval; } #else ssize_t vu_vudev_read(int fd, void *buf, size_t count, void *fdprivate) { diff --git a/vudev_modules/vudevnull.c b/vudev_modules/vudevnull.c index cfbfce2..b533b49 100644 --- a/vudev_modules/vudevnull.c +++ b/vudev_modules/vudevnull.c @@ -26,29 +26,29 @@ #include static int null_open(const char *pathname, mode_t mode, struct vudevfd_t *vudevfd) { - printkdebug(D,"null_open [%s]", pathname); - return 0; + printkdebug(D,"null_open [%s]", pathname); + return 0; } static int null_close(int fd, struct vudevfd_t *vudevfd) { - printkdebug(D,"null_close", NULL); - return 0; + printkdebug(D,"null_close", NULL); + return 0; } static ssize_t null_read (int fd, void *buf, size_t count, struct vudevfd_t *vudevfd) { - printkdebug(D,"null_read: [%d]", count); - return 0; + printkdebug(D,"null_read: [%d]", count); + return 0; } static ssize_t null_write(int fd, const void *buf, size_t count, struct vudevfd_t *vudevfd) { - printkdebug(D,"null_write: [%d]", count); - return count; + printkdebug(D,"null_write: [%d]", count); + return count; } struct vudev_operations_t vudev_ops = { - .open = null_open, - .close = null_close, - .read = null_read, - .write= null_write, + .open = null_open, + .close = null_close, + .read = null_read, + .write= null_write, }; diff --git a/vudev_modules/vudevramdisk.c b/vudev_modules/vudevramdisk.c index daf378e..33334a8 100644 --- a/vudev_modules/vudevramdisk.c +++ b/vudev_modules/vudevramdisk.c @@ -43,10 +43,10 @@ #define RAMDISK_SIZE(ramdisk) (ramdisk->rd_size * STD_SECTORSIZE) #define GET_CYLINDERS(ramdisk) \ - ((ramdisk->rd_size + (ramdisk->geometry.heads*ramdisk->geometry.sectors) -1) / (ramdisk->geometry.heads*ramdisk->geometry.sectors)) + ((ramdisk->rd_size + (ramdisk->geometry.heads*ramdisk->geometry.sectors) -1) / (ramdisk->geometry.heads*ramdisk->geometry.sectors)) struct vuramdisk_t { - char flags; + char flags; char *diskdata; size_t rd_size; struct hd_geometry geometry; @@ -56,15 +56,15 @@ struct vuramdisk_t { /************************************UTILS*************************************/ static inline ssize_t _get_size(char unit, ssize_t size) { - switch (unit) { - case 'k': + switch (unit) { + case 'k': case 'K': size *= 1024 / STD_SECTORSIZE; return size; case 'm': case 'M': size *= 1024 * 1024 / STD_SECTORSIZE; return size; case 'g': case 'G': size *= 1024 * 1024 * 1024 / STD_SECTORSIZE; return size; - default: return size; - } + default: return size; + } } static inline ssize_t _get_strsize(char *size) { @@ -74,10 +74,10 @@ static inline ssize_t _get_strsize(char *size) { static void set_mount_options(const char *input, struct vuramdisk_t *ramdisk) { int tagc = stropt(input, NULL, NULL, 0); if(tagc > 1) { - char buf[strlen(input)+1]; - char *tags[tagc]; - char *args[tagc]; - stropt(input, tags, args, buf); + char buf[strlen(input)+1]; + char *tags[tagc]; + char *args[tagc]; + stropt(input, tags, args, buf); for (int i=0; tags[i] != NULL; i++) { switch(strcase(tags[i])) { case STRCASE(s,i,z,e): @@ -88,54 +88,54 @@ static void set_mount_options(const char *input, struct vuramdisk_t *ramdisk) { ramdisk->flags = MBR; break; } - } - } + } + } } static inline ssize_t _ck_size(struct vuramdisk_t *ramdisk, size_t count, off_t offset) { - if((size_t) offset >= RAMDISK_SIZE(ramdisk)) - return 0; - count = (offset + count <= RAMDISK_SIZE(ramdisk))? count: (RAMDISK_SIZE(ramdisk) - offset); - return count; + if((size_t) offset >= RAMDISK_SIZE(ramdisk)) + return 0; + count = (offset + count <= RAMDISK_SIZE(ramdisk))? count: (RAMDISK_SIZE(ramdisk) - offset); + return count; } /******************************************************************************/ /***********************************SYSCALL************************************/ int vuramdisk_open(const char *pathname, mode_t mode, struct vudevfd_t *vudevfd) { - return 0; + return 0; } int vuramdisk_close(int fd, struct vudevfd_t *vudevfd) { - return 0; + return 0; } ssize_t vuramdisk_pread(int fd, void *buf, size_t count, off_t offset, struct vudevfd_t *vudevfd) { struct vuramdisk_t *ramdisk = vudev_get_private_data(vudevfd->vudev); count = _ck_size(ramdisk, count, offset); - memcpy(buf, (ramdisk->diskdata + offset), count); + memcpy(buf, (ramdisk->diskdata + offset), count); return count; } ssize_t vuramdisk_pwrite(int fd, const void *buf, size_t count, off_t offset, struct vudevfd_t *vudevfd) { struct vuramdisk_t *ramdisk = vudev_get_private_data(vudevfd->vudev); - if(ramdisk->flags & READONLY) { - errno = EBADF; + if(ramdisk->flags & READONLY) { + errno = EBADF; return -1; - } + } count = _ck_size(ramdisk, count, offset); - memcpy((ramdisk->diskdata + offset), buf, count); - return count; + memcpy((ramdisk->diskdata + offset), buf, count); + return count; } off_t vuramdisk_lseek(int fd, off_t offset, int whence, struct vudevfd_t *vudevfd) { struct vuramdisk_t *ramdisk = vudev_get_private_data(vudevfd->vudev); - off_t ret_value; + off_t ret_value; switch (whence) { case SEEK_SET: ret_value = offset; break; case SEEK_CUR: ret_value = vudevfd->offset + offset; break; case SEEK_END: ret_value = RAMDISK_SIZE(ramdisk) + offset; break; - default: errno = EINVAL; + default: errno = EINVAL; ret_value = (off_t) -1; break; } @@ -187,7 +187,7 @@ void *vuramdisk_init(const char *source, unsigned long flags, const char *args, if (ramdisk->rd_size == (unsigned int) ramdisk->rd_size) { /* 32 */ ramdisk->geometry.heads = 16; ramdisk->geometry.sectors = 16; - } else { /* 64 */ + } else { /* 64 */ ramdisk->geometry.heads = 128; ramdisk->geometry.sectors = 128; } @@ -197,28 +197,28 @@ void *vuramdisk_init(const char *source, unsigned long flags, const char *args, free(ramdisk); errno = ENOMEM; return NULL; - } + } vudev_set_devtype(vudev, S_IFBLK); return ramdisk; } int vuramdisk_fini(void *private_data) { - struct vuramdisk_t *ramdisk = private_data; + struct vuramdisk_t *ramdisk = private_data; if (ramdisk) { free(ramdisk->diskdata); free(ramdisk); - private_data = NULL; + private_data = NULL; } return 0; } struct vudev_operations_t vudev_ops = { - .open = vuramdisk_open, - .close = vuramdisk_close, + .open = vuramdisk_open, + .close = vuramdisk_close, .pread = vuramdisk_pread, .pwrite = vuramdisk_pwrite, - .lseek = vuramdisk_lseek, - .ioctl = vuramdisk_ioctl, - .init = vuramdisk_init, - .fini = vuramdisk_fini, + .lseek = vuramdisk_lseek, + .ioctl = vuramdisk_ioctl, + .init = vuramdisk_init, + .fini = vuramdisk_fini, }; diff --git a/vudev_modules/vudevvdi.c b/vudev_modules/vudevvdi.c index d7a48d1..c90d52f 100644 --- a/vudev_modules/vudevvdi.c +++ b/vudev_modules/vudevvdi.c @@ -64,14 +64,14 @@ static int (*vboxdd_get_LCHS_geometry) (); struct vuvdi_t { int fd; void *disk; - size_t size; - unsigned long flags; + size_t size; + unsigned long flags; }; struct vuvdi_pdmmediageom_t { uint32_t cHeads; uint32_t cSectors; - uint32_t cCylinders; + uint32_t cCylinders; }; /******************************************************************************/ @@ -117,8 +117,8 @@ static int dlload_vboxdd(void) { vboxdd_get_LCHS_geometry = (int *) dlsym(vboxdd_hdl, "VDGetLCHSGeometry"); #pragma GCC diagnostic pop printkdebug(D, "%p %p %p %p %p %p %p %p", - vboxdd_create, vboxdd_open, vboxdd_close, vboxdd_read, - vboxdd_write, vboxdd_flush, vboxdd_get_size, vboxdd_get_LCHS_geometry); + vboxdd_create, vboxdd_open, vboxdd_close, vboxdd_read, + vboxdd_write, vboxdd_flush, vboxdd_get_size, vboxdd_get_LCHS_geometry); return ++vboxdd_count; } @@ -221,13 +221,13 @@ static inline size_t _wrap_count(size_t size, off_t *offset, size_t count) { int vuvdi_open(const char *pathname, mode_t mode, struct vudevfd_t *vudevfd) { struct vuvdi_t *vdi = vudev_get_private_data(vudevfd->vudev); - return vdi->fd; + return vdi->fd; } int vuvdi_close(int fd, struct vudevfd_t *vudevfd) { struct vuvdi_t *vdi = vudev_get_private_data(vudevfd->vudev); vboxdd_flush(vdi->disk); - return 0; + return 0; } ssize_t vuvdi_pread(int fd, void *buf, size_t count, off_t offset, struct vudevfd_t *vudevfd) { @@ -245,7 +245,7 @@ ssize_t vuvdi_pwrite(int fd, const void *buf, size_t count, off_t offset, struct } off_t vuvdi_lseek(int fd, off_t offset, int whence, struct vudevfd_t *vudevfd) { - off_t ret_value; + off_t ret_value; switch (whence) { case SEEK_SET: ret_value = offset; break; @@ -256,7 +256,7 @@ off_t vuvdi_lseek(int fd, off_t offset, int whence, struct vudevfd_t *vudevfd) { ret_value = vdi->size + offset; break; } - default: + default: errno = EINVAL; ret_value = (off_t) -1; break; @@ -308,8 +308,8 @@ int vuvdi_ioctl(int fd, unsigned long request, void *addr, struct vudevfd_t *vud } return 0; } else { - return -1; - } + return -1; + } } static void *vuvdi_init(const char *source, unsigned long flags, const char *args, struct vudev_t *vudev) { @@ -344,7 +344,7 @@ static void *vuvdi_init(const char *source, unsigned long flags, const char *arg } int vuvdi_fini(void *private_data) { - struct vuvdi_t *vdi = private_data; + struct vuvdi_t *vdi = private_data; if(vdi) { vboxdd_close(vdi->disk, 0); /* If true, delete the image from the host disk. */ free(vdi); @@ -355,12 +355,12 @@ int vuvdi_fini(void *private_data) { } struct vudev_operations_t vudev_ops = { - .open = vuvdi_open, - .close = vuvdi_close, + .open = vuvdi_open, + .close = vuvdi_close, .pread = vuvdi_pread, .pwrite = vuvdi_pwrite, - .lseek = vuvdi_lseek, - .ioctl = vuvdi_ioctl, - .init = vuvdi_init, - .fini = vuvdi_fini, + .lseek = vuvdi_lseek, + .ioctl = vuvdi_ioctl, + .init = vuvdi_init, + .fini = vuvdi_fini, }; diff --git a/vudevfuse/devfuse.c b/vudevfuse/devfuse.c index aa53777..842f626 100644 --- a/vudevfuse/devfuse.c +++ b/vudevfuse/devfuse.c @@ -209,8 +209,8 @@ ssize_t vu_devfuse_read(int fd, void *buf, size_t count, void *fdprivate) { struct fusereq *req = fusereq_dequeue(&fusemount->reqq); // printk("read req %p\n", req); if (req == NULL) { // umount-> EOF on dev - // the fuse library uses several threads (workers) - // ENODEV must be returned to *all* the pending read reqs + // the fuse library uses several threads (workers) + // ENODEV must be returned to *all* the pending read reqs sem_V(fusemount->sem); pthread_mutex_unlock(&(fusemount->mutex)); return errno = ENODEV, -1; diff --git a/vudevfuse/eventsem.h b/vudevfuse/eventsem.h index cbc833c..b8c44fb 100644 --- a/vudevfuse/eventsem.h +++ b/vudevfuse/eventsem.h @@ -4,7 +4,7 @@ #include static inline int sem_open(int init) { - return eventfd(init, EFD_SEMAPHORE | EFD_CLOEXEC); + return eventfd(init, EFD_SEMAPHORE | EFD_CLOEXEC); } static inline size_t sem_P(int fd) { diff --git a/vufs/vufsops.c b/vufs/vufsops.c index 95d6ed1..0592fa5 100644 --- a/vufs/vufsops.c +++ b/vufs/vufsops.c @@ -42,7 +42,7 @@ #define log_if_err(S, X) \ do { \ if ((X) < 0) \ - printkdebug(V, "ERR: " #S "errno:%d", errno); \ + printkdebug(V, "ERR: " #S "errno:%d", errno); \ } while (0) static void vufs_copyfile_stat(struct vufs_t *vufs, const char *path, diff --git a/vufuse/fuse_opt.c b/vufuse/fuse_opt.c index 7af9eea..8a70e32 100644 --- a/vufuse/fuse_opt.c +++ b/vufuse/fuse_opt.c @@ -1,10 +1,10 @@ /* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi +FUSE: Filesystem in Userspace +Copyright (C) 2001-2007 Miklos Szeredi - This program can be distributed under the terms of the GNU LGPLv2. - See the file COPYING.LIB -*/ +This program can be distributed under the terms of the GNU LGPLv2. +See the file COPYING.LIB + */ #include @@ -66,7 +66,7 @@ int fuse_opt_add_arg(struct fuse_args *args, const char *arg) } static int fuse_opt_insert_arg_common(struct fuse_args *args, int pos, - const char *arg) + const char *arg) { assert(pos <= args->argc); if (fuse_opt_add_arg(args, arg) == -1) @@ -75,7 +75,7 @@ static int fuse_opt_insert_arg_common(struct fuse_args *args, int pos, if (pos != args->argc - 1) { char *newarg = args->argv[args->argc - 1]; memmove(&args->argv[pos + 1], &args->argv[pos], - sizeof(char *) * (args->argc - pos - 1)); + sizeof(char *) * (args->argc - pos - 1)); args->argv[pos] = newarg; } return 0; @@ -87,7 +87,7 @@ int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg) } int fuse_opt_insert_arg_compat(struct fuse_args *args, int pos, - const char *arg); + const char *arg); int fuse_opt_insert_arg_compat(struct fuse_args *args, int pos, const char *arg) { return fuse_opt_insert_arg_common(args, pos, arg); @@ -134,7 +134,7 @@ static int add_opt(struct fuse_opt_context *ctx, const char *opt) } static int call_proc(struct fuse_opt_context *ctx, const char *arg, int key, - int iso) + int iso) { if (key == FUSE_OPT_KEY_DISCARD) return 0; @@ -172,7 +172,7 @@ static int match_template(const char *t, const char *arg, unsigned *sepp) } static const struct fuse_opt *find_opt(const struct fuse_opt *opt, - const char *arg, unsigned *sepp) + const char *arg, unsigned *sepp) { for (; opt && opt->templ; opt++) if (match_template(opt->templ, arg, sepp)) @@ -187,7 +187,7 @@ int fuse_opt_match(const struct fuse_opt *opts, const char *opt) } static int process_opt_param(void *var, const char *format, const char *param, - const char *arg) + const char *arg) { assert(format[0] == '%'); if (format[1] == 's') { @@ -206,8 +206,8 @@ static int process_opt_param(void *var, const char *format, const char *param, } static int process_opt(struct fuse_opt_context *ctx, - const struct fuse_opt *opt, unsigned sep, - const char *arg, int iso) + const struct fuse_opt *opt, unsigned sep, + const char *arg, int iso) { if (opt->offset == -1U) { if (call_proc(ctx, arg, opt->value, iso) == -1) @@ -219,7 +219,7 @@ static int process_opt(struct fuse_opt_context *ctx, if (opt->templ[sep] == '=') param ++; if (process_opt_param(var, opt->templ + sep + 1, - param, arg) == -1) + param, arg) == -1) return -1; } else *(int *)var = opt->value; @@ -228,8 +228,8 @@ static int process_opt(struct fuse_opt_context *ctx, } static int process_opt_sep_arg(struct fuse_opt_context *ctx, - const struct fuse_opt *opt, unsigned sep, - const char *arg, int iso) + const struct fuse_opt *opt, unsigned sep, + const char *arg, int iso) { int res; char *newarg; @@ -260,7 +260,7 @@ static int process_gopt(struct fuse_opt_context *ctx, const char *arg, int iso) int res; if (sep && opt->templ[sep] == ' ' && !arg[sep]) res = process_opt_sep_arg(ctx, opt, sep, arg, - iso); + iso); else res = process_opt(ctx, opt, sep, arg, iso); if (res == -1) @@ -319,7 +319,7 @@ static int process_one(struct fuse_opt_context *ctx, const char *arg) return -1; return process_option_group(ctx, - ctx->argv[ctx->argctr]); + ctx->argv[ctx->argctr]); } } else if (arg[1] == '-' && !arg[2]) { if (add_arg(ctx, arg) == -1) @@ -343,7 +343,7 @@ static int opt_parse(struct fuse_opt_context *ctx) if (ctx->opts) { if (fuse_opt_insert_arg(&ctx->outargs, 1, "-o") == -1 || - fuse_opt_insert_arg(&ctx->outargs, 2, ctx->opts) == -1) + fuse_opt_insert_arg(&ctx->outargs, 2, ctx->opts) == -1) return -1; } if (ctx->nonopt && ctx->nonopt == ctx->outargs.argc) { @@ -355,7 +355,7 @@ static int opt_parse(struct fuse_opt_context *ctx) } int fuse_opt_parse(struct fuse_args *args, void *data, - const struct fuse_opt opts[], fuse_opt_proc_t proc) + const struct fuse_opt opts[], fuse_opt_proc_t proc) { int res; struct fuse_opt_context ctx = { diff --git a/vufuse/vufuse.c b/vufuse/vufuse.c index 5abd084..fde7034 100644 --- a/vufuse/vufuse.c +++ b/vufuse/vufuse.c @@ -393,25 +393,25 @@ int fuse_loop_mt(struct fuse *f) /* other dummy functions. useless for vufuse */ struct fuse_session *fuse_get_session(struct fuse *f) { - return NULL; + return NULL; } int fuse_set_signal_handlers(struct fuse_session *se) { - return 0; + return 0; } void fuse_remove_signal_handlers(struct fuse_session *se) { } int fuse_daemonize(int foreground) { - return 0; + return 0; } int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint, int *multithreaded, int *foreground) { - *mountpoint = strdup(""); - *multithreaded = 0; - *foreground = 1; + *mountpoint = strdup(""); + *multithreaded = 0; + *foreground = 1; return 0; } diff --git a/vufuse/vufuse_default_ops.c b/vufuse/vufuse_default_ops.c index 42317be..d1a8131 100644 --- a/vufuse/vufuse_default_ops.c +++ b/vufuse/vufuse_default_ops.c @@ -242,14 +242,14 @@ static int vustd_lock (const char *path, struct fuse_file_info *fileinfo, int cm static int vustd_utimens(const char *path, const struct timespec tv[2]) { - printkdebug(F,"DEFAULT utimens %s\n", path); - return -ENOSYS; + printkdebug(F,"DEFAULT utimens %s\n", path); + return -ENOSYS; } static int vustd_bmap (const char *path, size_t blocksize, uint64_t *idx) { - printkdebug(F,"DEFAULT bmap %s\n", path); - return -ENOSYS; + printkdebug(F,"DEFAULT bmap %s\n", path); + return -ENOSYS; } struct fuse_operations vufuse_default_ops = { @@ -281,7 +281,7 @@ struct fuse_operations vufuse_default_ops = { .opendir = vustd_opendir, .releasedir = vustd_releasedir, .fsyncdir = vustd_fsyncdir, - + .init = NULL, .destroy = NULL, diff --git a/vufuse/vufuse_node.c b/vufuse/vufuse_node.c index baef025..a9fc139 100644 --- a/vufuse/vufuse_node.c +++ b/vufuse/vufuse_node.c @@ -29,11 +29,11 @@ #define NODE_HASH_MASK (NODE_HASH_SIZE-1) struct fuse_node { - char *path; - struct fuse *fuse; - long hashsum; - int open_count; - struct fuse_node **pprevhash,*nexthash; + char *path; + struct fuse *fuse; + long hashsum; + int open_count; + struct fuse_node **pprevhash,*nexthash; }; static pthread_mutex_t vufuse_node_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -45,20 +45,20 @@ static struct fuse_node *vufuse_node_head[NODE_HASH_SIZE]; static char *vufuse_node_hiddenpath_rename(struct fuse *fuse, char *oldpath) { - char *name; - static unsigned long hiddencount; + char *name; + static unsigned long hiddencount; char *last_slash = strrchr(oldpath, '/'); int last_slash_pos = (last_slash == NULL) ? 0 : (last_slash - oldpath); - if (asprintf(&name,"%*.*s/.fuse%0*lx%010lu", last_slash_pos, last_slash_pos, oldpath, - ADDRESS_LEN, (uintptr_t)fuse, hiddencount++) < 0) + if (asprintf(&name,"%*.*s/.fuse%0*lx%010lu", last_slash_pos, last_slash_pos, oldpath, + ADDRESS_LEN, (uintptr_t)fuse, hiddencount++) < 0) return oldpath; free(oldpath); - return name; + return name; } static inline int vufuse_node_hiddenpath_check(struct fuse *fuse, const char *path) { - char *last_slash = strrchr(path, '/'); + char *last_slash = strrchr(path, '/'); if (last_slash) { char check[HIDDEN_PREFIX_LEN + 1]; snprintf(check,HIDDEN_PREFIX_LEN + 1,"/.fuse%0*lx", ADDRESS_LEN, (uintptr_t) fuse); @@ -69,32 +69,32 @@ static inline int vufuse_node_hiddenpath_check(struct fuse *fuse, const char *pa static inline long vufuse_node_hash_sum(struct fuse *fuse, const char *path) { - long sum = (long) fuse; - while (*path != 0) { - sum ^= ((sum << 5) + (sum >> 2) + *path); - path++; - } - return sum; + long sum = (long) fuse; + while (*path != 0) { + sum ^= ((sum << 5) + (sum >> 2) + *path); + path++; + } + return sum; } static inline int vufuse_node_hash_mod(long sum) { - return sum & NODE_HASH_MASK; + return sum & NODE_HASH_MASK; } static inline struct fuse_node *vufuse_node_find(void *fuse, const char *path, - long hashsum, int hashkey) + long hashsum, int hashkey) { - struct fuse_node *scan=vufuse_node_head[hashkey]; - //printk("node_find %s\n",path); - while (scan != NULL) { - //printk("node_find_scan %s\n",path,scan->path); - if (scan->hashsum == hashsum && scan->fuse == fuse && - strcmp(scan->path, path) == 0) - return scan; - scan=scan->nexthash; - } - return NULL; + struct fuse_node *scan=vufuse_node_head[hashkey]; + //printk("node_find %s\n",path); + while (scan != NULL) { + //printk("node_find_scan %s\n",path,scan->path); + if (scan->hashsum == hashsum && scan->fuse == fuse && + strcmp(scan->path, path) == 0) + return scan; + scan=scan->nexthash; + } + return NULL; } char *vufuse_node_path(struct fuse_node *node) { @@ -103,24 +103,24 @@ char *vufuse_node_path(struct fuse_node *node) { struct fuse_node *vufuse_node_add(struct fuse *fuse, const char *path) { long hashsum = vufuse_node_hash_sum(fuse, path); - int hashkey = vufuse_node_hash_mod(hashsum); - struct fuse_node *new; + int hashkey = vufuse_node_hash_mod(hashsum); + struct fuse_node *new; pthread_mutex_lock(&vufuse_node_mutex); new = vufuse_node_find(fuse, path, hashsum, hashkey); if (new != NULL) new->open_count++; else { new = malloc(sizeof (struct fuse_node)); - if (new != NULL) { + if (new != NULL) { new->path = strdup(path); new->fuse = fuse; new->hashsum = hashsum; new->open_count = 1; if (vufuse_node_head[hashkey] != NULL) vufuse_node_head[hashkey]->pprevhash = &(new->nexthash); - new->nexthash = vufuse_node_head[hashkey]; - new->pprevhash = &(vufuse_node_head[hashkey]); - vufuse_node_head[hashkey] = new; + new->nexthash = vufuse_node_head[hashkey]; + new->pprevhash = &(vufuse_node_head[hashkey]); + vufuse_node_head[hashkey] = new; } } pthread_mutex_unlock(&vufuse_node_mutex); @@ -129,7 +129,7 @@ struct fuse_node *vufuse_node_add(struct fuse *fuse, const char *path) { char *vufuse_node_del(struct fuse_node *old) { char *ret_value = NULL; - pthread_mutex_lock(&vufuse_node_mutex); + pthread_mutex_lock(&vufuse_node_mutex); if (old) { old->open_count--; if (old->open_count <= 0) { @@ -143,18 +143,18 @@ char *vufuse_node_del(struct fuse_node *old) { free(old->path); } free(old); - } - } - pthread_mutex_unlock(&vufuse_node_mutex); + } + } + pthread_mutex_unlock(&vufuse_node_mutex); return ret_value; } char *vufuse_node_rename(struct fuse *fuse, const char *path, const char *newpath) { long hashsum = vufuse_node_hash_sum(fuse, path); - int hashkey = vufuse_node_hash_mod(hashsum); - struct fuse_node *this; - char *ret_value = NULL; - pthread_mutex_lock(&vufuse_node_mutex); + int hashkey = vufuse_node_hash_mod(hashsum); + struct fuse_node *this; + char *ret_value = NULL; + pthread_mutex_lock(&vufuse_node_mutex); this = vufuse_node_find(fuse, path, hashsum, hashkey); if (this != NULL) { *(this->pprevhash)=this->nexthash; @@ -175,6 +175,6 @@ char *vufuse_node_rename(struct fuse *fuse, const char *path, const char *newpat vufuse_node_head[hashkey] = this; ret_value = this->path; } - pthread_mutex_unlock(&vufuse_node_mutex); + pthread_mutex_unlock(&vufuse_node_mutex); return ret_value; } diff --git a/vufuse/vufuse_startmain.c b/vufuse/vufuse_startmain.c index ed8f77c..f9a87c6 100644 --- a/vufuse/vufuse_startmain.c +++ b/vufuse/vufuse_startmain.c @@ -34,27 +34,27 @@ MS_LAZYTIME) static int countflagoptions(unsigned long mountflags) { - int retval = 0; - int i; - for (i = 0; i < 32; i++) { - if ((mountflags & (1UL << i)) && (mountflag_strings[i])) - retval++; - } - return retval; + int retval = 0; + int i; + for (i = 0; i < 32; i++) { + if ((mountflags & (1UL << i)) && (mountflag_strings[i])) + retval++; + } + return retval; } static void addflagoptions(char **tags, char **args, unsigned long mountflags) { - int i; - int flagoptc; - for (i = 0, flagoptc = 0; i < 32; i++) { - if ((mountflags & (1UL << i)) && (mountflag_strings[i])) { - tags[flagoptc] = mountflag_strings[i]; - args[flagoptc] = NULL; - flagoptc++; - } - } - tags[flagoptc] = NULL; - args[flagoptc] = NULL; + int i; + int flagoptc; + for (i = 0, flagoptc = 0; i < 32; i++) { + if ((mountflags & (1UL << i)) && (mountflag_strings[i])) { + tags[flagoptc] = mountflag_strings[i]; + args[flagoptc] = NULL; + flagoptc++; + } + } + tags[flagoptc] = NULL; + args[flagoptc] = NULL; } int fusestartmain(struct main_params *mntp) { diff --git a/vufuse/vufuse_startmain.h b/vufuse/vufuse_startmain.h index d6039e5..c2f0745 100644 --- a/vufuse/vufuse_startmain.h +++ b/vufuse/vufuse_startmain.h @@ -2,13 +2,13 @@ #define VUFUSE_STARTMAIN_H struct main_params { - int (*pmain)(int argc, char **argv); - const char *filesystemtype; - const char *source; - const char *target; - unsigned long *pmountflags; - unsigned long *pfuseflags; - char *opts; + int (*pmain)(int argc, char **argv); + const char *filesystemtype; + const char *source; + const char *target; + unsigned long *pmountflags; + unsigned long *pfuseflags; + char *opts; }; int fusestartmain(struct main_params *mntp); diff --git a/vufuse/vufuseop.c b/vufuse/vufuseop.c index 13f50d8..5dc0e44 100644 --- a/vufuse/vufuseop.c +++ b/vufuse/vufuseop.c @@ -36,15 +36,15 @@ VU_PROTOTYPES(vufuse) #define FILEPATH(x) vufuse_node_path(x->node) -/*heuristics for file system which does not set st_ino */ -static inline unsigned long hash_inodeno (const char *s) { - unsigned long sum = 0; - while (*s) { - sum = sum ^ ((sum << 5) + (sum >> 2) + *s); - s++; - } - return sum; -} + /*heuristics for file system which does not set st_ino */ + static inline unsigned long hash_inodeno (const char *s) { + unsigned long sum = 0; + while (*s) { + sum = sum ^ ((sum << 5) + (sum >> 2) + *s); + s++; + } + return sum; + } /* (vufuse_get_filesize callers need to hold the mutex */ static off_t vufuse_get_filesize(char *pathname) { @@ -878,29 +878,29 @@ int vu_vufuse_rename (const char *target, const char *linkpath, int flags) { int vu_vufuse_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags, int fd, void *private) { int rv; - struct fuse_context fc, *ofc; + struct fuse_context fc, *ofc; ofc = fuse_push_context(&fc); if (fc.fuse->mountflags & MS_RDONLY) { - fuse_pop_context(ofc); - errno = EROFS; - return -1; - } - pthread_mutex_lock(&(fc.fuse->mutex)); + fuse_pop_context(ofc); + errno = EROFS; + return -1; + } + pthread_mutex_lock(&(fc.fuse->mutex)); rv = fc.fuse->fops.utimens(pathname, times); if (rv == -ENOSYS) { - struct utimbuf utimes = {times[0].tv_sec, times[1].tv_sec}; + struct utimbuf utimes = {times[0].tv_sec, times[1].tv_sec}; rv = fc.fuse->fops.utime(pathname, &utimes); } - fuse_pop_context(ofc); + fuse_pop_context(ofc); pthread_mutex_unlock(&(fc.fuse->mutex)); - printkdebug(F,"UTIME path:%s", pathname); + printkdebug(F,"UTIME path:%s", pathname); - if (rv < 0) { - errno = -rv; - return -1; - } else - return rv; + if (rv < 0) { + errno = -rv; + return -1; + } else + return rv; } diff --git a/vufuse_modules/vufusenull.c b/vufuse_modules/vufusenull.c index 8462c94..562944d 100644 --- a/vufuse_modules/vufusenull.c +++ b/vufuse_modules/vufusenull.c @@ -49,14 +49,14 @@ int op_getattr(const char *path, struct stat *stbuf){ if (strcmp(path, "/") == 0) { memset(stbuf, 0, sizeof(*stbuf)); stbuf->st_mode = 0755 | S_IFDIR; - stbuf->st_nlink = 2; - return 0; + stbuf->st_nlink = 2; + return 0; } else return -ENOENT; } int op_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){ filler(buf, ".", NULL, 0); - filler(buf, "..", NULL, 0); + filler(buf, "..", NULL, 0); return 0; } diff --git a/vufuse_modules/vufusereal.c b/vufuse_modules/vufusereal.c index cf6e021..66c884e 100644 --- a/vufuse_modules/vufusereal.c +++ b/vufuse_modules/vufusereal.c @@ -47,8 +47,8 @@ int fuse_reentrant_tag = 0; #define GETPATH(source, path) \ char path ## _fullpath [PATH_MAX]; \ - snprintf((path ## _fullpath), PATH_MAX, "%s%s", (strcmp(source,"/")) ? source : "", path); \ - path = path ## _fullpath +snprintf((path ## _fullpath), PATH_MAX, "%s%s", (strcmp(source,"/")) ? source : "", path); \ +path = path ## _fullpath #define RETURN(retvalue) return ((retvalue < 0) ? -errno : retvalue) @@ -372,61 +372,61 @@ static const struct fuse_operations real_ops = { static void usage(void) { - fprintf(stderr, - "usage: " PROGNAME " sourcepath mountpoint [options]\n" - "\n" - "general options:\n" - " -h --help print help\n" - " -V --version print version\n" - "\n"); + fprintf(stderr, + "usage: " PROGNAME " sourcepath mountpoint [options]\n" + "\n" + "general options:\n" + " -h --help print help\n" + " -V --version print version\n" + "\n"); } struct options { - const char *source; - const char *mountpoint; + const char *source; + const char *mountpoint; }; - static int + static int real_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { - struct options *options = data; - switch(key) { - case FUSE_OPT_KEY_OPT: - return 1; - case FUSE_OPT_KEY_NONOPT: - if (!options->source) { - options->source = arg; - return 0; - } else if(!options->mountpoint) { - options->mountpoint = arg; - return 1; - } else - return -1; - break; - case 'h': - usage(); - fuse_opt_add_arg(outargs, "-ho"); - fuse_main(outargs->argc, outargs->argv, &real_ops, NULL); - return -1; - - case 'V': - fprintf(stderr, PROGNAME "\n"); - fuse_opt_add_arg(outargs, "--version"); - fuse_main(outargs->argc, outargs->argv, &real_ops, NULL); - return -1; - - default: - return -1; - } + struct options *options = data; + switch(key) { + case FUSE_OPT_KEY_OPT: + return 1; + case FUSE_OPT_KEY_NONOPT: + if (!options->source) { + options->source = arg; + return 0; + } else if(!options->mountpoint) { + options->mountpoint = arg; + return 1; + } else + return -1; + break; + case 'h': + usage(); + fuse_opt_add_arg(outargs, "-ho"); + fuse_main(outargs->argc, outargs->argv, &real_ops, NULL); + return -1; + + case 'V': + fprintf(stderr, PROGNAME "\n"); + fuse_opt_add_arg(outargs, "--version"); + fuse_main(outargs->argc, outargs->argv, &real_ops, NULL); + return -1; + + default: + return -1; + } } static struct fuse_opt real_opts[] = { - FUSE_OPT_KEY("-V", 'V'), - FUSE_OPT_KEY("--version", 'V'), - FUSE_OPT_KEY("-h", 'h'), - FUSE_OPT_KEY("--help", 'h'), - FUSE_OPT_END + FUSE_OPT_KEY("-V", 'V'), + FUSE_OPT_KEY("--version", 'V'), + FUSE_OPT_KEY("-h", 'h'), + FUSE_OPT_KEY("--help", 'h'), + FUSE_OPT_END }; int main(int argc, char *argv[]) @@ -443,14 +443,14 @@ int main(int argc, char *argv[]) if (options.source == NULL || options.mountpoint == NULL) { usage(); goto returnerr; - } + } err = fuse_main(args.argc, args.argv, &real_ops, (void *) options.source); fuse_opt_free_args(&args); return err; returnerr: - fuse_opt_free_args(&args); - return -1; + fuse_opt_free_args(&args); + return -1; } diff --git a/vunet/vunet.c b/vunet/vunet.c index 454b782..4cf8656 100644 --- a/vunet/vunet.c +++ b/vunet/vunet.c @@ -35,8 +35,8 @@ VU_PROTOTYPES(vunet) }; struct vunet_default_t { - pthread_rwlock_t lock; - size_t count; + pthread_rwlock_t lock; + size_t count; struct vunet *defstack[AF_MAX + 1]; }; @@ -131,7 +131,7 @@ static int checksocket(uint8_t type, void *arg, int arglen, /* confirmation function for ioctl */ static int checkioctl(uint8_t type, void *arg, int arglen, - struct vuht_entry_t *ht) { + struct vuht_entry_t *ht) { unsigned long *request = arg; struct vunet *vunet = vuht_get_private_data(ht); struct vunet *defvunet = get_defstack(PF_NETLINK); @@ -186,8 +186,8 @@ int vu_vunet_lchown(const char *pathname, uid_t owner, gid_t group, int fd, void int vu_vunet_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event, void *fdprivate) { current_vnetfd = fdprivate; if (current_vnetfd->vunet->netops->epoll_ctl == NULL) - return errno = ENOSYS, -1; - else + return errno = ENOSYS, -1; + else return current_vnetfd->vunet->netops->epoll_ctl(epfd, op, fd, event); } @@ -291,27 +291,27 @@ ssize_t vu_vunet_sendto(int sockfd, const void *buf, size_t len, int flags, current_vnetfd = fdprivate; printkdebug(N, "sendto %p %d %p %d", current_vnetfd, sockfd, buf, len); if (current_vnetfd->vunet->netops->sendmsg == NULL) - return errno = ENOSYS, -1; - else { + return errno = ENOSYS, -1; + else { struct iovec iov[] = {{(void *) buf, len}}; struct msghdr msgh = {(void *) dest_addr, addrlen, iov, 1, msg_control, msg_controllen, 0}; - return current_vnetfd->vunet->netops->sendmsg(sockfd, &msgh, flags); + return current_vnetfd->vunet->netops->sendmsg(sockfd, &msgh, flags); } } ssize_t vu_vunet_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen, void *msg_control, size_t *msg_controllen, void *fdprivate) { - current_vnetfd = fdprivate; + current_vnetfd = fdprivate; printkdebug(N, "recvfrom %p %d %p %d", current_vnetfd, sockfd, buf, len); - if (current_vnetfd->vunet->netops->recvmsg == NULL) - return errno = ENOSYS, -1; - else { + if (current_vnetfd->vunet->netops->recvmsg == NULL) + return errno = ENOSYS, -1; + else { struct iovec iov[] = {{buf, len}}; struct msghdr msgh = {(void *) src_addr, *addrlen, iov, 1, msg_control, 0, 0}; if (msg_controllen != NULL) msgh.msg_controllen = *msg_controllen; - int retval = current_vnetfd->vunet->netops->recvmsg(sockfd, &msgh, flags); + int retval = current_vnetfd->vunet->netops->recvmsg(sockfd, &msgh, flags); if (retval >= 0) { if (addrlen != NULL) *addrlen = msgh.msg_namelen; @@ -376,19 +376,19 @@ int vu_vunet_ioctl(int sockfd, unsigned long request, void *buf, uintptr_t addr, int vu_vunet_close(int sockfd, void *fdprivate) { current_vnetfd = fdprivate; printkdebug(N, "close %p %d", current_vnetfd, sockfd); - if (current_vnetfd->vunet->netops->close == NULL) - return errno = ENOSYS, -1; - else - return current_vnetfd->vunet->netops->close(sockfd); + if (current_vnetfd->vunet->netops->close == NULL) + return errno = ENOSYS, -1; + else + return current_vnetfd->vunet->netops->close(sockfd); } int vu_vunet_fcntl(int sockfd, int cmd, long arg, void *fdprivate) { - current_vnetfd = fdprivate; - printkdebug(N, "fcntl %p %d", current_vnetfd, sockfd); - if (current_vnetfd->vunet->netops->fcntl == NULL) - return errno = ENOSYS, -1; - else - return current_vnetfd->vunet->netops->fcntl(sockfd, cmd, arg); + current_vnetfd = fdprivate; + printkdebug(N, "fcntl %p %d", current_vnetfd, sockfd); + if (current_vnetfd->vunet->netops->fcntl == NULL) + return errno = ENOSYS, -1; + else + return current_vnetfd->vunet->netops->fcntl(sockfd, cmd, arg); } int vu_vunet_mount(const char *source, const char *target, @@ -440,34 +440,34 @@ int vu_vunet_mount(const char *source, const char *target, /* XXX umount usage count (default defs) */ int vu_vunet_umount2(const char *target, int flags) { struct vuht_entry_t *ht = vu_mod_getht(); - struct vunet *vunet = vu_get_ht_private_data(); - int ret_value; + struct vunet *vunet = vu_get_ht_private_data(); + int ret_value; printkdebug(N, "umount2 \'%s\' %p", target, vunet); vuht_del(vunet->socket_ht, flags); if (vunet->ioctl_ht) vuht_del(vunet->ioctl_ht, flags); - if ((ret_value = vuht_del(ht, flags)) < 0) - return errno = -ret_value, -1; - return 0; + if ((ret_value = vuht_del(ht, flags)) < 0) + return errno = -ret_value, -1; + return 0; } void vu_vunet_cleanup(uint8_t type, void *arg, int arglen, struct vuht_entry_t *ht) { struct vunet *vunet = vuht_get_private_data(ht); printkdebug(N, "cleanup %p %d", vunet, type); - if (type == CHECKSOCKET) + if (type == CHECKSOCKET) vunet->socket_ht = NULL; - if (type == CHECKIOCTL) + if (type == CHECKIOCTL) vunet->ioctl_ht = NULL; - if (type == CHECKPATH) + if (type == CHECKPATH) vunet->path_ht = NULL; if (vunet->socket_ht == NULL && vunet->ioctl_ht == NULL && vunet->path_ht == NULL) { if (vunet->netops->fini != NULL) vunet->netops->fini(vunet->private_data); - free(vunet); - } + free(vunet); + } } static void vu_default_modify_lock(void) { @@ -484,17 +484,17 @@ static void vu_default_modify_lock(void) { pthread_rwlock_wrlock(&vunet_default->lock); if (vunet_default->count > 1) { struct vunet_default_t *new; - int i; - new = malloc(sizeof(struct vunet_default_t)); - pthread_rwlock_init(&new->lock, NULL); - new->count = 1; - vunet_default->count -= 1; - for (i = 0; i < AF_MAX + 1; i++) - new->defstack[i] = vunet_default->defstack[i]; + int i; + new = malloc(sizeof(struct vunet_default_t)); + pthread_rwlock_init(&new->lock, NULL); + new->count = 1; + vunet_default->count -= 1; + for (i = 0; i < AF_MAX + 1; i++) + new->defstack[i] = vunet_default->defstack[i]; pthread_rwlock_unlock(&vunet_default->lock); - vunet_default = new; + vunet_default = new; pthread_rwlock_wrlock(&vunet_default->lock); - } + } } static void vu_default_read_lock(void) { @@ -506,46 +506,46 @@ static void vu_default_unlock(void) { } static void *vunet_default_clone(void *arg) { - if (vunet_default != NULL) { - pthread_rwlock_wrlock(&vunet_default->lock); - vunet_default->count++; - pthread_rwlock_unlock(&vunet_default->lock); - return vunet_default; - } else - return NULL; + if (vunet_default != NULL) { + pthread_rwlock_wrlock(&vunet_default->lock); + vunet_default->count++; + pthread_rwlock_unlock(&vunet_default->lock); + return vunet_default; + } else + return NULL; } static void vunet_default_terminate(void) { - if (vunet_default != NULL) { - pthread_rwlock_wrlock(&vunet_default->lock); - vunet_default->count -= 1; - if (vunet_default->count == 0) { - struct vunet_default_t *old_vunet_default = vunet_default; - vunet_default = NULL; - pthread_rwlock_unlock(&old_vunet_default->lock); - pthread_rwlock_destroy(&old_vunet_default->lock); - free(old_vunet_default); - } else - pthread_rwlock_unlock(&vunet_default->lock); - } + if (vunet_default != NULL) { + pthread_rwlock_wrlock(&vunet_default->lock); + vunet_default->count -= 1; + if (vunet_default->count == 0) { + struct vunet_default_t *old_vunet_default = vunet_default; + vunet_default = NULL; + pthread_rwlock_unlock(&old_vunet_default->lock); + pthread_rwlock_destroy(&old_vunet_default->lock); + free(old_vunet_default); + } else + pthread_rwlock_unlock(&vunet_default->lock); + } } static void *vunet_tracer_upcall(mod_inheritance_state_t state, void *ioarg, void *arg) { - void *ret_value = NULL; - switch (state) { - case MOD_INH_CLONE: - ret_value = vunet_default_clone(arg); - break; - case MOD_INH_START: - vunet_default = ioarg; - break; - case MOD_INH_EXEC: - break; - case MOD_INH_TERMINATE: - vunet_default_terminate(); - break; - } - return ret_value; + void *ret_value = NULL; + switch (state) { + case MOD_INH_CLONE: + ret_value = vunet_default_clone(arg); + break; + case MOD_INH_START: + vunet_default = ioarg; + break; + case MOD_INH_EXEC: + break; + case MOD_INH_TERMINATE: + vunet_default_terminate(); + break; + } + return ret_value; } void *vu_vunet_init (void) { @@ -559,12 +559,12 @@ int vu_vunet_fini(void *private) { } __attribute__((constructor)) - static void init(void) { + static void init(void) { debug_set_name(N, "VUNET"); } __attribute__((destructor)) - static void fini(void) { + static void fini(void) { debug_set_name(N, ""); } diff --git a/vunet/vunet_ioctl.c b/vunet/vunet_ioctl.c index 2d8ee65..ce7addd 100644 --- a/vunet/vunet_ioctl.c +++ b/vunet/vunet_ioctl.c @@ -25,82 +25,82 @@ long vunet_ioctl_parms(unsigned long request) { switch (request) { case FIONREAD: - return _IOW(' ', 0, int); - case FIONBIO: - return _IOR(' ', 0, int); - case SIOCGIFCONF: - return _IOWR(' ', 0, struct ifconf); + return _IOW(' ', 0, int); + case FIONBIO: + return _IOR(' ', 0, int); + case SIOCGIFCONF: + return _IOWR(' ', 0, struct ifconf); #ifdef SIOCGSTAMP - case SIOCGSTAMP: - return _IOW(' ', 0, struct timeval); + case SIOCGSTAMP: + return _IOW(' ', 0, struct timeval); #endif - case SIOCGIFNAME: - case SIOCGIFFLAGS: - case SIOCGIFADDR: - case SIOCGIFDSTADDR: - case SIOCGIFBRDADDR: - case SIOCGIFNETMASK: - case SIOCGIFMETRIC: - case SIOCGIFMEM: - case SIOCGIFMTU: - case SIOCGIFHWADDR: - case SIOCGIFINDEX: - case SIOCGIFTXQLEN: - return _IOWR(' ', 0, struct ifreq); - case SIOCSIFNAME: - case SIOCSIFFLAGS: - case SIOCSIFADDR: - case SIOCSIFDSTADDR: - case SIOCSIFBRDADDR: - case SIOCSIFNETMASK: - case SIOCSIFMETRIC: - case SIOCSIFMEM: - case SIOCSIFMTU: - case SIOCSIFHWADDR: - case SIOCSIFTXQLEN: - case SIOCSIFHWBROADCAST: - return _IOR(' ', 0, struct ifreq); - case SIOCGIFMAP: - return _IOWR(' ', 0, struct ifmap); - case SIOCSIFMAP: - return _IOR(' ', 0, struct ifmap); - default: - return 0; + case SIOCGIFNAME: + case SIOCGIFFLAGS: + case SIOCGIFADDR: + case SIOCGIFDSTADDR: + case SIOCGIFBRDADDR: + case SIOCGIFNETMASK: + case SIOCGIFMETRIC: + case SIOCGIFMEM: + case SIOCGIFMTU: + case SIOCGIFHWADDR: + case SIOCGIFINDEX: + case SIOCGIFTXQLEN: + return _IOWR(' ', 0, struct ifreq); + case SIOCSIFNAME: + case SIOCSIFFLAGS: + case SIOCSIFADDR: + case SIOCSIFDSTADDR: + case SIOCSIFBRDADDR: + case SIOCSIFNETMASK: + case SIOCSIFMETRIC: + case SIOCSIFMEM: + case SIOCSIFMTU: + case SIOCSIFHWADDR: + case SIOCSIFTXQLEN: + case SIOCSIFHWBROADCAST: + return _IOR(' ', 0, struct ifreq); + case SIOCGIFMAP: + return _IOWR(' ', 0, struct ifmap); + case SIOCSIFMAP: + return _IOR(' ', 0, struct ifmap); + default: + return 0; } } int vunet_is_netdev_ioctl(unsigned long request) { - switch (request) { - case SIOCGIFCONF: + switch (request) { + case SIOCGIFCONF: #ifdef SIOCGSTAMP - case SIOCGSTAMP: + case SIOCGSTAMP: #endif - case SIOCGIFNAME: - case SIOCGIFFLAGS: - case SIOCGIFADDR: - case SIOCGIFDSTADDR: - case SIOCGIFBRDADDR: - case SIOCGIFNETMASK: - case SIOCGIFMETRIC: - case SIOCGIFMEM: - case SIOCGIFMTU: - case SIOCGIFHWADDR: - case SIOCGIFINDEX: - case SIOCGIFTXQLEN: - case SIOCSIFNAME: - case SIOCSIFFLAGS: - case SIOCSIFADDR: - case SIOCSIFDSTADDR: - case SIOCSIFBRDADDR: - case SIOCSIFNETMASK: - case SIOCSIFMETRIC: - case SIOCSIFMEM: - case SIOCSIFMTU: - case SIOCSIFHWADDR: - case SIOCSIFTXQLEN: - case SIOCSIFHWBROADCAST: - case SIOCGIFMAP: - case SIOCSIFMAP: + case SIOCGIFNAME: + case SIOCGIFFLAGS: + case SIOCGIFADDR: + case SIOCGIFDSTADDR: + case SIOCGIFBRDADDR: + case SIOCGIFNETMASK: + case SIOCGIFMETRIC: + case SIOCGIFMEM: + case SIOCGIFMTU: + case SIOCGIFHWADDR: + case SIOCGIFINDEX: + case SIOCGIFTXQLEN: + case SIOCSIFNAME: + case SIOCSIFFLAGS: + case SIOCSIFADDR: + case SIOCSIFDSTADDR: + case SIOCSIFBRDADDR: + case SIOCSIFNETMASK: + case SIOCSIFMETRIC: + case SIOCSIFMEM: + case SIOCSIFMTU: + case SIOCSIFHWADDR: + case SIOCSIFTXQLEN: + case SIOCSIFHWBROADCAST: + case SIOCGIFMAP: + case SIOCSIFMAP: return 1; default: return 0;