file.c 20.3 KB
Newer Older
1 2 3 4
/*
 * Server-side file management
 *
 * Copyright (C) 1998 Alexandre Julliard
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 20
 */

21
#include "config.h"
22
#include "wine/port.h"
23

24 25 26
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
27
#include <string.h>
28
#include <stdlib.h>
29
#include <errno.h>
30
#ifdef HAVE_SYS_ERRNO_H
31
#include <sys/errno.h>
32
#endif
33 34 35 36 37
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
Steven Edwards's avatar
Steven Edwards committed
38
#ifdef HAVE_UTIME_H
39
#include <utime.h>
Steven Edwards's avatar
Steven Edwards committed
40
#endif
41 42

#include "winerror.h"
43
#include "winbase.h"
44

45
#include "file.h"
46 47
#include "handle.h"
#include "thread.h"
48
#include "request.h"
49
#include "async.h"
50 51 52

struct file
{
53
    struct object       obj;        /* object header */
54
    struct fd          *fd;         /* file descriptor for this file */
55 56 57 58 59
    struct file        *next;       /* next file in hashing list */
    char               *name;       /* file name */
    unsigned int        access;     /* file access (GENERIC_READ/WRITE) */
    unsigned int        flags;      /* flags (FILE_FLAG_*) */
    unsigned int        sharing;    /* file sharing mode */
60
    int                 drive_type; /* type of drive the file is on */
61 62
    struct async_queue  read_q;
    struct async_queue  write_q;
63 64
};

65 66 67 68
#define NAME_HASH_SIZE 37

static struct file *file_hash[NAME_HASH_SIZE];

69
static void file_dump( struct object *obj, int verbose );
70
static struct fd *file_get_fd( struct object *obj );
71
static void file_destroy( struct object *obj );
72 73 74

static int file_get_poll_events( struct fd *fd );
static void file_poll_event( struct fd *fd, int event );
75
static int file_flush( struct fd *fd, struct event **event );
76 77
static int file_get_info( struct fd *fd, struct get_file_info_reply *reply, int *flags );
static void file_queue_async( struct fd *fd, void *ptr, unsigned int status, int type, int count );
78 79 80

static const struct object_ops file_ops =
{
81 82
    sizeof(struct file),          /* size */
    file_dump,                    /* dump */
83 84 85
    default_fd_add_queue,         /* add_queue */
    default_fd_remove_queue,      /* remove_queue */
    default_fd_signaled,          /* signaled */
86
    no_satisfied,                 /* satisfied */
87
    file_get_fd,                  /* get_fd */
88 89 90 91 92
    file_destroy                  /* destroy */
};

static const struct fd_ops file_fd_ops =
{
93
    file_get_poll_events,         /* get_poll_events */
94
    file_poll_event,              /* poll_event */
95 96
    file_flush,                   /* flush */
    file_get_info,                /* get_file_info */
97
    file_queue_async              /* queue_async */
98 99
};

100 101 102
static int get_name_hash( const char *name )
{
    int hash = 0;
Eric Pouech's avatar
Eric Pouech committed
103
    while (*name) hash ^= (unsigned char)*name++;
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    return hash % NAME_HASH_SIZE;
}

/* check if the desired access is possible without violating */
/* the sharing mode of other opens of the same file */
static int check_sharing( const char *name, int hash, unsigned int access,
                          unsigned int sharing )
{
    struct file *file;
    unsigned int existing_sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
    unsigned int existing_access = 0;

    for (file = file_hash[hash]; file; file = file->next)
    {
        if (strcmp( file->name, name )) continue;
        existing_sharing &= file->sharing;
        existing_access |= file->access;
    }
122 123 124 125
    if ((access & GENERIC_READ) && !(existing_sharing & FILE_SHARE_READ)) goto error;
    if ((access & GENERIC_WRITE) && !(existing_sharing & FILE_SHARE_WRITE)) goto error;
    if ((existing_access & GENERIC_READ) && !(sharing & FILE_SHARE_READ)) goto error;
    if ((existing_access & GENERIC_WRITE) && !(sharing & FILE_SHARE_WRITE)) goto error;
126
    return 1;
127
 error:
128
    set_error( STATUS_SHARING_VIOLATION );
129
    return 0;
130 131
}

132 133
/* create a file from a file descriptor */
/* if the function fails the fd is closed */
134
static struct file *create_file_for_fd( int fd, unsigned int access, unsigned int sharing,
135
                                        unsigned int attrs, int drive_type )
136 137
{
    struct file *file;
138

139
    if ((file = alloc_object( &file_ops )))
140
    {
141 142 143 144 145 146
        file->name       = NULL;
        file->next       = NULL;
        file->access     = access;
        file->flags      = attrs;
        file->sharing    = sharing;
        file->drive_type = drive_type;
147 148 149 150 151
        if (file->flags & FILE_FLAG_OVERLAPPED)
        {
            init_async_queue (&file->read_q);
            init_async_queue (&file->write_q);
        }
152
        if (!(file->fd = create_anonymous_fd( &file_fd_ops, fd, &file->obj )))
153 154 155 156
        {
            release_object( file );
            return NULL;
        }
157 158 159
    }
    return file;
}
160 161


162
static struct file *create_file( const char *nameptr, size_t len, unsigned int access,
163 164
                                 unsigned int sharing, int create, unsigned int attrs,
                                 int drive_type )
165 166 167 168
{
    struct file *file;
    int hash, flags;
    char *name;
169
    mode_t mode;
170

171 172 173
    if (!(name = mem_alloc( len + 1 ))) return NULL;
    memcpy( name, nameptr, len );
    name[len] = 0;
174

175 176 177
    /* check sharing mode */
    hash = get_name_hash( name );
    if (!check_sharing( name, hash, access, sharing )) goto error;
178

179
    switch(create)
180
    {
181 182 183 184 185
    case CREATE_NEW:        flags = O_CREAT | O_EXCL; break;
    case CREATE_ALWAYS:     flags = O_CREAT | O_TRUNC; break;
    case OPEN_ALWAYS:       flags = O_CREAT; break;
    case TRUNCATE_EXISTING: flags = O_TRUNC; break;
    case OPEN_EXISTING:     flags = 0; break;
186
    default:                set_error( STATUS_INVALID_PARAMETER ); goto error;
187
    }
188
    switch(access & (GENERIC_READ | GENERIC_WRITE))
189
    {
190 191 192 193
    case 0: break;
    case GENERIC_READ:  flags |= O_RDONLY; break;
    case GENERIC_WRITE: flags |= O_WRONLY; break;
    case GENERIC_READ|GENERIC_WRITE: flags |= O_RDWR; break;
194
    }
195 196 197 198 199
    mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666;

    if (len >= 4 &&
        (!strcasecmp( name + len - 4, ".exe" ) || !strcasecmp( name + len - 4, ".com" )))
        mode |= 0111;
200

201 202 203 204 205 206 207 208 209 210
    if (!(file = alloc_object( &file_ops ))) goto error;

    file->access     = access;
    file->flags      = attrs;
    file->sharing    = sharing;
    file->drive_type = drive_type;
    file->name       = name;
    file->next       = file_hash[hash];
    file_hash[hash]  = file;
    if (file->flags & FILE_FLAG_OVERLAPPED)
211
    {
212 213
        init_async_queue (&file->read_q);
        init_async_queue (&file->write_q);
214
    }
215

216 217 218 219 220 221 222 223
    /* FIXME: should set error to STATUS_OBJECT_NAME_COLLISION if file existed before */
    if (!(file->fd = alloc_fd( &file_fd_ops, &file->obj )) ||
        !(file->fd = open_fd( file->fd, name, flags | O_NONBLOCK | O_LARGEFILE, &mode )))
    {
        release_object( file );
        return NULL;
    }
    /* refuse to open a directory */
224
    if (S_ISDIR(mode) && !(file->flags & FILE_FLAG_BACKUP_SEMANTICS))
225
    {
226 227
        set_error( STATUS_ACCESS_DENIED );
        release_object( file );
228 229
        return NULL;
    }
230 231 232 233 234
    return file;

 error:
    free( name );
    return NULL;
235 236
}

237 238 239 240 241 242
/* check if two file objects point to the same file */
int is_same_file( struct file *file1, struct file *file2 )
{
    return !strcmp( file1->name, file2->name );
}

243 244 245 246 247 248
/* get the type of drive the file is on */
int get_file_drive_type( struct file *file )
{
    return file->drive_type;
}

249 250
/* create a temp file for anonymous mappings */
struct file *create_temp_file( int access )
251
{
252
    char tmpfn[16];
253 254
    int fd;

255
    sprintf( tmpfn, "anonmap.XXXXXX" );  /* create it in the server directory */
256
    fd = mkstemps( tmpfn, 0 );
257 258 259
    if (fd == -1)
    {
        file_set_error();
260
        return NULL;
261
    }
262
    unlink( tmpfn );
263
    return create_file_for_fd( fd, access, 0, 0, DRIVE_FIXED );
264 265
}

266 267 268 269
static void file_dump( struct object *obj, int verbose )
{
    struct file *file = (struct file *)obj;
    assert( obj->ops == &file_ops );
270
    fprintf( stderr, "File fd=%p flags=%08x name='%s'\n", file->fd, file->flags, file->name );
271 272
}

273
static int file_get_poll_events( struct fd *fd )
274
{
275
    struct file *file = get_fd_user( fd );
276
    int events = 0;
277
    assert( file->obj.ops == &file_ops );
278 279
    if (file->access & GENERIC_READ) events |= POLLIN;
    if (file->access & GENERIC_WRITE) events |= POLLOUT;
280
    return events;
281 282
}

283
static void file_poll_event( struct fd *fd, int event )
284
{
285 286
    struct file *file = get_fd_user( fd );
    assert( file->obj.ops == &file_ops );
287 288 289 290 291 292 293 294 295 296 297 298 299
    if ( file->flags & FILE_FLAG_OVERLAPPED )
    {
        if( IS_READY(file->read_q) && (POLLIN & event) )
        {
            async_notify(file->read_q.head, STATUS_ALERTED);
            return;
        }
        if( IS_READY(file->write_q) && (POLLOUT & event) )
        {
            async_notify(file->write_q.head, STATUS_ALERTED);
            return;
        }
    }
300
    default_poll_event( fd, event );
301 302 303
}


304
static int file_flush( struct fd *fd, struct event **event )
305
{
306
    int ret = (fsync( get_unix_fd(fd) ) != -1);
307 308
    if (!ret) file_set_error();
    return ret;
309 310
}

311
static int file_get_info( struct fd *fd, struct get_file_info_reply *reply, int *flags )
312
{
313
    struct stat st;
314 315
    struct file *file = get_fd_user( fd );
    int unix_fd = get_unix_fd( fd );
316

317
    if (reply)
318
    {
319
        if (fstat( unix_fd, &st ) == -1)
320 321 322 323 324
        {
            file_set_error();
            return FD_TYPE_INVALID;
        }
        if (S_ISCHR(st.st_mode) || S_ISFIFO(st.st_mode) ||
325
            S_ISSOCK(st.st_mode) || isatty(unix_fd)) reply->type = FILE_TYPE_CHAR;
326 327 328 329 330 331
        else reply->type = FILE_TYPE_DISK;
        if (S_ISDIR(st.st_mode)) reply->attr = FILE_ATTRIBUTE_DIRECTORY;
        else reply->attr = FILE_ATTRIBUTE_ARCHIVE;
        if (!(st.st_mode & S_IWUSR)) reply->attr |= FILE_ATTRIBUTE_READONLY;
        reply->access_time = st.st_atime;
        reply->write_time  = st.st_mtime;
332
        reply->change_time = st.st_ctime;
333 334
        if (S_ISDIR(st.st_mode))
        {
335 336 337 338
            reply->size_high  = 0;
            reply->size_low   = 0;
            reply->alloc_high = 0;
            reply->alloc_low  = 0;
339 340 341
        }
        else
        {
342 343 344 345 346 347
            file_pos_t  alloc;
            reply->size_high  = st.st_size >> 32;
            reply->size_low   = st.st_size & 0xffffffff;
            alloc = (file_pos_t)st.st_blksize * st.st_blocks;
            reply->alloc_high = alloc >> 32;
            reply->alloc_low  = alloc & 0xffffffff;
348
        }
349 350 351 352
        reply->links       = st.st_nlink;
        reply->index_high  = st.st_dev;
        reply->index_low   = st.st_ino;
        reply->serial      = 0; /* FIXME */
353
    }
354 355
    *flags = 0;
    if (file->flags & FILE_FLAG_OVERLAPPED) *flags |= FD_FLAG_OVERLAPPED;
356
    return FD_TYPE_DEFAULT;
357 358
}

359
static void file_queue_async(struct fd *fd, void *ptr, unsigned int status, int type, int count)
360
{
361
    struct file *file = get_fd_user( fd );
362
    struct async *async;
363 364
    struct async_queue *q;

365
    assert( file->obj.ops == &file_ops );
366 367 368 369

    if ( !(file->flags & FILE_FLAG_OVERLAPPED) )
    {
        set_error ( STATUS_INVALID_HANDLE );
370
        return;
371 372 373 374 375 376 377 378 379 380 381 382
    }

    switch(type)
    {
    case ASYNC_TYPE_READ:
        q = &file->read_q;
        break;
    case ASYNC_TYPE_WRITE:
        q = &file->write_q;
        break;
    default:
        set_error( STATUS_INVALID_PARAMETER );
383
        return;
384 385
    }

386 387 388 389
    async = find_async ( q, current, ptr );

    if ( status == STATUS_PENDING )
    {
390
        int events;
391

392
        if ( !async )
393
            async = create_async ( &file->obj, current, ptr );
394 395 396 397 398 399
        if ( !async )
            return;

        async->status = STATUS_PENDING;
        if ( !async->q )
            async_insert( q, async );
400 401

        /* Check if the new pending request can be served immediately */
402 403
        events = check_fd_events( fd, file_get_poll_events( fd ) );
        if (events) file_poll_event ( fd, events );
404 405 406
    }
    else if ( async ) destroy_async ( async );
    else set_error ( STATUS_INVALID_PARAMETER );
407

408 409 410 411 412 413 414 415
    set_fd_events( fd, file_get_poll_events( fd ));
}

static struct fd *file_get_fd( struct object *obj )
{
    struct file *file = (struct file *)obj;
    assert( obj->ops == &file_ops );
    return (struct fd *)grab_object( file->fd );
416 417
}

418
static void file_destroy( struct object *obj )
419
{
420 421
    struct file *file = (struct file *)obj;
    assert( obj->ops == &file_ops );
422

423 424 425 426 427 428 429
    if (file->name)
    {
        /* remove it from the hashing list */
        struct file **pptr = &file_hash[get_name_hash( file->name )];
        while (*pptr && *pptr != file) pptr = &(*pptr)->next;
        assert( *pptr );
        *pptr = (*pptr)->next;
430
        if (file->flags & FILE_FLAG_DELETE_ON_CLOSE) unlink( file->name );
431 432
        free( file->name );
    }
433 434 435 436 437
    if (file->flags & FILE_FLAG_OVERLAPPED)
    {
        destroy_async_queue (&file->read_q);
        destroy_async_queue (&file->write_q);
    }
438
    if (file->fd) release_object( file->fd );
439 440 441 442 443 444 445
}

/* set the last error depending on errno */
void file_set_error(void)
{
    switch (errno)
    {
446 447 448
    case EAGAIN:    set_error( STATUS_SHARING_VIOLATION ); break;
    case EBADF:     set_error( STATUS_INVALID_HANDLE ); break;
    case ENOSPC:    set_error( STATUS_DISK_FULL ); break;
449
    case EACCES:
450
    case ESRCH:
451 452 453 454 455
    case EPERM:     set_error( STATUS_ACCESS_DENIED ); break;
    case EROFS:     set_error( STATUS_MEDIA_WRITE_PROTECTED ); break;
    case EBUSY:     set_error( STATUS_FILE_LOCK_CONFLICT ); break;
    case ENOENT:    set_error( STATUS_NO_SUCH_FILE ); break;
    case EISDIR:    set_error( 0xc0010000 | ERROR_CANNOT_MAKE /* FIXME */ ); break;
456
    case ENFILE:
457 458 459 460 461 462
    case EMFILE:    set_error( STATUS_NO_MORE_FILES ); break;
    case EEXIST:    set_error( STATUS_OBJECT_NAME_COLLISION ); break;
    case EINVAL:    set_error( STATUS_INVALID_PARAMETER ); break;
    case ESPIPE:    set_error( 0xc0010000 | ERROR_SEEK /* FIXME */ ); break;
    case ENOTEMPTY: set_error( STATUS_DIRECTORY_NOT_EMPTY ); break;
    case EIO:       set_error( STATUS_ACCESS_VIOLATION ); break;
463
    case EOVERFLOW: set_error( STATUS_INVALID_PARAMETER ); break;
464
    default:        perror("file_set_error"); set_error( ERROR_UNKNOWN /* FIXME */ ); break;
465
    }
466 467
}

468
struct file *get_file_obj( struct process *process, obj_handle_t handle, unsigned int access )
469
{
470
    return (struct file *)get_handle_obj( process, handle, access, &file_ops );
471
}
472

473 474
int get_file_unix_fd( struct file *file )
{
475
    return get_unix_fd( file->fd );
476 477
}

478
static int set_file_pointer( obj_handle_t handle, unsigned int *low, int *high, int whence )
479 480
{
    struct file *file;
481
    off_t result,xto;
482

483
    xto = *low+((off_t)*high<<32);
484
    if (!(file = get_file_obj( current->process, handle, 0 )))
485
        return 0;
486
    if ((result = lseek( get_file_unix_fd(file), xto, whence))==-1)
487 488
    {
        /* Check for seek before start of file */
489 490 491

        /* also check EPERM due to SuSE7 2.2.16 lseek() EPERM kernel bug */
        if (((errno == EINVAL) || (errno == EPERM))
492
            && (whence != SEEK_SET) && (*high < 0))
493
            set_error( 0xc0010000 | ERROR_NEGATIVE_SEEK /* FIXME */ );
494 495 496 497 498
        else
            file_set_error();
        release_object( file );
        return 0;
    }
499 500
    *low  = result & 0xffffffff;
    *high = result >> 32;
501 502 503 504
    release_object( file );
    return 1;
}

505 506
/* extend a file beyond the current end of file */
static int extend_file( struct file *file, off_t size )
507
{
508
    static const char zero;
509
    int unix_fd = get_file_unix_fd( file );
510

511 512
    /* extend the file one byte beyond the requested size and then truncate it */
    /* this should work around ftruncate implementations that can't extend files */
513 514
    if ((lseek( unix_fd, size, SEEK_SET ) != -1) &&
        (write( unix_fd, &zero, 1 ) != -1))
515
    {
516
        ftruncate( unix_fd, size );
517
        return 1;
518
    }
519 520 521 522 523 524 525 526
    file_set_error();
    return 0;
}

/* truncate file at current position */
static int truncate_file( struct file *file )
{
    int ret = 0;
527
    int unix_fd = get_file_unix_fd( file );
528 529
    off_t pos = lseek( unix_fd, 0, SEEK_CUR );
    off_t eof = lseek( unix_fd, 0, SEEK_END );
530 531 532 533

    if (eof < pos) ret = extend_file( file, pos );
    else
    {
534
        if (ftruncate( unix_fd, pos ) != -1) ret = 1;
535 536
        else file_set_error();
    }
537
    lseek( unix_fd, pos, SEEK_SET );  /* restore file pos */
538
    return ret;
539 540
}

541 542 543
/* try to grow the file to the specified size */
int grow_file( struct file *file, int size_high, int size_low )
{
544
    int ret = 0;
545
    struct stat st;
546
    int unix_fd = get_file_unix_fd( file );
547
    off_t old_pos, size = size_low + (((off_t)size_high)<<32);
548

549
    if (fstat( unix_fd, &st ) == -1)
550 551 552 553
    {
        file_set_error();
        return 0;
    }
554
    if (st.st_size >= size) return 1;  /* already large enough */
555
    old_pos = lseek( unix_fd, 0, SEEK_CUR );  /* save old pos */
556
    ret = extend_file( file, size );
557
    lseek( unix_fd, old_pos, SEEK_SET );  /* restore file pos */
558
    return ret;
559 560
}

561
static int set_file_time( obj_handle_t handle, time_t access_time, time_t write_time )
562 563
{
    struct file *file;
564
    struct utimbuf utimbuf;
565

566
    if (!(file = get_file_obj( current->process, handle, GENERIC_WRITE )))
567
        return 0;
568 569 570 571 572 573
    if (!file->name)
    {
        set_error( STATUS_INVALID_HANDLE );
        release_object( file );
        return 0;
    }
574
    if (!access_time || !write_time)
575
    {
576 577 578 579
        struct stat st;
        if (stat( file->name, &st ) == -1) goto error;
        if (!access_time) access_time = st.st_atime;
        if (!write_time) write_time = st.st_mtime;
580
    }
581 582 583
    utimbuf.actime  = access_time;
    utimbuf.modtime = write_time;
    if (utime( file->name, &utimbuf ) == -1) goto error;
584 585
    release_object( file );
    return 1;
586 587 588 589
 error:
    file_set_error();
    release_object( file );
    return 0;
590
}
591

592 593 594
/* create a file */
DECL_HANDLER(create_file)
{
595
    struct file *file;
596

597 598
    reply->handle = 0;
    if ((file = create_file( get_req_data(), get_req_data_size(), req->access,
599
                             req->sharing, req->create, req->attrs, req->drive_type )))
600
    {
601
        reply->handle = alloc_handle( current->process, file, req->access, req->inherit );
602
        release_object( file );
603
    }
604 605 606 607 608 609
}

/* allocate a file handle for a Unix fd */
DECL_HANDLER(alloc_file_handle)
{
    struct file *file;
610
    int fd;
611

612
    reply->handle = 0;
613
    if ((fd = thread_get_inflight_fd( current, req->fd )) == -1)
614
    {
615 616 617
        set_error( STATUS_INVALID_HANDLE );
        return;
    }
618 619
    if ((file = create_file_for_fd( fd, req->access, FILE_SHARE_READ | FILE_SHARE_WRITE,
                                    0, DRIVE_UNKNOWN )))
620
    {
621
        reply->handle = alloc_handle( current->process, file, req->access, req->inherit );
622
        release_object( file );
623 624 625 626 627 628
    }
}

/* set a file current position */
DECL_HANDLER(set_file_pointer)
{
629 630 631
    int high = req->high;
    int low  = req->low;
    set_file_pointer( req->handle, &low, &high, req->whence );
632 633
    reply->new_low  = low;
    reply->new_high = high;
634 635 636 637 638
}

/* truncate (or extend) a file */
DECL_HANDLER(truncate_file)
{
639 640 641 642 643 644 645
    struct file *file;

    if ((file = get_file_obj( current->process, req->handle, GENERIC_WRITE )))
    {
        truncate_file( file );
        release_object( file );
    }
646 647 648 649 650 651 652 653 654 655 656 657
}

/* set a file access and modification times */
DECL_HANDLER(set_file_time)
{
    set_file_time( req->handle, req->access_time, req->write_time );
}

/* lock a region of a file */
DECL_HANDLER(lock_file)
{
    struct file *file;
658 659
    file_pos_t offset = ((file_pos_t)req->offset_high << 32) | req->offset_low;
    file_pos_t count = ((file_pos_t)req->count_high << 32) | req->count_low;
660 661 662

    if ((file = get_file_obj( current->process, req->handle, 0 )))
    {
663 664
        reply->handle = lock_fd( file->fd, offset, count, req->shared, req->wait );
        reply->overlapped = (file->flags & FILE_FLAG_OVERLAPPED) != 0;
665 666 667 668 669 670 671 672
        release_object( file );
    }
}

/* unlock a region of a file */
DECL_HANDLER(unlock_file)
{
    struct file *file;
673 674
    file_pos_t offset = ((file_pos_t)req->offset_high << 32) | req->offset_low;
    file_pos_t count = ((file_pos_t)req->count_high << 32) | req->count_low;
675 676 677

    if ((file = get_file_obj( current->process, req->handle, 0 )))
    {
678
        unlock_fd( file->fd, offset, count );
679 680 681
        release_object( file );
    }
}