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
30 convert a windows path to a unix path - don't do any manging or case sensitive handling
32 char *svfs_unix_path(struct request_context *req, const char *name)
34 struct svfs_private *private = req->conn->ntvfs_private;
38 ret = talloc_asprintf(req->mem_ctx, "%s/%s", private->connectpath, name);
40 ret = talloc_asprintf(req->mem_ctx, "%s%s", private->connectpath, name);
42 all_string_sub(ret, "\\", "/", 0);
51 read a directory and find all matching file names and stat info
52 returned names are separate unix and DOS names. The returned names
53 are relative to the directory
55 struct svfs_dir *svfs_list_unix(TALLOC_CTX *mem_ctx, struct request_context *req, const char *unix_path)
64 dir = talloc(mem_ctx, sizeof(struct svfs_dir));
65 if (!dir) { return NULL; }
70 /* find the base directory */
71 p = strrchr(unix_path, '/');
72 if (!p) { return NULL; }
74 dir->unix_dir = talloc_strndup(mem_ctx, unix_path, PTR_DIFF(p, unix_path));
75 if (!dir->unix_dir) { return NULL; }
77 /* the wildcard pattern is the last part */
80 low_mask = talloc_strdup(mem_ctx, mask);
81 if (!low_mask) { return NULL; }
84 odir = opendir(dir->unix_dir);
85 if (!odir) { return NULL; }
87 while ((dent = readdir(odir))) {
88 uint_t i = dir->count;
92 if (strchr(dent->d_name, ':') && !strchr(unix_path, ':')) {
93 /* don't show streams in dir listing */
97 low_name = talloc_strdup(mem_ctx, dent->d_name);
98 if (!low_name) { continue; }
101 /* check it matches the wildcard pattern */
102 if (ms_fnmatch(low_mask, low_name, PROTOCOL_NT1) != 0) {
106 if (dir->count >= allocated) {
107 allocated = (allocated + 100) * 1.2;
108 dir->files = talloc_realloc(mem_ctx, dir->files, allocated * sizeof(dir->files[0]));
115 dir->files[i].name = low_name;
116 if (!dir->files[i].name) { continue; }
118 asprintf(&full_name, "%s/%s", dir->unix_dir, dir->files[i].name);
119 if (!full_name) { continue; }
121 if (stat(full_name, &dir->files[i].st) == 0) {
134 read a directory and find all matching file names and stat info
135 returned names are separate unix and DOS names. The returned names
136 are relative to the directory
138 struct svfs_dir *svfs_list(TALLOC_CTX *mem_ctx, struct request_context *req, const char *pattern)
142 unix_path = svfs_unix_path(req, pattern);
143 if (!unix_path) { return NULL; }
145 return svfs_list_unix(mem_ctx, req, unix_path);
149 /*******************************************************************
150 set the time on a file via file descriptor
151 *******************************************************************/
152 int svfs_file_utime(int fd, struct utimbuf *times)
154 char *fd_path = NULL;
157 asprintf(&fd_path, "/proc/self/%d", fd);
163 ret = utime(fd_path, times);
170 map a unix file attrib to a DOS attribute
172 uint16 svfs_unix_to_dos_attrib(mode_t mode)
175 if (S_ISDIR(mode)) ret |= FILE_ATTRIBUTE_DIRECTORY;
176 if (!(mode & S_IWUSR)) ret |= FILE_ATTRIBUTE_READONLY;
181 build a file_id from a stat struct
183 large_t svfs_file_id(struct stat *st)
185 large_t ret = st->st_ino;