/[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 600 by n-ki, Fri Feb 6 10:41:34 2004 UTC revision 618 by stargo, Sat Feb 28 10:52:29 2004 UTC
# Line 84  Line 84 
84  #define SOLARIS  #define SOLARIS
85  #endif  #endif
86    
87  #ifdef SOLARIS  #if (defined(SOLARIS) || defined(__hpux))
88  #define DIRFD(a) ((a)->dd_fd)  #define DIRFD(a) ((a)->dd_fd)
89  #else  #else
90  #define DIRFD(a) (dirfd(a))  #define DIRFD(a) (dirfd(a))
# Line 102  Line 102 
102  #include <time.h>               /* ctime */  #include <time.h>               /* ctime */
103    
104    
105  #if defined(SOLARIS)  #if (defined(SOLARIS) || defined (__hpux) || defined(__BEOS__))
106  #include <sys/statvfs.h>        /* solaris statvfs */  #include <sys/statvfs.h>        /* solaris statvfs */
107    #include <sys/mntent.h>
108    /* TODO: Fix mntent-handling for solaris */
109    #undef HAVE_MNTENT_H
110    #define MNTENT_PATH "/etc/mnttab"
111  #define STATFS_FN(path, buf) (statvfs(path,buf))  #define STATFS_FN(path, buf) (statvfs(path,buf))
112  #define STATFS_T statvfs  #define STATFS_T statvfs
113  #define F_NAMELEN(buf) ((buf).f_namemax)  #define F_NAMELEN(buf) ((buf).f_namemax)
# Line 117  Line 121 
121    
122  #else  #else
123  #include <sys/vfs.h>            /* linux statfs */  #include <sys/vfs.h>            /* linux statfs */
124    #include <mntent.h>
125    #define HAVE_MNTENT_H
126    #define MNTENT_PATH "/etc/mtab"
127  #define STATFS_FN(path, buf) (statfs(path,buf))  #define STATFS_FN(path, buf) (statfs(path,buf))
128  #define STATFS_T statfs  #define STATFS_T statfs
129  #define F_NAMELEN(buf) ((buf).f_namelen)  #define F_NAMELEN(buf) ((buf).f_namelen)
# Line 137  struct fileinfo Line 144  struct fileinfo
144  }  }
145  g_fileinfo[MAX_OPEN_FILES];  g_fileinfo[MAX_OPEN_FILES];
146    
147    typedef struct
148    {
149            char name[256];
150            char label[256];
151            unsigned long serial;
152            char type[256];
153    } FsInfoType;
154    
155    
156  time_t  time_t
157  get_create_time(struct stat *st)  get_create_time(struct stat *st)
# Line 182  convert_1970_to_filetime(uint32 high, ui Line 197  convert_1970_to_filetime(uint32 high, ui
197    
198  /* Enumeration of devices from rdesktop.c        */  /* Enumeration of devices from rdesktop.c        */
199  /* returns numer of units found and initialized. */  /* returns numer of units found and initialized. */
200  /* optarg looks like ':h:=/mnt/floppy,b:=/mnt/usbdevice1' */  /* optarg looks like ':h=/mnt/floppy,b=/mnt/usbdevice1' */
201  /* when it arrives to this function.             */  /* when it arrives to this function.             */
202  int  int
203  disk_enum_devices(int *id, char *optarg)  disk_enum_devices(uint32 * id, char *optarg)
204  {  {
205          char *pos = optarg;          char *pos = optarg;
206          char *pos2;          char *pos2;
# Line 341  disk_create(uint32 device_id, uint32 acc Line 356  disk_create(uint32 device_id, uint32 acc
356                                  case ENOENT:                                  case ENOENT:
357    
358                                          return STATUS_NO_SUCH_FILE;                                          return STATUS_NO_SUCH_FILE;
359                                    case EEXIST:
360    
361                                            return STATUS_OBJECT_NAME_COLLISION;
362                                  default:                                  default:
363    
364                                          perror("open");                                          perror("open");
# Line 405  disk_read(HANDLE handle, uint8 * data, u Line 423  disk_read(HANDLE handle, uint8 * data, u
423          }          }
424  #endif  #endif
425    
426          if (offset)          lseek(handle, offset, SEEK_SET);
427                  lseek(handle, offset, SEEK_SET);  
428          n = read(handle, data, length);          n = read(handle, data, length);
429    
430          if (n < 0)          if (n < 0)
# Line 432  disk_write(HANDLE handle, uint8 * data, Line 450  disk_write(HANDLE handle, uint8 * data,
450  {  {
451          int n;          int n;
452    
453          if (offset)          lseek(handle, offset, SEEK_SET);
                 lseek(handle, offset, SEEK_SET);  
454    
455          n = write(handle, data, length);          n = write(handle, data, length);
456    
# Line 547  disk_set_information(HANDLE handle, uint Line 564  disk_set_information(HANDLE handle, uint
564          struct stat filestat;          struct stat filestat;
565          time_t write_time, change_time, access_time, mod_time;          time_t write_time, change_time, access_time, mod_time;
566          struct utimbuf tvs;          struct utimbuf tvs;
567            struct STATFS_T stat_fs;
568    
569          pfinfo = &(g_fileinfo[handle]);          pfinfo = &(g_fileinfo[handle]);
570    
# Line 629  disk_set_information(HANDLE handle, uint Line 647  disk_set_information(HANDLE handle, uint
647    
648                          if (fchmod(handle, mode))                          if (fchmod(handle, mode))
649                                  return STATUS_ACCESS_DENIED;                                  return STATUS_ACCESS_DENIED;
650    
651                          break;                          break;
652    
653                  case 10:        /* FileRenameInformation */                  case 10:        /* FileRenameInformation */
# Line 660  disk_set_information(HANDLE handle, uint Line 679  disk_set_information(HANDLE handle, uint
679                  case 13:        /* FileDispositionInformation */                  case 13:        /* FileDispositionInformation */
680    
681                          //unimpl("IRP Set File Information class: FileDispositionInformation\n");                          //unimpl("IRP Set File Information class: FileDispositionInformation\n");
682                          // in_uint32_le(in, delete_on_close);  
683                            //in_uint32_le(in, delete_on_close);
684                          // disk_close(handle);                          // disk_close(handle);
685                          unlink(pfinfo->path);                          if ((pfinfo->flags_and_attributes & FILE_DIRECTORY_FILE))       // remove a directory
686                            {
687                                    if (rmdir(pfinfo->path) < 0)
688                                            return STATUS_ACCESS_DENIED;
689                            }
690                            else if (unlink(pfinfo->path) < 0)      // unlink a file
691                                    return STATUS_ACCESS_DENIED;
692    
693                          break;                          break;
694    
695                  case 19:        /* FileAllocationInformation */                  case 19:        /* FileAllocationInformation */
# Line 674  disk_set_information(HANDLE handle, uint Line 701  disk_set_information(HANDLE handle, uint
701                          in_uint8s(in, 28);      /* unknown */                          in_uint8s(in, 28);      /* unknown */
702                          in_uint32_le(in, length);       /* file size */                          in_uint32_le(in, length);       /* file size */
703    
704                          printf("FileEndOfFileInformation length = %d\n", length);                          /* prevents start of writing if not enough space left on device */
705                          // ????????????                          if (STATFS_FN(g_rdpdr_device[pfinfo->device_id].local_path, &stat_fs) == 0)
706                                    if (stat_fs.f_bsize * stat_fs.f_bfree < length)
707                                            return STATUS_DISK_FULL;
708    
709                          unimpl("IRP Set File Information class: FileEndOfFileInformation\n");                          //printf("FileEndOfFileInformation length = %d\n", length);
710                            // ????????????
711                            //unimpl("IRP Set File Information class: FileEndOfFileInformation\n");
712                          break;                          break;
713                  default:                  default:
714    
# Line 687  disk_set_information(HANDLE handle, uint Line 718  disk_set_information(HANDLE handle, uint
718          return STATUS_SUCCESS;          return STATUS_SUCCESS;
719  }  }
720    
721    FsInfoType *
722    FsVolumeInfo(char *fpath)
723    {
724    
725    #ifdef HAVE_MNTENT_H
726            FILE *fdfs;
727            struct mntent *e;
728            static FsInfoType info;
729    
730            /* initialize */
731            memset(&info, 0, sizeof(info));
732            strcpy(info.label, "RDESKTOP");
733            strcpy(info.type, "RDPFS");
734    
735            fdfs = setmntent(MNTENT_PATH, "r");
736            if (!fdfs)
737                    return &info;
738    
739            while ((e = getmntent(fdfs)))
740            {
741                    if (strncmp(fpath, e->mnt_dir, strlen(fpath)) == 0)
742                    {
743                            strcpy(info.type, e->mnt_type);
744                            strcpy(info.name, e->mnt_fsname);
745                            if (strstr(e->mnt_opts, "vfat") || strstr(e->mnt_opts, "iso9660"))
746                            {
747                                    int fd = open(e->mnt_fsname, O_RDONLY);
748                                    if (fd >= 0)
749                                    {
750                                            unsigned char buf[512];
751                                            memset(buf, 0, sizeof(buf));
752                                            if (strstr(e->mnt_opts, "vfat"))
753                                                     /*FAT*/
754                                            {
755                                                    strcpy(info.type, "vfat");
756                                                    read(fd, buf, sizeof(buf));
757                                                    info.serial =
758                                                            (buf[42] << 24) + (buf[41] << 16) +
759                                                            (buf[40] << 8) + buf[39];
760                                                    strncpy(info.label, buf + 43, 10);
761                                                    info.label[10] = '\0';
762                                            }
763                                            else if (lseek(fd, 32767, SEEK_SET) >= 0)       /* ISO9660 */
764                                            {
765                                                    read(fd, buf, sizeof(buf));
766                                                    strncpy(info.label, buf + 41, 32);
767                                                    info.label[32] = '\0';
768                                                    //info.Serial = (buf[128]<<24)+(buf[127]<<16)+(buf[126]<<8)+buf[125];
769                                            }
770                                            close(fd);
771                                    }
772                            }
773                    }
774            }
775            endmntent(fdfs);
776    #else
777            static FsInfoType info;
778    
779            /* initialize */
780            memset(&info, 0, sizeof(info));
781            strcpy(info.label, "RDESKTOP");
782            strcpy(info.type, "RDPFS");
783    
784    #endif
785            return &info;
786    }
787    
788    
789  NTSTATUS  NTSTATUS
790  disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out)  disk_query_volume_information(HANDLE handle, uint32 info_class, STREAM out)
791  {  {
         char *volume, *fs_type;  
792          struct STATFS_T stat_fs;          struct STATFS_T stat_fs;
793          struct fileinfo *pfinfo;          struct fileinfo *pfinfo;
794            FsInfoType *fsinfo;
795    
796          pfinfo = &(g_fileinfo[handle]);          pfinfo = &(g_fileinfo[handle]);
         volume = "RDESKTOP";  
         fs_type = "RDPFS";  
797    
798          if (STATFS_FN(pfinfo->path, &stat_fs) != 0)          if (STATFS_FN(pfinfo->path, &stat_fs) != 0)
799          {          {
# Line 704  disk_query_volume_information(HANDLE han Line 801  disk_query_volume_information(HANDLE han
801                  return STATUS_ACCESS_DENIED;                  return STATUS_ACCESS_DENIED;
802          }          }
803    
804            fsinfo = FsVolumeInfo(pfinfo->path);
805    
806          switch (info_class)          switch (info_class)
807          {          {
808                  case 1: /* FileFsVolumeInformation */                  case 1: /* FileFsVolumeInformation */
809    
810                          out_uint32_le(out, 0);  /* volume creation time low */                          out_uint32_le(out, 0);  /* volume creation time low */
811                          out_uint32_le(out, 0);  /* volume creation time high */                          out_uint32_le(out, 0);  /* volume creation time high */
812                          out_uint32_le(out, 0);  /* serial */                          out_uint32_le(out, fsinfo->serial);     /* serial */
813                          out_uint32_le(out, 2 * strlen(volume)); /* length of string */  
814                            out_uint32_le(out, 2 * strlen(fsinfo->label));  /* length of string */
815    
816                          out_uint8(out, 0);      /* support objects? */                          out_uint8(out, 0);      /* support objects? */
817                          rdp_out_unistr(out, volume, 2 * strlen(volume) - 2);                          rdp_out_unistr(out, fsinfo->label, 2 * strlen(fsinfo->label) - 2);
818                          break;                          break;
819    
820                  case 3: /* FileFsSizeInformation */                  case 3: /* FileFsSizeInformation */
# Line 730  disk_query_volume_information(HANDLE han Line 831  disk_query_volume_information(HANDLE han
831    
832                          out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED);   /* fs attributes */                          out_uint32_le(out, FS_CASE_SENSITIVE | FS_CASE_IS_PRESERVED);   /* fs attributes */
833                          out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */                          out_uint32_le(out, F_NAMELEN(stat_fs)); /* max length of filename */
834                          out_uint32_le(out, 2 * strlen(fs_type));        /* length of fs_type */  
835                          rdp_out_unistr(out, fs_type, 2 * strlen(fs_type) - 2);                          out_uint32_le(out, 2 * strlen(fsinfo->type));   /* length of fs_type */
836                            rdp_out_unistr(out, fsinfo->type, 2 * strlen(fsinfo->type) - 2);
837                          break;                          break;
838    
839                  case 2: /* FileFsLabelInformation */                  case 2: /* FileFsLabelInformation */

Legend:
Removed from v.600  
changed lines
  Added in v.618

  ViewVC Help
Powered by ViewVC 1.1.26