epoc32/include/stdapis/sys/file.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@4
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@4
     3
* All rights reserved.
williamr@4
     4
* This component and the accompanying materials are made available
williamr@4
     5
* under the terms of "Eclipse Public License v1.0"
williamr@4
     6
* which accompanies this distribution, and is available
williamr@4
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     8
*
williamr@4
     9
* Initial Contributors:
williamr@4
    10
* Nokia Corporation - initial contribution.
williamr@4
    11
*
williamr@4
    12
* Contributors:
williamr@4
    13
*
williamr@4
    14
* Description: 
williamr@2
    15
*
williamr@2
    16
*/
williamr@2
    17
williamr@2
    18
williamr@4
    19
williamr@2
    20
#ifndef _SYS_FILE_H_
williamr@2
    21
#define	_SYS_FILE_H_
williamr@2
    22
williamr@2
    23
#ifndef _KERNEL
williamr@2
    24
#include <sys/types.h> /* XXX */
williamr@2
    25
#include <sys/fcntl.h>
williamr@2
    26
#include <sys/unistd.h>
williamr@2
    27
#else
williamr@2
    28
#include <sys/queue.h>
williamr@2
    29
#include <sys/_lock.h>
williamr@2
    30
#include <sys/_mutex.h>
williamr@2
    31
williamr@2
    32
struct stat;
williamr@2
    33
struct thread;
williamr@2
    34
struct uio;
williamr@2
    35
struct knote;
williamr@2
    36
struct vnode;
williamr@2
    37
struct socket;
williamr@2
    38
williamr@2
    39
williamr@2
    40
#endif /* _KERNEL */
williamr@2
    41
williamr@2
    42
#define	DTYPE_VNODE	1	/* file */
williamr@2
    43
#define	DTYPE_SOCKET	2	/* communications endpoint */
williamr@2
    44
#define	DTYPE_PIPE	3	/* pipe */
williamr@2
    45
#define	DTYPE_FIFO	4	/* fifo (named pipe) */
williamr@2
    46
#define	DTYPE_KQUEUE	5	/* event queue */
williamr@2
    47
#define	DTYPE_CRYPTO	6	/* crypto */
williamr@2
    48
williamr@2
    49
#ifdef _KERNEL
williamr@2
    50
williamr@2
    51
struct file;
williamr@2
    52
struct ucred;
williamr@2
    53
williamr@2
    54
typedef int fo_rdwr_t(struct file *fp, struct uio *uio,
williamr@2
    55
		    struct ucred *active_cred, int flags,
williamr@2
    56
		    struct thread *td);
williamr@2
    57
#define	FOF_OFFSET	1	/* Use the offset in uio argument */
williamr@2
    58
typedef	int fo_ioctl_t(struct file *fp, u_long com, void *data,
williamr@2
    59
		    struct ucred *active_cred, struct thread *td);
williamr@2
    60
typedef	int fo_poll_t(struct file *fp, int events,
williamr@2
    61
		    struct ucred *active_cred, struct thread *td);
williamr@2
    62
typedef	int fo_kqfilter_t(struct file *fp, struct knote *kn);
williamr@2
    63
typedef	int fo_stat_t(struct file *fp, struct stat *sb,
williamr@2
    64
		    struct ucred *active_cred, struct thread *td);
williamr@2
    65
typedef	int fo_close_t(struct file *fp, struct thread *td);
williamr@2
    66
typedef	int fo_flags_t;
williamr@2
    67
williamr@2
    68
struct fileops {
williamr@2
    69
	fo_rdwr_t	*fo_read;
williamr@2
    70
	fo_rdwr_t	*fo_write;
williamr@2
    71
	fo_ioctl_t	*fo_ioctl;
williamr@2
    72
	fo_poll_t	*fo_poll;
williamr@2
    73
	fo_kqfilter_t	*fo_kqfilter;
williamr@2
    74
	fo_stat_t	*fo_stat;
williamr@2
    75
	fo_close_t	*fo_close;
williamr@2
    76
	fo_flags_t	fo_flags;	/* DFLAG_* below */
williamr@2
    77
};
williamr@2
    78
williamr@2
    79
#define DFLAG_PASSABLE	0x01	/* may be passed via unix sockets. */
williamr@2
    80
#define DFLAG_SEEKABLE	0x02	/* seekable / nonsequential */
williamr@2
    81
williamr@2
    82
/*
williamr@2
    83
 * Kernel descriptor table.
williamr@2
    84
 * One entry for each open kernel vnode and socket.
williamr@2
    85
 *
williamr@2
    86
 * Below is the list of locks that protects members in struct file.
williamr@2
    87
 *
williamr@2
    88
 * (fl)	filelist_lock
williamr@2
    89
 * (f)	f_mtx in struct file
williamr@2
    90
 * none	not locked
williamr@2
    91
 */
williamr@2
    92
williamr@2
    93
struct file {
williamr@2
    94
	LIST_ENTRY(file) f_list;/* (fl) list of active files */
williamr@2
    95
	short	f_type;		/* descriptor type */
williamr@2
    96
	void	*f_data;	/* file descriptor specific data */
williamr@2
    97
	u_int	f_flag;		/* see fcntl.h */
williamr@2
    98
	struct mtx	*f_mtxp;	/* mutex to protect data */
williamr@2
    99
	struct fileops *f_ops;	/* File operations */
williamr@2
   100
	struct	ucred *f_cred;	/* credentials associated with descriptor */
williamr@2
   101
	int	f_count;	/* (f) reference count */
williamr@2
   102
	struct vnode *f_vnode;	/* NULL or applicable vnode */
williamr@2
   103
williamr@2
   104
	/* DFLAG_SEEKABLE specific fields */
williamr@2
   105
	off_t	f_offset;
williamr@2
   106
williamr@2
   107
	/* DTYPE_SOCKET specific fields */
williamr@2
   108
	short	f_gcflag;	/* used by thread doing fd garbage collection */
williamr@2
   109
#define	FMARK		0x1	/* mark during gc() */
williamr@2
   110
#define	FDEFER		0x2	/* defer for next gc pass */
williamr@2
   111
	int	f_msgcount;	/* (f) references from message queue */
williamr@2
   112
williamr@2
   113
	/* DTYPE_VNODE specific fields */
williamr@2
   114
	int	f_seqcount;	/*
williamr@2
   115
				 * count of sequential accesses -- cleared
williamr@2
   116
				 * by most seek operations.
williamr@2
   117
				 */
williamr@2
   118
	off_t	f_nextoff;	/*
williamr@2
   119
				 * offset of next expected read or write
williamr@2
   120
				 */
williamr@2
   121
	void	*f_label;	/* Place-holder for struct label pointer. */
williamr@2
   122
};
williamr@2
   123
williamr@2
   124
#endif /* _KERNEL */
williamr@2
   125
williamr@2
   126
/*
williamr@2
   127
 * Userland version of struct file, for sysctl
williamr@2
   128
 */
williamr@2
   129
struct xfile {
williamr@2
   130
	size_t	xf_size;	/* size of struct xfile */
williamr@2
   131
	pid_t	xf_pid;		/* owning process */
williamr@2
   132
	uid_t	xf_uid;		/* effective uid of owning process */
williamr@2
   133
	int	xf_fd;		/* descriptor number */
williamr@2
   134
	void	*xf_file;	/* address of struct file */
williamr@2
   135
	short	xf_type;	/* descriptor type */
williamr@2
   136
	int	xf_count;	/* reference count */
williamr@2
   137
	int	xf_msgcount;	/* references from message queue */
williamr@2
   138
	off_t	xf_offset;	/* file offset */
williamr@2
   139
	void	*xf_data;	/* file descriptor specific data */
williamr@2
   140
	void	*xf_vnode;	/* vnode pointer */
williamr@2
   141
	u_int	xf_flag;	/* flags (see fcntl.h) */
williamr@2
   142
};
williamr@2
   143
williamr@2
   144
#ifdef _KERNEL
williamr@2
   145
extern struct filelist filehead; /* (fl) head of list of open files */
williamr@2
   146
extern struct fileops vnops;
williamr@2
   147
extern struct fileops badfileops;
williamr@2
   148
extern struct fileops socketops;
williamr@2
   149
extern int maxfiles;		/* kernel limit on number of open files */
williamr@2
   150
extern int maxfilesperproc;	/* per process limit on number of open files */
williamr@2
   151
extern int openfiles;		/* (fl) actual number of open files */
williamr@2
   152
extern struct sx filelist_lock; /* sx to protect filelist and openfiles */
williamr@2
   153
williamr@2
   154
/*
williamr@2
   155
 * The socket operations are used a couple of places.
williamr@2
   156
 * XXX: This is wrong, they should go through the operations vector for
williamr@2
   157
 * XXX: sockets instead of going directly for the individual functions. /phk
williamr@2
   158
 */
williamr@2
   159
fo_rdwr_t	soo_read;
williamr@2
   160
fo_rdwr_t	soo_write;
williamr@2
   161
fo_ioctl_t	soo_ioctl;
williamr@2
   162
fo_poll_t	soo_poll;
williamr@2
   163
fo_kqfilter_t	soo_kqfilter;
williamr@2
   164
fo_stat_t	soo_stat;
williamr@2
   165
fo_close_t	soo_close;
williamr@2
   166
williamr@2
   167
/* Lock a file. */
williamr@2
   168
#define	FILE_LOCK(f)	mtx_lock((f)->f_mtxp)
williamr@2
   169
#define	FILE_UNLOCK(f)	mtx_unlock((f)->f_mtxp)
williamr@2
   170
#define	FILE_LOCKED(f)	mtx_owned((f)->f_mtxp)
williamr@2
   171
#define	FILE_LOCK_ASSERT(f, type) mtx_assert((f)->f_mtxp, (type))
williamr@2
   172
williamr@2
   173
#define	fhold_locked(fp)						\
williamr@2
   174
	do {								\
williamr@2
   175
		FILE_LOCK_ASSERT(fp, MA_OWNED);				\
williamr@2
   176
		(fp)->f_count++;					\
williamr@2
   177
	} while (0)
williamr@2
   178
williamr@2
   179
#define	fhold(fp)							\
williamr@2
   180
	do {								\
williamr@2
   181
		FILE_LOCK(fp);						\
williamr@2
   182
		(fp)->f_count++;					\
williamr@2
   183
		FILE_UNLOCK(fp);					\
williamr@2
   184
	} while (0)
williamr@2
   185
williamr@2
   186
static __inline fo_rdwr_t	fo_read;
williamr@2
   187
static __inline fo_rdwr_t	fo_write;
williamr@2
   188
static __inline fo_ioctl_t	fo_ioctl;
williamr@2
   189
static __inline fo_poll_t	fo_poll;
williamr@2
   190
static __inline fo_kqfilter_t	fo_kqfilter;
williamr@2
   191
static __inline fo_stat_t	fo_stat;
williamr@2
   192
static __inline fo_close_t	fo_close;
williamr@2
   193
williamr@2
   194
static __inline int
williamr@2
   195
fo_read(fp, uio, active_cred, flags, td)
williamr@2
   196
	struct file *fp;
williamr@2
   197
	struct uio *uio;
williamr@2
   198
	struct ucred *active_cred;
williamr@2
   199
	int flags;
williamr@2
   200
	struct thread *td;
williamr@2
   201
{
williamr@2
   202
williamr@2
   203
	return ((*fp->f_ops->fo_read)(fp, uio, active_cred, flags, td));
williamr@2
   204
}
williamr@2
   205
williamr@2
   206
static __inline int
williamr@2
   207
fo_write(fp, uio, active_cred, flags, td)
williamr@2
   208
	struct file *fp;
williamr@2
   209
	struct uio *uio;
williamr@2
   210
	struct ucred *active_cred;
williamr@2
   211
	int flags;
williamr@2
   212
	struct thread *td;
williamr@2
   213
{
williamr@2
   214
williamr@2
   215
	return ((*fp->f_ops->fo_write)(fp, uio, active_cred, flags, td));
williamr@2
   216
}
williamr@2
   217
williamr@2
   218
static __inline int
williamr@2
   219
fo_ioctl(fp, com, data, active_cred, td)
williamr@2
   220
	struct file *fp;
williamr@2
   221
	u_long com;
williamr@2
   222
	void *data;
williamr@2
   223
	struct ucred *active_cred;
williamr@2
   224
	struct thread *td;
williamr@2
   225
{
williamr@2
   226
williamr@2
   227
	return ((*fp->f_ops->fo_ioctl)(fp, com, data, active_cred, td));
williamr@2
   228
}
williamr@2
   229
williamr@2
   230
static __inline int
williamr@2
   231
fo_poll(fp, events, active_cred, td)
williamr@2
   232
	struct file *fp;
williamr@2
   233
	int events;
williamr@2
   234
	struct ucred *active_cred;
williamr@2
   235
	struct thread *td;
williamr@2
   236
{
williamr@2
   237
williamr@2
   238
	return ((*fp->f_ops->fo_poll)(fp, events, active_cred, td));
williamr@2
   239
}
williamr@2
   240
williamr@2
   241
static __inline int
williamr@2
   242
fo_stat(fp, sb, active_cred, td)
williamr@2
   243
	struct file *fp;
williamr@2
   244
	struct stat *sb;
williamr@2
   245
	struct ucred *active_cred;
williamr@2
   246
	struct thread *td;
williamr@2
   247
{
williamr@2
   248
williamr@2
   249
	return ((*fp->f_ops->fo_stat)(fp, sb, active_cred, td));
williamr@2
   250
}
williamr@2
   251
williamr@2
   252
static __inline int
williamr@2
   253
fo_close(fp, td)
williamr@2
   254
	struct file *fp;
williamr@2
   255
	struct thread *td;
williamr@2
   256
{
williamr@2
   257
williamr@2
   258
	return ((*fp->f_ops->fo_close)(fp, td));
williamr@2
   259
}
williamr@2
   260
williamr@2
   261
static __inline int
williamr@2
   262
fo_kqfilter(fp, kn)
williamr@2
   263
	struct file *fp;
williamr@2
   264
	struct knote *kn;
williamr@2
   265
{
williamr@2
   266
williamr@2
   267
	return ((*fp->f_ops->fo_kqfilter)(fp, kn));
williamr@2
   268
}
williamr@2
   269
williamr@2
   270
#endif /* _KERNEL */
williamr@2
   271
williamr@2
   272
#endif /* !SYS_FILE_H */