2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 this implements the core code for all NTVFS modules. Backends register themselves here.
27 /* the list of currently registered NTVFS backends, note that there
28 * can be more than one backend with the same name, as long as they
29 * have different typesx */
33 struct ntvfs_ops *ops;
35 static int num_backends;
38 register a NTVFS backend.
40 The 'name' can be later used by other backends to find the operations
41 structure for this backend.
43 The 'type' is used to specify whether this is for a disk, printer or IPC$ share
45 BOOL ntvfs_register(const char *name, enum ntvfs_type type, struct ntvfs_ops *ops)
47 if (ntvfs_backend_byname(name, type) != NULL) {
48 /* its already registered! */
49 DEBUG(2,("NTVFS backend '%s' for type %d already registered\n",
54 backends = Realloc(backends, sizeof(backends[0]) * (num_backends+1));
56 smb_panic("out of memory in ntvfs_register");
59 backends[num_backends].name = smb_xstrdup(name);
60 backends[num_backends].type = type;
61 backends[num_backends].ops = smb_xmemdup(ops, sizeof(*ops));
70 return the operations structure for a named backend of the specified type
72 struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type)
76 for (i=0;i<num_backends;i++) {
77 if (backends[i].type == type &&
78 strcmp(backends[i].name, name) == 0) {
79 return backends[i].ops;
88 return the NTVFS interface version, and the size of some critical types
89 This can be used by backends to either detect compilation errors, or provide
90 multiple implementations for different smbd compilation options in one module
92 int ntvfs_interface_version(struct ntvfs_critical_sizes *sizes)
94 sizes->sizeof_ntvfs_ops = sizeof(struct ntvfs_ops);
95 sizes->sizeof_SMB_OFF_T = sizeof(SMB_OFF_T);
96 sizes->sizeof_tcon_context = sizeof(struct tcon_context);
97 sizes->sizeof_request_context = sizeof(struct request_context);
99 return NTVFS_INTERFACE_VERSION;
104 initialise the NTVFS subsystem
106 BOOL ntvfs_init(void)
108 /* initialise our 3 basic backends. These are assumed to be
109 * present and are always built in */
110 if (!posix_vfs_init() ||
115 /* initialize optional backends, e.g. CIFS. We allow failures here. */
122 DEBUG(3,("NTVFS version %d initialised\n", NTVFS_INTERFACE_VERSION));
128 initialise a connection structure to point at a NTVFS backend
130 NTSTATUS ntvfs_init_connection(struct request_context *req)
132 const char *handler = lp_ntvfs_handler(req->conn->service);
134 if (strequal(handler, "default"))
137 req->conn->ntvfs_ops = ntvfs_backend_byname(handler, req->conn->type);
139 if (!req->conn->ntvfs_ops) {
140 DEBUG(1,("ntvfs_init_connection: failed to find backend=%s, type=%d\n", handler, req->conn->type));
141 return NT_STATUS_UNSUCCESSFUL;