2 * Server-side file management
4 * Copyright (C) 1998 Alexandre Julliard
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
31 #ifdef HAVE_SYS_ERRNO_H
32 #include <sys/errno.h>
36 #include <sys/types.h>
47 #define WIN32_NO_STATUS
60 struct object obj
; /* object header */
61 struct fd
*fd
; /* file descriptor for this file */
62 unsigned int access
; /* file access (FILE_READ_DATA etc.) */
63 mode_t mode
; /* file stat.st_mode */
64 uid_t uid
; /* file stat.st_uid */
67 static unsigned int generic_file_map_access( unsigned int access
);
69 static void file_dump( struct object
*obj
, int verbose
);
70 static struct fd
*file_get_fd( struct object
*obj
);
71 static struct security_descriptor
*file_get_sd( struct object
*obj
);
72 static int file_set_sd( struct object
*obj
, const struct security_descriptor
*sd
, unsigned int set_info
);
73 static void file_destroy( struct object
*obj
);
75 static int file_get_poll_events( struct fd
*fd
);
76 static void file_flush( struct fd
*fd
, struct event
**event
);
77 static enum server_fd_type
file_get_fd_type( struct fd
*fd
);
79 static const struct object_ops file_ops
=
81 sizeof(struct file
), /* size */
83 no_get_type
, /* get_type */
84 add_queue
, /* add_queue */
85 remove_queue
, /* remove_queue */
86 default_fd_signaled
, /* signaled */
87 no_satisfied
, /* satisfied */
88 no_signal
, /* signal */
89 file_get_fd
, /* get_fd */
90 default_fd_map_access
, /* map_access */
91 file_get_sd
, /* get_sd */
92 file_set_sd
, /* set_sd */
93 no_lookup_name
, /* lookup_name */
94 no_open_file
, /* open_file */
95 fd_close_handle
, /* close_handle */
96 file_destroy
/* destroy */
99 static const struct fd_ops file_fd_ops
=
101 file_get_poll_events
, /* get_poll_events */
102 default_poll_event
, /* poll_event */
103 file_flush
, /* flush */
104 file_get_fd_type
, /* get_fd_type */
105 default_fd_ioctl
, /* ioctl */
106 default_fd_queue_async
, /* queue_async */
107 default_fd_reselect_async
, /* reselect_async */
108 default_fd_cancel_async
/* cancel_async */
111 static inline int is_overlapped( const struct file
*file
)
113 return !(get_fd_options( file
->fd
) & (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
116 /* create a file from a file descriptor */
117 /* if the function fails the fd is closed */
118 struct file
*create_file_for_fd( int fd
, unsigned int access
, unsigned int sharing
)
123 if (fstat( fd
, &st
) == -1)
129 if ((file
= alloc_object( &file_ops
)))
131 file
->mode
= st
.st_mode
;
132 file
->access
= default_fd_map_access( &file
->obj
, access
);
133 if (!(file
->fd
= create_anonymous_fd( &file_fd_ops
, fd
, &file
->obj
,
134 FILE_SYNCHRONOUS_IO_NONALERT
)))
136 release_object( file
);
143 static struct object
*create_file_obj( struct fd
*fd
, unsigned int access
, mode_t mode
)
145 struct file
*file
= alloc_object( &file_ops
);
147 if (!file
) return NULL
;
148 file
->access
= access
;
150 file
->uid
= ~(uid_t
)0;
153 set_fd_user( fd
, &file_fd_ops
, &file
->obj
);
157 static struct object
*create_file( const char *nameptr
, data_size_t len
, unsigned int access
,
158 unsigned int sharing
, int create
, unsigned int options
,
159 unsigned int attrs
, const struct security_descriptor
*sd
)
161 struct object
*obj
= NULL
;
167 if (!(name
= mem_alloc( len
+ 1 ))) return NULL
;
168 memcpy( name
, nameptr
, len
);
173 case FILE_CREATE
: flags
= O_CREAT
| O_EXCL
; break;
174 case FILE_OVERWRITE_IF
: /* FIXME: the difference is whether we trash existing attr or not */
175 case FILE_SUPERSEDE
: flags
= O_CREAT
| O_TRUNC
; break;
176 case FILE_OPEN
: flags
= 0; break;
177 case FILE_OPEN_IF
: flags
= O_CREAT
; break;
178 case FILE_OVERWRITE
: flags
= O_TRUNC
; break;
179 default: set_error( STATUS_INVALID_PARAMETER
); goto done
;
184 const SID
*owner
= sd_get_owner( sd
);
186 owner
= token_get_user( current
->process
->token
);
187 mode
= sd_to_mode( sd
, owner
);
190 mode
= (attrs
& FILE_ATTRIBUTE_READONLY
) ? 0444 : 0666;
193 (!strcasecmp( name
+ len
- 4, ".exe" ) || !strcasecmp( name
+ len
- 4, ".com" )))
203 access
= generic_file_map_access( access
);
205 /* FIXME: should set error to STATUS_OBJECT_NAME_COLLISION if file existed before */
206 fd
= open_fd( name
, flags
| O_NONBLOCK
| O_LARGEFILE
, &mode
, access
, sharing
, options
);
210 obj
= create_dir_obj( fd
, access
, mode
);
211 else if (S_ISCHR(mode
) && is_serial_fd( fd
))
212 obj
= create_serial( fd
);
214 obj
= create_file_obj( fd
, access
, mode
);
216 release_object( fd
);
223 /* check if two file objects point to the same file */
224 int is_same_file( struct file
*file1
, struct file
*file2
)
226 return is_same_file_fd( file1
->fd
, file2
->fd
);
229 static void file_dump( struct object
*obj
, int verbose
)
231 struct file
*file
= (struct file
*)obj
;
232 assert( obj
->ops
== &file_ops
);
233 fprintf( stderr
, "File fd=%p\n", file
->fd
);
236 static int file_get_poll_events( struct fd
*fd
)
238 struct file
*file
= get_fd_user( fd
);
240 assert( file
->obj
.ops
== &file_ops
);
241 if (file
->access
& FILE_UNIX_READ_ACCESS
) events
|= POLLIN
;
242 if (file
->access
& FILE_UNIX_WRITE_ACCESS
) events
|= POLLOUT
;
246 static void file_flush( struct fd
*fd
, struct event
**event
)
248 int unix_fd
= get_unix_fd( fd
);
249 if (unix_fd
!= -1 && fsync( unix_fd
) == -1) file_set_error();
252 static enum server_fd_type
file_get_fd_type( struct fd
*fd
)
254 struct file
*file
= get_fd_user( fd
);
256 if (S_ISREG(file
->mode
) || S_ISBLK(file
->mode
)) return FD_TYPE_FILE
;
257 if (S_ISDIR(file
->mode
)) return FD_TYPE_DIR
;
261 static struct fd
*file_get_fd( struct object
*obj
)
263 struct file
*file
= (struct file
*)obj
;
264 assert( obj
->ops
== &file_ops
);
265 return (struct fd
*)grab_object( file
->fd
);
268 static unsigned int generic_file_map_access( unsigned int access
)
270 if (access
& GENERIC_READ
) access
|= FILE_GENERIC_READ
;
271 if (access
& GENERIC_WRITE
) access
|= FILE_GENERIC_WRITE
;
272 if (access
& GENERIC_EXECUTE
) access
|= FILE_GENERIC_EXECUTE
;
273 if (access
& GENERIC_ALL
) access
|= FILE_ALL_ACCESS
;
274 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
277 struct security_descriptor
*mode_to_sd( mode_t mode
, const SID
*user
, const SID
*group
)
279 struct security_descriptor
*sd
;
281 ACE_HEADER
*current_ace
;
282 ACCESS_ALLOWED_ACE
*aaa
;
286 const SID
*world_sid
= security_world_sid
;
287 const SID
*local_system_sid
= security_local_system_sid
;
289 dacl_size
= sizeof(ACL
) + FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
290 FIELD_OFFSET(SID
, SubAuthority
[local_system_sid
->SubAuthorityCount
]);
292 dacl_size
+= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
293 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
294 if ((!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
))) ||
295 (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IWOTH
))) ||
296 (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
))))
297 dacl_size
+= FIELD_OFFSET(ACCESS_DENIED_ACE
, SidStart
) +
298 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
300 dacl_size
+= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
301 FIELD_OFFSET(SID
, SubAuthority
[world_sid
->SubAuthorityCount
]);
303 sd
= mem_alloc( sizeof(struct security_descriptor
) +
304 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) +
305 FIELD_OFFSET(SID
, SubAuthority
[group
->SubAuthorityCount
]) +
309 sd
->control
= SE_DACL_PRESENT
;
310 sd
->owner_len
= FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
311 sd
->group_len
= FIELD_OFFSET(SID
, SubAuthority
[group
->SubAuthorityCount
]);
313 sd
->dacl_len
= dacl_size
;
315 ptr
= (char *)(sd
+ 1);
316 memcpy( ptr
, user
, sd
->owner_len
);
317 ptr
+= sd
->owner_len
;
318 memcpy( ptr
, group
, sd
->group_len
);
319 ptr
+= sd
->group_len
;
322 dacl
->AclRevision
= ACL_REVISION
;
324 dacl
->AclSize
= dacl_size
;
325 dacl
->AceCount
= 1 + (mode
& S_IRWXU
? 1 : 0) + (mode
& S_IRWXO
? 1 : 0);
326 if ((!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
))) ||
327 (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IWOTH
))) ||
328 (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
))))
332 /* always give FILE_ALL_ACCESS for Local System */
333 aaa
= (ACCESS_ALLOWED_ACE
*)(dacl
+ 1);
334 current_ace
= &aaa
->Header
;
335 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
336 aaa
->Header
.AceFlags
= 0;
337 aaa
->Header
.AceSize
= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
338 FIELD_OFFSET(SID
, SubAuthority
[local_system_sid
->SubAuthorityCount
]);
339 aaa
->Mask
= FILE_ALL_ACCESS
;
340 sid
= (SID
*)&aaa
->SidStart
;
341 memcpy( sid
, local_system_sid
, FIELD_OFFSET(SID
, SubAuthority
[local_system_sid
->SubAuthorityCount
]) );
345 /* appropriate access rights for the user */
346 aaa
= (ACCESS_ALLOWED_ACE
*)ace_next( current_ace
);
347 current_ace
= &aaa
->Header
;
348 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
349 aaa
->Header
.AceFlags
= 0;
350 aaa
->Header
.AceSize
= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
351 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
352 aaa
->Mask
= WRITE_DAC
| WRITE_OWNER
;
354 aaa
->Mask
|= FILE_GENERIC_READ
;
356 aaa
->Mask
|= FILE_GENERIC_WRITE
| DELETE
;
358 aaa
->Mask
|= FILE_GENERIC_EXECUTE
;
359 sid
= (SID
*)&aaa
->SidStart
;
360 memcpy( sid
, user
, FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) );
362 if ((!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
))) ||
363 (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IWOTH
))) ||
364 (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
))))
366 /* deny just in case the user is a member of the group */
367 ACCESS_DENIED_ACE
*ada
= (ACCESS_DENIED_ACE
*)ace_next( current_ace
);
368 current_ace
= &ada
->Header
;
369 ada
->Header
.AceType
= ACCESS_DENIED_ACE_TYPE
;
370 ada
->Header
.AceFlags
= 0;
371 ada
->Header
.AceSize
= FIELD_OFFSET(ACCESS_DENIED_ACE
, SidStart
) +
372 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
374 if (!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
)))
375 ada
->Mask
|= FILE_GENERIC_READ
;
376 if (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IROTH
)))
377 ada
->Mask
|= FILE_GENERIC_WRITE
| DELETE
;
378 if (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
)))
379 ada
->Mask
|= FILE_GENERIC_EXECUTE
;
380 ada
->Mask
&= ~STANDARD_RIGHTS_ALL
; /* never deny standard rights */
381 sid
= (SID
*)&ada
->SidStart
;
382 memcpy( sid
, user
, FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) );
386 /* appropriate access rights for Everyone */
387 aaa
= (ACCESS_ALLOWED_ACE
*)ace_next( current_ace
);
388 current_ace
= &aaa
->Header
;
389 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
390 aaa
->Header
.AceFlags
= 0;
391 aaa
->Header
.AceSize
= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
392 FIELD_OFFSET(SID
, SubAuthority
[world_sid
->SubAuthorityCount
]);
395 aaa
->Mask
|= FILE_GENERIC_READ
;
397 aaa
->Mask
|= FILE_GENERIC_WRITE
| DELETE
;
399 aaa
->Mask
|= FILE_GENERIC_EXECUTE
;
400 sid
= (SID
*)&aaa
->SidStart
;
401 memcpy( sid
, world_sid
, FIELD_OFFSET(SID
, SubAuthority
[world_sid
->SubAuthorityCount
]) );
407 static struct security_descriptor
*file_get_sd( struct object
*obj
)
409 struct file
*file
= (struct file
*)obj
;
412 struct security_descriptor
*sd
;
414 assert( obj
->ops
== &file_ops
);
416 unix_fd
= get_file_unix_fd( file
);
418 if (unix_fd
== -1 || fstat( unix_fd
, &st
) == -1)
421 /* mode and uid the same? if so, no need to re-generate security descriptor */
422 if (obj
->sd
&& (st
.st_mode
& (S_IRWXU
|S_IRWXO
)) == (file
->mode
& (S_IRWXU
|S_IRWXO
)) &&
423 (st
.st_uid
== file
->uid
))
426 sd
= mode_to_sd( st
.st_mode
,
427 security_unix_uid_to_sid( st
.st_uid
),
428 token_get_primary_group( current
->process
->token
));
429 if (!sd
) return obj
->sd
;
431 file
->mode
= st
.st_mode
;
432 file
->uid
= st
.st_uid
;
438 mode_t
sd_to_mode( const struct security_descriptor
*sd
, const SID
*owner
)
441 mode_t denied_mode
= 0;
443 const ACL
*dacl
= sd_get_dacl( sd
, &present
);
446 const ACE_HEADER
*ace
= (const ACE_HEADER
*)(dacl
+ 1);
448 for (i
= 0; i
< dacl
->AceCount
; i
++, ace
= ace_next( ace
))
450 const ACCESS_ALLOWED_ACE
*aa_ace
;
451 const ACCESS_DENIED_ACE
*ad_ace
;
454 if (ace
->AceFlags
& INHERIT_ONLY_ACE
) continue;
456 switch (ace
->AceType
)
458 case ACCESS_DENIED_ACE_TYPE
:
459 ad_ace
= (const ACCESS_DENIED_ACE
*)ace
;
460 sid
= (const SID
*)&ad_ace
->SidStart
;
461 if (security_equal_sid( sid
, security_world_sid
))
463 unsigned int access
= generic_file_map_access( ad_ace
->Mask
);
464 if (access
& FILE_READ_DATA
)
465 denied_mode
|= S_IRUSR
|S_IRGRP
|S_IROTH
;
466 if (access
& FILE_WRITE_DATA
)
467 denied_mode
|= S_IWUSR
|S_IWGRP
|S_IWOTH
;
468 if (access
& FILE_EXECUTE
)
469 denied_mode
|= S_IXUSR
|S_IXGRP
|S_IXOTH
;
471 else if (security_equal_sid( sid
, owner
))
473 unsigned int access
= generic_file_map_access( ad_ace
->Mask
);
474 if (access
& FILE_READ_DATA
)
475 denied_mode
|= S_IRUSR
;
476 if (access
& FILE_WRITE_DATA
)
477 denied_mode
|= S_IWUSR
;
478 if (access
& FILE_EXECUTE
)
479 denied_mode
|= S_IXUSR
;
482 case ACCESS_ALLOWED_ACE_TYPE
:
483 aa_ace
= (const ACCESS_ALLOWED_ACE
*)ace
;
484 sid
= (const SID
*)&aa_ace
->SidStart
;
485 if (security_equal_sid( sid
, security_world_sid
))
487 unsigned int access
= generic_file_map_access( aa_ace
->Mask
);
488 if (access
& FILE_READ_DATA
)
489 new_mode
|= S_IRUSR
|S_IRGRP
|S_IROTH
;
490 if (access
& FILE_WRITE_DATA
)
491 new_mode
|= S_IWUSR
|S_IWGRP
|S_IWOTH
;
492 if (access
& FILE_EXECUTE
)
493 new_mode
|= S_IXUSR
|S_IXGRP
|S_IXOTH
;
495 else if (security_equal_sid( sid
, owner
))
497 unsigned int access
= generic_file_map_access( aa_ace
->Mask
);
498 if (access
& FILE_READ_DATA
)
500 if (access
& FILE_WRITE_DATA
)
502 if (access
& FILE_EXECUTE
)
510 /* no ACL means full access rights to anyone */
511 new_mode
= S_IRWXU
| S_IRWXO
;
513 return new_mode
& ~denied_mode
;
516 static int file_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
517 unsigned int set_info
)
519 struct file
*file
= (struct file
*)obj
;
525 assert( obj
->ops
== &file_ops
);
527 unix_fd
= get_file_unix_fd( file
);
529 if (unix_fd
== -1 || fstat( unix_fd
, &st
) == -1) return 1;
531 if (set_info
& OWNER_SECURITY_INFORMATION
)
533 owner
= sd_get_owner( sd
);
536 set_error( STATUS_INVALID_SECURITY_DESCR
);
539 if (!obj
->sd
|| !security_equal_sid( owner
, sd_get_owner( obj
->sd
) ))
541 /* FIXME: get Unix uid and call fchown */
545 owner
= sd_get_owner( obj
->sd
);
547 owner
= token_get_user( current
->process
->token
);
549 /* group and sacl not supported */
551 if (set_info
& DACL_SECURITY_INFORMATION
)
553 /* keep the bits that we don't map to access rights in the ACL */
554 mode
= st
.st_mode
& (S_ISUID
|S_ISGID
|S_ISVTX
|S_IRWXG
);
555 mode
|= sd_to_mode( sd
, owner
);
557 if (st
.st_mode
!= mode
&& fchmod( unix_fd
, mode
) == -1)
566 static void file_destroy( struct object
*obj
)
568 struct file
*file
= (struct file
*)obj
;
569 assert( obj
->ops
== &file_ops
);
571 if (file
->fd
) release_object( file
->fd
);
574 /* set the last error depending on errno */
575 void file_set_error(void)
580 case EAGAIN
: set_error( STATUS_SHARING_VIOLATION
); break;
581 case EBADF
: set_error( STATUS_INVALID_HANDLE
); break;
582 case ENOSPC
: set_error( STATUS_DISK_FULL
); break;
586 case EPERM
: set_error( STATUS_ACCESS_DENIED
); break;
587 case EBUSY
: set_error( STATUS_FILE_LOCK_CONFLICT
); break;
588 case ENOENT
: set_error( STATUS_NO_SUCH_FILE
); break;
589 case EISDIR
: set_error( STATUS_FILE_IS_A_DIRECTORY
); break;
591 case EMFILE
: set_error( STATUS_TOO_MANY_OPENED_FILES
); break;
592 case EEXIST
: set_error( STATUS_OBJECT_NAME_COLLISION
); break;
593 case EINVAL
: set_error( STATUS_INVALID_PARAMETER
); break;
594 case ESPIPE
: set_error( STATUS_ILLEGAL_FUNCTION
); break;
595 case ENOTEMPTY
: set_error( STATUS_DIRECTORY_NOT_EMPTY
); break;
596 case EIO
: set_error( STATUS_ACCESS_VIOLATION
); break;
597 case ENOTDIR
: set_error( STATUS_NOT_A_DIRECTORY
); break;
598 case EFBIG
: set_error( STATUS_SECTION_TOO_BIG
); break;
599 case ENODEV
: set_error( STATUS_NO_SUCH_DEVICE
); break;
600 case ENXIO
: set_error( STATUS_NO_SUCH_DEVICE
); break;
602 case EOVERFLOW
: set_error( STATUS_INVALID_PARAMETER
); break;
605 perror("wineserver: file_set_error() can't map error");
606 set_error( STATUS_UNSUCCESSFUL
);
611 struct file
*get_file_obj( struct process
*process
, obj_handle_t handle
, unsigned int access
)
613 return (struct file
*)get_handle_obj( process
, handle
, access
, &file_ops
);
616 int get_file_unix_fd( struct file
*file
)
618 return get_unix_fd( file
->fd
);
621 struct file
*grab_file_unless_removable( struct file
*file
)
623 if (is_fd_removable( file
->fd
)) return NULL
;
624 return (struct file
*)grab_object( file
);
628 DECL_HANDLER(create_file
)
631 const struct object_attributes
*objattr
= get_req_data();
632 const struct security_descriptor
*sd
;
634 data_size_t name_len
;
638 if (!objattr_is_valid( objattr
, get_req_data_size() ))
640 /* name is transferred in the unix codepage outside of the objattr structure */
641 if (objattr
->name_len
)
643 set_error( STATUS_INVALID_PARAMETER
);
647 sd
= objattr
->sd_len
? (const struct security_descriptor
*)(objattr
+ 1) : NULL
;
649 name
= (const char *)get_req_data() + sizeof(*objattr
) + objattr
->sd_len
;
650 name_len
= get_req_data_size() - sizeof(*objattr
) - objattr
->sd_len
;
653 if ((file
= create_file( name
, name_len
, req
->access
,
654 req
->sharing
, req
->create
, req
->options
,
657 reply
->handle
= alloc_handle( current
->process
, file
, req
->access
, req
->attributes
);
658 release_object( file
);
662 /* allocate a file handle for a Unix fd */
663 DECL_HANDLER(alloc_file_handle
)
669 if ((fd
= thread_get_inflight_fd( current
, req
->fd
)) == -1)
671 set_error( STATUS_INVALID_HANDLE
);
674 if ((file
= create_file_for_fd( fd
, req
->access
, FILE_SHARE_READ
| FILE_SHARE_WRITE
)))
676 reply
->handle
= alloc_handle( current
->process
, file
, req
->access
, req
->attributes
);
677 release_object( file
);
681 /* lock a region of a file */
682 DECL_HANDLER(lock_file
)
686 if ((file
= get_file_obj( current
->process
, req
->handle
, 0 )))
688 reply
->handle
= lock_fd( file
->fd
, req
->offset
, req
->count
, req
->shared
, req
->wait
);
689 reply
->overlapped
= is_overlapped( file
);
690 release_object( file
);
694 /* unlock a region of a file */
695 DECL_HANDLER(unlock_file
)
699 if ((file
= get_file_obj( current
->process
, req
->handle
, 0 )))
701 unlock_fd( file
->fd
, req
->offset
, req
->count
);
702 release_object( file
);