--- sourceforge.net/trunk/rdesktop/disk.c 2004/02/06 12:57:26 601 +++ sourceforge.net/trunk/rdesktop/disk.c 2004/04/15 20:42:19 652 @@ -18,73 +18,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define FILE_ATTRIBUTE_READONLY 0x00000001 -#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 +#include "disk.h" #if (defined(sun) && (defined(__svr4__) || defined(__SVR4))) #define SOLARIS #endif -#ifdef SOLARIS +#if (defined(SOLARIS) || defined(__hpux)) #define DIRFD(a) ((a)->dd_fd) #else #define DIRFD(a) (dirfd(a)) @@ -102,8 +42,12 @@ #include /* ctime */ -#if defined(SOLARIS) +#if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__)) #include /* solaris statvfs */ +#include +/* TODO: Fix mntent-handling for solaris */ +#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) @@ -117,6 +61,9 @@ #else #include /* linux statfs */ +#include +#define HAVE_MNTENT_H +#define MNTENT_PATH "/etc/mtab" #define STATFS_FN(path, buf) (statfs(path,buf)) #define STATFS_T statfs #define F_NAMELEN(buf) ((buf).f_namelen) @@ -126,16 +73,15 @@ extern RDPDR_DEVICE g_rdpdr_device[]; -struct fileinfo +FILEINFO g_fileinfo[MAX_OPEN_FILES]; + +typedef struct { - uint32 device_id, flags_and_attributes; - char path[256]; - DIR *pdir; - struct dirent *pdirent; - char pattern[64]; - BOOL delete_on_close; -} -g_fileinfo[MAX_OPEN_FILES]; + char name[256]; + char label[256]; + unsigned long serial; + char type[256]; +} FsInfoType; time_t @@ -182,10 +128,10 @@ /* Enumeration of devices from rdesktop.c */ /* returns numer of units found and initialized. */ -/* optarg looks like ':h:=/mnt/floppy,b:=/mnt/usbdevice1' */ +/* optarg looks like ':h=/mnt/floppy,b=/mnt/usbdevice1' */ /* when it arrives to this function. */ int -disk_enum_devices(int *id, char *optarg) +disk_enum_devices(uint32 * id, char *optarg) { char *pos = optarg; char *pos2; @@ -341,6 +287,9 @@ case ENOENT: return STATUS_NO_SUCH_FILE; + case EEXIST: + + return STATUS_OBJECT_NAME_COLLISION; default: perror("open"); @@ -405,8 +354,8 @@ } #endif - if (offset) - lseek(handle, offset, SEEK_SET); + lseek(handle, offset, SEEK_SET); + n = read(handle, data, length); if (n < 0) @@ -432,8 +381,7 @@ { int n; - if (offset) - lseek(handle, offset, SEEK_SET); + lseek(handle, offset, SEEK_SET); n = write(handle, data, length); @@ -547,6 +495,7 @@ struct stat filestat; time_t write_time, change_time, access_time, mod_time; struct utimbuf tvs; + struct STATFS_T stat_fs; pfinfo = &(g_fileinfo[handle]); @@ -629,6 +578,7 @@ if (fchmod(handle, mode)) return STATUS_ACCESS_DENIED; + break; case 10: /* FileRenameInformation */ @@ -682,10 +632,14 @@ in_uint8s(in, 28); /* unknown */ in_uint32_le(in, length); /* file size */ - printf("FileEndOfFileInformation length = %d\n", length); - // ???????????? + /* prevents start of writing if not enough space left on device */ + if (STATFS_FN(g_rdpdr_device[pfinfo->device_id].local_path, &stat_fs) == 0) + if (stat_fs.f_bsize * stat_fs.f_bfree < length) + return STATUS_DISK_FULL; - unimpl("IRP Set File Information class: FileEndOfFileInformation\n"); + //printf("FileEndOfFileInformation length = %d\n", length); + // ???????????? + //unimpl("IRP Set File Information class: FileEndOfFileInformation\n"); break; default: @@ -695,16 +649,82 @@ return STATUS_SUCCESS; } +FsInfoType * +FsVolumeInfo(char *fpath) +{ + +#ifdef HAVE_MNTENT_H + FILE *fdfs; + struct mntent *e; + static FsInfoType info; + + /* initialize */ + memset(&info, 0, sizeof(info)); + strcpy(info.label, "RDESKTOP"); + strcpy(info.type, "RDPFS"); + + fdfs = setmntent(MNTENT_PATH, "r"); + if (!fdfs) + return &info; + + while ((e = getmntent(fdfs))) + { + if (strncmp(fpath, e->mnt_dir, strlen(fpath)) == 0) + { + strcpy(info.type, e->mnt_type); + strcpy(info.name, e->mnt_fsname); + if (strstr(e->mnt_opts, "vfat") || strstr(e->mnt_opts, "iso9660")) + { + int fd = open(e->mnt_fsname, O_RDONLY); + if (fd >= 0) + { + unsigned char buf[512]; + memset(buf, 0, sizeof(buf)); + if (strstr(e->mnt_opts, "vfat")) + /*FAT*/ + { + strcpy(info.type, "vfat"); + read(fd, buf, sizeof(buf)); + info.serial = + (buf[42] << 24) + (buf[41] << 16) + + (buf[40] << 8) + buf[39]; + strncpy(info.label, buf + 43, 10); + info.label[10] = '\0'; + } + else if (lseek(fd, 32767, SEEK_SET) >= 0) /* ISO9660 */ + { + read(fd, buf, sizeof(buf)); + strncpy(info.label, buf + 41, 32); + info.label[32] = '\0'; + //info.Serial = (buf[128]<<24)+(buf[127]<<16)+(buf[126]<<8)+buf[125]; + } + close(fd); + } + } + } + } + endmntent(fdfs); +#else + static FsInfoType info; + + /* initialize */ + memset(&info, 0, sizeof(info)); + strcpy(info.label, "RDESKTOP"); + strcpy(info.type, "RDPFS"); + +#endif + return &info; +} + + NTSTATUS disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) { - char *volume, *fs_type; struct STATFS_T stat_fs; struct fileinfo *pfinfo; + FsInfoType *fsinfo; pfinfo = &(g_fileinfo[handle]); - volume = "RDESKTOP"; - fs_type = "RDPFS"; if (STATFS_FN(pfinfo->path, &stat_fs) != 0) { @@ -712,16 +732,20 @@ return STATUS_ACCESS_DENIED; } + fsinfo = FsVolumeInfo(pfinfo->path); + switch (info_class) { case 1: /* FileFsVolumeInformation */ out_uint32_le(out, 0); /* volume creation time low */ out_uint32_le(out, 0); /* volume creation time high */ - out_uint32_le(out, 0); /* serial */ - out_uint32_le(out, 2 * strlen(volume)); /* length of string */ + out_uint32_le(out, fsinfo->serial); /* serial */ + + out_uint32_le(out, 2 * strlen(fsinfo->label)); /* length of string */ + out_uint8(out, 0); /* support objects? */ - rdp_out_unistr(out, volume, 2 * strlen(volume) - 2); + rdp_out_unistr(out, fsinfo->label, 2 * strlen(fsinfo->label) - 2); break; case 3: /* FileFsSizeInformation */ @@ -738,8 +762,9 @@ out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED); /* fs attributes */ out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */ - out_uint32_le(out, 2 * strlen(fs_type)); /* length of fs_type */ - rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2); + + out_uint32_le(out, 2 * strlen(fsinfo->type)); /* length of fs_type */ + rdp_out_unistr(out, fsinfo->type, 2 * strlen(fsinfo->type) - 2); break; case 2: /* FileFsLabelInformation */