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