Home | History | Annotate | Download | only in syscall
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #pragma ident	"@(#)fsat.c	1.5	07/10/25 SMI"
     27 
     28 #include <sys/types.h>
     29 #include <sys/errno.h>
     30 #include <sys/fcntl.h>
     31 #include <sys/stat.h>
     32 #include <sys/vnode.h>
     33 #include <sys/vfs.h>
     34 #include <sys/time.h>
     35 #include <sys/systm.h>
     36 #include <sys/debug.h>
     37 
     38 extern int openat(int, char *, int, int);
     39 extern int renameat(int, char *, int, char *);
     40 extern int unlinkat(int, char *, int);
     41 extern int fchownat(int, char *, uid_t, gid_t, int);
     42 extern int fstatat(int, char *, struct stat *, int);
     43 extern int futimesat(int, char *, struct timeval *);
     44 extern int accessat(int, char *, int);
     45 extern int openattrdirat(int, char *);
     46 #if defined(_SYSCALL32_IMPL) || defined(_ILP32)
     47 extern int fstatat64_32(int, char *, struct stat64_32 *, int);
     48 extern int fstatat32(int, char *, struct stat32 *, int);
     49 extern int openat32(int, char *, int, int);
     50 extern int fstatat64(int, char *, struct stat64 *, int);
     51 extern int openat64(int, char *, int, int);
     52 extern int fstatat64_32(int, char *, struct stat64_32 *, int);
     53 #endif
     54 
     55 
     56 /*
     57  * Handle all of the *at system calls
     58  *
     59  * subcodes:
     60  * 0 - openat
     61  * 1 - openat64
     62  * 2 - fstatat64
     63  * 3 - fstatat
     64  * 4 - fchownat
     65  * 5 - unlinkat
     66  * 6 - futimesat
     67  * 7 - renameat
     68  * 8 - accessat
     69  * 9 - openattrdirat
     70  *
     71  * The code for handling the at functionality exists in the file where the
     72  * base syscall is defined.  For example openat is in open.c
     73  */
     74 
     75 #if defined(_SYSCALL32_IMPL) || defined(_ILP32)
     76 
     77 int
     78 fsat32(int code, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3,
     79     uintptr_t arg4, uintptr_t arg5)
     80 {
     81 	switch (code) {
     82 
     83 	case 0: /* openat */
     84 #if defined(_LP64)
     85 		return (openat32((int)arg1, (char *)arg2,
     86 		    (int)arg3, (int)arg4));
     87 #else
     88 		return (openat((int)arg1, (char *)arg2,
     89 		    (int)arg3, (int)arg4));
     90 #endif
     91 	case 1: /* openat64 */
     92 		return (openat64((int)arg1, (char *)arg2,
     93 		    (int)arg3, (int)arg4));
     94 	case 2: /* fstatat64 */
     95 #if defined(_LP64)
     96 		return (fstatat64_32((int)arg1, (char *)arg2,
     97 		    (struct stat64_32 *)arg3, (int)arg4));
     98 #else
     99 		return (fstatat64((int)arg1, (char *)arg2,
    100 		    (struct stat64 *)arg3, (int)arg4));
    101 #endif
    102 	case 3: /* fstatat */
    103 #if defined(_LP64)
    104 		return (fstatat32((int)arg1, (char *)arg2,
    105 		    (struct stat32 *)arg3, (int)arg4));
    106 #else
    107 		return (fstatat((int)arg1, (char *)arg2,
    108 		    (struct stat *)arg3, (int)arg4));
    109 #endif
    110 	case 4: /* fchownat */
    111 		return (fchownat((int)arg1, (char *)arg2,
    112 		    (uid_t)arg3, (gid_t)arg4, (int)arg5));
    113 	case 5: /* unlinkat */
    114 		return (unlinkat((int)arg1, (char *)arg2, (int)arg3));
    115 	case 6: /* futimesat */
    116 		return (futimesat((int)arg1,
    117 		    (char *)arg2, (struct timeval *)arg3));
    118 	case 7: /* renameat */
    119 		return (renameat((int)arg1, (char *)arg2, (int)arg3,
    120 		    (char *)arg4));
    121 	case 8: /* accessat */
    122 		return (accessat((int)arg1, (char *)arg2, (int)arg3));
    123 	case 9: /* openattrdirat */
    124 		return (openattrdirat((int)arg1, (char *)arg2));
    125 	default:
    126 		return (set_errno(EINVAL));
    127 	}
    128 }
    129 
    130 #endif
    131 
    132 /*
    133  * For 64 kernels, use fsat64
    134  */
    135 
    136 #if defined(_LP64)
    137 
    138 int
    139 fsat64(int code, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3,
    140     uintptr_t arg4, uintptr_t arg5)
    141 {
    142 	switch (code) {
    143 
    144 	case 0: /* openat */
    145 		return (openat((int)arg1, (char *)arg2,
    146 		    (int)arg3, (int)arg4));
    147 	case 1: /* openat64 */
    148 		return (set_errno(ENOSYS));
    149 	case 2: /* fstatat64 */
    150 		return (set_errno(ENOSYS));
    151 	case 3: /* fstatat */
    152 		return (fstatat((int)arg1, (char *)arg2,
    153 		    (struct stat *)arg3, (int)arg4));
    154 	case 4: /* fchownat */
    155 		return (fchownat((int)arg1, (char *)arg2,
    156 		    (uid_t)arg3, (gid_t)arg4, (int)arg5));
    157 	case 5: /* unlinkat */
    158 		return (unlinkat((int)arg1, (char *)arg2, (int)arg3));
    159 	case 6: /* futimesat */
    160 		return (futimesat((int)arg1,
    161 		    (char *)arg2, (struct timeval *)arg3));
    162 	case 7: /* renameat */
    163 		return (renameat((int)arg1, (char *)arg2, (int)arg3,
    164 		    (char *)arg4));
    165 	case 8: /* accessat */
    166 		return (accessat((int)arg1, (char *)arg2, (int)arg3));
    167 	case 9: /* openattrdirat */
    168 		return (openattrdirat((int)arg1, (char *)arg2));
    169 	default:
    170 		return (set_errno(EINVAL));
    171 	}
    172 }
    173 #endif
    174