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
);
139 allow_fd_caching( file
->fd
);
144 /* create a file by duplicating an fd object */
145 struct file
*create_file_for_fd_obj( struct fd
*fd
, unsigned int access
, unsigned int sharing
)
150 if (fstat( get_unix_fd(fd
), &st
) == -1)
156 if ((file
= alloc_object( &file_ops
)))
158 file
->mode
= st
.st_mode
;
159 file
->access
= default_fd_map_access( &file
->obj
, access
);
160 if (!(file
->fd
= dup_fd_object( fd
, access
, sharing
, FILE_SYNCHRONOUS_IO_NONALERT
)))
162 release_object( file
);
165 set_fd_user( file
->fd
, &file_fd_ops
, &file
->obj
);
170 static struct object
*create_file_obj( struct fd
*fd
, unsigned int access
, mode_t mode
)
172 struct file
*file
= alloc_object( &file_ops
);
174 if (!file
) return NULL
;
175 file
->access
= access
;
177 file
->uid
= ~(uid_t
)0;
180 set_fd_user( fd
, &file_fd_ops
, &file
->obj
);
184 static struct object
*create_file( struct fd
*root
, const char *nameptr
, data_size_t len
,
185 unsigned int access
, unsigned int sharing
, int create
,
186 unsigned int options
, unsigned int attrs
,
187 const struct security_descriptor
*sd
)
189 struct object
*obj
= NULL
;
195 if (!len
|| ((nameptr
[0] == '/') ^ !root
))
197 set_error( STATUS_OBJECT_PATH_SYNTAX_BAD
);
200 if (!(name
= mem_alloc( len
+ 1 ))) return NULL
;
201 memcpy( name
, nameptr
, len
);
206 case FILE_CREATE
: flags
= O_CREAT
| O_EXCL
; break;
207 case FILE_OVERWRITE_IF
: /* FIXME: the difference is whether we trash existing attr or not */
208 access
|= FILE_WRITE_ATTRIBUTES
;
209 case FILE_SUPERSEDE
: flags
= O_CREAT
| O_TRUNC
; break;
210 case FILE_OPEN
: flags
= 0; break;
211 case FILE_OPEN_IF
: flags
= O_CREAT
; break;
212 case FILE_OVERWRITE
: flags
= O_TRUNC
;
213 access
|= FILE_WRITE_ATTRIBUTES
; break;
214 default: set_error( STATUS_INVALID_PARAMETER
); goto done
;
219 const SID
*owner
= sd_get_owner( sd
);
221 owner
= token_get_user( current
->process
->token
);
222 mode
= sd_to_mode( sd
, owner
);
225 mode
= (attrs
& FILE_ATTRIBUTE_READONLY
) ? 0444 : 0666;
228 (!strcasecmp( name
+ len
- 4, ".exe" ) || !strcasecmp( name
+ len
- 4, ".com" )))
238 access
= generic_file_map_access( access
);
240 /* FIXME: should set error to STATUS_OBJECT_NAME_COLLISION if file existed before */
241 fd
= open_fd( root
, name
, flags
| O_NONBLOCK
| O_LARGEFILE
, &mode
, access
, sharing
, options
);
245 obj
= create_dir_obj( fd
, access
, mode
);
246 else if (S_ISCHR(mode
) && is_serial_fd( fd
))
247 obj
= create_serial( fd
);
249 obj
= create_file_obj( fd
, access
, mode
);
251 release_object( fd
);
258 /* check if two file objects point to the same file */
259 int is_same_file( struct file
*file1
, struct file
*file2
)
261 return is_same_file_fd( file1
->fd
, file2
->fd
);
264 static void file_dump( struct object
*obj
, int verbose
)
266 struct file
*file
= (struct file
*)obj
;
267 assert( obj
->ops
== &file_ops
);
268 fprintf( stderr
, "File fd=%p\n", file
->fd
);
271 static int file_get_poll_events( struct fd
*fd
)
273 struct file
*file
= get_fd_user( fd
);
275 assert( file
->obj
.ops
== &file_ops
);
276 if (file
->access
& FILE_UNIX_READ_ACCESS
) events
|= POLLIN
;
277 if (file
->access
& FILE_UNIX_WRITE_ACCESS
) events
|= POLLOUT
;
281 static void file_flush( struct fd
*fd
, struct event
**event
)
283 int unix_fd
= get_unix_fd( fd
);
284 if (unix_fd
!= -1 && fsync( unix_fd
) == -1) file_set_error();
287 static enum server_fd_type
file_get_fd_type( struct fd
*fd
)
289 struct file
*file
= get_fd_user( fd
);
291 if (S_ISREG(file
->mode
) || S_ISBLK(file
->mode
)) return FD_TYPE_FILE
;
292 if (S_ISDIR(file
->mode
)) return FD_TYPE_DIR
;
296 static struct fd
*file_get_fd( struct object
*obj
)
298 struct file
*file
= (struct file
*)obj
;
299 assert( obj
->ops
== &file_ops
);
300 return (struct fd
*)grab_object( file
->fd
);
303 static unsigned int generic_file_map_access( unsigned int access
)
305 if (access
& GENERIC_READ
) access
|= FILE_GENERIC_READ
;
306 if (access
& GENERIC_WRITE
) access
|= FILE_GENERIC_WRITE
;
307 if (access
& GENERIC_EXECUTE
) access
|= FILE_GENERIC_EXECUTE
;
308 if (access
& GENERIC_ALL
) access
|= FILE_ALL_ACCESS
;
309 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
312 struct security_descriptor
*mode_to_sd( mode_t mode
, const SID
*user
, const SID
*group
)
314 struct security_descriptor
*sd
;
316 ACE_HEADER
*current_ace
;
317 ACCESS_ALLOWED_ACE
*aaa
;
321 const SID
*world_sid
= security_world_sid
;
322 const SID
*local_system_sid
= security_local_system_sid
;
324 dacl_size
= sizeof(ACL
) + FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
325 FIELD_OFFSET(SID
, SubAuthority
[local_system_sid
->SubAuthorityCount
]);
327 dacl_size
+= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
328 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
329 if ((!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
))) ||
330 (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IWOTH
))) ||
331 (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
))))
332 dacl_size
+= FIELD_OFFSET(ACCESS_DENIED_ACE
, SidStart
) +
333 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
335 dacl_size
+= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
336 FIELD_OFFSET(SID
, SubAuthority
[world_sid
->SubAuthorityCount
]);
338 sd
= mem_alloc( sizeof(struct security_descriptor
) +
339 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) +
340 FIELD_OFFSET(SID
, SubAuthority
[group
->SubAuthorityCount
]) +
344 sd
->control
= SE_DACL_PRESENT
;
345 sd
->owner_len
= FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
346 sd
->group_len
= FIELD_OFFSET(SID
, SubAuthority
[group
->SubAuthorityCount
]);
348 sd
->dacl_len
= dacl_size
;
350 ptr
= (char *)(sd
+ 1);
351 memcpy( ptr
, user
, sd
->owner_len
);
352 ptr
+= sd
->owner_len
;
353 memcpy( ptr
, group
, sd
->group_len
);
354 ptr
+= sd
->group_len
;
357 dacl
->AclRevision
= ACL_REVISION
;
359 dacl
->AclSize
= dacl_size
;
360 dacl
->AceCount
= 1 + (mode
& S_IRWXU
? 1 : 0) + (mode
& S_IRWXO
? 1 : 0);
361 if ((!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
))) ||
362 (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IWOTH
))) ||
363 (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
))))
367 /* always give FILE_ALL_ACCESS for Local System */
368 aaa
= (ACCESS_ALLOWED_ACE
*)(dacl
+ 1);
369 current_ace
= &aaa
->Header
;
370 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
371 aaa
->Header
.AceFlags
= 0;
372 aaa
->Header
.AceSize
= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
373 FIELD_OFFSET(SID
, SubAuthority
[local_system_sid
->SubAuthorityCount
]);
374 aaa
->Mask
= FILE_ALL_ACCESS
;
375 sid
= (SID
*)&aaa
->SidStart
;
376 memcpy( sid
, local_system_sid
, FIELD_OFFSET(SID
, SubAuthority
[local_system_sid
->SubAuthorityCount
]) );
380 /* appropriate access rights for the user */
381 aaa
= (ACCESS_ALLOWED_ACE
*)ace_next( current_ace
);
382 current_ace
= &aaa
->Header
;
383 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
384 aaa
->Header
.AceFlags
= 0;
385 aaa
->Header
.AceSize
= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
386 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
387 aaa
->Mask
= WRITE_DAC
| WRITE_OWNER
;
389 aaa
->Mask
|= FILE_GENERIC_READ
| FILE_GENERIC_EXECUTE
;
391 aaa
->Mask
|= FILE_GENERIC_WRITE
| DELETE
| FILE_DELETE_CHILD
;
392 sid
= (SID
*)&aaa
->SidStart
;
393 memcpy( sid
, user
, FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) );
395 if ((!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
))) ||
396 (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IWOTH
))) ||
397 (!(mode
& S_IXUSR
) && (mode
& (S_IXGRP
|S_IXOTH
))))
399 /* deny just in case the user is a member of the group */
400 ACCESS_DENIED_ACE
*ada
= (ACCESS_DENIED_ACE
*)ace_next( current_ace
);
401 current_ace
= &ada
->Header
;
402 ada
->Header
.AceType
= ACCESS_DENIED_ACE_TYPE
;
403 ada
->Header
.AceFlags
= 0;
404 ada
->Header
.AceSize
= FIELD_OFFSET(ACCESS_DENIED_ACE
, SidStart
) +
405 FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]);
407 if (!(mode
& S_IRUSR
) && (mode
& (S_IRGRP
|S_IROTH
)))
408 ada
->Mask
|= FILE_GENERIC_READ
| FILE_GENERIC_EXECUTE
;
409 if (!(mode
& S_IWUSR
) && (mode
& (S_IWGRP
|S_IROTH
)))
410 ada
->Mask
|= FILE_GENERIC_WRITE
| DELETE
| FILE_DELETE_CHILD
;
411 ada
->Mask
&= ~STANDARD_RIGHTS_ALL
; /* never deny standard rights */
412 sid
= (SID
*)&ada
->SidStart
;
413 memcpy( sid
, user
, FIELD_OFFSET(SID
, SubAuthority
[user
->SubAuthorityCount
]) );
417 /* appropriate access rights for Everyone */
418 aaa
= (ACCESS_ALLOWED_ACE
*)ace_next( current_ace
);
419 current_ace
= &aaa
->Header
;
420 aaa
->Header
.AceType
= ACCESS_ALLOWED_ACE_TYPE
;
421 aaa
->Header
.AceFlags
= 0;
422 aaa
->Header
.AceSize
= FIELD_OFFSET(ACCESS_ALLOWED_ACE
, SidStart
) +
423 FIELD_OFFSET(SID
, SubAuthority
[world_sid
->SubAuthorityCount
]);
426 aaa
->Mask
|= FILE_GENERIC_READ
| FILE_GENERIC_EXECUTE
;
428 aaa
->Mask
|= FILE_GENERIC_WRITE
| DELETE
| FILE_DELETE_CHILD
;
429 sid
= (SID
*)&aaa
->SidStart
;
430 memcpy( sid
, world_sid
, FIELD_OFFSET(SID
, SubAuthority
[world_sid
->SubAuthorityCount
]) );
436 static struct security_descriptor
*file_get_sd( struct object
*obj
)
438 struct file
*file
= (struct file
*)obj
;
441 struct security_descriptor
*sd
;
443 assert( obj
->ops
== &file_ops
);
445 unix_fd
= get_file_unix_fd( file
);
447 if (unix_fd
== -1 || fstat( unix_fd
, &st
) == -1)
450 /* mode and uid the same? if so, no need to re-generate security descriptor */
451 if (obj
->sd
&& (st
.st_mode
& (S_IRWXU
|S_IRWXO
)) == (file
->mode
& (S_IRWXU
|S_IRWXO
)) &&
452 (st
.st_uid
== file
->uid
))
455 sd
= mode_to_sd( st
.st_mode
,
456 security_unix_uid_to_sid( st
.st_uid
),
457 token_get_primary_group( current
->process
->token
));
458 if (!sd
) return obj
->sd
;
460 file
->mode
= st
.st_mode
;
461 file
->uid
= st
.st_uid
;
467 static mode_t
file_access_to_mode( unsigned int access
)
471 access
= generic_file_map_access( access
);
472 if (access
& FILE_READ_DATA
) mode
|= 4;
473 if (access
& FILE_WRITE_DATA
) mode
|= 2;
474 if (access
& FILE_EXECUTE
) mode
|= 1;
478 mode_t
sd_to_mode( const struct security_descriptor
*sd
, const SID
*owner
)
481 mode_t denied_mode
= 0;
484 const ACL
*dacl
= sd_get_dacl( sd
, &present
);
485 const SID
*user
= token_get_user( current
->process
->token
);
488 const ACE_HEADER
*ace
= (const ACE_HEADER
*)(dacl
+ 1);
490 for (i
= 0; i
< dacl
->AceCount
; i
++, ace
= ace_next( ace
))
492 const ACCESS_ALLOWED_ACE
*aa_ace
;
493 const ACCESS_DENIED_ACE
*ad_ace
;
496 if (ace
->AceFlags
& INHERIT_ONLY_ACE
) continue;
498 switch (ace
->AceType
)
500 case ACCESS_DENIED_ACE_TYPE
:
501 ad_ace
= (const ACCESS_DENIED_ACE
*)ace
;
502 sid
= (const SID
*)&ad_ace
->SidStart
;
503 mode
= file_access_to_mode( ad_ace
->Mask
);
504 if (security_equal_sid( sid
, security_world_sid
))
506 denied_mode
|= (mode
<< 6) | (mode
<< 3) | mode
; /* all */
508 else if (security_equal_sid( sid
, owner
))
510 denied_mode
|= (mode
<< 6); /* user only */
512 else if ((security_equal_sid( user
, owner
) &&
513 token_sid_present( current
->process
->token
, sid
, TRUE
)))
515 denied_mode
|= (mode
<< 6) | (mode
<< 3); /* user + group */
518 case ACCESS_ALLOWED_ACE_TYPE
:
519 aa_ace
= (const ACCESS_ALLOWED_ACE
*)ace
;
520 sid
= (const SID
*)&aa_ace
->SidStart
;
521 mode
= file_access_to_mode( aa_ace
->Mask
);
522 if (security_equal_sid( sid
, security_world_sid
))
524 new_mode
|= (mode
<< 6) | (mode
<< 3) | mode
; /* all */
526 else if (security_equal_sid( sid
, owner
))
528 new_mode
|= (mode
<< 6); /* user only */
530 else if ((security_equal_sid( user
, owner
) &&
531 token_sid_present( current
->process
->token
, sid
, FALSE
)))
533 new_mode
|= (mode
<< 6) | (mode
<< 3); /* user + group */
540 /* no ACL means full access rights to anyone */
541 new_mode
= S_IRWXU
| S_IRWXG
| S_IRWXO
;
543 return new_mode
& ~denied_mode
;
546 static int file_set_sd( struct object
*obj
, const struct security_descriptor
*sd
,
547 unsigned int set_info
)
549 struct file
*file
= (struct file
*)obj
;
555 assert( obj
->ops
== &file_ops
);
557 unix_fd
= get_file_unix_fd( file
);
559 if (unix_fd
== -1 || fstat( unix_fd
, &st
) == -1) return 1;
561 if (set_info
& OWNER_SECURITY_INFORMATION
)
563 owner
= sd_get_owner( sd
);
566 set_error( STATUS_INVALID_SECURITY_DESCR
);
569 if (!obj
->sd
|| !security_equal_sid( owner
, sd_get_owner( obj
->sd
) ))
571 /* FIXME: get Unix uid and call fchown */
575 owner
= sd_get_owner( obj
->sd
);
577 owner
= token_get_user( current
->process
->token
);
579 /* group and sacl not supported */
581 if (set_info
& DACL_SECURITY_INFORMATION
)
583 /* keep the bits that we don't map to access rights in the ACL */
584 mode
= st
.st_mode
& (S_ISUID
|S_ISGID
|S_ISVTX
);
585 mode
|= sd_to_mode( sd
, owner
);
587 if (((st
.st_mode
^ mode
) & (S_IRWXU
|S_IRWXG
|S_IRWXO
)) && fchmod( unix_fd
, mode
) == -1)
596 static void file_destroy( struct object
*obj
)
598 struct file
*file
= (struct file
*)obj
;
599 assert( obj
->ops
== &file_ops
);
601 if (file
->fd
) release_object( file
->fd
);
604 /* set the last error depending on errno */
605 void file_set_error(void)
610 case EAGAIN
: set_error( STATUS_SHARING_VIOLATION
); break;
611 case EBADF
: set_error( STATUS_INVALID_HANDLE
); break;
612 case ENOSPC
: set_error( STATUS_DISK_FULL
); break;
616 case EPERM
: set_error( STATUS_ACCESS_DENIED
); break;
617 case EBUSY
: set_error( STATUS_FILE_LOCK_CONFLICT
); break;
618 case ENOENT
: set_error( STATUS_NO_SUCH_FILE
); break;
619 case EISDIR
: set_error( STATUS_FILE_IS_A_DIRECTORY
); break;
621 case EMFILE
: set_error( STATUS_TOO_MANY_OPENED_FILES
); break;
622 case EEXIST
: set_error( STATUS_OBJECT_NAME_COLLISION
); break;
623 case EINVAL
: set_error( STATUS_INVALID_PARAMETER
); break;
624 case ESPIPE
: set_error( STATUS_ILLEGAL_FUNCTION
); break;
625 case ENOTEMPTY
: set_error( STATUS_DIRECTORY_NOT_EMPTY
); break;
626 case EIO
: set_error( STATUS_ACCESS_VIOLATION
); break;
627 case ENOTDIR
: set_error( STATUS_NOT_A_DIRECTORY
); break;
628 case EFBIG
: set_error( STATUS_SECTION_TOO_BIG
); break;
629 case ENODEV
: set_error( STATUS_NO_SUCH_DEVICE
); break;
630 case ENXIO
: set_error( STATUS_NO_SUCH_DEVICE
); break;
632 case EOVERFLOW
: set_error( STATUS_INVALID_PARAMETER
); break;
635 perror("wineserver: file_set_error() can't map error");
636 set_error( STATUS_UNSUCCESSFUL
);
641 struct file
*get_file_obj( struct process
*process
, obj_handle_t handle
, unsigned int access
)
643 return (struct file
*)get_handle_obj( process
, handle
, access
, &file_ops
);
646 int get_file_unix_fd( struct file
*file
)
648 return get_unix_fd( file
->fd
);
652 DECL_HANDLER(create_file
)
655 struct fd
*root_fd
= NULL
;
656 const struct object_attributes
*objattr
= get_req_data();
657 const struct security_descriptor
*sd
;
659 data_size_t name_len
;
663 if (!objattr_is_valid( objattr
, get_req_data_size() ))
665 /* name is transferred in the unix codepage outside of the objattr structure */
666 if (objattr
->name_len
)
668 set_error( STATUS_INVALID_PARAMETER
);
672 if (objattr
->rootdir
)
676 if (!(root
= get_dir_obj( current
->process
, objattr
->rootdir
, 0 ))) return;
677 root_fd
= get_obj_fd( (struct object
*)root
);
678 release_object( root
);
679 if (!root_fd
) return;
682 sd
= objattr
->sd_len
? (const struct security_descriptor
*)(objattr
+ 1) : NULL
;
684 name
= (const char *)get_req_data() + sizeof(*objattr
) + objattr
->sd_len
;
685 name_len
= get_req_data_size() - sizeof(*objattr
) - objattr
->sd_len
;
688 if ((file
= create_file( root_fd
, name
, name_len
, req
->access
, req
->sharing
,
689 req
->create
, req
->options
, req
->attrs
, sd
)))
691 reply
->handle
= alloc_handle( current
->process
, file
, req
->access
, req
->attributes
);
692 release_object( file
);
694 if (root_fd
) release_object( root_fd
);
697 /* allocate a file handle for a Unix fd */
698 DECL_HANDLER(alloc_file_handle
)
704 if ((fd
= thread_get_inflight_fd( current
, req
->fd
)) == -1)
706 set_error( STATUS_INVALID_HANDLE
);
709 if ((file
= create_file_for_fd( fd
, req
->access
, FILE_SHARE_READ
| FILE_SHARE_WRITE
)))
711 reply
->handle
= alloc_handle( current
->process
, file
, req
->access
, req
->attributes
);
712 release_object( file
);
716 /* lock a region of a file */
717 DECL_HANDLER(lock_file
)
721 if ((file
= get_file_obj( current
->process
, req
->handle
, 0 )))
723 reply
->handle
= lock_fd( file
->fd
, req
->offset
, req
->count
, req
->shared
, req
->wait
);
724 reply
->overlapped
= is_overlapped( file
);
725 release_object( file
);
729 /* unlock a region of a file */
730 DECL_HANDLER(unlock_file
)
734 if ((file
= get_file_obj( current
->process
, req
->handle
, 0 )))
736 unlock_fd( file
->fd
, req
->offset
, req
->count
);
737 release_object( file
);