2 * Unix SMB/CIFS implementation.
5 * Copyright (C) Todd Stecher, 2009
6 * Copyright (C) Tim Prouty, 2009
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "onefs_config.h"
25 #include <ifs/ifs_syscalls.h>
27 #define ONEFS_DATA_FASTBUF 10
29 struct onefs_vfs_share_config vfs_share_config
[ONEFS_DATA_FASTBUF
];
30 struct onefs_vfs_share_config
*pvfs_share_config
;
32 static void onefs_load_faketimestamp_config(struct connection_struct
*conn
,
33 struct onefs_vfs_share_config
*cfg
)
36 int snum
= SNUM(conn
);
38 parm
= lp_parm_string_list(snum
, PARM_ONEFS_TYPE
, PARM_ATIME_NOW
,
39 PARM_ATIME_NOW_DEFAULT
);
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
,
47 PARM_CTIME_NOW_DEFAULT
);
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
,
55 PARM_MTIME_NOW_DEFAULT
);
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
,
63 PARM_ATIME_STATIC_DEFAULT
);
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
,
71 PARM_MTIME_STATIC_DEFAULT
);
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
,
79 PARM_ATIME_SLOP_DEFAULT
);
80 cfg
->ctime_slop
= lp_parm_int(snum
, PARM_ONEFS_TYPE
, PARM_CTIME_SLOP
,
81 PARM_CTIME_SLOP_DEFAULT
);
82 cfg
->mtime_slop
= lp_parm_int(snum
, PARM_ONEFS_TYPE
, PARM_MTIME_SLOP
,
83 PARM_MTIME_SLOP_DEFAULT
);
87 * Set onefs-specific vfs global config parameters.
89 * Since changes in these parameters require calling syscalls, we only want to
90 * call them when the configuration actually changes.
92 static void onefs_load_global_config(connection_struct
*conn
)
94 static struct onefs_vfs_global_config global_config
;
95 bool dot_snap_child_accessible
;
96 bool dot_snap_child_visible
;
97 bool dot_snap_root_accessible
;
98 bool dot_snap_root_visible
;
100 bool reconfig_dso
= false;
101 bool reconfig_tilde
= false;
103 /* Check if this is the first time setting the config options. */
104 if (!(global_config
.init_flags
& ONEFS_VFS_CONFIG_INITIALIZED
)) {
105 global_config
.init_flags
|= ONEFS_VFS_CONFIG_INITIALIZED
;
107 /* Set process encoding */
108 onefs_sys_config_enc();
111 reconfig_tilde
= true;
114 /* Get the dot snap options from the conf. */
115 dot_snap_child_accessible
=
116 lp_parm_bool(SNUM(conn
), PARM_ONEFS_TYPE
,
117 PARM_DOT_SNAP_CHILD_ACCESSIBLE
,
118 PARM_DOT_SNAP_CHILD_ACCESSIBLE_DEFAULT
);
119 dot_snap_child_visible
=
120 lp_parm_bool(SNUM(conn
), PARM_ONEFS_TYPE
,
121 PARM_DOT_SNAP_CHILD_VISIBLE
,
122 PARM_DOT_SNAP_CHILD_VISIBLE_DEFAULT
);
123 dot_snap_root_accessible
=
124 lp_parm_bool(SNUM(conn
), PARM_ONEFS_TYPE
,
125 PARM_DOT_SNAP_ROOT_ACCESSIBLE
,
126 PARM_DOT_SNAP_ROOT_ACCESSIBLE_DEFAULT
);
127 dot_snap_root_visible
=
128 lp_parm_bool(SNUM(conn
), PARM_ONEFS_TYPE
,
129 PARM_DOT_SNAP_ROOT_VISIBLE
,
130 PARM_DOT_SNAP_ROOT_VISIBLE_DEFAULT
);
132 lp_parm_bool(SNUM(conn
), PARM_ONEFS_TYPE
,
134 PARM_DOT_SNAP_TILDE_DEFAULT
);
136 /* Check if any of the dot snap options need updating. */
137 if (dot_snap_child_accessible
!=
138 global_config
.dot_snap_child_accessible
) {
139 global_config
.dot_snap_child_accessible
=
140 dot_snap_child_accessible
;
143 if (dot_snap_child_visible
!=
144 global_config
.dot_snap_child_visible
) {
145 global_config
.dot_snap_child_visible
=
146 dot_snap_child_visible
;
149 if (dot_snap_root_accessible
!=
150 global_config
.dot_snap_root_accessible
) {
151 global_config
.dot_snap_root_accessible
=
152 dot_snap_root_accessible
;
155 if (dot_snap_root_visible
!=
156 global_config
.dot_snap_root_visible
) {
157 global_config
.dot_snap_root_visible
=
158 dot_snap_root_visible
;
161 if (dot_snap_tilde
!= global_config
.dot_snap_tilde
) {
162 global_config
.dot_snap_tilde
= dot_snap_tilde
;
163 reconfig_tilde
= true;
166 /* If a dot snap option has changed update the process. */
168 onefs_sys_config_snap_opt(&global_config
);
171 /* If the dot snap tilde option has changed update the process. */
172 if (reconfig_tilde
) {
173 onefs_sys_config_tilde(&global_config
);
177 int onefs_load_config(connection_struct
*conn
)
179 int snum
= SNUM(conn
);
180 int share_count
= lp_numservices();
183 if (!pvfs_share_config
) {
185 if (share_count
<= ONEFS_DATA_FASTBUF
)
186 pvfs_share_config
= vfs_share_config
;
189 SMB_MALLOC_ARRAY(struct onefs_vfs_share_config
,
191 if (!pvfs_share_config
) {
196 memset(pvfs_share_config
, 0,
197 (sizeof(struct onefs_vfs_share_config
) *
202 if ((pvfs_share_config
[snum
].init_flags
&
203 ONEFS_VFS_CONFIG_INITIALIZED
) == 0) {
204 pvfs_share_config
[snum
].init_flags
=
205 ONEFS_VFS_CONFIG_INITIALIZED
;
206 onefs_load_faketimestamp_config(conn
,
207 &pvfs_share_config
[snum
]);
211 onefs_load_global_config(conn
);
216 bool onefs_get_config(int snum
, int config_type
,
217 struct onefs_vfs_share_config
*cfg
)
219 if (vfs_share_config
[snum
].init_flags
& config_type
)
220 *cfg
= vfs_share_config
[snum
];
229 * Set the per-process encoding, ignoring errors.
231 void onefs_sys_config_enc(void)
235 ret
= enc_set_proc(ENC_UTF8
);
237 DEBUG(0, ("Setting process encoding failed: %s",
243 * Set the per-process .snpashot directory options, ignoring errors.
245 void onefs_sys_config_snap_opt(struct onefs_vfs_global_config
*global_config
)
247 struct ifs_dotsnap_options dso
;
251 dso
.sub_accessible
= global_config
->dot_snap_child_accessible
;
252 dso
.sub_visible
= global_config
->dot_snap_child_visible
;
253 dso
.root_accessible
= global_config
->dot_snap_root_accessible
;
254 dso
.root_visible
= global_config
->dot_snap_root_visible
;
256 ret
= ifs_set_dotsnap_options(&dso
);
258 DEBUG(0, ("Setting snapshot visibility/accessibility "
259 "failed: %s", strerror(errno
)));
264 * Set the per-process flag saying whether or not to accept ~snapshot
265 * as an alternative name for .snapshot directories.
267 void onefs_sys_config_tilde(struct onefs_vfs_global_config
*global_config
)
271 ret
= ifs_tilde_snapshot(global_config
->dot_snap_tilde
);
273 DEBUG(0, ("Setting snapshot tilde failed: %s",