Whamcloud - gitweb
LU-1402 libcfs: CFS_ALLOC_HIGH is __GFP_HIGHMEM
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-fs.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 # define DEBUG_SUBSYSTEM S_LNET
36
37 #include <linux/fs.h>
38 #include <linux/kdev_t.h>
39 #include <linux/ctype.h>
40 #include <asm/uaccess.h>
41
42 #include <libcfs/libcfs.h>
43
44 cfs_file_t *
45 cfs_filp_open (const char *name, int flags, int mode, int *err)
46 {
47         /* XXX
48          * Maybe we need to handle flags and mode in the future
49          */
50         cfs_file_t      *filp = NULL;
51
52         filp = filp_open(name, flags, mode);
53         if (IS_ERR(filp)) {
54                 int rc;
55
56                 rc = PTR_ERR(filp);
57                 printk(KERN_ERR "LustreError: can't open %s file: err %d\n",
58                        name, rc);
59                 if (err)
60                         *err = rc;
61                 filp = NULL;
62         }
63         return filp;
64 }
65
66 /* write a userspace buffer to disk.
67  * NOTE: this returns 0 on success, not the number of bytes written. */
68 ssize_t
69 cfs_user_write (cfs_file_t *filp, const char *buf, size_t count, loff_t *offset)
70 {
71         mm_segment_t fs;
72         ssize_t size = 0;
73
74         fs = get_fs();
75         set_fs(KERNEL_DS);
76         while ((ssize_t)count > 0) {
77                 size = filp->f_op->write(filp, (char *)buf, count, offset);
78                 if (size < 0)
79                         break;
80                 count -= size;
81                 buf += size;
82                 size = 0;
83         }
84         set_fs(fs);
85
86         return size;
87 }
88
89 #if !(CFS_O_CREAT == O_CREAT && CFS_O_EXCL == O_EXCL && \
90      CFS_O_NOACCESS == O_NOACCESS &&\
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_NOACCESS;
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);