summaryrefslogtreecommitdiffstats
path: root/contrib/fuse-lib/misc.c
blob: 0c41b1a1917b2d298a880cb5d79fa09988bfa896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
  FUSE: Filesystem in Userspace
  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>

  This program can be distributed under the terms of the GNU LGPLv2.
  See the file COPYING.LIB
*/

#include <stdint.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include "glusterfs.h"
#include "fuse_kernel.h"
#include "fuse-misc.h"

unsigned long
calc_timeout_sec (double t)
{
        if (t > (double) ULONG_MAX)
                return ULONG_MAX;
        else if (t < 0.0)
                return 0;
        else
                return (unsigned long) t;
}

unsigned int
calc_timeout_nsec (double t)
{
        double f = t - (double) calc_timeout_sec (t);
        if (f < 0.0)
                return 0;
        else if (f >= 0.999999999)
                return 999999999;
        else
                return (unsigned int) (f * 1.0e9);
}

void
convert_fuse_file_lock (struct fuse_file_lock *fl, struct gf_flock *flock,
                        uint64_t lk_owner)
{
        memset (flock, 0, sizeof (struct flock));
        flock->l_type = fl->type;
        flock->l_whence = SEEK_SET;
        flock->l_start = fl->start;
        if (fl->end == OFFSET_MAX)
                flock->l_len = 0;
        else
                flock->l_len = fl->end - fl->start + 1;
        flock->l_pid = fl->pid;
        set_lk_owner_from_uint64 (&flock->l_owner, lk_owner);
}