Whamcloud - gitweb
LU-812 compat: file_operations.fsync needs 4 arguments
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-fs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2012, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  *
38  * libcfs/include/libcfs/linux/linux-fs.h
39  *
40  * Basic library routines.
41  */
42
43 #ifndef __LIBCFS_LINUX_CFS_FS_H__
44 #define __LIBCFS_LINUX_CFS_FS_H__
45
46 #ifndef __LIBCFS_LIBCFS_H__
47 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
48 #endif
49
50 #ifndef __KERNEL__
51 #error This include is only for kernel use.
52 #endif
53
54 #include <linux/fs.h>
55 #include <linux/stat.h>
56 #include <linux/mount.h>
57 #include <linux/backing-dev.h>
58
59 typedef struct file cfs_file_t;
60 typedef struct dentry cfs_dentry_t;
61 typedef struct dirent64 cfs_dirent_t;
62 typedef struct kstatfs cfs_kstatfs_t;
63
64 #define cfs_filp_size(f)               (i_size_read((f)->f_dentry->d_inode))
65 #define cfs_filp_poff(f)                (&(f)->f_pos)
66
67 /* 
68  * XXX Do we need to parse flags and mode in cfs_filp_open? 
69  */
70 cfs_file_t *cfs_filp_open (const char *name, int flags, int mode, int *err);
71 #ifdef HAVE_FILE_FSYNC_4ARGS
72 # define cfs_do_fsync(fp, flag)    ((fp)->f_op->fsync(fp, 0, LLONG_MAX, flag))
73 #elif defined(HAVE_FILE_FSYNC_2ARGS)
74 # define cfs_do_fsync(fp, flag)    ((fp)->f_op->fsync(fp, flag))
75 #else
76 # define cfs_do_fsync(fp, flag)    ((fp)->f_op->fsync(fp, (fp)->f_dentry, flag))
77 #endif
78 #define cfs_filp_close(f)                   filp_close(f, NULL)
79 #define cfs_filp_read(fp, buf, size, pos)   (fp)->f_op->read((fp), (buf), (size), pos)
80 #define cfs_filp_write(fp, buf, size, pos)  (fp)->f_op->write((fp), (buf), (size), pos)
81 #define cfs_filp_fsync(fp)                  cfs_do_fsync(fp, 1)
82
83 #define cfs_get_file(f)                     get_file(f)
84 #define cfs_get_fd(x)                       fget(x)
85 #define cfs_put_file(f)                     fput(f)
86 #define cfs_file_count(f)                   file_count(f)
87
88 typedef struct file_lock cfs_flock_t;
89 #define cfs_flock_type(fl)                  ((fl)->fl_type)
90 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
91 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
92 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
93 #define cfs_flock_start(fl)                 ((fl)->fl_start)
94 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
95 #define cfs_flock_end(fl)                   ((fl)->fl_end)
96 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
97
98 ssize_t cfs_user_write (cfs_file_t *filp, const char *buf, size_t count, loff_t *offset);
99
100 #define CFS_IFSHIFT 12
101
102 #define CFS_IFTODT(type)           (((type) & S_IFMT) >> CFS_IFSHIFT)
103 #define CFS_DTTOIF(dirtype)        ((dirtype) << CFS_IFSHIFT)
104
105 #endif