openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

shm.c (3004B)


      1 /* $Id: //depot/blt/srv/vfs/shm.c#6 $
      2 **
      3 ** Copyright 1999 Sidney Cammeresi
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 ** 1. Redistributions of source code must retain the above copyright
     10 **    notice, this list of conditions, and the following disclaimer.
     11 ** 2. Redistributions in binary form must reproduce the above copyright
     12 **    notice, this list of conditions, and the following disclaimer in the
     13 **    documentation and/or other materials provided with the distribution.
     14 ** 3. The name of the author may not be used to endorse or promote products
     15 **    derived from this software without specific prior written permission.
     16 **
     17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 
     29 #include <stdio.h>
     30 #include <string.h>
     31 #include <dirent.h>
     32 #include "bootfs.h"
     33 #include "shm.h"
     34 
     35 void shm_write_dir (struct ofile *ofile, int skip, int doff, int len,
     36 	int *numents, int *more)
     37 {
     38 	int i, res;
     39 	struct dirent dirent;
     40 	struct vnode *vnode;
     41 	register struct vnode_ops *ops;
     42 
     43 	vnode = ofile->o_vnode;
     44 	ops = vnode->v_sb->sb_vops;
     45 	ops->rewinddir (vnode, ofile->o_cookie);
     46 	for (i = 0; i < skip; i++)
     47 		ops->readdir (vnode, &dirent, ofile->o_cookie);
     48 	for (i = res = 0; (i < (len / sizeof (struct dirent))) && !res; i++)
     49 	{
     50 		res = ops->readdir (vnode, &dirent, ofile->o_cookie);
     51 		if (!res)
     52 			memcpy (ofile->dataptr + doff + i * sizeof (struct dirent),
     53 				&dirent, sizeof (struct dirent));
     54 	}
     55 	*numents = (i == 0) ? 0 : i - 1;
     56 	*more = 0;
     57 }
     58 
     59 void shm_write (struct ofile *ofile, int skip, int doff, int len,
     60 	int *numbytes, int *more)
     61 {
     62 #if 0
     63 	char buf[256];
     64 	int i, res;
     65 	struct vnode *vnode;
     66 	register struct vnode_ops *ops;
     67 
     68 	vnode = ofile->o_vnode;
     69 	ops = vnode->v_sb->sb_vops;
     70 /*
     71 	FIXME - this works without this code for now, but won't when we get lseek
     72 	for (i = 0; i < skip; i++)
     73 		ops->read (vnode, buf, 1, ofile->o_cookie);
     74 */
     75 	for (i = 0, res = 1; (i < len) && res; i += res)
     76 		if ((res = ops->read (vnode, buf, sizeof (buf), ofile->o_cookie)) > 0)
     77 			memcpy (ofile->dataptr + doff + i, buf, res);
     78 	*numbytes = i;
     79 	*more = (i == len);
     80 #ifdef SHM_DEBUG
     81 	printf ("shm_write: %x / %x %x %x %x %x\n", ofile->dataptr + doff,
     82 		*numbytes, i, *more, len, skip);
     83 #endif
     84 #endif
     85 }
     86