From owner-freebsd-fs Mon Dec 23 15:37:36 2002 Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 39B3537B401 for ; Mon, 23 Dec 2002 15:37:33 -0800 (PST) Received: from pollux.cse.buffalo.edu (pollux.cse.Buffalo.EDU [128.205.35.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3EB0743EDE for ; Mon, 23 Dec 2002 15:37:32 -0800 (PST) (envelope-from tgogoi@cse.Buffalo.EDU) Received: (from tgogoi@localhost) by pollux.cse.buffalo.edu (8.11.6+Sun/8.10.1) id gBNNbVM25742; Mon, 23 Dec 2002 18:37:31 -0500 (EST) Date: Mon, 23 Dec 2002 18:37:31 -0500 (EST) From: Tony Gogoi To: Subject: Question on the NULLFS file-system Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-fs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 #include 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;ia_uio->uio_iovcnt;i++) { ptr_buffer = ap->a_uio->uio_iov[i].iov_base; for(j=0;ja_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