kfile.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
The EFI kernel's interpretation of a "file".
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* 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
* 3. 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.
*
* file.h 8.3 (Berkeley) 1/9/95
NetBSD: file.h,v 1.56 2006/05/14 21:38:18 elad Exp
**/
#ifndef _PIF_KFILE_H_
#define _PIF_KFILE_H_
#include <Uefi.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/SimpleFileSystem.h>
#include <wchar.h>
#include <stdarg.h>
struct stat;
struct fileops;
struct _Device_Node;
/* The number of "special" character stream devices.
These include:
stdin, stdout, stderr
*/
#define NUM_SPECIAL 3
/* Organization of the f_iflags member of the __filedes structure. */
/*
This structure must be a multiple of 8 bytes in length.
*/
struct __filedes {
void *devdata; /* Device-specific data */
int Oflags; // From the open call
int Omode; // From the open call
int RefCount; // Reference count of opens
};
struct fileops {
/* These functions must always be implemented. */
/* Call the fnullop_* version of these functions if not implemented by the device. */
/* Call the fbadop_* version of these functions if not implemented by the device. */
/* Use a NULL if this function has not been implemented by the device. */
};
/* A generic instance structure which is valid for
for all device instance structures.
All device instance structures MUST be a multiple of 8-bytes in length.
*/
typedef struct {
/* Type of all Device-specific handler's open routines. */
typedef
(FIF_WANTCLOSE|FIF_LARVAL)) == 0)
#define FILE_SET_MATURE(fp) \
do { \
} while (/*CONSTCOND*/0)
/*
* Flags for fo_read and fo_write.
*/
/* Commonly used fileops
fnullop_* Does nothing and returns success.
fbadop_* Does nothing and returns EPERM
*/
/* From the original file... */
#if 0
//struct proc;
//struct lwp;
//struct uio;
//struct iovec;
//struct knote;
//LIST_HEAD(filelist, file);
//extern struct filelist filehead; /* head of list of open files */
//extern int maxfiles; /* kernel limit on # of open files */
//extern int nfiles; /* actual number of open files */
//extern const struct fileops vnops; /* vnode operations for files */
struct fileops {
};
/*
* Kernel descriptor table.
* One entry for each open kernel vnode and socket.
*/
struct file {
void *f_DevDesc; /* Device Descriptor pointer */
int f_advice; /* access pattern hint; UVM_ADV_* */
int f_type; /* descriptor type */
int f_usecount; /* number active users */
// kauth_cred_t f_cred; /* creds associated with descriptor */
struct simplelock f_slock;
};
#ifdef DIAGNOSTIC
do { \
if ((fp)->f_usecount < 0) \
} while (/* CONSTCOND */ 0)
#else
#endif
/*
* FILE_USE() must be called with the file lock held.
* (Typical usage is: `fp = fd_getfile(..); FILE_USE(fp);'
* and fd_getfile() returns the file locked)
*
* fp is a pointer to a __filedes structure.
*/
do { \
(fp)->f_usecount++; \
} while (/* CONSTCOND */ 0)
do { \
if (!(havelock)) \
/* Will drop usecount */ \
break; \
} else { \
(fp)->f_usecount--; \
} \
} while (/* CONSTCOND */ 0)
//int dofileread (struct lwp *, int, struct file *, void *, size_t, off_t *, int, register_t *);
//int dofilewrite (struct lwp *, int, struct file *, const void *, size_t, off_t *, int, register_t *);
//int dofilereadv (struct lwp *, int, struct file *, const struct iovec *, int, off_t *, int, register_t *);
//int dofilewritev(struct lwp *, int, struct file *, const struct iovec *, int, off_t *, int, register_t *);
//int fsetown (struct proc *, pid_t *, int, const void *);
//int fgetown (struct proc *, pid_t, int, void *);
//void fownsignal (pid_t, int, int, int, void *);
//int fdclone (struct lwp *, struct file *, int, int, const struct fileops *, void *);
/* Commonly used fileops
fnullop_* Does nothing and returns success.
fbadop_* Does nothing and returns EPERM
*/
//int fnullop_fcntl (struct file *, u_int, void *, struct lwp *);
//int fnullop_poll (struct file *, int, struct lwp *);
//int fnullop_kqfilter(struct file *, struct knote *);
//int fbadop_stat (struct file *, struct stat *, struct lwp *);
//int fbadop_ioctl (struct file *, u_long, void *, struct lwp *);
#endif
#endif /* _PIF_KFILE_H_ */