--- sourceforge.net/trunk/rdesktop/disk.c 2004/04/15 20:53:32 653 +++ sourceforge.net/trunk/rdesktop/disk.c 2004/08/25 15:42:42 759 @@ -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,11 +31,21 @@ #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)) @@ -59,6 +59,13 @@ #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,7 +167,7 @@ } /* 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) { @@ -319,7 +324,7 @@ return STATUS_SUCCESS; } -NTSTATUS +static NTSTATUS disk_close(HANDLE handle) { struct fileinfo *pfinfo; @@ -339,7 +344,7 @@ return STATUS_SUCCESS; } -NTSTATUS +static NTSTATUS disk_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { int n; @@ -376,7 +381,7 @@ return STATUS_SUCCESS; } -NTSTATUS +static NTSTATUS disk_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { int n; @@ -608,11 +613,25 @@ break; case FileDispositionInformation: - - //unimpl("IRP Set File Information class: FileDispositionInformation\n"); + /* As far as I understand it, the correct + thing to do here is to *schedule* a delete, + so it will be deleted when the file is + closed. Subsequent + FileDispositionInformation requests with + DeleteFile set to FALSE should unschedule + the delete. See + http://www.osronline.com/article.cfm?article=245. Currently, + we are deleting the file immediately. I + guess this is a FIXME. */ //in_uint32_le(in, delete_on_close); - // disk_close(handle); + + /* Make sure we close the file before + unlinking it. Not doing so would trigger + silly-delete if using NFS, which might fail + on FAT floppies, for example. */ + disk_close(handle); + if ((pfinfo->flags_and_attributes & FILE_DIRECTORY_FILE)) // remove a directory { if (rmdir(pfinfo->path) < 0) @@ -624,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 */ @@ -637,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: @@ -649,7 +675,7 @@ return STATUS_SUCCESS; } -FsInfoType * +static FsInfoType * FsVolumeInfo(char *fpath) { @@ -799,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) @@ -819,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)) @@ -869,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;