Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / libcfs / libcfs / linux / linux-fs.c
1 # define DEBUG_SUBSYSTEM S_LNET
2
3 #include <linux/fs.h>
4 #include <linux/kdev_t.h>
5 #include <linux/ctype.h>
6 #include <asm/uaccess.h>
7
8 #include <libcfs/libcfs.h>
9
10 cfs_file_t *
11 cfs_filp_open (const char *name, int flags, int mode, int *err)
12 {
13         /* XXX
14          * Maybe we need to handle flags and mode in the future
15          */
16         cfs_file_t      *filp = NULL;
17
18         filp = filp_open(name, flags, mode);
19         if (IS_ERR(filp)) {
20                 int rc;
21
22                 rc = PTR_ERR(filp);
23                 printk(KERN_ERR "LustreError: can't open %s file: err %d\n",
24                                 name, rc);
25                 if (err)
26                         *err = rc;
27                 filp = NULL;
28         }
29         return filp;
30 }
31
32 /* write a userspace buffer to disk.
33  * NOTE: this returns 0 on success, not the number of bytes written. */
34 ssize_t
35 cfs_user_write (cfs_file_t *filp, const char *buf, size_t count, loff_t *offset)
36 {
37         mm_segment_t fs;
38         ssize_t size = 0;
39
40         fs = get_fs();
41         set_fs(KERNEL_DS);
42         while (count > 0) {
43                 size = filp->f_op->write(filp, (char *)buf, count, offset);
44                 if (size < 0)
45                         break;
46                 count -= size;
47                 size = 0;
48         }
49         set_fs(fs);
50
51         return size;
52 }
53
54 #if !(CFS_O_CREAT == O_CREAT && CFS_O_EXCL == O_EXCL && \
55      CFS_O_TRUNC == O_TRUNC && CFS_O_APPEND == O_APPEND &&\
56      CFS_O_NONBLOCK == O_NONBLOCK && CFS_O_NDELAY == O_NDELAY &&\
57      CFS_O_SYNC == O_SYNC && CFS_O_ASYNC == FASYNC &&\
58      CFS_O_DIRECT == O_DIRECT && CFS_O_LARGEFILE == O_LARGEFILE &&\
59      CFS_O_DIRECTORY == O_DIRECTORY && CFS_O_NOFOLLOW == O_NOFOLLOW)
60
61 int cfs_oflags2univ(int flags)
62 {
63         int f; 
64         
65         f = flags & O_ACCMODE;
66         f |= (flags & O_CREAT) ? CFS_O_CREAT: 0;
67         f |= (flags & O_EXCL) ? CFS_O_EXCL: 0;
68         f |= (flags & O_NOCTTY) ? CFS_O_NOCTTY: 0;
69         f |= (flags & O_TRUNC) ? CFS_O_TRUNC: 0;
70         f |= (flags & O_APPEND) ? CFS_O_APPEND: 0;
71         f |= (flags & O_NONBLOCK) ? CFS_O_NONBLOCK: 0;
72         f |= (flags & O_SYNC)? CFS_O_SYNC: 0;
73         f |= (flags & FASYNC)? CFS_O_ASYNC: 0;
74         f |= (flags & O_DIRECTORY)? CFS_O_DIRECTORY: 0;
75         f |= (flags & O_DIRECT)? CFS_O_DIRECT: 0;
76         f |= (flags & O_LARGEFILE)? CFS_O_LARGEFILE: 0;
77         f |= (flags & O_NOFOLLOW)? CFS_O_NOFOLLOW: 0;
78         f |= (flags & O_NOATIME)? CFS_O_NOATIME: 0;
79         return f;
80 }
81 #else
82
83 int cfs_oflags2univ(int flags)
84 {
85         return (flags);
86 }
87 #endif
88
89 /* 
90  * XXX Liang: we don't need cfs_univ2oflags() now.
91  */
92 int cfs_univ2oflags(int flags)
93 {
94         return (flags);
95 }
96
97 EXPORT_SYMBOL(cfs_filp_open);
98 EXPORT_SYMBOL(cfs_user_write);
99 EXPORT_SYMBOL(cfs_oflags2univ);
100 EXPORT_SYMBOL(cfs_univ2oflags);