18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
*/ |
20 |
|
|
21 |
#define FILE_ATTRIBUTE_READONLY 0x00000001 |
#include "disk.h" |
|
#define FILE_ATTRIBUTE_HIDDEN 0x00000002 |
|
|
#define FILE_ATTRIBUTE_SYSTEM 0x00000004 |
|
|
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 |
|
|
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 |
|
|
#define FILE_ATTRIBUTE_DEVICE 0x00000040 |
|
|
#define FILE_ATTRIBUTE_UNKNOWNXXX0 0x00000060 /* ??? ACTION i.e. 0x860 == compress this file ? */ |
|
|
#define FILE_ATTRIBUTE_NORMAL 0x00000080 |
|
|
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 |
|
|
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 |
|
|
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 |
|
|
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 |
|
|
#define FILE_ATTRIBUTE_OFFLINE 0x00001000 |
|
|
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 |
|
|
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 |
|
|
|
|
|
#define FILE_FLAG_OPEN_NO_RECALL 0x00100000 |
|
|
#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000 |
|
|
#define FILE_FLAG_POSIX_SEMANTICS 0x01000000 |
|
|
#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000 /* sometimes used to create a directory */ |
|
|
#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000 |
|
|
#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 |
|
|
#define FILE_FLAG_RANDOM_ACCESS 0x10000000 |
|
|
#define FILE_FLAG_NO_BUFFERING 0x20000000 |
|
|
#define FILE_FLAG_OVERLAPPED 0x40000000 |
|
|
#define FILE_FLAG_WRITE_THROUGH 0x80000000 |
|
|
|
|
|
#define FILE_SHARE_READ 0x01 |
|
|
#define FILE_SHARE_WRITE 0x02 |
|
|
#define FILE_SHARE_DELETE 0x04 |
|
|
|
|
|
#define FILE_BASIC_INFORMATION 0x04 |
|
|
#define FILE_STANDARD_INFORMATION 0x05 |
|
|
|
|
|
#define FS_CASE_SENSITIVE 0x00000001 |
|
|
#define FS_CASE_IS_PRESERVED 0x00000002 |
|
|
#define FS_UNICODE_STORED_ON_DISK 0x00000004 |
|
|
#define FS_PERSISTENT_ACLS 0x00000008 |
|
|
#define FS_FILE_COMPRESSION 0x00000010 |
|
|
#define FS_VOLUME_QUOTAS 0x00000020 |
|
|
#define FS_SUPPORTS_SPARSE_FILES 0x00000040 |
|
|
#define FS_SUPPORTS_REPARSE_POINTS 0x00000080 |
|
|
#define FS_SUPPORTS_REMOTE_STORAGE 0X00000100 |
|
|
#define FS_VOL_IS_COMPRESSED 0x00008000 |
|
|
#define FILE_READ_ONLY_VOLUME 0x00080000 |
|
|
|
|
|
#define OPEN_EXISTING 1 |
|
|
#define CREATE_NEW 2 |
|
|
#define OPEN_ALWAYS 3 |
|
|
#define TRUNCATE_EXISTING 4 |
|
|
#define CREATE_ALWAYS 5 |
|
|
|
|
|
#define GENERIC_READ 0x80000000 |
|
|
#define GENERIC_WRITE 0x40000000 |
|
|
#define GENERIC_EXECUTE 0x20000000 |
|
|
#define GENERIC_ALL 0x10000000 |
|
|
|
|
|
#define ERROR_FILE_NOT_FOUND 2L |
|
|
#define ERROR_ALREADY_EXISTS 183L |
|
|
|
|
|
#define MAX_OPEN_FILES 0x100 |
|
|
|
|
|
#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) |
|
|
#define SOLARIS |
|
|
#endif |
|
|
|
|
|
#ifdef SOLARIS |
|
|
#define DIRFD(a) ((a)->dd_fd) |
|
|
#else |
|
|
#define DIRFD(a) (dirfd(a)) |
|
|
#endif |
|
22 |
|
|
23 |
#include <sys/types.h> |
#include <sys/types.h> |
24 |
#include <sys/stat.h> |
#include <sys/stat.h> |
28 |
#include <fnmatch.h> |
#include <fnmatch.h> |
29 |
#include <errno.h> /* errno */ |
#include <errno.h> /* errno */ |
30 |
|
|
31 |
#if defined(SOLARIS) |
#include <utime.h> |
32 |
|
#include <time.h> /* ctime */ |
33 |
|
|
34 |
|
#if (defined(HAVE_DIRFD) || (HAVE_DECL_DIRFD == 1)) |
35 |
|
#define DIRFD(a) (dirfd(a)) |
36 |
|
#else |
37 |
|
#define DIRFD(a) ((a)->DIR_FD_MEMBER_NAME) |
38 |
|
#endif |
39 |
|
|
40 |
|
/* TODO: let autoconf figure out everything below... */ |
41 |
|
#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) |
42 |
|
#define SOLARIS |
43 |
|
#endif |
44 |
|
|
45 |
|
#if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__)) |
46 |
#include <sys/statvfs.h> /* solaris statvfs */ |
#include <sys/statvfs.h> /* solaris statvfs */ |
47 |
|
/* TODO: Fix mntent-handling for solaris/hpux |
48 |
|
* #include <sys/mntent.h> */ |
49 |
|
#undef HAVE_MNTENT_H |
50 |
|
#define MNTENT_PATH "/etc/mnttab" |
51 |
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
52 |
#define STATFS_T statvfs |
#define STATFS_T statvfs |
53 |
#define F_NAMELEN(buf) ((buf).f_namemax) |
#define F_NAMELEN(buf) ((buf).f_namemax) |
54 |
|
|
55 |
#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) |
#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__)) |
56 |
#include <sys/param.h> |
#include <sys/param.h> |
57 |
#include <sys/mount.h> |
#include <sys/mount.h> |
58 |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
59 |
#define STATFS_T statfs |
#define STATFS_T statfs |
60 |
#define F_NAMELEN(buf) (NAME_MAX) |
#define F_NAMELEN(buf) (NAME_MAX) |
61 |
|
|
62 |
|
#elif (defined(__SGI_IRIX__)) |
63 |
|
#include <sys/types.h> |
64 |
|
#include <sys/statvfs.h> |
65 |
|
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
66 |
|
#define STATFS_T statvfs |
67 |
|
#define F_NAMELEN(buf) ((buf).f_namemax) |
68 |
|
|
69 |
#else |
#else |
70 |
#include <sys/vfs.h> /* linux statfs */ |
#include <sys/vfs.h> /* linux statfs */ |
71 |
|
#include <mntent.h> |
72 |
|
#define HAVE_MNTENT_H |
73 |
|
#define MNTENT_PATH "/etc/mtab" |
74 |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
75 |
#define STATFS_T statfs |
#define STATFS_T statfs |
76 |
#define F_NAMELEN(buf) ((buf).f_namelen) |
#define F_NAMELEN(buf) ((buf).f_namelen) |
80 |
|
|
81 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
82 |
|
|
83 |
struct fileinfo |
FILEINFO g_fileinfo[MAX_OPEN_FILES]; |
84 |
|
BOOL g_notify_stamp = False; |
85 |
|
|
86 |
|
typedef struct |
87 |
{ |
{ |
88 |
uint32 device_id, flags_and_attributes; |
char name[256]; |
89 |
char path[256]; |
char label[256]; |
90 |
DIR *pdir; |
unsigned long serial; |
91 |
struct dirent *pdirent; |
char type[256]; |
92 |
char pattern[64]; |
} FsInfoType; |
93 |
BOOL delete_on_close; |
|
94 |
|
static NTSTATUS NotifyInfo(NTHANDLE handle, uint32 info_class, NOTIFY * p); |
95 |
|
|
96 |
|
static time_t |
97 |
|
get_create_time(struct stat *st) |
98 |
|
{ |
99 |
|
time_t ret, ret1; |
100 |
|
|
101 |
|
ret = MIN(st->st_ctime, st->st_mtime); |
102 |
|
ret1 = MIN(ret, st->st_atime); |
103 |
|
|
104 |
|
if (ret1 != (time_t) 0) |
105 |
|
return ret1; |
106 |
|
|
107 |
|
return ret; |
108 |
} |
} |
|
g_fileinfo[MAX_OPEN_FILES]; |
|
109 |
|
|
110 |
/* Convert seconds since 1970 to a filetime */ |
/* Convert seconds since 1970 to a filetime */ |
111 |
void |
static void |
112 |
seconds_since_1970_to_filetime(time_t seconds, uint32 * high, uint32 * low) |
seconds_since_1970_to_filetime(time_t seconds, uint32 * high, uint32 * low) |
113 |
{ |
{ |
114 |
unsigned long long ticks; |
unsigned long long ticks; |
118 |
*high = (uint32) (ticks >> 32); |
*high = (uint32) (ticks >> 32); |
119 |
} |
} |
120 |
|
|
121 |
|
/* Convert seconds since 1970 back to filetime */ |
122 |
|
static time_t |
123 |
|
convert_1970_to_filetime(uint32 high, uint32 low) |
124 |
|
{ |
125 |
|
unsigned long long ticks; |
126 |
|
time_t val; |
127 |
|
|
128 |
|
ticks = low + (((unsigned long long) high) << 32); |
129 |
|
ticks /= 10000000; |
130 |
|
ticks -= 11644473600LL; |
131 |
|
|
132 |
|
val = (time_t) ticks; |
133 |
|
return (val); |
134 |
|
|
135 |
|
} |
136 |
|
|
137 |
|
/* A wrapper for ftruncate which supports growing files, even if the |
138 |
|
native ftruncate doesn't. This is needed on Linux FAT filesystems, |
139 |
|
for example. */ |
140 |
|
static int |
141 |
|
ftruncate_growable(int fd, off_t length) |
142 |
|
{ |
143 |
|
int ret; |
144 |
|
off_t pos; |
145 |
|
static const char zero; |
146 |
|
|
147 |
|
/* Try the simple method first */ |
148 |
|
if ((ret = ftruncate(fd, length)) != -1) |
149 |
|
{ |
150 |
|
return ret; |
151 |
|
} |
152 |
|
|
153 |
|
/* |
154 |
|
* Some kind of error. Perhaps we were trying to grow. Retry |
155 |
|
* in a safe way. |
156 |
|
*/ |
157 |
|
|
158 |
|
/* Get current position */ |
159 |
|
if ((pos = lseek(fd, 0, SEEK_CUR)) == -1) |
160 |
|
{ |
161 |
|
perror("lseek"); |
162 |
|
return -1; |
163 |
|
} |
164 |
|
|
165 |
|
/* Seek to new size */ |
166 |
|
if (lseek(fd, length, SEEK_SET) == -1) |
167 |
|
{ |
168 |
|
perror("lseek"); |
169 |
|
return -1; |
170 |
|
} |
171 |
|
|
172 |
|
/* Write a zero */ |
173 |
|
if (write(fd, &zero, 1) == -1) |
174 |
|
{ |
175 |
|
perror("write"); |
176 |
|
return -1; |
177 |
|
} |
178 |
|
|
179 |
|
/* Truncate. This shouldn't fail. */ |
180 |
|
if (ftruncate(fd, length) == -1) |
181 |
|
{ |
182 |
|
perror("ftruncate"); |
183 |
|
return -1; |
184 |
|
} |
185 |
|
|
186 |
|
/* Restore position */ |
187 |
|
if (lseek(fd, pos, SEEK_SET) == -1) |
188 |
|
{ |
189 |
|
perror("lseek"); |
190 |
|
return -1; |
191 |
|
} |
192 |
|
|
193 |
|
return 0; |
194 |
|
} |
195 |
|
|
196 |
|
/* Just like open(2), but if a open with O_EXCL fails, retry with |
197 |
|
GUARDED semantics. This might be necessary because some filesystems |
198 |
|
(such as NFS filesystems mounted from a unfsd server) doesn't |
199 |
|
support O_EXCL. GUARDED semantics are subject to race conditions, |
200 |
|
but we can live with that. |
201 |
|
*/ |
202 |
|
static int |
203 |
|
open_weak_exclusive(const char *pathname, int flags, mode_t mode) |
204 |
|
{ |
205 |
|
int ret; |
206 |
|
struct stat statbuf; |
207 |
|
|
208 |
|
ret = open(pathname, flags, mode); |
209 |
|
if (ret != -1 || !(flags & O_EXCL)) |
210 |
|
{ |
211 |
|
/* Success, or not using O_EXCL */ |
212 |
|
return ret; |
213 |
|
} |
214 |
|
|
215 |
|
/* An error occured, and we are using O_EXCL. In case the FS |
216 |
|
doesn't support O_EXCL, some kind of error will be |
217 |
|
returned. Unfortunately, we don't know which one. Linux |
218 |
|
2.6.8 seems to return 524, but I cannot find a documented |
219 |
|
#define for this case. So, we'll return only on errors that |
220 |
|
we know aren't related to O_EXCL. */ |
221 |
|
switch (errno) |
222 |
|
{ |
223 |
|
case EACCES: |
224 |
|
case EEXIST: |
225 |
|
case EINTR: |
226 |
|
case EISDIR: |
227 |
|
case ELOOP: |
228 |
|
case ENAMETOOLONG: |
229 |
|
case ENOENT: |
230 |
|
case ENOTDIR: |
231 |
|
return ret; |
232 |
|
} |
233 |
|
|
234 |
|
/* Retry with GUARDED semantics */ |
235 |
|
if (stat(pathname, &statbuf) != -1) |
236 |
|
{ |
237 |
|
/* File exists */ |
238 |
|
errno = EEXIST; |
239 |
|
return -1; |
240 |
|
} |
241 |
|
else |
242 |
|
{ |
243 |
|
return open(pathname, flags & ~O_EXCL, mode); |
244 |
|
} |
245 |
|
} |
246 |
|
|
247 |
/* Enumeration of devices from rdesktop.c */ |
/* Enumeration of devices from rdesktop.c */ |
248 |
/* returns numer of units found and initialized. */ |
/* returns numer of units found and initialized. */ |
249 |
/* optarg looks like ':h:=/mnt/floppy,b:=/mnt/usbdevice1' */ |
/* optarg looks like ':h=/mnt/floppy,b=/mnt/usbdevice1' */ |
250 |
/* when it arrives to this function. */ |
/* when it arrives to this function. */ |
251 |
int |
int |
252 |
disk_enum_devices(int *id, char *optarg) |
disk_enum_devices(uint32 * id, char *optarg) |
253 |
{ |
{ |
254 |
char *pos = optarg; |
char *pos = optarg; |
255 |
char *pos2; |
char *pos2; |
260 |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
261 |
{ |
{ |
262 |
pos2 = next_arg(optarg, '='); |
pos2 = next_arg(optarg, '='); |
|
strcpy(g_rdpdr_device[*id].name, optarg); |
|
263 |
|
|
264 |
toupper_str(g_rdpdr_device[*id].name); |
strncpy(g_rdpdr_device[*id].name, optarg, sizeof(g_rdpdr_device[*id].name)); |
265 |
|
if (strlen(optarg) > 8) |
266 |
/* add trailing colon to name. */ |
fprintf(stderr, "share name %s truncated to %s\n", optarg, |
267 |
strcat(g_rdpdr_device[*id].name, ":"); |
g_rdpdr_device[*id].name); |
268 |
|
|
269 |
g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); |
g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); |
270 |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
|
printf("DISK %s to %s\n", g_rdpdr_device[*id].name, g_rdpdr_device[*id].local_path); |
|
271 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_DISK; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_DISK; |
272 |
count++; |
count++; |
273 |
(*id)++; |
(*id)++; |
278 |
} |
} |
279 |
|
|
280 |
/* Opens or creates a file or directory */ |
/* Opens or creates a file or directory */ |
281 |
NTSTATUS |
static NTSTATUS |
282 |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
283 |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
uint32 flags_and_attributes, char *filename, NTHANDLE * phandle) |
284 |
{ |
{ |
285 |
HANDLE handle; |
NTHANDLE handle; |
286 |
DIR *dirp; |
DIR *dirp; |
287 |
int flags, mode; |
int flags, mode; |
288 |
char path[256]; |
char path[256]; |
289 |
|
struct stat filestat; |
290 |
|
|
291 |
handle = 0; |
handle = 0; |
292 |
dirp = NULL; |
dirp = NULL; |
293 |
flags = 0; |
flags = 0; |
294 |
mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
295 |
|
|
296 |
if (filename[strlen(filename) - 1] == '/') |
if (*filename && filename[strlen(filename) - 1] == '/') |
297 |
filename[strlen(filename) - 1] = 0; |
filename[strlen(filename) - 1] = 0; |
298 |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
299 |
|
|
330 |
break; |
break; |
331 |
} |
} |
332 |
|
|
333 |
//printf("Open: \"%s\" flags: %u, accessmask: %u sharemode: %u create disp: %u\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); |
//printf("Open: \"%s\" flags: %X, accessmask: %X sharemode: %X create disp: %X\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); |
|
|
|
|
/* since we can't trust the FILE_DIRECTORY_FILE flag */ |
|
|
/* we need to double check that the file isn't a dir */ |
|
|
struct stat filestat; |
|
334 |
|
|
335 |
// Get information about file and set that flag ourselfs |
// Get information about file and set that flag ourselfs |
336 |
if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
337 |
flags_and_attributes |= FILE_DIRECTORY_FILE; |
{ |
338 |
|
if (flags_and_attributes & FILE_NON_DIRECTORY_FILE) |
339 |
|
return STATUS_FILE_IS_A_DIRECTORY; |
340 |
|
else |
341 |
|
flags_and_attributes |= FILE_DIRECTORY_FILE; |
342 |
|
} |
343 |
|
|
344 |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
345 |
{ |
{ |
386 |
flags |= O_RDONLY; |
flags |= O_RDONLY; |
387 |
} |
} |
388 |
|
|
389 |
handle = open(path, flags, mode); |
handle = open_weak_exclusive(path, flags, mode); |
390 |
if (handle == -1) |
if (handle == -1) |
391 |
{ |
{ |
392 |
switch (errno) |
switch (errno) |
393 |
{ |
{ |
394 |
|
case EISDIR: |
395 |
|
|
396 |
|
return STATUS_FILE_IS_A_DIRECTORY; |
397 |
|
|
398 |
case EACCES: |
case EACCES: |
399 |
|
|
400 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
402 |
case ENOENT: |
case ENOENT: |
403 |
|
|
404 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
405 |
|
case EEXIST: |
406 |
|
|
407 |
|
return STATUS_OBJECT_NAME_COLLISION; |
408 |
default: |
default: |
409 |
|
|
410 |
perror("open"); |
perror("open"); |
426 |
|
|
427 |
if (dirp) |
if (dirp) |
428 |
g_fileinfo[handle].pdir = dirp; |
g_fileinfo[handle].pdir = dirp; |
429 |
|
else |
430 |
|
g_fileinfo[handle].pdir = NULL; |
431 |
|
|
432 |
g_fileinfo[handle].device_id = device_id; |
g_fileinfo[handle].device_id = device_id; |
433 |
g_fileinfo[handle].flags_and_attributes = flags_and_attributes; |
g_fileinfo[handle].flags_and_attributes = flags_and_attributes; |
434 |
|
g_fileinfo[handle].accessmask = accessmask; |
435 |
strncpy(g_fileinfo[handle].path, path, 255); |
strncpy(g_fileinfo[handle].path, path, 255); |
436 |
|
g_fileinfo[handle].delete_on_close = False; |
437 |
|
g_notify_stamp = True; |
438 |
|
|
439 |
*phandle = handle; |
*phandle = handle; |
440 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
441 |
} |
} |
442 |
|
|
443 |
NTSTATUS |
static NTSTATUS |
444 |
disk_close(HANDLE handle) |
disk_close(NTHANDLE handle) |
445 |
{ |
{ |
446 |
struct fileinfo *pfinfo; |
struct fileinfo *pfinfo; |
447 |
|
|
448 |
pfinfo = &(g_fileinfo[handle]); |
pfinfo = &(g_fileinfo[handle]); |
449 |
|
|
450 |
if (pfinfo->flags_and_attributes & FILE_DIRECTORY_FILE) |
g_notify_stamp = True; |
451 |
|
|
452 |
|
rdpdr_abort_io(handle, 0, STATUS_CANCELLED); |
453 |
|
|
454 |
|
if (pfinfo->pdir) |
455 |
{ |
{ |
456 |
closedir(pfinfo->pdir); |
if (closedir(pfinfo->pdir) < 0) |
457 |
//FIXME: Should check exit code |
{ |
458 |
|
perror("closedir"); |
459 |
|
return STATUS_INVALID_HANDLE; |
460 |
|
} |
461 |
|
|
462 |
|
if (pfinfo->delete_on_close) |
463 |
|
if (rmdir(pfinfo->path) < 0) |
464 |
|
{ |
465 |
|
perror(pfinfo->path); |
466 |
|
return STATUS_ACCESS_DENIED; |
467 |
|
} |
468 |
|
pfinfo->delete_on_close = False; |
469 |
} |
} |
470 |
else |
else |
471 |
{ |
{ |
472 |
close(handle); |
if (close(handle) < 0) |
473 |
|
{ |
474 |
|
perror("close"); |
475 |
|
return STATUS_INVALID_HANDLE; |
476 |
|
} |
477 |
|
if (pfinfo->delete_on_close) |
478 |
|
if (unlink(pfinfo->path) < 0) |
479 |
|
{ |
480 |
|
perror(pfinfo->path); |
481 |
|
return STATUS_ACCESS_DENIED; |
482 |
|
} |
483 |
|
|
484 |
|
pfinfo->delete_on_close = False; |
485 |
} |
} |
486 |
|
|
487 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
488 |
} |
} |
489 |
|
|
490 |
NTSTATUS |
static NTSTATUS |
491 |
disk_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
disk_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
492 |
{ |
{ |
493 |
int n; |
int n; |
494 |
|
|
495 |
|
#if 0 |
496 |
/* browsing dir ???? */ |
/* browsing dir ???? */ |
497 |
/* each request is 24 bytes */ |
/* each request is 24 bytes */ |
498 |
if (g_fileinfo[handle].flags_and_attributes & FILE_DIRECTORY_FILE) |
if (g_fileinfo[handle].flags_and_attributes & FILE_DIRECTORY_FILE) |
500 |
*result = 0; |
*result = 0; |
501 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
502 |
} |
} |
503 |
|
#endif |
504 |
|
|
505 |
|
lseek(handle, offset, SEEK_SET); |
506 |
|
|
|
if (offset) |
|
|
lseek(handle, offset, SEEK_SET); |
|
507 |
n = read(handle, data, length); |
n = read(handle, data, length); |
508 |
|
|
509 |
if (n < 0) |
if (n < 0) |
510 |
{ |
{ |
|
perror("read"); |
|
511 |
*result = 0; |
*result = 0; |
512 |
return STATUS_INVALID_PARAMETER; |
switch (errno) |
513 |
|
{ |
514 |
|
case EISDIR: |
515 |
|
/* Implement 24 Byte directory read ?? |
516 |
|
with STATUS_NOT_IMPLEMENTED server doesn't read again */ |
517 |
|
/* return STATUS_FILE_IS_A_DIRECTORY; */ |
518 |
|
return STATUS_NOT_IMPLEMENTED; |
519 |
|
default: |
520 |
|
perror("read"); |
521 |
|
return STATUS_INVALID_PARAMETER; |
522 |
|
} |
523 |
} |
} |
524 |
|
|
525 |
*result = n; |
*result = n; |
527 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
528 |
} |
} |
529 |
|
|
530 |
NTSTATUS |
static NTSTATUS |
531 |
disk_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
disk_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
532 |
{ |
{ |
533 |
int n; |
int n; |
534 |
|
|
535 |
if (offset) |
lseek(handle, offset, SEEK_SET); |
|
lseek(handle, offset, SEEK_SET); |
|
536 |
|
|
537 |
n = write(handle, data, length); |
n = write(handle, data, length); |
538 |
|
|
540 |
{ |
{ |
541 |
perror("write"); |
perror("write"); |
542 |
*result = 0; |
*result = 0; |
543 |
return STATUS_ACCESS_DENIED; |
switch (errno) |
544 |
|
{ |
545 |
|
case ENOSPC: |
546 |
|
return STATUS_DISK_FULL; |
547 |
|
default: |
548 |
|
return STATUS_ACCESS_DENIED; |
549 |
|
} |
550 |
} |
} |
551 |
|
|
552 |
*result = n; |
*result = n; |
555 |
} |
} |
556 |
|
|
557 |
NTSTATUS |
NTSTATUS |
558 |
disk_query_information(HANDLE handle, uint32 info_class, STREAM out) |
disk_query_information(NTHANDLE handle, uint32 info_class, STREAM out) |
559 |
{ |
{ |
560 |
uint32 file_attributes, ft_high, ft_low; |
uint32 file_attributes, ft_high, ft_low; |
561 |
struct stat filestat; |
struct stat filestat; |
574 |
// Set file attributes |
// Set file attributes |
575 |
file_attributes = 0; |
file_attributes = 0; |
576 |
if (S_ISDIR(filestat.st_mode)) |
if (S_ISDIR(filestat.st_mode)) |
|
{ |
|
577 |
file_attributes |= FILE_ATTRIBUTE_DIRECTORY; |
file_attributes |= FILE_ATTRIBUTE_DIRECTORY; |
578 |
} |
|
579 |
filename = 1 + strrchr(path, '/'); |
filename = 1 + strrchr(path, '/'); |
580 |
if (filename && filename[0] == '.') |
if (filename && filename[0] == '.') |
|
{ |
|
581 |
file_attributes |= FILE_ATTRIBUTE_HIDDEN; |
file_attributes |= FILE_ATTRIBUTE_HIDDEN; |
582 |
} |
|
583 |
|
if (!file_attributes) |
584 |
|
file_attributes |= FILE_ATTRIBUTE_NORMAL; |
585 |
|
|
586 |
|
if (!(filestat.st_mode & S_IWUSR)) |
587 |
|
file_attributes |= FILE_ATTRIBUTE_READONLY; |
588 |
|
|
589 |
// Return requested data |
// Return requested data |
590 |
switch (info_class) |
switch (info_class) |
591 |
{ |
{ |
592 |
case 4: /* FileBasicInformation */ |
case FileBasicInformation: |
593 |
|
seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high, |
594 |
out_uint8s(out, 8); //create_time not available; |
&ft_low); |
595 |
|
out_uint32_le(out, ft_low); //create_access_time |
596 |
|
out_uint32_le(out, ft_high); |
597 |
|
|
598 |
seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low); |
seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low); |
599 |
out_uint32_le(out, ft_low); //last_access_time |
out_uint32_le(out, ft_low); //last_access_time |
603 |
out_uint32_le(out, ft_low); //last_write_time |
out_uint32_le(out, ft_low); //last_write_time |
604 |
out_uint32_le(out, ft_high); |
out_uint32_le(out, ft_high); |
605 |
|
|
606 |
out_uint8s(out, 8); //unknown zero |
seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low); |
607 |
|
out_uint32_le(out, ft_low); //last_change_time |
608 |
|
out_uint32_le(out, ft_high); |
609 |
|
|
610 |
out_uint32_le(out, file_attributes); |
out_uint32_le(out, file_attributes); |
611 |
break; |
break; |
612 |
|
|
613 |
case 5: /* FileStandardInformation */ |
case FileStandardInformation: |
614 |
|
|
615 |
out_uint32_le(out, filestat.st_size); //Allocation size |
out_uint32_le(out, filestat.st_size); //Allocation size |
616 |
out_uint32_le(out, 0); |
out_uint32_le(out, 0); |
621 |
out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0); //Directory |
out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0); //Directory |
622 |
break; |
break; |
623 |
|
|
624 |
case 35: /* FileObjectIdInformation */ |
case FileObjectIdInformation: |
625 |
|
|
626 |
out_uint32_le(out, file_attributes); /* File Attributes */ |
out_uint32_le(out, file_attributes); /* File Attributes */ |
627 |
out_uint32_le(out, 0); /* Reparse Tag */ |
out_uint32_le(out, 0); /* Reparse Tag */ |
636 |
} |
} |
637 |
|
|
638 |
NTSTATUS |
NTSTATUS |
639 |
disk_set_information(HANDLE handle, uint32 info_class, STREAM in, STREAM out) |
disk_set_information(NTHANDLE handle, uint32 info_class, STREAM in, STREAM out) |
640 |
{ |
{ |
641 |
uint32 device_id, length, file_attributes, ft_high, ft_low; |
uint32 length, file_attributes, ft_high, ft_low, delete_on_close; |
642 |
char newname[256], fullpath[256]; |
char newname[256], fullpath[256]; |
643 |
struct fileinfo *pfinfo; |
struct fileinfo *pfinfo; |
644 |
|
int mode; |
645 |
|
struct stat filestat; |
646 |
|
time_t write_time, change_time, access_time, mod_time; |
647 |
|
struct utimbuf tvs; |
648 |
|
struct STATFS_T stat_fs; |
649 |
|
|
650 |
pfinfo = &(g_fileinfo[handle]); |
pfinfo = &(g_fileinfo[handle]); |
651 |
|
g_notify_stamp = True; |
652 |
|
|
653 |
switch (info_class) |
switch (info_class) |
654 |
{ |
{ |
655 |
case 4: /* FileBasicInformation */ |
case FileBasicInformation: |
656 |
|
write_time = change_time = access_time = 0; |
657 |
|
|
658 |
|
in_uint8s(in, 4); /* Handle of root dir? */ |
659 |
|
in_uint8s(in, 24); /* unknown */ |
660 |
|
|
661 |
|
// CreationTime |
662 |
|
in_uint32_le(in, ft_low); |
663 |
|
in_uint32_le(in, ft_high); |
664 |
|
|
665 |
|
// AccessTime |
666 |
|
in_uint32_le(in, ft_low); |
667 |
|
in_uint32_le(in, ft_high); |
668 |
|
if (ft_low || ft_high) |
669 |
|
access_time = convert_1970_to_filetime(ft_high, ft_low); |
670 |
|
|
671 |
|
// WriteTime |
672 |
|
in_uint32_le(in, ft_low); |
673 |
|
in_uint32_le(in, ft_high); |
674 |
|
if (ft_low || ft_high) |
675 |
|
write_time = convert_1970_to_filetime(ft_high, ft_low); |
676 |
|
|
677 |
|
// ChangeTime |
678 |
|
in_uint32_le(in, ft_low); |
679 |
|
in_uint32_le(in, ft_high); |
680 |
|
if (ft_low || ft_high) |
681 |
|
change_time = convert_1970_to_filetime(ft_high, ft_low); |
682 |
|
|
683 |
|
in_uint32_le(in, file_attributes); |
684 |
|
|
685 |
|
if (fstat(handle, &filestat)) |
686 |
|
return STATUS_ACCESS_DENIED; |
687 |
|
|
688 |
|
tvs.modtime = filestat.st_mtime; |
689 |
|
tvs.actime = filestat.st_atime; |
690 |
|
if (access_time) |
691 |
|
tvs.actime = access_time; |
692 |
|
|
693 |
|
|
694 |
|
if (write_time || change_time) |
695 |
|
mod_time = MIN(write_time, change_time); |
696 |
|
else |
697 |
|
mod_time = write_time ? write_time : change_time; |
698 |
|
|
699 |
|
if (mod_time) |
700 |
|
tvs.modtime = mod_time; |
701 |
|
|
702 |
|
|
703 |
|
if (access_time || write_time || change_time) |
704 |
|
{ |
705 |
|
#if WITH_DEBUG_RDP5 |
706 |
|
printf("FileBasicInformation access time %s", |
707 |
|
ctime(&tvs.actime)); |
708 |
|
printf("FileBasicInformation modification time %s", |
709 |
|
ctime(&tvs.modtime)); |
710 |
|
#endif |
711 |
|
if (utime(pfinfo->path, &tvs) && errno != EPERM) |
712 |
|
return STATUS_ACCESS_DENIED; |
713 |
|
} |
714 |
|
|
715 |
|
if (!file_attributes) |
716 |
|
break; // not valid |
717 |
|
|
718 |
|
mode = filestat.st_mode; |
719 |
|
|
720 |
|
if (file_attributes & FILE_ATTRIBUTE_READONLY) |
721 |
|
mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); |
722 |
|
else |
723 |
|
mode |= S_IWUSR; |
724 |
|
|
725 |
|
mode &= 0777; |
726 |
|
#if WITH_DEBUG_RDP5 |
727 |
|
printf("FileBasicInformation set access mode 0%o", mode); |
728 |
|
#endif |
729 |
|
|
730 |
|
if (fchmod(handle, mode)) |
731 |
|
return STATUS_ACCESS_DENIED; |
732 |
|
|
|
// Probably safe to ignore |
|
733 |
break; |
break; |
734 |
|
|
735 |
case 10: /* FileRenameInformation */ |
case FileRenameInformation: |
736 |
|
|
737 |
in_uint8s(in, 4); /* Handle of root dir? */ |
in_uint8s(in, 4); /* Handle of root dir? */ |
738 |
in_uint8s(in, 0x1a); /* unknown */ |
in_uint8s(in, 0x1a); /* unknown */ |
758 |
} |
} |
759 |
break; |
break; |
760 |
|
|
761 |
case 13: /* FileDispositionInformation */ |
case FileDispositionInformation: |
762 |
|
/* As far as I understand it, the correct |
763 |
|
thing to do here is to *schedule* a delete, |
764 |
|
so it will be deleted when the file is |
765 |
|
closed. Subsequent |
766 |
|
FileDispositionInformation requests with |
767 |
|
DeleteFile set to FALSE should unschedule |
768 |
|
the delete. See |
769 |
|
http://www.osronline.com/article.cfm?article=245. */ |
770 |
|
|
771 |
|
in_uint32_le(in, delete_on_close); |
772 |
|
|
773 |
|
if (delete_on_close || |
774 |
|
(pfinfo-> |
775 |
|
accessmask & (FILE_DELETE_ON_CLOSE | FILE_COMPLETE_IF_OPLOCKED))) |
776 |
|
{ |
777 |
|
pfinfo->delete_on_close = True; |
778 |
|
} |
779 |
|
|
|
//unimpl("IRP Set File Information class: FileDispositionInformation\n"); |
|
|
// in_uint32_le(in, delete_on_close); |
|
|
// disk_close(handle); |
|
|
unlink(pfinfo->path); |
|
780 |
break; |
break; |
781 |
|
|
782 |
case 19: /* FileAllocationInformation */ |
case FileAllocationInformation: |
783 |
|
/* Fall through to FileEndOfFileInformation, |
784 |
|
which uses ftrunc. This is like Samba with |
785 |
|
"strict allocation = false", and means that |
786 |
|
we won't detect out-of-quota errors, for |
787 |
|
example. */ |
788 |
|
|
789 |
|
case FileEndOfFileInformation: |
790 |
|
in_uint8s(in, 28); /* unknown */ |
791 |
|
in_uint32_le(in, length); /* file size */ |
792 |
|
|
793 |
|
/* prevents start of writing if not enough space left on device */ |
794 |
|
if (STATFS_FN(g_rdpdr_device[pfinfo->device_id].local_path, &stat_fs) == 0) |
795 |
|
if (stat_fs.f_bfree * stat_fs.f_bsize < length) |
796 |
|
return STATUS_DISK_FULL; |
797 |
|
|
798 |
unimpl("IRP Set File Information class: FileAllocationInformation\n"); |
if (ftruncate_growable(handle, length) != 0) |
799 |
break; |
{ |
800 |
|
return STATUS_DISK_FULL; |
801 |
case 20: /* FileEndOfFileInformation */ |
} |
802 |
|
|
|
unimpl("IRP Set File Information class: FileEndOfFileInformation\n"); |
|
803 |
break; |
break; |
|
|
|
804 |
default: |
default: |
805 |
|
|
806 |
unimpl("IRP Set File Information class: 0x%x\n", info_class); |
unimpl("IRP Set File Information class: 0x%x\n", info_class); |
810 |
} |
} |
811 |
|
|
812 |
NTSTATUS |
NTSTATUS |
813 |
disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) |
disk_check_notify(NTHANDLE handle) |
814 |
|
{ |
815 |
|
struct fileinfo *pfinfo; |
816 |
|
NTSTATUS status = STATUS_PENDING; |
817 |
|
|
818 |
|
NOTIFY notify; |
819 |
|
|
820 |
|
pfinfo = &(g_fileinfo[handle]); |
821 |
|
if (!pfinfo->pdir) |
822 |
|
return STATUS_INVALID_DEVICE_REQUEST; |
823 |
|
|
824 |
|
|
825 |
|
|
826 |
|
status = NotifyInfo(handle, pfinfo->info_class, ¬ify); |
827 |
|
|
828 |
|
if (status != STATUS_PENDING) |
829 |
|
return status; |
830 |
|
|
831 |
|
if (memcmp(&pfinfo->notify, ¬ify, sizeof(NOTIFY))) |
832 |
|
{ |
833 |
|
//printf("disk_check_notify found changed event\n"); |
834 |
|
memcpy(&pfinfo->notify, ¬ify, sizeof(NOTIFY)); |
835 |
|
status = STATUS_NOTIFY_ENUM_DIR; |
836 |
|
} |
837 |
|
|
838 |
|
return status; |
839 |
|
|
840 |
|
|
841 |
|
} |
842 |
|
|
843 |
|
NTSTATUS |
844 |
|
disk_create_notify(NTHANDLE handle, uint32 info_class) |
845 |
|
{ |
846 |
|
|
847 |
|
struct fileinfo *pfinfo; |
848 |
|
NTSTATUS ret = STATUS_PENDING; |
849 |
|
|
850 |
|
/* printf("start disk_create_notify info_class %X\n", info_class); */ |
851 |
|
|
852 |
|
pfinfo = &(g_fileinfo[handle]); |
853 |
|
pfinfo->info_class = info_class; |
854 |
|
|
855 |
|
ret = NotifyInfo(handle, info_class, &pfinfo->notify); |
856 |
|
|
857 |
|
if (info_class & 0x1000) |
858 |
|
{ /* ???? */ |
859 |
|
if (ret == STATUS_PENDING) |
860 |
|
return STATUS_SUCCESS; |
861 |
|
} |
862 |
|
|
863 |
|
/* printf("disk_create_notify: num_entries %d\n", pfinfo->notify.num_entries); */ |
864 |
|
|
865 |
|
|
866 |
|
return ret; |
867 |
|
|
868 |
|
} |
869 |
|
|
870 |
|
static NTSTATUS |
871 |
|
NotifyInfo(NTHANDLE handle, uint32 info_class, NOTIFY * p) |
872 |
|
{ |
873 |
|
struct fileinfo *pfinfo; |
874 |
|
struct stat buf; |
875 |
|
struct dirent *dp; |
876 |
|
char *fullname; |
877 |
|
DIR *dpr; |
878 |
|
|
879 |
|
pfinfo = &(g_fileinfo[handle]); |
880 |
|
if (fstat(handle, &buf) < 0) |
881 |
|
{ |
882 |
|
perror("NotifyInfo"); |
883 |
|
return STATUS_ACCESS_DENIED; |
884 |
|
} |
885 |
|
p->modify_time = buf.st_mtime; |
886 |
|
p->status_time = buf.st_ctime; |
887 |
|
p->num_entries = 0; |
888 |
|
p->total_time = 0; |
889 |
|
|
890 |
|
|
891 |
|
dpr = opendir(pfinfo->path); |
892 |
|
if (!dpr) |
893 |
|
{ |
894 |
|
perror("NotifyInfo"); |
895 |
|
return STATUS_ACCESS_DENIED; |
896 |
|
} |
897 |
|
|
898 |
|
|
899 |
|
while ((dp = readdir(dpr))) |
900 |
|
{ |
901 |
|
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) |
902 |
|
continue; |
903 |
|
p->num_entries++; |
904 |
|
fullname = xmalloc(strlen(pfinfo->path) + strlen(dp->d_name) + 2); |
905 |
|
sprintf(fullname, "%s/%s", pfinfo->path, dp->d_name); |
906 |
|
|
907 |
|
if (!stat(fullname, &buf)) |
908 |
|
{ |
909 |
|
p->total_time += (buf.st_mtime + buf.st_ctime); |
910 |
|
} |
911 |
|
|
912 |
|
xfree(fullname); |
913 |
|
} |
914 |
|
closedir(dpr); |
915 |
|
|
916 |
|
return STATUS_PENDING; |
917 |
|
} |
918 |
|
|
919 |
|
static FsInfoType * |
920 |
|
FsVolumeInfo(char *fpath) |
921 |
|
{ |
922 |
|
|
923 |
|
FILE *fdfs; |
924 |
|
static FsInfoType info; |
925 |
|
#ifdef HAVE_MNTENT_H |
926 |
|
struct mntent *e; |
927 |
|
#endif |
928 |
|
|
929 |
|
/* initialize */ |
930 |
|
memset(&info, 0, sizeof(info)); |
931 |
|
strcpy(info.label, "RDESKTOP"); |
932 |
|
strcpy(info.type, "RDPFS"); |
933 |
|
|
934 |
|
#ifdef HAVE_MNTENT_H |
935 |
|
fdfs = setmntent(MNTENT_PATH, "r"); |
936 |
|
if (!fdfs) |
937 |
|
return &info; |
938 |
|
|
939 |
|
while ((e = getmntent(fdfs))) |
940 |
|
{ |
941 |
|
if (strncmp(fpath, e->mnt_dir, strlen(fpath)) == 0) |
942 |
|
{ |
943 |
|
strcpy(info.type, e->mnt_type); |
944 |
|
strcpy(info.name, e->mnt_fsname); |
945 |
|
if (strstr(e->mnt_opts, "vfat") || strstr(e->mnt_opts, "iso9660")) |
946 |
|
{ |
947 |
|
int fd = open(e->mnt_fsname, O_RDONLY); |
948 |
|
if (fd >= 0) |
949 |
|
{ |
950 |
|
unsigned char buf[512]; |
951 |
|
memset(buf, 0, sizeof(buf)); |
952 |
|
if (strstr(e->mnt_opts, "vfat")) |
953 |
|
/*FAT*/ |
954 |
|
{ |
955 |
|
strcpy(info.type, "vfat"); |
956 |
|
read(fd, buf, sizeof(buf)); |
957 |
|
info.serial = |
958 |
|
(buf[42] << 24) + (buf[41] << 16) + |
959 |
|
(buf[40] << 8) + buf[39]; |
960 |
|
strncpy(info.label, buf + 43, 10); |
961 |
|
info.label[10] = '\0'; |
962 |
|
} |
963 |
|
else if (lseek(fd, 32767, SEEK_SET) >= 0) /* ISO9660 */ |
964 |
|
{ |
965 |
|
read(fd, buf, sizeof(buf)); |
966 |
|
strncpy(info.label, buf + 41, 32); |
967 |
|
info.label[32] = '\0'; |
968 |
|
//info.Serial = (buf[128]<<24)+(buf[127]<<16)+(buf[126]<<8)+buf[125]; |
969 |
|
} |
970 |
|
close(fd); |
971 |
|
} |
972 |
|
} |
973 |
|
} |
974 |
|
} |
975 |
|
endmntent(fdfs); |
976 |
|
#else |
977 |
|
/* initialize */ |
978 |
|
memset(&info, 0, sizeof(info)); |
979 |
|
strcpy(info.label, "RDESKTOP"); |
980 |
|
strcpy(info.type, "RDPFS"); |
981 |
|
|
982 |
|
#endif |
983 |
|
return &info; |
984 |
|
} |
985 |
|
|
986 |
|
|
987 |
|
NTSTATUS |
988 |
|
disk_query_volume_information(NTHANDLE handle, uint32 info_class, STREAM out) |
989 |
{ |
{ |
|
char *volume, *fs_type; |
|
990 |
struct STATFS_T stat_fs; |
struct STATFS_T stat_fs; |
991 |
struct fileinfo *pfinfo; |
struct fileinfo *pfinfo; |
992 |
|
FsInfoType *fsinfo; |
993 |
|
|
994 |
pfinfo = &(g_fileinfo[handle]); |
pfinfo = &(g_fileinfo[handle]); |
|
volume = "RDESKTOP"; |
|
|
fs_type = "RDPFS"; |
|
995 |
|
|
996 |
if (STATFS_FN(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ |
if (STATFS_FN(pfinfo->path, &stat_fs) != 0) |
997 |
{ |
{ |
998 |
perror("statfs"); |
perror("statfs"); |
999 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
1000 |
} |
} |
1001 |
|
|
1002 |
|
fsinfo = FsVolumeInfo(pfinfo->path); |
1003 |
|
|
1004 |
switch (info_class) |
switch (info_class) |
1005 |
{ |
{ |
1006 |
case 1: /* FileFsVolumeInformation */ |
case FileFsVolumeInformation: |
1007 |
|
|
1008 |
out_uint32_le(out, 0); /* volume creation time low */ |
out_uint32_le(out, 0); /* volume creation time low */ |
1009 |
out_uint32_le(out, 0); /* volume creation time high */ |
out_uint32_le(out, 0); /* volume creation time high */ |
1010 |
out_uint32_le(out, 0); /* serial */ |
out_uint32_le(out, fsinfo->serial); /* serial */ |
1011 |
out_uint32_le(out, 2 * strlen(volume)); /* length of string */ |
|
1012 |
|
out_uint32_le(out, 2 * strlen(fsinfo->label)); /* length of string */ |
1013 |
|
|
1014 |
out_uint8(out, 0); /* support objects? */ |
out_uint8(out, 0); /* support objects? */ |
1015 |
rdp_out_unistr(out, volume, 2 * strlen(volume) - 2); |
rdp_out_unistr(out, fsinfo->label, 2 * strlen(fsinfo->label) - 2); |
1016 |
break; |
break; |
1017 |
|
|
1018 |
case 3: /* FileFsSizeInformation */ |
case FileFsSizeInformation: |
1019 |
|
|
1020 |
out_uint32_le(out, stat_fs.f_blocks); /* Total allocation units low */ |
out_uint32_le(out, stat_fs.f_blocks); /* Total allocation units low */ |
1021 |
out_uint32_le(out, 0); /* Total allocation high units */ |
out_uint32_le(out, 0); /* Total allocation high units */ |
1025 |
out_uint32_le(out, 0x200); /* Bytes per sector */ |
out_uint32_le(out, 0x200); /* Bytes per sector */ |
1026 |
break; |
break; |
1027 |
|
|
1028 |
case 5: /* FileFsAttributeInformation */ |
case FileFsAttributeInformation: |
1029 |
|
|
1030 |
out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED); /* fs attributes */ |
out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED); /* fs attributes */ |
1031 |
out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */ |
out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */ |
1032 |
out_uint32_le(out, 2 * strlen(fs_type)); /* length of fs_type */ |
|
1033 |
rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2); |
out_uint32_le(out, 2 * strlen(fsinfo->type)); /* length of fs_type */ |
1034 |
|
rdp_out_unistr(out, fsinfo->type, 2 * strlen(fsinfo->type) - 2); |
1035 |
break; |
break; |
1036 |
|
|
1037 |
case 2: /* FileFsLabelInformation */ |
case FileFsLabelInformation: |
1038 |
case 4: /* FileFsDeviceInformation */ |
case FileFsDeviceInformation: |
1039 |
case 6: /* FileFsControlInformation */ |
case FileFsControlInformation: |
1040 |
case 7: /* FileFsFullSizeInformation */ |
case FileFsFullSizeInformation: |
1041 |
case 8: /* FileFsObjectIdInformation */ |
case FileFsObjectIdInformation: |
1042 |
case 9: /* FileFsMaximumInformation */ |
case FileFsMaximumInformation: |
1043 |
|
|
1044 |
default: |
default: |
1045 |
|
|
1046 |
unimpl("IRP Query Volume Information class: 0x%x\n", info_class); |
unimpl("IRP Query Volume Information class: 0x%x\n", info_class); |
1050 |
} |
} |
1051 |
|
|
1052 |
NTSTATUS |
NTSTATUS |
1053 |
disk_query_directory(HANDLE handle, uint32 info_class, char *pattern, STREAM out) |
disk_query_directory(NTHANDLE handle, uint32 info_class, char *pattern, STREAM out) |
1054 |
{ |
{ |
1055 |
uint32 file_attributes, ft_low, ft_high; |
uint32 file_attributes, ft_low, ft_high; |
1056 |
char *dirname, fullpath[256]; |
char *dirname, fullpath[256]; |
1066 |
|
|
1067 |
switch (info_class) |
switch (info_class) |
1068 |
{ |
{ |
1069 |
case 3: //FIXME: Why 3? |
case FileBothDirectoryInformation: |
1070 |
|
|
1071 |
// If a search pattern is received, remember this pattern, and restart search |
// If a search pattern is received, remember this pattern, and restart search |
1072 |
if (pattern[0] != 0) |
if (pattern[0] != 0) |
1078 |
// find next dirent matching pattern |
// find next dirent matching pattern |
1079 |
pdirent = readdir(pdir); |
pdirent = readdir(pdir); |
1080 |
while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0) |
while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0) |
|
{ |
|
1081 |
pdirent = readdir(pdir); |
pdirent = readdir(pdir); |
|
} |
|
1082 |
|
|
1083 |
if (pdirent == NULL) |
if (pdirent == NULL) |
|
{ |
|
1084 |
return STATUS_NO_MORE_FILES; |
return STATUS_NO_MORE_FILES; |
|
} |
|
1085 |
|
|
1086 |
// Get information for directory entry |
// Get information for directory entry |
1087 |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
1088 |
/* JIF |
|
|
printf("Stat: %s\n", fullpath); */ |
|
1089 |
if (stat(fullpath, &fstat)) |
if (stat(fullpath, &fstat)) |
1090 |
{ |
{ |
1091 |
perror("stat"); |
switch (errno) |
1092 |
out_uint8(out, 0); |
{ |
1093 |
return STATUS_ACCESS_DENIED; |
case ENOENT: |
1094 |
|
case ELOOP: |
1095 |
|
case EACCES: |
1096 |
|
/* These are non-fatal errors. */ |
1097 |
|
memset(&fstat, 0, sizeof(fstat)); |
1098 |
|
break; |
1099 |
|
default: |
1100 |
|
/* Fatal error. By returning STATUS_NO_SUCH_FILE, |
1101 |
|
the directory list operation will be aborted */ |
1102 |
|
perror(fullpath); |
1103 |
|
out_uint8(out, 0); |
1104 |
|
return STATUS_NO_SUCH_FILE; |
1105 |
|
} |
1106 |
} |
} |
1107 |
|
|
1108 |
if (S_ISDIR(fstat.st_mode)) |
if (S_ISDIR(fstat.st_mode)) |
1109 |
file_attributes |= FILE_ATTRIBUTE_DIRECTORY; |
file_attributes |= FILE_ATTRIBUTE_DIRECTORY; |
1110 |
if (pdirent->d_name[0] == '.') |
if (pdirent->d_name[0] == '.') |
1111 |
file_attributes |= FILE_ATTRIBUTE_HIDDEN; |
file_attributes |= FILE_ATTRIBUTE_HIDDEN; |
1112 |
|
if (!file_attributes) |
1113 |
|
file_attributes |= FILE_ATTRIBUTE_NORMAL; |
1114 |
|
if (!(fstat.st_mode & S_IWUSR)) |
1115 |
|
file_attributes |= FILE_ATTRIBUTE_READONLY; |
1116 |
|
|
1117 |
// Return requested information |
// Return requested information |
1118 |
out_uint8s(out, 8); //unknown zero |
out_uint8s(out, 8); //unknown zero |
1119 |
out_uint8s(out, 8); //create_time not available in posix; |
|
1120 |
|
seconds_since_1970_to_filetime(get_create_time(&fstat), &ft_high, &ft_low); |
1121 |
|
out_uint32_le(out, ft_low); // create time |
1122 |
|
out_uint32_le(out, ft_high); |
1123 |
|
|
1124 |
seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low); |
seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low); |
1125 |
out_uint32_le(out, ft_low); //last_access_time |
out_uint32_le(out, ft_low); //last_access_time |
1129 |
out_uint32_le(out, ft_low); //last_write_time |
out_uint32_le(out, ft_low); //last_write_time |
1130 |
out_uint32_le(out, ft_high); |
out_uint32_le(out, ft_high); |
1131 |
|
|
1132 |
out_uint8s(out, 8); //unknown zero |
seconds_since_1970_to_filetime(fstat.st_ctime, &ft_high, &ft_low); |
1133 |
|
out_uint32_le(out, ft_low); //change_write_time |
1134 |
|
out_uint32_le(out, ft_high); |
1135 |
|
|
1136 |
out_uint32_le(out, fstat.st_size); //filesize low |
out_uint32_le(out, fstat.st_size); //filesize low |
1137 |
out_uint32_le(out, 0); //filesize high |
out_uint32_le(out, 0); //filesize high |
1138 |
out_uint32_le(out, fstat.st_size); //filesize low |
out_uint32_le(out, fstat.st_size); //filesize low |
1146 |
break; |
break; |
1147 |
|
|
1148 |
default: |
default: |
1149 |
|
/* FIXME: Support FileDirectoryInformation, |
1150 |
|
FileFullDirectoryInformation, and |
1151 |
|
FileNamesInformation */ |
1152 |
|
|
1153 |
unimpl("IRP Query Directory sub: 0x%x\n", info_class); |
unimpl("IRP Query Directory sub: 0x%x\n", info_class); |
1154 |
return STATUS_INVALID_PARAMETER; |
return STATUS_INVALID_PARAMETER; |
1157 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
1158 |
} |
} |
1159 |
|
|
1160 |
|
|
1161 |
|
|
1162 |
|
static NTSTATUS |
1163 |
|
disk_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
1164 |
|
{ |
1165 |
|
if (((request >> 16) != 20) || ((request >> 16) != 9)) |
1166 |
|
return STATUS_INVALID_PARAMETER; |
1167 |
|
|
1168 |
|
/* extract operation */ |
1169 |
|
request >>= 2; |
1170 |
|
request &= 0xfff; |
1171 |
|
|
1172 |
|
printf("DISK IOCTL %d\n", request); |
1173 |
|
|
1174 |
|
switch (request) |
1175 |
|
{ |
1176 |
|
case 25: // ? |
1177 |
|
case 42: // ? |
1178 |
|
default: |
1179 |
|
unimpl("DISK IOCTL %d\n", request); |
1180 |
|
return STATUS_INVALID_PARAMETER; |
1181 |
|
} |
1182 |
|
|
1183 |
|
return STATUS_SUCCESS; |
1184 |
|
} |
1185 |
|
|
1186 |
DEVICE_FNS disk_fns = { |
DEVICE_FNS disk_fns = { |
1187 |
disk_create, |
disk_create, |
1188 |
disk_close, |
disk_close, |
1189 |
disk_read, |
disk_read, |
1190 |
disk_write, |
disk_write, |
1191 |
NULL /* device_control */ |
disk_device_control /* device_control */ |
1192 |
}; |
}; |