FileStream.st
changeset 25318 bc5c4223ece2
parent 25300 3acabb810952
child 25357 cec6ca6e3af4
equal deleted inserted replaced
25317:245086b1bfe6 25318:bc5c4223ece2
   757 
   757 
   758 accessRights
   758 accessRights
   759     "return the access rights of the file as opaque data
   759     "return the access rights of the file as opaque data
   760      (SmallInteger in unix/linux)"
   760      (SmallInteger in unix/linux)"
   761 
   761 
   762     ^ OperatingSystem accessModeOfFd:self fileDescriptor.
   762     |fd|
       
   763 
       
   764     "self fileDescriptor sets handle to nil and
       
   765      answers nil, if the handle is no longer valid!!"
       
   766     fd := self fileDescriptor. 
       
   767     fd isNil ifTrue:[
       
   768         self errorNotOpen.
       
   769         ^ nil.
       
   770     ]. 
       
   771     ^ OperatingSystem accessModeOfFd:fd.
   763 
   772 
   764     "
   773     "
   765       'Make.proto' asFilename readingFileDo:[:s|
   774       'Make.proto' asFilename readingFileDo:[:s|
   766 	  s accessRights
   775           s accessRights
   767       ]
   776       ]
   768     "
   777     "
       
   778 
       
   779     "Modified (comment): / 04-03-2020 / 13:11:30 / Stefan Vogel"
   769 !
   780 !
   770 
   781 
   771 accessRights:opaqueData
   782 accessRights:opaqueData
   772     "set the access rights of the file to opaqueData,
   783     "set the access rights of the file to opaqueData,
   773      which is normally retrieved by Filename>>#accessRights
   784      which is normally retrieved by Filename>>#accessRights
   774      or FileStreamm>>#accessRights."
   785      or FileStreamm>>#accessRights."
   775 
   786 
   776     (OperatingSystem changeAccessModeOfFd:self fileHandle to:opaqueData) ifFalse:[
   787     |fd|
   777 	OperatingSystem accessDeniedErrorSignal
   788 
   778 	    raiseRequestWith:self
   789     fd := self fileHandle.
   779 	    errorString:(' - cannot change access rights: ' , self pathName).
   790     fd isNil ifTrue:[
       
   791         self errorNotOpen.
       
   792         ^ self.
       
   793     ].    
       
   794 
       
   795     (OperatingSystem changeAccessModeOfFd:fd to:opaqueData) ifFalse:[
       
   796         OperatingSystem accessDeniedErrorSignal
       
   797             raiseRequestWith:self
       
   798             errorString:(' - cannot change access rights: ' , self pathName).
   780     ].
   799     ].
   781 
   800 
   782     "
   801     "
   783       'Make.proto' asFilename readingFileDo:[:s|
   802       'Make.proto' asFilename readingFileDo:[:s|
   784 	  s accessRights:s accessRights
   803           s accessRights:s accessRights
   785       ]
   804       ]
   786     "
   805     "
   787 
   806 
   788     "
   807     "
   789       '/' asFilename readingFileDo:[:s|
   808       '/' asFilename readingFileDo:[:s|
   790 	  s accessRights:s accessRights
   809           s accessRights:s accessRights
   791       ]
   810       ]
   792     "
   811     "
       
   812 
       
   813     "Modified: / 04-03-2020 / 15:00:22 / Stefan Vogel"
   793 ! !
   814 ! !
   794 
   815 
   795 !FileStream methodsFor:'accessing'!
   816 !FileStream methodsFor:'accessing'!
   796 
   817 
   797 asFilename
   818 asFilename
   917     "read from the receiver, and write numberOfBytes data to another aWriteStream.
   938     "read from the receiver, and write numberOfBytes data to another aWriteStream.
   918      Return the number of bytes which have been transferred.
   939      Return the number of bytes which have been transferred.
   919      If nuberOfBytesOrNil is nil, copy until the end of myself.
   940      If nuberOfBytesOrNil is nil, copy until the end of myself.
   920      Redefined to use operating system features to do a fast copy."
   941      Redefined to use operating system features to do a fast copy."
   921 
   942 
   922     |pos n nWritten|
   943     |pos n nWritten fromFd toFd|
   923 
   944 
   924     outStream isExternalStream ifTrue:[
   945     outStream isExternalStream ifTrue:[
   925         "sendfile() in Linux does not support any combination of file/pipe/socket fds.
   946         fromFd := self fileHandle.
   926          #copyFromFd:toFd:startIndex:count: is currently not available in windows."
   947         fromFd isNil ifTrue:[
       
   948             self errorNotOpen.
       
   949             ^ self.
       
   950         ].    
       
   951         toFd := outStream fileHandle.
       
   952         toFd isNil ifTrue:[
       
   953             outStream errorNotOpen.
       
   954             ^ self.
       
   955         ].    
   927 
   956 
   928         pos := self position.
   957         pos := self position.
   929         numberOfBytesOrNil isNil ifTrue:[
   958         numberOfBytesOrNil isNil ifTrue:[
   930             n := self size - pos.
   959             n := self size - pos.
   931         ] ifFalse:[
   960         ] ifFalse:[
   932             n := numberOfBytesOrNil.
   961             n := numberOfBytesOrNil.
   933         ].
   962         ].
       
   963         
       
   964         "sendfile() in Linux does not support any combination of file/pipe/socket fds.
       
   965          #copyFromFd:toFd:startIndex:count: is currently not available in windows.
       
   966          Both will return 0 and fall through to super."
       
   967 
   934         nWritten := OperatingSystem
   968         nWritten := OperatingSystem
   935                         copyFromFd:self fileHandle
   969                         copyFromFd:fromFd
   936                         toFd:outStream fileHandle
   970                         toFd:toFd
   937                         startIndex:pos
   971                         startIndex:pos
   938                         count:n.
   972                         count:n.
   939         nWritten > 0 ifTrue:[
   973         nWritten > 0 ifTrue:[
   940             self position:pos+nWritten.
   974             self position:pos+nWritten.
   941             ^ n
   975             ^ n
   961      '/tmp/test' asFilename contents.
   995      '/tmp/test' asFilename contents.
   962     "
   996     "
   963 
   997 
   964     "Created: / 13-03-2019 / 16:27:04 / Stefan Vogel"
   998     "Created: / 13-03-2019 / 16:27:04 / Stefan Vogel"
   965     "Modified (format): / 25-05-2019 / 16:47:53 / Claus Gittinger"
   999     "Modified (format): / 25-05-2019 / 16:47:53 / Claus Gittinger"
       
  1000     "Modified (comment): / 04-03-2020 / 15:09:52 / Stefan Vogel"
   966 !
  1001 !
   967 
  1002 
   968 syncFileSystem
  1003 syncFileSystem
   969     "sync the filesystem containing this FileStream"
  1004     "sync the filesystem containing this FileStream"
   970 
  1005