24 |
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 |
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 |
25 |
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 |
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 |
26 |
#define FILE_ATTRIBUTE_DEVICE 0x00000040 |
#define FILE_ATTRIBUTE_DEVICE 0x00000040 |
27 |
|
#define FILE_ATTRIBUTE_UNKNOWNXXX0 0x00000060 /* ??? ACTION i.e. 0x860 == compress this file ? */ |
28 |
#define FILE_ATTRIBUTE_NORMAL 0x00000080 |
#define FILE_ATTRIBUTE_NORMAL 0x00000080 |
29 |
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 |
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 |
30 |
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 |
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 |
34 |
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 |
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 |
35 |
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 |
#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 |
36 |
|
|
37 |
|
#define FILE_FLAG_OPEN_NO_RECALL 0x00100000 |
38 |
|
#define FILE_FLAG_OPEN_REPARSE_POINT 0x00200000 |
39 |
|
#define FILE_FLAG_POSIX_SEMANTICS 0x01000000 |
40 |
|
#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000 /* sometimes used to create a directory */ |
41 |
|
#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000 |
42 |
|
#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000 |
43 |
|
#define FILE_FLAG_RANDOM_ACCESS 0x10000000 |
44 |
|
#define FILE_FLAG_NO_BUFFERING 0x20000000 |
45 |
|
#define FILE_FLAG_OVERLAPPED 0x40000000 |
46 |
|
#define FILE_FLAG_WRITE_THROUGH 0x80000000 |
47 |
|
|
48 |
|
#define FILE_SHARE_READ 0x01 |
49 |
|
#define FILE_SHARE_WRITE 0x02 |
50 |
|
#define FILE_SHARE_DELETE 0x04 |
51 |
|
|
52 |
#define FILE_BASIC_INFORMATION 0x04 |
#define FILE_BASIC_INFORMATION 0x04 |
53 |
#define FILE_STANDARD_INFORMATION 0x05 |
#define FILE_STANDARD_INFORMATION 0x05 |
54 |
|
|
98 |
#include <fnmatch.h> |
#include <fnmatch.h> |
99 |
#include <errno.h> /* errno */ |
#include <errno.h> /* errno */ |
100 |
|
|
101 |
#ifdef SOLARIS |
#if defined(SOLARIS) |
102 |
#include <sys/statvfs.h> /* solaris statvfs */ |
#include <sys/statvfs.h> /* solaris statvfs */ |
103 |
#define HAVE_STATVFS |
#define STATFS_FN(path, buf) (statvfs(path,buf)) |
104 |
|
#define STATFS_T statvfs |
105 |
|
#define F_NAMELEN(buf) ((buf).f_namemax) |
106 |
|
|
107 |
|
#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) |
108 |
|
#include <sys/param.h> |
109 |
|
#include <sys/mount.h> |
110 |
|
#define STATFS_FN(path, buf) (statfs(path,buf)) |
111 |
|
#define STATFS_T statfs |
112 |
|
#define F_NAMELEN(buf) (NAME_MAX) |
113 |
|
|
114 |
#else |
#else |
115 |
#include <sys/vfs.h> /* linux statfs */ |
#include <sys/vfs.h> /* linux statfs */ |
116 |
#define HAVE_STATFS |
#define STATFS_FN(path, buf) (statfs(path,buf)) |
117 |
|
#define STATFS_T statfs |
118 |
|
#define F_NAMELEN(buf) ((buf).f_namelen) |
119 |
#endif |
#endif |
120 |
|
|
121 |
#include "rdesktop.h" |
#include "rdesktop.h" |
133 |
} |
} |
134 |
g_fileinfo[MAX_OPEN_FILES]; |
g_fileinfo[MAX_OPEN_FILES]; |
135 |
|
|
|
struct fsinfo |
|
|
{ |
|
|
uint32 f_blocks, f_bfree, f_bsize, f_namelen; |
|
|
}; |
|
|
|
|
136 |
/* Convert seconds since 1970 to a filetime */ |
/* Convert seconds since 1970 to a filetime */ |
137 |
void |
void |
138 |
seconds_since_1970_to_filetime(time_t seconds, uint32 * high, uint32 * low) |
seconds_since_1970_to_filetime(time_t seconds, uint32 * high, uint32 * low) |
179 |
return count; |
return count; |
180 |
} |
} |
181 |
|
|
182 |
/* Opens of creates a file or directory */ |
/* Opens or creates a file or directory */ |
183 |
NTSTATUS |
NTSTATUS |
184 |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
185 |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
uint32 flags_and_attributes, char *filename, HANDLE * phandle) |
197 |
if (filename[strlen(filename) - 1] == '/') |
if (filename[strlen(filename) - 1] == '/') |
198 |
filename[strlen(filename) - 1] = 0; |
filename[strlen(filename) - 1] = 0; |
199 |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
sprintf(path, "%s%s", g_rdpdr_device[device_id].local_path, filename); |
|
//printf("Open: %s\n", path); |
|
200 |
|
|
201 |
switch (create_disposition) |
switch (create_disposition) |
202 |
{ |
{ |
231 |
break; |
break; |
232 |
} |
} |
233 |
|
|
234 |
|
//printf("Open: \"%s\" flags: %u, accessmask: %u sharemode: %u create disp: %u\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); |
235 |
|
|
236 |
|
/* since we can't trust the FILE_DIRECTORY_FILE flag */ |
237 |
|
/* we need to double check that the file isn't a dir */ |
238 |
|
struct stat filestat; |
239 |
|
|
240 |
|
// Get information about file and set that flag ourselfs |
241 |
|
if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) |
242 |
|
flags_and_attributes |= FILE_DIRECTORY_FILE; |
243 |
|
|
244 |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
if (flags_and_attributes & FILE_DIRECTORY_FILE) |
245 |
{ |
{ |
246 |
if (flags & O_CREAT) |
if (flags & O_CREAT) |
271 |
} |
} |
272 |
else |
else |
273 |
{ |
{ |
274 |
|
|
275 |
if (accessmask & GENERIC_ALL |
if (accessmask & GENERIC_ALL |
276 |
|| (accessmask & GENERIC_READ && accessmask & GENERIC_WRITE)) |
|| (accessmask & GENERIC_READ && accessmask & GENERIC_WRITE)) |
277 |
{ |
{ |
298 |
case ENOENT: |
case ENOENT: |
299 |
|
|
300 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
|
|
|
301 |
default: |
default: |
302 |
|
|
303 |
perror("open"); |
perror("open"); |
304 |
return STATUS_NO_SUCH_FILE; |
return STATUS_NO_SUCH_FILE; |
305 |
} |
} |
306 |
} |
} |
307 |
|
|
308 |
|
/* all read and writes of files should be non blocking */ |
309 |
|
if (fcntl(handle, F_SETFL, O_NONBLOCK) == -1) |
310 |
|
perror("fcntl"); |
311 |
} |
} |
312 |
|
|
313 |
if (handle >= MAX_OPEN_FILES) |
if (handle >= MAX_OPEN_FILES) |
352 |
{ |
{ |
353 |
int n; |
int n; |
354 |
|
|
355 |
|
/* browsing dir ???? */ |
356 |
|
/* each request is 24 bytes */ |
357 |
|
if (g_fileinfo[handle].flags_and_attributes & FILE_DIRECTORY_FILE) |
358 |
|
{ |
359 |
|
*result = 0; |
360 |
|
return STATUS_SUCCESS; |
361 |
|
} |
362 |
|
|
363 |
if (offset) |
if (offset) |
364 |
lseek(handle, offset, SEEK_SET); |
lseek(handle, offset, SEEK_SET); |
365 |
n = read(handle, data, length); |
n = read(handle, data, length); |
539 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
540 |
} |
} |
541 |
|
|
|
int fsstat(const char *path, struct fsinfo *buf) |
|
|
{ |
|
|
int ret; |
|
|
#if defined(HAVE_STATFS) |
|
|
struct statfs statbuf; |
|
|
#elif defined(HAVE_STATVFS) |
|
|
struct statvfs statbuf; |
|
|
#endif |
|
|
|
|
|
#if defined(HAVE_STATFS) |
|
|
ret = statfs(path, &statbuf); |
|
|
buf->f_namelen = statbuf.f_namelen; |
|
|
#elif defined(HAVE_STATVFS) |
|
|
ret = statvfs(path, &statbuf); |
|
|
buf->f_namelen = statbuf.f_namemax; |
|
|
#else |
|
|
ret=-1; |
|
|
#endif |
|
|
|
|
|
buf->f_blocks = statbuf.f_blocks; |
|
|
buf->f_bfree = statbuf.f_bfree; |
|
|
buf->f_bsize = statbuf.f_bsize; |
|
|
|
|
|
return ret; |
|
|
} |
|
|
|
|
542 |
NTSTATUS |
NTSTATUS |
543 |
disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) |
disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) |
544 |
{ |
{ |
545 |
char *volume, *fs_type; |
char *volume, *fs_type; |
546 |
struct fsinfo stat_fs; |
struct STATFS_T stat_fs; |
547 |
struct fileinfo *pfinfo; |
struct fileinfo *pfinfo; |
548 |
|
|
549 |
pfinfo = &(g_fileinfo[handle]); |
pfinfo = &(g_fileinfo[handle]); |
550 |
volume = "RDESKTOP"; |
volume = "RDESKTOP"; |
551 |
fs_type = "RDPFS"; |
fs_type = "RDPFS"; |
552 |
|
|
553 |
if (fsstat(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ |
if (STATFS_FN(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ |
554 |
{ |
{ |
555 |
perror("statfs"); |
perror("statfs"); |
556 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
581 |
case 5: /* FileFsAttributeInformation */ |
case 5: /* FileFsAttributeInformation */ |
582 |
|
|
583 |
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 */ |
584 |
out_uint32_le(out, stat_fs.f_namelen); /* max length of filename */ |
out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */ |
585 |
out_uint32_le(out, 2 * strlen(fs_type)); /* length of fs_type */ |
out_uint32_le(out, 2 * strlen(fs_type)); /* length of fs_type */ |
586 |
rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2); |
rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2); |
587 |
break; |
break; |
640 |
|
|
641 |
// Get information for directory entry |
// Get information for directory entry |
642 |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); |
643 |
/* JIF |
/* JIF |
644 |
printf("Stat: %s\n", fullpath); */ |
printf("Stat: %s\n", fullpath); */ |
645 |
if (stat(fullpath, &fstat)) |
if (stat(fullpath, &fstat)) |
646 |
{ |
{ |