-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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);
- return fp;
+ fp->f_flags = FFLAGS(uflags);
+ fp->f_ctxt = vfs_context_create(NULL);
+
+ 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();
{
int f;
- f = flags & O_ACCMODE;
+ f = flags & O_NOACCESS;
f |= (flags & O_CREAT) ? CFS_O_CREAT: 0;
f |= (flags & O_TRUNC) ? CFS_O_TRUNC: 0;
f |= (flags & O_EXCL) ? CFS_O_EXCL: 0;