--- sourceforge.net/trunk/rdesktop/disk.c 2004/04/16 11:37:24 659 +++ sourceforge.net/trunk/rdesktop/disk.c 2004/10/15 18:02:45 783 @@ -20,16 +20,6 @@ #include "disk.h" -#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) -#define SOLARIS -#endif - -#if (defined(SOLARIS) || defined(__hpux)) -#define DIRFD(a) ((a)->dd_fd) -#else -#define DIRFD(a) (dirfd(a)) -#endif - #include #include #include @@ -41,24 +31,41 @@ #include #include /* ctime */ +#if (defined(HAVE_DIRFD) || (HAVE_DECL_DIRFD == 1)) +#define DIRFD(a) (dirfd(a)) +#else +#define DIRFD(a) ((a)->DIR_FD_MEMBER_NAME) +#endif + +/* TODO: let autoconf figure out everything below... */ +#if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) +#define SOLARIS +#endif #if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__)) #include /* solaris statvfs */ -#include -/* TODO: Fix mntent-handling for solaris */ +/* TODO: Fix mntent-handling for solaris/hpux + * #include */ #undef HAVE_MNTENT_H #define MNTENT_PATH "/etc/mnttab" #define STATFS_FN(path, buf) (statvfs(path,buf)) #define STATFS_T statvfs #define F_NAMELEN(buf) ((buf).f_namemax) -#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) +#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__)) #include #include #define STATFS_FN(path, buf) (statfs(path,buf)) #define STATFS_T statfs #define F_NAMELEN(buf) (NAME_MAX) +#elif (defined(__SGI_IRIX__)) +#include +#include +#define STATFS_FN(path, buf) (statvfs(path,buf)) +#define STATFS_T statvfs +#define F_NAMELEN(buf) ((buf).f_namemax) + #else #include /* linux statfs */ #include @@ -84,7 +91,7 @@ } FsInfoType; -time_t +static time_t get_create_time(struct stat *st) { time_t ret, ret1; @@ -99,7 +106,7 @@ } /* Convert seconds since 1970 to a filetime */ -void +static void seconds_since_1970_to_filetime(time_t seconds, uint32 * high, uint32 * low) { unsigned long long ticks; @@ -110,7 +117,7 @@ } /* Convert seconds since 1970 back to filetime */ -time_t +static time_t convert_1970_to_filetime(uint32 high, uint32 low) { unsigned long long ticks; @@ -142,16 +149,14 @@ while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) { pos2 = next_arg(optarg, '='); - strcpy(g_rdpdr_device[*id].name, optarg); - - toupper_str(g_rdpdr_device[*id].name); - /* add trailing colon to name. */ - strcat(g_rdpdr_device[*id].name, ":"); + strncpy(g_rdpdr_device[*id].name, optarg, sizeof(g_rdpdr_device[*id].name)); + if (strlen(optarg) > 8) + fprintf(stderr, "share name %s truncated to %s\n", optarg, + g_rdpdr_device[*id].name); g_rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1); 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); g_rdpdr_device[*id].device_type = DEVICE_TYPE_DISK; count++; (*id)++; @@ -162,11 +167,11 @@ } /* Opens or creates a file or directory */ -NTSTATUS +static NTSTATUS disk_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, - uint32 flags_and_attributes, char *filename, HANDLE * phandle) + uint32 flags_and_attributes, char *filename, NTHANDLE * phandle) { - HANDLE handle; + NTHANDLE handle; DIR *dirp; int flags, mode; char path[256]; @@ -319,8 +324,8 @@ return STATUS_SUCCESS; } -NTSTATUS -disk_close(HANDLE handle) +static NTSTATUS +disk_close(NTHANDLE handle) { struct fileinfo *pfinfo; @@ -339,8 +344,8 @@ return STATUS_SUCCESS; } -NTSTATUS -disk_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) +static NTSTATUS +disk_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { int n; @@ -376,8 +381,8 @@ return STATUS_SUCCESS; } -NTSTATUS -disk_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) +static NTSTATUS +disk_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { int n; @@ -404,7 +409,7 @@ } NTSTATUS -disk_query_information(HANDLE handle, uint32 info_class, STREAM out) +disk_query_information(NTHANDLE handle, uint32 info_class, STREAM out) { uint32 file_attributes, ft_high, ft_low; struct stat filestat; @@ -485,7 +490,7 @@ } NTSTATUS -disk_set_information(HANDLE handle, uint32 info_class, STREAM in, STREAM out) +disk_set_information(NTHANDLE handle, uint32 info_class, STREAM in, STREAM out) { uint32 device_id, length, file_attributes, ft_high, ft_low; char newname[256], fullpath[256]; @@ -638,9 +643,11 @@ break; case FileAllocationInformation: - - unimpl("IRP Set File Information class: FileAllocationInformation\n"); - break; + /* Fall through to FileEndOfFileInformation, + which uses ftrunc. This is like Samba with + "strict allocation = false", and means that + we won't detect out-of-quota errors, for + example. */ case FileEndOfFileInformation: in_uint8s(in, 28); /* unknown */ @@ -651,9 +658,14 @@ if (stat_fs.f_bsize * stat_fs.f_bfree < length) return STATUS_DISK_FULL; - //printf("FileEndOfFileInformation length = %d\n", length); - // ???????????? - //unimpl("IRP Set File Information class: FileEndOfFileInformation\n"); + /* FIXME: Growing file with ftruncate doesn't + work with Linux FAT fs */ + if (ftruncate(handle, length) != 0) + { + perror("ftruncate"); + return STATUS_DISK_FULL; + } + break; default: @@ -663,7 +675,7 @@ return STATUS_SUCCESS; } -FsInfoType * +static FsInfoType * FsVolumeInfo(char *fpath) { @@ -732,7 +744,7 @@ NTSTATUS -disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) +disk_query_volume_information(NTHANDLE handle, uint32 info_class, STREAM out) { struct STATFS_T stat_fs; struct fileinfo *pfinfo; @@ -797,7 +809,7 @@ } NTSTATUS -disk_query_directory(HANDLE handle, uint32 info_class, char *pattern, STREAM out) +disk_query_directory(NTHANDLE handle, uint32 info_class, char *pattern, STREAM out) { uint32 file_attributes, ft_low, ft_high; char *dirname, fullpath[256]; @@ -813,7 +825,7 @@ switch (info_class) { - case 3: //FIXME: Why 3? + case FileBothDirectoryInformation: // If a search pattern is received, remember this pattern, and restart search if (pattern[0] != 0) @@ -833,13 +845,23 @@ // Get information for directory entry sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); - /* JIF - printf("Stat: %s\n", fullpath); */ if (stat(fullpath, &fstat)) { - perror("stat"); - out_uint8(out, 0); - return STATUS_ACCESS_DENIED; + switch (errno) + { + case ENOENT: + case ELOOP: + case EACCES: + /* These are non-fatal errors. */ + memset(&fstat, 0, sizeof(fstat)); + break; + default: + /* Fatal error. By returning STATUS_NO_SUCH_FILE, + the directory list operation will be aborted */ + perror(fullpath); + out_uint8(out, 0); + return STATUS_NO_SUCH_FILE; + } } if (S_ISDIR(fstat.st_mode)) @@ -883,6 +905,9 @@ break; default: + /* FIXME: Support FileDirectoryInformation, + FileFullDirectoryInformation, and + FileNamesInformation */ unimpl("IRP Query Directory sub: 0x%x\n", info_class); return STATUS_INVALID_PARAMETER; @@ -894,7 +919,7 @@ static NTSTATUS -disk_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out) +disk_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) { uint32 result;