Whamcloud - gitweb
21fa32cd32979ad832aa7a41c47bff44fa1d12a3
[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 /* write a userspace buffer to disk.
45  * NOTE: this returns 0 on success, not the number of bytes written. */
46 ssize_t
47 filp_user_write(struct file *filp, const void *buf, size_t count,
48                 loff_t *offset)
49 {
50         mm_segment_t fs;
51         ssize_t size = 0;
52
53         fs = get_fs();
54         set_fs(KERNEL_DS);
55         while ((ssize_t)count > 0) {
56                 size = vfs_write(filp, (const void __user *)buf, count, offset);
57                 if (size < 0)
58                         break;
59                 count -= size;
60                 buf += size;
61                 size = 0;
62         }
63         set_fs(fs);
64
65         return size;
66 }
67 EXPORT_SYMBOL(filp_user_write);
68
69 #if !(CFS_O_CREAT == O_CREAT && CFS_O_EXCL == O_EXCL && \
70      CFS_O_NOACCESS == O_NOACCESS &&\
71      CFS_O_TRUNC == O_TRUNC && CFS_O_APPEND == O_APPEND &&\
72      CFS_O_NONBLOCK == O_NONBLOCK && CFS_O_NDELAY == O_NDELAY &&\
73      CFS_O_SYNC == O_SYNC && CFS_O_ASYNC == FASYNC &&\
74      CFS_O_DIRECT == O_DIRECT && CFS_O_LARGEFILE == O_LARGEFILE &&\
75      CFS_O_DIRECTORY == O_DIRECTORY && CFS_O_NOFOLLOW == O_NOFOLLOW)
76
77 int cfs_oflags2univ(int flags)
78 {
79         int f;
80
81         f = flags & O_NOACCESS;
82         f |= (flags & O_CREAT) ? CFS_O_CREAT: 0;
83         f |= (flags & O_EXCL) ? CFS_O_EXCL: 0;
84         f |= (flags & O_NOCTTY) ? CFS_O_NOCTTY: 0;
85         f |= (flags & O_TRUNC) ? CFS_O_TRUNC: 0;
86         f |= (flags & O_APPEND) ? CFS_O_APPEND: 0;
87         f |= (flags & O_NONBLOCK) ? CFS_O_NONBLOCK: 0;
88         f |= (flags & O_SYNC)? CFS_O_SYNC: 0;
89         f |= (flags & FASYNC)? CFS_O_ASYNC: 0;
90         f |= (flags & O_DIRECTORY)? CFS_O_DIRECTORY: 0;
91         f |= (flags & O_DIRECT)? CFS_O_DIRECT: 0;
92         f |= (flags & O_LARGEFILE)? CFS_O_LARGEFILE: 0;
93         f |= (flags & O_NOFOLLOW)? CFS_O_NOFOLLOW: 0;
94         f |= (flags & O_NOATIME)? CFS_O_NOATIME: 0;
95         return f;
96 }
97 #else
98
99 int cfs_oflags2univ(int flags)
100 {
101         return (flags);
102 }
103 #endif
104 EXPORT_SYMBOL(cfs_oflags2univ);
105
106 /*
107  * XXX Liang: we don't need cfs_univ2oflags() now.
108  */
109 int cfs_univ2oflags(int flags)
110 {
111         return (flags);
112 }
113 EXPORT_SYMBOL(cfs_univ2oflags);