Suspended threads should not acquire synchronization objects.
[wine] / server / smb.c
1 /*
2  * Server-side smb network file management
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  * Copyright (C) 2000, 2001, 2002 Mike McCormack
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * FIXME: if you can't find something to fix,
22  *          you're not looking hard enough
23  */
24
25 #include "config.h"
26
27 #include <assert.h>
28 #include <fcntl.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <sys/time.h>
33 #include <sys/types.h>
34 #include <time.h>
35 #include <unistd.h>
36 #ifdef HAVE_UTIME_H
37 #include <utime.h>
38 #endif
39 #ifdef HAVE_TERMIOS_H
40 #include <termios.h>
41 #endif
42 #ifdef HAVE_SYS_IOCTL_H
43 #include <sys/ioctl.h>
44 #endif
45
46 #include "winerror.h"
47 #include "winbase.h"
48
49 #include "file.h"
50 #include "handle.h"
51 #include "thread.h"
52 #include "request.h"
53
54 static void smb_dump( struct object *obj, int verbose );
55 static struct fd *smb_get_fd( struct object *obj );
56 static void smb_destroy(struct object *obj);
57
58 static int smb_get_info( struct fd *fd, struct get_file_info_reply *reply, int *flags );
59 static int smb_get_poll_events( struct fd *fd );
60
61 struct smb
62 {
63     struct object       obj;
64     struct fd          *fd;
65     unsigned int        tree_id;
66     unsigned int        user_id;
67     unsigned int        dialect;
68     unsigned int        file_id;
69     unsigned int        offset;
70 };
71
72 static const struct object_ops smb_ops =
73 {
74     sizeof(struct smb),        /* size */
75     smb_dump,                  /* dump */
76     default_fd_add_queue,      /* add_queue */
77     default_fd_remove_queue,   /* remove_queue */
78     default_fd_signaled,       /* signaled */
79     no_satisfied,              /* satisfied */
80     smb_get_fd,                /* get_fd */
81     smb_destroy                /* destroy */
82 };
83
84 static const struct fd_ops smb_fd_ops =
85 {
86     smb_get_poll_events,       /* get_poll_events */
87     default_poll_event,        /* poll_event */
88     no_flush,                  /* flush */
89     smb_get_info,              /* get_file_info */
90     no_queue_async             /* queue_async */
91 };
92
93 static struct fd *smb_get_fd( struct object *obj )
94 {
95     struct smb *smb = (struct smb *)obj;
96     return (struct fd *)grab_object( smb->fd );
97 }
98
99 static void smb_destroy( struct object *obj)
100 {
101     struct smb *smb = (struct smb *)obj;
102     assert( obj->ops == &smb_ops );
103     if (smb->fd) release_object( smb->fd );
104 }
105
106 static void smb_dump( struct object *obj, int verbose )
107 {
108     struct smb *smb = (struct smb *)obj;
109     assert( obj->ops == &smb_ops );
110     fprintf( stderr, "Smb file fd=%p\n", smb->fd );
111 }
112
113 static struct smb *get_smb_obj( struct process *process, obj_handle_t handle, unsigned int access )
114 {
115     return (struct smb *)get_handle_obj( process, handle, access, &smb_ops );
116 }
117
118 static int smb_get_poll_events( struct fd *fd )
119 {
120     struct smb *smb = get_fd_user( fd );
121     int events = 0;
122     assert( smb->obj.ops == &smb_ops );
123
124     events |= POLLIN;
125
126     /* fprintf(stderr,"poll events are %04x\n",events); */
127
128     return events;
129 }
130
131 static int smb_get_info( struct fd *fd, struct get_file_info_reply *reply, int *flags )
132 {
133 /*    struct smb *smb = get_fd_user( fd ); */
134 /*    assert( smb->obj.ops == &smb_ops ); */
135
136     if (reply)
137     {
138         reply->type        = FILE_TYPE_CHAR;
139         reply->attr        = 0;
140         reply->access_time = 0;
141         reply->write_time  = 0;
142         reply->size_high   = 0;
143         reply->size_low    = 0;
144         reply->links       = 0;
145         reply->index_high  = 0;
146         reply->index_low   = 0;
147         reply->serial      = 0;
148     }
149
150     *flags = 0;
151
152     return FD_TYPE_SMB;
153 }
154
155 /* create a smb */
156 DECL_HANDLER(create_smb)
157 {
158     struct smb *smb;
159     int fd;
160
161     reply->handle = 0;
162
163     fd = thread_get_inflight_fd( current, req->fd );
164     if (fd == -1)
165     {
166         set_error( STATUS_INVALID_HANDLE );
167         return;
168     }
169
170     smb = alloc_object( &smb_ops );
171     if (smb)
172     {
173         smb->tree_id = req->tree_id;
174         smb->user_id = req->user_id;
175         smb->dialect = req->dialect;
176         smb->file_id = req->file_id;
177         smb->offset = 0;
178         if (!(smb->fd = alloc_fd( &smb_fd_ops, fd, &smb->obj )))
179         {
180             release_object( smb );
181             return;
182         }
183         reply->handle = alloc_handle( current->process, smb, GENERIC_READ, 0);
184         release_object( smb );
185     }
186 }
187
188 DECL_HANDLER(get_smb_info)
189 {
190     struct smb *smb;
191
192     if ((smb = get_smb_obj( current->process, req->handle, 0 )))
193     {
194         if(req->flags & SMBINFO_SET_OFFSET)
195             smb->offset = req->offset;
196
197         reply->tree_id = smb->tree_id;
198         reply->user_id = smb->user_id;
199         reply->dialect = smb->dialect;
200         reply->file_id = smb->file_id;
201         reply->offset  = smb->offset;
202
203         release_object( smb );
204     }
205 }