blob: 890cdb3d511d9e8d4cbe8f35ab20d9987417fbbe [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 Julliardcf27a7f2003-02-14 20:27:09 +000040 int (*get_file_info)(struct fd *,struct get_file_info_reply *, int *flags);
Alexandre Julliard863637b2003-01-30 00:26:44 +000041 /* queue an async operation - see register_async handler in async.c*/
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000042 void (*queue_async)(struct fd *, void* ptr, unsigned int status, int type, int count);
Alexandre Julliard863637b2003-01-30 00:26:44 +000043};
44
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000045/* file descriptor functions */
46
Alexandre Julliard580da242003-03-12 22:38:14 +000047extern struct fd *alloc_fd( const struct fd_ops *fd_user_ops, struct object *user );
Gerald Pfeifer6dcc1af2003-03-18 18:26:44 +000048extern struct fd *open_fd( struct fd *fd, const char *name, int flags, mode_t *mode );
Alexandre Julliard580da242003-03-12 22:38:14 +000049extern struct fd *create_anonymous_fd( const struct fd_ops *fd_user_ops,
50 int unix_fd, struct object *user );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000051extern void *get_fd_user( struct fd *fd );
52extern int get_unix_fd( struct fd *fd );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000053extern void fd_poll_event( struct fd *fd, int event );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000054extern int check_fd_events( struct fd *fd, int events );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000055extern void set_fd_events( struct fd *fd, int events );
Alexandre Julliardce613492003-03-18 05:04:33 +000056extern obj_handle_t lock_fd( struct fd *fd, file_pos_t offset, file_pos_t count, int shared, int wait );
57extern void unlock_fd( struct fd *fd, file_pos_t offset, file_pos_t count );
Mike McCormackef8b9462003-05-15 04:22:45 +000058extern int flush_cached_fd( struct process *process, obj_handle_t handle );
Alexandre Julliard863637b2003-01-30 00:26:44 +000059
60extern int default_fd_add_queue( struct object *obj, struct wait_queue_entry *entry );
61extern void default_fd_remove_queue( struct object *obj, struct wait_queue_entry *entry );
62extern int default_fd_signaled( struct object *obj, struct thread *thread );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000063extern void default_poll_event( struct fd *fd, int event );
Mike McCormackef8b9462003-05-15 04:22:45 +000064extern int no_flush( struct fd *fd, struct event **event );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000065extern int no_get_file_info( struct fd *fd, struct get_file_info_reply *info, int *flags );
66extern void no_queue_async( struct fd *fd, void* ptr, unsigned int status, int type, int count );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000067extern void main_loop(void);
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000068
69inline static struct fd *get_obj_fd( struct object *obj ) { return obj->ops->get_fd( obj ); }
70
Alexandre Julliarde66207e2003-02-19 00:33:32 +000071/* timeout functions */
72
73struct timeout_user;
74
75typedef void (*timeout_callback)( void *private );
76
77extern struct timeout_user *add_timeout_user( struct timeval *when,
78 timeout_callback func, void *private );
79extern void remove_timeout_user( struct timeout_user *user );
80extern void add_timeout( struct timeval *when, int timeout );
81/* return 1 if t1 is before t2 */
82static inline int time_before( struct timeval *t1, struct timeval *t2 )
83{
84 return ((t1->tv_sec < t2->tv_sec) ||
85 ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec < t2->tv_usec)));
86}
87
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000088/* file functions */
89
90extern struct file *get_file_obj( struct process *process, obj_handle_t handle,
91 unsigned int access );
92extern int get_file_unix_fd( struct file *file );
93extern int is_same_file( struct file *file1, struct file *file2 );
Alexandre Julliardaf192f82003-10-08 00:25:32 +000094extern int is_file_removable( struct file *file );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000095extern int grow_file( struct file *file, int size_high, int size_low );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000096extern struct file *create_temp_file( int access );
97extern void file_set_error(void);
Alexandre Julliard863637b2003-01-30 00:26:44 +000098
Alexandre Julliard3e588e32003-03-26 23:41:43 +000099/* change notification functions */
100
101extern void do_change_notify( int unix_fd );
102extern void sigio_callback(void);
103
Alexandre Julliard863637b2003-01-30 00:26:44 +0000104#endif /* __WINE_SERVER_FILE_H */