--- sourceforge.net/trunk/rdesktop/disk.c 2005/02/21 12:39:34 818 +++ sourceforge.net/trunk/rdesktop/disk.c 2005/08/02 09:28:54 943 @@ -18,7 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "rdesktop.h" #include "disk.h" #include @@ -28,6 +27,7 @@ #include /* opendir, closedir, readdir */ #include #include /* errno */ +#include #include #include /* ctime */ @@ -38,51 +38,105 @@ #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 +/* TODO: Fix mntent-handling for solaris + * #include */ +#if (defined(HAVE_MNTENT_H) && defined(HAVE_SETMNTENT)) +#include +#define MNTENT_PATH "/etc/mtab" +#define USE_SETMNTENT #endif -#if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__)) -#include /* solaris statvfs */ -/* 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) +#ifdef HAVE_SYS_VFS_H +#include +#endif + +#ifdef HAVE_SYS_STATVFS_H +#include +#endif -#elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__)) +#ifdef HAVE_SYS_STATFS_H +#include +#endif + +#ifdef HAVE_SYS_PARAM_H #include +#endif + +#ifdef HAVE_SYS_MOUNT_H #include -#define STATFS_FN(path, buf) (statfs(path,buf)) +#endif + +#include "rdesktop.h" + +#ifdef STAT_STATFS3_OSF1 +#define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf))) #define STATFS_T statfs -#define F_NAMELEN(buf) (NAME_MAX) +#define USE_STATFS +#endif -#elif (defined(__SGI_IRIX__)) -#include -#include +#ifdef STAT_STATVFS #define STATFS_FN(path, buf) (statvfs(path,buf)) #define STATFS_T statvfs -#define F_NAMELEN(buf) ((buf).f_namemax) +#define USE_STATVFS +#endif -#elif (defined(__alpha) && !defined(linux)) -#include /* osf1 statfs */ -#define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf))) -#define STATFS_T statfs -#define F_NAMELEN(buf) (255) +#ifdef STAT_STATVFS64 +#define STATFS_FN(path, buf) (statvfs64(path,buf)) +#define STATFS_T statvfs64 +#define USE_STATVFS +#endif -#else -#include /* linux statfs */ -#include -#define HAVE_MNTENT_H -#define MNTENT_PATH "/etc/mtab" +#if (defined(STAT_STATFS2_FS_DATA) || defined(STAT_STATFS2_BSIZE) || defined(STAT_STATFS2_FSIZE)) #define STATFS_FN(path, buf) (statfs(path,buf)) #define STATFS_T statfs +#define USE_STATFS +#endif + +#ifdef STAT_STATFS4 +#define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf),0)) +#define STATFS_T statfs +#define USE_STATFS +#endif + +#if ((defined(USE_STATFS) && defined(HAVE_STRUCT_STATFS_F_NAMEMAX)) || (defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_NAMEMAX))) +#define F_NAMELEN(buf) ((buf).f_namemax) +#endif + +#if ((defined(USE_STATFS) && defined(HAVE_STRUCT_STATFS_F_NAMELEN)) || (defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_NAMELEN))) #define F_NAMELEN(buf) ((buf).f_namelen) #endif +#ifndef F_NAMELEN +#define F_NAMELEN(buf) (255) +#endif + +/* Dummy statfs fallback */ +#ifndef STATFS_T +struct dummy_statfs_t +{ + long f_bfree; + long f_bsize; + long f_blocks; + int f_namelen; + int f_namemax; +}; + +static int +dummy_statfs(struct dummy_statfs_t *buf) +{ + buf->f_blocks = 262144; + buf->f_bfree = 131072; + buf->f_bsize = 512; + buf->f_namelen = 255; + buf->f_namemax = 255; + + return 0; +} + +#define STATFS_T dummy_statfs_t +#define STATFS_FN(path,buf) (dummy_statfs(buf)) +#endif + extern RDPDR_DEVICE g_rdpdr_device[]; FILEINFO g_fileinfo[MAX_OPEN_FILES]; @@ -260,14 +314,14 @@ char *pos2; int count = 0; - // skip the first colon + /* skip the first colon */ optarg++; while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) { pos2 = next_arg(optarg, '='); - strncpy(g_rdpdr_device[*id].name, optarg, sizeof(g_rdpdr_device[*id].name)-1); - if (strlen(optarg) > (sizeof(g_rdpdr_device[*id].name)-1)) + strncpy(g_rdpdr_device[*id].name, optarg, sizeof(g_rdpdr_device[*id].name) - 1); + if (strlen(optarg) > (sizeof(g_rdpdr_device[*id].name) - 1)) fprintf(stderr, "share name %s truncated to %s\n", optarg, g_rdpdr_device[*id].name); @@ -306,38 +360,38 @@ { case CREATE_ALWAYS: - // Delete existing file/link. + /* Delete existing file/link. */ unlink(path); flags |= O_CREAT; break; case CREATE_NEW: - // If the file already exists, then fail. + /* If the file already exists, then fail. */ flags |= O_CREAT | O_EXCL; break; case OPEN_ALWAYS: - // Create if not already exists. + /* Create if not already exists. */ flags |= O_CREAT; break; case OPEN_EXISTING: - // Default behaviour + /* Default behaviour */ break; case TRUNCATE_EXISTING: - // If the file does not exist, then fail. + /* If the file does not exist, then fail. */ flags |= O_TRUNC; break; } - //printf("Open: \"%s\" flags: %X, accessmask: %X sharemode: %X create disp: %X\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); + /*printf("Open: \"%s\" flags: %X, accessmask: %X sharemode: %X create disp: %X\n", path, flags_and_attributes, accessmask, sharemode, create_disposition); */ - // Get information about file and set that flag ourselfs + /* Get information about file and set that flag ourselfs */ if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode))) { if (flags_and_attributes & FILE_NON_DIRECTORY_FILE) @@ -568,7 +622,7 @@ path = g_fileinfo[handle].path; - // Get information about file + /* Get information about file */ if (fstat(handle, &filestat) != 0) { perror("stat"); @@ -576,7 +630,7 @@ return STATUS_ACCESS_DENIED; } - // Set file attributes + /* Set file attributes */ file_attributes = 0; if (S_ISDIR(filestat.st_mode)) file_attributes |= FILE_ATTRIBUTE_DIRECTORY; @@ -591,25 +645,25 @@ if (!(filestat.st_mode & S_IWUSR)) file_attributes |= FILE_ATTRIBUTE_READONLY; - // Return requested data + /* Return requested data */ switch (info_class) { case FileBasicInformation: seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high, &ft_low); - out_uint32_le(out, ft_low); //create_access_time + out_uint32_le(out, ft_low); /* create_access_time */ out_uint32_le(out, ft_high); seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low); - out_uint32_le(out, ft_low); //last_access_time + out_uint32_le(out, ft_low); /* last_access_time */ out_uint32_le(out, ft_high); seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low); - out_uint32_le(out, ft_low); //last_write_time + out_uint32_le(out, ft_low); /* last_write_time */ out_uint32_le(out, ft_high); seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low); - out_uint32_le(out, ft_low); //last_change_time + out_uint32_le(out, ft_low); /* last_change_time */ out_uint32_le(out, ft_high); out_uint32_le(out, file_attributes); @@ -617,13 +671,13 @@ case FileStandardInformation: - out_uint32_le(out, filestat.st_size); //Allocation size + out_uint32_le(out, filestat.st_size); /* Allocation size */ out_uint32_le(out, 0); - out_uint32_le(out, filestat.st_size); //End of file + out_uint32_le(out, filestat.st_size); /* End of file */ out_uint32_le(out, 0); - out_uint32_le(out, filestat.st_nlink); //Number of links - out_uint8(out, 0); //Delete pending - out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0); //Directory + out_uint32_le(out, filestat.st_nlink); /* Number of links */ + out_uint8(out, 0); /* Delete pending */ + out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0); /* Directory */ break; case FileObjectIdInformation: @@ -663,23 +717,23 @@ in_uint8s(in, 4); /* Handle of root dir? */ in_uint8s(in, 24); /* unknown */ - // CreationTime + /* CreationTime */ in_uint32_le(in, ft_low); in_uint32_le(in, ft_high); - // AccessTime + /* AccessTime */ in_uint32_le(in, ft_low); in_uint32_le(in, ft_high); if (ft_low || ft_high) access_time = convert_1970_to_filetime(ft_high, ft_low); - // WriteTime + /* WriteTime */ in_uint32_le(in, ft_low); in_uint32_le(in, ft_high); if (ft_low || ft_high) write_time = convert_1970_to_filetime(ft_high, ft_low); - // ChangeTime + /* ChangeTime */ in_uint32_le(in, ft_low); in_uint32_le(in, ft_high); if (ft_low || ft_high) @@ -718,7 +772,7 @@ } if (!file_attributes) - break; // not valid + break; /* not valid */ mode = filestat.st_mode; @@ -835,7 +889,7 @@ if (memcmp(&pfinfo->notify, ¬ify, sizeof(NOTIFY))) { - //printf("disk_check_notify found changed event\n"); + /*printf("disk_check_notify found changed event\n"); */ memcpy(&pfinfo->notify, ¬ify, sizeof(NOTIFY)); status = STATUS_NOTIFY_ENUM_DIR; } @@ -925,9 +979,9 @@ FsVolumeInfo(char *fpath) { - FILE *fdfs; static FsInfoType info; -#ifdef HAVE_MNTENT_H +#ifdef USE_SETMNTENT + FILE *fdfs; struct mntent *e; #endif @@ -936,7 +990,7 @@ strcpy(info.label, "RDESKTOP"); strcpy(info.type, "RDPFS"); -#ifdef HAVE_MNTENT_H +#ifdef USE_SETMNTENT fdfs = setmntent(MNTENT_PATH, "r"); if (!fdfs) return &info; @@ -970,7 +1024,7 @@ 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]; + /* info.Serial = (buf[128]<<24)+(buf[127]<<16)+(buf[126]<<8)+buf[125]; */ } close(fd); } @@ -1073,14 +1127,14 @@ { case FileBothDirectoryInformation: - // If a search pattern is received, remember this pattern, and restart search + /* If a search pattern is received, remember this pattern, and restart search */ if (pattern[0] != 0) { strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), 64); rewinddir(pdir); } - // find next dirent matching pattern + /* find next dirent matching pattern */ pdirent = readdir(pdir); while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0) pdirent = readdir(pdir); @@ -1088,7 +1142,7 @@ if (pdirent == NULL) return STATUS_NO_MORE_FILES; - // Get information for directory entry + /* Get information for directory entry */ sprintf(fullpath, "%s/%s", dirname, pdirent->d_name); if (stat(fullpath, &fstat)) @@ -1119,34 +1173,34 @@ if (!(fstat.st_mode & S_IWUSR)) file_attributes |= FILE_ATTRIBUTE_READONLY; - // Return requested information - out_uint8s(out, 8); //unknown zero + /* Return requested information */ + out_uint8s(out, 8); /* unknown zero */ seconds_since_1970_to_filetime(get_create_time(&fstat), &ft_high, &ft_low); - out_uint32_le(out, ft_low); // create time + out_uint32_le(out, ft_low); /* create time */ out_uint32_le(out, ft_high); seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low); - out_uint32_le(out, ft_low); //last_access_time + out_uint32_le(out, ft_low); /* last_access_time */ out_uint32_le(out, ft_high); seconds_since_1970_to_filetime(fstat.st_mtime, &ft_high, &ft_low); - out_uint32_le(out, ft_low); //last_write_time + out_uint32_le(out, ft_low); /* last_write_time */ out_uint32_le(out, ft_high); seconds_since_1970_to_filetime(fstat.st_ctime, &ft_high, &ft_low); - out_uint32_le(out, ft_low); //change_write_time + out_uint32_le(out, ft_low); /* change_write_time */ out_uint32_le(out, ft_high); - out_uint32_le(out, fstat.st_size); //filesize low - out_uint32_le(out, 0); //filesize high - out_uint32_le(out, fstat.st_size); //filesize low - out_uint32_le(out, 0); //filesize high + out_uint32_le(out, fstat.st_size); /* filesize low */ + out_uint32_le(out, 0); /* filesize high */ + out_uint32_le(out, fstat.st_size); /* filesize low */ + out_uint32_le(out, 0); /* filesize high */ out_uint32_le(out, file_attributes); - out_uint8(out, 2 * strlen(pdirent->d_name) + 2); //unicode length - out_uint8s(out, 7); //pad? - out_uint8(out, 0); //8.3 file length - out_uint8s(out, 2 * 12); //8.3 unicode length + out_uint8(out, 2 * strlen(pdirent->d_name) + 2); /* unicode length */ + out_uint8s(out, 7); /* pad? */ + out_uint8(out, 0); /* 8.3 file length */ + out_uint8s(out, 2 * 12); /* 8.3 unicode length */ rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name)); break; @@ -1178,8 +1232,8 @@ switch (request) { - case 25: // ? - case 42: // ? + case 25: /* ? */ + case 42: /* ? */ default: unimpl("DISK IOCTL %d\n", request); return STATUS_INVALID_PARAMETER;