--- sourceforge.net/trunk/rdesktop/disk.c 2004/01/21 18:02:38 570 +++ sourceforge.net/trunk/rdesktop/disk.c 2004/01/21 22:13:20 573 @@ -64,14 +64,41 @@ #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 + #include #include -#include /* linux statfs */ #include #include /* open, close */ #include /* opendir, closedir, readdir */ #include #include /* errno */ + +#if defined(SOLARIS) +#include /* solaris statvfs */ +#define HAVE_STATVFS +#define F_NAMELEN(buf) ((buf).f_namemax) + +#elif defined(__OpenBSD__) +#include +#include +#define HAVE_STATFS +#define F_NAMELEN(buf) (NAME_MAX) + +#else +#include /* linux statfs */ +#define HAVE_STATFS +#define F_NAMELEN(buf) ((buf).f_namelen) +#endif + #include "rdesktop.h" extern RDPDR_DEVICE g_rdpdr_device[]; @@ -87,6 +114,11 @@ } g_fileinfo[MAX_OPEN_FILES]; +struct fsinfo +{ + uint32 f_blocks, f_bfree, f_bsize, f_namelen; +}; + /* Convert seconds since 1970 to a filetime */ void seconds_since_1970_to_filetime(time_t seconds, uint32 * high, uint32 * low) @@ -212,7 +244,7 @@ return STATUS_NO_SUCH_FILE; } } - handle = dirfd(dirp); /* FIXME: dirfd is not portable */ + handle = DIRFD(dirp); } else { @@ -472,18 +504,43 @@ return STATUS_SUCCESS; } +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); +#elif defined(HAVE_STATVFS) + ret = statvfs(path, &statbuf); +#else + ret=-1; +#endif + + buf->f_blocks = statbuf.f_blocks; + buf->f_bfree = statbuf.f_bfree; + buf->f_bsize = statbuf.f_bsize; + buf->f_namelen = F_NAMELEN(statbuf); + + return ret; +} + NTSTATUS disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out) { char *volume, *fs_type; - struct statfs stat_fs; + struct fsinfo stat_fs; struct fileinfo *pfinfo; pfinfo = &(g_fileinfo[handle]); volume = "RDESKTOP"; fs_type = "RDPFS"; - if (statfs(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ + if (fsstat(pfinfo->path, &stat_fs) != 0) /* FIXME: statfs is not portable */ { perror("statfs"); return STATUS_ACCESS_DENIED;