/[rdesktop]/sourceforge.net/trunk/rdesktop/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 /sourceforge.net/trunk/rdesktop/disk.c

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

revision 795 by stargo, Wed Nov 3 13:56:52 2004 UTC revision 875 by stargo, Sat Apr 2 17:49:56 2005 UTC
# Line 37  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
55  #define STATFS_T statvfs  
56  #define F_NAMELEN(buf) ((buf).f_namemax)  #ifdef HAVE_SYS_STATFS_H
57    #include <sys/statfs.h>
58    #endif
59    
60  #elif (defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__))  #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  #else  #ifdef STAT_STATVFS64
83  #include <sys/vfs.h>            /* linux statfs */  #define STATFS_FN(path, buf) (statvfs64(path,buf))
84  #include <mntent.h>  #define STATFS_T statvfs64
85  #define HAVE_MNTENT_H  #define USE_STATVFS
86  #define MNTENT_PATH "/etc/mtab"  #endif
87    
88    #if (defined(STAT_STATFS2_FS_DATA) || defined(STAT_STATFS2_BSIZE) || defined(STAT_STATFS2_FSIZE))
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  #include "rdesktop.h"  #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;
117            long f_bsize;
118            long f_blocks;
119            int f_namelen;
120            int f_namemax;
121    };
122    
123    int dummy_statfs(struct dummy_statfs_t *buf)
124    {
125            buf->f_blocks=262144;
126            buf->f_bfree=131072;
127            buf->f_bsize=512;
128            buf->f_namelen=255;
129            buf->f_namemax=255;
130    
131            return 0;
132    }
133    
134    #define STATFS_T dummy_statfs_t
135    #define STATFS_FN(path,buf) (dummy_statfs(buf))
136    #endif
137    
138  extern RDPDR_DEVICE g_rdpdr_device[];  extern RDPDR_DEVICE g_rdpdr_device[];
139    
# Line 255  disk_enum_devices(uint32 * id, char *opt Line 312  disk_enum_devices(uint32 * id, char *opt
312          char *pos2;          char *pos2;
313          int count = 0;          int count = 0;
314    
315          // skip the first colon          /* skip the first colon */
316          optarg++;          optarg++;
317          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)          while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
318          {          {
319                  pos2 = next_arg(optarg, '=');                  pos2 = next_arg(optarg, '=');
320    
321                  strncpy(g_rdpdr_device[*id].name, optarg, sizeof(g_rdpdr_device[*id].name));                  strncpy(g_rdpdr_device[*id].name, optarg, sizeof(g_rdpdr_device[*id].name) - 1);
322                  if (strlen(optarg) > 8)                  if (strlen(optarg) > (sizeof(g_rdpdr_device[*id].name) - 1))
323                          fprintf(stderr, "share name %s truncated to %s\n", optarg,                          fprintf(stderr, "share name %s truncated to %s\n", optarg,
324                                  g_rdpdr_device[*id].name);                                  g_rdpdr_device[*id].name);
325    
# Line 301  disk_create(uint32 device_id, uint32 acc Line 358  disk_create(uint32 device_id, uint32 acc
358          {          {
359                  case CREATE_ALWAYS:                  case CREATE_ALWAYS:
360    
361                          // Delete existing file/link.                          /* Delete existing file/link. */
362                          unlink(path);                          unlink(path);
363                          flags |= O_CREAT;                          flags |= O_CREAT;
364                          break;                          break;
365    
366                  case CREATE_NEW:                  case CREATE_NEW:
367    
368                          // If the file already exists, then fail.                          /* If the file already exists, then fail. */
369                          flags |= O_CREAT | O_EXCL;                          flags |= O_CREAT | O_EXCL;
370                          break;                          break;
371    
372                  case OPEN_ALWAYS:                  case OPEN_ALWAYS:
373    
374                          // Create if not already exists.                          /* Create if not already exists. */
375                          flags |= O_CREAT;                          flags |= O_CREAT;
376                          break;                          break;
377    
378                  case OPEN_EXISTING:                  case OPEN_EXISTING:
379    
380                          // Default behaviour                          /* Default behaviour */
381                          break;                          break;
382    
383                  case TRUNCATE_EXISTING:                  case TRUNCATE_EXISTING:
384    
385                          // If the file does not exist, then fail.                          /* If the file does not exist, then fail. */
386                          flags |= O_TRUNC;                          flags |= O_TRUNC;
387                          break;                          break;
388          }          }
389    
390          //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); */
391    
392          // Get information about file and set that flag ourselfs          /* Get information about file and set that flag ourselfs */
393          if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode)))          if ((stat(path, &filestat) == 0) && (S_ISDIR(filestat.st_mode)))
394          {          {
395                  if (flags_and_attributes & FILE_NON_DIRECTORY_FILE)                  if (flags_and_attributes & FILE_NON_DIRECTORY_FILE)
# Line 563  disk_query_information(NTHANDLE handle, Line 620  disk_query_information(NTHANDLE handle,
620    
621          path = g_fileinfo[handle].path;          path = g_fileinfo[handle].path;
622    
623          // Get information about file          /* Get information about file */
624          if (fstat(handle, &filestat) != 0)          if (fstat(handle, &filestat) != 0)
625          {          {
626                  perror("stat");                  perror("stat");
# Line 571  disk_query_information(NTHANDLE handle, Line 628  disk_query_information(NTHANDLE handle,
628                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
629          }          }
630    
631          // Set file attributes          /* Set file attributes */
632          file_attributes = 0;          file_attributes = 0;
633          if (S_ISDIR(filestat.st_mode))          if (S_ISDIR(filestat.st_mode))
634                  file_attributes |= FILE_ATTRIBUTE_DIRECTORY;                  file_attributes |= FILE_ATTRIBUTE_DIRECTORY;
# Line 586  disk_query_information(NTHANDLE handle, Line 643  disk_query_information(NTHANDLE handle,
643          if (!(filestat.st_mode & S_IWUSR))          if (!(filestat.st_mode & S_IWUSR))
644                  file_attributes |= FILE_ATTRIBUTE_READONLY;                  file_attributes |= FILE_ATTRIBUTE_READONLY;
645    
646          // Return requested data          /* Return requested data */
647          switch (info_class)          switch (info_class)
648          {          {
649                  case FileBasicInformation:                  case FileBasicInformation:
650                          seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,                          seconds_since_1970_to_filetime(get_create_time(&filestat), &ft_high,
651                                                         &ft_low);                                                         &ft_low);
652                          out_uint32_le(out, ft_low);     //create_access_time                          out_uint32_le(out, ft_low);     /* create_access_time */
653                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
654    
655                          seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(filestat.st_atime, &ft_high, &ft_low);
656                          out_uint32_le(out, ft_low);     //last_access_time                          out_uint32_le(out, ft_low);     /* last_access_time */
657                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
658    
659                          seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(filestat.st_mtime, &ft_high, &ft_low);
660                          out_uint32_le(out, ft_low);     //last_write_time                          out_uint32_le(out, ft_low);     /* last_write_time */
661                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
662    
663                          seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(filestat.st_ctime, &ft_high, &ft_low);
664                          out_uint32_le(out, ft_low);     //last_change_time                          out_uint32_le(out, ft_low);     /* last_change_time */
665                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
666    
667                          out_uint32_le(out, file_attributes);                          out_uint32_le(out, file_attributes);
# Line 612  disk_query_information(NTHANDLE handle, Line 669  disk_query_information(NTHANDLE handle,
669    
670                  case FileStandardInformation:                  case FileStandardInformation:
671    
672                          out_uint32_le(out, filestat.st_size);   //Allocation size                          out_uint32_le(out, filestat.st_size);   /* Allocation size */
673                          out_uint32_le(out, 0);                          out_uint32_le(out, 0);
674                          out_uint32_le(out, filestat.st_size);   //End of file                          out_uint32_le(out, filestat.st_size);   /* End of file */
675                          out_uint32_le(out, 0);                          out_uint32_le(out, 0);
676                          out_uint32_le(out, filestat.st_nlink);  //Number of links                          out_uint32_le(out, filestat.st_nlink);  /* Number of links */
677                          out_uint8(out, 0);      //Delete pending                          out_uint8(out, 0);      /* Delete pending */
678                          out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0);      //Directory                          out_uint8(out, S_ISDIR(filestat.st_mode) ? 1 : 0);      /* Directory */
679                          break;                          break;
680    
681                  case FileObjectIdInformation:                  case FileObjectIdInformation:
# Line 658  disk_set_information(NTHANDLE handle, ui Line 715  disk_set_information(NTHANDLE handle, ui
715                          in_uint8s(in, 4);       /* Handle of root dir? */                          in_uint8s(in, 4);       /* Handle of root dir? */
716                          in_uint8s(in, 24);      /* unknown */                          in_uint8s(in, 24);      /* unknown */
717    
718                          // CreationTime                          /* CreationTime */
719                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
720                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
721    
722                          // AccessTime                          /* AccessTime */
723                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
724                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
725                          if (ft_low || ft_high)                          if (ft_low || ft_high)
726                                  access_time = convert_1970_to_filetime(ft_high, ft_low);                                  access_time = convert_1970_to_filetime(ft_high, ft_low);
727    
728                          // WriteTime                          /* WriteTime */
729                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
730                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
731                          if (ft_low || ft_high)                          if (ft_low || ft_high)
732                                  write_time = convert_1970_to_filetime(ft_high, ft_low);                                  write_time = convert_1970_to_filetime(ft_high, ft_low);
733    
734                          // ChangeTime                          /* ChangeTime */
735                          in_uint32_le(in, ft_low);                          in_uint32_le(in, ft_low);
736                          in_uint32_le(in, ft_high);                          in_uint32_le(in, ft_high);
737                          if (ft_low || ft_high)                          if (ft_low || ft_high)
# Line 713  disk_set_information(NTHANDLE handle, ui Line 770  disk_set_information(NTHANDLE handle, ui
770                          }                          }
771    
772                          if (!file_attributes)                          if (!file_attributes)
773                                  break;  // not valid                                  break;  /* not valid */
774    
775                          mode = filestat.st_mode;                          mode = filestat.st_mode;
776    
# Line 830  disk_check_notify(NTHANDLE handle) Line 887  disk_check_notify(NTHANDLE handle)
887    
888          if (memcmp(&pfinfo->notify, &notify, sizeof(NOTIFY)))          if (memcmp(&pfinfo->notify, &notify, sizeof(NOTIFY)))
889          {          {
890                  //printf("disk_check_notify found changed event\n");                  /*printf("disk_check_notify found changed event\n"); */
891                  memcpy(&pfinfo->notify, &notify, sizeof(NOTIFY));                  memcpy(&pfinfo->notify, &notify, sizeof(NOTIFY));
892                  status = STATUS_NOTIFY_ENUM_DIR;                  status = STATUS_NOTIFY_ENUM_DIR;
893          }          }
# Line 920  static FsInfoType * Line 977  static FsInfoType *
977  FsVolumeInfo(char *fpath)  FsVolumeInfo(char *fpath)
978  {  {
979    
         FILE *fdfs;  
980          static FsInfoType info;          static FsInfoType info;
981  #ifdef HAVE_MNTENT_H  #ifdef USE_SETMNTENT
982            FILE *fdfs;
983          struct mntent *e;          struct mntent *e;
984  #endif  #endif
985    
# Line 931  FsVolumeInfo(char *fpath) Line 988  FsVolumeInfo(char *fpath)
988          strcpy(info.label, "RDESKTOP");          strcpy(info.label, "RDESKTOP");
989          strcpy(info.type, "RDPFS");          strcpy(info.type, "RDPFS");
990    
991  #ifdef HAVE_MNTENT_H  #ifdef USE_SETMNTENT
992          fdfs = setmntent(MNTENT_PATH, "r");          fdfs = setmntent(MNTENT_PATH, "r");
993          if (!fdfs)          if (!fdfs)
994                  return &info;                  return &info;
# Line 965  FsVolumeInfo(char *fpath) Line 1022  FsVolumeInfo(char *fpath)
1022                                                  read(fd, buf, sizeof(buf));                                                  read(fd, buf, sizeof(buf));
1023                                                  strncpy(info.label, buf + 41, 32);                                                  strncpy(info.label, buf + 41, 32);
1024                                                  info.label[32] = '\0';                                                  info.label[32] = '\0';
1025                                                  //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]; */
1026                                          }                                          }
1027                                          close(fd);                                          close(fd);
1028                                  }                                  }
# Line 1068  disk_query_directory(NTHANDLE handle, ui Line 1125  disk_query_directory(NTHANDLE handle, ui
1125          {          {
1126                  case FileBothDirectoryInformation:                  case FileBothDirectoryInformation:
1127    
1128                          // If a search pattern is received, remember this pattern, and restart search                          /* If a search pattern is received, remember this pattern, and restart search */
1129                          if (pattern[0] != 0)                          if (pattern[0] != 0)
1130                          {                          {
1131                                  strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), 64);                                  strncpy(pfinfo->pattern, 1 + strrchr(pattern, '/'), 64);
1132                                  rewinddir(pdir);                                  rewinddir(pdir);
1133                          }                          }
1134    
1135                          // find next dirent matching pattern                          /* find next dirent matching pattern */
1136                          pdirent = readdir(pdir);                          pdirent = readdir(pdir);
1137                          while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0)                          while (pdirent && fnmatch(pfinfo->pattern, pdirent->d_name, 0) != 0)
1138                                  pdirent = readdir(pdir);                                  pdirent = readdir(pdir);
# Line 1083  disk_query_directory(NTHANDLE handle, ui Line 1140  disk_query_directory(NTHANDLE handle, ui
1140                          if (pdirent == NULL)                          if (pdirent == NULL)
1141                                  return STATUS_NO_MORE_FILES;                                  return STATUS_NO_MORE_FILES;
1142    
1143                          // Get information for directory entry                          /* Get information for directory entry */
1144                          sprintf(fullpath, "%s/%s", dirname, pdirent->d_name);                          sprintf(fullpath, "%s/%s", dirname, pdirent->d_name);
1145    
1146                          if (stat(fullpath, &fstat))                          if (stat(fullpath, &fstat))
# Line 1114  disk_query_directory(NTHANDLE handle, ui Line 1171  disk_query_directory(NTHANDLE handle, ui
1171                          if (!(fstat.st_mode & S_IWUSR))                          if (!(fstat.st_mode & S_IWUSR))
1172                                  file_attributes |= FILE_ATTRIBUTE_READONLY;                                  file_attributes |= FILE_ATTRIBUTE_READONLY;
1173    
1174                          // Return requested information                          /* Return requested information */
1175                          out_uint8s(out, 8);     //unknown zero                          out_uint8s(out, 8);     /* unknown zero */
1176    
1177                          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);
1178                          out_uint32_le(out, ft_low);     // create time                          out_uint32_le(out, ft_low);     /* create time */
1179                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1180    
1181                          seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(fstat.st_atime, &ft_high, &ft_low);
1182                          out_uint32_le(out, ft_low);     //last_access_time                          out_uint32_le(out, ft_low);     /* last_access_time */
1183                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1184    
1185                          seconds_since_1970_to_filetime(fstat.st_mtime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(fstat.st_mtime, &ft_high, &ft_low);
1186                          out_uint32_le(out, ft_low);     //last_write_time                          out_uint32_le(out, ft_low);     /* last_write_time */
1187                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1188    
1189                          seconds_since_1970_to_filetime(fstat.st_ctime, &ft_high, &ft_low);                          seconds_since_1970_to_filetime(fstat.st_ctime, &ft_high, &ft_low);
1190                          out_uint32_le(out, ft_low);     //change_write_time                          out_uint32_le(out, ft_low);     /* change_write_time */
1191                          out_uint32_le(out, ft_high);                          out_uint32_le(out, ft_high);
1192    
1193                          out_uint32_le(out, fstat.st_size);      //filesize low                          out_uint32_le(out, fstat.st_size);      /* filesize low */
1194                          out_uint32_le(out, 0);  //filesize high                          out_uint32_le(out, 0);  /* filesize high */
1195                          out_uint32_le(out, fstat.st_size);      //filesize low                          out_uint32_le(out, fstat.st_size);      /* filesize low */
1196                          out_uint32_le(out, 0);  //filesize high                          out_uint32_le(out, 0);  /* filesize high */
1197                          out_uint32_le(out, file_attributes);                          out_uint32_le(out, file_attributes);
1198                          out_uint8(out, 2 * strlen(pdirent->d_name) + 2);        //unicode length                          out_uint8(out, 2 * strlen(pdirent->d_name) + 2);        /* unicode length */
1199                          out_uint8s(out, 7);     //pad?                          out_uint8s(out, 7);     /* pad? */
1200                          out_uint8(out, 0);      //8.3 file length                          out_uint8(out, 0);      /* 8.3 file length */
1201                          out_uint8s(out, 2 * 12);        //8.3 unicode length                          out_uint8s(out, 2 * 12);        /* 8.3 unicode length */
1202                          rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));                          rdp_out_unistr(out, pdirent->d_name, 2 * strlen(pdirent->d_name));
1203                          break;                          break;
1204    
# Line 1173  disk_device_control(NTHANDLE handle, uin Line 1230  disk_device_control(NTHANDLE handle, uin
1230    
1231          switch (request)          switch (request)
1232          {          {
1233                  case 25:        // ?                  case 25:        /* ? */
1234                  case 42:        // ?                  case 42:        /* ? */
1235                  default:                  default:
1236                          unimpl("DISK IOCTL %d\n", request);                          unimpl("DISK IOCTL %d\n", request);
1237                          return STATUS_INVALID_PARAMETER;                          return STATUS_INVALID_PARAMETER;

Legend:
Removed from v.795  
changed lines
  Added in v.875

  ViewVC Help
Powered by ViewVC 1.1.26