Modify OneFS module to support new NTIMES interfaces
[metze/samba/wip.git] / source3 / modules / vfs_onefs.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * Support for OneFS
4  *
5  * Copyright (C) Tim Prouty, 2008
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "includes.h"
22 #include "onefs.h"
23
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_VFS
26
27 static int onefs_mkdir(vfs_handle_struct *handle, const char *path,
28                        mode_t mode)
29 {
30         /* SMB_VFS_MKDIR should never be called in vfs_onefs */
31         SMB_ASSERT(false);
32         return SMB_VFS_NEXT_MKDIR(handle, path, mode);
33 }
34
35 static int onefs_open(vfs_handle_struct *handle, const char *fname,
36                       files_struct *fsp, int flags, mode_t mode)
37 {
38         /* SMB_VFS_OPEN should never be called in vfs_onefs */
39         SMB_ASSERT(false);
40         return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
41 }
42
43 static int onefs_statvfs(vfs_handle_struct *handle, const char *path,
44                          vfs_statvfs_struct *statbuf)
45 {
46         struct statvfs statvfs_buf;
47         int result;
48
49         DEBUG(5, ("Calling SMB_STAT_VFS \n"));
50         result = statvfs(path, &statvfs_buf);
51         ZERO_STRUCTP(statbuf);
52
53         if (!result) {
54                 statbuf->OptimalTransferSize = statvfs_buf.f_iosize;
55                 statbuf->BlockSize = statvfs_buf.f_bsize;
56                 statbuf->TotalBlocks = statvfs_buf.f_blocks;
57                 statbuf->BlocksAvail = statvfs_buf.f_bfree;
58                 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
59                 statbuf->TotalFileNodes = statvfs_buf.f_files;
60                 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
61                 statbuf->FsIdentifier =
62                     (((uint64_t)statvfs_buf.f_fsid.val[0]<<32) &
63                         0xffffffff00000000LL) |
64                     (uint64_t)statvfs_buf.f_fsid.val[1];
65         }
66         return result;
67 }
68
69 static int onefs_ntimes(vfs_handle_struct *handle, const char *fname,
70                         struct smb_file_time *ft)
71 {
72         int flags = 0;
73         struct timespec times[3];
74
75         if (!null_timespec(ft->atime)) {
76                 flags |= VT_ATIME;
77                 times[0] = ft->atime;
78                 DEBUG(6,("**** onefs_ntimes: actime: %s.%d\n",
79                         time_to_asc(convert_timespec_to_time_t(ft->atime)),
80                         ft->atime.tv_nsec));
81         }
82
83         if (!null_timespec(ft->mtime)) {
84                 flags |= VT_MTIME;
85                 times[1] = ft->mtime;
86                 DEBUG(6,("**** onefs_ntimes: modtime: %s.%d\n",
87                         time_to_asc(convert_timespec_to_time_t(ft->mtime)),
88                         ft->mtime.tv_nsec));
89         }
90
91         if (!null_timespec(ft->create_time)) {
92                 flags |= VT_BTIME;
93                 times[2] = ft->create_time;
94                 DEBUG(6,("**** onefs_ntimes: createtime: %s.%d\n",
95                    time_to_asc(convert_timespec_to_time_t(ft->create_time)),
96                    ft->create_time.tv_nsec));
97         }
98
99         return onefs_vtimes_streams(handle, fname, flags, times);
100 }
101
102 static uint32_t onefs_fs_capabilities(struct vfs_handle_struct *handle)
103 {
104         return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
105 }
106
107 static vfs_op_tuple onefs_ops[] = {
108         {SMB_VFS_OP(onefs_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
109          SMB_VFS_LAYER_TRANSPARENT},
110         {SMB_VFS_OP(onefs_mkdir), SMB_VFS_OP_MKDIR,
111          SMB_VFS_LAYER_OPAQUE},
112         {SMB_VFS_OP(onefs_open), SMB_VFS_OP_OPEN,
113          SMB_VFS_LAYER_OPAQUE},
114         {SMB_VFS_OP(onefs_create_file), SMB_VFS_OP_CREATE_FILE,
115          SMB_VFS_LAYER_OPAQUE},
116         {SMB_VFS_OP(onefs_close), SMB_VFS_OP_CLOSE,
117          SMB_VFS_LAYER_TRANSPARENT},
118         {SMB_VFS_OP(onefs_rename), SMB_VFS_OP_RENAME,
119          SMB_VFS_LAYER_TRANSPARENT},
120         {SMB_VFS_OP(onefs_stat), SMB_VFS_OP_STAT,
121          SMB_VFS_LAYER_TRANSPARENT},
122         {SMB_VFS_OP(onefs_fstat), SMB_VFS_OP_FSTAT,
123          SMB_VFS_LAYER_TRANSPARENT},
124         {SMB_VFS_OP(onefs_lstat), SMB_VFS_OP_LSTAT,
125          SMB_VFS_LAYER_TRANSPARENT},
126         {SMB_VFS_OP(onefs_unlink), SMB_VFS_OP_UNLINK,
127          SMB_VFS_LAYER_TRANSPARENT},
128         {SMB_VFS_OP(onefs_ntimes), SMB_VFS_OP_NTIMES,
129          SMB_VFS_LAYER_OPAQUE},
130         {SMB_VFS_OP(onefs_chflags), SMB_VFS_OP_CHFLAGS,
131          SMB_VFS_LAYER_TRANSPARENT},
132         {SMB_VFS_OP(onefs_streaminfo), SMB_VFS_OP_STREAMINFO,
133          SMB_VFS_LAYER_OPAQUE},
134         {SMB_VFS_OP(onefs_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
135          SMB_VFS_LAYER_OPAQUE},
136         {SMB_VFS_OP(onefs_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
137          SMB_VFS_LAYER_OPAQUE},
138         {SMB_VFS_OP(onefs_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
139          SMB_VFS_LAYER_OPAQUE},
140         {SMB_VFS_OP(onefs_statvfs), SMB_VFS_OP_STATVFS,
141          SMB_VFS_LAYER_OPAQUE},
142         {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
143 };
144
145 NTSTATUS vfs_onefs_init(void)
146 {
147         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "onefs",
148                                 onefs_ops);
149 }