blob: a4e8c7aaebd71393d6149673666bd36ed304e57d [file] [log] [blame]
Alexandre Julliard863637b2003-01-30 00:26:44 +00001/*
2 * Server-side file definitions
3 *
4 * Copyright (C) 2003 Alexandre Julliard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __WINE_SERVER_FILE_H
22#define __WINE_SERVER_FILE_H
23
24#include "object.h"
25
26struct fd;
27
Alexandre Julliardce613492003-03-18 05:04:33 +000028typedef unsigned __int64 file_pos_t;
29
Alexandre Julliard863637b2003-01-30 00:26:44 +000030/* operations valid on file descriptor objects */
31struct fd_ops
32{
33 /* get the events we want to poll() for on this object */
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000034 int (*get_poll_events)(struct fd *);
Francois Gouget3ca76122003-07-15 20:53:39 +000035 /* a poll() event occurred */
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000036 void (*poll_event)(struct fd *,int event);
Alexandre Julliard863637b2003-01-30 00:26:44 +000037 /* flush the object buffers */
Mike McCormackef8b9462003-05-15 04:22:45 +000038 int (*flush)(struct fd *, struct event **);
Alexandre Julliard863637b2003-01-30 00:26:44 +000039 /* get file information */
Alexandre Julliard6a27b482004-08-18 00:04:58 +000040 int (*get_file_info)(struct fd *);
Eric Pouech46344472005-01-14 19:54:38 +000041 /* queue an async operation */
42 void (*queue_async)(struct fd *, void* apc, void* user, void* io_sb, int type, int count);
43 /* cancel an async operation */
44 void (*cancel_async)(struct fd *);
Alexandre Julliard863637b2003-01-30 00:26:44 +000045};
46
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000047/* file descriptor functions */
48
Alexandre Julliard580da242003-03-12 22:38:14 +000049extern struct fd *alloc_fd( const struct fd_ops *fd_user_ops, struct object *user );
Alexandre Julliard67505c02005-12-12 14:27:45 +010050extern struct fd *alloc_pseudo_fd( const struct fd_ops *fd_user_ops, struct object *user );
Alexandre Julliard74bd1e42004-03-27 20:48:42 +000051extern struct fd *open_fd( struct fd *fd, const char *name, int flags, mode_t *mode,
Alexandre Julliard684b65c2004-04-16 04:31:35 +000052 unsigned int access, unsigned int sharing, unsigned int options );
Alexandre Julliard580da242003-03-12 22:38:14 +000053extern struct fd *create_anonymous_fd( const struct fd_ops *fd_user_ops,
54 int unix_fd, struct object *user );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000055extern void *get_fd_user( struct fd *fd );
56extern int get_unix_fd( struct fd *fd );
Alexandre Julliard74bd1e42004-03-27 20:48:42 +000057extern int is_same_file_fd( struct fd *fd1, struct fd *fd2 );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000058extern void fd_poll_event( struct fd *fd, int event );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000059extern int check_fd_events( struct fd *fd, int events );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000060extern void set_fd_events( struct fd *fd, int events );
Alexandre Julliardce613492003-03-18 05:04:33 +000061extern obj_handle_t lock_fd( struct fd *fd, file_pos_t offset, file_pos_t count, int shared, int wait );
62extern void unlock_fd( struct fd *fd, file_pos_t offset, file_pos_t count );
Alexandre Julliard863637b2003-01-30 00:26:44 +000063
64extern int default_fd_add_queue( struct object *obj, struct wait_queue_entry *entry );
65extern void default_fd_remove_queue( struct object *obj, struct wait_queue_entry *entry );
66extern int default_fd_signaled( struct object *obj, struct thread *thread );
Robert Shearmand6a4e342005-06-07 20:09:01 +000067extern int default_fd_get_poll_events( struct fd *fd );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000068extern void default_poll_event( struct fd *fd, int event );
Robert Shearman37773dd2005-07-14 12:18:05 +000069extern void fd_queue_async_timeout( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count, int *timeout );
Robert Shearmand6a4e342005-06-07 20:09:01 +000070extern void default_fd_queue_async( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count );
71extern void default_fd_cancel_async( struct fd *fd );
Mike McCormackef8b9462003-05-15 04:22:45 +000072extern int no_flush( struct fd *fd, struct event **event );
Alexandre Julliard6a27b482004-08-18 00:04:58 +000073extern int no_get_file_info( struct fd *fd );
Eric Pouech46344472005-01-14 19:54:38 +000074extern void no_queue_async( struct fd *fd, void* apc, void* user, void* io_sb, int type, int count);
75extern void no_cancel_async( struct fd *fd );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000076extern void main_loop(void);
Mike McCormackcdcb2032005-06-14 11:40:40 +000077extern void remove_process_locks( struct process *process );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000078
79inline static struct fd *get_obj_fd( struct object *obj ) { return obj->ops->get_fd( obj ); }
80
Alexandre Julliarde66207e2003-02-19 00:33:32 +000081/* timeout functions */
82
83struct timeout_user;
84
85typedef void (*timeout_callback)( void *private );
86
Eric Pouech7001d6e2005-03-29 11:40:10 +000087extern struct timeout_user *add_timeout_user( const struct timeval *when,
Alexandre Julliarde66207e2003-02-19 00:33:32 +000088 timeout_callback func, void *private );
89extern void remove_timeout_user( struct timeout_user *user );
90extern void add_timeout( struct timeval *when, int timeout );
91/* return 1 if t1 is before t2 */
Eric Pouech7001d6e2005-03-29 11:40:10 +000092static inline int time_before( const struct timeval *t1, const struct timeval *t2 )
Alexandre Julliarde66207e2003-02-19 00:33:32 +000093{
94 return ((t1->tv_sec < t2->tv_sec) ||
95 ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec < t2->tv_usec)));
96}
97
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000098/* file functions */
99
100extern struct file *get_file_obj( struct process *process, obj_handle_t handle,
101 unsigned int access );
102extern int get_file_unix_fd( struct file *file );
103extern int is_same_file( struct file *file1, struct file *file2 );
Alexandre Julliarda4334a62005-04-19 11:59:13 +0000104extern int grow_file( struct file *file, file_pos_t size );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +0000105extern struct file *create_temp_file( int access );
106extern void file_set_error(void);
Alexandre Julliard863637b2003-01-30 00:26:44 +0000107
Alexandre Julliard3e588e32003-03-26 23:41:43 +0000108/* change notification functions */
109
110extern void do_change_notify( int unix_fd );
111extern void sigio_callback(void);
112
Alexandre Julliardadc06102004-03-18 04:08:48 +0000113/* serial port functions */
114
115extern int is_serial_fd( struct fd *fd );
116extern struct object *create_serial( struct fd *fd, unsigned int options );
117
Eric Pouech46344472005-01-14 19:54:38 +0000118/* async I/O functions */
Eric Pouech7001d6e2005-03-29 11:40:10 +0000119extern struct async *create_async( struct thread *thread, int* timeout,
Alexandre Julliarddd81ac52005-02-24 17:06:31 +0000120 struct list *queue, void *, void *, void *);
121extern void async_terminate_head( struct list *queue, int status );
Eric Pouech46344472005-01-14 19:54:38 +0000122
Alexandre Julliarddd81ac52005-02-24 17:06:31 +0000123static inline void async_terminate_queue( struct list *queue, int status )
Eric Pouech46344472005-01-14 19:54:38 +0000124{
Alexandre Julliarddd81ac52005-02-24 17:06:31 +0000125 while (!list_empty( queue )) async_terminate_head( queue, status );
Eric Pouech46344472005-01-14 19:54:38 +0000126}
127
Alexandre Julliarda510a7e2005-12-12 16:46:17 +0100128/* access rights that require Unix read permission */
129#define FILE_UNIX_READ_ACCESS (FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA)
130
131/* access rights that require Unix write permission */
132#define FILE_UNIX_WRITE_ACCESS (FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA)
133
Alexandre Julliard863637b2003-01-30 00:26:44 +0000134#endif /* __WINE_SERVER_FILE_H */