📄 subr.c
字号:
printf("wrapfs %x/%d -> %x/%d [%s, %d]\n", WRAPFSTOV(a), WRAPFSTOV(a)->v_usecount, a->wrapfs_lowervp, a->wrapfs_lowervp->v_usecount, fil, lno);#endif return a->wrapfs_lowervp;}#endif/****************************************************************************//* ADDED BY EZK *//* allocate memory and zero it */void *kmem_zalloc(unsigned long size){ void *addr; addr = malloc(size, M_TEMP, M_WAITOK); if (addr) bzero(addr, size); return addr;}/* do an I/O move */intfist_uiomove(caddr_t cp, int n, enum uio_rw rwflag, struct uio *uio){ enum uio_rw saved_rwflag; int ret; if (uio->uio_rw != rwflag) { printf("UIOMOVE mismatching flags: uio->uio_rw=%d, rwflag=%d\n", uio->uio_rw, rwflag); } /* save uio's rwflag */ saved_rwflag = uio->uio_rw; uio->uio_rw = rwflag; ret = uiomove(cp, n, uio); uio->uio_rw = saved_rwflag; return ret;}#if 0#ifdef FIST_FILTER_DATA/* return the number of bytes written */intwrapfs_encode_block(char *func, int line, caddr_t base, int len, const vnode_t *vp, cred_t *cr){ /* blowfish variables */ unsigned char iv[8]; int n; /* ASSERT(fist_get_userpass(vp->v_vfsp,cr) != NULL); */ if (len > PAGE_SIZE || len < 0) printf("CEB: %s:%d: base=%x, len=%d, vp=%x\n", func, line, (int) base, len, (int) vp); bcopy(cbc_iv, iv, 8); n = 0; /* opaque variable for blowfish's internal stat */ BF_cfb64_encrypt(base, base, len, fist_get_userpass(vp->v_mount, cr), iv, &n, BF_ENCRYPT); return len;}intwrapfs_decode_block(char *func, int line, caddr_t base, int len, const vnode_t *vp, cred_t *cr){ /* blowfish variables */ unsigned char iv[8]; int n; /* ASSERT(fist_get_userpass(vp->v_vfsp,cr) != NULL); */ if (len > PAGE_SIZE || len < 0) printf("CDB: %s:%d: base=%x, len=%d, vp=%x\n", func, line, (int) base, len, (int) vp); bcopy(cbc_iv, iv, 8); n = 0; /* opaque variable for blowfish's internal stat */ BF_cfb64_encrypt(base, base, len, fist_get_userpass(vp->v_mount, cr), iv, &n, BF_DECRYPT); return len;}#endif /* FIST_FILTER_DATA */#endif#ifdef FIST_FILTER_NAME#if 0voidwrapfs_encode_filename( vfs_t *vfsp, char *name, char **uuencoded_name, /* null-terminated */ int *uuencoded_length, /* w/ terminating null */ int skip_dots, int use_namei_zone, cred_t *cr){ char *crypted_name,*ptr; int length, rounded_length, n, i, j; unsigned char iv[8]; short csum; /* ASSERT(fist_get_userpass(vfsp, cr) != NULL); */ if (skip_dots && (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))) { *uuencoded_length = strlen(name) + 1; *uuencoded_name = kmem_zalloc(*uuencoded_length); strcpy(*uuencoded_name, name); return; } for (csum = 0, length = 0, ptr = name; *ptr; ptr++, length++) csum += *ptr; /* * rounded_length is an multiple of 3 rounded-up length * the uuencode algorithm processes 3 source bytes at a time * so we have to make sure we don't read past the memory * we have allocated * * it uses length + 3 to provide 2 bytes for the checksum * and one byte for the length */ rounded_length = (((length + 3) + 2) / 3) * 3; crypted_name = kmem_zalloc(rounded_length); bcopy(cbc_iv, iv, 8); n = 0; *(short *)crypted_name = csum; crypted_name[2] = length; BF_cfb64_encrypt(name, crypted_name + 3, length, fist_get_userpass(vfsp, cr), iv, &n, BF_ENCRYPT); *uuencoded_length = (((length + 3) + 2) / 3) * 4 + 1; if (use_namei_zone) *uuencoded_name = zalloc(namei_zone); /* 'z' stands for Zone Alloc */ else *uuencoded_name = kmem_alloc(*uuencoded_length); for (i = 0, j = 0; i < rounded_length; i += 3, j += 4) { (*uuencoded_name)[j] = 48 + ((crypted_name[i] >> 2) & 63); (*uuencoded_name)[j + 1] = 48 + (((crypted_name[i] << 4) & 48) | ((crypted_name[i + 1] >> 4) & 15)); (*uuencoded_name)[j + 2] = 48 + (((crypted_name[i + 1] << 2) & 60) | ((crypted_name[i + 2] >> 6) & 3)); (*uuencoded_name)[j + 3] = 48 + (crypted_name[i + 2] & 63); } (*uuencoded_name)[j] = '\0'; kmem_free(crypted_name);}intwrapfs_decode_filename(vfs_t *vfsp, char *name, int length, char **decrypted_name, int *decrypted_length, /* w/ terminating null */ int skip_dots, cred_t *cr){ int n, i, j, saved_length, saved_csum, csum; int uudecoded_length, error = 0; unsigned char iv[8]; char *uudecoded_name; /* ASSERT(fist_get_userpass(vfsp, cr) != NULL); */ if (skip_dots && (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))) { /* used to add 1 to following */ *decrypted_length = length + 1; *decrypted_name = kmem_alloc(*decrypted_length); for (i = 0; i < length; i++) (*decrypted_name)[i] = name[i]; (*decrypted_name)[i] = 0; return 0; } uudecoded_length = ((length + 3) / 4) * 3; uudecoded_name = kmem_alloc(uudecoded_length); for (i = 0, j = 0; i < length; i += 4, j += 3) { uudecoded_name[j] = ((name[i] - 48) <<2) | ((name[i + 1] - 48) >>4); uudecoded_name[j + 1] = (((name[i + 1] - 48) <<4) & 240) | ((name[i + 2] - 48) >>2); uudecoded_name[j + 2] = (((name[i + 2] - 48) <<6) & 192) | ((name[i + 3] - 48) &63); } saved_csum = *(short *)uudecoded_name; saved_length = uudecoded_name[2]; if (saved_length > uudecoded_length) { printf("Problems with the length - too big: %d", saved_length); error = -1; goto out; } *decrypted_name = (char *)kmem_alloc(saved_length + 1); bcopy(cbc_iv, iv, 8); n = 0; BF_cfb64_encrypt(uudecoded_name + 3, *decrypted_name, saved_length, fist_get_userpass(vfsp, cr), iv, &n, BF_DECRYPT); for (csum = 0, i = 0; i < saved_length; i++) csum += (*decrypted_name)[i]; if (csum != saved_csum) { fist_dprint(6,"Checksum error\n"); kmem_free(*decrypted_name); error = -1; goto out; } (*decrypted_name)[saved_length] = 0; *decrypted_length = saved_length + 1;out: kmem_free(uudecoded_name); return error;}#endif/* * create a new (lower) componentname from an existing one * (this level) and encode the inner. */cn_t *wrapfs_new_cnp(const vnode_t *thisvp, const cn_t *thiscnp){ cn_t *lowercnp;#ifdef FIST_ENCODE static char buf[MAXNAMLEN];#else /* not FIST_ENCODE */ int len; char *name = NULL;#endif /* not FIST_ENCODE */ if (!thiscnp) return NULL; lowercnp = kmem_alloc(sizeof(cn_t)); if (!lowercnp) panic("wrapfs_new_cnp: no more memory\n"); /* copy all fields */ bcopy(thiscnp, lowercnp, sizeof(cn_t)); /* fix certain fields temporarily */ lowercnp->cn_pnbuf = NULL; lowercnp->cn_nameptr = NULL; lowercnp->cn_namelen = 0; /* prepare new path name for lookup */#ifdef FIST_ENCODE bcopy(thiscnp->cn_nameptr, buf, thiscnp->cn_namelen); buf[thiscnp->cn_namelen] = '\0'; wrapfs_encode_filename(thisvp->v_mount, buf, &lowercnp->cn_pnbuf, (int *) &lowercnp->cn_namelen, SKIP_DOTS, TRUE, /* use namei zone alloc */ thiscnp->cn_cred); /* updated other cnp fields */ lowercnp->cn_namelen--; /* don't count terminating null */ lowercnp->cn_nameptr = lowercnp->cn_pnbuf; /* I always allocate my own lowercnp buffer */#else /* not FIST_ENCODE */ len = thiscnp->cn_namelen; name = zalloc(namei_zone); if (!name) panic("wrapfs_new_cnp: no more memory for name\n"); bcopy(thiscnp->cn_nameptr, name, len+1); name[len] = '\0'; /* just in case (not needed) */ /* updated other cnp fields */ name[0]++; /* update first char of name */ lowercnp->cn_namelen = len; lowercnp->cn_nameptr = lowercnp->cn_pnbuf = name;#endif /* not FIST_ENCODE */ /* return formed string */ return lowercnp;}/* * Update an old cnp based on a newer one. * Also free previously allocated lowercnp and its fields. */voidwrapfs_update_cnp(const vnode_t *thisvp, cn_t **lowercnpp, cn_t *thiscnp, int error){ /* * free thiscnp if there no error, HASBUF was on, and SAVENAME was off. * XXX: what about SAVESTART (from <sys/namei.h>) */ if (!error && (thiscnp->cn_flags & (HASBUF|SAVENAME|SAVESTART)) == HASBUF) { fist_dprint(2, "UPDATE_CNP: freeing thiscnp->cn_pnbuf \"%s\"\n", thiscnp->cn_pnbuf); zfree(namei_zone, thiscnp->cn_pnbuf); } if (!fist_isdeadcode(*lowercnpp)) { fist_dprint(2, "UPDATE_CNP: lowercnp flags <%s>\n", fist_cn_flags((*lowercnpp)->cn_flags)); } /* always free space used by lowercnp, if not already free'd */ if (fist_isdeadcode(*lowercnpp)) return; if (!fist_isdeadcode((*lowercnpp)->cn_pnbuf)) { if (((*lowercnpp)->cn_flags & (HASBUF|SAVENAME|SAVESTART)) == HASBUF) { fist_dprint(2, "UPDATE_CNP: freeing lowercnp->cn_pnbuf \"%s\"\n", (*lowercnpp)->cn_pnbuf); zfree(namei_zone, (*lowercnpp)->cn_pnbuf); } else { fist_dprint(1, "UPDATE_CNP: not freeing 0x%x \"%s\" <%s>\n", (int) *lowercnpp, (*lowercnpp)->cn_pnbuf, fist_cn_flags((*lowercnpp)->cn_flags)); } } fist_dprint(2, "UPDATE_CNP: freeing lowercnp 0x%x\n", (int) *lowercnpp); kmem_free(*lowercnpp);}#endif /* FIST_FILTER_NAME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -