diff options
Diffstat (limited to 'CPP/Windows/FileIO.cpp')
| -rw-r--r-- | CPP/Windows/FileIO.cpp | 88 |
1 files changed, 84 insertions, 4 deletions
diff --git a/CPP/Windows/FileIO.cpp b/CPP/Windows/FileIO.cpp index 2974b1b..e51b0eb 100644 --- a/CPP/Windows/FileIO.cpp +++ b/CPP/Windows/FileIO.cpp | |||
| @@ -8,6 +8,14 @@ | |||
| 8 | 8 | ||
| 9 | // #include <stdio.h> | 9 | // #include <stdio.h> |
| 10 | 10 | ||
| 11 | /* | ||
| 12 | #ifndef _WIN32 | ||
| 13 | // for ioctl BLKGETSIZE64 | ||
| 14 | #include <sys/ioctl.h> | ||
| 15 | #include <linux/fs.h> | ||
| 16 | #endif | ||
| 17 | */ | ||
| 18 | |||
| 11 | #include "FileIO.h" | 19 | #include "FileIO.h" |
| 12 | #include "FileName.h" | 20 | #include "FileName.h" |
| 13 | 21 | ||
| @@ -615,7 +623,7 @@ namespace NWindows { | |||
| 615 | namespace NFile { | 623 | namespace NFile { |
| 616 | 624 | ||
| 617 | namespace NDir { | 625 | namespace NDir { |
| 618 | bool SetDirTime(CFSTR path, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime); | 626 | bool SetDirTime(CFSTR path, const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime); |
| 619 | } | 627 | } |
| 620 | 628 | ||
| 621 | namespace NIO { | 629 | namespace NIO { |
| @@ -629,6 +637,19 @@ bool CFileBase::OpenBinary(const char *name, int flags) | |||
| 629 | Close(); | 637 | Close(); |
| 630 | _handle = ::open(name, flags, 0666); | 638 | _handle = ::open(name, flags, 0666); |
| 631 | return _handle != -1; | 639 | return _handle != -1; |
| 640 | |||
| 641 | /* | ||
| 642 | if (_handle == -1) | ||
| 643 | return false; | ||
| 644 | if (IsString1PrefixedByString2(name, "/dev/")) | ||
| 645 | { | ||
| 646 | // /dev/sda | ||
| 647 | // IsDeviceFile = true; // for debug | ||
| 648 | // SizeDefined = false; | ||
| 649 | // SizeDefined = (GetDeviceSize_InBytes(Size) == 0); | ||
| 650 | } | ||
| 651 | return true; | ||
| 652 | */ | ||
| 632 | } | 653 | } |
| 633 | 654 | ||
| 634 | bool CFileBase::Close() | 655 | bool CFileBase::Close() |
| @@ -638,6 +659,10 @@ bool CFileBase::Close() | |||
| 638 | if (close(_handle) != 0) | 659 | if (close(_handle) != 0) |
| 639 | return false; | 660 | return false; |
| 640 | _handle = -1; | 661 | _handle = -1; |
| 662 | /* | ||
| 663 | IsDeviceFile = false; | ||
| 664 | SizeDefined = false; | ||
| 665 | */ | ||
| 641 | return true; | 666 | return true; |
| 642 | } | 667 | } |
| 643 | 668 | ||
| @@ -651,15 +676,35 @@ bool CFileBase::GetLength(UInt64 &length) const | |||
| 651 | const off_t lengthTemp = seek(0, SEEK_END); | 676 | const off_t lengthTemp = seek(0, SEEK_END); |
| 652 | seek(curPos, SEEK_SET); | 677 | seek(curPos, SEEK_SET); |
| 653 | length = (UInt64)lengthTemp; | 678 | length = (UInt64)lengthTemp; |
| 679 | |||
| 680 | /* | ||
| 681 | // 22.00: | ||
| 682 | if (lengthTemp == 1) | ||
| 683 | if (IsDeviceFile && SizeDefined) | ||
| 684 | { | ||
| 685 | length = Size; | ||
| 686 | return true; | ||
| 687 | } | ||
| 688 | */ | ||
| 689 | |||
| 654 | return (lengthTemp != -1); | 690 | return (lengthTemp != -1); |
| 655 | } | 691 | } |
| 656 | 692 | ||
| 657 | off_t CFileBase::seek(off_t distanceToMove, int moveMethod) const | 693 | off_t CFileBase::seek(off_t distanceToMove, int moveMethod) const |
| 658 | { | 694 | { |
| 695 | /* | ||
| 696 | if (IsDeviceFile && SizeDefined && moveMethod == SEEK_END) | ||
| 697 | { | ||
| 698 | printf("\n seek : IsDeviceFile moveMethod = %d distanceToMove = %ld\n", moveMethod, distanceToMove); | ||
| 699 | distanceToMove += Size; | ||
| 700 | moveMethod = SEEK_SET; | ||
| 701 | } | ||
| 702 | */ | ||
| 703 | |||
| 659 | // printf("\nCFileBase::seek() moveMethod = %d, distanceToMove = %lld", moveMethod, (long long)distanceToMove); | 704 | // printf("\nCFileBase::seek() moveMethod = %d, distanceToMove = %lld", moveMethod, (long long)distanceToMove); |
| 660 | // off_t res = ::lseek(_handle, distanceToMove, moveMethod); | 705 | // off_t res = ::lseek(_handle, distanceToMove, moveMethod); |
| 706 | // printf("\n lseek : moveMethod = %d distanceToMove = %ld\n", moveMethod, distanceToMove); | ||
| 661 | return ::lseek(_handle, distanceToMove, moveMethod); | 707 | return ::lseek(_handle, distanceToMove, moveMethod); |
| 662 | // printf(" res = %lld", (long long)res); | ||
| 663 | // return res; | 708 | // return res; |
| 664 | } | 709 | } |
| 665 | 710 | ||
| @@ -694,6 +739,28 @@ bool CInFile::OpenShared(const char *name, bool) | |||
| 694 | return Open(name); | 739 | return Open(name); |
| 695 | } | 740 | } |
| 696 | 741 | ||
| 742 | |||
| 743 | /* | ||
| 744 | int CFileBase::my_ioctl_BLKGETSIZE64(unsigned long long *numBlocks) | ||
| 745 | { | ||
| 746 | // we can read "/sys/block/sda/size" "/sys/block/sda/sda1/size" - partition | ||
| 747 | // #include <linux/fs.h> | ||
| 748 | return ioctl(_handle, BLKGETSIZE64, numBlocks); | ||
| 749 | // in block size | ||
| 750 | } | ||
| 751 | |||
| 752 | int CFileBase::GetDeviceSize_InBytes(UInt64 &size) | ||
| 753 | { | ||
| 754 | size = 0; | ||
| 755 | unsigned long long numBlocks; | ||
| 756 | int res = my_ioctl_BLKGETSIZE64(&numBlocks); | ||
| 757 | if (res == 0) | ||
| 758 | size = numBlocks; // another blockSize s possible? | ||
| 759 | printf("\nGetDeviceSize_InBytes res = %d, size = %lld\n", res, (long long)size); | ||
| 760 | return res; | ||
| 761 | } | ||
| 762 | */ | ||
| 763 | |||
| 697 | /* | 764 | /* |
| 698 | On Linux (32-bit and 64-bit): | 765 | On Linux (32-bit and 64-bit): |
| 699 | read(), write() (and similar system calls) will transfer at most | 766 | read(), write() (and similar system calls) will transfer at most |
| @@ -802,7 +869,7 @@ bool COutFile::Close() | |||
| 802 | return res; | 869 | return res; |
| 803 | } | 870 | } |
| 804 | 871 | ||
| 805 | bool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) throw() | 872 | bool COutFile::SetTime(const CFiTime *cTime, const CFiTime *aTime, const CFiTime *mTime) throw() |
| 806 | { | 873 | { |
| 807 | // On some OS (cygwin, MacOSX ...), you must close the file before updating times | 874 | // On some OS (cygwin, MacOSX ...), you must close the file before updating times |
| 808 | // return true; | 875 | // return true; |
| @@ -811,9 +878,22 @@ bool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILET | |||
| 811 | if (aTime) { ATime = *aTime; ATime_defined = true; } else ATime_defined = false; | 878 | if (aTime) { ATime = *aTime; ATime_defined = true; } else ATime_defined = false; |
| 812 | if (mTime) { MTime = *mTime; MTime_defined = true; } else MTime_defined = false; | 879 | if (mTime) { MTime = *mTime; MTime_defined = true; } else MTime_defined = false; |
| 813 | return true; | 880 | return true; |
| 881 | |||
| 882 | /* | ||
| 883 | struct timespec times[2]; | ||
| 884 | UNUSED_VAR(cTime) | ||
| 885 | if (!aTime && !mTime) | ||
| 886 | return true; | ||
| 887 | bool needChange; | ||
| 888 | needChange = FiTime_To_timespec(aTime, times[0]); | ||
| 889 | needChange |= FiTime_To_timespec(mTime, times[1]); | ||
| 890 | if (!needChange) | ||
| 891 | return true; | ||
| 892 | return futimens(_handle, times) == 0; | ||
| 893 | */ | ||
| 814 | } | 894 | } |
| 815 | 895 | ||
| 816 | bool COutFile::SetMTime(const FILETIME *mTime) throw() | 896 | bool COutFile::SetMTime(const CFiTime *mTime) throw() |
| 817 | { | 897 | { |
| 818 | if (mTime) { MTime = *mTime; MTime_defined = true; } else MTime_defined = false; | 898 | if (mTime) { MTime = *mTime; MTime_defined = true; } else MTime_defined = false; |
| 819 | return true; | 899 | return true; |
