-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
- * Copyright (C) 2002 Cluster File Systems, Inc.
- * Author: Phil Schwan <phil@clusterfs.com>
+/*
+ * GPL HEADER START
*
- * This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Lustre is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * Lustre is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU General Public License
- * along with Lustre; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * libcfs/libcfs/darwin/darwin-fs.c
*
* Darwin porting library
* Make things easy to port
+ *
+ * Author: Phil Schwan <phil@clusterfs.com>
*/
+
#include <mach/mach_types.h>
#include <string.h>
#include <sys/file.h>
#define DEBUG_SUBSYSTEM S_LNET
#include <libcfs/libcfs.h>
-#include <libcfs/kp30.h>
/*
* Kernel APIs for file system in xnu
* not so important to implement for MT.
*/
int
-kern_file_size(struct cfs_kern_file *fp, off_t *psize)
+kern_file_size(struct cfs_kern_file *fp, off_t *psize)
{
- int error;
- off_t size;
+ int error;
+ off_t size;
- error = vnode_size(fp->f_vp, &size, fp->f_ctxt);
- if (error)
- return error;
+ error = vnode_size(fp->f_vp, &size, fp->f_ctxt);
+ if (error)
+ return error;
- if (psize)
- *psize = size;
- return 0;
+ if (psize)
+ *psize = size;
+ return 0;
}
struct cfs_kern_file *
-kern_file_open(const char * filename, int uflags, int mode, int *err)
+kern_file_open(const char *filename, int uflags, int mode)
{
- struct cfs_kern_file *fp;
- vnode_t vp;
- int error;
-
- fp = (struct cfs_kern_file *)_MALLOC(sizeof(struct cfs_kern_file), M_TEMP, M_WAITOK);
- if (fp == NULL) {
- if (err != NULL)
- *err = -ENOMEM;
- return NULL;
- }
- fp->f_flags = FFLAGS(uflags);
- fp->f_ctxt = vfs_context_create(NULL);
-
- if ((error = vnode_open(filename, fp->f_flags,
- mode, 0, &vp, fp->f_ctxt))){
- if (err != NULL)
- *err = -error;
- _FREE(fp, M_TEMP);
- } else {
- if (err != NULL)
- *err = 0;
- fp->f_vp = vp;
- }
+ struct cfs_kern_file *fp;
+ vnode_t vp;
+ int error;
+
+ fp = (struct cfs_kern_file *)_MALLOC(sizeof(struct cfs_kern_file),
+ M_TEMP, M_WAITOK);
+ if (fp == NULL)
+ return ERR_PTR(-ENOMEM);
+
+ fp->f_flags = FFLAGS(uflags);
+ fp->f_ctxt = vfs_context_create(NULL);
- return fp;
+ error = vnode_open(filename, fp->f_flags, mode, 0, &vp, fp->f_ctxt);
+ if (error != 0) {
+ _FREE(fp, M_TEMP);
+ return ERR_PTR(-error);
+ } else {
+ fp->f_vp = vp;
+ }
+
+ return fp;
}
int
return 0;
}
-cfs_file_t *
-kern_file_open(const char * filename, int flags, int mode, int *err)
+struct file *
+kern_file_open(const char *filename, int flags, int mode)
{
- struct nameidata nd;
- cfs_file_t *fp;
+ struct nameidata nd;
+ struct file *fp;
register struct vnode *vp;
int rc;
extern struct fileops vnops;
extern int nfiles;
- CFS_DECL_CONE_DATA;
+ CFS_DECL_CONE_DATA;
- CFS_CONE_IN;
+ CFS_CONE_IN;
nfiles++;
- MALLOC_ZONE(fp, cfs_file_t *, sizeof(cfs_file_t), M_FILE, M_WAITOK|M_ZERO);
- bzero(fp, sizeof(cfs_file_t));
+ MALLOC_ZONE(fp, struct file *, sizeof(file_t), M_FILE, M_WAITOK|M_ZERO);
+ bzero(fp, sizeof(*fp));
fp->f_count = 1;
- LIST_CIRCLE(fp, f_list);
+ LIST_CIRCLE(fp, f_list);
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, (char *)filename, current_proc());
if ((rc = vn_open(&nd, flags, mode)) != 0){
- printf("filp_open failed at (%d)\n", rc);
- if (err != NULL)
- *err = rc;
- FREE_ZONE(fp, sizeof *fp, M_FILE);
- CFS_CONE_EX;
- return NULL;
+ printf("filp_open failed at (%d)\n", rc);
+ FREE_ZONE(fp, sizeof(*fp), M_FILE);
+ CFS_CONE_EX;
+ return ERR_PTR(rc);
}
vp = nd.ni_vp;
fp->f_flag = flags & FMASK;
* we should release the lock before return
*/
VOP_UNLOCK(vp, 0, current_proc());
- CFS_CONE_EX;
+ CFS_CONE_EX;
return fp;
}
static int
-frele_internal(cfs_file_t *fp)
+frele_internal(struct file *fp)
{
if (fp->f_count == (short)0xffff)
panic("frele of lustre: stale");
}
int
-kern_file_close (cfs_file_t *fp)
+kern_file_close(struct file *fp)
{
struct vnode *vp;
- CFS_DECL_CONE_DATA;
+ CFS_DECL_CONE_DATA;
if (fp == NULL)
return 0;
* Write buffer to filp inside kernel
*/
int
-kern_file_write (cfs_file_t *fp, void *buf, size_t nbyte, loff_t *pos)
+kern_file_write(struct file *fp, void *buf, size_t nbyte, loff_t *pos)
{
struct uio auio;
struct iovec aiov;
* Read from filp inside kernel
*/
int
-kern_file_read (cfs_file_t *fp, void *buf, size_t nbyte, loff_t *pos)
+kern_file_read(struct file *fp, void *buf, size_t nbyte, loff_t *pos)
{
struct uio auio;
struct iovec aiov;
}
int
-kern_file_sync (cfs_file_t *fp)
+kern_file_sync(struct file *fp)
{
struct vnode *vp = (struct vnode *)fp->f_data;
struct proc *p = current_proc();
static struct posix_acl acl;
return &acl;
}
-
-/*
- * XXX Liang: I've not converted all of them,
- * more is needed?
- */
-int cfs_oflags2univ(int flags)
-{
- int f;
-
- f = flags & O_ACCMODE;
- f |= (flags & O_CREAT) ? CFS_O_CREAT: 0;
- f |= (flags & O_TRUNC) ? CFS_O_TRUNC: 0;
- f |= (flags & O_EXCL) ? CFS_O_EXCL: 0;
- f |= (flags & O_NONBLOCK) ? CFS_O_NONBLOCK: 0;
- f |= (flags & O_APPEND) ? CFS_O_APPEND: 0;
- f |= (flags & O_NOFOLLOW) ? CFS_O_NOFOLLOW: 0;
- f |= (flags & O_SYNC)? CFS_O_SYNC: 0;
- return f;
-}
-
-/*
- * XXX Liang: we don't need it in OSX.
- * But it should be implemented anyway.
- */
-int cfs_univ2oflags(int flags)
-{
- return flags;
-}