Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lnet / 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  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Basic library routines. 
22  *
23  */
24
25 #ifndef __LIBCFS_LINUX_CFS_FS_H__
26 #define __LIBCFS_LINUX_CFS_FS_H__
27
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
30 #endif
31
32 #ifdef __KERNEL__
33 #include <linux/fs.h>
34 #include <linux/stat.h>
35 #include <linux/mount.h>
36 #else /* !__KERNEL__ */
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <unistd.h>
40 #include <fcntl.h>
41 #include <errno.h>
42 #include <string.h>
43 #include <sys/mount.h>
44 #include <mntent.h>
45 #endif  /* __KERNEL__ */
46
47 typedef struct file cfs_file_t;
48 typedef struct dentry cfs_dentry_t;
49 typedef struct dirent64 cfs_dirent_t;
50
51 #ifdef __KERNEL__
52 #define cfs_filp_size(f)               (i_size_read((f)->f_dentry->d_inode))
53 #define cfs_filp_poff(f)                (&(f)->f_pos)
54
55 /* 
56  * XXX Do we need to parse flags and mode in cfs_filp_open? 
57  */
58 cfs_file_t *cfs_filp_open (const char *name, int flags, int mode, int *err);
59 #define cfs_filp_close(f)                   filp_close(f, NULL)
60 #define cfs_filp_read(fp, buf, size, pos)   (fp)->f_op->read((fp), (buf), (size), pos)
61 #define cfs_filp_write(fp, buf, size, pos)  (fp)->f_op->write((fp), (buf), (size), pos)
62 #define cfs_filp_fsync(fp)                  (fp)->f_op->fsync((fp), (fp)->f_dentry, 1)
63
64 #define cfs_get_file(f)                     get_file(f)
65 #define cfs_put_file(f)                     fput(f)
66 #define cfs_file_count(f)                   file_count(f)
67
68 typedef struct file_lock cfs_flock_t;
69 #define cfs_flock_type(fl)                  ((fl)->fl_type)
70 #define cfs_flock_set_type(fl, type)        do { (fl)->fl_type = (type); } while(0)
71 #define cfs_flock_pid(fl)                   ((fl)->fl_pid)
72 #define cfs_flock_set_pid(fl, pid)          do { (fl)->fl_pid = (pid); } while(0)
73 #define cfs_flock_start(fl)                 ((fl)->fl_start)
74 #define cfs_flock_set_start(fl, start)      do { (fl)->fl_start = (start); } while(0)
75 #define cfs_flock_end(fl)                   ((fl)->fl_end)
76 #define cfs_flock_set_end(fl, end)          do { (fl)->fl_end = (end); } while(0)
77
78 ssize_t cfs_user_write (cfs_file_t *filp, const char *buf, size_t count, loff_t *offset);
79
80 #endif
81
82 #endif