Date: Mon, 23 Dec 2002 18:37:31 -0500 (EST) From: Tony Gogoi <tgogoi@cse.Buffalo.EDU> To: <freebsd-fs@freebsd.org> Subject: Question on the NULLFS file-system Message-ID: <Pine.SOL.4.30.0212231823330.24955-100000@pollux.cse.buffalo.edu>
next in thread | raw e-mail | index | archive | help
Hi everyone,
I was referred by someone to post my question here. Will be very grateful
if someone would respond....
I modified sys/miscfs/nullfs/null_vnops.c so that it now includes a
null_write and a null_read system call. The purpose is simple encryption.
Any file that has its first 3 characters as "---" would be encrpted such
that whats stored in the lowest layer (ufs) would be one ascii character
higher. Example if I do "vi N" and then store ---ABCD in the file, it gets
stored as ---BCDE ( i don't encrypt the -'s). This works when I use 'vi'
BUT when I write a simple program which has something like
/* start of test program */
#include <stdio.h>
#include <fcntl.h>
int main()
{
int fd = 0;
char buff[100];
fd = open("N",O_RDWR|O_CREAT);
if(fd < 0)
{
perror("open failed\n");
exit(1);
}
write(fd,"---Tony\nabcdefg",17);
close(fd);
return 0;
}
/* end of test program */
/***************************************.
Then the kernel crashes. It crashes whenever the first 3 characters of the
file are "---" sa then encryption needs to be performed.
Why does null_write system call work properly when I use "vi" but crashes
when i write such a simple test program ?
Below if the code I worte for null_write :
/***************************************************************************/
static int null_write(ap)
struct vop_write_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
struct ucred *a_cred;
} */ *ap;
{
int error;
char *ptr_buffer;
int i, j, Limit, Flag ;
ptr_buffer = ap->a_uio->uio_iov[0].iov_base;
if(ap->a_uio->uio_iovcnt > 1)
{
Limit = 3;
}
else
{
if(ap->a_uio->uio_iov[0].iov_len > 3)
Limit = 3;
else Limit = ap->a_uio->uio_iov[0].iov_len;
}
Flag = 1;
/*************************************************************************/
/* check if encryption requested */
if(Limit==3)
{
if(ptr_buffer[0]=='-' && ptr_buffer[1]=='-' && ptr_buffer[2]=='-')
{
Flag = 0;
}
}
/*************************************************************************/
if(Flag==0)
{
for(i=0;i<ap->a_uio->uio_iovcnt;i++)
{
ptr_buffer = ap->a_uio->uio_iov[i].iov_base;
for(j=0;j<ap->a_uio->uio_iov[i].iov_len;j++)
{
if((ptr_buffer[j] != '-') && (ptr_buffer[j] != '\n'))
{
ptr_buffer[j] = ptr_buffer[j] + 1;
}
}
}
}
if ((error = null_bypass((struct vop_generic_args *)ap)) != 0)
return (error);
return(0);
}
/* end of null_write code */
/*****************************************************************************************/
thanks for your time.
Tony Gogoi
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-fs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.4.30.0212231823330.24955-100000>
