blob: 26d170263ba41f5fd4285ad25b7ddd970c34af1c [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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard863637b2003-01-30 00:26:44 +000019 */
20
21#ifndef __WINE_SERVER_FILE_H
22#define __WINE_SERVER_FILE_H
23
24#include "object.h"
25
26struct fd;
Alexandre Julliarddf09ac52007-04-02 20:09:29 +020027struct async_queue;
Andrey Turkind1a81552007-09-28 00:03:39 +040028struct completion;
Alexandre Julliard863637b2003-01-30 00:26:44 +000029
30/* 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 */
Alexandre Julliarddf651872007-03-27 16:51:44 +020038 void (*flush)(struct fd *, struct event **);
Alexandre Julliard863637b2003-01-30 00:26:44 +000039 /* get file information */
Alexandre Julliard7a9363a2007-04-10 22:26:23 +020040 enum server_fd_type (*get_fd_type)(struct fd *fd);
Alexandre Julliard63571432007-04-16 14:45:03 +020041 /* perform an ioctl on the file */
Alexandre Julliardfd59e152007-05-03 17:43:18 +020042 obj_handle_t (*ioctl)(struct fd *fd, ioctl_code_t code, const async_data_t *async,
43 const void *data, data_size_t size);
Eric Pouech46344472005-01-14 19:54:38 +000044 /* queue an async operation */
Alexandre Julliard111610c2007-03-20 20:21:12 +010045 void (*queue_async)(struct fd *, const async_data_t *data, int type, int count);
Alexandre Julliard72bff2e2007-04-10 17:07:27 +020046 /* selected events for async i/o need an update */
47 void (*reselect_async)( struct fd *, struct async_queue *queue );
Eric Pouech46344472005-01-14 19:54:38 +000048 /* cancel an async operation */
49 void (*cancel_async)(struct fd *);
Alexandre Julliard863637b2003-01-30 00:26:44 +000050};
51
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000052/* file descriptor functions */
53
Alexandre Julliard017480d2007-05-03 16:07:30 +020054extern struct fd *alloc_pseudo_fd( const struct fd_ops *fd_user_ops, struct object *user,
55 unsigned int options );
Alexandre Julliardf3fbae42007-04-18 16:05:59 +020056extern void set_no_fd_status( struct fd *fd, unsigned int status );
Mike McCormack9a7124e2006-01-24 13:30:55 +010057extern struct fd *open_fd( const char *name, int flags, mode_t *mode, unsigned int access,
58 unsigned int sharing, unsigned int options );
Alexandre Julliard580da242003-03-12 22:38:14 +000059extern struct fd *create_anonymous_fd( const struct fd_ops *fd_user_ops,
Alexandre Julliardf85437c2007-04-10 22:25:07 +020060 int unix_fd, struct object *user, unsigned int options );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000061extern void *get_fd_user( struct fd *fd );
Mike McCormack9a7124e2006-01-24 13:30:55 +010062extern void set_fd_user( struct fd *fd, const struct fd_ops *ops, struct object *user );
Alexandre Julliardf85437c2007-04-10 22:25:07 +020063extern unsigned int get_fd_options( struct fd *fd );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000064extern int get_unix_fd( struct fd *fd );
Alexandre Julliard74bd1e42004-03-27 20:48:42 +000065extern int is_same_file_fd( struct fd *fd1, struct fd *fd2 );
Alexandre Julliard5bd51362007-01-12 14:42:43 +010066extern int is_fd_removable( struct fd *fd );
Alexandre Julliard715d78e2006-11-02 20:52:22 +010067extern int fd_close_handle( struct object *obj, struct process *process, obj_handle_t handle );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000068extern int check_fd_events( struct fd *fd, int events );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000069extern void set_fd_events( struct fd *fd, int events );
Alexandre Julliardce613492003-03-18 05:04:33 +000070extern obj_handle_t lock_fd( struct fd *fd, file_pos_t offset, file_pos_t count, int shared, int wait );
71extern void unlock_fd( struct fd *fd, file_pos_t offset, file_pos_t count );
Alexandre Julliardba896e72007-04-04 19:39:29 +020072extern void set_fd_signaled( struct fd *fd, int signaled );
Alexandre Julliard863637b2003-01-30 00:26:44 +000073
Alexandre Julliard863637b2003-01-30 00:26:44 +000074extern int default_fd_signaled( struct object *obj, struct thread *thread );
Alexandre Julliard24001e82007-10-02 14:20:15 +020075extern unsigned int default_fd_map_access( struct object *obj, unsigned int access );
Robert Shearmand6a4e342005-06-07 20:09:01 +000076extern int default_fd_get_poll_events( struct fd *fd );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000077extern void default_poll_event( struct fd *fd, int event );
Alexandre Julliard0aae1ca2007-04-02 20:41:59 +020078extern struct async *fd_queue_async( struct fd *fd, const async_data_t *data, int type, int count );
Alexandre Julliarddf09ac52007-04-02 20:09:29 +020079extern void fd_async_wake_up( struct fd *fd, int type, unsigned int status );
Alexandre Julliard72bff2e2007-04-10 17:07:27 +020080extern void fd_reselect_async( struct fd *fd, struct async_queue *queue );
Alexandre Julliardfd59e152007-05-03 17:43:18 +020081extern obj_handle_t default_fd_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async,
82 const void *data, data_size_t size );
Alexandre Julliard111610c2007-03-20 20:21:12 +010083extern void default_fd_queue_async( struct fd *fd, const async_data_t *data, int type, int count );
Alexandre Julliard72bff2e2007-04-10 17:07:27 +020084extern void default_fd_reselect_async( struct fd *fd, struct async_queue *queue );
Robert Shearmand6a4e342005-06-07 20:09:01 +000085extern void default_fd_cancel_async( struct fd *fd );
Alexandre Julliarddf651872007-03-27 16:51:44 +020086extern void no_flush( struct fd *fd, struct event **event );
Alexandre Julliarde66207e2003-02-19 00:33:32 +000087extern void main_loop(void);
Mike McCormackcdcb2032005-06-14 11:40:40 +000088extern void remove_process_locks( struct process *process );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000089
Andrew Talbotb1788c82007-03-17 10:52:14 +000090static inline struct fd *get_obj_fd( struct object *obj ) { return obj->ops->get_fd( obj ); }
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +000091
Alexandre Julliarde66207e2003-02-19 00:33:32 +000092/* timeout functions */
93
94struct timeout_user;
Alexandre Julliardaaf477f2007-04-17 20:08:59 +020095extern timeout_t current_time;
96
97#define TICKS_PER_SEC 10000000
Alexandre Julliarde66207e2003-02-19 00:33:32 +000098
99typedef void (*timeout_callback)( void *private );
100
Alexandre Julliardaaf477f2007-04-17 20:08:59 +0200101extern struct timeout_user *add_timeout_user( timeout_t when, timeout_callback func, void *private );
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000102extern void remove_timeout_user( struct timeout_user *user );
Alexandre Julliardaaf477f2007-04-17 20:08:59 +0200103extern const char *get_timeout_str( timeout_t timeout );
Alexandre Julliarde66207e2003-02-19 00:33:32 +0000104
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +0000105/* file functions */
106
107extern struct file *get_file_obj( struct process *process, obj_handle_t handle,
108 unsigned int access );
109extern int get_file_unix_fd( struct file *file );
110extern int is_same_file( struct file *file1, struct file *file2 );
Alexandre Julliard5bd51362007-01-12 14:42:43 +0100111extern struct file *grab_file_unless_removable( struct file *file );
Alexandre Julliarda4334a62005-04-19 11:59:13 +0000112extern int grow_file( struct file *file, file_pos_t size );
Alexandre Julliardcf27a7f2003-02-14 20:27:09 +0000113extern struct file *create_temp_file( int access );
114extern void file_set_error(void);
Alexandre Julliard863637b2003-01-30 00:26:44 +0000115
Alexandre Julliard3e588e32003-03-26 23:41:43 +0000116/* change notification functions */
117
118extern void do_change_notify( int unix_fd );
119extern void sigio_callback(void);
Mike McCormack08351072006-01-27 12:13:56 +0100120extern struct object *create_dir_obj( struct fd *fd );
Alexandre Julliard3e588e32003-03-26 23:41:43 +0000121
Andrey Turkind1a81552007-09-28 00:03:39 +0400122/* completion */
123
Andrey Turkinc702a912007-11-10 01:11:48 +0300124extern struct completion *get_completion_obj( struct process *process, obj_handle_t handle, unsigned int access );
125extern void add_completion( struct completion *completion, unsigned long ckey, unsigned long cvalue, unsigned int status, unsigned long information );
Andrey Turkind1a81552007-09-28 00:03:39 +0400126
Alexandre Julliardadc06102004-03-18 04:08:48 +0000127/* serial port functions */
128
129extern int is_serial_fd( struct fd *fd );
Alexandre Julliardf85437c2007-04-10 22:25:07 +0200130extern struct object *create_serial( struct fd *fd );
Alexandre Julliardadc06102004-03-18 04:08:48 +0000131
Eric Pouech46344472005-01-14 19:54:38 +0000132/* async I/O functions */
Alexandre Julliarddf09ac52007-04-02 20:09:29 +0200133extern struct async_queue *create_async_queue( struct fd *fd );
Alexandre Julliardb2cba952007-04-03 19:36:07 +0200134extern void free_async_queue( struct async_queue *queue );
Alexandre Julliard0aae1ca2007-04-02 20:41:59 +0200135extern struct async *create_async( struct thread *thread, struct async_queue *queue,
136 const async_data_t *data );
Alexandre Julliardaaf477f2007-04-17 20:08:59 +0200137extern void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status );
Andrey Turkin7a9210f2007-11-10 01:12:16 +0300138extern void async_set_result( struct object *obj, unsigned int status, unsigned long total );
Alexandre Julliarddf09ac52007-04-02 20:09:29 +0200139extern int async_waiting( struct async_queue *queue );
Alexandre Julliard61e08b32007-05-08 20:37:21 +0200140extern void async_terminate( struct async *async, unsigned int status );
Alexandre Julliarddf09ac52007-04-02 20:09:29 +0200141extern void async_wake_up( struct async_queue *queue, unsigned int status );
Andrey Turkin3afbee52007-12-17 22:06:17 +0300142extern void fd_assign_completion( struct fd *fd, struct completion **p_port, unsigned long *p_key );
Eric Pouech46344472005-01-14 19:54:38 +0000143
Alexandre Julliarda510a7e2005-12-12 16:46:17 +0100144/* access rights that require Unix read permission */
145#define FILE_UNIX_READ_ACCESS (FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA)
146
147/* access rights that require Unix write permission */
148#define FILE_UNIX_WRITE_ACCESS (FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|FILE_WRITE_EA)
149
Alexandre Julliard863637b2003-01-30 00:26:44 +0000150#endif /* __WINE_SERVER_FILE_H */