Whamcloud - gitweb
b=15977 analyse only consistent part of the log
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-fs.c
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  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 # define DEBUG_SUBSYSTEM S_LNET
38
39 #include <linux/fs.h>
40 #include <linux/kdev_t.h>
41 #include <linux/ctype.h>
42 #include <asm/uaccess.h>
43
44 #include <libcfs/libcfs.h>
45
46 cfs_file_t *
47 cfs_filp_open (const char *name, int flags, int mode, int *err)
48 {
49         /* XXX
50          * Maybe we need to handle flags and mode in the future
51          */
52         cfs_file_t      *filp = NULL;
53
54         filp = filp_open(name, flags, mode);
55         if (IS_ERR(filp)) {
56                 int rc;
57
58                 rc = PTR_ERR(filp);
59                 printk(KERN_ERR "LustreError: can't open %s file: err %d\n",
60                        name, rc);
61                 if (err)
62                         *err = rc;
63                 filp = NULL;
64         }
65         return filp;
66 }
67
68 /* write a userspace buffer to disk.
69  * NOTE: this returns 0 on success, not the number of bytes written. */
70 ssize_t
71 cfs_user_write (cfs_file_t *filp, const char *buf, size_t count, loff_t *offset)
72 {
73         mm_segment_t fs;
74         ssize_t size = 0;
75
76         fs = get_fs();
77         set_fs(KERNEL_DS);
78         while (count > 0) {
79                 size = filp->f_op->write(filp, (char *)buf, count, offset);
80                 if (size < 0)
81                         break;
82                 count -= size;
83                 size = 0;
84         }
85         set_fs(fs);
86
87         return size;
88 }
89
90 #if !(CFS_O_CREAT == O_CREAT && CFS_O_EXCL == O_EXCL && \
91      CFS_O_TRUNC == O_TRUNC && CFS_O_APPEND == O_APPEND &&\
92      CFS_O_NONBLOCK == O_NONBLOCK && CFS_O_NDELAY == O_NDELAY &&\
93      CFS_O_SYNC == O_SYNC && CFS_O_ASYNC == FASYNC &&\
94      CFS_O_DIRECT == O_DIRECT && CFS_O_LARGEFILE == O_LARGEFILE &&\
95      CFS_O_DIRECTORY == O_DIRECTORY && CFS_O_NOFOLLOW == O_NOFOLLOW)
96
97 int cfs_oflags2univ(int flags)
98 {
99         int f; 
100         
101         f = flags & O_ACCMODE;
102         f |= (flags & O_CREAT) ? CFS_O_CREAT: 0;
103         f |= (flags & O_EXCL) ? CFS_O_EXCL: 0;
104         f |= (flags & O_NOCTTY) ? CFS_O_NOCTTY: 0;
105         f |= (flags & O_TRUNC) ? CFS_O_TRUNC: 0;
106         f |= (flags & O_APPEND) ? CFS_O_APPEND: 0;
107         f |= (flags & O_NONBLOCK) ? CFS_O_NONBLOCK: 0;
108         f |= (flags & O_SYNC)? CFS_O_SYNC: 0;
109         f |= (flags & FASYNC)? CFS_O_ASYNC: 0;
110         f |= (flags & O_DIRECTORY)? CFS_O_DIRECTORY: 0;
111         f |= (flags & O_DIRECT)? CFS_O_DIRECT: 0;
112         f |= (flags & O_LARGEFILE)? CFS_O_LARGEFILE: 0;
113         f |= (flags & O_NOFOLLOW)? CFS_O_NOFOLLOW: 0;
114         f |= (flags & O_NOATIME)? CFS_O_NOATIME: 0;
115         return f;
116 }
117 #else
118
119 int cfs_oflags2univ(int flags)
120 {
121         return (flags);
122 }
123 #endif
124
125 /* 
126  * XXX Liang: we don't need cfs_univ2oflags() now.
127  */
128 int cfs_univ2oflags(int flags)
129 {
130         return (flags);
131 }
132
133 EXPORT_SYMBOL(cfs_filp_open);
134 EXPORT_SYMBOL(cfs_user_write);
135 EXPORT_SYMBOL(cfs_oflags2univ);
136 EXPORT_SYMBOL(cfs_univ2oflags);