2 Unix SMB/CIFS implementation.
4 simple NTVFS filesystem backend
6 Copyright (C) Andrew Tridgell 2003
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 utility functions for simple backend
27 #include "system/filesys.h"
29 #include "system/time.h"
30 #include "system/dir.h"
33 convert a windows path to a unix path - don't do any manging or case sensitive handling
35 char *svfs_unix_path(struct ntvfs_module_context *ntvfs,
36 struct smbsrv_request *req, const char *name)
38 struct svfs_private *private = ntvfs->private_data;
42 ret = talloc_asprintf(req, "%s/%s", private->connectpath, name);
44 ret = talloc_asprintf(req, "%s%s", private->connectpath, name);
46 all_string_sub(ret, "\\", "/", 0);
48 strlower(ret + strlen(private->connectpath));
55 read a directory and find all matching file names and stat info
56 returned names are separate unix and DOS names. The returned names
57 are relative to the directory
59 struct svfs_dir *svfs_list_unix(TALLOC_CTX *mem_ctx, struct smbsrv_request *req, const char *unix_path)
68 dir = talloc(mem_ctx, struct svfs_dir);
69 if (!dir) { return NULL; }
74 /* find the base directory */
75 p = strrchr(unix_path, '/');
76 if (!p) { return NULL; }
78 dir->unix_dir = talloc_strndup(mem_ctx, unix_path, PTR_DIFF(p, unix_path));
79 if (!dir->unix_dir) { return NULL; }
81 /* the wildcard pattern is the last part */
84 low_mask = talloc_strdup(mem_ctx, mask);
85 if (!low_mask) { return NULL; }
88 odir = opendir(dir->unix_dir);
89 if (!odir) { return NULL; }
91 while ((dent = readdir(odir))) {
92 uint_t i = dir->count;
96 if (strchr(dent->d_name, ':') && !strchr(unix_path, ':')) {
97 /* don't show streams in dir listing */
101 low_name = talloc_strdup(mem_ctx, dent->d_name);
102 if (!low_name) { continue; }
105 /* check it matches the wildcard pattern */
106 if (ms_fnmatch(low_mask, low_name, PROTOCOL_NT1) != 0) {
110 if (dir->count >= allocated) {
111 allocated = (allocated + 100) * 1.2;
112 dir->files = talloc_realloc(dir, dir->files, struct svfs_dirfile, allocated);
119 dir->files[i].name = low_name;
120 if (!dir->files[i].name) { continue; }
122 asprintf(&full_name, "%s/%s", dir->unix_dir, dir->files[i].name);
123 if (!full_name) { continue; }
125 if (stat(full_name, &dir->files[i].st) == 0) {
138 read a directory and find all matching file names and stat info
139 returned names are separate unix and DOS names. The returned names
140 are relative to the directory
142 struct svfs_dir *svfs_list(struct ntvfs_module_context *ntvfs, struct smbsrv_request *req, const char *pattern)
144 struct svfs_private *private = ntvfs->private_data;
147 unix_path = svfs_unix_path(ntvfs, req, pattern);
148 if (!unix_path) { return NULL; }
150 return svfs_list_unix(private, req, unix_path);
154 /*******************************************************************
155 set the time on a file via file descriptor
156 *******************************************************************/
157 int svfs_file_utime(int fd, struct utimbuf *times)
159 char *fd_path = NULL;
162 asprintf(&fd_path, "/proc/self/%d", fd);
168 ret = utime(fd_path, times);
175 map a unix file attrib to a DOS attribute
177 uint16_t svfs_unix_to_dos_attrib(mode_t mode)
180 if (S_ISDIR(mode)) ret |= FILE_ATTRIBUTE_DIRECTORY;
181 if (!(mode & S_IWUSR)) ret |= FILE_ATTRIBUTE_READONLY;
186 build a file_id from a stat struct
188 uint64_t svfs_file_id(struct stat *st)
190 uint64_t ret = st->st_ino;