2 * Unix SMB/CIFS implementation.
5 * Copyright (C) Tim Prouty, 2008
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.
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.
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/>.
25 #define DBGC_CLASS DBGC_VFS
27 #define ONEFS_DATA_FASTBUF 10
29 struct onefs_vfs_config share_config[ONEFS_DATA_FASTBUF];
30 struct onefs_vfs_config *pshare_config;
32 static void onefs_load_faketimestamp_config(struct vfs_handle_struct *handle,
33 struct onefs_vfs_config *cfg)
36 int snum = SNUM(handle->conn);
38 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_NOW,
42 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
43 set_namearray(&cfg->atime_now_list,*parm);
46 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_CTIME_NOW,
50 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
51 set_namearray(&cfg->ctime_now_list,*parm);
54 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_NOW,
58 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
59 set_namearray(&cfg->mtime_now_list,*parm);
62 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_STATIC,
66 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
67 set_namearray(&cfg->atime_static_list,*parm);
70 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_STATIC,
74 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
75 set_namearray(&cfg->mtime_static_list,*parm);
78 cfg->atime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_ATIME_SLOP,0);
79 cfg->ctime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_CTIME_SLOP,0);
80 cfg->mtime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_MTIME_SLOP,0);
84 static int onefs_load_config(struct vfs_handle_struct *handle)
86 int snum = SNUM(handle->conn);
87 int share_count = lp_numservices();
91 if (share_count <= ONEFS_DATA_FASTBUF)
92 pshare_config = share_config;
95 SMB_MALLOC_ARRAY(struct onefs_vfs_config,
102 memset(pshare_config, 0,
103 (sizeof(struct onefs_vfs_config) * share_count));
107 if ((pshare_config[snum].init_flags &
108 ONEFS_VFS_CONFIG_INITIALIZED) == 0) {
109 pshare_config[snum].init_flags =
110 ONEFS_VFS_CONFIG_INITIALIZED;
111 onefs_load_faketimestamp_config(handle,
112 &pshare_config[snum]);
118 bool onefs_get_config(int snum, int config_type,
119 struct onefs_vfs_config *cfg)
121 if (share_config[snum].init_flags & config_type)
122 *cfg = share_config[snum];
129 static int onefs_connect(struct vfs_handle_struct *handle, const char *service,
132 int ret = onefs_load_config(handle);
137 return SMB_VFS_NEXT_CONNECT(handle, service, user);
140 static int onefs_mkdir(vfs_handle_struct *handle, const char *path,
143 /* SMB_VFS_MKDIR should never be called in vfs_onefs */
145 return SMB_VFS_NEXT_MKDIR(handle, path, mode);
148 static int onefs_open(vfs_handle_struct *handle, const char *fname,
149 files_struct *fsp, int flags, mode_t mode)
151 /* SMB_VFS_OPEN should never be called in vfs_onefs */
153 return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
156 static uint64_t onefs_get_alloc_size(struct vfs_handle_struct *handle,
158 const SMB_STRUCT_STAT *sbuf)
162 START_PROFILE(syscall_get_alloc_size);
164 if(S_ISDIR(sbuf->st_mode)) {
169 /* Just use the file size since st_blocks is unreliable on OneFS. */
170 result = get_file_size_stat(sbuf);
172 if (fsp && fsp->initial_allocation_size)
173 result = MAX(result,fsp->initial_allocation_size);
175 result = smb_roundup(handle->conn, result);
178 END_PROFILE(syscall_get_alloc_size);
182 static int onefs_statvfs(vfs_handle_struct *handle, const char *path,
183 vfs_statvfs_struct *statbuf)
185 struct statvfs statvfs_buf;
188 DEBUG(5, ("Calling SMB_STAT_VFS \n"));
189 result = statvfs(path, &statvfs_buf);
190 ZERO_STRUCTP(statbuf);
193 statbuf->OptimalTransferSize = statvfs_buf.f_iosize;
194 statbuf->BlockSize = statvfs_buf.f_bsize;
195 statbuf->TotalBlocks = statvfs_buf.f_blocks;
196 statbuf->BlocksAvail = statvfs_buf.f_bfree;
197 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
198 statbuf->TotalFileNodes = statvfs_buf.f_files;
199 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
200 statbuf->FsIdentifier =
201 (((uint64_t)statvfs_buf.f_fsid.val[0]<<32) &
202 0xffffffff00000000LL) |
203 (uint64_t)statvfs_buf.f_fsid.val[1];
208 static int onefs_get_real_filename(vfs_handle_struct *handle, const char *path,
209 const char *name, TALLOC_CTX *mem_ctx,
213 struct stat_extra se;
215 char *full_name = NULL;
218 se.se_version = ESTAT_CURRENT_VERSION;
219 se.se_flags = ESTAT_CASE_INSENSITIVE | ESTAT_SYMLINK_NOFOLLOW;
222 if (!(full_name = talloc_asprintf(mem_ctx, "%s/%s", path, name))) {
224 DEBUG(2, ("talloc_asprintf failed\n"));
230 if ((result = estat(full_name ? full_name : name, &sb, &se)) != 0) {
231 DEBUG(2, ("error calling estat: %s\n", strerror(errno)));
235 *found_name = talloc_strdup(mem_ctx, se.se_realname);
236 if (*found_name == NULL) {
243 TALLOC_FREE(full_name);
247 static int onefs_ntimes(vfs_handle_struct *handle, const char *fname,
248 struct smb_file_time *ft)
251 struct timespec times[3];
253 if (!null_timespec(ft->atime)) {
255 times[0] = ft->atime;
256 DEBUG(6,("**** onefs_ntimes: actime: %s.%d\n",
257 time_to_asc(convert_timespec_to_time_t(ft->atime)),
261 if (!null_timespec(ft->mtime)) {
263 times[1] = ft->mtime;
264 DEBUG(6,("**** onefs_ntimes: modtime: %s.%d\n",
265 time_to_asc(convert_timespec_to_time_t(ft->mtime)),
269 if (!null_timespec(ft->create_time)) {
271 times[2] = ft->create_time;
272 DEBUG(6,("**** onefs_ntimes: createtime: %s.%d\n",
273 time_to_asc(convert_timespec_to_time_t(ft->create_time)),
274 ft->create_time.tv_nsec));
277 return onefs_vtimes_streams(handle, fname, flags, times);
280 static uint32_t onefs_fs_capabilities(struct vfs_handle_struct *handle)
282 return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
285 static vfs_op_tuple onefs_ops[] = {
286 {SMB_VFS_OP(onefs_connect), SMB_VFS_OP_CONNECT,
287 SMB_VFS_LAYER_TRANSPARENT},
288 {SMB_VFS_OP(onefs_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
289 SMB_VFS_LAYER_TRANSPARENT},
290 {SMB_VFS_OP(onefs_opendir), SMB_VFS_OP_OPENDIR,
291 SMB_VFS_LAYER_TRANSPARENT},
292 {SMB_VFS_OP(onefs_readdir), SMB_VFS_OP_READDIR,
293 SMB_VFS_LAYER_OPAQUE},
294 {SMB_VFS_OP(onefs_seekdir), SMB_VFS_OP_SEEKDIR,
295 SMB_VFS_LAYER_OPAQUE},
296 {SMB_VFS_OP(onefs_telldir), SMB_VFS_OP_TELLDIR,
297 SMB_VFS_LAYER_OPAQUE},
298 {SMB_VFS_OP(onefs_rewinddir), SMB_VFS_OP_REWINDDIR,
299 SMB_VFS_LAYER_OPAQUE},
300 {SMB_VFS_OP(onefs_mkdir), SMB_VFS_OP_MKDIR,
301 SMB_VFS_LAYER_OPAQUE},
302 {SMB_VFS_OP(onefs_closedir), SMB_VFS_OP_CLOSEDIR,
303 SMB_VFS_LAYER_TRANSPARENT},
304 {SMB_VFS_OP(onefs_init_search_op), SMB_VFS_OP_INIT_SEARCH_OP,
305 SMB_VFS_LAYER_OPAQUE},
306 {SMB_VFS_OP(onefs_open), SMB_VFS_OP_OPEN,
307 SMB_VFS_LAYER_OPAQUE},
308 {SMB_VFS_OP(onefs_create_file), SMB_VFS_OP_CREATE_FILE,
309 SMB_VFS_LAYER_OPAQUE},
310 {SMB_VFS_OP(onefs_close), SMB_VFS_OP_CLOSE,
311 SMB_VFS_LAYER_TRANSPARENT},
312 {SMB_VFS_OP(onefs_rename), SMB_VFS_OP_RENAME,
313 SMB_VFS_LAYER_TRANSPARENT},
314 {SMB_VFS_OP(onefs_stat), SMB_VFS_OP_STAT,
315 SMB_VFS_LAYER_TRANSPARENT},
316 {SMB_VFS_OP(onefs_fstat), SMB_VFS_OP_FSTAT,
317 SMB_VFS_LAYER_TRANSPARENT},
318 {SMB_VFS_OP(onefs_lstat), SMB_VFS_OP_LSTAT,
319 SMB_VFS_LAYER_TRANSPARENT},
320 {SMB_VFS_OP(onefs_get_alloc_size), SMB_VFS_OP_GET_ALLOC_SIZE,
321 SMB_VFS_LAYER_OPAQUE},
322 {SMB_VFS_OP(onefs_unlink), SMB_VFS_OP_UNLINK,
323 SMB_VFS_LAYER_TRANSPARENT},
324 {SMB_VFS_OP(onefs_ntimes), SMB_VFS_OP_NTIMES,
325 SMB_VFS_LAYER_OPAQUE},
326 {SMB_VFS_OP(onefs_chflags), SMB_VFS_OP_CHFLAGS,
327 SMB_VFS_LAYER_TRANSPARENT},
328 {SMB_VFS_OP(onefs_streaminfo), SMB_VFS_OP_STREAMINFO,
329 SMB_VFS_LAYER_OPAQUE},
330 {SMB_VFS_OP(onefs_brl_lock_windows), SMB_VFS_OP_BRL_LOCK_WINDOWS,
331 SMB_VFS_LAYER_OPAQUE},
332 {SMB_VFS_OP(onefs_brl_unlock_windows), SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
333 SMB_VFS_LAYER_OPAQUE},
334 {SMB_VFS_OP(onefs_brl_cancel_windows), SMB_VFS_OP_BRL_CANCEL_WINDOWS,
335 SMB_VFS_LAYER_OPAQUE},
336 {SMB_VFS_OP(onefs_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
337 SMB_VFS_LAYER_OPAQUE},
338 {SMB_VFS_OP(onefs_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
339 SMB_VFS_LAYER_OPAQUE},
340 {SMB_VFS_OP(onefs_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
341 SMB_VFS_LAYER_OPAQUE},
342 {SMB_VFS_OP(onefs_statvfs), SMB_VFS_OP_STATVFS,
343 SMB_VFS_LAYER_OPAQUE},
344 {SMB_VFS_OP(onefs_get_real_filename), SMB_VFS_OP_GET_REAL_FILENAME,
345 SMB_VFS_LAYER_OPAQUE},
346 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
349 NTSTATUS vfs_onefs_init(void)
351 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "onefs",