/* * 43BSD_FILE.C - 4.3BSD compatibility file syscalls * * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $DragonFly: src/sys/emulation/43bsd/43bsd_file.c,v 1.9 2005/08/27 20:23:05 joerg Exp $ * from: DragonFly kern/vfs_syscalls.c,v 1.20 * * These syscalls used to live in kern/vfs_syscalls.c. They are modified * to use the new split syscalls. */ #include "opt_compat.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int ocreat(struct ocreat_args *uap) { struct nlookupdata nd; int error; error = nlookup_init(&nd, uap->path, UIO_USERSPACE, NLC_FOLLOW); if (error == 0) { error = kern_open(&nd, O_WRONLY | O_CREAT | O_TRUNC, uap->mode, &uap->sysmsg_result); } return (error); } int oftruncate(struct oftruncate_args *uap) { int error; error = kern_ftruncate(uap->fd, uap->length); return (error); } int olseek(struct olseek_args *uap) { int error; error = kern_lseek(uap->fd, uap->offset, uap->whence, &uap->sysmsg_offset); return (error); } int otruncate(struct otruncate_args *uap) { struct nlookupdata nd; int error; error = nlookup_init(&nd, uap->path, UIO_USERSPACE, NLC_FOLLOW); if (error == 0) error = kern_truncate(&nd, uap->length); nlookup_done(&nd); return (error); } #define PADDED_SIZE(x) \ ((sizeof(struct odirent) + (x) + 1 + 3) & ~3) #define MAX_NAMELEN 255 struct odirent { uint32_t od_fileno; uint16_t od_reclen; uint8_t od_type; uint8_t od_namlen; char od_name[]; }; int ogetdirentries(struct ogetdirentries_args *uap) { int error, bytes_transfered; char *buf, *outbuf; size_t len; struct dirent *ndp; struct odirent *destdp; long base; if (uap->count > 16384) len = 16384; else len = uap->count; buf = malloc(len, M_TEMP, M_WAITOK); error = kern_getdirentries(uap->fd, buf, len, &base, &bytes_transfered, UIO_SYSSPACE); if (error) { free(buf, M_TEMP); return(error); } ndp = (struct dirent *)buf; outbuf = uap->buf; destdp = malloc(PADDED_SIZE(MAX_NAMELEN), M_TEMP, M_WAITOK); for (; (char *)ndp < buf + bytes_transfered; ndp = _DIRENT_NEXT(ndp)) { if ((char *)_DIRENT_NEXT(ndp) > buf + bytes_transfered) break; if (ndp->d_namlen > MAX_NAMELEN) continue; destdp->od_fileno = ndp->d_ino; #if BYTE_ORDER == LITTLE_ENDIAN destdp->od_type = ndp->d_namlen; destdp->od_namlen = ndp->d_type; #else destdp->od_type = ndp->d_type; destdp->od_namlen = ndp->d_namlen; #endif destdp->od_reclen = PADDED_SIZE(destdp->od_namlen); if (destdp->od_reclen > len) break; /* XXX can not happen */ bcopy(ndp->d_name, destdp->od_name, destdp->od_namlen); bzero(destdp->od_name + destdp->od_namlen, PADDED_SIZE(destdp->od_namlen) - sizeof(*destdp) - destdp->od_namlen); error = copyout(destdp, outbuf, PADDED_SIZE(destdp->od_namlen)); if (error) break; outbuf += PADDED_SIZE(destdp->od_namlen); len -= PADDED_SIZE(destdp->od_namlen); } free(destdp, M_TEMP); free(buf, M_TEMP); uap->sysmsg_result = outbuf - uap->buf; return (0); }