/[rdesktop]/jpeg/rdesktop/trunk/disk.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/disk.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 827 by astrand, Thu Mar 3 08:48:24 2005 UTC revision 873 by stargo, Sat Apr 2 17:31:27 2005 UTC
# Line 18  Line 18 
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */  */
20    
 #include "rdesktop.h"  
21  #include "disk.h"  #include "disk.h"
22    
23  #include <sys/types.h>  #include <sys/types.h>
# Line 38  Line 37 
37  #define DIRFD(a) ((a)->DIR_FD_MEMBER_NAME)  #define DIRFD(a) ((a)->DIR_FD_MEMBER_NAME)
38  #endif  #endif
39    
40  /* TODO: let autoconf figure out everything below... */  /* TODO: Fix mntent-handling for solaris
41  #if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))   * #include <sys/mntent.h> */
42  #define SOLARIS  #if (defined(HAVE_MNTENT_H) && defined(HAVE_SETMNTENT))
43    #include <mntent.h>
44    #define MNTENT_PATH "/etc/mtab"
45    #define USE_SETMNTENT
46  #endif  #endif
47    
48  #if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__))  #ifdef HAVE_SYS_VFS_H
49  #include <sys/statvfs.h>        /* solaris statvfs */  #include <sys/vfs.h>
50  /* TODO: Fix mntent-handling for solaris/hpux  #endif
51   * #include <sys/mntent.h> */  
52  #undef HAVE_MNTENT_H  #ifdef HAVE_SYS_STATVFS_H
53  #define MNTENT_PATH "/etc/mnttab"  #include <sys/statvfs.h>
54  #define STATFS_FN(path, buf) (statvfs(path,buf))  #endif
 #define STATFS_T statvfs  
 #define F_NAMELEN(buf) ((buf).f_namemax)  
55    
56  #elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__))  #ifdef HAVE_SYS_STATFS_H
57    #include <sys/statfs.h>
58    #endif
59    
60    #ifdef HAVE_SYS_PARAM_H
61  #include <sys/param.h>  #include <sys/param.h>
62    #endif
63    
64    #ifdef HAVE_SYS_MOUNT_H
65  #include <sys/mount.h>  #include <sys/mount.h>
66  #define STATFS_FN(path, buf) (statfs(path,buf))  #endif
67    
68    #include "rdesktop.h"
69    
70    #ifdef STAT_STATFS3_OSF1
71    #define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf)))
72  #define STATFS_T statfs  #define STATFS_T statfs
73  #define F_NAMELEN(buf) (NAME_MAX)  #define USE_STATFS
74    #endif
75    
76  #elif (defined(__SGI_IRIX__))  #ifdef STAT_STATVFS
 #include <sys/types.h>  
 #include <sys/statvfs.h>  
77  #define STATFS_FN(path, buf) (statvfs(path,buf))  #define STATFS_FN(path, buf) (statvfs(path,buf))
78  #define STATFS_T statvfs  #define STATFS_T statvfs
79  #define F_NAMELEN(buf) ((buf).f_namemax)  #define USE_STATVFS
80    #endif
81    
82  #elif (defined(__alpha) && !defined(linux))  #ifdef STAT_STATVFS64
83  #include <sys/mount.h>          /* osf1 statfs */  #define STATFS_FN(path, buf) (statvfs64(path,buf))
84  #define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf)))  #define STATFS_T statvfs64
85  #define STATFS_T statfs  #define USE_STATVFS
86  #define F_NAMELEN(buf) (255)  #endif
87    
88  #else  #if (defined(STAT_STATFS2_FS_DATA) || defined(STAT_STATFS2_BSIZE) || defined(STAT_STATFS2_FSIZE))
 #include <sys/vfs.h>            /* linux statfs */  
 #include <mntent.h>  
 #define HAVE_MNTENT_H  
 #define MNTENT_PATH "/etc/mtab"  
89  #define STATFS_FN(path, buf) (statfs(path,buf))  #define STATFS_FN(path, buf) (statfs(path,buf))
90  #define STATFS_T statfs  #define STATFS_T statfs
91    #define USE_STATFS
92    #endif
93    
94    #ifdef STAT_STATFS4
95    #define STATFS_FN(path, buf) (statfs(path,buf,sizeof(buf),0))
96    #define STATFS_T statfs
97    #define USE_STATFS
98    #endif
99    
100    #if ((defined(USE_STATFS) && defined(HAVE_STRUCT_STATFS_F_NAMEMAX)) || (defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_NAMEMAX)))
101    #define F_NAMELEN(buf) ((buf).f_namemax)
102    #endif
103    
104    #if ((defined(USE_STATFS) && defined(HAVE_STRUCT_STATFS_F_NAMELEN)) || (defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_NAMELEN)))
105  #define F_NAMELEN(buf) ((buf).f_namelen)  #define F_NAMELEN(buf) ((buf).f_namelen)
106  #endif  #endif
107    
108    #ifndef F_NAMELEN
109    #define F_NAMELEN(buf) (255)
110    #endif
111    
112    /* Dummy statfs fallback */
113    #ifndef STATFS_T
114    struct dummy_statfs_t
115    {
116            long f_bfree = 1;
117            long f_bsize = 512;
118            long f_blocks = 1;
119    };
120    #define STATFS_T dummy_statfs_t
121    #define STATFS_FN(path,buf) 0
122    #endif
123    
124  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
125    
126  FILEINFO g_fileinfo[MAX_OPEN_FILES];  FILEINFO g_fileinfo[MAX_OPEN_FILES];
# Line 260  disk_enum_devices(uint32 * id, char *opt Line 298  disk_enum_devices(uint32 * id, char *opt
298          char *pos2;          char *pos2;
299          int count = 0;          int count = 0;
300    
301          // skip the first colon          /* skip the first colon */
302          optarg++;          optarg++;
303          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
304          {          {
# Line 306  disk_create(uint32 device_id, uint32 acc Line 344  disk_create(uint32 device_id, uint32 acc
344          {          {
345                  case CREATE_ALWAYS:                  case CREATE_ALWAYS:
346    
347                          // Delete existing file/link.                          /* Delete existing file/link. */
348                          unlink(path);                          unlink(path);
349                          flags |= O_CREAT;                          flags |= O_CREAT;
350                          break;                          break;
351    
352                  case CREATE_NEW:                  case CREATE_NEW:
353    
354                          // If the file already exists, then fail.                          /* If the file already exists, then fail. */
355                          flags |= O_CREAT | O_EXCL;                          flags |= O_CREAT | O_EXCL;
356                          break;                          break;
357    
358                  case OPEN_ALWAYS:                  case OPEN_ALWAYS:
359    
360                          // Create if not already exists.                          /* Create if not already exists. */
361                          flags |= O_CREAT;                          flags |= O_CREAT;
362                          break;                          break;
363    
364                  case OPEN_EXISTING:                  case OPEN_EXISTING:
365    
366                          // Default behaviour                          /* Default behaviour */
367                          break;                          break;
368    
369                  case TRUNCATE_EXISTING:                  case TRUNCATE_EXISTING:
370    
371                          // If the file does not exist, then fail.                          /* If the file does not exist, then fail. */
372                          flags |= O_TRUNC;                          flags |= O_TRUNC;
373                          break;                          break;
374          }          }
375    
376          //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); */
377    
378          // Get information about file and set that flag ourselfs          /* Get information about file and set that flag ourselfs */
379          if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode)))          if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode)))
380          {          {
381                  if (flags_and_attributes & FILE_NON_DIRECTORY_FILE)                  if (flags_and_attributes & FILE_NON_DIRECTORY_FILE)
# Line 568  disk_query_information(NTHANDLE handle, Line 606  disk_query_information(NTHANDLE handle,
606    
607          path = g_fileinfo[handle].path;          path = g_fileinfo[handle].path;
608    
609          // Get information about file          /* Get information about file */
610          if (fstat(handle, &filestat) != 0)          if (fstat(handle, &filestat) != 0)
611          {          {
612                  perror("stat");                  perror("stat");
# Line 576  disk_query_information(NTHANDLE handle, Line 614  disk_query_information(NTHANDLE handle,
614                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
615          }          }
616    
617          // Set file attributes          /* Set file attributes */
618          file_attributes = 0;          file_attributes = 0;
619          if (S_ISDIR(filestat.st_mode))          if (S_ISDIR(filestat.st_mode))
620                  file_attributes |= FILE_ATTRIBUTE_DIRECTORY;                  file_attributes |= FILE_ATTRIBUTE_DIRECTORY;
# Line 591  disk_query_information(NTHANDLE handle, Line 629  disk_query_information(NTHANDLE handle,
629          if (!(filestat.st_mode & S_IWUSR))          if (!(filestat.st_mode & S_IWUSR))
630                  file_attributes |= FILE_ATTRIBUTE_READONLY;                  file_attributes |= FILE_ATTRIBUTE_READONLY;
631    
632          // Return requested data          /* Return requested data */
633          switch (info_class)          switch (info_class)
634          {          {
635                  case FileBasicInformation:                  case FileBasicInformation:
636                          seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,                          seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,
637                                                         &ft_low);                                                         &ft_low);
638                          out_uint32_le(out, ft_low);     //create_access_time                          out_uint32_le(out, ft_low);     /* create_access_time */
639                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
640    
641                          seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);
642                          out_uint32_le(out, ft_low);     //last_access_time                          out_uint32_le(out, ft_low);     /* last_access_time */
643                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
644    
645                          seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);
646                          out_uint32_le(out, ft_low);     //last_write_time                          out_uint32_le(out, ft_low);     /* last_write_time */
647                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
648    
649                          seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);
650                          out_uint32_le(out, ft_low);     //last_change_time                          out_uint32_le(out, ft_low);     /* last_change_time */
651                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
652    
653                          out_uint32_le(out, file_attributes);                          out_uint32_le(out, file_attributes);
# Line 617  disk_query_information(NTHANDLE handle, Line 655  disk_query_information(NTHANDLE handle,
655    
656                  case FileStandardInformation:                  case FileStandardInformation:
657    
658                          out_uint32_le(out, filestat.st_size);   //Allocation size                          out_uint32_le(out, filestat.st_size);   /* Allocation size */
659                          out_uint32_le(out, 0);                          out_uint32_le(out, 0);
660                          out_uint32_le(out, filestat.st_size);   //End of file                          out_uint32_le(out, filestat.st_size);   /* End of file */
661                          out_uint32_le(out, 0);                          out_uint32_le(out, 0);
662                          out_uint32_le(out, filestat.st_nlink);  //Number of links                          out_uint32_le(out, filestat.st_nlink);  /* Number of links */
663                          out_uint8(out, 0);      //Delete pending                          out_uint8(out, 0);      /* Delete pending */
664                          out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0);      //Directory                          out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0);      /* Directory */
665                          break;                          break;
666    
667                  case FileObjectIdInformation:                  case FileObjectIdInformation:
# Line 663  disk_set_information(NTHANDLE handle, ui Line 701  disk_set_information(NTHANDLE handle, ui
701                          in_uint8s(in, 4);       /* Handle of root dir? */                          in_uint8s(in, 4);       /* Handle of root dir? */
702                          in_uint8s(in, 24);      /* unknown */                          in_uint8s(in, 24);      /* unknown */
703    
704                          // CreationTime                          /* CreationTime */
705                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
706                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
707    
708                          // AccessTime                          /* AccessTime */
709                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
710                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
711                          if (ft_low || ft_high)                          if (ft_low || ft_high)
712                                  access_time = convert_1970_to_filetime(ft_high, ft_low);                                  access_time = convert_1970_to_filetime(ft_high, ft_low);
713    
714                          // WriteTime                          /* WriteTime */
715                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
716                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
717                          if (ft_low || ft_high)                          if (ft_low || ft_high)
718                                  write_time = convert_1970_to_filetime(ft_high, ft_low);                                  write_time = convert_1970_to_filetime(ft_high, ft_low);
719    
720                          // ChangeTime                          /* ChangeTime */
721                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
722                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
723                          if (ft_low || ft_high)                          if (ft_low || ft_high)
# Line 718  disk_set_information(NTHANDLE handle, ui Line 756  disk_set_information(NTHANDLE handle, ui
756                          }                          }
757    
758                          if (!file_attributes)                          if (!file_attributes)
759                                  break;  // not valid                                  break;  /* not valid */
760    
761                          mode = filestat.st_mode;                          mode = filestat.st_mode;
762    
# Line 835  disk_check_notify(NTHANDLE handle) Line 873  disk_check_notify(NTHANDLE handle)
873    
874          if (memcmp(&pfinfo->notify, &notify, sizeof(NOTIFY)))          if (memcmp(&pfinfo->notify, &notify, sizeof(NOTIFY)))
875          {          {
876                  //printf("disk_check_notify found changed event\n");                  /*printf("disk_check_notify found changed event\n"); */
877                  memcpy(&pfinfo->notify, &notify, sizeof(NOTIFY));                  memcpy(&pfinfo->notify, &notify, sizeof(NOTIFY));
878                  status = STATUS_NOTIFY_ENUM_DIR;                  status = STATUS_NOTIFY_ENUM_DIR;
879          }          }
# Line 925  static FsInfoType * Line 963  static FsInfoType *
963  FsVolumeInfo(char *fpath)  FsVolumeInfo(char *fpath)
964  {  {
965    
         FILE *fdfs;  
966          static FsInfoType info;          static FsInfoType info;
967  #ifdef HAVE_MNTENT_H  #ifdef USE_SETMNTENT
968            FILE *fdfs;
969          struct mntent *e;          struct mntent *e;
970  #endif  #endif
971    
# Line 936  FsVolumeInfo(char *fpath) Line 974  FsVolumeInfo(char *fpath)
974          strcpy(info.label, "RDESKTOP");          strcpy(info.label, "RDESKTOP");
975          strcpy(info.type, "RDPFS");          strcpy(info.type, "RDPFS");
976    
977  #ifdef HAVE_MNTENT_H  #ifdef USE_SETMNTENT
978          fdfs = setmntent(MNTENT_PATH, "r");          fdfs = setmntent(MNTENT_PATH, "r");
979          if (!fdfs)          if (!fdfs)
980                  return &info;                  return &info;
# Line 970  FsVolumeInfo(char *fpath) Line 1008  FsVolumeInfo(char *fpath)
1008                                                  read(fd, buf, sizeof(buf));                                                  read(fd, buf, sizeof(buf));
1009                                                  strncpy(info.label, buf + 41, 32);                                                  strncpy(info.label, buf + 41, 32);
1010                                                  info.label[32] = '\0';                                                  info.label[32] = '\0';
1011                                                  //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]; */
1012                                          }                                          }
1013                                          close(fd);                                          close(fd);
1014                                  }                                  }
# Line 1073  disk_query_directory(NTHANDLE handle, ui Line 1111  disk_query_directory(NTHANDLE handle, ui
1111          {          {
1112                  case FileBothDirectoryInformation:                  case FileBothDirectoryInformation:
1113    
1114                          // If a search pattern is received, remember this pattern, and restart search                          /* If a search pattern is received, remember this pattern, and restart search */
1115                          if (pattern[0] != 0)                          if (pattern[0] != 0)
1116                          {                          {
1117                                  strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), 64);                                  strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), 64);
1118                                  rewinddir(pdir);                                  rewinddir(pdir);
1119                          }                          }
1120    
1121                          // find next dirent matching pattern                          /* find next dirent matching pattern */
1122                          pdirent = readdir(pdir);                          pdirent = readdir(pdir);
1123                          while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0)                          while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0)
1124                                  pdirent = readdir(pdir);                                  pdirent = readdir(pdir);
# Line 1088  disk_query_directory(NTHANDLE handle, ui Line 1126  disk_query_directory(NTHANDLE handle, ui
1126                          if (pdirent == NULL)                          if (pdirent == NULL)
1127                                  return STATUS_NO_MORE_FILES;                                  return STATUS_NO_MORE_FILES;
1128    
1129                          // Get information for directory entry                          /* Get information for directory entry */
1130                          sprintf(fullpath, "%s/%s", dirname, pdirent->d_name);                          sprintf(fullpath, "%s/%s", dirname, pdirent->d_name);
1131    
1132                          if (stat(fullpath, &fstat))                          if (stat(fullpath, &fstat))
# Line 1119  disk_query_directory(NTHANDLE handle, ui Line 1157  disk_query_directory(NTHANDLE handle, ui
1157                          if (!(fstat.st_mode & S_IWUSR))                          if (!(fstat.st_mode & S_IWUSR))
1158                                  file_attributes |= FILE_ATTRIBUTE_READONLY;                                  file_attributes |= FILE_ATTRIBUTE_READONLY;
1159    
1160                          // Return requested information                          /* Return requested information */
1161                          out_uint8s(out, 8);     //unknown zero                          out_uint8s(out, 8);     /* unknown zero */
1162    
1163                          seconds_since_1970_to_filetime(get_create_time(&fstat), &ft_high, &ft_low);                          seconds_since_1970_to_filetime(get_create_time(&fstat), &ft_high, &ft_low);
1164                          out_uint32_le(out, ft_low);     // create time                          out_uint32_le(out, ft_low);     /* create time */
1165                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1166    
1167                          seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low);
1168                          out_uint32_le(out, ft_low);     //last_access_time                          out_uint32_le(out, ft_low);     /* last_access_time */
1169                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1170    
1171                          seconds_since_1970_to_filetime(fstat.st_mtime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(fstat.st_mtime, &ft_high, &ft_low);
1172                          out_uint32_le(out, ft_low);     //last_write_time                          out_uint32_le(out, ft_low);     /* last_write_time */
1173                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1174    
1175                          seconds_since_1970_to_filetime(fstat.st_ctime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(fstat.st_ctime, &ft_high, &ft_low);
1176                          out_uint32_le(out, ft_low);     //change_write_time                          out_uint32_le(out, ft_low);     /* change_write_time */
1177                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1178    
1179                          out_uint32_le(out, fstat.st_size);      //filesize low                          out_uint32_le(out, fstat.st_size);      /* filesize low */
1180                          out_uint32_le(out, 0);  //filesize high                          out_uint32_le(out, 0);  /* filesize high */
1181                          out_uint32_le(out, fstat.st_size);      //filesize low                          out_uint32_le(out, fstat.st_size);      /* filesize low */
1182                          out_uint32_le(out, 0);  //filesize high                          out_uint32_le(out, 0);  /* filesize high */
1183                          out_uint32_le(out, file_attributes);                          out_uint32_le(out, file_attributes);
1184                          out_uint8(out, 2 * strlen(pdirent->d_name) + 2);        //unicode length                          out_uint8(out, 2 * strlen(pdirent->d_name) + 2);        /* unicode length */
1185                          out_uint8s(out, 7);     //pad?                          out_uint8s(out, 7);     /* pad? */
1186                          out_uint8(out, 0);      //8.3 file length                          out_uint8(out, 0);      /* 8.3 file length */
1187                          out_uint8s(out, 2 * 12);        //8.3 unicode length                          out_uint8s(out, 2 * 12);        /* 8.3 unicode length */
1188                          rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));                          rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
1189                          break;                          break;
1190    
# Line 1178  disk_device_control(NTHANDLE handle, uin Line 1216  disk_device_control(NTHANDLE handle, uin
1216    
1217          switch (request)          switch (request)
1218          {          {
1219                  case 25:        // ?                  case 25:        /* ? */
1220                  case 42:        // ?                  case 42:        /* ? */
1221                  default:                  default:
1222                          unimpl("DISK IOCTL %d\n", request);                          unimpl("DISK IOCTL %d\n", request);
1223                          return STATUS_INVALID_PARAMETER;                          return STATUS_INVALID_PARAMETER;

Legend:
Removed from v.827  
changed lines
  Added in v.873

  ViewVC Help
Powered by ViewVC 1.1.26