diff --git a/include/vumodule.h b/include/vumodule.h index a882a7e..8332fff 100644 --- a/include/vumodule.h +++ b/include/vumodule.h @@ -168,19 +168,21 @@ void VU_SYSNAME(name, cleanup) (uint8_t type, void *arg, int arglen, \ #define SET_EPOCH 1 #define NEGATIVE_MOUNT ((confirmfun_t)1) +#define VUFLAG_PERMANENT 1 +#define VUFLAG_TRAILINGNUMBERS 2 + typedef int (*confirmfun_t)(uint8_t type, void *arg, int arglen, struct vuht_entry_t *ht); struct vuht_entry_t *vuht_add(uint8_t type, const void *obj, int objlen, - struct vu_service_t *service, confirmfun_t confirmfun, - void *ht_private_data, int permanent); + struct vu_service_t *service, int vuflags, + confirmfun_t confirmfun, void *private_data); struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source, const char *path, const char *fstype, unsigned long mountflags, const char *mountopts, - struct vu_service_t *service, - unsigned char trailingnumbers, - confirmfun_t confirmfun, void *ht_private_data); + struct vu_service_t *service, int vuflags, + confirmfun_t confirmfun, void *private_data); #define BINFMTBUFLEN 128 #define BINFMTLINELEN 1920 diff --git a/test_modules/netlinkdump.c b/test_modules/netlinkdump.c index 6719213..ec70d00 100644 --- a/test_modules/netlinkdump.c +++ b/test_modules/netlinkdump.c @@ -102,7 +102,7 @@ void *vu_netlinkdump_init(void) { vu_syscall_handler(s, close) = close; #pragma GCC diagnostic pop - ht = vuht_add(CHECKSOCKET, &family, sizeof(int), s, NULL, NULL, 0); + ht = vuht_add(CHECKSOCKET, &family, sizeof(int), s, 0, NULL, NULL); return NULL; } diff --git a/test_modules/unrealcap.c b/test_modules/unrealcap.c index b0169ae..b1e2b82 100644 --- a/test_modules/unrealcap.c +++ b/test_modules/unrealcap.c @@ -177,7 +177,7 @@ void *vu_unrealcap_init(void) { 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); + ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, 0, NULL, NULL); } mod_inheritance_upcall_register(vu_cap_tracer_upcall); return NULL; diff --git a/test_modules/unrealprw.c b/test_modules/unrealprw.c index 0003fe2..08d77f0 100644 --- a/test_modules/unrealprw.c +++ b/test_modules/unrealprw.c @@ -18,7 +18,7 @@ * */ -/* this is a test module: +/* this is a test module: it is a copy of unreal supporting only pread/pwrite. when loaded the entire file system "appears" as /unreal and /unreal/unreal. $ vu_insmod unreal diff --git a/test_modules/unrealsock.c b/test_modules/unrealsock.c index e4da75a..a5d40a7 100644 --- a/test_modules/unrealsock.c +++ b/test_modules/unrealsock.c @@ -64,7 +64,7 @@ void *vu_unrealsock_init(void) { #pragma GCC diagnostic pop for (i = 0; i < 3; i++) - ht[i] = vuht_add(CHECKSOCKET, &afs[i], sizeof(int), s, NULL, NULL, 0); + ht[i] = vuht_add(CHECKSOCKET, &afs[i], sizeof(int), s, 0, NULL, NULL); return NULL; } diff --git a/test_modules/unrealuidgid.c b/test_modules/unrealuidgid.c index bbc7f18..0be7a92 100644 --- a/test_modules/unrealuidgid.c +++ b/test_modules/unrealuidgid.c @@ -256,7 +256,7 @@ void *vu_unrealuidgid_init(void) { 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); + ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, 0, NULL, NULL); } mod_inheritance_upcall_register(vu_uid_gid_tracer_upcall); return NULL; diff --git a/umvu/include/hashtable.h b/umvu/include/hashtable.h index b4f093f..42874f9 100644 --- a/umvu/include/hashtable.h +++ b/umvu/include/hashtable.h @@ -33,6 +33,9 @@ struct vu_service_t; #define SET_EPOCH 1 #define NEGATIVE_MOUNT ((confirmfun_t)1) +#define VUFLAG_PERMANENT 1 +#define VUFLAG_TRAILINGNUMBERS 2 + /* hashtable elements may have exception. when a confirm function is defined (as an argument adding the hashtable element) that confirm function is called prior to confirm each match */ @@ -42,16 +45,15 @@ typedef int (*confirmfun_t)(uint8_t type, void *arg, int arglen, /* add an element to the hashtable */ /* confirmfun is a cleanup function for CHECKMODULE */ struct vuht_entry_t *vuht_add(uint8_t type, const void *obj, int objlen, - struct vu_service_t *service, confirmfun_t confirmfun, - void *private_data, int permanent); + struct vu_service_t *service, int vuflags, + confirmfun_t confirmfun, void *private_data); /* add a path element to the hashtable: This function is similar to vuht_add * extra parameters are provided to generate teh mounttab line (see /proc/mounts) */ struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source, const char *path, const char *fstype, unsigned long mountflags, const char *mountopts, - struct vu_service_t *service, - unsigned char trailingnumbers, + struct vu_service_t *service, int vuflags, confirmfun_t confirmfun, void *private_data); /* del takes the element out from the data structure.... */ diff --git a/umvu/src/hashtable.c b/umvu/src/hashtable.c index c473d81..02c64a8 100644 --- a/umvu/src/hashtable.c +++ b/umvu/src/hashtable.c @@ -60,7 +60,7 @@ struct vuht_entry_t { unsigned long mountflags; epoch_t timestamp; uint8_t type; - uint8_t trailingnumbers; + int vuflags; struct vu_service_t *service; struct vuht_entry_t *service_hte; void *private_data; @@ -269,7 +269,7 @@ static struct vuht_entry_t *vuht_internal_search(uint8_t type, void *obj, while (ht != NULL) { if (type == ht->type && sum == ht->hashsum && memcmp(obj, ht->obj, len) == 0 && - (ht->trailingnumbers || !trailnum(objc)) && + ((ht->vuflags & VUFLAG_TRAILINGNUMBERS) || !trailnum(objc)) && (e = matching_epoch(ht->timestamp)) > 0) { /*carrot add*/ if (ht->confirmfun == NEGATIVE_MOUNT) @@ -329,13 +329,12 @@ static inline int stringobj(uint8_t type) { type == CHECKFSALIAS; } + 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, - confirmfun_t confirmfun, void *private_data, - int permanent) -{ + struct vu_service_t *service, int vuflags, + confirmfun_t confirmfun, void *private_data) { struct vuht_entry_t **hashhead; struct vuht_entry_t *new = vuht_alloc(); /* create the entry and fill in the fields */ @@ -350,12 +349,12 @@ internal_vuht_add(uint8_t type, const void *obj, int objlen, new->type = type; new->mountflags = mountflags; new->mtabline = mtabline; - new->trailingnumbers = trailingnumbers; + new->vuflags = vuflags; new->private_data = private_data; new->service = service; new->service_hte = service->service_ht; new->confirmfun = confirmfun; - new->count = (permanent != 0); + new->count = !! (vuflags & VUFLAG_PERMANENT); if (service->service_ht) vuht_pick_again(service->service_ht); @@ -390,10 +389,10 @@ internal_vuht_add(uint8_t type, const void *obj, int objlen, } struct vuht_entry_t *vuht_add(uint8_t type, const void *obj, int objlen, - struct vu_service_t *service, confirmfun_t confirmfun, - void *private_data, int permanent) { - return internal_vuht_add(type, obj, objlen, 0, NULL, service, 1, - confirmfun, private_data, permanent); + struct vu_service_t *service, int vuflags, + confirmfun_t confirmfun, void *private_data) { + return internal_vuht_add(type, obj, objlen, 0, NULL, service, vuflags, + confirmfun, private_data); } static int permanent_mount(const char *opts) @@ -409,8 +408,7 @@ static int permanent_mount(const char *opts) struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source, const char *path, const char *fstype, unsigned long mountflags, const char *mountopts, - struct vu_service_t *service, - unsigned char trailingnumbers, + struct vu_service_t *service, int vuflags, confirmfun_t confirmfun, void *private_data) { char *mtabline; const char *addpath; @@ -433,9 +431,11 @@ struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source, addpath = ""; else addpath = path; + if (permanent_mount(mountopts)) + vuflags |= VUFLAG_PERMANENT; rv = internal_vuht_add(type, addpath, strlen(addpath), mountflags, - mtabline, service, trailingnumbers, confirmfun, - private_data, permanent_mount(mountopts)); + mtabline, service, vuflags, + confirmfun, private_data); if (rv == NULL && mtabline != NULL) free(mtabline); return rv; diff --git a/umvu/src/vu_vwrap_vumgmt.c b/umvu/src/vu_vwrap_vumgmt.c index 4d9b90a..5ba1591 100644 --- a/umvu/src/vu_vwrap_vumgmt.c +++ b/umvu/src/vu_vwrap_vumgmt.c @@ -81,7 +81,8 @@ void vw_insmod(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) { cleanup = module_getsym(service, "cleanup"); #pragma GCC diagnostic pop sht = vuht_add(CHECKMODULE, modname, strlen(modname), service, - cleanup, NULL, permanent); + permanent ? VUFLAG_PERMANENT : 0, + cleanup, NULL); service->service_ht = sht; diff --git a/vubinfmt/vubinfmt.c b/vubinfmt/vubinfmt.c index 122c5ea..fcd0d05 100644 --- a/vubinfmt/vubinfmt.c +++ b/vubinfmt/vubinfmt.c @@ -430,10 +430,10 @@ int vu_vubinfmt_mount(const char *source, const char *target, switch(strcase(source)) { case STRCASE(n,o,n,e): case STRCASE(slash): - new->binfmt_ht = vuht_add(CHECKBINFMT, NULL, 0, s, vubinfmt_confirm, new, 0); + new->binfmt_ht = vuht_add(CHECKBINFMT, NULL, 0, s, 0, vubinfmt_confirm, new); break; default: - new->binfmt_ht = vuht_add(CHECKBINFMT, source, strlen(source), s, vubinfmt_confirm, new, 0); + new->binfmt_ht = vuht_add(CHECKBINFMT, source, strlen(source), s, 0, vubinfmt_confirm, new); break; } new->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags, data, s, 0, NULL, new); diff --git a/vudev/vudev.c b/vudev/vudev.c index 209fcc6..0ea214e 100644 --- a/vudev/vudev.c +++ b/vudev/vudev.c @@ -436,12 +436,12 @@ int vu_vudev_mount(const char *source, const char *target, goto err_init_null; } new->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags, - data, s, 1, vudev_confirm_path, new); + data, s, VUFLAG_TRAILINGNUMBERS, vudev_confirm_path, new); if (new->flags & VUDEVFLAGS_DEVID) { if(S_ISCHR(new->stat.st_mode)) - new->dev_ht = vuht_add(CHECKCHRDEVICE, NULL, 0, s, vudev_confirm_dev, new, 0); + new->dev_ht = vuht_add(CHECKCHRDEVICE, NULL, 0, s, 0, vudev_confirm_dev, new); else if(S_ISBLK(new->stat.st_mode)) - new->dev_ht = vuht_add(CHECKBLKDEVICE, NULL, 0, s, vudev_confirm_dev, new, 0); + new->dev_ht = vuht_add(CHECKBLKDEVICE, NULL, 0, s, 0, vudev_confirm_dev, new); } else new->dev_ht = NULL; pthread_mutex_unlock(&(new->mutex)); diff --git a/vumisc/vumisc.c b/vumisc/vumisc.c index 16e92ca..695f4c2 100644 --- a/vumisc/vumisc.c +++ b/vumisc/vumisc.c @@ -299,7 +299,7 @@ int vu_vumisc_mount(const char *source, const char *target, pthread_mutex_lock(&(new->mutex)); new->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags, data, s, 0, NULL, new); - new->ops_ht = vuht_add(CHECKSC, NULL, 0, s, vumisc_confirm, new, 0); + new->ops_ht = vuht_add(CHECKSC, NULL, 0, s, 0, vumisc_confirm, new); pthread_mutex_unlock(&(new->mutex)); return errno = 0, 0; err_init_null: diff --git a/vunet/vunet.c b/vunet/vunet.c index 4cf8656..71e7eae 100644 --- a/vunet/vunet.c +++ b/vunet/vunet.c @@ -425,10 +425,10 @@ int vu_vunet_mount(const char *source, const char *target, retvalue = -1; } else { if (vunet->netops->supported_ioctl) - vunet->ioctl_ht = vuht_add(CHECKIOCTL, NULL, 0, s, checkioctl, vunet, 0); + vunet->ioctl_ht = vuht_add(CHECKIOCTL, NULL, 0, s, 0, checkioctl, vunet); else vunet->ioctl_ht = NULL; - vunet->socket_ht = vuht_add(CHECKSOCKET, NULL, 0, s, checksocket, vunet, 0); + vunet->socket_ht = vuht_add(CHECKSOCKET, NULL, 0, s, 0, checksocket, vunet); vunet->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags, data, s, 0, NULL, vunet); printkdebug(N, "mount \'%s\' \'%s\' %s -> %p", source, target, filesystemtype, vunet); }