summaryrefslogtreecommitdiff
path: root/sys/xfs/xfs_syscalls.c
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>1998-08-31 05:13:30 +0000
committerArtur Grabowski <art@cvs.openbsd.org>1998-08-31 05:13:30 +0000
commit30ed0a197fb0271433d779fa72cef1e9f946acdb (patch)
tree4d8a397b4c8d27c7ae2896852d222e32f20b2c52 /sys/xfs/xfs_syscalls.c
parent1de9611a8756024513a888ef62be9f487f9dc81f (diff)
indent the code and move around some includes, after discussion with Theo
Diffstat (limited to 'sys/xfs/xfs_syscalls.c')
-rw-r--r--sys/xfs/xfs_syscalls.c412
1 files changed, 207 insertions, 205 deletions
diff --git a/sys/xfs/xfs_syscalls.c b/sys/xfs/xfs_syscalls.c
index fe07630dbc2..323eb0ea95c 100644
--- a/sys/xfs/xfs_syscalls.c
+++ b/sys/xfs/xfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xfs_syscalls.c,v 1.2 1998/08/30 18:06:19 art Exp $ */
+/* $OpenBSD: xfs_syscalls.c,v 1.3 1998/08/31 05:13:17 art Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
@@ -55,24 +55,25 @@ RCSID("$KTH: xfs_syscalls.c,v 1.20 1998/07/19 21:18:30 art Exp $");
/*
* XFS system calls.
*/
-
-#include <sys/xfs_message.h>
+#include <xfs/xfs_message.h>
#include <xfs/xfs_syscalls.h>
#include <xfs/xfs_dev.h>
#include <xfs/xfs_node.h>
#include <xfs/xfs_deb.h>
/* Misc syscalls */
-#include <sys/xfs_pioctl.h>
+#include <xfs/xfs_pioctl.h>
#include <sys/syscallargs.h>
#ifdef ACTUALLY_LKM_NOT_KERNEL
+
/* XXX really defined in kern/kern_lkm.c */
extern int sys_lkmnosys(struct proc *p, void *v, register_t *retval);
#ifndef SYS_MAXSYSCALL /* Workaround for OpenBSD */
#define SYS_MAXSYSCALL 255
#endif
+
#endif /* ACTUALLY_LKM_NOT_KERNEL */
@@ -93,63 +94,61 @@ static gid_t pag_part_two = XFS_PAG2_LLIM;
static int
xfs_is_pag(struct ucred *cred)
{
- /* The first group is the gid of the user ? */
-
- if (cred->cr_ngroups >= 3 &&
- cred->cr_groups[1] >= XFS_PAG1_LLIM &&
- cred->cr_groups[1] <= XFS_PAG1_ULIM &&
- cred->cr_groups[2] >= XFS_PAG2_LLIM &&
- cred->cr_groups[2] <= XFS_PAG2_ULIM)
- return 1;
- else
- return 0;
+ /* The first group is the gid of the user ? */
+
+ if (cred->cr_ngroups >= 3 &&
+ cred->cr_groups[1] >= XFS_PAG1_LLIM &&
+ cred->cr_groups[1] <= XFS_PAG1_ULIM &&
+ cred->cr_groups[2] >= XFS_PAG2_LLIM &&
+ cred->cr_groups[2] <= XFS_PAG2_ULIM)
+ return 1;
+ else
+ return 0;
}
pag_t
xfs_get_pag(struct ucred *cred)
{
- if (xfs_is_pag(cred)) {
-
- return (((cred->cr_groups[1] << 16) & 0xFFFF0000) |
- ((cred->cr_groups[2] & 0x0000FFFF)));
-
- } else
- return cred->cr_uid; /* XXX */
+ if (xfs_is_pag(cred)) {
+ return (((cred->cr_groups[1] << 16) & 0xFFFF0000) |
+ ((cred->cr_groups[2] & 0x0000FFFF)));
+ } else
+ return cred->cr_uid; /* XXX */
}
static int
xfs_setpag_call(struct ucred **ret_cred)
{
- struct ucred *cred = *ret_cred;
- int i;
+ struct ucred *cred = *ret_cred;
+ int i;
- if (!xfs_is_pag(cred)) {
+ if (!xfs_is_pag(cred)) {
+ /* Check if it fits */
+ if (cred->cr_ngroups + 2 >= NGROUPS)
+ return E2BIG; /* XXX Hmmm, better error ? */
- /* Check if it fits */
- if (cred->cr_ngroups + 2 >= NGROUPS)
- return E2BIG; /* XXX Hmmm, better error ? */
+ cred = crcopy (cred);
- cred = crcopy (cred);
+ /* Copy the groups */
+ for (i = cred->cr_ngroups - 1; i > 0; i--) {
+ cred->cr_groups[i + 2] = cred->cr_groups[i];
+ }
+ cred->cr_ngroups += 2;
- /* Copy the groups */
- for (i = cred->cr_ngroups - 1; i > 0; i--) {
- cred->cr_groups[i + 2] = cred->cr_groups[i];
- }
- cred->cr_ngroups += 2;
+ } else
+ cred = crcopy(cred);
- } else
- cred = crcopy(cred);
+ cred->cr_groups[1] = pag_part_one;
+ cred->cr_groups[2] = pag_part_two++;
- cred->cr_groups[1] = pag_part_one;
- cred->cr_groups[2] = pag_part_two++;
+ if (pag_part_two > XFS_PAG2_ULIM) {
+ pag_part_one++;
+ pag_part_two = XFS_PAG2_LLIM;
+ }
+ *ret_cred = cred;
- if (pag_part_two > XFS_PAG2_ULIM) {
- pag_part_one++;
- pag_part_two = XFS_PAG2_LLIM;
- }
- *ret_cred = cred;
- return 0;
+ return 0;
}
#ifdef ACTUALLY_LKM_NOT_KERNEL
@@ -158,21 +157,21 @@ xfs_setpag_call(struct ucred **ret_cred)
#define syscallarg(x) union { x datum; register_t pad; }
struct sys_xfspioctl_args {
- syscallarg(int) operation;
- syscallarg(char *) a_pathP;
- syscallarg(int) a_opcode;
- syscallarg(struct ViceIoctl *) a_paramsP;
- syscallarg(int) a_followSymlinks;
+ syscallarg(int) operation;
+ syscallarg(char *) a_pathP;
+ syscallarg(int) a_opcode;
+ syscallarg(struct ViceIoctl *) a_paramsP;
+ syscallarg(int) a_followSymlinks;
};
#elif defined(__FreeBSD__)
struct sys_xfspioctl_args {
- int operation;
- char *a_pathP;
- int a_opcode;
- struct ViceIoctl *a_paramsP;
- int a_followSymlinks;
+ int operation;
+ char *a_pathP;
+ int a_opcode;
+ struct ViceIoctl *a_paramsP;
+ int a_followSymlinks;
};
#ifndef SCARG
@@ -180,106 +179,104 @@ struct sys_xfspioctl_args {
#endif
#endif
-#endif
+#endif /* ACTUALLY_LKM_NOT_KERNEL */
static int
xfs_pioctl_call(struct proc *p, void *v, int *i)
{
- int error;
- struct ViceIoctl vice_ioctl;
- struct xfs_message_pioctl msg;
- struct xfs_message_wakeup_data *msg2;
- char *pathptr;
+ int error;
+ struct ViceIoctl vice_ioctl;
+ struct xfs_message_pioctl msg;
+ struct xfs_message_wakeup_data *msg2;
+ char *pathptr;
- struct sys_xfspioctl_args *arg = (struct sys_xfspioctl_args *) v;
+ struct sys_xfspioctl_args *arg = (struct sys_xfspioctl_args *) v;
- /* Copy in the data structure for us */
-
- error = copyin(SCARG(arg, a_paramsP),
- &vice_ioctl,
- sizeof(vice_ioctl));
-
- if (error)
- return error;
-
- if (vice_ioctl.in_size > 2048) {
- printf("xfs_pioctl_call: got a humongous in packet: opcode: %d",
- SCARG(arg, a_opcode));
- return EINVAL;
- }
- if (vice_ioctl.in_size != 0) {
- error = copyin(vice_ioctl.in,
- &msg.msg,
- vice_ioctl.in_size);
+ /* Copy in the data structure for us */
+ error = copyin(SCARG(arg, a_paramsP),
+ &vice_ioctl,
+ sizeof(vice_ioctl));
if (error)
- return error;
- }
-
- pathptr = SCARG(arg, a_pathP);
-
- if (pathptr != NULL) {
- char path[MAXPATHLEN];
- struct xfs_node *xn;
- struct nameidata nd;
- struct vnode *vp;
- size_t done;
+ return error;
- XFSDEB(XDEBSYS, ("xfs_syscall: looking up: %p\n", pathptr));
-
- error = copyinstr(pathptr, path, MAXPATHLEN, &done);
+ if (vice_ioctl.in_size > 2048) {
+ printf("xfs_pioctl_call: got a humongous inpacket: opcode: %d",
+ SCARG(arg, a_opcode));
+ return EINVAL;
+ }
+ if (vice_ioctl.in_size != 0) {
+ error = copyin(vice_ioctl.in,
+ &msg.msg,
+ vice_ioctl.in_size);
- XFSDEB(XDEBSYS, ("xfs_syscall: looking up: %s len: %d error: %d\n",
- path, done, error));
+ if (error)
+ return error;
+ }
- if (error)
- return error;
+ pathptr = SCARG(arg, a_pathP);
- NDINIT(&nd, LOOKUP,
- SCARG(arg, a_followSymlinks) ? FOLLOW : 0,
- UIO_SYSSPACE, path, p);
+ if (pathptr != NULL) {
+ char path[MAXPATHLEN];
+ struct xfs_node *xn;
+ struct nameidata nd;
+ struct vnode *vp;
+ size_t done;
- error = namei(&nd);
-
- if (error != 0) {
- XFSDEB(XDEBSYS, ("xfs_syscall: error during namei: %d\n", error));
- return EINVAL;
- }
+ XFSDEB(XDEBSYS, ("xfs_syscall: looking up: %p\n", pathptr));
- vp = nd.ni_vp;
+ error = copyinstr(pathptr, path, sizeof(path) - 1, &done);
+ path[sizeof(path) - 1] = '\0';
+ XFSDEB(XDEBSYS, ("xfs_syscall: path: %s len: %d error: %d\n",
+ path, done, error));
- if (vp->v_tag != VT_AFS) {
- XFSDEB(XDEBSYS, ("xfs_syscall: %s not in afs\n", path));
- vrele(vp);
- return EINVAL;
- }
+ if (error)
+ return error;
- xn = VNODE_TO_XNODE(vp);
+ NDINIT(&nd, LOOKUP,
+ SCARG(arg, a_followSymlinks) ? FOLLOW : 0,
+ UIO_SYSSPACE, path, p);
- msg.handle = xn->handle;
- vrele(vp);
- }
+ error = namei(&nd);
+ if (error != 0) {
+ XFSDEB(XDEBSYS, ("xfs_syscall: error in namei: %d\n",
+ error));
+ return EINVAL;
+ }
- msg.header.opcode = XFS_MSG_PIOCTL;
- msg.opcode = SCARG(arg, a_opcode);
+ vp = nd.ni_vp;
- msg.insize = vice_ioctl.in_size;
- msg.outsize = vice_ioctl.out_size;
- msg.cred.uid = p->p_cred->p_ruid;
- msg.cred.pag = xfs_get_pag(p->p_ucred);
+ if (vp->v_tag != VT_AFS) {
+ XFSDEB(XDEBSYS, ("xfs_syscall: %s not in afs\n",
+ path));
+ vrele(vp);
+ return EINVAL;
+ }
- error = xfs_message_rpc(0, &msg.header, sizeof(msg)); /* XXX */
- msg2 = (struct xfs_message_wakeup_data *) &msg;
+ xn = VNODE_TO_XNODE(vp);
- if (error == 0)
- error = msg2->error;
- else
- error = EINVAL; /* return EINVAL to not confuse applications */
+ msg.handle = xn->handle;
+ vrele(vp);
+ }
- if (error == 0 && msg2->header.opcode == XFS_MSG_WAKEUP_DATA)
- error = copyout(msg2->msg, vice_ioctl.out,
- min(msg2->len, vice_ioctl.out_size));
- return error;
+ msg.header.opcode = XFS_MSG_PIOCTL;
+ msg.opcode = SCARG(arg, a_opcode);
+ msg.insize = vice_ioctl.in_size;
+ msg.outsize = vice_ioctl.out_size;
+ msg.cred.uid = p->p_cred->p_ruid;
+ msg.cred.pag = xfs_get_pag(p->p_ucred);
+
+ error = xfs_message_rpc(0, &msg.header, sizeof(msg)); /* XXX */
+ msg2 = (struct xfs_message_wakeup_data *) &msg;
+ if (error == 0)
+ error = msg2->error;
+ else
+ error = EINVAL; /* return EINVAL to not confuse applications */
+
+ if (error == 0 && msg2->header.opcode == XFS_MSG_WAKEUP_DATA)
+ error = copyout(msg2->msg, vice_ioctl.out,
+ min(msg2->len, vice_ioctl.out_size));
+ return error;
}
@@ -291,23 +288,23 @@ int
sys_xfspioctl(struct proc *p, void *v, int *i)
#endif
{
- struct sys_xfspioctl_args *arg = (struct sys_xfspioctl_args *) v;
- int error = EINVAL;
-
- switch (SCARG(arg, operation)) {
- case AFSCALL_PIOCTL:
- error = xfs_pioctl_call(p, v, i);
- break;
- case AFSCALL_SETPAG:
- error = xfs_setpag_call(&p->p_cred->pc_ucred);
- break;
- default:
- uprintf("Unimplemeted call: %d\n", SCARG(arg, operation));
- error = EINVAL;
- break;
- }
-
- return error;
+ struct sys_xfspioctl_args *arg = (struct sys_xfspioctl_args *) v;
+ int error = EINVAL;
+
+ switch (SCARG(arg, operation)) {
+ case AFSCALL_PIOCTL:
+ error = xfs_pioctl_call(p, v, i);
+ break;
+ case AFSCALL_SETPAG:
+ error = xfs_setpag_call(&p->p_cred->pc_ucred);
+ break;
+ default:
+ uprintf("Unimplemeted call: %d\n", SCARG(arg, operation));
+ error = EINVAL;
+ break;
+ }
+
+ return error;
}
#ifdef ACTUALLY_LKM_NOT_KERNEL
@@ -317,64 +314,65 @@ static int syscall_offset;
static struct sysent syscall_oldent;
static struct sysent xfs_syscallent = {
- 4, /* number of args */
- sizeof(struct sys_xfspioctl_args), /* size of args */
- xfs_syscall /* function pointer */
+ 4, /* number of args */
+ sizeof(struct sys_xfspioctl_args), /* size of args */
+ xfs_syscall /* function pointer */
};
static int
find_first_free_syscall(int *ret)
{
- int i;
-
- /*
- * Search the table looking for a slot...
- */
- for (i = 0; i < SYS_MAXSYSCALL; i++)
- if (sysent[i].sy_call == sys_lkmnosys) {
- *ret = i;
- return 0;
- }
- return ENFILE;
+ int i;
+
+ /*
+ * Search the table looking for a slot...
+ */
+ for (i = 0; i < SYS_MAXSYSCALL; i++)
+ if (sysent[i].sy_call == sys_lkmnosys) {
+ *ret = i;
+ return 0;
+ }
+
+ return ENFILE;
}
int
xfs_install_syscalls(void)
{
- int error;
+ int error;
#ifdef AFS_SYSCALL
- syscall_offset = AFS_SYSCALL;
+ syscall_offset = AFS_SYSCALL;
#else
- error = find_first_free_syscall(&syscall_offset);
- if (error)
- return error;
+ error = find_first_free_syscall(&syscall_offset);
+ if (error)
+ return error;
#endif
- syscall_oldent = sysent[syscall_offset];
+ syscall_oldent = sysent[syscall_offset];
- /* replace with new */
+ /* replace with new */
- sysent[syscall_offset] = xfs_syscallent;
+ sysent[syscall_offset] = xfs_syscallent;
- printf("syscall %d\n", syscall_offset);
- return 0;
+ printf("syscall %d\n", syscall_offset);
+ return 0;
}
int
xfs_uninstall_syscalls(void)
{
- /* replace current slot contents with old contents */
- if (syscall_offset)
- sysent[syscall_offset] = syscall_oldent;
+ /* replace current slot contents with old contents */
+ if (syscall_offset)
+ sysent[syscall_offset] = syscall_oldent;
- return 0;
+ return 0;
}
int
xfs_stat_syscalls(void)
{
- return 0;
+ return 0;
}
#elif defined(__FreeBSD__)
@@ -383,56 +381,60 @@ static int syscall_offset;
static struct sysent syscall_oldent;
static struct sysent xfs_syscallent = {
- 4,
- xfs_syscall
+ 4,
+ xfs_syscall
};
static int
find_first_free_syscall(int *ret)
{
- int i;
-
- /*
- * Search the table looking for a slot...
- */
- for (i = 0; i < aout_sysvec.sv_size; i++)
- if (aout_sysvec.sv_table[i].sy_call == (sy_call_t *) lkmnosys) {
- *ret = i;
- return 0;
- }
- return ENFILE;
+ int i;
+
+ /*
+ * Search the table looking for a slot...
+ */
+ for (i = 0; i < aout_sysvec.sv_size; i++)
+ if (aout_sysvec.sv_table[i].sy_call ==
+ (sy_call_t *) lkmnosys) {
+ *ret = i;
+ return 0;
+ }
+
+ return ENFILE;
}
int
xfs_install_syscalls(void)
{
- int i;
- int error;
+ int i;
+ int error;
#ifdef AFS_SYSCALL
- i = AFS_SYSCALL;
+ i = AFS_SYSCALL;
#else
- error = find_first_free_syscall(&i);
- if (error)
- return error;
+ error = find_first_free_syscall(&i);
+ if (error)
+ return error;
#endif
- syscall_oldent = aout_sysvec.sv_table[i];
+ syscall_oldent = aout_sysvec.sv_table[i];
- aout_sysvec.sv_table[i] = xfs_syscallent;
+ aout_sysvec.sv_table[i] = xfs_syscallent;
- syscall_offset = i;
- printf("syscall %d\n", i);
- return 0;
+ syscall_offset = i;
+ printf("syscall %d\n", i);
+
+ return 0;
}
int
xfs_uninstall_syscalls(void)
{
- if (syscall_offset) {
- aout_sysvec.sv_table[syscall_offset].sy_call = (sy_call_t *) lkmnosys;
- }
- return 0;
+ if (syscall_offset) {
+ aout_sysvec.sv_table[syscall_offset].sy_call =
+ (sy_call_t *) lkmnosys;
+ }
+ return 0;
}
int